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
66 #include <linux/kernel.h>
67 #include <linux/string.h>
68 #include <linux/errno.h>
69 #include <linux/ioport.h>
70 #include <linux/slab.h>
71 #include <linux/interrupt.h>
72 #include <linux/timer.h>
73 #include <linux/pci.h>
74 #include <linux/spinlock.h>
75 #include <linux/init.h>
76 #include <linux/bitops.h>
78 #include <linux/netdevice.h>
79 #include <linux/crc32.h>
80 #include <linux/etherdevice.h>
81 #include <linux/skbuff.h>
82 #include <linux/delay.h>
83 #include <linux/debugfs.h>
84 #include <linux/seq_file.h>
85 #include <linux/kthread.h>
86 #include <linux/module.h>
87 #include <linux/moduleparam.h>
89 #include <linux/firmware.h>
90 #include <linux/types.h>
91 #include <linux/dma-mapping.h>
92 #include <linux/mii.h>
93 #include <linux/if_vlan.h>
94 #include <asm/unaligned.h>
96 #include <linux/ethtool.h>
97 #include <linux/uaccess.h>
101 static uint slic_first_init
= 1;
102 static char *slic_banner
= "Alacritech SLIC Technology(tm) Server "\
103 "and Storage Accelerator (Non-Accelerated)";
105 static char *slic_proc_version
= "2.0.351 2006/07/14 12:26:00";
106 static char *slic_product_name
= "SLIC Technology(tm) Server "\
107 "and Storage Accelerator (Non-Accelerated)";
108 static char *slic_vendor
= "Alacritech, Inc.";
110 static int slic_debug
= 1;
111 static int debug
= -1;
112 static struct net_device
*head_netdevice
;
114 static struct base_driver slic_global
= { {}, 0, 0, 0, 1, NULL
, NULL
};
115 static int intagg_delay
= 100;
116 static u32 dynamic_intagg
;
117 static unsigned int rcv_count
;
118 static struct dentry
*slic_debugfs
;
120 #define DRV_NAME "slicoss"
121 #define DRV_VERSION "2.0.1"
122 #define DRV_AUTHOR "Alacritech, Inc. Engineering"
123 #define DRV_DESCRIPTION "Alacritech SLIC Techonology(tm) "\
124 "Non-Accelerated Driver"
125 #define DRV_COPYRIGHT "Copyright 2000-2006 Alacritech, Inc. "\
126 "All rights reserved."
127 #define PFX DRV_NAME " "
129 MODULE_AUTHOR(DRV_AUTHOR
);
130 MODULE_DESCRIPTION(DRV_DESCRIPTION
);
131 MODULE_LICENSE("Dual BSD/GPL");
133 module_param(dynamic_intagg
, int, 0);
134 MODULE_PARM_DESC(dynamic_intagg
, "Dynamic Interrupt Aggregation Setting");
135 module_param(intagg_delay
, int, 0);
136 MODULE_PARM_DESC(intagg_delay
, "uSec Interrupt Aggregation Delay");
138 static DEFINE_PCI_DEVICE_TABLE(slic_pci_tbl
) = {
139 { PCI_DEVICE(PCI_VENDOR_ID_ALACRITECH
, SLIC_1GB_DEVICE_ID
) },
140 { PCI_DEVICE(PCI_VENDOR_ID_ALACRITECH
, SLIC_2GB_DEVICE_ID
) },
144 MODULE_DEVICE_TABLE(pci
, slic_pci_tbl
);
146 #define SLIC_GET_SLIC_HANDLE(_adapter, _pslic_handle) \
148 spin_lock_irqsave(&_adapter->handle_lock.lock, \
149 _adapter->handle_lock.flags); \
150 _pslic_handle = _adapter->pfree_slic_handles; \
151 if (_pslic_handle) { \
152 _adapter->pfree_slic_handles = _pslic_handle->next; \
154 spin_unlock_irqrestore(&_adapter->handle_lock.lock, \
155 _adapter->handle_lock.flags); \
158 #define SLIC_FREE_SLIC_HANDLE(_adapter, _pslic_handle) \
160 _pslic_handle->type = SLIC_HANDLE_FREE; \
161 spin_lock_irqsave(&_adapter->handle_lock.lock, \
162 _adapter->handle_lock.flags); \
163 _pslic_handle->next = _adapter->pfree_slic_handles; \
164 _adapter->pfree_slic_handles = _pslic_handle; \
165 spin_unlock_irqrestore(&_adapter->handle_lock.lock, \
166 _adapter->handle_lock.flags); \
169 static inline void slic_reg32_write(void __iomem
*reg
, u32 value
, bool flush
)
176 static inline void slic_reg64_write(struct adapter
*adapter
, void __iomem
*reg
,
177 u32 value
, void __iomem
*regh
, u32 paddrh
,
180 spin_lock_irqsave(&adapter
->bit64reglock
.lock
,
181 adapter
->bit64reglock
.flags
);
182 if (paddrh
!= adapter
->curaddrupper
) {
183 adapter
->curaddrupper
= paddrh
;
184 writel(paddrh
, regh
);
189 spin_unlock_irqrestore(&adapter
->bit64reglock
.lock
,
190 adapter
->bit64reglock
.flags
);
193 static void slic_mcast_set_bit(struct adapter
*adapter
, char *address
)
195 unsigned char crcpoly
;
197 /* Get the CRC polynomial for the mac address */
198 /* we use bits 1-8 (lsb), bitwise reversed,
199 * msb (= lsb bit 0 before bitrev) is automatically discarded */
200 crcpoly
= (ether_crc(ETH_ALEN
, address
)>>23);
202 /* We only have space on the SLIC for 64 entries. Lop
203 * off the top two bits. (2^6 = 64)
207 /* OR in the new bit into our 64 bit mask. */
208 adapter
->mcastmask
|= (u64
) 1 << crcpoly
;
211 static void slic_mcast_set_mask(struct adapter
*adapter
)
213 __iomem
struct slic_regs
*slic_regs
= adapter
->slic_regs
;
215 if (adapter
->macopts
& (MAC_ALLMCAST
| MAC_PROMISC
)) {
216 /* Turn on all multicast addresses. We have to do this for
217 * promiscuous mode as well as ALLMCAST mode. It saves the
218 * Microcode from having to keep state about the MAC
221 slic_reg32_write(&slic_regs
->slic_mcastlow
, 0xFFFFFFFF, FLUSH
);
222 slic_reg32_write(&slic_regs
->slic_mcasthigh
, 0xFFFFFFFF,
225 /* Commit our multicast mast to the SLIC by writing to the
226 * multicast address mask registers
228 slic_reg32_write(&slic_regs
->slic_mcastlow
,
229 (u32
)(adapter
->mcastmask
& 0xFFFFFFFF), FLUSH
);
230 slic_reg32_write(&slic_regs
->slic_mcasthigh
,
231 (u32
)((adapter
->mcastmask
>> 32) & 0xFFFFFFFF), FLUSH
);
235 static void slic_timer_ping(ulong dev
)
237 struct adapter
*adapter
;
238 struct sliccard
*card
;
240 adapter
= netdev_priv((struct net_device
*)dev
);
241 card
= adapter
->card
;
243 adapter
->pingtimer
.expires
= jiffies
+ (PING_TIMER_INTERVAL
* HZ
);
244 add_timer(&adapter
->pingtimer
);
247 static void slic_unmap_mmio_space(struct adapter
*adapter
)
249 if (adapter
->slic_regs
)
250 iounmap(adapter
->slic_regs
);
251 adapter
->slic_regs
= NULL
;
257 * Write phy control to configure link duplex/speed
260 static void slic_link_config(struct adapter
*adapter
,
261 u32 linkspeed
, u32 linkduplex
)
270 if (adapter
->state
!= ADAPT_UP
)
273 if (linkspeed
> LINK_1000MB
)
274 linkspeed
= LINK_AUTOSPEED
;
275 if (linkduplex
> LINK_AUTOD
)
276 linkduplex
= LINK_AUTOD
;
278 wphy
= &adapter
->slic_regs
->slic_wphy
;
280 if ((linkspeed
== LINK_AUTOSPEED
) || (linkspeed
== LINK_1000MB
)) {
281 if (adapter
->flags
& ADAPT_FLAGS_FIBERMEDIA
) {
282 /* We've got a fiber gigabit interface, and register
283 * 4 is different in fiber mode than in copper mode
286 /* advertise FD only @1000 Mb */
287 phy_advreg
= (MIICR_REG_4
| (PAR_ADV1000XFD
));
288 /* enable PAUSE frames */
289 phy_advreg
|= PAR_ASYMPAUSE_FIBER
;
290 slic_reg32_write(wphy
, phy_advreg
, FLUSH
);
292 if (linkspeed
== LINK_AUTOSPEED
) {
293 /* reset phy, enable auto-neg */
296 (PCR_RESET
| PCR_AUTONEG
|
298 slic_reg32_write(wphy
, phy_config
, FLUSH
);
299 } else { /* forced 1000 Mb FD*/
300 /* power down phy to break link
301 this may not work) */
302 phy_config
= (MIICR_REG_PCR
| PCR_POWERDOWN
);
303 slic_reg32_write(wphy
, phy_config
, FLUSH
);
304 /* wait, Marvell says 1 sec,
305 try to get away with 10 ms */
308 /* disable auto-neg, set speed/duplex,
309 soft reset phy, powerup */
312 (PCR_RESET
| PCR_SPEED_1000
|
314 slic_reg32_write(wphy
, phy_config
, FLUSH
);
316 } else { /* copper gigabit */
318 /* Auto-Negotiate or 1000 Mb must be auto negotiated
319 * We've got a copper gigabit interface, and
320 * register 4 is different in copper mode than
323 if (linkspeed
== LINK_AUTOSPEED
) {
324 /* advertise 10/100 Mb modes */
327 (PAR_ADV100FD
| PAR_ADV100HD
| PAR_ADV10FD
330 /* linkspeed == LINK_1000MB -
331 don't advertise 10/100 Mb modes */
332 phy_advreg
= MIICR_REG_4
;
334 /* enable PAUSE frames */
335 phy_advreg
|= PAR_ASYMPAUSE
;
336 /* required by the Cicada PHY */
337 phy_advreg
|= PAR_802_3
;
338 slic_reg32_write(wphy
, phy_advreg
, FLUSH
);
339 /* advertise FD only @1000 Mb */
340 phy_gctlreg
= (MIICR_REG_9
| (PGC_ADV1000FD
));
341 slic_reg32_write(wphy
, phy_gctlreg
, FLUSH
);
343 if (adapter
->subsysid
!= SLIC_1GB_CICADA_SUBSYS_ID
) {
345 enable auto crossover */
347 (MIICR_REG_16
| (MRV_REG16_XOVERON
));
348 slic_reg32_write(wphy
, phy_config
, FLUSH
);
350 /* reset phy, enable auto-neg */
353 (PCR_RESET
| PCR_AUTONEG
|
355 slic_reg32_write(wphy
, phy_config
, FLUSH
);
356 } else { /* it's a Cicada PHY */
357 /* enable and restart auto-neg (don't reset) */
360 (PCR_AUTONEG
| PCR_AUTONEG_RST
));
361 slic_reg32_write(wphy
, phy_config
, FLUSH
);
366 if (linkspeed
== LINK_10MB
)
369 speed
= PCR_SPEED_100
;
370 if (linkduplex
== LINK_HALFD
)
373 duplex
= PCR_DUPLEX_FULL
;
375 if (adapter
->subsysid
!= SLIC_1GB_CICADA_SUBSYS_ID
) {
377 disable auto crossover */
378 phy_config
= (MIICR_REG_16
| (MRV_REG16_XOVEROFF
));
379 slic_reg32_write(wphy
, phy_config
, FLUSH
);
382 /* power down phy to break link (this may not work) */
383 phy_config
= (MIICR_REG_PCR
| (PCR_POWERDOWN
| speed
| duplex
));
384 slic_reg32_write(wphy
, phy_config
, FLUSH
);
386 /* wait, Marvell says 1 sec, try to get away with 10 ms */
389 if (adapter
->subsysid
!= SLIC_1GB_CICADA_SUBSYS_ID
) {
391 disable auto-neg, set speed,
392 soft reset phy, powerup */
394 (MIICR_REG_PCR
| (PCR_RESET
| speed
| duplex
));
395 slic_reg32_write(wphy
, phy_config
, FLUSH
);
396 } else { /* it's a Cicada PHY */
397 /* disable auto-neg, set speed, powerup */
398 phy_config
= (MIICR_REG_PCR
| (speed
| duplex
));
399 slic_reg32_write(wphy
, phy_config
, FLUSH
);
404 static int slic_card_download_gbrcv(struct adapter
*adapter
)
406 const struct firmware
*fw
;
407 const char *file
= "";
409 __iomem
struct slic_regs
*slic_regs
= adapter
->slic_regs
;
415 switch (adapter
->devid
) {
416 case SLIC_2GB_DEVICE_ID
:
417 file
= "slicoss/oasisrcvucode.sys";
419 case SLIC_1GB_DEVICE_ID
:
420 file
= "slicoss/gbrcvucode.sys";
426 ret
= request_firmware(&fw
, file
, &adapter
->pcidev
->dev
);
428 dev_err(&adapter
->pcidev
->dev
,
429 "SLICOSS: Failed to load firmware %s\n", file
);
433 rcvucodelen
= *(u32
*)(fw
->data
+ index
);
435 switch (adapter
->devid
) {
436 case SLIC_2GB_DEVICE_ID
:
437 if (rcvucodelen
!= OasisRcvUCodeLen
) {
438 release_firmware(fw
);
442 case SLIC_1GB_DEVICE_ID
:
443 if (rcvucodelen
!= GBRcvUCodeLen
) {
444 release_firmware(fw
);
450 slic_reg32_write(&slic_regs
->slic_rcv_wcs
, SLIC_RCVWCS_BEGIN
, FLUSH
);
451 /* download the rcv sequencer ucode */
452 for (codeaddr
= 0; codeaddr
< rcvucodelen
; codeaddr
++) {
453 /* write out instruction address */
454 slic_reg32_write(&slic_regs
->slic_rcv_wcs
, codeaddr
, FLUSH
);
456 instruction
= *(u32
*)(fw
->data
+ index
);
458 /* write out the instruction data low addr */
459 slic_reg32_write(&slic_regs
->slic_rcv_wcs
, instruction
, FLUSH
);
461 instruction
= *(u8
*)(fw
->data
+ index
);
463 /* write out the instruction data high addr */
464 slic_reg32_write(&slic_regs
->slic_rcv_wcs
, (u8
)instruction
,
468 /* download finished */
469 release_firmware(fw
);
470 slic_reg32_write(&slic_regs
->slic_rcv_wcs
, SLIC_RCVWCS_FINISH
, FLUSH
);
474 MODULE_FIRMWARE("slicoss/oasisrcvucode.sys");
475 MODULE_FIRMWARE("slicoss/gbrcvucode.sys");
477 static int slic_card_download(struct adapter
*adapter
)
479 const struct firmware
*fw
;
480 const char *file
= "";
485 __iomem
struct slic_regs
*slic_regs
= adapter
->slic_regs
;
492 int ucode_start
, index
= 0;
494 switch (adapter
->devid
) {
495 case SLIC_2GB_DEVICE_ID
:
496 file
= "slicoss/oasisdownload.sys";
498 case SLIC_1GB_DEVICE_ID
:
499 file
= "slicoss/gbdownload.sys";
504 ret
= request_firmware(&fw
, file
, &adapter
->pcidev
->dev
);
506 dev_err(&adapter
->pcidev
->dev
,
507 "SLICOSS: Failed to load firmware %s\n", file
);
510 numsects
= *(u32
*)(fw
->data
+ index
);
512 for (i
= 0; i
< numsects
; i
++) {
513 sectsize
[i
] = *(u32
*)(fw
->data
+ index
);
516 for (i
= 0; i
< numsects
; i
++) {
517 sectstart
[i
] = *(u32
*)(fw
->data
+ index
);
521 instruction
= *(u32
*)(fw
->data
+ index
);
523 for (section
= 0; section
< numsects
; section
++) {
524 baseaddress
= sectstart
[section
];
525 thissectionsize
= sectsize
[section
] >> 3;
527 for (codeaddr
= 0; codeaddr
< thissectionsize
; codeaddr
++) {
528 /* Write out instruction address */
529 slic_reg32_write(&slic_regs
->slic_wcs
,
530 baseaddress
+ codeaddr
, FLUSH
);
531 /* Write out instruction to low addr */
532 slic_reg32_write(&slic_regs
->slic_wcs
, instruction
, FLUSH
);
533 instruction
= *(u32
*)(fw
->data
+ index
);
536 /* Write out instruction to high addr */
537 slic_reg32_write(&slic_regs
->slic_wcs
, instruction
, FLUSH
);
538 instruction
= *(u32
*)(fw
->data
+ index
);
543 for (section
= 0; section
< numsects
; section
++) {
544 instruction
= *(u32
*)(fw
->data
+ index
);
545 baseaddress
= sectstart
[section
];
546 if (baseaddress
< 0x8000)
548 thissectionsize
= sectsize
[section
] >> 3;
550 for (codeaddr
= 0; codeaddr
< thissectionsize
; codeaddr
++) {
551 /* Write out instruction address */
552 slic_reg32_write(&slic_regs
->slic_wcs
,
553 SLIC_WCS_COMPARE
| (baseaddress
+ codeaddr
),
555 /* Write out instruction to low addr */
556 slic_reg32_write(&slic_regs
->slic_wcs
, instruction
,
558 instruction
= *(u32
*)(fw
->data
+ index
);
560 /* Write out instruction to high addr */
561 slic_reg32_write(&slic_regs
->slic_wcs
, instruction
,
563 instruction
= *(u32
*)(fw
->data
+ index
);
566 /* Check SRAM location zero. If it is non-zero. Abort.*/
567 /* failure = readl((u32 __iomem *)&slic_regs->slic_reset);
569 release_firmware(fw);
574 release_firmware(fw
);
575 /* Everything OK, kick off the card */
577 slic_reg32_write(&slic_regs
->slic_wcs
, SLIC_WCS_START
, FLUSH
);
579 /* stall for 20 ms, long enough for ucode to init card
580 and reach mainloop */
586 MODULE_FIRMWARE("slicoss/oasisdownload.sys");
587 MODULE_FIRMWARE("slicoss/gbdownload.sys");
589 static void slic_adapter_set_hwaddr(struct adapter
*adapter
)
591 struct sliccard
*card
= adapter
->card
;
593 if ((adapter
->card
) && (card
->config_set
)) {
594 memcpy(adapter
->macaddr
,
595 card
->config
.MacInfo
[adapter
->functionnumber
].macaddrA
,
596 sizeof(struct slic_config_mac
));
597 if (!(adapter
->currmacaddr
[0] || adapter
->currmacaddr
[1] ||
598 adapter
->currmacaddr
[2] || adapter
->currmacaddr
[3] ||
599 adapter
->currmacaddr
[4] || adapter
->currmacaddr
[5])) {
600 memcpy(adapter
->currmacaddr
, adapter
->macaddr
, 6);
602 if (adapter
->netdev
) {
603 memcpy(adapter
->netdev
->dev_addr
, adapter
->currmacaddr
,
609 static void slic_intagg_set(struct adapter
*adapter
, u32 value
)
611 slic_reg32_write(&adapter
->slic_regs
->slic_intagg
, value
, FLUSH
);
612 adapter
->card
->loadlevel_current
= value
;
615 static void slic_soft_reset(struct adapter
*adapter
)
617 if (adapter
->card
->state
== CARD_UP
) {
618 slic_reg32_write(&adapter
->slic_regs
->slic_quiesce
, 0, FLUSH
);
622 slic_reg32_write(&adapter
->slic_regs
->slic_reset
, SLIC_RESET_MAGIC
,
627 static void slic_mac_address_config(struct adapter
*adapter
)
631 __iomem
struct slic_regs
*slic_regs
= adapter
->slic_regs
;
633 value
= *(u32
*) &adapter
->currmacaddr
[2];
634 value
= ntohl(value
);
635 slic_reg32_write(&slic_regs
->slic_wraddral
, value
, FLUSH
);
636 slic_reg32_write(&slic_regs
->slic_wraddrbl
, value
, FLUSH
);
638 value2
= (u32
) ((adapter
->currmacaddr
[0] << 8 |
639 adapter
->currmacaddr
[1]) & 0xFFFF);
641 slic_reg32_write(&slic_regs
->slic_wraddrah
, value2
, FLUSH
);
642 slic_reg32_write(&slic_regs
->slic_wraddrbh
, value2
, FLUSH
);
644 /* Write our multicast mask out to the card. This is done */
645 /* here in addition to the slic_mcast_addr_set routine */
646 /* because ALL_MCAST may have been enabled or disabled */
647 slic_mcast_set_mask(adapter
);
650 static void slic_mac_config(struct adapter
*adapter
)
653 __iomem
struct slic_regs
*slic_regs
= adapter
->slic_regs
;
655 /* Setup GMAC gaps */
656 if (adapter
->linkspeed
== LINK_1000MB
) {
657 value
= ((GMCR_GAPBB_1000
<< GMCR_GAPBB_SHIFT
) |
658 (GMCR_GAPR1_1000
<< GMCR_GAPR1_SHIFT
) |
659 (GMCR_GAPR2_1000
<< GMCR_GAPR2_SHIFT
));
661 value
= ((GMCR_GAPBB_100
<< GMCR_GAPBB_SHIFT
) |
662 (GMCR_GAPR1_100
<< GMCR_GAPR1_SHIFT
) |
663 (GMCR_GAPR2_100
<< GMCR_GAPR2_SHIFT
));
667 if (adapter
->linkspeed
== LINK_1000MB
)
670 /* enable fullduplex */
671 if ((adapter
->linkduplex
== LINK_FULLD
)
672 || (adapter
->macopts
& MAC_LOOPBACK
)) {
676 /* write mac config */
677 slic_reg32_write(&slic_regs
->slic_wmcfg
, value
, FLUSH
);
679 /* setup mac addresses */
680 slic_mac_address_config(adapter
);
683 static void slic_config_set(struct adapter
*adapter
, bool linkchange
)
687 __iomem
struct slic_regs
*slic_regs
= adapter
->slic_regs
;
691 slic_mac_config(adapter
);
692 RcrReset
= GRCR_RESET
;
694 slic_mac_address_config(adapter
);
698 if (adapter
->linkduplex
== LINK_FULLD
) {
700 value
= (GXCR_RESET
| /* Always reset */
701 GXCR_XMTEN
| /* Enable transmit */
702 GXCR_PAUSEEN
); /* Enable pause */
704 slic_reg32_write(&slic_regs
->slic_wxcfg
, value
, FLUSH
);
706 /* Setup rcvcfg last */
707 value
= (RcrReset
| /* Reset, if linkchange */
708 GRCR_CTLEN
| /* Enable CTL frames */
709 GRCR_ADDRAEN
| /* Address A enable */
710 GRCR_RCVBAD
| /* Rcv bad frames */
711 (GRCR_HASHSIZE
<< GRCR_HASHSIZE_SHIFT
));
714 value
= (GXCR_RESET
| /* Always reset */
715 GXCR_XMTEN
); /* Enable transmit */
717 slic_reg32_write(&slic_regs
->slic_wxcfg
, value
, FLUSH
);
719 /* Setup rcvcfg last */
720 value
= (RcrReset
| /* Reset, if linkchange */
721 GRCR_ADDRAEN
| /* Address A enable */
722 GRCR_RCVBAD
| /* Rcv bad frames */
723 (GRCR_HASHSIZE
<< GRCR_HASHSIZE_SHIFT
));
726 if (adapter
->state
!= ADAPT_DOWN
) {
727 /* Only enable receive if we are restarting or running */
731 if (adapter
->macopts
& MAC_PROMISC
)
732 value
|= GRCR_RCVALL
;
734 slic_reg32_write(&slic_regs
->slic_wrcfg
, value
, FLUSH
);
738 * Turn off RCV and XMT, power down PHY
740 static void slic_config_clear(struct adapter
*adapter
)
744 __iomem
struct slic_regs
*slic_regs
= adapter
->slic_regs
;
747 value
= (GXCR_RESET
| /* Always reset */
748 GXCR_PAUSEEN
); /* Enable pause */
750 slic_reg32_write(&slic_regs
->slic_wxcfg
, value
, FLUSH
);
752 value
= (GRCR_RESET
| /* Always reset */
753 GRCR_CTLEN
| /* Enable CTL frames */
754 GRCR_ADDRAEN
| /* Address A enable */
755 (GRCR_HASHSIZE
<< GRCR_HASHSIZE_SHIFT
));
757 slic_reg32_write(&slic_regs
->slic_wrcfg
, value
, FLUSH
);
760 phy_config
= (MIICR_REG_PCR
| (PCR_POWERDOWN
));
761 slic_reg32_write(&slic_regs
->slic_wphy
, phy_config
, FLUSH
);
764 static bool slic_mac_filter(struct adapter
*adapter
,
765 struct ether_header
*ether_frame
)
767 struct net_device
*netdev
= adapter
->netdev
;
768 u32 opts
= adapter
->macopts
;
769 u32
*dhost4
= (u32
*)ðer_frame
->ether_dhost
[0];
770 u16
*dhost2
= (u16
*)ðer_frame
->ether_dhost
[4];
772 if (opts
& MAC_PROMISC
)
775 if ((*dhost4
== 0xFFFFFFFF) && (*dhost2
== 0xFFFF)) {
776 if (opts
& MAC_BCAST
) {
777 adapter
->rcv_broadcasts
++;
784 if (ether_frame
->ether_dhost
[0] & 0x01) {
785 if (opts
& MAC_ALLMCAST
) {
786 adapter
->rcv_multicasts
++;
787 netdev
->stats
.multicast
++;
790 if (opts
& MAC_MCAST
) {
791 struct mcast_address
*mcaddr
= adapter
->mcastaddrs
;
794 if (!compare_ether_addr(mcaddr
->address
,
795 ether_frame
->ether_dhost
)) {
796 adapter
->rcv_multicasts
++;
797 netdev
->stats
.multicast
++;
800 mcaddr
= mcaddr
->next
;
807 if (opts
& MAC_DIRECTED
) {
808 adapter
->rcv_unicasts
++;
815 static int slic_mac_set_address(struct net_device
*dev
, void *ptr
)
817 struct adapter
*adapter
= netdev_priv(dev
);
818 struct sockaddr
*addr
= ptr
;
820 if (netif_running(dev
))
825 if (!is_valid_ether_addr(addr
->sa_data
))
828 memcpy(dev
->dev_addr
, addr
->sa_data
, dev
->addr_len
);
829 memcpy(adapter
->currmacaddr
, addr
->sa_data
, dev
->addr_len
);
831 slic_config_set(adapter
, true);
835 static void slic_timer_load_check(ulong cardaddr
)
837 struct sliccard
*card
= (struct sliccard
*)cardaddr
;
838 struct adapter
*adapter
= card
->master
;
840 u32 load
= card
->events
;
843 if ((adapter
) && (adapter
->state
== ADAPT_UP
) &&
844 (card
->state
== CARD_UP
) && (slic_global
.dynamic_intagg
)) {
845 intagg
= &adapter
->slic_regs
->slic_intagg
;
846 if (adapter
->devid
== SLIC_1GB_DEVICE_ID
) {
847 if (adapter
->linkspeed
== LINK_1000MB
)
850 if (load
> SLIC_LOAD_5
)
851 level
= SLIC_INTAGG_5
;
852 else if (load
> SLIC_LOAD_4
)
853 level
= SLIC_INTAGG_4
;
854 else if (load
> SLIC_LOAD_3
)
855 level
= SLIC_INTAGG_3
;
856 else if (load
> SLIC_LOAD_2
)
857 level
= SLIC_INTAGG_2
;
858 else if (load
> SLIC_LOAD_1
)
859 level
= SLIC_INTAGG_1
;
861 level
= SLIC_INTAGG_0
;
863 if (card
->loadlevel_current
!= level
) {
864 card
->loadlevel_current
= level
;
865 slic_reg32_write(intagg
, level
, FLUSH
);
868 if (load
> SLIC_LOAD_5
)
869 level
= SLIC_INTAGG_5
;
870 else if (load
> SLIC_LOAD_4
)
871 level
= SLIC_INTAGG_4
;
872 else if (load
> SLIC_LOAD_3
)
873 level
= SLIC_INTAGG_3
;
874 else if (load
> SLIC_LOAD_2
)
875 level
= SLIC_INTAGG_2
;
876 else if (load
> SLIC_LOAD_1
)
877 level
= SLIC_INTAGG_1
;
879 level
= SLIC_INTAGG_0
;
880 if (card
->loadlevel_current
!= level
) {
881 card
->loadlevel_current
= level
;
882 slic_reg32_write(intagg
, level
, FLUSH
);
887 card
->loadtimer
.expires
= jiffies
+ (SLIC_LOADTIMER_PERIOD
* HZ
);
888 add_timer(&card
->loadtimer
);
891 static int slic_upr_queue_request(struct adapter
*adapter
,
895 u32 upr_buffer
, u32 upr_buffer_h
)
897 struct slic_upr
*upr
;
898 struct slic_upr
*uprqueue
;
900 upr
= kmalloc(sizeof(struct slic_upr
), GFP_ATOMIC
);
904 upr
->adapter
= adapter
->port
;
905 upr
->upr_request
= upr_request
;
906 upr
->upr_data
= upr_data
;
907 upr
->upr_buffer
= upr_buffer
;
908 upr
->upr_data_h
= upr_data_h
;
909 upr
->upr_buffer_h
= upr_buffer_h
;
911 if (adapter
->upr_list
) {
912 uprqueue
= adapter
->upr_list
;
914 while (uprqueue
->next
)
915 uprqueue
= uprqueue
->next
;
916 uprqueue
->next
= upr
;
918 adapter
->upr_list
= upr
;
923 static void slic_upr_start(struct adapter
*adapter
)
925 struct slic_upr
*upr
;
926 __iomem
struct slic_regs
*slic_regs
= adapter
->slic_regs
;
932 upr
= adapter
->upr_list
;
935 if (adapter
->upr_busy
)
937 adapter
->upr_busy
= 1;
939 switch (upr
->upr_request
) {
941 if (upr
->upr_data_h
== 0) {
942 slic_reg32_write(&slic_regs
->slic_stats
, upr
->upr_data
,
945 slic_reg64_write(adapter
, &slic_regs
->slic_stats64
,
947 &slic_regs
->slic_addr_upper
,
948 upr
->upr_data_h
, FLUSH
);
953 slic_reg64_write(adapter
, &slic_regs
->slic_rlsr
, upr
->upr_data
,
954 &slic_regs
->slic_addr_upper
, upr
->upr_data_h
,
958 case SLIC_UPR_RCONFIG
:
959 slic_reg64_write(adapter
, &slic_regs
->slic_rconfig
,
960 upr
->upr_data
, &slic_regs
->slic_addr_upper
,
961 upr
->upr_data_h
, FLUSH
);
964 slic_reg32_write(&slic_regs
->slic_ping
, 1, FLUSH
);
969 static int slic_upr_request(struct adapter
*adapter
,
973 u32 upr_buffer
, u32 upr_buffer_h
)
977 spin_lock_irqsave(&adapter
->upr_lock
.lock
, adapter
->upr_lock
.flags
);
978 rc
= slic_upr_queue_request(adapter
,
981 upr_data_h
, upr_buffer
, upr_buffer_h
);
985 slic_upr_start(adapter
);
987 spin_unlock_irqrestore(&adapter
->upr_lock
.lock
,
988 adapter
->upr_lock
.flags
);
992 static void slic_link_upr_complete(struct adapter
*adapter
, u32 isr
)
994 u32 linkstatus
= adapter
->pshmem
->linkstatus
;
996 unsigned char linkspeed
;
997 unsigned char linkduplex
;
999 if ((isr
& ISR_UPCERR
) || (isr
& ISR_UPCBSY
)) {
1000 struct slic_shmem
*pshmem
;
1002 pshmem
= (struct slic_shmem
*)(unsigned long)
1003 adapter
->phys_shmem
;
1004 #if BITS_PER_LONG == 64
1005 slic_upr_queue_request(adapter
,
1007 SLIC_GET_ADDR_LOW(&pshmem
->linkstatus
),
1008 SLIC_GET_ADDR_HIGH(&pshmem
->linkstatus
),
1011 slic_upr_queue_request(adapter
,
1013 (u32
) &pshmem
->linkstatus
,
1014 SLIC_GET_ADDR_HIGH(pshmem
), 0, 0);
1018 if (adapter
->state
!= ADAPT_UP
)
1021 linkup
= linkstatus
& GIG_LINKUP
? LINK_UP
: LINK_DOWN
;
1022 if (linkstatus
& GIG_SPEED_1000
)
1023 linkspeed
= LINK_1000MB
;
1024 else if (linkstatus
& GIG_SPEED_100
)
1025 linkspeed
= LINK_100MB
;
1027 linkspeed
= LINK_10MB
;
1029 if (linkstatus
& GIG_FULLDUPLEX
)
1030 linkduplex
= LINK_FULLD
;
1032 linkduplex
= LINK_HALFD
;
1034 if ((adapter
->linkstate
== LINK_DOWN
) && (linkup
== LINK_DOWN
))
1037 /* link up event, but nothing has changed */
1038 if ((adapter
->linkstate
== LINK_UP
) &&
1039 (linkup
== LINK_UP
) &&
1040 (adapter
->linkspeed
== linkspeed
) &&
1041 (adapter
->linkduplex
== linkduplex
))
1044 /* link has changed at this point */
1046 /* link has gone from up to down */
1047 if (linkup
== LINK_DOWN
) {
1048 adapter
->linkstate
= LINK_DOWN
;
1052 /* link has gone from down to up */
1053 adapter
->linkspeed
= linkspeed
;
1054 adapter
->linkduplex
= linkduplex
;
1056 if (adapter
->linkstate
!= LINK_UP
) {
1058 slic_config_set(adapter
, true);
1059 adapter
->linkstate
= LINK_UP
;
1060 netif_start_queue(adapter
->netdev
);
1064 static void slic_upr_request_complete(struct adapter
*adapter
, u32 isr
)
1066 struct sliccard
*card
= adapter
->card
;
1067 struct slic_upr
*upr
;
1069 spin_lock_irqsave(&adapter
->upr_lock
.lock
, adapter
->upr_lock
.flags
);
1070 upr
= adapter
->upr_list
;
1072 spin_unlock_irqrestore(&adapter
->upr_lock
.lock
,
1073 adapter
->upr_lock
.flags
);
1076 adapter
->upr_list
= upr
->next
;
1078 adapter
->upr_busy
= 0;
1079 switch (upr
->upr_request
) {
1080 case SLIC_UPR_STATS
:
1082 struct slic_stats
*slicstats
=
1083 (struct slic_stats
*) &adapter
->pshmem
->inicstats
;
1084 struct slic_stats
*newstats
= slicstats
;
1085 struct slic_stats
*old
= &adapter
->inicstats_prev
;
1086 struct slicnet_stats
*stst
= &adapter
->slic_stats
;
1088 if (isr
& ISR_UPCERR
) {
1089 dev_err(&adapter
->netdev
->dev
,
1090 "SLIC_UPR_STATS command failed isr[%x]\n",
1095 UPDATE_STATS_GB(stst
->tcp
.xmit_tcp_segs
,
1096 newstats
->xmit_tcp_segs_gb
,
1097 old
->xmit_tcp_segs_gb
);
1099 UPDATE_STATS_GB(stst
->tcp
.xmit_tcp_bytes
,
1100 newstats
->xmit_tcp_bytes_gb
,
1101 old
->xmit_tcp_bytes_gb
);
1103 UPDATE_STATS_GB(stst
->tcp
.rcv_tcp_segs
,
1104 newstats
->rcv_tcp_segs_gb
,
1105 old
->rcv_tcp_segs_gb
);
1107 UPDATE_STATS_GB(stst
->tcp
.rcv_tcp_bytes
,
1108 newstats
->rcv_tcp_bytes_gb
,
1109 old
->rcv_tcp_bytes_gb
);
1111 UPDATE_STATS_GB(stst
->iface
.xmt_bytes
,
1112 newstats
->xmit_bytes_gb
,
1113 old
->xmit_bytes_gb
);
1115 UPDATE_STATS_GB(stst
->iface
.xmt_ucast
,
1116 newstats
->xmit_unicasts_gb
,
1117 old
->xmit_unicasts_gb
);
1119 UPDATE_STATS_GB(stst
->iface
.rcv_bytes
,
1120 newstats
->rcv_bytes_gb
,
1123 UPDATE_STATS_GB(stst
->iface
.rcv_ucast
,
1124 newstats
->rcv_unicasts_gb
,
1125 old
->rcv_unicasts_gb
);
1127 UPDATE_STATS_GB(stst
->iface
.xmt_errors
,
1128 newstats
->xmit_collisions_gb
,
1129 old
->xmit_collisions_gb
);
1131 UPDATE_STATS_GB(stst
->iface
.xmt_errors
,
1132 newstats
->xmit_excess_collisions_gb
,
1133 old
->xmit_excess_collisions_gb
);
1135 UPDATE_STATS_GB(stst
->iface
.xmt_errors
,
1136 newstats
->xmit_other_error_gb
,
1137 old
->xmit_other_error_gb
);
1139 UPDATE_STATS_GB(stst
->iface
.rcv_errors
,
1140 newstats
->rcv_other_error_gb
,
1141 old
->rcv_other_error_gb
);
1143 UPDATE_STATS_GB(stst
->iface
.rcv_discards
,
1144 newstats
->rcv_drops_gb
,
1147 if (newstats
->rcv_drops_gb
> old
->rcv_drops_gb
) {
1148 adapter
->rcv_drops
+=
1149 (newstats
->rcv_drops_gb
-
1152 memcpy(old
, newstats
, sizeof(struct slic_stats
));
1156 slic_link_upr_complete(adapter
, isr
);
1158 case SLIC_UPR_RCONFIG
:
1161 card
->pingstatus
|= (isr
& ISR_PINGDSMASK
);
1165 slic_upr_start(adapter
);
1166 spin_unlock_irqrestore(&adapter
->upr_lock
.lock
,
1167 adapter
->upr_lock
.flags
);
1170 static void slic_config_get(struct adapter
*adapter
, u32 config
,
1175 status
= slic_upr_request(adapter
,
1177 (u32
) config
, (u32
) config_h
, 0, 0);
1181 * this is here to checksum the eeprom, there is some ucode bug
1182 * which prevens us from using the ucode result.
1183 * remove this once ucode is fixed.
1185 static ushort
slic_eeprom_cksum(char *m
, int len
)
1187 #define ADDCARRY(x) (x > 65535 ? x -= 65535 : x)
1188 #define REDUCE {l_util.l = sum; sum = l_util.s[0] + l_util.s[1]; ADDCARRY(sum);\
1193 u32 byte_swapped
= 0;
1210 #if BITS_PER_LONG == 64
1211 w_int
= (u32
) ((ulong
) w
& 0x00000000FFFFFFFF);
1215 if ((1 & w_int
) && (len
> 0)) {
1218 s_util
.c
[0] = *(unsigned char *)w
;
1219 w
= (u16
*)((char *)w
+ 1);
1224 /* Unroll the loop to make overhead from branches &c small. */
1225 while ((len
-= 32) >= 0) {
1242 w
= (u16
*)((ulong
) w
+ 16); /* verify */
1245 while ((len
-= 8) >= 0) {
1250 w
= (u16
*)((ulong
) w
+ 4); /* verify */
1253 if (len
!= 0 || byte_swapped
!= 0) {
1255 while ((len
-= 2) >= 0)
1256 sum
+= *w
++; /* verify */
1262 s_util
.c
[1] = *(char *) w
;
1269 } else if (len
== -1) {
1270 s_util
.c
[0] = *(char *) w
;
1279 return (ushort
) sum
;
1282 static void slic_rspqueue_free(struct adapter
*adapter
)
1285 struct slic_rspqueue
*rspq
= &adapter
->rspqueue
;
1287 for (i
= 0; i
< rspq
->num_pages
; i
++) {
1288 if (rspq
->vaddr
[i
]) {
1289 pci_free_consistent(adapter
->pcidev
, PAGE_SIZE
,
1290 rspq
->vaddr
[i
], rspq
->paddr
[i
]);
1292 rspq
->vaddr
[i
] = NULL
;
1296 rspq
->pageindex
= 0;
1297 rspq
->rspbuf
= NULL
;
1300 static int slic_rspqueue_init(struct adapter
*adapter
)
1303 struct slic_rspqueue
*rspq
= &adapter
->rspqueue
;
1304 __iomem
struct slic_regs
*slic_regs
= adapter
->slic_regs
;
1307 memset(rspq
, 0, sizeof(struct slic_rspqueue
));
1309 rspq
->num_pages
= SLIC_RSPQ_PAGES_GB
;
1311 for (i
= 0; i
< rspq
->num_pages
; i
++) {
1312 rspq
->vaddr
[i
] = pci_alloc_consistent(adapter
->pcidev
,
1315 if (!rspq
->vaddr
[i
]) {
1316 dev_err(&adapter
->pcidev
->dev
,
1317 "pci_alloc_consistent failed\n");
1318 slic_rspqueue_free(adapter
);
1322 * do we really need this assertions (4K PAGE_SIZE aligned addr)? */
1323 memset(rspq
->vaddr
[i
], 0, PAGE_SIZE
);
1326 slic_reg32_write(&slic_regs
->slic_rbar
,
1327 (rspq
->paddr
[i
] | SLIC_RSPQ_BUFSINPAGE
),
1330 slic_reg64_write(adapter
, &slic_regs
->slic_rbar64
,
1331 (rspq
->paddr
[i
] | SLIC_RSPQ_BUFSINPAGE
),
1332 &slic_regs
->slic_addr_upper
,
1333 paddrh
, DONT_FLUSH
);
1337 rspq
->pageindex
= 0;
1338 rspq
->rspbuf
= (struct slic_rspbuf
*)rspq
->vaddr
[0];
1342 static struct slic_rspbuf
*slic_rspqueue_getnext(struct adapter
*adapter
)
1344 struct slic_rspqueue
*rspq
= &adapter
->rspqueue
;
1345 struct slic_rspbuf
*buf
;
1347 if (!(rspq
->rspbuf
->status
))
1351 if (++rspq
->offset
< SLIC_RSPQ_BUFSINPAGE
) {
1354 slic_reg64_write(adapter
, &adapter
->slic_regs
->slic_rbar64
,
1355 (rspq
->paddr
[rspq
->pageindex
] | SLIC_RSPQ_BUFSINPAGE
),
1356 &adapter
->slic_regs
->slic_addr_upper
, 0, DONT_FLUSH
);
1357 rspq
->pageindex
= (rspq
->pageindex
+ 1) % rspq
->num_pages
;
1359 rspq
->rspbuf
= (struct slic_rspbuf
*)
1360 rspq
->vaddr
[rspq
->pageindex
];
1366 static void slic_cmdqmem_free(struct adapter
*adapter
)
1368 struct slic_cmdqmem
*cmdqmem
= &adapter
->cmdqmem
;
1371 for (i
= 0; i
< SLIC_CMDQ_MAXPAGES
; i
++) {
1372 if (cmdqmem
->pages
[i
]) {
1373 pci_free_consistent(adapter
->pcidev
,
1375 (void *) cmdqmem
->pages
[i
],
1376 cmdqmem
->dma_pages
[i
]);
1379 memset(cmdqmem
, 0, sizeof(struct slic_cmdqmem
));
1382 static u32
*slic_cmdqmem_addpage(struct adapter
*adapter
)
1384 struct slic_cmdqmem
*cmdqmem
= &adapter
->cmdqmem
;
1387 if (cmdqmem
->pagecnt
>= SLIC_CMDQ_MAXPAGES
)
1389 pageaddr
= pci_alloc_consistent(adapter
->pcidev
,
1391 &cmdqmem
->dma_pages
[cmdqmem
->pagecnt
]);
1395 cmdqmem
->pages
[cmdqmem
->pagecnt
] = pageaddr
;
1400 static void slic_cmdq_free(struct adapter
*adapter
)
1402 struct slic_hostcmd
*cmd
;
1404 cmd
= adapter
->cmdq_all
.head
;
1407 struct sk_buff
*tempskb
;
1412 dev_kfree_skb_irq(tempskb
);
1415 cmd
= cmd
->next_all
;
1417 memset(&adapter
->cmdq_all
, 0, sizeof(struct slic_cmdqueue
));
1418 memset(&adapter
->cmdq_free
, 0, sizeof(struct slic_cmdqueue
));
1419 memset(&adapter
->cmdq_done
, 0, sizeof(struct slic_cmdqueue
));
1420 slic_cmdqmem_free(adapter
);
1423 static void slic_cmdq_addcmdpage(struct adapter
*adapter
, u32
*page
)
1425 struct slic_hostcmd
*cmd
;
1426 struct slic_hostcmd
*prev
;
1427 struct slic_hostcmd
*tail
;
1428 struct slic_cmdqueue
*cmdq
;
1434 struct slic_handle
*pslic_handle
;
1437 cmd
= (struct slic_hostcmd
*)cmdaddr
;
1440 phys_addr
= virt_to_bus((void *)page
);
1441 phys_addrl
= SLIC_GET_ADDR_LOW(phys_addr
);
1442 phys_addrh
= SLIC_GET_ADDR_HIGH(phys_addr
);
1446 while ((cmdcnt
< SLIC_CMDQ_CMDSINPAGE
) &&
1447 (adapter
->slic_handle_ix
< 256)) {
1448 /* Allocate and initialize a SLIC_HANDLE for this command */
1449 SLIC_GET_SLIC_HANDLE(adapter
, pslic_handle
);
1450 pslic_handle
->type
= SLIC_HANDLE_CMD
;
1451 pslic_handle
->address
= (void *) cmd
;
1452 pslic_handle
->offset
= (ushort
) adapter
->slic_handle_ix
++;
1453 pslic_handle
->other_handle
= NULL
;
1454 pslic_handle
->next
= NULL
;
1456 cmd
->pslic_handle
= pslic_handle
;
1457 cmd
->cmd64
.hosthandle
= pslic_handle
->token
.handle_token
;
1459 cmd
->paddrl
= phys_addrl
;
1460 cmd
->paddrh
= phys_addrh
;
1461 cmd
->next_all
= prev
;
1464 phys_addrl
+= SLIC_HOSTCMD_SIZE
;
1465 cmdaddr
+= SLIC_HOSTCMD_SIZE
;
1467 cmd
= (struct slic_hostcmd
*)cmdaddr
;
1471 cmdq
= &adapter
->cmdq_all
;
1472 cmdq
->count
+= cmdcnt
; /* SLIC_CMDQ_CMDSINPAGE; mooktodo */
1473 tail
->next_all
= cmdq
->head
;
1475 cmdq
= &adapter
->cmdq_free
;
1476 spin_lock_irqsave(&cmdq
->lock
.lock
, cmdq
->lock
.flags
);
1477 cmdq
->count
+= cmdcnt
; /* SLIC_CMDQ_CMDSINPAGE; mooktodo */
1478 tail
->next
= cmdq
->head
;
1480 spin_unlock_irqrestore(&cmdq
->lock
.lock
, cmdq
->lock
.flags
);
1483 static int slic_cmdq_init(struct adapter
*adapter
)
1488 memset(&adapter
->cmdq_all
, 0, sizeof(struct slic_cmdqueue
));
1489 memset(&adapter
->cmdq_free
, 0, sizeof(struct slic_cmdqueue
));
1490 memset(&adapter
->cmdq_done
, 0, sizeof(struct slic_cmdqueue
));
1491 spin_lock_init(&adapter
->cmdq_all
.lock
.lock
);
1492 spin_lock_init(&adapter
->cmdq_free
.lock
.lock
);
1493 spin_lock_init(&adapter
->cmdq_done
.lock
.lock
);
1494 memset(&adapter
->cmdqmem
, 0, sizeof(struct slic_cmdqmem
));
1495 adapter
->slic_handle_ix
= 1;
1496 for (i
= 0; i
< SLIC_CMDQ_INITPAGES
; i
++) {
1497 pageaddr
= slic_cmdqmem_addpage(adapter
);
1499 slic_cmdq_free(adapter
);
1502 slic_cmdq_addcmdpage(adapter
, pageaddr
);
1504 adapter
->slic_handle_ix
= 1;
1509 static void slic_cmdq_reset(struct adapter
*adapter
)
1511 struct slic_hostcmd
*hcmd
;
1512 struct sk_buff
*skb
;
1515 spin_lock_irqsave(&adapter
->cmdq_free
.lock
.lock
,
1516 adapter
->cmdq_free
.lock
.flags
);
1517 spin_lock_irqsave(&adapter
->cmdq_done
.lock
.lock
,
1518 adapter
->cmdq_done
.lock
.flags
);
1519 outstanding
= adapter
->cmdq_all
.count
- adapter
->cmdq_done
.count
;
1520 outstanding
-= adapter
->cmdq_free
.count
;
1521 hcmd
= adapter
->cmdq_all
.head
;
1527 dev_kfree_skb_irq(skb
);
1529 hcmd
= hcmd
->next_all
;
1531 adapter
->cmdq_free
.count
= 0;
1532 adapter
->cmdq_free
.head
= NULL
;
1533 adapter
->cmdq_free
.tail
= NULL
;
1534 adapter
->cmdq_done
.count
= 0;
1535 adapter
->cmdq_done
.head
= NULL
;
1536 adapter
->cmdq_done
.tail
= NULL
;
1537 adapter
->cmdq_free
.head
= adapter
->cmdq_all
.head
;
1538 hcmd
= adapter
->cmdq_all
.head
;
1540 adapter
->cmdq_free
.count
++;
1541 hcmd
->next
= hcmd
->next_all
;
1542 hcmd
= hcmd
->next_all
;
1544 if (adapter
->cmdq_free
.count
!= adapter
->cmdq_all
.count
) {
1545 dev_err(&adapter
->netdev
->dev
,
1546 "free_count %d != all count %d\n",
1547 adapter
->cmdq_free
.count
, adapter
->cmdq_all
.count
);
1549 spin_unlock_irqrestore(&adapter
->cmdq_done
.lock
.lock
,
1550 adapter
->cmdq_done
.lock
.flags
);
1551 spin_unlock_irqrestore(&adapter
->cmdq_free
.lock
.lock
,
1552 adapter
->cmdq_free
.lock
.flags
);
1555 static void slic_cmdq_getdone(struct adapter
*adapter
)
1557 struct slic_cmdqueue
*done_cmdq
= &adapter
->cmdq_done
;
1558 struct slic_cmdqueue
*free_cmdq
= &adapter
->cmdq_free
;
1560 spin_lock_irqsave(&done_cmdq
->lock
.lock
, done_cmdq
->lock
.flags
);
1562 free_cmdq
->head
= done_cmdq
->head
;
1563 free_cmdq
->count
= done_cmdq
->count
;
1564 done_cmdq
->head
= NULL
;
1565 done_cmdq
->tail
= NULL
;
1566 done_cmdq
->count
= 0;
1567 spin_unlock_irqrestore(&done_cmdq
->lock
.lock
, done_cmdq
->lock
.flags
);
1570 static struct slic_hostcmd
*slic_cmdq_getfree(struct adapter
*adapter
)
1572 struct slic_cmdqueue
*cmdq
= &adapter
->cmdq_free
;
1573 struct slic_hostcmd
*cmd
= NULL
;
1576 spin_lock_irqsave(&cmdq
->lock
.lock
, cmdq
->lock
.flags
);
1580 cmdq
->head
= cmd
->next
;
1582 spin_unlock_irqrestore(&cmdq
->lock
.lock
, cmdq
->lock
.flags
);
1584 slic_cmdq_getdone(adapter
);
1591 spin_unlock_irqrestore(&cmdq
->lock
.lock
,
1593 pageaddr
= slic_cmdqmem_addpage(adapter
);
1595 slic_cmdq_addcmdpage(adapter
, pageaddr
);
1596 goto lock_and_retry
;
1603 static void slic_cmdq_putdone_irq(struct adapter
*adapter
,
1604 struct slic_hostcmd
*cmd
)
1606 struct slic_cmdqueue
*cmdq
= &adapter
->cmdq_done
;
1608 spin_lock(&cmdq
->lock
.lock
);
1610 cmd
->next
= cmdq
->head
;
1613 if ((adapter
->xmitq_full
) && (cmdq
->count
> 10))
1614 netif_wake_queue(adapter
->netdev
);
1615 spin_unlock(&cmdq
->lock
.lock
);
1618 static int slic_rcvqueue_fill(struct adapter
*adapter
)
1623 struct slic_rcvqueue
*rcvq
= &adapter
->rcvqueue
;
1625 struct device
*dev
= &adapter
->netdev
->dev
;
1627 while (i
< SLIC_RCVQ_FILLENTRIES
) {
1628 struct slic_rcvbuf
*rcvbuf
;
1629 struct sk_buff
*skb
;
1630 #ifdef KLUDGE_FOR_4GB_BOUNDARY
1633 skb
= alloc_skb(SLIC_RCVQ_RCVBUFSIZE
, GFP_ATOMIC
);
1635 paddr
= (void *)(unsigned long)
1636 pci_map_single(adapter
->pcidev
,
1638 SLIC_RCVQ_RCVBUFSIZE
,
1639 PCI_DMA_FROMDEVICE
);
1640 paddrl
= SLIC_GET_ADDR_LOW(paddr
);
1641 paddrh
= SLIC_GET_ADDR_HIGH(paddr
);
1643 skb
->len
= SLIC_RCVBUF_HEADSIZE
;
1644 rcvbuf
= (struct slic_rcvbuf
*)skb
->head
;
1647 #ifdef KLUDGE_FOR_4GB_BOUNDARY
1649 dev_err(dev
, "%s: LOW 32bits PHYSICAL ADDRESS == 0\n",
1651 dev_err(dev
, "skb[%p] PROBLEM\n", skb
);
1652 dev_err(dev
, " skbdata[%p]\n", skb
->data
);
1653 dev_err(dev
, " skblen[%x]\n", skb
->len
);
1654 dev_err(dev
, " paddr[%p]\n", paddr
);
1655 dev_err(dev
, " paddrl[%x]\n", paddrl
);
1656 dev_err(dev
, " paddrh[%x]\n", paddrh
);
1657 dev_err(dev
, " rcvq->head[%p]\n", rcvq
->head
);
1658 dev_err(dev
, " rcvq->tail[%p]\n", rcvq
->tail
);
1659 dev_err(dev
, " rcvq->count[%x]\n", rcvq
->count
);
1660 dev_err(dev
, "SKIP THIS SKB!!!!!!!!\n");
1661 goto retry_rcvqfill
;
1665 dev_err(dev
, "%s: LOW 32bits PHYSICAL ADDRESS == 0\n",
1667 dev_err(dev
, "skb[%p] PROBLEM\n", skb
);
1668 dev_err(dev
, " skbdata[%p]\n", skb
->data
);
1669 dev_err(dev
, " skblen[%x]\n", skb
->len
);
1670 dev_err(dev
, " paddr[%p]\n", paddr
);
1671 dev_err(dev
, " paddrl[%x]\n", paddrl
);
1672 dev_err(dev
, " paddrh[%x]\n", paddrh
);
1673 dev_err(dev
, " rcvq->head[%p]\n", rcvq
->head
);
1674 dev_err(dev
, " rcvq->tail[%p]\n", rcvq
->tail
);
1675 dev_err(dev
, " rcvq->count[%x]\n", rcvq
->count
);
1676 dev_err(dev
, "GIVE TO CARD ANYWAY\n");
1680 slic_reg32_write(&adapter
->slic_regs
->slic_hbar
,
1681 (u32
)paddrl
, DONT_FLUSH
);
1683 slic_reg64_write(adapter
,
1684 &adapter
->slic_regs
->slic_hbar64
,
1686 &adapter
->slic_regs
->slic_addr_upper
,
1687 paddrh
, DONT_FLUSH
);
1690 rcvq
->tail
->next
= skb
;
1697 dev_err(&adapter
->netdev
->dev
,
1698 "slic_rcvqueue_fill could only get [%d] skbuffs\n",
1706 static void slic_rcvqueue_free(struct adapter
*adapter
)
1708 struct slic_rcvqueue
*rcvq
= &adapter
->rcvqueue
;
1709 struct sk_buff
*skb
;
1711 while (rcvq
->head
) {
1713 rcvq
->head
= rcvq
->head
->next
;
1721 static int slic_rcvqueue_init(struct adapter
*adapter
)
1724 struct slic_rcvqueue
*rcvq
= &adapter
->rcvqueue
;
1728 rcvq
->size
= SLIC_RCVQ_ENTRIES
;
1731 i
= (SLIC_RCVQ_ENTRIES
/ SLIC_RCVQ_FILLENTRIES
);
1734 count
+= slic_rcvqueue_fill(adapter
);
1737 if (rcvq
->count
< SLIC_RCVQ_MINENTRIES
) {
1738 slic_rcvqueue_free(adapter
);
1744 static struct sk_buff
*slic_rcvqueue_getnext(struct adapter
*adapter
)
1746 struct slic_rcvqueue
*rcvq
= &adapter
->rcvqueue
;
1747 struct sk_buff
*skb
;
1748 struct slic_rcvbuf
*rcvbuf
;
1753 rcvbuf
= (struct slic_rcvbuf
*)skb
->head
;
1755 if (rcvbuf
->status
& IRHDDR_SVALID
) {
1756 rcvq
->head
= rcvq
->head
->next
;
1763 dev_err(&adapter
->netdev
->dev
,
1764 "RcvQ Empty!! rcvq[%p] count[%x]\n", rcvq
, rcvq
->count
);
1767 while (rcvq
->count
< SLIC_RCVQ_FILLTHRESH
) {
1768 count
= slic_rcvqueue_fill(adapter
);
1777 static u32
slic_rcvqueue_reinsert(struct adapter
*adapter
, struct sk_buff
*skb
)
1779 struct slic_rcvqueue
*rcvq
= &adapter
->rcvqueue
;
1783 struct slic_rcvbuf
*rcvbuf
= (struct slic_rcvbuf
*)skb
->head
;
1786 paddr
= (void *)(unsigned long)
1787 pci_map_single(adapter
->pcidev
, skb
->head
,
1788 SLIC_RCVQ_RCVBUFSIZE
, PCI_DMA_FROMDEVICE
);
1792 paddrl
= SLIC_GET_ADDR_LOW(paddr
);
1793 paddrh
= SLIC_GET_ADDR_HIGH(paddr
);
1796 dev
= &adapter
->netdev
->dev
;
1797 dev_err(dev
, "%s: LOW 32bits PHYSICAL ADDRESS == 0\n",
1799 dev_err(dev
, "skb[%p] PROBLEM\n", skb
);
1800 dev_err(dev
, " skbdata[%p]\n", skb
->data
);
1801 dev_err(dev
, " skblen[%x]\n", skb
->len
);
1802 dev_err(dev
, " paddr[%p]\n", paddr
);
1803 dev_err(dev
, " paddrl[%x]\n", paddrl
);
1804 dev_err(dev
, " paddrh[%x]\n", paddrh
);
1805 dev_err(dev
, " rcvq->head[%p]\n", rcvq
->head
);
1806 dev_err(dev
, " rcvq->tail[%p]\n", rcvq
->tail
);
1807 dev_err(dev
, " rcvq->count[%x]\n", rcvq
->count
);
1810 slic_reg32_write(&adapter
->slic_regs
->slic_hbar
, (u32
)paddrl
,
1813 slic_reg64_write(adapter
, &adapter
->slic_regs
->slic_hbar64
,
1814 paddrl
, &adapter
->slic_regs
->slic_addr_upper
,
1815 paddrh
, DONT_FLUSH
);
1818 rcvq
->tail
->next
= skb
;
1826 static int slic_debug_card_show(struct seq_file
*seq
, void *v
)
1830 struct sliccard
*card
= seq
->private;
1831 struct slic_config
*config
= &card
->config
;
1832 unsigned char *fru
= (unsigned char *)(&card
->config
.atk_fru
);
1833 unsigned char *oemfru
= (unsigned char *)(&card
->config
.OemFru
);
1836 seq_printf(seq
, "driver_version : %s\n", slic_proc_version
);
1837 seq_printf(seq
, "Microcode versions: \n");
1838 seq_printf(seq
, " Gigabit (gb) : %s %s\n",
1839 MOJAVE_UCODE_VERS_STRING
, MOJAVE_UCODE_VERS_DATE
);
1840 seq_printf(seq
, " Gigabit Receiver : %s %s\n",
1841 GB_RCVUCODE_VERS_STRING
, GB_RCVUCODE_VERS_DATE
);
1842 seq_printf(seq
, "Vendor : %s\n", slic_vendor
);
1843 seq_printf(seq
, "Product Name : %s\n", slic_product_name
);
1845 seq_printf(seq
, "VendorId : %4.4X\n",
1847 seq_printf(seq
, "DeviceId : %4.4X\n",
1849 seq_printf(seq
, "RevisionId : %2.2x\n",
1850 config
->RevisionId
);
1851 seq_printf(seq
, "Bus # : %d\n", card
->busnumber
);
1852 seq_printf(seq
, "Device # : %d\n", card
->slotnumber
);
1853 seq_printf(seq
, "Interfaces : %d\n", card
->card_size
);
1854 seq_printf(seq
, " Initialized : %d\n",
1855 card
->adapters_activated
);
1856 seq_printf(seq
, " Allocated : %d\n",
1857 card
->adapters_allocated
);
1858 for (i
= 0; i
< card
->card_size
; i
++) {
1860 " MAC%d : %2.2X %2.2X %2.2X %2.2X %2.2X %2.2X\n",
1861 i
, config
->macinfo
[i
].macaddrA
[0],
1862 config
->macinfo
[i
].macaddrA
[1],
1863 config
->macinfo
[i
].macaddrA
[2],
1864 config
->macinfo
[i
].macaddrA
[3],
1865 config
->macinfo
[i
].macaddrA
[4],
1866 config
->macinfo
[i
].macaddrA
[5]);
1868 seq_printf(seq
, " IF Init State Duplex/Speed irq\n");
1869 seq_printf(seq
, " -------------------------------\n");
1870 for (i
= 0; i
< card
->adapters_allocated
; i
++) {
1871 struct adapter
*adapter
;
1873 adapter
= card
->adapter
[i
];
1876 " %d %d %s %s %s 0x%X\n",
1877 adapter
->physport
, adapter
->state
,
1878 SLIC_LINKSTATE(adapter
->linkstate
),
1879 SLIC_DUPLEX(adapter
->linkduplex
),
1880 SLIC_SPEED(adapter
->linkspeed
),
1881 (uint
) adapter
->irq
);
1884 seq_printf(seq
, "Generation # : %4.4X\n", card
->gennumber
);
1885 seq_printf(seq
, "RcvQ max entries : %4.4X\n",
1887 seq_printf(seq
, "Ping Status : %8.8X\n",
1889 seq_printf(seq
, "Minimum grant : %2.2x\n",
1891 seq_printf(seq
, "Maximum Latency : %2.2x\n", config
->MaxLat
);
1892 seq_printf(seq
, "PciStatus : %4.4x\n",
1894 seq_printf(seq
, "Debug Device Id : %4.4x\n",
1896 seq_printf(seq
, "DRAM ROM Function : %4.4x\n",
1898 seq_printf(seq
, "Network interface Pin 1 : %2.2x\n",
1899 config
->NetIntPin1
);
1900 seq_printf(seq
, "Network interface Pin 2 : %2.2x\n",
1901 config
->NetIntPin1
);
1902 seq_printf(seq
, "Network interface Pin 3 : %2.2x\n",
1903 config
->NetIntPin1
);
1904 seq_printf(seq
, "PM capabilities : %4.4X\n",
1906 seq_printf(seq
, "Network Clock Controls : %4.4X\n",
1907 config
->NwClkCtrls
);
1909 switch (config
->FruFormat
) {
1910 case ATK_FRU_FORMAT
:
1913 "Vendor : Alacritech, Inc.\n");
1915 "Assembly # : %c%c%c%c%c%c\n",
1916 fru
[0], fru
[1], fru
[2], fru
[3], fru
[4],
1919 "Revision # : %c%c\n",
1922 if (config
->OEMFruFormat
== VENDOR4_FRU_FORMAT
) {
1925 "%c%c%c%c%c%c%c%c%c%c%c%c\n",
1926 fru
[8], fru
[9], fru
[10],
1927 fru
[11], fru
[12], fru
[13],
1928 fru
[16], fru
[17], fru
[18],
1929 fru
[19], fru
[20], fru
[21]);
1933 "%c%c%c%c%c%c%c%c%c%c%c%c%c%c\n",
1934 fru
[8], fru
[9], fru
[10],
1935 fru
[11], fru
[12], fru
[13],
1936 fru
[14], fru
[15], fru
[16],
1937 fru
[17], fru
[18], fru
[19],
1946 "Vendor : Alacritech, Inc.\n");
1948 "Serial # : Empty FRU\n");
1953 switch (config
->OEMFruFormat
) {
1954 case VENDOR1_FRU_FORMAT
:
1956 seq_printf(seq
, "FRU Information:\n");
1957 seq_printf(seq
, " Commodity # : %c\n",
1960 " Assembly # : %c%c%c%c\n",
1961 oemfru
[1], oemfru
[2], oemfru
[3], oemfru
[4]);
1963 " Revision # : %c%c\n",
1964 oemfru
[5], oemfru
[6]);
1966 " Supplier # : %c%c\n",
1967 oemfru
[7], oemfru
[8]);
1970 oemfru
[9], oemfru
[10]);
1972 " Sequence # : %c%c%c\n",
1973 oemfru
[11], oemfru
[12], oemfru
[13]);
1977 case VENDOR2_FRU_FORMAT
:
1979 seq_printf(seq
, "FRU Information:\n");
1982 "%c%c%c%c%c%c%c%c\n",
1983 oemfru
[0], oemfru
[1], oemfru
[2],
1984 oemfru
[3], oemfru
[4], oemfru
[5],
1985 oemfru
[6], oemfru
[7]);
1987 " Supplier # : %c%c%c%c%c\n",
1988 oemfru
[8], oemfru
[9], oemfru
[10],
1989 oemfru
[11], oemfru
[12]);
1992 oemfru
[13], oemfru
[14], oemfru
[15]);
1994 " Sequence # : %c%c%c%c\n",
1995 oemfru
[16], oemfru
[17], oemfru
[18],
2000 case VENDOR3_FRU_FORMAT
:
2002 seq_printf(seq
, "FRU Information:\n");
2005 case VENDOR4_FRU_FORMAT
:
2007 seq_printf(seq
, "FRU Information:\n");
2010 "%c%c%c%c%c%c%c%c\n",
2011 oemfru
[0], oemfru
[1], oemfru
[2],
2012 oemfru
[3], oemfru
[4], oemfru
[5],
2013 oemfru
[6], oemfru
[7]);
2016 "%c%c%c%c%c%c%c%c\n",
2017 oemfru
[8], oemfru
[9], oemfru
[10],
2018 oemfru
[11], oemfru
[12], oemfru
[13],
2019 oemfru
[14], oemfru
[15]);
2022 "%c%c%c%c%c%c%c%c\n",
2023 oemfru
[16], oemfru
[17], oemfru
[18],
2024 oemfru
[19], oemfru
[20], oemfru
[21],
2025 oemfru
[22], oemfru
[23]);
2037 static int slic_debug_adapter_show(struct seq_file
*seq
, void *v
)
2039 struct adapter
*adapter
= seq
->private;
2040 struct net_device
*netdev
= adapter
->netdev
;
2042 seq_printf(seq
, "info: interface : %s\n",
2043 adapter
->netdev
->name
);
2044 seq_printf(seq
, "info: status : %s\n",
2045 SLIC_LINKSTATE(adapter
->linkstate
));
2046 seq_printf(seq
, "info: port : %d\n",
2048 seq_printf(seq
, "info: speed : %s\n",
2049 SLIC_SPEED(adapter
->linkspeed
));
2050 seq_printf(seq
, "info: duplex : %s\n",
2051 SLIC_DUPLEX(adapter
->linkduplex
));
2052 seq_printf(seq
, "info: irq : 0x%X\n",
2053 (uint
) adapter
->irq
);
2054 seq_printf(seq
, "info: Interrupt Agg Delay: %d usec\n",
2055 adapter
->card
->loadlevel_current
);
2056 seq_printf(seq
, "info: RcvQ max entries : %4.4X\n",
2058 seq_printf(seq
, "info: RcvQ current : %4.4X\n",
2059 adapter
->rcvqueue
.count
);
2060 seq_printf(seq
, "rx stats: packets : %8.8lX\n",
2061 netdev
->stats
.rx_packets
);
2062 seq_printf(seq
, "rx stats: bytes : %8.8lX\n",
2063 netdev
->stats
.rx_bytes
);
2064 seq_printf(seq
, "rx stats: broadcasts : %8.8X\n",
2065 adapter
->rcv_broadcasts
);
2066 seq_printf(seq
, "rx stats: multicasts : %8.8X\n",
2067 adapter
->rcv_multicasts
);
2068 seq_printf(seq
, "rx stats: unicasts : %8.8X\n",
2069 adapter
->rcv_unicasts
);
2070 seq_printf(seq
, "rx stats: errors : %8.8X\n",
2071 (u32
) adapter
->slic_stats
.iface
.rcv_errors
);
2072 seq_printf(seq
, "rx stats: Missed errors : %8.8X\n",
2073 (u32
) adapter
->slic_stats
.iface
.rcv_discards
);
2074 seq_printf(seq
, "rx stats: drops : %8.8X\n",
2075 (u32
) adapter
->rcv_drops
);
2076 seq_printf(seq
, "tx stats: packets : %8.8lX\n",
2077 netdev
->stats
.tx_packets
);
2078 seq_printf(seq
, "tx stats: bytes : %8.8lX\n",
2079 netdev
->stats
.tx_bytes
);
2080 seq_printf(seq
, "tx stats: errors : %8.8X\n",
2081 (u32
) adapter
->slic_stats
.iface
.xmt_errors
);
2082 seq_printf(seq
, "rx stats: multicasts : %8.8lX\n",
2083 netdev
->stats
.multicast
);
2084 seq_printf(seq
, "tx stats: collision errors : %8.8X\n",
2085 (u32
) adapter
->slic_stats
.iface
.xmit_collisions
);
2086 seq_printf(seq
, "perf: Max rcv frames/isr : %8.8X\n",
2087 adapter
->max_isr_rcvs
);
2088 seq_printf(seq
, "perf: Rcv interrupt yields : %8.8X\n",
2089 adapter
->rcv_interrupt_yields
);
2090 seq_printf(seq
, "perf: Max xmit complete/isr : %8.8X\n",
2091 adapter
->max_isr_xmits
);
2092 seq_printf(seq
, "perf: error interrupts : %8.8X\n",
2093 adapter
->error_interrupts
);
2094 seq_printf(seq
, "perf: error rmiss interrupts : %8.8X\n",
2095 adapter
->error_rmiss_interrupts
);
2096 seq_printf(seq
, "perf: rcv interrupts : %8.8X\n",
2097 adapter
->rcv_interrupts
);
2098 seq_printf(seq
, "perf: xmit interrupts : %8.8X\n",
2099 adapter
->xmit_interrupts
);
2100 seq_printf(seq
, "perf: link event interrupts : %8.8X\n",
2101 adapter
->linkevent_interrupts
);
2102 seq_printf(seq
, "perf: UPR interrupts : %8.8X\n",
2103 adapter
->upr_interrupts
);
2104 seq_printf(seq
, "perf: interrupt count : %8.8X\n",
2106 seq_printf(seq
, "perf: false interrupts : %8.8X\n",
2107 adapter
->false_interrupts
);
2108 seq_printf(seq
, "perf: All register writes : %8.8X\n",
2109 adapter
->all_reg_writes
);
2110 seq_printf(seq
, "perf: ICR register writes : %8.8X\n",
2111 adapter
->icr_reg_writes
);
2112 seq_printf(seq
, "perf: ISR register writes : %8.8X\n",
2113 adapter
->isr_reg_writes
);
2114 seq_printf(seq
, "ifevents: overflow 802 errors : %8.8X\n",
2115 adapter
->if_events
.oflow802
);
2116 seq_printf(seq
, "ifevents: transport overflow errors: %8.8X\n",
2117 adapter
->if_events
.Tprtoflow
);
2118 seq_printf(seq
, "ifevents: underflow errors : %8.8X\n",
2119 adapter
->if_events
.uflow802
);
2120 seq_printf(seq
, "ifevents: receive early : %8.8X\n",
2121 adapter
->if_events
.rcvearly
);
2122 seq_printf(seq
, "ifevents: buffer overflows : %8.8X\n",
2123 adapter
->if_events
.Bufov
);
2124 seq_printf(seq
, "ifevents: carrier errors : %8.8X\n",
2125 adapter
->if_events
.Carre
);
2126 seq_printf(seq
, "ifevents: Long : %8.8X\n",
2127 adapter
->if_events
.Longe
);
2128 seq_printf(seq
, "ifevents: invalid preambles : %8.8X\n",
2129 adapter
->if_events
.Invp
);
2130 seq_printf(seq
, "ifevents: CRC errors : %8.8X\n",
2131 adapter
->if_events
.Crc
);
2132 seq_printf(seq
, "ifevents: dribble nibbles : %8.8X\n",
2133 adapter
->if_events
.Drbl
);
2134 seq_printf(seq
, "ifevents: Code violations : %8.8X\n",
2135 adapter
->if_events
.Code
);
2136 seq_printf(seq
, "ifevents: TCP checksum errors : %8.8X\n",
2137 adapter
->if_events
.TpCsum
);
2138 seq_printf(seq
, "ifevents: TCP header short errors : %8.8X\n",
2139 adapter
->if_events
.TpHlen
);
2140 seq_printf(seq
, "ifevents: IP checksum errors : %8.8X\n",
2141 adapter
->if_events
.IpCsum
);
2142 seq_printf(seq
, "ifevents: IP frame incompletes : %8.8X\n",
2143 adapter
->if_events
.IpLen
);
2144 seq_printf(seq
, "ifevents: IP headers shorts : %8.8X\n",
2145 adapter
->if_events
.IpHlen
);
2149 static int slic_debug_adapter_open(struct inode
*inode
, struct file
*file
)
2151 return single_open(file
, slic_debug_adapter_show
, inode
->i_private
);
2154 static int slic_debug_card_open(struct inode
*inode
, struct file
*file
)
2156 return single_open(file
, slic_debug_card_show
, inode
->i_private
);
2159 static const struct file_operations slic_debug_adapter_fops
= {
2160 .owner
= THIS_MODULE
,
2161 .open
= slic_debug_adapter_open
,
2163 .llseek
= seq_lseek
,
2164 .release
= single_release
,
2167 static const struct file_operations slic_debug_card_fops
= {
2168 .owner
= THIS_MODULE
,
2169 .open
= slic_debug_card_open
,
2171 .llseek
= seq_lseek
,
2172 .release
= single_release
,
2175 static void slic_debug_adapter_create(struct adapter
*adapter
)
2179 struct sliccard
*card
= adapter
->card
;
2181 if (!card
->debugfs_dir
)
2184 sprintf(name
, "port%d", adapter
->port
);
2185 d
= debugfs_create_file(name
, S_IRUGO
,
2186 card
->debugfs_dir
, adapter
,
2187 &slic_debug_adapter_fops
);
2188 if (!d
|| IS_ERR(d
))
2189 pr_info(PFX
"%s: debugfs create failed\n", name
);
2191 adapter
->debugfs_entry
= d
;
2194 static void slic_debug_adapter_destroy(struct adapter
*adapter
)
2196 debugfs_remove(adapter
->debugfs_entry
);
2197 adapter
->debugfs_entry
= NULL
;
2200 static void slic_debug_card_create(struct sliccard
*card
)
2203 char name
[IFNAMSIZ
];
2205 snprintf(name
, sizeof(name
), "slic%d", card
->cardnum
);
2206 d
= debugfs_create_dir(name
, slic_debugfs
);
2207 if (!d
|| IS_ERR(d
))
2208 pr_info(PFX
"%s: debugfs create dir failed\n",
2211 card
->debugfs_dir
= d
;
2212 d
= debugfs_create_file("cardinfo", S_IRUGO
,
2214 &slic_debug_card_fops
);
2215 if (!d
|| IS_ERR(d
))
2216 pr_info(PFX
"%s: debugfs create failed\n",
2219 card
->debugfs_cardinfo
= d
;
2223 static void slic_debug_card_destroy(struct sliccard
*card
)
2227 for (i
= 0; i
< card
->card_size
; i
++) {
2228 struct adapter
*adapter
;
2230 adapter
= card
->adapter
[i
];
2232 slic_debug_adapter_destroy(adapter
);
2234 if (card
->debugfs_cardinfo
) {
2235 debugfs_remove(card
->debugfs_cardinfo
);
2236 card
->debugfs_cardinfo
= NULL
;
2238 if (card
->debugfs_dir
) {
2239 debugfs_remove(card
->debugfs_dir
);
2240 card
->debugfs_dir
= NULL
;
2244 static void slic_debug_init(void)
2248 ent
= debugfs_create_dir("slic", NULL
);
2249 if (!ent
|| IS_ERR(ent
)) {
2250 pr_info(PFX
"debugfs create directory failed\n");
2257 static void slic_debug_cleanup(void)
2260 debugfs_remove(slic_debugfs
);
2261 slic_debugfs
= NULL
;
2266 * slic_link_event_handler -
2268 * Initiate a link configuration sequence. The link configuration begins
2269 * by issuing a READ_LINK_STATUS command to the Utility Processor on the
2270 * SLIC. Since the command finishes asynchronously, the slic_upr_comlete
2271 * routine will follow it up witha UP configuration write command, which
2272 * will also complete asynchronously.
2275 static void slic_link_event_handler(struct adapter
*adapter
)
2278 struct slic_shmem
*pshmem
;
2280 if (adapter
->state
!= ADAPT_UP
) {
2281 /* Adapter is not operational. Ignore. */
2285 pshmem
= (struct slic_shmem
*)(unsigned long)adapter
->phys_shmem
;
2287 #if BITS_PER_LONG == 64
2288 status
= slic_upr_request(adapter
,
2290 SLIC_GET_ADDR_LOW(&pshmem
->linkstatus
),
2291 SLIC_GET_ADDR_HIGH(&pshmem
->linkstatus
),
2294 status
= slic_upr_request(adapter
, SLIC_UPR_RLSR
,
2295 (u32
) &pshmem
->linkstatus
, /* no 4GB wrap guaranteed */
2300 static void slic_init_cleanup(struct adapter
*adapter
)
2302 if (adapter
->intrregistered
) {
2303 adapter
->intrregistered
= 0;
2304 free_irq(adapter
->netdev
->irq
, adapter
->netdev
);
2307 if (adapter
->pshmem
) {
2308 pci_free_consistent(adapter
->pcidev
,
2309 sizeof(struct slic_shmem
),
2310 adapter
->pshmem
, adapter
->phys_shmem
);
2311 adapter
->pshmem
= NULL
;
2312 adapter
->phys_shmem
= (dma_addr_t
)(unsigned long)NULL
;
2315 if (adapter
->pingtimerset
) {
2316 adapter
->pingtimerset
= 0;
2317 del_timer(&adapter
->pingtimer
);
2320 slic_rspqueue_free(adapter
);
2321 slic_cmdq_free(adapter
);
2322 slic_rcvqueue_free(adapter
);
2326 * Allocate a mcast_address structure to hold the multicast address.
2329 static int slic_mcast_add_list(struct adapter
*adapter
, char *address
)
2331 struct mcast_address
*mcaddr
, *mlist
;
2333 /* Check to see if it already exists */
2334 mlist
= adapter
->mcastaddrs
;
2336 if (!compare_ether_addr(mlist
->address
, address
))
2338 mlist
= mlist
->next
;
2341 /* Doesn't already exist. Allocate a structure to hold it */
2342 mcaddr
= kmalloc(sizeof(struct mcast_address
), GFP_ATOMIC
);
2346 memcpy(mcaddr
->address
, address
, 6);
2348 mcaddr
->next
= adapter
->mcastaddrs
;
2349 adapter
->mcastaddrs
= mcaddr
;
2354 static void slic_mcast_set_list(struct net_device
*dev
)
2356 struct adapter
*adapter
= netdev_priv(dev
);
2359 struct netdev_hw_addr
*ha
;
2361 netdev_for_each_mc_addr(ha
, dev
) {
2362 addresses
= (char *) &ha
->addr
;
2363 status
= slic_mcast_add_list(adapter
, addresses
);
2366 slic_mcast_set_bit(adapter
, addresses
);
2369 if (adapter
->devflags_prev
!= dev
->flags
) {
2370 adapter
->macopts
= MAC_DIRECTED
;
2372 if (dev
->flags
& IFF_BROADCAST
)
2373 adapter
->macopts
|= MAC_BCAST
;
2374 if (dev
->flags
& IFF_PROMISC
)
2375 adapter
->macopts
|= MAC_PROMISC
;
2376 if (dev
->flags
& IFF_ALLMULTI
)
2377 adapter
->macopts
|= MAC_ALLMCAST
;
2378 if (dev
->flags
& IFF_MULTICAST
)
2379 adapter
->macopts
|= MAC_MCAST
;
2381 adapter
->devflags_prev
= dev
->flags
;
2382 slic_config_set(adapter
, true);
2385 slic_mcast_set_mask(adapter
);
2389 #define XMIT_FAIL_LINK_STATE 1
2390 #define XMIT_FAIL_ZERO_LENGTH 2
2391 #define XMIT_FAIL_HOSTCMD_FAIL 3
2393 static void slic_xmit_build_request(struct adapter
*adapter
,
2394 struct slic_hostcmd
*hcmd
, struct sk_buff
*skb
)
2396 struct slic_host64_cmd
*ihcmd
;
2399 ihcmd
= &hcmd
->cmd64
;
2401 ihcmd
->flags
= (adapter
->port
<< IHFLG_IFSHFT
);
2402 ihcmd
->command
= IHCMD_XMT_REQ
;
2403 ihcmd
->u
.slic_buffers
.totlen
= skb
->len
;
2404 phys_addr
= pci_map_single(adapter
->pcidev
, skb
->data
, skb
->len
,
2406 ihcmd
->u
.slic_buffers
.bufs
[0].paddrl
= SLIC_GET_ADDR_LOW(phys_addr
);
2407 ihcmd
->u
.slic_buffers
.bufs
[0].paddrh
= SLIC_GET_ADDR_HIGH(phys_addr
);
2408 ihcmd
->u
.slic_buffers
.bufs
[0].length
= skb
->len
;
2409 #if BITS_PER_LONG == 64
2410 hcmd
->cmdsize
= (u32
) ((((u64
)&ihcmd
->u
.slic_buffers
.bufs
[1] -
2411 (u64
) hcmd
) + 31) >> 5);
2413 hcmd
->cmdsize
= ((((u32
) &ihcmd
->u
.slic_buffers
.bufs
[1] -
2414 (u32
) hcmd
) + 31) >> 5);
2418 static void slic_xmit_fail(struct adapter
*adapter
,
2419 struct sk_buff
*skb
,
2420 void *cmd
, u32 skbtype
, u32 status
)
2422 if (adapter
->xmitq_full
)
2423 netif_stop_queue(adapter
->netdev
);
2424 if ((cmd
== NULL
) && (status
<= XMIT_FAIL_HOSTCMD_FAIL
)) {
2426 case XMIT_FAIL_LINK_STATE
:
2427 dev_err(&adapter
->netdev
->dev
,
2428 "reject xmit skb[%p: %x] linkstate[%s] "
2429 "adapter[%s:%d] card[%s:%d]\n",
2431 SLIC_LINKSTATE(adapter
->linkstate
),
2432 SLIC_ADAPTER_STATE(adapter
->state
),
2434 SLIC_CARD_STATE(adapter
->card
->state
),
2435 adapter
->card
->state
);
2437 case XMIT_FAIL_ZERO_LENGTH
:
2438 dev_err(&adapter
->netdev
->dev
,
2439 "xmit_start skb->len == 0 skb[%p] type[%x]\n",
2440 skb
, skb
->pkt_type
);
2442 case XMIT_FAIL_HOSTCMD_FAIL
:
2443 dev_err(&adapter
->netdev
->dev
,
2444 "xmit_start skb[%p] type[%x] No host commands "
2445 "available\n", skb
, skb
->pkt_type
);
2450 adapter
->netdev
->stats
.tx_dropped
++;
2453 static void slic_rcv_handle_error(struct adapter
*adapter
,
2454 struct slic_rcvbuf
*rcvbuf
)
2456 struct slic_hddr_wds
*hdr
= (struct slic_hddr_wds
*)rcvbuf
->data
;
2457 struct net_device
*netdev
= adapter
->netdev
;
2459 if (adapter
->devid
!= SLIC_1GB_DEVICE_ID
) {
2460 if (hdr
->frame_status14
& VRHSTAT_802OE
)
2461 adapter
->if_events
.oflow802
++;
2462 if (hdr
->frame_status14
& VRHSTAT_TPOFLO
)
2463 adapter
->if_events
.Tprtoflow
++;
2464 if (hdr
->frame_status_b14
& VRHSTATB_802UE
)
2465 adapter
->if_events
.uflow802
++;
2466 if (hdr
->frame_status_b14
& VRHSTATB_RCVE
) {
2467 adapter
->if_events
.rcvearly
++;
2468 netdev
->stats
.rx_fifo_errors
++;
2470 if (hdr
->frame_status_b14
& VRHSTATB_BUFF
) {
2471 adapter
->if_events
.Bufov
++;
2472 netdev
->stats
.rx_over_errors
++;
2474 if (hdr
->frame_status_b14
& VRHSTATB_CARRE
) {
2475 adapter
->if_events
.Carre
++;
2476 netdev
->stats
.tx_carrier_errors
++;
2478 if (hdr
->frame_status_b14
& VRHSTATB_LONGE
)
2479 adapter
->if_events
.Longe
++;
2480 if (hdr
->frame_status_b14
& VRHSTATB_PREA
)
2481 adapter
->if_events
.Invp
++;
2482 if (hdr
->frame_status_b14
& VRHSTATB_CRC
) {
2483 adapter
->if_events
.Crc
++;
2484 netdev
->stats
.rx_crc_errors
++;
2486 if (hdr
->frame_status_b14
& VRHSTATB_DRBL
)
2487 adapter
->if_events
.Drbl
++;
2488 if (hdr
->frame_status_b14
& VRHSTATB_CODE
)
2489 adapter
->if_events
.Code
++;
2490 if (hdr
->frame_status_b14
& VRHSTATB_TPCSUM
)
2491 adapter
->if_events
.TpCsum
++;
2492 if (hdr
->frame_status_b14
& VRHSTATB_TPHLEN
)
2493 adapter
->if_events
.TpHlen
++;
2494 if (hdr
->frame_status_b14
& VRHSTATB_IPCSUM
)
2495 adapter
->if_events
.IpCsum
++;
2496 if (hdr
->frame_status_b14
& VRHSTATB_IPLERR
)
2497 adapter
->if_events
.IpLen
++;
2498 if (hdr
->frame_status_b14
& VRHSTATB_IPHERR
)
2499 adapter
->if_events
.IpHlen
++;
2501 if (hdr
->frame_statusGB
& VGBSTAT_XPERR
) {
2502 u32 xerr
= hdr
->frame_statusGB
>> VGBSTAT_XERRSHFT
;
2504 if (xerr
== VGBSTAT_XCSERR
)
2505 adapter
->if_events
.TpCsum
++;
2506 if (xerr
== VGBSTAT_XUFLOW
)
2507 adapter
->if_events
.Tprtoflow
++;
2508 if (xerr
== VGBSTAT_XHLEN
)
2509 adapter
->if_events
.TpHlen
++;
2511 if (hdr
->frame_statusGB
& VGBSTAT_NETERR
) {
2514 frame_statusGB
>> VGBSTAT_NERRSHFT
) &
2516 if (nerr
== VGBSTAT_NCSERR
)
2517 adapter
->if_events
.IpCsum
++;
2518 if (nerr
== VGBSTAT_NUFLOW
)
2519 adapter
->if_events
.IpLen
++;
2520 if (nerr
== VGBSTAT_NHLEN
)
2521 adapter
->if_events
.IpHlen
++;
2523 if (hdr
->frame_statusGB
& VGBSTAT_LNKERR
) {
2524 u32 lerr
= hdr
->frame_statusGB
& VGBSTAT_LERRMSK
;
2526 if (lerr
== VGBSTAT_LDEARLY
)
2527 adapter
->if_events
.rcvearly
++;
2528 if (lerr
== VGBSTAT_LBOFLO
)
2529 adapter
->if_events
.Bufov
++;
2530 if (lerr
== VGBSTAT_LCODERR
)
2531 adapter
->if_events
.Code
++;
2532 if (lerr
== VGBSTAT_LDBLNBL
)
2533 adapter
->if_events
.Drbl
++;
2534 if (lerr
== VGBSTAT_LCRCERR
)
2535 adapter
->if_events
.Crc
++;
2536 if (lerr
== VGBSTAT_LOFLO
)
2537 adapter
->if_events
.oflow802
++;
2538 if (lerr
== VGBSTAT_LUFLO
)
2539 adapter
->if_events
.uflow802
++;
2545 #define TCP_OFFLOAD_FRAME_PUSHFLAG 0x10000000
2546 #define M_FAST_PATH 0x0040
2548 static void slic_rcv_handler(struct adapter
*adapter
)
2550 struct net_device
*netdev
= adapter
->netdev
;
2551 struct sk_buff
*skb
;
2552 struct slic_rcvbuf
*rcvbuf
;
2555 while ((skb
= slic_rcvqueue_getnext(adapter
))) {
2558 rcvbuf
= (struct slic_rcvbuf
*)skb
->head
;
2559 adapter
->card
->events
++;
2560 if (rcvbuf
->status
& IRHDDR_ERR
) {
2561 adapter
->rx_errors
++;
2562 slic_rcv_handle_error(adapter
, rcvbuf
);
2563 slic_rcvqueue_reinsert(adapter
, skb
);
2567 if (!slic_mac_filter(adapter
, (struct ether_header
*)
2569 slic_rcvqueue_reinsert(adapter
, skb
);
2572 skb_pull(skb
, SLIC_RCVBUF_HEADSIZE
);
2573 rx_bytes
= (rcvbuf
->length
& IRHDDR_FLEN_MSK
);
2574 skb_put(skb
, rx_bytes
);
2575 netdev
->stats
.rx_packets
++;
2576 netdev
->stats
.rx_bytes
+= rx_bytes
;
2577 #if SLIC_OFFLOAD_IP_CHECKSUM
2578 skb
->ip_summed
= CHECKSUM_UNNECESSARY
;
2581 skb
->dev
= adapter
->netdev
;
2582 skb
->protocol
= eth_type_trans(skb
, skb
->dev
);
2586 #if SLIC_INTERRUPT_PROCESS_LIMIT
2587 if (frames
>= SLIC_RCVQ_MAX_PROCESS_ISR
) {
2588 adapter
->rcv_interrupt_yields
++;
2593 adapter
->max_isr_rcvs
= max(adapter
->max_isr_rcvs
, frames
);
2596 static void slic_xmit_complete(struct adapter
*adapter
)
2598 struct slic_hostcmd
*hcmd
;
2599 struct slic_rspbuf
*rspbuf
;
2601 struct slic_handle_word slic_handle_word
;
2604 rspbuf
= slic_rspqueue_getnext(adapter
);
2607 adapter
->xmit_completes
++;
2608 adapter
->card
->events
++;
2610 Get the complete host command buffer
2612 slic_handle_word
.handle_token
= rspbuf
->hosthandle
;
2614 (struct slic_hostcmd
*)
2615 adapter
->slic_handles
[slic_handle_word
.handle_index
].
2617 /* hcmd = (struct slic_hostcmd *) rspbuf->hosthandle; */
2618 if (hcmd
->type
== SLIC_CMD_DUMB
) {
2620 dev_kfree_skb_irq(hcmd
->skb
);
2621 slic_cmdq_putdone_irq(adapter
, hcmd
);
2624 rspbuf
->hosthandle
= 0;
2627 adapter
->max_isr_xmits
= max(adapter
->max_isr_xmits
, frames
);
2630 static irqreturn_t
slic_interrupt(int irq
, void *dev_id
)
2632 struct net_device
*dev
= (struct net_device
*)dev_id
;
2633 struct adapter
*adapter
= netdev_priv(dev
);
2636 if ((adapter
->pshmem
) && (adapter
->pshmem
->isr
)) {
2637 slic_reg32_write(&adapter
->slic_regs
->slic_icr
,
2638 ICR_INT_MASK
, FLUSH
);
2639 isr
= adapter
->isrcopy
= adapter
->pshmem
->isr
;
2640 adapter
->pshmem
->isr
= 0;
2641 adapter
->num_isrs
++;
2642 switch (adapter
->card
->state
) {
2644 if (isr
& ~ISR_IO
) {
2645 if (isr
& ISR_ERR
) {
2646 adapter
->error_interrupts
++;
2647 if (isr
& ISR_RMISS
) {
2652 struct slic_rcvqueue
*rcvq
=
2656 error_rmiss_interrupts
++;
2658 rcv_count
= rcvq
->count
;
2659 pre_count
= rcvq
->count
;
2660 errors
= rcvq
->errors
;
2662 while (rcvq
->count
<
2663 SLIC_RCVQ_FILLTHRESH
) {
2670 } else if (isr
& ISR_XDROP
) {
2672 "isr & ISR_ERR [%x] "
2673 "ISR_XDROP \n", isr
);
2676 "isr & ISR_ERR [%x]\n",
2681 if (isr
& ISR_LEVENT
) {
2682 adapter
->linkevent_interrupts
++;
2683 slic_link_event_handler(adapter
);
2686 if ((isr
& ISR_UPC
) ||
2687 (isr
& ISR_UPCERR
) || (isr
& ISR_UPCBSY
)) {
2688 adapter
->upr_interrupts
++;
2689 slic_upr_request_complete(adapter
, isr
);
2693 if (isr
& ISR_RCV
) {
2694 adapter
->rcv_interrupts
++;
2695 slic_rcv_handler(adapter
);
2698 if (isr
& ISR_CMD
) {
2699 adapter
->xmit_interrupts
++;
2700 slic_xmit_complete(adapter
);
2705 if ((isr
& ISR_UPC
) ||
2706 (isr
& ISR_UPCERR
) || (isr
& ISR_UPCBSY
)) {
2707 adapter
->upr_interrupts
++;
2708 slic_upr_request_complete(adapter
, isr
);
2713 adapter
->isrcopy
= 0;
2714 adapter
->all_reg_writes
+= 2;
2715 adapter
->isr_reg_writes
++;
2716 slic_reg32_write(&adapter
->slic_regs
->slic_isr
, 0, FLUSH
);
2718 adapter
->false_interrupts
++;
2723 #define NORMAL_ETHFRAME 0
2725 static netdev_tx_t
slic_xmit_start(struct sk_buff
*skb
, struct net_device
*dev
)
2727 struct sliccard
*card
;
2728 struct adapter
*adapter
= netdev_priv(dev
);
2729 struct slic_hostcmd
*hcmd
= NULL
;
2731 void *offloadcmd
= NULL
;
2733 card
= adapter
->card
;
2734 if ((adapter
->linkstate
!= LINK_UP
) ||
2735 (adapter
->state
!= ADAPT_UP
) || (card
->state
!= CARD_UP
)) {
2736 status
= XMIT_FAIL_LINK_STATE
;
2739 } else if (skb
->len
== 0) {
2740 status
= XMIT_FAIL_ZERO_LENGTH
;
2744 hcmd
= slic_cmdq_getfree(adapter
);
2746 adapter
->xmitq_full
= 1;
2747 status
= XMIT_FAIL_HOSTCMD_FAIL
;
2752 hcmd
->type
= SLIC_CMD_DUMB
;
2753 slic_xmit_build_request(adapter
, hcmd
, skb
);
2754 dev
->stats
.tx_packets
++;
2755 dev
->stats
.tx_bytes
+= skb
->len
;
2758 if (adapter
->kill_card
) {
2759 struct slic_host64_cmd ihcmd
;
2761 ihcmd
= &hcmd
->cmd64
;
2763 ihcmd
->flags
|= 0x40;
2764 adapter
->kill_card
= 0; /* only do this once */
2767 if (hcmd
->paddrh
== 0) {
2768 slic_reg32_write(&adapter
->slic_regs
->slic_cbar
,
2769 (hcmd
->paddrl
| hcmd
->cmdsize
), DONT_FLUSH
);
2771 slic_reg64_write(adapter
, &adapter
->slic_regs
->slic_cbar64
,
2772 (hcmd
->paddrl
| hcmd
->cmdsize
),
2773 &adapter
->slic_regs
->slic_addr_upper
,
2774 hcmd
->paddrh
, DONT_FLUSH
);
2777 return NETDEV_TX_OK
;
2779 slic_xmit_fail(adapter
, skb
, offloadcmd
, NORMAL_ETHFRAME
, status
);
2784 static void slic_adapter_freeresources(struct adapter
*adapter
)
2786 slic_init_cleanup(adapter
);
2787 adapter
->error_interrupts
= 0;
2788 adapter
->rcv_interrupts
= 0;
2789 adapter
->xmit_interrupts
= 0;
2790 adapter
->linkevent_interrupts
= 0;
2791 adapter
->upr_interrupts
= 0;
2792 adapter
->num_isrs
= 0;
2793 adapter
->xmit_completes
= 0;
2794 adapter
->rcv_broadcasts
= 0;
2795 adapter
->rcv_multicasts
= 0;
2796 adapter
->rcv_unicasts
= 0;
2799 static int slic_adapter_allocresources(struct adapter
*adapter
)
2801 if (!adapter
->intrregistered
) {
2804 spin_unlock_irqrestore(&slic_global
.driver_lock
.lock
,
2805 slic_global
.driver_lock
.flags
);
2807 retval
= request_irq(adapter
->netdev
->irq
,
2810 adapter
->netdev
->name
, adapter
->netdev
);
2812 spin_lock_irqsave(&slic_global
.driver_lock
.lock
,
2813 slic_global
.driver_lock
.flags
);
2816 dev_err(&adapter
->netdev
->dev
,
2817 "request_irq (%s) FAILED [%x]\n",
2818 adapter
->netdev
->name
, retval
);
2821 adapter
->intrregistered
= 1;
2829 * Perform initialization of our slic interface.
2832 static int slic_if_init(struct adapter
*adapter
)
2834 struct sliccard
*card
= adapter
->card
;
2835 struct net_device
*dev
= adapter
->netdev
;
2836 __iomem
struct slic_regs
*slic_regs
= adapter
->slic_regs
;
2837 struct slic_shmem
*pshmem
;
2840 /* adapter should be down at this point */
2841 if (adapter
->state
!= ADAPT_DOWN
) {
2842 dev_err(&dev
->dev
, "%s: adapter->state != ADAPT_DOWN\n",
2848 adapter
->devflags_prev
= dev
->flags
;
2849 adapter
->macopts
= MAC_DIRECTED
;
2851 if (dev
->flags
& IFF_BROADCAST
)
2852 adapter
->macopts
|= MAC_BCAST
;
2853 if (dev
->flags
& IFF_PROMISC
)
2854 adapter
->macopts
|= MAC_PROMISC
;
2855 if (dev
->flags
& IFF_ALLMULTI
)
2856 adapter
->macopts
|= MAC_ALLMCAST
;
2857 if (dev
->flags
& IFF_MULTICAST
)
2858 adapter
->macopts
|= MAC_MCAST
;
2860 rc
= slic_adapter_allocresources(adapter
);
2863 "%s: slic_adapter_allocresources FAILED %x\n",
2865 slic_adapter_freeresources(adapter
);
2869 if (!adapter
->queues_initialized
) {
2870 rc
= slic_rspqueue_init(adapter
);
2873 rc
= slic_cmdq_init(adapter
);
2876 rc
= slic_rcvqueue_init(adapter
);
2879 adapter
->queues_initialized
= 1;
2882 slic_reg32_write(&slic_regs
->slic_icr
, ICR_INT_OFF
, FLUSH
);
2885 if (!adapter
->isp_initialized
) {
2886 pshmem
= (struct slic_shmem
*)(unsigned long)
2887 adapter
->phys_shmem
;
2889 spin_lock_irqsave(&adapter
->bit64reglock
.lock
,
2890 adapter
->bit64reglock
.flags
);
2892 #if BITS_PER_LONG == 64
2893 slic_reg32_write(&slic_regs
->slic_addr_upper
,
2894 SLIC_GET_ADDR_HIGH(&pshmem
->isr
), DONT_FLUSH
);
2895 slic_reg32_write(&slic_regs
->slic_isp
,
2896 SLIC_GET_ADDR_LOW(&pshmem
->isr
), FLUSH
);
2898 slic_reg32_write(&slic_regs
->slic_addr_upper
, 0, DONT_FLUSH
);
2899 slic_reg32_write(&slic_regs
->slic_isp
, (u32
)&pshmem
->isr
, FLUSH
);
2901 spin_unlock_irqrestore(&adapter
->bit64reglock
.lock
,
2902 adapter
->bit64reglock
.flags
);
2903 adapter
->isp_initialized
= 1;
2906 adapter
->state
= ADAPT_UP
;
2907 if (!card
->loadtimerset
) {
2908 init_timer(&card
->loadtimer
);
2909 card
->loadtimer
.expires
=
2910 jiffies
+ (SLIC_LOADTIMER_PERIOD
* HZ
);
2911 card
->loadtimer
.data
= (ulong
) card
;
2912 card
->loadtimer
.function
= &slic_timer_load_check
;
2913 add_timer(&card
->loadtimer
);
2915 card
->loadtimerset
= 1;
2918 if (!adapter
->pingtimerset
) {
2919 init_timer(&adapter
->pingtimer
);
2920 adapter
->pingtimer
.expires
=
2921 jiffies
+ (PING_TIMER_INTERVAL
* HZ
);
2922 adapter
->pingtimer
.data
= (ulong
) dev
;
2923 adapter
->pingtimer
.function
= &slic_timer_ping
;
2924 add_timer(&adapter
->pingtimer
);
2925 adapter
->pingtimerset
= 1;
2926 adapter
->card
->pingstatus
= ISR_PINGMASK
;
2930 * clear any pending events, then enable interrupts
2932 adapter
->isrcopy
= 0;
2933 adapter
->pshmem
->isr
= 0;
2934 slic_reg32_write(&slic_regs
->slic_isr
, 0, FLUSH
);
2935 slic_reg32_write(&slic_regs
->slic_icr
, ICR_INT_ON
, FLUSH
);
2937 slic_link_config(adapter
, LINK_AUTOSPEED
, LINK_AUTOD
);
2938 slic_link_event_handler(adapter
);
2944 static int slic_entry_open(struct net_device
*dev
)
2946 struct adapter
*adapter
= netdev_priv(dev
);
2947 struct sliccard
*card
= adapter
->card
;
2950 netif_stop_queue(adapter
->netdev
);
2952 spin_lock_irqsave(&slic_global
.driver_lock
.lock
,
2953 slic_global
.driver_lock
.flags
);
2954 if (!adapter
->activated
) {
2955 card
->adapters_activated
++;
2956 slic_global
.num_slic_ports_active
++;
2957 adapter
->activated
= 1;
2959 status
= slic_if_init(adapter
);
2962 if (adapter
->activated
) {
2963 card
->adapters_activated
--;
2964 slic_global
.num_slic_ports_active
--;
2965 adapter
->activated
= 0;
2970 card
->master
= adapter
;
2973 spin_unlock_irqrestore(&slic_global
.driver_lock
.lock
,
2974 slic_global
.driver_lock
.flags
);
2978 static void slic_card_cleanup(struct sliccard
*card
)
2980 if (card
->loadtimerset
) {
2981 card
->loadtimerset
= 0;
2982 del_timer(&card
->loadtimer
);
2985 slic_debug_card_destroy(card
);
2990 static void slic_entry_remove(struct pci_dev
*pcidev
)
2992 struct net_device
*dev
= pci_get_drvdata(pcidev
);
2995 struct adapter
*adapter
= netdev_priv(dev
);
2996 struct sliccard
*card
;
2997 struct mcast_address
*mcaddr
, *mlist
;
2999 slic_adapter_freeresources(adapter
);
3000 slic_unmap_mmio_space(adapter
);
3001 unregister_netdev(dev
);
3003 mmio_start
= pci_resource_start(pcidev
, 0);
3004 mmio_len
= pci_resource_len(pcidev
, 0);
3006 release_mem_region(mmio_start
, mmio_len
);
3008 iounmap((void __iomem
*)dev
->base_addr
);
3009 /* free multicast addresses */
3010 mlist
= adapter
->mcastaddrs
;
3013 mlist
= mlist
->next
;
3016 card
= adapter
->card
;
3017 card
->adapters_allocated
--;
3018 adapter
->allocated
= 0;
3019 if (!card
->adapters_allocated
) {
3020 struct sliccard
*curr_card
= slic_global
.slic_card
;
3021 if (curr_card
== card
) {
3022 slic_global
.slic_card
= card
->next
;
3024 while (curr_card
->next
!= card
)
3025 curr_card
= curr_card
->next
;
3026 curr_card
->next
= card
->next
;
3028 slic_global
.num_slic_cards
--;
3029 slic_card_cleanup(card
);
3032 pci_release_regions(pcidev
);
3033 pci_disable_device(pcidev
);
3036 static int slic_entry_halt(struct net_device
*dev
)
3038 struct adapter
*adapter
= netdev_priv(dev
);
3039 struct sliccard
*card
= adapter
->card
;
3040 __iomem
struct slic_regs
*slic_regs
= adapter
->slic_regs
;
3042 spin_lock_irqsave(&slic_global
.driver_lock
.lock
,
3043 slic_global
.driver_lock
.flags
);
3044 netif_stop_queue(adapter
->netdev
);
3045 adapter
->state
= ADAPT_DOWN
;
3046 adapter
->linkstate
= LINK_DOWN
;
3047 adapter
->upr_list
= NULL
;
3048 adapter
->upr_busy
= 0;
3049 adapter
->devflags_prev
= 0;
3050 slic_reg32_write(&slic_regs
->slic_icr
, ICR_INT_OFF
, FLUSH
);
3051 adapter
->all_reg_writes
++;
3052 adapter
->icr_reg_writes
++;
3053 slic_config_clear(adapter
);
3054 if (adapter
->activated
) {
3055 card
->adapters_activated
--;
3056 slic_global
.num_slic_ports_active
--;
3057 adapter
->activated
= 0;
3059 #ifdef AUTOMATIC_RESET
3060 slic_reg32_write(&slic_regs
->slic_reset_iface
, 0, FLUSH
);
3063 * Reset the adapter's cmd queues
3065 slic_cmdq_reset(adapter
);
3067 #ifdef AUTOMATIC_RESET
3068 if (!card
->adapters_activated
)
3069 slic_card_init(card
, adapter
);
3072 spin_unlock_irqrestore(&slic_global
.driver_lock
.lock
,
3073 slic_global
.driver_lock
.flags
);
3077 static struct net_device_stats
*slic_get_stats(struct net_device
*dev
)
3079 struct adapter
*adapter
= netdev_priv(dev
);
3081 dev
->stats
.collisions
= adapter
->slic_stats
.iface
.xmit_collisions
;
3082 dev
->stats
.rx_errors
= adapter
->slic_stats
.iface
.rcv_errors
;
3083 dev
->stats
.tx_errors
= adapter
->slic_stats
.iface
.xmt_errors
;
3084 dev
->stats
.rx_missed_errors
= adapter
->slic_stats
.iface
.rcv_discards
;
3085 dev
->stats
.tx_heartbeat_errors
= 0;
3086 dev
->stats
.tx_aborted_errors
= 0;
3087 dev
->stats
.tx_window_errors
= 0;
3088 dev
->stats
.tx_fifo_errors
= 0;
3089 dev
->stats
.rx_frame_errors
= 0;
3090 dev
->stats
.rx_length_errors
= 0;
3095 static int slic_ioctl(struct net_device
*dev
, struct ifreq
*rq
, int cmd
)
3097 struct adapter
*adapter
= netdev_priv(dev
);
3098 struct ethtool_cmd edata
;
3099 struct ethtool_cmd ecmd
;
3104 case SIOCSLICSETINTAGG
:
3105 if (copy_from_user(data
, rq
->ifr_data
, 28))
3108 dev_err(&dev
->dev
, "%s: set interrupt aggregation to %d\n",
3110 slic_intagg_set(adapter
, intagg
);
3113 #ifdef SLIC_TRACE_DUMP_ENABLED
3114 case SIOCSLICTRACEDUMP
:
3117 DBG_IOCTL("slic_ioctl SIOCSLIC_TRACE_DUMP\n");
3119 if (copy_from_user(data
, rq
->ifr_data
, 28)) {
3121 ("slic: copy_from_user FAILED getting initial simba param\n");
3126 if (tracemon_request
== SLIC_DUMP_DONE
) {
3128 ("ATK Diagnostic Trace Dump Requested\n");
3129 tracemon_request
= SLIC_DUMP_REQUESTED
;
3130 tracemon_request_type
= value
;
3131 tracemon_timestamp
= jiffies
;
3132 } else if ((tracemon_request
== SLIC_DUMP_REQUESTED
) ||
3133 (tracemon_request
==
3134 SLIC_DUMP_IN_PROGRESS
)) {
3136 ("ATK Diagnostic Trace Dump Requested but already in progress... ignore\n");
3139 ("ATK Diagnostic Trace Dump Requested\n");
3140 tracemon_request
= SLIC_DUMP_REQUESTED
;
3141 tracemon_request_type
= value
;
3142 tracemon_timestamp
= jiffies
;
3148 if (copy_from_user(&ecmd
, rq
->ifr_data
, sizeof(ecmd
)))
3151 if (ecmd
.cmd
== ETHTOOL_GSET
) {
3152 memset(&edata
, 0, sizeof(edata
));
3153 edata
.supported
= (SUPPORTED_10baseT_Half
|
3154 SUPPORTED_10baseT_Full
|
3155 SUPPORTED_100baseT_Half
|
3156 SUPPORTED_100baseT_Full
|
3157 SUPPORTED_Autoneg
| SUPPORTED_MII
);
3158 edata
.port
= PORT_MII
;
3159 edata
.transceiver
= XCVR_INTERNAL
;
3160 edata
.phy_address
= 0;
3161 if (adapter
->linkspeed
== LINK_100MB
)
3162 edata
.speed
= SPEED_100
;
3163 else if (adapter
->linkspeed
== LINK_10MB
)
3164 edata
.speed
= SPEED_10
;
3168 if (adapter
->linkduplex
== LINK_FULLD
)
3169 edata
.duplex
= DUPLEX_FULL
;
3171 edata
.duplex
= DUPLEX_HALF
;
3173 edata
.autoneg
= AUTONEG_ENABLE
;
3176 if (copy_to_user(rq
->ifr_data
, &edata
, sizeof(edata
)))
3179 } else if (ecmd
.cmd
== ETHTOOL_SSET
) {
3180 if (!capable(CAP_NET_ADMIN
))
3183 if (adapter
->linkspeed
== LINK_100MB
)
3184 edata
.speed
= SPEED_100
;
3185 else if (adapter
->linkspeed
== LINK_10MB
)
3186 edata
.speed
= SPEED_10
;
3190 if (adapter
->linkduplex
== LINK_FULLD
)
3191 edata
.duplex
= DUPLEX_FULL
;
3193 edata
.duplex
= DUPLEX_HALF
;
3195 edata
.autoneg
= AUTONEG_ENABLE
;
3198 if ((ecmd
.speed
!= edata
.speed
) ||
3199 (ecmd
.duplex
!= edata
.duplex
)) {
3203 if (ecmd
.speed
== SPEED_10
)
3206 speed
= PCR_SPEED_100
;
3207 if (ecmd
.duplex
== DUPLEX_FULL
)
3208 duplex
= PCR_DUPLEX_FULL
;
3211 slic_link_config(adapter
, speed
, duplex
);
3212 slic_link_event_handler(adapter
);
3221 static void slic_config_pci(struct pci_dev
*pcidev
)
3226 pci_read_config_word(pcidev
, PCI_COMMAND
, &pci_command
);
3228 new_command
= pci_command
| PCI_COMMAND_MASTER
3229 | PCI_COMMAND_MEMORY
3230 | PCI_COMMAND_INVALIDATE
3231 | PCI_COMMAND_PARITY
| PCI_COMMAND_SERR
| PCI_COMMAND_FAST_BACK
;
3232 if (pci_command
!= new_command
)
3233 pci_write_config_word(pcidev
, PCI_COMMAND
, new_command
);
3236 static int slic_card_init(struct sliccard
*card
, struct adapter
*adapter
)
3238 __iomem
struct slic_regs
*slic_regs
= adapter
->slic_regs
;
3239 struct slic_eeprom
*peeprom
;
3240 struct oslic_eeprom
*pOeeprom
;
3241 dma_addr_t phys_config
;
3245 struct slic_shmem
*pshmem
;
3247 uint macaddrs
= card
->card_size
;
3252 struct slic_config_mac
*pmac
;
3253 unsigned char fruformat
;
3254 unsigned char oemfruformat
;
3255 struct atk_fru
*patkfru
;
3256 union oemfru
*poemfru
;
3258 /* Reset everything except PCI configuration space */
3259 slic_soft_reset(adapter
);
3261 /* Download the microcode */
3262 status
= slic_card_download(adapter
);
3265 dev_err(&adapter
->pcidev
->dev
,
3266 "download failed bus %d slot %d\n",
3267 adapter
->busnumber
, adapter
->slotnumber
);
3271 if (!card
->config_set
) {
3272 peeprom
= pci_alloc_consistent(adapter
->pcidev
,
3273 sizeof(struct slic_eeprom
),
3276 phys_configl
= SLIC_GET_ADDR_LOW(phys_config
);
3277 phys_configh
= SLIC_GET_ADDR_HIGH(phys_config
);
3280 dev_err(&adapter
->pcidev
->dev
,
3281 "eeprom read failed to get memory "
3282 "bus %d slot %d\n", adapter
->busnumber
,
3283 adapter
->slotnumber
);
3286 memset(peeprom
, 0, sizeof(struct slic_eeprom
));
3288 slic_reg32_write(&slic_regs
->slic_icr
, ICR_INT_OFF
, FLUSH
);
3290 pshmem
= (struct slic_shmem
*)(unsigned long)
3291 adapter
->phys_shmem
;
3293 spin_lock_irqsave(&adapter
->bit64reglock
.lock
,
3294 adapter
->bit64reglock
.flags
);
3295 slic_reg32_write(&slic_regs
->slic_addr_upper
, 0, DONT_FLUSH
);
3296 slic_reg32_write(&slic_regs
->slic_isp
,
3297 SLIC_GET_ADDR_LOW(&pshmem
->isr
), FLUSH
);
3298 spin_unlock_irqrestore(&adapter
->bit64reglock
.lock
,
3299 adapter
->bit64reglock
.flags
);
3301 slic_config_get(adapter
, phys_configl
, phys_configh
);
3304 if (adapter
->pshmem
->isr
) {
3305 if (adapter
->pshmem
->isr
& ISR_UPC
) {
3306 adapter
->pshmem
->isr
= 0;
3307 slic_reg64_write(adapter
,
3308 &slic_regs
->slic_isp
, 0,
3309 &slic_regs
->slic_addr_upper
,
3311 slic_reg32_write(&slic_regs
->slic_isr
,
3314 slic_upr_request_complete(adapter
, 0);
3317 adapter
->pshmem
->isr
= 0;
3318 slic_reg32_write(&slic_regs
->slic_isr
,
3325 dev_err(&adapter
->pcidev
->dev
,
3326 "%d config data fetch timed out!\n",
3328 slic_reg64_write(adapter
,
3329 &slic_regs
->slic_isp
, 0,
3330 &slic_regs
->slic_addr_upper
,
3337 switch (adapter
->devid
) {
3339 case SLIC_2GB_DEVICE_ID
:
3340 /* extract EEPROM data and pointers to EEPROM data */
3341 pOeeprom
= (struct oslic_eeprom
*) peeprom
;
3342 eecodesize
= pOeeprom
->EecodeSize
;
3343 dramsize
= pOeeprom
->DramSize
;
3344 pmac
= pOeeprom
->MacInfo
;
3345 fruformat
= pOeeprom
->FruFormat
;
3346 patkfru
= &pOeeprom
->AtkFru
;
3347 oemfruformat
= pOeeprom
->OemFruFormat
;
3348 poemfru
= &pOeeprom
->OemFru
;
3350 /* Minor kludge for Oasis card
3351 get 2 MAC addresses from the
3352 EEPROM to ensure that function 1
3353 gets the Port 1 MAC address */
3356 /* extract EEPROM data and pointers to EEPROM data */
3357 eecodesize
= peeprom
->EecodeSize
;
3358 dramsize
= peeprom
->DramSize
;
3359 pmac
= peeprom
->u2
.mac
.MacInfo
;
3360 fruformat
= peeprom
->FruFormat
;
3361 patkfru
= &peeprom
->AtkFru
;
3362 oemfruformat
= peeprom
->OemFruFormat
;
3363 poemfru
= &peeprom
->OemFru
;
3367 card
->config
.EepromValid
= false;
3369 /* see if the EEPROM is valid by checking it's checksum */
3370 if ((eecodesize
<= MAX_EECODE_SIZE
) &&
3371 (eecodesize
>= MIN_EECODE_SIZE
)) {
3374 *(u16
*) ((char *) peeprom
+ (eecodesize
- 2));
3376 calculate the EEPROM checksum
3379 ~slic_eeprom_cksum((char *) peeprom
,
3382 if the ucdoe chksum flag bit worked,
3383 we wouldn't need this
3385 if (ee_chksum
== calc_chksum
)
3386 card
->config
.EepromValid
= true;
3388 /* copy in the DRAM size */
3389 card
->config
.DramSize
= dramsize
;
3391 /* copy in the MAC address(es) */
3392 for (i
= 0; i
< macaddrs
; i
++) {
3393 memcpy(&card
->config
.MacInfo
[i
],
3394 &pmac
[i
], sizeof(struct slic_config_mac
));
3397 /* copy the Alacritech FRU information */
3398 card
->config
.FruFormat
= fruformat
;
3399 memcpy(&card
->config
.AtkFru
, patkfru
,
3400 sizeof(struct atk_fru
));
3402 pci_free_consistent(adapter
->pcidev
,
3403 sizeof(struct slic_eeprom
),
3404 peeprom
, phys_config
);
3406 if ((!card
->config
.EepromValid
) &&
3407 (adapter
->reg_params
.fail_on_bad_eeprom
)) {
3408 slic_reg64_write(adapter
, &slic_regs
->slic_isp
, 0,
3409 &slic_regs
->slic_addr_upper
,
3411 dev_err(&adapter
->pcidev
->dev
,
3412 "unsupported CONFIGURATION EEPROM invalid\n");
3416 card
->config_set
= 1;
3419 if (slic_card_download_gbrcv(adapter
)) {
3420 dev_err(&adapter
->pcidev
->dev
,
3421 "unable to download GB receive microcode\n");
3425 if (slic_global
.dynamic_intagg
)
3426 slic_intagg_set(adapter
, 0);
3428 slic_intagg_set(adapter
, intagg_delay
);
3431 * Initialize ping status to "ok"
3433 card
->pingstatus
= ISR_PINGMASK
;
3436 * Lastly, mark our card state as up and return success
3438 card
->state
= CARD_UP
;
3439 card
->reset_in_progress
= 0;
3444 static void slic_init_driver(void)
3446 if (slic_first_init
) {
3447 slic_first_init
= 0;
3448 spin_lock_init(&slic_global
.driver_lock
.lock
);
3453 static void slic_init_adapter(struct net_device
*netdev
,
3454 struct pci_dev
*pcidev
,
3455 const struct pci_device_id
*pci_tbl_entry
,
3456 void __iomem
*memaddr
, int chip_idx
)
3459 struct slic_handle
*pslic_handle
;
3460 struct adapter
*adapter
= netdev_priv(netdev
);
3462 /* adapter->pcidev = pcidev;*/
3463 adapter
->vendid
= pci_tbl_entry
->vendor
;
3464 adapter
->devid
= pci_tbl_entry
->device
;
3465 adapter
->subsysid
= pci_tbl_entry
->subdevice
;
3466 adapter
->busnumber
= pcidev
->bus
->number
;
3467 adapter
->slotnumber
= ((pcidev
->devfn
>> 3) & 0x1F);
3468 adapter
->functionnumber
= (pcidev
->devfn
& 0x7);
3469 adapter
->memorylength
= pci_resource_len(pcidev
, 0);
3470 adapter
->slic_regs
= (__iomem
struct slic_regs
*)memaddr
;
3471 adapter
->irq
= pcidev
->irq
;
3472 /* adapter->netdev = netdev;*/
3473 adapter
->next_netdevice
= head_netdevice
;
3474 head_netdevice
= netdev
;
3475 adapter
->chipid
= chip_idx
;
3476 adapter
->port
= 0; /*adapter->functionnumber;*/
3477 adapter
->cardindex
= adapter
->port
;
3478 adapter
->memorybase
= memaddr
;
3479 spin_lock_init(&adapter
->upr_lock
.lock
);
3480 spin_lock_init(&adapter
->bit64reglock
.lock
);
3481 spin_lock_init(&adapter
->adapter_lock
.lock
);
3482 spin_lock_init(&adapter
->reset_lock
.lock
);
3483 spin_lock_init(&adapter
->handle_lock
.lock
);
3485 adapter
->card_size
= 1;
3487 Initialize slic_handle array
3490 Start with 1. 0 is an invalid host handle.
3492 for (index
= 1, pslic_handle
= &adapter
->slic_handles
[1];
3493 index
< SLIC_CMDQ_MAXCMDS
; index
++, pslic_handle
++) {
3495 pslic_handle
->token
.handle_index
= index
;
3496 pslic_handle
->type
= SLIC_HANDLE_FREE
;
3497 pslic_handle
->next
= adapter
->pfree_slic_handles
;
3498 adapter
->pfree_slic_handles
= pslic_handle
;
3500 adapter
->pshmem
= (struct slic_shmem
*)
3501 pci_alloc_consistent(adapter
->pcidev
,
3502 sizeof(struct slic_shmem
),
3505 if (adapter
->pshmem
)
3506 memset(adapter
->pshmem
, 0, sizeof(struct slic_shmem
));
3509 static const struct net_device_ops slic_netdev_ops
= {
3510 .ndo_open
= slic_entry_open
,
3511 .ndo_stop
= slic_entry_halt
,
3512 .ndo_start_xmit
= slic_xmit_start
,
3513 .ndo_do_ioctl
= slic_ioctl
,
3514 .ndo_set_mac_address
= slic_mac_set_address
,
3515 .ndo_get_stats
= slic_get_stats
,
3516 .ndo_set_rx_mode
= slic_mcast_set_list
,
3517 .ndo_validate_addr
= eth_validate_addr
,
3518 .ndo_change_mtu
= eth_change_mtu
,
3521 static u32
slic_card_locate(struct adapter
*adapter
)
3523 struct sliccard
*card
= slic_global
.slic_card
;
3524 struct physcard
*physcard
= slic_global
.phys_card
;
3526 u16 __iomem
*hostid_reg
;
3528 uint rdhostid_offset
= 0;
3530 switch (adapter
->devid
) {
3531 case SLIC_2GB_DEVICE_ID
:
3532 rdhostid_offset
= SLIC_RDHOSTID_2GB
;
3534 case SLIC_1GB_DEVICE_ID
:
3535 rdhostid_offset
= SLIC_RDHOSTID_1GB
;
3542 (u16 __iomem
*) (((u8 __iomem
*) (adapter
->slic_regs
)) +
3545 /* read the 16 bit hostid from SRAM */
3546 card_hostid
= (ushort
) readw(hostid_reg
);
3548 /* Initialize a new card structure if need be */
3549 if (card_hostid
== SLIC_HOSTID_DEFAULT
) {
3550 card
= kzalloc(sizeof(struct sliccard
), GFP_KERNEL
);
3554 card
->next
= slic_global
.slic_card
;
3555 slic_global
.slic_card
= card
;
3556 card
->busnumber
= adapter
->busnumber
;
3557 card
->slotnumber
= adapter
->slotnumber
;
3559 /* Find an available cardnum */
3560 for (i
= 0; i
< SLIC_MAX_CARDS
; i
++) {
3561 if (slic_global
.cardnuminuse
[i
] == 0) {
3562 slic_global
.cardnuminuse
[i
] = 1;
3567 slic_global
.num_slic_cards
++;
3569 slic_debug_card_create(card
);
3571 /* Card exists, find the card this adapter belongs to */
3573 if (card
->cardnum
== card_hostid
)
3581 /* Put the adapter in the card's adapter list */
3582 if (!card
->adapter
[adapter
->port
]) {
3583 card
->adapter
[adapter
->port
] = adapter
;
3584 adapter
->card
= card
;
3587 card
->card_size
= 1; /* one port per *logical* card */
3590 for (i
= 0; i
< SLIC_MAX_PORTS
; i
++) {
3591 if (physcard
->adapter
[i
])
3594 if (i
== SLIC_MAX_PORTS
)
3597 if (physcard
->adapter
[i
]->slotnumber
== adapter
->slotnumber
)
3599 physcard
= physcard
->next
;
3602 /* no structure allocated for this physical card yet */
3603 physcard
= kzalloc(sizeof(struct physcard
), GFP_ATOMIC
);
3605 if (card_hostid
== SLIC_HOSTID_DEFAULT
)
3610 physcard
->next
= slic_global
.phys_card
;
3611 slic_global
.phys_card
= physcard
;
3612 physcard
->adapters_allocd
= 1;
3614 physcard
->adapters_allocd
++;
3616 /* Note - this is ZERO relative */
3617 adapter
->physport
= physcard
->adapters_allocd
- 1;
3619 physcard
->adapter
[adapter
->physport
] = adapter
;
3620 adapter
->physcard
= physcard
;
3625 static int slic_entry_probe(struct pci_dev
*pcidev
,
3626 const struct pci_device_id
*pci_tbl_entry
)
3628 static int cards_found
;
3629 static int did_version
;
3631 struct net_device
*netdev
;
3632 struct adapter
*adapter
;
3633 void __iomem
*memmapped_ioaddr
= NULL
;
3635 ulong mmio_start
= 0;
3637 struct sliccard
*card
= NULL
;
3638 int pci_using_dac
= 0;
3640 slic_global
.dynamic_intagg
= dynamic_intagg
;
3642 err
= pci_enable_device(pcidev
);
3647 if (slic_debug
> 0 && did_version
++ == 0) {
3648 printk(KERN_DEBUG
"%s\n", slic_banner
);
3649 printk(KERN_DEBUG
"%s\n", slic_proc_version
);
3652 if (!pci_set_dma_mask(pcidev
, DMA_BIT_MASK(64))) {
3654 err
= pci_set_consistent_dma_mask(pcidev
, DMA_BIT_MASK(64));
3656 dev_err(&pcidev
->dev
, "unable to obtain 64-bit DMA for "
3657 "consistent allocations\n");
3658 goto err_out_disable_pci
;
3661 err
= pci_set_dma_mask(pcidev
, DMA_BIT_MASK(32));
3663 dev_err(&pcidev
->dev
, "no usable DMA configuration\n");
3664 goto err_out_disable_pci
;
3667 pci_set_consistent_dma_mask(pcidev
, DMA_BIT_MASK(32));
3670 err
= pci_request_regions(pcidev
, DRV_NAME
);
3672 dev_err(&pcidev
->dev
, "can't obtain PCI resources\n");
3673 goto err_out_disable_pci
;
3676 pci_set_master(pcidev
);
3678 netdev
= alloc_etherdev(sizeof(struct adapter
));
3681 goto err_out_exit_slic_probe
;
3684 SET_NETDEV_DEV(netdev
, &pcidev
->dev
);
3686 pci_set_drvdata(pcidev
, netdev
);
3687 adapter
= netdev_priv(netdev
);
3688 adapter
->netdev
= netdev
;
3689 adapter
->pcidev
= pcidev
;
3691 netdev
->features
|= NETIF_F_HIGHDMA
;
3693 mmio_start
= pci_resource_start(pcidev
, 0);
3694 mmio_len
= pci_resource_len(pcidev
, 0);
3697 /* memmapped_ioaddr = (u32)ioremap_nocache(mmio_start, mmio_len);*/
3698 memmapped_ioaddr
= ioremap(mmio_start
, mmio_len
);
3699 if (!memmapped_ioaddr
) {
3700 dev_err(&pcidev
->dev
, "cannot remap MMIO region %lx @ %lx\n",
3701 mmio_len
, mmio_start
);
3703 goto err_out_free_netdev
;
3706 slic_config_pci(pcidev
);
3710 slic_init_adapter(netdev
,
3711 pcidev
, pci_tbl_entry
, memmapped_ioaddr
, cards_found
);
3713 err
= slic_card_locate(adapter
);
3715 dev_err(&pcidev
->dev
, "cannot locate card\n");
3716 goto err_out_free_mmio_region
;
3719 card
= adapter
->card
;
3721 if (!adapter
->allocated
) {
3722 card
->adapters_allocated
++;
3723 adapter
->allocated
= 1;
3726 status
= slic_card_init(card
, adapter
);
3729 card
->state
= CARD_FAIL
;
3730 adapter
->state
= ADAPT_FAIL
;
3731 adapter
->linkstate
= LINK_DOWN
;
3732 dev_err(&pcidev
->dev
, "FAILED status[%x]\n", status
);
3734 slic_adapter_set_hwaddr(adapter
);
3737 netdev
->base_addr
= (unsigned long)adapter
->memorybase
;
3738 netdev
->irq
= adapter
->irq
;
3739 netdev
->netdev_ops
= &slic_netdev_ops
;
3741 slic_debug_adapter_create(adapter
);
3743 strcpy(netdev
->name
, "eth%d");
3744 err
= register_netdev(netdev
);
3746 dev_err(&pcidev
->dev
, "Cannot register net device, aborting.\n");
3755 iounmap(memmapped_ioaddr
);
3756 err_out_free_mmio_region
:
3757 release_mem_region(mmio_start
, mmio_len
);
3758 err_out_free_netdev
:
3759 free_netdev(netdev
);
3760 err_out_exit_slic_probe
:
3761 pci_release_regions(pcidev
);
3762 err_out_disable_pci
:
3763 pci_disable_device(pcidev
);
3767 static struct pci_driver slic_driver
= {
3769 .id_table
= slic_pci_tbl
,
3770 .probe
= slic_entry_probe
,
3771 .remove
= slic_entry_remove
,
3774 static int __init
slic_module_init(void)
3778 if (debug
>= 0 && slic_debug
!= debug
)
3779 printk(KERN_DEBUG KBUILD_MODNAME
": debug level is %d.\n",
3784 return pci_register_driver(&slic_driver
);
3787 static void __exit
slic_module_cleanup(void)
3789 pci_unregister_driver(&slic_driver
);
3790 slic_debug_cleanup();
3793 module_init(slic_module_init
);
3794 module_exit(slic_module_cleanup
);