Staging: SLICOSS: free resources on entry_probe error path
[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 SLIC_PRODUCTION_BUILD           1
62 #define SLIC_FAILURE_RESET                  1
63 #define DBG                             1
64 #define SLIC_ASSERT_ENABLED                     1
65 #define SLIC_GET_STATS_ENABLED                  1
66 #define SLIC_GET_STATS_TIMER_ENABLED    0
67 #define SLIC_PING_TIMER_ENABLED             1
68 #define SLIC_POWER_MANAGEMENT_ENABLED   0
69 #define SLIC_INTERRUPT_PROCESS_LIMIT    1
70 #define LINUX_FREES_ADAPTER_RESOURCES   1
71 #define SLIC_OFFLOAD_IP_CHECKSUM                1
72 #define STATS_TIMER_INTERVAL                    2
73 #define PING_TIMER_INTERVAL                         1
74
75 #include <linux/kernel.h>
76 #include <linux/string.h>
77 #include <linux/errno.h>
78 #include <linux/ioport.h>
79 #include <linux/slab.h>
80 #include <linux/interrupt.h>
81 #include <linux/timer.h>
82 #include <linux/pci.h>
83 #include <linux/spinlock.h>
84 #include <linux/init.h>
85 #include <linux/bitops.h>
86 #include <linux/io.h>
87 #include <linux/netdevice.h>
88 #include <linux/etherdevice.h>
89 #include <linux/skbuff.h>
90 #include <linux/delay.h>
91 #include <linux/debugfs.h>
92 #include <linux/seq_file.h>
93 #include <linux/kthread.h>
94 #include <linux/module.h>
95 #include <linux/moduleparam.h>
96
97 #include <linux/firmware.h>
98 #include <linux/types.h>
99 #include <linux/dma-mapping.h>
100 #include <linux/mii.h>
101 #include <linux/if_vlan.h>
102 #include <asm/unaligned.h>
103
104 #include <linux/ethtool.h>
105 #define SLIC_ETHTOOL_SUPPORT     1
106
107 #include <linux/uaccess.h>
108 #include "slicinc.h"
109
110 #if SLIC_DUMP_ENABLED
111 #include "slicdump.h"
112 #endif
113
114 #define SLIC_POWER_MANAGEMENT  0
115
116 static uint slic_first_init = 1;
117 static char *slic_banner = "Alacritech SLIC Technology(tm) Server "\
118                 "and Storage Accelerator (Non-Accelerated)\n";
119
120 static char *slic_proc_version = "2.0.351  2006/07/14 12:26:00";
121 static char *slic_product_name = "SLIC Technology(tm) Server "\
122                 "and Storage Accelerator (Non-Accelerated)";
123 static char *slic_vendor = "Alacritech, Inc.";
124
125 static int slic_debug = 1;
126 static int debug = -1;
127 static struct net_device *head_netdevice;
128
129 static struct base_driver slic_global = { {}, 0, 0, 0, 1, NULL, NULL };
130 static int intagg_delay = 100;
131 static u32 dynamic_intagg;
132 static int errormsg;
133 static int goodmsg;
134 static unsigned int rcv_count;
135 static struct dentry *slic_debugfs;
136
137 #define DRV_NAME          "slicoss"
138 #define DRV_VERSION       "2.0.1"
139 #define DRV_AUTHOR        "Alacritech, Inc. Engineering"
140 #define DRV_DESCRIPTION   "Alacritech SLIC Techonology(tm) "\
141                 "Non-Accelerated Driver"
142 #define DRV_COPYRIGHT     "Copyright  2000-2006 Alacritech, Inc. "\
143                 "All rights reserved."
144 #define PFX                DRV_NAME " "
145
146 MODULE_AUTHOR(DRV_AUTHOR);
147 MODULE_DESCRIPTION(DRV_DESCRIPTION);
148 MODULE_LICENSE("Dual BSD/GPL");
149
150 module_param(dynamic_intagg, int, 0);
151 MODULE_PARM_DESC(dynamic_intagg, "Dynamic Interrupt Aggregation Setting");
152 module_param(intagg_delay, int, 0);
153 MODULE_PARM_DESC(intagg_delay, "uSec Interrupt Aggregation Delay");
154
155 static struct pci_device_id slic_pci_tbl[] __devinitdata = {
156         {PCI_VENDOR_ID_ALACRITECH,
157          SLIC_1GB_DEVICE_ID,
158          PCI_ANY_ID, PCI_ANY_ID,},
159         {PCI_VENDOR_ID_ALACRITECH,
160          SLIC_2GB_DEVICE_ID,
161          PCI_ANY_ID, PCI_ANY_ID,},
162         {0,}
163 };
164
165 MODULE_DEVICE_TABLE(pci, slic_pci_tbl);
166
167 #define SLIC_GET_SLIC_HANDLE(_adapter, _pslic_handle)                   \
168 {                                                                       \
169     spin_lock_irqsave(&_adapter->handle_lock.lock,                      \
170                         _adapter->handle_lock.flags);                   \
171     _pslic_handle  =  _adapter->pfree_slic_handles;                     \
172     if (_pslic_handle) {                                                \
173         ASSERT(_pslic_handle->type == SLIC_HANDLE_FREE);                \
174         _adapter->pfree_slic_handles = _pslic_handle->next;             \
175     }                                                                   \
176     spin_unlock_irqrestore(&_adapter->handle_lock.lock,                 \
177                         _adapter->handle_lock.flags);                   \
178 }
179
180 #define SLIC_FREE_SLIC_HANDLE(_adapter, _pslic_handle)                  \
181 {                                                                       \
182     _pslic_handle->type = SLIC_HANDLE_FREE;                             \
183     spin_lock_irqsave(&_adapter->handle_lock.lock,                      \
184                         _adapter->handle_lock.flags);                   \
185     _pslic_handle->next = _adapter->pfree_slic_handles;                 \
186     _adapter->pfree_slic_handles = _pslic_handle;                       \
187     spin_unlock_irqrestore(&_adapter->handle_lock.lock,                 \
188                         _adapter->handle_lock.flags);                   \
189 }
190
191 static void slic_debug_init(void);
192 static void slic_debug_cleanup(void);
193 static void slic_debug_adapter_create(struct adapter *adapter);
194 static void slic_debug_adapter_destroy(struct adapter *adapter);
195 static void slic_debug_card_create(struct sliccard *card);
196 static void slic_debug_card_destroy(struct sliccard *card);
197
198 static inline void slic_reg32_write(void __iomem *reg, u32 value, uint flush)
199 {
200         writel(value, reg);
201         if (flush)
202                 mb();
203 }
204
205 static inline void slic_reg64_write(struct adapter *adapter,
206                                void __iomem *reg,
207                                u32 value,
208                                void __iomem *regh, u32 paddrh, uint flush)
209 {
210         spin_lock_irqsave(&adapter->bit64reglock.lock,
211                                 adapter->bit64reglock.flags);
212         if (paddrh != adapter->curaddrupper) {
213                 adapter->curaddrupper = paddrh;
214                 writel(paddrh, regh);
215         }
216         writel(value, reg);
217         if (flush)
218                 mb();
219         spin_unlock_irqrestore(&adapter->bit64reglock.lock,
220                                 adapter->bit64reglock.flags);
221 }
222
223 static void slic_init_driver(void)
224 {
225         if (slic_first_init) {
226                 DBG_MSG("slicoss: %s slic_first_init set jiffies[%lx]\n",
227                         __func__, jiffies);
228                 slic_first_init = 0;
229                 spin_lock_init(&slic_global.driver_lock.lock);
230                 slic_debug_init();
231         }
232 }
233
234 static void slic_dbg_macaddrs(struct adapter *adapter)
235 {
236         DBG_MSG("  (%s) curr %2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X\n",
237                 adapter->netdev->name, adapter->currmacaddr[0],
238                 adapter->currmacaddr[1], adapter->currmacaddr[2],
239                 adapter->currmacaddr[3], adapter->currmacaddr[4],
240                 adapter->currmacaddr[5]);
241         DBG_MSG("  (%s) mac  %2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X\n",
242                 adapter->netdev->name, adapter->macaddr[0],
243                 adapter->macaddr[1], adapter->macaddr[2],
244                 adapter->macaddr[3], adapter->macaddr[4], adapter->macaddr[5]);
245         return;
246 }
247
248 #ifdef DEBUG_REGISTER_TRACE
249 static void slic_dbg_register_trace(struct adapter *adapter,
250                                         struct sliccard *card)
251 {
252         uint i;
253
254         DBG_ERROR("Dump Register Write Trace: curr_ix == %d\n", card->debug_ix);
255         for (i = 0; i < 32; i++) {
256                 DBG_ERROR("%2d %d %4x %x %x\n",
257                           i, card->reg_type[i], card->reg_offset[i],
258                           card->reg_value[i], card->reg_valueh[i]);
259         }
260 }
261 #endif
262
263 static void slic_init_adapter(struct net_device *netdev,
264                               struct pci_dev *pcidev,
265                               const struct pci_device_id *pci_tbl_entry,
266                               void __iomem *memaddr, int chip_idx)
267 {
268         ushort index;
269         struct slic_handle *pslic_handle;
270         struct adapter *adapter = (struct adapter *)netdev_priv(netdev);
271 /*
272     DBG_MSG("slicoss: %s (%s)\n    netdev [%p]\n    adapter[%p]\n    "
273             "pcidev [%p]\n", __func__, netdev->name, netdev, adapter, pcidev);*/
274 /*      adapter->pcidev = pcidev;*/
275         adapter->vendid = pci_tbl_entry->vendor;
276         adapter->devid = pci_tbl_entry->device;
277         adapter->subsysid = pci_tbl_entry->subdevice;
278         adapter->busnumber = pcidev->bus->number;
279         adapter->slotnumber = ((pcidev->devfn >> 3) & 0x1F);
280         adapter->functionnumber = (pcidev->devfn & 0x7);
281         adapter->memorylength = pci_resource_len(pcidev, 0);
282         adapter->slic_regs = (__iomem struct slic_regs *)memaddr;
283         adapter->irq = pcidev->irq;
284 /*      adapter->netdev = netdev;*/
285         adapter->next_netdevice = head_netdevice;
286         head_netdevice = netdev;
287         adapter->chipid = chip_idx;
288         adapter->port = 0;      /*adapter->functionnumber;*/
289         adapter->cardindex = adapter->port;
290         adapter->memorybase = memaddr;
291         spin_lock_init(&adapter->upr_lock.lock);
292         spin_lock_init(&adapter->bit64reglock.lock);
293         spin_lock_init(&adapter->adapter_lock.lock);
294         spin_lock_init(&adapter->reset_lock.lock);
295         spin_lock_init(&adapter->handle_lock.lock);
296
297         adapter->card_size = 1;
298         /*
299           Initialize slic_handle array
300         */
301         ASSERT(SLIC_CMDQ_MAXCMDS <= 0xFFFF);
302         /*
303          Start with 1.  0 is an invalid host handle.
304         */
305         for (index = 1, pslic_handle = &adapter->slic_handles[1];
306              index < SLIC_CMDQ_MAXCMDS; index++, pslic_handle++) {
307
308                 pslic_handle->token.handle_index = index;
309                 pslic_handle->type = SLIC_HANDLE_FREE;
310                 pslic_handle->next = adapter->pfree_slic_handles;
311                 adapter->pfree_slic_handles = pslic_handle;
312         }
313 /*
314     DBG_MSG(".........\nix[%d] phandle[%p] pfree[%p] next[%p]\n",
315         index, pslic_handle, adapter->pfree_slic_handles, pslic_handle->next);*/
316         adapter->pshmem = (struct slic_shmem *)
317                                         pci_alloc_consistent(adapter->pcidev,
318                                         sizeof(struct slic_shmem),
319                                         &adapter->
320                                         phys_shmem);
321 /*
322       DBG_MSG("slicoss: %s (%s)\n   pshmem    [%p]\n   phys_shmem[%p]\n"\
323                 "slic_regs [%p]\n", __func__, netdev->name, adapter->pshmem,
324                 (void *)adapter->phys_shmem, adapter->slic_regs);
325 */
326         ASSERT(adapter->pshmem);
327
328         memset(adapter->pshmem, 0, sizeof(struct slic_shmem));
329
330         return;
331 }
332
333 static int __devinit slic_entry_probe(struct pci_dev *pcidev,
334                                const struct pci_device_id *pci_tbl_entry)
335 {
336         static int cards_found;
337         static int did_version;
338         int err = -ENODEV;
339         struct net_device *netdev;
340         struct adapter *adapter;
341         void __iomem *memmapped_ioaddr = NULL;
342         u32 status = 0;
343         ulong mmio_start = 0;
344         ulong mmio_len = 0;
345         struct sliccard *card = NULL;
346
347         DBG_MSG("slicoss: %s 2.6 VERSION ENTER jiffies[%lx] cpu %d\n",
348                 __func__, jiffies, smp_processor_id());
349
350         slic_global.dynamic_intagg = dynamic_intagg;
351
352         err = pci_enable_device(pcidev);
353
354         DBG_MSG("Call pci_enable_device(%p)  status[%x]\n", pcidev, err);
355         if (err)
356                 return err;
357
358         if (slic_debug > 0 && did_version++ == 0) {
359                 printk(slic_banner);
360                 printk(slic_proc_version);
361         }
362
363         err = pci_set_dma_mask(pcidev, DMA_64BIT_MASK);
364         if (!err) {
365                 DBG_MSG("pci_set_dma_mask(DMA_64BIT_MASK) successful\n");
366         } else {
367                 err = pci_set_dma_mask(pcidev, DMA_32BIT_MASK);
368                 if (err) {
369                         DBG_MSG
370                             ("No usable DMA configuration, aborting  err[%x]\n",
371                              err);
372                         goto err_out_disable_pci;
373                 }
374                 DBG_MSG("pci_set_dma_mask(DMA_32BIT_MASK) successful\n");
375         }
376
377         DBG_MSG("Call pci_request_regions\n");
378
379         err = pci_request_regions(pcidev, DRV_NAME);
380         if (err) {
381                 DBG_MSG("pci_request_regions FAILED err[%x]\n", err);
382                 goto err_out_disable_pci;
383         }
384
385         DBG_MSG("call pci_set_master\n");
386         pci_set_master(pcidev);
387
388         DBG_MSG("call alloc_etherdev\n");
389         netdev = alloc_etherdev(sizeof(struct adapter));
390         if (!netdev) {
391                 err = -ENOMEM;
392                 goto err_out_exit_slic_probe;
393         }
394         DBG_MSG("alloc_etherdev for slic netdev[%p]\n", netdev);
395
396         SET_NETDEV_DEV(netdev, &pcidev->dev);
397
398         pci_set_drvdata(pcidev, netdev);
399         adapter = netdev_priv(netdev);
400         adapter->netdev = netdev;
401         adapter->pcidev = pcidev;
402
403         mmio_start = pci_resource_start(pcidev, 0);
404         mmio_len = pci_resource_len(pcidev, 0);
405
406         DBG_MSG("slicoss: call ioremap(mmio_start[%lx], mmio_len[%lx])\n",
407                 mmio_start, mmio_len);
408
409 /*  memmapped_ioaddr =  (u32)ioremap_nocache(mmio_start, mmio_len);*/
410         memmapped_ioaddr = ioremap(mmio_start, mmio_len);
411         DBG_MSG("slicoss: %s MEMMAPPED_IOADDR [%p]\n", __func__,
412                 memmapped_ioaddr);
413         if (!memmapped_ioaddr) {
414                 DBG_ERROR("%s cannot remap MMIO region %lx @ %lx\n",
415                           __func__, mmio_len, mmio_start);
416                 goto err_out_free_netdev;
417         }
418
419         DBG_MSG
420             ("slicoss: %s found Alacritech SLICOSS PCI, MMIO at %p, "\
421             "start[%lx] len[%lx], IRQ %d.\n",
422              __func__, memmapped_ioaddr, mmio_start, mmio_len, pcidev->irq);
423
424         slic_config_pci(pcidev);
425
426         slic_init_driver();
427
428         slic_init_adapter(netdev,
429                           pcidev, pci_tbl_entry, memmapped_ioaddr, cards_found);
430
431         status = slic_card_locate(adapter);
432         if (status) {
433                 DBG_ERROR("%s cannot locate card\n", __func__);
434                 goto err_out_free_mmio_region;
435         }
436
437         card = adapter->card;
438
439         if (!adapter->allocated) {
440                 card->adapters_allocated++;
441                 adapter->allocated = 1;
442         }
443
444         DBG_MSG("slicoss: %s    card:             %p\n", __func__,
445                 adapter->card);
446         DBG_MSG("slicoss: %s    card->adapter[%d] == [%p]\n", __func__,
447                 (uint) adapter->port, adapter);
448         DBG_MSG("slicoss: %s    card->adapters_allocated [%d]\n", __func__,
449                 card->adapters_allocated);
450         DBG_MSG("slicoss: %s    card->adapters_activated [%d]\n", __func__,
451                 card->adapters_activated);
452
453         status = slic_card_init(card, adapter);
454
455         if (status != STATUS_SUCCESS) {
456                 card->state = CARD_FAIL;
457                 adapter->state = ADAPT_FAIL;
458                 adapter->linkstate = LINK_DOWN;
459                 DBG_ERROR("slic_card_init FAILED status[%x]\n", status);
460         } else {
461                 slic_adapter_set_hwaddr(adapter);
462         }
463
464         netdev->base_addr = (unsigned long)adapter->memorybase;
465         netdev->irq = adapter->irq;
466         netdev->open = slic_entry_open;
467         netdev->stop = slic_entry_halt;
468         netdev->hard_start_xmit = slic_xmit_start;
469         netdev->do_ioctl = slic_ioctl;
470         netdev->set_mac_address = slic_mac_set_address;
471 #if SLIC_GET_STATS_ENABLED
472         netdev->get_stats = slic_get_stats;
473 #endif
474         netdev->set_multicast_list = slic_mcast_set_list;
475
476         slic_debug_adapter_create(adapter);
477
478         strcpy(netdev->name, "eth%d");
479         err = register_netdev(netdev);
480         if (err) {
481                 DBG_ERROR("Cannot register net device, aborting.\n");
482                 goto err_out_unmap;
483         }
484
485         DBG_MSG
486             ("slicoss: addr 0x%lx, irq %d, MAC addr "\
487              "%02X:%02X:%02X:%02X:%02X:%02X\n",
488              mmio_start, /*pci_resource_start(pcidev, 0), */ pcidev->irq,
489              netdev->dev_addr[0], netdev->dev_addr[1], netdev->dev_addr[2],
490              netdev->dev_addr[3], netdev->dev_addr[4], netdev->dev_addr[5]);
491
492         cards_found++;
493         DBG_MSG("slicoss: %s EXIT status[%x] jiffies[%lx] cpu %d\n",
494                 __func__, status, jiffies, smp_processor_id());
495
496         return status;
497
498 err_out_unmap:
499         iounmap(memmapped_ioaddr);
500 err_out_free_mmio_region:
501         release_mem_region(mmio_start, mmio_len);
502 err_out_free_netdev:
503         free_netdev(netdev);
504 err_out_exit_slic_probe:
505         pci_release_regions(pcidev);
506         DBG_ERROR("%s EXIT jiffies[%lx] cpu %d\n", __func__, jiffies,
507                   smp_processor_id());
508 err_out_disable_pci:
509         pci_disable_device(pcidev);
510         return err;
511 }
512
513 static int slic_entry_open(struct net_device *dev)
514 {
515         struct adapter *adapter = (struct adapter *) netdev_priv(dev);
516         struct sliccard *card = adapter->card;
517         u32 locked = 0;
518         int status;
519
520         ASSERT(adapter);
521         ASSERT(card);
522         DBG_MSG
523             ("slicoss: %s adapter->activated[%d] card->adapters[%x] "\
524              "allocd[%x]\n", __func__, adapter->activated,
525              card->adapters_activated,
526              card->adapters_allocated);
527         DBG_MSG
528             ("slicoss: %s (%s): [jiffies[%lx] cpu %d] dev[%p] adapt[%p] "\
529              "port[%d] card[%p]\n",
530              __func__, adapter->netdev->name, jiffies, smp_processor_id(),
531              adapter->netdev, adapter, adapter->port, card);
532
533         netif_stop_queue(adapter->netdev);
534
535         spin_lock_irqsave(&slic_global.driver_lock.lock,
536                                 slic_global.driver_lock.flags);
537         locked = 1;
538         if (!adapter->activated) {
539                 card->adapters_activated++;
540                 slic_global.num_slic_ports_active++;
541                 adapter->activated = 1;
542         }
543         status = slic_if_init(adapter);
544
545         if (status != STATUS_SUCCESS) {
546                 if (adapter->activated) {
547                         card->adapters_activated--;
548                         slic_global.num_slic_ports_active--;
549                         adapter->activated = 0;
550                 }
551                 if (locked) {
552                         spin_unlock_irqrestore(&slic_global.driver_lock.lock,
553                                                 slic_global.driver_lock.flags);
554                         locked = 0;
555                 }
556                 return status;
557         }
558         DBG_MSG("slicoss: %s set card->master[%p] adapter[%p]\n", __func__,
559                 card->master, adapter);
560         if (!card->master)
561                 card->master = adapter;
562 #if SLIC_DUMP_ENABLED
563         if (!(card->dumpthread_running))
564                 init_waitqueue_head(&card->dump_wq);
565 #endif
566
567         if (locked) {
568                 spin_unlock_irqrestore(&slic_global.driver_lock.lock,
569                                         slic_global.driver_lock.flags);
570                 locked = 0;
571         }
572 #if SLIC_DUMP_ENABLED
573         if (!(card->dumpthread_running)) {
574                 DBG_MSG("attempt to initialize dump thread\n");
575                 status = slic_init_dump_thread(card);
576                 /*
577                 Even if the dump thread fails, we will continue at this point
578                 */
579         }
580 #endif
581
582         return STATUS_SUCCESS;
583 }
584
585 static void __devexit slic_entry_remove(struct pci_dev *pcidev)
586 {
587         struct net_device *dev = pci_get_drvdata(pcidev);
588         u32 mmio_start = 0;
589         uint mmio_len = 0;
590         struct adapter *adapter = (struct adapter *) netdev_priv(dev);
591         struct sliccard *card;
592         struct mcast_address *mcaddr, *mlist;
593
594         ASSERT(adapter);
595         DBG_MSG("slicoss: %s ENTER dev[%p] adapter[%p]\n", __func__, dev,
596                 adapter);
597         slic_adapter_freeresources(adapter);
598         slic_unmap_mmio_space(adapter);
599         DBG_MSG("slicoss: %s unregister_netdev\n", __func__);
600         unregister_netdev(dev);
601
602         mmio_start = pci_resource_start(pcidev, 0);
603         mmio_len = pci_resource_len(pcidev, 0);
604
605         DBG_MSG("slicoss: %s rel_region(0) start[%x] len[%x]\n", __func__,
606                 mmio_start, mmio_len);
607         release_mem_region(mmio_start, mmio_len);
608
609         DBG_MSG("slicoss: %s iounmap dev->base_addr[%x]\n", __func__,
610                 (uint) dev->base_addr);
611         iounmap((void __iomem *)dev->base_addr);
612         /* free multicast addresses */
613         mlist = adapter->mcastaddrs;
614         while (mlist) {
615                 mcaddr = mlist;
616                 mlist = mlist->next;
617                 kfree(mcaddr);
618         }
619         ASSERT(adapter->card);
620         card = adapter->card;
621         ASSERT(card->adapters_allocated);
622         card->adapters_allocated--;
623         adapter->allocated = 0;
624         DBG_MSG
625             ("slicoss: %s init[%x] alloc[%x] card[%p] adapter[%p]\n",
626              __func__, card->adapters_activated, card->adapters_allocated,
627              card, adapter);
628         if (!card->adapters_allocated) {
629                 struct sliccard *curr_card = slic_global.slic_card;
630                 if (curr_card == card) {
631                         slic_global.slic_card = card->next;
632                 } else {
633                         while (curr_card->next != card)
634                                 curr_card = curr_card->next;
635                         ASSERT(curr_card);
636                         curr_card->next = card->next;
637                 }
638                 ASSERT(slic_global.num_slic_cards);
639                 slic_global.num_slic_cards--;
640                 slic_card_cleanup(card);
641         }
642         DBG_MSG("slicoss: %s deallocate device\n", __func__);
643         kfree(dev);
644         pci_release_regions(pcidev);
645         DBG_MSG("slicoss: %s EXIT\n", __func__);
646 }
647
648 static int slic_entry_halt(struct net_device *dev)
649 {
650         struct adapter *adapter = (struct adapter *)netdev_priv(dev);
651         struct sliccard *card = adapter->card;
652         __iomem struct slic_regs *slic_regs = adapter->slic_regs;
653
654         spin_lock_irqsave(&slic_global.driver_lock.lock,
655                                 slic_global.driver_lock.flags);
656         ASSERT(card);
657         DBG_MSG("slicoss: %s (%s) ENTER\n", __func__, dev->name);
658         DBG_MSG("slicoss: %s (%s) actvtd[%d] alloc[%d] state[%x] adapt[%p]\n",
659                 __func__, dev->name, card->adapters_activated,
660                 card->adapters_allocated, card->state, adapter);
661         slic_if_stop_queue(adapter);
662         adapter->state = ADAPT_DOWN;
663         adapter->linkstate = LINK_DOWN;
664         adapter->upr_list = NULL;
665         adapter->upr_busy = 0;
666         adapter->devflags_prev = 0;
667         DBG_MSG("slicoss: %s (%s) set adapter[%p] state to ADAPT_DOWN(%d)\n",
668                 __func__, dev->name, adapter, adapter->state);
669         ASSERT(card->adapter[adapter->cardindex] == adapter);
670         WRITE_REG(slic_regs->slic_icr, ICR_INT_OFF, FLUSH);
671         adapter->all_reg_writes++;
672         adapter->icr_reg_writes++;
673         slic_config_clear(adapter);
674         DBG_MSG("slicoss: %s (%s) dev[%p] adapt[%p] card[%p]\n",
675                 __func__, dev->name, dev, adapter, card);
676         if (adapter->activated) {
677                 card->adapters_activated--;
678                 slic_global.num_slic_ports_active--;
679                 adapter->activated = 0;
680         }
681 #ifdef AUTOMATIC_RESET
682         WRITE_REG(slic_regs->slic_reset_iface, 0, FLUSH);
683 #endif
684         /*
685          *  Reset the adapter's rsp, cmd, and rcv queues
686          */
687         slic_cmdq_reset(adapter);
688         slic_rspqueue_reset(adapter);
689         slic_rcvqueue_reset(adapter);
690
691 #ifdef AUTOMATIC_RESET
692         if (!card->adapters_activated) {
693
694 #if SLIC_DUMP_ENABLED
695                 if (card->dumpthread_running) {
696                         uint status;
697                         DBG_MSG("attempt to terminate dump thread pid[%x]\n",
698                                 card->dump_task_id);
699                         status = kill_proc(card->dump_task_id->pid, SIGKILL, 1);
700
701                         if (!status) {
702                                 int count = 10 * 100;
703                                 while (card->dumpthread_running && --count) {
704                                         current->state = TASK_INTERRUPTIBLE;
705                                         schedule_timeout(1);
706                                 }
707
708                                 if (!count) {
709                                         DBG_MSG
710                                             ("slicmon thread cleanup FAILED \
711                                              pid[%x]\n",
712                                              card->dump_task_id->pid);
713                                 }
714                         }
715                 }
716 #endif
717                 DBG_MSG("slicoss: %s (%s) initiate CARD_HALT\n", __func__,
718                         dev->name);
719
720                 slic_card_init(card, adapter);
721         }
722 #endif
723
724         DBG_MSG("slicoss: %s (%s) EXIT\n", __func__, dev->name);
725         DBG_MSG("slicoss: %s EXIT\n", __func__);
726         spin_unlock_irqrestore(&slic_global.driver_lock.lock,
727                                 slic_global.driver_lock.flags);
728         return STATUS_SUCCESS;
729 }
730
731 static int slic_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
732 {
733         ASSERT(rq);
734 /*
735       DBG_MSG("slicoss: %s cmd[%x] rq[%p] dev[%p]\n", __func__, cmd, rq, dev);
736 */
737         switch (cmd) {
738         case SIOCSLICSETINTAGG:
739                 {
740                         struct adapter *adapter = (struct adapter *)
741                                                         netdev_priv(dev);
742                         u32 data[7];
743                         u32 intagg;
744
745                         if (copy_from_user(data, rq->ifr_data, 28)) {
746                                 DBG_ERROR
747                                     ("copy_from_user FAILED getting initial \
748                                      params\n");
749                                 return -EFAULT;
750                         }
751                         intagg = data[0];
752                         printk(KERN_EMERG
753                                "%s: set interrupt aggregation to %d\n",
754                                __func__, intagg);
755                         slic_intagg_set(adapter, intagg);
756                         return 0;
757                 }
758 #ifdef SLIC_USER_REQUEST_DUMP_ENABLED
759         case SIOCSLICDUMPCARD:
760                 {
761                         struct adapter *adapter = netdev_priv(dev);
762                         struct sliccard *card;
763
764                         ASSERT(adapter);
765                         ASSERT(adapter->card)
766                         card = adapter->card;
767
768                         DBG_IOCTL("slic_ioctl  SIOCSLIC_DUMP_CARD\n");
769
770                         if (card->dump_requested == SLIC_DUMP_DONE) {
771                                 printk(SLICLEVEL
772                                        "SLIC Card dump to be overwritten\n");
773                                 card->dump_requested = SLIC_DUMP_REQUESTED;
774                         } else if ((card->dump_requested == SLIC_DUMP_REQUESTED)
775                                    || (card->dump_requested ==
776                                        SLIC_DUMP_IN_PROGRESS)) {
777                                 printk(SLICLEVEL
778                                        "SLIC Card dump Requested but already \
779                                         in progress... ignore\n");
780                         } else {
781                                 printk(SLICLEVEL
782                                        "SLIC Card #%d Dump Requested\n",
783                                        card->cardnum);
784                                 card->dump_requested = SLIC_DUMP_REQUESTED;
785                         }
786                         return 0;
787                 }
788 #endif
789
790 #ifdef SLIC_TRACE_DUMP_ENABLED
791         case SIOCSLICTRACEDUMP:
792                 {
793                         ulong data[7];
794                         ulong value;
795
796                         DBG_IOCTL("slic_ioctl  SIOCSLIC_TRACE_DUMP\n");
797
798                         if (copy_from_user(data, rq->ifr_data, 28)) {
799                                 PRINT_ERROR
800                                     ("slic: copy_from_user FAILED getting \
801                                      initial simba param\n");
802                                 return -EFAULT;
803                         }
804
805                         value = data[0];
806                         if (tracemon_request == SLIC_DUMP_DONE) {
807                                 PRINT_ERROR
808                                     ("ATK Diagnostic Trace Dump Requested\n");
809                                 tracemon_request = SLIC_DUMP_REQUESTED;
810                                 tracemon_request_type = value;
811                                 tracemon_timestamp = jiffies;
812                         } else if ((tracemon_request == SLIC_DUMP_REQUESTED) ||
813                                    (tracemon_request ==
814                                     SLIC_DUMP_IN_PROGRESS)) {
815                                 PRINT_ERROR
816                                     ("ATK Diagnostic Trace Dump Requested but \
817                                      already in progress... ignore\n");
818                         } else {
819                                 PRINT_ERROR
820                                     ("ATK Diagnostic Trace Dump Requested\n");
821                                 tracemon_request = SLIC_DUMP_REQUESTED;
822                                 tracemon_request_type = value;
823                                 tracemon_timestamp = jiffies;
824                         }
825                         return 0;
826                 }
827 #endif
828 #if SLIC_ETHTOOL_SUPPORT
829         case SIOCETHTOOL:
830                 {
831                         struct adapter *adapter = (struct adapter *)
832                                                         netdev_priv(dev);
833                         struct ethtool_cmd data;
834                         struct ethtool_cmd ecmd;
835
836                         ASSERT(adapter);
837 /*                      DBG_MSG("slicoss: %s SIOCETHTOOL\n", __func__); */
838                         if (copy_from_user(&ecmd, rq->ifr_data, sizeof(ecmd)))
839                                 return -EFAULT;
840
841                         if (ecmd.cmd == ETHTOOL_GSET) {
842                                 data.supported =
843                                     (SUPPORTED_10baseT_Half |
844                                      SUPPORTED_10baseT_Full |
845                                      SUPPORTED_100baseT_Half |
846                                      SUPPORTED_100baseT_Full |
847                                      SUPPORTED_Autoneg | SUPPORTED_MII);
848                                 data.port = PORT_MII;
849                                 data.transceiver = XCVR_INTERNAL;
850                                 data.phy_address = 0;
851                                 if (adapter->linkspeed == LINK_100MB)
852                                         data.speed = SPEED_100;
853                                 else if (adapter->linkspeed == LINK_10MB)
854                                         data.speed = SPEED_10;
855                                 else
856                                         data.speed = 0;
857
858                                 if (adapter->linkduplex == LINK_FULLD)
859                                         data.duplex = DUPLEX_FULL;
860                                 else
861                                         data.duplex = DUPLEX_HALF;
862
863                                 data.autoneg = AUTONEG_ENABLE;
864                                 data.maxtxpkt = 1;
865                                 data.maxrxpkt = 1;
866                                 if (copy_to_user
867                                     (rq->ifr_data, &data, sizeof(data)))
868                                         return -EFAULT;
869
870                         } else if (ecmd.cmd == ETHTOOL_SSET) {
871                                 if (!capable(CAP_NET_ADMIN))
872                                         return -EPERM;
873
874                                 if (adapter->linkspeed == LINK_100MB)
875                                         data.speed = SPEED_100;
876                                 else if (adapter->linkspeed == LINK_10MB)
877                                         data.speed = SPEED_10;
878                                 else
879                                         data.speed = 0;
880
881                                 if (adapter->linkduplex == LINK_FULLD)
882                                         data.duplex = DUPLEX_FULL;
883                                 else
884                                         data.duplex = DUPLEX_HALF;
885
886                                 data.autoneg = AUTONEG_ENABLE;
887                                 data.maxtxpkt = 1;
888                                 data.maxrxpkt = 1;
889                                 if ((ecmd.speed != data.speed) ||
890                                     (ecmd.duplex != data.duplex)) {
891                                         u32 speed;
892                                         u32 duplex;
893
894                                         if (ecmd.speed == SPEED_10) {
895                                                 speed = 0;
896                                                 SLIC_DISPLAY
897                                                     ("%s: slic ETHTOOL set \
898                                                      link speed==10MB",
899                                                      dev->name);
900                                         } else {
901                                                 speed = PCR_SPEED_100;
902                                                 SLIC_DISPLAY
903                                                     ("%s: slic ETHTOOL set \
904                                                     link speed==100MB",
905                                                      dev->name);
906                                         }
907                                         if (ecmd.duplex == DUPLEX_FULL) {
908                                                 duplex = PCR_DUPLEX_FULL;
909                                                 SLIC_DISPLAY
910                                                     (": duplex==FULL\n");
911                                         } else {
912                                                 duplex = 0;
913                                                 SLIC_DISPLAY
914                                                     (": duplex==HALF\n");
915                                         }
916                                         slic_link_config(adapter,
917                                                          speed, duplex);
918                                         slic_link_event_handler(adapter);
919                                 }
920                         }
921                         return 0;
922                 }
923 #endif
924         default:
925 /*              DBG_MSG("slicoss: %s UNSUPPORTED[%x]\n", __func__, cmd); */
926                 return -EOPNOTSUPP;
927         }
928 }
929
930 #define  XMIT_FAIL_LINK_STATE               1
931 #define  XMIT_FAIL_ZERO_LENGTH              2
932 #define  XMIT_FAIL_HOSTCMD_FAIL             3
933
934 static void slic_xmit_build_request(struct adapter *adapter,
935                              struct slic_hostcmd *hcmd, struct sk_buff *skb)
936 {
937         struct slic_host64_cmd *ihcmd;
938         ulong phys_addr;
939
940         ihcmd = &hcmd->cmd64;
941
942         ihcmd->flags = (adapter->port << IHFLG_IFSHFT);
943         ihcmd->command = IHCMD_XMT_REQ;
944         ihcmd->u.slic_buffers.totlen = skb->len;
945         phys_addr = pci_map_single(adapter->pcidev, skb->data, skb->len,
946                         PCI_DMA_TODEVICE);
947         ihcmd->u.slic_buffers.bufs[0].paddrl = SLIC_GET_ADDR_LOW(phys_addr);
948         ihcmd->u.slic_buffers.bufs[0].paddrh = SLIC_GET_ADDR_HIGH(phys_addr);
949         ihcmd->u.slic_buffers.bufs[0].length = skb->len;
950 #if defined(CONFIG_X86_64)
951         hcmd->cmdsize = (u32) ((((u64)&ihcmd->u.slic_buffers.bufs[1] -
952                                      (u64) hcmd) + 31) >> 5);
953 #elif defined(CONFIG_X86)
954         hcmd->cmdsize = ((((u32) &ihcmd->u.slic_buffers.bufs[1] -
955                            (u32) hcmd) + 31) >> 5);
956 #else
957         Stop Compilation;
958 #endif
959 }
960
961 #define NORMAL_ETHFRAME     0
962
963 static int slic_xmit_start(struct sk_buff *skb, struct net_device *dev)
964 {
965         struct sliccard *card;
966         struct adapter *adapter = (struct adapter *)netdev_priv(dev);
967         struct slic_hostcmd *hcmd = NULL;
968         u32 status = 0;
969         u32 skbtype = NORMAL_ETHFRAME;
970         void *offloadcmd = NULL;
971
972         card = adapter->card;
973         ASSERT(card);
974 /*
975     DBG_ERROR("xmit_start (%s) ENTER skb[%p] len[%d] linkstate[%x] state[%x]\n",
976         adapter->netdev->name, skb, skb->len, adapter->linkstate,
977          adapter->state);
978 */
979         if ((adapter->linkstate != LINK_UP) ||
980             (adapter->state != ADAPT_UP) || (card->state != CARD_UP)) {
981                 status = XMIT_FAIL_LINK_STATE;
982                 goto xmit_fail;
983
984         } else if (skb->len == 0) {
985                 status = XMIT_FAIL_ZERO_LENGTH;
986                 goto xmit_fail;
987         }
988
989         if (skbtype == NORMAL_ETHFRAME) {
990                 hcmd = slic_cmdq_getfree(adapter);
991                 if (!hcmd) {
992                         adapter->xmitq_full = 1;
993                         status = XMIT_FAIL_HOSTCMD_FAIL;
994                         goto xmit_fail;
995                 }
996                 ASSERT(hcmd->pslic_handle);
997                 ASSERT(hcmd->cmd64.hosthandle ==
998                        hcmd->pslic_handle->token.handle_token);
999                 hcmd->skb = skb;
1000                 hcmd->busy = 1;
1001                 hcmd->type = SLIC_CMD_DUMB;
1002                 if (skbtype == NORMAL_ETHFRAME)
1003                         slic_xmit_build_request(adapter, hcmd, skb);
1004         }
1005         adapter->stats.tx_packets++;
1006         adapter->stats.tx_bytes += skb->len;
1007
1008 #ifdef DEBUG_DUMP
1009         if (adapter->kill_card) {
1010                 struct slic_host64_cmd ihcmd;
1011
1012                 ihcmd = &hcmd->cmd64;
1013
1014                 ihcmd->flags |= 0x40;
1015                 adapter->kill_card = 0; /* only do this once */
1016         }
1017 #endif
1018         if (hcmd->paddrh == 0) {
1019                 WRITE_REG(adapter->slic_regs->slic_cbar,
1020                           (hcmd->paddrl | hcmd->cmdsize), DONT_FLUSH);
1021         } else {
1022                 WRITE_REG64(adapter,
1023                             adapter->slic_regs->slic_cbar64,
1024                             (hcmd->paddrl | hcmd->cmdsize),
1025                             adapter->slic_regs->slic_addr_upper,
1026                             hcmd->paddrh, DONT_FLUSH);
1027         }
1028 xmit_done:
1029         return 0;
1030 xmit_fail:
1031         slic_xmit_fail(adapter, skb, offloadcmd, skbtype, status);
1032         goto xmit_done;
1033 }
1034
1035 static void slic_xmit_fail(struct adapter *adapter,
1036                     struct sk_buff *skb,
1037                     void *cmd, u32 skbtype, u32 status)
1038 {
1039         if (adapter->xmitq_full)
1040                 slic_if_stop_queue(adapter);
1041         if ((cmd == NULL) && (status <= XMIT_FAIL_HOSTCMD_FAIL)) {
1042                 switch (status) {
1043                 case XMIT_FAIL_LINK_STATE:
1044                         DBG_ERROR
1045                             ("(%s) reject xmit skb[%p: %x] linkstate[%s] \
1046                              adapter[%s:%d] card[%s:%d]\n",
1047                              adapter->netdev->name, skb, skb->pkt_type,
1048                              SLIC_LINKSTATE(adapter->linkstate),
1049                              SLIC_ADAPTER_STATE(adapter->state), adapter->state,
1050                              SLIC_CARD_STATE(adapter->card->state),
1051                              adapter->card->state);
1052                         break;
1053                 case XMIT_FAIL_ZERO_LENGTH:
1054                         DBG_ERROR
1055                             ("xmit_start skb->len == 0 skb[%p] type[%x]!!!! \n",
1056                              skb, skb->pkt_type);
1057                         break;
1058                 case XMIT_FAIL_HOSTCMD_FAIL:
1059                         DBG_ERROR
1060                             ("xmit_start skb[%p] type[%x] No host commands \
1061                              available !!!! \n",
1062                              skb, skb->pkt_type);
1063                         break;
1064                 default:
1065                         ASSERT(0);
1066                 }
1067         }
1068         dev_kfree_skb(skb);
1069         adapter->stats.tx_dropped++;
1070 }
1071
1072 static void slic_rcv_handle_error(struct adapter *adapter,
1073                                         struct slic_rcvbuf *rcvbuf)
1074 {
1075         struct slic_hddr_wds *hdr = (struct slic_hddr_wds *)rcvbuf->data;
1076
1077         if (adapter->devid != SLIC_1GB_DEVICE_ID) {
1078                 if (hdr->frame_status14 & VRHSTAT_802OE)
1079                         adapter->if_events.oflow802++;
1080                 if (hdr->frame_status14 & VRHSTAT_TPOFLO)
1081                         adapter->if_events.Tprtoflow++;
1082                 if (hdr->frame_status_b14 & VRHSTATB_802UE)
1083                         adapter->if_events.uflow802++;
1084                 if (hdr->frame_status_b14 & VRHSTATB_RCVE) {
1085                         adapter->if_events.rcvearly++;
1086                         adapter->stats.rx_fifo_errors++;
1087                 }
1088                 if (hdr->frame_status_b14 & VRHSTATB_BUFF) {
1089                         adapter->if_events.Bufov++;
1090                         adapter->stats.rx_over_errors++;
1091                 }
1092                 if (hdr->frame_status_b14 & VRHSTATB_CARRE) {
1093                         adapter->if_events.Carre++;
1094                         adapter->stats.tx_carrier_errors++;
1095                 }
1096                 if (hdr->frame_status_b14 & VRHSTATB_LONGE)
1097                         adapter->if_events.Longe++;
1098                 if (hdr->frame_status_b14 & VRHSTATB_PREA)
1099                         adapter->if_events.Invp++;
1100                 if (hdr->frame_status_b14 & VRHSTATB_CRC) {
1101                         adapter->if_events.Crc++;
1102                         adapter->stats.rx_crc_errors++;
1103                 }
1104                 if (hdr->frame_status_b14 & VRHSTATB_DRBL)
1105                         adapter->if_events.Drbl++;
1106                 if (hdr->frame_status_b14 & VRHSTATB_CODE)
1107                         adapter->if_events.Code++;
1108                 if (hdr->frame_status_b14 & VRHSTATB_TPCSUM)
1109                         adapter->if_events.TpCsum++;
1110                 if (hdr->frame_status_b14 & VRHSTATB_TPHLEN)
1111                         adapter->if_events.TpHlen++;
1112                 if (hdr->frame_status_b14 & VRHSTATB_IPCSUM)
1113                         adapter->if_events.IpCsum++;
1114                 if (hdr->frame_status_b14 & VRHSTATB_IPLERR)
1115                         adapter->if_events.IpLen++;
1116                 if (hdr->frame_status_b14 & VRHSTATB_IPHERR)
1117                         adapter->if_events.IpHlen++;
1118         } else {
1119                 if (hdr->frame_statusGB & VGBSTAT_XPERR) {
1120                         u32 xerr = hdr->frame_statusGB >> VGBSTAT_XERRSHFT;
1121
1122                         if (xerr == VGBSTAT_XCSERR)
1123                                 adapter->if_events.TpCsum++;
1124                         if (xerr == VGBSTAT_XUFLOW)
1125                                 adapter->if_events.Tprtoflow++;
1126                         if (xerr == VGBSTAT_XHLEN)
1127                                 adapter->if_events.TpHlen++;
1128                 }
1129                 if (hdr->frame_statusGB & VGBSTAT_NETERR) {
1130                         u32 nerr =
1131                             (hdr->
1132                              frame_statusGB >> VGBSTAT_NERRSHFT) &
1133                             VGBSTAT_NERRMSK;
1134                         if (nerr == VGBSTAT_NCSERR)
1135                                 adapter->if_events.IpCsum++;
1136                         if (nerr == VGBSTAT_NUFLOW)
1137                                 adapter->if_events.IpLen++;
1138                         if (nerr == VGBSTAT_NHLEN)
1139                                 adapter->if_events.IpHlen++;
1140                 }
1141                 if (hdr->frame_statusGB & VGBSTAT_LNKERR) {
1142                         u32 lerr = hdr->frame_statusGB & VGBSTAT_LERRMSK;
1143
1144                         if (lerr == VGBSTAT_LDEARLY)
1145                                 adapter->if_events.rcvearly++;
1146                         if (lerr == VGBSTAT_LBOFLO)
1147                                 adapter->if_events.Bufov++;
1148                         if (lerr == VGBSTAT_LCODERR)
1149                                 adapter->if_events.Code++;
1150                         if (lerr == VGBSTAT_LDBLNBL)
1151                                 adapter->if_events.Drbl++;
1152                         if (lerr == VGBSTAT_LCRCERR)
1153                                 adapter->if_events.Crc++;
1154                         if (lerr == VGBSTAT_LOFLO)
1155                                 adapter->if_events.oflow802++;
1156                         if (lerr == VGBSTAT_LUFLO)
1157                                 adapter->if_events.uflow802++;
1158                 }
1159         }
1160         return;
1161 }
1162
1163 #define TCP_OFFLOAD_FRAME_PUSHFLAG  0x10000000
1164 #define M_FAST_PATH                 0x0040
1165
1166 static void slic_rcv_handler(struct adapter *adapter)
1167 {
1168         struct sk_buff *skb;
1169         struct slic_rcvbuf *rcvbuf;
1170         u32 frames = 0;
1171
1172         while ((skb = slic_rcvqueue_getnext(adapter))) {
1173                 u32 rx_bytes;
1174
1175                 ASSERT(skb->head);
1176                 rcvbuf = (struct slic_rcvbuf *)skb->head;
1177                 adapter->card->events++;
1178                 if (rcvbuf->status & IRHDDR_ERR) {
1179                         adapter->rx_errors++;
1180                         slic_rcv_handle_error(adapter, rcvbuf);
1181                         slic_rcvqueue_reinsert(adapter, skb);
1182                         continue;
1183                 }
1184
1185                 if (!slic_mac_filter(adapter, (struct ether_header *)
1186                                         rcvbuf->data)) {
1187 #if 0
1188                         DBG_MSG
1189                             ("slicoss: %s (%s) drop frame due to mac filter\n",
1190                              __func__, adapter->netdev->name);
1191 #endif
1192                         slic_rcvqueue_reinsert(adapter, skb);
1193                         continue;
1194                 }
1195                 skb_pull(skb, SLIC_RCVBUF_HEADSIZE);
1196                 rx_bytes = (rcvbuf->length & IRHDDR_FLEN_MSK);
1197                 skb_put(skb, rx_bytes);
1198                 adapter->stats.rx_packets++;
1199                 adapter->stats.rx_bytes += rx_bytes;
1200 #if SLIC_OFFLOAD_IP_CHECKSUM
1201                 skb->ip_summed = CHECKSUM_UNNECESSARY;
1202 #endif
1203
1204                 skb->dev = adapter->netdev;
1205                 skb->protocol = eth_type_trans(skb, skb->dev);
1206                 netif_rx(skb);
1207
1208                 ++frames;
1209 #if SLIC_INTERRUPT_PROCESS_LIMIT
1210                 if (frames >= SLIC_RCVQ_MAX_PROCESS_ISR) {
1211                         adapter->rcv_interrupt_yields++;
1212                         break;
1213                 }
1214 #endif
1215         }
1216         adapter->max_isr_rcvs = max(adapter->max_isr_rcvs, frames);
1217 }
1218
1219 static void slic_xmit_complete(struct adapter *adapter)
1220 {
1221         struct slic_hostcmd *hcmd;
1222         struct slic_rspbuf *rspbuf;
1223         u32 frames = 0;
1224         struct slic_handle_word slic_handle_word;
1225
1226         do {
1227                 rspbuf = slic_rspqueue_getnext(adapter);
1228                 if (!rspbuf)
1229                         break;
1230                 adapter->xmit_completes++;
1231                 adapter->card->events++;
1232                 /*
1233                  Get the complete host command buffer
1234                 */
1235                 slic_handle_word.handle_token = rspbuf->hosthandle;
1236                 ASSERT(slic_handle_word.handle_index);
1237                 ASSERT(slic_handle_word.handle_index <= SLIC_CMDQ_MAXCMDS);
1238                 hcmd =
1239                     (struct slic_hostcmd *)
1240                         adapter->slic_handles[slic_handle_word.handle_index].
1241                                                                         address;
1242 /*      hcmd = (struct slic_hostcmd *) rspbuf->hosthandle; */
1243                 ASSERT(hcmd);
1244                 ASSERT(hcmd->pslic_handle ==
1245                        &adapter->slic_handles[slic_handle_word.handle_index]);
1246 /*
1247       DBG_ERROR("xmit_complete (%s)   hcmd[%p]  hosthandle[%x]\n",
1248                 adapter->netdev->name, hcmd, hcmd->cmd64.hosthandle);
1249       DBG_ERROR("    skb[%p] len %d  hcmdtype[%x]\n", hcmd->skb,
1250                 hcmd->skb->len, hcmd->type);
1251 */
1252                 if (hcmd->type == SLIC_CMD_DUMB) {
1253                         if (hcmd->skb)
1254                                 dev_kfree_skb_irq(hcmd->skb);
1255                         slic_cmdq_putdone_irq(adapter, hcmd);
1256                 }
1257                 rspbuf->status = 0;
1258                 rspbuf->hosthandle = 0;
1259                 frames++;
1260         } while (1);
1261         adapter->max_isr_xmits = max(adapter->max_isr_xmits, frames);
1262 }
1263
1264 static irqreturn_t slic_interrupt(int irq, void *dev_id)
1265 {
1266         struct net_device *dev = (struct net_device *)dev_id;
1267         struct adapter *adapter = (struct adapter *)netdev_priv(dev);
1268         u32 isr;
1269
1270         if ((adapter->pshmem) && (adapter->pshmem->isr)) {
1271                 WRITE_REG(adapter->slic_regs->slic_icr, ICR_INT_MASK, FLUSH);
1272                 isr = adapter->isrcopy = adapter->pshmem->isr;
1273                 adapter->pshmem->isr = 0;
1274                 adapter->num_isrs++;
1275                 switch (adapter->card->state) {
1276                 case CARD_UP:
1277                         if (isr & ~ISR_IO) {
1278                                 if (isr & ISR_ERR) {
1279                                         adapter->error_interrupts++;
1280                                         if (isr & ISR_RMISS) {
1281                                                 int count;
1282                                                 int pre_count;
1283                                                 int errors;
1284
1285                                                 struct slic_rcvqueue *rcvq =
1286                                                     &adapter->rcvqueue;
1287
1288                                                 adapter->
1289                                                     error_rmiss_interrupts++;
1290                                                 if (!rcvq->errors)
1291                                                         rcv_count = rcvq->count;
1292                                                 pre_count = rcvq->count;
1293                                                 errors = rcvq->errors;
1294
1295                                                 while (rcvq->count <
1296                                                        SLIC_RCVQ_FILLTHRESH) {
1297                                                         count =
1298                                                             slic_rcvqueue_fill
1299                                                             (adapter);
1300                                                         if (!count)
1301                                                                 break;
1302                                                 }
1303                                                 DBG_MSG
1304                                                     ("(%s): [%x] ISR_RMISS \
1305                                                      initial[%x] pre[%x] \
1306                                                      errors[%x] \
1307                                                      post_count[%x]\n",
1308                                                      adapter->netdev->name,
1309                                                      isr, rcv_count, pre_count,
1310                                                      errors, rcvq->count);
1311                                         } else if (isr & ISR_XDROP) {
1312                                                 DBG_ERROR
1313                                                     ("isr & ISR_ERR [%x] \
1314                                                      ISR_XDROP \n",
1315                                                      isr);
1316                                         } else {
1317                                                 DBG_ERROR
1318                                                     ("isr & ISR_ERR [%x]\n",
1319                                                      isr);
1320                                         }
1321                                 }
1322
1323                                 if (isr & ISR_LEVENT) {
1324                                         /*DBG_MSG("%s (%s)  ISR_LEVENT \n",
1325                                            __func__, adapter->netdev->name);*/
1326                                         adapter->linkevent_interrupts++;
1327                                         slic_link_event_handler(adapter);
1328                                 }
1329
1330                                 if ((isr & ISR_UPC) ||
1331                                     (isr & ISR_UPCERR) || (isr & ISR_UPCBSY)) {
1332                                         adapter->upr_interrupts++;
1333                                         slic_upr_request_complete(adapter, isr);
1334                                 }
1335                         }
1336
1337                         if (isr & ISR_RCV) {
1338                                 adapter->rcv_interrupts++;
1339                                 slic_rcv_handler(adapter);
1340                         }
1341
1342                         if (isr & ISR_CMD) {
1343                                 adapter->xmit_interrupts++;
1344                                 slic_xmit_complete(adapter);
1345                         }
1346                         break;
1347
1348                 case CARD_DOWN:
1349                         if ((isr & ISR_UPC) ||
1350                             (isr & ISR_UPCERR) || (isr & ISR_UPCBSY)) {
1351                                 adapter->upr_interrupts++;
1352                                 slic_upr_request_complete(adapter, isr);
1353                         }
1354                         break;
1355
1356                 default:
1357                         break;
1358                 }
1359
1360                 adapter->isrcopy = 0;
1361                 adapter->all_reg_writes += 2;
1362                 adapter->isr_reg_writes++;
1363                 WRITE_REG(adapter->slic_regs->slic_isr, 0, FLUSH);
1364         } else {
1365                 adapter->false_interrupts++;
1366         }
1367         return IRQ_HANDLED;
1368 }
1369
1370 /*
1371  * slic_link_event_handler -
1372  *
1373  * Initiate a link configuration sequence.  The link configuration begins
1374  * by issuing a READ_LINK_STATUS command to the Utility Processor on the
1375  * SLIC.  Since the command finishes asynchronously, the slic_upr_comlete
1376  * routine will follow it up witha UP configuration write command, which
1377  * will also complete asynchronously.
1378  *
1379  */
1380 static void slic_link_event_handler(struct adapter *adapter)
1381 {
1382         int status;
1383         struct slic_shmem *pshmem;
1384
1385         if (adapter->state != ADAPT_UP) {
1386                 /* Adapter is not operational.  Ignore.  */
1387                 return;
1388         }
1389
1390         pshmem = (struct slic_shmem *)adapter->phys_shmem;
1391
1392 #if defined(CONFIG_X86_64)
1393 /*
1394     DBG_MSG("slic_event_handler  pshmem->linkstatus[%x]  pshmem[%p]\n   \
1395         &linkstatus[%p] &isr[%p]\n", adapter->pshmem->linkstatus, pshmem,
1396         &pshmem->linkstatus, &pshmem->isr);
1397 */
1398         status = slic_upr_request(adapter,
1399                                   SLIC_UPR_RLSR,
1400                                   SLIC_GET_ADDR_LOW(&pshmem->linkstatus),
1401                                   SLIC_GET_ADDR_HIGH(&pshmem->linkstatus),
1402                                   0, 0);
1403 #elif defined(CONFIG_X86)
1404         status = slic_upr_request(adapter, SLIC_UPR_RLSR,
1405                 (u32) &pshmem->linkstatus,      /* no 4GB wrap guaranteed */
1406                                   0, 0, 0);
1407 #else
1408         Stop compilation;
1409 #endif
1410         ASSERT((status == STATUS_SUCCESS) || (status == STATUS_PENDING));
1411 }
1412
1413 static void slic_init_cleanup(struct adapter *adapter)
1414 {
1415         DBG_MSG("slicoss: %s ENTER adapter[%p] ", __func__, adapter);
1416         if (adapter->intrregistered) {
1417                 DBG_MSG("FREE_IRQ ");
1418                 adapter->intrregistered = 0;
1419                 free_irq(adapter->netdev->irq, adapter->netdev);
1420
1421         }
1422         if (adapter->pshmem) {
1423                 DBG_MSG("FREE_SHMEM ");
1424                 DBG_MSG("adapter[%p] port %d pshmem[%p] FreeShmem ",
1425                         adapter, adapter->port, (void *) adapter->pshmem);
1426                 pci_free_consistent(adapter->pcidev,
1427                                     sizeof(struct slic_shmem),
1428                                     adapter->pshmem, adapter->phys_shmem);
1429                 adapter->pshmem = NULL;
1430                 adapter->phys_shmem = (dma_addr_t) NULL;
1431         }
1432 #if SLIC_GET_STATS_TIMER_ENABLED
1433         if (adapter->statstimerset) {
1434                 DBG_MSG("statstimer ");
1435                 adapter->statstimerset = 0;
1436                 del_timer(&adapter->statstimer);
1437         }
1438 #endif
1439 #if !SLIC_DUMP_ENABLED && SLIC_PING_TIMER_ENABLED
1440 /*#if SLIC_DUMP_ENABLED && SLIC_PING_TIMER_ENABLED*/
1441         if (adapter->pingtimerset) {
1442                 DBG_MSG("pingtimer ");
1443                 adapter->pingtimerset = 0;
1444                 del_timer(&adapter->pingtimer);
1445         }
1446 #endif
1447         slic_rspqueue_free(adapter);
1448         slic_cmdq_free(adapter);
1449         slic_rcvqueue_free(adapter);
1450
1451         DBG_MSG("\n");
1452 }
1453
1454 #if SLIC_GET_STATS_ENABLED
1455 static struct net_device_stats *slic_get_stats(struct net_device *dev)
1456 {
1457         struct adapter *adapter = (struct adapter *)netdev_priv(dev);
1458         struct net_device_stats *stats;
1459
1460         ASSERT(adapter);
1461         stats = &adapter->stats;
1462         stats->collisions = adapter->slic_stats.iface.xmit_collisions;
1463         stats->rx_errors = adapter->slic_stats.iface.rcv_errors;
1464         stats->tx_errors = adapter->slic_stats.iface.xmt_errors;
1465         stats->rx_missed_errors = adapter->slic_stats.iface.rcv_discards;
1466         stats->tx_heartbeat_errors = 0;
1467         stats->tx_aborted_errors = 0;
1468         stats->tx_window_errors = 0;
1469         stats->tx_fifo_errors = 0;
1470         stats->rx_frame_errors = 0;
1471         stats->rx_length_errors = 0;
1472         return &adapter->stats;
1473 }
1474 #endif
1475
1476 /*
1477  *  Allocate a mcast_address structure to hold the multicast address.
1478  *  Link it in.
1479  */
1480 static int slic_mcast_add_list(struct adapter *adapter, char *address)
1481 {
1482         struct mcast_address *mcaddr, *mlist;
1483         bool equaladdr;
1484
1485         /* Check to see if it already exists */
1486         mlist = adapter->mcastaddrs;
1487         while (mlist) {
1488                 ETHER_EQ_ADDR(mlist->address, address, equaladdr);
1489                 if (equaladdr)
1490                         return STATUS_SUCCESS;
1491                 mlist = mlist->next;
1492         }
1493
1494         /* Doesn't already exist.  Allocate a structure to hold it */
1495         mcaddr = kmalloc(sizeof(struct mcast_address), GFP_ATOMIC);
1496         if (mcaddr == NULL)
1497                 return 1;
1498
1499         memcpy(mcaddr->address, address, 6);
1500
1501         mcaddr->next = adapter->mcastaddrs;
1502         adapter->mcastaddrs = mcaddr;
1503
1504         return STATUS_SUCCESS;
1505 }
1506
1507 /*
1508  * Functions to obtain the CRC corresponding to the destination mac address.
1509  * This is a standard ethernet CRC in that it is a 32-bit, reflected CRC using
1510  * the polynomial:
1511  *   x^32 + x^26 + x^23 + x^22 + x^16 + x^12 + x^11 + x^10 + x^8 + x^7 + x^5 +
1512  *   x^4 + x^2 + x^1.
1513  *
1514  * After the CRC for the 6 bytes is generated (but before the value is
1515  * complemented),
1516  * we must then transpose the value and return bits 30-23.
1517  *
1518  */
1519 static u32 slic_crc_table[256]; /* Table of CRCs for all possible byte values */
1520 static u32 slic_crc_init;       /* Is table initialized */
1521
1522 /*
1523  *  Contruct the CRC32 table
1524  */
1525 static void slic_mcast_init_crc32(void)
1526 {
1527         u32 c;          /*  CRC shit reg                 */
1528         u32 e = 0;              /*  Poly X-or pattern            */
1529         int i;                  /*  counter                      */
1530         int k;                  /*  byte being shifted into crc  */
1531
1532         static int p[] = { 0, 1, 2, 4, 5, 7, 8, 10, 11, 12, 16, 22, 23, 26 };
1533
1534         for (i = 0; i < sizeof(p) / sizeof(int); i++)
1535                 e |= 1L << (31 - p[i]);
1536
1537         for (i = 1; i < 256; i++) {
1538                 c = i;
1539                 for (k = 8; k; k--)
1540                         c = c & 1 ? (c >> 1) ^ e : c >> 1;
1541                 slic_crc_table[i] = c;
1542         }
1543 }
1544
1545 /*
1546  *  Return the MAC hast as described above.
1547  */
1548 static unsigned char slic_mcast_get_mac_hash(char *macaddr)
1549 {
1550         u32 crc;
1551         char *p;
1552         int i;
1553         unsigned char machash = 0;
1554
1555         if (!slic_crc_init) {
1556                 slic_mcast_init_crc32();
1557                 slic_crc_init = 1;
1558         }
1559
1560         crc = 0xFFFFFFFF;       /* Preload shift register, per crc-32 spec */
1561         for (i = 0, p = macaddr; i < 6; ++p, ++i)
1562                 crc = (crc >> 8) ^ slic_crc_table[(crc ^ *p) & 0xFF];
1563
1564         /* Return bits 1-8, transposed */
1565         for (i = 1; i < 9; i++)
1566                 machash |= (((crc >> i) & 1) << (8 - i));
1567
1568         return machash;
1569 }
1570
1571 static void slic_mcast_set_bit(struct adapter *adapter, char *address)
1572 {
1573         unsigned char crcpoly;
1574
1575         /* Get the CRC polynomial for the mac address */
1576         crcpoly = slic_mcast_get_mac_hash(address);
1577
1578         /* We only have space on the SLIC for 64 entries.  Lop
1579          * off the top two bits. (2^6 = 64)
1580          */
1581         crcpoly &= 0x3F;
1582
1583         /* OR in the new bit into our 64 bit mask. */
1584         adapter->mcastmask |= (u64) 1 << crcpoly;
1585 }
1586
1587 static void slic_mcast_set_list(struct net_device *dev)
1588 {
1589         struct adapter *adapter = (struct adapter *)netdev_priv(dev);
1590         int status = STATUS_SUCCESS;
1591         int i;
1592         char *addresses;
1593         struct dev_mc_list *mc_list = dev->mc_list;
1594         int mc_count = dev->mc_count;
1595
1596         ASSERT(adapter);
1597
1598         for (i = 1; i <= mc_count; i++) {
1599                 addresses = (char *) &mc_list->dmi_addr;
1600                 if (mc_list->dmi_addrlen == 6) {
1601                         status = slic_mcast_add_list(adapter, addresses);
1602                         if (status != STATUS_SUCCESS)
1603                                 break;
1604                 } else {
1605                         status = -EINVAL;
1606                         break;
1607                 }
1608                 slic_mcast_set_bit(adapter, addresses);
1609                 mc_list = mc_list->next;
1610         }
1611
1612         DBG_MSG("%s a->devflags_prev[%x] dev->flags[%x] status[%x]\n",
1613                 __func__, adapter->devflags_prev, dev->flags, status);
1614         if (adapter->devflags_prev != dev->flags) {
1615                 adapter->macopts = MAC_DIRECTED;
1616                 if (dev->flags) {
1617                         if (dev->flags & IFF_BROADCAST)
1618                                 adapter->macopts |= MAC_BCAST;
1619                         if (dev->flags & IFF_PROMISC)
1620                                 adapter->macopts |= MAC_PROMISC;
1621                         if (dev->flags & IFF_ALLMULTI)
1622                                 adapter->macopts |= MAC_ALLMCAST;
1623                         if (dev->flags & IFF_MULTICAST)
1624                                 adapter->macopts |= MAC_MCAST;
1625                 }
1626                 adapter->devflags_prev = dev->flags;
1627                 DBG_MSG("%s call slic_config_set adapter->macopts[%x]\n",
1628                         __func__, adapter->macopts);
1629                 slic_config_set(adapter, TRUE);
1630         } else {
1631                 if (status == STATUS_SUCCESS)
1632                         slic_mcast_set_mask(adapter);
1633         }
1634         return;
1635 }
1636
1637 static void slic_mcast_set_mask(struct adapter *adapter)
1638 {
1639         __iomem struct slic_regs *slic_regs = adapter->slic_regs;
1640
1641         DBG_MSG("%s ENTER (%s) macopts[%x] mask[%llx]\n", __func__,
1642                 adapter->netdev->name, (uint) adapter->macopts,
1643                 adapter->mcastmask);
1644
1645         if (adapter->macopts & (MAC_ALLMCAST | MAC_PROMISC)) {
1646                 /* Turn on all multicast addresses. We have to do this for
1647                  * promiscuous mode as well as ALLMCAST mode.  It saves the
1648                  * Microcode from having to keep state about the MAC
1649                  * configuration.
1650                  */
1651 /*              DBG_MSG("slicoss: %s macopts = MAC_ALLMCAST | MAC_PROMISC\n\
1652                 SLUT MODE!!!\n",__func__); */
1653                 WRITE_REG(slic_regs->slic_mcastlow, 0xFFFFFFFF, FLUSH);
1654                 WRITE_REG(slic_regs->slic_mcasthigh, 0xFFFFFFFF, FLUSH);
1655 /*        DBG_MSG("%s (%s) WRITE to slic_regs slic_mcastlow&high 0xFFFFFFFF\n",
1656                 _func__, adapter->netdev->name); */
1657         } else {
1658                 /* Commit our multicast mast to the SLIC by writing to the
1659                  * multicast address mask registers
1660                  */
1661                 DBG_MSG("%s (%s) WRITE mcastlow[%x] mcasthigh[%x]\n",
1662                         __func__, adapter->netdev->name,
1663                         ((ulong) (adapter->mcastmask & 0xFFFFFFFF)),
1664                         ((ulong) ((adapter->mcastmask >> 32) & 0xFFFFFFFF)));
1665
1666                 WRITE_REG(slic_regs->slic_mcastlow,
1667                           (u32) (adapter->mcastmask & 0xFFFFFFFF), FLUSH);
1668                 WRITE_REG(slic_regs->slic_mcasthigh,
1669                           (u32) ((adapter->mcastmask >> 32) & 0xFFFFFFFF),
1670                           FLUSH);
1671         }
1672 }
1673
1674 static void slic_timer_ping(ulong dev)
1675 {
1676         struct adapter *adapter;
1677         struct sliccard *card;
1678
1679         ASSERT(dev);
1680         adapter = netdev_priv((struct net_device *)dev);
1681         ASSERT(adapter);
1682         card = adapter->card;
1683         ASSERT(card);
1684 #if !SLIC_DUMP_ENABLED
1685 /*#if SLIC_DUMP_ENABLED*/
1686         if ((adapter->state == ADAPT_UP) && (card->state == CARD_UP)) {
1687                 int status;
1688
1689                 if (card->pingstatus != ISR_PINGMASK) {
1690                         if (errormsg++ < 5) {
1691                                 DBG_MSG
1692                                     ("%s (%s) CARD HAS CRASHED  PING_status == \
1693                                      %x ERRORMSG# %d\n",
1694                                      __func__, adapter->netdev->name,
1695                                      card->pingstatus, errormsg);
1696                         }
1697                         /*   ASSERT(card->pingstatus == ISR_PINGMASK); */
1698                 } else {
1699                         if (goodmsg++ < 5) {
1700                                 DBG_MSG
1701                                     ("slicoss: %s (%s) PING_status == %x \
1702                                      GOOD!!!!!!!! msg# %d\n",
1703                                      __func__, adapter->netdev->name,
1704                                      card->pingstatus, errormsg);
1705                         }
1706                 }
1707                 card->pingstatus = 0;
1708                 status = slic_upr_request(adapter, SLIC_UPR_PING, 0, 0, 0, 0);
1709
1710                 ASSERT(status == 0);
1711         } else {
1712                 DBG_MSG("slicoss %s (%s) adapter[%p] NOT UP!!!!\n",
1713                         __func__, adapter->netdev->name, adapter);
1714         }
1715 #endif
1716         adapter->pingtimer.expires =
1717             jiffies + SLIC_SECS_TO_JIFFS(PING_TIMER_INTERVAL);
1718         add_timer(&adapter->pingtimer);
1719 }
1720
1721 static void slic_if_stop_queue(struct adapter *adapter)
1722 {
1723         netif_stop_queue(adapter->netdev);
1724 }
1725
1726 static void slic_if_start_queue(struct adapter *adapter)
1727 {
1728         netif_start_queue(adapter->netdev);
1729 }
1730
1731 /*
1732  *  slic_if_init
1733  *
1734  *  Perform initialization of our slic interface.
1735  *
1736  */
1737 static int slic_if_init(struct adapter *adapter)
1738 {
1739         struct sliccard *card = adapter->card;
1740         struct net_device *dev = adapter->netdev;
1741         __iomem struct slic_regs *slic_regs = adapter->slic_regs;
1742         struct slic_shmem *pshmem;
1743         int status = 0;
1744
1745         ASSERT(card);
1746         DBG_MSG("slicoss: %s (%s) ENTER states[%d:%d:%d:%d] flags[%x]\n",
1747                 __func__, adapter->netdev->name,
1748                 adapter->queues_initialized, adapter->state, adapter->linkstate,
1749                 card->state, dev->flags);
1750
1751         /* adapter should be down at this point */
1752         if (adapter->state != ADAPT_DOWN) {
1753                 DBG_ERROR("slic_if_init adapter->state != ADAPT_DOWN\n");
1754                 return -EIO;
1755         }
1756         ASSERT(adapter->linkstate == LINK_DOWN);
1757
1758         adapter->devflags_prev = dev->flags;
1759         adapter->macopts = MAC_DIRECTED;
1760         if (dev->flags) {
1761                 DBG_MSG("slicoss: %s (%s) Set MAC options: ", __func__,
1762                         adapter->netdev->name);
1763                 if (dev->flags & IFF_BROADCAST) {
1764                         adapter->macopts |= MAC_BCAST;
1765                         DBG_MSG("BCAST ");
1766                 }
1767                 if (dev->flags & IFF_PROMISC) {
1768                         adapter->macopts |= MAC_PROMISC;
1769                         DBG_MSG("PROMISC ");
1770                 }
1771                 if (dev->flags & IFF_ALLMULTI) {
1772                         adapter->macopts |= MAC_ALLMCAST;
1773                         DBG_MSG("ALL_MCAST ");
1774                 }
1775                 if (dev->flags & IFF_MULTICAST) {
1776                         adapter->macopts |= MAC_MCAST;
1777                         DBG_MSG("MCAST ");
1778                 }
1779                 DBG_MSG("\n");
1780         }
1781         status = slic_adapter_allocresources(adapter);
1782         if (status != STATUS_SUCCESS) {
1783                 DBG_ERROR
1784                     ("slic_if_init: slic_adapter_allocresources FAILED %x\n",
1785                      status);
1786                 slic_adapter_freeresources(adapter);
1787                 return status;
1788         }
1789
1790         if (!adapter->queues_initialized) {
1791                 DBG_MSG("slicoss: %s call slic_rspqueue_init\n", __func__);
1792                 if (slic_rspqueue_init(adapter))
1793                         return -ENOMEM;
1794                 DBG_MSG
1795                     ("slicoss: %s call slic_cmdq_init adapter[%p] port %d \n",
1796                      __func__, adapter, adapter->port);
1797                 if (slic_cmdq_init(adapter))
1798                         return -ENOMEM;
1799                 DBG_MSG
1800                     ("slicoss: %s call slic_rcvqueue_init adapter[%p] \
1801                      port %d \n", __func__, adapter, adapter->port);
1802                 if (slic_rcvqueue_init(adapter))
1803                         return -ENOMEM;
1804                 adapter->queues_initialized = 1;
1805         }
1806         DBG_MSG("slicoss: %s disable interrupts(slic)\n", __func__);
1807
1808         WRITE_REG(slic_regs->slic_icr, ICR_INT_OFF, FLUSH);
1809         mdelay(1);
1810
1811         if (!adapter->isp_initialized) {
1812                 pshmem = (struct slic_shmem *)adapter->phys_shmem;
1813
1814                 spin_lock_irqsave(&adapter->bit64reglock.lock,
1815                                         adapter->bit64reglock.flags);
1816
1817 #if defined(CONFIG_X86_64)
1818                 WRITE_REG(slic_regs->slic_addr_upper,
1819                           SLIC_GET_ADDR_HIGH(&pshmem->isr), DONT_FLUSH);
1820                 WRITE_REG(slic_regs->slic_isp,
1821                           SLIC_GET_ADDR_LOW(&pshmem->isr), FLUSH);
1822 #elif defined(CONFIG_X86)
1823                 WRITE_REG(slic_regs->slic_addr_upper, (u32) 0, DONT_FLUSH);
1824                 WRITE_REG(slic_regs->slic_isp, (u32) &pshmem->isr, FLUSH);
1825 #else
1826                 Stop Compilations
1827 #endif
1828                 spin_unlock_irqrestore(&adapter->bit64reglock.lock,
1829                                         adapter->bit64reglock.flags);
1830                 adapter->isp_initialized = 1;
1831         }
1832
1833         adapter->state = ADAPT_UP;
1834         if (!card->loadtimerset) {
1835                 init_timer(&card->loadtimer);
1836                 card->loadtimer.expires =
1837                     jiffies + SLIC_SECS_TO_JIFFS(SLIC_LOADTIMER_PERIOD);
1838                 card->loadtimer.data = (ulong) card;
1839                 card->loadtimer.function = &slic_timer_load_check;
1840                 add_timer(&card->loadtimer);
1841
1842                 card->loadtimerset = 1;
1843         }
1844 #if SLIC_GET_STATS_TIMER_ENABLED
1845         if (!adapter->statstimerset) {
1846                 DBG_MSG("slicoss: %s start getstats_timer(slic)\n",
1847                         __func__);
1848                 init_timer(&adapter->statstimer);
1849                 adapter->statstimer.expires =
1850                     jiffies + SLIC_SECS_TO_JIFFS(STATS_TIMER_INTERVAL);
1851                 adapter->statstimer.data = (ulong) adapter->netdev;
1852                 adapter->statstimer.function = &slic_timer_get_stats;
1853                 add_timer(&adapter->statstimer);
1854                 adapter->statstimerset = 1;
1855         }
1856 #endif
1857 #if !SLIC_DUMP_ENABLED && SLIC_PING_TIMER_ENABLED
1858 /*#if SLIC_DUMP_ENABLED && SLIC_PING_TIMER_ENABLED*/
1859         if (!adapter->pingtimerset) {
1860                 DBG_MSG("slicoss: %s start card_ping_timer(slic)\n",
1861                         __func__);
1862                 init_timer(&adapter->pingtimer);
1863                 adapter->pingtimer.expires =
1864                     jiffies + SLIC_SECS_TO_JIFFS(PING_TIMER_INTERVAL);
1865                 adapter->pingtimer.data = (ulong) dev;
1866                 adapter->pingtimer.function = &slic_timer_ping;
1867                 add_timer(&adapter->pingtimer);
1868                 adapter->pingtimerset = 1;
1869                 adapter->card->pingstatus = ISR_PINGMASK;
1870         }
1871 #endif
1872
1873         /*
1874          *    clear any pending events, then enable interrupts
1875          */
1876         DBG_MSG("slicoss: %s ENABLE interrupts(slic)\n", __func__);
1877         adapter->isrcopy = 0;
1878         adapter->pshmem->isr = 0;
1879         WRITE_REG(slic_regs->slic_isr, 0, FLUSH);
1880         WRITE_REG(slic_regs->slic_icr, ICR_INT_ON, FLUSH);
1881
1882         DBG_MSG("slicoss: %s call slic_link_config(slic)\n", __func__);
1883         slic_link_config(adapter, LINK_AUTOSPEED, LINK_AUTOD);
1884         slic_link_event_handler(adapter);
1885
1886         DBG_MSG("slicoss: %s EXIT\n", __func__);
1887         return STATUS_SUCCESS;
1888 }
1889
1890 static void slic_unmap_mmio_space(struct adapter *adapter)
1891 {
1892 #if LINUX_FREES_ADAPTER_RESOURCES
1893         if (adapter->slic_regs)
1894                 iounmap(adapter->slic_regs);
1895         adapter->slic_regs = NULL;
1896 #endif
1897 }
1898
1899 static int slic_adapter_allocresources(struct adapter *adapter)
1900 {
1901         if (!adapter->intrregistered) {
1902                 int retval;
1903
1904                 DBG_MSG
1905                     ("slicoss: %s AllocAdaptRsrcs adapter[%p] shmem[%p] \
1906                      phys_shmem[%p] dev->irq[%x] %x\n",
1907                      __func__, adapter, adapter->pshmem,
1908                      (void *)adapter->phys_shmem, adapter->netdev->irq,
1909                      NR_IRQS);
1910
1911                 spin_unlock_irqrestore(&slic_global.driver_lock.lock,
1912                                         slic_global.driver_lock.flags);
1913
1914                 retval = request_irq(adapter->netdev->irq,
1915                                      &slic_interrupt,
1916                                      IRQF_SHARED,
1917                                      adapter->netdev->name, adapter->netdev);
1918
1919                 spin_lock_irqsave(&slic_global.driver_lock.lock,
1920                                         slic_global.driver_lock.flags);
1921
1922                 if (retval) {
1923                         DBG_ERROR("slicoss: request_irq (%s) FAILED [%x]\n",
1924                                   adapter->netdev->name, retval);
1925                         return retval;
1926                 }
1927                 adapter->intrregistered = 1;
1928                 DBG_MSG
1929                     ("slicoss: %s AllocAdaptRsrcs adapter[%p] shmem[%p] \
1930                      pshmem[%p] dev->irq[%x]\n",
1931                      __func__, adapter, adapter->pshmem,
1932                      (void *)adapter->pshmem, adapter->netdev->irq);
1933         }
1934         return STATUS_SUCCESS;
1935 }
1936
1937 static void slic_config_pci(struct pci_dev *pcidev)
1938 {
1939         u16 pci_command;
1940         u16 new_command;
1941
1942         pci_read_config_word(pcidev, PCI_COMMAND, &pci_command);
1943         DBG_MSG("slicoss: %s  PCI command[%4.4x]\n", __func__, pci_command);
1944
1945         new_command = pci_command | PCI_COMMAND_MASTER
1946             | PCI_COMMAND_MEMORY
1947             | PCI_COMMAND_INVALIDATE
1948             | PCI_COMMAND_PARITY | PCI_COMMAND_SERR | PCI_COMMAND_FAST_BACK;
1949         if (pci_command != new_command) {
1950                 DBG_MSG("%s -- Updating PCI COMMAND register %4.4x->%4.4x.\n",
1951                         __func__, pci_command, new_command);
1952                 pci_write_config_word(pcidev, PCI_COMMAND, new_command);
1953         }
1954 }
1955
1956 static void slic_adapter_freeresources(struct adapter *adapter)
1957 {
1958         DBG_MSG("slicoss: %s ENTER adapter[%p]\n", __func__, adapter);
1959         slic_init_cleanup(adapter);
1960         memset(&adapter->stats, 0, sizeof(struct net_device_stats));
1961         adapter->error_interrupts = 0;
1962         adapter->rcv_interrupts = 0;
1963         adapter->xmit_interrupts = 0;
1964         adapter->linkevent_interrupts = 0;
1965         adapter->upr_interrupts = 0;
1966         adapter->num_isrs = 0;
1967         adapter->xmit_completes = 0;
1968         adapter->rcv_broadcasts = 0;
1969         adapter->rcv_multicasts = 0;
1970         adapter->rcv_unicasts = 0;
1971         DBG_MSG("slicoss: %s EXIT\n", __func__);
1972 }
1973
1974 /*
1975  *  slic_link_config
1976  *
1977  *  Write phy control to configure link duplex/speed
1978  *
1979  */
1980 static void slic_link_config(struct adapter *adapter,
1981                       u32 linkspeed, u32 linkduplex)
1982 {
1983         u32 speed;
1984         u32 duplex;
1985         u32 phy_config;
1986         u32 phy_advreg;
1987         u32 phy_gctlreg;
1988
1989         if (adapter->state != ADAPT_UP) {
1990                 DBG_MSG
1991                     ("%s (%s) ADAPT Not up yet, Return! speed[%x] duplex[%x]\n",
1992                      __func__, adapter->netdev->name, linkspeed,
1993                      linkduplex);
1994                 return;
1995         }
1996         DBG_MSG("slicoss: %s (%s) slic_link_config: speed[%x] duplex[%x]\n",
1997                 __func__, adapter->netdev->name, linkspeed, linkduplex);
1998
1999         ASSERT((adapter->devid == SLIC_1GB_DEVICE_ID)
2000                || (adapter->devid == SLIC_2GB_DEVICE_ID));
2001
2002         if (linkspeed > LINK_1000MB)
2003                 linkspeed = LINK_AUTOSPEED;
2004         if (linkduplex > LINK_AUTOD)
2005                 linkduplex = LINK_AUTOD;
2006
2007         if ((linkspeed == LINK_AUTOSPEED) || (linkspeed == LINK_1000MB)) {
2008                 if (adapter->flags & ADAPT_FLAGS_FIBERMEDIA) {
2009                         /*  We've got a fiber gigabit interface, and register
2010                          *  4 is different in fiber mode than in copper mode
2011                          */
2012
2013                         /* advertise FD only @1000 Mb */
2014                         phy_advreg = (MIICR_REG_4 | (PAR_ADV1000XFD));
2015                         /* enable PAUSE frames        */
2016                         phy_advreg |= PAR_ASYMPAUSE_FIBER;
2017                         WRITE_REG(adapter->slic_regs->slic_wphy, phy_advreg,
2018                                   FLUSH);
2019
2020                         if (linkspeed == LINK_AUTOSPEED) {
2021                                 /* reset phy, enable auto-neg  */
2022                                 phy_config =
2023                                     (MIICR_REG_PCR |
2024                                      (PCR_RESET | PCR_AUTONEG |
2025                                       PCR_AUTONEG_RST));
2026                                 WRITE_REG(adapter->slic_regs->slic_wphy,
2027                                           phy_config, FLUSH);
2028                         } else {        /* forced 1000 Mb FD*/
2029                                 /* power down phy to break link
2030                                    this may not work) */
2031                                 phy_config = (MIICR_REG_PCR | PCR_POWERDOWN);
2032                                 WRITE_REG(adapter->slic_regs->slic_wphy,
2033                                           phy_config, FLUSH);
2034                                 /* wait, Marvell says 1 sec,
2035                                    try to get away with 10 ms  */
2036                                 mdelay(10);
2037
2038                                 /* disable auto-neg, set speed/duplex,
2039                                    soft reset phy, powerup */
2040                                 phy_config =
2041                                     (MIICR_REG_PCR |
2042                                      (PCR_RESET | PCR_SPEED_1000 |
2043                                       PCR_DUPLEX_FULL));
2044                                 WRITE_REG(adapter->slic_regs->slic_wphy,
2045                                           phy_config, FLUSH);
2046                         }
2047                 } else {        /* copper gigabit */
2048
2049                         /* Auto-Negotiate or 1000 Mb must be auto negotiated
2050                          * We've got a copper gigabit interface, and
2051                          * register 4 is different in copper mode than
2052                          * in fiber mode
2053                          */
2054                         if (linkspeed == LINK_AUTOSPEED) {
2055                                 /* advertise 10/100 Mb modes   */
2056                                 phy_advreg =
2057                                     (MIICR_REG_4 |
2058                                      (PAR_ADV100FD | PAR_ADV100HD | PAR_ADV10FD
2059                                       | PAR_ADV10HD));
2060                         } else {
2061                         /* linkspeed == LINK_1000MB -
2062                            don't advertise 10/100 Mb modes  */
2063                                 phy_advreg = MIICR_REG_4;
2064                         }
2065                         /* enable PAUSE frames  */
2066                         phy_advreg |= PAR_ASYMPAUSE;
2067                         /* required by the Cicada PHY  */
2068                         phy_advreg |= PAR_802_3;
2069                         WRITE_REG(adapter->slic_regs->slic_wphy, phy_advreg,
2070                                   FLUSH);
2071                         /* advertise FD only @1000 Mb  */
2072                         phy_gctlreg = (MIICR_REG_9 | (PGC_ADV1000FD));
2073                         WRITE_REG(adapter->slic_regs->slic_wphy, phy_gctlreg,
2074                                   FLUSH);
2075
2076                         if (adapter->subsysid != SLIC_1GB_CICADA_SUBSYS_ID) {
2077                                 /* if a Marvell PHY
2078                                    enable auto crossover */
2079                                 phy_config =
2080                                     (MIICR_REG_16 | (MRV_REG16_XOVERON));
2081                                 WRITE_REG(adapter->slic_regs->slic_wphy,
2082                                           phy_config, FLUSH);
2083
2084                                 /* reset phy, enable auto-neg  */
2085                                 phy_config =
2086                                     (MIICR_REG_PCR |
2087                                      (PCR_RESET | PCR_AUTONEG |
2088                                       PCR_AUTONEG_RST));
2089                                 WRITE_REG(adapter->slic_regs->slic_wphy,
2090                                           phy_config, FLUSH);
2091                         } else {        /* it's a Cicada PHY  */
2092                                 /* enable and restart auto-neg (don't reset)  */
2093                                 phy_config =
2094                                     (MIICR_REG_PCR |
2095                                      (PCR_AUTONEG | PCR_AUTONEG_RST));
2096                                 WRITE_REG(adapter->slic_regs->slic_wphy,
2097                                           phy_config, FLUSH);
2098                         }
2099                 }
2100         } else {
2101                 /* Forced 10/100  */
2102                 if (linkspeed == LINK_10MB)
2103                         speed = 0;
2104                 else
2105                         speed = PCR_SPEED_100;
2106                 if (linkduplex == LINK_HALFD)
2107                         duplex = 0;
2108                 else
2109                         duplex = PCR_DUPLEX_FULL;
2110
2111                 if (adapter->subsysid != SLIC_1GB_CICADA_SUBSYS_ID) {
2112                         /* if a Marvell PHY
2113                            disable auto crossover  */
2114                         phy_config = (MIICR_REG_16 | (MRV_REG16_XOVEROFF));
2115                         WRITE_REG(adapter->slic_regs->slic_wphy, phy_config,
2116                                   FLUSH);
2117                 }
2118
2119                 /* power down phy to break link (this may not work)  */
2120                 phy_config = (MIICR_REG_PCR | (PCR_POWERDOWN | speed | duplex));
2121                 WRITE_REG(adapter->slic_regs->slic_wphy, phy_config, FLUSH);
2122
2123                 /* wait, Marvell says 1 sec, try to get away with 10 ms */
2124                 mdelay(10);
2125
2126                 if (adapter->subsysid != SLIC_1GB_CICADA_SUBSYS_ID) {
2127                         /* if a Marvell PHY
2128                            disable auto-neg, set speed,
2129                            soft reset phy, powerup */
2130                         phy_config =
2131                             (MIICR_REG_PCR | (PCR_RESET | speed | duplex));
2132                         WRITE_REG(adapter->slic_regs->slic_wphy, phy_config,
2133                                   FLUSH);
2134                 } else {        /* it's a Cicada PHY  */
2135                         /* disable auto-neg, set speed, powerup  */
2136                         phy_config = (MIICR_REG_PCR | (speed | duplex));
2137                         WRITE_REG(adapter->slic_regs->slic_wphy, phy_config,
2138                                   FLUSH);
2139                 }
2140         }
2141
2142         DBG_MSG
2143             ("slicoss: %s (%s) EXIT slic_link_config : state[%d] \
2144             phy_config[%x]\n", __func__, adapter->netdev->name, adapter->state,
2145             phy_config);
2146 }
2147
2148 static void slic_card_cleanup(struct sliccard *card)
2149 {
2150         DBG_MSG("slicoss: %s ENTER\n", __func__);
2151
2152 #if SLIC_DUMP_ENABLED
2153         if (card->dumpbuffer) {
2154                 card->dumpbuffer_phys = 0;
2155                 card->dumpbuffer_physl = 0;
2156                 card->dumpbuffer_physh = 0;
2157                 kfree(card->dumpbuffer);
2158                 card->dumpbuffer = NULL;
2159         }
2160         if (card->cmdbuffer) {
2161                 card->cmdbuffer_phys = 0;
2162                 card->cmdbuffer_physl = 0;
2163                 card->cmdbuffer_physh = 0;
2164                 kfree(card->cmdbuffer);
2165                 card->cmdbuffer = NULL;
2166         }
2167 #endif
2168
2169         if (card->loadtimerset) {
2170                 card->loadtimerset = 0;
2171                 del_timer(&card->loadtimer);
2172         }
2173
2174         slic_debug_card_destroy(card);
2175
2176         kfree(card);
2177         DBG_MSG("slicoss: %s EXIT\n", __func__);
2178 }
2179
2180 static int slic_card_download_gbrcv(struct adapter *adapter)
2181 {
2182         const struct firmware *fw;
2183         const char *file = "";
2184         int ret;
2185         __iomem struct slic_regs *slic_regs = adapter->slic_regs;
2186         u32 codeaddr;
2187         u32 instruction;
2188         int index = 0;
2189         u32 rcvucodelen = 0;
2190
2191         switch (adapter->devid) {
2192         case SLIC_2GB_DEVICE_ID:
2193                 file = "slicoss/oasisrcvucode.sys";
2194                 break;
2195         case SLIC_1GB_DEVICE_ID:
2196                 file = "slicoss/gbrcvucode.sys";
2197                 break;
2198         default:
2199                 ASSERT(0);
2200                 break;
2201         }
2202
2203         ret = request_firmware(&fw, file, &adapter->pcidev->dev);
2204         if (ret) {
2205                 printk(KERN_ERR "SLICOSS: Failed to load firmware %s\n", file);
2206                 return ret;
2207         }
2208
2209         rcvucodelen = *(u32 *)(fw->data + index);
2210         index += 4;
2211         switch (adapter->devid) {
2212         case SLIC_2GB_DEVICE_ID:
2213                 if (rcvucodelen != OasisRcvUCodeLen)
2214                         return -EINVAL;
2215                 break;
2216         case SLIC_1GB_DEVICE_ID:
2217                 if (rcvucodelen != GBRcvUCodeLen)
2218                         return -EINVAL;
2219                 break;
2220         default:
2221                 ASSERT(0);
2222                 break;
2223         }
2224         /* start download */
2225         WRITE_REG(slic_regs->slic_rcv_wcs, SLIC_RCVWCS_BEGIN, FLUSH);
2226         /* download the rcv sequencer ucode */
2227         for (codeaddr = 0; codeaddr < rcvucodelen; codeaddr++) {
2228                 /* write out instruction address */
2229                 WRITE_REG(slic_regs->slic_rcv_wcs, codeaddr, FLUSH);
2230
2231                 instruction = *(u32 *)(fw->data + index);
2232                 index += 4;
2233                 /* write out the instruction data low addr */
2234                 WRITE_REG(slic_regs->slic_rcv_wcs,
2235                           instruction, FLUSH);
2236
2237                 instruction = *(u8 *)(fw->data + index);
2238                 index++;
2239                 /* write out the instruction data high addr */
2240                 WRITE_REG(slic_regs->slic_rcv_wcs, (u8)instruction,
2241                           FLUSH);
2242         }
2243
2244         /* download finished */
2245         release_firmware(fw);
2246         WRITE_REG(slic_regs->slic_rcv_wcs, SLIC_RCVWCS_FINISH, FLUSH);
2247         return 0;
2248 }
2249
2250 static int slic_card_download(struct adapter *adapter)
2251 {
2252         const struct firmware *fw;
2253         const char *file = "";
2254         int ret;
2255         u32 section;
2256         int thissectionsize;
2257         int codeaddr;
2258         __iomem struct slic_regs *slic_regs = adapter->slic_regs;
2259         u32 instruction;
2260         u32 baseaddress;
2261         u32 failure;
2262         u32 i;
2263         u32 numsects = 0;
2264         u32 sectsize[3];
2265         u32 sectstart[3];
2266         int ucode_start, index = 0;
2267
2268 /*      DBG_MSG ("slicoss: %s (%s) adapter[%p] card[%p] devid[%x] \
2269         jiffies[%lx] cpu %d\n", __func__, adapter->netdev->name, adapter,
2270             adapter->card, adapter->devid,jiffies, smp_processor_id()); */
2271
2272         switch (adapter->devid) {
2273         case SLIC_2GB_DEVICE_ID:
2274                 file = "slicoss/oasisdownload.sys";
2275                 break;
2276         case SLIC_1GB_DEVICE_ID:
2277                 file = "slicoss/gbdownload.sys";
2278                 break;
2279         default:
2280                 ASSERT(0);
2281                 break;
2282         }
2283         ret = request_firmware(&fw, file, &adapter->pcidev->dev);
2284         if (ret) {
2285                 printk(KERN_ERR "SLICOSS: Failed to load firmware %s\n", file);
2286                 return ret;
2287         }
2288         numsects = *(u32 *)(fw->data + index);
2289         index += 4;
2290         ASSERT(numsects <= 3);
2291         for (i = 0; i < numsects; i++) {
2292                 sectsize[i] = *(u32 *)(fw->data + index);
2293                 index += 4;
2294         }
2295         for (i = 0; i < numsects; i++) {
2296                 sectstart[i] = *(u32 *)(fw->data + index);
2297                 index += 4;
2298         }
2299         ucode_start = index;
2300         instruction = *(u32 *)(fw->data + index);
2301         index += 4;
2302         for (section = 0; section < numsects; section++) {
2303                 baseaddress = sectstart[section];
2304                 thissectionsize = sectsize[section] >> 3;
2305
2306                 for (codeaddr = 0; codeaddr < thissectionsize; codeaddr++) {
2307                         /* Write out instruction address */
2308                         WRITE_REG(slic_regs->slic_wcs, baseaddress + codeaddr,
2309                                   FLUSH);
2310                         /* Write out instruction to low addr */
2311                         WRITE_REG(slic_regs->slic_wcs, instruction, FLUSH);
2312                         instruction = *(u32 *)(fw->data + index);
2313                         index += 4;
2314
2315                         /* Write out instruction to high addr */
2316                         WRITE_REG(slic_regs->slic_wcs, instruction, FLUSH);
2317                         instruction = *(u32 *)(fw->data + index);
2318                         index += 4;
2319                 }
2320         }
2321         index = ucode_start;
2322         for (section = 0; section < numsects; section++) {
2323                 instruction = *(u32 *)(fw->data + index);
2324                 baseaddress = sectstart[section];
2325                 if (baseaddress < 0x8000)
2326                         continue;
2327                 thissectionsize = sectsize[section] >> 3;
2328
2329 /*        DBG_MSG ("slicoss: COMPARE secton[%x] baseaddr[%x] sectnsize[%x]\n",
2330                 (uint)section,baseaddress,thissectionsize);*/
2331                 for (codeaddr = 0; codeaddr < thissectionsize; codeaddr++) {
2332                         /* Write out instruction address */
2333                         WRITE_REG(slic_regs->slic_wcs,
2334                                   SLIC_WCS_COMPARE | (baseaddress + codeaddr),
2335                                   FLUSH);
2336                         /* Write out instruction to low addr */
2337                         WRITE_REG(slic_regs->slic_wcs, instruction, FLUSH);
2338                         instruction = *(u32 *)(fw->data + index);
2339                         index += 4;
2340                         /* Write out instruction to high addr */
2341                         WRITE_REG(slic_regs->slic_wcs, instruction, FLUSH);
2342                         instruction = *(u32 *)(fw->data + index);
2343                         index += 4;
2344
2345                         /* Check SRAM location zero. If it is non-zero. Abort.*/
2346 /*                      failure = readl((u32 __iomem *)&slic_regs->slic_reset);
2347                         if (failure) {
2348                                 DBG_MSG
2349                                     ("slicoss: %s FAILURE EXIT codeaddr[%x] "
2350                                     "thissectionsize[%x] failure[%x]\n",
2351                                      __func__, codeaddr, thissectionsize,
2352                                      failure);
2353                                 release_firmware(fw);
2354                                 return -EIO;
2355                         }*/
2356                 }
2357         }
2358 /*    DBG_MSG ("slicoss: Compare done\n");*/
2359         release_firmware(fw);
2360         /* Everything OK, kick off the card */
2361         mdelay(10);
2362         WRITE_REG(slic_regs->slic_wcs, SLIC_WCS_START, FLUSH);
2363
2364         /* stall for 20 ms, long enough for ucode to init card
2365            and reach mainloop */
2366         mdelay(20);
2367
2368         DBG_MSG("slicoss: %s (%s) EXIT adapter[%p] card[%p]\n",
2369                 __func__, adapter->netdev->name, adapter, adapter->card);
2370
2371         return STATUS_SUCCESS;
2372 }
2373
2374 static void slic_adapter_set_hwaddr(struct adapter *adapter)
2375 {
2376         struct sliccard *card = adapter->card;
2377
2378 /*  DBG_MSG ("%s ENTER card->config_set[%x] port[%d] physport[%d] funct#[%d]\n",
2379     __func__, card->config_set, adapter->port, adapter->physport,
2380     adapter->functionnumber);
2381
2382     slic_dbg_macaddrs(adapter); */
2383
2384         if ((adapter->card) && (card->config_set)) {
2385                 memcpy(adapter->macaddr,
2386                        card->config.MacInfo[adapter->functionnumber].macaddrA,
2387                        sizeof(struct slic_config_mac));
2388 /*      DBG_MSG ("%s AFTER copying from config.macinfo into currmacaddr\n",
2389         __func__);
2390         slic_dbg_macaddrs(adapter);*/
2391                 if (!(adapter->currmacaddr[0] || adapter->currmacaddr[1] ||
2392                       adapter->currmacaddr[2] || adapter->currmacaddr[3] ||
2393                       adapter->currmacaddr[4] || adapter->currmacaddr[5])) {
2394                         memcpy(adapter->currmacaddr, adapter->macaddr, 6);
2395                 }
2396                 if (adapter->netdev) {
2397                         memcpy(adapter->netdev->dev_addr, adapter->currmacaddr,
2398                                6);
2399                 }
2400         }
2401 /*  DBG_MSG ("%s EXIT port %d\n", __func__, adapter->port);
2402     slic_dbg_macaddrs(adapter); */
2403 }
2404
2405 static void slic_intagg_set(struct adapter *adapter, u32 value)
2406 {
2407         __iomem struct slic_regs *slic_regs = adapter->slic_regs;
2408
2409         WRITE_REG(slic_regs->slic_intagg, value, FLUSH);
2410         adapter->card->loadlevel_current = value;
2411 }
2412
2413 static int slic_card_init(struct sliccard *card, struct adapter *adapter)
2414 {
2415         __iomem struct slic_regs *slic_regs = adapter->slic_regs;
2416         struct slic_eeprom *peeprom;
2417         struct oslic_eeprom *pOeeprom;
2418         dma_addr_t phys_config;
2419         u32 phys_configh;
2420         u32 phys_configl;
2421         u32 i = 0;
2422         struct slic_shmem *pshmem;
2423         int status;
2424         uint macaddrs = card->card_size;
2425         ushort eecodesize;
2426         ushort dramsize;
2427         ushort ee_chksum;
2428         ushort calc_chksum;
2429         struct slic_config_mac *pmac;
2430         unsigned char fruformat;
2431         unsigned char oemfruformat;
2432         struct atk_fru *patkfru;
2433         union oemfru *poemfru;
2434
2435         DBG_MSG
2436             ("slicoss: %s ENTER card[%p] adapter[%p] card->state[%x] \
2437             size[%d]\n", __func__, card, adapter, card->state, card->card_size);
2438
2439         /* Reset everything except PCI configuration space */
2440         slic_soft_reset(adapter);
2441
2442         /* Download the microcode */
2443         status = slic_card_download(adapter);
2444
2445         if (status != STATUS_SUCCESS) {
2446                 DBG_ERROR("SLIC download failed bus %d slot %d\n",
2447                           (uint) adapter->busnumber,
2448                           (uint) adapter->slotnumber);
2449                 return status;
2450         }
2451
2452         if (!card->config_set) {
2453                 peeprom = pci_alloc_consistent(adapter->pcidev,
2454                                                sizeof(struct slic_eeprom),
2455                                                &phys_config);
2456
2457                 phys_configl = SLIC_GET_ADDR_LOW(phys_config);
2458                 phys_configh = SLIC_GET_ADDR_HIGH(phys_config);
2459
2460                 DBG_MSG("slicoss: %s Eeprom info  adapter [%p]\n    "
2461                         "size        [%x]\n    peeprom     [%p]\n    "
2462                         "phys_config [%p]\n    phys_configl[%x]\n    "
2463                         "phys_configh[%x]\n",
2464                         __func__, adapter,
2465                         (u32)sizeof(struct slic_eeprom),
2466                         peeprom, (void *) phys_config, phys_configl,
2467                         phys_configh);
2468                 if (!peeprom) {
2469                         DBG_ERROR
2470                             ("SLIC eeprom read failed to get memory bus %d \
2471                             slot %d\n",
2472                              (uint) adapter->busnumber,
2473                              (uint) adapter->slotnumber);
2474                         return -ENOMEM;
2475                 } else {
2476                         memset(peeprom, 0, sizeof(struct slic_eeprom));
2477                 }
2478                 WRITE_REG(slic_regs->slic_icr, ICR_INT_OFF, FLUSH);
2479                 mdelay(1);
2480                 pshmem = (struct slic_shmem *)adapter->phys_shmem;
2481
2482                 spin_lock_irqsave(&adapter->bit64reglock.lock,
2483                                         adapter->bit64reglock.flags);
2484                 WRITE_REG(slic_regs->slic_addr_upper, 0, DONT_FLUSH);
2485                 WRITE_REG(slic_regs->slic_isp,
2486                           SLIC_GET_ADDR_LOW(&pshmem->isr), FLUSH);
2487                 spin_unlock_irqrestore(&adapter->bit64reglock.lock,
2488                                         adapter->bit64reglock.flags);
2489
2490                 slic_config_get(adapter, phys_configl, phys_configh);
2491
2492                 for (;;) {
2493                         if (adapter->pshmem->isr) {
2494                                 DBG_MSG("%s shmem[%p] shmem->isr[%x]\n",
2495                                         __func__, adapter->pshmem,
2496                                         adapter->pshmem->isr);
2497
2498                                 if (adapter->pshmem->isr & ISR_UPC) {
2499                                         adapter->pshmem->isr = 0;
2500                                         WRITE_REG64(adapter,
2501                                                     slic_regs->slic_isp,
2502                                                     0,
2503                                                     slic_regs->slic_addr_upper,
2504                                                     0, FLUSH);
2505                                         WRITE_REG(slic_regs->slic_isr, 0,
2506                                                   FLUSH);
2507
2508                                         slic_upr_request_complete(adapter, 0);
2509                                         break;
2510                                 } else {
2511                                         adapter->pshmem->isr = 0;
2512                                         WRITE_REG(slic_regs->slic_isr, 0,
2513                                                   FLUSH);
2514                                 }
2515                         } else {
2516                                 mdelay(1);
2517                                 i++;
2518                                 if (i > 5000) {
2519                                         DBG_ERROR
2520                                             ("SLIC: %d config data fetch timed "
2521                                               "out!\n", adapter->port);
2522                                         DBG_MSG("%s shmem[%p] shmem->isr[%x]\n",
2523                                                 __func__, adapter->pshmem,
2524                                                 adapter->pshmem->isr);
2525                                         WRITE_REG64(adapter,
2526                                                     slic_regs->slic_isp, 0,
2527                                                     slic_regs->slic_addr_upper,
2528                                                     0, FLUSH);
2529                                         return -EINVAL;
2530                                 }
2531                         }
2532                 }
2533
2534                 switch (adapter->devid) {
2535                 /* Oasis card */
2536                 case SLIC_2GB_DEVICE_ID:
2537                         /* extract EEPROM data and pointers to EEPROM data */
2538                         pOeeprom = (struct oslic_eeprom *) peeprom;
2539                         eecodesize = pOeeprom->EecodeSize;
2540                         dramsize = pOeeprom->DramSize;
2541                         pmac = pOeeprom->MacInfo;
2542                         fruformat = pOeeprom->FruFormat;
2543                         patkfru = &pOeeprom->AtkFru;
2544                         oemfruformat = pOeeprom->OemFruFormat;
2545                         poemfru = &pOeeprom->OemFru;
2546                         macaddrs = 2;
2547                         /* Minor kludge for Oasis card
2548                              get 2 MAC addresses from the
2549                              EEPROM to ensure that function 1
2550                              gets the Port 1 MAC address */
2551                         break;
2552                 default:
2553                         /* extract EEPROM data and pointers to EEPROM data */
2554                         eecodesize = peeprom->EecodeSize;
2555                         dramsize = peeprom->DramSize;
2556                         pmac = peeprom->u2.mac.MacInfo;
2557                         fruformat = peeprom->FruFormat;
2558                         patkfru = &peeprom->AtkFru;
2559                         oemfruformat = peeprom->OemFruFormat;
2560                         poemfru = &peeprom->OemFru;
2561                         break;
2562                 }
2563
2564                 card->config.EepromValid = FALSE;
2565
2566                 /*  see if the EEPROM is valid by checking it's checksum */
2567                 if ((eecodesize <= MAX_EECODE_SIZE) &&
2568                     (eecodesize >= MIN_EECODE_SIZE)) {
2569
2570                         ee_chksum =
2571                             *(u16 *) ((char *) peeprom + (eecodesize - 2));
2572                         /*
2573                             calculate the EEPROM checksum
2574                         */
2575                         calc_chksum =
2576                             ~slic_eeprom_cksum((char *) peeprom,
2577                                                (eecodesize - 2));
2578                         /*
2579                             if the ucdoe chksum flag bit worked,
2580                             we wouldn't need this shit
2581                         */
2582                         if (ee_chksum == calc_chksum)
2583                                 card->config.EepromValid = TRUE;
2584                 }
2585                 /*  copy in the DRAM size */
2586                 card->config.DramSize = dramsize;
2587
2588                 /*  copy in the MAC address(es) */
2589                 for (i = 0; i < macaddrs; i++) {
2590                         memcpy(&card->config.MacInfo[i],
2591                                &pmac[i], sizeof(struct slic_config_mac));
2592                 }
2593 /*      DBG_MSG ("%s EEPROM Checksum Good? %d  MacAddress\n",__func__,
2594                 card->config.EepromValid); */
2595
2596                 /*  copy the Alacritech FRU information */
2597                 card->config.FruFormat = fruformat;
2598                 memcpy(&card->config.AtkFru, patkfru,
2599                                                 sizeof(struct atk_fru));
2600
2601                 pci_free_consistent(adapter->pcidev,
2602                                     sizeof(struct slic_eeprom),
2603                                     peeprom, phys_config);
2604                 DBG_MSG
2605                     ("slicoss: %s adapter%d [%p] size[%x] FREE peeprom[%p] \
2606                      phys_config[%p]\n",
2607                      __func__, adapter->port, adapter,
2608                      (u32) sizeof(struct slic_eeprom), peeprom,
2609                      (void *) phys_config);
2610
2611                 if ((!card->config.EepromValid) &&
2612                     (adapter->reg_params.fail_on_bad_eeprom)) {
2613                         WRITE_REG64(adapter,
2614                                     slic_regs->slic_isp,
2615                                     0, slic_regs->slic_addr_upper, 0, FLUSH);
2616                         DBG_ERROR
2617                             ("unsupported CONFIGURATION  EEPROM invalid\n");
2618                         return -EINVAL;
2619                 }
2620
2621                 card->config_set = 1;
2622         }
2623
2624         if (slic_card_download_gbrcv(adapter)) {
2625                 DBG_ERROR("%s unable to download GB receive microcode\n",
2626                           __func__);
2627                 return -EINVAL;
2628         }
2629
2630         if (slic_global.dynamic_intagg) {
2631                 DBG_MSG
2632                     ("Dynamic Interrupt Aggregation[ENABLED]: slic%d \
2633                      SET intagg to %d\n",
2634                      card->cardnum, 0);
2635                 slic_intagg_set(adapter, 0);
2636         } else {
2637                 slic_intagg_set(adapter, intagg_delay);
2638                 DBG_MSG
2639                     ("Dynamic Interrupt Aggregation[DISABLED]: slic%d \
2640                      SET intagg to %d\n",
2641                      card->cardnum, intagg_delay);
2642         }
2643
2644         /*
2645          *  Initialize ping status to "ok"
2646          */
2647         card->pingstatus = ISR_PINGMASK;
2648
2649 #if SLIC_DUMP_ENABLED
2650         if (!card->dumpbuffer) {
2651                 card->dumpbuffer = kmalloc(DUMP_PAGE_SIZE, GFP_ATOMIC);
2652
2653                 ASSERT(card->dumpbuffer);
2654                 if (card->dumpbuffer == NULL)
2655                         return -ENOMEM;
2656         }
2657         /*
2658          *  Smear the shared memory structure and then obtain
2659          *  the PHYSICAL address of this structure
2660          */
2661         memset(card->dumpbuffer, 0, DUMP_PAGE_SIZE);
2662         card->dumpbuffer_phys = virt_to_bus(card->dumpbuffer);
2663         card->dumpbuffer_physh = SLIC_GET_ADDR_HIGH(card->dumpbuffer_phys);
2664         card->dumpbuffer_physl = SLIC_GET_ADDR_LOW(card->dumpbuffer_phys);
2665
2666         /*
2667          *  Allocate COMMAND BUFFER
2668          */
2669         if (!card->cmdbuffer) {
2670                 card->cmdbuffer = kmalloc(sizeof(struct dump_cmd), GFP_ATOMIC);
2671
2672                 ASSERT(card->cmdbuffer);
2673                 if (card->cmdbuffer == NULL)
2674                         return -ENOMEM;
2675         }
2676         /*
2677          *  Smear the shared memory structure and then obtain
2678          *  the PHYSICAL address of this structure
2679          */
2680         memset(card->cmdbuffer, 0, sizeof(struct dump_cmd));
2681         card->cmdbuffer_phys = virt_to_bus(card->cmdbuffer);
2682         card->cmdbuffer_physh = SLIC_GET_ADDR_HIGH(card->cmdbuffer_phys);
2683         card->cmdbuffer_physl = SLIC_GET_ADDR_LOW(card->cmdbuffer_phys);
2684 #endif
2685
2686         /*
2687          * Lastly, mark our card state as up and return success
2688          */
2689         card->state = CARD_UP;
2690         card->reset_in_progress = 0;
2691         DBG_MSG("slicoss: %s EXIT card[%p] adapter[%p] card->state[%x]\n",
2692                 __func__, card, adapter, card->state);
2693
2694         return STATUS_SUCCESS;
2695 }
2696
2697 static u32 slic_card_locate(struct adapter *adapter)
2698 {
2699         struct sliccard *card = slic_global.slic_card;
2700         struct physcard *physcard = slic_global.phys_card;
2701         ushort card_hostid;
2702         u16 __iomem *hostid_reg;
2703         uint i;
2704         uint rdhostid_offset = 0;
2705
2706         DBG_MSG("slicoss: %s adapter[%p] slot[%x] bus[%x] port[%x]\n",
2707                 __func__, adapter, adapter->slotnumber, adapter->busnumber,
2708                 adapter->port);
2709
2710         switch (adapter->devid) {
2711         case SLIC_2GB_DEVICE_ID:
2712                 rdhostid_offset = SLIC_RDHOSTID_2GB;
2713                 break;
2714         case SLIC_1GB_DEVICE_ID:
2715                 rdhostid_offset = SLIC_RDHOSTID_1GB;
2716                 break;
2717         default:
2718                 ASSERT(0);
2719                 break;
2720         }
2721
2722         hostid_reg =
2723             (u16 __iomem *) (((u8 __iomem *) (adapter->slic_regs)) +
2724             rdhostid_offset);
2725         DBG_MSG("slicoss: %s *hostid_reg[%p] == ", __func__, hostid_reg);
2726
2727         /* read the 16 bit hostid from SRAM */
2728         card_hostid = (ushort) readw(hostid_reg);
2729         DBG_MSG(" card_hostid[%x]\n", card_hostid);
2730
2731         /* Initialize a new card structure if need be */
2732         if (card_hostid == SLIC_HOSTID_DEFAULT) {
2733                 card = kzalloc(sizeof(struct sliccard), GFP_KERNEL);
2734                 if (card == NULL)
2735                         return -ENOMEM;
2736
2737                 card->next = slic_global.slic_card;
2738                 slic_global.slic_card = card;
2739 #if DBG
2740                 if (adapter->devid == SLIC_2GB_DEVICE_ID) {
2741                         DBG_MSG
2742                             ("SLICOSS ==> Initialize 2 Port Gigabit Server "
2743                              "and Storage Accelerator\n");
2744                 } else {
2745                         DBG_MSG
2746                             ("SLICOSS ==> Initialize 1 Port Gigabit Server "
2747                              "and Storage Accelerator\n");
2748                 }
2749 #endif
2750                 card->busnumber = adapter->busnumber;
2751                 card->slotnumber = adapter->slotnumber;
2752
2753                 /* Find an available cardnum */
2754                 for (i = 0; i < SLIC_MAX_CARDS; i++) {
2755                         if (slic_global.cardnuminuse[i] == 0) {
2756                                 slic_global.cardnuminuse[i] = 1;
2757                                 card->cardnum = i;
2758                                 break;
2759                         }
2760                 }
2761                 slic_global.num_slic_cards++;
2762                 DBG_MSG("\nCARDNUM == %d  Total %d  Card[%p]\n\n",
2763                         card->cardnum, slic_global.num_slic_cards, card);
2764
2765                 slic_debug_card_create(card);
2766         } else {
2767                 DBG_MSG
2768                     ("slicoss: %s CARD already allocated, find the \
2769                      correct card\n", __func__);
2770                 /* Card exists, find the card this adapter belongs to */
2771                 while (card) {
2772                         DBG_MSG
2773                             ("slicoss: %s card[%p] slot[%x] bus[%x] \
2774                               adaptport[%p] hostid[%x] cardnum[%x]\n",
2775                              __func__, card, card->slotnumber,
2776                              card->busnumber, card->adapter[adapter->port],
2777                              card_hostid, card->cardnum);
2778
2779                         if (card->cardnum == card_hostid)
2780                                 break;
2781                         card = card->next;
2782                 }
2783         }
2784
2785         ASSERT(card);
2786         if (!card)
2787                 return STATUS_FAILURE;
2788         /* Put the adapter in the card's adapter list */
2789         ASSERT(card->adapter[adapter->port] == NULL);
2790         if (!card->adapter[adapter->port]) {
2791                 card->adapter[adapter->port] = adapter;
2792                 adapter->card = card;
2793         }
2794
2795         card->card_size = 1;    /* one port per *logical* card */
2796
2797         while (physcard) {
2798                 for (i = 0; i < SLIC_MAX_PORTS; i++) {
2799                         if (!physcard->adapter[i])
2800                                 continue;
2801                         else
2802                                 break;
2803                 }
2804                 ASSERT(i != SLIC_MAX_PORTS);
2805                 if (physcard->adapter[i]->slotnumber == adapter->slotnumber)
2806                         break;
2807                 physcard = physcard->next;
2808         }
2809         if (!physcard) {
2810                 /* no structure allocated for this physical card yet */
2811                 physcard = kzalloc(sizeof(struct physcard), GFP_ATOMIC);
2812                 ASSERT(physcard);
2813
2814                 DBG_MSG
2815                     ("\n%s Allocate a PHYSICALcard:\n    PHYSICAL_Card[%p]\n"
2816                      "    LogicalCard  [%p]\n    adapter      [%p]\n",
2817                      __func__, physcard, card, adapter);
2818
2819                 physcard->next = slic_global.phys_card;
2820                 slic_global.phys_card = physcard;
2821                 physcard->adapters_allocd = 1;
2822         } else {
2823                 physcard->adapters_allocd++;
2824         }
2825         /* Note - this is ZERO relative */
2826         adapter->physport = physcard->adapters_allocd - 1;
2827
2828         ASSERT(physcard->adapter[adapter->physport] == NULL);
2829         physcard->adapter[adapter->physport] = adapter;
2830         adapter->physcard = physcard;
2831         DBG_MSG("    PHYSICAL_Port %d    Logical_Port  %d\n", adapter->physport,
2832                 adapter->port);
2833
2834         return 0;
2835 }
2836
2837 static void slic_soft_reset(struct adapter *adapter)
2838 {
2839         if (adapter->card->state == CARD_UP) {
2840                 DBG_MSG("slicoss: %s QUIESCE adapter[%p] card[%p] devid[%x]\n",
2841                         __func__, adapter, adapter->card, adapter->devid);
2842                 WRITE_REG(adapter->slic_regs->slic_quiesce, 0, FLUSH);
2843                 mdelay(1);
2844         }
2845 /*      DBG_MSG ("slicoss: %s (%s) adapter[%p] card[%p] devid[%x]\n",
2846         __func__, adapter->netdev->name, adapter, adapter->card,
2847            adapter->devid); */
2848
2849         WRITE_REG(adapter->slic_regs->slic_reset, SLIC_RESET_MAGIC, FLUSH);
2850         mdelay(1);
2851 }
2852
2853 static void slic_config_set(struct adapter *adapter, bool linkchange)
2854 {
2855         u32 value;
2856         u32 RcrReset;
2857         __iomem struct slic_regs *slic_regs = adapter->slic_regs;
2858
2859         DBG_MSG("slicoss: %s (%s) slic_interface_enable[%p](%d)\n",
2860                 __func__, adapter->netdev->name, adapter,
2861                 adapter->cardindex);
2862
2863         if (linkchange) {
2864                 /* Setup MAC */
2865                 slic_mac_config(adapter);
2866                 RcrReset = GRCR_RESET;
2867         } else {
2868                 slic_mac_address_config(adapter);
2869                 RcrReset = 0;
2870         }
2871
2872         if (adapter->linkduplex == LINK_FULLD) {
2873                 /* setup xmtcfg */
2874                 value = (GXCR_RESET |   /* Always reset     */
2875                          GXCR_XMTEN |   /* Enable transmit  */
2876                          GXCR_PAUSEEN); /* Enable pause     */
2877
2878                 DBG_MSG("slicoss: FDX adapt[%p] set xmtcfg to [%x]\n", adapter,
2879                         value);
2880                 WRITE_REG(slic_regs->slic_wxcfg, value, FLUSH);
2881
2882                 /* Setup rcvcfg last */
2883                 value = (RcrReset |     /* Reset, if linkchange */
2884                          GRCR_CTLEN |   /* Enable CTL frames    */
2885                          GRCR_ADDRAEN | /* Address A enable     */
2886                          GRCR_RCVBAD |  /* Rcv bad frames       */
2887                          (GRCR_HASHSIZE << GRCR_HASHSIZE_SHIFT));
2888         } else {
2889                 /* setup xmtcfg */
2890                 value = (GXCR_RESET |   /* Always reset     */
2891                          GXCR_XMTEN);   /* Enable transmit  */
2892
2893                 DBG_MSG("slicoss: HDX adapt[%p] set xmtcfg to [%x]\n", adapter,
2894                         value);
2895                 WRITE_REG(slic_regs->slic_wxcfg, value, FLUSH);
2896
2897                 /* Setup rcvcfg last */
2898                 value = (RcrReset |     /* Reset, if linkchange */
2899                          GRCR_ADDRAEN | /* Address A enable     */
2900                          GRCR_RCVBAD |  /* Rcv bad frames       */
2901                          (GRCR_HASHSIZE << GRCR_HASHSIZE_SHIFT));
2902         }
2903
2904         if (adapter->state != ADAPT_DOWN) {
2905                 /* Only enable receive if we are restarting or running */
2906                 value |= GRCR_RCVEN;
2907         }
2908
2909         if (adapter->macopts & MAC_PROMISC)
2910                 value |= GRCR_RCVALL;
2911
2912         DBG_MSG("slicoss: adapt[%p] set rcvcfg to [%x]\n", adapter, value);
2913         WRITE_REG(slic_regs->slic_wrcfg, value, FLUSH);
2914 }
2915
2916 /*
2917  *  Turn off RCV and XMT, power down PHY
2918  */
2919 static void slic_config_clear(struct adapter *adapter)
2920 {
2921         u32 value;
2922         u32 phy_config;
2923         __iomem struct slic_regs *slic_regs = adapter->slic_regs;
2924
2925         /* Setup xmtcfg */
2926         value = (GXCR_RESET |   /* Always reset */
2927                  GXCR_PAUSEEN); /* Enable pause */
2928
2929         WRITE_REG(slic_regs->slic_wxcfg, value, FLUSH);
2930
2931         value = (GRCR_RESET |   /* Always reset      */
2932                  GRCR_CTLEN |   /* Enable CTL frames */
2933                  GRCR_ADDRAEN | /* Address A enable  */
2934                  (GRCR_HASHSIZE << GRCR_HASHSIZE_SHIFT));
2935
2936         WRITE_REG(slic_regs->slic_wrcfg, value, FLUSH);
2937
2938         /* power down phy */
2939         phy_config = (MIICR_REG_PCR | (PCR_POWERDOWN));
2940         WRITE_REG(slic_regs->slic_wphy, phy_config, FLUSH);
2941 }
2942
2943 static void slic_config_get(struct adapter *adapter, u32 config,
2944                                                         u32 config_h)
2945 {
2946         int status;
2947
2948         status = slic_upr_request(adapter,
2949                                   SLIC_UPR_RCONFIG,
2950                                   (u32) config, (u32) config_h, 0, 0);
2951         ASSERT(status == 0);
2952 }
2953
2954 static void slic_mac_address_config(struct adapter *adapter)
2955 {
2956         u32 value;
2957         u32 value2;
2958         __iomem struct slic_regs *slic_regs = adapter->slic_regs;
2959
2960         value = *(u32 *) &adapter->currmacaddr[2];
2961         value = ntohl(value);
2962         WRITE_REG(slic_regs->slic_wraddral, value, FLUSH);
2963         WRITE_REG(slic_regs->slic_wraddrbl, value, FLUSH);
2964
2965         value2 = (u32) ((adapter->currmacaddr[0] << 8 |
2966                              adapter->currmacaddr[1]) & 0xFFFF);
2967
2968         WRITE_REG(slic_regs->slic_wraddrah, value2, FLUSH);
2969         WRITE_REG(slic_regs->slic_wraddrbh, value2, FLUSH);
2970
2971         DBG_MSG("%s value1[%x] value2[%x] Call slic_mcast_set_mask\n",
2972                 __func__, value, value2);
2973         slic_dbg_macaddrs(adapter);
2974
2975         /* Write our multicast mask out to the card.  This is done */
2976         /* here in addition to the slic_mcast_addr_set routine     */
2977         /* because ALL_MCAST may have been enabled or disabled     */
2978         slic_mcast_set_mask(adapter);
2979 }
2980
2981 static void slic_mac_config(struct adapter *adapter)
2982 {
2983         u32 value;
2984         __iomem struct slic_regs *slic_regs = adapter->slic_regs;
2985
2986         /* Setup GMAC gaps */
2987         if (adapter->linkspeed == LINK_1000MB) {
2988                 value = ((GMCR_GAPBB_1000 << GMCR_GAPBB_SHIFT) |
2989                          (GMCR_GAPR1_1000 << GMCR_GAPR1_SHIFT) |
2990                          (GMCR_GAPR2_1000 << GMCR_GAPR2_SHIFT));
2991         } else {
2992                 value = ((GMCR_GAPBB_100 << GMCR_GAPBB_SHIFT) |
2993                          (GMCR_GAPR1_100 << GMCR_GAPR1_SHIFT) |
2994                          (GMCR_GAPR2_100 << GMCR_GAPR2_SHIFT));
2995         }
2996
2997         /* enable GMII */
2998         if (adapter->linkspeed == LINK_1000MB)
2999                 value |= GMCR_GBIT;
3000
3001         /* enable fullduplex */
3002         if ((adapter->linkduplex == LINK_FULLD)
3003             || (adapter->macopts & MAC_LOOPBACK)) {
3004                 value |= GMCR_FULLD;
3005         }
3006
3007         /* write mac config */
3008         WRITE_REG(slic_regs->slic_wmcfg, value, FLUSH);
3009
3010         /* setup mac addresses */
3011         slic_mac_address_config(adapter);
3012 }
3013
3014 static bool slic_mac_filter(struct adapter *adapter,
3015                         struct ether_header *ether_frame)
3016 {
3017         u32 opts = adapter->macopts;
3018         u32 *dhost4 = (u32 *)&ether_frame->ether_dhost[0];
3019         u16 *dhost2 = (u16 *)&ether_frame->ether_dhost[4];
3020         bool equaladdr;
3021
3022         if (opts & MAC_PROMISC) {
3023                 DBG_MSG("slicoss: %s (%s) PROMISCUOUS. Accept frame\n",
3024                         __func__, adapter->netdev->name);
3025                 return TRUE;
3026         }
3027
3028         if ((*dhost4 == 0xFFFFFFFF) && (*dhost2 == 0xFFFF)) {
3029                 if (opts & MAC_BCAST) {
3030                         adapter->rcv_broadcasts++;
3031                         return TRUE;
3032                 } else {
3033                         return FALSE;
3034                 }
3035         }
3036
3037         if (ether_frame->ether_dhost[0] & 0x01) {
3038                 if (opts & MAC_ALLMCAST) {
3039                         adapter->rcv_multicasts++;
3040                         adapter->stats.multicast++;
3041                         return TRUE;
3042                 }
3043                 if (opts & MAC_MCAST) {
3044                         struct mcast_address *mcaddr = adapter->mcastaddrs;
3045
3046                         while (mcaddr) {
3047                                 ETHER_EQ_ADDR(mcaddr->address,
3048                                               ether_frame->ether_dhost,
3049                                               equaladdr);
3050                                 if (equaladdr) {
3051                                         adapter->rcv_multicasts++;
3052                                         adapter->stats.multicast++;
3053                                         return TRUE;
3054                                 }
3055                                 mcaddr = mcaddr->next;
3056                         }
3057                         return FALSE;
3058                 } else {
3059                         return FALSE;
3060                 }
3061         }
3062         if (opts & MAC_DIRECTED) {
3063                 adapter->rcv_unicasts++;
3064                 return TRUE;
3065         }
3066         return FALSE;
3067
3068 }
3069
3070 static int slic_mac_set_address(struct net_device *dev, void *ptr)
3071 {
3072         struct adapter *adapter = (struct adapter *)netdev_priv(dev);
3073         struct sockaddr *addr = ptr;
3074
3075         DBG_MSG("%s ENTER (%s)\n", __func__, adapter->netdev->name);
3076
3077         if (netif_running(dev))
3078                 return -EBUSY;
3079         if (!adapter)
3080                 return -EBUSY;
3081         DBG_MSG("slicoss: %s (%s) curr %2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X\n",
3082                 __func__, adapter->netdev->name, adapter->currmacaddr[0],
3083                 adapter->currmacaddr[1], adapter->currmacaddr[2],
3084                 adapter->currmacaddr[3], adapter->currmacaddr[4],
3085                 adapter->currmacaddr[5]);
3086         memcpy(dev->dev_addr, addr->sa_data, dev->addr_len);
3087         memcpy(adapter->currmacaddr, addr->sa_data, dev->addr_len);
3088         DBG_MSG("slicoss: %s (%s) new %2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X\n",
3089                 __func__, adapter->netdev->name, adapter->currmacaddr[0],
3090                 adapter->currmacaddr[1], adapter->currmacaddr[2],
3091                 adapter->currmacaddr[3], adapter->currmacaddr[4],
3092                 adapter->currmacaddr[5]);
3093
3094         slic_config_set(adapter, TRUE);
3095         return 0;
3096 }
3097
3098 /*
3099  *  slic_timer_get_stats
3100  *
3101  * Timer function used to suck the statistics out of the card every
3102  * 50 seconds or whatever STATS_TIMER_INTERVAL is set to.
3103  *
3104  */
3105 #if SLIC_GET_STATS_TIMER_ENABLED
3106 static void slic_timer_get_stats(ulong dev)
3107 {
3108         struct adapter *adapter;
3109         struct sliccard *card;
3110         struct slic_shmem *pshmem;
3111
3112         ASSERT(dev);
3113         adapter = netdev_priv((struct net_device *)dev);
3114         ASSERT(adapter);
3115         card = adapter->card;
3116         ASSERT(card);
3117
3118         if ((card->state == CARD_UP) &&
3119             (adapter->state == ADAPT_UP) && (adapter->linkstate == LINK_UP)) {
3120                 pshmem = (struct slic_shmem *)adapter->phys_shmem;
3121 #ifdef CONFIG_X86_64
3122                 slic_upr_request(adapter,
3123                                  SLIC_UPR_STATS,
3124                                  SLIC_GET_ADDR_LOW(&pshmem->inicstats),
3125                                  SLIC_GET_ADDR_HIGH(&pshmem->inicstats), 0, 0);
3126 #elif defined(CONFIG_X86)
3127                 slic_upr_request(adapter,
3128                                  SLIC_UPR_STATS,
3129                                  (u32) &pshmem->inicstats, 0, 0, 0);
3130 #else
3131                 Stop compilation;
3132 #endif
3133         } else {
3134 /*              DBG_MSG ("slicoss: %s adapter[%p] linkstate[%x] NOT UP!\n",
3135                         __func__, adapter, adapter->linkstate); */
3136         }
3137         adapter->statstimer.expires = jiffies +
3138             SLIC_SECS_TO_JIFFS(STATS_TIMER_INTERVAL);
3139         add_timer(&adapter->statstimer);
3140 }
3141 #endif
3142 static void slic_timer_load_check(ulong cardaddr)
3143 {
3144         struct sliccard *card = (struct sliccard *)cardaddr;
3145         struct adapter *adapter = card->master;
3146         u32 load = card->events;
3147         u32 level = 0;
3148
3149         if ((adapter) && (adapter->state == ADAPT_UP) &&
3150             (card->state == CARD_UP) && (slic_global.dynamic_intagg)) {
3151                 if (adapter->devid == SLIC_1GB_DEVICE_ID) {
3152                         if (adapter->linkspeed == LINK_1000MB)
3153                                 level = 100;
3154                         else {
3155                                 if (load > SLIC_LOAD_5)
3156                                         level = SLIC_INTAGG_5;
3157                                 else if (load > SLIC_LOAD_4)
3158                                         level = SLIC_INTAGG_4;
3159                                 else if (load > SLIC_LOAD_3)
3160                                         level = SLIC_INTAGG_3;
3161                                 else if (load > SLIC_LOAD_2)
3162                                         level = SLIC_INTAGG_2;
3163                                 else if (load > SLIC_LOAD_1)
3164                                         level = SLIC_INTAGG_1;
3165                                 else
3166                                         level = SLIC_INTAGG_0;
3167                         }
3168                         if (card->loadlevel_current != level) {
3169                                 card->loadlevel_current = level;
3170                                 WRITE_REG(adapter->slic_regs->slic_intagg,
3171                                           level, FLUSH);
3172                         }
3173                 } else {
3174                         if (load > SLIC_LOAD_5)
3175                                 level = SLIC_INTAGG_5;
3176                         else if (load > SLIC_LOAD_4)
3177                                 level = SLIC_INTAGG_4;
3178                         else if (load > SLIC_LOAD_3)
3179                                 level = SLIC_INTAGG_3;
3180                         else if (load > SLIC_LOAD_2)
3181                                 level = SLIC_INTAGG_2;
3182                         else if (load > SLIC_LOAD_1)
3183                                 level = SLIC_INTAGG_1;
3184                         else
3185                                 level = SLIC_INTAGG_0;
3186                         if (card->loadlevel_current != level) {
3187                                 card->loadlevel_current = level;
3188                                 WRITE_REG(adapter->slic_regs->slic_intagg,
3189                                           level, FLUSH);
3190                         }
3191                 }
3192         }
3193         card->events = 0;
3194         card->loadtimer.expires =
3195             jiffies + SLIC_SECS_TO_JIFFS(SLIC_LOADTIMER_PERIOD);
3196         add_timer(&card->loadtimer);
3197 }
3198
3199 static void slic_assert_fail(void)
3200 {
3201         u32 cpuid;
3202         u32 curr_pid;
3203         cpuid = smp_processor_id();
3204         curr_pid = current->pid;
3205
3206         DBG_ERROR("%s CPU # %d ---- PID # %d\n", __func__, cpuid, curr_pid);
3207 }
3208
3209 static int slic_upr_queue_request(struct adapter *adapter,
3210                            u32 upr_request,
3211                            u32 upr_data,
3212                            u32 upr_data_h,
3213                            u32 upr_buffer, u32 upr_buffer_h)
3214 {
3215         struct slic_upr *upr;
3216         struct slic_upr *uprqueue;
3217
3218         upr = kmalloc(sizeof(struct slic_upr), GFP_ATOMIC);
3219         if (!upr) {
3220                 DBG_MSG("%s COULD NOT ALLOCATE UPR MEM\n", __func__);
3221
3222                 return -ENOMEM;
3223         }
3224         upr->adapter = adapter->port;
3225         upr->upr_request = upr_request;
3226         upr->upr_data = upr_data;
3227         upr->upr_buffer = upr_buffer;
3228         upr->upr_data_h = upr_data_h;
3229         upr->upr_buffer_h = upr_buffer_h;
3230         upr->next = NULL;
3231         if (adapter->upr_list) {
3232                 uprqueue = adapter->upr_list;
3233
3234                 while (uprqueue->next)
3235                         uprqueue = uprqueue->next;
3236                 uprqueue->next = upr;
3237         } else {
3238                 adapter->upr_list = upr;
3239         }
3240         return STATUS_SUCCESS;
3241 }
3242
3243 static int slic_upr_request(struct adapter *adapter,
3244                      u32 upr_request,
3245                      u32 upr_data,
3246                      u32 upr_data_h,
3247                      u32 upr_buffer, u32 upr_buffer_h)
3248 {
3249         int status;
3250
3251         spin_lock_irqsave(&adapter->upr_lock.lock, adapter->upr_lock.flags);
3252         status = slic_upr_queue_request(adapter,
3253                                         upr_request,
3254                                         upr_data,
3255                                         upr_data_h, upr_buffer, upr_buffer_h);
3256         if (status != STATUS_SUCCESS) {
3257                 spin_unlock_irqrestore(&adapter->upr_lock.lock,
3258                                         adapter->upr_lock.flags);
3259                 return status;
3260         }
3261         slic_upr_start(adapter);
3262         spin_unlock_irqrestore(&adapter->upr_lock.lock,
3263                                 adapter->upr_lock.flags);
3264         return STATUS_PENDING;
3265 }
3266
3267 static void slic_upr_request_complete(struct adapter *adapter, u32 isr)
3268 {
3269         struct sliccard *card = adapter->card;
3270         struct slic_upr *upr;
3271
3272 /*    if (card->dump_requested) {
3273         DBG_MSG("ENTER slic_upr_request_complete Dump in progress ISR[%x]\n",
3274                 isr);
3275       } */
3276         spin_lock_irqsave(&adapter->upr_lock.lock, adapter->upr_lock.flags);
3277         upr = adapter->upr_list;
3278         if (!upr) {
3279                 ASSERT(0);
3280                 spin_unlock_irqrestore(&adapter->upr_lock.lock,
3281                                         adapter->upr_lock.flags);
3282                 return;
3283         }
3284         adapter->upr_list = upr->next;
3285         upr->next = NULL;
3286         adapter->upr_busy = 0;
3287         ASSERT(adapter->port == upr->adapter);
3288         switch (upr->upr_request) {
3289         case SLIC_UPR_STATS:
3290                 {
3291 #if SLIC_GET_STATS_ENABLED
3292                         struct slic_stats *slicstats =
3293                             (struct slic_stats *) &adapter->pshmem->inicstats;
3294                         struct slic_stats *newstats = slicstats;
3295                         struct slic_stats  *old = &adapter->inicstats_prev;
3296                         struct slicnet_stats *stst = &adapter->slic_stats;
3297 #endif
3298                         if (isr & ISR_UPCERR) {
3299                                 DBG_ERROR
3300                                     ("SLIC_UPR_STATS command failed isr[%x]\n",
3301                                      isr);
3302
3303                                 break;
3304                         }
3305 #if SLIC_GET_STATS_ENABLED
3306 /*                      DBG_MSG ("slicoss: %s rcv %lx:%lx:%lx:%lx:%lx %lx %lx "
3307                                 "xmt %lx:%lx:%lx:%lx:%lx %lx %lx\n",
3308                                  __func__,
3309                              slicstats->rcv_unicasts100,
3310                              slicstats->rcv_bytes100,
3311                              slicstats->rcv_bytes100,
3312                              slicstats->rcv_tcp_bytes100,
3313                              slicstats->rcv_tcp_segs100,
3314                              slicstats->rcv_other_error100,
3315                              slicstats->rcv_drops100,
3316                              slicstats->xmit_unicasts100,
3317                              slicstats->xmit_bytes100,
3318                              slicstats->xmit_bytes100,
3319                              slicstats->xmit_tcp_bytes100,
3320                              slicstats->xmit_tcp_segs100,
3321                              slicstats->xmit_other_error100,
3322                              slicstats->xmit_collisions100);*/
3323                         UPDATE_STATS_GB(stst->tcp.xmit_tcp_segs,
3324                                         newstats->xmit_tcp_segs_gb,
3325                                         old->xmit_tcp_segs_gb);
3326
3327                         UPDATE_STATS_GB(stst->tcp.xmit_tcp_bytes,
3328                                         newstats->xmit_tcp_bytes_gb,
3329                                         old->xmit_tcp_bytes_gb);
3330
3331                         UPDATE_STATS_GB(stst->tcp.rcv_tcp_segs,
3332                                         newstats->rcv_tcp_segs_gb,
3333                                         old->rcv_tcp_segs_gb);
3334
3335                         UPDATE_STATS_GB(stst->tcp.rcv_tcp_bytes,
3336                                         newstats->rcv_tcp_bytes_gb,
3337                                         old->rcv_tcp_bytes_gb);
3338
3339                         UPDATE_STATS_GB(stst->iface.xmt_bytes,
3340                                         newstats->xmit_bytes_gb,
3341                                         old->xmit_bytes_gb);
3342
3343                         UPDATE_STATS_GB(stst->iface.xmt_ucast,
3344                                         newstats->xmit_unicasts_gb,
3345                                         old->xmit_unicasts_gb);
3346
3347                         UPDATE_STATS_GB(stst->iface.rcv_bytes,
3348                                         newstats->rcv_bytes_gb,
3349                                         old->rcv_bytes_gb);
3350
3351                         UPDATE_STATS_GB(stst->iface.rcv_ucast,
3352                                         newstats->rcv_unicasts_gb,
3353                                         old->rcv_unicasts_gb);
3354
3355                         UPDATE_STATS_GB(stst->iface.xmt_errors,
3356                                         newstats->xmit_collisions_gb,
3357                                         old->xmit_collisions_gb);
3358
3359                         UPDATE_STATS_GB(stst->iface.xmt_errors,
3360                                         newstats->xmit_excess_collisions_gb,
3361                                         old->xmit_excess_collisions_gb);
3362
3363                         UPDATE_STATS_GB(stst->iface.xmt_errors,
3364                                         newstats->xmit_other_error_gb,
3365                                         old->xmit_other_error_gb);
3366
3367                         UPDATE_STATS_GB(stst->iface.rcv_errors,
3368                                         newstats->rcv_other_error_gb,
3369                                         old->rcv_other_error_gb);
3370
3371                         UPDATE_STATS_GB(stst->iface.rcv_discards,
3372                                         newstats->rcv_drops_gb,
3373                                         old->rcv_drops_gb);
3374
3375                         if (newstats->rcv_drops_gb > old->rcv_drops_gb) {
3376                                 adapter->rcv_drops +=
3377                                     (newstats->rcv_drops_gb -
3378                                      old->rcv_drops_gb);
3379                         }
3380                         memcpy(old, newstats, sizeof(struct slic_stats));
3381 #endif
3382                         break;
3383                 }
3384         case SLIC_UPR_RLSR:
3385                 slic_link_upr_complete(adapter, isr);
3386                 break;
3387         case SLIC_UPR_RCONFIG:
3388                 break;
3389         case SLIC_UPR_RPHY:
3390                 ASSERT(0);
3391                 break;
3392         case SLIC_UPR_ENLB:
3393                 ASSERT(0);
3394                 break;
3395         case SLIC_UPR_ENCT:
3396                 ASSERT(0);
3397                 break;
3398         case SLIC_UPR_PDWN:
3399                 ASSERT(0);
3400                 break;
3401         case SLIC_UPR_PING:
3402                 card->pingstatus |= (isr & ISR_PINGDSMASK);
3403                 break;
3404 #if SLIC_DUMP_ENABLED
3405         case SLIC_UPR_DUMP:
3406                 card->dumpstatus |= (isr & ISR_UPCMASK);
3407                 break;
3408 #endif
3409         default:
3410                 ASSERT(0);
3411         }
3412         kfree(upr);
3413         slic_upr_start(adapter);
3414         spin_unlock_irqrestore(&adapter->upr_lock.lock,
3415                                 adapter->upr_lock.flags);
3416 }
3417
3418 static void slic_upr_start(struct adapter *adapter)
3419 {
3420         struct slic_upr *upr;
3421         __iomem struct slic_regs *slic_regs = adapter->slic_regs;
3422 /*
3423     char * ptr1;
3424     char * ptr2;
3425     uint cmdoffset;
3426 */
3427         upr = adapter->upr_list;
3428         if (!upr)
3429                 return;
3430         if (adapter->upr_busy)
3431                 return;
3432         adapter->upr_busy = 1;
3433
3434         switch (upr->upr_request) {
3435         case SLIC_UPR_STATS:
3436                 if (upr->upr_data_h == 0) {
3437                         WRITE_REG(slic_regs->slic_stats, upr->upr_data, FLUSH);
3438                 } else {
3439                         WRITE_REG64(adapter,
3440                                     slic_regs->slic_stats64,
3441                                     upr->upr_data,
3442                                     slic_regs->slic_addr_upper,
3443                                     upr->upr_data_h, FLUSH);
3444                 }
3445                 break;
3446
3447         case SLIC_UPR_RLSR:
3448                 WRITE_REG64(adapter,
3449                             slic_regs->slic_rlsr,
3450                             upr->upr_data,
3451                             slic_regs->slic_addr_upper, upr->upr_data_h, FLUSH);
3452                 break;
3453
3454         case SLIC_UPR_RCONFIG:
3455                 DBG_MSG("%s SLIC_UPR_RCONFIG!!!!\n", __func__);
3456                 DBG_MSG("WRITE_REG64 adapter[%p]\n"
3457                         "    a->slic_regs[%p] slic_regs[%p]\n"
3458                         "    &slic_rconfig[%p] &slic_addr_upper[%p]\n"
3459                         "    upr[%p]\n"
3460                         "    uprdata[%x] uprdatah[%x]\n",
3461                         adapter, adapter->slic_regs, slic_regs,
3462                         &slic_regs->slic_rconfig, &slic_regs->slic_addr_upper,
3463                         upr, upr->upr_data, upr->upr_data_h);
3464                 WRITE_REG64(adapter,
3465                             slic_regs->slic_rconfig,
3466                             upr->upr_data,
3467                             slic_regs->slic_addr_upper, upr->upr_data_h, FLUSH);
3468                 break;
3469 #if SLIC_DUMP_ENABLED
3470         case SLIC_UPR_DUMP:
3471 #if 0
3472                 DBG_MSG("%s SLIC_UPR_DUMP!!!!\n", __func__);
3473                 DBG_MSG("WRITE_REG64 adapter[%p]\n"
3474                          "    upr_buffer[%x]   upr_bufferh[%x]\n"
3475                          "    upr_data[%x]     upr_datah[%x]\n"
3476                          "    cmdbuff[%p] cmdbuffP[%p]\n"
3477                          "    dumpbuff[%p] dumpbuffP[%p]\n",
3478                          adapter, upr->upr_buffer, upr->upr_buffer_h,
3479                          upr->upr_data, upr->upr_data_h,
3480                          adapter->card->cmdbuffer,
3481                          (void *)adapter->card->cmdbuffer_phys,
3482                          adapter->card->dumpbuffer, (
3483                          void *)adapter->card->dumpbuffer_phys);
3484
3485                 ptr1 = (char *)slic_regs;
3486                 ptr2 = (char *)(&slic_regs->slic_dump_cmd);
3487                 cmdoffset = ptr2 - ptr1;
3488                 DBG_MSG("slic_dump_cmd register offset [%x]\n", cmdoffset);
3489 #endif
3490                 if (upr->upr_buffer || upr->upr_buffer_h) {
3491                         WRITE_REG64(adapter,
3492                                     slic_regs->slic_dump_data,
3493                                     upr->upr_buffer,
3494                                     slic_regs->slic_addr_upper,
3495                                     upr->upr_buffer_h, FLUSH);
3496                 }
3497                 WRITE_REG64(adapter,
3498                             slic_regs->slic_dump_cmd,
3499                             upr->upr_data,
3500                             slic_regs->slic_addr_upper, upr->upr_data_h, FLUSH);
3501                 break;
3502 #endif
3503         case SLIC_UPR_PING:
3504                 WRITE_REG(slic_regs->slic_ping, 1, FLUSH);
3505                 break;
3506         default:
3507                 ASSERT(0);
3508         }
3509 }
3510
3511 static void slic_link_upr_complete(struct adapter *adapter, u32 isr)
3512 {
3513         u32 linkstatus = adapter->pshmem->linkstatus;
3514         uint linkup;
3515         unsigned char linkspeed;
3516         unsigned char linkduplex;
3517
3518         DBG_MSG("%s: %s ISR[%x] linkstatus[%x]\n   adapter[%p](%d)\n",
3519                 __func__, adapter->netdev->name, isr, linkstatus, adapter,
3520                 adapter->cardindex);
3521
3522         if ((isr & ISR_UPCERR) || (isr & ISR_UPCBSY)) {
3523                 struct slic_shmem *pshmem;
3524
3525                 pshmem = (struct slic_shmem *)adapter->phys_shmem;
3526 #if defined(CONFIG_X86_64)
3527                 slic_upr_queue_request(adapter,
3528                                        SLIC_UPR_RLSR,
3529                                        SLIC_GET_ADDR_LOW(&pshmem->linkstatus),
3530                                        SLIC_GET_ADDR_HIGH(&pshmem->linkstatus),
3531                                        0, 0);
3532 #elif defined(CONFIG_X86)
3533                 slic_upr_queue_request(adapter,
3534                                        SLIC_UPR_RLSR,
3535                                        (u32) &pshmem->linkstatus,
3536                                        SLIC_GET_ADDR_HIGH(pshmem), 0, 0);
3537 #else
3538                 Stop Compilation;
3539 #endif
3540                 return;
3541         }
3542         if (adapter->state != ADAPT_UP)
3543                 return;
3544
3545         ASSERT((adapter->devid == SLIC_1GB_DEVICE_ID)
3546                || (adapter->devid == SLIC_2GB_DEVICE_ID));
3547
3548         linkup = linkstatus & GIG_LINKUP ? LINK_UP : LINK_DOWN;
3549         if (linkstatus & GIG_SPEED_1000) {
3550                 linkspeed = LINK_1000MB;
3551                 DBG_MSG("slicoss: %s (%s) GIGABIT Speed==1000MB  ",
3552                         __func__, adapter->netdev->name);
3553         } else if (linkstatus & GIG_SPEED_100) {
3554                 linkspeed = LINK_100MB;
3555                 DBG_MSG("slicoss: %s (%s) GIGABIT Speed==100MB  ", __func__,
3556                         adapter->netdev->name);
3557         } else {
3558                 linkspeed = LINK_10MB;
3559                 DBG_MSG("slicoss: %s (%s) GIGABIT Speed==10MB  ", __func__,
3560                         adapter->netdev->name);
3561         }
3562         if (linkstatus & GIG_FULLDUPLEX) {
3563                 linkduplex = LINK_FULLD;
3564                 DBG_MSG(" Duplex == FULL\n");
3565         } else {
3566                 linkduplex = LINK_HALFD;
3567                 DBG_MSG(" Duplex == HALF\n");
3568         }
3569
3570         if ((adapter->linkstate == LINK_DOWN) && (linkup == LINK_DOWN)) {
3571                 DBG_MSG("slicoss: %s (%s) physport(%d) link still down\n",
3572                         __func__, adapter->netdev->name, adapter->physport);
3573                 return;
3574         }
3575
3576         /* link up event, but nothing has changed */
3577         if ((adapter->linkstate == LINK_UP) &&
3578             (linkup == LINK_UP) &&
3579             (adapter->linkspeed == linkspeed) &&
3580             (adapter->linkduplex == linkduplex)) {
3581                 DBG_MSG("slicoss: %s (%s) port(%d) link still up\n",
3582                         __func__, adapter->netdev->name, adapter->physport);
3583                 return;
3584         }
3585
3586         /* link has changed at this point */
3587
3588         /* link has gone from up to down */
3589         if (linkup == LINK_DOWN) {
3590                 adapter->linkstate = LINK_DOWN;
3591                 DBG_MSG("slicoss: %s %d LinkDown!\n", __func__,
3592                         adapter->physport);
3593                 return;
3594         }
3595
3596         /* link has gone from down to up */
3597         adapter->linkspeed = linkspeed;
3598         adapter->linkduplex = linkduplex;
3599
3600         if (adapter->linkstate != LINK_UP) {
3601                 /* setup the mac */
3602                 DBG_MSG("%s call slic_config_set\n", __func__);
3603                 slic_config_set(adapter, TRUE);
3604                 adapter->linkstate = LINK_UP;
3605                 DBG_MSG("\n(%s) Link UP: CALL slic_if_start_queue",
3606                         adapter->netdev->name);
3607                 slic_if_start_queue(adapter);
3608         }
3609 #if 1
3610         switch (linkspeed) {
3611         case LINK_1000MB:
3612                 DBG_MSG
3613                     ("\n(%s) LINK UP!: GIGABIT SPEED == 1000MB  duplex[%x]\n",
3614                      adapter->netdev->name, adapter->linkduplex);
3615                 break;
3616         case LINK_100MB:
3617                 DBG_MSG("\n(%s) LINK UP!: SPEED == 100MB  duplex[%x]\n",
3618                         adapter->netdev->name, adapter->linkduplex);
3619                 break;
3620         default:
3621                 DBG_MSG("\n(%s) LINK UP!: SPEED == 10MB  duplex[%x]\n",
3622                         adapter->netdev->name, adapter->linkduplex);
3623                 break;
3624         }
3625 #endif
3626 }
3627
3628 /*
3629  *  this is here to checksum the eeprom, there is some ucode bug
3630  *  which prevens us from using the ucode result.
3631  *  remove this once ucode is fixed.
3632  */
3633 static ushort slic_eeprom_cksum(char *m, int len)
3634 {
3635 #define ADDCARRY(x)  (x > 65535 ? x -= 65535 : x)
3636 #define REDUCE {l_util.l = sum; sum = l_util.s[0] + l_util.s[1]; ADDCARRY(sum);\
3637                 }
3638
3639         u16 *w;
3640         u32 sum = 0;
3641         u32 byte_swapped = 0;
3642         u32 w_int;
3643
3644         union {
3645                 char c[2];
3646                 ushort s;
3647         } s_util;
3648
3649         union {
3650                 ushort s[2];
3651                 int l;
3652         } l_util;
3653
3654         l_util.l = 0;
3655         s_util.s = 0;
3656
3657         w = (u16 *)m;
3658 #ifdef CONFIG_X86_64
3659         w_int = (u32) ((ulong) w & 0x00000000FFFFFFFF);
3660 #else
3661         w_int = (u32) (w);
3662 #endif
3663         if ((1 & w_int) && (len > 0)) {
3664                 REDUCE;
3665                 sum <<= 8;
3666                 s_util.c[0] = *(unsigned char *)w;
3667                 w = (u16 *)((char *)w + 1);
3668                 len--;
3669                 byte_swapped = 1;
3670         }
3671
3672         /* Unroll the loop to make overhead from branches &c small. */
3673         while ((len -= 32) >= 0) {
3674                 sum += w[0];
3675                 sum += w[1];
3676                 sum += w[2];
3677                 sum += w[3];
3678                 sum += w[4];
3679                 sum += w[5];
3680                 sum += w[6];
3681                 sum += w[7];
3682                 sum += w[8];
3683                 sum += w[9];
3684                 sum += w[10];
3685                 sum += w[11];
3686                 sum += w[12];
3687                 sum += w[13];
3688                 sum += w[14];
3689                 sum += w[15];
3690                 w = (u16 *)((ulong) w + 16);    /* verify */
3691         }
3692         len += 32;
3693         while ((len -= 8) >= 0) {
3694                 sum += w[0];
3695                 sum += w[1];
3696                 sum += w[2];
3697                 sum += w[3];
3698                 w = (u16 *)((ulong) w + 4);     /* verify */
3699         }
3700         len += 8;
3701         if (len != 0 || byte_swapped != 0) {
3702                 REDUCE;
3703                 while ((len -= 2) >= 0)
3704                         sum += *w++;    /* verify */
3705                 if (byte_swapped) {
3706                         REDUCE;
3707                         sum <<= 8;
3708                         byte_swapped = 0;
3709                         if (len == -1) {
3710                                 s_util.c[1] = *(char *) w;
3711                                 sum += s_util.s;
3712                                 len = 0;
3713                         } else {
3714                                 len = -1;
3715                         }
3716
3717                 } else if (len == -1) {
3718                         s_util.c[0] = *(char *) w;
3719                 }
3720
3721                 if (len == -1) {
3722                         s_util.c[1] = 0;
3723                         sum += s_util.s;
3724                 }
3725         }
3726         REDUCE;
3727         return (ushort) sum;
3728 }
3729
3730 static int slic_rspqueue_init(struct adapter *adapter)
3731 {
3732         int i;
3733         struct slic_rspqueue *rspq = &adapter->rspqueue;
3734         __iomem struct slic_regs *slic_regs = adapter->slic_regs;
3735         u32 paddrh = 0;
3736
3737         DBG_MSG("slicoss: %s (%s) ENTER adapter[%p]\n", __func__,
3738                 adapter->netdev->name, adapter);
3739         ASSERT(adapter->state == ADAPT_DOWN);
3740         memset(rspq, 0, sizeof(struct slic_rspqueue));
3741
3742         rspq->num_pages = SLIC_RSPQ_PAGES_GB;
3743
3744         for (i = 0; i < rspq->num_pages; i++) {
3745                 rspq->vaddr[i] =
3746                     pci_alloc_consistent(adapter->pcidev, PAGE_SIZE,
3747                                          &rspq->paddr[i]);
3748                 if (!rspq->vaddr[i]) {
3749                         DBG_ERROR
3750                             ("rspqueue_init_failed  pci_alloc_consistent\n");
3751                         slic_rspqueue_free(adapter);
3752                         return STATUS_FAILURE;
3753                 }
3754 #ifndef CONFIG_X86_64
3755                 ASSERT(((u32) rspq->vaddr[i] & 0xFFFFF000) ==
3756                        (u32) rspq->vaddr[i]);
3757                 ASSERT(((u32) rspq->paddr[i] & 0xFFFFF000) ==
3758                        (u32) rspq->paddr[i]);
3759 #endif
3760                 memset(rspq->vaddr[i], 0, PAGE_SIZE);
3761 /*              DBG_MSG("slicoss: %s UPLOAD RSPBUFF Page pageix[%x] paddr[%p] "
3762                         "vaddr[%p]\n",
3763                         __func__, i, (void *)rspq->paddr[i], rspq->vaddr[i]); */
3764
3765                 if (paddrh == 0) {
3766                         WRITE_REG(slic_regs->slic_rbar,
3767                                   (rspq->paddr[i] | SLIC_RSPQ_BUFSINPAGE),
3768                                   DONT_FLUSH);
3769                 } else {
3770                         WRITE_REG64(adapter,
3771                                     slic_regs->slic_rbar64,
3772                                     (rspq->paddr[i] | SLIC_RSPQ_BUFSINPAGE),
3773                                     slic_regs->slic_addr_upper,
3774                                     paddrh, DONT_FLUSH);
3775                 }
3776         }
3777         rspq->offset = 0;
3778         rspq->pageindex = 0;
3779         rspq->rspbuf = (struct slic_rspbuf *)rspq->vaddr[0];
3780         DBG_MSG("slicoss: %s (%s) EXIT adapter[%p]\n", __func__,
3781                 adapter->netdev->name, adapter);
3782         return STATUS_SUCCESS;
3783 }
3784
3785 static int slic_rspqueue_reset(struct adapter *adapter)
3786 {
3787         struct slic_rspqueue *rspq = &adapter->rspqueue;
3788
3789         DBG_MSG("slicoss: %s (%s) ENTER adapter[%p]\n", __func__,
3790                 adapter->netdev->name, adapter);
3791         ASSERT(adapter->state == ADAPT_DOWN);
3792         ASSERT(rspq);
3793
3794         DBG_MSG("slicoss: Nothing to do. rspq[%p]\n"
3795                 "                             offset[%x]\n"
3796                 "                             pageix[%x]\n"
3797                 "                             rspbuf[%p]\n",
3798                 rspq, rspq->offset, rspq->pageindex, rspq->rspbuf);
3799
3800         DBG_MSG("slicoss: %s (%s) EXIT adapter[%p]\n", __func__,
3801                 adapter->netdev->name, adapter);
3802         return STATUS_SUCCESS;
3803 }
3804
3805 static void slic_rspqueue_free(struct adapter *adapter)
3806 {
3807         int i;
3808         struct slic_rspqueue *rspq = &adapter->rspqueue;
3809
3810         DBG_MSG("slicoss: %s adapter[%p] port %d rspq[%p] FreeRSPQ\n",
3811                 __func__, adapter, adapter->physport, rspq);
3812         for (i = 0; i < rspq->num_pages; i++) {
3813                 if (rspq->vaddr[i]) {
3814                         DBG_MSG
3815                             ("slicoss:  pci_free_consistent rspq->vaddr[%p] \
3816                             paddr[%p]\n",
3817                              rspq->vaddr[i], (void *) rspq->paddr[i]);
3818                         pci_free_consistent(adapter->pcidev, PAGE_SIZE,
3819                                             rspq->vaddr[i], rspq->paddr[i]);
3820                 }
3821                 rspq->vaddr[i] = NULL;
3822                 rspq->paddr[i] = 0;
3823         }
3824         rspq->offset = 0;
3825         rspq->pageindex = 0;
3826         rspq->rspbuf = NULL;
3827 }
3828
3829 static struct slic_rspbuf *slic_rspqueue_getnext(struct adapter *adapter)
3830 {
3831         struct slic_rspqueue *rspq = &adapter->rspqueue;
3832         struct slic_rspbuf *buf;
3833
3834         if (!(rspq->rspbuf->status))
3835                 return NULL;
3836
3837         buf = rspq->rspbuf;
3838 #ifndef CONFIG_X86_64
3839         ASSERT((buf->status & 0xFFFFFFE0) == 0);
3840 #endif
3841         ASSERT(buf->hosthandle);
3842         if (++rspq->offset < SLIC_RSPQ_BUFSINPAGE) {
3843                 rspq->rspbuf++;
3844 #ifndef CONFIG_X86_64
3845                 ASSERT(((u32) rspq->rspbuf & 0xFFFFFFE0) ==
3846                        (u32) rspq->rspbuf);
3847 #endif
3848         } else {
3849                 ASSERT(rspq->offset == SLIC_RSPQ_BUFSINPAGE);
3850                 WRITE_REG64(adapter,
3851                             adapter->slic_regs->slic_rbar64,
3852                             (rspq->
3853                              paddr[rspq->pageindex] | SLIC_RSPQ_BUFSINPAGE),
3854                             adapter->slic_regs->slic_addr_upper, 0, DONT_FLUSH);
3855                 rspq->pageindex = (++rspq->pageindex) % rspq->num_pages;
3856                 rspq->offset = 0;
3857                 rspq->rspbuf = (struct slic_rspbuf *)
3858                                                 rspq->vaddr[rspq->pageindex];
3859 #ifndef CONFIG_X86_64
3860                 ASSERT(((u32) rspq->rspbuf & 0xFFFFF000) ==
3861                        (u32) rspq->rspbuf);
3862 #endif
3863         }
3864 #ifndef CONFIG_X86_64
3865         ASSERT(((u32) buf & 0xFFFFFFE0) == (u32) buf);
3866 #endif
3867         return buf;
3868 }
3869
3870 static void slic_cmdqmem_init(struct adapter *adapter)
3871 {
3872         struct slic_cmdqmem *cmdqmem = &adapter->cmdqmem;
3873
3874         memset(cmdqmem, 0, sizeof(struct slic_cmdqmem));
3875 }
3876
3877 static void slic_cmdqmem_free(struct adapter *adapter)
3878 {
3879         struct slic_cmdqmem *cmdqmem = &adapter->cmdqmem;
3880         int i;
3881
3882         DBG_MSG("slicoss: (%s) adapter[%p] port %d rspq[%p] Free CMDQ Memory\n",
3883                 __func__, adapter, adapter->physport, cmdqmem);
3884         for (i = 0; i < SLIC_CMDQ_MAXPAGES; i++) {
3885                 if (cmdqmem->pages[i]) {
3886                         DBG_MSG("slicoss: %s Deallocate page  CmdQPage[%p]\n",
3887                                 __func__, (void *) cmdqmem->pages[i]);
3888                         pci_free_consistent(adapter->pcidev,
3889                                             PAGE_SIZE,
3890                                             (void *) cmdqmem->pages[i],
3891                                             cmdqmem->dma_pages[i]);
3892                 }
3893         }
3894         memset(cmdqmem, 0, sizeof(struct slic_cmdqmem));
3895 }
3896
3897 static u32 *slic_cmdqmem_addpage(struct adapter *adapter)
3898 {
3899         struct slic_cmdqmem *cmdqmem = &adapter->cmdqmem;
3900         u32 *pageaddr;
3901
3902         if (cmdqmem->pagecnt >= SLIC_CMDQ_MAXPAGES)
3903                 return NULL;
3904         pageaddr = pci_alloc_consistent(adapter->pcidev,
3905                                         PAGE_SIZE,
3906                                         &cmdqmem->dma_pages[cmdqmem->pagecnt]);
3907         if (!pageaddr)
3908                 return NULL;
3909 #ifndef CONFIG_X86_64
3910         ASSERT(((u32) pageaddr & 0xFFFFF000) == (u32) pageaddr);
3911 #endif
3912         cmdqmem->pages[cmdqmem->pagecnt] = pageaddr;
3913         cmdqmem->pagecnt++;
3914         return pageaddr;
3915 }
3916
3917 static int slic_cmdq_init(struct adapter *adapter)
3918 {
3919         int i;
3920         u32 *pageaddr;
3921
3922         DBG_MSG("slicoss: %s ENTER adapter[%p]\n", __func__, adapter);
3923         ASSERT(adapter->state == ADAPT_DOWN);
3924         memset(&adapter->cmdq_all, 0, sizeof(struct slic_cmdqueue));
3925         memset(&adapter->cmdq_free, 0, sizeof(struct slic_cmdqueue));
3926         memset(&adapter->cmdq_done, 0, sizeof(struct slic_cmdqueue));
3927         spin_lock_init(&adapter->cmdq_all.lock.lock);
3928         spin_lock_init(&adapter->cmdq_free.lock.lock);
3929         spin_lock_init(&adapter->cmdq_done.lock.lock);
3930         slic_cmdqmem_init(adapter);
3931         adapter->slic_handle_ix = 1;
3932         for (i = 0; i < SLIC_CMDQ_INITPAGES; i++) {
3933                 pageaddr = slic_cmdqmem_addpage(adapter);
3934 #ifndef CONFIG_X86_64
3935                 ASSERT(((u32) pageaddr & 0xFFFFF000) == (u32) pageaddr);
3936 #endif
3937                 if (!pageaddr) {
3938                         slic_cmdq_free(adapter);
3939                         return STATUS_FAILURE;
3940                 }
3941                 slic_cmdq_addcmdpage(adapter, pageaddr);
3942         }
3943         adapter->slic_handle_ix = 1;
3944         DBG_MSG("slicoss: %s reset slic_handle_ix to ONE\n", __func__);
3945
3946         return STATUS_SUCCESS;
3947 }
3948
3949 static void slic_cmdq_free(struct adapter *adapter)
3950 {
3951         struct slic_hostcmd *cmd;
3952
3953         DBG_MSG("slicoss: %s adapter[%p] port %d FreeCommandsFrom CMDQ\n",
3954                 __func__, adapter, adapter->physport);
3955         cmd = adapter->cmdq_all.head;
3956         while (cmd) {
3957                 if (cmd->busy) {
3958                         struct sk_buff *tempskb;
3959
3960                         tempskb = cmd->skb;
3961                         if (tempskb) {
3962                                 cmd->skb = NULL;
3963                                 dev_kfree_skb_irq(tempskb);
3964                         }
3965                 }
3966                 cmd = cmd->next_all;
3967         }
3968         memset(&adapter->cmdq_all, 0, sizeof(struct slic_cmdqueue));
3969         memset(&adapter->cmdq_free, 0, sizeof(struct slic_cmdqueue));
3970         memset(&adapter->cmdq_done, 0, sizeof(struct slic_cmdqueue));
3971         slic_cmdqmem_free(adapter);
3972 }
3973
3974 static void slic_cmdq_reset(struct adapter *adapter)
3975 {
3976         struct slic_hostcmd *hcmd;
3977         struct sk_buff *skb;
3978         u32 outstanding;
3979
3980         DBG_MSG("%s ENTER adapter[%p]\n", __func__, adapter);
3981         spin_lock_irqsave(&adapter->cmdq_free.lock.lock,
3982                         adapter->cmdq_free.lock.flags);
3983         spin_lock_irqsave(&adapter->cmdq_done.lock.lock,
3984                         adapter->cmdq_done.lock.flags);
3985         outstanding = adapter->cmdq_all.count - adapter->cmdq_done.count;
3986         outstanding -= adapter->cmdq_free.count;
3987         hcmd = adapter->cmdq_all.head;
3988         while (hcmd) {
3989                 if (hcmd->busy) {
3990                         skb = hcmd->skb;
3991                         ASSERT(skb);
3992                         DBG_MSG("slicoss: %s hcmd[%p] skb[%p] ", __func__,
3993                                 hcmd, skb);
3994                         hcmd->busy = 0;
3995                         hcmd->skb = NULL;
3996                         DBG_MSG(" Free SKB\n");
3997                         dev_kfree_skb_irq(skb);
3998                 }
3999                 hcmd = hcmd->next_all;
4000         }
4001         adapter->cmdq_free.count = 0;
4002         adapter->cmdq_free.head = NULL;
4003         adapter->cmdq_free.tail = NULL;
4004         adapter->cmdq_done.count = 0;
4005         adapter->cmdq_done.head = NULL;
4006         adapter->cmdq_done.tail = NULL;
4007         adapter->cmdq_free.head = adapter->cmdq_all.head;
4008         hcmd = adapter->cmdq_all.head;
4009         while (hcmd) {
4010                 adapter->cmdq_free.count++;
4011                 hcmd->next = hcmd->next_all;
4012                 hcmd = hcmd->next_all;
4013         }
4014         if (adapter->cmdq_free.count != adapter->cmdq_all.count) {
4015                 DBG_ERROR("%s free_count %d != all count %d\n", __func__,
4016                           adapter->cmdq_free.count, adapter->cmdq_all.count);
4017         }
4018         spin_unlock_irqrestore(&adapter->cmdq_done.lock.lock,
4019                                 adapter->cmdq_done.lock.flags);
4020         spin_unlock_irqrestore(&adapter->cmdq_free.lock.lock,
4021                                 adapter->cmdq_free.lock.flags);
4022         DBG_MSG("%s EXIT adapter[%p]\n", __func__, adapter);
4023 }
4024
4025 static void slic_cmdq_addcmdpage(struct adapter *adapter, u32 *page)
4026 {
4027         struct slic_hostcmd *cmd;
4028         struct slic_hostcmd *prev;
4029         struct slic_hostcmd *tail;
4030         struct slic_cmdqueue *cmdq;
4031         int cmdcnt;
4032         void *cmdaddr;
4033         ulong phys_addr;
4034         u32 phys_addrl;
4035         u32 phys_addrh;
4036         struct slic_handle *pslic_handle;
4037
4038         cmdaddr = page;
4039         cmd = (struct slic_hostcmd *)cmdaddr;
4040 /*  DBG_MSG("CMDQ Page addr[%p] ix[%d] pfree[%p]\n", cmdaddr, slic_handle_ix,
4041     adapter->pfree_slic_handles); */
4042         cmdcnt = 0;
4043
4044         phys_addr = virt_to_bus((void *)page);
4045         phys_addrl = SLIC_GET_ADDR_LOW(phys_addr);
4046         phys_addrh = SLIC_GET_ADDR_HIGH(phys_addr);
4047
4048         prev = NULL;
4049         tail = cmd;
4050         while ((cmdcnt < SLIC_CMDQ_CMDSINPAGE) &&
4051                (adapter->slic_handle_ix < 256)) {
4052                 /* Allocate and initialize a SLIC_HANDLE for this command */
4053                 SLIC_GET_SLIC_HANDLE(adapter, pslic_handle);
4054                 if (pslic_handle == NULL)
4055                         ASSERT(0);
4056                 ASSERT(pslic_handle ==
4057                        &adapter->slic_handles[pslic_handle->token.
4058                                               handle_index]);
4059                 pslic_handle->type = SLIC_HANDLE_CMD;
4060                 pslic_handle->address = (void *) cmd;
4061                 pslic_handle->offset = (ushort) adapter->slic_handle_ix++;
4062                 pslic_handle->other_handle = NULL;
4063                 pslic_handle->next = NULL;
4064
4065                 cmd->pslic_handle = pslic_handle;
4066                 cmd->cmd64.hosthandle = pslic_handle->token.handle_token;
4067                 cmd->busy = FALSE;
4068                 cmd->paddrl = phys_addrl;
4069                 cmd->paddrh = phys_addrh;
4070                 cmd->next_all = prev;
4071                 cmd->next = prev;
4072                 prev = cmd;
4073                 phys_addrl += SLIC_HOSTCMD_SIZE;
4074                 cmdaddr += SLIC_HOSTCMD_SIZE;
4075
4076                 cmd = (struct slic_hostcmd *)cmdaddr;
4077                 cmdcnt++;
4078         }
4079
4080         cmdq = &adapter->cmdq_all;
4081         cmdq->count += cmdcnt;  /*  SLIC_CMDQ_CMDSINPAGE;   mooktodo */
4082         tail->next_all = cmdq->head;
4083         ASSERT(VALID_ADDRESS(prev));
4084         cmdq->head = prev;
4085         cmdq = &adapter->cmdq_free;
4086         spin_lock_irqsave(&cmdq->lock.lock, cmdq->lock.flags);
4087         cmdq->count += cmdcnt;  /*  SLIC_CMDQ_CMDSINPAGE;   mooktodo */
4088         tail->next = cmdq->head;
4089         ASSERT(VALID_ADDRESS(prev));
4090         cmdq->head = prev;
4091         spin_unlock_irqrestore(&cmdq->lock.lock, cmdq->lock.flags);
4092 }
4093
4094 static struct slic_hostcmd *slic_cmdq_getfree(struct adapter *adapter)
4095 {
4096         struct slic_cmdqueue *cmdq = &adapter->cmdq_free;
4097         struct slic_hostcmd *cmd = NULL;
4098
4099 lock_and_retry:
4100         spin_lock_irqsave(&cmdq->lock.lock, cmdq->lock.flags);
4101 retry:
4102         cmd = cmdq->head;
4103         if (cmd) {
4104                 cmdq->head = cmd->next;
4105                 cmdq->count--;
4106                 spin_unlock_irqrestore(&cmdq->lock.lock, cmdq->lock.flags);
4107         } else {
4108                 slic_cmdq_getdone(adapter);
4109                 cmd = cmdq->head;
4110                 if (cmd) {
4111                         goto retry;
4112                 } else {
4113                         u32 *pageaddr;
4114
4115                         spin_unlock_irqrestore(&cmdq->lock.lock,
4116                                                 cmdq->lock.flags);
4117                         pageaddr = slic_cmdqmem_addpage(adapter);
4118                         if (pageaddr) {
4119                                 slic_cmdq_addcmdpage(adapter, pageaddr);
4120                                 goto lock_and_retry;
4121                         }
4122                 }
4123         }
4124         return cmd;
4125 }
4126
4127 static void slic_cmdq_getdone(struct adapter *adapter)
4128 {
4129         struct slic_cmdqueue *done_cmdq = &adapter->cmdq_done;
4130         struct slic_cmdqueue *free_cmdq = &adapter->cmdq_free;
4131
4132         ASSERT(free_cmdq->head == NULL);
4133         spin_lock_irqsave(&done_cmdq->lock.lock, done_cmdq->lock.flags);
4134         ASSERT(VALID_ADDRESS(done_cmdq->head));
4135
4136         free_cmdq->head = done_cmdq->head;
4137         free_cmdq->count = done_cmdq->count;
4138         done_cmdq->head = NULL;
4139         done_cmdq->tail = NULL;
4140         done_cmdq->count = 0;
4141         spin_unlock_irqrestore(&done_cmdq->lock.lock, done_cmdq->lock.flags);
4142 }
4143
4144 static void slic_cmdq_putdone_irq(struct adapter *adapter,
4145                                 struct slic_hostcmd *cmd)
4146 {
4147         struct slic_cmdqueue *cmdq = &adapter->cmdq_done;
4148
4149         spin_lock(&cmdq->lock.lock);
4150         cmd->busy = 0;
4151         ASSERT(VALID_ADDRESS(cmdq->head));
4152         cmd->next = cmdq->head;
4153         ASSERT(VALID_ADDRESS(cmd));
4154         cmdq->head = cmd;
4155         cmdq->count++;
4156         if ((adapter->xmitq_full) && (cmdq->count > 10))
4157                 netif_wake_queue(adapter->netdev);
4158         spin_unlock(&cmdq->lock.lock);
4159 }
4160
4161 static int slic_rcvqueue_init(struct adapter *adapter)
4162 {
4163         int i, count;
4164         struct slic_rcvqueue *rcvq = &adapter->rcvqueue;
4165
4166         DBG_MSG("slicoss: %s ENTER adapter[%p]\n", __func__, adapter);
4167         ASSERT(adapter->state == ADAPT_DOWN);
4168         rcvq->tail = NULL;
4169         rcvq->head = NULL;
4170         rcvq->size = SLIC_RCVQ_ENTRIES;
4171         rcvq->errors = 0;
4172         rcvq->count = 0;
4173         i = (SLIC_RCVQ_ENTRIES / SLIC_RCVQ_FILLENTRIES);
4174         count = 0;
4175         while (i) {
4176                 count += slic_rcvqueue_fill(adapter);
4177                 i--;
4178         }
4179         if (rcvq->count < SLIC_RCVQ_MINENTRIES) {
4180                 slic_rcvqueue_free(adapter);
4181                 return STATUS_FAILURE;
4182         }
4183         DBG_MSG("slicoss: %s EXIT adapter[%p]\n", __func__, adapter);
4184         return STATUS_SUCCESS;
4185 }
4186
4187 static int slic_rcvqueue_reset(struct adapter *adapter)
4188 {
4189         struct slic_rcvqueue *rcvq = &adapter->rcvqueue;
4190
4191         DBG_MSG("slicoss: %s ENTER adapter[%p]\n", __func__, adapter);
4192         ASSERT(adapter->state == ADAPT_DOWN);
4193         ASSERT(rcvq);
4194
4195         DBG_MSG("slicoss: Nothing to do. rcvq[%p]\n"
4196                 "                             count[%x]\n"
4197                 "                             head[%p]\n"
4198                 "                             tail[%p]\n",
4199                 rcvq, rcvq->count, rcvq->head, rcvq->tail);
4200
4201         DBG_MSG("slicoss: %s EXIT adapter[%p]\n", __func__, adapter);
4202         return STATUS_SUCCESS;
4203 }
4204
4205 static void slic_rcvqueue_free(struct adapter *adapter)
4206 {
4207         struct slic_rcvqueue *rcvq = &adapter->rcvqueue;
4208         struct sk_buff *skb;
4209
4210         while (rcvq->head) {
4211                 skb = rcvq->head;
4212                 rcvq->head = rcvq->head->next;
4213                 dev_kfree_skb(skb);
4214         }
4215         rcvq->tail = NULL;
4216         rcvq->head = NULL;
4217         rcvq->count = 0;
4218 }
4219
4220 static struct sk_buff *slic_rcvqueue_getnext(struct adapter *adapter)
4221 {
4222         struct slic_rcvqueue *rcvq = &adapter->rcvqueue;
4223         struct sk_buff *skb;
4224         struct slic_rcvbuf *rcvbuf;
4225         int count;
4226
4227         if (rcvq->count) {
4228                 skb = rcvq->head;
4229                 rcvbuf = (struct slic_rcvbuf *)skb->head;
4230                 ASSERT(rcvbuf);
4231
4232                 if (rcvbuf->status & IRHDDR_SVALID) {
4233                         rcvq->head = rcvq->head->next;
4234                         skb->next = NULL;
4235                         rcvq->count--;
4236                 } else {
4237                         skb = NULL;
4238                 }
4239         } else {
4240                 DBG_ERROR("RcvQ Empty!! adapter[%p] rcvq[%p] count[%x]\n",
4241                           adapter, rcvq, rcvq->count);
4242                 skb = NULL;
4243         }
4244         while (rcvq->count < SLIC_RCVQ_FILLTHRESH) {
4245                 count = slic_rcvqueue_fill(adapter);
4246                 if (!count)
4247                         break;
4248         }
4249         if (skb)
4250                 rcvq->errors = 0;
4251         return skb;
4252 }
4253
4254 static int slic_rcvqueue_fill(struct adapter *adapter)
4255 {
4256         void *paddr;
4257         u32 paddrl;
4258         u32 paddrh;
4259         struct slic_rcvqueue *rcvq = &adapter->rcvqueue;
4260         int i = 0;
4261
4262         while (i < SLIC_RCVQ_FILLENTRIES) {
4263                 struct slic_rcvbuf *rcvbuf;
4264                 struct sk_buff *skb;
4265 #ifdef KLUDGE_FOR_4GB_BOUNDARY
4266 retry_rcvqfill:
4267 #endif
4268                 skb = alloc_skb(SLIC_RCVQ_RCVBUFSIZE, GFP_ATOMIC);
4269                 if (skb) {
4270                         paddr = (void *)pci_map_single(adapter->pcidev,
4271                                                           skb->data,
4272                                                           SLIC_RCVQ_RCVBUFSIZE,
4273                                                           PCI_DMA_FROMDEVICE);
4274                         paddrl = SLIC_GET_ADDR_LOW(paddr);
4275                         paddrh = SLIC_GET_ADDR_HIGH(paddr);
4276
4277                         skb->len = SLIC_RCVBUF_HEADSIZE;
4278                         rcvbuf = (struct slic_rcvbuf *)skb->head;
4279                         rcvbuf->status = 0;
4280                         skb->next = NULL;
4281 #ifdef KLUDGE_FOR_4GB_BOUNDARY
4282                         if (paddrl == 0) {
4283                                 DBG_ERROR
4284                                     ("%s: LOW 32bits PHYSICAL ADDRESS == 0 "
4285                                      "skb[%p]   PROBLEM\n"
4286                                      "         skbdata[%p]\n"
4287                                      "         skblen[%x]\n"
4288                                      "         paddr[%p]\n"
4289                                      "         paddrl[%x]\n"
4290                                      "         paddrh[%x]\n", __func__, skb,
4291                                      skb->data, skb->len, paddr, paddrl,
4292                                      paddrh);
4293                                 DBG_ERROR("         rcvq->head[%p]\n"
4294                                           "         rcvq->tail[%p]\n"
4295                                           "         rcvq->count[%x]\n",
4296                                           rcvq->head, rcvq->tail, rcvq->count);
4297                                 DBG_ERROR("SKIP THIS SKB!!!!!!!!\n");
4298                                 goto retry_rcvqfill;
4299                         }
4300 #else
4301                         if (paddrl == 0) {
4302                                 DBG_ERROR
4303                                     ("\n\n%s: LOW 32bits PHYSICAL ADDRESS == 0 "
4304                                      "skb[%p]  GIVE TO CARD ANYWAY\n"
4305                                      "         skbdata[%p]\n"
4306                                      "         paddr[%p]\n"
4307                                      "         paddrl[%x]\n"
4308                                      "         paddrh[%x]\n", __func__, skb,
4309                                      skb->data, paddr, paddrl, paddrh);
4310                         }
4311 #endif
4312                         if (paddrh == 0) {
4313                                 WRITE_REG(adapter->slic_regs->slic_hbar,
4314                                           (u32) paddrl, DONT_FLUSH);
4315                         } else {
4316                                 WRITE_REG64(adapter,
4317                                             adapter->slic_regs->slic_hbar64,
4318                                             (u32) paddrl,
4319                                             adapter->slic_regs->slic_addr_upper,
4320                                             (u32) 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                         i++;
4329                 } else {
4330                         DBG_ERROR
4331                             ("%s slic_rcvqueue_fill could only get [%d] "
4332                              "skbuffs\n",
4333                              adapter->netdev->name, i);
4334                         break;
4335                 }
4336         }
4337         return i;
4338 }
4339
4340 static u32 slic_rcvqueue_reinsert(struct adapter *adapter, struct sk_buff *skb)
4341 {
4342         struct slic_rcvqueue *rcvq = &adapter->rcvqueue;
4343         void *paddr;
4344         u32 paddrl;
4345         u32 paddrh;
4346         struct slic_rcvbuf *rcvbuf = (struct slic_rcvbuf *)skb->head;
4347
4348         ASSERT(skb->len == SLIC_RCVBUF_HEADSIZE);
4349
4350         paddr = (void *)pci_map_single(adapter->pcidev, skb->head,
4351                                   SLIC_RCVQ_RCVBUFSIZE, PCI_DMA_FROMDEVICE);
4352         rcvbuf->status = 0;
4353         skb->next = NULL;
4354
4355         paddrl = SLIC_GET_ADDR_LOW(paddr);
4356         paddrh = SLIC_GET_ADDR_HIGH(paddr);
4357
4358         if (paddrl == 0) {
4359                 DBG_ERROR
4360                     ("%s: LOW 32bits PHYSICAL ADDRESS == 0 skb[%p]   PROBLEM\n"
4361                      "         skbdata[%p]\n" "         skblen[%x]\n"
4362                      "         paddr[%p]\n" "         paddrl[%x]\n"
4363                      "         paddrh[%x]\n", __func__, skb, skb->data,
4364                      skb->len, paddr, paddrl, paddrh);
4365                 DBG_ERROR("         rcvq->head[%p]\n"
4366                           "         rcvq->tail[%p]\n"
4367                           "         rcvq->count[%x]\n", rcvq->head, rcvq->tail,
4368                           rcvq->count);
4369         }
4370         if (paddrh == 0) {
4371                 WRITE_REG(adapter->slic_regs->slic_hbar, (u32) paddrl,
4372                           DONT_FLUSH);
4373         } else {
4374                 WRITE_REG64(adapter,
4375                             adapter->slic_regs->slic_hbar64,
4376                             paddrl,
4377                             adapter->slic_regs->slic_addr_upper,
4378                             paddrh, DONT_FLUSH);
4379         }
4380         if (rcvq->head)
4381                 rcvq->tail->next = skb;
4382         else
4383                 rcvq->head = skb;
4384         rcvq->tail = skb;
4385         rcvq->count++;
4386         return rcvq->count;
4387 }
4388
4389 static int slic_debug_card_show(struct seq_file *seq, void *v)
4390 {
4391 #ifdef MOOKTODO
4392         int i;
4393         struct sliccard *card = seq->private;
4394         struct slic_config *config = &card->config;
4395         unsigned char *fru = (unsigned char *)(&card->config.atk_fru);
4396         unsigned char *oemfru = (unsigned char *)(&card->config.OemFru);
4397 #endif
4398
4399         seq_printf(seq, "driver_version           : %s\n", slic_proc_version);
4400         seq_printf(seq, "Microcode versions:           \n");
4401         seq_printf(seq, "    Gigabit (gb)         : %s %s\n",
4402                     MOJAVE_UCODE_VERS_STRING, MOJAVE_UCODE_VERS_DATE);
4403         seq_printf(seq, "    Gigabit Receiver     : %s %s\n",
4404                     GB_RCVUCODE_VERS_STRING, GB_RCVUCODE_VERS_DATE);
4405         seq_printf(seq, "Vendor                   : %s\n", slic_vendor);
4406         seq_printf(seq, "Product Name             : %s\n", slic_product_name);
4407 #ifdef MOOKTODO
4408         seq_printf(seq, "VendorId                 : %4.4X\n",
4409                     config->VendorId);
4410         seq_printf(seq, "DeviceId                 : %4.4X\n",
4411                     config->DeviceId);
4412         seq_printf(seq, "RevisionId               : %2.2x\n",
4413                     config->RevisionId);
4414         seq_printf(seq, "Bus    #                 : %d\n", card->busnumber);
4415         seq_printf(seq, "Device #                 : %d\n", card->slotnumber);
4416         seq_printf(seq, "Interfaces               : %d\n", card->card_size);
4417         seq_printf(seq, "     Initialized         : %d\n",
4418                     card->adapters_activated);
4419         seq_printf(seq, "     Allocated           : %d\n",
4420                     card->adapters_allocated);
4421         ASSERT(card->card_size <= SLIC_NBR_MACS);
4422         for (i = 0; i < card->card_size; i++) {
4423                 seq_printf(seq,
4424                            "     MAC%d : %2.2X %2.2X %2.2X %2.2X %2.2X %2.2X\n",
4425                            i, config->macinfo[i].macaddrA[0],
4426                            config->macinfo[i].macaddrA[1],
4427                            config->macinfo[i].macaddrA[2],
4428                            config->macinfo[i].macaddrA[3],
4429                            config->macinfo[i].macaddrA[4],
4430                            config->macinfo[i].macaddrA[5]);
4431         }
4432         seq_printf(seq, "     IF  Init State Duplex/Speed irq\n");
4433         seq_printf(seq, "     -------------------------------\n");
4434         for (i = 0; i < card->adapters_allocated; i++) {
4435                 struct adapter *adapter;
4436
4437                 adapter = card->adapter[i];
4438                 if (adapter) {
4439                         seq_printf(seq,
4440                                     "     %d   %d   %s  %s  %s    0x%X\n",
4441                                     adapter->physport, adapter->state,
4442                                     SLIC_LINKSTATE(adapter->linkstate),
4443                                     SLIC_DUPLEX(adapter->linkduplex),
4444                                     SLIC_SPEED(adapter->linkspeed),
4445                                     (uint) adapter->irq);
4446                 }
4447         }
4448         seq_printf(seq, "Generation #             : %4.4X\n", card->gennumber);
4449         seq_printf(seq, "RcvQ max entries         : %4.4X\n",
4450                     SLIC_RCVQ_ENTRIES);
4451         seq_printf(seq, "Ping Status              : %8.8X\n",
4452                     card->pingstatus);
4453         seq_printf(seq, "Minimum grant            : %2.2x\n",
4454                     config->MinGrant);
4455         seq_printf(seq, "Maximum Latency          : %2.2x\n", config->MaxLat);
4456         seq_printf(seq, "PciStatus                : %4.4x\n",
4457                     config->Pcistatus);
4458         seq_printf(seq, "Debug Device Id          : %4.4x\n",
4459                     config->DbgDevId);
4460         seq_printf(seq, "DRAM ROM Function        : %4.4x\n",
4461                     config->DramRomFn);
4462         seq_printf(seq, "Network interface Pin 1  : %2.2x\n",
4463                     config->NetIntPin1);
4464         seq_printf(seq, "Network interface Pin 2  : %2.2x\n",
4465                     config->NetIntPin1);
4466         seq_printf(seq, "Network interface Pin 3  : %2.2x\n",
4467                     config->NetIntPin1);
4468         seq_printf(seq, "PM capabilities          : %4.4X\n",
4469                     config->PMECapab);
4470         seq_printf(seq, "Network Clock Controls   : %4.4X\n",
4471                     config->NwClkCtrls);
4472
4473         switch (config->FruFormat) {
4474         case ATK_FRU_FORMAT:
4475                 {
4476                         seq_printf(seq,
4477                             "Vendor                   : Alacritech, Inc.\n");
4478                         seq_printf(seq,
4479                             "Assembly #               : %c%c%c%c%c%c\n",
4480                                     fru[0], fru[1], fru[2], fru[3], fru[4],
4481                                     fru[5]);
4482                         seq_printf(seq,
4483                                     "Revision #               : %c%c\n",
4484                                     fru[6], fru[7]);
4485
4486                         if (config->OEMFruFormat == VENDOR4_FRU_FORMAT) {
4487                                 seq_printf(seq,
4488                                             "Serial   #               : "
4489                                             "%c%c%c%c%c%c%c%c%c%c%c%c\n",
4490                                             fru[8], fru[9], fru[10],
4491                                             fru[11], fru[12], fru[13],
4492                                             fru[16], fru[17], fru[18],
4493                                             fru[19], fru[20], fru[21]);
4494                         } else {
4495                                 seq_printf(seq,
4496                                             "Serial   #               : "
4497                                             "%c%c%c%c%c%c%c%c%c%c%c%c%c%c\n",
4498                                             fru[8], fru[9], fru[10],
4499                                             fru[11], fru[12], fru[13],
4500                                             fru[14], fru[15], fru[16],
4501                                             fru[17], fru[18], fru[19],
4502                                             fru[20], fru[21]);
4503                         }
4504                         break;
4505                 }
4506
4507         default:
4508                 {
4509                         seq_printf(seq,
4510                             "Vendor                   : Alacritech, Inc.\n");
4511                         seq_printf(seq,
4512                             "Serial   #               : Empty FRU\n");
4513                         break;
4514                 }
4515         }
4516
4517         switch (config->OEMFruFormat) {
4518         case VENDOR1_FRU_FORMAT:
4519                 {
4520                         seq_printf(seq, "FRU Information:\n");
4521                         seq_printf(seq, "    Commodity #          : %c\n",
4522                                     oemfru[0]);
4523                         seq_printf(seq,
4524                                     "    Assembly #           : %c%c%c%c\n",
4525                                     oemfru[1], oemfru[2], oemfru[3], oemfru[4]);
4526                         seq_printf(seq,
4527                                     "    Revision #           : %c%c\n",
4528                                     oemfru[5], oemfru[6]);
4529                         seq_printf(seq,
4530                                     "    Supplier #           : %c%c\n",
4531                                     oemfru[7], oemfru[8]);
4532                         seq_printf(seq,
4533                                     "    Date                 : %c%c\n",
4534                                     oemfru[9], oemfru[10]);
4535                         seq_sprintf(seq,
4536                                     "    Sequence #           : %c%c%c\n",
4537                                     oemfru[11], oemfru[12], oemfru[13]);
4538                         break;
4539                 }
4540
4541         case VENDOR2_FRU_FORMAT:
4542                 {
4543                         seq_printf(seq, "FRU Information:\n");
4544                         seq_printf(seq,
4545                                     "    Part     #           : "
4546                                     "%c%c%c%c%c%c%c%c\n",
4547                                     oemfru[0], oemfru[1], oemfru[2],
4548                                     oemfru[3], oemfru[4], oemfru[5],
4549                                     oemfru[6], oemfru[7]);
4550                         seq_printf(seq,
4551                                     "    Supplier #           : %c%c%c%c%c\n",
4552                                     oemfru[8], oemfru[9], oemfru[10],
4553                                     oemfru[11], oemfru[12]);
4554                         seq_printf(seq,
4555                                     "    Date                 : %c%c%c\n",
4556                                     oemfru[13], oemfru[14], oemfru[15]);
4557                         seq_sprintf(seq,
4558                                     "    Sequence #           : %c%c%c%c\n",
4559                                     oemfru[16], oemfru[17], oemfru[18],
4560                                     oemfru[19]);
4561                         break;
4562                 }
4563
4564         case VENDOR3_FRU_FORMAT:
4565                 {
4566                         seq_printf(seq, "FRU Information:\n");
4567                 }
4568
4569         case VENDOR4_FRU_FORMAT:
4570                 {
4571                         seq_printf(seq, "FRU Information:\n");
4572                         seq_printf(seq,
4573                                     "    FRU Number           : "
4574                                     "%c%c%c%c%c%c%c%c\n",
4575                                     oemfru[0], oemfru[1], oemfru[2],
4576                                     oemfru[3], oemfru[4], oemfru[5],
4577                                     oemfru[6], oemfru[7]);
4578                         seq_sprintf(seq,
4579                                     "    Part Number          : "
4580                                     "%c%c%c%c%c%c%c%c\n",
4581                                     oemfru[8], oemfru[9], oemfru[10],
4582                                     oemfru[11], oemfru[12], oemfru[13],
4583                                     oemfru[14], oemfru[15]);
4584                         seq_printf(seq,
4585                                     "    EC Level             : "
4586                                     "%c%c%c%c%c%c%c%c\n",
4587                                     oemfru[16], oemfru[17], oemfru[18],
4588                                     oemfru[19], oemfru[20], oemfru[21],
4589                                     oemfru[22], oemfru[23]);
4590                         break;
4591                 }
4592
4593         default:
4594                 break;
4595         }
4596 #endif
4597
4598         return 0;
4599 }
4600
4601 static int slic_debug_adapter_show(struct seq_file *seq, void *v)
4602 {
4603         struct adapter *adapter = seq->private;
4604
4605         if ((adapter->netdev) && (adapter->netdev->name)) {
4606                 seq_printf(seq, "info: interface          : %s\n",
4607                             adapter->netdev->name);
4608         }
4609         seq_printf(seq, "info: status             : %s\n",
4610                 SLIC_LINKSTATE(adapter->linkstate));
4611         seq_printf(seq, "info: port               : %d\n",
4612                 adapter->physport);
4613         seq_printf(seq, "info: speed              : %s\n",
4614                 SLIC_SPEED(adapter->linkspeed));
4615         seq_printf(seq, "info: duplex             : %s\n",
4616                 SLIC_DUPLEX(adapter->linkduplex));
4617         seq_printf(seq, "info: irq                : 0x%X\n",
4618                 (uint) adapter->irq);
4619         seq_printf(seq, "info: Interrupt Agg Delay: %d usec\n",
4620                 adapter->card->loadlevel_current);
4621         seq_printf(seq, "info: RcvQ max entries   : %4.4X\n",
4622                 SLIC_RCVQ_ENTRIES);
4623         seq_printf(seq, "info: RcvQ current       : %4.4X\n",
4624                     adapter->rcvqueue.count);
4625         seq_printf(seq, "rx stats: packets                  : %8.8lX\n",
4626                     adapter->stats.rx_packets);
4627         seq_printf(seq, "rx stats: bytes                    : %8.8lX\n",
4628                     adapter->stats.rx_bytes);
4629         seq_printf(seq, "rx stats: broadcasts               : %8.8X\n",
4630                     adapter->rcv_broadcasts);
4631         seq_printf(seq, "rx stats: multicasts               : %8.8X\n",
4632                     adapter->rcv_multicasts);
4633         seq_printf(seq, "rx stats: unicasts                 : %8.8X\n",
4634                     adapter->rcv_unicasts);
4635         seq_printf(seq, "rx stats: errors                   : %8.8X\n",
4636                     (u32) adapter->slic_stats.iface.rcv_errors);
4637         seq_printf(seq, "rx stats: Missed errors            : %8.8X\n",
4638                     (u32) adapter->slic_stats.iface.rcv_discards);
4639         seq_printf(seq, "rx stats: drops                    : %8.8X\n",
4640                         (u32) adapter->rcv_drops);
4641         seq_printf(seq, "tx stats: packets                  : %8.8lX\n",
4642                         adapter->stats.tx_packets);
4643         seq_printf(seq, "tx stats: bytes                    : %8.8lX\n",
4644                         adapter->stats.tx_bytes);
4645         seq_printf(seq, "tx stats: errors                   : %8.8X\n",
4646                         (u32) adapter->slic_stats.iface.xmt_errors);
4647         seq_printf(seq, "rx stats: multicasts               : %8.8lX\n",
4648                         adapter->stats.multicast);
4649         seq_printf(seq, "tx stats: collision errors         : %8.8X\n",
4650                         (u32) adapter->slic_stats.iface.xmit_collisions);
4651         seq_printf(seq, "perf: Max rcv frames/isr           : %8.8X\n",
4652                         adapter->max_isr_rcvs);
4653         seq_printf(seq, "perf: Rcv interrupt yields         : %8.8X\n",
4654                         adapter->rcv_interrupt_yields);
4655         seq_printf(seq, "perf: Max xmit complete/isr        : %8.8X\n",
4656                         adapter->max_isr_xmits);
4657         seq_printf(seq, "perf: error interrupts             : %8.8X\n",
4658                         adapter->error_interrupts);
4659         seq_printf(seq, "perf: error rmiss interrupts       : %8.8X\n",
4660                         adapter->error_rmiss_interrupts);
4661         seq_printf(seq, "perf: rcv interrupts               : %8.8X\n",
4662                         adapter->rcv_interrupts);
4663         seq_printf(seq, "perf: xmit interrupts              : %8.8X\n",
4664                         adapter->xmit_interrupts);
4665         seq_printf(seq, "perf: link event interrupts        : %8.8X\n",
4666                         adapter->linkevent_interrupts);
4667         seq_printf(seq, "perf: UPR interrupts               : %8.8X\n",
4668                         adapter->upr_interrupts);
4669         seq_printf(seq, "perf: interrupt count              : %8.8X\n",
4670                         adapter->num_isrs);
4671         seq_printf(seq, "perf: false interrupts             : %8.8X\n",
4672                         adapter->false_interrupts);
4673         seq_printf(seq, "perf: All register writes          : %8.8X\n",
4674                         adapter->all_reg_writes);
4675         seq_printf(seq, "perf: ICR register writes          : %8.8X\n",
4676                         adapter->icr_reg_writes);
4677         seq_printf(seq, "perf: ISR register writes          : %8.8X\n",
4678                         adapter->isr_reg_writes);
4679         seq_printf(seq, "ifevents: overflow 802 errors      : %8.8X\n",
4680                         adapter->if_events.oflow802);
4681         seq_printf(seq, "ifevents: transport overflow errors: %8.8X\n",
4682                         adapter->if_events.Tprtoflow);
4683         seq_printf(seq, "ifevents: underflow errors         : %8.8X\n",
4684                         adapter->if_events.uflow802);
4685         seq_printf(seq, "ifevents: receive early            : %8.8X\n",
4686                         adapter->if_events.rcvearly);
4687         seq_printf(seq, "ifevents: buffer overflows         : %8.8X\n",
4688                         adapter->if_events.Bufov);
4689         seq_printf(seq, "ifevents: carrier errors           : %8.8X\n",
4690                         adapter->if_events.Carre);
4691         seq_printf(seq, "ifevents: Long                     : %8.8X\n",
4692                         adapter->if_events.Longe);
4693         seq_printf(seq, "ifevents: invalid preambles        : %8.8X\n",
4694                         adapter->if_events.Invp);
4695         seq_printf(seq, "ifevents: CRC errors               : %8.8X\n",
4696                         adapter->if_events.Crc);
4697         seq_printf(seq, "ifevents: dribble nibbles          : %8.8X\n",
4698                         adapter->if_events.Drbl);
4699         seq_printf(seq, "ifevents: Code violations          : %8.8X\n",
4700                         adapter->if_events.Code);
4701         seq_printf(seq, "ifevents: TCP checksum errors      : %8.8X\n",
4702                         adapter->if_events.TpCsum);
4703         seq_printf(seq, "ifevents: TCP header short errors  : %8.8X\n",
4704                         adapter->if_events.TpHlen);
4705         seq_printf(seq, "ifevents: IP checksum errors       : %8.8X\n",
4706                         adapter->if_events.IpCsum);
4707         seq_printf(seq, "ifevents: IP frame incompletes     : %8.8X\n",
4708                         adapter->if_events.IpLen);
4709         seq_printf(seq, "ifevents: IP headers shorts        : %8.8X\n",
4710                         adapter->if_events.IpHlen);
4711
4712         return 0;
4713 }
4714 static int slic_debug_adapter_open(struct inode *inode, struct file *file)
4715 {
4716         return single_open(file, slic_debug_adapter_show, inode->i_private);
4717 }
4718
4719 static int slic_debug_card_open(struct inode *inode, struct file *file)
4720 {
4721         return single_open(file, slic_debug_card_show, inode->i_private);
4722 }
4723
4724 static const struct file_operations slic_debug_adapter_fops = {
4725         .owner          = THIS_MODULE,
4726         .open           = slic_debug_adapter_open,
4727         .read           = seq_read,
4728         .llseek         = seq_lseek,
4729         .release        = single_release,
4730 };
4731
4732 static const struct file_operations slic_debug_card_fops = {
4733         .owner          = THIS_MODULE,
4734         .open           = slic_debug_card_open,
4735         .read           = seq_read,
4736         .llseek         = seq_lseek,
4737         .release        = single_release,
4738 };
4739
4740 static void slic_debug_adapter_create(struct adapter *adapter)
4741 {
4742         struct dentry *d;
4743         char    name[7];
4744         struct sliccard *card = adapter->card;
4745
4746         if (!card->debugfs_dir)
4747                 return;
4748
4749         sprintf(name, "port%d", adapter->port);
4750         d = debugfs_create_file(name, S_IRUGO,
4751                                 card->debugfs_dir, adapter,
4752                                 &slic_debug_adapter_fops);
4753         if (!d || IS_ERR(d))
4754                 pr_info(PFX "%s: debugfs create failed\n", name);
4755         else
4756                 adapter->debugfs_entry = d;
4757 }
4758
4759 static void slic_debug_adapter_destroy(struct adapter *adapter)
4760 {
4761         if (adapter->debugfs_entry) {
4762                 debugfs_remove(adapter->debugfs_entry);
4763                 adapter->debugfs_entry = NULL;
4764         }
4765 }
4766
4767 static void slic_debug_card_create(struct sliccard *card)
4768 {
4769         struct dentry *d;
4770         char    name[IFNAMSIZ];
4771
4772         snprintf(name, sizeof(name), "slic%d", card->cardnum);
4773         d = debugfs_create_dir(name, slic_debugfs);
4774         if (!d || IS_ERR(d))
4775                 pr_info(PFX "%s: debugfs create dir failed\n",
4776                                 name);
4777         else {
4778                 card->debugfs_dir = d;
4779                 d = debugfs_create_file("cardinfo", S_IRUGO,
4780                                 slic_debugfs, card,
4781                                 &slic_debug_card_fops);
4782                 if (!d || IS_ERR(d))
4783                         pr_info(PFX "%s: debugfs create failed\n",
4784                                         name);
4785                 else
4786                         card->debugfs_cardinfo = d;
4787         }
4788 }
4789
4790 static void slic_debug_card_destroy(struct sliccard *card)
4791 {
4792         int i;
4793
4794         for (i = 0; i < card->card_size; i++) {
4795                 struct adapter *adapter;
4796
4797                 adapter = card->adapter[i];
4798                 if (adapter)
4799                         slic_debug_adapter_destroy(adapter);
4800         }
4801         if (card->debugfs_cardinfo) {
4802                 debugfs_remove(card->debugfs_cardinfo);
4803                 card->debugfs_cardinfo = NULL;
4804         }
4805         if (card->debugfs_dir) {
4806                 debugfs_remove(card->debugfs_dir);
4807                 card->debugfs_dir = NULL;
4808         }
4809 }
4810
4811 static void slic_debug_init(void)
4812 {
4813         struct dentry *ent;
4814
4815         ent = debugfs_create_dir("slic", NULL);
4816         if (!ent || IS_ERR(ent)) {
4817                 pr_info(PFX "debugfs create directory failed\n");
4818                 return;
4819         }
4820
4821         slic_debugfs = ent;
4822 }
4823
4824 static void slic_debug_cleanup(void)
4825 {
4826         if (slic_debugfs) {
4827                 debugfs_remove(slic_debugfs);
4828                 slic_debugfs = NULL;
4829         }
4830 }
4831
4832 /*=============================================================================
4833   =============================================================================
4834   ===                                                                       ===
4835   ===       SLIC  DUMP  MANAGEMENT        SECTION                           ===
4836   ===                                                                       ===
4837   ===                                                                       ===
4838   === Dump routines                                                         ===
4839   ===                                                                       ===
4840   ===                                                                       ===
4841   =============================================================================
4842   ============================================================================*/
4843
4844 #if SLIC_DUMP_ENABLED
4845
4846 #include <stdarg.h>
4847
4848 void *slic_dump_handle;         /* thread handle */
4849
4850 /*
4851  * These are the only things you should do on a core-file: use only these
4852  * functions to write out all the necessary info.
4853  */
4854 static int slic_dump_seek(struct file *SLIChandle, u32 file_offset)
4855 {
4856         if (SLIChandle->f_pos != file_offset) {
4857                 /*DBG_MSG("slic_dump_seek  now needed [%x : %x]\n",
4858                         (u32)SLIChandle->f_pos, (u32)file_offset); */
4859                 if (SLIChandle->f_op->llseek) {
4860                         if (SLIChandle->f_op->
4861                             llseek(SLIChandle, file_offset, 0) != file_offset)
4862                                 return 0;
4863                 } else {
4864                         SLIChandle->f_pos = file_offset;
4865                 }
4866         }
4867         return 1;
4868 }
4869
4870 static int slic_dump_write(struct sliccard *card,
4871                            const void *addr, int size, u32 file_offset)
4872 {
4873         int r = 1;
4874         u32 result = 0;
4875         struct file *SLIChandle = card->dumphandle;
4876
4877 #ifdef HISTORICAL               /* legacy */
4878         down(&SLIChandle->f_dentry->d_inode->i_sem);
4879 #endif
4880         if (size) {
4881                 slic_dump_seek(SLIChandle, file_offset);
4882
4883                 result =
4884                     SLIChandle->f_op->write(SLIChandle, addr, size,
4885                                             &SLIChandle->f_pos);
4886
4887                 r = result == size;
4888         }
4889
4890         card->dumptime_complete = jiffies;
4891         card->dumptime_delta = card->dumptime_complete - card->dumptime_start;
4892         card->dumptime_start = jiffies;
4893
4894 #ifdef HISTORICAL
4895         up(&SLIChandle->f_dentry->d_inode->i_sem);
4896 #endif
4897         if (!r) {
4898                 DBG_ERROR("%s: addr[%p] size[%x] result[%x] file_offset[%x]\n",
4899                           __func__, addr, size, result, file_offset);
4900         }
4901         return r;
4902 }
4903
4904 static uint slic_init_dump_thread(struct sliccard *card)
4905 {
4906         card->dump_task_id = kthread_run(slic_dump_thread, (void *)card, 0);
4907
4908 /*  DBG_MSG("create slic_dump_thread dump_pid[%x]\n", card->dump_pid); */
4909         if (IS_ERR(card->dump_task_id)) {
4910                 DBG_MSG("create slic_dump_thread FAILED \n");
4911                 return STATUS_FAILURE;
4912         }
4913
4914         return STATUS_SUCCESS;
4915 }
4916
4917 static int slic_dump_thread(void *context)
4918 {
4919         struct sliccard *card = (struct sliccard *)context;
4920         struct adapter *adapter;
4921         struct adapter *dump_adapter = NULL;
4922         u32 dump_complete = 0;
4923         u32 delay = SLIC_SECS_TO_JIFFS(PING_TIMER_INTERVAL);
4924         struct slic_regs *pregs;
4925         u32 i;
4926         struct slic_upr *upr, *uprnext;
4927         u32 dump_card;
4928
4929         ASSERT(card);
4930
4931         card->dumpthread_running = 1;
4932
4933 #ifdef HISTORICAL
4934         lock_kernel();
4935         /*
4936          * This thread doesn't need any user-level access,
4937          * so get rid of all our resources
4938          */
4939         exit_files(current);    /* daemonize doesn't do exit_files */
4940         current->files = init_task.files;
4941         atomic_inc(&current->files->count);
4942 #endif
4943
4944         daemonize("%s", "slicmon");
4945
4946         /* Setup a nice name */
4947         strcpy(current->comm, "slicmon");
4948         DBG_ERROR
4949             ("slic_dump_thread[slicmon] daemon is alive card[%p] pid[%x]\n",
4950              card, card->dump_task_id->pid);
4951
4952         /*
4953          *    Send me a signal to get me to die (for debugging)
4954          */
4955         do {
4956                 /*
4957                  * If card state is not set to up, skip
4958                  */
4959                 if (card->state != CARD_UP) {
4960                         if (card->adapters_activated)
4961                                 goto wait;
4962                         else
4963                                 goto end_thread;
4964                 }
4965                 /*
4966                  *    Check the results of our last ping.
4967                  */
4968                 dump_card = 0;
4969 #ifdef SLIC_FAILURE_DUMP
4970                 if (card->pingstatus != ISR_PINGMASK) {
4971                         DBG_MSG
4972                             ("\n[slicmon]  CARD #%d TIMED OUT - status "
4973                              "%x: DUMP THE CARD!\n",
4974                              card->cardnum, card->pingstatus);
4975                         dump_card = 1;
4976                 }
4977 #else
4978                 /*
4979                  *  Cause a card RESET instead?
4980                  */
4981                 if (card->pingstatus != ISR_PINGMASK) {
4982                         /* todo. do we want to reset the card in production */
4983                         /* DBG_MSG("\n[slicmon]  CARD #%d TIMED OUT - "
4984                            status %x: RESET THE CARD!\n", card->cardnum,
4985                            card->pingstatus); */
4986                         DBG_ERROR
4987                             ("\n[slicmon]  CARD #%d TIMED OUT - status %x: "
4988                              "DUMP THE CARD!\n",
4989                              card->cardnum, card->pingstatus);
4990                         dump_card = 1;
4991                 }
4992 #endif
4993                 if ((dump_card)
4994                     || (card->dump_requested == SLIC_DUMP_REQUESTED)) {
4995                         if (card->dump_requested == SLIC_DUMP_REQUESTED) {
4996                                 DBG_ERROR
4997                             ("[slicmon]: Dump card Requested: Card %x\n",
4998                                      card->cardnum);
4999                         }
5000                         if (card->pingstatus != ISR_PINGMASK) {
5001                                 ushort cpuid = 0;
5002                                 ushort crashpc = 0;
5003
5004                                 if (card->adapter[0]) {
5005                                         if ((card->adapter[0])->memorylength >=
5006                                             CRASH_INFO_OFFSET +
5007                                             sizeof(slic_crash_info)) {
5008                                                 char *crashptr;
5009                                                 p_slic_crash_info crashinfo;
5010
5011                                                 crashptr =
5012                                                     ((char *)card->adapter[0]->
5013                                                      slic_regs) +
5014                                                     CRASH_INFO_OFFSET;
5015                                                 crashinfo =
5016                                                     (p_slic_crash_info)
5017                                                     crashptr;
5018                                                 cpuid = crashinfo->cpu_id;
5019                                                 crashpc = crashinfo->crash_pc;
5020                                         }
5021                                 }
5022                                 DBG_ERROR
5023                                     ("[slicmon]: Dump card: Card %x crashed "
5024                                      "and failed to answer PING. "
5025                                      "CPUID[%x] PC[%x]\n ",
5026                                      card->cardnum, cpuid, crashpc);
5027                         }
5028
5029                         card->dump_requested = SLIC_DUMP_IN_PROGRESS;
5030
5031                         /*
5032                          * Set the card state to DOWN and the adapter states
5033                          * to RESET.They will check this in SimbaCheckForHang
5034                          * and initiate interface reset (which in turn will
5035                          * reinitialize the card).
5036                          */
5037                         card->state = CARD_DOWN;
5038
5039                         for (i = 0; i < card->card_size; i++) {
5040                                 adapter = card->adapter[i];
5041                                 if (adapter) {
5042                                         slic_if_stop_queue(adapter);
5043
5044                                         if (adapter->state == ADAPT_UP) {
5045                                                 adapter->state = ADAPT_RESET;
5046                                                 adapter->linkstate = LINK_DOWN;
5047                                                 DBG_ERROR
5048                                                     ("[slicmon]: SLIC Card[%d] "
5049                                                      "Port[%d] adapter[%p] "
5050                                                      "down\n",
5051                                                      (uint) card->cardnum,
5052                                                      (uint) i, adapter);
5053                                         }
5054 #if SLIC_GET_STATS_TIMER_ENABLED
5055                                         /* free stats timer */
5056                                         if (adapter->statstimerset) {
5057                                                 adapter->statstimerset = 0;
5058                                                 del_timer(&adapter->statstimer);
5059                                         }
5060 #endif
5061                                 }
5062                         }
5063
5064                         for (i = 0; i < card->card_size; i++) {
5065                                 adapter = card->adapter[i];
5066                                 if ((adapter) && (adapter->activated)) {
5067                                         pregs = adapter->slic_regs;
5068                                         dump_adapter = adapter;
5069
5070                                         /*
5071                                          * If the dump status is zero, then
5072                                          * the utility processor has crashed.
5073                                          * If this is the case, any pending
5074                                          * utilityprocessor requests will not
5075                                          * complete and our dump commands will
5076                                          * not be issued.
5077                                          *
5078                                          * To avoid this we will clear any
5079                                          * pending utility processor requests
5080                                          * now.
5081                                          */
5082                                         if (!card->pingstatus) {
5083                                                 spin_lock_irqsave(
5084                                                     &adapter->upr_lock.lock,
5085                                                     adapter->upr_lock.flags);
5086                                                 upr = adapter->upr_list;
5087                                                 while (upr) {
5088                                                         uprnext = upr->next;
5089                                                         kfree(upr);
5090                                                         upr = uprnext;
5091                                                 }
5092                                                 adapter->upr_list = 0;
5093                                                 adapter->upr_busy = 0;
5094                                                 spin_unlock_irqrestore(
5095                                                     &adapter->upr_lock.lock,
5096                                                     adapter->upr_lock.flags);
5097                                         }
5098
5099                                         slic_dump_card(card, FALSE);
5100                                         dump_complete = 1;
5101                                 }
5102
5103                                 if (dump_complete) {
5104                                         DBG_ERROR("SLIC Dump Complete\n");
5105                                         /*  Only dump the card one time */
5106                                         break;
5107                                 }
5108                         }
5109
5110                         if (dump_adapter) {
5111                                 DBG_ERROR
5112                                     ("slic dump completed. "
5113                                      "Reenable interfaces\n");
5114                                 slic_card_init(card, dump_adapter);
5115
5116                                 /*
5117                                  *  Reenable the adapters that were reset
5118                                  */
5119                                 for (i = 0; i < card->card_size; i++) {
5120                                         adapter = card->adapter[i];
5121                                         if (adapter) {
5122                                                 if (adapter->state ==
5123                                                     ADAPT_RESET) {
5124                                                         DBG_ERROR
5125                                                             ("slicdump: SLIC "
5126                                            "Card[%d] Port[%d] adapter[%p] "
5127                                            "bring UP\n",
5128                                                              (uint) card->
5129                                                              cardnum, (uint) i,
5130                                                              adapter);
5131                                                         adapter->state =
5132                                                             ADAPT_DOWN;
5133                                                         adapter->linkstate =
5134                                                             LINK_DOWN;
5135                                                         slic_entry_open
5136                                                             (adapter->netdev);
5137                                                 }
5138                                         }
5139                                 }
5140
5141                                 card->dump_requested = SLIC_DUMP_DONE;
5142                         }
5143                 } else {
5144                 /* if pingstatus != ISR_PINGMASK) || dump_requested...ELSE
5145                  *    We received a valid ping response.
5146                  *    Clear the Pingstatus field, find a valid adapter
5147                  *    structure and send another ping.
5148                  */
5149                         for (i = 0; i < card->card_size; i++) {
5150                                 adapter = card->adapter[i];
5151                                 if (adapter && (adapter->state == ADAPT_UP)) {
5152                                         card->pingstatus = 0;
5153                                         slic_upr_request(adapter, SLIC_UPR_PING,
5154                                                          0, 0, 0, 0);
5155                                         break;  /* Only issue one per card */
5156                                 }
5157                         }
5158                 }
5159 wait:
5160                 SLIC_INTERRUPTIBLE_SLEEP_ON_TIMEOUT(card->dump_wq, delay);
5161         } while (!signal_pending(current));
5162
5163 end_thread:
5164 /*  DBG_MSG("[slicmon] slic_dump_thread card[%p] pid[%x] ENDING\n",
5165     card, card->dump_pid); */
5166         card->dumpthread_running = 0;
5167
5168         return 0;
5169 }
5170
5171 /*
5172  * Read a single byte from our dump index file.  This
5173  * value is used as our suffix for our dump path.  The
5174  * value is incremented and written back to the file
5175  */
5176 static unsigned char slic_get_dump_index(char *path)
5177 {
5178         unsigned char index = 0;
5179 #ifdef SLIC_DUMP_INDEX_SUPPORT
5180         u32 status;
5181         void *FileHandle;
5182         u32 offset;
5183
5184         offset = 0;
5185
5186         /*
5187          * Open the index file.  If one doesn't exist, create it
5188          */
5189         status = create_file(&FileHandle);
5190
5191         if (status != STATUS_SUCCESS)
5192                 return (unsigned char) 0;
5193
5194         status = read_file(FileHandle, &index, 1, &offset);
5195
5196         index++;
5197
5198         status = write_file(FileHandle, &index, 1, &offset);
5199
5200         close_file(FileHandle);
5201 #else
5202         index = 0;
5203 #endif
5204         return index;
5205 }
5206
5207 static struct file *slic_dump_open_file(struct sliccard *card)
5208 {
5209         struct file *SLIChandle = NULL;
5210         struct dentry *dentry = NULL;
5211         struct inode *inode = NULL;
5212         char SLICfile[50];
5213
5214         card->dumpfile_fs = get_fs();
5215
5216         set_fs(KERNEL_DS);
5217
5218         memset(SLICfile, 0, sizeof(SLICfile));
5219         sprintf(SLICfile, "/var/tmp/slic%d-dump-%d", card->cardnum,
5220                 (uint) card->dump_count);
5221         card->dump_count++;
5222
5223         SLIChandle =
5224             filp_open(SLICfile, O_CREAT | O_RDWR | O_SYNC | O_LARGEFILE, 0666);
5225
5226         DBG_MSG("[slicmon]: Dump Card #%d to file: %s \n", card->cardnum,
5227                 SLICfile);
5228
5229 /*  DBG_MSG("[slicmon] filp_open %s SLIChandle[%p]\n", SLICfile, SLIChandle);*/
5230
5231         if (IS_ERR(SLIChandle))
5232                 goto end_slicdump;
5233
5234         dentry = SLIChandle->f_dentry;
5235         inode = dentry->d_inode;
5236
5237 /*  DBG_MSG("[slicmon] inode[%p] i_nlink[%x] i_mode[%x] i_op[%p] i_fop[%p]\n"
5238                 "f_op->write[%p]\n",
5239                 inode, inode->i_nlink, inode->i_mode, inode->i_op,
5240                 inode->i_fop, SLIChandle->f_op->write); */
5241         if (inode->i_nlink > 1)
5242                 goto close_slicdump;    /* multiple links - don't dump */
5243 #ifdef HISTORICAL
5244         if (!S_ISREG(inode->i_mode))
5245                 goto close_slicdump;
5246 #endif
5247         if (!inode->i_op || !inode->i_fop)
5248                 goto close_slicdump;
5249
5250         if (!SLIChandle->f_op->write)
5251                 goto close_slicdump;
5252
5253         /*
5254          *  If we got here we have SUCCESSFULLY OPENED the dump file
5255          */
5256 /*  DBG_MSG("opened %s SLIChandle[%p]\n", SLICfile, SLIChandle); */
5257         return SLIChandle;
5258
5259 close_slicdump:
5260         DBG_MSG("[slicmon] slic_dump_open_file failed close SLIChandle[%p]\n",
5261                 SLIChandle);
5262         filp_close(SLIChandle, NULL);
5263
5264 end_slicdump:
5265         set_fs(card->dumpfile_fs);
5266
5267         return NULL;
5268 }
5269
5270 static void slic_dump_close_file(struct sliccard *card)
5271 {
5272
5273 /*  DBG_MSG("[slicmon] slic_dump_CLOSE_file close SLIChandle[%p]\n",
5274    card->dumphandle); */
5275
5276         filp_close(card->dumphandle, NULL);
5277
5278         set_fs(card->dumpfile_fs);
5279 }
5280
5281 static u32 slic_dump_card(struct sliccard *card, bool resume)
5282 {
5283         struct adapter *adapter = card->master;
5284         u32 status;
5285         u32 queue;
5286         u32 len, offset;
5287         u32 sram_size, dram_size, regs;
5288         struct sliccore_hdr corehdr;
5289         u32 file_offset;
5290         char *namestr;
5291         u32 i;
5292         u32 max_queues = 0;
5293         u32 result;
5294
5295         card->dumphandle = slic_dump_open_file(card);
5296
5297         if (card->dumphandle == NULL) {
5298                 DBG_MSG("[slicmon] Cant create Dump file - dump failed\n");
5299                 return -ENOMEM;
5300         }
5301         if (!card->dumpbuffer) {
5302                 DBG_MSG("[slicmon] Insufficient memory for dump\n");
5303                 return -ENOMEM;
5304         }
5305         if (!card->cmdbuffer) {
5306                 DBG_MSG("[slicmon] Insufficient cmd memory for dump\n");
5307                 return -ENOMEM;
5308         }
5309
5310         /*
5311          * Write the file version to the core header.
5312          */
5313         namestr = slic_proc_version;
5314         for (i = 0; i < (DRIVER_NAME_SIZE - 1); i++, namestr++) {
5315                 if (!namestr)
5316                         break;
5317                 corehdr.driver_version[i] = *namestr;
5318         }
5319         corehdr.driver_version[i] = 0;
5320
5321         file_offset = sizeof(struct sliccore_hdr);
5322
5323         /*
5324          * Issue the following debug commands to the SLIC:
5325          *        - Halt both receive and transmit
5326          *        - Dump receive registers
5327          *        - Dump transmit registers
5328          *        - Dump sram
5329          *        - Dump dram
5330          *        - Dump queues
5331          */
5332         DBG_MSG("slicDump HALT Receive Processor\n");
5333         card->dumptime_start = jiffies;
5334
5335         status = slic_dump_halt(card, PROC_RECEIVE);
5336         if (status != STATUS_SUCCESS) {
5337                 DBG_ERROR
5338                     ("Cant halt receive sequencer - dump failed status[%x]\n",
5339                      status);
5340                 goto done;
5341         }
5342
5343         DBG_MSG("slicDump HALT Transmit Processor\n");
5344         status = slic_dump_halt(card, PROC_TRANSMIT);
5345         if (status != STATUS_SUCCESS) {
5346                 DBG_ERROR("Cant halt transmit sequencer - dump failed\n");
5347                 goto done;
5348         }
5349
5350         /* Dump receive regs */
5351         status = slic_dump_reg(card, PROC_RECEIVE);
5352         if (status != STATUS_SUCCESS) {
5353                 DBG_ERROR("Cant dump receive registers - dump failed\n");
5354                 goto done;
5355         }
5356
5357         DBG_MSG("slicDump Write Receive REGS len[%x] offset[%x]\n",
5358                 (SLIC_NUM_REG * 4), file_offset);
5359
5360         result =
5361             slic_dump_write(card, card->dumpbuffer, SLIC_NUM_REG * 4,
5362                             file_offset);
5363         if (!result) {
5364                 DBG_ERROR
5365                     ("Cant write rcv registers to dump file - dump failed\n");
5366                 goto done;
5367         }
5368
5369         corehdr.RcvRegOff = file_offset;
5370         corehdr.RcvRegsize = SLIC_NUM_REG * 4;
5371         file_offset += SLIC_NUM_REG * 4;
5372
5373         /* Dump transmit regs */
5374         status = slic_dump_reg(card, PROC_TRANSMIT);
5375         if (status != STATUS_SUCCESS) {
5376                 DBG_ERROR("Cant dump transmit registers - dump failed\n");
5377                 goto done;
5378         }
5379
5380         DBG_MSG("slicDump Write XMIT REGS len[%x] offset[%x]\n",
5381                 (SLIC_NUM_REG * 4), file_offset);
5382
5383         result =
5384             slic_dump_write(card, card->dumpbuffer, SLIC_NUM_REG * 4,
5385                             file_offset);
5386         if (!result) {
5387                 DBG_ERROR
5388                     ("Cant write xmt registers to dump file - dump failed\n");
5389                 goto done;
5390         }
5391
5392         corehdr.XmtRegOff = file_offset;
5393         corehdr.XmtRegsize = SLIC_NUM_REG * 4;
5394         file_offset += SLIC_NUM_REG * 4;
5395
5396         regs = SLIC_GBMAX_REG;
5397
5398         corehdr.FileRegOff = file_offset;
5399         corehdr.FileRegsize = regs * 4;
5400
5401         for (offset = 0; regs;) {
5402                 len = MIN(regs, 16);    /* Can only xfr 16 regs at a time */
5403
5404                 status = slic_dump_data(card, offset, (ushort) len, DESC_RFILE);
5405
5406                 if (status != STATUS_SUCCESS) {
5407                         DBG_ERROR("Cant dump register file - dump failed\n");
5408                         goto done;
5409                 }
5410
5411                 DBG_MSG("slicDump Write RegisterFile len[%x] offset[%x]\n",
5412                         (len * 4), file_offset);
5413
5414                 result =
5415                     slic_dump_write(card, card->dumpbuffer, len * 4,
5416                                     file_offset);
5417                 if (!result) {
5418                         DBG_ERROR
5419                             ("Cant write register file to dump file - "
5420                              "dump failed\n");
5421                         goto done;
5422                 }
5423
5424                 file_offset += len * 4;
5425                 offset += len;
5426                 regs -= len;
5427         }
5428
5429         dram_size = card->config.DramSize * 0x10000;
5430
5431         switch (adapter->devid) {
5432         case SLIC_2GB_DEVICE_ID:
5433                 sram_size = SLIC_SRAM_SIZE2GB;
5434                 break;
5435         case SLIC_1GB_DEVICE_ID:
5436                 sram_size = SLIC_SRAM_SIZE1GB;
5437                 break;
5438         default:
5439                 sram_size = 0;
5440                 ASSERT(0);
5441                 break;
5442         }
5443
5444         corehdr.SramOff = file_offset;
5445         corehdr.Sramsize = sram_size;
5446
5447         for (offset = 0; sram_size;) {
5448                 len = MIN(sram_size, DUMP_BUF_SIZE);
5449                 status = slic_dump_data(card, offset, (ushort) len, DESC_SRAM);
5450                 if (status != STATUS_SUCCESS) {
5451                         DBG_ERROR
5452                             ("[slicmon] Cant dump SRAM at offset %x - "
5453                              "dump failed\n", (uint) offset);
5454                         goto done;
5455                 }
5456
5457                 DBG_MSG("[slicmon] slicDump Write SRAM  len[%x] offset[%x]\n",
5458                         len, file_offset);
5459
5460                 result =
5461                     slic_dump_write(card, card->dumpbuffer, len, file_offset);
5462                 if (!result) {
5463                         DBG_ERROR
5464                             ("[slicmon] Cant write SRAM to dump file - "
5465                              "dump failed\n");
5466                         goto done;
5467                 }
5468
5469                 file_offset += len;
5470                 offset += len;
5471                 sram_size -= len;
5472         }
5473
5474         corehdr.DramOff = file_offset;
5475         corehdr.Dramsize = dram_size;
5476
5477         for (offset = 0; dram_size;) {
5478                 len = MIN(dram_size, DUMP_BUF_SIZE);
5479
5480                 status = slic_dump_data(card, offset, (ushort) len, DESC_DRAM);
5481                 if (status != STATUS_SUCCESS) {
5482                         DBG_ERROR
5483                             ("[slicmon] Cant dump dram at offset %x - "
5484                              "dump failed\n", (uint) offset);
5485                         goto done;
5486                 }
5487
5488                 DBG_MSG("slicDump Write DRAM  len[%x] offset[%x]\n", len,
5489                         file_offset);
5490
5491                 result =
5492                     slic_dump_write(card, card->dumpbuffer, len, file_offset);
5493                 if (!result) {
5494                         DBG_ERROR
5495                             ("[slicmon] Cant write DRAM to dump file - "
5496                              "dump failed\n");
5497                         goto done;
5498                 }
5499
5500                 file_offset += len;
5501                 offset += len;
5502                 dram_size -= len;
5503         }
5504
5505         max_queues = SLIC_MAX_QUEUE;
5506
5507         for (queue = 0; queue < max_queues; queue++) {
5508                 u32 *qarray = (u32 *) card->dumpbuffer;
5509                 u32 qarray_physl = card->dumpbuffer_physl;
5510                 u32 qarray_physh = card->dumpbuffer_physh;
5511                 u32 qstart;
5512                 u32 qdelta;
5513                 u32 qtotal = 0;
5514
5515                 DBG_MSG("[slicmon] Start Dump of QUEUE #0x%x\n", (uint) queue);
5516
5517                 for (offset = 0; offset < (DUMP_BUF_SIZE >> 2); offset++) {
5518                         qstart = jiffies;
5519                         qdelta = 0;
5520
5521                         status = slic_dump_queue(card,
5522                                                  qarray_physl,
5523                                                  qarray_physh, queue);
5524                         qarray_physl += 4;
5525
5526                         if (status != STATUS_SUCCESS)
5527                                 break;
5528
5529                         if (jiffies > qstart) {
5530                                 qdelta = jiffies - qstart;
5531                                 qtotal += qdelta;
5532                         }
5533                 }
5534
5535                 if (offset)
5536                         qdelta = qtotal / offset;
5537                 else
5538                         qdelta = 0;
5539
5540 /*        DBG_MSG("   slicDump Write QUEUE #0x%x len[%x] offset[%x] "
5541                 "avgjiffs[%x]\n", queue, (offset*4), file_offset, qdelta); */
5542
5543                 result =
5544                     slic_dump_write(card, card->dumpbuffer, offset * 4,
5545                                     file_offset);
5546
5547                 if (!result) {
5548                         DBG_ERROR
5549                             ("[slicmon] Cant write QUEUES to dump file - "
5550                              "dump failed\n");
5551                         goto done;
5552                 }
5553
5554                 corehdr.queues[queue].queueOff = file_offset;
5555                 corehdr.queues[queue].queuesize = offset * 4;
5556                 file_offset += offset * 4;
5557
5558 /*      DBG_MSG("    Reload QUEUE #0x%x elements[%x]\n", (uint)queue, offset);*/
5559                 /*
5560                  * Fill the queue back up
5561                  */
5562                 for (i = 0; i < offset; i++) {
5563                         qstart = jiffies;
5564                         qdelta = 0;
5565
5566                         status = slic_dump_load_queue(card, qarray[i], queue);
5567                         if (status != STATUS_SUCCESS)
5568                                 break;
5569
5570                         if (jiffies > qstart) {
5571                                 qdelta = jiffies - qstart;
5572                                 qtotal += qdelta;
5573                         }
5574                 }
5575
5576                 if (offset)
5577                         qdelta = qtotal / offset;
5578                 else
5579                         qdelta = 0;
5580
5581 /*      DBG_MSG("   Reload DONE avgjiffs[%x]\n", qdelta); */
5582
5583                 resume = 1;
5584         }
5585
5586         len = SLIC_GB_CAMAB_SZE * 4;
5587         status = slic_dump_cam(card, 0, len, DUMP_CAM_A);
5588         if (status != STATUS_SUCCESS) {
5589                 DBG_ERROR("[slicmon] Can't dump CAM_A - dump failed\n");
5590                 goto done;
5591         }
5592
5593         result = slic_dump_write(card, card->dumpbuffer, len, file_offset);
5594         if (result) {
5595                 DBG_ERROR
5596                     ("[slicmon] Can't write CAM_A data to dump file - "
5597                      "dump failed\n");
5598                 goto done;
5599         }
5600         corehdr.CamAMOff = file_offset;
5601         corehdr.CamASize = len;
5602         file_offset += len;
5603
5604         len = SLIC_GB_CAMCD_SZE * 4;
5605         status = slic_dump_cam(card, 0, len, DUMP_CAM_C);
5606         if (status) {
5607                 DBG_ERROR("[slicmon] Can't dump CAM_C - dump failed\n");
5608                 goto done;
5609         }
5610
5611         result = slic_dump_write(card, card->dumpbuffer, len, file_offset);
5612         if (result) {
5613                 DBG_ERROR
5614                     ("[slicmon] Can't write CAM_C data to dump file - "
5615                      "dump failed\n");
5616                 goto done;
5617         }
5618         corehdr.CamCMOff = file_offset;
5619         corehdr.CamCSize = len;
5620         file_offset += len;
5621
5622 done:
5623         /*
5624          * Write out the core header
5625          */
5626         file_offset = 0;
5627         DBG_MSG("[slicmon] Write CoreHeader len[%x] offset[%x]\n",
5628                 (uint) sizeof(struct sliccore_hdr), file_offset);
5629
5630         result =
5631             slic_dump_write(card, &corehdr, sizeof(struct sliccore_hdr),
5632                             file_offset);
5633         DBG_MSG("[slicmon] corehdr  xoff[%x] xsz[%x]\n"
5634                 "    roff[%x] rsz[%x] fileoff[%x] filesz[%x]\n"
5635                 "    sramoff[%x] sramsz[%x], dramoff[%x] dramsz[%x]\n"
5636                 "    corehdr_offset[%x]\n", corehdr.XmtRegOff,
5637                 corehdr.XmtRegsize, corehdr.RcvRegOff, corehdr.RcvRegsize,
5638                 corehdr.FileRegOff, corehdr.FileRegsize, corehdr.SramOff,
5639                 corehdr.Sramsize, corehdr.DramOff, corehdr.Dramsize,
5640                 (uint) sizeof(struct sliccore_hdr));
5641         for (i = 0; i < max_queues; i++) {
5642                 DBG_MSG("[slicmon]  QUEUE 0x%x  offset[%x] size[%x]\n",
5643                         (uint) i, corehdr.queues[i].queueOff,
5644                         corehdr.queues[i].queuesize);
5645
5646         }
5647
5648         slic_dump_close_file(card);
5649
5650         if (resume) {
5651                 DBG_MSG("slicDump RESTART RECEIVE and XMIT PROCESSORS\n\n");
5652                 slic_dump_resume(card, PROC_RECEIVE);
5653                 slic_dump_resume(card, PROC_TRANSMIT);
5654         }
5655
5656         return status;
5657 }
5658
5659 static u32 slic_dump_halt(struct sliccard *card, unsigned char proc)
5660 {
5661         unsigned char *cmd = card->cmdbuffer;
5662
5663         *cmd = COMMAND_BYTE(CMD_HALT, 0, proc);
5664
5665         return slic_dump_send_cmd(card,
5666                                    card->cmdbuffer_physl,
5667                                    card->cmdbuffer_physh, 0, 0);
5668 }
5669
5670 static u32 slic_dump_resume(struct sliccard *card, unsigned char proc)
5671 {
5672         unsigned char *cmd = card->cmdbuffer;
5673
5674         *cmd = COMMAND_BYTE(CMD_RUN, 0, proc);
5675
5676         return slic_dump_send_cmd(card,
5677                                    card->cmdbuffer_physl,
5678                                    card->cmdbuffer_physh, 0, 0);
5679 }
5680
5681 static u32 slic_dump_reg(struct sliccard *card, unsigned char proc)
5682 {
5683         struct dump_cmd *dump = (struct dump_cmd *)card->cmdbuffer;
5684
5685         dump->cmd = COMMAND_BYTE(CMD_DUMP, 0, proc);
5686         dump->desc = DESC_REG;
5687         dump->count = 0;
5688         dump->addr = 0;
5689
5690         return slic_dump_send_cmd(card,
5691                                    card->cmdbuffer_physl,
5692                                    card->cmdbuffer_physh,
5693                                    card->dumpbuffer_physl,
5694                                    card->dumpbuffer_physh);
5695 }
5696
5697 static u32 slic_dump_data(struct sliccard *card,
5698                        u32 addr, ushort count, unsigned char desc)
5699 {
5700         struct dump_cmd *dump = (struct dump_cmd *)card->cmdbuffer;
5701
5702         dump->cmd = COMMAND_BYTE(CMD_DUMP, 0, PROC_RECEIVE);
5703         dump->desc = desc;
5704         dump->count = count;
5705         dump->addr = addr;
5706
5707         return slic_dump_send_cmd(card,
5708                                    card->cmdbuffer_physl,
5709                                    card->cmdbuffer_physh,
5710                                    card->dumpbuffer_physl,
5711                                    card->dumpbuffer_physh);
5712 }
5713
5714 static u32 slic_dump_queue(struct sliccard *card,
5715                         u32 addr, u32 buf_physh, u32 queue)
5716 {
5717         struct dump_cmd *dump = (struct dump_cmd *)card->cmdbuffer;
5718
5719         dump->cmd = COMMAND_BYTE(CMD_DUMP, 0, PROC_RECEIVE);
5720         dump->desc = DESC_QUEUE;
5721         dump->count = 1;
5722         dump->addr = queue;
5723
5724         return slic_dump_send_cmd(card,
5725                                    card->cmdbuffer_physl,
5726                                    card->cmdbuffer_physh,
5727                                    addr, card->dumpbuffer_physh);
5728 }
5729
5730 static u32 slic_dump_load_queue(struct sliccard *card, u32 data,
5731                                 u32 queue)
5732 {
5733         struct dump_cmd *load = (struct dump_cmd *) card->cmdbuffer;
5734
5735         load->cmd = COMMAND_BYTE(CMD_LOAD, 0, PROC_RECEIVE);
5736         load->desc = DESC_QUEUE;
5737         load->count = (ushort) queue;
5738         load->addr = data;
5739
5740         return slic_dump_send_cmd(card,
5741                                    card->cmdbuffer_physl,
5742                                    card->cmdbuffer_physh, 0, 0);
5743 }
5744
5745 static u32 slic_dump_cam(struct sliccard *card,
5746                       u32 addr, u32 count, unsigned char desc)
5747 {
5748         struct dump_cmd *dump = (struct dump_cmd *)card->cmdbuffer;
5749
5750         dump->cmd = COMMAND_BYTE(CMD_CAM_OPS, 0, PROC_NONE);
5751         dump->desc = desc;
5752         dump->count = count;
5753         dump->addr = 0;
5754
5755         return slic_dump_send_cmd(card,
5756                                    card->cmdbuffer_physl,
5757                                    card->cmdbuffer_physh,
5758                                    addr, card->dumpbuffer_physh);
5759 }
5760
5761 static u32 slic_dump_send_cmd(struct sliccard *card,
5762                            u32 cmd_physl,
5763                            u32 cmd_physh,
5764                            u32 buf_physl, u32 buf_physh)
5765 {
5766         ulong timeout = SLIC_MS_TO_JIFFIES(500);        /* 500 msec */
5767         u32 attempts = 5;
5768         u32 delay = SLIC_MS_TO_JIFFIES(10);     /* 10 msec */
5769         struct adapter *adapter = card->master;
5770
5771         ASSERT(adapter);
5772         do {
5773                 /*
5774                  * Zero the Dumpstatus field of the adapter structure
5775                  */
5776                 card->dumpstatus = 0;
5777                 /*
5778                  * Issue the dump command via a utility processor request.
5779                  *
5780                  * Kludge: We use the Informationbuffer parameter to hold
5781                  * the buffer address
5782                  */
5783                 slic_upr_request(adapter, SLIC_UPR_DUMP, cmd_physl, cmd_physh,
5784                                  buf_physl, buf_physh);
5785
5786                 timeout += jiffies;
5787                 /*
5788                  * Spin until completion or timeout.
5789                  */
5790                 while (!card->dumpstatus) {
5791                         int num_sleeps = 0;
5792
5793                         if (jiffies > timeout) {
5794                                 /*
5795                                  *  Complete the timed-out DUMP UPR request.
5796                                  */
5797                                 slic_upr_request_complete(adapter, 0);
5798                                 DBG_ERROR
5799                                     ("%s: TIMED OUT num_sleeps[%x] "
5800                                      "status[%x]\n",
5801                                      __func__, num_sleeps, STATUS_FAILURE);
5802
5803                                 return STATUS_FAILURE;
5804                         }
5805                         num_sleeps++;
5806                         SLIC_INTERRUPTIBLE_SLEEP_ON_TIMEOUT(card->dump_wq,
5807                                                             delay);
5808                 }
5809
5810                 if (card->dumpstatus & ISR_UPCERR) {
5811                         /*
5812                          * Error (or queue empty)
5813                          */
5814 /*          DBG_ERROR("[slicmon] %s: DUMP_STATUS & ISR_UPCERR status[%x]\n",
5815                 __func__, STATUS_FAILURE); */
5816
5817                         return STATUS_FAILURE;
5818                 } else if (card->dumpstatus & ISR_UPCBSY) {
5819                         /*
5820                          * Retry
5821                          */
5822                         DBG_ERROR("%s: ISR_UPCBUSY attempt[%x]\n", __func__,
5823                                   attempts);
5824
5825                         attempts--;
5826                 } else {
5827                         /*
5828                          * success
5829                          */
5830                         return STATUS_SUCCESS;
5831                 }
5832
5833         } while (attempts);
5834
5835         DBG_ERROR("%s: GAVE UP AFTER SEVERAL ATTEMPTS status[%x]\n",
5836                   __func__, STATUS_FAILURE);
5837
5838         /*
5839          * Gave up after several attempts
5840          */
5841         return STATUS_FAILURE;
5842 }
5843
5844 #endif
5845 /*=============================================================================
5846   =============================================================================
5847   ===                                                                       ===
5848   ===      *** END **** END **** END **** END ***                           ===
5849   ===       SLIC  DUMP  MANAGEMENT        SECTION                           ===
5850   ===                                                                       ===
5851   ===                                                                       ===
5852   ===                                                                       ===
5853   =============================================================================
5854   ============================================================================*/
5855
5856 /******************************************************************************/
5857 /****************   MODULE INITIATION / TERMINATION FUNCTIONS   ***************/
5858 /******************************************************************************/
5859
5860 static struct pci_driver slic_driver = {
5861         .name = DRV_NAME,
5862         .id_table = slic_pci_tbl,
5863         .probe = slic_entry_probe,
5864         .remove = slic_entry_remove,
5865 #if SLIC_POWER_MANAGEMENT_ENABLED
5866         .suspend = slicpm_suspend,
5867         .resume = slicpm_resume,
5868 #endif
5869 /*    .shutdown   =     slic_shutdown,  MOOK_INVESTIGATE */
5870 };
5871
5872 static int __init slic_module_init(void)
5873 {
5874         struct pci_device_id *pcidev;
5875         int ret;
5876
5877 /*      DBG_MSG("slicoss: %s ENTER cpu %d\n", __func__, smp_processor_id()); */
5878
5879         slic_init_driver();
5880
5881         if (debug >= 0 && slic_debug != debug)
5882                 printk(SLICLEVEL "slicoss: debug level is %d.\n", debug);
5883         if (debug >= 0)
5884                 slic_debug = debug;
5885
5886         pcidev = (struct pci_device_id *)slic_driver.id_table;
5887 /*      DBG_MSG("slicoss: %s call pci_module_init jiffies[%lx] cpu #%d\n",
5888         __func__, jiffies, smp_processor_id()); */
5889
5890         ret = pci_register_driver(&slic_driver);
5891
5892 /*  DBG_MSG("slicoss: %s EXIT after call pci_module_init jiffies[%lx] "
5893             "cpu #%d status[%x]\n",__func__, jiffies,
5894             smp_processor_id(), ret); */
5895
5896         return ret;
5897 }
5898
5899 static void __exit slic_module_cleanup(void)
5900 {
5901 /*      DBG_MSG("slicoss: %s ENTER\n", __func__); */
5902         pci_unregister_driver(&slic_driver);
5903         slic_debug_cleanup();
5904 /*      DBG_MSG("slicoss: %s EXIT\n", __func__); */
5905 }
5906
5907 module_init(slic_module_init);
5908 module_exit(slic_module_cleanup);