2 * acenic.c: Linux driver for the Alteon AceNIC Gigabit Ethernet card
3 * and other Tigon based cards.
5 * Copyright 1998-2002 by Jes Sorensen, <jes@trained-monkey.org>.
7 * Thanks to Alteon and 3Com for providing hardware and documentation
8 * enabling me to write this driver.
10 * A mailing list for discussing the use of this driver has been
11 * setup, please subscribe to the lists if you have any questions
12 * about the driver. Send mail to linux-acenic-help@sunsite.auc.dk to
13 * see how to subscribe.
15 * This program is free software; you can redistribute it and/or modify
16 * it under the terms of the GNU General Public License as published by
17 * the Free Software Foundation; either version 2 of the License, or
18 * (at your option) any later version.
21 * Pete Wyckoff <wyckoff@ca.sandia.gov>: Initial Linux/Alpha and trace
22 * dump support. The trace dump support has not been
23 * integrated yet however.
24 * Troy Benjegerdes: Big Endian (PPC) patches.
25 * Nate Stahl: Better out of memory handling and stats support.
26 * Aman Singla: Nasty race between interrupt handler and tx code dealing
27 * with 'testing the tx_ret_csm and setting tx_full'
28 * David S. Miller <davem@redhat.com>: conversion to new PCI dma mapping
29 * infrastructure and Sparc support
30 * Pierrick Pinasseau (CERN): For lending me an Ultra 5 to test the
31 * driver under Linux/Sparc64
32 * Matt Domsch <Matt_Domsch@dell.com>: Detect Alteon 1000baseT cards
33 * ETHTOOL_GDRVINFO support
34 * Chip Salzenberg <chip@valinux.com>: Fix race condition between tx
35 * handler and close() cleanup.
36 * Ken Aaker <kdaaker@rchland.vnet.ibm.com>: Correct check for whether
37 * memory mapped IO is enabled to
38 * make the driver work on RS/6000.
39 * Takayoshi Kouchi <kouchi@hpc.bs1.fc.nec.co.jp>: Identifying problem
40 * where the driver would disable
41 * bus master mode if it had to disable
42 * write and invalidate.
43 * Stephen Hack <stephen_hack@hp.com>: Fixed ace_set_mac_addr for little
45 * Val Henson <vhenson@esscom.com>: Reset Jumbo skb producer and
46 * rx producer index when
47 * flushing the Jumbo ring.
48 * Hans Grobler <grobh@sun.ac.za>: Memory leak fixes in the
50 * Grant Grundler <grundler@cup.hp.com>: PCI write posting fixes.
53 #include <linux/config.h>
54 #include <linux/module.h>
55 #include <linux/version.h>
56 #include <linux/types.h>
57 #include <linux/errno.h>
58 #include <linux/ioport.h>
59 #include <linux/pci.h>
60 #include <linux/kernel.h>
61 #include <linux/netdevice.h>
62 #include <linux/etherdevice.h>
63 #include <linux/skbuff.h>
64 #include <linux/init.h>
65 #include <linux/delay.h>
67 #include <linux/highmem.h>
68 #include <linux/sockios.h>
70 #if defined(CONFIG_VLAN_8021Q) || defined(CONFIG_VLAN_8021Q_MODULE)
71 #include <linux/if_vlan.h>
75 #include <linux/ethtool.h>
81 #include <asm/system.h>
84 #include <asm/byteorder.h>
85 #include <asm/uaccess.h>
90 #ifdef CONFIG_ACENIC_OMIT_TIGON_I
91 #define ACE_IS_TIGON_I(ap) 0
92 #define ACE_TX_RING_ENTRIES(ap) MAX_TX_RING_ENTRIES
94 #define ACE_IS_TIGON_I(ap) (ap->version == 1)
95 #define ACE_TX_RING_ENTRIES(ap) ap->tx_ring_entries
98 #ifndef PCI_VENDOR_ID_ALTEON
99 #define PCI_VENDOR_ID_ALTEON 0x12ae
101 #ifndef PCI_DEVICE_ID_ALTEON_ACENIC_FIBRE
102 #define PCI_DEVICE_ID_ALTEON_ACENIC_FIBRE 0x0001
103 #define PCI_DEVICE_ID_ALTEON_ACENIC_COPPER 0x0002
105 #ifndef PCI_DEVICE_ID_3COM_3C985
106 #define PCI_DEVICE_ID_3COM_3C985 0x0001
108 #ifndef PCI_VENDOR_ID_NETGEAR
109 #define PCI_VENDOR_ID_NETGEAR 0x1385
110 #define PCI_DEVICE_ID_NETGEAR_GA620 0x620a
112 #ifndef PCI_DEVICE_ID_NETGEAR_GA620T
113 #define PCI_DEVICE_ID_NETGEAR_GA620T 0x630a
118 * Farallon used the DEC vendor ID by mistake and they seem not
121 #ifndef PCI_DEVICE_ID_FARALLON_PN9000SX
122 #define PCI_DEVICE_ID_FARALLON_PN9000SX 0x1a
124 #ifndef PCI_DEVICE_ID_FARALLON_PN9100T
125 #define PCI_DEVICE_ID_FARALLON_PN9100T 0xfa
127 #ifndef PCI_VENDOR_ID_SGI
128 #define PCI_VENDOR_ID_SGI 0x10a9
130 #ifndef PCI_DEVICE_ID_SGI_ACENIC
131 #define PCI_DEVICE_ID_SGI_ACENIC 0x0009
134 #if LINUX_VERSION_CODE >= 0x20400
135 static struct pci_device_id acenic_pci_tbl[] = {
136 { PCI_VENDOR_ID_ALTEON, PCI_DEVICE_ID_ALTEON_ACENIC_FIBRE,
137 PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_NETWORK_ETHERNET << 8, 0xffff00, },
138 { PCI_VENDOR_ID_ALTEON, PCI_DEVICE_ID_ALTEON_ACENIC_COPPER,
139 PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_NETWORK_ETHERNET << 8, 0xffff00, },
140 { PCI_VENDOR_ID_3COM, PCI_DEVICE_ID_3COM_3C985,
141 PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_NETWORK_ETHERNET << 8, 0xffff00, },
142 { PCI_VENDOR_ID_NETGEAR, PCI_DEVICE_ID_NETGEAR_GA620,
143 PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_NETWORK_ETHERNET << 8, 0xffff00, },
144 { PCI_VENDOR_ID_NETGEAR, PCI_DEVICE_ID_NETGEAR_GA620T,
145 PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_NETWORK_ETHERNET << 8, 0xffff00, },
147 * Farallon used the DEC vendor ID on their cards incorrectly,
148 * then later Alteon's ID.
150 { PCI_VENDOR_ID_DEC, PCI_DEVICE_ID_FARALLON_PN9000SX,
151 PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_NETWORK_ETHERNET << 8, 0xffff00, },
152 { PCI_VENDOR_ID_ALTEON, PCI_DEVICE_ID_FARALLON_PN9100T,
153 PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_NETWORK_ETHERNET << 8, 0xffff00, },
154 { PCI_VENDOR_ID_SGI, PCI_DEVICE_ID_SGI_ACENIC,
155 PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_NETWORK_ETHERNET << 8, 0xffff00, },
158 MODULE_DEVICE_TABLE(pci, acenic_pci_tbl);
162 #ifndef MODULE_LICENSE
163 #define MODULE_LICENSE(a)
175 #define __devinit __init
178 #ifndef SMP_CACHE_BYTES
179 #define SMP_CACHE_BYTES L1_CACHE_BYTES
182 #ifndef SET_MODULE_OWNER
183 #define SET_MODULE_OWNER(dev) do{} while(0)
184 #define ACE_MOD_INC_USE_COUNT MOD_INC_USE_COUNT
185 #define ACE_MOD_DEC_USE_COUNT MOD_DEC_USE_COUNT
187 #define ACE_MOD_INC_USE_COUNT do{} while(0)
188 #define ACE_MOD_DEC_USE_COUNT do{} while(0)
191 #ifndef SET_NETDEV_DEV
192 #define SET_NETDEV_DEV(net, pdev) do{} while(0)
195 #if LINUX_VERSION_CODE >= 0x2051c
196 #define ace_sync_irq(irq) synchronize_irq(irq)
198 #define ace_sync_irq(irq) synchronize_irq()
201 #if LINUX_VERSION_CODE < 0x2051e
202 #define local_irq_save(flags) do{__save_flags(flags) ; \
204 #define local_irq_restore(flags) __restore_flags(flags)
207 #if (LINUX_VERSION_CODE < 0x02030d)
208 #define pci_resource_start(dev, bar) dev->base_address[bar]
209 #elif (LINUX_VERSION_CODE < 0x02032c)
210 #define pci_resource_start(dev, bar) dev->resource[bar].start
213 #if (LINUX_VERSION_CODE < 0x02030e)
214 #define net_device device
218 #if (LINUX_VERSION_CODE < 0x02032a)
219 typedef u32 dma_addr_t;
221 static inline void *pci_alloc_consistent(struct pci_dev *hwdev, size_t size,
222 dma_addr_t *dma_handle)
226 virt_ptr = kmalloc(size, GFP_KERNEL);
229 *dma_handle = virt_to_bus(virt_ptr);
233 #define pci_free_consistent(cookie, size, ptr, dma_ptr) kfree(ptr)
234 #define pci_map_page(cookie, page, off, size, dir) \
235 virt_to_bus(page_address(page)+(off))
236 #define pci_unmap_page(cookie, address, size, dir)
237 #define pci_set_dma_mask(dev, mask) \
238 (((u64)(mask) & 0xffffffff00000000) == 0 ? 0 : -EIO)
239 #define pci_dma_supported(dev, mask) \
240 (((u64)(mask) & 0xffffffff00000000) == 0 ? 1 : 0)
242 #elif (LINUX_VERSION_CODE < 0x02040d)
245 * 2.4.13 introduced pci_map_page()/pci_unmap_page() - for 2.4.12 and prior,
246 * fall back on pci_map_single()/pci_unnmap_single().
248 * We are guaranteed that the page is mapped at this point since
249 * pci_map_page() is only used upon valid struct skb's.
251 static inline dma_addr_t
252 pci_map_page(struct pci_dev *cookie, struct page *page, unsigned long off,
253 size_t size, int dir)
257 page_virt = page_address(page);
260 return pci_map_single(cookie, (page_virt + off), size, dir);
262 #define pci_unmap_page(cookie, dma_addr, size, dir) \
263 pci_unmap_single(cookie, dma_addr, size, dir)
266 #if (LINUX_VERSION_CODE < 0x020412)
267 #define DECLARE_PCI_UNMAP_ADDR(ADDR_NAME)
268 #define DECLARE_PCI_UNMAP_LEN(LEN_NAME)
269 #define pci_unmap_addr(PTR, ADDR_NAME) 0
270 #define pci_unmap_addr_set(PTR, ADDR_NAME, VAL) do{} while(0)
271 #define pci_unmap_len(PTR, LEN_NAME) 0
272 #define pci_unmap_len_set(PTR, LEN_NAME, VAL) do{} while(0)
276 #if (LINUX_VERSION_CODE < 0x02032b)
280 * For pre-softnet kernels we need to tell the upper layer not to
281 * re-enter start_xmit() while we are in there. However softnet
282 * guarantees not to enter while we are in there so there is no need
283 * to do the netif_stop_queue() dance unless the transmit queue really
284 * gets stuck. This should also improve performance according to tests
285 * done by Aman Singla.
287 #define dev_kfree_skb_irq(a) dev_kfree_skb(a)
288 #define netif_wake_queue(dev) clear_bit(0, &dev->tbusy)
289 #define netif_stop_queue(dev) set_bit(0, &dev->tbusy)
290 #define late_stop_netif_stop_queue(dev) do{} while(0)
291 #define early_stop_netif_stop_queue(dev) test_and_set_bit(0,&dev->tbusy)
292 #define early_stop_netif_wake_queue(dev) netif_wake_queue(dev)
294 static inline void netif_start_queue(struct net_device *dev)
301 #define ace_mark_net_bh() mark_bh(NET_BH)
302 #define netif_queue_stopped(dev) dev->tbusy
303 #define netif_running(dev) dev->start
304 #define ace_if_down(dev) do{dev->start = 0;} while(0)
306 #define tasklet_struct tq_struct
307 static inline void tasklet_schedule(struct tasklet_struct *tasklet)
309 queue_task(tasklet, &tq_immediate);
310 mark_bh(IMMEDIATE_BH);
313 static inline void tasklet_init(struct tasklet_struct *tasklet,
314 void (*func)(unsigned long),
317 tasklet->next = NULL;
319 tasklet->routine = (void (*)(void *))func;
320 tasklet->data = (void *)data;
322 #define tasklet_kill(tasklet) do{} while(0)
324 #define late_stop_netif_stop_queue(dev) netif_stop_queue(dev)
325 #define early_stop_netif_stop_queue(dev) 0
326 #define early_stop_netif_wake_queue(dev) do{} while(0)
327 #define ace_mark_net_bh() do{} while(0)
328 #define ace_if_down(dev) do{} while(0)
331 #if (LINUX_VERSION_CODE >= 0x02031b)
333 #define ACE_PROBE_ARG void
335 #define ACE_PROBE_ARG struct net_device *dev
339 #define min_t(type,a,b) (((a)<(b))?(a):(b))
342 #ifndef ARCH_HAS_PREFETCHW
344 #define prefetchw(x) do{} while(0)
348 #define ACE_MAX_MOD_PARMS 8
349 #define BOARD_IDX_STATIC 0
350 #define BOARD_IDX_OVERFLOW -1
352 #if (defined(CONFIG_VLAN_8021Q) || defined(CONFIG_VLAN_8021Q_MODULE)) && \
353 defined(NETIF_F_HW_VLAN_RX)
354 #define ACENIC_DO_VLAN 1
355 #define ACE_RCB_VLAN_FLAG RCB_FLG_VLAN_ASSIST
357 #define ACENIC_DO_VLAN 0
358 #define ACE_RCB_VLAN_FLAG 0
364 * These must be defined before the firmware is included.
366 #define MAX_TEXT_LEN 96*1024
367 #define MAX_RODATA_LEN 8*1024
368 #define MAX_DATA_LEN 2*1024
370 #include "acenic_firmware.h"
372 #ifndef tigon2FwReleaseLocal
373 #define tigon2FwReleaseLocal 0
377 * This driver currently supports Tigon I and Tigon II based cards
378 * including the Alteon AceNIC, the 3Com 3C985[B] and NetGear
379 * GA620. The driver should also work on the SGI, DEC and Farallon
380 * versions of the card, however I have not been able to test that
383 * This card is really neat, it supports receive hardware checksumming
384 * and jumbo frames (up to 9000 bytes) and does a lot of work in the
385 * firmware. Also the programming interface is quite neat, except for
386 * the parts dealing with the i2c eeprom on the card ;-)
388 * Using jumbo frames:
390 * To enable jumbo frames, simply specify an mtu between 1500 and 9000
391 * bytes to ifconfig. Jumbo frames can be enabled or disabled at any time
392 * by running `ifconfig eth<X> mtu <MTU>' with <X> being the Ethernet
393 * interface number and <MTU> being the MTU value.
397 * When compiled as a loadable module, the driver allows for a number
398 * of module parameters to be specified. The driver supports the
399 * following module parameters:
401 * trace=<val> - Firmware trace level. This requires special traced
402 * firmware to replace the firmware supplied with
403 * the driver - for debugging purposes only.
405 * link=<val> - Link state. Normally you want to use the default link
406 * parameters set by the driver. This can be used to
407 * override these in case your switch doesn't negotiate
408 * the link properly. Valid values are:
409 * 0x0001 - Force half duplex link.
410 * 0x0002 - Do not negotiate line speed with the other end.
411 * 0x0010 - 10Mbit/sec link.
412 * 0x0020 - 100Mbit/sec link.
413 * 0x0040 - 1000Mbit/sec link.
414 * 0x0100 - Do not negotiate flow control.
415 * 0x0200 - Enable RX flow control Y
416 * 0x0400 - Enable TX flow control Y (Tigon II NICs only).
417 * Default value is 0x0270, ie. enable link+flow
418 * control negotiation. Negotiating the highest
419 * possible link speed with RX flow control enabled.
421 * When disabling link speed negotiation, only one link
422 * speed is allowed to be specified!
424 * tx_coal_tick=<val> - number of coalescing clock ticks (us) allowed
425 * to wait for more packets to arive before
426 * interrupting the host, from the time the first
429 * rx_coal_tick=<val> - number of coalescing clock ticks (us) allowed
430 * to wait for more packets to arive in the transmit ring,
431 * before interrupting the host, after transmitting the
432 * first packet in the ring.
434 * max_tx_desc=<val> - maximum number of transmit descriptors
435 * (packets) transmitted before interrupting the host.
437 * max_rx_desc=<val> - maximum number of receive descriptors
438 * (packets) received before interrupting the host.
440 * tx_ratio=<val> - 7 bit value (0 - 63) specifying the split in 64th
441 * increments of the NIC's on board memory to be used for
442 * transmit and receive buffers. For the 1MB NIC app. 800KB
443 * is available, on the 1/2MB NIC app. 300KB is available.
444 * 68KB will always be available as a minimum for both
445 * directions. The default value is a 50/50 split.
446 * dis_pci_mem_inval=<val> - disable PCI memory write and invalidate
447 * operations, default (1) is to always disable this as
448 * that is what Alteon does on NT. I have not been able
449 * to measure any real performance differences with
450 * this on my systems. Set <val>=0 if you want to
451 * enable these operations.
453 * If you use more than one NIC, specify the parameters for the
454 * individual NICs with a comma, ie. trace=0,0x00001fff,0 you want to
455 * run tracing on NIC #2 but not on NIC #1 and #3.
459 * - Proper multicast support.
460 * - NIC dump support.
461 * - More tuning parameters.
463 * The mini ring is not used under Linux and I am not sure it makes sense
464 * to actually use it.
466 * New interrupt handler strategy:
468 * The old interrupt handler worked using the traditional method of
469 * replacing an skbuff with a new one when a packet arrives. However
470 * the rx rings do not need to contain a static number of buffer
471 * descriptors, thus it makes sense to move the memory allocation out
472 * of the main interrupt handler and do it in a bottom half handler
473 * and only allocate new buffers when the number of buffers in the
474 * ring is below a certain threshold. In order to avoid starving the
475 * NIC under heavy load it is however necessary to force allocation
476 * when hitting a minimum threshold. The strategy for alloction is as
479 * RX_LOW_BUF_THRES - allocate buffers in the bottom half
480 * RX_PANIC_LOW_THRES - we are very low on buffers, allocate
481 * the buffers in the interrupt handler
482 * RX_RING_THRES - maximum number of buffers in the rx ring
483 * RX_MINI_THRES - maximum number of buffers in the mini ring
484 * RX_JUMBO_THRES - maximum number of buffers in the jumbo ring
486 * One advantagous side effect of this allocation approach is that the
487 * entire rx processing can be done without holding any spin lock
488 * since the rx rings and registers are totally independent of the tx
489 * ring and its registers. This of course includes the kmalloc's of
490 * new skb's. Thus start_xmit can run in parallel with rx processing
491 * and the memory allocation on SMP systems.
493 * Note that running the skb reallocation in a bottom half opens up
494 * another can of races which needs to be handled properly. In
495 * particular it can happen that the interrupt handler tries to run
496 * the reallocation while the bottom half is either running on another
497 * CPU or was interrupted on the same CPU. To get around this the
498 * driver uses bitops to prevent the reallocation routines from being
501 * TX handling can also be done without holding any spin lock, wheee
502 * this is fun! since tx_ret_csm is only written to by the interrupt
503 * handler. The case to be aware of is when shutting down the device
504 * and cleaning up where it is necessary to make sure that
505 * start_xmit() is not running while this is happening. Well DaveM
506 * informs me that this case is already protected against ... bye bye
507 * Mr. Spin Lock, it was nice to know you.
509 * TX interrupts are now partly disabled so the NIC will only generate
510 * TX interrupts for the number of coal ticks, not for the number of
511 * TX packets in the queue. This should reduce the number of TX only,
512 * ie. when no RX processing is done, interrupts seen.
516 * Threshold values for RX buffer allocation - the low water marks for
517 * when to start refilling the rings are set to 75% of the ring
518 * sizes. It seems to make sense to refill the rings entirely from the
519 * intrrupt handler once it gets below the panic threshold, that way
520 * we don't risk that the refilling is moved to another CPU when the
521 * one running the interrupt handler just got the slab code hot in its
524 #define RX_RING_SIZE 72
525 #define RX_MINI_SIZE 64
526 #define RX_JUMBO_SIZE 48
528 #define RX_PANIC_STD_THRES 16
529 #define RX_PANIC_STD_REFILL (3*RX_PANIC_STD_THRES)/2
530 #define RX_LOW_STD_THRES (3*RX_RING_SIZE)/4
531 #define RX_PANIC_MINI_THRES 12
532 #define RX_PANIC_MINI_REFILL (3*RX_PANIC_MINI_THRES)/2
533 #define RX_LOW_MINI_THRES (3*RX_MINI_SIZE)/4
534 #define RX_PANIC_JUMBO_THRES 6
535 #define RX_PANIC_JUMBO_REFILL (3*RX_PANIC_JUMBO_THRES)/2
536 #define RX_LOW_JUMBO_THRES (3*RX_JUMBO_SIZE)/4
540 * Size of the mini ring entries, basically these just should be big
541 * enough to take TCP ACKs
543 #define ACE_MINI_SIZE 100
545 #define ACE_MINI_BUFSIZE (ACE_MINI_SIZE + 2 + 16)
546 #define ACE_STD_BUFSIZE (ACE_STD_MTU + ETH_HLEN + 2+4+16)
547 #define ACE_JUMBO_BUFSIZE (ACE_JUMBO_MTU + ETH_HLEN + 2+4+16)
550 * There seems to be a magic difference in the effect between 995 and 996
551 * but little difference between 900 and 995 ... no idea why.
553 * There is now a default set of tuning parameters which is set, depending
554 * on whether or not the user enables Jumbo frames. It's assumed that if
555 * Jumbo frames are enabled, the user wants optimal tuning for that case.
557 #define DEF_TX_COAL 400 /* 996 */
558 #define DEF_TX_MAX_DESC 60 /* was 40 */
559 #define DEF_RX_COAL 120 /* 1000 */
560 #define DEF_RX_MAX_DESC 25
561 #define DEF_TX_RATIO 21 /* 24 */
563 #define DEF_JUMBO_TX_COAL 20
564 #define DEF_JUMBO_TX_MAX_DESC 60
565 #define DEF_JUMBO_RX_COAL 30
566 #define DEF_JUMBO_RX_MAX_DESC 6
567 #define DEF_JUMBO_TX_RATIO 21
569 #if tigon2FwReleaseLocal < 20001118
571 * Standard firmware and early modifications duplicate
572 * IRQ load without this flag (coal timer is never reset).
573 * Note that with this flag tx_coal should be less than
574 * time to xmit full tx ring.
575 * 400usec is not so bad for tx ring size of 128.
577 #define TX_COAL_INTS_ONLY 1 /* worth it */
580 * With modified firmware, this is not necessary, but still useful.
582 #define TX_COAL_INTS_ONLY 1
586 #define DEF_STAT (2 * TICKS_PER_SEC)
589 static int link[ACE_MAX_MOD_PARMS];
590 static int trace[ACE_MAX_MOD_PARMS];
591 static int tx_coal_tick[ACE_MAX_MOD_PARMS];
592 static int rx_coal_tick[ACE_MAX_MOD_PARMS];
593 static int max_tx_desc[ACE_MAX_MOD_PARMS];
594 static int max_rx_desc[ACE_MAX_MOD_PARMS];
595 static int tx_ratio[ACE_MAX_MOD_PARMS];
596 static int dis_pci_mem_inval[ACE_MAX_MOD_PARMS] = {1, 1, 1, 1, 1, 1, 1, 1};
598 static char version[] __initdata =
599 "acenic.c: v0.92 08/05/2002 Jes Sorensen, linux-acenic@SunSITE.dk\n"
600 " http://home.cern.ch/~jes/gige/acenic.html\n";
602 static struct net_device *root_dev;
604 static int probed __initdata = 0;
607 int __devinit acenic_probe (ACE_PROBE_ARG)
610 struct net_device *dev;
612 struct ace_private *ap;
613 struct pci_dev *pdev = NULL;
614 int boards_found = 0;
623 while ((pdev = pci_find_class(PCI_CLASS_NETWORK_ETHERNET<<8, pdev))) {
625 if (!((pdev->vendor == PCI_VENDOR_ID_ALTEON) &&
626 ((pdev->device == PCI_DEVICE_ID_ALTEON_ACENIC_FIBRE) ||
627 (pdev->device == PCI_DEVICE_ID_ALTEON_ACENIC_COPPER)))&&
628 !((pdev->vendor == PCI_VENDOR_ID_3COM) &&
629 (pdev->device == PCI_DEVICE_ID_3COM_3C985)) &&
630 !((pdev->vendor == PCI_VENDOR_ID_NETGEAR) &&
631 ((pdev->device == PCI_DEVICE_ID_NETGEAR_GA620) ||
632 (pdev->device == PCI_DEVICE_ID_NETGEAR_GA620T))) &&
634 * Farallon used the DEC vendor ID on their cards by
635 * mistake for a while
637 !((pdev->vendor == PCI_VENDOR_ID_DEC) &&
638 (pdev->device == PCI_DEVICE_ID_FARALLON_PN9000SX)) &&
639 !((pdev->vendor == PCI_VENDOR_ID_ALTEON) &&
640 (pdev->device == PCI_DEVICE_ID_FARALLON_PN9100T)) &&
641 !((pdev->vendor == PCI_VENDOR_ID_SGI) &&
642 (pdev->device == PCI_DEVICE_ID_SGI_ACENIC)))
645 dev = alloc_etherdev(sizeof(struct ace_private));
647 printk(KERN_ERR "acenic: Unable to allocate "
648 "net_device structure!\n");
652 SET_MODULE_OWNER(dev);
653 SET_NETDEV_DEV(dev, &pdev->dev);
658 dev->open = &ace_open;
659 dev->hard_start_xmit = &ace_start_xmit;
660 dev->features |= NETIF_F_SG | NETIF_F_IP_CSUM;
662 dev->features |= NETIF_F_HW_VLAN_TX | NETIF_F_HW_VLAN_RX;
663 dev->vlan_rx_register = ace_vlan_rx_register;
664 dev->vlan_rx_kill_vid = ace_vlan_rx_kill_vid;
667 static void ace_watchdog(struct net_device *dev);
668 dev->tx_timeout = &ace_watchdog;
669 dev->watchdog_timeo = 5*HZ;
671 dev->stop = &ace_close;
672 dev->get_stats = &ace_get_stats;
673 dev->set_multicast_list = &ace_set_multicast_list;
674 dev->do_ioctl = &ace_ioctl;
675 dev->set_mac_address = &ace_set_mac_addr;
676 dev->change_mtu = &ace_change_mtu;
678 /* display version info if adapter is found */
681 /* set display flag to TRUE so that */
682 /* we only display this string ONCE */
687 if (pci_enable_device(pdev)) {
693 * Enable master mode before we start playing with the
694 * pci_command word since pci_set_master() will modify
697 pci_set_master(pdev);
699 pci_read_config_word(pdev, PCI_COMMAND, &ap->pci_command);
701 /* OpenFirmware on Mac's does not set this - DOH.. */
702 if (!(ap->pci_command & PCI_COMMAND_MEMORY)) {
703 printk(KERN_INFO "%s: Enabling PCI Memory Mapped "
704 "access - was not enabled by BIOS/Firmware\n",
706 ap->pci_command = ap->pci_command | PCI_COMMAND_MEMORY;
707 pci_write_config_word(ap->pdev, PCI_COMMAND,
712 pci_read_config_byte(pdev, PCI_LATENCY_TIMER,
714 if (ap->pci_latency <= 0x40) {
715 ap->pci_latency = 0x40;
716 pci_write_config_byte(pdev, PCI_LATENCY_TIMER,
721 * Remap the regs into kernel space - this is abuse of
722 * dev->base_addr since it was means for I/O port
723 * addresses but who gives a damn.
725 dev->base_addr = pci_resource_start(pdev, 0);
726 ap->regs = (struct ace_regs *)ioremap(dev->base_addr, 0x4000);
728 printk(KERN_ERR "%s: Unable to map I/O register, "
729 "AceNIC %i will be disabled.\n",
730 dev->name, boards_found);
734 switch(pdev->vendor) {
735 case PCI_VENDOR_ID_ALTEON:
736 if (pdev->device == PCI_DEVICE_ID_FARALLON_PN9100T) {
737 strncpy(ap->name, "Farallon PN9100-T "
738 "Gigabit Ethernet", sizeof (ap->name));
739 printk(KERN_INFO "%s: Farallon PN9100-T ",
742 strncpy(ap->name, "AceNIC Gigabit Ethernet",
744 printk(KERN_INFO "%s: Alteon AceNIC ",
748 case PCI_VENDOR_ID_3COM:
749 strncpy(ap->name, "3Com 3C985 Gigabit Ethernet",
751 printk(KERN_INFO "%s: 3Com 3C985 ", dev->name);
753 case PCI_VENDOR_ID_NETGEAR:
754 strncpy(ap->name, "NetGear GA620 Gigabit Ethernet",
756 printk(KERN_INFO "%s: NetGear GA620 ", dev->name);
758 case PCI_VENDOR_ID_DEC:
759 if (pdev->device == PCI_DEVICE_ID_FARALLON_PN9000SX) {
760 strncpy(ap->name, "Farallon PN9000-SX "
761 "Gigabit Ethernet", sizeof (ap->name));
762 printk(KERN_INFO "%s: Farallon PN9000-SX ",
766 case PCI_VENDOR_ID_SGI:
767 strncpy(ap->name, "SGI AceNIC Gigabit Ethernet",
769 printk(KERN_INFO "%s: SGI AceNIC ", dev->name);
772 strncpy(ap->name, "Unknown AceNIC based Gigabit "
773 "Ethernet", sizeof (ap->name));
774 printk(KERN_INFO "%s: Unknown AceNIC ", dev->name);
777 ap->name [sizeof (ap->name) - 1] = '\0';
778 printk("Gigabit Ethernet at 0x%08lx, ", dev->base_addr);
780 printk("irq %s\n", __irq_itoa(pdev->irq));
782 printk("irq %i\n", pdev->irq);
785 #ifdef CONFIG_ACENIC_OMIT_TIGON_I
786 if ((readl(&ap->regs->HostCtrl) >> 28) == 4) {
787 printk(KERN_ERR "%s: Driver compiled without Tigon I"
788 " support - NIC disabled\n", dev->name);
789 ace_init_cleanup(dev);
795 if (ace_allocate_descriptors(dev)) {
797 * ace_allocate_descriptors() calls
798 * ace_init_cleanup() on error.
805 if (boards_found >= ACE_MAX_MOD_PARMS)
806 ap->board_idx = BOARD_IDX_OVERFLOW;
808 ap->board_idx = boards_found;
810 ap->board_idx = BOARD_IDX_STATIC;
815 * ace_init() calls ace_init_cleanup() on error.
821 if (register_netdev(dev)) {
822 printk(KERN_ERR "acenic: device registration failed\n");
823 ace_init_cleanup(dev);
828 if (ap->pci_using_dac)
829 dev->features |= NETIF_F_HIGHDMA;
835 * If we're at this point we're going through ace_probe() for
836 * the first time. Return success (0) if we've initialized 1
837 * or more boards. Otherwise, return failure (-ENODEV).
840 if (boards_found > 0)
848 MODULE_AUTHOR("Jes Sorensen <jes@trained-monkey.org>");
849 MODULE_LICENSE("GPL");
850 MODULE_DESCRIPTION("AceNIC/3C985/GA620 Gigabit Ethernet driver");
851 MODULE_PARM(link, "1-" __MODULE_STRING(8) "i");
852 MODULE_PARM(trace, "1-" __MODULE_STRING(8) "i");
853 MODULE_PARM(tx_coal_tick, "1-" __MODULE_STRING(8) "i");
854 MODULE_PARM(max_tx_desc, "1-" __MODULE_STRING(8) "i");
855 MODULE_PARM(rx_coal_tick, "1-" __MODULE_STRING(8) "i");
856 MODULE_PARM(max_rx_desc, "1-" __MODULE_STRING(8) "i");
857 MODULE_PARM(tx_ratio, "1-" __MODULE_STRING(8) "i");
858 MODULE_PARM_DESC(link, "AceNIC/3C985/NetGear link state");
859 MODULE_PARM_DESC(trace, "AceNIC/3C985/NetGear firmware trace level");
860 MODULE_PARM_DESC(tx_coal_tick, "AceNIC/3C985/GA620 max clock ticks to wait from first tx descriptor arrives");
861 MODULE_PARM_DESC(max_tx_desc, "AceNIC/3C985/GA620 max number of transmit descriptors to wait");
862 MODULE_PARM_DESC(rx_coal_tick, "AceNIC/3C985/GA620 max clock ticks to wait from first rx descriptor arrives");
863 MODULE_PARM_DESC(max_rx_desc, "AceNIC/3C985/GA620 max number of receive descriptors to wait");
864 MODULE_PARM_DESC(tx_ratio, "AceNIC/3C985/GA620 ratio of NIC memory used for TX/RX descriptors (range 0-63)");
868 static void __exit ace_module_cleanup(void)
870 struct ace_private *ap;
871 struct ace_regs *regs;
872 struct net_device *next;
878 unregister_netdev(root_dev);
882 writel(readl(®s->CpuCtrl) | CPU_HALT, ®s->CpuCtrl);
883 if (ap->version >= 2)
884 writel(readl(®s->CpuBCtrl) | CPU_HALT,
887 * This clears any pending interrupts
889 writel(1, ®s->Mb0Lo);
890 readl(®s->CpuCtrl); /* flush */
893 * Make sure no other CPUs are processing interrupts
894 * on the card before the buffers are being released.
895 * Otherwise one might experience some `interesting'
898 * Then release the RX buffers - jumbo buffers were
899 * already released in ace_close().
901 ace_sync_irq(root_dev->irq);
903 for (i = 0; i < RX_STD_RING_ENTRIES; i++) {
904 struct sk_buff *skb = ap->skb->rx_std_skbuff[i].skb;
907 struct ring_info *ringp;
910 ringp = &ap->skb->rx_std_skbuff[i];
911 mapping = pci_unmap_addr(ringp, mapping);
912 pci_unmap_page(ap->pdev, mapping,
913 ACE_STD_BUFSIZE - (2 + 16),
916 ap->rx_std_ring[i].size = 0;
917 ap->skb->rx_std_skbuff[i].skb = NULL;
921 if (ap->version >= 2) {
922 for (i = 0; i < RX_MINI_RING_ENTRIES; i++) {
923 struct sk_buff *skb = ap->skb->rx_mini_skbuff[i].skb;
926 struct ring_info *ringp;
929 ringp = &ap->skb->rx_mini_skbuff[i];
930 mapping = pci_unmap_addr(ringp,mapping);
931 pci_unmap_page(ap->pdev, mapping,
932 ACE_MINI_BUFSIZE - (2 + 16),
935 ap->rx_mini_ring[i].size = 0;
936 ap->skb->rx_mini_skbuff[i].skb = NULL;
941 for (i = 0; i < RX_JUMBO_RING_ENTRIES; i++) {
942 struct sk_buff *skb = ap->skb->rx_jumbo_skbuff[i].skb;
944 struct ring_info *ringp;
947 ringp = &ap->skb->rx_jumbo_skbuff[i];
948 mapping = pci_unmap_addr(ringp, mapping);
949 pci_unmap_page(ap->pdev, mapping,
950 ACE_JUMBO_BUFSIZE - (2 + 16),
953 ap->rx_jumbo_ring[i].size = 0;
954 ap->skb->rx_jumbo_skbuff[i].skb = NULL;
959 ace_init_cleanup(root_dev);
960 free_netdev(root_dev);
966 int __init ace_module_init(void)
973 status = acenic_probe();
975 status = acenic_probe(NULL);
981 #if (LINUX_VERSION_CODE < 0x02032a)
983 int init_module(void)
985 return ace_module_init();
989 void cleanup_module(void)
991 ace_module_cleanup();
995 module_init(ace_module_init);
996 module_exit(ace_module_cleanup);
1000 static void ace_free_descriptors(struct net_device *dev)
1002 struct ace_private *ap = dev->priv;
1005 if (ap->rx_std_ring != NULL) {
1006 size = (sizeof(struct rx_desc) *
1007 (RX_STD_RING_ENTRIES +
1008 RX_JUMBO_RING_ENTRIES +
1009 RX_MINI_RING_ENTRIES +
1010 RX_RETURN_RING_ENTRIES));
1011 pci_free_consistent(ap->pdev, size, ap->rx_std_ring,
1012 ap->rx_ring_base_dma);
1013 ap->rx_std_ring = NULL;
1014 ap->rx_jumbo_ring = NULL;
1015 ap->rx_mini_ring = NULL;
1016 ap->rx_return_ring = NULL;
1018 if (ap->evt_ring != NULL) {
1019 size = (sizeof(struct event) * EVT_RING_ENTRIES);
1020 pci_free_consistent(ap->pdev, size, ap->evt_ring,
1022 ap->evt_ring = NULL;
1024 if (ap->tx_ring != NULL && !ACE_IS_TIGON_I(ap)) {
1025 size = (sizeof(struct tx_desc) * MAX_TX_RING_ENTRIES);
1026 pci_free_consistent(ap->pdev, size, ap->tx_ring,
1031 if (ap->evt_prd != NULL) {
1032 pci_free_consistent(ap->pdev, sizeof(u32),
1033 (void *)ap->evt_prd, ap->evt_prd_dma);
1036 if (ap->rx_ret_prd != NULL) {
1037 pci_free_consistent(ap->pdev, sizeof(u32),
1038 (void *)ap->rx_ret_prd,
1039 ap->rx_ret_prd_dma);
1040 ap->rx_ret_prd = NULL;
1042 if (ap->tx_csm != NULL) {
1043 pci_free_consistent(ap->pdev, sizeof(u32),
1044 (void *)ap->tx_csm, ap->tx_csm_dma);
1050 static int ace_allocate_descriptors(struct net_device *dev)
1052 struct ace_private *ap = dev->priv;
1055 size = (sizeof(struct rx_desc) *
1056 (RX_STD_RING_ENTRIES +
1057 RX_JUMBO_RING_ENTRIES +
1058 RX_MINI_RING_ENTRIES +
1059 RX_RETURN_RING_ENTRIES));
1061 ap->rx_std_ring = pci_alloc_consistent(ap->pdev, size,
1062 &ap->rx_ring_base_dma);
1063 if (ap->rx_std_ring == NULL)
1066 ap->rx_jumbo_ring = ap->rx_std_ring + RX_STD_RING_ENTRIES;
1067 ap->rx_mini_ring = ap->rx_jumbo_ring + RX_JUMBO_RING_ENTRIES;
1068 ap->rx_return_ring = ap->rx_mini_ring + RX_MINI_RING_ENTRIES;
1070 size = (sizeof(struct event) * EVT_RING_ENTRIES);
1072 ap->evt_ring = pci_alloc_consistent(ap->pdev, size, &ap->evt_ring_dma);
1074 if (ap->evt_ring == NULL)
1078 * Only allocate a host TX ring for the Tigon II, the Tigon I
1079 * has to use PCI registers for this ;-(
1081 if (!ACE_IS_TIGON_I(ap)) {
1082 size = (sizeof(struct tx_desc) * MAX_TX_RING_ENTRIES);
1084 ap->tx_ring = pci_alloc_consistent(ap->pdev, size,
1087 if (ap->tx_ring == NULL)
1091 ap->evt_prd = pci_alloc_consistent(ap->pdev, sizeof(u32),
1093 if (ap->evt_prd == NULL)
1096 ap->rx_ret_prd = pci_alloc_consistent(ap->pdev, sizeof(u32),
1097 &ap->rx_ret_prd_dma);
1098 if (ap->rx_ret_prd == NULL)
1101 ap->tx_csm = pci_alloc_consistent(ap->pdev, sizeof(u32),
1103 if (ap->tx_csm == NULL)
1110 ace_init_cleanup(dev);
1116 * Generic cleanup handling data allocated during init. Used when the
1117 * module is unloaded or if an error occurs during initialization
1119 static void ace_init_cleanup(struct net_device *dev)
1121 struct ace_private *ap;
1125 ace_free_descriptors(dev);
1128 pci_free_consistent(ap->pdev, sizeof(struct ace_info),
1129 ap->info, ap->info_dma);
1133 kfree(ap->trace_buf);
1136 free_irq(dev->irq, dev);
1143 * Commands are considered to be slow.
1145 static inline void ace_issue_cmd(struct ace_regs *regs, struct cmd *cmd)
1149 idx = readl(®s->CmdPrd);
1151 writel(*(u32 *)(cmd), ®s->CmdRng[idx]);
1152 idx = (idx + 1) % CMD_RING_ENTRIES;
1154 writel(idx, ®s->CmdPrd);
1158 static int __init ace_init(struct net_device *dev)
1160 struct ace_private *ap;
1161 struct ace_regs *regs;
1162 struct ace_info *info = NULL;
1163 struct pci_dev *pdev;
1164 unsigned long myjif;
1166 u32 tig_ver, mac1, mac2, tmp, pci_state;
1167 int board_idx, ecode = 0;
1169 unsigned char cache_size;
1174 board_idx = ap->board_idx;
1177 * aman@sgi.com - its useful to do a NIC reset here to
1178 * address the `Firmware not running' problem subsequent
1179 * to any crashes involving the NIC
1181 writel(HW_RESET | (HW_RESET << 24), ®s->HostCtrl);
1182 readl(®s->HostCtrl); /* PCI write posting */
1186 * Don't access any other registers before this point!
1190 * This will most likely need BYTE_SWAP once we switch
1191 * to using __raw_writel()
1193 writel((WORD_SWAP | CLR_INT | ((WORD_SWAP | CLR_INT) << 24)),
1196 writel((CLR_INT | WORD_SWAP | ((CLR_INT | WORD_SWAP) << 24)),
1199 readl(®s->HostCtrl); /* PCI write posting */
1202 * Stop the NIC CPU and clear pending interrupts
1204 writel(readl(®s->CpuCtrl) | CPU_HALT, ®s->CpuCtrl);
1205 readl(®s->CpuCtrl); /* PCI write posting */
1206 writel(0, ®s->Mb0Lo);
1208 tig_ver = readl(®s->HostCtrl) >> 28;
1211 #ifndef CONFIG_ACENIC_OMIT_TIGON_I
1214 printk(KERN_INFO " Tigon I (Rev. %i), Firmware: %i.%i.%i, ",
1215 tig_ver, tigonFwReleaseMajor, tigonFwReleaseMinor,
1217 writel(0, ®s->LocalCtrl);
1219 ap->tx_ring_entries = TIGON_I_TX_RING_ENTRIES;
1223 printk(KERN_INFO " Tigon II (Rev. %i), Firmware: %i.%i.%i, ",
1224 tig_ver, tigon2FwReleaseMajor, tigon2FwReleaseMinor,
1225 tigon2FwReleaseFix);
1226 writel(readl(®s->CpuBCtrl) | CPU_HALT, ®s->CpuBCtrl);
1227 readl(®s->CpuBCtrl); /* PCI write posting */
1229 * The SRAM bank size does _not_ indicate the amount
1230 * of memory on the card, it controls the _bank_ size!
1231 * Ie. a 1MB AceNIC will have two banks of 512KB.
1233 writel(SRAM_BANK_512K, ®s->LocalCtrl);
1234 writel(SYNC_SRAM_TIMING, ®s->MiscCfg);
1236 ap->tx_ring_entries = MAX_TX_RING_ENTRIES;
1239 printk(KERN_WARNING " Unsupported Tigon version detected "
1246 * ModeStat _must_ be set after the SRAM settings as this change
1247 * seems to corrupt the ModeStat and possible other registers.
1248 * The SRAM settings survive resets and setting it to the same
1249 * value a second time works as well. This is what caused the
1250 * `Firmware not running' problem on the Tigon II.
1253 writel(ACE_BYTE_SWAP_DMA | ACE_WARN | ACE_FATAL | ACE_BYTE_SWAP_BD |
1254 ACE_WORD_SWAP_BD | ACE_NO_JUMBO_FRAG, ®s->ModeStat);
1256 writel(ACE_BYTE_SWAP_DMA | ACE_WARN | ACE_FATAL |
1257 ACE_WORD_SWAP_BD | ACE_NO_JUMBO_FRAG, ®s->ModeStat);
1259 readl(®s->ModeStat); /* PCI write posting */
1262 for(i = 0; i < 4; i++) {
1264 tmp = read_eeprom_byte(dev, 0x8c+i);
1269 mac1 |= (tmp & 0xff);
1272 for(i = 4; i < 8; i++) {
1274 tmp = read_eeprom_byte(dev, 0x8c+i);
1279 mac2 |= (tmp & 0xff);
1282 writel(mac1, ®s->MacAddrHi);
1283 writel(mac2, ®s->MacAddrLo);
1285 printk("MAC: %02x:%02x:%02x:%02x:%02x:%02x\n",
1286 (mac1 >> 8) & 0xff, mac1 & 0xff, (mac2 >> 24) &0xff,
1287 (mac2 >> 16) & 0xff, (mac2 >> 8) & 0xff, mac2 & 0xff);
1289 dev->dev_addr[0] = (mac1 >> 8) & 0xff;
1290 dev->dev_addr[1] = mac1 & 0xff;
1291 dev->dev_addr[2] = (mac2 >> 24) & 0xff;
1292 dev->dev_addr[3] = (mac2 >> 16) & 0xff;
1293 dev->dev_addr[4] = (mac2 >> 8) & 0xff;
1294 dev->dev_addr[5] = mac2 & 0xff;
1297 * Looks like this is necessary to deal with on all architectures,
1298 * even this %$#%$# N440BX Intel based thing doesn't get it right.
1299 * Ie. having two NICs in the machine, one will have the cache
1300 * line set at boot time, the other will not.
1303 pci_read_config_byte(pdev, PCI_CACHE_LINE_SIZE, &cache_size);
1305 if (cache_size != SMP_CACHE_BYTES) {
1306 printk(KERN_INFO " PCI cache line size set incorrectly "
1307 "(%i bytes) by BIOS/FW, ", cache_size);
1308 if (cache_size > SMP_CACHE_BYTES)
1309 printk("expecting %i\n", SMP_CACHE_BYTES);
1311 printk("correcting to %i\n", SMP_CACHE_BYTES);
1312 pci_write_config_byte(pdev, PCI_CACHE_LINE_SIZE,
1313 SMP_CACHE_BYTES >> 2);
1317 pci_state = readl(®s->PciState);
1318 printk(KERN_INFO " PCI bus width: %i bits, speed: %iMHz, "
1319 "latency: %i clks\n",
1320 (pci_state & PCI_32BIT) ? 32 : 64,
1321 (pci_state & PCI_66MHZ) ? 66 : 33,
1325 * Set the max DMA transfer size. Seems that for most systems
1326 * the performance is better when no MAX parameter is
1327 * set. However for systems enabling PCI write and invalidate,
1328 * DMA writes must be set to the L1 cache line size to get
1329 * optimal performance.
1331 * The default is now to turn the PCI write and invalidate off
1332 * - that is what Alteon does for NT.
1334 tmp = READ_CMD_MEM | WRITE_CMD_MEM;
1335 if (ap->version >= 2) {
1336 tmp |= (MEM_READ_MULTIPLE | (pci_state & PCI_66MHZ));
1338 * Tuning parameters only supported for 8 cards
1340 if (board_idx == BOARD_IDX_OVERFLOW ||
1341 dis_pci_mem_inval[board_idx]) {
1342 if (ap->pci_command & PCI_COMMAND_INVALIDATE) {
1343 ap->pci_command &= ~PCI_COMMAND_INVALIDATE;
1344 pci_write_config_word(pdev, PCI_COMMAND,
1346 printk(KERN_INFO " Disabling PCI memory "
1347 "write and invalidate\n");
1349 } else if (ap->pci_command & PCI_COMMAND_INVALIDATE) {
1350 printk(KERN_INFO " PCI memory write & invalidate "
1351 "enabled by BIOS, enabling counter measures\n");
1353 switch(SMP_CACHE_BYTES) {
1355 tmp |= DMA_WRITE_MAX_16;
1358 tmp |= DMA_WRITE_MAX_32;
1361 tmp |= DMA_WRITE_MAX_64;
1364 tmp |= DMA_WRITE_MAX_128;
1367 printk(KERN_INFO " Cache line size %i not "
1368 "supported, PCI write and invalidate "
1369 "disabled\n", SMP_CACHE_BYTES);
1370 ap->pci_command &= ~PCI_COMMAND_INVALIDATE;
1371 pci_write_config_word(pdev, PCI_COMMAND,
1379 * On this platform, we know what the best dma settings
1380 * are. We use 64-byte maximum bursts, because if we
1381 * burst larger than the cache line size (or even cross
1382 * a 64byte boundary in a single burst) the UltraSparc
1383 * PCI controller will disconnect at 64-byte multiples.
1385 * Read-multiple will be properly enabled above, and when
1386 * set will give the PCI controller proper hints about
1389 tmp &= ~DMA_READ_WRITE_MASK;
1390 tmp |= DMA_READ_MAX_64;
1391 tmp |= DMA_WRITE_MAX_64;
1394 tmp &= ~DMA_READ_WRITE_MASK;
1395 tmp |= DMA_READ_MAX_128;
1397 * All the docs say MUST NOT. Well, I did.
1398 * Nothing terrible happens, if we load wrong size.
1399 * Bit w&i still works better!
1401 tmp |= DMA_WRITE_MAX_128;
1403 writel(tmp, ®s->PciState);
1407 * The Host PCI bus controller driver has to set FBB.
1408 * If all devices on that PCI bus support FBB, then the controller
1409 * can enable FBB support in the Host PCI Bus controller (or on
1410 * the PCI-PCI bridge if that applies).
1414 * I have received reports from people having problems when this
1417 if (!(ap->pci_command & PCI_COMMAND_FAST_BACK)) {
1418 printk(KERN_INFO " Enabling PCI Fast Back to Back\n");
1419 ap->pci_command |= PCI_COMMAND_FAST_BACK;
1420 pci_write_config_word(pdev, PCI_COMMAND, ap->pci_command);
1425 * Configure DMA attributes.
1427 if (!pci_set_dma_mask(pdev, 0xffffffffffffffffULL)) {
1428 ap->pci_using_dac = 1;
1429 } else if (!pci_set_dma_mask(pdev, 0xffffffffULL)) {
1430 ap->pci_using_dac = 0;
1437 * Initialize the generic info block and the command+event rings
1438 * and the control blocks for the transmit and receive rings
1439 * as they need to be setup once and for all.
1441 if (!(info = pci_alloc_consistent(ap->pdev, sizeof(struct ace_info),
1449 * Get the memory for the skb rings.
1451 if (!(ap->skb = kmalloc(sizeof(struct ace_skb), GFP_KERNEL))) {
1456 ecode = request_irq(pdev->irq, ace_interrupt, SA_SHIRQ,
1459 printk(KERN_WARNING "%s: Requested IRQ %d is busy\n",
1460 dev->name, pdev->irq);
1463 dev->irq = pdev->irq;
1466 * Register the device here to be able to catch allocated
1467 * interrupt handlers in case the firmware doesn't come up.
1469 ap->next = root_dev;
1473 spin_lock_init(&ap->debug_lock);
1474 ap->last_tx = ACE_TX_RING_ENTRIES(ap) - 1;
1475 ap->last_std_rx = 0;
1476 ap->last_mini_rx = 0;
1479 memset(ap->info, 0, sizeof(struct ace_info));
1480 memset(ap->skb, 0, sizeof(struct ace_skb));
1482 ace_load_firmware(dev);
1485 tmp_ptr = ap->info_dma;
1486 writel(tmp_ptr >> 32, ®s->InfoPtrHi);
1487 writel(tmp_ptr & 0xffffffff, ®s->InfoPtrLo);
1489 memset(ap->evt_ring, 0, EVT_RING_ENTRIES * sizeof(struct event));
1491 set_aceaddr(&info->evt_ctrl.rngptr, ap->evt_ring_dma);
1492 info->evt_ctrl.flags = 0;
1496 set_aceaddr(&info->evt_prd_ptr, ap->evt_prd_dma);
1497 writel(0, ®s->EvtCsm);
1499 set_aceaddr(&info->cmd_ctrl.rngptr, 0x100);
1500 info->cmd_ctrl.flags = 0;
1501 info->cmd_ctrl.max_len = 0;
1503 for (i = 0; i < CMD_RING_ENTRIES; i++)
1504 writel(0, ®s->CmdRng[i]);
1506 writel(0, ®s->CmdPrd);
1507 writel(0, ®s->CmdCsm);
1509 tmp_ptr = ap->info_dma;
1510 tmp_ptr += (unsigned long) &(((struct ace_info *)0)->s.stats);
1511 set_aceaddr(&info->stats2_ptr, (dma_addr_t) tmp_ptr);
1513 set_aceaddr(&info->rx_std_ctrl.rngptr, ap->rx_ring_base_dma);
1514 info->rx_std_ctrl.max_len = ACE_STD_MTU + ETH_HLEN + 4;
1515 info->rx_std_ctrl.flags =
1516 RCB_FLG_TCP_UDP_SUM | RCB_FLG_NO_PSEUDO_HDR | ACE_RCB_VLAN_FLAG;
1518 memset(ap->rx_std_ring, 0,
1519 RX_STD_RING_ENTRIES * sizeof(struct rx_desc));
1521 for (i = 0; i < RX_STD_RING_ENTRIES; i++)
1522 ap->rx_std_ring[i].flags = BD_FLG_TCP_UDP_SUM;
1524 ap->rx_std_skbprd = 0;
1525 atomic_set(&ap->cur_rx_bufs, 0);
1527 set_aceaddr(&info->rx_jumbo_ctrl.rngptr,
1528 (ap->rx_ring_base_dma +
1529 (sizeof(struct rx_desc) * RX_STD_RING_ENTRIES)));
1530 info->rx_jumbo_ctrl.max_len = 0;
1531 info->rx_jumbo_ctrl.flags =
1532 RCB_FLG_TCP_UDP_SUM | RCB_FLG_NO_PSEUDO_HDR | ACE_RCB_VLAN_FLAG;
1534 memset(ap->rx_jumbo_ring, 0,
1535 RX_JUMBO_RING_ENTRIES * sizeof(struct rx_desc));
1537 for (i = 0; i < RX_JUMBO_RING_ENTRIES; i++)
1538 ap->rx_jumbo_ring[i].flags = BD_FLG_TCP_UDP_SUM | BD_FLG_JUMBO;
1540 ap->rx_jumbo_skbprd = 0;
1541 atomic_set(&ap->cur_jumbo_bufs, 0);
1543 memset(ap->rx_mini_ring, 0,
1544 RX_MINI_RING_ENTRIES * sizeof(struct rx_desc));
1546 if (ap->version >= 2) {
1547 set_aceaddr(&info->rx_mini_ctrl.rngptr,
1548 (ap->rx_ring_base_dma +
1549 (sizeof(struct rx_desc) *
1550 (RX_STD_RING_ENTRIES +
1551 RX_JUMBO_RING_ENTRIES))));
1552 info->rx_mini_ctrl.max_len = ACE_MINI_SIZE;
1553 info->rx_mini_ctrl.flags =
1554 RCB_FLG_TCP_UDP_SUM|RCB_FLG_NO_PSEUDO_HDR|ACE_RCB_VLAN_FLAG;
1556 for (i = 0; i < RX_MINI_RING_ENTRIES; i++)
1557 ap->rx_mini_ring[i].flags =
1558 BD_FLG_TCP_UDP_SUM | BD_FLG_MINI;
1560 set_aceaddr(&info->rx_mini_ctrl.rngptr, 0);
1561 info->rx_mini_ctrl.flags = RCB_FLG_RNG_DISABLE;
1562 info->rx_mini_ctrl.max_len = 0;
1565 ap->rx_mini_skbprd = 0;
1566 atomic_set(&ap->cur_mini_bufs, 0);
1568 set_aceaddr(&info->rx_return_ctrl.rngptr,
1569 (ap->rx_ring_base_dma +
1570 (sizeof(struct rx_desc) *
1571 (RX_STD_RING_ENTRIES +
1572 RX_JUMBO_RING_ENTRIES +
1573 RX_MINI_RING_ENTRIES))));
1574 info->rx_return_ctrl.flags = 0;
1575 info->rx_return_ctrl.max_len = RX_RETURN_RING_ENTRIES;
1577 memset(ap->rx_return_ring, 0,
1578 RX_RETURN_RING_ENTRIES * sizeof(struct rx_desc));
1580 set_aceaddr(&info->rx_ret_prd_ptr, ap->rx_ret_prd_dma);
1581 *(ap->rx_ret_prd) = 0;
1583 writel(TX_RING_BASE, ®s->WinBase);
1585 if (ACE_IS_TIGON_I(ap)) {
1586 ap->tx_ring = (struct tx_desc *)regs->Window;
1587 for (i = 0; i < (TIGON_I_TX_RING_ENTRIES *
1588 sizeof(struct tx_desc) / 4); i++) {
1589 writel(0, (unsigned long)ap->tx_ring + i * 4);
1592 set_aceaddr(&info->tx_ctrl.rngptr, TX_RING_BASE);
1594 memset(ap->tx_ring, 0,
1595 MAX_TX_RING_ENTRIES * sizeof(struct tx_desc));
1597 set_aceaddr(&info->tx_ctrl.rngptr, ap->tx_ring_dma);
1600 info->tx_ctrl.max_len = ACE_TX_RING_ENTRIES(ap);
1601 tmp = RCB_FLG_TCP_UDP_SUM | RCB_FLG_NO_PSEUDO_HDR | ACE_RCB_VLAN_FLAG;
1604 * The Tigon I does not like having the TX ring in host memory ;-(
1606 if (!ACE_IS_TIGON_I(ap))
1607 tmp |= RCB_FLG_TX_HOST_RING;
1608 #if TX_COAL_INTS_ONLY
1609 tmp |= RCB_FLG_COAL_INT_ONLY;
1611 info->tx_ctrl.flags = tmp;
1613 set_aceaddr(&info->tx_csm_ptr, ap->tx_csm_dma);
1616 * Potential item for tuning parameter
1619 writel(DMA_THRESH_16W, ®s->DmaReadCfg);
1620 writel(DMA_THRESH_16W, ®s->DmaWriteCfg);
1622 writel(DMA_THRESH_8W, ®s->DmaReadCfg);
1623 writel(DMA_THRESH_8W, ®s->DmaWriteCfg);
1626 writel(0, ®s->MaskInt);
1627 writel(1, ®s->IfIdx);
1630 * McKinley boxes do not like us fiddling with AssistState
1633 writel(1, ®s->AssistState);
1636 writel(DEF_STAT, ®s->TuneStatTicks);
1637 writel(DEF_TRACE, ®s->TuneTrace);
1639 ace_set_rxtx_parms(dev, 0);
1641 if (board_idx == BOARD_IDX_OVERFLOW) {
1642 printk(KERN_WARNING "%s: more than %i NICs detected, "
1643 "ignoring module parameters!\n",
1644 dev->name, ACE_MAX_MOD_PARMS);
1645 } else if (board_idx >= 0) {
1646 if (tx_coal_tick[board_idx])
1647 writel(tx_coal_tick[board_idx],
1648 ®s->TuneTxCoalTicks);
1649 if (max_tx_desc[board_idx])
1650 writel(max_tx_desc[board_idx], ®s->TuneMaxTxDesc);
1652 if (rx_coal_tick[board_idx])
1653 writel(rx_coal_tick[board_idx],
1654 ®s->TuneRxCoalTicks);
1655 if (max_rx_desc[board_idx])
1656 writel(max_rx_desc[board_idx], ®s->TuneMaxRxDesc);
1658 if (trace[board_idx])
1659 writel(trace[board_idx], ®s->TuneTrace);
1661 if ((tx_ratio[board_idx] > 0) && (tx_ratio[board_idx] < 64))
1662 writel(tx_ratio[board_idx], ®s->TxBufRat);
1666 * Default link parameters
1668 tmp = LNK_ENABLE | LNK_FULL_DUPLEX | LNK_1000MB | LNK_100MB |
1669 LNK_10MB | LNK_RX_FLOW_CTL_Y | LNK_NEG_FCTL | LNK_NEGOTIATE;
1670 if(ap->version >= 2)
1671 tmp |= LNK_TX_FLOW_CTL_Y;
1674 * Override link default parameters
1676 if ((board_idx >= 0) && link[board_idx]) {
1677 int option = link[board_idx];
1681 if (option & 0x01) {
1682 printk(KERN_INFO "%s: Setting half duplex link\n",
1684 tmp &= ~LNK_FULL_DUPLEX;
1687 tmp &= ~LNK_NEGOTIATE;
1694 if ((option & 0x70) == 0) {
1695 printk(KERN_WARNING "%s: No media speed specified, "
1696 "forcing auto negotiation\n", dev->name);
1697 tmp |= LNK_NEGOTIATE | LNK_1000MB |
1698 LNK_100MB | LNK_10MB;
1700 if ((option & 0x100) == 0)
1701 tmp |= LNK_NEG_FCTL;
1703 printk(KERN_INFO "%s: Disabling flow control "
1704 "negotiation\n", dev->name);
1706 tmp |= LNK_RX_FLOW_CTL_Y;
1707 if ((option & 0x400) && (ap->version >= 2)) {
1708 printk(KERN_INFO "%s: Enabling TX flow control\n",
1710 tmp |= LNK_TX_FLOW_CTL_Y;
1715 writel(tmp, ®s->TuneLink);
1716 if (ap->version >= 2)
1717 writel(tmp, ®s->TuneFastLink);
1719 if (ACE_IS_TIGON_I(ap))
1720 writel(tigonFwStartAddr, ®s->Pc);
1721 if (ap->version == 2)
1722 writel(tigon2FwStartAddr, ®s->Pc);
1724 writel(0, ®s->Mb0Lo);
1727 * Set tx_csm before we start receiving interrupts, otherwise
1728 * the interrupt handler might think it is supposed to process
1729 * tx ints before we are up and running, which may cause a null
1730 * pointer access in the int handler.
1733 ap->tx_prd = *(ap->tx_csm) = ap->tx_ret_csm = 0;
1736 ace_set_txprd(regs, ap, 0);
1737 writel(0, ®s->RxRetCsm);
1740 * Zero the stats before starting the interface
1742 memset(&ap->stats, 0, sizeof(ap->stats));
1745 * Enable DMA engine now.
1746 * If we do this sooner, Mckinley box pukes.
1747 * I assume it's because Tigon II DMA engine wants to check
1748 * *something* even before the CPU is started.
1750 writel(1, ®s->AssistState); /* enable DMA */
1755 writel(readl(®s->CpuCtrl) & ~(CPU_HALT|CPU_TRACE), ®s->CpuCtrl);
1756 readl(®s->CpuCtrl);
1759 * Wait for the firmware to spin up - max 3 seconds.
1761 myjif = jiffies + 3 * HZ;
1762 while (time_before(jiffies, myjif) && !ap->fw_running)
1765 if (!ap->fw_running) {
1766 printk(KERN_ERR "%s: Firmware NOT running!\n", dev->name);
1769 writel(readl(®s->CpuCtrl) | CPU_HALT, ®s->CpuCtrl);
1770 readl(®s->CpuCtrl);
1772 /* aman@sgi.com - account for badly behaving firmware/NIC:
1773 * - have observed that the NIC may continue to generate
1774 * interrupts for some reason; attempt to stop it - halt
1775 * second CPU for Tigon II cards, and also clear Mb0
1776 * - if we're a module, we'll fail to load if this was
1777 * the only GbE card in the system => if the kernel does
1778 * see an interrupt from the NIC, code to handle it is
1779 * gone and OOps! - so free_irq also
1781 if (ap->version >= 2)
1782 writel(readl(®s->CpuBCtrl) | CPU_HALT,
1784 writel(0, ®s->Mb0Lo);
1785 readl(®s->Mb0Lo);
1792 * We load the ring here as there seem to be no way to tell the
1793 * firmware to wipe the ring without re-initializing it.
1795 if (!test_and_set_bit(0, &ap->std_refill_busy))
1796 ace_load_std_rx_ring(ap, RX_RING_SIZE);
1798 printk(KERN_ERR "%s: Someone is busy refilling the RX ring\n",
1800 if (ap->version >= 2) {
1801 if (!test_and_set_bit(0, &ap->mini_refill_busy))
1802 ace_load_mini_rx_ring(ap, RX_MINI_SIZE);
1804 printk(KERN_ERR "%s: Someone is busy refilling "
1805 "the RX mini ring\n", dev->name);
1810 ace_init_cleanup(dev);
1815 static void ace_set_rxtx_parms(struct net_device *dev, int jumbo)
1817 struct ace_private *ap;
1818 struct ace_regs *regs;
1824 board_idx = ap->board_idx;
1826 if (board_idx >= 0) {
1828 if (!tx_coal_tick[board_idx])
1829 writel(DEF_TX_COAL, ®s->TuneTxCoalTicks);
1830 if (!max_tx_desc[board_idx])
1831 writel(DEF_TX_MAX_DESC, ®s->TuneMaxTxDesc);
1832 if (!rx_coal_tick[board_idx])
1833 writel(DEF_RX_COAL, ®s->TuneRxCoalTicks);
1834 if (!max_rx_desc[board_idx])
1835 writel(DEF_RX_MAX_DESC, ®s->TuneMaxRxDesc);
1836 if (!tx_ratio[board_idx])
1837 writel(DEF_TX_RATIO, ®s->TxBufRat);
1839 if (!tx_coal_tick[board_idx])
1840 writel(DEF_JUMBO_TX_COAL,
1841 ®s->TuneTxCoalTicks);
1842 if (!max_tx_desc[board_idx])
1843 writel(DEF_JUMBO_TX_MAX_DESC,
1844 ®s->TuneMaxTxDesc);
1845 if (!rx_coal_tick[board_idx])
1846 writel(DEF_JUMBO_RX_COAL,
1847 ®s->TuneRxCoalTicks);
1848 if (!max_rx_desc[board_idx])
1849 writel(DEF_JUMBO_RX_MAX_DESC,
1850 ®s->TuneMaxRxDesc);
1851 if (!tx_ratio[board_idx])
1852 writel(DEF_JUMBO_TX_RATIO, ®s->TxBufRat);
1858 static void ace_watchdog(struct net_device *data)
1860 struct net_device *dev = data;
1861 struct ace_private *ap = dev->priv;
1862 struct ace_regs *regs = ap->regs;
1865 * We haven't received a stats update event for more than 2.5
1866 * seconds and there is data in the transmit queue, thus we
1867 * asume the card is stuck.
1869 if (*ap->tx_csm != ap->tx_ret_csm) {
1870 printk(KERN_WARNING "%s: Transmitter is stuck, %08x\n",
1871 dev->name, (unsigned int)readl(®s->HostCtrl));
1872 /* This can happen due to ieee flow control. */
1874 printk(KERN_DEBUG "%s: BUG... transmitter died. Kicking it.\n",
1877 netif_wake_queue(dev);
1883 static void ace_tasklet(unsigned long dev)
1885 struct ace_private *ap = ((struct net_device *)dev)->priv;
1888 cur_size = atomic_read(&ap->cur_rx_bufs);
1889 if ((cur_size < RX_LOW_STD_THRES) &&
1890 !test_and_set_bit(0, &ap->std_refill_busy)) {
1892 printk("refilling buffers (current %i)\n", cur_size);
1894 ace_load_std_rx_ring(ap, RX_RING_SIZE - cur_size);
1897 if (ap->version >= 2) {
1898 cur_size = atomic_read(&ap->cur_mini_bufs);
1899 if ((cur_size < RX_LOW_MINI_THRES) &&
1900 !test_and_set_bit(0, &ap->mini_refill_busy)) {
1902 printk("refilling mini buffers (current %i)\n",
1905 ace_load_mini_rx_ring(ap, RX_MINI_SIZE - cur_size);
1909 cur_size = atomic_read(&ap->cur_jumbo_bufs);
1910 if (ap->jumbo && (cur_size < RX_LOW_JUMBO_THRES) &&
1911 !test_and_set_bit(0, &ap->jumbo_refill_busy)) {
1913 printk("refilling jumbo buffers (current %i)\n", cur_size);
1915 ace_load_jumbo_rx_ring(ap, RX_JUMBO_SIZE - cur_size);
1917 ap->tasklet_pending = 0;
1922 * Copy the contents of the NIC's trace buffer to kernel memory.
1924 static void ace_dump_trace(struct ace_private *ap)
1928 if (!(ap->trace_buf = kmalloc(ACE_TRACE_SIZE, GFP_KERNEL)))
1935 * Load the standard rx ring.
1937 * Loading rings is safe without holding the spin lock since this is
1938 * done only before the device is enabled, thus no interrupts are
1939 * generated and by the interrupt handler/tasklet handler.
1941 static void ace_load_std_rx_ring(struct ace_private *ap, int nr_bufs)
1943 struct ace_regs *regs;
1948 prefetchw(&ap->cur_rx_bufs);
1950 idx = ap->rx_std_skbprd;
1952 for (i = 0; i < nr_bufs; i++) {
1953 struct sk_buff *skb;
1957 skb = alloc_skb(ACE_STD_BUFSIZE, GFP_ATOMIC);
1962 * Make sure IP header starts on a fresh cache line.
1964 skb_reserve(skb, 2 + 16);
1965 mapping = pci_map_page(ap->pdev, virt_to_page(skb->data),
1966 offset_in_page(skb->data),
1967 ACE_STD_BUFSIZE - (2 + 16),
1968 PCI_DMA_FROMDEVICE);
1969 ap->skb->rx_std_skbuff[idx].skb = skb;
1970 pci_unmap_addr_set(&ap->skb->rx_std_skbuff[idx],
1973 rd = &ap->rx_std_ring[idx];
1974 set_aceaddr(&rd->addr, mapping);
1975 rd->size = ACE_STD_MTU + ETH_HLEN + 4;
1977 idx = (idx + 1) % RX_STD_RING_ENTRIES;
1983 atomic_add(i, &ap->cur_rx_bufs);
1984 ap->rx_std_skbprd = idx;
1986 if (ACE_IS_TIGON_I(ap)) {
1988 cmd.evt = C_SET_RX_PRD_IDX;
1990 cmd.idx = ap->rx_std_skbprd;
1991 ace_issue_cmd(regs, &cmd);
1993 writel(idx, ®s->RxStdPrd);
1998 clear_bit(0, &ap->std_refill_busy);
2002 printk(KERN_INFO "Out of memory when allocating "
2003 "standard receive buffers\n");
2008 static void ace_load_mini_rx_ring(struct ace_private *ap, int nr_bufs)
2010 struct ace_regs *regs;
2015 prefetchw(&ap->cur_mini_bufs);
2017 idx = ap->rx_mini_skbprd;
2018 for (i = 0; i < nr_bufs; i++) {
2019 struct sk_buff *skb;
2023 skb = alloc_skb(ACE_MINI_BUFSIZE, GFP_ATOMIC);
2028 * Make sure the IP header ends up on a fresh cache line
2030 skb_reserve(skb, 2 + 16);
2031 mapping = pci_map_page(ap->pdev, virt_to_page(skb->data),
2032 offset_in_page(skb->data),
2033 ACE_MINI_BUFSIZE - (2 + 16),
2034 PCI_DMA_FROMDEVICE);
2035 ap->skb->rx_mini_skbuff[idx].skb = skb;
2036 pci_unmap_addr_set(&ap->skb->rx_mini_skbuff[idx],
2039 rd = &ap->rx_mini_ring[idx];
2040 set_aceaddr(&rd->addr, mapping);
2041 rd->size = ACE_MINI_SIZE;
2043 idx = (idx + 1) % RX_MINI_RING_ENTRIES;
2049 atomic_add(i, &ap->cur_mini_bufs);
2051 ap->rx_mini_skbprd = idx;
2053 writel(idx, ®s->RxMiniPrd);
2057 clear_bit(0, &ap->mini_refill_busy);
2060 printk(KERN_INFO "Out of memory when allocating "
2061 "mini receive buffers\n");
2067 * Load the jumbo rx ring, this may happen at any time if the MTU
2068 * is changed to a value > 1500.
2070 static void ace_load_jumbo_rx_ring(struct ace_private *ap, int nr_bufs)
2072 struct ace_regs *regs;
2077 idx = ap->rx_jumbo_skbprd;
2079 for (i = 0; i < nr_bufs; i++) {
2080 struct sk_buff *skb;
2084 skb = alloc_skb(ACE_JUMBO_BUFSIZE, GFP_ATOMIC);
2089 * Make sure the IP header ends up on a fresh cache line
2091 skb_reserve(skb, 2 + 16);
2092 mapping = pci_map_page(ap->pdev, virt_to_page(skb->data),
2093 offset_in_page(skb->data),
2094 ACE_JUMBO_BUFSIZE - (2 + 16),
2095 PCI_DMA_FROMDEVICE);
2096 ap->skb->rx_jumbo_skbuff[idx].skb = skb;
2097 pci_unmap_addr_set(&ap->skb->rx_jumbo_skbuff[idx],
2100 rd = &ap->rx_jumbo_ring[idx];
2101 set_aceaddr(&rd->addr, mapping);
2102 rd->size = ACE_JUMBO_MTU + ETH_HLEN + 4;
2104 idx = (idx + 1) % RX_JUMBO_RING_ENTRIES;
2110 atomic_add(i, &ap->cur_jumbo_bufs);
2111 ap->rx_jumbo_skbprd = idx;
2113 if (ACE_IS_TIGON_I(ap)) {
2115 cmd.evt = C_SET_RX_JUMBO_PRD_IDX;
2117 cmd.idx = ap->rx_jumbo_skbprd;
2118 ace_issue_cmd(regs, &cmd);
2120 writel(idx, ®s->RxJumboPrd);
2125 clear_bit(0, &ap->jumbo_refill_busy);
2128 if (net_ratelimit())
2129 printk(KERN_INFO "Out of memory when allocating "
2130 "jumbo receive buffers\n");
2136 * All events are considered to be slow (RX/TX ints do not generate
2137 * events) and are handled here, outside the main interrupt handler,
2138 * to reduce the size of the handler.
2140 static u32 ace_handle_event(struct net_device *dev, u32 evtcsm, u32 evtprd)
2142 struct ace_private *ap;
2146 while (evtcsm != evtprd) {
2147 switch (ap->evt_ring[evtcsm].evt) {
2149 printk(KERN_INFO "%s: Firmware up and running\n",
2154 case E_STATS_UPDATED:
2158 u16 code = ap->evt_ring[evtcsm].code;
2162 u32 state = readl(&ap->regs->GigLnkState);
2163 printk(KERN_WARNING "%s: Optical link UP "
2164 "(%s Duplex, Flow Control: %s%s)\n",
2166 state & LNK_FULL_DUPLEX ? "Full":"Half",
2167 state & LNK_TX_FLOW_CTL_Y ? "TX " : "",
2168 state & LNK_RX_FLOW_CTL_Y ? "RX" : "");
2172 printk(KERN_WARNING "%s: Optical link DOWN\n",
2175 case E_C_LINK_10_100:
2176 printk(KERN_WARNING "%s: 10/100BaseT link "
2180 printk(KERN_ERR "%s: Unknown optical link "
2181 "state %02x\n", dev->name, code);
2186 switch(ap->evt_ring[evtcsm].code) {
2187 case E_C_ERR_INVAL_CMD:
2188 printk(KERN_ERR "%s: invalid command error\n",
2191 case E_C_ERR_UNIMP_CMD:
2192 printk(KERN_ERR "%s: unimplemented command "
2193 "error\n", dev->name);
2195 case E_C_ERR_BAD_CFG:
2196 printk(KERN_ERR "%s: bad config error\n",
2200 printk(KERN_ERR "%s: unknown error %02x\n",
2201 dev->name, ap->evt_ring[evtcsm].code);
2204 case E_RESET_JUMBO_RNG:
2207 for (i = 0; i < RX_JUMBO_RING_ENTRIES; i++) {
2208 if (ap->skb->rx_jumbo_skbuff[i].skb) {
2209 ap->rx_jumbo_ring[i].size = 0;
2210 set_aceaddr(&ap->rx_jumbo_ring[i].addr, 0);
2211 dev_kfree_skb(ap->skb->rx_jumbo_skbuff[i].skb);
2212 ap->skb->rx_jumbo_skbuff[i].skb = NULL;
2216 if (ACE_IS_TIGON_I(ap)) {
2218 cmd.evt = C_SET_RX_JUMBO_PRD_IDX;
2221 ace_issue_cmd(ap->regs, &cmd);
2223 writel(0, &((ap->regs)->RxJumboPrd));
2228 ap->rx_jumbo_skbprd = 0;
2229 printk(KERN_INFO "%s: Jumbo ring flushed\n",
2231 clear_bit(0, &ap->jumbo_refill_busy);
2235 printk(KERN_ERR "%s: Unhandled event 0x%02x\n",
2236 dev->name, ap->evt_ring[evtcsm].evt);
2238 evtcsm = (evtcsm + 1) % EVT_RING_ENTRIES;
2245 static void ace_rx_int(struct net_device *dev, u32 rxretprd, u32 rxretcsm)
2247 struct ace_private *ap = dev->priv;
2249 int mini_count = 0, std_count = 0;
2253 prefetchw(&ap->cur_rx_bufs);
2254 prefetchw(&ap->cur_mini_bufs);
2256 while (idx != rxretprd) {
2257 struct ring_info *rip;
2258 struct sk_buff *skb;
2259 struct rx_desc *rxdesc, *retdesc;
2261 int bd_flags, desc_type, mapsize;
2264 retdesc = &ap->rx_return_ring[idx];
2265 skbidx = retdesc->idx;
2266 bd_flags = retdesc->flags;
2267 desc_type = bd_flags & (BD_FLG_JUMBO | BD_FLG_MINI);
2271 * Normal frames do not have any flags set
2273 * Mini and normal frames arrive frequently,
2274 * so use a local counter to avoid doing
2275 * atomic operations for each packet arriving.
2278 rip = &ap->skb->rx_std_skbuff[skbidx];
2279 mapsize = ACE_STD_BUFSIZE - (2 + 16);
2280 rxdesc = &ap->rx_std_ring[skbidx];
2284 rip = &ap->skb->rx_jumbo_skbuff[skbidx];
2285 mapsize = ACE_JUMBO_BUFSIZE - (2 + 16);
2286 rxdesc = &ap->rx_jumbo_ring[skbidx];
2287 atomic_dec(&ap->cur_jumbo_bufs);
2290 rip = &ap->skb->rx_mini_skbuff[skbidx];
2291 mapsize = ACE_MINI_BUFSIZE - (2 + 16);
2292 rxdesc = &ap->rx_mini_ring[skbidx];
2296 printk(KERN_INFO "%s: unknown frame type (0x%02x) "
2297 "returned by NIC\n", dev->name,
2304 pci_unmap_page(ap->pdev,
2305 pci_unmap_addr(rip, mapping),
2307 PCI_DMA_FROMDEVICE);
2308 skb_put(skb, retdesc->size);
2313 csum = retdesc->tcp_udp_csum;
2316 skb->protocol = eth_type_trans(skb, dev);
2319 * Instead of forcing the poor tigon mips cpu to calculate
2320 * pseudo hdr checksum, we do this ourselves.
2322 if (bd_flags & BD_FLG_TCP_UDP_SUM) {
2323 skb->csum = htons(csum);
2324 skb->ip_summed = CHECKSUM_HW;
2326 skb->ip_summed = CHECKSUM_NONE;
2331 if (ap->vlgrp && (bd_flags & BD_FLG_VLAN_TAG)) {
2332 vlan_hwaccel_rx(skb, ap->vlgrp, retdesc->vlan);
2337 dev->last_rx = jiffies;
2338 ap->stats.rx_packets++;
2339 ap->stats.rx_bytes += retdesc->size;
2341 idx = (idx + 1) % RX_RETURN_RING_ENTRIES;
2344 atomic_sub(std_count, &ap->cur_rx_bufs);
2345 if (!ACE_IS_TIGON_I(ap))
2346 atomic_sub(mini_count, &ap->cur_mini_bufs);
2350 * According to the documentation RxRetCsm is obsolete with
2351 * the 12.3.x Firmware - my Tigon I NICs seem to disagree!
2353 if (ACE_IS_TIGON_I(ap)) {
2354 struct ace_regs *regs = ap->regs;
2355 writel(idx, ®s->RxRetCsm);
2366 static inline void ace_tx_int(struct net_device *dev,
2369 struct ace_private *ap = dev->priv;
2372 struct sk_buff *skb;
2374 struct tx_ring_info *info;
2376 info = ap->skb->tx_skbuff + idx;
2378 mapping = pci_unmap_addr(info, mapping);
2381 pci_unmap_page(ap->pdev, mapping,
2382 pci_unmap_len(info, maplen),
2384 pci_unmap_addr_set(info, mapping, 0);
2388 ap->stats.tx_packets++;
2389 ap->stats.tx_bytes += skb->len;
2390 dev_kfree_skb_irq(skb);
2394 idx = (idx + 1) % ACE_TX_RING_ENTRIES(ap);
2395 } while (idx != txcsm);
2397 if (netif_queue_stopped(dev))
2398 netif_wake_queue(dev);
2401 ap->tx_ret_csm = txcsm;
2403 /* So... tx_ret_csm is advanced _after_ check for device wakeup.
2405 * We could try to make it before. In this case we would get
2406 * the following race condition: hard_start_xmit on other cpu
2407 * enters after we advanced tx_ret_csm and fills space,
2408 * which we have just freed, so that we make illegal device wakeup.
2409 * There is no good way to workaround this (at entry
2410 * to ace_start_xmit detects this condition and prevents
2411 * ring corruption, but it is not a good workaround.)
2413 * When tx_ret_csm is advanced after, we wake up device _only_
2414 * if we really have some space in ring (though the core doing
2415 * hard_start_xmit can see full ring for some period and has to
2416 * synchronize.) Superb.
2417 * BUT! We get another subtle race condition. hard_start_xmit
2418 * may think that ring is full between wakeup and advancing
2419 * tx_ret_csm and will stop device instantly! It is not so bad.
2420 * We are guaranteed that there is something in ring, so that
2421 * the next irq will resume transmission. To speedup this we could
2422 * mark descriptor, which closes ring with BD_FLG_COAL_NOW
2423 * (see ace_start_xmit).
2425 * Well, this dilemma exists in all lock-free devices.
2426 * We, following scheme used in drivers by Donald Becker,
2427 * select the least dangerous.
2433 static irqreturn_t ace_interrupt(int irq, void *dev_id, struct pt_regs *ptregs)
2435 struct ace_private *ap;
2436 struct ace_regs *regs;
2437 struct net_device *dev = (struct net_device *)dev_id;
2439 u32 txcsm, rxretcsm, rxretprd;
2446 * In case of PCI shared interrupts or spurious interrupts,
2447 * we want to make sure it is actually our interrupt before
2448 * spending any time in here.
2450 if (!(readl(®s->HostCtrl) & IN_INT))
2454 * ACK intr now. Otherwise we will lose updates to rx_ret_prd,
2455 * which happened _after_ rxretprd = *ap->rx_ret_prd; but before
2456 * writel(0, ®s->Mb0Lo).
2458 * "IRQ avoidance" recommended in docs applies to IRQs served
2459 * threads and it is wrong even for that case.
2461 writel(0, ®s->Mb0Lo);
2462 readl(®s->Mb0Lo);
2465 * There is no conflict between transmit handling in
2466 * start_xmit and receive processing, thus there is no reason
2467 * to take a spin lock for RX handling. Wait until we start
2468 * working on the other stuff - hey we don't need a spin lock
2471 rxretprd = *ap->rx_ret_prd;
2472 rxretcsm = ap->cur_rx;
2474 if (rxretprd != rxretcsm)
2475 ace_rx_int(dev, rxretprd, rxretcsm);
2477 txcsm = *ap->tx_csm;
2478 idx = ap->tx_ret_csm;
2482 * If each skb takes only one descriptor this check degenerates
2483 * to identity, because new space has just been opened.
2484 * But if skbs are fragmented we must check that this index
2485 * update releases enough of space, otherwise we just
2486 * wait for device to make more work.
2488 if (!tx_ring_full(ap, txcsm, ap->tx_prd))
2489 ace_tx_int(dev, txcsm, idx);
2492 evtcsm = readl(®s->EvtCsm);
2493 evtprd = *ap->evt_prd;
2495 if (evtcsm != evtprd) {
2496 evtcsm = ace_handle_event(dev, evtcsm, evtprd);
2497 writel(evtcsm, ®s->EvtCsm);
2501 * This has to go last in the interrupt handler and run with
2502 * the spin lock released ... what lock?
2504 if (netif_running(dev)) {
2506 int run_tasklet = 0;
2508 cur_size = atomic_read(&ap->cur_rx_bufs);
2509 if (cur_size < RX_LOW_STD_THRES) {
2510 if ((cur_size < RX_PANIC_STD_THRES) &&
2511 !test_and_set_bit(0, &ap->std_refill_busy)) {
2513 printk("low on std buffers %i\n", cur_size);
2515 ace_load_std_rx_ring(ap,
2516 RX_RING_SIZE - cur_size);
2521 if (!ACE_IS_TIGON_I(ap)) {
2522 cur_size = atomic_read(&ap->cur_mini_bufs);
2523 if (cur_size < RX_LOW_MINI_THRES) {
2524 if ((cur_size < RX_PANIC_MINI_THRES) &&
2525 !test_and_set_bit(0,
2526 &ap->mini_refill_busy)) {
2528 printk("low on mini buffers %i\n",
2531 ace_load_mini_rx_ring(ap, RX_MINI_SIZE - cur_size);
2538 cur_size = atomic_read(&ap->cur_jumbo_bufs);
2539 if (cur_size < RX_LOW_JUMBO_THRES) {
2540 if ((cur_size < RX_PANIC_JUMBO_THRES) &&
2541 !test_and_set_bit(0,
2542 &ap->jumbo_refill_busy)){
2544 printk("low on jumbo buffers %i\n",
2547 ace_load_jumbo_rx_ring(ap, RX_JUMBO_SIZE - cur_size);
2552 if (run_tasklet && !ap->tasklet_pending) {
2553 ap->tasklet_pending = 1;
2554 tasklet_schedule(&ap->ace_tasklet);
2563 static void ace_vlan_rx_register(struct net_device *dev, struct vlan_group *grp)
2565 struct ace_private *ap = dev->priv;
2566 unsigned long flags;
2568 local_irq_save(flags);
2573 ace_unmask_irq(dev);
2574 local_irq_restore(flags);
2578 static void ace_vlan_rx_kill_vid(struct net_device *dev, unsigned short vid)
2580 struct ace_private *ap = dev->priv;
2581 unsigned long flags;
2583 local_irq_save(flags);
2587 ap->vlgrp->vlan_devices[vid] = NULL;
2589 ace_unmask_irq(dev);
2590 local_irq_restore(flags);
2592 #endif /* ACENIC_DO_VLAN */
2595 static int ace_open(struct net_device *dev)
2597 struct ace_private *ap;
2598 struct ace_regs *regs;
2604 if (!(ap->fw_running)) {
2605 printk(KERN_WARNING "%s: Firmware not running!\n", dev->name);
2609 writel(dev->mtu + ETH_HLEN + 4, ®s->IfMtu);
2611 cmd.evt = C_CLEAR_STATS;
2614 ace_issue_cmd(regs, &cmd);
2616 cmd.evt = C_HOST_STATE;
2617 cmd.code = C_C_STACK_UP;
2619 ace_issue_cmd(regs, &cmd);
2622 !test_and_set_bit(0, &ap->jumbo_refill_busy))
2623 ace_load_jumbo_rx_ring(ap, RX_JUMBO_SIZE);
2625 if (dev->flags & IFF_PROMISC) {
2626 cmd.evt = C_SET_PROMISC_MODE;
2627 cmd.code = C_C_PROMISC_ENABLE;
2629 ace_issue_cmd(regs, &cmd);
2637 cmd.evt = C_LNK_NEGOTIATION;
2640 ace_issue_cmd(regs, &cmd);
2643 netif_start_queue(dev);
2645 ACE_MOD_INC_USE_COUNT;
2648 * Setup the bottom half rx ring refill handler
2650 tasklet_init(&ap->ace_tasklet, ace_tasklet, (unsigned long)dev);
2655 static int ace_close(struct net_device *dev)
2657 struct ace_private *ap;
2658 struct ace_regs *regs;
2660 unsigned long flags;
2666 * Without (or before) releasing irq and stopping hardware, this
2667 * is an absolute non-sense, by the way. It will be reset instantly
2670 netif_stop_queue(dev);
2676 cmd.evt = C_SET_PROMISC_MODE;
2677 cmd.code = C_C_PROMISC_DISABLE;
2679 ace_issue_cmd(regs, &cmd);
2683 cmd.evt = C_HOST_STATE;
2684 cmd.code = C_C_STACK_DOWN;
2686 ace_issue_cmd(regs, &cmd);
2688 tasklet_kill(&ap->ace_tasklet);
2691 * Make sure one CPU is not processing packets while
2692 * buffers are being released by another.
2695 local_irq_save(flags);
2698 for (i = 0; i < ACE_TX_RING_ENTRIES(ap); i++) {
2699 struct sk_buff *skb;
2701 struct tx_ring_info *info;
2703 info = ap->skb->tx_skbuff + i;
2705 mapping = pci_unmap_addr(info, mapping);
2708 if (ACE_IS_TIGON_I(ap)) {
2709 writel(0, &ap->tx_ring[i].addr.addrhi);
2710 writel(0, &ap->tx_ring[i].addr.addrlo);
2711 writel(0, &ap->tx_ring[i].flagsize);
2713 memset(ap->tx_ring + i, 0,
2714 sizeof(struct tx_desc));
2715 pci_unmap_page(ap->pdev, mapping,
2716 pci_unmap_len(info, maplen),
2718 pci_unmap_addr_set(info, mapping, 0);
2727 cmd.evt = C_RESET_JUMBO_RNG;
2730 ace_issue_cmd(regs, &cmd);
2733 ace_unmask_irq(dev);
2734 local_irq_restore(flags);
2736 ACE_MOD_DEC_USE_COUNT;
2741 static inline dma_addr_t
2742 ace_map_tx_skb(struct ace_private *ap, struct sk_buff *skb,
2743 struct sk_buff *tail, u32 idx)
2746 struct tx_ring_info *info;
2748 mapping = pci_map_page(ap->pdev, virt_to_page(skb->data),
2749 offset_in_page(skb->data),
2750 skb->len, PCI_DMA_TODEVICE);
2752 info = ap->skb->tx_skbuff + idx;
2754 pci_unmap_addr_set(info, mapping, mapping);
2755 pci_unmap_len_set(info, maplen, skb->len);
2761 ace_load_tx_bd(struct ace_private *ap, struct tx_desc *desc, u64 addr,
2762 u32 flagsize, u32 vlan_tag)
2764 #if !USE_TX_COAL_NOW
2765 flagsize &= ~BD_FLG_COAL_NOW;
2768 if (ACE_IS_TIGON_I(ap)) {
2769 writel(addr >> 32, &desc->addr.addrhi);
2770 writel(addr & 0xffffffff, &desc->addr.addrlo);
2771 writel(flagsize, &desc->flagsize);
2773 writel(vlan_tag, &desc->vlanres);
2776 desc->addr.addrhi = addr >> 32;
2777 desc->addr.addrlo = addr;
2778 desc->flagsize = flagsize;
2780 desc->vlanres = vlan_tag;
2786 static int ace_start_xmit(struct sk_buff *skb, struct net_device *dev)
2788 struct ace_private *ap = dev->priv;
2789 struct ace_regs *regs = ap->regs;
2790 struct tx_desc *desc;
2794 * This only happens with pre-softnet, ie. 2.2.x kernels.
2796 if (early_stop_netif_stop_queue(dev))
2802 if (tx_ring_full(ap, ap->tx_ret_csm, idx))
2806 if (!skb_shinfo(skb)->nr_frags)
2812 mapping = ace_map_tx_skb(ap, skb, skb, idx);
2813 flagsize = (skb->len << 16) | (BD_FLG_END);
2814 if (skb->ip_summed == CHECKSUM_HW)
2815 flagsize |= BD_FLG_TCP_UDP_SUM;
2817 if (vlan_tx_tag_present(skb)) {
2818 flagsize |= BD_FLG_VLAN_TAG;
2819 vlan_tag = vlan_tx_tag_get(skb);
2822 desc = ap->tx_ring + idx;
2823 idx = (idx + 1) % ACE_TX_RING_ENTRIES(ap);
2825 /* Look at ace_tx_int for explanations. */
2826 if (tx_ring_full(ap, ap->tx_ret_csm, idx))
2827 flagsize |= BD_FLG_COAL_NOW;
2829 ace_load_tx_bd(ap, desc, mapping, flagsize, vlan_tag);
2837 mapping = ace_map_tx_skb(ap, skb, NULL, idx);
2838 flagsize = (skb_headlen(skb) << 16);
2839 if (skb->ip_summed == CHECKSUM_HW)
2840 flagsize |= BD_FLG_TCP_UDP_SUM;
2842 if (vlan_tx_tag_present(skb)) {
2843 flagsize |= BD_FLG_VLAN_TAG;
2844 vlan_tag = vlan_tx_tag_get(skb);
2848 ace_load_tx_bd(ap, ap->tx_ring + idx, mapping, flagsize, vlan_tag);
2850 idx = (idx + 1) % ACE_TX_RING_ENTRIES(ap);
2852 for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) {
2853 skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
2854 struct tx_ring_info *info;
2857 info = ap->skb->tx_skbuff + idx;
2858 desc = ap->tx_ring + idx;
2860 mapping = pci_map_page(ap->pdev, frag->page,
2861 frag->page_offset, frag->size,
2864 flagsize = (frag->size << 16);
2865 if (skb->ip_summed == CHECKSUM_HW)
2866 flagsize |= BD_FLG_TCP_UDP_SUM;
2867 idx = (idx + 1) % ACE_TX_RING_ENTRIES(ap);
2869 if (i == skb_shinfo(skb)->nr_frags - 1) {
2870 flagsize |= BD_FLG_END;
2871 if (tx_ring_full(ap, ap->tx_ret_csm, idx))
2872 flagsize |= BD_FLG_COAL_NOW;
2875 * Only the last fragment frees
2882 pci_unmap_addr_set(info, mapping, mapping);
2883 pci_unmap_len_set(info, maplen, frag->size);
2884 ace_load_tx_bd(ap, desc, mapping, flagsize, vlan_tag);
2891 ace_set_txprd(regs, ap, idx);
2893 if (flagsize & BD_FLG_COAL_NOW) {
2894 netif_stop_queue(dev);
2897 * A TX-descriptor producer (an IRQ) might have gotten
2898 * inbetween, making the ring free again. Since xmit is
2899 * serialized, this is the only situation we have to
2902 if (!tx_ring_full(ap, ap->tx_ret_csm, idx))
2903 netif_wake_queue(dev);
2906 dev->trans_start = jiffies;
2911 * This race condition is unavoidable with lock-free drivers.
2912 * We wake up the queue _before_ tx_prd is advanced, so that we can
2913 * enter hard_start_xmit too early, while tx ring still looks closed.
2914 * This happens ~1-4 times per 100000 packets, so that we can allow
2915 * to loop syncing to other CPU. Probably, we need an additional
2916 * wmb() in ace_tx_intr as well.
2918 * Note that this race is relieved by reserving one more entry
2919 * in tx ring than it is necessary (see original non-SG driver).
2920 * However, with SG we need to reserve 2*MAX_SKB_FRAGS+1, which
2921 * is already overkill.
2923 * Alternative is to return with 1 not throttling queue. In this
2924 * case loop becomes longer, no more useful effects.
2931 static int ace_change_mtu(struct net_device *dev, int new_mtu)
2933 struct ace_private *ap = dev->priv;
2934 struct ace_regs *regs = ap->regs;
2936 if (new_mtu > ACE_JUMBO_MTU)
2939 writel(new_mtu + ETH_HLEN + 4, ®s->IfMtu);
2942 if (new_mtu > ACE_STD_MTU) {
2944 printk(KERN_INFO "%s: Enabling Jumbo frame "
2945 "support\n", dev->name);
2947 if (!test_and_set_bit(0, &ap->jumbo_refill_busy))
2948 ace_load_jumbo_rx_ring(ap, RX_JUMBO_SIZE);
2949 ace_set_rxtx_parms(dev, 1);
2952 while (test_and_set_bit(0, &ap->jumbo_refill_busy));
2953 ace_sync_irq(dev->irq);
2954 ace_set_rxtx_parms(dev, 0);
2958 cmd.evt = C_RESET_JUMBO_RNG;
2961 ace_issue_cmd(regs, &cmd);
2969 static int ace_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
2971 struct ace_private *ap = dev->priv;
2972 struct ace_regs *regs = ap->regs;
2974 struct ethtool_cmd ecmd;
2977 if (cmd != SIOCETHTOOL)
2979 if (copy_from_user(&ecmd, ifr->ifr_data, sizeof(ecmd)))
2984 (SUPPORTED_10baseT_Half | SUPPORTED_10baseT_Full |
2985 SUPPORTED_100baseT_Half | SUPPORTED_100baseT_Full |
2986 SUPPORTED_1000baseT_Half | SUPPORTED_1000baseT_Full |
2987 SUPPORTED_Autoneg | SUPPORTED_FIBRE);
2989 ecmd.port = PORT_FIBRE;
2990 ecmd.transceiver = XCVR_INTERNAL;
2991 ecmd.phy_address = 0;
2993 link = readl(®s->GigLnkState);
2994 if (link & LNK_1000MB)
2995 ecmd.speed = SPEED_1000;
2997 link = readl(®s->FastLnkState);
2998 if (link & LNK_100MB)
2999 ecmd.speed = SPEED_100;
3000 else if (link & LNK_100MB)
3001 ecmd.speed = SPEED_10;
3005 if (link & LNK_FULL_DUPLEX)
3006 ecmd.duplex = DUPLEX_FULL;
3008 ecmd.duplex = DUPLEX_HALF;
3010 if (link & LNK_NEGOTIATE)
3011 ecmd.autoneg = AUTONEG_ENABLE;
3013 ecmd.autoneg = AUTONEG_DISABLE;
3017 * Current struct ethtool_cmd is insufficient
3019 ecmd.trace = readl(®s->TuneTrace);
3021 ecmd.txcoal = readl(®s->TuneTxCoalTicks);
3022 ecmd.rxcoal = readl(®s->TuneRxCoalTicks);
3024 ecmd.maxtxpkt = readl(®s->TuneMaxTxDesc);
3025 ecmd.maxrxpkt = readl(®s->TuneMaxRxDesc);
3027 if(copy_to_user(ifr->ifr_data, &ecmd, sizeof(ecmd)))
3032 link = readl(®s->GigLnkState);
3033 if (link & LNK_1000MB)
3036 link = readl(®s->FastLnkState);
3037 if (link & LNK_100MB)
3039 else if (link & LNK_100MB)
3045 link = LNK_ENABLE | LNK_1000MB | LNK_100MB | LNK_10MB |
3046 LNK_RX_FLOW_CTL_Y | LNK_NEG_FCTL;
3047 if (!ACE_IS_TIGON_I(ap))
3048 link |= LNK_TX_FLOW_CTL_Y;
3049 if (ecmd.autoneg == AUTONEG_ENABLE)
3050 link |= LNK_NEGOTIATE;
3051 if (ecmd.speed != speed) {
3052 link &= ~(LNK_1000MB | LNK_100MB | LNK_10MB);
3065 if (ecmd.duplex == DUPLEX_FULL)
3066 link |= LNK_FULL_DUPLEX;
3068 if (link != ap->link) {
3070 printk(KERN_INFO "%s: Renegotiating link state\n",
3074 writel(link, ®s->TuneLink);
3075 if (!ACE_IS_TIGON_I(ap))
3076 writel(link, ®s->TuneFastLink);
3079 cmd.evt = C_LNK_NEGOTIATION;
3082 ace_issue_cmd(regs, &cmd);
3086 case ETHTOOL_GDRVINFO: {
3087 struct ethtool_drvinfo info = {ETHTOOL_GDRVINFO};
3088 strncpy(info.driver, "acenic", sizeof(info.driver) - 1);
3089 sprintf(info.fw_version, "%i.%i.%i",
3090 tigonFwReleaseMajor, tigonFwReleaseMinor,
3092 strncpy(info.version, version, sizeof(info.version) - 1);
3094 strcpy(info.bus_info, pci_name(ap->pdev));
3095 if (copy_to_user(ifr->ifr_data, &info, sizeof(info)))
3110 * Set the hardware MAC address.
3112 static int ace_set_mac_addr(struct net_device *dev, void *p)
3114 struct sockaddr *addr=p;
3115 struct ace_regs *regs;
3119 if(netif_running(dev))
3122 memcpy(dev->dev_addr, addr->sa_data,dev->addr_len);
3124 da = (u8 *)dev->dev_addr;
3126 regs = ((struct ace_private *)dev->priv)->regs;
3127 writel(da[0] << 8 | da[1], ®s->MacAddrHi);
3128 writel((da[2] << 24) | (da[3] << 16) | (da[4] << 8) | da[5],
3131 cmd.evt = C_SET_MAC_ADDR;
3134 ace_issue_cmd(regs, &cmd);
3140 static void ace_set_multicast_list(struct net_device *dev)
3142 struct ace_private *ap = dev->priv;
3143 struct ace_regs *regs = ap->regs;
3146 if ((dev->flags & IFF_ALLMULTI) && !(ap->mcast_all)) {
3147 cmd.evt = C_SET_MULTICAST_MODE;
3148 cmd.code = C_C_MCAST_ENABLE;
3150 ace_issue_cmd(regs, &cmd);
3152 } else if (ap->mcast_all) {
3153 cmd.evt = C_SET_MULTICAST_MODE;
3154 cmd.code = C_C_MCAST_DISABLE;
3156 ace_issue_cmd(regs, &cmd);
3160 if ((dev->flags & IFF_PROMISC) && !(ap->promisc)) {
3161 cmd.evt = C_SET_PROMISC_MODE;
3162 cmd.code = C_C_PROMISC_ENABLE;
3164 ace_issue_cmd(regs, &cmd);
3166 }else if (!(dev->flags & IFF_PROMISC) && (ap->promisc)) {
3167 cmd.evt = C_SET_PROMISC_MODE;
3168 cmd.code = C_C_PROMISC_DISABLE;
3170 ace_issue_cmd(regs, &cmd);
3175 * For the time being multicast relies on the upper layers
3176 * filtering it properly. The Firmware does not allow one to
3177 * set the entire multicast list at a time and keeping track of
3178 * it here is going to be messy.
3180 if ((dev->mc_count) && !(ap->mcast_all)) {
3181 cmd.evt = C_SET_MULTICAST_MODE;
3182 cmd.code = C_C_MCAST_ENABLE;
3184 ace_issue_cmd(regs, &cmd);
3185 }else if (!ap->mcast_all) {
3186 cmd.evt = C_SET_MULTICAST_MODE;
3187 cmd.code = C_C_MCAST_DISABLE;
3189 ace_issue_cmd(regs, &cmd);
3194 static struct net_device_stats *ace_get_stats(struct net_device *dev)
3196 struct ace_private *ap = dev->priv;
3197 struct ace_mac_stats *mac_stats =
3198 (struct ace_mac_stats *)ap->regs->Stats;
3200 ap->stats.rx_missed_errors = readl(&mac_stats->drop_space);
3201 ap->stats.multicast = readl(&mac_stats->kept_mc);
3202 ap->stats.collisions = readl(&mac_stats->coll);
3208 static void __init ace_copy(struct ace_regs *regs, void *src,
3211 unsigned long tdest;
3219 tsize = min_t(u32, ((~dest & (ACE_WINDOW_SIZE - 1)) + 1),
3220 min_t(u32, size, ACE_WINDOW_SIZE));
3221 tdest = (unsigned long)®s->Window +
3222 (dest & (ACE_WINDOW_SIZE - 1));
3223 writel(dest & ~(ACE_WINDOW_SIZE - 1), ®s->WinBase);
3225 * This requires byte swapping on big endian, however
3226 * writel does that for us
3229 for (i = 0; i < (tsize / 4); i++) {
3230 writel(wsrc[i], tdest + i*4);
3241 static void __init ace_clear(struct ace_regs *regs, u32 dest, int size)
3243 unsigned long tdest;
3250 tsize = min_t(u32, ((~dest & (ACE_WINDOW_SIZE - 1)) + 1),
3251 min_t(u32, size, ACE_WINDOW_SIZE));
3252 tdest = (unsigned long)®s->Window +
3253 (dest & (ACE_WINDOW_SIZE - 1));
3254 writel(dest & ~(ACE_WINDOW_SIZE - 1), ®s->WinBase);
3256 for (i = 0; i < (tsize / 4); i++) {
3257 writel(0, tdest + i*4);
3269 * Download the firmware into the SRAM on the NIC
3271 * This operation requires the NIC to be halted and is performed with
3272 * interrupts disabled and with the spinlock hold.
3274 int __init ace_load_firmware(struct net_device *dev)
3276 struct ace_private *ap;
3277 struct ace_regs *regs;
3282 if (!(readl(®s->CpuCtrl) & CPU_HALTED)) {
3283 printk(KERN_ERR "%s: trying to download firmware while the "
3284 "CPU is running!\n", dev->name);
3289 * Do not try to clear more than 512KB or we end up seeing
3290 * funny things on NICs with only 512KB SRAM
3292 ace_clear(regs, 0x2000, 0x80000-0x2000);
3293 if (ACE_IS_TIGON_I(ap)) {
3294 ace_copy(regs, tigonFwText, tigonFwTextAddr, tigonFwTextLen);
3295 ace_copy(regs, tigonFwData, tigonFwDataAddr, tigonFwDataLen);
3296 ace_copy(regs, tigonFwRodata, tigonFwRodataAddr,
3298 ace_clear(regs, tigonFwBssAddr, tigonFwBssLen);
3299 ace_clear(regs, tigonFwSbssAddr, tigonFwSbssLen);
3300 }else if (ap->version == 2) {
3301 ace_clear(regs, tigon2FwBssAddr, tigon2FwBssLen);
3302 ace_clear(regs, tigon2FwSbssAddr, tigon2FwSbssLen);
3303 ace_copy(regs, tigon2FwText, tigon2FwTextAddr,tigon2FwTextLen);
3304 ace_copy(regs, tigon2FwRodata, tigon2FwRodataAddr,
3306 ace_copy(regs, tigon2FwData, tigon2FwDataAddr,tigon2FwDataLen);
3314 * The eeprom on the AceNIC is an Atmel i2c EEPROM.
3316 * Accessing the EEPROM is `interesting' to say the least - don't read
3317 * this code right after dinner.
3319 * This is all about black magic and bit-banging the device .... I
3320 * wonder in what hospital they have put the guy who designed the i2c
3323 * Oh yes, this is only the beginning!
3325 * Thanks to Stevarino Webinski for helping tracking down the bugs in the
3326 * code i2c readout code by beta testing all my hacks.
3328 static void __init eeprom_start(struct ace_regs *regs)
3332 readl(®s->LocalCtrl);
3333 udelay(ACE_SHORT_DELAY);
3334 local = readl(®s->LocalCtrl);
3335 local |= EEPROM_DATA_OUT | EEPROM_WRITE_ENABLE;
3336 writel(local, ®s->LocalCtrl);
3337 readl(®s->LocalCtrl);
3339 udelay(ACE_SHORT_DELAY);
3340 local |= EEPROM_CLK_OUT;
3341 writel(local, ®s->LocalCtrl);
3342 readl(®s->LocalCtrl);
3344 udelay(ACE_SHORT_DELAY);
3345 local &= ~EEPROM_DATA_OUT;
3346 writel(local, ®s->LocalCtrl);
3347 readl(®s->LocalCtrl);
3349 udelay(ACE_SHORT_DELAY);
3350 local &= ~EEPROM_CLK_OUT;
3351 writel(local, ®s->LocalCtrl);
3352 readl(®s->LocalCtrl);
3357 static void __init eeprom_prep(struct ace_regs *regs, u8 magic)
3362 udelay(ACE_SHORT_DELAY);
3363 local = readl(®s->LocalCtrl);
3364 local &= ~EEPROM_DATA_OUT;
3365 local |= EEPROM_WRITE_ENABLE;
3366 writel(local, ®s->LocalCtrl);
3367 readl(®s->LocalCtrl);
3370 for (i = 0; i < 8; i++, magic <<= 1) {
3371 udelay(ACE_SHORT_DELAY);
3373 local |= EEPROM_DATA_OUT;
3375 local &= ~EEPROM_DATA_OUT;
3376 writel(local, ®s->LocalCtrl);
3377 readl(®s->LocalCtrl);
3380 udelay(ACE_SHORT_DELAY);
3381 local |= EEPROM_CLK_OUT;
3382 writel(local, ®s->LocalCtrl);
3383 readl(®s->LocalCtrl);
3385 udelay(ACE_SHORT_DELAY);
3386 local &= ~(EEPROM_CLK_OUT | EEPROM_DATA_OUT);
3387 writel(local, ®s->LocalCtrl);
3388 readl(®s->LocalCtrl);
3394 static int __init eeprom_check_ack(struct ace_regs *regs)
3399 local = readl(®s->LocalCtrl);
3400 local &= ~EEPROM_WRITE_ENABLE;
3401 writel(local, ®s->LocalCtrl);
3402 readl(®s->LocalCtrl);
3404 udelay(ACE_LONG_DELAY);
3405 local |= EEPROM_CLK_OUT;
3406 writel(local, ®s->LocalCtrl);
3407 readl(®s->LocalCtrl);
3409 udelay(ACE_SHORT_DELAY);
3410 /* sample data in middle of high clk */
3411 state = (readl(®s->LocalCtrl) & EEPROM_DATA_IN) != 0;
3412 udelay(ACE_SHORT_DELAY);
3414 writel(readl(®s->LocalCtrl) & ~EEPROM_CLK_OUT, ®s->LocalCtrl);
3415 readl(®s->LocalCtrl);
3422 static void __init eeprom_stop(struct ace_regs *regs)
3426 udelay(ACE_SHORT_DELAY);
3427 local = readl(®s->LocalCtrl);
3428 local |= EEPROM_WRITE_ENABLE;
3429 writel(local, ®s->LocalCtrl);
3430 readl(®s->LocalCtrl);
3432 udelay(ACE_SHORT_DELAY);
3433 local &= ~EEPROM_DATA_OUT;
3434 writel(local, ®s->LocalCtrl);
3435 readl(®s->LocalCtrl);
3437 udelay(ACE_SHORT_DELAY);
3438 local |= EEPROM_CLK_OUT;
3439 writel(local, ®s->LocalCtrl);
3440 readl(®s->LocalCtrl);
3442 udelay(ACE_SHORT_DELAY);
3443 local |= EEPROM_DATA_OUT;
3444 writel(local, ®s->LocalCtrl);
3445 readl(®s->LocalCtrl);
3447 udelay(ACE_LONG_DELAY);
3448 local &= ~EEPROM_CLK_OUT;
3449 writel(local, ®s->LocalCtrl);
3455 * Read a whole byte from the EEPROM.
3457 static int __init read_eeprom_byte(struct net_device *dev,
3458 unsigned long offset)
3460 struct ace_regs *regs;
3461 unsigned long flags;
3467 printk(KERN_ERR "No device!\n");
3469 goto eeprom_read_error;
3472 regs = ((struct ace_private *)dev->priv)->regs;
3475 * Don't take interrupts on this CPU will bit banging
3476 * the %#%#@$ I2C device
3478 local_irq_save(flags);
3482 eeprom_prep(regs, EEPROM_WRITE_SELECT);
3483 if (eeprom_check_ack(regs)) {
3484 local_irq_restore(flags);
3485 printk(KERN_ERR "%s: Unable to sync eeprom\n", dev->name);
3487 goto eeprom_read_error;
3490 eeprom_prep(regs, (offset >> 8) & 0xff);
3491 if (eeprom_check_ack(regs)) {
3492 local_irq_restore(flags);
3493 printk(KERN_ERR "%s: Unable to set address byte 0\n",
3496 goto eeprom_read_error;
3499 eeprom_prep(regs, offset & 0xff);
3500 if (eeprom_check_ack(regs)) {
3501 local_irq_restore(flags);
3502 printk(KERN_ERR "%s: Unable to set address byte 1\n",
3505 goto eeprom_read_error;
3509 eeprom_prep(regs, EEPROM_READ_SELECT);
3510 if (eeprom_check_ack(regs)) {
3511 local_irq_restore(flags);
3512 printk(KERN_ERR "%s: Unable to set READ_SELECT\n",
3515 goto eeprom_read_error;
3518 for (i = 0; i < 8; i++) {
3519 local = readl(®s->LocalCtrl);
3520 local &= ~EEPROM_WRITE_ENABLE;
3521 writel(local, ®s->LocalCtrl);
3522 readl(®s->LocalCtrl);
3523 udelay(ACE_LONG_DELAY);
3525 local |= EEPROM_CLK_OUT;
3526 writel(local, ®s->LocalCtrl);
3527 readl(®s->LocalCtrl);
3529 udelay(ACE_SHORT_DELAY);
3530 /* sample data mid high clk */
3531 result = (result << 1) |
3532 ((readl(®s->LocalCtrl) & EEPROM_DATA_IN) != 0);
3533 udelay(ACE_SHORT_DELAY);
3535 local = readl(®s->LocalCtrl);
3536 local &= ~EEPROM_CLK_OUT;
3537 writel(local, ®s->LocalCtrl);
3538 readl(®s->LocalCtrl);
3539 udelay(ACE_SHORT_DELAY);
3542 local |= EEPROM_WRITE_ENABLE;
3543 writel(local, ®s->LocalCtrl);
3544 readl(®s->LocalCtrl);
3546 udelay(ACE_SHORT_DELAY);
3550 local |= EEPROM_DATA_OUT;
3551 writel(local, ®s->LocalCtrl);
3552 readl(®s->LocalCtrl);
3554 udelay(ACE_SHORT_DELAY);
3555 writel(readl(®s->LocalCtrl) | EEPROM_CLK_OUT, ®s->LocalCtrl);
3556 readl(®s->LocalCtrl);
3557 udelay(ACE_LONG_DELAY);
3558 writel(readl(®s->LocalCtrl) & ~EEPROM_CLK_OUT, ®s->LocalCtrl);
3559 readl(®s->LocalCtrl);
3561 udelay(ACE_SHORT_DELAY);
3564 local_irq_restore(flags);
3569 printk(KERN_ERR "%s: Unable to read eeprom byte 0x%02lx\n",
3577 * compile-command: "gcc -D__SMP__ -D__KERNEL__ -DMODULE -I../../include -Wall -Wstrict-prototypes -O2 -fomit-frame-pointer -pipe -fno-strength-reduce -DMODVERSIONS -include ../../include/linux/modversions.h -c -o acenic.o acenic.c"