Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-only
0002 /*
0003  * Copyright 2008 Cisco Systems, Inc.  All rights reserved.
0004  * Copyright 2007 Nuova Systems, Inc.  All rights reserved.
0005  */
0006 #include <linux/module.h>
0007 #include <linux/mempool.h>
0008 #include <linux/string.h>
0009 #include <linux/slab.h>
0010 #include <linux/errno.h>
0011 #include <linux/init.h>
0012 #include <linux/pci.h>
0013 #include <linux/skbuff.h>
0014 #include <linux/interrupt.h>
0015 #include <linux/spinlock.h>
0016 #include <linux/workqueue.h>
0017 #include <linux/if_ether.h>
0018 #include <scsi/fc/fc_fip.h>
0019 #include <scsi/scsi_host.h>
0020 #include <scsi/scsi_transport.h>
0021 #include <scsi/scsi_transport_fc.h>
0022 #include <scsi/scsi_tcq.h>
0023 #include <scsi/libfc.h>
0024 #include <scsi/fc_frame.h>
0025 
0026 #include "vnic_dev.h"
0027 #include "vnic_intr.h"
0028 #include "vnic_stats.h"
0029 #include "fnic_io.h"
0030 #include "fnic_fip.h"
0031 #include "fnic.h"
0032 
0033 #define PCI_DEVICE_ID_CISCO_FNIC    0x0045
0034 
0035 /* Timer to poll notification area for events. Used for MSI interrupts */
0036 #define FNIC_NOTIFY_TIMER_PERIOD    (2 * HZ)
0037 
0038 static struct kmem_cache *fnic_sgl_cache[FNIC_SGL_NUM_CACHES];
0039 static struct kmem_cache *fnic_io_req_cache;
0040 static LIST_HEAD(fnic_list);
0041 static DEFINE_SPINLOCK(fnic_list_lock);
0042 
0043 /* Supported devices by fnic module */
0044 static struct pci_device_id fnic_id_table[] = {
0045     { PCI_DEVICE(PCI_VENDOR_ID_CISCO, PCI_DEVICE_ID_CISCO_FNIC) },
0046     { 0, }
0047 };
0048 
0049 MODULE_DESCRIPTION(DRV_DESCRIPTION);
0050 MODULE_AUTHOR("Abhijeet Joglekar <abjoglek@cisco.com>, "
0051           "Joseph R. Eykholt <jeykholt@cisco.com>");
0052 MODULE_LICENSE("GPL v2");
0053 MODULE_VERSION(DRV_VERSION);
0054 MODULE_DEVICE_TABLE(pci, fnic_id_table);
0055 
0056 unsigned int fnic_log_level;
0057 module_param(fnic_log_level, int, S_IRUGO|S_IWUSR);
0058 MODULE_PARM_DESC(fnic_log_level, "bit mask of fnic logging levels");
0059 
0060 
0061 unsigned int io_completions = FNIC_DFLT_IO_COMPLETIONS;
0062 module_param(io_completions, int, S_IRUGO|S_IWUSR);
0063 MODULE_PARM_DESC(io_completions, "Max CQ entries to process at a time");
0064 
0065 unsigned int fnic_trace_max_pages = 16;
0066 module_param(fnic_trace_max_pages, uint, S_IRUGO|S_IWUSR);
0067 MODULE_PARM_DESC(fnic_trace_max_pages, "Total allocated memory pages "
0068                     "for fnic trace buffer");
0069 
0070 unsigned int fnic_fc_trace_max_pages = 64;
0071 module_param(fnic_fc_trace_max_pages, uint, S_IRUGO|S_IWUSR);
0072 MODULE_PARM_DESC(fnic_fc_trace_max_pages,
0073          "Total allocated memory pages for fc trace buffer");
0074 
0075 static unsigned int fnic_max_qdepth = FNIC_DFLT_QUEUE_DEPTH;
0076 module_param(fnic_max_qdepth, uint, S_IRUGO|S_IWUSR);
0077 MODULE_PARM_DESC(fnic_max_qdepth, "Queue depth to report for each LUN");
0078 
0079 static struct libfc_function_template fnic_transport_template = {
0080     .frame_send = fnic_send,
0081     .lport_set_port_id = fnic_set_port_id,
0082     .fcp_abort_io = fnic_empty_scsi_cleanup,
0083     .fcp_cleanup = fnic_empty_scsi_cleanup,
0084     .exch_mgr_reset = fnic_exch_mgr_reset
0085 };
0086 
0087 static int fnic_slave_alloc(struct scsi_device *sdev)
0088 {
0089     struct fc_rport *rport = starget_to_rport(scsi_target(sdev));
0090 
0091     if (!rport || fc_remote_port_chkready(rport))
0092         return -ENXIO;
0093 
0094     scsi_change_queue_depth(sdev, fnic_max_qdepth);
0095     return 0;
0096 }
0097 
0098 static struct scsi_host_template fnic_host_template = {
0099     .module = THIS_MODULE,
0100     .name = DRV_NAME,
0101     .queuecommand = fnic_queuecommand,
0102     .eh_timed_out = fc_eh_timed_out,
0103     .eh_abort_handler = fnic_abort_cmd,
0104     .eh_device_reset_handler = fnic_device_reset,
0105     .eh_host_reset_handler = fnic_host_reset,
0106     .slave_alloc = fnic_slave_alloc,
0107     .change_queue_depth = scsi_change_queue_depth,
0108     .this_id = -1,
0109     .cmd_per_lun = 3,
0110     .can_queue = FNIC_DFLT_IO_REQ,
0111     .sg_tablesize = FNIC_MAX_SG_DESC_CNT,
0112     .max_sectors = 0xffff,
0113     .shost_groups = fnic_host_groups,
0114     .track_queue_depth = 1,
0115     .cmd_size = sizeof(struct fnic_cmd_priv),
0116 };
0117 
0118 static void
0119 fnic_set_rport_dev_loss_tmo(struct fc_rport *rport, u32 timeout)
0120 {
0121     if (timeout)
0122         rport->dev_loss_tmo = timeout;
0123     else
0124         rport->dev_loss_tmo = 1;
0125 }
0126 
0127 static void fnic_get_host_speed(struct Scsi_Host *shost);
0128 static struct scsi_transport_template *fnic_fc_transport;
0129 static struct fc_host_statistics *fnic_get_stats(struct Scsi_Host *);
0130 static void fnic_reset_host_stats(struct Scsi_Host *);
0131 
0132 static struct fc_function_template fnic_fc_functions = {
0133 
0134     .show_host_node_name = 1,
0135     .show_host_port_name = 1,
0136     .show_host_supported_classes = 1,
0137     .show_host_supported_fc4s = 1,
0138     .show_host_active_fc4s = 1,
0139     .show_host_maxframe_size = 1,
0140     .show_host_port_id = 1,
0141     .show_host_supported_speeds = 1,
0142     .get_host_speed = fnic_get_host_speed,
0143     .show_host_speed = 1,
0144     .show_host_port_type = 1,
0145     .get_host_port_state = fc_get_host_port_state,
0146     .show_host_port_state = 1,
0147     .show_host_symbolic_name = 1,
0148     .show_rport_maxframe_size = 1,
0149     .show_rport_supported_classes = 1,
0150     .show_host_fabric_name = 1,
0151     .show_starget_node_name = 1,
0152     .show_starget_port_name = 1,
0153     .show_starget_port_id = 1,
0154     .show_rport_dev_loss_tmo = 1,
0155     .set_rport_dev_loss_tmo = fnic_set_rport_dev_loss_tmo,
0156     .issue_fc_host_lip = fnic_reset,
0157     .get_fc_host_stats = fnic_get_stats,
0158     .reset_fc_host_stats = fnic_reset_host_stats,
0159     .dd_fcrport_size = sizeof(struct fc_rport_libfc_priv),
0160     .terminate_rport_io = fnic_terminate_rport_io,
0161     .bsg_request = fc_lport_bsg_request,
0162 };
0163 
0164 static void fnic_get_host_speed(struct Scsi_Host *shost)
0165 {
0166     struct fc_lport *lp = shost_priv(shost);
0167     struct fnic *fnic = lport_priv(lp);
0168     u32 port_speed = vnic_dev_port_speed(fnic->vdev);
0169 
0170     /* Add in other values as they get defined in fw */
0171     switch (port_speed) {
0172     case DCEM_PORTSPEED_10G:
0173         fc_host_speed(shost) = FC_PORTSPEED_10GBIT;
0174         break;
0175     case DCEM_PORTSPEED_20G:
0176         fc_host_speed(shost) = FC_PORTSPEED_20GBIT;
0177         break;
0178     case DCEM_PORTSPEED_25G:
0179         fc_host_speed(shost) = FC_PORTSPEED_25GBIT;
0180         break;
0181     case DCEM_PORTSPEED_40G:
0182     case DCEM_PORTSPEED_4x10G:
0183         fc_host_speed(shost) = FC_PORTSPEED_40GBIT;
0184         break;
0185     case DCEM_PORTSPEED_100G:
0186         fc_host_speed(shost) = FC_PORTSPEED_100GBIT;
0187         break;
0188     default:
0189         fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
0190         break;
0191     }
0192 }
0193 
0194 static struct fc_host_statistics *fnic_get_stats(struct Scsi_Host *host)
0195 {
0196     int ret;
0197     struct fc_lport *lp = shost_priv(host);
0198     struct fnic *fnic = lport_priv(lp);
0199     struct fc_host_statistics *stats = &lp->host_stats;
0200     struct vnic_stats *vs;
0201     unsigned long flags;
0202 
0203     if (time_before(jiffies, fnic->stats_time + HZ / FNIC_STATS_RATE_LIMIT))
0204         return stats;
0205     fnic->stats_time = jiffies;
0206 
0207     spin_lock_irqsave(&fnic->fnic_lock, flags);
0208     ret = vnic_dev_stats_dump(fnic->vdev, &fnic->stats);
0209     spin_unlock_irqrestore(&fnic->fnic_lock, flags);
0210 
0211     if (ret) {
0212         FNIC_MAIN_DBG(KERN_DEBUG, fnic->lport->host,
0213                   "fnic: Get vnic stats failed"
0214                   " 0x%x", ret);
0215         return stats;
0216     }
0217     vs = fnic->stats;
0218     stats->tx_frames = vs->tx.tx_unicast_frames_ok;
0219     stats->tx_words  = vs->tx.tx_unicast_bytes_ok / 4;
0220     stats->rx_frames = vs->rx.rx_unicast_frames_ok;
0221     stats->rx_words  = vs->rx.rx_unicast_bytes_ok / 4;
0222     stats->error_frames = vs->tx.tx_errors + vs->rx.rx_errors;
0223     stats->dumped_frames = vs->tx.tx_drops + vs->rx.rx_drop;
0224     stats->invalid_crc_count = vs->rx.rx_crc_errors;
0225     stats->seconds_since_last_reset =
0226             (jiffies - fnic->stats_reset_time) / HZ;
0227     stats->fcp_input_megabytes = div_u64(fnic->fcp_input_bytes, 1000000);
0228     stats->fcp_output_megabytes = div_u64(fnic->fcp_output_bytes, 1000000);
0229 
0230     return stats;
0231 }
0232 
0233 /*
0234  * fnic_dump_fchost_stats
0235  * note : dumps fc_statistics into system logs
0236  */
0237 void fnic_dump_fchost_stats(struct Scsi_Host *host,
0238                 struct fc_host_statistics *stats)
0239 {
0240     FNIC_MAIN_NOTE(KERN_NOTICE, host,
0241             "fnic: seconds since last reset = %llu\n",
0242             stats->seconds_since_last_reset);
0243     FNIC_MAIN_NOTE(KERN_NOTICE, host,
0244             "fnic: tx frames        = %llu\n",
0245             stats->tx_frames);
0246     FNIC_MAIN_NOTE(KERN_NOTICE, host,
0247             "fnic: tx words     = %llu\n",
0248             stats->tx_words);
0249     FNIC_MAIN_NOTE(KERN_NOTICE, host,
0250             "fnic: rx frames        = %llu\n",
0251             stats->rx_frames);
0252     FNIC_MAIN_NOTE(KERN_NOTICE, host,
0253             "fnic: rx words     = %llu\n",
0254             stats->rx_words);
0255     FNIC_MAIN_NOTE(KERN_NOTICE, host,
0256             "fnic: lip count        = %llu\n",
0257             stats->lip_count);
0258     FNIC_MAIN_NOTE(KERN_NOTICE, host,
0259             "fnic: nos count        = %llu\n",
0260             stats->nos_count);
0261     FNIC_MAIN_NOTE(KERN_NOTICE, host,
0262             "fnic: error frames     = %llu\n",
0263             stats->error_frames);
0264     FNIC_MAIN_NOTE(KERN_NOTICE, host,
0265             "fnic: dumped frames    = %llu\n",
0266             stats->dumped_frames);
0267     FNIC_MAIN_NOTE(KERN_NOTICE, host,
0268             "fnic: link failure count   = %llu\n",
0269             stats->link_failure_count);
0270     FNIC_MAIN_NOTE(KERN_NOTICE, host,
0271             "fnic: loss of sync count   = %llu\n",
0272             stats->loss_of_sync_count);
0273     FNIC_MAIN_NOTE(KERN_NOTICE, host,
0274             "fnic: loss of signal count = %llu\n",
0275             stats->loss_of_signal_count);
0276     FNIC_MAIN_NOTE(KERN_NOTICE, host,
0277             "fnic: prim seq protocol err count = %llu\n",
0278             stats->prim_seq_protocol_err_count);
0279     FNIC_MAIN_NOTE(KERN_NOTICE, host,
0280             "fnic: invalid tx word count= %llu\n",
0281             stats->invalid_tx_word_count);
0282     FNIC_MAIN_NOTE(KERN_NOTICE, host,
0283             "fnic: invalid crc count    = %llu\n",
0284             stats->invalid_crc_count);
0285     FNIC_MAIN_NOTE(KERN_NOTICE, host,
0286             "fnic: fcp input requests   = %llu\n",
0287             stats->fcp_input_requests);
0288     FNIC_MAIN_NOTE(KERN_NOTICE, host,
0289             "fnic: fcp output requests  = %llu\n",
0290             stats->fcp_output_requests);
0291     FNIC_MAIN_NOTE(KERN_NOTICE, host,
0292             "fnic: fcp control requests = %llu\n",
0293             stats->fcp_control_requests);
0294     FNIC_MAIN_NOTE(KERN_NOTICE, host,
0295             "fnic: fcp input megabytes  = %llu\n",
0296             stats->fcp_input_megabytes);
0297     FNIC_MAIN_NOTE(KERN_NOTICE, host,
0298             "fnic: fcp output megabytes = %llu\n",
0299             stats->fcp_output_megabytes);
0300     return;
0301 }
0302 
0303 /*
0304  * fnic_reset_host_stats : clears host stats
0305  * note : called when reset_statistics set under sysfs dir
0306  */
0307 static void fnic_reset_host_stats(struct Scsi_Host *host)
0308 {
0309     int ret;
0310     struct fc_lport *lp = shost_priv(host);
0311     struct fnic *fnic = lport_priv(lp);
0312     struct fc_host_statistics *stats;
0313     unsigned long flags;
0314 
0315     /* dump current stats, before clearing them */
0316     stats = fnic_get_stats(host);
0317     fnic_dump_fchost_stats(host, stats);
0318 
0319     spin_lock_irqsave(&fnic->fnic_lock, flags);
0320     ret = vnic_dev_stats_clear(fnic->vdev);
0321     spin_unlock_irqrestore(&fnic->fnic_lock, flags);
0322 
0323     if (ret) {
0324         FNIC_MAIN_DBG(KERN_DEBUG, fnic->lport->host,
0325                 "fnic: Reset vnic stats failed"
0326                 " 0x%x", ret);
0327         return;
0328     }
0329     fnic->stats_reset_time = jiffies;
0330     memset(stats, 0, sizeof(*stats));
0331 
0332     return;
0333 }
0334 
0335 void fnic_log_q_error(struct fnic *fnic)
0336 {
0337     unsigned int i;
0338     u32 error_status;
0339 
0340     for (i = 0; i < fnic->raw_wq_count; i++) {
0341         error_status = ioread32(&fnic->wq[i].ctrl->error_status);
0342         if (error_status)
0343             shost_printk(KERN_ERR, fnic->lport->host,
0344                      "WQ[%d] error_status"
0345                      " %d\n", i, error_status);
0346     }
0347 
0348     for (i = 0; i < fnic->rq_count; i++) {
0349         error_status = ioread32(&fnic->rq[i].ctrl->error_status);
0350         if (error_status)
0351             shost_printk(KERN_ERR, fnic->lport->host,
0352                      "RQ[%d] error_status"
0353                      " %d\n", i, error_status);
0354     }
0355 
0356     for (i = 0; i < fnic->wq_copy_count; i++) {
0357         error_status = ioread32(&fnic->wq_copy[i].ctrl->error_status);
0358         if (error_status)
0359             shost_printk(KERN_ERR, fnic->lport->host,
0360                      "CWQ[%d] error_status"
0361                      " %d\n", i, error_status);
0362     }
0363 }
0364 
0365 void fnic_handle_link_event(struct fnic *fnic)
0366 {
0367     unsigned long flags;
0368 
0369     spin_lock_irqsave(&fnic->fnic_lock, flags);
0370     if (fnic->stop_rx_link_events) {
0371         spin_unlock_irqrestore(&fnic->fnic_lock, flags);
0372         return;
0373     }
0374     spin_unlock_irqrestore(&fnic->fnic_lock, flags);
0375 
0376     queue_work(fnic_event_queue, &fnic->link_work);
0377 
0378 }
0379 
0380 static int fnic_notify_set(struct fnic *fnic)
0381 {
0382     int err;
0383 
0384     switch (vnic_dev_get_intr_mode(fnic->vdev)) {
0385     case VNIC_DEV_INTR_MODE_INTX:
0386         err = vnic_dev_notify_set(fnic->vdev, FNIC_INTX_NOTIFY);
0387         break;
0388     case VNIC_DEV_INTR_MODE_MSI:
0389         err = vnic_dev_notify_set(fnic->vdev, -1);
0390         break;
0391     case VNIC_DEV_INTR_MODE_MSIX:
0392         err = vnic_dev_notify_set(fnic->vdev, FNIC_MSIX_ERR_NOTIFY);
0393         break;
0394     default:
0395         shost_printk(KERN_ERR, fnic->lport->host,
0396                  "Interrupt mode should be set up"
0397                  " before devcmd notify set %d\n",
0398                  vnic_dev_get_intr_mode(fnic->vdev));
0399         err = -1;
0400         break;
0401     }
0402 
0403     return err;
0404 }
0405 
0406 static void fnic_notify_timer(struct timer_list *t)
0407 {
0408     struct fnic *fnic = from_timer(fnic, t, notify_timer);
0409 
0410     fnic_handle_link_event(fnic);
0411     mod_timer(&fnic->notify_timer,
0412           round_jiffies(jiffies + FNIC_NOTIFY_TIMER_PERIOD));
0413 }
0414 
0415 static void fnic_fip_notify_timer(struct timer_list *t)
0416 {
0417     struct fnic *fnic = from_timer(fnic, t, fip_timer);
0418 
0419     fnic_handle_fip_timer(fnic);
0420 }
0421 
0422 static void fnic_notify_timer_start(struct fnic *fnic)
0423 {
0424     switch (vnic_dev_get_intr_mode(fnic->vdev)) {
0425     case VNIC_DEV_INTR_MODE_MSI:
0426         /*
0427          * Schedule first timeout immediately. The driver is
0428          * initiatialized and ready to look for link up notification
0429          */
0430         mod_timer(&fnic->notify_timer, jiffies);
0431         break;
0432     default:
0433         /* Using intr for notification for INTx/MSI-X */
0434         break;
0435     }
0436 }
0437 
0438 static int fnic_dev_wait(struct vnic_dev *vdev,
0439              int (*start)(struct vnic_dev *, int),
0440              int (*finished)(struct vnic_dev *, int *),
0441              int arg)
0442 {
0443     unsigned long time;
0444     int done;
0445     int err;
0446     int count;
0447 
0448     count = 0;
0449 
0450     err = start(vdev, arg);
0451     if (err)
0452         return err;
0453 
0454     /* Wait for func to complete.
0455     * Sometime schedule_timeout_uninterruptible take long time
0456     * to wake up so we do not retry as we are only waiting for
0457     * 2 seconds in while loop. By adding count, we make sure
0458     * we try atleast three times before returning -ETIMEDOUT
0459     */
0460     time = jiffies + (HZ * 2);
0461     do {
0462         err = finished(vdev, &done);
0463         count++;
0464         if (err)
0465             return err;
0466         if (done)
0467             return 0;
0468         schedule_timeout_uninterruptible(HZ / 10);
0469     } while (time_after(time, jiffies) || (count < 3));
0470 
0471     return -ETIMEDOUT;
0472 }
0473 
0474 static int fnic_cleanup(struct fnic *fnic)
0475 {
0476     unsigned int i;
0477     int err;
0478 
0479     vnic_dev_disable(fnic->vdev);
0480     for (i = 0; i < fnic->intr_count; i++)
0481         vnic_intr_mask(&fnic->intr[i]);
0482 
0483     for (i = 0; i < fnic->rq_count; i++) {
0484         err = vnic_rq_disable(&fnic->rq[i]);
0485         if (err)
0486             return err;
0487     }
0488     for (i = 0; i < fnic->raw_wq_count; i++) {
0489         err = vnic_wq_disable(&fnic->wq[i]);
0490         if (err)
0491             return err;
0492     }
0493     for (i = 0; i < fnic->wq_copy_count; i++) {
0494         err = vnic_wq_copy_disable(&fnic->wq_copy[i]);
0495         if (err)
0496             return err;
0497     }
0498 
0499     /* Clean up completed IOs and FCS frames */
0500     fnic_wq_copy_cmpl_handler(fnic, io_completions);
0501     fnic_wq_cmpl_handler(fnic, -1);
0502     fnic_rq_cmpl_handler(fnic, -1);
0503 
0504     /* Clean up the IOs and FCS frames that have not completed */
0505     for (i = 0; i < fnic->raw_wq_count; i++)
0506         vnic_wq_clean(&fnic->wq[i], fnic_free_wq_buf);
0507     for (i = 0; i < fnic->rq_count; i++)
0508         vnic_rq_clean(&fnic->rq[i], fnic_free_rq_buf);
0509     for (i = 0; i < fnic->wq_copy_count; i++)
0510         vnic_wq_copy_clean(&fnic->wq_copy[i],
0511                    fnic_wq_copy_cleanup_handler);
0512 
0513     for (i = 0; i < fnic->cq_count; i++)
0514         vnic_cq_clean(&fnic->cq[i]);
0515     for (i = 0; i < fnic->intr_count; i++)
0516         vnic_intr_clean(&fnic->intr[i]);
0517 
0518     mempool_destroy(fnic->io_req_pool);
0519     for (i = 0; i < FNIC_SGL_NUM_CACHES; i++)
0520         mempool_destroy(fnic->io_sgl_pool[i]);
0521 
0522     return 0;
0523 }
0524 
0525 static void fnic_iounmap(struct fnic *fnic)
0526 {
0527     if (fnic->bar0.vaddr)
0528         iounmap(fnic->bar0.vaddr);
0529 }
0530 
0531 /**
0532  * fnic_get_mac() - get assigned data MAC address for FIP code.
0533  * @lport:  local port.
0534  */
0535 static u8 *fnic_get_mac(struct fc_lport *lport)
0536 {
0537     struct fnic *fnic = lport_priv(lport);
0538 
0539     return fnic->data_src_addr;
0540 }
0541 
0542 static void fnic_set_vlan(struct fnic *fnic, u16 vlan_id)
0543 {
0544     vnic_dev_set_default_vlan(fnic->vdev, vlan_id);
0545 }
0546 
0547 static int fnic_scsi_drv_init(struct fnic *fnic)
0548 {
0549     struct Scsi_Host *host = fnic->lport->host;
0550 
0551     /* Configure maximum outstanding IO reqs*/
0552     if (fnic->config.io_throttle_count != FNIC_UCSM_DFLT_THROTTLE_CNT_BLD)
0553         host->can_queue = min_t(u32, FNIC_MAX_IO_REQ,
0554                     max_t(u32, FNIC_MIN_IO_REQ,
0555                     fnic->config.io_throttle_count));
0556 
0557     fnic->fnic_max_tag_id = host->can_queue;
0558     host->max_lun = fnic->config.luns_per_tgt;
0559     host->max_id = FNIC_MAX_FCP_TARGET;
0560     host->max_cmd_len = FCOE_MAX_CMD_LEN;
0561 
0562     host->nr_hw_queues = fnic->wq_copy_count;
0563     if (host->nr_hw_queues > 1)
0564         shost_printk(KERN_ERR, host,
0565                 "fnic: blk-mq is not supported");
0566 
0567     host->nr_hw_queues = fnic->wq_copy_count = 1;
0568 
0569     shost_printk(KERN_INFO, host,
0570             "fnic: can_queue: %d max_lun: %llu",
0571             host->can_queue, host->max_lun);
0572 
0573     shost_printk(KERN_INFO, host,
0574             "fnic: max_id: %d max_cmd_len: %d nr_hw_queues: %d",
0575             host->max_id, host->max_cmd_len, host->nr_hw_queues);
0576 
0577     return 0;
0578 }
0579 
0580 static int fnic_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
0581 {
0582     struct Scsi_Host *host;
0583     struct fc_lport *lp;
0584     struct fnic *fnic;
0585     mempool_t *pool;
0586     int err;
0587     int i;
0588     unsigned long flags;
0589 
0590     /*
0591      * Allocate SCSI Host and set up association between host,
0592      * local port, and fnic
0593      */
0594     lp = libfc_host_alloc(&fnic_host_template, sizeof(struct fnic));
0595     if (!lp) {
0596         printk(KERN_ERR PFX "Unable to alloc libfc local port\n");
0597         err = -ENOMEM;
0598         goto err_out;
0599     }
0600     host = lp->host;
0601     fnic = lport_priv(lp);
0602     fnic->lport = lp;
0603     fnic->ctlr.lp = lp;
0604 
0605     fnic->link_events = 0;
0606 
0607     snprintf(fnic->name, sizeof(fnic->name) - 1, "%s%d", DRV_NAME,
0608          host->host_no);
0609 
0610     host->transportt = fnic_fc_transport;
0611 
0612     fnic_stats_debugfs_init(fnic);
0613 
0614     /* Setup PCI resources */
0615     pci_set_drvdata(pdev, fnic);
0616 
0617     fnic->pdev = pdev;
0618 
0619     err = pci_enable_device(pdev);
0620     if (err) {
0621         shost_printk(KERN_ERR, fnic->lport->host,
0622                  "Cannot enable PCI device, aborting.\n");
0623         goto err_out_free_hba;
0624     }
0625 
0626     err = pci_request_regions(pdev, DRV_NAME);
0627     if (err) {
0628         shost_printk(KERN_ERR, fnic->lport->host,
0629                  "Cannot enable PCI resources, aborting\n");
0630         goto err_out_disable_device;
0631     }
0632 
0633     pci_set_master(pdev);
0634 
0635     /* Query PCI controller on system for DMA addressing
0636      * limitation for the device.  Try 47-bit first, and
0637      * fail to 32-bit. Cisco VIC supports 47 bits only.
0638      */
0639     err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(47));
0640     if (err) {
0641         err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
0642         if (err) {
0643             shost_printk(KERN_ERR, fnic->lport->host,
0644                      "No usable DMA configuration "
0645                      "aborting\n");
0646             goto err_out_release_regions;
0647         }
0648     }
0649 
0650     /* Map vNIC resources from BAR0 */
0651     if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) {
0652         shost_printk(KERN_ERR, fnic->lport->host,
0653                  "BAR0 not memory-map'able, aborting.\n");
0654         err = -ENODEV;
0655         goto err_out_release_regions;
0656     }
0657 
0658     fnic->bar0.vaddr = pci_iomap(pdev, 0, 0);
0659     fnic->bar0.bus_addr = pci_resource_start(pdev, 0);
0660     fnic->bar0.len = pci_resource_len(pdev, 0);
0661 
0662     if (!fnic->bar0.vaddr) {
0663         shost_printk(KERN_ERR, fnic->lport->host,
0664                  "Cannot memory-map BAR0 res hdr, "
0665                  "aborting.\n");
0666         err = -ENODEV;
0667         goto err_out_release_regions;
0668     }
0669 
0670     fnic->vdev = vnic_dev_register(NULL, fnic, pdev, &fnic->bar0);
0671     if (!fnic->vdev) {
0672         shost_printk(KERN_ERR, fnic->lport->host,
0673                  "vNIC registration failed, "
0674                  "aborting.\n");
0675         err = -ENODEV;
0676         goto err_out_iounmap;
0677     }
0678 
0679     err = vnic_dev_cmd_init(fnic->vdev);
0680     if (err) {
0681         shost_printk(KERN_ERR, fnic->lport->host,
0682                 "vnic_dev_cmd_init() returns %d, aborting\n",
0683                 err);
0684         goto err_out_vnic_unregister;
0685     }
0686 
0687     err = fnic_dev_wait(fnic->vdev, vnic_dev_open,
0688                 vnic_dev_open_done, CMD_OPENF_RQ_ENABLE_THEN_POST);
0689     if (err) {
0690         shost_printk(KERN_ERR, fnic->lport->host,
0691                  "vNIC dev open failed, aborting.\n");
0692         goto err_out_dev_cmd_deinit;
0693     }
0694 
0695     err = vnic_dev_init(fnic->vdev, 0);
0696     if (err) {
0697         shost_printk(KERN_ERR, fnic->lport->host,
0698                  "vNIC dev init failed, aborting.\n");
0699         goto err_out_dev_close;
0700     }
0701 
0702     err = vnic_dev_mac_addr(fnic->vdev, fnic->ctlr.ctl_src_addr);
0703     if (err) {
0704         shost_printk(KERN_ERR, fnic->lport->host,
0705                  "vNIC get MAC addr failed \n");
0706         goto err_out_dev_close;
0707     }
0708     /* set data_src for point-to-point mode and to keep it non-zero */
0709     memcpy(fnic->data_src_addr, fnic->ctlr.ctl_src_addr, ETH_ALEN);
0710 
0711     /* Get vNIC configuration */
0712     err = fnic_get_vnic_config(fnic);
0713     if (err) {
0714         shost_printk(KERN_ERR, fnic->lport->host,
0715                  "Get vNIC configuration failed, "
0716                  "aborting.\n");
0717         goto err_out_dev_close;
0718     }
0719 
0720     fnic_scsi_drv_init(fnic);
0721 
0722     fnic_get_res_counts(fnic);
0723 
0724     err = fnic_set_intr_mode(fnic);
0725     if (err) {
0726         shost_printk(KERN_ERR, fnic->lport->host,
0727                  "Failed to set intr mode, "
0728                  "aborting.\n");
0729         goto err_out_dev_close;
0730     }
0731 
0732     err = fnic_alloc_vnic_resources(fnic);
0733     if (err) {
0734         shost_printk(KERN_ERR, fnic->lport->host,
0735                  "Failed to alloc vNIC resources, "
0736                  "aborting.\n");
0737         goto err_out_clear_intr;
0738     }
0739 
0740 
0741     /* initialize all fnic locks */
0742     spin_lock_init(&fnic->fnic_lock);
0743 
0744     for (i = 0; i < FNIC_WQ_MAX; i++)
0745         spin_lock_init(&fnic->wq_lock[i]);
0746 
0747     for (i = 0; i < FNIC_WQ_COPY_MAX; i++) {
0748         spin_lock_init(&fnic->wq_copy_lock[i]);
0749         fnic->wq_copy_desc_low[i] = DESC_CLEAN_LOW_WATERMARK;
0750         fnic->fw_ack_recd[i] = 0;
0751         fnic->fw_ack_index[i] = -1;
0752     }
0753 
0754     for (i = 0; i < FNIC_IO_LOCKS; i++)
0755         spin_lock_init(&fnic->io_req_lock[i]);
0756 
0757     err = -ENOMEM;
0758     fnic->io_req_pool = mempool_create_slab_pool(2, fnic_io_req_cache);
0759     if (!fnic->io_req_pool)
0760         goto err_out_free_resources;
0761 
0762     pool = mempool_create_slab_pool(2, fnic_sgl_cache[FNIC_SGL_CACHE_DFLT]);
0763     if (!pool)
0764         goto err_out_free_ioreq_pool;
0765     fnic->io_sgl_pool[FNIC_SGL_CACHE_DFLT] = pool;
0766 
0767     pool = mempool_create_slab_pool(2, fnic_sgl_cache[FNIC_SGL_CACHE_MAX]);
0768     if (!pool)
0769         goto err_out_free_dflt_pool;
0770     fnic->io_sgl_pool[FNIC_SGL_CACHE_MAX] = pool;
0771 
0772     /* setup vlan config, hw inserts vlan header */
0773     fnic->vlan_hw_insert = 1;
0774     fnic->vlan_id = 0;
0775 
0776     /* Initialize the FIP fcoe_ctrl struct */
0777     fnic->ctlr.send = fnic_eth_send;
0778     fnic->ctlr.update_mac = fnic_update_mac;
0779     fnic->ctlr.get_src_addr = fnic_get_mac;
0780     if (fnic->config.flags & VFCF_FIP_CAPABLE) {
0781         shost_printk(KERN_INFO, fnic->lport->host,
0782                  "firmware supports FIP\n");
0783         /* enable directed and multicast */
0784         vnic_dev_packet_filter(fnic->vdev, 1, 1, 0, 0, 0);
0785         vnic_dev_add_addr(fnic->vdev, FIP_ALL_ENODE_MACS);
0786         vnic_dev_add_addr(fnic->vdev, fnic->ctlr.ctl_src_addr);
0787         fnic->set_vlan = fnic_set_vlan;
0788         fcoe_ctlr_init(&fnic->ctlr, FIP_MODE_AUTO);
0789         timer_setup(&fnic->fip_timer, fnic_fip_notify_timer, 0);
0790         spin_lock_init(&fnic->vlans_lock);
0791         INIT_WORK(&fnic->fip_frame_work, fnic_handle_fip_frame);
0792         INIT_WORK(&fnic->event_work, fnic_handle_event);
0793         skb_queue_head_init(&fnic->fip_frame_queue);
0794         INIT_LIST_HEAD(&fnic->evlist);
0795         INIT_LIST_HEAD(&fnic->vlans);
0796     } else {
0797         shost_printk(KERN_INFO, fnic->lport->host,
0798                  "firmware uses non-FIP mode\n");
0799         fcoe_ctlr_init(&fnic->ctlr, FIP_MODE_NON_FIP);
0800         fnic->ctlr.state = FIP_ST_NON_FIP;
0801     }
0802     fnic->state = FNIC_IN_FC_MODE;
0803 
0804     atomic_set(&fnic->in_flight, 0);
0805     fnic->state_flags = FNIC_FLAGS_NONE;
0806 
0807     /* Enable hardware stripping of vlan header on ingress */
0808     fnic_set_nic_config(fnic, 0, 0, 0, 0, 0, 0, 1);
0809 
0810     /* Setup notification buffer area */
0811     err = fnic_notify_set(fnic);
0812     if (err) {
0813         shost_printk(KERN_ERR, fnic->lport->host,
0814                  "Failed to alloc notify buffer, aborting.\n");
0815         goto err_out_free_max_pool;
0816     }
0817 
0818     /* Setup notify timer when using MSI interrupts */
0819     if (vnic_dev_get_intr_mode(fnic->vdev) == VNIC_DEV_INTR_MODE_MSI)
0820         timer_setup(&fnic->notify_timer, fnic_notify_timer, 0);
0821 
0822     /* allocate RQ buffers and post them to RQ*/
0823     for (i = 0; i < fnic->rq_count; i++) {
0824         vnic_rq_enable(&fnic->rq[i]);
0825         err = vnic_rq_fill(&fnic->rq[i], fnic_alloc_rq_frame);
0826         if (err) {
0827             shost_printk(KERN_ERR, fnic->lport->host,
0828                      "fnic_alloc_rq_frame can't alloc "
0829                      "frame\n");
0830             goto err_out_free_rq_buf;
0831         }
0832     }
0833 
0834     /*
0835      * Initialization done with PCI system, hardware, firmware.
0836      * Add host to SCSI
0837      */
0838     err = scsi_add_host(lp->host, &pdev->dev);
0839     if (err) {
0840         shost_printk(KERN_ERR, fnic->lport->host,
0841                  "fnic: scsi_add_host failed...exiting\n");
0842         goto err_out_free_rq_buf;
0843     }
0844 
0845     /* Start local port initiatialization */
0846 
0847     lp->link_up = 0;
0848 
0849     lp->max_retry_count = fnic->config.flogi_retries;
0850     lp->max_rport_retry_count = fnic->config.plogi_retries;
0851     lp->service_params = (FCP_SPPF_INIT_FCN | FCP_SPPF_RD_XRDY_DIS |
0852                   FCP_SPPF_CONF_COMPL);
0853     if (fnic->config.flags & VFCF_FCP_SEQ_LVL_ERR)
0854         lp->service_params |= FCP_SPPF_RETRY;
0855 
0856     lp->boot_time = jiffies;
0857     lp->e_d_tov = fnic->config.ed_tov;
0858     lp->r_a_tov = fnic->config.ra_tov;
0859     lp->link_supported_speeds = FC_PORTSPEED_10GBIT;
0860     fc_set_wwnn(lp, fnic->config.node_wwn);
0861     fc_set_wwpn(lp, fnic->config.port_wwn);
0862 
0863     fcoe_libfc_config(lp, &fnic->ctlr, &fnic_transport_template, 0);
0864 
0865     if (!fc_exch_mgr_alloc(lp, FC_CLASS_3, FCPIO_HOST_EXCH_RANGE_START,
0866                    FCPIO_HOST_EXCH_RANGE_END, NULL)) {
0867         err = -ENOMEM;
0868         goto err_out_remove_scsi_host;
0869     }
0870 
0871     fc_lport_init_stats(lp);
0872     fnic->stats_reset_time = jiffies;
0873 
0874     fc_lport_config(lp);
0875 
0876     if (fc_set_mfs(lp, fnic->config.maxdatafieldsize +
0877                sizeof(struct fc_frame_header))) {
0878         err = -EINVAL;
0879         goto err_out_free_exch_mgr;
0880     }
0881     fc_host_maxframe_size(lp->host) = lp->mfs;
0882     fc_host_dev_loss_tmo(lp->host) = fnic->config.port_down_timeout / 1000;
0883 
0884     sprintf(fc_host_symbolic_name(lp->host),
0885         DRV_NAME " v" DRV_VERSION " over %s", fnic->name);
0886 
0887     spin_lock_irqsave(&fnic_list_lock, flags);
0888     list_add_tail(&fnic->list, &fnic_list);
0889     spin_unlock_irqrestore(&fnic_list_lock, flags);
0890 
0891     INIT_WORK(&fnic->link_work, fnic_handle_link);
0892     INIT_WORK(&fnic->frame_work, fnic_handle_frame);
0893     skb_queue_head_init(&fnic->frame_queue);
0894     skb_queue_head_init(&fnic->tx_queue);
0895 
0896     /* Enable all queues */
0897     for (i = 0; i < fnic->raw_wq_count; i++)
0898         vnic_wq_enable(&fnic->wq[i]);
0899     for (i = 0; i < fnic->wq_copy_count; i++)
0900         vnic_wq_copy_enable(&fnic->wq_copy[i]);
0901 
0902     fc_fabric_login(lp);
0903 
0904     err = fnic_request_intr(fnic);
0905     if (err) {
0906         shost_printk(KERN_ERR, fnic->lport->host,
0907                  "Unable to request irq.\n");
0908         goto err_out_free_exch_mgr;
0909     }
0910 
0911     vnic_dev_enable(fnic->vdev);
0912 
0913     for (i = 0; i < fnic->intr_count; i++)
0914         vnic_intr_unmask(&fnic->intr[i]);
0915 
0916     fnic_notify_timer_start(fnic);
0917 
0918     return 0;
0919 
0920 err_out_free_exch_mgr:
0921     fc_exch_mgr_free(lp);
0922 err_out_remove_scsi_host:
0923     fc_remove_host(lp->host);
0924     scsi_remove_host(lp->host);
0925 err_out_free_rq_buf:
0926     for (i = 0; i < fnic->rq_count; i++)
0927         vnic_rq_clean(&fnic->rq[i], fnic_free_rq_buf);
0928     vnic_dev_notify_unset(fnic->vdev);
0929 err_out_free_max_pool:
0930     mempool_destroy(fnic->io_sgl_pool[FNIC_SGL_CACHE_MAX]);
0931 err_out_free_dflt_pool:
0932     mempool_destroy(fnic->io_sgl_pool[FNIC_SGL_CACHE_DFLT]);
0933 err_out_free_ioreq_pool:
0934     mempool_destroy(fnic->io_req_pool);
0935 err_out_free_resources:
0936     fnic_free_vnic_resources(fnic);
0937 err_out_clear_intr:
0938     fnic_clear_intr_mode(fnic);
0939 err_out_dev_close:
0940     vnic_dev_close(fnic->vdev);
0941 err_out_dev_cmd_deinit:
0942 err_out_vnic_unregister:
0943     vnic_dev_unregister(fnic->vdev);
0944 err_out_iounmap:
0945     fnic_iounmap(fnic);
0946 err_out_release_regions:
0947     pci_release_regions(pdev);
0948 err_out_disable_device:
0949     pci_disable_device(pdev);
0950 err_out_free_hba:
0951     fnic_stats_debugfs_remove(fnic);
0952     scsi_host_put(lp->host);
0953 err_out:
0954     return err;
0955 }
0956 
0957 static void fnic_remove(struct pci_dev *pdev)
0958 {
0959     struct fnic *fnic = pci_get_drvdata(pdev);
0960     struct fc_lport *lp = fnic->lport;
0961     unsigned long flags;
0962 
0963     /*
0964      * Mark state so that the workqueue thread stops forwarding
0965      * received frames and link events to the local port. ISR and
0966      * other threads that can queue work items will also stop
0967      * creating work items on the fnic workqueue
0968      */
0969     spin_lock_irqsave(&fnic->fnic_lock, flags);
0970     fnic->stop_rx_link_events = 1;
0971     spin_unlock_irqrestore(&fnic->fnic_lock, flags);
0972 
0973     if (vnic_dev_get_intr_mode(fnic->vdev) == VNIC_DEV_INTR_MODE_MSI)
0974         del_timer_sync(&fnic->notify_timer);
0975 
0976     /*
0977      * Flush the fnic event queue. After this call, there should
0978      * be no event queued for this fnic device in the workqueue
0979      */
0980     flush_workqueue(fnic_event_queue);
0981     skb_queue_purge(&fnic->frame_queue);
0982     skb_queue_purge(&fnic->tx_queue);
0983 
0984     if (fnic->config.flags & VFCF_FIP_CAPABLE) {
0985         del_timer_sync(&fnic->fip_timer);
0986         skb_queue_purge(&fnic->fip_frame_queue);
0987         fnic_fcoe_reset_vlans(fnic);
0988         fnic_fcoe_evlist_free(fnic);
0989     }
0990 
0991     /*
0992      * Log off the fabric. This stops all remote ports, dns port,
0993      * logs off the fabric. This flushes all rport, disc, lport work
0994      * before returning
0995      */
0996     fc_fabric_logoff(fnic->lport);
0997 
0998     spin_lock_irqsave(&fnic->fnic_lock, flags);
0999     fnic->in_remove = 1;
1000     spin_unlock_irqrestore(&fnic->fnic_lock, flags);
1001 
1002     fcoe_ctlr_destroy(&fnic->ctlr);
1003     fc_lport_destroy(lp);
1004     fnic_stats_debugfs_remove(fnic);
1005 
1006     /*
1007      * This stops the fnic device, masks all interrupts. Completed
1008      * CQ entries are drained. Posted WQ/RQ/Copy-WQ entries are
1009      * cleaned up
1010      */
1011     fnic_cleanup(fnic);
1012 
1013     BUG_ON(!skb_queue_empty(&fnic->frame_queue));
1014     BUG_ON(!skb_queue_empty(&fnic->tx_queue));
1015 
1016     spin_lock_irqsave(&fnic_list_lock, flags);
1017     list_del(&fnic->list);
1018     spin_unlock_irqrestore(&fnic_list_lock, flags);
1019 
1020     fc_remove_host(fnic->lport->host);
1021     scsi_remove_host(fnic->lport->host);
1022     fc_exch_mgr_free(fnic->lport);
1023     vnic_dev_notify_unset(fnic->vdev);
1024     fnic_free_intr(fnic);
1025     fnic_free_vnic_resources(fnic);
1026     fnic_clear_intr_mode(fnic);
1027     vnic_dev_close(fnic->vdev);
1028     vnic_dev_unregister(fnic->vdev);
1029     fnic_iounmap(fnic);
1030     pci_release_regions(pdev);
1031     pci_disable_device(pdev);
1032     scsi_host_put(lp->host);
1033 }
1034 
1035 static struct pci_driver fnic_driver = {
1036     .name = DRV_NAME,
1037     .id_table = fnic_id_table,
1038     .probe = fnic_probe,
1039     .remove = fnic_remove,
1040 };
1041 
1042 static int __init fnic_init_module(void)
1043 {
1044     size_t len;
1045     int err = 0;
1046 
1047     printk(KERN_INFO PFX "%s, ver %s\n", DRV_DESCRIPTION, DRV_VERSION);
1048 
1049     /* Create debugfs entries for fnic */
1050     err = fnic_debugfs_init();
1051     if (err < 0) {
1052         printk(KERN_ERR PFX "Failed to create fnic directory "
1053                 "for tracing and stats logging\n");
1054         fnic_debugfs_terminate();
1055     }
1056 
1057     /* Allocate memory for trace buffer */
1058     err = fnic_trace_buf_init();
1059     if (err < 0) {
1060         printk(KERN_ERR PFX
1061                "Trace buffer initialization Failed. "
1062                "Fnic Tracing utility is disabled\n");
1063         fnic_trace_free();
1064     }
1065 
1066     /* Allocate memory for fc trace buffer */
1067     err = fnic_fc_trace_init();
1068     if (err < 0) {
1069         printk(KERN_ERR PFX "FC trace buffer initialization Failed "
1070                "FC frame tracing utility is disabled\n");
1071         fnic_fc_trace_free();
1072     }
1073 
1074     /* Create a cache for allocation of default size sgls */
1075     len = sizeof(struct fnic_dflt_sgl_list);
1076     fnic_sgl_cache[FNIC_SGL_CACHE_DFLT] = kmem_cache_create
1077         ("fnic_sgl_dflt", len + FNIC_SG_DESC_ALIGN, FNIC_SG_DESC_ALIGN,
1078          SLAB_HWCACHE_ALIGN,
1079          NULL);
1080     if (!fnic_sgl_cache[FNIC_SGL_CACHE_DFLT]) {
1081         printk(KERN_ERR PFX "failed to create fnic dflt sgl slab\n");
1082         err = -ENOMEM;
1083         goto err_create_fnic_sgl_slab_dflt;
1084     }
1085 
1086     /* Create a cache for allocation of max size sgls*/
1087     len = sizeof(struct fnic_sgl_list);
1088     fnic_sgl_cache[FNIC_SGL_CACHE_MAX] = kmem_cache_create
1089         ("fnic_sgl_max", len + FNIC_SG_DESC_ALIGN, FNIC_SG_DESC_ALIGN,
1090           SLAB_HWCACHE_ALIGN,
1091           NULL);
1092     if (!fnic_sgl_cache[FNIC_SGL_CACHE_MAX]) {
1093         printk(KERN_ERR PFX "failed to create fnic max sgl slab\n");
1094         err = -ENOMEM;
1095         goto err_create_fnic_sgl_slab_max;
1096     }
1097 
1098     /* Create a cache of io_req structs for use via mempool */
1099     fnic_io_req_cache = kmem_cache_create("fnic_io_req",
1100                           sizeof(struct fnic_io_req),
1101                           0, SLAB_HWCACHE_ALIGN, NULL);
1102     if (!fnic_io_req_cache) {
1103         printk(KERN_ERR PFX "failed to create fnic io_req slab\n");
1104         err = -ENOMEM;
1105         goto err_create_fnic_ioreq_slab;
1106     }
1107 
1108     fnic_event_queue = create_singlethread_workqueue("fnic_event_wq");
1109     if (!fnic_event_queue) {
1110         printk(KERN_ERR PFX "fnic work queue create failed\n");
1111         err = -ENOMEM;
1112         goto err_create_fnic_workq;
1113     }
1114 
1115     fnic_fip_queue = create_singlethread_workqueue("fnic_fip_q");
1116     if (!fnic_fip_queue) {
1117         printk(KERN_ERR PFX "fnic FIP work queue create failed\n");
1118         err = -ENOMEM;
1119         goto err_create_fip_workq;
1120     }
1121 
1122     fnic_fc_transport = fc_attach_transport(&fnic_fc_functions);
1123     if (!fnic_fc_transport) {
1124         printk(KERN_ERR PFX "fc_attach_transport error\n");
1125         err = -ENOMEM;
1126         goto err_fc_transport;
1127     }
1128 
1129     /* register the driver with PCI system */
1130     err = pci_register_driver(&fnic_driver);
1131     if (err < 0) {
1132         printk(KERN_ERR PFX "pci register error\n");
1133         goto err_pci_register;
1134     }
1135     return err;
1136 
1137 err_pci_register:
1138     fc_release_transport(fnic_fc_transport);
1139 err_fc_transport:
1140     destroy_workqueue(fnic_fip_queue);
1141 err_create_fip_workq:
1142     destroy_workqueue(fnic_event_queue);
1143 err_create_fnic_workq:
1144     kmem_cache_destroy(fnic_io_req_cache);
1145 err_create_fnic_ioreq_slab:
1146     kmem_cache_destroy(fnic_sgl_cache[FNIC_SGL_CACHE_MAX]);
1147 err_create_fnic_sgl_slab_max:
1148     kmem_cache_destroy(fnic_sgl_cache[FNIC_SGL_CACHE_DFLT]);
1149 err_create_fnic_sgl_slab_dflt:
1150     fnic_trace_free();
1151     fnic_fc_trace_free();
1152     fnic_debugfs_terminate();
1153     return err;
1154 }
1155 
1156 static void __exit fnic_cleanup_module(void)
1157 {
1158     pci_unregister_driver(&fnic_driver);
1159     destroy_workqueue(fnic_event_queue);
1160     if (fnic_fip_queue)
1161         destroy_workqueue(fnic_fip_queue);
1162     kmem_cache_destroy(fnic_sgl_cache[FNIC_SGL_CACHE_MAX]);
1163     kmem_cache_destroy(fnic_sgl_cache[FNIC_SGL_CACHE_DFLT]);
1164     kmem_cache_destroy(fnic_io_req_cache);
1165     fc_release_transport(fnic_fc_transport);
1166     fnic_trace_free();
1167     fnic_fc_trace_free();
1168     fnic_debugfs_terminate();
1169 }
1170 
1171 module_init(fnic_init_module);
1172 module_exit(fnic_cleanup_module);