Version:  2.0.40 2.2.26 2.4.37 3.1 3.2 3.3 3.4 3.5 3.6 3.7 3.8 3.9 3.10 3.11 3.12 3.13 3.14 3.15 3.16 3.17

Linux/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 actually 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 KLUDGE_FOR_4GB_BOUNDARY         1
 59 #define DEBUG_MICROCODE                 1
 60 #define DBG                             1
 61 #define SLIC_INTERRUPT_PROCESS_LIMIT    1
 62 #define SLIC_OFFLOAD_IP_CHECKSUM                1
 63 #define STATS_TIMER_INTERVAL                    2
 64 #define PING_TIMER_INTERVAL                         1
 65 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
 66 
 67 #include <linux/kernel.h>
 68 #include <linux/string.h>
 69 #include <linux/errno.h>
 70 #include <linux/ioport.h>
 71 #include <linux/slab.h>
 72 #include <linux/interrupt.h>
 73 #include <linux/timer.h>
 74 #include <linux/pci.h>
 75 #include <linux/spinlock.h>
 76 #include <linux/init.h>
 77 #include <linux/bitops.h>
 78 #include <linux/io.h>
 79 #include <linux/netdevice.h>
 80 #include <linux/crc32.h>
 81 #include <linux/etherdevice.h>
 82 #include <linux/skbuff.h>
 83 #include <linux/delay.h>
 84 #include <linux/seq_file.h>
 85 #include <linux/kthread.h>
 86 #include <linux/module.h>
 87 #include <linux/moduleparam.h>
 88 
 89 #include <linux/firmware.h>
 90 #include <linux/types.h>
 91 #include <linux/dma-mapping.h>
 92 #include <linux/mii.h>
 93 #include <linux/if_vlan.h>
 94 #include <asm/unaligned.h>
 95 
 96 #include <linux/ethtool.h>
 97 #include <linux/uaccess.h>
 98 #include "slichw.h"
 99 #include "slic.h"
