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 acutally 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/etherdevice.h>
80 #include <linux/skbuff.h>
81 #include <linux/delay.h>
82 #include <linux/debugfs.h>
83 #include <linux/seq_file.h>
84 #include <linux/kthread.h>
85 #include <linux/module.h>
86 #include <linux/moduleparam.h>
88 #include <linux/firmware.h>
89 #include <linux/types.h>
90 #include <linux/dma-mapping.h>
91 #include <linux/mii.h>
92 #include <linux/if_vlan.h>
93 #include <asm/unaligned.h>
95 #include <linux/ethtool.h>
96 #include <linux/uaccess.h>
100 static uint slic_first_init
= 1;
101 static char *slic_banner
= "Alacritech SLIC Technology(tm) Server "\
102 "and Storage Accelerator (Non-Accelerated)";
104 static char *slic_proc_version
= "2.0.351 2006/07/14 12:26:00";
105 static char *slic_product_name
= "SLIC Technology(tm) Server "\
106 "and Storage Accelerator (Non-Accelerated)";
107 static char *slic_vendor
= "Alacritech, Inc.";
109 static int slic_debug
= 1;
110 static int debug
= -1;
111 static struct net_device
*head_netdevice
;
113 static struct base_driver slic_global
= { {}, 0, 0, 0, 1, NULL
, NULL
};
114 static int intagg_delay
= 100;
115 static u32 dynamic_intagg
;
116 static unsigned int rcv_count
;
117 static struct dentry
*slic_debugfs
;
119 #define DRV_NAME "slicoss"
120 #define DRV_VERSION "2.0.1"
121 #define DRV_AUTHOR "Alacritech, Inc. Engineering"
122 #define DRV_DESCRIPTION "Alacritech SLIC Techonology(tm) "\
123 "Non-Accelerated Driver"
124 #define DRV_COPYRIGHT "Copyright 2000-2006 Alacritech, Inc. "\
125 "All rights reserved."
126 #define PFX DRV_NAME " "
128 MODULE_AUTHOR(DRV_AUTHOR
);
129 MODULE_DESCRIPTION(DRV_DESCRIPTION
);
130 MODULE_LICENSE("Dual BSD/GPL");
132 module_param(dynamic_intagg
, int, 0);
133 MODULE_PARM_DESC(dynamic_intagg
, "Dynamic Interrupt Aggregation Setting");
134 module_param(intagg_delay
, int, 0);
135 MODULE_PARM_DESC(intagg_delay
, "uSec Interrupt Aggregation Delay");
137 static DEFINE_PCI_DEVICE_TABLE(slic_pci_tbl
) = {
138 { PCI_DEVICE(PCI_VENDOR_ID_ALACRITECH
, SLIC_1GB_DEVICE_ID
) },
139 { PCI_DEVICE(PCI_VENDOR_ID_ALACRITECH
, SLIC_2GB_DEVICE_ID
) },
143 MODULE_DEVICE_TABLE(pci
, slic_pci_tbl
);
149 static void slic_assert_fail(void)
153 cpuid
= smp_processor_id();
154 curr_pid
= current
->pid
;
156 printk(KERN_ERR
"%s CPU # %d ---- PID # %d\n",
157 __func__
, cpuid
, curr_pid
);
161 #define ASSERT(a) do { \
163 printk(KERN_ERR "slicoss ASSERT() Failure: function %s" \
164 "line %d\n", __func__, __LINE__); \
165 slic_assert_fail(); \
171 #define SLIC_GET_SLIC_HANDLE(_adapter, _pslic_handle) \
173 spin_lock_irqsave(&_adapter->handle_lock.lock, \
174 _adapter->handle_lock.flags); \
175 _pslic_handle = _adapter->pfree_slic_handles; \
176 if (_pslic_handle) { \
177 ASSERT(_pslic_handle->type == SLIC_HANDLE_FREE); \
178 _adapter->pfree_slic_handles = _pslic_handle->next; \
180 spin_unlock_irqrestore(&_adapter->handle_lock.lock, \
181 _adapter->handle_lock.flags); \
184 #define SLIC_FREE_SLIC_HANDLE(_adapter, _pslic_handle) \
186 _pslic_handle->type = SLIC_HANDLE_FREE; \
187 spin_lock_irqsave(&_adapter->handle_lock.lock, \
188 _adapter->handle_lock.flags); \
189 _pslic_handle->next = _adapter->pfree_slic_handles; \
190 _adapter->pfree_slic_handles = _pslic_handle; \
191 spin_unlock_irqrestore(&_adapter->handle_lock.lock, \
192 _adapter->handle_lock.flags); \
195 static inline void slic_reg32_write(void __iomem
*reg
, u32 value
, bool flush
)
202 static inline void slic_reg64_write(struct adapter
*adapter
, void __iomem
*reg
,
203 u32 value
, void __iomem
*regh
, u32 paddrh
,
206 spin_lock_irqsave(&adapter
->bit64reglock
.lock
,
207 adapter
->bit64reglock
.flags
);
208 if (paddrh
!= adapter
->curaddrupper
) {
209 adapter
->curaddrupper
= paddrh
;
210 writel(paddrh
, regh
);
215 spin_unlock_irqrestore(&adapter
->bit64reglock
.lock
,
216 adapter
->bit64reglock
.flags
);
220 * Functions to obtain the CRC corresponding to the destination mac address.
221 * This is a standard ethernet CRC in that it is a 32-bit, reflected CRC using
223 * x^32 + x^26 + x^23 + x^22 + x^16 + x^12 + x^11 + x^10 + x^8 + x^7 + x^5 +
226 * After the CRC for the 6 bytes is generated (but before the value is
228 * we must then transpose the value and return bits 30-23.
231 static u32 slic_crc_table
[256]; /* Table of CRCs for all possible byte values */
232 static u32 slic_crc_init
; /* Is table initialized */
235 * Contruct the CRC32 table
237 static void slic_mcast_init_crc32(void)
239 u32 c
; /* CRC shit reg */
240 u32 e
= 0; /* Poly X-or pattern */
242 int k
; /* byte being shifted into crc */
244 static int p
[] = { 0, 1, 2, 4, 5, 7, 8, 10, 11, 12, 16, 22, 23, 26 };
246 for (i
= 0; i
< ARRAY_SIZE(p
); i
++)
247 e
|= 1L << (31 - p
[i
]);
249 for (i
= 1; i
< 256; i
++) {
252 c
= c
& 1 ? (c
>> 1) ^ e
: c
>> 1;
253 slic_crc_table
[i
] = c
;
258 * Return the MAC hast as described above.
260 static unsigned char slic_mcast_get_mac_hash(char *macaddr
)
265 unsigned char machash
= 0;
267 if (!slic_crc_init
) {
268 slic_mcast_init_crc32();
272 crc
= 0xFFFFFFFF; /* Preload shift register, per crc-32 spec */
273 for (i
= 0, p
= macaddr
; i
< 6; ++p
, ++i
)
274 crc
= (crc
>> 8) ^ slic_crc_table
[(crc
^ *p
) & 0xFF];
276 /* Return bits 1-8, transposed */
277 for (i
= 1; i
< 9; i
++)
278 machash
|= (((crc
>> i
) & 1) << (8 - i
));
283 static void slic_mcast_set_bit(struct adapter
*adapter
, char *address
)
285 unsigned char crcpoly
;
287 /* Get the CRC polynomial for the mac address */
288 crcpoly
= slic_mcast_get_mac_hash(address
);
290 /* We only have space on the SLIC for 64 entries. Lop
291 * off the top two bits. (2^6 = 64)
295 /* OR in the new bit into our 64 bit mask. */
296 adapter
->mcastmask
|= (u64
) 1 << crcpoly
;
299 static void slic_mcast_set_mask(struct adapter
*adapter
)
301 __iomem
struct slic_regs
*slic_regs
= adapter
->slic_regs
;
303 if (adapter
->macopts
& (MAC_ALLMCAST
| MAC_PROMISC
)) {
304 /* Turn on all multicast addresses. We have to do this for
305 * promiscuous mode as well as ALLMCAST mode. It saves the
306 * Microcode from having to keep state about the MAC
309 slic_reg32_write(&slic_regs
->slic_mcastlow
, 0xFFFFFFFF, FLUSH
);
310 slic_reg32_write(&slic_regs
->slic_mcasthigh
, 0xFFFFFFFF,
313 /* Commit our multicast mast to the SLIC by writing to the
314 * multicast address mask registers
316 slic_reg32_write(&slic_regs
->slic_mcastlow
,
317 (u32
)(adapter
->mcastmask
& 0xFFFFFFFF), FLUSH
);
318 slic_reg32_write(&slic_regs
->slic_mcasthigh
,
319 (u32
)((adapter
->mcastmask
>> 32) & 0xFFFFFFFF), FLUSH
);
323 static void slic_timer_ping(ulong dev
)
325 struct adapter
*adapter
;
326 struct sliccard
*card
;
329 adapter
= netdev_priv((struct net_device
*)dev
);
331 card
= adapter
->card
;
334 adapter
->pingtimer
.expires
= jiffies
+ (PING_TIMER_INTERVAL
* HZ
);
335 add_timer(&adapter
->pingtimer
);
338 static void slic_unmap_mmio_space(struct adapter
*adapter
)
340 if (adapter
->slic_regs
)
341 iounmap(adapter
->slic_regs
);
342 adapter
->slic_regs
= NULL
;
348 * Write phy control to configure link duplex/speed
351 static void slic_link_config(struct adapter
*adapter
,
352 u32 linkspeed
, u32 linkduplex
)
361 if (adapter
->state
!= ADAPT_UP
)
364 ASSERT((adapter
->devid
== SLIC_1GB_DEVICE_ID
)
365 || (adapter
->devid
== SLIC_2GB_DEVICE_ID
));
367 if (linkspeed
> LINK_1000MB
)
368 linkspeed
= LINK_AUTOSPEED
;
369 if (linkduplex
> LINK_AUTOD
)
370 linkduplex
= LINK_AUTOD
;
372 wphy
= &adapter
->slic_regs
->slic_wphy
;
374 if ((linkspeed
== LINK_AUTOSPEED
) || (linkspeed
== LINK_1000MB
)) {
375 if (adapter
->flags
& ADAPT_FLAGS_FIBERMEDIA
) {
376 /* We've got a fiber gigabit interface, and register
377 * 4 is different in fiber mode than in copper mode
380 /* advertise FD only @1000 Mb */
381 phy_advreg
= (MIICR_REG_4
| (PAR_ADV1000XFD
));
382 /* enable PAUSE frames */
383 phy_advreg
|= PAR_ASYMPAUSE_FIBER
;
384 slic_reg32_write(wphy
, phy_advreg
, FLUSH
);
386 if (linkspeed
== LINK_AUTOSPEED
) {
387 /* reset phy, enable auto-neg */
390 (PCR_RESET
| PCR_AUTONEG
|
392 slic_reg32_write(wphy
, phy_config
, FLUSH
);
393 } else { /* forced 1000 Mb FD*/
394 /* power down phy to break link
395 this may not work) */
396 phy_config
= (MIICR_REG_PCR
| PCR_POWERDOWN
);
397 slic_reg32_write(wphy
, phy_config
, FLUSH
);
398 /* wait, Marvell says 1 sec,
399 try to get away with 10 ms */
402 /* disable auto-neg, set speed/duplex,
403 soft reset phy, powerup */
406 (PCR_RESET
| PCR_SPEED_1000
|
408 slic_reg32_write(wphy
, phy_config
, FLUSH
);
410 } else { /* copper gigabit */
412 /* Auto-Negotiate or 1000 Mb must be auto negotiated
413 * We've got a copper gigabit interface, and
414 * register 4 is different in copper mode than
417 if (linkspeed
== LINK_AUTOSPEED
) {
418 /* advertise 10/100 Mb modes */
421 (PAR_ADV100FD
| PAR_ADV100HD
| PAR_ADV10FD
424 /* linkspeed == LINK_1000MB -
425 don't advertise 10/100 Mb modes */
426 phy_advreg
= MIICR_REG_4
;
428 /* enable PAUSE frames */
429 phy_advreg
|= PAR_ASYMPAUSE
;
430 /* required by the Cicada PHY */
431 phy_advreg
|= PAR_802_3
;
432 slic_reg32_write(wphy
, phy_advreg
, FLUSH
);
433 /* advertise FD only @1000 Mb */
434 phy_gctlreg
= (MIICR_REG_9
| (PGC_ADV1000FD
));
435 slic_reg32_write(wphy
, phy_gctlreg
, FLUSH
);
437 if (adapter
->subsysid
!= SLIC_1GB_CICADA_SUBSYS_ID
) {
439 enable auto crossover */
441 (MIICR_REG_16
| (MRV_REG16_XOVERON
));
442 slic_reg32_write(wphy
, phy_config
, FLUSH
);
444 /* reset phy, enable auto-neg */
447 (PCR_RESET
| PCR_AUTONEG
|
449 slic_reg32_write(wphy
, phy_config
, FLUSH
);
450 } else { /* it's a Cicada PHY */
451 /* enable and restart auto-neg (don't reset) */
454 (PCR_AUTONEG
| PCR_AUTONEG_RST
));
455 slic_reg32_write(wphy
, phy_config
, FLUSH
);
460 if (linkspeed
== LINK_10MB
)
463 speed
= PCR_SPEED_100
;
464 if (linkduplex
== LINK_HALFD
)
467 duplex
= PCR_DUPLEX_FULL
;
469 if (adapter
->subsysid
!= SLIC_1GB_CICADA_SUBSYS_ID
) {
471 disable auto crossover */
472 phy_config
= (MIICR_REG_16
| (MRV_REG16_XOVEROFF
));
473 slic_reg32_write(wphy
, phy_config
, FLUSH
);
476 /* power down phy to break link (this may not work) */
477 phy_config
= (MIICR_REG_PCR
| (PCR_POWERDOWN
| speed
| duplex
));
478 slic_reg32_write(wphy
, phy_config
, FLUSH
);
480 /* wait, Marvell says 1 sec, try to get away with 10 ms */
483 if (adapter
->subsysid
!= SLIC_1GB_CICADA_SUBSYS_ID
) {
485 disable auto-neg, set speed,
486 soft reset phy, powerup */
488 (MIICR_REG_PCR
| (PCR_RESET
| speed
| duplex
));
489 slic_reg32_write(wphy
, phy_config
, FLUSH
);
490 } else { /* it's a Cicada PHY */
491 /* disable auto-neg, set speed, powerup */
492 phy_config
= (MIICR_REG_PCR
| (speed
| duplex
));
493 slic_reg32_write(wphy
, phy_config
, FLUSH
);
498 static int slic_card_download_gbrcv(struct adapter
*adapter
)
500 const struct firmware
*fw
;
501 const char *file
= "";
503 __iomem
struct slic_regs
*slic_regs
= adapter
->slic_regs
;
509 switch (adapter
->devid
) {
510 case SLIC_2GB_DEVICE_ID
:
511 file
= "slicoss/oasisrcvucode.sys";
513 case SLIC_1GB_DEVICE_ID
:
514 file
= "slicoss/gbrcvucode.sys";
521 ret
= request_firmware(&fw
, file
, &adapter
->pcidev
->dev
);
523 dev_err(&adapter
->pcidev
->dev
,
524 "SLICOSS: Failed to load firmware %s\n", file
);
528 rcvucodelen
= *(u32
*)(fw
->data
+ index
);
530 switch (adapter
->devid
) {
531 case SLIC_2GB_DEVICE_ID
:
532 if (rcvucodelen
!= OasisRcvUCodeLen
)
535 case SLIC_1GB_DEVICE_ID
:
536 if (rcvucodelen
!= GBRcvUCodeLen
)
544 slic_reg32_write(&slic_regs
->slic_rcv_wcs
, SLIC_RCVWCS_BEGIN
, FLUSH
);
545 /* download the rcv sequencer ucode */
546 for (codeaddr
= 0; codeaddr
< rcvucodelen
; codeaddr
++) {
547 /* write out instruction address */
548 slic_reg32_write(&slic_regs
->slic_rcv_wcs
, codeaddr
, FLUSH
);
550 instruction
= *(u32
*)(fw
->data
+ index
);
552 /* write out the instruction data low addr */
553 slic_reg32_write(&slic_regs
->slic_rcv_wcs
, instruction
, FLUSH
);
555 instruction
= *(u8
*)(fw
->data
+ index
);
557 /* write out the instruction data high addr */
558 slic_reg32_write(&slic_regs
->slic_rcv_wcs
, (u8
)instruction
,
562 /* download finished */
563 release_firmware(fw
);
564 slic_reg32_write(&slic_regs
->slic_rcv_wcs
, SLIC_RCVWCS_FINISH
, FLUSH
);
568 MODULE_FIRMWARE("slicoss/oasisrcvucode.sys");
569 MODULE_FIRMWARE("slicoss/gbrcvucode.sys");
571 static int slic_card_download(struct adapter
*adapter
)
573 const struct firmware
*fw
;
574 const char *file
= "";
579 __iomem
struct slic_regs
*slic_regs
= adapter
->slic_regs
;
586 int ucode_start
, index
= 0;
588 switch (adapter
->devid
) {
589 case SLIC_2GB_DEVICE_ID
:
590 file
= "slicoss/oasisdownload.sys";
592 case SLIC_1GB_DEVICE_ID
:
593 file
= "slicoss/gbdownload.sys";
599 ret
= request_firmware(&fw
, file
, &adapter
->pcidev
->dev
);
601 dev_err(&adapter
->pcidev
->dev
,
602 "SLICOSS: Failed to load firmware %s\n", file
);
605 numsects
= *(u32
*)(fw
->data
+ index
);
607 ASSERT(numsects
<= 3);
608 for (i
= 0; i
< numsects
; i
++) {
609 sectsize
[i
] = *(u32
*)(fw
->data
+ index
);
612 for (i
= 0; i
< numsects
; i
++) {
613 sectstart
[i
] = *(u32
*)(fw
->data
+ index
);
617 instruction
= *(u32
*)(fw
->data
+ index
);
619 for (section
= 0; section
< numsects
; section
++) {
620 baseaddress
= sectstart
[section
];
621 thissectionsize
= sectsize
[section
] >> 3;
623 for (codeaddr
= 0; codeaddr
< thissectionsize
; codeaddr
++) {
624 /* Write out instruction address */
625 slic_reg32_write(&slic_regs
->slic_wcs
,
626 baseaddress
+ codeaddr
, FLUSH
);
627 /* Write out instruction to low addr */
628 slic_reg32_write(&slic_regs
->slic_wcs
, instruction
, FLUSH
);
629 instruction
= *(u32
*)(fw
->data
+ index
);
632 /* Write out instruction to high addr */
633 slic_reg32_write(&slic_regs
->slic_wcs
, instruction
, FLUSH
);
634 instruction
= *(u32
*)(fw
->data
+ index
);
639 for (section
= 0; section
< numsects
; section
++) {
640 instruction
= *(u32
*)(fw
->data
+ index
);
641 baseaddress
= sectstart
[section
];
642 if (baseaddress
< 0x8000)
644 thissectionsize
= sectsize
[section
] >> 3;
646 for (codeaddr
= 0; codeaddr
< thissectionsize
; codeaddr
++) {
647 /* Write out instruction address */
648 slic_reg32_write(&slic_regs
->slic_wcs
,
649 SLIC_WCS_COMPARE
| (baseaddress
+ codeaddr
),
651 /* Write out instruction to low addr */
652 slic_reg32_write(&slic_regs
->slic_wcs
, instruction
,
654 instruction
= *(u32
*)(fw
->data
+ index
);
656 /* Write out instruction to high addr */
657 slic_reg32_write(&slic_regs
->slic_wcs
, instruction
,
659 instruction
= *(u32
*)(fw
->data
+ index
);
662 /* Check SRAM location zero. If it is non-zero. Abort.*/
663 /* failure = readl((u32 __iomem *)&slic_regs->slic_reset);
665 release_firmware(fw);
670 release_firmware(fw
);
671 /* Everything OK, kick off the card */
673 slic_reg32_write(&slic_regs
->slic_wcs
, SLIC_WCS_START
, FLUSH
);
675 /* stall for 20 ms, long enough for ucode to init card
676 and reach mainloop */
682 MODULE_FIRMWARE("slicoss/oasisdownload.sys");
683 MODULE_FIRMWARE("slicoss/gbdownload.sys");
685 static void slic_adapter_set_hwaddr(struct adapter
*adapter
)
687 struct sliccard
*card
= adapter
->card
;
689 if ((adapter
->card
) && (card
->config_set
)) {
690 memcpy(adapter
->macaddr
,
691 card
->config
.MacInfo
[adapter
->functionnumber
].macaddrA
,
692 sizeof(struct slic_config_mac
));
693 if (!(adapter
->currmacaddr
[0] || adapter
->currmacaddr
[1] ||
694 adapter
->currmacaddr
[2] || adapter
->currmacaddr
[3] ||
695 adapter
->currmacaddr
[4] || adapter
->currmacaddr
[5])) {
696 memcpy(adapter
->currmacaddr
, adapter
->macaddr
, 6);
698 if (adapter
->netdev
) {
699 memcpy(adapter
->netdev
->dev_addr
, adapter
->currmacaddr
,
705 static void slic_intagg_set(struct adapter
*adapter
, u32 value
)
707 slic_reg32_write(&adapter
->slic_regs
->slic_intagg
, value
, FLUSH
);
708 adapter
->card
->loadlevel_current
= value
;
711 static void slic_soft_reset(struct adapter
*adapter
)
713 if (adapter
->card
->state
== CARD_UP
) {
714 slic_reg32_write(&adapter
->slic_regs
->slic_quiesce
, 0, FLUSH
);
718 slic_reg32_write(&adapter
->slic_regs
->slic_reset
, SLIC_RESET_MAGIC
,
723 static void slic_mac_address_config(struct adapter
*adapter
)
727 __iomem
struct slic_regs
*slic_regs
= adapter
->slic_regs
;
729 value
= *(u32
*) &adapter
->currmacaddr
[2];
730 value
= ntohl(value
);
731 slic_reg32_write(&slic_regs
->slic_wraddral
, value
, FLUSH
);
732 slic_reg32_write(&slic_regs
->slic_wraddrbl
, value
, FLUSH
);
734 value2
= (u32
) ((adapter
->currmacaddr
[0] << 8 |
735 adapter
->currmacaddr
[1]) & 0xFFFF);
737 slic_reg32_write(&slic_regs
->slic_wraddrah
, value2
, FLUSH
);
738 slic_reg32_write(&slic_regs
->slic_wraddrbh
, value2
, FLUSH
);
740 /* Write our multicast mask out to the card. This is done */
741 /* here in addition to the slic_mcast_addr_set routine */
742 /* because ALL_MCAST may have been enabled or disabled */
743 slic_mcast_set_mask(adapter
);
746 static void slic_mac_config(struct adapter
*adapter
)
749 __iomem
struct slic_regs
*slic_regs
= adapter
->slic_regs
;
751 /* Setup GMAC gaps */
752 if (adapter
->linkspeed
== LINK_1000MB
) {
753 value
= ((GMCR_GAPBB_1000
<< GMCR_GAPBB_SHIFT
) |
754 (GMCR_GAPR1_1000
<< GMCR_GAPR1_SHIFT
) |
755 (GMCR_GAPR2_1000
<< GMCR_GAPR2_SHIFT
));
757 value
= ((GMCR_GAPBB_100
<< GMCR_GAPBB_SHIFT
) |
758 (GMCR_GAPR1_100
<< GMCR_GAPR1_SHIFT
) |
759 (GMCR_GAPR2_100
<< GMCR_GAPR2_SHIFT
));
763 if (adapter
->linkspeed
== LINK_1000MB
)
766 /* enable fullduplex */
767 if ((adapter
->linkduplex
== LINK_FULLD
)
768 || (adapter
->macopts
& MAC_LOOPBACK
)) {
772 /* write mac config */
773 slic_reg32_write(&slic_regs
->slic_wmcfg
, value
, FLUSH
);
775 /* setup mac addresses */
776 slic_mac_address_config(adapter
);
779 static void slic_config_set(struct adapter
*adapter
, bool linkchange
)
783 __iomem
struct slic_regs
*slic_regs
= adapter
->slic_regs
;
787 slic_mac_config(adapter
);
788 RcrReset
= GRCR_RESET
;
790 slic_mac_address_config(adapter
);
794 if (adapter
->linkduplex
== LINK_FULLD
) {
796 value
= (GXCR_RESET
| /* Always reset */
797 GXCR_XMTEN
| /* Enable transmit */
798 GXCR_PAUSEEN
); /* Enable pause */
800 slic_reg32_write(&slic_regs
->slic_wxcfg
, value
, FLUSH
);
802 /* Setup rcvcfg last */
803 value
= (RcrReset
| /* Reset, if linkchange */
804 GRCR_CTLEN
| /* Enable CTL frames */
805 GRCR_ADDRAEN
| /* Address A enable */
806 GRCR_RCVBAD
| /* Rcv bad frames */
807 (GRCR_HASHSIZE
<< GRCR_HASHSIZE_SHIFT
));
810 value
= (GXCR_RESET
| /* Always reset */
811 GXCR_XMTEN
); /* Enable transmit */
813 slic_reg32_write(&slic_regs
->slic_wxcfg
, value
, FLUSH
);
815 /* Setup rcvcfg last */
816 value
= (RcrReset
| /* Reset, if linkchange */
817 GRCR_ADDRAEN
| /* Address A enable */
818 GRCR_RCVBAD
| /* Rcv bad frames */
819 (GRCR_HASHSIZE
<< GRCR_HASHSIZE_SHIFT
));
822 if (adapter
->state
!= ADAPT_DOWN
) {
823 /* Only enable receive if we are restarting or running */
827 if (adapter
->macopts
& MAC_PROMISC
)
828 value
|= GRCR_RCVALL
;
830 slic_reg32_write(&slic_regs
->slic_wrcfg
, value
, FLUSH
);
834 * Turn off RCV and XMT, power down PHY
836 static void slic_config_clear(struct adapter
*adapter
)
840 __iomem
struct slic_regs
*slic_regs
= adapter
->slic_regs
;
843 value
= (GXCR_RESET
| /* Always reset */
844 GXCR_PAUSEEN
); /* Enable pause */
846 slic_reg32_write(&slic_regs
->slic_wxcfg
, value
, FLUSH
);
848 value
= (GRCR_RESET
| /* Always reset */
849 GRCR_CTLEN
| /* Enable CTL frames */
850 GRCR_ADDRAEN
| /* Address A enable */
851 (GRCR_HASHSIZE
<< GRCR_HASHSIZE_SHIFT
));
853 slic_reg32_write(&slic_regs
->slic_wrcfg
, value
, FLUSH
);
856 phy_config
= (MIICR_REG_PCR
| (PCR_POWERDOWN
));
857 slic_reg32_write(&slic_regs
->slic_wphy
, phy_config
, FLUSH
);
860 static bool slic_mac_filter(struct adapter
*adapter
,
861 struct ether_header
*ether_frame
)
863 struct net_device
*netdev
= adapter
->netdev
;
864 u32 opts
= adapter
->macopts
;
865 u32
*dhost4
= (u32
*)ðer_frame
->ether_dhost
[0];
866 u16
*dhost2
= (u16
*)ðer_frame
->ether_dhost
[4];
868 if (opts
& MAC_PROMISC
)
871 if ((*dhost4
== 0xFFFFFFFF) && (*dhost2
== 0xFFFF)) {
872 if (opts
& MAC_BCAST
) {
873 adapter
->rcv_broadcasts
++;
880 if (ether_frame
->ether_dhost
[0] & 0x01) {
881 if (opts
& MAC_ALLMCAST
) {
882 adapter
->rcv_multicasts
++;
883 netdev
->stats
.multicast
++;
886 if (opts
& MAC_MCAST
) {
887 struct mcast_address
*mcaddr
= adapter
->mcastaddrs
;
890 if (!compare_ether_addr(mcaddr
->address
,
891 ether_frame
->ether_dhost
)) {
892 adapter
->rcv_multicasts
++;
893 netdev
->stats
.multicast
++;
896 mcaddr
= mcaddr
->next
;
903 if (opts
& MAC_DIRECTED
) {
904 adapter
->rcv_unicasts
++;
911 static int slic_mac_set_address(struct net_device
*dev
, void *ptr
)
913 struct adapter
*adapter
= netdev_priv(dev
);
914 struct sockaddr
*addr
= ptr
;
916 if (netif_running(dev
))
921 if (!is_valid_ether_addr(addr
->sa_data
))
924 memcpy(dev
->dev_addr
, addr
->sa_data
, dev
->addr_len
);
925 memcpy(adapter
->currmacaddr
, addr
->sa_data
, dev
->addr_len
);
927 slic_config_set(adapter
, true);
931 static void slic_timer_load_check(ulong cardaddr
)
933 struct sliccard
*card
= (struct sliccard
*)cardaddr
;
934 struct adapter
*adapter
= card
->master
;
936 u32 load
= card
->events
;
939 intagg
= &adapter
->slic_regs
->slic_intagg
;
941 if ((adapter
) && (adapter
->state
== ADAPT_UP
) &&
942 (card
->state
== CARD_UP
) && (slic_global
.dynamic_intagg
)) {
943 if (adapter
->devid
== SLIC_1GB_DEVICE_ID
) {
944 if (adapter
->linkspeed
== LINK_1000MB
)
947 if (load
> SLIC_LOAD_5
)
948 level
= SLIC_INTAGG_5
;
949 else if (load
> SLIC_LOAD_4
)
950 level
= SLIC_INTAGG_4
;
951 else if (load
> SLIC_LOAD_3
)
952 level
= SLIC_INTAGG_3
;
953 else if (load
> SLIC_LOAD_2
)
954 level
= SLIC_INTAGG_2
;
955 else if (load
> SLIC_LOAD_1
)
956 level
= SLIC_INTAGG_1
;
958 level
= SLIC_INTAGG_0
;
960 if (card
->loadlevel_current
!= level
) {
961 card
->loadlevel_current
= level
;
962 slic_reg32_write(intagg
, level
, FLUSH
);
965 if (load
> SLIC_LOAD_5
)
966 level
= SLIC_INTAGG_5
;
967 else if (load
> SLIC_LOAD_4
)
968 level
= SLIC_INTAGG_4
;
969 else if (load
> SLIC_LOAD_3
)
970 level
= SLIC_INTAGG_3
;
971 else if (load
> SLIC_LOAD_2
)
972 level
= SLIC_INTAGG_2
;
973 else if (load
> SLIC_LOAD_1
)
974 level
= SLIC_INTAGG_1
;
976 level
= SLIC_INTAGG_0
;
977 if (card
->loadlevel_current
!= level
) {
978 card
->loadlevel_current
= level
;
979 slic_reg32_write(intagg
, level
, FLUSH
);
984 card
->loadtimer
.expires
= jiffies
+ (SLIC_LOADTIMER_PERIOD
* HZ
);
985 add_timer(&card
->loadtimer
);
988 static int slic_upr_queue_request(struct adapter
*adapter
,
992 u32 upr_buffer
, u32 upr_buffer_h
)
994 struct slic_upr
*upr
;
995 struct slic_upr
*uprqueue
;
997 upr
= kmalloc(sizeof(struct slic_upr
), GFP_ATOMIC
);
1001 upr
->adapter
= adapter
->port
;
1002 upr
->upr_request
= upr_request
;
1003 upr
->upr_data
= upr_data
;
1004 upr
->upr_buffer
= upr_buffer
;
1005 upr
->upr_data_h
= upr_data_h
;
1006 upr
->upr_buffer_h
= upr_buffer_h
;
1008 if (adapter
->upr_list
) {
1009 uprqueue
= adapter
->upr_list
;
1011 while (uprqueue
->next
)
1012 uprqueue
= uprqueue
->next
;
1013 uprqueue
->next
= upr
;
1015 adapter
->upr_list
= upr
;
1020 static void slic_upr_start(struct adapter
*adapter
)
1022 struct slic_upr
*upr
;
1023 __iomem
struct slic_regs
*slic_regs
= adapter
->slic_regs
;
1029 upr
= adapter
->upr_list
;
1032 if (adapter
->upr_busy
)
1034 adapter
->upr_busy
= 1;
1036 switch (upr
->upr_request
) {
1037 case SLIC_UPR_STATS
:
1038 if (upr
->upr_data_h
== 0) {
1039 slic_reg32_write(&slic_regs
->slic_stats
, upr
->upr_data
,
1042 slic_reg64_write(adapter
, &slic_regs
->slic_stats64
,
1044 &slic_regs
->slic_addr_upper
,
1045 upr
->upr_data_h
, FLUSH
);
1050 slic_reg64_write(adapter
, &slic_regs
->slic_rlsr
, upr
->upr_data
,
1051 &slic_regs
->slic_addr_upper
, upr
->upr_data_h
,
1055 case SLIC_UPR_RCONFIG
:
1056 slic_reg64_write(adapter
, &slic_regs
->slic_rconfig
,
1057 upr
->upr_data
, &slic_regs
->slic_addr_upper
,
1058 upr
->upr_data_h
, FLUSH
);
1061 slic_reg32_write(&slic_regs
->slic_ping
, 1, FLUSH
);
1068 static int slic_upr_request(struct adapter
*adapter
,
1072 u32 upr_buffer
, u32 upr_buffer_h
)
1076 spin_lock_irqsave(&adapter
->upr_lock
.lock
, adapter
->upr_lock
.flags
);
1077 rc
= slic_upr_queue_request(adapter
,
1080 upr_data_h
, upr_buffer
, upr_buffer_h
);
1082 goto err_unlock_irq
;
1084 slic_upr_start(adapter
);
1086 spin_unlock_irqrestore(&adapter
->upr_lock
.lock
,
1087 adapter
->upr_lock
.flags
);
1091 static void slic_link_upr_complete(struct adapter
*adapter
, u32 isr
)
1093 u32 linkstatus
= adapter
->pshmem
->linkstatus
;
1095 unsigned char linkspeed
;
1096 unsigned char linkduplex
;
1098 if ((isr
& ISR_UPCERR
) || (isr
& ISR_UPCBSY
)) {
1099 struct slic_shmem
*pshmem
;
1101 pshmem
= (struct slic_shmem
*)adapter
->phys_shmem
;
1102 #if BITS_PER_LONG == 64
1103 slic_upr_queue_request(adapter
,
1105 SLIC_GET_ADDR_LOW(&pshmem
->linkstatus
),
1106 SLIC_GET_ADDR_HIGH(&pshmem
->linkstatus
),
1109 slic_upr_queue_request(adapter
,
1111 (u32
) &pshmem
->linkstatus
,
1112 SLIC_GET_ADDR_HIGH(pshmem
), 0, 0);
1116 if (adapter
->state
!= ADAPT_UP
)
1119 ASSERT((adapter
->devid
== SLIC_1GB_DEVICE_ID
)
1120 || (adapter
->devid
== SLIC_2GB_DEVICE_ID
));
1122 linkup
= linkstatus
& GIG_LINKUP
? LINK_UP
: LINK_DOWN
;
1123 if (linkstatus
& GIG_SPEED_1000
)
1124 linkspeed
= LINK_1000MB
;
1125 else if (linkstatus
& GIG_SPEED_100
)
1126 linkspeed
= LINK_100MB
;
1128 linkspeed
= LINK_10MB
;
1130 if (linkstatus
& GIG_FULLDUPLEX
)
1131 linkduplex
= LINK_FULLD
;
1133 linkduplex
= LINK_HALFD
;
1135 if ((adapter
->linkstate
== LINK_DOWN
) && (linkup
== LINK_DOWN
))
1138 /* link up event, but nothing has changed */
1139 if ((adapter
->linkstate
== LINK_UP
) &&
1140 (linkup
== LINK_UP
) &&
1141 (adapter
->linkspeed
== linkspeed
) &&
1142 (adapter
->linkduplex
== linkduplex
))
1145 /* link has changed at this point */
1147 /* link has gone from up to down */
1148 if (linkup
== LINK_DOWN
) {
1149 adapter
->linkstate
= LINK_DOWN
;
1153 /* link has gone from down to up */
1154 adapter
->linkspeed
= linkspeed
;
1155 adapter
->linkduplex
= linkduplex
;
1157 if (adapter
->linkstate
!= LINK_UP
) {
1159 slic_config_set(adapter
, true);
1160 adapter
->linkstate
= LINK_UP
;
1161 netif_start_queue(adapter
->netdev
);
1165 static void slic_upr_request_complete(struct adapter
*adapter
, u32 isr
)
1167 struct sliccard
*card
= adapter
->card
;
1168 struct slic_upr
*upr
;
1170 spin_lock_irqsave(&adapter
->upr_lock
.lock
, adapter
->upr_lock
.flags
);
1171 upr
= adapter
->upr_list
;
1174 spin_unlock_irqrestore(&adapter
->upr_lock
.lock
,
1175 adapter
->upr_lock
.flags
);
1178 adapter
->upr_list
= upr
->next
;
1180 adapter
->upr_busy
= 0;
1181 ASSERT(adapter
->port
== upr
->adapter
);
1182 switch (upr
->upr_request
) {
1183 case SLIC_UPR_STATS
:
1185 struct slic_stats
*slicstats
=
1186 (struct slic_stats
*) &adapter
->pshmem
->inicstats
;
1187 struct slic_stats
*newstats
= slicstats
;
1188 struct slic_stats
*old
= &adapter
->inicstats_prev
;
1189 struct slicnet_stats
*stst
= &adapter
->slic_stats
;
1191 if (isr
& ISR_UPCERR
) {
1192 dev_err(&adapter
->netdev
->dev
,
1193 "SLIC_UPR_STATS command failed isr[%x]\n",
1198 UPDATE_STATS_GB(stst
->tcp
.xmit_tcp_segs
,
1199 newstats
->xmit_tcp_segs_gb
,
1200 old
->xmit_tcp_segs_gb
);
1202 UPDATE_STATS_GB(stst
->tcp
.xmit_tcp_bytes
,
1203 newstats
->xmit_tcp_bytes_gb
,
1204 old
->xmit_tcp_bytes_gb
);
1206 UPDATE_STATS_GB(stst
->tcp
.rcv_tcp_segs
,
1207 newstats
->rcv_tcp_segs_gb
,
1208 old
->rcv_tcp_segs_gb
);
1210 UPDATE_STATS_GB(stst
->tcp
.rcv_tcp_bytes
,
1211 newstats
->rcv_tcp_bytes_gb
,
1212 old
->rcv_tcp_bytes_gb
);
1214 UPDATE_STATS_GB(stst
->iface
.xmt_bytes
,
1215 newstats
->xmit_bytes_gb
,
1216 old
->xmit_bytes_gb
);
1218 UPDATE_STATS_GB(stst
->iface
.xmt_ucast
,
1219 newstats
->xmit_unicasts_gb
,
1220 old
->xmit_unicasts_gb
);
1222 UPDATE_STATS_GB(stst
->iface
.rcv_bytes
,
1223 newstats
->rcv_bytes_gb
,
1226 UPDATE_STATS_GB(stst
->iface
.rcv_ucast
,
1227 newstats
->rcv_unicasts_gb
,
1228 old
->rcv_unicasts_gb
);
1230 UPDATE_STATS_GB(stst
->iface
.xmt_errors
,
1231 newstats
->xmit_collisions_gb
,
1232 old
->xmit_collisions_gb
);
1234 UPDATE_STATS_GB(stst
->iface
.xmt_errors
,
1235 newstats
->xmit_excess_collisions_gb
,
1236 old
->xmit_excess_collisions_gb
);
1238 UPDATE_STATS_GB(stst
->iface
.xmt_errors
,
1239 newstats
->xmit_other_error_gb
,
1240 old
->xmit_other_error_gb
);
1242 UPDATE_STATS_GB(stst
->iface
.rcv_errors
,
1243 newstats
->rcv_other_error_gb
,
1244 old
->rcv_other_error_gb
);
1246 UPDATE_STATS_GB(stst
->iface
.rcv_discards
,
1247 newstats
->rcv_drops_gb
,
1250 if (newstats
->rcv_drops_gb
> old
->rcv_drops_gb
) {
1251 adapter
->rcv_drops
+=
1252 (newstats
->rcv_drops_gb
-
1255 memcpy(old
, newstats
, sizeof(struct slic_stats
));
1259 slic_link_upr_complete(adapter
, isr
);
1261 case SLIC_UPR_RCONFIG
:
1276 card
->pingstatus
|= (isr
& ISR_PINGDSMASK
);
1282 slic_upr_start(adapter
);
1283 spin_unlock_irqrestore(&adapter
->upr_lock
.lock
,
1284 adapter
->upr_lock
.flags
);
1287 static void slic_config_get(struct adapter
*adapter
, u32 config
,
1292 status
= slic_upr_request(adapter
,
1294 (u32
) config
, (u32
) config_h
, 0, 0);
1295 ASSERT(status
== 0);
1299 * this is here to checksum the eeprom, there is some ucode bug
1300 * which prevens us from using the ucode result.
1301 * remove this once ucode is fixed.
1303 static ushort
slic_eeprom_cksum(char *m
, int len
)
1305 #define ADDCARRY(x) (x > 65535 ? x -= 65535 : x)
1306 #define REDUCE {l_util.l = sum; sum = l_util.s[0] + l_util.s[1]; ADDCARRY(sum);\
1311 u32 byte_swapped
= 0;
1328 #if BITS_PER_LONG == 64
1329 w_int
= (u32
) ((ulong
) w
& 0x00000000FFFFFFFF);
1333 if ((1 & w_int
) && (len
> 0)) {
1336 s_util
.c
[0] = *(unsigned char *)w
;
1337 w
= (u16
*)((char *)w
+ 1);
1342 /* Unroll the loop to make overhead from branches &c small. */
1343 while ((len
-= 32) >= 0) {
1360 w
= (u16
*)((ulong
) w
+ 16); /* verify */
1363 while ((len
-= 8) >= 0) {
1368 w
= (u16
*)((ulong
) w
+ 4); /* verify */
1371 if (len
!= 0 || byte_swapped
!= 0) {
1373 while ((len
-= 2) >= 0)
1374 sum
+= *w
++; /* verify */
1380 s_util
.c
[1] = *(char *) w
;
1387 } else if (len
== -1) {
1388 s_util
.c
[0] = *(char *) w
;
1397 return (ushort
) sum
;
1400 static void slic_rspqueue_free(struct adapter
*adapter
)
1403 struct slic_rspqueue
*rspq
= &adapter
->rspqueue
;
1405 for (i
= 0; i
< rspq
->num_pages
; i
++) {
1406 if (rspq
->vaddr
[i
]) {
1407 pci_free_consistent(adapter
->pcidev
, PAGE_SIZE
,
1408 rspq
->vaddr
[i
], rspq
->paddr
[i
]);
1410 rspq
->vaddr
[i
] = NULL
;
1414 rspq
->pageindex
= 0;
1415 rspq
->rspbuf
= NULL
;
1418 static int slic_rspqueue_init(struct adapter
*adapter
)
1421 struct slic_rspqueue
*rspq
= &adapter
->rspqueue
;
1422 __iomem
struct slic_regs
*slic_regs
= adapter
->slic_regs
;
1425 ASSERT(adapter
->state
== ADAPT_DOWN
);
1426 memset(rspq
, 0, sizeof(struct slic_rspqueue
));
1428 rspq
->num_pages
= SLIC_RSPQ_PAGES_GB
;
1430 for (i
= 0; i
< rspq
->num_pages
; i
++) {
1431 rspq
->vaddr
[i
] = pci_alloc_consistent(adapter
->pcidev
,
1434 if (!rspq
->vaddr
[i
]) {
1435 dev_err(&adapter
->pcidev
->dev
,
1436 "pci_alloc_consistent failed\n");
1437 slic_rspqueue_free(adapter
);
1441 * do we really need this assertions (4K PAGE_SIZE aligned addr)? */
1443 #ifndef CONFIG_X86_64
1444 ASSERT(((u32
) rspq
->vaddr
[i
] & 0xFFFFF000) ==
1445 (u32
) rspq
->vaddr
[i
]);
1446 ASSERT(((u32
) rspq
->paddr
[i
] & 0xFFFFF000) ==
1447 (u32
) rspq
->paddr
[i
]);
1450 memset(rspq
->vaddr
[i
], 0, PAGE_SIZE
);
1453 slic_reg32_write(&slic_regs
->slic_rbar
,
1454 (rspq
->paddr
[i
] | SLIC_RSPQ_BUFSINPAGE
),
1457 slic_reg64_write(adapter
, &slic_regs
->slic_rbar64
,
1458 (rspq
->paddr
[i
] | SLIC_RSPQ_BUFSINPAGE
),
1459 &slic_regs
->slic_addr_upper
,
1460 paddrh
, DONT_FLUSH
);
1464 rspq
->pageindex
= 0;
1465 rspq
->rspbuf
= (struct slic_rspbuf
*)rspq
->vaddr
[0];
1469 static struct slic_rspbuf
*slic_rspqueue_getnext(struct adapter
*adapter
)
1471 struct slic_rspqueue
*rspq
= &adapter
->rspqueue
;
1472 struct slic_rspbuf
*buf
;
1474 if (!(rspq
->rspbuf
->status
))
1478 #if BITS_PER_LONG == 32
1479 ASSERT((buf
->status
& 0xFFFFFFE0) == 0);
1481 ASSERT(buf
->hosthandle
);
1482 if (++rspq
->offset
< SLIC_RSPQ_BUFSINPAGE
) {
1484 #if BITS_PER_LONG == 32
1485 ASSERT(((u32
) rspq
->rspbuf
& 0xFFFFFFE0) ==
1486 (u32
) rspq
->rspbuf
);
1489 ASSERT(rspq
->offset
== SLIC_RSPQ_BUFSINPAGE
);
1490 slic_reg64_write(adapter
, &adapter
->slic_regs
->slic_rbar64
,
1491 (rspq
->paddr
[rspq
->pageindex
] | SLIC_RSPQ_BUFSINPAGE
),
1492 &adapter
->slic_regs
->slic_addr_upper
, 0, DONT_FLUSH
);
1493 rspq
->pageindex
= (++rspq
->pageindex
) % rspq
->num_pages
;
1495 rspq
->rspbuf
= (struct slic_rspbuf
*)
1496 rspq
->vaddr
[rspq
->pageindex
];
1497 #if BITS_PER_LONG == 32
1498 ASSERT(((u32
) rspq
->rspbuf
& 0xFFFFF000) ==
1499 (u32
) rspq
->rspbuf
);
1502 #if BITS_PER_LONG == 32
1503 ASSERT(((u32
) buf
& 0xFFFFFFE0) == (u32
) buf
);
1508 static void slic_cmdqmem_init(struct adapter
*adapter
)
1510 struct slic_cmdqmem
*cmdqmem
= &adapter
->cmdqmem
;
1512 memset(cmdqmem
, 0, sizeof(struct slic_cmdqmem
));
1515 static void slic_cmdqmem_free(struct adapter
*adapter
)
1517 struct slic_cmdqmem
*cmdqmem
= &adapter
->cmdqmem
;
1520 for (i
= 0; i
< SLIC_CMDQ_MAXPAGES
; i
++) {
1521 if (cmdqmem
->pages
[i
]) {
1522 pci_free_consistent(adapter
->pcidev
,
1524 (void *) cmdqmem
->pages
[i
],
1525 cmdqmem
->dma_pages
[i
]);
1528 memset(cmdqmem
, 0, sizeof(struct slic_cmdqmem
));
1531 static u32
*slic_cmdqmem_addpage(struct adapter
*adapter
)
1533 struct slic_cmdqmem
*cmdqmem
= &adapter
->cmdqmem
;
1536 if (cmdqmem
->pagecnt
>= SLIC_CMDQ_MAXPAGES
)
1538 pageaddr
= pci_alloc_consistent(adapter
->pcidev
,
1540 &cmdqmem
->dma_pages
[cmdqmem
->pagecnt
]);
1543 #if BITS_PER_LONG == 32
1544 ASSERT(((u32
) pageaddr
& 0xFFFFF000) == (u32
) pageaddr
);
1546 cmdqmem
->pages
[cmdqmem
->pagecnt
] = pageaddr
;
1551 static void slic_cmdq_free(struct adapter
*adapter
)
1553 struct slic_hostcmd
*cmd
;
1555 cmd
= adapter
->cmdq_all
.head
;
1558 struct sk_buff
*tempskb
;
1563 dev_kfree_skb_irq(tempskb
);
1566 cmd
= cmd
->next_all
;
1568 memset(&adapter
->cmdq_all
, 0, sizeof(struct slic_cmdqueue
));
1569 memset(&adapter
->cmdq_free
, 0, sizeof(struct slic_cmdqueue
));
1570 memset(&adapter
->cmdq_done
, 0, sizeof(struct slic_cmdqueue
));
1571 slic_cmdqmem_free(adapter
);
1574 static void slic_cmdq_addcmdpage(struct adapter
*adapter
, u32
*page
)
1576 struct slic_hostcmd
*cmd
;
1577 struct slic_hostcmd
*prev
;
1578 struct slic_hostcmd
*tail
;
1579 struct slic_cmdqueue
*cmdq
;
1585 struct slic_handle
*pslic_handle
;
1588 cmd
= (struct slic_hostcmd
*)cmdaddr
;
1591 phys_addr
= virt_to_bus((void *)page
);
1592 phys_addrl
= SLIC_GET_ADDR_LOW(phys_addr
);
1593 phys_addrh
= SLIC_GET_ADDR_HIGH(phys_addr
);
1597 while ((cmdcnt
< SLIC_CMDQ_CMDSINPAGE
) &&
1598 (adapter
->slic_handle_ix
< 256)) {
1599 /* Allocate and initialize a SLIC_HANDLE for this command */
1600 SLIC_GET_SLIC_HANDLE(adapter
, pslic_handle
);
1601 if (pslic_handle
== NULL
)
1603 ASSERT(pslic_handle
==
1604 &adapter
->slic_handles
[pslic_handle
->token
.
1606 pslic_handle
->type
= SLIC_HANDLE_CMD
;
1607 pslic_handle
->address
= (void *) cmd
;
1608 pslic_handle
->offset
= (ushort
) adapter
->slic_handle_ix
++;
1609 pslic_handle
->other_handle
= NULL
;
1610 pslic_handle
->next
= NULL
;
1612 cmd
->pslic_handle
= pslic_handle
;
1613 cmd
->cmd64
.hosthandle
= pslic_handle
->token
.handle_token
;
1615 cmd
->paddrl
= phys_addrl
;
1616 cmd
->paddrh
= phys_addrh
;
1617 cmd
->next_all
= prev
;
1620 phys_addrl
+= SLIC_HOSTCMD_SIZE
;
1621 cmdaddr
+= SLIC_HOSTCMD_SIZE
;
1623 cmd
= (struct slic_hostcmd
*)cmdaddr
;
1627 cmdq
= &adapter
->cmdq_all
;
1628 cmdq
->count
+= cmdcnt
; /* SLIC_CMDQ_CMDSINPAGE; mooktodo */
1629 tail
->next_all
= cmdq
->head
;
1631 cmdq
= &adapter
->cmdq_free
;
1632 spin_lock_irqsave(&cmdq
->lock
.lock
, cmdq
->lock
.flags
);
1633 cmdq
->count
+= cmdcnt
; /* SLIC_CMDQ_CMDSINPAGE; mooktodo */
1634 tail
->next
= cmdq
->head
;
1636 spin_unlock_irqrestore(&cmdq
->lock
.lock
, cmdq
->lock
.flags
);
1639 static int slic_cmdq_init(struct adapter
*adapter
)
1644 ASSERT(adapter
->state
== ADAPT_DOWN
);
1645 memset(&adapter
->cmdq_all
, 0, sizeof(struct slic_cmdqueue
));
1646 memset(&adapter
->cmdq_free
, 0, sizeof(struct slic_cmdqueue
));
1647 memset(&adapter
->cmdq_done
, 0, sizeof(struct slic_cmdqueue
));
1648 spin_lock_init(&adapter
->cmdq_all
.lock
.lock
);
1649 spin_lock_init(&adapter
->cmdq_free
.lock
.lock
);
1650 spin_lock_init(&adapter
->cmdq_done
.lock
.lock
);
1651 slic_cmdqmem_init(adapter
);
1652 adapter
->slic_handle_ix
= 1;
1653 for (i
= 0; i
< SLIC_CMDQ_INITPAGES
; i
++) {
1654 pageaddr
= slic_cmdqmem_addpage(adapter
);
1655 #if BITS_PER_LONG == 32
1656 ASSERT(((u32
) pageaddr
& 0xFFFFF000) == (u32
) pageaddr
);
1659 slic_cmdq_free(adapter
);
1662 slic_cmdq_addcmdpage(adapter
, pageaddr
);
1664 adapter
->slic_handle_ix
= 1;
1669 static void slic_cmdq_reset(struct adapter
*adapter
)
1671 struct slic_hostcmd
*hcmd
;
1672 struct sk_buff
*skb
;
1675 spin_lock_irqsave(&adapter
->cmdq_free
.lock
.lock
,
1676 adapter
->cmdq_free
.lock
.flags
);
1677 spin_lock_irqsave(&adapter
->cmdq_done
.lock
.lock
,
1678 adapter
->cmdq_done
.lock
.flags
);
1679 outstanding
= adapter
->cmdq_all
.count
- adapter
->cmdq_done
.count
;
1680 outstanding
-= adapter
->cmdq_free
.count
;
1681 hcmd
= adapter
->cmdq_all
.head
;
1688 dev_kfree_skb_irq(skb
);
1690 hcmd
= hcmd
->next_all
;
1692 adapter
->cmdq_free
.count
= 0;
1693 adapter
->cmdq_free
.head
= NULL
;
1694 adapter
->cmdq_free
.tail
= NULL
;
1695 adapter
->cmdq_done
.count
= 0;
1696 adapter
->cmdq_done
.head
= NULL
;
1697 adapter
->cmdq_done
.tail
= NULL
;
1698 adapter
->cmdq_free
.head
= adapter
->cmdq_all
.head
;
1699 hcmd
= adapter
->cmdq_all
.head
;
1701 adapter
->cmdq_free
.count
++;
1702 hcmd
->next
= hcmd
->next_all
;
1703 hcmd
= hcmd
->next_all
;
1705 if (adapter
->cmdq_free
.count
!= adapter
->cmdq_all
.count
) {
1706 dev_err(&adapter
->netdev
->dev
,
1707 "free_count %d != all count %d\n",
1708 adapter
->cmdq_free
.count
, adapter
->cmdq_all
.count
);
1710 spin_unlock_irqrestore(&adapter
->cmdq_done
.lock
.lock
,
1711 adapter
->cmdq_done
.lock
.flags
);
1712 spin_unlock_irqrestore(&adapter
->cmdq_free
.lock
.lock
,
1713 adapter
->cmdq_free
.lock
.flags
);
1716 static void slic_cmdq_getdone(struct adapter
*adapter
)
1718 struct slic_cmdqueue
*done_cmdq
= &adapter
->cmdq_done
;
1719 struct slic_cmdqueue
*free_cmdq
= &adapter
->cmdq_free
;
1721 ASSERT(free_cmdq
->head
== NULL
);
1722 spin_lock_irqsave(&done_cmdq
->lock
.lock
, done_cmdq
->lock
.flags
);
1724 free_cmdq
->head
= done_cmdq
->head
;
1725 free_cmdq
->count
= done_cmdq
->count
;
1726 done_cmdq
->head
= NULL
;
1727 done_cmdq
->tail
= NULL
;
1728 done_cmdq
->count
= 0;
1729 spin_unlock_irqrestore(&done_cmdq
->lock
.lock
, done_cmdq
->lock
.flags
);
1732 static struct slic_hostcmd
*slic_cmdq_getfree(struct adapter
*adapter
)
1734 struct slic_cmdqueue
*cmdq
= &adapter
->cmdq_free
;
1735 struct slic_hostcmd
*cmd
= NULL
;
1738 spin_lock_irqsave(&cmdq
->lock
.lock
, cmdq
->lock
.flags
);
1742 cmdq
->head
= cmd
->next
;
1744 spin_unlock_irqrestore(&cmdq
->lock
.lock
, cmdq
->lock
.flags
);
1746 slic_cmdq_getdone(adapter
);
1753 spin_unlock_irqrestore(&cmdq
->lock
.lock
,
1755 pageaddr
= slic_cmdqmem_addpage(adapter
);
1757 slic_cmdq_addcmdpage(adapter
, pageaddr
);
1758 goto lock_and_retry
;
1765 static void slic_cmdq_putdone_irq(struct adapter
*adapter
,
1766 struct slic_hostcmd
*cmd
)
1768 struct slic_cmdqueue
*cmdq
= &adapter
->cmdq_done
;
1770 spin_lock(&cmdq
->lock
.lock
);
1772 cmd
->next
= cmdq
->head
;
1775 if ((adapter
->xmitq_full
) && (cmdq
->count
> 10))
1776 netif_wake_queue(adapter
->netdev
);
1777 spin_unlock(&cmdq
->lock
.lock
);
1780 static int slic_rcvqueue_fill(struct adapter
*adapter
)
1785 struct slic_rcvqueue
*rcvq
= &adapter
->rcvqueue
;
1787 struct device
*dev
= &adapter
->netdev
->dev
;
1789 while (i
< SLIC_RCVQ_FILLENTRIES
) {
1790 struct slic_rcvbuf
*rcvbuf
;
1791 struct sk_buff
*skb
;
1792 #ifdef KLUDGE_FOR_4GB_BOUNDARY
1795 skb
= alloc_skb(SLIC_RCVQ_RCVBUFSIZE
, GFP_ATOMIC
);
1797 paddr
= (void *)pci_map_single(adapter
->pcidev
,
1799 SLIC_RCVQ_RCVBUFSIZE
,
1800 PCI_DMA_FROMDEVICE
);
1801 paddrl
= SLIC_GET_ADDR_LOW(paddr
);
1802 paddrh
= SLIC_GET_ADDR_HIGH(paddr
);
1804 skb
->len
= SLIC_RCVBUF_HEADSIZE
;
1805 rcvbuf
= (struct slic_rcvbuf
*)skb
->head
;
1808 #ifdef KLUDGE_FOR_4GB_BOUNDARY
1810 dev_err(dev
, "%s: LOW 32bits PHYSICAL ADDRESS == 0\n",
1812 dev_err(dev
, "skb[%p] PROBLEM\n", skb
);
1813 dev_err(dev
, " skbdata[%p]\n", skb
->data
);
1814 dev_err(dev
, " skblen[%x]\n", skb
->len
);
1815 dev_err(dev
, " paddr[%p]\n", paddr
);
1816 dev_err(dev
, " paddrl[%x]\n", paddrl
);
1817 dev_err(dev
, " paddrh[%x]\n", paddrh
);
1818 dev_err(dev
, " rcvq->head[%p]\n", rcvq
->head
);
1819 dev_err(dev
, " rcvq->tail[%p]\n", rcvq
->tail
);
1820 dev_err(dev
, " rcvq->count[%x]\n", rcvq
->count
);
1821 dev_err(dev
, "SKIP THIS SKB!!!!!!!!\n");
1822 goto retry_rcvqfill
;
1826 dev_err(dev
, "%s: LOW 32bits PHYSICAL ADDRESS == 0\n",
1828 dev_err(dev
, "skb[%p] PROBLEM\n", skb
);
1829 dev_err(dev
, " skbdata[%p]\n", skb
->data
);
1830 dev_err(dev
, " skblen[%x]\n", skb
->len
);
1831 dev_err(dev
, " paddr[%p]\n", paddr
);
1832 dev_err(dev
, " paddrl[%x]\n", paddrl
);
1833 dev_err(dev
, " paddrh[%x]\n", paddrh
);
1834 dev_err(dev
, " rcvq->head[%p]\n", rcvq
->head
);
1835 dev_err(dev
, " rcvq->tail[%p]\n", rcvq
->tail
);
1836 dev_err(dev
, " rcvq->count[%x]\n", rcvq
->count
);
1837 dev_err(dev
, "GIVE TO CARD ANYWAY\n");
1841 slic_reg32_write(&adapter
->slic_regs
->slic_hbar
,
1842 (u32
)paddrl
, DONT_FLUSH
);
1844 slic_reg64_write(adapter
,
1845 &adapter
->slic_regs
->slic_hbar64
,
1847 &adapter
->slic_regs
->slic_addr_upper
,
1848 paddrh
, DONT_FLUSH
);
1851 rcvq
->tail
->next
= skb
;
1858 dev_err(&adapter
->netdev
->dev
,
1859 "slic_rcvqueue_fill could only get [%d] skbuffs\n",
1867 static void slic_rcvqueue_free(struct adapter
*adapter
)
1869 struct slic_rcvqueue
*rcvq
= &adapter
->rcvqueue
;
1870 struct sk_buff
*skb
;
1872 while (rcvq
->head
) {
1874 rcvq
->head
= rcvq
->head
->next
;
1882 static int slic_rcvqueue_init(struct adapter
*adapter
)
1885 struct slic_rcvqueue
*rcvq
= &adapter
->rcvqueue
;
1887 ASSERT(adapter
->state
== ADAPT_DOWN
);
1890 rcvq
->size
= SLIC_RCVQ_ENTRIES
;
1893 i
= (SLIC_RCVQ_ENTRIES
/ SLIC_RCVQ_FILLENTRIES
);
1896 count
+= slic_rcvqueue_fill(adapter
);
1899 if (rcvq
->count
< SLIC_RCVQ_MINENTRIES
) {
1900 slic_rcvqueue_free(adapter
);
1906 static struct sk_buff
*slic_rcvqueue_getnext(struct adapter
*adapter
)
1908 struct slic_rcvqueue
*rcvq
= &adapter
->rcvqueue
;
1909 struct sk_buff
*skb
;
1910 struct slic_rcvbuf
*rcvbuf
;
1915 rcvbuf
= (struct slic_rcvbuf
*)skb
->head
;
1918 if (rcvbuf
->status
& IRHDDR_SVALID
) {
1919 rcvq
->head
= rcvq
->head
->next
;
1926 dev_err(&adapter
->netdev
->dev
,
1927 "RcvQ Empty!! rcvq[%p] count[%x]\n", rcvq
, rcvq
->count
);
1930 while (rcvq
->count
< SLIC_RCVQ_FILLTHRESH
) {
1931 count
= slic_rcvqueue_fill(adapter
);
1940 static u32
slic_rcvqueue_reinsert(struct adapter
*adapter
, struct sk_buff
*skb
)
1942 struct slic_rcvqueue
*rcvq
= &adapter
->rcvqueue
;
1946 struct slic_rcvbuf
*rcvbuf
= (struct slic_rcvbuf
*)skb
->head
;
1949 ASSERT(skb
->len
== SLIC_RCVBUF_HEADSIZE
);
1951 paddr
= (void *)pci_map_single(adapter
->pcidev
, skb
->head
,
1952 SLIC_RCVQ_RCVBUFSIZE
, PCI_DMA_FROMDEVICE
);
1956 paddrl
= SLIC_GET_ADDR_LOW(paddr
);
1957 paddrh
= SLIC_GET_ADDR_HIGH(paddr
);
1960 dev
= &adapter
->netdev
->dev
;
1961 dev_err(dev
, "%s: LOW 32bits PHYSICAL ADDRESS == 0\n",
1963 dev_err(dev
, "skb[%p] PROBLEM\n", skb
);
1964 dev_err(dev
, " skbdata[%p]\n", skb
->data
);
1965 dev_err(dev
, " skblen[%x]\n", skb
->len
);
1966 dev_err(dev
, " paddr[%p]\n", paddr
);
1967 dev_err(dev
, " paddrl[%x]\n", paddrl
);
1968 dev_err(dev
, " paddrh[%x]\n", paddrh
);
1969 dev_err(dev
, " rcvq->head[%p]\n", rcvq
->head
);
1970 dev_err(dev
, " rcvq->tail[%p]\n", rcvq
->tail
);
1971 dev_err(dev
, " rcvq->count[%x]\n", rcvq
->count
);
1974 slic_reg32_write(&adapter
->slic_regs
->slic_hbar
, (u32
)paddrl
,
1977 slic_reg64_write(adapter
, &adapter
->slic_regs
->slic_hbar64
,
1978 paddrl
, &adapter
->slic_regs
->slic_addr_upper
,
1979 paddrh
, DONT_FLUSH
);
1982 rcvq
->tail
->next
= skb
;
1990 static int slic_debug_card_show(struct seq_file
*seq
, void *v
)
1994 struct sliccard
*card
= seq
->private;
1995 struct slic_config
*config
= &card
->config
;
1996 unsigned char *fru
= (unsigned char *)(&card
->config
.atk_fru
);
1997 unsigned char *oemfru
= (unsigned char *)(&card
->config
.OemFru
);
2000 seq_printf(seq
, "driver_version : %s\n", slic_proc_version
);
2001 seq_printf(seq
, "Microcode versions: \n");
2002 seq_printf(seq
, " Gigabit (gb) : %s %s\n",
2003 MOJAVE_UCODE_VERS_STRING
, MOJAVE_UCODE_VERS_DATE
);
2004 seq_printf(seq
, " Gigabit Receiver : %s %s\n",
2005 GB_RCVUCODE_VERS_STRING
, GB_RCVUCODE_VERS_DATE
);
2006 seq_printf(seq
, "Vendor : %s\n", slic_vendor
);
2007 seq_printf(seq
, "Product Name : %s\n", slic_product_name
);
2009 seq_printf(seq
, "VendorId : %4.4X\n",
2011 seq_printf(seq
, "DeviceId : %4.4X\n",
2013 seq_printf(seq
, "RevisionId : %2.2x\n",
2014 config
->RevisionId
);
2015 seq_printf(seq
, "Bus # : %d\n", card
->busnumber
);
2016 seq_printf(seq
, "Device # : %d\n", card
->slotnumber
);
2017 seq_printf(seq
, "Interfaces : %d\n", card
->card_size
);
2018 seq_printf(seq
, " Initialized : %d\n",
2019 card
->adapters_activated
);
2020 seq_printf(seq
, " Allocated : %d\n",
2021 card
->adapters_allocated
);
2022 ASSERT(card
->card_size
<= SLIC_NBR_MACS
);
2023 for (i
= 0; i
< card
->card_size
; i
++) {
2025 " MAC%d : %2.2X %2.2X %2.2X %2.2X %2.2X %2.2X\n",
2026 i
, config
->macinfo
[i
].macaddrA
[0],
2027 config
->macinfo
[i
].macaddrA
[1],
2028 config
->macinfo
[i
].macaddrA
[2],
2029 config
->macinfo
[i
].macaddrA
[3],
2030 config
->macinfo
[i
].macaddrA
[4],
2031 config
->macinfo
[i
].macaddrA
[5]);
2033 seq_printf(seq
, " IF Init State Duplex/Speed irq\n");
2034 seq_printf(seq
, " -------------------------------\n");
2035 for (i
= 0; i
< card
->adapters_allocated
; i
++) {
2036 struct adapter
*adapter
;
2038 adapter
= card
->adapter
[i
];
2041 " %d %d %s %s %s 0x%X\n",
2042 adapter
->physport
, adapter
->state
,
2043 SLIC_LINKSTATE(adapter
->linkstate
),
2044 SLIC_DUPLEX(adapter
->linkduplex
),
2045 SLIC_SPEED(adapter
->linkspeed
),
2046 (uint
) adapter
->irq
);
2049 seq_printf(seq
, "Generation # : %4.4X\n", card
->gennumber
);
2050 seq_printf(seq
, "RcvQ max entries : %4.4X\n",
2052 seq_printf(seq
, "Ping Status : %8.8X\n",
2054 seq_printf(seq
, "Minimum grant : %2.2x\n",
2056 seq_printf(seq
, "Maximum Latency : %2.2x\n", config
->MaxLat
);
2057 seq_printf(seq
, "PciStatus : %4.4x\n",
2059 seq_printf(seq
, "Debug Device Id : %4.4x\n",
2061 seq_printf(seq
, "DRAM ROM Function : %4.4x\n",
2063 seq_printf(seq
, "Network interface Pin 1 : %2.2x\n",
2064 config
->NetIntPin1
);
2065 seq_printf(seq
, "Network interface Pin 2 : %2.2x\n",
2066 config
->NetIntPin1
);
2067 seq_printf(seq
, "Network interface Pin 3 : %2.2x\n",
2068 config
->NetIntPin1
);
2069 seq_printf(seq
, "PM capabilities : %4.4X\n",
2071 seq_printf(seq
, "Network Clock Controls : %4.4X\n",
2072 config
->NwClkCtrls
);
2074 switch (config
->FruFormat
) {
2075 case ATK_FRU_FORMAT
:
2078 "Vendor : Alacritech, Inc.\n");
2080 "Assembly # : %c%c%c%c%c%c\n",
2081 fru
[0], fru
[1], fru
[2], fru
[3], fru
[4],
2084 "Revision # : %c%c\n",
2087 if (config
->OEMFruFormat
== VENDOR4_FRU_FORMAT
) {
2090 "%c%c%c%c%c%c%c%c%c%c%c%c\n",
2091 fru
[8], fru
[9], fru
[10],
2092 fru
[11], fru
[12], fru
[13],
2093 fru
[16], fru
[17], fru
[18],
2094 fru
[19], fru
[20], fru
[21]);
2098 "%c%c%c%c%c%c%c%c%c%c%c%c%c%c\n",
2099 fru
[8], fru
[9], fru
[10],
2100 fru
[11], fru
[12], fru
[13],
2101 fru
[14], fru
[15], fru
[16],
2102 fru
[17], fru
[18], fru
[19],
2111 "Vendor : Alacritech, Inc.\n");
2113 "Serial # : Empty FRU\n");
2118 switch (config
->OEMFruFormat
) {
2119 case VENDOR1_FRU_FORMAT
:
2121 seq_printf(seq
, "FRU Information:\n");
2122 seq_printf(seq
, " Commodity # : %c\n",
2125 " Assembly # : %c%c%c%c\n",
2126 oemfru
[1], oemfru
[2], oemfru
[3], oemfru
[4]);
2128 " Revision # : %c%c\n",
2129 oemfru
[5], oemfru
[6]);
2131 " Supplier # : %c%c\n",
2132 oemfru
[7], oemfru
[8]);
2135 oemfru
[9], oemfru
[10]);
2137 " Sequence # : %c%c%c\n",
2138 oemfru
[11], oemfru
[12], oemfru
[13]);
2142 case VENDOR2_FRU_FORMAT
:
2144 seq_printf(seq
, "FRU Information:\n");
2147 "%c%c%c%c%c%c%c%c\n",
2148 oemfru
[0], oemfru
[1], oemfru
[2],
2149 oemfru
[3], oemfru
[4], oemfru
[5],
2150 oemfru
[6], oemfru
[7]);
2152 " Supplier # : %c%c%c%c%c\n",
2153 oemfru
[8], oemfru
[9], oemfru
[10],
2154 oemfru
[11], oemfru
[12]);
2157 oemfru
[13], oemfru
[14], oemfru
[15]);
2159 " Sequence # : %c%c%c%c\n",
2160 oemfru
[16], oemfru
[17], oemfru
[18],
2165 case VENDOR3_FRU_FORMAT
:
2167 seq_printf(seq
, "FRU Information:\n");
2170 case VENDOR4_FRU_FORMAT
:
2172 seq_printf(seq
, "FRU Information:\n");
2175 "%c%c%c%c%c%c%c%c\n",
2176 oemfru
[0], oemfru
[1], oemfru
[2],
2177 oemfru
[3], oemfru
[4], oemfru
[5],
2178 oemfru
[6], oemfru
[7]);
2181 "%c%c%c%c%c%c%c%c\n",
2182 oemfru
[8], oemfru
[9], oemfru
[10],
2183 oemfru
[11], oemfru
[12], oemfru
[13],
2184 oemfru
[14], oemfru
[15]);
2187 "%c%c%c%c%c%c%c%c\n",
2188 oemfru
[16], oemfru
[17], oemfru
[18],
2189 oemfru
[19], oemfru
[20], oemfru
[21],
2190 oemfru
[22], oemfru
[23]);
2202 static int slic_debug_adapter_show(struct seq_file
*seq
, void *v
)
2204 struct adapter
*adapter
= seq
->private;
2205 struct net_device
*netdev
= adapter
->netdev
;
2207 seq_printf(seq
, "info: interface : %s\n",
2208 adapter
->netdev
->name
);
2209 seq_printf(seq
, "info: status : %s\n",
2210 SLIC_LINKSTATE(adapter
->linkstate
));
2211 seq_printf(seq
, "info: port : %d\n",
2213 seq_printf(seq
, "info: speed : %s\n",
2214 SLIC_SPEED(adapter
->linkspeed
));
2215 seq_printf(seq
, "info: duplex : %s\n",
2216 SLIC_DUPLEX(adapter
->linkduplex
));
2217 seq_printf(seq
, "info: irq : 0x%X\n",
2218 (uint
) adapter
->irq
);
2219 seq_printf(seq
, "info: Interrupt Agg Delay: %d usec\n",
2220 adapter
->card
->loadlevel_current
);
2221 seq_printf(seq
, "info: RcvQ max entries : %4.4X\n",
2223 seq_printf(seq
, "info: RcvQ current : %4.4X\n",
2224 adapter
->rcvqueue
.count
);
2225 seq_printf(seq
, "rx stats: packets : %8.8lX\n",
2226 netdev
->stats
.rx_packets
);
2227 seq_printf(seq
, "rx stats: bytes : %8.8lX\n",
2228 netdev
->stats
.rx_bytes
);
2229 seq_printf(seq
, "rx stats: broadcasts : %8.8X\n",
2230 adapter
->rcv_broadcasts
);
2231 seq_printf(seq
, "rx stats: multicasts : %8.8X\n",
2232 adapter
->rcv_multicasts
);
2233 seq_printf(seq
, "rx stats: unicasts : %8.8X\n",
2234 adapter
->rcv_unicasts
);
2235 seq_printf(seq
, "rx stats: errors : %8.8X\n",
2236 (u32
) adapter
->slic_stats
.iface
.rcv_errors
);
2237 seq_printf(seq
, "rx stats: Missed errors : %8.8X\n",
2238 (u32
) adapter
->slic_stats
.iface
.rcv_discards
);
2239 seq_printf(seq
, "rx stats: drops : %8.8X\n",
2240 (u32
) adapter
->rcv_drops
);
2241 seq_printf(seq
, "tx stats: packets : %8.8lX\n",
2242 netdev
->stats
.tx_packets
);
2243 seq_printf(seq
, "tx stats: bytes : %8.8lX\n",
2244 netdev
->stats
.tx_bytes
);
2245 seq_printf(seq
, "tx stats: errors : %8.8X\n",
2246 (u32
) adapter
->slic_stats
.iface
.xmt_errors
);
2247 seq_printf(seq
, "rx stats: multicasts : %8.8lX\n",
2248 netdev
->stats
.multicast
);
2249 seq_printf(seq
, "tx stats: collision errors : %8.8X\n",
2250 (u32
) adapter
->slic_stats
.iface
.xmit_collisions
);
2251 seq_printf(seq
, "perf: Max rcv frames/isr : %8.8X\n",
2252 adapter
->max_isr_rcvs
);
2253 seq_printf(seq
, "perf: Rcv interrupt yields : %8.8X\n",
2254 adapter
->rcv_interrupt_yields
);
2255 seq_printf(seq
, "perf: Max xmit complete/isr : %8.8X\n",
2256 adapter
->max_isr_xmits
);
2257 seq_printf(seq
, "perf: error interrupts : %8.8X\n",
2258 adapter
->error_interrupts
);
2259 seq_printf(seq
, "perf: error rmiss interrupts : %8.8X\n",
2260 adapter
->error_rmiss_interrupts
);
2261 seq_printf(seq
, "perf: rcv interrupts : %8.8X\n",
2262 adapter
->rcv_interrupts
);
2263 seq_printf(seq
, "perf: xmit interrupts : %8.8X\n",
2264 adapter
->xmit_interrupts
);
2265 seq_printf(seq
, "perf: link event interrupts : %8.8X\n",
2266 adapter
->linkevent_interrupts
);
2267 seq_printf(seq
, "perf: UPR interrupts : %8.8X\n",
2268 adapter
->upr_interrupts
);
2269 seq_printf(seq
, "perf: interrupt count : %8.8X\n",
2271 seq_printf(seq
, "perf: false interrupts : %8.8X\n",
2272 adapter
->false_interrupts
);
2273 seq_printf(seq
, "perf: All register writes : %8.8X\n",
2274 adapter
->all_reg_writes
);
2275 seq_printf(seq
, "perf: ICR register writes : %8.8X\n",
2276 adapter
->icr_reg_writes
);
2277 seq_printf(seq
, "perf: ISR register writes : %8.8X\n",
2278 adapter
->isr_reg_writes
);
2279 seq_printf(seq
, "ifevents: overflow 802 errors : %8.8X\n",
2280 adapter
->if_events
.oflow802
);
2281 seq_printf(seq
, "ifevents: transport overflow errors: %8.8X\n",
2282 adapter
->if_events
.Tprtoflow
);
2283 seq_printf(seq
, "ifevents: underflow errors : %8.8X\n",
2284 adapter
->if_events
.uflow802
);
2285 seq_printf(seq
, "ifevents: receive early : %8.8X\n",
2286 adapter
->if_events
.rcvearly
);
2287 seq_printf(seq
, "ifevents: buffer overflows : %8.8X\n",
2288 adapter
->if_events
.Bufov
);
2289 seq_printf(seq
, "ifevents: carrier errors : %8.8X\n",
2290 adapter
->if_events
.Carre
);
2291 seq_printf(seq
, "ifevents: Long : %8.8X\n",
2292 adapter
->if_events
.Longe
);
2293 seq_printf(seq
, "ifevents: invalid preambles : %8.8X\n",
2294 adapter
->if_events
.Invp
);
2295 seq_printf(seq
, "ifevents: CRC errors : %8.8X\n",
2296 adapter
->if_events
.Crc
);
2297 seq_printf(seq
, "ifevents: dribble nibbles : %8.8X\n",
2298 adapter
->if_events
.Drbl
);
2299 seq_printf(seq
, "ifevents: Code violations : %8.8X\n",
2300 adapter
->if_events
.Code
);
2301 seq_printf(seq
, "ifevents: TCP checksum errors : %8.8X\n",
2302 adapter
->if_events
.TpCsum
);
2303 seq_printf(seq
, "ifevents: TCP header short errors : %8.8X\n",
2304 adapter
->if_events
.TpHlen
);
2305 seq_printf(seq
, "ifevents: IP checksum errors : %8.8X\n",
2306 adapter
->if_events
.IpCsum
);
2307 seq_printf(seq
, "ifevents: IP frame incompletes : %8.8X\n",
2308 adapter
->if_events
.IpLen
);
2309 seq_printf(seq
, "ifevents: IP headers shorts : %8.8X\n",
2310 adapter
->if_events
.IpHlen
);
2314 static int slic_debug_adapter_open(struct inode
*inode
, struct file
*file
)
2316 return single_open(file
, slic_debug_adapter_show
, inode
->i_private
);
2319 static int slic_debug_card_open(struct inode
*inode
, struct file
*file
)
2321 return single_open(file
, slic_debug_card_show
, inode
->i_private
);
2324 static const struct file_operations slic_debug_adapter_fops
= {
2325 .owner
= THIS_MODULE
,
2326 .open
= slic_debug_adapter_open
,
2328 .llseek
= seq_lseek
,
2329 .release
= single_release
,
2332 static const struct file_operations slic_debug_card_fops
= {
2333 .owner
= THIS_MODULE
,
2334 .open
= slic_debug_card_open
,
2336 .llseek
= seq_lseek
,
2337 .release
= single_release
,
2340 static void slic_debug_adapter_create(struct adapter
*adapter
)
2344 struct sliccard
*card
= adapter
->card
;
2346 if (!card
->debugfs_dir
)
2349 sprintf(name
, "port%d", adapter
->port
);
2350 d
= debugfs_create_file(name
, S_IRUGO
,
2351 card
->debugfs_dir
, adapter
,
2352 &slic_debug_adapter_fops
);
2353 if (!d
|| IS_ERR(d
))
2354 pr_info(PFX
"%s: debugfs create failed\n", name
);
2356 adapter
->debugfs_entry
= d
;
2359 static void slic_debug_adapter_destroy(struct adapter
*adapter
)
2361 debugfs_remove(adapter
->debugfs_entry
);
2362 adapter
->debugfs_entry
= NULL
;
2365 static void slic_debug_card_create(struct sliccard
*card
)
2368 char name
[IFNAMSIZ
];
2370 snprintf(name
, sizeof(name
), "slic%d", card
->cardnum
);
2371 d
= debugfs_create_dir(name
, slic_debugfs
);
2372 if (!d
|| IS_ERR(d
))
2373 pr_info(PFX
"%s: debugfs create dir failed\n",
2376 card
->debugfs_dir
= d
;
2377 d
= debugfs_create_file("cardinfo", S_IRUGO
,
2379 &slic_debug_card_fops
);
2380 if (!d
|| IS_ERR(d
))
2381 pr_info(PFX
"%s: debugfs create failed\n",
2384 card
->debugfs_cardinfo
= d
;
2388 static void slic_debug_card_destroy(struct sliccard
*card
)
2392 for (i
= 0; i
< card
->card_size
; i
++) {
2393 struct adapter
*adapter
;
2395 adapter
= card
->adapter
[i
];
2397 slic_debug_adapter_destroy(adapter
);
2399 if (card
->debugfs_cardinfo
) {
2400 debugfs_remove(card
->debugfs_cardinfo
);
2401 card
->debugfs_cardinfo
= NULL
;
2403 if (card
->debugfs_dir
) {
2404 debugfs_remove(card
->debugfs_dir
);
2405 card
->debugfs_dir
= NULL
;
2409 static void slic_debug_init(void)
2413 ent
= debugfs_create_dir("slic", NULL
);
2414 if (!ent
|| IS_ERR(ent
)) {
2415 pr_info(PFX
"debugfs create directory failed\n");
2422 static void slic_debug_cleanup(void)
2425 debugfs_remove(slic_debugfs
);
2426 slic_debugfs
= NULL
;
2431 * slic_link_event_handler -
2433 * Initiate a link configuration sequence. The link configuration begins
2434 * by issuing a READ_LINK_STATUS command to the Utility Processor on the
2435 * SLIC. Since the command finishes asynchronously, the slic_upr_comlete
2436 * routine will follow it up witha UP configuration write command, which
2437 * will also complete asynchronously.
2440 static void slic_link_event_handler(struct adapter
*adapter
)
2443 struct slic_shmem
*pshmem
;
2445 if (adapter
->state
!= ADAPT_UP
) {
2446 /* Adapter is not operational. Ignore. */
2450 pshmem
= (struct slic_shmem
*)adapter
->phys_shmem
;
2452 #if BITS_PER_LONG == 64
2453 status
= slic_upr_request(adapter
,
2455 SLIC_GET_ADDR_LOW(&pshmem
->linkstatus
),
2456 SLIC_GET_ADDR_HIGH(&pshmem
->linkstatus
),
2459 status
= slic_upr_request(adapter
, SLIC_UPR_RLSR
,
2460 (u32
) &pshmem
->linkstatus
, /* no 4GB wrap guaranteed */
2463 ASSERT(status
== 0);
2466 static void slic_init_cleanup(struct adapter
*adapter
)
2468 if (adapter
->intrregistered
) {
2469 adapter
->intrregistered
= 0;
2470 free_irq(adapter
->netdev
->irq
, adapter
->netdev
);
2473 if (adapter
->pshmem
) {
2474 pci_free_consistent(adapter
->pcidev
,
2475 sizeof(struct slic_shmem
),
2476 adapter
->pshmem
, adapter
->phys_shmem
);
2477 adapter
->pshmem
= NULL
;
2478 adapter
->phys_shmem
= (dma_addr_t
) NULL
;
2481 if (adapter
->pingtimerset
) {
2482 adapter
->pingtimerset
= 0;
2483 del_timer(&adapter
->pingtimer
);
2486 slic_rspqueue_free(adapter
);
2487 slic_cmdq_free(adapter
);
2488 slic_rcvqueue_free(adapter
);
2492 * Allocate a mcast_address structure to hold the multicast address.
2495 static int slic_mcast_add_list(struct adapter
*adapter
, char *address
)
2497 struct mcast_address
*mcaddr
, *mlist
;
2499 /* Check to see if it already exists */
2500 mlist
= adapter
->mcastaddrs
;
2502 if (!compare_ether_addr(mlist
->address
, address
))
2504 mlist
= mlist
->next
;
2507 /* Doesn't already exist. Allocate a structure to hold it */
2508 mcaddr
= kmalloc(sizeof(struct mcast_address
), GFP_ATOMIC
);
2512 memcpy(mcaddr
->address
, address
, 6);
2514 mcaddr
->next
= adapter
->mcastaddrs
;
2515 adapter
->mcastaddrs
= mcaddr
;
2520 static void slic_mcast_set_list(struct net_device
*dev
)
2522 struct adapter
*adapter
= netdev_priv(dev
);
2525 struct netdev_hw_addr
*ha
;
2529 netdev_for_each_mc_addr(ha
, dev
) {
2530 addresses
= (char *) &ha
->addr
;
2531 status
= slic_mcast_add_list(adapter
, addresses
);
2534 slic_mcast_set_bit(adapter
, addresses
);
2537 if (adapter
->devflags_prev
!= dev
->flags
) {
2538 adapter
->macopts
= MAC_DIRECTED
;
2540 if (dev
->flags
& IFF_BROADCAST
)
2541 adapter
->macopts
|= MAC_BCAST
;
2542 if (dev
->flags
& IFF_PROMISC
)
2543 adapter
->macopts
|= MAC_PROMISC
;
2544 if (dev
->flags
& IFF_ALLMULTI
)
2545 adapter
->macopts
|= MAC_ALLMCAST
;
2546 if (dev
->flags
& IFF_MULTICAST
)
2547 adapter
->macopts
|= MAC_MCAST
;
2549 adapter
->devflags_prev
= dev
->flags
;
2550 slic_config_set(adapter
, true);
2553 slic_mcast_set_mask(adapter
);
2558 #define XMIT_FAIL_LINK_STATE 1
2559 #define XMIT_FAIL_ZERO_LENGTH 2
2560 #define XMIT_FAIL_HOSTCMD_FAIL 3
2562 static void slic_xmit_build_request(struct adapter
*adapter
,
2563 struct slic_hostcmd
*hcmd
, struct sk_buff
*skb
)
2565 struct slic_host64_cmd
*ihcmd
;
2568 ihcmd
= &hcmd
->cmd64
;
2570 ihcmd
->flags
= (adapter
->port
<< IHFLG_IFSHFT
);
2571 ihcmd
->command
= IHCMD_XMT_REQ
;
2572 ihcmd
->u
.slic_buffers
.totlen
= skb
->len
;
2573 phys_addr
= pci_map_single(adapter
->pcidev
, skb
->data
, skb
->len
,
2575 ihcmd
->u
.slic_buffers
.bufs
[0].paddrl
= SLIC_GET_ADDR_LOW(phys_addr
);
2576 ihcmd
->u
.slic_buffers
.bufs
[0].paddrh
= SLIC_GET_ADDR_HIGH(phys_addr
);
2577 ihcmd
->u
.slic_buffers
.bufs
[0].length
= skb
->len
;
2578 #if BITS_PER_LONG == 64
2579 hcmd
->cmdsize
= (u32
) ((((u64
)&ihcmd
->u
.slic_buffers
.bufs
[1] -
2580 (u64
) hcmd
) + 31) >> 5);
2582 hcmd
->cmdsize
= ((((u32
) &ihcmd
->u
.slic_buffers
.bufs
[1] -
2583 (u32
) hcmd
) + 31) >> 5);
2587 static void slic_xmit_fail(struct adapter
*adapter
,
2588 struct sk_buff
*skb
,
2589 void *cmd
, u32 skbtype
, u32 status
)
2591 if (adapter
->xmitq_full
)
2592 netif_stop_queue(adapter
->netdev
);
2593 if ((cmd
== NULL
) && (status
<= XMIT_FAIL_HOSTCMD_FAIL
)) {
2595 case XMIT_FAIL_LINK_STATE
:
2596 dev_err(&adapter
->netdev
->dev
,
2597 "reject xmit skb[%p: %x] linkstate[%s] "
2598 "adapter[%s:%d] card[%s:%d]\n",
2600 SLIC_LINKSTATE(adapter
->linkstate
),
2601 SLIC_ADAPTER_STATE(adapter
->state
),
2603 SLIC_CARD_STATE(adapter
->card
->state
),
2604 adapter
->card
->state
);
2606 case XMIT_FAIL_ZERO_LENGTH
:
2607 dev_err(&adapter
->netdev
->dev
,
2608 "xmit_start skb->len == 0 skb[%p] type[%x]\n",
2609 skb
, skb
->pkt_type
);
2611 case XMIT_FAIL_HOSTCMD_FAIL
:
2612 dev_err(&adapter
->netdev
->dev
,
2613 "xmit_start skb[%p] type[%x] No host commands "
2614 "available\n", skb
, skb
->pkt_type
);
2621 adapter
->netdev
->stats
.tx_dropped
++;
2624 static void slic_rcv_handle_error(struct adapter
*adapter
,
2625 struct slic_rcvbuf
*rcvbuf
)
2627 struct slic_hddr_wds
*hdr
= (struct slic_hddr_wds
*)rcvbuf
->data
;
2628 struct net_device
*netdev
= adapter
->netdev
;
2630 if (adapter
->devid
!= SLIC_1GB_DEVICE_ID
) {
2631 if (hdr
->frame_status14
& VRHSTAT_802OE
)
2632 adapter
->if_events
.oflow802
++;
2633 if (hdr
->frame_status14
& VRHSTAT_TPOFLO
)
2634 adapter
->if_events
.Tprtoflow
++;
2635 if (hdr
->frame_status_b14
& VRHSTATB_802UE
)
2636 adapter
->if_events
.uflow802
++;
2637 if (hdr
->frame_status_b14
& VRHSTATB_RCVE
) {
2638 adapter
->if_events
.rcvearly
++;
2639 netdev
->stats
.rx_fifo_errors
++;
2641 if (hdr
->frame_status_b14
& VRHSTATB_BUFF
) {
2642 adapter
->if_events
.Bufov
++;
2643 netdev
->stats
.rx_over_errors
++;
2645 if (hdr
->frame_status_b14
& VRHSTATB_CARRE
) {
2646 adapter
->if_events
.Carre
++;
2647 netdev
->stats
.tx_carrier_errors
++;
2649 if (hdr
->frame_status_b14
& VRHSTATB_LONGE
)
2650 adapter
->if_events
.Longe
++;
2651 if (hdr
->frame_status_b14
& VRHSTATB_PREA
)
2652 adapter
->if_events
.Invp
++;
2653 if (hdr
->frame_status_b14
& VRHSTATB_CRC
) {
2654 adapter
->if_events
.Crc
++;
2655 netdev
->stats
.rx_crc_errors
++;
2657 if (hdr
->frame_status_b14
& VRHSTATB_DRBL
)
2658 adapter
->if_events
.Drbl
++;
2659 if (hdr
->frame_status_b14
& VRHSTATB_CODE
)
2660 adapter
->if_events
.Code
++;
2661 if (hdr
->frame_status_b14
& VRHSTATB_TPCSUM
)
2662 adapter
->if_events
.TpCsum
++;
2663 if (hdr
->frame_status_b14
& VRHSTATB_TPHLEN
)
2664 adapter
->if_events
.TpHlen
++;
2665 if (hdr
->frame_status_b14
& VRHSTATB_IPCSUM
)
2666 adapter
->if_events
.IpCsum
++;
2667 if (hdr
->frame_status_b14
& VRHSTATB_IPLERR
)
2668 adapter
->if_events
.IpLen
++;
2669 if (hdr
->frame_status_b14
& VRHSTATB_IPHERR
)
2670 adapter
->if_events
.IpHlen
++;
2672 if (hdr
->frame_statusGB
& VGBSTAT_XPERR
) {
2673 u32 xerr
= hdr
->frame_statusGB
>> VGBSTAT_XERRSHFT
;
2675 if (xerr
== VGBSTAT_XCSERR
)
2676 adapter
->if_events
.TpCsum
++;
2677 if (xerr
== VGBSTAT_XUFLOW
)
2678 adapter
->if_events
.Tprtoflow
++;
2679 if (xerr
== VGBSTAT_XHLEN
)
2680 adapter
->if_events
.TpHlen
++;
2682 if (hdr
->frame_statusGB
& VGBSTAT_NETERR
) {
2685 frame_statusGB
>> VGBSTAT_NERRSHFT
) &
2687 if (nerr
== VGBSTAT_NCSERR
)
2688 adapter
->if_events
.IpCsum
++;
2689 if (nerr
== VGBSTAT_NUFLOW
)
2690 adapter
->if_events
.IpLen
++;
2691 if (nerr
== VGBSTAT_NHLEN
)
2692 adapter
->if_events
.IpHlen
++;
2694 if (hdr
->frame_statusGB
& VGBSTAT_LNKERR
) {
2695 u32 lerr
= hdr
->frame_statusGB
& VGBSTAT_LERRMSK
;
2697 if (lerr
== VGBSTAT_LDEARLY
)
2698 adapter
->if_events
.rcvearly
++;
2699 if (lerr
== VGBSTAT_LBOFLO
)
2700 adapter
->if_events
.Bufov
++;
2701 if (lerr
== VGBSTAT_LCODERR
)
2702 adapter
->if_events
.Code
++;
2703 if (lerr
== VGBSTAT_LDBLNBL
)
2704 adapter
->if_events
.Drbl
++;
2705 if (lerr
== VGBSTAT_LCRCERR
)
2706 adapter
->if_events
.Crc
++;
2707 if (lerr
== VGBSTAT_LOFLO
)
2708 adapter
->if_events
.oflow802
++;
2709 if (lerr
== VGBSTAT_LUFLO
)
2710 adapter
->if_events
.uflow802
++;
2716 #define TCP_OFFLOAD_FRAME_PUSHFLAG 0x10000000
2717 #define M_FAST_PATH 0x0040
2719 static void slic_rcv_handler(struct adapter
*adapter
)
2721 struct net_device
*netdev
= adapter
->netdev
;
2722 struct sk_buff
*skb
;
2723 struct slic_rcvbuf
*rcvbuf
;
2726 while ((skb
= slic_rcvqueue_getnext(adapter
))) {
2730 rcvbuf
= (struct slic_rcvbuf
*)skb
->head
;
2731 adapter
->card
->events
++;
2732 if (rcvbuf
->status
& IRHDDR_ERR
) {
2733 adapter
->rx_errors
++;
2734 slic_rcv_handle_error(adapter
, rcvbuf
);
2735 slic_rcvqueue_reinsert(adapter
, skb
);
2739 if (!slic_mac_filter(adapter
, (struct ether_header
*)
2741 slic_rcvqueue_reinsert(adapter
, skb
);
2744 skb_pull(skb
, SLIC_RCVBUF_HEADSIZE
);
2745 rx_bytes
= (rcvbuf
->length
& IRHDDR_FLEN_MSK
);
2746 skb_put(skb
, rx_bytes
);
2747 netdev
->stats
.rx_packets
++;
2748 netdev
->stats
.rx_bytes
+= rx_bytes
;
2749 #if SLIC_OFFLOAD_IP_CHECKSUM
2750 skb
->ip_summed
= CHECKSUM_UNNECESSARY
;
2753 skb
->dev
= adapter
->netdev
;
2754 skb
->protocol
= eth_type_trans(skb
, skb
->dev
);
2758 #if SLIC_INTERRUPT_PROCESS_LIMIT
2759 if (frames
>= SLIC_RCVQ_MAX_PROCESS_ISR
) {
2760 adapter
->rcv_interrupt_yields
++;
2765 adapter
->max_isr_rcvs
= max(adapter
->max_isr_rcvs
, frames
);
2768 static void slic_xmit_complete(struct adapter
*adapter
)
2770 struct slic_hostcmd
*hcmd
;
2771 struct slic_rspbuf
*rspbuf
;
2773 struct slic_handle_word slic_handle_word
;
2776 rspbuf
= slic_rspqueue_getnext(adapter
);
2779 adapter
->xmit_completes
++;
2780 adapter
->card
->events
++;
2782 Get the complete host command buffer
2784 slic_handle_word
.handle_token
= rspbuf
->hosthandle
;
2785 ASSERT(slic_handle_word
.handle_index
);
2786 ASSERT(slic_handle_word
.handle_index
<= SLIC_CMDQ_MAXCMDS
);
2788 (struct slic_hostcmd
*)
2789 adapter
->slic_handles
[slic_handle_word
.handle_index
].
2791 /* hcmd = (struct slic_hostcmd *) rspbuf->hosthandle; */
2793 ASSERT(hcmd
->pslic_handle
==
2794 &adapter
->slic_handles
[slic_handle_word
.handle_index
]);
2795 if (hcmd
->type
== SLIC_CMD_DUMB
) {
2797 dev_kfree_skb_irq(hcmd
->skb
);
2798 slic_cmdq_putdone_irq(adapter
, hcmd
);
2801 rspbuf
->hosthandle
= 0;
2804 adapter
->max_isr_xmits
= max(adapter
->max_isr_xmits
, frames
);
2807 static irqreturn_t
slic_interrupt(int irq
, void *dev_id
)
2809 struct net_device
*dev
= (struct net_device
*)dev_id
;
2810 struct adapter
*adapter
= netdev_priv(dev
);
2813 if ((adapter
->pshmem
) && (adapter
->pshmem
->isr
)) {
2814 slic_reg32_write(&adapter
->slic_regs
->slic_icr
,
2815 ICR_INT_MASK
, FLUSH
);
2816 isr
= adapter
->isrcopy
= adapter
->pshmem
->isr
;
2817 adapter
->pshmem
->isr
= 0;
2818 adapter
->num_isrs
++;
2819 switch (adapter
->card
->state
) {
2821 if (isr
& ~ISR_IO
) {
2822 if (isr
& ISR_ERR
) {
2823 adapter
->error_interrupts
++;
2824 if (isr
& ISR_RMISS
) {
2829 struct slic_rcvqueue
*rcvq
=
2833 error_rmiss_interrupts
++;
2835 rcv_count
= rcvq
->count
;
2836 pre_count
= rcvq
->count
;
2837 errors
= rcvq
->errors
;
2839 while (rcvq
->count
<
2840 SLIC_RCVQ_FILLTHRESH
) {
2847 } else if (isr
& ISR_XDROP
) {
2849 "isr & ISR_ERR [%x] "
2850 "ISR_XDROP \n", isr
);
2853 "isr & ISR_ERR [%x]\n",
2858 if (isr
& ISR_LEVENT
) {
2859 adapter
->linkevent_interrupts
++;
2860 slic_link_event_handler(adapter
);
2863 if ((isr
& ISR_UPC
) ||
2864 (isr
& ISR_UPCERR
) || (isr
& ISR_UPCBSY
)) {
2865 adapter
->upr_interrupts
++;
2866 slic_upr_request_complete(adapter
, isr
);
2870 if (isr
& ISR_RCV
) {
2871 adapter
->rcv_interrupts
++;
2872 slic_rcv_handler(adapter
);
2875 if (isr
& ISR_CMD
) {
2876 adapter
->xmit_interrupts
++;
2877 slic_xmit_complete(adapter
);
2882 if ((isr
& ISR_UPC
) ||
2883 (isr
& ISR_UPCERR
) || (isr
& ISR_UPCBSY
)) {
2884 adapter
->upr_interrupts
++;
2885 slic_upr_request_complete(adapter
, isr
);
2893 adapter
->isrcopy
= 0;
2894 adapter
->all_reg_writes
+= 2;
2895 adapter
->isr_reg_writes
++;
2896 slic_reg32_write(&adapter
->slic_regs
->slic_isr
, 0, FLUSH
);
2898 adapter
->false_interrupts
++;
2903 #define NORMAL_ETHFRAME 0
2905 static netdev_tx_t
slic_xmit_start(struct sk_buff
*skb
, struct net_device
*dev
)
2907 struct sliccard
*card
;
2908 struct adapter
*adapter
= netdev_priv(dev
);
2909 struct slic_hostcmd
*hcmd
= NULL
;
2911 u32 skbtype
= NORMAL_ETHFRAME
;
2912 void *offloadcmd
= NULL
;
2914 card
= adapter
->card
;
2916 if ((adapter
->linkstate
!= LINK_UP
) ||
2917 (adapter
->state
!= ADAPT_UP
) || (card
->state
!= CARD_UP
)) {
2918 status
= XMIT_FAIL_LINK_STATE
;
2921 } else if (skb
->len
== 0) {
2922 status
= XMIT_FAIL_ZERO_LENGTH
;
2926 if (skbtype
== NORMAL_ETHFRAME
) {
2927 hcmd
= slic_cmdq_getfree(adapter
);
2929 adapter
->xmitq_full
= 1;
2930 status
= XMIT_FAIL_HOSTCMD_FAIL
;
2933 ASSERT(hcmd
->pslic_handle
);
2934 ASSERT(hcmd
->cmd64
.hosthandle
==
2935 hcmd
->pslic_handle
->token
.handle_token
);
2938 hcmd
->type
= SLIC_CMD_DUMB
;
2939 if (skbtype
== NORMAL_ETHFRAME
)
2940 slic_xmit_build_request(adapter
, hcmd
, skb
);
2942 dev
->stats
.tx_packets
++;
2943 dev
->stats
.tx_bytes
+= skb
->len
;
2946 if (adapter
->kill_card
) {
2947 struct slic_host64_cmd ihcmd
;
2949 ihcmd
= &hcmd
->cmd64
;
2951 ihcmd
->flags
|= 0x40;
2952 adapter
->kill_card
= 0; /* only do this once */
2955 if (hcmd
->paddrh
== 0) {
2956 slic_reg32_write(&adapter
->slic_regs
->slic_cbar
,
2957 (hcmd
->paddrl
| hcmd
->cmdsize
), DONT_FLUSH
);
2959 slic_reg64_write(adapter
, &adapter
->slic_regs
->slic_cbar64
,
2960 (hcmd
->paddrl
| hcmd
->cmdsize
),
2961 &adapter
->slic_regs
->slic_addr_upper
,
2962 hcmd
->paddrh
, DONT_FLUSH
);
2965 return NETDEV_TX_OK
;
2967 slic_xmit_fail(adapter
, skb
, offloadcmd
, skbtype
, status
);
2972 static void slic_adapter_freeresources(struct adapter
*adapter
)
2974 slic_init_cleanup(adapter
);
2975 adapter
->error_interrupts
= 0;
2976 adapter
->rcv_interrupts
= 0;
2977 adapter
->xmit_interrupts
= 0;
2978 adapter
->linkevent_interrupts
= 0;
2979 adapter
->upr_interrupts
= 0;
2980 adapter
->num_isrs
= 0;
2981 adapter
->xmit_completes
= 0;
2982 adapter
->rcv_broadcasts
= 0;
2983 adapter
->rcv_multicasts
= 0;
2984 adapter
->rcv_unicasts
= 0;
2987 static int slic_adapter_allocresources(struct adapter
*adapter
)
2989 if (!adapter
->intrregistered
) {
2992 spin_unlock_irqrestore(&slic_global
.driver_lock
.lock
,
2993 slic_global
.driver_lock
.flags
);
2995 retval
= request_irq(adapter
->netdev
->irq
,
2998 adapter
->netdev
->name
, adapter
->netdev
);
3000 spin_lock_irqsave(&slic_global
.driver_lock
.lock
,
3001 slic_global
.driver_lock
.flags
);
3004 dev_err(&adapter
->netdev
->dev
,
3005 "request_irq (%s) FAILED [%x]\n",
3006 adapter
->netdev
->name
, retval
);
3009 adapter
->intrregistered
= 1;
3017 * Perform initialization of our slic interface.
3020 static int slic_if_init(struct adapter
*adapter
)
3022 struct sliccard
*card
= adapter
->card
;
3023 struct net_device
*dev
= adapter
->netdev
;
3024 __iomem
struct slic_regs
*slic_regs
= adapter
->slic_regs
;
3025 struct slic_shmem
*pshmem
;
3030 /* adapter should be down at this point */
3031 if (adapter
->state
!= ADAPT_DOWN
) {
3032 dev_err(&dev
->dev
, "%s: adapter->state != ADAPT_DOWN\n",
3037 ASSERT(adapter
->linkstate
== LINK_DOWN
);
3039 adapter
->devflags_prev
= dev
->flags
;
3040 adapter
->macopts
= MAC_DIRECTED
;
3042 if (dev
->flags
& IFF_BROADCAST
)
3043 adapter
->macopts
|= MAC_BCAST
;
3044 if (dev
->flags
& IFF_PROMISC
)
3045 adapter
->macopts
|= MAC_PROMISC
;
3046 if (dev
->flags
& IFF_ALLMULTI
)
3047 adapter
->macopts
|= MAC_ALLMCAST
;
3048 if (dev
->flags
& IFF_MULTICAST
)
3049 adapter
->macopts
|= MAC_MCAST
;
3051 rc
= slic_adapter_allocresources(adapter
);
3054 "%s: slic_adapter_allocresources FAILED %x\n",
3056 slic_adapter_freeresources(adapter
);
3060 if (!adapter
->queues_initialized
) {
3061 if ((rc
= slic_rspqueue_init(adapter
)))
3063 if ((rc
= slic_cmdq_init(adapter
)))
3065 if ((rc
= slic_rcvqueue_init(adapter
)))
3067 adapter
->queues_initialized
= 1;
3070 slic_reg32_write(&slic_regs
->slic_icr
, ICR_INT_OFF
, FLUSH
);
3073 if (!adapter
->isp_initialized
) {
3074 pshmem
= (struct slic_shmem
*)adapter
->phys_shmem
;
3076 spin_lock_irqsave(&adapter
->bit64reglock
.lock
,
3077 adapter
->bit64reglock
.flags
);
3079 #if BITS_PER_LONG == 64
3080 slic_reg32_write(&slic_regs
->slic_addr_upper
,
3081 SLIC_GET_ADDR_HIGH(&pshmem
->isr
), DONT_FLUSH
);
3082 slic_reg32_write(&slic_regs
->slic_isp
,
3083 SLIC_GET_ADDR_LOW(&pshmem
->isr
), FLUSH
);
3085 slic_reg32_write(&slic_regs
->slic_addr_upper
, 0, DONT_FLUSH
);
3086 slic_reg32_write(&slic_regs
->slic_isp
, (u32
)&pshmem
->isr
, FLUSH
);
3088 spin_unlock_irqrestore(&adapter
->bit64reglock
.lock
,
3089 adapter
->bit64reglock
.flags
);
3090 adapter
->isp_initialized
= 1;
3093 adapter
->state
= ADAPT_UP
;
3094 if (!card
->loadtimerset
) {
3095 init_timer(&card
->loadtimer
);
3096 card
->loadtimer
.expires
=
3097 jiffies
+ (SLIC_LOADTIMER_PERIOD
* HZ
);
3098 card
->loadtimer
.data
= (ulong
) card
;
3099 card
->loadtimer
.function
= &slic_timer_load_check
;
3100 add_timer(&card
->loadtimer
);
3102 card
->loadtimerset
= 1;
3105 if (!adapter
->pingtimerset
) {
3106 init_timer(&adapter
->pingtimer
);
3107 adapter
->pingtimer
.expires
=
3108 jiffies
+ (PING_TIMER_INTERVAL
* HZ
);
3109 adapter
->pingtimer
.data
= (ulong
) dev
;
3110 adapter
->pingtimer
.function
= &slic_timer_ping
;
3111 add_timer(&adapter
->pingtimer
);
3112 adapter
->pingtimerset
= 1;
3113 adapter
->card
->pingstatus
= ISR_PINGMASK
;
3117 * clear any pending events, then enable interrupts
3119 adapter
->isrcopy
= 0;
3120 adapter
->pshmem
->isr
= 0;
3121 slic_reg32_write(&slic_regs
->slic_isr
, 0, FLUSH
);
3122 slic_reg32_write(&slic_regs
->slic_icr
, ICR_INT_ON
, FLUSH
);
3124 slic_link_config(adapter
, LINK_AUTOSPEED
, LINK_AUTOD
);
3125 slic_link_event_handler(adapter
);
3131 static int slic_entry_open(struct net_device
*dev
)
3133 struct adapter
*adapter
= netdev_priv(dev
);
3134 struct sliccard
*card
= adapter
->card
;
3141 netif_stop_queue(adapter
->netdev
);
3143 spin_lock_irqsave(&slic_global
.driver_lock
.lock
,
3144 slic_global
.driver_lock
.flags
);
3146 if (!adapter
->activated
) {
3147 card
->adapters_activated
++;
3148 slic_global
.num_slic_ports_active
++;
3149 adapter
->activated
= 1;
3151 status
= slic_if_init(adapter
);
3154 if (adapter
->activated
) {
3155 card
->adapters_activated
--;
3156 slic_global
.num_slic_ports_active
--;
3157 adapter
->activated
= 0;
3160 spin_unlock_irqrestore(&slic_global
.driver_lock
.lock
,
3161 slic_global
.driver_lock
.flags
);
3167 card
->master
= adapter
;
3170 spin_unlock_irqrestore(&slic_global
.driver_lock
.lock
,
3171 slic_global
.driver_lock
.flags
);
3178 static void slic_card_cleanup(struct sliccard
*card
)
3180 if (card
->loadtimerset
) {
3181 card
->loadtimerset
= 0;
3182 del_timer(&card
->loadtimer
);
3185 slic_debug_card_destroy(card
);
3190 static void __devexit
slic_entry_remove(struct pci_dev
*pcidev
)
3192 struct net_device
*dev
= pci_get_drvdata(pcidev
);
3195 struct adapter
*adapter
= netdev_priv(dev
);
3196 struct sliccard
*card
;
3197 struct mcast_address
*mcaddr
, *mlist
;
3200 slic_adapter_freeresources(adapter
);
3201 slic_unmap_mmio_space(adapter
);
3202 unregister_netdev(dev
);
3204 mmio_start
= pci_resource_start(pcidev
, 0);
3205 mmio_len
= pci_resource_len(pcidev
, 0);
3207 release_mem_region(mmio_start
, mmio_len
);
3209 iounmap((void __iomem
*)dev
->base_addr
);
3210 /* free multicast addresses */
3211 mlist
= adapter
->mcastaddrs
;
3214 mlist
= mlist
->next
;
3217 ASSERT(adapter
->card
);
3218 card
= adapter
->card
;
3219 ASSERT(card
->adapters_allocated
);
3220 card
->adapters_allocated
--;
3221 adapter
->allocated
= 0;
3222 if (!card
->adapters_allocated
) {
3223 struct sliccard
*curr_card
= slic_global
.slic_card
;
3224 if (curr_card
== card
) {
3225 slic_global
.slic_card
= card
->next
;
3227 while (curr_card
->next
!= card
)
3228 curr_card
= curr_card
->next
;
3230 curr_card
->next
= card
->next
;
3232 ASSERT(slic_global
.num_slic_cards
);
3233 slic_global
.num_slic_cards
--;
3234 slic_card_cleanup(card
);
3237 pci_release_regions(pcidev
);
3240 static int slic_entry_halt(struct net_device
*dev
)
3242 struct adapter
*adapter
= netdev_priv(dev
);
3243 struct sliccard
*card
= adapter
->card
;
3244 __iomem
struct slic_regs
*slic_regs
= adapter
->slic_regs
;
3246 spin_lock_irqsave(&slic_global
.driver_lock
.lock
,
3247 slic_global
.driver_lock
.flags
);
3249 netif_stop_queue(adapter
->netdev
);
3250 adapter
->state
= ADAPT_DOWN
;
3251 adapter
->linkstate
= LINK_DOWN
;
3252 adapter
->upr_list
= NULL
;
3253 adapter
->upr_busy
= 0;
3254 adapter
->devflags_prev
= 0;
3255 ASSERT(card
->adapter
[adapter
->cardindex
] == adapter
);
3256 slic_reg32_write(&slic_regs
->slic_icr
, ICR_INT_OFF
, FLUSH
);
3257 adapter
->all_reg_writes
++;
3258 adapter
->icr_reg_writes
++;
3259 slic_config_clear(adapter
);
3260 if (adapter
->activated
) {
3261 card
->adapters_activated
--;
3262 slic_global
.num_slic_ports_active
--;
3263 adapter
->activated
= 0;
3265 #ifdef AUTOMATIC_RESET
3266 slic_reg32_write(&slic_regs
->slic_reset_iface
, 0, FLUSH
);
3269 * Reset the adapter's cmd queues
3271 slic_cmdq_reset(adapter
);
3273 #ifdef AUTOMATIC_RESET
3274 if (!card
->adapters_activated
)
3275 slic_card_init(card
, adapter
);
3278 spin_unlock_irqrestore(&slic_global
.driver_lock
.lock
,
3279 slic_global
.driver_lock
.flags
);
3283 static struct net_device_stats
*slic_get_stats(struct net_device
*dev
)
3285 struct adapter
*adapter
= netdev_priv(dev
);
3288 dev
->stats
.collisions
= adapter
->slic_stats
.iface
.xmit_collisions
;
3289 dev
->stats
.rx_errors
= adapter
->slic_stats
.iface
.rcv_errors
;
3290 dev
->stats
.tx_errors
= adapter
->slic_stats
.iface
.xmt_errors
;
3291 dev
->stats
.rx_missed_errors
= adapter
->slic_stats
.iface
.rcv_discards
;
3292 dev
->stats
.tx_heartbeat_errors
= 0;
3293 dev
->stats
.tx_aborted_errors
= 0;
3294 dev
->stats
.tx_window_errors
= 0;
3295 dev
->stats
.tx_fifo_errors
= 0;
3296 dev
->stats
.rx_frame_errors
= 0;
3297 dev
->stats
.rx_length_errors
= 0;
3302 static int slic_ioctl(struct net_device
*dev
, struct ifreq
*rq
, int cmd
)
3304 struct adapter
*adapter
= netdev_priv(dev
);
3305 struct ethtool_cmd edata
;
3306 struct ethtool_cmd ecmd
;
3312 case SIOCSLICSETINTAGG
:
3313 if (copy_from_user(data
, rq
->ifr_data
, 28))
3316 dev_err(&dev
->dev
, "%s: set interrupt aggregation to %d\n",
3318 slic_intagg_set(adapter
, intagg
);
3321 #ifdef SLIC_TRACE_DUMP_ENABLED
3322 case SIOCSLICTRACEDUMP
:
3325 DBG_IOCTL("slic_ioctl SIOCSLIC_TRACE_DUMP\n");
3327 if (copy_from_user(data
, rq
->ifr_data
, 28)) {
3329 ("slic: copy_from_user FAILED getting initial simba param\n");
3334 if (tracemon_request
== SLIC_DUMP_DONE
) {
3336 ("ATK Diagnostic Trace Dump Requested\n");
3337 tracemon_request
= SLIC_DUMP_REQUESTED
;
3338 tracemon_request_type
= value
;
3339 tracemon_timestamp
= jiffies
;
3340 } else if ((tracemon_request
== SLIC_DUMP_REQUESTED
) ||
3341 (tracemon_request
==
3342 SLIC_DUMP_IN_PROGRESS
)) {
3344 ("ATK Diagnostic Trace Dump Requested but already in progress... ignore\n");
3347 ("ATK Diagnostic Trace Dump Requested\n");
3348 tracemon_request
= SLIC_DUMP_REQUESTED
;
3349 tracemon_request_type
= value
;
3350 tracemon_timestamp
= jiffies
;
3357 if (copy_from_user(&ecmd
, rq
->ifr_data
, sizeof(ecmd
)))
3360 if (ecmd
.cmd
== ETHTOOL_GSET
) {
3361 edata
.supported
= (SUPPORTED_10baseT_Half
|
3362 SUPPORTED_10baseT_Full
|
3363 SUPPORTED_100baseT_Half
|
3364 SUPPORTED_100baseT_Full
|
3365 SUPPORTED_Autoneg
| SUPPORTED_MII
);
3366 edata
.port
= PORT_MII
;
3367 edata
.transceiver
= XCVR_INTERNAL
;
3368 edata
.phy_address
= 0;
3369 if (adapter
->linkspeed
== LINK_100MB
)
3370 edata
.speed
= SPEED_100
;
3371 else if (adapter
->linkspeed
== LINK_10MB
)
3372 edata
.speed
= SPEED_10
;
3376 if (adapter
->linkduplex
== LINK_FULLD
)
3377 edata
.duplex
= DUPLEX_FULL
;
3379 edata
.duplex
= DUPLEX_HALF
;
3381 edata
.autoneg
= AUTONEG_ENABLE
;
3384 if (copy_to_user(rq
->ifr_data
, &edata
, sizeof(edata
)))
3387 } else if (ecmd
.cmd
== ETHTOOL_SSET
) {
3388 if (!capable(CAP_NET_ADMIN
))
3391 if (adapter
->linkspeed
== LINK_100MB
)
3392 edata
.speed
= SPEED_100
;
3393 else if (adapter
->linkspeed
== LINK_10MB
)
3394 edata
.speed
= SPEED_10
;
3398 if (adapter
->linkduplex
== LINK_FULLD
)
3399 edata
.duplex
= DUPLEX_FULL
;
3401 edata
.duplex
= DUPLEX_HALF
;
3403 edata
.autoneg
= AUTONEG_ENABLE
;
3406 if ((ecmd
.speed
!= edata
.speed
) ||
3407 (ecmd
.duplex
!= edata
.duplex
)) {
3411 if (ecmd
.speed
== SPEED_10
)
3414 speed
= PCR_SPEED_100
;
3415 if (ecmd
.duplex
== DUPLEX_FULL
)
3416 duplex
= PCR_DUPLEX_FULL
;
3419 slic_link_config(adapter
, speed
, duplex
);
3420 slic_link_event_handler(adapter
);
3429 static void slic_config_pci(struct pci_dev
*pcidev
)
3434 pci_read_config_word(pcidev
, PCI_COMMAND
, &pci_command
);
3436 new_command
= pci_command
| PCI_COMMAND_MASTER
3437 | PCI_COMMAND_MEMORY
3438 | PCI_COMMAND_INVALIDATE
3439 | PCI_COMMAND_PARITY
| PCI_COMMAND_SERR
| PCI_COMMAND_FAST_BACK
;
3440 if (pci_command
!= new_command
)
3441 pci_write_config_word(pcidev
, PCI_COMMAND
, new_command
);
3444 static int slic_card_init(struct sliccard
*card
, struct adapter
*adapter
)
3446 __iomem
struct slic_regs
*slic_regs
= adapter
->slic_regs
;
3447 struct slic_eeprom
*peeprom
;
3448 struct oslic_eeprom
*pOeeprom
;
3449 dma_addr_t phys_config
;
3453 struct slic_shmem
*pshmem
;
3455 uint macaddrs
= card
->card_size
;
3460 struct slic_config_mac
*pmac
;
3461 unsigned char fruformat
;
3462 unsigned char oemfruformat
;
3463 struct atk_fru
*patkfru
;
3464 union oemfru
*poemfru
;
3466 /* Reset everything except PCI configuration space */
3467 slic_soft_reset(adapter
);
3469 /* Download the microcode */
3470 status
= slic_card_download(adapter
);
3473 dev_err(&adapter
->pcidev
->dev
,
3474 "download failed bus %d slot %d\n",
3475 adapter
->busnumber
, adapter
->slotnumber
);
3479 if (!card
->config_set
) {
3480 peeprom
= pci_alloc_consistent(adapter
->pcidev
,
3481 sizeof(struct slic_eeprom
),
3484 phys_configl
= SLIC_GET_ADDR_LOW(phys_config
);
3485 phys_configh
= SLIC_GET_ADDR_HIGH(phys_config
);
3488 dev_err(&adapter
->pcidev
->dev
,
3489 "eeprom read failed to get memory "
3490 "bus %d slot %d\n", adapter
->busnumber
,
3491 adapter
->slotnumber
);
3494 memset(peeprom
, 0, sizeof(struct slic_eeprom
));
3496 slic_reg32_write(&slic_regs
->slic_icr
, ICR_INT_OFF
, FLUSH
);
3498 pshmem
= (struct slic_shmem
*)adapter
->phys_shmem
;
3500 spin_lock_irqsave(&adapter
->bit64reglock
.lock
,
3501 adapter
->bit64reglock
.flags
);
3502 slic_reg32_write(&slic_regs
->slic_addr_upper
, 0, DONT_FLUSH
);
3503 slic_reg32_write(&slic_regs
->slic_isp
,
3504 SLIC_GET_ADDR_LOW(&pshmem
->isr
), FLUSH
);
3505 spin_unlock_irqrestore(&adapter
->bit64reglock
.lock
,
3506 adapter
->bit64reglock
.flags
);
3508 slic_config_get(adapter
, phys_configl
, phys_configh
);
3511 if (adapter
->pshmem
->isr
) {
3512 if (adapter
->pshmem
->isr
& ISR_UPC
) {
3513 adapter
->pshmem
->isr
= 0;
3514 slic_reg64_write(adapter
,
3515 &slic_regs
->slic_isp
, 0,
3516 &slic_regs
->slic_addr_upper
,
3518 slic_reg32_write(&slic_regs
->slic_isr
,
3521 slic_upr_request_complete(adapter
, 0);
3524 adapter
->pshmem
->isr
= 0;
3525 slic_reg32_write(&slic_regs
->slic_isr
,
3532 dev_err(&adapter
->pcidev
->dev
,
3533 "%d config data fetch timed out!\n",
3535 slic_reg64_write(adapter
,
3536 &slic_regs
->slic_isp
, 0,
3537 &slic_regs
->slic_addr_upper
,
3544 switch (adapter
->devid
) {
3546 case SLIC_2GB_DEVICE_ID
:
3547 /* extract EEPROM data and pointers to EEPROM data */
3548 pOeeprom
= (struct oslic_eeprom
*) peeprom
;
3549 eecodesize
= pOeeprom
->EecodeSize
;
3550 dramsize
= pOeeprom
->DramSize
;
3551 pmac
= pOeeprom
->MacInfo
;
3552 fruformat
= pOeeprom
->FruFormat
;
3553 patkfru
= &pOeeprom
->AtkFru
;
3554 oemfruformat
= pOeeprom
->OemFruFormat
;
3555 poemfru
= &pOeeprom
->OemFru
;
3557 /* Minor kludge for Oasis card
3558 get 2 MAC addresses from the
3559 EEPROM to ensure that function 1
3560 gets the Port 1 MAC address */
3563 /* extract EEPROM data and pointers to EEPROM data */
3564 eecodesize
= peeprom
->EecodeSize
;
3565 dramsize
= peeprom
->DramSize
;
3566 pmac
= peeprom
->u2
.mac
.MacInfo
;
3567 fruformat
= peeprom
->FruFormat
;
3568 patkfru
= &peeprom
->AtkFru
;
3569 oemfruformat
= peeprom
->OemFruFormat
;
3570 poemfru
= &peeprom
->OemFru
;
3574 card
->config
.EepromValid
= false;
3576 /* see if the EEPROM is valid by checking it's checksum */
3577 if ((eecodesize
<= MAX_EECODE_SIZE
) &&
3578 (eecodesize
>= MIN_EECODE_SIZE
)) {
3581 *(u16
*) ((char *) peeprom
+ (eecodesize
- 2));
3583 calculate the EEPROM checksum
3586 ~slic_eeprom_cksum((char *) peeprom
,
3589 if the ucdoe chksum flag bit worked,
3590 we wouldn't need this shit
3592 if (ee_chksum
== calc_chksum
)
3593 card
->config
.EepromValid
= true;
3595 /* copy in the DRAM size */
3596 card
->config
.DramSize
= dramsize
;
3598 /* copy in the MAC address(es) */
3599 for (i
= 0; i
< macaddrs
; i
++) {
3600 memcpy(&card
->config
.MacInfo
[i
],
3601 &pmac
[i
], sizeof(struct slic_config_mac
));
3604 /* copy the Alacritech FRU information */
3605 card
->config
.FruFormat
= fruformat
;
3606 memcpy(&card
->config
.AtkFru
, patkfru
,
3607 sizeof(struct atk_fru
));
3609 pci_free_consistent(adapter
->pcidev
,
3610 sizeof(struct slic_eeprom
),
3611 peeprom
, phys_config
);
3613 if ((!card
->config
.EepromValid
) &&
3614 (adapter
->reg_params
.fail_on_bad_eeprom
)) {
3615 slic_reg64_write(adapter
, &slic_regs
->slic_isp
, 0,
3616 &slic_regs
->slic_addr_upper
,
3618 dev_err(&adapter
->pcidev
->dev
,
3619 "unsupported CONFIGURATION EEPROM invalid\n");
3623 card
->config_set
= 1;
3626 if (slic_card_download_gbrcv(adapter
)) {
3627 dev_err(&adapter
->pcidev
->dev
,
3628 "unable to download GB receive microcode\n");
3632 if (slic_global
.dynamic_intagg
)
3633 slic_intagg_set(adapter
, 0);
3635 slic_intagg_set(adapter
, intagg_delay
);
3638 * Initialize ping status to "ok"
3640 card
->pingstatus
= ISR_PINGMASK
;
3643 * Lastly, mark our card state as up and return success
3645 card
->state
= CARD_UP
;
3646 card
->reset_in_progress
= 0;
3651 static void slic_init_driver(void)
3653 if (slic_first_init
) {
3654 slic_first_init
= 0;
3655 spin_lock_init(&slic_global
.driver_lock
.lock
);
3660 static void slic_init_adapter(struct net_device
*netdev
,
3661 struct pci_dev
*pcidev
,
3662 const struct pci_device_id
*pci_tbl_entry
,
3663 void __iomem
*memaddr
, int chip_idx
)
3666 struct slic_handle
*pslic_handle
;
3667 struct adapter
*adapter
= netdev_priv(netdev
);
3669 /* adapter->pcidev = pcidev;*/
3670 adapter
->vendid
= pci_tbl_entry
->vendor
;
3671 adapter
->devid
= pci_tbl_entry
->device
;
3672 adapter
->subsysid
= pci_tbl_entry
->subdevice
;
3673 adapter
->busnumber
= pcidev
->bus
->number
;
3674 adapter
->slotnumber
= ((pcidev
->devfn
>> 3) & 0x1F);
3675 adapter
->functionnumber
= (pcidev
->devfn
& 0x7);
3676 adapter
->memorylength
= pci_resource_len(pcidev
, 0);
3677 adapter
->slic_regs
= (__iomem
struct slic_regs
*)memaddr
;
3678 adapter
->irq
= pcidev
->irq
;
3679 /* adapter->netdev = netdev;*/
3680 adapter
->next_netdevice
= head_netdevice
;
3681 head_netdevice
= netdev
;
3682 adapter
->chipid
= chip_idx
;
3683 adapter
->port
= 0; /*adapter->functionnumber;*/
3684 adapter
->cardindex
= adapter
->port
;
3685 adapter
->memorybase
= memaddr
;
3686 spin_lock_init(&adapter
->upr_lock
.lock
);
3687 spin_lock_init(&adapter
->bit64reglock
.lock
);
3688 spin_lock_init(&adapter
->adapter_lock
.lock
);
3689 spin_lock_init(&adapter
->reset_lock
.lock
);
3690 spin_lock_init(&adapter
->handle_lock
.lock
);
3692 adapter
->card_size
= 1;
3694 Initialize slic_handle array
3696 ASSERT(SLIC_CMDQ_MAXCMDS
<= 0xFFFF);
3698 Start with 1. 0 is an invalid host handle.
3700 for (index
= 1, pslic_handle
= &adapter
->slic_handles
[1];
3701 index
< SLIC_CMDQ_MAXCMDS
; index
++, pslic_handle
++) {
3703 pslic_handle
->token
.handle_index
= index
;
3704 pslic_handle
->type
= SLIC_HANDLE_FREE
;
3705 pslic_handle
->next
= adapter
->pfree_slic_handles
;
3706 adapter
->pfree_slic_handles
= pslic_handle
;
3708 adapter
->pshmem
= (struct slic_shmem
*)
3709 pci_alloc_consistent(adapter
->pcidev
,
3710 sizeof(struct slic_shmem
),
3713 ASSERT(adapter
->pshmem
);
3715 memset(adapter
->pshmem
, 0, sizeof(struct slic_shmem
));
3720 static const struct net_device_ops slic_netdev_ops
= {
3721 .ndo_open
= slic_entry_open
,
3722 .ndo_stop
= slic_entry_halt
,
3723 .ndo_start_xmit
= slic_xmit_start
,
3724 .ndo_do_ioctl
= slic_ioctl
,
3725 .ndo_set_mac_address
= slic_mac_set_address
,
3726 .ndo_get_stats
= slic_get_stats
,
3727 .ndo_set_multicast_list
= slic_mcast_set_list
,
3728 .ndo_validate_addr
= eth_validate_addr
,
3729 .ndo_change_mtu
= eth_change_mtu
,
3732 static u32
slic_card_locate(struct adapter
*adapter
)
3734 struct sliccard
*card
= slic_global
.slic_card
;
3735 struct physcard
*physcard
= slic_global
.phys_card
;
3737 u16 __iomem
*hostid_reg
;
3739 uint rdhostid_offset
= 0;
3741 switch (adapter
->devid
) {
3742 case SLIC_2GB_DEVICE_ID
:
3743 rdhostid_offset
= SLIC_RDHOSTID_2GB
;
3745 case SLIC_1GB_DEVICE_ID
:
3746 rdhostid_offset
= SLIC_RDHOSTID_1GB
;
3754 (u16 __iomem
*) (((u8 __iomem
*) (adapter
->slic_regs
)) +
3757 /* read the 16 bit hostid from SRAM */
3758 card_hostid
= (ushort
) readw(hostid_reg
);
3760 /* Initialize a new card structure if need be */
3761 if (card_hostid
== SLIC_HOSTID_DEFAULT
) {
3762 card
= kzalloc(sizeof(struct sliccard
), GFP_KERNEL
);
3766 card
->next
= slic_global
.slic_card
;
3767 slic_global
.slic_card
= card
;
3768 card
->busnumber
= adapter
->busnumber
;
3769 card
->slotnumber
= adapter
->slotnumber
;
3771 /* Find an available cardnum */
3772 for (i
= 0; i
< SLIC_MAX_CARDS
; i
++) {
3773 if (slic_global
.cardnuminuse
[i
] == 0) {
3774 slic_global
.cardnuminuse
[i
] = 1;
3779 slic_global
.num_slic_cards
++;
3781 slic_debug_card_create(card
);
3783 /* Card exists, find the card this adapter belongs to */
3785 if (card
->cardnum
== card_hostid
)
3794 /* Put the adapter in the card's adapter list */
3795 ASSERT(card
->adapter
[adapter
->port
] == NULL
);
3796 if (!card
->adapter
[adapter
->port
]) {
3797 card
->adapter
[adapter
->port
] = adapter
;
3798 adapter
->card
= card
;
3801 card
->card_size
= 1; /* one port per *logical* card */
3804 for (i
= 0; i
< SLIC_MAX_PORTS
; i
++) {
3805 if (!physcard
->adapter
[i
])
3810 ASSERT(i
!= SLIC_MAX_PORTS
);
3811 if (physcard
->adapter
[i
]->slotnumber
== adapter
->slotnumber
)
3813 physcard
= physcard
->next
;
3816 /* no structure allocated for this physical card yet */
3817 physcard
= kzalloc(sizeof(struct physcard
), GFP_ATOMIC
);
3820 physcard
->next
= slic_global
.phys_card
;
3821 slic_global
.phys_card
= physcard
;
3822 physcard
->adapters_allocd
= 1;
3824 physcard
->adapters_allocd
++;
3826 /* Note - this is ZERO relative */
3827 adapter
->physport
= physcard
->adapters_allocd
- 1;
3829 ASSERT(physcard
->adapter
[adapter
->physport
] == NULL
);
3830 physcard
->adapter
[adapter
->physport
] = adapter
;
3831 adapter
->physcard
= physcard
;
3836 static int __devinit
slic_entry_probe(struct pci_dev
*pcidev
,
3837 const struct pci_device_id
*pci_tbl_entry
)
3839 static int cards_found
;
3840 static int did_version
;
3842 struct net_device
*netdev
;
3843 struct adapter
*adapter
;
3844 void __iomem
*memmapped_ioaddr
= NULL
;
3846 ulong mmio_start
= 0;
3848 struct sliccard
*card
= NULL
;
3849 int pci_using_dac
= 0;
3851 slic_global
.dynamic_intagg
= dynamic_intagg
;
3853 err
= pci_enable_device(pcidev
);
3858 if (slic_debug
> 0 && did_version
++ == 0) {
3859 printk(KERN_DEBUG
"%s\n", slic_banner
);
3860 printk(KERN_DEBUG
"%s\n", slic_proc_version
);
3863 if (!pci_set_dma_mask(pcidev
, DMA_BIT_MASK(64))) {
3865 if (pci_set_consistent_dma_mask(pcidev
, DMA_BIT_MASK(64))) {
3866 dev_err(&pcidev
->dev
, "unable to obtain 64-bit DMA for "
3867 "consistent allocations\n");
3868 goto err_out_disable_pci
;
3870 } else if (pci_set_dma_mask(pcidev
, DMA_BIT_MASK(32))) {
3872 pci_set_consistent_dma_mask(pcidev
, DMA_BIT_MASK(32));
3874 dev_err(&pcidev
->dev
, "no usable DMA configuration\n");
3875 goto err_out_disable_pci
;
3878 err
= pci_request_regions(pcidev
, DRV_NAME
);
3880 dev_err(&pcidev
->dev
, "can't obtain PCI resources\n");
3881 goto err_out_disable_pci
;
3884 pci_set_master(pcidev
);
3886 netdev
= alloc_etherdev(sizeof(struct adapter
));
3889 goto err_out_exit_slic_probe
;
3892 SET_NETDEV_DEV(netdev
, &pcidev
->dev
);
3894 pci_set_drvdata(pcidev
, netdev
);
3895 adapter
= netdev_priv(netdev
);
3896 adapter
->netdev
= netdev
;
3897 adapter
->pcidev
= pcidev
;
3899 netdev
->features
|= NETIF_F_HIGHDMA
;
3901 mmio_start
= pci_resource_start(pcidev
, 0);
3902 mmio_len
= pci_resource_len(pcidev
, 0);
3905 /* memmapped_ioaddr = (u32)ioremap_nocache(mmio_start, mmio_len);*/
3906 memmapped_ioaddr
= ioremap(mmio_start
, mmio_len
);
3907 if (!memmapped_ioaddr
) {
3908 dev_err(&pcidev
->dev
, "cannot remap MMIO region %lx @ %lx\n",
3909 mmio_len
, mmio_start
);
3910 goto err_out_free_netdev
;
3913 slic_config_pci(pcidev
);
3917 slic_init_adapter(netdev
,
3918 pcidev
, pci_tbl_entry
, memmapped_ioaddr
, cards_found
);
3920 status
= slic_card_locate(adapter
);
3922 dev_err(&pcidev
->dev
, "cannot locate card\n");
3923 goto err_out_free_mmio_region
;
3926 card
= adapter
->card
;
3928 if (!adapter
->allocated
) {
3929 card
->adapters_allocated
++;
3930 adapter
->allocated
= 1;
3933 status
= slic_card_init(card
, adapter
);
3936 card
->state
= CARD_FAIL
;
3937 adapter
->state
= ADAPT_FAIL
;
3938 adapter
->linkstate
= LINK_DOWN
;
3939 dev_err(&pcidev
->dev
, "FAILED status[%x]\n", status
);
3941 slic_adapter_set_hwaddr(adapter
);
3944 netdev
->base_addr
= (unsigned long)adapter
->memorybase
;
3945 netdev
->irq
= adapter
->irq
;
3946 netdev
->netdev_ops
= &slic_netdev_ops
;
3948 slic_debug_adapter_create(adapter
);
3950 strcpy(netdev
->name
, "eth%d");
3951 err
= register_netdev(netdev
);
3953 dev_err(&pcidev
->dev
, "Cannot register net device, aborting.\n");
3962 iounmap(memmapped_ioaddr
);
3963 err_out_free_mmio_region
:
3964 release_mem_region(mmio_start
, mmio_len
);
3965 err_out_free_netdev
:
3966 free_netdev(netdev
);
3967 err_out_exit_slic_probe
:
3968 pci_release_regions(pcidev
);
3969 err_out_disable_pci
:
3970 pci_disable_device(pcidev
);
3974 static struct pci_driver slic_driver
= {
3976 .id_table
= slic_pci_tbl
,
3977 .probe
= slic_entry_probe
,
3978 .remove
= __devexit_p(slic_entry_remove
),
3981 static int __init
slic_module_init(void)
3985 if (debug
>= 0 && slic_debug
!= debug
)
3986 printk(KERN_DEBUG KBUILD_MODNAME
": debug level is %d.\n",
3991 return pci_register_driver(&slic_driver
);
3994 static void __exit
slic_module_cleanup(void)
3996 pci_unregister_driver(&slic_driver
);
3997 slic_debug_cleanup();
4000 module_init(slic_module_init
);
4001 module_exit(slic_module_cleanup
);