Staging: slicoss: remove jiffies macros
[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_KERNEL);
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 = jiffies + (PING_TIMER_INTERVAL * HZ);
1717         add_timer(&adapter->pingtimer);
1718 }
1719
1720 static void slic_if_stop_queue(struct adapter *adapter)
1721 {
1722         netif_stop_queue(adapter->netdev);
1723 }
1724
1725 static void slic_if_start_queue(struct adapter *adapter)
1726 {
1727         netif_start_queue(adapter->netdev);
1728 }
1729
1730 /*
1731  *  slic_if_init
1732  *
1733  *  Perform initialization of our slic interface.
1734  *
1735  */
1736 static int slic_if_init(struct adapter *adapter)
1737 {
1738         struct sliccard *card = adapter->card;
1739         struct net_device *dev = adapter->netdev;
1740         __iomem struct slic_regs *slic_regs = adapter->slic_regs;
1741         struct slic_shmem *pshmem;
1742         int status = 0;
1743
1744         ASSERT(card);
1745         DBG_MSG("slicoss: %s (%s) ENTER states[%d:%d:%d:%d] flags[%x]\n",
1746                 __func__, adapter->netdev->name,
1747                 adapter->queues_initialized, adapter->state, adapter->linkstate,
1748                 card->state, dev->flags);
1749
1750         /* adapter should be down at this point */
1751         if (adapter->state != ADAPT_DOWN) {
1752                 DBG_ERROR("slic_if_init adapter->state != ADAPT_DOWN\n");
1753                 return -EIO;
1754         }
1755         ASSERT(adapter->linkstate == LINK_DOWN);
1756
1757         adapter->devflags_prev = dev->flags;
1758         adapter->macopts = MAC_DIRECTED;
1759         if (dev->flags) {
1760                 DBG_MSG("slicoss: %s (%s) Set MAC options: ", __func__,
1761                         adapter->netdev->name);
1762                 if (dev->flags & IFF_BROADCAST) {
1763                         adapter->macopts |= MAC_BCAST;
1764                         DBG_MSG("BCAST ");
1765                 }
1766                 if (dev->flags & IFF_PROMISC) {
1767                         adapter->macopts |= MAC_PROMISC;
1768                         DBG_MSG("PROMISC ");
1769                 }
1770                 if (dev->flags & IFF_ALLMULTI) {
1771                         adapter->macopts |= MAC_ALLMCAST;
1772                         DBG_MSG("ALL_MCAST ");
1773                 }
1774                 if (dev->flags & IFF_MULTICAST) {
1775                         adapter->macopts |= MAC_MCAST;
1776                         DBG_MSG("MCAST ");
1777                 }
1778                 DBG_MSG("\n");
1779         }
1780         status = slic_adapter_allocresources(adapter);
1781         if (status != STATUS_SUCCESS) {
1782                 DBG_ERROR
1783                     ("slic_if_init: slic_adapter_allocresources FAILED %x\n",
1784                      status);
1785                 slic_adapter_freeresources(adapter);
1786                 return status;
1787         }
1788
1789         if (!adapter->queues_initialized) {
1790                 DBG_MSG("slicoss: %s call slic_rspqueue_init\n", __func__);
1791                 if (slic_rspqueue_init(adapter))
1792                         return -ENOMEM;
1793                 DBG_MSG
1794                     ("slicoss: %s call slic_cmdq_init adapter[%p] port %d \n",
1795                      __func__, adapter, adapter->port);
1796                 if (slic_cmdq_init(adapter))
1797                         return -ENOMEM;
1798                 DBG_MSG
1799                     ("slicoss: %s call slic_rcvqueue_init adapter[%p] \
1800                      port %d \n", __func__, adapter, adapter->port);
1801                 if (slic_rcvqueue_init(adapter))
1802                         return -ENOMEM;
1803                 adapter->queues_initialized = 1;
1804         }
1805         DBG_MSG("slicoss: %s disable interrupts(slic)\n", __func__);
1806
1807         WRITE_REG(slic_regs->slic_icr, ICR_INT_OFF, FLUSH);
1808         mdelay(1);
1809
1810         if (!adapter->isp_initialized) {
1811                 pshmem = (struct slic_shmem *)adapter->phys_shmem;
1812
1813                 spin_lock_irqsave(&adapter->bit64reglock.lock,
1814                                         adapter->bit64reglock.flags);
1815
1816 #if defined(CONFIG_X86_64)
1817                 WRITE_REG(slic_regs->slic_addr_upper,
1818                           SLIC_GET_ADDR_HIGH(&pshmem->isr), DONT_FLUSH);
1819                 WRITE_REG(slic_regs->slic_isp,
1820                           SLIC_GET_ADDR_LOW(&pshmem->isr), FLUSH);
1821 #elif defined(CONFIG_X86)
1822                 WRITE_REG(slic_regs->slic_addr_upper, (u32) 0, DONT_FLUSH);
1823                 WRITE_REG(slic_regs->slic_isp, (u32) &pshmem->isr, FLUSH);
1824 #else
1825                 Stop Compilations
1826 #endif
1827                 spin_unlock_irqrestore(&adapter->bit64reglock.lock,
1828                                         adapter->bit64reglock.flags);
1829                 adapter->isp_initialized = 1;
1830         }
1831
1832         adapter->state = ADAPT_UP;
1833         if (!card->loadtimerset) {
1834                 init_timer(&card->loadtimer);
1835                 card->loadtimer.expires =
1836                     jiffies + (SLIC_LOADTIMER_PERIOD * HZ);
1837                 card->loadtimer.data = (ulong) card;
1838                 card->loadtimer.function = &slic_timer_load_check;
1839                 add_timer(&card->loadtimer);
1840
1841                 card->loadtimerset = 1;
1842         }
1843 #if SLIC_GET_STATS_TIMER_ENABLED
1844         if (!adapter->statstimerset) {
1845                 DBG_MSG("slicoss: %s start getstats_timer(slic)\n",
1846                         __func__);
1847                 init_timer(&adapter->statstimer);
1848                 adapter->statstimer.expires =
1849                     jiffies + (STATS_TIMER_INTERVAL * HZ);
1850                 adapter->statstimer.data = (ulong) adapter->netdev;
1851                 adapter->statstimer.function = &slic_timer_get_stats;
1852                 add_timer(&adapter->statstimer);
1853                 adapter->statstimerset = 1;
1854         }
1855 #endif
1856 #if !SLIC_DUMP_ENABLED && SLIC_PING_TIMER_ENABLED
1857 /*#if SLIC_DUMP_ENABLED && SLIC_PING_TIMER_ENABLED*/
1858         if (!adapter->pingtimerset) {
1859                 DBG_MSG("slicoss: %s start card_ping_timer(slic)\n",
1860                         __func__);
1861                 init_timer(&adapter->pingtimer);
1862                 adapter->pingtimer.expires =
1863                     jiffies + (PING_TIMER_INTERVAL * HZ);
1864                 adapter->pingtimer.data = (ulong) dev;
1865                 adapter->pingtimer.function = &slic_timer_ping;
1866                 add_timer(&adapter->pingtimer);
1867                 adapter->pingtimerset = 1;
1868                 adapter->card->pingstatus = ISR_PINGMASK;
1869         }
1870 #endif
1871
1872         /*
1873          *    clear any pending events, then enable interrupts
1874          */
1875         DBG_MSG("slicoss: %s ENABLE interrupts(slic)\n", __func__);
1876         adapter->isrcopy = 0;
1877         adapter->pshmem->isr = 0;
1878         WRITE_REG(slic_regs->slic_isr, 0, FLUSH);
1879         WRITE_REG(slic_regs->slic_icr, ICR_INT_ON, FLUSH);
1880
1881         DBG_MSG("slicoss: %s call slic_link_config(slic)\n", __func__);
1882         slic_link_config(adapter, LINK_AUTOSPEED, LINK_AUTOD);
1883         slic_link_event_handler(adapter);
1884
1885         DBG_MSG("slicoss: %s EXIT\n", __func__);
1886         return STATUS_SUCCESS;
1887 }
1888
1889 static void slic_unmap_mmio_space(struct adapter *adapter)
1890 {
1891 #if LINUX_FREES_ADAPTER_RESOURCES
1892         if (adapter->slic_regs)
1893                 iounmap(adapter->slic_regs);
1894         adapter->slic_regs = NULL;
1895 #endif
1896 }
1897
1898 static int slic_adapter_allocresources(struct adapter *adapter)
1899 {
1900         if (!adapter->intrregistered) {
1901                 int retval;
1902
1903                 DBG_MSG
1904                     ("slicoss: %s AllocAdaptRsrcs adapter[%p] shmem[%p] \
1905                      phys_shmem[%p] dev->irq[%x] %x\n",
1906                      __func__, adapter, adapter->pshmem,
1907                      (void *)adapter->phys_shmem, adapter->netdev->irq,
1908                      NR_IRQS);
1909
1910                 spin_unlock_irqrestore(&slic_global.driver_lock.lock,
1911                                         slic_global.driver_lock.flags);
1912
1913                 retval = request_irq(adapter->netdev->irq,
1914                                      &slic_interrupt,
1915                                      IRQF_SHARED,
1916                                      adapter->netdev->name, adapter->netdev);
1917
1918                 spin_lock_irqsave(&slic_global.driver_lock.lock,
1919                                         slic_global.driver_lock.flags);
1920
1921                 if (retval) {
1922                         DBG_ERROR("slicoss: request_irq (%s) FAILED [%x]\n",
1923                                   adapter->netdev->name, retval);
1924                         return retval;
1925                 }
1926                 adapter->intrregistered = 1;
1927                 DBG_MSG
1928                     ("slicoss: %s AllocAdaptRsrcs adapter[%p] shmem[%p] \
1929                      pshmem[%p] dev->irq[%x]\n",
1930                      __func__, adapter, adapter->pshmem,
1931                      (void *)adapter->pshmem, adapter->netdev->irq);
1932         }
1933         return STATUS_SUCCESS;
1934 }
1935
1936 static void slic_config_pci(struct pci_dev *pcidev)
1937 {
1938         u16 pci_command;
1939         u16 new_command;
1940
1941         pci_read_config_word(pcidev, PCI_COMMAND, &pci_command);
1942         DBG_MSG("slicoss: %s  PCI command[%4.4x]\n", __func__, pci_command);
1943
1944         new_command = pci_command | PCI_COMMAND_MASTER
1945             | PCI_COMMAND_MEMORY
1946             | PCI_COMMAND_INVALIDATE
1947             | PCI_COMMAND_PARITY | PCI_COMMAND_SERR | PCI_COMMAND_FAST_BACK;
1948         if (pci_command != new_command) {
1949                 DBG_MSG("%s -- Updating PCI COMMAND register %4.4x->%4.4x.\n",
1950                         __func__, pci_command, new_command);
1951                 pci_write_config_word(pcidev, PCI_COMMAND, new_command);
1952         }
1953 }
1954
1955 static void slic_adapter_freeresources(struct adapter *adapter)
1956 {
1957         DBG_MSG("slicoss: %s ENTER adapter[%p]\n", __func__, adapter);
1958         slic_init_cleanup(adapter);
1959         memset(&adapter->stats, 0, sizeof(struct net_device_stats));
1960         adapter->error_interrupts = 0;
1961         adapter->rcv_interrupts = 0;
1962         adapter->xmit_interrupts = 0;
1963         adapter->linkevent_interrupts = 0;
1964         adapter->upr_interrupts = 0;
1965         adapter->num_isrs = 0;
1966         adapter->xmit_completes = 0;
1967         adapter->rcv_broadcasts = 0;
1968         adapter->rcv_multicasts = 0;
1969         adapter->rcv_unicasts = 0;
1970         DBG_MSG("slicoss: %s EXIT\n", __func__);
1971 }
1972
1973 /*
1974  *  slic_link_config
1975  *
1976  *  Write phy control to configure link duplex/speed
1977  *
1978  */
1979 static void slic_link_config(struct adapter *adapter,
1980                       u32 linkspeed, u32 linkduplex)
1981 {
1982         u32 speed;
1983         u32 duplex;
1984         u32 phy_config;
1985         u32 phy_advreg;
1986         u32 phy_gctlreg;
1987
1988         if (adapter->state != ADAPT_UP) {
1989                 DBG_MSG
1990                     ("%s (%s) ADAPT Not up yet, Return! speed[%x] duplex[%x]\n",
1991                      __func__, adapter->netdev->name, linkspeed,
1992                      linkduplex);
1993                 return;
1994         }
1995         DBG_MSG("slicoss: %s (%s) slic_link_config: speed[%x] duplex[%x]\n",
1996                 __func__, adapter->netdev->name, linkspeed, linkduplex);
1997
1998         ASSERT((adapter->devid == SLIC_1GB_DEVICE_ID)
1999                || (adapter->devid == SLIC_2GB_DEVICE_ID));
2000
2001         if (linkspeed > LINK_1000MB)
2002                 linkspeed = LINK_AUTOSPEED;
2003         if (linkduplex > LINK_AUTOD)
2004                 linkduplex = LINK_AUTOD;
2005
2006         if ((linkspeed == LINK_AUTOSPEED) || (linkspeed == LINK_1000MB)) {
2007                 if (adapter->flags & ADAPT_FLAGS_FIBERMEDIA) {
2008                         /*  We've got a fiber gigabit interface, and register
2009                          *  4 is different in fiber mode than in copper mode
2010                          */
2011
2012                         /* advertise FD only @1000 Mb */
2013                         phy_advreg = (MIICR_REG_4 | (PAR_ADV1000XFD));
2014                         /* enable PAUSE frames        */
2015                         phy_advreg |= PAR_ASYMPAUSE_FIBER;
2016                         WRITE_REG(adapter->slic_regs->slic_wphy, phy_advreg,
2017                                   FLUSH);
2018
2019                         if (linkspeed == LINK_AUTOSPEED) {
2020                                 /* reset phy, enable auto-neg  */
2021                                 phy_config =
2022                                     (MIICR_REG_PCR |
2023                                      (PCR_RESET | PCR_AUTONEG |
2024                                       PCR_AUTONEG_RST));
2025                                 WRITE_REG(adapter->slic_regs->slic_wphy,
2026                                           phy_config, FLUSH);
2027                         } else {        /* forced 1000 Mb FD*/
2028                                 /* power down phy to break link
2029                                    this may not work) */
2030                                 phy_config = (MIICR_REG_PCR | PCR_POWERDOWN);
2031                                 WRITE_REG(adapter->slic_regs->slic_wphy,
2032                                           phy_config, FLUSH);
2033                                 /* wait, Marvell says 1 sec,
2034                                    try to get away with 10 ms  */
2035                                 mdelay(10);
2036
2037                                 /* disable auto-neg, set speed/duplex,
2038                                    soft reset phy, powerup */
2039                                 phy_config =
2040                                     (MIICR_REG_PCR |
2041                                      (PCR_RESET | PCR_SPEED_1000 |
2042                                       PCR_DUPLEX_FULL));
2043                                 WRITE_REG(adapter->slic_regs->slic_wphy,
2044                                           phy_config, FLUSH);
2045                         }
2046                 } else {        /* copper gigabit */
2047
2048                         /* Auto-Negotiate or 1000 Mb must be auto negotiated
2049                          * We've got a copper gigabit interface, and
2050                          * register 4 is different in copper mode than
2051                          * in fiber mode
2052                          */
2053                         if (linkspeed == LINK_AUTOSPEED) {
2054                                 /* advertise 10/100 Mb modes   */
2055                                 phy_advreg =
2056                                     (MIICR_REG_4 |
2057                                      (PAR_ADV100FD | PAR_ADV100HD | PAR_ADV10FD
2058                                       | PAR_ADV10HD));
2059                         } else {
2060                         /* linkspeed == LINK_1000MB -
2061                            don't advertise 10/100 Mb modes  */
2062                                 phy_advreg = MIICR_REG_4;
2063                         }
2064                         /* enable PAUSE frames  */
2065                         phy_advreg |= PAR_ASYMPAUSE;
2066                         /* required by the Cicada PHY  */
2067                         phy_advreg |= PAR_802_3;
2068                         WRITE_REG(adapter->slic_regs->slic_wphy, phy_advreg,
2069                                   FLUSH);
2070                         /* advertise FD only @1000 Mb  */
2071                         phy_gctlreg = (MIICR_REG_9 | (PGC_ADV1000FD));
2072                         WRITE_REG(adapter->slic_regs->slic_wphy, phy_gctlreg,
2073                                   FLUSH);
2074
2075                         if (adapter->subsysid != SLIC_1GB_CICADA_SUBSYS_ID) {
2076                                 /* if a Marvell PHY
2077                                    enable auto crossover */
2078                                 phy_config =
2079                                     (MIICR_REG_16 | (MRV_REG16_XOVERON));
2080                                 WRITE_REG(adapter->slic_regs->slic_wphy,
2081                                           phy_config, FLUSH);
2082
2083                                 /* reset phy, enable auto-neg  */
2084                                 phy_config =
2085                                     (MIICR_REG_PCR |
2086                                      (PCR_RESET | PCR_AUTONEG |
2087                                       PCR_AUTONEG_RST));
2088                                 WRITE_REG(adapter->slic_regs->slic_wphy,
2089                                           phy_config, FLUSH);
2090                         } else {        /* it's a Cicada PHY  */
2091                                 /* enable and restart auto-neg (don't reset)  */
2092                                 phy_config =
2093                                     (MIICR_REG_PCR |
2094                                      (PCR_AUTONEG | PCR_AUTONEG_RST));
2095                                 WRITE_REG(adapter->slic_regs->slic_wphy,
2096                                           phy_config, FLUSH);
2097                         }
2098                 }
2099         } else {
2100                 /* Forced 10/100  */
2101                 if (linkspeed == LINK_10MB)
2102                         speed = 0;
2103                 else
2104                         speed = PCR_SPEED_100;
2105                 if (linkduplex == LINK_HALFD)
2106                         duplex = 0;
2107                 else
2108                         duplex = PCR_DUPLEX_FULL;
2109
2110                 if (adapter->subsysid != SLIC_1GB_CICADA_SUBSYS_ID) {
2111                         /* if a Marvell PHY
2112                            disable auto crossover  */
2113                         phy_config = (MIICR_REG_16 | (MRV_REG16_XOVEROFF));
2114                         WRITE_REG(adapter->slic_regs->slic_wphy, phy_config,
2115                                   FLUSH);
2116                 }
2117
2118                 /* power down phy to break link (this may not work)  */
2119                 phy_config = (MIICR_REG_PCR | (PCR_POWERDOWN | speed | duplex));
2120                 WRITE_REG(adapter->slic_regs->slic_wphy, phy_config, FLUSH);
2121
2122                 /* wait, Marvell says 1 sec, try to get away with 10 ms */
2123                 mdelay(10);
2124
2125                 if (adapter->subsysid != SLIC_1GB_CICADA_SUBSYS_ID) {
2126                         /* if a Marvell PHY
2127                            disable auto-neg, set speed,
2128                            soft reset phy, powerup */
2129                         phy_config =
2130                             (MIICR_REG_PCR | (PCR_RESET | speed | duplex));
2131                         WRITE_REG(adapter->slic_regs->slic_wphy, phy_config,
2132                                   FLUSH);
2133                 } else {        /* it's a Cicada PHY  */
2134                         /* disable auto-neg, set speed, powerup  */
2135                         phy_config = (MIICR_REG_PCR | (speed | duplex));
2136                         WRITE_REG(adapter->slic_regs->slic_wphy, phy_config,
2137                                   FLUSH);
2138                 }
2139         }
2140
2141         DBG_MSG
2142             ("slicoss: %s (%s) EXIT slic_link_config : state[%d] \
2143             phy_config[%x]\n", __func__, adapter->netdev->name, adapter->state,
2144             phy_config);
2145 }
2146
2147 static void slic_card_cleanup(struct sliccard *card)
2148 {
2149         DBG_MSG("slicoss: %s ENTER\n", __func__);
2150
2151 #if SLIC_DUMP_ENABLED
2152         if (card->dumpbuffer) {
2153                 card->dumpbuffer_phys = 0;
2154                 card->dumpbuffer_physl = 0;
2155                 card->dumpbuffer_physh = 0;
2156                 kfree(card->dumpbuffer);
2157                 card->dumpbuffer = NULL;
2158         }
2159         if (card->cmdbuffer) {
2160                 card->cmdbuffer_phys = 0;
2161                 card->cmdbuffer_physl = 0;
2162                 card->cmdbuffer_physh = 0;
2163                 kfree(card->cmdbuffer);
2164                 card->cmdbuffer = NULL;
2165         }
2166 #endif
2167
2168         if (card->loadtimerset) {
2169                 card->loadtimerset = 0;
2170                 del_timer(&card->loadtimer);
2171         }
2172
2173         slic_debug_card_destroy(card);
2174
2175         kfree(card);
2176         DBG_MSG("slicoss: %s EXIT\n", __func__);
2177 }
2178
2179 static int slic_card_download_gbrcv(struct adapter *adapter)
2180 {
2181         const struct firmware *fw;
2182         const char *file = "";
2183         int ret;
2184         __iomem struct slic_regs *slic_regs = adapter->slic_regs;
2185         u32 codeaddr;
2186         u32 instruction;
2187         int index = 0;
2188         u32 rcvucodelen = 0;
2189
2190         switch (adapter->devid) {
2191         case SLIC_2GB_DEVICE_ID:
2192                 file = "slicoss/oasisrcvucode.sys";
2193                 break;
2194         case SLIC_1GB_DEVICE_ID:
2195                 file = "slicoss/gbrcvucode.sys";
2196                 break;
2197         default:
2198                 ASSERT(0);
2199                 break;
2200         }
2201
2202         ret = request_firmware(&fw, file, &adapter->pcidev->dev);
2203         if (ret) {
2204                 printk(KERN_ERR "SLICOSS: Failed to load firmware %s\n", file);
2205                 return ret;
2206         }
2207
2208         rcvucodelen = *(u32 *)(fw->data + index);
2209         index += 4;
2210         switch (adapter->devid) {
2211         case SLIC_2GB_DEVICE_ID:
2212                 if (rcvucodelen != OasisRcvUCodeLen)
2213                         return -EINVAL;
2214                 break;
2215         case SLIC_1GB_DEVICE_ID:
2216                 if (rcvucodelen != GBRcvUCodeLen)
2217                         return -EINVAL;
2218                 break;
2219         default:
2220                 ASSERT(0);
2221                 break;
2222         }
2223         /* start download */
2224         WRITE_REG(slic_regs->slic_rcv_wcs, SLIC_RCVWCS_BEGIN, FLUSH);
2225         /* download the rcv sequencer ucode */
2226         for (codeaddr = 0; codeaddr < rcvucodelen; codeaddr++) {
2227                 /* write out instruction address */
2228                 WRITE_REG(slic_regs->slic_rcv_wcs, codeaddr, FLUSH);
2229
2230                 instruction = *(u32 *)(fw->data + index);
2231                 index += 4;
2232                 /* write out the instruction data low addr */
2233                 WRITE_REG(slic_regs->slic_rcv_wcs,
2234                           instruction, FLUSH);
2235
2236                 instruction = *(u8 *)(fw->data + index);
2237                 index++;
2238                 /* write out the instruction data high addr */
2239                 WRITE_REG(slic_regs->slic_rcv_wcs, (u8)instruction,
2240                           FLUSH);
2241         }
2242
2243         /* download finished */
2244         release_firmware(fw);
2245         WRITE_REG(slic_regs->slic_rcv_wcs, SLIC_RCVWCS_FINISH, FLUSH);
2246         return 0;
2247 }
2248
2249 static int slic_card_download(struct adapter *adapter)
2250 {
2251         const struct firmware *fw;
2252         const char *file = "";
2253         int ret;
2254         u32 section;
2255         int thissectionsize;
2256         int codeaddr;
2257         __iomem struct slic_regs *slic_regs = adapter->slic_regs;
2258         u32 instruction;
2259         u32 baseaddress;
2260         u32 failure;
2261         u32 i;
2262         u32 numsects = 0;
2263         u32 sectsize[3];
2264         u32 sectstart[3];
2265         int ucode_start, index = 0;
2266
2267 /*      DBG_MSG ("slicoss: %s (%s) adapter[%p] card[%p] devid[%x] \
2268         jiffies[%lx] cpu %d\n", __func__, adapter->netdev->name, adapter,
2269             adapter->card, adapter->devid,jiffies, smp_processor_id()); */
2270
2271         switch (adapter->devid) {
2272         case SLIC_2GB_DEVICE_ID:
2273                 file = "slicoss/oasisdownload.sys";
2274                 break;
2275         case SLIC_1GB_DEVICE_ID:
2276                 file = "slicoss/gbdownload.sys";
2277                 break;
2278         default:
2279                 ASSERT(0);
2280                 break;
2281         }
2282         ret = request_firmware(&fw, file, &adapter->pcidev->dev);
2283         if (ret) {
2284                 printk(KERN_ERR "SLICOSS: Failed to load firmware %s\n", file);
2285                 return ret;
2286         }
2287         numsects = *(u32 *)(fw->data + index);
2288         index += 4;
2289         ASSERT(numsects <= 3);
2290         for (i = 0; i < numsects; i++) {
2291                 sectsize[i] = *(u32 *)(fw->data + index);
2292                 index += 4;
2293         }
2294         for (i = 0; i < numsects; i++) {
2295                 sectstart[i] = *(u32 *)(fw->data + index);
2296                 index += 4;
2297         }
2298         ucode_start = index;
2299         instruction = *(u32 *)(fw->data + index);
2300         index += 4;
2301         for (section = 0; section < numsects; section++) {
2302                 baseaddress = sectstart[section];
2303                 thissectionsize = sectsize[section] >> 3;
2304
2305                 for (codeaddr = 0; codeaddr < thissectionsize; codeaddr++) {
2306                         /* Write out instruction address */
2307                         WRITE_REG(slic_regs->slic_wcs, baseaddress + codeaddr,
2308                                   FLUSH);
2309                         /* Write out instruction to low addr */
2310                         WRITE_REG(slic_regs->slic_wcs, instruction, FLUSH);
2311                         instruction = *(u32 *)(fw->data + index);
2312                         index += 4;
2313
2314                         /* Write out instruction to high addr */
2315                         WRITE_REG(slic_regs->slic_wcs, instruction, FLUSH);
2316                         instruction = *(u32 *)(fw->data + index);
2317                         index += 4;
2318                 }
2319         }
2320         index = ucode_start;
2321         for (section = 0; section < numsects; section++) {
2322                 instruction = *(u32 *)(fw->data + index);
2323                 baseaddress = sectstart[section];
2324                 if (baseaddress < 0x8000)
2325                         continue;
2326                 thissectionsize = sectsize[section] >> 3;
2327
2328 /*        DBG_MSG ("slicoss: COMPARE secton[%x] baseaddr[%x] sectnsize[%x]\n",
2329                 (uint)section,baseaddress,thissectionsize);*/
2330                 for (codeaddr = 0; codeaddr < thissectionsize; codeaddr++) {
2331                         /* Write out instruction address */
2332                         WRITE_REG(slic_regs->slic_wcs,
2333                                   SLIC_WCS_COMPARE | (baseaddress + codeaddr),
2334                                   FLUSH);
2335                         /* Write out instruction to low addr */
2336                         WRITE_REG(slic_regs->slic_wcs, instruction, FLUSH);
2337                         instruction = *(u32 *)(fw->data + index);
2338                         index += 4;
2339                         /* Write out instruction to high addr */
2340                         WRITE_REG(slic_regs->slic_wcs, instruction, FLUSH);
2341                         instruction = *(u32 *)(fw->data + index);
2342                         index += 4;
2343
2344                         /* Check SRAM location zero. If it is non-zero. Abort.*/
2345 /*                      failure = readl((u32 __iomem *)&slic_regs->slic_reset);
2346                         if (failure) {
2347                                 DBG_MSG
2348                                     ("slicoss: %s FAILURE EXIT codeaddr[%x] "
2349                                     "thissectionsize[%x] failure[%x]\n",
2350                                      __func__, codeaddr, thissectionsize,
2351                                      failure);
2352                                 release_firmware(fw);
2353                                 return -EIO;
2354                         }*/
2355                 }
2356         }
2357 /*    DBG_MSG ("slicoss: Compare done\n");*/
2358         release_firmware(fw);
2359         /* Everything OK, kick off the card */
2360         mdelay(10);
2361         WRITE_REG(slic_regs->slic_wcs, SLIC_WCS_START, FLUSH);
2362
2363         /* stall for 20 ms, long enough for ucode to init card
2364            and reach mainloop */
2365         mdelay(20);
2366
2367         DBG_MSG("slicoss: %s (%s) EXIT adapter[%p] card[%p]\n",
2368                 __func__, adapter->netdev->name, adapter, adapter->card);
2369
2370         return STATUS_SUCCESS;
2371 }
2372
2373 static void slic_adapter_set_hwaddr(struct adapter *adapter)
2374 {
2375         struct sliccard *card = adapter->card;
2376
2377 /*  DBG_MSG ("%s ENTER card->config_set[%x] port[%d] physport[%d] funct#[%d]\n",
2378     __func__, card->config_set, adapter->port, adapter->physport,
2379     adapter->functionnumber);
2380
2381     slic_dbg_macaddrs(adapter); */
2382
2383         if ((adapter->card) && (card->config_set)) {
2384                 memcpy(adapter->macaddr,
2385                        card->config.MacInfo[adapter->functionnumber].macaddrA,
2386                        sizeof(struct slic_config_mac));
2387 /*      DBG_MSG ("%s AFTER copying from config.macinfo into currmacaddr\n",
2388         __func__);
2389         slic_dbg_macaddrs(adapter);*/
2390                 if (!(adapter->currmacaddr[0] || adapter->currmacaddr[1] ||
2391                       adapter->currmacaddr[2] || adapter->currmacaddr[3] ||
2392                       adapter->currmacaddr[4] || adapter->currmacaddr[5])) {
2393                         memcpy(adapter->currmacaddr, adapter->macaddr, 6);
2394                 }
2395                 if (adapter->netdev) {
2396                         memcpy(adapter->netdev->dev_addr, adapter->currmacaddr,
2397                                6);
2398                 }
2399         }
2400 /*  DBG_MSG ("%s EXIT port %d\n", __func__, adapter->port);
2401     slic_dbg_macaddrs(adapter); */
2402 }
2403
2404 static void slic_intagg_set(struct adapter *adapter, u32 value)
2405 {
2406         __iomem struct slic_regs *slic_regs = adapter->slic_regs;
2407
2408         WRITE_REG(slic_regs->slic_intagg, value, FLUSH);
2409         adapter->card->loadlevel_current = value;
2410 }
2411
2412 static int slic_card_init(struct sliccard *card, struct adapter *adapter)
2413 {
2414         __iomem struct slic_regs *slic_regs = adapter->slic_regs;
2415         struct slic_eeprom *peeprom;
2416         struct oslic_eeprom *pOeeprom;
2417         dma_addr_t phys_config;
2418         u32 phys_configh;
2419         u32 phys_configl;
2420         u32 i = 0;
2421         struct slic_shmem *pshmem;
2422         int status;
2423         uint macaddrs = card->card_size;
2424         ushort eecodesize;
2425         ushort dramsize;
2426         ushort ee_chksum;
2427         ushort calc_chksum;
2428         struct slic_config_mac *pmac;
2429         unsigned char fruformat;
2430         unsigned char oemfruformat;
2431         struct atk_fru *patkfru;
2432         union oemfru *poemfru;
2433
2434         DBG_MSG
2435             ("slicoss: %s ENTER card[%p] adapter[%p] card->state[%x] \
2436             size[%d]\n", __func__, card, adapter, card->state, card->card_size);
2437
2438         /* Reset everything except PCI configuration space */
2439         slic_soft_reset(adapter);
2440
2441         /* Download the microcode */
2442         status = slic_card_download(adapter);
2443
2444         if (status != STATUS_SUCCESS) {
2445                 DBG_ERROR("SLIC download failed bus %d slot %d\n",
2446                           (uint) adapter->busnumber,
2447                           (uint) adapter->slotnumber);
2448                 return status;
2449         }
2450
2451         if (!card->config_set) {
2452                 peeprom = pci_alloc_consistent(adapter->pcidev,
2453                                                sizeof(struct slic_eeprom),
2454                                                &phys_config);
2455
2456                 phys_configl = SLIC_GET_ADDR_LOW(phys_config);
2457                 phys_configh = SLIC_GET_ADDR_HIGH(phys_config);
2458
2459                 DBG_MSG("slicoss: %s Eeprom info  adapter [%p]\n    "
2460                         "size        [%x]\n    peeprom     [%p]\n    "
2461                         "phys_config [%p]\n    phys_configl[%x]\n    "
2462                         "phys_configh[%x]\n",
2463                         __func__, adapter,
2464                         (u32)sizeof(struct slic_eeprom),
2465                         peeprom, (void *) phys_config, phys_configl,
2466                         phys_configh);
2467                 if (!peeprom) {
2468                         DBG_ERROR
2469                             ("SLIC eeprom read failed to get memory bus %d \
2470                             slot %d\n",
2471                              (uint) adapter->busnumber,
2472                              (uint) adapter->slotnumber);
2473                         return -ENOMEM;
2474                 } else {
2475                         memset(peeprom, 0, sizeof(struct slic_eeprom));
2476                 }
2477                 WRITE_REG(slic_regs->slic_icr, ICR_INT_OFF, FLUSH);
2478                 mdelay(1);
2479                 pshmem = (struct slic_shmem *)adapter->phys_shmem;
2480
2481                 spin_lock_irqsave(&adapter->bit64reglock.lock,
2482                                         adapter->bit64reglock.flags);
2483                 WRITE_REG(slic_regs->slic_addr_upper, 0, DONT_FLUSH);
2484                 WRITE_REG(slic_regs->slic_isp,
2485                           SLIC_GET_ADDR_LOW(&pshmem->isr), FLUSH);
2486                 spin_unlock_irqrestore(&adapter->bit64reglock.lock,
2487                                         adapter->bit64reglock.flags);
2488
2489                 slic_config_get(adapter, phys_configl, phys_configh);
2490
2491                 for (;;) {
2492                         if (adapter->pshmem->isr) {
2493                                 DBG_MSG("%s shmem[%p] shmem->isr[%x]\n",
2494                                         __func__, adapter->pshmem,
2495                                         adapter->pshmem->isr);
2496
2497                                 if (adapter->pshmem->isr & ISR_UPC) {
2498                                         adapter->pshmem->isr = 0;
2499                                         WRITE_REG64(adapter,
2500                                                     slic_regs->slic_isp,
2501                                                     0,
2502                                                     slic_regs->slic_addr_upper,
2503                                                     0, FLUSH);
2504                                         WRITE_REG(slic_regs->slic_isr, 0,
2505                                                   FLUSH);
2506
2507                                         slic_upr_request_complete(adapter, 0);
2508                                         break;
2509                                 } else {
2510                                         adapter->pshmem->isr = 0;
2511                                         WRITE_REG(slic_regs->slic_isr, 0,
2512                                                   FLUSH);
2513                                 }
2514                         } else {
2515                                 mdelay(1);
2516                                 i++;
2517                                 if (i > 5000) {
2518                                         DBG_ERROR
2519                                             ("SLIC: %d config data fetch timed "
2520                                               "out!\n", adapter->port);
2521                                         DBG_MSG("%s shmem[%p] shmem->isr[%x]\n",
2522                                                 __func__, adapter->pshmem,
2523                                                 adapter->pshmem->isr);
2524                                         WRITE_REG64(adapter,
2525                                                     slic_regs->slic_isp, 0,
2526                                                     slic_regs->slic_addr_upper,
2527                                                     0, FLUSH);
2528                                         return -EINVAL;
2529                                 }
2530                         }
2531                 }
2532
2533                 switch (adapter->devid) {
2534                 /* Oasis card */
2535                 case SLIC_2GB_DEVICE_ID:
2536                         /* extract EEPROM data and pointers to EEPROM data */
2537                         pOeeprom = (struct oslic_eeprom *) peeprom;
2538                         eecodesize = pOeeprom->EecodeSize;
2539                         dramsize = pOeeprom->DramSize;
2540                         pmac = pOeeprom->MacInfo;
2541                         fruformat = pOeeprom->FruFormat;
2542                         patkfru = &pOeeprom->AtkFru;
2543                         oemfruformat = pOeeprom->OemFruFormat;
2544                         poemfru = &pOeeprom->OemFru;
2545                         macaddrs = 2;
2546                         /* Minor kludge for Oasis card
2547                              get 2 MAC addresses from the
2548                              EEPROM to ensure that function 1
2549                              gets the Port 1 MAC address */
2550                         break;
2551                 default:
2552                         /* extract EEPROM data and pointers to EEPROM data */
2553                         eecodesize = peeprom->EecodeSize;
2554                         dramsize = peeprom->DramSize;
2555                         pmac = peeprom->u2.mac.MacInfo;
2556                         fruformat = peeprom->FruFormat;
2557                         patkfru = &peeprom->AtkFru;
2558                         oemfruformat = peeprom->OemFruFormat;
2559                         poemfru = &peeprom->OemFru;
2560                         break;
2561                 }
2562
2563                 card->config.EepromValid = false;
2564
2565                 /*  see if the EEPROM is valid by checking it's checksum */
2566                 if ((eecodesize <= MAX_EECODE_SIZE) &&
2567                     (eecodesize >= MIN_EECODE_SIZE)) {
2568
2569                         ee_chksum =
2570                             *(u16 *) ((char *) peeprom + (eecodesize - 2));
2571                         /*
2572                             calculate the EEPROM checksum
2573                         */
2574                         calc_chksum =
2575                             ~slic_eeprom_cksum((char *) peeprom,
2576                                                (eecodesize - 2));
2577                         /*
2578                             if the ucdoe chksum flag bit worked,
2579                             we wouldn't need this shit
2580                         */
2581                         if (ee_chksum == calc_chksum)
2582                                 card->config.EepromValid = true;
2583                 }
2584                 /*  copy in the DRAM size */
2585                 card->config.DramSize = dramsize;
2586
2587                 /*  copy in the MAC address(es) */
2588                 for (i = 0; i < macaddrs; i++) {
2589                         memcpy(&card->config.MacInfo[i],
2590                                &pmac[i], sizeof(struct slic_config_mac));
2591                 }
2592 /*      DBG_MSG ("%s EEPROM Checksum Good? %d  MacAddress\n",__func__,
2593                 card->config.EepromValid); */
2594
2595                 /*  copy the Alacritech FRU information */
2596                 card->config.FruFormat = fruformat;
2597                 memcpy(&card->config.AtkFru, patkfru,
2598                                                 sizeof(struct atk_fru));
2599
2600                 pci_free_consistent(adapter->pcidev,
2601                                     sizeof(struct slic_eeprom),
2602                                     peeprom, phys_config);
2603                 DBG_MSG
2604                     ("slicoss: %s adapter%d [%p] size[%x] FREE peeprom[%p] \
2605                      phys_config[%p]\n",
2606                      __func__, adapter->port, adapter,
2607                      (u32) sizeof(struct slic_eeprom), peeprom,
2608                      (void *) phys_config);
2609
2610                 if ((!card->config.EepromValid) &&
2611                     (adapter->reg_params.fail_on_bad_eeprom)) {
2612                         WRITE_REG64(adapter,
2613                                     slic_regs->slic_isp,
2614                                     0, slic_regs->slic_addr_upper, 0, FLUSH);
2615                         DBG_ERROR
2616                             ("unsupported CONFIGURATION  EEPROM invalid\n");
2617                         return -EINVAL;
2618                 }
2619
2620                 card->config_set = 1;
2621         }
2622
2623         if (slic_card_download_gbrcv(adapter)) {
2624                 DBG_ERROR("%s unable to download GB receive microcode\n",
2625                           __func__);
2626                 return -EINVAL;
2627         }
2628
2629         if (slic_global.dynamic_intagg) {
2630                 DBG_MSG
2631                     ("Dynamic Interrupt Aggregation[ENABLED]: slic%d \
2632                      SET intagg to %d\n",
2633                      card->cardnum, 0);
2634                 slic_intagg_set(adapter, 0);
2635         } else {
2636                 slic_intagg_set(adapter, intagg_delay);
2637                 DBG_MSG
2638                     ("Dynamic Interrupt Aggregation[DISABLED]: slic%d \
2639                      SET intagg to %d\n",
2640                      card->cardnum, intagg_delay);
2641         }
2642
2643         /*
2644          *  Initialize ping status to "ok"
2645          */
2646         card->pingstatus = ISR_PINGMASK;
2647
2648 #if SLIC_DUMP_ENABLED
2649         if (!card->dumpbuffer) {
2650                 card->dumpbuffer = kmalloc(DUMP_PAGE_SIZE, GFP_KERNEL);
2651
2652                 ASSERT(card->dumpbuffer);
2653                 if (card->dumpbuffer == NULL)
2654                         return -ENOMEM;
2655         }
2656         /*
2657          *  Smear the shared memory structure and then obtain
2658          *  the PHYSICAL address of this structure
2659          */
2660         memset(card->dumpbuffer, 0, DUMP_PAGE_SIZE);
2661         card->dumpbuffer_phys = virt_to_bus(card->dumpbuffer);
2662         card->dumpbuffer_physh = SLIC_GET_ADDR_HIGH(card->dumpbuffer_phys);
2663         card->dumpbuffer_physl = SLIC_GET_ADDR_LOW(card->dumpbuffer_phys);
2664
2665         /*
2666          *  Allocate COMMAND BUFFER
2667          */
2668         if (!card->cmdbuffer) {
2669                 card->cmdbuffer = kmalloc(sizeof(struct dump_cmd), GFP_KERNEL);
2670
2671                 ASSERT(card->cmdbuffer);
2672                 if (card->cmdbuffer == NULL)
2673                         return -ENOMEM;
2674         }
2675         /*
2676          *  Smear the shared memory structure and then obtain
2677          *  the PHYSICAL address of this structure
2678          */
2679         memset(card->cmdbuffer, 0, sizeof(struct dump_cmd));
2680         card->cmdbuffer_phys = virt_to_bus(card->cmdbuffer);
2681         card->cmdbuffer_physh = SLIC_GET_ADDR_HIGH(card->cmdbuffer_phys);
2682         card->cmdbuffer_physl = SLIC_GET_ADDR_LOW(card->cmdbuffer_phys);
2683 #endif
2684
2685         /*
2686          * Lastly, mark our card state as up and return success
2687          */
2688         card->state = CARD_UP;
2689         card->reset_in_progress = 0;
2690         DBG_MSG("slicoss: %s EXIT card[%p] adapter[%p] card->state[%x]\n",
2691                 __func__, card, adapter, card->state);
2692
2693         return STATUS_SUCCESS;
2694 }
2695
2696 static u32 slic_card_locate(struct adapter *adapter)
2697 {
2698         struct sliccard *card = slic_global.slic_card;
2699         struct physcard *physcard = slic_global.phys_card;
2700         ushort card_hostid;
2701         u16 __iomem *hostid_reg;
2702         uint i;
2703         uint rdhostid_offset = 0;
2704
2705         DBG_MSG("slicoss: %s adapter[%p] slot[%x] bus[%x] port[%x]\n",
2706                 __func__, adapter, adapter->slotnumber, adapter->busnumber,
2707                 adapter->port);
2708
2709         switch (adapter->devid) {
2710         case SLIC_2GB_DEVICE_ID:
2711                 rdhostid_offset = SLIC_RDHOSTID_2GB;
2712                 break;
2713         case SLIC_1GB_DEVICE_ID:
2714                 rdhostid_offset = SLIC_RDHOSTID_1GB;
2715                 break;
2716         default:
2717                 ASSERT(0);
2718                 break;
2719         }
2720
2721         hostid_reg =
2722             (u16 __iomem *) (((u8 __iomem *) (adapter->slic_regs)) +
2723             rdhostid_offset);
2724         DBG_MSG("slicoss: %s *hostid_reg[%p] == ", __func__, hostid_reg);
2725
2726         /* read the 16 bit hostid from SRAM */
2727         card_hostid = (ushort) readw(hostid_reg);
2728         DBG_MSG(" card_hostid[%x]\n", card_hostid);
2729
2730         /* Initialize a new card structure if need be */
2731         if (card_hostid == SLIC_HOSTID_DEFAULT) {
2732                 card = kzalloc(sizeof(struct sliccard), GFP_KERNEL);
2733                 if (card == NULL)
2734                         return -ENOMEM;
2735
2736                 card->next = slic_global.slic_card;
2737                 slic_global.slic_card = card;
2738 #if DBG
2739                 if (adapter->devid == SLIC_2GB_DEVICE_ID) {
2740                         DBG_MSG
2741                             ("SLICOSS ==> Initialize 2 Port Gigabit Server "
2742                              "and Storage Accelerator\n");
2743                 } else {
2744                         DBG_MSG
2745                             ("SLICOSS ==> Initialize 1 Port Gigabit Server "
2746                              "and Storage Accelerator\n");
2747                 }
2748 #endif
2749                 card->busnumber = adapter->busnumber;
2750                 card->slotnumber = adapter->slotnumber;
2751
2752                 /* Find an available cardnum */
2753                 for (i = 0; i < SLIC_MAX_CARDS; i++) {
2754                         if (slic_global.cardnuminuse[i] == 0) {
2755                                 slic_global.cardnuminuse[i] = 1;
2756                                 card->cardnum = i;
2757                                 break;
2758                         }
2759                 }
2760                 slic_global.num_slic_cards++;
2761                 DBG_MSG("\nCARDNUM == %d  Total %d  Card[%p]\n\n",
2762                         card->cardnum, slic_global.num_slic_cards, card);
2763
2764                 slic_debug_card_create(card);
2765         } else {
2766                 DBG_MSG
2767                     ("slicoss: %s CARD already allocated, find the \
2768                      correct card\n", __func__);
2769                 /* Card exists, find the card this adapter belongs to */
2770                 while (card) {
2771                         DBG_MSG
2772                             ("slicoss: %s card[%p] slot[%x] bus[%x] \
2773                               adaptport[%p] hostid[%x] cardnum[%x]\n",
2774                              __func__, card, card->slotnumber,
2775                              card->busnumber, card->adapter[adapter->port],
2776                              card_hostid, card->cardnum);
2777
2778                         if (card->cardnum == card_hostid)
2779                                 break;
2780                         card = card->next;
2781                 }
2782         }
2783
2784         ASSERT(card);
2785         if (!card)
2786                 return STATUS_FAILURE;
2787         /* Put the adapter in the card's adapter list */
2788         ASSERT(card->adapter[adapter->port] == NULL);
2789         if (!card->adapter[adapter->port]) {
2790                 card->adapter[adapter->port] = adapter;
2791                 adapter->card = card;
2792         }
2793
2794         card->card_size = 1;    /* one port per *logical* card */
2795
2796         while (physcard) {
2797                 for (i = 0; i < SLIC_MAX_PORTS; i++) {
2798                         if (!physcard->adapter[i])
2799                                 continue;
2800                         else
2801                                 break;
2802                 }
2803                 ASSERT(i != SLIC_MAX_PORTS);
2804                 if (physcard->adapter[i]->slotnumber == adapter->slotnumber)
2805                         break;
2806                 physcard = physcard->next;
2807         }
2808         if (!physcard) {
2809                 /* no structure allocated for this physical card yet */
2810                 physcard = kzalloc(sizeof(struct physcard), GFP_KERNEL);
2811                 ASSERT(physcard);
2812
2813                 DBG_MSG
2814                     ("\n%s Allocate a PHYSICALcard:\n    PHYSICAL_Card[%p]\n"
2815                      "    LogicalCard  [%p]\n    adapter      [%p]\n",
2816                      __func__, physcard, card, adapter);
2817
2818                 physcard->next = slic_global.phys_card;
2819                 slic_global.phys_card = physcard;
2820                 physcard->adapters_allocd = 1;
2821         } else {
2822                 physcard->adapters_allocd++;
2823         }
2824         /* Note - this is ZERO relative */
2825         adapter->physport = physcard->adapters_allocd - 1;
2826
2827         ASSERT(physcard->adapter[adapter->physport] == NULL);
2828         physcard->adapter[adapter->physport] = adapter;
2829         adapter->physcard = physcard;
2830         DBG_MSG("    PHYSICAL_Port %d    Logical_Port  %d\n", adapter->physport,
2831                 adapter->port);
2832
2833         return 0;
2834 }
2835
2836 static void slic_soft_reset(struct adapter *adapter)
2837 {
2838         if (adapter->card->state == CARD_UP) {
2839                 DBG_MSG("slicoss: %s QUIESCE adapter[%p] card[%p] devid[%x]\n",
2840                         __func__, adapter, adapter->card, adapter->devid);
2841                 WRITE_REG(adapter->slic_regs->slic_quiesce, 0, FLUSH);
2842                 mdelay(1);
2843         }
2844 /*      DBG_MSG ("slicoss: %s (%s) adapter[%p] card[%p] devid[%x]\n",
2845         __func__, adapter->netdev->name, adapter, adapter->card,
2846            adapter->devid); */
2847
2848         WRITE_REG(adapter->slic_regs->slic_reset, SLIC_RESET_MAGIC, FLUSH);
2849         mdelay(1);
2850 }
2851
2852 static void slic_config_set(struct adapter *adapter, bool linkchange)
2853 {
2854         u32 value;
2855         u32 RcrReset;
2856         __iomem struct slic_regs *slic_regs = adapter->slic_regs;
2857
2858         DBG_MSG("slicoss: %s (%s) slic_interface_enable[%p](%d)\n",
2859                 __func__, adapter->netdev->name, adapter,
2860                 adapter->cardindex);
2861
2862         if (linkchange) {
2863                 /* Setup MAC */
2864                 slic_mac_config(adapter);
2865                 RcrReset = GRCR_RESET;
2866         } else {
2867                 slic_mac_address_config(adapter);
2868                 RcrReset = 0;
2869         }
2870
2871         if (adapter->linkduplex == LINK_FULLD) {
2872                 /* setup xmtcfg */
2873                 value = (GXCR_RESET |   /* Always reset     */
2874                          GXCR_XMTEN |   /* Enable transmit  */
2875                          GXCR_PAUSEEN); /* Enable pause     */
2876
2877                 DBG_MSG("slicoss: FDX adapt[%p] set xmtcfg to [%x]\n", adapter,
2878                         value);
2879                 WRITE_REG(slic_regs->slic_wxcfg, value, FLUSH);
2880
2881                 /* Setup rcvcfg last */
2882                 value = (RcrReset |     /* Reset, if linkchange */
2883                          GRCR_CTLEN |   /* Enable CTL frames    */
2884                          GRCR_ADDRAEN | /* Address A enable     */
2885                          GRCR_RCVBAD |  /* Rcv bad frames       */
2886                          (GRCR_HASHSIZE << GRCR_HASHSIZE_SHIFT));
2887         } else {
2888                 /* setup xmtcfg */
2889                 value = (GXCR_RESET |   /* Always reset     */
2890                          GXCR_XMTEN);   /* Enable transmit  */
2891
2892                 DBG_MSG("slicoss: HDX adapt[%p] set xmtcfg to [%x]\n", adapter,
2893                         value);
2894                 WRITE_REG(slic_regs->slic_wxcfg, value, FLUSH);
2895
2896                 /* Setup rcvcfg last */
2897                 value = (RcrReset |     /* Reset, if linkchange */
2898                          GRCR_ADDRAEN | /* Address A enable     */
2899                          GRCR_RCVBAD |  /* Rcv bad frames       */
2900                          (GRCR_HASHSIZE << GRCR_HASHSIZE_SHIFT));
2901         }
2902
2903         if (adapter->state != ADAPT_DOWN) {
2904                 /* Only enable receive if we are restarting or running */
2905                 value |= GRCR_RCVEN;
2906         }
2907
2908         if (adapter->macopts & MAC_PROMISC)
2909                 value |= GRCR_RCVALL;
2910
2911         DBG_MSG("slicoss: adapt[%p] set rcvcfg to [%x]\n", adapter, value);
2912         WRITE_REG(slic_regs->slic_wrcfg, value, FLUSH);
2913 }
2914
2915 /*
2916  *  Turn off RCV and XMT, power down PHY
2917  */
2918 static void slic_config_clear(struct adapter *adapter)
2919 {
2920         u32 value;
2921         u32 phy_config;
2922         __iomem struct slic_regs *slic_regs = adapter->slic_regs;
2923
2924         /* Setup xmtcfg */
2925         value = (GXCR_RESET |   /* Always reset */
2926                  GXCR_PAUSEEN); /* Enable pause */
2927
2928         WRITE_REG(slic_regs->slic_wxcfg, value, FLUSH);
2929
2930         value = (GRCR_RESET |   /* Always reset      */
2931                  GRCR_CTLEN |   /* Enable CTL frames */
2932                  GRCR_ADDRAEN | /* Address A enable  */
2933                  (GRCR_HASHSIZE << GRCR_HASHSIZE_SHIFT));
2934
2935         WRITE_REG(slic_regs->slic_wrcfg, value, FLUSH);
2936
2937         /* power down phy */
2938         phy_config = (MIICR_REG_PCR | (PCR_POWERDOWN));
2939         WRITE_REG(slic_regs->slic_wphy, phy_config, FLUSH);
2940 }
2941
2942 static void slic_config_get(struct adapter *adapter, u32 config,
2943                                                         u32 config_h)
2944 {
2945         int status;
2946
2947         status = slic_upr_request(adapter,
2948                                   SLIC_UPR_RCONFIG,
2949                                   (u32) config, (u32) config_h, 0, 0);
2950         ASSERT(status == 0);
2951 }
2952
2953 static void slic_mac_address_config(struct adapter *adapter)
2954 {
2955         u32 value;
2956         u32 value2;
2957         __iomem struct slic_regs *slic_regs = adapter->slic_regs;
2958
2959         value = *(u32 *) &adapter->currmacaddr[2];
2960         value = ntohl(value);
2961         WRITE_REG(slic_regs->slic_wraddral, value, FLUSH);
2962         WRITE_REG(slic_regs->slic_wraddrbl, value, FLUSH);
2963
2964         value2 = (u32) ((adapter->currmacaddr[0] << 8 |
2965                              adapter->currmacaddr[1]) & 0xFFFF);
2966
2967         WRITE_REG(slic_regs->slic_wraddrah, value2, FLUSH);
2968         WRITE_REG(slic_regs->slic_wraddrbh, value2, FLUSH);
2969
2970         DBG_MSG("%s value1[%x] value2[%x] Call slic_mcast_set_mask\n",
2971                 __func__, value, value2);
2972         slic_dbg_macaddrs(adapter);
2973
2974         /* Write our multicast mask out to the card.  This is done */
2975         /* here in addition to the slic_mcast_addr_set routine     */
2976         /* because ALL_MCAST may have been enabled or disabled     */
2977         slic_mcast_set_mask(adapter);
2978 }
2979
2980 static void slic_mac_config(struct adapter *adapter)
2981 {
2982         u32 value;
2983         __iomem struct slic_regs *slic_regs = adapter->slic_regs;
2984
2985         /* Setup GMAC gaps */
2986         if (adapter->linkspeed == LINK_1000MB) {
2987                 value = ((GMCR_GAPBB_1000 << GMCR_GAPBB_SHIFT) |
2988                          (GMCR_GAPR1_1000 << GMCR_GAPR1_SHIFT) |
2989                          (GMCR_GAPR2_1000 << GMCR_GAPR2_SHIFT));
2990         } else {
2991                 value = ((GMCR_GAPBB_100 << GMCR_GAPBB_SHIFT) |
2992                          (GMCR_GAPR1_100 << GMCR_GAPR1_SHIFT) |
2993                          (GMCR_GAPR2_100 << GMCR_GAPR2_SHIFT));
2994         }
2995
2996         /* enable GMII */
2997         if (adapter->linkspeed == LINK_1000MB)
2998                 value |= GMCR_GBIT;
2999
3000         /* enable fullduplex */
3001         if ((adapter->linkduplex == LINK_FULLD)
3002             || (adapter->macopts & MAC_LOOPBACK)) {
3003                 value |= GMCR_FULLD;
3004         }
3005
3006         /* write mac config */
3007         WRITE_REG(slic_regs->slic_wmcfg, value, FLUSH);
3008
3009         /* setup mac addresses */
3010         slic_mac_address_config(adapter);
3011 }
3012
3013 static bool slic_mac_filter(struct adapter *adapter,
3014                         struct ether_header *ether_frame)
3015 {
3016         u32 opts = adapter->macopts;
3017         u32 *dhost4 = (u32 *)&ether_frame->ether_dhost[0];
3018         u16 *dhost2 = (u16 *)&ether_frame->ether_dhost[4];
3019         bool equaladdr;
3020
3021         if (opts & MAC_PROMISC) {
3022                 DBG_MSG("slicoss: %s (%s) PROMISCUOUS. Accept frame\n",
3023                         __func__, adapter->netdev->name);
3024                 return true;
3025         }
3026
3027         if ((*dhost4 == 0xFFFFFFFF) && (*dhost2 == 0xFFFF)) {
3028                 if (opts & MAC_BCAST) {
3029                         adapter->rcv_broadcasts++;
3030                         return true;
3031                 } else {
3032                         return false;
3033                 }
3034         }
3035
3036         if (ether_frame->ether_dhost[0] & 0x01) {
3037                 if (opts & MAC_ALLMCAST) {
3038                         adapter->rcv_multicasts++;
3039                         adapter->stats.multicast++;
3040                         return true;
3041                 }
3042                 if (opts & MAC_MCAST) {
3043                         struct mcast_address *mcaddr = adapter->mcastaddrs;
3044
3045                         while (mcaddr) {
3046                                 ETHER_EQ_ADDR(mcaddr->address,
3047                                               ether_frame->ether_dhost,
3048                                               equaladdr);
3049                                 if (equaladdr) {
3050                                         adapter->rcv_multicasts++;
3051                                         adapter->stats.multicast++;
3052                                         return true;
3053                                 }
3054                                 mcaddr = mcaddr->next;
3055                         }
3056                         return false;
3057                 } else {
3058                         return false;
3059                 }
3060         }
3061         if (opts & MAC_DIRECTED) {
3062                 adapter->rcv_unicasts++;
3063                 return true;
3064         }
3065         return false;
3066
3067 }
3068
3069 static int slic_mac_set_address(struct net_device *dev, void *ptr)
3070 {
3071         struct adapter *adapter = (struct adapter *)netdev_priv(dev);
3072         struct sockaddr *addr = ptr;
3073
3074         DBG_MSG("%s ENTER (%s)\n", __func__, adapter->netdev->name);
3075
3076         if (netif_running(dev))
3077                 return -EBUSY;
3078         if (!adapter)
3079                 return -EBUSY;
3080         DBG_MSG("slicoss: %s (%s) curr %2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X\n",
3081                 __func__, adapter->netdev->name, adapter->currmacaddr[0],
3082                 adapter->currmacaddr[1], adapter->currmacaddr[2],
3083                 adapter->currmacaddr[3], adapter->currmacaddr[4],
3084                 adapter->currmacaddr[5]);
3085         memcpy(dev->dev_addr, addr->sa_data, dev->addr_len);
3086         memcpy(adapter->currmacaddr, addr->sa_data, dev->addr_len);
3087         DBG_MSG("slicoss: %s (%s) new %2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X\n",
3088                 __func__, adapter->netdev->name, adapter->currmacaddr[0],
3089                 adapter->currmacaddr[1], adapter->currmacaddr[2],
3090                 adapter->currmacaddr[3], adapter->currmacaddr[4],
3091                 adapter->currmacaddr[5]);
3092
3093         slic_config_set(adapter, true);
3094         return 0;
3095 }
3096
3097 /*
3098  *  slic_timer_get_stats
3099  *
3100  * Timer function used to suck the statistics out of the card every
3101  * 50 seconds or whatever STATS_TIMER_INTERVAL is set to.
3102  *
3103  */
3104 #if SLIC_GET_STATS_TIMER_ENABLED
3105 static void slic_timer_get_stats(ulong dev)
3106 {
3107         struct adapter *adapter;
3108         struct sliccard *card;
3109         struct slic_shmem *pshmem;
3110
3111         ASSERT(dev);
3112         adapter = netdev_priv((struct net_device *)dev);
3113         ASSERT(adapter);
3114         card = adapter->card;
3115         ASSERT(card);
3116
3117         if ((card->state == CARD_UP) &&
3118             (adapter->state == ADAPT_UP) && (adapter->linkstate == LINK_UP)) {
3119                 pshmem = (struct slic_shmem *)adapter->phys_shmem;
3120 #ifdef CONFIG_X86_64
3121                 slic_upr_request(adapter,
3122                                  SLIC_UPR_STATS,
3123                                  SLIC_GET_ADDR_LOW(&pshmem->inicstats),
3124                                  SLIC_GET_ADDR_HIGH(&pshmem->inicstats), 0, 0);
3125 #elif defined(CONFIG_X86)
3126                 slic_upr_request(adapter,
3127                                  SLIC_UPR_STATS,
3128                                  (u32) &pshmem->inicstats, 0, 0, 0);
3129 #else
3130                 Stop compilation;
3131 #endif
3132         } else {
3133 /*              DBG_MSG ("slicoss: %s adapter[%p] linkstate[%x] NOT UP!\n",
3134                         __func__, adapter, adapter->linkstate); */
3135         }
3136         adapter->statstimer.expires = jiffies + (STATS_TIMER_INTERVAL * HZ);
3137         add_timer(&adapter->statstimer);
3138 }
3139 #endif
3140 static void slic_timer_load_check(ulong cardaddr)
3141 {
3142         struct sliccard *card = (struct sliccard *)cardaddr;
3143         struct adapter *adapter = card->master;
3144         u32 load = card->events;
3145         u32 level = 0;
3146
3147         if ((adapter) && (adapter->state == ADAPT_UP) &&
3148             (card->state == CARD_UP) && (slic_global.dynamic_intagg)) {
3149                 if (adapter->devid == SLIC_1GB_DEVICE_ID) {
3150                         if (adapter->linkspeed == LINK_1000MB)
3151                                 level = 100;
3152                         else {
3153                                 if (load > SLIC_LOAD_5)
3154                                         level = SLIC_INTAGG_5;
3155                                 else if (load > SLIC_LOAD_4)
3156                                         level = SLIC_INTAGG_4;
3157                                 else if (load > SLIC_LOAD_3)
3158                                         level = SLIC_INTAGG_3;
3159                                 else if (load > SLIC_LOAD_2)
3160                                         level = SLIC_INTAGG_2;
3161                                 else if (load > SLIC_LOAD_1)
3162                                         level = SLIC_INTAGG_1;
3163                                 else
3164                                         level = SLIC_INTAGG_0;
3165                         }
3166                         if (card->loadlevel_current != level) {
3167                                 card->loadlevel_current = level;
3168                                 WRITE_REG(adapter->slic_regs->slic_intagg,
3169                                           level, FLUSH);
3170                         }
3171                 } else {
3172                         if (load > SLIC_LOAD_5)
3173                                 level = SLIC_INTAGG_5;
3174                         else if (load > SLIC_LOAD_4)
3175                                 level = SLIC_INTAGG_4;
3176                         else if (load > SLIC_LOAD_3)
3177                                 level = SLIC_INTAGG_3;
3178                         else if (load > SLIC_LOAD_2)
3179                                 level = SLIC_INTAGG_2;
3180                         else if (load > SLIC_LOAD_1)
3181                                 level = SLIC_INTAGG_1;
3182                         else
3183                                 level = SLIC_INTAGG_0;
3184                         if (card->loadlevel_current != level) {
3185                                 card->loadlevel_current = level;
3186                                 WRITE_REG(adapter->slic_regs->slic_intagg,
3187                                           level, FLUSH);
3188                         }
3189                 }
3190         }
3191         card->events = 0;
3192         card->loadtimer.expires = jiffies + (SLIC_LOADTIMER_PERIOD * HZ);
3193         add_timer(&card->loadtimer);
3194 }
3195
3196 static void slic_assert_fail(void)
3197 {
3198         u32 cpuid;
3199         u32 curr_pid;
3200         cpuid = smp_processor_id();
3201         curr_pid = current->pid;
3202
3203         DBG_ERROR("%s CPU # %d ---- PID # %d\n", __func__, cpuid, curr_pid);
3204 }
3205
3206 static int slic_upr_queue_request(struct adapter *adapter,
3207                            u32 upr_request,
3208                            u32 upr_data,
3209                            u32 upr_data_h,
3210                            u32 upr_buffer, u32 upr_buffer_h)
3211 {
3212         struct slic_upr *upr;
3213         struct slic_upr *uprqueue;
3214
3215         upr = kmalloc(sizeof(struct slic_upr), GFP_ATOMIC);
3216         if (!upr) {
3217                 DBG_MSG("%s COULD NOT ALLOCATE UPR MEM\n", __func__);
3218
3219                 return -ENOMEM;
3220         }
3221         upr->adapter = adapter->port;
3222         upr->upr_request = upr_request;
3223         upr->upr_data = upr_data;
3224         upr->upr_buffer = upr_buffer;
3225         upr->upr_data_h = upr_data_h;
3226         upr->upr_buffer_h = upr_buffer_h;
3227         upr->next = NULL;
3228         if (adapter->upr_list) {
3229                 uprqueue = adapter->upr_list;
3230
3231                 while (uprqueue->next)
3232                         uprqueue = uprqueue->next;
3233                 uprqueue->next = upr;
3234         } else {
3235                 adapter->upr_list = upr;
3236         }
3237         return STATUS_SUCCESS;
3238 }
3239
3240 static int slic_upr_request(struct adapter *adapter,
3241                      u32 upr_request,
3242                      u32 upr_data,
3243                      u32 upr_data_h,
3244                      u32 upr_buffer, u32 upr_buffer_h)
3245 {
3246         int status;
3247
3248         spin_lock_irqsave(&adapter->upr_lock.lock, adapter->upr_lock.flags);
3249         status = slic_upr_queue_request(adapter,
3250                                         upr_request,
3251                                         upr_data,
3252                                         upr_data_h, upr_buffer, upr_buffer_h);
3253         if (status != STATUS_SUCCESS) {
3254                 spin_unlock_irqrestore(&adapter->upr_lock.lock,
3255                                         adapter->upr_lock.flags);
3256                 return status;
3257         }
3258         slic_upr_start(adapter);
3259         spin_unlock_irqrestore(&adapter->upr_lock.lock,
3260                                 adapter->upr_lock.flags);
3261         return STATUS_PENDING;
3262 }
3263
3264 static void slic_upr_request_complete(struct adapter *adapter, u32 isr)
3265 {
3266         struct sliccard *card = adapter->card;
3267         struct slic_upr *upr;
3268
3269 /*    if (card->dump_requested) {
3270         DBG_MSG("ENTER slic_upr_request_complete Dump in progress ISR[%x]\n",
3271                 isr);
3272       } */
3273         spin_lock_irqsave(&adapter->upr_lock.lock, adapter->upr_lock.flags);
3274         upr = adapter->upr_list;
3275         if (!upr) {
3276                 ASSERT(0);
3277                 spin_unlock_irqrestore(&adapter->upr_lock.lock,
3278                                         adapter->upr_lock.flags);
3279                 return;
3280         }
3281         adapter->upr_list = upr->next;
3282         upr->next = NULL;
3283         adapter->upr_busy = 0;
3284         ASSERT(adapter->port == upr->adapter);
3285         switch (upr->upr_request) {
3286         case SLIC_UPR_STATS:
3287                 {
3288 #if SLIC_GET_STATS_ENABLED
3289                         struct slic_stats *slicstats =
3290                             (struct slic_stats *) &adapter->pshmem->inicstats;
3291                         struct slic_stats *newstats = slicstats;
3292                         struct slic_stats  *old = &adapter->inicstats_prev;
3293                         struct slicnet_stats *stst = &adapter->slic_stats;
3294 #endif
3295                         if (isr & ISR_UPCERR) {
3296                                 DBG_ERROR
3297                                     ("SLIC_UPR_STATS command failed isr[%x]\n",
3298                                      isr);
3299
3300                                 break;
3301                         }
3302 #if SLIC_GET_STATS_ENABLED
3303 /*                      DBG_MSG ("slicoss: %s rcv %lx:%lx:%lx:%lx:%lx %lx %lx "
3304                                 "xmt %lx:%lx:%lx:%lx:%lx %lx %lx\n",
3305                                  __func__,
3306                              slicstats->rcv_unicasts100,
3307                              slicstats->rcv_bytes100,
3308                              slicstats->rcv_bytes100,
3309                              slicstats->rcv_tcp_bytes100,
3310                              slicstats->rcv_tcp_segs100,
3311                              slicstats->rcv_other_error100,
3312                              slicstats->rcv_drops100,
3313                              slicstats->xmit_unicasts100,
3314                              slicstats->xmit_bytes100,
3315                              slicstats->xmit_bytes100,
3316                              slicstats->xmit_tcp_bytes100,
3317                              slicstats->xmit_tcp_segs100,
3318                              slicstats->xmit_other_error100,
3319                              slicstats->xmit_collisions100);*/
3320                         UPDATE_STATS_GB(stst->tcp.xmit_tcp_segs,
3321                                         newstats->xmit_tcp_segs_gb,
3322                                         old->xmit_tcp_segs_gb);
3323
3324                         UPDATE_STATS_GB(stst->tcp.xmit_tcp_bytes,
3325                                         newstats->xmit_tcp_bytes_gb,
3326                                         old->xmit_tcp_bytes_gb);
3327
3328                         UPDATE_STATS_GB(stst->tcp.rcv_tcp_segs,
3329                                         newstats->rcv_tcp_segs_gb,
3330                                         old->rcv_tcp_segs_gb);
3331
3332                         UPDATE_STATS_GB(stst->tcp.rcv_tcp_bytes,
3333                                         newstats->rcv_tcp_bytes_gb,
3334                                         old->rcv_tcp_bytes_gb);
3335
3336                         UPDATE_STATS_GB(stst->iface.xmt_bytes,
3337                                         newstats->xmit_bytes_gb,
3338                                         old->xmit_bytes_gb);
3339
3340                         UPDATE_STATS_GB(stst->iface.xmt_ucast,
3341                                         newstats->xmit_unicasts_gb,
3342                                         old->xmit_unicasts_gb);
3343
3344                         UPDATE_STATS_GB(stst->iface.rcv_bytes,
3345                                         newstats->rcv_bytes_gb,
3346                                         old->rcv_bytes_gb);
3347
3348                         UPDATE_STATS_GB(stst->iface.rcv_ucast,
3349                                         newstats->rcv_unicasts_gb,
3350                                         old->rcv_unicasts_gb);
3351
3352                         UPDATE_STATS_GB(stst->iface.xmt_errors,
3353                                         newstats->xmit_collisions_gb,
3354                                         old->xmit_collisions_gb);
3355
3356                         UPDATE_STATS_GB(stst->iface.xmt_errors,
3357                                         newstats->xmit_excess_collisions_gb,
3358                                         old->xmit_excess_collisions_gb);
3359
3360                         UPDATE_STATS_GB(stst->iface.xmt_errors,
3361                                         newstats->xmit_other_error_gb,
3362                                         old->xmit_other_error_gb);
3363
3364                         UPDATE_STATS_GB(stst->iface.rcv_errors,
3365                                         newstats->rcv_other_error_gb,
3366                                         old->rcv_other_error_gb);
3367
3368                         UPDATE_STATS_GB(stst->iface.rcv_discards,
3369                                         newstats->rcv_drops_gb,
3370                                         old->rcv_drops_gb);
3371
3372                         if (newstats->rcv_drops_gb > old->rcv_drops_gb) {
3373                                 adapter->rcv_drops +=
3374                                     (newstats->rcv_drops_gb -
3375                                      old->rcv_drops_gb);
3376                         }
3377                         memcpy(old, newstats, sizeof(struct slic_stats));
3378 #endif
3379                         break;
3380                 }
3381         case SLIC_UPR_RLSR:
3382                 slic_link_upr_complete(adapter, isr);
3383                 break;
3384         case SLIC_UPR_RCONFIG:
3385                 break;
3386         case SLIC_UPR_RPHY:
3387                 ASSERT(0);
3388                 break;
3389         case SLIC_UPR_ENLB:
3390                 ASSERT(0);
3391                 break;
3392         case SLIC_UPR_ENCT:
3393                 ASSERT(0);
3394                 break;
3395         case SLIC_UPR_PDWN:
3396                 ASSERT(0);
3397                 break;
3398         case SLIC_UPR_PING:
3399                 card->pingstatus |= (isr & ISR_PINGDSMASK);
3400                 break;
3401 #if SLIC_DUMP_ENABLED
3402         case SLIC_UPR_DUMP:
3403                 card->dumpstatus |= (isr & ISR_UPCMASK);
3404                 break;
3405 #endif
3406         default:
3407                 ASSERT(0);
3408         }
3409         kfree(upr);
3410         slic_upr_start(adapter);
3411         spin_unlock_irqrestore(&adapter->upr_lock.lock,
3412                                 adapter->upr_lock.flags);
3413 }
3414
3415 static void slic_upr_start(struct adapter *adapter)
3416 {
3417         struct slic_upr *upr;
3418         __iomem struct slic_regs *slic_regs = adapter->slic_regs;
3419 /*
3420     char * ptr1;
3421     char * ptr2;
3422     uint cmdoffset;
3423 */
3424         upr = adapter->upr_list;
3425         if (!upr)
3426                 return;
3427         if (adapter->upr_busy)
3428                 return;
3429         adapter->upr_busy = 1;
3430
3431         switch (upr->upr_request) {
3432         case SLIC_UPR_STATS:
3433                 if (upr->upr_data_h == 0) {
3434                         WRITE_REG(slic_regs->slic_stats, upr->upr_data, FLUSH);
3435                 } else {
3436                         WRITE_REG64(adapter,
3437                                     slic_regs->slic_stats64,
3438                                     upr->upr_data,
3439                                     slic_regs->slic_addr_upper,
3440                                     upr->upr_data_h, FLUSH);
3441                 }
3442                 break;
3443
3444         case SLIC_UPR_RLSR:
3445                 WRITE_REG64(adapter,
3446                             slic_regs->slic_rlsr,
3447                             upr->upr_data,
3448                             slic_regs->slic_addr_upper, upr->upr_data_h, FLUSH);
3449                 break;
3450
3451         case SLIC_UPR_RCONFIG:
3452                 DBG_MSG("%s SLIC_UPR_RCONFIG!!!!\n", __func__);
3453                 DBG_MSG("WRITE_REG64 adapter[%p]\n"
3454                         "    a->slic_regs[%p] slic_regs[%p]\n"
3455                         "    &slic_rconfig[%p] &slic_addr_upper[%p]\n"
3456                         "    upr[%p]\n"
3457                         "    uprdata[%x] uprdatah[%x]\n",
3458                         adapter, adapter->slic_regs, slic_regs,
3459                         &slic_regs->slic_rconfig, &slic_regs->slic_addr_upper,
3460                         upr, upr->upr_data, upr->upr_data_h);
3461                 WRITE_REG64(adapter,
3462                             slic_regs->slic_rconfig,
3463                             upr->upr_data,
3464                             slic_regs->slic_addr_upper, upr->upr_data_h, FLUSH);
3465                 break;
3466 #if SLIC_DUMP_ENABLED
3467         case SLIC_UPR_DUMP:
3468 #if 0
3469                 DBG_MSG("%s SLIC_UPR_DUMP!!!!\n", __func__);
3470                 DBG_MSG("WRITE_REG64 adapter[%p]\n"
3471                          "    upr_buffer[%x]   upr_bufferh[%x]\n"
3472                          "    upr_data[%x]     upr_datah[%x]\n"
3473                          "    cmdbuff[%p] cmdbuffP[%p]\n"
3474                          "    dumpbuff[%p] dumpbuffP[%p]\n",
3475                          adapter, upr->upr_buffer, upr->upr_buffer_h,
3476                          upr->upr_data, upr->upr_data_h,
3477                          adapter->card->cmdbuffer,
3478                          (void *)adapter->card->cmdbuffer_phys,
3479                          adapter->card->dumpbuffer, (
3480                          void *)adapter->card->dumpbuffer_phys);
3481
3482                 ptr1 = (char *)slic_regs;
3483                 ptr2 = (char *)(&slic_regs->slic_dump_cmd);
3484                 cmdoffset = ptr2 - ptr1;
3485                 DBG_MSG("slic_dump_cmd register offset [%x]\n", cmdoffset);
3486 #endif
3487                 if (upr->upr_buffer || upr->upr_buffer_h) {
3488                         WRITE_REG64(adapter,
3489                                     slic_regs->slic_dump_data,
3490                                     upr->upr_buffer,
3491                                     slic_regs->slic_addr_upper,
3492                                     upr->upr_buffer_h, FLUSH);
3493                 }
3494                 WRITE_REG64(adapter,
3495                             slic_regs->slic_dump_cmd,
3496                             upr->upr_data,
3497                             slic_regs->slic_addr_upper, upr->upr_data_h, FLUSH);
3498                 break;
3499 #endif
3500         case SLIC_UPR_PING:
3501                 WRITE_REG(slic_regs->slic_ping, 1, FLUSH);
3502                 break;
3503         default:
3504                 ASSERT(0);
3505         }
3506 }
3507
3508 static void slic_link_upr_complete(struct adapter *adapter, u32 isr)
3509 {
3510         u32 linkstatus = adapter->pshmem->linkstatus;
3511         uint linkup;
3512         unsigned char linkspeed;
3513         unsigned char linkduplex;
3514
3515         DBG_MSG("%s: %s ISR[%x] linkstatus[%x]\n   adapter[%p](%d)\n",
3516                 __func__, adapter->netdev->name, isr, linkstatus, adapter,
3517                 adapter->cardindex);
3518
3519         if ((isr & ISR_UPCERR) || (isr & ISR_UPCBSY)) {
3520                 struct slic_shmem *pshmem;
3521
3522                 pshmem = (struct slic_shmem *)adapter->phys_shmem;
3523 #if defined(CONFIG_X86_64)
3524                 slic_upr_queue_request(adapter,
3525                                        SLIC_UPR_RLSR,
3526                                        SLIC_GET_ADDR_LOW(&pshmem->linkstatus),
3527                                        SLIC_GET_ADDR_HIGH(&pshmem->linkstatus),
3528                                        0, 0);
3529 #elif defined(CONFIG_X86)
3530                 slic_upr_queue_request(adapter,
3531                                        SLIC_UPR_RLSR,
3532                                        (u32) &pshmem->linkstatus,
3533                                        SLIC_GET_ADDR_HIGH(pshmem), 0, 0);
3534 #else
3535                 Stop Compilation;
3536 #endif
3537                 return;
3538         }
3539         if (adapter->state != ADAPT_UP)
3540                 return;
3541
3542         ASSERT((adapter->devid == SLIC_1GB_DEVICE_ID)
3543                || (adapter->devid == SLIC_2GB_DEVICE_ID));
3544
3545         linkup = linkstatus & GIG_LINKUP ? LINK_UP : LINK_DOWN;
3546         if (linkstatus & GIG_SPEED_1000) {
3547                 linkspeed = LINK_1000MB;
3548                 DBG_MSG("slicoss: %s (%s) GIGABIT Speed==1000MB  ",
3549                         __func__, adapter->netdev->name);
3550         } else if (linkstatus & GIG_SPEED_100) {
3551                 linkspeed = LINK_100MB;
3552                 DBG_MSG("slicoss: %s (%s) GIGABIT Speed==100MB  ", __func__,
3553                         adapter->netdev->name);
3554         } else {
3555                 linkspeed = LINK_10MB;
3556                 DBG_MSG("slicoss: %s (%s) GIGABIT Speed==10MB  ", __func__,
3557                         adapter->netdev->name);
3558         }
3559         if (linkstatus & GIG_FULLDUPLEX) {
3560                 linkduplex = LINK_FULLD;
3561                 DBG_MSG(" Duplex == FULL\n");
3562         } else {
3563                 linkduplex = LINK_HALFD;
3564                 DBG_MSG(" Duplex == HALF\n");
3565         }
3566
3567         if ((adapter->linkstate == LINK_DOWN) && (linkup == LINK_DOWN)) {
3568                 DBG_MSG("slicoss: %s (%s) physport(%d) link still down\n",
3569                         __func__, adapter->netdev->name, adapter->physport);
3570                 return;
3571         }
3572
3573         /* link up event, but nothing has changed */
3574         if ((adapter->linkstate == LINK_UP) &&
3575             (linkup == LINK_UP) &&
3576             (adapter->linkspeed == linkspeed) &&
3577             (adapter->linkduplex == linkduplex)) {
3578                 DBG_MSG("slicoss: %s (%s) port(%d) link still up\n",
3579                         __func__, adapter->netdev->name, adapter->physport);
3580                 return;
3581         }
3582
3583         /* link has changed at this point */
3584
3585         /* link has gone from up to down */
3586         if (linkup == LINK_DOWN) {
3587                 adapter->linkstate = LINK_DOWN;
3588                 DBG_MSG("slicoss: %s %d LinkDown!\n", __func__,
3589                         adapter->physport);
3590                 return;
3591         }
3592
3593         /* link has gone from down to up */
3594         adapter->linkspeed = linkspeed;
3595         adapter->linkduplex = linkduplex;
3596
3597         if (adapter->linkstate != LINK_UP) {
3598                 /* setup the mac */
3599                 DBG_MSG("%s call slic_config_set\n", __func__);
3600                 slic_config_set(adapter, true);
3601                 adapter->linkstate = LINK_UP;
3602                 DBG_MSG("\n(%s) Link UP: CALL slic_if_start_queue",
3603                         adapter->netdev->name);
3604                 slic_if_start_queue(adapter);
3605         }
3606 #if 1
3607         switch (linkspeed) {
3608         case LINK_1000MB:
3609                 DBG_MSG
3610                     ("\n(%s) LINK UP!: GIGABIT SPEED == 1000MB  duplex[%x]\n",
3611                      adapter->netdev->name, adapter->linkduplex);
3612                 break;
3613         case LINK_100MB:
3614                 DBG_MSG("\n(%s) LINK UP!: SPEED == 100MB  duplex[%x]\n",
3615                         adapter->netdev->name, adapter->linkduplex);
3616                 break;
3617         default:
3618                 DBG_MSG("\n(%s) LINK UP!: SPEED == 10MB  duplex[%x]\n",
3619                         adapter->netdev->name, adapter->linkduplex);
3620                 break;
3621         }
3622 #endif
3623 }
3624
3625 /*
3626  *  this is here to checksum the eeprom, there is some ucode bug
3627  *  which prevens us from using the ucode result.
3628  *  remove this once ucode is fixed.
3629  */
3630 static ushort slic_eeprom_cksum(char *m, int len)
3631 {
3632 #define ADDCARRY(x)  (x > 65535 ? x -= 65535 : x)
3633 #define REDUCE {l_util.l = sum; sum = l_util.s[0] + l_util.s[1]; ADDCARRY(sum);\
3634                 }
3635
3636         u16 *w;
3637         u32 sum = 0;
3638         u32 byte_swapped = 0;
3639         u32 w_int;
3640
3641         union {
3642                 char c[2];
3643                 ushort s;
3644         } s_util;
3645
3646         union {
3647                 ushort s[2];
3648                 int l;
3649         } l_util;
3650
3651         l_util.l = 0;
3652         s_util.s = 0;
3653
3654         w = (u16 *)m;
3655 #ifdef CONFIG_X86_64
3656         w_int = (u32) ((ulong) w & 0x00000000FFFFFFFF);
3657 #else
3658         w_int = (u32) (w);
3659 #endif
3660         if ((1 & w_int) && (len > 0)) {
3661                 REDUCE;
3662                 sum <<= 8;
3663                 s_util.c[0] = *(unsigned char *)w;
3664                 w = (u16 *)((char *)w + 1);
3665                 len--;
3666                 byte_swapped = 1;
3667         }
3668
3669         /* Unroll the loop to make overhead from branches &c small. */
3670         while ((len -= 32) >= 0) {
3671                 sum += w[0];
3672                 sum += w[1];
3673                 sum += w[2];
3674                 sum += w[3];
3675                 sum += w[4];
3676                 sum += w[5];
3677                 sum += w[6];
3678                 sum += w[7];
3679                 sum += w[8];
3680                 sum += w[9];
3681                 sum += w[10];
3682                 sum += w[11];
3683                 sum += w[12];
3684                 sum += w[13];
3685                 sum += w[14];
3686                 sum += w[15];
3687                 w = (u16 *)((ulong) w + 16);    /* verify */
3688         }
3689         len += 32;
3690         while ((len -= 8) >= 0) {
3691                 sum += w[0];
3692                 sum += w[1];
3693                 sum += w[2];
3694                 sum += w[3];
3695                 w = (u16 *)((ulong) w + 4);     /* verify */
3696         }
3697         len += 8;
3698         if (len != 0 || byte_swapped != 0) {
3699                 REDUCE;
3700                 while ((len -= 2) >= 0)
3701                         sum += *w++;    /* verify */
3702                 if (byte_swapped) {
3703                         REDUCE;
3704                         sum <<= 8;
3705                         byte_swapped = 0;
3706                         if (len == -1) {
3707                                 s_util.c[1] = *(char *) w;
3708                                 sum += s_util.s;
3709                                 len = 0;
3710                         } else {
3711                                 len = -1;
3712                         }
3713
3714                 } else if (len == -1) {
3715                         s_util.c[0] = *(char *) w;
3716                 }
3717
3718                 if (len == -1) {
3719                         s_util.c[1] = 0;
3720                         sum += s_util.s;
3721                 }
3722         }
3723         REDUCE;
3724         return (ushort) sum;
3725 }
3726
3727 static int slic_rspqueue_init(struct adapter *adapter)
3728 {
3729         int i;
3730         struct slic_rspqueue *rspq = &adapter->rspqueue;
3731         __iomem struct slic_regs *slic_regs = adapter->slic_regs;
3732         u32 paddrh = 0;
3733
3734         DBG_MSG("slicoss: %s (%s) ENTER adapter[%p]\n", __func__,
3735                 adapter->netdev->name, adapter);
3736         ASSERT(adapter->state == ADAPT_DOWN);
3737         memset(rspq, 0, sizeof(struct slic_rspqueue));
3738
3739         rspq->num_pages = SLIC_RSPQ_PAGES_GB;
3740
3741         for (i = 0; i < rspq->num_pages; i++) {
3742                 rspq->vaddr[i] =
3743                     pci_alloc_consistent(adapter->pcidev, PAGE_SIZE,
3744                                          &rspq->paddr[i]);
3745                 if (!rspq->vaddr[i]) {
3746                         DBG_ERROR
3747                             ("rspqueue_init_failed  pci_alloc_consistent\n");
3748                         slic_rspqueue_free(adapter);
3749                         return STATUS_FAILURE;
3750                 }
3751 #ifndef CONFIG_X86_64
3752                 ASSERT(((u32) rspq->vaddr[i] & 0xFFFFF000) ==
3753                        (u32) rspq->vaddr[i]);
3754                 ASSERT(((u32) rspq->paddr[i] & 0xFFFFF000) ==
3755                        (u32) rspq->paddr[i]);
3756 #endif
3757                 memset(rspq->vaddr[i], 0, PAGE_SIZE);
3758 /*              DBG_MSG("slicoss: %s UPLOAD RSPBUFF Page pageix[%x] paddr[%p] "
3759                         "vaddr[%p]\n",
3760                         __func__, i, (void *)rspq->paddr[i], rspq->vaddr[i]); */
3761
3762                 if (paddrh == 0) {
3763                         WRITE_REG(slic_regs->slic_rbar,
3764                                   (rspq->paddr[i] | SLIC_RSPQ_BUFSINPAGE),
3765                                   DONT_FLUSH);
3766                 } else {
3767                         WRITE_REG64(adapter,
3768                                     slic_regs->slic_rbar64,
3769                                     (rspq->paddr[i] | SLIC_RSPQ_BUFSINPAGE),
3770                                     slic_regs->slic_addr_upper,
3771                                     paddrh, DONT_FLUSH);
3772                 }
3773         }
3774         rspq->offset = 0;
3775         rspq->pageindex = 0;
3776         rspq->rspbuf = (struct slic_rspbuf *)rspq->vaddr[0];
3777         DBG_MSG("slicoss: %s (%s) EXIT adapter[%p]\n", __func__,
3778                 adapter->netdev->name, adapter);
3779         return STATUS_SUCCESS;
3780 }
3781
3782 static int slic_rspqueue_reset(struct adapter *adapter)
3783 {
3784         struct slic_rspqueue *rspq = &adapter->rspqueue;
3785
3786         DBG_MSG("slicoss: %s (%s) ENTER adapter[%p]\n", __func__,
3787                 adapter->netdev->name, adapter);
3788         ASSERT(adapter->state == ADAPT_DOWN);
3789         ASSERT(rspq);
3790
3791         DBG_MSG("slicoss: Nothing to do. rspq[%p]\n"
3792                 "                             offset[%x]\n"
3793                 "                             pageix[%x]\n"
3794                 "                             rspbuf[%p]\n",
3795                 rspq, rspq->offset, rspq->pageindex, rspq->rspbuf);
3796
3797         DBG_MSG("slicoss: %s (%s) EXIT adapter[%p]\n", __func__,
3798                 adapter->netdev->name, adapter);
3799         return STATUS_SUCCESS;
3800 }
3801
3802 static void slic_rspqueue_free(struct adapter *adapter)
3803 {
3804         int i;
3805         struct slic_rspqueue *rspq = &adapter->rspqueue;
3806
3807         DBG_MSG("slicoss: %s adapter[%p] port %d rspq[%p] FreeRSPQ\n",
3808                 __func__, adapter, adapter->physport, rspq);
3809         for (i = 0; i < rspq->num_pages; i++) {
3810                 if (rspq->vaddr[i]) {
3811                         DBG_MSG
3812                             ("slicoss:  pci_free_consistent rspq->vaddr[%p] \
3813                             paddr[%p]\n",
3814                              rspq->vaddr[i], (void *) rspq->paddr[i]);
3815                         pci_free_consistent(adapter->pcidev, PAGE_SIZE,
3816                                             rspq->vaddr[i], rspq->paddr[i]);
3817                 }
3818                 rspq->vaddr[i] = NULL;
3819                 rspq->paddr[i] = 0;
3820         }
3821         rspq->offset = 0;
3822         rspq->pageindex = 0;
3823         rspq->rspbuf = NULL;
3824 }
3825
3826 static struct slic_rspbuf *slic_rspqueue_getnext(struct adapter *adapter)
3827 {
3828         struct slic_rspqueue *rspq = &adapter->rspqueue;
3829         struct slic_rspbuf *buf;
3830
3831         if (!(rspq->rspbuf->status))
3832                 return NULL;
3833
3834         buf = rspq->rspbuf;
3835 #ifndef CONFIG_X86_64
3836         ASSERT((buf->status & 0xFFFFFFE0) == 0);
3837 #endif
3838         ASSERT(buf->hosthandle);
3839         if (++rspq->offset < SLIC_RSPQ_BUFSINPAGE) {
3840                 rspq->rspbuf++;
3841 #ifndef CONFIG_X86_64
3842                 ASSERT(((u32) rspq->rspbuf & 0xFFFFFFE0) ==
3843                        (u32) rspq->rspbuf);
3844 #endif
3845         } else {
3846                 ASSERT(rspq->offset == SLIC_RSPQ_BUFSINPAGE);
3847                 WRITE_REG64(adapter,
3848                             adapter->slic_regs->slic_rbar64,
3849                             (rspq->
3850                              paddr[rspq->pageindex] | SLIC_RSPQ_BUFSINPAGE),
3851                             adapter->slic_regs->slic_addr_upper, 0, DONT_FLUSH);
3852                 rspq->pageindex = (++rspq->pageindex) % rspq->num_pages;
3853                 rspq->offset = 0;
3854                 rspq->rspbuf = (struct slic_rspbuf *)
3855                                                 rspq->vaddr[rspq->pageindex];
3856 #ifndef CONFIG_X86_64
3857                 ASSERT(((u32) rspq->rspbuf & 0xFFFFF000) ==
3858                        (u32) rspq->rspbuf);
3859 #endif
3860         }
3861 #ifndef CONFIG_X86_64
3862         ASSERT(((u32) buf & 0xFFFFFFE0) == (u32) buf);
3863 #endif
3864         return buf;
3865 }
3866
3867 static void slic_cmdqmem_init(struct adapter *adapter)
3868 {
3869         struct slic_cmdqmem *cmdqmem = &adapter->cmdqmem;
3870
3871         memset(cmdqmem, 0, sizeof(struct slic_cmdqmem));
3872 }
3873
3874 static void slic_cmdqmem_free(struct adapter *adapter)
3875 {
3876         struct slic_cmdqmem *cmdqmem = &adapter->cmdqmem;
3877         int i;
3878
3879         DBG_MSG("slicoss: (%s) adapter[%p] port %d rspq[%p] Free CMDQ Memory\n",
3880                 __func__, adapter, adapter->physport, cmdqmem);
3881         for (i = 0; i < SLIC_CMDQ_MAXPAGES; i++) {
3882                 if (cmdqmem->pages[i]) {
3883                         DBG_MSG("slicoss: %s Deallocate page  CmdQPage[%p]\n",
3884                                 __func__, (void *) cmdqmem->pages[i]);
3885                         pci_free_consistent(adapter->pcidev,
3886                                             PAGE_SIZE,
3887                                             (void *) cmdqmem->pages[i],
3888                                             cmdqmem->dma_pages[i]);
3889                 }
3890         }
3891         memset(cmdqmem, 0, sizeof(struct slic_cmdqmem));
3892 }
3893
3894 static u32 *slic_cmdqmem_addpage(struct adapter *adapter)
3895 {
3896         struct slic_cmdqmem *cmdqmem = &adapter->cmdqmem;
3897         u32 *pageaddr;
3898
3899         if (cmdqmem->pagecnt >= SLIC_CMDQ_MAXPAGES)
3900                 return NULL;
3901         pageaddr = pci_alloc_consistent(adapter->pcidev,
3902                                         PAGE_SIZE,
3903                                         &cmdqmem->dma_pages[cmdqmem->pagecnt]);
3904         if (!pageaddr)
3905                 return NULL;
3906 #ifndef CONFIG_X86_64
3907         ASSERT(((u32) pageaddr & 0xFFFFF000) == (u32) pageaddr);
3908 #endif
3909         cmdqmem->pages[cmdqmem->pagecnt] = pageaddr;
3910         cmdqmem->pagecnt++;
3911         return pageaddr;
3912 }
3913
3914 static int slic_cmdq_init(struct adapter *adapter)
3915 {
3916         int i;
3917         u32 *pageaddr;
3918
3919         DBG_MSG("slicoss: %s ENTER adapter[%p]\n", __func__, adapter);
3920         ASSERT(adapter->state == ADAPT_DOWN);
3921         memset(&adapter->cmdq_all, 0, sizeof(struct slic_cmdqueue));
3922         memset(&adapter->cmdq_free, 0, sizeof(struct slic_cmdqueue));
3923         memset(&adapter->cmdq_done, 0, sizeof(struct slic_cmdqueue));
3924         spin_lock_init(&adapter->cmdq_all.lock.lock);
3925         spin_lock_init(&adapter->cmdq_free.lock.lock);
3926         spin_lock_init(&adapter->cmdq_done.lock.lock);
3927         slic_cmdqmem_init(adapter);
3928         adapter->slic_handle_ix = 1;
3929         for (i = 0; i < SLIC_CMDQ_INITPAGES; i++) {
3930                 pageaddr = slic_cmdqmem_addpage(adapter);
3931 #ifndef CONFIG_X86_64
3932                 ASSERT(((u32) pageaddr & 0xFFFFF000) == (u32) pageaddr);
3933 #endif
3934                 if (!pageaddr) {
3935                         slic_cmdq_free(adapter);
3936                         return STATUS_FAILURE;
3937                 }
3938                 slic_cmdq_addcmdpage(adapter, pageaddr);
3939         }
3940         adapter->slic_handle_ix = 1;
3941         DBG_MSG("slicoss: %s reset slic_handle_ix to ONE\n", __func__);
3942
3943         return STATUS_SUCCESS;
3944 }
3945
3946 static void slic_cmdq_free(struct adapter *adapter)
3947 {
3948         struct slic_hostcmd *cmd;
3949
3950         DBG_MSG("slicoss: %s adapter[%p] port %d FreeCommandsFrom CMDQ\n",
3951                 __func__, adapter, adapter->physport);
3952         cmd = adapter->cmdq_all.head;
3953         while (cmd) {
3954                 if (cmd->busy) {
3955                         struct sk_buff *tempskb;
3956
3957                         tempskb = cmd->skb;
3958                         if (tempskb) {
3959                                 cmd->skb = NULL;
3960                                 dev_kfree_skb_irq(tempskb);
3961                         }
3962                 }
3963                 cmd = cmd->next_all;
3964         }
3965         memset(&adapter->cmdq_all, 0, sizeof(struct slic_cmdqueue));
3966         memset(&adapter->cmdq_free, 0, sizeof(struct slic_cmdqueue));
3967         memset(&adapter->cmdq_done, 0, sizeof(struct slic_cmdqueue));
3968         slic_cmdqmem_free(adapter);
3969 }
3970
3971 static void slic_cmdq_reset(struct adapter *adapter)
3972 {
3973         struct slic_hostcmd *hcmd;
3974         struct sk_buff *skb;
3975         u32 outstanding;
3976
3977         DBG_MSG("%s ENTER adapter[%p]\n", __func__, adapter);
3978         spin_lock_irqsave(&adapter->cmdq_free.lock.lock,
3979                         adapter->cmdq_free.lock.flags);
3980         spin_lock_irqsave(&adapter->cmdq_done.lock.lock,
3981                         adapter->cmdq_done.lock.flags);
3982         outstanding = adapter->cmdq_all.count - adapter->cmdq_done.count;
3983         outstanding -= adapter->cmdq_free.count;
3984         hcmd = adapter->cmdq_all.head;
3985         while (hcmd) {
3986                 if (hcmd->busy) {
3987                         skb = hcmd->skb;
3988                         ASSERT(skb);
3989                         DBG_MSG("slicoss: %s hcmd[%p] skb[%p] ", __func__,
3990                                 hcmd, skb);
3991                         hcmd->busy = 0;
3992                         hcmd->skb = NULL;
3993                         DBG_MSG(" Free SKB\n");
3994                         dev_kfree_skb_irq(skb);
3995                 }
3996                 hcmd = hcmd->next_all;
3997         }
3998         adapter->cmdq_free.count = 0;
3999         adapter->cmdq_free.head = NULL;
4000         adapter->cmdq_free.tail = NULL;
4001         adapter->cmdq_done.count = 0;
4002         adapter->cmdq_done.head = NULL;
4003         adapter->cmdq_done.tail = NULL;
4004         adapter->cmdq_free.head = adapter->cmdq_all.head;
4005         hcmd = adapter->cmdq_all.head;
4006         while (hcmd) {
4007                 adapter->cmdq_free.count++;
4008                 hcmd->next = hcmd->next_all;
4009                 hcmd = hcmd->next_all;
4010         }
4011         if (adapter->cmdq_free.count != adapter->cmdq_all.count) {
4012                 DBG_ERROR("%s free_count %d != all count %d\n", __func__,
4013                           adapter->cmdq_free.count, adapter->cmdq_all.count);
4014         }
4015         spin_unlock_irqrestore(&adapter->cmdq_done.lock.lock,
4016                                 adapter->cmdq_done.lock.flags);
4017         spin_unlock_irqrestore(&adapter->cmdq_free.lock.lock,
4018                                 adapter->cmdq_free.lock.flags);
4019         DBG_MSG("%s EXIT adapter[%p]\n", __func__, adapter);
4020 }
4021
4022 static void slic_cmdq_addcmdpage(struct adapter *adapter, u32 *page)
4023 {
4024         struct slic_hostcmd *cmd;
4025         struct slic_hostcmd *prev;
4026         struct slic_hostcmd *tail;
4027         struct slic_cmdqueue *cmdq;
4028         int cmdcnt;
4029         void *cmdaddr;
4030         ulong phys_addr;
4031         u32 phys_addrl;
4032         u32 phys_addrh;
4033         struct slic_handle *pslic_handle;
4034
4035         cmdaddr = page;
4036         cmd = (struct slic_hostcmd *)cmdaddr;
4037 /*  DBG_MSG("CMDQ Page addr[%p] ix[%d] pfree[%p]\n", cmdaddr, slic_handle_ix,
4038     adapter->pfree_slic_handles); */
4039         cmdcnt = 0;
4040
4041         phys_addr = virt_to_bus((void *)page);
4042         phys_addrl = SLIC_GET_ADDR_LOW(phys_addr);
4043         phys_addrh = SLIC_GET_ADDR_HIGH(phys_addr);
4044
4045         prev = NULL;
4046         tail = cmd;
4047         while ((cmdcnt < SLIC_CMDQ_CMDSINPAGE) &&
4048                (adapter->slic_handle_ix < 256)) {
4049                 /* Allocate and initialize a SLIC_HANDLE for this command */
4050                 SLIC_GET_SLIC_HANDLE(adapter, pslic_handle);
4051                 if (pslic_handle == NULL)
4052                         ASSERT(0);
4053                 ASSERT(pslic_handle ==
4054                        &adapter->slic_handles[pslic_handle->token.
4055                                               handle_index]);
4056                 pslic_handle->type = SLIC_HANDLE_CMD;
4057                 pslic_handle->address = (void *) cmd;
4058                 pslic_handle->offset = (ushort) adapter->slic_handle_ix++;
4059                 pslic_handle->other_handle = NULL;
4060                 pslic_handle->next = NULL;
4061
4062                 cmd->pslic_handle = pslic_handle;
4063                 cmd->cmd64.hosthandle = pslic_handle->token.handle_token;
4064                 cmd->busy = false;
4065                 cmd->paddrl = phys_addrl;
4066                 cmd->paddrh = phys_addrh;
4067                 cmd->next_all = prev;
4068                 cmd->next = prev;
4069                 prev = cmd;
4070                 phys_addrl += SLIC_HOSTCMD_SIZE;
4071                 cmdaddr += SLIC_HOSTCMD_SIZE;
4072
4073                 cmd = (struct slic_hostcmd *)cmdaddr;
4074                 cmdcnt++;
4075         }
4076
4077         cmdq = &adapter->cmdq_all;
4078         cmdq->count += cmdcnt;  /*  SLIC_CMDQ_CMDSINPAGE;   mooktodo */
4079         tail->next_all = cmdq->head;
4080         ASSERT(VALID_ADDRESS(prev));
4081         cmdq->head = prev;
4082         cmdq = &adapter->cmdq_free;
4083         spin_lock_irqsave(&cmdq->lock.lock, cmdq->lock.flags);
4084         cmdq->count += cmdcnt;  /*  SLIC_CMDQ_CMDSINPAGE;   mooktodo */
4085         tail->next = cmdq->head;
4086         ASSERT(VALID_ADDRESS(prev));
4087         cmdq->head = prev;
4088         spin_unlock_irqrestore(&cmdq->lock.lock, cmdq->lock.flags);
4089 }
4090
4091 static struct slic_hostcmd *slic_cmdq_getfree(struct adapter *adapter)
4092 {
4093         struct slic_cmdqueue *cmdq = &adapter->cmdq_free;
4094         struct slic_hostcmd *cmd = NULL;
4095
4096 lock_and_retry:
4097         spin_lock_irqsave(&cmdq->lock.lock, cmdq->lock.flags);
4098 retry:
4099         cmd = cmdq->head;
4100         if (cmd) {
4101                 cmdq->head = cmd->next;
4102                 cmdq->count--;
4103                 spin_unlock_irqrestore(&cmdq->lock.lock, cmdq->lock.flags);
4104         } else {
4105                 slic_cmdq_getdone(adapter);
4106                 cmd = cmdq->head;
4107                 if (cmd) {
4108                         goto retry;
4109                 } else {
4110                         u32 *pageaddr;
4111
4112                         spin_unlock_irqrestore(&cmdq->lock.lock,
4113                                                 cmdq->lock.flags);
4114                         pageaddr = slic_cmdqmem_addpage(adapter);
4115                         if (pageaddr) {
4116                                 slic_cmdq_addcmdpage(adapter, pageaddr);
4117                                 goto lock_and_retry;
4118                         }
4119                 }
4120         }
4121         return cmd;
4122 }
4123
4124 static void slic_cmdq_getdone(struct adapter *adapter)
4125 {
4126         struct slic_cmdqueue *done_cmdq = &adapter->cmdq_done;
4127         struct slic_cmdqueue *free_cmdq = &adapter->cmdq_free;
4128
4129         ASSERT(free_cmdq->head == NULL);
4130         spin_lock_irqsave(&done_cmdq->lock.lock, done_cmdq->lock.flags);
4131         ASSERT(VALID_ADDRESS(done_cmdq->head));
4132
4133         free_cmdq->head = done_cmdq->head;
4134         free_cmdq->count = done_cmdq->count;
4135         done_cmdq->head = NULL;
4136         done_cmdq->tail = NULL;
4137         done_cmdq->count = 0;
4138         spin_unlock_irqrestore(&done_cmdq->lock.lock, done_cmdq->lock.flags);
4139 }
4140
4141 static void slic_cmdq_putdone_irq(struct adapter *adapter,
4142                                 struct slic_hostcmd *cmd)
4143 {
4144         struct slic_cmdqueue *cmdq = &adapter->cmdq_done;
4145
4146         spin_lock(&cmdq->lock.lock);
4147         cmd->busy = 0;
4148         ASSERT(VALID_ADDRESS(cmdq->head));
4149         cmd->next = cmdq->head;
4150         ASSERT(VALID_ADDRESS(cmd));
4151         cmdq->head = cmd;
4152         cmdq->count++;
4153         if ((adapter->xmitq_full) && (cmdq->count > 10))
4154                 netif_wake_queue(adapter->netdev);
4155         spin_unlock(&cmdq->lock.lock);
4156 }
4157
4158 static int slic_rcvqueue_init(struct adapter *adapter)
4159 {
4160         int i, count;
4161         struct slic_rcvqueue *rcvq = &adapter->rcvqueue;
4162
4163         DBG_MSG("slicoss: %s ENTER adapter[%p]\n", __func__, adapter);
4164         ASSERT(adapter->state == ADAPT_DOWN);
4165         rcvq->tail = NULL;
4166         rcvq->head = NULL;
4167         rcvq->size = SLIC_RCVQ_ENTRIES;
4168         rcvq->errors = 0;
4169         rcvq->count = 0;
4170         i = (SLIC_RCVQ_ENTRIES / SLIC_RCVQ_FILLENTRIES);
4171         count = 0;
4172         while (i) {
4173                 count += slic_rcvqueue_fill(adapter);
4174                 i--;
4175         }
4176         if (rcvq->count < SLIC_RCVQ_MINENTRIES) {
4177                 slic_rcvqueue_free(adapter);
4178                 return STATUS_FAILURE;
4179         }
4180         DBG_MSG("slicoss: %s EXIT adapter[%p]\n", __func__, adapter);
4181         return STATUS_SUCCESS;
4182 }
4183
4184 static int slic_rcvqueue_reset(struct adapter *adapter)
4185 {
4186         struct slic_rcvqueue *rcvq = &adapter->rcvqueue;
4187
4188         DBG_MSG("slicoss: %s ENTER adapter[%p]\n", __func__, adapter);
4189         ASSERT(adapter->state == ADAPT_DOWN);
4190         ASSERT(rcvq);
4191
4192         DBG_MSG("slicoss: Nothing to do. rcvq[%p]\n"
4193                 "                             count[%x]\n"
4194                 "                             head[%p]\n"
4195                 "                             tail[%p]\n",
4196                 rcvq, rcvq->count, rcvq->head, rcvq->tail);
4197
4198         DBG_MSG("slicoss: %s EXIT adapter[%p]\n", __func__, adapter);
4199         return STATUS_SUCCESS;
4200 }
4201
4202 static void slic_rcvqueue_free(struct adapter *adapter)
4203 {
4204         struct slic_rcvqueue *rcvq = &adapter->rcvqueue;
4205         struct sk_buff *skb;
4206
4207         while (rcvq->head) {
4208                 skb = rcvq->head;
4209                 rcvq->head = rcvq->head->next;
4210                 dev_kfree_skb(skb);
4211         }
4212         rcvq->tail = NULL;
4213         rcvq->head = NULL;
4214         rcvq->count = 0;
4215 }
4216
4217 static struct sk_buff *slic_rcvqueue_getnext(struct adapter *adapter)
4218 {
4219         struct slic_rcvqueue *rcvq = &adapter->rcvqueue;
4220         struct sk_buff *skb;
4221         struct slic_rcvbuf *rcvbuf;
4222         int count;
4223
4224         if (rcvq->count) {
4225                 skb = rcvq->head;
4226                 rcvbuf = (struct slic_rcvbuf *)skb->head;
4227                 ASSERT(rcvbuf);
4228
4229                 if (rcvbuf->status & IRHDDR_SVALID) {
4230                         rcvq->head = rcvq->head->next;
4231                         skb->next = NULL;
4232                         rcvq->count--;
4233                 } else {
4234                         skb = NULL;
4235                 }
4236         } else {
4237                 DBG_ERROR("RcvQ Empty!! adapter[%p] rcvq[%p] count[%x]\n",
4238                           adapter, rcvq, rcvq->count);
4239                 skb = NULL;
4240         }
4241         while (rcvq->count < SLIC_RCVQ_FILLTHRESH) {
4242                 count = slic_rcvqueue_fill(adapter);
4243                 if (!count)
4244                         break;
4245         }
4246         if (skb)
4247                 rcvq->errors = 0;
4248         return skb;
4249 }
4250
4251 static int slic_rcvqueue_fill(struct adapter *adapter)
4252 {
4253         void *paddr;
4254         u32 paddrl;
4255         u32 paddrh;
4256         struct slic_rcvqueue *rcvq = &adapter->rcvqueue;
4257         int i = 0;
4258
4259         while (i < SLIC_RCVQ_FILLENTRIES) {
4260                 struct slic_rcvbuf *rcvbuf;
4261                 struct sk_buff *skb;
4262 #ifdef KLUDGE_FOR_4GB_BOUNDARY
4263 retry_rcvqfill:
4264 #endif
4265                 skb = alloc_skb(SLIC_RCVQ_RCVBUFSIZE, GFP_ATOMIC);
4266                 if (skb) {
4267                         paddr = (void *)pci_map_single(adapter->pcidev,
4268                                                           skb->data,
4269                                                           SLIC_RCVQ_RCVBUFSIZE,
4270                                                           PCI_DMA_FROMDEVICE);
4271                         paddrl = SLIC_GET_ADDR_LOW(paddr);
4272                         paddrh = SLIC_GET_ADDR_HIGH(paddr);
4273
4274                         skb->len = SLIC_RCVBUF_HEADSIZE;
4275                         rcvbuf = (struct slic_rcvbuf *)skb->head;
4276                         rcvbuf->status = 0;
4277                         skb->next = NULL;
4278 #ifdef KLUDGE_FOR_4GB_BOUNDARY
4279                         if (paddrl == 0) {
4280                                 DBG_ERROR
4281                                     ("%s: LOW 32bits PHYSICAL ADDRESS == 0 "
4282                                      "skb[%p]   PROBLEM\n"
4283                                      "         skbdata[%p]\n"
4284                                      "         skblen[%x]\n"
4285                                      "         paddr[%p]\n"
4286                                      "         paddrl[%x]\n"
4287                                      "         paddrh[%x]\n", __func__, skb,
4288                                      skb->data, skb->len, paddr, paddrl,
4289                                      paddrh);
4290                                 DBG_ERROR("         rcvq->head[%p]\n"
4291                                           "         rcvq->tail[%p]\n"
4292                                           "         rcvq->count[%x]\n",
4293                                           rcvq->head, rcvq->tail, rcvq->count);
4294                                 DBG_ERROR("SKIP THIS SKB!!!!!!!!\n");
4295                                 goto retry_rcvqfill;
4296                         }
4297 #else
4298                         if (paddrl == 0) {
4299                                 DBG_ERROR
4300                                     ("\n\n%s: LOW 32bits PHYSICAL ADDRESS == 0 "
4301                                      "skb[%p]  GIVE TO CARD ANYWAY\n"
4302                                      "         skbdata[%p]\n"
4303                                      "         paddr[%p]\n"
4304                                      "         paddrl[%x]\n"
4305                                      "         paddrh[%x]\n", __func__, skb,
4306                                      skb->data, paddr, paddrl, paddrh);
4307                         }
4308 #endif
4309                         if (paddrh == 0) {
4310                                 WRITE_REG(adapter->slic_regs->slic_hbar,
4311                                           (u32) paddrl, DONT_FLUSH);
4312                         } else {
4313                                 WRITE_REG64(adapter,
4314                                             adapter->slic_regs->slic_hbar64,
4315                                             (u32) paddrl,
4316                                             adapter->slic_regs->slic_addr_upper,
4317                                             (u32) paddrh, DONT_FLUSH);
4318                         }
4319                         if (rcvq->head)
4320                                 rcvq->tail->next = skb;
4321                         else
4322                                 rcvq->head = skb;
4323                         rcvq->tail = skb;
4324                         rcvq->count++;
4325                         i++;
4326                 } else {
4327                         DBG_ERROR
4328                             ("%s slic_rcvqueue_fill could only get [%d] "
4329                              "skbuffs\n",
4330                              adapter->netdev->name, i);
4331                         break;
4332                 }
4333         }
4334         return i;
4335 }
4336
4337 static u32 slic_rcvqueue_reinsert(struct adapter *adapter, struct sk_buff *skb)
4338 {
4339         struct slic_rcvqueue *rcvq = &adapter->rcvqueue;
4340         void *paddr;
4341         u32 paddrl;
4342         u32 paddrh;
4343         struct slic_rcvbuf *rcvbuf = (struct slic_rcvbuf *)skb->head;
4344
4345         ASSERT(skb->len == SLIC_RCVBUF_HEADSIZE);
4346
4347         paddr = (void *)pci_map_single(adapter->pcidev, skb->head,
4348                                   SLIC_RCVQ_RCVBUFSIZE, PCI_DMA_FROMDEVICE);
4349         rcvbuf->status = 0;
4350         skb->next = NULL;
4351
4352         paddrl = SLIC_GET_ADDR_LOW(paddr);
4353         paddrh = SLIC_GET_ADDR_HIGH(paddr);
4354
4355         if (paddrl == 0) {
4356                 DBG_ERROR
4357                     ("%s: LOW 32bits PHYSICAL ADDRESS == 0 skb[%p]   PROBLEM\n"
4358                      "         skbdata[%p]\n" "         skblen[%x]\n"
4359                      "         paddr[%p]\n" "         paddrl[%x]\n"
4360                      "         paddrh[%x]\n", __func__, skb, skb->data,
4361                      skb->len, paddr, paddrl, paddrh);
4362                 DBG_ERROR("         rcvq->head[%p]\n"
4363                           "         rcvq->tail[%p]\n"
4364                           "         rcvq->count[%x]\n", rcvq->head, rcvq->tail,
4365                           rcvq->count);
4366         }
4367         if (paddrh == 0) {
4368                 WRITE_REG(adapter->slic_regs->slic_hbar, (u32) paddrl,
4369                           DONT_FLUSH);
4370         } else {
4371                 WRITE_REG64(adapter,
4372                             adapter->slic_regs->slic_hbar64,
4373                             paddrl,
4374                             adapter->slic_regs->slic_addr_upper,
4375                             paddrh, DONT_FLUSH);
4376         }
4377         if (rcvq->head)
4378                 rcvq->tail->next = skb;
4379         else
4380                 rcvq->head = skb;
4381         rcvq->tail = skb;
4382         rcvq->count++;
4383         return rcvq->count;
4384 }
4385
4386 static int slic_debug_card_show(struct seq_file *seq, void *v)
4387 {
4388 #ifdef MOOKTODO
4389         int i;
4390         struct sliccard *card = seq->private;
4391         struct slic_config *config = &card->config;
4392         unsigned char *fru = (unsigned char *)(&card->config.atk_fru);
4393         unsigned char *oemfru = (unsigned char *)(&card->config.OemFru);
4394 #endif
4395
4396         seq_printf(seq, "driver_version           : %s\n", slic_proc_version);
4397         seq_printf(seq, "Microcode versions:           \n");
4398         seq_printf(seq, "    Gigabit (gb)         : %s %s\n",
4399                     MOJAVE_UCODE_VERS_STRING, MOJAVE_UCODE_VERS_DATE);
4400         seq_printf(seq, "    Gigabit Receiver     : %s %s\n",
4401                     GB_RCVUCODE_VERS_STRING, GB_RCVUCODE_VERS_DATE);
4402         seq_printf(seq, "Vendor                   : %s\n", slic_vendor);
4403         seq_printf(seq, "Product Name             : %s\n", slic_product_name);
4404 #ifdef MOOKTODO
4405         seq_printf(seq, "VendorId                 : %4.4X\n",
4406                     config->VendorId);
4407         seq_printf(seq, "DeviceId                 : %4.4X\n",
4408                     config->DeviceId);
4409         seq_printf(seq, "RevisionId               : %2.2x\n",
4410                     config->RevisionId);
4411         seq_printf(seq, "Bus    #                 : %d\n", card->busnumber);
4412         seq_printf(seq, "Device #                 : %d\n", card->slotnumber);
4413         seq_printf(seq, "Interfaces               : %d\n", card->card_size);
4414         seq_printf(seq, "     Initialized         : %d\n",
4415                     card->adapters_activated);
4416         seq_printf(seq, "     Allocated           : %d\n",
4417                     card->adapters_allocated);
4418         ASSERT(card->card_size <= SLIC_NBR_MACS);
4419         for (i = 0; i < card->card_size; i++) {
4420                 seq_printf(seq,
4421                            "     MAC%d : %2.2X %2.2X %2.2X %2.2X %2.2X %2.2X\n",
4422                            i, config->macinfo[i].macaddrA[0],
4423                            config->macinfo[i].macaddrA[1],
4424                            config->macinfo[i].macaddrA[2],
4425                            config->macinfo[i].macaddrA[3],
4426                            config->macinfo[i].macaddrA[4],
4427                            config->macinfo[i].macaddrA[5]);
4428         }
4429         seq_printf(seq, "     IF  Init State Duplex/Speed irq\n");
4430         seq_printf(seq, "     -------------------------------\n");
4431         for (i = 0; i < card->adapters_allocated; i++) {
4432                 struct adapter *adapter;
4433
4434                 adapter = card->adapter[i];
4435                 if (adapter) {
4436                         seq_printf(seq,
4437                                     "     %d   %d   %s  %s  %s    0x%X\n",
4438                                     adapter->physport, adapter->state,
4439                                     SLIC_LINKSTATE(adapter->linkstate),
4440                                     SLIC_DUPLEX(adapter->linkduplex),
4441                                     SLIC_SPEED(adapter->linkspeed),
4442                                     (uint) adapter->irq);
4443                 }
4444         }
4445         seq_printf(seq, "Generation #             : %4.4X\n", card->gennumber);
4446         seq_printf(seq, "RcvQ max entries         : %4.4X\n",
4447                     SLIC_RCVQ_ENTRIES);
4448         seq_printf(seq, "Ping Status              : %8.8X\n",
4449                     card->pingstatus);
4450         seq_printf(seq, "Minimum grant            : %2.2x\n",
4451                     config->MinGrant);
4452         seq_printf(seq, "Maximum Latency          : %2.2x\n", config->MaxLat);
4453         seq_printf(seq, "PciStatus                : %4.4x\n",
4454                     config->Pcistatus);
4455         seq_printf(seq, "Debug Device Id          : %4.4x\n",
4456                     config->DbgDevId);
4457         seq_printf(seq, "DRAM ROM Function        : %4.4x\n",
4458                     config->DramRomFn);
4459         seq_printf(seq, "Network interface Pin 1  : %2.2x\n",
4460                     config->NetIntPin1);
4461         seq_printf(seq, "Network interface Pin 2  : %2.2x\n",
4462                     config->NetIntPin1);
4463         seq_printf(seq, "Network interface Pin 3  : %2.2x\n",
4464                     config->NetIntPin1);
4465         seq_printf(seq, "PM capabilities          : %4.4X\n",
4466                     config->PMECapab);
4467         seq_printf(seq, "Network Clock Controls   : %4.4X\n",
4468                     config->NwClkCtrls);
4469
4470         switch (config->FruFormat) {
4471         case ATK_FRU_FORMAT:
4472                 {
4473                         seq_printf(seq,
4474                             "Vendor                   : Alacritech, Inc.\n");
4475                         seq_printf(seq,
4476                             "Assembly #               : %c%c%c%c%c%c\n",
4477                                     fru[0], fru[1], fru[2], fru[3], fru[4],
4478                                     fru[5]);
4479                         seq_printf(seq,
4480                                     "Revision #               : %c%c\n",
4481                                     fru[6], fru[7]);
4482
4483                         if (config->OEMFruFormat == VENDOR4_FRU_FORMAT) {
4484                                 seq_printf(seq,
4485                                             "Serial   #               : "
4486                                             "%c%c%c%c%c%c%c%c%c%c%c%c\n",
4487                                             fru[8], fru[9], fru[10],
4488                                             fru[11], fru[12], fru[13],
4489                                             fru[16], fru[17], fru[18],
4490                                             fru[19], fru[20], fru[21]);
4491                         } else {
4492                                 seq_printf(seq,
4493                                             "Serial   #               : "
4494                                             "%c%c%c%c%c%c%c%c%c%c%c%c%c%c\n",
4495                                             fru[8], fru[9], fru[10],
4496                                             fru[11], fru[12], fru[13],
4497                                             fru[14], fru[15], fru[16],
4498                                             fru[17], fru[18], fru[19],
4499                                             fru[20], fru[21]);
4500                         }
4501                         break;
4502                 }
4503
4504         default:
4505                 {
4506                         seq_printf(seq,
4507                             "Vendor                   : Alacritech, Inc.\n");
4508                         seq_printf(seq,
4509                             "Serial   #               : Empty FRU\n");
4510                         break;
4511                 }
4512         }
4513
4514         switch (config->OEMFruFormat) {
4515         case VENDOR1_FRU_FORMAT:
4516                 {
4517                         seq_printf(seq, "FRU Information:\n");
4518                         seq_printf(seq, "    Commodity #          : %c\n",
4519                                     oemfru[0]);
4520                         seq_printf(seq,
4521                                     "    Assembly #           : %c%c%c%c\n",
4522                                     oemfru[1], oemfru[2], oemfru[3], oemfru[4]);
4523                         seq_printf(seq,
4524                                     "    Revision #           : %c%c\n",
4525                                     oemfru[5], oemfru[6]);
4526                         seq_printf(seq,
4527                                     "    Supplier #           : %c%c\n",
4528                                     oemfru[7], oemfru[8]);
4529                         seq_printf(seq,
4530                                     "    Date                 : %c%c\n",
4531                                     oemfru[9], oemfru[10]);
4532                         seq_sprintf(seq,
4533                                     "    Sequence #           : %c%c%c\n",
4534                                     oemfru[11], oemfru[12], oemfru[13]);
4535                         break;
4536                 }
4537
4538         case VENDOR2_FRU_FORMAT:
4539                 {
4540                         seq_printf(seq, "FRU Information:\n");
4541                         seq_printf(seq,
4542                                     "    Part     #           : "
4543                                     "%c%c%c%c%c%c%c%c\n",
4544                                     oemfru[0], oemfru[1], oemfru[2],
4545                                     oemfru[3], oemfru[4], oemfru[5],
4546                                     oemfru[6], oemfru[7]);
4547                         seq_printf(seq,
4548                                     "    Supplier #           : %c%c%c%c%c\n",
4549                                     oemfru[8], oemfru[9], oemfru[10],
4550                                     oemfru[11], oemfru[12]);
4551                         seq_printf(seq,
4552                                     "    Date                 : %c%c%c\n",
4553                                     oemfru[13], oemfru[14], oemfru[15]);
4554                         seq_sprintf(seq,
4555                                     "    Sequence #           : %c%c%c%c\n",
4556                                     oemfru[16], oemfru[17], oemfru[18],
4557                                     oemfru[19]);
4558                         break;
4559                 }
4560
4561         case VENDOR3_FRU_FORMAT:
4562                 {
4563                         seq_printf(seq, "FRU Information:\n");
4564                 }
4565
4566         case VENDOR4_FRU_FORMAT:
4567                 {
4568                         seq_printf(seq, "FRU Information:\n");
4569                         seq_printf(seq,
4570                                     "    FRU Number           : "
4571                                     "%c%c%c%c%c%c%c%c\n",
4572                                     oemfru[0], oemfru[1], oemfru[2],
4573                                     oemfru[3], oemfru[4], oemfru[5],
4574                                     oemfru[6], oemfru[7]);
4575                         seq_sprintf(seq,
4576                                     "    Part Number          : "
4577                                     "%c%c%c%c%c%c%c%c\n",
4578                                     oemfru[8], oemfru[9], oemfru[10],
4579                                     oemfru[11], oemfru[12], oemfru[13],
4580                                     oemfru[14], oemfru[15]);
4581                         seq_printf(seq,
4582                                     "    EC Level             : "
4583                                     "%c%c%c%c%c%c%c%c\n",
4584                                     oemfru[16], oemfru[17], oemfru[18],
4585                                     oemfru[19], oemfru[20], oemfru[21],
4586                                     oemfru[22], oemfru[23]);
4587                         break;
4588                 }
4589
4590         default:
4591                 break;
4592         }
4593 #endif
4594
4595         return 0;
4596 }
4597
4598 static int slic_debug_adapter_show(struct seq_file *seq, void *v)
4599 {
4600         struct adapter *adapter = seq->private;
4601
4602         if ((adapter->netdev) && (adapter->netdev->name)) {
4603                 seq_printf(seq, "info: interface          : %s\n",
4604                             adapter->netdev->name);
4605         }
4606         seq_printf(seq, "info: status             : %s\n",
4607                 SLIC_LINKSTATE(adapter->linkstate));
4608         seq_printf(seq, "info: port               : %d\n",
4609                 adapter->physport);
4610         seq_printf(seq, "info: speed              : %s\n",
4611                 SLIC_SPEED(adapter->linkspeed));
4612         seq_printf(seq, "info: duplex             : %s\n",
4613                 SLIC_DUPLEX(adapter->linkduplex));
4614         seq_printf(seq, "info: irq                : 0x%X\n",
4615                 (uint) adapter->irq);
4616         seq_printf(seq, "info: Interrupt Agg Delay: %d usec\n",
4617                 adapter->card->loadlevel_current);
4618         seq_printf(seq, "info: RcvQ max entries   : %4.4X\n",
4619                 SLIC_RCVQ_ENTRIES);
4620         seq_printf(seq, "info: RcvQ current       : %4.4X\n",
4621                     adapter->rcvqueue.count);
4622         seq_printf(seq, "rx stats: packets                  : %8.8lX\n",
4623                     adapter->stats.rx_packets);
4624         seq_printf(seq, "rx stats: bytes                    : %8.8lX\n",
4625                     adapter->stats.rx_bytes);
4626         seq_printf(seq, "rx stats: broadcasts               : %8.8X\n",
4627                     adapter->rcv_broadcasts);
4628         seq_printf(seq, "rx stats: multicasts               : %8.8X\n",
4629                     adapter->rcv_multicasts);
4630         seq_printf(seq, "rx stats: unicasts                 : %8.8X\n",
4631                     adapter->rcv_unicasts);
4632         seq_printf(seq, "rx stats: errors                   : %8.8X\n",
4633                     (u32) adapter->slic_stats.iface.rcv_errors);
4634         seq_printf(seq, "rx stats: Missed errors            : %8.8X\n",
4635                     (u32) adapter->slic_stats.iface.rcv_discards);
4636         seq_printf(seq, "rx stats: drops                    : %8.8X\n",
4637                         (u32) adapter->rcv_drops);
4638         seq_printf(seq, "tx stats: packets                  : %8.8lX\n",
4639                         adapter->stats.tx_packets);
4640         seq_printf(seq, "tx stats: bytes                    : %8.8lX\n",
4641                         adapter->stats.tx_bytes);
4642         seq_printf(seq, "tx stats: errors                   : %8.8X\n",
4643                         (u32) adapter->slic_stats.iface.xmt_errors);
4644         seq_printf(seq, "rx stats: multicasts               : %8.8lX\n",
4645                         adapter->stats.multicast);
4646         seq_printf(seq, "tx stats: collision errors         : %8.8X\n",
4647                         (u32) adapter->slic_stats.iface.xmit_collisions);
4648         seq_printf(seq, "perf: Max rcv frames/isr           : %8.8X\n",
4649                         adapter->max_isr_rcvs);
4650         seq_printf(seq, "perf: Rcv interrupt yields         : %8.8X\n",
4651                         adapter->rcv_interrupt_yields);
4652         seq_printf(seq, "perf: Max xmit complete/isr        : %8.8X\n",
4653                         adapter->max_isr_xmits);
4654         seq_printf(seq, "perf: error interrupts             : %8.8X\n",
4655                         adapter->error_interrupts);
4656         seq_printf(seq, "perf: error rmiss interrupts       : %8.8X\n",
4657                         adapter->error_rmiss_interrupts);
4658         seq_printf(seq, "perf: rcv interrupts               : %8.8X\n",
4659                         adapter->rcv_interrupts);
4660         seq_printf(seq, "perf: xmit interrupts              : %8.8X\n",
4661                         adapter->xmit_interrupts);
4662         seq_printf(seq, "perf: link event interrupts        : %8.8X\n",
4663                         adapter->linkevent_interrupts);
4664         seq_printf(seq, "perf: UPR interrupts               : %8.8X\n",
4665                         adapter->upr_interrupts);
4666         seq_printf(seq, "perf: interrupt count              : %8.8X\n",
4667                         adapter->num_isrs);
4668         seq_printf(seq, "perf: false interrupts             : %8.8X\n",
4669                         adapter->false_interrupts);
4670         seq_printf(seq, "perf: All register writes          : %8.8X\n",
4671                         adapter->all_reg_writes);
4672         seq_printf(seq, "perf: ICR register writes          : %8.8X\n",
4673                         adapter->icr_reg_writes);
4674         seq_printf(seq, "perf: ISR register writes          : %8.8X\n",
4675                         adapter->isr_reg_writes);
4676         seq_printf(seq, "ifevents: overflow 802 errors      : %8.8X\n",
4677                         adapter->if_events.oflow802);
4678         seq_printf(seq, "ifevents: transport overflow errors: %8.8X\n",
4679                         adapter->if_events.Tprtoflow);
4680         seq_printf(seq, "ifevents: underflow errors         : %8.8X\n",
4681                         adapter->if_events.uflow802);
4682         seq_printf(seq, "ifevents: receive early            : %8.8X\n",
4683                         adapter->if_events.rcvearly);
4684         seq_printf(seq, "ifevents: buffer overflows         : %8.8X\n",
4685                         adapter->if_events.Bufov);
4686         seq_printf(seq, "ifevents: carrier errors           : %8.8X\n",
4687                         adapter->if_events.Carre);
4688         seq_printf(seq, "ifevents: Long                     : %8.8X\n",
4689                         adapter->if_events.Longe);
4690         seq_printf(seq, "ifevents: invalid preambles        : %8.8X\n",
4691                         adapter->if_events.Invp);
4692         seq_printf(seq, "ifevents: CRC errors               : %8.8X\n",
4693                         adapter->if_events.Crc);
4694         seq_printf(seq, "ifevents: dribble nibbles          : %8.8X\n",
4695                         adapter->if_events.Drbl);
4696         seq_printf(seq, "ifevents: Code violations          : %8.8X\n",
4697                         adapter->if_events.Code);
4698         seq_printf(seq, "ifevents: TCP checksum errors      : %8.8X\n",
4699                         adapter->if_events.TpCsum);
4700         seq_printf(seq, "ifevents: TCP header short errors  : %8.8X\n",
4701                         adapter->if_events.TpHlen);
4702         seq_printf(seq, "ifevents: IP checksum errors       : %8.8X\n",
4703                         adapter->if_events.IpCsum);
4704         seq_printf(seq, "ifevents: IP frame incompletes     : %8.8X\n",
4705                         adapter->if_events.IpLen);
4706         seq_printf(seq, "ifevents: IP headers shorts        : %8.8X\n",
4707                         adapter->if_events.IpHlen);
4708
4709         return 0;
4710 }
4711 static int slic_debug_adapter_open(struct inode *inode, struct file *file)
4712 {
4713         return single_open(file, slic_debug_adapter_show, inode->i_private);
4714 }
4715
4716 static int slic_debug_card_open(struct inode *inode, struct file *file)
4717 {
4718         return single_open(file, slic_debug_card_show, inode->i_private);
4719 }
4720
4721 static const struct file_operations slic_debug_adapter_fops = {
4722         .owner          = THIS_MODULE,
4723         .open           = slic_debug_adapter_open,
4724         .read           = seq_read,
4725         .llseek         = seq_lseek,
4726         .release        = single_release,
4727 };
4728
4729 static const struct file_operations slic_debug_card_fops = {
4730         .owner          = THIS_MODULE,
4731         .open           = slic_debug_card_open,
4732         .read           = seq_read,
4733         .llseek         = seq_lseek,
4734         .release        = single_release,
4735 };
4736
4737 static void slic_debug_adapter_create(struct adapter *adapter)
4738 {
4739         struct dentry *d;
4740         char    name[7];
4741         struct sliccard *card = adapter->card;
4742
4743         if (!card->debugfs_dir)
4744                 return;
4745
4746         sprintf(name, "port%d", adapter->port);
4747         d = debugfs_create_file(name, S_IRUGO,
4748                                 card->debugfs_dir, adapter,
4749                                 &slic_debug_adapter_fops);
4750         if (!d || IS_ERR(d))
4751                 pr_info(PFX "%s: debugfs create failed\n", name);
4752         else
4753                 adapter->debugfs_entry = d;
4754 }
4755
4756 static void slic_debug_adapter_destroy(struct adapter *adapter)
4757 {
4758         if (adapter->debugfs_entry) {
4759                 debugfs_remove(adapter->debugfs_entry);
4760                 adapter->debugfs_entry = NULL;
4761         }
4762 }
4763
4764 static void slic_debug_card_create(struct sliccard *card)
4765 {
4766         struct dentry *d;
4767         char    name[IFNAMSIZ];
4768
4769         snprintf(name, sizeof(name), "slic%d", card->cardnum);
4770         d = debugfs_create_dir(name, slic_debugfs);
4771         if (!d || IS_ERR(d))
4772                 pr_info(PFX "%s: debugfs create dir failed\n",
4773                                 name);
4774         else {
4775                 card->debugfs_dir = d;
4776                 d = debugfs_create_file("cardinfo", S_IRUGO,
4777                                 slic_debugfs, card,
4778                                 &slic_debug_card_fops);
4779                 if (!d || IS_ERR(d))
4780                         pr_info(PFX "%s: debugfs create failed\n",
4781                                         name);
4782                 else
4783                         card->debugfs_cardinfo = d;
4784         }
4785 }
4786
4787 static void slic_debug_card_destroy(struct sliccard *card)
4788 {
4789         int i;
4790
4791         for (i = 0; i < card->card_size; i++) {
4792                 struct adapter *adapter;
4793
4794                 adapter = card->adapter[i];
4795                 if (adapter)
4796                         slic_debug_adapter_destroy(adapter);
4797         }
4798         if (card->debugfs_cardinfo) {
4799                 debugfs_remove(card->debugfs_cardinfo);
4800                 card->debugfs_cardinfo = NULL;
4801         }
4802         if (card->debugfs_dir) {
4803                 debugfs_remove(card->debugfs_dir);
4804                 card->debugfs_dir = NULL;
4805         }
4806 }
4807
4808 static void slic_debug_init(void)
4809 {
4810         struct dentry *ent;
4811
4812         ent = debugfs_create_dir("slic", NULL);
4813         if (!ent || IS_ERR(ent)) {
4814                 pr_info(PFX "debugfs create directory failed\n");
4815                 return;
4816         }
4817
4818         slic_debugfs = ent;
4819 }
4820
4821 static void slic_debug_cleanup(void)
4822 {
4823         if (slic_debugfs) {
4824                 debugfs_remove(slic_debugfs);
4825                 slic_debugfs = NULL;
4826         }
4827 }
4828
4829 /*=============================================================================
4830   =============================================================================
4831   ===                                                                       ===
4832   ===       SLIC  DUMP  MANAGEMENT        SECTION                           ===
4833   ===                                                                       ===
4834   ===                                                                       ===
4835   === Dump routines                                                         ===
4836   ===                                                                       ===
4837   ===                                                                       ===
4838   =============================================================================
4839   ============================================================================*/
4840
4841 #if SLIC_DUMP_ENABLED
4842
4843 #include <stdarg.h>
4844
4845 void *slic_dump_handle;         /* thread handle */
4846
4847 /*
4848  * These are the only things you should do on a core-file: use only these
4849  * functions to write out all the necessary info.
4850  */
4851 static int slic_dump_seek(struct file *SLIChandle, u32 file_offset)
4852 {
4853         if (SLIChandle->f_pos != file_offset) {
4854                 /*DBG_MSG("slic_dump_seek  now needed [%x : %x]\n",
4855                         (u32)SLIChandle->f_pos, (u32)file_offset); */
4856                 if (SLIChandle->f_op->llseek) {
4857                         if (SLIChandle->f_op->
4858                             llseek(SLIChandle, file_offset, 0) != file_offset)
4859                                 return 0;
4860                 } else {
4861                         SLIChandle->f_pos = file_offset;
4862                 }
4863         }
4864         return 1;
4865 }
4866
4867 static int slic_dump_write(struct sliccard *card,
4868                            const void *addr, int size, u32 file_offset)
4869 {
4870         int r = 1;
4871         u32 result = 0;
4872         struct file *SLIChandle = card->dumphandle;
4873
4874 #ifdef HISTORICAL               /* legacy */
4875         down(&SLIChandle->f_dentry->d_inode->i_sem);
4876 #endif
4877         if (size) {
4878                 slic_dump_seek(SLIChandle, file_offset);
4879
4880                 result =
4881                     SLIChandle->f_op->write(SLIChandle, addr, size,
4882                                             &SLIChandle->f_pos);
4883
4884                 r = result == size;
4885         }
4886
4887         card->dumptime_complete = jiffies;
4888         card->dumptime_delta = card->dumptime_complete - card->dumptime_start;
4889         card->dumptime_start = jiffies;
4890
4891 #ifdef HISTORICAL
4892         up(&SLIChandle->f_dentry->d_inode->i_sem);
4893 #endif
4894         if (!r) {
4895                 DBG_ERROR("%s: addr[%p] size[%x] result[%x] file_offset[%x]\n",
4896                           __func__, addr, size, result, file_offset);
4897         }
4898         return r;
4899 }
4900
4901 static uint slic_init_dump_thread(struct sliccard *card)
4902 {
4903         card->dump_task_id = kthread_run(slic_dump_thread, (void *)card, 0);
4904
4905 /*  DBG_MSG("create slic_dump_thread dump_pid[%x]\n", card->dump_pid); */
4906         if (IS_ERR(card->dump_task_id)) {
4907                 DBG_MSG("create slic_dump_thread FAILED \n");
4908                 return STATUS_FAILURE;
4909         }
4910
4911         return STATUS_SUCCESS;
4912 }
4913
4914 static int slic_dump_thread(void *context)
4915 {
4916         struct sliccard *card = (struct sliccard *)context;
4917         struct adapter *adapter;
4918         struct adapter *dump_adapter = NULL;
4919         u32 dump_complete = 0;
4920         u32 delay = (PING_TIMER_INTERVAL * HZ);
4921         struct slic_regs *pregs;
4922         u32 i;
4923         struct slic_upr *upr, *uprnext;
4924         u32 dump_card;
4925
4926         ASSERT(card);
4927
4928         card->dumpthread_running = 1;
4929
4930 #ifdef HISTORICAL
4931         lock_kernel();
4932         /*
4933          * This thread doesn't need any user-level access,
4934          * so get rid of all our resources
4935          */
4936         exit_files(current);    /* daemonize doesn't do exit_files */
4937         current->files = init_task.files;
4938         atomic_inc(&current->files->count);
4939 #endif
4940
4941         daemonize("%s", "slicmon");
4942
4943         /* Setup a nice name */
4944         strcpy(current->comm, "slicmon");
4945         DBG_ERROR
4946             ("slic_dump_thread[slicmon] daemon is alive card[%p] pid[%x]\n",
4947              card, card->dump_task_id->pid);
4948
4949         /*
4950          *    Send me a signal to get me to die (for debugging)
4951          */
4952         do {
4953                 /*
4954                  * If card state is not set to up, skip
4955                  */
4956                 if (card->state != CARD_UP) {
4957                         if (card->adapters_activated)
4958                                 goto wait;
4959                         else
4960                                 goto end_thread;
4961                 }
4962                 /*
4963                  *    Check the results of our last ping.
4964                  */
4965                 dump_card = 0;
4966 #ifdef SLIC_FAILURE_DUMP
4967                 if (card->pingstatus != ISR_PINGMASK) {
4968                         DBG_MSG
4969                             ("\n[slicmon]  CARD #%d TIMED OUT - status "
4970                              "%x: DUMP THE CARD!\n",
4971                              card->cardnum, card->pingstatus);
4972                         dump_card = 1;
4973                 }
4974 #else
4975                 /*
4976                  *  Cause a card RESET instead?
4977                  */
4978                 if (card->pingstatus != ISR_PINGMASK) {
4979                         /* todo. do we want to reset the card in production */
4980                         /* DBG_MSG("\n[slicmon]  CARD #%d TIMED OUT - "
4981                            status %x: RESET THE CARD!\n", card->cardnum,
4982                            card->pingstatus); */
4983                         DBG_ERROR
4984                             ("\n[slicmon]  CARD #%d TIMED OUT - status %x: "
4985                              "DUMP THE CARD!\n",
4986                              card->cardnum, card->pingstatus);
4987                         dump_card = 1;
4988                 }
4989 #endif
4990                 if ((dump_card)
4991                     || (card->dump_requested == SLIC_DUMP_REQUESTED)) {
4992                         if (card->dump_requested == SLIC_DUMP_REQUESTED) {
4993                                 DBG_ERROR
4994                             ("[slicmon]: Dump card Requested: Card %x\n",
4995                                      card->cardnum);
4996                         }
4997                         if (card->pingstatus != ISR_PINGMASK) {
4998                                 ushort cpuid = 0;
4999                                 ushort crashpc = 0;
5000
5001                                 if (card->adapter[0]) {
5002                                         if ((card->adapter[0])->memorylength >=
5003                                             CRASH_INFO_OFFSET +
5004                                             sizeof(slic_crash_info)) {
5005                                                 char *crashptr;
5006                                                 p_slic_crash_info crashinfo;
5007
5008                                                 crashptr =
5009                                                     ((char *)card->adapter[0]->
5010                                                      slic_regs) +
5011                                                     CRASH_INFO_OFFSET;
5012                                                 crashinfo =
5013                                                     (p_slic_crash_info)
5014                                                     crashptr;
5015                                                 cpuid = crashinfo->cpu_id;
5016                                                 crashpc = crashinfo->crash_pc;
5017                                         }
5018                                 }
5019                                 DBG_ERROR
5020                                     ("[slicmon]: Dump card: Card %x crashed "
5021                                      "and failed to answer PING. "
5022                                      "CPUID[%x] PC[%x]\n ",
5023                                      card->cardnum, cpuid, crashpc);
5024                         }
5025
5026                         card->dump_requested = SLIC_DUMP_IN_PROGRESS;
5027
5028                         /*
5029                          * Set the card state to DOWN and the adapter states
5030                          * to RESET.They will check this in SimbaCheckForHang
5031                          * and initiate interface reset (which in turn will
5032                          * reinitialize the card).
5033                          */
5034                         card->state = CARD_DOWN;
5035
5036                         for (i = 0; i < card->card_size; i++) {
5037                                 adapter = card->adapter[i];
5038                                 if (adapter) {
5039                                         slic_if_stop_queue(adapter);
5040
5041                                         if (adapter->state == ADAPT_UP) {
5042                                                 adapter->state = ADAPT_RESET;
5043                                                 adapter->linkstate = LINK_DOWN;
5044                                                 DBG_ERROR
5045                                                     ("[slicmon]: SLIC Card[%d] "
5046                                                      "Port[%d] adapter[%p] "
5047                                                      "down\n",
5048                                                      (uint) card->cardnum,
5049                                                      (uint) i, adapter);
5050                                         }
5051 #if SLIC_GET_STATS_TIMER_ENABLED
5052                                         /* free stats timer */
5053                                         if (adapter->statstimerset) {
5054                                                 adapter->statstimerset = 0;
5055                                                 del_timer(&adapter->statstimer);
5056                                         }
5057 #endif
5058                                 }
5059                         }
5060
5061                         for (i = 0; i < card->card_size; i++) {
5062                                 adapter = card->adapter[i];
5063                                 if ((adapter) && (adapter->activated)) {
5064                                         pregs = adapter->slic_regs;
5065                                         dump_adapter = adapter;
5066
5067                                         /*
5068                                          * If the dump status is zero, then
5069                                          * the utility processor has crashed.
5070                                          * If this is the case, any pending
5071                                          * utilityprocessor requests will not
5072                                          * complete and our dump commands will
5073                                          * not be issued.
5074                                          *
5075                                          * To avoid this we will clear any
5076                                          * pending utility processor requests
5077                                          * now.
5078                                          */
5079                                         if (!card->pingstatus) {
5080                                                 spin_lock_irqsave(
5081                                                     &adapter->upr_lock.lock,
5082                                                     adapter->upr_lock.flags);
5083                                                 upr = adapter->upr_list;
5084                                                 while (upr) {
5085                                                         uprnext = upr->next;
5086                                                         kfree(upr);
5087                                                         upr = uprnext;
5088                                                 }
5089                                                 adapter->upr_list = 0;
5090                                                 adapter->upr_busy = 0;
5091                                                 spin_unlock_irqrestore(
5092                                                     &adapter->upr_lock.lock,
5093                                                     adapter->upr_lock.flags);
5094                                         }
5095
5096                                         slic_dump_card(card, false);
5097                                         dump_complete = 1;
5098                                 }
5099
5100                                 if (dump_complete) {
5101                                         DBG_ERROR("SLIC Dump Complete\n");
5102                                         /*  Only dump the card one time */
5103                                         break;
5104                                 }
5105                         }
5106
5107                         if (dump_adapter) {
5108                                 DBG_ERROR
5109                                     ("slic dump completed. "
5110                                      "Reenable interfaces\n");
5111                                 slic_card_init(card, dump_adapter);
5112
5113                                 /*
5114                                  *  Reenable the adapters that were reset
5115                                  */
5116                                 for (i = 0; i < card->card_size; i++) {
5117                                         adapter = card->adapter[i];
5118                                         if (adapter) {
5119                                                 if (adapter->state ==
5120                                                     ADAPT_RESET) {
5121                                                         DBG_ERROR
5122                                                             ("slicdump: SLIC "
5123                                            "Card[%d] Port[%d] adapter[%p] "
5124                                            "bring UP\n",
5125                                                              (uint) card->
5126                                                              cardnum, (uint) i,
5127                                                              adapter);
5128                                                         adapter->state =
5129                                                             ADAPT_DOWN;
5130                                                         adapter->linkstate =
5131                                                             LINK_DOWN;
5132                                                         slic_entry_open
5133                                                             (adapter->netdev);
5134                                                 }
5135                                         }
5136                                 }
5137
5138                                 card->dump_requested = SLIC_DUMP_DONE;
5139                         }
5140                 } else {
5141                 /* if pingstatus != ISR_PINGMASK) || dump_requested...ELSE
5142                  *    We received a valid ping response.
5143                  *    Clear the Pingstatus field, find a valid adapter
5144                  *    structure and send another ping.
5145                  */
5146                         for (i = 0; i < card->card_size; i++) {
5147                                 adapter = card->adapter[i];
5148                                 if (adapter && (adapter->state == ADAPT_UP)) {
5149                                         card->pingstatus = 0;
5150                                         slic_upr_request(adapter, SLIC_UPR_PING,
5151                                                          0, 0, 0, 0);
5152                                         break;  /* Only issue one per card */
5153                                 }
5154                         }
5155                 }
5156 wait:
5157                 SLIC_INTERRUPTIBLE_SLEEP_ON_TIMEOUT(card->dump_wq, delay);
5158         } while (!signal_pending(current));
5159
5160 end_thread:
5161 /*  DBG_MSG("[slicmon] slic_dump_thread card[%p] pid[%x] ENDING\n",
5162     card, card->dump_pid); */
5163         card->dumpthread_running = 0;
5164
5165         return 0;
5166 }
5167
5168 /*
5169  * Read a single byte from our dump index file.  This
5170  * value is used as our suffix for our dump path.  The
5171  * value is incremented and written back to the file
5172  */
5173 static unsigned char slic_get_dump_index(char *path)
5174 {
5175         unsigned char index = 0;
5176 #ifdef SLIC_DUMP_INDEX_SUPPORT
5177         u32 status;
5178         void *FileHandle;
5179         u32 offset;
5180
5181         offset = 0;
5182
5183         /*
5184          * Open the index file.  If one doesn't exist, create it
5185          */
5186         status = create_file(&FileHandle);
5187
5188         if (status != STATUS_SUCCESS)
5189                 return (unsigned char) 0;
5190
5191         status = read_file(FileHandle, &index, 1, &offset);
5192
5193         index++;
5194
5195         status = write_file(FileHandle, &index, 1, &offset);
5196
5197         close_file(FileHandle);
5198 #else
5199         index = 0;
5200 #endif
5201         return index;
5202 }
5203
5204 static struct file *slic_dump_open_file(struct sliccard *card)
5205 {
5206         struct file *SLIChandle = NULL;
5207         struct dentry *dentry = NULL;
5208         struct inode *inode = NULL;
5209         char SLICfile[50];
5210
5211         card->dumpfile_fs = get_fs();
5212
5213         set_fs(KERNEL_DS);
5214
5215         memset(SLICfile, 0, sizeof(SLICfile));
5216         sprintf(SLICfile, "/var/tmp/slic%d-dump-%d", card->cardnum,
5217                 (uint) card->dump_count);
5218         card->dump_count++;
5219
5220         SLIChandle =
5221             filp_open(SLICfile, O_CREAT | O_RDWR | O_SYNC | O_LARGEFILE, 0666);
5222
5223         DBG_MSG("[slicmon]: Dump Card #%d to file: %s \n", card->cardnum,
5224                 SLICfile);
5225
5226 /*  DBG_MSG("[slicmon] filp_open %s SLIChandle[%p]\n", SLICfile, SLIChandle);*/
5227
5228         if (IS_ERR(SLIChandle))
5229                 goto end_slicdump;
5230
5231         dentry = SLIChandle->f_dentry;
5232         inode = dentry->d_inode;
5233
5234 /*  DBG_MSG("[slicmon] inode[%p] i_nlink[%x] i_mode[%x] i_op[%p] i_fop[%p]\n"
5235                 "f_op->write[%p]\n",
5236                 inode, inode->i_nlink, inode->i_mode, inode->i_op,
5237                 inode->i_fop, SLIChandle->f_op->write); */
5238         if (inode->i_nlink > 1)
5239                 goto close_slicdump;    /* multiple links - don't dump */
5240 #ifdef HISTORICAL
5241         if (!S_ISREG(inode->i_mode))
5242                 goto close_slicdump;
5243 #endif
5244         if (!inode->i_op || !inode->i_fop)
5245                 goto close_slicdump;
5246
5247         if (!SLIChandle->f_op->write)
5248                 goto close_slicdump;
5249
5250         /*
5251          *  If we got here we have SUCCESSFULLY OPENED the dump file
5252          */
5253 /*  DBG_MSG("opened %s SLIChandle[%p]\n", SLICfile, SLIChandle); */
5254         return SLIChandle;
5255
5256 close_slicdump:
5257         DBG_MSG("[slicmon] slic_dump_open_file failed close SLIChandle[%p]\n",
5258                 SLIChandle);
5259         filp_close(SLIChandle, NULL);
5260
5261 end_slicdump:
5262         set_fs(card->dumpfile_fs);
5263
5264         return NULL;
5265 }
5266
5267 static void slic_dump_close_file(struct sliccard *card)
5268 {
5269
5270 /*  DBG_MSG("[slicmon] slic_dump_CLOSE_file close SLIChandle[%p]\n",
5271    card->dumphandle); */
5272
5273         filp_close(card->dumphandle, NULL);
5274
5275         set_fs(card->dumpfile_fs);
5276 }
5277
5278 static u32 slic_dump_card(struct sliccard *card, bool resume)
5279 {
5280         struct adapter *adapter = card->master;
5281         u32 status;
5282         u32 queue;
5283         u32 len, offset;
5284         u32 sram_size, dram_size, regs;
5285         struct sliccore_hdr corehdr;
5286         u32 file_offset;
5287         char *namestr;
5288         u32 i;
5289         u32 max_queues = 0;
5290         u32 result;
5291
5292         card->dumphandle = slic_dump_open_file(card);
5293
5294         if (card->dumphandle == NULL) {
5295                 DBG_MSG("[slicmon] Cant create Dump file - dump failed\n");
5296                 return -ENOMEM;
5297         }
5298         if (!card->dumpbuffer) {
5299                 DBG_MSG("[slicmon] Insufficient memory for dump\n");
5300                 return -ENOMEM;
5301         }
5302         if (!card->cmdbuffer) {
5303                 DBG_MSG("[slicmon] Insufficient cmd memory for dump\n");
5304                 return -ENOMEM;
5305         }
5306
5307         /*
5308          * Write the file version to the core header.
5309          */
5310         namestr = slic_proc_version;
5311         for (i = 0; i < (DRIVER_NAME_SIZE - 1); i++, namestr++) {
5312                 if (!namestr)
5313                         break;
5314                 corehdr.driver_version[i] = *namestr;
5315         }
5316         corehdr.driver_version[i] = 0;
5317
5318         file_offset = sizeof(struct sliccore_hdr);
5319
5320         /*
5321          * Issue the following debug commands to the SLIC:
5322          *        - Halt both receive and transmit
5323          *        - Dump receive registers
5324          *        - Dump transmit registers
5325          *        - Dump sram
5326          *        - Dump dram
5327          *        - Dump queues
5328          */
5329         DBG_MSG("slicDump HALT Receive Processor\n");
5330         card->dumptime_start = jiffies;
5331
5332         status = slic_dump_halt(card, PROC_RECEIVE);
5333         if (status != STATUS_SUCCESS) {
5334                 DBG_ERROR
5335                     ("Cant halt receive sequencer - dump failed status[%x]\n",
5336                      status);
5337                 goto done;
5338         }
5339
5340         DBG_MSG("slicDump HALT Transmit Processor\n");
5341         status = slic_dump_halt(card, PROC_TRANSMIT);
5342         if (status != STATUS_SUCCESS) {
5343                 DBG_ERROR("Cant halt transmit sequencer - dump failed\n");
5344                 goto done;
5345         }
5346
5347         /* Dump receive regs */
5348         status = slic_dump_reg(card, PROC_RECEIVE);
5349         if (status != STATUS_SUCCESS) {
5350                 DBG_ERROR("Cant dump receive registers - dump failed\n");
5351                 goto done;
5352         }
5353
5354         DBG_MSG("slicDump Write Receive REGS len[%x] offset[%x]\n",
5355                 (SLIC_NUM_REG * 4), file_offset);
5356
5357         result =
5358             slic_dump_write(card, card->dumpbuffer, SLIC_NUM_REG * 4,
5359                             file_offset);
5360         if (!result) {
5361                 DBG_ERROR
5362                     ("Cant write rcv registers to dump file - dump failed\n");
5363                 goto done;
5364         }
5365
5366         corehdr.RcvRegOff = file_offset;
5367         corehdr.RcvRegsize = SLIC_NUM_REG * 4;
5368         file_offset += SLIC_NUM_REG * 4;
5369
5370         /* Dump transmit regs */
5371         status = slic_dump_reg(card, PROC_TRANSMIT);
5372         if (status != STATUS_SUCCESS) {
5373                 DBG_ERROR("Cant dump transmit registers - dump failed\n");
5374                 goto done;
5375         }
5376
5377         DBG_MSG("slicDump Write XMIT REGS len[%x] offset[%x]\n",
5378                 (SLIC_NUM_REG * 4), file_offset);
5379
5380         result =
5381             slic_dump_write(card, card->dumpbuffer, SLIC_NUM_REG * 4,
5382                             file_offset);
5383         if (!result) {
5384                 DBG_ERROR
5385                     ("Cant write xmt registers to dump file - dump failed\n");
5386                 goto done;
5387         }
5388
5389         corehdr.XmtRegOff = file_offset;
5390         corehdr.XmtRegsize = SLIC_NUM_REG * 4;
5391         file_offset += SLIC_NUM_REG * 4;
5392
5393         regs = SLIC_GBMAX_REG;
5394
5395         corehdr.FileRegOff = file_offset;
5396         corehdr.FileRegsize = regs * 4;
5397
5398         for (offset = 0; regs;) {
5399                 len = MIN(regs, 16);    /* Can only xfr 16 regs at a time */
5400
5401                 status = slic_dump_data(card, offset, (ushort) len, DESC_RFILE);
5402
5403                 if (status != STATUS_SUCCESS) {
5404                         DBG_ERROR("Cant dump register file - dump failed\n");
5405                         goto done;
5406                 }
5407
5408                 DBG_MSG("slicDump Write RegisterFile len[%x] offset[%x]\n",
5409                         (len * 4), file_offset);
5410
5411                 result =
5412                     slic_dump_write(card, card->dumpbuffer, len * 4,
5413                                     file_offset);
5414                 if (!result) {
5415                         DBG_ERROR
5416                             ("Cant write register file to dump file - "
5417                              "dump failed\n");
5418                         goto done;
5419                 }
5420
5421                 file_offset += len * 4;
5422                 offset += len;
5423                 regs -= len;
5424         }
5425
5426         dram_size = card->config.DramSize * 0x10000;
5427
5428         switch (adapter->devid) {
5429         case SLIC_2GB_DEVICE_ID:
5430                 sram_size = SLIC_SRAM_SIZE2GB;
5431                 break;
5432         case SLIC_1GB_DEVICE_ID:
5433                 sram_size = SLIC_SRAM_SIZE1GB;
5434                 break;
5435         default:
5436                 sram_size = 0;
5437                 ASSERT(0);
5438                 break;
5439         }
5440
5441         corehdr.SramOff = file_offset;
5442         corehdr.Sramsize = sram_size;
5443
5444         for (offset = 0; sram_size;) {
5445                 len = MIN(sram_size, DUMP_BUF_SIZE);
5446                 status = slic_dump_data(card, offset, (ushort) len, DESC_SRAM);
5447                 if (status != STATUS_SUCCESS) {
5448                         DBG_ERROR
5449                             ("[slicmon] Cant dump SRAM at offset %x - "
5450                              "dump failed\n", (uint) offset);
5451                         goto done;
5452                 }
5453
5454                 DBG_MSG("[slicmon] slicDump Write SRAM  len[%x] offset[%x]\n",
5455                         len, file_offset);
5456
5457                 result =
5458                     slic_dump_write(card, card->dumpbuffer, len, file_offset);
5459                 if (!result) {
5460                         DBG_ERROR
5461                             ("[slicmon] Cant write SRAM to dump file - "
5462                              "dump failed\n");
5463                         goto done;
5464                 }
5465
5466                 file_offset += len;
5467                 offset += len;
5468                 sram_size -= len;
5469         }
5470
5471         corehdr.DramOff = file_offset;
5472         corehdr.Dramsize = dram_size;
5473
5474         for (offset = 0; dram_size;) {
5475                 len = MIN(dram_size, DUMP_BUF_SIZE);
5476
5477                 status = slic_dump_data(card, offset, (ushort) len, DESC_DRAM);
5478                 if (status != STATUS_SUCCESS) {
5479                         DBG_ERROR
5480                             ("[slicmon] Cant dump dram at offset %x - "
5481                              "dump failed\n", (uint) offset);
5482                         goto done;
5483                 }
5484
5485                 DBG_MSG("slicDump Write DRAM  len[%x] offset[%x]\n", len,
5486                         file_offset);
5487
5488                 result =
5489                     slic_dump_write(card, card->dumpbuffer, len, file_offset);
5490                 if (!result) {
5491                         DBG_ERROR
5492                             ("[slicmon] Cant write DRAM to dump file - "
5493                              "dump failed\n");
5494                         goto done;
5495                 }
5496
5497                 file_offset += len;
5498                 offset += len;
5499                 dram_size -= len;
5500         }
5501
5502         max_queues = SLIC_MAX_QUEUE;
5503
5504         for (queue = 0; queue < max_queues; queue++) {
5505                 u32 *qarray = (u32 *) card->dumpbuffer;
5506                 u32 qarray_physl = card->dumpbuffer_physl;
5507                 u32 qarray_physh = card->dumpbuffer_physh;
5508                 u32 qstart;
5509                 u32 qdelta;
5510                 u32 qtotal = 0;
5511
5512                 DBG_MSG("[slicmon] Start Dump of QUEUE #0x%x\n", (uint) queue);
5513
5514                 for (offset = 0; offset < (DUMP_BUF_SIZE >> 2); offset++) {
5515                         qstart = jiffies;
5516                         qdelta = 0;
5517
5518                         status = slic_dump_queue(card,
5519                                                  qarray_physl,
5520                                                  qarray_physh, queue);
5521                         qarray_physl += 4;
5522
5523                         if (status != STATUS_SUCCESS)
5524                                 break;
5525
5526                         if (jiffies > qstart) {
5527                                 qdelta = jiffies - qstart;
5528                                 qtotal += qdelta;
5529                         }
5530                 }
5531
5532                 if (offset)
5533                         qdelta = qtotal / offset;
5534                 else
5535                         qdelta = 0;
5536
5537 /*        DBG_MSG("   slicDump Write QUEUE #0x%x len[%x] offset[%x] "
5538                 "avgjiffs[%x]\n", queue, (offset*4), file_offset, qdelta); */
5539
5540                 result =
5541                     slic_dump_write(card, card->dumpbuffer, offset * 4,
5542                                     file_offset);
5543
5544                 if (!result) {
5545                         DBG_ERROR
5546                             ("[slicmon] Cant write QUEUES to dump file - "
5547                              "dump failed\n");
5548                         goto done;
5549                 }
5550
5551                 corehdr.queues[queue].queueOff = file_offset;
5552                 corehdr.queues[queue].queuesize = offset * 4;
5553                 file_offset += offset * 4;
5554
5555 /*      DBG_MSG("    Reload QUEUE #0x%x elements[%x]\n", (uint)queue, offset);*/
5556                 /*
5557                  * Fill the queue back up
5558                  */
5559                 for (i = 0; i < offset; i++) {
5560                         qstart = jiffies;
5561                         qdelta = 0;
5562
5563                         status = slic_dump_load_queue(card, qarray[i], queue);
5564                         if (status != STATUS_SUCCESS)
5565                                 break;
5566
5567                         if (jiffies > qstart) {
5568                                 qdelta = jiffies - qstart;
5569                                 qtotal += qdelta;
5570                         }
5571                 }
5572
5573                 if (offset)
5574                         qdelta = qtotal / offset;
5575                 else
5576                         qdelta = 0;
5577
5578 /*      DBG_MSG("   Reload DONE avgjiffs[%x]\n", qdelta); */
5579
5580                 resume = 1;
5581         }
5582
5583         len = SLIC_GB_CAMAB_SZE * 4;
5584         status = slic_dump_cam(card, 0, len, DUMP_CAM_A);
5585         if (status != STATUS_SUCCESS) {
5586                 DBG_ERROR("[slicmon] Can't dump CAM_A - dump failed\n");
5587                 goto done;
5588         }
5589
5590         result = slic_dump_write(card, card->dumpbuffer, len, file_offset);
5591         if (result) {
5592                 DBG_ERROR
5593                     ("[slicmon] Can't write CAM_A data to dump file - "
5594                      "dump failed\n");
5595                 goto done;
5596         }
5597         corehdr.CamAMOff = file_offset;
5598         corehdr.CamASize = len;
5599         file_offset += len;
5600
5601         len = SLIC_GB_CAMCD_SZE * 4;
5602         status = slic_dump_cam(card, 0, len, DUMP_CAM_C);
5603         if (status) {
5604                 DBG_ERROR("[slicmon] Can't dump CAM_C - dump failed\n");
5605                 goto done;
5606         }
5607
5608         result = slic_dump_write(card, card->dumpbuffer, len, file_offset);
5609         if (result) {
5610                 DBG_ERROR
5611                     ("[slicmon] Can't write CAM_C data to dump file - "
5612                      "dump failed\n");
5613                 goto done;
5614         }
5615         corehdr.CamCMOff = file_offset;
5616         corehdr.CamCSize = len;
5617         file_offset += len;
5618
5619 done:
5620         /*
5621          * Write out the core header
5622          */
5623         file_offset = 0;
5624         DBG_MSG("[slicmon] Write CoreHeader len[%x] offset[%x]\n",
5625                 (uint) sizeof(struct sliccore_hdr), file_offset);
5626
5627         result =
5628             slic_dump_write(card, &corehdr, sizeof(struct sliccore_hdr),
5629                             file_offset);
5630         DBG_MSG("[slicmon] corehdr  xoff[%x] xsz[%x]\n"
5631                 "    roff[%x] rsz[%x] fileoff[%x] filesz[%x]\n"
5632                 "    sramoff[%x] sramsz[%x], dramoff[%x] dramsz[%x]\n"
5633                 "    corehdr_offset[%x]\n", corehdr.XmtRegOff,
5634                 corehdr.XmtRegsize, corehdr.RcvRegOff, corehdr.RcvRegsize,
5635                 corehdr.FileRegOff, corehdr.FileRegsize, corehdr.SramOff,
5636                 corehdr.Sramsize, corehdr.DramOff, corehdr.Dramsize,
5637                 (uint) sizeof(struct sliccore_hdr));
5638         for (i = 0; i < max_queues; i++) {
5639                 DBG_MSG("[slicmon]  QUEUE 0x%x  offset[%x] size[%x]\n",
5640                         (uint) i, corehdr.queues[i].queueOff,
5641                         corehdr.queues[i].queuesize);
5642
5643         }
5644
5645         slic_dump_close_file(card);
5646
5647         if (resume) {
5648                 DBG_MSG("slicDump RESTART RECEIVE and XMIT PROCESSORS\n\n");
5649                 slic_dump_resume(card, PROC_RECEIVE);
5650                 slic_dump_resume(card, PROC_TRANSMIT);
5651         }
5652
5653         return status;
5654 }
5655
5656 static u32 slic_dump_halt(struct sliccard *card, unsigned char proc)
5657 {
5658         unsigned char *cmd = card->cmdbuffer;
5659
5660         *cmd = COMMAND_BYTE(CMD_HALT, 0, proc);
5661
5662         return slic_dump_send_cmd(card,
5663                                    card->cmdbuffer_physl,
5664                                    card->cmdbuffer_physh, 0, 0);
5665 }
5666
5667 static u32 slic_dump_resume(struct sliccard *card, unsigned char proc)
5668 {
5669         unsigned char *cmd = card->cmdbuffer;
5670
5671         *cmd = COMMAND_BYTE(CMD_RUN, 0, proc);
5672
5673         return slic_dump_send_cmd(card,
5674                                    card->cmdbuffer_physl,
5675                                    card->cmdbuffer_physh, 0, 0);
5676 }
5677
5678 static u32 slic_dump_reg(struct sliccard *card, unsigned char proc)
5679 {
5680         struct dump_cmd *dump = (struct dump_cmd *)card->cmdbuffer;
5681
5682         dump->cmd = COMMAND_BYTE(CMD_DUMP, 0, proc);
5683         dump->desc = DESC_REG;
5684         dump->count = 0;
5685         dump->addr = 0;
5686
5687         return slic_dump_send_cmd(card,
5688                                    card->cmdbuffer_physl,
5689                                    card->cmdbuffer_physh,
5690                                    card->dumpbuffer_physl,
5691                                    card->dumpbuffer_physh);
5692 }
5693
5694 static u32 slic_dump_data(struct sliccard *card,
5695                        u32 addr, ushort count, unsigned char desc)
5696 {
5697         struct dump_cmd *dump = (struct dump_cmd *)card->cmdbuffer;
5698
5699         dump->cmd = COMMAND_BYTE(CMD_DUMP, 0, PROC_RECEIVE);
5700         dump->desc = desc;
5701         dump->count = count;
5702         dump->addr = addr;
5703
5704         return slic_dump_send_cmd(card,
5705                                    card->cmdbuffer_physl,
5706                                    card->cmdbuffer_physh,
5707                                    card->dumpbuffer_physl,
5708                                    card->dumpbuffer_physh);
5709 }
5710
5711 static u32 slic_dump_queue(struct sliccard *card,
5712                         u32 addr, u32 buf_physh, u32 queue)
5713 {
5714         struct dump_cmd *dump = (struct dump_cmd *)card->cmdbuffer;
5715
5716         dump->cmd = COMMAND_BYTE(CMD_DUMP, 0, PROC_RECEIVE);
5717         dump->desc = DESC_QUEUE;
5718         dump->count = 1;
5719         dump->addr = queue;
5720
5721         return slic_dump_send_cmd(card,
5722                                    card->cmdbuffer_physl,
5723                                    card->cmdbuffer_physh,
5724                                    addr, card->dumpbuffer_physh);
5725 }
5726
5727 static u32 slic_dump_load_queue(struct sliccard *card, u32 data,
5728                                 u32 queue)
5729 {
5730         struct dump_cmd *load = (struct dump_cmd *) card->cmdbuffer;
5731
5732         load->cmd = COMMAND_BYTE(CMD_LOAD, 0, PROC_RECEIVE);
5733         load->desc = DESC_QUEUE;
5734         load->count = (ushort) queue;
5735         load->addr = data;
5736
5737         return slic_dump_send_cmd(card,
5738                                    card->cmdbuffer_physl,
5739                                    card->cmdbuffer_physh, 0, 0);
5740 }
5741
5742 static u32 slic_dump_cam(struct sliccard *card,
5743                       u32 addr, u32 count, unsigned char desc)
5744 {
5745         struct dump_cmd *dump = (struct dump_cmd *)card->cmdbuffer;
5746
5747         dump->cmd = COMMAND_BYTE(CMD_CAM_OPS, 0, PROC_NONE);
5748         dump->desc = desc;
5749         dump->count = count;
5750         dump->addr = 0;
5751
5752         return slic_dump_send_cmd(card,
5753                                    card->cmdbuffer_physl,
5754                                    card->cmdbuffer_physh,
5755                                    addr, card->dumpbuffer_physh);
5756 }
5757
5758 static u32 slic_dump_send_cmd(struct sliccard *card,
5759                            u32 cmd_physl,
5760                            u32 cmd_physh,
5761                            u32 buf_physl, u32 buf_physh)
5762 {
5763         ulong timeout = msecs_to_jiffies(500);  /* 500 msec */
5764         u32 attempts = 5;
5765         u32 delay = msecs_to_jiffies(10);       /* 10 msec */
5766         struct adapter *adapter = card->master;
5767
5768         ASSERT(adapter);
5769         do {
5770                 /*
5771                  * Zero the Dumpstatus field of the adapter structure
5772                  */
5773                 card->dumpstatus = 0;
5774                 /*
5775                  * Issue the dump command via a utility processor request.
5776                  *
5777                  * Kludge: We use the Informationbuffer parameter to hold
5778                  * the buffer address
5779                  */
5780                 slic_upr_request(adapter, SLIC_UPR_DUMP, cmd_physl, cmd_physh,
5781                                  buf_physl, buf_physh);
5782
5783                 timeout += jiffies;
5784                 /*
5785                  * Spin until completion or timeout.
5786                  */
5787                 while (!card->dumpstatus) {
5788                         int num_sleeps = 0;
5789
5790                         if (jiffies > timeout) {
5791                                 /*
5792                                  *  Complete the timed-out DUMP UPR request.
5793                                  */
5794                                 slic_upr_request_complete(adapter, 0);
5795                                 DBG_ERROR
5796                                     ("%s: TIMED OUT num_sleeps[%x] "
5797                                      "status[%x]\n",
5798                                      __func__, num_sleeps, STATUS_FAILURE);
5799
5800                                 return STATUS_FAILURE;
5801                         }
5802                         num_sleeps++;
5803                         SLIC_INTERRUPTIBLE_SLEEP_ON_TIMEOUT(card->dump_wq,
5804                                                             delay);
5805                 }
5806
5807                 if (card->dumpstatus & ISR_UPCERR) {
5808                         /*
5809                          * Error (or queue empty)
5810                          */
5811 /*          DBG_ERROR("[slicmon] %s: DUMP_STATUS & ISR_UPCERR status[%x]\n",
5812                 __func__, STATUS_FAILURE); */
5813
5814                         return STATUS_FAILURE;
5815                 } else if (card->dumpstatus & ISR_UPCBSY) {
5816                         /*
5817                          * Retry
5818                          */
5819                         DBG_ERROR("%s: ISR_UPCBUSY attempt[%x]\n", __func__,
5820                                   attempts);
5821
5822                         attempts--;
5823                 } else {
5824                         /*
5825                          * success
5826                          */
5827                         return STATUS_SUCCESS;
5828                 }
5829
5830         } while (attempts);
5831
5832         DBG_ERROR("%s: GAVE UP AFTER SEVERAL ATTEMPTS status[%x]\n",
5833                   __func__, STATUS_FAILURE);
5834
5835         /*
5836          * Gave up after several attempts
5837          */
5838         return STATUS_FAILURE;
5839 }
5840
5841 #endif
5842 /*=============================================================================
5843   =============================================================================
5844   ===                                                                       ===
5845   ===      *** END **** END **** END **** END ***                           ===
5846   ===       SLIC  DUMP  MANAGEMENT        SECTION                           ===
5847   ===                                                                       ===
5848   ===                                                                       ===
5849   ===                                                                       ===
5850   =============================================================================
5851   ============================================================================*/
5852
5853 /******************************************************************************/
5854 /****************   MODULE INITIATION / TERMINATION FUNCTIONS   ***************/
5855 /******************************************************************************/
5856
5857 static struct pci_driver slic_driver = {
5858         .name = DRV_NAME,
5859         .id_table = slic_pci_tbl,
5860         .probe = slic_entry_probe,
5861         .remove = slic_entry_remove,
5862 #if SLIC_POWER_MANAGEMENT_ENABLED
5863         .suspend = slicpm_suspend,
5864         .resume = slicpm_resume,
5865 #endif
5866 /*    .shutdown   =     slic_shutdown,  MOOK_INVESTIGATE */
5867 };
5868
5869 static int __init slic_module_init(void)
5870 {
5871         struct pci_device_id *pcidev;
5872         int ret;
5873
5874 /*      DBG_MSG("slicoss: %s ENTER cpu %d\n", __func__, smp_processor_id()); */
5875
5876         slic_init_driver();
5877
5878         if (debug >= 0 && slic_debug != debug)
5879                 printk(SLICLEVEL "slicoss: debug level is %d.\n", debug);
5880         if (debug >= 0)
5881                 slic_debug = debug;
5882
5883         pcidev = (struct pci_device_id *)slic_driver.id_table;
5884 /*      DBG_MSG("slicoss: %s call pci_module_init jiffies[%lx] cpu #%d\n",
5885         __func__, jiffies, smp_processor_id()); */
5886
5887         ret = pci_register_driver(&slic_driver);
5888
5889 /*  DBG_MSG("slicoss: %s EXIT after call pci_module_init jiffies[%lx] "
5890             "cpu #%d status[%x]\n",__func__, jiffies,
5891             smp_processor_id(), ret); */
5892
5893         return ret;
5894 }
5895
5896 static void __exit slic_module_cleanup(void)
5897 {
5898 /*      DBG_MSG("slicoss: %s ENTER\n", __func__); */
5899         pci_unregister_driver(&slic_driver);
5900         slic_debug_cleanup();
5901 /*      DBG_MSG("slicoss: %s EXIT\n", __func__); */
5902 }
5903
5904 module_init(slic_module_init);
5905 module_exit(slic_module_cleanup);