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 SLIC_DUMP_ENABLED 0
59 #define KLUDGE_FOR_4GB_BOUNDARY 1
60 #define DEBUG_MICROCODE 1
61 #define SLIC_PRODUCTION_BUILD 1
62 #define SLIC_FAILURE_RESET 1
64 #define SLIC_ASSERT_ENABLED 1
65 #define SLIC_GET_STATS_ENABLED 1
66 #define SLIC_GET_STATS_TIMER_ENABLED 0
67 #define SLIC_PING_TIMER_ENABLED 1
68 #define SLIC_POWER_MANAGEMENT_ENABLED 0
69 #define SLIC_INTERRUPT_PROCESS_LIMIT 1
70 #define LINUX_FREES_ADAPTER_RESOURCES 1
71 #define SLIC_OFFLOAD_IP_CHECKSUM 1
72 #define STATS_TIMER_INTERVAL 2
73 #define PING_TIMER_INTERVAL 1
75 #include <linux/kernel.h>
76 #include <linux/string.h>
77 #include <linux/errno.h>
78 #include <linux/ioport.h>
79 #include <linux/slab.h>
80 #include <linux/interrupt.h>
81 #include <linux/timer.h>
82 #include <linux/pci.h>
83 #include <linux/spinlock.h>
84 #include <linux/init.h>
85 #include <linux/bitops.h>
87 #include <linux/netdevice.h>
88 #include <linux/etherdevice.h>
89 #include <linux/skbuff.h>
90 #include <linux/delay.h>
91 #include <linux/debugfs.h>
92 #include <linux/seq_file.h>
93 #include <linux/kthread.h>
94 #include <linux/module.h>
95 #include <linux/moduleparam.h>
97 #include <linux/firmware.h>
98 #include <linux/types.h>
99 #include <linux/dma-mapping.h>
100 #include <linux/mii.h>
101 #include <linux/if_vlan.h>
102 #include <asm/unaligned.h>
104 #include <linux/ethtool.h>
105 #define SLIC_ETHTOOL_SUPPORT 1
107 #include <linux/uaccess.h>
110 #if SLIC_DUMP_ENABLED
111 #include "slicdump.h"
114 #define SLIC_POWER_MANAGEMENT 0
116 static uint slic_first_init = 1;
117 static char *slic_banner = "Alacritech SLIC Technology(tm) Server "\
118 "and Storage Accelerator (Non-Accelerated)\n";
120 static char *slic_proc_version = "2.0.351 2006/07/14 12:26:00";
121 static char *slic_product_name = "SLIC Technology(tm) Server "\
122 "and Storage Accelerator (Non-Accelerated)";
123 static char *slic_vendor = "Alacritech, Inc.";
125 static int slic_debug = 1;
126 static int debug = -1;
127 static struct net_device *head_netdevice;
129 static struct base_driver slic_global = { {}, 0, 0, 0, 1, NULL, NULL };
130 static int intagg_delay = 100;
131 static u32 dynamic_intagg;
134 static unsigned int rcv_count;
135 static struct dentry *slic_debugfs;
137 #define DRV_NAME "slicoss"
138 #define DRV_VERSION "2.0.1"
139 #define DRV_AUTHOR "Alacritech, Inc. Engineering"
140 #define DRV_DESCRIPTION "Alacritech SLIC Techonology(tm) "\
141 "Non-Accelerated Driver"
142 #define DRV_COPYRIGHT "Copyright 2000-2006 Alacritech, Inc. "\
143 "All rights reserved."
144 #define PFX DRV_NAME " "
146 MODULE_AUTHOR(DRV_AUTHOR);
147 MODULE_DESCRIPTION(DRV_DESCRIPTION);
148 MODULE_LICENSE("Dual BSD/GPL");
150 module_param(dynamic_intagg, int, 0);
151 MODULE_PARM_DESC(dynamic_intagg, "Dynamic Interrupt Aggregation Setting");
152 module_param(intagg_delay, int, 0);
153 MODULE_PARM_DESC(intagg_delay, "uSec Interrupt Aggregation Delay");
155 static struct pci_device_id slic_pci_tbl[] __devinitdata = {
156 {PCI_VENDOR_ID_ALACRITECH,
158 PCI_ANY_ID, PCI_ANY_ID,},
159 {PCI_VENDOR_ID_ALACRITECH,
161 PCI_ANY_ID, PCI_ANY_ID,},
165 MODULE_DEVICE_TABLE(pci, slic_pci_tbl);
167 #define SLIC_GET_SLIC_HANDLE(_adapter, _pslic_handle) \
169 spin_lock_irqsave(&_adapter->handle_lock.lock, \
170 _adapter->handle_lock.flags); \
171 _pslic_handle = _adapter->pfree_slic_handles; \
172 if (_pslic_handle) { \
173 ASSERT(_pslic_handle->type == SLIC_HANDLE_FREE); \
174 _adapter->pfree_slic_handles = _pslic_handle->next; \
176 spin_unlock_irqrestore(&_adapter->handle_lock.lock, \
177 _adapter->handle_lock.flags); \
180 #define SLIC_FREE_SLIC_HANDLE(_adapter, _pslic_handle) \
182 _pslic_handle->type = SLIC_HANDLE_FREE; \
183 spin_lock_irqsave(&_adapter->handle_lock.lock, \
184 _adapter->handle_lock.flags); \
185 _pslic_handle->next = _adapter->pfree_slic_handles; \
186 _adapter->pfree_slic_handles = _pslic_handle; \
187 spin_unlock_irqrestore(&_adapter->handle_lock.lock, \
188 _adapter->handle_lock.flags); \
191 static void slic_debug_init(void);
192 static void slic_debug_cleanup(void);
193 static void slic_debug_adapter_create(struct adapter *adapter);
194 static void slic_debug_adapter_destroy(struct adapter *adapter);
195 static void slic_debug_card_create(struct sliccard *card);
196 static void slic_debug_card_destroy(struct sliccard *card);
198 static inline void slic_reg32_write(void __iomem *reg, u32 value, uint flush)
205 static inline void slic_reg64_write(struct adapter *adapter,
208 void __iomem *regh, u32 paddrh, uint flush)
210 spin_lock_irqsave(&adapter->bit64reglock.lock,
211 adapter->bit64reglock.flags);
212 if (paddrh != adapter->curaddrupper) {
213 adapter->curaddrupper = paddrh;
214 writel(paddrh, regh);
219 spin_unlock_irqrestore(&adapter->bit64reglock.lock,
220 adapter->bit64reglock.flags);
223 static void slic_init_driver(void)
225 if (slic_first_init) {
226 DBG_MSG("slicoss: %s slic_first_init set jiffies[%lx]\n",
229 spin_lock_init(&slic_global.driver_lock.lock);
234 static void slic_dbg_macaddrs(struct adapter *adapter)
236 DBG_MSG(" (%s) curr %2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X\n",
237 adapter->netdev->name, adapter->currmacaddr[0],
238 adapter->currmacaddr[1], adapter->currmacaddr[2],
239 adapter->currmacaddr[3], adapter->currmacaddr[4],
240 adapter->currmacaddr[5]);
241 DBG_MSG(" (%s) mac %2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X\n",
242 adapter->netdev->name, adapter->macaddr[0],
243 adapter->macaddr[1], adapter->macaddr[2],
244 adapter->macaddr[3], adapter->macaddr[4], adapter->macaddr[5]);
248 #ifdef DEBUG_REGISTER_TRACE
249 static void slic_dbg_register_trace(struct adapter *adapter,
250 struct sliccard *card)
254 DBG_ERROR("Dump Register Write Trace: curr_ix == %d\n", card->debug_ix);
255 for (i = 0; i < 32; i++) {
256 DBG_ERROR("%2d %d %4x %x %x\n",
257 i, card->reg_type[i], card->reg_offset[i],
258 card->reg_value[i], card->reg_valueh[i]);
263 static void slic_init_adapter(struct net_device *netdev,
264 struct pci_dev *pcidev,
265 const struct pci_device_id *pci_tbl_entry,
266 void __iomem *memaddr, int chip_idx)
269 struct slic_handle *pslic_handle;
270 struct adapter *adapter = (struct adapter *)netdev_priv(netdev);
272 DBG_MSG("slicoss: %s (%s)\n netdev [%p]\n adapter[%p]\n "
273 "pcidev [%p]\n", __func__, netdev->name, netdev, adapter, pcidev);*/
274 /* adapter->pcidev = pcidev;*/
275 adapter->vendid = pci_tbl_entry->vendor;
276 adapter->devid = pci_tbl_entry->device;
277 adapter->subsysid = pci_tbl_entry->subdevice;
278 adapter->busnumber = pcidev->bus->number;
279 adapter->slotnumber = ((pcidev->devfn >> 3) & 0x1F);
280 adapter->functionnumber = (pcidev->devfn & 0x7);
281 adapter->memorylength = pci_resource_len(pcidev, 0);
282 adapter->slic_regs = (__iomem struct slic_regs *)memaddr;
283 adapter->irq = pcidev->irq;
284 /* adapter->netdev = netdev;*/
285 adapter->next_netdevice = head_netdevice;
286 head_netdevice = netdev;
287 adapter->chipid = chip_idx;
288 adapter->port = 0; /*adapter->functionnumber;*/
289 adapter->cardindex = adapter->port;
290 adapter->memorybase = memaddr;
291 spin_lock_init(&adapter->upr_lock.lock);
292 spin_lock_init(&adapter->bit64reglock.lock);
293 spin_lock_init(&adapter->adapter_lock.lock);
294 spin_lock_init(&adapter->reset_lock.lock);
295 spin_lock_init(&adapter->handle_lock.lock);
297 adapter->card_size = 1;
299 Initialize slic_handle array
301 ASSERT(SLIC_CMDQ_MAXCMDS <= 0xFFFF);
303 Start with 1. 0 is an invalid host handle.
305 for (index = 1, pslic_handle = &adapter->slic_handles[1];
306 index < SLIC_CMDQ_MAXCMDS; index++, pslic_handle++) {
308 pslic_handle->token.handle_index = index;
309 pslic_handle->type = SLIC_HANDLE_FREE;
310 pslic_handle->next = adapter->pfree_slic_handles;
311 adapter->pfree_slic_handles = pslic_handle;
314 DBG_MSG(".........\nix[%d] phandle[%p] pfree[%p] next[%p]\n",
315 index, pslic_handle, adapter->pfree_slic_handles, pslic_handle->next);*/
316 adapter->pshmem = (struct slic_shmem *)
317 pci_alloc_consistent(adapter->pcidev,
318 sizeof(struct slic_shmem),
322 DBG_MSG("slicoss: %s (%s)\n pshmem [%p]\n phys_shmem[%p]\n"\
323 "slic_regs [%p]\n", __func__, netdev->name, adapter->pshmem,
324 (void *)adapter->phys_shmem, adapter->slic_regs);
326 ASSERT(adapter->pshmem);
328 memset(adapter->pshmem, 0, sizeof(struct slic_shmem));
333 static int __devinit slic_entry_probe(struct pci_dev *pcidev,
334 const struct pci_device_id *pci_tbl_entry)
336 static int cards_found;
337 static int did_version;
339 struct net_device *netdev;
340 struct adapter *adapter;
341 void __iomem *memmapped_ioaddr = NULL;
343 ulong mmio_start = 0;
345 struct sliccard *card = NULL;
347 DBG_MSG("slicoss: %s 2.6 VERSION ENTER jiffies[%lx] cpu %d\n",
348 __func__, jiffies, smp_processor_id());
350 slic_global.dynamic_intagg = dynamic_intagg;
352 err = pci_enable_device(pcidev);
354 DBG_MSG("Call pci_enable_device(%p) status[%x]\n", pcidev, err);
358 if (slic_debug > 0 && did_version++ == 0) {
360 printk(slic_proc_version);
363 err = pci_set_dma_mask(pcidev, DMA_64BIT_MASK);
365 DBG_MSG("pci_set_dma_mask(DMA_64BIT_MASK) successful\n");
367 err = pci_set_dma_mask(pcidev, DMA_32BIT_MASK);
370 ("No usable DMA configuration, aborting err[%x]\n",
372 goto err_out_disable_pci;
374 DBG_MSG("pci_set_dma_mask(DMA_32BIT_MASK) successful\n");
377 DBG_MSG("Call pci_request_regions\n");
379 err = pci_request_regions(pcidev, DRV_NAME);
381 DBG_MSG("pci_request_regions FAILED err[%x]\n", err);
382 goto err_out_disable_pci;
385 DBG_MSG("call pci_set_master\n");
386 pci_set_master(pcidev);
388 DBG_MSG("call alloc_etherdev\n");
389 netdev = alloc_etherdev(sizeof(struct adapter));
392 goto err_out_exit_slic_probe;
394 DBG_MSG("alloc_etherdev for slic netdev[%p]\n", netdev);
396 SET_NETDEV_DEV(netdev, &pcidev->dev);
398 pci_set_drvdata(pcidev, netdev);
399 adapter = netdev_priv(netdev);
400 adapter->netdev = netdev;
401 adapter->pcidev = pcidev;
403 mmio_start = pci_resource_start(pcidev, 0);
404 mmio_len = pci_resource_len(pcidev, 0);
406 DBG_MSG("slicoss: call ioremap(mmio_start[%lx], mmio_len[%lx])\n",
407 mmio_start, mmio_len);
409 /* memmapped_ioaddr = (u32)ioremap_nocache(mmio_start, mmio_len);*/
410 memmapped_ioaddr = ioremap(mmio_start, mmio_len);
411 DBG_MSG("slicoss: %s MEMMAPPED_IOADDR [%p]\n", __func__,
413 if (!memmapped_ioaddr) {
414 DBG_ERROR("%s cannot remap MMIO region %lx @ %lx\n",
415 __func__, mmio_len, mmio_start);
416 goto err_out_free_netdev;
420 ("slicoss: %s found Alacritech SLICOSS PCI, MMIO at %p, "\
421 "start[%lx] len[%lx], IRQ %d.\n",
422 __func__, memmapped_ioaddr, mmio_start, mmio_len, pcidev->irq);
424 slic_config_pci(pcidev);
428 slic_init_adapter(netdev,
429 pcidev, pci_tbl_entry, memmapped_ioaddr, cards_found);
431 status = slic_card_locate(adapter);
433 DBG_ERROR("%s cannot locate card\n", __func__);
434 goto err_out_free_mmio_region;
437 card = adapter->card;
439 if (!adapter->allocated) {
440 card->adapters_allocated++;
441 adapter->allocated = 1;
444 DBG_MSG("slicoss: %s card: %p\n", __func__,
446 DBG_MSG("slicoss: %s card->adapter[%d] == [%p]\n", __func__,
447 (uint) adapter->port, adapter);
448 DBG_MSG("slicoss: %s card->adapters_allocated [%d]\n", __func__,
449 card->adapters_allocated);
450 DBG_MSG("slicoss: %s card->adapters_activated [%d]\n", __func__,
451 card->adapters_activated);
453 status = slic_card_init(card, adapter);
455 if (status != STATUS_SUCCESS) {
456 card->state = CARD_FAIL;
457 adapter->state = ADAPT_FAIL;
458 adapter->linkstate = LINK_DOWN;
459 DBG_ERROR("slic_card_init FAILED status[%x]\n", status);
461 slic_adapter_set_hwaddr(adapter);
464 netdev->base_addr = (unsigned long)adapter->memorybase;
465 netdev->irq = adapter->irq;
466 netdev->open = slic_entry_open;
467 netdev->stop = slic_entry_halt;
468 netdev->hard_start_xmit = slic_xmit_start;
469 netdev->do_ioctl = slic_ioctl;
470 netdev->set_mac_address = slic_mac_set_address;
471 #if SLIC_GET_STATS_ENABLED
472 netdev->get_stats = slic_get_stats;
474 netdev->set_multicast_list = slic_mcast_set_list;
476 slic_debug_adapter_create(adapter);
478 strcpy(netdev->name, "eth%d");
479 err = register_netdev(netdev);
481 DBG_ERROR("Cannot register net device, aborting.\n");
486 ("slicoss: addr 0x%lx, irq %d, MAC addr "\
487 "%02X:%02X:%02X:%02X:%02X:%02X\n",
488 mmio_start, /*pci_resource_start(pcidev, 0), */ pcidev->irq,
489 netdev->dev_addr[0], netdev->dev_addr[1], netdev->dev_addr[2],
490 netdev->dev_addr[3], netdev->dev_addr[4], netdev->dev_addr[5]);
493 DBG_MSG("slicoss: %s EXIT status[%x] jiffies[%lx] cpu %d\n",
494 __func__, status, jiffies, smp_processor_id());
499 iounmap(memmapped_ioaddr);
500 err_out_free_mmio_region:
501 release_mem_region(mmio_start, mmio_len);
504 err_out_exit_slic_probe:
505 pci_release_regions(pcidev);
506 DBG_ERROR("%s EXIT jiffies[%lx] cpu %d\n", __func__, jiffies,
509 pci_disable_device(pcidev);
513 static int slic_entry_open(struct net_device *dev)
515 struct adapter *adapter = (struct adapter *) netdev_priv(dev);
516 struct sliccard *card = adapter->card;
523 ("slicoss: %s adapter->activated[%d] card->adapters[%x] "\
524 "allocd[%x]\n", __func__, adapter->activated,
525 card->adapters_activated,
526 card->adapters_allocated);
528 ("slicoss: %s (%s): [jiffies[%lx] cpu %d] dev[%p] adapt[%p] "\
529 "port[%d] card[%p]\n",
530 __func__, adapter->netdev->name, jiffies, smp_processor_id(),
531 adapter->netdev, adapter, adapter->port, card);
533 netif_stop_queue(adapter->netdev);
535 spin_lock_irqsave(&slic_global.driver_lock.lock,
536 slic_global.driver_lock.flags);
538 if (!adapter->activated) {
539 card->adapters_activated++;
540 slic_global.num_slic_ports_active++;
541 adapter->activated = 1;
543 status = slic_if_init(adapter);
545 if (status != STATUS_SUCCESS) {
546 if (adapter->activated) {
547 card->adapters_activated--;
548 slic_global.num_slic_ports_active--;
549 adapter->activated = 0;
552 spin_unlock_irqrestore(&slic_global.driver_lock.lock,
553 slic_global.driver_lock.flags);
558 DBG_MSG("slicoss: %s set card->master[%p] adapter[%p]\n", __func__,
559 card->master, adapter);
561 card->master = adapter;
562 #if SLIC_DUMP_ENABLED
563 if (!(card->dumpthread_running))
564 init_waitqueue_head(&card->dump_wq);
568 spin_unlock_irqrestore(&slic_global.driver_lock.lock,
569 slic_global.driver_lock.flags);
572 #if SLIC_DUMP_ENABLED
573 if (!(card->dumpthread_running)) {
574 DBG_MSG("attempt to initialize dump thread\n");
575 status = slic_init_dump_thread(card);
577 Even if the dump thread fails, we will continue at this point
582 return STATUS_SUCCESS;
585 static void __devexit slic_entry_remove(struct pci_dev *pcidev)
587 struct net_device *dev = pci_get_drvdata(pcidev);
590 struct adapter *adapter = (struct adapter *) netdev_priv(dev);
591 struct sliccard *card;
592 struct mcast_address *mcaddr, *mlist;
595 DBG_MSG("slicoss: %s ENTER dev[%p] adapter[%p]\n", __func__, dev,
597 slic_adapter_freeresources(adapter);
598 slic_unmap_mmio_space(adapter);
599 DBG_MSG("slicoss: %s unregister_netdev\n", __func__);
600 unregister_netdev(dev);
602 mmio_start = pci_resource_start(pcidev, 0);
603 mmio_len = pci_resource_len(pcidev, 0);
605 DBG_MSG("slicoss: %s rel_region(0) start[%x] len[%x]\n", __func__,
606 mmio_start, mmio_len);
607 release_mem_region(mmio_start, mmio_len);
609 DBG_MSG("slicoss: %s iounmap dev->base_addr[%x]\n", __func__,
610 (uint) dev->base_addr);
611 iounmap((void __iomem *)dev->base_addr);
612 /* free multicast addresses */
613 mlist = adapter->mcastaddrs;
619 ASSERT(adapter->card);
620 card = adapter->card;
621 ASSERT(card->adapters_allocated);
622 card->adapters_allocated--;
623 adapter->allocated = 0;
625 ("slicoss: %s init[%x] alloc[%x] card[%p] adapter[%p]\n",
626 __func__, card->adapters_activated, card->adapters_allocated,
628 if (!card->adapters_allocated) {
629 struct sliccard *curr_card = slic_global.slic_card;
630 if (curr_card == card) {
631 slic_global.slic_card = card->next;
633 while (curr_card->next != card)
634 curr_card = curr_card->next;
636 curr_card->next = card->next;
638 ASSERT(slic_global.num_slic_cards);
639 slic_global.num_slic_cards--;
640 slic_card_cleanup(card);
642 DBG_MSG("slicoss: %s deallocate device\n", __func__);
644 pci_release_regions(pcidev);
645 DBG_MSG("slicoss: %s EXIT\n", __func__);
648 static int slic_entry_halt(struct net_device *dev)
650 struct adapter *adapter = (struct adapter *)netdev_priv(dev);
651 struct sliccard *card = adapter->card;
652 __iomem struct slic_regs *slic_regs = adapter->slic_regs;
654 spin_lock_irqsave(&slic_global.driver_lock.lock,
655 slic_global.driver_lock.flags);
657 DBG_MSG("slicoss: %s (%s) ENTER\n", __func__, dev->name);
658 DBG_MSG("slicoss: %s (%s) actvtd[%d] alloc[%d] state[%x] adapt[%p]\n",
659 __func__, dev->name, card->adapters_activated,
660 card->adapters_allocated, card->state, adapter);
661 slic_if_stop_queue(adapter);
662 adapter->state = ADAPT_DOWN;
663 adapter->linkstate = LINK_DOWN;
664 adapter->upr_list = NULL;
665 adapter->upr_busy = 0;
666 adapter->devflags_prev = 0;
667 DBG_MSG("slicoss: %s (%s) set adapter[%p] state to ADAPT_DOWN(%d)\n",
668 __func__, dev->name, adapter, adapter->state);
669 ASSERT(card->adapter[adapter->cardindex] == adapter);
670 WRITE_REG(slic_regs->slic_icr, ICR_INT_OFF, FLUSH);
671 adapter->all_reg_writes++;
672 adapter->icr_reg_writes++;
673 slic_config_clear(adapter);
674 DBG_MSG("slicoss: %s (%s) dev[%p] adapt[%p] card[%p]\n",
675 __func__, dev->name, dev, adapter, card);
676 if (adapter->activated) {
677 card->adapters_activated--;
678 slic_global.num_slic_ports_active--;
679 adapter->activated = 0;
681 #ifdef AUTOMATIC_RESET
682 WRITE_REG(slic_regs->slic_reset_iface, 0, FLUSH);
685 * Reset the adapter's rsp, cmd, and rcv queues
687 slic_cmdq_reset(adapter);
688 slic_rspqueue_reset(adapter);
689 slic_rcvqueue_reset(adapter);
691 #ifdef AUTOMATIC_RESET
692 if (!card->adapters_activated) {
694 #if SLIC_DUMP_ENABLED
695 if (card->dumpthread_running) {
697 DBG_MSG("attempt to terminate dump thread pid[%x]\n",
699 status = kill_proc(card->dump_task_id->pid, SIGKILL, 1);
702 int count = 10 * 100;
703 while (card->dumpthread_running && --count) {
704 current->state = TASK_INTERRUPTIBLE;
710 ("slicmon thread cleanup FAILED \
712 card->dump_task_id->pid);
717 DBG_MSG("slicoss: %s (%s) initiate CARD_HALT\n", __func__,
720 slic_card_init(card, adapter);
724 DBG_MSG("slicoss: %s (%s) EXIT\n", __func__, dev->name);
725 DBG_MSG("slicoss: %s EXIT\n", __func__);
726 spin_unlock_irqrestore(&slic_global.driver_lock.lock,
727 slic_global.driver_lock.flags);
728 return STATUS_SUCCESS;
731 static int slic_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
735 DBG_MSG("slicoss: %s cmd[%x] rq[%p] dev[%p]\n", __func__, cmd, rq, dev);
738 case SIOCSLICSETINTAGG:
740 struct adapter *adapter = (struct adapter *)
745 if (copy_from_user(data, rq->ifr_data, 28)) {
747 ("copy_from_user FAILED getting initial \
753 "%s: set interrupt aggregation to %d\n",
755 slic_intagg_set(adapter, intagg);
758 #ifdef SLIC_USER_REQUEST_DUMP_ENABLED
759 case SIOCSLICDUMPCARD:
761 struct adapter *adapter = netdev_priv(dev);
762 struct sliccard *card;
765 ASSERT(adapter->card)
766 card = adapter->card;
768 DBG_IOCTL("slic_ioctl SIOCSLIC_DUMP_CARD\n");
770 if (card->dump_requested == SLIC_DUMP_DONE) {
772 "SLIC Card dump to be overwritten\n");
773 card->dump_requested = SLIC_DUMP_REQUESTED;
774 } else if ((card->dump_requested == SLIC_DUMP_REQUESTED)
775 || (card->dump_requested ==
776 SLIC_DUMP_IN_PROGRESS)) {
778 "SLIC Card dump Requested but already \
779 in progress... ignore\n");
782 "SLIC Card #%d Dump Requested\n",
784 card->dump_requested = SLIC_DUMP_REQUESTED;
790 #ifdef SLIC_TRACE_DUMP_ENABLED
791 case SIOCSLICTRACEDUMP:
796 DBG_IOCTL("slic_ioctl SIOCSLIC_TRACE_DUMP\n");
798 if (copy_from_user(data, rq->ifr_data, 28)) {
800 ("slic: copy_from_user FAILED getting \
801 initial simba param\n");
806 if (tracemon_request == SLIC_DUMP_DONE) {
808 ("ATK Diagnostic Trace Dump Requested\n");
809 tracemon_request = SLIC_DUMP_REQUESTED;
810 tracemon_request_type = value;
811 tracemon_timestamp = jiffies;
812 } else if ((tracemon_request == SLIC_DUMP_REQUESTED) ||
814 SLIC_DUMP_IN_PROGRESS)) {
816 ("ATK Diagnostic Trace Dump Requested but \
817 already in progress... ignore\n");
820 ("ATK Diagnostic Trace Dump Requested\n");
821 tracemon_request = SLIC_DUMP_REQUESTED;
822 tracemon_request_type = value;
823 tracemon_timestamp = jiffies;
828 #if SLIC_ETHTOOL_SUPPORT
831 struct adapter *adapter = (struct adapter *)
833 struct ethtool_cmd data;
834 struct ethtool_cmd ecmd;
837 /* DBG_MSG("slicoss: %s SIOCETHTOOL\n", __func__); */
838 if (copy_from_user(&ecmd, rq->ifr_data, sizeof(ecmd)))
841 if (ecmd.cmd == ETHTOOL_GSET) {
843 (SUPPORTED_10baseT_Half |
844 SUPPORTED_10baseT_Full |
845 SUPPORTED_100baseT_Half |
846 SUPPORTED_100baseT_Full |
847 SUPPORTED_Autoneg | SUPPORTED_MII);
848 data.port = PORT_MII;
849 data.transceiver = XCVR_INTERNAL;
850 data.phy_address = 0;
851 if (adapter->linkspeed == LINK_100MB)
852 data.speed = SPEED_100;
853 else if (adapter->linkspeed == LINK_10MB)
854 data.speed = SPEED_10;
858 if (adapter->linkduplex == LINK_FULLD)
859 data.duplex = DUPLEX_FULL;
861 data.duplex = DUPLEX_HALF;
863 data.autoneg = AUTONEG_ENABLE;
867 (rq->ifr_data, &data, sizeof(data)))
870 } else if (ecmd.cmd == ETHTOOL_SSET) {
871 if (!capable(CAP_NET_ADMIN))
874 if (adapter->linkspeed == LINK_100MB)
875 data.speed = SPEED_100;
876 else if (adapter->linkspeed == LINK_10MB)
877 data.speed = SPEED_10;
881 if (adapter->linkduplex == LINK_FULLD)
882 data.duplex = DUPLEX_FULL;
884 data.duplex = DUPLEX_HALF;
886 data.autoneg = AUTONEG_ENABLE;
889 if ((ecmd.speed != data.speed) ||
890 (ecmd.duplex != data.duplex)) {
894 if (ecmd.speed == SPEED_10) {
897 ("%s: slic ETHTOOL set \
901 speed = PCR_SPEED_100;
903 ("%s: slic ETHTOOL set \
907 if (ecmd.duplex == DUPLEX_FULL) {
908 duplex = PCR_DUPLEX_FULL;
910 (": duplex==FULL\n");
914 (": duplex==HALF\n");
916 slic_link_config(adapter,
918 slic_link_event_handler(adapter);
925 /* DBG_MSG("slicoss: %s UNSUPPORTED[%x]\n", __func__, cmd); */
930 #define XMIT_FAIL_LINK_STATE 1
931 #define XMIT_FAIL_ZERO_LENGTH 2
932 #define XMIT_FAIL_HOSTCMD_FAIL 3
934 static void slic_xmit_build_request(struct adapter *adapter,
935 struct slic_hostcmd *hcmd, struct sk_buff *skb)
937 struct slic_host64_cmd *ihcmd;
940 ihcmd = &hcmd->cmd64;
942 ihcmd->flags = (adapter->port << IHFLG_IFSHFT);
943 ihcmd->command = IHCMD_XMT_REQ;
944 ihcmd->u.slic_buffers.totlen = skb->len;
945 phys_addr = pci_map_single(adapter->pcidev, skb->data, skb->len,
947 ihcmd->u.slic_buffers.bufs[0].paddrl = SLIC_GET_ADDR_LOW(phys_addr);
948 ihcmd->u.slic_buffers.bufs[0].paddrh = SLIC_GET_ADDR_HIGH(phys_addr);
949 ihcmd->u.slic_buffers.bufs[0].length = skb->len;
950 #if defined(CONFIG_X86_64)
951 hcmd->cmdsize = (u32) ((((u64)&ihcmd->u.slic_buffers.bufs[1] -
952 (u64) hcmd) + 31) >> 5);
953 #elif defined(CONFIG_X86)
954 hcmd->cmdsize = ((((u32) &ihcmd->u.slic_buffers.bufs[1] -
955 (u32) hcmd) + 31) >> 5);
961 #define NORMAL_ETHFRAME 0
963 static int slic_xmit_start(struct sk_buff *skb, struct net_device *dev)
965 struct sliccard *card;
966 struct adapter *adapter = (struct adapter *)netdev_priv(dev);
967 struct slic_hostcmd *hcmd = NULL;
969 u32 skbtype = NORMAL_ETHFRAME;
970 void *offloadcmd = NULL;
972 card = adapter->card;
975 DBG_ERROR("xmit_start (%s) ENTER skb[%p] len[%d] linkstate[%x] state[%x]\n",
976 adapter->netdev->name, skb, skb->len, adapter->linkstate,
979 if ((adapter->linkstate != LINK_UP) ||
980 (adapter->state != ADAPT_UP) || (card->state != CARD_UP)) {
981 status = XMIT_FAIL_LINK_STATE;
984 } else if (skb->len == 0) {
985 status = XMIT_FAIL_ZERO_LENGTH;
989 if (skbtype == NORMAL_ETHFRAME) {
990 hcmd = slic_cmdq_getfree(adapter);
992 adapter->xmitq_full = 1;
993 status = XMIT_FAIL_HOSTCMD_FAIL;
996 ASSERT(hcmd->pslic_handle);
997 ASSERT(hcmd->cmd64.hosthandle ==
998 hcmd->pslic_handle->token.handle_token);
1001 hcmd->type = SLIC_CMD_DUMB;
1002 if (skbtype == NORMAL_ETHFRAME)
1003 slic_xmit_build_request(adapter, hcmd, skb);
1005 adapter->stats.tx_packets++;
1006 adapter->stats.tx_bytes += skb->len;
1009 if (adapter->kill_card) {
1010 struct slic_host64_cmd ihcmd;
1012 ihcmd = &hcmd->cmd64;
1014 ihcmd->flags |= 0x40;
1015 adapter->kill_card = 0; /* only do this once */
1018 if (hcmd->paddrh == 0) {
1019 WRITE_REG(adapter->slic_regs->slic_cbar,
1020 (hcmd->paddrl | hcmd->cmdsize), DONT_FLUSH);
1022 WRITE_REG64(adapter,
1023 adapter->slic_regs->slic_cbar64,
1024 (hcmd->paddrl | hcmd->cmdsize),
1025 adapter->slic_regs->slic_addr_upper,
1026 hcmd->paddrh, DONT_FLUSH);
1031 slic_xmit_fail(adapter, skb, offloadcmd, skbtype, status);
1035 static void slic_xmit_fail(struct adapter *adapter,
1036 struct sk_buff *skb,
1037 void *cmd, u32 skbtype, u32 status)
1039 if (adapter->xmitq_full)
1040 slic_if_stop_queue(adapter);
1041 if ((cmd == NULL) && (status <= XMIT_FAIL_HOSTCMD_FAIL)) {
1043 case XMIT_FAIL_LINK_STATE:
1045 ("(%s) reject xmit skb[%p: %x] linkstate[%s] \
1046 adapter[%s:%d] card[%s:%d]\n",
1047 adapter->netdev->name, skb, skb->pkt_type,
1048 SLIC_LINKSTATE(adapter->linkstate),
1049 SLIC_ADAPTER_STATE(adapter->state), adapter->state,
1050 SLIC_CARD_STATE(adapter->card->state),
1051 adapter->card->state);
1053 case XMIT_FAIL_ZERO_LENGTH:
1055 ("xmit_start skb->len == 0 skb[%p] type[%x]!!!! \n",
1056 skb, skb->pkt_type);
1058 case XMIT_FAIL_HOSTCMD_FAIL:
1060 ("xmit_start skb[%p] type[%x] No host commands \
1062 skb, skb->pkt_type);
1069 adapter->stats.tx_dropped++;
1072 static void slic_rcv_handle_error(struct adapter *adapter,
1073 struct slic_rcvbuf *rcvbuf)
1075 struct slic_hddr_wds *hdr = (struct slic_hddr_wds *)rcvbuf->data;
1077 if (adapter->devid != SLIC_1GB_DEVICE_ID) {
1078 if (hdr->frame_status14 & VRHSTAT_802OE)
1079 adapter->if_events.oflow802++;
1080 if (hdr->frame_status14 & VRHSTAT_TPOFLO)
1081 adapter->if_events.Tprtoflow++;
1082 if (hdr->frame_status_b14 & VRHSTATB_802UE)
1083 adapter->if_events.uflow802++;
1084 if (hdr->frame_status_b14 & VRHSTATB_RCVE) {
1085 adapter->if_events.rcvearly++;
1086 adapter->stats.rx_fifo_errors++;
1088 if (hdr->frame_status_b14 & VRHSTATB_BUFF) {
1089 adapter->if_events.Bufov++;
1090 adapter->stats.rx_over_errors++;
1092 if (hdr->frame_status_b14 & VRHSTATB_CARRE) {
1093 adapter->if_events.Carre++;
1094 adapter->stats.tx_carrier_errors++;
1096 if (hdr->frame_status_b14 & VRHSTATB_LONGE)
1097 adapter->if_events.Longe++;
1098 if (hdr->frame_status_b14 & VRHSTATB_PREA)
1099 adapter->if_events.Invp++;
1100 if (hdr->frame_status_b14 & VRHSTATB_CRC) {
1101 adapter->if_events.Crc++;
1102 adapter->stats.rx_crc_errors++;
1104 if (hdr->frame_status_b14 & VRHSTATB_DRBL)
1105 adapter->if_events.Drbl++;
1106 if (hdr->frame_status_b14 & VRHSTATB_CODE)
1107 adapter->if_events.Code++;
1108 if (hdr->frame_status_b14 & VRHSTATB_TPCSUM)
1109 adapter->if_events.TpCsum++;
1110 if (hdr->frame_status_b14 & VRHSTATB_TPHLEN)
1111 adapter->if_events.TpHlen++;
1112 if (hdr->frame_status_b14 & VRHSTATB_IPCSUM)
1113 adapter->if_events.IpCsum++;
1114 if (hdr->frame_status_b14 & VRHSTATB_IPLERR)
1115 adapter->if_events.IpLen++;
1116 if (hdr->frame_status_b14 & VRHSTATB_IPHERR)
1117 adapter->if_events.IpHlen++;
1119 if (hdr->frame_statusGB & VGBSTAT_XPERR) {
1120 u32 xerr = hdr->frame_statusGB >> VGBSTAT_XERRSHFT;
1122 if (xerr == VGBSTAT_XCSERR)
1123 adapter->if_events.TpCsum++;
1124 if (xerr == VGBSTAT_XUFLOW)
1125 adapter->if_events.Tprtoflow++;
1126 if (xerr == VGBSTAT_XHLEN)
1127 adapter->if_events.TpHlen++;
1129 if (hdr->frame_statusGB & VGBSTAT_NETERR) {
1132 frame_statusGB >> VGBSTAT_NERRSHFT) &
1134 if (nerr == VGBSTAT_NCSERR)
1135 adapter->if_events.IpCsum++;
1136 if (nerr == VGBSTAT_NUFLOW)
1137 adapter->if_events.IpLen++;
1138 if (nerr == VGBSTAT_NHLEN)
1139 adapter->if_events.IpHlen++;
1141 if (hdr->frame_statusGB & VGBSTAT_LNKERR) {
1142 u32 lerr = hdr->frame_statusGB & VGBSTAT_LERRMSK;
1144 if (lerr == VGBSTAT_LDEARLY)
1145 adapter->if_events.rcvearly++;
1146 if (lerr == VGBSTAT_LBOFLO)
1147 adapter->if_events.Bufov++;
1148 if (lerr == VGBSTAT_LCODERR)
1149 adapter->if_events.Code++;
1150 if (lerr == VGBSTAT_LDBLNBL)
1151 adapter->if_events.Drbl++;
1152 if (lerr == VGBSTAT_LCRCERR)
1153 adapter->if_events.Crc++;
1154 if (lerr == VGBSTAT_LOFLO)
1155 adapter->if_events.oflow802++;
1156 if (lerr == VGBSTAT_LUFLO)
1157 adapter->if_events.uflow802++;
1163 #define TCP_OFFLOAD_FRAME_PUSHFLAG 0x10000000
1164 #define M_FAST_PATH 0x0040
1166 static void slic_rcv_handler(struct adapter *adapter)
1168 struct sk_buff *skb;
1169 struct slic_rcvbuf *rcvbuf;
1172 while ((skb = slic_rcvqueue_getnext(adapter))) {
1176 rcvbuf = (struct slic_rcvbuf *)skb->head;
1177 adapter->card->events++;
1178 if (rcvbuf->status & IRHDDR_ERR) {
1179 adapter->rx_errors++;
1180 slic_rcv_handle_error(adapter, rcvbuf);
1181 slic_rcvqueue_reinsert(adapter, skb);
1185 if (!slic_mac_filter(adapter, (struct ether_header *)
1189 ("slicoss: %s (%s) drop frame due to mac filter\n",
1190 __func__, adapter->netdev->name);
1192 slic_rcvqueue_reinsert(adapter, skb);
1195 skb_pull(skb, SLIC_RCVBUF_HEADSIZE);
1196 rx_bytes = (rcvbuf->length & IRHDDR_FLEN_MSK);
1197 skb_put(skb, rx_bytes);
1198 adapter->stats.rx_packets++;
1199 adapter->stats.rx_bytes += rx_bytes;
1200 #if SLIC_OFFLOAD_IP_CHECKSUM
1201 skb->ip_summed = CHECKSUM_UNNECESSARY;
1204 skb->dev = adapter->netdev;
1205 skb->protocol = eth_type_trans(skb, skb->dev);
1209 #if SLIC_INTERRUPT_PROCESS_LIMIT
1210 if (frames >= SLIC_RCVQ_MAX_PROCESS_ISR) {
1211 adapter->rcv_interrupt_yields++;
1216 adapter->max_isr_rcvs = max(adapter->max_isr_rcvs, frames);
1219 static void slic_xmit_complete(struct adapter *adapter)
1221 struct slic_hostcmd *hcmd;
1222 struct slic_rspbuf *rspbuf;
1224 struct slic_handle_word slic_handle_word;
1227 rspbuf = slic_rspqueue_getnext(adapter);
1230 adapter->xmit_completes++;
1231 adapter->card->events++;
1233 Get the complete host command buffer
1235 slic_handle_word.handle_token = rspbuf->hosthandle;
1236 ASSERT(slic_handle_word.handle_index);
1237 ASSERT(slic_handle_word.handle_index <= SLIC_CMDQ_MAXCMDS);
1239 (struct slic_hostcmd *)
1240 adapter->slic_handles[slic_handle_word.handle_index].
1242 /* hcmd = (struct slic_hostcmd *) rspbuf->hosthandle; */
1244 ASSERT(hcmd->pslic_handle ==
1245 &adapter->slic_handles[slic_handle_word.handle_index]);
1247 DBG_ERROR("xmit_complete (%s) hcmd[%p] hosthandle[%x]\n",
1248 adapter->netdev->name, hcmd, hcmd->cmd64.hosthandle);
1249 DBG_ERROR(" skb[%p] len %d hcmdtype[%x]\n", hcmd->skb,
1250 hcmd->skb->len, hcmd->type);
1252 if (hcmd->type == SLIC_CMD_DUMB) {
1254 dev_kfree_skb_irq(hcmd->skb);
1255 slic_cmdq_putdone_irq(adapter, hcmd);
1258 rspbuf->hosthandle = 0;
1261 adapter->max_isr_xmits = max(adapter->max_isr_xmits, frames);
1264 static irqreturn_t slic_interrupt(int irq, void *dev_id)
1266 struct net_device *dev = (struct net_device *)dev_id;
1267 struct adapter *adapter = (struct adapter *)netdev_priv(dev);
1270 if ((adapter->pshmem) && (adapter->pshmem->isr)) {
1271 WRITE_REG(adapter->slic_regs->slic_icr, ICR_INT_MASK, FLUSH);
1272 isr = adapter->isrcopy = adapter->pshmem->isr;
1273 adapter->pshmem->isr = 0;
1274 adapter->num_isrs++;
1275 switch (adapter->card->state) {
1277 if (isr & ~ISR_IO) {
1278 if (isr & ISR_ERR) {
1279 adapter->error_interrupts++;
1280 if (isr & ISR_RMISS) {
1285 struct slic_rcvqueue *rcvq =
1289 error_rmiss_interrupts++;
1291 rcv_count = rcvq->count;
1292 pre_count = rcvq->count;
1293 errors = rcvq->errors;
1295 while (rcvq->count <
1296 SLIC_RCVQ_FILLTHRESH) {
1304 ("(%s): [%x] ISR_RMISS \
1305 initial[%x] pre[%x] \
1308 adapter->netdev->name,
1309 isr, rcv_count, pre_count,
1310 errors, rcvq->count);
1311 } else if (isr & ISR_XDROP) {
1313 ("isr & ISR_ERR [%x] \
1318 ("isr & ISR_ERR [%x]\n",
1323 if (isr & ISR_LEVENT) {
1324 /*DBG_MSG("%s (%s) ISR_LEVENT \n",
1325 __func__, adapter->netdev->name);*/
1326 adapter->linkevent_interrupts++;
1327 slic_link_event_handler(adapter);
1330 if ((isr & ISR_UPC) ||
1331 (isr & ISR_UPCERR) || (isr & ISR_UPCBSY)) {
1332 adapter->upr_interrupts++;
1333 slic_upr_request_complete(adapter, isr);
1337 if (isr & ISR_RCV) {
1338 adapter->rcv_interrupts++;
1339 slic_rcv_handler(adapter);
1342 if (isr & ISR_CMD) {
1343 adapter->xmit_interrupts++;
1344 slic_xmit_complete(adapter);
1349 if ((isr & ISR_UPC) ||
1350 (isr & ISR_UPCERR) || (isr & ISR_UPCBSY)) {
1351 adapter->upr_interrupts++;
1352 slic_upr_request_complete(adapter, isr);
1360 adapter->isrcopy = 0;
1361 adapter->all_reg_writes += 2;
1362 adapter->isr_reg_writes++;
1363 WRITE_REG(adapter->slic_regs->slic_isr, 0, FLUSH);
1365 adapter->false_interrupts++;
1371 * slic_link_event_handler -
1373 * Initiate a link configuration sequence. The link configuration begins
1374 * by issuing a READ_LINK_STATUS command to the Utility Processor on the
1375 * SLIC. Since the command finishes asynchronously, the slic_upr_comlete
1376 * routine will follow it up witha UP configuration write command, which
1377 * will also complete asynchronously.
1380 static void slic_link_event_handler(struct adapter *adapter)
1383 struct slic_shmem *pshmem;
1385 if (adapter->state != ADAPT_UP) {
1386 /* Adapter is not operational. Ignore. */
1390 pshmem = (struct slic_shmem *)adapter->phys_shmem;
1392 #if defined(CONFIG_X86_64)
1394 DBG_MSG("slic_event_handler pshmem->linkstatus[%x] pshmem[%p]\n \
1395 &linkstatus[%p] &isr[%p]\n", adapter->pshmem->linkstatus, pshmem,
1396 &pshmem->linkstatus, &pshmem->isr);
1398 status = slic_upr_request(adapter,
1400 SLIC_GET_ADDR_LOW(&pshmem->linkstatus),
1401 SLIC_GET_ADDR_HIGH(&pshmem->linkstatus),
1403 #elif defined(CONFIG_X86)
1404 status = slic_upr_request(adapter, SLIC_UPR_RLSR,
1405 (u32) &pshmem->linkstatus, /* no 4GB wrap guaranteed */
1410 ASSERT((status == STATUS_SUCCESS) || (status == STATUS_PENDING));
1413 static void slic_init_cleanup(struct adapter *adapter)
1415 DBG_MSG("slicoss: %s ENTER adapter[%p] ", __func__, adapter);
1416 if (adapter->intrregistered) {
1417 DBG_MSG("FREE_IRQ ");
1418 adapter->intrregistered = 0;
1419 free_irq(adapter->netdev->irq, adapter->netdev);
1422 if (adapter->pshmem) {
1423 DBG_MSG("FREE_SHMEM ");
1424 DBG_MSG("adapter[%p] port %d pshmem[%p] FreeShmem ",
1425 adapter, adapter->port, (void *) adapter->pshmem);
1426 pci_free_consistent(adapter->pcidev,
1427 sizeof(struct slic_shmem),
1428 adapter->pshmem, adapter->phys_shmem);
1429 adapter->pshmem = NULL;
1430 adapter->phys_shmem = (dma_addr_t) NULL;
1432 #if SLIC_GET_STATS_TIMER_ENABLED
1433 if (adapter->statstimerset) {
1434 DBG_MSG("statstimer ");
1435 adapter->statstimerset = 0;
1436 del_timer(&adapter->statstimer);
1439 #if !SLIC_DUMP_ENABLED && SLIC_PING_TIMER_ENABLED
1440 /*#if SLIC_DUMP_ENABLED && SLIC_PING_TIMER_ENABLED*/
1441 if (adapter->pingtimerset) {
1442 DBG_MSG("pingtimer ");
1443 adapter->pingtimerset = 0;
1444 del_timer(&adapter->pingtimer);
1447 slic_rspqueue_free(adapter);
1448 slic_cmdq_free(adapter);
1449 slic_rcvqueue_free(adapter);
1454 #if SLIC_GET_STATS_ENABLED
1455 static struct net_device_stats *slic_get_stats(struct net_device *dev)
1457 struct adapter *adapter = (struct adapter *)netdev_priv(dev);
1458 struct net_device_stats *stats;
1461 stats = &adapter->stats;
1462 stats->collisions = adapter->slic_stats.iface.xmit_collisions;
1463 stats->rx_errors = adapter->slic_stats.iface.rcv_errors;
1464 stats->tx_errors = adapter->slic_stats.iface.xmt_errors;
1465 stats->rx_missed_errors = adapter->slic_stats.iface.rcv_discards;
1466 stats->tx_heartbeat_errors = 0;
1467 stats->tx_aborted_errors = 0;
1468 stats->tx_window_errors = 0;
1469 stats->tx_fifo_errors = 0;
1470 stats->rx_frame_errors = 0;
1471 stats->rx_length_errors = 0;
1472 return &adapter->stats;
1477 * Allocate a mcast_address structure to hold the multicast address.
1480 static int slic_mcast_add_list(struct adapter *adapter, char *address)
1482 struct mcast_address *mcaddr, *mlist;
1485 /* Check to see if it already exists */
1486 mlist = adapter->mcastaddrs;
1488 ETHER_EQ_ADDR(mlist->address, address, equaladdr);
1490 return STATUS_SUCCESS;
1491 mlist = mlist->next;
1494 /* Doesn't already exist. Allocate a structure to hold it */
1495 mcaddr = kmalloc(sizeof(struct mcast_address), GFP_KERNEL);
1499 memcpy(mcaddr->address, address, 6);
1501 mcaddr->next = adapter->mcastaddrs;
1502 adapter->mcastaddrs = mcaddr;
1504 return STATUS_SUCCESS;
1508 * Functions to obtain the CRC corresponding to the destination mac address.
1509 * This is a standard ethernet CRC in that it is a 32-bit, reflected CRC using
1511 * x^32 + x^26 + x^23 + x^22 + x^16 + x^12 + x^11 + x^10 + x^8 + x^7 + x^5 +
1514 * After the CRC for the 6 bytes is generated (but before the value is
1516 * we must then transpose the value and return bits 30-23.
1519 static u32 slic_crc_table[256]; /* Table of CRCs for all possible byte values */
1520 static u32 slic_crc_init; /* Is table initialized */
1523 * Contruct the CRC32 table
1525 static void slic_mcast_init_crc32(void)
1527 u32 c; /* CRC shit reg */
1528 u32 e = 0; /* Poly X-or pattern */
1529 int i; /* counter */
1530 int k; /* byte being shifted into crc */
1532 static int p[] = { 0, 1, 2, 4, 5, 7, 8, 10, 11, 12, 16, 22, 23, 26 };
1534 for (i = 0; i < sizeof(p) / sizeof(int); i++)
1535 e |= 1L << (31 - p[i]);
1537 for (i = 1; i < 256; i++) {
1540 c = c & 1 ? (c >> 1) ^ e : c >> 1;
1541 slic_crc_table[i] = c;
1546 * Return the MAC hast as described above.
1548 static unsigned char slic_mcast_get_mac_hash(char *macaddr)
1553 unsigned char machash = 0;
1555 if (!slic_crc_init) {
1556 slic_mcast_init_crc32();
1560 crc = 0xFFFFFFFF; /* Preload shift register, per crc-32 spec */
1561 for (i = 0, p = macaddr; i < 6; ++p, ++i)
1562 crc = (crc >> 8) ^ slic_crc_table[(crc ^ *p) & 0xFF];
1564 /* Return bits 1-8, transposed */
1565 for (i = 1; i < 9; i++)
1566 machash |= (((crc >> i) & 1) << (8 - i));
1571 static void slic_mcast_set_bit(struct adapter *adapter, char *address)
1573 unsigned char crcpoly;
1575 /* Get the CRC polynomial for the mac address */
1576 crcpoly = slic_mcast_get_mac_hash(address);
1578 /* We only have space on the SLIC for 64 entries. Lop
1579 * off the top two bits. (2^6 = 64)
1583 /* OR in the new bit into our 64 bit mask. */
1584 adapter->mcastmask |= (u64) 1 << crcpoly;
1587 static void slic_mcast_set_list(struct net_device *dev)
1589 struct adapter *adapter = (struct adapter *)netdev_priv(dev);
1590 int status = STATUS_SUCCESS;
1593 struct dev_mc_list *mc_list = dev->mc_list;
1594 int mc_count = dev->mc_count;
1598 for (i = 1; i <= mc_count; i++) {
1599 addresses = (char *) &mc_list->dmi_addr;
1600 if (mc_list->dmi_addrlen == 6) {
1601 status = slic_mcast_add_list(adapter, addresses);
1602 if (status != STATUS_SUCCESS)
1608 slic_mcast_set_bit(adapter, addresses);
1609 mc_list = mc_list->next;
1612 DBG_MSG("%s a->devflags_prev[%x] dev->flags[%x] status[%x]\n",
1613 __func__, adapter->devflags_prev, dev->flags, status);
1614 if (adapter->devflags_prev != dev->flags) {
1615 adapter->macopts = MAC_DIRECTED;
1617 if (dev->flags & IFF_BROADCAST)
1618 adapter->macopts |= MAC_BCAST;
1619 if (dev->flags & IFF_PROMISC)
1620 adapter->macopts |= MAC_PROMISC;
1621 if (dev->flags & IFF_ALLMULTI)
1622 adapter->macopts |= MAC_ALLMCAST;
1623 if (dev->flags & IFF_MULTICAST)
1624 adapter->macopts |= MAC_MCAST;
1626 adapter->devflags_prev = dev->flags;
1627 DBG_MSG("%s call slic_config_set adapter->macopts[%x]\n",
1628 __func__, adapter->macopts);
1629 slic_config_set(adapter, true);
1631 if (status == STATUS_SUCCESS)
1632 slic_mcast_set_mask(adapter);
1637 static void slic_mcast_set_mask(struct adapter *adapter)
1639 __iomem struct slic_regs *slic_regs = adapter->slic_regs;
1641 DBG_MSG("%s ENTER (%s) macopts[%x] mask[%llx]\n", __func__,
1642 adapter->netdev->name, (uint) adapter->macopts,
1643 adapter->mcastmask);
1645 if (adapter->macopts & (MAC_ALLMCAST | MAC_PROMISC)) {
1646 /* Turn on all multicast addresses. We have to do this for
1647 * promiscuous mode as well as ALLMCAST mode. It saves the
1648 * Microcode from having to keep state about the MAC
1651 /* DBG_MSG("slicoss: %s macopts = MAC_ALLMCAST | MAC_PROMISC\n\
1652 SLUT MODE!!!\n",__func__); */
1653 WRITE_REG(slic_regs->slic_mcastlow, 0xFFFFFFFF, FLUSH);
1654 WRITE_REG(slic_regs->slic_mcasthigh, 0xFFFFFFFF, FLUSH);
1655 /* DBG_MSG("%s (%s) WRITE to slic_regs slic_mcastlow&high 0xFFFFFFFF\n",
1656 _func__, adapter->netdev->name); */
1658 /* Commit our multicast mast to the SLIC by writing to the
1659 * multicast address mask registers
1661 DBG_MSG("%s (%s) WRITE mcastlow[%x] mcasthigh[%x]\n",
1662 __func__, adapter->netdev->name,
1663 ((ulong) (adapter->mcastmask & 0xFFFFFFFF)),
1664 ((ulong) ((adapter->mcastmask >> 32) & 0xFFFFFFFF)));
1666 WRITE_REG(slic_regs->slic_mcastlow,
1667 (u32) (adapter->mcastmask & 0xFFFFFFFF), FLUSH);
1668 WRITE_REG(slic_regs->slic_mcasthigh,
1669 (u32) ((adapter->mcastmask >> 32) & 0xFFFFFFFF),
1674 static void slic_timer_ping(ulong dev)
1676 struct adapter *adapter;
1677 struct sliccard *card;
1680 adapter = netdev_priv((struct net_device *)dev);
1682 card = adapter->card;
1684 #if !SLIC_DUMP_ENABLED
1685 /*#if SLIC_DUMP_ENABLED*/
1686 if ((adapter->state == ADAPT_UP) && (card->state == CARD_UP)) {
1689 if (card->pingstatus != ISR_PINGMASK) {
1690 if (errormsg++ < 5) {
1692 ("%s (%s) CARD HAS CRASHED PING_status == \
1694 __func__, adapter->netdev->name,
1695 card->pingstatus, errormsg);
1697 /* ASSERT(card->pingstatus == ISR_PINGMASK); */
1699 if (goodmsg++ < 5) {
1701 ("slicoss: %s (%s) PING_status == %x \
1702 GOOD!!!!!!!! msg# %d\n",
1703 __func__, adapter->netdev->name,
1704 card->pingstatus, errormsg);
1707 card->pingstatus = 0;
1708 status = slic_upr_request(adapter, SLIC_UPR_PING, 0, 0, 0, 0);
1710 ASSERT(status == 0);
1712 DBG_MSG("slicoss %s (%s) adapter[%p] NOT UP!!!!\n",
1713 __func__, adapter->netdev->name, adapter);
1716 adapter->pingtimer.expires = jiffies + (PING_TIMER_INTERVAL * HZ);
1717 add_timer(&adapter->pingtimer);
1720 static void slic_if_stop_queue(struct adapter *adapter)
1722 netif_stop_queue(adapter->netdev);
1725 static void slic_if_start_queue(struct adapter *adapter)
1727 netif_start_queue(adapter->netdev);
1733 * Perform initialization of our slic interface.
1736 static int slic_if_init(struct adapter *adapter)
1738 struct sliccard *card = adapter->card;
1739 struct net_device *dev = adapter->netdev;
1740 __iomem struct slic_regs *slic_regs = adapter->slic_regs;
1741 struct slic_shmem *pshmem;
1745 DBG_MSG("slicoss: %s (%s) ENTER states[%d:%d:%d:%d] flags[%x]\n",
1746 __func__, adapter->netdev->name,
1747 adapter->queues_initialized, adapter->state, adapter->linkstate,
1748 card->state, dev->flags);
1750 /* adapter should be down at this point */
1751 if (adapter->state != ADAPT_DOWN) {
1752 DBG_ERROR("slic_if_init adapter->state != ADAPT_DOWN\n");
1755 ASSERT(adapter->linkstate == LINK_DOWN);
1757 adapter->devflags_prev = dev->flags;
1758 adapter->macopts = MAC_DIRECTED;
1760 DBG_MSG("slicoss: %s (%s) Set MAC options: ", __func__,
1761 adapter->netdev->name);
1762 if (dev->flags & IFF_BROADCAST) {
1763 adapter->macopts |= MAC_BCAST;
1766 if (dev->flags & IFF_PROMISC) {
1767 adapter->macopts |= MAC_PROMISC;
1768 DBG_MSG("PROMISC ");
1770 if (dev->flags & IFF_ALLMULTI) {
1771 adapter->macopts |= MAC_ALLMCAST;
1772 DBG_MSG("ALL_MCAST ");
1774 if (dev->flags & IFF_MULTICAST) {
1775 adapter->macopts |= MAC_MCAST;
1780 status = slic_adapter_allocresources(adapter);
1781 if (status != STATUS_SUCCESS) {
1783 ("slic_if_init: slic_adapter_allocresources FAILED %x\n",
1785 slic_adapter_freeresources(adapter);
1789 if (!adapter->queues_initialized) {
1790 DBG_MSG("slicoss: %s call slic_rspqueue_init\n", __func__);
1791 if (slic_rspqueue_init(adapter))
1794 ("slicoss: %s call slic_cmdq_init adapter[%p] port %d \n",
1795 __func__, adapter, adapter->port);
1796 if (slic_cmdq_init(adapter))
1799 ("slicoss: %s call slic_rcvqueue_init adapter[%p] \
1800 port %d \n", __func__, adapter, adapter->port);
1801 if (slic_rcvqueue_init(adapter))
1803 adapter->queues_initialized = 1;
1805 DBG_MSG("slicoss: %s disable interrupts(slic)\n", __func__);
1807 WRITE_REG(slic_regs->slic_icr, ICR_INT_OFF, FLUSH);
1810 if (!adapter->isp_initialized) {
1811 pshmem = (struct slic_shmem *)adapter->phys_shmem;
1813 spin_lock_irqsave(&adapter->bit64reglock.lock,
1814 adapter->bit64reglock.flags);
1816 #if defined(CONFIG_X86_64)
1817 WRITE_REG(slic_regs->slic_addr_upper,
1818 SLIC_GET_ADDR_HIGH(&pshmem->isr), DONT_FLUSH);
1819 WRITE_REG(slic_regs->slic_isp,
1820 SLIC_GET_ADDR_LOW(&pshmem->isr), FLUSH);
1821 #elif defined(CONFIG_X86)
1822 WRITE_REG(slic_regs->slic_addr_upper, (u32) 0, DONT_FLUSH);
1823 WRITE_REG(slic_regs->slic_isp, (u32) &pshmem->isr, FLUSH);
1827 spin_unlock_irqrestore(&adapter->bit64reglock.lock,
1828 adapter->bit64reglock.flags);
1829 adapter->isp_initialized = 1;
1832 adapter->state = ADAPT_UP;
1833 if (!card->loadtimerset) {
1834 init_timer(&card->loadtimer);
1835 card->loadtimer.expires =
1836 jiffies + (SLIC_LOADTIMER_PERIOD * HZ);
1837 card->loadtimer.data = (ulong) card;
1838 card->loadtimer.function = &slic_timer_load_check;
1839 add_timer(&card->loadtimer);
1841 card->loadtimerset = 1;
1843 #if SLIC_GET_STATS_TIMER_ENABLED
1844 if (!adapter->statstimerset) {
1845 DBG_MSG("slicoss: %s start getstats_timer(slic)\n",
1847 init_timer(&adapter->statstimer);
1848 adapter->statstimer.expires =
1849 jiffies + (STATS_TIMER_INTERVAL * HZ);
1850 adapter->statstimer.data = (ulong) adapter->netdev;
1851 adapter->statstimer.function = &slic_timer_get_stats;
1852 add_timer(&adapter->statstimer);
1853 adapter->statstimerset = 1;
1856 #if !SLIC_DUMP_ENABLED && SLIC_PING_TIMER_ENABLED
1857 /*#if SLIC_DUMP_ENABLED && SLIC_PING_TIMER_ENABLED*/
1858 if (!adapter->pingtimerset) {
1859 DBG_MSG("slicoss: %s start card_ping_timer(slic)\n",
1861 init_timer(&adapter->pingtimer);
1862 adapter->pingtimer.expires =
1863 jiffies + (PING_TIMER_INTERVAL * HZ);
1864 adapter->pingtimer.data = (ulong) dev;
1865 adapter->pingtimer.function = &slic_timer_ping;
1866 add_timer(&adapter->pingtimer);
1867 adapter->pingtimerset = 1;
1868 adapter->card->pingstatus = ISR_PINGMASK;
1873 * clear any pending events, then enable interrupts
1875 DBG_MSG("slicoss: %s ENABLE interrupts(slic)\n", __func__);
1876 adapter->isrcopy = 0;
1877 adapter->pshmem->isr = 0;
1878 WRITE_REG(slic_regs->slic_isr, 0, FLUSH);
1879 WRITE_REG(slic_regs->slic_icr, ICR_INT_ON, FLUSH);
1881 DBG_MSG("slicoss: %s call slic_link_config(slic)\n", __func__);
1882 slic_link_config(adapter, LINK_AUTOSPEED, LINK_AUTOD);
1883 slic_link_event_handler(adapter);
1885 DBG_MSG("slicoss: %s EXIT\n", __func__);
1886 return STATUS_SUCCESS;
1889 static void slic_unmap_mmio_space(struct adapter *adapter)
1891 #if LINUX_FREES_ADAPTER_RESOURCES
1892 if (adapter->slic_regs)
1893 iounmap(adapter->slic_regs);
1894 adapter->slic_regs = NULL;
1898 static int slic_adapter_allocresources(struct adapter *adapter)
1900 if (!adapter->intrregistered) {
1904 ("slicoss: %s AllocAdaptRsrcs adapter[%p] shmem[%p] \
1905 phys_shmem[%p] dev->irq[%x] %x\n",
1906 __func__, adapter, adapter->pshmem,
1907 (void *)adapter->phys_shmem, adapter->netdev->irq,
1910 spin_unlock_irqrestore(&slic_global.driver_lock.lock,
1911 slic_global.driver_lock.flags);
1913 retval = request_irq(adapter->netdev->irq,
1916 adapter->netdev->name, adapter->netdev);
1918 spin_lock_irqsave(&slic_global.driver_lock.lock,
1919 slic_global.driver_lock.flags);
1922 DBG_ERROR("slicoss: request_irq (%s) FAILED [%x]\n",
1923 adapter->netdev->name, retval);
1926 adapter->intrregistered = 1;
1928 ("slicoss: %s AllocAdaptRsrcs adapter[%p] shmem[%p] \
1929 pshmem[%p] dev->irq[%x]\n",
1930 __func__, adapter, adapter->pshmem,
1931 (void *)adapter->pshmem, adapter->netdev->irq);
1933 return STATUS_SUCCESS;
1936 static void slic_config_pci(struct pci_dev *pcidev)
1941 pci_read_config_word(pcidev, PCI_COMMAND, &pci_command);
1942 DBG_MSG("slicoss: %s PCI command[%4.4x]\n", __func__, pci_command);
1944 new_command = pci_command | PCI_COMMAND_MASTER
1945 | PCI_COMMAND_MEMORY
1946 | PCI_COMMAND_INVALIDATE
1947 | PCI_COMMAND_PARITY | PCI_COMMAND_SERR | PCI_COMMAND_FAST_BACK;
1948 if (pci_command != new_command) {
1949 DBG_MSG("%s -- Updating PCI COMMAND register %4.4x->%4.4x.\n",
1950 __func__, pci_command, new_command);
1951 pci_write_config_word(pcidev, PCI_COMMAND, new_command);
1955 static void slic_adapter_freeresources(struct adapter *adapter)
1957 DBG_MSG("slicoss: %s ENTER adapter[%p]\n", __func__, adapter);
1958 slic_init_cleanup(adapter);
1959 memset(&adapter->stats, 0, sizeof(struct net_device_stats));
1960 adapter->error_interrupts = 0;
1961 adapter->rcv_interrupts = 0;
1962 adapter->xmit_interrupts = 0;
1963 adapter->linkevent_interrupts = 0;
1964 adapter->upr_interrupts = 0;
1965 adapter->num_isrs = 0;
1966 adapter->xmit_completes = 0;
1967 adapter->rcv_broadcasts = 0;
1968 adapter->rcv_multicasts = 0;
1969 adapter->rcv_unicasts = 0;
1970 DBG_MSG("slicoss: %s EXIT\n", __func__);
1976 * Write phy control to configure link duplex/speed
1979 static void slic_link_config(struct adapter *adapter,
1980 u32 linkspeed, u32 linkduplex)
1988 if (adapter->state != ADAPT_UP) {
1990 ("%s (%s) ADAPT Not up yet, Return! speed[%x] duplex[%x]\n",
1991 __func__, adapter->netdev->name, linkspeed,
1995 DBG_MSG("slicoss: %s (%s) slic_link_config: speed[%x] duplex[%x]\n",
1996 __func__, adapter->netdev->name, linkspeed, linkduplex);
1998 ASSERT((adapter->devid == SLIC_1GB_DEVICE_ID)
1999 || (adapter->devid == SLIC_2GB_DEVICE_ID));
2001 if (linkspeed > LINK_1000MB)
2002 linkspeed = LINK_AUTOSPEED;
2003 if (linkduplex > LINK_AUTOD)
2004 linkduplex = LINK_AUTOD;
2006 if ((linkspeed == LINK_AUTOSPEED) || (linkspeed == LINK_1000MB)) {
2007 if (adapter->flags & ADAPT_FLAGS_FIBERMEDIA) {
2008 /* We've got a fiber gigabit interface, and register
2009 * 4 is different in fiber mode than in copper mode
2012 /* advertise FD only @1000 Mb */
2013 phy_advreg = (MIICR_REG_4 | (PAR_ADV1000XFD));
2014 /* enable PAUSE frames */
2015 phy_advreg |= PAR_ASYMPAUSE_FIBER;
2016 WRITE_REG(adapter->slic_regs->slic_wphy, phy_advreg,
2019 if (linkspeed == LINK_AUTOSPEED) {
2020 /* reset phy, enable auto-neg */
2023 (PCR_RESET | PCR_AUTONEG |
2025 WRITE_REG(adapter->slic_regs->slic_wphy,
2027 } else { /* forced 1000 Mb FD*/
2028 /* power down phy to break link
2029 this may not work) */
2030 phy_config = (MIICR_REG_PCR | PCR_POWERDOWN);
2031 WRITE_REG(adapter->slic_regs->slic_wphy,
2033 /* wait, Marvell says 1 sec,
2034 try to get away with 10 ms */
2037 /* disable auto-neg, set speed/duplex,
2038 soft reset phy, powerup */
2041 (PCR_RESET | PCR_SPEED_1000 |
2043 WRITE_REG(adapter->slic_regs->slic_wphy,
2046 } else { /* copper gigabit */
2048 /* Auto-Negotiate or 1000 Mb must be auto negotiated
2049 * We've got a copper gigabit interface, and
2050 * register 4 is different in copper mode than
2053 if (linkspeed == LINK_AUTOSPEED) {
2054 /* advertise 10/100 Mb modes */
2057 (PAR_ADV100FD | PAR_ADV100HD | PAR_ADV10FD
2060 /* linkspeed == LINK_1000MB -
2061 don't advertise 10/100 Mb modes */
2062 phy_advreg = MIICR_REG_4;
2064 /* enable PAUSE frames */
2065 phy_advreg |= PAR_ASYMPAUSE;
2066 /* required by the Cicada PHY */
2067 phy_advreg |= PAR_802_3;
2068 WRITE_REG(adapter->slic_regs->slic_wphy, phy_advreg,
2070 /* advertise FD only @1000 Mb */
2071 phy_gctlreg = (MIICR_REG_9 | (PGC_ADV1000FD));
2072 WRITE_REG(adapter->slic_regs->slic_wphy, phy_gctlreg,
2075 if (adapter->subsysid != SLIC_1GB_CICADA_SUBSYS_ID) {
2077 enable auto crossover */
2079 (MIICR_REG_16 | (MRV_REG16_XOVERON));
2080 WRITE_REG(adapter->slic_regs->slic_wphy,
2083 /* reset phy, enable auto-neg */
2086 (PCR_RESET | PCR_AUTONEG |
2088 WRITE_REG(adapter->slic_regs->slic_wphy,
2090 } else { /* it's a Cicada PHY */
2091 /* enable and restart auto-neg (don't reset) */
2094 (PCR_AUTONEG | PCR_AUTONEG_RST));
2095 WRITE_REG(adapter->slic_regs->slic_wphy,
2101 if (linkspeed == LINK_10MB)
2104 speed = PCR_SPEED_100;
2105 if (linkduplex == LINK_HALFD)
2108 duplex = PCR_DUPLEX_FULL;
2110 if (adapter->subsysid != SLIC_1GB_CICADA_SUBSYS_ID) {
2112 disable auto crossover */
2113 phy_config = (MIICR_REG_16 | (MRV_REG16_XOVEROFF));
2114 WRITE_REG(adapter->slic_regs->slic_wphy, phy_config,
2118 /* power down phy to break link (this may not work) */
2119 phy_config = (MIICR_REG_PCR | (PCR_POWERDOWN | speed | duplex));
2120 WRITE_REG(adapter->slic_regs->slic_wphy, phy_config, FLUSH);
2122 /* wait, Marvell says 1 sec, try to get away with 10 ms */
2125 if (adapter->subsysid != SLIC_1GB_CICADA_SUBSYS_ID) {
2127 disable auto-neg, set speed,
2128 soft reset phy, powerup */
2130 (MIICR_REG_PCR | (PCR_RESET | speed | duplex));
2131 WRITE_REG(adapter->slic_regs->slic_wphy, phy_config,
2133 } else { /* it's a Cicada PHY */
2134 /* disable auto-neg, set speed, powerup */
2135 phy_config = (MIICR_REG_PCR | (speed | duplex));
2136 WRITE_REG(adapter->slic_regs->slic_wphy, phy_config,
2142 ("slicoss: %s (%s) EXIT slic_link_config : state[%d] \
2143 phy_config[%x]\n", __func__, adapter->netdev->name, adapter->state,
2147 static void slic_card_cleanup(struct sliccard *card)
2149 DBG_MSG("slicoss: %s ENTER\n", __func__);
2151 #if SLIC_DUMP_ENABLED
2152 if (card->dumpbuffer) {
2153 card->dumpbuffer_phys = 0;
2154 card->dumpbuffer_physl = 0;
2155 card->dumpbuffer_physh = 0;
2156 kfree(card->dumpbuffer);
2157 card->dumpbuffer = NULL;
2159 if (card->cmdbuffer) {
2160 card->cmdbuffer_phys = 0;
2161 card->cmdbuffer_physl = 0;
2162 card->cmdbuffer_physh = 0;
2163 kfree(card->cmdbuffer);
2164 card->cmdbuffer = NULL;
2168 if (card->loadtimerset) {
2169 card->loadtimerset = 0;
2170 del_timer(&card->loadtimer);
2173 slic_debug_card_destroy(card);
2176 DBG_MSG("slicoss: %s EXIT\n", __func__);
2179 static int slic_card_download_gbrcv(struct adapter *adapter)
2181 const struct firmware *fw;
2182 const char *file = "";
2184 __iomem struct slic_regs *slic_regs = adapter->slic_regs;
2188 u32 rcvucodelen = 0;
2190 switch (adapter->devid) {
2191 case SLIC_2GB_DEVICE_ID:
2192 file = "slicoss/oasisrcvucode.sys";
2194 case SLIC_1GB_DEVICE_ID:
2195 file = "slicoss/gbrcvucode.sys";
2202 ret = request_firmware(&fw, file, &adapter->pcidev->dev);
2204 printk(KERN_ERR "SLICOSS: Failed to load firmware %s\n", file);
2208 rcvucodelen = *(u32 *)(fw->data + index);
2210 switch (adapter->devid) {
2211 case SLIC_2GB_DEVICE_ID:
2212 if (rcvucodelen != OasisRcvUCodeLen)
2215 case SLIC_1GB_DEVICE_ID:
2216 if (rcvucodelen != GBRcvUCodeLen)
2223 /* start download */
2224 WRITE_REG(slic_regs->slic_rcv_wcs, SLIC_RCVWCS_BEGIN, FLUSH);
2225 /* download the rcv sequencer ucode */
2226 for (codeaddr = 0; codeaddr < rcvucodelen; codeaddr++) {
2227 /* write out instruction address */
2228 WRITE_REG(slic_regs->slic_rcv_wcs, codeaddr, FLUSH);
2230 instruction = *(u32 *)(fw->data + index);
2232 /* write out the instruction data low addr */
2233 WRITE_REG(slic_regs->slic_rcv_wcs,
2234 instruction, FLUSH);
2236 instruction = *(u8 *)(fw->data + index);
2238 /* write out the instruction data high addr */
2239 WRITE_REG(slic_regs->slic_rcv_wcs, (u8)instruction,
2243 /* download finished */
2244 release_firmware(fw);
2245 WRITE_REG(slic_regs->slic_rcv_wcs, SLIC_RCVWCS_FINISH, FLUSH);
2249 static int slic_card_download(struct adapter *adapter)
2251 const struct firmware *fw;
2252 const char *file = "";
2255 int thissectionsize;
2257 __iomem struct slic_regs *slic_regs = adapter->slic_regs;
2265 int ucode_start, index = 0;
2267 /* DBG_MSG ("slicoss: %s (%s) adapter[%p] card[%p] devid[%x] \
2268 jiffies[%lx] cpu %d\n", __func__, adapter->netdev->name, adapter,
2269 adapter->card, adapter->devid,jiffies, smp_processor_id()); */
2271 switch (adapter->devid) {
2272 case SLIC_2GB_DEVICE_ID:
2273 file = "slicoss/oasisdownload.sys";
2275 case SLIC_1GB_DEVICE_ID:
2276 file = "slicoss/gbdownload.sys";
2282 ret = request_firmware(&fw, file, &adapter->pcidev->dev);
2284 printk(KERN_ERR "SLICOSS: Failed to load firmware %s\n", file);
2287 numsects = *(u32 *)(fw->data + index);
2289 ASSERT(numsects <= 3);
2290 for (i = 0; i < numsects; i++) {
2291 sectsize[i] = *(u32 *)(fw->data + index);
2294 for (i = 0; i < numsects; i++) {
2295 sectstart[i] = *(u32 *)(fw->data + index);
2298 ucode_start = index;
2299 instruction = *(u32 *)(fw->data + index);
2301 for (section = 0; section < numsects; section++) {
2302 baseaddress = sectstart[section];
2303 thissectionsize = sectsize[section] >> 3;
2305 for (codeaddr = 0; codeaddr < thissectionsize; codeaddr++) {
2306 /* Write out instruction address */
2307 WRITE_REG(slic_regs->slic_wcs, baseaddress + codeaddr,
2309 /* Write out instruction to low addr */
2310 WRITE_REG(slic_regs->slic_wcs, instruction, FLUSH);
2311 instruction = *(u32 *)(fw->data + index);
2314 /* Write out instruction to high addr */
2315 WRITE_REG(slic_regs->slic_wcs, instruction, FLUSH);
2316 instruction = *(u32 *)(fw->data + index);
2320 index = ucode_start;
2321 for (section = 0; section < numsects; section++) {
2322 instruction = *(u32 *)(fw->data + index);
2323 baseaddress = sectstart[section];
2324 if (baseaddress < 0x8000)
2326 thissectionsize = sectsize[section] >> 3;
2328 /* DBG_MSG ("slicoss: COMPARE secton[%x] baseaddr[%x] sectnsize[%x]\n",
2329 (uint)section,baseaddress,thissectionsize);*/
2330 for (codeaddr = 0; codeaddr < thissectionsize; codeaddr++) {
2331 /* Write out instruction address */
2332 WRITE_REG(slic_regs->slic_wcs,
2333 SLIC_WCS_COMPARE | (baseaddress + codeaddr),
2335 /* Write out instruction to low addr */
2336 WRITE_REG(slic_regs->slic_wcs, instruction, FLUSH);
2337 instruction = *(u32 *)(fw->data + index);
2339 /* Write out instruction to high addr */
2340 WRITE_REG(slic_regs->slic_wcs, instruction, FLUSH);
2341 instruction = *(u32 *)(fw->data + index);
2344 /* Check SRAM location zero. If it is non-zero. Abort.*/
2345 /* failure = readl((u32 __iomem *)&slic_regs->slic_reset);
2348 ("slicoss: %s FAILURE EXIT codeaddr[%x] "
2349 "thissectionsize[%x] failure[%x]\n",
2350 __func__, codeaddr, thissectionsize,
2352 release_firmware(fw);
2357 /* DBG_MSG ("slicoss: Compare done\n");*/
2358 release_firmware(fw);
2359 /* Everything OK, kick off the card */
2361 WRITE_REG(slic_regs->slic_wcs, SLIC_WCS_START, FLUSH);
2363 /* stall for 20 ms, long enough for ucode to init card
2364 and reach mainloop */
2367 DBG_MSG("slicoss: %s (%s) EXIT adapter[%p] card[%p]\n",
2368 __func__, adapter->netdev->name, adapter, adapter->card);
2370 return STATUS_SUCCESS;
2373 static void slic_adapter_set_hwaddr(struct adapter *adapter)
2375 struct sliccard *card = adapter->card;
2377 /* DBG_MSG ("%s ENTER card->config_set[%x] port[%d] physport[%d] funct#[%d]\n",
2378 __func__, card->config_set, adapter->port, adapter->physport,
2379 adapter->functionnumber);
2381 slic_dbg_macaddrs(adapter); */
2383 if ((adapter->card) && (card->config_set)) {
2384 memcpy(adapter->macaddr,
2385 card->config.MacInfo[adapter->functionnumber].macaddrA,
2386 sizeof(struct slic_config_mac));
2387 /* DBG_MSG ("%s AFTER copying from config.macinfo into currmacaddr\n",
2389 slic_dbg_macaddrs(adapter);*/
2390 if (!(adapter->currmacaddr[0] || adapter->currmacaddr[1] ||
2391 adapter->currmacaddr[2] || adapter->currmacaddr[3] ||
2392 adapter->currmacaddr[4] || adapter->currmacaddr[5])) {
2393 memcpy(adapter->currmacaddr, adapter->macaddr, 6);
2395 if (adapter->netdev) {
2396 memcpy(adapter->netdev->dev_addr, adapter->currmacaddr,
2400 /* DBG_MSG ("%s EXIT port %d\n", __func__, adapter->port);
2401 slic_dbg_macaddrs(adapter); */
2404 static void slic_intagg_set(struct adapter *adapter, u32 value)
2406 __iomem struct slic_regs *slic_regs = adapter->slic_regs;
2408 WRITE_REG(slic_regs->slic_intagg, value, FLUSH);
2409 adapter->card->loadlevel_current = value;
2412 static int slic_card_init(struct sliccard *card, struct adapter *adapter)
2414 __iomem struct slic_regs *slic_regs = adapter->slic_regs;
2415 struct slic_eeprom *peeprom;
2416 struct oslic_eeprom *pOeeprom;
2417 dma_addr_t phys_config;
2421 struct slic_shmem *pshmem;
2423 uint macaddrs = card->card_size;
2428 struct slic_config_mac *pmac;
2429 unsigned char fruformat;
2430 unsigned char oemfruformat;
2431 struct atk_fru *patkfru;
2432 union oemfru *poemfru;
2435 ("slicoss: %s ENTER card[%p] adapter[%p] card->state[%x] \
2436 size[%d]\n", __func__, card, adapter, card->state, card->card_size);
2438 /* Reset everything except PCI configuration space */
2439 slic_soft_reset(adapter);
2441 /* Download the microcode */
2442 status = slic_card_download(adapter);
2444 if (status != STATUS_SUCCESS) {
2445 DBG_ERROR("SLIC download failed bus %d slot %d\n",
2446 (uint) adapter->busnumber,
2447 (uint) adapter->slotnumber);
2451 if (!card->config_set) {
2452 peeprom = pci_alloc_consistent(adapter->pcidev,
2453 sizeof(struct slic_eeprom),
2456 phys_configl = SLIC_GET_ADDR_LOW(phys_config);
2457 phys_configh = SLIC_GET_ADDR_HIGH(phys_config);
2459 DBG_MSG("slicoss: %s Eeprom info adapter [%p]\n "
2460 "size [%x]\n peeprom [%p]\n "
2461 "phys_config [%p]\n phys_configl[%x]\n "
2462 "phys_configh[%x]\n",
2464 (u32)sizeof(struct slic_eeprom),
2465 peeprom, (void *) phys_config, phys_configl,
2469 ("SLIC eeprom read failed to get memory bus %d \
2471 (uint) adapter->busnumber,
2472 (uint) adapter->slotnumber);
2475 memset(peeprom, 0, sizeof(struct slic_eeprom));
2477 WRITE_REG(slic_regs->slic_icr, ICR_INT_OFF, FLUSH);
2479 pshmem = (struct slic_shmem *)adapter->phys_shmem;
2481 spin_lock_irqsave(&adapter->bit64reglock.lock,
2482 adapter->bit64reglock.flags);
2483 WRITE_REG(slic_regs->slic_addr_upper, 0, DONT_FLUSH);
2484 WRITE_REG(slic_regs->slic_isp,
2485 SLIC_GET_ADDR_LOW(&pshmem->isr), FLUSH);
2486 spin_unlock_irqrestore(&adapter->bit64reglock.lock,
2487 adapter->bit64reglock.flags);
2489 slic_config_get(adapter, phys_configl, phys_configh);
2492 if (adapter->pshmem->isr) {
2493 DBG_MSG("%s shmem[%p] shmem->isr[%x]\n",
2494 __func__, adapter->pshmem,
2495 adapter->pshmem->isr);
2497 if (adapter->pshmem->isr & ISR_UPC) {
2498 adapter->pshmem->isr = 0;
2499 WRITE_REG64(adapter,
2500 slic_regs->slic_isp,
2502 slic_regs->slic_addr_upper,
2504 WRITE_REG(slic_regs->slic_isr, 0,
2507 slic_upr_request_complete(adapter, 0);
2510 adapter->pshmem->isr = 0;
2511 WRITE_REG(slic_regs->slic_isr, 0,
2519 ("SLIC: %d config data fetch timed "
2520 "out!\n", adapter->port);
2521 DBG_MSG("%s shmem[%p] shmem->isr[%x]\n",
2522 __func__, adapter->pshmem,
2523 adapter->pshmem->isr);
2524 WRITE_REG64(adapter,
2525 slic_regs->slic_isp, 0,
2526 slic_regs->slic_addr_upper,
2533 switch (adapter->devid) {
2535 case SLIC_2GB_DEVICE_ID:
2536 /* extract EEPROM data and pointers to EEPROM data */
2537 pOeeprom = (struct oslic_eeprom *) peeprom;
2538 eecodesize = pOeeprom->EecodeSize;
2539 dramsize = pOeeprom->DramSize;
2540 pmac = pOeeprom->MacInfo;
2541 fruformat = pOeeprom->FruFormat;
2542 patkfru = &pOeeprom->AtkFru;
2543 oemfruformat = pOeeprom->OemFruFormat;
2544 poemfru = &pOeeprom->OemFru;
2546 /* Minor kludge for Oasis card
2547 get 2 MAC addresses from the
2548 EEPROM to ensure that function 1
2549 gets the Port 1 MAC address */
2552 /* extract EEPROM data and pointers to EEPROM data */
2553 eecodesize = peeprom->EecodeSize;
2554 dramsize = peeprom->DramSize;
2555 pmac = peeprom->u2.mac.MacInfo;
2556 fruformat = peeprom->FruFormat;
2557 patkfru = &peeprom->AtkFru;
2558 oemfruformat = peeprom->OemFruFormat;
2559 poemfru = &peeprom->OemFru;
2563 card->config.EepromValid = false;
2565 /* see if the EEPROM is valid by checking it's checksum */
2566 if ((eecodesize <= MAX_EECODE_SIZE) &&
2567 (eecodesize >= MIN_EECODE_SIZE)) {
2570 *(u16 *) ((char *) peeprom + (eecodesize - 2));
2572 calculate the EEPROM checksum
2575 ~slic_eeprom_cksum((char *) peeprom,
2578 if the ucdoe chksum flag bit worked,
2579 we wouldn't need this shit
2581 if (ee_chksum == calc_chksum)
2582 card->config.EepromValid = true;
2584 /* copy in the DRAM size */
2585 card->config.DramSize = dramsize;
2587 /* copy in the MAC address(es) */
2588 for (i = 0; i < macaddrs; i++) {
2589 memcpy(&card->config.MacInfo[i],
2590 &pmac[i], sizeof(struct slic_config_mac));
2592 /* DBG_MSG ("%s EEPROM Checksum Good? %d MacAddress\n",__func__,
2593 card->config.EepromValid); */
2595 /* copy the Alacritech FRU information */
2596 card->config.FruFormat = fruformat;
2597 memcpy(&card->config.AtkFru, patkfru,
2598 sizeof(struct atk_fru));
2600 pci_free_consistent(adapter->pcidev,
2601 sizeof(struct slic_eeprom),
2602 peeprom, phys_config);
2604 ("slicoss: %s adapter%d [%p] size[%x] FREE peeprom[%p] \
2606 __func__, adapter->port, adapter,
2607 (u32) sizeof(struct slic_eeprom), peeprom,
2608 (void *) phys_config);
2610 if ((!card->config.EepromValid) &&
2611 (adapter->reg_params.fail_on_bad_eeprom)) {
2612 WRITE_REG64(adapter,
2613 slic_regs->slic_isp,
2614 0, slic_regs->slic_addr_upper, 0, FLUSH);
2616 ("unsupported CONFIGURATION EEPROM invalid\n");
2620 card->config_set = 1;
2623 if (slic_card_download_gbrcv(adapter)) {
2624 DBG_ERROR("%s unable to download GB receive microcode\n",
2629 if (slic_global.dynamic_intagg) {
2631 ("Dynamic Interrupt Aggregation[ENABLED]: slic%d \
2632 SET intagg to %d\n",
2634 slic_intagg_set(adapter, 0);
2636 slic_intagg_set(adapter, intagg_delay);
2638 ("Dynamic Interrupt Aggregation[DISABLED]: slic%d \
2639 SET intagg to %d\n",
2640 card->cardnum, intagg_delay);
2644 * Initialize ping status to "ok"
2646 card->pingstatus = ISR_PINGMASK;
2648 #if SLIC_DUMP_ENABLED
2649 if (!card->dumpbuffer) {
2650 card->dumpbuffer = kmalloc(DUMP_PAGE_SIZE, GFP_KERNEL);
2652 ASSERT(card->dumpbuffer);
2653 if (card->dumpbuffer == NULL)
2657 * Smear the shared memory structure and then obtain
2658 * the PHYSICAL address of this structure
2660 memset(card->dumpbuffer, 0, DUMP_PAGE_SIZE);
2661 card->dumpbuffer_phys = virt_to_bus(card->dumpbuffer);
2662 card->dumpbuffer_physh = SLIC_GET_ADDR_HIGH(card->dumpbuffer_phys);
2663 card->dumpbuffer_physl = SLIC_GET_ADDR_LOW(card->dumpbuffer_phys);
2666 * Allocate COMMAND BUFFER
2668 if (!card->cmdbuffer) {
2669 card->cmdbuffer = kmalloc(sizeof(struct dump_cmd), GFP_KERNEL);
2671 ASSERT(card->cmdbuffer);
2672 if (card->cmdbuffer == NULL)
2676 * Smear the shared memory structure and then obtain
2677 * the PHYSICAL address of this structure
2679 memset(card->cmdbuffer, 0, sizeof(struct dump_cmd));
2680 card->cmdbuffer_phys = virt_to_bus(card->cmdbuffer);
2681 card->cmdbuffer_physh = SLIC_GET_ADDR_HIGH(card->cmdbuffer_phys);
2682 card->cmdbuffer_physl = SLIC_GET_ADDR_LOW(card->cmdbuffer_phys);
2686 * Lastly, mark our card state as up and return success
2688 card->state = CARD_UP;
2689 card->reset_in_progress = 0;
2690 DBG_MSG("slicoss: %s EXIT card[%p] adapter[%p] card->state[%x]\n",
2691 __func__, card, adapter, card->state);
2693 return STATUS_SUCCESS;
2696 static u32 slic_card_locate(struct adapter *adapter)
2698 struct sliccard *card = slic_global.slic_card;
2699 struct physcard *physcard = slic_global.phys_card;
2701 u16 __iomem *hostid_reg;
2703 uint rdhostid_offset = 0;
2705 DBG_MSG("slicoss: %s adapter[%p] slot[%x] bus[%x] port[%x]\n",
2706 __func__, adapter, adapter->slotnumber, adapter->busnumber,
2709 switch (adapter->devid) {
2710 case SLIC_2GB_DEVICE_ID:
2711 rdhostid_offset = SLIC_RDHOSTID_2GB;
2713 case SLIC_1GB_DEVICE_ID:
2714 rdhostid_offset = SLIC_RDHOSTID_1GB;
2722 (u16 __iomem *) (((u8 __iomem *) (adapter->slic_regs)) +
2724 DBG_MSG("slicoss: %s *hostid_reg[%p] == ", __func__, hostid_reg);
2726 /* read the 16 bit hostid from SRAM */
2727 card_hostid = (ushort) readw(hostid_reg);
2728 DBG_MSG(" card_hostid[%x]\n", card_hostid);
2730 /* Initialize a new card structure if need be */
2731 if (card_hostid == SLIC_HOSTID_DEFAULT) {
2732 card = kzalloc(sizeof(struct sliccard), GFP_KERNEL);
2736 card->next = slic_global.slic_card;
2737 slic_global.slic_card = card;
2739 if (adapter->devid == SLIC_2GB_DEVICE_ID) {
2741 ("SLICOSS ==> Initialize 2 Port Gigabit Server "
2742 "and Storage Accelerator\n");
2745 ("SLICOSS ==> Initialize 1 Port Gigabit Server "
2746 "and Storage Accelerator\n");
2749 card->busnumber = adapter->busnumber;
2750 card->slotnumber = adapter->slotnumber;
2752 /* Find an available cardnum */
2753 for (i = 0; i < SLIC_MAX_CARDS; i++) {
2754 if (slic_global.cardnuminuse[i] == 0) {
2755 slic_global.cardnuminuse[i] = 1;
2760 slic_global.num_slic_cards++;
2761 DBG_MSG("\nCARDNUM == %d Total %d Card[%p]\n\n",
2762 card->cardnum, slic_global.num_slic_cards, card);
2764 slic_debug_card_create(card);
2767 ("slicoss: %s CARD already allocated, find the \
2768 correct card\n", __func__);
2769 /* Card exists, find the card this adapter belongs to */
2772 ("slicoss: %s card[%p] slot[%x] bus[%x] \
2773 adaptport[%p] hostid[%x] cardnum[%x]\n",
2774 __func__, card, card->slotnumber,
2775 card->busnumber, card->adapter[adapter->port],
2776 card_hostid, card->cardnum);
2778 if (card->cardnum == card_hostid)
2786 return STATUS_FAILURE;
2787 /* Put the adapter in the card's adapter list */
2788 ASSERT(card->adapter[adapter->port] == NULL);
2789 if (!card->adapter[adapter->port]) {
2790 card->adapter[adapter->port] = adapter;
2791 adapter->card = card;
2794 card->card_size = 1; /* one port per *logical* card */
2797 for (i = 0; i < SLIC_MAX_PORTS; i++) {
2798 if (!physcard->adapter[i])
2803 ASSERT(i != SLIC_MAX_PORTS);
2804 if (physcard->adapter[i]->slotnumber == adapter->slotnumber)
2806 physcard = physcard->next;
2809 /* no structure allocated for this physical card yet */
2810 physcard = kzalloc(sizeof(struct physcard), GFP_KERNEL);
2814 ("\n%s Allocate a PHYSICALcard:\n PHYSICAL_Card[%p]\n"
2815 " LogicalCard [%p]\n adapter [%p]\n",
2816 __func__, physcard, card, adapter);
2818 physcard->next = slic_global.phys_card;
2819 slic_global.phys_card = physcard;
2820 physcard->adapters_allocd = 1;
2822 physcard->adapters_allocd++;
2824 /* Note - this is ZERO relative */
2825 adapter->physport = physcard->adapters_allocd - 1;
2827 ASSERT(physcard->adapter[adapter->physport] == NULL);
2828 physcard->adapter[adapter->physport] = adapter;
2829 adapter->physcard = physcard;
2830 DBG_MSG(" PHYSICAL_Port %d Logical_Port %d\n", adapter->physport,
2836 static void slic_soft_reset(struct adapter *adapter)
2838 if (adapter->card->state == CARD_UP) {
2839 DBG_MSG("slicoss: %s QUIESCE adapter[%p] card[%p] devid[%x]\n",
2840 __func__, adapter, adapter->card, adapter->devid);
2841 WRITE_REG(adapter->slic_regs->slic_quiesce, 0, FLUSH);
2844 /* DBG_MSG ("slicoss: %s (%s) adapter[%p] card[%p] devid[%x]\n",
2845 __func__, adapter->netdev->name, adapter, adapter->card,
2848 WRITE_REG(adapter->slic_regs->slic_reset, SLIC_RESET_MAGIC, FLUSH);
2852 static void slic_config_set(struct adapter *adapter, bool linkchange)
2856 __iomem struct slic_regs *slic_regs = adapter->slic_regs;
2858 DBG_MSG("slicoss: %s (%s) slic_interface_enable[%p](%d)\n",
2859 __func__, adapter->netdev->name, adapter,
2860 adapter->cardindex);
2864 slic_mac_config(adapter);
2865 RcrReset = GRCR_RESET;
2867 slic_mac_address_config(adapter);
2871 if (adapter->linkduplex == LINK_FULLD) {
2873 value = (GXCR_RESET | /* Always reset */
2874 GXCR_XMTEN | /* Enable transmit */
2875 GXCR_PAUSEEN); /* Enable pause */
2877 DBG_MSG("slicoss: FDX adapt[%p] set xmtcfg to [%x]\n", adapter,
2879 WRITE_REG(slic_regs->slic_wxcfg, value, FLUSH);
2881 /* Setup rcvcfg last */
2882 value = (RcrReset | /* Reset, if linkchange */
2883 GRCR_CTLEN | /* Enable CTL frames */
2884 GRCR_ADDRAEN | /* Address A enable */
2885 GRCR_RCVBAD | /* Rcv bad frames */
2886 (GRCR_HASHSIZE << GRCR_HASHSIZE_SHIFT));
2889 value = (GXCR_RESET | /* Always reset */
2890 GXCR_XMTEN); /* Enable transmit */
2892 DBG_MSG("slicoss: HDX adapt[%p] set xmtcfg to [%x]\n", adapter,
2894 WRITE_REG(slic_regs->slic_wxcfg, value, FLUSH);
2896 /* Setup rcvcfg last */
2897 value = (RcrReset | /* Reset, if linkchange */
2898 GRCR_ADDRAEN | /* Address A enable */
2899 GRCR_RCVBAD | /* Rcv bad frames */
2900 (GRCR_HASHSIZE << GRCR_HASHSIZE_SHIFT));
2903 if (adapter->state != ADAPT_DOWN) {
2904 /* Only enable receive if we are restarting or running */
2905 value |= GRCR_RCVEN;
2908 if (adapter->macopts & MAC_PROMISC)
2909 value |= GRCR_RCVALL;
2911 DBG_MSG("slicoss: adapt[%p] set rcvcfg to [%x]\n", adapter, value);
2912 WRITE_REG(slic_regs->slic_wrcfg, value, FLUSH);
2916 * Turn off RCV and XMT, power down PHY
2918 static void slic_config_clear(struct adapter *adapter)
2922 __iomem struct slic_regs *slic_regs = adapter->slic_regs;
2925 value = (GXCR_RESET | /* Always reset */
2926 GXCR_PAUSEEN); /* Enable pause */
2928 WRITE_REG(slic_regs->slic_wxcfg, value, FLUSH);
2930 value = (GRCR_RESET | /* Always reset */
2931 GRCR_CTLEN | /* Enable CTL frames */
2932 GRCR_ADDRAEN | /* Address A enable */
2933 (GRCR_HASHSIZE << GRCR_HASHSIZE_SHIFT));
2935 WRITE_REG(slic_regs->slic_wrcfg, value, FLUSH);
2937 /* power down phy */
2938 phy_config = (MIICR_REG_PCR | (PCR_POWERDOWN));
2939 WRITE_REG(slic_regs->slic_wphy, phy_config, FLUSH);
2942 static void slic_config_get(struct adapter *adapter, u32 config,
2947 status = slic_upr_request(adapter,
2949 (u32) config, (u32) config_h, 0, 0);
2950 ASSERT(status == 0);
2953 static void slic_mac_address_config(struct adapter *adapter)
2957 __iomem struct slic_regs *slic_regs = adapter->slic_regs;
2959 value = *(u32 *) &adapter->currmacaddr[2];
2960 value = ntohl(value);
2961 WRITE_REG(slic_regs->slic_wraddral, value, FLUSH);
2962 WRITE_REG(slic_regs->slic_wraddrbl, value, FLUSH);
2964 value2 = (u32) ((adapter->currmacaddr[0] << 8 |
2965 adapter->currmacaddr[1]) & 0xFFFF);
2967 WRITE_REG(slic_regs->slic_wraddrah, value2, FLUSH);
2968 WRITE_REG(slic_regs->slic_wraddrbh, value2, FLUSH);
2970 DBG_MSG("%s value1[%x] value2[%x] Call slic_mcast_set_mask\n",
2971 __func__, value, value2);
2972 slic_dbg_macaddrs(adapter);
2974 /* Write our multicast mask out to the card. This is done */
2975 /* here in addition to the slic_mcast_addr_set routine */
2976 /* because ALL_MCAST may have been enabled or disabled */
2977 slic_mcast_set_mask(adapter);
2980 static void slic_mac_config(struct adapter *adapter)
2983 __iomem struct slic_regs *slic_regs = adapter->slic_regs;
2985 /* Setup GMAC gaps */
2986 if (adapter->linkspeed == LINK_1000MB) {
2987 value = ((GMCR_GAPBB_1000 << GMCR_GAPBB_SHIFT) |
2988 (GMCR_GAPR1_1000 << GMCR_GAPR1_SHIFT) |
2989 (GMCR_GAPR2_1000 << GMCR_GAPR2_SHIFT));
2991 value = ((GMCR_GAPBB_100 << GMCR_GAPBB_SHIFT) |
2992 (GMCR_GAPR1_100 << GMCR_GAPR1_SHIFT) |
2993 (GMCR_GAPR2_100 << GMCR_GAPR2_SHIFT));
2997 if (adapter->linkspeed == LINK_1000MB)
3000 /* enable fullduplex */
3001 if ((adapter->linkduplex == LINK_FULLD)
3002 || (adapter->macopts & MAC_LOOPBACK)) {
3003 value |= GMCR_FULLD;
3006 /* write mac config */
3007 WRITE_REG(slic_regs->slic_wmcfg, value, FLUSH);
3009 /* setup mac addresses */
3010 slic_mac_address_config(adapter);
3013 static bool slic_mac_filter(struct adapter *adapter,
3014 struct ether_header *ether_frame)
3016 u32 opts = adapter->macopts;
3017 u32 *dhost4 = (u32 *)ðer_frame->ether_dhost[0];
3018 u16 *dhost2 = (u16 *)ðer_frame->ether_dhost[4];
3021 if (opts & MAC_PROMISC) {
3022 DBG_MSG("slicoss: %s (%s) PROMISCUOUS. Accept frame\n",
3023 __func__, adapter->netdev->name);
3027 if ((*dhost4 == 0xFFFFFFFF) && (*dhost2 == 0xFFFF)) {
3028 if (opts & MAC_BCAST) {
3029 adapter->rcv_broadcasts++;
3036 if (ether_frame->ether_dhost[0] & 0x01) {
3037 if (opts & MAC_ALLMCAST) {
3038 adapter->rcv_multicasts++;
3039 adapter->stats.multicast++;
3042 if (opts & MAC_MCAST) {
3043 struct mcast_address *mcaddr = adapter->mcastaddrs;
3046 ETHER_EQ_ADDR(mcaddr->address,
3047 ether_frame->ether_dhost,
3050 adapter->rcv_multicasts++;
3051 adapter->stats.multicast++;
3054 mcaddr = mcaddr->next;
3061 if (opts & MAC_DIRECTED) {
3062 adapter->rcv_unicasts++;
3069 static int slic_mac_set_address(struct net_device *dev, void *ptr)
3071 struct adapter *adapter = (struct adapter *)netdev_priv(dev);
3072 struct sockaddr *addr = ptr;
3074 DBG_MSG("%s ENTER (%s)\n", __func__, adapter->netdev->name);
3076 if (netif_running(dev))
3080 DBG_MSG("slicoss: %s (%s) curr %2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X\n",
3081 __func__, adapter->netdev->name, adapter->currmacaddr[0],
3082 adapter->currmacaddr[1], adapter->currmacaddr[2],
3083 adapter->currmacaddr[3], adapter->currmacaddr[4],
3084 adapter->currmacaddr[5]);
3085 memcpy(dev->dev_addr, addr->sa_data, dev->addr_len);
3086 memcpy(adapter->currmacaddr, addr->sa_data, dev->addr_len);
3087 DBG_MSG("slicoss: %s (%s) new %2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X\n",
3088 __func__, adapter->netdev->name, adapter->currmacaddr[0],
3089 adapter->currmacaddr[1], adapter->currmacaddr[2],
3090 adapter->currmacaddr[3], adapter->currmacaddr[4],
3091 adapter->currmacaddr[5]);
3093 slic_config_set(adapter, true);
3098 * slic_timer_get_stats
3100 * Timer function used to suck the statistics out of the card every
3101 * 50 seconds or whatever STATS_TIMER_INTERVAL is set to.
3104 #if SLIC_GET_STATS_TIMER_ENABLED
3105 static void slic_timer_get_stats(ulong dev)
3107 struct adapter *adapter;
3108 struct sliccard *card;
3109 struct slic_shmem *pshmem;
3112 adapter = netdev_priv((struct net_device *)dev);
3114 card = adapter->card;
3117 if ((card->state == CARD_UP) &&
3118 (adapter->state == ADAPT_UP) && (adapter->linkstate == LINK_UP)) {
3119 pshmem = (struct slic_shmem *)adapter->phys_shmem;
3120 #ifdef CONFIG_X86_64
3121 slic_upr_request(adapter,
3123 SLIC_GET_ADDR_LOW(&pshmem->inicstats),
3124 SLIC_GET_ADDR_HIGH(&pshmem->inicstats), 0, 0);
3125 #elif defined(CONFIG_X86)
3126 slic_upr_request(adapter,
3128 (u32) &pshmem->inicstats, 0, 0, 0);
3133 /* DBG_MSG ("slicoss: %s adapter[%p] linkstate[%x] NOT UP!\n",
3134 __func__, adapter, adapter->linkstate); */
3136 adapter->statstimer.expires = jiffies + (STATS_TIMER_INTERVAL * HZ);
3137 add_timer(&adapter->statstimer);
3140 static void slic_timer_load_check(ulong cardaddr)
3142 struct sliccard *card = (struct sliccard *)cardaddr;
3143 struct adapter *adapter = card->master;
3144 u32 load = card->events;
3147 if ((adapter) && (adapter->state == ADAPT_UP) &&
3148 (card->state == CARD_UP) && (slic_global.dynamic_intagg)) {
3149 if (adapter->devid == SLIC_1GB_DEVICE_ID) {
3150 if (adapter->linkspeed == LINK_1000MB)
3153 if (load > SLIC_LOAD_5)
3154 level = SLIC_INTAGG_5;
3155 else if (load > SLIC_LOAD_4)
3156 level = SLIC_INTAGG_4;
3157 else if (load > SLIC_LOAD_3)
3158 level = SLIC_INTAGG_3;
3159 else if (load > SLIC_LOAD_2)
3160 level = SLIC_INTAGG_2;
3161 else if (load > SLIC_LOAD_1)
3162 level = SLIC_INTAGG_1;
3164 level = SLIC_INTAGG_0;
3166 if (card->loadlevel_current != level) {
3167 card->loadlevel_current = level;
3168 WRITE_REG(adapter->slic_regs->slic_intagg,
3172 if (load > SLIC_LOAD_5)
3173 level = SLIC_INTAGG_5;
3174 else if (load > SLIC_LOAD_4)
3175 level = SLIC_INTAGG_4;
3176 else if (load > SLIC_LOAD_3)
3177 level = SLIC_INTAGG_3;
3178 else if (load > SLIC_LOAD_2)
3179 level = SLIC_INTAGG_2;
3180 else if (load > SLIC_LOAD_1)
3181 level = SLIC_INTAGG_1;
3183 level = SLIC_INTAGG_0;
3184 if (card->loadlevel_current != level) {
3185 card->loadlevel_current = level;
3186 WRITE_REG(adapter->slic_regs->slic_intagg,
3192 card->loadtimer.expires = jiffies + (SLIC_LOADTIMER_PERIOD * HZ);
3193 add_timer(&card->loadtimer);
3196 static void slic_assert_fail(void)
3200 cpuid = smp_processor_id();
3201 curr_pid = current->pid;
3203 DBG_ERROR("%s CPU # %d ---- PID # %d\n", __func__, cpuid, curr_pid);
3206 static int slic_upr_queue_request(struct adapter *adapter,
3210 u32 upr_buffer, u32 upr_buffer_h)
3212 struct slic_upr *upr;
3213 struct slic_upr *uprqueue;
3215 upr = kmalloc(sizeof(struct slic_upr), GFP_ATOMIC);
3217 DBG_MSG("%s COULD NOT ALLOCATE UPR MEM\n", __func__);
3221 upr->adapter = adapter->port;
3222 upr->upr_request = upr_request;
3223 upr->upr_data = upr_data;
3224 upr->upr_buffer = upr_buffer;
3225 upr->upr_data_h = upr_data_h;
3226 upr->upr_buffer_h = upr_buffer_h;
3228 if (adapter->upr_list) {
3229 uprqueue = adapter->upr_list;
3231 while (uprqueue->next)
3232 uprqueue = uprqueue->next;
3233 uprqueue->next = upr;
3235 adapter->upr_list = upr;
3237 return STATUS_SUCCESS;
3240 static int slic_upr_request(struct adapter *adapter,
3244 u32 upr_buffer, u32 upr_buffer_h)
3248 spin_lock_irqsave(&adapter->upr_lock.lock, adapter->upr_lock.flags);
3249 status = slic_upr_queue_request(adapter,
3252 upr_data_h, upr_buffer, upr_buffer_h);
3253 if (status != STATUS_SUCCESS) {
3254 spin_unlock_irqrestore(&adapter->upr_lock.lock,
3255 adapter->upr_lock.flags);
3258 slic_upr_start(adapter);
3259 spin_unlock_irqrestore(&adapter->upr_lock.lock,
3260 adapter->upr_lock.flags);
3261 return STATUS_PENDING;
3264 static void slic_upr_request_complete(struct adapter *adapter, u32 isr)
3266 struct sliccard *card = adapter->card;
3267 struct slic_upr *upr;
3269 /* if (card->dump_requested) {
3270 DBG_MSG("ENTER slic_upr_request_complete Dump in progress ISR[%x]\n",
3273 spin_lock_irqsave(&adapter->upr_lock.lock, adapter->upr_lock.flags);
3274 upr = adapter->upr_list;
3277 spin_unlock_irqrestore(&adapter->upr_lock.lock,
3278 adapter->upr_lock.flags);
3281 adapter->upr_list = upr->next;
3283 adapter->upr_busy = 0;
3284 ASSERT(adapter->port == upr->adapter);
3285 switch (upr->upr_request) {
3286 case SLIC_UPR_STATS:
3288 #if SLIC_GET_STATS_ENABLED
3289 struct slic_stats *slicstats =
3290 (struct slic_stats *) &adapter->pshmem->inicstats;
3291 struct slic_stats *newstats = slicstats;
3292 struct slic_stats *old = &adapter->inicstats_prev;
3293 struct slicnet_stats *stst = &adapter->slic_stats;
3295 if (isr & ISR_UPCERR) {
3297 ("SLIC_UPR_STATS command failed isr[%x]\n",
3302 #if SLIC_GET_STATS_ENABLED
3303 /* DBG_MSG ("slicoss: %s rcv %lx:%lx:%lx:%lx:%lx %lx %lx "
3304 "xmt %lx:%lx:%lx:%lx:%lx %lx %lx\n",
3306 slicstats->rcv_unicasts100,
3307 slicstats->rcv_bytes100,
3308 slicstats->rcv_bytes100,
3309 slicstats->rcv_tcp_bytes100,
3310 slicstats->rcv_tcp_segs100,
3311 slicstats->rcv_other_error100,
3312 slicstats->rcv_drops100,
3313 slicstats->xmit_unicasts100,
3314 slicstats->xmit_bytes100,
3315 slicstats->xmit_bytes100,
3316 slicstats->xmit_tcp_bytes100,
3317 slicstats->xmit_tcp_segs100,
3318 slicstats->xmit_other_error100,
3319 slicstats->xmit_collisions100);*/
3320 UPDATE_STATS_GB(stst->tcp.xmit_tcp_segs,
3321 newstats->xmit_tcp_segs_gb,
3322 old->xmit_tcp_segs_gb);
3324 UPDATE_STATS_GB(stst->tcp.xmit_tcp_bytes,
3325 newstats->xmit_tcp_bytes_gb,
3326 old->xmit_tcp_bytes_gb);
3328 UPDATE_STATS_GB(stst->tcp.rcv_tcp_segs,
3329 newstats->rcv_tcp_segs_gb,
3330 old->rcv_tcp_segs_gb);
3332 UPDATE_STATS_GB(stst->tcp.rcv_tcp_bytes,
3333 newstats->rcv_tcp_bytes_gb,
3334 old->rcv_tcp_bytes_gb);
3336 UPDATE_STATS_GB(stst->iface.xmt_bytes,
3337 newstats->xmit_bytes_gb,
3338 old->xmit_bytes_gb);
3340 UPDATE_STATS_GB(stst->iface.xmt_ucast,
3341 newstats->xmit_unicasts_gb,
3342 old->xmit_unicasts_gb);
3344 UPDATE_STATS_GB(stst->iface.rcv_bytes,
3345 newstats->rcv_bytes_gb,
3348 UPDATE_STATS_GB(stst->iface.rcv_ucast,
3349 newstats->rcv_unicasts_gb,
3350 old->rcv_unicasts_gb);
3352 UPDATE_STATS_GB(stst->iface.xmt_errors,
3353 newstats->xmit_collisions_gb,
3354 old->xmit_collisions_gb);
3356 UPDATE_STATS_GB(stst->iface.xmt_errors,
3357 newstats->xmit_excess_collisions_gb,
3358 old->xmit_excess_collisions_gb);
3360 UPDATE_STATS_GB(stst->iface.xmt_errors,
3361 newstats->xmit_other_error_gb,
3362 old->xmit_other_error_gb);
3364 UPDATE_STATS_GB(stst->iface.rcv_errors,
3365 newstats->rcv_other_error_gb,
3366 old->rcv_other_error_gb);
3368 UPDATE_STATS_GB(stst->iface.rcv_discards,
3369 newstats->rcv_drops_gb,
3372 if (newstats->rcv_drops_gb > old->rcv_drops_gb) {
3373 adapter->rcv_drops +=
3374 (newstats->rcv_drops_gb -
3377 memcpy(old, newstats, sizeof(struct slic_stats));
3382 slic_link_upr_complete(adapter, isr);
3384 case SLIC_UPR_RCONFIG:
3399 card->pingstatus |= (isr & ISR_PINGDSMASK);
3401 #if SLIC_DUMP_ENABLED
3403 card->dumpstatus |= (isr & ISR_UPCMASK);
3410 slic_upr_start(adapter);
3411 spin_unlock_irqrestore(&adapter->upr_lock.lock,
3412 adapter->upr_lock.flags);
3415 static void slic_upr_start(struct adapter *adapter)
3417 struct slic_upr *upr;
3418 __iomem struct slic_regs *slic_regs = adapter->slic_regs;
3424 upr = adapter->upr_list;
3427 if (adapter->upr_busy)
3429 adapter->upr_busy = 1;
3431 switch (upr->upr_request) {
3432 case SLIC_UPR_STATS:
3433 if (upr->upr_data_h == 0) {
3434 WRITE_REG(slic_regs->slic_stats, upr->upr_data, FLUSH);
3436 WRITE_REG64(adapter,
3437 slic_regs->slic_stats64,
3439 slic_regs->slic_addr_upper,
3440 upr->upr_data_h, FLUSH);
3445 WRITE_REG64(adapter,
3446 slic_regs->slic_rlsr,
3448 slic_regs->slic_addr_upper, upr->upr_data_h, FLUSH);
3451 case SLIC_UPR_RCONFIG:
3452 DBG_MSG("%s SLIC_UPR_RCONFIG!!!!\n", __func__);
3453 DBG_MSG("WRITE_REG64 adapter[%p]\n"
3454 " a->slic_regs[%p] slic_regs[%p]\n"
3455 " &slic_rconfig[%p] &slic_addr_upper[%p]\n"
3457 " uprdata[%x] uprdatah[%x]\n",
3458 adapter, adapter->slic_regs, slic_regs,
3459 &slic_regs->slic_rconfig, &slic_regs->slic_addr_upper,
3460 upr, upr->upr_data, upr->upr_data_h);
3461 WRITE_REG64(adapter,
3462 slic_regs->slic_rconfig,
3464 slic_regs->slic_addr_upper, upr->upr_data_h, FLUSH);
3466 #if SLIC_DUMP_ENABLED
3469 DBG_MSG("%s SLIC_UPR_DUMP!!!!\n", __func__);
3470 DBG_MSG("WRITE_REG64 adapter[%p]\n"
3471 " upr_buffer[%x] upr_bufferh[%x]\n"
3472 " upr_data[%x] upr_datah[%x]\n"
3473 " cmdbuff[%p] cmdbuffP[%p]\n"
3474 " dumpbuff[%p] dumpbuffP[%p]\n",
3475 adapter, upr->upr_buffer, upr->upr_buffer_h,
3476 upr->upr_data, upr->upr_data_h,
3477 adapter->card->cmdbuffer,
3478 (void *)adapter->card->cmdbuffer_phys,
3479 adapter->card->dumpbuffer, (
3480 void *)adapter->card->dumpbuffer_phys);
3482 ptr1 = (char *)slic_regs;
3483 ptr2 = (char *)(&slic_regs->slic_dump_cmd);
3484 cmdoffset = ptr2 - ptr1;
3485 DBG_MSG("slic_dump_cmd register offset [%x]\n", cmdoffset);
3487 if (upr->upr_buffer || upr->upr_buffer_h) {
3488 WRITE_REG64(adapter,
3489 slic_regs->slic_dump_data,
3491 slic_regs->slic_addr_upper,
3492 upr->upr_buffer_h, FLUSH);
3494 WRITE_REG64(adapter,
3495 slic_regs->slic_dump_cmd,
3497 slic_regs->slic_addr_upper, upr->upr_data_h, FLUSH);
3501 WRITE_REG(slic_regs->slic_ping, 1, FLUSH);
3508 static void slic_link_upr_complete(struct adapter *adapter, u32 isr)
3510 u32 linkstatus = adapter->pshmem->linkstatus;
3512 unsigned char linkspeed;
3513 unsigned char linkduplex;
3515 DBG_MSG("%s: %s ISR[%x] linkstatus[%x]\n adapter[%p](%d)\n",
3516 __func__, adapter->netdev->name, isr, linkstatus, adapter,
3517 adapter->cardindex);
3519 if ((isr & ISR_UPCERR) || (isr & ISR_UPCBSY)) {
3520 struct slic_shmem *pshmem;
3522 pshmem = (struct slic_shmem *)adapter->phys_shmem;
3523 #if defined(CONFIG_X86_64)
3524 slic_upr_queue_request(adapter,
3526 SLIC_GET_ADDR_LOW(&pshmem->linkstatus),
3527 SLIC_GET_ADDR_HIGH(&pshmem->linkstatus),
3529 #elif defined(CONFIG_X86)
3530 slic_upr_queue_request(adapter,
3532 (u32) &pshmem->linkstatus,
3533 SLIC_GET_ADDR_HIGH(pshmem), 0, 0);
3539 if (adapter->state != ADAPT_UP)
3542 ASSERT((adapter->devid == SLIC_1GB_DEVICE_ID)
3543 || (adapter->devid == SLIC_2GB_DEVICE_ID));
3545 linkup = linkstatus & GIG_LINKUP ? LINK_UP : LINK_DOWN;
3546 if (linkstatus & GIG_SPEED_1000) {
3547 linkspeed = LINK_1000MB;
3548 DBG_MSG("slicoss: %s (%s) GIGABIT Speed==1000MB ",
3549 __func__, adapter->netdev->name);
3550 } else if (linkstatus & GIG_SPEED_100) {
3551 linkspeed = LINK_100MB;
3552 DBG_MSG("slicoss: %s (%s) GIGABIT Speed==100MB ", __func__,
3553 adapter->netdev->name);
3555 linkspeed = LINK_10MB;
3556 DBG_MSG("slicoss: %s (%s) GIGABIT Speed==10MB ", __func__,
3557 adapter->netdev->name);
3559 if (linkstatus & GIG_FULLDUPLEX) {
3560 linkduplex = LINK_FULLD;
3561 DBG_MSG(" Duplex == FULL\n");
3563 linkduplex = LINK_HALFD;
3564 DBG_MSG(" Duplex == HALF\n");
3567 if ((adapter->linkstate == LINK_DOWN) && (linkup == LINK_DOWN)) {
3568 DBG_MSG("slicoss: %s (%s) physport(%d) link still down\n",
3569 __func__, adapter->netdev->name, adapter->physport);
3573 /* link up event, but nothing has changed */
3574 if ((adapter->linkstate == LINK_UP) &&
3575 (linkup == LINK_UP) &&
3576 (adapter->linkspeed == linkspeed) &&
3577 (adapter->linkduplex == linkduplex)) {
3578 DBG_MSG("slicoss: %s (%s) port(%d) link still up\n",
3579 __func__, adapter->netdev->name, adapter->physport);
3583 /* link has changed at this point */
3585 /* link has gone from up to down */
3586 if (linkup == LINK_DOWN) {
3587 adapter->linkstate = LINK_DOWN;
3588 DBG_MSG("slicoss: %s %d LinkDown!\n", __func__,
3593 /* link has gone from down to up */
3594 adapter->linkspeed = linkspeed;
3595 adapter->linkduplex = linkduplex;
3597 if (adapter->linkstate != LINK_UP) {
3599 DBG_MSG("%s call slic_config_set\n", __func__);
3600 slic_config_set(adapter, true);
3601 adapter->linkstate = LINK_UP;
3602 DBG_MSG("\n(%s) Link UP: CALL slic_if_start_queue",
3603 adapter->netdev->name);
3604 slic_if_start_queue(adapter);
3607 switch (linkspeed) {
3610 ("\n(%s) LINK UP!: GIGABIT SPEED == 1000MB duplex[%x]\n",
3611 adapter->netdev->name, adapter->linkduplex);
3614 DBG_MSG("\n(%s) LINK UP!: SPEED == 100MB duplex[%x]\n",
3615 adapter->netdev->name, adapter->linkduplex);
3618 DBG_MSG("\n(%s) LINK UP!: SPEED == 10MB duplex[%x]\n",
3619 adapter->netdev->name, adapter->linkduplex);
3626 * this is here to checksum the eeprom, there is some ucode bug
3627 * which prevens us from using the ucode result.
3628 * remove this once ucode is fixed.
3630 static ushort slic_eeprom_cksum(char *m, int len)
3632 #define ADDCARRY(x) (x > 65535 ? x -= 65535 : x)
3633 #define REDUCE {l_util.l = sum; sum = l_util.s[0] + l_util.s[1]; ADDCARRY(sum);\
3638 u32 byte_swapped = 0;
3655 #ifdef CONFIG_X86_64
3656 w_int = (u32) ((ulong) w & 0x00000000FFFFFFFF);
3660 if ((1 & w_int) && (len > 0)) {
3663 s_util.c[0] = *(unsigned char *)w;
3664 w = (u16 *)((char *)w + 1);
3669 /* Unroll the loop to make overhead from branches &c small. */
3670 while ((len -= 32) >= 0) {
3687 w = (u16 *)((ulong) w + 16); /* verify */
3690 while ((len -= 8) >= 0) {
3695 w = (u16 *)((ulong) w + 4); /* verify */
3698 if (len != 0 || byte_swapped != 0) {
3700 while ((len -= 2) >= 0)
3701 sum += *w++; /* verify */
3707 s_util.c[1] = *(char *) w;
3714 } else if (len == -1) {
3715 s_util.c[0] = *(char *) w;
3724 return (ushort) sum;
3727 static int slic_rspqueue_init(struct adapter *adapter)
3730 struct slic_rspqueue *rspq = &adapter->rspqueue;
3731 __iomem struct slic_regs *slic_regs = adapter->slic_regs;
3734 DBG_MSG("slicoss: %s (%s) ENTER adapter[%p]\n", __func__,
3735 adapter->netdev->name, adapter);
3736 ASSERT(adapter->state == ADAPT_DOWN);
3737 memset(rspq, 0, sizeof(struct slic_rspqueue));
3739 rspq->num_pages = SLIC_RSPQ_PAGES_GB;
3741 for (i = 0; i < rspq->num_pages; i++) {
3743 pci_alloc_consistent(adapter->pcidev, PAGE_SIZE,
3745 if (!rspq->vaddr[i]) {
3747 ("rspqueue_init_failed pci_alloc_consistent\n");
3748 slic_rspqueue_free(adapter);
3749 return STATUS_FAILURE;
3751 #ifndef CONFIG_X86_64
3752 ASSERT(((u32) rspq->vaddr[i] & 0xFFFFF000) ==
3753 (u32) rspq->vaddr[i]);
3754 ASSERT(((u32) rspq->paddr[i] & 0xFFFFF000) ==
3755 (u32) rspq->paddr[i]);
3757 memset(rspq->vaddr[i], 0, PAGE_SIZE);
3758 /* DBG_MSG("slicoss: %s UPLOAD RSPBUFF Page pageix[%x] paddr[%p] "
3760 __func__, i, (void *)rspq->paddr[i], rspq->vaddr[i]); */
3763 WRITE_REG(slic_regs->slic_rbar,
3764 (rspq->paddr[i] | SLIC_RSPQ_BUFSINPAGE),
3767 WRITE_REG64(adapter,
3768 slic_regs->slic_rbar64,
3769 (rspq->paddr[i] | SLIC_RSPQ_BUFSINPAGE),
3770 slic_regs->slic_addr_upper,
3771 paddrh, DONT_FLUSH);
3775 rspq->pageindex = 0;
3776 rspq->rspbuf = (struct slic_rspbuf *)rspq->vaddr[0];
3777 DBG_MSG("slicoss: %s (%s) EXIT adapter[%p]\n", __func__,
3778 adapter->netdev->name, adapter);
3779 return STATUS_SUCCESS;
3782 static int slic_rspqueue_reset(struct adapter *adapter)
3784 struct slic_rspqueue *rspq = &adapter->rspqueue;
3786 DBG_MSG("slicoss: %s (%s) ENTER adapter[%p]\n", __func__,
3787 adapter->netdev->name, adapter);
3788 ASSERT(adapter->state == ADAPT_DOWN);
3791 DBG_MSG("slicoss: Nothing to do. rspq[%p]\n"
3795 rspq, rspq->offset, rspq->pageindex, rspq->rspbuf);
3797 DBG_MSG("slicoss: %s (%s) EXIT adapter[%p]\n", __func__,
3798 adapter->netdev->name, adapter);
3799 return STATUS_SUCCESS;
3802 static void slic_rspqueue_free(struct adapter *adapter)
3805 struct slic_rspqueue *rspq = &adapter->rspqueue;
3807 DBG_MSG("slicoss: %s adapter[%p] port %d rspq[%p] FreeRSPQ\n",
3808 __func__, adapter, adapter->physport, rspq);
3809 for (i = 0; i < rspq->num_pages; i++) {
3810 if (rspq->vaddr[i]) {
3812 ("slicoss: pci_free_consistent rspq->vaddr[%p] \
3814 rspq->vaddr[i], (void *) rspq->paddr[i]);
3815 pci_free_consistent(adapter->pcidev, PAGE_SIZE,
3816 rspq->vaddr[i], rspq->paddr[i]);
3818 rspq->vaddr[i] = NULL;
3822 rspq->pageindex = 0;
3823 rspq->rspbuf = NULL;
3826 static struct slic_rspbuf *slic_rspqueue_getnext(struct adapter *adapter)
3828 struct slic_rspqueue *rspq = &adapter->rspqueue;
3829 struct slic_rspbuf *buf;
3831 if (!(rspq->rspbuf->status))
3835 #ifndef CONFIG_X86_64
3836 ASSERT((buf->status & 0xFFFFFFE0) == 0);
3838 ASSERT(buf->hosthandle);
3839 if (++rspq->offset < SLIC_RSPQ_BUFSINPAGE) {
3841 #ifndef CONFIG_X86_64
3842 ASSERT(((u32) rspq->rspbuf & 0xFFFFFFE0) ==
3843 (u32) rspq->rspbuf);
3846 ASSERT(rspq->offset == SLIC_RSPQ_BUFSINPAGE);
3847 WRITE_REG64(adapter,
3848 adapter->slic_regs->slic_rbar64,
3850 paddr[rspq->pageindex] | SLIC_RSPQ_BUFSINPAGE),
3851 adapter->slic_regs->slic_addr_upper, 0, DONT_FLUSH);
3852 rspq->pageindex = (++rspq->pageindex) % rspq->num_pages;
3854 rspq->rspbuf = (struct slic_rspbuf *)
3855 rspq->vaddr[rspq->pageindex];
3856 #ifndef CONFIG_X86_64
3857 ASSERT(((u32) rspq->rspbuf & 0xFFFFF000) ==
3858 (u32) rspq->rspbuf);
3861 #ifndef CONFIG_X86_64
3862 ASSERT(((u32) buf & 0xFFFFFFE0) == (u32) buf);
3867 static void slic_cmdqmem_init(struct adapter *adapter)
3869 struct slic_cmdqmem *cmdqmem = &adapter->cmdqmem;
3871 memset(cmdqmem, 0, sizeof(struct slic_cmdqmem));
3874 static void slic_cmdqmem_free(struct adapter *adapter)
3876 struct slic_cmdqmem *cmdqmem = &adapter->cmdqmem;
3879 DBG_MSG("slicoss: (%s) adapter[%p] port %d rspq[%p] Free CMDQ Memory\n",
3880 __func__, adapter, adapter->physport, cmdqmem);
3881 for (i = 0; i < SLIC_CMDQ_MAXPAGES; i++) {
3882 if (cmdqmem->pages[i]) {
3883 DBG_MSG("slicoss: %s Deallocate page CmdQPage[%p]\n",
3884 __func__, (void *) cmdqmem->pages[i]);
3885 pci_free_consistent(adapter->pcidev,
3887 (void *) cmdqmem->pages[i],
3888 cmdqmem->dma_pages[i]);
3891 memset(cmdqmem, 0, sizeof(struct slic_cmdqmem));
3894 static u32 *slic_cmdqmem_addpage(struct adapter *adapter)
3896 struct slic_cmdqmem *cmdqmem = &adapter->cmdqmem;
3899 if (cmdqmem->pagecnt >= SLIC_CMDQ_MAXPAGES)
3901 pageaddr = pci_alloc_consistent(adapter->pcidev,
3903 &cmdqmem->dma_pages[cmdqmem->pagecnt]);
3906 #ifndef CONFIG_X86_64
3907 ASSERT(((u32) pageaddr & 0xFFFFF000) == (u32) pageaddr);
3909 cmdqmem->pages[cmdqmem->pagecnt] = pageaddr;
3914 static int slic_cmdq_init(struct adapter *adapter)
3919 DBG_MSG("slicoss: %s ENTER adapter[%p]\n", __func__, adapter);
3920 ASSERT(adapter->state == ADAPT_DOWN);
3921 memset(&adapter->cmdq_all, 0, sizeof(struct slic_cmdqueue));
3922 memset(&adapter->cmdq_free, 0, sizeof(struct slic_cmdqueue));
3923 memset(&adapter->cmdq_done, 0, sizeof(struct slic_cmdqueue));
3924 spin_lock_init(&adapter->cmdq_all.lock.lock);
3925 spin_lock_init(&adapter->cmdq_free.lock.lock);
3926 spin_lock_init(&adapter->cmdq_done.lock.lock);
3927 slic_cmdqmem_init(adapter);
3928 adapter->slic_handle_ix = 1;
3929 for (i = 0; i < SLIC_CMDQ_INITPAGES; i++) {
3930 pageaddr = slic_cmdqmem_addpage(adapter);
3931 #ifndef CONFIG_X86_64
3932 ASSERT(((u32) pageaddr & 0xFFFFF000) == (u32) pageaddr);
3935 slic_cmdq_free(adapter);
3936 return STATUS_FAILURE;
3938 slic_cmdq_addcmdpage(adapter, pageaddr);
3940 adapter->slic_handle_ix = 1;
3941 DBG_MSG("slicoss: %s reset slic_handle_ix to ONE\n", __func__);
3943 return STATUS_SUCCESS;
3946 static void slic_cmdq_free(struct adapter *adapter)
3948 struct slic_hostcmd *cmd;
3950 DBG_MSG("slicoss: %s adapter[%p] port %d FreeCommandsFrom CMDQ\n",
3951 __func__, adapter, adapter->physport);
3952 cmd = adapter->cmdq_all.head;
3955 struct sk_buff *tempskb;
3960 dev_kfree_skb_irq(tempskb);
3963 cmd = cmd->next_all;
3965 memset(&adapter->cmdq_all, 0, sizeof(struct slic_cmdqueue));
3966 memset(&adapter->cmdq_free, 0, sizeof(struct slic_cmdqueue));
3967 memset(&adapter->cmdq_done, 0, sizeof(struct slic_cmdqueue));
3968 slic_cmdqmem_free(adapter);
3971 static void slic_cmdq_reset(struct adapter *adapter)
3973 struct slic_hostcmd *hcmd;
3974 struct sk_buff *skb;
3977 DBG_MSG("%s ENTER adapter[%p]\n", __func__, adapter);
3978 spin_lock_irqsave(&adapter->cmdq_free.lock.lock,
3979 adapter->cmdq_free.lock.flags);
3980 spin_lock_irqsave(&adapter->cmdq_done.lock.lock,
3981 adapter->cmdq_done.lock.flags);
3982 outstanding = adapter->cmdq_all.count - adapter->cmdq_done.count;
3983 outstanding -= adapter->cmdq_free.count;
3984 hcmd = adapter->cmdq_all.head;
3989 DBG_MSG("slicoss: %s hcmd[%p] skb[%p] ", __func__,
3993 DBG_MSG(" Free SKB\n");
3994 dev_kfree_skb_irq(skb);
3996 hcmd = hcmd->next_all;
3998 adapter->cmdq_free.count = 0;
3999 adapter->cmdq_free.head = NULL;
4000 adapter->cmdq_free.tail = NULL;
4001 adapter->cmdq_done.count = 0;
4002 adapter->cmdq_done.head = NULL;
4003 adapter->cmdq_done.tail = NULL;
4004 adapter->cmdq_free.head = adapter->cmdq_all.head;
4005 hcmd = adapter->cmdq_all.head;
4007 adapter->cmdq_free.count++;
4008 hcmd->next = hcmd->next_all;
4009 hcmd = hcmd->next_all;
4011 if (adapter->cmdq_free.count != adapter->cmdq_all.count) {
4012 DBG_ERROR("%s free_count %d != all count %d\n", __func__,
4013 adapter->cmdq_free.count, adapter->cmdq_all.count);
4015 spin_unlock_irqrestore(&adapter->cmdq_done.lock.lock,
4016 adapter->cmdq_done.lock.flags);
4017 spin_unlock_irqrestore(&adapter->cmdq_free.lock.lock,
4018 adapter->cmdq_free.lock.flags);
4019 DBG_MSG("%s EXIT adapter[%p]\n", __func__, adapter);
4022 static void slic_cmdq_addcmdpage(struct adapter *adapter, u32 *page)
4024 struct slic_hostcmd *cmd;
4025 struct slic_hostcmd *prev;
4026 struct slic_hostcmd *tail;
4027 struct slic_cmdqueue *cmdq;
4033 struct slic_handle *pslic_handle;
4036 cmd = (struct slic_hostcmd *)cmdaddr;
4037 /* DBG_MSG("CMDQ Page addr[%p] ix[%d] pfree[%p]\n", cmdaddr, slic_handle_ix,
4038 adapter->pfree_slic_handles); */
4041 phys_addr = virt_to_bus((void *)page);
4042 phys_addrl = SLIC_GET_ADDR_LOW(phys_addr);
4043 phys_addrh = SLIC_GET_ADDR_HIGH(phys_addr);
4047 while ((cmdcnt < SLIC_CMDQ_CMDSINPAGE) &&
4048 (adapter->slic_handle_ix < 256)) {
4049 /* Allocate and initialize a SLIC_HANDLE for this command */
4050 SLIC_GET_SLIC_HANDLE(adapter, pslic_handle);
4051 if (pslic_handle == NULL)
4053 ASSERT(pslic_handle ==
4054 &adapter->slic_handles[pslic_handle->token.
4056 pslic_handle->type = SLIC_HANDLE_CMD;
4057 pslic_handle->address = (void *) cmd;
4058 pslic_handle->offset = (ushort) adapter->slic_handle_ix++;
4059 pslic_handle->other_handle = NULL;
4060 pslic_handle->next = NULL;
4062 cmd->pslic_handle = pslic_handle;
4063 cmd->cmd64.hosthandle = pslic_handle->token.handle_token;
4065 cmd->paddrl = phys_addrl;
4066 cmd->paddrh = phys_addrh;
4067 cmd->next_all = prev;
4070 phys_addrl += SLIC_HOSTCMD_SIZE;
4071 cmdaddr += SLIC_HOSTCMD_SIZE;
4073 cmd = (struct slic_hostcmd *)cmdaddr;
4077 cmdq = &adapter->cmdq_all;
4078 cmdq->count += cmdcnt; /* SLIC_CMDQ_CMDSINPAGE; mooktodo */
4079 tail->next_all = cmdq->head;
4080 ASSERT(VALID_ADDRESS(prev));
4082 cmdq = &adapter->cmdq_free;
4083 spin_lock_irqsave(&cmdq->lock.lock, cmdq->lock.flags);
4084 cmdq->count += cmdcnt; /* SLIC_CMDQ_CMDSINPAGE; mooktodo */
4085 tail->next = cmdq->head;
4086 ASSERT(VALID_ADDRESS(prev));
4088 spin_unlock_irqrestore(&cmdq->lock.lock, cmdq->lock.flags);
4091 static struct slic_hostcmd *slic_cmdq_getfree(struct adapter *adapter)
4093 struct slic_cmdqueue *cmdq = &adapter->cmdq_free;
4094 struct slic_hostcmd *cmd = NULL;
4097 spin_lock_irqsave(&cmdq->lock.lock, cmdq->lock.flags);
4101 cmdq->head = cmd->next;
4103 spin_unlock_irqrestore(&cmdq->lock.lock, cmdq->lock.flags);
4105 slic_cmdq_getdone(adapter);
4112 spin_unlock_irqrestore(&cmdq->lock.lock,
4114 pageaddr = slic_cmdqmem_addpage(adapter);
4116 slic_cmdq_addcmdpage(adapter, pageaddr);
4117 goto lock_and_retry;
4124 static void slic_cmdq_getdone(struct adapter *adapter)
4126 struct slic_cmdqueue *done_cmdq = &adapter->cmdq_done;
4127 struct slic_cmdqueue *free_cmdq = &adapter->cmdq_free;
4129 ASSERT(free_cmdq->head == NULL);
4130 spin_lock_irqsave(&done_cmdq->lock.lock, done_cmdq->lock.flags);
4131 ASSERT(VALID_ADDRESS(done_cmdq->head));
4133 free_cmdq->head = done_cmdq->head;
4134 free_cmdq->count = done_cmdq->count;
4135 done_cmdq->head = NULL;
4136 done_cmdq->tail = NULL;
4137 done_cmdq->count = 0;
4138 spin_unlock_irqrestore(&done_cmdq->lock.lock, done_cmdq->lock.flags);
4141 static void slic_cmdq_putdone_irq(struct adapter *adapter,
4142 struct slic_hostcmd *cmd)
4144 struct slic_cmdqueue *cmdq = &adapter->cmdq_done;
4146 spin_lock(&cmdq->lock.lock);
4148 ASSERT(VALID_ADDRESS(cmdq->head));
4149 cmd->next = cmdq->head;
4150 ASSERT(VALID_ADDRESS(cmd));
4153 if ((adapter->xmitq_full) && (cmdq->count > 10))
4154 netif_wake_queue(adapter->netdev);
4155 spin_unlock(&cmdq->lock.lock);
4158 static int slic_rcvqueue_init(struct adapter *adapter)
4161 struct slic_rcvqueue *rcvq = &adapter->rcvqueue;
4163 DBG_MSG("slicoss: %s ENTER adapter[%p]\n", __func__, adapter);
4164 ASSERT(adapter->state == ADAPT_DOWN);
4167 rcvq->size = SLIC_RCVQ_ENTRIES;
4170 i = (SLIC_RCVQ_ENTRIES / SLIC_RCVQ_FILLENTRIES);
4173 count += slic_rcvqueue_fill(adapter);
4176 if (rcvq->count < SLIC_RCVQ_MINENTRIES) {
4177 slic_rcvqueue_free(adapter);
4178 return STATUS_FAILURE;
4180 DBG_MSG("slicoss: %s EXIT adapter[%p]\n", __func__, adapter);
4181 return STATUS_SUCCESS;
4184 static int slic_rcvqueue_reset(struct adapter *adapter)
4186 struct slic_rcvqueue *rcvq = &adapter->rcvqueue;
4188 DBG_MSG("slicoss: %s ENTER adapter[%p]\n", __func__, adapter);
4189 ASSERT(adapter->state == ADAPT_DOWN);
4192 DBG_MSG("slicoss: Nothing to do. rcvq[%p]\n"
4196 rcvq, rcvq->count, rcvq->head, rcvq->tail);
4198 DBG_MSG("slicoss: %s EXIT adapter[%p]\n", __func__, adapter);
4199 return STATUS_SUCCESS;
4202 static void slic_rcvqueue_free(struct adapter *adapter)
4204 struct slic_rcvqueue *rcvq = &adapter->rcvqueue;
4205 struct sk_buff *skb;
4207 while (rcvq->head) {
4209 rcvq->head = rcvq->head->next;
4217 static struct sk_buff *slic_rcvqueue_getnext(struct adapter *adapter)
4219 struct slic_rcvqueue *rcvq = &adapter->rcvqueue;
4220 struct sk_buff *skb;
4221 struct slic_rcvbuf *rcvbuf;
4226 rcvbuf = (struct slic_rcvbuf *)skb->head;
4229 if (rcvbuf->status & IRHDDR_SVALID) {
4230 rcvq->head = rcvq->head->next;
4237 DBG_ERROR("RcvQ Empty!! adapter[%p] rcvq[%p] count[%x]\n",
4238 adapter, rcvq, rcvq->count);
4241 while (rcvq->count < SLIC_RCVQ_FILLTHRESH) {
4242 count = slic_rcvqueue_fill(adapter);
4251 static int slic_rcvqueue_fill(struct adapter *adapter)
4256 struct slic_rcvqueue *rcvq = &adapter->rcvqueue;
4259 while (i < SLIC_RCVQ_FILLENTRIES) {
4260 struct slic_rcvbuf *rcvbuf;
4261 struct sk_buff *skb;
4262 #ifdef KLUDGE_FOR_4GB_BOUNDARY
4265 skb = alloc_skb(SLIC_RCVQ_RCVBUFSIZE, GFP_ATOMIC);
4267 paddr = (void *)pci_map_single(adapter->pcidev,
4269 SLIC_RCVQ_RCVBUFSIZE,
4270 PCI_DMA_FROMDEVICE);
4271 paddrl = SLIC_GET_ADDR_LOW(paddr);
4272 paddrh = SLIC_GET_ADDR_HIGH(paddr);
4274 skb->len = SLIC_RCVBUF_HEADSIZE;
4275 rcvbuf = (struct slic_rcvbuf *)skb->head;
4278 #ifdef KLUDGE_FOR_4GB_BOUNDARY
4281 ("%s: LOW 32bits PHYSICAL ADDRESS == 0 "
4287 " paddrh[%x]\n", __func__, skb,
4288 skb->data, skb->len, paddr, paddrl,
4290 DBG_ERROR(" rcvq->head[%p]\n"
4292 " rcvq->count[%x]\n",
4293 rcvq->head, rcvq->tail, rcvq->count);
4294 DBG_ERROR("SKIP THIS SKB!!!!!!!!\n");
4295 goto retry_rcvqfill;
4300 ("\n\n%s: LOW 32bits PHYSICAL ADDRESS == 0 "
4301 "skb[%p] GIVE TO CARD ANYWAY\n"
4305 " paddrh[%x]\n", __func__, skb,
4306 skb->data, paddr, paddrl, paddrh);
4310 WRITE_REG(adapter->slic_regs->slic_hbar,
4311 (u32) paddrl, DONT_FLUSH);
4313 WRITE_REG64(adapter,
4314 adapter->slic_regs->slic_hbar64,
4316 adapter->slic_regs->slic_addr_upper,
4317 (u32) paddrh, DONT_FLUSH);
4320 rcvq->tail->next = skb;
4328 ("%s slic_rcvqueue_fill could only get [%d] "
4330 adapter->netdev->name, i);
4337 static u32 slic_rcvqueue_reinsert(struct adapter *adapter, struct sk_buff *skb)
4339 struct slic_rcvqueue *rcvq = &adapter->rcvqueue;
4343 struct slic_rcvbuf *rcvbuf = (struct slic_rcvbuf *)skb->head;
4345 ASSERT(skb->len == SLIC_RCVBUF_HEADSIZE);
4347 paddr = (void *)pci_map_single(adapter->pcidev, skb->head,
4348 SLIC_RCVQ_RCVBUFSIZE, PCI_DMA_FROMDEVICE);
4352 paddrl = SLIC_GET_ADDR_LOW(paddr);
4353 paddrh = SLIC_GET_ADDR_HIGH(paddr);
4357 ("%s: LOW 32bits PHYSICAL ADDRESS == 0 skb[%p] PROBLEM\n"
4358 " skbdata[%p]\n" " skblen[%x]\n"
4359 " paddr[%p]\n" " paddrl[%x]\n"
4360 " paddrh[%x]\n", __func__, skb, skb->data,
4361 skb->len, paddr, paddrl, paddrh);
4362 DBG_ERROR(" rcvq->head[%p]\n"
4364 " rcvq->count[%x]\n", rcvq->head, rcvq->tail,
4368 WRITE_REG(adapter->slic_regs->slic_hbar, (u32) paddrl,
4371 WRITE_REG64(adapter,
4372 adapter->slic_regs->slic_hbar64,
4374 adapter->slic_regs->slic_addr_upper,
4375 paddrh, DONT_FLUSH);
4378 rcvq->tail->next = skb;
4386 static int slic_debug_card_show(struct seq_file *seq, void *v)
4390 struct sliccard *card = seq->private;
4391 struct slic_config *config = &card->config;
4392 unsigned char *fru = (unsigned char *)(&card->config.atk_fru);
4393 unsigned char *oemfru = (unsigned char *)(&card->config.OemFru);
4396 seq_printf(seq, "driver_version : %s\n", slic_proc_version);
4397 seq_printf(seq, "Microcode versions: \n");
4398 seq_printf(seq, " Gigabit (gb) : %s %s\n",
4399 MOJAVE_UCODE_VERS_STRING, MOJAVE_UCODE_VERS_DATE);
4400 seq_printf(seq, " Gigabit Receiver : %s %s\n",
4401 GB_RCVUCODE_VERS_STRING, GB_RCVUCODE_VERS_DATE);
4402 seq_printf(seq, "Vendor : %s\n", slic_vendor);
4403 seq_printf(seq, "Product Name : %s\n", slic_product_name);
4405 seq_printf(seq, "VendorId : %4.4X\n",
4407 seq_printf(seq, "DeviceId : %4.4X\n",
4409 seq_printf(seq, "RevisionId : %2.2x\n",
4410 config->RevisionId);
4411 seq_printf(seq, "Bus # : %d\n", card->busnumber);
4412 seq_printf(seq, "Device # : %d\n", card->slotnumber);
4413 seq_printf(seq, "Interfaces : %d\n", card->card_size);
4414 seq_printf(seq, " Initialized : %d\n",
4415 card->adapters_activated);
4416 seq_printf(seq, " Allocated : %d\n",
4417 card->adapters_allocated);
4418 ASSERT(card->card_size <= SLIC_NBR_MACS);
4419 for (i = 0; i < card->card_size; i++) {
4421 " MAC%d : %2.2X %2.2X %2.2X %2.2X %2.2X %2.2X\n",
4422 i, config->macinfo[i].macaddrA[0],
4423 config->macinfo[i].macaddrA[1],
4424 config->macinfo[i].macaddrA[2],
4425 config->macinfo[i].macaddrA[3],
4426 config->macinfo[i].macaddrA[4],
4427 config->macinfo[i].macaddrA[5]);
4429 seq_printf(seq, " IF Init State Duplex/Speed irq\n");
4430 seq_printf(seq, " -------------------------------\n");
4431 for (i = 0; i < card->adapters_allocated; i++) {
4432 struct adapter *adapter;
4434 adapter = card->adapter[i];
4437 " %d %d %s %s %s 0x%X\n",
4438 adapter->physport, adapter->state,
4439 SLIC_LINKSTATE(adapter->linkstate),
4440 SLIC_DUPLEX(adapter->linkduplex),
4441 SLIC_SPEED(adapter->linkspeed),
4442 (uint) adapter->irq);
4445 seq_printf(seq, "Generation # : %4.4X\n", card->gennumber);
4446 seq_printf(seq, "RcvQ max entries : %4.4X\n",
4448 seq_printf(seq, "Ping Status : %8.8X\n",
4450 seq_printf(seq, "Minimum grant : %2.2x\n",
4452 seq_printf(seq, "Maximum Latency : %2.2x\n", config->MaxLat);
4453 seq_printf(seq, "PciStatus : %4.4x\n",
4455 seq_printf(seq, "Debug Device Id : %4.4x\n",
4457 seq_printf(seq, "DRAM ROM Function : %4.4x\n",
4459 seq_printf(seq, "Network interface Pin 1 : %2.2x\n",
4460 config->NetIntPin1);
4461 seq_printf(seq, "Network interface Pin 2 : %2.2x\n",
4462 config->NetIntPin1);
4463 seq_printf(seq, "Network interface Pin 3 : %2.2x\n",
4464 config->NetIntPin1);
4465 seq_printf(seq, "PM capabilities : %4.4X\n",
4467 seq_printf(seq, "Network Clock Controls : %4.4X\n",
4468 config->NwClkCtrls);
4470 switch (config->FruFormat) {
4471 case ATK_FRU_FORMAT:
4474 "Vendor : Alacritech, Inc.\n");
4476 "Assembly # : %c%c%c%c%c%c\n",
4477 fru[0], fru[1], fru[2], fru[3], fru[4],
4480 "Revision # : %c%c\n",
4483 if (config->OEMFruFormat == VENDOR4_FRU_FORMAT) {
4486 "%c%c%c%c%c%c%c%c%c%c%c%c\n",
4487 fru[8], fru[9], fru[10],
4488 fru[11], fru[12], fru[13],
4489 fru[16], fru[17], fru[18],
4490 fru[19], fru[20], fru[21]);
4494 "%c%c%c%c%c%c%c%c%c%c%c%c%c%c\n",
4495 fru[8], fru[9], fru[10],
4496 fru[11], fru[12], fru[13],
4497 fru[14], fru[15], fru[16],
4498 fru[17], fru[18], fru[19],
4507 "Vendor : Alacritech, Inc.\n");
4509 "Serial # : Empty FRU\n");
4514 switch (config->OEMFruFormat) {
4515 case VENDOR1_FRU_FORMAT:
4517 seq_printf(seq, "FRU Information:\n");
4518 seq_printf(seq, " Commodity # : %c\n",
4521 " Assembly # : %c%c%c%c\n",
4522 oemfru[1], oemfru[2], oemfru[3], oemfru[4]);
4524 " Revision # : %c%c\n",
4525 oemfru[5], oemfru[6]);
4527 " Supplier # : %c%c\n",
4528 oemfru[7], oemfru[8]);
4531 oemfru[9], oemfru[10]);
4533 " Sequence # : %c%c%c\n",
4534 oemfru[11], oemfru[12], oemfru[13]);
4538 case VENDOR2_FRU_FORMAT:
4540 seq_printf(seq, "FRU Information:\n");
4543 "%c%c%c%c%c%c%c%c\n",
4544 oemfru[0], oemfru[1], oemfru[2],
4545 oemfru[3], oemfru[4], oemfru[5],
4546 oemfru[6], oemfru[7]);
4548 " Supplier # : %c%c%c%c%c\n",
4549 oemfru[8], oemfru[9], oemfru[10],
4550 oemfru[11], oemfru[12]);
4553 oemfru[13], oemfru[14], oemfru[15]);
4555 " Sequence # : %c%c%c%c\n",
4556 oemfru[16], oemfru[17], oemfru[18],
4561 case VENDOR3_FRU_FORMAT:
4563 seq_printf(seq, "FRU Information:\n");
4566 case VENDOR4_FRU_FORMAT:
4568 seq_printf(seq, "FRU Information:\n");
4571 "%c%c%c%c%c%c%c%c\n",
4572 oemfru[0], oemfru[1], oemfru[2],
4573 oemfru[3], oemfru[4], oemfru[5],
4574 oemfru[6], oemfru[7]);
4577 "%c%c%c%c%c%c%c%c\n",
4578 oemfru[8], oemfru[9], oemfru[10],
4579 oemfru[11], oemfru[12], oemfru[13],
4580 oemfru[14], oemfru[15]);
4583 "%c%c%c%c%c%c%c%c\n",
4584 oemfru[16], oemfru[17], oemfru[18],
4585 oemfru[19], oemfru[20], oemfru[21],
4586 oemfru[22], oemfru[23]);
4598 static int slic_debug_adapter_show(struct seq_file *seq, void *v)
4600 struct adapter *adapter = seq->private;
4602 if ((adapter->netdev) && (adapter->netdev->name)) {
4603 seq_printf(seq, "info: interface : %s\n",
4604 adapter->netdev->name);
4606 seq_printf(seq, "info: status : %s\n",
4607 SLIC_LINKSTATE(adapter->linkstate));
4608 seq_printf(seq, "info: port : %d\n",
4610 seq_printf(seq, "info: speed : %s\n",
4611 SLIC_SPEED(adapter->linkspeed));
4612 seq_printf(seq, "info: duplex : %s\n",
4613 SLIC_DUPLEX(adapter->linkduplex));
4614 seq_printf(seq, "info: irq : 0x%X\n",
4615 (uint) adapter->irq);
4616 seq_printf(seq, "info: Interrupt Agg Delay: %d usec\n",
4617 adapter->card->loadlevel_current);
4618 seq_printf(seq, "info: RcvQ max entries : %4.4X\n",
4620 seq_printf(seq, "info: RcvQ current : %4.4X\n",
4621 adapter->rcvqueue.count);
4622 seq_printf(seq, "rx stats: packets : %8.8lX\n",
4623 adapter->stats.rx_packets);
4624 seq_printf(seq, "rx stats: bytes : %8.8lX\n",
4625 adapter->stats.rx_bytes);
4626 seq_printf(seq, "rx stats: broadcasts : %8.8X\n",
4627 adapter->rcv_broadcasts);
4628 seq_printf(seq, "rx stats: multicasts : %8.8X\n",
4629 adapter->rcv_multicasts);
4630 seq_printf(seq, "rx stats: unicasts : %8.8X\n",
4631 adapter->rcv_unicasts);
4632 seq_printf(seq, "rx stats: errors : %8.8X\n",
4633 (u32) adapter->slic_stats.iface.rcv_errors);
4634 seq_printf(seq, "rx stats: Missed errors : %8.8X\n",
4635 (u32) adapter->slic_stats.iface.rcv_discards);
4636 seq_printf(seq, "rx stats: drops : %8.8X\n",
4637 (u32) adapter->rcv_drops);
4638 seq_printf(seq, "tx stats: packets : %8.8lX\n",
4639 adapter->stats.tx_packets);
4640 seq_printf(seq, "tx stats: bytes : %8.8lX\n",
4641 adapter->stats.tx_bytes);
4642 seq_printf(seq, "tx stats: errors : %8.8X\n",
4643 (u32) adapter->slic_stats.iface.xmt_errors);
4644 seq_printf(seq, "rx stats: multicasts : %8.8lX\n",
4645 adapter->stats.multicast);
4646 seq_printf(seq, "tx stats: collision errors : %8.8X\n",
4647 (u32) adapter->slic_stats.iface.xmit_collisions);
4648 seq_printf(seq, "perf: Max rcv frames/isr : %8.8X\n",
4649 adapter->max_isr_rcvs);
4650 seq_printf(seq, "perf: Rcv interrupt yields : %8.8X\n",
4651 adapter->rcv_interrupt_yields);
4652 seq_printf(seq, "perf: Max xmit complete/isr : %8.8X\n",
4653 adapter->max_isr_xmits);
4654 seq_printf(seq, "perf: error interrupts : %8.8X\n",
4655 adapter->error_interrupts);
4656 seq_printf(seq, "perf: error rmiss interrupts : %8.8X\n",
4657 adapter->error_rmiss_interrupts);
4658 seq_printf(seq, "perf: rcv interrupts : %8.8X\n",
4659 adapter->rcv_interrupts);
4660 seq_printf(seq, "perf: xmit interrupts : %8.8X\n",
4661 adapter->xmit_interrupts);
4662 seq_printf(seq, "perf: link event interrupts : %8.8X\n",
4663 adapter->linkevent_interrupts);
4664 seq_printf(seq, "perf: UPR interrupts : %8.8X\n",
4665 adapter->upr_interrupts);
4666 seq_printf(seq, "perf: interrupt count : %8.8X\n",
4668 seq_printf(seq, "perf: false interrupts : %8.8X\n",
4669 adapter->false_interrupts);
4670 seq_printf(seq, "perf: All register writes : %8.8X\n",
4671 adapter->all_reg_writes);
4672 seq_printf(seq, "perf: ICR register writes : %8.8X\n",
4673 adapter->icr_reg_writes);
4674 seq_printf(seq, "perf: ISR register writes : %8.8X\n",
4675 adapter->isr_reg_writes);
4676 seq_printf(seq, "ifevents: overflow 802 errors : %8.8X\n",
4677 adapter->if_events.oflow802);
4678 seq_printf(seq, "ifevents: transport overflow errors: %8.8X\n",
4679 adapter->if_events.Tprtoflow);
4680 seq_printf(seq, "ifevents: underflow errors : %8.8X\n",
4681 adapter->if_events.uflow802);
4682 seq_printf(seq, "ifevents: receive early : %8.8X\n",
4683 adapter->if_events.rcvearly);
4684 seq_printf(seq, "ifevents: buffer overflows : %8.8X\n",
4685 adapter->if_events.Bufov);
4686 seq_printf(seq, "ifevents: carrier errors : %8.8X\n",
4687 adapter->if_events.Carre);
4688 seq_printf(seq, "ifevents: Long : %8.8X\n",
4689 adapter->if_events.Longe);
4690 seq_printf(seq, "ifevents: invalid preambles : %8.8X\n",
4691 adapter->if_events.Invp);
4692 seq_printf(seq, "ifevents: CRC errors : %8.8X\n",
4693 adapter->if_events.Crc);
4694 seq_printf(seq, "ifevents: dribble nibbles : %8.8X\n",
4695 adapter->if_events.Drbl);
4696 seq_printf(seq, "ifevents: Code violations : %8.8X\n",
4697 adapter->if_events.Code);
4698 seq_printf(seq, "ifevents: TCP checksum errors : %8.8X\n",
4699 adapter->if_events.TpCsum);
4700 seq_printf(seq, "ifevents: TCP header short errors : %8.8X\n",
4701 adapter->if_events.TpHlen);
4702 seq_printf(seq, "ifevents: IP checksum errors : %8.8X\n",
4703 adapter->if_events.IpCsum);
4704 seq_printf(seq, "ifevents: IP frame incompletes : %8.8X\n",
4705 adapter->if_events.IpLen);
4706 seq_printf(seq, "ifevents: IP headers shorts : %8.8X\n",
4707 adapter->if_events.IpHlen);
4711 static int slic_debug_adapter_open(struct inode *inode, struct file *file)
4713 return single_open(file, slic_debug_adapter_show, inode->i_private);
4716 static int slic_debug_card_open(struct inode *inode, struct file *file)
4718 return single_open(file, slic_debug_card_show, inode->i_private);
4721 static const struct file_operations slic_debug_adapter_fops = {
4722 .owner = THIS_MODULE,
4723 .open = slic_debug_adapter_open,
4725 .llseek = seq_lseek,
4726 .release = single_release,
4729 static const struct file_operations slic_debug_card_fops = {
4730 .owner = THIS_MODULE,
4731 .open = slic_debug_card_open,
4733 .llseek = seq_lseek,
4734 .release = single_release,
4737 static void slic_debug_adapter_create(struct adapter *adapter)
4741 struct sliccard *card = adapter->card;
4743 if (!card->debugfs_dir)
4746 sprintf(name, "port%d", adapter->port);
4747 d = debugfs_create_file(name, S_IRUGO,
4748 card->debugfs_dir, adapter,
4749 &slic_debug_adapter_fops);
4750 if (!d || IS_ERR(d))
4751 pr_info(PFX "%s: debugfs create failed\n", name);
4753 adapter->debugfs_entry = d;
4756 static void slic_debug_adapter_destroy(struct adapter *adapter)
4758 if (adapter->debugfs_entry) {
4759 debugfs_remove(adapter->debugfs_entry);
4760 adapter->debugfs_entry = NULL;
4764 static void slic_debug_card_create(struct sliccard *card)
4767 char name[IFNAMSIZ];
4769 snprintf(name, sizeof(name), "slic%d", card->cardnum);
4770 d = debugfs_create_dir(name, slic_debugfs);
4771 if (!d || IS_ERR(d))
4772 pr_info(PFX "%s: debugfs create dir failed\n",
4775 card->debugfs_dir = d;
4776 d = debugfs_create_file("cardinfo", S_IRUGO,
4778 &slic_debug_card_fops);
4779 if (!d || IS_ERR(d))
4780 pr_info(PFX "%s: debugfs create failed\n",
4783 card->debugfs_cardinfo = d;
4787 static void slic_debug_card_destroy(struct sliccard *card)
4791 for (i = 0; i < card->card_size; i++) {
4792 struct adapter *adapter;
4794 adapter = card->adapter[i];
4796 slic_debug_adapter_destroy(adapter);
4798 if (card->debugfs_cardinfo) {
4799 debugfs_remove(card->debugfs_cardinfo);
4800 card->debugfs_cardinfo = NULL;
4802 if (card->debugfs_dir) {
4803 debugfs_remove(card->debugfs_dir);
4804 card->debugfs_dir = NULL;
4808 static void slic_debug_init(void)
4812 ent = debugfs_create_dir("slic", NULL);
4813 if (!ent || IS_ERR(ent)) {
4814 pr_info(PFX "debugfs create directory failed\n");
4821 static void slic_debug_cleanup(void)
4824 debugfs_remove(slic_debugfs);
4825 slic_debugfs = NULL;
4829 /*=============================================================================
4830 =============================================================================
4832 === SLIC DUMP MANAGEMENT SECTION ===
4835 === Dump routines ===
4838 =============================================================================
4839 ============================================================================*/
4841 #if SLIC_DUMP_ENABLED
4845 void *slic_dump_handle; /* thread handle */
4848 * These are the only things you should do on a core-file: use only these
4849 * functions to write out all the necessary info.
4851 static int slic_dump_seek(struct file *SLIChandle, u32 file_offset)
4853 if (SLIChandle->f_pos != file_offset) {
4854 /*DBG_MSG("slic_dump_seek now needed [%x : %x]\n",
4855 (u32)SLIChandle->f_pos, (u32)file_offset); */
4856 if (SLIChandle->f_op->llseek) {
4857 if (SLIChandle->f_op->
4858 llseek(SLIChandle, file_offset, 0) != file_offset)
4861 SLIChandle->f_pos = file_offset;
4867 static int slic_dump_write(struct sliccard *card,
4868 const void *addr, int size, u32 file_offset)
4872 struct file *SLIChandle = card->dumphandle;
4874 #ifdef HISTORICAL /* legacy */
4875 down(&SLIChandle->f_dentry->d_inode->i_sem);
4878 slic_dump_seek(SLIChandle, file_offset);
4881 SLIChandle->f_op->write(SLIChandle, addr, size,
4882 &SLIChandle->f_pos);
4887 card->dumptime_complete = jiffies;
4888 card->dumptime_delta = card->dumptime_complete - card->dumptime_start;
4889 card->dumptime_start = jiffies;
4892 up(&SLIChandle->f_dentry->d_inode->i_sem);
4895 DBG_ERROR("%s: addr[%p] size[%x] result[%x] file_offset[%x]\n",
4896 __func__, addr, size, result, file_offset);
4901 static uint slic_init_dump_thread(struct sliccard *card)
4903 card->dump_task_id = kthread_run(slic_dump_thread, (void *)card, 0);
4905 /* DBG_MSG("create slic_dump_thread dump_pid[%x]\n", card->dump_pid); */
4906 if (IS_ERR(card->dump_task_id)) {
4907 DBG_MSG("create slic_dump_thread FAILED \n");
4908 return STATUS_FAILURE;
4911 return STATUS_SUCCESS;
4914 static int slic_dump_thread(void *context)
4916 struct sliccard *card = (struct sliccard *)context;
4917 struct adapter *adapter;
4918 struct adapter *dump_adapter = NULL;
4919 u32 dump_complete = 0;
4920 u32 delay = (PING_TIMER_INTERVAL * HZ);
4921 struct slic_regs *pregs;
4923 struct slic_upr *upr, *uprnext;
4928 card->dumpthread_running = 1;
4933 * This thread doesn't need any user-level access,
4934 * so get rid of all our resources
4936 exit_files(current); /* daemonize doesn't do exit_files */
4937 current->files = init_task.files;
4938 atomic_inc(¤t->files->count);
4941 daemonize("%s", "slicmon");
4943 /* Setup a nice name */
4944 strcpy(current->comm, "slicmon");
4946 ("slic_dump_thread[slicmon] daemon is alive card[%p] pid[%x]\n",
4947 card, card->dump_task_id->pid);
4950 * Send me a signal to get me to die (for debugging)
4954 * If card state is not set to up, skip
4956 if (card->state != CARD_UP) {
4957 if (card->adapters_activated)
4963 * Check the results of our last ping.
4966 #ifdef SLIC_FAILURE_DUMP
4967 if (card->pingstatus != ISR_PINGMASK) {
4969 ("\n[slicmon] CARD #%d TIMED OUT - status "
4970 "%x: DUMP THE CARD!\n",
4971 card->cardnum, card->pingstatus);
4976 * Cause a card RESET instead?
4978 if (card->pingstatus != ISR_PINGMASK) {
4979 /* todo. do we want to reset the card in production */
4980 /* DBG_MSG("\n[slicmon] CARD #%d TIMED OUT - "
4981 status %x: RESET THE CARD!\n", card->cardnum,
4982 card->pingstatus); */
4984 ("\n[slicmon] CARD #%d TIMED OUT - status %x: "
4986 card->cardnum, card->pingstatus);
4991 || (card->dump_requested == SLIC_DUMP_REQUESTED)) {
4992 if (card->dump_requested == SLIC_DUMP_REQUESTED) {
4994 ("[slicmon]: Dump card Requested: Card %x\n",
4997 if (card->pingstatus != ISR_PINGMASK) {
5001 if (card->adapter[0]) {
5002 if ((card->adapter[0])->memorylength >=
5004 sizeof(slic_crash_info)) {
5006 p_slic_crash_info crashinfo;
5009 ((char *)card->adapter[0]->
5015 cpuid = crashinfo->cpu_id;
5016 crashpc = crashinfo->crash_pc;
5020 ("[slicmon]: Dump card: Card %x crashed "
5021 "and failed to answer PING. "
5022 "CPUID[%x] PC[%x]\n ",
5023 card->cardnum, cpuid, crashpc);
5026 card->dump_requested = SLIC_DUMP_IN_PROGRESS;
5029 * Set the card state to DOWN and the adapter states
5030 * to RESET.They will check this in SimbaCheckForHang
5031 * and initiate interface reset (which in turn will
5032 * reinitialize the card).
5034 card->state = CARD_DOWN;
5036 for (i = 0; i < card->card_size; i++) {
5037 adapter = card->adapter[i];
5039 slic_if_stop_queue(adapter);
5041 if (adapter->state == ADAPT_UP) {
5042 adapter->state = ADAPT_RESET;
5043 adapter->linkstate = LINK_DOWN;
5045 ("[slicmon]: SLIC Card[%d] "
5046 "Port[%d] adapter[%p] "
5048 (uint) card->cardnum,
5051 #if SLIC_GET_STATS_TIMER_ENABLED
5052 /* free stats timer */
5053 if (adapter->statstimerset) {
5054 adapter->statstimerset = 0;
5055 del_timer(&adapter->statstimer);
5061 for (i = 0; i < card->card_size; i++) {
5062 adapter = card->adapter[i];
5063 if ((adapter) && (adapter->activated)) {
5064 pregs = adapter->slic_regs;
5065 dump_adapter = adapter;
5068 * If the dump status is zero, then
5069 * the utility processor has crashed.
5070 * If this is the case, any pending
5071 * utilityprocessor requests will not
5072 * complete and our dump commands will
5075 * To avoid this we will clear any
5076 * pending utility processor requests
5079 if (!card->pingstatus) {
5081 &adapter->upr_lock.lock,
5082 adapter->upr_lock.flags);
5083 upr = adapter->upr_list;
5085 uprnext = upr->next;
5089 adapter->upr_list = 0;
5090 adapter->upr_busy = 0;
5091 spin_unlock_irqrestore(
5092 &adapter->upr_lock.lock,
5093 adapter->upr_lock.flags);
5096 slic_dump_card(card, false);
5100 if (dump_complete) {
5101 DBG_ERROR("SLIC Dump Complete\n");
5102 /* Only dump the card one time */
5109 ("slic dump completed. "
5110 "Reenable interfaces\n");
5111 slic_card_init(card, dump_adapter);
5114 * Reenable the adapters that were reset
5116 for (i = 0; i < card->card_size; i++) {
5117 adapter = card->adapter[i];
5119 if (adapter->state ==
5123 "Card[%d] Port[%d] adapter[%p] "
5130 adapter->linkstate =
5138 card->dump_requested = SLIC_DUMP_DONE;
5141 /* if pingstatus != ISR_PINGMASK) || dump_requested...ELSE
5142 * We received a valid ping response.
5143 * Clear the Pingstatus field, find a valid adapter
5144 * structure and send another ping.
5146 for (i = 0; i < card->card_size; i++) {
5147 adapter = card->adapter[i];
5148 if (adapter && (adapter->state == ADAPT_UP)) {
5149 card->pingstatus = 0;
5150 slic_upr_request(adapter, SLIC_UPR_PING,
5152 break; /* Only issue one per card */
5157 SLIC_INTERRUPTIBLE_SLEEP_ON_TIMEOUT(card->dump_wq, delay);
5158 } while (!signal_pending(current));
5161 /* DBG_MSG("[slicmon] slic_dump_thread card[%p] pid[%x] ENDING\n",
5162 card, card->dump_pid); */
5163 card->dumpthread_running = 0;
5169 * Read a single byte from our dump index file. This
5170 * value is used as our suffix for our dump path. The
5171 * value is incremented and written back to the file
5173 static unsigned char slic_get_dump_index(char *path)
5175 unsigned char index = 0;
5176 #ifdef SLIC_DUMP_INDEX_SUPPORT
5184 * Open the index file. If one doesn't exist, create it
5186 status = create_file(&FileHandle);
5188 if (status != STATUS_SUCCESS)
5189 return (unsigned char) 0;
5191 status = read_file(FileHandle, &index, 1, &offset);
5195 status = write_file(FileHandle, &index, 1, &offset);
5197 close_file(FileHandle);
5204 static struct file *slic_dump_open_file(struct sliccard *card)
5206 struct file *SLIChandle = NULL;
5207 struct dentry *dentry = NULL;
5208 struct inode *inode = NULL;
5211 card->dumpfile_fs = get_fs();
5215 memset(SLICfile, 0, sizeof(SLICfile));
5216 sprintf(SLICfile, "/var/tmp/slic%d-dump-%d", card->cardnum,
5217 (uint) card->dump_count);
5221 filp_open(SLICfile, O_CREAT | O_RDWR | O_SYNC | O_LARGEFILE, 0666);
5223 DBG_MSG("[slicmon]: Dump Card #%d to file: %s \n", card->cardnum,
5226 /* DBG_MSG("[slicmon] filp_open %s SLIChandle[%p]\n", SLICfile, SLIChandle);*/
5228 if (IS_ERR(SLIChandle))
5231 dentry = SLIChandle->f_dentry;
5232 inode = dentry->d_inode;
5234 /* DBG_MSG("[slicmon] inode[%p] i_nlink[%x] i_mode[%x] i_op[%p] i_fop[%p]\n"
5235 "f_op->write[%p]\n",
5236 inode, inode->i_nlink, inode->i_mode, inode->i_op,
5237 inode->i_fop, SLIChandle->f_op->write); */
5238 if (inode->i_nlink > 1)
5239 goto close_slicdump; /* multiple links - don't dump */
5241 if (!S_ISREG(inode->i_mode))
5242 goto close_slicdump;
5244 if (!inode->i_op || !inode->i_fop)
5245 goto close_slicdump;
5247 if (!SLIChandle->f_op->write)
5248 goto close_slicdump;
5251 * If we got here we have SUCCESSFULLY OPENED the dump file
5253 /* DBG_MSG("opened %s SLIChandle[%p]\n", SLICfile, SLIChandle); */
5257 DBG_MSG("[slicmon] slic_dump_open_file failed close SLIChandle[%p]\n",
5259 filp_close(SLIChandle, NULL);
5262 set_fs(card->dumpfile_fs);
5267 static void slic_dump_close_file(struct sliccard *card)
5270 /* DBG_MSG("[slicmon] slic_dump_CLOSE_file close SLIChandle[%p]\n",
5271 card->dumphandle); */
5273 filp_close(card->dumphandle, NULL);
5275 set_fs(card->dumpfile_fs);
5278 static u32 slic_dump_card(struct sliccard *card, bool resume)
5280 struct adapter *adapter = card->master;
5284 u32 sram_size, dram_size, regs;
5285 struct sliccore_hdr corehdr;
5292 card->dumphandle = slic_dump_open_file(card);
5294 if (card->dumphandle == NULL) {
5295 DBG_MSG("[slicmon] Cant create Dump file - dump failed\n");
5298 if (!card->dumpbuffer) {
5299 DBG_MSG("[slicmon] Insufficient memory for dump\n");
5302 if (!card->cmdbuffer) {
5303 DBG_MSG("[slicmon] Insufficient cmd memory for dump\n");
5308 * Write the file version to the core header.
5310 namestr = slic_proc_version;
5311 for (i = 0; i < (DRIVER_NAME_SIZE - 1); i++, namestr++) {
5314 corehdr.driver_version[i] = *namestr;
5316 corehdr.driver_version[i] = 0;
5318 file_offset = sizeof(struct sliccore_hdr);
5321 * Issue the following debug commands to the SLIC:
5322 * - Halt both receive and transmit
5323 * - Dump receive registers
5324 * - Dump transmit registers
5329 DBG_MSG("slicDump HALT Receive Processor\n");
5330 card->dumptime_start = jiffies;
5332 status = slic_dump_halt(card, PROC_RECEIVE);
5333 if (status != STATUS_SUCCESS) {
5335 ("Cant halt receive sequencer - dump failed status[%x]\n",
5340 DBG_MSG("slicDump HALT Transmit Processor\n");
5341 status = slic_dump_halt(card, PROC_TRANSMIT);
5342 if (status != STATUS_SUCCESS) {
5343 DBG_ERROR("Cant halt transmit sequencer - dump failed\n");
5347 /* Dump receive regs */
5348 status = slic_dump_reg(card, PROC_RECEIVE);
5349 if (status != STATUS_SUCCESS) {
5350 DBG_ERROR("Cant dump receive registers - dump failed\n");
5354 DBG_MSG("slicDump Write Receive REGS len[%x] offset[%x]\n",
5355 (SLIC_NUM_REG * 4), file_offset);
5358 slic_dump_write(card, card->dumpbuffer, SLIC_NUM_REG * 4,
5362 ("Cant write rcv registers to dump file - dump failed\n");
5366 corehdr.RcvRegOff = file_offset;
5367 corehdr.RcvRegsize = SLIC_NUM_REG * 4;
5368 file_offset += SLIC_NUM_REG * 4;
5370 /* Dump transmit regs */
5371 status = slic_dump_reg(card, PROC_TRANSMIT);
5372 if (status != STATUS_SUCCESS) {
5373 DBG_ERROR("Cant dump transmit registers - dump failed\n");
5377 DBG_MSG("slicDump Write XMIT REGS len[%x] offset[%x]\n",
5378 (SLIC_NUM_REG * 4), file_offset);
5381 slic_dump_write(card, card->dumpbuffer, SLIC_NUM_REG * 4,
5385 ("Cant write xmt registers to dump file - dump failed\n");
5389 corehdr.XmtRegOff = file_offset;
5390 corehdr.XmtRegsize = SLIC_NUM_REG * 4;
5391 file_offset += SLIC_NUM_REG * 4;
5393 regs = SLIC_GBMAX_REG;
5395 corehdr.FileRegOff = file_offset;
5396 corehdr.FileRegsize = regs * 4;
5398 for (offset = 0; regs;) {
5399 len = MIN(regs, 16); /* Can only xfr 16 regs at a time */
5401 status = slic_dump_data(card, offset, (ushort) len, DESC_RFILE);
5403 if (status != STATUS_SUCCESS) {
5404 DBG_ERROR("Cant dump register file - dump failed\n");
5408 DBG_MSG("slicDump Write RegisterFile len[%x] offset[%x]\n",
5409 (len * 4), file_offset);
5412 slic_dump_write(card, card->dumpbuffer, len * 4,
5416 ("Cant write register file to dump file - "
5421 file_offset += len * 4;
5426 dram_size = card->config.DramSize * 0x10000;
5428 switch (adapter->devid) {
5429 case SLIC_2GB_DEVICE_ID:
5430 sram_size = SLIC_SRAM_SIZE2GB;
5432 case SLIC_1GB_DEVICE_ID:
5433 sram_size = SLIC_SRAM_SIZE1GB;
5441 corehdr.SramOff = file_offset;
5442 corehdr.Sramsize = sram_size;
5444 for (offset = 0; sram_size;) {
5445 len = MIN(sram_size, DUMP_BUF_SIZE);
5446 status = slic_dump_data(card, offset, (ushort) len, DESC_SRAM);
5447 if (status != STATUS_SUCCESS) {
5449 ("[slicmon] Cant dump SRAM at offset %x - "
5450 "dump failed\n", (uint) offset);
5454 DBG_MSG("[slicmon] slicDump Write SRAM len[%x] offset[%x]\n",
5458 slic_dump_write(card, card->dumpbuffer, len, file_offset);
5461 ("[slicmon] Cant write SRAM to dump file - "
5471 corehdr.DramOff = file_offset;
5472 corehdr.Dramsize = dram_size;
5474 for (offset = 0; dram_size;) {
5475 len = MIN(dram_size, DUMP_BUF_SIZE);
5477 status = slic_dump_data(card, offset, (ushort) len, DESC_DRAM);
5478 if (status != STATUS_SUCCESS) {
5480 ("[slicmon] Cant dump dram at offset %x - "
5481 "dump failed\n", (uint) offset);
5485 DBG_MSG("slicDump Write DRAM len[%x] offset[%x]\n", len,
5489 slic_dump_write(card, card->dumpbuffer, len, file_offset);
5492 ("[slicmon] Cant write DRAM to dump file - "
5502 max_queues = SLIC_MAX_QUEUE;
5504 for (queue = 0; queue < max_queues; queue++) {
5505 u32 *qarray = (u32 *) card->dumpbuffer;
5506 u32 qarray_physl = card->dumpbuffer_physl;
5507 u32 qarray_physh = card->dumpbuffer_physh;
5512 DBG_MSG("[slicmon] Start Dump of QUEUE #0x%x\n", (uint) queue);
5514 for (offset = 0; offset < (DUMP_BUF_SIZE >> 2); offset++) {
5518 status = slic_dump_queue(card,
5520 qarray_physh, queue);
5523 if (status != STATUS_SUCCESS)
5526 if (jiffies > qstart) {
5527 qdelta = jiffies - qstart;
5533 qdelta = qtotal / offset;
5537 /* DBG_MSG(" slicDump Write QUEUE #0x%x len[%x] offset[%x] "
5538 "avgjiffs[%x]\n", queue, (offset*4), file_offset, qdelta); */
5541 slic_dump_write(card, card->dumpbuffer, offset * 4,
5546 ("[slicmon] Cant write QUEUES to dump file - "
5551 corehdr.queues[queue].queueOff = file_offset;
5552 corehdr.queues[queue].queuesize = offset * 4;
5553 file_offset += offset * 4;
5555 /* DBG_MSG(" Reload QUEUE #0x%x elements[%x]\n", (uint)queue, offset);*/
5557 * Fill the queue back up
5559 for (i = 0; i < offset; i++) {
5563 status = slic_dump_load_queue(card, qarray[i], queue);
5564 if (status != STATUS_SUCCESS)
5567 if (jiffies > qstart) {
5568 qdelta = jiffies - qstart;
5574 qdelta = qtotal / offset;
5578 /* DBG_MSG(" Reload DONE avgjiffs[%x]\n", qdelta); */
5583 len = SLIC_GB_CAMAB_SZE * 4;
5584 status = slic_dump_cam(card, 0, len, DUMP_CAM_A);
5585 if (status != STATUS_SUCCESS) {
5586 DBG_ERROR("[slicmon] Can't dump CAM_A - dump failed\n");
5590 result = slic_dump_write(card, card->dumpbuffer, len, file_offset);
5593 ("[slicmon] Can't write CAM_A data to dump file - "
5597 corehdr.CamAMOff = file_offset;
5598 corehdr.CamASize = len;
5601 len = SLIC_GB_CAMCD_SZE * 4;
5602 status = slic_dump_cam(card, 0, len, DUMP_CAM_C);
5604 DBG_ERROR("[slicmon] Can't dump CAM_C - dump failed\n");
5608 result = slic_dump_write(card, card->dumpbuffer, len, file_offset);
5611 ("[slicmon] Can't write CAM_C data to dump file - "
5615 corehdr.CamCMOff = file_offset;
5616 corehdr.CamCSize = len;
5621 * Write out the core header
5624 DBG_MSG("[slicmon] Write CoreHeader len[%x] offset[%x]\n",
5625 (uint) sizeof(struct sliccore_hdr), file_offset);
5628 slic_dump_write(card, &corehdr, sizeof(struct sliccore_hdr),
5630 DBG_MSG("[slicmon] corehdr xoff[%x] xsz[%x]\n"
5631 " roff[%x] rsz[%x] fileoff[%x] filesz[%x]\n"
5632 " sramoff[%x] sramsz[%x], dramoff[%x] dramsz[%x]\n"
5633 " corehdr_offset[%x]\n", corehdr.XmtRegOff,
5634 corehdr.XmtRegsize, corehdr.RcvRegOff, corehdr.RcvRegsize,
5635 corehdr.FileRegOff, corehdr.FileRegsize, corehdr.SramOff,
5636 corehdr.Sramsize, corehdr.DramOff, corehdr.Dramsize,
5637 (uint) sizeof(struct sliccore_hdr));
5638 for (i = 0; i < max_queues; i++) {
5639 DBG_MSG("[slicmon] QUEUE 0x%x offset[%x] size[%x]\n",
5640 (uint) i, corehdr.queues[i].queueOff,
5641 corehdr.queues[i].queuesize);
5645 slic_dump_close_file(card);
5648 DBG_MSG("slicDump RESTART RECEIVE and XMIT PROCESSORS\n\n");
5649 slic_dump_resume(card, PROC_RECEIVE);
5650 slic_dump_resume(card, PROC_TRANSMIT);
5656 static u32 slic_dump_halt(struct sliccard *card, unsigned char proc)
5658 unsigned char *cmd = card->cmdbuffer;
5660 *cmd = COMMAND_BYTE(CMD_HALT, 0, proc);
5662 return slic_dump_send_cmd(card,
5663 card->cmdbuffer_physl,
5664 card->cmdbuffer_physh, 0, 0);
5667 static u32 slic_dump_resume(struct sliccard *card, unsigned char proc)
5669 unsigned char *cmd = card->cmdbuffer;
5671 *cmd = COMMAND_BYTE(CMD_RUN, 0, proc);
5673 return slic_dump_send_cmd(card,
5674 card->cmdbuffer_physl,
5675 card->cmdbuffer_physh, 0, 0);
5678 static u32 slic_dump_reg(struct sliccard *card, unsigned char proc)
5680 struct dump_cmd *dump = (struct dump_cmd *)card->cmdbuffer;
5682 dump->cmd = COMMAND_BYTE(CMD_DUMP, 0, proc);
5683 dump->desc = DESC_REG;
5687 return slic_dump_send_cmd(card,
5688 card->cmdbuffer_physl,
5689 card->cmdbuffer_physh,
5690 card->dumpbuffer_physl,
5691 card->dumpbuffer_physh);
5694 static u32 slic_dump_data(struct sliccard *card,
5695 u32 addr, ushort count, unsigned char desc)
5697 struct dump_cmd *dump = (struct dump_cmd *)card->cmdbuffer;
5699 dump->cmd = COMMAND_BYTE(CMD_DUMP, 0, PROC_RECEIVE);
5701 dump->count = count;
5704 return slic_dump_send_cmd(card,
5705 card->cmdbuffer_physl,
5706 card->cmdbuffer_physh,
5707 card->dumpbuffer_physl,
5708 card->dumpbuffer_physh);
5711 static u32 slic_dump_queue(struct sliccard *card,
5712 u32 addr, u32 buf_physh, u32 queue)
5714 struct dump_cmd *dump = (struct dump_cmd *)card->cmdbuffer;
5716 dump->cmd = COMMAND_BYTE(CMD_DUMP, 0, PROC_RECEIVE);
5717 dump->desc = DESC_QUEUE;
5721 return slic_dump_send_cmd(card,
5722 card->cmdbuffer_physl,
5723 card->cmdbuffer_physh,
5724 addr, card->dumpbuffer_physh);
5727 static u32 slic_dump_load_queue(struct sliccard *card, u32 data,
5730 struct dump_cmd *load = (struct dump_cmd *) card->cmdbuffer;
5732 load->cmd = COMMAND_BYTE(CMD_LOAD, 0, PROC_RECEIVE);
5733 load->desc = DESC_QUEUE;
5734 load->count = (ushort) queue;
5737 return slic_dump_send_cmd(card,
5738 card->cmdbuffer_physl,
5739 card->cmdbuffer_physh, 0, 0);
5742 static u32 slic_dump_cam(struct sliccard *card,
5743 u32 addr, u32 count, unsigned char desc)
5745 struct dump_cmd *dump = (struct dump_cmd *)card->cmdbuffer;
5747 dump->cmd = COMMAND_BYTE(CMD_CAM_OPS, 0, PROC_NONE);
5749 dump->count = count;
5752 return slic_dump_send_cmd(card,
5753 card->cmdbuffer_physl,
5754 card->cmdbuffer_physh,
5755 addr, card->dumpbuffer_physh);
5758 static u32 slic_dump_send_cmd(struct sliccard *card,
5761 u32 buf_physl, u32 buf_physh)
5763 ulong timeout = msecs_to_jiffies(500); /* 500 msec */
5765 u32 delay = msecs_to_jiffies(10); /* 10 msec */
5766 struct adapter *adapter = card->master;
5771 * Zero the Dumpstatus field of the adapter structure
5773 card->dumpstatus = 0;
5775 * Issue the dump command via a utility processor request.
5777 * Kludge: We use the Informationbuffer parameter to hold
5778 * the buffer address
5780 slic_upr_request(adapter, SLIC_UPR_DUMP, cmd_physl, cmd_physh,
5781 buf_physl, buf_physh);
5785 * Spin until completion or timeout.
5787 while (!card->dumpstatus) {
5790 if (jiffies > timeout) {
5792 * Complete the timed-out DUMP UPR request.
5794 slic_upr_request_complete(adapter, 0);
5796 ("%s: TIMED OUT num_sleeps[%x] "
5798 __func__, num_sleeps, STATUS_FAILURE);
5800 return STATUS_FAILURE;
5803 SLIC_INTERRUPTIBLE_SLEEP_ON_TIMEOUT(card->dump_wq,
5807 if (card->dumpstatus & ISR_UPCERR) {
5809 * Error (or queue empty)
5811 /* DBG_ERROR("[slicmon] %s: DUMP_STATUS & ISR_UPCERR status[%x]\n",
5812 __func__, STATUS_FAILURE); */
5814 return STATUS_FAILURE;
5815 } else if (card->dumpstatus & ISR_UPCBSY) {
5819 DBG_ERROR("%s: ISR_UPCBUSY attempt[%x]\n", __func__,
5827 return STATUS_SUCCESS;
5832 DBG_ERROR("%s: GAVE UP AFTER SEVERAL ATTEMPTS status[%x]\n",
5833 __func__, STATUS_FAILURE);
5836 * Gave up after several attempts
5838 return STATUS_FAILURE;
5842 /*=============================================================================
5843 =============================================================================
5845 === *** END **** END **** END **** END *** ===
5846 === SLIC DUMP MANAGEMENT SECTION ===
5850 =============================================================================
5851 ============================================================================*/
5853 /******************************************************************************/
5854 /**************** MODULE INITIATION / TERMINATION FUNCTIONS ***************/
5855 /******************************************************************************/
5857 static struct pci_driver slic_driver = {
5859 .id_table = slic_pci_tbl,
5860 .probe = slic_entry_probe,
5861 .remove = slic_entry_remove,
5862 #if SLIC_POWER_MANAGEMENT_ENABLED
5863 .suspend = slicpm_suspend,
5864 .resume = slicpm_resume,
5866 /* .shutdown = slic_shutdown, MOOK_INVESTIGATE */
5869 static int __init slic_module_init(void)
5871 struct pci_device_id *pcidev;
5874 /* DBG_MSG("slicoss: %s ENTER cpu %d\n", __func__, smp_processor_id()); */
5878 if (debug >= 0 && slic_debug != debug)
5879 printk(SLICLEVEL "slicoss: debug level is %d.\n", debug);
5883 pcidev = (struct pci_device_id *)slic_driver.id_table;
5884 /* DBG_MSG("slicoss: %s call pci_module_init jiffies[%lx] cpu #%d\n",
5885 __func__, jiffies, smp_processor_id()); */
5887 ret = pci_register_driver(&slic_driver);
5889 /* DBG_MSG("slicoss: %s EXIT after call pci_module_init jiffies[%lx] "
5890 "cpu #%d status[%x]\n",__func__, jiffies,
5891 smp_processor_id(), ret); */
5896 static void __exit slic_module_cleanup(void)
5898 /* DBG_MSG("slicoss: %s ENTER\n", __func__); */
5899 pci_unregister_driver(&slic_driver);
5900 slic_debug_cleanup();
5901 /* DBG_MSG("slicoss: %s EXIT\n", __func__); */
5904 module_init(slic_module_init);
5905 module_exit(slic_module_cleanup);