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_ATOMIC);
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 =
1717 jiffies + SLIC_SECS_TO_JIFFS(PING_TIMER_INTERVAL);
1718 add_timer(&adapter->pingtimer);
1721 static void slic_if_stop_queue(struct adapter *adapter)
1723 netif_stop_queue(adapter->netdev);
1726 static void slic_if_start_queue(struct adapter *adapter)
1728 netif_start_queue(adapter->netdev);
1734 * Perform initialization of our slic interface.
1737 static int slic_if_init(struct adapter *adapter)
1739 struct sliccard *card = adapter->card;
1740 struct net_device *dev = adapter->netdev;
1741 __iomem struct slic_regs *slic_regs = adapter->slic_regs;
1742 struct slic_shmem *pshmem;
1746 DBG_MSG("slicoss: %s (%s) ENTER states[%d:%d:%d:%d] flags[%x]\n",
1747 __func__, adapter->netdev->name,
1748 adapter->queues_initialized, adapter->state, adapter->linkstate,
1749 card->state, dev->flags);
1751 /* adapter should be down at this point */
1752 if (adapter->state != ADAPT_DOWN) {
1753 DBG_ERROR("slic_if_init adapter->state != ADAPT_DOWN\n");
1756 ASSERT(adapter->linkstate == LINK_DOWN);
1758 adapter->devflags_prev = dev->flags;
1759 adapter->macopts = MAC_DIRECTED;
1761 DBG_MSG("slicoss: %s (%s) Set MAC options: ", __func__,
1762 adapter->netdev->name);
1763 if (dev->flags & IFF_BROADCAST) {
1764 adapter->macopts |= MAC_BCAST;
1767 if (dev->flags & IFF_PROMISC) {
1768 adapter->macopts |= MAC_PROMISC;
1769 DBG_MSG("PROMISC ");
1771 if (dev->flags & IFF_ALLMULTI) {
1772 adapter->macopts |= MAC_ALLMCAST;
1773 DBG_MSG("ALL_MCAST ");
1775 if (dev->flags & IFF_MULTICAST) {
1776 adapter->macopts |= MAC_MCAST;
1781 status = slic_adapter_allocresources(adapter);
1782 if (status != STATUS_SUCCESS) {
1784 ("slic_if_init: slic_adapter_allocresources FAILED %x\n",
1786 slic_adapter_freeresources(adapter);
1790 if (!adapter->queues_initialized) {
1791 DBG_MSG("slicoss: %s call slic_rspqueue_init\n", __func__);
1792 if (slic_rspqueue_init(adapter))
1795 ("slicoss: %s call slic_cmdq_init adapter[%p] port %d \n",
1796 __func__, adapter, adapter->port);
1797 if (slic_cmdq_init(adapter))
1800 ("slicoss: %s call slic_rcvqueue_init adapter[%p] \
1801 port %d \n", __func__, adapter, adapter->port);
1802 if (slic_rcvqueue_init(adapter))
1804 adapter->queues_initialized = 1;
1806 DBG_MSG("slicoss: %s disable interrupts(slic)\n", __func__);
1808 WRITE_REG(slic_regs->slic_icr, ICR_INT_OFF, FLUSH);
1811 if (!adapter->isp_initialized) {
1812 pshmem = (struct slic_shmem *)adapter->phys_shmem;
1814 spin_lock_irqsave(&adapter->bit64reglock.lock,
1815 adapter->bit64reglock.flags);
1817 #if defined(CONFIG_X86_64)
1818 WRITE_REG(slic_regs->slic_addr_upper,
1819 SLIC_GET_ADDR_HIGH(&pshmem->isr), DONT_FLUSH);
1820 WRITE_REG(slic_regs->slic_isp,
1821 SLIC_GET_ADDR_LOW(&pshmem->isr), FLUSH);
1822 #elif defined(CONFIG_X86)
1823 WRITE_REG(slic_regs->slic_addr_upper, (u32) 0, DONT_FLUSH);
1824 WRITE_REG(slic_regs->slic_isp, (u32) &pshmem->isr, FLUSH);
1828 spin_unlock_irqrestore(&adapter->bit64reglock.lock,
1829 adapter->bit64reglock.flags);
1830 adapter->isp_initialized = 1;
1833 adapter->state = ADAPT_UP;
1834 if (!card->loadtimerset) {
1835 init_timer(&card->loadtimer);
1836 card->loadtimer.expires =
1837 jiffies + SLIC_SECS_TO_JIFFS(SLIC_LOADTIMER_PERIOD);
1838 card->loadtimer.data = (ulong) card;
1839 card->loadtimer.function = &slic_timer_load_check;
1840 add_timer(&card->loadtimer);
1842 card->loadtimerset = 1;
1844 #if SLIC_GET_STATS_TIMER_ENABLED
1845 if (!adapter->statstimerset) {
1846 DBG_MSG("slicoss: %s start getstats_timer(slic)\n",
1848 init_timer(&adapter->statstimer);
1849 adapter->statstimer.expires =
1850 jiffies + SLIC_SECS_TO_JIFFS(STATS_TIMER_INTERVAL);
1851 adapter->statstimer.data = (ulong) adapter->netdev;
1852 adapter->statstimer.function = &slic_timer_get_stats;
1853 add_timer(&adapter->statstimer);
1854 adapter->statstimerset = 1;
1857 #if !SLIC_DUMP_ENABLED && SLIC_PING_TIMER_ENABLED
1858 /*#if SLIC_DUMP_ENABLED && SLIC_PING_TIMER_ENABLED*/
1859 if (!adapter->pingtimerset) {
1860 DBG_MSG("slicoss: %s start card_ping_timer(slic)\n",
1862 init_timer(&adapter->pingtimer);
1863 adapter->pingtimer.expires =
1864 jiffies + SLIC_SECS_TO_JIFFS(PING_TIMER_INTERVAL);
1865 adapter->pingtimer.data = (ulong) dev;
1866 adapter->pingtimer.function = &slic_timer_ping;
1867 add_timer(&adapter->pingtimer);
1868 adapter->pingtimerset = 1;
1869 adapter->card->pingstatus = ISR_PINGMASK;
1874 * clear any pending events, then enable interrupts
1876 DBG_MSG("slicoss: %s ENABLE interrupts(slic)\n", __func__);
1877 adapter->isrcopy = 0;
1878 adapter->pshmem->isr = 0;
1879 WRITE_REG(slic_regs->slic_isr, 0, FLUSH);
1880 WRITE_REG(slic_regs->slic_icr, ICR_INT_ON, FLUSH);
1882 DBG_MSG("slicoss: %s call slic_link_config(slic)\n", __func__);
1883 slic_link_config(adapter, LINK_AUTOSPEED, LINK_AUTOD);
1884 slic_link_event_handler(adapter);
1886 DBG_MSG("slicoss: %s EXIT\n", __func__);
1887 return STATUS_SUCCESS;
1890 static void slic_unmap_mmio_space(struct adapter *adapter)
1892 #if LINUX_FREES_ADAPTER_RESOURCES
1893 if (adapter->slic_regs)
1894 iounmap(adapter->slic_regs);
1895 adapter->slic_regs = NULL;
1899 static int slic_adapter_allocresources(struct adapter *adapter)
1901 if (!adapter->intrregistered) {
1905 ("slicoss: %s AllocAdaptRsrcs adapter[%p] shmem[%p] \
1906 phys_shmem[%p] dev->irq[%x] %x\n",
1907 __func__, adapter, adapter->pshmem,
1908 (void *)adapter->phys_shmem, adapter->netdev->irq,
1911 spin_unlock_irqrestore(&slic_global.driver_lock.lock,
1912 slic_global.driver_lock.flags);
1914 retval = request_irq(adapter->netdev->irq,
1917 adapter->netdev->name, adapter->netdev);
1919 spin_lock_irqsave(&slic_global.driver_lock.lock,
1920 slic_global.driver_lock.flags);
1923 DBG_ERROR("slicoss: request_irq (%s) FAILED [%x]\n",
1924 adapter->netdev->name, retval);
1927 adapter->intrregistered = 1;
1929 ("slicoss: %s AllocAdaptRsrcs adapter[%p] shmem[%p] \
1930 pshmem[%p] dev->irq[%x]\n",
1931 __func__, adapter, adapter->pshmem,
1932 (void *)adapter->pshmem, adapter->netdev->irq);
1934 return STATUS_SUCCESS;
1937 static void slic_config_pci(struct pci_dev *pcidev)
1942 pci_read_config_word(pcidev, PCI_COMMAND, &pci_command);
1943 DBG_MSG("slicoss: %s PCI command[%4.4x]\n", __func__, pci_command);
1945 new_command = pci_command | PCI_COMMAND_MASTER
1946 | PCI_COMMAND_MEMORY
1947 | PCI_COMMAND_INVALIDATE
1948 | PCI_COMMAND_PARITY | PCI_COMMAND_SERR | PCI_COMMAND_FAST_BACK;
1949 if (pci_command != new_command) {
1950 DBG_MSG("%s -- Updating PCI COMMAND register %4.4x->%4.4x.\n",
1951 __func__, pci_command, new_command);
1952 pci_write_config_word(pcidev, PCI_COMMAND, new_command);
1956 static void slic_adapter_freeresources(struct adapter *adapter)
1958 DBG_MSG("slicoss: %s ENTER adapter[%p]\n", __func__, adapter);
1959 slic_init_cleanup(adapter);
1960 memset(&adapter->stats, 0, sizeof(struct net_device_stats));
1961 adapter->error_interrupts = 0;
1962 adapter->rcv_interrupts = 0;
1963 adapter->xmit_interrupts = 0;
1964 adapter->linkevent_interrupts = 0;
1965 adapter->upr_interrupts = 0;
1966 adapter->num_isrs = 0;
1967 adapter->xmit_completes = 0;
1968 adapter->rcv_broadcasts = 0;
1969 adapter->rcv_multicasts = 0;
1970 adapter->rcv_unicasts = 0;
1971 DBG_MSG("slicoss: %s EXIT\n", __func__);
1977 * Write phy control to configure link duplex/speed
1980 static void slic_link_config(struct adapter *adapter,
1981 u32 linkspeed, u32 linkduplex)
1989 if (adapter->state != ADAPT_UP) {
1991 ("%s (%s) ADAPT Not up yet, Return! speed[%x] duplex[%x]\n",
1992 __func__, adapter->netdev->name, linkspeed,
1996 DBG_MSG("slicoss: %s (%s) slic_link_config: speed[%x] duplex[%x]\n",
1997 __func__, adapter->netdev->name, linkspeed, linkduplex);
1999 ASSERT((adapter->devid == SLIC_1GB_DEVICE_ID)
2000 || (adapter->devid == SLIC_2GB_DEVICE_ID));
2002 if (linkspeed > LINK_1000MB)
2003 linkspeed = LINK_AUTOSPEED;
2004 if (linkduplex > LINK_AUTOD)
2005 linkduplex = LINK_AUTOD;
2007 if ((linkspeed == LINK_AUTOSPEED) || (linkspeed == LINK_1000MB)) {
2008 if (adapter->flags & ADAPT_FLAGS_FIBERMEDIA) {
2009 /* We've got a fiber gigabit interface, and register
2010 * 4 is different in fiber mode than in copper mode
2013 /* advertise FD only @1000 Mb */
2014 phy_advreg = (MIICR_REG_4 | (PAR_ADV1000XFD));
2015 /* enable PAUSE frames */
2016 phy_advreg |= PAR_ASYMPAUSE_FIBER;
2017 WRITE_REG(adapter->slic_regs->slic_wphy, phy_advreg,
2020 if (linkspeed == LINK_AUTOSPEED) {
2021 /* reset phy, enable auto-neg */
2024 (PCR_RESET | PCR_AUTONEG |
2026 WRITE_REG(adapter->slic_regs->slic_wphy,
2028 } else { /* forced 1000 Mb FD*/
2029 /* power down phy to break link
2030 this may not work) */
2031 phy_config = (MIICR_REG_PCR | PCR_POWERDOWN);
2032 WRITE_REG(adapter->slic_regs->slic_wphy,
2034 /* wait, Marvell says 1 sec,
2035 try to get away with 10 ms */
2038 /* disable auto-neg, set speed/duplex,
2039 soft reset phy, powerup */
2042 (PCR_RESET | PCR_SPEED_1000 |
2044 WRITE_REG(adapter->slic_regs->slic_wphy,
2047 } else { /* copper gigabit */
2049 /* Auto-Negotiate or 1000 Mb must be auto negotiated
2050 * We've got a copper gigabit interface, and
2051 * register 4 is different in copper mode than
2054 if (linkspeed == LINK_AUTOSPEED) {
2055 /* advertise 10/100 Mb modes */
2058 (PAR_ADV100FD | PAR_ADV100HD | PAR_ADV10FD
2061 /* linkspeed == LINK_1000MB -
2062 don't advertise 10/100 Mb modes */
2063 phy_advreg = MIICR_REG_4;
2065 /* enable PAUSE frames */
2066 phy_advreg |= PAR_ASYMPAUSE;
2067 /* required by the Cicada PHY */
2068 phy_advreg |= PAR_802_3;
2069 WRITE_REG(adapter->slic_regs->slic_wphy, phy_advreg,
2071 /* advertise FD only @1000 Mb */
2072 phy_gctlreg = (MIICR_REG_9 | (PGC_ADV1000FD));
2073 WRITE_REG(adapter->slic_regs->slic_wphy, phy_gctlreg,
2076 if (adapter->subsysid != SLIC_1GB_CICADA_SUBSYS_ID) {
2078 enable auto crossover */
2080 (MIICR_REG_16 | (MRV_REG16_XOVERON));
2081 WRITE_REG(adapter->slic_regs->slic_wphy,
2084 /* reset phy, enable auto-neg */
2087 (PCR_RESET | PCR_AUTONEG |
2089 WRITE_REG(adapter->slic_regs->slic_wphy,
2091 } else { /* it's a Cicada PHY */
2092 /* enable and restart auto-neg (don't reset) */
2095 (PCR_AUTONEG | PCR_AUTONEG_RST));
2096 WRITE_REG(adapter->slic_regs->slic_wphy,
2102 if (linkspeed == LINK_10MB)
2105 speed = PCR_SPEED_100;
2106 if (linkduplex == LINK_HALFD)
2109 duplex = PCR_DUPLEX_FULL;
2111 if (adapter->subsysid != SLIC_1GB_CICADA_SUBSYS_ID) {
2113 disable auto crossover */
2114 phy_config = (MIICR_REG_16 | (MRV_REG16_XOVEROFF));
2115 WRITE_REG(adapter->slic_regs->slic_wphy, phy_config,
2119 /* power down phy to break link (this may not work) */
2120 phy_config = (MIICR_REG_PCR | (PCR_POWERDOWN | speed | duplex));
2121 WRITE_REG(adapter->slic_regs->slic_wphy, phy_config, FLUSH);
2123 /* wait, Marvell says 1 sec, try to get away with 10 ms */
2126 if (adapter->subsysid != SLIC_1GB_CICADA_SUBSYS_ID) {
2128 disable auto-neg, set speed,
2129 soft reset phy, powerup */
2131 (MIICR_REG_PCR | (PCR_RESET | speed | duplex));
2132 WRITE_REG(adapter->slic_regs->slic_wphy, phy_config,
2134 } else { /* it's a Cicada PHY */
2135 /* disable auto-neg, set speed, powerup */
2136 phy_config = (MIICR_REG_PCR | (speed | duplex));
2137 WRITE_REG(adapter->slic_regs->slic_wphy, phy_config,
2143 ("slicoss: %s (%s) EXIT slic_link_config : state[%d] \
2144 phy_config[%x]\n", __func__, adapter->netdev->name, adapter->state,
2148 static void slic_card_cleanup(struct sliccard *card)
2150 DBG_MSG("slicoss: %s ENTER\n", __func__);
2152 #if SLIC_DUMP_ENABLED
2153 if (card->dumpbuffer) {
2154 card->dumpbuffer_phys = 0;
2155 card->dumpbuffer_physl = 0;
2156 card->dumpbuffer_physh = 0;
2157 kfree(card->dumpbuffer);
2158 card->dumpbuffer = NULL;
2160 if (card->cmdbuffer) {
2161 card->cmdbuffer_phys = 0;
2162 card->cmdbuffer_physl = 0;
2163 card->cmdbuffer_physh = 0;
2164 kfree(card->cmdbuffer);
2165 card->cmdbuffer = NULL;
2169 if (card->loadtimerset) {
2170 card->loadtimerset = 0;
2171 del_timer(&card->loadtimer);
2174 slic_debug_card_destroy(card);
2177 DBG_MSG("slicoss: %s EXIT\n", __func__);
2180 static int slic_card_download_gbrcv(struct adapter *adapter)
2182 const struct firmware *fw;
2183 const char *file = "";
2185 __iomem struct slic_regs *slic_regs = adapter->slic_regs;
2189 u32 rcvucodelen = 0;
2191 switch (adapter->devid) {
2192 case SLIC_2GB_DEVICE_ID:
2193 file = "slicoss/oasisrcvucode.sys";
2195 case SLIC_1GB_DEVICE_ID:
2196 file = "slicoss/gbrcvucode.sys";
2203 ret = request_firmware(&fw, file, &adapter->pcidev->dev);
2205 printk(KERN_ERR "SLICOSS: Failed to load firmware %s\n", file);
2209 rcvucodelen = *(u32 *)(fw->data + index);
2211 switch (adapter->devid) {
2212 case SLIC_2GB_DEVICE_ID:
2213 if (rcvucodelen != OasisRcvUCodeLen)
2216 case SLIC_1GB_DEVICE_ID:
2217 if (rcvucodelen != GBRcvUCodeLen)
2224 /* start download */
2225 WRITE_REG(slic_regs->slic_rcv_wcs, SLIC_RCVWCS_BEGIN, FLUSH);
2226 /* download the rcv sequencer ucode */
2227 for (codeaddr = 0; codeaddr < rcvucodelen; codeaddr++) {
2228 /* write out instruction address */
2229 WRITE_REG(slic_regs->slic_rcv_wcs, codeaddr, FLUSH);
2231 instruction = *(u32 *)(fw->data + index);
2233 /* write out the instruction data low addr */
2234 WRITE_REG(slic_regs->slic_rcv_wcs,
2235 instruction, FLUSH);
2237 instruction = *(u8 *)(fw->data + index);
2239 /* write out the instruction data high addr */
2240 WRITE_REG(slic_regs->slic_rcv_wcs, (u8)instruction,
2244 /* download finished */
2245 release_firmware(fw);
2246 WRITE_REG(slic_regs->slic_rcv_wcs, SLIC_RCVWCS_FINISH, FLUSH);
2250 static int slic_card_download(struct adapter *adapter)
2252 const struct firmware *fw;
2253 const char *file = "";
2256 int thissectionsize;
2258 __iomem struct slic_regs *slic_regs = adapter->slic_regs;
2266 int ucode_start, index = 0;
2268 /* DBG_MSG ("slicoss: %s (%s) adapter[%p] card[%p] devid[%x] \
2269 jiffies[%lx] cpu %d\n", __func__, adapter->netdev->name, adapter,
2270 adapter->card, adapter->devid,jiffies, smp_processor_id()); */
2272 switch (adapter->devid) {
2273 case SLIC_2GB_DEVICE_ID:
2274 file = "slicoss/oasisdownload.sys";
2276 case SLIC_1GB_DEVICE_ID:
2277 file = "slicoss/gbdownload.sys";
2283 ret = request_firmware(&fw, file, &adapter->pcidev->dev);
2285 printk(KERN_ERR "SLICOSS: Failed to load firmware %s\n", file);
2288 numsects = *(u32 *)(fw->data + index);
2290 ASSERT(numsects <= 3);
2291 for (i = 0; i < numsects; i++) {
2292 sectsize[i] = *(u32 *)(fw->data + index);
2295 for (i = 0; i < numsects; i++) {
2296 sectstart[i] = *(u32 *)(fw->data + index);
2299 ucode_start = index;
2300 instruction = *(u32 *)(fw->data + index);
2302 for (section = 0; section < numsects; section++) {
2303 baseaddress = sectstart[section];
2304 thissectionsize = sectsize[section] >> 3;
2306 for (codeaddr = 0; codeaddr < thissectionsize; codeaddr++) {
2307 /* Write out instruction address */
2308 WRITE_REG(slic_regs->slic_wcs, baseaddress + codeaddr,
2310 /* Write out instruction to low addr */
2311 WRITE_REG(slic_regs->slic_wcs, instruction, FLUSH);
2312 instruction = *(u32 *)(fw->data + index);
2315 /* Write out instruction to high addr */
2316 WRITE_REG(slic_regs->slic_wcs, instruction, FLUSH);
2317 instruction = *(u32 *)(fw->data + index);
2321 index = ucode_start;
2322 for (section = 0; section < numsects; section++) {
2323 instruction = *(u32 *)(fw->data + index);
2324 baseaddress = sectstart[section];
2325 if (baseaddress < 0x8000)
2327 thissectionsize = sectsize[section] >> 3;
2329 /* DBG_MSG ("slicoss: COMPARE secton[%x] baseaddr[%x] sectnsize[%x]\n",
2330 (uint)section,baseaddress,thissectionsize);*/
2331 for (codeaddr = 0; codeaddr < thissectionsize; codeaddr++) {
2332 /* Write out instruction address */
2333 WRITE_REG(slic_regs->slic_wcs,
2334 SLIC_WCS_COMPARE | (baseaddress + codeaddr),
2336 /* Write out instruction to low addr */
2337 WRITE_REG(slic_regs->slic_wcs, instruction, FLUSH);
2338 instruction = *(u32 *)(fw->data + index);
2340 /* Write out instruction to high addr */
2341 WRITE_REG(slic_regs->slic_wcs, instruction, FLUSH);
2342 instruction = *(u32 *)(fw->data + index);
2345 /* Check SRAM location zero. If it is non-zero. Abort.*/
2346 /* failure = readl((u32 __iomem *)&slic_regs->slic_reset);
2349 ("slicoss: %s FAILURE EXIT codeaddr[%x] "
2350 "thissectionsize[%x] failure[%x]\n",
2351 __func__, codeaddr, thissectionsize,
2353 release_firmware(fw);
2358 /* DBG_MSG ("slicoss: Compare done\n");*/
2359 release_firmware(fw);
2360 /* Everything OK, kick off the card */
2362 WRITE_REG(slic_regs->slic_wcs, SLIC_WCS_START, FLUSH);
2364 /* stall for 20 ms, long enough for ucode to init card
2365 and reach mainloop */
2368 DBG_MSG("slicoss: %s (%s) EXIT adapter[%p] card[%p]\n",
2369 __func__, adapter->netdev->name, adapter, adapter->card);
2371 return STATUS_SUCCESS;
2374 static void slic_adapter_set_hwaddr(struct adapter *adapter)
2376 struct sliccard *card = adapter->card;
2378 /* DBG_MSG ("%s ENTER card->config_set[%x] port[%d] physport[%d] funct#[%d]\n",
2379 __func__, card->config_set, adapter->port, adapter->physport,
2380 adapter->functionnumber);
2382 slic_dbg_macaddrs(adapter); */
2384 if ((adapter->card) && (card->config_set)) {
2385 memcpy(adapter->macaddr,
2386 card->config.MacInfo[adapter->functionnumber].macaddrA,
2387 sizeof(struct slic_config_mac));
2388 /* DBG_MSG ("%s AFTER copying from config.macinfo into currmacaddr\n",
2390 slic_dbg_macaddrs(adapter);*/
2391 if (!(adapter->currmacaddr[0] || adapter->currmacaddr[1] ||
2392 adapter->currmacaddr[2] || adapter->currmacaddr[3] ||
2393 adapter->currmacaddr[4] || adapter->currmacaddr[5])) {
2394 memcpy(adapter->currmacaddr, adapter->macaddr, 6);
2396 if (adapter->netdev) {
2397 memcpy(adapter->netdev->dev_addr, adapter->currmacaddr,
2401 /* DBG_MSG ("%s EXIT port %d\n", __func__, adapter->port);
2402 slic_dbg_macaddrs(adapter); */
2405 static void slic_intagg_set(struct adapter *adapter, u32 value)
2407 __iomem struct slic_regs *slic_regs = adapter->slic_regs;
2409 WRITE_REG(slic_regs->slic_intagg, value, FLUSH);
2410 adapter->card->loadlevel_current = value;
2413 static int slic_card_init(struct sliccard *card, struct adapter *adapter)
2415 __iomem struct slic_regs *slic_regs = adapter->slic_regs;
2416 struct slic_eeprom *peeprom;
2417 struct oslic_eeprom *pOeeprom;
2418 dma_addr_t phys_config;
2422 struct slic_shmem *pshmem;
2424 uint macaddrs = card->card_size;
2429 struct slic_config_mac *pmac;
2430 unsigned char fruformat;
2431 unsigned char oemfruformat;
2432 struct atk_fru *patkfru;
2433 union oemfru *poemfru;
2436 ("slicoss: %s ENTER card[%p] adapter[%p] card->state[%x] \
2437 size[%d]\n", __func__, card, adapter, card->state, card->card_size);
2439 /* Reset everything except PCI configuration space */
2440 slic_soft_reset(adapter);
2442 /* Download the microcode */
2443 status = slic_card_download(adapter);
2445 if (status != STATUS_SUCCESS) {
2446 DBG_ERROR("SLIC download failed bus %d slot %d\n",
2447 (uint) adapter->busnumber,
2448 (uint) adapter->slotnumber);
2452 if (!card->config_set) {
2453 peeprom = pci_alloc_consistent(adapter->pcidev,
2454 sizeof(struct slic_eeprom),
2457 phys_configl = SLIC_GET_ADDR_LOW(phys_config);
2458 phys_configh = SLIC_GET_ADDR_HIGH(phys_config);
2460 DBG_MSG("slicoss: %s Eeprom info adapter [%p]\n "
2461 "size [%x]\n peeprom [%p]\n "
2462 "phys_config [%p]\n phys_configl[%x]\n "
2463 "phys_configh[%x]\n",
2465 (u32)sizeof(struct slic_eeprom),
2466 peeprom, (void *) phys_config, phys_configl,
2470 ("SLIC eeprom read failed to get memory bus %d \
2472 (uint) adapter->busnumber,
2473 (uint) adapter->slotnumber);
2476 memset(peeprom, 0, sizeof(struct slic_eeprom));
2478 WRITE_REG(slic_regs->slic_icr, ICR_INT_OFF, FLUSH);
2480 pshmem = (struct slic_shmem *)adapter->phys_shmem;
2482 spin_lock_irqsave(&adapter->bit64reglock.lock,
2483 adapter->bit64reglock.flags);
2484 WRITE_REG(slic_regs->slic_addr_upper, 0, DONT_FLUSH);
2485 WRITE_REG(slic_regs->slic_isp,
2486 SLIC_GET_ADDR_LOW(&pshmem->isr), FLUSH);
2487 spin_unlock_irqrestore(&adapter->bit64reglock.lock,
2488 adapter->bit64reglock.flags);
2490 slic_config_get(adapter, phys_configl, phys_configh);
2493 if (adapter->pshmem->isr) {
2494 DBG_MSG("%s shmem[%p] shmem->isr[%x]\n",
2495 __func__, adapter->pshmem,
2496 adapter->pshmem->isr);
2498 if (adapter->pshmem->isr & ISR_UPC) {
2499 adapter->pshmem->isr = 0;
2500 WRITE_REG64(adapter,
2501 slic_regs->slic_isp,
2503 slic_regs->slic_addr_upper,
2505 WRITE_REG(slic_regs->slic_isr, 0,
2508 slic_upr_request_complete(adapter, 0);
2511 adapter->pshmem->isr = 0;
2512 WRITE_REG(slic_regs->slic_isr, 0,
2520 ("SLIC: %d config data fetch timed "
2521 "out!\n", adapter->port);
2522 DBG_MSG("%s shmem[%p] shmem->isr[%x]\n",
2523 __func__, adapter->pshmem,
2524 adapter->pshmem->isr);
2525 WRITE_REG64(adapter,
2526 slic_regs->slic_isp, 0,
2527 slic_regs->slic_addr_upper,
2534 switch (adapter->devid) {
2536 case SLIC_2GB_DEVICE_ID:
2537 /* extract EEPROM data and pointers to EEPROM data */
2538 pOeeprom = (struct oslic_eeprom *) peeprom;
2539 eecodesize = pOeeprom->EecodeSize;
2540 dramsize = pOeeprom->DramSize;
2541 pmac = pOeeprom->MacInfo;
2542 fruformat = pOeeprom->FruFormat;
2543 patkfru = &pOeeprom->AtkFru;
2544 oemfruformat = pOeeprom->OemFruFormat;
2545 poemfru = &pOeeprom->OemFru;
2547 /* Minor kludge for Oasis card
2548 get 2 MAC addresses from the
2549 EEPROM to ensure that function 1
2550 gets the Port 1 MAC address */
2553 /* extract EEPROM data and pointers to EEPROM data */
2554 eecodesize = peeprom->EecodeSize;
2555 dramsize = peeprom->DramSize;
2556 pmac = peeprom->u2.mac.MacInfo;
2557 fruformat = peeprom->FruFormat;
2558 patkfru = &peeprom->AtkFru;
2559 oemfruformat = peeprom->OemFruFormat;
2560 poemfru = &peeprom->OemFru;
2564 card->config.EepromValid = FALSE;
2566 /* see if the EEPROM is valid by checking it's checksum */
2567 if ((eecodesize <= MAX_EECODE_SIZE) &&
2568 (eecodesize >= MIN_EECODE_SIZE)) {
2571 *(u16 *) ((char *) peeprom + (eecodesize - 2));
2573 calculate the EEPROM checksum
2576 ~slic_eeprom_cksum((char *) peeprom,
2579 if the ucdoe chksum flag bit worked,
2580 we wouldn't need this shit
2582 if (ee_chksum == calc_chksum)
2583 card->config.EepromValid = TRUE;
2585 /* copy in the DRAM size */
2586 card->config.DramSize = dramsize;
2588 /* copy in the MAC address(es) */
2589 for (i = 0; i < macaddrs; i++) {
2590 memcpy(&card->config.MacInfo[i],
2591 &pmac[i], sizeof(struct slic_config_mac));
2593 /* DBG_MSG ("%s EEPROM Checksum Good? %d MacAddress\n",__func__,
2594 card->config.EepromValid); */
2596 /* copy the Alacritech FRU information */
2597 card->config.FruFormat = fruformat;
2598 memcpy(&card->config.AtkFru, patkfru,
2599 sizeof(struct atk_fru));
2601 pci_free_consistent(adapter->pcidev,
2602 sizeof(struct slic_eeprom),
2603 peeprom, phys_config);
2605 ("slicoss: %s adapter%d [%p] size[%x] FREE peeprom[%p] \
2607 __func__, adapter->port, adapter,
2608 (u32) sizeof(struct slic_eeprom), peeprom,
2609 (void *) phys_config);
2611 if ((!card->config.EepromValid) &&
2612 (adapter->reg_params.fail_on_bad_eeprom)) {
2613 WRITE_REG64(adapter,
2614 slic_regs->slic_isp,
2615 0, slic_regs->slic_addr_upper, 0, FLUSH);
2617 ("unsupported CONFIGURATION EEPROM invalid\n");
2621 card->config_set = 1;
2624 if (slic_card_download_gbrcv(adapter)) {
2625 DBG_ERROR("%s unable to download GB receive microcode\n",
2630 if (slic_global.dynamic_intagg) {
2632 ("Dynamic Interrupt Aggregation[ENABLED]: slic%d \
2633 SET intagg to %d\n",
2635 slic_intagg_set(adapter, 0);
2637 slic_intagg_set(adapter, intagg_delay);
2639 ("Dynamic Interrupt Aggregation[DISABLED]: slic%d \
2640 SET intagg to %d\n",
2641 card->cardnum, intagg_delay);
2645 * Initialize ping status to "ok"
2647 card->pingstatus = ISR_PINGMASK;
2649 #if SLIC_DUMP_ENABLED
2650 if (!card->dumpbuffer) {
2651 card->dumpbuffer = kmalloc(DUMP_PAGE_SIZE, GFP_ATOMIC);
2653 ASSERT(card->dumpbuffer);
2654 if (card->dumpbuffer == NULL)
2658 * Smear the shared memory structure and then obtain
2659 * the PHYSICAL address of this structure
2661 memset(card->dumpbuffer, 0, DUMP_PAGE_SIZE);
2662 card->dumpbuffer_phys = virt_to_bus(card->dumpbuffer);
2663 card->dumpbuffer_physh = SLIC_GET_ADDR_HIGH(card->dumpbuffer_phys);
2664 card->dumpbuffer_physl = SLIC_GET_ADDR_LOW(card->dumpbuffer_phys);
2667 * Allocate COMMAND BUFFER
2669 if (!card->cmdbuffer) {
2670 card->cmdbuffer = kmalloc(sizeof(struct dump_cmd), GFP_ATOMIC);
2672 ASSERT(card->cmdbuffer);
2673 if (card->cmdbuffer == NULL)
2677 * Smear the shared memory structure and then obtain
2678 * the PHYSICAL address of this structure
2680 memset(card->cmdbuffer, 0, sizeof(struct dump_cmd));
2681 card->cmdbuffer_phys = virt_to_bus(card->cmdbuffer);
2682 card->cmdbuffer_physh = SLIC_GET_ADDR_HIGH(card->cmdbuffer_phys);
2683 card->cmdbuffer_physl = SLIC_GET_ADDR_LOW(card->cmdbuffer_phys);
2687 * Lastly, mark our card state as up and return success
2689 card->state = CARD_UP;
2690 card->reset_in_progress = 0;
2691 DBG_MSG("slicoss: %s EXIT card[%p] adapter[%p] card->state[%x]\n",
2692 __func__, card, adapter, card->state);
2694 return STATUS_SUCCESS;
2697 static u32 slic_card_locate(struct adapter *adapter)
2699 struct sliccard *card = slic_global.slic_card;
2700 struct physcard *physcard = slic_global.phys_card;
2702 u16 __iomem *hostid_reg;
2704 uint rdhostid_offset = 0;
2706 DBG_MSG("slicoss: %s adapter[%p] slot[%x] bus[%x] port[%x]\n",
2707 __func__, adapter, adapter->slotnumber, adapter->busnumber,
2710 switch (adapter->devid) {
2711 case SLIC_2GB_DEVICE_ID:
2712 rdhostid_offset = SLIC_RDHOSTID_2GB;
2714 case SLIC_1GB_DEVICE_ID:
2715 rdhostid_offset = SLIC_RDHOSTID_1GB;
2723 (u16 __iomem *) (((u8 __iomem *) (adapter->slic_regs)) +
2725 DBG_MSG("slicoss: %s *hostid_reg[%p] == ", __func__, hostid_reg);
2727 /* read the 16 bit hostid from SRAM */
2728 card_hostid = (ushort) readw(hostid_reg);
2729 DBG_MSG(" card_hostid[%x]\n", card_hostid);
2731 /* Initialize a new card structure if need be */
2732 if (card_hostid == SLIC_HOSTID_DEFAULT) {
2733 card = kzalloc(sizeof(struct sliccard), GFP_KERNEL);
2737 card->next = slic_global.slic_card;
2738 slic_global.slic_card = card;
2740 if (adapter->devid == SLIC_2GB_DEVICE_ID) {
2742 ("SLICOSS ==> Initialize 2 Port Gigabit Server "
2743 "and Storage Accelerator\n");
2746 ("SLICOSS ==> Initialize 1 Port Gigabit Server "
2747 "and Storage Accelerator\n");
2750 card->busnumber = adapter->busnumber;
2751 card->slotnumber = adapter->slotnumber;
2753 /* Find an available cardnum */
2754 for (i = 0; i < SLIC_MAX_CARDS; i++) {
2755 if (slic_global.cardnuminuse[i] == 0) {
2756 slic_global.cardnuminuse[i] = 1;
2761 slic_global.num_slic_cards++;
2762 DBG_MSG("\nCARDNUM == %d Total %d Card[%p]\n\n",
2763 card->cardnum, slic_global.num_slic_cards, card);
2765 slic_debug_card_create(card);
2768 ("slicoss: %s CARD already allocated, find the \
2769 correct card\n", __func__);
2770 /* Card exists, find the card this adapter belongs to */
2773 ("slicoss: %s card[%p] slot[%x] bus[%x] \
2774 adaptport[%p] hostid[%x] cardnum[%x]\n",
2775 __func__, card, card->slotnumber,
2776 card->busnumber, card->adapter[adapter->port],
2777 card_hostid, card->cardnum);
2779 if (card->cardnum == card_hostid)
2787 return STATUS_FAILURE;
2788 /* Put the adapter in the card's adapter list */
2789 ASSERT(card->adapter[adapter->port] == NULL);
2790 if (!card->adapter[adapter->port]) {
2791 card->adapter[adapter->port] = adapter;
2792 adapter->card = card;
2795 card->card_size = 1; /* one port per *logical* card */
2798 for (i = 0; i < SLIC_MAX_PORTS; i++) {
2799 if (!physcard->adapter[i])
2804 ASSERT(i != SLIC_MAX_PORTS);
2805 if (physcard->adapter[i]->slotnumber == adapter->slotnumber)
2807 physcard = physcard->next;
2810 /* no structure allocated for this physical card yet */
2811 physcard = kzalloc(sizeof(struct physcard), GFP_ATOMIC);
2815 ("\n%s Allocate a PHYSICALcard:\n PHYSICAL_Card[%p]\n"
2816 " LogicalCard [%p]\n adapter [%p]\n",
2817 __func__, physcard, card, adapter);
2819 physcard->next = slic_global.phys_card;
2820 slic_global.phys_card = physcard;
2821 physcard->adapters_allocd = 1;
2823 physcard->adapters_allocd++;
2825 /* Note - this is ZERO relative */
2826 adapter->physport = physcard->adapters_allocd - 1;
2828 ASSERT(physcard->adapter[adapter->physport] == NULL);
2829 physcard->adapter[adapter->physport] = adapter;
2830 adapter->physcard = physcard;
2831 DBG_MSG(" PHYSICAL_Port %d Logical_Port %d\n", adapter->physport,
2837 static void slic_soft_reset(struct adapter *adapter)
2839 if (adapter->card->state == CARD_UP) {
2840 DBG_MSG("slicoss: %s QUIESCE adapter[%p] card[%p] devid[%x]\n",
2841 __func__, adapter, adapter->card, adapter->devid);
2842 WRITE_REG(adapter->slic_regs->slic_quiesce, 0, FLUSH);
2845 /* DBG_MSG ("slicoss: %s (%s) adapter[%p] card[%p] devid[%x]\n",
2846 __func__, adapter->netdev->name, adapter, adapter->card,
2849 WRITE_REG(adapter->slic_regs->slic_reset, SLIC_RESET_MAGIC, FLUSH);
2853 static void slic_config_set(struct adapter *adapter, bool linkchange)
2857 __iomem struct slic_regs *slic_regs = adapter->slic_regs;
2859 DBG_MSG("slicoss: %s (%s) slic_interface_enable[%p](%d)\n",
2860 __func__, adapter->netdev->name, adapter,
2861 adapter->cardindex);
2865 slic_mac_config(adapter);
2866 RcrReset = GRCR_RESET;
2868 slic_mac_address_config(adapter);
2872 if (adapter->linkduplex == LINK_FULLD) {
2874 value = (GXCR_RESET | /* Always reset */
2875 GXCR_XMTEN | /* Enable transmit */
2876 GXCR_PAUSEEN); /* Enable pause */
2878 DBG_MSG("slicoss: FDX adapt[%p] set xmtcfg to [%x]\n", adapter,
2880 WRITE_REG(slic_regs->slic_wxcfg, value, FLUSH);
2882 /* Setup rcvcfg last */
2883 value = (RcrReset | /* Reset, if linkchange */
2884 GRCR_CTLEN | /* Enable CTL frames */
2885 GRCR_ADDRAEN | /* Address A enable */
2886 GRCR_RCVBAD | /* Rcv bad frames */
2887 (GRCR_HASHSIZE << GRCR_HASHSIZE_SHIFT));
2890 value = (GXCR_RESET | /* Always reset */
2891 GXCR_XMTEN); /* Enable transmit */
2893 DBG_MSG("slicoss: HDX adapt[%p] set xmtcfg to [%x]\n", adapter,
2895 WRITE_REG(slic_regs->slic_wxcfg, value, FLUSH);
2897 /* Setup rcvcfg last */
2898 value = (RcrReset | /* Reset, if linkchange */
2899 GRCR_ADDRAEN | /* Address A enable */
2900 GRCR_RCVBAD | /* Rcv bad frames */
2901 (GRCR_HASHSIZE << GRCR_HASHSIZE_SHIFT));
2904 if (adapter->state != ADAPT_DOWN) {
2905 /* Only enable receive if we are restarting or running */
2906 value |= GRCR_RCVEN;
2909 if (adapter->macopts & MAC_PROMISC)
2910 value |= GRCR_RCVALL;
2912 DBG_MSG("slicoss: adapt[%p] set rcvcfg to [%x]\n", adapter, value);
2913 WRITE_REG(slic_regs->slic_wrcfg, value, FLUSH);
2917 * Turn off RCV and XMT, power down PHY
2919 static void slic_config_clear(struct adapter *adapter)
2923 __iomem struct slic_regs *slic_regs = adapter->slic_regs;
2926 value = (GXCR_RESET | /* Always reset */
2927 GXCR_PAUSEEN); /* Enable pause */
2929 WRITE_REG(slic_regs->slic_wxcfg, value, FLUSH);
2931 value = (GRCR_RESET | /* Always reset */
2932 GRCR_CTLEN | /* Enable CTL frames */
2933 GRCR_ADDRAEN | /* Address A enable */
2934 (GRCR_HASHSIZE << GRCR_HASHSIZE_SHIFT));
2936 WRITE_REG(slic_regs->slic_wrcfg, value, FLUSH);
2938 /* power down phy */
2939 phy_config = (MIICR_REG_PCR | (PCR_POWERDOWN));
2940 WRITE_REG(slic_regs->slic_wphy, phy_config, FLUSH);
2943 static void slic_config_get(struct adapter *adapter, u32 config,
2948 status = slic_upr_request(adapter,
2950 (u32) config, (u32) config_h, 0, 0);
2951 ASSERT(status == 0);
2954 static void slic_mac_address_config(struct adapter *adapter)
2958 __iomem struct slic_regs *slic_regs = adapter->slic_regs;
2960 value = *(u32 *) &adapter->currmacaddr[2];
2961 value = ntohl(value);
2962 WRITE_REG(slic_regs->slic_wraddral, value, FLUSH);
2963 WRITE_REG(slic_regs->slic_wraddrbl, value, FLUSH);
2965 value2 = (u32) ((adapter->currmacaddr[0] << 8 |
2966 adapter->currmacaddr[1]) & 0xFFFF);
2968 WRITE_REG(slic_regs->slic_wraddrah, value2, FLUSH);
2969 WRITE_REG(slic_regs->slic_wraddrbh, value2, FLUSH);
2971 DBG_MSG("%s value1[%x] value2[%x] Call slic_mcast_set_mask\n",
2972 __func__, value, value2);
2973 slic_dbg_macaddrs(adapter);
2975 /* Write our multicast mask out to the card. This is done */
2976 /* here in addition to the slic_mcast_addr_set routine */
2977 /* because ALL_MCAST may have been enabled or disabled */
2978 slic_mcast_set_mask(adapter);
2981 static void slic_mac_config(struct adapter *adapter)
2984 __iomem struct slic_regs *slic_regs = adapter->slic_regs;
2986 /* Setup GMAC gaps */
2987 if (adapter->linkspeed == LINK_1000MB) {
2988 value = ((GMCR_GAPBB_1000 << GMCR_GAPBB_SHIFT) |
2989 (GMCR_GAPR1_1000 << GMCR_GAPR1_SHIFT) |
2990 (GMCR_GAPR2_1000 << GMCR_GAPR2_SHIFT));
2992 value = ((GMCR_GAPBB_100 << GMCR_GAPBB_SHIFT) |
2993 (GMCR_GAPR1_100 << GMCR_GAPR1_SHIFT) |
2994 (GMCR_GAPR2_100 << GMCR_GAPR2_SHIFT));
2998 if (adapter->linkspeed == LINK_1000MB)
3001 /* enable fullduplex */
3002 if ((adapter->linkduplex == LINK_FULLD)
3003 || (adapter->macopts & MAC_LOOPBACK)) {
3004 value |= GMCR_FULLD;
3007 /* write mac config */
3008 WRITE_REG(slic_regs->slic_wmcfg, value, FLUSH);
3010 /* setup mac addresses */
3011 slic_mac_address_config(adapter);
3014 static bool slic_mac_filter(struct adapter *adapter,
3015 struct ether_header *ether_frame)
3017 u32 opts = adapter->macopts;
3018 u32 *dhost4 = (u32 *)ðer_frame->ether_dhost[0];
3019 u16 *dhost2 = (u16 *)ðer_frame->ether_dhost[4];
3022 if (opts & MAC_PROMISC) {
3023 DBG_MSG("slicoss: %s (%s) PROMISCUOUS. Accept frame\n",
3024 __func__, adapter->netdev->name);
3028 if ((*dhost4 == 0xFFFFFFFF) && (*dhost2 == 0xFFFF)) {
3029 if (opts & MAC_BCAST) {
3030 adapter->rcv_broadcasts++;
3037 if (ether_frame->ether_dhost[0] & 0x01) {
3038 if (opts & MAC_ALLMCAST) {
3039 adapter->rcv_multicasts++;
3040 adapter->stats.multicast++;
3043 if (opts & MAC_MCAST) {
3044 struct mcast_address *mcaddr = adapter->mcastaddrs;
3047 ETHER_EQ_ADDR(mcaddr->address,
3048 ether_frame->ether_dhost,
3051 adapter->rcv_multicasts++;
3052 adapter->stats.multicast++;
3055 mcaddr = mcaddr->next;
3062 if (opts & MAC_DIRECTED) {
3063 adapter->rcv_unicasts++;
3070 static int slic_mac_set_address(struct net_device *dev, void *ptr)
3072 struct adapter *adapter = (struct adapter *)netdev_priv(dev);
3073 struct sockaddr *addr = ptr;
3075 DBG_MSG("%s ENTER (%s)\n", __func__, adapter->netdev->name);
3077 if (netif_running(dev))
3081 DBG_MSG("slicoss: %s (%s) curr %2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X\n",
3082 __func__, adapter->netdev->name, adapter->currmacaddr[0],
3083 adapter->currmacaddr[1], adapter->currmacaddr[2],
3084 adapter->currmacaddr[3], adapter->currmacaddr[4],
3085 adapter->currmacaddr[5]);
3086 memcpy(dev->dev_addr, addr->sa_data, dev->addr_len);
3087 memcpy(adapter->currmacaddr, addr->sa_data, dev->addr_len);
3088 DBG_MSG("slicoss: %s (%s) new %2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X\n",
3089 __func__, adapter->netdev->name, adapter->currmacaddr[0],
3090 adapter->currmacaddr[1], adapter->currmacaddr[2],
3091 adapter->currmacaddr[3], adapter->currmacaddr[4],
3092 adapter->currmacaddr[5]);
3094 slic_config_set(adapter, TRUE);
3099 * slic_timer_get_stats
3101 * Timer function used to suck the statistics out of the card every
3102 * 50 seconds or whatever STATS_TIMER_INTERVAL is set to.
3105 #if SLIC_GET_STATS_TIMER_ENABLED
3106 static void slic_timer_get_stats(ulong dev)
3108 struct adapter *adapter;
3109 struct sliccard *card;
3110 struct slic_shmem *pshmem;
3113 adapter = netdev_priv((struct net_device *)dev);
3115 card = adapter->card;
3118 if ((card->state == CARD_UP) &&
3119 (adapter->state == ADAPT_UP) && (adapter->linkstate == LINK_UP)) {
3120 pshmem = (struct slic_shmem *)adapter->phys_shmem;
3121 #ifdef CONFIG_X86_64
3122 slic_upr_request(adapter,
3124 SLIC_GET_ADDR_LOW(&pshmem->inicstats),
3125 SLIC_GET_ADDR_HIGH(&pshmem->inicstats), 0, 0);
3126 #elif defined(CONFIG_X86)
3127 slic_upr_request(adapter,
3129 (u32) &pshmem->inicstats, 0, 0, 0);
3134 /* DBG_MSG ("slicoss: %s adapter[%p] linkstate[%x] NOT UP!\n",
3135 __func__, adapter, adapter->linkstate); */
3137 adapter->statstimer.expires = jiffies +
3138 SLIC_SECS_TO_JIFFS(STATS_TIMER_INTERVAL);
3139 add_timer(&adapter->statstimer);
3142 static void slic_timer_load_check(ulong cardaddr)
3144 struct sliccard *card = (struct sliccard *)cardaddr;
3145 struct adapter *adapter = card->master;
3146 u32 load = card->events;
3149 if ((adapter) && (adapter->state == ADAPT_UP) &&
3150 (card->state == CARD_UP) && (slic_global.dynamic_intagg)) {
3151 if (adapter->devid == SLIC_1GB_DEVICE_ID) {
3152 if (adapter->linkspeed == LINK_1000MB)
3155 if (load > SLIC_LOAD_5)
3156 level = SLIC_INTAGG_5;
3157 else if (load > SLIC_LOAD_4)
3158 level = SLIC_INTAGG_4;
3159 else if (load > SLIC_LOAD_3)
3160 level = SLIC_INTAGG_3;
3161 else if (load > SLIC_LOAD_2)
3162 level = SLIC_INTAGG_2;
3163 else if (load > SLIC_LOAD_1)
3164 level = SLIC_INTAGG_1;
3166 level = SLIC_INTAGG_0;
3168 if (card->loadlevel_current != level) {
3169 card->loadlevel_current = level;
3170 WRITE_REG(adapter->slic_regs->slic_intagg,
3174 if (load > SLIC_LOAD_5)
3175 level = SLIC_INTAGG_5;
3176 else if (load > SLIC_LOAD_4)
3177 level = SLIC_INTAGG_4;
3178 else if (load > SLIC_LOAD_3)
3179 level = SLIC_INTAGG_3;
3180 else if (load > SLIC_LOAD_2)
3181 level = SLIC_INTAGG_2;
3182 else if (load > SLIC_LOAD_1)
3183 level = SLIC_INTAGG_1;
3185 level = SLIC_INTAGG_0;
3186 if (card->loadlevel_current != level) {
3187 card->loadlevel_current = level;
3188 WRITE_REG(adapter->slic_regs->slic_intagg,
3194 card->loadtimer.expires =
3195 jiffies + SLIC_SECS_TO_JIFFS(SLIC_LOADTIMER_PERIOD);
3196 add_timer(&card->loadtimer);
3199 static void slic_assert_fail(void)
3203 cpuid = smp_processor_id();
3204 curr_pid = current->pid;
3206 DBG_ERROR("%s CPU # %d ---- PID # %d\n", __func__, cpuid, curr_pid);
3209 static int slic_upr_queue_request(struct adapter *adapter,
3213 u32 upr_buffer, u32 upr_buffer_h)
3215 struct slic_upr *upr;
3216 struct slic_upr *uprqueue;
3218 upr = kmalloc(sizeof(struct slic_upr), GFP_ATOMIC);
3220 DBG_MSG("%s COULD NOT ALLOCATE UPR MEM\n", __func__);
3224 upr->adapter = adapter->port;
3225 upr->upr_request = upr_request;
3226 upr->upr_data = upr_data;
3227 upr->upr_buffer = upr_buffer;
3228 upr->upr_data_h = upr_data_h;
3229 upr->upr_buffer_h = upr_buffer_h;
3231 if (adapter->upr_list) {
3232 uprqueue = adapter->upr_list;
3234 while (uprqueue->next)
3235 uprqueue = uprqueue->next;
3236 uprqueue->next = upr;
3238 adapter->upr_list = upr;
3240 return STATUS_SUCCESS;
3243 static int slic_upr_request(struct adapter *adapter,
3247 u32 upr_buffer, u32 upr_buffer_h)
3251 spin_lock_irqsave(&adapter->upr_lock.lock, adapter->upr_lock.flags);
3252 status = slic_upr_queue_request(adapter,
3255 upr_data_h, upr_buffer, upr_buffer_h);
3256 if (status != STATUS_SUCCESS) {
3257 spin_unlock_irqrestore(&adapter->upr_lock.lock,
3258 adapter->upr_lock.flags);
3261 slic_upr_start(adapter);
3262 spin_unlock_irqrestore(&adapter->upr_lock.lock,
3263 adapter->upr_lock.flags);
3264 return STATUS_PENDING;
3267 static void slic_upr_request_complete(struct adapter *adapter, u32 isr)
3269 struct sliccard *card = adapter->card;
3270 struct slic_upr *upr;
3272 /* if (card->dump_requested) {
3273 DBG_MSG("ENTER slic_upr_request_complete Dump in progress ISR[%x]\n",
3276 spin_lock_irqsave(&adapter->upr_lock.lock, adapter->upr_lock.flags);
3277 upr = adapter->upr_list;
3280 spin_unlock_irqrestore(&adapter->upr_lock.lock,
3281 adapter->upr_lock.flags);
3284 adapter->upr_list = upr->next;
3286 adapter->upr_busy = 0;
3287 ASSERT(adapter->port == upr->adapter);
3288 switch (upr->upr_request) {
3289 case SLIC_UPR_STATS:
3291 #if SLIC_GET_STATS_ENABLED
3292 struct slic_stats *slicstats =
3293 (struct slic_stats *) &adapter->pshmem->inicstats;
3294 struct slic_stats *newstats = slicstats;
3295 struct slic_stats *old = &adapter->inicstats_prev;
3296 struct slicnet_stats *stst = &adapter->slic_stats;
3298 if (isr & ISR_UPCERR) {
3300 ("SLIC_UPR_STATS command failed isr[%x]\n",
3305 #if SLIC_GET_STATS_ENABLED
3306 /* DBG_MSG ("slicoss: %s rcv %lx:%lx:%lx:%lx:%lx %lx %lx "
3307 "xmt %lx:%lx:%lx:%lx:%lx %lx %lx\n",
3309 slicstats->rcv_unicasts100,
3310 slicstats->rcv_bytes100,
3311 slicstats->rcv_bytes100,
3312 slicstats->rcv_tcp_bytes100,
3313 slicstats->rcv_tcp_segs100,
3314 slicstats->rcv_other_error100,
3315 slicstats->rcv_drops100,
3316 slicstats->xmit_unicasts100,
3317 slicstats->xmit_bytes100,
3318 slicstats->xmit_bytes100,
3319 slicstats->xmit_tcp_bytes100,
3320 slicstats->xmit_tcp_segs100,
3321 slicstats->xmit_other_error100,
3322 slicstats->xmit_collisions100);*/
3323 UPDATE_STATS_GB(stst->tcp.xmit_tcp_segs,
3324 newstats->xmit_tcp_segs_gb,
3325 old->xmit_tcp_segs_gb);
3327 UPDATE_STATS_GB(stst->tcp.xmit_tcp_bytes,
3328 newstats->xmit_tcp_bytes_gb,
3329 old->xmit_tcp_bytes_gb);
3331 UPDATE_STATS_GB(stst->tcp.rcv_tcp_segs,
3332 newstats->rcv_tcp_segs_gb,
3333 old->rcv_tcp_segs_gb);
3335 UPDATE_STATS_GB(stst->tcp.rcv_tcp_bytes,
3336 newstats->rcv_tcp_bytes_gb,
3337 old->rcv_tcp_bytes_gb);
3339 UPDATE_STATS_GB(stst->iface.xmt_bytes,
3340 newstats->xmit_bytes_gb,
3341 old->xmit_bytes_gb);
3343 UPDATE_STATS_GB(stst->iface.xmt_ucast,
3344 newstats->xmit_unicasts_gb,
3345 old->xmit_unicasts_gb);
3347 UPDATE_STATS_GB(stst->iface.rcv_bytes,
3348 newstats->rcv_bytes_gb,
3351 UPDATE_STATS_GB(stst->iface.rcv_ucast,
3352 newstats->rcv_unicasts_gb,
3353 old->rcv_unicasts_gb);
3355 UPDATE_STATS_GB(stst->iface.xmt_errors,
3356 newstats->xmit_collisions_gb,
3357 old->xmit_collisions_gb);
3359 UPDATE_STATS_GB(stst->iface.xmt_errors,
3360 newstats->xmit_excess_collisions_gb,
3361 old->xmit_excess_collisions_gb);
3363 UPDATE_STATS_GB(stst->iface.xmt_errors,
3364 newstats->xmit_other_error_gb,
3365 old->xmit_other_error_gb);
3367 UPDATE_STATS_GB(stst->iface.rcv_errors,
3368 newstats->rcv_other_error_gb,
3369 old->rcv_other_error_gb);
3371 UPDATE_STATS_GB(stst->iface.rcv_discards,
3372 newstats->rcv_drops_gb,
3375 if (newstats->rcv_drops_gb > old->rcv_drops_gb) {
3376 adapter->rcv_drops +=
3377 (newstats->rcv_drops_gb -
3380 memcpy(old, newstats, sizeof(struct slic_stats));
3385 slic_link_upr_complete(adapter, isr);
3387 case SLIC_UPR_RCONFIG:
3402 card->pingstatus |= (isr & ISR_PINGDSMASK);
3404 #if SLIC_DUMP_ENABLED
3406 card->dumpstatus |= (isr & ISR_UPCMASK);
3413 slic_upr_start(adapter);
3414 spin_unlock_irqrestore(&adapter->upr_lock.lock,
3415 adapter->upr_lock.flags);
3418 static void slic_upr_start(struct adapter *adapter)
3420 struct slic_upr *upr;
3421 __iomem struct slic_regs *slic_regs = adapter->slic_regs;
3427 upr = adapter->upr_list;
3430 if (adapter->upr_busy)
3432 adapter->upr_busy = 1;
3434 switch (upr->upr_request) {
3435 case SLIC_UPR_STATS:
3436 if (upr->upr_data_h == 0) {
3437 WRITE_REG(slic_regs->slic_stats, upr->upr_data, FLUSH);
3439 WRITE_REG64(adapter,
3440 slic_regs->slic_stats64,
3442 slic_regs->slic_addr_upper,
3443 upr->upr_data_h, FLUSH);
3448 WRITE_REG64(adapter,
3449 slic_regs->slic_rlsr,
3451 slic_regs->slic_addr_upper, upr->upr_data_h, FLUSH);
3454 case SLIC_UPR_RCONFIG:
3455 DBG_MSG("%s SLIC_UPR_RCONFIG!!!!\n", __func__);
3456 DBG_MSG("WRITE_REG64 adapter[%p]\n"
3457 " a->slic_regs[%p] slic_regs[%p]\n"
3458 " &slic_rconfig[%p] &slic_addr_upper[%p]\n"
3460 " uprdata[%x] uprdatah[%x]\n",
3461 adapter, adapter->slic_regs, slic_regs,
3462 &slic_regs->slic_rconfig, &slic_regs->slic_addr_upper,
3463 upr, upr->upr_data, upr->upr_data_h);
3464 WRITE_REG64(adapter,
3465 slic_regs->slic_rconfig,
3467 slic_regs->slic_addr_upper, upr->upr_data_h, FLUSH);
3469 #if SLIC_DUMP_ENABLED
3472 DBG_MSG("%s SLIC_UPR_DUMP!!!!\n", __func__);
3473 DBG_MSG("WRITE_REG64 adapter[%p]\n"
3474 " upr_buffer[%x] upr_bufferh[%x]\n"
3475 " upr_data[%x] upr_datah[%x]\n"
3476 " cmdbuff[%p] cmdbuffP[%p]\n"
3477 " dumpbuff[%p] dumpbuffP[%p]\n",
3478 adapter, upr->upr_buffer, upr->upr_buffer_h,
3479 upr->upr_data, upr->upr_data_h,
3480 adapter->card->cmdbuffer,
3481 (void *)adapter->card->cmdbuffer_phys,
3482 adapter->card->dumpbuffer, (
3483 void *)adapter->card->dumpbuffer_phys);
3485 ptr1 = (char *)slic_regs;
3486 ptr2 = (char *)(&slic_regs->slic_dump_cmd);
3487 cmdoffset = ptr2 - ptr1;
3488 DBG_MSG("slic_dump_cmd register offset [%x]\n", cmdoffset);
3490 if (upr->upr_buffer || upr->upr_buffer_h) {
3491 WRITE_REG64(adapter,
3492 slic_regs->slic_dump_data,
3494 slic_regs->slic_addr_upper,
3495 upr->upr_buffer_h, FLUSH);
3497 WRITE_REG64(adapter,
3498 slic_regs->slic_dump_cmd,
3500 slic_regs->slic_addr_upper, upr->upr_data_h, FLUSH);
3504 WRITE_REG(slic_regs->slic_ping, 1, FLUSH);
3511 static void slic_link_upr_complete(struct adapter *adapter, u32 isr)
3513 u32 linkstatus = adapter->pshmem->linkstatus;
3515 unsigned char linkspeed;
3516 unsigned char linkduplex;
3518 DBG_MSG("%s: %s ISR[%x] linkstatus[%x]\n adapter[%p](%d)\n",
3519 __func__, adapter->netdev->name, isr, linkstatus, adapter,
3520 adapter->cardindex);
3522 if ((isr & ISR_UPCERR) || (isr & ISR_UPCBSY)) {
3523 struct slic_shmem *pshmem;
3525 pshmem = (struct slic_shmem *)adapter->phys_shmem;
3526 #if defined(CONFIG_X86_64)
3527 slic_upr_queue_request(adapter,
3529 SLIC_GET_ADDR_LOW(&pshmem->linkstatus),
3530 SLIC_GET_ADDR_HIGH(&pshmem->linkstatus),
3532 #elif defined(CONFIG_X86)
3533 slic_upr_queue_request(adapter,
3535 (u32) &pshmem->linkstatus,
3536 SLIC_GET_ADDR_HIGH(pshmem), 0, 0);
3542 if (adapter->state != ADAPT_UP)
3545 ASSERT((adapter->devid == SLIC_1GB_DEVICE_ID)
3546 || (adapter->devid == SLIC_2GB_DEVICE_ID));
3548 linkup = linkstatus & GIG_LINKUP ? LINK_UP : LINK_DOWN;
3549 if (linkstatus & GIG_SPEED_1000) {
3550 linkspeed = LINK_1000MB;
3551 DBG_MSG("slicoss: %s (%s) GIGABIT Speed==1000MB ",
3552 __func__, adapter->netdev->name);
3553 } else if (linkstatus & GIG_SPEED_100) {
3554 linkspeed = LINK_100MB;
3555 DBG_MSG("slicoss: %s (%s) GIGABIT Speed==100MB ", __func__,
3556 adapter->netdev->name);
3558 linkspeed = LINK_10MB;
3559 DBG_MSG("slicoss: %s (%s) GIGABIT Speed==10MB ", __func__,
3560 adapter->netdev->name);
3562 if (linkstatus & GIG_FULLDUPLEX) {
3563 linkduplex = LINK_FULLD;
3564 DBG_MSG(" Duplex == FULL\n");
3566 linkduplex = LINK_HALFD;
3567 DBG_MSG(" Duplex == HALF\n");
3570 if ((adapter->linkstate == LINK_DOWN) && (linkup == LINK_DOWN)) {
3571 DBG_MSG("slicoss: %s (%s) physport(%d) link still down\n",
3572 __func__, adapter->netdev->name, adapter->physport);
3576 /* link up event, but nothing has changed */
3577 if ((adapter->linkstate == LINK_UP) &&
3578 (linkup == LINK_UP) &&
3579 (adapter->linkspeed == linkspeed) &&
3580 (adapter->linkduplex == linkduplex)) {
3581 DBG_MSG("slicoss: %s (%s) port(%d) link still up\n",
3582 __func__, adapter->netdev->name, adapter->physport);
3586 /* link has changed at this point */
3588 /* link has gone from up to down */
3589 if (linkup == LINK_DOWN) {
3590 adapter->linkstate = LINK_DOWN;
3591 DBG_MSG("slicoss: %s %d LinkDown!\n", __func__,
3596 /* link has gone from down to up */
3597 adapter->linkspeed = linkspeed;
3598 adapter->linkduplex = linkduplex;
3600 if (adapter->linkstate != LINK_UP) {
3602 DBG_MSG("%s call slic_config_set\n", __func__);
3603 slic_config_set(adapter, TRUE);
3604 adapter->linkstate = LINK_UP;
3605 DBG_MSG("\n(%s) Link UP: CALL slic_if_start_queue",
3606 adapter->netdev->name);
3607 slic_if_start_queue(adapter);
3610 switch (linkspeed) {
3613 ("\n(%s) LINK UP!: GIGABIT SPEED == 1000MB duplex[%x]\n",
3614 adapter->netdev->name, adapter->linkduplex);
3617 DBG_MSG("\n(%s) LINK UP!: SPEED == 100MB duplex[%x]\n",
3618 adapter->netdev->name, adapter->linkduplex);
3621 DBG_MSG("\n(%s) LINK UP!: SPEED == 10MB duplex[%x]\n",
3622 adapter->netdev->name, adapter->linkduplex);
3629 * this is here to checksum the eeprom, there is some ucode bug
3630 * which prevens us from using the ucode result.
3631 * remove this once ucode is fixed.
3633 static ushort slic_eeprom_cksum(char *m, int len)
3635 #define ADDCARRY(x) (x > 65535 ? x -= 65535 : x)
3636 #define REDUCE {l_util.l = sum; sum = l_util.s[0] + l_util.s[1]; ADDCARRY(sum);\
3641 u32 byte_swapped = 0;
3658 #ifdef CONFIG_X86_64
3659 w_int = (u32) ((ulong) w & 0x00000000FFFFFFFF);
3663 if ((1 & w_int) && (len > 0)) {
3666 s_util.c[0] = *(unsigned char *)w;
3667 w = (u16 *)((char *)w + 1);
3672 /* Unroll the loop to make overhead from branches &c small. */
3673 while ((len -= 32) >= 0) {
3690 w = (u16 *)((ulong) w + 16); /* verify */
3693 while ((len -= 8) >= 0) {
3698 w = (u16 *)((ulong) w + 4); /* verify */
3701 if (len != 0 || byte_swapped != 0) {
3703 while ((len -= 2) >= 0)
3704 sum += *w++; /* verify */
3710 s_util.c[1] = *(char *) w;
3717 } else if (len == -1) {
3718 s_util.c[0] = *(char *) w;
3727 return (ushort) sum;
3730 static int slic_rspqueue_init(struct adapter *adapter)
3733 struct slic_rspqueue *rspq = &adapter->rspqueue;
3734 __iomem struct slic_regs *slic_regs = adapter->slic_regs;
3737 DBG_MSG("slicoss: %s (%s) ENTER adapter[%p]\n", __func__,
3738 adapter->netdev->name, adapter);
3739 ASSERT(adapter->state == ADAPT_DOWN);
3740 memset(rspq, 0, sizeof(struct slic_rspqueue));
3742 rspq->num_pages = SLIC_RSPQ_PAGES_GB;
3744 for (i = 0; i < rspq->num_pages; i++) {
3746 pci_alloc_consistent(adapter->pcidev, PAGE_SIZE,
3748 if (!rspq->vaddr[i]) {
3750 ("rspqueue_init_failed pci_alloc_consistent\n");
3751 slic_rspqueue_free(adapter);
3752 return STATUS_FAILURE;
3754 #ifndef CONFIG_X86_64
3755 ASSERT(((u32) rspq->vaddr[i] & 0xFFFFF000) ==
3756 (u32) rspq->vaddr[i]);
3757 ASSERT(((u32) rspq->paddr[i] & 0xFFFFF000) ==
3758 (u32) rspq->paddr[i]);
3760 memset(rspq->vaddr[i], 0, PAGE_SIZE);
3761 /* DBG_MSG("slicoss: %s UPLOAD RSPBUFF Page pageix[%x] paddr[%p] "
3763 __func__, i, (void *)rspq->paddr[i], rspq->vaddr[i]); */
3766 WRITE_REG(slic_regs->slic_rbar,
3767 (rspq->paddr[i] | SLIC_RSPQ_BUFSINPAGE),
3770 WRITE_REG64(adapter,
3771 slic_regs->slic_rbar64,
3772 (rspq->paddr[i] | SLIC_RSPQ_BUFSINPAGE),
3773 slic_regs->slic_addr_upper,
3774 paddrh, DONT_FLUSH);
3778 rspq->pageindex = 0;
3779 rspq->rspbuf = (struct slic_rspbuf *)rspq->vaddr[0];
3780 DBG_MSG("slicoss: %s (%s) EXIT adapter[%p]\n", __func__,
3781 adapter->netdev->name, adapter);
3782 return STATUS_SUCCESS;
3785 static int slic_rspqueue_reset(struct adapter *adapter)
3787 struct slic_rspqueue *rspq = &adapter->rspqueue;
3789 DBG_MSG("slicoss: %s (%s) ENTER adapter[%p]\n", __func__,
3790 adapter->netdev->name, adapter);
3791 ASSERT(adapter->state == ADAPT_DOWN);
3794 DBG_MSG("slicoss: Nothing to do. rspq[%p]\n"
3798 rspq, rspq->offset, rspq->pageindex, rspq->rspbuf);
3800 DBG_MSG("slicoss: %s (%s) EXIT adapter[%p]\n", __func__,
3801 adapter->netdev->name, adapter);
3802 return STATUS_SUCCESS;
3805 static void slic_rspqueue_free(struct adapter *adapter)
3808 struct slic_rspqueue *rspq = &adapter->rspqueue;
3810 DBG_MSG("slicoss: %s adapter[%p] port %d rspq[%p] FreeRSPQ\n",
3811 __func__, adapter, adapter->physport, rspq);
3812 for (i = 0; i < rspq->num_pages; i++) {
3813 if (rspq->vaddr[i]) {
3815 ("slicoss: pci_free_consistent rspq->vaddr[%p] \
3817 rspq->vaddr[i], (void *) rspq->paddr[i]);
3818 pci_free_consistent(adapter->pcidev, PAGE_SIZE,
3819 rspq->vaddr[i], rspq->paddr[i]);
3821 rspq->vaddr[i] = NULL;
3825 rspq->pageindex = 0;
3826 rspq->rspbuf = NULL;
3829 static struct slic_rspbuf *slic_rspqueue_getnext(struct adapter *adapter)
3831 struct slic_rspqueue *rspq = &adapter->rspqueue;
3832 struct slic_rspbuf *buf;
3834 if (!(rspq->rspbuf->status))
3838 #ifndef CONFIG_X86_64
3839 ASSERT((buf->status & 0xFFFFFFE0) == 0);
3841 ASSERT(buf->hosthandle);
3842 if (++rspq->offset < SLIC_RSPQ_BUFSINPAGE) {
3844 #ifndef CONFIG_X86_64
3845 ASSERT(((u32) rspq->rspbuf & 0xFFFFFFE0) ==
3846 (u32) rspq->rspbuf);
3849 ASSERT(rspq->offset == SLIC_RSPQ_BUFSINPAGE);
3850 WRITE_REG64(adapter,
3851 adapter->slic_regs->slic_rbar64,
3853 paddr[rspq->pageindex] | SLIC_RSPQ_BUFSINPAGE),
3854 adapter->slic_regs->slic_addr_upper, 0, DONT_FLUSH);
3855 rspq->pageindex = (++rspq->pageindex) % rspq->num_pages;
3857 rspq->rspbuf = (struct slic_rspbuf *)
3858 rspq->vaddr[rspq->pageindex];
3859 #ifndef CONFIG_X86_64
3860 ASSERT(((u32) rspq->rspbuf & 0xFFFFF000) ==
3861 (u32) rspq->rspbuf);
3864 #ifndef CONFIG_X86_64
3865 ASSERT(((u32) buf & 0xFFFFFFE0) == (u32) buf);
3870 static void slic_cmdqmem_init(struct adapter *adapter)
3872 struct slic_cmdqmem *cmdqmem = &adapter->cmdqmem;
3874 memset(cmdqmem, 0, sizeof(struct slic_cmdqmem));
3877 static void slic_cmdqmem_free(struct adapter *adapter)
3879 struct slic_cmdqmem *cmdqmem = &adapter->cmdqmem;
3882 DBG_MSG("slicoss: (%s) adapter[%p] port %d rspq[%p] Free CMDQ Memory\n",
3883 __func__, adapter, adapter->physport, cmdqmem);
3884 for (i = 0; i < SLIC_CMDQ_MAXPAGES; i++) {
3885 if (cmdqmem->pages[i]) {
3886 DBG_MSG("slicoss: %s Deallocate page CmdQPage[%p]\n",
3887 __func__, (void *) cmdqmem->pages[i]);
3888 pci_free_consistent(adapter->pcidev,
3890 (void *) cmdqmem->pages[i],
3891 cmdqmem->dma_pages[i]);
3894 memset(cmdqmem, 0, sizeof(struct slic_cmdqmem));
3897 static u32 *slic_cmdqmem_addpage(struct adapter *adapter)
3899 struct slic_cmdqmem *cmdqmem = &adapter->cmdqmem;
3902 if (cmdqmem->pagecnt >= SLIC_CMDQ_MAXPAGES)
3904 pageaddr = pci_alloc_consistent(adapter->pcidev,
3906 &cmdqmem->dma_pages[cmdqmem->pagecnt]);
3909 #ifndef CONFIG_X86_64
3910 ASSERT(((u32) pageaddr & 0xFFFFF000) == (u32) pageaddr);
3912 cmdqmem->pages[cmdqmem->pagecnt] = pageaddr;
3917 static int slic_cmdq_init(struct adapter *adapter)
3922 DBG_MSG("slicoss: %s ENTER adapter[%p]\n", __func__, adapter);
3923 ASSERT(adapter->state == ADAPT_DOWN);
3924 memset(&adapter->cmdq_all, 0, sizeof(struct slic_cmdqueue));
3925 memset(&adapter->cmdq_free, 0, sizeof(struct slic_cmdqueue));
3926 memset(&adapter->cmdq_done, 0, sizeof(struct slic_cmdqueue));
3927 spin_lock_init(&adapter->cmdq_all.lock.lock);
3928 spin_lock_init(&adapter->cmdq_free.lock.lock);
3929 spin_lock_init(&adapter->cmdq_done.lock.lock);
3930 slic_cmdqmem_init(adapter);
3931 adapter->slic_handle_ix = 1;
3932 for (i = 0; i < SLIC_CMDQ_INITPAGES; i++) {
3933 pageaddr = slic_cmdqmem_addpage(adapter);
3934 #ifndef CONFIG_X86_64
3935 ASSERT(((u32) pageaddr & 0xFFFFF000) == (u32) pageaddr);
3938 slic_cmdq_free(adapter);
3939 return STATUS_FAILURE;
3941 slic_cmdq_addcmdpage(adapter, pageaddr);
3943 adapter->slic_handle_ix = 1;
3944 DBG_MSG("slicoss: %s reset slic_handle_ix to ONE\n", __func__);
3946 return STATUS_SUCCESS;
3949 static void slic_cmdq_free(struct adapter *adapter)
3951 struct slic_hostcmd *cmd;
3953 DBG_MSG("slicoss: %s adapter[%p] port %d FreeCommandsFrom CMDQ\n",
3954 __func__, adapter, adapter->physport);
3955 cmd = adapter->cmdq_all.head;
3958 struct sk_buff *tempskb;
3963 dev_kfree_skb_irq(tempskb);
3966 cmd = cmd->next_all;
3968 memset(&adapter->cmdq_all, 0, sizeof(struct slic_cmdqueue));
3969 memset(&adapter->cmdq_free, 0, sizeof(struct slic_cmdqueue));
3970 memset(&adapter->cmdq_done, 0, sizeof(struct slic_cmdqueue));
3971 slic_cmdqmem_free(adapter);
3974 static void slic_cmdq_reset(struct adapter *adapter)
3976 struct slic_hostcmd *hcmd;
3977 struct sk_buff *skb;
3980 DBG_MSG("%s ENTER adapter[%p]\n", __func__, adapter);
3981 spin_lock_irqsave(&adapter->cmdq_free.lock.lock,
3982 adapter->cmdq_free.lock.flags);
3983 spin_lock_irqsave(&adapter->cmdq_done.lock.lock,
3984 adapter->cmdq_done.lock.flags);
3985 outstanding = adapter->cmdq_all.count - adapter->cmdq_done.count;
3986 outstanding -= adapter->cmdq_free.count;
3987 hcmd = adapter->cmdq_all.head;
3992 DBG_MSG("slicoss: %s hcmd[%p] skb[%p] ", __func__,
3996 DBG_MSG(" Free SKB\n");
3997 dev_kfree_skb_irq(skb);
3999 hcmd = hcmd->next_all;
4001 adapter->cmdq_free.count = 0;
4002 adapter->cmdq_free.head = NULL;
4003 adapter->cmdq_free.tail = NULL;
4004 adapter->cmdq_done.count = 0;
4005 adapter->cmdq_done.head = NULL;
4006 adapter->cmdq_done.tail = NULL;
4007 adapter->cmdq_free.head = adapter->cmdq_all.head;
4008 hcmd = adapter->cmdq_all.head;
4010 adapter->cmdq_free.count++;
4011 hcmd->next = hcmd->next_all;
4012 hcmd = hcmd->next_all;
4014 if (adapter->cmdq_free.count != adapter->cmdq_all.count) {
4015 DBG_ERROR("%s free_count %d != all count %d\n", __func__,
4016 adapter->cmdq_free.count, adapter->cmdq_all.count);
4018 spin_unlock_irqrestore(&adapter->cmdq_done.lock.lock,
4019 adapter->cmdq_done.lock.flags);
4020 spin_unlock_irqrestore(&adapter->cmdq_free.lock.lock,
4021 adapter->cmdq_free.lock.flags);
4022 DBG_MSG("%s EXIT adapter[%p]\n", __func__, adapter);
4025 static void slic_cmdq_addcmdpage(struct adapter *adapter, u32 *page)
4027 struct slic_hostcmd *cmd;
4028 struct slic_hostcmd *prev;
4029 struct slic_hostcmd *tail;
4030 struct slic_cmdqueue *cmdq;
4036 struct slic_handle *pslic_handle;
4039 cmd = (struct slic_hostcmd *)cmdaddr;
4040 /* DBG_MSG("CMDQ Page addr[%p] ix[%d] pfree[%p]\n", cmdaddr, slic_handle_ix,
4041 adapter->pfree_slic_handles); */
4044 phys_addr = virt_to_bus((void *)page);
4045 phys_addrl = SLIC_GET_ADDR_LOW(phys_addr);
4046 phys_addrh = SLIC_GET_ADDR_HIGH(phys_addr);
4050 while ((cmdcnt < SLIC_CMDQ_CMDSINPAGE) &&
4051 (adapter->slic_handle_ix < 256)) {
4052 /* Allocate and initialize a SLIC_HANDLE for this command */
4053 SLIC_GET_SLIC_HANDLE(adapter, pslic_handle);
4054 if (pslic_handle == NULL)
4056 ASSERT(pslic_handle ==
4057 &adapter->slic_handles[pslic_handle->token.
4059 pslic_handle->type = SLIC_HANDLE_CMD;
4060 pslic_handle->address = (void *) cmd;
4061 pslic_handle->offset = (ushort) adapter->slic_handle_ix++;
4062 pslic_handle->other_handle = NULL;
4063 pslic_handle->next = NULL;
4065 cmd->pslic_handle = pslic_handle;
4066 cmd->cmd64.hosthandle = pslic_handle->token.handle_token;
4068 cmd->paddrl = phys_addrl;
4069 cmd->paddrh = phys_addrh;
4070 cmd->next_all = prev;
4073 phys_addrl += SLIC_HOSTCMD_SIZE;
4074 cmdaddr += SLIC_HOSTCMD_SIZE;
4076 cmd = (struct slic_hostcmd *)cmdaddr;
4080 cmdq = &adapter->cmdq_all;
4081 cmdq->count += cmdcnt; /* SLIC_CMDQ_CMDSINPAGE; mooktodo */
4082 tail->next_all = cmdq->head;
4083 ASSERT(VALID_ADDRESS(prev));
4085 cmdq = &adapter->cmdq_free;
4086 spin_lock_irqsave(&cmdq->lock.lock, cmdq->lock.flags);
4087 cmdq->count += cmdcnt; /* SLIC_CMDQ_CMDSINPAGE; mooktodo */
4088 tail->next = cmdq->head;
4089 ASSERT(VALID_ADDRESS(prev));
4091 spin_unlock_irqrestore(&cmdq->lock.lock, cmdq->lock.flags);
4094 static struct slic_hostcmd *slic_cmdq_getfree(struct adapter *adapter)
4096 struct slic_cmdqueue *cmdq = &adapter->cmdq_free;
4097 struct slic_hostcmd *cmd = NULL;
4100 spin_lock_irqsave(&cmdq->lock.lock, cmdq->lock.flags);
4104 cmdq->head = cmd->next;
4106 spin_unlock_irqrestore(&cmdq->lock.lock, cmdq->lock.flags);
4108 slic_cmdq_getdone(adapter);
4115 spin_unlock_irqrestore(&cmdq->lock.lock,
4117 pageaddr = slic_cmdqmem_addpage(adapter);
4119 slic_cmdq_addcmdpage(adapter, pageaddr);
4120 goto lock_and_retry;
4127 static void slic_cmdq_getdone(struct adapter *adapter)
4129 struct slic_cmdqueue *done_cmdq = &adapter->cmdq_done;
4130 struct slic_cmdqueue *free_cmdq = &adapter->cmdq_free;
4132 ASSERT(free_cmdq->head == NULL);
4133 spin_lock_irqsave(&done_cmdq->lock.lock, done_cmdq->lock.flags);
4134 ASSERT(VALID_ADDRESS(done_cmdq->head));
4136 free_cmdq->head = done_cmdq->head;
4137 free_cmdq->count = done_cmdq->count;
4138 done_cmdq->head = NULL;
4139 done_cmdq->tail = NULL;
4140 done_cmdq->count = 0;
4141 spin_unlock_irqrestore(&done_cmdq->lock.lock, done_cmdq->lock.flags);
4144 static void slic_cmdq_putdone_irq(struct adapter *adapter,
4145 struct slic_hostcmd *cmd)
4147 struct slic_cmdqueue *cmdq = &adapter->cmdq_done;
4149 spin_lock(&cmdq->lock.lock);
4151 ASSERT(VALID_ADDRESS(cmdq->head));
4152 cmd->next = cmdq->head;
4153 ASSERT(VALID_ADDRESS(cmd));
4156 if ((adapter->xmitq_full) && (cmdq->count > 10))
4157 netif_wake_queue(adapter->netdev);
4158 spin_unlock(&cmdq->lock.lock);
4161 static int slic_rcvqueue_init(struct adapter *adapter)
4164 struct slic_rcvqueue *rcvq = &adapter->rcvqueue;
4166 DBG_MSG("slicoss: %s ENTER adapter[%p]\n", __func__, adapter);
4167 ASSERT(adapter->state == ADAPT_DOWN);
4170 rcvq->size = SLIC_RCVQ_ENTRIES;
4173 i = (SLIC_RCVQ_ENTRIES / SLIC_RCVQ_FILLENTRIES);
4176 count += slic_rcvqueue_fill(adapter);
4179 if (rcvq->count < SLIC_RCVQ_MINENTRIES) {
4180 slic_rcvqueue_free(adapter);
4181 return STATUS_FAILURE;
4183 DBG_MSG("slicoss: %s EXIT adapter[%p]\n", __func__, adapter);
4184 return STATUS_SUCCESS;
4187 static int slic_rcvqueue_reset(struct adapter *adapter)
4189 struct slic_rcvqueue *rcvq = &adapter->rcvqueue;
4191 DBG_MSG("slicoss: %s ENTER adapter[%p]\n", __func__, adapter);
4192 ASSERT(adapter->state == ADAPT_DOWN);
4195 DBG_MSG("slicoss: Nothing to do. rcvq[%p]\n"
4199 rcvq, rcvq->count, rcvq->head, rcvq->tail);
4201 DBG_MSG("slicoss: %s EXIT adapter[%p]\n", __func__, adapter);
4202 return STATUS_SUCCESS;
4205 static void slic_rcvqueue_free(struct adapter *adapter)
4207 struct slic_rcvqueue *rcvq = &adapter->rcvqueue;
4208 struct sk_buff *skb;
4210 while (rcvq->head) {
4212 rcvq->head = rcvq->head->next;
4220 static struct sk_buff *slic_rcvqueue_getnext(struct adapter *adapter)
4222 struct slic_rcvqueue *rcvq = &adapter->rcvqueue;
4223 struct sk_buff *skb;
4224 struct slic_rcvbuf *rcvbuf;
4229 rcvbuf = (struct slic_rcvbuf *)skb->head;
4232 if (rcvbuf->status & IRHDDR_SVALID) {
4233 rcvq->head = rcvq->head->next;
4240 DBG_ERROR("RcvQ Empty!! adapter[%p] rcvq[%p] count[%x]\n",
4241 adapter, rcvq, rcvq->count);
4244 while (rcvq->count < SLIC_RCVQ_FILLTHRESH) {
4245 count = slic_rcvqueue_fill(adapter);
4254 static int slic_rcvqueue_fill(struct adapter *adapter)
4259 struct slic_rcvqueue *rcvq = &adapter->rcvqueue;
4262 while (i < SLIC_RCVQ_FILLENTRIES) {
4263 struct slic_rcvbuf *rcvbuf;
4264 struct sk_buff *skb;
4265 #ifdef KLUDGE_FOR_4GB_BOUNDARY
4268 skb = alloc_skb(SLIC_RCVQ_RCVBUFSIZE, GFP_ATOMIC);
4270 paddr = (void *)pci_map_single(adapter->pcidev,
4272 SLIC_RCVQ_RCVBUFSIZE,
4273 PCI_DMA_FROMDEVICE);
4274 paddrl = SLIC_GET_ADDR_LOW(paddr);
4275 paddrh = SLIC_GET_ADDR_HIGH(paddr);
4277 skb->len = SLIC_RCVBUF_HEADSIZE;
4278 rcvbuf = (struct slic_rcvbuf *)skb->head;
4281 #ifdef KLUDGE_FOR_4GB_BOUNDARY
4284 ("%s: LOW 32bits PHYSICAL ADDRESS == 0 "
4290 " paddrh[%x]\n", __func__, skb,
4291 skb->data, skb->len, paddr, paddrl,
4293 DBG_ERROR(" rcvq->head[%p]\n"
4295 " rcvq->count[%x]\n",
4296 rcvq->head, rcvq->tail, rcvq->count);
4297 DBG_ERROR("SKIP THIS SKB!!!!!!!!\n");
4298 goto retry_rcvqfill;
4303 ("\n\n%s: LOW 32bits PHYSICAL ADDRESS == 0 "
4304 "skb[%p] GIVE TO CARD ANYWAY\n"
4308 " paddrh[%x]\n", __func__, skb,
4309 skb->data, paddr, paddrl, paddrh);
4313 WRITE_REG(adapter->slic_regs->slic_hbar,
4314 (u32) paddrl, DONT_FLUSH);
4316 WRITE_REG64(adapter,
4317 adapter->slic_regs->slic_hbar64,
4319 adapter->slic_regs->slic_addr_upper,
4320 (u32) paddrh, DONT_FLUSH);
4323 rcvq->tail->next = skb;
4331 ("%s slic_rcvqueue_fill could only get [%d] "
4333 adapter->netdev->name, i);
4340 static u32 slic_rcvqueue_reinsert(struct adapter *adapter, struct sk_buff *skb)
4342 struct slic_rcvqueue *rcvq = &adapter->rcvqueue;
4346 struct slic_rcvbuf *rcvbuf = (struct slic_rcvbuf *)skb->head;
4348 ASSERT(skb->len == SLIC_RCVBUF_HEADSIZE);
4350 paddr = (void *)pci_map_single(adapter->pcidev, skb->head,
4351 SLIC_RCVQ_RCVBUFSIZE, PCI_DMA_FROMDEVICE);
4355 paddrl = SLIC_GET_ADDR_LOW(paddr);
4356 paddrh = SLIC_GET_ADDR_HIGH(paddr);
4360 ("%s: LOW 32bits PHYSICAL ADDRESS == 0 skb[%p] PROBLEM\n"
4361 " skbdata[%p]\n" " skblen[%x]\n"
4362 " paddr[%p]\n" " paddrl[%x]\n"
4363 " paddrh[%x]\n", __func__, skb, skb->data,
4364 skb->len, paddr, paddrl, paddrh);
4365 DBG_ERROR(" rcvq->head[%p]\n"
4367 " rcvq->count[%x]\n", rcvq->head, rcvq->tail,
4371 WRITE_REG(adapter->slic_regs->slic_hbar, (u32) paddrl,
4374 WRITE_REG64(adapter,
4375 adapter->slic_regs->slic_hbar64,
4377 adapter->slic_regs->slic_addr_upper,
4378 paddrh, DONT_FLUSH);
4381 rcvq->tail->next = skb;
4389 static int slic_debug_card_show(struct seq_file *seq, void *v)
4393 struct sliccard *card = seq->private;
4394 struct slic_config *config = &card->config;
4395 unsigned char *fru = (unsigned char *)(&card->config.atk_fru);
4396 unsigned char *oemfru = (unsigned char *)(&card->config.OemFru);
4399 seq_printf(seq, "driver_version : %s\n", slic_proc_version);
4400 seq_printf(seq, "Microcode versions: \n");
4401 seq_printf(seq, " Gigabit (gb) : %s %s\n",
4402 MOJAVE_UCODE_VERS_STRING, MOJAVE_UCODE_VERS_DATE);
4403 seq_printf(seq, " Gigabit Receiver : %s %s\n",
4404 GB_RCVUCODE_VERS_STRING, GB_RCVUCODE_VERS_DATE);
4405 seq_printf(seq, "Vendor : %s\n", slic_vendor);
4406 seq_printf(seq, "Product Name : %s\n", slic_product_name);
4408 seq_printf(seq, "VendorId : %4.4X\n",
4410 seq_printf(seq, "DeviceId : %4.4X\n",
4412 seq_printf(seq, "RevisionId : %2.2x\n",
4413 config->RevisionId);
4414 seq_printf(seq, "Bus # : %d\n", card->busnumber);
4415 seq_printf(seq, "Device # : %d\n", card->slotnumber);
4416 seq_printf(seq, "Interfaces : %d\n", card->card_size);
4417 seq_printf(seq, " Initialized : %d\n",
4418 card->adapters_activated);
4419 seq_printf(seq, " Allocated : %d\n",
4420 card->adapters_allocated);
4421 ASSERT(card->card_size <= SLIC_NBR_MACS);
4422 for (i = 0; i < card->card_size; i++) {
4424 " MAC%d : %2.2X %2.2X %2.2X %2.2X %2.2X %2.2X\n",
4425 i, config->macinfo[i].macaddrA[0],
4426 config->macinfo[i].macaddrA[1],
4427 config->macinfo[i].macaddrA[2],
4428 config->macinfo[i].macaddrA[3],
4429 config->macinfo[i].macaddrA[4],
4430 config->macinfo[i].macaddrA[5]);
4432 seq_printf(seq, " IF Init State Duplex/Speed irq\n");
4433 seq_printf(seq, " -------------------------------\n");
4434 for (i = 0; i < card->adapters_allocated; i++) {
4435 struct adapter *adapter;
4437 adapter = card->adapter[i];
4440 " %d %d %s %s %s 0x%X\n",
4441 adapter->physport, adapter->state,
4442 SLIC_LINKSTATE(adapter->linkstate),
4443 SLIC_DUPLEX(adapter->linkduplex),
4444 SLIC_SPEED(adapter->linkspeed),
4445 (uint) adapter->irq);
4448 seq_printf(seq, "Generation # : %4.4X\n", card->gennumber);
4449 seq_printf(seq, "RcvQ max entries : %4.4X\n",
4451 seq_printf(seq, "Ping Status : %8.8X\n",
4453 seq_printf(seq, "Minimum grant : %2.2x\n",
4455 seq_printf(seq, "Maximum Latency : %2.2x\n", config->MaxLat);
4456 seq_printf(seq, "PciStatus : %4.4x\n",
4458 seq_printf(seq, "Debug Device Id : %4.4x\n",
4460 seq_printf(seq, "DRAM ROM Function : %4.4x\n",
4462 seq_printf(seq, "Network interface Pin 1 : %2.2x\n",
4463 config->NetIntPin1);
4464 seq_printf(seq, "Network interface Pin 2 : %2.2x\n",
4465 config->NetIntPin1);
4466 seq_printf(seq, "Network interface Pin 3 : %2.2x\n",
4467 config->NetIntPin1);
4468 seq_printf(seq, "PM capabilities : %4.4X\n",
4470 seq_printf(seq, "Network Clock Controls : %4.4X\n",
4471 config->NwClkCtrls);
4473 switch (config->FruFormat) {
4474 case ATK_FRU_FORMAT:
4477 "Vendor : Alacritech, Inc.\n");
4479 "Assembly # : %c%c%c%c%c%c\n",
4480 fru[0], fru[1], fru[2], fru[3], fru[4],
4483 "Revision # : %c%c\n",
4486 if (config->OEMFruFormat == VENDOR4_FRU_FORMAT) {
4489 "%c%c%c%c%c%c%c%c%c%c%c%c\n",
4490 fru[8], fru[9], fru[10],
4491 fru[11], fru[12], fru[13],
4492 fru[16], fru[17], fru[18],
4493 fru[19], fru[20], fru[21]);
4497 "%c%c%c%c%c%c%c%c%c%c%c%c%c%c\n",
4498 fru[8], fru[9], fru[10],
4499 fru[11], fru[12], fru[13],
4500 fru[14], fru[15], fru[16],
4501 fru[17], fru[18], fru[19],
4510 "Vendor : Alacritech, Inc.\n");
4512 "Serial # : Empty FRU\n");
4517 switch (config->OEMFruFormat) {
4518 case VENDOR1_FRU_FORMAT:
4520 seq_printf(seq, "FRU Information:\n");
4521 seq_printf(seq, " Commodity # : %c\n",
4524 " Assembly # : %c%c%c%c\n",
4525 oemfru[1], oemfru[2], oemfru[3], oemfru[4]);
4527 " Revision # : %c%c\n",
4528 oemfru[5], oemfru[6]);
4530 " Supplier # : %c%c\n",
4531 oemfru[7], oemfru[8]);
4534 oemfru[9], oemfru[10]);
4536 " Sequence # : %c%c%c\n",
4537 oemfru[11], oemfru[12], oemfru[13]);
4541 case VENDOR2_FRU_FORMAT:
4543 seq_printf(seq, "FRU Information:\n");
4546 "%c%c%c%c%c%c%c%c\n",
4547 oemfru[0], oemfru[1], oemfru[2],
4548 oemfru[3], oemfru[4], oemfru[5],
4549 oemfru[6], oemfru[7]);
4551 " Supplier # : %c%c%c%c%c\n",
4552 oemfru[8], oemfru[9], oemfru[10],
4553 oemfru[11], oemfru[12]);
4556 oemfru[13], oemfru[14], oemfru[15]);
4558 " Sequence # : %c%c%c%c\n",
4559 oemfru[16], oemfru[17], oemfru[18],
4564 case VENDOR3_FRU_FORMAT:
4566 seq_printf(seq, "FRU Information:\n");
4569 case VENDOR4_FRU_FORMAT:
4571 seq_printf(seq, "FRU Information:\n");
4574 "%c%c%c%c%c%c%c%c\n",
4575 oemfru[0], oemfru[1], oemfru[2],
4576 oemfru[3], oemfru[4], oemfru[5],
4577 oemfru[6], oemfru[7]);
4580 "%c%c%c%c%c%c%c%c\n",
4581 oemfru[8], oemfru[9], oemfru[10],
4582 oemfru[11], oemfru[12], oemfru[13],
4583 oemfru[14], oemfru[15]);
4586 "%c%c%c%c%c%c%c%c\n",
4587 oemfru[16], oemfru[17], oemfru[18],
4588 oemfru[19], oemfru[20], oemfru[21],
4589 oemfru[22], oemfru[23]);
4601 static int slic_debug_adapter_show(struct seq_file *seq, void *v)
4603 struct adapter *adapter = seq->private;
4605 if ((adapter->netdev) && (adapter->netdev->name)) {
4606 seq_printf(seq, "info: interface : %s\n",
4607 adapter->netdev->name);
4609 seq_printf(seq, "info: status : %s\n",
4610 SLIC_LINKSTATE(adapter->linkstate));
4611 seq_printf(seq, "info: port : %d\n",
4613 seq_printf(seq, "info: speed : %s\n",
4614 SLIC_SPEED(adapter->linkspeed));
4615 seq_printf(seq, "info: duplex : %s\n",
4616 SLIC_DUPLEX(adapter->linkduplex));
4617 seq_printf(seq, "info: irq : 0x%X\n",
4618 (uint) adapter->irq);
4619 seq_printf(seq, "info: Interrupt Agg Delay: %d usec\n",
4620 adapter->card->loadlevel_current);
4621 seq_printf(seq, "info: RcvQ max entries : %4.4X\n",
4623 seq_printf(seq, "info: RcvQ current : %4.4X\n",
4624 adapter->rcvqueue.count);
4625 seq_printf(seq, "rx stats: packets : %8.8lX\n",
4626 adapter->stats.rx_packets);
4627 seq_printf(seq, "rx stats: bytes : %8.8lX\n",
4628 adapter->stats.rx_bytes);
4629 seq_printf(seq, "rx stats: broadcasts : %8.8X\n",
4630 adapter->rcv_broadcasts);
4631 seq_printf(seq, "rx stats: multicasts : %8.8X\n",
4632 adapter->rcv_multicasts);
4633 seq_printf(seq, "rx stats: unicasts : %8.8X\n",
4634 adapter->rcv_unicasts);
4635 seq_printf(seq, "rx stats: errors : %8.8X\n",
4636 (u32) adapter->slic_stats.iface.rcv_errors);
4637 seq_printf(seq, "rx stats: Missed errors : %8.8X\n",
4638 (u32) adapter->slic_stats.iface.rcv_discards);
4639 seq_printf(seq, "rx stats: drops : %8.8X\n",
4640 (u32) adapter->rcv_drops);
4641 seq_printf(seq, "tx stats: packets : %8.8lX\n",
4642 adapter->stats.tx_packets);
4643 seq_printf(seq, "tx stats: bytes : %8.8lX\n",
4644 adapter->stats.tx_bytes);
4645 seq_printf(seq, "tx stats: errors : %8.8X\n",
4646 (u32) adapter->slic_stats.iface.xmt_errors);
4647 seq_printf(seq, "rx stats: multicasts : %8.8lX\n",
4648 adapter->stats.multicast);
4649 seq_printf(seq, "tx stats: collision errors : %8.8X\n",
4650 (u32) adapter->slic_stats.iface.xmit_collisions);
4651 seq_printf(seq, "perf: Max rcv frames/isr : %8.8X\n",
4652 adapter->max_isr_rcvs);
4653 seq_printf(seq, "perf: Rcv interrupt yields : %8.8X\n",
4654 adapter->rcv_interrupt_yields);
4655 seq_printf(seq, "perf: Max xmit complete/isr : %8.8X\n",
4656 adapter->max_isr_xmits);
4657 seq_printf(seq, "perf: error interrupts : %8.8X\n",
4658 adapter->error_interrupts);
4659 seq_printf(seq, "perf: error rmiss interrupts : %8.8X\n",
4660 adapter->error_rmiss_interrupts);
4661 seq_printf(seq, "perf: rcv interrupts : %8.8X\n",
4662 adapter->rcv_interrupts);
4663 seq_printf(seq, "perf: xmit interrupts : %8.8X\n",
4664 adapter->xmit_interrupts);
4665 seq_printf(seq, "perf: link event interrupts : %8.8X\n",
4666 adapter->linkevent_interrupts);
4667 seq_printf(seq, "perf: UPR interrupts : %8.8X\n",
4668 adapter->upr_interrupts);
4669 seq_printf(seq, "perf: interrupt count : %8.8X\n",
4671 seq_printf(seq, "perf: false interrupts : %8.8X\n",
4672 adapter->false_interrupts);
4673 seq_printf(seq, "perf: All register writes : %8.8X\n",
4674 adapter->all_reg_writes);
4675 seq_printf(seq, "perf: ICR register writes : %8.8X\n",
4676 adapter->icr_reg_writes);
4677 seq_printf(seq, "perf: ISR register writes : %8.8X\n",
4678 adapter->isr_reg_writes);
4679 seq_printf(seq, "ifevents: overflow 802 errors : %8.8X\n",
4680 adapter->if_events.oflow802);
4681 seq_printf(seq, "ifevents: transport overflow errors: %8.8X\n",
4682 adapter->if_events.Tprtoflow);
4683 seq_printf(seq, "ifevents: underflow errors : %8.8X\n",
4684 adapter->if_events.uflow802);
4685 seq_printf(seq, "ifevents: receive early : %8.8X\n",
4686 adapter->if_events.rcvearly);
4687 seq_printf(seq, "ifevents: buffer overflows : %8.8X\n",
4688 adapter->if_events.Bufov);
4689 seq_printf(seq, "ifevents: carrier errors : %8.8X\n",
4690 adapter->if_events.Carre);
4691 seq_printf(seq, "ifevents: Long : %8.8X\n",
4692 adapter->if_events.Longe);
4693 seq_printf(seq, "ifevents: invalid preambles : %8.8X\n",
4694 adapter->if_events.Invp);
4695 seq_printf(seq, "ifevents: CRC errors : %8.8X\n",
4696 adapter->if_events.Crc);
4697 seq_printf(seq, "ifevents: dribble nibbles : %8.8X\n",
4698 adapter->if_events.Drbl);
4699 seq_printf(seq, "ifevents: Code violations : %8.8X\n",
4700 adapter->if_events.Code);
4701 seq_printf(seq, "ifevents: TCP checksum errors : %8.8X\n",
4702 adapter->if_events.TpCsum);
4703 seq_printf(seq, "ifevents: TCP header short errors : %8.8X\n",
4704 adapter->if_events.TpHlen);
4705 seq_printf(seq, "ifevents: IP checksum errors : %8.8X\n",
4706 adapter->if_events.IpCsum);
4707 seq_printf(seq, "ifevents: IP frame incompletes : %8.8X\n",
4708 adapter->if_events.IpLen);
4709 seq_printf(seq, "ifevents: IP headers shorts : %8.8X\n",
4710 adapter->if_events.IpHlen);
4714 static int slic_debug_adapter_open(struct inode *inode, struct file *file)
4716 return single_open(file, slic_debug_adapter_show, inode->i_private);
4719 static int slic_debug_card_open(struct inode *inode, struct file *file)
4721 return single_open(file, slic_debug_card_show, inode->i_private);
4724 static const struct file_operations slic_debug_adapter_fops = {
4725 .owner = THIS_MODULE,
4726 .open = slic_debug_adapter_open,
4728 .llseek = seq_lseek,
4729 .release = single_release,
4732 static const struct file_operations slic_debug_card_fops = {
4733 .owner = THIS_MODULE,
4734 .open = slic_debug_card_open,
4736 .llseek = seq_lseek,
4737 .release = single_release,
4740 static void slic_debug_adapter_create(struct adapter *adapter)
4744 struct sliccard *card = adapter->card;
4746 if (!card->debugfs_dir)
4749 sprintf(name, "port%d", adapter->port);
4750 d = debugfs_create_file(name, S_IRUGO,
4751 card->debugfs_dir, adapter,
4752 &slic_debug_adapter_fops);
4753 if (!d || IS_ERR(d))
4754 pr_info(PFX "%s: debugfs create failed\n", name);
4756 adapter->debugfs_entry = d;
4759 static void slic_debug_adapter_destroy(struct adapter *adapter)
4761 if (adapter->debugfs_entry) {
4762 debugfs_remove(adapter->debugfs_entry);
4763 adapter->debugfs_entry = NULL;
4767 static void slic_debug_card_create(struct sliccard *card)
4770 char name[IFNAMSIZ];
4772 snprintf(name, sizeof(name), "slic%d", card->cardnum);
4773 d = debugfs_create_dir(name, slic_debugfs);
4774 if (!d || IS_ERR(d))
4775 pr_info(PFX "%s: debugfs create dir failed\n",
4778 card->debugfs_dir = d;
4779 d = debugfs_create_file("cardinfo", S_IRUGO,
4781 &slic_debug_card_fops);
4782 if (!d || IS_ERR(d))
4783 pr_info(PFX "%s: debugfs create failed\n",
4786 card->debugfs_cardinfo = d;
4790 static void slic_debug_card_destroy(struct sliccard *card)
4794 for (i = 0; i < card->card_size; i++) {
4795 struct adapter *adapter;
4797 adapter = card->adapter[i];
4799 slic_debug_adapter_destroy(adapter);
4801 if (card->debugfs_cardinfo) {
4802 debugfs_remove(card->debugfs_cardinfo);
4803 card->debugfs_cardinfo = NULL;
4805 if (card->debugfs_dir) {
4806 debugfs_remove(card->debugfs_dir);
4807 card->debugfs_dir = NULL;
4811 static void slic_debug_init(void)
4815 ent = debugfs_create_dir("slic", NULL);
4816 if (!ent || IS_ERR(ent)) {
4817 pr_info(PFX "debugfs create directory failed\n");
4824 static void slic_debug_cleanup(void)
4827 debugfs_remove(slic_debugfs);
4828 slic_debugfs = NULL;
4832 /*=============================================================================
4833 =============================================================================
4835 === SLIC DUMP MANAGEMENT SECTION ===
4838 === Dump routines ===
4841 =============================================================================
4842 ============================================================================*/
4844 #if SLIC_DUMP_ENABLED
4848 void *slic_dump_handle; /* thread handle */
4851 * These are the only things you should do on a core-file: use only these
4852 * functions to write out all the necessary info.
4854 static int slic_dump_seek(struct file *SLIChandle, u32 file_offset)
4856 if (SLIChandle->f_pos != file_offset) {
4857 /*DBG_MSG("slic_dump_seek now needed [%x : %x]\n",
4858 (u32)SLIChandle->f_pos, (u32)file_offset); */
4859 if (SLIChandle->f_op->llseek) {
4860 if (SLIChandle->f_op->
4861 llseek(SLIChandle, file_offset, 0) != file_offset)
4864 SLIChandle->f_pos = file_offset;
4870 static int slic_dump_write(struct sliccard *card,
4871 const void *addr, int size, u32 file_offset)
4875 struct file *SLIChandle = card->dumphandle;
4877 #ifdef HISTORICAL /* legacy */
4878 down(&SLIChandle->f_dentry->d_inode->i_sem);
4881 slic_dump_seek(SLIChandle, file_offset);
4884 SLIChandle->f_op->write(SLIChandle, addr, size,
4885 &SLIChandle->f_pos);
4890 card->dumptime_complete = jiffies;
4891 card->dumptime_delta = card->dumptime_complete - card->dumptime_start;
4892 card->dumptime_start = jiffies;
4895 up(&SLIChandle->f_dentry->d_inode->i_sem);
4898 DBG_ERROR("%s: addr[%p] size[%x] result[%x] file_offset[%x]\n",
4899 __func__, addr, size, result, file_offset);
4904 static uint slic_init_dump_thread(struct sliccard *card)
4906 card->dump_task_id = kthread_run(slic_dump_thread, (void *)card, 0);
4908 /* DBG_MSG("create slic_dump_thread dump_pid[%x]\n", card->dump_pid); */
4909 if (IS_ERR(card->dump_task_id)) {
4910 DBG_MSG("create slic_dump_thread FAILED \n");
4911 return STATUS_FAILURE;
4914 return STATUS_SUCCESS;
4917 static int slic_dump_thread(void *context)
4919 struct sliccard *card = (struct sliccard *)context;
4920 struct adapter *adapter;
4921 struct adapter *dump_adapter = NULL;
4922 u32 dump_complete = 0;
4923 u32 delay = SLIC_SECS_TO_JIFFS(PING_TIMER_INTERVAL);
4924 struct slic_regs *pregs;
4926 struct slic_upr *upr, *uprnext;
4931 card->dumpthread_running = 1;
4936 * This thread doesn't need any user-level access,
4937 * so get rid of all our resources
4939 exit_files(current); /* daemonize doesn't do exit_files */
4940 current->files = init_task.files;
4941 atomic_inc(¤t->files->count);
4944 daemonize("%s", "slicmon");
4946 /* Setup a nice name */
4947 strcpy(current->comm, "slicmon");
4949 ("slic_dump_thread[slicmon] daemon is alive card[%p] pid[%x]\n",
4950 card, card->dump_task_id->pid);
4953 * Send me a signal to get me to die (for debugging)
4957 * If card state is not set to up, skip
4959 if (card->state != CARD_UP) {
4960 if (card->adapters_activated)
4966 * Check the results of our last ping.
4969 #ifdef SLIC_FAILURE_DUMP
4970 if (card->pingstatus != ISR_PINGMASK) {
4972 ("\n[slicmon] CARD #%d TIMED OUT - status "
4973 "%x: DUMP THE CARD!\n",
4974 card->cardnum, card->pingstatus);
4979 * Cause a card RESET instead?
4981 if (card->pingstatus != ISR_PINGMASK) {
4982 /* todo. do we want to reset the card in production */
4983 /* DBG_MSG("\n[slicmon] CARD #%d TIMED OUT - "
4984 status %x: RESET THE CARD!\n", card->cardnum,
4985 card->pingstatus); */
4987 ("\n[slicmon] CARD #%d TIMED OUT - status %x: "
4989 card->cardnum, card->pingstatus);
4994 || (card->dump_requested == SLIC_DUMP_REQUESTED)) {
4995 if (card->dump_requested == SLIC_DUMP_REQUESTED) {
4997 ("[slicmon]: Dump card Requested: Card %x\n",
5000 if (card->pingstatus != ISR_PINGMASK) {
5004 if (card->adapter[0]) {
5005 if ((card->adapter[0])->memorylength >=
5007 sizeof(slic_crash_info)) {
5009 p_slic_crash_info crashinfo;
5012 ((char *)card->adapter[0]->
5018 cpuid = crashinfo->cpu_id;
5019 crashpc = crashinfo->crash_pc;
5023 ("[slicmon]: Dump card: Card %x crashed "
5024 "and failed to answer PING. "
5025 "CPUID[%x] PC[%x]\n ",
5026 card->cardnum, cpuid, crashpc);
5029 card->dump_requested = SLIC_DUMP_IN_PROGRESS;
5032 * Set the card state to DOWN and the adapter states
5033 * to RESET.They will check this in SimbaCheckForHang
5034 * and initiate interface reset (which in turn will
5035 * reinitialize the card).
5037 card->state = CARD_DOWN;
5039 for (i = 0; i < card->card_size; i++) {
5040 adapter = card->adapter[i];
5042 slic_if_stop_queue(adapter);
5044 if (adapter->state == ADAPT_UP) {
5045 adapter->state = ADAPT_RESET;
5046 adapter->linkstate = LINK_DOWN;
5048 ("[slicmon]: SLIC Card[%d] "
5049 "Port[%d] adapter[%p] "
5051 (uint) card->cardnum,
5054 #if SLIC_GET_STATS_TIMER_ENABLED
5055 /* free stats timer */
5056 if (adapter->statstimerset) {
5057 adapter->statstimerset = 0;
5058 del_timer(&adapter->statstimer);
5064 for (i = 0; i < card->card_size; i++) {
5065 adapter = card->adapter[i];
5066 if ((adapter) && (adapter->activated)) {
5067 pregs = adapter->slic_regs;
5068 dump_adapter = adapter;
5071 * If the dump status is zero, then
5072 * the utility processor has crashed.
5073 * If this is the case, any pending
5074 * utilityprocessor requests will not
5075 * complete and our dump commands will
5078 * To avoid this we will clear any
5079 * pending utility processor requests
5082 if (!card->pingstatus) {
5084 &adapter->upr_lock.lock,
5085 adapter->upr_lock.flags);
5086 upr = adapter->upr_list;
5088 uprnext = upr->next;
5092 adapter->upr_list = 0;
5093 adapter->upr_busy = 0;
5094 spin_unlock_irqrestore(
5095 &adapter->upr_lock.lock,
5096 adapter->upr_lock.flags);
5099 slic_dump_card(card, FALSE);
5103 if (dump_complete) {
5104 DBG_ERROR("SLIC Dump Complete\n");
5105 /* Only dump the card one time */
5112 ("slic dump completed. "
5113 "Reenable interfaces\n");
5114 slic_card_init(card, dump_adapter);
5117 * Reenable the adapters that were reset
5119 for (i = 0; i < card->card_size; i++) {
5120 adapter = card->adapter[i];
5122 if (adapter->state ==
5126 "Card[%d] Port[%d] adapter[%p] "
5133 adapter->linkstate =
5141 card->dump_requested = SLIC_DUMP_DONE;
5144 /* if pingstatus != ISR_PINGMASK) || dump_requested...ELSE
5145 * We received a valid ping response.
5146 * Clear the Pingstatus field, find a valid adapter
5147 * structure and send another ping.
5149 for (i = 0; i < card->card_size; i++) {
5150 adapter = card->adapter[i];
5151 if (adapter && (adapter->state == ADAPT_UP)) {
5152 card->pingstatus = 0;
5153 slic_upr_request(adapter, SLIC_UPR_PING,
5155 break; /* Only issue one per card */
5160 SLIC_INTERRUPTIBLE_SLEEP_ON_TIMEOUT(card->dump_wq, delay);
5161 } while (!signal_pending(current));
5164 /* DBG_MSG("[slicmon] slic_dump_thread card[%p] pid[%x] ENDING\n",
5165 card, card->dump_pid); */
5166 card->dumpthread_running = 0;
5172 * Read a single byte from our dump index file. This
5173 * value is used as our suffix for our dump path. The
5174 * value is incremented and written back to the file
5176 static unsigned char slic_get_dump_index(char *path)
5178 unsigned char index = 0;
5179 #ifdef SLIC_DUMP_INDEX_SUPPORT
5187 * Open the index file. If one doesn't exist, create it
5189 status = create_file(&FileHandle);
5191 if (status != STATUS_SUCCESS)
5192 return (unsigned char) 0;
5194 status = read_file(FileHandle, &index, 1, &offset);
5198 status = write_file(FileHandle, &index, 1, &offset);
5200 close_file(FileHandle);
5207 static struct file *slic_dump_open_file(struct sliccard *card)
5209 struct file *SLIChandle = NULL;
5210 struct dentry *dentry = NULL;
5211 struct inode *inode = NULL;
5214 card->dumpfile_fs = get_fs();
5218 memset(SLICfile, 0, sizeof(SLICfile));
5219 sprintf(SLICfile, "/var/tmp/slic%d-dump-%d", card->cardnum,
5220 (uint) card->dump_count);
5224 filp_open(SLICfile, O_CREAT | O_RDWR | O_SYNC | O_LARGEFILE, 0666);
5226 DBG_MSG("[slicmon]: Dump Card #%d to file: %s \n", card->cardnum,
5229 /* DBG_MSG("[slicmon] filp_open %s SLIChandle[%p]\n", SLICfile, SLIChandle);*/
5231 if (IS_ERR(SLIChandle))
5234 dentry = SLIChandle->f_dentry;
5235 inode = dentry->d_inode;
5237 /* DBG_MSG("[slicmon] inode[%p] i_nlink[%x] i_mode[%x] i_op[%p] i_fop[%p]\n"
5238 "f_op->write[%p]\n",
5239 inode, inode->i_nlink, inode->i_mode, inode->i_op,
5240 inode->i_fop, SLIChandle->f_op->write); */
5241 if (inode->i_nlink > 1)
5242 goto close_slicdump; /* multiple links - don't dump */
5244 if (!S_ISREG(inode->i_mode))
5245 goto close_slicdump;
5247 if (!inode->i_op || !inode->i_fop)
5248 goto close_slicdump;
5250 if (!SLIChandle->f_op->write)
5251 goto close_slicdump;
5254 * If we got here we have SUCCESSFULLY OPENED the dump file
5256 /* DBG_MSG("opened %s SLIChandle[%p]\n", SLICfile, SLIChandle); */
5260 DBG_MSG("[slicmon] slic_dump_open_file failed close SLIChandle[%p]\n",
5262 filp_close(SLIChandle, NULL);
5265 set_fs(card->dumpfile_fs);
5270 static void slic_dump_close_file(struct sliccard *card)
5273 /* DBG_MSG("[slicmon] slic_dump_CLOSE_file close SLIChandle[%p]\n",
5274 card->dumphandle); */
5276 filp_close(card->dumphandle, NULL);
5278 set_fs(card->dumpfile_fs);
5281 static u32 slic_dump_card(struct sliccard *card, bool resume)
5283 struct adapter *adapter = card->master;
5287 u32 sram_size, dram_size, regs;
5288 struct sliccore_hdr corehdr;
5295 card->dumphandle = slic_dump_open_file(card);
5297 if (card->dumphandle == NULL) {
5298 DBG_MSG("[slicmon] Cant create Dump file - dump failed\n");
5301 if (!card->dumpbuffer) {
5302 DBG_MSG("[slicmon] Insufficient memory for dump\n");
5305 if (!card->cmdbuffer) {
5306 DBG_MSG("[slicmon] Insufficient cmd memory for dump\n");
5311 * Write the file version to the core header.
5313 namestr = slic_proc_version;
5314 for (i = 0; i < (DRIVER_NAME_SIZE - 1); i++, namestr++) {
5317 corehdr.driver_version[i] = *namestr;
5319 corehdr.driver_version[i] = 0;
5321 file_offset = sizeof(struct sliccore_hdr);
5324 * Issue the following debug commands to the SLIC:
5325 * - Halt both receive and transmit
5326 * - Dump receive registers
5327 * - Dump transmit registers
5332 DBG_MSG("slicDump HALT Receive Processor\n");
5333 card->dumptime_start = jiffies;
5335 status = slic_dump_halt(card, PROC_RECEIVE);
5336 if (status != STATUS_SUCCESS) {
5338 ("Cant halt receive sequencer - dump failed status[%x]\n",
5343 DBG_MSG("slicDump HALT Transmit Processor\n");
5344 status = slic_dump_halt(card, PROC_TRANSMIT);
5345 if (status != STATUS_SUCCESS) {
5346 DBG_ERROR("Cant halt transmit sequencer - dump failed\n");
5350 /* Dump receive regs */
5351 status = slic_dump_reg(card, PROC_RECEIVE);
5352 if (status != STATUS_SUCCESS) {
5353 DBG_ERROR("Cant dump receive registers - dump failed\n");
5357 DBG_MSG("slicDump Write Receive REGS len[%x] offset[%x]\n",
5358 (SLIC_NUM_REG * 4), file_offset);
5361 slic_dump_write(card, card->dumpbuffer, SLIC_NUM_REG * 4,
5365 ("Cant write rcv registers to dump file - dump failed\n");
5369 corehdr.RcvRegOff = file_offset;
5370 corehdr.RcvRegsize = SLIC_NUM_REG * 4;
5371 file_offset += SLIC_NUM_REG * 4;
5373 /* Dump transmit regs */
5374 status = slic_dump_reg(card, PROC_TRANSMIT);
5375 if (status != STATUS_SUCCESS) {
5376 DBG_ERROR("Cant dump transmit registers - dump failed\n");
5380 DBG_MSG("slicDump Write XMIT REGS len[%x] offset[%x]\n",
5381 (SLIC_NUM_REG * 4), file_offset);
5384 slic_dump_write(card, card->dumpbuffer, SLIC_NUM_REG * 4,
5388 ("Cant write xmt registers to dump file - dump failed\n");
5392 corehdr.XmtRegOff = file_offset;
5393 corehdr.XmtRegsize = SLIC_NUM_REG * 4;
5394 file_offset += SLIC_NUM_REG * 4;
5396 regs = SLIC_GBMAX_REG;
5398 corehdr.FileRegOff = file_offset;
5399 corehdr.FileRegsize = regs * 4;
5401 for (offset = 0; regs;) {
5402 len = MIN(regs, 16); /* Can only xfr 16 regs at a time */
5404 status = slic_dump_data(card, offset, (ushort) len, DESC_RFILE);
5406 if (status != STATUS_SUCCESS) {
5407 DBG_ERROR("Cant dump register file - dump failed\n");
5411 DBG_MSG("slicDump Write RegisterFile len[%x] offset[%x]\n",
5412 (len * 4), file_offset);
5415 slic_dump_write(card, card->dumpbuffer, len * 4,
5419 ("Cant write register file to dump file - "
5424 file_offset += len * 4;
5429 dram_size = card->config.DramSize * 0x10000;
5431 switch (adapter->devid) {
5432 case SLIC_2GB_DEVICE_ID:
5433 sram_size = SLIC_SRAM_SIZE2GB;
5435 case SLIC_1GB_DEVICE_ID:
5436 sram_size = SLIC_SRAM_SIZE1GB;
5444 corehdr.SramOff = file_offset;
5445 corehdr.Sramsize = sram_size;
5447 for (offset = 0; sram_size;) {
5448 len = MIN(sram_size, DUMP_BUF_SIZE);
5449 status = slic_dump_data(card, offset, (ushort) len, DESC_SRAM);
5450 if (status != STATUS_SUCCESS) {
5452 ("[slicmon] Cant dump SRAM at offset %x - "
5453 "dump failed\n", (uint) offset);
5457 DBG_MSG("[slicmon] slicDump Write SRAM len[%x] offset[%x]\n",
5461 slic_dump_write(card, card->dumpbuffer, len, file_offset);
5464 ("[slicmon] Cant write SRAM to dump file - "
5474 corehdr.DramOff = file_offset;
5475 corehdr.Dramsize = dram_size;
5477 for (offset = 0; dram_size;) {
5478 len = MIN(dram_size, DUMP_BUF_SIZE);
5480 status = slic_dump_data(card, offset, (ushort) len, DESC_DRAM);
5481 if (status != STATUS_SUCCESS) {
5483 ("[slicmon] Cant dump dram at offset %x - "
5484 "dump failed\n", (uint) offset);
5488 DBG_MSG("slicDump Write DRAM len[%x] offset[%x]\n", len,
5492 slic_dump_write(card, card->dumpbuffer, len, file_offset);
5495 ("[slicmon] Cant write DRAM to dump file - "
5505 max_queues = SLIC_MAX_QUEUE;
5507 for (queue = 0; queue < max_queues; queue++) {
5508 u32 *qarray = (u32 *) card->dumpbuffer;
5509 u32 qarray_physl = card->dumpbuffer_physl;
5510 u32 qarray_physh = card->dumpbuffer_physh;
5515 DBG_MSG("[slicmon] Start Dump of QUEUE #0x%x\n", (uint) queue);
5517 for (offset = 0; offset < (DUMP_BUF_SIZE >> 2); offset++) {
5521 status = slic_dump_queue(card,
5523 qarray_physh, queue);
5526 if (status != STATUS_SUCCESS)
5529 if (jiffies > qstart) {
5530 qdelta = jiffies - qstart;
5536 qdelta = qtotal / offset;
5540 /* DBG_MSG(" slicDump Write QUEUE #0x%x len[%x] offset[%x] "
5541 "avgjiffs[%x]\n", queue, (offset*4), file_offset, qdelta); */
5544 slic_dump_write(card, card->dumpbuffer, offset * 4,
5549 ("[slicmon] Cant write QUEUES to dump file - "
5554 corehdr.queues[queue].queueOff = file_offset;
5555 corehdr.queues[queue].queuesize = offset * 4;
5556 file_offset += offset * 4;
5558 /* DBG_MSG(" Reload QUEUE #0x%x elements[%x]\n", (uint)queue, offset);*/
5560 * Fill the queue back up
5562 for (i = 0; i < offset; i++) {
5566 status = slic_dump_load_queue(card, qarray[i], queue);
5567 if (status != STATUS_SUCCESS)
5570 if (jiffies > qstart) {
5571 qdelta = jiffies - qstart;
5577 qdelta = qtotal / offset;
5581 /* DBG_MSG(" Reload DONE avgjiffs[%x]\n", qdelta); */
5586 len = SLIC_GB_CAMAB_SZE * 4;
5587 status = slic_dump_cam(card, 0, len, DUMP_CAM_A);
5588 if (status != STATUS_SUCCESS) {
5589 DBG_ERROR("[slicmon] Can't dump CAM_A - dump failed\n");
5593 result = slic_dump_write(card, card->dumpbuffer, len, file_offset);
5596 ("[slicmon] Can't write CAM_A data to dump file - "
5600 corehdr.CamAMOff = file_offset;
5601 corehdr.CamASize = len;
5604 len = SLIC_GB_CAMCD_SZE * 4;
5605 status = slic_dump_cam(card, 0, len, DUMP_CAM_C);
5607 DBG_ERROR("[slicmon] Can't dump CAM_C - dump failed\n");
5611 result = slic_dump_write(card, card->dumpbuffer, len, file_offset);
5614 ("[slicmon] Can't write CAM_C data to dump file - "
5618 corehdr.CamCMOff = file_offset;
5619 corehdr.CamCSize = len;
5624 * Write out the core header
5627 DBG_MSG("[slicmon] Write CoreHeader len[%x] offset[%x]\n",
5628 (uint) sizeof(struct sliccore_hdr), file_offset);
5631 slic_dump_write(card, &corehdr, sizeof(struct sliccore_hdr),
5633 DBG_MSG("[slicmon] corehdr xoff[%x] xsz[%x]\n"
5634 " roff[%x] rsz[%x] fileoff[%x] filesz[%x]\n"
5635 " sramoff[%x] sramsz[%x], dramoff[%x] dramsz[%x]\n"
5636 " corehdr_offset[%x]\n", corehdr.XmtRegOff,
5637 corehdr.XmtRegsize, corehdr.RcvRegOff, corehdr.RcvRegsize,
5638 corehdr.FileRegOff, corehdr.FileRegsize, corehdr.SramOff,
5639 corehdr.Sramsize, corehdr.DramOff, corehdr.Dramsize,
5640 (uint) sizeof(struct sliccore_hdr));
5641 for (i = 0; i < max_queues; i++) {
5642 DBG_MSG("[slicmon] QUEUE 0x%x offset[%x] size[%x]\n",
5643 (uint) i, corehdr.queues[i].queueOff,
5644 corehdr.queues[i].queuesize);
5648 slic_dump_close_file(card);
5651 DBG_MSG("slicDump RESTART RECEIVE and XMIT PROCESSORS\n\n");
5652 slic_dump_resume(card, PROC_RECEIVE);
5653 slic_dump_resume(card, PROC_TRANSMIT);
5659 static u32 slic_dump_halt(struct sliccard *card, unsigned char proc)
5661 unsigned char *cmd = card->cmdbuffer;
5663 *cmd = COMMAND_BYTE(CMD_HALT, 0, proc);
5665 return slic_dump_send_cmd(card,
5666 card->cmdbuffer_physl,
5667 card->cmdbuffer_physh, 0, 0);
5670 static u32 slic_dump_resume(struct sliccard *card, unsigned char proc)
5672 unsigned char *cmd = card->cmdbuffer;
5674 *cmd = COMMAND_BYTE(CMD_RUN, 0, proc);
5676 return slic_dump_send_cmd(card,
5677 card->cmdbuffer_physl,
5678 card->cmdbuffer_physh, 0, 0);
5681 static u32 slic_dump_reg(struct sliccard *card, unsigned char proc)
5683 struct dump_cmd *dump = (struct dump_cmd *)card->cmdbuffer;
5685 dump->cmd = COMMAND_BYTE(CMD_DUMP, 0, proc);
5686 dump->desc = DESC_REG;
5690 return slic_dump_send_cmd(card,
5691 card->cmdbuffer_physl,
5692 card->cmdbuffer_physh,
5693 card->dumpbuffer_physl,
5694 card->dumpbuffer_physh);
5697 static u32 slic_dump_data(struct sliccard *card,
5698 u32 addr, ushort count, unsigned char desc)
5700 struct dump_cmd *dump = (struct dump_cmd *)card->cmdbuffer;
5702 dump->cmd = COMMAND_BYTE(CMD_DUMP, 0, PROC_RECEIVE);
5704 dump->count = count;
5707 return slic_dump_send_cmd(card,
5708 card->cmdbuffer_physl,
5709 card->cmdbuffer_physh,
5710 card->dumpbuffer_physl,
5711 card->dumpbuffer_physh);
5714 static u32 slic_dump_queue(struct sliccard *card,
5715 u32 addr, u32 buf_physh, u32 queue)
5717 struct dump_cmd *dump = (struct dump_cmd *)card->cmdbuffer;
5719 dump->cmd = COMMAND_BYTE(CMD_DUMP, 0, PROC_RECEIVE);
5720 dump->desc = DESC_QUEUE;
5724 return slic_dump_send_cmd(card,
5725 card->cmdbuffer_physl,
5726 card->cmdbuffer_physh,
5727 addr, card->dumpbuffer_physh);
5730 static u32 slic_dump_load_queue(struct sliccard *card, u32 data,
5733 struct dump_cmd *load = (struct dump_cmd *) card->cmdbuffer;
5735 load->cmd = COMMAND_BYTE(CMD_LOAD, 0, PROC_RECEIVE);
5736 load->desc = DESC_QUEUE;
5737 load->count = (ushort) queue;
5740 return slic_dump_send_cmd(card,
5741 card->cmdbuffer_physl,
5742 card->cmdbuffer_physh, 0, 0);
5745 static u32 slic_dump_cam(struct sliccard *card,
5746 u32 addr, u32 count, unsigned char desc)
5748 struct dump_cmd *dump = (struct dump_cmd *)card->cmdbuffer;
5750 dump->cmd = COMMAND_BYTE(CMD_CAM_OPS, 0, PROC_NONE);
5752 dump->count = count;
5755 return slic_dump_send_cmd(card,
5756 card->cmdbuffer_physl,
5757 card->cmdbuffer_physh,
5758 addr, card->dumpbuffer_physh);
5761 static u32 slic_dump_send_cmd(struct sliccard *card,
5764 u32 buf_physl, u32 buf_physh)
5766 ulong timeout = SLIC_MS_TO_JIFFIES(500); /* 500 msec */
5768 u32 delay = SLIC_MS_TO_JIFFIES(10); /* 10 msec */
5769 struct adapter *adapter = card->master;
5774 * Zero the Dumpstatus field of the adapter structure
5776 card->dumpstatus = 0;
5778 * Issue the dump command via a utility processor request.
5780 * Kludge: We use the Informationbuffer parameter to hold
5781 * the buffer address
5783 slic_upr_request(adapter, SLIC_UPR_DUMP, cmd_physl, cmd_physh,
5784 buf_physl, buf_physh);
5788 * Spin until completion or timeout.
5790 while (!card->dumpstatus) {
5793 if (jiffies > timeout) {
5795 * Complete the timed-out DUMP UPR request.
5797 slic_upr_request_complete(adapter, 0);
5799 ("%s: TIMED OUT num_sleeps[%x] "
5801 __func__, num_sleeps, STATUS_FAILURE);
5803 return STATUS_FAILURE;
5806 SLIC_INTERRUPTIBLE_SLEEP_ON_TIMEOUT(card->dump_wq,
5810 if (card->dumpstatus & ISR_UPCERR) {
5812 * Error (or queue empty)
5814 /* DBG_ERROR("[slicmon] %s: DUMP_STATUS & ISR_UPCERR status[%x]\n",
5815 __func__, STATUS_FAILURE); */
5817 return STATUS_FAILURE;
5818 } else if (card->dumpstatus & ISR_UPCBSY) {
5822 DBG_ERROR("%s: ISR_UPCBUSY attempt[%x]\n", __func__,
5830 return STATUS_SUCCESS;
5835 DBG_ERROR("%s: GAVE UP AFTER SEVERAL ATTEMPTS status[%x]\n",
5836 __func__, STATUS_FAILURE);
5839 * Gave up after several attempts
5841 return STATUS_FAILURE;
5845 /*=============================================================================
5846 =============================================================================
5848 === *** END **** END **** END **** END *** ===
5849 === SLIC DUMP MANAGEMENT SECTION ===
5853 =============================================================================
5854 ============================================================================*/
5856 /******************************************************************************/
5857 /**************** MODULE INITIATION / TERMINATION FUNCTIONS ***************/
5858 /******************************************************************************/
5860 static struct pci_driver slic_driver = {
5862 .id_table = slic_pci_tbl,
5863 .probe = slic_entry_probe,
5864 .remove = slic_entry_remove,
5865 #if SLIC_POWER_MANAGEMENT_ENABLED
5866 .suspend = slicpm_suspend,
5867 .resume = slicpm_resume,
5869 /* .shutdown = slic_shutdown, MOOK_INVESTIGATE */
5872 static int __init slic_module_init(void)
5874 struct pci_device_id *pcidev;
5877 /* DBG_MSG("slicoss: %s ENTER cpu %d\n", __func__, smp_processor_id()); */
5881 if (debug >= 0 && slic_debug != debug)
5882 printk(SLICLEVEL "slicoss: debug level is %d.\n", debug);
5886 pcidev = (struct pci_device_id *)slic_driver.id_table;
5887 /* DBG_MSG("slicoss: %s call pci_module_init jiffies[%lx] cpu #%d\n",
5888 __func__, jiffies, smp_processor_id()); */
5890 ret = pci_register_driver(&slic_driver);
5892 /* DBG_MSG("slicoss: %s EXIT after call pci_module_init jiffies[%lx] "
5893 "cpu #%d status[%x]\n",__func__, jiffies,
5894 smp_processor_id(), ret); */
5899 static void __exit slic_module_cleanup(void)
5901 /* DBG_MSG("slicoss: %s ENTER\n", __func__); */
5902 pci_unregister_driver(&slic_driver);
5903 slic_debug_cleanup();
5904 /* DBG_MSG("slicoss: %s EXIT\n", __func__); */
5907 module_init(slic_module_init);
5908 module_exit(slic_module_cleanup);