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