Staging: slicoss: remove unused #defines
[linux-2.6] / drivers / staging / slicoss / slicoss.c
1 /**************************************************************************
2  *
3  * Copyright  2000-2006 Alacritech, Inc.  All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
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.
15  *
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.
19  *
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
31  * SUCH DAMAGE.
32  *
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.
36  *
37  **************************************************************************/
38
39 /*
40  * FILENAME: slicoss.c
41  *
42  * The SLICOSS driver for Alacritech's IS-NIC products.
43  *
44  * This driver is supposed to support:
45  *
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
49  *
50  * The driver was acutally tested on Oasis and Kalahari cards.
51  *
52  *
53  * NOTE: This is the standard, non-accelerated version of Alacritech's
54  *       IS-NIC driver.
55  */
56
57
58 #define SLIC_DUMP_ENABLED               0
59 #define KLUDGE_FOR_4GB_BOUNDARY         1
60 #define DEBUG_MICROCODE                 1
61 #define DBG                             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
72
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>
84 #include <linux/io.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>
94
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>
101
102 #include <linux/ethtool.h>
103 #define SLIC_ETHTOOL_SUPPORT     1
104
105 #include <linux/uaccess.h>
106 #include "slicinc.h"
107
108 #if SLIC_DUMP_ENABLED
109 #include "slicdump.h"
110 #endif
111
112 #define SLIC_POWER_MANAGEMENT  0
113
114 static uint slic_first_init = 1;
115 static char *slic_banner = "Alacritech SLIC Technology(tm) Server "\
116                 "and Storage Accelerator (Non-Accelerated)\n";
117
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.";
122
123 static int slic_debug = 1;
124 static int debug = -1;
125 static struct net_device *head_netdevice;
126
127 static struct base_driver slic_global = { {}, 0, 0, 0, 1, NULL, NULL };
128 static int intagg_delay = 100;
129 static u32 dynamic_intagg;
130 static int errormsg;
131 static int goodmsg;
132 static unsigned int rcv_count;
133 static struct dentry *slic_debugfs;
134
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 " "
143
144 MODULE_AUTHOR(DRV_AUTHOR);
145 MODULE_DESCRIPTION(DRV_DESCRIPTION);
146 MODULE_LICENSE("Dual BSD/GPL");
147
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");
152
153 static struct pci_device_id slic_pci_tbl[] __devinitdata = {
154         {PCI_VENDOR_ID_ALACRITECH,
155          SLIC_1GB_DEVICE_ID,
156          PCI_ANY_ID, PCI_ANY_ID,},
157         {PCI_VENDOR_ID_ALACRITECH,
158          SLIC_2GB_DEVICE_ID,
159          PCI_ANY_ID, PCI_ANY_ID,},
160         {0,}
161 };
162
163 MODULE_DEVICE_TABLE(pci, slic_pci_tbl);
164
165 #define SLIC_GET_SLIC_HANDLE(_adapter, _pslic_handle)                   \
166 {                                                                       \
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;             \
173     }                                                                   \
174     spin_unlock_irqrestore(&_adapter->handle_lock.lock,                 \
175                         _adapter->handle_lock.flags);                   \
176 }
177
178 #define SLIC_FREE_SLIC_HANDLE(_adapter, _pslic_handle)                  \
179 {                                                                       \
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);                   \
187 }
188
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);
195
196 static inline void slic_reg32_write(void __iomem *reg, u32 value, bool flush)
197 {
198         writel(value, reg);
199         if (flush)
200                 mb();
201 }
202
203 static inline void slic_reg64_write(struct adapter *adapter, void __iomem *reg,
204                                     u32 value, void __iomem *regh, u32 paddrh,
205                                     bool flush)
206 {
207         spin_lock_irqsave(&adapter->bit64reglock.lock,
208                                 adapter->bit64reglock.flags);
209         if (paddrh != adapter->curaddrupper) {
210                 adapter->curaddrupper = paddrh;
211                 writel(paddrh, regh);
212         }
213         writel(value, reg);
214         if (flush)
215                 mb();
216         spin_unlock_irqrestore(&adapter->bit64reglock.lock,
217                                 adapter->bit64reglock.flags);
218 }
219
220 static void slic_init_driver(void)
221 {
222         if (slic_first_init) {
223                 DBG_MSG("slicoss: %s slic_first_init set jiffies[%lx]\n",
224                         __func__, jiffies);
225                 slic_first_init = 0;
226                 spin_lock_init(&slic_global.driver_lock.lock);
227                 slic_debug_init();
228         }
229 }
230
231 static void slic_dbg_macaddrs(struct adapter *adapter)
232 {
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]);
242         return;
243 }
244
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)
249 {
250         ushort index;
251         struct slic_handle *pslic_handle;
252         struct adapter *adapter = (struct adapter *)netdev_priv(netdev);
253 /*
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);
278
279         adapter->card_size = 1;
280         /*
281           Initialize slic_handle array
282         */
283         ASSERT(SLIC_CMDQ_MAXCMDS <= 0xFFFF);
284         /*
285          Start with 1.  0 is an invalid host handle.
286         */
287         for (index = 1, pslic_handle = &adapter->slic_handles[1];
288              index < SLIC_CMDQ_MAXCMDS; index++, pslic_handle++) {
289
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;
294         }
295 /*
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),
301                                         &adapter->
302                                         phys_shmem);
303 /*
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);
307 */
308         ASSERT(adapter->pshmem);
309
310         memset(adapter->pshmem, 0, sizeof(struct slic_shmem));
311
312         return;
313 }
314
315 static int __devinit slic_entry_probe(struct pci_dev *pcidev,
316                                const struct pci_device_id *pci_tbl_entry)
317 {
318         static int cards_found;
319         static int did_version;
320         int err = -ENODEV;
321         struct net_device *netdev;
322         struct adapter *adapter;
323         void __iomem *memmapped_ioaddr = NULL;
324         u32 status = 0;
325         ulong mmio_start = 0;
326         ulong mmio_len = 0;
327         struct sliccard *card = NULL;
328
329         DBG_MSG("slicoss: %s 2.6 VERSION ENTER jiffies[%lx] cpu %d\n",
330                 __func__, jiffies, smp_processor_id());
331
332         slic_global.dynamic_intagg = dynamic_intagg;
333
334         err = pci_enable_device(pcidev);
335
336         DBG_MSG("Call pci_enable_device(%p)  status[%x]\n", pcidev, err);
337         if (err)
338                 return err;
339
340         if (slic_debug > 0 && did_version++ == 0) {
341                 printk(slic_banner);
342                 printk(slic_proc_version);
343         }
344
345         err = pci_set_dma_mask(pcidev, DMA_64BIT_MASK);
346         if (!err) {
347                 DBG_MSG("pci_set_dma_mask(DMA_64BIT_MASK) successful\n");
348         } else {
349                 err = pci_set_dma_mask(pcidev, DMA_32BIT_MASK);
350                 if (err) {
351                         DBG_MSG
352                             ("No usable DMA configuration, aborting  err[%x]\n",
353                              err);
354                         goto err_out_disable_pci;
355                 }
356                 DBG_MSG("pci_set_dma_mask(DMA_32BIT_MASK) successful\n");
357         }
358
359         DBG_MSG("Call pci_request_regions\n");
360
361         err = pci_request_regions(pcidev, DRV_NAME);
362         if (err) {
363                 DBG_MSG("pci_request_regions FAILED err[%x]\n", err);
364                 goto err_out_disable_pci;
365         }
366
367         DBG_MSG("call pci_set_master\n");
368         pci_set_master(pcidev);
369
370         DBG_MSG("call alloc_etherdev\n");
371         netdev = alloc_etherdev(sizeof(struct adapter));
372         if (!netdev) {
373                 err = -ENOMEM;
374                 goto err_out_exit_slic_probe;
375         }
376         DBG_MSG("alloc_etherdev for slic netdev[%p]\n", netdev);
377
378         SET_NETDEV_DEV(netdev, &pcidev->dev);
379
380         pci_set_drvdata(pcidev, netdev);
381         adapter = netdev_priv(netdev);
382         adapter->netdev = netdev;
383         adapter->pcidev = pcidev;
384
385         mmio_start = pci_resource_start(pcidev, 0);
386         mmio_len = pci_resource_len(pcidev, 0);
387
388         DBG_MSG("slicoss: call ioremap(mmio_start[%lx], mmio_len[%lx])\n",
389                 mmio_start, mmio_len);
390
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__,
394                 memmapped_ioaddr);
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;
399         }
400
401         DBG_MSG
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);
405
406         slic_config_pci(pcidev);
407
408         slic_init_driver();
409
410         slic_init_adapter(netdev,
411                           pcidev, pci_tbl_entry, memmapped_ioaddr, cards_found);
412
413         status = slic_card_locate(adapter);
414         if (status) {
415                 DBG_ERROR("%s cannot locate card\n", __func__);
416                 goto err_out_free_mmio_region;
417         }
418
419         card = adapter->card;
420
421         if (!adapter->allocated) {
422                 card->adapters_allocated++;
423                 adapter->allocated = 1;
424         }
425
426         DBG_MSG("slicoss: %s    card:             %p\n", __func__,
427                 adapter->card);
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);
434
435         status = slic_card_init(card, adapter);
436
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);
442         } else {
443                 slic_adapter_set_hwaddr(adapter);
444         }
445
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;
455 #endif
456         netdev->set_multicast_list = slic_mcast_set_list;
457
458         slic_debug_adapter_create(adapter);
459
460         strcpy(netdev->name, "eth%d");
461         err = register_netdev(netdev);
462         if (err) {
463                 DBG_ERROR("Cannot register net device, aborting.\n");
464                 goto err_out_unmap;
465         }
466
467         DBG_MSG
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]);
473
474         cards_found++;
475         DBG_MSG("slicoss: %s EXIT status[%x] jiffies[%lx] cpu %d\n",
476                 __func__, status, jiffies, smp_processor_id());
477
478         return status;
479
480 err_out_unmap:
481         iounmap(memmapped_ioaddr);
482 err_out_free_mmio_region:
483         release_mem_region(mmio_start, mmio_len);
484 err_out_free_netdev:
485         free_netdev(netdev);
486 err_out_exit_slic_probe:
487         pci_release_regions(pcidev);
488         DBG_ERROR("%s EXIT jiffies[%lx] cpu %d\n", __func__, jiffies,
489                   smp_processor_id());
490 err_out_disable_pci:
491         pci_disable_device(pcidev);
492         return err;
493 }
494
495 static int slic_entry_open(struct net_device *dev)
496 {
497         struct adapter *adapter = (struct adapter *) netdev_priv(dev);
498         struct sliccard *card = adapter->card;
499         u32 locked = 0;
500         int status;
501
502         ASSERT(adapter);
503         ASSERT(card);
504         DBG_MSG
505             ("slicoss: %s adapter->activated[%d] card->adapters[%x] "\
506              "allocd[%x]\n", __func__, adapter->activated,
507              card->adapters_activated,
508              card->adapters_allocated);
509         DBG_MSG
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);
514
515         netif_stop_queue(adapter->netdev);
516
517         spin_lock_irqsave(&slic_global.driver_lock.lock,
518                                 slic_global.driver_lock.flags);
519         locked = 1;
520         if (!adapter->activated) {
521                 card->adapters_activated++;
522                 slic_global.num_slic_ports_active++;
523                 adapter->activated = 1;
524         }
525         status = slic_if_init(adapter);
526
527         if (status != STATUS_SUCCESS) {
528                 if (adapter->activated) {
529                         card->adapters_activated--;
530                         slic_global.num_slic_ports_active--;
531                         adapter->activated = 0;
532                 }
533                 if (locked) {
534                         spin_unlock_irqrestore(&slic_global.driver_lock.lock,
535                                                 slic_global.driver_lock.flags);
536                         locked = 0;
537                 }
538                 return status;
539         }
540         DBG_MSG("slicoss: %s set card->master[%p] adapter[%p]\n", __func__,
541                 card->master, adapter);
542         if (!card->master)
543                 card->master = adapter;
544 #if SLIC_DUMP_ENABLED
545         if (!(card->dumpthread_running))
546                 init_waitqueue_head(&card->dump_wq);
547 #endif
548
549         if (locked) {
550                 spin_unlock_irqrestore(&slic_global.driver_lock.lock,
551                                         slic_global.driver_lock.flags);
552                 locked = 0;
553         }
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);
558                 /*
559                 Even if the dump thread fails, we will continue at this point
560                 */
561         }
562 #endif
563
564         return STATUS_SUCCESS;
565 }
566
567 static void __devexit slic_entry_remove(struct pci_dev *pcidev)
568 {
569         struct net_device *dev = pci_get_drvdata(pcidev);
570         u32 mmio_start = 0;
571         uint mmio_len = 0;
572         struct adapter *adapter = (struct adapter *) netdev_priv(dev);
573         struct sliccard *card;
574         struct mcast_address *mcaddr, *mlist;
575
576         ASSERT(adapter);
577         DBG_MSG("slicoss: %s ENTER dev[%p] adapter[%p]\n", __func__, dev,
578                 adapter);
579         slic_adapter_freeresources(adapter);
580         slic_unmap_mmio_space(adapter);
581         DBG_MSG("slicoss: %s unregister_netdev\n", __func__);
582         unregister_netdev(dev);
583
584         mmio_start = pci_resource_start(pcidev, 0);
585         mmio_len = pci_resource_len(pcidev, 0);
586
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);
590
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;
596         while (mlist) {
597                 mcaddr = mlist;
598                 mlist = mlist->next;
599                 kfree(mcaddr);
600         }
601         ASSERT(adapter->card);
602         card = adapter->card;
603         ASSERT(card->adapters_allocated);
604         card->adapters_allocated--;
605         adapter->allocated = 0;
606         DBG_MSG
607             ("slicoss: %s init[%x] alloc[%x] card[%p] adapter[%p]\n",
608              __func__, card->adapters_activated, card->adapters_allocated,
609              card, adapter);
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;
614                 } else {
615                         while (curr_card->next != card)
616                                 curr_card = curr_card->next;
617                         ASSERT(curr_card);
618                         curr_card->next = card->next;
619                 }
620                 ASSERT(slic_global.num_slic_cards);
621                 slic_global.num_slic_cards--;
622                 slic_card_cleanup(card);
623         }
624         DBG_MSG("slicoss: %s deallocate device\n", __func__);
625         kfree(dev);
626         pci_release_regions(pcidev);
627         DBG_MSG("slicoss: %s EXIT\n", __func__);
628 }
629
630 static int slic_entry_halt(struct net_device *dev)
631 {
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;
635
636         spin_lock_irqsave(&slic_global.driver_lock.lock,
637                                 slic_global.driver_lock.flags);
638         ASSERT(card);
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;
662         }
663 #ifdef AUTOMATIC_RESET
664         slic_reg32_write(&slic_regs->slic_reset_iface, 0, FLUSH);
665 #endif
666         /*
667          *  Reset the adapter's rsp, cmd, and rcv queues
668          */
669         slic_cmdq_reset(adapter);
670         slic_rspqueue_reset(adapter);
671         slic_rcvqueue_reset(adapter);
672
673 #ifdef AUTOMATIC_RESET
674         if (!card->adapters_activated) {
675
676 #if SLIC_DUMP_ENABLED
677                 if (card->dumpthread_running) {
678                         uint status;
679                         DBG_MSG("attempt to terminate dump thread pid[%x]\n",
680                                 card->dump_task_id);
681                         status = kill_proc(card->dump_task_id->pid, SIGKILL, 1);
682
683                         if (!status) {
684                                 int count = 10 * 100;
685                                 while (card->dumpthread_running && --count) {
686                                         current->state = TASK_INTERRUPTIBLE;
687                                         schedule_timeout(1);
688                                 }
689
690                                 if (!count) {
691                                         DBG_MSG
692                                             ("slicmon thread cleanup FAILED \
693                                              pid[%x]\n",
694                                              card->dump_task_id->pid);
695                                 }
696                         }
697                 }
698 #endif
699                 DBG_MSG("slicoss: %s (%s) initiate CARD_HALT\n", __func__,
700                         dev->name);
701
702                 slic_card_init(card, adapter);
703         }
704 #endif
705
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;
711 }
712
713 static int slic_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
714 {
715         ASSERT(rq);
716 /*
717       DBG_MSG("slicoss: %s cmd[%x] rq[%p] dev[%p]\n", __func__, cmd, rq, dev);
718 */
719         switch (cmd) {
720         case SIOCSLICSETINTAGG:
721                 {
722                         struct adapter *adapter = (struct adapter *)
723                                                         netdev_priv(dev);
724                         u32 data[7];
725                         u32 intagg;
726
727                         if (copy_from_user(data, rq->ifr_data, 28)) {
728                                 DBG_ERROR
729                                     ("copy_from_user FAILED getting initial \
730                                      params\n");
731                                 return -EFAULT;
732                         }
733                         intagg = data[0];
734                         printk(KERN_EMERG
735                                "%s: set interrupt aggregation to %d\n",
736                                __func__, intagg);
737                         slic_intagg_set(adapter, intagg);
738                         return 0;
739                 }
740 #ifdef SLIC_USER_REQUEST_DUMP_ENABLED
741         case SIOCSLICDUMPCARD:
742                 {
743                         struct adapter *adapter = netdev_priv(dev);
744                         struct sliccard *card;
745
746                         ASSERT(adapter);
747                         ASSERT(adapter->card)
748                         card = adapter->card;
749
750                         DBG_IOCTL("slic_ioctl  SIOCSLIC_DUMP_CARD\n");
751
752                         if (card->dump_requested == SLIC_DUMP_DONE) {
753                                 printk(SLICLEVEL
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)) {
759                                 printk(SLICLEVEL
760                                        "SLIC Card dump Requested but already \
761                                         in progress... ignore\n");
762                         } else {
763                                 printk(SLICLEVEL
764                                        "SLIC Card #%d Dump Requested\n",
765                                        card->cardnum);
766                                 card->dump_requested = SLIC_DUMP_REQUESTED;
767                         }
768                         return 0;
769                 }
770 #endif
771
772 #ifdef SLIC_TRACE_DUMP_ENABLED
773         case SIOCSLICTRACEDUMP:
774                 {
775                         ulong data[7];
776                         ulong value;
777
778                         DBG_IOCTL("slic_ioctl  SIOCSLIC_TRACE_DUMP\n");
779
780                         if (copy_from_user(data, rq->ifr_data, 28)) {
781                                 PRINT_ERROR
782                                     ("slic: copy_from_user FAILED getting \
783                                      initial simba param\n");
784                                 return -EFAULT;
785                         }
786
787                         value = data[0];
788                         if (tracemon_request == SLIC_DUMP_DONE) {
789                                 PRINT_ERROR
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) ||
795                                    (tracemon_request ==
796                                     SLIC_DUMP_IN_PROGRESS)) {
797                                 PRINT_ERROR
798                                     ("ATK Diagnostic Trace Dump Requested but \
799                                      already in progress... ignore\n");
800                         } else {
801                                 PRINT_ERROR
802                                     ("ATK Diagnostic Trace Dump Requested\n");
803                                 tracemon_request = SLIC_DUMP_REQUESTED;
804                                 tracemon_request_type = value;
805                                 tracemon_timestamp = jiffies;
806                         }
807                         return 0;
808                 }
809 #endif
810 #if SLIC_ETHTOOL_SUPPORT
811         case SIOCETHTOOL:
812                 {
813                         struct adapter *adapter = (struct adapter *)
814                                                         netdev_priv(dev);
815                         struct ethtool_cmd data;
816                         struct ethtool_cmd ecmd;
817
818                         ASSERT(adapter);
819 /*                      DBG_MSG("slicoss: %s SIOCETHTOOL\n", __func__); */
820                         if (copy_from_user(&ecmd, rq->ifr_data, sizeof(ecmd)))
821                                 return -EFAULT;
822
823                         if (ecmd.cmd == ETHTOOL_GSET) {
824                                 data.supported =
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;
837                                 else
838                                         data.speed = 0;
839
840                                 if (adapter->linkduplex == LINK_FULLD)
841                                         data.duplex = DUPLEX_FULL;
842                                 else
843                                         data.duplex = DUPLEX_HALF;
844
845                                 data.autoneg = AUTONEG_ENABLE;
846                                 data.maxtxpkt = 1;
847                                 data.maxrxpkt = 1;
848                                 if (copy_to_user
849                                     (rq->ifr_data, &data, sizeof(data)))
850                                         return -EFAULT;
851
852                         } else if (ecmd.cmd == ETHTOOL_SSET) {
853                                 if (!capable(CAP_NET_ADMIN))
854                                         return -EPERM;
855
856                                 if (adapter->linkspeed == LINK_100MB)
857                                         data.speed = SPEED_100;
858                                 else if (adapter->linkspeed == LINK_10MB)
859                                         data.speed = SPEED_10;
860                                 else
861                                         data.speed = 0;
862
863                                 if (adapter->linkduplex == LINK_FULLD)
864                                         data.duplex = DUPLEX_FULL;
865                                 else
866                                         data.duplex = DUPLEX_HALF;
867
868                                 data.autoneg = AUTONEG_ENABLE;
869                                 data.maxtxpkt = 1;
870                                 data.maxrxpkt = 1;
871                                 if ((ecmd.speed != data.speed) ||
872                                     (ecmd.duplex != data.duplex)) {
873                                         u32 speed;
874                                         u32 duplex;
875
876                                         if (ecmd.speed == SPEED_10) {
877                                                 speed = 0;
878                                                 SLIC_DISPLAY
879                                                     ("%s: slic ETHTOOL set \
880                                                      link speed==10MB",
881                                                      dev->name);
882                                         } else {
883                                                 speed = PCR_SPEED_100;
884                                                 SLIC_DISPLAY
885                                                     ("%s: slic ETHTOOL set \
886                                                     link speed==100MB",
887                                                      dev->name);
888                                         }
889                                         if (ecmd.duplex == DUPLEX_FULL) {
890                                                 duplex = PCR_DUPLEX_FULL;
891                                                 SLIC_DISPLAY
892                                                     (": duplex==FULL\n");
893                                         } else {
894                                                 duplex = 0;
895                                                 SLIC_DISPLAY
896                                                     (": duplex==HALF\n");
897                                         }
898                                         slic_link_config(adapter,
899                                                          speed, duplex);
900                                         slic_link_event_handler(adapter);
901                                 }
902                         }
903                         return 0;
904                 }
905 #endif
906         default:
907 /*              DBG_MSG("slicoss: %s UNSUPPORTED[%x]\n", __func__, cmd); */
908                 return -EOPNOTSUPP;
909         }
910 }
911
912 #define  XMIT_FAIL_LINK_STATE               1
913 #define  XMIT_FAIL_ZERO_LENGTH              2
914 #define  XMIT_FAIL_HOSTCMD_FAIL             3
915
916 static void slic_xmit_build_request(struct adapter *adapter,
917                              struct slic_hostcmd *hcmd, struct sk_buff *skb)
918 {
919         struct slic_host64_cmd *ihcmd;
920         ulong phys_addr;
921
922         ihcmd = &hcmd->cmd64;
923
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,
928                         PCI_DMA_TODEVICE);
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);
938 #else
939         Stop Compilation;
940 #endif
941 }
942
943 #define NORMAL_ETHFRAME     0
944
945 static int slic_xmit_start(struct sk_buff *skb, struct net_device *dev)
946 {
947         struct sliccard *card;
948         struct adapter *adapter = (struct adapter *)netdev_priv(dev);
949         struct slic_hostcmd *hcmd = NULL;
950         u32 status = 0;
951         u32 skbtype = NORMAL_ETHFRAME;
952         void *offloadcmd = NULL;
953
954         card = adapter->card;
955         ASSERT(card);
956 /*
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,
959          adapter->state);
960 */
961         if ((adapter->linkstate != LINK_UP) ||
962             (adapter->state != ADAPT_UP) || (card->state != CARD_UP)) {
963                 status = XMIT_FAIL_LINK_STATE;
964                 goto xmit_fail;
965
966         } else if (skb->len == 0) {
967                 status = XMIT_FAIL_ZERO_LENGTH;
968                 goto xmit_fail;
969         }
970
971         if (skbtype == NORMAL_ETHFRAME) {
972                 hcmd = slic_cmdq_getfree(adapter);
973                 if (!hcmd) {
974                         adapter->xmitq_full = 1;
975                         status = XMIT_FAIL_HOSTCMD_FAIL;
976                         goto xmit_fail;
977                 }
978                 ASSERT(hcmd->pslic_handle);
979                 ASSERT(hcmd->cmd64.hosthandle ==
980                        hcmd->pslic_handle->token.handle_token);
981                 hcmd->skb = skb;
982                 hcmd->busy = 1;
983                 hcmd->type = SLIC_CMD_DUMB;
984                 if (skbtype == NORMAL_ETHFRAME)
985                         slic_xmit_build_request(adapter, hcmd, skb);
986         }
987         adapter->stats.tx_packets++;
988         adapter->stats.tx_bytes += skb->len;
989
990 #ifdef DEBUG_DUMP
991         if (adapter->kill_card) {
992                 struct slic_host64_cmd ihcmd;
993
994                 ihcmd = &hcmd->cmd64;
995
996                 ihcmd->flags |= 0x40;
997                 adapter->kill_card = 0; /* only do this once */
998         }
999 #endif
1000         if (hcmd->paddrh == 0) {
1001                 slic_reg32_write(&adapter->slic_regs->slic_cbar,
1002                                  (hcmd->paddrl | hcmd->cmdsize), DONT_FLUSH);
1003         } else {
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);
1008         }
1009 xmit_done:
1010         return 0;
1011 xmit_fail:
1012         slic_xmit_fail(adapter, skb, offloadcmd, skbtype, status);
1013         goto xmit_done;
1014 }
1015
1016 static void slic_xmit_fail(struct adapter *adapter,
1017                     struct sk_buff *skb,
1018                     void *cmd, u32 skbtype, u32 status)
1019 {
1020         if (adapter->xmitq_full)
1021                 slic_if_stop_queue(adapter);
1022         if ((cmd == NULL) && (status <= XMIT_FAIL_HOSTCMD_FAIL)) {
1023                 switch (status) {
1024                 case XMIT_FAIL_LINK_STATE:
1025                         DBG_ERROR
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);
1033                         break;
1034                 case XMIT_FAIL_ZERO_LENGTH:
1035                         DBG_ERROR
1036                             ("xmit_start skb->len == 0 skb[%p] type[%x]!!!! \n",
1037                              skb, skb->pkt_type);
1038                         break;
1039                 case XMIT_FAIL_HOSTCMD_FAIL:
1040                         DBG_ERROR
1041                             ("xmit_start skb[%p] type[%x] No host commands \
1042                              available !!!! \n",
1043                              skb, skb->pkt_type);
1044                         break;
1045                 default:
1046                         ASSERT(0);
1047                 }
1048         }
1049         dev_kfree_skb(skb);
1050         adapter->stats.tx_dropped++;
1051 }
1052
1053 static void slic_rcv_handle_error(struct adapter *adapter,
1054                                         struct slic_rcvbuf *rcvbuf)
1055 {
1056         struct slic_hddr_wds *hdr = (struct slic_hddr_wds *)rcvbuf->data;
1057
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++;
1068                 }
1069                 if (hdr->frame_status_b14 & VRHSTATB_BUFF) {
1070                         adapter->if_events.Bufov++;
1071                         adapter->stats.rx_over_errors++;
1072                 }
1073                 if (hdr->frame_status_b14 & VRHSTATB_CARRE) {
1074                         adapter->if_events.Carre++;
1075                         adapter->stats.tx_carrier_errors++;
1076                 }
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++;
1084                 }
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++;
1099         } else {
1100                 if (hdr->frame_statusGB & VGBSTAT_XPERR) {
1101                         u32 xerr = hdr->frame_statusGB >> VGBSTAT_XERRSHFT;
1102
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++;
1109                 }
1110                 if (hdr->frame_statusGB & VGBSTAT_NETERR) {
1111                         u32 nerr =
1112                             (hdr->
1113                              frame_statusGB >> VGBSTAT_NERRSHFT) &
1114                             VGBSTAT_NERRMSK;
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++;
1121                 }
1122                 if (hdr->frame_statusGB & VGBSTAT_LNKERR) {
1123                         u32 lerr = hdr->frame_statusGB & VGBSTAT_LERRMSK;
1124
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++;
1139                 }
1140         }
1141         return;
1142 }
1143
1144 #define TCP_OFFLOAD_FRAME_PUSHFLAG  0x10000000
1145 #define M_FAST_PATH                 0x0040
1146
1147 static void slic_rcv_handler(struct adapter *adapter)
1148 {
1149         struct sk_buff *skb;
1150         struct slic_rcvbuf *rcvbuf;
1151         u32 frames = 0;
1152
1153         while ((skb = slic_rcvqueue_getnext(adapter))) {
1154                 u32 rx_bytes;
1155
1156                 ASSERT(skb->head);
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);
1163                         continue;
1164                 }
1165
1166                 if (!slic_mac_filter(adapter, (struct ether_header *)
1167                                         rcvbuf->data)) {
1168 #if 0
1169                         DBG_MSG
1170                             ("slicoss: %s (%s) drop frame due to mac filter\n",
1171                              __func__, adapter->netdev->name);
1172 #endif
1173                         slic_rcvqueue_reinsert(adapter, skb);
1174                         continue;
1175                 }
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;
1183 #endif
1184
1185                 skb->dev = adapter->netdev;
1186                 skb->protocol = eth_type_trans(skb, skb->dev);
1187                 netif_rx(skb);
1188
1189                 ++frames;
1190 #if SLIC_INTERRUPT_PROCESS_LIMIT
1191                 if (frames >= SLIC_RCVQ_MAX_PROCESS_ISR) {
1192                         adapter->rcv_interrupt_yields++;
1193                         break;
1194                 }
1195 #endif
1196         }
1197         adapter->max_isr_rcvs = max(adapter->max_isr_rcvs, frames);
1198 }
1199
1200 static void slic_xmit_complete(struct adapter *adapter)
1201 {
1202         struct slic_hostcmd *hcmd;
1203         struct slic_rspbuf *rspbuf;
1204         u32 frames = 0;
1205         struct slic_handle_word slic_handle_word;
1206
1207         do {
1208                 rspbuf = slic_rspqueue_getnext(adapter);
1209                 if (!rspbuf)
1210                         break;
1211                 adapter->xmit_completes++;
1212                 adapter->card->events++;
1213                 /*
1214                  Get the complete host command buffer
1215                 */
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);
1219                 hcmd =
1220                     (struct slic_hostcmd *)
1221                         adapter->slic_handles[slic_handle_word.handle_index].
1222                                                                         address;
1223 /*      hcmd = (struct slic_hostcmd *) rspbuf->hosthandle; */
1224                 ASSERT(hcmd);
1225                 ASSERT(hcmd->pslic_handle ==
1226                        &adapter->slic_handles[slic_handle_word.handle_index]);
1227 /*
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);
1232 */
1233                 if (hcmd->type == SLIC_CMD_DUMB) {
1234                         if (hcmd->skb)
1235                                 dev_kfree_skb_irq(hcmd->skb);
1236                         slic_cmdq_putdone_irq(adapter, hcmd);
1237                 }
1238                 rspbuf->status = 0;
1239                 rspbuf->hosthandle = 0;
1240                 frames++;
1241         } while (1);
1242         adapter->max_isr_xmits = max(adapter->max_isr_xmits, frames);
1243 }
1244
1245 static irqreturn_t slic_interrupt(int irq, void *dev_id)
1246 {
1247         struct net_device *dev = (struct net_device *)dev_id;
1248         struct adapter *adapter = (struct adapter *)netdev_priv(dev);
1249         u32 isr;
1250
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) {
1258                 case CARD_UP:
1259                         if (isr & ~ISR_IO) {
1260                                 if (isr & ISR_ERR) {
1261                                         adapter->error_interrupts++;
1262                                         if (isr & ISR_RMISS) {
1263                                                 int count;
1264                                                 int pre_count;
1265                                                 int errors;
1266
1267                                                 struct slic_rcvqueue *rcvq =
1268                                                     &adapter->rcvqueue;
1269
1270                                                 adapter->
1271                                                     error_rmiss_interrupts++;
1272                                                 if (!rcvq->errors)
1273                                                         rcv_count = rcvq->count;
1274                                                 pre_count = rcvq->count;
1275                                                 errors = rcvq->errors;
1276
1277                                                 while (rcvq->count <
1278                                                        SLIC_RCVQ_FILLTHRESH) {
1279                                                         count =
1280                                                             slic_rcvqueue_fill
1281                                                             (adapter);
1282                                                         if (!count)
1283                                                                 break;
1284                                                 }
1285                                                 DBG_MSG
1286                                                     ("(%s): [%x] ISR_RMISS \
1287                                                      initial[%x] pre[%x] \
1288                                                      errors[%x] \
1289                                                      post_count[%x]\n",
1290                                                      adapter->netdev->name,
1291                                                      isr, rcv_count, pre_count,
1292                                                      errors, rcvq->count);
1293                                         } else if (isr & ISR_XDROP) {
1294                                                 DBG_ERROR
1295                                                     ("isr & ISR_ERR [%x] \
1296                                                      ISR_XDROP \n",
1297                                                      isr);
1298                                         } else {
1299                                                 DBG_ERROR
1300                                                     ("isr & ISR_ERR [%x]\n",
1301                                                      isr);
1302                                         }
1303                                 }
1304
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);
1310                                 }
1311
1312                                 if ((isr & ISR_UPC) ||
1313                                     (isr & ISR_UPCERR) || (isr & ISR_UPCBSY)) {
1314                                         adapter->upr_interrupts++;
1315                                         slic_upr_request_complete(adapter, isr);
1316                                 }
1317                         }
1318
1319                         if (isr & ISR_RCV) {
1320                                 adapter->rcv_interrupts++;
1321                                 slic_rcv_handler(adapter);
1322                         }
1323
1324                         if (isr & ISR_CMD) {
1325                                 adapter->xmit_interrupts++;
1326                                 slic_xmit_complete(adapter);
1327                         }
1328                         break;
1329
1330                 case CARD_DOWN:
1331                         if ((isr & ISR_UPC) ||
1332                             (isr & ISR_UPCERR) || (isr & ISR_UPCBSY)) {
1333                                 adapter->upr_interrupts++;
1334                                 slic_upr_request_complete(adapter, isr);
1335                         }
1336                         break;
1337
1338                 default:
1339                         break;
1340                 }
1341
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);
1346         } else {
1347                 adapter->false_interrupts++;
1348         }
1349         return IRQ_HANDLED;
1350 }
1351
1352 /*
1353  * slic_link_event_handler -
1354  *
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.
1360  *
1361  */
1362 static void slic_link_event_handler(struct adapter *adapter)
1363 {
1364         int status;
1365         struct slic_shmem *pshmem;
1366
1367         if (adapter->state != ADAPT_UP) {
1368                 /* Adapter is not operational.  Ignore.  */
1369                 return;
1370         }
1371
1372         pshmem = (struct slic_shmem *)adapter->phys_shmem;
1373
1374 #if defined(CONFIG_X86_64)
1375 /*
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);
1379 */
1380         status = slic_upr_request(adapter,
1381                                   SLIC_UPR_RLSR,
1382                                   SLIC_GET_ADDR_LOW(&pshmem->linkstatus),
1383                                   SLIC_GET_ADDR_HIGH(&pshmem->linkstatus),
1384                                   0, 0);
1385 #elif defined(CONFIG_X86)
1386         status = slic_upr_request(adapter, SLIC_UPR_RLSR,
1387                 (u32) &pshmem->linkstatus,      /* no 4GB wrap guaranteed */
1388                                   0, 0, 0);
1389 #else
1390         Stop compilation;
1391 #endif
1392         ASSERT((status == STATUS_SUCCESS) || (status == STATUS_PENDING));
1393 }
1394
1395 static void slic_init_cleanup(struct adapter *adapter)
1396 {
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);
1402
1403         }
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;
1413         }
1414 #if SLIC_GET_STATS_TIMER_ENABLED
1415         if (adapter->statstimerset) {
1416                 DBG_MSG("statstimer ");
1417                 adapter->statstimerset = 0;
1418                 del_timer(&adapter->statstimer);
1419         }
1420 #endif
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);
1427         }
1428 #endif
1429         slic_rspqueue_free(adapter);
1430         slic_cmdq_free(adapter);
1431         slic_rcvqueue_free(adapter);
1432
1433         DBG_MSG("\n");
1434 }
1435
1436 #if SLIC_GET_STATS_ENABLED
1437 static struct net_device_stats *slic_get_stats(struct net_device *dev)
1438 {
1439         struct adapter *adapter = (struct adapter *)netdev_priv(dev);
1440         struct net_device_stats *stats;
1441
1442         ASSERT(adapter);
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;
1455 }
1456 #endif
1457
1458 /*
1459  *  Allocate a mcast_address structure to hold the multicast address.
1460  *  Link it in.
1461  */
1462 static int slic_mcast_add_list(struct adapter *adapter, char *address)
1463 {
1464         struct mcast_address *mcaddr, *mlist;
1465         bool equaladdr;
1466
1467         /* Check to see if it already exists */
1468         mlist = adapter->mcastaddrs;
1469         while (mlist) {
1470                 ETHER_EQ_ADDR(mlist->address, address, equaladdr);
1471                 if (equaladdr)
1472                         return STATUS_SUCCESS;
1473                 mlist = mlist->next;
1474         }
1475
1476         /* Doesn't already exist.  Allocate a structure to hold it */
1477         mcaddr = kmalloc(sizeof(struct mcast_address), GFP_KERNEL);
1478         if (mcaddr == NULL)
1479                 return 1;
1480
1481         memcpy(mcaddr->address, address, 6);
1482
1483         mcaddr->next = adapter->mcastaddrs;
1484         adapter->mcastaddrs = mcaddr;
1485
1486         return STATUS_SUCCESS;
1487 }
1488
1489 /*
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
1492  * the polynomial:
1493  *   x^32 + x^26 + x^23 + x^22 + x^16 + x^12 + x^11 + x^10 + x^8 + x^7 + x^5 +
1494  *   x^4 + x^2 + x^1.
1495  *
1496  * After the CRC for the 6 bytes is generated (but before the value is
1497  * complemented),
1498  * we must then transpose the value and return bits 30-23.
1499  *
1500  */
1501 static u32 slic_crc_table[256]; /* Table of CRCs for all possible byte values */
1502 static u32 slic_crc_init;       /* Is table initialized */
1503
1504 /*
1505  *  Contruct the CRC32 table
1506  */
1507 static void slic_mcast_init_crc32(void)
1508 {
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  */
1513
1514         static int p[] = { 0, 1, 2, 4, 5, 7, 8, 10, 11, 12, 16, 22, 23, 26 };
1515
1516         for (i = 0; i < sizeof(p) / sizeof(int); i++)
1517                 e |= 1L << (31 - p[i]);
1518
1519         for (i = 1; i < 256; i++) {
1520                 c = i;
1521                 for (k = 8; k; k--)
1522                         c = c & 1 ? (c >> 1) ^ e : c >> 1;
1523                 slic_crc_table[i] = c;
1524         }
1525 }
1526
1527 /*
1528  *  Return the MAC hast as described above.
1529  */
1530 static unsigned char slic_mcast_get_mac_hash(char *macaddr)
1531 {
1532         u32 crc;
1533         char *p;
1534         int i;
1535         unsigned char machash = 0;
1536
1537         if (!slic_crc_init) {
1538                 slic_mcast_init_crc32();
1539                 slic_crc_init = 1;
1540         }
1541
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];
1545
1546         /* Return bits 1-8, transposed */
1547         for (i = 1; i < 9; i++)
1548                 machash |= (((crc >> i) & 1) << (8 - i));
1549
1550         return machash;
1551 }
1552
1553 static void slic_mcast_set_bit(struct adapter *adapter, char *address)
1554 {
1555         unsigned char crcpoly;
1556
1557         /* Get the CRC polynomial for the mac address */
1558         crcpoly = slic_mcast_get_mac_hash(address);
1559
1560         /* We only have space on the SLIC for 64 entries.  Lop
1561          * off the top two bits. (2^6 = 64)
1562          */
1563         crcpoly &= 0x3F;
1564
1565         /* OR in the new bit into our 64 bit mask. */
1566         adapter->mcastmask |= (u64) 1 << crcpoly;
1567 }
1568
1569 static void slic_mcast_set_list(struct net_device *dev)
1570 {
1571         struct adapter *adapter = (struct adapter *)netdev_priv(dev);
1572         int status = STATUS_SUCCESS;
1573         int i;
1574         char *addresses;
1575         struct dev_mc_list *mc_list = dev->mc_list;
1576         int mc_count = dev->mc_count;
1577
1578         ASSERT(adapter);
1579
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)
1585                                 break;
1586                 } else {
1587                         status = -EINVAL;
1588                         break;
1589                 }
1590                 slic_mcast_set_bit(adapter, addresses);
1591                 mc_list = mc_list->next;
1592         }
1593
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;
1598                 if (dev->flags) {
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;
1607                 }
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);
1612         } else {
1613                 if (status == STATUS_SUCCESS)
1614                         slic_mcast_set_mask(adapter);
1615         }
1616         return;
1617 }
1618
1619 static void slic_mcast_set_mask(struct adapter *adapter)
1620 {
1621         __iomem struct slic_regs *slic_regs = adapter->slic_regs;
1622
1623         DBG_MSG("%s ENTER (%s) macopts[%x] mask[%llx]\n", __func__,
1624                 adapter->netdev->name, (uint) adapter->macopts,
1625                 adapter->mcastmask);
1626
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
1631                  * configuration.
1632                  */
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,
1637                                  FLUSH);
1638 /*        DBG_MSG("%s (%s) WRITE to slic_regs slic_mcastlow&high 0xFFFFFFFF\n",
1639                 _func__, adapter->netdev->name); */
1640         } else {
1641                 /* Commit our multicast mast to the SLIC by writing to the
1642                  * multicast address mask registers
1643                  */
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)));
1648
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);
1653         }
1654 }
1655
1656 static void slic_timer_ping(ulong dev)
1657 {
1658         struct adapter *adapter;
1659         struct sliccard *card;
1660
1661         ASSERT(dev);
1662         adapter = netdev_priv((struct net_device *)dev);
1663         ASSERT(adapter);
1664         card = adapter->card;
1665         ASSERT(card);
1666 #if !SLIC_DUMP_ENABLED
1667 /*#if SLIC_DUMP_ENABLED*/
1668         if ((adapter->state == ADAPT_UP) && (card->state == CARD_UP)) {
1669                 int status;
1670
1671                 if (card->pingstatus != ISR_PINGMASK) {
1672                         if (errormsg++ < 5) {
1673                                 DBG_MSG
1674                                     ("%s (%s) CARD HAS CRASHED  PING_status == \
1675                                      %x ERRORMSG# %d\n",
1676                                      __func__, adapter->netdev->name,
1677                                      card->pingstatus, errormsg);
1678                         }
1679                         /*   ASSERT(card->pingstatus == ISR_PINGMASK); */
1680                 } else {
1681                         if (goodmsg++ < 5) {
1682                                 DBG_MSG
1683                                     ("slicoss: %s (%s) PING_status == %x \
1684                                      GOOD!!!!!!!! msg# %d\n",
1685                                      __func__, adapter->netdev->name,
1686                                      card->pingstatus, errormsg);
1687                         }
1688                 }
1689                 card->pingstatus = 0;
1690                 status = slic_upr_request(adapter, SLIC_UPR_PING, 0, 0, 0, 0);
1691
1692                 ASSERT(status == 0);
1693         } else {
1694                 DBG_MSG("slicoss %s (%s) adapter[%p] NOT UP!!!!\n",
1695                         __func__, adapter->netdev->name, adapter);
1696         }
1697 #endif
1698         adapter->pingtimer.expires = jiffies + (PING_TIMER_INTERVAL * HZ);
1699         add_timer(&adapter->pingtimer);
1700 }
1701
1702 static void slic_if_stop_queue(struct adapter *adapter)
1703 {
1704         netif_stop_queue(adapter->netdev);
1705 }
1706
1707 static void slic_if_start_queue(struct adapter *adapter)
1708 {
1709         netif_start_queue(adapter->netdev);
1710 }
1711
1712 /*
1713  *  slic_if_init
1714  *
1715  *  Perform initialization of our slic interface.
1716  *
1717  */
1718 static int slic_if_init(struct adapter *adapter)
1719 {
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;
1724         int status = 0;
1725
1726         ASSERT(card);
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);
1731
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");
1735                 return -EIO;
1736         }
1737         ASSERT(adapter->linkstate == LINK_DOWN);
1738
1739         adapter->devflags_prev = dev->flags;
1740         adapter->macopts = MAC_DIRECTED;
1741         if (dev->flags) {
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;
1746                         DBG_MSG("BCAST ");
1747                 }
1748                 if (dev->flags & IFF_PROMISC) {
1749                         adapter->macopts |= MAC_PROMISC;
1750                         DBG_MSG("PROMISC ");
1751                 }
1752                 if (dev->flags & IFF_ALLMULTI) {
1753                         adapter->macopts |= MAC_ALLMCAST;
1754                         DBG_MSG("ALL_MCAST ");
1755                 }
1756                 if (dev->flags & IFF_MULTICAST) {
1757                         adapter->macopts |= MAC_MCAST;
1758                         DBG_MSG("MCAST ");
1759                 }
1760                 DBG_MSG("\n");
1761         }
1762         status = slic_adapter_allocresources(adapter);
1763         if (status != STATUS_SUCCESS) {
1764                 DBG_ERROR
1765                     ("slic_if_init: slic_adapter_allocresources FAILED %x\n",
1766                      status);
1767                 slic_adapter_freeresources(adapter);
1768                 return status;
1769         }
1770
1771         if (!adapter->queues_initialized) {
1772                 DBG_MSG("slicoss: %s call slic_rspqueue_init\n", __func__);
1773                 if (slic_rspqueue_init(adapter))
1774                         return -ENOMEM;
1775                 DBG_MSG
1776                     ("slicoss: %s call slic_cmdq_init adapter[%p] port %d \n",
1777                      __func__, adapter, adapter->port);
1778                 if (slic_cmdq_init(adapter))
1779                         return -ENOMEM;
1780                 DBG_MSG
1781                     ("slicoss: %s call slic_rcvqueue_init adapter[%p] \
1782                      port %d \n", __func__, adapter, adapter->port);
1783                 if (slic_rcvqueue_init(adapter))
1784                         return -ENOMEM;
1785                 adapter->queues_initialized = 1;
1786         }
1787         DBG_MSG("slicoss: %s disable interrupts(slic)\n", __func__);
1788
1789         slic_reg32_write(&slic_regs->slic_icr, ICR_INT_OFF, FLUSH);
1790         mdelay(1);
1791
1792         if (!adapter->isp_initialized) {
1793                 pshmem = (struct slic_shmem *)adapter->phys_shmem;
1794
1795                 spin_lock_irqsave(&adapter->bit64reglock.lock,
1796                                         adapter->bit64reglock.flags);
1797
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);
1806 #else
1807                 Stop Compilations
1808 #endif
1809                 spin_unlock_irqrestore(&adapter->bit64reglock.lock,
1810                                         adapter->bit64reglock.flags);
1811                 adapter->isp_initialized = 1;
1812         }
1813
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);
1822
1823                 card->loadtimerset = 1;
1824         }
1825 #if SLIC_GET_STATS_TIMER_ENABLED
1826         if (!adapter->statstimerset) {
1827                 DBG_MSG("slicoss: %s start getstats_timer(slic)\n",
1828                         __func__);
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;
1836         }
1837 #endif
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",
1842                         __func__);
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;
1851         }
1852 #endif
1853
1854         /*
1855          *    clear any pending events, then enable interrupts
1856          */
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);
1862
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);
1866
1867         DBG_MSG("slicoss: %s EXIT\n", __func__);
1868         return STATUS_SUCCESS;
1869 }
1870
1871 static void slic_unmap_mmio_space(struct adapter *adapter)
1872 {
1873 #if LINUX_FREES_ADAPTER_RESOURCES
1874         if (adapter->slic_regs)
1875                 iounmap(adapter->slic_regs);
1876         adapter->slic_regs = NULL;
1877 #endif
1878 }
1879
1880 static int slic_adapter_allocresources(struct adapter *adapter)
1881 {
1882         if (!adapter->intrregistered) {
1883                 int retval;
1884
1885                 DBG_MSG
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,
1890                      NR_IRQS);
1891
1892                 spin_unlock_irqrestore(&slic_global.driver_lock.lock,
1893                                         slic_global.driver_lock.flags);
1894
1895                 retval = request_irq(adapter->netdev->irq,
1896                                      &slic_interrupt,
1897                                      IRQF_SHARED,
1898                                      adapter->netdev->name, adapter->netdev);
1899
1900                 spin_lock_irqsave(&slic_global.driver_lock.lock,
1901                                         slic_global.driver_lock.flags);
1902
1903                 if (retval) {
1904                         DBG_ERROR("slicoss: request_irq (%s) FAILED [%x]\n",
1905                                   adapter->netdev->name, retval);
1906                         return retval;
1907                 }
1908                 adapter->intrregistered = 1;
1909                 DBG_MSG
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);
1914         }
1915         return STATUS_SUCCESS;
1916 }
1917
1918 static void slic_config_pci(struct pci_dev *pcidev)
1919 {
1920         u16 pci_command;
1921         u16 new_command;
1922
1923         pci_read_config_word(pcidev, PCI_COMMAND, &pci_command);
1924         DBG_MSG("slicoss: %s  PCI command[%4.4x]\n", __func__, pci_command);
1925
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);
1934         }
1935 }
1936
1937 static void slic_adapter_freeresources(struct adapter *adapter)
1938 {
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__);
1953 }
1954
1955 /*
1956  *  slic_link_config
1957  *
1958  *  Write phy control to configure link duplex/speed
1959  *
1960  */
1961 static void slic_link_config(struct adapter *adapter,
1962                       u32 linkspeed, u32 linkduplex)
1963 {
1964         u32 __iomem *wphy;
1965         u32 speed;
1966         u32 duplex;
1967         u32 phy_config;
1968         u32 phy_advreg;
1969         u32 phy_gctlreg;
1970
1971         if (adapter->state != ADAPT_UP) {
1972                 DBG_MSG
1973                     ("%s (%s) ADAPT Not up yet, Return! speed[%x] duplex[%x]\n",
1974                      __func__, adapter->netdev->name, linkspeed,
1975                      linkduplex);
1976                 return;
1977         }
1978         DBG_MSG("slicoss: %s (%s) slic_link_config: speed[%x] duplex[%x]\n",
1979                 __func__, adapter->netdev->name, linkspeed, linkduplex);
1980
1981         ASSERT((adapter->devid == SLIC_1GB_DEVICE_ID)
1982                || (adapter->devid == SLIC_2GB_DEVICE_ID));
1983
1984         if (linkspeed > LINK_1000MB)
1985                 linkspeed = LINK_AUTOSPEED;
1986         if (linkduplex > LINK_AUTOD)
1987                 linkduplex = LINK_AUTOD;
1988
1989         wphy = &adapter->slic_regs->slic_wphy;
1990
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
1995                          */
1996
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);
2002
2003                         if (linkspeed == LINK_AUTOSPEED) {
2004                                 /* reset phy, enable auto-neg  */
2005                                 phy_config =
2006                                     (MIICR_REG_PCR |
2007                                      (PCR_RESET | PCR_AUTONEG |
2008                                       PCR_AUTONEG_RST));
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  */
2017                                 mdelay(10);
2018
2019                                 /* disable auto-neg, set speed/duplex,
2020                                    soft reset phy, powerup */
2021                                 phy_config =
2022                                     (MIICR_REG_PCR |
2023                                      (PCR_RESET | PCR_SPEED_1000 |
2024                                       PCR_DUPLEX_FULL));
2025                                 slic_reg32_write(wphy, phy_config, FLUSH);
2026                         }
2027                 } else {        /* copper gigabit */
2028
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
2032                          * in fiber mode
2033                          */
2034                         if (linkspeed == LINK_AUTOSPEED) {
2035                                 /* advertise 10/100 Mb modes   */
2036                                 phy_advreg =
2037                                     (MIICR_REG_4 |
2038                                      (PAR_ADV100FD | PAR_ADV100HD | PAR_ADV10FD
2039                                       | PAR_ADV10HD));
2040                         } else {
2041                         /* linkspeed == LINK_1000MB -
2042                            don't advertise 10/100 Mb modes  */
2043                                 phy_advreg = MIICR_REG_4;
2044                         }
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);
2053
2054                         if (adapter->subsysid != SLIC_1GB_CICADA_SUBSYS_ID) {
2055                                 /* if a Marvell PHY
2056                                    enable auto crossover */
2057                                 phy_config =
2058                                     (MIICR_REG_16 | (MRV_REG16_XOVERON));
2059                                 slic_reg32_write(wphy, phy_config, FLUSH);
2060
2061                                 /* reset phy, enable auto-neg  */
2062                                 phy_config =
2063                                     (MIICR_REG_PCR |
2064                                      (PCR_RESET | PCR_AUTONEG |
2065                                       PCR_AUTONEG_RST));
2066                                 slic_reg32_write(wphy, phy_config, FLUSH);
2067                         } else {        /* it's a Cicada PHY  */
2068                                 /* enable and restart auto-neg (don't reset)  */
2069                                 phy_config =
2070                                     (MIICR_REG_PCR |
2071                                      (PCR_AUTONEG | PCR_AUTONEG_RST));
2072                                 slic_reg32_write(wphy, phy_config, FLUSH);
2073                         }
2074                 }
2075         } else {
2076                 /* Forced 10/100  */
2077                 if (linkspeed == LINK_10MB)
2078                         speed = 0;
2079                 else
2080                         speed = PCR_SPEED_100;
2081                 if (linkduplex == LINK_HALFD)
2082                         duplex = 0;
2083                 else
2084                         duplex = PCR_DUPLEX_FULL;
2085
2086                 if (adapter->subsysid != SLIC_1GB_CICADA_SUBSYS_ID) {
2087                         /* if a Marvell PHY
2088                            disable auto crossover  */
2089                         phy_config = (MIICR_REG_16 | (MRV_REG16_XOVEROFF));
2090                         slic_reg32_write(wphy, phy_config, FLUSH);
2091                 }
2092
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);
2096
2097                 /* wait, Marvell says 1 sec, try to get away with 10 ms */
2098                 mdelay(10);
2099
2100                 if (adapter->subsysid != SLIC_1GB_CICADA_SUBSYS_ID) {
2101                         /* if a Marvell PHY
2102                            disable auto-neg, set speed,
2103                            soft reset phy, powerup */
2104                         phy_config =
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);
2111                 }
2112         }
2113
2114         DBG_MSG
2115             ("slicoss: %s (%s) EXIT slic_link_config : state[%d] \
2116             phy_config[%x]\n", __func__, adapter->netdev->name, adapter->state,
2117             phy_config);
2118 }
2119
2120 static void slic_card_cleanup(struct sliccard *card)
2121 {
2122         DBG_MSG("slicoss: %s ENTER\n", __func__);
2123
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;
2131         }
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;
2138         }
2139 #endif
2140
2141         if (card->loadtimerset) {
2142                 card->loadtimerset = 0;
2143                 del_timer(&card->loadtimer);
2144         }
2145
2146         slic_debug_card_destroy(card);
2147
2148         kfree(card);
2149         DBG_MSG("slicoss: %s EXIT\n", __func__);
2150 }
2151
2152 static int slic_card_download_gbrcv(struct adapter *adapter)
2153 {
2154         const struct firmware *fw;
2155         const char *file = "";
2156         int ret;
2157         __iomem struct slic_regs *slic_regs = adapter->slic_regs;
2158         u32 codeaddr;
2159         u32 instruction;
2160         int index = 0;
2161         u32 rcvucodelen = 0;
2162
2163         switch (adapter->devid) {
2164         case SLIC_2GB_DEVICE_ID:
2165                 file = "slicoss/oasisrcvucode.sys";
2166                 break;
2167         case SLIC_1GB_DEVICE_ID:
2168                 file = "slicoss/gbrcvucode.sys";
2169                 break;
2170         default:
2171                 ASSERT(0);
2172                 break;
2173         }
2174
2175         ret = request_firmware(&fw, file, &adapter->pcidev->dev);
2176         if (ret) {
2177                 printk(KERN_ERR "SLICOSS: Failed to load firmware %s\n", file);
2178                 return ret;
2179         }
2180
2181         rcvucodelen = *(u32 *)(fw->data + index);
2182         index += 4;
2183         switch (adapter->devid) {
2184         case SLIC_2GB_DEVICE_ID:
2185                 if (rcvucodelen != OasisRcvUCodeLen)
2186                         return -EINVAL;
2187                 break;
2188         case SLIC_1GB_DEVICE_ID:
2189                 if (rcvucodelen != GBRcvUCodeLen)
2190                         return -EINVAL;
2191                 break;
2192         default:
2193                 ASSERT(0);
2194                 break;
2195         }
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);
2202
2203                 instruction = *(u32 *)(fw->data + index);
2204                 index += 4;
2205                 /* write out the instruction data low addr */
2206                 slic_reg32_write(&slic_regs->slic_rcv_wcs, instruction, FLUSH);
2207
2208                 instruction = *(u8 *)(fw->data + index);
2209                 index++;
2210                 /* write out the instruction data high addr */
2211                 slic_reg32_write(&slic_regs->slic_rcv_wcs, (u8)instruction,
2212                                  FLUSH);
2213         }
2214
2215         /* download finished */
2216         release_firmware(fw);
2217         slic_reg32_write(&slic_regs->slic_rcv_wcs, SLIC_RCVWCS_FINISH, FLUSH);
2218         return 0;
2219 }
2220
2221 static int slic_card_download(struct adapter *adapter)
2222 {
2223         const struct firmware *fw;
2224         const char *file = "";
2225         int ret;
2226         u32 section;
2227         int thissectionsize;
2228         int codeaddr;
2229         __iomem struct slic_regs *slic_regs = adapter->slic_regs;
2230         u32 instruction;
2231         u32 baseaddress;
2232         u32 failure;
2233         u32 i;
2234         u32 numsects = 0;
2235         u32 sectsize[3];
2236         u32 sectstart[3];
2237         int ucode_start, index = 0;
2238
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()); */
2242
2243         switch (adapter->devid) {
2244         case SLIC_2GB_DEVICE_ID:
2245                 file = "slicoss/oasisdownload.sys";
2246                 break;
2247         case SLIC_1GB_DEVICE_ID:
2248                 file = "slicoss/gbdownload.sys";
2249                 break;
2250         default:
2251                 ASSERT(0);
2252                 break;
2253         }
2254         ret = request_firmware(&fw, file, &adapter->pcidev->dev);
2255         if (ret) {
2256                 printk(KERN_ERR "SLICOSS: Failed to load firmware %s\n", file);
2257                 return ret;
2258         }
2259         numsects = *(u32 *)(fw->data + index);
2260         index += 4;
2261         ASSERT(numsects <= 3);
2262         for (i = 0; i < numsects; i++) {
2263                 sectsize[i] = *(u32 *)(fw->data + index);
2264                 index += 4;
2265         }
2266         for (i = 0; i < numsects; i++) {
2267                 sectstart[i] = *(u32 *)(fw->data + index);
2268                 index += 4;
2269         }
2270         ucode_start = index;
2271         instruction = *(u32 *)(fw->data + index);
2272         index += 4;
2273         for (section = 0; section < numsects; section++) {
2274                 baseaddress = sectstart[section];
2275                 thissectionsize = sectsize[section] >> 3;
2276
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);
2284                         index += 4;
2285
2286                         /* Write out instruction to high addr */
2287                         slic_reg32_write(&slic_regs->slic_wcs, instruction, FLUSH);
2288                         instruction = *(u32 *)(fw->data + index);
2289                         index += 4;
2290                 }
2291         }
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)
2297                         continue;
2298                 thissectionsize = sectsize[section] >> 3;
2299
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),
2306                                 FLUSH);
2307                         /* Write out instruction to low addr */
2308                         slic_reg32_write(&slic_regs->slic_wcs, instruction,
2309                                          FLUSH);
2310                         instruction = *(u32 *)(fw->data + index);
2311                         index += 4;
2312                         /* Write out instruction to high addr */
2313                         slic_reg32_write(&slic_regs->slic_wcs, instruction,
2314                                          FLUSH);
2315                         instruction = *(u32 *)(fw->data + index);
2316                         index += 4;
2317
2318                         /* Check SRAM location zero. If it is non-zero. Abort.*/
2319 /*                      failure = readl((u32 __iomem *)&slic_regs->slic_reset);
2320                         if (failure) {
2321                                 DBG_MSG
2322                                     ("slicoss: %s FAILURE EXIT codeaddr[%x] "
2323                                     "thissectionsize[%x] failure[%x]\n",
2324                                      __func__, codeaddr, thissectionsize,
2325                                      failure);
2326                                 release_firmware(fw);
2327                                 return -EIO;
2328                         }*/
2329                 }
2330         }
2331 /*    DBG_MSG ("slicoss: Compare done\n");*/
2332         release_firmware(fw);
2333         /* Everything OK, kick off the card */
2334         mdelay(10);
2335         slic_reg32_write(&slic_regs->slic_wcs, SLIC_WCS_START, FLUSH);
2336
2337         /* stall for 20 ms, long enough for ucode to init card
2338            and reach mainloop */
2339         mdelay(20);
2340
2341         DBG_MSG("slicoss: %s (%s) EXIT adapter[%p] card[%p]\n",
2342                 __func__, adapter->netdev->name, adapter, adapter->card);
2343
2344         return STATUS_SUCCESS;
2345 }
2346
2347 static void slic_adapter_set_hwaddr(struct adapter *adapter)
2348 {
2349         struct sliccard *card = adapter->card;
2350
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);
2354
2355     slic_dbg_macaddrs(adapter); */
2356
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",
2362         __func__);
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);
2368                 }
2369                 if (adapter->netdev) {
2370                         memcpy(adapter->netdev->dev_addr, adapter->currmacaddr,
2371                                6);
2372                 }
2373         }
2374 /*  DBG_MSG ("%s EXIT port %d\n", __func__, adapter->port);
2375     slic_dbg_macaddrs(adapter); */
2376 }
2377
2378 static void slic_intagg_set(struct adapter *adapter, u32 value)
2379 {
2380         slic_reg32_write(&adapter->slic_regs->slic_intagg, value, FLUSH);
2381         adapter->card->loadlevel_current = value;
2382 }
2383
2384 static int slic_card_init(struct sliccard *card, struct adapter *adapter)
2385 {
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;
2390         u32 phys_configh;
2391         u32 phys_configl;
2392         u32 i = 0;
2393         struct slic_shmem *pshmem;
2394         int status;
2395         uint macaddrs = card->card_size;
2396         ushort eecodesize;
2397         ushort dramsize;
2398         ushort ee_chksum;
2399         ushort calc_chksum;
2400         struct slic_config_mac *pmac;
2401         unsigned char fruformat;
2402         unsigned char oemfruformat;
2403         struct atk_fru *patkfru;
2404         union oemfru *poemfru;
2405
2406         DBG_MSG
2407             ("slicoss: %s ENTER card[%p] adapter[%p] card->state[%x] \
2408             size[%d]\n", __func__, card, adapter, card->state, card->card_size);
2409
2410         /* Reset everything except PCI configuration space */
2411         slic_soft_reset(adapter);
2412
2413         /* Download the microcode */
2414         status = slic_card_download(adapter);
2415
2416         if (status != STATUS_SUCCESS) {
2417                 DBG_ERROR("SLIC download failed bus %d slot %d\n",
2418                           (uint) adapter->busnumber,
2419                           (uint) adapter->slotnumber);
2420                 return status;
2421         }
2422
2423         if (!card->config_set) {
2424                 peeprom = pci_alloc_consistent(adapter->pcidev,
2425                                                sizeof(struct slic_eeprom),
2426                                                &phys_config);
2427
2428                 phys_configl = SLIC_GET_ADDR_LOW(phys_config);
2429                 phys_configh = SLIC_GET_ADDR_HIGH(phys_config);
2430
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",
2435                         __func__, adapter,
2436                         (u32)sizeof(struct slic_eeprom),
2437                         peeprom, (void *) phys_config, phys_configl,
2438                         phys_configh);
2439                 if (!peeprom) {
2440                         DBG_ERROR
2441                             ("SLIC eeprom read failed to get memory bus %d \
2442                             slot %d\n",
2443                              (uint) adapter->busnumber,
2444                              (uint) adapter->slotnumber);
2445                         return -ENOMEM;
2446                 } else {
2447                         memset(peeprom, 0, sizeof(struct slic_eeprom));
2448                 }
2449                 slic_reg32_write(&slic_regs->slic_icr, ICR_INT_OFF, FLUSH);
2450                 mdelay(1);
2451                 pshmem = (struct slic_shmem *)adapter->phys_shmem;
2452
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);
2460
2461                 slic_config_get(adapter, phys_configl, phys_configh);
2462
2463                 for (;;) {
2464                         if (adapter->pshmem->isr) {
2465                                 DBG_MSG("%s shmem[%p] shmem->isr[%x]\n",
2466                                         __func__, adapter->pshmem,
2467                                         adapter->pshmem->isr);
2468
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,
2474                                                 0, FLUSH);
2475                                         slic_reg32_write(&slic_regs->slic_isr,
2476                                                          0, FLUSH);
2477
2478                                         slic_upr_request_complete(adapter, 0);
2479                                         break;
2480                                 } else {
2481                                         adapter->pshmem->isr = 0;
2482                                         slic_reg32_write(&slic_regs->slic_isr,
2483                                                          0, FLUSH);
2484                                 }
2485                         } else {
2486                                 mdelay(1);
2487                                 i++;
2488                                 if (i > 5000) {
2489                                         DBG_ERROR
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,
2498                                                 0, FLUSH);
2499                                         return -EINVAL;
2500                                 }
2501                         }
2502                 }
2503
2504                 switch (adapter->devid) {
2505                 /* Oasis card */
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;
2516                         macaddrs = 2;
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 */
2521                         break;
2522                 default:
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;
2531                         break;
2532                 }
2533
2534                 card->config.EepromValid = false;
2535
2536                 /*  see if the EEPROM is valid by checking it's checksum */
2537                 if ((eecodesize <= MAX_EECODE_SIZE) &&
2538                     (eecodesize >= MIN_EECODE_SIZE)) {
2539
2540                         ee_chksum =
2541                             *(u16 *) ((char *) peeprom + (eecodesize - 2));
2542                         /*
2543                             calculate the EEPROM checksum
2544                         */
2545                         calc_chksum =
2546                             ~slic_eeprom_cksum((char *) peeprom,
2547                                                (eecodesize - 2));
2548                         /*
2549                             if the ucdoe chksum flag bit worked,
2550                             we wouldn't need this shit
2551                         */
2552                         if (ee_chksum == calc_chksum)
2553                                 card->config.EepromValid = true;
2554                 }
2555                 /*  copy in the DRAM size */
2556                 card->config.DramSize = dramsize;
2557
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));
2562                 }
2563 /*      DBG_MSG ("%s EEPROM Checksum Good? %d  MacAddress\n",__func__,
2564                 card->config.EepromValid); */
2565
2566                 /*  copy the Alacritech FRU information */
2567                 card->config.FruFormat = fruformat;
2568                 memcpy(&card->config.AtkFru, patkfru,
2569                                                 sizeof(struct atk_fru));
2570
2571                 pci_free_consistent(adapter->pcidev,
2572                                     sizeof(struct slic_eeprom),
2573                                     peeprom, phys_config);
2574                 DBG_MSG
2575                     ("slicoss: %s adapter%d [%p] size[%x] FREE peeprom[%p] \
2576                      phys_config[%p]\n",
2577                      __func__, adapter->port, adapter,
2578                      (u32) sizeof(struct slic_eeprom), peeprom,
2579                      (void *) phys_config);
2580
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,
2585                                          0, FLUSH);
2586                         DBG_ERROR
2587                             ("unsupported CONFIGURATION  EEPROM invalid\n");
2588                         return -EINVAL;
2589                 }
2590
2591                 card->config_set = 1;
2592         }
2593
2594         if (slic_card_download_gbrcv(adapter)) {
2595                 DBG_ERROR("%s unable to download GB receive microcode\n",
2596                           __func__);
2597                 return -EINVAL;
2598         }
2599
2600         if (slic_global.dynamic_intagg) {
2601                 DBG_MSG
2602                     ("Dynamic Interrupt Aggregation[ENABLED]: slic%d \
2603                      SET intagg to %d\n",
2604                      card->cardnum, 0);
2605                 slic_intagg_set(adapter, 0);
2606         } else {
2607                 slic_intagg_set(adapter, intagg_delay);
2608                 DBG_MSG
2609                     ("Dynamic Interrupt Aggregation[DISABLED]: slic%d \
2610                      SET intagg to %d\n",
2611                      card->cardnum, intagg_delay);
2612         }
2613
2614         /*
2615          *  Initialize ping status to "ok"
2616          */
2617         card->pingstatus = ISR_PINGMASK;
2618
2619 #if SLIC_DUMP_ENABLED
2620         if (!card->dumpbuffer) {
2621                 card->dumpbuffer = kmalloc(DUMP_PAGE_SIZE, GFP_KERNEL);
2622
2623                 ASSERT(card->dumpbuffer);
2624                 if (card->dumpbuffer == NULL)
2625                         return -ENOMEM;
2626         }
2627         /*
2628          *  Smear the shared memory structure and then obtain
2629          *  the PHYSICAL address of this structure
2630          */
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);
2635
2636         /*
2637          *  Allocate COMMAND BUFFER
2638          */
2639         if (!card->cmdbuffer) {
2640                 card->cmdbuffer = kmalloc(sizeof(struct dump_cmd), GFP_KERNEL);
2641
2642                 ASSERT(card->cmdbuffer);
2643                 if (card->cmdbuffer == NULL)
2644                         return -ENOMEM;
2645         }
2646         /*
2647          *  Smear the shared memory structure and then obtain
2648          *  the PHYSICAL address of this structure
2649          */
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);
2654 #endif
2655
2656         /*
2657          * Lastly, mark our card state as up and return success
2658          */
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);
2663
2664         return STATUS_SUCCESS;
2665 }
2666
2667 static u32 slic_card_locate(struct adapter *adapter)
2668 {
2669         struct sliccard *card = slic_global.slic_card;
2670         struct physcard *physcard = slic_global.phys_card;
2671         ushort card_hostid;
2672         u16 __iomem *hostid_reg;
2673         uint i;
2674         uint rdhostid_offset = 0;
2675
2676         DBG_MSG("slicoss: %s adapter[%p] slot[%x] bus[%x] port[%x]\n",
2677                 __func__, adapter, adapter->slotnumber, adapter->busnumber,
2678                 adapter->port);
2679
2680         switch (adapter->devid) {
2681         case SLIC_2GB_DEVICE_ID:
2682                 rdhostid_offset = SLIC_RDHOSTID_2GB;
2683                 break;
2684         case SLIC_1GB_DEVICE_ID:
2685                 rdhostid_offset = SLIC_RDHOSTID_1GB;
2686                 break;
2687         default:
2688                 ASSERT(0);
2689                 break;
2690         }
2691
2692         hostid_reg =
2693             (u16 __iomem *) (((u8 __iomem *) (adapter->slic_regs)) +
2694             rdhostid_offset);
2695         DBG_MSG("slicoss: %s *hostid_reg[%p] == ", __func__, hostid_reg);
2696
2697         /* read the 16 bit hostid from SRAM */
2698         card_hostid = (ushort) readw(hostid_reg);
2699         DBG_MSG(" card_hostid[%x]\n", card_hostid);
2700
2701         /* Initialize a new card structure if need be */
2702         if (card_hostid == SLIC_HOSTID_DEFAULT) {
2703                 card = kzalloc(sizeof(struct sliccard), GFP_KERNEL);
2704                 if (card == NULL)
2705                         return -ENOMEM;
2706
2707                 card->next = slic_global.slic_card;
2708                 slic_global.slic_card = card;
2709 #if DBG
2710                 if (adapter->devid == SLIC_2GB_DEVICE_ID) {
2711                         DBG_MSG
2712                             ("SLICOSS ==> Initialize 2 Port Gigabit Server "
2713                              "and Storage Accelerator\n");
2714                 } else {
2715                         DBG_MSG
2716                             ("SLICOSS ==> Initialize 1 Port Gigabit Server "
2717                              "and Storage Accelerator\n");
2718                 }
2719 #endif
2720                 card->busnumber = adapter->busnumber;
2721                 card->slotnumber = adapter->slotnumber;
2722
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;
2727                                 card->cardnum = i;
2728                                 break;
2729                         }
2730                 }
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);
2734
2735                 slic_debug_card_create(card);
2736         } else {
2737                 DBG_MSG
2738                     ("slicoss: %s CARD already allocated, find the \
2739                      correct card\n", __func__);
2740                 /* Card exists, find the card this adapter belongs to */
2741                 while (card) {
2742                         DBG_MSG
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);
2748
2749                         if (card->cardnum == card_hostid)
2750                                 break;
2751                         card = card->next;
2752                 }
2753         }
2754
2755         ASSERT(card);
2756         if (!card)
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;
2763         }
2764
2765         card->card_size = 1;    /* one port per *logical* card */
2766
2767         while (physcard) {
2768                 for (i = 0; i < SLIC_MAX_PORTS; i++) {
2769                         if (!physcard->adapter[i])
2770                                 continue;
2771                         else
2772                                 break;
2773                 }
2774                 ASSERT(i != SLIC_MAX_PORTS);
2775                 if (physcard->adapter[i]->slotnumber == adapter->slotnumber)
2776                         break;
2777                 physcard = physcard->next;
2778         }
2779         if (!physcard) {
2780                 /* no structure allocated for this physical card yet */
2781                 physcard = kzalloc(sizeof(struct physcard), GFP_KERNEL);
2782                 ASSERT(physcard);
2783
2784                 DBG_MSG
2785                     ("\n%s Allocate a PHYSICALcard:\n    PHYSICAL_Card[%p]\n"
2786                      "    LogicalCard  [%p]\n    adapter      [%p]\n",
2787                      __func__, physcard, card, adapter);
2788
2789                 physcard->next = slic_global.phys_card;
2790                 slic_global.phys_card = physcard;
2791                 physcard->adapters_allocd = 1;
2792         } else {
2793                 physcard->adapters_allocd++;
2794         }
2795         /* Note - this is ZERO relative */
2796         adapter->physport = physcard->adapters_allocd - 1;
2797
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,
2802                 adapter->port);
2803
2804         return 0;
2805 }
2806
2807 static void slic_soft_reset(struct adapter *adapter)
2808 {
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);
2813                 mdelay(1);
2814         }
2815 /*      DBG_MSG ("slicoss: %s (%s) adapter[%p] card[%p] devid[%x]\n",
2816         __func__, adapter->netdev->name, adapter, adapter->card,
2817            adapter->devid); */
2818
2819         slic_reg32_write(&adapter->slic_regs->slic_reset, SLIC_RESET_MAGIC,
2820                          FLUSH);
2821         mdelay(1);
2822 }
2823
2824 static void slic_config_set(struct adapter *adapter, bool linkchange)
2825 {
2826         u32 value;
2827         u32 RcrReset;
2828         __iomem struct slic_regs *slic_regs = adapter->slic_regs;
2829
2830         DBG_MSG("slicoss: %s (%s) slic_interface_enable[%p](%d)\n",
2831                 __func__, adapter->netdev->name, adapter,
2832                 adapter->cardindex);
2833
2834         if (linkchange) {
2835                 /* Setup MAC */
2836                 slic_mac_config(adapter);
2837                 RcrReset = GRCR_RESET;
2838         } else {
2839                 slic_mac_address_config(adapter);
2840                 RcrReset = 0;
2841         }
2842
2843         if (adapter->linkduplex == LINK_FULLD) {
2844                 /* setup xmtcfg */
2845                 value = (GXCR_RESET |   /* Always reset     */
2846                          GXCR_XMTEN |   /* Enable transmit  */
2847                          GXCR_PAUSEEN); /* Enable pause     */
2848
2849                 DBG_MSG("slicoss: FDX adapt[%p] set xmtcfg to [%x]\n", adapter,
2850                         value);
2851                 slic_reg32_write(&slic_regs->slic_wxcfg, value, FLUSH);
2852
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));
2859         } else {
2860                 /* setup xmtcfg */
2861                 value = (GXCR_RESET |   /* Always reset     */
2862                          GXCR_XMTEN);   /* Enable transmit  */
2863
2864                 DBG_MSG("slicoss: HDX adapt[%p] set xmtcfg to [%x]\n", adapter,
2865                         value);
2866                 slic_reg32_write(&slic_regs->slic_wxcfg, value, FLUSH);
2867
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));
2873         }
2874
2875         if (adapter->state != ADAPT_DOWN) {
2876                 /* Only enable receive if we are restarting or running */
2877                 value |= GRCR_RCVEN;
2878         }
2879
2880         if (adapter->macopts & MAC_PROMISC)
2881                 value |= GRCR_RCVALL;
2882
2883         DBG_MSG("slicoss: adapt[%p] set rcvcfg to [%x]\n", adapter, value);
2884         slic_reg32_write(&slic_regs->slic_wrcfg, value, FLUSH);
2885 }
2886
2887 /*
2888  *  Turn off RCV and XMT, power down PHY
2889  */
2890 static void slic_config_clear(struct adapter *adapter)
2891 {
2892         u32 value;
2893         u32 phy_config;
2894         __iomem struct slic_regs *slic_regs = adapter->slic_regs;
2895
2896         /* Setup xmtcfg */
2897         value = (GXCR_RESET |   /* Always reset */
2898                  GXCR_PAUSEEN); /* Enable pause */
2899
2900         slic_reg32_write(&slic_regs->slic_wxcfg, value, FLUSH);
2901
2902         value = (GRCR_RESET |   /* Always reset      */
2903                  GRCR_CTLEN |   /* Enable CTL frames */
2904                  GRCR_ADDRAEN | /* Address A enable  */
2905                  (GRCR_HASHSIZE << GRCR_HASHSIZE_SHIFT));
2906
2907         slic_reg32_write(&slic_regs->slic_wrcfg, value, FLUSH);
2908
2909         /* power down phy */
2910         phy_config = (MIICR_REG_PCR | (PCR_POWERDOWN));
2911         slic_reg32_write(&slic_regs->slic_wphy, phy_config, FLUSH);
2912 }
2913
2914 static void slic_config_get(struct adapter *adapter, u32 config,
2915                                                         u32 config_h)
2916 {
2917         int status;
2918
2919         status = slic_upr_request(adapter,
2920                                   SLIC_UPR_RCONFIG,
2921                                   (u32) config, (u32) config_h, 0, 0);
2922         ASSERT(status == 0);
2923 }
2924
2925 static void slic_mac_address_config(struct adapter *adapter)
2926 {
2927         u32 value;
2928         u32 value2;
2929         __iomem struct slic_regs *slic_regs = adapter->slic_regs;
2930
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);
2935
2936         value2 = (u32) ((adapter->currmacaddr[0] << 8 |
2937                              adapter->currmacaddr[1]) & 0xFFFF);
2938
2939         slic_reg32_write(&slic_regs->slic_wraddrah, value2, FLUSH);
2940         slic_reg32_write(&slic_regs->slic_wraddrbh, value2, FLUSH);
2941
2942         DBG_MSG("%s value1[%x] value2[%x] Call slic_mcast_set_mask\n",
2943                 __func__, value, value2);
2944         slic_dbg_macaddrs(adapter);
2945
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);
2950 }
2951
2952 static void slic_mac_config(struct adapter *adapter)
2953 {
2954         u32 value;
2955         __iomem struct slic_regs *slic_regs = adapter->slic_regs;
2956
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));
2962         } else {
2963                 value = ((GMCR_GAPBB_100 << GMCR_GAPBB_SHIFT) |
2964                          (GMCR_GAPR1_100 << GMCR_GAPR1_SHIFT) |
2965                          (GMCR_GAPR2_100 << GMCR_GAPR2_SHIFT));
2966         }
2967
2968         /* enable GMII */
2969         if (adapter->linkspeed == LINK_1000MB)
2970                 value |= GMCR_GBIT;
2971
2972         /* enable fullduplex */
2973         if ((adapter->linkduplex == LINK_FULLD)
2974             || (adapter->macopts & MAC_LOOPBACK)) {
2975                 value |= GMCR_FULLD;
2976         }
2977
2978         /* write mac config */
2979         slic_reg32_write(&slic_regs->slic_wmcfg, value, FLUSH);
2980
2981         /* setup mac addresses */
2982         slic_mac_address_config(adapter);
2983 }
2984
2985 static bool slic_mac_filter(struct adapter *adapter,
2986                         struct ether_header *ether_frame)
2987 {
2988         u32 opts = adapter->macopts;
2989         u32 *dhost4 = (u32 *)&ether_frame->ether_dhost[0];
2990         u16 *dhost2 = (u16 *)&ether_frame->ether_dhost[4];
2991         bool equaladdr;
2992
2993         if (opts & MAC_PROMISC) {
2994                 DBG_MSG("slicoss: %s (%s) PROMISCUOUS. Accept frame\n",
2995                         __func__, adapter->netdev->name);
2996                 return true;
2997         }
2998
2999         if ((*dhost4 == 0xFFFFFFFF) && (*dhost2 == 0xFFFF)) {
3000                 if (opts & MAC_BCAST) {
3001                         adapter->rcv_broadcasts++;
3002                         return true;
3003                 } else {
3004                         return false;
3005                 }
3006         }
3007
3008         if (ether_frame->ether_dhost[0] & 0x01) {
3009                 if (opts & MAC_ALLMCAST) {
3010                         adapter->rcv_multicasts++;
3011                         adapter->stats.multicast++;
3012                         return true;
3013                 }
3014                 if (opts & MAC_MCAST) {
3015                         struct mcast_address *mcaddr = adapter->mcastaddrs;
3016
3017                         while (mcaddr) {
3018                                 ETHER_EQ_ADDR(mcaddr->address,
3019                                               ether_frame->ether_dhost,
3020                                               equaladdr);
3021                                 if (equaladdr) {
3022                                         adapter->rcv_multicasts++;
3023                                         adapter->stats.multicast++;
3024                                         return true;
3025                                 }
3026                                 mcaddr = mcaddr->next;
3027                         }
3028                         return false;
3029                 } else {
3030                         return false;
3031                 }
3032         }
3033         if (opts & MAC_DIRECTED) {
3034                 adapter->rcv_unicasts++;
3035                 return true;
3036         }
3037         return false;
3038
3039 }
3040
3041 static int slic_mac_set_address(struct net_device *dev, void *ptr)
3042 {
3043         struct adapter *adapter = (struct adapter *)netdev_priv(dev);
3044         struct sockaddr *addr = ptr;
3045
3046         DBG_MSG("%s ENTER (%s)\n", __func__, adapter->netdev->name);
3047
3048         if (netif_running(dev))
3049                 return -EBUSY;
3050         if (!adapter)
3051                 return -EBUSY;
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]);
3064
3065         slic_config_set(adapter, true);
3066         return 0;
3067 }
3068
3069 /*
3070  *  slic_timer_get_stats
3071  *
3072  * Timer function used to suck the statistics out of the card every
3073  * 50 seconds or whatever STATS_TIMER_INTERVAL is set to.
3074  *
3075  */
3076 #if SLIC_GET_STATS_TIMER_ENABLED
3077 static void slic_timer_get_stats(ulong dev)
3078 {
3079         struct adapter *adapter;
3080         struct sliccard *card;
3081         struct slic_shmem *pshmem;
3082
3083         ASSERT(dev);
3084         adapter = netdev_priv((struct net_device *)dev);
3085         ASSERT(adapter);
3086         card = adapter->card;
3087         ASSERT(card);
3088
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,
3094                                  SLIC_UPR_STATS,
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,
3099                                  SLIC_UPR_STATS,
3100                                  (u32) &pshmem->inicstats, 0, 0, 0);
3101 #else
3102                 Stop compilation;
3103 #endif
3104         } else {
3105 /*              DBG_MSG ("slicoss: %s adapter[%p] linkstate[%x] NOT UP!\n",
3106                         __func__, adapter, adapter->linkstate); */
3107         }
3108         adapter->statstimer.expires = jiffies + (STATS_TIMER_INTERVAL * HZ);
3109         add_timer(&adapter->statstimer);
3110 }
3111 #endif
3112 static void slic_timer_load_check(ulong cardaddr)
3113 {
3114         struct sliccard *card = (struct sliccard *)cardaddr;
3115         struct adapter *adapter = card->master;
3116         u32 __iomem *intagg;
3117         u32 load = card->events;
3118         u32 level = 0;
3119
3120         intagg = &adapter->slic_regs->slic_intagg;
3121
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)
3126                                 level = 100;
3127                         else {
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;
3138                                 else
3139                                         level = SLIC_INTAGG_0;
3140                         }
3141                         if (card->loadlevel_current != level) {
3142                                 card->loadlevel_current = level;
3143                                 slic_reg32_write(intagg, level, FLUSH);
3144                         }
3145                 } else {
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;
3156                         else
3157                                 level = SLIC_INTAGG_0;
3158                         if (card->loadlevel_current != level) {
3159                                 card->loadlevel_current = level;
3160                                 slic_reg32_write(intagg, level, FLUSH);
3161                         }
3162                 }
3163         }
3164         card->events = 0;
3165         card->loadtimer.expires = jiffies + (SLIC_LOADTIMER_PERIOD * HZ);
3166         add_timer(&card->loadtimer);
3167 }
3168
3169 static void slic_assert_fail(void)
3170 {
3171         u32 cpuid;
3172         u32 curr_pid;
3173         cpuid = smp_processor_id();
3174         curr_pid = current->pid;
3175
3176         DBG_ERROR("%s CPU # %d ---- PID # %d\n", __func__, cpuid, curr_pid);
3177 }
3178
3179 static int slic_upr_queue_request(struct adapter *adapter,
3180                            u32 upr_request,
3181                            u32 upr_data,
3182                            u32 upr_data_h,
3183                            u32 upr_buffer, u32 upr_buffer_h)
3184 {
3185         struct slic_upr *upr;
3186         struct slic_upr *uprqueue;
3187
3188         upr = kmalloc(sizeof(struct slic_upr), GFP_ATOMIC);
3189         if (!upr) {
3190                 DBG_MSG("%s COULD NOT ALLOCATE UPR MEM\n", __func__);
3191
3192                 return -ENOMEM;
3193         }
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;
3200         upr->next = NULL;
3201         if (adapter->upr_list) {
3202                 uprqueue = adapter->upr_list;
3203
3204                 while (uprqueue->next)
3205                         uprqueue = uprqueue->next;
3206                 uprqueue->next = upr;
3207         } else {
3208                 adapter->upr_list = upr;
3209         }
3210         return STATUS_SUCCESS;
3211 }
3212
3213 static int slic_upr_request(struct adapter *adapter,
3214                      u32 upr_request,
3215                      u32 upr_data,
3216                      u32 upr_data_h,
3217                      u32 upr_buffer, u32 upr_buffer_h)
3218 {
3219         int status;
3220
3221         spin_lock_irqsave(&adapter->upr_lock.lock, adapter->upr_lock.flags);
3222         status = slic_upr_queue_request(adapter,
3223                                         upr_request,
3224                                         upr_data,
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);
3229                 return status;
3230         }
3231         slic_upr_start(adapter);
3232         spin_unlock_irqrestore(&adapter->upr_lock.lock,
3233                                 adapter->upr_lock.flags);
3234         return STATUS_PENDING;
3235 }
3236
3237 static void slic_upr_request_complete(struct adapter *adapter, u32 isr)
3238 {
3239         struct sliccard *card = adapter->card;
3240         struct slic_upr *upr;
3241
3242 /*    if (card->dump_requested) {
3243         DBG_MSG("ENTER slic_upr_request_complete Dump in progress ISR[%x]\n",
3244                 isr);
3245       } */
3246         spin_lock_irqsave(&adapter->upr_lock.lock, adapter->upr_lock.flags);
3247         upr = adapter->upr_list;
3248         if (!upr) {
3249                 ASSERT(0);
3250                 spin_unlock_irqrestore(&adapter->upr_lock.lock,
3251                                         adapter->upr_lock.flags);
3252                 return;
3253         }
3254         adapter->upr_list = upr->next;
3255         upr->next = NULL;
3256         adapter->upr_busy = 0;
3257         ASSERT(adapter->port == upr->adapter);
3258         switch (upr->upr_request) {
3259         case SLIC_UPR_STATS:
3260                 {
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;
3267 #endif
3268                         if (isr & ISR_UPCERR) {
3269                                 DBG_ERROR
3270                                     ("SLIC_UPR_STATS command failed isr[%x]\n",
3271                                      isr);
3272
3273                                 break;
3274                         }
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",
3278                                  __func__,
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);
3296
3297                         UPDATE_STATS_GB(stst->tcp.xmit_tcp_bytes,
3298                                         newstats->xmit_tcp_bytes_gb,
3299                                         old->xmit_tcp_bytes_gb);
3300
3301                         UPDATE_STATS_GB(stst->tcp.rcv_tcp_segs,
3302                                         newstats->rcv_tcp_segs_gb,
3303                                         old->rcv_tcp_segs_gb);
3304
3305                         UPDATE_STATS_GB(stst->tcp.rcv_tcp_bytes,
3306                                         newstats->rcv_tcp_bytes_gb,
3307                                         old->rcv_tcp_bytes_gb);
3308
3309                         UPDATE_STATS_GB(stst->iface.xmt_bytes,
3310                                         newstats->xmit_bytes_gb,
3311                                         old->xmit_bytes_gb);
3312
3313                         UPDATE_STATS_GB(stst->iface.xmt_ucast,
3314                                         newstats->xmit_unicasts_gb,
3315                                         old->xmit_unicasts_gb);
3316
3317                         UPDATE_STATS_GB(stst->iface.rcv_bytes,
3318                                         newstats->rcv_bytes_gb,
3319                                         old->rcv_bytes_gb);
3320
3321                         UPDATE_STATS_GB(stst->iface.rcv_ucast,
3322                                         newstats->rcv_unicasts_gb,
3323                                         old->rcv_unicasts_gb);
3324
3325                         UPDATE_STATS_GB(stst->iface.xmt_errors,
3326                                         newstats->xmit_collisions_gb,
3327                                         old->xmit_collisions_gb);
3328
3329                         UPDATE_STATS_GB(stst->iface.xmt_errors,
3330                                         newstats->xmit_excess_collisions_gb,
3331                                         old->xmit_excess_collisions_gb);
3332
3333                         UPDATE_STATS_GB(stst->iface.xmt_errors,
3334                                         newstats->xmit_other_error_gb,
3335                                         old->xmit_other_error_gb);
3336
3337                         UPDATE_STATS_GB(stst->iface.rcv_errors,
3338                                         newstats->rcv_other_error_gb,
3339                                         old->rcv_other_error_gb);
3340
3341                         UPDATE_STATS_GB(stst->iface.rcv_discards,
3342                                         newstats->rcv_drops_gb,
3343                                         old->rcv_drops_gb);
3344
3345                         if (newstats->rcv_drops_gb > old->rcv_drops_gb) {
3346                                 adapter->rcv_drops +=
3347                                     (newstats->rcv_drops_gb -
3348                                      old->rcv_drops_gb);
3349                         }
3350                         memcpy(old, newstats, sizeof(struct slic_stats));
3351 #endif
3352                         break;
3353                 }
3354         case SLIC_UPR_RLSR:
3355                 slic_link_upr_complete(adapter, isr);
3356                 break;
3357         case SLIC_UPR_RCONFIG:
3358                 break;
3359         case SLIC_UPR_RPHY:
3360                 ASSERT(0);
3361                 break;
3362         case SLIC_UPR_ENLB:
3363                 ASSERT(0);
3364                 break;
3365         case SLIC_UPR_ENCT:
3366                 ASSERT(0);
3367                 break;
3368         case SLIC_UPR_PDWN:
3369                 ASSERT(0);
3370                 break;
3371         case SLIC_UPR_PING:
3372                 card->pingstatus |= (isr & ISR_PINGDSMASK);
3373                 break;
3374 #if SLIC_DUMP_ENABLED
3375         case SLIC_UPR_DUMP:
3376                 card->dumpstatus |= (isr & ISR_UPCMASK);
3377                 break;
3378 #endif
3379         default:
3380                 ASSERT(0);
3381         }
3382         kfree(upr);
3383         slic_upr_start(adapter);
3384         spin_unlock_irqrestore(&adapter->upr_lock.lock,
3385                                 adapter->upr_lock.flags);
3386 }
3387
3388 static void slic_upr_start(struct adapter *adapter)
3389 {
3390         struct slic_upr *upr;
3391         __iomem struct slic_regs *slic_regs = adapter->slic_regs;
3392 /*
3393     char * ptr1;
3394     char * ptr2;
3395     uint cmdoffset;
3396 */
3397         upr = adapter->upr_list;
3398         if (!upr)
3399                 return;
3400         if (adapter->upr_busy)
3401                 return;
3402         adapter->upr_busy = 1;
3403
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,
3408                                          FLUSH);
3409                 } else {
3410                         slic_reg64_write(adapter, &slic_regs->slic_stats64,
3411                                          upr->upr_data,
3412                                          &slic_regs->slic_addr_upper,
3413                                          upr->upr_data_h, FLUSH);
3414                 }
3415                 break;
3416
3417         case SLIC_UPR_RLSR:
3418                 slic_reg64_write(adapter, &slic_regs->slic_rlsr, upr->upr_data,
3419                                  &slic_regs->slic_addr_upper, upr->upr_data_h,
3420                                  FLUSH);
3421                 break;
3422
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"
3428                         "    upr[%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);
3436                 break;
3437 #if SLIC_DUMP_ENABLED
3438         case SLIC_UPR_DUMP:
3439                 if (upr->upr_buffer || upr->upr_buffer_h) {
3440                         slic_reg64_write(adapter, &slic_regs->slic_dump_data,
3441                                          upr->upr_buffer,
3442                                          &slic_regs->slic_addr_upper,
3443                                          upr->upr_buffer_h, FLUSH);
3444                 }
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);
3448                 break;
3449 #endif
3450         case SLIC_UPR_PING:
3451                 slic_reg32_write(&slic_regs->slic_ping, 1, FLUSH);
3452                 break;
3453         default:
3454                 ASSERT(0);
3455         }
3456 }
3457
3458 static void slic_link_upr_complete(struct adapter *adapter, u32 isr)
3459 {
3460         u32 linkstatus = adapter->pshmem->linkstatus;
3461         uint linkup;
3462         unsigned char linkspeed;
3463         unsigned char linkduplex;
3464
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);
3468
3469         if ((isr & ISR_UPCERR) || (isr & ISR_UPCBSY)) {
3470                 struct slic_shmem *pshmem;
3471
3472                 pshmem = (struct slic_shmem *)adapter->phys_shmem;
3473 #if defined(CONFIG_X86_64)
3474                 slic_upr_queue_request(adapter,
3475                                        SLIC_UPR_RLSR,
3476                                        SLIC_GET_ADDR_LOW(&pshmem->linkstatus),
3477                                        SLIC_GET_ADDR_HIGH(&pshmem->linkstatus),
3478                                        0, 0);
3479 #elif defined(CONFIG_X86)
3480                 slic_upr_queue_request(adapter,
3481                                        SLIC_UPR_RLSR,
3482                                        (u32) &pshmem->linkstatus,
3483                                        SLIC_GET_ADDR_HIGH(pshmem), 0, 0);
3484 #else
3485                 Stop Compilation;
3486 #endif
3487                 return;
3488         }
3489         if (adapter->state != ADAPT_UP)
3490                 return;
3491
3492         ASSERT((adapter->devid == SLIC_1GB_DEVICE_ID)
3493                || (adapter->devid == SLIC_2GB_DEVICE_ID));
3494
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);
3504         } else {
3505                 linkspeed = LINK_10MB;
3506                 DBG_MSG("slicoss: %s (%s) GIGABIT Speed==10MB  ", __func__,
3507                         adapter->netdev->name);
3508         }
3509         if (linkstatus & GIG_FULLDUPLEX) {
3510                 linkduplex = LINK_FULLD;
3511                 DBG_MSG(" Duplex == FULL\n");
3512         } else {
3513                 linkduplex = LINK_HALFD;
3514                 DBG_MSG(" Duplex == HALF\n");
3515         }
3516
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);
3520                 return;
3521         }
3522
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);
3530                 return;
3531         }
3532
3533         /* link has changed at this point */
3534
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__,
3539                         adapter->physport);
3540                 return;
3541         }
3542
3543         /* link has gone from down to up */
3544         adapter->linkspeed = linkspeed;
3545         adapter->linkduplex = linkduplex;
3546
3547         if (adapter->linkstate != LINK_UP) {
3548                 /* setup the mac */
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);
3555         }
3556 #if 1
3557         switch (linkspeed) {
3558         case LINK_1000MB:
3559                 DBG_MSG
3560                     ("\n(%s) LINK UP!: GIGABIT SPEED == 1000MB  duplex[%x]\n",
3561                      adapter->netdev->name, adapter->linkduplex);
3562                 break;
3563         case LINK_100MB:
3564                 DBG_MSG("\n(%s) LINK UP!: SPEED == 100MB  duplex[%x]\n",
3565                         adapter->netdev->name, adapter->linkduplex);
3566                 break;
3567         default:
3568                 DBG_MSG("\n(%s) LINK UP!: SPEED == 10MB  duplex[%x]\n",
3569                         adapter->netdev->name, adapter->linkduplex);
3570                 break;
3571         }
3572 #endif
3573 }
3574
3575 /*
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.
3579  */
3580 static ushort slic_eeprom_cksum(char *m, int len)
3581 {
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);\
3584                 }
3585
3586         u16 *w;
3587         u32 sum = 0;
3588         u32 byte_swapped = 0;
3589         u32 w_int;
3590
3591         union {
3592                 char c[2];
3593                 ushort s;
3594         } s_util;
3595
3596         union {
3597                 ushort s[2];
3598                 int l;
3599         } l_util;
3600
3601         l_util.l = 0;
3602         s_util.s = 0;
3603
3604         w = (u16 *)m;
3605 #ifdef CONFIG_X86_64
3606         w_int = (u32) ((ulong) w & 0x00000000FFFFFFFF);
3607 #else
3608         w_int = (u32) (w);
3609 #endif
3610         if ((1 & w_int) && (len > 0)) {
3611                 REDUCE;
3612                 sum <<= 8;
3613                 s_util.c[0] = *(unsigned char *)w;
3614                 w = (u16 *)((char *)w + 1);
3615                 len--;
3616                 byte_swapped = 1;
3617         }
3618
3619         /* Unroll the loop to make overhead from branches &c small. */
3620         while ((len -= 32) >= 0) {
3621                 sum += w[0];
3622                 sum += w[1];
3623                 sum += w[2];
3624                 sum += w[3];
3625                 sum += w[4];
3626                 sum += w[5];
3627                 sum += w[6];
3628                 sum += w[7];
3629                 sum += w[8];
3630                 sum += w[9];
3631                 sum += w[10];
3632                 sum += w[11];
3633                 sum += w[12];
3634                 sum += w[13];
3635                 sum += w[14];
3636                 sum += w[15];
3637                 w = (u16 *)((ulong) w + 16);    /* verify */
3638         }
3639         len += 32;
3640         while ((len -= 8) >= 0) {
3641                 sum += w[0];
3642                 sum += w[1];
3643                 sum += w[2];
3644                 sum += w[3];
3645                 w = (u16 *)((ulong) w + 4);     /* verify */
3646         }
3647         len += 8;
3648         if (len != 0 || byte_swapped != 0) {
3649                 REDUCE;
3650                 while ((len -= 2) >= 0)
3651                         sum += *w++;    /* verify */
3652                 if (byte_swapped) {
3653                         REDUCE;
3654                         sum <<= 8;
3655                         byte_swapped = 0;
3656                         if (len == -1) {
3657                                 s_util.c[1] = *(char *) w;
3658                                 sum += s_util.s;
3659                                 len = 0;
3660                         } else {
3661                                 len = -1;
3662                         }
3663
3664                 } else if (len == -1) {
3665                         s_util.c[0] = *(char *) w;
3666                 }
3667
3668                 if (len == -1) {
3669                         s_util.c[1] = 0;
3670                         sum += s_util.s;
3671                 }
3672         }
3673         REDUCE;
3674         return (ushort) sum;
3675 }
3676
3677 static int slic_rspqueue_init(struct adapter *adapter)
3678 {
3679         int i;
3680         struct slic_rspqueue *rspq = &adapter->rspqueue;
3681         __iomem struct slic_regs *slic_regs = adapter->slic_regs;
3682         u32 paddrh = 0;
3683
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));
3688
3689         rspq->num_pages = SLIC_RSPQ_PAGES_GB;
3690
3691         for (i = 0; i < rspq->num_pages; i++) {
3692                 rspq->vaddr[i] =
3693                     pci_alloc_consistent(adapter->pcidev, PAGE_SIZE,
3694                                          &rspq->paddr[i]);
3695                 if (!rspq->vaddr[i]) {
3696                         DBG_ERROR
3697                             ("rspqueue_init_failed  pci_alloc_consistent\n");
3698                         slic_rspqueue_free(adapter);
3699                         return STATUS_FAILURE;
3700                 }
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]);
3706 #endif
3707                 memset(rspq->vaddr[i], 0, PAGE_SIZE);
3708 /*              DBG_MSG("slicoss: %s UPLOAD RSPBUFF Page pageix[%x] paddr[%p] "
3709                         "vaddr[%p]\n",
3710                         __func__, i, (void *)rspq->paddr[i], rspq->vaddr[i]); */
3711
3712                 if (paddrh == 0) {
3713                         slic_reg32_write(&slic_regs->slic_rbar,
3714                                 (rspq->paddr[i] | SLIC_RSPQ_BUFSINPAGE),
3715                                 DONT_FLUSH);
3716                 } else {
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);
3721                 }
3722         }
3723         rspq->offset = 0;
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;
3729 }
3730
3731 static int slic_rspqueue_reset(struct adapter *adapter)
3732 {
3733         struct slic_rspqueue *rspq = &adapter->rspqueue;
3734
3735         DBG_MSG("slicoss: %s (%s) ENTER adapter[%p]\n", __func__,
3736                 adapter->netdev->name, adapter);
3737         ASSERT(adapter->state == ADAPT_DOWN);
3738         ASSERT(rspq);
3739
3740         DBG_MSG("slicoss: Nothing to do. rspq[%p]\n"
3741                 "                             offset[%x]\n"
3742                 "                             pageix[%x]\n"
3743                 "                             rspbuf[%p]\n",
3744                 rspq, rspq->offset, rspq->pageindex, rspq->rspbuf);
3745
3746         DBG_MSG("slicoss: %s (%s) EXIT adapter[%p]\n", __func__,
3747                 adapter->netdev->name, adapter);
3748         return STATUS_SUCCESS;
3749 }
3750
3751 static void slic_rspqueue_free(struct adapter *adapter)
3752 {
3753         int i;
3754         struct slic_rspqueue *rspq = &adapter->rspqueue;
3755
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]) {
3760                         DBG_MSG
3761                             ("slicoss:  pci_free_consistent rspq->vaddr[%p] \
3762                             paddr[%p]\n",
3763                              rspq->vaddr[i], (void *) rspq->paddr[i]);
3764                         pci_free_consistent(adapter->pcidev, PAGE_SIZE,
3765                                             rspq->vaddr[i], rspq->paddr[i]);
3766                 }
3767                 rspq->vaddr[i] = NULL;
3768                 rspq->paddr[i] = 0;
3769         }
3770         rspq->offset = 0;
3771         rspq->pageindex = 0;
3772         rspq->rspbuf = NULL;
3773 }
3774
3775 static struct slic_rspbuf *slic_rspqueue_getnext(struct adapter *adapter)
3776 {
3777         struct slic_rspqueue *rspq = &adapter->rspqueue;
3778         struct slic_rspbuf *buf;
3779
3780         if (!(rspq->rspbuf->status))
3781                 return NULL;
3782
3783         buf = rspq->rspbuf;
3784 #ifndef CONFIG_X86_64
3785         ASSERT((buf->status & 0xFFFFFFE0) == 0);
3786 #endif
3787         ASSERT(buf->hosthandle);
3788         if (++rspq->offset < SLIC_RSPQ_BUFSINPAGE) {
3789                 rspq->rspbuf++;
3790 #ifndef CONFIG_X86_64
3791                 ASSERT(((u32) rspq->rspbuf & 0xFFFFFFE0) ==
3792                        (u32) rspq->rspbuf);
3793 #endif
3794         } else {
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;
3800                 rspq->offset = 0;
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);
3806 #endif
3807         }
3808 #ifndef CONFIG_X86_64
3809         ASSERT(((u32) buf & 0xFFFFFFE0) == (u32) buf);
3810 #endif
3811         return buf;
3812 }
3813
3814 static void slic_cmdqmem_init(struct adapter *adapter)
3815 {
3816         struct slic_cmdqmem *cmdqmem = &adapter->cmdqmem;
3817
3818         memset(cmdqmem, 0, sizeof(struct slic_cmdqmem));
3819 }
3820
3821 static void slic_cmdqmem_free(struct adapter *adapter)
3822 {
3823         struct slic_cmdqmem *cmdqmem = &adapter->cmdqmem;
3824         int i;
3825
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,
3833                                             PAGE_SIZE,
3834                                             (void *) cmdqmem->pages[i],
3835                                             cmdqmem->dma_pages[i]);
3836                 }
3837         }
3838         memset(cmdqmem, 0, sizeof(struct slic_cmdqmem));
3839 }
3840
3841 static u32 *slic_cmdqmem_addpage(struct adapter *adapter)
3842 {
3843         struct slic_cmdqmem *cmdqmem = &adapter->cmdqmem;
3844         u32 *pageaddr;
3845
3846         if (cmdqmem->pagecnt >= SLIC_CMDQ_MAXPAGES)
3847                 return NULL;
3848         pageaddr = pci_alloc_consistent(adapter->pcidev,
3849                                         PAGE_SIZE,
3850                                         &cmdqmem->dma_pages[cmdqmem->pagecnt]);
3851         if (!pageaddr)
3852                 return NULL;
3853 #ifndef CONFIG_X86_64
3854         ASSERT(((u32) pageaddr & 0xFFFFF000) == (u32) pageaddr);
3855 #endif
3856         cmdqmem->pages[cmdqmem->pagecnt] = pageaddr;
3857         cmdqmem->pagecnt++;
3858         return pageaddr;
3859 }
3860
3861 static int slic_cmdq_init(struct adapter *adapter)
3862 {
3863         int i;
3864         u32 *pageaddr;
3865
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);
3880 #endif
3881                 if (!pageaddr) {
3882                         slic_cmdq_free(adapter);
3883                         return STATUS_FAILURE;
3884                 }
3885                 slic_cmdq_addcmdpage(adapter, pageaddr);
3886         }
3887         adapter->slic_handle_ix = 1;
3888         DBG_MSG("slicoss: %s reset slic_handle_ix to ONE\n", __func__);
3889
3890         return STATUS_SUCCESS;
3891 }
3892
3893 static void slic_cmdq_free(struct adapter *adapter)
3894 {
3895         struct slic_hostcmd *cmd;
3896
3897         DBG_MSG("slicoss: %s adapter[%p] port %d FreeCommandsFrom CMDQ\n",
3898                 __func__, adapter, adapter->physport);
3899         cmd = adapter->cmdq_all.head;
3900         while (cmd) {
3901                 if (cmd->busy) {
3902                         struct sk_buff *tempskb;
3903
3904                         tempskb = cmd->skb;
3905                         if (tempskb) {
3906                                 cmd->skb = NULL;
3907                                 dev_kfree_skb_irq(tempskb);
3908                         }
3909                 }
3910                 cmd = cmd->next_all;
3911         }
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);
3916 }
3917
3918 static void slic_cmdq_reset(struct adapter *adapter)
3919 {
3920         struct slic_hostcmd *hcmd;
3921         struct sk_buff *skb;
3922         u32 outstanding;
3923
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;
3932         while (hcmd) {
3933                 if (hcmd->busy) {
3934                         skb = hcmd->skb;
3935                         ASSERT(skb);
3936                         DBG_MSG("slicoss: %s hcmd[%p] skb[%p] ", __func__,
3937                                 hcmd, skb);
3938                         hcmd->busy = 0;
3939                         hcmd->skb = NULL;
3940                         DBG_MSG(" Free SKB\n");
3941                         dev_kfree_skb_irq(skb);
3942                 }
3943                 hcmd = hcmd->next_all;
3944         }
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;
3953         while (hcmd) {
3954                 adapter->cmdq_free.count++;
3955                 hcmd->next = hcmd->next_all;
3956                 hcmd = hcmd->next_all;
3957         }
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);
3961         }
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);
3967 }
3968
3969 static void slic_cmdq_addcmdpage(struct adapter *adapter, u32 *page)
3970 {
3971         struct slic_hostcmd *cmd;
3972         struct slic_hostcmd *prev;
3973         struct slic_hostcmd *tail;
3974         struct slic_cmdqueue *cmdq;
3975         int cmdcnt;
3976         void *cmdaddr;
3977         ulong phys_addr;
3978         u32 phys_addrl;
3979         u32 phys_addrh;
3980         struct slic_handle *pslic_handle;
3981
3982         cmdaddr = page;
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); */
3986         cmdcnt = 0;
3987
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);
3991
3992         prev = NULL;
3993         tail = cmd;
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)
3999                         ASSERT(0);
4000                 ASSERT(pslic_handle ==
4001                        &adapter->slic_handles[pslic_handle->token.
4002                                               handle_index]);
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;
4008
4009                 cmd->pslic_handle = pslic_handle;
4010                 cmd->cmd64.hosthandle = pslic_handle->token.handle_token;
4011                 cmd->busy = false;
4012                 cmd->paddrl = phys_addrl;
4013                 cmd->paddrh = phys_addrh;
4014                 cmd->next_all = prev;
4015                 cmd->next = prev;
4016                 prev = cmd;
4017                 phys_addrl += SLIC_HOSTCMD_SIZE;
4018                 cmdaddr += SLIC_HOSTCMD_SIZE;
4019
4020                 cmd = (struct slic_hostcmd *)cmdaddr;
4021                 cmdcnt++;
4022         }
4023
4024         cmdq = &adapter->cmdq_all;
4025         cmdq->count += cmdcnt;  /*  SLIC_CMDQ_CMDSINPAGE;   mooktodo */
4026         tail->next_all = cmdq->head;
4027         ASSERT(VALID_ADDRESS(prev));
4028         cmdq->head = 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));
4034         cmdq->head = prev;
4035         spin_unlock_irqrestore(&cmdq->lock.lock, cmdq->lock.flags);
4036 }
4037
4038 static struct slic_hostcmd *slic_cmdq_getfree(struct adapter *adapter)
4039 {
4040         struct slic_cmdqueue *cmdq = &adapter->cmdq_free;
4041         struct slic_hostcmd *cmd = NULL;
4042
4043 lock_and_retry:
4044         spin_lock_irqsave(&cmdq->lock.lock, cmdq->lock.flags);
4045 retry:
4046         cmd = cmdq->head;
4047         if (cmd) {
4048                 cmdq->head = cmd->next;
4049                 cmdq->count--;
4050                 spin_unlock_irqrestore(&cmdq->lock.lock, cmdq->lock.flags);
4051         } else {
4052                 slic_cmdq_getdone(adapter);
4053                 cmd = cmdq->head;
4054                 if (cmd) {
4055                         goto retry;
4056                 } else {
4057                         u32 *pageaddr;
4058
4059                         spin_unlock_irqrestore(&cmdq->lock.lock,
4060                                                 cmdq->lock.flags);
4061                         pageaddr = slic_cmdqmem_addpage(adapter);
4062                         if (pageaddr) {
4063                                 slic_cmdq_addcmdpage(adapter, pageaddr);
4064                                 goto lock_and_retry;
4065                         }
4066                 }
4067         }
4068         return cmd;
4069 }
4070
4071 static void slic_cmdq_getdone(struct adapter *adapter)
4072 {
4073         struct slic_cmdqueue *done_cmdq = &adapter->cmdq_done;
4074         struct slic_cmdqueue *free_cmdq = &adapter->cmdq_free;
4075
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));
4079
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);
4086 }
4087
4088 static void slic_cmdq_putdone_irq(struct adapter *adapter,
4089                                 struct slic_hostcmd *cmd)
4090 {
4091         struct slic_cmdqueue *cmdq = &adapter->cmdq_done;
4092
4093         spin_lock(&cmdq->lock.lock);
4094         cmd->busy = 0;
4095         ASSERT(VALID_ADDRESS(cmdq->head));
4096         cmd->next = cmdq->head;
4097         ASSERT(VALID_ADDRESS(cmd));
4098         cmdq->head = cmd;
4099         cmdq->count++;
4100         if ((adapter->xmitq_full) && (cmdq->count > 10))
4101                 netif_wake_queue(adapter->netdev);
4102         spin_unlock(&cmdq->lock.lock);
4103 }
4104
4105 static int slic_rcvqueue_init(struct adapter *adapter)
4106 {
4107         int i, count;
4108         struct slic_rcvqueue *rcvq = &adapter->rcvqueue;
4109
4110         DBG_MSG("slicoss: %s ENTER adapter[%p]\n", __func__, adapter);
4111         ASSERT(adapter->state == ADAPT_DOWN);
4112         rcvq->tail = NULL;
4113         rcvq->head = NULL;
4114         rcvq->size = SLIC_RCVQ_ENTRIES;
4115         rcvq->errors = 0;
4116         rcvq->count = 0;
4117         i = (SLIC_RCVQ_ENTRIES / SLIC_RCVQ_FILLENTRIES);
4118         count = 0;
4119         while (i) {
4120                 count += slic_rcvqueue_fill(adapter);
4121                 i--;
4122         }
4123         if (rcvq->count < SLIC_RCVQ_MINENTRIES) {
4124                 slic_rcvqueue_free(adapter);
4125                 return STATUS_FAILURE;
4126         }
4127         DBG_MSG("slicoss: %s EXIT adapter[%p]\n", __func__, adapter);
4128         return STATUS_SUCCESS;
4129 }
4130
4131 static int slic_rcvqueue_reset(struct adapter *adapter)
4132 {
4133         struct slic_rcvqueue *rcvq = &adapter->rcvqueue;
4134
4135         DBG_MSG("slicoss: %s ENTER adapter[%p]\n", __func__, adapter);
4136         ASSERT(adapter->state == ADAPT_DOWN);
4137         ASSERT(rcvq);
4138
4139         DBG_MSG("slicoss: Nothing to do. rcvq[%p]\n"
4140                 "                             count[%x]\n"
4141                 "                             head[%p]\n"
4142                 "                             tail[%p]\n",
4143                 rcvq, rcvq->count, rcvq->head, rcvq->tail);
4144
4145         DBG_MSG("slicoss: %s EXIT adapter[%p]\n", __func__, adapter);
4146         return STATUS_SUCCESS;
4147 }
4148
4149 static void slic_rcvqueue_free(struct adapter *adapter)
4150 {
4151         struct slic_rcvqueue *rcvq = &adapter->rcvqueue;
4152         struct sk_buff *skb;
4153
4154         while (rcvq->head) {
4155                 skb = rcvq->head;
4156                 rcvq->head = rcvq->head->next;
4157                 dev_kfree_skb(skb);
4158         }
4159         rcvq->tail = NULL;
4160         rcvq->head = NULL;
4161         rcvq->count = 0;
4162 }
4163
4164 static struct sk_buff *slic_rcvqueue_getnext(struct adapter *adapter)
4165 {
4166         struct slic_rcvqueue *rcvq = &adapter->rcvqueue;
4167         struct sk_buff *skb;
4168         struct slic_rcvbuf *rcvbuf;
4169         int count;
4170
4171         if (rcvq->count) {
4172                 skb = rcvq->head;
4173                 rcvbuf = (struct slic_rcvbuf *)skb->head;
4174                 ASSERT(rcvbuf);
4175
4176                 if (rcvbuf->status & IRHDDR_SVALID) {
4177                         rcvq->head = rcvq->head->next;
4178                         skb->next = NULL;
4179                         rcvq->count--;
4180                 } else {
4181                         skb = NULL;
4182                 }
4183         } else {
4184                 DBG_ERROR("RcvQ Empty!! adapter[%p] rcvq[%p] count[%x]\n",
4185                           adapter, rcvq, rcvq->count);
4186                 skb = NULL;
4187         }
4188         while (rcvq->count < SLIC_RCVQ_FILLTHRESH) {
4189                 count = slic_rcvqueue_fill(adapter);
4190                 if (!count)
4191                         break;
4192         }
4193         if (skb)
4194                 rcvq->errors = 0;
4195         return skb;
4196 }
4197
4198 static int slic_rcvqueue_fill(struct adapter *adapter)
4199 {
4200         void *paddr;
4201         u32 paddrl;
4202         u32 paddrh;
4203         struct slic_rcvqueue *rcvq = &adapter->rcvqueue;
4204         int i = 0;
4205
4206         while (i < SLIC_RCVQ_FILLENTRIES) {
4207                 struct slic_rcvbuf *rcvbuf;
4208                 struct sk_buff *skb;
4209 #ifdef KLUDGE_FOR_4GB_BOUNDARY
4210 retry_rcvqfill:
4211 #endif
4212                 skb = alloc_skb(SLIC_RCVQ_RCVBUFSIZE, GFP_ATOMIC);
4213                 if (skb) {
4214                         paddr = (void *)pci_map_single(adapter->pcidev,
4215                                                           skb->data,
4216                                                           SLIC_RCVQ_RCVBUFSIZE,
4217                                                           PCI_DMA_FROMDEVICE);
4218                         paddrl = SLIC_GET_ADDR_LOW(paddr);
4219                         paddrh = SLIC_GET_ADDR_HIGH(paddr);
4220
4221                         skb->len = SLIC_RCVBUF_HEADSIZE;
4222                         rcvbuf = (struct slic_rcvbuf *)skb->head;
4223                         rcvbuf->status = 0;
4224                         skb->next = NULL;
4225 #ifdef KLUDGE_FOR_4GB_BOUNDARY
4226                         if (paddrl == 0) {
4227                                 DBG_ERROR
4228                                     ("%s: LOW 32bits PHYSICAL ADDRESS == 0 "
4229                                      "skb[%p]   PROBLEM\n"
4230                                      "         skbdata[%p]\n"
4231                                      "         skblen[%x]\n"
4232                                      "         paddr[%p]\n"
4233                                      "         paddrl[%x]\n"
4234                                      "         paddrh[%x]\n", __func__, skb,
4235                                      skb->data, skb->len, paddr, paddrl,
4236                                      paddrh);
4237                                 DBG_ERROR("         rcvq->head[%p]\n"
4238                                           "         rcvq->tail[%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;
4243                         }
4244 #else
4245                         if (paddrl == 0) {
4246                                 DBG_ERROR
4247                                     ("\n\n%s: LOW 32bits PHYSICAL ADDRESS == 0 "
4248                                      "skb[%p]  GIVE TO CARD ANYWAY\n"
4249                                      "         skbdata[%p]\n"
4250                                      "         paddr[%p]\n"
4251                                      "         paddrl[%x]\n"
4252                                      "         paddrh[%x]\n", __func__, skb,
4253                                      skb->data, paddr, paddrl, paddrh);
4254                         }
4255 #endif
4256                         if (paddrh == 0) {
4257                                 slic_reg32_write(&adapter->slic_regs->slic_hbar,
4258                                                  (u32)paddrl, DONT_FLUSH);
4259                         } else {
4260                                 slic_reg64_write(adapter,
4261                                         &adapter->slic_regs->slic_hbar64,
4262                                         paddrl,
4263                                         &adapter->slic_regs->slic_addr_upper,
4264                                         paddrh, DONT_FLUSH);
4265                         }
4266                         if (rcvq->head)
4267                                 rcvq->tail->next = skb;
4268                         else
4269                                 rcvq->head = skb;
4270                         rcvq->tail = skb;
4271                         rcvq->count++;
4272                         i++;
4273                 } else {
4274                         DBG_ERROR
4275                             ("%s slic_rcvqueue_fill could only get [%d] "
4276                              "skbuffs\n",
4277                              adapter->netdev->name, i);
4278                         break;
4279                 }
4280         }
4281         return i;
4282 }
4283
4284 static u32 slic_rcvqueue_reinsert(struct adapter *adapter, struct sk_buff *skb)
4285 {
4286         struct slic_rcvqueue *rcvq = &adapter->rcvqueue;
4287         void *paddr;
4288         u32 paddrl;
4289         u32 paddrh;
4290         struct slic_rcvbuf *rcvbuf = (struct slic_rcvbuf *)skb->head;
4291
4292         ASSERT(skb->len == SLIC_RCVBUF_HEADSIZE);
4293
4294         paddr = (void *)pci_map_single(adapter->pcidev, skb->head,
4295                                   SLIC_RCVQ_RCVBUFSIZE, PCI_DMA_FROMDEVICE);
4296         rcvbuf->status = 0;
4297         skb->next = NULL;
4298
4299         paddrl = SLIC_GET_ADDR_LOW(paddr);
4300         paddrh = SLIC_GET_ADDR_HIGH(paddr);
4301
4302         if (paddrl == 0) {
4303                 DBG_ERROR
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"
4310                           "         rcvq->tail[%p]\n"
4311                           "         rcvq->count[%x]\n", rcvq->head, rcvq->tail,
4312                           rcvq->count);
4313         }
4314         if (paddrh == 0) {
4315                 slic_reg32_write(&adapter->slic_regs->slic_hbar, (u32)paddrl,
4316                                  DONT_FLUSH);
4317         } else {
4318                 slic_reg64_write(adapter, &adapter->slic_regs->slic_hbar64,
4319                                  paddrl, &adapter->slic_regs->slic_addr_upper,
4320                                  paddrh, DONT_FLUSH);
4321         }
4322         if (rcvq->head)
4323                 rcvq->tail->next = skb;
4324         else
4325                 rcvq->head = skb;
4326         rcvq->tail = skb;
4327         rcvq->count++;
4328         return rcvq->count;
4329 }
4330
4331 static int slic_debug_card_show(struct seq_file *seq, void *v)
4332 {
4333 #ifdef MOOKTODO
4334         int i;
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);
4339 #endif
4340
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);
4349 #ifdef MOOKTODO
4350         seq_printf(seq, "VendorId                 : %4.4X\n",
4351                     config->VendorId);
4352         seq_printf(seq, "DeviceId                 : %4.4X\n",
4353                     config->DeviceId);
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++) {
4365                 seq_printf(seq,
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]);
4373         }
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;
4378
4379                 adapter = card->adapter[i];
4380                 if (adapter) {
4381                         seq_printf(seq,
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);
4388                 }
4389         }
4390         seq_printf(seq, "Generation #             : %4.4X\n", card->gennumber);
4391         seq_printf(seq, "RcvQ max entries         : %4.4X\n",
4392                     SLIC_RCVQ_ENTRIES);
4393         seq_printf(seq, "Ping Status              : %8.8X\n",
4394                     card->pingstatus);
4395         seq_printf(seq, "Minimum grant            : %2.2x\n",
4396                     config->MinGrant);
4397         seq_printf(seq, "Maximum Latency          : %2.2x\n", config->MaxLat);
4398         seq_printf(seq, "PciStatus                : %4.4x\n",
4399                     config->Pcistatus);
4400         seq_printf(seq, "Debug Device Id          : %4.4x\n",
4401                     config->DbgDevId);
4402         seq_printf(seq, "DRAM ROM Function        : %4.4x\n",
4403                     config->DramRomFn);
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",
4411                     config->PMECapab);
4412         seq_printf(seq, "Network Clock Controls   : %4.4X\n",
4413                     config->NwClkCtrls);
4414
4415         switch (config->FruFormat) {
4416         case ATK_FRU_FORMAT:
4417                 {
4418                         seq_printf(seq,
4419                             "Vendor                   : Alacritech, Inc.\n");
4420                         seq_printf(seq,
4421                             "Assembly #               : %c%c%c%c%c%c\n",
4422                                     fru[0], fru[1], fru[2], fru[3], fru[4],
4423                                     fru[5]);
4424                         seq_printf(seq,
4425                                     "Revision #               : %c%c\n",
4426                                     fru[6], fru[7]);
4427
4428                         if (config->OEMFruFormat == VENDOR4_FRU_FORMAT) {
4429                                 seq_printf(seq,
4430                                             "Serial   #               : "
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]);
4436                         } else {
4437                                 seq_printf(seq,
4438                                             "Serial   #               : "
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],
4444                                             fru[20], fru[21]);
4445                         }
4446                         break;
4447                 }
4448
4449         default:
4450                 {
4451                         seq_printf(seq,
4452                             "Vendor                   : Alacritech, Inc.\n");
4453                         seq_printf(seq,
4454                             "Serial   #               : Empty FRU\n");
4455                         break;
4456                 }
4457         }
4458
4459         switch (config->OEMFruFormat) {
4460         case VENDOR1_FRU_FORMAT:
4461                 {
4462                         seq_printf(seq, "FRU Information:\n");
4463                         seq_printf(seq, "    Commodity #          : %c\n",
4464                                     oemfru[0]);
4465                         seq_printf(seq,
4466                                     "    Assembly #           : %c%c%c%c\n",
4467                                     oemfru[1], oemfru[2], oemfru[3], oemfru[4]);
4468                         seq_printf(seq,
4469                                     "    Revision #           : %c%c\n",
4470                                     oemfru[5], oemfru[6]);
4471                         seq_printf(seq,
4472                                     "    Supplier #           : %c%c\n",
4473                                     oemfru[7], oemfru[8]);
4474                         seq_printf(seq,
4475                                     "    Date                 : %c%c\n",
4476                                     oemfru[9], oemfru[10]);
4477                         seq_sprintf(seq,
4478                                     "    Sequence #           : %c%c%c\n",
4479                                     oemfru[11], oemfru[12], oemfru[13]);
4480                         break;
4481                 }
4482
4483         case VENDOR2_FRU_FORMAT:
4484                 {
4485                         seq_printf(seq, "FRU Information:\n");
4486                         seq_printf(seq,
4487                                     "    Part     #           : "
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]);
4492                         seq_printf(seq,
4493                                     "    Supplier #           : %c%c%c%c%c\n",
4494                                     oemfru[8], oemfru[9], oemfru[10],
4495                                     oemfru[11], oemfru[12]);
4496                         seq_printf(seq,
4497                                     "    Date                 : %c%c%c\n",
4498                                     oemfru[13], oemfru[14], oemfru[15]);
4499                         seq_sprintf(seq,
4500                                     "    Sequence #           : %c%c%c%c\n",
4501                                     oemfru[16], oemfru[17], oemfru[18],
4502                                     oemfru[19]);
4503                         break;
4504                 }
4505
4506         case VENDOR3_FRU_FORMAT:
4507                 {
4508                         seq_printf(seq, "FRU Information:\n");
4509                 }
4510
4511         case VENDOR4_FRU_FORMAT:
4512                 {
4513                         seq_printf(seq, "FRU Information:\n");
4514                         seq_printf(seq,
4515                                     "    FRU Number           : "
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]);
4520                         seq_sprintf(seq,
4521                                     "    Part Number          : "
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]);
4526                         seq_printf(seq,
4527                                     "    EC Level             : "
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]);
4532                         break;
4533                 }
4534
4535         default:
4536                 break;
4537         }
4538 #endif
4539
4540         return 0;
4541 }
4542
4543 static int slic_debug_adapter_show(struct seq_file *seq, void *v)
4544 {
4545         struct adapter *adapter = seq->private;
4546
4547         if ((adapter->netdev) && (adapter->netdev->name)) {
4548                 seq_printf(seq, "info: interface          : %s\n",
4549                             adapter->netdev->name);
4550         }
4551         seq_printf(seq, "info: status             : %s\n",
4552                 SLIC_LINKSTATE(adapter->linkstate));
4553         seq_printf(seq, "info: port               : %d\n",
4554                 adapter->physport);
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",
4564                 SLIC_RCVQ_ENTRIES);
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",
4612                         adapter->num_isrs);
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);
4653
4654         return 0;
4655 }
4656 static int slic_debug_adapter_open(struct inode *inode, struct file *file)
4657 {
4658         return single_open(file, slic_debug_adapter_show, inode->i_private);
4659 }
4660
4661 static int slic_debug_card_open(struct inode *inode, struct file *file)
4662 {
4663         return single_open(file, slic_debug_card_show, inode->i_private);
4664 }
4665
4666 static const struct file_operations slic_debug_adapter_fops = {
4667         .owner          = THIS_MODULE,
4668         .open           = slic_debug_adapter_open,
4669         .read           = seq_read,
4670         .llseek         = seq_lseek,
4671         .release        = single_release,
4672 };
4673
4674 static const struct file_operations slic_debug_card_fops = {
4675         .owner          = THIS_MODULE,
4676         .open           = slic_debug_card_open,
4677         .read           = seq_read,
4678         .llseek         = seq_lseek,
4679         .release        = single_release,
4680 };
4681
4682 static void slic_debug_adapter_create(struct adapter *adapter)
4683 {
4684         struct dentry *d;
4685         char    name[7];
4686         struct sliccard *card = adapter->card;
4687
4688         if (!card->debugfs_dir)
4689                 return;
4690
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);
4697         else
4698                 adapter->debugfs_entry = d;
4699 }
4700
4701 static void slic_debug_adapter_destroy(struct adapter *adapter)
4702 {
4703         if (adapter->debugfs_entry) {
4704                 debugfs_remove(adapter->debugfs_entry);
4705                 adapter->debugfs_entry = NULL;
4706         }
4707 }
4708
4709 static void slic_debug_card_create(struct sliccard *card)
4710 {
4711         struct dentry *d;
4712         char    name[IFNAMSIZ];
4713
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",
4718                                 name);
4719         else {
4720                 card->debugfs_dir = d;
4721                 d = debugfs_create_file("cardinfo", S_IRUGO,
4722                                 slic_debugfs, card,
4723                                 &slic_debug_card_fops);
4724                 if (!d || IS_ERR(d))
4725                         pr_info(PFX "%s: debugfs create failed\n",
4726                                         name);
4727                 else
4728                         card->debugfs_cardinfo = d;
4729         }
4730 }
4731
4732 static void slic_debug_card_destroy(struct sliccard *card)
4733 {
4734         int i;
4735
4736         for (i = 0; i < card->card_size; i++) {
4737                 struct adapter *adapter;
4738
4739                 adapter = card->adapter[i];
4740                 if (adapter)
4741                         slic_debug_adapter_destroy(adapter);
4742         }
4743         if (card->debugfs_cardinfo) {
4744                 debugfs_remove(card->debugfs_cardinfo);
4745                 card->debugfs_cardinfo = NULL;
4746         }
4747         if (card->debugfs_dir) {
4748                 debugfs_remove(card->debugfs_dir);
4749                 card->debugfs_dir = NULL;
4750         }
4751 }
4752
4753 static void slic_debug_init(void)
4754 {
4755         struct dentry *ent;
4756
4757         ent = debugfs_create_dir("slic", NULL);
4758         if (!ent || IS_ERR(ent)) {
4759                 pr_info(PFX "debugfs create directory failed\n");
4760                 return;
4761         }
4762
4763         slic_debugfs = ent;
4764 }
4765
4766 static void slic_debug_cleanup(void)
4767 {
4768         if (slic_debugfs) {
4769                 debugfs_remove(slic_debugfs);
4770                 slic_debugfs = NULL;
4771         }
4772 }
4773
4774 /*=============================================================================
4775   =============================================================================
4776   ===                                                                       ===
4777   ===       SLIC  DUMP  MANAGEMENT        SECTION                           ===
4778   ===                                                                       ===
4779   ===                                                                       ===
4780   === Dump routines                                                         ===
4781   ===                                                                       ===
4782   ===                                                                       ===
4783   =============================================================================
4784   ============================================================================*/
4785
4786 #if SLIC_DUMP_ENABLED
4787
4788 #include <stdarg.h>
4789
4790 void *slic_dump_handle;         /* thread handle */
4791
4792 /*
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.
4795  */
4796 static int slic_dump_seek(struct file *SLIChandle, u32 file_offset)
4797 {
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)
4804                                 return 0;
4805                 } else {
4806                         SLIChandle->f_pos = file_offset;
4807                 }
4808         }
4809         return 1;
4810 }
4811
4812 static int slic_dump_write(struct sliccard *card,
4813                            const void *addr, int size, u32 file_offset)
4814 {
4815         int r = 1;
4816         u32 result = 0;
4817         struct file *SLIChandle = card->dumphandle;
4818
4819 #ifdef HISTORICAL               /* legacy */
4820         down(&SLIChandle->f_dentry->d_inode->i_sem);
4821 #endif
4822         if (size) {
4823                 slic_dump_seek(SLIChandle, file_offset);
4824
4825                 result =
4826                     SLIChandle->f_op->write(SLIChandle, addr, size,
4827                                             &SLIChandle->f_pos);
4828
4829                 r = result == size;
4830         }
4831
4832         card->dumptime_complete = jiffies;
4833         card->dumptime_delta = card->dumptime_complete - card->dumptime_start;
4834         card->dumptime_start = jiffies;
4835
4836 #ifdef HISTORICAL
4837         up(&SLIChandle->f_dentry->d_inode->i_sem);
4838 #endif
4839         if (!r) {
4840                 DBG_ERROR("%s: addr[%p] size[%x] result[%x] file_offset[%x]\n",
4841                           __func__, addr, size, result, file_offset);
4842         }
4843         return r;
4844 }
4845
4846 static uint slic_init_dump_thread(struct sliccard *card)
4847 {
4848         card->dump_task_id = kthread_run(slic_dump_thread, (void *)card, 0);
4849
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;
4854         }
4855
4856         return STATUS_SUCCESS;
4857 }
4858
4859 static int slic_dump_thread(void *context)
4860 {
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;
4867         u32 i;
4868         struct slic_upr *upr, *uprnext;
4869         u32 dump_card;
4870
4871         ASSERT(card);
4872
4873         card->dumpthread_running = 1;
4874
4875 #ifdef HISTORICAL
4876         lock_kernel();
4877         /*
4878          * This thread doesn't need any user-level access,
4879          * so get rid of all our resources
4880          */
4881         exit_files(current);    /* daemonize doesn't do exit_files */
4882         current->files = init_task.files;
4883         atomic_inc(&current->files->count);
4884 #endif
4885
4886         daemonize("%s", "slicmon");
4887
4888         /* Setup a nice name */
4889         strcpy(current->comm, "slicmon");
4890         DBG_ERROR
4891             ("slic_dump_thread[slicmon] daemon is alive card[%p] pid[%x]\n",
4892              card, card->dump_task_id->pid);
4893
4894         /*
4895          *    Send me a signal to get me to die (for debugging)
4896          */
4897         do {
4898                 /*
4899                  * If card state is not set to up, skip
4900                  */
4901                 if (card->state != CARD_UP) {
4902                         if (card->adapters_activated)
4903                                 goto wait;
4904                         else
4905                                 goto end_thread;
4906                 }
4907                 /*
4908                  *    Check the results of our last ping.
4909                  */
4910                 dump_card = 0;
4911 #ifdef SLIC_FAILURE_DUMP
4912                 if (card->pingstatus != ISR_PINGMASK) {
4913                         DBG_MSG
4914                             ("\n[slicmon]  CARD #%d TIMED OUT - status "
4915                              "%x: DUMP THE CARD!\n",
4916                              card->cardnum, card->pingstatus);
4917                         dump_card = 1;
4918                 }
4919 #else
4920                 /*
4921                  *  Cause a card RESET instead?
4922                  */
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); */
4928                         DBG_ERROR
4929                             ("\n[slicmon]  CARD #%d TIMED OUT - status %x: "
4930                              "DUMP THE CARD!\n",
4931                              card->cardnum, card->pingstatus);
4932                         dump_card = 1;
4933                 }
4934 #endif
4935                 if ((dump_card)
4936                     || (card->dump_requested == SLIC_DUMP_REQUESTED)) {
4937                         if (card->dump_requested == SLIC_DUMP_REQUESTED) {
4938                                 DBG_ERROR
4939                             ("[slicmon]: Dump card Requested: Card %x\n",
4940                                      card->cardnum);
4941                         }
4942                         if (card->pingstatus != ISR_PINGMASK) {
4943                                 ushort cpuid = 0;
4944                                 ushort crashpc = 0;
4945
4946                                 if (card->adapter[0]) {
4947                                         if ((card->adapter[0])->memorylength >=
4948                                             CRASH_INFO_OFFSET +
4949                                             sizeof(slic_crash_info)) {
4950                                                 char *crashptr;
4951                                                 p_slic_crash_info crashinfo;
4952
4953                                                 crashptr =
4954                                                     ((char *)card->adapter[0]->
4955                                                      slic_regs) +
4956                                                     CRASH_INFO_OFFSET;
4957                                                 crashinfo =
4958                                                     (p_slic_crash_info)
4959                                                     crashptr;
4960                                                 cpuid = crashinfo->cpu_id;
4961                                                 crashpc = crashinfo->crash_pc;
4962                                         }
4963                                 }
4964                                 DBG_ERROR
4965                                     ("[slicmon]: Dump card: Card %x crashed "
4966                                      "and failed to answer PING. "
4967                                      "CPUID[%x] PC[%x]\n ",
4968                                      card->cardnum, cpuid, crashpc);
4969                         }
4970
4971                         card->dump_requested = SLIC_DUMP_IN_PROGRESS;
4972
4973                         /*
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).
4978                          */
4979                         card->state = CARD_DOWN;
4980
4981                         for (i = 0; i < card->card_size; i++) {
4982                                 adapter = card->adapter[i];
4983                                 if (adapter) {
4984                                         slic_if_stop_queue(adapter);
4985
4986                                         if (adapter->state == ADAPT_UP) {
4987                                                 adapter->state = ADAPT_RESET;
4988                                                 adapter->linkstate = LINK_DOWN;
4989                                                 DBG_ERROR
4990                                                     ("[slicmon]: SLIC Card[%d] "
4991                                                      "Port[%d] adapter[%p] "
4992                                                      "down\n",
4993                                                      (uint) card->cardnum,
4994                                                      (uint) i, adapter);
4995                                         }
4996 #if SLIC_GET_STATS_TIMER_ENABLED
4997                                         /* free stats timer */
4998                                         if (adapter->statstimerset) {
4999                                                 adapter->statstimerset = 0;
5000                                                 del_timer(&adapter->statstimer);
5001                                         }
5002 #endif
5003                                 }
5004                         }
5005
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;
5011
5012                                         /*
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
5018                                          * not be issued.
5019                                          *
5020                                          * To avoid this we will clear any
5021                                          * pending utility processor requests
5022                                          * now.
5023                                          */
5024                                         if (!card->pingstatus) {
5025                                                 spin_lock_irqsave(
5026                                                     &adapter->upr_lock.lock,
5027                                                     adapter->upr_lock.flags);
5028                                                 upr = adapter->upr_list;
5029                                                 while (upr) {
5030                                                         uprnext = upr->next;
5031                                                         kfree(upr);
5032                                                         upr = uprnext;
5033                                                 }
5034                                                 adapter->upr_list = 0;
5035                                                 adapter->upr_busy = 0;
5036                                                 spin_unlock_irqrestore(
5037                                                     &adapter->upr_lock.lock,
5038                                                     adapter->upr_lock.flags);
5039                                         }
5040
5041                                         slic_dump_card(card, false);
5042                                         dump_complete = 1;
5043                                 }
5044
5045                                 if (dump_complete) {
5046                                         DBG_ERROR("SLIC Dump Complete\n");
5047                                         /*  Only dump the card one time */
5048                                         break;
5049                                 }
5050                         }
5051
5052                         if (dump_adapter) {
5053                                 DBG_ERROR
5054                                     ("slic dump completed. "
5055                                      "Reenable interfaces\n");
5056                                 slic_card_init(card, dump_adapter);
5057
5058                                 /*
5059                                  *  Reenable the adapters that were reset
5060                                  */
5061                                 for (i = 0; i < card->card_size; i++) {
5062                                         adapter = card->adapter[i];
5063                                         if (adapter) {
5064                                                 if (adapter->state ==
5065                                                     ADAPT_RESET) {
5066                                                         DBG_ERROR
5067                                                             ("slicdump: SLIC "
5068                                            "Card[%d] Port[%d] adapter[%p] "
5069                                            "bring UP\n",
5070                                                              (uint) card->
5071                                                              cardnum, (uint) i,
5072                                                              adapter);
5073                                                         adapter->state =
5074                                                             ADAPT_DOWN;
5075                                                         adapter->linkstate =
5076                                                             LINK_DOWN;
5077                                                         slic_entry_open
5078                                                             (adapter->netdev);
5079                                                 }
5080                                         }
5081                                 }
5082
5083                                 card->dump_requested = SLIC_DUMP_DONE;
5084                         }
5085                 } else {
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.
5090                  */
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,
5096                                                          0, 0, 0, 0);
5097                                         break;  /* Only issue one per card */
5098                                 }
5099                         }
5100                 }
5101 wait:
5102                 SLIC_INTERRUPTIBLE_SLEEP_ON_TIMEOUT(card->dump_wq, delay);
5103         } while (!signal_pending(current));
5104
5105 end_thread:
5106 /*  DBG_MSG("[slicmon] slic_dump_thread card[%p] pid[%x] ENDING\n",
5107     card, card->dump_pid); */
5108         card->dumpthread_running = 0;
5109
5110         return 0;
5111 }
5112
5113 /*
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
5117  */
5118 static unsigned char slic_get_dump_index(char *path)
5119 {
5120         unsigned char index = 0;
5121 #ifdef SLIC_DUMP_INDEX_SUPPORT
5122         u32 status;
5123         void *FileHandle;
5124         u32 offset;
5125
5126         offset = 0;
5127
5128         /*
5129          * Open the index file.  If one doesn't exist, create it
5130          */
5131         status = create_file(&FileHandle);
5132
5133         if (status != STATUS_SUCCESS)
5134                 return (unsigned char) 0;
5135
5136         status = read_file(FileHandle, &index, 1, &offset);
5137
5138         index++;
5139
5140         status = write_file(FileHandle, &index, 1, &offset);
5141
5142         close_file(FileHandle);
5143 #else
5144         index = 0;
5145 #endif
5146         return index;
5147 }
5148
5149 static struct file *slic_dump_open_file(struct sliccard *card)
5150 {
5151         struct file *SLIChandle = NULL;
5152         struct dentry *dentry = NULL;
5153         struct inode *inode = NULL;
5154         char SLICfile[50];
5155
5156         card->dumpfile_fs = get_fs();
5157
5158         set_fs(KERNEL_DS);
5159
5160         memset(SLICfile, 0, sizeof(SLICfile));
5161         sprintf(SLICfile, "/var/tmp/slic%d-dump-%d", card->cardnum,
5162                 (uint) card->dump_count);
5163         card->dump_count++;
5164
5165         SLIChandle =
5166             filp_open(SLICfile, O_CREAT | O_RDWR | O_SYNC | O_LARGEFILE, 0666);
5167
5168         DBG_MSG("[slicmon]: Dump Card #%d to file: %s \n", card->cardnum,
5169                 SLICfile);
5170
5171 /*  DBG_MSG("[slicmon] filp_open %s SLIChandle[%p]\n", SLICfile, SLIChandle);*/
5172
5173         if (IS_ERR(SLIChandle))
5174                 goto end_slicdump;
5175
5176         dentry = SLIChandle->f_dentry;
5177         inode = dentry->d_inode;
5178
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 */
5185 #ifdef HISTORICAL
5186         if (!S_ISREG(inode->i_mode))
5187                 goto close_slicdump;
5188 #endif
5189         if (!inode->i_op || !inode->i_fop)
5190                 goto close_slicdump;
5191
5192         if (!SLIChandle->f_op->write)
5193                 goto close_slicdump;
5194
5195         /*
5196          *  If we got here we have SUCCESSFULLY OPENED the dump file
5197          */
5198 /*  DBG_MSG("opened %s SLIChandle[%p]\n", SLICfile, SLIChandle); */
5199         return SLIChandle;
5200
5201 close_slicdump:
5202         DBG_MSG("[slicmon] slic_dump_open_file failed close SLIChandle[%p]\n",
5203                 SLIChandle);
5204         filp_close(SLIChandle, NULL);
5205
5206 end_slicdump:
5207         set_fs(card->dumpfile_fs);
5208
5209         return NULL;
5210 }
5211
5212 static void slic_dump_close_file(struct sliccard *card)
5213 {
5214
5215 /*  DBG_MSG("[slicmon] slic_dump_CLOSE_file close SLIChandle[%p]\n",
5216    card->dumphandle); */
5217
5218         filp_close(card->dumphandle, NULL);
5219
5220         set_fs(card->dumpfile_fs);
5221 }
5222
5223 static u32 slic_dump_card(struct sliccard *card, bool resume)
5224 {
5225         struct adapter *adapter = card->master;
5226         u32 status;
5227         u32 queue;
5228         u32 len, offset;
5229         u32 sram_size, dram_size, regs;
5230         struct sliccore_hdr corehdr;
5231         u32 file_offset;
5232         char *namestr;
5233         u32 i;
5234         u32 max_queues = 0;
5235         u32 result;
5236
5237         card->dumphandle = slic_dump_open_file(card);
5238
5239         if (card->dumphandle == NULL) {
5240                 DBG_MSG("[slicmon] Cant create Dump file - dump failed\n");
5241                 return -ENOMEM;
5242         }
5243         if (!card->dumpbuffer) {
5244                 DBG_MSG("[slicmon] Insufficient memory for dump\n");
5245                 return -ENOMEM;
5246         }
5247         if (!card->cmdbuffer) {
5248                 DBG_MSG("[slicmon] Insufficient cmd memory for dump\n");
5249                 return -ENOMEM;
5250         }
5251
5252         /*
5253          * Write the file version to the core header.
5254          */
5255         namestr = slic_proc_version;
5256         for (i = 0; i < (DRIVER_NAME_SIZE - 1); i++, namestr++) {
5257                 if (!namestr)
5258                         break;
5259                 corehdr.driver_version[i] = *namestr;
5260         }
5261         corehdr.driver_version[i] = 0;
5262
5263         file_offset = sizeof(struct sliccore_hdr);
5264
5265         /*
5266          * Issue the following debug commands to the SLIC:
5267          *        - Halt both receive and transmit
5268          *        - Dump receive registers
5269          *        - Dump transmit registers
5270          *        - Dump sram
5271          *        - Dump dram
5272          *        - Dump queues
5273          */
5274         DBG_MSG("slicDump HALT Receive Processor\n");
5275         card->dumptime_start = jiffies;
5276
5277         status = slic_dump_halt(card, PROC_RECEIVE);
5278         if (status != STATUS_SUCCESS) {
5279                 DBG_ERROR
5280                     ("Cant halt receive sequencer - dump failed status[%x]\n",
5281                      status);
5282                 goto done;
5283         }
5284
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");
5289                 goto done;
5290         }
5291
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");
5296                 goto done;
5297         }
5298
5299         DBG_MSG("slicDump Write Receive REGS len[%x] offset[%x]\n",
5300                 (SLIC_NUM_REG * 4), file_offset);
5301
5302         result =
5303             slic_dump_write(card, card->dumpbuffer, SLIC_NUM_REG * 4,
5304                             file_offset);
5305         if (!result) {
5306                 DBG_ERROR
5307                     ("Cant write rcv registers to dump file - dump failed\n");
5308                 goto done;
5309         }
5310
5311         corehdr.RcvRegOff = file_offset;
5312         corehdr.RcvRegsize = SLIC_NUM_REG * 4;
5313         file_offset += SLIC_NUM_REG * 4;
5314
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");
5319                 goto done;
5320         }
5321
5322         DBG_MSG("slicDump Write XMIT REGS len[%x] offset[%x]\n",
5323                 (SLIC_NUM_REG * 4), file_offset);
5324
5325         result =
5326             slic_dump_write(card, card->dumpbuffer, SLIC_NUM_REG * 4,
5327                             file_offset);
5328         if (!result) {
5329                 DBG_ERROR
5330                     ("Cant write xmt registers to dump file - dump failed\n");
5331                 goto done;
5332         }
5333
5334         corehdr.XmtRegOff = file_offset;
5335         corehdr.XmtRegsize = SLIC_NUM_REG * 4;
5336         file_offset += SLIC_NUM_REG * 4;
5337
5338         regs = SLIC_GBMAX_REG;
5339
5340         corehdr.FileRegOff = file_offset;
5341         corehdr.FileRegsize = regs * 4;
5342
5343         for (offset = 0; regs;) {
5344                 len = MIN(regs, 16);    /* Can only xfr 16 regs at a time */
5345
5346                 status = slic_dump_data(card, offset, (ushort) len, DESC_RFILE);
5347
5348                 if (status != STATUS_SUCCESS) {
5349                         DBG_ERROR("Cant dump register file - dump failed\n");
5350                         goto done;
5351                 }
5352
5353                 DBG_MSG("slicDump Write RegisterFile len[%x] offset[%x]\n",
5354                         (len * 4), file_offset);
5355
5356                 result =
5357                     slic_dump_write(card, card->dumpbuffer, len * 4,
5358                                     file_offset);
5359                 if (!result) {
5360                         DBG_ERROR
5361                             ("Cant write register file to dump file - "
5362                              "dump failed\n");
5363                         goto done;
5364                 }
5365
5366                 file_offset += len * 4;
5367                 offset += len;
5368                 regs -= len;
5369         }
5370
5371         dram_size = card->config.DramSize * 0x10000;
5372
5373         switch (adapter->devid) {
5374         case SLIC_2GB_DEVICE_ID:
5375                 sram_size = SLIC_SRAM_SIZE2GB;
5376                 break;
5377         case SLIC_1GB_DEVICE_ID:
5378                 sram_size = SLIC_SRAM_SIZE1GB;
5379                 break;
5380         default:
5381                 sram_size = 0;
5382                 ASSERT(0);
5383                 break;
5384         }
5385
5386         corehdr.SramOff = file_offset;
5387         corehdr.Sramsize = sram_size;
5388
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) {
5393                         DBG_ERROR
5394                             ("[slicmon] Cant dump SRAM at offset %x - "
5395                              "dump failed\n", (uint) offset);
5396                         goto done;
5397                 }
5398
5399                 DBG_MSG("[slicmon] slicDump Write SRAM  len[%x] offset[%x]\n",
5400                         len, file_offset);
5401
5402                 result =
5403                     slic_dump_write(card, card->dumpbuffer, len, file_offset);
5404                 if (!result) {
5405                         DBG_ERROR
5406                             ("[slicmon] Cant write SRAM to dump file - "
5407                              "dump failed\n");
5408                         goto done;
5409                 }
5410
5411                 file_offset += len;
5412                 offset += len;
5413                 sram_size -= len;
5414         }
5415
5416         corehdr.DramOff = file_offset;
5417         corehdr.Dramsize = dram_size;
5418
5419         for (offset = 0; dram_size;) {
5420                 len = MIN(dram_size, DUMP_BUF_SIZE);
5421
5422                 status = slic_dump_data(card, offset, (ushort) len, DESC_DRAM);
5423                 if (status != STATUS_SUCCESS) {
5424                         DBG_ERROR
5425                             ("[slicmon] Cant dump dram at offset %x - "
5426                              "dump failed\n", (uint) offset);
5427                         goto done;
5428                 }
5429
5430                 DBG_MSG("slicDump Write DRAM  len[%x] offset[%x]\n", len,
5431                         file_offset);
5432
5433                 result =
5434                     slic_dump_write(card, card->dumpbuffer, len, file_offset);
5435                 if (!result) {
5436                         DBG_ERROR
5437                             ("[slicmon] Cant write DRAM to dump file - "
5438                              "dump failed\n");
5439                         goto done;
5440                 }
5441
5442                 file_offset += len;
5443                 offset += len;
5444                 dram_size -= len;
5445         }
5446
5447         max_queues = SLIC_MAX_QUEUE;
5448
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;
5453                 u32 qstart;
5454                 u32 qdelta;
5455                 u32 qtotal = 0;
5456
5457                 DBG_MSG("[slicmon] Start Dump of QUEUE #0x%x\n", (uint) queue);
5458
5459                 for (offset = 0; offset < (DUMP_BUF_SIZE >> 2); offset++) {
5460                         qstart = jiffies;
5461                         qdelta = 0;
5462
5463                         status = slic_dump_queue(card,
5464                                                  qarray_physl,
5465                                                  qarray_physh, queue);
5466                         qarray_physl += 4;
5467
5468                         if (status != STATUS_SUCCESS)
5469                                 break;
5470
5471                         if (jiffies > qstart) {
5472                                 qdelta = jiffies - qstart;
5473                                 qtotal += qdelta;
5474                         }
5475                 }
5476
5477                 if (offset)
5478                         qdelta = qtotal / offset;
5479                 else
5480                         qdelta = 0;
5481
5482 /*        DBG_MSG("   slicDump Write QUEUE #0x%x len[%x] offset[%x] "
5483                 "avgjiffs[%x]\n", queue, (offset*4), file_offset, qdelta); */
5484
5485                 result =
5486                     slic_dump_write(card, card->dumpbuffer, offset * 4,
5487                                     file_offset);
5488
5489                 if (!result) {
5490                         DBG_ERROR
5491                             ("[slicmon] Cant write QUEUES to dump file - "
5492                              "dump failed\n");
5493                         goto done;
5494                 }
5495
5496                 corehdr.queues[queue].queueOff = file_offset;
5497                 corehdr.queues[queue].queuesize = offset * 4;
5498                 file_offset += offset * 4;
5499
5500 /*      DBG_MSG("    Reload QUEUE #0x%x elements[%x]\n", (uint)queue, offset);*/
5501                 /*
5502                  * Fill the queue back up
5503                  */
5504                 for (i = 0; i < offset; i++) {
5505                         qstart = jiffies;
5506                         qdelta = 0;
5507
5508                         status = slic_dump_load_queue(card, qarray[i], queue);
5509                         if (status != STATUS_SUCCESS)
5510                                 break;
5511
5512                         if (jiffies > qstart) {
5513                                 qdelta = jiffies - qstart;
5514                                 qtotal += qdelta;
5515                         }
5516                 }
5517
5518                 if (offset)
5519                         qdelta = qtotal / offset;
5520                 else
5521                         qdelta = 0;
5522
5523 /*      DBG_MSG("   Reload DONE avgjiffs[%x]\n", qdelta); */
5524
5525                 resume = 1;
5526         }
5527
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");
5532                 goto done;
5533         }
5534
5535         result = slic_dump_write(card, card->dumpbuffer, len, file_offset);
5536         if (result) {
5537                 DBG_ERROR
5538                     ("[slicmon] Can't write CAM_A data to dump file - "
5539                      "dump failed\n");
5540                 goto done;
5541         }
5542         corehdr.CamAMOff = file_offset;
5543         corehdr.CamASize = len;
5544         file_offset += len;
5545
5546         len = SLIC_GB_CAMCD_SZE * 4;
5547         status = slic_dump_cam(card, 0, len, DUMP_CAM_C);
5548         if (status) {
5549                 DBG_ERROR("[slicmon] Can't dump CAM_C - dump failed\n");
5550                 goto done;
5551         }
5552
5553         result = slic_dump_write(card, card->dumpbuffer, len, file_offset);
5554         if (result) {
5555                 DBG_ERROR
5556                     ("[slicmon] Can't write CAM_C data to dump file - "
5557                      "dump failed\n");
5558                 goto done;
5559         }
5560         corehdr.CamCMOff = file_offset;
5561         corehdr.CamCSize = len;
5562         file_offset += len;
5563
5564 done:
5565         /*
5566          * Write out the core header
5567          */
5568         file_offset = 0;
5569         DBG_MSG("[slicmon] Write CoreHeader len[%x] offset[%x]\n",
5570                 (uint) sizeof(struct sliccore_hdr), file_offset);
5571
5572         result =
5573             slic_dump_write(card, &corehdr, sizeof(struct sliccore_hdr),
5574                             file_offset);
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);
5587
5588         }
5589
5590         slic_dump_close_file(card);
5591
5592         if (resume) {
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);
5596         }
5597
5598         return status;
5599 }
5600
5601 static u32 slic_dump_halt(struct sliccard *card, unsigned char proc)
5602 {
5603         unsigned char *cmd = card->cmdbuffer;
5604
5605         *cmd = COMMAND_BYTE(CMD_HALT, 0, proc);
5606
5607         return slic_dump_send_cmd(card,
5608                                    card->cmdbuffer_physl,
5609                                    card->cmdbuffer_physh, 0, 0);
5610 }
5611
5612 static u32 slic_dump_resume(struct sliccard *card, unsigned char proc)
5613 {
5614         unsigned char *cmd = card->cmdbuffer;
5615
5616         *cmd = COMMAND_BYTE(CMD_RUN, 0, proc);
5617
5618         return slic_dump_send_cmd(card,
5619                                    card->cmdbuffer_physl,
5620                                    card->cmdbuffer_physh, 0, 0);
5621 }
5622
5623 static u32 slic_dump_reg(struct sliccard *card, unsigned char proc)
5624 {
5625         struct dump_cmd *dump = (struct dump_cmd *)card->cmdbuffer;
5626
5627         dump->cmd = COMMAND_BYTE(CMD_DUMP, 0, proc);
5628         dump->desc = DESC_REG;
5629         dump->count = 0;
5630         dump->addr = 0;
5631
5632         return slic_dump_send_cmd(card,
5633                                    card->cmdbuffer_physl,
5634                                    card->cmdbuffer_physh,
5635                                    card->dumpbuffer_physl,
5636                                    card->dumpbuffer_physh);
5637 }
5638
5639 static u32 slic_dump_data(struct sliccard *card,
5640                        u32 addr, ushort count, unsigned char desc)
5641 {
5642         struct dump_cmd *dump = (struct dump_cmd *)card->cmdbuffer;
5643
5644         dump->cmd = COMMAND_BYTE(CMD_DUMP, 0, PROC_RECEIVE);
5645         dump->desc = desc;
5646         dump->count = count;
5647         dump->addr = addr;
5648
5649         return slic_dump_send_cmd(card,
5650                                    card->cmdbuffer_physl,
5651                                    card->cmdbuffer_physh,
5652                                    card->dumpbuffer_physl,
5653                                    card->dumpbuffer_physh);
5654 }
5655
5656 static u32 slic_dump_queue(struct sliccard *card,
5657                         u32 addr, u32 buf_physh, u32 queue)
5658 {
5659         struct dump_cmd *dump = (struct dump_cmd *)card->cmdbuffer;
5660
5661         dump->cmd = COMMAND_BYTE(CMD_DUMP, 0, PROC_RECEIVE);
5662         dump->desc = DESC_QUEUE;
5663         dump->count = 1;
5664         dump->addr = queue;
5665
5666         return slic_dump_send_cmd(card,
5667                                    card->cmdbuffer_physl,
5668                                    card->cmdbuffer_physh,
5669                                    addr, card->dumpbuffer_physh);
5670 }
5671
5672 static u32 slic_dump_load_queue(struct sliccard *card, u32 data,
5673                                 u32 queue)
5674 {
5675         struct dump_cmd *load = (struct dump_cmd *) card->cmdbuffer;
5676
5677         load->cmd = COMMAND_BYTE(CMD_LOAD, 0, PROC_RECEIVE);
5678         load->desc = DESC_QUEUE;
5679         load->count = (ushort) queue;
5680         load->addr = data;
5681
5682         return slic_dump_send_cmd(card,
5683                                    card->cmdbuffer_physl,
5684                                    card->cmdbuffer_physh, 0, 0);
5685 }
5686
5687 static u32 slic_dump_cam(struct sliccard *card,
5688                       u32 addr, u32 count, unsigned char desc)
5689 {
5690         struct dump_cmd *dump = (struct dump_cmd *)card->cmdbuffer;
5691
5692         dump->cmd = COMMAND_BYTE(CMD_CAM_OPS, 0, PROC_NONE);
5693         dump->desc = desc;
5694         dump->count = count;
5695         dump->addr = 0;
5696
5697         return slic_dump_send_cmd(card,
5698                                    card->cmdbuffer_physl,
5699                                    card->cmdbuffer_physh,
5700                                    addr, card->dumpbuffer_physh);
5701 }
5702
5703 static u32 slic_dump_send_cmd(struct sliccard *card,
5704                            u32 cmd_physl,
5705                            u32 cmd_physh,
5706                            u32 buf_physl, u32 buf_physh)
5707 {
5708         ulong timeout = msecs_to_jiffies(500);  /* 500 msec */
5709         u32 attempts = 5;
5710         u32 delay = msecs_to_jiffies(10);       /* 10 msec */
5711         struct adapter *adapter = card->master;
5712
5713         ASSERT(adapter);
5714         do {
5715                 /*
5716                  * Zero the Dumpstatus field of the adapter structure
5717                  */
5718                 card->dumpstatus = 0;
5719                 /*
5720                  * Issue the dump command via a utility processor request.
5721                  *
5722                  * Kludge: We use the Informationbuffer parameter to hold
5723                  * the buffer address
5724                  */
5725                 slic_upr_request(adapter, SLIC_UPR_DUMP, cmd_physl, cmd_physh,
5726                                  buf_physl, buf_physh);
5727
5728                 timeout += jiffies;
5729                 /*
5730                  * Spin until completion or timeout.
5731                  */
5732                 while (!card->dumpstatus) {
5733                         int num_sleeps = 0;
5734
5735                         if (jiffies > timeout) {
5736                                 /*
5737                                  *  Complete the timed-out DUMP UPR request.
5738                                  */
5739                                 slic_upr_request_complete(adapter, 0);
5740                                 DBG_ERROR
5741                                     ("%s: TIMED OUT num_sleeps[%x] "
5742                                      "status[%x]\n",
5743                                      __func__, num_sleeps, STATUS_FAILURE);
5744
5745                                 return STATUS_FAILURE;
5746                         }
5747                         num_sleeps++;
5748                         SLIC_INTERRUPTIBLE_SLEEP_ON_TIMEOUT(card->dump_wq,
5749                                                             delay);
5750                 }
5751
5752                 if (card->dumpstatus & ISR_UPCERR) {
5753                         /*
5754                          * Error (or queue empty)
5755                          */
5756 /*          DBG_ERROR("[slicmon] %s: DUMP_STATUS & ISR_UPCERR status[%x]\n",
5757                 __func__, STATUS_FAILURE); */
5758
5759                         return STATUS_FAILURE;
5760                 } else if (card->dumpstatus & ISR_UPCBSY) {
5761                         /*
5762                          * Retry
5763                          */
5764                         DBG_ERROR("%s: ISR_UPCBUSY attempt[%x]\n", __func__,
5765                                   attempts);
5766
5767                         attempts--;
5768                 } else {
5769                         /*
5770                          * success
5771                          */
5772                         return STATUS_SUCCESS;
5773                 }
5774
5775         } while (attempts);
5776
5777         DBG_ERROR("%s: GAVE UP AFTER SEVERAL ATTEMPTS status[%x]\n",
5778                   __func__, STATUS_FAILURE);
5779
5780         /*
5781          * Gave up after several attempts
5782          */
5783         return STATUS_FAILURE;
5784 }
5785
5786 #endif
5787 /*=============================================================================
5788   =============================================================================
5789   ===                                                                       ===
5790   ===      *** END **** END **** END **** END ***                           ===
5791   ===       SLIC  DUMP  MANAGEMENT        SECTION                           ===
5792   ===                                                                       ===
5793   ===                                                                       ===
5794   ===                                                                       ===
5795   =============================================================================
5796   ============================================================================*/
5797
5798 /******************************************************************************/
5799 /****************   MODULE INITIATION / TERMINATION FUNCTIONS   ***************/
5800 /******************************************************************************/
5801
5802 static struct pci_driver slic_driver = {
5803         .name = DRV_NAME,
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,
5810 #endif
5811 /*    .shutdown   =     slic_shutdown,  MOOK_INVESTIGATE */
5812 };
5813
5814 static int __init slic_module_init(void)
5815 {
5816         struct pci_device_id *pcidev;
5817         int ret;
5818
5819 /*      DBG_MSG("slicoss: %s ENTER cpu %d\n", __func__, smp_processor_id()); */
5820
5821         slic_init_driver();
5822
5823         if (debug >= 0 && slic_debug != debug)
5824                 printk(SLICLEVEL "slicoss: debug level is %d.\n", debug);
5825         if (debug >= 0)
5826                 slic_debug = debug;
5827
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()); */
5831
5832         ret = pci_register_driver(&slic_driver);
5833
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); */
5837
5838         return ret;
5839 }
5840
5841 static void __exit slic_module_cleanup(void)
5842 {
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__); */
5847 }
5848
5849 module_init(slic_module_init);
5850 module_exit(slic_module_cleanup);