acenic.c
上传用户:jlfgdled
上传日期:2013-04-10
资源大小:33168k
文件大小:93k
源码类别:

Linux/Unix编程

开发平台:

Unix_Linux

  1. /*
  2.  * acenic.c: Linux driver for the Alteon AceNIC Gigabit Ethernet card
  3.  *           and other Tigon based cards.
  4.  *
  5.  * Copyright 1998-2002 by Jes Sorensen, <jes@trained-monkey.org>.
  6.  *
  7.  * Thanks to Alteon and 3Com for providing hardware and documentation
  8.  * enabling me to write this driver.
  9.  *
  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.
  14.  *
  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.
  19.  *
  20.  * Additional credits:
  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
  44.  *                                       endian systems.
  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
  49.  *                                       driver init path.
  50.  *   Grant Grundler <grundler@cup.hp.com>: PCI write posting fixes.
  51.  */
  52. #include <linux/config.h>
  53. #include <linux/module.h>
  54. #include <linux/version.h>
  55. #include <linux/types.h>
  56. #include <linux/errno.h>
  57. #include <linux/ioport.h>
  58. #include <linux/pci.h>
  59. #include <linux/kernel.h>
  60. #include <linux/netdevice.h>
  61. #include <linux/etherdevice.h>
  62. #include <linux/skbuff.h>
  63. #include <linux/init.h>
  64. #include <linux/delay.h>
  65. #include <linux/mm.h>
  66. #include <linux/highmem.h>
  67. #include <linux/sockios.h>
  68. #if defined(CONFIG_VLAN_8021Q) || defined(CONFIG_VLAN_8021Q_MODULE)
  69. #include <linux/if_vlan.h>
  70. #endif
  71. #ifdef SIOCETHTOOL
  72. #include <linux/ethtool.h>
  73. #endif
  74. #include <net/sock.h>
  75. #include <net/ip.h>
  76. #include <asm/system.h>
  77. #include <asm/io.h>
  78. #include <asm/irq.h>
  79. #include <asm/byteorder.h>
  80. #include <asm/uaccess.h>
  81. #undef INDEX_DEBUG
  82. #ifdef CONFIG_ACENIC_OMIT_TIGON_I
  83. #define ACE_IS_TIGON_I(ap) 0
  84. #define ACE_TX_RING_ENTRIES(ap) MAX_TX_RING_ENTRIES
  85. #else
  86. #define ACE_IS_TIGON_I(ap) (ap->version == 1)
  87. #define ACE_TX_RING_ENTRIES(ap) ap->tx_ring_entries
  88. #endif
  89. #ifndef PCI_VENDOR_ID_ALTEON
  90. #define PCI_VENDOR_ID_ALTEON 0x12ae
  91. #endif
  92. #ifndef PCI_DEVICE_ID_ALTEON_ACENIC_FIBRE
  93. #define PCI_DEVICE_ID_ALTEON_ACENIC_FIBRE  0x0001
  94. #define PCI_DEVICE_ID_ALTEON_ACENIC_COPPER 0x0002
  95. #endif
  96. #ifndef PCI_DEVICE_ID_3COM_3C985
  97. #define PCI_DEVICE_ID_3COM_3C985 0x0001
  98. #endif
  99. #ifndef PCI_VENDOR_ID_NETGEAR
  100. #define PCI_VENDOR_ID_NETGEAR 0x1385
  101. #define PCI_DEVICE_ID_NETGEAR_GA620 0x620a
  102. #endif
  103. #ifndef PCI_DEVICE_ID_NETGEAR_GA620T
  104. #define PCI_DEVICE_ID_NETGEAR_GA620T 0x630a
  105. #endif
  106. /*
  107.  * Farallon used the DEC vendor ID by mistake and they seem not
  108.  * to care - stinky!
  109.  */
  110. #ifndef PCI_DEVICE_ID_FARALLON_PN9000SX
  111. #define PCI_DEVICE_ID_FARALLON_PN9000SX 0x1a
  112. #endif
  113. #ifndef PCI_DEVICE_ID_FARALLON_PN9100T
  114. #define PCI_DEVICE_ID_FARALLON_PN9100T  0xfa
  115. #endif
  116. #ifndef PCI_VENDOR_ID_SGI
  117. #define PCI_VENDOR_ID_SGI 0x10a9
  118. #endif
  119. #ifndef PCI_DEVICE_ID_SGI_ACENIC
  120. #define PCI_DEVICE_ID_SGI_ACENIC 0x0009
  121. #endif
  122. #if LINUX_VERSION_CODE >= 0x20400
  123. static struct pci_device_id acenic_pci_tbl[] __initdata = {
  124. { PCI_VENDOR_ID_ALTEON, PCI_DEVICE_ID_ALTEON_ACENIC_FIBRE,
  125.   PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_NETWORK_ETHERNET << 8, 0xffff00, },
  126. { PCI_VENDOR_ID_ALTEON, PCI_DEVICE_ID_ALTEON_ACENIC_COPPER,
  127.   PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_NETWORK_ETHERNET << 8, 0xffff00, },
  128. { PCI_VENDOR_ID_3COM, PCI_DEVICE_ID_3COM_3C985,
  129.   PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_NETWORK_ETHERNET << 8, 0xffff00, },
  130. { PCI_VENDOR_ID_NETGEAR, PCI_DEVICE_ID_NETGEAR_GA620,
  131.   PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_NETWORK_ETHERNET << 8, 0xffff00, },
  132. { PCI_VENDOR_ID_NETGEAR, PCI_DEVICE_ID_NETGEAR_GA620T,
  133.   PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_NETWORK_ETHERNET << 8, 0xffff00, },
  134. /*
  135.  * Farallon used the DEC vendor ID on their cards incorrectly,
  136.  * then later Alteon's ID.
  137.  */
  138. { PCI_VENDOR_ID_DEC, PCI_DEVICE_ID_FARALLON_PN9000SX,
  139.   PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_NETWORK_ETHERNET << 8, 0xffff00, },
  140. { PCI_VENDOR_ID_ALTEON, PCI_DEVICE_ID_FARALLON_PN9100T,
  141.   PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_NETWORK_ETHERNET << 8, 0xffff00, },
  142. { PCI_VENDOR_ID_SGI, PCI_DEVICE_ID_SGI_ACENIC,
  143.   PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_NETWORK_ETHERNET << 8, 0xffff00, },
  144. { }
  145. };
  146. MODULE_DEVICE_TABLE(pci, acenic_pci_tbl);
  147. #endif
  148. #ifndef MODULE_LICENSE
  149. #define MODULE_LICENSE(a)
  150. #endif
  151. #ifndef wmb
  152. #define wmb() mb()
  153. #endif
  154. #ifndef __exit
  155. #define __exit
  156. #endif
  157. #ifndef __devinit
  158. #define __devinit __init
  159. #endif
  160. #ifndef SMP_CACHE_BYTES
  161. #define SMP_CACHE_BYTES L1_CACHE_BYTES
  162. #endif
  163. #ifndef SET_MODULE_OWNER
  164. #define SET_MODULE_OWNER(dev) do{} while(0)
  165. #define ACE_MOD_INC_USE_COUNT MOD_INC_USE_COUNT
  166. #define ACE_MOD_DEC_USE_COUNT MOD_DEC_USE_COUNT
  167. #else
  168. #define ACE_MOD_INC_USE_COUNT do{} while(0)
  169. #define ACE_MOD_DEC_USE_COUNT do{} while(0)
  170. #endif
  171. #if LINUX_VERSION_CODE >= 0x2051c
  172. #define ace_sync_irq(irq) synchronize_irq(irq)
  173. #else
  174. #define ace_sync_irq(irq) synchronize_irq()
  175. #endif
  176. #if (LINUX_VERSION_CODE < 0x02030d)
  177. #define pci_resource_start(dev, bar) dev->base_address[bar]
  178. #elif (LINUX_VERSION_CODE < 0x02032c)
  179. #define pci_resource_start(dev, bar) dev->resource[bar].start
  180. #endif
  181. #if (LINUX_VERSION_CODE < 0x02030e)
  182. #define net_device device
  183. #endif
  184. #if (LINUX_VERSION_CODE < 0x02032a)
  185. typedef u32 dma_addr_t;
  186. static inline void *pci_alloc_consistent(struct pci_dev *hwdev, size_t size,
  187.  dma_addr_t *dma_handle)
  188. {
  189. void *virt_ptr;
  190. virt_ptr = kmalloc(size, GFP_KERNEL);
  191. if (!virt_ptr)
  192. return NULL;
  193. *dma_handle = virt_to_bus(virt_ptr);
  194. return virt_ptr;
  195. }
  196. #define pci_free_consistent(cookie, size, ptr, dma_ptr) kfree(ptr)
  197. #define pci_map_page(cookie, page, off, size, dir)
  198. virt_to_bus(page_address(page)+(off))
  199. #define pci_unmap_page(cookie, address, size, dir)
  200. #define pci_set_dma_mask(dev, mask)
  201. (((u64)(mask) & 0xffffffff00000000) == 0 ? 0 : -EIO)
  202. #define pci_dma_supported(dev, mask)
  203. (((u64)(mask) & 0xffffffff00000000) == 0 ? 1 : 0)
  204. #elif (LINUX_VERSION_CODE < 0x02040d)
  205. /*
  206.  * 2.4.13 introduced pci_map_page()/pci_unmap_page() - for 2.4.12 and prior,
  207.  * fall back on pci_map_single()/pci_unnmap_single().
  208.  *
  209.  * We are guaranteed that the page is mapped at this point since
  210.  * pci_map_page() is only used upon valid struct skb's.
  211.  */
  212. static inline dma_addr_t
  213. pci_map_page(struct pci_dev *cookie, struct page *page, unsigned long off,
  214.      size_t size, int dir)
  215. {
  216. void *page_virt;
  217. page_virt = page_address(page);
  218. if (!page_virt)
  219. BUG();
  220. return pci_map_single(cookie, (page_virt + off), size, dir);
  221. }
  222. #define pci_unmap_page(cookie, dma_addr, size, dir)
  223. pci_unmap_single(cookie, dma_addr, size, dir)
  224. #endif
  225. #if (LINUX_VERSION_CODE < 0x020412)
  226. #define DECLARE_PCI_UNMAP_ADDR(ADDR_NAME)
  227. #define DECLARE_PCI_UNMAP_LEN(LEN_NAME)
  228. #define pci_unmap_addr(PTR, ADDR_NAME) 0
  229. #define pci_unmap_addr_set(PTR, ADDR_NAME, VAL) do{} while(0)
  230. #define pci_unmap_len(PTR, LEN_NAME) 0
  231. #define pci_unmap_len_set(PTR, LEN_NAME, VAL) do{} while(0)
  232. #endif
  233. #if (LINUX_VERSION_CODE < 0x02032b)
  234. /*
  235.  * SoftNet
  236.  *
  237.  * For pre-softnet kernels we need to tell the upper layer not to
  238.  * re-enter start_xmit() while we are in there. However softnet
  239.  * guarantees not to enter while we are in there so there is no need
  240.  * to do the netif_stop_queue() dance unless the transmit queue really
  241.  * gets stuck. This should also improve performance according to tests
  242.  * done by Aman Singla.
  243.  */
  244. #define dev_kfree_skb_irq(a) dev_kfree_skb(a)
  245. #define netif_wake_queue(dev) clear_bit(0, &dev->tbusy)
  246. #define netif_stop_queue(dev) set_bit(0, &dev->tbusy)
  247. #define late_stop_netif_stop_queue(dev) do{} while(0)
  248. #define early_stop_netif_stop_queue(dev) test_and_set_bit(0,&dev->tbusy)
  249. #define early_stop_netif_wake_queue(dev) netif_wake_queue(dev)
  250. static inline void netif_start_queue(struct net_device *dev)
  251. {
  252. dev->tbusy = 0;
  253. dev->interrupt = 0;
  254. dev->start = 1;
  255. }
  256. #define ace_mark_net_bh() mark_bh(NET_BH)
  257. #define netif_queue_stopped(dev) dev->tbusy
  258. #define netif_running(dev) dev->start
  259. #define ace_if_down(dev) do{dev->start = 0;} while(0)
  260. #define tasklet_struct tq_struct
  261. static inline void tasklet_schedule(struct tasklet_struct *tasklet)
  262. {
  263. queue_task(tasklet, &tq_immediate);
  264. mark_bh(IMMEDIATE_BH);
  265. }
  266. static inline void tasklet_init(struct tasklet_struct *tasklet,
  267. void (*func)(unsigned long),
  268. unsigned long data)
  269. {
  270. tasklet->next = NULL;
  271. tasklet->sync = 0;
  272. tasklet->routine = (void (*)(void *))func;
  273. tasklet->data = (void *)data;
  274. }
  275. #define tasklet_kill(tasklet) do{} while(0)
  276. #else
  277. #define late_stop_netif_stop_queue(dev) netif_stop_queue(dev)
  278. #define early_stop_netif_stop_queue(dev) 0
  279. #define early_stop_netif_wake_queue(dev) do{} while(0)
  280. #define ace_mark_net_bh() do{} while(0)
  281. #define ace_if_down(dev) do{} while(0)
  282. #endif
  283. #if (LINUX_VERSION_CODE >= 0x02031b)
  284. #define NEW_NETINIT
  285. #define ACE_PROBE_ARG void
  286. #else
  287. #define ACE_PROBE_ARG struct net_device *dev
  288. #endif
  289. #ifndef min_t
  290. #define min_t(type,a,b) (((a)<(b))?(a):(b))
  291. #endif
  292. #ifndef ARCH_HAS_PREFETCHW
  293. #ifndef prefetchw
  294. #define prefetchw(x) do{} while(0)
  295. #endif
  296. #endif
  297. #define ACE_MAX_MOD_PARMS 8
  298. #define BOARD_IDX_STATIC 0
  299. #define BOARD_IDX_OVERFLOW -1
  300. #if (defined(CONFIG_VLAN_8021Q) || defined(CONFIG_VLAN_8021Q_MODULE)) && 
  301. defined(NETIF_F_HW_VLAN_RX)
  302. #define ACENIC_DO_VLAN 1
  303. #define ACE_RCB_VLAN_FLAG RCB_FLG_VLAN_ASSIST
  304. #else
  305. #define ACENIC_DO_VLAN 0
  306. #define ACE_RCB_VLAN_FLAG 0
  307. #endif
  308. #include "acenic.h"
  309. /*
  310.  * These must be defined before the firmware is included.
  311.  */
  312. #define MAX_TEXT_LEN 96*1024
  313. #define MAX_RODATA_LEN 8*1024
  314. #define MAX_DATA_LEN 2*1024
  315. #include "acenic_firmware.h"
  316. #ifndef tigon2FwReleaseLocal
  317. #define tigon2FwReleaseLocal 0
  318. #endif
  319. /*
  320.  * This driver currently supports Tigon I and Tigon II based cards
  321.  * including the Alteon AceNIC, the 3Com 3C985[B] and NetGear
  322.  * GA620. The driver should also work on the SGI, DEC and Farallon
  323.  * versions of the card, however I have not been able to test that
  324.  * myself.
  325.  *
  326.  * This card is really neat, it supports receive hardware checksumming
  327.  * and jumbo frames (up to 9000 bytes) and does a lot of work in the
  328.  * firmware. Also the programming interface is quite neat, except for
  329.  * the parts dealing with the i2c eeprom on the card ;-)
  330.  *
  331.  * Using jumbo frames:
  332.  *
  333.  * To enable jumbo frames, simply specify an mtu between 1500 and 9000
  334.  * bytes to ifconfig. Jumbo frames can be enabled or disabled at any time
  335.  * by running `ifconfig eth<X> mtu <MTU>' with <X> being the Ethernet
  336.  * interface number and <MTU> being the MTU value.
  337.  *
  338.  * Module parameters:
  339.  *
  340.  * When compiled as a loadable module, the driver allows for a number
  341.  * of module parameters to be specified. The driver supports the
  342.  * following module parameters:
  343.  *
  344.  *  trace=<val> - Firmware trace level. This requires special traced
  345.  *                firmware to replace the firmware supplied with
  346.  *                the driver - for debugging purposes only.
  347.  *
  348.  *  link=<val>  - Link state. Normally you want to use the default link
  349.  *                parameters set by the driver. This can be used to
  350.  *                override these in case your switch doesn't negotiate
  351.  *                the link properly. Valid values are:
  352.  *         0x0001 - Force half duplex link.
  353.  *         0x0002 - Do not negotiate line speed with the other end.
  354.  *         0x0010 - 10Mbit/sec link.
  355.  *         0x0020 - 100Mbit/sec link.
  356.  *         0x0040 - 1000Mbit/sec link.
  357.  *         0x0100 - Do not negotiate flow control.
  358.  *         0x0200 - Enable RX flow control Y
  359.  *         0x0400 - Enable TX flow control Y (Tigon II NICs only).
  360.  *                Default value is 0x0270, ie. enable link+flow
  361.  *                control negotiation. Negotiating the highest
  362.  *                possible link speed with RX flow control enabled.
  363.  *
  364.  *                When disabling link speed negotiation, only one link
  365.  *                speed is allowed to be specified!
  366.  *
  367.  *  tx_coal_tick=<val> - number of coalescing clock ticks (us) allowed
  368.  *                to wait for more packets to arive before
  369.  *                interrupting the host, from the time the first
  370.  *                packet arrives.
  371.  *
  372.  *  rx_coal_tick=<val> - number of coalescing clock ticks (us) allowed
  373.  *                to wait for more packets to arive in the transmit ring,
  374.  *                before interrupting the host, after transmitting the
  375.  *                first packet in the ring.
  376.  *
  377.  *  max_tx_desc=<val> - maximum number of transmit descriptors
  378.  *                (packets) transmitted before interrupting the host.
  379.  *
  380.  *  max_rx_desc=<val> - maximum number of receive descriptors
  381.  *                (packets) received before interrupting the host.
  382.  *
  383.  *  tx_ratio=<val> - 7 bit value (0 - 63) specifying the split in 64th
  384.  *                increments of the NIC's on board memory to be used for
  385.  *                transmit and receive buffers. For the 1MB NIC app. 800KB
  386.  *                is available, on the 1/2MB NIC app. 300KB is available.
  387.  *                68KB will always be available as a minimum for both
  388.  *                directions. The default value is a 50/50 split.
  389.  *  dis_pci_mem_inval=<val> - disable PCI memory write and invalidate
  390.  *                operations, default (1) is to always disable this as
  391.  *                that is what Alteon does on NT. I have not been able
  392.  *                to measure any real performance differences with
  393.  *                this on my systems. Set <val>=0 if you want to
  394.  *                enable these operations.
  395.  *
  396.  * If you use more than one NIC, specify the parameters for the
  397.  * individual NICs with a comma, ie. trace=0,0x00001fff,0 you want to
  398.  * run tracing on NIC #2 but not on NIC #1 and #3.
  399.  *
  400.  * TODO:
  401.  *
  402.  * - Proper multicast support.
  403.  * - NIC dump support.
  404.  * - More tuning parameters.
  405.  *
  406.  * The mini ring is not used under Linux and I am not sure it makes sense
  407.  * to actually use it.
  408.  *
  409.  * New interrupt handler strategy:
  410.  *
  411.  * The old interrupt handler worked using the traditional method of
  412.  * replacing an skbuff with a new one when a packet arrives. However
  413.  * the rx rings do not need to contain a static number of buffer
  414.  * descriptors, thus it makes sense to move the memory allocation out
  415.  * of the main interrupt handler and do it in a bottom half handler
  416.  * and only allocate new buffers when the number of buffers in the
  417.  * ring is below a certain threshold. In order to avoid starving the
  418.  * NIC under heavy load it is however necessary to force allocation
  419.  * when hitting a minimum threshold. The strategy for alloction is as
  420.  * follows:
  421.  *
  422.  *     RX_LOW_BUF_THRES    - allocate buffers in the bottom half
  423.  *     RX_PANIC_LOW_THRES  - we are very low on buffers, allocate
  424.  *                           the buffers in the interrupt handler
  425.  *     RX_RING_THRES       - maximum number of buffers in the rx ring
  426.  *     RX_MINI_THRES       - maximum number of buffers in the mini ring
  427.  *     RX_JUMBO_THRES      - maximum number of buffers in the jumbo ring
  428.  *
  429.  * One advantagous side effect of this allocation approach is that the
  430.  * entire rx processing can be done without holding any spin lock
  431.  * since the rx rings and registers are totally independant of the tx
  432.  * ring and its registers.  This of course includes the kmalloc's of
  433.  * new skb's. Thus start_xmit can run in parallel with rx processing
  434.  * and the memory allocation on SMP systems.
  435.  *
  436.  * Note that running the skb reallocation in a bottom half opens up
  437.  * another can of races which needs to be handled properly. In
  438.  * particular it can happen that the interrupt handler tries to run
  439.  * the reallocation while the bottom half is either running on another
  440.  * CPU or was interrupted on the same CPU. To get around this the
  441.  * driver uses bitops to prevent the reallocation routines from being
  442.  * reentered.
  443.  *
  444.  * TX handling can also be done without holding any spin lock, wheee
  445.  * this is fun! since tx_ret_csm is only written to by the interrupt
  446.  * handler. The case to be aware of is when shutting down the device
  447.  * and cleaning up where it is necessary to make sure that
  448.  * start_xmit() is not running while this is happening. Well DaveM
  449.  * informs me that this case is already protected against ... bye bye
  450.  * Mr. Spin Lock, it was nice to know you.
  451.  *
  452.  * TX interrupts are now partly disabled so the NIC will only generate
  453.  * TX interrupts for the number of coal ticks, not for the number of
  454.  * TX packets in the queue. This should reduce the number of TX only,
  455.  * ie. when no RX processing is done, interrupts seen.
  456.  */
  457. /*
  458.  * Threshold values for RX buffer allocation - the low water marks for
  459.  * when to start refilling the rings are set to 75% of the ring
  460.  * sizes. It seems to make sense to refill the rings entirely from the
  461.  * intrrupt handler once it gets below the panic threshold, that way
  462.  * we don't risk that the refilling is moved to another CPU when the
  463.  * one running the interrupt handler just got the slab code hot in its
  464.  * cache.
  465.  */
  466. #define RX_RING_SIZE 72
  467. #define RX_MINI_SIZE 64
  468. #define RX_JUMBO_SIZE 48
  469. #define RX_PANIC_STD_THRES 16
  470. #define RX_PANIC_STD_REFILL (3*RX_PANIC_STD_THRES)/2
  471. #define RX_LOW_STD_THRES (3*RX_RING_SIZE)/4
  472. #define RX_PANIC_MINI_THRES 12
  473. #define RX_PANIC_MINI_REFILL (3*RX_PANIC_MINI_THRES)/2
  474. #define RX_LOW_MINI_THRES (3*RX_MINI_SIZE)/4
  475. #define RX_PANIC_JUMBO_THRES 6
  476. #define RX_PANIC_JUMBO_REFILL (3*RX_PANIC_JUMBO_THRES)/2
  477. #define RX_LOW_JUMBO_THRES (3*RX_JUMBO_SIZE)/4
  478. /*
  479.  * Size of the mini ring entries, basically these just should be big
  480.  * enough to take TCP ACKs
  481.  */
  482. #define ACE_MINI_SIZE 100
  483. #define ACE_MINI_BUFSIZE (ACE_MINI_SIZE + 2 + 16)
  484. #define ACE_STD_BUFSIZE (ACE_STD_MTU + ETH_HLEN + 2+4+16)
  485. #define ACE_JUMBO_BUFSIZE (ACE_JUMBO_MTU + ETH_HLEN + 2+4+16)
  486. /*
  487.  * There seems to be a magic difference in the effect between 995 and 996
  488.  * but little difference between 900 and 995 ... no idea why.
  489.  *
  490.  * There is now a default set of tuning parameters which is set, depending
  491.  * on whether or not the user enables Jumbo frames. It's assumed that if
  492.  * Jumbo frames are enabled, the user wants optimal tuning for that case.
  493.  */
  494. #define DEF_TX_COAL 400 /* 996 */
  495. #define DEF_TX_MAX_DESC 60  /* was 40 */
  496. #define DEF_RX_COAL 120 /* 1000 */
  497. #define DEF_RX_MAX_DESC 25
  498. #define DEF_TX_RATIO 21 /* 24 */
  499. #define DEF_JUMBO_TX_COAL 20
  500. #define DEF_JUMBO_TX_MAX_DESC 60
  501. #define DEF_JUMBO_RX_COAL 30
  502. #define DEF_JUMBO_RX_MAX_DESC 6
  503. #define DEF_JUMBO_TX_RATIO 21
  504. #if tigon2FwReleaseLocal < 20001118
  505. /*
  506.  * Standard firmware and early modifications duplicate
  507.  * IRQ load without this flag (coal timer is never reset).
  508.  * Note that with this flag tx_coal should be less than
  509.  * time to xmit full tx ring.
  510.  * 400usec is not so bad for tx ring size of 128.
  511.  */
  512. #define TX_COAL_INTS_ONLY 1 /* worth it */
  513. #else
  514. /*
  515.  * With modified firmware, this is not necessary, but still useful.
  516.  */
  517. #define TX_COAL_INTS_ONLY 1
  518. #endif
  519. #define DEF_TRACE 0
  520. #define DEF_STAT (2 * TICKS_PER_SEC)
  521. static int link[ACE_MAX_MOD_PARMS];
  522. static int trace[ACE_MAX_MOD_PARMS];
  523. static int tx_coal_tick[ACE_MAX_MOD_PARMS];
  524. static int rx_coal_tick[ACE_MAX_MOD_PARMS];
  525. static int max_tx_desc[ACE_MAX_MOD_PARMS];
  526. static int max_rx_desc[ACE_MAX_MOD_PARMS];
  527. static int tx_ratio[ACE_MAX_MOD_PARMS];
  528. static int dis_pci_mem_inval[ACE_MAX_MOD_PARMS] = {1, 1, 1, 1, 1, 1, 1, 1};
  529. static char version[] __initdata = 
  530.   "acenic.c: v0.92 08/05/2002  Jes Sorensen, linux-acenic@SunSITE.dkn"
  531.   "                            http://home.cern.ch/~jes/gige/acenic.htmln";
  532. static struct net_device *root_dev;
  533. static int probed __initdata = 0;
  534. int __devinit acenic_probe (ACE_PROBE_ARG)
  535. {
  536. #ifdef NEW_NETINIT
  537. struct net_device *dev;
  538. #endif
  539. struct ace_private *ap;
  540. struct pci_dev *pdev = NULL;
  541. int boards_found = 0;
  542. int version_disp;
  543. if (probed)
  544. return -ENODEV;
  545. probed++;
  546. if (!pci_present()) /* is PCI support present? */
  547. return -ENODEV;
  548. version_disp = 0;
  549. while ((pdev = pci_find_class(PCI_CLASS_NETWORK_ETHERNET<<8, pdev))) {
  550. if (!((pdev->vendor == PCI_VENDOR_ID_ALTEON) &&
  551.       ((pdev->device == PCI_DEVICE_ID_ALTEON_ACENIC_FIBRE) ||
  552.        (pdev->device == PCI_DEVICE_ID_ALTEON_ACENIC_COPPER)))&&
  553.     !((pdev->vendor == PCI_VENDOR_ID_3COM) &&
  554.       (pdev->device == PCI_DEVICE_ID_3COM_3C985)) &&
  555.     !((pdev->vendor == PCI_VENDOR_ID_NETGEAR) &&
  556.       ((pdev->device == PCI_DEVICE_ID_NETGEAR_GA620) || 
  557.        (pdev->device == PCI_DEVICE_ID_NETGEAR_GA620T))) &&
  558. /*
  559.  * Farallon used the DEC vendor ID on their cards by
  560.  * mistake for a while
  561.  */
  562.     !((pdev->vendor == PCI_VENDOR_ID_DEC) &&
  563.       (pdev->device == PCI_DEVICE_ID_FARALLON_PN9000SX)) &&
  564.     !((pdev->vendor == PCI_VENDOR_ID_ALTEON) &&
  565.       (pdev->device == PCI_DEVICE_ID_FARALLON_PN9100T)) &&
  566.     !((pdev->vendor == PCI_VENDOR_ID_SGI) &&
  567.       (pdev->device == PCI_DEVICE_ID_SGI_ACENIC)))
  568. continue;
  569. dev = init_etherdev(NULL, sizeof(struct ace_private));
  570. if (dev == NULL) {
  571. printk(KERN_ERR "acenic: Unable to allocate "
  572.        "net_device structure!n");
  573. break;
  574. }
  575. SET_MODULE_OWNER(dev);
  576. if (!dev->priv)
  577. dev->priv = kmalloc(sizeof(*ap), GFP_KERNEL);
  578. if (!dev->priv) {
  579. printk(KERN_ERR "acenic: Unable to allocate memoryn");
  580. return -ENOMEM;
  581. }
  582. ap = dev->priv;
  583. ap->pdev = pdev;
  584. dev->open = &ace_open;
  585. dev->hard_start_xmit = &ace_start_xmit;
  586. dev->features |= NETIF_F_SG | NETIF_F_IP_CSUM;
  587. #if ACENIC_DO_VLAN
  588. dev->features |= NETIF_F_HW_VLAN_TX | NETIF_F_HW_VLAN_RX;
  589. dev->vlan_rx_register = ace_vlan_rx_register;
  590. dev->vlan_rx_kill_vid = ace_vlan_rx_kill_vid;
  591. #endif
  592. if (1) {
  593. static void ace_watchdog(struct net_device *dev);
  594. dev->tx_timeout = &ace_watchdog;
  595. dev->watchdog_timeo = 5*HZ;
  596. }
  597. dev->stop = &ace_close;
  598. dev->get_stats = &ace_get_stats;
  599. dev->set_multicast_list = &ace_set_multicast_list;
  600. dev->do_ioctl = &ace_ioctl;
  601. dev->set_mac_address = &ace_set_mac_addr;
  602. dev->change_mtu = &ace_change_mtu;
  603. /* display version info if adapter is found */
  604. if (!version_disp)
  605. {
  606. /* set display flag to TRUE so that */
  607. /* we only display this string ONCE */
  608. version_disp = 1;
  609. printk(version);
  610. }
  611. if (pci_enable_device(pdev)) {
  612. kfree(dev);
  613. continue;
  614. }
  615. /*
  616.  * Enable master mode before we start playing with the
  617.  * pci_command word since pci_set_master() will modify
  618.  * it.
  619.  */
  620. pci_set_master(pdev);
  621. pci_read_config_word(pdev, PCI_COMMAND, &ap->pci_command);
  622. /* OpenFirmware on Mac's does not set this - DOH.. */ 
  623. if (!(ap->pci_command & PCI_COMMAND_MEMORY)) {
  624. printk(KERN_INFO "%s: Enabling PCI Memory Mapped "
  625.        "access - was not enabled by BIOS/Firmwaren",
  626.        dev->name);
  627. ap->pci_command = ap->pci_command | PCI_COMMAND_MEMORY;
  628. pci_write_config_word(ap->pdev, PCI_COMMAND,
  629.       ap->pci_command);
  630. wmb();
  631. }
  632. pci_read_config_byte(pdev, PCI_LATENCY_TIMER,
  633.      &ap->pci_latency);
  634. if (ap->pci_latency <= 0x40) {
  635. ap->pci_latency = 0x40;
  636. pci_write_config_byte(pdev, PCI_LATENCY_TIMER,
  637.       ap->pci_latency);
  638. }
  639. /*
  640.  * Remap the regs into kernel space - this is abuse of
  641.  * dev->base_addr since it was means for I/O port
  642.  * addresses but who gives a damn.
  643.  */
  644. dev->base_addr = pci_resource_start(pdev, 0);
  645. ap->regs = (struct ace_regs *)ioremap(dev->base_addr, 0x4000);
  646. if (!ap->regs) {
  647. printk(KERN_ERR "%s:  Unable to map I/O register, "
  648.        "AceNIC %i will be disabled.n",
  649.        dev->name, boards_found);
  650. break;
  651. }
  652. switch(pdev->vendor) {
  653. case PCI_VENDOR_ID_ALTEON:
  654. if (pdev->device == PCI_DEVICE_ID_FARALLON_PN9100T) {
  655. strncpy(ap->name, "Farallon PN9100-T "
  656. "Gigabit Ethernet", sizeof (ap->name));
  657. printk(KERN_INFO "%s: Farallon PN9100-T ",
  658.        dev->name);
  659. } else {
  660. strncpy(ap->name, "AceNIC Gigabit Ethernet",
  661. sizeof (ap->name));
  662. printk(KERN_INFO "%s: Alteon AceNIC ",
  663.        dev->name);
  664. }
  665. break;
  666. case PCI_VENDOR_ID_3COM:
  667. strncpy(ap->name, "3Com 3C985 Gigabit Ethernet",
  668. sizeof (ap->name));
  669. printk(KERN_INFO "%s: 3Com 3C985 ", dev->name);
  670. break;
  671. case PCI_VENDOR_ID_NETGEAR:
  672. strncpy(ap->name, "NetGear GA620 Gigabit Ethernet",
  673. sizeof (ap->name));
  674. printk(KERN_INFO "%s: NetGear GA620 ", dev->name);
  675. break;
  676. case PCI_VENDOR_ID_DEC:
  677. if (pdev->device == PCI_DEVICE_ID_FARALLON_PN9000SX) {
  678. strncpy(ap->name, "Farallon PN9000-SX "
  679. "Gigabit Ethernet", sizeof (ap->name));
  680. printk(KERN_INFO "%s: Farallon PN9000-SX ",
  681.        dev->name);
  682. break;
  683. }
  684. case PCI_VENDOR_ID_SGI:
  685. strncpy(ap->name, "SGI AceNIC Gigabit Ethernet",
  686. sizeof (ap->name));
  687. printk(KERN_INFO "%s: SGI AceNIC ", dev->name);
  688. break;
  689. default:
  690.   strncpy(ap->name, "Unknown AceNIC based Gigabit "
  691. "Ethernet", sizeof (ap->name));
  692. printk(KERN_INFO "%s: Unknown AceNIC ", dev->name);
  693. break;
  694. }
  695. ap->name [sizeof (ap->name) - 1] = '';
  696. printk("Gigabit Ethernet at 0x%08lx, ", dev->base_addr);
  697. #ifdef __sparc__
  698. printk("irq %sn", __irq_itoa(pdev->irq));
  699. #else
  700. printk("irq %in", pdev->irq);
  701. #endif
  702. #ifdef CONFIG_ACENIC_OMIT_TIGON_I
  703. if ((readl(&ap->regs->HostCtrl) >> 28) == 4) {
  704. printk(KERN_ERR "%s: Driver compiled without Tigon I"
  705.        " support - NIC disabledn", dev->name);
  706. ace_init_cleanup(dev);
  707. kfree(dev);
  708. continue;
  709. }
  710. #endif
  711. if (ace_allocate_descriptors(dev)) {
  712. /*
  713.  * ace_allocate_descriptors() calls
  714.  * ace_init_cleanup() on error.
  715.  */
  716. kfree(dev);
  717. continue;
  718. }
  719. #ifdef MODULE
  720. if (boards_found >= ACE_MAX_MOD_PARMS)
  721. ap->board_idx = BOARD_IDX_OVERFLOW;
  722. else
  723. ap->board_idx = boards_found;
  724. #else
  725. ap->board_idx = BOARD_IDX_STATIC;
  726. #endif
  727. if (ace_init(dev)) {
  728. /*
  729.  * ace_init() calls ace_init_cleanup() on error.
  730.  */
  731. kfree(dev);
  732. continue;
  733. }
  734. if (ap->pci_using_dac)
  735. dev->features |= NETIF_F_HIGHDMA;
  736. boards_found++;
  737. }
  738. /*
  739.  * If we're at this point we're going through ace_probe() for
  740.  * the first time.  Return success (0) if we've initialized 1
  741.  * or more boards. Otherwise, return failure (-ENODEV).
  742.  */
  743. if (boards_found > 0)
  744. return 0;
  745. else
  746. return -ENODEV;
  747. }
  748. #ifdef MODULE
  749. MODULE_AUTHOR("Jes Sorensen <jes@trained-monkey.org>");
  750. MODULE_LICENSE("GPL");
  751. MODULE_DESCRIPTION("AceNIC/3C985/GA620 Gigabit Ethernet driver");
  752. MODULE_PARM(link, "1-" __MODULE_STRING(8) "i");
  753. MODULE_PARM(trace, "1-" __MODULE_STRING(8) "i");
  754. MODULE_PARM(tx_coal_tick, "1-" __MODULE_STRING(8) "i");
  755. MODULE_PARM(max_tx_desc, "1-" __MODULE_STRING(8) "i");
  756. MODULE_PARM(rx_coal_tick, "1-" __MODULE_STRING(8) "i");
  757. MODULE_PARM(max_rx_desc, "1-" __MODULE_STRING(8) "i");
  758. MODULE_PARM(tx_ratio, "1-" __MODULE_STRING(8) "i");
  759. MODULE_PARM_DESC(link, "AceNIC/3C985/NetGear link state");
  760. MODULE_PARM_DESC(trace, "AceNIC/3C985/NetGear firmware trace level");
  761. MODULE_PARM_DESC(tx_coal_tick, "AceNIC/3C985/GA620 max clock ticks to wait from first tx descriptor arrives");
  762. MODULE_PARM_DESC(max_tx_desc, "AceNIC/3C985/GA620 max number of transmit descriptors to wait");
  763. MODULE_PARM_DESC(rx_coal_tick, "AceNIC/3C985/GA620 max clock ticks to wait from first rx descriptor arrives");
  764. MODULE_PARM_DESC(max_rx_desc, "AceNIC/3C985/GA620 max number of receive descriptors to wait");
  765. MODULE_PARM_DESC(tx_ratio, "AceNIC/3C985/GA620 ratio of NIC memory used for TX/RX descriptors (range 0-63)");
  766. #endif
  767. static void __exit ace_module_cleanup(void)
  768. {
  769. struct ace_private *ap;
  770. struct ace_regs *regs;
  771. struct net_device *next;
  772. short i;
  773. while (root_dev) {
  774. ap = root_dev->priv;
  775. next = ap->next;
  776. regs = ap->regs;
  777. writel(readl(&regs->CpuCtrl) | CPU_HALT, &regs->CpuCtrl);
  778. if (ap->version >= 2)
  779. writel(readl(&regs->CpuBCtrl) | CPU_HALT,
  780.        &regs->CpuBCtrl);
  781. /*
  782.  * This clears any pending interrupts
  783.  */
  784. writel(1, &regs->Mb0Lo);
  785. readl(&regs->CpuCtrl); /* flush */
  786. /*
  787.  * Make sure no other CPUs are processing interrupts
  788.  * on the card before the buffers are being released.
  789.  * Otherwise one might experience some `interesting'
  790.  * effects.
  791.  *
  792.  * Then release the RX buffers - jumbo buffers were
  793.  * already released in ace_close().
  794.  */
  795. ace_sync_irq(root_dev->irq);
  796. for (i = 0; i < RX_STD_RING_ENTRIES; i++) {
  797. struct sk_buff *skb = ap->skb->rx_std_skbuff[i].skb;
  798. if (skb) {
  799. struct ring_info *ringp;
  800. dma_addr_t mapping;
  801. ringp = &ap->skb->rx_std_skbuff[i];
  802. mapping = pci_unmap_addr(ringp, mapping);
  803. pci_unmap_page(ap->pdev, mapping,
  804.        ACE_STD_BUFSIZE - (2 + 16),
  805.        PCI_DMA_FROMDEVICE);
  806. ap->rx_std_ring[i].size = 0;
  807. ap->skb->rx_std_skbuff[i].skb = NULL;
  808. dev_kfree_skb(skb);
  809. }
  810. }
  811. if (ap->version >= 2) {
  812. for (i = 0; i < RX_MINI_RING_ENTRIES; i++) {
  813. struct sk_buff *skb = ap->skb->rx_mini_skbuff[i].skb;
  814. if (skb) {
  815. struct ring_info *ringp;
  816. dma_addr_t mapping;
  817. ringp = &ap->skb->rx_mini_skbuff[i];
  818. mapping = pci_unmap_addr(ringp,mapping);
  819. pci_unmap_page(ap->pdev, mapping,
  820.        ACE_MINI_BUFSIZE - (2 + 16),
  821.        PCI_DMA_FROMDEVICE);
  822. ap->rx_mini_ring[i].size = 0;
  823. ap->skb->rx_mini_skbuff[i].skb = NULL;
  824. dev_kfree_skb(skb);
  825. }
  826. }
  827. }
  828. for (i = 0; i < RX_JUMBO_RING_ENTRIES; i++) {
  829. struct sk_buff *skb = ap->skb->rx_jumbo_skbuff[i].skb;
  830. if (skb) {
  831. struct ring_info *ringp;
  832. dma_addr_t mapping;
  833. ringp = &ap->skb->rx_jumbo_skbuff[i];
  834. mapping = pci_unmap_addr(ringp, mapping);
  835. pci_unmap_page(ap->pdev, mapping,
  836.        ACE_JUMBO_BUFSIZE - (2 + 16),
  837.        PCI_DMA_FROMDEVICE);
  838. ap->rx_jumbo_ring[i].size = 0;
  839. ap->skb->rx_jumbo_skbuff[i].skb = NULL;
  840. dev_kfree_skb(skb);
  841. }
  842. }
  843. ace_init_cleanup(root_dev);
  844. kfree(root_dev);
  845. root_dev = next;
  846. }
  847. }
  848. int __init ace_module_init(void)
  849. {
  850. int status;
  851. root_dev = NULL;
  852. #ifdef NEW_NETINIT
  853. status = acenic_probe();
  854. #else
  855. status = acenic_probe(NULL);
  856. #endif
  857. return status;
  858. }
  859. #if (LINUX_VERSION_CODE < 0x02032a)
  860. #ifdef MODULE
  861. int init_module(void)
  862. {
  863. return ace_module_init();
  864. }
  865. void cleanup_module(void)
  866. {
  867. ace_module_cleanup();
  868. }
  869. #endif
  870. #else
  871. module_init(ace_module_init);
  872. module_exit(ace_module_cleanup);
  873. #endif
  874. static void ace_free_descriptors(struct net_device *dev)
  875. {
  876. struct ace_private *ap = dev->priv;
  877. int size;
  878. if (ap->rx_std_ring != NULL) {
  879. size = (sizeof(struct rx_desc) *
  880. (RX_STD_RING_ENTRIES +
  881.  RX_JUMBO_RING_ENTRIES +
  882.  RX_MINI_RING_ENTRIES +
  883.  RX_RETURN_RING_ENTRIES));
  884. pci_free_consistent(ap->pdev, size, ap->rx_std_ring,
  885.     ap->rx_ring_base_dma);
  886. ap->rx_std_ring = NULL;
  887. ap->rx_jumbo_ring = NULL;
  888. ap->rx_mini_ring = NULL;
  889. ap->rx_return_ring = NULL;
  890. }
  891. if (ap->evt_ring != NULL) {
  892. size = (sizeof(struct event) * EVT_RING_ENTRIES);
  893. pci_free_consistent(ap->pdev, size, ap->evt_ring,
  894.     ap->evt_ring_dma);
  895. ap->evt_ring = NULL;
  896. }
  897. if (ap->tx_ring != NULL && !ACE_IS_TIGON_I(ap)) {
  898. size = (sizeof(struct tx_desc) * MAX_TX_RING_ENTRIES);
  899. pci_free_consistent(ap->pdev, size, ap->tx_ring,
  900.     ap->tx_ring_dma);
  901. }
  902. ap->tx_ring = NULL;
  903. if (ap->evt_prd != NULL) {
  904. pci_free_consistent(ap->pdev, sizeof(u32),
  905.     (void *)ap->evt_prd, ap->evt_prd_dma);
  906. ap->evt_prd = NULL;
  907. }
  908. if (ap->rx_ret_prd != NULL) {
  909. pci_free_consistent(ap->pdev, sizeof(u32),
  910.     (void *)ap->rx_ret_prd,
  911.     ap->rx_ret_prd_dma);
  912. ap->rx_ret_prd = NULL;
  913. }
  914. if (ap->tx_csm != NULL) {
  915. pci_free_consistent(ap->pdev, sizeof(u32),
  916.     (void *)ap->tx_csm, ap->tx_csm_dma);
  917. ap->tx_csm = NULL;
  918. }
  919. }
  920. static int ace_allocate_descriptors(struct net_device *dev)
  921. {
  922. struct ace_private *ap = dev->priv;
  923. int size;
  924. size = (sizeof(struct rx_desc) *
  925. (RX_STD_RING_ENTRIES +
  926.  RX_JUMBO_RING_ENTRIES +
  927.  RX_MINI_RING_ENTRIES +
  928.  RX_RETURN_RING_ENTRIES));
  929. ap->rx_std_ring = pci_alloc_consistent(ap->pdev, size,
  930.        &ap->rx_ring_base_dma);
  931. if (ap->rx_std_ring == NULL)
  932. goto fail;
  933. ap->rx_jumbo_ring = ap->rx_std_ring + RX_STD_RING_ENTRIES;
  934. ap->rx_mini_ring = ap->rx_jumbo_ring + RX_JUMBO_RING_ENTRIES;
  935. ap->rx_return_ring = ap->rx_mini_ring + RX_MINI_RING_ENTRIES;
  936. size = (sizeof(struct event) * EVT_RING_ENTRIES);
  937. ap->evt_ring = pci_alloc_consistent(ap->pdev, size, &ap->evt_ring_dma);
  938. if (ap->evt_ring == NULL)
  939. goto fail;
  940. /*
  941.  * Only allocate a host TX ring for the Tigon II, the Tigon I
  942.  * has to use PCI registers for this ;-(
  943.  */
  944. if (!ACE_IS_TIGON_I(ap)) {
  945. size = (sizeof(struct tx_desc) * MAX_TX_RING_ENTRIES);
  946. ap->tx_ring = pci_alloc_consistent(ap->pdev, size,
  947.    &ap->tx_ring_dma);
  948. if (ap->tx_ring == NULL)
  949. goto fail;
  950. }
  951. ap->evt_prd = pci_alloc_consistent(ap->pdev, sizeof(u32),
  952.    &ap->evt_prd_dma);
  953. if (ap->evt_prd == NULL)
  954. goto fail;
  955. ap->rx_ret_prd = pci_alloc_consistent(ap->pdev, sizeof(u32),
  956.       &ap->rx_ret_prd_dma);
  957. if (ap->rx_ret_prd == NULL)
  958. goto fail;
  959. ap->tx_csm = pci_alloc_consistent(ap->pdev, sizeof(u32),
  960.   &ap->tx_csm_dma);
  961. if (ap->tx_csm == NULL)
  962. goto fail;
  963. return 0;
  964. fail:
  965. /* Clean up. */
  966. ace_init_cleanup(dev);
  967. return 1;
  968. }
  969. /*
  970.  * Generic cleanup handling data allocated during init. Used when the
  971.  * module is unloaded or if an error occurs during initialization
  972.  */
  973. static void ace_init_cleanup(struct net_device *dev)
  974. {
  975. struct ace_private *ap;
  976. ap = dev->priv;
  977. ace_free_descriptors(dev);
  978. if (ap->info)
  979. pci_free_consistent(ap->pdev, sizeof(struct ace_info),
  980.     ap->info, ap->info_dma);
  981. if (ap->skb)
  982. kfree(ap->skb);
  983. if (ap->trace_buf)
  984. kfree(ap->trace_buf);
  985. if (dev->irq)
  986. free_irq(dev->irq, dev);
  987. unregister_netdev(dev);
  988. iounmap(ap->regs);
  989. }
  990. /*
  991.  * Commands are considered to be slow.
  992.  */
  993. static inline void ace_issue_cmd(struct ace_regs *regs, struct cmd *cmd)
  994. {
  995. u32 idx;
  996. idx = readl(&regs->CmdPrd);
  997. writel(*(u32 *)(cmd), &regs->CmdRng[idx]);
  998. idx = (idx + 1) % CMD_RING_ENTRIES;
  999. writel(idx, &regs->CmdPrd);
  1000. }
  1001. static int __init ace_init(struct net_device *dev)
  1002. {
  1003. struct ace_private *ap;
  1004. struct ace_regs *regs;
  1005. struct ace_info *info = NULL;
  1006. struct pci_dev *pdev;
  1007. unsigned long myjif;
  1008. u64 tmp_ptr;
  1009. u32 tig_ver, mac1, mac2, tmp, pci_state;
  1010. int board_idx, ecode = 0;
  1011. short i;
  1012. unsigned char cache_size;
  1013. ap = dev->priv;
  1014. regs = ap->regs;
  1015. board_idx = ap->board_idx;
  1016. /*
  1017.  * aman@sgi.com - its useful to do a NIC reset here to
  1018.  * address the `Firmware not running' problem subsequent
  1019.  * to any crashes involving the NIC
  1020.  */
  1021. writel(HW_RESET | (HW_RESET << 24), &regs->HostCtrl);
  1022. readl(&regs->HostCtrl); /* PCI write posting */
  1023. udelay(5);
  1024. /*
  1025.  * Don't access any other registers before this point!
  1026.  */
  1027. #ifdef __BIG_ENDIAN
  1028. /*
  1029.  * This will most likely need BYTE_SWAP once we switch
  1030.  * to using __raw_writel()
  1031.  */
  1032. writel((WORD_SWAP | CLR_INT | ((WORD_SWAP | CLR_INT) << 24)),
  1033.        &regs->HostCtrl);
  1034. #else
  1035. writel((CLR_INT | WORD_SWAP | ((CLR_INT | WORD_SWAP) << 24)),
  1036.        &regs->HostCtrl);
  1037. #endif
  1038. readl(&regs->HostCtrl); /* PCI write posting */
  1039. /*
  1040.  * Stop the NIC CPU and clear pending interrupts
  1041.  */
  1042. writel(readl(&regs->CpuCtrl) | CPU_HALT, &regs->CpuCtrl);
  1043. readl(&regs->CpuCtrl); /* PCI write posting */
  1044. writel(0, &regs->Mb0Lo);
  1045. tig_ver = readl(&regs->HostCtrl) >> 28;
  1046. switch(tig_ver){
  1047. #ifndef CONFIG_ACENIC_OMIT_TIGON_I
  1048. case 4:
  1049. printk(KERN_INFO "  Tigon I  (Rev. 4), Firmware: %i.%i.%i, ",
  1050.        tigonFwReleaseMajor, tigonFwReleaseMinor,
  1051.        tigonFwReleaseFix);
  1052. writel(0, &regs->LocalCtrl);
  1053. ap->version = 1;
  1054. ap->tx_ring_entries = TIGON_I_TX_RING_ENTRIES;
  1055. break;
  1056. #endif
  1057. case 6:
  1058. printk(KERN_INFO "  Tigon II (Rev. %i), Firmware: %i.%i.%i, ",
  1059.        tig_ver, tigon2FwReleaseMajor, tigon2FwReleaseMinor,
  1060.        tigon2FwReleaseFix);
  1061. writel(readl(&regs->CpuBCtrl) | CPU_HALT, &regs->CpuBCtrl);
  1062. readl(&regs->CpuBCtrl); /* PCI write posting */
  1063. /*
  1064.  * The SRAM bank size does _not_ indicate the amount
  1065.  * of memory on the card, it controls the _bank_ size!
  1066.  * Ie. a 1MB AceNIC will have two banks of 512KB.
  1067.  */
  1068. writel(SRAM_BANK_512K, &regs->LocalCtrl);
  1069. writel(SYNC_SRAM_TIMING, &regs->MiscCfg);
  1070. ap->version = 2;
  1071. ap->tx_ring_entries = MAX_TX_RING_ENTRIES;
  1072. break;
  1073. default:
  1074. printk(KERN_WARNING "  Unsupported Tigon version detected "
  1075.        "(%i), ", tig_ver);
  1076. ecode = -ENODEV;
  1077. goto init_error;
  1078. }
  1079. /*
  1080.  * ModeStat _must_ be set after the SRAM settings as this change
  1081.  * seems to corrupt the ModeStat and possible other registers.
  1082.  * The SRAM settings survive resets and setting it to the same
  1083.  * value a second time works as well. This is what caused the
  1084.  * `Firmware not running' problem on the Tigon II.
  1085.  */
  1086. #ifdef __BIG_ENDIAN
  1087. writel(ACE_BYTE_SWAP_DMA | ACE_WARN | ACE_FATAL | ACE_BYTE_SWAP_BD |
  1088.        ACE_WORD_SWAP_BD | ACE_NO_JUMBO_FRAG, &regs->ModeStat);
  1089. #else
  1090. writel(ACE_BYTE_SWAP_DMA | ACE_WARN | ACE_FATAL |
  1091.        ACE_WORD_SWAP_BD | ACE_NO_JUMBO_FRAG, &regs->ModeStat);
  1092. #endif
  1093. readl(&regs->ModeStat); /* PCI write posting */
  1094. mac1 = 0;
  1095. for(i = 0; i < 4; i++) {
  1096. mac1 = mac1 << 8;
  1097. tmp = read_eeprom_byte(dev, 0x8c+i);
  1098. if (tmp < 0) {
  1099. ecode = -EIO;
  1100. goto init_error;
  1101. } else
  1102. mac1 |= (tmp & 0xff);
  1103. }
  1104. mac2 = 0;
  1105. for(i = 4; i < 8; i++) {
  1106. mac2 = mac2 << 8;
  1107. tmp = read_eeprom_byte(dev, 0x8c+i);
  1108. if (tmp < 0) {
  1109. ecode = -EIO;
  1110. goto init_error;
  1111. } else
  1112. mac2 |= (tmp & 0xff);
  1113. }
  1114. writel(mac1, &regs->MacAddrHi);
  1115. writel(mac2, &regs->MacAddrLo);
  1116. printk("MAC: %02x:%02x:%02x:%02x:%02x:%02xn",
  1117.        (mac1 >> 8) & 0xff, mac1 & 0xff, (mac2 >> 24) &0xff,
  1118.        (mac2 >> 16) & 0xff, (mac2 >> 8) & 0xff, mac2 & 0xff);
  1119. dev->dev_addr[0] = (mac1 >> 8) & 0xff;
  1120. dev->dev_addr[1] = mac1 & 0xff;
  1121. dev->dev_addr[2] = (mac2 >> 24) & 0xff;
  1122. dev->dev_addr[3] = (mac2 >> 16) & 0xff;
  1123. dev->dev_addr[4] = (mac2 >> 8) & 0xff;
  1124. dev->dev_addr[5] = mac2 & 0xff;
  1125. /*
  1126.  * Looks like this is necessary to deal with on all architectures,
  1127.  * even this %$#%$# N440BX Intel based thing doesn't get it right.
  1128.  * Ie. having two NICs in the machine, one will have the cache
  1129.  * line set at boot time, the other will not.
  1130.  */
  1131. pdev = ap->pdev;
  1132. pci_read_config_byte(pdev, PCI_CACHE_LINE_SIZE, &cache_size);
  1133. cache_size <<= 2;
  1134. if (cache_size != SMP_CACHE_BYTES) {
  1135. printk(KERN_INFO "  PCI cache line size set incorrectly "
  1136.        "(%i bytes) by BIOS/FW, ", cache_size);
  1137. if (cache_size > SMP_CACHE_BYTES)
  1138. printk("expecting %in", SMP_CACHE_BYTES);
  1139. else {
  1140. printk("correcting to %in", SMP_CACHE_BYTES);
  1141. pci_write_config_byte(pdev, PCI_CACHE_LINE_SIZE,
  1142.       SMP_CACHE_BYTES >> 2);
  1143. }
  1144. }
  1145. pci_state = readl(&regs->PciState);
  1146. printk(KERN_INFO "  PCI bus width: %i bits, speed: %iMHz, "
  1147.        "latency: %i clksn",
  1148.         (pci_state & PCI_32BIT) ? 32 : 64,
  1149. (pci_state & PCI_66MHZ) ? 66 : 33, 
  1150. ap->pci_latency);
  1151. /*
  1152.  * Set the max DMA transfer size. Seems that for most systems
  1153.  * the performance is better when no MAX parameter is
  1154.  * set. However for systems enabling PCI write and invalidate,
  1155.  * DMA writes must be set to the L1 cache line size to get
  1156.  * optimal performance.
  1157.  *
  1158.  * The default is now to turn the PCI write and invalidate off
  1159.  * - that is what Alteon does for NT.
  1160.  */
  1161. tmp = READ_CMD_MEM | WRITE_CMD_MEM;
  1162. if (ap->version >= 2) {
  1163. tmp |= (MEM_READ_MULTIPLE | (pci_state & PCI_66MHZ));
  1164. /*
  1165.  * Tuning parameters only supported for 8 cards
  1166.  */
  1167. if (board_idx == BOARD_IDX_OVERFLOW ||
  1168.     dis_pci_mem_inval[board_idx]) {
  1169. if (ap->pci_command & PCI_COMMAND_INVALIDATE) {
  1170. ap->pci_command &= ~PCI_COMMAND_INVALIDATE;
  1171. pci_write_config_word(pdev, PCI_COMMAND,
  1172.       ap->pci_command);
  1173. printk(KERN_INFO "  Disabling PCI memory "
  1174.        "write and invalidaten");
  1175. }
  1176. } else if (ap->pci_command & PCI_COMMAND_INVALIDATE) {
  1177. printk(KERN_INFO "  PCI memory write & invalidate "
  1178.        "enabled by BIOS, enabling counter measuresn");
  1179. switch(SMP_CACHE_BYTES) {
  1180. case 16:
  1181. tmp |= DMA_WRITE_MAX_16;
  1182. break;
  1183. case 32:
  1184. tmp |= DMA_WRITE_MAX_32;
  1185. break;
  1186. case 64:
  1187. tmp |= DMA_WRITE_MAX_64;
  1188. break;
  1189. case 128:
  1190. tmp |= DMA_WRITE_MAX_128;
  1191. break;
  1192. default:
  1193. printk(KERN_INFO "  Cache line size %i not "
  1194.        "supported, PCI write and invalidate "
  1195.        "disabledn", SMP_CACHE_BYTES);
  1196. ap->pci_command &= ~PCI_COMMAND_INVALIDATE;
  1197. pci_write_config_word(pdev, PCI_COMMAND,
  1198.       ap->pci_command);
  1199. }
  1200. }
  1201. }
  1202. #ifdef __sparc__
  1203. /*
  1204.  * On this platform, we know what the best dma settings
  1205.  * are.  We use 64-byte maximum bursts, because if we
  1206.  * burst larger than the cache line size (or even cross
  1207.  * a 64byte boundry in a single burst) the UltraSparc
  1208.  * PCI controller will disconnect at 64-byte multiples.
  1209.  *
  1210.  * Read-multiple will be properly enabled above, and when
  1211.  * set will give the PCI controller proper hints about
  1212.  * prefetching.
  1213.  */
  1214. tmp &= ~DMA_READ_WRITE_MASK;
  1215. tmp |= DMA_READ_MAX_64;
  1216. tmp |= DMA_WRITE_MAX_64;
  1217. #endif
  1218. #ifdef __alpha__
  1219. tmp &= ~DMA_READ_WRITE_MASK;
  1220. tmp |= DMA_READ_MAX_128;
  1221. /*
  1222.  * All the docs say MUST NOT. Well, I did.
  1223.  * Nothing terrible happens, if we load wrong size.
  1224.  * Bit w&i still works better!
  1225.  */
  1226. tmp |= DMA_WRITE_MAX_128;
  1227. #endif
  1228. writel(tmp, &regs->PciState);
  1229. #if 0
  1230. /*
  1231.  * The Host PCI bus controller driver has to set FBB.
  1232.  * If all devices on that PCI bus support FBB, then the controller
  1233.  * can enable FBB support in the Host PCI Bus controller (or on
  1234.  * the PCI-PCI bridge if that applies).
  1235.  * -ggg
  1236.  */
  1237. /*
  1238.  * I have received reports from people having problems when this
  1239.  * bit is enabled.
  1240.  */
  1241. if (!(ap->pci_command & PCI_COMMAND_FAST_BACK)) {
  1242. printk(KERN_INFO "  Enabling PCI Fast Back to Backn");
  1243. ap->pci_command |= PCI_COMMAND_FAST_BACK;
  1244. pci_write_config_word(pdev, PCI_COMMAND, ap->pci_command);
  1245. }
  1246. #endif
  1247. /*
  1248.  * Configure DMA attributes.
  1249.  */
  1250. if (!pci_set_dma_mask(pdev, 0xffffffffffffffffULL)) {
  1251. ap->pci_using_dac = 1;
  1252. } else if (!pci_set_dma_mask(pdev, 0xffffffffULL)) {
  1253. ap->pci_using_dac = 0;
  1254. } else {
  1255. ecode = -ENODEV;
  1256. goto init_error;
  1257. }
  1258. /*
  1259.  * Initialize the generic info block and the command+event rings
  1260.  * and the control blocks for the transmit and receive rings
  1261.  * as they need to be setup once and for all.
  1262.  */
  1263. if (!(info = pci_alloc_consistent(ap->pdev, sizeof(struct ace_info),
  1264.   &ap->info_dma))) {
  1265. ecode = -EAGAIN;
  1266. goto init_error;
  1267. }
  1268. ap->info = info;
  1269. /*
  1270.  * Get the memory for the skb rings.
  1271.  */
  1272. if (!(ap->skb = kmalloc(sizeof(struct ace_skb), GFP_KERNEL))) {
  1273. ecode = -EAGAIN;
  1274. goto init_error;
  1275. }
  1276. ecode = request_irq(pdev->irq, ace_interrupt, SA_SHIRQ,
  1277.     dev->name, dev);
  1278. if (ecode) {
  1279. printk(KERN_WARNING "%s: Requested IRQ %d is busyn",
  1280.        dev->name, pdev->irq);
  1281. goto init_error;
  1282. } else
  1283. dev->irq = pdev->irq;
  1284. /*
  1285.  * Register the device here to be able to catch allocated
  1286.  * interrupt handlers in case the firmware doesn't come up.
  1287.  */
  1288. ap->next = root_dev;
  1289. root_dev = dev;
  1290. #ifdef INDEX_DEBUG
  1291. spin_lock_init(&ap->debug_lock);
  1292. ap->last_tx = ACE_TX_RING_ENTRIES(ap) - 1;
  1293. ap->last_std_rx = 0;
  1294. ap->last_mini_rx = 0;
  1295. #endif
  1296. memset(ap->info, 0, sizeof(struct ace_info));
  1297. memset(ap->skb, 0, sizeof(struct ace_skb));
  1298. ace_load_firmware(dev);
  1299. ap->fw_running = 0;
  1300. tmp_ptr = ap->info_dma;
  1301. writel(tmp_ptr >> 32, &regs->InfoPtrHi);
  1302. writel(tmp_ptr & 0xffffffff, &regs->InfoPtrLo);
  1303. memset(ap->evt_ring, 0, EVT_RING_ENTRIES * sizeof(struct event));
  1304. set_aceaddr(&info->evt_ctrl.rngptr, ap->evt_ring_dma);
  1305. info->evt_ctrl.flags = 0;
  1306. *(ap->evt_prd) = 0;
  1307. wmb();
  1308. set_aceaddr(&info->evt_prd_ptr, ap->evt_prd_dma);
  1309. writel(0, &regs->EvtCsm);
  1310. set_aceaddr(&info->cmd_ctrl.rngptr, 0x100);
  1311. info->cmd_ctrl.flags = 0;
  1312. info->cmd_ctrl.max_len = 0;
  1313. for (i = 0; i < CMD_RING_ENTRIES; i++)
  1314. writel(0, &regs->CmdRng[i]);
  1315. writel(0, &regs->CmdPrd);
  1316. writel(0, &regs->CmdCsm);
  1317. tmp_ptr = ap->info_dma;
  1318. tmp_ptr += (unsigned long) &(((struct ace_info *)0)->s.stats);
  1319. set_aceaddr(&info->stats2_ptr, (dma_addr_t) tmp_ptr);
  1320. set_aceaddr(&info->rx_std_ctrl.rngptr, ap->rx_ring_base_dma);
  1321. info->rx_std_ctrl.max_len = ACE_STD_MTU + ETH_HLEN + 4;
  1322. info->rx_std_ctrl.flags =
  1323.   RCB_FLG_TCP_UDP_SUM | RCB_FLG_NO_PSEUDO_HDR | ACE_RCB_VLAN_FLAG;
  1324. memset(ap->rx_std_ring, 0,
  1325.        RX_STD_RING_ENTRIES * sizeof(struct rx_desc));
  1326. for (i = 0; i < RX_STD_RING_ENTRIES; i++)
  1327. ap->rx_std_ring[i].flags = BD_FLG_TCP_UDP_SUM;
  1328. ap->rx_std_skbprd = 0;
  1329. atomic_set(&ap->cur_rx_bufs, 0);
  1330. set_aceaddr(&info->rx_jumbo_ctrl.rngptr,
  1331.     (ap->rx_ring_base_dma +
  1332.      (sizeof(struct rx_desc) * RX_STD_RING_ENTRIES)));
  1333. info->rx_jumbo_ctrl.max_len = 0;
  1334. info->rx_jumbo_ctrl.flags =
  1335.   RCB_FLG_TCP_UDP_SUM | RCB_FLG_NO_PSEUDO_HDR | ACE_RCB_VLAN_FLAG;
  1336. memset(ap->rx_jumbo_ring, 0,
  1337.        RX_JUMBO_RING_ENTRIES * sizeof(struct rx_desc));
  1338. for (i = 0; i < RX_JUMBO_RING_ENTRIES; i++)
  1339. ap->rx_jumbo_ring[i].flags = BD_FLG_TCP_UDP_SUM | BD_FLG_JUMBO;
  1340. ap->rx_jumbo_skbprd = 0;
  1341. atomic_set(&ap->cur_jumbo_bufs, 0);
  1342. memset(ap->rx_mini_ring, 0,
  1343.        RX_MINI_RING_ENTRIES * sizeof(struct rx_desc));
  1344. if (ap->version >= 2) {
  1345. set_aceaddr(&info->rx_mini_ctrl.rngptr,
  1346.     (ap->rx_ring_base_dma +
  1347.      (sizeof(struct rx_desc) *
  1348.       (RX_STD_RING_ENTRIES +
  1349.        RX_JUMBO_RING_ENTRIES))));
  1350. info->rx_mini_ctrl.max_len = ACE_MINI_SIZE;
  1351. info->rx_mini_ctrl.flags = 
  1352.   RCB_FLG_TCP_UDP_SUM|RCB_FLG_NO_PSEUDO_HDR|ACE_RCB_VLAN_FLAG;
  1353. for (i = 0; i < RX_MINI_RING_ENTRIES; i++)
  1354. ap->rx_mini_ring[i].flags =
  1355. BD_FLG_TCP_UDP_SUM | BD_FLG_MINI;
  1356. } else {
  1357. set_aceaddr(&info->rx_mini_ctrl.rngptr, 0);
  1358. info->rx_mini_ctrl.flags = RCB_FLG_RNG_DISABLE;
  1359. info->rx_mini_ctrl.max_len = 0;
  1360. }
  1361. ap->rx_mini_skbprd = 0;
  1362. atomic_set(&ap->cur_mini_bufs, 0);
  1363. set_aceaddr(&info->rx_return_ctrl.rngptr,
  1364.     (ap->rx_ring_base_dma +
  1365.      (sizeof(struct rx_desc) *
  1366.       (RX_STD_RING_ENTRIES +
  1367.        RX_JUMBO_RING_ENTRIES +
  1368.        RX_MINI_RING_ENTRIES))));
  1369. info->rx_return_ctrl.flags = 0;
  1370. info->rx_return_ctrl.max_len = RX_RETURN_RING_ENTRIES;
  1371. memset(ap->rx_return_ring, 0,
  1372.        RX_RETURN_RING_ENTRIES * sizeof(struct rx_desc));
  1373. set_aceaddr(&info->rx_ret_prd_ptr, ap->rx_ret_prd_dma);
  1374. *(ap->rx_ret_prd) = 0;
  1375. writel(TX_RING_BASE, &regs->WinBase);
  1376. if (ACE_IS_TIGON_I(ap)) {
  1377. ap->tx_ring = (struct tx_desc *)regs->Window;
  1378. for (i = 0; i < (TIGON_I_TX_RING_ENTRIES * 
  1379.  sizeof(struct tx_desc) / 4); i++) {
  1380. writel(0, (unsigned long)ap->tx_ring + i * 4);
  1381. }
  1382. set_aceaddr(&info->tx_ctrl.rngptr, TX_RING_BASE);
  1383. } else {
  1384. memset(ap->tx_ring, 0,
  1385.        MAX_TX_RING_ENTRIES * sizeof(struct tx_desc));
  1386. set_aceaddr(&info->tx_ctrl.rngptr, ap->tx_ring_dma);
  1387. }
  1388. info->tx_ctrl.max_len = ACE_TX_RING_ENTRIES(ap);
  1389. tmp = RCB_FLG_TCP_UDP_SUM | RCB_FLG_NO_PSEUDO_HDR | ACE_RCB_VLAN_FLAG;
  1390. /*
  1391.  * The Tigon I does not like having the TX ring in host memory ;-(
  1392.  */
  1393. if (!ACE_IS_TIGON_I(ap))
  1394. tmp |= RCB_FLG_TX_HOST_RING;
  1395. #if TX_COAL_INTS_ONLY
  1396. tmp |= RCB_FLG_COAL_INT_ONLY;
  1397. #endif
  1398. info->tx_ctrl.flags = tmp;
  1399. set_aceaddr(&info->tx_csm_ptr, ap->tx_csm_dma);
  1400. /*
  1401.  * Potential item for tuning parameter
  1402.  */
  1403. #if 0 /* NO */
  1404. writel(DMA_THRESH_16W, &regs->DmaReadCfg);
  1405. writel(DMA_THRESH_16W, &regs->DmaWriteCfg);
  1406. #else
  1407. writel(DMA_THRESH_8W, &regs->DmaReadCfg);
  1408. writel(DMA_THRESH_8W, &regs->DmaWriteCfg);
  1409. #endif
  1410. writel(0, &regs->MaskInt);
  1411. writel(1, &regs->IfIdx);
  1412. #if 0
  1413. /*
  1414.  * McKinley boxes do not like us fiddling with AssistState
  1415.  * this early
  1416.  */
  1417. writel(1, &regs->AssistState);
  1418. #endif
  1419. writel(DEF_STAT, &regs->TuneStatTicks);
  1420. writel(DEF_TRACE, &regs->TuneTrace);
  1421. ace_set_rxtx_parms(dev, 0);
  1422. if (board_idx == BOARD_IDX_OVERFLOW) {
  1423. printk(KERN_WARNING "%s: more than %i NICs detected, "
  1424.        "ignoring module parameters!n",
  1425.        dev->name, ACE_MAX_MOD_PARMS);
  1426. } else if (board_idx >= 0) {
  1427. if (tx_coal_tick[board_idx])
  1428. writel(tx_coal_tick[board_idx],
  1429.        &regs->TuneTxCoalTicks);
  1430. if (max_tx_desc[board_idx])
  1431. writel(max_tx_desc[board_idx], &regs->TuneMaxTxDesc);
  1432. if (rx_coal_tick[board_idx])
  1433. writel(rx_coal_tick[board_idx],
  1434.        &regs->TuneRxCoalTicks);
  1435. if (max_rx_desc[board_idx])
  1436. writel(max_rx_desc[board_idx], &regs->TuneMaxRxDesc);
  1437. if (trace[board_idx])
  1438. writel(trace[board_idx], &regs->TuneTrace);
  1439. if ((tx_ratio[board_idx] > 0) && (tx_ratio[board_idx] < 64))
  1440. writel(tx_ratio[board_idx], &regs->TxBufRat);
  1441. }
  1442. /*
  1443.  * Default link parameters
  1444.  */
  1445. tmp = LNK_ENABLE | LNK_FULL_DUPLEX | LNK_1000MB | LNK_100MB |
  1446. LNK_10MB | LNK_RX_FLOW_CTL_Y | LNK_NEG_FCTL | LNK_NEGOTIATE;
  1447. if(ap->version >= 2)
  1448. tmp |= LNK_TX_FLOW_CTL_Y;
  1449. /*
  1450.  * Override link default parameters
  1451.  */
  1452. if ((board_idx >= 0) && link[board_idx]) {
  1453. int option = link[board_idx];
  1454. tmp = LNK_ENABLE;
  1455. if (option & 0x01) {
  1456. printk(KERN_INFO "%s: Setting half duplex linkn",
  1457.        dev->name);
  1458. tmp &= ~LNK_FULL_DUPLEX;
  1459. }
  1460. if (option & 0x02)
  1461. tmp &= ~LNK_NEGOTIATE;
  1462. if (option & 0x10)
  1463. tmp |= LNK_10MB;
  1464. if (option & 0x20)
  1465. tmp |= LNK_100MB;
  1466. if (option & 0x40)
  1467. tmp |= LNK_1000MB;
  1468. if ((option & 0x70) == 0) {
  1469. printk(KERN_WARNING "%s: No media speed specified, "
  1470.        "forcing auto negotiationn", dev->name);
  1471. tmp |= LNK_NEGOTIATE | LNK_1000MB |
  1472. LNK_100MB | LNK_10MB;
  1473. }
  1474. if ((option & 0x100) == 0)
  1475. tmp |= LNK_NEG_FCTL;
  1476. else
  1477. printk(KERN_INFO "%s: Disabling flow control "
  1478.        "negotiationn", dev->name);
  1479. if (option & 0x200)
  1480. tmp |= LNK_RX_FLOW_CTL_Y;
  1481. if ((option & 0x400) && (ap->version >= 2)) {
  1482. printk(KERN_INFO "%s: Enabling TX flow controln",
  1483.        dev->name);
  1484. tmp |= LNK_TX_FLOW_CTL_Y;
  1485. }
  1486. }
  1487. ap->link = tmp;
  1488. writel(tmp, &regs->TuneLink);
  1489. if (ap->version >= 2)
  1490. writel(tmp, &regs->TuneFastLink);
  1491. if (ACE_IS_TIGON_I(ap))
  1492. writel(tigonFwStartAddr, &regs->Pc);
  1493. if (ap->version == 2)
  1494. writel(tigon2FwStartAddr, &regs->Pc);
  1495. writel(0, &regs->Mb0Lo);
  1496. /*
  1497.  * Set tx_csm before we start receiving interrupts, otherwise
  1498.  * the interrupt handler might think it is supposed to process
  1499.  * tx ints before we are up and running, which may cause a null
  1500.  * pointer access in the int handler.
  1501.  */
  1502. ap->cur_rx = 0;
  1503. ap->tx_prd = *(ap->tx_csm) = ap->tx_ret_csm = 0;
  1504. wmb();
  1505. ace_set_txprd(regs, ap, 0);
  1506. writel(0, &regs->RxRetCsm);
  1507. /*
  1508.  * Zero the stats before starting the interface
  1509.  */
  1510. memset(&ap->stats, 0, sizeof(ap->stats));
  1511.        /*
  1512. * Enable DMA engine now.
  1513. * If we do this sooner, Mckinley box pukes.
  1514. * I assume it's because Tigon II DMA engine wants to check
  1515. * *something* even before the CPU is started.
  1516. */
  1517.        writel(1, &regs->AssistState);  /* enable DMA */
  1518. /*
  1519.  * Start the NIC CPU
  1520.  */
  1521. writel(readl(&regs->CpuCtrl) & ~(CPU_HALT|CPU_TRACE), &regs->CpuCtrl);
  1522. readl(&regs->CpuCtrl);
  1523. /*
  1524.  * Wait for the firmware to spin up - max 3 seconds.
  1525.  */
  1526. myjif = jiffies + 3 * HZ;
  1527. while (time_before(jiffies, myjif) && !ap->fw_running);
  1528. if (!ap->fw_running) {
  1529. printk(KERN_ERR "%s: Firmware NOT running!n", dev->name);
  1530. ace_dump_trace(ap);
  1531. writel(readl(&regs->CpuCtrl) | CPU_HALT, &regs->CpuCtrl);
  1532. readl(&regs->CpuCtrl);
  1533. /* aman@sgi.com - account for badly behaving firmware/NIC:
  1534.  * - have observed that the NIC may continue to generate
  1535.  *   interrupts for some reason; attempt to stop it - halt
  1536.  *   second CPU for Tigon II cards, and also clear Mb0
  1537.  * - if we're a module, we'll fail to load if this was
  1538.  *   the only GbE card in the system => if the kernel does
  1539.  *   see an interrupt from the NIC, code to handle it is
  1540.  *   gone and OOps! - so free_irq also
  1541.  */
  1542. if (ap->version >= 2)
  1543. writel(readl(&regs->CpuBCtrl) | CPU_HALT,
  1544.        &regs->CpuBCtrl);
  1545. writel(0, &regs->Mb0Lo);
  1546. readl(&regs->Mb0Lo);
  1547. ecode = -EBUSY;
  1548. goto init_error;
  1549. }
  1550. /*
  1551.  * We load the ring here as there seem to be no way to tell the
  1552.  * firmware to wipe the ring without re-initializing it.
  1553.  */
  1554. if (!test_and_set_bit(0, &ap->std_refill_busy))
  1555. ace_load_std_rx_ring(ap, RX_RING_SIZE);
  1556. else
  1557. printk(KERN_ERR "%s: Someone is busy refilling the RX ringn",
  1558.        dev->name);
  1559. if (ap->version >= 2) {
  1560. if (!test_and_set_bit(0, &ap->mini_refill_busy))
  1561. ace_load_mini_rx_ring(ap, RX_MINI_SIZE);
  1562. else
  1563. printk(KERN_ERR "%s: Someone is busy refilling "
  1564.        "the RX mini ringn", dev->name);
  1565. }
  1566. return 0;
  1567.  init_error:
  1568. ace_init_cleanup(dev);
  1569. return ecode;
  1570. }
  1571. static void ace_set_rxtx_parms(struct net_device *dev, int jumbo)
  1572. {
  1573. struct ace_private *ap;
  1574. struct ace_regs *regs;
  1575. int board_idx;
  1576. ap = dev->priv;
  1577. regs = ap->regs;
  1578. board_idx = ap->board_idx;
  1579. if (board_idx >= 0) {
  1580. if (!jumbo) {
  1581. if (!tx_coal_tick[board_idx])
  1582. writel(DEF_TX_COAL, &regs->TuneTxCoalTicks);
  1583. if (!max_tx_desc[board_idx])
  1584. writel(DEF_TX_MAX_DESC, &regs->TuneMaxTxDesc);
  1585. if (!rx_coal_tick[board_idx])
  1586. writel(DEF_RX_COAL, &regs->TuneRxCoalTicks);
  1587. if (!max_rx_desc[board_idx])
  1588. writel(DEF_RX_MAX_DESC, &regs->TuneMaxRxDesc);
  1589. if (!tx_ratio[board_idx])
  1590. writel(DEF_TX_RATIO, &regs->TxBufRat);
  1591. } else {
  1592. if (!tx_coal_tick[board_idx])
  1593. writel(DEF_JUMBO_TX_COAL,
  1594.        &regs->TuneTxCoalTicks);
  1595. if (!max_tx_desc[board_idx])
  1596. writel(DEF_JUMBO_TX_MAX_DESC,
  1597.        &regs->TuneMaxTxDesc);
  1598. if (!rx_coal_tick[board_idx])
  1599. writel(DEF_JUMBO_RX_COAL,
  1600.        &regs->TuneRxCoalTicks);
  1601. if (!max_rx_desc[board_idx])
  1602. writel(DEF_JUMBO_RX_MAX_DESC,
  1603.        &regs->TuneMaxRxDesc);
  1604. if (!tx_ratio[board_idx])
  1605. writel(DEF_JUMBO_TX_RATIO, &regs->TxBufRat);
  1606. }
  1607. }
  1608. }
  1609. static void ace_watchdog(struct net_device *data)
  1610. {
  1611. struct net_device *dev = data;
  1612. struct ace_private *ap = dev->priv;
  1613. struct ace_regs *regs = ap->regs;
  1614. /*
  1615.  * We haven't received a stats update event for more than 2.5
  1616.  * seconds and there is data in the transmit queue, thus we
  1617.  * asume the card is stuck.
  1618.  */
  1619. if (*ap->tx_csm != ap->tx_ret_csm) {
  1620. printk(KERN_WARNING "%s: Transmitter is stuck, %08xn",
  1621.        dev->name, (unsigned int)readl(&regs->HostCtrl));
  1622. /* This can happen due to ieee flow control. */
  1623. } else {
  1624. printk(KERN_DEBUG "%s: BUG... transmitter died. Kicking it.n",
  1625.        dev->name);
  1626. netif_wake_queue(dev);
  1627. }
  1628. }
  1629. static void ace_tasklet(unsigned long dev)
  1630. {
  1631. struct ace_private *ap = ((struct net_device *)dev)->priv;
  1632. int cur_size;
  1633. cur_size = atomic_read(&ap->cur_rx_bufs);
  1634. if ((cur_size < RX_LOW_STD_THRES) &&
  1635.     !test_and_set_bit(0, &ap->std_refill_busy)) {
  1636. #if DEBUG
  1637. printk("refilling buffers (current %i)n", cur_size);
  1638. #endif
  1639. ace_load_std_rx_ring(ap, RX_RING_SIZE - cur_size);
  1640. }
  1641. if (ap->version >= 2) {
  1642. cur_size = atomic_read(&ap->cur_mini_bufs);
  1643. if ((cur_size < RX_LOW_MINI_THRES) &&
  1644.     !test_and_set_bit(0, &ap->mini_refill_busy)) {
  1645. #if DEBUG
  1646. printk("refilling mini buffers (current %i)n",
  1647.        cur_size);
  1648. #endif
  1649. ace_load_mini_rx_ring(ap, RX_MINI_SIZE - cur_size);
  1650. }
  1651. }
  1652. cur_size = atomic_read(&ap->cur_jumbo_bufs);
  1653. if (ap->jumbo && (cur_size < RX_LOW_JUMBO_THRES) &&
  1654.     !test_and_set_bit(0, &ap->jumbo_refill_busy)) {
  1655. #if DEBUG
  1656. printk("refilling jumbo buffers (current %i)n", cur_size);
  1657. #endif
  1658. ace_load_jumbo_rx_ring(ap, RX_JUMBO_SIZE - cur_size);
  1659. }
  1660. ap->tasklet_pending = 0;
  1661. }
  1662. /*
  1663.  * Copy the contents of the NIC's trace buffer to kernel memory.
  1664.  */
  1665. static void ace_dump_trace(struct ace_private *ap)
  1666. {
  1667. #if 0
  1668. if (!ap->trace_buf)
  1669. if (!(ap->trace_buf = kmalloc(ACE_TRACE_SIZE, GFP_KERNEL)))
  1670.     return;
  1671. #endif
  1672. }
  1673. /*
  1674.  * Load the standard rx ring.
  1675.  *
  1676.  * Loading rings is safe without holding the spin lock since this is
  1677.  * done only before the device is enabled, thus no interrupts are
  1678.  * generated and by the interrupt handler/tasklet handler.
  1679.  */
  1680. static void ace_load_std_rx_ring(struct ace_private *ap, int nr_bufs)
  1681. {
  1682. struct ace_regs *regs;
  1683. short i, idx;
  1684. regs = ap->regs;
  1685. prefetchw(&ap->cur_rx_bufs);
  1686. idx = ap->rx_std_skbprd;
  1687. for (i = 0; i < nr_bufs; i++) {
  1688. struct sk_buff *skb;
  1689. struct rx_desc *rd;
  1690. dma_addr_t mapping;
  1691. skb = alloc_skb(ACE_STD_BUFSIZE, GFP_ATOMIC);
  1692. if (!skb)
  1693. break;
  1694. /*
  1695.  * Make sure IP header starts on a fresh cache line.
  1696.  */
  1697. skb_reserve(skb, 2 + 16);
  1698. mapping = pci_map_page(ap->pdev, virt_to_page(skb->data),
  1699.        ((unsigned long)skb->data & ~PAGE_MASK),
  1700.        ACE_STD_BUFSIZE - (2 + 16),
  1701.        PCI_DMA_FROMDEVICE);
  1702. ap->skb->rx_std_skbuff[idx].skb = skb;
  1703. pci_unmap_addr_set(&ap->skb->rx_std_skbuff[idx],
  1704.    mapping, mapping);
  1705. rd = &ap->rx_std_ring[idx];
  1706. set_aceaddr(&rd->addr, mapping);
  1707. rd->size = ACE_STD_MTU + ETH_HLEN + 4;
  1708. rd->idx = idx;
  1709. idx = (idx + 1) % RX_STD_RING_ENTRIES;
  1710. }
  1711. if (!i)
  1712. goto error_out;
  1713. atomic_add(i, &ap->cur_rx_bufs);
  1714. ap->rx_std_skbprd = idx;
  1715. if (ACE_IS_TIGON_I(ap)) {
  1716. struct cmd cmd;
  1717. cmd.evt = C_SET_RX_PRD_IDX;
  1718. cmd.code = 0;
  1719. cmd.idx = ap->rx_std_skbprd;
  1720. ace_issue_cmd(regs, &cmd);
  1721. } else {
  1722. writel(idx, &regs->RxStdPrd);
  1723. wmb();
  1724. }
  1725.  out:
  1726. clear_bit(0, &ap->std_refill_busy);
  1727. return;
  1728.  error_out:
  1729. printk(KERN_INFO "Out of memory when allocating "
  1730.        "standard receive buffersn");
  1731. goto out;
  1732. }
  1733. static void ace_load_mini_rx_ring(struct ace_private *ap, int nr_bufs)
  1734. {
  1735. struct ace_regs *regs;
  1736. short i, idx;
  1737. regs = ap->regs;
  1738. prefetchw(&ap->cur_mini_bufs);
  1739. idx = ap->rx_mini_skbprd;
  1740. for (i = 0; i < nr_bufs; i++) {
  1741. struct sk_buff *skb;
  1742. struct rx_desc *rd;
  1743. dma_addr_t mapping;
  1744. skb = alloc_skb(ACE_MINI_BUFSIZE, GFP_ATOMIC);
  1745. if (!skb)
  1746. break;
  1747. /*
  1748.  * Make sure the IP header ends up on a fresh cache line
  1749.  */
  1750. skb_reserve(skb, 2 + 16);
  1751. mapping = pci_map_page(ap->pdev, virt_to_page(skb->data),
  1752.        ((unsigned long)skb->data & ~PAGE_MASK),
  1753.        ACE_MINI_BUFSIZE - (2 + 16),
  1754.        PCI_DMA_FROMDEVICE);
  1755. ap->skb->rx_mini_skbuff[idx].skb = skb;
  1756. pci_unmap_addr_set(&ap->skb->rx_mini_skbuff[idx],
  1757.    mapping, mapping);
  1758. rd = &ap->rx_mini_ring[idx];
  1759. set_aceaddr(&rd->addr, mapping);
  1760. rd->size = ACE_MINI_SIZE;
  1761. rd->idx = idx;
  1762. idx = (idx + 1) % RX_MINI_RING_ENTRIES;
  1763. }
  1764. if (!i)
  1765. goto error_out;
  1766. atomic_add(i, &ap->cur_mini_bufs);
  1767. ap->rx_mini_skbprd = idx;
  1768. writel(idx, &regs->RxMiniPrd);
  1769. wmb();
  1770.  out:
  1771. clear_bit(0, &ap->mini_refill_busy);
  1772. return;
  1773.  error_out:
  1774. printk(KERN_INFO "Out of memory when allocating "
  1775.        "mini receive buffersn");
  1776. goto out;
  1777. }
  1778. /*
  1779.  * Load the jumbo rx ring, this may happen at any time if the MTU
  1780.  * is changed to a value > 1500.
  1781.  */
  1782. static void ace_load_jumbo_rx_ring(struct ace_private *ap, int nr_bufs)
  1783. {
  1784. struct ace_regs *regs;
  1785. short i, idx;
  1786. regs = ap->regs;
  1787. idx = ap->rx_jumbo_skbprd;
  1788. for (i = 0; i < nr_bufs; i++) {
  1789. struct sk_buff *skb;
  1790. struct rx_desc *rd;
  1791. dma_addr_t mapping;
  1792. skb = alloc_skb(ACE_JUMBO_BUFSIZE, GFP_ATOMIC);
  1793. if (!skb)
  1794. break;
  1795. /*
  1796.  * Make sure the IP header ends up on a fresh cache line
  1797.  */
  1798. skb_reserve(skb, 2 + 16);
  1799. mapping = pci_map_page(ap->pdev, virt_to_page(skb->data),
  1800.        ((unsigned long)skb->data & ~PAGE_MASK),
  1801.        ACE_JUMBO_BUFSIZE - (2 + 16),
  1802.        PCI_DMA_FROMDEVICE);
  1803. ap->skb->rx_jumbo_skbuff[idx].skb = skb;
  1804. pci_unmap_addr_set(&ap->skb->rx_jumbo_skbuff[idx],
  1805.    mapping, mapping);
  1806. rd = &ap->rx_jumbo_ring[idx];
  1807. set_aceaddr(&rd->addr, mapping);
  1808. rd->size = ACE_JUMBO_MTU + ETH_HLEN + 4;
  1809. rd->idx = idx;
  1810. idx = (idx + 1) % RX_JUMBO_RING_ENTRIES;
  1811. }
  1812. if (!i)
  1813. goto error_out;
  1814. atomic_add(i, &ap->cur_jumbo_bufs);
  1815. ap->rx_jumbo_skbprd = idx;
  1816. if (ACE_IS_TIGON_I(ap)) {
  1817. struct cmd cmd;
  1818. cmd.evt = C_SET_RX_JUMBO_PRD_IDX;
  1819. cmd.code = 0;
  1820. cmd.idx = ap->rx_jumbo_skbprd;
  1821. ace_issue_cmd(regs, &cmd);
  1822. } else {
  1823. writel(idx, &regs->RxJumboPrd);
  1824. wmb();
  1825. }
  1826.  out:
  1827. clear_bit(0, &ap->jumbo_refill_busy);
  1828. return;
  1829.  error_out:
  1830. if (net_ratelimit())
  1831. printk(KERN_INFO "Out of memory when allocating "
  1832.        "jumbo receive buffersn");
  1833. goto out;
  1834. }
  1835. /*
  1836.  * All events are considered to be slow (RX/TX ints do not generate
  1837.  * events) and are handled here, outside the main interrupt handler,
  1838.  * to reduce the size of the handler.
  1839.  */
  1840. static u32 ace_handle_event(struct net_device *dev, u32 evtcsm, u32 evtprd)
  1841. {
  1842. struct ace_private *ap;
  1843. ap = dev->priv;
  1844. while (evtcsm != evtprd) {
  1845. switch (ap->evt_ring[evtcsm].evt) {
  1846. case E_FW_RUNNING:
  1847. printk(KERN_INFO "%s: Firmware up and runningn",
  1848.        dev->name);
  1849. ap->fw_running = 1;
  1850. wmb();
  1851. break;
  1852. case E_STATS_UPDATED:
  1853. break;
  1854. case E_LNK_STATE:
  1855. {
  1856. u16 code = ap->evt_ring[evtcsm].code;
  1857. switch (code) {
  1858. case E_C_LINK_UP:
  1859. {
  1860. u32 state = readl(&ap->regs->GigLnkState);
  1861. printk(KERN_WARNING "%s: Optical link UP "
  1862.        "(%s Duplex, Flow Control: %s%s)n",
  1863.        dev->name,
  1864.        state & LNK_FULL_DUPLEX ? "Full":"Half",
  1865.        state & LNK_TX_FLOW_CTL_Y ? "TX " : "",
  1866.        state & LNK_RX_FLOW_CTL_Y ? "RX" : "");
  1867. break;
  1868. }
  1869. case E_C_LINK_DOWN:
  1870. printk(KERN_WARNING "%s: Optical link DOWNn",
  1871.        dev->name);
  1872. break;
  1873. case E_C_LINK_10_100:
  1874. printk(KERN_WARNING "%s: 10/100BaseT link "
  1875.        "UPn", dev->name);
  1876. break;
  1877. default:
  1878. printk(KERN_ERR "%s: Unknown optical link "
  1879.        "state %02xn", dev->name, code);
  1880. }
  1881. break;
  1882. }
  1883. case E_ERROR:
  1884. switch(ap->evt_ring[evtcsm].code) {
  1885. case E_C_ERR_INVAL_CMD:
  1886. printk(KERN_ERR "%s: invalid command errorn",
  1887.        dev->name);
  1888. break;
  1889. case E_C_ERR_UNIMP_CMD:
  1890. printk(KERN_ERR "%s: unimplemented command "
  1891.        "errorn", dev->name);
  1892. break;
  1893. case E_C_ERR_BAD_CFG:
  1894. printk(KERN_ERR "%s: bad config errorn",
  1895.        dev->name);
  1896. break;
  1897. default:
  1898. printk(KERN_ERR "%s: unknown error %02xn",
  1899.        dev->name, ap->evt_ring[evtcsm].code);
  1900. }
  1901. break;
  1902. case E_RESET_JUMBO_RNG:
  1903. {
  1904. int i;
  1905. for (i = 0; i < RX_JUMBO_RING_ENTRIES; i++) {
  1906. if (ap->skb->rx_jumbo_skbuff[i].skb) {
  1907. ap->rx_jumbo_ring[i].size = 0;
  1908. set_aceaddr(&ap->rx_jumbo_ring[i].addr, 0);
  1909. dev_kfree_skb(ap->skb->rx_jumbo_skbuff[i].skb);
  1910. ap->skb->rx_jumbo_skbuff[i].skb = NULL;
  1911. }
  1912. }
  1913.   if (ACE_IS_TIGON_I(ap)) {
  1914.   struct cmd cmd;
  1915.   cmd.evt = C_SET_RX_JUMBO_PRD_IDX;
  1916.   cmd.code = 0;
  1917.   cmd.idx = 0;
  1918.   ace_issue_cmd(ap->regs, &cmd);
  1919.   } else {
  1920.   writel(0, &((ap->regs)->RxJumboPrd));
  1921.   wmb();
  1922.   }
  1923. ap->jumbo = 0;
  1924. ap->rx_jumbo_skbprd = 0;
  1925. printk(KERN_INFO "%s: Jumbo ring flushedn",
  1926.        dev->name);
  1927. clear_bit(0, &ap->jumbo_refill_busy);
  1928. break;
  1929. }
  1930. default:
  1931. printk(KERN_ERR "%s: Unhandled event 0x%02xn",
  1932.        dev->name, ap->evt_ring[evtcsm].evt);
  1933. }
  1934. evtcsm = (evtcsm + 1) % EVT_RING_ENTRIES;
  1935. }
  1936. return evtcsm;
  1937. }
  1938. static void ace_rx_int(struct net_device *dev, u32 rxretprd, u32 rxretcsm)
  1939. {
  1940. struct ace_private *ap = dev->priv;
  1941. u32 idx;
  1942. int mini_count = 0, std_count = 0;
  1943. idx = rxretcsm;
  1944. prefetchw(&ap->cur_rx_bufs);
  1945. prefetchw(&ap->cur_mini_bufs);
  1946. while (idx != rxretprd) {
  1947. struct ring_info *rip;
  1948. struct sk_buff *skb;
  1949. struct rx_desc *rxdesc, *retdesc;
  1950. u32 skbidx;
  1951. int bd_flags, desc_type, mapsize;
  1952. u16 csum;
  1953. retdesc = &ap->rx_return_ring[idx];
  1954. skbidx = retdesc->idx;
  1955. bd_flags = retdesc->flags;
  1956. desc_type = bd_flags & (BD_FLG_JUMBO | BD_FLG_MINI);
  1957. switch(desc_type) {
  1958. /*
  1959.  * Normal frames do not have any flags set
  1960.  *
  1961.  * Mini and normal frames arrive frequently,
  1962.  * so use a local counter to avoid doing
  1963.  * atomic operations for each packet arriving.
  1964.  */
  1965. case 0:
  1966. rip = &ap->skb->rx_std_skbuff[skbidx];
  1967. mapsize = ACE_STD_BUFSIZE - (2 + 16);
  1968. rxdesc = &ap->rx_std_ring[skbidx];
  1969. std_count++;
  1970. break;
  1971. case BD_FLG_JUMBO:
  1972. rip = &ap->skb->rx_jumbo_skbuff[skbidx];
  1973. mapsize = ACE_JUMBO_BUFSIZE - (2 + 16);
  1974. rxdesc = &ap->rx_jumbo_ring[skbidx];
  1975. atomic_dec(&ap->cur_jumbo_bufs);
  1976. break;
  1977. case BD_FLG_MINI:
  1978. rip = &ap->skb->rx_mini_skbuff[skbidx];
  1979. mapsize = ACE_MINI_BUFSIZE - (2 + 16);
  1980. rxdesc = &ap->rx_mini_ring[skbidx];
  1981. mini_count++; 
  1982. break;
  1983. default:
  1984. printk(KERN_INFO "%s: unknown frame type (0x%02x) "
  1985.        "returned by NICn", dev->name,
  1986.        retdesc->flags);
  1987. goto error;
  1988. }
  1989. skb = rip->skb;
  1990. rip->skb = NULL;
  1991. pci_unmap_page(ap->pdev,
  1992.        pci_unmap_addr(rip, mapping),
  1993.        mapsize,
  1994.        PCI_DMA_FROMDEVICE);
  1995. skb_put(skb, retdesc->size);
  1996. /*
  1997.  * Fly baby, fly!
  1998.  */
  1999. csum = retdesc->tcp_udp_csum;
  2000. skb->dev = dev;
  2001. skb->protocol = eth_type_trans(skb, dev);
  2002. /*
  2003.  * Instead of forcing the poor tigon mips cpu to calculate
  2004.  * pseudo hdr checksum, we do this ourselves.
  2005.  */
  2006. if (bd_flags & BD_FLG_TCP_UDP_SUM) {
  2007. skb->csum = htons(csum);
  2008. skb->ip_summed = CHECKSUM_HW;
  2009. } else {
  2010. skb->ip_summed = CHECKSUM_NONE;
  2011. }
  2012. /* send it up */
  2013. #if ACENIC_DO_VLAN
  2014. if (ap->vlgrp && (bd_flags & BD_FLG_VLAN_TAG)) {
  2015. vlan_hwaccel_rx(skb, ap->vlgrp, retdesc->vlan);
  2016. } else
  2017. #endif
  2018. netif_rx(skb);
  2019. dev->last_rx = jiffies;
  2020. ap->stats.rx_packets++;
  2021. ap->stats.rx_bytes += retdesc->size;
  2022. idx = (idx + 1) % RX_RETURN_RING_ENTRIES;
  2023. }
  2024. atomic_sub(std_count, &ap->cur_rx_bufs);
  2025. if (!ACE_IS_TIGON_I(ap))
  2026. atomic_sub(mini_count, &ap->cur_mini_bufs);
  2027.  out:
  2028. /*
  2029.  * According to the documentation RxRetCsm is obsolete with
  2030.  * the 12.3.x Firmware - my Tigon I NICs seem to disagree!
  2031.  */
  2032. if (ACE_IS_TIGON_I(ap)) {
  2033. struct ace_regs *regs = ap->regs;
  2034. writel(idx, &regs->RxRetCsm);
  2035. }
  2036. ap->cur_rx = idx;
  2037. return;
  2038.  error:
  2039. idx = rxretprd;
  2040. goto out;
  2041. }
  2042. static inline void ace_tx_int(struct net_device *dev,
  2043.       u32 txcsm, u32 idx)
  2044. {
  2045. struct ace_private *ap = dev->priv;
  2046. do {
  2047. struct sk_buff *skb;
  2048. dma_addr_t mapping;
  2049. struct tx_ring_info *info;
  2050. info = ap->skb->tx_skbuff + idx;
  2051. skb = info->skb;
  2052. mapping = pci_unmap_addr(info, mapping);
  2053. if (mapping) {
  2054. pci_unmap_page(ap->pdev, mapping,
  2055.        pci_unmap_len(info, maplen),
  2056.        PCI_DMA_TODEVICE);
  2057. pci_unmap_addr_set(info, mapping, 0);
  2058. }
  2059. if (skb) {
  2060. ap->stats.tx_packets++;
  2061. ap->stats.tx_bytes += skb->len;
  2062. dev_kfree_skb_irq(skb);
  2063. info->skb = NULL;
  2064. }
  2065. idx = (idx + 1) % ACE_TX_RING_ENTRIES(ap);
  2066. } while (idx != txcsm);
  2067. if (netif_queue_stopped(dev))
  2068. netif_wake_queue(dev);
  2069. wmb();
  2070. ap->tx_ret_csm = txcsm;
  2071. /* So... tx_ret_csm is advanced _after_ check for device wakeup.
  2072.  *
  2073.  * We could try to make it before. In this case we would get
  2074.  * the following race condition: hard_start_xmit on other cpu
  2075.  * enters after we advanced tx_ret_csm and fills space,
  2076.  * which we have just freed, so that we make illegal device wakeup.
  2077.  * There is no good way to workaround this (at entry
  2078.  * to ace_start_xmit detects this condition and prevents
  2079.  * ring corruption, but it is not a good workaround.)
  2080.  *
  2081.  * When tx_ret_csm is advanced after, we wake up device _only_
  2082.  * if we really have some space in ring (though the core doing
  2083.  * hard_start_xmit can see full ring for some period and has to
  2084.  * synchronize.) Superb.
  2085.  * BUT! We get another subtle race condition. hard_start_xmit
  2086.  * may think that ring is full between wakeup and advancing
  2087.  * tx_ret_csm and will stop device instantly! It is not so bad.
  2088.  * We are guaranteed that there is something in ring, so that
  2089.  * the next irq will resume transmission. To speedup this we could
  2090.  * mark descriptor, which closes ring with BD_FLG_COAL_NOW
  2091.  * (see ace_start_xmit).
  2092.  *
  2093.  * Well, this dilemma exists in all lock-free devices.
  2094.  * We, following scheme used in drivers by Donald Becker,
  2095.  * select the least dangerous.
  2096.  * --ANK
  2097.  */
  2098. }
  2099. static void ace_interrupt(int irq, void *dev_id, struct pt_regs *ptregs)
  2100. {
  2101. struct ace_private *ap;
  2102. struct ace_regs *regs;
  2103. struct net_device *dev = (struct net_device *)dev_id;
  2104. u32 idx;
  2105. u32 txcsm, rxretcsm, rxretprd;
  2106. u32 evtcsm, evtprd;
  2107. ap = dev->priv;
  2108. regs = ap->regs;
  2109. /*
  2110.  * In case of PCI shared interrupts or spurious interrupts,
  2111.  * we want to make sure it is actually our interrupt before
  2112.  * spending any time in here.
  2113.  */
  2114. if (!(readl(&regs->HostCtrl) & IN_INT))
  2115. return;
  2116. /*
  2117.  * ACK intr now. Otherwise we will lose updates to rx_ret_prd,
  2118.  * which happened _after_ rxretprd = *ap->rx_ret_prd; but before
  2119.  * writel(0, &regs->Mb0Lo).
  2120.  *
  2121.  * "IRQ avoidance" recommended in docs applies to IRQs served
  2122.  * threads and it is wrong even for that case.
  2123.  */
  2124. writel(0, &regs->Mb0Lo);
  2125. readl(&regs->Mb0Lo);
  2126. /*
  2127.  * There is no conflict between transmit handling in
  2128.  * start_xmit and receive processing, thus there is no reason
  2129.  * to take a spin lock for RX handling. Wait until we start
  2130.  * working on the other stuff - hey we don't need a spin lock
  2131.  * anymore.
  2132.  */
  2133. rxretprd = *ap->rx_ret_prd;
  2134. rxretcsm = ap->cur_rx;
  2135. if (rxretprd != rxretcsm)
  2136. ace_rx_int(dev, rxretprd, rxretcsm);
  2137. txcsm = *ap->tx_csm;
  2138. idx = ap->tx_ret_csm;
  2139. if (txcsm != idx) {
  2140. /*
  2141.  * If each skb takes only one descriptor this check degenerates
  2142.  * to identity, because new space has just been opened.
  2143.  * But if skbs are fragmented we must check that this index
  2144.  * update releases enough of space, otherwise we just
  2145.  * wait for device to make more work.
  2146.  */
  2147. if (!tx_ring_full(ap, txcsm, ap->tx_prd))
  2148. ace_tx_int(dev, txcsm, idx);
  2149. }
  2150. evtcsm = readl(&regs->EvtCsm);
  2151. evtprd = *ap->evt_prd;
  2152. if (evtcsm != evtprd) {
  2153. evtcsm = ace_handle_event(dev, evtcsm, evtprd);
  2154. writel(evtcsm, &regs->EvtCsm);
  2155. }
  2156. /*
  2157.  * This has to go last in the interrupt handler and run with
  2158.  * the spin lock released ... what lock?
  2159.  */
  2160. if (netif_running(dev)) {
  2161. int cur_size;
  2162. int run_tasklet = 0;
  2163. cur_size = atomic_read(&ap->cur_rx_bufs);
  2164. if (cur_size < RX_LOW_STD_THRES) {
  2165. if ((cur_size < RX_PANIC_STD_THRES) &&
  2166.     !test_and_set_bit(0, &ap->std_refill_busy)) {
  2167. #if DEBUG
  2168. printk("low on std buffers %in", cur_size);
  2169. #endif
  2170. ace_load_std_rx_ring(ap,
  2171.      RX_RING_SIZE - cur_size);
  2172. } else
  2173. run_tasklet = 1;
  2174. }
  2175. if (!ACE_IS_TIGON_I(ap)) {
  2176. cur_size = atomic_read(&ap->cur_mini_bufs);
  2177. if (cur_size < RX_LOW_MINI_THRES) {
  2178. if ((cur_size < RX_PANIC_MINI_THRES) &&
  2179.     !test_and_set_bit(0,
  2180.       &ap->mini_refill_busy)) {
  2181. #if DEBUG
  2182. printk("low on mini buffers %in",
  2183.        cur_size);
  2184. #endif
  2185. ace_load_mini_rx_ring(ap, RX_MINI_SIZE - cur_size);
  2186. } else
  2187. run_tasklet = 1;
  2188. }
  2189. }
  2190. if (ap->jumbo) {
  2191. cur_size = atomic_read(&ap->cur_jumbo_bufs);
  2192. if (cur_size < RX_LOW_JUMBO_THRES) {
  2193. if ((cur_size < RX_PANIC_JUMBO_THRES) &&
  2194.     !test_and_set_bit(0,
  2195.       &ap->jumbo_refill_busy)){
  2196. #if DEBUG
  2197. printk("low on jumbo buffers %in",
  2198.        cur_size);
  2199. #endif
  2200. ace_load_jumbo_rx_ring(ap, RX_JUMBO_SIZE - cur_size);
  2201. } else
  2202. run_tasklet = 1;
  2203. }
  2204. }
  2205. if (run_tasklet && !ap->tasklet_pending) {
  2206. ap->tasklet_pending = 1;
  2207. tasklet_schedule(&ap->ace_tasklet);
  2208. }
  2209. }
  2210. }
  2211. #if ACENIC_DO_VLAN
  2212. static void ace_vlan_rx_register(struct net_device *dev, struct vlan_group *grp)
  2213. {
  2214. struct ace_private *ap = dev->priv;
  2215. unsigned long flags;
  2216. local_irq_save(flags);
  2217. ace_mask_irq(dev);
  2218. ap->vlgrp = grp;
  2219. ace_unmask_irq(dev);
  2220. local_irq_restore(flags);
  2221. }
  2222. static void ace_vlan_rx_kill_vid(struct net_device *dev, unsigned short vid)
  2223. {
  2224. struct ace_private *ap = dev->priv;
  2225. unsigned long flags;
  2226. local_irq_save(flags);
  2227. ace_mask_irq(dev);
  2228. if (ap->vlgrp)
  2229. ap->vlgrp->vlan_devices[vid] = NULL;
  2230. ace_unmask_irq(dev);
  2231. local_irq_restore(flags);
  2232. }
  2233. #endif /* ACENIC_DO_VLAN */
  2234. static int ace_open(struct net_device *dev)
  2235. {
  2236. struct ace_private *ap;
  2237. struct ace_regs *regs;
  2238. struct cmd cmd;
  2239. ap = dev->priv;
  2240. regs = ap->regs;
  2241. if (!(ap->fw_running)) {
  2242. printk(KERN_WARNING "%s: Firmware not running!n", dev->name);
  2243. return -EBUSY;
  2244. }
  2245. writel(dev->mtu + ETH_HLEN + 4, &regs->IfMtu);
  2246. cmd.evt = C_CLEAR_STATS;
  2247. cmd.code = 0;
  2248. cmd.idx = 0;
  2249. ace_issue_cmd(regs, &cmd);
  2250. cmd.evt = C_HOST_STATE;
  2251. cmd.code = C_C_STACK_UP;
  2252. cmd.idx = 0;
  2253. ace_issue_cmd(regs, &cmd);
  2254. if (ap->jumbo &&
  2255.     !test_and_set_bit(0, &ap->jumbo_refill_busy))
  2256. ace_load_jumbo_rx_ring(ap, RX_JUMBO_SIZE);
  2257. if (dev->flags & IFF_PROMISC) {
  2258. cmd.evt = C_SET_PROMISC_MODE;
  2259. cmd.code = C_C_PROMISC_ENABLE;
  2260. cmd.idx = 0;
  2261. ace_issue_cmd(regs, &cmd);
  2262. ap->promisc = 1;
  2263. }else
  2264. ap->promisc = 0;
  2265. ap->mcast_all = 0;
  2266. #if 0
  2267. cmd.evt = C_LNK_NEGOTIATION;
  2268. cmd.code = 0;
  2269. cmd.idx = 0;
  2270. ace_issue_cmd(regs, &cmd);
  2271. #endif
  2272. netif_start_queue(dev);
  2273. ACE_MOD_INC_USE_COUNT;
  2274. /*
  2275.  * Setup the bottom half rx ring refill handler
  2276.  */
  2277. tasklet_init(&ap->ace_tasklet, ace_tasklet, (unsigned long)dev);
  2278. return 0;
  2279. }
  2280. static int ace_close(struct net_device *dev)
  2281. {
  2282. struct ace_private *ap;
  2283. struct ace_regs *regs;
  2284. struct cmd cmd;
  2285. unsigned long flags;
  2286. short i;
  2287. ace_if_down(dev);
  2288. /*
  2289.  * Without (or before) releasing irq and stopping hardware, this
  2290.  * is an absolute non-sense, by the way. It will be reset instantly
  2291.  * by the first irq.
  2292.  */
  2293. netif_stop_queue(dev);
  2294. ap = dev->priv;
  2295. regs = ap->regs;
  2296. if (ap->promisc) {
  2297. cmd.evt = C_SET_PROMISC_MODE;
  2298. cmd.code = C_C_PROMISC_DISABLE;
  2299. cmd.idx = 0;
  2300. ace_issue_cmd(regs, &cmd);
  2301. ap->promisc = 0;
  2302. }
  2303. cmd.evt = C_HOST_STATE;
  2304. cmd.code = C_C_STACK_DOWN;
  2305. cmd.idx = 0;
  2306. ace_issue_cmd(regs, &cmd);
  2307. tasklet_kill(&ap->ace_tasklet);
  2308. /*
  2309.  * Make sure one CPU is not processing packets while
  2310.  * buffers are being released by another.
  2311.  */
  2312. local_irq_save(flags);
  2313. ace_mask_irq(dev);
  2314. for (i = 0; i < ACE_TX_RING_ENTRIES(ap); i++) {
  2315. struct sk_buff *skb;
  2316. dma_addr_t mapping;
  2317. struct tx_ring_info *info;
  2318. info = ap->skb->tx_skbuff + i;
  2319. skb = info->skb;
  2320. mapping = pci_unmap_addr(info, mapping);
  2321. if (mapping) {
  2322. if (ACE_IS_TIGON_I(ap)) {
  2323. writel(0, &ap->tx_ring[i].addr.addrhi);
  2324. writel(0, &ap->tx_ring[i].addr.addrlo);
  2325. writel(0, &ap->tx_ring[i].flagsize);
  2326. } else
  2327. memset(ap->tx_ring + i, 0,
  2328.        sizeof(struct tx_desc));
  2329. pci_unmap_page(ap->pdev, mapping,
  2330.        pci_unmap_len(info, maplen),
  2331.        PCI_DMA_TODEVICE);
  2332. pci_unmap_addr_set(info, mapping, 0);
  2333. }
  2334. if (skb) {
  2335. dev_kfree_skb(skb);
  2336. info->skb = NULL;
  2337. }
  2338. }
  2339. if (ap->jumbo) {
  2340. cmd.evt = C_RESET_JUMBO_RNG;
  2341. cmd.code = 0;
  2342. cmd.idx = 0;
  2343. ace_issue_cmd(regs, &cmd);
  2344. }
  2345. ace_unmask_irq(dev);
  2346. local_irq_restore(flags);
  2347. ACE_MOD_DEC_USE_COUNT;
  2348. return 0;
  2349. }
  2350. static inline dma_addr_t
  2351. ace_map_tx_skb(struct ace_private *ap, struct sk_buff *skb,
  2352.        struct sk_buff *tail, u32 idx)
  2353. {
  2354. dma_addr_t mapping;
  2355. struct tx_ring_info *info;
  2356. mapping = pci_map_page(ap->pdev, virt_to_page(skb->data),
  2357.        ((unsigned long) skb->data & ~PAGE_MASK),
  2358.        skb->len, PCI_DMA_TODEVICE);
  2359. info = ap->skb->tx_skbuff + idx;
  2360. info->skb = tail;
  2361. pci_unmap_addr_set(info, mapping, mapping);
  2362. pci_unmap_len_set(info, maplen, skb->len);
  2363. return mapping;
  2364. }
  2365. static inline void
  2366. ace_load_tx_bd(struct ace_private *ap, struct tx_desc *desc, u64 addr,
  2367.        u32 flagsize, u32 vlan_tag)
  2368. {
  2369. #if !USE_TX_COAL_NOW
  2370. flagsize &= ~BD_FLG_COAL_NOW;
  2371. #endif
  2372. if (ACE_IS_TIGON_I(ap)) {
  2373. writel(addr >> 32, &desc->addr.addrhi);
  2374. writel(addr & 0xffffffff, &desc->addr.addrlo);
  2375. writel(flagsize, &desc->flagsize);
  2376. #if ACENIC_DO_VLAN
  2377. writel(vlan_tag, &desc->vlanres);
  2378. #endif
  2379. } else {
  2380. desc->addr.addrhi = addr >> 32;
  2381. desc->addr.addrlo = addr;
  2382. desc->flagsize = flagsize;
  2383. #if ACENIC_DO_VLAN
  2384. desc->vlanres = vlan_tag;
  2385. #endif
  2386. }
  2387. }
  2388. static int ace_start_xmit(struct sk_buff *skb, struct net_device *dev)
  2389. {
  2390. struct ace_private *ap = dev->priv;
  2391. struct ace_regs *regs = ap->regs;
  2392. struct tx_desc *desc;
  2393. u32 idx, flagsize;
  2394.   /*
  2395.  * This only happens with pre-softnet, ie. 2.2.x kernels.
  2396.    */
  2397. if (early_stop_netif_stop_queue(dev))
  2398.   return 1;
  2399. restart:
  2400. idx = ap->tx_prd;
  2401. if (tx_ring_full(ap, ap->tx_ret_csm, idx))
  2402. goto overflow;
  2403. #if MAX_SKB_FRAGS
  2404. if (!skb_shinfo(skb)->nr_frags)
  2405. #endif
  2406. {
  2407. dma_addr_t mapping;
  2408. u32 vlan_tag = 0;
  2409. mapping = ace_map_tx_skb(ap, skb, skb, idx);
  2410. flagsize = (skb->len << 16) | (BD_FLG_END);
  2411. if (skb->ip_summed == CHECKSUM_HW)
  2412. flagsize |= BD_FLG_TCP_UDP_SUM;
  2413. #if ACENIC_DO_VLAN
  2414. if (vlan_tx_tag_present(skb)) {
  2415. flagsize |= BD_FLG_VLAN_TAG;
  2416. vlan_tag = vlan_tx_tag_get(skb);
  2417. }
  2418. #endif
  2419. desc = ap->tx_ring + idx;
  2420. idx = (idx + 1) % ACE_TX_RING_ENTRIES(ap);
  2421. /* Look at ace_tx_int for explanations. */
  2422. if (tx_ring_full(ap, ap->tx_ret_csm, idx))
  2423. flagsize |= BD_FLG_COAL_NOW;
  2424. ace_load_tx_bd(ap, desc, mapping, flagsize, vlan_tag);
  2425. }
  2426. #if MAX_SKB_FRAGS
  2427. else {
  2428. dma_addr_t mapping;
  2429. u32 vlan_tag = 0;
  2430. int i, len = 0;
  2431. mapping = ace_map_tx_skb(ap, skb, NULL, idx);
  2432. flagsize = ((skb->len - skb->data_len) << 16);
  2433. if (skb->ip_summed == CHECKSUM_HW)
  2434. flagsize |= BD_FLG_TCP_UDP_SUM;
  2435. #if ACENIC_DO_VLAN
  2436. if (vlan_tx_tag_present(skb)) {
  2437. flagsize |= BD_FLG_VLAN_TAG;
  2438. vlan_tag = vlan_tx_tag_get(skb);
  2439. }
  2440. #endif
  2441. ace_load_tx_bd(ap, ap->tx_ring + idx, mapping, flagsize, vlan_tag);
  2442. idx = (idx + 1) % ACE_TX_RING_ENTRIES(ap);
  2443. for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) {
  2444. skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
  2445. struct tx_ring_info *info;
  2446. len += frag->size;
  2447. info = ap->skb->tx_skbuff + idx;
  2448. desc = ap->tx_ring + idx;
  2449. mapping = pci_map_page(ap->pdev, frag->page,
  2450.        frag->page_offset, frag->size,
  2451.        PCI_DMA_TODEVICE);
  2452. flagsize = (frag->size << 16);
  2453. if (skb->ip_summed == CHECKSUM_HW)
  2454. flagsize |= BD_FLG_TCP_UDP_SUM;
  2455. idx = (idx + 1) % ACE_TX_RING_ENTRIES(ap);
  2456. if (i == skb_shinfo(skb)->nr_frags - 1) {
  2457. flagsize |= BD_FLG_END;
  2458. if (tx_ring_full(ap, ap->tx_ret_csm, idx))
  2459. flagsize |= BD_FLG_COAL_NOW;
  2460. /*
  2461.  * Only the last fragment frees
  2462.  * the skb!
  2463.  */
  2464. info->skb = skb;
  2465. } else {
  2466. info->skb = NULL;
  2467. }
  2468. pci_unmap_addr_set(info, mapping, mapping);
  2469. pci_unmap_len_set(info, maplen, frag->size);
  2470. ace_load_tx_bd(ap, desc, mapping, flagsize, vlan_tag);
  2471. }
  2472. }
  2473. #endif
  2474.   wmb();
  2475.   ap->tx_prd = idx;
  2476.   ace_set_txprd(regs, ap, idx);
  2477. if (flagsize & BD_FLG_COAL_NOW) {
  2478. netif_stop_queue(dev);
  2479. /*
  2480.  * A TX-descriptor producer (an IRQ) might have gotten
  2481.  * inbetween, making the ring free again. Since xmit is
  2482.  * serialized, this is the only situation we have to
  2483.  * re-test.
  2484.  */
  2485. if (!tx_ring_full(ap, ap->tx_ret_csm, idx))
  2486. netif_wake_queue(dev);
  2487. }
  2488. dev->trans_start = jiffies;
  2489. return 0;
  2490. overflow:
  2491. /*
  2492.  * This race condition is unavoidable with lock-free drivers.
  2493.  * We wake up the queue _before_ tx_prd is advanced, so that we can
  2494.  * enter hard_start_xmit too early, while tx ring still looks closed.
  2495.  * This happens ~1-4 times per 100000 packets, so that we can allow
  2496.  * to loop syncing to other CPU. Probably, we need an additional
  2497.  * wmb() in ace_tx_intr as well.
  2498.  *
  2499.  * Note that this race is relieved by reserving one more entry
  2500.  * in tx ring than it is necessary (see original non-SG driver).
  2501.  * However, with SG we need to reserve 2*MAX_SKB_FRAGS+1, which
  2502.  * is already overkill.
  2503.  *
  2504.  * Alternative is to return with 1 not throttling queue. In this
  2505.  * case loop becomes longer, no more useful effects.
  2506.  */
  2507. barrier();
  2508. goto restart;
  2509. }
  2510. static int ace_change_mtu(struct net_device *dev, int new_mtu)
  2511. {
  2512. struct ace_private *ap = dev->priv;
  2513. struct ace_regs *regs = ap->regs;
  2514. if (new_mtu > ACE_JUMBO_MTU)
  2515. return -EINVAL;
  2516. writel(new_mtu + ETH_HLEN + 4, &regs->IfMtu);
  2517. dev->mtu = new_mtu;
  2518. if (new_mtu > ACE_STD_MTU) {
  2519. if (!(ap->jumbo)) {
  2520. printk(KERN_INFO "%s: Enabling Jumbo frame "
  2521.        "supportn", dev->name);
  2522. ap->jumbo = 1;
  2523. if (!test_and_set_bit(0, &ap->jumbo_refill_busy))
  2524. ace_load_jumbo_rx_ring(ap, RX_JUMBO_SIZE);
  2525. ace_set_rxtx_parms(dev, 1);
  2526. }
  2527. } else {
  2528. while (test_and_set_bit(0, &ap->jumbo_refill_busy));
  2529. ace_sync_irq(dev->irq);
  2530. ace_set_rxtx_parms(dev, 0);
  2531. if (ap->jumbo) {
  2532. struct cmd cmd;
  2533. cmd.evt = C_RESET_JUMBO_RNG;
  2534. cmd.code = 0;
  2535. cmd.idx = 0;
  2536. ace_issue_cmd(regs, &cmd);
  2537. }
  2538. }
  2539. return 0;
  2540. }
  2541. static int ace_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
  2542. {
  2543. struct ace_private *ap = dev->priv;
  2544. struct ace_regs *regs = ap->regs;
  2545. #ifdef SIOCETHTOOL
  2546. struct ethtool_cmd ecmd;
  2547. u32 link, speed;
  2548. if (cmd != SIOCETHTOOL)
  2549. return -EOPNOTSUPP;
  2550. if (copy_from_user(&ecmd, ifr->ifr_data, sizeof(ecmd)))
  2551. return -EFAULT;
  2552. switch (ecmd.cmd) {
  2553. case ETHTOOL_GSET:
  2554. ecmd.supported =
  2555. (SUPPORTED_10baseT_Half | SUPPORTED_10baseT_Full |
  2556.  SUPPORTED_100baseT_Half | SUPPORTED_100baseT_Full |
  2557.  SUPPORTED_1000baseT_Half | SUPPORTED_1000baseT_Full |
  2558.  SUPPORTED_Autoneg | SUPPORTED_FIBRE);
  2559. ecmd.port = PORT_FIBRE;
  2560. ecmd.transceiver = XCVR_INTERNAL;
  2561. ecmd.phy_address = 0;
  2562. link = readl(&regs->GigLnkState);
  2563. if (link & LNK_1000MB)
  2564. ecmd.speed = SPEED_1000;
  2565. else {
  2566. link = readl(&regs->FastLnkState);
  2567. if (link & LNK_100MB)
  2568. ecmd.speed = SPEED_100;
  2569. else if (link & LNK_100MB)
  2570. ecmd.speed = SPEED_10;
  2571. else
  2572. ecmd.speed = 0;
  2573. }
  2574. if (link & LNK_FULL_DUPLEX)
  2575. ecmd.duplex = DUPLEX_FULL;
  2576. else
  2577. ecmd.duplex = DUPLEX_HALF;
  2578. if (link & LNK_NEGOTIATE)
  2579. ecmd.autoneg = AUTONEG_ENABLE;
  2580. else
  2581. ecmd.autoneg = AUTONEG_DISABLE;
  2582. #if 0
  2583. /*
  2584.  * Current struct ethtool_cmd is insufficient
  2585.  */
  2586. ecmd.trace = readl(&regs->TuneTrace);
  2587. ecmd.txcoal = readl(&regs->TuneTxCoalTicks);
  2588. ecmd.rxcoal = readl(&regs->TuneRxCoalTicks);
  2589. #endif
  2590. ecmd.maxtxpkt = readl(&regs->TuneMaxTxDesc);
  2591. ecmd.maxrxpkt = readl(&regs->TuneMaxRxDesc);
  2592. if(copy_to_user(ifr->ifr_data, &ecmd, sizeof(ecmd)))
  2593. return -EFAULT;
  2594. return 0;
  2595. case ETHTOOL_SSET:
  2596. if(!capable(CAP_NET_ADMIN))
  2597. return -EPERM;
  2598. link = readl(&regs->GigLnkState);
  2599. if (link & LNK_1000MB)
  2600. speed = SPEED_1000;
  2601. else {
  2602. link = readl(&regs->FastLnkState);
  2603. if (link & LNK_100MB)
  2604. speed = SPEED_100;
  2605. else if (link & LNK_100MB)
  2606. speed = SPEED_10;
  2607. else
  2608. speed = SPEED_100;
  2609. }
  2610. link = LNK_ENABLE | LNK_1000MB | LNK_100MB | LNK_10MB |
  2611. LNK_RX_FLOW_CTL_Y | LNK_NEG_FCTL;
  2612. if (!ACE_IS_TIGON_I(ap))
  2613. link |= LNK_TX_FLOW_CTL_Y;
  2614. if (ecmd.autoneg == AUTONEG_ENABLE)
  2615. link |= LNK_NEGOTIATE;
  2616. if (ecmd.speed != speed) {
  2617. link &= ~(LNK_1000MB | LNK_100MB | LNK_10MB);
  2618. switch (speed) {
  2619. case SPEED_1000:
  2620. link |= LNK_1000MB;
  2621. break;
  2622. case SPEED_100:
  2623. link |= LNK_100MB;
  2624. break;
  2625. case SPEED_10:
  2626. link |= LNK_10MB;
  2627. break;
  2628. }
  2629. }
  2630. if (ecmd.duplex == DUPLEX_FULL)
  2631. link |= LNK_FULL_DUPLEX;
  2632. if (link != ap->link) {
  2633. struct cmd cmd;
  2634. printk(KERN_INFO "%s: Renegotiating link staten",
  2635.        dev->name);
  2636. ap->link = link;
  2637. writel(link, &regs->TuneLink);
  2638. if (!ACE_IS_TIGON_I(ap))
  2639. writel(link, &regs->TuneFastLink);
  2640. wmb();
  2641. cmd.evt = C_LNK_NEGOTIATION;
  2642. cmd.code = 0;
  2643. cmd.idx = 0;
  2644. ace_issue_cmd(regs, &cmd);
  2645. }
  2646. return 0;
  2647. case ETHTOOL_GDRVINFO: {
  2648. struct ethtool_drvinfo info = {ETHTOOL_GDRVINFO};
  2649. strncpy(info.driver, "acenic", sizeof(info.driver) - 1);
  2650. sprintf(info.fw_version, "%i.%i.%i", 
  2651.  tigonFwReleaseMajor, tigonFwReleaseMinor,
  2652.  tigonFwReleaseFix);
  2653. strncpy(info.version, version, sizeof(info.version) - 1);
  2654. if (ap && ap->pdev)
  2655. strcpy(info.bus_info, ap->pdev->slot_name);
  2656. if (copy_to_user(ifr->ifr_data, &info, sizeof(info)))
  2657. return -EFAULT;
  2658. return 0;
  2659. }
  2660. default:
  2661. break;
  2662. }
  2663. #endif
  2664. return -EOPNOTSUPP;
  2665. }
  2666. /*
  2667.  * Set the hardware MAC address.
  2668.  */
  2669. static int ace_set_mac_addr(struct net_device *dev, void *p)
  2670. {
  2671. struct sockaddr *addr=p;
  2672. struct ace_regs *regs;
  2673. u8 *da;
  2674. struct cmd cmd;
  2675. if(netif_running(dev))
  2676. return -EBUSY;
  2677. memcpy(dev->dev_addr, addr->sa_data,dev->addr_len);
  2678. da = (u8 *)dev->dev_addr;
  2679. regs = ((struct ace_private *)dev->priv)->regs;
  2680. writel(da[0] << 8 | da[1], &regs->MacAddrHi);
  2681. writel((da[2] << 24) | (da[3] << 16) | (da[4] << 8) | da[5],
  2682.        &regs->MacAddrLo);
  2683. cmd.evt = C_SET_MAC_ADDR;
  2684. cmd.code = 0;
  2685. cmd.idx = 0;
  2686. ace_issue_cmd(regs, &cmd);
  2687. return 0;
  2688. }
  2689. static void ace_set_multicast_list(struct net_device *dev)
  2690. {
  2691. struct ace_private *ap = dev->priv;
  2692. struct ace_regs *regs = ap->regs;
  2693. struct cmd cmd;
  2694. if ((dev->flags & IFF_ALLMULTI) && !(ap->mcast_all)) {
  2695. cmd.evt = C_SET_MULTICAST_MODE;
  2696. cmd.code = C_C_MCAST_ENABLE;
  2697. cmd.idx = 0;
  2698. ace_issue_cmd(regs, &cmd);
  2699. ap->mcast_all = 1;
  2700. } else if (ap->mcast_all) {
  2701. cmd.evt = C_SET_MULTICAST_MODE;
  2702. cmd.code = C_C_MCAST_DISABLE;
  2703. cmd.idx = 0;
  2704. ace_issue_cmd(regs, &cmd);
  2705. ap->mcast_all = 0;
  2706. }
  2707. if ((dev->flags & IFF_PROMISC) && !(ap->promisc)) {
  2708. cmd.evt = C_SET_PROMISC_MODE;
  2709. cmd.code = C_C_PROMISC_ENABLE;
  2710. cmd.idx = 0;
  2711. ace_issue_cmd(regs, &cmd);
  2712. ap->promisc = 1;
  2713. }else if (!(dev->flags & IFF_PROMISC) && (ap->promisc)) {
  2714. cmd.evt = C_SET_PROMISC_MODE;
  2715. cmd.code = C_C_PROMISC_DISABLE;
  2716. cmd.idx = 0;
  2717. ace_issue_cmd(regs, &cmd);
  2718. ap->promisc = 0;
  2719. }
  2720. /*
  2721.  * For the time being multicast relies on the upper layers
  2722.  * filtering it properly. The Firmware does not allow one to
  2723.  * set the entire multicast list at a time and keeping track of
  2724.  * it here is going to be messy.
  2725.  */
  2726. if ((dev->mc_count) && !(ap->mcast_all)) {
  2727. cmd.evt = C_SET_MULTICAST_MODE;
  2728. cmd.code = C_C_MCAST_ENABLE;
  2729. cmd.idx = 0;
  2730. ace_issue_cmd(regs, &cmd);
  2731. }else if (!ap->mcast_all) {
  2732. cmd.evt = C_SET_MULTICAST_MODE;
  2733. cmd.code = C_C_MCAST_DISABLE;
  2734. cmd.idx = 0;
  2735. ace_issue_cmd(regs, &cmd);
  2736. }
  2737. }
  2738. static struct net_device_stats *ace_get_stats(struct net_device *dev)
  2739. {
  2740. struct ace_private *ap = dev->priv;
  2741. struct ace_mac_stats *mac_stats =
  2742. (struct ace_mac_stats *)ap->regs->Stats;
  2743. ap->stats.rx_missed_errors = readl(&mac_stats->drop_space);
  2744. ap->stats.multicast = readl(&mac_stats->kept_mc);
  2745. ap->stats.collisions = readl(&mac_stats->coll);
  2746. return &ap->stats;
  2747. }
  2748. static void __init ace_copy(struct ace_regs *regs, void *src,
  2749.     u32 dest, int size)
  2750. {
  2751. unsigned long tdest;
  2752. u32 *wsrc;
  2753. short tsize, i;
  2754. if (size <= 0)
  2755. return;
  2756. while (size > 0) {
  2757. tsize = min_t(u32, ((~dest & (ACE_WINDOW_SIZE - 1)) + 1),
  2758.     min_t(u32, size, ACE_WINDOW_SIZE));
  2759. tdest = (unsigned long)&regs->Window +
  2760. (dest & (ACE_WINDOW_SIZE - 1));
  2761. writel(dest & ~(ACE_WINDOW_SIZE - 1), &regs->WinBase);
  2762. /*
  2763.  * This requires byte swapping on big endian, however
  2764.  * writel does that for us
  2765.  */
  2766. wsrc = src;
  2767. for (i = 0; i < (tsize / 4); i++) {
  2768. writel(wsrc[i], tdest + i*4);
  2769. }
  2770. dest += tsize;
  2771. src += tsize;
  2772. size -= tsize;
  2773. }
  2774. return;
  2775. }
  2776. static void __init ace_clear(struct ace_regs *regs, u32 dest, int size)
  2777. {
  2778. unsigned long tdest;
  2779. short tsize = 0, i;
  2780. if (size <= 0)
  2781. return;
  2782. while (size > 0) {
  2783. tsize = min_t(u32, ((~dest & (ACE_WINDOW_SIZE - 1)) + 1),
  2784. min_t(u32, size, ACE_WINDOW_SIZE));
  2785. tdest = (unsigned long)&regs->Window +
  2786. (dest & (ACE_WINDOW_SIZE - 1));
  2787. writel(dest & ~(ACE_WINDOW_SIZE - 1), &regs->WinBase);
  2788. for (i = 0; i < (tsize / 4); i++) {
  2789. writel(0, tdest + i*4);
  2790. }
  2791. dest += tsize;
  2792. size -= tsize;
  2793. }
  2794. return;
  2795. }
  2796. /*
  2797.  * Download the firmware into the SRAM on the NIC
  2798.  *
  2799.  * This operation requires the NIC to be halted and is performed with
  2800.  * interrupts disabled and with the spinlock hold.
  2801.  */
  2802. int __init ace_load_firmware(struct net_device *dev)
  2803. {
  2804. struct ace_private *ap;
  2805. struct ace_regs *regs;
  2806. ap = dev->priv;
  2807. regs = ap->regs;
  2808. if (!(readl(&regs->CpuCtrl) & CPU_HALTED)) {
  2809. printk(KERN_ERR "%s: trying to download firmware while the "
  2810.        "CPU is running!n", dev->name);
  2811. return -EFAULT;
  2812. }
  2813. /*
  2814.  * Do not try to clear more than 512KB or we end up seeing
  2815.  * funny things on NICs with only 512KB SRAM
  2816.  */
  2817. ace_clear(regs, 0x2000, 0x80000-0x2000);
  2818. if (ACE_IS_TIGON_I(ap)) {
  2819. ace_copy(regs, tigonFwText, tigonFwTextAddr, tigonFwTextLen);
  2820. ace_copy(regs, tigonFwData, tigonFwDataAddr, tigonFwDataLen);
  2821. ace_copy(regs, tigonFwRodata, tigonFwRodataAddr,
  2822.  tigonFwRodataLen);
  2823. ace_clear(regs, tigonFwBssAddr, tigonFwBssLen);
  2824. ace_clear(regs, tigonFwSbssAddr, tigonFwSbssLen);
  2825. }else if (ap->version == 2) {
  2826. ace_clear(regs, tigon2FwBssAddr, tigon2FwBssLen);
  2827. ace_clear(regs, tigon2FwSbssAddr, tigon2FwSbssLen);
  2828. ace_copy(regs, tigon2FwText, tigon2FwTextAddr,tigon2FwTextLen);
  2829. ace_copy(regs, tigon2FwRodata, tigon2FwRodataAddr,
  2830.  tigon2FwRodataLen);
  2831. ace_copy(regs, tigon2FwData, tigon2FwDataAddr,tigon2FwDataLen);
  2832. }
  2833. return 0;
  2834. }
  2835. /*
  2836.  * The eeprom on the AceNIC is an Atmel i2c EEPROM.
  2837.  *
  2838.  * Accessing the EEPROM is `interesting' to say the least - don't read
  2839.  * this code right after dinner.
  2840.  *
  2841.  * This is all about black magic and bit-banging the device .... I
  2842.  * wonder in what hospital they have put the guy who designed the i2c
  2843.  * specs.
  2844.  *
  2845.  * Oh yes, this is only the beginning!
  2846.  *
  2847.  * Thanks to Stevarino Webinski for helping tracking down the bugs in the
  2848.  * code i2c readout code by beta testing all my hacks.
  2849.  */
  2850. static void __init eeprom_start(struct ace_regs *regs)
  2851. {
  2852. u32 local;
  2853. readl(&regs->LocalCtrl);
  2854. udelay(ACE_SHORT_DELAY);
  2855. local = readl(&regs->LocalCtrl);
  2856. local |= EEPROM_DATA_OUT | EEPROM_WRITE_ENABLE;
  2857. writel(local, &regs->LocalCtrl);
  2858. readl(&regs->LocalCtrl);
  2859. mb();
  2860. udelay(ACE_SHORT_DELAY);
  2861. local |= EEPROM_CLK_OUT;
  2862. writel(local, &regs->LocalCtrl);
  2863. readl(&regs->LocalCtrl);
  2864. mb();
  2865. udelay(ACE_SHORT_DELAY);
  2866. local &= ~EEPROM_DATA_OUT;
  2867. writel(local, &regs->LocalCtrl);
  2868. readl(&regs->LocalCtrl);
  2869. mb();
  2870. udelay(ACE_SHORT_DELAY);
  2871. local &= ~EEPROM_CLK_OUT;
  2872. writel(local, &regs->LocalCtrl);
  2873. readl(&regs->LocalCtrl);
  2874. mb();
  2875. }
  2876. static void __init eeprom_prep(struct ace_regs *regs, u8 magic)
  2877. {
  2878. short i;
  2879. u32 local;
  2880. udelay(ACE_SHORT_DELAY);
  2881. local = readl(&regs->LocalCtrl);
  2882. local &= ~EEPROM_DATA_OUT;
  2883. local |= EEPROM_WRITE_ENABLE;
  2884. writel(local, &regs->LocalCtrl);
  2885. readl(&regs->LocalCtrl);
  2886. mb();
  2887. for (i = 0; i < 8; i++, magic <<= 1) {
  2888. udelay(ACE_SHORT_DELAY);
  2889. if (magic & 0x80) 
  2890. local |= EEPROM_DATA_OUT;
  2891. else
  2892. local &= ~EEPROM_DATA_OUT;
  2893. writel(local, &regs->LocalCtrl);
  2894. readl(&regs->LocalCtrl);
  2895. mb();
  2896. udelay(ACE_SHORT_DELAY);
  2897. local |= EEPROM_CLK_OUT;
  2898. writel(local, &regs->LocalCtrl);
  2899. readl(&regs->LocalCtrl);
  2900. mb();
  2901. udelay(ACE_SHORT_DELAY);
  2902. local &= ~(EEPROM_CLK_OUT | EEPROM_DATA_OUT);
  2903. writel(local, &regs->LocalCtrl);
  2904. readl(&regs->LocalCtrl);
  2905. mb();
  2906. }
  2907. }
  2908. static int __init eeprom_check_ack(struct ace_regs *regs)
  2909. {
  2910. int state;
  2911. u32 local;
  2912. local = readl(&regs->LocalCtrl);
  2913. local &= ~EEPROM_WRITE_ENABLE;
  2914. writel(local, &regs->LocalCtrl);
  2915. readl(&regs->LocalCtrl);
  2916. mb();
  2917. udelay(ACE_LONG_DELAY);
  2918. local |= EEPROM_CLK_OUT;
  2919. writel(local, &regs->LocalCtrl);
  2920. readl(&regs->LocalCtrl);
  2921. mb();
  2922. udelay(ACE_SHORT_DELAY);
  2923. /* sample data in middle of high clk */
  2924. state = (readl(&regs->LocalCtrl) & EEPROM_DATA_IN) != 0;
  2925. udelay(ACE_SHORT_DELAY);
  2926. mb();
  2927. writel(readl(&regs->LocalCtrl) & ~EEPROM_CLK_OUT, &regs->LocalCtrl);
  2928. readl(&regs->LocalCtrl);
  2929. mb();
  2930. return state;
  2931. }
  2932. static void __init eeprom_stop(struct ace_regs *regs)
  2933. {
  2934. u32 local;
  2935. udelay(ACE_SHORT_DELAY);
  2936. local = readl(&regs->LocalCtrl);
  2937. local |= EEPROM_WRITE_ENABLE;
  2938. writel(local, &regs->LocalCtrl);
  2939. readl(&regs->LocalCtrl);
  2940. mb();
  2941. udelay(ACE_SHORT_DELAY);
  2942. local &= ~EEPROM_DATA_OUT;
  2943. writel(local, &regs->LocalCtrl);
  2944. readl(&regs->LocalCtrl);
  2945. mb();
  2946. udelay(ACE_SHORT_DELAY);
  2947. local |= EEPROM_CLK_OUT;
  2948. writel(local, &regs->LocalCtrl);
  2949. readl(&regs->LocalCtrl);
  2950. mb();
  2951. udelay(ACE_SHORT_DELAY);
  2952. local |= EEPROM_DATA_OUT;
  2953. writel(local, &regs->LocalCtrl);
  2954. readl(&regs->LocalCtrl);
  2955. mb();
  2956. udelay(ACE_LONG_DELAY);
  2957. local &= ~EEPROM_CLK_OUT;
  2958. writel(local, &regs->LocalCtrl);
  2959. mb();
  2960. }
  2961. /*
  2962.  * Read a whole byte from the EEPROM.
  2963.  */
  2964. static int __init read_eeprom_byte(struct net_device *dev,
  2965.    unsigned long offset)
  2966. {
  2967. struct ace_regs *regs;
  2968. unsigned long flags;
  2969. u32 local;
  2970. int result = 0;
  2971. short i;
  2972. if (!dev) {
  2973. printk(KERN_ERR "No device!n");
  2974. result = -ENODEV;
  2975. goto eeprom_read_error;
  2976. }
  2977. regs = ((struct ace_private *)dev->priv)->regs;
  2978. /*
  2979.  * Don't take interrupts on this CPU will bit banging
  2980.  * the %#%#@$ I2C device
  2981.  */
  2982. local_irq_save(flags);
  2983. eeprom_start(regs);
  2984. eeprom_prep(regs, EEPROM_WRITE_SELECT);
  2985. if (eeprom_check_ack(regs)) {
  2986. local_irq_restore(flags);
  2987. printk(KERN_ERR "%s: Unable to sync eepromn", dev->name);
  2988. result = -EIO;
  2989. goto eeprom_read_error;
  2990. }
  2991. eeprom_prep(regs, (offset >> 8) & 0xff);
  2992. if (eeprom_check_ack(regs)) {
  2993. local_irq_restore(flags);
  2994. printk(KERN_ERR "%s: Unable to set address byte 0n",
  2995.        dev->name);
  2996. result = -EIO;
  2997. goto eeprom_read_error;
  2998. }
  2999. eeprom_prep(regs, offset & 0xff);
  3000. if (eeprom_check_ack(regs)) {
  3001. local_irq_restore(flags);
  3002. printk(KERN_ERR "%s: Unable to set address byte 1n",
  3003.        dev->name);
  3004. result = -EIO;
  3005. goto eeprom_read_error;
  3006. }
  3007. eeprom_start(regs);
  3008. eeprom_prep(regs, EEPROM_READ_SELECT);
  3009. if (eeprom_check_ack(regs)) {
  3010. local_irq_restore(flags);
  3011. printk(KERN_ERR "%s: Unable to set READ_SELECTn",
  3012.        dev->name);
  3013. result = -EIO;
  3014. goto eeprom_read_error;
  3015. }
  3016. for (i = 0; i < 8; i++) {
  3017. local = readl(&regs->LocalCtrl);
  3018. local &= ~EEPROM_WRITE_ENABLE;
  3019. writel(local, &regs->LocalCtrl);
  3020. readl(&regs->LocalCtrl);
  3021. udelay(ACE_LONG_DELAY);
  3022. mb();
  3023. local |= EEPROM_CLK_OUT;
  3024. writel(local, &regs->LocalCtrl);
  3025. readl(&regs->LocalCtrl);
  3026. mb();
  3027. udelay(ACE_SHORT_DELAY);
  3028. /* sample data mid high clk */
  3029. result = (result << 1) |
  3030. ((readl(&regs->LocalCtrl) & EEPROM_DATA_IN) != 0);
  3031. udelay(ACE_SHORT_DELAY);
  3032. mb();
  3033. local = readl(&regs->LocalCtrl);
  3034. local &= ~EEPROM_CLK_OUT;
  3035. writel(local, &regs->LocalCtrl);
  3036. readl(&regs->LocalCtrl);
  3037. udelay(ACE_SHORT_DELAY);
  3038. mb();
  3039. if (i == 7) {
  3040. local |= EEPROM_WRITE_ENABLE;
  3041. writel(local, &regs->LocalCtrl);
  3042. readl(&regs->LocalCtrl);
  3043. mb();
  3044. udelay(ACE_SHORT_DELAY);
  3045. }
  3046. }
  3047. local |= EEPROM_DATA_OUT;
  3048. writel(local, &regs->LocalCtrl);
  3049. readl(&regs->LocalCtrl);
  3050. mb();
  3051. udelay(ACE_SHORT_DELAY);
  3052. writel(readl(&regs->LocalCtrl) | EEPROM_CLK_OUT, &regs->LocalCtrl);
  3053. readl(&regs->LocalCtrl);
  3054. udelay(ACE_LONG_DELAY);
  3055. writel(readl(&regs->LocalCtrl) & ~EEPROM_CLK_OUT, &regs->LocalCtrl);
  3056. readl(&regs->LocalCtrl);
  3057. mb();
  3058. udelay(ACE_SHORT_DELAY);
  3059. eeprom_stop(regs);
  3060. local_irq_restore(flags);
  3061.  out:
  3062. return result;
  3063.  eeprom_read_error:
  3064. printk(KERN_ERR "%s: Unable to read eeprom byte 0x%02lxn",
  3065.        dev->name, offset);
  3066. goto out;
  3067. }
  3068. /*
  3069.  * Local variables:
  3070.  * 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"
  3071.  * End:
  3072.  */