update atheros 2.6 port - add support for the older chip generation
[openwrt/openwrt.git] / target / linux / atheros-2.6 / files / drivers / net / ar2313 / ar2313.h
1 #ifndef _AR2313_H_
2 #define _AR2313_H_
3
4 #include <linux/autoconf.h>
5 #include <asm/bootinfo.h>
6 #include "platform.h"
7
8 extern unsigned long mips_machtype;
9
10 #undef ETHERNET_BASE
11 #define ETHERNET_BASE ar_eth_base
12 #define ETHERNET_SIZE 0x00100000
13 #define ETHERNET_MACS 2
14
15 #undef DMA_BASE
16 #define DMA_BASE ar_dma_base
17 #define DMA_SIZE 0x00100000
18
19
20 /*
21 * probe link timer - 5 secs
22 */
23 #define LINK_TIMER (5*HZ)
24
25 /*
26 * Interrupt register base address
27 */
28 #define INTERRUPT_BASE PHYS_TO_K1(ar_int_base)
29
30 /*
31 * Reset Register
32 */
33 #define AR531X_RESET (AR531X_RESETTMR + 0x0020)
34 #define RESET_SYSTEM 0x00000001 /* cold reset full system */
35 #define RESET_PROC 0x00000002 /* cold reset MIPS core */
36 #define RESET_WLAN0 0x00000004 /* cold reset WLAN MAC and BB */
37 #define RESET_EPHY0 0x00000008 /* cold reset ENET0 phy */
38 #define RESET_EPHY1 0x00000010 /* cold reset ENET1 phy */
39 #define RESET_ENET0 0x00000020 /* cold reset ENET0 mac */
40 #define RESET_ENET1 0x00000040 /* cold reset ENET1 mac */
41
42 #define IS_DMA_TX_INT(X) (((X) & (DMA_STATUS_TI)) != 0)
43 #define IS_DMA_RX_INT(X) (((X) & (DMA_STATUS_RI)) != 0)
44 #define IS_DRIVER_OWNED(X) (((X) & (DMA_TX_OWN)) == 0)
45
46 #ifndef K1_TO_PHYS
47 // hack
48 #define K1_TO_PHYS(x) (((unsigned int)(x)) & 0x1FFFFFFF) /* kseg1 to physical */
49 #endif
50
51 #ifndef PHYS_TO_K1
52 // hack
53 #define PHYS_TO_K1(x) (((unsigned int)(x)) | 0xA0000000) /* physical to kseg1 */
54 #endif
55
56 #define AR2313_TX_TIMEOUT (HZ/4)
57
58 /*
59 * Rings
60 */
61 #define DSC_RING_ENTRIES_SIZE (AR2313_DESCR_ENTRIES * sizeof(struct desc))
62 #define DSC_NEXT(idx) ((idx + 1) & (AR2313_DESCR_ENTRIES - 1))
63
64 static inline int tx_space (u32 csm, u32 prd)
65 {
66 return (csm - prd - 1) & (AR2313_DESCR_ENTRIES - 1);
67 }
68
69 #if MAX_SKB_FRAGS
70 #define TX_RESERVED (MAX_SKB_FRAGS+1) /* +1 for message header */
71 #define tx_ring_full(csm, prd) (tx_space(csm, prd) <= TX_RESERVED)
72 #else
73 #define tx_ring_full 0
74 #endif
75
76 #define AR2313_MBGET 2
77 #define AR2313_MBSET 3
78 #define AR2313_PCI_RECONFIG 4
79 #define AR2313_PCI_DUMP 5
80 #define AR2313_TEST_PANIC 6
81 #define AR2313_TEST_NULLPTR 7
82 #define AR2313_READ_DATA 8
83 #define AR2313_WRITE_DATA 9
84 #define AR2313_GET_VERSION 10
85 #define AR2313_TEST_HANG 11
86 #define AR2313_SYNC 12
87
88
89 struct ar2313_cmd {
90 u32 cmd;
91 u32 address; /* virtual address of image */
92 u32 length; /* size of image to download */
93 u32 mailbox; /* mailbox to get/set */
94 u32 data[2]; /* contents of mailbox to read/write */
95 };
96
97
98 /*
99 * Struct private for the Sibyte.
100 *
101 * Elements are grouped so variables used by the tx handling goes
102 * together, and will go into the same cache lines etc. in order to
103 * avoid cache line contention between the rx and tx handling on SMP.
104 *
105 * Frequently accessed variables are put at the beginning of the
106 * struct to help the compiler generate better/shorter code.
107 */
108 struct ar2313_private
109 {
110 struct net_device *dev;
111 int version;
112 u32 mb[2];
113
114 volatile ETHERNET_STRUCT *eth_regs;
115 volatile DMA *dma_regs;
116 volatile u32 *int_regs;
117
118 spinlock_t lock; /* Serialise access to device */
119
120 /*
121 * RX and TX descriptors, must be adjacent
122 */
123 ar2313_descr_t *rx_ring;
124 ar2313_descr_t *tx_ring;
125
126
127 struct sk_buff **rx_skb;
128 struct sk_buff **tx_skb;
129
130 /*
131 * RX elements
132 */
133 u32 rx_skbprd;
134 u32 cur_rx;
135
136 /*
137 * TX elements
138 */
139 u32 tx_prd;
140 u32 tx_csm;
141
142 /*
143 * Misc elements
144 */
145 int board_idx;
146 char name[48];
147 struct net_device_stats stats;
148 struct {
149 u32 address;
150 u32 length;
151 char *mapping;
152 } desc;
153
154
155 struct timer_list link_timer;
156 unsigned short phy; /* merlot phy = 1, samsung phy = 0x1f */
157 unsigned short mac;
158 unsigned short link; /* 0 - link down, 1 - link up */
159 u16 phyData;
160
161 struct tasklet_struct rx_tasklet;
162 int unloading;
163 };
164
165
166 /*
167 * Prototypes
168 */
169 static int ar2313_init(struct net_device *dev);
170 #ifdef TX_TIMEOUT
171 static void ar2313_tx_timeout(struct net_device *dev);
172 #endif
173 #if 0
174 static void ar2313_multicast_list(struct net_device *dev);
175 #endif
176 static int ar2313_restart(struct net_device *dev);
177 #if DEBUG
178 static void ar2313_dump_regs(struct net_device *dev);
179 #endif
180 static void ar2313_load_rx_ring(struct net_device *dev, int bufs);
181 static irqreturn_t ar2313_interrupt(int irq, void *dev_id);
182 static int ar2313_open(struct net_device *dev);
183 static int ar2313_start_xmit(struct sk_buff *skb, struct net_device *dev);
184 static int ar2313_close(struct net_device *dev);
185 static int ar2313_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd);
186 static void ar2313_init_cleanup(struct net_device *dev);
187 static int ar2313_setup_timer(struct net_device *dev);
188 static void ar2313_link_timer_fn(unsigned long data);
189 static void ar2313_check_link(struct net_device *dev);
190 static struct net_device_stats *ar2313_get_stats(struct net_device *dev);
191 #endif /* _AR2313_H_ */