1 /**************************************************************************
3 * Copyright 2000-2006 Alacritech, Inc. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above
12 * copyright notice, this list of conditions and the following
13 * disclaimer in the documentation and/or other materials provided
14 * with the distribution.
16 * Alternatively, this software may be distributed under the terms of the
17 * GNU General Public License ("GPL") version 2 as published by the Free
18 * Software Foundation.
20 * THIS SOFTWARE IS PROVIDED BY ALACRITECH, INC. ``AS IS'' AND ANY
21 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ALACRITECH, INC. OR
24 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
27 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
28 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
30 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 * The views and conclusions contained in the software and documentation
34 * are those of the authors and should not be interpreted as representing
35 * official policies, either expressed or implied, of Alacritech, Inc.
37 **************************************************************************/
42 * The SLICOSS driver for Alacritech's IS-NIC products.
44 * This driver is supposed to support:
46 * Mojave cards (single port PCI Gigabit) both copper and fiber
47 * Oasis cards (single and dual port PCI-x Gigabit) copper and fiber
48 * Kalahari cards (dual and quad port PCI-e Gigabit) copper and fiber
50 * The driver was acutally tested on Oasis and Kalahari cards.
53 * NOTE: This is the standard, non-accelerated version of Alacritech's
58 #define KLUDGE_FOR_4GB_BOUNDARY 1
59 #define DEBUG_MICROCODE 1
61 #define SLIC_INTERRUPT_PROCESS_LIMIT 1
62 #define SLIC_OFFLOAD_IP_CHECKSUM 1
63 #define STATS_TIMER_INTERVAL 2
64 #define PING_TIMER_INTERVAL 1
66 #include <linux/kernel.h>
67 #include <linux/string.h>
68 #include <linux/errno.h>
69 #include <linux/ioport.h>
70 #include <linux/slab.h>
71 #include <linux/interrupt.h>
72 #include <linux/timer.h>
73 #include <linux/pci.h>
74 #include <linux/spinlock.h>
75 #include <linux/init.h>
76 #include <linux/bitops.h>
78 #include <linux/netdevice.h>
79 #include <linux/etherdevice.h>
80 #include <linux/skbuff.h>
81 #include <linux/delay.h>
82 #include <linux/debugfs.h>
83 #include <linux/seq_file.h>
84 #include <linux/kthread.h>
85 #include <linux/module.h>
86 #include <linux/moduleparam.h>
88 #include <linux/firmware.h>
89 #include <linux/types.h>
90 #include <linux/dma-mapping.h>
91 #include <linux/mii.h>
92 #include <linux/if_vlan.h>
93 #include <asm/unaligned.h>
95 #include <linux/ethtool.h>
96 #include <linux/uaccess.h>
100 static struct net_device_stats *slic_get_stats(struct net_device *dev);
101 static int slic_entry_open(struct net_device *dev);
102 static int slic_entry_halt(struct net_device *dev);
103 static int slic_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
104 static int slic_xmit_start(struct sk_buff *skb, struct net_device *dev);
105 static void slic_xmit_fail(struct adapter *adapter, struct sk_buff *skb,
106 void *cmd, u32 skbtype, u32 status);
107 static void slic_config_pci(struct pci_dev *pcidev);
108 static struct sk_buff *slic_rcvqueue_getnext(struct adapter *adapter);
109 static int slic_mac_set_address(struct net_device *dev, void *ptr);
110 static void slic_link_event_handler(struct adapter *adapter);
111 static void slic_upr_request_complete(struct adapter *adapter, u32 isr);
112 static int slic_rspqueue_init(struct adapter *adapter);
113 static void slic_rspqueue_free(struct adapter *adapter);
114 static struct slic_rspbuf *slic_rspqueue_getnext(struct adapter *adapter);
115 static int slic_cmdq_init(struct adapter *adapter);
116 static void slic_cmdq_free(struct adapter *adapter);
117 static void slic_cmdq_reset(struct adapter *adapter);
118 static void slic_cmdq_addcmdpage(struct adapter *adapter, u32 *page);
119 static void slic_cmdq_getdone(struct adapter *adapter);
120 static void slic_cmdq_putdone_irq(struct adapter *adapter,
121 struct slic_hostcmd *cmd);
122 static struct slic_hostcmd *slic_cmdq_getfree(struct adapter *adapter);
123 static int slic_rcvqueue_init(struct adapter *adapter);
124 static int slic_rcvqueue_fill(struct adapter *adapter);
125 static u32 slic_rcvqueue_reinsert(struct adapter *adapter, struct sk_buff *skb);
126 static void slic_rcvqueue_free(struct adapter *adapter);
127 static void slic_adapter_set_hwaddr(struct adapter *adapter);
128 static int slic_card_init(struct sliccard *card, struct adapter *adapter);
129 static void slic_intagg_set(struct adapter *adapter, u32 value);
130 static int slic_card_download(struct adapter *adapter);
131 static u32 slic_card_locate(struct adapter *adapter);
132 static int slic_if_init(struct adapter *adapter);
133 static int slic_adapter_allocresources(struct adapter *adapter);
134 static void slic_adapter_freeresources(struct adapter *adapter);
135 static void slic_link_config(struct adapter *adapter, u32 linkspeed,
137 static void slic_unmap_mmio_space(struct adapter *adapter);
138 static void slic_card_cleanup(struct sliccard *card);
139 static void slic_soft_reset(struct adapter *adapter);
140 static bool slic_mac_filter(struct adapter *adapter,
141 struct ether_header *ether_frame);
142 static void slic_mac_address_config(struct adapter *adapter);
143 static void slic_mac_config(struct adapter *adapter);
144 static void slic_mcast_set_mask(struct adapter *adapter);
145 static void slic_config_set(struct adapter *adapter, bool linkchange);
146 static void slic_config_clear(struct adapter *adapter);
147 static void slic_config_get(struct adapter *adapter, u32 config,
149 static void slic_timer_load_check(ulong context);
150 static void slic_assert_fail(void);
151 static ushort slic_eeprom_cksum(char *m, int len);
152 static void slic_upr_start(struct adapter *adapter);
153 static void slic_link_upr_complete(struct adapter *adapter, u32 Isr);
154 static int slic_upr_request(struct adapter *adapter, u32 upr_request,
155 u32 upr_data, u32 upr_data_h, u32 upr_buffer,
157 static void slic_mcast_set_list(struct net_device *dev);
160 static uint slic_first_init = 1;
161 static char *slic_banner = "Alacritech SLIC Technology(tm) Server "\
162 "and Storage Accelerator (Non-Accelerated)";
164 static char *slic_proc_version = "2.0.351 2006/07/14 12:26:00";
165 static char *slic_product_name = "SLIC Technology(tm) Server "\
166 "and Storage Accelerator (Non-Accelerated)";
167 static char *slic_vendor = "Alacritech, Inc.";
169 static int slic_debug = 1;
170 static int debug = -1;
171 static struct net_device *head_netdevice;
173 static struct base_driver slic_global = { {}, 0, 0, 0, 1, NULL, NULL };
174 static int intagg_delay = 100;
175 static u32 dynamic_intagg;
176 static unsigned int rcv_count;
177 static struct dentry *slic_debugfs;
179 #define DRV_NAME "slicoss"
180 #define DRV_VERSION "2.0.1"
181 #define DRV_AUTHOR "Alacritech, Inc. Engineering"
182 #define DRV_DESCRIPTION "Alacritech SLIC Techonology(tm) "\
183 "Non-Accelerated Driver"
184 #define DRV_COPYRIGHT "Copyright 2000-2006 Alacritech, Inc. "\
185 "All rights reserved."
186 #define PFX DRV_NAME " "
188 MODULE_AUTHOR(DRV_AUTHOR);
189 MODULE_DESCRIPTION(DRV_DESCRIPTION);
190 MODULE_LICENSE("Dual BSD/GPL");
192 module_param(dynamic_intagg, int, 0);
193 MODULE_PARM_DESC(dynamic_intagg, "Dynamic Interrupt Aggregation Setting");
194 module_param(intagg_delay, int, 0);
195 MODULE_PARM_DESC(intagg_delay, "uSec Interrupt Aggregation Delay");
197 static struct pci_device_id slic_pci_tbl[] __devinitdata = {
198 {PCI_VENDOR_ID_ALACRITECH,
200 PCI_ANY_ID, PCI_ANY_ID,},
201 {PCI_VENDOR_ID_ALACRITECH,
203 PCI_ANY_ID, PCI_ANY_ID,},
207 MODULE_DEVICE_TABLE(pci, slic_pci_tbl);
214 #define ASSERT(a) do { \
216 printk(KERN_ERR "slicoss ASSERT() Failure: function %s" \
217 "line %d\n", __func__, __LINE__); \
218 slic_assert_fail(); \
224 #define SLIC_GET_SLIC_HANDLE(_adapter, _pslic_handle) \
226 spin_lock_irqsave(&_adapter->handle_lock.lock, \
227 _adapter->handle_lock.flags); \
228 _pslic_handle = _adapter->pfree_slic_handles; \
229 if (_pslic_handle) { \
230 ASSERT(_pslic_handle->type == SLIC_HANDLE_FREE); \
231 _adapter->pfree_slic_handles = _pslic_handle->next; \
233 spin_unlock_irqrestore(&_adapter->handle_lock.lock, \
234 _adapter->handle_lock.flags); \
237 #define SLIC_FREE_SLIC_HANDLE(_adapter, _pslic_handle) \
239 _pslic_handle->type = SLIC_HANDLE_FREE; \
240 spin_lock_irqsave(&_adapter->handle_lock.lock, \
241 _adapter->handle_lock.flags); \
242 _pslic_handle->next = _adapter->pfree_slic_handles; \
243 _adapter->pfree_slic_handles = _pslic_handle; \
244 spin_unlock_irqrestore(&_adapter->handle_lock.lock, \
245 _adapter->handle_lock.flags); \
248 static void slic_debug_init(void);
249 static void slic_debug_cleanup(void);
250 static void slic_debug_adapter_create(struct adapter *adapter);
251 static void slic_debug_adapter_destroy(struct adapter *adapter);
252 static void slic_debug_card_create(struct sliccard *card);
253 static void slic_debug_card_destroy(struct sliccard *card);
255 static inline void slic_reg32_write(void __iomem *reg, u32 value, bool flush)
262 static inline void slic_reg64_write(struct adapter *adapter, void __iomem *reg,
263 u32 value, void __iomem *regh, u32 paddrh,
266 spin_lock_irqsave(&adapter->bit64reglock.lock,
267 adapter->bit64reglock.flags);
268 if (paddrh != adapter->curaddrupper) {
269 adapter->curaddrupper = paddrh;
270 writel(paddrh, regh);
275 spin_unlock_irqrestore(&adapter->bit64reglock.lock,
276 adapter->bit64reglock.flags);
279 static void slic_init_driver(void)
281 if (slic_first_init) {
283 spin_lock_init(&slic_global.driver_lock.lock);
288 static void slic_init_adapter(struct net_device *netdev,
289 struct pci_dev *pcidev,
290 const struct pci_device_id *pci_tbl_entry,
291 void __iomem *memaddr, int chip_idx)
294 struct slic_handle *pslic_handle;
295 struct adapter *adapter = (struct adapter *)netdev_priv(netdev);
297 /* adapter->pcidev = pcidev;*/
298 adapter->vendid = pci_tbl_entry->vendor;
299 adapter->devid = pci_tbl_entry->device;
300 adapter->subsysid = pci_tbl_entry->subdevice;
301 adapter->busnumber = pcidev->bus->number;
302 adapter->slotnumber = ((pcidev->devfn >> 3) & 0x1F);
303 adapter->functionnumber = (pcidev->devfn & 0x7);
304 adapter->memorylength = pci_resource_len(pcidev, 0);
305 adapter->slic_regs = (__iomem struct slic_regs *)memaddr;
306 adapter->irq = pcidev->irq;
307 /* adapter->netdev = netdev;*/
308 adapter->next_netdevice = head_netdevice;
309 head_netdevice = netdev;
310 adapter->chipid = chip_idx;
311 adapter->port = 0; /*adapter->functionnumber;*/
312 adapter->cardindex = adapter->port;
313 adapter->memorybase = memaddr;
314 spin_lock_init(&adapter->upr_lock.lock);
315 spin_lock_init(&adapter->bit64reglock.lock);
316 spin_lock_init(&adapter->adapter_lock.lock);
317 spin_lock_init(&adapter->reset_lock.lock);
318 spin_lock_init(&adapter->handle_lock.lock);
320 adapter->card_size = 1;
322 Initialize slic_handle array
324 ASSERT(SLIC_CMDQ_MAXCMDS <= 0xFFFF);
326 Start with 1. 0 is an invalid host handle.
328 for (index = 1, pslic_handle = &adapter->slic_handles[1];
329 index < SLIC_CMDQ_MAXCMDS; index++, pslic_handle++) {
331 pslic_handle->token.handle_index = index;
332 pslic_handle->type = SLIC_HANDLE_FREE;
333 pslic_handle->next = adapter->pfree_slic_handles;
334 adapter->pfree_slic_handles = pslic_handle;
336 adapter->pshmem = (struct slic_shmem *)
337 pci_alloc_consistent(adapter->pcidev,
338 sizeof(struct slic_shmem),
341 ASSERT(adapter->pshmem);
343 memset(adapter->pshmem, 0, sizeof(struct slic_shmem));
348 static const struct net_device_ops slic_netdev_ops = {
349 .ndo_open = slic_entry_open,
350 .ndo_stop = slic_entry_halt,
351 .ndo_start_xmit = slic_xmit_start,
352 .ndo_do_ioctl = slic_ioctl,
353 .ndo_set_mac_address = slic_mac_set_address,
354 .ndo_get_stats = slic_get_stats,
355 .ndo_set_multicast_list = slic_mcast_set_list,
356 .ndo_validate_addr = eth_validate_addr,
357 .ndo_set_mac_address = eth_mac_addr,
358 .ndo_change_mtu = eth_change_mtu,
361 static int __devinit slic_entry_probe(struct pci_dev *pcidev,
362 const struct pci_device_id *pci_tbl_entry)
364 static int cards_found;
365 static int did_version;
367 struct net_device *netdev;
368 struct adapter *adapter;
369 void __iomem *memmapped_ioaddr = NULL;
371 ulong mmio_start = 0;
373 struct sliccard *card = NULL;
375 slic_global.dynamic_intagg = dynamic_intagg;
377 err = pci_enable_device(pcidev);
382 if (slic_debug > 0 && did_version++ == 0) {
383 printk(KERN_DEBUG "%s\n", slic_banner);
384 printk(KERN_DEBUG "%s\n", slic_proc_version);
387 err = pci_set_dma_mask(pcidev, DMA_BIT_MASK(64));
389 err = pci_set_dma_mask(pcidev, DMA_BIT_MASK(32));
391 goto err_out_disable_pci;
394 err = pci_request_regions(pcidev, DRV_NAME);
396 goto err_out_disable_pci;
398 pci_set_master(pcidev);
400 netdev = alloc_etherdev(sizeof(struct adapter));
403 goto err_out_exit_slic_probe;
406 SET_NETDEV_DEV(netdev, &pcidev->dev);
408 pci_set_drvdata(pcidev, netdev);
409 adapter = netdev_priv(netdev);
410 adapter->netdev = netdev;
411 adapter->pcidev = pcidev;
413 mmio_start = pci_resource_start(pcidev, 0);
414 mmio_len = pci_resource_len(pcidev, 0);
417 /* memmapped_ioaddr = (u32)ioremap_nocache(mmio_start, mmio_len);*/
418 memmapped_ioaddr = ioremap(mmio_start, mmio_len);
419 if (!memmapped_ioaddr) {
420 dev_err(&pcidev->dev, "cannot remap MMIO region %lx @ %lx\n",
421 mmio_len, mmio_start);
422 goto err_out_free_netdev;
425 slic_config_pci(pcidev);
429 slic_init_adapter(netdev,
430 pcidev, pci_tbl_entry, memmapped_ioaddr, cards_found);
432 status = slic_card_locate(adapter);
434 dev_err(&pcidev->dev, "cannot locate card\n");
435 goto err_out_free_mmio_region;
438 card = adapter->card;
440 if (!adapter->allocated) {
441 card->adapters_allocated++;
442 adapter->allocated = 1;
445 status = slic_card_init(card, adapter);
447 if (status != STATUS_SUCCESS) {
448 card->state = CARD_FAIL;
449 adapter->state = ADAPT_FAIL;
450 adapter->linkstate = LINK_DOWN;
451 dev_err(&pcidev->dev, "FAILED status[%x]\n", status);
453 slic_adapter_set_hwaddr(adapter);
456 netdev->base_addr = (unsigned long)adapter->memorybase;
457 netdev->irq = adapter->irq;
458 netdev->netdev_ops = &slic_netdev_ops;
460 slic_debug_adapter_create(adapter);
462 strcpy(netdev->name, "eth%d");
463 err = register_netdev(netdev);
465 dev_err(&pcidev->dev, "Cannot register net device, aborting.\n");
474 iounmap(memmapped_ioaddr);
475 err_out_free_mmio_region:
476 release_mem_region(mmio_start, mmio_len);
479 err_out_exit_slic_probe:
480 pci_release_regions(pcidev);
482 pci_disable_device(pcidev);
486 static int slic_entry_open(struct net_device *dev)
488 struct adapter *adapter = (struct adapter *) netdev_priv(dev);
489 struct sliccard *card = adapter->card;
496 netif_stop_queue(adapter->netdev);
498 spin_lock_irqsave(&slic_global.driver_lock.lock,
499 slic_global.driver_lock.flags);
501 if (!adapter->activated) {
502 card->adapters_activated++;
503 slic_global.num_slic_ports_active++;
504 adapter->activated = 1;
506 status = slic_if_init(adapter);
508 if (status != STATUS_SUCCESS) {
509 if (adapter->activated) {
510 card->adapters_activated--;
511 slic_global.num_slic_ports_active--;
512 adapter->activated = 0;
515 spin_unlock_irqrestore(&slic_global.driver_lock.lock,
516 slic_global.driver_lock.flags);
522 card->master = adapter;
525 spin_unlock_irqrestore(&slic_global.driver_lock.lock,
526 slic_global.driver_lock.flags);
530 return STATUS_SUCCESS;
533 static void __devexit slic_entry_remove(struct pci_dev *pcidev)
535 struct net_device *dev = pci_get_drvdata(pcidev);
538 struct adapter *adapter = (struct adapter *) netdev_priv(dev);
539 struct sliccard *card;
540 struct mcast_address *mcaddr, *mlist;
543 slic_adapter_freeresources(adapter);
544 slic_unmap_mmio_space(adapter);
545 unregister_netdev(dev);
547 mmio_start = pci_resource_start(pcidev, 0);
548 mmio_len = pci_resource_len(pcidev, 0);
550 release_mem_region(mmio_start, mmio_len);
552 iounmap((void __iomem *)dev->base_addr);
553 /* free multicast addresses */
554 mlist = adapter->mcastaddrs;
560 ASSERT(adapter->card);
561 card = adapter->card;
562 ASSERT(card->adapters_allocated);
563 card->adapters_allocated--;
564 adapter->allocated = 0;
565 if (!card->adapters_allocated) {
566 struct sliccard *curr_card = slic_global.slic_card;
567 if (curr_card == card) {
568 slic_global.slic_card = card->next;
570 while (curr_card->next != card)
571 curr_card = curr_card->next;
573 curr_card->next = card->next;
575 ASSERT(slic_global.num_slic_cards);
576 slic_global.num_slic_cards--;
577 slic_card_cleanup(card);
580 pci_release_regions(pcidev);
583 static int slic_entry_halt(struct net_device *dev)
585 struct adapter *adapter = (struct adapter *)netdev_priv(dev);
586 struct sliccard *card = adapter->card;
587 __iomem struct slic_regs *slic_regs = adapter->slic_regs;
589 spin_lock_irqsave(&slic_global.driver_lock.lock,
590 slic_global.driver_lock.flags);
592 netif_stop_queue(adapter->netdev);
593 adapter->state = ADAPT_DOWN;
594 adapter->linkstate = LINK_DOWN;
595 adapter->upr_list = NULL;
596 adapter->upr_busy = 0;
597 adapter->devflags_prev = 0;
598 ASSERT(card->adapter[adapter->cardindex] == adapter);
599 slic_reg32_write(&slic_regs->slic_icr, ICR_INT_OFF, FLUSH);
600 adapter->all_reg_writes++;
601 adapter->icr_reg_writes++;
602 slic_config_clear(adapter);
603 if (adapter->activated) {
604 card->adapters_activated--;
605 slic_global.num_slic_ports_active--;
606 adapter->activated = 0;
608 #ifdef AUTOMATIC_RESET
609 slic_reg32_write(&slic_regs->slic_reset_iface, 0, FLUSH);
612 * Reset the adapter's cmd queues
614 slic_cmdq_reset(adapter);
616 #ifdef AUTOMATIC_RESET
617 if (!card->adapters_activated)
618 slic_card_init(card, adapter);
621 spin_unlock_irqrestore(&slic_global.driver_lock.lock,
622 slic_global.driver_lock.flags);
623 return STATUS_SUCCESS;
626 static int slic_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
628 struct adapter *adapter = (struct adapter *)netdev_priv(dev);
629 struct ethtool_cmd edata;
630 struct ethtool_cmd ecmd;
636 case SIOCSLICSETINTAGG:
637 if (copy_from_user(data, rq->ifr_data, 28))
640 dev_err(&dev->dev, "%s: set interrupt aggregation to %d\n",
642 slic_intagg_set(adapter, intagg);
645 #ifdef SLIC_TRACE_DUMP_ENABLED
646 case SIOCSLICTRACEDUMP:
649 DBG_IOCTL("slic_ioctl SIOCSLIC_TRACE_DUMP\n");
651 if (copy_from_user(data, rq->ifr_data, 28)) {
653 ("slic: copy_from_user FAILED getting \
654 initial simba param\n");
659 if (tracemon_request == SLIC_DUMP_DONE) {
661 ("ATK Diagnostic Trace Dump Requested\n");
662 tracemon_request = SLIC_DUMP_REQUESTED;
663 tracemon_request_type = value;
664 tracemon_timestamp = jiffies;
665 } else if ((tracemon_request == SLIC_DUMP_REQUESTED) ||
667 SLIC_DUMP_IN_PROGRESS)) {
669 ("ATK Diagnostic Trace Dump Requested but \
670 already in progress... ignore\n");
673 ("ATK Diagnostic Trace Dump Requested\n");
674 tracemon_request = SLIC_DUMP_REQUESTED;
675 tracemon_request_type = value;
676 tracemon_timestamp = jiffies;
683 if (copy_from_user(&ecmd, rq->ifr_data, sizeof(ecmd)))
686 if (ecmd.cmd == ETHTOOL_GSET) {
687 edata.supported = (SUPPORTED_10baseT_Half |
688 SUPPORTED_10baseT_Full |
689 SUPPORTED_100baseT_Half |
690 SUPPORTED_100baseT_Full |
691 SUPPORTED_Autoneg | SUPPORTED_MII);
692 edata.port = PORT_MII;
693 edata.transceiver = XCVR_INTERNAL;
694 edata.phy_address = 0;
695 if (adapter->linkspeed == LINK_100MB)
696 edata.speed = SPEED_100;
697 else if (adapter->linkspeed == LINK_10MB)
698 edata.speed = SPEED_10;
702 if (adapter->linkduplex == LINK_FULLD)
703 edata.duplex = DUPLEX_FULL;
705 edata.duplex = DUPLEX_HALF;
707 edata.autoneg = AUTONEG_ENABLE;
710 if (copy_to_user(rq->ifr_data, &edata, sizeof(edata)))
713 } else if (ecmd.cmd == ETHTOOL_SSET) {
714 if (!capable(CAP_NET_ADMIN))
717 if (adapter->linkspeed == LINK_100MB)
718 edata.speed = SPEED_100;
719 else if (adapter->linkspeed == LINK_10MB)
720 edata.speed = SPEED_10;
724 if (adapter->linkduplex == LINK_FULLD)
725 edata.duplex = DUPLEX_FULL;
727 edata.duplex = DUPLEX_HALF;
729 edata.autoneg = AUTONEG_ENABLE;
732 if ((ecmd.speed != edata.speed) ||
733 (ecmd.duplex != edata.duplex)) {
737 if (ecmd.speed == SPEED_10)
740 speed = PCR_SPEED_100;
741 if (ecmd.duplex == DUPLEX_FULL)
742 duplex = PCR_DUPLEX_FULL;
745 slic_link_config(adapter, speed, duplex);
746 slic_link_event_handler(adapter);
755 #define XMIT_FAIL_LINK_STATE 1
756 #define XMIT_FAIL_ZERO_LENGTH 2
757 #define XMIT_FAIL_HOSTCMD_FAIL 3
759 static void slic_xmit_build_request(struct adapter *adapter,
760 struct slic_hostcmd *hcmd, struct sk_buff *skb)
762 struct slic_host64_cmd *ihcmd;
765 ihcmd = &hcmd->cmd64;
767 ihcmd->flags = (adapter->port << IHFLG_IFSHFT);
768 ihcmd->command = IHCMD_XMT_REQ;
769 ihcmd->u.slic_buffers.totlen = skb->len;
770 phys_addr = pci_map_single(adapter->pcidev, skb->data, skb->len,
772 ihcmd->u.slic_buffers.bufs[0].paddrl = SLIC_GET_ADDR_LOW(phys_addr);
773 ihcmd->u.slic_buffers.bufs[0].paddrh = SLIC_GET_ADDR_HIGH(phys_addr);
774 ihcmd->u.slic_buffers.bufs[0].length = skb->len;
775 #if defined(CONFIG_X86_64)
776 hcmd->cmdsize = (u32) ((((u64)&ihcmd->u.slic_buffers.bufs[1] -
777 (u64) hcmd) + 31) >> 5);
778 #elif defined(CONFIG_X86)
779 hcmd->cmdsize = ((((u32) &ihcmd->u.slic_buffers.bufs[1] -
780 (u32) hcmd) + 31) >> 5);
786 #define NORMAL_ETHFRAME 0
788 static int slic_xmit_start(struct sk_buff *skb, struct net_device *dev)
790 struct sliccard *card;
791 struct adapter *adapter = (struct adapter *)netdev_priv(dev);
792 struct slic_hostcmd *hcmd = NULL;
794 u32 skbtype = NORMAL_ETHFRAME;
795 void *offloadcmd = NULL;
797 card = adapter->card;
799 if ((adapter->linkstate != LINK_UP) ||
800 (adapter->state != ADAPT_UP) || (card->state != CARD_UP)) {
801 status = XMIT_FAIL_LINK_STATE;
804 } else if (skb->len == 0) {
805 status = XMIT_FAIL_ZERO_LENGTH;
809 if (skbtype == NORMAL_ETHFRAME) {
810 hcmd = slic_cmdq_getfree(adapter);
812 adapter->xmitq_full = 1;
813 status = XMIT_FAIL_HOSTCMD_FAIL;
816 ASSERT(hcmd->pslic_handle);
817 ASSERT(hcmd->cmd64.hosthandle ==
818 hcmd->pslic_handle->token.handle_token);
821 hcmd->type = SLIC_CMD_DUMB;
822 if (skbtype == NORMAL_ETHFRAME)
823 slic_xmit_build_request(adapter, hcmd, skb);
825 adapter->stats.tx_packets++;
826 adapter->stats.tx_bytes += skb->len;
829 if (adapter->kill_card) {
830 struct slic_host64_cmd ihcmd;
832 ihcmd = &hcmd->cmd64;
834 ihcmd->flags |= 0x40;
835 adapter->kill_card = 0; /* only do this once */
838 if (hcmd->paddrh == 0) {
839 slic_reg32_write(&adapter->slic_regs->slic_cbar,
840 (hcmd->paddrl | hcmd->cmdsize), DONT_FLUSH);
842 slic_reg64_write(adapter, &adapter->slic_regs->slic_cbar64,
843 (hcmd->paddrl | hcmd->cmdsize),
844 &adapter->slic_regs->slic_addr_upper,
845 hcmd->paddrh, DONT_FLUSH);
850 slic_xmit_fail(adapter, skb, offloadcmd, skbtype, status);
854 static void slic_xmit_fail(struct adapter *adapter,
856 void *cmd, u32 skbtype, u32 status)
858 if (adapter->xmitq_full)
859 netif_stop_queue(adapter->netdev);
860 if ((cmd == NULL) && (status <= XMIT_FAIL_HOSTCMD_FAIL)) {
862 case XMIT_FAIL_LINK_STATE:
863 dev_err(&adapter->netdev->dev,
864 "reject xmit skb[%p: %x] linkstate[%s] "
865 "adapter[%s:%d] card[%s:%d]\n",
867 SLIC_LINKSTATE(adapter->linkstate),
868 SLIC_ADAPTER_STATE(adapter->state),
870 SLIC_CARD_STATE(adapter->card->state),
871 adapter->card->state);
873 case XMIT_FAIL_ZERO_LENGTH:
874 dev_err(&adapter->netdev->dev,
875 "xmit_start skb->len == 0 skb[%p] type[%x]\n",
878 case XMIT_FAIL_HOSTCMD_FAIL:
879 dev_err(&adapter->netdev->dev,
880 "xmit_start skb[%p] type[%x] No host commands "
881 "available\n", skb, skb->pkt_type);
888 adapter->stats.tx_dropped++;
891 static void slic_rcv_handle_error(struct adapter *adapter,
892 struct slic_rcvbuf *rcvbuf)
894 struct slic_hddr_wds *hdr = (struct slic_hddr_wds *)rcvbuf->data;
896 if (adapter->devid != SLIC_1GB_DEVICE_ID) {
897 if (hdr->frame_status14 & VRHSTAT_802OE)
898 adapter->if_events.oflow802++;
899 if (hdr->frame_status14 & VRHSTAT_TPOFLO)
900 adapter->if_events.Tprtoflow++;
901 if (hdr->frame_status_b14 & VRHSTATB_802UE)
902 adapter->if_events.uflow802++;
903 if (hdr->frame_status_b14 & VRHSTATB_RCVE) {
904 adapter->if_events.rcvearly++;
905 adapter->stats.rx_fifo_errors++;
907 if (hdr->frame_status_b14 & VRHSTATB_BUFF) {
908 adapter->if_events.Bufov++;
909 adapter->stats.rx_over_errors++;
911 if (hdr->frame_status_b14 & VRHSTATB_CARRE) {
912 adapter->if_events.Carre++;
913 adapter->stats.tx_carrier_errors++;
915 if (hdr->frame_status_b14 & VRHSTATB_LONGE)
916 adapter->if_events.Longe++;
917 if (hdr->frame_status_b14 & VRHSTATB_PREA)
918 adapter->if_events.Invp++;
919 if (hdr->frame_status_b14 & VRHSTATB_CRC) {
920 adapter->if_events.Crc++;
921 adapter->stats.rx_crc_errors++;
923 if (hdr->frame_status_b14 & VRHSTATB_DRBL)
924 adapter->if_events.Drbl++;
925 if (hdr->frame_status_b14 & VRHSTATB_CODE)
926 adapter->if_events.Code++;
927 if (hdr->frame_status_b14 & VRHSTATB_TPCSUM)
928 adapter->if_events.TpCsum++;
929 if (hdr->frame_status_b14 & VRHSTATB_TPHLEN)
930 adapter->if_events.TpHlen++;
931 if (hdr->frame_status_b14 & VRHSTATB_IPCSUM)
932 adapter->if_events.IpCsum++;
933 if (hdr->frame_status_b14 & VRHSTATB_IPLERR)
934 adapter->if_events.IpLen++;
935 if (hdr->frame_status_b14 & VRHSTATB_IPHERR)
936 adapter->if_events.IpHlen++;
938 if (hdr->frame_statusGB & VGBSTAT_XPERR) {
939 u32 xerr = hdr->frame_statusGB >> VGBSTAT_XERRSHFT;
941 if (xerr == VGBSTAT_XCSERR)
942 adapter->if_events.TpCsum++;
943 if (xerr == VGBSTAT_XUFLOW)
944 adapter->if_events.Tprtoflow++;
945 if (xerr == VGBSTAT_XHLEN)
946 adapter->if_events.TpHlen++;
948 if (hdr->frame_statusGB & VGBSTAT_NETERR) {
951 frame_statusGB >> VGBSTAT_NERRSHFT) &
953 if (nerr == VGBSTAT_NCSERR)
954 adapter->if_events.IpCsum++;
955 if (nerr == VGBSTAT_NUFLOW)
956 adapter->if_events.IpLen++;
957 if (nerr == VGBSTAT_NHLEN)
958 adapter->if_events.IpHlen++;
960 if (hdr->frame_statusGB & VGBSTAT_LNKERR) {
961 u32 lerr = hdr->frame_statusGB & VGBSTAT_LERRMSK;
963 if (lerr == VGBSTAT_LDEARLY)
964 adapter->if_events.rcvearly++;
965 if (lerr == VGBSTAT_LBOFLO)
966 adapter->if_events.Bufov++;
967 if (lerr == VGBSTAT_LCODERR)
968 adapter->if_events.Code++;
969 if (lerr == VGBSTAT_LDBLNBL)
970 adapter->if_events.Drbl++;
971 if (lerr == VGBSTAT_LCRCERR)
972 adapter->if_events.Crc++;
973 if (lerr == VGBSTAT_LOFLO)
974 adapter->if_events.oflow802++;
975 if (lerr == VGBSTAT_LUFLO)
976 adapter->if_events.uflow802++;
982 #define TCP_OFFLOAD_FRAME_PUSHFLAG 0x10000000
983 #define M_FAST_PATH 0x0040
985 static void slic_rcv_handler(struct adapter *adapter)
988 struct slic_rcvbuf *rcvbuf;
991 while ((skb = slic_rcvqueue_getnext(adapter))) {
995 rcvbuf = (struct slic_rcvbuf *)skb->head;
996 adapter->card->events++;
997 if (rcvbuf->status & IRHDDR_ERR) {
998 adapter->rx_errors++;
999 slic_rcv_handle_error(adapter, rcvbuf);
1000 slic_rcvqueue_reinsert(adapter, skb);
1004 if (!slic_mac_filter(adapter, (struct ether_header *)
1006 slic_rcvqueue_reinsert(adapter, skb);
1009 skb_pull(skb, SLIC_RCVBUF_HEADSIZE);
1010 rx_bytes = (rcvbuf->length & IRHDDR_FLEN_MSK);
1011 skb_put(skb, rx_bytes);
1012 adapter->stats.rx_packets++;
1013 adapter->stats.rx_bytes += rx_bytes;
1014 #if SLIC_OFFLOAD_IP_CHECKSUM
1015 skb->ip_summed = CHECKSUM_UNNECESSARY;
1018 skb->dev = adapter->netdev;
1019 skb->protocol = eth_type_trans(skb, skb->dev);
1023 #if SLIC_INTERRUPT_PROCESS_LIMIT
1024 if (frames >= SLIC_RCVQ_MAX_PROCESS_ISR) {
1025 adapter->rcv_interrupt_yields++;
1030 adapter->max_isr_rcvs = max(adapter->max_isr_rcvs, frames);
1033 static void slic_xmit_complete(struct adapter *adapter)
1035 struct slic_hostcmd *hcmd;
1036 struct slic_rspbuf *rspbuf;
1038 struct slic_handle_word slic_handle_word;
1041 rspbuf = slic_rspqueue_getnext(adapter);
1044 adapter->xmit_completes++;
1045 adapter->card->events++;
1047 Get the complete host command buffer
1049 slic_handle_word.handle_token = rspbuf->hosthandle;
1050 ASSERT(slic_handle_word.handle_index);
1051 ASSERT(slic_handle_word.handle_index <= SLIC_CMDQ_MAXCMDS);
1053 (struct slic_hostcmd *)
1054 adapter->slic_handles[slic_handle_word.handle_index].
1056 /* hcmd = (struct slic_hostcmd *) rspbuf->hosthandle; */
1058 ASSERT(hcmd->pslic_handle ==
1059 &adapter->slic_handles[slic_handle_word.handle_index]);
1060 if (hcmd->type == SLIC_CMD_DUMB) {
1062 dev_kfree_skb_irq(hcmd->skb);
1063 slic_cmdq_putdone_irq(adapter, hcmd);
1066 rspbuf->hosthandle = 0;
1069 adapter->max_isr_xmits = max(adapter->max_isr_xmits, frames);
1072 static irqreturn_t slic_interrupt(int irq, void *dev_id)
1074 struct net_device *dev = (struct net_device *)dev_id;
1075 struct adapter *adapter = (struct adapter *)netdev_priv(dev);
1078 if ((adapter->pshmem) && (adapter->pshmem->isr)) {
1079 slic_reg32_write(&adapter->slic_regs->slic_icr,
1080 ICR_INT_MASK, FLUSH);
1081 isr = adapter->isrcopy = adapter->pshmem->isr;
1082 adapter->pshmem->isr = 0;
1083 adapter->num_isrs++;
1084 switch (adapter->card->state) {
1086 if (isr & ~ISR_IO) {
1087 if (isr & ISR_ERR) {
1088 adapter->error_interrupts++;
1089 if (isr & ISR_RMISS) {
1094 struct slic_rcvqueue *rcvq =
1098 error_rmiss_interrupts++;
1100 rcv_count = rcvq->count;
1101 pre_count = rcvq->count;
1102 errors = rcvq->errors;
1104 while (rcvq->count <
1105 SLIC_RCVQ_FILLTHRESH) {
1112 } else if (isr & ISR_XDROP) {
1114 "isr & ISR_ERR [%x] "
1115 "ISR_XDROP \n", isr);
1118 "isr & ISR_ERR [%x]\n",
1123 if (isr & ISR_LEVENT) {
1124 adapter->linkevent_interrupts++;
1125 slic_link_event_handler(adapter);
1128 if ((isr & ISR_UPC) ||
1129 (isr & ISR_UPCERR) || (isr & ISR_UPCBSY)) {
1130 adapter->upr_interrupts++;
1131 slic_upr_request_complete(adapter, isr);
1135 if (isr & ISR_RCV) {
1136 adapter->rcv_interrupts++;
1137 slic_rcv_handler(adapter);
1140 if (isr & ISR_CMD) {
1141 adapter->xmit_interrupts++;
1142 slic_xmit_complete(adapter);
1147 if ((isr & ISR_UPC) ||
1148 (isr & ISR_UPCERR) || (isr & ISR_UPCBSY)) {
1149 adapter->upr_interrupts++;
1150 slic_upr_request_complete(adapter, isr);
1158 adapter->isrcopy = 0;
1159 adapter->all_reg_writes += 2;
1160 adapter->isr_reg_writes++;
1161 slic_reg32_write(&adapter->slic_regs->slic_isr, 0, FLUSH);
1163 adapter->false_interrupts++;
1169 * slic_link_event_handler -
1171 * Initiate a link configuration sequence. The link configuration begins
1172 * by issuing a READ_LINK_STATUS command to the Utility Processor on the
1173 * SLIC. Since the command finishes asynchronously, the slic_upr_comlete
1174 * routine will follow it up witha UP configuration write command, which
1175 * will also complete asynchronously.
1178 static void slic_link_event_handler(struct adapter *adapter)
1181 struct slic_shmem *pshmem;
1183 if (adapter->state != ADAPT_UP) {
1184 /* Adapter is not operational. Ignore. */
1188 pshmem = (struct slic_shmem *)adapter->phys_shmem;
1190 #if defined(CONFIG_X86_64)
1191 status = slic_upr_request(adapter,
1193 SLIC_GET_ADDR_LOW(&pshmem->linkstatus),
1194 SLIC_GET_ADDR_HIGH(&pshmem->linkstatus),
1196 #elif defined(CONFIG_X86)
1197 status = slic_upr_request(adapter, SLIC_UPR_RLSR,
1198 (u32) &pshmem->linkstatus, /* no 4GB wrap guaranteed */
1203 ASSERT((status == STATUS_SUCCESS) || (status == STATUS_PENDING));
1206 static void slic_init_cleanup(struct adapter *adapter)
1208 if (adapter->intrregistered) {
1209 adapter->intrregistered = 0;
1210 free_irq(adapter->netdev->irq, adapter->netdev);
1213 if (adapter->pshmem) {
1214 pci_free_consistent(adapter->pcidev,
1215 sizeof(struct slic_shmem),
1216 adapter->pshmem, adapter->phys_shmem);
1217 adapter->pshmem = NULL;
1218 adapter->phys_shmem = (dma_addr_t) NULL;
1221 if (adapter->pingtimerset) {
1222 adapter->pingtimerset = 0;
1223 del_timer(&adapter->pingtimer);
1226 slic_rspqueue_free(adapter);
1227 slic_cmdq_free(adapter);
1228 slic_rcvqueue_free(adapter);
1231 static struct net_device_stats *slic_get_stats(struct net_device *dev)
1233 struct adapter *adapter = (struct adapter *)netdev_priv(dev);
1234 struct net_device_stats *stats;
1237 stats = &adapter->stats;
1238 stats->collisions = adapter->slic_stats.iface.xmit_collisions;
1239 stats->rx_errors = adapter->slic_stats.iface.rcv_errors;
1240 stats->tx_errors = adapter->slic_stats.iface.xmt_errors;
1241 stats->rx_missed_errors = adapter->slic_stats.iface.rcv_discards;
1242 stats->tx_heartbeat_errors = 0;
1243 stats->tx_aborted_errors = 0;
1244 stats->tx_window_errors = 0;
1245 stats->tx_fifo_errors = 0;
1246 stats->rx_frame_errors = 0;
1247 stats->rx_length_errors = 0;
1248 return &adapter->stats;
1252 * Allocate a mcast_address structure to hold the multicast address.
1255 static int slic_mcast_add_list(struct adapter *adapter, char *address)
1257 struct mcast_address *mcaddr, *mlist;
1260 /* Check to see if it already exists */
1261 mlist = adapter->mcastaddrs;
1263 ETHER_EQ_ADDR(mlist->address, address, equaladdr);
1265 return STATUS_SUCCESS;
1266 mlist = mlist->next;
1269 /* Doesn't already exist. Allocate a structure to hold it */
1270 mcaddr = kmalloc(sizeof(struct mcast_address), GFP_ATOMIC);
1274 memcpy(mcaddr->address, address, 6);
1276 mcaddr->next = adapter->mcastaddrs;
1277 adapter->mcastaddrs = mcaddr;
1279 return STATUS_SUCCESS;
1283 * Functions to obtain the CRC corresponding to the destination mac address.
1284 * This is a standard ethernet CRC in that it is a 32-bit, reflected CRC using
1286 * x^32 + x^26 + x^23 + x^22 + x^16 + x^12 + x^11 + x^10 + x^8 + x^7 + x^5 +
1289 * After the CRC for the 6 bytes is generated (but before the value is
1291 * we must then transpose the value and return bits 30-23.
1294 static u32 slic_crc_table[256]; /* Table of CRCs for all possible byte values */
1295 static u32 slic_crc_init; /* Is table initialized */
1298 * Contruct the CRC32 table
1300 static void slic_mcast_init_crc32(void)
1302 u32 c; /* CRC shit reg */
1303 u32 e = 0; /* Poly X-or pattern */
1304 int i; /* counter */
1305 int k; /* byte being shifted into crc */
1307 static int p[] = { 0, 1, 2, 4, 5, 7, 8, 10, 11, 12, 16, 22, 23, 26 };
1309 for (i = 0; i < sizeof(p) / sizeof(int); i++)
1310 e |= 1L << (31 - p[i]);
1312 for (i = 1; i < 256; i++) {
1315 c = c & 1 ? (c >> 1) ^ e : c >> 1;
1316 slic_crc_table[i] = c;
1321 * Return the MAC hast as described above.
1323 static unsigned char slic_mcast_get_mac_hash(char *macaddr)
1328 unsigned char machash = 0;
1330 if (!slic_crc_init) {
1331 slic_mcast_init_crc32();
1335 crc = 0xFFFFFFFF; /* Preload shift register, per crc-32 spec */
1336 for (i = 0, p = macaddr; i < 6; ++p, ++i)
1337 crc = (crc >> 8) ^ slic_crc_table[(crc ^ *p) & 0xFF];
1339 /* Return bits 1-8, transposed */
1340 for (i = 1; i < 9; i++)
1341 machash |= (((crc >> i) & 1) << (8 - i));
1346 static void slic_mcast_set_bit(struct adapter *adapter, char *address)
1348 unsigned char crcpoly;
1350 /* Get the CRC polynomial for the mac address */
1351 crcpoly = slic_mcast_get_mac_hash(address);
1353 /* We only have space on the SLIC for 64 entries. Lop
1354 * off the top two bits. (2^6 = 64)
1358 /* OR in the new bit into our 64 bit mask. */
1359 adapter->mcastmask |= (u64) 1 << crcpoly;
1362 static void slic_mcast_set_list(struct net_device *dev)
1364 struct adapter *adapter = (struct adapter *)netdev_priv(dev);
1365 int status = STATUS_SUCCESS;
1368 struct dev_mc_list *mc_list = dev->mc_list;
1369 int mc_count = dev->mc_count;
1373 for (i = 1; i <= mc_count; i++) {
1374 addresses = (char *) &mc_list->dmi_addr;
1375 if (mc_list->dmi_addrlen == 6) {
1376 status = slic_mcast_add_list(adapter, addresses);
1377 if (status != STATUS_SUCCESS)
1383 slic_mcast_set_bit(adapter, addresses);
1384 mc_list = mc_list->next;
1387 if (adapter->devflags_prev != dev->flags) {
1388 adapter->macopts = MAC_DIRECTED;
1390 if (dev->flags & IFF_BROADCAST)
1391 adapter->macopts |= MAC_BCAST;
1392 if (dev->flags & IFF_PROMISC)
1393 adapter->macopts |= MAC_PROMISC;
1394 if (dev->flags & IFF_ALLMULTI)
1395 adapter->macopts |= MAC_ALLMCAST;
1396 if (dev->flags & IFF_MULTICAST)
1397 adapter->macopts |= MAC_MCAST;
1399 adapter->devflags_prev = dev->flags;
1400 slic_config_set(adapter, true);
1402 if (status == STATUS_SUCCESS)
1403 slic_mcast_set_mask(adapter);
1408 static void slic_mcast_set_mask(struct adapter *adapter)
1410 __iomem struct slic_regs *slic_regs = adapter->slic_regs;
1412 if (adapter->macopts & (MAC_ALLMCAST | MAC_PROMISC)) {
1413 /* Turn on all multicast addresses. We have to do this for
1414 * promiscuous mode as well as ALLMCAST mode. It saves the
1415 * Microcode from having to keep state about the MAC
1418 slic_reg32_write(&slic_regs->slic_mcastlow, 0xFFFFFFFF, FLUSH);
1419 slic_reg32_write(&slic_regs->slic_mcasthigh, 0xFFFFFFFF,
1422 /* Commit our multicast mast to the SLIC by writing to the
1423 * multicast address mask registers
1425 slic_reg32_write(&slic_regs->slic_mcastlow,
1426 (u32)(adapter->mcastmask & 0xFFFFFFFF), FLUSH);
1427 slic_reg32_write(&slic_regs->slic_mcasthigh,
1428 (u32)((adapter->mcastmask >> 32) & 0xFFFFFFFF), FLUSH);
1432 static void slic_timer_ping(ulong dev)
1434 struct adapter *adapter;
1435 struct sliccard *card;
1438 adapter = netdev_priv((struct net_device *)dev);
1440 card = adapter->card;
1443 adapter->pingtimer.expires = jiffies + (PING_TIMER_INTERVAL * HZ);
1444 add_timer(&adapter->pingtimer);
1450 * Perform initialization of our slic interface.
1453 static int slic_if_init(struct adapter *adapter)
1455 struct sliccard *card = adapter->card;
1456 struct net_device *dev = adapter->netdev;
1457 __iomem struct slic_regs *slic_regs = adapter->slic_regs;
1458 struct slic_shmem *pshmem;
1463 /* adapter should be down at this point */
1464 if (adapter->state != ADAPT_DOWN) {
1465 dev_err(&dev->dev, "%s: adapter->state != ADAPT_DOWN\n",
1469 ASSERT(adapter->linkstate == LINK_DOWN);
1471 adapter->devflags_prev = dev->flags;
1472 adapter->macopts = MAC_DIRECTED;
1474 if (dev->flags & IFF_BROADCAST)
1475 adapter->macopts |= MAC_BCAST;
1476 if (dev->flags & IFF_PROMISC)
1477 adapter->macopts |= MAC_PROMISC;
1478 if (dev->flags & IFF_ALLMULTI)
1479 adapter->macopts |= MAC_ALLMCAST;
1480 if (dev->flags & IFF_MULTICAST)
1481 adapter->macopts |= MAC_MCAST;
1483 status = slic_adapter_allocresources(adapter);
1484 if (status != STATUS_SUCCESS) {
1486 "%s: slic_adapter_allocresources FAILED %x\n",
1488 slic_adapter_freeresources(adapter);
1492 if (!adapter->queues_initialized) {
1493 if (slic_rspqueue_init(adapter))
1495 if (slic_cmdq_init(adapter))
1497 if (slic_rcvqueue_init(adapter))
1499 adapter->queues_initialized = 1;
1502 slic_reg32_write(&slic_regs->slic_icr, ICR_INT_OFF, FLUSH);
1505 if (!adapter->isp_initialized) {
1506 pshmem = (struct slic_shmem *)adapter->phys_shmem;
1508 spin_lock_irqsave(&adapter->bit64reglock.lock,
1509 adapter->bit64reglock.flags);
1511 #if defined(CONFIG_X86_64)
1512 slic_reg32_write(&slic_regs->slic_addr_upper,
1513 SLIC_GET_ADDR_HIGH(&pshmem->isr), DONT_FLUSH);
1514 slic_reg32_write(&slic_regs->slic_isp,
1515 SLIC_GET_ADDR_LOW(&pshmem->isr), FLUSH);
1516 #elif defined(CONFIG_X86)
1517 slic_reg32_write(&slic_regs->slic_addr_upper, 0, DONT_FLUSH);
1518 slic_reg32_write(&slic_regs->slic_isp, (u32)&pshmem->isr, FLUSH);
1522 spin_unlock_irqrestore(&adapter->bit64reglock.lock,
1523 adapter->bit64reglock.flags);
1524 adapter->isp_initialized = 1;
1527 adapter->state = ADAPT_UP;
1528 if (!card->loadtimerset) {
1529 init_timer(&card->loadtimer);
1530 card->loadtimer.expires =
1531 jiffies + (SLIC_LOADTIMER_PERIOD * HZ);
1532 card->loadtimer.data = (ulong) card;
1533 card->loadtimer.function = &slic_timer_load_check;
1534 add_timer(&card->loadtimer);
1536 card->loadtimerset = 1;
1539 if (!adapter->pingtimerset) {
1540 init_timer(&adapter->pingtimer);
1541 adapter->pingtimer.expires =
1542 jiffies + (PING_TIMER_INTERVAL * HZ);
1543 adapter->pingtimer.data = (ulong) dev;
1544 adapter->pingtimer.function = &slic_timer_ping;
1545 add_timer(&adapter->pingtimer);
1546 adapter->pingtimerset = 1;
1547 adapter->card->pingstatus = ISR_PINGMASK;
1551 * clear any pending events, then enable interrupts
1553 adapter->isrcopy = 0;
1554 adapter->pshmem->isr = 0;
1555 slic_reg32_write(&slic_regs->slic_isr, 0, FLUSH);
1556 slic_reg32_write(&slic_regs->slic_icr, ICR_INT_ON, FLUSH);
1558 slic_link_config(adapter, LINK_AUTOSPEED, LINK_AUTOD);
1559 slic_link_event_handler(adapter);
1561 return STATUS_SUCCESS;
1564 static void slic_unmap_mmio_space(struct adapter *adapter)
1566 if (adapter->slic_regs)
1567 iounmap(adapter->slic_regs);
1568 adapter->slic_regs = NULL;
1571 static int slic_adapter_allocresources(struct adapter *adapter)
1573 if (!adapter->intrregistered) {
1576 spin_unlock_irqrestore(&slic_global.driver_lock.lock,
1577 slic_global.driver_lock.flags);
1579 retval = request_irq(adapter->netdev->irq,
1582 adapter->netdev->name, adapter->netdev);
1584 spin_lock_irqsave(&slic_global.driver_lock.lock,
1585 slic_global.driver_lock.flags);
1588 dev_err(&adapter->netdev->dev,
1589 "request_irq (%s) FAILED [%x]\n",
1590 adapter->netdev->name, retval);
1593 adapter->intrregistered = 1;
1595 return STATUS_SUCCESS;
1598 static void slic_config_pci(struct pci_dev *pcidev)
1603 pci_read_config_word(pcidev, PCI_COMMAND, &pci_command);
1605 new_command = pci_command | PCI_COMMAND_MASTER
1606 | PCI_COMMAND_MEMORY
1607 | PCI_COMMAND_INVALIDATE
1608 | PCI_COMMAND_PARITY | PCI_COMMAND_SERR | PCI_COMMAND_FAST_BACK;
1609 if (pci_command != new_command)
1610 pci_write_config_word(pcidev, PCI_COMMAND, new_command);
1613 static void slic_adapter_freeresources(struct adapter *adapter)
1615 slic_init_cleanup(adapter);
1616 memset(&adapter->stats, 0, sizeof(struct net_device_stats));
1617 adapter->error_interrupts = 0;
1618 adapter->rcv_interrupts = 0;
1619 adapter->xmit_interrupts = 0;
1620 adapter->linkevent_interrupts = 0;
1621 adapter->upr_interrupts = 0;
1622 adapter->num_isrs = 0;
1623 adapter->xmit_completes = 0;
1624 adapter->rcv_broadcasts = 0;
1625 adapter->rcv_multicasts = 0;
1626 adapter->rcv_unicasts = 0;
1632 * Write phy control to configure link duplex/speed
1635 static void slic_link_config(struct adapter *adapter,
1636 u32 linkspeed, u32 linkduplex)
1645 if (adapter->state != ADAPT_UP)
1648 ASSERT((adapter->devid == SLIC_1GB_DEVICE_ID)
1649 || (adapter->devid == SLIC_2GB_DEVICE_ID));
1651 if (linkspeed > LINK_1000MB)
1652 linkspeed = LINK_AUTOSPEED;
1653 if (linkduplex > LINK_AUTOD)
1654 linkduplex = LINK_AUTOD;
1656 wphy = &adapter->slic_regs->slic_wphy;
1658 if ((linkspeed == LINK_AUTOSPEED) || (linkspeed == LINK_1000MB)) {
1659 if (adapter->flags & ADAPT_FLAGS_FIBERMEDIA) {
1660 /* We've got a fiber gigabit interface, and register
1661 * 4 is different in fiber mode than in copper mode
1664 /* advertise FD only @1000 Mb */
1665 phy_advreg = (MIICR_REG_4 | (PAR_ADV1000XFD));
1666 /* enable PAUSE frames */
1667 phy_advreg |= PAR_ASYMPAUSE_FIBER;
1668 slic_reg32_write(wphy, phy_advreg, FLUSH);
1670 if (linkspeed == LINK_AUTOSPEED) {
1671 /* reset phy, enable auto-neg */
1674 (PCR_RESET | PCR_AUTONEG |
1676 slic_reg32_write(wphy, phy_config, FLUSH);
1677 } else { /* forced 1000 Mb FD*/
1678 /* power down phy to break link
1679 this may not work) */
1680 phy_config = (MIICR_REG_PCR | PCR_POWERDOWN);
1681 slic_reg32_write(wphy, phy_config, FLUSH);
1682 /* wait, Marvell says 1 sec,
1683 try to get away with 10 ms */
1686 /* disable auto-neg, set speed/duplex,
1687 soft reset phy, powerup */
1690 (PCR_RESET | PCR_SPEED_1000 |
1692 slic_reg32_write(wphy, phy_config, FLUSH);
1694 } else { /* copper gigabit */
1696 /* Auto-Negotiate or 1000 Mb must be auto negotiated
1697 * We've got a copper gigabit interface, and
1698 * register 4 is different in copper mode than
1701 if (linkspeed == LINK_AUTOSPEED) {
1702 /* advertise 10/100 Mb modes */
1705 (PAR_ADV100FD | PAR_ADV100HD | PAR_ADV10FD
1708 /* linkspeed == LINK_1000MB -
1709 don't advertise 10/100 Mb modes */
1710 phy_advreg = MIICR_REG_4;
1712 /* enable PAUSE frames */
1713 phy_advreg |= PAR_ASYMPAUSE;
1714 /* required by the Cicada PHY */
1715 phy_advreg |= PAR_802_3;
1716 slic_reg32_write(wphy, phy_advreg, FLUSH);
1717 /* advertise FD only @1000 Mb */
1718 phy_gctlreg = (MIICR_REG_9 | (PGC_ADV1000FD));
1719 slic_reg32_write(wphy, phy_gctlreg, FLUSH);
1721 if (adapter->subsysid != SLIC_1GB_CICADA_SUBSYS_ID) {
1723 enable auto crossover */
1725 (MIICR_REG_16 | (MRV_REG16_XOVERON));
1726 slic_reg32_write(wphy, phy_config, FLUSH);
1728 /* reset phy, enable auto-neg */
1731 (PCR_RESET | PCR_AUTONEG |
1733 slic_reg32_write(wphy, phy_config, FLUSH);
1734 } else { /* it's a Cicada PHY */
1735 /* enable and restart auto-neg (don't reset) */
1738 (PCR_AUTONEG | PCR_AUTONEG_RST));
1739 slic_reg32_write(wphy, phy_config, FLUSH);
1744 if (linkspeed == LINK_10MB)
1747 speed = PCR_SPEED_100;
1748 if (linkduplex == LINK_HALFD)
1751 duplex = PCR_DUPLEX_FULL;
1753 if (adapter->subsysid != SLIC_1GB_CICADA_SUBSYS_ID) {
1755 disable auto crossover */
1756 phy_config = (MIICR_REG_16 | (MRV_REG16_XOVEROFF));
1757 slic_reg32_write(wphy, phy_config, FLUSH);
1760 /* power down phy to break link (this may not work) */
1761 phy_config = (MIICR_REG_PCR | (PCR_POWERDOWN | speed | duplex));
1762 slic_reg32_write(wphy, phy_config, FLUSH);
1764 /* wait, Marvell says 1 sec, try to get away with 10 ms */
1767 if (adapter->subsysid != SLIC_1GB_CICADA_SUBSYS_ID) {
1769 disable auto-neg, set speed,
1770 soft reset phy, powerup */
1772 (MIICR_REG_PCR | (PCR_RESET | speed | duplex));
1773 slic_reg32_write(wphy, phy_config, FLUSH);
1774 } else { /* it's a Cicada PHY */
1775 /* disable auto-neg, set speed, powerup */
1776 phy_config = (MIICR_REG_PCR | (speed | duplex));
1777 slic_reg32_write(wphy, phy_config, FLUSH);
1782 static void slic_card_cleanup(struct sliccard *card)
1784 if (card->loadtimerset) {
1785 card->loadtimerset = 0;
1786 del_timer(&card->loadtimer);
1789 slic_debug_card_destroy(card);
1794 static int slic_card_download_gbrcv(struct adapter *adapter)
1796 const struct firmware *fw;
1797 const char *file = "";
1799 __iomem struct slic_regs *slic_regs = adapter->slic_regs;
1803 u32 rcvucodelen = 0;
1805 switch (adapter->devid) {
1806 case SLIC_2GB_DEVICE_ID:
1807 file = "slicoss/oasisrcvucode.sys";
1809 case SLIC_1GB_DEVICE_ID:
1810 file = "slicoss/gbrcvucode.sys";
1817 ret = request_firmware(&fw, file, &adapter->pcidev->dev);
1819 dev_err(&adapter->pcidev->dev,
1820 "SLICOSS: Failed to load firmware %s\n", file);
1824 rcvucodelen = *(u32 *)(fw->data + index);
1826 switch (adapter->devid) {
1827 case SLIC_2GB_DEVICE_ID:
1828 if (rcvucodelen != OasisRcvUCodeLen)
1831 case SLIC_1GB_DEVICE_ID:
1832 if (rcvucodelen != GBRcvUCodeLen)
1839 /* start download */
1840 slic_reg32_write(&slic_regs->slic_rcv_wcs, SLIC_RCVWCS_BEGIN, FLUSH);
1841 /* download the rcv sequencer ucode */
1842 for (codeaddr = 0; codeaddr < rcvucodelen; codeaddr++) {
1843 /* write out instruction address */
1844 slic_reg32_write(&slic_regs->slic_rcv_wcs, codeaddr, FLUSH);
1846 instruction = *(u32 *)(fw->data + index);
1848 /* write out the instruction data low addr */
1849 slic_reg32_write(&slic_regs->slic_rcv_wcs, instruction, FLUSH);
1851 instruction = *(u8 *)(fw->data + index);
1853 /* write out the instruction data high addr */
1854 slic_reg32_write(&slic_regs->slic_rcv_wcs, (u8)instruction,
1858 /* download finished */
1859 release_firmware(fw);
1860 slic_reg32_write(&slic_regs->slic_rcv_wcs, SLIC_RCVWCS_FINISH, FLUSH);
1864 static int slic_card_download(struct adapter *adapter)
1866 const struct firmware *fw;
1867 const char *file = "";
1870 int thissectionsize;
1872 __iomem struct slic_regs *slic_regs = adapter->slic_regs;
1880 int ucode_start, index = 0;
1882 switch (adapter->devid) {
1883 case SLIC_2GB_DEVICE_ID:
1884 file = "slicoss/oasisdownload.sys";
1886 case SLIC_1GB_DEVICE_ID:
1887 file = "slicoss/gbdownload.sys";
1893 ret = request_firmware(&fw, file, &adapter->pcidev->dev);
1895 dev_err(&adapter->pcidev->dev,
1896 "SLICOSS: Failed to load firmware %s\n", file);
1899 numsects = *(u32 *)(fw->data + index);
1901 ASSERT(numsects <= 3);
1902 for (i = 0; i < numsects; i++) {
1903 sectsize[i] = *(u32 *)(fw->data + index);
1906 for (i = 0; i < numsects; i++) {
1907 sectstart[i] = *(u32 *)(fw->data + index);
1910 ucode_start = index;
1911 instruction = *(u32 *)(fw->data + index);
1913 for (section = 0; section < numsects; section++) {
1914 baseaddress = sectstart[section];
1915 thissectionsize = sectsize[section] >> 3;
1917 for (codeaddr = 0; codeaddr < thissectionsize; codeaddr++) {
1918 /* Write out instruction address */
1919 slic_reg32_write(&slic_regs->slic_wcs,
1920 baseaddress + codeaddr, FLUSH);
1921 /* Write out instruction to low addr */
1922 slic_reg32_write(&slic_regs->slic_wcs, instruction, FLUSH);
1923 instruction = *(u32 *)(fw->data + index);
1926 /* Write out instruction to high addr */
1927 slic_reg32_write(&slic_regs->slic_wcs, instruction, FLUSH);
1928 instruction = *(u32 *)(fw->data + index);
1932 index = ucode_start;
1933 for (section = 0; section < numsects; section++) {
1934 instruction = *(u32 *)(fw->data + index);
1935 baseaddress = sectstart[section];
1936 if (baseaddress < 0x8000)
1938 thissectionsize = sectsize[section] >> 3;
1940 for (codeaddr = 0; codeaddr < thissectionsize; codeaddr++) {
1941 /* Write out instruction address */
1942 slic_reg32_write(&slic_regs->slic_wcs,
1943 SLIC_WCS_COMPARE | (baseaddress + codeaddr),
1945 /* Write out instruction to low addr */
1946 slic_reg32_write(&slic_regs->slic_wcs, instruction,
1948 instruction = *(u32 *)(fw->data + index);
1950 /* Write out instruction to high addr */
1951 slic_reg32_write(&slic_regs->slic_wcs, instruction,
1953 instruction = *(u32 *)(fw->data + index);
1956 /* Check SRAM location zero. If it is non-zero. Abort.*/
1957 /* failure = readl((u32 __iomem *)&slic_regs->slic_reset);
1959 release_firmware(fw);
1964 release_firmware(fw);
1965 /* Everything OK, kick off the card */
1967 slic_reg32_write(&slic_regs->slic_wcs, SLIC_WCS_START, FLUSH);
1969 /* stall for 20 ms, long enough for ucode to init card
1970 and reach mainloop */
1973 return STATUS_SUCCESS;
1976 static void slic_adapter_set_hwaddr(struct adapter *adapter)
1978 struct sliccard *card = adapter->card;
1980 if ((adapter->card) && (card->config_set)) {
1981 memcpy(adapter->macaddr,
1982 card->config.MacInfo[adapter->functionnumber].macaddrA,
1983 sizeof(struct slic_config_mac));
1984 if (!(adapter->currmacaddr[0] || adapter->currmacaddr[1] ||
1985 adapter->currmacaddr[2] || adapter->currmacaddr[3] ||
1986 adapter->currmacaddr[4] || adapter->currmacaddr[5])) {
1987 memcpy(adapter->currmacaddr, adapter->macaddr, 6);
1989 if (adapter->netdev) {
1990 memcpy(adapter->netdev->dev_addr, adapter->currmacaddr,
1996 static void slic_intagg_set(struct adapter *adapter, u32 value)
1998 slic_reg32_write(&adapter->slic_regs->slic_intagg, value, FLUSH);
1999 adapter->card->loadlevel_current = value;
2002 static int slic_card_init(struct sliccard *card, struct adapter *adapter)
2004 __iomem struct slic_regs *slic_regs = adapter->slic_regs;
2005 struct slic_eeprom *peeprom;
2006 struct oslic_eeprom *pOeeprom;
2007 dma_addr_t phys_config;
2011 struct slic_shmem *pshmem;
2013 uint macaddrs = card->card_size;
2018 struct slic_config_mac *pmac;
2019 unsigned char fruformat;
2020 unsigned char oemfruformat;
2021 struct atk_fru *patkfru;
2022 union oemfru *poemfru;
2024 /* Reset everything except PCI configuration space */
2025 slic_soft_reset(adapter);
2027 /* Download the microcode */
2028 status = slic_card_download(adapter);
2030 if (status != STATUS_SUCCESS) {
2031 dev_err(&adapter->pcidev->dev,
2032 "download failed bus %d slot %d\n",
2033 adapter->busnumber, adapter->slotnumber);
2037 if (!card->config_set) {
2038 peeprom = pci_alloc_consistent(adapter->pcidev,
2039 sizeof(struct slic_eeprom),
2042 phys_configl = SLIC_GET_ADDR_LOW(phys_config);
2043 phys_configh = SLIC_GET_ADDR_HIGH(phys_config);
2046 dev_err(&adapter->pcidev->dev,
2047 "eeprom read failed to get memory "
2048 "bus %d slot %d\n", adapter->busnumber,
2049 adapter->slotnumber);
2052 memset(peeprom, 0, sizeof(struct slic_eeprom));
2054 slic_reg32_write(&slic_regs->slic_icr, ICR_INT_OFF, FLUSH);
2056 pshmem = (struct slic_shmem *)adapter->phys_shmem;
2058 spin_lock_irqsave(&adapter->bit64reglock.lock,
2059 adapter->bit64reglock.flags);
2060 slic_reg32_write(&slic_regs->slic_addr_upper, 0, DONT_FLUSH);
2061 slic_reg32_write(&slic_regs->slic_isp,
2062 SLIC_GET_ADDR_LOW(&pshmem->isr), FLUSH);
2063 spin_unlock_irqrestore(&adapter->bit64reglock.lock,
2064 adapter->bit64reglock.flags);
2066 slic_config_get(adapter, phys_configl, phys_configh);
2069 if (adapter->pshmem->isr) {
2070 if (adapter->pshmem->isr & ISR_UPC) {
2071 adapter->pshmem->isr = 0;
2072 slic_reg64_write(adapter,
2073 &slic_regs->slic_isp, 0,
2074 &slic_regs->slic_addr_upper,
2076 slic_reg32_write(&slic_regs->slic_isr,
2079 slic_upr_request_complete(adapter, 0);
2082 adapter->pshmem->isr = 0;
2083 slic_reg32_write(&slic_regs->slic_isr,
2090 dev_err(&adapter->pcidev->dev,
2091 "%d config data fetch timed out!\n",
2093 slic_reg64_write(adapter,
2094 &slic_regs->slic_isp, 0,
2095 &slic_regs->slic_addr_upper,
2102 switch (adapter->devid) {
2104 case SLIC_2GB_DEVICE_ID:
2105 /* extract EEPROM data and pointers to EEPROM data */
2106 pOeeprom = (struct oslic_eeprom *) peeprom;
2107 eecodesize = pOeeprom->EecodeSize;
2108 dramsize = pOeeprom->DramSize;
2109 pmac = pOeeprom->MacInfo;
2110 fruformat = pOeeprom->FruFormat;
2111 patkfru = &pOeeprom->AtkFru;
2112 oemfruformat = pOeeprom->OemFruFormat;
2113 poemfru = &pOeeprom->OemFru;
2115 /* Minor kludge for Oasis card
2116 get 2 MAC addresses from the
2117 EEPROM to ensure that function 1
2118 gets the Port 1 MAC address */
2121 /* extract EEPROM data and pointers to EEPROM data */
2122 eecodesize = peeprom->EecodeSize;
2123 dramsize = peeprom->DramSize;
2124 pmac = peeprom->u2.mac.MacInfo;
2125 fruformat = peeprom->FruFormat;
2126 patkfru = &peeprom->AtkFru;
2127 oemfruformat = peeprom->OemFruFormat;
2128 poemfru = &peeprom->OemFru;
2132 card->config.EepromValid = false;
2134 /* see if the EEPROM is valid by checking it's checksum */
2135 if ((eecodesize <= MAX_EECODE_SIZE) &&
2136 (eecodesize >= MIN_EECODE_SIZE)) {
2139 *(u16 *) ((char *) peeprom + (eecodesize - 2));
2141 calculate the EEPROM checksum
2144 ~slic_eeprom_cksum((char *) peeprom,
2147 if the ucdoe chksum flag bit worked,
2148 we wouldn't need this shit
2150 if (ee_chksum == calc_chksum)
2151 card->config.EepromValid = true;
2153 /* copy in the DRAM size */
2154 card->config.DramSize = dramsize;
2156 /* copy in the MAC address(es) */
2157 for (i = 0; i < macaddrs; i++) {
2158 memcpy(&card->config.MacInfo[i],
2159 &pmac[i], sizeof(struct slic_config_mac));
2162 /* copy the Alacritech FRU information */
2163 card->config.FruFormat = fruformat;
2164 memcpy(&card->config.AtkFru, patkfru,
2165 sizeof(struct atk_fru));
2167 pci_free_consistent(adapter->pcidev,
2168 sizeof(struct slic_eeprom),
2169 peeprom, phys_config);
2171 if ((!card->config.EepromValid) &&
2172 (adapter->reg_params.fail_on_bad_eeprom)) {
2173 slic_reg64_write(adapter, &slic_regs->slic_isp, 0,
2174 &slic_regs->slic_addr_upper,
2176 dev_err(&adapter->pcidev->dev,
2177 "unsupported CONFIGURATION EEPROM invalid\n");
2181 card->config_set = 1;
2184 if (slic_card_download_gbrcv(adapter)) {
2185 dev_err(&adapter->pcidev->dev,
2186 "unable to download GB receive microcode\n");
2190 if (slic_global.dynamic_intagg)
2191 slic_intagg_set(adapter, 0);
2193 slic_intagg_set(adapter, intagg_delay);
2196 * Initialize ping status to "ok"
2198 card->pingstatus = ISR_PINGMASK;
2201 * Lastly, mark our card state as up and return success
2203 card->state = CARD_UP;
2204 card->reset_in_progress = 0;
2206 return STATUS_SUCCESS;
2209 static u32 slic_card_locate(struct adapter *adapter)
2211 struct sliccard *card = slic_global.slic_card;
2212 struct physcard *physcard = slic_global.phys_card;
2214 u16 __iomem *hostid_reg;
2216 uint rdhostid_offset = 0;
2218 switch (adapter->devid) {
2219 case SLIC_2GB_DEVICE_ID:
2220 rdhostid_offset = SLIC_RDHOSTID_2GB;
2222 case SLIC_1GB_DEVICE_ID:
2223 rdhostid_offset = SLIC_RDHOSTID_1GB;
2231 (u16 __iomem *) (((u8 __iomem *) (adapter->slic_regs)) +
2234 /* read the 16 bit hostid from SRAM */
2235 card_hostid = (ushort) readw(hostid_reg);
2237 /* Initialize a new card structure if need be */
2238 if (card_hostid == SLIC_HOSTID_DEFAULT) {
2239 card = kzalloc(sizeof(struct sliccard), GFP_KERNEL);
2243 card->next = slic_global.slic_card;
2244 slic_global.slic_card = card;
2245 card->busnumber = adapter->busnumber;
2246 card->slotnumber = adapter->slotnumber;
2248 /* Find an available cardnum */
2249 for (i = 0; i < SLIC_MAX_CARDS; i++) {
2250 if (slic_global.cardnuminuse[i] == 0) {
2251 slic_global.cardnuminuse[i] = 1;
2256 slic_global.num_slic_cards++;
2258 slic_debug_card_create(card);
2260 /* Card exists, find the card this adapter belongs to */
2262 if (card->cardnum == card_hostid)
2270 return STATUS_FAILURE;
2271 /* Put the adapter in the card's adapter list */
2272 ASSERT(card->adapter[adapter->port] == NULL);
2273 if (!card->adapter[adapter->port]) {
2274 card->adapter[adapter->port] = adapter;
2275 adapter->card = card;
2278 card->card_size = 1; /* one port per *logical* card */
2281 for (i = 0; i < SLIC_MAX_PORTS; i++) {
2282 if (!physcard->adapter[i])
2287 ASSERT(i != SLIC_MAX_PORTS);
2288 if (physcard->adapter[i]->slotnumber == adapter->slotnumber)
2290 physcard = physcard->next;
2293 /* no structure allocated for this physical card yet */
2294 physcard = kzalloc(sizeof(struct physcard), GFP_ATOMIC);
2297 physcard->next = slic_global.phys_card;
2298 slic_global.phys_card = physcard;
2299 physcard->adapters_allocd = 1;
2301 physcard->adapters_allocd++;
2303 /* Note - this is ZERO relative */
2304 adapter->physport = physcard->adapters_allocd - 1;
2306 ASSERT(physcard->adapter[adapter->physport] == NULL);
2307 physcard->adapter[adapter->physport] = adapter;
2308 adapter->physcard = physcard;
2313 static void slic_soft_reset(struct adapter *adapter)
2315 if (adapter->card->state == CARD_UP) {
2316 slic_reg32_write(&adapter->slic_regs->slic_quiesce, 0, FLUSH);
2320 slic_reg32_write(&adapter->slic_regs->slic_reset, SLIC_RESET_MAGIC,
2325 static void slic_config_set(struct adapter *adapter, bool linkchange)
2329 __iomem struct slic_regs *slic_regs = adapter->slic_regs;
2333 slic_mac_config(adapter);
2334 RcrReset = GRCR_RESET;
2336 slic_mac_address_config(adapter);
2340 if (adapter->linkduplex == LINK_FULLD) {
2342 value = (GXCR_RESET | /* Always reset */
2343 GXCR_XMTEN | /* Enable transmit */
2344 GXCR_PAUSEEN); /* Enable pause */
2346 slic_reg32_write(&slic_regs->slic_wxcfg, value, FLUSH);
2348 /* Setup rcvcfg last */
2349 value = (RcrReset | /* Reset, if linkchange */
2350 GRCR_CTLEN | /* Enable CTL frames */
2351 GRCR_ADDRAEN | /* Address A enable */
2352 GRCR_RCVBAD | /* Rcv bad frames */
2353 (GRCR_HASHSIZE << GRCR_HASHSIZE_SHIFT));
2356 value = (GXCR_RESET | /* Always reset */
2357 GXCR_XMTEN); /* Enable transmit */
2359 slic_reg32_write(&slic_regs->slic_wxcfg, value, FLUSH);
2361 /* Setup rcvcfg last */
2362 value = (RcrReset | /* Reset, if linkchange */
2363 GRCR_ADDRAEN | /* Address A enable */
2364 GRCR_RCVBAD | /* Rcv bad frames */
2365 (GRCR_HASHSIZE << GRCR_HASHSIZE_SHIFT));
2368 if (adapter->state != ADAPT_DOWN) {
2369 /* Only enable receive if we are restarting or running */
2370 value |= GRCR_RCVEN;
2373 if (adapter->macopts & MAC_PROMISC)
2374 value |= GRCR_RCVALL;
2376 slic_reg32_write(&slic_regs->slic_wrcfg, value, FLUSH);
2380 * Turn off RCV and XMT, power down PHY
2382 static void slic_config_clear(struct adapter *adapter)
2386 __iomem struct slic_regs *slic_regs = adapter->slic_regs;
2389 value = (GXCR_RESET | /* Always reset */
2390 GXCR_PAUSEEN); /* Enable pause */
2392 slic_reg32_write(&slic_regs->slic_wxcfg, value, FLUSH);
2394 value = (GRCR_RESET | /* Always reset */
2395 GRCR_CTLEN | /* Enable CTL frames */
2396 GRCR_ADDRAEN | /* Address A enable */
2397 (GRCR_HASHSIZE << GRCR_HASHSIZE_SHIFT));
2399 slic_reg32_write(&slic_regs->slic_wrcfg, value, FLUSH);
2401 /* power down phy */
2402 phy_config = (MIICR_REG_PCR | (PCR_POWERDOWN));
2403 slic_reg32_write(&slic_regs->slic_wphy, phy_config, FLUSH);
2406 static void slic_config_get(struct adapter *adapter, u32 config,
2411 status = slic_upr_request(adapter,
2413 (u32) config, (u32) config_h, 0, 0);
2414 ASSERT(status == 0);
2417 static void slic_mac_address_config(struct adapter *adapter)
2421 __iomem struct slic_regs *slic_regs = adapter->slic_regs;
2423 value = *(u32 *) &adapter->currmacaddr[2];
2424 value = ntohl(value);
2425 slic_reg32_write(&slic_regs->slic_wraddral, value, FLUSH);
2426 slic_reg32_write(&slic_regs->slic_wraddrbl, value, FLUSH);
2428 value2 = (u32) ((adapter->currmacaddr[0] << 8 |
2429 adapter->currmacaddr[1]) & 0xFFFF);
2431 slic_reg32_write(&slic_regs->slic_wraddrah, value2, FLUSH);
2432 slic_reg32_write(&slic_regs->slic_wraddrbh, value2, FLUSH);
2434 /* Write our multicast mask out to the card. This is done */
2435 /* here in addition to the slic_mcast_addr_set routine */
2436 /* because ALL_MCAST may have been enabled or disabled */
2437 slic_mcast_set_mask(adapter);
2440 static void slic_mac_config(struct adapter *adapter)
2443 __iomem struct slic_regs *slic_regs = adapter->slic_regs;
2445 /* Setup GMAC gaps */
2446 if (adapter->linkspeed == LINK_1000MB) {
2447 value = ((GMCR_GAPBB_1000 << GMCR_GAPBB_SHIFT) |
2448 (GMCR_GAPR1_1000 << GMCR_GAPR1_SHIFT) |
2449 (GMCR_GAPR2_1000 << GMCR_GAPR2_SHIFT));
2451 value = ((GMCR_GAPBB_100 << GMCR_GAPBB_SHIFT) |
2452 (GMCR_GAPR1_100 << GMCR_GAPR1_SHIFT) |
2453 (GMCR_GAPR2_100 << GMCR_GAPR2_SHIFT));
2457 if (adapter->linkspeed == LINK_1000MB)
2460 /* enable fullduplex */
2461 if ((adapter->linkduplex == LINK_FULLD)
2462 || (adapter->macopts & MAC_LOOPBACK)) {
2463 value |= GMCR_FULLD;
2466 /* write mac config */
2467 slic_reg32_write(&slic_regs->slic_wmcfg, value, FLUSH);
2469 /* setup mac addresses */
2470 slic_mac_address_config(adapter);
2473 static bool slic_mac_filter(struct adapter *adapter,
2474 struct ether_header *ether_frame)
2476 u32 opts = adapter->macopts;
2477 u32 *dhost4 = (u32 *)ðer_frame->ether_dhost[0];
2478 u16 *dhost2 = (u16 *)ðer_frame->ether_dhost[4];
2481 if (opts & MAC_PROMISC)
2484 if ((*dhost4 == 0xFFFFFFFF) && (*dhost2 == 0xFFFF)) {
2485 if (opts & MAC_BCAST) {
2486 adapter->rcv_broadcasts++;
2493 if (ether_frame->ether_dhost[0] & 0x01) {
2494 if (opts & MAC_ALLMCAST) {
2495 adapter->rcv_multicasts++;
2496 adapter->stats.multicast++;
2499 if (opts & MAC_MCAST) {
2500 struct mcast_address *mcaddr = adapter->mcastaddrs;
2503 ETHER_EQ_ADDR(mcaddr->address,
2504 ether_frame->ether_dhost,
2507 adapter->rcv_multicasts++;
2508 adapter->stats.multicast++;
2511 mcaddr = mcaddr->next;
2518 if (opts & MAC_DIRECTED) {
2519 adapter->rcv_unicasts++;
2526 static int slic_mac_set_address(struct net_device *dev, void *ptr)
2528 struct adapter *adapter = (struct adapter *)netdev_priv(dev);
2529 struct sockaddr *addr = ptr;
2531 if (netif_running(dev))
2536 memcpy(dev->dev_addr, addr->sa_data, dev->addr_len);
2537 memcpy(adapter->currmacaddr, addr->sa_data, dev->addr_len);
2539 slic_config_set(adapter, true);
2543 static void slic_timer_load_check(ulong cardaddr)
2545 struct sliccard *card = (struct sliccard *)cardaddr;
2546 struct adapter *adapter = card->master;
2547 u32 __iomem *intagg;
2548 u32 load = card->events;
2551 intagg = &adapter->slic_regs->slic_intagg;
2553 if ((adapter) && (adapter->state == ADAPT_UP) &&
2554 (card->state == CARD_UP) && (slic_global.dynamic_intagg)) {
2555 if (adapter->devid == SLIC_1GB_DEVICE_ID) {
2556 if (adapter->linkspeed == LINK_1000MB)
2559 if (load > SLIC_LOAD_5)
2560 level = SLIC_INTAGG_5;
2561 else if (load > SLIC_LOAD_4)
2562 level = SLIC_INTAGG_4;
2563 else if (load > SLIC_LOAD_3)
2564 level = SLIC_INTAGG_3;
2565 else if (load > SLIC_LOAD_2)
2566 level = SLIC_INTAGG_2;
2567 else if (load > SLIC_LOAD_1)
2568 level = SLIC_INTAGG_1;
2570 level = SLIC_INTAGG_0;
2572 if (card->loadlevel_current != level) {
2573 card->loadlevel_current = level;
2574 slic_reg32_write(intagg, level, FLUSH);
2577 if (load > SLIC_LOAD_5)
2578 level = SLIC_INTAGG_5;
2579 else if (load > SLIC_LOAD_4)
2580 level = SLIC_INTAGG_4;
2581 else if (load > SLIC_LOAD_3)
2582 level = SLIC_INTAGG_3;
2583 else if (load > SLIC_LOAD_2)
2584 level = SLIC_INTAGG_2;
2585 else if (load > SLIC_LOAD_1)
2586 level = SLIC_INTAGG_1;
2588 level = SLIC_INTAGG_0;
2589 if (card->loadlevel_current != level) {
2590 card->loadlevel_current = level;
2591 slic_reg32_write(intagg, level, FLUSH);
2596 card->loadtimer.expires = jiffies + (SLIC_LOADTIMER_PERIOD * HZ);
2597 add_timer(&card->loadtimer);
2600 static void slic_assert_fail(void)
2604 cpuid = smp_processor_id();
2605 curr_pid = current->pid;
2607 printk(KERN_ERR "%s CPU # %d ---- PID # %d\n",
2608 __func__, cpuid, curr_pid);
2611 static int slic_upr_queue_request(struct adapter *adapter,
2615 u32 upr_buffer, u32 upr_buffer_h)
2617 struct slic_upr *upr;
2618 struct slic_upr *uprqueue;
2620 upr = kmalloc(sizeof(struct slic_upr), GFP_ATOMIC);
2624 upr->adapter = adapter->port;
2625 upr->upr_request = upr_request;
2626 upr->upr_data = upr_data;
2627 upr->upr_buffer = upr_buffer;
2628 upr->upr_data_h = upr_data_h;
2629 upr->upr_buffer_h = upr_buffer_h;
2631 if (adapter->upr_list) {
2632 uprqueue = adapter->upr_list;
2634 while (uprqueue->next)
2635 uprqueue = uprqueue->next;
2636 uprqueue->next = upr;
2638 adapter->upr_list = upr;
2640 return STATUS_SUCCESS;
2643 static int slic_upr_request(struct adapter *adapter,
2647 u32 upr_buffer, u32 upr_buffer_h)
2651 spin_lock_irqsave(&adapter->upr_lock.lock, adapter->upr_lock.flags);
2652 status = slic_upr_queue_request(adapter,
2655 upr_data_h, upr_buffer, upr_buffer_h);
2656 if (status != STATUS_SUCCESS) {
2657 spin_unlock_irqrestore(&adapter->upr_lock.lock,
2658 adapter->upr_lock.flags);
2661 slic_upr_start(adapter);
2662 spin_unlock_irqrestore(&adapter->upr_lock.lock,
2663 adapter->upr_lock.flags);
2664 return STATUS_PENDING;
2667 static void slic_upr_request_complete(struct adapter *adapter, u32 isr)
2669 struct sliccard *card = adapter->card;
2670 struct slic_upr *upr;
2672 spin_lock_irqsave(&adapter->upr_lock.lock, adapter->upr_lock.flags);
2673 upr = adapter->upr_list;
2676 spin_unlock_irqrestore(&adapter->upr_lock.lock,
2677 adapter->upr_lock.flags);
2680 adapter->upr_list = upr->next;
2682 adapter->upr_busy = 0;
2683 ASSERT(adapter->port == upr->adapter);
2684 switch (upr->upr_request) {
2685 case SLIC_UPR_STATS:
2687 struct slic_stats *slicstats =
2688 (struct slic_stats *) &adapter->pshmem->inicstats;
2689 struct slic_stats *newstats = slicstats;
2690 struct slic_stats *old = &adapter->inicstats_prev;
2691 struct slicnet_stats *stst = &adapter->slic_stats;
2693 if (isr & ISR_UPCERR) {
2694 dev_err(&adapter->netdev->dev,
2695 "SLIC_UPR_STATS command failed isr[%x]\n",
2700 UPDATE_STATS_GB(stst->tcp.xmit_tcp_segs,
2701 newstats->xmit_tcp_segs_gb,
2702 old->xmit_tcp_segs_gb);
2704 UPDATE_STATS_GB(stst->tcp.xmit_tcp_bytes,
2705 newstats->xmit_tcp_bytes_gb,
2706 old->xmit_tcp_bytes_gb);
2708 UPDATE_STATS_GB(stst->tcp.rcv_tcp_segs,
2709 newstats->rcv_tcp_segs_gb,
2710 old->rcv_tcp_segs_gb);
2712 UPDATE_STATS_GB(stst->tcp.rcv_tcp_bytes,
2713 newstats->rcv_tcp_bytes_gb,
2714 old->rcv_tcp_bytes_gb);
2716 UPDATE_STATS_GB(stst->iface.xmt_bytes,
2717 newstats->xmit_bytes_gb,
2718 old->xmit_bytes_gb);
2720 UPDATE_STATS_GB(stst->iface.xmt_ucast,
2721 newstats->xmit_unicasts_gb,
2722 old->xmit_unicasts_gb);
2724 UPDATE_STATS_GB(stst->iface.rcv_bytes,
2725 newstats->rcv_bytes_gb,
2728 UPDATE_STATS_GB(stst->iface.rcv_ucast,
2729 newstats->rcv_unicasts_gb,
2730 old->rcv_unicasts_gb);
2732 UPDATE_STATS_GB(stst->iface.xmt_errors,
2733 newstats->xmit_collisions_gb,
2734 old->xmit_collisions_gb);
2736 UPDATE_STATS_GB(stst->iface.xmt_errors,
2737 newstats->xmit_excess_collisions_gb,
2738 old->xmit_excess_collisions_gb);
2740 UPDATE_STATS_GB(stst->iface.xmt_errors,
2741 newstats->xmit_other_error_gb,
2742 old->xmit_other_error_gb);
2744 UPDATE_STATS_GB(stst->iface.rcv_errors,
2745 newstats->rcv_other_error_gb,
2746 old->rcv_other_error_gb);
2748 UPDATE_STATS_GB(stst->iface.rcv_discards,
2749 newstats->rcv_drops_gb,
2752 if (newstats->rcv_drops_gb > old->rcv_drops_gb) {
2753 adapter->rcv_drops +=
2754 (newstats->rcv_drops_gb -
2757 memcpy(old, newstats, sizeof(struct slic_stats));
2761 slic_link_upr_complete(adapter, isr);
2763 case SLIC_UPR_RCONFIG:
2778 card->pingstatus |= (isr & ISR_PINGDSMASK);
2784 slic_upr_start(adapter);
2785 spin_unlock_irqrestore(&adapter->upr_lock.lock,
2786 adapter->upr_lock.flags);
2789 static void slic_upr_start(struct adapter *adapter)
2791 struct slic_upr *upr;
2792 __iomem struct slic_regs *slic_regs = adapter->slic_regs;
2798 upr = adapter->upr_list;
2801 if (adapter->upr_busy)
2803 adapter->upr_busy = 1;
2805 switch (upr->upr_request) {
2806 case SLIC_UPR_STATS:
2807 if (upr->upr_data_h == 0) {
2808 slic_reg32_write(&slic_regs->slic_stats, upr->upr_data,
2811 slic_reg64_write(adapter, &slic_regs->slic_stats64,
2813 &slic_regs->slic_addr_upper,
2814 upr->upr_data_h, FLUSH);
2819 slic_reg64_write(adapter, &slic_regs->slic_rlsr, upr->upr_data,
2820 &slic_regs->slic_addr_upper, upr->upr_data_h,
2824 case SLIC_UPR_RCONFIG:
2825 slic_reg64_write(adapter, &slic_regs->slic_rconfig,
2826 upr->upr_data, &slic_regs->slic_addr_upper,
2827 upr->upr_data_h, FLUSH);
2830 slic_reg32_write(&slic_regs->slic_ping, 1, FLUSH);
2837 static void slic_link_upr_complete(struct adapter *adapter, u32 isr)
2839 u32 linkstatus = adapter->pshmem->linkstatus;
2841 unsigned char linkspeed;
2842 unsigned char linkduplex;
2844 if ((isr & ISR_UPCERR) || (isr & ISR_UPCBSY)) {
2845 struct slic_shmem *pshmem;
2847 pshmem = (struct slic_shmem *)adapter->phys_shmem;
2848 #if defined(CONFIG_X86_64)
2849 slic_upr_queue_request(adapter,
2851 SLIC_GET_ADDR_LOW(&pshmem->linkstatus),
2852 SLIC_GET_ADDR_HIGH(&pshmem->linkstatus),
2854 #elif defined(CONFIG_X86)
2855 slic_upr_queue_request(adapter,
2857 (u32) &pshmem->linkstatus,
2858 SLIC_GET_ADDR_HIGH(pshmem), 0, 0);
2864 if (adapter->state != ADAPT_UP)
2867 ASSERT((adapter->devid == SLIC_1GB_DEVICE_ID)
2868 || (adapter->devid == SLIC_2GB_DEVICE_ID));
2870 linkup = linkstatus & GIG_LINKUP ? LINK_UP : LINK_DOWN;
2871 if (linkstatus & GIG_SPEED_1000)
2872 linkspeed = LINK_1000MB;
2873 else if (linkstatus & GIG_SPEED_100)
2874 linkspeed = LINK_100MB;
2876 linkspeed = LINK_10MB;
2878 if (linkstatus & GIG_FULLDUPLEX)
2879 linkduplex = LINK_FULLD;
2881 linkduplex = LINK_HALFD;
2883 if ((adapter->linkstate == LINK_DOWN) && (linkup == LINK_DOWN))
2886 /* link up event, but nothing has changed */
2887 if ((adapter->linkstate == LINK_UP) &&
2888 (linkup == LINK_UP) &&
2889 (adapter->linkspeed == linkspeed) &&
2890 (adapter->linkduplex == linkduplex))
2893 /* link has changed at this point */
2895 /* link has gone from up to down */
2896 if (linkup == LINK_DOWN) {
2897 adapter->linkstate = LINK_DOWN;
2901 /* link has gone from down to up */
2902 adapter->linkspeed = linkspeed;
2903 adapter->linkduplex = linkduplex;
2905 if (adapter->linkstate != LINK_UP) {
2907 slic_config_set(adapter, true);
2908 adapter->linkstate = LINK_UP;
2909 netif_start_queue(adapter->netdev);
2914 * this is here to checksum the eeprom, there is some ucode bug
2915 * which prevens us from using the ucode result.
2916 * remove this once ucode is fixed.
2918 static ushort slic_eeprom_cksum(char *m, int len)
2920 #define ADDCARRY(x) (x > 65535 ? x -= 65535 : x)
2921 #define REDUCE {l_util.l = sum; sum = l_util.s[0] + l_util.s[1]; ADDCARRY(sum);\
2926 u32 byte_swapped = 0;
2943 #ifdef CONFIG_X86_64
2944 w_int = (u32) ((ulong) w & 0x00000000FFFFFFFF);
2948 if ((1 & w_int) && (len > 0)) {
2951 s_util.c[0] = *(unsigned char *)w;
2952 w = (u16 *)((char *)w + 1);
2957 /* Unroll the loop to make overhead from branches &c small. */
2958 while ((len -= 32) >= 0) {
2975 w = (u16 *)((ulong) w + 16); /* verify */
2978 while ((len -= 8) >= 0) {
2983 w = (u16 *)((ulong) w + 4); /* verify */
2986 if (len != 0 || byte_swapped != 0) {
2988 while ((len -= 2) >= 0)
2989 sum += *w++; /* verify */
2995 s_util.c[1] = *(char *) w;
3002 } else if (len == -1) {
3003 s_util.c[0] = *(char *) w;
3012 return (ushort) sum;
3015 static int slic_rspqueue_init(struct adapter *adapter)
3018 struct slic_rspqueue *rspq = &adapter->rspqueue;
3019 __iomem struct slic_regs *slic_regs = adapter->slic_regs;
3022 ASSERT(adapter->state == ADAPT_DOWN);
3023 memset(rspq, 0, sizeof(struct slic_rspqueue));
3025 rspq->num_pages = SLIC_RSPQ_PAGES_GB;
3027 for (i = 0; i < rspq->num_pages; i++) {
3028 rspq->vaddr[i] = pci_alloc_consistent(adapter->pcidev,
3031 if (!rspq->vaddr[i]) {
3032 dev_err(&adapter->pcidev->dev,
3033 "pci_alloc_consistent failed\n");
3034 slic_rspqueue_free(adapter);
3035 return STATUS_FAILURE;
3037 #ifndef CONFIG_X86_64
3038 ASSERT(((u32) rspq->vaddr[i] & 0xFFFFF000) ==
3039 (u32) rspq->vaddr[i]);
3040 ASSERT(((u32) rspq->paddr[i] & 0xFFFFF000) ==
3041 (u32) rspq->paddr[i]);
3043 memset(rspq->vaddr[i], 0, PAGE_SIZE);
3046 slic_reg32_write(&slic_regs->slic_rbar,
3047 (rspq->paddr[i] | SLIC_RSPQ_BUFSINPAGE),
3050 slic_reg64_write(adapter, &slic_regs->slic_rbar64,
3051 (rspq->paddr[i] | SLIC_RSPQ_BUFSINPAGE),
3052 &slic_regs->slic_addr_upper,
3053 paddrh, DONT_FLUSH);
3057 rspq->pageindex = 0;
3058 rspq->rspbuf = (struct slic_rspbuf *)rspq->vaddr[0];
3059 return STATUS_SUCCESS;
3062 static void slic_rspqueue_free(struct adapter *adapter)
3065 struct slic_rspqueue *rspq = &adapter->rspqueue;
3067 for (i = 0; i < rspq->num_pages; i++) {
3068 if (rspq->vaddr[i]) {
3069 pci_free_consistent(adapter->pcidev, PAGE_SIZE,
3070 rspq->vaddr[i], rspq->paddr[i]);
3072 rspq->vaddr[i] = NULL;
3076 rspq->pageindex = 0;
3077 rspq->rspbuf = NULL;
3080 static struct slic_rspbuf *slic_rspqueue_getnext(struct adapter *adapter)
3082 struct slic_rspqueue *rspq = &adapter->rspqueue;
3083 struct slic_rspbuf *buf;
3085 if (!(rspq->rspbuf->status))
3089 #ifndef CONFIG_X86_64
3090 ASSERT((buf->status & 0xFFFFFFE0) == 0);
3092 ASSERT(buf->hosthandle);
3093 if (++rspq->offset < SLIC_RSPQ_BUFSINPAGE) {
3095 #ifndef CONFIG_X86_64
3096 ASSERT(((u32) rspq->rspbuf & 0xFFFFFFE0) ==
3097 (u32) rspq->rspbuf);
3100 ASSERT(rspq->offset == SLIC_RSPQ_BUFSINPAGE);
3101 slic_reg64_write(adapter, &adapter->slic_regs->slic_rbar64,
3102 (rspq->paddr[rspq->pageindex] | SLIC_RSPQ_BUFSINPAGE),
3103 &adapter->slic_regs->slic_addr_upper, 0, DONT_FLUSH);
3104 rspq->pageindex = (++rspq->pageindex) % rspq->num_pages;
3106 rspq->rspbuf = (struct slic_rspbuf *)
3107 rspq->vaddr[rspq->pageindex];
3108 #ifndef CONFIG_X86_64
3109 ASSERT(((u32) rspq->rspbuf & 0xFFFFF000) ==
3110 (u32) rspq->rspbuf);
3113 #ifndef CONFIG_X86_64
3114 ASSERT(((u32) buf & 0xFFFFFFE0) == (u32) buf);
3119 static void slic_cmdqmem_init(struct adapter *adapter)
3121 struct slic_cmdqmem *cmdqmem = &adapter->cmdqmem;
3123 memset(cmdqmem, 0, sizeof(struct slic_cmdqmem));
3126 static void slic_cmdqmem_free(struct adapter *adapter)
3128 struct slic_cmdqmem *cmdqmem = &adapter->cmdqmem;
3131 for (i = 0; i < SLIC_CMDQ_MAXPAGES; i++) {
3132 if (cmdqmem->pages[i]) {
3133 pci_free_consistent(adapter->pcidev,
3135 (void *) cmdqmem->pages[i],
3136 cmdqmem->dma_pages[i]);
3139 memset(cmdqmem, 0, sizeof(struct slic_cmdqmem));
3142 static u32 *slic_cmdqmem_addpage(struct adapter *adapter)
3144 struct slic_cmdqmem *cmdqmem = &adapter->cmdqmem;
3147 if (cmdqmem->pagecnt >= SLIC_CMDQ_MAXPAGES)
3149 pageaddr = pci_alloc_consistent(adapter->pcidev,
3151 &cmdqmem->dma_pages[cmdqmem->pagecnt]);
3154 #ifndef CONFIG_X86_64
3155 ASSERT(((u32) pageaddr & 0xFFFFF000) == (u32) pageaddr);
3157 cmdqmem->pages[cmdqmem->pagecnt] = pageaddr;
3162 static int slic_cmdq_init(struct adapter *adapter)
3167 ASSERT(adapter->state == ADAPT_DOWN);
3168 memset(&adapter->cmdq_all, 0, sizeof(struct slic_cmdqueue));
3169 memset(&adapter->cmdq_free, 0, sizeof(struct slic_cmdqueue));
3170 memset(&adapter->cmdq_done, 0, sizeof(struct slic_cmdqueue));
3171 spin_lock_init(&adapter->cmdq_all.lock.lock);
3172 spin_lock_init(&adapter->cmdq_free.lock.lock);
3173 spin_lock_init(&adapter->cmdq_done.lock.lock);
3174 slic_cmdqmem_init(adapter);
3175 adapter->slic_handle_ix = 1;
3176 for (i = 0; i < SLIC_CMDQ_INITPAGES; i++) {
3177 pageaddr = slic_cmdqmem_addpage(adapter);
3178 #ifndef CONFIG_X86_64
3179 ASSERT(((u32) pageaddr & 0xFFFFF000) == (u32) pageaddr);
3182 slic_cmdq_free(adapter);
3183 return STATUS_FAILURE;
3185 slic_cmdq_addcmdpage(adapter, pageaddr);
3187 adapter->slic_handle_ix = 1;
3189 return STATUS_SUCCESS;
3192 static void slic_cmdq_free(struct adapter *adapter)
3194 struct slic_hostcmd *cmd;
3196 cmd = adapter->cmdq_all.head;
3199 struct sk_buff *tempskb;
3204 dev_kfree_skb_irq(tempskb);
3207 cmd = cmd->next_all;
3209 memset(&adapter->cmdq_all, 0, sizeof(struct slic_cmdqueue));
3210 memset(&adapter->cmdq_free, 0, sizeof(struct slic_cmdqueue));
3211 memset(&adapter->cmdq_done, 0, sizeof(struct slic_cmdqueue));
3212 slic_cmdqmem_free(adapter);
3215 static void slic_cmdq_reset(struct adapter *adapter)
3217 struct slic_hostcmd *hcmd;
3218 struct sk_buff *skb;
3221 spin_lock_irqsave(&adapter->cmdq_free.lock.lock,
3222 adapter->cmdq_free.lock.flags);
3223 spin_lock_irqsave(&adapter->cmdq_done.lock.lock,
3224 adapter->cmdq_done.lock.flags);
3225 outstanding = adapter->cmdq_all.count - adapter->cmdq_done.count;
3226 outstanding -= adapter->cmdq_free.count;
3227 hcmd = adapter->cmdq_all.head;
3234 dev_kfree_skb_irq(skb);
3236 hcmd = hcmd->next_all;
3238 adapter->cmdq_free.count = 0;
3239 adapter->cmdq_free.head = NULL;
3240 adapter->cmdq_free.tail = NULL;
3241 adapter->cmdq_done.count = 0;
3242 adapter->cmdq_done.head = NULL;
3243 adapter->cmdq_done.tail = NULL;
3244 adapter->cmdq_free.head = adapter->cmdq_all.head;
3245 hcmd = adapter->cmdq_all.head;
3247 adapter->cmdq_free.count++;
3248 hcmd->next = hcmd->next_all;
3249 hcmd = hcmd->next_all;
3251 if (adapter->cmdq_free.count != adapter->cmdq_all.count) {
3252 dev_err(&adapter->netdev->dev,
3253 "free_count %d != all count %d\n",
3254 adapter->cmdq_free.count, adapter->cmdq_all.count);
3256 spin_unlock_irqrestore(&adapter->cmdq_done.lock.lock,
3257 adapter->cmdq_done.lock.flags);
3258 spin_unlock_irqrestore(&adapter->cmdq_free.lock.lock,
3259 adapter->cmdq_free.lock.flags);
3262 static void slic_cmdq_addcmdpage(struct adapter *adapter, u32 *page)
3264 struct slic_hostcmd *cmd;
3265 struct slic_hostcmd *prev;
3266 struct slic_hostcmd *tail;
3267 struct slic_cmdqueue *cmdq;
3273 struct slic_handle *pslic_handle;
3276 cmd = (struct slic_hostcmd *)cmdaddr;
3279 phys_addr = virt_to_bus((void *)page);
3280 phys_addrl = SLIC_GET_ADDR_LOW(phys_addr);
3281 phys_addrh = SLIC_GET_ADDR_HIGH(phys_addr);
3285 while ((cmdcnt < SLIC_CMDQ_CMDSINPAGE) &&
3286 (adapter->slic_handle_ix < 256)) {
3287 /* Allocate and initialize a SLIC_HANDLE for this command */
3288 SLIC_GET_SLIC_HANDLE(adapter, pslic_handle);
3289 if (pslic_handle == NULL)
3291 ASSERT(pslic_handle ==
3292 &adapter->slic_handles[pslic_handle->token.
3294 pslic_handle->type = SLIC_HANDLE_CMD;
3295 pslic_handle->address = (void *) cmd;
3296 pslic_handle->offset = (ushort) adapter->slic_handle_ix++;
3297 pslic_handle->other_handle = NULL;
3298 pslic_handle->next = NULL;
3300 cmd->pslic_handle = pslic_handle;
3301 cmd->cmd64.hosthandle = pslic_handle->token.handle_token;
3303 cmd->paddrl = phys_addrl;
3304 cmd->paddrh = phys_addrh;
3305 cmd->next_all = prev;
3308 phys_addrl += SLIC_HOSTCMD_SIZE;
3309 cmdaddr += SLIC_HOSTCMD_SIZE;
3311 cmd = (struct slic_hostcmd *)cmdaddr;
3315 cmdq = &adapter->cmdq_all;
3316 cmdq->count += cmdcnt; /* SLIC_CMDQ_CMDSINPAGE; mooktodo */
3317 tail->next_all = cmdq->head;
3319 cmdq = &adapter->cmdq_free;
3320 spin_lock_irqsave(&cmdq->lock.lock, cmdq->lock.flags);
3321 cmdq->count += cmdcnt; /* SLIC_CMDQ_CMDSINPAGE; mooktodo */
3322 tail->next = cmdq->head;
3324 spin_unlock_irqrestore(&cmdq->lock.lock, cmdq->lock.flags);
3327 static struct slic_hostcmd *slic_cmdq_getfree(struct adapter *adapter)
3329 struct slic_cmdqueue *cmdq = &adapter->cmdq_free;
3330 struct slic_hostcmd *cmd = NULL;
3333 spin_lock_irqsave(&cmdq->lock.lock, cmdq->lock.flags);
3337 cmdq->head = cmd->next;
3339 spin_unlock_irqrestore(&cmdq->lock.lock, cmdq->lock.flags);
3341 slic_cmdq_getdone(adapter);
3348 spin_unlock_irqrestore(&cmdq->lock.lock,
3350 pageaddr = slic_cmdqmem_addpage(adapter);
3352 slic_cmdq_addcmdpage(adapter, pageaddr);
3353 goto lock_and_retry;
3360 static void slic_cmdq_getdone(struct adapter *adapter)
3362 struct slic_cmdqueue *done_cmdq = &adapter->cmdq_done;
3363 struct slic_cmdqueue *free_cmdq = &adapter->cmdq_free;
3365 ASSERT(free_cmdq->head == NULL);
3366 spin_lock_irqsave(&done_cmdq->lock.lock, done_cmdq->lock.flags);
3368 free_cmdq->head = done_cmdq->head;
3369 free_cmdq->count = done_cmdq->count;
3370 done_cmdq->head = NULL;
3371 done_cmdq->tail = NULL;
3372 done_cmdq->count = 0;
3373 spin_unlock_irqrestore(&done_cmdq->lock.lock, done_cmdq->lock.flags);
3376 static void slic_cmdq_putdone_irq(struct adapter *adapter,
3377 struct slic_hostcmd *cmd)
3379 struct slic_cmdqueue *cmdq = &adapter->cmdq_done;
3381 spin_lock(&cmdq->lock.lock);
3383 cmd->next = cmdq->head;
3386 if ((adapter->xmitq_full) && (cmdq->count > 10))
3387 netif_wake_queue(adapter->netdev);
3388 spin_unlock(&cmdq->lock.lock);
3391 static int slic_rcvqueue_init(struct adapter *adapter)
3394 struct slic_rcvqueue *rcvq = &adapter->rcvqueue;
3396 ASSERT(adapter->state == ADAPT_DOWN);
3399 rcvq->size = SLIC_RCVQ_ENTRIES;
3402 i = (SLIC_RCVQ_ENTRIES / SLIC_RCVQ_FILLENTRIES);
3405 count += slic_rcvqueue_fill(adapter);
3408 if (rcvq->count < SLIC_RCVQ_MINENTRIES) {
3409 slic_rcvqueue_free(adapter);
3410 return STATUS_FAILURE;
3412 return STATUS_SUCCESS;
3415 static void slic_rcvqueue_free(struct adapter *adapter)
3417 struct slic_rcvqueue *rcvq = &adapter->rcvqueue;
3418 struct sk_buff *skb;
3420 while (rcvq->head) {
3422 rcvq->head = rcvq->head->next;
3430 static struct sk_buff *slic_rcvqueue_getnext(struct adapter *adapter)
3432 struct slic_rcvqueue *rcvq = &adapter->rcvqueue;
3433 struct sk_buff *skb;
3434 struct slic_rcvbuf *rcvbuf;
3439 rcvbuf = (struct slic_rcvbuf *)skb->head;
3442 if (rcvbuf->status & IRHDDR_SVALID) {
3443 rcvq->head = rcvq->head->next;
3450 dev_err(&adapter->netdev->dev,
3451 "RcvQ Empty!! rcvq[%p] count[%x]\n", rcvq, rcvq->count);
3454 while (rcvq->count < SLIC_RCVQ_FILLTHRESH) {
3455 count = slic_rcvqueue_fill(adapter);
3464 static int slic_rcvqueue_fill(struct adapter *adapter)
3469 struct slic_rcvqueue *rcvq = &adapter->rcvqueue;
3471 struct device *dev = &adapter->netdev->dev;
3473 while (i < SLIC_RCVQ_FILLENTRIES) {
3474 struct slic_rcvbuf *rcvbuf;
3475 struct sk_buff *skb;
3476 #ifdef KLUDGE_FOR_4GB_BOUNDARY
3479 skb = alloc_skb(SLIC_RCVQ_RCVBUFSIZE, GFP_ATOMIC);
3481 paddr = (void *)pci_map_single(adapter->pcidev,
3483 SLIC_RCVQ_RCVBUFSIZE,
3484 PCI_DMA_FROMDEVICE);
3485 paddrl = SLIC_GET_ADDR_LOW(paddr);
3486 paddrh = SLIC_GET_ADDR_HIGH(paddr);
3488 skb->len = SLIC_RCVBUF_HEADSIZE;
3489 rcvbuf = (struct slic_rcvbuf *)skb->head;
3492 #ifdef KLUDGE_FOR_4GB_BOUNDARY
3494 dev_err(dev, "%s: LOW 32bits PHYSICAL ADDRESS == 0\n",
3496 dev_err(dev, "skb[%p] PROBLEM\n", skb);
3497 dev_err(dev, " skbdata[%p]\n", skb->data);
3498 dev_err(dev, " skblen[%x]\n", skb->len);
3499 dev_err(dev, " paddr[%p]\n", paddr);
3500 dev_err(dev, " paddrl[%x]\n", paddrl);
3501 dev_err(dev, " paddrh[%x]\n", paddrh);
3502 dev_err(dev, " rcvq->head[%p]\n", rcvq->head);
3503 dev_err(dev, " rcvq->tail[%p]\n", rcvq->tail);
3504 dev_err(dev, " rcvq->count[%x]\n", rcvq->count);
3505 dev_err(dev, "SKIP THIS SKB!!!!!!!!\n");
3506 goto retry_rcvqfill;
3510 dev_err(dev, "%s: LOW 32bits PHYSICAL ADDRESS == 0\n",
3512 dev_err(dev, "skb[%p] PROBLEM\n", skb);
3513 dev_err(dev, " skbdata[%p]\n", skb->data);
3514 dev_err(dev, " skblen[%x]\n", skb->len);
3515 dev_err(dev, " paddr[%p]\n", paddr);
3516 dev_err(dev, " paddrl[%x]\n", paddrl);
3517 dev_err(dev, " paddrh[%x]\n", paddrh);
3518 dev_err(dev, " rcvq->head[%p]\n", rcvq->head);
3519 dev_err(dev, " rcvq->tail[%p]\n", rcvq->tail);
3520 dev_err(dev, " rcvq->count[%x]\n", rcvq->count);
3521 dev_err(dev, "GIVE TO CARD ANYWAY\n");
3525 slic_reg32_write(&adapter->slic_regs->slic_hbar,
3526 (u32)paddrl, DONT_FLUSH);
3528 slic_reg64_write(adapter,
3529 &adapter->slic_regs->slic_hbar64,
3531 &adapter->slic_regs->slic_addr_upper,
3532 paddrh, DONT_FLUSH);
3535 rcvq->tail->next = skb;
3542 dev_err(&adapter->netdev->dev,
3543 "slic_rcvqueue_fill could only get [%d] skbuffs\n",
3551 static u32 slic_rcvqueue_reinsert(struct adapter *adapter, struct sk_buff *skb)
3553 struct slic_rcvqueue *rcvq = &adapter->rcvqueue;
3557 struct slic_rcvbuf *rcvbuf = (struct slic_rcvbuf *)skb->head;
3560 ASSERT(skb->len == SLIC_RCVBUF_HEADSIZE);
3562 paddr = (void *)pci_map_single(adapter->pcidev, skb->head,
3563 SLIC_RCVQ_RCVBUFSIZE, PCI_DMA_FROMDEVICE);
3567 paddrl = SLIC_GET_ADDR_LOW(paddr);
3568 paddrh = SLIC_GET_ADDR_HIGH(paddr);
3571 dev = &adapter->netdev->dev;
3572 dev_err(dev, "%s: LOW 32bits PHYSICAL ADDRESS == 0\n",
3574 dev_err(dev, "skb[%p] PROBLEM\n", skb);
3575 dev_err(dev, " skbdata[%p]\n", skb->data);
3576 dev_err(dev, " skblen[%x]\n", skb->len);
3577 dev_err(dev, " paddr[%p]\n", paddr);
3578 dev_err(dev, " paddrl[%x]\n", paddrl);
3579 dev_err(dev, " paddrh[%x]\n", paddrh);
3580 dev_err(dev, " rcvq->head[%p]\n", rcvq->head);
3581 dev_err(dev, " rcvq->tail[%p]\n", rcvq->tail);
3582 dev_err(dev, " rcvq->count[%x]\n", rcvq->count);
3585 slic_reg32_write(&adapter->slic_regs->slic_hbar, (u32)paddrl,
3588 slic_reg64_write(adapter, &adapter->slic_regs->slic_hbar64,
3589 paddrl, &adapter->slic_regs->slic_addr_upper,
3590 paddrh, DONT_FLUSH);
3593 rcvq->tail->next = skb;
3601 static int slic_debug_card_show(struct seq_file *seq, void *v)
3605 struct sliccard *card = seq->private;
3606 struct slic_config *config = &card->config;
3607 unsigned char *fru = (unsigned char *)(&card->config.atk_fru);
3608 unsigned char *oemfru = (unsigned char *)(&card->config.OemFru);
3611 seq_printf(seq, "driver_version : %s\n", slic_proc_version);
3612 seq_printf(seq, "Microcode versions: \n");
3613 seq_printf(seq, " Gigabit (gb) : %s %s\n",
3614 MOJAVE_UCODE_VERS_STRING, MOJAVE_UCODE_VERS_DATE);
3615 seq_printf(seq, " Gigabit Receiver : %s %s\n",
3616 GB_RCVUCODE_VERS_STRING, GB_RCVUCODE_VERS_DATE);
3617 seq_printf(seq, "Vendor : %s\n", slic_vendor);
3618 seq_printf(seq, "Product Name : %s\n", slic_product_name);
3620 seq_printf(seq, "VendorId : %4.4X\n",
3622 seq_printf(seq, "DeviceId : %4.4X\n",
3624 seq_printf(seq, "RevisionId : %2.2x\n",
3625 config->RevisionId);
3626 seq_printf(seq, "Bus # : %d\n", card->busnumber);
3627 seq_printf(seq, "Device # : %d\n", card->slotnumber);
3628 seq_printf(seq, "Interfaces : %d\n", card->card_size);
3629 seq_printf(seq, " Initialized : %d\n",
3630 card->adapters_activated);
3631 seq_printf(seq, " Allocated : %d\n",
3632 card->adapters_allocated);
3633 ASSERT(card->card_size <= SLIC_NBR_MACS);
3634 for (i = 0; i < card->card_size; i++) {
3636 " MAC%d : %2.2X %2.2X %2.2X %2.2X %2.2X %2.2X\n",
3637 i, config->macinfo[i].macaddrA[0],
3638 config->macinfo[i].macaddrA[1],
3639 config->macinfo[i].macaddrA[2],
3640 config->macinfo[i].macaddrA[3],
3641 config->macinfo[i].macaddrA[4],
3642 config->macinfo[i].macaddrA[5]);
3644 seq_printf(seq, " IF Init State Duplex/Speed irq\n");
3645 seq_printf(seq, " -------------------------------\n");
3646 for (i = 0; i < card->adapters_allocated; i++) {
3647 struct adapter *adapter;
3649 adapter = card->adapter[i];
3652 " %d %d %s %s %s 0x%X\n",
3653 adapter->physport, adapter->state,
3654 SLIC_LINKSTATE(adapter->linkstate),
3655 SLIC_DUPLEX(adapter->linkduplex),
3656 SLIC_SPEED(adapter->linkspeed),
3657 (uint) adapter->irq);
3660 seq_printf(seq, "Generation # : %4.4X\n", card->gennumber);
3661 seq_printf(seq, "RcvQ max entries : %4.4X\n",
3663 seq_printf(seq, "Ping Status : %8.8X\n",
3665 seq_printf(seq, "Minimum grant : %2.2x\n",
3667 seq_printf(seq, "Maximum Latency : %2.2x\n", config->MaxLat);
3668 seq_printf(seq, "PciStatus : %4.4x\n",
3670 seq_printf(seq, "Debug Device Id : %4.4x\n",
3672 seq_printf(seq, "DRAM ROM Function : %4.4x\n",
3674 seq_printf(seq, "Network interface Pin 1 : %2.2x\n",
3675 config->NetIntPin1);
3676 seq_printf(seq, "Network interface Pin 2 : %2.2x\n",
3677 config->NetIntPin1);
3678 seq_printf(seq, "Network interface Pin 3 : %2.2x\n",
3679 config->NetIntPin1);
3680 seq_printf(seq, "PM capabilities : %4.4X\n",
3682 seq_printf(seq, "Network Clock Controls : %4.4X\n",
3683 config->NwClkCtrls);
3685 switch (config->FruFormat) {
3686 case ATK_FRU_FORMAT:
3689 "Vendor : Alacritech, Inc.\n");
3691 "Assembly # : %c%c%c%c%c%c\n",
3692 fru[0], fru[1], fru[2], fru[3], fru[4],
3695 "Revision # : %c%c\n",
3698 if (config->OEMFruFormat == VENDOR4_FRU_FORMAT) {
3701 "%c%c%c%c%c%c%c%c%c%c%c%c\n",
3702 fru[8], fru[9], fru[10],
3703 fru[11], fru[12], fru[13],
3704 fru[16], fru[17], fru[18],
3705 fru[19], fru[20], fru[21]);
3709 "%c%c%c%c%c%c%c%c%c%c%c%c%c%c\n",
3710 fru[8], fru[9], fru[10],
3711 fru[11], fru[12], fru[13],
3712 fru[14], fru[15], fru[16],
3713 fru[17], fru[18], fru[19],
3722 "Vendor : Alacritech, Inc.\n");
3724 "Serial # : Empty FRU\n");
3729 switch (config->OEMFruFormat) {
3730 case VENDOR1_FRU_FORMAT:
3732 seq_printf(seq, "FRU Information:\n");
3733 seq_printf(seq, " Commodity # : %c\n",
3736 " Assembly # : %c%c%c%c\n",
3737 oemfru[1], oemfru[2], oemfru[3], oemfru[4]);
3739 " Revision # : %c%c\n",
3740 oemfru[5], oemfru[6]);
3742 " Supplier # : %c%c\n",
3743 oemfru[7], oemfru[8]);
3746 oemfru[9], oemfru[10]);
3748 " Sequence # : %c%c%c\n",
3749 oemfru[11], oemfru[12], oemfru[13]);
3753 case VENDOR2_FRU_FORMAT:
3755 seq_printf(seq, "FRU Information:\n");
3758 "%c%c%c%c%c%c%c%c\n",
3759 oemfru[0], oemfru[1], oemfru[2],
3760 oemfru[3], oemfru[4], oemfru[5],
3761 oemfru[6], oemfru[7]);
3763 " Supplier # : %c%c%c%c%c\n",
3764 oemfru[8], oemfru[9], oemfru[10],
3765 oemfru[11], oemfru[12]);
3768 oemfru[13], oemfru[14], oemfru[15]);
3770 " Sequence # : %c%c%c%c\n",
3771 oemfru[16], oemfru[17], oemfru[18],
3776 case VENDOR3_FRU_FORMAT:
3778 seq_printf(seq, "FRU Information:\n");
3781 case VENDOR4_FRU_FORMAT:
3783 seq_printf(seq, "FRU Information:\n");
3786 "%c%c%c%c%c%c%c%c\n",
3787 oemfru[0], oemfru[1], oemfru[2],
3788 oemfru[3], oemfru[4], oemfru[5],
3789 oemfru[6], oemfru[7]);
3792 "%c%c%c%c%c%c%c%c\n",
3793 oemfru[8], oemfru[9], oemfru[10],
3794 oemfru[11], oemfru[12], oemfru[13],
3795 oemfru[14], oemfru[15]);
3798 "%c%c%c%c%c%c%c%c\n",
3799 oemfru[16], oemfru[17], oemfru[18],
3800 oemfru[19], oemfru[20], oemfru[21],
3801 oemfru[22], oemfru[23]);
3813 static int slic_debug_adapter_show(struct seq_file *seq, void *v)
3815 struct adapter *adapter = seq->private;
3817 if ((adapter->netdev) && (adapter->netdev->name)) {
3818 seq_printf(seq, "info: interface : %s\n",
3819 adapter->netdev->name);
3821 seq_printf(seq, "info: status : %s\n",
3822 SLIC_LINKSTATE(adapter->linkstate));
3823 seq_printf(seq, "info: port : %d\n",
3825 seq_printf(seq, "info: speed : %s\n",
3826 SLIC_SPEED(adapter->linkspeed));
3827 seq_printf(seq, "info: duplex : %s\n",
3828 SLIC_DUPLEX(adapter->linkduplex));
3829 seq_printf(seq, "info: irq : 0x%X\n",
3830 (uint) adapter->irq);
3831 seq_printf(seq, "info: Interrupt Agg Delay: %d usec\n",
3832 adapter->card->loadlevel_current);
3833 seq_printf(seq, "info: RcvQ max entries : %4.4X\n",
3835 seq_printf(seq, "info: RcvQ current : %4.4X\n",
3836 adapter->rcvqueue.count);
3837 seq_printf(seq, "rx stats: packets : %8.8lX\n",
3838 adapter->stats.rx_packets);
3839 seq_printf(seq, "rx stats: bytes : %8.8lX\n",
3840 adapter->stats.rx_bytes);
3841 seq_printf(seq, "rx stats: broadcasts : %8.8X\n",
3842 adapter->rcv_broadcasts);
3843 seq_printf(seq, "rx stats: multicasts : %8.8X\n",
3844 adapter->rcv_multicasts);
3845 seq_printf(seq, "rx stats: unicasts : %8.8X\n",
3846 adapter->rcv_unicasts);
3847 seq_printf(seq, "rx stats: errors : %8.8X\n",
3848 (u32) adapter->slic_stats.iface.rcv_errors);
3849 seq_printf(seq, "rx stats: Missed errors : %8.8X\n",
3850 (u32) adapter->slic_stats.iface.rcv_discards);
3851 seq_printf(seq, "rx stats: drops : %8.8X\n",
3852 (u32) adapter->rcv_drops);
3853 seq_printf(seq, "tx stats: packets : %8.8lX\n",
3854 adapter->stats.tx_packets);
3855 seq_printf(seq, "tx stats: bytes : %8.8lX\n",
3856 adapter->stats.tx_bytes);
3857 seq_printf(seq, "tx stats: errors : %8.8X\n",
3858 (u32) adapter->slic_stats.iface.xmt_errors);
3859 seq_printf(seq, "rx stats: multicasts : %8.8lX\n",
3860 adapter->stats.multicast);
3861 seq_printf(seq, "tx stats: collision errors : %8.8X\n",
3862 (u32) adapter->slic_stats.iface.xmit_collisions);
3863 seq_printf(seq, "perf: Max rcv frames/isr : %8.8X\n",
3864 adapter->max_isr_rcvs);
3865 seq_printf(seq, "perf: Rcv interrupt yields : %8.8X\n",
3866 adapter->rcv_interrupt_yields);
3867 seq_printf(seq, "perf: Max xmit complete/isr : %8.8X\n",
3868 adapter->max_isr_xmits);
3869 seq_printf(seq, "perf: error interrupts : %8.8X\n",
3870 adapter->error_interrupts);
3871 seq_printf(seq, "perf: error rmiss interrupts : %8.8X\n",
3872 adapter->error_rmiss_interrupts);
3873 seq_printf(seq, "perf: rcv interrupts : %8.8X\n",
3874 adapter->rcv_interrupts);
3875 seq_printf(seq, "perf: xmit interrupts : %8.8X\n",
3876 adapter->xmit_interrupts);
3877 seq_printf(seq, "perf: link event interrupts : %8.8X\n",
3878 adapter->linkevent_interrupts);
3879 seq_printf(seq, "perf: UPR interrupts : %8.8X\n",
3880 adapter->upr_interrupts);
3881 seq_printf(seq, "perf: interrupt count : %8.8X\n",
3883 seq_printf(seq, "perf: false interrupts : %8.8X\n",
3884 adapter->false_interrupts);
3885 seq_printf(seq, "perf: All register writes : %8.8X\n",
3886 adapter->all_reg_writes);
3887 seq_printf(seq, "perf: ICR register writes : %8.8X\n",
3888 adapter->icr_reg_writes);
3889 seq_printf(seq, "perf: ISR register writes : %8.8X\n",
3890 adapter->isr_reg_writes);
3891 seq_printf(seq, "ifevents: overflow 802 errors : %8.8X\n",
3892 adapter->if_events.oflow802);
3893 seq_printf(seq, "ifevents: transport overflow errors: %8.8X\n",
3894 adapter->if_events.Tprtoflow);
3895 seq_printf(seq, "ifevents: underflow errors : %8.8X\n",
3896 adapter->if_events.uflow802);
3897 seq_printf(seq, "ifevents: receive early : %8.8X\n",
3898 adapter->if_events.rcvearly);
3899 seq_printf(seq, "ifevents: buffer overflows : %8.8X\n",
3900 adapter->if_events.Bufov);
3901 seq_printf(seq, "ifevents: carrier errors : %8.8X\n",
3902 adapter->if_events.Carre);
3903 seq_printf(seq, "ifevents: Long : %8.8X\n",
3904 adapter->if_events.Longe);
3905 seq_printf(seq, "ifevents: invalid preambles : %8.8X\n",
3906 adapter->if_events.Invp);
3907 seq_printf(seq, "ifevents: CRC errors : %8.8X\n",
3908 adapter->if_events.Crc);
3909 seq_printf(seq, "ifevents: dribble nibbles : %8.8X\n",
3910 adapter->if_events.Drbl);
3911 seq_printf(seq, "ifevents: Code violations : %8.8X\n",
3912 adapter->if_events.Code);
3913 seq_printf(seq, "ifevents: TCP checksum errors : %8.8X\n",
3914 adapter->if_events.TpCsum);
3915 seq_printf(seq, "ifevents: TCP header short errors : %8.8X\n",
3916 adapter->if_events.TpHlen);
3917 seq_printf(seq, "ifevents: IP checksum errors : %8.8X\n",
3918 adapter->if_events.IpCsum);
3919 seq_printf(seq, "ifevents: IP frame incompletes : %8.8X\n",
3920 adapter->if_events.IpLen);
3921 seq_printf(seq, "ifevents: IP headers shorts : %8.8X\n",
3922 adapter->if_events.IpHlen);
3926 static int slic_debug_adapter_open(struct inode *inode, struct file *file)
3928 return single_open(file, slic_debug_adapter_show, inode->i_private);
3931 static int slic_debug_card_open(struct inode *inode, struct file *file)
3933 return single_open(file, slic_debug_card_show, inode->i_private);
3936 static const struct file_operations slic_debug_adapter_fops = {
3937 .owner = THIS_MODULE,
3938 .open = slic_debug_adapter_open,
3940 .llseek = seq_lseek,
3941 .release = single_release,
3944 static const struct file_operations slic_debug_card_fops = {
3945 .owner = THIS_MODULE,
3946 .open = slic_debug_card_open,
3948 .llseek = seq_lseek,
3949 .release = single_release,
3952 static void slic_debug_adapter_create(struct adapter *adapter)
3956 struct sliccard *card = adapter->card;
3958 if (!card->debugfs_dir)
3961 sprintf(name, "port%d", adapter->port);
3962 d = debugfs_create_file(name, S_IRUGO,
3963 card->debugfs_dir, adapter,
3964 &slic_debug_adapter_fops);
3965 if (!d || IS_ERR(d))
3966 pr_info(PFX "%s: debugfs create failed\n", name);
3968 adapter->debugfs_entry = d;
3971 static void slic_debug_adapter_destroy(struct adapter *adapter)
3973 if (adapter->debugfs_entry) {
3974 debugfs_remove(adapter->debugfs_entry);
3975 adapter->debugfs_entry = NULL;
3979 static void slic_debug_card_create(struct sliccard *card)
3982 char name[IFNAMSIZ];
3984 snprintf(name, sizeof(name), "slic%d", card->cardnum);
3985 d = debugfs_create_dir(name, slic_debugfs);
3986 if (!d || IS_ERR(d))
3987 pr_info(PFX "%s: debugfs create dir failed\n",
3990 card->debugfs_dir = d;
3991 d = debugfs_create_file("cardinfo", S_IRUGO,
3993 &slic_debug_card_fops);
3994 if (!d || IS_ERR(d))
3995 pr_info(PFX "%s: debugfs create failed\n",
3998 card->debugfs_cardinfo = d;
4002 static void slic_debug_card_destroy(struct sliccard *card)
4006 for (i = 0; i < card->card_size; i++) {
4007 struct adapter *adapter;
4009 adapter = card->adapter[i];
4011 slic_debug_adapter_destroy(adapter);
4013 if (card->debugfs_cardinfo) {
4014 debugfs_remove(card->debugfs_cardinfo);
4015 card->debugfs_cardinfo = NULL;
4017 if (card->debugfs_dir) {
4018 debugfs_remove(card->debugfs_dir);
4019 card->debugfs_dir = NULL;
4023 static void slic_debug_init(void)
4027 ent = debugfs_create_dir("slic", NULL);
4028 if (!ent || IS_ERR(ent)) {
4029 pr_info(PFX "debugfs create directory failed\n");
4036 static void slic_debug_cleanup(void)
4039 debugfs_remove(slic_debugfs);
4040 slic_debugfs = NULL;
4044 /******************************************************************************/
4045 /**************** MODULE INITIATION / TERMINATION FUNCTIONS ***************/
4046 /******************************************************************************/
4048 static struct pci_driver slic_driver = {
4050 .id_table = slic_pci_tbl,
4051 .probe = slic_entry_probe,
4052 .remove = slic_entry_remove,
4055 static int __init slic_module_init(void)
4059 if (debug >= 0 && slic_debug != debug)
4060 printk(KERN_DEBUG KBUILD_MODNAME ": debug level is %d.\n",
4065 return pci_register_driver(&slic_driver);
4068 static void __exit slic_module_cleanup(void)
4070 pci_unregister_driver(&slic_driver);
4071 slic_debug_cleanup();
4074 module_init(slic_module_init);
4075 module_exit(slic_module_cleanup);