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_ASSERT_ENABLED 1
62 #define SLIC_INTERRUPT_PROCESS_LIMIT 1
63 #define SLIC_OFFLOAD_IP_CHECKSUM 1
64 #define STATS_TIMER_INTERVAL 2
65 #define PING_TIMER_INTERVAL 1
67 #include <linux/kernel.h>
68 #include <linux/string.h>
69 #include <linux/errno.h>
70 #include <linux/ioport.h>
71 #include <linux/slab.h>
72 #include <linux/interrupt.h>
73 #include <linux/timer.h>
74 #include <linux/pci.h>
75 #include <linux/spinlock.h>
76 #include <linux/init.h>
77 #include <linux/bitops.h>
79 #include <linux/netdevice.h>
80 #include <linux/etherdevice.h>
81 #include <linux/skbuff.h>
82 #include <linux/delay.h>
83 #include <linux/debugfs.h>
84 #include <linux/seq_file.h>
85 #include <linux/kthread.h>
86 #include <linux/module.h>
87 #include <linux/moduleparam.h>
89 #include <linux/firmware.h>
90 #include <linux/types.h>
91 #include <linux/dma-mapping.h>
92 #include <linux/mii.h>
93 #include <linux/if_vlan.h>
94 #include <asm/unaligned.h>
96 #include <linux/ethtool.h>
97 #include <linux/uaccess.h>
102 static struct net_device_stats *slic_get_stats(struct net_device *dev);
103 static int slic_entry_open(struct net_device *dev);
104 static int slic_entry_halt(struct net_device *dev);
105 static int slic_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
106 static int slic_xmit_start(struct sk_buff *skb, struct net_device *dev);
107 static void slic_xmit_fail(struct adapter *adapter, struct sk_buff *skb,
108 void *cmd, u32 skbtype, u32 status);
109 static void slic_config_pci(struct pci_dev *pcidev);
110 static struct sk_buff *slic_rcvqueue_getnext(struct adapter *adapter);
111 static int slic_mac_set_address(struct net_device *dev, void *ptr);
112 static void slic_link_event_handler(struct adapter *adapter);
113 static void slic_upr_request_complete(struct adapter *adapter, u32 isr);
114 static int slic_rspqueue_init(struct adapter *adapter);
115 static void slic_rspqueue_free(struct adapter *adapter);
116 static struct slic_rspbuf *slic_rspqueue_getnext(struct adapter *adapter);
117 static int slic_cmdq_init(struct adapter *adapter);
118 static void slic_cmdq_free(struct adapter *adapter);
119 static void slic_cmdq_reset(struct adapter *adapter);
120 static void slic_cmdq_addcmdpage(struct adapter *adapter, u32 *page);
121 static void slic_cmdq_getdone(struct adapter *adapter);
122 static void slic_cmdq_putdone_irq(struct adapter *adapter,
123 struct slic_hostcmd *cmd);
124 static struct slic_hostcmd *slic_cmdq_getfree(struct adapter *adapter);
125 static int slic_rcvqueue_init(struct adapter *adapter);
126 static int slic_rcvqueue_fill(struct adapter *adapter);
127 static u32 slic_rcvqueue_reinsert(struct adapter *adapter, struct sk_buff *skb);
128 static void slic_rcvqueue_free(struct adapter *adapter);
129 static void slic_adapter_set_hwaddr(struct adapter *adapter);
130 static int slic_card_init(struct sliccard *card, struct adapter *adapter);
131 static void slic_intagg_set(struct adapter *adapter, u32 value);
132 static int slic_card_download(struct adapter *adapter);
133 static u32 slic_card_locate(struct adapter *adapter);
134 static int slic_if_init(struct adapter *adapter);
135 static int slic_adapter_allocresources(struct adapter *adapter);
136 static void slic_adapter_freeresources(struct adapter *adapter);
137 static void slic_link_config(struct adapter *adapter, u32 linkspeed,
139 static void slic_unmap_mmio_space(struct adapter *adapter);
140 static void slic_card_cleanup(struct sliccard *card);
141 static void slic_soft_reset(struct adapter *adapter);
142 static bool slic_mac_filter(struct adapter *adapter,
143 struct ether_header *ether_frame);
144 static void slic_mac_address_config(struct adapter *adapter);
145 static void slic_mac_config(struct adapter *adapter);
146 static void slic_mcast_set_mask(struct adapter *adapter);
147 static void slic_config_set(struct adapter *adapter, bool linkchange);
148 static void slic_config_clear(struct adapter *adapter);
149 static void slic_config_get(struct adapter *adapter, u32 config,
151 static void slic_timer_load_check(ulong context);
152 static void slic_assert_fail(void);
153 static ushort slic_eeprom_cksum(char *m, int len);
154 static void slic_upr_start(struct adapter *adapter);
155 static void slic_link_upr_complete(struct adapter *adapter, u32 Isr);
156 static int slic_upr_request(struct adapter *adapter, u32 upr_request,
157 u32 upr_data, u32 upr_data_h, u32 upr_buffer,
159 static void slic_mcast_set_list(struct net_device *dev);
162 static uint slic_first_init = 1;
163 static char *slic_banner = "Alacritech SLIC Technology(tm) Server "\
164 "and Storage Accelerator (Non-Accelerated)";
166 static char *slic_proc_version = "2.0.351 2006/07/14 12:26:00";
167 static char *slic_product_name = "SLIC Technology(tm) Server "\
168 "and Storage Accelerator (Non-Accelerated)";
169 static char *slic_vendor = "Alacritech, Inc.";
171 static int slic_debug = 1;
172 static int debug = -1;
173 static struct net_device *head_netdevice;
175 static struct base_driver slic_global = { {}, 0, 0, 0, 1, NULL, NULL };
176 static int intagg_delay = 100;
177 static u32 dynamic_intagg;
178 static unsigned int rcv_count;
179 static struct dentry *slic_debugfs;
181 #define DRV_NAME "slicoss"
182 #define DRV_VERSION "2.0.1"
183 #define DRV_AUTHOR "Alacritech, Inc. Engineering"
184 #define DRV_DESCRIPTION "Alacritech SLIC Techonology(tm) "\
185 "Non-Accelerated Driver"
186 #define DRV_COPYRIGHT "Copyright 2000-2006 Alacritech, Inc. "\
187 "All rights reserved."
188 #define PFX DRV_NAME " "
190 MODULE_AUTHOR(DRV_AUTHOR);
191 MODULE_DESCRIPTION(DRV_DESCRIPTION);
192 MODULE_LICENSE("Dual BSD/GPL");
194 module_param(dynamic_intagg, int, 0);
195 MODULE_PARM_DESC(dynamic_intagg, "Dynamic Interrupt Aggregation Setting");
196 module_param(intagg_delay, int, 0);
197 MODULE_PARM_DESC(intagg_delay, "uSec Interrupt Aggregation Delay");
199 static struct pci_device_id slic_pci_tbl[] __devinitdata = {
200 {PCI_VENDOR_ID_ALACRITECH,
202 PCI_ANY_ID, PCI_ANY_ID,},
203 {PCI_VENDOR_ID_ALACRITECH,
205 PCI_ANY_ID, PCI_ANY_ID,},
209 MODULE_DEVICE_TABLE(pci, slic_pci_tbl);
211 #define SLIC_GET_SLIC_HANDLE(_adapter, _pslic_handle) \
213 spin_lock_irqsave(&_adapter->handle_lock.lock, \
214 _adapter->handle_lock.flags); \
215 _pslic_handle = _adapter->pfree_slic_handles; \
216 if (_pslic_handle) { \
217 ASSERT(_pslic_handle->type == SLIC_HANDLE_FREE); \
218 _adapter->pfree_slic_handles = _pslic_handle->next; \
220 spin_unlock_irqrestore(&_adapter->handle_lock.lock, \
221 _adapter->handle_lock.flags); \
224 #define SLIC_FREE_SLIC_HANDLE(_adapter, _pslic_handle) \
226 _pslic_handle->type = SLIC_HANDLE_FREE; \
227 spin_lock_irqsave(&_adapter->handle_lock.lock, \
228 _adapter->handle_lock.flags); \
229 _pslic_handle->next = _adapter->pfree_slic_handles; \
230 _adapter->pfree_slic_handles = _pslic_handle; \
231 spin_unlock_irqrestore(&_adapter->handle_lock.lock, \
232 _adapter->handle_lock.flags); \
235 static void slic_debug_init(void);
236 static void slic_debug_cleanup(void);
237 static void slic_debug_adapter_create(struct adapter *adapter);
238 static void slic_debug_adapter_destroy(struct adapter *adapter);
239 static void slic_debug_card_create(struct sliccard *card);
240 static void slic_debug_card_destroy(struct sliccard *card);
242 static inline void slic_reg32_write(void __iomem *reg, u32 value, bool flush)
249 static inline void slic_reg64_write(struct adapter *adapter, void __iomem *reg,
250 u32 value, void __iomem *regh, u32 paddrh,
253 spin_lock_irqsave(&adapter->bit64reglock.lock,
254 adapter->bit64reglock.flags);
255 if (paddrh != adapter->curaddrupper) {
256 adapter->curaddrupper = paddrh;
257 writel(paddrh, regh);
262 spin_unlock_irqrestore(&adapter->bit64reglock.lock,
263 adapter->bit64reglock.flags);
266 static void slic_init_driver(void)
268 if (slic_first_init) {
270 spin_lock_init(&slic_global.driver_lock.lock);
275 static void slic_init_adapter(struct net_device *netdev,
276 struct pci_dev *pcidev,
277 const struct pci_device_id *pci_tbl_entry,
278 void __iomem *memaddr, int chip_idx)
281 struct slic_handle *pslic_handle;
282 struct adapter *adapter = (struct adapter *)netdev_priv(netdev);
284 /* adapter->pcidev = pcidev;*/
285 adapter->vendid = pci_tbl_entry->vendor;
286 adapter->devid = pci_tbl_entry->device;
287 adapter->subsysid = pci_tbl_entry->subdevice;
288 adapter->busnumber = pcidev->bus->number;
289 adapter->slotnumber = ((pcidev->devfn >> 3) & 0x1F);
290 adapter->functionnumber = (pcidev->devfn & 0x7);
291 adapter->memorylength = pci_resource_len(pcidev, 0);
292 adapter->slic_regs = (__iomem struct slic_regs *)memaddr;
293 adapter->irq = pcidev->irq;
294 /* adapter->netdev = netdev;*/
295 adapter->next_netdevice = head_netdevice;
296 head_netdevice = netdev;
297 adapter->chipid = chip_idx;
298 adapter->port = 0; /*adapter->functionnumber;*/
299 adapter->cardindex = adapter->port;
300 adapter->memorybase = memaddr;
301 spin_lock_init(&adapter->upr_lock.lock);
302 spin_lock_init(&adapter->bit64reglock.lock);
303 spin_lock_init(&adapter->adapter_lock.lock);
304 spin_lock_init(&adapter->reset_lock.lock);
305 spin_lock_init(&adapter->handle_lock.lock);
307 adapter->card_size = 1;
309 Initialize slic_handle array
311 ASSERT(SLIC_CMDQ_MAXCMDS <= 0xFFFF);
313 Start with 1. 0 is an invalid host handle.
315 for (index = 1, pslic_handle = &adapter->slic_handles[1];
316 index < SLIC_CMDQ_MAXCMDS; index++, pslic_handle++) {
318 pslic_handle->token.handle_index = index;
319 pslic_handle->type = SLIC_HANDLE_FREE;
320 pslic_handle->next = adapter->pfree_slic_handles;
321 adapter->pfree_slic_handles = pslic_handle;
323 adapter->pshmem = (struct slic_shmem *)
324 pci_alloc_consistent(adapter->pcidev,
325 sizeof(struct slic_shmem),
328 ASSERT(adapter->pshmem);
330 memset(adapter->pshmem, 0, sizeof(struct slic_shmem));
335 static int __devinit slic_entry_probe(struct pci_dev *pcidev,
336 const struct pci_device_id *pci_tbl_entry)
338 static int cards_found;
339 static int did_version;
341 struct net_device *netdev;
342 struct adapter *adapter;
343 void __iomem *memmapped_ioaddr = NULL;
345 ulong mmio_start = 0;
347 struct sliccard *card = NULL;
349 slic_global.dynamic_intagg = dynamic_intagg;
351 err = pci_enable_device(pcidev);
356 if (slic_debug > 0 && did_version++ == 0) {
357 printk(KERN_DEBUG "%s\n", slic_banner);
358 printk(KERN_DEBUG "%s\n", slic_proc_version);
361 err = pci_set_dma_mask(pcidev, DMA_64BIT_MASK);
363 err = pci_set_dma_mask(pcidev, DMA_32BIT_MASK);
365 goto err_out_disable_pci;
368 err = pci_request_regions(pcidev, DRV_NAME);
370 goto err_out_disable_pci;
372 pci_set_master(pcidev);
374 netdev = alloc_etherdev(sizeof(struct adapter));
377 goto err_out_exit_slic_probe;
380 SET_NETDEV_DEV(netdev, &pcidev->dev);
382 pci_set_drvdata(pcidev, netdev);
383 adapter = netdev_priv(netdev);
384 adapter->netdev = netdev;
385 adapter->pcidev = pcidev;
387 mmio_start = pci_resource_start(pcidev, 0);
388 mmio_len = pci_resource_len(pcidev, 0);
391 /* memmapped_ioaddr = (u32)ioremap_nocache(mmio_start, mmio_len);*/
392 memmapped_ioaddr = ioremap(mmio_start, mmio_len);
393 if (!memmapped_ioaddr) {
394 DBG_ERROR("%s cannot remap MMIO region %lx @ %lx\n",
395 __func__, mmio_len, mmio_start);
396 goto err_out_free_netdev;
399 slic_config_pci(pcidev);
403 slic_init_adapter(netdev,
404 pcidev, pci_tbl_entry, memmapped_ioaddr, cards_found);
406 status = slic_card_locate(adapter);
408 DBG_ERROR("%s cannot locate card\n", __func__);
409 goto err_out_free_mmio_region;
412 card = adapter->card;
414 if (!adapter->allocated) {
415 card->adapters_allocated++;
416 adapter->allocated = 1;
419 status = slic_card_init(card, adapter);
421 if (status != STATUS_SUCCESS) {
422 card->state = CARD_FAIL;
423 adapter->state = ADAPT_FAIL;
424 adapter->linkstate = LINK_DOWN;
425 DBG_ERROR("slic_card_init FAILED status[%x]\n", status);
427 slic_adapter_set_hwaddr(adapter);
430 netdev->base_addr = (unsigned long)adapter->memorybase;
431 netdev->irq = adapter->irq;
432 netdev->open = slic_entry_open;
433 netdev->stop = slic_entry_halt;
434 netdev->hard_start_xmit = slic_xmit_start;
435 netdev->do_ioctl = slic_ioctl;
436 netdev->set_mac_address = slic_mac_set_address;
437 netdev->get_stats = slic_get_stats;
438 netdev->set_multicast_list = slic_mcast_set_list;
440 slic_debug_adapter_create(adapter);
442 strcpy(netdev->name, "eth%d");
443 err = register_netdev(netdev);
445 DBG_ERROR("Cannot register net device, aborting.\n");
454 iounmap(memmapped_ioaddr);
455 err_out_free_mmio_region:
456 release_mem_region(mmio_start, mmio_len);
459 err_out_exit_slic_probe:
460 pci_release_regions(pcidev);
461 DBG_ERROR("%s EXIT jiffies[%lx] cpu %d\n", __func__, jiffies,
464 pci_disable_device(pcidev);
468 static int slic_entry_open(struct net_device *dev)
470 struct adapter *adapter = (struct adapter *) netdev_priv(dev);
471 struct sliccard *card = adapter->card;
478 netif_stop_queue(adapter->netdev);
480 spin_lock_irqsave(&slic_global.driver_lock.lock,
481 slic_global.driver_lock.flags);
483 if (!adapter->activated) {
484 card->adapters_activated++;
485 slic_global.num_slic_ports_active++;
486 adapter->activated = 1;
488 status = slic_if_init(adapter);
490 if (status != STATUS_SUCCESS) {
491 if (adapter->activated) {
492 card->adapters_activated--;
493 slic_global.num_slic_ports_active--;
494 adapter->activated = 0;
497 spin_unlock_irqrestore(&slic_global.driver_lock.lock,
498 slic_global.driver_lock.flags);
504 card->master = adapter;
507 spin_unlock_irqrestore(&slic_global.driver_lock.lock,
508 slic_global.driver_lock.flags);
512 return STATUS_SUCCESS;
515 static void __devexit slic_entry_remove(struct pci_dev *pcidev)
517 struct net_device *dev = pci_get_drvdata(pcidev);
520 struct adapter *adapter = (struct adapter *) netdev_priv(dev);
521 struct sliccard *card;
522 struct mcast_address *mcaddr, *mlist;
525 slic_adapter_freeresources(adapter);
526 slic_unmap_mmio_space(adapter);
527 unregister_netdev(dev);
529 mmio_start = pci_resource_start(pcidev, 0);
530 mmio_len = pci_resource_len(pcidev, 0);
532 release_mem_region(mmio_start, mmio_len);
534 iounmap((void __iomem *)dev->base_addr);
535 /* free multicast addresses */
536 mlist = adapter->mcastaddrs;
542 ASSERT(adapter->card);
543 card = adapter->card;
544 ASSERT(card->adapters_allocated);
545 card->adapters_allocated--;
546 adapter->allocated = 0;
547 if (!card->adapters_allocated) {
548 struct sliccard *curr_card = slic_global.slic_card;
549 if (curr_card == card) {
550 slic_global.slic_card = card->next;
552 while (curr_card->next != card)
553 curr_card = curr_card->next;
555 curr_card->next = card->next;
557 ASSERT(slic_global.num_slic_cards);
558 slic_global.num_slic_cards--;
559 slic_card_cleanup(card);
562 pci_release_regions(pcidev);
565 static int slic_entry_halt(struct net_device *dev)
567 struct adapter *adapter = (struct adapter *)netdev_priv(dev);
568 struct sliccard *card = adapter->card;
569 __iomem struct slic_regs *slic_regs = adapter->slic_regs;
571 spin_lock_irqsave(&slic_global.driver_lock.lock,
572 slic_global.driver_lock.flags);
574 netif_stop_queue(adapter->netdev);
575 adapter->state = ADAPT_DOWN;
576 adapter->linkstate = LINK_DOWN;
577 adapter->upr_list = NULL;
578 adapter->upr_busy = 0;
579 adapter->devflags_prev = 0;
580 ASSERT(card->adapter[adapter->cardindex] == adapter);
581 slic_reg32_write(&slic_regs->slic_icr, ICR_INT_OFF, FLUSH);
582 adapter->all_reg_writes++;
583 adapter->icr_reg_writes++;
584 slic_config_clear(adapter);
585 if (adapter->activated) {
586 card->adapters_activated--;
587 slic_global.num_slic_ports_active--;
588 adapter->activated = 0;
590 #ifdef AUTOMATIC_RESET
591 slic_reg32_write(&slic_regs->slic_reset_iface, 0, FLUSH);
594 * Reset the adapter's cmd queues
596 slic_cmdq_reset(adapter);
598 #ifdef AUTOMATIC_RESET
599 if (!card->adapters_activated)
600 slic_card_init(card, adapter);
603 spin_unlock_irqrestore(&slic_global.driver_lock.lock,
604 slic_global.driver_lock.flags);
605 return STATUS_SUCCESS;
608 static int slic_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
610 struct adapter *adapter = (struct adapter *)netdev_priv(dev);
611 struct ethtool_cmd edata;
612 struct ethtool_cmd ecmd;
618 case SIOCSLICSETINTAGG:
619 if (copy_from_user(data, rq->ifr_data, 28))
622 printk(KERN_EMERG "%s: set interrupt aggregation to %d\n",
624 slic_intagg_set(adapter, intagg);
627 #ifdef SLIC_TRACE_DUMP_ENABLED
628 case SIOCSLICTRACEDUMP:
631 DBG_IOCTL("slic_ioctl SIOCSLIC_TRACE_DUMP\n");
633 if (copy_from_user(data, rq->ifr_data, 28)) {
635 ("slic: copy_from_user FAILED getting \
636 initial simba param\n");
641 if (tracemon_request == SLIC_DUMP_DONE) {
643 ("ATK Diagnostic Trace Dump Requested\n");
644 tracemon_request = SLIC_DUMP_REQUESTED;
645 tracemon_request_type = value;
646 tracemon_timestamp = jiffies;
647 } else if ((tracemon_request == SLIC_DUMP_REQUESTED) ||
649 SLIC_DUMP_IN_PROGRESS)) {
651 ("ATK Diagnostic Trace Dump Requested but \
652 already in progress... ignore\n");
655 ("ATK Diagnostic Trace Dump Requested\n");
656 tracemon_request = SLIC_DUMP_REQUESTED;
657 tracemon_request_type = value;
658 tracemon_timestamp = jiffies;
665 if (copy_from_user(&ecmd, rq->ifr_data, sizeof(ecmd)))
668 if (ecmd.cmd == ETHTOOL_GSET) {
669 edata.supported = (SUPPORTED_10baseT_Half |
670 SUPPORTED_10baseT_Full |
671 SUPPORTED_100baseT_Half |
672 SUPPORTED_100baseT_Full |
673 SUPPORTED_Autoneg | SUPPORTED_MII);
674 edata.port = PORT_MII;
675 edata.transceiver = XCVR_INTERNAL;
676 edata.phy_address = 0;
677 if (adapter->linkspeed == LINK_100MB)
678 edata.speed = SPEED_100;
679 else if (adapter->linkspeed == LINK_10MB)
680 edata.speed = SPEED_10;
684 if (adapter->linkduplex == LINK_FULLD)
685 edata.duplex = DUPLEX_FULL;
687 edata.duplex = DUPLEX_HALF;
689 edata.autoneg = AUTONEG_ENABLE;
692 if (copy_to_user(rq->ifr_data, &edata, sizeof(edata)))
695 } else if (ecmd.cmd == ETHTOOL_SSET) {
696 if (!capable(CAP_NET_ADMIN))
699 if (adapter->linkspeed == LINK_100MB)
700 edata.speed = SPEED_100;
701 else if (adapter->linkspeed == LINK_10MB)
702 edata.speed = SPEED_10;
706 if (adapter->linkduplex == LINK_FULLD)
707 edata.duplex = DUPLEX_FULL;
709 edata.duplex = DUPLEX_HALF;
711 edata.autoneg = AUTONEG_ENABLE;
714 if ((ecmd.speed != edata.speed) ||
715 (ecmd.duplex != edata.duplex)) {
719 if (ecmd.speed == SPEED_10)
722 speed = PCR_SPEED_100;
723 if (ecmd.duplex == DUPLEX_FULL)
724 duplex = PCR_DUPLEX_FULL;
727 slic_link_config(adapter, speed, duplex);
728 slic_link_event_handler(adapter);
737 #define XMIT_FAIL_LINK_STATE 1
738 #define XMIT_FAIL_ZERO_LENGTH 2
739 #define XMIT_FAIL_HOSTCMD_FAIL 3
741 static void slic_xmit_build_request(struct adapter *adapter,
742 struct slic_hostcmd *hcmd, struct sk_buff *skb)
744 struct slic_host64_cmd *ihcmd;
747 ihcmd = &hcmd->cmd64;
749 ihcmd->flags = (adapter->port << IHFLG_IFSHFT);
750 ihcmd->command = IHCMD_XMT_REQ;
751 ihcmd->u.slic_buffers.totlen = skb->len;
752 phys_addr = pci_map_single(adapter->pcidev, skb->data, skb->len,
754 ihcmd->u.slic_buffers.bufs[0].paddrl = SLIC_GET_ADDR_LOW(phys_addr);
755 ihcmd->u.slic_buffers.bufs[0].paddrh = SLIC_GET_ADDR_HIGH(phys_addr);
756 ihcmd->u.slic_buffers.bufs[0].length = skb->len;
757 #if defined(CONFIG_X86_64)
758 hcmd->cmdsize = (u32) ((((u64)&ihcmd->u.slic_buffers.bufs[1] -
759 (u64) hcmd) + 31) >> 5);
760 #elif defined(CONFIG_X86)
761 hcmd->cmdsize = ((((u32) &ihcmd->u.slic_buffers.bufs[1] -
762 (u32) hcmd) + 31) >> 5);
768 #define NORMAL_ETHFRAME 0
770 static int slic_xmit_start(struct sk_buff *skb, struct net_device *dev)
772 struct sliccard *card;
773 struct adapter *adapter = (struct adapter *)netdev_priv(dev);
774 struct slic_hostcmd *hcmd = NULL;
776 u32 skbtype = NORMAL_ETHFRAME;
777 void *offloadcmd = NULL;
779 card = adapter->card;
782 DBG_ERROR("xmit_start (%s) ENTER skb[%p] len[%d] linkstate[%x] state[%x]\n",
783 adapter->netdev->name, skb, skb->len, adapter->linkstate,
786 if ((adapter->linkstate != LINK_UP) ||
787 (adapter->state != ADAPT_UP) || (card->state != CARD_UP)) {
788 status = XMIT_FAIL_LINK_STATE;
791 } else if (skb->len == 0) {
792 status = XMIT_FAIL_ZERO_LENGTH;
796 if (skbtype == NORMAL_ETHFRAME) {
797 hcmd = slic_cmdq_getfree(adapter);
799 adapter->xmitq_full = 1;
800 status = XMIT_FAIL_HOSTCMD_FAIL;
803 ASSERT(hcmd->pslic_handle);
804 ASSERT(hcmd->cmd64.hosthandle ==
805 hcmd->pslic_handle->token.handle_token);
808 hcmd->type = SLIC_CMD_DUMB;
809 if (skbtype == NORMAL_ETHFRAME)
810 slic_xmit_build_request(adapter, hcmd, skb);
812 adapter->stats.tx_packets++;
813 adapter->stats.tx_bytes += skb->len;
816 if (adapter->kill_card) {
817 struct slic_host64_cmd ihcmd;
819 ihcmd = &hcmd->cmd64;
821 ihcmd->flags |= 0x40;
822 adapter->kill_card = 0; /* only do this once */
825 if (hcmd->paddrh == 0) {
826 slic_reg32_write(&adapter->slic_regs->slic_cbar,
827 (hcmd->paddrl | hcmd->cmdsize), DONT_FLUSH);
829 slic_reg64_write(adapter, &adapter->slic_regs->slic_cbar64,
830 (hcmd->paddrl | hcmd->cmdsize),
831 &adapter->slic_regs->slic_addr_upper,
832 hcmd->paddrh, DONT_FLUSH);
837 slic_xmit_fail(adapter, skb, offloadcmd, skbtype, status);
841 static void slic_xmit_fail(struct adapter *adapter,
843 void *cmd, u32 skbtype, u32 status)
845 if (adapter->xmitq_full)
846 netif_stop_queue(adapter->netdev);
847 if ((cmd == NULL) && (status <= XMIT_FAIL_HOSTCMD_FAIL)) {
849 case XMIT_FAIL_LINK_STATE:
851 ("(%s) reject xmit skb[%p: %x] linkstate[%s] \
852 adapter[%s:%d] card[%s:%d]\n",
853 adapter->netdev->name, skb, skb->pkt_type,
854 SLIC_LINKSTATE(adapter->linkstate),
855 SLIC_ADAPTER_STATE(adapter->state), adapter->state,
856 SLIC_CARD_STATE(adapter->card->state),
857 adapter->card->state);
859 case XMIT_FAIL_ZERO_LENGTH:
861 ("xmit_start skb->len == 0 skb[%p] type[%x]!!!! \n",
864 case XMIT_FAIL_HOSTCMD_FAIL:
866 ("xmit_start skb[%p] type[%x] No host commands \
875 adapter->stats.tx_dropped++;
878 static void slic_rcv_handle_error(struct adapter *adapter,
879 struct slic_rcvbuf *rcvbuf)
881 struct slic_hddr_wds *hdr = (struct slic_hddr_wds *)rcvbuf->data;
883 if (adapter->devid != SLIC_1GB_DEVICE_ID) {
884 if (hdr->frame_status14 & VRHSTAT_802OE)
885 adapter->if_events.oflow802++;
886 if (hdr->frame_status14 & VRHSTAT_TPOFLO)
887 adapter->if_events.Tprtoflow++;
888 if (hdr->frame_status_b14 & VRHSTATB_802UE)
889 adapter->if_events.uflow802++;
890 if (hdr->frame_status_b14 & VRHSTATB_RCVE) {
891 adapter->if_events.rcvearly++;
892 adapter->stats.rx_fifo_errors++;
894 if (hdr->frame_status_b14 & VRHSTATB_BUFF) {
895 adapter->if_events.Bufov++;
896 adapter->stats.rx_over_errors++;
898 if (hdr->frame_status_b14 & VRHSTATB_CARRE) {
899 adapter->if_events.Carre++;
900 adapter->stats.tx_carrier_errors++;
902 if (hdr->frame_status_b14 & VRHSTATB_LONGE)
903 adapter->if_events.Longe++;
904 if (hdr->frame_status_b14 & VRHSTATB_PREA)
905 adapter->if_events.Invp++;
906 if (hdr->frame_status_b14 & VRHSTATB_CRC) {
907 adapter->if_events.Crc++;
908 adapter->stats.rx_crc_errors++;
910 if (hdr->frame_status_b14 & VRHSTATB_DRBL)
911 adapter->if_events.Drbl++;
912 if (hdr->frame_status_b14 & VRHSTATB_CODE)
913 adapter->if_events.Code++;
914 if (hdr->frame_status_b14 & VRHSTATB_TPCSUM)
915 adapter->if_events.TpCsum++;
916 if (hdr->frame_status_b14 & VRHSTATB_TPHLEN)
917 adapter->if_events.TpHlen++;
918 if (hdr->frame_status_b14 & VRHSTATB_IPCSUM)
919 adapter->if_events.IpCsum++;
920 if (hdr->frame_status_b14 & VRHSTATB_IPLERR)
921 adapter->if_events.IpLen++;
922 if (hdr->frame_status_b14 & VRHSTATB_IPHERR)
923 adapter->if_events.IpHlen++;
925 if (hdr->frame_statusGB & VGBSTAT_XPERR) {
926 u32 xerr = hdr->frame_statusGB >> VGBSTAT_XERRSHFT;
928 if (xerr == VGBSTAT_XCSERR)
929 adapter->if_events.TpCsum++;
930 if (xerr == VGBSTAT_XUFLOW)
931 adapter->if_events.Tprtoflow++;
932 if (xerr == VGBSTAT_XHLEN)
933 adapter->if_events.TpHlen++;
935 if (hdr->frame_statusGB & VGBSTAT_NETERR) {
938 frame_statusGB >> VGBSTAT_NERRSHFT) &
940 if (nerr == VGBSTAT_NCSERR)
941 adapter->if_events.IpCsum++;
942 if (nerr == VGBSTAT_NUFLOW)
943 adapter->if_events.IpLen++;
944 if (nerr == VGBSTAT_NHLEN)
945 adapter->if_events.IpHlen++;
947 if (hdr->frame_statusGB & VGBSTAT_LNKERR) {
948 u32 lerr = hdr->frame_statusGB & VGBSTAT_LERRMSK;
950 if (lerr == VGBSTAT_LDEARLY)
951 adapter->if_events.rcvearly++;
952 if (lerr == VGBSTAT_LBOFLO)
953 adapter->if_events.Bufov++;
954 if (lerr == VGBSTAT_LCODERR)
955 adapter->if_events.Code++;
956 if (lerr == VGBSTAT_LDBLNBL)
957 adapter->if_events.Drbl++;
958 if (lerr == VGBSTAT_LCRCERR)
959 adapter->if_events.Crc++;
960 if (lerr == VGBSTAT_LOFLO)
961 adapter->if_events.oflow802++;
962 if (lerr == VGBSTAT_LUFLO)
963 adapter->if_events.uflow802++;
969 #define TCP_OFFLOAD_FRAME_PUSHFLAG 0x10000000
970 #define M_FAST_PATH 0x0040
972 static void slic_rcv_handler(struct adapter *adapter)
975 struct slic_rcvbuf *rcvbuf;
978 while ((skb = slic_rcvqueue_getnext(adapter))) {
982 rcvbuf = (struct slic_rcvbuf *)skb->head;
983 adapter->card->events++;
984 if (rcvbuf->status & IRHDDR_ERR) {
985 adapter->rx_errors++;
986 slic_rcv_handle_error(adapter, rcvbuf);
987 slic_rcvqueue_reinsert(adapter, skb);
991 if (!slic_mac_filter(adapter, (struct ether_header *)
993 slic_rcvqueue_reinsert(adapter, skb);
996 skb_pull(skb, SLIC_RCVBUF_HEADSIZE);
997 rx_bytes = (rcvbuf->length & IRHDDR_FLEN_MSK);
998 skb_put(skb, rx_bytes);
999 adapter->stats.rx_packets++;
1000 adapter->stats.rx_bytes += rx_bytes;
1001 #if SLIC_OFFLOAD_IP_CHECKSUM
1002 skb->ip_summed = CHECKSUM_UNNECESSARY;
1005 skb->dev = adapter->netdev;
1006 skb->protocol = eth_type_trans(skb, skb->dev);
1010 #if SLIC_INTERRUPT_PROCESS_LIMIT
1011 if (frames >= SLIC_RCVQ_MAX_PROCESS_ISR) {
1012 adapter->rcv_interrupt_yields++;
1017 adapter->max_isr_rcvs = max(adapter->max_isr_rcvs, frames);
1020 static void slic_xmit_complete(struct adapter *adapter)
1022 struct slic_hostcmd *hcmd;
1023 struct slic_rspbuf *rspbuf;
1025 struct slic_handle_word slic_handle_word;
1028 rspbuf = slic_rspqueue_getnext(adapter);
1031 adapter->xmit_completes++;
1032 adapter->card->events++;
1034 Get the complete host command buffer
1036 slic_handle_word.handle_token = rspbuf->hosthandle;
1037 ASSERT(slic_handle_word.handle_index);
1038 ASSERT(slic_handle_word.handle_index <= SLIC_CMDQ_MAXCMDS);
1040 (struct slic_hostcmd *)
1041 adapter->slic_handles[slic_handle_word.handle_index].
1043 /* hcmd = (struct slic_hostcmd *) rspbuf->hosthandle; */
1045 ASSERT(hcmd->pslic_handle ==
1046 &adapter->slic_handles[slic_handle_word.handle_index]);
1048 DBG_ERROR("xmit_complete (%s) hcmd[%p] hosthandle[%x]\n",
1049 adapter->netdev->name, hcmd, hcmd->cmd64.hosthandle);
1050 DBG_ERROR(" skb[%p] len %d hcmdtype[%x]\n", hcmd->skb,
1051 hcmd->skb->len, hcmd->type);
1053 if (hcmd->type == SLIC_CMD_DUMB) {
1055 dev_kfree_skb_irq(hcmd->skb);
1056 slic_cmdq_putdone_irq(adapter, hcmd);
1059 rspbuf->hosthandle = 0;
1062 adapter->max_isr_xmits = max(adapter->max_isr_xmits, frames);
1065 static irqreturn_t slic_interrupt(int irq, void *dev_id)
1067 struct net_device *dev = (struct net_device *)dev_id;
1068 struct adapter *adapter = (struct adapter *)netdev_priv(dev);
1071 if ((adapter->pshmem) && (adapter->pshmem->isr)) {
1072 slic_reg32_write(&adapter->slic_regs->slic_icr,
1073 ICR_INT_MASK, FLUSH);
1074 isr = adapter->isrcopy = adapter->pshmem->isr;
1075 adapter->pshmem->isr = 0;
1076 adapter->num_isrs++;
1077 switch (adapter->card->state) {
1079 if (isr & ~ISR_IO) {
1080 if (isr & ISR_ERR) {
1081 adapter->error_interrupts++;
1082 if (isr & ISR_RMISS) {
1087 struct slic_rcvqueue *rcvq =
1091 error_rmiss_interrupts++;
1093 rcv_count = rcvq->count;
1094 pre_count = rcvq->count;
1095 errors = rcvq->errors;
1097 while (rcvq->count <
1098 SLIC_RCVQ_FILLTHRESH) {
1105 } else if (isr & ISR_XDROP) {
1107 ("isr & ISR_ERR [%x] \
1112 ("isr & ISR_ERR [%x]\n",
1117 if (isr & ISR_LEVENT) {
1118 adapter->linkevent_interrupts++;
1119 slic_link_event_handler(adapter);
1122 if ((isr & ISR_UPC) ||
1123 (isr & ISR_UPCERR) || (isr & ISR_UPCBSY)) {
1124 adapter->upr_interrupts++;
1125 slic_upr_request_complete(adapter, isr);
1129 if (isr & ISR_RCV) {
1130 adapter->rcv_interrupts++;
1131 slic_rcv_handler(adapter);
1134 if (isr & ISR_CMD) {
1135 adapter->xmit_interrupts++;
1136 slic_xmit_complete(adapter);
1141 if ((isr & ISR_UPC) ||
1142 (isr & ISR_UPCERR) || (isr & ISR_UPCBSY)) {
1143 adapter->upr_interrupts++;
1144 slic_upr_request_complete(adapter, isr);
1152 adapter->isrcopy = 0;
1153 adapter->all_reg_writes += 2;
1154 adapter->isr_reg_writes++;
1155 slic_reg32_write(&adapter->slic_regs->slic_isr, 0, FLUSH);
1157 adapter->false_interrupts++;
1163 * slic_link_event_handler -
1165 * Initiate a link configuration sequence. The link configuration begins
1166 * by issuing a READ_LINK_STATUS command to the Utility Processor on the
1167 * SLIC. Since the command finishes asynchronously, the slic_upr_comlete
1168 * routine will follow it up witha UP configuration write command, which
1169 * will also complete asynchronously.
1172 static void slic_link_event_handler(struct adapter *adapter)
1175 struct slic_shmem *pshmem;
1177 if (adapter->state != ADAPT_UP) {
1178 /* Adapter is not operational. Ignore. */
1182 pshmem = (struct slic_shmem *)adapter->phys_shmem;
1184 #if defined(CONFIG_X86_64)
1185 status = slic_upr_request(adapter,
1187 SLIC_GET_ADDR_LOW(&pshmem->linkstatus),
1188 SLIC_GET_ADDR_HIGH(&pshmem->linkstatus),
1190 #elif defined(CONFIG_X86)
1191 status = slic_upr_request(adapter, SLIC_UPR_RLSR,
1192 (u32) &pshmem->linkstatus, /* no 4GB wrap guaranteed */
1197 ASSERT((status == STATUS_SUCCESS) || (status == STATUS_PENDING));
1200 static void slic_init_cleanup(struct adapter *adapter)
1202 if (adapter->intrregistered) {
1203 adapter->intrregistered = 0;
1204 free_irq(adapter->netdev->irq, adapter->netdev);
1207 if (adapter->pshmem) {
1208 pci_free_consistent(adapter->pcidev,
1209 sizeof(struct slic_shmem),
1210 adapter->pshmem, adapter->phys_shmem);
1211 adapter->pshmem = NULL;
1212 adapter->phys_shmem = (dma_addr_t) NULL;
1215 if (adapter->pingtimerset) {
1216 adapter->pingtimerset = 0;
1217 del_timer(&adapter->pingtimer);
1220 slic_rspqueue_free(adapter);
1221 slic_cmdq_free(adapter);
1222 slic_rcvqueue_free(adapter);
1225 static struct net_device_stats *slic_get_stats(struct net_device *dev)
1227 struct adapter *adapter = (struct adapter *)netdev_priv(dev);
1228 struct net_device_stats *stats;
1231 stats = &adapter->stats;
1232 stats->collisions = adapter->slic_stats.iface.xmit_collisions;
1233 stats->rx_errors = adapter->slic_stats.iface.rcv_errors;
1234 stats->tx_errors = adapter->slic_stats.iface.xmt_errors;
1235 stats->rx_missed_errors = adapter->slic_stats.iface.rcv_discards;
1236 stats->tx_heartbeat_errors = 0;
1237 stats->tx_aborted_errors = 0;
1238 stats->tx_window_errors = 0;
1239 stats->tx_fifo_errors = 0;
1240 stats->rx_frame_errors = 0;
1241 stats->rx_length_errors = 0;
1242 return &adapter->stats;
1246 * Allocate a mcast_address structure to hold the multicast address.
1249 static int slic_mcast_add_list(struct adapter *adapter, char *address)
1251 struct mcast_address *mcaddr, *mlist;
1254 /* Check to see if it already exists */
1255 mlist = adapter->mcastaddrs;
1257 ETHER_EQ_ADDR(mlist->address, address, equaladdr);
1259 return STATUS_SUCCESS;
1260 mlist = mlist->next;
1263 /* Doesn't already exist. Allocate a structure to hold it */
1264 mcaddr = kmalloc(sizeof(struct mcast_address), GFP_KERNEL);
1268 memcpy(mcaddr->address, address, 6);
1270 mcaddr->next = adapter->mcastaddrs;
1271 adapter->mcastaddrs = mcaddr;
1273 return STATUS_SUCCESS;
1277 * Functions to obtain the CRC corresponding to the destination mac address.
1278 * This is a standard ethernet CRC in that it is a 32-bit, reflected CRC using
1280 * x^32 + x^26 + x^23 + x^22 + x^16 + x^12 + x^11 + x^10 + x^8 + x^7 + x^5 +
1283 * After the CRC for the 6 bytes is generated (but before the value is
1285 * we must then transpose the value and return bits 30-23.
1288 static u32 slic_crc_table[256]; /* Table of CRCs for all possible byte values */
1289 static u32 slic_crc_init; /* Is table initialized */
1292 * Contruct the CRC32 table
1294 static void slic_mcast_init_crc32(void)
1296 u32 c; /* CRC shit reg */
1297 u32 e = 0; /* Poly X-or pattern */
1298 int i; /* counter */
1299 int k; /* byte being shifted into crc */
1301 static int p[] = { 0, 1, 2, 4, 5, 7, 8, 10, 11, 12, 16, 22, 23, 26 };
1303 for (i = 0; i < sizeof(p) / sizeof(int); i++)
1304 e |= 1L << (31 - p[i]);
1306 for (i = 1; i < 256; i++) {
1309 c = c & 1 ? (c >> 1) ^ e : c >> 1;
1310 slic_crc_table[i] = c;
1315 * Return the MAC hast as described above.
1317 static unsigned char slic_mcast_get_mac_hash(char *macaddr)
1322 unsigned char machash = 0;
1324 if (!slic_crc_init) {
1325 slic_mcast_init_crc32();
1329 crc = 0xFFFFFFFF; /* Preload shift register, per crc-32 spec */
1330 for (i = 0, p = macaddr; i < 6; ++p, ++i)
1331 crc = (crc >> 8) ^ slic_crc_table[(crc ^ *p) & 0xFF];
1333 /* Return bits 1-8, transposed */
1334 for (i = 1; i < 9; i++)
1335 machash |= (((crc >> i) & 1) << (8 - i));
1340 static void slic_mcast_set_bit(struct adapter *adapter, char *address)
1342 unsigned char crcpoly;
1344 /* Get the CRC polynomial for the mac address */
1345 crcpoly = slic_mcast_get_mac_hash(address);
1347 /* We only have space on the SLIC for 64 entries. Lop
1348 * off the top two bits. (2^6 = 64)
1352 /* OR in the new bit into our 64 bit mask. */
1353 adapter->mcastmask |= (u64) 1 << crcpoly;
1356 static void slic_mcast_set_list(struct net_device *dev)
1358 struct adapter *adapter = (struct adapter *)netdev_priv(dev);
1359 int status = STATUS_SUCCESS;
1362 struct dev_mc_list *mc_list = dev->mc_list;
1363 int mc_count = dev->mc_count;
1367 for (i = 1; i <= mc_count; i++) {
1368 addresses = (char *) &mc_list->dmi_addr;
1369 if (mc_list->dmi_addrlen == 6) {
1370 status = slic_mcast_add_list(adapter, addresses);
1371 if (status != STATUS_SUCCESS)
1377 slic_mcast_set_bit(adapter, addresses);
1378 mc_list = mc_list->next;
1381 if (adapter->devflags_prev != dev->flags) {
1382 adapter->macopts = MAC_DIRECTED;
1384 if (dev->flags & IFF_BROADCAST)
1385 adapter->macopts |= MAC_BCAST;
1386 if (dev->flags & IFF_PROMISC)
1387 adapter->macopts |= MAC_PROMISC;
1388 if (dev->flags & IFF_ALLMULTI)
1389 adapter->macopts |= MAC_ALLMCAST;
1390 if (dev->flags & IFF_MULTICAST)
1391 adapter->macopts |= MAC_MCAST;
1393 adapter->devflags_prev = dev->flags;
1394 slic_config_set(adapter, true);
1396 if (status == STATUS_SUCCESS)
1397 slic_mcast_set_mask(adapter);
1402 static void slic_mcast_set_mask(struct adapter *adapter)
1404 __iomem struct slic_regs *slic_regs = adapter->slic_regs;
1406 if (adapter->macopts & (MAC_ALLMCAST | MAC_PROMISC)) {
1407 /* Turn on all multicast addresses. We have to do this for
1408 * promiscuous mode as well as ALLMCAST mode. It saves the
1409 * Microcode from having to keep state about the MAC
1412 slic_reg32_write(&slic_regs->slic_mcastlow, 0xFFFFFFFF, FLUSH);
1413 slic_reg32_write(&slic_regs->slic_mcasthigh, 0xFFFFFFFF,
1416 /* Commit our multicast mast to the SLIC by writing to the
1417 * multicast address mask registers
1419 slic_reg32_write(&slic_regs->slic_mcastlow,
1420 (u32)(adapter->mcastmask & 0xFFFFFFFF), FLUSH);
1421 slic_reg32_write(&slic_regs->slic_mcasthigh,
1422 (u32)((adapter->mcastmask >> 32) & 0xFFFFFFFF), FLUSH);
1426 static void slic_timer_ping(ulong dev)
1428 struct adapter *adapter;
1429 struct sliccard *card;
1432 adapter = netdev_priv((struct net_device *)dev);
1434 card = adapter->card;
1437 adapter->pingtimer.expires = jiffies + (PING_TIMER_INTERVAL * HZ);
1438 add_timer(&adapter->pingtimer);
1444 * Perform initialization of our slic interface.
1447 static int slic_if_init(struct adapter *adapter)
1449 struct sliccard *card = adapter->card;
1450 struct net_device *dev = adapter->netdev;
1451 __iomem struct slic_regs *slic_regs = adapter->slic_regs;
1452 struct slic_shmem *pshmem;
1457 /* adapter should be down at this point */
1458 if (adapter->state != ADAPT_DOWN) {
1459 DBG_ERROR("slic_if_init adapter->state != ADAPT_DOWN\n");
1462 ASSERT(adapter->linkstate == LINK_DOWN);
1464 adapter->devflags_prev = dev->flags;
1465 adapter->macopts = MAC_DIRECTED;
1467 if (dev->flags & IFF_BROADCAST)
1468 adapter->macopts |= MAC_BCAST;
1469 if (dev->flags & IFF_PROMISC)
1470 adapter->macopts |= MAC_PROMISC;
1471 if (dev->flags & IFF_ALLMULTI)
1472 adapter->macopts |= MAC_ALLMCAST;
1473 if (dev->flags & IFF_MULTICAST)
1474 adapter->macopts |= MAC_MCAST;
1476 status = slic_adapter_allocresources(adapter);
1477 if (status != STATUS_SUCCESS) {
1479 ("slic_if_init: slic_adapter_allocresources FAILED %x\n",
1481 slic_adapter_freeresources(adapter);
1485 if (!adapter->queues_initialized) {
1486 if (slic_rspqueue_init(adapter))
1488 if (slic_cmdq_init(adapter))
1490 if (slic_rcvqueue_init(adapter))
1492 adapter->queues_initialized = 1;
1495 slic_reg32_write(&slic_regs->slic_icr, ICR_INT_OFF, FLUSH);
1498 if (!adapter->isp_initialized) {
1499 pshmem = (struct slic_shmem *)adapter->phys_shmem;
1501 spin_lock_irqsave(&adapter->bit64reglock.lock,
1502 adapter->bit64reglock.flags);
1504 #if defined(CONFIG_X86_64)
1505 slic_reg32_write(&slic_regs->slic_addr_upper,
1506 SLIC_GET_ADDR_HIGH(&pshmem->isr), DONT_FLUSH);
1507 slic_reg32_write(&slic_regs->slic_isp,
1508 SLIC_GET_ADDR_LOW(&pshmem->isr), FLUSH);
1509 #elif defined(CONFIG_X86)
1510 slic_reg32_write(&slic_regs->slic_addr_upper, 0, DONT_FLUSH);
1511 slic_reg32_write(&slic_regs->slic_isp, (u32)&pshmem->isr, FLUSH);
1515 spin_unlock_irqrestore(&adapter->bit64reglock.lock,
1516 adapter->bit64reglock.flags);
1517 adapter->isp_initialized = 1;
1520 adapter->state = ADAPT_UP;
1521 if (!card->loadtimerset) {
1522 init_timer(&card->loadtimer);
1523 card->loadtimer.expires =
1524 jiffies + (SLIC_LOADTIMER_PERIOD * HZ);
1525 card->loadtimer.data = (ulong) card;
1526 card->loadtimer.function = &slic_timer_load_check;
1527 add_timer(&card->loadtimer);
1529 card->loadtimerset = 1;
1532 if (!adapter->pingtimerset) {
1533 init_timer(&adapter->pingtimer);
1534 adapter->pingtimer.expires =
1535 jiffies + (PING_TIMER_INTERVAL * HZ);
1536 adapter->pingtimer.data = (ulong) dev;
1537 adapter->pingtimer.function = &slic_timer_ping;
1538 add_timer(&adapter->pingtimer);
1539 adapter->pingtimerset = 1;
1540 adapter->card->pingstatus = ISR_PINGMASK;
1544 * clear any pending events, then enable interrupts
1546 adapter->isrcopy = 0;
1547 adapter->pshmem->isr = 0;
1548 slic_reg32_write(&slic_regs->slic_isr, 0, FLUSH);
1549 slic_reg32_write(&slic_regs->slic_icr, ICR_INT_ON, FLUSH);
1551 slic_link_config(adapter, LINK_AUTOSPEED, LINK_AUTOD);
1552 slic_link_event_handler(adapter);
1554 return STATUS_SUCCESS;
1557 static void slic_unmap_mmio_space(struct adapter *adapter)
1559 if (adapter->slic_regs)
1560 iounmap(adapter->slic_regs);
1561 adapter->slic_regs = NULL;
1564 static int slic_adapter_allocresources(struct adapter *adapter)
1566 if (!adapter->intrregistered) {
1569 spin_unlock_irqrestore(&slic_global.driver_lock.lock,
1570 slic_global.driver_lock.flags);
1572 retval = request_irq(adapter->netdev->irq,
1575 adapter->netdev->name, adapter->netdev);
1577 spin_lock_irqsave(&slic_global.driver_lock.lock,
1578 slic_global.driver_lock.flags);
1581 DBG_ERROR("slicoss: request_irq (%s) FAILED [%x]\n",
1582 adapter->netdev->name, retval);
1585 adapter->intrregistered = 1;
1587 return STATUS_SUCCESS;
1590 static void slic_config_pci(struct pci_dev *pcidev)
1595 pci_read_config_word(pcidev, PCI_COMMAND, &pci_command);
1597 new_command = pci_command | PCI_COMMAND_MASTER
1598 | PCI_COMMAND_MEMORY
1599 | PCI_COMMAND_INVALIDATE
1600 | PCI_COMMAND_PARITY | PCI_COMMAND_SERR | PCI_COMMAND_FAST_BACK;
1601 if (pci_command != new_command)
1602 pci_write_config_word(pcidev, PCI_COMMAND, new_command);
1605 static void slic_adapter_freeresources(struct adapter *adapter)
1607 slic_init_cleanup(adapter);
1608 memset(&adapter->stats, 0, sizeof(struct net_device_stats));
1609 adapter->error_interrupts = 0;
1610 adapter->rcv_interrupts = 0;
1611 adapter->xmit_interrupts = 0;
1612 adapter->linkevent_interrupts = 0;
1613 adapter->upr_interrupts = 0;
1614 adapter->num_isrs = 0;
1615 adapter->xmit_completes = 0;
1616 adapter->rcv_broadcasts = 0;
1617 adapter->rcv_multicasts = 0;
1618 adapter->rcv_unicasts = 0;
1624 * Write phy control to configure link duplex/speed
1627 static void slic_link_config(struct adapter *adapter,
1628 u32 linkspeed, u32 linkduplex)
1637 if (adapter->state != ADAPT_UP)
1640 ASSERT((adapter->devid == SLIC_1GB_DEVICE_ID)
1641 || (adapter->devid == SLIC_2GB_DEVICE_ID));
1643 if (linkspeed > LINK_1000MB)
1644 linkspeed = LINK_AUTOSPEED;
1645 if (linkduplex > LINK_AUTOD)
1646 linkduplex = LINK_AUTOD;
1648 wphy = &adapter->slic_regs->slic_wphy;
1650 if ((linkspeed == LINK_AUTOSPEED) || (linkspeed == LINK_1000MB)) {
1651 if (adapter->flags & ADAPT_FLAGS_FIBERMEDIA) {
1652 /* We've got a fiber gigabit interface, and register
1653 * 4 is different in fiber mode than in copper mode
1656 /* advertise FD only @1000 Mb */
1657 phy_advreg = (MIICR_REG_4 | (PAR_ADV1000XFD));
1658 /* enable PAUSE frames */
1659 phy_advreg |= PAR_ASYMPAUSE_FIBER;
1660 slic_reg32_write(wphy, phy_advreg, FLUSH);
1662 if (linkspeed == LINK_AUTOSPEED) {
1663 /* reset phy, enable auto-neg */
1666 (PCR_RESET | PCR_AUTONEG |
1668 slic_reg32_write(wphy, phy_config, FLUSH);
1669 } else { /* forced 1000 Mb FD*/
1670 /* power down phy to break link
1671 this may not work) */
1672 phy_config = (MIICR_REG_PCR | PCR_POWERDOWN);
1673 slic_reg32_write(wphy, phy_config, FLUSH);
1674 /* wait, Marvell says 1 sec,
1675 try to get away with 10 ms */
1678 /* disable auto-neg, set speed/duplex,
1679 soft reset phy, powerup */
1682 (PCR_RESET | PCR_SPEED_1000 |
1684 slic_reg32_write(wphy, phy_config, FLUSH);
1686 } else { /* copper gigabit */
1688 /* Auto-Negotiate or 1000 Mb must be auto negotiated
1689 * We've got a copper gigabit interface, and
1690 * register 4 is different in copper mode than
1693 if (linkspeed == LINK_AUTOSPEED) {
1694 /* advertise 10/100 Mb modes */
1697 (PAR_ADV100FD | PAR_ADV100HD | PAR_ADV10FD
1700 /* linkspeed == LINK_1000MB -
1701 don't advertise 10/100 Mb modes */
1702 phy_advreg = MIICR_REG_4;
1704 /* enable PAUSE frames */
1705 phy_advreg |= PAR_ASYMPAUSE;
1706 /* required by the Cicada PHY */
1707 phy_advreg |= PAR_802_3;
1708 slic_reg32_write(wphy, phy_advreg, FLUSH);
1709 /* advertise FD only @1000 Mb */
1710 phy_gctlreg = (MIICR_REG_9 | (PGC_ADV1000FD));
1711 slic_reg32_write(wphy, phy_gctlreg, FLUSH);
1713 if (adapter->subsysid != SLIC_1GB_CICADA_SUBSYS_ID) {
1715 enable auto crossover */
1717 (MIICR_REG_16 | (MRV_REG16_XOVERON));
1718 slic_reg32_write(wphy, phy_config, FLUSH);
1720 /* reset phy, enable auto-neg */
1723 (PCR_RESET | PCR_AUTONEG |
1725 slic_reg32_write(wphy, phy_config, FLUSH);
1726 } else { /* it's a Cicada PHY */
1727 /* enable and restart auto-neg (don't reset) */
1730 (PCR_AUTONEG | PCR_AUTONEG_RST));
1731 slic_reg32_write(wphy, phy_config, FLUSH);
1736 if (linkspeed == LINK_10MB)
1739 speed = PCR_SPEED_100;
1740 if (linkduplex == LINK_HALFD)
1743 duplex = PCR_DUPLEX_FULL;
1745 if (adapter->subsysid != SLIC_1GB_CICADA_SUBSYS_ID) {
1747 disable auto crossover */
1748 phy_config = (MIICR_REG_16 | (MRV_REG16_XOVEROFF));
1749 slic_reg32_write(wphy, phy_config, FLUSH);
1752 /* power down phy to break link (this may not work) */
1753 phy_config = (MIICR_REG_PCR | (PCR_POWERDOWN | speed | duplex));
1754 slic_reg32_write(wphy, phy_config, FLUSH);
1756 /* wait, Marvell says 1 sec, try to get away with 10 ms */
1759 if (adapter->subsysid != SLIC_1GB_CICADA_SUBSYS_ID) {
1761 disable auto-neg, set speed,
1762 soft reset phy, powerup */
1764 (MIICR_REG_PCR | (PCR_RESET | speed | duplex));
1765 slic_reg32_write(wphy, phy_config, FLUSH);
1766 } else { /* it's a Cicada PHY */
1767 /* disable auto-neg, set speed, powerup */
1768 phy_config = (MIICR_REG_PCR | (speed | duplex));
1769 slic_reg32_write(wphy, phy_config, FLUSH);
1774 static void slic_card_cleanup(struct sliccard *card)
1776 if (card->loadtimerset) {
1777 card->loadtimerset = 0;
1778 del_timer(&card->loadtimer);
1781 slic_debug_card_destroy(card);
1786 static int slic_card_download_gbrcv(struct adapter *adapter)
1788 const struct firmware *fw;
1789 const char *file = "";
1791 __iomem struct slic_regs *slic_regs = adapter->slic_regs;
1795 u32 rcvucodelen = 0;
1797 switch (adapter->devid) {
1798 case SLIC_2GB_DEVICE_ID:
1799 file = "slicoss/oasisrcvucode.sys";
1801 case SLIC_1GB_DEVICE_ID:
1802 file = "slicoss/gbrcvucode.sys";
1809 ret = request_firmware(&fw, file, &adapter->pcidev->dev);
1811 printk(KERN_ERR "SLICOSS: Failed to load firmware %s\n", file);
1815 rcvucodelen = *(u32 *)(fw->data + index);
1817 switch (adapter->devid) {
1818 case SLIC_2GB_DEVICE_ID:
1819 if (rcvucodelen != OasisRcvUCodeLen)
1822 case SLIC_1GB_DEVICE_ID:
1823 if (rcvucodelen != GBRcvUCodeLen)
1830 /* start download */
1831 slic_reg32_write(&slic_regs->slic_rcv_wcs, SLIC_RCVWCS_BEGIN, FLUSH);
1832 /* download the rcv sequencer ucode */
1833 for (codeaddr = 0; codeaddr < rcvucodelen; codeaddr++) {
1834 /* write out instruction address */
1835 slic_reg32_write(&slic_regs->slic_rcv_wcs, codeaddr, FLUSH);
1837 instruction = *(u32 *)(fw->data + index);
1839 /* write out the instruction data low addr */
1840 slic_reg32_write(&slic_regs->slic_rcv_wcs, instruction, FLUSH);
1842 instruction = *(u8 *)(fw->data + index);
1844 /* write out the instruction data high addr */
1845 slic_reg32_write(&slic_regs->slic_rcv_wcs, (u8)instruction,
1849 /* download finished */
1850 release_firmware(fw);
1851 slic_reg32_write(&slic_regs->slic_rcv_wcs, SLIC_RCVWCS_FINISH, FLUSH);
1855 static int slic_card_download(struct adapter *adapter)
1857 const struct firmware *fw;
1858 const char *file = "";
1861 int thissectionsize;
1863 __iomem struct slic_regs *slic_regs = adapter->slic_regs;
1871 int ucode_start, index = 0;
1873 switch (adapter->devid) {
1874 case SLIC_2GB_DEVICE_ID:
1875 file = "slicoss/oasisdownload.sys";
1877 case SLIC_1GB_DEVICE_ID:
1878 file = "slicoss/gbdownload.sys";
1884 ret = request_firmware(&fw, file, &adapter->pcidev->dev);
1886 printk(KERN_ERR "SLICOSS: Failed to load firmware %s\n", file);
1889 numsects = *(u32 *)(fw->data + index);
1891 ASSERT(numsects <= 3);
1892 for (i = 0; i < numsects; i++) {
1893 sectsize[i] = *(u32 *)(fw->data + index);
1896 for (i = 0; i < numsects; i++) {
1897 sectstart[i] = *(u32 *)(fw->data + index);
1900 ucode_start = index;
1901 instruction = *(u32 *)(fw->data + index);
1903 for (section = 0; section < numsects; section++) {
1904 baseaddress = sectstart[section];
1905 thissectionsize = sectsize[section] >> 3;
1907 for (codeaddr = 0; codeaddr < thissectionsize; codeaddr++) {
1908 /* Write out instruction address */
1909 slic_reg32_write(&slic_regs->slic_wcs,
1910 baseaddress + codeaddr, FLUSH);
1911 /* Write out instruction to low addr */
1912 slic_reg32_write(&slic_regs->slic_wcs, instruction, FLUSH);
1913 instruction = *(u32 *)(fw->data + index);
1916 /* Write out instruction to high addr */
1917 slic_reg32_write(&slic_regs->slic_wcs, instruction, FLUSH);
1918 instruction = *(u32 *)(fw->data + index);
1922 index = ucode_start;
1923 for (section = 0; section < numsects; section++) {
1924 instruction = *(u32 *)(fw->data + index);
1925 baseaddress = sectstart[section];
1926 if (baseaddress < 0x8000)
1928 thissectionsize = sectsize[section] >> 3;
1930 for (codeaddr = 0; codeaddr < thissectionsize; codeaddr++) {
1931 /* Write out instruction address */
1932 slic_reg32_write(&slic_regs->slic_wcs,
1933 SLIC_WCS_COMPARE | (baseaddress + codeaddr),
1935 /* Write out instruction to low addr */
1936 slic_reg32_write(&slic_regs->slic_wcs, instruction,
1938 instruction = *(u32 *)(fw->data + index);
1940 /* Write out instruction to high addr */
1941 slic_reg32_write(&slic_regs->slic_wcs, instruction,
1943 instruction = *(u32 *)(fw->data + index);
1946 /* Check SRAM location zero. If it is non-zero. Abort.*/
1947 /* failure = readl((u32 __iomem *)&slic_regs->slic_reset);
1949 release_firmware(fw);
1954 release_firmware(fw);
1955 /* Everything OK, kick off the card */
1957 slic_reg32_write(&slic_regs->slic_wcs, SLIC_WCS_START, FLUSH);
1959 /* stall for 20 ms, long enough for ucode to init card
1960 and reach mainloop */
1963 return STATUS_SUCCESS;
1966 static void slic_adapter_set_hwaddr(struct adapter *adapter)
1968 struct sliccard *card = adapter->card;
1970 if ((adapter->card) && (card->config_set)) {
1971 memcpy(adapter->macaddr,
1972 card->config.MacInfo[adapter->functionnumber].macaddrA,
1973 sizeof(struct slic_config_mac));
1974 if (!(adapter->currmacaddr[0] || adapter->currmacaddr[1] ||
1975 adapter->currmacaddr[2] || adapter->currmacaddr[3] ||
1976 adapter->currmacaddr[4] || adapter->currmacaddr[5])) {
1977 memcpy(adapter->currmacaddr, adapter->macaddr, 6);
1979 if (adapter->netdev) {
1980 memcpy(adapter->netdev->dev_addr, adapter->currmacaddr,
1986 static void slic_intagg_set(struct adapter *adapter, u32 value)
1988 slic_reg32_write(&adapter->slic_regs->slic_intagg, value, FLUSH);
1989 adapter->card->loadlevel_current = value;
1992 static int slic_card_init(struct sliccard *card, struct adapter *adapter)
1994 __iomem struct slic_regs *slic_regs = adapter->slic_regs;
1995 struct slic_eeprom *peeprom;
1996 struct oslic_eeprom *pOeeprom;
1997 dma_addr_t phys_config;
2001 struct slic_shmem *pshmem;
2003 uint macaddrs = card->card_size;
2008 struct slic_config_mac *pmac;
2009 unsigned char fruformat;
2010 unsigned char oemfruformat;
2011 struct atk_fru *patkfru;
2012 union oemfru *poemfru;
2014 /* Reset everything except PCI configuration space */
2015 slic_soft_reset(adapter);
2017 /* Download the microcode */
2018 status = slic_card_download(adapter);
2020 if (status != STATUS_SUCCESS) {
2021 DBG_ERROR("SLIC download failed bus %d slot %d\n",
2022 (uint) adapter->busnumber,
2023 (uint) adapter->slotnumber);
2027 if (!card->config_set) {
2028 peeprom = pci_alloc_consistent(adapter->pcidev,
2029 sizeof(struct slic_eeprom),
2032 phys_configl = SLIC_GET_ADDR_LOW(phys_config);
2033 phys_configh = SLIC_GET_ADDR_HIGH(phys_config);
2037 ("SLIC eeprom read failed to get memory bus %d \
2039 (uint) adapter->busnumber,
2040 (uint) adapter->slotnumber);
2043 memset(peeprom, 0, sizeof(struct slic_eeprom));
2045 slic_reg32_write(&slic_regs->slic_icr, ICR_INT_OFF, FLUSH);
2047 pshmem = (struct slic_shmem *)adapter->phys_shmem;
2049 spin_lock_irqsave(&adapter->bit64reglock.lock,
2050 adapter->bit64reglock.flags);
2051 slic_reg32_write(&slic_regs->slic_addr_upper, 0, DONT_FLUSH);
2052 slic_reg32_write(&slic_regs->slic_isp,
2053 SLIC_GET_ADDR_LOW(&pshmem->isr), FLUSH);
2054 spin_unlock_irqrestore(&adapter->bit64reglock.lock,
2055 adapter->bit64reglock.flags);
2057 slic_config_get(adapter, phys_configl, phys_configh);
2060 if (adapter->pshmem->isr) {
2061 if (adapter->pshmem->isr & ISR_UPC) {
2062 adapter->pshmem->isr = 0;
2063 slic_reg64_write(adapter,
2064 &slic_regs->slic_isp, 0,
2065 &slic_regs->slic_addr_upper,
2067 slic_reg32_write(&slic_regs->slic_isr,
2070 slic_upr_request_complete(adapter, 0);
2073 adapter->pshmem->isr = 0;
2074 slic_reg32_write(&slic_regs->slic_isr,
2082 ("SLIC: %d config data fetch timed "
2083 "out!\n", adapter->port);
2084 slic_reg64_write(adapter,
2085 &slic_regs->slic_isp, 0,
2086 &slic_regs->slic_addr_upper,
2093 switch (adapter->devid) {
2095 case SLIC_2GB_DEVICE_ID:
2096 /* extract EEPROM data and pointers to EEPROM data */
2097 pOeeprom = (struct oslic_eeprom *) peeprom;
2098 eecodesize = pOeeprom->EecodeSize;
2099 dramsize = pOeeprom->DramSize;
2100 pmac = pOeeprom->MacInfo;
2101 fruformat = pOeeprom->FruFormat;
2102 patkfru = &pOeeprom->AtkFru;
2103 oemfruformat = pOeeprom->OemFruFormat;
2104 poemfru = &pOeeprom->OemFru;
2106 /* Minor kludge for Oasis card
2107 get 2 MAC addresses from the
2108 EEPROM to ensure that function 1
2109 gets the Port 1 MAC address */
2112 /* extract EEPROM data and pointers to EEPROM data */
2113 eecodesize = peeprom->EecodeSize;
2114 dramsize = peeprom->DramSize;
2115 pmac = peeprom->u2.mac.MacInfo;
2116 fruformat = peeprom->FruFormat;
2117 patkfru = &peeprom->AtkFru;
2118 oemfruformat = peeprom->OemFruFormat;
2119 poemfru = &peeprom->OemFru;
2123 card->config.EepromValid = false;
2125 /* see if the EEPROM is valid by checking it's checksum */
2126 if ((eecodesize <= MAX_EECODE_SIZE) &&
2127 (eecodesize >= MIN_EECODE_SIZE)) {
2130 *(u16 *) ((char *) peeprom + (eecodesize - 2));
2132 calculate the EEPROM checksum
2135 ~slic_eeprom_cksum((char *) peeprom,
2138 if the ucdoe chksum flag bit worked,
2139 we wouldn't need this shit
2141 if (ee_chksum == calc_chksum)
2142 card->config.EepromValid = true;
2144 /* copy in the DRAM size */
2145 card->config.DramSize = dramsize;
2147 /* copy in the MAC address(es) */
2148 for (i = 0; i < macaddrs; i++) {
2149 memcpy(&card->config.MacInfo[i],
2150 &pmac[i], sizeof(struct slic_config_mac));
2153 /* copy the Alacritech FRU information */
2154 card->config.FruFormat = fruformat;
2155 memcpy(&card->config.AtkFru, patkfru,
2156 sizeof(struct atk_fru));
2158 pci_free_consistent(adapter->pcidev,
2159 sizeof(struct slic_eeprom),
2160 peeprom, phys_config);
2162 if ((!card->config.EepromValid) &&
2163 (adapter->reg_params.fail_on_bad_eeprom)) {
2164 slic_reg64_write(adapter, &slic_regs->slic_isp, 0,
2165 &slic_regs->slic_addr_upper,
2168 ("unsupported CONFIGURATION EEPROM invalid\n");
2172 card->config_set = 1;
2175 if (slic_card_download_gbrcv(adapter)) {
2176 DBG_ERROR("%s unable to download GB receive microcode\n",
2181 if (slic_global.dynamic_intagg)
2182 slic_intagg_set(adapter, 0);
2184 slic_intagg_set(adapter, intagg_delay);
2187 * Initialize ping status to "ok"
2189 card->pingstatus = ISR_PINGMASK;
2192 * Lastly, mark our card state as up and return success
2194 card->state = CARD_UP;
2195 card->reset_in_progress = 0;
2197 return STATUS_SUCCESS;
2200 static u32 slic_card_locate(struct adapter *adapter)
2202 struct sliccard *card = slic_global.slic_card;
2203 struct physcard *physcard = slic_global.phys_card;
2205 u16 __iomem *hostid_reg;
2207 uint rdhostid_offset = 0;
2209 switch (adapter->devid) {
2210 case SLIC_2GB_DEVICE_ID:
2211 rdhostid_offset = SLIC_RDHOSTID_2GB;
2213 case SLIC_1GB_DEVICE_ID:
2214 rdhostid_offset = SLIC_RDHOSTID_1GB;
2222 (u16 __iomem *) (((u8 __iomem *) (adapter->slic_regs)) +
2225 /* read the 16 bit hostid from SRAM */
2226 card_hostid = (ushort) readw(hostid_reg);
2228 /* Initialize a new card structure if need be */
2229 if (card_hostid == SLIC_HOSTID_DEFAULT) {
2230 card = kzalloc(sizeof(struct sliccard), GFP_KERNEL);
2234 card->next = slic_global.slic_card;
2235 slic_global.slic_card = card;
2236 card->busnumber = adapter->busnumber;
2237 card->slotnumber = adapter->slotnumber;
2239 /* Find an available cardnum */
2240 for (i = 0; i < SLIC_MAX_CARDS; i++) {
2241 if (slic_global.cardnuminuse[i] == 0) {
2242 slic_global.cardnuminuse[i] = 1;
2247 slic_global.num_slic_cards++;
2249 slic_debug_card_create(card);
2251 /* Card exists, find the card this adapter belongs to */
2253 if (card->cardnum == card_hostid)
2261 return STATUS_FAILURE;
2262 /* Put the adapter in the card's adapter list */
2263 ASSERT(card->adapter[adapter->port] == NULL);
2264 if (!card->adapter[adapter->port]) {
2265 card->adapter[adapter->port] = adapter;
2266 adapter->card = card;
2269 card->card_size = 1; /* one port per *logical* card */
2272 for (i = 0; i < SLIC_MAX_PORTS; i++) {
2273 if (!physcard->adapter[i])
2278 ASSERT(i != SLIC_MAX_PORTS);
2279 if (physcard->adapter[i]->slotnumber == adapter->slotnumber)
2281 physcard = physcard->next;
2284 /* no structure allocated for this physical card yet */
2285 physcard = kzalloc(sizeof(struct physcard), GFP_KERNEL);
2288 physcard->next = slic_global.phys_card;
2289 slic_global.phys_card = physcard;
2290 physcard->adapters_allocd = 1;
2292 physcard->adapters_allocd++;
2294 /* Note - this is ZERO relative */
2295 adapter->physport = physcard->adapters_allocd - 1;
2297 ASSERT(physcard->adapter[adapter->physport] == NULL);
2298 physcard->adapter[adapter->physport] = adapter;
2299 adapter->physcard = physcard;
2304 static void slic_soft_reset(struct adapter *adapter)
2306 if (adapter->card->state == CARD_UP) {
2307 slic_reg32_write(&adapter->slic_regs->slic_quiesce, 0, FLUSH);
2311 slic_reg32_write(&adapter->slic_regs->slic_reset, SLIC_RESET_MAGIC,
2316 static void slic_config_set(struct adapter *adapter, bool linkchange)
2320 __iomem struct slic_regs *slic_regs = adapter->slic_regs;
2324 slic_mac_config(adapter);
2325 RcrReset = GRCR_RESET;
2327 slic_mac_address_config(adapter);
2331 if (adapter->linkduplex == LINK_FULLD) {
2333 value = (GXCR_RESET | /* Always reset */
2334 GXCR_XMTEN | /* Enable transmit */
2335 GXCR_PAUSEEN); /* Enable pause */
2337 slic_reg32_write(&slic_regs->slic_wxcfg, value, FLUSH);
2339 /* Setup rcvcfg last */
2340 value = (RcrReset | /* Reset, if linkchange */
2341 GRCR_CTLEN | /* Enable CTL frames */
2342 GRCR_ADDRAEN | /* Address A enable */
2343 GRCR_RCVBAD | /* Rcv bad frames */
2344 (GRCR_HASHSIZE << GRCR_HASHSIZE_SHIFT));
2347 value = (GXCR_RESET | /* Always reset */
2348 GXCR_XMTEN); /* Enable transmit */
2350 slic_reg32_write(&slic_regs->slic_wxcfg, value, FLUSH);
2352 /* Setup rcvcfg last */
2353 value = (RcrReset | /* Reset, if linkchange */
2354 GRCR_ADDRAEN | /* Address A enable */
2355 GRCR_RCVBAD | /* Rcv bad frames */
2356 (GRCR_HASHSIZE << GRCR_HASHSIZE_SHIFT));
2359 if (adapter->state != ADAPT_DOWN) {
2360 /* Only enable receive if we are restarting or running */
2361 value |= GRCR_RCVEN;
2364 if (adapter->macopts & MAC_PROMISC)
2365 value |= GRCR_RCVALL;
2367 slic_reg32_write(&slic_regs->slic_wrcfg, value, FLUSH);
2371 * Turn off RCV and XMT, power down PHY
2373 static void slic_config_clear(struct adapter *adapter)
2377 __iomem struct slic_regs *slic_regs = adapter->slic_regs;
2380 value = (GXCR_RESET | /* Always reset */
2381 GXCR_PAUSEEN); /* Enable pause */
2383 slic_reg32_write(&slic_regs->slic_wxcfg, value, FLUSH);
2385 value = (GRCR_RESET | /* Always reset */
2386 GRCR_CTLEN | /* Enable CTL frames */
2387 GRCR_ADDRAEN | /* Address A enable */
2388 (GRCR_HASHSIZE << GRCR_HASHSIZE_SHIFT));
2390 slic_reg32_write(&slic_regs->slic_wrcfg, value, FLUSH);
2392 /* power down phy */
2393 phy_config = (MIICR_REG_PCR | (PCR_POWERDOWN));
2394 slic_reg32_write(&slic_regs->slic_wphy, phy_config, FLUSH);
2397 static void slic_config_get(struct adapter *adapter, u32 config,
2402 status = slic_upr_request(adapter,
2404 (u32) config, (u32) config_h, 0, 0);
2405 ASSERT(status == 0);
2408 static void slic_mac_address_config(struct adapter *adapter)
2412 __iomem struct slic_regs *slic_regs = adapter->slic_regs;
2414 value = *(u32 *) &adapter->currmacaddr[2];
2415 value = ntohl(value);
2416 slic_reg32_write(&slic_regs->slic_wraddral, value, FLUSH);
2417 slic_reg32_write(&slic_regs->slic_wraddrbl, value, FLUSH);
2419 value2 = (u32) ((adapter->currmacaddr[0] << 8 |
2420 adapter->currmacaddr[1]) & 0xFFFF);
2422 slic_reg32_write(&slic_regs->slic_wraddrah, value2, FLUSH);
2423 slic_reg32_write(&slic_regs->slic_wraddrbh, value2, FLUSH);
2425 /* Write our multicast mask out to the card. This is done */
2426 /* here in addition to the slic_mcast_addr_set routine */
2427 /* because ALL_MCAST may have been enabled or disabled */
2428 slic_mcast_set_mask(adapter);
2431 static void slic_mac_config(struct adapter *adapter)
2434 __iomem struct slic_regs *slic_regs = adapter->slic_regs;
2436 /* Setup GMAC gaps */
2437 if (adapter->linkspeed == LINK_1000MB) {
2438 value = ((GMCR_GAPBB_1000 << GMCR_GAPBB_SHIFT) |
2439 (GMCR_GAPR1_1000 << GMCR_GAPR1_SHIFT) |
2440 (GMCR_GAPR2_1000 << GMCR_GAPR2_SHIFT));
2442 value = ((GMCR_GAPBB_100 << GMCR_GAPBB_SHIFT) |
2443 (GMCR_GAPR1_100 << GMCR_GAPR1_SHIFT) |
2444 (GMCR_GAPR2_100 << GMCR_GAPR2_SHIFT));
2448 if (adapter->linkspeed == LINK_1000MB)
2451 /* enable fullduplex */
2452 if ((adapter->linkduplex == LINK_FULLD)
2453 || (adapter->macopts & MAC_LOOPBACK)) {
2454 value |= GMCR_FULLD;
2457 /* write mac config */
2458 slic_reg32_write(&slic_regs->slic_wmcfg, value, FLUSH);
2460 /* setup mac addresses */
2461 slic_mac_address_config(adapter);
2464 static bool slic_mac_filter(struct adapter *adapter,
2465 struct ether_header *ether_frame)
2467 u32 opts = adapter->macopts;
2468 u32 *dhost4 = (u32 *)ðer_frame->ether_dhost[0];
2469 u16 *dhost2 = (u16 *)ðer_frame->ether_dhost[4];
2472 if (opts & MAC_PROMISC)
2475 if ((*dhost4 == 0xFFFFFFFF) && (*dhost2 == 0xFFFF)) {
2476 if (opts & MAC_BCAST) {
2477 adapter->rcv_broadcasts++;
2484 if (ether_frame->ether_dhost[0] & 0x01) {
2485 if (opts & MAC_ALLMCAST) {
2486 adapter->rcv_multicasts++;
2487 adapter->stats.multicast++;
2490 if (opts & MAC_MCAST) {
2491 struct mcast_address *mcaddr = adapter->mcastaddrs;
2494 ETHER_EQ_ADDR(mcaddr->address,
2495 ether_frame->ether_dhost,
2498 adapter->rcv_multicasts++;
2499 adapter->stats.multicast++;
2502 mcaddr = mcaddr->next;
2509 if (opts & MAC_DIRECTED) {
2510 adapter->rcv_unicasts++;
2517 static int slic_mac_set_address(struct net_device *dev, void *ptr)
2519 struct adapter *adapter = (struct adapter *)netdev_priv(dev);
2520 struct sockaddr *addr = ptr;
2522 if (netif_running(dev))
2527 memcpy(dev->dev_addr, addr->sa_data, dev->addr_len);
2528 memcpy(adapter->currmacaddr, addr->sa_data, dev->addr_len);
2530 slic_config_set(adapter, true);
2534 static void slic_timer_load_check(ulong cardaddr)
2536 struct sliccard *card = (struct sliccard *)cardaddr;
2537 struct adapter *adapter = card->master;
2538 u32 __iomem *intagg;
2539 u32 load = card->events;
2542 intagg = &adapter->slic_regs->slic_intagg;
2544 if ((adapter) && (adapter->state == ADAPT_UP) &&
2545 (card->state == CARD_UP) && (slic_global.dynamic_intagg)) {
2546 if (adapter->devid == SLIC_1GB_DEVICE_ID) {
2547 if (adapter->linkspeed == LINK_1000MB)
2550 if (load > SLIC_LOAD_5)
2551 level = SLIC_INTAGG_5;
2552 else if (load > SLIC_LOAD_4)
2553 level = SLIC_INTAGG_4;
2554 else if (load > SLIC_LOAD_3)
2555 level = SLIC_INTAGG_3;
2556 else if (load > SLIC_LOAD_2)
2557 level = SLIC_INTAGG_2;
2558 else if (load > SLIC_LOAD_1)
2559 level = SLIC_INTAGG_1;
2561 level = SLIC_INTAGG_0;
2563 if (card->loadlevel_current != level) {
2564 card->loadlevel_current = level;
2565 slic_reg32_write(intagg, level, FLUSH);
2568 if (load > SLIC_LOAD_5)
2569 level = SLIC_INTAGG_5;
2570 else if (load > SLIC_LOAD_4)
2571 level = SLIC_INTAGG_4;
2572 else if (load > SLIC_LOAD_3)
2573 level = SLIC_INTAGG_3;
2574 else if (load > SLIC_LOAD_2)
2575 level = SLIC_INTAGG_2;
2576 else if (load > SLIC_LOAD_1)
2577 level = SLIC_INTAGG_1;
2579 level = SLIC_INTAGG_0;
2580 if (card->loadlevel_current != level) {
2581 card->loadlevel_current = level;
2582 slic_reg32_write(intagg, level, FLUSH);
2587 card->loadtimer.expires = jiffies + (SLIC_LOADTIMER_PERIOD * HZ);
2588 add_timer(&card->loadtimer);
2591 static void slic_assert_fail(void)
2595 cpuid = smp_processor_id();
2596 curr_pid = current->pid;
2598 DBG_ERROR("%s CPU # %d ---- PID # %d\n", __func__, cpuid, curr_pid);
2601 static int slic_upr_queue_request(struct adapter *adapter,
2605 u32 upr_buffer, u32 upr_buffer_h)
2607 struct slic_upr *upr;
2608 struct slic_upr *uprqueue;
2610 upr = kmalloc(sizeof(struct slic_upr), GFP_ATOMIC);
2614 upr->adapter = adapter->port;
2615 upr->upr_request = upr_request;
2616 upr->upr_data = upr_data;
2617 upr->upr_buffer = upr_buffer;
2618 upr->upr_data_h = upr_data_h;
2619 upr->upr_buffer_h = upr_buffer_h;
2621 if (adapter->upr_list) {
2622 uprqueue = adapter->upr_list;
2624 while (uprqueue->next)
2625 uprqueue = uprqueue->next;
2626 uprqueue->next = upr;
2628 adapter->upr_list = upr;
2630 return STATUS_SUCCESS;
2633 static int slic_upr_request(struct adapter *adapter,
2637 u32 upr_buffer, u32 upr_buffer_h)
2641 spin_lock_irqsave(&adapter->upr_lock.lock, adapter->upr_lock.flags);
2642 status = slic_upr_queue_request(adapter,
2645 upr_data_h, upr_buffer, upr_buffer_h);
2646 if (status != STATUS_SUCCESS) {
2647 spin_unlock_irqrestore(&adapter->upr_lock.lock,
2648 adapter->upr_lock.flags);
2651 slic_upr_start(adapter);
2652 spin_unlock_irqrestore(&adapter->upr_lock.lock,
2653 adapter->upr_lock.flags);
2654 return STATUS_PENDING;
2657 static void slic_upr_request_complete(struct adapter *adapter, u32 isr)
2659 struct sliccard *card = adapter->card;
2660 struct slic_upr *upr;
2662 spin_lock_irqsave(&adapter->upr_lock.lock, adapter->upr_lock.flags);
2663 upr = adapter->upr_list;
2666 spin_unlock_irqrestore(&adapter->upr_lock.lock,
2667 adapter->upr_lock.flags);
2670 adapter->upr_list = upr->next;
2672 adapter->upr_busy = 0;
2673 ASSERT(adapter->port == upr->adapter);
2674 switch (upr->upr_request) {
2675 case SLIC_UPR_STATS:
2677 struct slic_stats *slicstats =
2678 (struct slic_stats *) &adapter->pshmem->inicstats;
2679 struct slic_stats *newstats = slicstats;
2680 struct slic_stats *old = &adapter->inicstats_prev;
2681 struct slicnet_stats *stst = &adapter->slic_stats;
2683 if (isr & ISR_UPCERR) {
2685 ("SLIC_UPR_STATS command failed isr[%x]\n",
2690 UPDATE_STATS_GB(stst->tcp.xmit_tcp_segs,
2691 newstats->xmit_tcp_segs_gb,
2692 old->xmit_tcp_segs_gb);
2694 UPDATE_STATS_GB(stst->tcp.xmit_tcp_bytes,
2695 newstats->xmit_tcp_bytes_gb,
2696 old->xmit_tcp_bytes_gb);
2698 UPDATE_STATS_GB(stst->tcp.rcv_tcp_segs,
2699 newstats->rcv_tcp_segs_gb,
2700 old->rcv_tcp_segs_gb);
2702 UPDATE_STATS_GB(stst->tcp.rcv_tcp_bytes,
2703 newstats->rcv_tcp_bytes_gb,
2704 old->rcv_tcp_bytes_gb);
2706 UPDATE_STATS_GB(stst->iface.xmt_bytes,
2707 newstats->xmit_bytes_gb,
2708 old->xmit_bytes_gb);
2710 UPDATE_STATS_GB(stst->iface.xmt_ucast,
2711 newstats->xmit_unicasts_gb,
2712 old->xmit_unicasts_gb);
2714 UPDATE_STATS_GB(stst->iface.rcv_bytes,
2715 newstats->rcv_bytes_gb,
2718 UPDATE_STATS_GB(stst->iface.rcv_ucast,
2719 newstats->rcv_unicasts_gb,
2720 old->rcv_unicasts_gb);
2722 UPDATE_STATS_GB(stst->iface.xmt_errors,
2723 newstats->xmit_collisions_gb,
2724 old->xmit_collisions_gb);
2726 UPDATE_STATS_GB(stst->iface.xmt_errors,
2727 newstats->xmit_excess_collisions_gb,
2728 old->xmit_excess_collisions_gb);
2730 UPDATE_STATS_GB(stst->iface.xmt_errors,
2731 newstats->xmit_other_error_gb,
2732 old->xmit_other_error_gb);
2734 UPDATE_STATS_GB(stst->iface.rcv_errors,
2735 newstats->rcv_other_error_gb,
2736 old->rcv_other_error_gb);
2738 UPDATE_STATS_GB(stst->iface.rcv_discards,
2739 newstats->rcv_drops_gb,
2742 if (newstats->rcv_drops_gb > old->rcv_drops_gb) {
2743 adapter->rcv_drops +=
2744 (newstats->rcv_drops_gb -
2747 memcpy(old, newstats, sizeof(struct slic_stats));
2751 slic_link_upr_complete(adapter, isr);
2753 case SLIC_UPR_RCONFIG:
2768 card->pingstatus |= (isr & ISR_PINGDSMASK);
2774 slic_upr_start(adapter);
2775 spin_unlock_irqrestore(&adapter->upr_lock.lock,
2776 adapter->upr_lock.flags);
2779 static void slic_upr_start(struct adapter *adapter)
2781 struct slic_upr *upr;
2782 __iomem struct slic_regs *slic_regs = adapter->slic_regs;
2788 upr = adapter->upr_list;
2791 if (adapter->upr_busy)
2793 adapter->upr_busy = 1;
2795 switch (upr->upr_request) {
2796 case SLIC_UPR_STATS:
2797 if (upr->upr_data_h == 0) {
2798 slic_reg32_write(&slic_regs->slic_stats, upr->upr_data,
2801 slic_reg64_write(adapter, &slic_regs->slic_stats64,
2803 &slic_regs->slic_addr_upper,
2804 upr->upr_data_h, FLUSH);
2809 slic_reg64_write(adapter, &slic_regs->slic_rlsr, upr->upr_data,
2810 &slic_regs->slic_addr_upper, upr->upr_data_h,
2814 case SLIC_UPR_RCONFIG:
2815 slic_reg64_write(adapter, &slic_regs->slic_rconfig,
2816 upr->upr_data, &slic_regs->slic_addr_upper,
2817 upr->upr_data_h, FLUSH);
2820 slic_reg32_write(&slic_regs->slic_ping, 1, FLUSH);
2827 static void slic_link_upr_complete(struct adapter *adapter, u32 isr)
2829 u32 linkstatus = adapter->pshmem->linkstatus;
2831 unsigned char linkspeed;
2832 unsigned char linkduplex;
2834 if ((isr & ISR_UPCERR) || (isr & ISR_UPCBSY)) {
2835 struct slic_shmem *pshmem;
2837 pshmem = (struct slic_shmem *)adapter->phys_shmem;
2838 #if defined(CONFIG_X86_64)
2839 slic_upr_queue_request(adapter,
2841 SLIC_GET_ADDR_LOW(&pshmem->linkstatus),
2842 SLIC_GET_ADDR_HIGH(&pshmem->linkstatus),
2844 #elif defined(CONFIG_X86)
2845 slic_upr_queue_request(adapter,
2847 (u32) &pshmem->linkstatus,
2848 SLIC_GET_ADDR_HIGH(pshmem), 0, 0);
2854 if (adapter->state != ADAPT_UP)
2857 ASSERT((adapter->devid == SLIC_1GB_DEVICE_ID)
2858 || (adapter->devid == SLIC_2GB_DEVICE_ID));
2860 linkup = linkstatus & GIG_LINKUP ? LINK_UP : LINK_DOWN;
2861 if (linkstatus & GIG_SPEED_1000)
2862 linkspeed = LINK_1000MB;
2863 else if (linkstatus & GIG_SPEED_100)
2864 linkspeed = LINK_100MB;
2866 linkspeed = LINK_10MB;
2868 if (linkstatus & GIG_FULLDUPLEX)
2869 linkduplex = LINK_FULLD;
2871 linkduplex = LINK_HALFD;
2873 if ((adapter->linkstate == LINK_DOWN) && (linkup == LINK_DOWN))
2876 /* link up event, but nothing has changed */
2877 if ((adapter->linkstate == LINK_UP) &&
2878 (linkup == LINK_UP) &&
2879 (adapter->linkspeed == linkspeed) &&
2880 (adapter->linkduplex == linkduplex))
2883 /* link has changed at this point */
2885 /* link has gone from up to down */
2886 if (linkup == LINK_DOWN) {
2887 adapter->linkstate = LINK_DOWN;
2891 /* link has gone from down to up */
2892 adapter->linkspeed = linkspeed;
2893 adapter->linkduplex = linkduplex;
2895 if (adapter->linkstate != LINK_UP) {
2897 slic_config_set(adapter, true);
2898 adapter->linkstate = LINK_UP;
2899 netif_start_queue(adapter->netdev);
2904 * this is here to checksum the eeprom, there is some ucode bug
2905 * which prevens us from using the ucode result.
2906 * remove this once ucode is fixed.
2908 static ushort slic_eeprom_cksum(char *m, int len)
2910 #define ADDCARRY(x) (x > 65535 ? x -= 65535 : x)
2911 #define REDUCE {l_util.l = sum; sum = l_util.s[0] + l_util.s[1]; ADDCARRY(sum);\
2916 u32 byte_swapped = 0;
2933 #ifdef CONFIG_X86_64
2934 w_int = (u32) ((ulong) w & 0x00000000FFFFFFFF);
2938 if ((1 & w_int) && (len > 0)) {
2941 s_util.c[0] = *(unsigned char *)w;
2942 w = (u16 *)((char *)w + 1);
2947 /* Unroll the loop to make overhead from branches &c small. */
2948 while ((len -= 32) >= 0) {
2965 w = (u16 *)((ulong) w + 16); /* verify */
2968 while ((len -= 8) >= 0) {
2973 w = (u16 *)((ulong) w + 4); /* verify */
2976 if (len != 0 || byte_swapped != 0) {
2978 while ((len -= 2) >= 0)
2979 sum += *w++; /* verify */
2985 s_util.c[1] = *(char *) w;
2992 } else if (len == -1) {
2993 s_util.c[0] = *(char *) w;
3002 return (ushort) sum;
3005 static int slic_rspqueue_init(struct adapter *adapter)
3008 struct slic_rspqueue *rspq = &adapter->rspqueue;
3009 __iomem struct slic_regs *slic_regs = adapter->slic_regs;
3012 ASSERT(adapter->state == ADAPT_DOWN);
3013 memset(rspq, 0, sizeof(struct slic_rspqueue));
3015 rspq->num_pages = SLIC_RSPQ_PAGES_GB;
3017 for (i = 0; i < rspq->num_pages; i++) {
3019 pci_alloc_consistent(adapter->pcidev, PAGE_SIZE,
3021 if (!rspq->vaddr[i]) {
3023 ("rspqueue_init_failed pci_alloc_consistent\n");
3024 slic_rspqueue_free(adapter);
3025 return STATUS_FAILURE;
3027 #ifndef CONFIG_X86_64
3028 ASSERT(((u32) rspq->vaddr[i] & 0xFFFFF000) ==
3029 (u32) rspq->vaddr[i]);
3030 ASSERT(((u32) rspq->paddr[i] & 0xFFFFF000) ==
3031 (u32) rspq->paddr[i]);
3033 memset(rspq->vaddr[i], 0, PAGE_SIZE);
3036 slic_reg32_write(&slic_regs->slic_rbar,
3037 (rspq->paddr[i] | SLIC_RSPQ_BUFSINPAGE),
3040 slic_reg64_write(adapter, &slic_regs->slic_rbar64,
3041 (rspq->paddr[i] | SLIC_RSPQ_BUFSINPAGE),
3042 &slic_regs->slic_addr_upper,
3043 paddrh, DONT_FLUSH);
3047 rspq->pageindex = 0;
3048 rspq->rspbuf = (struct slic_rspbuf *)rspq->vaddr[0];
3049 return STATUS_SUCCESS;
3052 static void slic_rspqueue_free(struct adapter *adapter)
3055 struct slic_rspqueue *rspq = &adapter->rspqueue;
3057 for (i = 0; i < rspq->num_pages; i++) {
3058 if (rspq->vaddr[i]) {
3059 pci_free_consistent(adapter->pcidev, PAGE_SIZE,
3060 rspq->vaddr[i], rspq->paddr[i]);
3062 rspq->vaddr[i] = NULL;
3066 rspq->pageindex = 0;
3067 rspq->rspbuf = NULL;
3070 static struct slic_rspbuf *slic_rspqueue_getnext(struct adapter *adapter)
3072 struct slic_rspqueue *rspq = &adapter->rspqueue;
3073 struct slic_rspbuf *buf;
3075 if (!(rspq->rspbuf->status))
3079 #ifndef CONFIG_X86_64
3080 ASSERT((buf->status & 0xFFFFFFE0) == 0);
3082 ASSERT(buf->hosthandle);
3083 if (++rspq->offset < SLIC_RSPQ_BUFSINPAGE) {
3085 #ifndef CONFIG_X86_64
3086 ASSERT(((u32) rspq->rspbuf & 0xFFFFFFE0) ==
3087 (u32) rspq->rspbuf);
3090 ASSERT(rspq->offset == SLIC_RSPQ_BUFSINPAGE);
3091 slic_reg64_write(adapter, &adapter->slic_regs->slic_rbar64,
3092 (rspq->paddr[rspq->pageindex] | SLIC_RSPQ_BUFSINPAGE),
3093 &adapter->slic_regs->slic_addr_upper, 0, DONT_FLUSH);
3094 rspq->pageindex = (++rspq->pageindex) % rspq->num_pages;
3096 rspq->rspbuf = (struct slic_rspbuf *)
3097 rspq->vaddr[rspq->pageindex];
3098 #ifndef CONFIG_X86_64
3099 ASSERT(((u32) rspq->rspbuf & 0xFFFFF000) ==
3100 (u32) rspq->rspbuf);
3103 #ifndef CONFIG_X86_64
3104 ASSERT(((u32) buf & 0xFFFFFFE0) == (u32) buf);
3109 static void slic_cmdqmem_init(struct adapter *adapter)
3111 struct slic_cmdqmem *cmdqmem = &adapter->cmdqmem;
3113 memset(cmdqmem, 0, sizeof(struct slic_cmdqmem));
3116 static void slic_cmdqmem_free(struct adapter *adapter)
3118 struct slic_cmdqmem *cmdqmem = &adapter->cmdqmem;
3121 for (i = 0; i < SLIC_CMDQ_MAXPAGES; i++) {
3122 if (cmdqmem->pages[i]) {
3123 pci_free_consistent(adapter->pcidev,
3125 (void *) cmdqmem->pages[i],
3126 cmdqmem->dma_pages[i]);
3129 memset(cmdqmem, 0, sizeof(struct slic_cmdqmem));
3132 static u32 *slic_cmdqmem_addpage(struct adapter *adapter)
3134 struct slic_cmdqmem *cmdqmem = &adapter->cmdqmem;
3137 if (cmdqmem->pagecnt >= SLIC_CMDQ_MAXPAGES)
3139 pageaddr = pci_alloc_consistent(adapter->pcidev,
3141 &cmdqmem->dma_pages[cmdqmem->pagecnt]);
3144 #ifndef CONFIG_X86_64
3145 ASSERT(((u32) pageaddr & 0xFFFFF000) == (u32) pageaddr);
3147 cmdqmem->pages[cmdqmem->pagecnt] = pageaddr;
3152 static int slic_cmdq_init(struct adapter *adapter)
3157 ASSERT(adapter->state == ADAPT_DOWN);
3158 memset(&adapter->cmdq_all, 0, sizeof(struct slic_cmdqueue));
3159 memset(&adapter->cmdq_free, 0, sizeof(struct slic_cmdqueue));
3160 memset(&adapter->cmdq_done, 0, sizeof(struct slic_cmdqueue));
3161 spin_lock_init(&adapter->cmdq_all.lock.lock);
3162 spin_lock_init(&adapter->cmdq_free.lock.lock);
3163 spin_lock_init(&adapter->cmdq_done.lock.lock);
3164 slic_cmdqmem_init(adapter);
3165 adapter->slic_handle_ix = 1;
3166 for (i = 0; i < SLIC_CMDQ_INITPAGES; i++) {
3167 pageaddr = slic_cmdqmem_addpage(adapter);
3168 #ifndef CONFIG_X86_64
3169 ASSERT(((u32) pageaddr & 0xFFFFF000) == (u32) pageaddr);
3172 slic_cmdq_free(adapter);
3173 return STATUS_FAILURE;
3175 slic_cmdq_addcmdpage(adapter, pageaddr);
3177 adapter->slic_handle_ix = 1;
3179 return STATUS_SUCCESS;
3182 static void slic_cmdq_free(struct adapter *adapter)
3184 struct slic_hostcmd *cmd;
3186 cmd = adapter->cmdq_all.head;
3189 struct sk_buff *tempskb;
3194 dev_kfree_skb_irq(tempskb);
3197 cmd = cmd->next_all;
3199 memset(&adapter->cmdq_all, 0, sizeof(struct slic_cmdqueue));
3200 memset(&adapter->cmdq_free, 0, sizeof(struct slic_cmdqueue));
3201 memset(&adapter->cmdq_done, 0, sizeof(struct slic_cmdqueue));
3202 slic_cmdqmem_free(adapter);
3205 static void slic_cmdq_reset(struct adapter *adapter)
3207 struct slic_hostcmd *hcmd;
3208 struct sk_buff *skb;
3211 spin_lock_irqsave(&adapter->cmdq_free.lock.lock,
3212 adapter->cmdq_free.lock.flags);
3213 spin_lock_irqsave(&adapter->cmdq_done.lock.lock,
3214 adapter->cmdq_done.lock.flags);
3215 outstanding = adapter->cmdq_all.count - adapter->cmdq_done.count;
3216 outstanding -= adapter->cmdq_free.count;
3217 hcmd = adapter->cmdq_all.head;
3224 dev_kfree_skb_irq(skb);
3226 hcmd = hcmd->next_all;
3228 adapter->cmdq_free.count = 0;
3229 adapter->cmdq_free.head = NULL;
3230 adapter->cmdq_free.tail = NULL;
3231 adapter->cmdq_done.count = 0;
3232 adapter->cmdq_done.head = NULL;
3233 adapter->cmdq_done.tail = NULL;
3234 adapter->cmdq_free.head = adapter->cmdq_all.head;
3235 hcmd = adapter->cmdq_all.head;
3237 adapter->cmdq_free.count++;
3238 hcmd->next = hcmd->next_all;
3239 hcmd = hcmd->next_all;
3241 if (adapter->cmdq_free.count != adapter->cmdq_all.count) {
3242 DBG_ERROR("%s free_count %d != all count %d\n", __func__,
3243 adapter->cmdq_free.count, adapter->cmdq_all.count);
3245 spin_unlock_irqrestore(&adapter->cmdq_done.lock.lock,
3246 adapter->cmdq_done.lock.flags);
3247 spin_unlock_irqrestore(&adapter->cmdq_free.lock.lock,
3248 adapter->cmdq_free.lock.flags);
3251 static void slic_cmdq_addcmdpage(struct adapter *adapter, u32 *page)
3253 struct slic_hostcmd *cmd;
3254 struct slic_hostcmd *prev;
3255 struct slic_hostcmd *tail;
3256 struct slic_cmdqueue *cmdq;
3262 struct slic_handle *pslic_handle;
3265 cmd = (struct slic_hostcmd *)cmdaddr;
3268 phys_addr = virt_to_bus((void *)page);
3269 phys_addrl = SLIC_GET_ADDR_LOW(phys_addr);
3270 phys_addrh = SLIC_GET_ADDR_HIGH(phys_addr);
3274 while ((cmdcnt < SLIC_CMDQ_CMDSINPAGE) &&
3275 (adapter->slic_handle_ix < 256)) {
3276 /* Allocate and initialize a SLIC_HANDLE for this command */
3277 SLIC_GET_SLIC_HANDLE(adapter, pslic_handle);
3278 if (pslic_handle == NULL)
3280 ASSERT(pslic_handle ==
3281 &adapter->slic_handles[pslic_handle->token.
3283 pslic_handle->type = SLIC_HANDLE_CMD;
3284 pslic_handle->address = (void *) cmd;
3285 pslic_handle->offset = (ushort) adapter->slic_handle_ix++;
3286 pslic_handle->other_handle = NULL;
3287 pslic_handle->next = NULL;
3289 cmd->pslic_handle = pslic_handle;
3290 cmd->cmd64.hosthandle = pslic_handle->token.handle_token;
3292 cmd->paddrl = phys_addrl;
3293 cmd->paddrh = phys_addrh;
3294 cmd->next_all = prev;
3297 phys_addrl += SLIC_HOSTCMD_SIZE;
3298 cmdaddr += SLIC_HOSTCMD_SIZE;
3300 cmd = (struct slic_hostcmd *)cmdaddr;
3304 cmdq = &adapter->cmdq_all;
3305 cmdq->count += cmdcnt; /* SLIC_CMDQ_CMDSINPAGE; mooktodo */
3306 tail->next_all = cmdq->head;
3308 cmdq = &adapter->cmdq_free;
3309 spin_lock_irqsave(&cmdq->lock.lock, cmdq->lock.flags);
3310 cmdq->count += cmdcnt; /* SLIC_CMDQ_CMDSINPAGE; mooktodo */
3311 tail->next = cmdq->head;
3313 spin_unlock_irqrestore(&cmdq->lock.lock, cmdq->lock.flags);
3316 static struct slic_hostcmd *slic_cmdq_getfree(struct adapter *adapter)
3318 struct slic_cmdqueue *cmdq = &adapter->cmdq_free;
3319 struct slic_hostcmd *cmd = NULL;
3322 spin_lock_irqsave(&cmdq->lock.lock, cmdq->lock.flags);
3326 cmdq->head = cmd->next;
3328 spin_unlock_irqrestore(&cmdq->lock.lock, cmdq->lock.flags);
3330 slic_cmdq_getdone(adapter);
3337 spin_unlock_irqrestore(&cmdq->lock.lock,
3339 pageaddr = slic_cmdqmem_addpage(adapter);
3341 slic_cmdq_addcmdpage(adapter, pageaddr);
3342 goto lock_and_retry;
3349 static void slic_cmdq_getdone(struct adapter *adapter)
3351 struct slic_cmdqueue *done_cmdq = &adapter->cmdq_done;
3352 struct slic_cmdqueue *free_cmdq = &adapter->cmdq_free;
3354 ASSERT(free_cmdq->head == NULL);
3355 spin_lock_irqsave(&done_cmdq->lock.lock, done_cmdq->lock.flags);
3357 free_cmdq->head = done_cmdq->head;
3358 free_cmdq->count = done_cmdq->count;
3359 done_cmdq->head = NULL;
3360 done_cmdq->tail = NULL;
3361 done_cmdq->count = 0;
3362 spin_unlock_irqrestore(&done_cmdq->lock.lock, done_cmdq->lock.flags);
3365 static void slic_cmdq_putdone_irq(struct adapter *adapter,
3366 struct slic_hostcmd *cmd)
3368 struct slic_cmdqueue *cmdq = &adapter->cmdq_done;
3370 spin_lock(&cmdq->lock.lock);
3372 cmd->next = cmdq->head;
3375 if ((adapter->xmitq_full) && (cmdq->count > 10))
3376 netif_wake_queue(adapter->netdev);
3377 spin_unlock(&cmdq->lock.lock);
3380 static int slic_rcvqueue_init(struct adapter *adapter)
3383 struct slic_rcvqueue *rcvq = &adapter->rcvqueue;
3385 ASSERT(adapter->state == ADAPT_DOWN);
3388 rcvq->size = SLIC_RCVQ_ENTRIES;
3391 i = (SLIC_RCVQ_ENTRIES / SLIC_RCVQ_FILLENTRIES);
3394 count += slic_rcvqueue_fill(adapter);
3397 if (rcvq->count < SLIC_RCVQ_MINENTRIES) {
3398 slic_rcvqueue_free(adapter);
3399 return STATUS_FAILURE;
3401 return STATUS_SUCCESS;
3404 static void slic_rcvqueue_free(struct adapter *adapter)
3406 struct slic_rcvqueue *rcvq = &adapter->rcvqueue;
3407 struct sk_buff *skb;
3409 while (rcvq->head) {
3411 rcvq->head = rcvq->head->next;
3419 static struct sk_buff *slic_rcvqueue_getnext(struct adapter *adapter)
3421 struct slic_rcvqueue *rcvq = &adapter->rcvqueue;
3422 struct sk_buff *skb;
3423 struct slic_rcvbuf *rcvbuf;
3428 rcvbuf = (struct slic_rcvbuf *)skb->head;
3431 if (rcvbuf->status & IRHDDR_SVALID) {
3432 rcvq->head = rcvq->head->next;
3439 DBG_ERROR("RcvQ Empty!! adapter[%p] rcvq[%p] count[%x]\n",
3440 adapter, rcvq, rcvq->count);
3443 while (rcvq->count < SLIC_RCVQ_FILLTHRESH) {
3444 count = slic_rcvqueue_fill(adapter);
3453 static int slic_rcvqueue_fill(struct adapter *adapter)
3458 struct slic_rcvqueue *rcvq = &adapter->rcvqueue;
3461 while (i < SLIC_RCVQ_FILLENTRIES) {
3462 struct slic_rcvbuf *rcvbuf;
3463 struct sk_buff *skb;
3464 #ifdef KLUDGE_FOR_4GB_BOUNDARY
3467 skb = alloc_skb(SLIC_RCVQ_RCVBUFSIZE, GFP_ATOMIC);
3469 paddr = (void *)pci_map_single(adapter->pcidev,
3471 SLIC_RCVQ_RCVBUFSIZE,
3472 PCI_DMA_FROMDEVICE);
3473 paddrl = SLIC_GET_ADDR_LOW(paddr);
3474 paddrh = SLIC_GET_ADDR_HIGH(paddr);
3476 skb->len = SLIC_RCVBUF_HEADSIZE;
3477 rcvbuf = (struct slic_rcvbuf *)skb->head;
3480 #ifdef KLUDGE_FOR_4GB_BOUNDARY
3483 ("%s: LOW 32bits PHYSICAL ADDRESS == 0 "
3489 " paddrh[%x]\n", __func__, skb,
3490 skb->data, skb->len, paddr, paddrl,
3492 DBG_ERROR(" rcvq->head[%p]\n"
3494 " rcvq->count[%x]\n",
3495 rcvq->head, rcvq->tail, rcvq->count);
3496 DBG_ERROR("SKIP THIS SKB!!!!!!!!\n");
3497 goto retry_rcvqfill;
3502 ("\n\n%s: LOW 32bits PHYSICAL ADDRESS == 0 "
3503 "skb[%p] GIVE TO CARD ANYWAY\n"
3507 " paddrh[%x]\n", __func__, skb,
3508 skb->data, paddr, paddrl, paddrh);
3512 slic_reg32_write(&adapter->slic_regs->slic_hbar,
3513 (u32)paddrl, DONT_FLUSH);
3515 slic_reg64_write(adapter,
3516 &adapter->slic_regs->slic_hbar64,
3518 &adapter->slic_regs->slic_addr_upper,
3519 paddrh, DONT_FLUSH);
3522 rcvq->tail->next = skb;
3530 ("%s slic_rcvqueue_fill could only get [%d] "
3532 adapter->netdev->name, i);
3539 static u32 slic_rcvqueue_reinsert(struct adapter *adapter, struct sk_buff *skb)
3541 struct slic_rcvqueue *rcvq = &adapter->rcvqueue;
3545 struct slic_rcvbuf *rcvbuf = (struct slic_rcvbuf *)skb->head;
3547 ASSERT(skb->len == SLIC_RCVBUF_HEADSIZE);
3549 paddr = (void *)pci_map_single(adapter->pcidev, skb->head,
3550 SLIC_RCVQ_RCVBUFSIZE, PCI_DMA_FROMDEVICE);
3554 paddrl = SLIC_GET_ADDR_LOW(paddr);
3555 paddrh = SLIC_GET_ADDR_HIGH(paddr);
3559 ("%s: LOW 32bits PHYSICAL ADDRESS == 0 skb[%p] PROBLEM\n"
3560 " skbdata[%p]\n" " skblen[%x]\n"
3561 " paddr[%p]\n" " paddrl[%x]\n"
3562 " paddrh[%x]\n", __func__, skb, skb->data,
3563 skb->len, paddr, paddrl, paddrh);
3564 DBG_ERROR(" rcvq->head[%p]\n"
3566 " rcvq->count[%x]\n", rcvq->head, rcvq->tail,
3570 slic_reg32_write(&adapter->slic_regs->slic_hbar, (u32)paddrl,
3573 slic_reg64_write(adapter, &adapter->slic_regs->slic_hbar64,
3574 paddrl, &adapter->slic_regs->slic_addr_upper,
3575 paddrh, DONT_FLUSH);
3578 rcvq->tail->next = skb;
3586 static int slic_debug_card_show(struct seq_file *seq, void *v)
3590 struct sliccard *card = seq->private;
3591 struct slic_config *config = &card->config;
3592 unsigned char *fru = (unsigned char *)(&card->config.atk_fru);
3593 unsigned char *oemfru = (unsigned char *)(&card->config.OemFru);
3596 seq_printf(seq, "driver_version : %s\n", slic_proc_version);
3597 seq_printf(seq, "Microcode versions: \n");
3598 seq_printf(seq, " Gigabit (gb) : %s %s\n",
3599 MOJAVE_UCODE_VERS_STRING, MOJAVE_UCODE_VERS_DATE);
3600 seq_printf(seq, " Gigabit Receiver : %s %s\n",
3601 GB_RCVUCODE_VERS_STRING, GB_RCVUCODE_VERS_DATE);
3602 seq_printf(seq, "Vendor : %s\n", slic_vendor);
3603 seq_printf(seq, "Product Name : %s\n", slic_product_name);
3605 seq_printf(seq, "VendorId : %4.4X\n",
3607 seq_printf(seq, "DeviceId : %4.4X\n",
3609 seq_printf(seq, "RevisionId : %2.2x\n",
3610 config->RevisionId);
3611 seq_printf(seq, "Bus # : %d\n", card->busnumber);
3612 seq_printf(seq, "Device # : %d\n", card->slotnumber);
3613 seq_printf(seq, "Interfaces : %d\n", card->card_size);
3614 seq_printf(seq, " Initialized : %d\n",
3615 card->adapters_activated);
3616 seq_printf(seq, " Allocated : %d\n",
3617 card->adapters_allocated);
3618 ASSERT(card->card_size <= SLIC_NBR_MACS);
3619 for (i = 0; i < card->card_size; i++) {
3621 " MAC%d : %2.2X %2.2X %2.2X %2.2X %2.2X %2.2X\n",
3622 i, config->macinfo[i].macaddrA[0],
3623 config->macinfo[i].macaddrA[1],
3624 config->macinfo[i].macaddrA[2],
3625 config->macinfo[i].macaddrA[3],
3626 config->macinfo[i].macaddrA[4],
3627 config->macinfo[i].macaddrA[5]);
3629 seq_printf(seq, " IF Init State Duplex/Speed irq\n");
3630 seq_printf(seq, " -------------------------------\n");
3631 for (i = 0; i < card->adapters_allocated; i++) {
3632 struct adapter *adapter;
3634 adapter = card->adapter[i];
3637 " %d %d %s %s %s 0x%X\n",
3638 adapter->physport, adapter->state,
3639 SLIC_LINKSTATE(adapter->linkstate),
3640 SLIC_DUPLEX(adapter->linkduplex),
3641 SLIC_SPEED(adapter->linkspeed),
3642 (uint) adapter->irq);
3645 seq_printf(seq, "Generation # : %4.4X\n", card->gennumber);
3646 seq_printf(seq, "RcvQ max entries : %4.4X\n",
3648 seq_printf(seq, "Ping Status : %8.8X\n",
3650 seq_printf(seq, "Minimum grant : %2.2x\n",
3652 seq_printf(seq, "Maximum Latency : %2.2x\n", config->MaxLat);
3653 seq_printf(seq, "PciStatus : %4.4x\n",
3655 seq_printf(seq, "Debug Device Id : %4.4x\n",
3657 seq_printf(seq, "DRAM ROM Function : %4.4x\n",
3659 seq_printf(seq, "Network interface Pin 1 : %2.2x\n",
3660 config->NetIntPin1);
3661 seq_printf(seq, "Network interface Pin 2 : %2.2x\n",
3662 config->NetIntPin1);
3663 seq_printf(seq, "Network interface Pin 3 : %2.2x\n",
3664 config->NetIntPin1);
3665 seq_printf(seq, "PM capabilities : %4.4X\n",
3667 seq_printf(seq, "Network Clock Controls : %4.4X\n",
3668 config->NwClkCtrls);
3670 switch (config->FruFormat) {
3671 case ATK_FRU_FORMAT:
3674 "Vendor : Alacritech, Inc.\n");
3676 "Assembly # : %c%c%c%c%c%c\n",
3677 fru[0], fru[1], fru[2], fru[3], fru[4],
3680 "Revision # : %c%c\n",
3683 if (config->OEMFruFormat == VENDOR4_FRU_FORMAT) {
3686 "%c%c%c%c%c%c%c%c%c%c%c%c\n",
3687 fru[8], fru[9], fru[10],
3688 fru[11], fru[12], fru[13],
3689 fru[16], fru[17], fru[18],
3690 fru[19], fru[20], fru[21]);
3694 "%c%c%c%c%c%c%c%c%c%c%c%c%c%c\n",
3695 fru[8], fru[9], fru[10],
3696 fru[11], fru[12], fru[13],
3697 fru[14], fru[15], fru[16],
3698 fru[17], fru[18], fru[19],
3707 "Vendor : Alacritech, Inc.\n");
3709 "Serial # : Empty FRU\n");
3714 switch (config->OEMFruFormat) {
3715 case VENDOR1_FRU_FORMAT:
3717 seq_printf(seq, "FRU Information:\n");
3718 seq_printf(seq, " Commodity # : %c\n",
3721 " Assembly # : %c%c%c%c\n",
3722 oemfru[1], oemfru[2], oemfru[3], oemfru[4]);
3724 " Revision # : %c%c\n",
3725 oemfru[5], oemfru[6]);
3727 " Supplier # : %c%c\n",
3728 oemfru[7], oemfru[8]);
3731 oemfru[9], oemfru[10]);
3733 " Sequence # : %c%c%c\n",
3734 oemfru[11], oemfru[12], oemfru[13]);
3738 case VENDOR2_FRU_FORMAT:
3740 seq_printf(seq, "FRU Information:\n");
3743 "%c%c%c%c%c%c%c%c\n",
3744 oemfru[0], oemfru[1], oemfru[2],
3745 oemfru[3], oemfru[4], oemfru[5],
3746 oemfru[6], oemfru[7]);
3748 " Supplier # : %c%c%c%c%c\n",
3749 oemfru[8], oemfru[9], oemfru[10],
3750 oemfru[11], oemfru[12]);
3753 oemfru[13], oemfru[14], oemfru[15]);
3755 " Sequence # : %c%c%c%c\n",
3756 oemfru[16], oemfru[17], oemfru[18],
3761 case VENDOR3_FRU_FORMAT:
3763 seq_printf(seq, "FRU Information:\n");
3766 case VENDOR4_FRU_FORMAT:
3768 seq_printf(seq, "FRU Information:\n");
3771 "%c%c%c%c%c%c%c%c\n",
3772 oemfru[0], oemfru[1], oemfru[2],
3773 oemfru[3], oemfru[4], oemfru[5],
3774 oemfru[6], oemfru[7]);
3777 "%c%c%c%c%c%c%c%c\n",
3778 oemfru[8], oemfru[9], oemfru[10],
3779 oemfru[11], oemfru[12], oemfru[13],
3780 oemfru[14], oemfru[15]);
3783 "%c%c%c%c%c%c%c%c\n",
3784 oemfru[16], oemfru[17], oemfru[18],
3785 oemfru[19], oemfru[20], oemfru[21],
3786 oemfru[22], oemfru[23]);
3798 static int slic_debug_adapter_show(struct seq_file *seq, void *v)
3800 struct adapter *adapter = seq->private;
3802 if ((adapter->netdev) && (adapter->netdev->name)) {
3803 seq_printf(seq, "info: interface : %s\n",
3804 adapter->netdev->name);
3806 seq_printf(seq, "info: status : %s\n",
3807 SLIC_LINKSTATE(adapter->linkstate));
3808 seq_printf(seq, "info: port : %d\n",
3810 seq_printf(seq, "info: speed : %s\n",
3811 SLIC_SPEED(adapter->linkspeed));
3812 seq_printf(seq, "info: duplex : %s\n",
3813 SLIC_DUPLEX(adapter->linkduplex));
3814 seq_printf(seq, "info: irq : 0x%X\n",
3815 (uint) adapter->irq);
3816 seq_printf(seq, "info: Interrupt Agg Delay: %d usec\n",
3817 adapter->card->loadlevel_current);
3818 seq_printf(seq, "info: RcvQ max entries : %4.4X\n",
3820 seq_printf(seq, "info: RcvQ current : %4.4X\n",
3821 adapter->rcvqueue.count);
3822 seq_printf(seq, "rx stats: packets : %8.8lX\n",
3823 adapter->stats.rx_packets);
3824 seq_printf(seq, "rx stats: bytes : %8.8lX\n",
3825 adapter->stats.rx_bytes);
3826 seq_printf(seq, "rx stats: broadcasts : %8.8X\n",
3827 adapter->rcv_broadcasts);
3828 seq_printf(seq, "rx stats: multicasts : %8.8X\n",
3829 adapter->rcv_multicasts);
3830 seq_printf(seq, "rx stats: unicasts : %8.8X\n",
3831 adapter->rcv_unicasts);
3832 seq_printf(seq, "rx stats: errors : %8.8X\n",
3833 (u32) adapter->slic_stats.iface.rcv_errors);
3834 seq_printf(seq, "rx stats: Missed errors : %8.8X\n",
3835 (u32) adapter->slic_stats.iface.rcv_discards);
3836 seq_printf(seq, "rx stats: drops : %8.8X\n",
3837 (u32) adapter->rcv_drops);
3838 seq_printf(seq, "tx stats: packets : %8.8lX\n",
3839 adapter->stats.tx_packets);
3840 seq_printf(seq, "tx stats: bytes : %8.8lX\n",
3841 adapter->stats.tx_bytes);
3842 seq_printf(seq, "tx stats: errors : %8.8X\n",
3843 (u32) adapter->slic_stats.iface.xmt_errors);
3844 seq_printf(seq, "rx stats: multicasts : %8.8lX\n",
3845 adapter->stats.multicast);
3846 seq_printf(seq, "tx stats: collision errors : %8.8X\n",
3847 (u32) adapter->slic_stats.iface.xmit_collisions);
3848 seq_printf(seq, "perf: Max rcv frames/isr : %8.8X\n",
3849 adapter->max_isr_rcvs);
3850 seq_printf(seq, "perf: Rcv interrupt yields : %8.8X\n",
3851 adapter->rcv_interrupt_yields);
3852 seq_printf(seq, "perf: Max xmit complete/isr : %8.8X\n",
3853 adapter->max_isr_xmits);
3854 seq_printf(seq, "perf: error interrupts : %8.8X\n",
3855 adapter->error_interrupts);
3856 seq_printf(seq, "perf: error rmiss interrupts : %8.8X\n",
3857 adapter->error_rmiss_interrupts);
3858 seq_printf(seq, "perf: rcv interrupts : %8.8X\n",
3859 adapter->rcv_interrupts);
3860 seq_printf(seq, "perf: xmit interrupts : %8.8X\n",
3861 adapter->xmit_interrupts);
3862 seq_printf(seq, "perf: link event interrupts : %8.8X\n",
3863 adapter->linkevent_interrupts);
3864 seq_printf(seq, "perf: UPR interrupts : %8.8X\n",
3865 adapter->upr_interrupts);
3866 seq_printf(seq, "perf: interrupt count : %8.8X\n",
3868 seq_printf(seq, "perf: false interrupts : %8.8X\n",
3869 adapter->false_interrupts);
3870 seq_printf(seq, "perf: All register writes : %8.8X\n",
3871 adapter->all_reg_writes);
3872 seq_printf(seq, "perf: ICR register writes : %8.8X\n",
3873 adapter->icr_reg_writes);
3874 seq_printf(seq, "perf: ISR register writes : %8.8X\n",
3875 adapter->isr_reg_writes);
3876 seq_printf(seq, "ifevents: overflow 802 errors : %8.8X\n",
3877 adapter->if_events.oflow802);
3878 seq_printf(seq, "ifevents: transport overflow errors: %8.8X\n",
3879 adapter->if_events.Tprtoflow);
3880 seq_printf(seq, "ifevents: underflow errors : %8.8X\n",
3881 adapter->if_events.uflow802);
3882 seq_printf(seq, "ifevents: receive early : %8.8X\n",
3883 adapter->if_events.rcvearly);
3884 seq_printf(seq, "ifevents: buffer overflows : %8.8X\n",
3885 adapter->if_events.Bufov);
3886 seq_printf(seq, "ifevents: carrier errors : %8.8X\n",
3887 adapter->if_events.Carre);
3888 seq_printf(seq, "ifevents: Long : %8.8X\n",
3889 adapter->if_events.Longe);
3890 seq_printf(seq, "ifevents: invalid preambles : %8.8X\n",
3891 adapter->if_events.Invp);
3892 seq_printf(seq, "ifevents: CRC errors : %8.8X\n",
3893 adapter->if_events.Crc);
3894 seq_printf(seq, "ifevents: dribble nibbles : %8.8X\n",
3895 adapter->if_events.Drbl);
3896 seq_printf(seq, "ifevents: Code violations : %8.8X\n",
3897 adapter->if_events.Code);
3898 seq_printf(seq, "ifevents: TCP checksum errors : %8.8X\n",
3899 adapter->if_events.TpCsum);
3900 seq_printf(seq, "ifevents: TCP header short errors : %8.8X\n",
3901 adapter->if_events.TpHlen);
3902 seq_printf(seq, "ifevents: IP checksum errors : %8.8X\n",
3903 adapter->if_events.IpCsum);
3904 seq_printf(seq, "ifevents: IP frame incompletes : %8.8X\n",
3905 adapter->if_events.IpLen);
3906 seq_printf(seq, "ifevents: IP headers shorts : %8.8X\n",
3907 adapter->if_events.IpHlen);
3911 static int slic_debug_adapter_open(struct inode *inode, struct file *file)
3913 return single_open(file, slic_debug_adapter_show, inode->i_private);
3916 static int slic_debug_card_open(struct inode *inode, struct file *file)
3918 return single_open(file, slic_debug_card_show, inode->i_private);
3921 static const struct file_operations slic_debug_adapter_fops = {
3922 .owner = THIS_MODULE,
3923 .open = slic_debug_adapter_open,
3925 .llseek = seq_lseek,
3926 .release = single_release,
3929 static const struct file_operations slic_debug_card_fops = {
3930 .owner = THIS_MODULE,
3931 .open = slic_debug_card_open,
3933 .llseek = seq_lseek,
3934 .release = single_release,
3937 static void slic_debug_adapter_create(struct adapter *adapter)
3941 struct sliccard *card = adapter->card;
3943 if (!card->debugfs_dir)
3946 sprintf(name, "port%d", adapter->port);
3947 d = debugfs_create_file(name, S_IRUGO,
3948 card->debugfs_dir, adapter,
3949 &slic_debug_adapter_fops);
3950 if (!d || IS_ERR(d))
3951 pr_info(PFX "%s: debugfs create failed\n", name);
3953 adapter->debugfs_entry = d;
3956 static void slic_debug_adapter_destroy(struct adapter *adapter)
3958 if (adapter->debugfs_entry) {
3959 debugfs_remove(adapter->debugfs_entry);
3960 adapter->debugfs_entry = NULL;
3964 static void slic_debug_card_create(struct sliccard *card)
3967 char name[IFNAMSIZ];
3969 snprintf(name, sizeof(name), "slic%d", card->cardnum);
3970 d = debugfs_create_dir(name, slic_debugfs);
3971 if (!d || IS_ERR(d))
3972 pr_info(PFX "%s: debugfs create dir failed\n",
3975 card->debugfs_dir = d;
3976 d = debugfs_create_file("cardinfo", S_IRUGO,
3978 &slic_debug_card_fops);
3979 if (!d || IS_ERR(d))
3980 pr_info(PFX "%s: debugfs create failed\n",
3983 card->debugfs_cardinfo = d;
3987 static void slic_debug_card_destroy(struct sliccard *card)
3991 for (i = 0; i < card->card_size; i++) {
3992 struct adapter *adapter;
3994 adapter = card->adapter[i];
3996 slic_debug_adapter_destroy(adapter);
3998 if (card->debugfs_cardinfo) {
3999 debugfs_remove(card->debugfs_cardinfo);
4000 card->debugfs_cardinfo = NULL;
4002 if (card->debugfs_dir) {
4003 debugfs_remove(card->debugfs_dir);
4004 card->debugfs_dir = NULL;
4008 static void slic_debug_init(void)
4012 ent = debugfs_create_dir("slic", NULL);
4013 if (!ent || IS_ERR(ent)) {
4014 pr_info(PFX "debugfs create directory failed\n");
4021 static void slic_debug_cleanup(void)
4024 debugfs_remove(slic_debugfs);
4025 slic_debugfs = NULL;
4029 /******************************************************************************/
4030 /**************** MODULE INITIATION / TERMINATION FUNCTIONS ***************/
4031 /******************************************************************************/
4033 static struct pci_driver slic_driver = {
4035 .id_table = slic_pci_tbl,
4036 .probe = slic_entry_probe,
4037 .remove = slic_entry_remove,
4040 static int __init slic_module_init(void)
4044 if (debug >= 0 && slic_debug != debug)
4045 printk(SLICLEVEL "slicoss: debug level is %d.\n", debug);
4049 return pci_register_driver(&slic_driver);
4052 static void __exit slic_module_cleanup(void)
4054 pci_unregister_driver(&slic_driver);
4055 slic_debug_cleanup();
4058 module_init(slic_module_init);
4059 module_exit(slic_module_cleanup);