1 /**************************************************************************
3 * Copyright 2000-2006 Alacritech, Inc. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above
12 * copyright notice, this list of conditions and the following
13 * disclaimer in the documentation and/or other materials provided
14 * with the distribution.
16 * Alternatively, this software may be distributed under the terms of the
17 * GNU General Public License ("GPL") version 2 as published by the Free
18 * Software Foundation.
20 * THIS SOFTWARE IS PROVIDED BY ALACRITECH, INC. ``AS IS'' AND ANY
21 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ALACRITECH, INC. OR
24 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
27 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
28 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
30 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 * The views and conclusions contained in the software and documentation
34 * are those of the authors and should not be interpreted as representing
35 * official policies, either expressed or implied, of Alacritech, Inc.
37 **************************************************************************/
42 * The SLICOSS driver for Alacritech's IS-NIC products.
44 * This driver is supposed to support:
46 * Mojave cards (single port PCI Gigabit) both copper and fiber
47 * Oasis cards (single and dual port PCI-x Gigabit) copper and fiber
48 * Kalahari cards (dual and quad port PCI-e Gigabit) copper and fiber
50 * The driver was actually tested on Oasis and Kalahari cards.
53 * NOTE: This is the standard, non-accelerated version of Alacritech's
58 #define KLUDGE_FOR_4GB_BOUNDARY 1
59 #define DEBUG_MICROCODE 1
61 #define SLIC_INTERRUPT_PROCESS_LIMIT 1
62 #define SLIC_OFFLOAD_IP_CHECKSUM 1
63 #define STATS_TIMER_INTERVAL 2
64 #define PING_TIMER_INTERVAL 1
65 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
67 #include <linux/kernel.h>
68 #include <linux/string.h>
69 #include <linux/errno.h>
70 #include <linux/ioport.h>
71 #include <linux/slab.h>
72 #include <linux/interrupt.h>
73 #include <linux/timer.h>
74 #include <linux/pci.h>
75 #include <linux/spinlock.h>
76 #include <linux/init.h>
77 #include <linux/bitops.h>
79 #include <linux/netdevice.h>
80 #include <linux/crc32.h>
81 #include <linux/etherdevice.h>
82 #include <linux/skbuff.h>
83 #include <linux/delay.h>
84 #include <linux/debugfs.h>
85 #include <linux/seq_file.h>
86 #include <linux/kthread.h>
87 #include <linux/module.h>
88 #include <linux/moduleparam.h>
90 #include <linux/firmware.h>
91 #include <linux/types.h>
92 #include <linux/dma-mapping.h>
93 #include <linux/mii.h>
94 #include <linux/if_vlan.h>
95 #include <asm/unaligned.h>
97 #include <linux/ethtool.h>
98 #include <linux/uaccess.h>
102 static uint slic_first_init = 1;
103 static char *slic_banner = "Alacritech SLIC Technology(tm) Server "\
104 "and Storage Accelerator (Non-Accelerated)";
106 static char *slic_proc_version = "2.0.351 2006/07/14 12:26:00";
107 static char *slic_product_name = "SLIC Technology(tm) Server "\
108 "and Storage Accelerator (Non-Accelerated)";
109 static char *slic_vendor = "Alacritech, Inc.";
111 static int slic_debug = 1;
112 static int debug = -1;
113 static struct net_device *head_netdevice;
115 static struct base_driver slic_global = { {}, 0, 0, 0, 1, NULL, NULL };
116 static int intagg_delay = 100;
117 static u32 dynamic_intagg;
118 static unsigned int rcv_count;
119 static struct dentry *slic_debugfs;
121 #define DRV_NAME "slicoss"
122 #define DRV_VERSION "2.0.1"
123 #define DRV_AUTHOR "Alacritech, Inc. Engineering"
124 #define DRV_DESCRIPTION "Alacritech SLIC Techonology(tm) "\
125 "Non-Accelerated Driver"
126 #define DRV_COPYRIGHT "Copyright 2000-2006 Alacritech, Inc. "\
127 "All rights reserved."
128 #define PFX DRV_NAME " "
130 MODULE_AUTHOR(DRV_AUTHOR);
131 MODULE_DESCRIPTION(DRV_DESCRIPTION);
132 MODULE_LICENSE("Dual BSD/GPL");
134 module_param(dynamic_intagg, int, 0);
135 MODULE_PARM_DESC(dynamic_intagg, "Dynamic Interrupt Aggregation Setting");
136 module_param(intagg_delay, int, 0);
137 MODULE_PARM_DESC(intagg_delay, "uSec Interrupt Aggregation Delay");
139 static const struct pci_device_id slic_pci_tbl[] = {
140 { PCI_DEVICE(PCI_VENDOR_ID_ALACRITECH, SLIC_1GB_DEVICE_ID) },
141 { PCI_DEVICE(PCI_VENDOR_ID_ALACRITECH, SLIC_2GB_DEVICE_ID) },
145 MODULE_DEVICE_TABLE(pci, slic_pci_tbl);
147 #define SLIC_GET_SLIC_HANDLE(_adapter, _pslic_handle) \
149 spin_lock_irqsave(&_adapter->handle_lock.lock, \
150 _adapter->handle_lock.flags); \
151 _pslic_handle = _adapter->pfree_slic_handles; \
152 if (_pslic_handle) { \
153 _adapter->pfree_slic_handles = _pslic_handle->next; \
155 spin_unlock_irqrestore(&_adapter->handle_lock.lock, \
156 _adapter->handle_lock.flags); \
159 static inline void slic_reg32_write(void __iomem *reg, u32 value, bool flush)
166 static inline void slic_reg64_write(struct adapter *adapter, void __iomem *reg,
167 u32 value, void __iomem *regh, u32 paddrh,
170 spin_lock_irqsave(&adapter->bit64reglock.lock,
171 adapter->bit64reglock.flags);
172 if (paddrh != adapter->curaddrupper) {
173 adapter->curaddrupper = paddrh;
174 writel(paddrh, regh);
179 spin_unlock_irqrestore(&adapter->bit64reglock.lock,
180 adapter->bit64reglock.flags);
183 static void slic_mcast_set_bit(struct adapter *adapter, char *address)
185 unsigned char crcpoly;
187 /* Get the CRC polynomial for the mac address */
188 /* we use bits 1-8 (lsb), bitwise reversed,
189 * msb (= lsb bit 0 before bitrev) is automatically discarded */
190 crcpoly = (ether_crc(ETH_ALEN, address)>>23);
192 /* We only have space on the SLIC for 64 entries. Lop
193 * off the top two bits. (2^6 = 64)
197 /* OR in the new bit into our 64 bit mask. */
198 adapter->mcastmask |= (u64) 1 << crcpoly;
201 static void slic_mcast_set_mask(struct adapter *adapter)
203 __iomem struct slic_regs *slic_regs = adapter->slic_regs;
205 if (adapter->macopts & (MAC_ALLMCAST | MAC_PROMISC)) {
206 /* Turn on all multicast addresses. We have to do this for
207 * promiscuous mode as well as ALLMCAST mode. It saves the
208 * Microcode from having to keep state about the MAC
211 slic_reg32_write(&slic_regs->slic_mcastlow, 0xFFFFFFFF, FLUSH);
212 slic_reg32_write(&slic_regs->slic_mcasthigh, 0xFFFFFFFF,
215 /* Commit our multicast mast to the SLIC by writing to the
216 * multicast address mask registers
218 slic_reg32_write(&slic_regs->slic_mcastlow,
219 (u32)(adapter->mcastmask & 0xFFFFFFFF), FLUSH);
220 slic_reg32_write(&slic_regs->slic_mcasthigh,
221 (u32)((adapter->mcastmask >> 32) & 0xFFFFFFFF), FLUSH);
225 static void slic_timer_ping(ulong dev)
227 struct adapter *adapter;
228 struct sliccard *card;
230 adapter = netdev_priv((struct net_device *)dev);
231 card = adapter->card;
233 adapter->pingtimer.expires = jiffies + (PING_TIMER_INTERVAL * HZ);
234 add_timer(&adapter->pingtimer);
237 static void slic_unmap_mmio_space(struct adapter *adapter)
239 if (adapter->slic_regs)
240 iounmap(adapter->slic_regs);
241 adapter->slic_regs = NULL;
247 * Write phy control to configure link duplex/speed
250 static void slic_link_config(struct adapter *adapter,
251 u32 linkspeed, u32 linkduplex)
260 if (adapter->state != ADAPT_UP)
263 if (linkspeed > LINK_1000MB)
264 linkspeed = LINK_AUTOSPEED;
265 if (linkduplex > LINK_AUTOD)
266 linkduplex = LINK_AUTOD;
268 wphy = &adapter->slic_regs->slic_wphy;
270 if ((linkspeed == LINK_AUTOSPEED) || (linkspeed == LINK_1000MB)) {
271 if (adapter->flags & ADAPT_FLAGS_FIBERMEDIA) {
272 /* We've got a fiber gigabit interface, and register
273 * 4 is different in fiber mode than in copper mode
276 /* advertise FD only @1000 Mb */
277 phy_advreg = (MIICR_REG_4 | (PAR_ADV1000XFD));
278 /* enable PAUSE frames */
279 phy_advreg |= PAR_ASYMPAUSE_FIBER;
280 slic_reg32_write(wphy, phy_advreg, FLUSH);
282 if (linkspeed == LINK_AUTOSPEED) {
283 /* reset phy, enable auto-neg */
286 (PCR_RESET | PCR_AUTONEG |
288 slic_reg32_write(wphy, phy_config, FLUSH);
289 } else { /* forced 1000 Mb FD*/
290 /* power down phy to break link
291 this may not work) */
292 phy_config = (MIICR_REG_PCR | PCR_POWERDOWN);
293 slic_reg32_write(wphy, phy_config, FLUSH);
294 /* wait, Marvell says 1 sec,
295 try to get away with 10 ms */
298 /* disable auto-neg, set speed/duplex,
299 soft reset phy, powerup */
302 (PCR_RESET | PCR_SPEED_1000 |
304 slic_reg32_write(wphy, phy_config, FLUSH);
306 } else { /* copper gigabit */
308 /* Auto-Negotiate or 1000 Mb must be auto negotiated
309 * We've got a copper gigabit interface, and
310 * register 4 is different in copper mode than
313 if (linkspeed == LINK_AUTOSPEED) {
314 /* advertise 10/100 Mb modes */
317 (PAR_ADV100FD | PAR_ADV100HD | PAR_ADV10FD
320 /* linkspeed == LINK_1000MB -
321 don't advertise 10/100 Mb modes */
322 phy_advreg = MIICR_REG_4;
324 /* enable PAUSE frames */
325 phy_advreg |= PAR_ASYMPAUSE;
326 /* required by the Cicada PHY */
327 phy_advreg |= PAR_802_3;
328 slic_reg32_write(wphy, phy_advreg, FLUSH);
329 /* advertise FD only @1000 Mb */
330 phy_gctlreg = (MIICR_REG_9 | (PGC_ADV1000FD));
331 slic_reg32_write(wphy, phy_gctlreg, FLUSH);
333 if (adapter->subsysid != SLIC_1GB_CICADA_SUBSYS_ID) {
335 enable auto crossover */
337 (MIICR_REG_16 | (MRV_REG16_XOVERON));
338 slic_reg32_write(wphy, phy_config, FLUSH);
340 /* reset phy, enable auto-neg */
343 (PCR_RESET | PCR_AUTONEG |
345 slic_reg32_write(wphy, phy_config, FLUSH);
346 } else { /* it's a Cicada PHY */
347 /* enable and restart auto-neg (don't reset) */
350 (PCR_AUTONEG | PCR_AUTONEG_RST));
351 slic_reg32_write(wphy, phy_config, FLUSH);
356 if (linkspeed == LINK_10MB)
359 speed = PCR_SPEED_100;
360 if (linkduplex == LINK_HALFD)
363 duplex = PCR_DUPLEX_FULL;
365 if (adapter->subsysid != SLIC_1GB_CICADA_SUBSYS_ID) {
367 disable auto crossover */
368 phy_config = (MIICR_REG_16 | (MRV_REG16_XOVEROFF));
369 slic_reg32_write(wphy, phy_config, FLUSH);
372 /* power down phy to break link (this may not work) */
373 phy_config = (MIICR_REG_PCR | (PCR_POWERDOWN | speed | duplex));
374 slic_reg32_write(wphy, phy_config, FLUSH);
376 /* wait, Marvell says 1 sec, try to get away with 10 ms */
379 if (adapter->subsysid != SLIC_1GB_CICADA_SUBSYS_ID) {
381 disable auto-neg, set speed,
382 soft reset phy, powerup */
384 (MIICR_REG_PCR | (PCR_RESET | speed | duplex));
385 slic_reg32_write(wphy, phy_config, FLUSH);
386 } else { /* it's a Cicada PHY */
387 /* disable auto-neg, set speed, powerup */
388 phy_config = (MIICR_REG_PCR | (speed | duplex));
389 slic_reg32_write(wphy, phy_config, FLUSH);
394 static int slic_card_download_gbrcv(struct adapter *adapter)
396 const struct firmware *fw;
397 const char *file = "";
399 __iomem struct slic_regs *slic_regs = adapter->slic_regs;
405 switch (adapter->devid) {
406 case SLIC_2GB_DEVICE_ID:
407 file = "slicoss/oasisrcvucode.sys";
409 case SLIC_1GB_DEVICE_ID:
410 file = "slicoss/gbrcvucode.sys";
416 ret = request_firmware(&fw, file, &adapter->pcidev->dev);
418 dev_err(&adapter->pcidev->dev,
419 "SLICOSS: Failed to load firmware %s\n", file);
423 rcvucodelen = *(u32 *)(fw->data + index);
425 switch (adapter->devid) {
426 case SLIC_2GB_DEVICE_ID:
427 if (rcvucodelen != OasisRcvUCodeLen) {
428 release_firmware(fw);
432 case SLIC_1GB_DEVICE_ID:
433 if (rcvucodelen != GBRcvUCodeLen) {
434 release_firmware(fw);
440 slic_reg32_write(&slic_regs->slic_rcv_wcs, SLIC_RCVWCS_BEGIN, FLUSH);
441 /* download the rcv sequencer ucode */
442 for (codeaddr = 0; codeaddr < rcvucodelen; codeaddr++) {
443 /* write out instruction address */
444 slic_reg32_write(&slic_regs->slic_rcv_wcs, codeaddr, FLUSH);
446 instruction = *(u32 *)(fw->data + index);
448 /* write out the instruction data low addr */
449 slic_reg32_write(&slic_regs->slic_rcv_wcs, instruction, FLUSH);
451 instruction = *(u8 *)(fw->data + index);
453 /* write out the instruction data high addr */
454 slic_reg32_write(&slic_regs->slic_rcv_wcs, (u8)instruction,
458 /* download finished */
459 release_firmware(fw);
460 slic_reg32_write(&slic_regs->slic_rcv_wcs, SLIC_RCVWCS_FINISH, FLUSH);
464 MODULE_FIRMWARE("slicoss/oasisrcvucode.sys");
465 MODULE_FIRMWARE("slicoss/gbrcvucode.sys");
467 static int slic_card_download(struct adapter *adapter)
469 const struct firmware *fw;
470 const char *file = "";
475 __iomem struct slic_regs *slic_regs = adapter->slic_regs;
482 int ucode_start, index = 0;
484 switch (adapter->devid) {
485 case SLIC_2GB_DEVICE_ID:
486 file = "slicoss/oasisdownload.sys";
488 case SLIC_1GB_DEVICE_ID:
489 file = "slicoss/gbdownload.sys";
494 ret = request_firmware(&fw, file, &adapter->pcidev->dev);
496 dev_err(&adapter->pcidev->dev,
497 "SLICOSS: Failed to load firmware %s\n", file);
500 numsects = *(u32 *)(fw->data + index);
502 for (i = 0; i < numsects; i++) {
503 sectsize[i] = *(u32 *)(fw->data + index);
506 for (i = 0; i < numsects; i++) {
507 sectstart[i] = *(u32 *)(fw->data + index);
511 instruction = *(u32 *)(fw->data + index);
513 for (section = 0; section < numsects; section++) {
514 baseaddress = sectstart[section];
515 thissectionsize = sectsize[section] >> 3;
517 for (codeaddr = 0; codeaddr < thissectionsize; codeaddr++) {
518 /* Write out instruction address */
519 slic_reg32_write(&slic_regs->slic_wcs,
520 baseaddress + codeaddr, FLUSH);
521 /* Write out instruction to low addr */
522 slic_reg32_write(&slic_regs->slic_wcs, instruction, FLUSH);
523 instruction = *(u32 *)(fw->data + index);
526 /* Write out instruction to high addr */
527 slic_reg32_write(&slic_regs->slic_wcs, instruction, FLUSH);
528 instruction = *(u32 *)(fw->data + index);
533 for (section = 0; section < numsects; section++) {
534 instruction = *(u32 *)(fw->data + index);
535 baseaddress = sectstart[section];
536 if (baseaddress < 0x8000)
538 thissectionsize = sectsize[section] >> 3;
540 for (codeaddr = 0; codeaddr < thissectionsize; codeaddr++) {
541 /* Write out instruction address */
542 slic_reg32_write(&slic_regs->slic_wcs,
543 SLIC_WCS_COMPARE | (baseaddress + codeaddr),
545 /* Write out instruction to low addr */
546 slic_reg32_write(&slic_regs->slic_wcs, instruction,
548 instruction = *(u32 *)(fw->data + index);
550 /* Write out instruction to high addr */
551 slic_reg32_write(&slic_regs->slic_wcs, instruction,
553 instruction = *(u32 *)(fw->data + index);
556 /* Check SRAM location zero. If it is non-zero. Abort.*/
557 /* failure = readl((u32 __iomem *)&slic_regs->slic_reset);
559 release_firmware(fw);
564 release_firmware(fw);
565 /* Everything OK, kick off the card */
567 slic_reg32_write(&slic_regs->slic_wcs, SLIC_WCS_START, FLUSH);
569 /* stall for 20 ms, long enough for ucode to init card
570 and reach mainloop */
576 MODULE_FIRMWARE("slicoss/oasisdownload.sys");
577 MODULE_FIRMWARE("slicoss/gbdownload.sys");
579 static void slic_adapter_set_hwaddr(struct adapter *adapter)
581 struct sliccard *card = adapter->card;
583 if ((adapter->card) && (card->config_set)) {
584 memcpy(adapter->macaddr,
585 card->config.MacInfo[adapter->functionnumber].macaddrA,
586 sizeof(struct slic_config_mac));
587 if (is_zero_ether_addr(adapter->currmacaddr))
588 memcpy(adapter->currmacaddr, adapter->macaddr,
591 memcpy(adapter->netdev->dev_addr, adapter->currmacaddr,
596 static void slic_intagg_set(struct adapter *adapter, u32 value)
598 slic_reg32_write(&adapter->slic_regs->slic_intagg, value, FLUSH);
599 adapter->card->loadlevel_current = value;
602 static void slic_soft_reset(struct adapter *adapter)
604 if (adapter->card->state == CARD_UP) {
605 slic_reg32_write(&adapter->slic_regs->slic_quiesce, 0, FLUSH);
609 slic_reg32_write(&adapter->slic_regs->slic_reset, SLIC_RESET_MAGIC,
614 static void slic_mac_address_config(struct adapter *adapter)
618 __iomem struct slic_regs *slic_regs = adapter->slic_regs;
620 value = *(u32 *) &adapter->currmacaddr[2];
621 value = ntohl(value);
622 slic_reg32_write(&slic_regs->slic_wraddral, value, FLUSH);
623 slic_reg32_write(&slic_regs->slic_wraddrbl, value, FLUSH);
625 value2 = (u32) ((adapter->currmacaddr[0] << 8 |
626 adapter->currmacaddr[1]) & 0xFFFF);
628 slic_reg32_write(&slic_regs->slic_wraddrah, value2, FLUSH);
629 slic_reg32_write(&slic_regs->slic_wraddrbh, value2, FLUSH);
631 /* Write our multicast mask out to the card. This is done */
632 /* here in addition to the slic_mcast_addr_set routine */
633 /* because ALL_MCAST may have been enabled or disabled */
634 slic_mcast_set_mask(adapter);
637 static void slic_mac_config(struct adapter *adapter)
640 __iomem struct slic_regs *slic_regs = adapter->slic_regs;
642 /* Setup GMAC gaps */
643 if (adapter->linkspeed == LINK_1000MB) {
644 value = ((GMCR_GAPBB_1000 << GMCR_GAPBB_SHIFT) |
645 (GMCR_GAPR1_1000 << GMCR_GAPR1_SHIFT) |
646 (GMCR_GAPR2_1000 << GMCR_GAPR2_SHIFT));
648 value = ((GMCR_GAPBB_100 << GMCR_GAPBB_SHIFT) |
649 (GMCR_GAPR1_100 << GMCR_GAPR1_SHIFT) |
650 (GMCR_GAPR2_100 << GMCR_GAPR2_SHIFT));
654 if (adapter->linkspeed == LINK_1000MB)
657 /* enable fullduplex */
658 if ((adapter->linkduplex == LINK_FULLD)
659 || (adapter->macopts & MAC_LOOPBACK)) {
663 /* write mac config */
664 slic_reg32_write(&slic_regs->slic_wmcfg, value, FLUSH);
666 /* setup mac addresses */
667 slic_mac_address_config(adapter);
670 static void slic_config_set(struct adapter *adapter, bool linkchange)
674 __iomem struct slic_regs *slic_regs = adapter->slic_regs;
678 slic_mac_config(adapter);
679 RcrReset = GRCR_RESET;
681 slic_mac_address_config(adapter);
685 if (adapter->linkduplex == LINK_FULLD) {
687 value = (GXCR_RESET | /* Always reset */
688 GXCR_XMTEN | /* Enable transmit */
689 GXCR_PAUSEEN); /* Enable pause */
691 slic_reg32_write(&slic_regs->slic_wxcfg, value, FLUSH);
693 /* Setup rcvcfg last */
694 value = (RcrReset | /* Reset, if linkchange */
695 GRCR_CTLEN | /* Enable CTL frames */
696 GRCR_ADDRAEN | /* Address A enable */
697 GRCR_RCVBAD | /* Rcv bad frames */
698 (GRCR_HASHSIZE << GRCR_HASHSIZE_SHIFT));
701 value = (GXCR_RESET | /* Always reset */
702 GXCR_XMTEN); /* Enable transmit */
704 slic_reg32_write(&slic_regs->slic_wxcfg, value, FLUSH);
706 /* Setup rcvcfg last */
707 value = (RcrReset | /* Reset, if linkchange */
708 GRCR_ADDRAEN | /* Address A enable */
709 GRCR_RCVBAD | /* Rcv bad frames */
710 (GRCR_HASHSIZE << GRCR_HASHSIZE_SHIFT));
713 if (adapter->state != ADAPT_DOWN) {
714 /* Only enable receive if we are restarting or running */
718 if (adapter->macopts & MAC_PROMISC)
719 value |= GRCR_RCVALL;
721 slic_reg32_write(&slic_regs->slic_wrcfg, value, FLUSH);
725 * Turn off RCV and XMT, power down PHY
727 static void slic_config_clear(struct adapter *adapter)
731 __iomem struct slic_regs *slic_regs = adapter->slic_regs;
734 value = (GXCR_RESET | /* Always reset */
735 GXCR_PAUSEEN); /* Enable pause */
737 slic_reg32_write(&slic_regs->slic_wxcfg, value, FLUSH);
739 value = (GRCR_RESET | /* Always reset */
740 GRCR_CTLEN | /* Enable CTL frames */
741 GRCR_ADDRAEN | /* Address A enable */
742 (GRCR_HASHSIZE << GRCR_HASHSIZE_SHIFT));
744 slic_reg32_write(&slic_regs->slic_wrcfg, value, FLUSH);
747 phy_config = (MIICR_REG_PCR | (PCR_POWERDOWN));
748 slic_reg32_write(&slic_regs->slic_wphy, phy_config, FLUSH);
751 static bool slic_mac_filter(struct adapter *adapter,
752 struct ether_header *ether_frame)
754 struct net_device *netdev = adapter->netdev;
755 u32 opts = adapter->macopts;
757 if (opts & MAC_PROMISC)
760 if (is_broadcast_ether_addr(ether_frame->ether_dhost)) {
761 if (opts & MAC_BCAST) {
762 adapter->rcv_broadcasts++;
769 if (is_multicast_ether_addr(ether_frame->ether_dhost)) {
770 if (opts & MAC_ALLMCAST) {
771 adapter->rcv_multicasts++;
772 netdev->stats.multicast++;
775 if (opts & MAC_MCAST) {
776 struct mcast_address *mcaddr = adapter->mcastaddrs;
779 if (ether_addr_equal(mcaddr->address,
780 ether_frame->ether_dhost)) {
781 adapter->rcv_multicasts++;
782 netdev->stats.multicast++;
785 mcaddr = mcaddr->next;
792 if (opts & MAC_DIRECTED) {
793 adapter->rcv_unicasts++;
800 static int slic_mac_set_address(struct net_device *dev, void *ptr)
802 struct adapter *adapter = netdev_priv(dev);
803 struct sockaddr *addr = ptr;
805 if (netif_running(dev))
810 if (!is_valid_ether_addr(addr->sa_data))
813 memcpy(dev->dev_addr, addr->sa_data, dev->addr_len);
814 memcpy(adapter->currmacaddr, addr->sa_data, dev->addr_len);
816 slic_config_set(adapter, true);
820 static void slic_timer_load_check(ulong cardaddr)
822 struct sliccard *card = (struct sliccard *)cardaddr;
823 struct adapter *adapter = card->master;
825 u32 load = card->events;
828 if ((adapter) && (adapter->state == ADAPT_UP) &&
829 (card->state == CARD_UP) && (slic_global.dynamic_intagg)) {
830 intagg = &adapter->slic_regs->slic_intagg;
831 if (adapter->devid == SLIC_1GB_DEVICE_ID) {
832 if (adapter->linkspeed == LINK_1000MB)
835 if (load > SLIC_LOAD_5)
836 level = SLIC_INTAGG_5;
837 else if (load > SLIC_LOAD_4)
838 level = SLIC_INTAGG_4;
839 else if (load > SLIC_LOAD_3)
840 level = SLIC_INTAGG_3;
841 else if (load > SLIC_LOAD_2)
842 level = SLIC_INTAGG_2;
843 else if (load > SLIC_LOAD_1)
844 level = SLIC_INTAGG_1;
846 level = SLIC_INTAGG_0;
848 if (card->loadlevel_current != level) {
849 card->loadlevel_current = level;
850 slic_reg32_write(intagg, level, FLUSH);
853 if (load > SLIC_LOAD_5)
854 level = SLIC_INTAGG_5;
855 else if (load > SLIC_LOAD_4)
856 level = SLIC_INTAGG_4;
857 else if (load > SLIC_LOAD_3)
858 level = SLIC_INTAGG_3;
859 else if (load > SLIC_LOAD_2)
860 level = SLIC_INTAGG_2;
861 else if (load > SLIC_LOAD_1)
862 level = SLIC_INTAGG_1;
864 level = SLIC_INTAGG_0;
865 if (card->loadlevel_current != level) {
866 card->loadlevel_current = level;
867 slic_reg32_write(intagg, level, FLUSH);
872 card->loadtimer.expires = jiffies + (SLIC_LOADTIMER_PERIOD * HZ);
873 add_timer(&card->loadtimer);
876 static int slic_upr_queue_request(struct adapter *adapter,
880 u32 upr_buffer, u32 upr_buffer_h)
882 struct slic_upr *upr;
883 struct slic_upr *uprqueue;
885 upr = kmalloc(sizeof(struct slic_upr), GFP_ATOMIC);
889 upr->adapter = adapter->port;
890 upr->upr_request = upr_request;
891 upr->upr_data = upr_data;
892 upr->upr_buffer = upr_buffer;
893 upr->upr_data_h = upr_data_h;
894 upr->upr_buffer_h = upr_buffer_h;
896 if (adapter->upr_list) {
897 uprqueue = adapter->upr_list;
899 while (uprqueue->next)
900 uprqueue = uprqueue->next;
901 uprqueue->next = upr;
903 adapter->upr_list = upr;
908 static void slic_upr_start(struct adapter *adapter)
910 struct slic_upr *upr;
911 __iomem struct slic_regs *slic_regs = adapter->slic_regs;
917 upr = adapter->upr_list;
920 if (adapter->upr_busy)
922 adapter->upr_busy = 1;
924 switch (upr->upr_request) {
926 if (upr->upr_data_h == 0) {
927 slic_reg32_write(&slic_regs->slic_stats, upr->upr_data,
930 slic_reg64_write(adapter, &slic_regs->slic_stats64,
932 &slic_regs->slic_addr_upper,
933 upr->upr_data_h, FLUSH);
938 slic_reg64_write(adapter, &slic_regs->slic_rlsr, upr->upr_data,
939 &slic_regs->slic_addr_upper, upr->upr_data_h,
943 case SLIC_UPR_RCONFIG:
944 slic_reg64_write(adapter, &slic_regs->slic_rconfig,
945 upr->upr_data, &slic_regs->slic_addr_upper,
946 upr->upr_data_h, FLUSH);
949 slic_reg32_write(&slic_regs->slic_ping, 1, FLUSH);
954 static int slic_upr_request(struct adapter *adapter,
958 u32 upr_buffer, u32 upr_buffer_h)
962 spin_lock_irqsave(&adapter->upr_lock.lock, adapter->upr_lock.flags);
963 rc = slic_upr_queue_request(adapter,
966 upr_data_h, upr_buffer, upr_buffer_h);
970 slic_upr_start(adapter);
972 spin_unlock_irqrestore(&adapter->upr_lock.lock,
973 adapter->upr_lock.flags);
977 static void slic_link_upr_complete(struct adapter *adapter, u32 isr)
979 u32 linkstatus = adapter->pshmem->linkstatus;
981 unsigned char linkspeed;
982 unsigned char linkduplex;
984 if ((isr & ISR_UPCERR) || (isr & ISR_UPCBSY)) {
985 struct slic_shmem *pshmem;
987 pshmem = (struct slic_shmem *)(unsigned long)
989 #if BITS_PER_LONG == 64
990 slic_upr_queue_request(adapter,
992 SLIC_GET_ADDR_LOW(&pshmem->linkstatus),
993 SLIC_GET_ADDR_HIGH(&pshmem->linkstatus),
996 slic_upr_queue_request(adapter,
998 (u32) &pshmem->linkstatus,
999 SLIC_GET_ADDR_HIGH(pshmem), 0, 0);
1003 if (adapter->state != ADAPT_UP)
1006 linkup = linkstatus & GIG_LINKUP ? LINK_UP : LINK_DOWN;
1007 if (linkstatus & GIG_SPEED_1000)
1008 linkspeed = LINK_1000MB;
1009 else if (linkstatus & GIG_SPEED_100)
1010 linkspeed = LINK_100MB;
1012 linkspeed = LINK_10MB;
1014 if (linkstatus & GIG_FULLDUPLEX)
1015 linkduplex = LINK_FULLD;
1017 linkduplex = LINK_HALFD;
1019 if ((adapter->linkstate == LINK_DOWN) && (linkup == LINK_DOWN))
1022 /* link up event, but nothing has changed */
1023 if ((adapter->linkstate == LINK_UP) &&
1024 (linkup == LINK_UP) &&
1025 (adapter->linkspeed == linkspeed) &&
1026 (adapter->linkduplex == linkduplex))
1029 /* link has changed at this point */
1031 /* link has gone from up to down */
1032 if (linkup == LINK_DOWN) {
1033 adapter->linkstate = LINK_DOWN;
1037 /* link has gone from down to up */
1038 adapter->linkspeed = linkspeed;
1039 adapter->linkduplex = linkduplex;
1041 if (adapter->linkstate != LINK_UP) {
1043 slic_config_set(adapter, true);
1044 adapter->linkstate = LINK_UP;
1045 netif_start_queue(adapter->netdev);
1049 static void slic_upr_request_complete(struct adapter *adapter, u32 isr)
1051 struct sliccard *card = adapter->card;
1052 struct slic_upr *upr;
1054 spin_lock_irqsave(&adapter->upr_lock.lock, adapter->upr_lock.flags);
1055 upr = adapter->upr_list;
1057 spin_unlock_irqrestore(&adapter->upr_lock.lock,
1058 adapter->upr_lock.flags);
1061 adapter->upr_list = upr->next;
1063 adapter->upr_busy = 0;
1064 switch (upr->upr_request) {
1065 case SLIC_UPR_STATS:
1067 struct slic_stats *slicstats =
1068 (struct slic_stats *) &adapter->pshmem->inicstats;
1069 struct slic_stats *newstats = slicstats;
1070 struct slic_stats *old = &adapter->inicstats_prev;
1071 struct slicnet_stats *stst = &adapter->slic_stats;
1073 if (isr & ISR_UPCERR) {
1074 dev_err(&adapter->netdev->dev,
1075 "SLIC_UPR_STATS command failed isr[%x]\n",
1080 UPDATE_STATS_GB(stst->tcp.xmit_tcp_segs,
1081 newstats->xmit_tcp_segs_gb,
1082 old->xmit_tcp_segs_gb);
1084 UPDATE_STATS_GB(stst->tcp.xmit_tcp_bytes,
1085 newstats->xmit_tcp_bytes_gb,
1086 old->xmit_tcp_bytes_gb);
1088 UPDATE_STATS_GB(stst->tcp.rcv_tcp_segs,
1089 newstats->rcv_tcp_segs_gb,
1090 old->rcv_tcp_segs_gb);
1092 UPDATE_STATS_GB(stst->tcp.rcv_tcp_bytes,
1093 newstats->rcv_tcp_bytes_gb,
1094 old->rcv_tcp_bytes_gb);
1096 UPDATE_STATS_GB(stst->iface.xmt_bytes,
1097 newstats->xmit_bytes_gb,
1098 old->xmit_bytes_gb);
1100 UPDATE_STATS_GB(stst->iface.xmt_ucast,
1101 newstats->xmit_unicasts_gb,
1102 old->xmit_unicasts_gb);
1104 UPDATE_STATS_GB(stst->iface.rcv_bytes,
1105 newstats->rcv_bytes_gb,
1108 UPDATE_STATS_GB(stst->iface.rcv_ucast,
1109 newstats->rcv_unicasts_gb,
1110 old->rcv_unicasts_gb);
1112 UPDATE_STATS_GB(stst->iface.xmt_errors,
1113 newstats->xmit_collisions_gb,
1114 old->xmit_collisions_gb);
1116 UPDATE_STATS_GB(stst->iface.xmt_errors,
1117 newstats->xmit_excess_collisions_gb,
1118 old->xmit_excess_collisions_gb);
1120 UPDATE_STATS_GB(stst->iface.xmt_errors,
1121 newstats->xmit_other_error_gb,
1122 old->xmit_other_error_gb);
1124 UPDATE_STATS_GB(stst->iface.rcv_errors,
1125 newstats->rcv_other_error_gb,
1126 old->rcv_other_error_gb);
1128 UPDATE_STATS_GB(stst->iface.rcv_discards,
1129 newstats->rcv_drops_gb,
1132 if (newstats->rcv_drops_gb > old->rcv_drops_gb) {
1133 adapter->rcv_drops +=
1134 (newstats->rcv_drops_gb -
1137 memcpy(old, newstats, sizeof(struct slic_stats));
1141 slic_link_upr_complete(adapter, isr);
1143 case SLIC_UPR_RCONFIG:
1146 card->pingstatus |= (isr & ISR_PINGDSMASK);
1150 slic_upr_start(adapter);
1151 spin_unlock_irqrestore(&adapter->upr_lock.lock,
1152 adapter->upr_lock.flags);
1155 static void slic_config_get(struct adapter *adapter, u32 config,
1160 status = slic_upr_request(adapter,
1162 (u32) config, (u32) config_h, 0, 0);
1166 * this is here to checksum the eeprom, there is some ucode bug
1167 * which prevens us from using the ucode result.
1168 * remove this once ucode is fixed.
1170 static ushort slic_eeprom_cksum(char *m, int len)
1172 #define ADDCARRY(x) (x > 65535 ? x -= 65535 : x)
1173 #define REDUCE {l_util.l = sum; sum = l_util.s[0] + l_util.s[1]; ADDCARRY(sum);\
1178 u32 byte_swapped = 0;
1195 #if BITS_PER_LONG == 64
1196 w_int = (u32) ((ulong) w & 0x00000000FFFFFFFF);
1200 if ((1 & w_int) && (len > 0)) {
1203 s_util.c[0] = *(unsigned char *)w;
1204 w = (u16 *)((char *)w + 1);
1209 /* Unroll the loop to make overhead from branches &c small. */
1210 while ((len -= 32) >= 0) {
1227 w = (u16 *)((ulong) w + 16); /* verify */
1230 while ((len -= 8) >= 0) {
1235 w = (u16 *)((ulong) w + 4); /* verify */
1238 if (len != 0 || byte_swapped != 0) {
1240 while ((len -= 2) >= 0)
1241 sum += *w++; /* verify */
1247 s_util.c[1] = *(char *) w;
1254 } else if (len == -1) {
1255 s_util.c[0] = *(char *) w;
1264 return (ushort) sum;
1267 static void slic_rspqueue_free(struct adapter *adapter)
1270 struct slic_rspqueue *rspq = &adapter->rspqueue;
1272 for (i = 0; i < rspq->num_pages; i++) {
1273 if (rspq->vaddr[i]) {
1274 pci_free_consistent(adapter->pcidev, PAGE_SIZE,
1275 rspq->vaddr[i], rspq->paddr[i]);
1277 rspq->vaddr[i] = NULL;
1281 rspq->pageindex = 0;
1282 rspq->rspbuf = NULL;
1285 static int slic_rspqueue_init(struct adapter *adapter)
1288 struct slic_rspqueue *rspq = &adapter->rspqueue;
1289 __iomem struct slic_regs *slic_regs = adapter->slic_regs;
1292 memset(rspq, 0, sizeof(struct slic_rspqueue));
1294 rspq->num_pages = SLIC_RSPQ_PAGES_GB;
1296 for (i = 0; i < rspq->num_pages; i++) {
1297 rspq->vaddr[i] = pci_alloc_consistent(adapter->pcidev,
1300 if (!rspq->vaddr[i]) {
1301 dev_err(&adapter->pcidev->dev,
1302 "pci_alloc_consistent failed\n");
1303 slic_rspqueue_free(adapter);
1307 * do we really need this assertions (4K PAGE_SIZE aligned addr)? */
1308 memset(rspq->vaddr[i], 0, PAGE_SIZE);
1311 slic_reg32_write(&slic_regs->slic_rbar,
1312 (rspq->paddr[i] | SLIC_RSPQ_BUFSINPAGE),
1315 slic_reg64_write(adapter, &slic_regs->slic_rbar64,
1316 (rspq->paddr[i] | SLIC_RSPQ_BUFSINPAGE),
1317 &slic_regs->slic_addr_upper,
1318 paddrh, DONT_FLUSH);
1322 rspq->pageindex = 0;
1323 rspq->rspbuf = (struct slic_rspbuf *)rspq->vaddr[0];
1327 static struct slic_rspbuf *slic_rspqueue_getnext(struct adapter *adapter)
1329 struct slic_rspqueue *rspq = &adapter->rspqueue;
1330 struct slic_rspbuf *buf;
1332 if (!(rspq->rspbuf->status))
1336 if (++rspq->offset < SLIC_RSPQ_BUFSINPAGE) {
1339 slic_reg64_write(adapter, &adapter->slic_regs->slic_rbar64,
1340 (rspq->paddr[rspq->pageindex] | SLIC_RSPQ_BUFSINPAGE),
1341 &adapter->slic_regs->slic_addr_upper, 0, DONT_FLUSH);
1342 rspq->pageindex = (rspq->pageindex + 1) % rspq->num_pages;
1344 rspq->rspbuf = (struct slic_rspbuf *)
1345 rspq->vaddr[rspq->pageindex];
1351 static void slic_cmdqmem_free(struct adapter *adapter)
1353 struct slic_cmdqmem *cmdqmem = &adapter->cmdqmem;
1356 for (i = 0; i < SLIC_CMDQ_MAXPAGES; i++) {
1357 if (cmdqmem->pages[i]) {
1358 pci_free_consistent(adapter->pcidev,
1360 (void *) cmdqmem->pages[i],
1361 cmdqmem->dma_pages[i]);
1364 memset(cmdqmem, 0, sizeof(struct slic_cmdqmem));
1367 static u32 *slic_cmdqmem_addpage(struct adapter *adapter)
1369 struct slic_cmdqmem *cmdqmem = &adapter->cmdqmem;
1372 if (cmdqmem->pagecnt >= SLIC_CMDQ_MAXPAGES)
1374 pageaddr = pci_alloc_consistent(adapter->pcidev,
1376 &cmdqmem->dma_pages[cmdqmem->pagecnt]);
1380 cmdqmem->pages[cmdqmem->pagecnt] = pageaddr;
1385 static void slic_cmdq_free(struct adapter *adapter)
1387 struct slic_hostcmd *cmd;
1389 cmd = adapter->cmdq_all.head;
1392 struct sk_buff *tempskb;
1397 dev_kfree_skb_irq(tempskb);
1400 cmd = cmd->next_all;
1402 memset(&adapter->cmdq_all, 0, sizeof(struct slic_cmdqueue));
1403 memset(&adapter->cmdq_free, 0, sizeof(struct slic_cmdqueue));
1404 memset(&adapter->cmdq_done, 0, sizeof(struct slic_cmdqueue));
1405 slic_cmdqmem_free(adapter);
1408 static void slic_cmdq_addcmdpage(struct adapter *adapter, u32 *page)
1410 struct slic_hostcmd *cmd;
1411 struct slic_hostcmd *prev;
1412 struct slic_hostcmd *tail;
1413 struct slic_cmdqueue *cmdq;
1419 struct slic_handle *pslic_handle;
1422 cmd = (struct slic_hostcmd *)cmdaddr;
1425 phys_addr = virt_to_bus((void *)page);
1426 phys_addrl = SLIC_GET_ADDR_LOW(phys_addr);
1427 phys_addrh = SLIC_GET_ADDR_HIGH(phys_addr);
1431 while ((cmdcnt < SLIC_CMDQ_CMDSINPAGE) &&
1432 (adapter->slic_handle_ix < 256)) {
1433 /* Allocate and initialize a SLIC_HANDLE for this command */
1434 SLIC_GET_SLIC_HANDLE(adapter, pslic_handle);
1435 pslic_handle->type = SLIC_HANDLE_CMD;
1436 pslic_handle->address = (void *) cmd;
1437 pslic_handle->offset = (ushort) adapter->slic_handle_ix++;
1438 pslic_handle->other_handle = NULL;
1439 pslic_handle->next = NULL;
1441 cmd->pslic_handle = pslic_handle;
1442 cmd->cmd64.hosthandle = pslic_handle->token.handle_token;
1444 cmd->paddrl = phys_addrl;
1445 cmd->paddrh = phys_addrh;
1446 cmd->next_all = prev;
1449 phys_addrl += SLIC_HOSTCMD_SIZE;
1450 cmdaddr += SLIC_HOSTCMD_SIZE;
1452 cmd = (struct slic_hostcmd *)cmdaddr;
1456 cmdq = &adapter->cmdq_all;
1457 cmdq->count += cmdcnt; /* SLIC_CMDQ_CMDSINPAGE; mooktodo */
1458 tail->next_all = cmdq->head;
1460 cmdq = &adapter->cmdq_free;
1461 spin_lock_irqsave(&cmdq->lock.lock, cmdq->lock.flags);
1462 cmdq->count += cmdcnt; /* SLIC_CMDQ_CMDSINPAGE; mooktodo */
1463 tail->next = cmdq->head;
1465 spin_unlock_irqrestore(&cmdq->lock.lock, cmdq->lock.flags);
1468 static int slic_cmdq_init(struct adapter *adapter)
1473 memset(&adapter->cmdq_all, 0, sizeof(struct slic_cmdqueue));
1474 memset(&adapter->cmdq_free, 0, sizeof(struct slic_cmdqueue));
1475 memset(&adapter->cmdq_done, 0, sizeof(struct slic_cmdqueue));
1476 spin_lock_init(&adapter->cmdq_all.lock.lock);
1477 spin_lock_init(&adapter->cmdq_free.lock.lock);
1478 spin_lock_init(&adapter->cmdq_done.lock.lock);
1479 memset(&adapter->cmdqmem, 0, sizeof(struct slic_cmdqmem));
1480 adapter->slic_handle_ix = 1;
1481 for (i = 0; i < SLIC_CMDQ_INITPAGES; i++) {
1482 pageaddr = slic_cmdqmem_addpage(adapter);
1484 slic_cmdq_free(adapter);
1487 slic_cmdq_addcmdpage(adapter, pageaddr);
1489 adapter->slic_handle_ix = 1;
1494 static void slic_cmdq_reset(struct adapter *adapter)
1496 struct slic_hostcmd *hcmd;
1497 struct sk_buff *skb;
1500 spin_lock_irqsave(&adapter->cmdq_free.lock.lock,
1501 adapter->cmdq_free.lock.flags);
1502 spin_lock_irqsave(&adapter->cmdq_done.lock.lock,
1503 adapter->cmdq_done.lock.flags);
1504 outstanding = adapter->cmdq_all.count - adapter->cmdq_done.count;
1505 outstanding -= adapter->cmdq_free.count;
1506 hcmd = adapter->cmdq_all.head;
1512 dev_kfree_skb_irq(skb);
1514 hcmd = hcmd->next_all;
1516 adapter->cmdq_free.count = 0;
1517 adapter->cmdq_free.head = NULL;
1518 adapter->cmdq_free.tail = NULL;
1519 adapter->cmdq_done.count = 0;
1520 adapter->cmdq_done.head = NULL;
1521 adapter->cmdq_done.tail = NULL;
1522 adapter->cmdq_free.head = adapter->cmdq_all.head;
1523 hcmd = adapter->cmdq_all.head;
1525 adapter->cmdq_free.count++;
1526 hcmd->next = hcmd->next_all;
1527 hcmd = hcmd->next_all;
1529 if (adapter->cmdq_free.count != adapter->cmdq_all.count) {
1530 dev_err(&adapter->netdev->dev,
1531 "free_count %d != all count %d\n",
1532 adapter->cmdq_free.count, adapter->cmdq_all.count);
1534 spin_unlock_irqrestore(&adapter->cmdq_done.lock.lock,
1535 adapter->cmdq_done.lock.flags);
1536 spin_unlock_irqrestore(&adapter->cmdq_free.lock.lock,
1537 adapter->cmdq_free.lock.flags);
1540 static void slic_cmdq_getdone(struct adapter *adapter)
1542 struct slic_cmdqueue *done_cmdq = &adapter->cmdq_done;
1543 struct slic_cmdqueue *free_cmdq = &adapter->cmdq_free;
1545 spin_lock_irqsave(&done_cmdq->lock.lock, done_cmdq->lock.flags);
1547 free_cmdq->head = done_cmdq->head;
1548 free_cmdq->count = done_cmdq->count;
1549 done_cmdq->head = NULL;
1550 done_cmdq->tail = NULL;
1551 done_cmdq->count = 0;
1552 spin_unlock_irqrestore(&done_cmdq->lock.lock, done_cmdq->lock.flags);
1555 static struct slic_hostcmd *slic_cmdq_getfree(struct adapter *adapter)
1557 struct slic_cmdqueue *cmdq = &adapter->cmdq_free;
1558 struct slic_hostcmd *cmd = NULL;
1561 spin_lock_irqsave(&cmdq->lock.lock, cmdq->lock.flags);
1565 cmdq->head = cmd->next;
1567 spin_unlock_irqrestore(&cmdq->lock.lock, cmdq->lock.flags);
1569 slic_cmdq_getdone(adapter);
1576 spin_unlock_irqrestore(&cmdq->lock.lock,
1578 pageaddr = slic_cmdqmem_addpage(adapter);
1580 slic_cmdq_addcmdpage(adapter, pageaddr);
1581 goto lock_and_retry;
1588 static void slic_cmdq_putdone_irq(struct adapter *adapter,
1589 struct slic_hostcmd *cmd)
1591 struct slic_cmdqueue *cmdq = &adapter->cmdq_done;
1593 spin_lock(&cmdq->lock.lock);
1595 cmd->next = cmdq->head;
1598 if ((adapter->xmitq_full) && (cmdq->count > 10))
1599 netif_wake_queue(adapter->netdev);
1600 spin_unlock(&cmdq->lock.lock);
1603 static int slic_rcvqueue_fill(struct adapter *adapter)
1608 struct slic_rcvqueue *rcvq = &adapter->rcvqueue;
1610 struct device *dev = &adapter->netdev->dev;
1612 while (i < SLIC_RCVQ_FILLENTRIES) {
1613 struct slic_rcvbuf *rcvbuf;
1614 struct sk_buff *skb;
1615 #ifdef KLUDGE_FOR_4GB_BOUNDARY
1618 skb = alloc_skb(SLIC_RCVQ_RCVBUFSIZE, GFP_ATOMIC);
1620 paddr = (void *)(unsigned long)
1621 pci_map_single(adapter->pcidev,
1623 SLIC_RCVQ_RCVBUFSIZE,
1624 PCI_DMA_FROMDEVICE);
1625 paddrl = SLIC_GET_ADDR_LOW(paddr);
1626 paddrh = SLIC_GET_ADDR_HIGH(paddr);
1628 skb->len = SLIC_RCVBUF_HEADSIZE;
1629 rcvbuf = (struct slic_rcvbuf *)skb->head;
1632 #ifdef KLUDGE_FOR_4GB_BOUNDARY
1634 dev_err(dev, "%s: LOW 32bits PHYSICAL ADDRESS == 0\n",
1636 dev_err(dev, "skb[%p] PROBLEM\n", skb);
1637 dev_err(dev, " skbdata[%p]\n", skb->data);
1638 dev_err(dev, " skblen[%x]\n", skb->len);
1639 dev_err(dev, " paddr[%p]\n", paddr);
1640 dev_err(dev, " paddrl[%x]\n", paddrl);
1641 dev_err(dev, " paddrh[%x]\n", paddrh);
1642 dev_err(dev, " rcvq->head[%p]\n", rcvq->head);
1643 dev_err(dev, " rcvq->tail[%p]\n", rcvq->tail);
1644 dev_err(dev, " rcvq->count[%x]\n", rcvq->count);
1645 dev_err(dev, "SKIP THIS SKB!!!!!!!!\n");
1646 goto retry_rcvqfill;
1650 dev_err(dev, "%s: LOW 32bits PHYSICAL ADDRESS == 0\n",
1652 dev_err(dev, "skb[%p] PROBLEM\n", skb);
1653 dev_err(dev, " skbdata[%p]\n", skb->data);
1654 dev_err(dev, " skblen[%x]\n", skb->len);
1655 dev_err(dev, " paddr[%p]\n", paddr);
1656 dev_err(dev, " paddrl[%x]\n", paddrl);
1657 dev_err(dev, " paddrh[%x]\n", paddrh);
1658 dev_err(dev, " rcvq->head[%p]\n", rcvq->head);
1659 dev_err(dev, " rcvq->tail[%p]\n", rcvq->tail);
1660 dev_err(dev, " rcvq->count[%x]\n", rcvq->count);
1661 dev_err(dev, "GIVE TO CARD ANYWAY\n");
1665 slic_reg32_write(&adapter->slic_regs->slic_hbar,
1666 (u32)paddrl, DONT_FLUSH);
1668 slic_reg64_write(adapter,
1669 &adapter->slic_regs->slic_hbar64,
1671 &adapter->slic_regs->slic_addr_upper,
1672 paddrh, DONT_FLUSH);
1675 rcvq->tail->next = skb;
1682 dev_err(&adapter->netdev->dev,
1683 "slic_rcvqueue_fill could only get [%d] skbuffs\n",
1691 static void slic_rcvqueue_free(struct adapter *adapter)
1693 struct slic_rcvqueue *rcvq = &adapter->rcvqueue;
1694 struct sk_buff *skb;
1696 while (rcvq->head) {
1698 rcvq->head = rcvq->head->next;
1706 static int slic_rcvqueue_init(struct adapter *adapter)
1709 struct slic_rcvqueue *rcvq = &adapter->rcvqueue;
1713 rcvq->size = SLIC_RCVQ_ENTRIES;
1716 i = (SLIC_RCVQ_ENTRIES / SLIC_RCVQ_FILLENTRIES);
1719 count += slic_rcvqueue_fill(adapter);
1722 if (rcvq->count < SLIC_RCVQ_MINENTRIES) {
1723 slic_rcvqueue_free(adapter);
1729 static struct sk_buff *slic_rcvqueue_getnext(struct adapter *adapter)
1731 struct slic_rcvqueue *rcvq = &adapter->rcvqueue;
1732 struct sk_buff *skb;
1733 struct slic_rcvbuf *rcvbuf;
1738 rcvbuf = (struct slic_rcvbuf *)skb->head;
1740 if (rcvbuf->status & IRHDDR_SVALID) {
1741 rcvq->head = rcvq->head->next;
1748 dev_err(&adapter->netdev->dev,
1749 "RcvQ Empty!! rcvq[%p] count[%x]\n", rcvq, rcvq->count);
1752 while (rcvq->count < SLIC_RCVQ_FILLTHRESH) {
1753 count = slic_rcvqueue_fill(adapter);
1762 static u32 slic_rcvqueue_reinsert(struct adapter *adapter, struct sk_buff *skb)
1764 struct slic_rcvqueue *rcvq = &adapter->rcvqueue;
1768 struct slic_rcvbuf *rcvbuf = (struct slic_rcvbuf *)skb->head;
1771 paddr = (void *)(unsigned long)
1772 pci_map_single(adapter->pcidev, skb->head,
1773 SLIC_RCVQ_RCVBUFSIZE, PCI_DMA_FROMDEVICE);
1777 paddrl = SLIC_GET_ADDR_LOW(paddr);
1778 paddrh = SLIC_GET_ADDR_HIGH(paddr);
1781 dev = &adapter->netdev->dev;
1782 dev_err(dev, "%s: LOW 32bits PHYSICAL ADDRESS == 0\n",
1784 dev_err(dev, "skb[%p] PROBLEM\n", skb);
1785 dev_err(dev, " skbdata[%p]\n", skb->data);
1786 dev_err(dev, " skblen[%x]\n", skb->len);
1787 dev_err(dev, " paddr[%p]\n", paddr);
1788 dev_err(dev, " paddrl[%x]\n", paddrl);
1789 dev_err(dev, " paddrh[%x]\n", paddrh);
1790 dev_err(dev, " rcvq->head[%p]\n", rcvq->head);
1791 dev_err(dev, " rcvq->tail[%p]\n", rcvq->tail);
1792 dev_err(dev, " rcvq->count[%x]\n", rcvq->count);
1795 slic_reg32_write(&adapter->slic_regs->slic_hbar, (u32)paddrl,
1798 slic_reg64_write(adapter, &adapter->slic_regs->slic_hbar64,
1799 paddrl, &adapter->slic_regs->slic_addr_upper,
1800 paddrh, DONT_FLUSH);
1803 rcvq->tail->next = skb;
1811 static int slic_debug_card_show(struct seq_file *seq, void *v)
1815 struct sliccard *card = seq->private;
1816 struct slic_config *config = &card->config;
1817 unsigned char *fru = (unsigned char *)(&card->config.atk_fru);
1818 unsigned char *oemfru = (unsigned char *)(&card->config.OemFru);
1821 seq_printf(seq, "driver_version : %s\n", slic_proc_version);
1822 seq_puts(seq, "Microcode versions:\n");
1823 seq_printf(seq, " Gigabit (gb) : %s %s\n",
1824 MOJAVE_UCODE_VERS_STRING, MOJAVE_UCODE_VERS_DATE);
1825 seq_printf(seq, " Gigabit Receiver : %s %s\n",
1826 GB_RCVUCODE_VERS_STRING, GB_RCVUCODE_VERS_DATE);
1827 seq_printf(seq, "Vendor : %s\n", slic_vendor);
1828 seq_printf(seq, "Product Name : %s\n", slic_product_name);
1830 seq_printf(seq, "VendorId : %4.4X\n",
1832 seq_printf(seq, "DeviceId : %4.4X\n",
1834 seq_printf(seq, "RevisionId : %2.2x\n",
1835 config->RevisionId);
1836 seq_printf(seq, "Bus # : %d\n", card->busnumber);
1837 seq_printf(seq, "Device # : %d\n", card->slotnumber);
1838 seq_printf(seq, "Interfaces : %d\n", card->card_size);
1839 seq_printf(seq, " Initialized : %d\n",
1840 card->adapters_activated);
1841 seq_printf(seq, " Allocated : %d\n",
1842 card->adapters_allocated);
1843 for (i = 0; i < card->card_size; i++) {
1845 " MAC%d : %2.2X %2.2X %2.2X %2.2X %2.2X %2.2X\n",
1846 i, config->macinfo[i].macaddrA[0],
1847 config->macinfo[i].macaddrA[1],
1848 config->macinfo[i].macaddrA[2],
1849 config->macinfo[i].macaddrA[3],
1850 config->macinfo[i].macaddrA[4],
1851 config->macinfo[i].macaddrA[5]);
1853 seq_puts(seq, " IF Init State Duplex/Speed irq\n");
1854 seq_puts(seq, " -------------------------------\n");
1855 for (i = 0; i < card->adapters_allocated; i++) {
1856 struct adapter *adapter;
1858 adapter = card->adapter[i];
1861 " %d %d %s %s %s 0x%X\n",
1862 adapter->physport, adapter->state,
1863 SLIC_LINKSTATE(adapter->linkstate),
1864 SLIC_DUPLEX(adapter->linkduplex),
1865 SLIC_SPEED(adapter->linkspeed),
1866 (uint) adapter->irq);
1869 seq_printf(seq, "Generation # : %4.4X\n", card->gennumber);
1870 seq_printf(seq, "RcvQ max entries : %4.4X\n",
1872 seq_printf(seq, "Ping Status : %8.8X\n",
1874 seq_printf(seq, "Minimum grant : %2.2x\n",
1876 seq_printf(seq, "Maximum Latency : %2.2x\n", config->MaxLat);
1877 seq_printf(seq, "PciStatus : %4.4x\n",
1879 seq_printf(seq, "Debug Device Id : %4.4x\n",
1881 seq_printf(seq, "DRAM ROM Function : %4.4x\n",
1883 seq_printf(seq, "Network interface Pin 1 : %2.2x\n",
1884 config->NetIntPin1);
1885 seq_printf(seq, "Network interface Pin 2 : %2.2x\n",
1886 config->NetIntPin1);
1887 seq_printf(seq, "Network interface Pin 3 : %2.2x\n",
1888 config->NetIntPin1);
1889 seq_printf(seq, "PM capabilities : %4.4X\n",
1891 seq_printf(seq, "Network Clock Controls : %4.4X\n",
1892 config->NwClkCtrls);
1894 switch (config->FruFormat) {
1895 case ATK_FRU_FORMAT:
1898 "Vendor : Alacritech, Inc.\n");
1900 "Assembly # : %c%c%c%c%c%c\n",
1901 fru[0], fru[1], fru[2], fru[3], fru[4],
1904 "Revision # : %c%c\n",
1907 if (config->OEMFruFormat == VENDOR4_FRU_FORMAT) {
1909 "Serial # : %c%c%c%c%c%c%c%c%c%c%c%c\n",
1910 fru[8], fru[9], fru[10],
1911 fru[11], fru[12], fru[13],
1912 fru[16], fru[17], fru[18],
1913 fru[19], fru[20], fru[21]);
1916 "Serial # : %c%c%c%c%c%c%c%c%c%c%c%c%c%c\n",
1917 fru[8], fru[9], fru[10],
1918 fru[11], fru[12], fru[13],
1919 fru[14], fru[15], fru[16],
1920 fru[17], fru[18], fru[19],
1929 "Vendor : Alacritech, Inc.\n");
1931 "Serial # : Empty FRU\n");
1936 switch (config->OEMFruFormat) {
1937 case VENDOR1_FRU_FORMAT:
1939 seq_puts(seq, "FRU Information:\n");
1940 seq_printf(seq, " Commodity # : %c\n",
1943 " Assembly # : %c%c%c%c\n",
1944 oemfru[1], oemfru[2], oemfru[3], oemfru[4]);
1946 " Revision # : %c%c\n",
1947 oemfru[5], oemfru[6]);
1949 " Supplier # : %c%c\n",
1950 oemfru[7], oemfru[8]);
1953 oemfru[9], oemfru[10]);
1955 " Sequence # : %c%c%c\n",
1956 oemfru[11], oemfru[12], oemfru[13]);
1960 case VENDOR2_FRU_FORMAT:
1962 seq_puts(seq, "FRU Information:\n");
1964 " Part # : %c%c%c%c%c%c%c%c\n",
1965 oemfru[0], oemfru[1], oemfru[2],
1966 oemfru[3], oemfru[4], oemfru[5],
1967 oemfru[6], oemfru[7]);
1969 " Supplier # : %c%c%c%c%c\n",
1970 oemfru[8], oemfru[9], oemfru[10],
1971 oemfru[11], oemfru[12]);
1974 oemfru[13], oemfru[14], oemfru[15]);
1976 " Sequence # : %c%c%c%c\n",
1977 oemfru[16], oemfru[17], oemfru[18],
1982 case VENDOR3_FRU_FORMAT:
1984 seq_puts(seq, "FRU Information:\n");
1987 case VENDOR4_FRU_FORMAT:
1989 seq_puts(seq, "FRU Information:\n");
1991 " FRU Number : %c%c%c%c%c%c%c%c\n",
1992 oemfru[0], oemfru[1], oemfru[2],
1993 oemfru[3], oemfru[4], oemfru[5],
1994 oemfru[6], oemfru[7]);
1996 " Part Number : %c%c%c%c%c%c%c%c\n",
1997 oemfru[8], oemfru[9], oemfru[10],
1998 oemfru[11], oemfru[12], oemfru[13],
1999 oemfru[14], oemfru[15]);
2001 " EC Level : %c%c%c%c%c%c%c%c\n",
2002 oemfru[16], oemfru[17], oemfru[18],
2003 oemfru[19], oemfru[20], oemfru[21],
2004 oemfru[22], oemfru[23]);
2016 static int slic_debug_adapter_show(struct seq_file *seq, void *v)
2018 struct adapter *adapter = seq->private;
2019 struct net_device *netdev = adapter->netdev;
2021 seq_printf(seq, "info: interface : %s\n",
2022 adapter->netdev->name);
2023 seq_printf(seq, "info: status : %s\n",
2024 SLIC_LINKSTATE(adapter->linkstate));
2025 seq_printf(seq, "info: port : %d\n",
2027 seq_printf(seq, "info: speed : %s\n",
2028 SLIC_SPEED(adapter->linkspeed));
2029 seq_printf(seq, "info: duplex : %s\n",
2030 SLIC_DUPLEX(adapter->linkduplex));
2031 seq_printf(seq, "info: irq : 0x%X\n",
2032 (uint) adapter->irq);
2033 seq_printf(seq, "info: Interrupt Agg Delay: %d usec\n",
2034 adapter->card->loadlevel_current);
2035 seq_printf(seq, "info: RcvQ max entries : %4.4X\n",
2037 seq_printf(seq, "info: RcvQ current : %4.4X\n",
2038 adapter->rcvqueue.count);
2039 seq_printf(seq, "rx stats: packets : %8.8lX\n",
2040 netdev->stats.rx_packets);
2041 seq_printf(seq, "rx stats: bytes : %8.8lX\n",
2042 netdev->stats.rx_bytes);
2043 seq_printf(seq, "rx stats: broadcasts : %8.8X\n",
2044 adapter->rcv_broadcasts);
2045 seq_printf(seq, "rx stats: multicasts : %8.8X\n",
2046 adapter->rcv_multicasts);
2047 seq_printf(seq, "rx stats: unicasts : %8.8X\n",
2048 adapter->rcv_unicasts);
2049 seq_printf(seq, "rx stats: errors : %8.8X\n",
2050 (u32) adapter->slic_stats.iface.rcv_errors);
2051 seq_printf(seq, "rx stats: Missed errors : %8.8X\n",
2052 (u32) adapter->slic_stats.iface.rcv_discards);
2053 seq_printf(seq, "rx stats: drops : %8.8X\n",
2054 (u32) adapter->rcv_drops);
2055 seq_printf(seq, "tx stats: packets : %8.8lX\n",
2056 netdev->stats.tx_packets);
2057 seq_printf(seq, "tx stats: bytes : %8.8lX\n",
2058 netdev->stats.tx_bytes);
2059 seq_printf(seq, "tx stats: errors : %8.8X\n",
2060 (u32) adapter->slic_stats.iface.xmt_errors);
2061 seq_printf(seq, "rx stats: multicasts : %8.8lX\n",
2062 netdev->stats.multicast);
2063 seq_printf(seq, "tx stats: collision errors : %8.8X\n",
2064 (u32) adapter->slic_stats.iface.xmit_collisions);
2065 seq_printf(seq, "perf: Max rcv frames/isr : %8.8X\n",
2066 adapter->max_isr_rcvs);
2067 seq_printf(seq, "perf: Rcv interrupt yields : %8.8X\n",
2068 adapter->rcv_interrupt_yields);
2069 seq_printf(seq, "perf: Max xmit complete/isr : %8.8X\n",
2070 adapter->max_isr_xmits);
2071 seq_printf(seq, "perf: error interrupts : %8.8X\n",
2072 adapter->error_interrupts);
2073 seq_printf(seq, "perf: error rmiss interrupts : %8.8X\n",
2074 adapter->error_rmiss_interrupts);
2075 seq_printf(seq, "perf: rcv interrupts : %8.8X\n",
2076 adapter->rcv_interrupts);
2077 seq_printf(seq, "perf: xmit interrupts : %8.8X\n",
2078 adapter->xmit_interrupts);
2079 seq_printf(seq, "perf: link event interrupts : %8.8X\n",
2080 adapter->linkevent_interrupts);
2081 seq_printf(seq, "perf: UPR interrupts : %8.8X\n",
2082 adapter->upr_interrupts);
2083 seq_printf(seq, "perf: interrupt count : %8.8X\n",
2085 seq_printf(seq, "perf: false interrupts : %8.8X\n",
2086 adapter->false_interrupts);
2087 seq_printf(seq, "perf: All register writes : %8.8X\n",
2088 adapter->all_reg_writes);
2089 seq_printf(seq, "perf: ICR register writes : %8.8X\n",
2090 adapter->icr_reg_writes);
2091 seq_printf(seq, "perf: ISR register writes : %8.8X\n",
2092 adapter->isr_reg_writes);
2093 seq_printf(seq, "ifevents: overflow 802 errors : %8.8X\n",
2094 adapter->if_events.oflow802);
2095 seq_printf(seq, "ifevents: transport overflow errors: %8.8X\n",
2096 adapter->if_events.Tprtoflow);
2097 seq_printf(seq, "ifevents: underflow errors : %8.8X\n",
2098 adapter->if_events.uflow802);
2099 seq_printf(seq, "ifevents: receive early : %8.8X\n",
2100 adapter->if_events.rcvearly);
2101 seq_printf(seq, "ifevents: buffer overflows : %8.8X\n",
2102 adapter->if_events.Bufov);
2103 seq_printf(seq, "ifevents: carrier errors : %8.8X\n",
2104 adapter->if_events.Carre);
2105 seq_printf(seq, "ifevents: Long : %8.8X\n",
2106 adapter->if_events.Longe);
2107 seq_printf(seq, "ifevents: invalid preambles : %8.8X\n",
2108 adapter->if_events.Invp);
2109 seq_printf(seq, "ifevents: CRC errors : %8.8X\n",
2110 adapter->if_events.Crc);
2111 seq_printf(seq, "ifevents: dribble nibbles : %8.8X\n",
2112 adapter->if_events.Drbl);
2113 seq_printf(seq, "ifevents: Code violations : %8.8X\n",
2114 adapter->if_events.Code);
2115 seq_printf(seq, "ifevents: TCP checksum errors : %8.8X\n",
2116 adapter->if_events.TpCsum);
2117 seq_printf(seq, "ifevents: TCP header short errors : %8.8X\n",
2118 adapter->if_events.TpHlen);
2119 seq_printf(seq, "ifevents: IP checksum errors : %8.8X\n",
2120 adapter->if_events.IpCsum);
2121 seq_printf(seq, "ifevents: IP frame incompletes : %8.8X\n",
2122 adapter->if_events.IpLen);
2123 seq_printf(seq, "ifevents: IP headers shorts : %8.8X\n",
2124 adapter->if_events.IpHlen);
2128 static int slic_debug_adapter_open(struct inode *inode, struct file *file)
2130 return single_open(file, slic_debug_adapter_show, inode->i_private);
2133 static int slic_debug_card_open(struct inode *inode, struct file *file)
2135 return single_open(file, slic_debug_card_show, inode->i_private);
2138 static const struct file_operations slic_debug_adapter_fops = {
2139 .owner = THIS_MODULE,
2140 .open = slic_debug_adapter_open,
2142 .llseek = seq_lseek,
2143 .release = single_release,
2146 static const struct file_operations slic_debug_card_fops = {
2147 .owner = THIS_MODULE,
2148 .open = slic_debug_card_open,
2150 .llseek = seq_lseek,
2151 .release = single_release,
2154 static void slic_debug_adapter_create(struct adapter *adapter)
2158 struct sliccard *card = adapter->card;
2160 if (!card->debugfs_dir)
2163 sprintf(name, "port%d", adapter->port);
2164 d = debugfs_create_file(name, S_IRUGO,
2165 card->debugfs_dir, adapter,
2166 &slic_debug_adapter_fops);
2167 if (!d || IS_ERR(d))
2168 pr_info(PFX "%s: debugfs create failed\n", name);
2170 adapter->debugfs_entry = d;
2173 static void slic_debug_adapter_destroy(struct adapter *adapter)
2175 debugfs_remove(adapter->debugfs_entry);
2176 adapter->debugfs_entry = NULL;
2179 static void slic_debug_card_create(struct sliccard *card)
2182 char name[IFNAMSIZ];
2184 snprintf(name, sizeof(name), "slic%d", card->cardnum);
2185 d = debugfs_create_dir(name, slic_debugfs);
2186 if (!d || IS_ERR(d))
2187 pr_info(PFX "%s: debugfs create dir failed\n",
2190 card->debugfs_dir = d;
2191 d = debugfs_create_file("cardinfo", S_IRUGO,
2193 &slic_debug_card_fops);
2194 if (!d || IS_ERR(d))
2195 pr_info(PFX "%s: debugfs create failed\n",
2198 card->debugfs_cardinfo = d;
2202 static void slic_debug_card_destroy(struct sliccard *card)
2206 for (i = 0; i < card->card_size; i++) {
2207 struct adapter *adapter;
2209 adapter = card->adapter[i];
2211 slic_debug_adapter_destroy(adapter);
2213 debugfs_remove(card->debugfs_cardinfo);
2214 debugfs_remove(card->debugfs_dir);
2217 static void slic_debug_init(void)
2221 ent = debugfs_create_dir("slic", NULL);
2222 if (!ent || IS_ERR(ent)) {
2223 pr_info(PFX "debugfs create directory failed\n");
2230 static void slic_debug_cleanup(void)
2232 debugfs_remove(slic_debugfs);
2236 * slic_link_event_handler -
2238 * Initiate a link configuration sequence. The link configuration begins
2239 * by issuing a READ_LINK_STATUS command to the Utility Processor on the
2240 * SLIC. Since the command finishes asynchronously, the slic_upr_comlete
2241 * routine will follow it up witha UP configuration write command, which
2242 * will also complete asynchronously.
2245 static void slic_link_event_handler(struct adapter *adapter)
2248 struct slic_shmem *pshmem;
2250 if (adapter->state != ADAPT_UP) {
2251 /* Adapter is not operational. Ignore. */
2255 pshmem = (struct slic_shmem *)(unsigned long)adapter->phys_shmem;
2257 #if BITS_PER_LONG == 64
2258 status = slic_upr_request(adapter,
2260 SLIC_GET_ADDR_LOW(&pshmem->linkstatus),
2261 SLIC_GET_ADDR_HIGH(&pshmem->linkstatus),
2264 status = slic_upr_request(adapter, SLIC_UPR_RLSR,
2265 (u32) &pshmem->linkstatus, /* no 4GB wrap guaranteed */
2270 static void slic_init_cleanup(struct adapter *adapter)
2272 if (adapter->intrregistered) {
2273 adapter->intrregistered = 0;
2274 free_irq(adapter->netdev->irq, adapter->netdev);
2277 if (adapter->pshmem) {
2278 pci_free_consistent(adapter->pcidev,
2279 sizeof(struct slic_shmem),
2280 adapter->pshmem, adapter->phys_shmem);
2281 adapter->pshmem = NULL;
2282 adapter->phys_shmem = (dma_addr_t)(unsigned long)NULL;
2285 if (adapter->pingtimerset) {
2286 adapter->pingtimerset = 0;
2287 del_timer(&adapter->pingtimer);
2290 slic_rspqueue_free(adapter);
2291 slic_cmdq_free(adapter);
2292 slic_rcvqueue_free(adapter);
2296 * Allocate a mcast_address structure to hold the multicast address.
2299 static int slic_mcast_add_list(struct adapter *adapter, char *address)
2301 struct mcast_address *mcaddr, *mlist;
2303 /* Check to see if it already exists */
2304 mlist = adapter->mcastaddrs;
2306 if (ether_addr_equal(mlist->address, address))
2308 mlist = mlist->next;
2311 /* Doesn't already exist. Allocate a structure to hold it */
2312 mcaddr = kmalloc(sizeof(struct mcast_address), GFP_ATOMIC);
2316 memcpy(mcaddr->address, address, ETH_ALEN);
2318 mcaddr->next = adapter->mcastaddrs;
2319 adapter->mcastaddrs = mcaddr;
2324 static void slic_mcast_set_list(struct net_device *dev)
2326 struct adapter *adapter = netdev_priv(dev);
2329 struct netdev_hw_addr *ha;
2331 netdev_for_each_mc_addr(ha, dev) {
2332 addresses = (char *) &ha->addr;
2333 status = slic_mcast_add_list(adapter, addresses);
2336 slic_mcast_set_bit(adapter, addresses);
2339 if (adapter->devflags_prev != dev->flags) {
2340 adapter->macopts = MAC_DIRECTED;
2342 if (dev->flags & IFF_BROADCAST)
2343 adapter->macopts |= MAC_BCAST;
2344 if (dev->flags & IFF_PROMISC)
2345 adapter->macopts |= MAC_PROMISC;
2346 if (dev->flags & IFF_ALLMULTI)
2347 adapter->macopts |= MAC_ALLMCAST;
2348 if (dev->flags & IFF_MULTICAST)
2349 adapter->macopts |= MAC_MCAST;
2351 adapter->devflags_prev = dev->flags;
2352 slic_config_set(adapter, true);
2355 slic_mcast_set_mask(adapter);
2359 #define XMIT_FAIL_LINK_STATE 1
2360 #define XMIT_FAIL_ZERO_LENGTH 2
2361 #define XMIT_FAIL_HOSTCMD_FAIL 3
2363 static void slic_xmit_build_request(struct adapter *adapter,
2364 struct slic_hostcmd *hcmd, struct sk_buff *skb)
2366 struct slic_host64_cmd *ihcmd;
2369 ihcmd = &hcmd->cmd64;
2371 ihcmd->flags = (adapter->port << IHFLG_IFSHFT);
2372 ihcmd->command = IHCMD_XMT_REQ;
2373 ihcmd->u.slic_buffers.totlen = skb->len;
2374 phys_addr = pci_map_single(adapter->pcidev, skb->data, skb->len,
2376 ihcmd->u.slic_buffers.bufs[0].paddrl = SLIC_GET_ADDR_LOW(phys_addr);
2377 ihcmd->u.slic_buffers.bufs[0].paddrh = SLIC_GET_ADDR_HIGH(phys_addr);
2378 ihcmd->u.slic_buffers.bufs[0].length = skb->len;
2379 #if BITS_PER_LONG == 64
2380 hcmd->cmdsize = (u32) ((((u64)&ihcmd->u.slic_buffers.bufs[1] -
2381 (u64) hcmd) + 31) >> 5);
2383 hcmd->cmdsize = ((((u32) &ihcmd->u.slic_buffers.bufs[1] -
2384 (u32) hcmd) + 31) >> 5);
2388 static void slic_xmit_fail(struct adapter *adapter,
2389 struct sk_buff *skb,
2390 void *cmd, u32 skbtype, u32 status)
2392 if (adapter->xmitq_full)
2393 netif_stop_queue(adapter->netdev);
2394 if ((cmd == NULL) && (status <= XMIT_FAIL_HOSTCMD_FAIL)) {
2396 case XMIT_FAIL_LINK_STATE:
2397 dev_err(&adapter->netdev->dev,
2398 "reject xmit skb[%p: %x] linkstate[%s] adapter[%s:%d] card[%s:%d]\n",
2400 SLIC_LINKSTATE(adapter->linkstate),
2401 SLIC_ADAPTER_STATE(adapter->state),
2403 SLIC_CARD_STATE(adapter->card->state),
2404 adapter->card->state);
2406 case XMIT_FAIL_ZERO_LENGTH:
2407 dev_err(&adapter->netdev->dev,
2408 "xmit_start skb->len == 0 skb[%p] type[%x]\n",
2409 skb, skb->pkt_type);
2411 case XMIT_FAIL_HOSTCMD_FAIL:
2412 dev_err(&adapter->netdev->dev,
2413 "xmit_start skb[%p] type[%x] No host commands available\n", skb, skb->pkt_type);
2418 adapter->netdev->stats.tx_dropped++;
2421 static void slic_rcv_handle_error(struct adapter *adapter,
2422 struct slic_rcvbuf *rcvbuf)
2424 struct slic_hddr_wds *hdr = (struct slic_hddr_wds *)rcvbuf->data;
2425 struct net_device *netdev = adapter->netdev;
2427 if (adapter->devid != SLIC_1GB_DEVICE_ID) {
2428 if (hdr->frame_status14 & VRHSTAT_802OE)
2429 adapter->if_events.oflow802++;
2430 if (hdr->frame_status14 & VRHSTAT_TPOFLO)
2431 adapter->if_events.Tprtoflow++;
2432 if (hdr->frame_status_b14 & VRHSTATB_802UE)
2433 adapter->if_events.uflow802++;
2434 if (hdr->frame_status_b14 & VRHSTATB_RCVE) {
2435 adapter->if_events.rcvearly++;
2436 netdev->stats.rx_fifo_errors++;
2438 if (hdr->frame_status_b14 & VRHSTATB_BUFF) {
2439 adapter->if_events.Bufov++;
2440 netdev->stats.rx_over_errors++;
2442 if (hdr->frame_status_b14 & VRHSTATB_CARRE) {
2443 adapter->if_events.Carre++;
2444 netdev->stats.tx_carrier_errors++;
2446 if (hdr->frame_status_b14 & VRHSTATB_LONGE)
2447 adapter->if_events.Longe++;
2448 if (hdr->frame_status_b14 & VRHSTATB_PREA)
2449 adapter->if_events.Invp++;
2450 if (hdr->frame_status_b14 & VRHSTATB_CRC) {
2451 adapter->if_events.Crc++;
2452 netdev->stats.rx_crc_errors++;
2454 if (hdr->frame_status_b14 & VRHSTATB_DRBL)
2455 adapter->if_events.Drbl++;
2456 if (hdr->frame_status_b14 & VRHSTATB_CODE)
2457 adapter->if_events.Code++;
2458 if (hdr->frame_status_b14 & VRHSTATB_TPCSUM)
2459 adapter->if_events.TpCsum++;
2460 if (hdr->frame_status_b14 & VRHSTATB_TPHLEN)
2461 adapter->if_events.TpHlen++;
2462 if (hdr->frame_status_b14 & VRHSTATB_IPCSUM)
2463 adapter->if_events.IpCsum++;
2464 if (hdr->frame_status_b14 & VRHSTATB_IPLERR)
2465 adapter->if_events.IpLen++;
2466 if (hdr->frame_status_b14 & VRHSTATB_IPHERR)
2467 adapter->if_events.IpHlen++;
2469 if (hdr->frame_statusGB & VGBSTAT_XPERR) {
2470 u32 xerr = hdr->frame_statusGB >> VGBSTAT_XERRSHFT;
2472 if (xerr == VGBSTAT_XCSERR)
2473 adapter->if_events.TpCsum++;
2474 if (xerr == VGBSTAT_XUFLOW)
2475 adapter->if_events.Tprtoflow++;
2476 if (xerr == VGBSTAT_XHLEN)
2477 adapter->if_events.TpHlen++;
2479 if (hdr->frame_statusGB & VGBSTAT_NETERR) {
2482 frame_statusGB >> VGBSTAT_NERRSHFT) &
2484 if (nerr == VGBSTAT_NCSERR)
2485 adapter->if_events.IpCsum++;
2486 if (nerr == VGBSTAT_NUFLOW)
2487 adapter->if_events.IpLen++;
2488 if (nerr == VGBSTAT_NHLEN)
2489 adapter->if_events.IpHlen++;
2491 if (hdr->frame_statusGB & VGBSTAT_LNKERR) {
2492 u32 lerr = hdr->frame_statusGB & VGBSTAT_LERRMSK;
2494 if (lerr == VGBSTAT_LDEARLY)
2495 adapter->if_events.rcvearly++;
2496 if (lerr == VGBSTAT_LBOFLO)
2497 adapter->if_events.Bufov++;
2498 if (lerr == VGBSTAT_LCODERR)
2499 adapter->if_events.Code++;
2500 if (lerr == VGBSTAT_LDBLNBL)
2501 adapter->if_events.Drbl++;
2502 if (lerr == VGBSTAT_LCRCERR)
2503 adapter->if_events.Crc++;
2504 if (lerr == VGBSTAT_LOFLO)
2505 adapter->if_events.oflow802++;
2506 if (lerr == VGBSTAT_LUFLO)
2507 adapter->if_events.uflow802++;
2513 #define TCP_OFFLOAD_FRAME_PUSHFLAG 0x10000000
2514 #define M_FAST_PATH 0x0040
2516 static void slic_rcv_handler(struct adapter *adapter)
2518 struct net_device *netdev = adapter->netdev;
2519 struct sk_buff *skb;
2520 struct slic_rcvbuf *rcvbuf;
2523 while ((skb = slic_rcvqueue_getnext(adapter))) {
2526 rcvbuf = (struct slic_rcvbuf *)skb->head;
2527 adapter->card->events++;
2528 if (rcvbuf->status & IRHDDR_ERR) {
2529 adapter->rx_errors++;
2530 slic_rcv_handle_error(adapter, rcvbuf);
2531 slic_rcvqueue_reinsert(adapter, skb);
2535 if (!slic_mac_filter(adapter, (struct ether_header *)
2537 slic_rcvqueue_reinsert(adapter, skb);
2540 skb_pull(skb, SLIC_RCVBUF_HEADSIZE);
2541 rx_bytes = (rcvbuf->length & IRHDDR_FLEN_MSK);
2542 skb_put(skb, rx_bytes);
2543 netdev->stats.rx_packets++;
2544 netdev->stats.rx_bytes += rx_bytes;
2545 #if SLIC_OFFLOAD_IP_CHECKSUM
2546 skb->ip_summed = CHECKSUM_UNNECESSARY;
2549 skb->dev = adapter->netdev;
2550 skb->protocol = eth_type_trans(skb, skb->dev);
2554 #if SLIC_INTERRUPT_PROCESS_LIMIT
2555 if (frames >= SLIC_RCVQ_MAX_PROCESS_ISR) {
2556 adapter->rcv_interrupt_yields++;
2561 adapter->max_isr_rcvs = max(adapter->max_isr_rcvs, frames);
2564 static void slic_xmit_complete(struct adapter *adapter)
2566 struct slic_hostcmd *hcmd;
2567 struct slic_rspbuf *rspbuf;
2569 struct slic_handle_word slic_handle_word;
2572 rspbuf = slic_rspqueue_getnext(adapter);
2575 adapter->xmit_completes++;
2576 adapter->card->events++;
2578 Get the complete host command buffer
2580 slic_handle_word.handle_token = rspbuf->hosthandle;
2582 (struct slic_hostcmd *)
2583 adapter->slic_handles[slic_handle_word.handle_index].
2585 /* hcmd = (struct slic_hostcmd *) rspbuf->hosthandle; */
2586 if (hcmd->type == SLIC_CMD_DUMB) {
2588 dev_kfree_skb_irq(hcmd->skb);
2589 slic_cmdq_putdone_irq(adapter, hcmd);
2592 rspbuf->hosthandle = 0;
2595 adapter->max_isr_xmits = max(adapter->max_isr_xmits, frames);
2598 static void slic_interrupt_card_up(u32 isr, struct adapter *adapter,
2599 struct net_device *dev)
2601 if (isr & ~ISR_IO) {
2602 if (isr & ISR_ERR) {
2603 adapter->error_interrupts++;
2604 if (isr & ISR_RMISS) {
2609 struct slic_rcvqueue *rcvq =
2612 adapter->error_rmiss_interrupts++;
2615 rcv_count = rcvq->count;
2616 pre_count = rcvq->count;
2617 errors = rcvq->errors;
2619 while (rcvq->count < SLIC_RCVQ_FILLTHRESH) {
2620 count = slic_rcvqueue_fill(adapter);
2624 } else if (isr & ISR_XDROP) {
2626 "isr & ISR_ERR [%x] ISR_XDROP\n", isr);
2629 "isr & ISR_ERR [%x]\n",
2634 if (isr & ISR_LEVENT) {
2635 adapter->linkevent_interrupts++;
2636 slic_link_event_handler(adapter);
2639 if ((isr & ISR_UPC) || (isr & ISR_UPCERR) ||
2640 (isr & ISR_UPCBSY)) {
2641 adapter->upr_interrupts++;
2642 slic_upr_request_complete(adapter, isr);
2646 if (isr & ISR_RCV) {
2647 adapter->rcv_interrupts++;
2648 slic_rcv_handler(adapter);
2651 if (isr & ISR_CMD) {
2652 adapter->xmit_interrupts++;
2653 slic_xmit_complete(adapter);
2658 static irqreturn_t slic_interrupt(int irq, void *dev_id)
2660 struct net_device *dev = (struct net_device *)dev_id;
2661 struct adapter *adapter = netdev_priv(dev);
2664 if ((adapter->pshmem) && (adapter->pshmem->isr)) {
2665 slic_reg32_write(&adapter->slic_regs->slic_icr,
2666 ICR_INT_MASK, FLUSH);
2667 isr = adapter->isrcopy = adapter->pshmem->isr;
2668 adapter->pshmem->isr = 0;
2669 adapter->num_isrs++;
2670 switch (adapter->card->state) {
2672 slic_interrupt_card_up(isr, adapter, dev);
2676 if ((isr & ISR_UPC) ||
2677 (isr & ISR_UPCERR) || (isr & ISR_UPCBSY)) {
2678 adapter->upr_interrupts++;
2679 slic_upr_request_complete(adapter, isr);
2684 adapter->isrcopy = 0;
2685 adapter->all_reg_writes += 2;
2686 adapter->isr_reg_writes++;
2687 slic_reg32_write(&adapter->slic_regs->slic_isr, 0, FLUSH);
2689 adapter->false_interrupts++;
2694 #define NORMAL_ETHFRAME 0
2696 static netdev_tx_t slic_xmit_start(struct sk_buff *skb, struct net_device *dev)
2698 struct sliccard *card;
2699 struct adapter *adapter = netdev_priv(dev);
2700 struct slic_hostcmd *hcmd = NULL;
2702 void *offloadcmd = NULL;
2704 card = adapter->card;
2705 if ((adapter->linkstate != LINK_UP) ||
2706 (adapter->state != ADAPT_UP) || (card->state != CARD_UP)) {
2707 status = XMIT_FAIL_LINK_STATE;
2710 } else if (skb->len == 0) {
2711 status = XMIT_FAIL_ZERO_LENGTH;
2715 hcmd = slic_cmdq_getfree(adapter);
2717 adapter->xmitq_full = 1;
2718 status = XMIT_FAIL_HOSTCMD_FAIL;
2723 hcmd->type = SLIC_CMD_DUMB;
2724 slic_xmit_build_request(adapter, hcmd, skb);
2725 dev->stats.tx_packets++;
2726 dev->stats.tx_bytes += skb->len;
2729 if (adapter->kill_card) {
2730 struct slic_host64_cmd ihcmd;
2732 ihcmd = &hcmd->cmd64;
2734 ihcmd->flags |= 0x40;
2735 adapter->kill_card = 0; /* only do this once */
2738 if (hcmd->paddrh == 0) {
2739 slic_reg32_write(&adapter->slic_regs->slic_cbar,
2740 (hcmd->paddrl | hcmd->cmdsize), DONT_FLUSH);
2742 slic_reg64_write(adapter, &adapter->slic_regs->slic_cbar64,
2743 (hcmd->paddrl | hcmd->cmdsize),
2744 &adapter->slic_regs->slic_addr_upper,
2745 hcmd->paddrh, DONT_FLUSH);
2748 return NETDEV_TX_OK;
2750 slic_xmit_fail(adapter, skb, offloadcmd, NORMAL_ETHFRAME, status);
2755 static void slic_adapter_freeresources(struct adapter *adapter)
2757 slic_init_cleanup(adapter);
2758 adapter->error_interrupts = 0;
2759 adapter->rcv_interrupts = 0;
2760 adapter->xmit_interrupts = 0;
2761 adapter->linkevent_interrupts = 0;
2762 adapter->upr_interrupts = 0;
2763 adapter->num_isrs = 0;
2764 adapter->xmit_completes = 0;
2765 adapter->rcv_broadcasts = 0;
2766 adapter->rcv_multicasts = 0;
2767 adapter->rcv_unicasts = 0;
2770 static int slic_adapter_allocresources(struct adapter *adapter)
2772 if (!adapter->intrregistered) {
2775 spin_unlock_irqrestore(&slic_global.driver_lock.lock,
2776 slic_global.driver_lock.flags);
2778 retval = request_irq(adapter->netdev->irq,
2781 adapter->netdev->name, adapter->netdev);
2783 spin_lock_irqsave(&slic_global.driver_lock.lock,
2784 slic_global.driver_lock.flags);
2787 dev_err(&adapter->netdev->dev,
2788 "request_irq (%s) FAILED [%x]\n",
2789 adapter->netdev->name, retval);
2792 adapter->intrregistered = 1;
2800 * Perform initialization of our slic interface.
2803 static int slic_if_init(struct adapter *adapter)
2805 struct sliccard *card = adapter->card;
2806 struct net_device *dev = adapter->netdev;
2807 __iomem struct slic_regs *slic_regs = adapter->slic_regs;
2808 struct slic_shmem *pshmem;
2811 /* adapter should be down at this point */
2812 if (adapter->state != ADAPT_DOWN) {
2813 dev_err(&dev->dev, "%s: adapter->state != ADAPT_DOWN\n",
2819 adapter->devflags_prev = dev->flags;
2820 adapter->macopts = MAC_DIRECTED;
2822 if (dev->flags & IFF_BROADCAST)
2823 adapter->macopts |= MAC_BCAST;
2824 if (dev->flags & IFF_PROMISC)
2825 adapter->macopts |= MAC_PROMISC;
2826 if (dev->flags & IFF_ALLMULTI)
2827 adapter->macopts |= MAC_ALLMCAST;
2828 if (dev->flags & IFF_MULTICAST)
2829 adapter->macopts |= MAC_MCAST;
2831 rc = slic_adapter_allocresources(adapter);
2834 "%s: slic_adapter_allocresources FAILED %x\n",
2836 slic_adapter_freeresources(adapter);
2840 if (!adapter->queues_initialized) {
2841 rc = slic_rspqueue_init(adapter);
2844 rc = slic_cmdq_init(adapter);
2847 rc = slic_rcvqueue_init(adapter);
2850 adapter->queues_initialized = 1;
2853 slic_reg32_write(&slic_regs->slic_icr, ICR_INT_OFF, FLUSH);
2856 if (!adapter->isp_initialized) {
2857 pshmem = (struct slic_shmem *)(unsigned long)
2858 adapter->phys_shmem;
2860 spin_lock_irqsave(&adapter->bit64reglock.lock,
2861 adapter->bit64reglock.flags);
2863 #if BITS_PER_LONG == 64
2864 slic_reg32_write(&slic_regs->slic_addr_upper,
2865 SLIC_GET_ADDR_HIGH(&pshmem->isr), DONT_FLUSH);
2866 slic_reg32_write(&slic_regs->slic_isp,
2867 SLIC_GET_ADDR_LOW(&pshmem->isr), FLUSH);
2869 slic_reg32_write(&slic_regs->slic_addr_upper, 0, DONT_FLUSH);
2870 slic_reg32_write(&slic_regs->slic_isp, (u32)&pshmem->isr, FLUSH);
2872 spin_unlock_irqrestore(&adapter->bit64reglock.lock,
2873 adapter->bit64reglock.flags);
2874 adapter->isp_initialized = 1;
2877 adapter->state = ADAPT_UP;
2878 if (!card->loadtimerset) {
2879 init_timer(&card->loadtimer);
2880 card->loadtimer.expires =
2881 jiffies + (SLIC_LOADTIMER_PERIOD * HZ);
2882 card->loadtimer.data = (ulong) card;
2883 card->loadtimer.function = &slic_timer_load_check;
2884 add_timer(&card->loadtimer);
2886 card->loadtimerset = 1;
2889 if (!adapter->pingtimerset) {
2890 init_timer(&adapter->pingtimer);
2891 adapter->pingtimer.expires =
2892 jiffies + (PING_TIMER_INTERVAL * HZ);
2893 adapter->pingtimer.data = (ulong) dev;
2894 adapter->pingtimer.function = &slic_timer_ping;
2895 add_timer(&adapter->pingtimer);
2896 adapter->pingtimerset = 1;
2897 adapter->card->pingstatus = ISR_PINGMASK;
2901 * clear any pending events, then enable interrupts
2903 adapter->isrcopy = 0;
2904 adapter->pshmem->isr = 0;
2905 slic_reg32_write(&slic_regs->slic_isr, 0, FLUSH);
2906 slic_reg32_write(&slic_regs->slic_icr, ICR_INT_ON, FLUSH);
2908 slic_link_config(adapter, LINK_AUTOSPEED, LINK_AUTOD);
2909 slic_link_event_handler(adapter);
2915 static int slic_entry_open(struct net_device *dev)
2917 struct adapter *adapter = netdev_priv(dev);
2918 struct sliccard *card = adapter->card;
2921 netif_stop_queue(adapter->netdev);
2923 spin_lock_irqsave(&slic_global.driver_lock.lock,
2924 slic_global.driver_lock.flags);
2925 if (!adapter->activated) {
2926 card->adapters_activated++;
2927 slic_global.num_slic_ports_active++;
2928 adapter->activated = 1;
2930 status = slic_if_init(adapter);
2933 if (adapter->activated) {
2934 card->adapters_activated--;
2935 slic_global.num_slic_ports_active--;
2936 adapter->activated = 0;
2941 card->master = adapter;
2944 spin_unlock_irqrestore(&slic_global.driver_lock.lock,
2945 slic_global.driver_lock.flags);
2949 static void slic_card_cleanup(struct sliccard *card)
2951 if (card->loadtimerset) {
2952 card->loadtimerset = 0;
2953 del_timer_sync(&card->loadtimer);
2956 slic_debug_card_destroy(card);
2961 static void slic_entry_remove(struct pci_dev *pcidev)
2963 struct net_device *dev = pci_get_drvdata(pcidev);
2966 struct adapter *adapter = netdev_priv(dev);
2967 struct sliccard *card;
2968 struct mcast_address *mcaddr, *mlist;
2970 slic_adapter_freeresources(adapter);
2971 slic_unmap_mmio_space(adapter);
2972 unregister_netdev(dev);
2974 mmio_start = pci_resource_start(pcidev, 0);
2975 mmio_len = pci_resource_len(pcidev, 0);
2977 release_mem_region(mmio_start, mmio_len);
2979 iounmap((void __iomem *)dev->base_addr);
2980 /* free multicast addresses */
2981 mlist = adapter->mcastaddrs;
2984 mlist = mlist->next;
2987 card = adapter->card;
2988 card->adapters_allocated--;
2989 adapter->allocated = 0;
2990 if (!card->adapters_allocated) {
2991 struct sliccard *curr_card = slic_global.slic_card;
2992 if (curr_card == card) {
2993 slic_global.slic_card = card->next;
2995 while (curr_card->next != card)
2996 curr_card = curr_card->next;
2997 curr_card->next = card->next;
2999 slic_global.num_slic_cards--;
3000 slic_card_cleanup(card);
3003 pci_release_regions(pcidev);
3004 pci_disable_device(pcidev);
3007 static int slic_entry_halt(struct net_device *dev)
3009 struct adapter *adapter = netdev_priv(dev);
3010 struct sliccard *card = adapter->card;
3011 __iomem struct slic_regs *slic_regs = adapter->slic_regs;
3013 spin_lock_irqsave(&slic_global.driver_lock.lock,
3014 slic_global.driver_lock.flags);
3015 netif_stop_queue(adapter->netdev);
3016 adapter->state = ADAPT_DOWN;
3017 adapter->linkstate = LINK_DOWN;
3018 adapter->upr_list = NULL;
3019 adapter->upr_busy = 0;
3020 adapter->devflags_prev = 0;
3021 slic_reg32_write(&slic_regs->slic_icr, ICR_INT_OFF, FLUSH);
3022 adapter->all_reg_writes++;
3023 adapter->icr_reg_writes++;
3024 slic_config_clear(adapter);
3025 if (adapter->activated) {
3026 card->adapters_activated--;
3027 slic_global.num_slic_ports_active--;
3028 adapter->activated = 0;
3030 #ifdef AUTOMATIC_RESET
3031 slic_reg32_write(&slic_regs->slic_reset_iface, 0, FLUSH);
3034 * Reset the adapter's cmd queues
3036 slic_cmdq_reset(adapter);
3038 #ifdef AUTOMATIC_RESET
3039 if (!card->adapters_activated)
3040 slic_card_init(card, adapter);
3043 spin_unlock_irqrestore(&slic_global.driver_lock.lock,
3044 slic_global.driver_lock.flags);
3048 static struct net_device_stats *slic_get_stats(struct net_device *dev)
3050 struct adapter *adapter = netdev_priv(dev);
3052 dev->stats.collisions = adapter->slic_stats.iface.xmit_collisions;
3053 dev->stats.rx_errors = adapter->slic_stats.iface.rcv_errors;
3054 dev->stats.tx_errors = adapter->slic_stats.iface.xmt_errors;
3055 dev->stats.rx_missed_errors = adapter->slic_stats.iface.rcv_discards;
3056 dev->stats.tx_heartbeat_errors = 0;
3057 dev->stats.tx_aborted_errors = 0;
3058 dev->stats.tx_window_errors = 0;
3059 dev->stats.tx_fifo_errors = 0;
3060 dev->stats.rx_frame_errors = 0;
3061 dev->stats.rx_length_errors = 0;
3066 static int slic_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
3068 struct adapter *adapter = netdev_priv(dev);
3069 struct ethtool_cmd edata;
3070 struct ethtool_cmd ecmd;
3075 case SIOCSLICSETINTAGG:
3076 if (copy_from_user(data, rq->ifr_data, 28))
3079 dev_err(&dev->dev, "%s: set interrupt aggregation to %d\n",
3081 slic_intagg_set(adapter, intagg);
3084 #ifdef SLIC_TRACE_DUMP_ENABLED
3085 case SIOCSLICTRACEDUMP:
3088 DBG_IOCTL("slic_ioctl SIOCSLIC_TRACE_DUMP\n");
3090 if (copy_from_user(data, rq->ifr_data, 28)) {
3092 ("slic: copy_from_user FAILED getting initial simba param\n");
3097 if (tracemon_request == SLIC_DUMP_DONE) {
3099 ("ATK Diagnostic Trace Dump Requested\n");
3100 tracemon_request = SLIC_DUMP_REQUESTED;
3101 tracemon_request_type = value;
3102 tracemon_timestamp = jiffies;
3103 } else if ((tracemon_request == SLIC_DUMP_REQUESTED) ||
3104 (tracemon_request ==
3105 SLIC_DUMP_IN_PROGRESS)) {
3107 ("ATK Diagnostic Trace Dump Requested but already in progress... ignore\n");
3110 ("ATK Diagnostic Trace Dump Requested\n");
3111 tracemon_request = SLIC_DUMP_REQUESTED;
3112 tracemon_request_type = value;
3113 tracemon_timestamp = jiffies;
3119 if (copy_from_user(&ecmd, rq->ifr_data, sizeof(ecmd)))
3122 if (ecmd.cmd == ETHTOOL_GSET) {
3123 memset(&edata, 0, sizeof(edata));
3124 edata.supported = (SUPPORTED_10baseT_Half |
3125 SUPPORTED_10baseT_Full |
3126 SUPPORTED_100baseT_Half |
3127 SUPPORTED_100baseT_Full |
3128 SUPPORTED_Autoneg | SUPPORTED_MII);
3129 edata.port = PORT_MII;
3130 edata.transceiver = XCVR_INTERNAL;
3131 edata.phy_address = 0;
3132 if (adapter->linkspeed == LINK_100MB)
3133 edata.speed = SPEED_100;
3134 else if (adapter->linkspeed == LINK_10MB)
3135 edata.speed = SPEED_10;
3139 if (adapter->linkduplex == LINK_FULLD)
3140 edata.duplex = DUPLEX_FULL;
3142 edata.duplex = DUPLEX_HALF;
3144 edata.autoneg = AUTONEG_ENABLE;
3147 if (copy_to_user(rq->ifr_data, &edata, sizeof(edata)))
3150 } else if (ecmd.cmd == ETHTOOL_SSET) {
3151 if (!capable(CAP_NET_ADMIN))
3154 if (adapter->linkspeed == LINK_100MB)
3155 edata.speed = SPEED_100;
3156 else if (adapter->linkspeed == LINK_10MB)
3157 edata.speed = SPEED_10;
3161 if (adapter->linkduplex == LINK_FULLD)
3162 edata.duplex = DUPLEX_FULL;
3164 edata.duplex = DUPLEX_HALF;
3166 edata.autoneg = AUTONEG_ENABLE;
3169 if ((ecmd.speed != edata.speed) ||
3170 (ecmd.duplex != edata.duplex)) {
3174 if (ecmd.speed == SPEED_10)
3177 speed = PCR_SPEED_100;
3178 if (ecmd.duplex == DUPLEX_FULL)
3179 duplex = PCR_DUPLEX_FULL;
3182 slic_link_config(adapter, speed, duplex);
3183 slic_link_event_handler(adapter);
3192 static void slic_config_pci(struct pci_dev *pcidev)
3197 pci_read_config_word(pcidev, PCI_COMMAND, &pci_command);
3199 new_command = pci_command | PCI_COMMAND_MASTER
3200 | PCI_COMMAND_MEMORY
3201 | PCI_COMMAND_INVALIDATE
3202 | PCI_COMMAND_PARITY | PCI_COMMAND_SERR | PCI_COMMAND_FAST_BACK;
3203 if (pci_command != new_command)
3204 pci_write_config_word(pcidev, PCI_COMMAND, new_command);
3207 static int slic_card_init(struct sliccard *card, struct adapter *adapter)
3209 __iomem struct slic_regs *slic_regs = adapter->slic_regs;
3210 struct slic_eeprom *peeprom;
3211 struct oslic_eeprom *pOeeprom;
3212 dma_addr_t phys_config;
3216 struct slic_shmem *pshmem;
3218 uint macaddrs = card->card_size;
3223 struct slic_config_mac *pmac;
3224 unsigned char fruformat;
3225 unsigned char oemfruformat;
3226 struct atk_fru *patkfru;
3227 union oemfru *poemfru;
3229 /* Reset everything except PCI configuration space */
3230 slic_soft_reset(adapter);
3232 /* Download the microcode */
3233 status = slic_card_download(adapter);
3236 dev_err(&adapter->pcidev->dev,
3237 "download failed bus %d slot %d\n",
3238 adapter->busnumber, adapter->slotnumber);
3242 if (!card->config_set) {
3243 peeprom = pci_alloc_consistent(adapter->pcidev,
3244 sizeof(struct slic_eeprom),
3247 phys_configl = SLIC_GET_ADDR_LOW(phys_config);
3248 phys_configh = SLIC_GET_ADDR_HIGH(phys_config);
3251 dev_err(&adapter->pcidev->dev,
3252 "eeprom read failed to get memory bus %d slot %d\n", adapter->busnumber,
3253 adapter->slotnumber);
3256 memset(peeprom, 0, sizeof(struct slic_eeprom));
3258 slic_reg32_write(&slic_regs->slic_icr, ICR_INT_OFF, FLUSH);
3260 pshmem = (struct slic_shmem *)(unsigned long)
3261 adapter->phys_shmem;
3263 spin_lock_irqsave(&adapter->bit64reglock.lock,
3264 adapter->bit64reglock.flags);
3265 slic_reg32_write(&slic_regs->slic_addr_upper, 0, DONT_FLUSH);
3266 slic_reg32_write(&slic_regs->slic_isp,
3267 SLIC_GET_ADDR_LOW(&pshmem->isr), FLUSH);
3268 spin_unlock_irqrestore(&adapter->bit64reglock.lock,
3269 adapter->bit64reglock.flags);
3271 slic_config_get(adapter, phys_configl, phys_configh);
3274 if (adapter->pshmem->isr) {
3275 if (adapter->pshmem->isr & ISR_UPC) {
3276 adapter->pshmem->isr = 0;
3277 slic_reg64_write(adapter,
3278 &slic_regs->slic_isp, 0,
3279 &slic_regs->slic_addr_upper,
3281 slic_reg32_write(&slic_regs->slic_isr,
3284 slic_upr_request_complete(adapter, 0);
3287 adapter->pshmem->isr = 0;
3288 slic_reg32_write(&slic_regs->slic_isr,
3295 dev_err(&adapter->pcidev->dev,
3296 "%d config data fetch timed out!\n",
3298 slic_reg64_write(adapter,
3299 &slic_regs->slic_isp, 0,
3300 &slic_regs->slic_addr_upper,
3307 switch (adapter->devid) {
3309 case SLIC_2GB_DEVICE_ID:
3310 /* extract EEPROM data and pointers to EEPROM data */
3311 pOeeprom = (struct oslic_eeprom *) peeprom;
3312 eecodesize = pOeeprom->EecodeSize;
3313 dramsize = pOeeprom->DramSize;
3314 pmac = pOeeprom->MacInfo;
3315 fruformat = pOeeprom->FruFormat;
3316 patkfru = &pOeeprom->AtkFru;
3317 oemfruformat = pOeeprom->OemFruFormat;
3318 poemfru = &pOeeprom->OemFru;
3320 /* Minor kludge for Oasis card
3321 get 2 MAC addresses from the
3322 EEPROM to ensure that function 1
3323 gets the Port 1 MAC address */
3326 /* extract EEPROM data and pointers to EEPROM data */
3327 eecodesize = peeprom->EecodeSize;
3328 dramsize = peeprom->DramSize;
3329 pmac = peeprom->u2.mac.MacInfo;
3330 fruformat = peeprom->FruFormat;
3331 patkfru = &peeprom->AtkFru;
3332 oemfruformat = peeprom->OemFruFormat;
3333 poemfru = &peeprom->OemFru;
3337 card->config.EepromValid = false;
3339 /* see if the EEPROM is valid by checking it's checksum */
3340 if ((eecodesize <= MAX_EECODE_SIZE) &&
3341 (eecodesize >= MIN_EECODE_SIZE)) {
3344 *(u16 *) ((char *) peeprom + (eecodesize - 2));
3346 calculate the EEPROM checksum
3349 ~slic_eeprom_cksum((char *) peeprom,
3352 if the ucdoe chksum flag bit worked,
3353 we wouldn't need this
3355 if (ee_chksum == calc_chksum)
3356 card->config.EepromValid = true;
3358 /* copy in the DRAM size */
3359 card->config.DramSize = dramsize;
3361 /* copy in the MAC address(es) */
3362 for (i = 0; i < macaddrs; i++) {
3363 memcpy(&card->config.MacInfo[i],
3364 &pmac[i], sizeof(struct slic_config_mac));
3367 /* copy the Alacritech FRU information */
3368 card->config.FruFormat = fruformat;
3369 memcpy(&card->config.AtkFru, patkfru,
3370 sizeof(struct atk_fru));
3372 pci_free_consistent(adapter->pcidev,
3373 sizeof(struct slic_eeprom),
3374 peeprom, phys_config);
3376 if ((!card->config.EepromValid) &&
3377 (adapter->reg_params.fail_on_bad_eeprom)) {
3378 slic_reg64_write(adapter, &slic_regs->slic_isp, 0,
3379 &slic_regs->slic_addr_upper,
3381 dev_err(&adapter->pcidev->dev,
3382 "unsupported CONFIGURATION EEPROM invalid\n");
3386 card->config_set = 1;
3389 if (slic_card_download_gbrcv(adapter)) {
3390 dev_err(&adapter->pcidev->dev,
3391 "unable to download GB receive microcode\n");
3395 if (slic_global.dynamic_intagg)
3396 slic_intagg_set(adapter, 0);
3398 slic_intagg_set(adapter, intagg_delay);
3401 * Initialize ping status to "ok"
3403 card->pingstatus = ISR_PINGMASK;
3406 * Lastly, mark our card state as up and return success
3408 card->state = CARD_UP;
3409 card->reset_in_progress = 0;
3414 static void slic_init_driver(void)
3416 if (slic_first_init) {
3417 slic_first_init = 0;
3418 spin_lock_init(&slic_global.driver_lock.lock);
3423 static void slic_init_adapter(struct net_device *netdev,
3424 struct pci_dev *pcidev,
3425 const struct pci_device_id *pci_tbl_entry,
3426 void __iomem *memaddr, int chip_idx)
3429 struct slic_handle *pslic_handle;
3430 struct adapter *adapter = netdev_priv(netdev);
3432 /* adapter->pcidev = pcidev;*/
3433 adapter->vendid = pci_tbl_entry->vendor;
3434 adapter->devid = pci_tbl_entry->device;
3435 adapter->subsysid = pci_tbl_entry->subdevice;
3436 adapter->busnumber = pcidev->bus->number;
3437 adapter->slotnumber = ((pcidev->devfn >> 3) & 0x1F);
3438 adapter->functionnumber = (pcidev->devfn & 0x7);
3439 adapter->memorylength = pci_resource_len(pcidev, 0);
3440 adapter->slic_regs = (__iomem struct slic_regs *)memaddr;
3441 adapter->irq = pcidev->irq;
3442 /* adapter->netdev = netdev;*/
3443 adapter->next_netdevice = head_netdevice;
3444 head_netdevice = netdev;
3445 adapter->chipid = chip_idx;
3446 adapter->port = 0; /*adapter->functionnumber;*/
3447 adapter->cardindex = adapter->port;
3448 adapter->memorybase = memaddr;
3449 spin_lock_init(&adapter->upr_lock.lock);
3450 spin_lock_init(&adapter->bit64reglock.lock);
3451 spin_lock_init(&adapter->adapter_lock.lock);
3452 spin_lock_init(&adapter->reset_lock.lock);
3453 spin_lock_init(&adapter->handle_lock.lock);
3455 adapter->card_size = 1;
3457 Initialize slic_handle array
3460 Start with 1. 0 is an invalid host handle.
3462 for (index = 1, pslic_handle = &adapter->slic_handles[1];
3463 index < SLIC_CMDQ_MAXCMDS; index++, pslic_handle++) {
3465 pslic_handle->token.handle_index = index;
3466 pslic_handle->type = SLIC_HANDLE_FREE;
3467 pslic_handle->next = adapter->pfree_slic_handles;
3468 adapter->pfree_slic_handles = pslic_handle;
3470 adapter->pshmem = (struct slic_shmem *)
3471 pci_alloc_consistent(adapter->pcidev,
3472 sizeof(struct slic_shmem),
3475 if (adapter->pshmem)
3476 memset(adapter->pshmem, 0, sizeof(struct slic_shmem));
3479 static const struct net_device_ops slic_netdev_ops = {
3480 .ndo_open = slic_entry_open,
3481 .ndo_stop = slic_entry_halt,
3482 .ndo_start_xmit = slic_xmit_start,
3483 .ndo_do_ioctl = slic_ioctl,
3484 .ndo_set_mac_address = slic_mac_set_address,
3485 .ndo_get_stats = slic_get_stats,
3486 .ndo_set_rx_mode = slic_mcast_set_list,
3487 .ndo_validate_addr = eth_validate_addr,
3488 .ndo_change_mtu = eth_change_mtu,
3491 static u32 slic_card_locate(struct adapter *adapter)
3493 struct sliccard *card = slic_global.slic_card;
3494 struct physcard *physcard = slic_global.phys_card;
3496 u16 __iomem *hostid_reg;
3498 uint rdhostid_offset = 0;
3500 switch (adapter->devid) {
3501 case SLIC_2GB_DEVICE_ID:
3502 rdhostid_offset = SLIC_RDHOSTID_2GB;
3504 case SLIC_1GB_DEVICE_ID:
3505 rdhostid_offset = SLIC_RDHOSTID_1GB;
3512 (u16 __iomem *) (((u8 __iomem *) (adapter->slic_regs)) +
3515 /* read the 16 bit hostid from SRAM */
3516 card_hostid = (ushort) readw(hostid_reg);
3518 /* Initialize a new card structure if need be */
3519 if (card_hostid == SLIC_HOSTID_DEFAULT) {
3520 card = kzalloc(sizeof(struct sliccard), GFP_KERNEL);
3524 card->next = slic_global.slic_card;
3525 slic_global.slic_card = card;
3526 card->busnumber = adapter->busnumber;
3527 card->slotnumber = adapter->slotnumber;
3529 /* Find an available cardnum */
3530 for (i = 0; i < SLIC_MAX_CARDS; i++) {
3531 if (slic_global.cardnuminuse[i] == 0) {
3532 slic_global.cardnuminuse[i] = 1;
3537 slic_global.num_slic_cards++;
3539 slic_debug_card_create(card);
3541 /* Card exists, find the card this adapter belongs to */
3543 if (card->cardnum == card_hostid)
3551 /* Put the adapter in the card's adapter list */
3552 if (!card->adapter[adapter->port]) {
3553 card->adapter[adapter->port] = adapter;
3554 adapter->card = card;
3557 card->card_size = 1; /* one port per *logical* card */
3560 for (i = 0; i < SLIC_MAX_PORTS; i++) {
3561 if (physcard->adapter[i])
3564 if (i == SLIC_MAX_PORTS)
3567 if (physcard->adapter[i]->slotnumber == adapter->slotnumber)
3569 physcard = physcard->next;
3572 /* no structure allocated for this physical card yet */
3573 physcard = kzalloc(sizeof(struct physcard), GFP_ATOMIC);
3575 if (card_hostid == SLIC_HOSTID_DEFAULT)
3580 physcard->next = slic_global.phys_card;
3581 slic_global.phys_card = physcard;
3582 physcard->adapters_allocd = 1;
3584 physcard->adapters_allocd++;
3586 /* Note - this is ZERO relative */
3587 adapter->physport = physcard->adapters_allocd - 1;
3589 physcard->adapter[adapter->physport] = adapter;
3590 adapter->physcard = physcard;
3595 static int slic_entry_probe(struct pci_dev *pcidev,
3596 const struct pci_device_id *pci_tbl_entry)
3598 static int cards_found;
3599 static int did_version;
3601 struct net_device *netdev;
3602 struct adapter *adapter;
3603 void __iomem *memmapped_ioaddr = NULL;
3605 ulong mmio_start = 0;
3607 struct sliccard *card = NULL;
3608 int pci_using_dac = 0;
3610 slic_global.dynamic_intagg = dynamic_intagg;
3612 err = pci_enable_device(pcidev);
3617 if (slic_debug > 0 && did_version++ == 0) {
3618 dev_dbg(&pcidev->dev, "%s\n", slic_banner);
3619 dev_dbg(&pcidev->dev, "%s\n", slic_proc_version);
3622 if (!pci_set_dma_mask(pcidev, DMA_BIT_MASK(64))) {
3624 err = pci_set_consistent_dma_mask(pcidev, DMA_BIT_MASK(64));
3626 dev_err(&pcidev->dev, "unable to obtain 64-bit DMA for consistent allocations\n");
3627 goto err_out_disable_pci;
3630 err = pci_set_dma_mask(pcidev, DMA_BIT_MASK(32));
3632 dev_err(&pcidev->dev, "no usable DMA configuration\n");
3633 goto err_out_disable_pci;
3636 pci_set_consistent_dma_mask(pcidev, DMA_BIT_MASK(32));
3639 err = pci_request_regions(pcidev, DRV_NAME);
3641 dev_err(&pcidev->dev, "can't obtain PCI resources\n");
3642 goto err_out_disable_pci;
3645 pci_set_master(pcidev);
3647 netdev = alloc_etherdev(sizeof(struct adapter));
3650 goto err_out_exit_slic_probe;
3653 SET_NETDEV_DEV(netdev, &pcidev->dev);
3655 pci_set_drvdata(pcidev, netdev);
3656 adapter = netdev_priv(netdev);
3657 adapter->netdev = netdev;
3658 adapter->pcidev = pcidev;
3660 netdev->features |= NETIF_F_HIGHDMA;
3662 mmio_start = pci_resource_start(pcidev, 0);
3663 mmio_len = pci_resource_len(pcidev, 0);
3666 /* memmapped_ioaddr = (u32)ioremap_nocache(mmio_start, mmio_len);*/
3667 memmapped_ioaddr = ioremap(mmio_start, mmio_len);
3668 if (!memmapped_ioaddr) {
3669 dev_err(&pcidev->dev, "cannot remap MMIO region %lx @ %lx\n",
3670 mmio_len, mmio_start);
3672 goto err_out_free_netdev;
3675 slic_config_pci(pcidev);
3679 slic_init_adapter(netdev,
3680 pcidev, pci_tbl_entry, memmapped_ioaddr, cards_found);
3682 err = slic_card_locate(adapter);
3684 dev_err(&pcidev->dev, "cannot locate card\n");
3685 goto err_out_free_mmio_region;
3688 card = adapter->card;
3690 if (!adapter->allocated) {
3691 card->adapters_allocated++;
3692 adapter->allocated = 1;
3695 status = slic_card_init(card, adapter);
3698 card->state = CARD_FAIL;
3699 adapter->state = ADAPT_FAIL;
3700 adapter->linkstate = LINK_DOWN;
3701 dev_err(&pcidev->dev, "FAILED status[%x]\n", status);
3703 slic_adapter_set_hwaddr(adapter);
3706 netdev->base_addr = (unsigned long)adapter->memorybase;
3707 netdev->irq = adapter->irq;
3708 netdev->netdev_ops = &slic_netdev_ops;
3710 slic_debug_adapter_create(adapter);
3712 strcpy(netdev->name, "eth%d");
3713 err = register_netdev(netdev);
3715 dev_err(&pcidev->dev, "Cannot register net device, aborting.\n");
3724 iounmap(memmapped_ioaddr);
3725 err_out_free_mmio_region:
3726 release_mem_region(mmio_start, mmio_len);
3727 err_out_free_netdev:
3728 free_netdev(netdev);
3729 err_out_exit_slic_probe:
3730 pci_release_regions(pcidev);
3731 err_out_disable_pci:
3732 pci_disable_device(pcidev);
3736 static struct pci_driver slic_driver = {
3738 .id_table = slic_pci_tbl,
3739 .probe = slic_entry_probe,
3740 .remove = slic_entry_remove,
3743 static int __init slic_module_init(void)
3747 if (debug >= 0 && slic_debug != debug)
3748 pr_debug("debug level is %d.\n", debug);
3752 return pci_register_driver(&slic_driver);
3755 static void __exit slic_module_cleanup(void)
3757 pci_unregister_driver(&slic_driver);
3758 slic_debug_cleanup();
3761 module_init(slic_module_init);
3762 module_exit(slic_module_cleanup);