diff options
author | Jens Osterkamp <Jens.Osterkamp@de.ibm.com> | 2005-09-05 18:19:29 -0400 |
---|---|---|
committer | Jeff Garzik <jgarzik@pobox.com> | 2005-09-06 22:17:49 -0400 |
commit | aaec0fab5f8809fe1509fdc204e769bb35ebe41a (patch) | |
tree | 8f2ae06374413dd9d3e56a12b0592be9bb58c6e5 /drivers | |
parent | 25097d4bda4a554d8b4a9989c7d8bcb67ef53f48 (diff) |
[PATCH] net: add driver for the NIC on Cell Blades
This patch adds a driver for a new 1000 Mbit ethernet NIC. It is
integrated on the south bridge that is used for our Cell Blades.
The code gets the MAC address from the Open Firmware device tree, so it
won't compile on platforms other than ppc64.
This is the first public release, so I don't expect the first version to
get merged, but I'd aim for integration within the 2.6.13 time frame.
Cc: Utz Bacher <utz.bacher@de.ibm.com>
Signed-off-by: Arnd Bergmann <arndb@de.ibm.com>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Jeff Garzik <jgarzik@pobox.com>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/net/Kconfig | 7 | ||||
-rw-r--r-- | drivers/net/Makefile | 2 | ||||
-rw-r--r-- | drivers/net/spider_net.c | 2298 | ||||
-rw-r--r-- | drivers/net/spider_net.h | 469 | ||||
-rw-r--r-- | drivers/net/spider_net_ethtool.c | 107 |
5 files changed, 2883 insertions, 0 deletions
diff --git a/drivers/net/Kconfig b/drivers/net/Kconfig index ae9e7a579b94..6bb9232514b4 100644 --- a/drivers/net/Kconfig +++ b/drivers/net/Kconfig | |||
@@ -2058,6 +2058,13 @@ config BNX2 | |||
2058 | To compile this driver as a module, choose M here: the module | 2058 | To compile this driver as a module, choose M here: the module |
2059 | will be called bnx2. This is recommended. | 2059 | will be called bnx2. This is recommended. |
2060 | 2060 | ||
2061 | config SPIDER_NET | ||
2062 | tristate "Spider Gigabit Ethernet driver" | ||
2063 | depends on PCI && PPC_BPA | ||
2064 | help | ||
2065 | This driver supports the Gigabit Ethernet chips present on the | ||
2066 | Cell Processor-Based Blades from IBM. | ||
2067 | |||
2061 | config GIANFAR | 2068 | config GIANFAR |
2062 | tristate "Gianfar Ethernet" | 2069 | tristate "Gianfar Ethernet" |
2063 | depends on 85xx || 83xx | 2070 | depends on 85xx || 83xx |
diff --git a/drivers/net/Makefile b/drivers/net/Makefile index 5baafcd55610..8645c843cf4d 100644 --- a/drivers/net/Makefile +++ b/drivers/net/Makefile | |||
@@ -54,6 +54,8 @@ obj-$(CONFIG_STNIC) += stnic.o 8390.o | |||
54 | obj-$(CONFIG_FEALNX) += fealnx.o | 54 | obj-$(CONFIG_FEALNX) += fealnx.o |
55 | obj-$(CONFIG_TIGON3) += tg3.o | 55 | obj-$(CONFIG_TIGON3) += tg3.o |
56 | obj-$(CONFIG_BNX2) += bnx2.o | 56 | obj-$(CONFIG_BNX2) += bnx2.o |
57 | spidernet-y += spider_net.o spider_net_ethtool.o sungem_phy.o | ||
58 | obj-$(CONFIG_SPIDER_NET) += spidernet.o | ||
57 | obj-$(CONFIG_TC35815) += tc35815.o | 59 | obj-$(CONFIG_TC35815) += tc35815.o |
58 | obj-$(CONFIG_SKGE) += skge.o | 60 | obj-$(CONFIG_SKGE) += skge.o |
59 | obj-$(CONFIG_SK98LIN) += sk98lin/ | 61 | obj-$(CONFIG_SK98LIN) += sk98lin/ |
diff --git a/drivers/net/spider_net.c b/drivers/net/spider_net.c new file mode 100644 index 000000000000..692a0437fef7 --- /dev/null +++ b/drivers/net/spider_net.c | |||
@@ -0,0 +1,2298 @@ | |||
1 | /* | ||
2 | * Network device driver for Cell Processor-Based Blade | ||
3 | * | ||
4 | * (C) Copyright IBM Corp. 2005 | ||
5 | * | ||
6 | * Authors : Utz Bacher <utz.bacher@de.ibm.com> | ||
7 | * Jens Osterkamp <Jens.Osterkamp@de.ibm.com> | ||
8 | * | ||
9 | * This program is free software; you can redistribute it and/or modify | ||
10 | * it under the terms of the GNU General Public License as published by | ||
11 | * the Free Software Foundation; either version 2, or (at your option) | ||
12 | * any later version. | ||
13 | * | ||
14 | * This program is distributed in the hope that it will be useful, | ||
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
17 | * GNU General Public License for more details. | ||
18 | * | ||
19 | * You should have received a copy of the GNU General Public License | ||
20 | * along with this program; if not, write to the Free Software | ||
21 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | ||
22 | */ | ||
23 | |||
24 | #include <linux/config.h> | ||
25 | |||
26 | #include <linux/compiler.h> | ||
27 | #include <linux/crc32.h> | ||
28 | #include <linux/delay.h> | ||
29 | #include <linux/etherdevice.h> | ||
30 | #include <linux/ethtool.h> | ||
31 | #include <linux/firmware.h> | ||
32 | #include <linux/if_vlan.h> | ||
33 | #include <linux/init.h> | ||
34 | #include <linux/ioport.h> | ||
35 | #include <linux/ip.h> | ||
36 | #include <linux/kernel.h> | ||
37 | #include <linux/mii.h> | ||
38 | #include <linux/module.h> | ||
39 | #include <linux/netdevice.h> | ||
40 | #include <linux/device.h> | ||
41 | #include <linux/pci.h> | ||
42 | #include <linux/skbuff.h> | ||
43 | #include <linux/slab.h> | ||
44 | #include <linux/tcp.h> | ||
45 | #include <linux/types.h> | ||
46 | #include <linux/wait.h> | ||
47 | #include <linux/workqueue.h> | ||
48 | #include <asm/bitops.h> | ||
49 | #include <asm/pci-bridge.h> | ||
50 | #include <net/checksum.h> | ||
51 | |||
52 | #include "spider_net.h" | ||
53 | |||
54 | MODULE_AUTHOR("Utz Bacher <utz.bacher@de.ibm.com> and Jens Osterkamp " \ | ||
55 | "<Jens.Osterkamp@de.ibm.com>"); | ||
56 | MODULE_DESCRIPTION("Spider Southbridge Gigabit Ethernet driver"); | ||
57 | MODULE_LICENSE("GPL"); | ||
58 | |||
59 | static int rx_descriptors = SPIDER_NET_RX_DESCRIPTORS_DEFAULT; | ||
60 | static int tx_descriptors = SPIDER_NET_TX_DESCRIPTORS_DEFAULT; | ||
61 | |||
62 | module_param(rx_descriptors, int, 0644); | ||
63 | module_param(tx_descriptors, int, 0644); | ||
64 | |||
65 | MODULE_PARM_DESC(rx_descriptors, "number of descriptors used " \ | ||
66 | "in rx chains"); | ||
67 | MODULE_PARM_DESC(tx_descriptors, "number of descriptors used " \ | ||
68 | "in tx chain"); | ||
69 | |||
70 | char spider_net_driver_name[] = "spidernet"; | ||
71 | |||
72 | static struct pci_device_id spider_net_pci_tbl[] = { | ||
73 | { PCI_VENDOR_ID_TOSHIBA_2, PCI_DEVICE_ID_TOSHIBA_SPIDER_NET, | ||
74 | PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL }, | ||
75 | { 0, } | ||
76 | }; | ||
77 | |||
78 | MODULE_DEVICE_TABLE(pci, spider_net_pci_tbl); | ||
79 | |||
80 | /** | ||
81 | * spider_net_read_reg - reads an SMMIO register of a card | ||
82 | * @card: device structure | ||
83 | * @reg: register to read from | ||
84 | * | ||
85 | * returns the content of the specified SMMIO register. | ||
86 | */ | ||
87 | static u32 | ||
88 | spider_net_read_reg(struct spider_net_card *card, u32 reg) | ||
89 | { | ||
90 | u32 value; | ||
91 | |||
92 | value = readl(card->regs + reg); | ||
93 | value = le32_to_cpu(value); | ||
94 | |||
95 | return value; | ||
96 | } | ||
97 | |||
98 | /** | ||
99 | * spider_net_write_reg - writes to an SMMIO register of a card | ||
100 | * @card: device structure | ||
101 | * @reg: register to write to | ||
102 | * @value: value to write into the specified SMMIO register | ||
103 | */ | ||
104 | static void | ||
105 | spider_net_write_reg(struct spider_net_card *card, u32 reg, u32 value) | ||
106 | { | ||
107 | value = cpu_to_le32(value); | ||
108 | writel(value, card->regs + reg); | ||
109 | } | ||
110 | |||
111 | /** | ||
112 | * spider_net_rx_irq_off - switch off rx irq on this spider card | ||
113 | * @card: device structure | ||
114 | * | ||
115 | * switches off rx irq by masking them out in the GHIINTnMSK register | ||
116 | */ | ||
117 | static void | ||
118 | spider_net_rx_irq_off(struct spider_net_card *card) | ||
119 | { | ||
120 | u32 regvalue; | ||
121 | unsigned long flags; | ||
122 | |||
123 | spin_lock_irqsave(&card->intmask_lock, flags); | ||
124 | regvalue = spider_net_read_reg(card, SPIDER_NET_GHIINT0MSK); | ||
125 | regvalue &= ~SPIDER_NET_RXINT; | ||
126 | spider_net_write_reg(card, SPIDER_NET_GHIINT0MSK, regvalue); | ||
127 | spin_unlock_irqrestore(&card->intmask_lock, flags); | ||
128 | } | ||
129 | |||
130 | /** spider_net_write_phy - write to phy register | ||
131 | * @netdev: adapter to be written to | ||
132 | * @mii_id: id of MII | ||
133 | * @reg: PHY register | ||
134 | * @val: value to be written to phy register | ||
135 | * | ||
136 | * spider_net_write_phy_register writes to an arbitrary PHY | ||
137 | * register via the spider GPCWOPCMD register. We assume the queue does | ||
138 | * not run full (not more than 15 commands outstanding). | ||
139 | **/ | ||
140 | static void | ||
141 | spider_net_write_phy(struct net_device *netdev, int mii_id, | ||
142 | int reg, int val) | ||
143 | { | ||
144 | struct spider_net_card *card = netdev_priv(netdev); | ||
145 | u32 writevalue; | ||
146 | |||
147 | writevalue = ((u32)mii_id << 21) | | ||
148 | ((u32)reg << 16) | ((u32)val); | ||
149 | |||
150 | spider_net_write_reg(card, SPIDER_NET_GPCWOPCMD, writevalue); | ||
151 | } | ||
152 | |||
153 | /** spider_net_read_phy - read from phy register | ||
154 | * @netdev: network device to be read from | ||
155 | * @mii_id: id of MII | ||
156 | * @reg: PHY register | ||
157 | * | ||
158 | * Returns value read from PHY register | ||
159 | * | ||
160 | * spider_net_write_phy reads from an arbitrary PHY | ||
161 | * register via the spider GPCROPCMD register | ||
162 | **/ | ||
163 | static int | ||
164 | spider_net_read_phy(struct net_device *netdev, int mii_id, int reg) | ||
165 | { | ||
166 | struct spider_net_card *card = netdev_priv(netdev); | ||
167 | u32 readvalue; | ||
168 | |||
169 | readvalue = ((u32)mii_id << 21) | ((u32)reg << 16); | ||
170 | spider_net_write_reg(card, SPIDER_NET_GPCROPCMD, readvalue); | ||
171 | |||
172 | /* we don't use semaphores to wait for an SPIDER_NET_GPROPCMPINT | ||
173 | * interrupt, as we poll for the completion of the read operation | ||
174 | * in spider_net_read_phy. Should take about 50 us */ | ||
175 | do { | ||
176 | readvalue = spider_net_read_reg(card, SPIDER_NET_GPCROPCMD); | ||
177 | } while (readvalue & SPIDER_NET_GPREXEC); | ||
178 | |||
179 | readvalue &= SPIDER_NET_GPRDAT_MASK; | ||
180 | |||
181 | return readvalue; | ||
182 | } | ||
183 | |||
184 | /** | ||
185 | * spider_net_rx_irq_on - switch on rx irq on this spider card | ||
186 | * @card: device structure | ||
187 | * | ||
188 | * switches on rx irq by enabling them in the GHIINTnMSK register | ||
189 | */ | ||
190 | static void | ||
191 | spider_net_rx_irq_on(struct spider_net_card *card) | ||
192 | { | ||
193 | u32 regvalue; | ||
194 | unsigned long flags; | ||
195 | |||
196 | spin_lock_irqsave(&card->intmask_lock, flags); | ||
197 | regvalue = spider_net_read_reg(card, SPIDER_NET_GHIINT0MSK); | ||
198 | regvalue |= SPIDER_NET_RXINT; | ||
199 | spider_net_write_reg(card, SPIDER_NET_GHIINT0MSK, regvalue); | ||
200 | spin_unlock_irqrestore(&card->intmask_lock, flags); | ||
201 | } | ||
202 | |||
203 | /** | ||
204 | * spider_net_tx_irq_off - switch off tx irq on this spider card | ||
205 | * @card: device structure | ||
206 | * | ||
207 | * switches off tx irq by masking them out in the GHIINTnMSK register | ||
208 | */ | ||
209 | static void | ||
210 | spider_net_tx_irq_off(struct spider_net_card *card) | ||
211 | { | ||
212 | u32 regvalue; | ||
213 | unsigned long flags; | ||
214 | |||
215 | spin_lock_irqsave(&card->intmask_lock, flags); | ||
216 | regvalue = spider_net_read_reg(card, SPIDER_NET_GHIINT0MSK); | ||
217 | regvalue &= ~SPIDER_NET_TXINT; | ||
218 | spider_net_write_reg(card, SPIDER_NET_GHIINT0MSK, regvalue); | ||
219 | spin_unlock_irqrestore(&card->intmask_lock, flags); | ||
220 | } | ||
221 | |||
222 | /** | ||
223 | * spider_net_tx_irq_on - switch on tx irq on this spider card | ||
224 | * @card: device structure | ||
225 | * | ||
226 | * switches on tx irq by enabling them in the GHIINTnMSK register | ||
227 | */ | ||
228 | static void | ||
229 | spider_net_tx_irq_on(struct spider_net_card *card) | ||
230 | { | ||
231 | u32 regvalue; | ||
232 | unsigned long flags; | ||
233 | |||
234 | spin_lock_irqsave(&card->intmask_lock, flags); | ||
235 | regvalue = spider_net_read_reg(card, SPIDER_NET_GHIINT0MSK); | ||
236 | regvalue |= SPIDER_NET_TXINT; | ||
237 | spider_net_write_reg(card, SPIDER_NET_GHIINT0MSK, regvalue); | ||
238 | spin_unlock_irqrestore(&card->intmask_lock, flags); | ||
239 | } | ||
240 | |||
241 | /** | ||
242 | * spider_net_set_promisc - sets the unicast address or the promiscuous mode | ||
243 | * @card: card structure | ||
244 | * | ||
245 | * spider_net_set_promisc sets the unicast destination address filter and | ||
246 | * thus either allows for non-promisc mode or promisc mode | ||
247 | */ | ||
248 | static void | ||
249 | spider_net_set_promisc(struct spider_net_card *card) | ||
250 | { | ||
251 | u32 macu, macl; | ||
252 | struct net_device *netdev = card->netdev; | ||
253 | |||
254 | if (netdev->flags & IFF_PROMISC) { | ||
255 | /* clear destination entry 0 */ | ||
256 | spider_net_write_reg(card, SPIDER_NET_GMRUAFILnR, 0); | ||
257 | spider_net_write_reg(card, SPIDER_NET_GMRUAFILnR + 0x04, 0); | ||
258 | spider_net_write_reg(card, SPIDER_NET_GMRUA0FIL15R, | ||
259 | SPIDER_NET_PROMISC_VALUE); | ||
260 | } else { | ||
261 | macu = netdev->dev_addr[0]; | ||
262 | macu <<= 8; | ||
263 | macu |= netdev->dev_addr[1]; | ||
264 | memcpy(&macl, &netdev->dev_addr[2], sizeof(macl)); | ||
265 | |||
266 | macu |= SPIDER_NET_UA_DESCR_VALUE; | ||
267 | spider_net_write_reg(card, SPIDER_NET_GMRUAFILnR, macu); | ||
268 | spider_net_write_reg(card, SPIDER_NET_GMRUAFILnR + 0x04, macl); | ||
269 | spider_net_write_reg(card, SPIDER_NET_GMRUA0FIL15R, | ||
270 | SPIDER_NET_NONPROMISC_VALUE); | ||
271 | } | ||
272 | } | ||
273 | |||
274 | /** | ||
275 | * spider_net_get_mac_address - read mac address from spider card | ||
276 | * @card: device structure | ||
277 | * | ||
278 | * reads MAC address from GMACUNIMACU and GMACUNIMACL registers | ||
279 | */ | ||
280 | static int | ||
281 | spider_net_get_mac_address(struct net_device *netdev) | ||
282 | { | ||
283 | struct spider_net_card *card = netdev_priv(netdev); | ||
284 | u32 macl, macu; | ||
285 | |||
286 | macl = spider_net_read_reg(card, SPIDER_NET_GMACUNIMACL); | ||
287 | macu = spider_net_read_reg(card, SPIDER_NET_GMACUNIMACU); | ||
288 | |||
289 | netdev->dev_addr[0] = (macu >> 24) & 0xff; | ||
290 | netdev->dev_addr[1] = (macu >> 16) & 0xff; | ||
291 | netdev->dev_addr[2] = (macu >> 8) & 0xff; | ||
292 | netdev->dev_addr[3] = macu & 0xff; | ||
293 | netdev->dev_addr[4] = (macl >> 8) & 0xff; | ||
294 | netdev->dev_addr[5] = macl & 0xff; | ||
295 | |||
296 | if (!is_valid_ether_addr(&netdev->dev_addr[0])) | ||
297 | return -EINVAL; | ||
298 | |||
299 | return 0; | ||
300 | } | ||
301 | |||
302 | /** | ||
303 | * spider_net_get_descr_status -- returns the status of a descriptor | ||
304 | * @descr: descriptor to look at | ||
305 | * | ||
306 | * returns the status as in the dmac_cmd_status field of the descriptor | ||
307 | */ | ||
308 | static enum spider_net_descr_status | ||
309 | spider_net_get_descr_status(struct spider_net_descr *descr) | ||
310 | { | ||
311 | u32 cmd_status; | ||
312 | rmb(); | ||
313 | cmd_status = descr->dmac_cmd_status; | ||
314 | rmb(); | ||
315 | cmd_status >>= SPIDER_NET_DESCR_IND_PROC_SHIFT; | ||
316 | /* no need to mask out any bits, as cmd_status is 32 bits wide only | ||
317 | * (and unsigned) */ | ||
318 | return cmd_status; | ||
319 | } | ||
320 | |||
321 | /** | ||
322 | * spider_net_set_descr_status -- sets the status of a descriptor | ||
323 | * @descr: descriptor to change | ||
324 | * @status: status to set in the descriptor | ||
325 | * | ||
326 | * changes the status to the specified value. Doesn't change other bits | ||
327 | * in the status | ||
328 | */ | ||
329 | static void | ||
330 | spider_net_set_descr_status(struct spider_net_descr *descr, | ||
331 | enum spider_net_descr_status status) | ||
332 | { | ||
333 | u32 cmd_status; | ||
334 | /* read the status */ | ||
335 | mb(); | ||
336 | cmd_status = descr->dmac_cmd_status; | ||
337 | /* clean the upper 4 bits */ | ||
338 | cmd_status &= SPIDER_NET_DESCR_IND_PROC_MASKO; | ||
339 | /* add the status to it */ | ||
340 | cmd_status |= ((u32)status)<<SPIDER_NET_DESCR_IND_PROC_SHIFT; | ||
341 | /* and write it back */ | ||
342 | descr->dmac_cmd_status = cmd_status; | ||
343 | wmb(); | ||
344 | } | ||
345 | |||
346 | /** | ||
347 | * spider_net_free_chain - free descriptor chain | ||
348 | * @card: card structure | ||
349 | * @chain: address of chain | ||
350 | * | ||
351 | */ | ||
352 | static void | ||
353 | spider_net_free_chain(struct spider_net_card *card, | ||
354 | struct spider_net_descr_chain *chain) | ||
355 | { | ||
356 | struct spider_net_descr *descr; | ||
357 | |||
358 | for (descr = chain->tail; !descr->bus_addr; descr = descr->next) { | ||
359 | pci_unmap_single(card->pdev, descr->bus_addr, | ||
360 | SPIDER_NET_DESCR_SIZE, PCI_DMA_BIDIRECTIONAL); | ||
361 | descr->bus_addr = 0; | ||
362 | } | ||
363 | } | ||
364 | |||
365 | /** | ||
366 | * spider_net_init_chain - links descriptor chain | ||
367 | * @card: card structure | ||
368 | * @chain: address of chain | ||
369 | * @start_descr: address of descriptor array | ||
370 | * @no: number of descriptors | ||
371 | * | ||
372 | * we manage a circular list that mirrors the hardware structure, | ||
373 | * except that the hardware uses bus addresses. | ||
374 | * | ||
375 | * returns 0 on success, <0 on failure | ||
376 | */ | ||
377 | static int | ||
378 | spider_net_init_chain(struct spider_net_card *card, | ||
379 | struct spider_net_descr_chain *chain, | ||
380 | struct spider_net_descr *start_descr, int no) | ||
381 | { | ||
382 | int i; | ||
383 | struct spider_net_descr *descr; | ||
384 | |||
385 | spin_lock_init(&card->chain_lock); | ||
386 | |||
387 | descr = start_descr; | ||
388 | memset(descr, 0, sizeof(*descr) * no); | ||
389 | |||
390 | /* set up the hardware pointers in each descriptor */ | ||
391 | for (i=0; i<no; i++, descr++) { | ||
392 | spider_net_set_descr_status(descr, SPIDER_NET_DESCR_NOT_IN_USE); | ||
393 | |||
394 | descr->bus_addr = | ||
395 | pci_map_single(card->pdev, descr, | ||
396 | SPIDER_NET_DESCR_SIZE, | ||
397 | PCI_DMA_BIDIRECTIONAL); | ||
398 | |||
399 | if (descr->bus_addr == DMA_ERROR_CODE) | ||
400 | goto iommu_error; | ||
401 | |||
402 | descr->next = descr + 1; | ||
403 | descr->prev = descr - 1; | ||
404 | |||
405 | } | ||
406 | /* do actual circular list */ | ||
407 | (descr-1)->next = start_descr; | ||
408 | start_descr->prev = descr-1; | ||
409 | |||
410 | descr = start_descr; | ||
411 | for (i=0; i < no; i++, descr++) { | ||
412 | descr->next_descr_addr = descr->next->bus_addr; | ||
413 | } | ||
414 | |||
415 | chain->head = start_descr; | ||
416 | chain->tail = start_descr; | ||
417 | |||
418 | return 0; | ||
419 | |||
420 | iommu_error: | ||
421 | descr = start_descr; | ||
422 | for (i=0; i < no; i++, descr++) | ||
423 | if (descr->bus_addr) | ||
424 | pci_unmap_single(card->pdev, descr->bus_addr, | ||
425 | SPIDER_NET_DESCR_SIZE, PCI_DMA_BIDIRECTIONAL); | ||
426 | return -ENOMEM; | ||
427 | } | ||
428 | |||
429 | /** | ||
430 | * spider_net_free_rx_chain_contents - frees descr contents in rx chain | ||
431 | * @card: card structure | ||
432 | * | ||
433 | * returns 0 on success, <0 on failure | ||
434 | */ | ||
435 | static void | ||
436 | spider_net_free_rx_chain_contents(struct spider_net_card *card) | ||
437 | { | ||
438 | struct spider_net_descr *descr; | ||
439 | |||
440 | descr = card->rx_chain.head; | ||
441 | while (descr->next != card->rx_chain.head) { | ||
442 | if (descr->skb) { | ||
443 | dev_kfree_skb(descr->skb); | ||
444 | pci_unmap_single(card->pdev, descr->buf_addr, | ||
445 | SPIDER_NET_MAX_MTU, | ||
446 | PCI_DMA_BIDIRECTIONAL); | ||
447 | } | ||
448 | descr = descr->next; | ||
449 | } | ||
450 | } | ||
451 | |||
452 | /** | ||
453 | * spider_net_prepare_rx_descr - reinitializes a rx descriptor | ||
454 | * @card: card structure | ||
455 | * @descr: descriptor to re-init | ||
456 | * | ||
457 | * return 0 on succes, <0 on failure | ||
458 | * | ||
459 | * allocates a new rx skb, iommu-maps it and attaches it to the descriptor. | ||
460 | * Activate the descriptor state-wise | ||
461 | */ | ||
462 | static int | ||
463 | spider_net_prepare_rx_descr(struct spider_net_card *card, | ||
464 | struct spider_net_descr *descr) | ||
465 | { | ||
466 | int error = 0; | ||
467 | int offset; | ||
468 | int bufsize; | ||
469 | |||
470 | /* we need to round up the buffer size to a multiple of 128 */ | ||
471 | bufsize = (SPIDER_NET_MAX_MTU + SPIDER_NET_RXBUF_ALIGN - 1) & | ||
472 | (~(SPIDER_NET_RXBUF_ALIGN - 1)); | ||
473 | |||
474 | /* and we need to have it 128 byte aligned, therefore we allocate a | ||
475 | * bit more */ | ||
476 | /* allocate an skb */ | ||
477 | descr->skb = dev_alloc_skb(bufsize + SPIDER_NET_RXBUF_ALIGN - 1); | ||
478 | if (!descr->skb) { | ||
479 | if (net_ratelimit()) | ||
480 | if (netif_msg_rx_err(card)) | ||
481 | pr_err("Not enough memory to allocate " | ||
482 | "rx buffer\n"); | ||
483 | return -ENOMEM; | ||
484 | } | ||
485 | descr->buf_size = bufsize; | ||
486 | descr->result_size = 0; | ||
487 | descr->valid_size = 0; | ||
488 | descr->data_status = 0; | ||
489 | descr->data_error = 0; | ||
490 | |||
491 | offset = ((unsigned long)descr->skb->data) & | ||
492 | (SPIDER_NET_RXBUF_ALIGN - 1); | ||
493 | if (offset) | ||
494 | skb_reserve(descr->skb, SPIDER_NET_RXBUF_ALIGN - offset); | ||
495 | /* io-mmu-map the skb */ | ||
496 | descr->buf_addr = pci_map_single(card->pdev, descr->skb->data, | ||
497 | SPIDER_NET_MAX_MTU, | ||
498 | PCI_DMA_BIDIRECTIONAL); | ||
499 | if (descr->buf_addr == DMA_ERROR_CODE) { | ||
500 | dev_kfree_skb_any(descr->skb); | ||
501 | if (netif_msg_rx_err(card)) | ||
502 | pr_err("Could not iommu-map rx buffer\n"); | ||
503 | spider_net_set_descr_status(descr, SPIDER_NET_DESCR_NOT_IN_USE); | ||
504 | } else { | ||
505 | descr->dmac_cmd_status = SPIDER_NET_DMAC_RX_CARDOWNED; | ||
506 | } | ||
507 | |||
508 | return error; | ||
509 | } | ||
510 | |||
511 | /** | ||
512 | * spider_net_enable_rxctails - sets RX dmac chain tail addresses | ||
513 | * @card: card structure | ||
514 | * | ||
515 | * spider_net_enable_rxctails sets the RX DMAC chain tail adresses in the | ||
516 | * chip by writing to the appropriate register. DMA is enabled in | ||
517 | * spider_net_enable_rxdmac. | ||
518 | */ | ||
519 | static void | ||
520 | spider_net_enable_rxchtails(struct spider_net_card *card) | ||
521 | { | ||
522 | /* assume chain is aligned correctly */ | ||
523 | spider_net_write_reg(card, SPIDER_NET_GDADCHA , | ||
524 | card->rx_chain.tail->bus_addr); | ||
525 | } | ||
526 | |||
527 | /** | ||
528 | * spider_net_enable_rxdmac - enables a receive DMA controller | ||
529 | * @card: card structure | ||
530 | * | ||
531 | * spider_net_enable_rxdmac enables the DMA controller by setting RX_DMA_EN | ||
532 | * in the GDADMACCNTR register | ||
533 | */ | ||
534 | static void | ||
535 | spider_net_enable_rxdmac(struct spider_net_card *card) | ||
536 | { | ||
537 | spider_net_write_reg(card, SPIDER_NET_GDADMACCNTR, | ||
538 | SPIDER_NET_DMA_RX_VALUE); | ||
539 | } | ||
540 | |||
541 | /** | ||
542 | * spider_net_refill_rx_chain - refills descriptors/skbs in the rx chains | ||
543 | * @card: card structure | ||
544 | * | ||
545 | * refills descriptors in all chains (last used chain first): allocates skbs | ||
546 | * and iommu-maps them. | ||
547 | */ | ||
548 | static void | ||
549 | spider_net_refill_rx_chain(struct spider_net_card *card) | ||
550 | { | ||
551 | struct spider_net_descr_chain *chain; | ||
552 | int count = 0; | ||
553 | unsigned long flags; | ||
554 | |||
555 | chain = &card->rx_chain; | ||
556 | |||
557 | spin_lock_irqsave(&card->chain_lock, flags); | ||
558 | while (spider_net_get_descr_status(chain->head) == | ||
559 | SPIDER_NET_DESCR_NOT_IN_USE) { | ||
560 | if (spider_net_prepare_rx_descr(card, chain->head)) | ||
561 | break; | ||
562 | count++; | ||
563 | chain->head = chain->head->next; | ||
564 | } | ||
565 | spin_unlock_irqrestore(&card->chain_lock, flags); | ||
566 | |||
567 | /* could be optimized, only do that, if we know the DMA processing | ||
568 | * has terminated */ | ||
569 | if (count) | ||
570 | spider_net_enable_rxdmac(card); | ||
571 | } | ||
572 | |||
573 | /** | ||
574 | * spider_net_alloc_rx_skbs - allocates rx skbs in rx descriptor chains | ||
575 | * @card: card structure | ||
576 | * | ||
577 | * returns 0 on success, <0 on failure | ||
578 | */ | ||
579 | static int | ||
580 | spider_net_alloc_rx_skbs(struct spider_net_card *card) | ||
581 | { | ||
582 | int result; | ||
583 | struct spider_net_descr_chain *chain; | ||
584 | |||
585 | result = -ENOMEM; | ||
586 | |||
587 | chain = &card->rx_chain; | ||
588 | /* put at least one buffer into the chain. if this fails, | ||
589 | * we've got a problem. if not, spider_net_refill_rx_chain | ||
590 | * will do the rest at the end of this function */ | ||
591 | if (spider_net_prepare_rx_descr(card, chain->head)) | ||
592 | goto error; | ||
593 | else | ||
594 | chain->head = chain->head->next; | ||
595 | |||
596 | /* this will allocate the rest of the rx buffers; if not, it's | ||
597 | * business as usual later on */ | ||
598 | spider_net_refill_rx_chain(card); | ||
599 | return 0; | ||
600 | |||
601 | error: | ||
602 | spider_net_free_rx_chain_contents(card); | ||
603 | return result; | ||
604 | } | ||
605 | |||
606 | /** | ||
607 | * spider_net_release_tx_descr - processes a used tx descriptor | ||
608 | * @card: card structure | ||
609 | * @descr: descriptor to release | ||
610 | * | ||
611 | * releases a used tx descriptor (unmapping, freeing of skb) | ||
612 | */ | ||
613 | static void | ||
614 | spider_net_release_tx_descr(struct spider_net_card *card, | ||
615 | struct spider_net_descr *descr) | ||
616 | { | ||
617 | struct sk_buff *skb; | ||
618 | |||
619 | /* unmap the skb */ | ||
620 | skb = descr->skb; | ||
621 | pci_unmap_single(card->pdev, descr->buf_addr, skb->len, | ||
622 | PCI_DMA_BIDIRECTIONAL); | ||
623 | |||
624 | dev_kfree_skb_any(skb); | ||
625 | |||
626 | /* set status to not used */ | ||
627 | spider_net_set_descr_status(descr, SPIDER_NET_DESCR_NOT_IN_USE); | ||
628 | } | ||
629 | |||
630 | /** | ||
631 | * spider_net_release_tx_chain - processes sent tx descriptors | ||
632 | * @card: adapter structure | ||
633 | * @brutal: if set, don't care about whether descriptor seems to be in use | ||
634 | * | ||
635 | * releases the tx descriptors that spider has finished with (if non-brutal) | ||
636 | * or simply release tx descriptors (if brutal) | ||
637 | */ | ||
638 | static void | ||
639 | spider_net_release_tx_chain(struct spider_net_card *card, int brutal) | ||
640 | { | ||
641 | struct spider_net_descr_chain *tx_chain = &card->tx_chain; | ||
642 | enum spider_net_descr_status status; | ||
643 | |||
644 | spider_net_tx_irq_off(card); | ||
645 | |||
646 | /* no lock for chain needed, if this is only executed once at a time */ | ||
647 | again: | ||
648 | for (;;) { | ||
649 | status = spider_net_get_descr_status(tx_chain->tail); | ||
650 | switch (status) { | ||
651 | case SPIDER_NET_DESCR_CARDOWNED: | ||
652 | if (!brutal) goto out; | ||
653 | /* fallthrough, if we release the descriptors | ||
654 | * brutally (then we don't care about | ||
655 | * SPIDER_NET_DESCR_CARDOWNED) */ | ||
656 | case SPIDER_NET_DESCR_RESPONSE_ERROR: | ||
657 | case SPIDER_NET_DESCR_PROTECTION_ERROR: | ||
658 | case SPIDER_NET_DESCR_FORCE_END: | ||
659 | if (netif_msg_tx_err(card)) | ||
660 | pr_err("%s: forcing end of tx descriptor " | ||
661 | "with status x%02x\n", | ||
662 | card->netdev->name, status); | ||
663 | card->netdev_stats.tx_dropped++; | ||
664 | break; | ||
665 | |||
666 | case SPIDER_NET_DESCR_COMPLETE: | ||
667 | card->netdev_stats.tx_packets++; | ||
668 | card->netdev_stats.tx_bytes += | ||
669 | tx_chain->tail->skb->len; | ||
670 | break; | ||
671 | |||
672 | default: /* any other value (== SPIDER_NET_DESCR_NOT_IN_USE) */ | ||
673 | goto out; | ||
674 | } | ||
675 | spider_net_release_tx_descr(card, tx_chain->tail); | ||
676 | tx_chain->tail = tx_chain->tail->next; | ||
677 | } | ||
678 | out: | ||
679 | netif_wake_queue(card->netdev); | ||
680 | |||
681 | if (!brutal) { | ||
682 | /* switch on tx irqs (while we are still in the interrupt | ||
683 | * handler, so we don't get an interrupt), check again | ||
684 | * for done descriptors. This results in fewer interrupts */ | ||
685 | spider_net_tx_irq_on(card); | ||
686 | status = spider_net_get_descr_status(tx_chain->tail); | ||
687 | switch (status) { | ||
688 | case SPIDER_NET_DESCR_RESPONSE_ERROR: | ||
689 | case SPIDER_NET_DESCR_PROTECTION_ERROR: | ||
690 | case SPIDER_NET_DESCR_FORCE_END: | ||
691 | case SPIDER_NET_DESCR_COMPLETE: | ||
692 | goto again; | ||
693 | default: | ||
694 | break; | ||
695 | } | ||
696 | } | ||
697 | |||
698 | } | ||
699 | |||
700 | /** | ||
701 | * spider_net_get_multicast_hash - generates hash for multicast filter table | ||
702 | * @addr: multicast address | ||
703 | * | ||
704 | * returns the hash value. | ||
705 | * | ||
706 | * spider_net_get_multicast_hash calculates a hash value for a given multicast | ||
707 | * address, that is used to set the multicast filter tables | ||
708 | */ | ||
709 | static u8 | ||
710 | spider_net_get_multicast_hash(struct net_device *netdev, __u8 *addr) | ||
711 | { | ||
712 | /* FIXME: an addr of 01:00:5e:00:00:01 must result in 0xa9, | ||
713 | * ff:ff:ff:ff:ff:ff must result in 0xfd */ | ||
714 | u32 crc; | ||
715 | u8 hash; | ||
716 | |||
717 | crc = crc32_be(~0, addr, netdev->addr_len); | ||
718 | |||
719 | hash = (crc >> 27); | ||
720 | hash <<= 3; | ||
721 | hash |= crc & 7; | ||
722 | |||
723 | return hash; | ||
724 | } | ||
725 | |||
726 | /** | ||
727 | * spider_net_set_multi - sets multicast addresses and promisc flags | ||
728 | * @netdev: interface device structure | ||
729 | * | ||
730 | * spider_net_set_multi configures multicast addresses as needed for the | ||
731 | * netdev interface. It also sets up multicast, allmulti and promisc | ||
732 | * flags appropriately | ||
733 | */ | ||
734 | static void | ||
735 | spider_net_set_multi(struct net_device *netdev) | ||
736 | { | ||
737 | struct dev_mc_list *mc; | ||
738 | u8 hash; | ||
739 | int i; | ||
740 | u32 reg; | ||
741 | struct spider_net_card *card = netdev_priv(netdev); | ||
742 | unsigned long bitmask[SPIDER_NET_MULTICAST_HASHES / BITS_PER_LONG] = | ||
743 | {0, }; | ||
744 | |||
745 | spider_net_set_promisc(card); | ||
746 | |||
747 | if (netdev->flags & IFF_ALLMULTI) { | ||
748 | for (i = 0; i < SPIDER_NET_MULTICAST_HASHES; i++) { | ||
749 | set_bit(i, bitmask); | ||
750 | } | ||
751 | goto write_hash; | ||
752 | } | ||
753 | |||
754 | /* well, we know, what the broadcast hash value is: it's xfd | ||
755 | hash = spider_net_get_multicast_hash(netdev, netdev->broadcast); */ | ||
756 | set_bit(0xfd, bitmask); | ||
757 | |||
758 | for (mc = netdev->mc_list; mc; mc = mc->next) { | ||
759 | hash = spider_net_get_multicast_hash(netdev, mc->dmi_addr); | ||
760 | set_bit(hash, bitmask); | ||
761 | } | ||
762 | |||
763 | write_hash: | ||
764 | for (i = 0; i < SPIDER_NET_MULTICAST_HASHES / 4; i++) { | ||
765 | reg = 0; | ||
766 | if (test_bit(i * 4, bitmask)) | ||
767 | reg += 0x08; | ||
768 | reg <<= 8; | ||
769 | if (test_bit(i * 4 + 1, bitmask)) | ||
770 | reg += 0x08; | ||
771 | reg <<= 8; | ||
772 | if (test_bit(i * 4 + 2, bitmask)) | ||
773 | reg += 0x08; | ||
774 | reg <<= 8; | ||
775 | if (test_bit(i * 4 + 3, bitmask)) | ||
776 | reg += 0x08; | ||
777 | |||
778 | spider_net_write_reg(card, SPIDER_NET_GMRMHFILnR + i * 4, reg); | ||
779 | } | ||
780 | } | ||
781 | |||
782 | /** | ||
783 | * spider_net_disable_rxdmac - disables the receive DMA controller | ||
784 | * @card: card structure | ||
785 | * | ||
786 | * spider_net_disable_rxdmac terminates processing on the DMA controller by | ||
787 | * turing off DMA and issueing a force end | ||
788 | */ | ||
789 | static void | ||
790 | spider_net_disable_rxdmac(struct spider_net_card *card) | ||
791 | { | ||
792 | spider_net_write_reg(card, SPIDER_NET_GDADMACCNTR, | ||
793 | SPIDER_NET_DMA_RX_FEND_VALUE); | ||
794 | } | ||
795 | |||
796 | /** | ||
797 | * spider_net_stop - called upon ifconfig down | ||
798 | * @netdev: interface device structure | ||
799 | * | ||
800 | * always returns 0 | ||
801 | */ | ||
802 | int | ||
803 | spider_net_stop(struct net_device *netdev) | ||
804 | { | ||
805 | struct spider_net_card *card = netdev_priv(netdev); | ||
806 | |||
807 | netif_poll_disable(netdev); | ||
808 | netif_carrier_off(netdev); | ||
809 | netif_stop_queue(netdev); | ||
810 | |||
811 | /* disable/mask all interrupts */ | ||
812 | spider_net_write_reg(card, SPIDER_NET_GHIINT0MSK, 0); | ||
813 | spider_net_write_reg(card, SPIDER_NET_GHIINT1MSK, 0); | ||
814 | spider_net_write_reg(card, SPIDER_NET_GHIINT2MSK, 0); | ||
815 | |||
816 | spider_net_write_reg(card, SPIDER_NET_GDTDMACCNTR, | ||
817 | SPIDER_NET_DMA_TX_FEND_VALUE); | ||
818 | |||
819 | /* turn off DMA, force end */ | ||
820 | spider_net_disable_rxdmac(card); | ||
821 | |||
822 | /* release chains */ | ||
823 | spider_net_release_tx_chain(card, 1); | ||
824 | |||
825 | /* switch off card */ | ||
826 | spider_net_write_reg(card, SPIDER_NET_CKRCTRL, | ||
827 | SPIDER_NET_CKRCTRL_STOP_VALUE); | ||
828 | |||
829 | spider_net_free_chain(card, &card->tx_chain); | ||
830 | spider_net_free_chain(card, &card->rx_chain); | ||
831 | |||
832 | return 0; | ||
833 | } | ||
834 | |||
835 | /** | ||
836 | * spider_net_get_next_tx_descr - returns the next available tx descriptor | ||
837 | * @card: device structure to get descriptor from | ||
838 | * | ||
839 | * returns the address of the next descriptor, or NULL if not available. | ||
840 | */ | ||
841 | static struct spider_net_descr * | ||
842 | spider_net_get_next_tx_descr(struct spider_net_card *card) | ||
843 | { | ||
844 | /* check, if head points to not-in-use descr */ | ||
845 | if ( spider_net_get_descr_status(card->tx_chain.head) == | ||
846 | SPIDER_NET_DESCR_NOT_IN_USE ) { | ||
847 | return card->tx_chain.head; | ||
848 | } else { | ||
849 | return NULL; | ||
850 | } | ||
851 | } | ||
852 | |||
853 | /** | ||
854 | * spider_net_set_txdescr_cmdstat - sets the tx descriptor command field | ||
855 | * @descr: descriptor structure to fill out | ||
856 | * @skb: packet to consider | ||
857 | * | ||
858 | * fills out the command and status field of the descriptor structure, | ||
859 | * depending on hardware checksum settings. This function assumes a wmb() | ||
860 | * has executed before. | ||
861 | */ | ||
862 | static void | ||
863 | spider_net_set_txdescr_cmdstat(struct spider_net_descr *descr, | ||
864 | struct sk_buff *skb) | ||
865 | { | ||
866 | if (skb->ip_summed != CHECKSUM_HW) { | ||
867 | descr->dmac_cmd_status = SPIDER_NET_DMAC_CMDSTAT_NOCS; | ||
868 | return; | ||
869 | } | ||
870 | |||
871 | /* is packet ip? | ||
872 | * if yes: tcp? udp? */ | ||
873 | if (skb->protocol == htons(ETH_P_IP)) { | ||
874 | if (skb->nh.iph->protocol == IPPROTO_TCP) { | ||
875 | descr->dmac_cmd_status = SPIDER_NET_DMAC_CMDSTAT_TCPCS; | ||
876 | } else if (skb->nh.iph->protocol == IPPROTO_UDP) { | ||
877 | descr->dmac_cmd_status = SPIDER_NET_DMAC_CMDSTAT_UDPCS; | ||
878 | } else { /* the stack should checksum non-tcp and non-udp | ||
879 | packets on his own: NETIF_F_IP_CSUM */ | ||
880 | descr->dmac_cmd_status = SPIDER_NET_DMAC_CMDSTAT_NOCS; | ||
881 | } | ||
882 | } | ||
883 | } | ||
884 | |||
885 | /** | ||
886 | * spider_net_prepare_tx_descr - fill tx descriptor with skb data | ||
887 | * @card: card structure | ||
888 | * @descr: descriptor structure to fill out | ||
889 | * @skb: packet to use | ||
890 | * | ||
891 | * returns 0 on success, <0 on failure. | ||
892 | * | ||
893 | * fills out the descriptor structure with skb data and len. Copies data, | ||
894 | * if needed (32bit DMA!) | ||
895 | */ | ||
896 | static int | ||
897 | spider_net_prepare_tx_descr(struct spider_net_card *card, | ||
898 | struct spider_net_descr *descr, | ||
899 | struct sk_buff *skb) | ||
900 | { | ||
901 | descr->buf_addr = pci_map_single(card->pdev, skb->data, | ||
902 | skb->len, PCI_DMA_BIDIRECTIONAL); | ||
903 | if (descr->buf_addr == DMA_ERROR_CODE) { | ||
904 | if (netif_msg_tx_err(card)) | ||
905 | pr_err("could not iommu-map packet (%p, %i). " | ||
906 | "Dropping packet\n", skb->data, skb->len); | ||
907 | return -ENOMEM; | ||
908 | } | ||
909 | |||
910 | descr->buf_size = skb->len; | ||
911 | descr->skb = skb; | ||
912 | descr->data_status = 0; | ||
913 | |||
914 | /* make sure the above values are in memory before we change the | ||
915 | * status */ | ||
916 | wmb(); | ||
917 | |||
918 | spider_net_set_txdescr_cmdstat(descr,skb); | ||
919 | |||
920 | return 0; | ||
921 | } | ||
922 | |||
923 | /** | ||
924 | * spider_net_kick_tx_dma - enables TX DMA processing | ||
925 | * @card: card structure | ||
926 | * @descr: descriptor address to enable TX processing at | ||
927 | * | ||
928 | * spider_net_kick_tx_dma writes the current tx chain head as start address | ||
929 | * of the tx descriptor chain and enables the transmission DMA engine | ||
930 | */ | ||
931 | static void | ||
932 | spider_net_kick_tx_dma(struct spider_net_card *card, | ||
933 | struct spider_net_descr *descr) | ||
934 | { | ||
935 | /* this is the only descriptor in the output chain. | ||
936 | * Enable TX DMA */ | ||
937 | |||
938 | spider_net_write_reg(card, SPIDER_NET_GDTDCHA, | ||
939 | descr->bus_addr); | ||
940 | |||
941 | spider_net_write_reg(card, SPIDER_NET_GDTDMACCNTR, | ||
942 | SPIDER_NET_DMA_TX_VALUE); | ||
943 | } | ||
944 | |||
945 | /** | ||
946 | * spider_net_xmit - transmits a frame over the device | ||
947 | * @skb: packet to send out | ||
948 | * @netdev: interface device structure | ||
949 | * | ||
950 | * returns 0 on success, <0 on failure | ||
951 | */ | ||
952 | static int | ||
953 | spider_net_xmit(struct sk_buff *skb, struct net_device *netdev) | ||
954 | { | ||
955 | struct spider_net_card *card = netdev_priv(netdev); | ||
956 | struct spider_net_descr *descr; | ||
957 | int result; | ||
958 | |||
959 | descr = spider_net_get_next_tx_descr(card); | ||
960 | |||
961 | if (!descr) { | ||
962 | netif_stop_queue(netdev); | ||
963 | |||
964 | descr = spider_net_get_next_tx_descr(card); | ||
965 | if (!descr) | ||
966 | goto error; | ||
967 | else | ||
968 | netif_start_queue(netdev); | ||
969 | } | ||
970 | |||
971 | result = spider_net_prepare_tx_descr(card, descr, skb); | ||
972 | if (result) | ||
973 | goto error; | ||
974 | |||
975 | card->tx_chain.head = card->tx_chain.head->next; | ||
976 | |||
977 | /* make sure the status from spider_net_prepare_tx_descr is in | ||
978 | * memory before we check out the previous descriptor */ | ||
979 | wmb(); | ||
980 | |||
981 | if (spider_net_get_descr_status(descr->prev) != | ||
982 | SPIDER_NET_DESCR_CARDOWNED) | ||
983 | spider_net_kick_tx_dma(card, descr); | ||
984 | |||
985 | return NETDEV_TX_OK; | ||
986 | |||
987 | error: | ||
988 | card->netdev_stats.tx_dropped++; | ||
989 | return NETDEV_TX_LOCKED; | ||
990 | } | ||
991 | |||
992 | /** | ||
993 | * spider_net_do_ioctl - called for device ioctls | ||
994 | * @netdev: interface device structure | ||
995 | * @ifr: request parameter structure for ioctl | ||
996 | * @cmd: command code for ioctl | ||
997 | * | ||
998 | * returns 0 on success, <0 on failure. Currently, we have no special ioctls. | ||
999 | * -EOPNOTSUPP is returned, if an unknown ioctl was requested | ||
1000 | */ | ||
1001 | static int | ||
1002 | spider_net_do_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd) | ||
1003 | { | ||
1004 | switch (cmd) { | ||
1005 | default: | ||
1006 | return -EOPNOTSUPP; | ||
1007 | } | ||
1008 | } | ||
1009 | |||
1010 | /** | ||
1011 | * spider_net_pass_skb_up - takes an skb from a descriptor and passes it on | ||
1012 | * @descr: descriptor to process | ||
1013 | * @card: card structure | ||
1014 | * | ||
1015 | * returns 1 on success, 0 if no packet was passed to the stack | ||
1016 | * | ||
1017 | * iommu-unmaps the skb, fills out skb structure and passes the data to the | ||
1018 | * stack. The descriptor state is not changed. | ||
1019 | */ | ||
1020 | static int | ||
1021 | spider_net_pass_skb_up(struct spider_net_descr *descr, | ||
1022 | struct spider_net_card *card) | ||
1023 | { | ||
1024 | struct sk_buff *skb; | ||
1025 | struct net_device *netdev; | ||
1026 | u32 data_status, data_error; | ||
1027 | |||
1028 | data_status = descr->data_status; | ||
1029 | data_error = descr->data_error; | ||
1030 | |||
1031 | netdev = card->netdev; | ||
1032 | |||
1033 | /* check for errors in the data_error flag */ | ||
1034 | if ((data_error & SPIDER_NET_DATA_ERROR_MASK) && | ||
1035 | netif_msg_rx_err(card)) | ||
1036 | pr_err("error in received descriptor found, " | ||
1037 | "data_status=x%08x, data_error=x%08x\n", | ||
1038 | data_status, data_error); | ||
1039 | |||
1040 | /* prepare skb, unmap descriptor */ | ||
1041 | skb = descr->skb; | ||
1042 | pci_unmap_single(card->pdev, descr->buf_addr, SPIDER_NET_MAX_MTU, | ||
1043 | PCI_DMA_BIDIRECTIONAL); | ||
1044 | |||
1045 | /* the cases we'll throw away the packet immediately */ | ||
1046 | if (data_error & SPIDER_NET_DESTROY_RX_FLAGS) | ||
1047 | return 0; | ||
1048 | |||
1049 | skb->dev = netdev; | ||
1050 | skb_put(skb, descr->valid_size); | ||
1051 | |||
1052 | /* the card seems to add 2 bytes of junk in front | ||
1053 | * of the ethernet frame */ | ||
1054 | #define SPIDER_MISALIGN 2 | ||
1055 | skb_pull(skb, SPIDER_MISALIGN); | ||
1056 | skb->protocol = eth_type_trans(skb, netdev); | ||
1057 | |||
1058 | /* checksum offload */ | ||
1059 | if (card->options.rx_csum) { | ||
1060 | if ( (data_status & SPIDER_NET_DATA_STATUS_CHK_MASK) && | ||
1061 | (!(data_error & SPIDER_NET_DATA_ERROR_CHK_MASK)) ) | ||
1062 | skb->ip_summed = CHECKSUM_UNNECESSARY; | ||
1063 | else | ||
1064 | skb->ip_summed = CHECKSUM_NONE; | ||
1065 | } else { | ||
1066 | skb->ip_summed = CHECKSUM_NONE; | ||
1067 | } | ||
1068 | |||
1069 | if (data_status & SPIDER_NET_VLAN_PACKET) { | ||
1070 | /* further enhancements: HW-accel VLAN | ||
1071 | * vlan_hwaccel_receive_skb | ||
1072 | */ | ||
1073 | } | ||
1074 | |||
1075 | /* pass skb up to stack */ | ||
1076 | netif_receive_skb(skb); | ||
1077 | |||
1078 | /* update netdevice statistics */ | ||
1079 | card->netdev_stats.rx_packets++; | ||
1080 | card->netdev_stats.rx_bytes += skb->len; | ||
1081 | |||
1082 | return 1; | ||
1083 | } | ||
1084 | |||
1085 | /** | ||
1086 | * spider_net_decode_descr - processes an rx descriptor | ||
1087 | * @card: card structure | ||
1088 | * | ||
1089 | * returns 1 if a packet has been sent to the stack, otherwise 0 | ||
1090 | * | ||
1091 | * processes an rx descriptor by iommu-unmapping the data buffer and passing | ||
1092 | * the packet up to the stack | ||
1093 | */ | ||
1094 | static int | ||
1095 | spider_net_decode_one_descr(struct spider_net_card *card) | ||
1096 | { | ||
1097 | enum spider_net_descr_status status; | ||
1098 | struct spider_net_descr *descr; | ||
1099 | struct spider_net_descr_chain *chain; | ||
1100 | int result; | ||
1101 | |||
1102 | chain = &card->rx_chain; | ||
1103 | descr = chain->tail; | ||
1104 | |||
1105 | status = spider_net_get_descr_status(descr); | ||
1106 | |||
1107 | if (status == SPIDER_NET_DESCR_CARDOWNED) { | ||
1108 | /* nothing in the descriptor yet */ | ||
1109 | return 0; | ||
1110 | } | ||
1111 | |||
1112 | if (status == SPIDER_NET_DESCR_NOT_IN_USE) { | ||
1113 | /* not initialized yet, I bet chain->tail == chain->head | ||
1114 | * and the ring is empty */ | ||
1115 | spider_net_refill_rx_chain(card); | ||
1116 | return 0; | ||
1117 | } | ||
1118 | |||
1119 | /* descriptor definitively used -- move on head */ | ||
1120 | chain->tail = descr->next; | ||
1121 | |||
1122 | result = 0; | ||
1123 | if ( (status == SPIDER_NET_DESCR_RESPONSE_ERROR) || | ||
1124 | (status == SPIDER_NET_DESCR_PROTECTION_ERROR) || | ||
1125 | (status == SPIDER_NET_DESCR_FORCE_END) ) { | ||
1126 | if (netif_msg_rx_err(card)) | ||
1127 | pr_err("%s: dropping RX descriptor with state %d\n", | ||
1128 | card->netdev->name, status); | ||
1129 | card->netdev_stats.rx_dropped++; | ||
1130 | goto refill; | ||
1131 | } | ||
1132 | |||
1133 | if ( (status != SPIDER_NET_DESCR_COMPLETE) && | ||
1134 | (status != SPIDER_NET_DESCR_FRAME_END) ) { | ||
1135 | if (netif_msg_rx_err(card)) | ||
1136 | pr_err("%s: RX descriptor with state %d\n", | ||
1137 | card->netdev->name, status); | ||
1138 | goto refill; | ||
1139 | } | ||
1140 | |||
1141 | /* ok, we've got a packet in descr */ | ||
1142 | result = spider_net_pass_skb_up(descr, card); | ||
1143 | refill: | ||
1144 | spider_net_set_descr_status(descr, SPIDER_NET_DESCR_NOT_IN_USE); | ||
1145 | /* change the descriptor state: */ | ||
1146 | spider_net_refill_rx_chain(card); | ||
1147 | |||
1148 | return result; | ||
1149 | } | ||
1150 | |||
1151 | /** | ||
1152 | * spider_net_poll - NAPI poll function called by the stack to return packets | ||
1153 | * @netdev: interface device structure | ||
1154 | * @budget: number of packets we can pass to the stack at most | ||
1155 | * | ||
1156 | * returns 0 if no more packets available to the driver/stack. Returns 1, | ||
1157 | * if the quota is exceeded, but the driver has still packets. | ||
1158 | * | ||
1159 | * spider_net_poll returns all packets from the rx descriptors to the stack | ||
1160 | * (using netif_receive_skb). If all/enough packets are up, the driver | ||
1161 | * reenables interrupts and returns 0. If not, 1 is returned. | ||
1162 | */ | ||
1163 | static int | ||
1164 | spider_net_poll(struct net_device *netdev, int *budget) | ||
1165 | { | ||
1166 | struct spider_net_card *card = netdev_priv(netdev); | ||
1167 | int packets_to_do, packets_done = 0; | ||
1168 | int no_more_packets = 0; | ||
1169 | |||
1170 | packets_to_do = min(*budget, netdev->quota); | ||
1171 | |||
1172 | while (packets_to_do) { | ||
1173 | if (spider_net_decode_one_descr(card)) { | ||
1174 | packets_done++; | ||
1175 | packets_to_do--; | ||
1176 | } else { | ||
1177 | /* no more packets for the stack */ | ||
1178 | no_more_packets = 1; | ||
1179 | break; | ||
1180 | } | ||
1181 | } | ||
1182 | |||
1183 | netdev->quota -= packets_done; | ||
1184 | *budget -= packets_done; | ||
1185 | |||
1186 | /* if all packets are in the stack, enable interrupts and return 0 */ | ||
1187 | /* if not, return 1 */ | ||
1188 | if (no_more_packets) { | ||
1189 | netif_rx_complete(netdev); | ||
1190 | spider_net_rx_irq_on(card); | ||
1191 | return 0; | ||
1192 | } | ||
1193 | |||
1194 | return 1; | ||
1195 | } | ||
1196 | |||
1197 | /** | ||
1198 | * spider_net_vlan_rx_reg - initializes VLAN structures in the driver and card | ||
1199 | * @netdev: interface device structure | ||
1200 | * @grp: vlan_group structure that is registered (NULL on destroying interface) | ||
1201 | */ | ||
1202 | static void | ||
1203 | spider_net_vlan_rx_reg(struct net_device *netdev, struct vlan_group *grp) | ||
1204 | { | ||
1205 | /* further enhancement... yet to do */ | ||
1206 | return; | ||
1207 | } | ||
1208 | |||
1209 | /** | ||
1210 | * spider_net_vlan_rx_add - adds VLAN id to the card filter | ||
1211 | * @netdev: interface device structure | ||
1212 | * @vid: VLAN id to add | ||
1213 | */ | ||
1214 | static void | ||
1215 | spider_net_vlan_rx_add(struct net_device *netdev, uint16_t vid) | ||
1216 | { | ||
1217 | /* further enhancement... yet to do */ | ||
1218 | /* add vid to card's VLAN filter table */ | ||
1219 | return; | ||
1220 | } | ||
1221 | |||
1222 | /** | ||
1223 | * spider_net_vlan_rx_kill - removes VLAN id to the card filter | ||
1224 | * @netdev: interface device structure | ||
1225 | * @vid: VLAN id to remove | ||
1226 | */ | ||
1227 | static void | ||
1228 | spider_net_vlan_rx_kill(struct net_device *netdev, uint16_t vid) | ||
1229 | { | ||
1230 | /* further enhancement... yet to do */ | ||
1231 | /* remove vid from card's VLAN filter table */ | ||
1232 | } | ||
1233 | |||
1234 | /** | ||
1235 | * spider_net_get_stats - get interface statistics | ||
1236 | * @netdev: interface device structure | ||
1237 | * | ||
1238 | * returns the interface statistics residing in the spider_net_card struct | ||
1239 | */ | ||
1240 | static struct net_device_stats * | ||
1241 | spider_net_get_stats(struct net_device *netdev) | ||
1242 | { | ||
1243 | struct spider_net_card *card = netdev_priv(netdev); | ||
1244 | struct net_device_stats *stats = &card->netdev_stats; | ||
1245 | return stats; | ||
1246 | } | ||
1247 | |||
1248 | /** | ||
1249 | * spider_net_change_mtu - changes the MTU of an interface | ||
1250 | * @netdev: interface device structure | ||
1251 | * @new_mtu: new MTU value | ||
1252 | * | ||
1253 | * returns 0 on success, <0 on failure | ||
1254 | */ | ||
1255 | static int | ||
1256 | spider_net_change_mtu(struct net_device *netdev, int new_mtu) | ||
1257 | { | ||
1258 | /* no need to re-alloc skbs or so -- the max mtu is about 2.3k | ||
1259 | * and mtu is outbound only anyway */ | ||
1260 | if ( (new_mtu < SPIDER_NET_MIN_MTU ) || | ||
1261 | (new_mtu > SPIDER_NET_MAX_MTU) ) | ||
1262 | return -EINVAL; | ||
1263 | netdev->mtu = new_mtu; | ||
1264 | return 0; | ||
1265 | } | ||
1266 | |||
1267 | /** | ||
1268 | * spider_net_set_mac - sets the MAC of an interface | ||
1269 | * @netdev: interface device structure | ||
1270 | * @ptr: pointer to new MAC address | ||
1271 | * | ||
1272 | * Returns 0 on success, <0 on failure. Currently, we don't support this | ||
1273 | * and will always return EOPNOTSUPP. | ||
1274 | */ | ||
1275 | static int | ||
1276 | spider_net_set_mac(struct net_device *netdev, void *p) | ||
1277 | { | ||
1278 | struct spider_net_card *card = netdev_priv(netdev); | ||
1279 | u32 macl, macu; | ||
1280 | struct sockaddr *addr = p; | ||
1281 | |||
1282 | /* GMACTPE and GMACRPE must be off, so we only allow this, if | ||
1283 | * the device is down */ | ||
1284 | if (netdev->flags & IFF_UP) | ||
1285 | return -EBUSY; | ||
1286 | |||
1287 | if (!is_valid_ether_addr(addr->sa_data)) | ||
1288 | return -EADDRNOTAVAIL; | ||
1289 | |||
1290 | macu = (addr->sa_data[0]<<24) + (addr->sa_data[1]<<16) + | ||
1291 | (addr->sa_data[2]<<8) + (addr->sa_data[3]); | ||
1292 | macl = (addr->sa_data[4]<<8) + (addr->sa_data[5]); | ||
1293 | spider_net_write_reg(card, SPIDER_NET_GMACUNIMACU, macu); | ||
1294 | spider_net_write_reg(card, SPIDER_NET_GMACUNIMACL, macl); | ||
1295 | |||
1296 | spider_net_set_promisc(card); | ||
1297 | |||
1298 | /* look up, whether we have been successful */ | ||
1299 | if (spider_net_get_mac_address(netdev)) | ||
1300 | return -EADDRNOTAVAIL; | ||
1301 | if (memcmp(netdev->dev_addr,addr->sa_data,netdev->addr_len)) | ||
1302 | return -EADDRNOTAVAIL; | ||
1303 | |||
1304 | return 0; | ||
1305 | } | ||
1306 | |||
1307 | /** | ||
1308 | * spider_net_enable_txdmac - enables a TX DMA controller | ||
1309 | * @card: card structure | ||
1310 | * | ||
1311 | * spider_net_enable_txdmac enables the TX DMA controller by setting the | ||
1312 | * descriptor chain tail address | ||
1313 | */ | ||
1314 | static void | ||
1315 | spider_net_enable_txdmac(struct spider_net_card *card) | ||
1316 | { | ||
1317 | /* assume chain is aligned correctly */ | ||
1318 | spider_net_write_reg(card, SPIDER_NET_GDTDCHA, | ||
1319 | card->tx_chain.tail->bus_addr); | ||
1320 | } | ||
1321 | |||
1322 | /** | ||
1323 | * spider_net_handle_error_irq - handles errors raised by an interrupt | ||
1324 | * @card: card structure | ||
1325 | * @status_reg: interrupt status register 0 (GHIINT0STS) | ||
1326 | * | ||
1327 | * spider_net_handle_error_irq treats or ignores all error conditions | ||
1328 | * found when an interrupt is presented | ||
1329 | */ | ||
1330 | static void | ||
1331 | spider_net_handle_error_irq(struct spider_net_card *card, u32 status_reg) | ||
1332 | { | ||
1333 | u32 error_reg1, error_reg2; | ||
1334 | u32 i; | ||
1335 | int show_error = 1; | ||
1336 | |||
1337 | error_reg1 = spider_net_read_reg(card, SPIDER_NET_GHIINT1STS); | ||
1338 | error_reg2 = spider_net_read_reg(card, SPIDER_NET_GHIINT2STS); | ||
1339 | |||
1340 | /* check GHIINT0STS ************************************/ | ||
1341 | if (status_reg) | ||
1342 | for (i = 0; i < 32; i++) | ||
1343 | if (status_reg & (1<<i)) | ||
1344 | switch (i) | ||
1345 | { | ||
1346 | /* let error_reg1 and error_reg2 evaluation decide, what to do | ||
1347 | case SPIDER_NET_PHYINT: | ||
1348 | case SPIDER_NET_GMAC2INT: | ||
1349 | case SPIDER_NET_GMAC1INT: | ||
1350 | case SPIDER_NET_GIPSINT: | ||
1351 | case SPIDER_NET_GFIFOINT: | ||
1352 | case SPIDER_NET_DMACINT: | ||
1353 | case SPIDER_NET_GSYSINT: | ||
1354 | break; */ | ||
1355 | |||
1356 | case SPIDER_NET_GPWOPCMPINT: | ||
1357 | /* PHY write operation completed */ | ||
1358 | show_error = 0; | ||
1359 | break; | ||
1360 | case SPIDER_NET_GPROPCMPINT: | ||
1361 | /* PHY read operation completed */ | ||
1362 | /* we don't use semaphores, as we poll for the completion | ||
1363 | * of the read operation in spider_net_read_phy. Should take | ||
1364 | * about 50 us */ | ||
1365 | show_error = 0; | ||
1366 | break; | ||
1367 | case SPIDER_NET_GPWFFINT: | ||
1368 | /* PHY command queue full */ | ||
1369 | if (netif_msg_intr(card)) | ||
1370 | pr_err("PHY write queue full\n"); | ||
1371 | show_error = 0; | ||
1372 | break; | ||
1373 | |||
1374 | /* case SPIDER_NET_GRMDADRINT: not used. print a message */ | ||
1375 | /* case SPIDER_NET_GRMARPINT: not used. print a message */ | ||
1376 | /* case SPIDER_NET_GRMMPINT: not used. print a message */ | ||
1377 | |||
1378 | case SPIDER_NET_GDTDEN0INT: | ||
1379 | /* someone has set TX_DMA_EN to 0 */ | ||
1380 | show_error = 0; | ||
1381 | break; | ||
1382 | |||
1383 | case SPIDER_NET_GDDDEN0INT: /* fallthrough */ | ||
1384 | case SPIDER_NET_GDCDEN0INT: /* fallthrough */ | ||
1385 | case SPIDER_NET_GDBDEN0INT: /* fallthrough */ | ||
1386 | case SPIDER_NET_GDADEN0INT: | ||
1387 | /* someone has set RX_DMA_EN to 0 */ | ||
1388 | show_error = 0; | ||
1389 | break; | ||
1390 | |||
1391 | /* RX interrupts */ | ||
1392 | case SPIDER_NET_GDDFDCINT: | ||
1393 | case SPIDER_NET_GDCFDCINT: | ||
1394 | case SPIDER_NET_GDBFDCINT: | ||
1395 | case SPIDER_NET_GDAFDCINT: | ||
1396 | /* case SPIDER_NET_GDNMINT: not used. print a message */ | ||
1397 | /* case SPIDER_NET_GCNMINT: not used. print a message */ | ||
1398 | /* case SPIDER_NET_GBNMINT: not used. print a message */ | ||
1399 | /* case SPIDER_NET_GANMINT: not used. print a message */ | ||
1400 | /* case SPIDER_NET_GRFNMINT: not used. print a message */ | ||
1401 | show_error = 0; | ||
1402 | break; | ||
1403 | |||
1404 | /* TX interrupts */ | ||
1405 | case SPIDER_NET_GDTFDCINT: | ||
1406 | show_error = 0; | ||
1407 | break; | ||
1408 | case SPIDER_NET_GTTEDINT: | ||
1409 | show_error = 0; | ||
1410 | break; | ||
1411 | case SPIDER_NET_GDTDCEINT: | ||
1412 | /* chain end. If a descriptor should be sent, kick off | ||
1413 | * tx dma | ||
1414 | if (card->tx_chain.tail == card->tx_chain.head) | ||
1415 | spider_net_kick_tx_dma(card); | ||
1416 | show_error = 0; */ | ||
1417 | break; | ||
1418 | |||
1419 | /* case SPIDER_NET_G1TMCNTINT: not used. print a message */ | ||
1420 | /* case SPIDER_NET_GFREECNTINT: not used. print a message */ | ||
1421 | } | ||
1422 | |||
1423 | /* check GHIINT1STS ************************************/ | ||
1424 | if (error_reg1) | ||
1425 | for (i = 0; i < 32; i++) | ||
1426 | if (error_reg1 & (1<<i)) | ||
1427 | switch (i) | ||
1428 | { | ||
1429 | case SPIDER_NET_GTMFLLINT: | ||
1430 | if (netif_msg_intr(card)) | ||
1431 | pr_err("Spider TX RAM full\n"); | ||
1432 | show_error = 0; | ||
1433 | break; | ||
1434 | case SPIDER_NET_GRMFLLINT: | ||
1435 | if (netif_msg_intr(card)) | ||
1436 | pr_err("Spider RX RAM full, incoming packets " | ||
1437 | "might be discarded !\n"); | ||
1438 | netif_rx_schedule(card->netdev); | ||
1439 | spider_net_enable_rxchtails(card); | ||
1440 | spider_net_enable_rxdmac(card); | ||
1441 | break; | ||
1442 | |||
1443 | /* case SPIDER_NET_GTMSHTINT: problem, print a message */ | ||
1444 | case SPIDER_NET_GDTINVDINT: | ||
1445 | /* allrighty. tx from previous descr ok */ | ||
1446 | show_error = 0; | ||
1447 | break; | ||
1448 | /* case SPIDER_NET_GRFDFLLINT: print a message down there */ | ||
1449 | /* case SPIDER_NET_GRFCFLLINT: print a message down there */ | ||
1450 | /* case SPIDER_NET_GRFBFLLINT: print a message down there */ | ||
1451 | /* case SPIDER_NET_GRFAFLLINT: print a message down there */ | ||
1452 | |||
1453 | /* chain end */ | ||
1454 | case SPIDER_NET_GDDDCEINT: /* fallthrough */ | ||
1455 | case SPIDER_NET_GDCDCEINT: /* fallthrough */ | ||
1456 | case SPIDER_NET_GDBDCEINT: /* fallthrough */ | ||
1457 | case SPIDER_NET_GDADCEINT: | ||
1458 | if (netif_msg_intr(card)) | ||
1459 | pr_err("got descriptor chain end interrupt, " | ||
1460 | "restarting DMAC %c.\n", | ||
1461 | 'D'+i-SPIDER_NET_GDDDCEINT); | ||
1462 | spider_net_refill_rx_chain(card); | ||
1463 | show_error = 0; | ||
1464 | break; | ||
1465 | |||
1466 | /* invalid descriptor */ | ||
1467 | case SPIDER_NET_GDDINVDINT: /* fallthrough */ | ||
1468 | case SPIDER_NET_GDCINVDINT: /* fallthrough */ | ||
1469 | case SPIDER_NET_GDBINVDINT: /* fallthrough */ | ||
1470 | case SPIDER_NET_GDAINVDINT: | ||
1471 | /* could happen when rx chain is full */ | ||
1472 | spider_net_refill_rx_chain(card); | ||
1473 | show_error = 0; | ||
1474 | break; | ||
1475 | |||
1476 | /* case SPIDER_NET_GDTRSERINT: problem, print a message */ | ||
1477 | /* case SPIDER_NET_GDDRSERINT: problem, print a message */ | ||
1478 | /* case SPIDER_NET_GDCRSERINT: problem, print a message */ | ||
1479 | /* case SPIDER_NET_GDBRSERINT: problem, print a message */ | ||
1480 | /* case SPIDER_NET_GDARSERINT: problem, print a message */ | ||
1481 | /* case SPIDER_NET_GDSERINT: problem, print a message */ | ||
1482 | /* case SPIDER_NET_GDTPTERINT: problem, print a message */ | ||
1483 | /* case SPIDER_NET_GDDPTERINT: problem, print a message */ | ||
1484 | /* case SPIDER_NET_GDCPTERINT: problem, print a message */ | ||
1485 | /* case SPIDER_NET_GDBPTERINT: problem, print a message */ | ||
1486 | /* case SPIDER_NET_GDAPTERINT: problem, print a message */ | ||
1487 | default: | ||
1488 | show_error = 1; | ||
1489 | break; | ||
1490 | } | ||
1491 | |||
1492 | /* check GHIINT2STS ************************************/ | ||
1493 | if (error_reg2) | ||
1494 | for (i = 0; i < 32; i++) | ||
1495 | if (error_reg2 & (1<<i)) | ||
1496 | switch (i) | ||
1497 | { | ||
1498 | /* there is nothing we can (want to) do at this time. Log a | ||
1499 | * message, we can switch on and off the specific values later on | ||
1500 | case SPIDER_NET_GPROPERINT: | ||
1501 | case SPIDER_NET_GMCTCRSNGINT: | ||
1502 | case SPIDER_NET_GMCTLCOLINT: | ||
1503 | case SPIDER_NET_GMCTTMOTINT: | ||
1504 | case SPIDER_NET_GMCRCAERINT: | ||
1505 | case SPIDER_NET_GMCRCALERINT: | ||
1506 | case SPIDER_NET_GMCRALNERINT: | ||
1507 | case SPIDER_NET_GMCROVRINT: | ||
1508 | case SPIDER_NET_GMCRRNTINT: | ||
1509 | case SPIDER_NET_GMCRRXERINT: | ||
1510 | case SPIDER_NET_GTITCSERINT: | ||
1511 | case SPIDER_NET_GTIFMTERINT: | ||
1512 | case SPIDER_NET_GTIPKTRVKINT: | ||
1513 | case SPIDER_NET_GTISPINGINT: | ||
1514 | case SPIDER_NET_GTISADNGINT: | ||
1515 | case SPIDER_NET_GTISPDNGINT: | ||
1516 | case SPIDER_NET_GRIFMTERINT: | ||
1517 | case SPIDER_NET_GRIPKTRVKINT: | ||
1518 | case SPIDER_NET_GRISPINGINT: | ||
1519 | case SPIDER_NET_GRISADNGINT: | ||
1520 | case SPIDER_NET_GRISPDNGINT: | ||
1521 | break; | ||
1522 | */ | ||
1523 | default: | ||
1524 | break; | ||
1525 | } | ||
1526 | |||
1527 | if ((show_error) && (netif_msg_intr(card))) | ||
1528 | pr_err("Got error interrupt, GHIINT0STS = 0x%08x, " | ||
1529 | "GHIINT1STS = 0x%08x, GHIINT2STS = 0x%08x\n", | ||
1530 | status_reg, error_reg1, error_reg2); | ||
1531 | |||
1532 | /* clear interrupt sources */ | ||
1533 | spider_net_write_reg(card, SPIDER_NET_GHIINT1STS, error_reg1); | ||
1534 | spider_net_write_reg(card, SPIDER_NET_GHIINT2STS, error_reg2); | ||
1535 | } | ||
1536 | |||
1537 | /** | ||
1538 | * spider_net_interrupt - interrupt handler for spider_net | ||
1539 | * @irq: interupt number | ||
1540 | * @ptr: pointer to net_device | ||
1541 | * @regs: PU registers | ||
1542 | * | ||
1543 | * returns IRQ_HANDLED, if interrupt was for driver, or IRQ_NONE, if no | ||
1544 | * interrupt found raised by card. | ||
1545 | * | ||
1546 | * This is the interrupt handler, that turns off | ||
1547 | * interrupts for this device and makes the stack poll the driver | ||
1548 | */ | ||
1549 | static irqreturn_t | ||
1550 | spider_net_interrupt(int irq, void *ptr, struct pt_regs *regs) | ||
1551 | { | ||
1552 | struct net_device *netdev = ptr; | ||
1553 | struct spider_net_card *card = netdev_priv(netdev); | ||
1554 | u32 status_reg; | ||
1555 | |||
1556 | status_reg = spider_net_read_reg(card, SPIDER_NET_GHIINT0STS); | ||
1557 | |||
1558 | if (!status_reg) | ||
1559 | return IRQ_NONE; | ||
1560 | |||
1561 | if (status_reg & SPIDER_NET_TXINT) | ||
1562 | spider_net_release_tx_chain(card, 0); | ||
1563 | |||
1564 | if (status_reg & SPIDER_NET_RXINT ) { | ||
1565 | spider_net_rx_irq_off(card); | ||
1566 | netif_rx_schedule(netdev); | ||
1567 | } | ||
1568 | |||
1569 | /* we do this after rx and tx processing, as we want the tx chain | ||
1570 | * processed to see, whether we should restart tx dma processing */ | ||
1571 | spider_net_handle_error_irq(card, status_reg); | ||
1572 | |||
1573 | /* clear interrupt sources */ | ||
1574 | spider_net_write_reg(card, SPIDER_NET_GHIINT0STS, status_reg); | ||
1575 | |||
1576 | return IRQ_HANDLED; | ||
1577 | } | ||
1578 | |||
1579 | #ifdef CONFIG_NET_POLL_CONTROLLER | ||
1580 | /** | ||
1581 | * spider_net_poll_controller - artificial interrupt for netconsole etc. | ||
1582 | * @netdev: interface device structure | ||
1583 | * | ||
1584 | * see Documentation/networking/netconsole.txt | ||
1585 | */ | ||
1586 | static void | ||
1587 | spider_net_poll_controller(struct net_device *netdev) | ||
1588 | { | ||
1589 | disable_irq(netdev->irq); | ||
1590 | spider_net_interrupt(netdev->irq, netdev, NULL); | ||
1591 | enable_irq(netdev->irq); | ||
1592 | } | ||
1593 | #endif /* CONFIG_NET_POLL_CONTROLLER */ | ||
1594 | |||
1595 | /** | ||
1596 | * spider_net_init_card - initializes the card | ||
1597 | * @card: card structure | ||
1598 | * | ||
1599 | * spider_net_init_card initializes the card so that other registers can | ||
1600 | * be used | ||
1601 | */ | ||
1602 | static void | ||
1603 | spider_net_init_card(struct spider_net_card *card) | ||
1604 | { | ||
1605 | spider_net_write_reg(card, SPIDER_NET_CKRCTRL, | ||
1606 | SPIDER_NET_CKRCTRL_STOP_VALUE); | ||
1607 | |||
1608 | spider_net_write_reg(card, SPIDER_NET_CKRCTRL, | ||
1609 | SPIDER_NET_CKRCTRL_RUN_VALUE); | ||
1610 | } | ||
1611 | |||
1612 | /** | ||
1613 | * spider_net_enable_card - enables the card by setting all kinds of regs | ||
1614 | * @card: card structure | ||
1615 | * | ||
1616 | * spider_net_enable_card sets a lot of SMMIO registers to enable the device | ||
1617 | */ | ||
1618 | static void | ||
1619 | spider_net_enable_card(struct spider_net_card *card) | ||
1620 | { | ||
1621 | int i; | ||
1622 | /* the following array consists of (register),(value) pairs | ||
1623 | * that are set in this function. A register of 0 ends the list */ | ||
1624 | u32 regs[][2] = { | ||
1625 | { SPIDER_NET_GRESUMINTNUM, 0 }, | ||
1626 | { SPIDER_NET_GREINTNUM, 0 }, | ||
1627 | |||
1628 | /* set interrupt frame number registers */ | ||
1629 | /* clear the single DMA engine registers first */ | ||
1630 | { SPIDER_NET_GFAFRMNUM, SPIDER_NET_GFXFRAMES_VALUE }, | ||
1631 | { SPIDER_NET_GFBFRMNUM, SPIDER_NET_GFXFRAMES_VALUE }, | ||
1632 | { SPIDER_NET_GFCFRMNUM, SPIDER_NET_GFXFRAMES_VALUE }, | ||
1633 | { SPIDER_NET_GFDFRMNUM, SPIDER_NET_GFXFRAMES_VALUE }, | ||
1634 | /* then set, what we really need */ | ||
1635 | { SPIDER_NET_GFFRMNUM, SPIDER_NET_FRAMENUM_VALUE }, | ||
1636 | |||
1637 | /* timer counter registers and stuff */ | ||
1638 | { SPIDER_NET_GFREECNNUM, 0 }, | ||
1639 | { SPIDER_NET_GONETIMENUM, 0 }, | ||
1640 | { SPIDER_NET_GTOUTFRMNUM, 0 }, | ||
1641 | |||
1642 | /* RX mode setting */ | ||
1643 | { SPIDER_NET_GRXMDSET, SPIDER_NET_RXMODE_VALUE }, | ||
1644 | /* TX mode setting */ | ||
1645 | { SPIDER_NET_GTXMDSET, SPIDER_NET_TXMODE_VALUE }, | ||
1646 | /* IPSEC mode setting */ | ||
1647 | { SPIDER_NET_GIPSECINIT, SPIDER_NET_IPSECINIT_VALUE }, | ||
1648 | |||
1649 | { SPIDER_NET_GFTRESTRT, SPIDER_NET_RESTART_VALUE }, | ||
1650 | |||
1651 | { SPIDER_NET_GMRWOLCTRL, 0 }, | ||
1652 | { SPIDER_NET_GTESTMD, 0 }, | ||
1653 | |||
1654 | { SPIDER_NET_GMACINTEN, 0 }, | ||
1655 | |||
1656 | /* flow control stuff */ | ||
1657 | { SPIDER_NET_GMACAPAUSE, SPIDER_NET_MACAPAUSE_VALUE }, | ||
1658 | { SPIDER_NET_GMACTXPAUSE, SPIDER_NET_TXPAUSE_VALUE }, | ||
1659 | |||
1660 | { SPIDER_NET_GMACBSTLMT, SPIDER_NET_BURSTLMT_VALUE }, | ||
1661 | { 0, 0} | ||
1662 | }; | ||
1663 | |||
1664 | i = 0; | ||
1665 | while (regs[i][0]) { | ||
1666 | spider_net_write_reg(card, regs[i][0], regs[i][1]); | ||
1667 | i++; | ||
1668 | } | ||
1669 | |||
1670 | /* clear unicast filter table entries 1 to 14 */ | ||
1671 | for (i = 1; i <= 14; i++) { | ||
1672 | spider_net_write_reg(card, | ||
1673 | SPIDER_NET_GMRUAFILnR + i * 8, | ||
1674 | 0x00080000); | ||
1675 | spider_net_write_reg(card, | ||
1676 | SPIDER_NET_GMRUAFILnR + i * 8 + 4, | ||
1677 | 0x00000000); | ||
1678 | } | ||
1679 | |||
1680 | spider_net_write_reg(card, SPIDER_NET_GMRUA0FIL15R, 0x08080000); | ||
1681 | |||
1682 | spider_net_write_reg(card, SPIDER_NET_ECMODE, SPIDER_NET_ECMODE_VALUE); | ||
1683 | |||
1684 | /* set chain tail adress for RX chains and | ||
1685 | * enable DMA */ | ||
1686 | spider_net_enable_rxchtails(card); | ||
1687 | spider_net_enable_rxdmac(card); | ||
1688 | |||
1689 | spider_net_write_reg(card, SPIDER_NET_GRXDMAEN, SPIDER_NET_WOL_VALUE); | ||
1690 | |||
1691 | /* set chain tail adress for TX chain */ | ||
1692 | spider_net_enable_txdmac(card); | ||
1693 | |||
1694 | spider_net_write_reg(card, SPIDER_NET_GMACLENLMT, | ||
1695 | SPIDER_NET_LENLMT_VALUE); | ||
1696 | spider_net_write_reg(card, SPIDER_NET_GMACMODE, | ||
1697 | SPIDER_NET_MACMODE_VALUE); | ||
1698 | spider_net_write_reg(card, SPIDER_NET_GMACOPEMD, | ||
1699 | SPIDER_NET_OPMODE_VALUE); | ||
1700 | |||
1701 | /* set interrupt mask registers */ | ||
1702 | spider_net_write_reg(card, SPIDER_NET_GHIINT0MSK, | ||
1703 | SPIDER_NET_INT0_MASK_VALUE); | ||
1704 | spider_net_write_reg(card, SPIDER_NET_GHIINT1MSK, | ||
1705 | SPIDER_NET_INT1_MASK_VALUE); | ||
1706 | spider_net_write_reg(card, SPIDER_NET_GHIINT2MSK, | ||
1707 | SPIDER_NET_INT2_MASK_VALUE); | ||
1708 | } | ||
1709 | |||
1710 | /** | ||
1711 | * spider_net_open - called upon ifonfig up | ||
1712 | * @netdev: interface device structure | ||
1713 | * | ||
1714 | * returns 0 on success, <0 on failure | ||
1715 | * | ||
1716 | * spider_net_open allocates all the descriptors and memory needed for | ||
1717 | * operation, sets up multicast list and enables interrupts | ||
1718 | */ | ||
1719 | int | ||
1720 | spider_net_open(struct net_device *netdev) | ||
1721 | { | ||
1722 | struct spider_net_card *card = netdev_priv(netdev); | ||
1723 | int result; | ||
1724 | |||
1725 | result = -ENOMEM; | ||
1726 | if (spider_net_init_chain(card, &card->tx_chain, | ||
1727 | card->descr, tx_descriptors)) | ||
1728 | goto alloc_tx_failed; | ||
1729 | if (spider_net_init_chain(card, &card->rx_chain, | ||
1730 | card->descr + tx_descriptors, rx_descriptors)) | ||
1731 | goto alloc_rx_failed; | ||
1732 | |||
1733 | /* allocate rx skbs */ | ||
1734 | if (spider_net_alloc_rx_skbs(card)) | ||
1735 | goto alloc_skbs_failed; | ||
1736 | |||
1737 | spider_net_set_multi(netdev); | ||
1738 | |||
1739 | /* further enhancement: setup hw vlan, if needed */ | ||
1740 | |||
1741 | result = -EBUSY; | ||
1742 | if (request_irq(netdev->irq, spider_net_interrupt, | ||
1743 | SA_SHIRQ, netdev->name, netdev)) | ||
1744 | goto register_int_failed; | ||
1745 | |||
1746 | spider_net_enable_card(card); | ||
1747 | |||
1748 | return 0; | ||
1749 | |||
1750 | register_int_failed: | ||
1751 | spider_net_free_rx_chain_contents(card); | ||
1752 | alloc_skbs_failed: | ||
1753 | spider_net_free_chain(card, &card->rx_chain); | ||
1754 | alloc_rx_failed: | ||
1755 | spider_net_free_chain(card, &card->tx_chain); | ||
1756 | alloc_tx_failed: | ||
1757 | return result; | ||
1758 | } | ||
1759 | |||
1760 | /** | ||
1761 | * spider_net_setup_phy - setup PHY | ||
1762 | * @card: card structure | ||
1763 | * | ||
1764 | * returns 0 on success, <0 on failure | ||
1765 | * | ||
1766 | * spider_net_setup_phy is used as part of spider_net_probe. Sets | ||
1767 | * the PHY to 1000 Mbps | ||
1768 | **/ | ||
1769 | static int | ||
1770 | spider_net_setup_phy(struct spider_net_card *card) | ||
1771 | { | ||
1772 | struct mii_phy *phy = &card->phy; | ||
1773 | |||
1774 | spider_net_write_reg(card, SPIDER_NET_GDTDMASEL, | ||
1775 | SPIDER_NET_DMASEL_VALUE); | ||
1776 | spider_net_write_reg(card, SPIDER_NET_GPCCTRL, | ||
1777 | SPIDER_NET_PHY_CTRL_VALUE); | ||
1778 | phy->mii_id = 1; | ||
1779 | phy->dev = card->netdev; | ||
1780 | phy->mdio_read = spider_net_read_phy; | ||
1781 | phy->mdio_write = spider_net_write_phy; | ||
1782 | |||
1783 | mii_phy_probe(phy, phy->mii_id); | ||
1784 | |||
1785 | if (phy->def->ops->setup_forced) | ||
1786 | phy->def->ops->setup_forced(phy, SPEED_1000, DUPLEX_FULL); | ||
1787 | |||
1788 | /* the following two writes could be moved to sungem_phy.c */ | ||
1789 | /* enable fiber mode */ | ||
1790 | spider_net_write_phy(card->netdev, 1, MII_NCONFIG, 0x9020); | ||
1791 | /* LEDs active in both modes, autosense prio = fiber */ | ||
1792 | spider_net_write_phy(card->netdev, 1, MII_NCONFIG, 0x945f); | ||
1793 | |||
1794 | phy->def->ops->read_link(phy); | ||
1795 | pr_info("Found %s with %i Mbps, %s-duplex.\n", phy->def->name, | ||
1796 | phy->speed, phy->duplex==1 ? "Full" : "Half"); | ||
1797 | |||
1798 | return 0; | ||
1799 | } | ||
1800 | |||
1801 | /** | ||
1802 | * spider_net_download_firmware - loads firmware into the adapter | ||
1803 | * @card: card structure | ||
1804 | * @firmware: firmware pointer | ||
1805 | * | ||
1806 | * spider_net_download_firmware loads the firmware opened by | ||
1807 | * spider_net_init_firmware into the adapter. | ||
1808 | */ | ||
1809 | static void | ||
1810 | spider_net_download_firmware(struct spider_net_card *card, | ||
1811 | const struct firmware *firmware) | ||
1812 | { | ||
1813 | int sequencer, i; | ||
1814 | u32 *fw_ptr = (u32 *)firmware->data; | ||
1815 | |||
1816 | /* stop sequencers */ | ||
1817 | spider_net_write_reg(card, SPIDER_NET_GSINIT, | ||
1818 | SPIDER_NET_STOP_SEQ_VALUE); | ||
1819 | |||
1820 | for (sequencer = 0; sequencer < 6; sequencer++) { | ||
1821 | spider_net_write_reg(card, | ||
1822 | SPIDER_NET_GSnPRGADR + sequencer * 8, 0); | ||
1823 | for (i = 0; i < SPIDER_NET_FIRMWARE_LEN; i++) { | ||
1824 | spider_net_write_reg(card, SPIDER_NET_GSnPRGDAT + | ||
1825 | sequencer * 8, *fw_ptr); | ||
1826 | fw_ptr++; | ||
1827 | } | ||
1828 | } | ||
1829 | |||
1830 | spider_net_write_reg(card, SPIDER_NET_GSINIT, | ||
1831 | SPIDER_NET_RUN_SEQ_VALUE); | ||
1832 | } | ||
1833 | |||
1834 | /** | ||
1835 | * spider_net_init_firmware - reads in firmware parts | ||
1836 | * @card: card structure | ||
1837 | * | ||
1838 | * Returns 0 on success, <0 on failure | ||
1839 | * | ||
1840 | * spider_net_init_firmware opens the sequencer firmware and does some basic | ||
1841 | * checks. This function opens and releases the firmware structure. A call | ||
1842 | * to download the firmware is performed before the release. | ||
1843 | * | ||
1844 | * Firmware format | ||
1845 | * =============== | ||
1846 | * spider_fw.bin is expected to be a file containing 6*1024*4 bytes, 4k being | ||
1847 | * the program for each sequencer. Use the command | ||
1848 | * tail -q -n +2 Seq_code1_0x088.txt Seq_code2_0x090.txt \ | ||
1849 | * Seq_code3_0x098.txt Seq_code4_0x0A0.txt Seq_code5_0x0A8.txt \ | ||
1850 | * Seq_code6_0x0B0.txt | xxd -r -p -c4 > spider_fw.bin | ||
1851 | * | ||
1852 | * to generate spider_fw.bin, if you have sequencer programs with something | ||
1853 | * like the following contents for each sequencer: | ||
1854 | * <ONE LINE COMMENT> | ||
1855 | * <FIRST 4-BYTES-WORD FOR SEQUENCER> | ||
1856 | * <SECOND 4-BYTES-WORD FOR SEQUENCER> | ||
1857 | * ... | ||
1858 | * <1024th 4-BYTES-WORD FOR SEQUENCER> | ||
1859 | */ | ||
1860 | static int | ||
1861 | spider_net_init_firmware(struct spider_net_card *card) | ||
1862 | { | ||
1863 | const struct firmware *firmware; | ||
1864 | int err = -EIO; | ||
1865 | |||
1866 | if (request_firmware(&firmware, | ||
1867 | SPIDER_NET_FIRMWARE_NAME, &card->pdev->dev) < 0) { | ||
1868 | if (netif_msg_probe(card)) | ||
1869 | pr_err("Couldn't read in sequencer data file %s.\n", | ||
1870 | SPIDER_NET_FIRMWARE_NAME); | ||
1871 | firmware = NULL; | ||
1872 | goto out; | ||
1873 | } | ||
1874 | |||
1875 | if (firmware->size != 6 * SPIDER_NET_FIRMWARE_LEN * sizeof(u32)) { | ||
1876 | if (netif_msg_probe(card)) | ||
1877 | pr_err("Invalid size of sequencer data file %s.\n", | ||
1878 | SPIDER_NET_FIRMWARE_NAME); | ||
1879 | goto out; | ||
1880 | } | ||
1881 | |||
1882 | spider_net_download_firmware(card, firmware); | ||
1883 | |||
1884 | err = 0; | ||
1885 | out: | ||
1886 | release_firmware(firmware); | ||
1887 | |||
1888 | return err; | ||
1889 | } | ||
1890 | |||
1891 | /** | ||
1892 | * spider_net_workaround_rxramfull - work around firmware bug | ||
1893 | * @card: card structure | ||
1894 | * | ||
1895 | * no return value | ||
1896 | **/ | ||
1897 | static void | ||
1898 | spider_net_workaround_rxramfull(struct spider_net_card *card) | ||
1899 | { | ||
1900 | int i, sequencer = 0; | ||
1901 | |||
1902 | /* cancel reset */ | ||
1903 | spider_net_write_reg(card, SPIDER_NET_CKRCTRL, | ||
1904 | SPIDER_NET_CKRCTRL_RUN_VALUE); | ||
1905 | |||
1906 | /* empty sequencer data */ | ||
1907 | for (sequencer = 0; sequencer < 6; sequencer++) { | ||
1908 | spider_net_write_reg(card, SPIDER_NET_GSnPRGDAT + | ||
1909 | sequencer * 8, 0x0); | ||
1910 | for (i = 0; i < SPIDER_NET_FIRMWARE_LEN; i++) { | ||
1911 | spider_net_write_reg(card, SPIDER_NET_GSnPRGDAT + | ||
1912 | sequencer * 8, 0x0); | ||
1913 | } | ||
1914 | } | ||
1915 | |||
1916 | /* set sequencer operation */ | ||
1917 | spider_net_write_reg(card, SPIDER_NET_GSINIT, 0x000000fe); | ||
1918 | |||
1919 | /* reset */ | ||
1920 | spider_net_write_reg(card, SPIDER_NET_CKRCTRL, | ||
1921 | SPIDER_NET_CKRCTRL_STOP_VALUE); | ||
1922 | } | ||
1923 | |||
1924 | /** | ||
1925 | * spider_net_tx_timeout_task - task scheduled by the watchdog timeout | ||
1926 | * function (to be called not under interrupt status) | ||
1927 | * @data: data, is interface device structure | ||
1928 | * | ||
1929 | * called as task when tx hangs, resets interface (if interface is up) | ||
1930 | */ | ||
1931 | static void | ||
1932 | spider_net_tx_timeout_task(void *data) | ||
1933 | { | ||
1934 | struct net_device *netdev = data; | ||
1935 | struct spider_net_card *card = netdev_priv(netdev); | ||
1936 | |||
1937 | if (!(netdev->flags & IFF_UP)) | ||
1938 | goto out; | ||
1939 | |||
1940 | netif_device_detach(netdev); | ||
1941 | spider_net_stop(netdev); | ||
1942 | |||
1943 | spider_net_workaround_rxramfull(card); | ||
1944 | spider_net_init_card(card); | ||
1945 | |||
1946 | if (spider_net_setup_phy(card)) | ||
1947 | goto out; | ||
1948 | if (spider_net_init_firmware(card)) | ||
1949 | goto out; | ||
1950 | |||
1951 | spider_net_open(netdev); | ||
1952 | spider_net_kick_tx_dma(card, card->tx_chain.head); | ||
1953 | netif_device_attach(netdev); | ||
1954 | |||
1955 | out: | ||
1956 | atomic_dec(&card->tx_timeout_task_counter); | ||
1957 | } | ||
1958 | |||
1959 | /** | ||
1960 | * spider_net_tx_timeout - called when the tx timeout watchdog kicks in. | ||
1961 | * @netdev: interface device structure | ||
1962 | * | ||
1963 | * called, if tx hangs. Schedules a task that resets the interface | ||
1964 | */ | ||
1965 | static void | ||
1966 | spider_net_tx_timeout(struct net_device *netdev) | ||
1967 | { | ||
1968 | struct spider_net_card *card; | ||
1969 | |||
1970 | card = netdev_priv(netdev); | ||
1971 | atomic_inc(&card->tx_timeout_task_counter); | ||
1972 | if (netdev->flags & IFF_UP) | ||
1973 | schedule_work(&card->tx_timeout_task); | ||
1974 | else | ||
1975 | atomic_dec(&card->tx_timeout_task_counter); | ||
1976 | } | ||
1977 | |||
1978 | /** | ||
1979 | * spider_net_setup_netdev_ops - initialization of net_device operations | ||
1980 | * @netdev: net_device structure | ||
1981 | * | ||
1982 | * fills out function pointers in the net_device structure | ||
1983 | */ | ||
1984 | static void | ||
1985 | spider_net_setup_netdev_ops(struct net_device *netdev) | ||
1986 | { | ||
1987 | netdev->open = &spider_net_open; | ||
1988 | netdev->stop = &spider_net_stop; | ||
1989 | netdev->hard_start_xmit = &spider_net_xmit; | ||
1990 | netdev->get_stats = &spider_net_get_stats; | ||
1991 | netdev->set_multicast_list = &spider_net_set_multi; | ||
1992 | netdev->set_mac_address = &spider_net_set_mac; | ||
1993 | netdev->change_mtu = &spider_net_change_mtu; | ||
1994 | netdev->do_ioctl = &spider_net_do_ioctl; | ||
1995 | /* tx watchdog */ | ||
1996 | netdev->tx_timeout = &spider_net_tx_timeout; | ||
1997 | netdev->watchdog_timeo = SPIDER_NET_WATCHDOG_TIMEOUT; | ||
1998 | /* NAPI */ | ||
1999 | netdev->poll = &spider_net_poll; | ||
2000 | netdev->weight = SPIDER_NET_NAPI_WEIGHT; | ||
2001 | /* HW VLAN */ | ||
2002 | netdev->vlan_rx_register = &spider_net_vlan_rx_reg; | ||
2003 | netdev->vlan_rx_add_vid = &spider_net_vlan_rx_add; | ||
2004 | netdev->vlan_rx_kill_vid = &spider_net_vlan_rx_kill; | ||
2005 | #ifdef CONFIG_NET_POLL_CONTROLLER | ||
2006 | /* poll controller */ | ||
2007 | netdev->poll_controller = &spider_net_poll_controller; | ||
2008 | #endif /* CONFIG_NET_POLL_CONTROLLER */ | ||
2009 | /* ethtool ops */ | ||
2010 | netdev->ethtool_ops = &spider_net_ethtool_ops; | ||
2011 | } | ||
2012 | |||
2013 | /** | ||
2014 | * spider_net_setup_netdev - initialization of net_device | ||
2015 | * @card: card structure | ||
2016 | * | ||
2017 | * Returns 0 on success or <0 on failure | ||
2018 | * | ||
2019 | * spider_net_setup_netdev initializes the net_device structure | ||
2020 | **/ | ||
2021 | static int | ||
2022 | spider_net_setup_netdev(struct spider_net_card *card) | ||
2023 | { | ||
2024 | int result; | ||
2025 | struct net_device *netdev = card->netdev; | ||
2026 | struct device_node *dn; | ||
2027 | struct sockaddr addr; | ||
2028 | u8 *mac; | ||
2029 | |||
2030 | SET_MODULE_OWNER(netdev); | ||
2031 | SET_NETDEV_DEV(netdev, &card->pdev->dev); | ||
2032 | |||
2033 | pci_set_drvdata(card->pdev, netdev); | ||
2034 | spin_lock_init(&card->intmask_lock); | ||
2035 | netdev->irq = card->pdev->irq; | ||
2036 | |||
2037 | card->options.rx_csum = SPIDER_NET_RX_CSUM_DEFAULT; | ||
2038 | |||
2039 | spider_net_setup_netdev_ops(netdev); | ||
2040 | |||
2041 | netdev->features = 0; | ||
2042 | /* some time: NETIF_F_HW_VLAN_TX | NETIF_F_HW_VLAN_RX | | ||
2043 | * NETIF_F_HW_VLAN_FILTER */ | ||
2044 | |||
2045 | netdev->irq = card->pdev->irq; | ||
2046 | |||
2047 | dn = pci_device_to_OF_node(card->pdev); | ||
2048 | mac = (u8 *)get_property(dn, "local-mac-address", NULL); | ||
2049 | memcpy(addr.sa_data, mac, ETH_ALEN); | ||
2050 | |||
2051 | result = spider_net_set_mac(netdev, &addr); | ||
2052 | if ((result) && (netif_msg_probe(card))) | ||
2053 | pr_err("Failed to set MAC address: %i\n", result); | ||
2054 | |||
2055 | result = register_netdev(netdev); | ||
2056 | if (result) { | ||
2057 | if (netif_msg_probe(card)) | ||
2058 | pr_err("Couldn't register net_device: %i\n", | ||
2059 | result); | ||
2060 | return result; | ||
2061 | } | ||
2062 | |||
2063 | if (netif_msg_probe(card)) | ||
2064 | pr_info("Initialized device %s.\n", netdev->name); | ||
2065 | |||
2066 | return 0; | ||
2067 | } | ||
2068 | |||
2069 | /** | ||
2070 | * spider_net_alloc_card - allocates net_device and card structure | ||
2071 | * | ||
2072 | * returns the card structure or NULL in case of errors | ||
2073 | * | ||
2074 | * the card and net_device structures are linked to each other | ||
2075 | */ | ||
2076 | static struct spider_net_card * | ||
2077 | spider_net_alloc_card(void) | ||
2078 | { | ||
2079 | struct net_device *netdev; | ||
2080 | struct spider_net_card *card; | ||
2081 | size_t alloc_size; | ||
2082 | |||
2083 | alloc_size = sizeof (*card) + | ||
2084 | sizeof (struct spider_net_descr) * rx_descriptors + | ||
2085 | sizeof (struct spider_net_descr) * tx_descriptors; | ||
2086 | netdev = alloc_etherdev(alloc_size); | ||
2087 | if (!netdev) | ||
2088 | return NULL; | ||
2089 | |||
2090 | card = netdev_priv(netdev); | ||
2091 | card->netdev = netdev; | ||
2092 | card->msg_enable = SPIDER_NET_DEFAULT_MSG; | ||
2093 | INIT_WORK(&card->tx_timeout_task, spider_net_tx_timeout_task, netdev); | ||
2094 | init_waitqueue_head(&card->waitq); | ||
2095 | atomic_set(&card->tx_timeout_task_counter, 0); | ||
2096 | |||
2097 | return card; | ||
2098 | } | ||
2099 | |||
2100 | /** | ||
2101 | * spider_net_undo_pci_setup - releases PCI ressources | ||
2102 | * @card: card structure | ||
2103 | * | ||
2104 | * spider_net_undo_pci_setup releases the mapped regions | ||
2105 | */ | ||
2106 | static void | ||
2107 | spider_net_undo_pci_setup(struct spider_net_card *card) | ||
2108 | { | ||
2109 | iounmap(card->regs); | ||
2110 | pci_release_regions(card->pdev); | ||
2111 | } | ||
2112 | |||
2113 | /** | ||
2114 | * spider_net_setup_pci_dev - sets up the device in terms of PCI operations | ||
2115 | * @card: card structure | ||
2116 | * @pdev: PCI device | ||
2117 | * | ||
2118 | * Returns the card structure or NULL if any errors occur | ||
2119 | * | ||
2120 | * spider_net_setup_pci_dev initializes pdev and together with the | ||
2121 | * functions called in spider_net_open configures the device so that | ||
2122 | * data can be transferred over it | ||
2123 | * The net_device structure is attached to the card structure, if the | ||
2124 | * function returns without error. | ||
2125 | **/ | ||
2126 | static struct spider_net_card * | ||
2127 | spider_net_setup_pci_dev(struct pci_dev *pdev) | ||
2128 | { | ||
2129 | struct spider_net_card *card; | ||
2130 | unsigned long mmio_start, mmio_len; | ||
2131 | |||
2132 | if (pci_enable_device(pdev)) { | ||
2133 | pr_err("Couldn't enable PCI device\n"); | ||
2134 | return NULL; | ||
2135 | } | ||
2136 | |||
2137 | if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) { | ||
2138 | pr_err("Couldn't find proper PCI device base address.\n"); | ||
2139 | goto out_disable_dev; | ||
2140 | } | ||
2141 | |||
2142 | if (pci_request_regions(pdev, spider_net_driver_name)) { | ||
2143 | pr_err("Couldn't obtain PCI resources, aborting.\n"); | ||
2144 | goto out_disable_dev; | ||
2145 | } | ||
2146 | |||
2147 | pci_set_master(pdev); | ||
2148 | |||
2149 | card = spider_net_alloc_card(); | ||
2150 | if (!card) { | ||
2151 | pr_err("Couldn't allocate net_device structure, " | ||
2152 | "aborting.\n"); | ||
2153 | goto out_release_regions; | ||
2154 | } | ||
2155 | card->pdev = pdev; | ||
2156 | |||
2157 | /* fetch base address and length of first resource */ | ||
2158 | mmio_start = pci_resource_start(pdev, 0); | ||
2159 | mmio_len = pci_resource_len(pdev, 0); | ||
2160 | |||
2161 | card->netdev->mem_start = mmio_start; | ||
2162 | card->netdev->mem_end = mmio_start + mmio_len; | ||
2163 | card->regs = ioremap(mmio_start, mmio_len); | ||
2164 | |||
2165 | if (!card->regs) { | ||
2166 | pr_err("Couldn't obtain PCI resources, aborting.\n"); | ||
2167 | goto out_release_regions; | ||
2168 | } | ||
2169 | |||
2170 | return card; | ||
2171 | |||
2172 | out_release_regions: | ||
2173 | pci_release_regions(pdev); | ||
2174 | out_disable_dev: | ||
2175 | pci_disable_device(pdev); | ||
2176 | pci_set_drvdata(pdev, NULL); | ||
2177 | return NULL; | ||
2178 | } | ||
2179 | |||
2180 | /** | ||
2181 | * spider_net_probe - initialization of a device | ||
2182 | * @pdev: PCI device | ||
2183 | * @ent: entry in the device id list | ||
2184 | * | ||
2185 | * Returns 0 on success, <0 on failure | ||
2186 | * | ||
2187 | * spider_net_probe initializes pdev and registers a net_device | ||
2188 | * structure for it. After that, the device can be ifconfig'ed up | ||
2189 | **/ | ||
2190 | static int __devinit | ||
2191 | spider_net_probe(struct pci_dev *pdev, const struct pci_device_id *ent) | ||
2192 | { | ||
2193 | int err = -EIO; | ||
2194 | struct spider_net_card *card; | ||
2195 | |||
2196 | card = spider_net_setup_pci_dev(pdev); | ||
2197 | if (!card) | ||
2198 | goto out; | ||
2199 | |||
2200 | spider_net_workaround_rxramfull(card); | ||
2201 | spider_net_init_card(card); | ||
2202 | |||
2203 | err = spider_net_setup_phy(card); | ||
2204 | if (err) | ||
2205 | goto out_undo_pci; | ||
2206 | |||
2207 | err = spider_net_init_firmware(card); | ||
2208 | if (err) | ||
2209 | goto out_undo_pci; | ||
2210 | |||
2211 | err = spider_net_setup_netdev(card); | ||
2212 | if (err) | ||
2213 | goto out_undo_pci; | ||
2214 | |||
2215 | return 0; | ||
2216 | |||
2217 | out_undo_pci: | ||
2218 | spider_net_undo_pci_setup(card); | ||
2219 | free_netdev(card->netdev); | ||
2220 | out: | ||
2221 | return err; | ||
2222 | } | ||
2223 | |||
2224 | /** | ||
2225 | * spider_net_remove - removal of a device | ||
2226 | * @pdev: PCI device | ||
2227 | * | ||
2228 | * Returns 0 on success, <0 on failure | ||
2229 | * | ||
2230 | * spider_net_remove is called to remove the device and unregisters the | ||
2231 | * net_device | ||
2232 | **/ | ||
2233 | static void __devexit | ||
2234 | spider_net_remove(struct pci_dev *pdev) | ||
2235 | { | ||
2236 | struct net_device *netdev; | ||
2237 | struct spider_net_card *card; | ||
2238 | |||
2239 | netdev = pci_get_drvdata(pdev); | ||
2240 | card = netdev_priv(netdev); | ||
2241 | |||
2242 | wait_event(card->waitq, | ||
2243 | atomic_read(&card->tx_timeout_task_counter) == 0); | ||
2244 | |||
2245 | unregister_netdev(netdev); | ||
2246 | spider_net_undo_pci_setup(card); | ||
2247 | free_netdev(netdev); | ||
2248 | |||
2249 | free_irq(to_pci_dev(netdev->class_dev.dev)->irq, netdev); | ||
2250 | } | ||
2251 | |||
2252 | static struct pci_driver spider_net_driver = { | ||
2253 | .owner = THIS_MODULE, | ||
2254 | .name = spider_net_driver_name, | ||
2255 | .id_table = spider_net_pci_tbl, | ||
2256 | .probe = spider_net_probe, | ||
2257 | .remove = __devexit_p(spider_net_remove) | ||
2258 | }; | ||
2259 | |||
2260 | /** | ||
2261 | * spider_net_init - init function when the driver is loaded | ||
2262 | * | ||
2263 | * spider_net_init registers the device driver | ||
2264 | */ | ||
2265 | static int __init spider_net_init(void) | ||
2266 | { | ||
2267 | if (rx_descriptors < SPIDER_NET_RX_DESCRIPTORS_MIN) { | ||
2268 | rx_descriptors = SPIDER_NET_RX_DESCRIPTORS_MIN; | ||
2269 | pr_info("adjusting rx descriptors to %i.\n", rx_descriptors); | ||
2270 | } | ||
2271 | if (rx_descriptors > SPIDER_NET_RX_DESCRIPTORS_MAX) { | ||
2272 | rx_descriptors = SPIDER_NET_RX_DESCRIPTORS_MAX; | ||
2273 | pr_info("adjusting rx descriptors to %i.\n", rx_descriptors); | ||
2274 | } | ||
2275 | if (tx_descriptors < SPIDER_NET_TX_DESCRIPTORS_MIN) { | ||
2276 | tx_descriptors = SPIDER_NET_TX_DESCRIPTORS_MIN; | ||
2277 | pr_info("adjusting tx descriptors to %i.\n", tx_descriptors); | ||
2278 | } | ||
2279 | if (tx_descriptors > SPIDER_NET_TX_DESCRIPTORS_MAX) { | ||
2280 | tx_descriptors = SPIDER_NET_TX_DESCRIPTORS_MAX; | ||
2281 | pr_info("adjusting tx descriptors to %i.\n", tx_descriptors); | ||
2282 | } | ||
2283 | |||
2284 | return pci_register_driver(&spider_net_driver); | ||
2285 | } | ||
2286 | |||
2287 | /** | ||
2288 | * spider_net_cleanup - exit function when driver is unloaded | ||
2289 | * | ||
2290 | * spider_net_cleanup unregisters the device driver | ||
2291 | */ | ||
2292 | static void __exit spider_net_cleanup(void) | ||
2293 | { | ||
2294 | pci_unregister_driver(&spider_net_driver); | ||
2295 | } | ||
2296 | |||
2297 | module_init(spider_net_init); | ||
2298 | module_exit(spider_net_cleanup); | ||
diff --git a/drivers/net/spider_net.h b/drivers/net/spider_net.h new file mode 100644 index 000000000000..22b2f2347351 --- /dev/null +++ b/drivers/net/spider_net.h | |||
@@ -0,0 +1,469 @@ | |||
1 | /* | ||
2 | * Network device driver for Cell Processor-Based Blade | ||
3 | * | ||
4 | * (C) Copyright IBM Corp. 2005 | ||
5 | * | ||
6 | * Authors : Utz Bacher <utz.bacher@de.ibm.com> | ||
7 | * Jens Osterkamp <Jens.Osterkamp@de.ibm.com> | ||
8 | * | ||
9 | * This program is free software; you can redistribute it and/or modify | ||
10 | * it under the terms of the GNU General Public License as published by | ||
11 | * the Free Software Foundation; either version 2, or (at your option) | ||
12 | * any later version. | ||
13 | * | ||
14 | * This program is distributed in the hope that it will be useful, | ||
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
17 | * GNU General Public License for more details. | ||
18 | * | ||
19 | * You should have received a copy of the GNU General Public License | ||
20 | * along with this program; if not, write to the Free Software | ||
21 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | ||
22 | */ | ||
23 | |||
24 | #ifndef _SPIDER_NET_H | ||
25 | #define _SPIDER_NET_H | ||
26 | |||
27 | #include "sungem_phy.h" | ||
28 | |||
29 | extern int spider_net_stop(struct net_device *netdev); | ||
30 | extern int spider_net_open(struct net_device *netdev); | ||
31 | |||
32 | extern struct ethtool_ops spider_net_ethtool_ops; | ||
33 | |||
34 | extern char spider_net_driver_name[]; | ||
35 | |||
36 | #define SPIDER_NET_MAX_MTU 2308 | ||
37 | #define SPIDER_NET_MIN_MTU 64 | ||
38 | |||
39 | #define SPIDER_NET_RXBUF_ALIGN 128 | ||
40 | |||
41 | #define SPIDER_NET_RX_DESCRIPTORS_DEFAULT 64 | ||
42 | #define SPIDER_NET_RX_DESCRIPTORS_MIN 16 | ||
43 | #define SPIDER_NET_RX_DESCRIPTORS_MAX 256 | ||
44 | |||
45 | #define SPIDER_NET_TX_DESCRIPTORS_DEFAULT 64 | ||
46 | #define SPIDER_NET_TX_DESCRIPTORS_MIN 16 | ||
47 | #define SPIDER_NET_TX_DESCRIPTORS_MAX 256 | ||
48 | |||
49 | #define SPIDER_NET_RX_CSUM_DEFAULT 1 | ||
50 | |||
51 | #define SPIDER_NET_WATCHDOG_TIMEOUT 5*HZ | ||
52 | #define SPIDER_NET_NAPI_WEIGHT 64 | ||
53 | |||
54 | #define SPIDER_NET_FIRMWARE_LEN 1024 | ||
55 | #define SPIDER_NET_FIRMWARE_NAME "spider_fw.bin" | ||
56 | |||
57 | /** spider_net SMMIO registers */ | ||
58 | #define SPIDER_NET_GHIINT0STS 0x00000000 | ||
59 | #define SPIDER_NET_GHIINT1STS 0x00000004 | ||
60 | #define SPIDER_NET_GHIINT2STS 0x00000008 | ||
61 | #define SPIDER_NET_GHIINT0MSK 0x00000010 | ||
62 | #define SPIDER_NET_GHIINT1MSK 0x00000014 | ||
63 | #define SPIDER_NET_GHIINT2MSK 0x00000018 | ||
64 | |||
65 | #define SPIDER_NET_GRESUMINTNUM 0x00000020 | ||
66 | #define SPIDER_NET_GREINTNUM 0x00000024 | ||
67 | |||
68 | #define SPIDER_NET_GFFRMNUM 0x00000028 | ||
69 | #define SPIDER_NET_GFAFRMNUM 0x0000002c | ||
70 | #define SPIDER_NET_GFBFRMNUM 0x00000030 | ||
71 | #define SPIDER_NET_GFCFRMNUM 0x00000034 | ||
72 | #define SPIDER_NET_GFDFRMNUM 0x00000038 | ||
73 | |||
74 | /* clear them (don't use it) */ | ||
75 | #define SPIDER_NET_GFREECNNUM 0x0000003c | ||
76 | #define SPIDER_NET_GONETIMENUM 0x00000040 | ||
77 | |||
78 | #define SPIDER_NET_GTOUTFRMNUM 0x00000044 | ||
79 | |||
80 | #define SPIDER_NET_GTXMDSET 0x00000050 | ||
81 | #define SPIDER_NET_GPCCTRL 0x00000054 | ||
82 | #define SPIDER_NET_GRXMDSET 0x00000058 | ||
83 | #define SPIDER_NET_GIPSECINIT 0x0000005c | ||
84 | #define SPIDER_NET_GFTRESTRT 0x00000060 | ||
85 | #define SPIDER_NET_GRXDMAEN 0x00000064 | ||
86 | #define SPIDER_NET_GMRWOLCTRL 0x00000068 | ||
87 | #define SPIDER_NET_GPCWOPCMD 0x0000006c | ||
88 | #define SPIDER_NET_GPCROPCMD 0x00000070 | ||
89 | #define SPIDER_NET_GTTFRMCNT 0x00000078 | ||
90 | #define SPIDER_NET_GTESTMD 0x0000007c | ||
91 | |||
92 | #define SPIDER_NET_GSINIT 0x00000080 | ||
93 | #define SPIDER_NET_GSnPRGADR 0x00000084 | ||
94 | #define SPIDER_NET_GSnPRGDAT 0x00000088 | ||
95 | |||
96 | #define SPIDER_NET_GMACOPEMD 0x00000100 | ||
97 | #define SPIDER_NET_GMACLENLMT 0x00000108 | ||
98 | #define SPIDER_NET_GMACINTEN 0x00000118 | ||
99 | #define SPIDER_NET_GMACPHYCTRL 0x00000120 | ||
100 | |||
101 | #define SPIDER_NET_GMACAPAUSE 0x00000154 | ||
102 | #define SPIDER_NET_GMACTXPAUSE 0x00000164 | ||
103 | |||
104 | #define SPIDER_NET_GMACMODE 0x000001b0 | ||
105 | #define SPIDER_NET_GMACBSTLMT 0x000001b4 | ||
106 | |||
107 | #define SPIDER_NET_GMACUNIMACU 0x000001c0 | ||
108 | #define SPIDER_NET_GMACUNIMACL 0x000001c8 | ||
109 | |||
110 | #define SPIDER_NET_GMRMHFILnR 0x00000400 | ||
111 | #define SPIDER_NET_MULTICAST_HASHES 256 | ||
112 | |||
113 | #define SPIDER_NET_GMRUAFILnR 0x00000500 | ||
114 | #define SPIDER_NET_GMRUA0FIL15R 0x00000578 | ||
115 | |||
116 | /* RX DMA controller registers, all 0x00000a.. are for DMA controller A, | ||
117 | * 0x00000b.. for DMA controller B, etc. */ | ||
118 | #define SPIDER_NET_GDADCHA 0x00000a00 | ||
119 | #define SPIDER_NET_GDADMACCNTR 0x00000a04 | ||
120 | #define SPIDER_NET_GDACTDPA 0x00000a08 | ||
121 | #define SPIDER_NET_GDACTDCNT 0x00000a0c | ||
122 | #define SPIDER_NET_GDACDBADDR 0x00000a20 | ||
123 | #define SPIDER_NET_GDACDBSIZE 0x00000a24 | ||
124 | #define SPIDER_NET_GDACNEXTDA 0x00000a28 | ||
125 | #define SPIDER_NET_GDACCOMST 0x00000a2c | ||
126 | #define SPIDER_NET_GDAWBCOMST 0x00000a30 | ||
127 | #define SPIDER_NET_GDAWBRSIZE 0x00000a34 | ||
128 | #define SPIDER_NET_GDAWBVSIZE 0x00000a38 | ||
129 | #define SPIDER_NET_GDAWBTRST 0x00000a3c | ||
130 | #define SPIDER_NET_GDAWBTRERR 0x00000a40 | ||
131 | |||
132 | /* TX DMA controller registers */ | ||
133 | #define SPIDER_NET_GDTDCHA 0x00000e00 | ||
134 | #define SPIDER_NET_GDTDMACCNTR 0x00000e04 | ||
135 | #define SPIDER_NET_GDTCDPA 0x00000e08 | ||
136 | #define SPIDER_NET_GDTDMASEL 0x00000e14 | ||
137 | |||
138 | #define SPIDER_NET_ECMODE 0x00000f00 | ||
139 | /* clock and reset control register */ | ||
140 | #define SPIDER_NET_CKRCTRL 0x00000ff0 | ||
141 | |||
142 | /** SCONFIG registers */ | ||
143 | #define SPIDER_NET_SCONFIG_IOACTE 0x00002810 | ||
144 | |||
145 | /** hardcoded register values */ | ||
146 | #define SPIDER_NET_INT0_MASK_VALUE 0x3f7fe3ff | ||
147 | #define SPIDER_NET_INT1_MASK_VALUE 0xffffffff | ||
148 | /* no MAC aborts -> auto retransmission */ | ||
149 | #define SPIDER_NET_INT2_MASK_VALUE 0xfffffff1 | ||
150 | |||
151 | /* clear counter when interrupt sources are cleared | ||
152 | #define SPIDER_NET_FRAMENUM_VALUE 0x0001f001 */ | ||
153 | /* we rely on flagged descriptor interrupts */ | ||
154 | #define SPIDER_NET_FRAMENUM_VALUE 0x00000000 | ||
155 | /* set this first, then the FRAMENUM_VALUE */ | ||
156 | #define SPIDER_NET_GFXFRAMES_VALUE 0x00000000 | ||
157 | |||
158 | #define SPIDER_NET_STOP_SEQ_VALUE 0x00000000 | ||
159 | #define SPIDER_NET_RUN_SEQ_VALUE 0x0000007e | ||
160 | |||
161 | #define SPIDER_NET_PHY_CTRL_VALUE 0x00040040 | ||
162 | /* #define SPIDER_NET_PHY_CTRL_VALUE 0x01070080*/ | ||
163 | #define SPIDER_NET_RXMODE_VALUE 0x00000011 | ||
164 | /* auto retransmission in case of MAC aborts */ | ||
165 | #define SPIDER_NET_TXMODE_VALUE 0x00010000 | ||
166 | #define SPIDER_NET_RESTART_VALUE 0x00000000 | ||
167 | #define SPIDER_NET_WOL_VALUE 0x00001111 | ||
168 | #if 0 | ||
169 | #define SPIDER_NET_WOL_VALUE 0x00000000 | ||
170 | #endif | ||
171 | #define SPIDER_NET_IPSECINIT_VALUE 0x00f000f8 | ||
172 | |||
173 | /* pause frames: automatic, no upper retransmission count */ | ||
174 | /* outside loopback mode: ETOMOD signal dont matter, not connected */ | ||
175 | #define SPIDER_NET_OPMODE_VALUE 0x00000063 | ||
176 | /*#define SPIDER_NET_OPMODE_VALUE 0x001b0062*/ | ||
177 | #define SPIDER_NET_LENLMT_VALUE 0x00000908 | ||
178 | |||
179 | #define SPIDER_NET_MACAPAUSE_VALUE 0x00000800 /* about 1 ms */ | ||
180 | #define SPIDER_NET_TXPAUSE_VALUE 0x00000000 | ||
181 | |||
182 | #define SPIDER_NET_MACMODE_VALUE 0x00000001 | ||
183 | #define SPIDER_NET_BURSTLMT_VALUE 0x00000200 /* about 16 us */ | ||
184 | |||
185 | /* 1(0) enable r/tx dma | ||
186 | * 0000000 fixed to 0 | ||
187 | * | ||
188 | * 000000 fixed to 0 | ||
189 | * 0(1) en/disable descr writeback on force end | ||
190 | * 0(1) force end | ||
191 | * | ||
192 | * 000000 fixed to 0 | ||
193 | * 00 burst alignment: 128 bytes | ||
194 | * | ||
195 | * 00000 fixed to 0 | ||
196 | * 0 descr writeback size 32 bytes | ||
197 | * 0(1) descr chain end interrupt enable | ||
198 | * 0(1) descr status writeback enable */ | ||
199 | |||
200 | /* to set RX_DMA_EN */ | ||
201 | #define SPIDER_NET_DMA_RX_VALUE 0x80000000 | ||
202 | #define SPIDER_NET_DMA_RX_FEND_VALUE 0x00030003 | ||
203 | /* to set TX_DMA_EN */ | ||
204 | #define SPIDER_NET_DMA_TX_VALUE 0x80000000 | ||
205 | #define SPIDER_NET_DMA_TX_FEND_VALUE 0x00030003 | ||
206 | |||
207 | /* SPIDER_NET_UA_DESCR_VALUE is OR'ed with the unicast address */ | ||
208 | #define SPIDER_NET_UA_DESCR_VALUE 0x00080000 | ||
209 | #define SPIDER_NET_PROMISC_VALUE 0x00080000 | ||
210 | #define SPIDER_NET_NONPROMISC_VALUE 0x00000000 | ||
211 | |||
212 | #define SPIDER_NET_DMASEL_VALUE 0x00000001 | ||
213 | |||
214 | #define SPIDER_NET_ECMODE_VALUE 0x00000000 | ||
215 | |||
216 | #define SPIDER_NET_CKRCTRL_RUN_VALUE 0x1fff010f | ||
217 | #define SPIDER_NET_CKRCTRL_STOP_VALUE 0x0000010f | ||
218 | |||
219 | #define SPIDER_NET_SBIMSTATE_VALUE 0x00000000 | ||
220 | #define SPIDER_NET_SBTMSTATE_VALUE 0x00000000 | ||
221 | |||
222 | /* SPIDER_NET_GHIINT0STS bits, in reverse order so that they can be used | ||
223 | * with 1 << SPIDER_NET_... */ | ||
224 | enum spider_net_int0_status { | ||
225 | SPIDER_NET_GPHYINT = 0, | ||
226 | SPIDER_NET_GMAC2INT, | ||
227 | SPIDER_NET_GMAC1INT, | ||
228 | SPIDER_NET_GIPSINT, | ||
229 | SPIDER_NET_GFIFOINT, | ||
230 | SPIDER_NET_GDMACINT, | ||
231 | SPIDER_NET_GSYSINT, | ||
232 | SPIDER_NET_GPWOPCMPINT, | ||
233 | SPIDER_NET_GPROPCMPINT, | ||
234 | SPIDER_NET_GPWFFINT, | ||
235 | SPIDER_NET_GRMDADRINT, | ||
236 | SPIDER_NET_GRMARPINT, | ||
237 | SPIDER_NET_GRMMPINT, | ||
238 | SPIDER_NET_GDTDEN0INT, | ||
239 | SPIDER_NET_GDDDEN0INT, | ||
240 | SPIDER_NET_GDCDEN0INT, | ||
241 | SPIDER_NET_GDBDEN0INT, | ||
242 | SPIDER_NET_GDADEN0INT, | ||
243 | SPIDER_NET_GDTFDCINT, | ||
244 | SPIDER_NET_GDDFDCINT, | ||
245 | SPIDER_NET_GDCFDCINT, | ||
246 | SPIDER_NET_GDBFDCINT, | ||
247 | SPIDER_NET_GDAFDCINT, | ||
248 | SPIDER_NET_GTTEDINT, | ||
249 | SPIDER_NET_GDTDCEINT, | ||
250 | SPIDER_NET_GRFDNMINT, | ||
251 | SPIDER_NET_GRFCNMINT, | ||
252 | SPIDER_NET_GRFBNMINT, | ||
253 | SPIDER_NET_GRFANMINT, | ||
254 | SPIDER_NET_GRFNMINT, | ||
255 | SPIDER_NET_G1TMCNTINT, | ||
256 | SPIDER_NET_GFREECNTINT | ||
257 | }; | ||
258 | /* GHIINT1STS bits */ | ||
259 | enum spider_net_int1_status { | ||
260 | SPIDER_NET_GTMFLLINT = 0, | ||
261 | SPIDER_NET_GRMFLLINT, | ||
262 | SPIDER_NET_GTMSHTINT, | ||
263 | SPIDER_NET_GDTINVDINT, | ||
264 | SPIDER_NET_GRFDFLLINT, | ||
265 | SPIDER_NET_GDDDCEINT, | ||
266 | SPIDER_NET_GDDINVDINT, | ||
267 | SPIDER_NET_GRFCFLLINT, | ||
268 | SPIDER_NET_GDCDCEINT, | ||
269 | SPIDER_NET_GDCINVDINT, | ||
270 | SPIDER_NET_GRFBFLLINT, | ||
271 | SPIDER_NET_GDBDCEINT, | ||
272 | SPIDER_NET_GDBINVDINT, | ||
273 | SPIDER_NET_GRFAFLLINT, | ||
274 | SPIDER_NET_GDADCEINT, | ||
275 | SPIDER_NET_GDAINVDINT, | ||
276 | SPIDER_NET_GDTRSERINT, | ||
277 | SPIDER_NET_GDDRSERINT, | ||
278 | SPIDER_NET_GDCRSERINT, | ||
279 | SPIDER_NET_GDBRSERINT, | ||
280 | SPIDER_NET_GDARSERINT, | ||
281 | SPIDER_NET_GDSERINT, | ||
282 | SPIDER_NET_GDTPTERINT, | ||
283 | SPIDER_NET_GDDPTERINT, | ||
284 | SPIDER_NET_GDCPTERINT, | ||
285 | SPIDER_NET_GDBPTERINT, | ||
286 | SPIDER_NET_GDAPTERINT | ||
287 | }; | ||
288 | /* GHIINT2STS bits */ | ||
289 | enum spider_net_int2_status { | ||
290 | SPIDER_NET_GPROPERINT = 0, | ||
291 | SPIDER_NET_GMCTCRSNGINT, | ||
292 | SPIDER_NET_GMCTLCOLINT, | ||
293 | SPIDER_NET_GMCTTMOTINT, | ||
294 | SPIDER_NET_GMCRCAERINT, | ||
295 | SPIDER_NET_GMCRCALERINT, | ||
296 | SPIDER_NET_GMCRALNERINT, | ||
297 | SPIDER_NET_GMCROVRINT, | ||
298 | SPIDER_NET_GMCRRNTINT, | ||
299 | SPIDER_NET_GMCRRXERINT, | ||
300 | SPIDER_NET_GTITCSERINT, | ||
301 | SPIDER_NET_GTIFMTERINT, | ||
302 | SPIDER_NET_GTIPKTRVKINT, | ||
303 | SPIDER_NET_GTISPINGINT, | ||
304 | SPIDER_NET_GTISADNGINT, | ||
305 | SPIDER_NET_GTISPDNGINT, | ||
306 | SPIDER_NET_GRIFMTERINT, | ||
307 | SPIDER_NET_GRIPKTRVKINT, | ||
308 | SPIDER_NET_GRISPINGINT, | ||
309 | SPIDER_NET_GRISADNGINT, | ||
310 | SPIDER_NET_GRISPDNGINT | ||
311 | }; | ||
312 | |||
313 | #define SPIDER_NET_TXINT ( (1 << SPIDER_NET_GTTEDINT) | \ | ||
314 | (1 << SPIDER_NET_GDTDCEINT) | \ | ||
315 | (1 << SPIDER_NET_GDTFDCINT) ) | ||
316 | |||
317 | /* we rely on flagged descriptor interrupts*/ | ||
318 | #define SPIDER_NET_RXINT ( (1 << SPIDER_NET_GDAFDCINT) | \ | ||
319 | (1 << SPIDER_NET_GRMFLLINT) ) | ||
320 | |||
321 | #define SPIDER_NET_GPREXEC 0x80000000 | ||
322 | #define SPIDER_NET_GPRDAT_MASK 0x0000ffff | ||
323 | |||
324 | /* descriptor bits | ||
325 | * | ||
326 | * 1010 descriptor ready | ||
327 | * 0 descr in middle of chain | ||
328 | * 000 fixed to 0 | ||
329 | * | ||
330 | * 0 no interrupt on completion | ||
331 | * 000 fixed to 0 | ||
332 | * 1 no ipsec processing | ||
333 | * 1 last descriptor for this frame | ||
334 | * 00 no checksum | ||
335 | * 10 tcp checksum | ||
336 | * 11 udp checksum | ||
337 | * | ||
338 | * 00 fixed to 0 | ||
339 | * 0 fixed to 0 | ||
340 | * 0 no interrupt on response errors | ||
341 | * 0 no interrupt on invalid descr | ||
342 | * 0 no interrupt on dma process termination | ||
343 | * 0 no interrupt on descr chain end | ||
344 | * 0 no interrupt on descr complete | ||
345 | * | ||
346 | * 000 fixed to 0 | ||
347 | * 0 response error interrupt status | ||
348 | * 0 invalid descr status | ||
349 | * 0 dma termination status | ||
350 | * 0 descr chain end status | ||
351 | * 0 descr complete status */ | ||
352 | #define SPIDER_NET_DMAC_CMDSTAT_NOCS 0xa00c0000 | ||
353 | #define SPIDER_NET_DMAC_CMDSTAT_TCPCS 0xa00e0000 | ||
354 | #define SPIDER_NET_DMAC_CMDSTAT_UDPCS 0xa00f0000 | ||
355 | #define SPIDER_NET_DESCR_IND_PROC_SHIFT 28 | ||
356 | #define SPIDER_NET_DESCR_IND_PROC_MASKO 0x0fffffff | ||
357 | |||
358 | /* descr ready, descr is in middle of chain, get interrupt on completion */ | ||
359 | #define SPIDER_NET_DMAC_RX_CARDOWNED 0xa0800000 | ||
360 | |||
361 | /* multicast is no problem */ | ||
362 | #define SPIDER_NET_DATA_ERROR_MASK 0xffffbfff | ||
363 | |||
364 | enum spider_net_descr_status { | ||
365 | SPIDER_NET_DESCR_COMPLETE = 0x00, /* used in rx and tx */ | ||
366 | SPIDER_NET_DESCR_RESPONSE_ERROR = 0x01, /* used in rx and tx */ | ||
367 | SPIDER_NET_DESCR_PROTECTION_ERROR = 0x02, /* used in rx and tx */ | ||
368 | SPIDER_NET_DESCR_FRAME_END = 0x04, /* used in rx */ | ||
369 | SPIDER_NET_DESCR_FORCE_END = 0x05, /* used in rx and tx */ | ||
370 | SPIDER_NET_DESCR_CARDOWNED = 0x0a, /* used in rx and tx */ | ||
371 | SPIDER_NET_DESCR_NOT_IN_USE /* any other value */ | ||
372 | }; | ||
373 | |||
374 | struct spider_net_descr { | ||
375 | /* as defined by the hardware */ | ||
376 | dma_addr_t buf_addr; | ||
377 | u32 buf_size; | ||
378 | dma_addr_t next_descr_addr; | ||
379 | u32 dmac_cmd_status; | ||
380 | u32 result_size; | ||
381 | u32 valid_size; /* all zeroes for tx */ | ||
382 | u32 data_status; | ||
383 | u32 data_error; /* all zeroes for tx */ | ||
384 | |||
385 | /* used in the driver */ | ||
386 | struct sk_buff *skb; | ||
387 | dma_addr_t bus_addr; | ||
388 | struct spider_net_descr *next; | ||
389 | struct spider_net_descr *prev; | ||
390 | } __attribute__((aligned(32))); | ||
391 | |||
392 | struct spider_net_descr_chain { | ||
393 | /* we walk from tail to head */ | ||
394 | struct spider_net_descr *head; | ||
395 | struct spider_net_descr *tail; | ||
396 | }; | ||
397 | |||
398 | /* descriptor data_status bits */ | ||
399 | #define SPIDER_NET_RXIPCHK 29 | ||
400 | #define SPIDER_NET_TCPUDPIPCHK 28 | ||
401 | #define SPIDER_NET_DATA_STATUS_CHK_MASK (1 << SPIDER_NET_RXIPCHK | \ | ||
402 | 1 << SPIDER_NET_TCPUDPIPCHK) | ||
403 | |||
404 | #define SPIDER_NET_VLAN_PACKET 21 | ||
405 | |||
406 | /* descriptor data_error bits */ | ||
407 | #define SPIDER_NET_RXIPCHKERR 27 | ||
408 | #define SPIDER_NET_RXTCPCHKERR 26 | ||
409 | #define SPIDER_NET_DATA_ERROR_CHK_MASK (1 << SPIDER_NET_RXIPCHKERR | \ | ||
410 | 1 << SPIDER_NET_RXTCPCHKERR) | ||
411 | |||
412 | /* the cases we don't pass the packet to the stack */ | ||
413 | #define SPIDER_NET_DESTROY_RX_FLAGS 0x70138000 | ||
414 | |||
415 | #define SPIDER_NET_DESCR_SIZE 32 | ||
416 | |||
417 | /* this will be bigger some time */ | ||
418 | struct spider_net_options { | ||
419 | int rx_csum; /* for rx: if 0 ip_summed=NONE, | ||
420 | if 1 and hw has verified, ip_summed=UNNECESSARY */ | ||
421 | }; | ||
422 | |||
423 | #define SPIDER_NET_DEFAULT_MSG ( NETIF_MSG_DRV | \ | ||
424 | NETIF_MSG_PROBE | \ | ||
425 | NETIF_MSG_LINK | \ | ||
426 | NETIF_MSG_TIMER | \ | ||
427 | NETIF_MSG_IFDOWN | \ | ||
428 | NETIF_MSG_IFUP | \ | ||
429 | NETIF_MSG_RX_ERR | \ | ||
430 | NETIF_MSG_TX_ERR | \ | ||
431 | NETIF_MSG_TX_QUEUED | \ | ||
432 | NETIF_MSG_INTR | \ | ||
433 | NETIF_MSG_TX_DONE | \ | ||
434 | NETIF_MSG_RX_STATUS | \ | ||
435 | NETIF_MSG_PKTDATA | \ | ||
436 | NETIF_MSG_HW | \ | ||
437 | NETIF_MSG_WOL ) | ||
438 | |||
439 | struct spider_net_card { | ||
440 | struct net_device *netdev; | ||
441 | struct pci_dev *pdev; | ||
442 | struct mii_phy phy; | ||
443 | |||
444 | void __iomem *regs; | ||
445 | |||
446 | struct spider_net_descr_chain tx_chain; | ||
447 | struct spider_net_descr_chain rx_chain; | ||
448 | spinlock_t chain_lock; | ||
449 | |||
450 | struct net_device_stats netdev_stats; | ||
451 | |||
452 | struct spider_net_options options; | ||
453 | |||
454 | spinlock_t intmask_lock; | ||
455 | |||
456 | struct work_struct tx_timeout_task; | ||
457 | atomic_t tx_timeout_task_counter; | ||
458 | wait_queue_head_t waitq; | ||
459 | |||
460 | /* for ethtool */ | ||
461 | int msg_enable; | ||
462 | |||
463 | struct spider_net_descr descr[0]; | ||
464 | }; | ||
465 | |||
466 | #define pr_err(fmt,arg...) \ | ||
467 | printk(KERN_ERR fmt ,##arg) | ||
468 | |||
469 | #endif | ||
diff --git a/drivers/net/spider_net_ethtool.c b/drivers/net/spider_net_ethtool.c new file mode 100644 index 000000000000..9447c2ccd70a --- /dev/null +++ b/drivers/net/spider_net_ethtool.c | |||
@@ -0,0 +1,107 @@ | |||
1 | /* | ||
2 | * Network device driver for Cell Processor-Based Blade | ||
3 | * | ||
4 | * (C) Copyright IBM Corp. 2005 | ||
5 | * | ||
6 | * Authors : Utz Bacher <utz.bacher@de.ibm.com> | ||
7 | * Jens Osterkamp <Jens.Osterkamp@de.ibm.com> | ||
8 | * | ||
9 | * This program is free software; you can redistribute it and/or modify | ||
10 | * it under the terms of the GNU General Public License as published by | ||
11 | * the Free Software Foundation; either version 2, or (at your option) | ||
12 | * any later version. | ||
13 | * | ||
14 | * This program is distributed in the hope that it will be useful, | ||
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
17 | * GNU General Public License for more details. | ||
18 | * | ||
19 | * You should have received a copy of the GNU General Public License | ||
20 | * along with this program; if not, write to the Free Software | ||
21 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | ||
22 | */ | ||
23 | |||
24 | #include <linux/netdevice.h> | ||
25 | #include <linux/ethtool.h> | ||
26 | #include <linux/pci.h> | ||
27 | |||
28 | #include "spider_net.h" | ||
29 | |||
30 | static void | ||
31 | spider_net_ethtool_get_drvinfo(struct net_device *netdev, | ||
32 | struct ethtool_drvinfo *drvinfo) | ||
33 | { | ||
34 | struct spider_net_card *card; | ||
35 | card = netdev_priv(netdev); | ||
36 | |||
37 | /* clear and fill out info */ | ||
38 | memset(drvinfo, 0, sizeof(struct ethtool_drvinfo)); | ||
39 | strncpy(drvinfo->driver, spider_net_driver_name, 32); | ||
40 | strncpy(drvinfo->version, "0.1", 32); | ||
41 | strcpy(drvinfo->fw_version, "no information"); | ||
42 | strncpy(drvinfo->bus_info, pci_name(card->pdev), 32); | ||
43 | } | ||
44 | |||
45 | static void | ||
46 | spider_net_ethtool_get_wol(struct net_device *netdev, | ||
47 | struct ethtool_wolinfo *wolinfo) | ||
48 | { | ||
49 | /* no support for wol */ | ||
50 | wolinfo->supported = 0; | ||
51 | wolinfo->wolopts = 0; | ||
52 | } | ||
53 | |||
54 | static u32 | ||
55 | spider_net_ethtool_get_msglevel(struct net_device *netdev) | ||
56 | { | ||
57 | struct spider_net_card *card; | ||
58 | card = netdev_priv(netdev); | ||
59 | return card->msg_enable; | ||
60 | } | ||
61 | |||
62 | static void | ||
63 | spider_net_ethtool_set_msglevel(struct net_device *netdev, | ||
64 | u32 level) | ||
65 | { | ||
66 | struct spider_net_card *card; | ||
67 | card = netdev_priv(netdev); | ||
68 | card->msg_enable = level; | ||
69 | } | ||
70 | |||
71 | static int | ||
72 | spider_net_ethtool_nway_reset(struct net_device *netdev) | ||
73 | { | ||
74 | if (netif_running(netdev)) { | ||
75 | spider_net_stop(netdev); | ||
76 | spider_net_open(netdev); | ||
77 | } | ||
78 | return 0; | ||
79 | } | ||
80 | |||
81 | static u32 | ||
82 | spider_net_ethtool_get_rx_csum(struct net_device *netdev) | ||
83 | { | ||
84 | struct spider_net_card *card = netdev->priv; | ||
85 | |||
86 | return card->options.rx_csum; | ||
87 | } | ||
88 | |||
89 | static int | ||
90 | spider_net_ethtool_set_rx_csum(struct net_device *netdev, u32 n) | ||
91 | { | ||
92 | struct spider_net_card *card = netdev->priv; | ||
93 | |||
94 | card->options.rx_csum = n; | ||
95 | return 0; | ||
96 | } | ||
97 | |||
98 | struct ethtool_ops spider_net_ethtool_ops = { | ||
99 | .get_drvinfo = spider_net_ethtool_get_drvinfo, | ||
100 | .get_wol = spider_net_ethtool_get_wol, | ||
101 | .get_msglevel = spider_net_ethtool_get_msglevel, | ||
102 | .set_msglevel = spider_net_ethtool_set_msglevel, | ||
103 | .nway_reset = spider_net_ethtool_nway_reset, | ||
104 | .get_rx_csum = spider_net_ethtool_get_rx_csum, | ||
105 | .set_rx_csum = spider_net_ethtool_set_rx_csum, | ||
106 | }; | ||
107 | |||