100 
101 static uint slic_first_init = 1;
102 static char *slic_banner = "Alacritech SLIC Technology(tm) Server "
103                 "and Storage Accelerator (Non-Accelerated)";
104 
105 static char *slic_proc_version = "2.0.351  2006/07/14 12:26:00";
106 
107 static struct base_driver slic_global = { {}, 0, 0, 0, 1, NULL, NULL };
108 static int intagg_delay = 100;
109 static u32 dynamic_intagg;
110 static unsigned int rcv_count;
111 
112 #define DRV_NAME          "slicoss"
113 #define DRV_VERSION       "2.0.1"
114 #define DRV_AUTHOR        "Alacritech, Inc. Engineering"
115 #define DRV_DESCRIPTION   "Alacritech SLIC Techonology(tm) "\
116                 "Non-Accelerated Driver"
117 #define DRV_COPYRIGHT     "Copyright  2000-2006 Alacritech, Inc. "\
118                 "All rights reserved."
119 #define PFX                DRV_NAME " "
120 
121 MODULE_AUTHOR(DRV_AUTHOR);
122 MODULE_DESCRIPTION(DRV_DESCRIPTION);
123 MODULE_LICENSE("Dual BSD/GPL");
124 
125 module_param(dynamic_intagg, int, 0);
126 MODULE_PARM_DESC(dynamic_intagg, "Dynamic Interrupt Aggregation Setting");
127 module_param(intagg_delay, int, 0);
128 MODULE_PARM_DESC(intagg_delay, "uSec Interrupt Aggregation Delay");
129 
130 static const struct pci_device_id slic_pci_tbl[] = {
131         { PCI_DEVICE(PCI_VENDOR_ID_ALACRITECH, SLIC_1GB_DEVICE_ID) },
132         { PCI_DEVICE(PCI_VENDOR_ID_ALACRITECH, SLIC_2GB_DEVICE_ID) },
133         { 0 }
134 };
135 
136 MODULE_DEVICE_TABLE(pci, slic_pci_tbl);
137 
138 static inline void slic_reg32_write(void __iomem *reg, u32 value, bool flush)
139 {
140         writel(value, reg);
141         if (flush)
142                 mb();
143 }
144 
145 static inline void slic_reg64_write(struct adapter *adapter, void __iomem *reg,
146                                     u32 value, void __iomem *regh, u32 paddrh,
147                                     bool flush)
148 {
149         spin_lock_irqsave(&adapter->bit64reglock.lock,
150                                 adapter->bit64reglock.flags);
151         if (paddrh != adapter->curaddrupper) {
152                 adapter->curaddrupper = paddrh;
153                 writel(paddrh, regh);
154         }
155         writel(value, reg);
156         if (flush)
157                 mb();
158         spin_unlock_irqrestore(&adapter->bit64reglock.lock,
159                                 adapter->bit64reglock.flags);
160 }
161 
162 static void slic_mcast_set_bit(struct adapter *adapter, char *address)
163 {
164         unsigned char crcpoly;
165 
166         /* Get the CRC polynomial for the mac address */
167         /* we use bits 1-8 (lsb), bitwise reversed,
168          * msb (= lsb bit 0 before bitrev) is automatically discarded */
169         crcpoly = (ether_crc(ETH_ALEN, address)>>23);
170 
171         /* We only have space on the SLIC for 64 entries.  Lop
172          * off the top two bits. (2^6 = 64)
173          */
174         crcpoly &= 0x3F;
175 
176         /* OR in the new bit into our 64 bit mask. */
177         adapter->mcastmask |= (u64) 1 << crcpoly;
178 }
179 
180 static void slic_mcast_set_mask(struct adapter *adapter)
181 {
182         __iomem struct slic_regs *slic_regs = adapter->slic_regs;
183 
184         if (adapter->macopts & (MAC_ALLMCAST | MAC_PROMISC)) {
185                 /* Turn on all multicast addresses. We have to do this for
186                  * promiscuous mode as well as ALLMCAST mode.  It saves the
187                  * Microcode from having to keep state about the MAC
188                  * configuration.
189                  */
190                 slic_reg32_write(&slic_regs->slic_mcastlow, 0xFFFFFFFF, FLUSH);
191                 slic_reg32_write(&slic_regs->slic_mcasthigh, 0xFFFFFFFF,
192                                  FLUSH);
193         } else {
194                 /* Commit our multicast mast to the SLIC by writing to the
195                  * multicast address mask registers
196                  */
197                 slic_reg32_write(&slic_regs->slic_mcastlow,
198                         (u32)(adapter->mcastmask & 0xFFFFFFFF), FLUSH);
199                 slic_reg32_write(&slic_regs->slic_mcasthigh,
200                         (u32)((adapter->mcastmask >> 32) & 0xFFFFFFFF), FLUSH);
201         }
202 }
203 
204 static void slic_timer_ping(ulong dev)
205 {
206         struct adapter *adapter;
207         struct sliccard *card;
208 
209         adapter = netdev_priv((struct net_device *)dev);
210         card = adapter->card;
211 
212         adapter->pingtimer.expires = jiffies + (PING_TIMER_INTERVAL * HZ);
213         add_timer(&adapter->pingtimer);
214 }
215 
216 static void slic_unmap_mmio_space(struct adapter *adapter)
217 {
218         if (adapter->slic_regs)
219                 iounmap(adapter->slic_regs);
220         adapter->slic_regs = NULL;
221 }
222 
223 /*
224  *  slic_link_config
225  *
226  *  Write phy control to configure link duplex/speed
227  *
228  */
229 static void slic_link_config(struct adapter *adapter,
230                       u32 linkspeed, u32 linkduplex)
231 {
232         u32 __iomem *wphy;
233         u32 speed;
234         u32 duplex;
235         u32 phy_config;
236         u32 phy_advreg;
237         u32 phy_gctlreg;
238 
239         if (adapter->state != ADAPT_UP)
240                 return;
241 
242         if (linkspeed > LINK_1000MB)
243                 linkspeed = LINK_AUTOSPEED;
244         if (linkduplex > LINK_AUTOD)
245                 linkduplex = LINK_AUTOD;
246 
247         wphy = &adapter->slic_regs->slic_wphy;
248 
249         if ((linkspeed == LINK_AUTOSPEED) || (linkspeed == LINK_1000MB)) {
250                 if (adapter->flags & ADAPT_FLAGS_FIBERMEDIA) {
251                         /*  We've got a fiber gigabit interface, and register
252                          *  4 is different in fiber mode than in copper mode
253                          */
254 
255                         /* advertise FD only @1000 Mb */
256                         phy_advreg = (MIICR_REG_4 | (PAR_ADV1000XFD));
257                         /* enable PAUSE frames        */
258                         phy_advreg |= PAR_ASYMPAUSE_FIBER;
259                         slic_reg32_write(wphy, phy_advreg, FLUSH);
260 
261                         if (linkspeed == LINK_AUTOSPEED) {
262                                 /* reset phy, enable auto-neg  */
263                                 phy_config =
264                                     (MIICR_REG_PCR |
265                                      (PCR_RESET | PCR_AUTONEG |
266                                       PCR_AUTONEG_RST));
267                                 slic_reg32_write(wphy, phy_config, FLUSH);
268                         } else {        /* forced 1000 Mb FD*/
269                                 /* power down phy to break link
270                                    this may not work) */
271                                 phy_config = (MIICR_REG_PCR | PCR_POWERDOWN);
272                                 slic_reg32_write(wphy, phy_config, FLUSH);
273                                 /* wait, Marvell says 1 sec,
274                                    try to get away with 10 ms  */
275                                 mdelay(10);
276 
277                                 /* disable auto-neg, set speed/duplex,
278                                    soft reset phy, powerup */
279                                 phy_config =
280                                     (MIICR_REG_PCR |
281                                      (PCR_RESET | PCR_SPEED_1000 |
282                                       PCR_DUPLEX_FULL));
283                                 slic_reg32_write(wphy, phy_config, FLUSH);
284                         }
285                 } else {        /* copper gigabit */
286 
287                         /* Auto-Negotiate or 1000 Mb must be auto negotiated
288                          * We've got a copper gigabit interface, and
289                          * register 4 is different in copper mode than
290                          * in fiber mode
291                          */
292                         if (linkspeed == LINK_AUTOSPEED) {
293                                 /* advertise 10/100 Mb modes   */
294                                 phy_advreg =
295                                     (MIICR_REG_4 |
296                                      (PAR_ADV100FD | PAR_ADV100HD | PAR_ADV10FD
297                                       | PAR_ADV10HD));
298                         } else {
299                         /* linkspeed == LINK_1000MB -
300                            don't advertise 10/100 Mb modes  */
301                                 phy_advreg = MIICR_REG_4;
302                         }
303                         /* enable PAUSE frames  */
304                         phy_advreg |= PAR_ASYMPAUSE;
305                         /* required by the Cicada PHY  */
306                         phy_advreg |= PAR_802_3;
307                         slic_reg32_write(wphy, phy_advreg, FLUSH);
308                         /* advertise FD only @1000 Mb  */
309                         phy_gctlreg = (MIICR_REG_9 | (PGC_ADV1000FD));
310                         slic_reg32_write(wphy, phy_gctlreg, FLUSH);
311 
312                         if (adapter->subsysid != SLIC_1GB_CICADA_SUBSYS_ID) {
313                                 /* if a Marvell PHY
314                                    enable auto crossover */
315                                 phy_config =
316                                     (MIICR_REG_16 | (MRV_REG16_XOVERON));
317                                 slic_reg32_write(wphy, phy_config, FLUSH);
318 
319                                 /* reset phy, enable auto-neg  */
320                                 phy_config =
321                                     (MIICR_REG_PCR |
322                                      (PCR_RESET | PCR_AUTONEG |
323                                       PCR_AUTONEG_RST));
324                                 slic_reg32_write(wphy, phy_config, FLUSH);
325                         } else {        /* it's a Cicada PHY  */
326                                 /* enable and restart auto-neg (don't reset)  */
327                                 phy_config =
328                                     (MIICR_REG_PCR |
329                                      (PCR_AUTONEG | PCR_AUTONEG_RST));
330                                 slic_reg32_write(wphy, phy_config, FLUSH);
331                         }
332                 }
333         } else {
334                 /* Forced 10/100  */
335                 if (linkspeed == LINK_10MB)
336                         speed = 0;
337                 else
338                         speed = PCR_SPEED_100;
339                 if (linkduplex == LINK_HALFD)
340                         duplex = 0;
341                 else
342                         duplex = PCR_DUPLEX_FULL;
343 
344                 if (adapter->subsysid != SLIC_1GB_CICADA_SUBSYS_ID) {
345                         /* if a Marvell PHY
346                            disable auto crossover  */
347                         phy_config = (MIICR_REG_16 | (MRV_REG16_XOVEROFF));
348                         slic_reg32_write(wphy, phy_config, FLUSH);
349                 }
350 
351                 /* power down phy to break link (this may not work)  */
352                 phy_config = (MIICR_REG_PCR | (PCR_POWERDOWN | speed | duplex));
353                 slic_reg32_write(wphy, phy_config, FLUSH);
354 
355                 /* wait, Marvell says 1 sec, try to get away with 10 ms */
356                 mdelay(10);
357 
358                 if (adapter->subsysid != SLIC_1GB_CICADA_SUBSYS_ID) {
359                         /* if a Marvell PHY
360                            disable auto-neg, set speed,
361                            soft reset phy, powerup */
362                         phy_config =
363                             (MIICR_REG_PCR | (PCR_RESET | speed | duplex));
364                         slic_reg32_write(wphy, phy_config, FLUSH);
365                 } else {        /* it's a Cicada PHY  */
366                         /* disable auto-neg, set speed, powerup  */
367                         phy_config = (MIICR_REG_PCR | (speed | duplex));
368                         slic_reg32_write(wphy, phy_config, FLUSH);
369                 }
370         }
371 }
372 
373 static int slic_card_download_gbrcv(struct adapter *adapter)
374 {
375         const struct firmware *fw;
376         const char *file = "";
377         int ret;
378         __iomem struct slic_regs *slic_regs = adapter->slic_regs;
379         u32 codeaddr;
380         u32 instruction;
381         int index = 0;
382         u32 rcvucodelen = 0;
383 
384         switch (adapter->devid) {
385         case SLIC_2GB_DEVICE_ID:
386                 file = "slicoss/oasisrcvucode.sys";
387                 break;
388         case SLIC_1GB_DEVICE_ID:
389                 file = "slicoss/gbrcvucode.sys";
390                 break;
391         default:
392                 return -ENOENT;
393         }
394 
395         ret = request_firmware(&fw, file, &adapter->pcidev->dev);
396         if (ret) {
397                 dev_err(&adapter->pcidev->dev,
398                         "Failed to load firmware %s\n", file);
399                 return ret;
400         }
401 
402         rcvucodelen = *(u32 *)(fw->data + index);
403         index += 4;
404         switch (adapter->devid) {
405         case SLIC_2GB_DEVICE_ID:
406                 if (rcvucodelen != OasisRcvUCodeLen) {
407                         release_firmware(fw);
408                         return -EINVAL;
409                 }
410                 break;
411         case SLIC_1GB_DEVICE_ID:
412                 if (rcvucodelen != GBRcvUCodeLen) {
413                         release_firmware(fw);
414                         return -EINVAL;
415                 }
416                 break;
417         }
418         /* start download */
419         slic_reg32_write(&slic_regs->slic_rcv_wcs, SLIC_RCVWCS_BEGIN, FLUSH);
420         /* download the rcv sequencer ucode */
421         for (codeaddr = 0; codeaddr < rcvucodelen; codeaddr++) {
422                 /* write out instruction address */
423                 slic_reg32_write(&slic_regs->slic_rcv_wcs, codeaddr, FLUSH);
424 
425                 instruction = *(u32 *)(fw->data + index);
426                 index += 4;
427                 /* write out the instruction data low addr */
428                 slic_reg32_write(&slic_regs->slic_rcv_wcs, instruction, FLUSH);
429 
430                 instruction = *(u8 *)(fw->data + index);
431                 index++;
432                 /* write out the instruction data high addr */
433                 slic_reg32_write(&slic_regs->slic_rcv_wcs, (u8)instruction,
434                                  FLUSH);
435         }
436 
437         /* download finished */
438         release_firmware(fw);
439         slic_reg32_write(&slic_regs->slic_rcv_wcs, SLIC_RCVWCS_FINISH, FLUSH);
440         return 0;
441 }
442 
443 MODULE_FIRMWARE("slicoss/oasisrcvucode.sys");
444 MODULE_FIRMWARE("slicoss/gbrcvucode.sys");
445 
446 static int slic_card_download(struct adapter *adapter)
447 {
448         const struct firmware *fw;
449         const char *file = "";
450         int ret;
451         u32 section;
452         int thissectionsize;
453         int codeaddr;
454         __iomem struct slic_regs *slic_regs = adapter->slic_regs;
455         u32 instruction;
456         u32 baseaddress;
457         u32 i;
458         u32 numsects = 0;
459         u32 sectsize[3];
460         u32 sectstart[3];
461         int ucode_start, index = 0;
462 
463         switch (adapter->devid) {
464         case SLIC_2GB_DEVICE_ID:
465                 file = "slicoss/oasisdownload.sys";
466                 break;
467         case SLIC_1GB_DEVICE_ID:
468                 file = "slicoss/gbdownload.sys";
469                 break;
470         default:
471                 return -ENOENT;
472         }
473         ret = request_firmware(&fw, file, &adapter->pcidev->dev);
474         if (ret) {
475                 dev_err(&adapter->pcidev->dev,
476                         "Failed to load firmware %s\n", file);
477                 return ret;
478         }
479         numsects = *(u32 *)(fw->data + index);
480         index += 4;
481         for (i = 0; i < numsects; i++) {
482                 sectsize[i] = *(u32 *)(fw->data + index);
483                 index += 4;
484         }
485         for (i = 0; i < numsects; i++) {
486                 sectstart[i] = *(u32 *)(fw->data + index);
487                 index += 4;
488         }
489         ucode_start = index;
490         instruction = *(u32 *)(fw->data + index);
491         index += 4;
492         for (section = 0; section < numsects; section++) {
493                 baseaddress = sectstart[section];
494                 thissectionsize = sectsize[section] >> 3;
495 
496                 for (codeaddr = 0; codeaddr < thissectionsize; codeaddr++) {
497                         /* Write out instruction address */
498                         slic_reg32_write(&slic_regs->slic_wcs,
499                                          baseaddress + codeaddr, FLUSH);
500                         /* Write out instruction to low addr */
501                         slic_reg32_write(&slic_regs->slic_wcs, instruction, FLUSH);
502                         instruction = *(u32 *)(fw->data + index);
503                         index += 4;
504 
505                         /* Write out instruction to high addr */
506                         slic_reg32_write(&slic_regs->slic_wcs, instruction, FLUSH);
507                         instruction = *(u32 *)(fw->data + index);
508                         index += 4;
509                 }
510         }
511         index = ucode_start;
512         for (section = 0; section < numsects; section++) {
513                 instruction = *(u32 *)(fw->data + index);
514                 baseaddress = sectstart[section];
515                 if (baseaddress < 0x8000)
516                         continue;
517                 thissectionsize = sectsize[section] >> 3;
518 
519                 for (codeaddr = 0; codeaddr < thissectionsize; codeaddr++) {
520                         /* Write out instruction address */
521                         slic_reg32_write(&slic_regs->slic_wcs,
522                                 SLIC_WCS_COMPARE | (baseaddress + codeaddr),
523                                 FLUSH);
524                         /* Write out instruction to low addr */
525                         slic_reg32_write(&slic_regs->slic_wcs, instruction,
526                                          FLUSH);
527                         instruction = *(u32 *)(fw->data + index);
528                         index += 4;
529                         /* Write out instruction to high addr */
530                         slic_reg32_write(&slic_regs->slic_wcs, instruction,
531                                          FLUSH);
532                         instruction = *(u32 *)(fw->data + index);
533                         index += 4;
534 
535                         /* Check SRAM location zero. If it is non-zero. Abort.*/
536 /*                      failure = readl((u32 __iomem *)&slic_regs->slic_reset);
537                         if (failure) {
538                                 release_firmware(fw);
539                                 return -EIO;
540                         }*/
541                 }
542         }
543         release_firmware(fw);
544         /* Everything OK, kick off the card */
545         mdelay(10);
546         slic_reg32_write(&slic_regs->slic_wcs, SLIC_WCS_START, FLUSH);
547 
548         /* stall for 20 ms, long enough for ucode to init card
549            and reach mainloop */
550         mdelay(20);
551 
552         return 0;
553 }
554 
555 MODULE_FIRMWARE("slicoss/oasisdownload.sys");
556 MODULE_FIRMWARE("slicoss/gbdownload.sys");
557 
558 static void slic_adapter_set_hwaddr(struct adapter *adapter)
559 {
560         struct sliccard *card = adapter->card;
561 
562         if ((adapter->card) && (card->config_set)) {
563                 memcpy(adapter->macaddr,
564                        card->config.MacInfo[adapter->functionnumber].macaddrA,
565                        sizeof(struct slic_config_mac));
566                 if (is_zero_ether_addr(adapter->currmacaddr))
567                         memcpy(adapter->currmacaddr, adapter->macaddr,
568                                ETH_ALEN);
569                 if (adapter->netdev)
570                         memcpy(adapter->netdev->dev_addr, adapter->currmacaddr,
571                                ETH_ALEN);
572         }
573 }
574 
575 static void slic_intagg_set(struct adapter *adapter, u32 value)
576 {
577         slic_reg32_write(&adapter->slic_regs->slic_intagg, value, FLUSH);
578         adapter->card->loadlevel_current = value;
579 }
580 
581 static void slic_soft_reset(struct adapter *adapter)
582 {
583         if (adapter->card->state == CARD_UP) {
584                 slic_reg32_write(&adapter->slic_regs->slic_quiesce, 0, FLUSH);
585                 mdelay(1);
586         }
587 
588         slic_reg32_write(&adapter->slic_regs->slic_reset, SLIC_RESET_MAGIC,
589                          FLUSH);
590         mdelay(1);
591 }
592 
593 static void slic_mac_address_config(struct adapter *adapter)
594 {
595         u32 value;
596         u32 value2;
597         __iomem struct slic_regs *slic_regs = adapter->slic_regs;
598 
599         value = *(u32 *) &adapter->currmacaddr[2];
600         value = ntohl(value);
601         slic_reg32_write(&slic_regs->slic_wraddral, value, FLUSH);
602         slic_reg32_write(&slic_regs->slic_wraddrbl, value, FLUSH);
603 
604         value2 = (u32) ((adapter->currmacaddr[0] << 8 |
605                              adapter->currmacaddr[1]) & 0xFFFF);
606 
607         slic_reg32_write(&slic_regs->slic_wraddrah, value2, FLUSH);
608         slic_reg32_write(&slic_regs->slic_wraddrbh, value2, FLUSH);
609 
610         /* Write our multicast mask out to the card.  This is done */
611         /* here in addition to the slic_mcast_addr_set routine     */
612         /* because ALL_MCAST may have been enabled or disabled     */
613         slic_mcast_set_mask(adapter);
614 }
615 
616 static void slic_mac_config(struct adapter *adapter)
617 {
618         u32 value;
619         __iomem struct slic_regs *slic_regs = adapter->slic_regs;
620 
621         /* Setup GMAC gaps */
622         if (adapter->linkspeed == LINK_1000MB) {
623                 value = ((GMCR_GAPBB_1000 << GMCR_GAPBB_SHIFT) |
624                          (GMCR_GAPR1_1000 << GMCR_GAPR1_SHIFT) |
625                          (GMCR_GAPR2_1000 << GMCR_GAPR2_SHIFT));
626         } else {
627                 value = ((GMCR_GAPBB_100 << GMCR_GAPBB_SHIFT) |
628                          (GMCR_GAPR1_100 << GMCR_GAPR1_SHIFT) |
629                          (GMCR_GAPR2_100 << GMCR_GAPR2_SHIFT));
630         }
631 
632         /* enable GMII */
633         if (adapter->linkspeed == LINK_1000MB)
634                 value |= GMCR_GBIT;
635 
636         /* enable fullduplex */
637         if ((adapter->linkduplex == LINK_FULLD)
638             || (adapter->macopts & MAC_LOOPBACK)) {
639                 value |= GMCR_FULLD;
640         }
641 
642         /* write mac config */
643         slic_reg32_write(&slic_regs->slic_wmcfg, value, FLUSH);
644 
645         /* setup mac addresses */
646         slic_mac_address_config(adapter);
647 }
648 
649 static void slic_config_set(struct adapter *adapter, bool linkchange)
650 {
651         u32 value;
652         u32 RcrReset;
653         __iomem struct slic_regs *slic_regs = adapter->slic_regs;
654 
655         if (linkchange) {
656                 /* Setup MAC */
657                 slic_mac_config(adapter);
658                 RcrReset = GRCR_RESET;
659         } else {
660                 slic_mac_address_config(adapter);
661                 RcrReset = 0;
662         }
663 
664         if (adapter->linkduplex == LINK_FULLD) {
665                 /* setup xmtcfg */
666                 value = (GXCR_RESET |   /* Always reset     */
667                          GXCR_XMTEN |   /* Enable transmit  */
668                          GXCR_PAUSEEN); /* Enable pause     */
669 
670                 slic_reg32_write(&slic_regs->slic_wxcfg, value, FLUSH);
671 
672                 /* Setup rcvcfg last */
673                 value = (RcrReset |     /* Reset, if linkchange */
674                          GRCR_CTLEN |   /* Enable CTL frames    */
675                          GRCR_ADDRAEN | /* Address A enable     */
676                          GRCR_RCVBAD |  /* Rcv bad frames       */
677                          (GRCR_HASHSIZE << GRCR_HASHSIZE_SHIFT));
678         } else {
679                 /* setup xmtcfg */
680                 value = (GXCR_RESET |   /* Always reset     */
681                          GXCR_XMTEN);   /* Enable transmit  */
682 
683                 slic_reg32_write(&slic_regs->slic_wxcfg, value, FLUSH);
684 
685                 /* Setup rcvcfg last */
686                 value = (RcrReset |     /* Reset, if linkchange */
687                          GRCR_ADDRAEN | /* Address A enable     */
688                          GRCR_RCVBAD |  /* Rcv bad frames       */
689                          (GRCR_HASHSIZE << GRCR_HASHSIZE_SHIFT));
690         }
691 
692         if (adapter->state != ADAPT_DOWN) {
693                 /* Only enable receive if we are restarting or running */
694                 value |= GRCR_RCVEN;
695         }
696 
697         if (adapter->macopts & MAC_PROMISC)
698                 value |= GRCR_RCVALL;
699 
700         slic_reg32_write(&slic_regs->slic_wrcfg, value, FLUSH);
701 }
702 
703 /*
704  *  Turn off RCV and XMT, power down PHY
705  */
706 static void slic_config_clear(struct adapter *adapter)
707 {
708         u32 value;
709         u32 phy_config;
710         __iomem struct slic_regs *slic_regs = adapter->slic_regs;
711 
712         /* Setup xmtcfg */
713         value = (GXCR_RESET |   /* Always reset */
714                  GXCR_PAUSEEN); /* Enable pause */
715 
716         slic_reg32_write(&slic_regs->slic_wxcfg, value, FLUSH);
717 
718         value = (GRCR_RESET |   /* Always reset      */
719                  GRCR_CTLEN |   /* Enable CTL frames */
720                  GRCR_ADDRAEN | /* Address A enable  */
721                  (GRCR_HASHSIZE << GRCR_HASHSIZE_SHIFT));
722 
723         slic_reg32_write(&slic_regs->slic_wrcfg, value, FLUSH);
724 
725         /* power down phy */
726         phy_config = (MIICR_REG_PCR | (PCR_POWERDOWN));
727         slic_reg32_write(&slic_regs->slic_wphy, phy_config, FLUSH);
728 }
729 
730 static bool slic_mac_filter(struct adapter *adapter,
731                         struct ether_header *ether_frame)
732 {
733         struct net_device *netdev = adapter->netdev;
734         u32 opts = adapter->macopts;
735 
736         if (opts & MAC_PROMISC)
737                 return true;
738 
739         if (is_broadcast_ether_addr(ether_frame->ether_dhost)) {
740                 if (opts & MAC_BCAST) {
741                         adapter->rcv_broadcasts++;
742                         return true;
743                 }
744 
745                 return false;
746         }
747 
748         if (is_multicast_ether_addr(ether_frame->ether_dhost)) {
749                 if (opts & MAC_ALLMCAST) {
750                         adapter->rcv_multicasts++;
751                         netdev->stats.multicast++;
752                         return true;
753                 }
754                 if (opts & MAC_MCAST) {
755                         struct mcast_address *mcaddr = adapter->mcastaddrs;
756 
757                         while (mcaddr) {
758                                 if (ether_addr_equal(mcaddr->address,
759                                                      ether_frame->ether_dhost)) {
760                                         adapter->rcv_multicasts++;
761                                         netdev->stats.multicast++;
762                                         return true;
763                                 }
764                                 mcaddr = mcaddr->next;
765                         }
766 
767                         return false;
768                 }
769 
770                 return false;
771         }
772         if (opts & MAC_DIRECTED) {
773                 adapter->rcv_unicasts++;
774                 return true;
775         }
776         return false;
777 
778 }
779 
780 static int slic_mac_set_address(struct net_device *dev, void *ptr)
781 {
782         struct adapter *adapter = netdev_priv(dev);
783         struct sockaddr *addr = ptr;
784 
785         if (netif_running(dev))
786                 return -EBUSY;
787         if (!adapter)
788                 return -EBUSY;
789 
790         if (!is_valid_ether_addr(addr->sa_data))
791                 return -EINVAL;
792 
793         memcpy(dev->dev_addr, addr->sa_data, dev->addr_len);
794         memcpy(adapter->currmacaddr, addr->sa_data, dev->addr_len);
795 
796         slic_config_set(adapter, true);
797         return 0;
798 }
799 
800 static void slic_timer_load_check(ulong cardaddr)
801 {
802         struct sliccard *card = (struct sliccard *)cardaddr;
803         struct adapter *adapter = card->master;
804         u32 __iomem *intagg;
805         u32 load = card->events;
806         u32 level = 0;
807 
808         if ((adapter) && (adapter->state == ADAPT_UP) &&
809             (card->state == CARD_UP) && (slic_global.dynamic_intagg)) {
810                 intagg = &adapter->slic_regs->slic_intagg;
811                 if (adapter->devid == SLIC_1GB_DEVICE_ID) {
812                         if (adapter->linkspeed == LINK_1000MB)
813                                 level = 100;
814                         else {
815                                 if (load > SLIC_LOAD_5)
816                                         level = SLIC_INTAGG_5;
817                                 else if (load > SLIC_LOAD_4)
818                                         level = SLIC_INTAGG_4;
819                                 else if (load > SLIC_LOAD_3)
820                                         level = SLIC_INTAGG_3;
821                                 else if (load > SLIC_LOAD_2)
822                                         level = SLIC_INTAGG_2;
823                                 else if (load > SLIC_LOAD_1)
824                                         level = SLIC_INTAGG_1;
825                                 else
826                                         level = SLIC_INTAGG_0;
827                         }
828                         if (card->loadlevel_current != level) {
829                                 card->loadlevel_current = level;
830                                 slic_reg32_write(intagg, level, FLUSH);
831                         }
832                 } else {
833                         if (load > SLIC_LOAD_5)
834                                 level = SLIC_INTAGG_5;
835                         else if (load > SLIC_LOAD_4)
836                                 level = SLIC_INTAGG_4;
837                         else if (load > SLIC_LOAD_3)
838                                 level = SLIC_INTAGG_3;
839                         else if (load > SLIC_LOAD_2)
840                                 level = SLIC_INTAGG_2;
841                         else if (load > SLIC_LOAD_1)
842                                 level = SLIC_INTAGG_1;
843                         else
844                                 level = SLIC_INTAGG_0;
845                         if (card->loadlevel_current != level) {
846                                 card->loadlevel_current = level;
847                                 slic_reg32_write(intagg, level, FLUSH);
848                         }
849                 }
850         }
851         card->events = 0;
852         card->loadtimer.expires = jiffies + (SLIC_LOADTIMER_PERIOD * HZ);
853         add_timer(&card->loadtimer);
854 }
855 
856 static int slic_upr_queue_request(struct adapter *adapter,
857                            u32 upr_request,
858                            u32 upr_data,
859                            u32 upr_data_h,
860                            u32 upr_buffer, u32 upr_buffer_h)
861 {
862         struct slic_upr *upr;
863         struct slic_upr *uprqueue;
864 
865         upr = kmalloc(sizeof(struct slic_upr), GFP_ATOMIC);
866         if (!upr)
867                 return -ENOMEM;
868 
869         upr->adapter = adapter->port;
870         upr->upr_request = upr_request;
871         upr->upr_data = upr_data;
872         upr->upr_buffer = upr_buffer;
873         upr->upr_data_h = upr_data_h;
874         upr->upr_buffer_h = upr_buffer_h;
875         upr->next = NULL;
876         if (adapter->upr_list) {
877                 uprqueue = adapter->upr_list;
878 
879                 while (uprqueue->next)
880                         uprqueue = uprqueue->next;
881                 uprqueue->next = upr;
882         } else {
883                 adapter->upr_list = upr;
884         }
885         return 0;
886 }
887 
888 static void slic_upr_start(struct adapter *adapter)
889 {
890         struct slic_upr *upr;
891         __iomem struct slic_regs *slic_regs = adapter->slic_regs;
892 /*
893     char * ptr1;
894     char * ptr2;
895     uint cmdoffset;
896 */
897         upr = adapter->upr_list;
898         if (!upr)
899                 return;
900         if (adapter->upr_busy)
901                 return;
902         adapter->upr_busy = 1;
903 
904         switch (upr->upr_request) {
905         case SLIC_UPR_STATS:
906                 if (upr->upr_data_h == 0) {
907                         slic_reg32_write(&slic_regs->slic_stats, upr->upr_data,
908                                          FLUSH);
909                 } else {
910                         slic_reg64_write(adapter, &slic_regs->slic_stats64,
911                                          upr->upr_data,
912                                          &slic_regs->slic_addr_upper,
913                                          upr->upr_data_h, FLUSH);
914                 }
915                 break;
916 
917         case SLIC_UPR_RLSR:
918                 slic_reg64_write(adapter, &slic_regs->slic_rlsr, upr->upr_data,
919                                  &slic_regs->slic_addr_upper, upr->upr_data_h,
920                                  FLUSH);
921                 break;
922 
923         case SLIC_UPR_RCONFIG:
924                 slic_reg64_write(adapter, &slic_regs->slic_rconfig,
925                                  upr->upr_data, &slic_regs->slic_addr_upper,
926                                  upr->upr_data_h, FLUSH);
927                 break;
928         case SLIC_UPR_PING:
929                 slic_reg32_write(&slic_regs->slic_ping, 1, FLUSH);
930                 break;
931         }
932 }
933 
934 static int slic_upr_request(struct adapter *adapter,
935                      u32 upr_request,
936                      u32 upr_data,
937                      u32 upr_data_h,
938                      u32 upr_buffer, u32 upr_buffer_h)
939 {
940         int rc;
941 
942         spin_lock_irqsave(&adapter->upr_lock.lock, adapter->upr_lock.flags);
943         rc = slic_upr_queue_request(adapter,
944                                         upr_request,
945                                         upr_data,
946                                         upr_data_h, upr_buffer, upr_buffer_h);
947         if (rc)
948                 goto err_unlock_irq;
949 
950         slic_upr_start(adapter);
951 err_unlock_irq:
952         spin_unlock_irqrestore(&adapter->upr_lock.lock,
953                                 adapter->upr_lock.flags);
954         return rc;
955 }
956 
957 static void slic_link_upr_complete(struct adapter *adapter, u32 isr)
958 {
959         u32 linkstatus = adapter->pshmem->linkstatus;
960         uint linkup;
961         unsigned char linkspeed;
962         unsigned char linkduplex;
963 
964         if ((isr & ISR_UPCERR) || (isr & ISR_UPCBSY)) {
965                 struct slic_shmem *pshmem;
966 
967                 pshmem = (struct slic_shmem *)(unsigned long)
968                          adapter->phys_shmem;
969 #if BITS_PER_LONG == 64
970                 slic_upr_queue_request(adapter,
971                                        SLIC_UPR_RLSR,
972                                        SLIC_GET_ADDR_LOW(&pshmem->linkstatus),
973                                        SLIC_GET_ADDR_HIGH(&pshmem->linkstatus),
974                                        0, 0);
975 #else
976                 slic_upr_queue_request(adapter,
977                                        SLIC_UPR_RLSR,
978                                        (u32) &pshmem->linkstatus,
979                                        SLIC_GET_ADDR_HIGH(pshmem), 0, 0);
980 #endif
981                 return;
982         }
983         if (adapter->state != ADAPT_UP)
984                 return;
985 
986         linkup = linkstatus & GIG_LINKUP ? LINK_UP : LINK_DOWN;
987         if (linkstatus & GIG_SPEED_1000)
988                 linkspeed = LINK_1000MB;
989         else if (linkstatus & GIG_SPEED_100)
990                 linkspeed = LINK_100MB;
991         else
992                 linkspeed = LINK_10MB;
993 
994         if (linkstatus & GIG_FULLDUPLEX)
995                 linkduplex = LINK_FULLD;
996         else
997                 linkduplex = LINK_HALFD;
998 
999         if ((adapter->linkstate == LINK_DOWN) && (linkup == LINK_DOWN))
1000                 return;
1001 
1002         /* link up event, but nothing has changed */
1003         if ((adapter->linkstate == LINK_UP) &&
1004             (linkup == LINK_UP) &&
1005             (adapter->linkspeed == linkspeed) &&
1006             (adapter->linkduplex == linkduplex))
1007                 return;
1008 
1009         /* link has changed at this point */
1010 
1011         /* link has gone from up to down */
1012         if (linkup == LINK_DOWN) {
1013                 adapter->linkstate = LINK_DOWN;
1014                 return;
1015         }
1016 
1017         /* link has gone from down to up */
1018         adapter->linkspeed = linkspeed;
1019         adapter->linkduplex = linkduplex;
1020 
1021         if (adapter->linkstate != LINK_UP) {
1022                 /* setup the mac */
1023                 slic_config_set(adapter, true);
1024                 adapter->linkstate = LINK_UP;
1025                 netif_start_queue(adapter->netdev);
1026         }
1027 }
1028 
1029 static void slic_upr_request_complete(struct adapter *adapter, u32 isr)
1030 {
1031         struct sliccard *card = adapter->card;
1032         struct slic_upr *upr;
1033 
1034         spin_lock_irqsave(&adapter->upr_lock.lock, adapter->upr_lock.flags);
1035         upr = adapter->upr_list;
1036         if (!upr) {
1037                 spin_unlock_irqrestore(&adapter->upr_lock.lock,
1038                                         adapter->upr_lock.flags);
1039                 return;
1040         }
1041         adapter->upr_list = upr->next;
1042         upr->next = NULL;
1043         adapter->upr_busy = 0;
1044         switch (upr->upr_request) {
1045         case SLIC_UPR_STATS:
1046                 {
1047                         struct slic_stats *slicstats =
1048                             (struct slic_stats *) &adapter->pshmem->inicstats;
1049                         struct slic_stats *newstats = slicstats;
1050                         struct slic_stats  *old = &adapter->inicstats_prev;
1051                         struct slicnet_stats *stst = &adapter->slic_stats;
1052 
1053                         if (isr & ISR_UPCERR) {
1054                                 dev_err(&adapter->netdev->dev,
1055                                         "SLIC_UPR_STATS command failed isr[%x]\n",
1056                                         isr);
1057 
1058                                 break;
1059                         }
1060                         UPDATE_STATS_GB(stst->tcp.xmit_tcp_segs,
1061                                         newstats->xmit_tcp_segs_gb,
1062                                         old->xmit_tcp_segs_gb);
1063 
1064                         UPDATE_STATS_GB(stst->tcp.xmit_tcp_bytes,
1065                                         newstats->xmit_tcp_bytes_gb,
1066                                         old->xmit_tcp_bytes_gb);
1067 
1068                         UPDATE_STATS_GB(stst->tcp.rcv_tcp_segs,
1069                                         newstats->rcv_tcp_segs_gb,
1070                                         old->rcv_tcp_segs_gb);
1071 
1072                         UPDATE_STATS_GB(stst->tcp.rcv_tcp_bytes,
1073                                         newstats->rcv_tcp_bytes_gb,
1074                                         old->rcv_tcp_bytes_gb);
1075 
1076                         UPDATE_STATS_GB(stst->iface.xmt_bytes,
1077                                         newstats->xmit_bytes_gb,
1078                                         old->xmit_bytes_gb);
1079 
1080                         UPDATE_STATS_GB(stst->iface.xmt_ucast,
1081                                         newstats->xmit_unicasts_gb,
1082                                         old->xmit_unicasts_gb);
1083 
1084                         UPDATE_STATS_GB(stst->iface.rcv_bytes,
1085                                         newstats->rcv_bytes_gb,
1086                                         old->rcv_bytes_gb);
1087 
1088                         UPDATE_STATS_GB(stst->iface.rcv_ucast,
1089                                         newstats->rcv_unicasts_gb,
1090                                         old->rcv_unicasts_gb);
1091 
1092                         UPDATE_STATS_GB(stst->iface.xmt_errors,
1093                                         newstats->xmit_collisions_gb,
1094                                         old->xmit_collisions_gb);
1095 
1096                         UPDATE_STATS_GB(stst->iface.xmt_errors,
1097                                         newstats->xmit_excess_collisions_gb,
1098                                         old->xmit_excess_collisions_gb);
1099 
1100                         UPDATE_STATS_GB(stst->iface.xmt_errors,
1101                                         newstats->xmit_other_error_gb,
1102                                         old->xmit_other_error_gb);
1103 
1104                         UPDATE_STATS_GB(stst->iface.rcv_errors,
1105                                         newstats->rcv_other_error_gb,
1106                                         old->rcv_other_error_gb);
1107 
1108                         UPDATE_STATS_GB(stst->iface.rcv_discards,
1109                                         newstats->rcv_drops_gb,
1110                                         old->rcv_drops_gb);
1111 
1112                         if (newstats->rcv_drops_gb > old->rcv_drops_gb) {
1113                                 adapter->rcv_drops +=
1114                                     (newstats->rcv_drops_gb -
1115                                      old->rcv_drops_gb);
1116                         }
1117                         memcpy(old, newstats, sizeof(struct slic_stats));
1118                         break;
1119                 }
1120         case SLIC_UPR_RLSR:
1121                 slic_link_upr_complete(adapter, isr);
1122                 break;
1123         case SLIC_UPR_RCONFIG:
1124                 break;
1125         case SLIC_UPR_PING:
1126                 card->pingstatus |= (isr & ISR_PINGDSMASK);
1127                 break;
1128         }
1129         kfree(upr);
1130         slic_upr_start(adapter);
1131         spin_unlock_irqrestore(&adapter->upr_lock.lock,
1132                                 adapter->upr_lock.flags);
1133 }
1134 
1135 static int slic_config_get(struct adapter *adapter, u32 config, u32 config_h)
1136 {
1137         return slic_upr_request(adapter, SLIC_UPR_RCONFIG, config, config_h,
1138                                 0, 0);
1139 }
1140 
1141 /*
1142  * Compute a checksum of the EEPROM according to RFC 1071.
1143  */
1144 static u16 slic_eeprom_cksum(void *eeprom, unsigned len)
1145 {
1146         u16 *wp = eeprom;
1147         u32 checksum = 0;
1148 
1149         while (len > 1) {
1150                 checksum += *(wp++);
1151                 len -= 2;
1152         }
1153 
1154         if (len > 0)
1155                 checksum += *(u8 *) wp;
1156 
1157 
1158         while (checksum >> 16)
1159                 checksum = (checksum & 0xFFFF) + ((checksum >> 16) & 0xFFFF);
1160 
1161         return ~checksum;
1162 }
1163 
1164 static void slic_rspqueue_free(struct adapter *adapter)
1165 {
1166         int i;
1167         struct slic_rspqueue *rspq = &adapter->rspqueue;
1168 
1169         for (i = 0; i < rspq->num_pages; i++) {
1170                 if (rspq->vaddr[i]) {
1171                         pci_free_consistent(adapter->pcidev, PAGE_SIZE,
1172                                             rspq->vaddr[i], rspq->paddr[i]);
1173                 }
1174                 rspq->vaddr[i] = NULL;
1175                 rspq->paddr[i] = 0;
1176         }
1177         rspq->offset = 0;
1178         rspq->pageindex = 0;
1179         rspq->rspbuf = NULL;
1180 }
1181 
1182 static int slic_rspqueue_init(struct adapter *adapter)
1183 {
1184         int i;
1185         struct slic_rspqueue *rspq = &adapter->rspqueue;
1186         __iomem struct slic_regs *slic_regs = adapter->slic_regs;
1187         u32 paddrh = 0;
1188 
1189         memset(rspq, 0, sizeof(struct slic_rspqueue));
1190 
1191         rspq->num_pages = SLIC_RSPQ_PAGES_GB;
1192 
1193         for (i = 0; i < rspq->num_pages; i++) {
1194                 rspq->vaddr[i] = pci_zalloc_consistent(adapter->pcidev,
1195                                                        PAGE_SIZE,
1196                                                        &rspq->paddr[i]);
1197                 if (!rspq->vaddr[i]) {
1198                         dev_err(&adapter->pcidev->dev,
1199                                 "pci_alloc_consistent failed\n");
1200                         slic_rspqueue_free(adapter);
1201                         return -ENOMEM;
1202                 }
1203 
1204                 if (paddrh == 0) {
1205                         slic_reg32_write(&slic_regs->slic_rbar,
1206                                 (rspq->paddr[i] | SLIC_RSPQ_BUFSINPAGE),
1207                                 DONT_FLUSH);
1208                 } else {
1209                         slic_reg64_write(adapter, &slic_regs->slic_rbar64,
1210                                 (rspq->paddr[i] | SLIC_RSPQ_BUFSINPAGE),
1211                                 &slic_regs->slic_addr_upper,
1212                                 paddrh, DONT_FLUSH);
1213                 }
1214         }
1215         rspq->offset = 0;
1216         rspq->pageindex = 0;
1217         rspq->rspbuf = (struct slic_rspbuf *)rspq->vaddr[0];
1218         return 0;
1219 }
1220 
1221 static struct slic_rspbuf *slic_rspqueue_getnext(struct adapter *adapter)
1222 {
1223         struct slic_rspqueue *rspq = &adapter->rspqueue;
1224         struct slic_rspbuf *buf;
1225 
1226         if (!(rspq->rspbuf->status))
1227                 return NULL;
1228 
1229         buf = rspq->rspbuf;
1230         if (++rspq->offset < SLIC_RSPQ_BUFSINPAGE) {
1231                 rspq->rspbuf++;
1232         } else {
1233                 slic_reg64_write(adapter, &adapter->slic_regs->slic_rbar64,
1234                         (rspq->paddr[rspq->pageindex] | SLIC_RSPQ_BUFSINPAGE),
1235                         &adapter->slic_regs->slic_addr_upper, 0, DONT_FLUSH);
1236                 rspq->pageindex = (rspq->pageindex + 1) % rspq->num_pages;
1237                 rspq->offset = 0;
1238                 rspq->rspbuf = (struct slic_rspbuf *)
1239                                                 rspq->vaddr[rspq->pageindex];
1240         }
1241 
1242         return buf;
1243 }
1244 
1245 static void slic_cmdqmem_free(struct adapter *adapter)
1246 {
1247         struct slic_cmdqmem *cmdqmem = &adapter->cmdqmem;
1248         int i;
1249 
1250         for (i = 0; i < SLIC_CMDQ_MAXPAGES; i++) {
1251                 if (cmdqmem->pages[i]) {
1252                         pci_free_consistent(adapter->pcidev,
1253                                             PAGE_SIZE,
1254                                             (void *) cmdqmem->pages[i],
1255                                             cmdqmem->dma_pages[i]);
1256                 }
1257         }
1258         memset(cmdqmem, 0, sizeof(struct slic_cmdqmem));
1259 }
1260 
1261 static u32 *slic_cmdqmem_addpage(struct adapter *adapter)
1262 {
1263         struct slic_cmdqmem *cmdqmem = &adapter->cmdqmem;
1264         u32 *pageaddr;
1265 
1266         if (cmdqmem->pagecnt >= SLIC_CMDQ_MAXPAGES)
1267                 return NULL;
1268         pageaddr = pci_alloc_consistent(adapter->pcidev,
1269                                         PAGE_SIZE,
1270                                         &cmdqmem->dma_pages[cmdqmem->pagecnt]);
1271         if (!pageaddr)
1272                 return NULL;
1273 
1274         cmdqmem->pages[cmdqmem->pagecnt] = pageaddr;
1275         cmdqmem->pagecnt++;
1276         return pageaddr;
1277 }
1278 
1279 static void slic_cmdq_free(struct adapter *adapter)
1280 {
1281         struct slic_hostcmd *cmd;
1282 
1283         cmd = adapter->cmdq_all.head;
1284         while (cmd) {
1285                 if (cmd->busy) {
1286                         struct sk_buff *tempskb;
1287 
1288                         tempskb = cmd->skb;
1289                         if (tempskb) {
1290                                 cmd->skb = NULL;
1291                                 dev_kfree_skb_irq(tempskb);
1292                         }
1293                 }
1294                 cmd = cmd->next_all;
1295         }
1296         memset(&adapter->cmdq_all, 0, sizeof(struct slic_cmdqueue));
1297         memset(&adapter->cmdq_free, 0, sizeof(struct slic_cmdqueue));
1298         memset(&adapter->cmdq_done, 0, sizeof(struct slic_cmdqueue));
1299         slic_cmdqmem_free(adapter);
1300 }
1301 
1302 static void slic_cmdq_addcmdpage(struct adapter *adapter, u32 *page)
1303 {
1304         struct slic_hostcmd *cmd;
1305         struct slic_hostcmd *prev;
1306         struct slic_hostcmd *tail;
1307         struct slic_cmdqueue *cmdq;
1308         int cmdcnt;
1309         void *cmdaddr;
1310         ulong phys_addr;
1311         u32 phys_addrl;
1312         u32 phys_addrh;
1313         struct slic_handle *pslic_handle;
1314 
1315         cmdaddr = page;
1316         cmd = (struct slic_hostcmd *)cmdaddr;
1317         cmdcnt = 0;
1318 
1319         phys_addr = virt_to_bus((void *)page);
1320         phys_addrl = SLIC_GET_ADDR_LOW(phys_addr);
1321         phys_addrh = SLIC_GET_ADDR_HIGH(phys_addr);
1322 
1323         prev = NULL;
1324         tail = cmd;
1325         while ((cmdcnt < SLIC_CMDQ_CMDSINPAGE) &&
1326                (adapter->slic_handle_ix < 256)) {
1327                 /* Allocate and initialize a SLIC_HANDLE for this command */
1328                 spin_lock_irqsave(&adapter->handle_lock.lock,
1329                                 adapter->handle_lock.flags);
1330                 pslic_handle  =  adapter->pfree_slic_handles;
1331                 adapter->pfree_slic_handles = pslic_handle->next;
1332                 spin_unlock_irqrestore(&adapter->handle_lock.lock,
1333                                 adapter->handle_lock.flags);
1334                 pslic_handle->type = SLIC_HANDLE_CMD;
1335                 pslic_handle->address = (void *) cmd;
1336                 pslic_handle->offset = (ushort) adapter->slic_handle_ix++;
1337                 pslic_handle->other_handle = NULL;
1338                 pslic_handle->next = NULL;
1339 
1340                 cmd->pslic_handle = pslic_handle;
1341                 cmd->cmd64.hosthandle = pslic_handle->token.handle_token;
1342                 cmd->busy = false;
1343                 cmd->paddrl = phys_addrl;
1344                 cmd->paddrh = phys_addrh;
1345                 cmd->next_all = prev;
1346                 cmd->next = prev;
1347                 prev = cmd;
1348                 phys_addrl += SLIC_HOSTCMD_SIZE;
1349                 cmdaddr += SLIC_HOSTCMD_SIZE;
1350 
1351                 cmd = (struct slic_hostcmd *)cmdaddr;
1352                 cmdcnt++;
1353         }
1354 
1355         cmdq = &adapter->cmdq_all;
1356         cmdq->count += cmdcnt;  /*  SLIC_CMDQ_CMDSINPAGE;   mooktodo */
1357         tail->next_all = cmdq->head;
1358         cmdq->head = prev;
1359         cmdq = &adapter->cmdq_free;
1360         spin_lock_irqsave(&cmdq->lock.lock, cmdq->lock.flags);
1361         cmdq->count += cmdcnt;  /*  SLIC_CMDQ_CMDSINPAGE;   mooktodo */
1362         tail->next = cmdq->head;
1363         cmdq->head = prev;
1364         spin_unlock_irqrestore(&cmdq->lock.lock, cmdq->lock.flags);
1365 }
1366 
1367 static int slic_cmdq_init(struct adapter *adapter)
1368 {
1369         int i;
1370         u32 *pageaddr;
1371 
1372         memset(&adapter->cmdq_all, 0, sizeof(struct slic_cmdqueue));
1373         memset(&adapter->cmdq_free, 0, sizeof(struct slic_cmdqueue));
1374         memset(&adapter->cmdq_done, 0, sizeof(struct slic_cmdqueue));
1375         spin_lock_init(&adapter->cmdq_all.lock.lock);
1376         spin_lock_init(&adapter->cmdq_free.lock.lock);
1377         spin_lock_init(&adapter->cmdq_done.lock.lock);
1378         memset(&adapter->cmdqmem, 0, sizeof(struct slic_cmdqmem));
1379         adapter->slic_handle_ix = 1;
1380         for (i = 0; i < SLIC_CMDQ_INITPAGES; i++) {
1381                 pageaddr = slic_cmdqmem_addpage(adapter);
1382                 if (!pageaddr) {
1383                         slic_cmdq_free(adapter);
1384                         return -ENOMEM;
1385                 }
1386                 slic_cmdq_addcmdpage(adapter, pageaddr);
1387         }
1388         adapter->slic_handle_ix = 1;
1389 
1390         return 0;
1391 }
1392 
1393 static void slic_cmdq_reset(struct adapter *adapter)
1394 {
1395         struct slic_hostcmd *hcmd;
1396         struct sk_buff *skb;
1397         u32 outstanding;
1398 
1399         spin_lock_irqsave(&adapter->cmdq_free.lock.lock,
1400                         adapter->cmdq_free.lock.flags);
1401         spin_lock_irqsave(&adapter->cmdq_done.lock.lock,
1402                         adapter->cmdq_done.lock.flags);
1403         outstanding = adapter->cmdq_all.count - adapter->cmdq_done.count;
1404         outstanding -= adapter->cmdq_free.count;
1405         hcmd = adapter->cmdq_all.head;
1406         while (hcmd) {
1407                 if (hcmd->busy) {
1408                         skb = hcmd->skb;
1409                         hcmd->busy = 0;
1410                         hcmd->skb = NULL;
1411                         dev_kfree_skb_irq(skb);
1412                 }
1413                 hcmd = hcmd->next_all;
1414         }
1415         adapter->cmdq_free.count = 0;
1416         adapter->cmdq_free.head = NULL;
1417         adapter->cmdq_free.tail = NULL;
1418         adapter->cmdq_done.count = 0;
1419         adapter->cmdq_done.head = NULL;
1420         adapter->cmdq_done.tail = NULL;
1421         adapter->cmdq_free.head = adapter->cmdq_all.head;
1422         hcmd = adapter->cmdq_all.head;
1423         while (hcmd) {
1424                 adapter->cmdq_free.count++;
1425                 hcmd->next = hcmd->next_all;
1426                 hcmd = hcmd->next_all;
1427         }
1428         if (adapter->cmdq_free.count != adapter->cmdq_all.count) {
1429                 dev_err(&adapter->netdev->dev,
1430                         "free_count %d != all count %d\n",
1431                         adapter->cmdq_free.count, adapter->cmdq_all.count);
1432         }
1433         spin_unlock_irqrestore(&adapter->cmdq_done.lock.lock,
1434                                 adapter->cmdq_done.lock.flags);
1435         spin_unlock_irqrestore(&adapter->cmdq_free.lock.lock,
1436                                 adapter->cmdq_free.lock.flags);
1437 }
1438 
1439 static void slic_cmdq_getdone(struct adapter *adapter)
1440 {
1441         struct slic_cmdqueue *done_cmdq = &adapter->cmdq_done;
1442         struct slic_cmdqueue *free_cmdq = &adapter->cmdq_free;
1443 
1444         spin_lock_irqsave(&done_cmdq->lock.lock, done_cmdq->lock.flags);
1445 
1446         free_cmdq->head = done_cmdq->head;
1447         free_cmdq->count = done_cmdq->count;
1448         done_cmdq->head = NULL;
1449         done_cmdq->tail = NULL;
1450         done_cmdq->count = 0;
1451         spin_unlock_irqrestore(&done_cmdq->lock.lock, done_cmdq->lock.flags);
1452 }
1453 
1454 static struct slic_hostcmd *slic_cmdq_getfree(struct adapter *adapter)
1455 {
1456         struct slic_cmdqueue *cmdq = &adapter->cmdq_free;
1457         struct slic_hostcmd *cmd = NULL;
1458 
1459 lock_and_retry:
1460         spin_lock_irqsave(&cmdq->lock.lock, cmdq->lock.flags);
1461 retry:
1462         cmd = cmdq->head;
1463         if (cmd) {
1464                 cmdq->head = cmd->next;
1465                 cmdq->count--;
1466                 spin_unlock_irqrestore(&cmdq->lock.lock, cmdq->lock.flags);
1467         } else {
1468                 slic_cmdq_getdone(adapter);
1469                 cmd = cmdq->head;
1470                 if (cmd) {
1471                         goto retry;
1472                 } else {
1473                         u32 *pageaddr;
1474 
1475                         spin_unlock_irqrestore(&cmdq->lock.lock,
1476                                                 cmdq->lock.flags);
1477                         pageaddr = slic_cmdqmem_addpage(adapter);
1478                         if (pageaddr) {
1479                                 slic_cmdq_addcmdpage(adapter, pageaddr);
1480                                 goto lock_and_retry;
1481                         }
1482                 }
1483         }
1484         return cmd;
1485 }
1486 
1487 static void slic_cmdq_putdone_irq(struct adapter *adapter,
1488                                 struct slic_hostcmd *cmd)
1489 {
1490         struct slic_cmdqueue *cmdq = &adapter->cmdq_done;
1491 
1492         spin_lock(&cmdq->lock.lock);
1493         cmd->busy = 0;
1494         cmd->next = cmdq->head;
1495         cmdq->head = cmd;
1496         cmdq->count++;
1497         if ((adapter->xmitq_full) && (cmdq->count > 10))
1498                 netif_wake_queue(adapter->netdev);
1499         spin_unlock(&cmdq->lock.lock);
1500 }
1501 
1502 static int slic_rcvqueue_fill(struct adapter *adapter)
1503 {
1504         void *paddr;
1505         u32 paddrl;
1506         u32 paddrh;
1507         struct slic_rcvqueue *rcvq = &adapter->rcvqueue;
1508         int i = 0;
1509         struct device *dev = &adapter->netdev->dev;
1510 
1511         while (i < SLIC_RCVQ_FILLENTRIES) {
1512                 struct slic_rcvbuf *rcvbuf;
1513                 struct sk_buff *skb;
1514 #ifdef KLUDGE_FOR_4GB_BOUNDARY
1515 retry_rcvqfill:
1516 #endif
1517                 skb = alloc_skb(SLIC_RCVQ_RCVBUFSIZE, GFP_ATOMIC);
1518                 if (skb) {
1519                         paddr = (void *)(unsigned long)
1520                                 pci_map_single(adapter->pcidev,
1521                                                skb->data,
1522                                                SLIC_RCVQ_RCVBUFSIZE,
1523                                                PCI_DMA_FROMDEVICE);
1524                         paddrl = SLIC_GET_ADDR_LOW(paddr);
1525                         paddrh = SLIC_GET_ADDR_HIGH(paddr);
1526 
1527                         skb->len = SLIC_RCVBUF_HEADSIZE;
1528                         rcvbuf = (struct slic_rcvbuf *)skb->head;
1529                         rcvbuf->status = 0;
1530                         skb->next = NULL;
1531 #ifdef KLUDGE_FOR_4GB_BOUNDARY
1532                         if (paddrl == 0) {
1533                                 dev_err(dev, "%s: LOW 32bits PHYSICAL ADDRESS == 0\n",
1534                                         __func__);
1535                                 dev_err(dev, "skb[%p] PROBLEM\n", skb);
1536                                 dev_err(dev, "         skbdata[%p]\n", skb->data);
1537                                 dev_err(dev, "         skblen[%x]\n", skb->len);
1538                                 dev_err(dev, "         paddr[%p]\n", paddr);
1539                                 dev_err(dev, "         paddrl[%x]\n", paddrl);
1540                                 dev_err(dev, "         paddrh[%x]\n", paddrh);
1541                                 dev_err(dev, "         rcvq->head[%p]\n", rcvq->head);
1542                                 dev_err(dev, "         rcvq->tail[%p]\n", rcvq->tail);
1543                                 dev_err(dev, "         rcvq->count[%x]\n", rcvq->count);
1544                                 dev_err(dev, "SKIP THIS SKB!!!!!!!!\n");
1545                                 goto retry_rcvqfill;
1546                         }
1547 #else
1548                         if (paddrl == 0) {
1549                                 dev_err(dev, "%s: LOW 32bits PHYSICAL ADDRESS == 0\n",
1550                                         __func__);
1551                                 dev_err(dev, "skb[%p] PROBLEM\n", skb);
1552                                 dev_err(dev, "         skbdata[%p]\n", skb->data);
1553                                 dev_err(dev, "         skblen[%x]\n", skb->len);
1554                                 dev_err(dev, "         paddr[%p]\n", paddr);
1555                                 dev_err(dev, "         paddrl[%x]\n", paddrl);
1556                                 dev_err(dev, "         paddrh[%x]\n", paddrh);
1557                                 dev_err(dev, "         rcvq->head[%p]\n", rcvq->head);
1558                                 dev_err(dev, "         rcvq->tail[%p]\n", rcvq->tail);
1559                                 dev_err(dev, "         rcvq->count[%x]\n", rcvq->count);
1560                                 dev_err(dev, "GIVE TO CARD ANYWAY\n");
1561                         }
1562 #endif
1563                         if (paddrh == 0) {
1564                                 slic_reg32_write(&adapter->slic_regs->slic_hbar,
1565                                                  (u32)paddrl, DONT_FLUSH);
1566                         } else {
1567                                 slic_reg64_write(adapter,
1568                                         &adapter->slic_regs->slic_hbar64,
1569                                         paddrl,
1570                                         &adapter->slic_regs->slic_addr_upper,
1571                                         paddrh, DONT_FLUSH);
1572                         }
1573                         if (rcvq->head)
1574                                 rcvq->tail->next = skb;
1575                         else
1576                                 rcvq->head = skb;
1577                         rcvq->tail = skb;
1578                         rcvq->count++;
1579                         i++;
1580                 } else {
1581                         dev_err(&adapter->netdev->dev,
1582                                 "slic_rcvqueue_fill could only get [%d] skbuffs\n",
1583                                 i);
1584                         break;
1585                 }
1586         }
1587         return i;
1588 }
1589 
1590 static void slic_rcvqueue_free(struct adapter *adapter)
1591 {
1592         struct slic_rcvqueue *rcvq = &adapter->rcvqueue;
1593         struct sk_buff *skb;
1594 
1595         while (rcvq->head) {
1596                 skb = rcvq->head;
1597                 rcvq->head = rcvq->head->next;
1598                 dev_kfree_skb(skb);
1599         }
1600         rcvq->tail = NULL;
1601         rcvq->head = NULL;
1602         rcvq->count = 0;
1603 }
1604 
1605 static int slic_rcvqueue_init(struct adapter *adapter)
1606 {
1607         int i, count;
1608         struct slic_rcvqueue *rcvq = &adapter->rcvqueue;
1609 
1610         rcvq->tail = NULL;
1611         rcvq->head = NULL;
1612         rcvq->size = SLIC_RCVQ_ENTRIES;
1613         rcvq->errors = 0;
1614         rcvq->count = 0;
1615         i = (SLIC_RCVQ_ENTRIES / SLIC_RCVQ_FILLENTRIES);
1616         count = 0;
1617         while (i) {
1618                 count += slic_rcvqueue_fill(adapter);
1619                 i--;
1620         }
1621         if (rcvq->count < SLIC_RCVQ_MINENTRIES) {
1622                 slic_rcvqueue_free(adapter);
1623                 return -ENOMEM;
1624         }
1625         return 0;
1626 }
1627 
1628 static struct sk_buff *slic_rcvqueue_getnext(struct adapter *adapter)
1629 {
1630         struct slic_rcvqueue *rcvq = &adapter->rcvqueue;
1631         struct sk_buff *skb;
1632         struct slic_rcvbuf *rcvbuf;
1633         int count;
1634 
1635         if (rcvq->count) {
1636                 skb = rcvq->head;
1637                 rcvbuf = (struct slic_rcvbuf *)skb->head;
1638 
1639                 if (rcvbuf->status & IRHDDR_SVALID) {
1640                         rcvq->head = rcvq->head->next;
1641                         skb->next = NULL;
1642                         rcvq->count--;
1643                 } else {
1644                         skb = NULL;
1645                 }
1646         } else {
1647                 dev_err(&adapter->netdev->dev,
1648                         "RcvQ Empty!! rcvq[%p] count[%x]\n", rcvq, rcvq->count);
1649                 skb = NULL;
1650         }
1651         while (rcvq->count < SLIC_RCVQ_FILLTHRESH) {
1652                 count = slic_rcvqueue_fill(adapter);
1653                 if (!count)
1654                         break;
1655         }
1656         if (skb)
1657                 rcvq->errors = 0;
1658         return skb;
1659 }
1660 
1661 static u32 slic_rcvqueue_reinsert(struct adapter *adapter, struct sk_buff *skb)
1662 {
1663         struct slic_rcvqueue *rcvq = &adapter->rcvqueue;
1664         void *paddr;
1665         u32 paddrl;
1666         u32 paddrh;
1667         struct slic_rcvbuf *rcvbuf = (struct slic_rcvbuf *)skb->head;
1668         struct device *dev;
1669 
1670         paddr = (void *)(unsigned long)
1671                 pci_map_single(adapter->pcidev, skb->head,
1672                                SLIC_RCVQ_RCVBUFSIZE, PCI_DMA_FROMDEVICE);
1673         rcvbuf->status = 0;
1674         skb->next = NULL;
1675 
1676         paddrl = SLIC_GET_ADDR_LOW(paddr);
1677         paddrh = SLIC_GET_ADDR_HIGH(paddr);
1678 
1679         if (paddrl == 0) {
1680                 dev = &adapter->netdev->dev;
1681                 dev_err(dev, "%s: LOW 32bits PHYSICAL ADDRESS == 0\n",
1682                         __func__);
1683                 dev_err(dev, "skb[%p] PROBLEM\n", skb);
1684                 dev_err(dev, "         skbdata[%p]\n", skb->data);
1685                 dev_err(dev, "         skblen[%x]\n", skb->len);
1686                 dev_err(dev, "         paddr[%p]\n", paddr);
1687                 dev_err(dev, "         paddrl[%x]\n", paddrl);
1688                 dev_err(dev, "         paddrh[%x]\n", paddrh);
1689                 dev_err(dev, "         rcvq->head[%p]\n", rcvq->head);
1690                 dev_err(dev, "         rcvq->tail[%p]\n", rcvq->tail);
1691                 dev_err(dev, "         rcvq->count[%x]\n", rcvq->count);
1692         }
1693         if (paddrh == 0) {
1694                 slic_reg32_write(&adapter->slic_regs->slic_hbar, (u32)paddrl,
1695                                  DONT_FLUSH);
1696         } else {
1697                 slic_reg64_write(adapter, &adapter->slic_regs->slic_hbar64,
1698                                  paddrl, &adapter->slic_regs->slic_addr_upper,
1699                                  paddrh, DONT_FLUSH);
1700         }
1701         if (rcvq->head)
1702                 rcvq->tail->next = skb;
1703         else
1704                 rcvq->head = skb;
1705         rcvq->tail = skb;
1706         rcvq->count++;
1707         return rcvq->count;
1708 }
1709 
1710 /*
1711  * slic_link_event_handler -
1712  *
1713  * Initiate a link configuration sequence.  The link configuration begins
1714  * by issuing a READ_LINK_STATUS command to the Utility Processor on the
1715  * SLIC.  Since the command finishes asynchronously, the slic_upr_comlete
1716  * routine will follow it up witha UP configuration write command, which
1717  * will also complete asynchronously.
1718  *
1719  */
1720 static void slic_link_event_handler(struct adapter *adapter)
1721 {
1722         int status;
1723         struct slic_shmem *pshmem;
1724 
1725         if (adapter->state != ADAPT_UP) {
1726                 /* Adapter is not operational.  Ignore.  */
1727                 return;
1728         }
1729 
1730         pshmem = (struct slic_shmem *)(unsigned long)adapter->phys_shmem;
1731 
1732 #if BITS_PER_LONG == 64
1733         status = slic_upr_request(adapter,
1734                                   SLIC_UPR_RLSR,
1735                                   SLIC_GET_ADDR_LOW(&pshmem->linkstatus),
1736                                   SLIC_GET_ADDR_HIGH(&pshmem->linkstatus),
1737                                   0, 0);
1738 #else
1739         status = slic_upr_request(adapter, SLIC_UPR_RLSR,
1740                 (u32) &pshmem->linkstatus,      /* no 4GB wrap guaranteed */
1741                                   0, 0, 0);
1742 #endif
1743 }
1744 
1745 static void slic_init_cleanup(struct adapter *adapter)
1746 {
1747         if (adapter->intrregistered) {
1748                 adapter->intrregistered = 0;
1749                 free_irq(adapter->netdev->irq, adapter->netdev);
1750 
1751         }
1752         if (adapter->pshmem) {
1753                 pci_free_consistent(adapter->pcidev,
1754                                     sizeof(struct slic_shmem),
1755                                     adapter->pshmem, adapter->phys_shmem);
1756                 adapter->pshmem = NULL;
1757                 adapter->phys_shmem = (dma_addr_t)(unsigned long)NULL;
1758         }
1759 
1760         if (adapter->pingtimerset) {
1761                 adapter->pingtimerset = 0;
1762                 del_timer(&adapter->pingtimer);
1763         }
1764 
1765         slic_rspqueue_free(adapter);
1766         slic_cmdq_free(adapter);
1767         slic_rcvqueue_free(adapter);
1768 }
1769 
1770 /*
1771  *  Allocate a mcast_address structure to hold the multicast address.
1772  *  Link it in.
1773  */
1774 static int slic_mcast_add_list(struct adapter *adapter, char *address)
1775 {
1776         struct mcast_address *mcaddr, *mlist;
1777 
1778         /* Check to see if it already exists */
1779         mlist = adapter->mcastaddrs;
1780         while (mlist) {
1781                 if (ether_addr_equal(mlist->address, address))
1782                         return 0;
1783                 mlist = mlist->next;
1784         }
1785 
1786         /* Doesn't already exist.  Allocate a structure to hold it */
1787         mcaddr = kmalloc(sizeof(struct mcast_address), GFP_ATOMIC);
1788         if (mcaddr == NULL)
1789                 return 1;
1790 
1791         memcpy(mcaddr->address, address, ETH_ALEN);
1792 
1793         mcaddr->next = adapter->mcastaddrs;
1794         adapter->mcastaddrs = mcaddr;
1795 
1796         return 0;
1797 }
1798 
1799 static void slic_mcast_set_list(struct net_device *dev)
1800 {
1801         struct adapter *adapter = netdev_priv(dev);
1802         int status = 0;
1803         char *addresses;
1804         struct netdev_hw_addr *ha;
1805 
1806         netdev_for_each_mc_addr(ha, dev) {
1807                 addresses = (char *) &ha->addr;
1808                 status = slic_mcast_add_list(adapter, addresses);
1809                 if (status != 0)
1810                         break;
1811                 slic_mcast_set_bit(adapter, addresses);
1812         }
1813 
1814         if (adapter->devflags_prev != dev->flags) {
1815                 adapter->macopts = MAC_DIRECTED;
1816                 if (dev->flags) {
1817                         if (dev->flags & IFF_BROADCAST)
1818                                 adapter->macopts |= MAC_BCAST;
1819                         if (dev->flags & IFF_PROMISC)
1820                                 adapter->macopts |= MAC_PROMISC;
1821                         if (dev->flags & IFF_ALLMULTI)
1822                                 adapter->macopts |= MAC_ALLMCAST;
1823                         if (dev->flags & IFF_MULTICAST)
1824                                 adapter->macopts |= MAC_MCAST;
1825                 }
1826                 adapter->devflags_prev = dev->flags;
1827                 slic_config_set(adapter, true);
1828         } else {
1829                 if (status == 0)
1830                         slic_mcast_set_mask(adapter);
1831         }
1832 }
1833 
1834 #define  XMIT_FAIL_LINK_STATE               1
1835 #define  XMIT_FAIL_ZERO_LENGTH              2
1836 #define  XMIT_FAIL_HOSTCMD_FAIL             3
1837 
1838 static void slic_xmit_build_request(struct adapter *adapter,
1839                              struct slic_hostcmd *hcmd, struct sk_buff *skb)
1840 {
1841         struct slic_host64_cmd *ihcmd;
1842         ulong phys_addr;
1843 
1844         ihcmd = &hcmd->cmd64;
1845 
1846         ihcmd->flags = (adapter->port << IHFLG_IFSHFT);
1847         ihcmd->command = IHCMD_XMT_REQ;
1848         ihcmd->u.slic_buffers.totlen = skb->len;
1849         phys_addr = pci_map_single(adapter->pcidev, skb->data, skb->len,
1850                         PCI_DMA_TODEVICE);
1851         ihcmd->u.slic_buffers.bufs[0].paddrl = SLIC_GET_ADDR_LOW(phys_addr);
1852         ihcmd->u.slic_buffers.bufs[0].paddrh = SLIC_GET_ADDR_HIGH(phys_addr);
1853         ihcmd->u.slic_buffers.bufs[0].length = skb->len;
1854 #if BITS_PER_LONG == 64
1855         hcmd->cmdsize = (u32) ((((u64)&ihcmd->u.slic_buffers.bufs[1] -
1856                                      (u64) hcmd) + 31) >> 5);
1857 #else
1858         hcmd->cmdsize = ((((u32) &ihcmd->u.slic_buffers.bufs[1] -
1859                            (u32) hcmd) + 31) >> 5);
1860 #endif
1861 }
1862 
1863 static void slic_xmit_fail(struct adapter *adapter,
1864                     struct sk_buff *skb,
1865                     void *cmd, u32 skbtype, u32 status)
1866 {
1867         if (adapter->xmitq_full)
1868                 netif_stop_queue(adapter->netdev);
1869         if ((cmd == NULL) && (status <= XMIT_FAIL_HOSTCMD_FAIL)) {
1870                 switch (status) {
1871                 case XMIT_FAIL_LINK_STATE:
1872                         dev_err(&adapter->netdev->dev,
1873                                 "reject xmit skb[%p: %x] linkstate[%s] adapter[%s:%d] card[%s:%d]\n",
1874                                 skb, skb->pkt_type,
1875                                 SLIC_LINKSTATE(adapter->linkstate),
1876                                 SLIC_ADAPTER_STATE(adapter->state),
1877                                 adapter->state,
1878                                 SLIC_CARD_STATE(adapter->card->state),
1879                                 adapter->card->state);
1880                         break;
1881                 case XMIT_FAIL_ZERO_LENGTH:
1882                         dev_err(&adapter->netdev->dev,
1883                                 "xmit_start skb->len == 0 skb[%p] type[%x]\n",
1884                                 skb, skb->pkt_type);
1885                         break;
1886                 case XMIT_FAIL_HOSTCMD_FAIL:
1887                         dev_err(&adapter->netdev->dev,
1888                                 "xmit_start skb[%p] type[%x] No host commands available\n", skb, skb->pkt_type);
1889                         break;
1890                 }
1891         }
1892         dev_kfree_skb(skb);
1893         adapter->netdev->stats.tx_dropped++;
1894 }
1895 
1896 static void slic_rcv_handle_error(struct adapter *adapter,
1897                                         struct slic_rcvbuf *rcvbuf)
1898 {
1899         struct slic_hddr_wds *hdr = (struct slic_hddr_wds *)rcvbuf->data;
1900         struct net_device *netdev = adapter->netdev;
1901 
1902         if (adapter->devid != SLIC_1GB_DEVICE_ID) {
1903                 if (hdr->frame_status14 & VRHSTAT_802OE)
1904                         adapter->if_events.oflow802++;
1905                 if (hdr->frame_status14 & VRHSTAT_TPOFLO)
1906                         adapter->if_events.Tprtoflow++;
1907                 if (hdr->frame_status_b14 & VRHSTATB_802UE)
1908                         adapter->if_events.uflow802++;
1909                 if (hdr->frame_status_b14 & VRHSTATB_RCVE) {
1910                         adapter->if_events.rcvearly++;
1911                         netdev->stats.rx_fifo_errors++;
1912                 }
1913                 if (hdr->frame_status_b14 & VRHSTATB_BUFF) {
1914                         adapter->if_events.Bufov++;
1915                         netdev->stats.rx_over_errors++;
1916                 }
1917                 if (hdr->frame_status_b14 & VRHSTATB_CARRE) {
1918                         adapter->if_events.Carre++;
1919                         netdev->stats.tx_carrier_errors++;
1920                 }
1921                 if (hdr->frame_status_b14 & VRHSTATB_LONGE)
1922                         adapter->if_events.Longe++;
1923                 if (hdr->frame_status_b14 & VRHSTATB_PREA)
1924                         adapter->if_events.Invp++;
1925                 if (hdr->frame_status_b14 & VRHSTATB_CRC) {
1926                         adapter->if_events.Crc++;
1927                         netdev->stats.rx_crc_errors++;
1928                 }
1929                 if (hdr->frame_status_b14 & VRHSTATB_DRBL)
1930                         adapter->if_events.Drbl++;
1931                 if (hdr->frame_status_b14 & VRHSTATB_CODE)
1932                         adapter->if_events.Code++;
1933                 if (hdr->frame_status_b14 & VRHSTATB_TPCSUM)
1934                         adapter->if_events.TpCsum++;
1935                 if (hdr->frame_status_b14 & VRHSTATB_TPHLEN)
1936                         adapter->if_events.TpHlen++;
1937                 if (hdr->frame_status_b14 & VRHSTATB_IPCSUM)
1938                         adapter->if_events.IpCsum++;
1939                 if (hdr->frame_status_b14 & VRHSTATB_IPLERR)
1940                         adapter->if_events.IpLen++;
1941                 if (hdr->frame_status_b14 & VRHSTATB_IPHERR)
1942                         adapter->if_events.IpHlen++;
1943         } else {
1944                 if (hdr->frame_statusGB & VGBSTAT_XPERR) {
1945                         u32 xerr = hdr->frame_statusGB >> VGBSTAT_XERRSHFT;
1946 
1947                         if (xerr == VGBSTAT_XCSERR)
1948                                 adapter->if_events.TpCsum++;
1949                         if (xerr == VGBSTAT_XUFLOW)
1950                                 adapter->if_events.Tprtoflow++;
1951                         if (xerr == VGBSTAT_XHLEN)
1952                                 adapter->if_events.TpHlen++;
1953                 }
1954                 if (hdr->frame_statusGB & VGBSTAT_NETERR) {
1955                         u32 nerr =
1956                             (hdr->
1957                              frame_statusGB >> VGBSTAT_NERRSHFT) &
1958                             VGBSTAT_NERRMSK;
1959                         if (nerr == VGBSTAT_NCSERR)
1960                                 adapter->if_events.IpCsum++;
1961                         if (nerr == VGBSTAT_NUFLOW)
1962                                 adapter->if_events.IpLen++;
1963                         if (nerr == VGBSTAT_NHLEN)
1964                                 adapter->if_events.IpHlen++;
1965                 }
1966                 if (hdr->frame_statusGB & VGBSTAT_LNKERR) {
1967                         u32 lerr = hdr->frame_statusGB & VGBSTAT_LERRMSK;
1968 
1969                         if (lerr == VGBSTAT_LDEARLY)
1970                                 adapter->if_events.rcvearly++;
1971                         if (lerr == VGBSTAT_LBOFLO)
1972                                 adapter->if_events.Bufov++;
1973                         if (lerr == VGBSTAT_LCODERR)
1974                                 adapter->if_events.Code++;
1975                         if (lerr == VGBSTAT_LDBLNBL)
1976                                 adapter->if_events.Drbl++;
1977                         if (lerr == VGBSTAT_LCRCERR)
1978                                 adapter->if_events.Crc++;
1979                         if (lerr == VGBSTAT_LOFLO)
1980                                 adapter->if_events.oflow802++;
1981                         if (lerr == VGBSTAT_LUFLO)
1982                                 adapter->if_events.uflow802++;
1983                 }
1984         }
1985         return;
1986 }
1987 
1988 #define TCP_OFFLOAD_FRAME_PUSHFLAG  0x10000000
1989 #define M_FAST_PATH                 0x0040
1990 
1991 static void slic_rcv_handler(struct adapter *adapter)
1992 {
1993         struct net_device *netdev = adapter->netdev;
1994         struct sk_buff *skb;
1995         struct slic_rcvbuf *rcvbuf;
1996         u32 frames = 0;
1997 
1998         while ((skb = slic_rcvqueue_getnext(adapter))) {
1999                 u32 rx_bytes;
2000 
2001                 rcvbuf = (struct slic_rcvbuf *)skb->head;
2002                 adapter->card->events++;
2003                 if (rcvbuf->status & IRHDDR_ERR) {
2004                         adapter->rx_errors++;
2005                         slic_rcv_handle_error(adapter, rcvbuf);
2006                         slic_rcvqueue_reinsert(adapter, skb);
2007                         continue;
2008                 }
2009 
2010                 if (!slic_mac_filter(adapter, (struct ether_header *)
2011                                         rcvbuf->data)) {
2012                         slic_rcvqueue_reinsert(adapter, skb);
2013                         continue;
2014                 }
2015                 skb_pull(skb, SLIC_RCVBUF_HEADSIZE);
2016                 rx_bytes = (rcvbuf->length & IRHDDR_FLEN_MSK);
2017                 skb_put(skb, rx_bytes);
2018                 netdev->stats.rx_packets++;
2019                 netdev->stats.rx_bytes += rx_bytes;
2020 #if SLIC_OFFLOAD_IP_CHECKSUM
2021                 skb->ip_summed = CHECKSUM_UNNECESSARY;
2022 #endif
2023 
2024                 skb->dev = adapter->netdev;
2025                 skb->protocol = eth_type_trans(skb, skb->dev);
2026                 netif_rx(skb);
2027 
2028                 ++frames;
2029 #if SLIC_INTERRUPT_PROCESS_LIMIT
2030                 if (frames >= SLIC_RCVQ_MAX_PROCESS_ISR) {
2031                         adapter->rcv_interrupt_yields++;
2032                         break;
2033                 }
2034 #endif
2035         }
2036         adapter->max_isr_rcvs = max(adapter->max_isr_rcvs, frames);
2037 }
2038 
2039 static void slic_xmit_complete(struct adapter *adapter)
2040 {
2041         struct slic_hostcmd *hcmd;
2042         struct slic_rspbuf *rspbuf;
2043         u32 frames = 0;
2044         struct slic_handle_word slic_handle_word;
2045 
2046         do {
2047                 rspbuf = slic_rspqueue_getnext(adapter);
2048                 if (!rspbuf)
2049                         break;
2050                 adapter->xmit_completes++;
2051                 adapter->card->events++;
2052                 /*
2053                  Get the complete host command buffer
2054                 */
2055                 slic_handle_word.handle_token = rspbuf->hosthandle;
2056                 hcmd =
2057                     (struct slic_hostcmd *)
2058                         adapter->slic_handles[slic_handle_word.handle_index].
2059                                                                         address;
2060 /*      hcmd = (struct slic_hostcmd *) rspbuf->hosthandle; */
2061                 if (hcmd->type == SLIC_CMD_DUMB) {
2062                         if (hcmd->skb)
2063                                 dev_kfree_skb_irq(hcmd->skb);
2064                         slic_cmdq_putdone_irq(adapter, hcmd);
2065                 }
2066                 rspbuf->status = 0;
2067                 rspbuf->hosthandle = 0;
2068                 frames++;
2069         } while (1);
2070         adapter->max_isr_xmits = max(adapter->max_isr_xmits, frames);
2071 }
2072 
2073 static void slic_interrupt_card_up(u32 isr, struct adapter *adapter,
2074                         struct net_device *dev)
2075 {
2076         if (isr & ~ISR_IO) {
2077                 if (isr & ISR_ERR) {
2078                         adapter->error_interrupts++;
2079                         if (isr & ISR_RMISS) {
2080                                 int count;
2081                                 int pre_count;
2082                                 int errors;
2083 
2084                                 struct slic_rcvqueue *rcvq =
2085                                         &adapter->rcvqueue;
2086 
2087                                 adapter->error_rmiss_interrupts++;
2088 
2089                                 if (!rcvq->errors)
2090                                         rcv_count = rcvq->count;
2091                                 pre_count = rcvq->count;
2092                                 errors = rcvq->errors;
2093 
2094                                 while (rcvq->count < SLIC_RCVQ_FILLTHRESH) {
2095                                         count = slic_rcvqueue_fill(adapter);
2096                                         if (!count)
2097                                                 break;
2098                                 }
2099                         } else if (isr & ISR_XDROP) {
2100                                 dev_err(&dev->dev,
2101                                                 "isr & ISR_ERR [%x] ISR_XDROP\n", isr);
2102                         } else {
2103                                 dev_err(&dev->dev,
2104                                                 "isr & ISR_ERR [%x]\n",
2105                                                 isr);
2106                         }
2107                 }
2108 
2109                 if (isr & ISR_LEVENT) {
2110                         adapter->linkevent_interrupts++;
2111                         slic_link_event_handler(adapter);
2112                 }
2113 
2114                 if ((isr & ISR_UPC) || (isr & ISR_UPCERR) ||
2115                     (isr & ISR_UPCBSY)) {
2116                         adapter->upr_interrupts++;
2117                         slic_upr_request_complete(adapter, isr);
2118                 }
2119         }
2120 
2121         if (isr & ISR_RCV) {
2122                 adapter->rcv_interrupts++;
2123                 slic_rcv_handler(adapter);
2124         }
2125 
2126         if (isr & ISR_CMD) {
2127                 adapter->xmit_interrupts++;
2128                 slic_xmit_complete(adapter);
2129         }
2130 }
2131 
2132 
2133 static irqreturn_t slic_interrupt(int irq, void *dev_id)
2134 {
2135         struct net_device *dev = (struct net_device *)dev_id;
2136         struct adapter *adapter = netdev_priv(dev);
2137         u32 isr;
2138 
2139         if ((adapter->pshmem) && (adapter->pshmem->isr)) {
2140                 slic_reg32_write(&adapter->slic_regs->slic_icr,
2141                                  ICR_INT_MASK, FLUSH);
2142                 isr = adapter->isrcopy = adapter->pshmem->isr;
2143                 adapter->pshmem->isr = 0;
2144                 adapter->num_isrs++;
2145                 switch (adapter->card->state) {
2146                 case CARD_UP:
2147                         slic_interrupt_card_up(isr, adapter, dev);
2148                         break;
2149 
2150                 case CARD_DOWN:
2151                         if ((isr & ISR_UPC) ||
2152                             (isr & ISR_UPCERR) || (isr & ISR_UPCBSY)) {
2153                                 adapter->upr_interrupts++;
2154                                 slic_upr_request_complete(adapter, isr);
2155                         }
2156                         break;
2157                 }
2158 
2159                 adapter->isrcopy = 0;
2160                 adapter->all_reg_writes += 2;
2161                 adapter->isr_reg_writes++;
2162                 slic_reg32_write(&adapter->slic_regs->slic_isr, 0, FLUSH);
2163         } else {
2164                 adapter->false_interrupts++;
2165         }
2166         return IRQ_HANDLED;
2167 }
2168 
2169 #define NORMAL_ETHFRAME     0
2170 
2171 static netdev_tx_t slic_xmit_start(struct sk_buff *skb, struct net_device *dev)
2172 {
2173         struct sliccard *card;
2174         struct adapter *adapter = netdev_priv(dev);
2175         struct slic_hostcmd *hcmd = NULL;
2176         u32 status = 0;
2177         void *offloadcmd = NULL;
2178 
2179         card = adapter->card;
2180         if ((adapter->linkstate != LINK_UP) ||
2181             (adapter->state != ADAPT_UP) || (card->state != CARD_UP)) {
2182                 status = XMIT_FAIL_LINK_STATE;
2183                 goto xmit_fail;
2184 
2185         } else if (skb->len == 0) {
2186                 status = XMIT_FAIL_ZERO_LENGTH;
2187                 goto xmit_fail;
2188         }
2189 
2190         hcmd = slic_cmdq_getfree(adapter);
2191         if (!hcmd) {
2192                 adapter->xmitq_full = 1;
2193                 status = XMIT_FAIL_HOSTCMD_FAIL;
2194                 goto xmit_fail;
2195         }
2196         hcmd->skb = skb;
2197         hcmd->busy = 1;
2198         hcmd->type = SLIC_CMD_DUMB;
2199         slic_xmit_build_request(adapter, hcmd, skb);
2200         dev->stats.tx_packets++;
2201         dev->stats.tx_bytes += skb->len;
2202 
2203 #ifdef DEBUG_DUMP
2204         if (adapter->kill_card) {
2205                 struct slic_host64_cmd ihcmd;
2206 
2207                 ihcmd = &hcmd->cmd64;
2208 
2209                 ihcmd->flags |= 0x40;
2210                 adapter->kill_card = 0; /* only do this once */
2211         }
2212 #endif
2213         if (hcmd->paddrh == 0) {
2214                 slic_reg32_write(&adapter->slic_regs->slic_cbar,
2215                                  (hcmd->paddrl | hcmd->cmdsize), DONT_FLUSH);
2216         } else {
2217                 slic_reg64_write(adapter, &adapter->slic_regs->slic_cbar64,
2218                                  (hcmd->paddrl | hcmd->cmdsize),
2219                                  &adapter->slic_regs->slic_addr_upper,
2220                                  hcmd->paddrh, DONT_FLUSH);
2221         }
2222 xmit_done:
2223         return NETDEV_TX_OK;
2224 xmit_fail:
2225         slic_xmit_fail(adapter, skb, offloadcmd, NORMAL_ETHFRAME, status);
2226         goto xmit_done;
2227 }
2228 
2229 
2230 static void slic_adapter_freeresources(struct adapter *adapter)
2231 {
2232         slic_init_cleanup(adapter);
2233         adapter->error_interrupts = 0;
2234         adapter->rcv_interrupts = 0;
2235         adapter->xmit_interrupts = 0;
2236         adapter->linkevent_interrupts = 0;
2237         adapter->upr_interrupts = 0;
2238         adapter->num_isrs = 0;
2239         adapter->xmit_completes = 0;
2240         adapter->rcv_broadcasts = 0;
2241         adapter->rcv_multicasts = 0;
2242         adapter->rcv_unicasts = 0;
2243 }
2244 
2245 static int slic_adapter_allocresources(struct adapter *adapter)
2246 {
2247         if (!adapter->intrregistered) {
2248                 int retval;
2249 
2250                 spin_unlock_irqrestore(&slic_global.driver_lock.lock,
2251                                         slic_global.driver_lock.flags);
2252 
2253                 retval = request_irq(adapter->netdev->irq,
2254                                      &slic_interrupt,
2255                                      IRQF_SHARED,
2256                                      adapter->netdev->name, adapter->netdev);
2257 
2258                 spin_lock_irqsave(&slic_global.driver_lock.lock,
2259                                         slic_global.driver_lock.flags);
2260 
2261                 if (retval) {
2262                         dev_err(&adapter->netdev->dev,
2263                                 "request_irq (%s) FAILED [%x]\n",
2264                                 adapter->netdev->name, retval);
2265                         return retval;
2266                 }
2267                 adapter->intrregistered = 1;
2268         }
2269         return 0;
2270 }
2271 
2272 /*
2273  *  slic_if_init
2274  *
2275  *  Perform initialization of our slic interface.
2276  *
2277  */
2278 static int slic_if_init(struct adapter *adapter)
2279 {
2280         struct sliccard *card = adapter->card;
2281         struct net_device *dev = adapter->netdev;
2282         __iomem struct slic_regs *slic_regs = adapter->slic_regs;
2283         struct slic_shmem *pshmem;
2284         int rc;
2285 
2286         /* adapter should be down at this point */
2287         if (adapter->state != ADAPT_DOWN) {
2288                 dev_err(&dev->dev, "%s: adapter->state != ADAPT_DOWN\n",
2289                         __func__);
2290                 rc = -EIO;
2291                 goto err;
2292         }
2293 
2294         adapter->devflags_prev = dev->flags;
2295         adapter->macopts = MAC_DIRECTED;
2296         if (dev->flags) {
2297                 if (dev->flags & IFF_BROADCAST)
2298                         adapter->macopts |= MAC_BCAST;
2299                 if (dev->flags & IFF_PROMISC)
2300                         adapter->macopts |= MAC_PROMISC;
2301                 if (dev->flags & IFF_ALLMULTI)
2302                         adapter->macopts |= MAC_ALLMCAST;
2303                 if (dev->flags & IFF_MULTICAST)
2304                         adapter->macopts |= MAC_MCAST;
2305         }
2306         rc = slic_adapter_allocresources(adapter);
2307         if (rc) {
2308                 dev_err(&dev->dev,
2309                         "%s: slic_adapter_allocresources FAILED %x\n",
2310                         __func__, rc);
2311                 slic_adapter_freeresources(adapter);
2312                 goto err;
2313         }
2314 
2315         if (!adapter->queues_initialized) {
2316                 rc = slic_rspqueue_init(adapter);
2317                 if (rc)
2318                         goto err;
2319                 rc = slic_cmdq_init(adapter);
2320                 if (rc)
2321                         goto err;
2322                 rc = slic_rcvqueue_init(adapter);
2323                 if (rc)
2324                         goto err;
2325                 adapter->queues_initialized = 1;
2326         }
2327 
2328         slic_reg32_write(&slic_regs->slic_icr, ICR_INT_OFF, FLUSH);
2329         mdelay(1);
2330 
2331         if (!adapter->isp_initialized) {
2332                 pshmem = (struct slic_shmem *)(unsigned long)
2333                          adapter->phys_shmem;
2334 
2335                 spin_lock_irqsave(&adapter->bit64reglock.lock,
2336                                         adapter->bit64reglock.flags);
2337 
2338 #if BITS_PER_LONG == 64
2339                 slic_reg32_write(&slic_regs->slic_addr_upper,
2340                                  SLIC_GET_ADDR_HIGH(&pshmem->isr), DONT_FLUSH);
2341                 slic_reg32_write(&slic_regs->slic_isp,
2342                                  SLIC_GET_ADDR_LOW(&pshmem->isr), FLUSH);
2343 #else
2344                 slic_reg32_write(&slic_regs->slic_addr_upper, 0, DONT_FLUSH);
2345                 slic_reg32_write(&slic_regs->slic_isp, (u32)&pshmem->isr, FLUSH);
2346 #endif
2347                 spin_unlock_irqrestore(&adapter->bit64reglock.lock,
2348                                         adapter->bit64reglock.flags);
2349                 adapter->isp_initialized = 1;
2350         }
2351 
2352         adapter->state = ADAPT_UP;
2353         if (!card->loadtimerset) {
2354                 init_timer(&card->loadtimer);
2355                 card->loadtimer.expires =
2356                     jiffies + (SLIC_LOADTIMER_PERIOD * HZ);
2357                 card->loadtimer.data = (ulong) card;
2358                 card->loadtimer.function = &slic_timer_load_check;
2359                 add_timer(&card->loadtimer);
2360 
2361                 card->loadtimerset = 1;
2362         }
2363 
2364         if (!adapter->pingtimerset) {
2365                 init_timer(&adapter->pingtimer);
2366                 adapter->pingtimer.expires =
2367                     jiffies + (PING_TIMER_INTERVAL * HZ);
2368                 adapter->pingtimer.data = (ulong) dev;
2369                 adapter->pingtimer.function = &slic_timer_ping;
2370                 add_timer(&adapter->pingtimer);
2371                 adapter->pingtimerset = 1;
2372                 adapter->card->pingstatus = ISR_PINGMASK;
2373         }
2374 
2375         /*
2376          *    clear any pending events, then enable interrupts
2377          */
2378         adapter->isrcopy = 0;
2379         adapter->pshmem->isr = 0;
2380         slic_reg32_write(&slic_regs->slic_isr, 0, FLUSH);
2381         slic_reg32_write(&slic_regs->slic_icr, ICR_INT_ON, FLUSH);
2382 
2383         slic_link_config(adapter, LINK_AUTOSPEED, LINK_AUTOD);
2384         slic_link_event_handler(adapter);
2385 
2386 err:
2387         return rc;
2388 }
2389 
2390 static int slic_entry_open(struct net_device *dev)
2391 {
2392         struct adapter *adapter = netdev_priv(dev);
2393         struct sliccard *card = adapter->card;
2394         int status;
2395 
2396         netif_stop_queue(adapter->netdev);
2397 
2398         spin_lock_irqsave(&slic_global.driver_lock.lock,
2399                                 slic_global.driver_lock.flags);
2400         if (!adapter->activated) {
2401                 card->adapters_activated++;
2402                 slic_global.num_slic_ports_active++;
2403                 adapter->activated = 1;
2404         }
2405         status = slic_if_init(adapter);
2406 
2407         if (status != 0) {
2408                 if (adapter->activated) {
2409                         card->adapters_activated--;
2410                         slic_global.num_slic_ports_active--;
2411                         adapter->activated = 0;
2412                 }
2413                 goto spin_unlock;
2414         }
2415         if (!card->master)
2416                 card->master = adapter;
2417 
2418 spin_unlock:
2419         spin_unlock_irqrestore(&slic_global.driver_lock.lock,
2420                                slic_global.driver_lock.flags);
2421         return status;
2422 }
2423 
2424 static void slic_card_cleanup(struct sliccard *card)
2425 {
2426         if (card->loadtimerset) {
2427                 card->loadtimerset = 0;
2428                 del_timer_sync(&card->loadtimer);
2429         }
2430 
2431         kfree(card);
2432 }
2433 
2434 static void slic_entry_remove(struct pci_dev *pcidev)
2435 {
2436         struct net_device *dev = pci_get_drvdata(pcidev);
2437         struct adapter *adapter = netdev_priv(dev);
2438         struct sliccard *card;
2439         struct mcast_address *mcaddr, *mlist;
2440 
2441         unregister_netdev(dev);
2442 
2443         slic_adapter_freeresources(adapter);
2444         slic_unmap_mmio_space(adapter);
2445 
2446         /* free multicast addresses */
2447         mlist = adapter->mcastaddrs;
2448         while (mlist) {
2449                 mcaddr = mlist;
2450                 mlist = mlist->next;
2451                 kfree(mcaddr);
2452         }
2453         card = adapter->card;
2454         card->adapters_allocated--;
2455         adapter->allocated = 0;
2456         if (!card->adapters_allocated) {
2457                 struct sliccard *curr_card = slic_global.slic_card;
2458                 if (curr_card == card) {
2459                         slic_global.slic_card = card->next;
2460                 } else {
2461                         while (curr_card->next != card)
2462                                 curr_card = curr_card->next;
2463                         curr_card->next = card->next;
2464                 }
2465                 slic_global.num_slic_cards--;
2466                 slic_card_cleanup(card);
2467         }
2468         free_netdev(dev);
2469         pci_release_regions(pcidev);
2470         pci_disable_device(pcidev);
2471 }
2472 
2473 static int slic_entry_halt(struct net_device *dev)
2474 {
2475         struct adapter *adapter = netdev_priv(dev);
2476         struct sliccard *card = adapter->card;
2477         __iomem struct slic_regs *slic_regs = adapter->slic_regs;
2478 
2479         spin_lock_irqsave(&slic_global.driver_lock.lock,
2480                                 slic_global.driver_lock.flags);
2481         netif_stop_queue(adapter->netdev);
2482         adapter->state = ADAPT_DOWN;
2483         adapter->linkstate = LINK_DOWN;
2484         adapter->upr_list = NULL;
2485         adapter->upr_busy = 0;
2486         adapter->devflags_prev = 0;
2487         slic_reg32_write(&slic_regs->slic_icr, ICR_INT_OFF, FLUSH);
2488         adapter->all_reg_writes++;
2489         adapter->icr_reg_writes++;
2490         slic_config_clear(adapter);
2491         if (adapter->activated) {
2492                 card->adapters_activated--;
2493                 slic_global.num_slic_ports_active--;
2494                 adapter->activated = 0;
2495         }
2496 #ifdef AUTOMATIC_RESET
2497         slic_reg32_write(&slic_regs->slic_reset_iface, 0, FLUSH);
2498 #endif
2499         /*
2500          *  Reset the adapter's cmd queues
2501          */
2502         slic_cmdq_reset(adapter);
2503 
2504 #ifdef AUTOMATIC_RESET
2505         if (!card->adapters_activated)
2506                 slic_card_init(card, adapter);
2507 #endif
2508 
2509         spin_unlock_irqrestore(&slic_global.driver_lock.lock,
2510                                 slic_global.driver_lock.flags);
2511         return 0;
2512 }
2513 
2514 static struct net_device_stats *slic_get_stats(struct net_device *dev)
2515 {
2516         struct adapter *adapter = netdev_priv(dev);
2517 
2518         dev->stats.collisions = adapter->slic_stats.iface.xmit_collisions;
2519         dev->stats.rx_errors = adapter->slic_stats.iface.rcv_errors;
2520         dev->stats.tx_errors = adapter->slic_stats.iface.xmt_errors;
2521         dev->stats.rx_missed_errors = adapter->slic_stats.iface.rcv_discards;
2522         dev->stats.tx_heartbeat_errors = 0;
2523         dev->stats.tx_aborted_errors = 0;
2524         dev->stats.tx_window_errors = 0;
2525         dev->stats.tx_fifo_errors = 0;
2526         dev->stats.rx_frame_errors = 0;
2527         dev->stats.rx_length_errors = 0;
2528 
2529         return &dev->stats;
2530 }
2531 
2532 static int slic_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
2533 {
2534         struct adapter *adapter = netdev_priv(dev);
2535         struct ethtool_cmd edata;
2536         struct ethtool_cmd ecmd;
2537         u32 data[7];
2538         u32 intagg;
2539 
2540         switch (cmd) {
2541         case SIOCSLICSETINTAGG:
2542                 if (copy_from_user(data, rq->ifr_data, 28))
2543                         return -EFAULT;
2544                 intagg = data[0];
2545                 dev_err(&dev->dev, "%s: set interrupt aggregation to %d\n",
2546                         __func__, intagg);
2547                 slic_intagg_set(adapter, intagg);
2548                 return 0;
2549 
2550 #ifdef SLIC_TRACE_DUMP_ENABLED
2551         case SIOCSLICTRACEDUMP:
2552                 {
2553                         u32 value;
2554                         DBG_IOCTL("slic_ioctl  SIOCSLIC_TRACE_DUMP\n");
2555 
2556                         if (copy_from_user(data, rq->ifr_data, 28)) {
2557                                 PRINT_ERROR
2558                                     ("slic: copy_from_user FAILED getting initial simba param\n");
2559                                 return -EFAULT;
2560                         }
2561 
2562                         value = data[0];
2563                         if (tracemon_request == SLIC_DUMP_DONE) {
2564                                 PRINT_ERROR
2565                                     ("ATK Diagnostic Trace Dump Requested\n");
2566                                 tracemon_request = SLIC_DUMP_REQUESTED;
2567                                 tracemon_request_type = value;
2568                                 tracemon_timestamp = jiffies;
2569                         } else if ((tracemon_request == SLIC_DUMP_REQUESTED) ||
2570                                    (tracemon_request ==
2571                                     SLIC_DUMP_IN_PROGRESS)) {
2572                                 PRINT_ERROR
2573                                     ("ATK Diagnostic Trace Dump Requested but already in progress... ignore\n");
2574                         } else {
2575                                 PRINT_ERROR
2576                                     ("ATK Diagnostic Trace Dump Requested\n");
2577                                 tracemon_request = SLIC_DUMP_REQUESTED;
2578                                 tracemon_request_type = value;
2579                                 tracemon_timestamp = jiffies;
2580                         }
2581                         return 0;
2582                 }
2583 #endif
2584         case SIOCETHTOOL:
2585                 if (copy_from_user(&ecmd, rq->ifr_data, sizeof(ecmd)))
2586                         return -EFAULT;
2587 
2588                 if (ecmd.cmd == ETHTOOL_GSET) {
2589                         memset(&edata, 0, sizeof(edata));
2590                         edata.supported = (SUPPORTED_10baseT_Half |
2591                                            SUPPORTED_10baseT_Full |
2592                                            SUPPORTED_100baseT_Half |
2593                                            SUPPORTED_100baseT_Full |
2594                                            SUPPORTED_Autoneg | SUPPORTED_MII);
2595                         edata.port = PORT_MII;
2596                         edata.transceiver = XCVR_INTERNAL;
2597                         edata.phy_address = 0;
2598                         if (adapter->linkspeed == LINK_100MB)
2599                                 edata.speed = SPEED_100;
2600                         else if (adapter->linkspeed == LINK_10MB)
2601                                 edata.speed = SPEED_10;
2602                         else
2603                                 edata.speed = 0;
2604 
2605                         if (adapter->linkduplex == LINK_FULLD)
2606                                 edata.duplex = DUPLEX_FULL;
2607                         else
2608                                 edata.duplex = DUPLEX_HALF;
2609 
2610                         edata.autoneg = AUTONEG_ENABLE;
2611                         edata.maxtxpkt = 1;
2612                         edata.maxrxpkt = 1;
2613                         if (copy_to_user(rq->ifr_data, &edata, sizeof(edata)))
2614                                 return -EFAULT;
2615 
2616                 } else if (ecmd.cmd == ETHTOOL_SSET) {
2617                         if (!capable(CAP_NET_ADMIN))
2618                                 return -EPERM;
2619 
2620                         if (adapter->linkspeed == LINK_100MB)
2621                                 edata.speed = SPEED_100;
2622                         else if (adapter->linkspeed == LINK_10MB)
2623                                 edata.speed = SPEED_10;
2624                         else
2625                                 edata.speed = 0;
2626 
2627                         if (adapter->linkduplex == LINK_FULLD)
2628                                 edata.duplex = DUPLEX_FULL;
2629                         else
2630                                 edata.duplex = DUPLEX_HALF;
2631 
2632                         edata.autoneg = AUTONEG_ENABLE;
2633                         edata.maxtxpkt = 1;
2634                         edata.maxrxpkt = 1;
2635                         if ((ecmd.speed != edata.speed) ||
2636                             (ecmd.duplex != edata.duplex)) {
2637                                 u32 speed;
2638                                 u32 duplex;
2639 
2640                                 if (ecmd.speed == SPEED_10)
2641                                         speed = 0;
2642                                 else
2643                                         speed = PCR_SPEED_100;
2644                                 if (ecmd.duplex == DUPLEX_FULL)
2645                                         duplex = PCR_DUPLEX_FULL;
2646                                 else
2647                                         duplex = 0;
2648                                 slic_link_config(adapter, speed, duplex);
2649                                 slic_link_event_handler(adapter);
2650                         }
2651                 }
2652                 return 0;
2653         default:
2654                 return -EOPNOTSUPP;
2655         }
2656 }
2657 
2658 static void slic_config_pci(struct pci_dev *pcidev)
2659 {
2660         u16 pci_command;
2661         u16 new_command;
2662 
2663         pci_read_config_word(pcidev, PCI_COMMAND, &pci_command);
2664 
2665         new_command = pci_command | PCI_COMMAND_MASTER
2666             | PCI_COMMAND_MEMORY
2667             | PCI_COMMAND_INVALIDATE
2668             | PCI_COMMAND_PARITY | PCI_COMMAND_SERR | PCI_COMMAND_FAST_BACK;
2669         if (pci_command != new_command)
2670                 pci_write_config_word(pcidev, PCI_COMMAND, new_command);
2671 }
2672 
2673 static int slic_card_init(struct sliccard *card, struct adapter *adapter)
2674 {
2675         __iomem struct slic_regs *slic_regs = adapter->slic_regs;
2676         struct slic_eeprom *peeprom;
2677         struct oslic_eeprom *pOeeprom;
2678         dma_addr_t phys_config;
2679         u32 phys_configh;
2680         u32 phys_configl;
2681         u32 i = 0;
2682         struct slic_shmem *pshmem;
2683         int status;
2684         uint macaddrs = card->card_size;
2685         ushort eecodesize;
2686         ushort dramsize;
2687         ushort ee_chksum;
2688         ushort calc_chksum;
2689         struct slic_config_mac *pmac;
2690         unsigned char fruformat;
2691         unsigned char oemfruformat;
2692         struct atk_fru *patkfru;
2693         union oemfru *poemfru;
2694 
2695         /* Reset everything except PCI configuration space */
2696         slic_soft_reset(adapter);
2697 
2698         /* Download the microcode */
2699         status = slic_card_download(adapter);
2700         if (status)
2701                 return status;
2702 
2703         if (!card->config_set) {
2704                 peeprom = pci_alloc_consistent(adapter->pcidev,
2705                                                sizeof(struct slic_eeprom),
2706                                                &phys_config);
2707 
2708                 phys_configl = SLIC_GET_ADDR_LOW(phys_config);
2709                 phys_configh = SLIC_GET_ADDR_HIGH(phys_config);
2710 
2711                 if (!peeprom) {
2712                         dev_err(&adapter->pcidev->dev,
2713                                 "Failed to allocate DMA memory for EEPROM.\n");
2714                         return -ENOMEM;
2715                 }
2716 
2717                 memset(peeprom, 0, sizeof(struct slic_eeprom));
2718 
2719                 slic_reg32_write(&slic_regs->slic_icr, ICR_INT_OFF, FLUSH);
2720                 mdelay(1);
2721                 pshmem = (struct slic_shmem *)(unsigned long)
2722                          adapter->phys_shmem;
2723 
2724                 spin_lock_irqsave(&adapter->bit64reglock.lock,
2725                                         adapter->bit64reglock.flags);
2726                 slic_reg32_write(&slic_regs->slic_addr_upper,
2727                                  SLIC_GET_ADDR_HIGH(&pshmem->isr), DONT_FLUSH);
2728                 slic_reg32_write(&slic_regs->slic_isp,
2729                                  SLIC_GET_ADDR_LOW(&pshmem->isr), FLUSH);
2730                 spin_unlock_irqrestore(&adapter->bit64reglock.lock,
2731                                         adapter->bit64reglock.flags);
2732 
2733                 status = slic_config_get(adapter, phys_configl, phys_configh);
2734                 if (status) {
2735                         dev_err(&adapter->pcidev->dev,
2736                                 "Failed to fetch config data from device.\n");
2737                         goto card_init_err;
2738                 }
2739 
2740                 for (;;) {
2741                         if (adapter->pshmem->isr) {
2742                                 if (adapter->pshmem->isr & ISR_UPC) {
2743                                         adapter->pshmem->isr = 0;
2744                                         slic_reg64_write(adapter,
2745                                                 &slic_regs->slic_isp, 0,
2746                                                 &slic_regs->slic_addr_upper,
2747                                                 0, FLUSH);
2748                                         slic_reg32_write(&slic_regs->slic_isr,
2749                                                          0, FLUSH);
2750 
2751                                         slic_upr_request_complete(adapter, 0);
2752                                         break;
2753                                 }
2754 
2755                                 adapter->pshmem->isr = 0;
2756                                 slic_reg32_write(&slic_regs->slic_isr,
2757                                                  0, FLUSH);
2758                         } else {
2759                                 mdelay(1);
2760                                 i++;
2761                                 if (i > 5000) {
2762                                         dev_err(&adapter->pcidev->dev,
2763                                                 "Fetch of config data timed out.\n");
2764                                         slic_reg64_write(adapter,
2765                                                 &slic_regs->slic_isp, 0,
2766                                                 &slic_regs->slic_addr_upper,
2767                                                 0, FLUSH);
2768                                         status = -EINVAL;
2769                                         goto card_init_err;
2770                                 }
2771                         }
2772                 }
2773 
2774                 switch (adapter->devid) {
2775                 /* Oasis card */
2776                 case SLIC_2GB_DEVICE_ID:
2777                         /* extract EEPROM data and pointers to EEPROM data */
2778                         pOeeprom = (struct oslic_eeprom *) peeprom;
2779                         eecodesize = pOeeprom->EecodeSize;
2780                         dramsize = pOeeprom->DramSize;
2781                         pmac = pOeeprom->MacInfo;
2782                         fruformat = pOeeprom->FruFormat;
2783                         patkfru = &pOeeprom->AtkFru;
2784                         oemfruformat = pOeeprom->OemFruFormat;
2785                         poemfru = &pOeeprom->OemFru;
2786                         macaddrs = 2;
2787                         /* Minor kludge for Oasis card
2788                              get 2 MAC addresses from the
2789                              EEPROM to ensure that function 1
2790                              gets the Port 1 MAC address */
2791                         break;
2792                 default:
2793                         /* extract EEPROM data and pointers to EEPROM data */
2794                         eecodesize = peeprom->EecodeSize;
2795                         dramsize = peeprom->DramSize;
2796                         pmac = peeprom->u2.mac.MacInfo;
2797                         fruformat = peeprom->FruFormat;
2798                         patkfru = &peeprom->AtkFru;
2799                         oemfruformat = peeprom->OemFruFormat;
2800                         poemfru = &peeprom->OemFru;
2801                         break;
2802                 }
2803 
2804                 card->config.EepromValid = false;
2805 
2806                 /*  see if the EEPROM is valid by checking it's checksum */
2807                 if ((eecodesize <= MAX_EECODE_SIZE) &&
2808                     (eecodesize >= MIN_EECODE_SIZE)) {
2809 
2810                         ee_chksum =
2811                             *(u16 *) ((char *) peeprom + (eecodesize - 2));
2812                         /*
2813                             calculate the EEPROM checksum
2814                         */
2815                         calc_chksum = slic_eeprom_cksum(peeprom,
2816                                                         eecodesize - 2);
2817                         /*
2818                             if the ucdoe chksum flag bit worked,
2819                             we wouldn't need this
2820                         */
2821                         if (ee_chksum == calc_chksum)
2822                                 card->config.EepromValid = true;
2823                 }
2824                 /*  copy in the DRAM size */
2825                 card->config.DramSize = dramsize;
2826 
2827                 /*  copy in the MAC address(es) */
2828                 for (i = 0; i < macaddrs; i++) {
2829                         memcpy(&card->config.MacInfo[i],
2830                                &pmac[i], sizeof(struct slic_config_mac));
2831                 }
2832 
2833                 /*  copy the Alacritech FRU information */
2834                 card->config.FruFormat = fruformat;
2835                 memcpy(&card->config.AtkFru, patkfru,
2836                                                 sizeof(struct atk_fru));
2837 
2838                 pci_free_consistent(adapter->pcidev,
2839                                     sizeof(struct slic_eeprom),
2840                                     peeprom, phys_config);
2841 
2842                 if (!card->config.EepromValid) {
2843                         slic_reg64_write(adapter, &slic_regs->slic_isp, 0,
2844                                          &slic_regs->slic_addr_upper,
2845                                          0, FLUSH);
2846                         dev_err(&adapter->pcidev->dev, "EEPROM invalid.\n");
2847                         return -EINVAL;
2848                 }
2849 
2850                 card->config_set = 1;
2851         }
2852 
2853         status = slic_card_download_gbrcv(adapter);
2854         if (status)
2855                 return status;
2856 
2857         if (slic_global.dynamic_intagg)
2858                 slic_intagg_set(adapter, 0);
2859         else
2860                 slic_intagg_set(adapter, intagg_delay);
2861 
2862         /*
2863          *  Initialize ping status to "ok"
2864          */
2865         card->pingstatus = ISR_PINGMASK;
2866 
2867         /*
2868          * Lastly, mark our card state as up and return success
2869          */
2870         card->state = CARD_UP;
2871         card->reset_in_progress = 0;
2872 
2873         return 0;
2874 
2875 card_init_err:
2876         pci_free_consistent(adapter->pcidev, sizeof(struct slic_eeprom),
2877                             peeprom, phys_config);
2878         return status;
2879 }
2880 
2881 static void slic_init_driver(void)
2882 {
2883         if (slic_first_init) {
2884                 slic_first_init = 0;
2885                 spin_lock_init(&slic_global.driver_lock.lock);
2886         }
2887 }
2888 
2889 static void slic_init_adapter(struct net_device *netdev,
2890                               struct pci_dev *pcidev,
2891                               const struct pci_device_id *pci_tbl_entry,
2892                               void __iomem *memaddr, int chip_idx)
2893 {
2894         ushort index;
2895         struct slic_handle *pslic_handle;
2896         struct adapter *adapter = netdev_priv(netdev);
2897 
2898 /*      adapter->pcidev = pcidev;*/
2899         adapter->vendid = pci_tbl_entry->vendor;
2900         adapter->devid = pci_tbl_entry->device;
2901         adapter->subsysid = pci_tbl_entry->subdevice;
2902         adapter->busnumber = pcidev->bus->number;
2903         adapter->slotnumber = ((pcidev->devfn >> 3) & 0x1F);
2904         adapter->functionnumber = (pcidev->devfn & 0x7);
2905         adapter->slic_regs = (__iomem struct slic_regs *)memaddr;
2906         adapter->irq = pcidev->irq;
2907 /*      adapter->netdev = netdev;*/
2908         adapter->chipid = chip_idx;
2909         adapter->port = 0;      /*adapter->functionnumber;*/
2910         adapter->cardindex = adapter->port;
2911         spin_lock_init(&adapter->upr_lock.lock);
2912         spin_lock_init(&adapter->bit64reglock.lock);
2913         spin_lock_init(&adapter->adapter_lock.lock);
2914         spin_lock_init(&adapter->reset_lock.lock);
2915         spin_lock_init(&adapter->handle_lock.lock);
2916 
2917         adapter->card_size = 1;
2918         /*
2919           Initialize slic_handle array
2920         */
2921         /*
2922          Start with 1.  0 is an invalid host handle.
2923         */
2924         for (index = 1, pslic_handle = &adapter->slic_handles[1];
2925              index < SLIC_CMDQ_MAXCMDS; index++, pslic_handle++) {
2926 
2927                 pslic_handle->token.handle_index = index;
2928                 pslic_handle->type = SLIC_HANDLE_FREE;
2929                 pslic_handle->next = adapter->pfree_slic_handles;
2930                 adapter->pfree_slic_handles = pslic_handle;
2931         }
2932         adapter->pshmem = (struct slic_shmem *)
2933                                         pci_alloc_consistent(adapter->pcidev,
2934                                         sizeof(struct slic_shmem),
2935                                         &adapter->
2936                                         phys_shmem);
2937         if (adapter->pshmem)
2938                 memset(adapter->pshmem, 0, sizeof(struct slic_shmem));
2939 }
2940 
2941 static const struct net_device_ops slic_netdev_ops = {
2942         .ndo_open               = slic_entry_open,
2943         .ndo_stop               = slic_entry_halt,
2944         .ndo_start_xmit         = slic_xmit_start,
2945         .ndo_do_ioctl           = slic_ioctl,
2946         .ndo_set_mac_address    = slic_mac_set_address,
2947         .ndo_get_stats          = slic_get_stats,
2948         .ndo_set_rx_mode        = slic_mcast_set_list,
2949         .ndo_validate_addr      = eth_validate_addr,
2950         .ndo_change_mtu         = eth_change_mtu,
2951 };
2952 
2953 static u32 slic_card_locate(struct adapter *adapter)
2954 {
2955         struct sliccard *card = slic_global.slic_card;
2956         struct physcard *physcard = slic_global.phys_card;
2957         ushort card_hostid;
2958         u16 __iomem *hostid_reg;
2959         uint i;
2960         uint rdhostid_offset = 0;
2961 
2962         switch (adapter->devid) {
2963         case SLIC_2GB_DEVICE_ID:
2964                 rdhostid_offset = SLIC_RDHOSTID_2GB;
2965                 break;
2966         case SLIC_1GB_DEVICE_ID:
2967                 rdhostid_offset = SLIC_RDHOSTID_1GB;
2968                 break;
2969         default:
2970                 return -ENODEV;
2971         }
2972 
2973         hostid_reg =
2974             (u16 __iomem *) (((u8 __iomem *) (adapter->slic_regs)) +
2975             rdhostid_offset);
2976 
2977         /* read the 16 bit hostid from SRAM */
2978         card_hostid = (ushort) readw(hostid_reg);
2979 
2980         /* Initialize a new card structure if need be */
2981         if (card_hostid == SLIC_HOSTID_DEFAULT) {
2982                 card = kzalloc(sizeof(struct sliccard), GFP_KERNEL);
2983                 if (card == NULL)
2984                         return -ENOMEM;
2985 
2986                 card->next = slic_global.slic_card;
2987                 slic_global.slic_card = card;
2988                 card->busnumber = adapter->busnumber;
2989                 card->slotnumber = adapter->slotnumber;
2990 
2991                 /* Find an available cardnum */
2992                 for (i = 0; i < SLIC_MAX_CARDS; i++) {
2993                         if (slic_global.cardnuminuse[i] == 0) {
2994                                 slic_global.cardnuminuse[i] = 1;
2995                                 card->cardnum = i;
2996                                 break;
2997                         }
2998                 }
2999                 slic_global.num_slic_cards++;
3000         } else {
3001                 /* Card exists, find the card this adapter belongs to */
3002                 while (card) {
3003                         if (card->cardnum == card_hostid)
3004                                 break;
3005                         card = card->next;
3006                 }
3007         }
3008 
3009         if (!card)
3010                 return -ENXIO;
3011         /* Put the adapter in the card's adapter list */
3012         if (!card->adapter[adapter->port]) {
3013                 card->adapter[adapter->port] = adapter;
3014                 adapter->card = card;
3015         }
3016 
3017         card->card_size = 1;    /* one port per *logical* card */
3018 
3019         while (physcard) {
3020                 for (i = 0; i < SLIC_MAX_PORTS; i++) {
3021                         if (physcard->adapter[i])
3022                                 break;
3023                 }
3024                 if (i == SLIC_MAX_PORTS)
3025                         break;
3026 
3027                 if (physcard->adapter[i]->slotnumber == adapter->slotnumber)
3028                         break;
3029                 physcard = physcard->next;
3030         }
3031         if (!physcard) {
3032                 /* no structure allocated for this physical card yet */
3033                 physcard = kzalloc(sizeof(struct physcard), GFP_ATOMIC);
3034                 if (!physcard) {
3035                         if (card_hostid == SLIC_HOSTID_DEFAULT)
3036                                 kfree(card);
3037                         return -ENOMEM;
3038                 }
3039 
3040                 physcard->next = slic_global.phys_card;
3041                 slic_global.phys_card = physcard;
3042                 physcard->adapters_allocd = 1;
3043         } else {
3044                 physcard->adapters_allocd++;
3045         }
3046         /* Note - this is ZERO relative */
3047         adapter->physport = physcard->adapters_allocd - 1;
3048 
3049         physcard->adapter[adapter->physport] = adapter;
3050         adapter->physcard = physcard;
3051 
3052         return 0;
3053 }
3054 
3055 static int slic_entry_probe(struct pci_dev *pcidev,
3056                                const struct pci_device_id *pci_tbl_entry)
3057 {
3058         static int cards_found;
3059         static int did_version;
3060         int err = -ENODEV;
3061         struct net_device *netdev;
3062         struct adapter *adapter;
3063         void __iomem *memmapped_ioaddr = NULL;
3064         ulong mmio_start = 0;
3065         ulong mmio_len = 0;
3066         struct sliccard *card = NULL;
3067         int pci_using_dac = 0;
3068 
3069         slic_global.dynamic_intagg = dynamic_intagg;
3070 
3071         err = pci_enable_device(pcidev);
3072 
3073         if (err)
3074                 return err;
3075 
3076         if (did_version++ == 0) {
3077                 dev_info(&pcidev->dev, "%s\n", slic_banner);
3078                 dev_info(&pcidev->dev, "%s\n", slic_proc_version);
3079         }
3080 
3081         if (!pci_set_dma_mask(pcidev, DMA_BIT_MASK(64))) {
3082                 pci_using_dac = 1;
3083                 err = pci_set_consistent_dma_mask(pcidev, DMA_BIT_MASK(64));
3084                 if (err) {
3085                         dev_err(&pcidev->dev, "unable to obtain 64-bit DMA for consistent allocations\n");
3086                         goto err_out_disable_pci;
3087                 }
3088         } else {
3089                 err = pci_set_dma_mask(pcidev, DMA_BIT_MASK(32));
3090                 if (err) {
3091                         dev_err(&pcidev->dev, "no usable DMA configuration\n");
3092                         goto err_out_disable_pci;
3093                 }
3094                 pci_using_dac = 0;
3095                 pci_set_consistent_dma_mask(pcidev, DMA_BIT_MASK(32));
3096         }
3097 
3098         err = pci_request_regions(pcidev, DRV_NAME);
3099         if (err) {
3100                 dev_err(&pcidev->dev, "can't obtain PCI resources\n");
3101                 goto err_out_disable_pci;
3102         }
3103 
3104         pci_set_master(pcidev);
3105 
3106         netdev = alloc_etherdev(sizeof(struct adapter));
3107         if (!netdev) {
3108                 err = -ENOMEM;
3109                 goto err_out_exit_slic_probe;
3110         }
3111 
3112         SET_NETDEV_DEV(netdev, &pcidev->dev);
3113 
3114         pci_set_drvdata(pcidev, netdev);
3115         adapter = netdev_priv(netdev);
3116         adapter->netdev = netdev;
3117         adapter->pcidev = pcidev;
3118         if (pci_using_dac)
3119                 netdev->features |= NETIF_F_HIGHDMA;
3120 
3121         mmio_start = pci_resource_start(pcidev, 0);
3122         mmio_len = pci_resource_len(pcidev, 0);
3123 
3124 
3125 /*      memmapped_ioaddr =  (u32)ioremap_nocache(mmio_start, mmio_len);*/
3126         memmapped_ioaddr = ioremap(mmio_start, mmio_len);
3127         if (!memmapped_ioaddr) {
3128                 dev_err(&pcidev->dev, "cannot remap MMIO region %lx @ %lx\n",
3129                         mmio_len, mmio_start);
3130                 err = -ENOMEM;
3131                 goto err_out_free_netdev;
3132         }
3133 
3134         slic_config_pci(pcidev);
3135 
3136         slic_init_driver();
3137 
3138         slic_init_adapter(netdev,
3139                           pcidev, pci_tbl_entry, memmapped_ioaddr, cards_found);
3140 
3141         err = slic_card_locate(adapter);
3142         if (err) {
3143                 dev_err(&pcidev->dev, "cannot locate card\n");
3144                 goto err_out_unmap;
3145         }
3146 
3147         card = adapter->card;
3148 
3149         if (!adapter->allocated) {
3150                 card->adapters_allocated++;
3151                 adapter->allocated = 1;
3152         }
3153 
3154         err = slic_card_init(card, adapter);
3155         if (err)
3156                 goto err_out_unmap;
3157 
3158         slic_adapter_set_hwaddr(adapter);
3159 
3160         netdev->base_addr = (unsigned long) memmapped_ioaddr;
3161         netdev->irq = adapter->irq;
3162         netdev->netdev_ops = &slic_netdev_ops;
3163 
3164         strcpy(netdev->name, "eth%d");
3165         err = register_netdev(netdev);
3166         if (err) {
3167                 dev_err(&pcidev->dev, "Cannot register net device, aborting.\n");
3168                 goto err_out_unmap;
3169         }
3170 
3171         cards_found++;
3172 
3173         return 0;
3174 
3175 err_out_unmap:
3176         iounmap(memmapped_ioaddr);
3177 err_out_free_netdev:
3178         free_netdev(netdev);
3179 err_out_exit_slic_probe:
3180         pci_release_regions(pcidev);
3181 err_out_disable_pci:
3182         pci_disable_device(pcidev);
3183         return err;
3184 }
3185 
3186 static struct pci_driver slic_driver = {
3187         .name = DRV_NAME,
3188         .id_table = slic_pci_tbl,
3189         .probe = slic_entry_probe,
3190         .remove = slic_entry_remove,
3191 };
3192 
3193 static int __init slic_module_init(void)
3194 {
3195         slic_init_driver();
3196 
3197         return pci_register_driver(&slic_driver);
3198 }
3199 
3200 static void __exit slic_module_cleanup(void)
3201 {
3202         pci_unregister_driver(&slic_driver);
3203 }
3204 
3205 module_init(slic_module_init);
3206 module_exit(slic_module_cleanup);
3207 

This page was automatically generated by LXR 0.3.1 (source).  •  Linux is a registered trademark of Linus Torvalds  •  Contact us