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
62 #define SLIC_ASSERT_ENABLED 1
63 #define SLIC_GET_STATS_ENABLED 1
64 #define SLIC_GET_STATS_TIMER_ENABLED 0
65 #define SLIC_PING_TIMER_ENABLED 1
66 #define SLIC_POWER_MANAGEMENT_ENABLED 0
67 #define SLIC_INTERRUPT_PROCESS_LIMIT 1
68 #define LINUX_FREES_ADAPTER_RESOURCES 1
69 #define SLIC_OFFLOAD_IP_CHECKSUM 1
70 #define STATS_TIMER_INTERVAL 2
71 #define PING_TIMER_INTERVAL 1
73 #include <linux/kernel.h>
74 #include <linux/string.h>
75 #include <linux/errno.h>
76 #include <linux/ioport.h>
77 #include <linux/slab.h>
78 #include <linux/interrupt.h>
79 #include <linux/timer.h>
80 #include <linux/pci.h>
81 #include <linux/spinlock.h>
82 #include <linux/init.h>
83 #include <linux/bitops.h>
85 #include <linux/netdevice.h>
86 #include <linux/etherdevice.h>
87 #include <linux/skbuff.h>
88 #include <linux/delay.h>
89 #include <linux/debugfs.h>
90 #include <linux/seq_file.h>
91 #include <linux/kthread.h>
92 #include <linux/module.h>
93 #include <linux/moduleparam.h>
95 #include <linux/firmware.h>
96 #include <linux/types.h>
97 #include <linux/dma-mapping.h>
98 #include <linux/mii.h>
99 #include <linux/if_vlan.h>
100 #include <asm/unaligned.h>
102 #include <linux/ethtool.h>
103 #define SLIC_ETHTOOL_SUPPORT 1
105 #include <linux/uaccess.h>
108 #if SLIC_DUMP_ENABLED
109 #include "slicdump.h"
112 #define SLIC_POWER_MANAGEMENT 0
114 static uint slic_first_init = 1;
115 static char *slic_banner = "Alacritech SLIC Technology(tm) Server "\
116 "and Storage Accelerator (Non-Accelerated)\n";
118 static char *slic_proc_version = "2.0.351 2006/07/14 12:26:00";
119 static char *slic_product_name = "SLIC Technology(tm) Server "\
120 "and Storage Accelerator (Non-Accelerated)";
121 static char *slic_vendor = "Alacritech, Inc.";
123 static int slic_debug = 1;
124 static int debug = -1;
125 static struct net_device *head_netdevice;
127 static struct base_driver slic_global = { {}, 0, 0, 0, 1, NULL, NULL };
128 static int intagg_delay = 100;
129 static u32 dynamic_intagg;
132 static unsigned int rcv_count;
133 static struct dentry *slic_debugfs;
135 #define DRV_NAME "slicoss"
136 #define DRV_VERSION "2.0.1"
137 #define DRV_AUTHOR "Alacritech, Inc. Engineering"
138 #define DRV_DESCRIPTION "Alacritech SLIC Techonology(tm) "\
139 "Non-Accelerated Driver"
140 #define DRV_COPYRIGHT "Copyright 2000-2006 Alacritech, Inc. "\
141 "All rights reserved."
142 #define PFX DRV_NAME " "
144 MODULE_AUTHOR(DRV_AUTHOR);
145 MODULE_DESCRIPTION(DRV_DESCRIPTION);
146 MODULE_LICENSE("Dual BSD/GPL");
148 module_param(dynamic_intagg, int, 0);
149 MODULE_PARM_DESC(dynamic_intagg, "Dynamic Interrupt Aggregation Setting");
150 module_param(intagg_delay, int, 0);
151 MODULE_PARM_DESC(intagg_delay, "uSec Interrupt Aggregation Delay");
153 static struct pci_device_id slic_pci_tbl[] __devinitdata = {
154 {PCI_VENDOR_ID_ALACRITECH,
156 PCI_ANY_ID, PCI_ANY_ID,},
157 {PCI_VENDOR_ID_ALACRITECH,
159 PCI_ANY_ID, PCI_ANY_ID,},
163 MODULE_DEVICE_TABLE(pci, slic_pci_tbl);
165 #define SLIC_GET_SLIC_HANDLE(_adapter, _pslic_handle) \
167 spin_lock_irqsave(&_adapter->handle_lock.lock, \
168 _adapter->handle_lock.flags); \
169 _pslic_handle = _adapter->pfree_slic_handles; \
170 if (_pslic_handle) { \
171 ASSERT(_pslic_handle->type == SLIC_HANDLE_FREE); \
172 _adapter->pfree_slic_handles = _pslic_handle->next; \
174 spin_unlock_irqrestore(&_adapter->handle_lock.lock, \
175 _adapter->handle_lock.flags); \
178 #define SLIC_FREE_SLIC_HANDLE(_adapter, _pslic_handle) \
180 _pslic_handle->type = SLIC_HANDLE_FREE; \
181 spin_lock_irqsave(&_adapter->handle_lock.lock, \
182 _adapter->handle_lock.flags); \
183 _pslic_handle->next = _adapter->pfree_slic_handles; \
184 _adapter->pfree_slic_handles = _pslic_handle; \
185 spin_unlock_irqrestore(&_adapter->handle_lock.lock, \
186 _adapter->handle_lock.flags); \
189 static void slic_debug_init(void);
190 static void slic_debug_cleanup(void);
191 static void slic_debug_adapter_create(struct adapter *adapter);
192 static void slic_debug_adapter_destroy(struct adapter *adapter);
193 static void slic_debug_card_create(struct sliccard *card);
194 static void slic_debug_card_destroy(struct sliccard *card);
196 static inline void slic_reg32_write(void __iomem *reg, u32 value, bool flush)
203 static inline void slic_reg64_write(struct adapter *adapter, void __iomem *reg,
204 u32 value, void __iomem *regh, u32 paddrh,
207 spin_lock_irqsave(&adapter->bit64reglock.lock,
208 adapter->bit64reglock.flags);
209 if (paddrh != adapter->curaddrupper) {
210 adapter->curaddrupper = paddrh;
211 writel(paddrh, regh);
216 spin_unlock_irqrestore(&adapter->bit64reglock.lock,
217 adapter->bit64reglock.flags);
220 static void slic_init_driver(void)
222 if (slic_first_init) {
223 DBG_MSG("slicoss: %s slic_first_init set jiffies[%lx]\n",
226 spin_lock_init(&slic_global.driver_lock.lock);
231 static void slic_dbg_macaddrs(struct adapter *adapter)
233 DBG_MSG(" (%s) curr %2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X\n",
234 adapter->netdev->name, adapter->currmacaddr[0],
235 adapter->currmacaddr[1], adapter->currmacaddr[2],
236 adapter->currmacaddr[3], adapter->currmacaddr[4],
237 adapter->currmacaddr[5]);
238 DBG_MSG(" (%s) mac %2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X\n",
239 adapter->netdev->name, adapter->macaddr[0],
240 adapter->macaddr[1], adapter->macaddr[2],
241 adapter->macaddr[3], adapter->macaddr[4], adapter->macaddr[5]);
245 static void slic_init_adapter(struct net_device *netdev,
246 struct pci_dev *pcidev,
247 const struct pci_device_id *pci_tbl_entry,
248 void __iomem *memaddr, int chip_idx)
251 struct slic_handle *pslic_handle;
252 struct adapter *adapter = (struct adapter *)netdev_priv(netdev);
254 DBG_MSG("slicoss: %s (%s)\n netdev [%p]\n adapter[%p]\n "
255 "pcidev [%p]\n", __func__, netdev->name, netdev, adapter, pcidev);*/
256 /* adapter->pcidev = pcidev;*/
257 adapter->vendid = pci_tbl_entry->vendor;
258 adapter->devid = pci_tbl_entry->device;
259 adapter->subsysid = pci_tbl_entry->subdevice;
260 adapter->busnumber = pcidev->bus->number;
261 adapter->slotnumber = ((pcidev->devfn >> 3) & 0x1F);
262 adapter->functionnumber = (pcidev->devfn & 0x7);
263 adapter->memorylength = pci_resource_len(pcidev, 0);
264 adapter->slic_regs = (__iomem struct slic_regs *)memaddr;
265 adapter->irq = pcidev->irq;
266 /* adapter->netdev = netdev;*/
267 adapter->next_netdevice = head_netdevice;
268 head_netdevice = netdev;
269 adapter->chipid = chip_idx;
270 adapter->port = 0; /*adapter->functionnumber;*/
271 adapter->cardindex = adapter->port;
272 adapter->memorybase = memaddr;
273 spin_lock_init(&adapter->upr_lock.lock);
274 spin_lock_init(&adapter->bit64reglock.lock);
275 spin_lock_init(&adapter->adapter_lock.lock);
276 spin_lock_init(&adapter->reset_lock.lock);
277 spin_lock_init(&adapter->handle_lock.lock);
279 adapter->card_size = 1;
281 Initialize slic_handle array
283 ASSERT(SLIC_CMDQ_MAXCMDS <= 0xFFFF);
285 Start with 1. 0 is an invalid host handle.
287 for (index = 1, pslic_handle = &adapter->slic_handles[1];
288 index < SLIC_CMDQ_MAXCMDS; index++, pslic_handle++) {
290 pslic_handle->token.handle_index = index;
291 pslic_handle->type = SLIC_HANDLE_FREE;
292 pslic_handle->next = adapter->pfree_slic_handles;
293 adapter->pfree_slic_handles = pslic_handle;
296 DBG_MSG(".........\nix[%d] phandle[%p] pfree[%p] next[%p]\n",
297 index, pslic_handle, adapter->pfree_slic_handles, pslic_handle->next);*/
298 adapter->pshmem = (struct slic_shmem *)
299 pci_alloc_consistent(adapter->pcidev,
300 sizeof(struct slic_shmem),
304 DBG_MSG("slicoss: %s (%s)\n pshmem [%p]\n phys_shmem[%p]\n"\
305 "slic_regs [%p]\n", __func__, netdev->name, adapter->pshmem,
306 (void *)adapter->phys_shmem, adapter->slic_regs);
308 ASSERT(adapter->pshmem);
310 memset(adapter->pshmem, 0, sizeof(struct slic_shmem));
315 static int __devinit slic_entry_probe(struct pci_dev *pcidev,
316 const struct pci_device_id *pci_tbl_entry)
318 static int cards_found;
319 static int did_version;
321 struct net_device *netdev;
322 struct adapter *adapter;
323 void __iomem *memmapped_ioaddr = NULL;
325 ulong mmio_start = 0;
327 struct sliccard *card = NULL;
329 DBG_MSG("slicoss: %s 2.6 VERSION ENTER jiffies[%lx] cpu %d\n",
330 __func__, jiffies, smp_processor_id());
332 slic_global.dynamic_intagg = dynamic_intagg;
334 err = pci_enable_device(pcidev);
336 DBG_MSG("Call pci_enable_device(%p) status[%x]\n", pcidev, err);
340 if (slic_debug > 0 && did_version++ == 0) {
342 printk(slic_proc_version);
345 err = pci_set_dma_mask(pcidev, DMA_64BIT_MASK);
347 DBG_MSG("pci_set_dma_mask(DMA_64BIT_MASK) successful\n");
349 err = pci_set_dma_mask(pcidev, DMA_32BIT_MASK);
352 ("No usable DMA configuration, aborting err[%x]\n",
354 goto err_out_disable_pci;
356 DBG_MSG("pci_set_dma_mask(DMA_32BIT_MASK) successful\n");
359 DBG_MSG("Call pci_request_regions\n");
361 err = pci_request_regions(pcidev, DRV_NAME);
363 DBG_MSG("pci_request_regions FAILED err[%x]\n", err);
364 goto err_out_disable_pci;
367 DBG_MSG("call pci_set_master\n");
368 pci_set_master(pcidev);
370 DBG_MSG("call alloc_etherdev\n");
371 netdev = alloc_etherdev(sizeof(struct adapter));
374 goto err_out_exit_slic_probe;
376 DBG_MSG("alloc_etherdev for slic netdev[%p]\n", netdev);
378 SET_NETDEV_DEV(netdev, &pcidev->dev);
380 pci_set_drvdata(pcidev, netdev);
381 adapter = netdev_priv(netdev);
382 adapter->netdev = netdev;
383 adapter->pcidev = pcidev;
385 mmio_start = pci_resource_start(pcidev, 0);
386 mmio_len = pci_resource_len(pcidev, 0);
388 DBG_MSG("slicoss: call ioremap(mmio_start[%lx], mmio_len[%lx])\n",
389 mmio_start, mmio_len);
391 /* memmapped_ioaddr = (u32)ioremap_nocache(mmio_start, mmio_len);*/
392 memmapped_ioaddr = ioremap(mmio_start, mmio_len);
393 DBG_MSG("slicoss: %s MEMMAPPED_IOADDR [%p]\n", __func__,
395 if (!memmapped_ioaddr) {
396 DBG_ERROR("%s cannot remap MMIO region %lx @ %lx\n",
397 __func__, mmio_len, mmio_start);
398 goto err_out_free_netdev;
402 ("slicoss: %s found Alacritech SLICOSS PCI, MMIO at %p, "\
403 "start[%lx] len[%lx], IRQ %d.\n",
404 __func__, memmapped_ioaddr, mmio_start, mmio_len, pcidev->irq);
406 slic_config_pci(pcidev);
410 slic_init_adapter(netdev,
411 pcidev, pci_tbl_entry, memmapped_ioaddr, cards_found);
413 status = slic_card_locate(adapter);
415 DBG_ERROR("%s cannot locate card\n", __func__);
416 goto err_out_free_mmio_region;
419 card = adapter->card;
421 if (!adapter->allocated) {
422 card->adapters_allocated++;
423 adapter->allocated = 1;
426 DBG_MSG("slicoss: %s card: %p\n", __func__,
428 DBG_MSG("slicoss: %s card->adapter[%d] == [%p]\n", __func__,
429 (uint) adapter->port, adapter);
430 DBG_MSG("slicoss: %s card->adapters_allocated [%d]\n", __func__,
431 card->adapters_allocated);
432 DBG_MSG("slicoss: %s card->adapters_activated [%d]\n", __func__,
433 card->adapters_activated);
435 status = slic_card_init(card, adapter);
437 if (status != STATUS_SUCCESS) {
438 card->state = CARD_FAIL;
439 adapter->state = ADAPT_FAIL;
440 adapter->linkstate = LINK_DOWN;
441 DBG_ERROR("slic_card_init FAILED status[%x]\n", status);
443 slic_adapter_set_hwaddr(adapter);
446 netdev->base_addr = (unsigned long)adapter->memorybase;
447 netdev->irq = adapter->irq;
448 netdev->open = slic_entry_open;
449 netdev->stop = slic_entry_halt;
450 netdev->hard_start_xmit = slic_xmit_start;
451 netdev->do_ioctl = slic_ioctl;
452 netdev->set_mac_address = slic_mac_set_address;
453 #if SLIC_GET_STATS_ENABLED
454 netdev->get_stats = slic_get_stats;
456 netdev->set_multicast_list = slic_mcast_set_list;
458 slic_debug_adapter_create(adapter);
460 strcpy(netdev->name, "eth%d");
461 err = register_netdev(netdev);
463 DBG_ERROR("Cannot register net device, aborting.\n");
468 ("slicoss: addr 0x%lx, irq %d, MAC addr "\
469 "%02X:%02X:%02X:%02X:%02X:%02X\n",
470 mmio_start, /*pci_resource_start(pcidev, 0), */ pcidev->irq,
471 netdev->dev_addr[0], netdev->dev_addr[1], netdev->dev_addr[2],
472 netdev->dev_addr[3], netdev->dev_addr[4], netdev->dev_addr[5]);
475 DBG_MSG("slicoss: %s EXIT status[%x] jiffies[%lx] cpu %d\n",
476 __func__, status, jiffies, smp_processor_id());
481 iounmap(memmapped_ioaddr);
482 err_out_free_mmio_region:
483 release_mem_region(mmio_start, mmio_len);
486 err_out_exit_slic_probe:
487 pci_release_regions(pcidev);
488 DBG_ERROR("%s EXIT jiffies[%lx] cpu %d\n", __func__, jiffies,
491 pci_disable_device(pcidev);
495 static int slic_entry_open(struct net_device *dev)
497 struct adapter *adapter = (struct adapter *) netdev_priv(dev);
498 struct sliccard *card = adapter->card;
505 ("slicoss: %s adapter->activated[%d] card->adapters[%x] "\
506 "allocd[%x]\n", __func__, adapter->activated,
507 card->adapters_activated,
508 card->adapters_allocated);
510 ("slicoss: %s (%s): [jiffies[%lx] cpu %d] dev[%p] adapt[%p] "\
511 "port[%d] card[%p]\n",
512 __func__, adapter->netdev->name, jiffies, smp_processor_id(),
513 adapter->netdev, adapter, adapter->port, card);
515 netif_stop_queue(adapter->netdev);
517 spin_lock_irqsave(&slic_global.driver_lock.lock,
518 slic_global.driver_lock.flags);
520 if (!adapter->activated) {
521 card->adapters_activated++;
522 slic_global.num_slic_ports_active++;
523 adapter->activated = 1;
525 status = slic_if_init(adapter);
527 if (status != STATUS_SUCCESS) {
528 if (adapter->activated) {
529 card->adapters_activated--;
530 slic_global.num_slic_ports_active--;
531 adapter->activated = 0;
534 spin_unlock_irqrestore(&slic_global.driver_lock.lock,
535 slic_global.driver_lock.flags);
540 DBG_MSG("slicoss: %s set card->master[%p] adapter[%p]\n", __func__,
541 card->master, adapter);
543 card->master = adapter;
544 #if SLIC_DUMP_ENABLED
545 if (!(card->dumpthread_running))
546 init_waitqueue_head(&card->dump_wq);
550 spin_unlock_irqrestore(&slic_global.driver_lock.lock,
551 slic_global.driver_lock.flags);
554 #if SLIC_DUMP_ENABLED
555 if (!(card->dumpthread_running)) {
556 DBG_MSG("attempt to initialize dump thread\n");
557 status = slic_init_dump_thread(card);
559 Even if the dump thread fails, we will continue at this point
564 return STATUS_SUCCESS;
567 static void __devexit slic_entry_remove(struct pci_dev *pcidev)
569 struct net_device *dev = pci_get_drvdata(pcidev);
572 struct adapter *adapter = (struct adapter *) netdev_priv(dev);
573 struct sliccard *card;
574 struct mcast_address *mcaddr, *mlist;
577 DBG_MSG("slicoss: %s ENTER dev[%p] adapter[%p]\n", __func__, dev,
579 slic_adapter_freeresources(adapter);
580 slic_unmap_mmio_space(adapter);
581 DBG_MSG("slicoss: %s unregister_netdev\n", __func__);
582 unregister_netdev(dev);
584 mmio_start = pci_resource_start(pcidev, 0);
585 mmio_len = pci_resource_len(pcidev, 0);
587 DBG_MSG("slicoss: %s rel_region(0) start[%x] len[%x]\n", __func__,
588 mmio_start, mmio_len);
589 release_mem_region(mmio_start, mmio_len);
591 DBG_MSG("slicoss: %s iounmap dev->base_addr[%x]\n", __func__,
592 (uint) dev->base_addr);
593 iounmap((void __iomem *)dev->base_addr);
594 /* free multicast addresses */
595 mlist = adapter->mcastaddrs;
601 ASSERT(adapter->card);
602 card = adapter->card;
603 ASSERT(card->adapters_allocated);
604 card->adapters_allocated--;
605 adapter->allocated = 0;
607 ("slicoss: %s init[%x] alloc[%x] card[%p] adapter[%p]\n",
608 __func__, card->adapters_activated, card->adapters_allocated,
610 if (!card->adapters_allocated) {
611 struct sliccard *curr_card = slic_global.slic_card;
612 if (curr_card == card) {
613 slic_global.slic_card = card->next;
615 while (curr_card->next != card)
616 curr_card = curr_card->next;
618 curr_card->next = card->next;
620 ASSERT(slic_global.num_slic_cards);
621 slic_global.num_slic_cards--;
622 slic_card_cleanup(card);
624 DBG_MSG("slicoss: %s deallocate device\n", __func__);
626 pci_release_regions(pcidev);
627 DBG_MSG("slicoss: %s EXIT\n", __func__);
630 static int slic_entry_halt(struct net_device *dev)
632 struct adapter *adapter = (struct adapter *)netdev_priv(dev);
633 struct sliccard *card = adapter->card;
634 __iomem struct slic_regs *slic_regs = adapter->slic_regs;
636 spin_lock_irqsave(&slic_global.driver_lock.lock,
637 slic_global.driver_lock.flags);
639 DBG_MSG("slicoss: %s (%s) ENTER\n", __func__, dev->name);
640 DBG_MSG("slicoss: %s (%s) actvtd[%d] alloc[%d] state[%x] adapt[%p]\n",
641 __func__, dev->name, card->adapters_activated,
642 card->adapters_allocated, card->state, adapter);
643 slic_if_stop_queue(adapter);
644 adapter->state = ADAPT_DOWN;
645 adapter->linkstate = LINK_DOWN;
646 adapter->upr_list = NULL;
647 adapter->upr_busy = 0;
648 adapter->devflags_prev = 0;
649 DBG_MSG("slicoss: %s (%s) set adapter[%p] state to ADAPT_DOWN(%d)\n",
650 __func__, dev->name, adapter, adapter->state);
651 ASSERT(card->adapter[adapter->cardindex] == adapter);
652 slic_reg32_write(&slic_regs->slic_icr, ICR_INT_OFF, FLUSH);
653 adapter->all_reg_writes++;
654 adapter->icr_reg_writes++;
655 slic_config_clear(adapter);
656 DBG_MSG("slicoss: %s (%s) dev[%p] adapt[%p] card[%p]\n",
657 __func__, dev->name, dev, adapter, card);
658 if (adapter->activated) {
659 card->adapters_activated--;
660 slic_global.num_slic_ports_active--;
661 adapter->activated = 0;
663 #ifdef AUTOMATIC_RESET
664 slic_reg32_write(&slic_regs->slic_reset_iface, 0, FLUSH);
667 * Reset the adapter's rsp, cmd, and rcv queues
669 slic_cmdq_reset(adapter);
670 slic_rspqueue_reset(adapter);
671 slic_rcvqueue_reset(adapter);
673 #ifdef AUTOMATIC_RESET
674 if (!card->adapters_activated) {
676 #if SLIC_DUMP_ENABLED
677 if (card->dumpthread_running) {
679 DBG_MSG("attempt to terminate dump thread pid[%x]\n",
681 status = kill_proc(card->dump_task_id->pid, SIGKILL, 1);
684 int count = 10 * 100;
685 while (card->dumpthread_running && --count) {
686 current->state = TASK_INTERRUPTIBLE;
692 ("slicmon thread cleanup FAILED \
694 card->dump_task_id->pid);
699 DBG_MSG("slicoss: %s (%s) initiate CARD_HALT\n", __func__,
702 slic_card_init(card, adapter);
706 DBG_MSG("slicoss: %s (%s) EXIT\n", __func__, dev->name);
707 DBG_MSG("slicoss: %s EXIT\n", __func__);
708 spin_unlock_irqrestore(&slic_global.driver_lock.lock,
709 slic_global.driver_lock.flags);
710 return STATUS_SUCCESS;
713 static int slic_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
717 DBG_MSG("slicoss: %s cmd[%x] rq[%p] dev[%p]\n", __func__, cmd, rq, dev);
720 case SIOCSLICSETINTAGG:
722 struct adapter *adapter = (struct adapter *)
727 if (copy_from_user(data, rq->ifr_data, 28)) {
729 ("copy_from_user FAILED getting initial \
735 "%s: set interrupt aggregation to %d\n",
737 slic_intagg_set(adapter, intagg);
740 #ifdef SLIC_USER_REQUEST_DUMP_ENABLED
741 case SIOCSLICDUMPCARD:
743 struct adapter *adapter = netdev_priv(dev);
744 struct sliccard *card;
747 ASSERT(adapter->card)
748 card = adapter->card;
750 DBG_IOCTL("slic_ioctl SIOCSLIC_DUMP_CARD\n");
752 if (card->dump_requested == SLIC_DUMP_DONE) {
754 "SLIC Card dump to be overwritten\n");
755 card->dump_requested = SLIC_DUMP_REQUESTED;
756 } else if ((card->dump_requested == SLIC_DUMP_REQUESTED)
757 || (card->dump_requested ==
758 SLIC_DUMP_IN_PROGRESS)) {
760 "SLIC Card dump Requested but already \
761 in progress... ignore\n");
764 "SLIC Card #%d Dump Requested\n",
766 card->dump_requested = SLIC_DUMP_REQUESTED;
772 #ifdef SLIC_TRACE_DUMP_ENABLED
773 case SIOCSLICTRACEDUMP:
778 DBG_IOCTL("slic_ioctl SIOCSLIC_TRACE_DUMP\n");
780 if (copy_from_user(data, rq->ifr_data, 28)) {
782 ("slic: copy_from_user FAILED getting \
783 initial simba param\n");
788 if (tracemon_request == SLIC_DUMP_DONE) {
790 ("ATK Diagnostic Trace Dump Requested\n");
791 tracemon_request = SLIC_DUMP_REQUESTED;
792 tracemon_request_type = value;
793 tracemon_timestamp = jiffies;
794 } else if ((tracemon_request == SLIC_DUMP_REQUESTED) ||
796 SLIC_DUMP_IN_PROGRESS)) {
798 ("ATK Diagnostic Trace Dump Requested but \
799 already in progress... ignore\n");
802 ("ATK Diagnostic Trace Dump Requested\n");
803 tracemon_request = SLIC_DUMP_REQUESTED;
804 tracemon_request_type = value;
805 tracemon_timestamp = jiffies;
810 #if SLIC_ETHTOOL_SUPPORT
813 struct adapter *adapter = (struct adapter *)
815 struct ethtool_cmd data;
816 struct ethtool_cmd ecmd;
819 /* DBG_MSG("slicoss: %s SIOCETHTOOL\n", __func__); */
820 if (copy_from_user(&ecmd, rq->ifr_data, sizeof(ecmd)))
823 if (ecmd.cmd == ETHTOOL_GSET) {
825 (SUPPORTED_10baseT_Half |
826 SUPPORTED_10baseT_Full |
827 SUPPORTED_100baseT_Half |
828 SUPPORTED_100baseT_Full |
829 SUPPORTED_Autoneg | SUPPORTED_MII);
830 data.port = PORT_MII;
831 data.transceiver = XCVR_INTERNAL;
832 data.phy_address = 0;
833 if (adapter->linkspeed == LINK_100MB)
834 data.speed = SPEED_100;
835 else if (adapter->linkspeed == LINK_10MB)
836 data.speed = SPEED_10;
840 if (adapter->linkduplex == LINK_FULLD)
841 data.duplex = DUPLEX_FULL;
843 data.duplex = DUPLEX_HALF;
845 data.autoneg = AUTONEG_ENABLE;
849 (rq->ifr_data, &data, sizeof(data)))
852 } else if (ecmd.cmd == ETHTOOL_SSET) {
853 if (!capable(CAP_NET_ADMIN))
856 if (adapter->linkspeed == LINK_100MB)
857 data.speed = SPEED_100;
858 else if (adapter->linkspeed == LINK_10MB)
859 data.speed = SPEED_10;
863 if (adapter->linkduplex == LINK_FULLD)
864 data.duplex = DUPLEX_FULL;
866 data.duplex = DUPLEX_HALF;
868 data.autoneg = AUTONEG_ENABLE;
871 if ((ecmd.speed != data.speed) ||
872 (ecmd.duplex != data.duplex)) {
876 if (ecmd.speed == SPEED_10) {
879 ("%s: slic ETHTOOL set \
883 speed = PCR_SPEED_100;
885 ("%s: slic ETHTOOL set \
889 if (ecmd.duplex == DUPLEX_FULL) {
890 duplex = PCR_DUPLEX_FULL;
892 (": duplex==FULL\n");
896 (": duplex==HALF\n");
898 slic_link_config(adapter,
900 slic_link_event_handler(adapter);
907 /* DBG_MSG("slicoss: %s UNSUPPORTED[%x]\n", __func__, cmd); */
912 #define XMIT_FAIL_LINK_STATE 1
913 #define XMIT_FAIL_ZERO_LENGTH 2
914 #define XMIT_FAIL_HOSTCMD_FAIL 3
916 static void slic_xmit_build_request(struct adapter *adapter,
917 struct slic_hostcmd *hcmd, struct sk_buff *skb)
919 struct slic_host64_cmd *ihcmd;
922 ihcmd = &hcmd->cmd64;
924 ihcmd->flags = (adapter->port << IHFLG_IFSHFT);
925 ihcmd->command = IHCMD_XMT_REQ;
926 ihcmd->u.slic_buffers.totlen = skb->len;
927 phys_addr = pci_map_single(adapter->pcidev, skb->data, skb->len,
929 ihcmd->u.slic_buffers.bufs[0].paddrl = SLIC_GET_ADDR_LOW(phys_addr);
930 ihcmd->u.slic_buffers.bufs[0].paddrh = SLIC_GET_ADDR_HIGH(phys_addr);
931 ihcmd->u.slic_buffers.bufs[0].length = skb->len;
932 #if defined(CONFIG_X86_64)
933 hcmd->cmdsize = (u32) ((((u64)&ihcmd->u.slic_buffers.bufs[1] -
934 (u64) hcmd) + 31) >> 5);
935 #elif defined(CONFIG_X86)
936 hcmd->cmdsize = ((((u32) &ihcmd->u.slic_buffers.bufs[1] -
937 (u32) hcmd) + 31) >> 5);
943 #define NORMAL_ETHFRAME 0
945 static int slic_xmit_start(struct sk_buff *skb, struct net_device *dev)
947 struct sliccard *card;
948 struct adapter *adapter = (struct adapter *)netdev_priv(dev);
949 struct slic_hostcmd *hcmd = NULL;
951 u32 skbtype = NORMAL_ETHFRAME;
952 void *offloadcmd = NULL;
954 card = adapter->card;
957 DBG_ERROR("xmit_start (%s) ENTER skb[%p] len[%d] linkstate[%x] state[%x]\n",
958 adapter->netdev->name, skb, skb->len, adapter->linkstate,
961 if ((adapter->linkstate != LINK_UP) ||
962 (adapter->state != ADAPT_UP) || (card->state != CARD_UP)) {
963 status = XMIT_FAIL_LINK_STATE;
966 } else if (skb->len == 0) {
967 status = XMIT_FAIL_ZERO_LENGTH;
971 if (skbtype == NORMAL_ETHFRAME) {
972 hcmd = slic_cmdq_getfree(adapter);
974 adapter->xmitq_full = 1;
975 status = XMIT_FAIL_HOSTCMD_FAIL;
978 ASSERT(hcmd->pslic_handle);
979 ASSERT(hcmd->cmd64.hosthandle ==
980 hcmd->pslic_handle->token.handle_token);
983 hcmd->type = SLIC_CMD_DUMB;
984 if (skbtype == NORMAL_ETHFRAME)
985 slic_xmit_build_request(adapter, hcmd, skb);
987 adapter->stats.tx_packets++;
988 adapter->stats.tx_bytes += skb->len;
991 if (adapter->kill_card) {
992 struct slic_host64_cmd ihcmd;
994 ihcmd = &hcmd->cmd64;
996 ihcmd->flags |= 0x40;
997 adapter->kill_card = 0; /* only do this once */
1000 if (hcmd->paddrh == 0) {
1001 slic_reg32_write(&adapter->slic_regs->slic_cbar,
1002 (hcmd->paddrl | hcmd->cmdsize), DONT_FLUSH);
1004 slic_reg64_write(adapter, &adapter->slic_regs->slic_cbar64,
1005 (hcmd->paddrl | hcmd->cmdsize),
1006 &adapter->slic_regs->slic_addr_upper,
1007 hcmd->paddrh, DONT_FLUSH);
1012 slic_xmit_fail(adapter, skb, offloadcmd, skbtype, status);
1016 static void slic_xmit_fail(struct adapter *adapter,
1017 struct sk_buff *skb,
1018 void *cmd, u32 skbtype, u32 status)
1020 if (adapter->xmitq_full)
1021 slic_if_stop_queue(adapter);
1022 if ((cmd == NULL) && (status <= XMIT_FAIL_HOSTCMD_FAIL)) {
1024 case XMIT_FAIL_LINK_STATE:
1026 ("(%s) reject xmit skb[%p: %x] linkstate[%s] \
1027 adapter[%s:%d] card[%s:%d]\n",
1028 adapter->netdev->name, skb, skb->pkt_type,
1029 SLIC_LINKSTATE(adapter->linkstate),
1030 SLIC_ADAPTER_STATE(adapter->state), adapter->state,
1031 SLIC_CARD_STATE(adapter->card->state),
1032 adapter->card->state);
1034 case XMIT_FAIL_ZERO_LENGTH:
1036 ("xmit_start skb->len == 0 skb[%p] type[%x]!!!! \n",
1037 skb, skb->pkt_type);
1039 case XMIT_FAIL_HOSTCMD_FAIL:
1041 ("xmit_start skb[%p] type[%x] No host commands \
1043 skb, skb->pkt_type);
1050 adapter->stats.tx_dropped++;
1053 static void slic_rcv_handle_error(struct adapter *adapter,
1054 struct slic_rcvbuf *rcvbuf)
1056 struct slic_hddr_wds *hdr = (struct slic_hddr_wds *)rcvbuf->data;
1058 if (adapter->devid != SLIC_1GB_DEVICE_ID) {
1059 if (hdr->frame_status14 & VRHSTAT_802OE)
1060 adapter->if_events.oflow802++;
1061 if (hdr->frame_status14 & VRHSTAT_TPOFLO)
1062 adapter->if_events.Tprtoflow++;
1063 if (hdr->frame_status_b14 & VRHSTATB_802UE)
1064 adapter->if_events.uflow802++;
1065 if (hdr->frame_status_b14 & VRHSTATB_RCVE) {
1066 adapter->if_events.rcvearly++;
1067 adapter->stats.rx_fifo_errors++;
1069 if (hdr->frame_status_b14 & VRHSTATB_BUFF) {
1070 adapter->if_events.Bufov++;
1071 adapter->stats.rx_over_errors++;
1073 if (hdr->frame_status_b14 & VRHSTATB_CARRE) {
1074 adapter->if_events.Carre++;
1075 adapter->stats.tx_carrier_errors++;
1077 if (hdr->frame_status_b14 & VRHSTATB_LONGE)
1078 adapter->if_events.Longe++;
1079 if (hdr->frame_status_b14 & VRHSTATB_PREA)
1080 adapter->if_events.Invp++;
1081 if (hdr->frame_status_b14 & VRHSTATB_CRC) {
1082 adapter->if_events.Crc++;
1083 adapter->stats.rx_crc_errors++;
1085 if (hdr->frame_status_b14 & VRHSTATB_DRBL)
1086 adapter->if_events.Drbl++;
1087 if (hdr->frame_status_b14 & VRHSTATB_CODE)
1088 adapter->if_events.Code++;
1089 if (hdr->frame_status_b14 & VRHSTATB_TPCSUM)
1090 adapter->if_events.TpCsum++;
1091 if (hdr->frame_status_b14 & VRHSTATB_TPHLEN)
1092 adapter->if_events.TpHlen++;
1093 if (hdr->frame_status_b14 & VRHSTATB_IPCSUM)
1094 adapter->if_events.IpCsum++;
1095 if (hdr->frame_status_b14 & VRHSTATB_IPLERR)
1096 adapter->if_events.IpLen++;
1097 if (hdr->frame_status_b14 & VRHSTATB_IPHERR)
1098 adapter->if_events.IpHlen++;
1100 if (hdr->frame_statusGB & VGBSTAT_XPERR) {
1101 u32 xerr = hdr->frame_statusGB >> VGBSTAT_XERRSHFT;
1103 if (xerr == VGBSTAT_XCSERR)
1104 adapter->if_events.TpCsum++;
1105 if (xerr == VGBSTAT_XUFLOW)
1106 adapter->if_events.Tprtoflow++;
1107 if (xerr == VGBSTAT_XHLEN)
1108 adapter->if_events.TpHlen++;
1110 if (hdr->frame_statusGB & VGBSTAT_NETERR) {
1113 frame_statusGB >> VGBSTAT_NERRSHFT) &
1115 if (nerr == VGBSTAT_NCSERR)
1116 adapter->if_events.IpCsum++;
1117 if (nerr == VGBSTAT_NUFLOW)
1118 adapter->if_events.IpLen++;
1119 if (nerr == VGBSTAT_NHLEN)
1120 adapter->if_events.IpHlen++;
1122 if (hdr->frame_statusGB & VGBSTAT_LNKERR) {
1123 u32 lerr = hdr->frame_statusGB & VGBSTAT_LERRMSK;
1125 if (lerr == VGBSTAT_LDEARLY)
1126 adapter->if_events.rcvearly++;
1127 if (lerr == VGBSTAT_LBOFLO)
1128 adapter->if_events.Bufov++;
1129 if (lerr == VGBSTAT_LCODERR)
1130 adapter->if_events.Code++;
1131 if (lerr == VGBSTAT_LDBLNBL)
1132 adapter->if_events.Drbl++;
1133 if (lerr == VGBSTAT_LCRCERR)
1134 adapter->if_events.Crc++;
1135 if (lerr == VGBSTAT_LOFLO)
1136 adapter->if_events.oflow802++;
1137 if (lerr == VGBSTAT_LUFLO)
1138 adapter->if_events.uflow802++;
1144 #define TCP_OFFLOAD_FRAME_PUSHFLAG 0x10000000
1145 #define M_FAST_PATH 0x0040
1147 static void slic_rcv_handler(struct adapter *adapter)
1149 struct sk_buff *skb;
1150 struct slic_rcvbuf *rcvbuf;
1153 while ((skb = slic_rcvqueue_getnext(adapter))) {
1157 rcvbuf = (struct slic_rcvbuf *)skb->head;
1158 adapter->card->events++;
1159 if (rcvbuf->status & IRHDDR_ERR) {
1160 adapter->rx_errors++;
1161 slic_rcv_handle_error(adapter, rcvbuf);
1162 slic_rcvqueue_reinsert(adapter, skb);
1166 if (!slic_mac_filter(adapter, (struct ether_header *)
1170 ("slicoss: %s (%s) drop frame due to mac filter\n",
1171 __func__, adapter->netdev->name);
1173 slic_rcvqueue_reinsert(adapter, skb);
1176 skb_pull(skb, SLIC_RCVBUF_HEADSIZE);
1177 rx_bytes = (rcvbuf->length & IRHDDR_FLEN_MSK);
1178 skb_put(skb, rx_bytes);
1179 adapter->stats.rx_packets++;
1180 adapter->stats.rx_bytes += rx_bytes;
1181 #if SLIC_OFFLOAD_IP_CHECKSUM
1182 skb->ip_summed = CHECKSUM_UNNECESSARY;
1185 skb->dev = adapter->netdev;
1186 skb->protocol = eth_type_trans(skb, skb->dev);
1190 #if SLIC_INTERRUPT_PROCESS_LIMIT
1191 if (frames >= SLIC_RCVQ_MAX_PROCESS_ISR) {
1192 adapter->rcv_interrupt_yields++;
1197 adapter->max_isr_rcvs = max(adapter->max_isr_rcvs, frames);
1200 static void slic_xmit_complete(struct adapter *adapter)
1202 struct slic_hostcmd *hcmd;
1203 struct slic_rspbuf *rspbuf;
1205 struct slic_handle_word slic_handle_word;
1208 rspbuf = slic_rspqueue_getnext(adapter);
1211 adapter->xmit_completes++;
1212 adapter->card->events++;
1214 Get the complete host command buffer
1216 slic_handle_word.handle_token = rspbuf->hosthandle;
1217 ASSERT(slic_handle_word.handle_index);
1218 ASSERT(slic_handle_word.handle_index <= SLIC_CMDQ_MAXCMDS);
1220 (struct slic_hostcmd *)
1221 adapter->slic_handles[slic_handle_word.handle_index].
1223 /* hcmd = (struct slic_hostcmd *) rspbuf->hosthandle; */
1225 ASSERT(hcmd->pslic_handle ==
1226 &adapter->slic_handles[slic_handle_word.handle_index]);
1228 DBG_ERROR("xmit_complete (%s) hcmd[%p] hosthandle[%x]\n",
1229 adapter->netdev->name, hcmd, hcmd->cmd64.hosthandle);
1230 DBG_ERROR(" skb[%p] len %d hcmdtype[%x]\n", hcmd->skb,
1231 hcmd->skb->len, hcmd->type);
1233 if (hcmd->type == SLIC_CMD_DUMB) {
1235 dev_kfree_skb_irq(hcmd->skb);
1236 slic_cmdq_putdone_irq(adapter, hcmd);
1239 rspbuf->hosthandle = 0;
1242 adapter->max_isr_xmits = max(adapter->max_isr_xmits, frames);
1245 static irqreturn_t slic_interrupt(int irq, void *dev_id)
1247 struct net_device *dev = (struct net_device *)dev_id;
1248 struct adapter *adapter = (struct adapter *)netdev_priv(dev);
1251 if ((adapter->pshmem) && (adapter->pshmem->isr)) {
1252 slic_reg32_write(&adapter->slic_regs->slic_icr,
1253 ICR_INT_MASK, FLUSH);
1254 isr = adapter->isrcopy = adapter->pshmem->isr;
1255 adapter->pshmem->isr = 0;
1256 adapter->num_isrs++;
1257 switch (adapter->card->state) {
1259 if (isr & ~ISR_IO) {
1260 if (isr & ISR_ERR) {
1261 adapter->error_interrupts++;
1262 if (isr & ISR_RMISS) {
1267 struct slic_rcvqueue *rcvq =
1271 error_rmiss_interrupts++;
1273 rcv_count = rcvq->count;
1274 pre_count = rcvq->count;
1275 errors = rcvq->errors;
1277 while (rcvq->count <
1278 SLIC_RCVQ_FILLTHRESH) {
1286 ("(%s): [%x] ISR_RMISS \
1287 initial[%x] pre[%x] \
1290 adapter->netdev->name,
1291 isr, rcv_count, pre_count,
1292 errors, rcvq->count);
1293 } else if (isr & ISR_XDROP) {
1295 ("isr & ISR_ERR [%x] \
1300 ("isr & ISR_ERR [%x]\n",
1305 if (isr & ISR_LEVENT) {
1306 /*DBG_MSG("%s (%s) ISR_LEVENT \n",
1307 __func__, adapter->netdev->name);*/
1308 adapter->linkevent_interrupts++;
1309 slic_link_event_handler(adapter);
1312 if ((isr & ISR_UPC) ||
1313 (isr & ISR_UPCERR) || (isr & ISR_UPCBSY)) {
1314 adapter->upr_interrupts++;
1315 slic_upr_request_complete(adapter, isr);
1319 if (isr & ISR_RCV) {
1320 adapter->rcv_interrupts++;
1321 slic_rcv_handler(adapter);
1324 if (isr & ISR_CMD) {
1325 adapter->xmit_interrupts++;
1326 slic_xmit_complete(adapter);
1331 if ((isr & ISR_UPC) ||
1332 (isr & ISR_UPCERR) || (isr & ISR_UPCBSY)) {
1333 adapter->upr_interrupts++;
1334 slic_upr_request_complete(adapter, isr);
1342 adapter->isrcopy = 0;
1343 adapter->all_reg_writes += 2;
1344 adapter->isr_reg_writes++;
1345 slic_reg32_write(&adapter->slic_regs->slic_isr, 0, FLUSH);
1347 adapter->false_interrupts++;
1353 * slic_link_event_handler -
1355 * Initiate a link configuration sequence. The link configuration begins
1356 * by issuing a READ_LINK_STATUS command to the Utility Processor on the
1357 * SLIC. Since the command finishes asynchronously, the slic_upr_comlete
1358 * routine will follow it up witha UP configuration write command, which
1359 * will also complete asynchronously.
1362 static void slic_link_event_handler(struct adapter *adapter)
1365 struct slic_shmem *pshmem;
1367 if (adapter->state != ADAPT_UP) {
1368 /* Adapter is not operational. Ignore. */
1372 pshmem = (struct slic_shmem *)adapter->phys_shmem;
1374 #if defined(CONFIG_X86_64)
1376 DBG_MSG("slic_event_handler pshmem->linkstatus[%x] pshmem[%p]\n \
1377 &linkstatus[%p] &isr[%p]\n", adapter->pshmem->linkstatus, pshmem,
1378 &pshmem->linkstatus, &pshmem->isr);
1380 status = slic_upr_request(adapter,
1382 SLIC_GET_ADDR_LOW(&pshmem->linkstatus),
1383 SLIC_GET_ADDR_HIGH(&pshmem->linkstatus),
1385 #elif defined(CONFIG_X86)
1386 status = slic_upr_request(adapter, SLIC_UPR_RLSR,
1387 (u32) &pshmem->linkstatus, /* no 4GB wrap guaranteed */
1392 ASSERT((status == STATUS_SUCCESS) || (status == STATUS_PENDING));
1395 static void slic_init_cleanup(struct adapter *adapter)
1397 DBG_MSG("slicoss: %s ENTER adapter[%p] ", __func__, adapter);
1398 if (adapter->intrregistered) {
1399 DBG_MSG("FREE_IRQ ");
1400 adapter->intrregistered = 0;
1401 free_irq(adapter->netdev->irq, adapter->netdev);
1404 if (adapter->pshmem) {
1405 DBG_MSG("FREE_SHMEM ");
1406 DBG_MSG("adapter[%p] port %d pshmem[%p] FreeShmem ",
1407 adapter, adapter->port, (void *) adapter->pshmem);
1408 pci_free_consistent(adapter->pcidev,
1409 sizeof(struct slic_shmem),
1410 adapter->pshmem, adapter->phys_shmem);
1411 adapter->pshmem = NULL;
1412 adapter->phys_shmem = (dma_addr_t) NULL;
1414 #if SLIC_GET_STATS_TIMER_ENABLED
1415 if (adapter->statstimerset) {
1416 DBG_MSG("statstimer ");
1417 adapter->statstimerset = 0;
1418 del_timer(&adapter->statstimer);
1421 #if !SLIC_DUMP_ENABLED && SLIC_PING_TIMER_ENABLED
1422 /*#if SLIC_DUMP_ENABLED && SLIC_PING_TIMER_ENABLED*/
1423 if (adapter->pingtimerset) {
1424 DBG_MSG("pingtimer ");
1425 adapter->pingtimerset = 0;
1426 del_timer(&adapter->pingtimer);
1429 slic_rspqueue_free(adapter);
1430 slic_cmdq_free(adapter);
1431 slic_rcvqueue_free(adapter);
1436 #if SLIC_GET_STATS_ENABLED
1437 static struct net_device_stats *slic_get_stats(struct net_device *dev)
1439 struct adapter *adapter = (struct adapter *)netdev_priv(dev);
1440 struct net_device_stats *stats;
1443 stats = &adapter->stats;
1444 stats->collisions = adapter->slic_stats.iface.xmit_collisions;
1445 stats->rx_errors = adapter->slic_stats.iface.rcv_errors;
1446 stats->tx_errors = adapter->slic_stats.iface.xmt_errors;
1447 stats->rx_missed_errors = adapter->slic_stats.iface.rcv_discards;
1448 stats->tx_heartbeat_errors = 0;
1449 stats->tx_aborted_errors = 0;
1450 stats->tx_window_errors = 0;
1451 stats->tx_fifo_errors = 0;
1452 stats->rx_frame_errors = 0;
1453 stats->rx_length_errors = 0;
1454 return &adapter->stats;
1459 * Allocate a mcast_address structure to hold the multicast address.
1462 static int slic_mcast_add_list(struct adapter *adapter, char *address)
1464 struct mcast_address *mcaddr, *mlist;
1467 /* Check to see if it already exists */
1468 mlist = adapter->mcastaddrs;
1470 ETHER_EQ_ADDR(mlist->address, address, equaladdr);
1472 return STATUS_SUCCESS;
1473 mlist = mlist->next;
1476 /* Doesn't already exist. Allocate a structure to hold it */
1477 mcaddr = kmalloc(sizeof(struct mcast_address), GFP_KERNEL);
1481 memcpy(mcaddr->address, address, 6);
1483 mcaddr->next = adapter->mcastaddrs;
1484 adapter->mcastaddrs = mcaddr;
1486 return STATUS_SUCCESS;
1490 * Functions to obtain the CRC corresponding to the destination mac address.
1491 * This is a standard ethernet CRC in that it is a 32-bit, reflected CRC using
1493 * x^32 + x^26 + x^23 + x^22 + x^16 + x^12 + x^11 + x^10 + x^8 + x^7 + x^5 +
1496 * After the CRC for the 6 bytes is generated (but before the value is
1498 * we must then transpose the value and return bits 30-23.
1501 static u32 slic_crc_table[256]; /* Table of CRCs for all possible byte values */
1502 static u32 slic_crc_init; /* Is table initialized */
1505 * Contruct the CRC32 table
1507 static void slic_mcast_init_crc32(void)
1509 u32 c; /* CRC shit reg */
1510 u32 e = 0; /* Poly X-or pattern */
1511 int i; /* counter */
1512 int k; /* byte being shifted into crc */
1514 static int p[] = { 0, 1, 2, 4, 5, 7, 8, 10, 11, 12, 16, 22, 23, 26 };
1516 for (i = 0; i < sizeof(p) / sizeof(int); i++)
1517 e |= 1L << (31 - p[i]);
1519 for (i = 1; i < 256; i++) {
1522 c = c & 1 ? (c >> 1) ^ e : c >> 1;
1523 slic_crc_table[i] = c;
1528 * Return the MAC hast as described above.
1530 static unsigned char slic_mcast_get_mac_hash(char *macaddr)
1535 unsigned char machash = 0;
1537 if (!slic_crc_init) {
1538 slic_mcast_init_crc32();
1542 crc = 0xFFFFFFFF; /* Preload shift register, per crc-32 spec */
1543 for (i = 0, p = macaddr; i < 6; ++p, ++i)
1544 crc = (crc >> 8) ^ slic_crc_table[(crc ^ *p) & 0xFF];
1546 /* Return bits 1-8, transposed */
1547 for (i = 1; i < 9; i++)
1548 machash |= (((crc >> i) & 1) << (8 - i));
1553 static void slic_mcast_set_bit(struct adapter *adapter, char *address)
1555 unsigned char crcpoly;
1557 /* Get the CRC polynomial for the mac address */
1558 crcpoly = slic_mcast_get_mac_hash(address);
1560 /* We only have space on the SLIC for 64 entries. Lop
1561 * off the top two bits. (2^6 = 64)
1565 /* OR in the new bit into our 64 bit mask. */
1566 adapter->mcastmask |= (u64) 1 << crcpoly;
1569 static void slic_mcast_set_list(struct net_device *dev)
1571 struct adapter *adapter = (struct adapter *)netdev_priv(dev);
1572 int status = STATUS_SUCCESS;
1575 struct dev_mc_list *mc_list = dev->mc_list;
1576 int mc_count = dev->mc_count;
1580 for (i = 1; i <= mc_count; i++) {
1581 addresses = (char *) &mc_list->dmi_addr;
1582 if (mc_list->dmi_addrlen == 6) {
1583 status = slic_mcast_add_list(adapter, addresses);
1584 if (status != STATUS_SUCCESS)
1590 slic_mcast_set_bit(adapter, addresses);
1591 mc_list = mc_list->next;
1594 DBG_MSG("%s a->devflags_prev[%x] dev->flags[%x] status[%x]\n",
1595 __func__, adapter->devflags_prev, dev->flags, status);
1596 if (adapter->devflags_prev != dev->flags) {
1597 adapter->macopts = MAC_DIRECTED;
1599 if (dev->flags & IFF_BROADCAST)
1600 adapter->macopts |= MAC_BCAST;
1601 if (dev->flags & IFF_PROMISC)
1602 adapter->macopts |= MAC_PROMISC;
1603 if (dev->flags & IFF_ALLMULTI)
1604 adapter->macopts |= MAC_ALLMCAST;
1605 if (dev->flags & IFF_MULTICAST)
1606 adapter->macopts |= MAC_MCAST;
1608 adapter->devflags_prev = dev->flags;
1609 DBG_MSG("%s call slic_config_set adapter->macopts[%x]\n",
1610 __func__, adapter->macopts);
1611 slic_config_set(adapter, true);
1613 if (status == STATUS_SUCCESS)
1614 slic_mcast_set_mask(adapter);
1619 static void slic_mcast_set_mask(struct adapter *adapter)
1621 __iomem struct slic_regs *slic_regs = adapter->slic_regs;
1623 DBG_MSG("%s ENTER (%s) macopts[%x] mask[%llx]\n", __func__,
1624 adapter->netdev->name, (uint) adapter->macopts,
1625 adapter->mcastmask);
1627 if (adapter->macopts & (MAC_ALLMCAST | MAC_PROMISC)) {
1628 /* Turn on all multicast addresses. We have to do this for
1629 * promiscuous mode as well as ALLMCAST mode. It saves the
1630 * Microcode from having to keep state about the MAC
1633 /* DBG_MSG("slicoss: %s macopts = MAC_ALLMCAST | MAC_PROMISC\n\
1634 SLUT MODE!!!\n",__func__); */
1635 slic_reg32_write(&slic_regs->slic_mcastlow, 0xFFFFFFFF, FLUSH);
1636 slic_reg32_write(&slic_regs->slic_mcasthigh, 0xFFFFFFFF,
1638 /* DBG_MSG("%s (%s) WRITE to slic_regs slic_mcastlow&high 0xFFFFFFFF\n",
1639 _func__, adapter->netdev->name); */
1641 /* Commit our multicast mast to the SLIC by writing to the
1642 * multicast address mask registers
1644 DBG_MSG("%s (%s) WRITE mcastlow[%x] mcasthigh[%x]\n",
1645 __func__, adapter->netdev->name,
1646 ((ulong) (adapter->mcastmask & 0xFFFFFFFF)),
1647 ((ulong) ((adapter->mcastmask >> 32) & 0xFFFFFFFF)));
1649 slic_reg32_write(&slic_regs->slic_mcastlow,
1650 (u32)(adapter->mcastmask & 0xFFFFFFFF), FLUSH);
1651 slic_reg32_write(&slic_regs->slic_mcasthigh,
1652 (u32)((adapter->mcastmask >> 32) & 0xFFFFFFFF), FLUSH);
1656 static void slic_timer_ping(ulong dev)
1658 struct adapter *adapter;
1659 struct sliccard *card;
1662 adapter = netdev_priv((struct net_device *)dev);
1664 card = adapter->card;
1666 #if !SLIC_DUMP_ENABLED
1667 /*#if SLIC_DUMP_ENABLED*/
1668 if ((adapter->state == ADAPT_UP) && (card->state == CARD_UP)) {
1671 if (card->pingstatus != ISR_PINGMASK) {
1672 if (errormsg++ < 5) {
1674 ("%s (%s) CARD HAS CRASHED PING_status == \
1676 __func__, adapter->netdev->name,
1677 card->pingstatus, errormsg);
1679 /* ASSERT(card->pingstatus == ISR_PINGMASK); */
1681 if (goodmsg++ < 5) {
1683 ("slicoss: %s (%s) PING_status == %x \
1684 GOOD!!!!!!!! msg# %d\n",
1685 __func__, adapter->netdev->name,
1686 card->pingstatus, errormsg);
1689 card->pingstatus = 0;
1690 status = slic_upr_request(adapter, SLIC_UPR_PING, 0, 0, 0, 0);
1692 ASSERT(status == 0);
1694 DBG_MSG("slicoss %s (%s) adapter[%p] NOT UP!!!!\n",
1695 __func__, adapter->netdev->name, adapter);
1698 adapter->pingtimer.expires = jiffies + (PING_TIMER_INTERVAL * HZ);
1699 add_timer(&adapter->pingtimer);
1702 static void slic_if_stop_queue(struct adapter *adapter)
1704 netif_stop_queue(adapter->netdev);
1707 static void slic_if_start_queue(struct adapter *adapter)
1709 netif_start_queue(adapter->netdev);
1715 * Perform initialization of our slic interface.
1718 static int slic_if_init(struct adapter *adapter)
1720 struct sliccard *card = adapter->card;
1721 struct net_device *dev = adapter->netdev;
1722 __iomem struct slic_regs *slic_regs = adapter->slic_regs;
1723 struct slic_shmem *pshmem;
1727 DBG_MSG("slicoss: %s (%s) ENTER states[%d:%d:%d:%d] flags[%x]\n",
1728 __func__, adapter->netdev->name,
1729 adapter->queues_initialized, adapter->state, adapter->linkstate,
1730 card->state, dev->flags);
1732 /* adapter should be down at this point */
1733 if (adapter->state != ADAPT_DOWN) {
1734 DBG_ERROR("slic_if_init adapter->state != ADAPT_DOWN\n");
1737 ASSERT(adapter->linkstate == LINK_DOWN);
1739 adapter->devflags_prev = dev->flags;
1740 adapter->macopts = MAC_DIRECTED;
1742 DBG_MSG("slicoss: %s (%s) Set MAC options: ", __func__,
1743 adapter->netdev->name);
1744 if (dev->flags & IFF_BROADCAST) {
1745 adapter->macopts |= MAC_BCAST;
1748 if (dev->flags & IFF_PROMISC) {
1749 adapter->macopts |= MAC_PROMISC;
1750 DBG_MSG("PROMISC ");
1752 if (dev->flags & IFF_ALLMULTI) {
1753 adapter->macopts |= MAC_ALLMCAST;
1754 DBG_MSG("ALL_MCAST ");
1756 if (dev->flags & IFF_MULTICAST) {
1757 adapter->macopts |= MAC_MCAST;
1762 status = slic_adapter_allocresources(adapter);
1763 if (status != STATUS_SUCCESS) {
1765 ("slic_if_init: slic_adapter_allocresources FAILED %x\n",
1767 slic_adapter_freeresources(adapter);
1771 if (!adapter->queues_initialized) {
1772 DBG_MSG("slicoss: %s call slic_rspqueue_init\n", __func__);
1773 if (slic_rspqueue_init(adapter))
1776 ("slicoss: %s call slic_cmdq_init adapter[%p] port %d \n",
1777 __func__, adapter, adapter->port);
1778 if (slic_cmdq_init(adapter))
1781 ("slicoss: %s call slic_rcvqueue_init adapter[%p] \
1782 port %d \n", __func__, adapter, adapter->port);
1783 if (slic_rcvqueue_init(adapter))
1785 adapter->queues_initialized = 1;
1787 DBG_MSG("slicoss: %s disable interrupts(slic)\n", __func__);
1789 slic_reg32_write(&slic_regs->slic_icr, ICR_INT_OFF, FLUSH);
1792 if (!adapter->isp_initialized) {
1793 pshmem = (struct slic_shmem *)adapter->phys_shmem;
1795 spin_lock_irqsave(&adapter->bit64reglock.lock,
1796 adapter->bit64reglock.flags);
1798 #if defined(CONFIG_X86_64)
1799 slic_reg32_write(&slic_regs->slic_addr_upper,
1800 SLIC_GET_ADDR_HIGH(&pshmem->isr), DONT_FLUSH);
1801 slic_reg32_write(&slic_regs->slic_isp,
1802 SLIC_GET_ADDR_LOW(&pshmem->isr), FLUSH);
1803 #elif defined(CONFIG_X86)
1804 slic_reg32_write(&slic_regs->slic_addr_upper, 0, DONT_FLUSH);
1805 slic_reg32_write(&slic_regs->slic_isp, (u32)&pshmem->isr, FLUSH);
1809 spin_unlock_irqrestore(&adapter->bit64reglock.lock,
1810 adapter->bit64reglock.flags);
1811 adapter->isp_initialized = 1;
1814 adapter->state = ADAPT_UP;
1815 if (!card->loadtimerset) {
1816 init_timer(&card->loadtimer);
1817 card->loadtimer.expires =
1818 jiffies + (SLIC_LOADTIMER_PERIOD * HZ);
1819 card->loadtimer.data = (ulong) card;
1820 card->loadtimer.function = &slic_timer_load_check;
1821 add_timer(&card->loadtimer);
1823 card->loadtimerset = 1;
1825 #if SLIC_GET_STATS_TIMER_ENABLED
1826 if (!adapter->statstimerset) {
1827 DBG_MSG("slicoss: %s start getstats_timer(slic)\n",
1829 init_timer(&adapter->statstimer);
1830 adapter->statstimer.expires =
1831 jiffies + (STATS_TIMER_INTERVAL * HZ);
1832 adapter->statstimer.data = (ulong) adapter->netdev;
1833 adapter->statstimer.function = &slic_timer_get_stats;
1834 add_timer(&adapter->statstimer);
1835 adapter->statstimerset = 1;
1838 #if !SLIC_DUMP_ENABLED && SLIC_PING_TIMER_ENABLED
1839 /*#if SLIC_DUMP_ENABLED && SLIC_PING_TIMER_ENABLED*/
1840 if (!adapter->pingtimerset) {
1841 DBG_MSG("slicoss: %s start card_ping_timer(slic)\n",
1843 init_timer(&adapter->pingtimer);
1844 adapter->pingtimer.expires =
1845 jiffies + (PING_TIMER_INTERVAL * HZ);
1846 adapter->pingtimer.data = (ulong) dev;
1847 adapter->pingtimer.function = &slic_timer_ping;
1848 add_timer(&adapter->pingtimer);
1849 adapter->pingtimerset = 1;
1850 adapter->card->pingstatus = ISR_PINGMASK;
1855 * clear any pending events, then enable interrupts
1857 DBG_MSG("slicoss: %s ENABLE interrupts(slic)\n", __func__);
1858 adapter->isrcopy = 0;
1859 adapter->pshmem->isr = 0;
1860 slic_reg32_write(&slic_regs->slic_isr, 0, FLUSH);
1861 slic_reg32_write(&slic_regs->slic_icr, ICR_INT_ON, FLUSH);
1863 DBG_MSG("slicoss: %s call slic_link_config(slic)\n", __func__);
1864 slic_link_config(adapter, LINK_AUTOSPEED, LINK_AUTOD);
1865 slic_link_event_handler(adapter);
1867 DBG_MSG("slicoss: %s EXIT\n", __func__);
1868 return STATUS_SUCCESS;
1871 static void slic_unmap_mmio_space(struct adapter *adapter)
1873 #if LINUX_FREES_ADAPTER_RESOURCES
1874 if (adapter->slic_regs)
1875 iounmap(adapter->slic_regs);
1876 adapter->slic_regs = NULL;
1880 static int slic_adapter_allocresources(struct adapter *adapter)
1882 if (!adapter->intrregistered) {
1886 ("slicoss: %s AllocAdaptRsrcs adapter[%p] shmem[%p] \
1887 phys_shmem[%p] dev->irq[%x] %x\n",
1888 __func__, adapter, adapter->pshmem,
1889 (void *)adapter->phys_shmem, adapter->netdev->irq,
1892 spin_unlock_irqrestore(&slic_global.driver_lock.lock,
1893 slic_global.driver_lock.flags);
1895 retval = request_irq(adapter->netdev->irq,
1898 adapter->netdev->name, adapter->netdev);
1900 spin_lock_irqsave(&slic_global.driver_lock.lock,
1901 slic_global.driver_lock.flags);
1904 DBG_ERROR("slicoss: request_irq (%s) FAILED [%x]\n",
1905 adapter->netdev->name, retval);
1908 adapter->intrregistered = 1;
1910 ("slicoss: %s AllocAdaptRsrcs adapter[%p] shmem[%p] \
1911 pshmem[%p] dev->irq[%x]\n",
1912 __func__, adapter, adapter->pshmem,
1913 (void *)adapter->pshmem, adapter->netdev->irq);
1915 return STATUS_SUCCESS;
1918 static void slic_config_pci(struct pci_dev *pcidev)
1923 pci_read_config_word(pcidev, PCI_COMMAND, &pci_command);
1924 DBG_MSG("slicoss: %s PCI command[%4.4x]\n", __func__, pci_command);
1926 new_command = pci_command | PCI_COMMAND_MASTER
1927 | PCI_COMMAND_MEMORY
1928 | PCI_COMMAND_INVALIDATE
1929 | PCI_COMMAND_PARITY | PCI_COMMAND_SERR | PCI_COMMAND_FAST_BACK;
1930 if (pci_command != new_command) {
1931 DBG_MSG("%s -- Updating PCI COMMAND register %4.4x->%4.4x.\n",
1932 __func__, pci_command, new_command);
1933 pci_write_config_word(pcidev, PCI_COMMAND, new_command);
1937 static void slic_adapter_freeresources(struct adapter *adapter)
1939 DBG_MSG("slicoss: %s ENTER adapter[%p]\n", __func__, adapter);
1940 slic_init_cleanup(adapter);
1941 memset(&adapter->stats, 0, sizeof(struct net_device_stats));
1942 adapter->error_interrupts = 0;
1943 adapter->rcv_interrupts = 0;
1944 adapter->xmit_interrupts = 0;
1945 adapter->linkevent_interrupts = 0;
1946 adapter->upr_interrupts = 0;
1947 adapter->num_isrs = 0;
1948 adapter->xmit_completes = 0;
1949 adapter->rcv_broadcasts = 0;
1950 adapter->rcv_multicasts = 0;
1951 adapter->rcv_unicasts = 0;
1952 DBG_MSG("slicoss: %s EXIT\n", __func__);
1958 * Write phy control to configure link duplex/speed
1961 static void slic_link_config(struct adapter *adapter,
1962 u32 linkspeed, u32 linkduplex)
1971 if (adapter->state != ADAPT_UP) {
1973 ("%s (%s) ADAPT Not up yet, Return! speed[%x] duplex[%x]\n",
1974 __func__, adapter->netdev->name, linkspeed,
1978 DBG_MSG("slicoss: %s (%s) slic_link_config: speed[%x] duplex[%x]\n",
1979 __func__, adapter->netdev->name, linkspeed, linkduplex);
1981 ASSERT((adapter->devid == SLIC_1GB_DEVICE_ID)
1982 || (adapter->devid == SLIC_2GB_DEVICE_ID));
1984 if (linkspeed > LINK_1000MB)
1985 linkspeed = LINK_AUTOSPEED;
1986 if (linkduplex > LINK_AUTOD)
1987 linkduplex = LINK_AUTOD;
1989 wphy = &adapter->slic_regs->slic_wphy;
1991 if ((linkspeed == LINK_AUTOSPEED) || (linkspeed == LINK_1000MB)) {
1992 if (adapter->flags & ADAPT_FLAGS_FIBERMEDIA) {
1993 /* We've got a fiber gigabit interface, and register
1994 * 4 is different in fiber mode than in copper mode
1997 /* advertise FD only @1000 Mb */
1998 phy_advreg = (MIICR_REG_4 | (PAR_ADV1000XFD));
1999 /* enable PAUSE frames */
2000 phy_advreg |= PAR_ASYMPAUSE_FIBER;
2001 slic_reg32_write(wphy, phy_advreg, FLUSH);
2003 if (linkspeed == LINK_AUTOSPEED) {
2004 /* reset phy, enable auto-neg */
2007 (PCR_RESET | PCR_AUTONEG |
2009 slic_reg32_write(wphy, phy_config, FLUSH);
2010 } else { /* forced 1000 Mb FD*/
2011 /* power down phy to break link
2012 this may not work) */
2013 phy_config = (MIICR_REG_PCR | PCR_POWERDOWN);
2014 slic_reg32_write(wphy, phy_config, FLUSH);
2015 /* wait, Marvell says 1 sec,
2016 try to get away with 10 ms */
2019 /* disable auto-neg, set speed/duplex,
2020 soft reset phy, powerup */
2023 (PCR_RESET | PCR_SPEED_1000 |
2025 slic_reg32_write(wphy, phy_config, FLUSH);
2027 } else { /* copper gigabit */
2029 /* Auto-Negotiate or 1000 Mb must be auto negotiated
2030 * We've got a copper gigabit interface, and
2031 * register 4 is different in copper mode than
2034 if (linkspeed == LINK_AUTOSPEED) {
2035 /* advertise 10/100 Mb modes */
2038 (PAR_ADV100FD | PAR_ADV100HD | PAR_ADV10FD
2041 /* linkspeed == LINK_1000MB -
2042 don't advertise 10/100 Mb modes */
2043 phy_advreg = MIICR_REG_4;
2045 /* enable PAUSE frames */
2046 phy_advreg |= PAR_ASYMPAUSE;
2047 /* required by the Cicada PHY */
2048 phy_advreg |= PAR_802_3;
2049 slic_reg32_write(wphy, phy_advreg, FLUSH);
2050 /* advertise FD only @1000 Mb */
2051 phy_gctlreg = (MIICR_REG_9 | (PGC_ADV1000FD));
2052 slic_reg32_write(wphy, phy_gctlreg, FLUSH);
2054 if (adapter->subsysid != SLIC_1GB_CICADA_SUBSYS_ID) {
2056 enable auto crossover */
2058 (MIICR_REG_16 | (MRV_REG16_XOVERON));
2059 slic_reg32_write(wphy, phy_config, FLUSH);
2061 /* reset phy, enable auto-neg */
2064 (PCR_RESET | PCR_AUTONEG |
2066 slic_reg32_write(wphy, phy_config, FLUSH);
2067 } else { /* it's a Cicada PHY */
2068 /* enable and restart auto-neg (don't reset) */
2071 (PCR_AUTONEG | PCR_AUTONEG_RST));
2072 slic_reg32_write(wphy, phy_config, FLUSH);
2077 if (linkspeed == LINK_10MB)
2080 speed = PCR_SPEED_100;
2081 if (linkduplex == LINK_HALFD)
2084 duplex = PCR_DUPLEX_FULL;
2086 if (adapter->subsysid != SLIC_1GB_CICADA_SUBSYS_ID) {
2088 disable auto crossover */
2089 phy_config = (MIICR_REG_16 | (MRV_REG16_XOVEROFF));
2090 slic_reg32_write(wphy, phy_config, FLUSH);
2093 /* power down phy to break link (this may not work) */
2094 phy_config = (MIICR_REG_PCR | (PCR_POWERDOWN | speed | duplex));
2095 slic_reg32_write(wphy, phy_config, FLUSH);
2097 /* wait, Marvell says 1 sec, try to get away with 10 ms */
2100 if (adapter->subsysid != SLIC_1GB_CICADA_SUBSYS_ID) {
2102 disable auto-neg, set speed,
2103 soft reset phy, powerup */
2105 (MIICR_REG_PCR | (PCR_RESET | speed | duplex));
2106 slic_reg32_write(wphy, phy_config, FLUSH);
2107 } else { /* it's a Cicada PHY */
2108 /* disable auto-neg, set speed, powerup */
2109 phy_config = (MIICR_REG_PCR | (speed | duplex));
2110 slic_reg32_write(wphy, phy_config, FLUSH);
2115 ("slicoss: %s (%s) EXIT slic_link_config : state[%d] \
2116 phy_config[%x]\n", __func__, adapter->netdev->name, adapter->state,
2120 static void slic_card_cleanup(struct sliccard *card)
2122 DBG_MSG("slicoss: %s ENTER\n", __func__);
2124 #if SLIC_DUMP_ENABLED
2125 if (card->dumpbuffer) {
2126 card->dumpbuffer_phys = 0;
2127 card->dumpbuffer_physl = 0;
2128 card->dumpbuffer_physh = 0;
2129 kfree(card->dumpbuffer);
2130 card->dumpbuffer = NULL;
2132 if (card->cmdbuffer) {
2133 card->cmdbuffer_phys = 0;
2134 card->cmdbuffer_physl = 0;
2135 card->cmdbuffer_physh = 0;
2136 kfree(card->cmdbuffer);
2137 card->cmdbuffer = NULL;
2141 if (card->loadtimerset) {
2142 card->loadtimerset = 0;
2143 del_timer(&card->loadtimer);
2146 slic_debug_card_destroy(card);
2149 DBG_MSG("slicoss: %s EXIT\n", __func__);
2152 static int slic_card_download_gbrcv(struct adapter *adapter)
2154 const struct firmware *fw;
2155 const char *file = "";
2157 __iomem struct slic_regs *slic_regs = adapter->slic_regs;
2161 u32 rcvucodelen = 0;
2163 switch (adapter->devid) {
2164 case SLIC_2GB_DEVICE_ID:
2165 file = "slicoss/oasisrcvucode.sys";
2167 case SLIC_1GB_DEVICE_ID:
2168 file = "slicoss/gbrcvucode.sys";
2175 ret = request_firmware(&fw, file, &adapter->pcidev->dev);
2177 printk(KERN_ERR "SLICOSS: Failed to load firmware %s\n", file);
2181 rcvucodelen = *(u32 *)(fw->data + index);
2183 switch (adapter->devid) {
2184 case SLIC_2GB_DEVICE_ID:
2185 if (rcvucodelen != OasisRcvUCodeLen)
2188 case SLIC_1GB_DEVICE_ID:
2189 if (rcvucodelen != GBRcvUCodeLen)
2196 /* start download */
2197 slic_reg32_write(&slic_regs->slic_rcv_wcs, SLIC_RCVWCS_BEGIN, FLUSH);
2198 /* download the rcv sequencer ucode */
2199 for (codeaddr = 0; codeaddr < rcvucodelen; codeaddr++) {
2200 /* write out instruction address */
2201 slic_reg32_write(&slic_regs->slic_rcv_wcs, codeaddr, FLUSH);
2203 instruction = *(u32 *)(fw->data + index);
2205 /* write out the instruction data low addr */
2206 slic_reg32_write(&slic_regs->slic_rcv_wcs, instruction, FLUSH);
2208 instruction = *(u8 *)(fw->data + index);
2210 /* write out the instruction data high addr */
2211 slic_reg32_write(&slic_regs->slic_rcv_wcs, (u8)instruction,
2215 /* download finished */
2216 release_firmware(fw);
2217 slic_reg32_write(&slic_regs->slic_rcv_wcs, SLIC_RCVWCS_FINISH, FLUSH);
2221 static int slic_card_download(struct adapter *adapter)
2223 const struct firmware *fw;
2224 const char *file = "";
2227 int thissectionsize;
2229 __iomem struct slic_regs *slic_regs = adapter->slic_regs;
2237 int ucode_start, index = 0;
2239 /* DBG_MSG ("slicoss: %s (%s) adapter[%p] card[%p] devid[%x] \
2240 jiffies[%lx] cpu %d\n", __func__, adapter->netdev->name, adapter,
2241 adapter->card, adapter->devid,jiffies, smp_processor_id()); */
2243 switch (adapter->devid) {
2244 case SLIC_2GB_DEVICE_ID:
2245 file = "slicoss/oasisdownload.sys";
2247 case SLIC_1GB_DEVICE_ID:
2248 file = "slicoss/gbdownload.sys";
2254 ret = request_firmware(&fw, file, &adapter->pcidev->dev);
2256 printk(KERN_ERR "SLICOSS: Failed to load firmware %s\n", file);
2259 numsects = *(u32 *)(fw->data + index);
2261 ASSERT(numsects <= 3);
2262 for (i = 0; i < numsects; i++) {
2263 sectsize[i] = *(u32 *)(fw->data + index);
2266 for (i = 0; i < numsects; i++) {
2267 sectstart[i] = *(u32 *)(fw->data + index);
2270 ucode_start = index;
2271 instruction = *(u32 *)(fw->data + index);
2273 for (section = 0; section < numsects; section++) {
2274 baseaddress = sectstart[section];
2275 thissectionsize = sectsize[section] >> 3;
2277 for (codeaddr = 0; codeaddr < thissectionsize; codeaddr++) {
2278 /* Write out instruction address */
2279 slic_reg32_write(&slic_regs->slic_wcs,
2280 baseaddress + codeaddr, FLUSH);
2281 /* Write out instruction to low addr */
2282 slic_reg32_write(&slic_regs->slic_wcs, instruction, FLUSH);
2283 instruction = *(u32 *)(fw->data + index);
2286 /* Write out instruction to high addr */
2287 slic_reg32_write(&slic_regs->slic_wcs, instruction, FLUSH);
2288 instruction = *(u32 *)(fw->data + index);
2292 index = ucode_start;
2293 for (section = 0; section < numsects; section++) {
2294 instruction = *(u32 *)(fw->data + index);
2295 baseaddress = sectstart[section];
2296 if (baseaddress < 0x8000)
2298 thissectionsize = sectsize[section] >> 3;
2300 /* DBG_MSG ("slicoss: COMPARE secton[%x] baseaddr[%x] sectnsize[%x]\n",
2301 (uint)section,baseaddress,thissectionsize);*/
2302 for (codeaddr = 0; codeaddr < thissectionsize; codeaddr++) {
2303 /* Write out instruction address */
2304 slic_reg32_write(&slic_regs->slic_wcs,
2305 SLIC_WCS_COMPARE | (baseaddress + codeaddr),
2307 /* Write out instruction to low addr */
2308 slic_reg32_write(&slic_regs->slic_wcs, instruction,
2310 instruction = *(u32 *)(fw->data + index);
2312 /* Write out instruction to high addr */
2313 slic_reg32_write(&slic_regs->slic_wcs, instruction,
2315 instruction = *(u32 *)(fw->data + index);
2318 /* Check SRAM location zero. If it is non-zero. Abort.*/
2319 /* failure = readl((u32 __iomem *)&slic_regs->slic_reset);
2322 ("slicoss: %s FAILURE EXIT codeaddr[%x] "
2323 "thissectionsize[%x] failure[%x]\n",
2324 __func__, codeaddr, thissectionsize,
2326 release_firmware(fw);
2331 /* DBG_MSG ("slicoss: Compare done\n");*/
2332 release_firmware(fw);
2333 /* Everything OK, kick off the card */
2335 slic_reg32_write(&slic_regs->slic_wcs, SLIC_WCS_START, FLUSH);
2337 /* stall for 20 ms, long enough for ucode to init card
2338 and reach mainloop */
2341 DBG_MSG("slicoss: %s (%s) EXIT adapter[%p] card[%p]\n",
2342 __func__, adapter->netdev->name, adapter, adapter->card);
2344 return STATUS_SUCCESS;
2347 static void slic_adapter_set_hwaddr(struct adapter *adapter)
2349 struct sliccard *card = adapter->card;
2351 /* DBG_MSG ("%s ENTER card->config_set[%x] port[%d] physport[%d] funct#[%d]\n",
2352 __func__, card->config_set, adapter->port, adapter->physport,
2353 adapter->functionnumber);
2355 slic_dbg_macaddrs(adapter); */
2357 if ((adapter->card) && (card->config_set)) {
2358 memcpy(adapter->macaddr,
2359 card->config.MacInfo[adapter->functionnumber].macaddrA,
2360 sizeof(struct slic_config_mac));
2361 /* DBG_MSG ("%s AFTER copying from config.macinfo into currmacaddr\n",
2363 slic_dbg_macaddrs(adapter);*/
2364 if (!(adapter->currmacaddr[0] || adapter->currmacaddr[1] ||
2365 adapter->currmacaddr[2] || adapter->currmacaddr[3] ||
2366 adapter->currmacaddr[4] || adapter->currmacaddr[5])) {
2367 memcpy(adapter->currmacaddr, adapter->macaddr, 6);
2369 if (adapter->netdev) {
2370 memcpy(adapter->netdev->dev_addr, adapter->currmacaddr,
2374 /* DBG_MSG ("%s EXIT port %d\n", __func__, adapter->port);
2375 slic_dbg_macaddrs(adapter); */
2378 static void slic_intagg_set(struct adapter *adapter, u32 value)
2380 slic_reg32_write(&adapter->slic_regs->slic_intagg, value, FLUSH);
2381 adapter->card->loadlevel_current = value;
2384 static int slic_card_init(struct sliccard *card, struct adapter *adapter)
2386 __iomem struct slic_regs *slic_regs = adapter->slic_regs;
2387 struct slic_eeprom *peeprom;
2388 struct oslic_eeprom *pOeeprom;
2389 dma_addr_t phys_config;
2393 struct slic_shmem *pshmem;
2395 uint macaddrs = card->card_size;
2400 struct slic_config_mac *pmac;
2401 unsigned char fruformat;
2402 unsigned char oemfruformat;
2403 struct atk_fru *patkfru;
2404 union oemfru *poemfru;
2407 ("slicoss: %s ENTER card[%p] adapter[%p] card->state[%x] \
2408 size[%d]\n", __func__, card, adapter, card->state, card->card_size);
2410 /* Reset everything except PCI configuration space */
2411 slic_soft_reset(adapter);
2413 /* Download the microcode */
2414 status = slic_card_download(adapter);
2416 if (status != STATUS_SUCCESS) {
2417 DBG_ERROR("SLIC download failed bus %d slot %d\n",
2418 (uint) adapter->busnumber,
2419 (uint) adapter->slotnumber);
2423 if (!card->config_set) {
2424 peeprom = pci_alloc_consistent(adapter->pcidev,
2425 sizeof(struct slic_eeprom),
2428 phys_configl = SLIC_GET_ADDR_LOW(phys_config);
2429 phys_configh = SLIC_GET_ADDR_HIGH(phys_config);
2431 DBG_MSG("slicoss: %s Eeprom info adapter [%p]\n "
2432 "size [%x]\n peeprom [%p]\n "
2433 "phys_config [%p]\n phys_configl[%x]\n "
2434 "phys_configh[%x]\n",
2436 (u32)sizeof(struct slic_eeprom),
2437 peeprom, (void *) phys_config, phys_configl,
2441 ("SLIC eeprom read failed to get memory bus %d \
2443 (uint) adapter->busnumber,
2444 (uint) adapter->slotnumber);
2447 memset(peeprom, 0, sizeof(struct slic_eeprom));
2449 slic_reg32_write(&slic_regs->slic_icr, ICR_INT_OFF, FLUSH);
2451 pshmem = (struct slic_shmem *)adapter->phys_shmem;
2453 spin_lock_irqsave(&adapter->bit64reglock.lock,
2454 adapter->bit64reglock.flags);
2455 slic_reg32_write(&slic_regs->slic_addr_upper, 0, DONT_FLUSH);
2456 slic_reg32_write(&slic_regs->slic_isp,
2457 SLIC_GET_ADDR_LOW(&pshmem->isr), FLUSH);
2458 spin_unlock_irqrestore(&adapter->bit64reglock.lock,
2459 adapter->bit64reglock.flags);
2461 slic_config_get(adapter, phys_configl, phys_configh);
2464 if (adapter->pshmem->isr) {
2465 DBG_MSG("%s shmem[%p] shmem->isr[%x]\n",
2466 __func__, adapter->pshmem,
2467 adapter->pshmem->isr);
2469 if (adapter->pshmem->isr & ISR_UPC) {
2470 adapter->pshmem->isr = 0;
2471 slic_reg64_write(adapter,
2472 &slic_regs->slic_isp, 0,
2473 &slic_regs->slic_addr_upper,
2475 slic_reg32_write(&slic_regs->slic_isr,
2478 slic_upr_request_complete(adapter, 0);
2481 adapter->pshmem->isr = 0;
2482 slic_reg32_write(&slic_regs->slic_isr,
2490 ("SLIC: %d config data fetch timed "
2491 "out!\n", adapter->port);
2492 DBG_MSG("%s shmem[%p] shmem->isr[%x]\n",
2493 __func__, adapter->pshmem,
2494 adapter->pshmem->isr);
2495 slic_reg64_write(adapter,
2496 &slic_regs->slic_isp, 0,
2497 &slic_regs->slic_addr_upper,
2504 switch (adapter->devid) {
2506 case SLIC_2GB_DEVICE_ID:
2507 /* extract EEPROM data and pointers to EEPROM data */
2508 pOeeprom = (struct oslic_eeprom *) peeprom;
2509 eecodesize = pOeeprom->EecodeSize;
2510 dramsize = pOeeprom->DramSize;
2511 pmac = pOeeprom->MacInfo;
2512 fruformat = pOeeprom->FruFormat;
2513 patkfru = &pOeeprom->AtkFru;
2514 oemfruformat = pOeeprom->OemFruFormat;
2515 poemfru = &pOeeprom->OemFru;
2517 /* Minor kludge for Oasis card
2518 get 2 MAC addresses from the
2519 EEPROM to ensure that function 1
2520 gets the Port 1 MAC address */
2523 /* extract EEPROM data and pointers to EEPROM data */
2524 eecodesize = peeprom->EecodeSize;
2525 dramsize = peeprom->DramSize;
2526 pmac = peeprom->u2.mac.MacInfo;
2527 fruformat = peeprom->FruFormat;
2528 patkfru = &peeprom->AtkFru;
2529 oemfruformat = peeprom->OemFruFormat;
2530 poemfru = &peeprom->OemFru;
2534 card->config.EepromValid = false;
2536 /* see if the EEPROM is valid by checking it's checksum */
2537 if ((eecodesize <= MAX_EECODE_SIZE) &&
2538 (eecodesize >= MIN_EECODE_SIZE)) {
2541 *(u16 *) ((char *) peeprom + (eecodesize - 2));
2543 calculate the EEPROM checksum
2546 ~slic_eeprom_cksum((char *) peeprom,
2549 if the ucdoe chksum flag bit worked,
2550 we wouldn't need this shit
2552 if (ee_chksum == calc_chksum)
2553 card->config.EepromValid = true;
2555 /* copy in the DRAM size */
2556 card->config.DramSize = dramsize;
2558 /* copy in the MAC address(es) */
2559 for (i = 0; i < macaddrs; i++) {
2560 memcpy(&card->config.MacInfo[i],
2561 &pmac[i], sizeof(struct slic_config_mac));
2563 /* DBG_MSG ("%s EEPROM Checksum Good? %d MacAddress\n",__func__,
2564 card->config.EepromValid); */
2566 /* copy the Alacritech FRU information */
2567 card->config.FruFormat = fruformat;
2568 memcpy(&card->config.AtkFru, patkfru,
2569 sizeof(struct atk_fru));
2571 pci_free_consistent(adapter->pcidev,
2572 sizeof(struct slic_eeprom),
2573 peeprom, phys_config);
2575 ("slicoss: %s adapter%d [%p] size[%x] FREE peeprom[%p] \
2577 __func__, adapter->port, adapter,
2578 (u32) sizeof(struct slic_eeprom), peeprom,
2579 (void *) phys_config);
2581 if ((!card->config.EepromValid) &&
2582 (adapter->reg_params.fail_on_bad_eeprom)) {
2583 slic_reg64_write(adapter, &slic_regs->slic_isp, 0,
2584 &slic_regs->slic_addr_upper,
2587 ("unsupported CONFIGURATION EEPROM invalid\n");
2591 card->config_set = 1;
2594 if (slic_card_download_gbrcv(adapter)) {
2595 DBG_ERROR("%s unable to download GB receive microcode\n",
2600 if (slic_global.dynamic_intagg) {
2602 ("Dynamic Interrupt Aggregation[ENABLED]: slic%d \
2603 SET intagg to %d\n",
2605 slic_intagg_set(adapter, 0);
2607 slic_intagg_set(adapter, intagg_delay);
2609 ("Dynamic Interrupt Aggregation[DISABLED]: slic%d \
2610 SET intagg to %d\n",
2611 card->cardnum, intagg_delay);
2615 * Initialize ping status to "ok"
2617 card->pingstatus = ISR_PINGMASK;
2619 #if SLIC_DUMP_ENABLED
2620 if (!card->dumpbuffer) {
2621 card->dumpbuffer = kmalloc(DUMP_PAGE_SIZE, GFP_KERNEL);
2623 ASSERT(card->dumpbuffer);
2624 if (card->dumpbuffer == NULL)
2628 * Smear the shared memory structure and then obtain
2629 * the PHYSICAL address of this structure
2631 memset(card->dumpbuffer, 0, DUMP_PAGE_SIZE);
2632 card->dumpbuffer_phys = virt_to_bus(card->dumpbuffer);
2633 card->dumpbuffer_physh = SLIC_GET_ADDR_HIGH(card->dumpbuffer_phys);
2634 card->dumpbuffer_physl = SLIC_GET_ADDR_LOW(card->dumpbuffer_phys);
2637 * Allocate COMMAND BUFFER
2639 if (!card->cmdbuffer) {
2640 card->cmdbuffer = kmalloc(sizeof(struct dump_cmd), GFP_KERNEL);
2642 ASSERT(card->cmdbuffer);
2643 if (card->cmdbuffer == NULL)
2647 * Smear the shared memory structure and then obtain
2648 * the PHYSICAL address of this structure
2650 memset(card->cmdbuffer, 0, sizeof(struct dump_cmd));
2651 card->cmdbuffer_phys = virt_to_bus(card->cmdbuffer);
2652 card->cmdbuffer_physh = SLIC_GET_ADDR_HIGH(card->cmdbuffer_phys);
2653 card->cmdbuffer_physl = SLIC_GET_ADDR_LOW(card->cmdbuffer_phys);
2657 * Lastly, mark our card state as up and return success
2659 card->state = CARD_UP;
2660 card->reset_in_progress = 0;
2661 DBG_MSG("slicoss: %s EXIT card[%p] adapter[%p] card->state[%x]\n",
2662 __func__, card, adapter, card->state);
2664 return STATUS_SUCCESS;
2667 static u32 slic_card_locate(struct adapter *adapter)
2669 struct sliccard *card = slic_global.slic_card;
2670 struct physcard *physcard = slic_global.phys_card;
2672 u16 __iomem *hostid_reg;
2674 uint rdhostid_offset = 0;
2676 DBG_MSG("slicoss: %s adapter[%p] slot[%x] bus[%x] port[%x]\n",
2677 __func__, adapter, adapter->slotnumber, adapter->busnumber,
2680 switch (adapter->devid) {
2681 case SLIC_2GB_DEVICE_ID:
2682 rdhostid_offset = SLIC_RDHOSTID_2GB;
2684 case SLIC_1GB_DEVICE_ID:
2685 rdhostid_offset = SLIC_RDHOSTID_1GB;
2693 (u16 __iomem *) (((u8 __iomem *) (adapter->slic_regs)) +
2695 DBG_MSG("slicoss: %s *hostid_reg[%p] == ", __func__, hostid_reg);
2697 /* read the 16 bit hostid from SRAM */
2698 card_hostid = (ushort) readw(hostid_reg);
2699 DBG_MSG(" card_hostid[%x]\n", card_hostid);
2701 /* Initialize a new card structure if need be */
2702 if (card_hostid == SLIC_HOSTID_DEFAULT) {
2703 card = kzalloc(sizeof(struct sliccard), GFP_KERNEL);
2707 card->next = slic_global.slic_card;
2708 slic_global.slic_card = card;
2710 if (adapter->devid == SLIC_2GB_DEVICE_ID) {
2712 ("SLICOSS ==> Initialize 2 Port Gigabit Server "
2713 "and Storage Accelerator\n");
2716 ("SLICOSS ==> Initialize 1 Port Gigabit Server "
2717 "and Storage Accelerator\n");
2720 card->busnumber = adapter->busnumber;
2721 card->slotnumber = adapter->slotnumber;
2723 /* Find an available cardnum */
2724 for (i = 0; i < SLIC_MAX_CARDS; i++) {
2725 if (slic_global.cardnuminuse[i] == 0) {
2726 slic_global.cardnuminuse[i] = 1;
2731 slic_global.num_slic_cards++;
2732 DBG_MSG("\nCARDNUM == %d Total %d Card[%p]\n\n",
2733 card->cardnum, slic_global.num_slic_cards, card);
2735 slic_debug_card_create(card);
2738 ("slicoss: %s CARD already allocated, find the \
2739 correct card\n", __func__);
2740 /* Card exists, find the card this adapter belongs to */
2743 ("slicoss: %s card[%p] slot[%x] bus[%x] \
2744 adaptport[%p] hostid[%x] cardnum[%x]\n",
2745 __func__, card, card->slotnumber,
2746 card->busnumber, card->adapter[adapter->port],
2747 card_hostid, card->cardnum);
2749 if (card->cardnum == card_hostid)
2757 return STATUS_FAILURE;
2758 /* Put the adapter in the card's adapter list */
2759 ASSERT(card->adapter[adapter->port] == NULL);
2760 if (!card->adapter[adapter->port]) {
2761 card->adapter[adapter->port] = adapter;
2762 adapter->card = card;
2765 card->card_size = 1; /* one port per *logical* card */
2768 for (i = 0; i < SLIC_MAX_PORTS; i++) {
2769 if (!physcard->adapter[i])
2774 ASSERT(i != SLIC_MAX_PORTS);
2775 if (physcard->adapter[i]->slotnumber == adapter->slotnumber)
2777 physcard = physcard->next;
2780 /* no structure allocated for this physical card yet */
2781 physcard = kzalloc(sizeof(struct physcard), GFP_KERNEL);
2785 ("\n%s Allocate a PHYSICALcard:\n PHYSICAL_Card[%p]\n"
2786 " LogicalCard [%p]\n adapter [%p]\n",
2787 __func__, physcard, card, adapter);
2789 physcard->next = slic_global.phys_card;
2790 slic_global.phys_card = physcard;
2791 physcard->adapters_allocd = 1;
2793 physcard->adapters_allocd++;
2795 /* Note - this is ZERO relative */
2796 adapter->physport = physcard->adapters_allocd - 1;
2798 ASSERT(physcard->adapter[adapter->physport] == NULL);
2799 physcard->adapter[adapter->physport] = adapter;
2800 adapter->physcard = physcard;
2801 DBG_MSG(" PHYSICAL_Port %d Logical_Port %d\n", adapter->physport,
2807 static void slic_soft_reset(struct adapter *adapter)
2809 if (adapter->card->state == CARD_UP) {
2810 DBG_MSG("slicoss: %s QUIESCE adapter[%p] card[%p] devid[%x]\n",
2811 __func__, adapter, adapter->card, adapter->devid);
2812 slic_reg32_write(&adapter->slic_regs->slic_quiesce, 0, FLUSH);
2815 /* DBG_MSG ("slicoss: %s (%s) adapter[%p] card[%p] devid[%x]\n",
2816 __func__, adapter->netdev->name, adapter, adapter->card,
2819 slic_reg32_write(&adapter->slic_regs->slic_reset, SLIC_RESET_MAGIC,
2824 static void slic_config_set(struct adapter *adapter, bool linkchange)
2828 __iomem struct slic_regs *slic_regs = adapter->slic_regs;
2830 DBG_MSG("slicoss: %s (%s) slic_interface_enable[%p](%d)\n",
2831 __func__, adapter->netdev->name, adapter,
2832 adapter->cardindex);
2836 slic_mac_config(adapter);
2837 RcrReset = GRCR_RESET;
2839 slic_mac_address_config(adapter);
2843 if (adapter->linkduplex == LINK_FULLD) {
2845 value = (GXCR_RESET | /* Always reset */
2846 GXCR_XMTEN | /* Enable transmit */
2847 GXCR_PAUSEEN); /* Enable pause */
2849 DBG_MSG("slicoss: FDX adapt[%p] set xmtcfg to [%x]\n", adapter,
2851 slic_reg32_write(&slic_regs->slic_wxcfg, value, FLUSH);
2853 /* Setup rcvcfg last */
2854 value = (RcrReset | /* Reset, if linkchange */
2855 GRCR_CTLEN | /* Enable CTL frames */
2856 GRCR_ADDRAEN | /* Address A enable */
2857 GRCR_RCVBAD | /* Rcv bad frames */
2858 (GRCR_HASHSIZE << GRCR_HASHSIZE_SHIFT));
2861 value = (GXCR_RESET | /* Always reset */
2862 GXCR_XMTEN); /* Enable transmit */
2864 DBG_MSG("slicoss: HDX adapt[%p] set xmtcfg to [%x]\n", adapter,
2866 slic_reg32_write(&slic_regs->slic_wxcfg, value, FLUSH);
2868 /* Setup rcvcfg last */
2869 value = (RcrReset | /* Reset, if linkchange */
2870 GRCR_ADDRAEN | /* Address A enable */
2871 GRCR_RCVBAD | /* Rcv bad frames */
2872 (GRCR_HASHSIZE << GRCR_HASHSIZE_SHIFT));
2875 if (adapter->state != ADAPT_DOWN) {
2876 /* Only enable receive if we are restarting or running */
2877 value |= GRCR_RCVEN;
2880 if (adapter->macopts & MAC_PROMISC)
2881 value |= GRCR_RCVALL;
2883 DBG_MSG("slicoss: adapt[%p] set rcvcfg to [%x]\n", adapter, value);
2884 slic_reg32_write(&slic_regs->slic_wrcfg, value, FLUSH);
2888 * Turn off RCV and XMT, power down PHY
2890 static void slic_config_clear(struct adapter *adapter)
2894 __iomem struct slic_regs *slic_regs = adapter->slic_regs;
2897 value = (GXCR_RESET | /* Always reset */
2898 GXCR_PAUSEEN); /* Enable pause */
2900 slic_reg32_write(&slic_regs->slic_wxcfg, value, FLUSH);
2902 value = (GRCR_RESET | /* Always reset */
2903 GRCR_CTLEN | /* Enable CTL frames */
2904 GRCR_ADDRAEN | /* Address A enable */
2905 (GRCR_HASHSIZE << GRCR_HASHSIZE_SHIFT));
2907 slic_reg32_write(&slic_regs->slic_wrcfg, value, FLUSH);
2909 /* power down phy */
2910 phy_config = (MIICR_REG_PCR | (PCR_POWERDOWN));
2911 slic_reg32_write(&slic_regs->slic_wphy, phy_config, FLUSH);
2914 static void slic_config_get(struct adapter *adapter, u32 config,
2919 status = slic_upr_request(adapter,
2921 (u32) config, (u32) config_h, 0, 0);
2922 ASSERT(status == 0);
2925 static void slic_mac_address_config(struct adapter *adapter)
2929 __iomem struct slic_regs *slic_regs = adapter->slic_regs;
2931 value = *(u32 *) &adapter->currmacaddr[2];
2932 value = ntohl(value);
2933 slic_reg32_write(&slic_regs->slic_wraddral, value, FLUSH);
2934 slic_reg32_write(&slic_regs->slic_wraddrbl, value, FLUSH);
2936 value2 = (u32) ((adapter->currmacaddr[0] << 8 |
2937 adapter->currmacaddr[1]) & 0xFFFF);
2939 slic_reg32_write(&slic_regs->slic_wraddrah, value2, FLUSH);
2940 slic_reg32_write(&slic_regs->slic_wraddrbh, value2, FLUSH);
2942 DBG_MSG("%s value1[%x] value2[%x] Call slic_mcast_set_mask\n",
2943 __func__, value, value2);
2944 slic_dbg_macaddrs(adapter);
2946 /* Write our multicast mask out to the card. This is done */
2947 /* here in addition to the slic_mcast_addr_set routine */
2948 /* because ALL_MCAST may have been enabled or disabled */
2949 slic_mcast_set_mask(adapter);
2952 static void slic_mac_config(struct adapter *adapter)
2955 __iomem struct slic_regs *slic_regs = adapter->slic_regs;
2957 /* Setup GMAC gaps */
2958 if (adapter->linkspeed == LINK_1000MB) {
2959 value = ((GMCR_GAPBB_1000 << GMCR_GAPBB_SHIFT) |
2960 (GMCR_GAPR1_1000 << GMCR_GAPR1_SHIFT) |
2961 (GMCR_GAPR2_1000 << GMCR_GAPR2_SHIFT));
2963 value = ((GMCR_GAPBB_100 << GMCR_GAPBB_SHIFT) |
2964 (GMCR_GAPR1_100 << GMCR_GAPR1_SHIFT) |
2965 (GMCR_GAPR2_100 << GMCR_GAPR2_SHIFT));
2969 if (adapter->linkspeed == LINK_1000MB)
2972 /* enable fullduplex */
2973 if ((adapter->linkduplex == LINK_FULLD)
2974 || (adapter->macopts & MAC_LOOPBACK)) {
2975 value |= GMCR_FULLD;
2978 /* write mac config */
2979 slic_reg32_write(&slic_regs->slic_wmcfg, value, FLUSH);
2981 /* setup mac addresses */
2982 slic_mac_address_config(adapter);
2985 static bool slic_mac_filter(struct adapter *adapter,
2986 struct ether_header *ether_frame)
2988 u32 opts = adapter->macopts;
2989 u32 *dhost4 = (u32 *)ðer_frame->ether_dhost[0];
2990 u16 *dhost2 = (u16 *)ðer_frame->ether_dhost[4];
2993 if (opts & MAC_PROMISC) {
2994 DBG_MSG("slicoss: %s (%s) PROMISCUOUS. Accept frame\n",
2995 __func__, adapter->netdev->name);
2999 if ((*dhost4 == 0xFFFFFFFF) && (*dhost2 == 0xFFFF)) {
3000 if (opts & MAC_BCAST) {
3001 adapter->rcv_broadcasts++;
3008 if (ether_frame->ether_dhost[0] & 0x01) {
3009 if (opts & MAC_ALLMCAST) {
3010 adapter->rcv_multicasts++;
3011 adapter->stats.multicast++;
3014 if (opts & MAC_MCAST) {
3015 struct mcast_address *mcaddr = adapter->mcastaddrs;
3018 ETHER_EQ_ADDR(mcaddr->address,
3019 ether_frame->ether_dhost,
3022 adapter->rcv_multicasts++;
3023 adapter->stats.multicast++;
3026 mcaddr = mcaddr->next;
3033 if (opts & MAC_DIRECTED) {
3034 adapter->rcv_unicasts++;
3041 static int slic_mac_set_address(struct net_device *dev, void *ptr)
3043 struct adapter *adapter = (struct adapter *)netdev_priv(dev);
3044 struct sockaddr *addr = ptr;
3046 DBG_MSG("%s ENTER (%s)\n", __func__, adapter->netdev->name);
3048 if (netif_running(dev))
3052 DBG_MSG("slicoss: %s (%s) curr %2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X\n",
3053 __func__, adapter->netdev->name, adapter->currmacaddr[0],
3054 adapter->currmacaddr[1], adapter->currmacaddr[2],
3055 adapter->currmacaddr[3], adapter->currmacaddr[4],
3056 adapter->currmacaddr[5]);
3057 memcpy(dev->dev_addr, addr->sa_data, dev->addr_len);
3058 memcpy(adapter->currmacaddr, addr->sa_data, dev->addr_len);
3059 DBG_MSG("slicoss: %s (%s) new %2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X\n",
3060 __func__, adapter->netdev->name, adapter->currmacaddr[0],
3061 adapter->currmacaddr[1], adapter->currmacaddr[2],
3062 adapter->currmacaddr[3], adapter->currmacaddr[4],
3063 adapter->currmacaddr[5]);
3065 slic_config_set(adapter, true);
3070 * slic_timer_get_stats
3072 * Timer function used to suck the statistics out of the card every
3073 * 50 seconds or whatever STATS_TIMER_INTERVAL is set to.
3076 #if SLIC_GET_STATS_TIMER_ENABLED
3077 static void slic_timer_get_stats(ulong dev)
3079 struct adapter *adapter;
3080 struct sliccard *card;
3081 struct slic_shmem *pshmem;
3084 adapter = netdev_priv((struct net_device *)dev);
3086 card = adapter->card;
3089 if ((card->state == CARD_UP) &&
3090 (adapter->state == ADAPT_UP) && (adapter->linkstate == LINK_UP)) {
3091 pshmem = (struct slic_shmem *)adapter->phys_shmem;
3092 #ifdef CONFIG_X86_64
3093 slic_upr_request(adapter,
3095 SLIC_GET_ADDR_LOW(&pshmem->inicstats),
3096 SLIC_GET_ADDR_HIGH(&pshmem->inicstats), 0, 0);
3097 #elif defined(CONFIG_X86)
3098 slic_upr_request(adapter,
3100 (u32) &pshmem->inicstats, 0, 0, 0);
3105 /* DBG_MSG ("slicoss: %s adapter[%p] linkstate[%x] NOT UP!\n",
3106 __func__, adapter, adapter->linkstate); */
3108 adapter->statstimer.expires = jiffies + (STATS_TIMER_INTERVAL * HZ);
3109 add_timer(&adapter->statstimer);
3112 static void slic_timer_load_check(ulong cardaddr)
3114 struct sliccard *card = (struct sliccard *)cardaddr;
3115 struct adapter *adapter = card->master;
3116 u32 __iomem *intagg;
3117 u32 load = card->events;
3120 intagg = &adapter->slic_regs->slic_intagg;
3122 if ((adapter) && (adapter->state == ADAPT_UP) &&
3123 (card->state == CARD_UP) && (slic_global.dynamic_intagg)) {
3124 if (adapter->devid == SLIC_1GB_DEVICE_ID) {
3125 if (adapter->linkspeed == LINK_1000MB)
3128 if (load > SLIC_LOAD_5)
3129 level = SLIC_INTAGG_5;
3130 else if (load > SLIC_LOAD_4)
3131 level = SLIC_INTAGG_4;
3132 else if (load > SLIC_LOAD_3)
3133 level = SLIC_INTAGG_3;
3134 else if (load > SLIC_LOAD_2)
3135 level = SLIC_INTAGG_2;
3136 else if (load > SLIC_LOAD_1)
3137 level = SLIC_INTAGG_1;
3139 level = SLIC_INTAGG_0;
3141 if (card->loadlevel_current != level) {
3142 card->loadlevel_current = level;
3143 slic_reg32_write(intagg, level, FLUSH);
3146 if (load > SLIC_LOAD_5)
3147 level = SLIC_INTAGG_5;
3148 else if (load > SLIC_LOAD_4)
3149 level = SLIC_INTAGG_4;
3150 else if (load > SLIC_LOAD_3)
3151 level = SLIC_INTAGG_3;
3152 else if (load > SLIC_LOAD_2)
3153 level = SLIC_INTAGG_2;
3154 else if (load > SLIC_LOAD_1)
3155 level = SLIC_INTAGG_1;
3157 level = SLIC_INTAGG_0;
3158 if (card->loadlevel_current != level) {
3159 card->loadlevel_current = level;
3160 slic_reg32_write(intagg, level, FLUSH);
3165 card->loadtimer.expires = jiffies + (SLIC_LOADTIMER_PERIOD * HZ);
3166 add_timer(&card->loadtimer);
3169 static void slic_assert_fail(void)
3173 cpuid = smp_processor_id();
3174 curr_pid = current->pid;
3176 DBG_ERROR("%s CPU # %d ---- PID # %d\n", __func__, cpuid, curr_pid);
3179 static int slic_upr_queue_request(struct adapter *adapter,
3183 u32 upr_buffer, u32 upr_buffer_h)
3185 struct slic_upr *upr;
3186 struct slic_upr *uprqueue;
3188 upr = kmalloc(sizeof(struct slic_upr), GFP_ATOMIC);
3190 DBG_MSG("%s COULD NOT ALLOCATE UPR MEM\n", __func__);
3194 upr->adapter = adapter->port;
3195 upr->upr_request = upr_request;
3196 upr->upr_data = upr_data;
3197 upr->upr_buffer = upr_buffer;
3198 upr->upr_data_h = upr_data_h;
3199 upr->upr_buffer_h = upr_buffer_h;
3201 if (adapter->upr_list) {
3202 uprqueue = adapter->upr_list;
3204 while (uprqueue->next)
3205 uprqueue = uprqueue->next;
3206 uprqueue->next = upr;
3208 adapter->upr_list = upr;
3210 return STATUS_SUCCESS;
3213 static int slic_upr_request(struct adapter *adapter,
3217 u32 upr_buffer, u32 upr_buffer_h)
3221 spin_lock_irqsave(&adapter->upr_lock.lock, adapter->upr_lock.flags);
3222 status = slic_upr_queue_request(adapter,
3225 upr_data_h, upr_buffer, upr_buffer_h);
3226 if (status != STATUS_SUCCESS) {
3227 spin_unlock_irqrestore(&adapter->upr_lock.lock,
3228 adapter->upr_lock.flags);
3231 slic_upr_start(adapter);
3232 spin_unlock_irqrestore(&adapter->upr_lock.lock,
3233 adapter->upr_lock.flags);
3234 return STATUS_PENDING;
3237 static void slic_upr_request_complete(struct adapter *adapter, u32 isr)
3239 struct sliccard *card = adapter->card;
3240 struct slic_upr *upr;
3242 /* if (card->dump_requested) {
3243 DBG_MSG("ENTER slic_upr_request_complete Dump in progress ISR[%x]\n",
3246 spin_lock_irqsave(&adapter->upr_lock.lock, adapter->upr_lock.flags);
3247 upr = adapter->upr_list;
3250 spin_unlock_irqrestore(&adapter->upr_lock.lock,
3251 adapter->upr_lock.flags);
3254 adapter->upr_list = upr->next;
3256 adapter->upr_busy = 0;
3257 ASSERT(adapter->port == upr->adapter);
3258 switch (upr->upr_request) {
3259 case SLIC_UPR_STATS:
3261 #if SLIC_GET_STATS_ENABLED
3262 struct slic_stats *slicstats =
3263 (struct slic_stats *) &adapter->pshmem->inicstats;
3264 struct slic_stats *newstats = slicstats;
3265 struct slic_stats *old = &adapter->inicstats_prev;
3266 struct slicnet_stats *stst = &adapter->slic_stats;
3268 if (isr & ISR_UPCERR) {
3270 ("SLIC_UPR_STATS command failed isr[%x]\n",
3275 #if SLIC_GET_STATS_ENABLED
3276 /* DBG_MSG ("slicoss: %s rcv %lx:%lx:%lx:%lx:%lx %lx %lx "
3277 "xmt %lx:%lx:%lx:%lx:%lx %lx %lx\n",
3279 slicstats->rcv_unicasts100,
3280 slicstats->rcv_bytes100,
3281 slicstats->rcv_bytes100,
3282 slicstats->rcv_tcp_bytes100,
3283 slicstats->rcv_tcp_segs100,
3284 slicstats->rcv_other_error100,
3285 slicstats->rcv_drops100,
3286 slicstats->xmit_unicasts100,
3287 slicstats->xmit_bytes100,
3288 slicstats->xmit_bytes100,
3289 slicstats->xmit_tcp_bytes100,
3290 slicstats->xmit_tcp_segs100,
3291 slicstats->xmit_other_error100,
3292 slicstats->xmit_collisions100);*/
3293 UPDATE_STATS_GB(stst->tcp.xmit_tcp_segs,
3294 newstats->xmit_tcp_segs_gb,
3295 old->xmit_tcp_segs_gb);
3297 UPDATE_STATS_GB(stst->tcp.xmit_tcp_bytes,
3298 newstats->xmit_tcp_bytes_gb,
3299 old->xmit_tcp_bytes_gb);
3301 UPDATE_STATS_GB(stst->tcp.rcv_tcp_segs,
3302 newstats->rcv_tcp_segs_gb,
3303 old->rcv_tcp_segs_gb);
3305 UPDATE_STATS_GB(stst->tcp.rcv_tcp_bytes,
3306 newstats->rcv_tcp_bytes_gb,
3307 old->rcv_tcp_bytes_gb);
3309 UPDATE_STATS_GB(stst->iface.xmt_bytes,
3310 newstats->xmit_bytes_gb,
3311 old->xmit_bytes_gb);
3313 UPDATE_STATS_GB(stst->iface.xmt_ucast,
3314 newstats->xmit_unicasts_gb,
3315 old->xmit_unicasts_gb);
3317 UPDATE_STATS_GB(stst->iface.rcv_bytes,
3318 newstats->rcv_bytes_gb,
3321 UPDATE_STATS_GB(stst->iface.rcv_ucast,
3322 newstats->rcv_unicasts_gb,
3323 old->rcv_unicasts_gb);
3325 UPDATE_STATS_GB(stst->iface.xmt_errors,
3326 newstats->xmit_collisions_gb,
3327 old->xmit_collisions_gb);
3329 UPDATE_STATS_GB(stst->iface.xmt_errors,
3330 newstats->xmit_excess_collisions_gb,
3331 old->xmit_excess_collisions_gb);
3333 UPDATE_STATS_GB(stst->iface.xmt_errors,
3334 newstats->xmit_other_error_gb,
3335 old->xmit_other_error_gb);
3337 UPDATE_STATS_GB(stst->iface.rcv_errors,
3338 newstats->rcv_other_error_gb,
3339 old->rcv_other_error_gb);
3341 UPDATE_STATS_GB(stst->iface.rcv_discards,
3342 newstats->rcv_drops_gb,
3345 if (newstats->rcv_drops_gb > old->rcv_drops_gb) {
3346 adapter->rcv_drops +=
3347 (newstats->rcv_drops_gb -
3350 memcpy(old, newstats, sizeof(struct slic_stats));
3355 slic_link_upr_complete(adapter, isr);
3357 case SLIC_UPR_RCONFIG:
3372 card->pingstatus |= (isr & ISR_PINGDSMASK);
3374 #if SLIC_DUMP_ENABLED
3376 card->dumpstatus |= (isr & ISR_UPCMASK);
3383 slic_upr_start(adapter);
3384 spin_unlock_irqrestore(&adapter->upr_lock.lock,
3385 adapter->upr_lock.flags);
3388 static void slic_upr_start(struct adapter *adapter)
3390 struct slic_upr *upr;
3391 __iomem struct slic_regs *slic_regs = adapter->slic_regs;
3397 upr = adapter->upr_list;
3400 if (adapter->upr_busy)
3402 adapter->upr_busy = 1;
3404 switch (upr->upr_request) {
3405 case SLIC_UPR_STATS:
3406 if (upr->upr_data_h == 0) {
3407 slic_reg32_write(&slic_regs->slic_stats, upr->upr_data,
3410 slic_reg64_write(adapter, &slic_regs->slic_stats64,
3412 &slic_regs->slic_addr_upper,
3413 upr->upr_data_h, FLUSH);
3418 slic_reg64_write(adapter, &slic_regs->slic_rlsr, upr->upr_data,
3419 &slic_regs->slic_addr_upper, upr->upr_data_h,
3423 case SLIC_UPR_RCONFIG:
3424 DBG_MSG("%s SLIC_UPR_RCONFIG!!!!\n", __func__);
3425 DBG_MSG("slic_reg64_write adapter[%p]\n"
3426 " a->slic_regs[%p] slic_regs[%p]\n"
3427 " &slic_rconfig[%p] &slic_addr_upper[%p]\n"
3429 " uprdata[%x] uprdatah[%x]\n",
3430 adapter, adapter->slic_regs, slic_regs,
3431 &slic_regs->slic_rconfig, &slic_regs->slic_addr_upper,
3432 upr, upr->upr_data, upr->upr_data_h);
3433 slic_reg64_write(adapter, &slic_regs->slic_rconfig,
3434 upr->upr_data, &slic_regs->slic_addr_upper,
3435 upr->upr_data_h, FLUSH);
3437 #if SLIC_DUMP_ENABLED
3439 if (upr->upr_buffer || upr->upr_buffer_h) {
3440 slic_reg64_write(adapter, &slic_regs->slic_dump_data,
3442 &slic_regs->slic_addr_upper,
3443 upr->upr_buffer_h, FLUSH);
3445 slic_reg64_write(adapter, &slic_regs->slic_dump_cmd,
3446 upr->upr_data, slic_regs->slic_addr_upper,
3447 upr->upr_data_h, FLUSH);
3451 slic_reg32_write(&slic_regs->slic_ping, 1, FLUSH);
3458 static void slic_link_upr_complete(struct adapter *adapter, u32 isr)
3460 u32 linkstatus = adapter->pshmem->linkstatus;
3462 unsigned char linkspeed;
3463 unsigned char linkduplex;
3465 DBG_MSG("%s: %s ISR[%x] linkstatus[%x]\n adapter[%p](%d)\n",
3466 __func__, adapter->netdev->name, isr, linkstatus, adapter,
3467 adapter->cardindex);
3469 if ((isr & ISR_UPCERR) || (isr & ISR_UPCBSY)) {
3470 struct slic_shmem *pshmem;
3472 pshmem = (struct slic_shmem *)adapter->phys_shmem;
3473 #if defined(CONFIG_X86_64)
3474 slic_upr_queue_request(adapter,
3476 SLIC_GET_ADDR_LOW(&pshmem->linkstatus),
3477 SLIC_GET_ADDR_HIGH(&pshmem->linkstatus),
3479 #elif defined(CONFIG_X86)
3480 slic_upr_queue_request(adapter,
3482 (u32) &pshmem->linkstatus,
3483 SLIC_GET_ADDR_HIGH(pshmem), 0, 0);
3489 if (adapter->state != ADAPT_UP)
3492 ASSERT((adapter->devid == SLIC_1GB_DEVICE_ID)
3493 || (adapter->devid == SLIC_2GB_DEVICE_ID));
3495 linkup = linkstatus & GIG_LINKUP ? LINK_UP : LINK_DOWN;
3496 if (linkstatus & GIG_SPEED_1000) {
3497 linkspeed = LINK_1000MB;
3498 DBG_MSG("slicoss: %s (%s) GIGABIT Speed==1000MB ",
3499 __func__, adapter->netdev->name);
3500 } else if (linkstatus & GIG_SPEED_100) {
3501 linkspeed = LINK_100MB;
3502 DBG_MSG("slicoss: %s (%s) GIGABIT Speed==100MB ", __func__,
3503 adapter->netdev->name);
3505 linkspeed = LINK_10MB;
3506 DBG_MSG("slicoss: %s (%s) GIGABIT Speed==10MB ", __func__,
3507 adapter->netdev->name);
3509 if (linkstatus & GIG_FULLDUPLEX) {
3510 linkduplex = LINK_FULLD;
3511 DBG_MSG(" Duplex == FULL\n");
3513 linkduplex = LINK_HALFD;
3514 DBG_MSG(" Duplex == HALF\n");
3517 if ((adapter->linkstate == LINK_DOWN) && (linkup == LINK_DOWN)) {
3518 DBG_MSG("slicoss: %s (%s) physport(%d) link still down\n",
3519 __func__, adapter->netdev->name, adapter->physport);
3523 /* link up event, but nothing has changed */
3524 if ((adapter->linkstate == LINK_UP) &&
3525 (linkup == LINK_UP) &&
3526 (adapter->linkspeed == linkspeed) &&
3527 (adapter->linkduplex == linkduplex)) {
3528 DBG_MSG("slicoss: %s (%s) port(%d) link still up\n",
3529 __func__, adapter->netdev->name, adapter->physport);
3533 /* link has changed at this point */
3535 /* link has gone from up to down */
3536 if (linkup == LINK_DOWN) {
3537 adapter->linkstate = LINK_DOWN;
3538 DBG_MSG("slicoss: %s %d LinkDown!\n", __func__,
3543 /* link has gone from down to up */
3544 adapter->linkspeed = linkspeed;
3545 adapter->linkduplex = linkduplex;
3547 if (adapter->linkstate != LINK_UP) {
3549 DBG_MSG("%s call slic_config_set\n", __func__);
3550 slic_config_set(adapter, true);
3551 adapter->linkstate = LINK_UP;
3552 DBG_MSG("\n(%s) Link UP: CALL slic_if_start_queue",
3553 adapter->netdev->name);
3554 slic_if_start_queue(adapter);
3557 switch (linkspeed) {
3560 ("\n(%s) LINK UP!: GIGABIT SPEED == 1000MB duplex[%x]\n",
3561 adapter->netdev->name, adapter->linkduplex);
3564 DBG_MSG("\n(%s) LINK UP!: SPEED == 100MB duplex[%x]\n",
3565 adapter->netdev->name, adapter->linkduplex);
3568 DBG_MSG("\n(%s) LINK UP!: SPEED == 10MB duplex[%x]\n",
3569 adapter->netdev->name, adapter->linkduplex);
3576 * this is here to checksum the eeprom, there is some ucode bug
3577 * which prevens us from using the ucode result.
3578 * remove this once ucode is fixed.
3580 static ushort slic_eeprom_cksum(char *m, int len)
3582 #define ADDCARRY(x) (x > 65535 ? x -= 65535 : x)
3583 #define REDUCE {l_util.l = sum; sum = l_util.s[0] + l_util.s[1]; ADDCARRY(sum);\
3588 u32 byte_swapped = 0;
3605 #ifdef CONFIG_X86_64
3606 w_int = (u32) ((ulong) w & 0x00000000FFFFFFFF);
3610 if ((1 & w_int) && (len > 0)) {
3613 s_util.c[0] = *(unsigned char *)w;
3614 w = (u16 *)((char *)w + 1);
3619 /* Unroll the loop to make overhead from branches &c small. */
3620 while ((len -= 32) >= 0) {
3637 w = (u16 *)((ulong) w + 16); /* verify */
3640 while ((len -= 8) >= 0) {
3645 w = (u16 *)((ulong) w + 4); /* verify */
3648 if (len != 0 || byte_swapped != 0) {
3650 while ((len -= 2) >= 0)
3651 sum += *w++; /* verify */
3657 s_util.c[1] = *(char *) w;
3664 } else if (len == -1) {
3665 s_util.c[0] = *(char *) w;
3674 return (ushort) sum;
3677 static int slic_rspqueue_init(struct adapter *adapter)
3680 struct slic_rspqueue *rspq = &adapter->rspqueue;
3681 __iomem struct slic_regs *slic_regs = adapter->slic_regs;
3684 DBG_MSG("slicoss: %s (%s) ENTER adapter[%p]\n", __func__,
3685 adapter->netdev->name, adapter);
3686 ASSERT(adapter->state == ADAPT_DOWN);
3687 memset(rspq, 0, sizeof(struct slic_rspqueue));
3689 rspq->num_pages = SLIC_RSPQ_PAGES_GB;
3691 for (i = 0; i < rspq->num_pages; i++) {
3693 pci_alloc_consistent(adapter->pcidev, PAGE_SIZE,
3695 if (!rspq->vaddr[i]) {
3697 ("rspqueue_init_failed pci_alloc_consistent\n");
3698 slic_rspqueue_free(adapter);
3699 return STATUS_FAILURE;
3701 #ifndef CONFIG_X86_64
3702 ASSERT(((u32) rspq->vaddr[i] & 0xFFFFF000) ==
3703 (u32) rspq->vaddr[i]);
3704 ASSERT(((u32) rspq->paddr[i] & 0xFFFFF000) ==
3705 (u32) rspq->paddr[i]);
3707 memset(rspq->vaddr[i], 0, PAGE_SIZE);
3708 /* DBG_MSG("slicoss: %s UPLOAD RSPBUFF Page pageix[%x] paddr[%p] "
3710 __func__, i, (void *)rspq->paddr[i], rspq->vaddr[i]); */
3713 slic_reg32_write(&slic_regs->slic_rbar,
3714 (rspq->paddr[i] | SLIC_RSPQ_BUFSINPAGE),
3717 slic_reg64_write(adapter, &slic_regs->slic_rbar64,
3718 (rspq->paddr[i] | SLIC_RSPQ_BUFSINPAGE),
3719 &slic_regs->slic_addr_upper,
3720 paddrh, DONT_FLUSH);
3724 rspq->pageindex = 0;
3725 rspq->rspbuf = (struct slic_rspbuf *)rspq->vaddr[0];
3726 DBG_MSG("slicoss: %s (%s) EXIT adapter[%p]\n", __func__,
3727 adapter->netdev->name, adapter);
3728 return STATUS_SUCCESS;
3731 static int slic_rspqueue_reset(struct adapter *adapter)
3733 struct slic_rspqueue *rspq = &adapter->rspqueue;
3735 DBG_MSG("slicoss: %s (%s) ENTER adapter[%p]\n", __func__,
3736 adapter->netdev->name, adapter);
3737 ASSERT(adapter->state == ADAPT_DOWN);
3740 DBG_MSG("slicoss: Nothing to do. rspq[%p]\n"
3744 rspq, rspq->offset, rspq->pageindex, rspq->rspbuf);
3746 DBG_MSG("slicoss: %s (%s) EXIT adapter[%p]\n", __func__,
3747 adapter->netdev->name, adapter);
3748 return STATUS_SUCCESS;
3751 static void slic_rspqueue_free(struct adapter *adapter)
3754 struct slic_rspqueue *rspq = &adapter->rspqueue;
3756 DBG_MSG("slicoss: %s adapter[%p] port %d rspq[%p] FreeRSPQ\n",
3757 __func__, adapter, adapter->physport, rspq);
3758 for (i = 0; i < rspq->num_pages; i++) {
3759 if (rspq->vaddr[i]) {
3761 ("slicoss: pci_free_consistent rspq->vaddr[%p] \
3763 rspq->vaddr[i], (void *) rspq->paddr[i]);
3764 pci_free_consistent(adapter->pcidev, PAGE_SIZE,
3765 rspq->vaddr[i], rspq->paddr[i]);
3767 rspq->vaddr[i] = NULL;
3771 rspq->pageindex = 0;
3772 rspq->rspbuf = NULL;
3775 static struct slic_rspbuf *slic_rspqueue_getnext(struct adapter *adapter)
3777 struct slic_rspqueue *rspq = &adapter->rspqueue;
3778 struct slic_rspbuf *buf;
3780 if (!(rspq->rspbuf->status))
3784 #ifndef CONFIG_X86_64
3785 ASSERT((buf->status & 0xFFFFFFE0) == 0);
3787 ASSERT(buf->hosthandle);
3788 if (++rspq->offset < SLIC_RSPQ_BUFSINPAGE) {
3790 #ifndef CONFIG_X86_64
3791 ASSERT(((u32) rspq->rspbuf & 0xFFFFFFE0) ==
3792 (u32) rspq->rspbuf);
3795 ASSERT(rspq->offset == SLIC_RSPQ_BUFSINPAGE);
3796 slic_reg64_write(adapter, &adapter->slic_regs->slic_rbar64,
3797 (rspq->paddr[rspq->pageindex] | SLIC_RSPQ_BUFSINPAGE),
3798 &adapter->slic_regs->slic_addr_upper, 0, DONT_FLUSH);
3799 rspq->pageindex = (++rspq->pageindex) % rspq->num_pages;
3801 rspq->rspbuf = (struct slic_rspbuf *)
3802 rspq->vaddr[rspq->pageindex];
3803 #ifndef CONFIG_X86_64
3804 ASSERT(((u32) rspq->rspbuf & 0xFFFFF000) ==
3805 (u32) rspq->rspbuf);
3808 #ifndef CONFIG_X86_64
3809 ASSERT(((u32) buf & 0xFFFFFFE0) == (u32) buf);
3814 static void slic_cmdqmem_init(struct adapter *adapter)
3816 struct slic_cmdqmem *cmdqmem = &adapter->cmdqmem;
3818 memset(cmdqmem, 0, sizeof(struct slic_cmdqmem));
3821 static void slic_cmdqmem_free(struct adapter *adapter)
3823 struct slic_cmdqmem *cmdqmem = &adapter->cmdqmem;
3826 DBG_MSG("slicoss: (%s) adapter[%p] port %d rspq[%p] Free CMDQ Memory\n",
3827 __func__, adapter, adapter->physport, cmdqmem);
3828 for (i = 0; i < SLIC_CMDQ_MAXPAGES; i++) {
3829 if (cmdqmem->pages[i]) {
3830 DBG_MSG("slicoss: %s Deallocate page CmdQPage[%p]\n",
3831 __func__, (void *) cmdqmem->pages[i]);
3832 pci_free_consistent(adapter->pcidev,
3834 (void *) cmdqmem->pages[i],
3835 cmdqmem->dma_pages[i]);
3838 memset(cmdqmem, 0, sizeof(struct slic_cmdqmem));
3841 static u32 *slic_cmdqmem_addpage(struct adapter *adapter)
3843 struct slic_cmdqmem *cmdqmem = &adapter->cmdqmem;
3846 if (cmdqmem->pagecnt >= SLIC_CMDQ_MAXPAGES)
3848 pageaddr = pci_alloc_consistent(adapter->pcidev,
3850 &cmdqmem->dma_pages[cmdqmem->pagecnt]);
3853 #ifndef CONFIG_X86_64
3854 ASSERT(((u32) pageaddr & 0xFFFFF000) == (u32) pageaddr);
3856 cmdqmem->pages[cmdqmem->pagecnt] = pageaddr;
3861 static int slic_cmdq_init(struct adapter *adapter)
3866 DBG_MSG("slicoss: %s ENTER adapter[%p]\n", __func__, adapter);
3867 ASSERT(adapter->state == ADAPT_DOWN);
3868 memset(&adapter->cmdq_all, 0, sizeof(struct slic_cmdqueue));
3869 memset(&adapter->cmdq_free, 0, sizeof(struct slic_cmdqueue));
3870 memset(&adapter->cmdq_done, 0, sizeof(struct slic_cmdqueue));
3871 spin_lock_init(&adapter->cmdq_all.lock.lock);
3872 spin_lock_init(&adapter->cmdq_free.lock.lock);
3873 spin_lock_init(&adapter->cmdq_done.lock.lock);
3874 slic_cmdqmem_init(adapter);
3875 adapter->slic_handle_ix = 1;
3876 for (i = 0; i < SLIC_CMDQ_INITPAGES; i++) {
3877 pageaddr = slic_cmdqmem_addpage(adapter);
3878 #ifndef CONFIG_X86_64
3879 ASSERT(((u32) pageaddr & 0xFFFFF000) == (u32) pageaddr);
3882 slic_cmdq_free(adapter);
3883 return STATUS_FAILURE;
3885 slic_cmdq_addcmdpage(adapter, pageaddr);
3887 adapter->slic_handle_ix = 1;
3888 DBG_MSG("slicoss: %s reset slic_handle_ix to ONE\n", __func__);
3890 return STATUS_SUCCESS;
3893 static void slic_cmdq_free(struct adapter *adapter)
3895 struct slic_hostcmd *cmd;
3897 DBG_MSG("slicoss: %s adapter[%p] port %d FreeCommandsFrom CMDQ\n",
3898 __func__, adapter, adapter->physport);
3899 cmd = adapter->cmdq_all.head;
3902 struct sk_buff *tempskb;
3907 dev_kfree_skb_irq(tempskb);
3910 cmd = cmd->next_all;
3912 memset(&adapter->cmdq_all, 0, sizeof(struct slic_cmdqueue));
3913 memset(&adapter->cmdq_free, 0, sizeof(struct slic_cmdqueue));
3914 memset(&adapter->cmdq_done, 0, sizeof(struct slic_cmdqueue));
3915 slic_cmdqmem_free(adapter);
3918 static void slic_cmdq_reset(struct adapter *adapter)
3920 struct slic_hostcmd *hcmd;
3921 struct sk_buff *skb;
3924 DBG_MSG("%s ENTER adapter[%p]\n", __func__, adapter);
3925 spin_lock_irqsave(&adapter->cmdq_free.lock.lock,
3926 adapter->cmdq_free.lock.flags);
3927 spin_lock_irqsave(&adapter->cmdq_done.lock.lock,
3928 adapter->cmdq_done.lock.flags);
3929 outstanding = adapter->cmdq_all.count - adapter->cmdq_done.count;
3930 outstanding -= adapter->cmdq_free.count;
3931 hcmd = adapter->cmdq_all.head;
3936 DBG_MSG("slicoss: %s hcmd[%p] skb[%p] ", __func__,
3940 DBG_MSG(" Free SKB\n");
3941 dev_kfree_skb_irq(skb);
3943 hcmd = hcmd->next_all;
3945 adapter->cmdq_free.count = 0;
3946 adapter->cmdq_free.head = NULL;
3947 adapter->cmdq_free.tail = NULL;
3948 adapter->cmdq_done.count = 0;
3949 adapter->cmdq_done.head = NULL;
3950 adapter->cmdq_done.tail = NULL;
3951 adapter->cmdq_free.head = adapter->cmdq_all.head;
3952 hcmd = adapter->cmdq_all.head;
3954 adapter->cmdq_free.count++;
3955 hcmd->next = hcmd->next_all;
3956 hcmd = hcmd->next_all;
3958 if (adapter->cmdq_free.count != adapter->cmdq_all.count) {
3959 DBG_ERROR("%s free_count %d != all count %d\n", __func__,
3960 adapter->cmdq_free.count, adapter->cmdq_all.count);
3962 spin_unlock_irqrestore(&adapter->cmdq_done.lock.lock,
3963 adapter->cmdq_done.lock.flags);
3964 spin_unlock_irqrestore(&adapter->cmdq_free.lock.lock,
3965 adapter->cmdq_free.lock.flags);
3966 DBG_MSG("%s EXIT adapter[%p]\n", __func__, adapter);
3969 static void slic_cmdq_addcmdpage(struct adapter *adapter, u32 *page)
3971 struct slic_hostcmd *cmd;
3972 struct slic_hostcmd *prev;
3973 struct slic_hostcmd *tail;
3974 struct slic_cmdqueue *cmdq;
3980 struct slic_handle *pslic_handle;
3983 cmd = (struct slic_hostcmd *)cmdaddr;
3984 /* DBG_MSG("CMDQ Page addr[%p] ix[%d] pfree[%p]\n", cmdaddr, slic_handle_ix,
3985 adapter->pfree_slic_handles); */
3988 phys_addr = virt_to_bus((void *)page);
3989 phys_addrl = SLIC_GET_ADDR_LOW(phys_addr);
3990 phys_addrh = SLIC_GET_ADDR_HIGH(phys_addr);
3994 while ((cmdcnt < SLIC_CMDQ_CMDSINPAGE) &&
3995 (adapter->slic_handle_ix < 256)) {
3996 /* Allocate and initialize a SLIC_HANDLE for this command */
3997 SLIC_GET_SLIC_HANDLE(adapter, pslic_handle);
3998 if (pslic_handle == NULL)
4000 ASSERT(pslic_handle ==
4001 &adapter->slic_handles[pslic_handle->token.
4003 pslic_handle->type = SLIC_HANDLE_CMD;
4004 pslic_handle->address = (void *) cmd;
4005 pslic_handle->offset = (ushort) adapter->slic_handle_ix++;
4006 pslic_handle->other_handle = NULL;
4007 pslic_handle->next = NULL;
4009 cmd->pslic_handle = pslic_handle;
4010 cmd->cmd64.hosthandle = pslic_handle->token.handle_token;
4012 cmd->paddrl = phys_addrl;
4013 cmd->paddrh = phys_addrh;
4014 cmd->next_all = prev;
4017 phys_addrl += SLIC_HOSTCMD_SIZE;
4018 cmdaddr += SLIC_HOSTCMD_SIZE;
4020 cmd = (struct slic_hostcmd *)cmdaddr;
4024 cmdq = &adapter->cmdq_all;
4025 cmdq->count += cmdcnt; /* SLIC_CMDQ_CMDSINPAGE; mooktodo */
4026 tail->next_all = cmdq->head;
4027 ASSERT(VALID_ADDRESS(prev));
4029 cmdq = &adapter->cmdq_free;
4030 spin_lock_irqsave(&cmdq->lock.lock, cmdq->lock.flags);
4031 cmdq->count += cmdcnt; /* SLIC_CMDQ_CMDSINPAGE; mooktodo */
4032 tail->next = cmdq->head;
4033 ASSERT(VALID_ADDRESS(prev));
4035 spin_unlock_irqrestore(&cmdq->lock.lock, cmdq->lock.flags);
4038 static struct slic_hostcmd *slic_cmdq_getfree(struct adapter *adapter)
4040 struct slic_cmdqueue *cmdq = &adapter->cmdq_free;
4041 struct slic_hostcmd *cmd = NULL;
4044 spin_lock_irqsave(&cmdq->lock.lock, cmdq->lock.flags);
4048 cmdq->head = cmd->next;
4050 spin_unlock_irqrestore(&cmdq->lock.lock, cmdq->lock.flags);
4052 slic_cmdq_getdone(adapter);
4059 spin_unlock_irqrestore(&cmdq->lock.lock,
4061 pageaddr = slic_cmdqmem_addpage(adapter);
4063 slic_cmdq_addcmdpage(adapter, pageaddr);
4064 goto lock_and_retry;
4071 static void slic_cmdq_getdone(struct adapter *adapter)
4073 struct slic_cmdqueue *done_cmdq = &adapter->cmdq_done;
4074 struct slic_cmdqueue *free_cmdq = &adapter->cmdq_free;
4076 ASSERT(free_cmdq->head == NULL);
4077 spin_lock_irqsave(&done_cmdq->lock.lock, done_cmdq->lock.flags);
4078 ASSERT(VALID_ADDRESS(done_cmdq->head));
4080 free_cmdq->head = done_cmdq->head;
4081 free_cmdq->count = done_cmdq->count;
4082 done_cmdq->head = NULL;
4083 done_cmdq->tail = NULL;
4084 done_cmdq->count = 0;
4085 spin_unlock_irqrestore(&done_cmdq->lock.lock, done_cmdq->lock.flags);
4088 static void slic_cmdq_putdone_irq(struct adapter *adapter,
4089 struct slic_hostcmd *cmd)
4091 struct slic_cmdqueue *cmdq = &adapter->cmdq_done;
4093 spin_lock(&cmdq->lock.lock);
4095 ASSERT(VALID_ADDRESS(cmdq->head));
4096 cmd->next = cmdq->head;
4097 ASSERT(VALID_ADDRESS(cmd));
4100 if ((adapter->xmitq_full) && (cmdq->count > 10))
4101 netif_wake_queue(adapter->netdev);
4102 spin_unlock(&cmdq->lock.lock);
4105 static int slic_rcvqueue_init(struct adapter *adapter)
4108 struct slic_rcvqueue *rcvq = &adapter->rcvqueue;
4110 DBG_MSG("slicoss: %s ENTER adapter[%p]\n", __func__, adapter);
4111 ASSERT(adapter->state == ADAPT_DOWN);
4114 rcvq->size = SLIC_RCVQ_ENTRIES;
4117 i = (SLIC_RCVQ_ENTRIES / SLIC_RCVQ_FILLENTRIES);
4120 count += slic_rcvqueue_fill(adapter);
4123 if (rcvq->count < SLIC_RCVQ_MINENTRIES) {
4124 slic_rcvqueue_free(adapter);
4125 return STATUS_FAILURE;
4127 DBG_MSG("slicoss: %s EXIT adapter[%p]\n", __func__, adapter);
4128 return STATUS_SUCCESS;
4131 static int slic_rcvqueue_reset(struct adapter *adapter)
4133 struct slic_rcvqueue *rcvq = &adapter->rcvqueue;
4135 DBG_MSG("slicoss: %s ENTER adapter[%p]\n", __func__, adapter);
4136 ASSERT(adapter->state == ADAPT_DOWN);
4139 DBG_MSG("slicoss: Nothing to do. rcvq[%p]\n"
4143 rcvq, rcvq->count, rcvq->head, rcvq->tail);
4145 DBG_MSG("slicoss: %s EXIT adapter[%p]\n", __func__, adapter);
4146 return STATUS_SUCCESS;
4149 static void slic_rcvqueue_free(struct adapter *adapter)
4151 struct slic_rcvqueue *rcvq = &adapter->rcvqueue;
4152 struct sk_buff *skb;
4154 while (rcvq->head) {
4156 rcvq->head = rcvq->head->next;
4164 static struct sk_buff *slic_rcvqueue_getnext(struct adapter *adapter)
4166 struct slic_rcvqueue *rcvq = &adapter->rcvqueue;
4167 struct sk_buff *skb;
4168 struct slic_rcvbuf *rcvbuf;
4173 rcvbuf = (struct slic_rcvbuf *)skb->head;
4176 if (rcvbuf->status & IRHDDR_SVALID) {
4177 rcvq->head = rcvq->head->next;
4184 DBG_ERROR("RcvQ Empty!! adapter[%p] rcvq[%p] count[%x]\n",
4185 adapter, rcvq, rcvq->count);
4188 while (rcvq->count < SLIC_RCVQ_FILLTHRESH) {
4189 count = slic_rcvqueue_fill(adapter);
4198 static int slic_rcvqueue_fill(struct adapter *adapter)
4203 struct slic_rcvqueue *rcvq = &adapter->rcvqueue;
4206 while (i < SLIC_RCVQ_FILLENTRIES) {
4207 struct slic_rcvbuf *rcvbuf;
4208 struct sk_buff *skb;
4209 #ifdef KLUDGE_FOR_4GB_BOUNDARY
4212 skb = alloc_skb(SLIC_RCVQ_RCVBUFSIZE, GFP_ATOMIC);
4214 paddr = (void *)pci_map_single(adapter->pcidev,
4216 SLIC_RCVQ_RCVBUFSIZE,
4217 PCI_DMA_FROMDEVICE);
4218 paddrl = SLIC_GET_ADDR_LOW(paddr);
4219 paddrh = SLIC_GET_ADDR_HIGH(paddr);
4221 skb->len = SLIC_RCVBUF_HEADSIZE;
4222 rcvbuf = (struct slic_rcvbuf *)skb->head;
4225 #ifdef KLUDGE_FOR_4GB_BOUNDARY
4228 ("%s: LOW 32bits PHYSICAL ADDRESS == 0 "
4234 " paddrh[%x]\n", __func__, skb,
4235 skb->data, skb->len, paddr, paddrl,
4237 DBG_ERROR(" rcvq->head[%p]\n"
4239 " rcvq->count[%x]\n",
4240 rcvq->head, rcvq->tail, rcvq->count);
4241 DBG_ERROR("SKIP THIS SKB!!!!!!!!\n");
4242 goto retry_rcvqfill;
4247 ("\n\n%s: LOW 32bits PHYSICAL ADDRESS == 0 "
4248 "skb[%p] GIVE TO CARD ANYWAY\n"
4252 " paddrh[%x]\n", __func__, skb,
4253 skb->data, paddr, paddrl, paddrh);
4257 slic_reg32_write(&adapter->slic_regs->slic_hbar,
4258 (u32)paddrl, DONT_FLUSH);
4260 slic_reg64_write(adapter,
4261 &adapter->slic_regs->slic_hbar64,
4263 &adapter->slic_regs->slic_addr_upper,
4264 paddrh, DONT_FLUSH);
4267 rcvq->tail->next = skb;
4275 ("%s slic_rcvqueue_fill could only get [%d] "
4277 adapter->netdev->name, i);
4284 static u32 slic_rcvqueue_reinsert(struct adapter *adapter, struct sk_buff *skb)
4286 struct slic_rcvqueue *rcvq = &adapter->rcvqueue;
4290 struct slic_rcvbuf *rcvbuf = (struct slic_rcvbuf *)skb->head;
4292 ASSERT(skb->len == SLIC_RCVBUF_HEADSIZE);
4294 paddr = (void *)pci_map_single(adapter->pcidev, skb->head,
4295 SLIC_RCVQ_RCVBUFSIZE, PCI_DMA_FROMDEVICE);
4299 paddrl = SLIC_GET_ADDR_LOW(paddr);
4300 paddrh = SLIC_GET_ADDR_HIGH(paddr);
4304 ("%s: LOW 32bits PHYSICAL ADDRESS == 0 skb[%p] PROBLEM\n"
4305 " skbdata[%p]\n" " skblen[%x]\n"
4306 " paddr[%p]\n" " paddrl[%x]\n"
4307 " paddrh[%x]\n", __func__, skb, skb->data,
4308 skb->len, paddr, paddrl, paddrh);
4309 DBG_ERROR(" rcvq->head[%p]\n"
4311 " rcvq->count[%x]\n", rcvq->head, rcvq->tail,
4315 slic_reg32_write(&adapter->slic_regs->slic_hbar, (u32)paddrl,
4318 slic_reg64_write(adapter, &adapter->slic_regs->slic_hbar64,
4319 paddrl, &adapter->slic_regs->slic_addr_upper,
4320 paddrh, DONT_FLUSH);
4323 rcvq->tail->next = skb;
4331 static int slic_debug_card_show(struct seq_file *seq, void *v)
4335 struct sliccard *card = seq->private;
4336 struct slic_config *config = &card->config;
4337 unsigned char *fru = (unsigned char *)(&card->config.atk_fru);
4338 unsigned char *oemfru = (unsigned char *)(&card->config.OemFru);
4341 seq_printf(seq, "driver_version : %s\n", slic_proc_version);
4342 seq_printf(seq, "Microcode versions: \n");
4343 seq_printf(seq, " Gigabit (gb) : %s %s\n",
4344 MOJAVE_UCODE_VERS_STRING, MOJAVE_UCODE_VERS_DATE);
4345 seq_printf(seq, " Gigabit Receiver : %s %s\n",
4346 GB_RCVUCODE_VERS_STRING, GB_RCVUCODE_VERS_DATE);
4347 seq_printf(seq, "Vendor : %s\n", slic_vendor);
4348 seq_printf(seq, "Product Name : %s\n", slic_product_name);
4350 seq_printf(seq, "VendorId : %4.4X\n",
4352 seq_printf(seq, "DeviceId : %4.4X\n",
4354 seq_printf(seq, "RevisionId : %2.2x\n",
4355 config->RevisionId);
4356 seq_printf(seq, "Bus # : %d\n", card->busnumber);
4357 seq_printf(seq, "Device # : %d\n", card->slotnumber);
4358 seq_printf(seq, "Interfaces : %d\n", card->card_size);
4359 seq_printf(seq, " Initialized : %d\n",
4360 card->adapters_activated);
4361 seq_printf(seq, " Allocated : %d\n",
4362 card->adapters_allocated);
4363 ASSERT(card->card_size <= SLIC_NBR_MACS);
4364 for (i = 0; i < card->card_size; i++) {
4366 " MAC%d : %2.2X %2.2X %2.2X %2.2X %2.2X %2.2X\n",
4367 i, config->macinfo[i].macaddrA[0],
4368 config->macinfo[i].macaddrA[1],
4369 config->macinfo[i].macaddrA[2],
4370 config->macinfo[i].macaddrA[3],
4371 config->macinfo[i].macaddrA[4],
4372 config->macinfo[i].macaddrA[5]);
4374 seq_printf(seq, " IF Init State Duplex/Speed irq\n");
4375 seq_printf(seq, " -------------------------------\n");
4376 for (i = 0; i < card->adapters_allocated; i++) {
4377 struct adapter *adapter;
4379 adapter = card->adapter[i];
4382 " %d %d %s %s %s 0x%X\n",
4383 adapter->physport, adapter->state,
4384 SLIC_LINKSTATE(adapter->linkstate),
4385 SLIC_DUPLEX(adapter->linkduplex),
4386 SLIC_SPEED(adapter->linkspeed),
4387 (uint) adapter->irq);
4390 seq_printf(seq, "Generation # : %4.4X\n", card->gennumber);
4391 seq_printf(seq, "RcvQ max entries : %4.4X\n",
4393 seq_printf(seq, "Ping Status : %8.8X\n",
4395 seq_printf(seq, "Minimum grant : %2.2x\n",
4397 seq_printf(seq, "Maximum Latency : %2.2x\n", config->MaxLat);
4398 seq_printf(seq, "PciStatus : %4.4x\n",
4400 seq_printf(seq, "Debug Device Id : %4.4x\n",
4402 seq_printf(seq, "DRAM ROM Function : %4.4x\n",
4404 seq_printf(seq, "Network interface Pin 1 : %2.2x\n",
4405 config->NetIntPin1);
4406 seq_printf(seq, "Network interface Pin 2 : %2.2x\n",
4407 config->NetIntPin1);
4408 seq_printf(seq, "Network interface Pin 3 : %2.2x\n",
4409 config->NetIntPin1);
4410 seq_printf(seq, "PM capabilities : %4.4X\n",
4412 seq_printf(seq, "Network Clock Controls : %4.4X\n",
4413 config->NwClkCtrls);
4415 switch (config->FruFormat) {
4416 case ATK_FRU_FORMAT:
4419 "Vendor : Alacritech, Inc.\n");
4421 "Assembly # : %c%c%c%c%c%c\n",
4422 fru[0], fru[1], fru[2], fru[3], fru[4],
4425 "Revision # : %c%c\n",
4428 if (config->OEMFruFormat == VENDOR4_FRU_FORMAT) {
4431 "%c%c%c%c%c%c%c%c%c%c%c%c\n",
4432 fru[8], fru[9], fru[10],
4433 fru[11], fru[12], fru[13],
4434 fru[16], fru[17], fru[18],
4435 fru[19], fru[20], fru[21]);
4439 "%c%c%c%c%c%c%c%c%c%c%c%c%c%c\n",
4440 fru[8], fru[9], fru[10],
4441 fru[11], fru[12], fru[13],
4442 fru[14], fru[15], fru[16],
4443 fru[17], fru[18], fru[19],
4452 "Vendor : Alacritech, Inc.\n");
4454 "Serial # : Empty FRU\n");
4459 switch (config->OEMFruFormat) {
4460 case VENDOR1_FRU_FORMAT:
4462 seq_printf(seq, "FRU Information:\n");
4463 seq_printf(seq, " Commodity # : %c\n",
4466 " Assembly # : %c%c%c%c\n",
4467 oemfru[1], oemfru[2], oemfru[3], oemfru[4]);
4469 " Revision # : %c%c\n",
4470 oemfru[5], oemfru[6]);
4472 " Supplier # : %c%c\n",
4473 oemfru[7], oemfru[8]);
4476 oemfru[9], oemfru[10]);
4478 " Sequence # : %c%c%c\n",
4479 oemfru[11], oemfru[12], oemfru[13]);
4483 case VENDOR2_FRU_FORMAT:
4485 seq_printf(seq, "FRU Information:\n");
4488 "%c%c%c%c%c%c%c%c\n",
4489 oemfru[0], oemfru[1], oemfru[2],
4490 oemfru[3], oemfru[4], oemfru[5],
4491 oemfru[6], oemfru[7]);
4493 " Supplier # : %c%c%c%c%c\n",
4494 oemfru[8], oemfru[9], oemfru[10],
4495 oemfru[11], oemfru[12]);
4498 oemfru[13], oemfru[14], oemfru[15]);
4500 " Sequence # : %c%c%c%c\n",
4501 oemfru[16], oemfru[17], oemfru[18],
4506 case VENDOR3_FRU_FORMAT:
4508 seq_printf(seq, "FRU Information:\n");
4511 case VENDOR4_FRU_FORMAT:
4513 seq_printf(seq, "FRU Information:\n");
4516 "%c%c%c%c%c%c%c%c\n",
4517 oemfru[0], oemfru[1], oemfru[2],
4518 oemfru[3], oemfru[4], oemfru[5],
4519 oemfru[6], oemfru[7]);
4522 "%c%c%c%c%c%c%c%c\n",
4523 oemfru[8], oemfru[9], oemfru[10],
4524 oemfru[11], oemfru[12], oemfru[13],
4525 oemfru[14], oemfru[15]);
4528 "%c%c%c%c%c%c%c%c\n",
4529 oemfru[16], oemfru[17], oemfru[18],
4530 oemfru[19], oemfru[20], oemfru[21],
4531 oemfru[22], oemfru[23]);
4543 static int slic_debug_adapter_show(struct seq_file *seq, void *v)
4545 struct adapter *adapter = seq->private;
4547 if ((adapter->netdev) && (adapter->netdev->name)) {
4548 seq_printf(seq, "info: interface : %s\n",
4549 adapter->netdev->name);
4551 seq_printf(seq, "info: status : %s\n",
4552 SLIC_LINKSTATE(adapter->linkstate));
4553 seq_printf(seq, "info: port : %d\n",
4555 seq_printf(seq, "info: speed : %s\n",
4556 SLIC_SPEED(adapter->linkspeed));
4557 seq_printf(seq, "info: duplex : %s\n",
4558 SLIC_DUPLEX(adapter->linkduplex));
4559 seq_printf(seq, "info: irq : 0x%X\n",
4560 (uint) adapter->irq);
4561 seq_printf(seq, "info: Interrupt Agg Delay: %d usec\n",
4562 adapter->card->loadlevel_current);
4563 seq_printf(seq, "info: RcvQ max entries : %4.4X\n",
4565 seq_printf(seq, "info: RcvQ current : %4.4X\n",
4566 adapter->rcvqueue.count);
4567 seq_printf(seq, "rx stats: packets : %8.8lX\n",
4568 adapter->stats.rx_packets);
4569 seq_printf(seq, "rx stats: bytes : %8.8lX\n",
4570 adapter->stats.rx_bytes);
4571 seq_printf(seq, "rx stats: broadcasts : %8.8X\n",
4572 adapter->rcv_broadcasts);
4573 seq_printf(seq, "rx stats: multicasts : %8.8X\n",
4574 adapter->rcv_multicasts);
4575 seq_printf(seq, "rx stats: unicasts : %8.8X\n",
4576 adapter->rcv_unicasts);
4577 seq_printf(seq, "rx stats: errors : %8.8X\n",
4578 (u32) adapter->slic_stats.iface.rcv_errors);
4579 seq_printf(seq, "rx stats: Missed errors : %8.8X\n",
4580 (u32) adapter->slic_stats.iface.rcv_discards);
4581 seq_printf(seq, "rx stats: drops : %8.8X\n",
4582 (u32) adapter->rcv_drops);
4583 seq_printf(seq, "tx stats: packets : %8.8lX\n",
4584 adapter->stats.tx_packets);
4585 seq_printf(seq, "tx stats: bytes : %8.8lX\n",
4586 adapter->stats.tx_bytes);
4587 seq_printf(seq, "tx stats: errors : %8.8X\n",
4588 (u32) adapter->slic_stats.iface.xmt_errors);
4589 seq_printf(seq, "rx stats: multicasts : %8.8lX\n",
4590 adapter->stats.multicast);
4591 seq_printf(seq, "tx stats: collision errors : %8.8X\n",
4592 (u32) adapter->slic_stats.iface.xmit_collisions);
4593 seq_printf(seq, "perf: Max rcv frames/isr : %8.8X\n",
4594 adapter->max_isr_rcvs);
4595 seq_printf(seq, "perf: Rcv interrupt yields : %8.8X\n",
4596 adapter->rcv_interrupt_yields);
4597 seq_printf(seq, "perf: Max xmit complete/isr : %8.8X\n",
4598 adapter->max_isr_xmits);
4599 seq_printf(seq, "perf: error interrupts : %8.8X\n",
4600 adapter->error_interrupts);
4601 seq_printf(seq, "perf: error rmiss interrupts : %8.8X\n",
4602 adapter->error_rmiss_interrupts);
4603 seq_printf(seq, "perf: rcv interrupts : %8.8X\n",
4604 adapter->rcv_interrupts);
4605 seq_printf(seq, "perf: xmit interrupts : %8.8X\n",
4606 adapter->xmit_interrupts);
4607 seq_printf(seq, "perf: link event interrupts : %8.8X\n",
4608 adapter->linkevent_interrupts);
4609 seq_printf(seq, "perf: UPR interrupts : %8.8X\n",
4610 adapter->upr_interrupts);
4611 seq_printf(seq, "perf: interrupt count : %8.8X\n",
4613 seq_printf(seq, "perf: false interrupts : %8.8X\n",
4614 adapter->false_interrupts);
4615 seq_printf(seq, "perf: All register writes : %8.8X\n",
4616 adapter->all_reg_writes);
4617 seq_printf(seq, "perf: ICR register writes : %8.8X\n",
4618 adapter->icr_reg_writes);
4619 seq_printf(seq, "perf: ISR register writes : %8.8X\n",
4620 adapter->isr_reg_writes);
4621 seq_printf(seq, "ifevents: overflow 802 errors : %8.8X\n",
4622 adapter->if_events.oflow802);
4623 seq_printf(seq, "ifevents: transport overflow errors: %8.8X\n",
4624 adapter->if_events.Tprtoflow);
4625 seq_printf(seq, "ifevents: underflow errors : %8.8X\n",
4626 adapter->if_events.uflow802);
4627 seq_printf(seq, "ifevents: receive early : %8.8X\n",
4628 adapter->if_events.rcvearly);
4629 seq_printf(seq, "ifevents: buffer overflows : %8.8X\n",
4630 adapter->if_events.Bufov);
4631 seq_printf(seq, "ifevents: carrier errors : %8.8X\n",
4632 adapter->if_events.Carre);
4633 seq_printf(seq, "ifevents: Long : %8.8X\n",
4634 adapter->if_events.Longe);
4635 seq_printf(seq, "ifevents: invalid preambles : %8.8X\n",
4636 adapter->if_events.Invp);
4637 seq_printf(seq, "ifevents: CRC errors : %8.8X\n",
4638 adapter->if_events.Crc);
4639 seq_printf(seq, "ifevents: dribble nibbles : %8.8X\n",
4640 adapter->if_events.Drbl);
4641 seq_printf(seq, "ifevents: Code violations : %8.8X\n",
4642 adapter->if_events.Code);
4643 seq_printf(seq, "ifevents: TCP checksum errors : %8.8X\n",
4644 adapter->if_events.TpCsum);
4645 seq_printf(seq, "ifevents: TCP header short errors : %8.8X\n",
4646 adapter->if_events.TpHlen);
4647 seq_printf(seq, "ifevents: IP checksum errors : %8.8X\n",
4648 adapter->if_events.IpCsum);
4649 seq_printf(seq, "ifevents: IP frame incompletes : %8.8X\n",
4650 adapter->if_events.IpLen);
4651 seq_printf(seq, "ifevents: IP headers shorts : %8.8X\n",
4652 adapter->if_events.IpHlen);
4656 static int slic_debug_adapter_open(struct inode *inode, struct file *file)
4658 return single_open(file, slic_debug_adapter_show, inode->i_private);
4661 static int slic_debug_card_open(struct inode *inode, struct file *file)
4663 return single_open(file, slic_debug_card_show, inode->i_private);
4666 static const struct file_operations slic_debug_adapter_fops = {
4667 .owner = THIS_MODULE,
4668 .open = slic_debug_adapter_open,
4670 .llseek = seq_lseek,
4671 .release = single_release,
4674 static const struct file_operations slic_debug_card_fops = {
4675 .owner = THIS_MODULE,
4676 .open = slic_debug_card_open,
4678 .llseek = seq_lseek,
4679 .release = single_release,
4682 static void slic_debug_adapter_create(struct adapter *adapter)
4686 struct sliccard *card = adapter->card;
4688 if (!card->debugfs_dir)
4691 sprintf(name, "port%d", adapter->port);
4692 d = debugfs_create_file(name, S_IRUGO,
4693 card->debugfs_dir, adapter,
4694 &slic_debug_adapter_fops);
4695 if (!d || IS_ERR(d))
4696 pr_info(PFX "%s: debugfs create failed\n", name);
4698 adapter->debugfs_entry = d;
4701 static void slic_debug_adapter_destroy(struct adapter *adapter)
4703 if (adapter->debugfs_entry) {
4704 debugfs_remove(adapter->debugfs_entry);
4705 adapter->debugfs_entry = NULL;
4709 static void slic_debug_card_create(struct sliccard *card)
4712 char name[IFNAMSIZ];
4714 snprintf(name, sizeof(name), "slic%d", card->cardnum);
4715 d = debugfs_create_dir(name, slic_debugfs);
4716 if (!d || IS_ERR(d))
4717 pr_info(PFX "%s: debugfs create dir failed\n",
4720 card->debugfs_dir = d;
4721 d = debugfs_create_file("cardinfo", S_IRUGO,
4723 &slic_debug_card_fops);
4724 if (!d || IS_ERR(d))
4725 pr_info(PFX "%s: debugfs create failed\n",
4728 card->debugfs_cardinfo = d;
4732 static void slic_debug_card_destroy(struct sliccard *card)
4736 for (i = 0; i < card->card_size; i++) {
4737 struct adapter *adapter;
4739 adapter = card->adapter[i];
4741 slic_debug_adapter_destroy(adapter);
4743 if (card->debugfs_cardinfo) {
4744 debugfs_remove(card->debugfs_cardinfo);
4745 card->debugfs_cardinfo = NULL;
4747 if (card->debugfs_dir) {
4748 debugfs_remove(card->debugfs_dir);
4749 card->debugfs_dir = NULL;
4753 static void slic_debug_init(void)
4757 ent = debugfs_create_dir("slic", NULL);
4758 if (!ent || IS_ERR(ent)) {
4759 pr_info(PFX "debugfs create directory failed\n");
4766 static void slic_debug_cleanup(void)
4769 debugfs_remove(slic_debugfs);
4770 slic_debugfs = NULL;
4774 /*=============================================================================
4775 =============================================================================
4777 === SLIC DUMP MANAGEMENT SECTION ===
4780 === Dump routines ===
4783 =============================================================================
4784 ============================================================================*/
4786 #if SLIC_DUMP_ENABLED
4790 void *slic_dump_handle; /* thread handle */
4793 * These are the only things you should do on a core-file: use only these
4794 * functions to write out all the necessary info.
4796 static int slic_dump_seek(struct file *SLIChandle, u32 file_offset)
4798 if (SLIChandle->f_pos != file_offset) {
4799 /*DBG_MSG("slic_dump_seek now needed [%x : %x]\n",
4800 (u32)SLIChandle->f_pos, (u32)file_offset); */
4801 if (SLIChandle->f_op->llseek) {
4802 if (SLIChandle->f_op->
4803 llseek(SLIChandle, file_offset, 0) != file_offset)
4806 SLIChandle->f_pos = file_offset;
4812 static int slic_dump_write(struct sliccard *card,
4813 const void *addr, int size, u32 file_offset)
4817 struct file *SLIChandle = card->dumphandle;
4819 #ifdef HISTORICAL /* legacy */
4820 down(&SLIChandle->f_dentry->d_inode->i_sem);
4823 slic_dump_seek(SLIChandle, file_offset);
4826 SLIChandle->f_op->write(SLIChandle, addr, size,
4827 &SLIChandle->f_pos);
4832 card->dumptime_complete = jiffies;
4833 card->dumptime_delta = card->dumptime_complete - card->dumptime_start;
4834 card->dumptime_start = jiffies;
4837 up(&SLIChandle->f_dentry->d_inode->i_sem);
4840 DBG_ERROR("%s: addr[%p] size[%x] result[%x] file_offset[%x]\n",
4841 __func__, addr, size, result, file_offset);
4846 static uint slic_init_dump_thread(struct sliccard *card)
4848 card->dump_task_id = kthread_run(slic_dump_thread, (void *)card, 0);
4850 /* DBG_MSG("create slic_dump_thread dump_pid[%x]\n", card->dump_pid); */
4851 if (IS_ERR(card->dump_task_id)) {
4852 DBG_MSG("create slic_dump_thread FAILED \n");
4853 return STATUS_FAILURE;
4856 return STATUS_SUCCESS;
4859 static int slic_dump_thread(void *context)
4861 struct sliccard *card = (struct sliccard *)context;
4862 struct adapter *adapter;
4863 struct adapter *dump_adapter = NULL;
4864 u32 dump_complete = 0;
4865 u32 delay = (PING_TIMER_INTERVAL * HZ);
4866 struct slic_regs *pregs;
4868 struct slic_upr *upr, *uprnext;
4873 card->dumpthread_running = 1;
4878 * This thread doesn't need any user-level access,
4879 * so get rid of all our resources
4881 exit_files(current); /* daemonize doesn't do exit_files */
4882 current->files = init_task.files;
4883 atomic_inc(¤t->files->count);
4886 daemonize("%s", "slicmon");
4888 /* Setup a nice name */
4889 strcpy(current->comm, "slicmon");
4891 ("slic_dump_thread[slicmon] daemon is alive card[%p] pid[%x]\n",
4892 card, card->dump_task_id->pid);
4895 * Send me a signal to get me to die (for debugging)
4899 * If card state is not set to up, skip
4901 if (card->state != CARD_UP) {
4902 if (card->adapters_activated)
4908 * Check the results of our last ping.
4911 #ifdef SLIC_FAILURE_DUMP
4912 if (card->pingstatus != ISR_PINGMASK) {
4914 ("\n[slicmon] CARD #%d TIMED OUT - status "
4915 "%x: DUMP THE CARD!\n",
4916 card->cardnum, card->pingstatus);
4921 * Cause a card RESET instead?
4923 if (card->pingstatus != ISR_PINGMASK) {
4924 /* todo. do we want to reset the card in production */
4925 /* DBG_MSG("\n[slicmon] CARD #%d TIMED OUT - "
4926 status %x: RESET THE CARD!\n", card->cardnum,
4927 card->pingstatus); */
4929 ("\n[slicmon] CARD #%d TIMED OUT - status %x: "
4931 card->cardnum, card->pingstatus);
4936 || (card->dump_requested == SLIC_DUMP_REQUESTED)) {
4937 if (card->dump_requested == SLIC_DUMP_REQUESTED) {
4939 ("[slicmon]: Dump card Requested: Card %x\n",
4942 if (card->pingstatus != ISR_PINGMASK) {
4946 if (card->adapter[0]) {
4947 if ((card->adapter[0])->memorylength >=
4949 sizeof(slic_crash_info)) {
4951 p_slic_crash_info crashinfo;
4954 ((char *)card->adapter[0]->
4960 cpuid = crashinfo->cpu_id;
4961 crashpc = crashinfo->crash_pc;
4965 ("[slicmon]: Dump card: Card %x crashed "
4966 "and failed to answer PING. "
4967 "CPUID[%x] PC[%x]\n ",
4968 card->cardnum, cpuid, crashpc);
4971 card->dump_requested = SLIC_DUMP_IN_PROGRESS;
4974 * Set the card state to DOWN and the adapter states
4975 * to RESET.They will check this in SimbaCheckForHang
4976 * and initiate interface reset (which in turn will
4977 * reinitialize the card).
4979 card->state = CARD_DOWN;
4981 for (i = 0; i < card->card_size; i++) {
4982 adapter = card->adapter[i];
4984 slic_if_stop_queue(adapter);
4986 if (adapter->state == ADAPT_UP) {
4987 adapter->state = ADAPT_RESET;
4988 adapter->linkstate = LINK_DOWN;
4990 ("[slicmon]: SLIC Card[%d] "
4991 "Port[%d] adapter[%p] "
4993 (uint) card->cardnum,
4996 #if SLIC_GET_STATS_TIMER_ENABLED
4997 /* free stats timer */
4998 if (adapter->statstimerset) {
4999 adapter->statstimerset = 0;
5000 del_timer(&adapter->statstimer);
5006 for (i = 0; i < card->card_size; i++) {
5007 adapter = card->adapter[i];
5008 if ((adapter) && (adapter->activated)) {
5009 pregs = adapter->slic_regs;
5010 dump_adapter = adapter;
5013 * If the dump status is zero, then
5014 * the utility processor has crashed.
5015 * If this is the case, any pending
5016 * utilityprocessor requests will not
5017 * complete and our dump commands will
5020 * To avoid this we will clear any
5021 * pending utility processor requests
5024 if (!card->pingstatus) {
5026 &adapter->upr_lock.lock,
5027 adapter->upr_lock.flags);
5028 upr = adapter->upr_list;
5030 uprnext = upr->next;
5034 adapter->upr_list = 0;
5035 adapter->upr_busy = 0;
5036 spin_unlock_irqrestore(
5037 &adapter->upr_lock.lock,
5038 adapter->upr_lock.flags);
5041 slic_dump_card(card, false);
5045 if (dump_complete) {
5046 DBG_ERROR("SLIC Dump Complete\n");
5047 /* Only dump the card one time */
5054 ("slic dump completed. "
5055 "Reenable interfaces\n");
5056 slic_card_init(card, dump_adapter);
5059 * Reenable the adapters that were reset
5061 for (i = 0; i < card->card_size; i++) {
5062 adapter = card->adapter[i];
5064 if (adapter->state ==
5068 "Card[%d] Port[%d] adapter[%p] "
5075 adapter->linkstate =
5083 card->dump_requested = SLIC_DUMP_DONE;
5086 /* if pingstatus != ISR_PINGMASK) || dump_requested...ELSE
5087 * We received a valid ping response.
5088 * Clear the Pingstatus field, find a valid adapter
5089 * structure and send another ping.
5091 for (i = 0; i < card->card_size; i++) {
5092 adapter = card->adapter[i];
5093 if (adapter && (adapter->state == ADAPT_UP)) {
5094 card->pingstatus = 0;
5095 slic_upr_request(adapter, SLIC_UPR_PING,
5097 break; /* Only issue one per card */
5102 SLIC_INTERRUPTIBLE_SLEEP_ON_TIMEOUT(card->dump_wq, delay);
5103 } while (!signal_pending(current));
5106 /* DBG_MSG("[slicmon] slic_dump_thread card[%p] pid[%x] ENDING\n",
5107 card, card->dump_pid); */
5108 card->dumpthread_running = 0;
5114 * Read a single byte from our dump index file. This
5115 * value is used as our suffix for our dump path. The
5116 * value is incremented and written back to the file
5118 static unsigned char slic_get_dump_index(char *path)
5120 unsigned char index = 0;
5121 #ifdef SLIC_DUMP_INDEX_SUPPORT
5129 * Open the index file. If one doesn't exist, create it
5131 status = create_file(&FileHandle);
5133 if (status != STATUS_SUCCESS)
5134 return (unsigned char) 0;
5136 status = read_file(FileHandle, &index, 1, &offset);
5140 status = write_file(FileHandle, &index, 1, &offset);
5142 close_file(FileHandle);
5149 static struct file *slic_dump_open_file(struct sliccard *card)
5151 struct file *SLIChandle = NULL;
5152 struct dentry *dentry = NULL;
5153 struct inode *inode = NULL;
5156 card->dumpfile_fs = get_fs();
5160 memset(SLICfile, 0, sizeof(SLICfile));
5161 sprintf(SLICfile, "/var/tmp/slic%d-dump-%d", card->cardnum,
5162 (uint) card->dump_count);
5166 filp_open(SLICfile, O_CREAT | O_RDWR | O_SYNC | O_LARGEFILE, 0666);
5168 DBG_MSG("[slicmon]: Dump Card #%d to file: %s \n", card->cardnum,
5171 /* DBG_MSG("[slicmon] filp_open %s SLIChandle[%p]\n", SLICfile, SLIChandle);*/
5173 if (IS_ERR(SLIChandle))
5176 dentry = SLIChandle->f_dentry;
5177 inode = dentry->d_inode;
5179 /* DBG_MSG("[slicmon] inode[%p] i_nlink[%x] i_mode[%x] i_op[%p] i_fop[%p]\n"
5180 "f_op->write[%p]\n",
5181 inode, inode->i_nlink, inode->i_mode, inode->i_op,
5182 inode->i_fop, SLIChandle->f_op->write); */
5183 if (inode->i_nlink > 1)
5184 goto close_slicdump; /* multiple links - don't dump */
5186 if (!S_ISREG(inode->i_mode))
5187 goto close_slicdump;
5189 if (!inode->i_op || !inode->i_fop)
5190 goto close_slicdump;
5192 if (!SLIChandle->f_op->write)
5193 goto close_slicdump;
5196 * If we got here we have SUCCESSFULLY OPENED the dump file
5198 /* DBG_MSG("opened %s SLIChandle[%p]\n", SLICfile, SLIChandle); */
5202 DBG_MSG("[slicmon] slic_dump_open_file failed close SLIChandle[%p]\n",
5204 filp_close(SLIChandle, NULL);
5207 set_fs(card->dumpfile_fs);
5212 static void slic_dump_close_file(struct sliccard *card)
5215 /* DBG_MSG("[slicmon] slic_dump_CLOSE_file close SLIChandle[%p]\n",
5216 card->dumphandle); */
5218 filp_close(card->dumphandle, NULL);
5220 set_fs(card->dumpfile_fs);
5223 static u32 slic_dump_card(struct sliccard *card, bool resume)
5225 struct adapter *adapter = card->master;
5229 u32 sram_size, dram_size, regs;
5230 struct sliccore_hdr corehdr;
5237 card->dumphandle = slic_dump_open_file(card);
5239 if (card->dumphandle == NULL) {
5240 DBG_MSG("[slicmon] Cant create Dump file - dump failed\n");
5243 if (!card->dumpbuffer) {
5244 DBG_MSG("[slicmon] Insufficient memory for dump\n");
5247 if (!card->cmdbuffer) {
5248 DBG_MSG("[slicmon] Insufficient cmd memory for dump\n");
5253 * Write the file version to the core header.
5255 namestr = slic_proc_version;
5256 for (i = 0; i < (DRIVER_NAME_SIZE - 1); i++, namestr++) {
5259 corehdr.driver_version[i] = *namestr;
5261 corehdr.driver_version[i] = 0;
5263 file_offset = sizeof(struct sliccore_hdr);
5266 * Issue the following debug commands to the SLIC:
5267 * - Halt both receive and transmit
5268 * - Dump receive registers
5269 * - Dump transmit registers
5274 DBG_MSG("slicDump HALT Receive Processor\n");
5275 card->dumptime_start = jiffies;
5277 status = slic_dump_halt(card, PROC_RECEIVE);
5278 if (status != STATUS_SUCCESS) {
5280 ("Cant halt receive sequencer - dump failed status[%x]\n",
5285 DBG_MSG("slicDump HALT Transmit Processor\n");
5286 status = slic_dump_halt(card, PROC_TRANSMIT);
5287 if (status != STATUS_SUCCESS) {
5288 DBG_ERROR("Cant halt transmit sequencer - dump failed\n");
5292 /* Dump receive regs */
5293 status = slic_dump_reg(card, PROC_RECEIVE);
5294 if (status != STATUS_SUCCESS) {
5295 DBG_ERROR("Cant dump receive registers - dump failed\n");
5299 DBG_MSG("slicDump Write Receive REGS len[%x] offset[%x]\n",
5300 (SLIC_NUM_REG * 4), file_offset);
5303 slic_dump_write(card, card->dumpbuffer, SLIC_NUM_REG * 4,
5307 ("Cant write rcv registers to dump file - dump failed\n");
5311 corehdr.RcvRegOff = file_offset;
5312 corehdr.RcvRegsize = SLIC_NUM_REG * 4;
5313 file_offset += SLIC_NUM_REG * 4;
5315 /* Dump transmit regs */
5316 status = slic_dump_reg(card, PROC_TRANSMIT);
5317 if (status != STATUS_SUCCESS) {
5318 DBG_ERROR("Cant dump transmit registers - dump failed\n");
5322 DBG_MSG("slicDump Write XMIT REGS len[%x] offset[%x]\n",
5323 (SLIC_NUM_REG * 4), file_offset);
5326 slic_dump_write(card, card->dumpbuffer, SLIC_NUM_REG * 4,
5330 ("Cant write xmt registers to dump file - dump failed\n");
5334 corehdr.XmtRegOff = file_offset;
5335 corehdr.XmtRegsize = SLIC_NUM_REG * 4;
5336 file_offset += SLIC_NUM_REG * 4;
5338 regs = SLIC_GBMAX_REG;
5340 corehdr.FileRegOff = file_offset;
5341 corehdr.FileRegsize = regs * 4;
5343 for (offset = 0; regs;) {
5344 len = MIN(regs, 16); /* Can only xfr 16 regs at a time */
5346 status = slic_dump_data(card, offset, (ushort) len, DESC_RFILE);
5348 if (status != STATUS_SUCCESS) {
5349 DBG_ERROR("Cant dump register file - dump failed\n");
5353 DBG_MSG("slicDump Write RegisterFile len[%x] offset[%x]\n",
5354 (len * 4), file_offset);
5357 slic_dump_write(card, card->dumpbuffer, len * 4,
5361 ("Cant write register file to dump file - "
5366 file_offset += len * 4;
5371 dram_size = card->config.DramSize * 0x10000;
5373 switch (adapter->devid) {
5374 case SLIC_2GB_DEVICE_ID:
5375 sram_size = SLIC_SRAM_SIZE2GB;
5377 case SLIC_1GB_DEVICE_ID:
5378 sram_size = SLIC_SRAM_SIZE1GB;
5386 corehdr.SramOff = file_offset;
5387 corehdr.Sramsize = sram_size;
5389 for (offset = 0; sram_size;) {
5390 len = MIN(sram_size, DUMP_BUF_SIZE);
5391 status = slic_dump_data(card, offset, (ushort) len, DESC_SRAM);
5392 if (status != STATUS_SUCCESS) {
5394 ("[slicmon] Cant dump SRAM at offset %x - "
5395 "dump failed\n", (uint) offset);
5399 DBG_MSG("[slicmon] slicDump Write SRAM len[%x] offset[%x]\n",
5403 slic_dump_write(card, card->dumpbuffer, len, file_offset);
5406 ("[slicmon] Cant write SRAM to dump file - "
5416 corehdr.DramOff = file_offset;
5417 corehdr.Dramsize = dram_size;
5419 for (offset = 0; dram_size;) {
5420 len = MIN(dram_size, DUMP_BUF_SIZE);
5422 status = slic_dump_data(card, offset, (ushort) len, DESC_DRAM);
5423 if (status != STATUS_SUCCESS) {
5425 ("[slicmon] Cant dump dram at offset %x - "
5426 "dump failed\n", (uint) offset);
5430 DBG_MSG("slicDump Write DRAM len[%x] offset[%x]\n", len,
5434 slic_dump_write(card, card->dumpbuffer, len, file_offset);
5437 ("[slicmon] Cant write DRAM to dump file - "
5447 max_queues = SLIC_MAX_QUEUE;
5449 for (queue = 0; queue < max_queues; queue++) {
5450 u32 *qarray = (u32 *) card->dumpbuffer;
5451 u32 qarray_physl = card->dumpbuffer_physl;
5452 u32 qarray_physh = card->dumpbuffer_physh;
5457 DBG_MSG("[slicmon] Start Dump of QUEUE #0x%x\n", (uint) queue);
5459 for (offset = 0; offset < (DUMP_BUF_SIZE >> 2); offset++) {
5463 status = slic_dump_queue(card,
5465 qarray_physh, queue);
5468 if (status != STATUS_SUCCESS)
5471 if (jiffies > qstart) {
5472 qdelta = jiffies - qstart;
5478 qdelta = qtotal / offset;
5482 /* DBG_MSG(" slicDump Write QUEUE #0x%x len[%x] offset[%x] "
5483 "avgjiffs[%x]\n", queue, (offset*4), file_offset, qdelta); */
5486 slic_dump_write(card, card->dumpbuffer, offset * 4,
5491 ("[slicmon] Cant write QUEUES to dump file - "
5496 corehdr.queues[queue].queueOff = file_offset;
5497 corehdr.queues[queue].queuesize = offset * 4;
5498 file_offset += offset * 4;
5500 /* DBG_MSG(" Reload QUEUE #0x%x elements[%x]\n", (uint)queue, offset);*/
5502 * Fill the queue back up
5504 for (i = 0; i < offset; i++) {
5508 status = slic_dump_load_queue(card, qarray[i], queue);
5509 if (status != STATUS_SUCCESS)
5512 if (jiffies > qstart) {
5513 qdelta = jiffies - qstart;
5519 qdelta = qtotal / offset;
5523 /* DBG_MSG(" Reload DONE avgjiffs[%x]\n", qdelta); */
5528 len = SLIC_GB_CAMAB_SZE * 4;
5529 status = slic_dump_cam(card, 0, len, DUMP_CAM_A);
5530 if (status != STATUS_SUCCESS) {
5531 DBG_ERROR("[slicmon] Can't dump CAM_A - dump failed\n");
5535 result = slic_dump_write(card, card->dumpbuffer, len, file_offset);
5538 ("[slicmon] Can't write CAM_A data to dump file - "
5542 corehdr.CamAMOff = file_offset;
5543 corehdr.CamASize = len;
5546 len = SLIC_GB_CAMCD_SZE * 4;
5547 status = slic_dump_cam(card, 0, len, DUMP_CAM_C);
5549 DBG_ERROR("[slicmon] Can't dump CAM_C - dump failed\n");
5553 result = slic_dump_write(card, card->dumpbuffer, len, file_offset);
5556 ("[slicmon] Can't write CAM_C data to dump file - "
5560 corehdr.CamCMOff = file_offset;
5561 corehdr.CamCSize = len;
5566 * Write out the core header
5569 DBG_MSG("[slicmon] Write CoreHeader len[%x] offset[%x]\n",
5570 (uint) sizeof(struct sliccore_hdr), file_offset);
5573 slic_dump_write(card, &corehdr, sizeof(struct sliccore_hdr),
5575 DBG_MSG("[slicmon] corehdr xoff[%x] xsz[%x]\n"
5576 " roff[%x] rsz[%x] fileoff[%x] filesz[%x]\n"
5577 " sramoff[%x] sramsz[%x], dramoff[%x] dramsz[%x]\n"
5578 " corehdr_offset[%x]\n", corehdr.XmtRegOff,
5579 corehdr.XmtRegsize, corehdr.RcvRegOff, corehdr.RcvRegsize,
5580 corehdr.FileRegOff, corehdr.FileRegsize, corehdr.SramOff,
5581 corehdr.Sramsize, corehdr.DramOff, corehdr.Dramsize,
5582 (uint) sizeof(struct sliccore_hdr));
5583 for (i = 0; i < max_queues; i++) {
5584 DBG_MSG("[slicmon] QUEUE 0x%x offset[%x] size[%x]\n",
5585 (uint) i, corehdr.queues[i].queueOff,
5586 corehdr.queues[i].queuesize);
5590 slic_dump_close_file(card);
5593 DBG_MSG("slicDump RESTART RECEIVE and XMIT PROCESSORS\n\n");
5594 slic_dump_resume(card, PROC_RECEIVE);
5595 slic_dump_resume(card, PROC_TRANSMIT);
5601 static u32 slic_dump_halt(struct sliccard *card, unsigned char proc)
5603 unsigned char *cmd = card->cmdbuffer;
5605 *cmd = COMMAND_BYTE(CMD_HALT, 0, proc);
5607 return slic_dump_send_cmd(card,
5608 card->cmdbuffer_physl,
5609 card->cmdbuffer_physh, 0, 0);
5612 static u32 slic_dump_resume(struct sliccard *card, unsigned char proc)
5614 unsigned char *cmd = card->cmdbuffer;
5616 *cmd = COMMAND_BYTE(CMD_RUN, 0, proc);
5618 return slic_dump_send_cmd(card,
5619 card->cmdbuffer_physl,
5620 card->cmdbuffer_physh, 0, 0);
5623 static u32 slic_dump_reg(struct sliccard *card, unsigned char proc)
5625 struct dump_cmd *dump = (struct dump_cmd *)card->cmdbuffer;
5627 dump->cmd = COMMAND_BYTE(CMD_DUMP, 0, proc);
5628 dump->desc = DESC_REG;
5632 return slic_dump_send_cmd(card,
5633 card->cmdbuffer_physl,
5634 card->cmdbuffer_physh,
5635 card->dumpbuffer_physl,
5636 card->dumpbuffer_physh);
5639 static u32 slic_dump_data(struct sliccard *card,
5640 u32 addr, ushort count, unsigned char desc)
5642 struct dump_cmd *dump = (struct dump_cmd *)card->cmdbuffer;
5644 dump->cmd = COMMAND_BYTE(CMD_DUMP, 0, PROC_RECEIVE);
5646 dump->count = count;
5649 return slic_dump_send_cmd(card,
5650 card->cmdbuffer_physl,
5651 card->cmdbuffer_physh,
5652 card->dumpbuffer_physl,
5653 card->dumpbuffer_physh);
5656 static u32 slic_dump_queue(struct sliccard *card,
5657 u32 addr, u32 buf_physh, u32 queue)
5659 struct dump_cmd *dump = (struct dump_cmd *)card->cmdbuffer;
5661 dump->cmd = COMMAND_BYTE(CMD_DUMP, 0, PROC_RECEIVE);
5662 dump->desc = DESC_QUEUE;
5666 return slic_dump_send_cmd(card,
5667 card->cmdbuffer_physl,
5668 card->cmdbuffer_physh,
5669 addr, card->dumpbuffer_physh);
5672 static u32 slic_dump_load_queue(struct sliccard *card, u32 data,
5675 struct dump_cmd *load = (struct dump_cmd *) card->cmdbuffer;
5677 load->cmd = COMMAND_BYTE(CMD_LOAD, 0, PROC_RECEIVE);
5678 load->desc = DESC_QUEUE;
5679 load->count = (ushort) queue;
5682 return slic_dump_send_cmd(card,
5683 card->cmdbuffer_physl,
5684 card->cmdbuffer_physh, 0, 0);
5687 static u32 slic_dump_cam(struct sliccard *card,
5688 u32 addr, u32 count, unsigned char desc)
5690 struct dump_cmd *dump = (struct dump_cmd *)card->cmdbuffer;
5692 dump->cmd = COMMAND_BYTE(CMD_CAM_OPS, 0, PROC_NONE);
5694 dump->count = count;
5697 return slic_dump_send_cmd(card,
5698 card->cmdbuffer_physl,
5699 card->cmdbuffer_physh,
5700 addr, card->dumpbuffer_physh);
5703 static u32 slic_dump_send_cmd(struct sliccard *card,
5706 u32 buf_physl, u32 buf_physh)
5708 ulong timeout = msecs_to_jiffies(500); /* 500 msec */
5710 u32 delay = msecs_to_jiffies(10); /* 10 msec */
5711 struct adapter *adapter = card->master;
5716 * Zero the Dumpstatus field of the adapter structure
5718 card->dumpstatus = 0;
5720 * Issue the dump command via a utility processor request.
5722 * Kludge: We use the Informationbuffer parameter to hold
5723 * the buffer address
5725 slic_upr_request(adapter, SLIC_UPR_DUMP, cmd_physl, cmd_physh,
5726 buf_physl, buf_physh);
5730 * Spin until completion or timeout.
5732 while (!card->dumpstatus) {
5735 if (jiffies > timeout) {
5737 * Complete the timed-out DUMP UPR request.
5739 slic_upr_request_complete(adapter, 0);
5741 ("%s: TIMED OUT num_sleeps[%x] "
5743 __func__, num_sleeps, STATUS_FAILURE);
5745 return STATUS_FAILURE;
5748 SLIC_INTERRUPTIBLE_SLEEP_ON_TIMEOUT(card->dump_wq,
5752 if (card->dumpstatus & ISR_UPCERR) {
5754 * Error (or queue empty)
5756 /* DBG_ERROR("[slicmon] %s: DUMP_STATUS & ISR_UPCERR status[%x]\n",
5757 __func__, STATUS_FAILURE); */
5759 return STATUS_FAILURE;
5760 } else if (card->dumpstatus & ISR_UPCBSY) {
5764 DBG_ERROR("%s: ISR_UPCBUSY attempt[%x]\n", __func__,
5772 return STATUS_SUCCESS;
5777 DBG_ERROR("%s: GAVE UP AFTER SEVERAL ATTEMPTS status[%x]\n",
5778 __func__, STATUS_FAILURE);
5781 * Gave up after several attempts
5783 return STATUS_FAILURE;
5787 /*=============================================================================
5788 =============================================================================
5790 === *** END **** END **** END **** END *** ===
5791 === SLIC DUMP MANAGEMENT SECTION ===
5795 =============================================================================
5796 ============================================================================*/
5798 /******************************************************************************/
5799 /**************** MODULE INITIATION / TERMINATION FUNCTIONS ***************/
5800 /******************************************************************************/
5802 static struct pci_driver slic_driver = {
5804 .id_table = slic_pci_tbl,
5805 .probe = slic_entry_probe,
5806 .remove = slic_entry_remove,
5807 #if SLIC_POWER_MANAGEMENT_ENABLED
5808 .suspend = slicpm_suspend,
5809 .resume = slicpm_resume,
5811 /* .shutdown = slic_shutdown, MOOK_INVESTIGATE */
5814 static int __init slic_module_init(void)
5816 struct pci_device_id *pcidev;
5819 /* DBG_MSG("slicoss: %s ENTER cpu %d\n", __func__, smp_processor_id()); */
5823 if (debug >= 0 && slic_debug != debug)
5824 printk(SLICLEVEL "slicoss: debug level is %d.\n", debug);
5828 pcidev = (struct pci_device_id *)slic_driver.id_table;
5829 /* DBG_MSG("slicoss: %s call pci_module_init jiffies[%lx] cpu #%d\n",
5830 __func__, jiffies, smp_processor_id()); */
5832 ret = pci_register_driver(&slic_driver);
5834 /* DBG_MSG("slicoss: %s EXIT after call pci_module_init jiffies[%lx] "
5835 "cpu #%d status[%x]\n",__func__, jiffies,
5836 smp_processor_id(), ret); */
5841 static void __exit slic_module_cleanup(void)
5843 /* DBG_MSG("slicoss: %s ENTER\n", __func__); */
5844 pci_unregister_driver(&slic_driver);
5845 slic_debug_cleanup();
5846 /* DBG_MSG("slicoss: %s EXIT\n", __func__); */
5849 module_init(slic_module_init);
5850 module_exit(slic_module_cleanup);