Back to home page

OSCL-LXR

 
 

    


0001 /* bnx2fc_fcoe.c: QLogic Linux FCoE offload driver.
0002  * This file contains the code that interacts with libfc, libfcoe,
0003  * cnic modules to create FCoE instances, send/receive non-offloaded
0004  * FIP/FCoE packets, listen to link events etc.
0005  *
0006  * Copyright (c) 2008-2013 Broadcom Corporation
0007  * Copyright (c) 2014-2016 QLogic Corporation
0008  * Copyright (c) 2016-2017 Cavium Inc.
0009  *
0010  * This program is free software; you can redistribute it and/or modify
0011  * it under the terms of the GNU General Public License as published by
0012  * the Free Software Foundation.
0013  *
0014  * Written by: Bhanu Prakash Gollapudi (bprakash@broadcom.com)
0015  */
0016 
0017 #include "bnx2fc.h"
0018 
0019 #include <linux/ethtool.h>
0020 
0021 static struct list_head adapter_list;
0022 static struct list_head if_list;
0023 static u32 adapter_count;
0024 static DEFINE_MUTEX(bnx2fc_dev_lock);
0025 DEFINE_PER_CPU(struct bnx2fc_percpu_s, bnx2fc_percpu);
0026 
0027 #define DRV_MODULE_NAME     "bnx2fc"
0028 #define DRV_MODULE_VERSION  BNX2FC_VERSION
0029 #define DRV_MODULE_RELDATE  "October 15, 2015"
0030 
0031 
0032 static char version[] =
0033         "QLogic FCoE Driver " DRV_MODULE_NAME \
0034         " v" DRV_MODULE_VERSION " (" DRV_MODULE_RELDATE ")\n";
0035 
0036 
0037 MODULE_AUTHOR("Bhanu Prakash Gollapudi <bprakash@broadcom.com>");
0038 MODULE_DESCRIPTION("QLogic FCoE Driver");
0039 MODULE_LICENSE("GPL");
0040 MODULE_VERSION(DRV_MODULE_VERSION);
0041 
0042 #define BNX2FC_MAX_QUEUE_DEPTH  256
0043 #define BNX2FC_MIN_QUEUE_DEPTH  32
0044 #define FCOE_WORD_TO_BYTE  4
0045 
0046 static struct scsi_transport_template   *bnx2fc_transport_template;
0047 static struct scsi_transport_template   *bnx2fc_vport_xport_template;
0048 
0049 struct workqueue_struct *bnx2fc_wq;
0050 
0051 /* bnx2fc structure needs only one instance of the fcoe_percpu_s structure.
0052  * Here the io threads are per cpu but the l2 thread is just one
0053  */
0054 struct fcoe_percpu_s bnx2fc_global;
0055 static DEFINE_SPINLOCK(bnx2fc_global_lock);
0056 
0057 static struct cnic_ulp_ops bnx2fc_cnic_cb;
0058 static struct libfc_function_template bnx2fc_libfc_fcn_templ;
0059 static struct scsi_host_template bnx2fc_shost_template;
0060 static struct fc_function_template bnx2fc_transport_function;
0061 static struct fcoe_sysfs_function_template bnx2fc_fcoe_sysfs_templ;
0062 static struct fc_function_template bnx2fc_vport_xport_function;
0063 static int bnx2fc_create(struct net_device *netdev, enum fip_mode fip_mode);
0064 static void __bnx2fc_destroy(struct bnx2fc_interface *interface);
0065 static int bnx2fc_destroy(struct net_device *net_device);
0066 static int bnx2fc_enable(struct net_device *netdev);
0067 static int bnx2fc_disable(struct net_device *netdev);
0068 
0069 /* fcoe_syfs control interface handlers */
0070 static int bnx2fc_ctlr_alloc(struct net_device *netdev);
0071 static int bnx2fc_ctlr_enabled(struct fcoe_ctlr_device *cdev);
0072 
0073 static void bnx2fc_recv_frame(struct sk_buff *skb);
0074 
0075 static void bnx2fc_start_disc(struct bnx2fc_interface *interface);
0076 static int bnx2fc_shost_config(struct fc_lport *lport, struct device *dev);
0077 static int bnx2fc_lport_config(struct fc_lport *lport);
0078 static int bnx2fc_em_config(struct fc_lport *lport, struct bnx2fc_hba *hba);
0079 static int bnx2fc_bind_adapter_devices(struct bnx2fc_hba *hba);
0080 static void bnx2fc_unbind_adapter_devices(struct bnx2fc_hba *hba);
0081 static int bnx2fc_bind_pcidev(struct bnx2fc_hba *hba);
0082 static void bnx2fc_unbind_pcidev(struct bnx2fc_hba *hba);
0083 static struct fc_lport *bnx2fc_if_create(struct bnx2fc_interface *interface,
0084                   struct device *parent, int npiv);
0085 static void bnx2fc_port_destroy(struct fcoe_port *port);
0086 
0087 static struct bnx2fc_hba *bnx2fc_hba_lookup(struct net_device *phys_dev);
0088 static struct bnx2fc_interface *bnx2fc_interface_lookup(struct net_device
0089                             *phys_dev);
0090 static inline void bnx2fc_interface_put(struct bnx2fc_interface *interface);
0091 static struct bnx2fc_hba *bnx2fc_find_hba_for_cnic(struct cnic_dev *cnic);
0092 
0093 static int bnx2fc_fw_init(struct bnx2fc_hba *hba);
0094 static void bnx2fc_fw_destroy(struct bnx2fc_hba *hba);
0095 
0096 static void bnx2fc_port_shutdown(struct fc_lport *lport);
0097 static void bnx2fc_stop(struct bnx2fc_interface *interface);
0098 static int __init bnx2fc_mod_init(void);
0099 static void __exit bnx2fc_mod_exit(void);
0100 
0101 unsigned int bnx2fc_debug_level;
0102 module_param_named(debug_logging, bnx2fc_debug_level, int, S_IRUGO|S_IWUSR);
0103 MODULE_PARM_DESC(debug_logging,
0104         "Option to enable extended logging,\n"
0105         "\t\tDefault is 0 - no logging.\n"
0106         "\t\t0x01 - SCSI cmd error, cleanup.\n"
0107         "\t\t0x02 - Session setup, cleanup, etc.\n"
0108         "\t\t0x04 - lport events, link, mtu, etc.\n"
0109         "\t\t0x08 - ELS logs.\n"
0110         "\t\t0x10 - fcoe L2 fame related logs.\n"
0111         "\t\t0xff - LOG all messages.");
0112 
0113 static uint bnx2fc_devloss_tmo;
0114 module_param_named(devloss_tmo, bnx2fc_devloss_tmo, uint, S_IRUGO);
0115 MODULE_PARM_DESC(devloss_tmo, " Change devloss_tmo for the remote ports "
0116     "attached via bnx2fc.");
0117 
0118 static uint bnx2fc_max_luns = BNX2FC_MAX_LUN;
0119 module_param_named(max_luns, bnx2fc_max_luns, uint, S_IRUGO);
0120 MODULE_PARM_DESC(max_luns, " Change the default max_lun per SCSI host. Default "
0121     "0xffff.");
0122 
0123 static uint bnx2fc_queue_depth;
0124 module_param_named(queue_depth, bnx2fc_queue_depth, uint, S_IRUGO);
0125 MODULE_PARM_DESC(queue_depth, " Change the default queue depth of SCSI devices "
0126     "attached via bnx2fc.");
0127 
0128 static uint bnx2fc_log_fka;
0129 module_param_named(log_fka, bnx2fc_log_fka, uint, S_IRUGO|S_IWUSR);
0130 MODULE_PARM_DESC(log_fka, " Print message to kernel log when fcoe is "
0131     "initiating a FIP keep alive when debug logging is enabled.");
0132 
0133 static inline struct net_device *bnx2fc_netdev(const struct fc_lport *lport)
0134 {
0135     return ((struct bnx2fc_interface *)
0136         ((struct fcoe_port *)lport_priv(lport))->priv)->netdev;
0137 }
0138 
0139 static void bnx2fc_fcf_get_vlan_id(struct fcoe_fcf_device *fcf_dev)
0140 {
0141     struct fcoe_ctlr_device *ctlr_dev =
0142         fcoe_fcf_dev_to_ctlr_dev(fcf_dev);
0143     struct fcoe_ctlr *ctlr = fcoe_ctlr_device_priv(ctlr_dev);
0144     struct bnx2fc_interface *fcoe = fcoe_ctlr_priv(ctlr);
0145 
0146     fcf_dev->vlan_id = fcoe->vlan_id;
0147 }
0148 
0149 static void bnx2fc_clean_rx_queue(struct fc_lport *lp)
0150 {
0151     struct fcoe_percpu_s *bg;
0152     struct fcoe_rcv_info *fr;
0153     struct sk_buff_head *list;
0154     struct sk_buff *skb, *next;
0155 
0156     bg = &bnx2fc_global;
0157     spin_lock_bh(&bg->fcoe_rx_list.lock);
0158     list = &bg->fcoe_rx_list;
0159     skb_queue_walk_safe(list, skb, next) {
0160         fr = fcoe_dev_from_skb(skb);
0161         if (fr->fr_dev == lp) {
0162             __skb_unlink(skb, list);
0163             kfree_skb(skb);
0164         }
0165     }
0166     spin_unlock_bh(&bg->fcoe_rx_list.lock);
0167 }
0168 
0169 int bnx2fc_get_paged_crc_eof(struct sk_buff *skb, int tlen)
0170 {
0171     int rc;
0172     spin_lock(&bnx2fc_global_lock);
0173     rc = fcoe_get_paged_crc_eof(skb, tlen, &bnx2fc_global);
0174     spin_unlock(&bnx2fc_global_lock);
0175 
0176     return rc;
0177 }
0178 
0179 static void bnx2fc_abort_io(struct fc_lport *lport)
0180 {
0181     /*
0182      * This function is no-op for bnx2fc, but we do
0183      * not want to leave it as NULL either, as libfc
0184      * can call the default function which is
0185      * fc_fcp_abort_io.
0186      */
0187 }
0188 
0189 static void bnx2fc_cleanup(struct fc_lport *lport)
0190 {
0191     struct fcoe_port *port = lport_priv(lport);
0192     struct bnx2fc_interface *interface = port->priv;
0193     struct bnx2fc_hba *hba = interface->hba;
0194     struct bnx2fc_rport *tgt;
0195     int i;
0196 
0197     BNX2FC_MISC_DBG("Entered %s\n", __func__);
0198     mutex_lock(&hba->hba_mutex);
0199     spin_lock_bh(&hba->hba_lock);
0200     for (i = 0; i < BNX2FC_NUM_MAX_SESS; i++) {
0201         tgt = hba->tgt_ofld_list[i];
0202         if (tgt) {
0203             /* Cleanup IOs belonging to requested vport */
0204             if (tgt->port == port) {
0205                 spin_unlock_bh(&hba->hba_lock);
0206                 BNX2FC_TGT_DBG(tgt, "flush/cleanup\n");
0207                 bnx2fc_flush_active_ios(tgt);
0208                 spin_lock_bh(&hba->hba_lock);
0209             }
0210         }
0211     }
0212     spin_unlock_bh(&hba->hba_lock);
0213     mutex_unlock(&hba->hba_mutex);
0214 }
0215 
0216 static int bnx2fc_xmit_l2_frame(struct bnx2fc_rport *tgt,
0217                  struct fc_frame *fp)
0218 {
0219     struct fc_rport_priv *rdata = tgt->rdata;
0220     struct fc_frame_header *fh;
0221     int rc = 0;
0222 
0223     fh = fc_frame_header_get(fp);
0224     BNX2FC_TGT_DBG(tgt, "Xmit L2 frame rport = 0x%x, oxid = 0x%x, "
0225             "r_ctl = 0x%x\n", rdata->ids.port_id,
0226             ntohs(fh->fh_ox_id), fh->fh_r_ctl);
0227     if ((fh->fh_type == FC_TYPE_ELS) &&
0228         (fh->fh_r_ctl == FC_RCTL_ELS_REQ)) {
0229 
0230         switch (fc_frame_payload_op(fp)) {
0231         case ELS_ADISC:
0232             rc = bnx2fc_send_adisc(tgt, fp);
0233             break;
0234         case ELS_LOGO:
0235             rc = bnx2fc_send_logo(tgt, fp);
0236             break;
0237         case ELS_RLS:
0238             rc = bnx2fc_send_rls(tgt, fp);
0239             break;
0240         default:
0241             break;
0242         }
0243     } else if ((fh->fh_type ==  FC_TYPE_BLS) &&
0244         (fh->fh_r_ctl == FC_RCTL_BA_ABTS))
0245         BNX2FC_TGT_DBG(tgt, "ABTS frame\n");
0246     else {
0247         BNX2FC_TGT_DBG(tgt, "Send L2 frame type 0x%x "
0248                 "rctl 0x%x thru non-offload path\n",
0249                 fh->fh_type, fh->fh_r_ctl);
0250         return -ENODEV;
0251     }
0252     if (rc)
0253         return -ENOMEM;
0254     else
0255         return 0;
0256 }
0257 
0258 /**
0259  * bnx2fc_xmit - bnx2fc's FCoE frame transmit function
0260  *
0261  * @lport:  the associated local port
0262  * @fp: the fc_frame to be transmitted
0263  */
0264 static int bnx2fc_xmit(struct fc_lport *lport, struct fc_frame *fp)
0265 {
0266     struct ethhdr       *eh;
0267     struct fcoe_crc_eof *cp;
0268     struct sk_buff      *skb;
0269     struct fc_frame_header  *fh;
0270     struct bnx2fc_interface *interface;
0271     struct fcoe_ctlr        *ctlr;
0272     struct bnx2fc_hba *hba;
0273     struct fcoe_port    *port;
0274     struct fcoe_hdr     *hp;
0275     struct bnx2fc_rport *tgt;
0276     u8          sof, eof;
0277     u32         crc;
0278     unsigned int        hlen, tlen, elen;
0279     int         wlen, rc = 0;
0280 
0281     port = (struct fcoe_port *)lport_priv(lport);
0282     interface = port->priv;
0283     ctlr = bnx2fc_to_ctlr(interface);
0284     hba = interface->hba;
0285 
0286     fh = fc_frame_header_get(fp);
0287 
0288     skb = fp_skb(fp);
0289     if (!lport->link_up) {
0290         BNX2FC_HBA_DBG(lport, "bnx2fc_xmit link down\n");
0291         kfree_skb(skb);
0292         return 0;
0293     }
0294 
0295     if (unlikely(fh->fh_r_ctl == FC_RCTL_ELS_REQ)) {
0296         if (!ctlr->sel_fcf) {
0297             BNX2FC_HBA_DBG(lport, "FCF not selected yet!\n");
0298             kfree_skb(skb);
0299             return -EINVAL;
0300         }
0301         if (fcoe_ctlr_els_send(ctlr, lport, skb))
0302             return 0;
0303     }
0304 
0305     sof = fr_sof(fp);
0306     eof = fr_eof(fp);
0307 
0308     /*
0309      * Snoop the frame header to check if the frame is for
0310      * an offloaded session
0311      */
0312     /*
0313      * tgt_ofld_list access is synchronized using
0314      * both hba mutex and hba lock. Atleast hba mutex or
0315      * hba lock needs to be held for read access.
0316      */
0317 
0318     spin_lock_bh(&hba->hba_lock);
0319     tgt = bnx2fc_tgt_lookup(port, ntoh24(fh->fh_d_id));
0320     if (tgt && (test_bit(BNX2FC_FLAG_SESSION_READY, &tgt->flags))) {
0321         /* This frame is for offloaded session */
0322         BNX2FC_HBA_DBG(lport, "xmit: Frame is for offloaded session "
0323                 "port_id = 0x%x\n", ntoh24(fh->fh_d_id));
0324         spin_unlock_bh(&hba->hba_lock);
0325         rc = bnx2fc_xmit_l2_frame(tgt, fp);
0326         if (rc != -ENODEV) {
0327             kfree_skb(skb);
0328             return rc;
0329         }
0330     } else {
0331         spin_unlock_bh(&hba->hba_lock);
0332     }
0333 
0334     elen = sizeof(struct ethhdr);
0335     hlen = sizeof(struct fcoe_hdr);
0336     tlen = sizeof(struct fcoe_crc_eof);
0337     wlen = (skb->len - tlen + sizeof(crc)) / FCOE_WORD_TO_BYTE;
0338 
0339     skb->ip_summed = CHECKSUM_NONE;
0340     crc = fcoe_fc_crc(fp);
0341 
0342     /* copy port crc and eof to the skb buff */
0343     if (skb_is_nonlinear(skb)) {
0344         skb_frag_t *frag;
0345         if (bnx2fc_get_paged_crc_eof(skb, tlen)) {
0346             kfree_skb(skb);
0347             return -ENOMEM;
0348         }
0349         frag = &skb_shinfo(skb)->frags[skb_shinfo(skb)->nr_frags - 1];
0350         cp = kmap_atomic(skb_frag_page(frag)) + skb_frag_off(frag);
0351     } else {
0352         cp = skb_put(skb, tlen);
0353     }
0354 
0355     memset(cp, 0, sizeof(*cp));
0356     cp->fcoe_eof = eof;
0357     cp->fcoe_crc32 = cpu_to_le32(~crc);
0358     if (skb_is_nonlinear(skb)) {
0359         kunmap_atomic(cp);
0360         cp = NULL;
0361     }
0362 
0363     /* adjust skb network/transport offsets to match mac/fcoe/port */
0364     skb_push(skb, elen + hlen);
0365     skb_reset_mac_header(skb);
0366     skb_reset_network_header(skb);
0367     skb->mac_len = elen;
0368     skb->protocol = htons(ETH_P_FCOE);
0369     skb->dev = interface->netdev;
0370 
0371     /* fill up mac and fcoe headers */
0372     eh = eth_hdr(skb);
0373     eh->h_proto = htons(ETH_P_FCOE);
0374     if (ctlr->map_dest)
0375         fc_fcoe_set_mac(eh->h_dest, fh->fh_d_id);
0376     else
0377         /* insert GW address */
0378         memcpy(eh->h_dest, ctlr->dest_addr, ETH_ALEN);
0379 
0380     if (unlikely(ctlr->flogi_oxid != FC_XID_UNKNOWN))
0381         memcpy(eh->h_source, ctlr->ctl_src_addr, ETH_ALEN);
0382     else
0383         memcpy(eh->h_source, port->data_src_addr, ETH_ALEN);
0384 
0385     hp = (struct fcoe_hdr *)(eh + 1);
0386     memset(hp, 0, sizeof(*hp));
0387     if (FC_FCOE_VER)
0388         FC_FCOE_ENCAPS_VER(hp, FC_FCOE_VER);
0389     hp->fcoe_sof = sof;
0390 
0391     /* fcoe lso, mss is in max_payload which is non-zero for FCP data */
0392     if (lport->seq_offload && fr_max_payload(fp)) {
0393         skb_shinfo(skb)->gso_type = SKB_GSO_FCOE;
0394         skb_shinfo(skb)->gso_size = fr_max_payload(fp);
0395     } else {
0396         skb_shinfo(skb)->gso_type = 0;
0397         skb_shinfo(skb)->gso_size = 0;
0398     }
0399 
0400     /*update tx stats */
0401     this_cpu_inc(lport->stats->TxFrames);
0402     this_cpu_add(lport->stats->TxWords, wlen);
0403 
0404     /* send down to lld */
0405     fr_dev(fp) = lport;
0406     if (port->fcoe_pending_queue.qlen)
0407         fcoe_check_wait_queue(lport, skb);
0408     else if (fcoe_start_io(skb))
0409         fcoe_check_wait_queue(lport, skb);
0410 
0411     return 0;
0412 }
0413 
0414 /**
0415  * bnx2fc_rcv - This is bnx2fc's receive function called by NET_RX_SOFTIRQ
0416  *
0417  * @skb:    the receive socket buffer
0418  * @dev:    associated net device
0419  * @ptype:  context
0420  * @olddev: last device
0421  *
0422  * This function receives the packet and builds FC frame and passes it up
0423  */
0424 static int bnx2fc_rcv(struct sk_buff *skb, struct net_device *dev,
0425         struct packet_type *ptype, struct net_device *olddev)
0426 {
0427     struct fc_lport *lport;
0428     struct bnx2fc_interface *interface;
0429     struct fcoe_ctlr *ctlr;
0430     struct fcoe_rcv_info *fr;
0431     struct fcoe_percpu_s *bg;
0432     struct sk_buff *tmp_skb;
0433 
0434     interface = container_of(ptype, struct bnx2fc_interface,
0435                  fcoe_packet_type);
0436     ctlr = bnx2fc_to_ctlr(interface);
0437     lport = ctlr->lp;
0438 
0439     if (unlikely(lport == NULL)) {
0440         printk(KERN_ERR PFX "bnx2fc_rcv: lport is NULL\n");
0441         goto err;
0442     }
0443 
0444     tmp_skb = skb_share_check(skb, GFP_ATOMIC);
0445     if (!tmp_skb)
0446         goto err;
0447 
0448     skb = tmp_skb;
0449 
0450     if (unlikely(eth_hdr(skb)->h_proto != htons(ETH_P_FCOE))) {
0451         printk(KERN_ERR PFX "bnx2fc_rcv: Wrong FC type frame\n");
0452         goto err;
0453     }
0454 
0455     /*
0456      * Check for minimum frame length, and make sure required FCoE
0457      * and FC headers are pulled into the linear data area.
0458      */
0459     if (unlikely((skb->len < FCOE_MIN_FRAME) ||
0460         !pskb_may_pull(skb, FCOE_HEADER_LEN)))
0461         goto err;
0462 
0463     skb_set_transport_header(skb, sizeof(struct fcoe_hdr));
0464 
0465     fr = fcoe_dev_from_skb(skb);
0466     fr->fr_dev = lport;
0467 
0468     bg = &bnx2fc_global;
0469     spin_lock(&bg->fcoe_rx_list.lock);
0470 
0471     __skb_queue_tail(&bg->fcoe_rx_list, skb);
0472     if (bg->fcoe_rx_list.qlen == 1)
0473         wake_up_process(bg->kthread);
0474 
0475     spin_unlock(&bg->fcoe_rx_list.lock);
0476 
0477     return 0;
0478 err:
0479     kfree_skb(skb);
0480     return -1;
0481 }
0482 
0483 static int bnx2fc_l2_rcv_thread(void *arg)
0484 {
0485     struct fcoe_percpu_s *bg = arg;
0486     struct sk_buff *skb;
0487 
0488     set_user_nice(current, MIN_NICE);
0489     set_current_state(TASK_INTERRUPTIBLE);
0490     while (!kthread_should_stop()) {
0491         schedule();
0492         spin_lock_bh(&bg->fcoe_rx_list.lock);
0493         while ((skb = __skb_dequeue(&bg->fcoe_rx_list)) != NULL) {
0494             spin_unlock_bh(&bg->fcoe_rx_list.lock);
0495             bnx2fc_recv_frame(skb);
0496             spin_lock_bh(&bg->fcoe_rx_list.lock);
0497         }
0498         __set_current_state(TASK_INTERRUPTIBLE);
0499         spin_unlock_bh(&bg->fcoe_rx_list.lock);
0500     }
0501     __set_current_state(TASK_RUNNING);
0502     return 0;
0503 }
0504 
0505 
0506 static void bnx2fc_recv_frame(struct sk_buff *skb)
0507 {
0508     u64 crc_err;
0509     u32 fr_len, fr_crc;
0510     struct fc_lport *lport;
0511     struct fcoe_rcv_info *fr;
0512     struct fc_frame_header *fh;
0513     struct fcoe_crc_eof crc_eof;
0514     struct fc_frame *fp;
0515     struct fc_lport *vn_port;
0516     struct fcoe_port *port, *phys_port;
0517     u8 *mac = NULL;
0518     u8 *dest_mac = NULL;
0519     struct fcoe_hdr *hp;
0520     struct bnx2fc_interface *interface;
0521     struct fcoe_ctlr *ctlr;
0522 
0523     fr = fcoe_dev_from_skb(skb);
0524     lport = fr->fr_dev;
0525     if (unlikely(lport == NULL)) {
0526         printk(KERN_ERR PFX "Invalid lport struct\n");
0527         kfree_skb(skb);
0528         return;
0529     }
0530 
0531     if (skb_is_nonlinear(skb))
0532         skb_linearize(skb);
0533     mac = eth_hdr(skb)->h_source;
0534     dest_mac = eth_hdr(skb)->h_dest;
0535 
0536     /* Pull the header */
0537     hp = (struct fcoe_hdr *) skb_network_header(skb);
0538     fh = (struct fc_frame_header *) skb_transport_header(skb);
0539     skb_pull(skb, sizeof(struct fcoe_hdr));
0540     fr_len = skb->len - sizeof(struct fcoe_crc_eof);
0541 
0542     this_cpu_inc(lport->stats->RxFrames);
0543     this_cpu_add(lport->stats->RxWords, fr_len / FCOE_WORD_TO_BYTE);
0544 
0545     fp = (struct fc_frame *)skb;
0546     fc_frame_init(fp);
0547     fr_dev(fp) = lport;
0548     fr_sof(fp) = hp->fcoe_sof;
0549     if (skb_copy_bits(skb, fr_len, &crc_eof, sizeof(crc_eof))) {
0550         kfree_skb(skb);
0551         return;
0552     }
0553     fr_eof(fp) = crc_eof.fcoe_eof;
0554     fr_crc(fp) = crc_eof.fcoe_crc32;
0555     if (pskb_trim(skb, fr_len)) {
0556         kfree_skb(skb);
0557         return;
0558     }
0559 
0560     phys_port = lport_priv(lport);
0561     interface = phys_port->priv;
0562     ctlr = bnx2fc_to_ctlr(interface);
0563 
0564     fh = fc_frame_header_get(fp);
0565 
0566     if (ntoh24(&dest_mac[3]) != ntoh24(fh->fh_d_id)) {
0567         BNX2FC_HBA_DBG(lport, "FC frame d_id mismatch with MAC %pM.\n",
0568             dest_mac);
0569         kfree_skb(skb);
0570         return;
0571     }
0572 
0573     vn_port = fc_vport_id_lookup(lport, ntoh24(fh->fh_d_id));
0574     if (vn_port) {
0575         port = lport_priv(vn_port);
0576         if (!ether_addr_equal(port->data_src_addr, dest_mac)) {
0577             BNX2FC_HBA_DBG(lport, "fpma mismatch\n");
0578             kfree_skb(skb);
0579             return;
0580         }
0581     }
0582     if (ctlr->state) {
0583         if (!ether_addr_equal(mac, ctlr->dest_addr)) {
0584             BNX2FC_HBA_DBG(lport, "Wrong source address: mac:%pM dest_addr:%pM.\n",
0585                 mac, ctlr->dest_addr);
0586             kfree_skb(skb);
0587             return;
0588         }
0589     }
0590     if (fh->fh_r_ctl == FC_RCTL_DD_SOL_DATA &&
0591         fh->fh_type == FC_TYPE_FCP) {
0592         /* Drop FCP data. We dont this in L2 path */
0593         kfree_skb(skb);
0594         return;
0595     }
0596     if (fh->fh_r_ctl == FC_RCTL_ELS_REQ &&
0597         fh->fh_type == FC_TYPE_ELS) {
0598         switch (fc_frame_payload_op(fp)) {
0599         case ELS_LOGO:
0600             if (ntoh24(fh->fh_s_id) == FC_FID_FLOGI) {
0601                 /* drop non-FIP LOGO */
0602                 kfree_skb(skb);
0603                 return;
0604             }
0605             break;
0606         }
0607     }
0608 
0609     if (fh->fh_r_ctl == FC_RCTL_BA_ABTS) {
0610         /* Drop incoming ABTS */
0611         kfree_skb(skb);
0612         return;
0613     }
0614 
0615     /*
0616      * If the destination ID from the frame header does not match what we
0617      * have on record for lport and the search for a NPIV port came up
0618      * empty then this is not addressed to our port so simply drop it.
0619      */
0620     if (lport->port_id != ntoh24(fh->fh_d_id) && !vn_port) {
0621         BNX2FC_HBA_DBG(lport, "Dropping frame due to destination mismatch: lport->port_id=%x fh->d_id=%x.\n",
0622             lport->port_id, ntoh24(fh->fh_d_id));
0623         kfree_skb(skb);
0624         return;
0625     }
0626 
0627     fr_crc = le32_to_cpu(fr_crc(fp));
0628 
0629     if (unlikely(fr_crc != ~crc32(~0, skb->data, fr_len))) {
0630         crc_err = this_cpu_inc_return(lport->stats->InvalidCRCCount);
0631         if (crc_err < 5)
0632             printk(KERN_WARNING PFX "dropping frame with "
0633                    "CRC error\n");
0634         kfree_skb(skb);
0635         return;
0636     }
0637     fc_exch_recv(lport, fp);
0638 }
0639 
0640 /**
0641  * bnx2fc_percpu_io_thread - thread per cpu for ios
0642  *
0643  * @arg:    ptr to bnx2fc_percpu_info structure
0644  */
0645 static int bnx2fc_percpu_io_thread(void *arg)
0646 {
0647     struct bnx2fc_percpu_s *p = arg;
0648     struct bnx2fc_work *work, *tmp;
0649     LIST_HEAD(work_list);
0650 
0651     set_user_nice(current, MIN_NICE);
0652     set_current_state(TASK_INTERRUPTIBLE);
0653     while (!kthread_should_stop()) {
0654         schedule();
0655         spin_lock_bh(&p->fp_work_lock);
0656         while (!list_empty(&p->work_list)) {
0657             list_splice_init(&p->work_list, &work_list);
0658             spin_unlock_bh(&p->fp_work_lock);
0659 
0660             list_for_each_entry_safe(work, tmp, &work_list, list) {
0661                 list_del_init(&work->list);
0662                 bnx2fc_process_cq_compl(work->tgt, work->wqe,
0663                             work->rq_data,
0664                             work->num_rq,
0665                             work->task);
0666                 kfree(work);
0667             }
0668 
0669             spin_lock_bh(&p->fp_work_lock);
0670         }
0671         __set_current_state(TASK_INTERRUPTIBLE);
0672         spin_unlock_bh(&p->fp_work_lock);
0673     }
0674     __set_current_state(TASK_RUNNING);
0675 
0676     return 0;
0677 }
0678 
0679 static struct fc_host_statistics *bnx2fc_get_host_stats(struct Scsi_Host *shost)
0680 {
0681     struct fc_host_statistics *bnx2fc_stats;
0682     struct fc_lport *lport = shost_priv(shost);
0683     struct fcoe_port *port = lport_priv(lport);
0684     struct bnx2fc_interface *interface = port->priv;
0685     struct bnx2fc_hba *hba = interface->hba;
0686     struct fcoe_statistics_params *fw_stats;
0687     int rc = 0;
0688 
0689     fw_stats = (struct fcoe_statistics_params *)hba->stats_buffer;
0690     if (!fw_stats)
0691         return NULL;
0692 
0693     mutex_lock(&hba->hba_stats_mutex);
0694 
0695     bnx2fc_stats = fc_get_host_stats(shost);
0696 
0697     init_completion(&hba->stat_req_done);
0698     if (bnx2fc_send_stat_req(hba))
0699         goto unlock_stats_mutex;
0700     rc = wait_for_completion_timeout(&hba->stat_req_done, (2 * HZ));
0701     if (!rc) {
0702         BNX2FC_HBA_DBG(lport, "FW stat req timed out\n");
0703         goto unlock_stats_mutex;
0704     }
0705     BNX2FC_STATS(hba, rx_stat2, fc_crc_cnt);
0706     bnx2fc_stats->invalid_crc_count += hba->bfw_stats.fc_crc_cnt;
0707     BNX2FC_STATS(hba, tx_stat, fcoe_tx_pkt_cnt);
0708     bnx2fc_stats->tx_frames += hba->bfw_stats.fcoe_tx_pkt_cnt;
0709     BNX2FC_STATS(hba, tx_stat, fcoe_tx_byte_cnt);
0710     bnx2fc_stats->tx_words += ((hba->bfw_stats.fcoe_tx_byte_cnt) / 4);
0711     BNX2FC_STATS(hba, rx_stat0, fcoe_rx_pkt_cnt);
0712     bnx2fc_stats->rx_frames += hba->bfw_stats.fcoe_rx_pkt_cnt;
0713     BNX2FC_STATS(hba, rx_stat0, fcoe_rx_byte_cnt);
0714     bnx2fc_stats->rx_words += ((hba->bfw_stats.fcoe_rx_byte_cnt) / 4);
0715 
0716     bnx2fc_stats->dumped_frames = 0;
0717     bnx2fc_stats->lip_count = 0;
0718     bnx2fc_stats->nos_count = 0;
0719     bnx2fc_stats->loss_of_sync_count = 0;
0720     bnx2fc_stats->loss_of_signal_count = 0;
0721     bnx2fc_stats->prim_seq_protocol_err_count = 0;
0722 
0723     memcpy(&hba->prev_stats, hba->stats_buffer,
0724            sizeof(struct fcoe_statistics_params));
0725 
0726 unlock_stats_mutex:
0727     mutex_unlock(&hba->hba_stats_mutex);
0728     return bnx2fc_stats;
0729 }
0730 
0731 static int bnx2fc_shost_config(struct fc_lport *lport, struct device *dev)
0732 {
0733     struct fcoe_port *port = lport_priv(lport);
0734     struct bnx2fc_interface *interface = port->priv;
0735     struct bnx2fc_hba *hba = interface->hba;
0736     struct Scsi_Host *shost = lport->host;
0737     int rc = 0;
0738 
0739     shost->max_cmd_len = BNX2FC_MAX_CMD_LEN;
0740     shost->max_lun = bnx2fc_max_luns;
0741     shost->max_id = BNX2FC_MAX_FCP_TGT;
0742     shost->max_channel = 0;
0743     if (lport->vport)
0744         shost->transportt = bnx2fc_vport_xport_template;
0745     else
0746         shost->transportt = bnx2fc_transport_template;
0747 
0748     /* Add the new host to SCSI-ml */
0749     rc = scsi_add_host(lport->host, dev);
0750     if (rc) {
0751         printk(KERN_ERR PFX "Error on scsi_add_host\n");
0752         return rc;
0753     }
0754     if (!lport->vport)
0755         fc_host_max_npiv_vports(lport->host) = USHRT_MAX;
0756     snprintf(fc_host_symbolic_name(lport->host), 256,
0757          "%s (QLogic %s) v%s over %s",
0758         BNX2FC_NAME, hba->chip_num, BNX2FC_VERSION,
0759         interface->netdev->name);
0760 
0761     return 0;
0762 }
0763 
0764 static int bnx2fc_link_ok(struct fc_lport *lport)
0765 {
0766     struct fcoe_port *port = lport_priv(lport);
0767     struct bnx2fc_interface *interface = port->priv;
0768     struct bnx2fc_hba *hba = interface->hba;
0769     struct net_device *dev = hba->phys_dev;
0770     int rc = 0;
0771 
0772     if ((dev->flags & IFF_UP) && netif_carrier_ok(dev))
0773         clear_bit(ADAPTER_STATE_LINK_DOWN, &hba->adapter_state);
0774     else {
0775         set_bit(ADAPTER_STATE_LINK_DOWN, &hba->adapter_state);
0776         rc = -1;
0777     }
0778     return rc;
0779 }
0780 
0781 /**
0782  * bnx2fc_get_link_state - get network link state
0783  *
0784  * @hba:    adapter instance pointer
0785  *
0786  * updates adapter structure flag based on netdev state
0787  */
0788 void bnx2fc_get_link_state(struct bnx2fc_hba *hba)
0789 {
0790     if (test_bit(__LINK_STATE_NOCARRIER, &hba->phys_dev->state))
0791         set_bit(ADAPTER_STATE_LINK_DOWN, &hba->adapter_state);
0792     else
0793         clear_bit(ADAPTER_STATE_LINK_DOWN, &hba->adapter_state);
0794 }
0795 
0796 static int bnx2fc_net_config(struct fc_lport *lport, struct net_device *netdev)
0797 {
0798     struct bnx2fc_hba *hba;
0799     struct bnx2fc_interface *interface;
0800     struct fcoe_ctlr *ctlr;
0801     struct fcoe_port *port;
0802     u64 wwnn, wwpn;
0803 
0804     port = lport_priv(lport);
0805     interface = port->priv;
0806     ctlr = bnx2fc_to_ctlr(interface);
0807     hba = interface->hba;
0808 
0809     /* require support for get_pauseparam ethtool op. */
0810     if (!hba->phys_dev->ethtool_ops ||
0811         !hba->phys_dev->ethtool_ops->get_pauseparam)
0812         return -EOPNOTSUPP;
0813 
0814     if (fc_set_mfs(lport, BNX2FC_MFS))
0815         return -EINVAL;
0816 
0817     skb_queue_head_init(&port->fcoe_pending_queue);
0818     port->fcoe_pending_queue_active = 0;
0819     timer_setup(&port->timer, fcoe_queue_timer, 0);
0820 
0821     fcoe_link_speed_update(lport);
0822 
0823     if (!lport->vport) {
0824         if (fcoe_get_wwn(netdev, &wwnn, NETDEV_FCOE_WWNN))
0825             wwnn = fcoe_wwn_from_mac(ctlr->ctl_src_addr,
0826                          1, 0);
0827         BNX2FC_HBA_DBG(lport, "WWNN = 0x%llx\n", wwnn);
0828         fc_set_wwnn(lport, wwnn);
0829 
0830         if (fcoe_get_wwn(netdev, &wwpn, NETDEV_FCOE_WWPN))
0831             wwpn = fcoe_wwn_from_mac(ctlr->ctl_src_addr,
0832                          2, 0);
0833 
0834         BNX2FC_HBA_DBG(lport, "WWPN = 0x%llx\n", wwpn);
0835         fc_set_wwpn(lport, wwpn);
0836     }
0837 
0838     return 0;
0839 }
0840 
0841 static void bnx2fc_destroy_timer(struct timer_list *t)
0842 {
0843     struct bnx2fc_hba *hba = from_timer(hba, t, destroy_timer);
0844 
0845     printk(KERN_ERR PFX "ERROR:bnx2fc_destroy_timer - "
0846            "Destroy compl not received!!\n");
0847     set_bit(BNX2FC_FLAG_DESTROY_CMPL, &hba->flags);
0848     wake_up_interruptible(&hba->destroy_wait);
0849 }
0850 
0851 /**
0852  * bnx2fc_indicate_netevent - Generic netdev event handler
0853  *
0854  * @context:    adapter structure pointer
0855  * @event:  event type
0856  * @vlan_id:    vlan id - associated vlan id with this event
0857  *
0858  * Handles NETDEV_UP, NETDEV_DOWN, NETDEV_GOING_DOWN,NETDEV_CHANGE and
0859  * NETDEV_CHANGE_MTU events. Handle NETDEV_UNREGISTER only for vlans.
0860  */
0861 static void bnx2fc_indicate_netevent(void *context, unsigned long event,
0862                      u16 vlan_id)
0863 {
0864     struct bnx2fc_hba *hba = (struct bnx2fc_hba *)context;
0865     struct fcoe_ctlr_device *cdev;
0866     struct fc_lport *lport;
0867     struct fc_lport *vport;
0868     struct bnx2fc_interface *interface, *tmp;
0869     struct fcoe_ctlr *ctlr;
0870     int wait_for_upload = 0;
0871     u32 link_possible = 1;
0872 
0873     if (vlan_id != 0 && event != NETDEV_UNREGISTER)
0874         return;
0875 
0876     switch (event) {
0877     case NETDEV_UP:
0878         if (!test_bit(ADAPTER_STATE_UP, &hba->adapter_state))
0879             printk(KERN_ERR "indicate_netevent: "\
0880                     "hba is not UP!!\n");
0881         break;
0882 
0883     case NETDEV_DOWN:
0884         clear_bit(ADAPTER_STATE_GOING_DOWN, &hba->adapter_state);
0885         clear_bit(ADAPTER_STATE_UP, &hba->adapter_state);
0886         link_possible = 0;
0887         break;
0888 
0889     case NETDEV_GOING_DOWN:
0890         set_bit(ADAPTER_STATE_GOING_DOWN, &hba->adapter_state);
0891         link_possible = 0;
0892         break;
0893 
0894     case NETDEV_CHANGE:
0895         break;
0896 
0897     case NETDEV_UNREGISTER:
0898         if (!vlan_id)
0899             return;
0900         mutex_lock(&bnx2fc_dev_lock);
0901         list_for_each_entry_safe(interface, tmp, &if_list, list) {
0902             if (interface->hba == hba &&
0903                 interface->vlan_id == (vlan_id & VLAN_VID_MASK))
0904                 __bnx2fc_destroy(interface);
0905         }
0906         mutex_unlock(&bnx2fc_dev_lock);
0907         return;
0908 
0909     default:
0910         return;
0911     }
0912 
0913     mutex_lock(&bnx2fc_dev_lock);
0914     list_for_each_entry(interface, &if_list, list) {
0915 
0916         if (interface->hba != hba)
0917             continue;
0918 
0919         ctlr = bnx2fc_to_ctlr(interface);
0920         lport = ctlr->lp;
0921         BNX2FC_HBA_DBG(lport, "netevent handler - event=%s %ld\n",
0922                 interface->netdev->name, event);
0923 
0924         fcoe_link_speed_update(lport);
0925 
0926         cdev = fcoe_ctlr_to_ctlr_dev(ctlr);
0927 
0928         if (link_possible && !bnx2fc_link_ok(lport)) {
0929             switch (cdev->enabled) {
0930             case FCOE_CTLR_DISABLED:
0931                 pr_info("Link up while interface is disabled.\n");
0932                 break;
0933             case FCOE_CTLR_ENABLED:
0934             case FCOE_CTLR_UNUSED:
0935                 /* Reset max recv frame size to default */
0936                 fc_set_mfs(lport, BNX2FC_MFS);
0937                 /*
0938                  * ctlr link up will only be handled during
0939                  * enable to avoid sending discovery
0940                  * solicitation on a stale vlan
0941                  */
0942                 if (interface->enabled)
0943                     fcoe_ctlr_link_up(ctlr);
0944             }
0945         } else if (fcoe_ctlr_link_down(ctlr)) {
0946             switch (cdev->enabled) {
0947             case FCOE_CTLR_DISABLED:
0948                 pr_info("Link down while interface is disabled.\n");
0949                 break;
0950             case FCOE_CTLR_ENABLED:
0951             case FCOE_CTLR_UNUSED:
0952                 mutex_lock(&lport->lp_mutex);
0953                 list_for_each_entry(vport, &lport->vports, list)
0954                     fc_host_port_type(vport->host) =
0955                     FC_PORTTYPE_UNKNOWN;
0956                 mutex_unlock(&lport->lp_mutex);
0957                 fc_host_port_type(lport->host) =
0958                     FC_PORTTYPE_UNKNOWN;
0959                 this_cpu_inc(lport->stats->LinkFailureCount);
0960                 fcoe_clean_pending_queue(lport);
0961                 wait_for_upload = 1;
0962             }
0963         }
0964     }
0965     mutex_unlock(&bnx2fc_dev_lock);
0966 
0967     if (wait_for_upload) {
0968         clear_bit(ADAPTER_STATE_READY, &hba->adapter_state);
0969         init_waitqueue_head(&hba->shutdown_wait);
0970         BNX2FC_MISC_DBG("indicate_netevent "
0971                 "num_ofld_sess = %d\n",
0972                 hba->num_ofld_sess);
0973         hba->wait_for_link_down = 1;
0974         wait_event_interruptible(hba->shutdown_wait,
0975                      (hba->num_ofld_sess == 0));
0976         BNX2FC_MISC_DBG("wakeup - num_ofld_sess = %d\n",
0977                 hba->num_ofld_sess);
0978         hba->wait_for_link_down = 0;
0979 
0980         if (signal_pending(current))
0981             flush_signals(current);
0982     }
0983 }
0984 
0985 static int bnx2fc_libfc_config(struct fc_lport *lport)
0986 {
0987 
0988     /* Set the function pointers set by bnx2fc driver */
0989     memcpy(&lport->tt, &bnx2fc_libfc_fcn_templ,
0990         sizeof(struct libfc_function_template));
0991     fc_elsct_init(lport);
0992     fc_exch_init(lport);
0993     fc_disc_init(lport);
0994     fc_disc_config(lport, lport);
0995     return 0;
0996 }
0997 
0998 static int bnx2fc_em_config(struct fc_lport *lport, struct bnx2fc_hba *hba)
0999 {
1000     int fcoe_min_xid, fcoe_max_xid;
1001 
1002     fcoe_min_xid = hba->max_xid + 1;
1003     if (nr_cpu_ids <= 2)
1004         fcoe_max_xid = hba->max_xid + FCOE_XIDS_PER_CPU_OFFSET;
1005     else
1006         fcoe_max_xid = hba->max_xid + FCOE_MAX_XID_OFFSET;
1007     if (!fc_exch_mgr_alloc(lport, FC_CLASS_3, fcoe_min_xid,
1008                    fcoe_max_xid, NULL)) {
1009         printk(KERN_ERR PFX "em_config:fc_exch_mgr_alloc failed\n");
1010         return -ENOMEM;
1011     }
1012 
1013     return 0;
1014 }
1015 
1016 static int bnx2fc_lport_config(struct fc_lport *lport)
1017 {
1018     lport->link_up = 0;
1019     lport->qfull = 0;
1020     lport->max_retry_count = BNX2FC_MAX_RETRY_CNT;
1021     lport->max_rport_retry_count = BNX2FC_MAX_RPORT_RETRY_CNT;
1022     lport->e_d_tov = 2 * 1000;
1023     lport->r_a_tov = 10 * 1000;
1024 
1025     lport->service_params = (FCP_SPPF_INIT_FCN | FCP_SPPF_RD_XRDY_DIS |
1026                 FCP_SPPF_RETRY | FCP_SPPF_CONF_COMPL);
1027     lport->does_npiv = 1;
1028 
1029     memset(&lport->rnid_gen, 0, sizeof(struct fc_els_rnid_gen));
1030     lport->rnid_gen.rnid_atype = BNX2FC_RNID_HBA;
1031 
1032     /* alloc stats structure */
1033     if (fc_lport_init_stats(lport))
1034         return -ENOMEM;
1035 
1036     /* Finish fc_lport configuration */
1037     fc_lport_config(lport);
1038 
1039     return 0;
1040 }
1041 
1042 /**
1043  * bnx2fc_fip_recv - handle a received FIP frame.
1044  *
1045  * @skb: the received skb
1046  * @dev: associated &net_device
1047  * @ptype: the &packet_type structure which was used to register this handler.
1048  * @orig_dev: original receive &net_device, in case @ dev is a bond.
1049  *
1050  * Returns: 0 for success
1051  */
1052 static int bnx2fc_fip_recv(struct sk_buff *skb, struct net_device *dev,
1053                struct packet_type *ptype,
1054                struct net_device *orig_dev)
1055 {
1056     struct bnx2fc_interface *interface;
1057     struct fcoe_ctlr *ctlr;
1058     interface = container_of(ptype, struct bnx2fc_interface,
1059                  fip_packet_type);
1060     ctlr = bnx2fc_to_ctlr(interface);
1061     fcoe_ctlr_recv(ctlr, skb);
1062     return 0;
1063 }
1064 
1065 /**
1066  * bnx2fc_update_src_mac - Update Ethernet MAC filters.
1067  *
1068  * @lport: The local port
1069  * @addr: Location of data to copy
1070  *
1071  * Remove any previously-set unicast MAC filter.
1072  * Add secondary FCoE MAC address filter for our OUI.
1073  */
1074 static void bnx2fc_update_src_mac(struct fc_lport *lport, u8 *addr)
1075 {
1076     struct fcoe_port *port = lport_priv(lport);
1077 
1078     memcpy(port->data_src_addr, addr, ETH_ALEN);
1079 }
1080 
1081 /**
1082  * bnx2fc_get_src_mac - return the ethernet source address for an lport
1083  *
1084  * @lport: libfc port
1085  */
1086 static u8 *bnx2fc_get_src_mac(struct fc_lport *lport)
1087 {
1088     struct fcoe_port *port;
1089 
1090     port = (struct fcoe_port *)lport_priv(lport);
1091     return port->data_src_addr;
1092 }
1093 
1094 /**
1095  * bnx2fc_fip_send - send an Ethernet-encapsulated FIP frame.
1096  *
1097  * @fip: FCoE controller.
1098  * @skb: FIP Packet.
1099  */
1100 static void bnx2fc_fip_send(struct fcoe_ctlr *fip, struct sk_buff *skb)
1101 {
1102     struct fip_header *fiph;
1103     struct ethhdr *eth_hdr;
1104     u16 op;
1105     u8 sub;
1106 
1107     fiph = (struct fip_header *) ((void *)skb->data + 2 * ETH_ALEN + 2);
1108     eth_hdr = (struct ethhdr *)skb_mac_header(skb);
1109     op = ntohs(fiph->fip_op);
1110     sub = fiph->fip_subcode;
1111 
1112     if (op == FIP_OP_CTRL && sub == FIP_SC_SOL && bnx2fc_log_fka)
1113         BNX2FC_MISC_DBG("Sending FKA from %pM to %pM.\n",
1114             eth_hdr->h_source, eth_hdr->h_dest);
1115 
1116     skb->dev = bnx2fc_from_ctlr(fip)->netdev;
1117     dev_queue_xmit(skb);
1118 }
1119 
1120 static int bnx2fc_vport_create(struct fc_vport *vport, bool disabled)
1121 {
1122     struct Scsi_Host *shost = vport_to_shost(vport);
1123     struct fc_lport *n_port = shost_priv(shost);
1124     struct fcoe_port *port = lport_priv(n_port);
1125     struct bnx2fc_interface *interface = port->priv;
1126     struct net_device *netdev = interface->netdev;
1127     struct fc_lport *vn_port;
1128     int rc;
1129     char buf[32];
1130 
1131     rc = fcoe_validate_vport_create(vport);
1132     if (rc) {
1133         fcoe_wwn_to_str(vport->port_name, buf, sizeof(buf));
1134         printk(KERN_ERR PFX "Failed to create vport, "
1135                "WWPN (0x%s) already exists\n",
1136                buf);
1137         return rc;
1138     }
1139 
1140     if (!test_bit(BNX2FC_FLAG_FW_INIT_DONE, &interface->hba->flags)) {
1141         printk(KERN_ERR PFX "vn ports cannot be created on"
1142             "this interface\n");
1143         return -EIO;
1144     }
1145     rtnl_lock();
1146     mutex_lock(&bnx2fc_dev_lock);
1147     vn_port = bnx2fc_if_create(interface, &vport->dev, 1);
1148     mutex_unlock(&bnx2fc_dev_lock);
1149     rtnl_unlock();
1150 
1151     if (!vn_port) {
1152         printk(KERN_ERR PFX "bnx2fc_vport_create (%s) failed\n",
1153             netdev->name);
1154         return -EIO;
1155     }
1156 
1157     if (bnx2fc_devloss_tmo)
1158         fc_host_dev_loss_tmo(vn_port->host) = bnx2fc_devloss_tmo;
1159 
1160     if (disabled) {
1161         fc_vport_set_state(vport, FC_VPORT_DISABLED);
1162     } else {
1163         vn_port->boot_time = jiffies;
1164         fc_lport_init(vn_port);
1165         fc_fabric_login(vn_port);
1166         fc_vport_setlink(vn_port);
1167     }
1168     return 0;
1169 }
1170 
1171 static void bnx2fc_free_vport(struct bnx2fc_hba *hba, struct fc_lport *lport)
1172 {
1173     struct bnx2fc_lport *blport, *tmp;
1174 
1175     spin_lock_bh(&hba->hba_lock);
1176     list_for_each_entry_safe(blport, tmp, &hba->vports, list) {
1177         if (blport->lport == lport) {
1178             list_del(&blport->list);
1179             kfree(blport);
1180         }
1181     }
1182     spin_unlock_bh(&hba->hba_lock);
1183 }
1184 
1185 static int bnx2fc_vport_destroy(struct fc_vport *vport)
1186 {
1187     struct Scsi_Host *shost = vport_to_shost(vport);
1188     struct fc_lport *n_port = shost_priv(shost);
1189     struct fc_lport *vn_port = vport->dd_data;
1190     struct fcoe_port *port = lport_priv(vn_port);
1191     struct bnx2fc_interface *interface = port->priv;
1192     struct fc_lport *v_port;
1193     bool found = false;
1194 
1195     mutex_lock(&n_port->lp_mutex);
1196     list_for_each_entry(v_port, &n_port->vports, list)
1197         if (v_port->vport == vport) {
1198             found = true;
1199             break;
1200         }
1201 
1202     if (!found) {
1203         mutex_unlock(&n_port->lp_mutex);
1204         return -ENOENT;
1205     }
1206     list_del(&vn_port->list);
1207     mutex_unlock(&n_port->lp_mutex);
1208     bnx2fc_free_vport(interface->hba, port->lport);
1209     bnx2fc_port_shutdown(port->lport);
1210     bnx2fc_port_destroy(port);
1211     bnx2fc_interface_put(interface);
1212     return 0;
1213 }
1214 
1215 static int bnx2fc_vport_disable(struct fc_vport *vport, bool disable)
1216 {
1217     struct fc_lport *lport = vport->dd_data;
1218 
1219     if (disable) {
1220         fc_vport_set_state(vport, FC_VPORT_DISABLED);
1221         fc_fabric_logoff(lport);
1222     } else {
1223         lport->boot_time = jiffies;
1224         fc_fabric_login(lport);
1225         fc_vport_setlink(lport);
1226     }
1227     return 0;
1228 }
1229 
1230 
1231 static int bnx2fc_interface_setup(struct bnx2fc_interface *interface)
1232 {
1233     struct net_device *netdev = interface->netdev;
1234     struct net_device *physdev = interface->hba->phys_dev;
1235     struct fcoe_ctlr *ctlr = bnx2fc_to_ctlr(interface);
1236     struct netdev_hw_addr *ha;
1237     int sel_san_mac = 0;
1238 
1239     /* setup Source MAC Address */
1240     rcu_read_lock();
1241     for_each_dev_addr(physdev, ha) {
1242         BNX2FC_MISC_DBG("net_config: ha->type = %d, fip_mac = ",
1243                 ha->type);
1244         printk(KERN_INFO "%2x:%2x:%2x:%2x:%2x:%2x\n", ha->addr[0],
1245                 ha->addr[1], ha->addr[2], ha->addr[3],
1246                 ha->addr[4], ha->addr[5]);
1247 
1248         if ((ha->type == NETDEV_HW_ADDR_T_SAN) &&
1249             (is_valid_ether_addr(ha->addr))) {
1250             memcpy(ctlr->ctl_src_addr, ha->addr,
1251                    ETH_ALEN);
1252             sel_san_mac = 1;
1253             BNX2FC_MISC_DBG("Found SAN MAC\n");
1254         }
1255     }
1256     rcu_read_unlock();
1257 
1258     if (!sel_san_mac)
1259         return -ENODEV;
1260 
1261     interface->fip_packet_type.func = bnx2fc_fip_recv;
1262     interface->fip_packet_type.type = htons(ETH_P_FIP);
1263     interface->fip_packet_type.dev = netdev;
1264     dev_add_pack(&interface->fip_packet_type);
1265 
1266     interface->fcoe_packet_type.func = bnx2fc_rcv;
1267     interface->fcoe_packet_type.type = __constant_htons(ETH_P_FCOE);
1268     interface->fcoe_packet_type.dev = netdev;
1269     dev_add_pack(&interface->fcoe_packet_type);
1270 
1271     return 0;
1272 }
1273 
1274 static int bnx2fc_attach_transport(void)
1275 {
1276     bnx2fc_transport_template =
1277         fc_attach_transport(&bnx2fc_transport_function);
1278 
1279     if (bnx2fc_transport_template == NULL) {
1280         printk(KERN_ERR PFX "Failed to attach FC transport\n");
1281         return -ENODEV;
1282     }
1283 
1284     bnx2fc_vport_xport_template =
1285         fc_attach_transport(&bnx2fc_vport_xport_function);
1286     if (bnx2fc_vport_xport_template == NULL) {
1287         printk(KERN_ERR PFX
1288                "Failed to attach FC transport for vport\n");
1289         fc_release_transport(bnx2fc_transport_template);
1290         bnx2fc_transport_template = NULL;
1291         return -ENODEV;
1292     }
1293     return 0;
1294 }
1295 static void bnx2fc_release_transport(void)
1296 {
1297     fc_release_transport(bnx2fc_transport_template);
1298     fc_release_transport(bnx2fc_vport_xport_template);
1299     bnx2fc_transport_template = NULL;
1300     bnx2fc_vport_xport_template = NULL;
1301 }
1302 
1303 static void bnx2fc_interface_release(struct kref *kref)
1304 {
1305     struct fcoe_ctlr_device *ctlr_dev;
1306     struct bnx2fc_interface *interface;
1307     struct fcoe_ctlr *ctlr;
1308     struct net_device *netdev;
1309 
1310     interface = container_of(kref, struct bnx2fc_interface, kref);
1311     BNX2FC_MISC_DBG("Interface is being released\n");
1312 
1313     ctlr = bnx2fc_to_ctlr(interface);
1314     ctlr_dev = fcoe_ctlr_to_ctlr_dev(ctlr);
1315     netdev = interface->netdev;
1316 
1317     /* tear-down FIP controller */
1318     if (test_and_clear_bit(BNX2FC_CTLR_INIT_DONE, &interface->if_flags))
1319         fcoe_ctlr_destroy(ctlr);
1320 
1321     fcoe_ctlr_device_delete(ctlr_dev);
1322 
1323     dev_put(netdev);
1324     module_put(THIS_MODULE);
1325 }
1326 
1327 static inline void bnx2fc_interface_get(struct bnx2fc_interface *interface)
1328 {
1329     kref_get(&interface->kref);
1330 }
1331 
1332 static inline void bnx2fc_interface_put(struct bnx2fc_interface *interface)
1333 {
1334     kref_put(&interface->kref, bnx2fc_interface_release);
1335 }
1336 static void bnx2fc_hba_destroy(struct bnx2fc_hba *hba)
1337 {
1338     /* Free the command manager */
1339     if (hba->cmd_mgr) {
1340         bnx2fc_cmd_mgr_free(hba->cmd_mgr);
1341         hba->cmd_mgr = NULL;
1342     }
1343     kfree(hba->tgt_ofld_list);
1344     bnx2fc_unbind_pcidev(hba);
1345     kfree(hba);
1346 }
1347 
1348 /**
1349  * bnx2fc_hba_create - create a new bnx2fc hba
1350  *
1351  * @cnic:   pointer to cnic device
1352  *
1353  * Creates a new FCoE hba on the given device.
1354  *
1355  */
1356 static struct bnx2fc_hba *bnx2fc_hba_create(struct cnic_dev *cnic)
1357 {
1358     struct bnx2fc_hba *hba;
1359     struct fcoe_capabilities *fcoe_cap;
1360     int rc;
1361 
1362     hba = kzalloc(sizeof(*hba), GFP_KERNEL);
1363     if (!hba) {
1364         printk(KERN_ERR PFX "Unable to allocate hba structure\n");
1365         return NULL;
1366     }
1367     spin_lock_init(&hba->hba_lock);
1368     mutex_init(&hba->hba_mutex);
1369     mutex_init(&hba->hba_stats_mutex);
1370 
1371     hba->cnic = cnic;
1372 
1373     hba->max_tasks = cnic->max_fcoe_exchanges;
1374     hba->elstm_xids = (hba->max_tasks / 2);
1375     hba->max_outstanding_cmds = hba->elstm_xids;
1376     hba->max_xid = (hba->max_tasks - 1);
1377 
1378     rc = bnx2fc_bind_pcidev(hba);
1379     if (rc) {
1380         printk(KERN_ERR PFX "create_adapter:  bind error\n");
1381         goto bind_err;
1382     }
1383     hba->phys_dev = cnic->netdev;
1384     hba->next_conn_id = 0;
1385 
1386     hba->tgt_ofld_list =
1387         kcalloc(BNX2FC_NUM_MAX_SESS, sizeof(struct bnx2fc_rport *),
1388             GFP_KERNEL);
1389     if (!hba->tgt_ofld_list) {
1390         printk(KERN_ERR PFX "Unable to allocate tgt offload list\n");
1391         goto tgtofld_err;
1392     }
1393 
1394     hba->num_ofld_sess = 0;
1395 
1396     hba->cmd_mgr = bnx2fc_cmd_mgr_alloc(hba);
1397     if (!hba->cmd_mgr) {
1398         printk(KERN_ERR PFX "em_config:bnx2fc_cmd_mgr_alloc failed\n");
1399         goto cmgr_err;
1400     }
1401     fcoe_cap = &hba->fcoe_cap;
1402 
1403     fcoe_cap->capability1 = BNX2FC_TM_MAX_SQES <<
1404                     FCOE_IOS_PER_CONNECTION_SHIFT;
1405     fcoe_cap->capability1 |= BNX2FC_NUM_MAX_SESS <<
1406                     FCOE_LOGINS_PER_PORT_SHIFT;
1407     fcoe_cap->capability2 = hba->max_outstanding_cmds <<
1408                     FCOE_NUMBER_OF_EXCHANGES_SHIFT;
1409     fcoe_cap->capability2 |= BNX2FC_MAX_NPIV <<
1410                     FCOE_NPIV_WWN_PER_PORT_SHIFT;
1411     fcoe_cap->capability3 = BNX2FC_NUM_MAX_SESS <<
1412                     FCOE_TARGETS_SUPPORTED_SHIFT;
1413     fcoe_cap->capability3 |= hba->max_outstanding_cmds <<
1414                     FCOE_OUTSTANDING_COMMANDS_SHIFT;
1415     fcoe_cap->capability4 = FCOE_CAPABILITY4_STATEFUL;
1416 
1417     init_waitqueue_head(&hba->shutdown_wait);
1418     init_waitqueue_head(&hba->destroy_wait);
1419     INIT_LIST_HEAD(&hba->vports);
1420 
1421     return hba;
1422 
1423 cmgr_err:
1424     kfree(hba->tgt_ofld_list);
1425 tgtofld_err:
1426     bnx2fc_unbind_pcidev(hba);
1427 bind_err:
1428     kfree(hba);
1429     return NULL;
1430 }
1431 
1432 static struct bnx2fc_interface *
1433 bnx2fc_interface_create(struct bnx2fc_hba *hba,
1434             struct net_device *netdev,
1435             enum fip_mode fip_mode)
1436 {
1437     struct fcoe_ctlr_device *ctlr_dev;
1438     struct bnx2fc_interface *interface;
1439     struct fcoe_ctlr *ctlr;
1440     int size;
1441     int rc = 0;
1442 
1443     size = (sizeof(*interface) + sizeof(struct fcoe_ctlr));
1444     ctlr_dev = fcoe_ctlr_device_add(&netdev->dev, &bnx2fc_fcoe_sysfs_templ,
1445                      size);
1446     if (!ctlr_dev) {
1447         printk(KERN_ERR PFX "Unable to allocate interface structure\n");
1448         return NULL;
1449     }
1450     ctlr = fcoe_ctlr_device_priv(ctlr_dev);
1451     ctlr->cdev = ctlr_dev;
1452     interface = fcoe_ctlr_priv(ctlr);
1453     dev_hold(netdev);
1454     kref_init(&interface->kref);
1455     interface->hba = hba;
1456     interface->netdev = netdev;
1457 
1458     /* Initialize FIP */
1459     fcoe_ctlr_init(ctlr, fip_mode);
1460     ctlr->send = bnx2fc_fip_send;
1461     ctlr->update_mac = bnx2fc_update_src_mac;
1462     ctlr->get_src_addr = bnx2fc_get_src_mac;
1463     set_bit(BNX2FC_CTLR_INIT_DONE, &interface->if_flags);
1464 
1465     rc = bnx2fc_interface_setup(interface);
1466     if (!rc)
1467         return interface;
1468 
1469     fcoe_ctlr_destroy(ctlr);
1470     dev_put(netdev);
1471     fcoe_ctlr_device_delete(ctlr_dev);
1472     return NULL;
1473 }
1474 
1475 /**
1476  * bnx2fc_if_create - Create FCoE instance on a given interface
1477  *
1478  * @interface:  FCoE interface to create a local port on
1479  * @parent: Device pointer to be the parent in sysfs for the SCSI host
1480  * @npiv:   Indicates if the port is vport or not
1481  *
1482  * Creates a fc_lport instance and a Scsi_Host instance and configure them.
1483  *
1484  * Returns: Allocated fc_lport or an error pointer
1485  */
1486 static struct fc_lport *bnx2fc_if_create(struct bnx2fc_interface *interface,
1487                   struct device *parent, int npiv)
1488 {
1489     struct fcoe_ctlr        *ctlr = bnx2fc_to_ctlr(interface);
1490     struct fc_lport     *lport, *n_port;
1491     struct fcoe_port    *port;
1492     struct Scsi_Host    *shost;
1493     struct fc_vport     *vport = dev_to_vport(parent);
1494     struct bnx2fc_lport *blport;
1495     struct bnx2fc_hba   *hba = interface->hba;
1496     int         rc = 0;
1497 
1498     blport = kzalloc(sizeof(struct bnx2fc_lport), GFP_KERNEL);
1499     if (!blport) {
1500         BNX2FC_HBA_DBG(ctlr->lp, "Unable to alloc blport\n");
1501         return NULL;
1502     }
1503 
1504     /* Allocate Scsi_Host structure */
1505     bnx2fc_shost_template.can_queue = hba->max_outstanding_cmds;
1506     if (!npiv)
1507         lport = libfc_host_alloc(&bnx2fc_shost_template, sizeof(*port));
1508     else
1509         lport = libfc_vport_create(vport, sizeof(*port));
1510 
1511     if (!lport) {
1512         printk(KERN_ERR PFX "could not allocate scsi host structure\n");
1513         goto free_blport;
1514     }
1515     shost = lport->host;
1516     port = lport_priv(lport);
1517     port->lport = lport;
1518     port->priv = interface;
1519     port->get_netdev = bnx2fc_netdev;
1520 
1521     /* Configure fcoe_port */
1522     rc = bnx2fc_lport_config(lport);
1523     if (rc)
1524         goto lp_config_err;
1525 
1526     if (npiv) {
1527         printk(KERN_ERR PFX "Setting vport names, 0x%llX 0x%llX\n",
1528             vport->node_name, vport->port_name);
1529         fc_set_wwnn(lport, vport->node_name);
1530         fc_set_wwpn(lport, vport->port_name);
1531     }
1532     /* Configure netdev and networking properties of the lport */
1533     rc = bnx2fc_net_config(lport, interface->netdev);
1534     if (rc) {
1535         printk(KERN_ERR PFX "Error on bnx2fc_net_config\n");
1536         goto lp_config_err;
1537     }
1538 
1539     rc = bnx2fc_shost_config(lport, parent);
1540     if (rc) {
1541         printk(KERN_ERR PFX "Couldn't configure shost for %s\n",
1542             interface->netdev->name);
1543         goto lp_config_err;
1544     }
1545 
1546     /* Initialize the libfc library */
1547     rc = bnx2fc_libfc_config(lport);
1548     if (rc) {
1549         printk(KERN_ERR PFX "Couldn't configure libfc\n");
1550         goto shost_err;
1551     }
1552     fc_host_port_type(lport->host) = FC_PORTTYPE_UNKNOWN;
1553 
1554     if (bnx2fc_devloss_tmo)
1555         fc_host_dev_loss_tmo(shost) = bnx2fc_devloss_tmo;
1556 
1557     /* Allocate exchange manager */
1558     if (!npiv)
1559         rc = bnx2fc_em_config(lport, hba);
1560     else {
1561         shost = vport_to_shost(vport);
1562         n_port = shost_priv(shost);
1563         rc = fc_exch_mgr_list_clone(n_port, lport);
1564     }
1565 
1566     if (rc) {
1567         printk(KERN_ERR PFX "Error on bnx2fc_em_config\n");
1568         goto shost_err;
1569     }
1570 
1571     bnx2fc_interface_get(interface);
1572 
1573     spin_lock_bh(&hba->hba_lock);
1574     blport->lport = lport;
1575     list_add_tail(&blport->list, &hba->vports);
1576     spin_unlock_bh(&hba->hba_lock);
1577 
1578     return lport;
1579 
1580 shost_err:
1581     scsi_remove_host(shost);
1582 lp_config_err:
1583     scsi_host_put(lport->host);
1584 free_blport:
1585     kfree(blport);
1586     return NULL;
1587 }
1588 
1589 static void bnx2fc_net_cleanup(struct bnx2fc_interface *interface)
1590 {
1591     /* Dont listen for Ethernet packets anymore */
1592     __dev_remove_pack(&interface->fcoe_packet_type);
1593     __dev_remove_pack(&interface->fip_packet_type);
1594     synchronize_net();
1595 }
1596 
1597 static void bnx2fc_interface_cleanup(struct bnx2fc_interface *interface)
1598 {
1599     struct fcoe_ctlr *ctlr = bnx2fc_to_ctlr(interface);
1600     struct fc_lport *lport = ctlr->lp;
1601     struct fcoe_port *port = lport_priv(lport);
1602     struct bnx2fc_hba *hba = interface->hba;
1603 
1604     /* Stop the transmit retry timer */
1605     del_timer_sync(&port->timer);
1606 
1607     /* Free existing transmit skbs */
1608     fcoe_clean_pending_queue(lport);
1609 
1610     bnx2fc_net_cleanup(interface);
1611 
1612     bnx2fc_free_vport(hba, lport);
1613 }
1614 
1615 static void bnx2fc_if_destroy(struct fc_lport *lport)
1616 {
1617 
1618     /* Free queued packets for the receive thread */
1619     bnx2fc_clean_rx_queue(lport);
1620 
1621     /* Detach from scsi-ml */
1622     fc_remove_host(lport->host);
1623     scsi_remove_host(lport->host);
1624 
1625     /*
1626      * Note that only the physical lport will have the exchange manager.
1627      * for vports, this function is NOP
1628      */
1629     fc_exch_mgr_free(lport);
1630 
1631     /* Free memory used by statistical counters */
1632     fc_lport_free_stats(lport);
1633 
1634     /* Release Scsi_Host */
1635     scsi_host_put(lport->host);
1636 }
1637 
1638 static void __bnx2fc_destroy(struct bnx2fc_interface *interface)
1639 {
1640     struct fcoe_ctlr *ctlr = bnx2fc_to_ctlr(interface);
1641     struct fc_lport *lport = ctlr->lp;
1642     struct fcoe_port *port = lport_priv(lport);
1643 
1644     bnx2fc_interface_cleanup(interface);
1645     bnx2fc_stop(interface);
1646     list_del(&interface->list);
1647     bnx2fc_port_destroy(port);
1648     bnx2fc_interface_put(interface);
1649 }
1650 
1651 /**
1652  * bnx2fc_destroy - Destroy a bnx2fc FCoE interface
1653  *
1654  * @netdev: The net device that the FCoE interface is on
1655  *
1656  * Called from sysfs.
1657  *
1658  * Returns: 0 for success
1659  */
1660 static int bnx2fc_destroy(struct net_device *netdev)
1661 {
1662     struct bnx2fc_interface *interface = NULL;
1663     struct workqueue_struct *timer_work_queue;
1664     struct fcoe_ctlr *ctlr;
1665     int rc = 0;
1666 
1667     rtnl_lock();
1668     mutex_lock(&bnx2fc_dev_lock);
1669 
1670     interface = bnx2fc_interface_lookup(netdev);
1671     ctlr = bnx2fc_to_ctlr(interface);
1672     if (!interface || !ctlr->lp) {
1673         rc = -ENODEV;
1674         printk(KERN_ERR PFX "bnx2fc_destroy: interface or lport not found\n");
1675         goto netdev_err;
1676     }
1677 
1678     timer_work_queue = interface->timer_work_queue;
1679     __bnx2fc_destroy(interface);
1680     destroy_workqueue(timer_work_queue);
1681 
1682 netdev_err:
1683     mutex_unlock(&bnx2fc_dev_lock);
1684     rtnl_unlock();
1685     return rc;
1686 }
1687 
1688 static void bnx2fc_port_destroy(struct fcoe_port *port)
1689 {
1690     struct fc_lport *lport;
1691 
1692     lport = port->lport;
1693     BNX2FC_HBA_DBG(lport, "Entered %s, destroying lport %p\n", __func__, lport);
1694 
1695     bnx2fc_if_destroy(lport);
1696 }
1697 
1698 static void bnx2fc_unbind_adapter_devices(struct bnx2fc_hba *hba)
1699 {
1700     bnx2fc_free_fw_resc(hba);
1701     bnx2fc_free_task_ctx(hba);
1702 }
1703 
1704 /**
1705  * bnx2fc_bind_adapter_devices - binds bnx2fc adapter with the associated
1706  *          pci structure
1707  *
1708  * @hba:        Adapter instance
1709  */
1710 static int bnx2fc_bind_adapter_devices(struct bnx2fc_hba *hba)
1711 {
1712     if (bnx2fc_setup_task_ctx(hba))
1713         goto mem_err;
1714 
1715     if (bnx2fc_setup_fw_resc(hba))
1716         goto mem_err;
1717 
1718     return 0;
1719 mem_err:
1720     bnx2fc_unbind_adapter_devices(hba);
1721     return -ENOMEM;
1722 }
1723 
1724 static int bnx2fc_bind_pcidev(struct bnx2fc_hba *hba)
1725 {
1726     struct cnic_dev *cnic;
1727     struct pci_dev *pdev;
1728 
1729     if (!hba->cnic) {
1730         printk(KERN_ERR PFX "cnic is NULL\n");
1731         return -ENODEV;
1732     }
1733     cnic = hba->cnic;
1734     pdev = hba->pcidev = cnic->pcidev;
1735     if (!hba->pcidev)
1736         return -ENODEV;
1737 
1738     switch (pdev->device) {
1739     case PCI_DEVICE_ID_NX2_57710:
1740         strncpy(hba->chip_num, "BCM57710", BCM_CHIP_LEN);
1741         break;
1742     case PCI_DEVICE_ID_NX2_57711:
1743         strncpy(hba->chip_num, "BCM57711", BCM_CHIP_LEN);
1744         break;
1745     case PCI_DEVICE_ID_NX2_57712:
1746     case PCI_DEVICE_ID_NX2_57712_MF:
1747     case PCI_DEVICE_ID_NX2_57712_VF:
1748         strncpy(hba->chip_num, "BCM57712", BCM_CHIP_LEN);
1749         break;
1750     case PCI_DEVICE_ID_NX2_57800:
1751     case PCI_DEVICE_ID_NX2_57800_MF:
1752     case PCI_DEVICE_ID_NX2_57800_VF:
1753         strncpy(hba->chip_num, "BCM57800", BCM_CHIP_LEN);
1754         break;
1755     case PCI_DEVICE_ID_NX2_57810:
1756     case PCI_DEVICE_ID_NX2_57810_MF:
1757     case PCI_DEVICE_ID_NX2_57810_VF:
1758         strncpy(hba->chip_num, "BCM57810", BCM_CHIP_LEN);
1759         break;
1760     case PCI_DEVICE_ID_NX2_57840:
1761     case PCI_DEVICE_ID_NX2_57840_MF:
1762     case PCI_DEVICE_ID_NX2_57840_VF:
1763     case PCI_DEVICE_ID_NX2_57840_2_20:
1764     case PCI_DEVICE_ID_NX2_57840_4_10:
1765         strncpy(hba->chip_num, "BCM57840", BCM_CHIP_LEN);
1766         break;
1767     default:
1768         pr_err(PFX "Unknown device id 0x%x\n", pdev->device);
1769         break;
1770     }
1771     pci_dev_get(hba->pcidev);
1772     return 0;
1773 }
1774 
1775 static void bnx2fc_unbind_pcidev(struct bnx2fc_hba *hba)
1776 {
1777     if (hba->pcidev) {
1778         hba->chip_num[0] = '\0';
1779         pci_dev_put(hba->pcidev);
1780     }
1781     hba->pcidev = NULL;
1782 }
1783 
1784 /**
1785  * bnx2fc_ulp_get_stats - cnic callback to populate FCoE stats
1786  *
1787  * @handle:    transport handle pointing to adapter structure
1788  */
1789 static int bnx2fc_ulp_get_stats(void *handle)
1790 {
1791     struct bnx2fc_hba *hba = handle;
1792     struct cnic_dev *cnic;
1793     struct fcoe_stats_info *stats_addr;
1794 
1795     if (!hba)
1796         return -EINVAL;
1797 
1798     cnic = hba->cnic;
1799     stats_addr = &cnic->stats_addr->fcoe_stat;
1800     if (!stats_addr)
1801         return -EINVAL;
1802 
1803     strncpy(stats_addr->version, BNX2FC_VERSION,
1804         sizeof(stats_addr->version));
1805     stats_addr->txq_size = BNX2FC_SQ_WQES_MAX;
1806     stats_addr->rxq_size = BNX2FC_CQ_WQES_MAX;
1807 
1808     return 0;
1809 }
1810 
1811 
1812 /**
1813  * bnx2fc_ulp_start - cnic callback to initialize & start adapter instance
1814  *
1815  * @handle: transport handle pointing to adapter structure
1816  *
1817  * This function maps adapter structure to pcidev structure and initiates
1818  *  firmware handshake to enable/initialize on-chip FCoE components.
1819  *  This bnx2fc - cnic interface api callback is used after following
1820  *  conditions are met -
1821  *  a) underlying network interface is up (marked by event NETDEV_UP
1822  *      from netdev
1823  *  b) bnx2fc adatper structure is registered.
1824  */
1825 static void bnx2fc_ulp_start(void *handle)
1826 {
1827     struct bnx2fc_hba *hba = handle;
1828     struct bnx2fc_interface *interface;
1829     struct fcoe_ctlr *ctlr;
1830     struct fc_lport *lport;
1831 
1832     mutex_lock(&bnx2fc_dev_lock);
1833 
1834     if (!test_bit(BNX2FC_FLAG_FW_INIT_DONE, &hba->flags))
1835         bnx2fc_fw_init(hba);
1836 
1837     BNX2FC_MISC_DBG("bnx2fc started.\n");
1838 
1839     list_for_each_entry(interface, &if_list, list) {
1840         if (interface->hba == hba) {
1841             ctlr = bnx2fc_to_ctlr(interface);
1842             lport = ctlr->lp;
1843             /* Kick off Fabric discovery*/
1844             printk(KERN_ERR PFX "ulp_init: start discovery\n");
1845             lport->tt.frame_send = bnx2fc_xmit;
1846             bnx2fc_start_disc(interface);
1847         }
1848     }
1849 
1850     mutex_unlock(&bnx2fc_dev_lock);
1851 }
1852 
1853 static void bnx2fc_port_shutdown(struct fc_lport *lport)
1854 {
1855     BNX2FC_MISC_DBG("Entered %s\n", __func__);
1856     fc_fabric_logoff(lport);
1857     fc_lport_destroy(lport);
1858 }
1859 
1860 static void bnx2fc_stop(struct bnx2fc_interface *interface)
1861 {
1862     struct fcoe_ctlr *ctlr = bnx2fc_to_ctlr(interface);
1863     struct fc_lport *lport;
1864     struct fc_lport *vport;
1865 
1866     if (!test_bit(BNX2FC_FLAG_FW_INIT_DONE, &interface->hba->flags))
1867         return;
1868 
1869     lport = ctlr->lp;
1870     bnx2fc_port_shutdown(lport);
1871 
1872     mutex_lock(&lport->lp_mutex);
1873     list_for_each_entry(vport, &lport->vports, list)
1874         fc_host_port_type(vport->host) =
1875                     FC_PORTTYPE_UNKNOWN;
1876     mutex_unlock(&lport->lp_mutex);
1877     fc_host_port_type(lport->host) = FC_PORTTYPE_UNKNOWN;
1878     fcoe_ctlr_link_down(ctlr);
1879     fcoe_clean_pending_queue(lport);
1880 }
1881 
1882 static int bnx2fc_fw_init(struct bnx2fc_hba *hba)
1883 {
1884 #define BNX2FC_INIT_POLL_TIME       (1000 / HZ)
1885     int rc = -1;
1886     int i = HZ;
1887 
1888     rc = bnx2fc_bind_adapter_devices(hba);
1889     if (rc) {
1890         printk(KERN_ALERT PFX
1891             "bnx2fc_bind_adapter_devices failed - rc = %d\n", rc);
1892         goto err_out;
1893     }
1894 
1895     rc = bnx2fc_send_fw_fcoe_init_msg(hba);
1896     if (rc) {
1897         printk(KERN_ALERT PFX
1898             "bnx2fc_send_fw_fcoe_init_msg failed - rc = %d\n", rc);
1899         goto err_unbind;
1900     }
1901 
1902     /*
1903      * Wait until the adapter init message is complete, and adapter
1904      * state is UP.
1905      */
1906     while (!test_bit(ADAPTER_STATE_UP, &hba->adapter_state) && i--)
1907         msleep(BNX2FC_INIT_POLL_TIME);
1908 
1909     if (!test_bit(ADAPTER_STATE_UP, &hba->adapter_state)) {
1910         printk(KERN_ERR PFX "bnx2fc_start: %s failed to initialize.  "
1911                 "Ignoring...\n",
1912                 hba->cnic->netdev->name);
1913         rc = -1;
1914         goto err_unbind;
1915     }
1916 
1917 
1918     set_bit(BNX2FC_FLAG_FW_INIT_DONE, &hba->flags);
1919     return 0;
1920 
1921 err_unbind:
1922     bnx2fc_unbind_adapter_devices(hba);
1923 err_out:
1924     return rc;
1925 }
1926 
1927 static void bnx2fc_fw_destroy(struct bnx2fc_hba *hba)
1928 {
1929     if (test_and_clear_bit(BNX2FC_FLAG_FW_INIT_DONE, &hba->flags)) {
1930         if (bnx2fc_send_fw_fcoe_destroy_msg(hba) == 0) {
1931             timer_setup(&hba->destroy_timer, bnx2fc_destroy_timer,
1932                     0);
1933             hba->destroy_timer.expires = BNX2FC_FW_TIMEOUT +
1934                                 jiffies;
1935             add_timer(&hba->destroy_timer);
1936             wait_event_interruptible(hba->destroy_wait,
1937                     test_bit(BNX2FC_FLAG_DESTROY_CMPL,
1938                          &hba->flags));
1939             clear_bit(BNX2FC_FLAG_DESTROY_CMPL, &hba->flags);
1940             /* This should never happen */
1941             if (signal_pending(current))
1942                 flush_signals(current);
1943 
1944             del_timer_sync(&hba->destroy_timer);
1945         }
1946         bnx2fc_unbind_adapter_devices(hba);
1947     }
1948 }
1949 
1950 /**
1951  * bnx2fc_ulp_stop - cnic callback to shutdown adapter instance
1952  *
1953  * @handle: transport handle pointing to adapter structure
1954  *
1955  * Driver checks if adapter is already in shutdown mode, if not start
1956  *  the shutdown process.
1957  */
1958 static void bnx2fc_ulp_stop(void *handle)
1959 {
1960     struct bnx2fc_hba *hba = handle;
1961     struct bnx2fc_interface *interface;
1962 
1963     printk(KERN_ERR "ULP_STOP\n");
1964 
1965     mutex_lock(&bnx2fc_dev_lock);
1966     if (!test_bit(BNX2FC_FLAG_FW_INIT_DONE, &hba->flags))
1967         goto exit;
1968     list_for_each_entry(interface, &if_list, list) {
1969         if (interface->hba == hba)
1970             bnx2fc_stop(interface);
1971     }
1972     BUG_ON(hba->num_ofld_sess != 0);
1973 
1974     mutex_lock(&hba->hba_mutex);
1975     clear_bit(ADAPTER_STATE_UP, &hba->adapter_state);
1976     clear_bit(ADAPTER_STATE_GOING_DOWN,
1977           &hba->adapter_state);
1978 
1979     clear_bit(ADAPTER_STATE_READY, &hba->adapter_state);
1980     mutex_unlock(&hba->hba_mutex);
1981 
1982     bnx2fc_fw_destroy(hba);
1983 exit:
1984     mutex_unlock(&bnx2fc_dev_lock);
1985 }
1986 
1987 static void bnx2fc_start_disc(struct bnx2fc_interface *interface)
1988 {
1989     struct fcoe_ctlr *ctlr = bnx2fc_to_ctlr(interface);
1990     struct fc_lport *lport;
1991     int wait_cnt = 0;
1992 
1993     BNX2FC_MISC_DBG("Entered %s\n", __func__);
1994     /* Kick off FIP/FLOGI */
1995     if (!test_bit(BNX2FC_FLAG_FW_INIT_DONE, &interface->hba->flags)) {
1996         printk(KERN_ERR PFX "Init not done yet\n");
1997         return;
1998     }
1999 
2000     lport = ctlr->lp;
2001     BNX2FC_HBA_DBG(lport, "calling fc_fabric_login\n");
2002 
2003     if (!bnx2fc_link_ok(lport) && interface->enabled) {
2004         BNX2FC_HBA_DBG(lport, "ctlr_link_up\n");
2005         fcoe_ctlr_link_up(ctlr);
2006         fc_host_port_type(lport->host) = FC_PORTTYPE_NPORT;
2007         set_bit(ADAPTER_STATE_READY, &interface->hba->adapter_state);
2008     }
2009 
2010     /* wait for the FCF to be selected before issuing FLOGI */
2011     while (!ctlr->sel_fcf) {
2012         msleep(250);
2013         /* give up after 3 secs */
2014         if (++wait_cnt > 12)
2015             break;
2016     }
2017 
2018     /* Reset max receive frame size to default */
2019     if (fc_set_mfs(lport, BNX2FC_MFS))
2020         return;
2021 
2022     fc_lport_init(lport);
2023     fc_fabric_login(lport);
2024 }
2025 
2026 
2027 /**
2028  * bnx2fc_ulp_init - Initialize an adapter instance
2029  *
2030  * @dev :   cnic device handle
2031  * Called from cnic_register_driver() context to initialize all
2032  *  enumerated cnic devices. This routine allocates adapter structure
2033  *  and other device specific resources.
2034  */
2035 static void bnx2fc_ulp_init(struct cnic_dev *dev)
2036 {
2037     struct bnx2fc_hba *hba;
2038     int rc = 0;
2039 
2040     BNX2FC_MISC_DBG("Entered %s\n", __func__);
2041     /* bnx2fc works only when bnx2x is loaded */
2042     if (!test_bit(CNIC_F_BNX2X_CLASS, &dev->flags) ||
2043         (dev->max_fcoe_conn == 0)) {
2044         printk(KERN_ERR PFX "bnx2fc FCoE not supported on %s,"
2045                     " flags: %lx fcoe_conn: %d\n",
2046             dev->netdev->name, dev->flags, dev->max_fcoe_conn);
2047         return;
2048     }
2049 
2050     hba = bnx2fc_hba_create(dev);
2051     if (!hba) {
2052         printk(KERN_ERR PFX "hba initialization failed\n");
2053         return;
2054     }
2055 
2056     pr_info(PFX "FCoE initialized for %s.\n", dev->netdev->name);
2057 
2058     /* Add HBA to the adapter list */
2059     mutex_lock(&bnx2fc_dev_lock);
2060     list_add_tail(&hba->list, &adapter_list);
2061     adapter_count++;
2062     mutex_unlock(&bnx2fc_dev_lock);
2063 
2064     dev->fcoe_cap = &hba->fcoe_cap;
2065     clear_bit(BNX2FC_CNIC_REGISTERED, &hba->reg_with_cnic);
2066     rc = dev->register_device(dev, CNIC_ULP_FCOE,
2067                         (void *) hba);
2068     if (rc)
2069         printk(KERN_ERR PFX "register_device failed, rc = %d\n", rc);
2070     else
2071         set_bit(BNX2FC_CNIC_REGISTERED, &hba->reg_with_cnic);
2072 }
2073 
2074 /* Assumes rtnl_lock and the bnx2fc_dev_lock are already taken */
2075 static int __bnx2fc_disable(struct fcoe_ctlr *ctlr)
2076 {
2077     struct bnx2fc_interface *interface = fcoe_ctlr_priv(ctlr);
2078 
2079     if (interface->enabled) {
2080         if (!ctlr->lp) {
2081             pr_err(PFX "__bnx2fc_disable: lport not found\n");
2082             return -ENODEV;
2083         } else {
2084             interface->enabled = false;
2085             fcoe_ctlr_link_down(ctlr);
2086             fcoe_clean_pending_queue(ctlr->lp);
2087         }
2088     }
2089     return 0;
2090 }
2091 
2092 /*
2093  * Deperecated: Use bnx2fc_enabled()
2094  */
2095 static int bnx2fc_disable(struct net_device *netdev)
2096 {
2097     struct bnx2fc_interface *interface;
2098     struct fcoe_ctlr *ctlr;
2099     int rc = 0;
2100 
2101     rtnl_lock();
2102     mutex_lock(&bnx2fc_dev_lock);
2103 
2104     interface = bnx2fc_interface_lookup(netdev);
2105     ctlr = bnx2fc_to_ctlr(interface);
2106 
2107     if (!interface) {
2108         rc = -ENODEV;
2109         pr_err(PFX "bnx2fc_disable: interface not found\n");
2110     } else {
2111         rc = __bnx2fc_disable(ctlr);
2112     }
2113     mutex_unlock(&bnx2fc_dev_lock);
2114     rtnl_unlock();
2115     return rc;
2116 }
2117 
2118 static uint bnx2fc_npiv_create_vports(struct fc_lport *lport,
2119                       struct cnic_fc_npiv_tbl *npiv_tbl)
2120 {
2121     struct fc_vport_identifiers vpid;
2122     uint i, created = 0;
2123     u64 wwnn = 0;
2124     char wwpn_str[32];
2125     char wwnn_str[32];
2126 
2127     if (npiv_tbl->count > MAX_NPIV_ENTRIES) {
2128         BNX2FC_HBA_DBG(lport, "Exceeded count max of npiv table\n");
2129         goto done;
2130     }
2131 
2132     /* Sanity check the first entry to make sure it's not 0 */
2133     if (wwn_to_u64(npiv_tbl->wwnn[0]) == 0 &&
2134         wwn_to_u64(npiv_tbl->wwpn[0]) == 0) {
2135         BNX2FC_HBA_DBG(lport, "First NPIV table entries invalid.\n");
2136         goto done;
2137     }
2138 
2139     vpid.roles = FC_PORT_ROLE_FCP_INITIATOR;
2140     vpid.vport_type = FC_PORTTYPE_NPIV;
2141     vpid.disable = false;
2142 
2143     for (i = 0; i < npiv_tbl->count; i++) {
2144         wwnn = wwn_to_u64(npiv_tbl->wwnn[i]);
2145         if (wwnn == 0) {
2146             /*
2147              * If we get a 0 element from for the WWNN then assume
2148              * the WWNN should be the same as the physical port.
2149              */
2150             wwnn = lport->wwnn;
2151         }
2152         vpid.node_name = wwnn;
2153         vpid.port_name = wwn_to_u64(npiv_tbl->wwpn[i]);
2154         scnprintf(vpid.symbolic_name, sizeof(vpid.symbolic_name),
2155             "NPIV[%u]:%016llx-%016llx",
2156             created, vpid.port_name, vpid.node_name);
2157         fcoe_wwn_to_str(vpid.node_name, wwnn_str, sizeof(wwnn_str));
2158         fcoe_wwn_to_str(vpid.port_name, wwpn_str, sizeof(wwpn_str));
2159         BNX2FC_HBA_DBG(lport, "Creating vport %s:%s.\n", wwnn_str,
2160             wwpn_str);
2161         if (fc_vport_create(lport->host, 0, &vpid))
2162             created++;
2163         else
2164             BNX2FC_HBA_DBG(lport, "Failed to create vport\n");
2165     }
2166 done:
2167     return created;
2168 }
2169 
2170 static int __bnx2fc_enable(struct fcoe_ctlr *ctlr)
2171 {
2172     struct bnx2fc_interface *interface = fcoe_ctlr_priv(ctlr);
2173     struct bnx2fc_hba *hba;
2174     struct cnic_fc_npiv_tbl *npiv_tbl;
2175     struct fc_lport *lport;
2176 
2177     if (!interface->enabled) {
2178         if (!ctlr->lp) {
2179             pr_err(PFX "__bnx2fc_enable: lport not found\n");
2180             return -ENODEV;
2181         } else if (!bnx2fc_link_ok(ctlr->lp)) {
2182             fcoe_ctlr_link_up(ctlr);
2183             interface->enabled = true;
2184         }
2185     }
2186 
2187     /* Create static NPIV ports if any are contained in NVRAM */
2188     hba = interface->hba;
2189     lport = ctlr->lp;
2190 
2191     if (!hba)
2192         goto done;
2193 
2194     if (!hba->cnic)
2195         goto done;
2196 
2197     if (!lport)
2198         goto done;
2199 
2200     if (!lport->host)
2201         goto done;
2202 
2203     if (!hba->cnic->get_fc_npiv_tbl)
2204         goto done;
2205 
2206     npiv_tbl = kzalloc(sizeof(struct cnic_fc_npiv_tbl), GFP_KERNEL);
2207     if (!npiv_tbl)
2208         goto done;
2209 
2210     if (hba->cnic->get_fc_npiv_tbl(hba->cnic, npiv_tbl))
2211         goto done_free;
2212 
2213     bnx2fc_npiv_create_vports(lport, npiv_tbl);
2214 done_free:
2215     kfree(npiv_tbl);
2216 done:
2217     return 0;
2218 }
2219 
2220 /*
2221  * Deprecated: Use bnx2fc_enabled()
2222  */
2223 static int bnx2fc_enable(struct net_device *netdev)
2224 {
2225     struct bnx2fc_interface *interface;
2226     struct fcoe_ctlr *ctlr;
2227     int rc = 0;
2228 
2229     rtnl_lock();
2230     mutex_lock(&bnx2fc_dev_lock);
2231 
2232     interface = bnx2fc_interface_lookup(netdev);
2233     ctlr = bnx2fc_to_ctlr(interface);
2234     if (!interface) {
2235         rc = -ENODEV;
2236         pr_err(PFX "bnx2fc_enable: interface not found\n");
2237     } else {
2238         rc = __bnx2fc_enable(ctlr);
2239     }
2240 
2241     mutex_unlock(&bnx2fc_dev_lock);
2242     rtnl_unlock();
2243     return rc;
2244 }
2245 
2246 /**
2247  * bnx2fc_ctlr_enabled() - Enable or disable an FCoE Controller
2248  * @cdev: The FCoE Controller that is being enabled or disabled
2249  *
2250  * fcoe_sysfs will ensure that the state of 'enabled' has
2251  * changed, so no checking is necessary here. This routine simply
2252  * calls fcoe_enable or fcoe_disable, both of which are deprecated.
2253  * When those routines are removed the functionality can be merged
2254  * here.
2255  */
2256 static int bnx2fc_ctlr_enabled(struct fcoe_ctlr_device *cdev)
2257 {
2258     struct fcoe_ctlr *ctlr = fcoe_ctlr_device_priv(cdev);
2259 
2260     switch (cdev->enabled) {
2261     case FCOE_CTLR_ENABLED:
2262         return __bnx2fc_enable(ctlr);
2263     case FCOE_CTLR_DISABLED:
2264         return __bnx2fc_disable(ctlr);
2265     case FCOE_CTLR_UNUSED:
2266     default:
2267         return -ENOTSUPP;
2268     }
2269 }
2270 
2271 enum bnx2fc_create_link_state {
2272     BNX2FC_CREATE_LINK_DOWN,
2273     BNX2FC_CREATE_LINK_UP,
2274 };
2275 
2276 /**
2277  * _bnx2fc_create() - Create bnx2fc FCoE interface
2278  * @netdev  :   The net_device object the Ethernet interface to create on
2279  * @fip_mode:   The FIP mode for this creation
2280  * @link_state: The ctlr link state on creation
2281  *
2282  * Called from either the libfcoe 'create' module parameter
2283  * via fcoe_create or from fcoe_syfs's ctlr_create file.
2284  *
2285  * libfcoe's 'create' module parameter is deprecated so some
2286  * consolidation of code can be done when that interface is
2287  * removed.
2288  *
2289  * Returns: 0 for success
2290  */
2291 static int _bnx2fc_create(struct net_device *netdev,
2292               enum fip_mode fip_mode,
2293               enum bnx2fc_create_link_state link_state)
2294 {
2295     struct fcoe_ctlr_device *cdev;
2296     struct fcoe_ctlr *ctlr;
2297     struct bnx2fc_interface *interface;
2298     struct bnx2fc_hba *hba;
2299     struct net_device *phys_dev = netdev;
2300     struct fc_lport *lport;
2301     struct ethtool_drvinfo drvinfo;
2302     int rc = 0;
2303     int vlan_id = 0;
2304 
2305     BNX2FC_MISC_DBG("Entered bnx2fc_create\n");
2306     if (fip_mode != FIP_MODE_FABRIC) {
2307         printk(KERN_ERR "fip mode not FABRIC\n");
2308         return -EIO;
2309     }
2310 
2311     rtnl_lock();
2312 
2313     mutex_lock(&bnx2fc_dev_lock);
2314 
2315     if (!try_module_get(THIS_MODULE)) {
2316         rc = -EINVAL;
2317         goto mod_err;
2318     }
2319 
2320     /* obtain physical netdev */
2321     if (is_vlan_dev(netdev))
2322         phys_dev = vlan_dev_real_dev(netdev);
2323 
2324     /* verify if the physical device is a netxtreme2 device */
2325     if (phys_dev->ethtool_ops && phys_dev->ethtool_ops->get_drvinfo) {
2326         memset(&drvinfo, 0, sizeof(drvinfo));
2327         phys_dev->ethtool_ops->get_drvinfo(phys_dev, &drvinfo);
2328         if (strncmp(drvinfo.driver, "bnx2x", strlen("bnx2x"))) {
2329             printk(KERN_ERR PFX "Not a netxtreme2 device\n");
2330             rc = -EINVAL;
2331             goto netdev_err;
2332         }
2333     } else {
2334         printk(KERN_ERR PFX "unable to obtain drv_info\n");
2335         rc = -EINVAL;
2336         goto netdev_err;
2337     }
2338 
2339     /* obtain interface and initialize rest of the structure */
2340     hba = bnx2fc_hba_lookup(phys_dev);
2341     if (!hba) {
2342         rc = -ENODEV;
2343         printk(KERN_ERR PFX "bnx2fc_create: hba not found\n");
2344         goto netdev_err;
2345     }
2346 
2347     if (bnx2fc_interface_lookup(netdev)) {
2348         rc = -EEXIST;
2349         goto netdev_err;
2350     }
2351 
2352     interface = bnx2fc_interface_create(hba, netdev, fip_mode);
2353     if (!interface) {
2354         printk(KERN_ERR PFX "bnx2fc_interface_create failed\n");
2355         rc = -ENOMEM;
2356         goto netdev_err;
2357     }
2358 
2359     if (is_vlan_dev(netdev)) {
2360         vlan_id = vlan_dev_vlan_id(netdev);
2361         interface->vlan_enabled = 1;
2362     }
2363 
2364     ctlr = bnx2fc_to_ctlr(interface);
2365     cdev = fcoe_ctlr_to_ctlr_dev(ctlr);
2366     interface->vlan_id = vlan_id;
2367     interface->tm_timeout = BNX2FC_TM_TIMEOUT;
2368 
2369     interface->timer_work_queue =
2370             create_singlethread_workqueue("bnx2fc_timer_wq");
2371     if (!interface->timer_work_queue) {
2372         printk(KERN_ERR PFX "ulp_init could not create timer_wq\n");
2373         rc = -EINVAL;
2374         goto ifput_err;
2375     }
2376 
2377     lport = bnx2fc_if_create(interface, &cdev->dev, 0);
2378     if (!lport) {
2379         printk(KERN_ERR PFX "Failed to create interface (%s)\n",
2380             netdev->name);
2381         rc = -EINVAL;
2382         goto if_create_err;
2383     }
2384 
2385     /* Add interface to if_list */
2386     list_add_tail(&interface->list, &if_list);
2387 
2388     lport->boot_time = jiffies;
2389 
2390     /* Make this master N_port */
2391     ctlr->lp = lport;
2392 
2393     if (link_state == BNX2FC_CREATE_LINK_UP)
2394         cdev->enabled = FCOE_CTLR_ENABLED;
2395     else
2396         cdev->enabled = FCOE_CTLR_DISABLED;
2397 
2398     if (link_state == BNX2FC_CREATE_LINK_UP &&
2399         !bnx2fc_link_ok(lport)) {
2400         fcoe_ctlr_link_up(ctlr);
2401         fc_host_port_type(lport->host) = FC_PORTTYPE_NPORT;
2402         set_bit(ADAPTER_STATE_READY, &interface->hba->adapter_state);
2403     }
2404 
2405     BNX2FC_HBA_DBG(lport, "create: START DISC\n");
2406     bnx2fc_start_disc(interface);
2407 
2408     if (link_state == BNX2FC_CREATE_LINK_UP)
2409         interface->enabled = true;
2410 
2411     /*
2412      * Release from kref_init in bnx2fc_interface_setup, on success
2413      * lport should be holding a reference taken in bnx2fc_if_create
2414      */
2415     bnx2fc_interface_put(interface);
2416     /* put netdev that was held while calling dev_get_by_name */
2417     mutex_unlock(&bnx2fc_dev_lock);
2418     rtnl_unlock();
2419     return 0;
2420 
2421 if_create_err:
2422     destroy_workqueue(interface->timer_work_queue);
2423 ifput_err:
2424     bnx2fc_net_cleanup(interface);
2425     bnx2fc_interface_put(interface);
2426     goto mod_err;
2427 netdev_err:
2428     module_put(THIS_MODULE);
2429 mod_err:
2430     mutex_unlock(&bnx2fc_dev_lock);
2431     rtnl_unlock();
2432     return rc;
2433 }
2434 
2435 /**
2436  * bnx2fc_create() - Create a bnx2fc interface
2437  * @netdev  : The net_device object the Ethernet interface to create on
2438  * @fip_mode: The FIP mode for this creation
2439  *
2440  * Called from fcoe transport
2441  *
2442  * Returns: 0 for success
2443  */
2444 static int bnx2fc_create(struct net_device *netdev, enum fip_mode fip_mode)
2445 {
2446     return _bnx2fc_create(netdev, fip_mode, BNX2FC_CREATE_LINK_UP);
2447 }
2448 
2449 /**
2450  * bnx2fc_ctlr_alloc() - Allocate a bnx2fc interface from fcoe_sysfs
2451  * @netdev: The net_device to be used by the allocated FCoE Controller
2452  *
2453  * This routine is called from fcoe_sysfs. It will start the fcoe_ctlr
2454  * in a link_down state. The allows the user an opportunity to configure
2455  * the FCoE Controller from sysfs before enabling the FCoE Controller.
2456  *
2457  * Creating in with this routine starts the FCoE Controller in Fabric
2458  * mode. The user can change to VN2VN or another mode before enabling.
2459  */
2460 static int bnx2fc_ctlr_alloc(struct net_device *netdev)
2461 {
2462     return _bnx2fc_create(netdev, FIP_MODE_FABRIC,
2463                   BNX2FC_CREATE_LINK_DOWN);
2464 }
2465 
2466 /**
2467  * bnx2fc_find_hba_for_cnic - maps cnic instance to bnx2fc hba instance
2468  *
2469  * @cnic:   Pointer to cnic device instance
2470  *
2471  **/
2472 static struct bnx2fc_hba *bnx2fc_find_hba_for_cnic(struct cnic_dev *cnic)
2473 {
2474     struct bnx2fc_hba *hba;
2475 
2476     /* Called with bnx2fc_dev_lock held */
2477     list_for_each_entry(hba, &adapter_list, list) {
2478         if (hba->cnic == cnic)
2479             return hba;
2480     }
2481     return NULL;
2482 }
2483 
2484 static struct bnx2fc_interface *bnx2fc_interface_lookup(struct net_device
2485                             *netdev)
2486 {
2487     struct bnx2fc_interface *interface;
2488 
2489     /* Called with bnx2fc_dev_lock held */
2490     list_for_each_entry(interface, &if_list, list) {
2491         if (interface->netdev == netdev)
2492             return interface;
2493     }
2494     return NULL;
2495 }
2496 
2497 static struct bnx2fc_hba *bnx2fc_hba_lookup(struct net_device
2498                               *phys_dev)
2499 {
2500     struct bnx2fc_hba *hba;
2501 
2502     /* Called with bnx2fc_dev_lock held */
2503     list_for_each_entry(hba, &adapter_list, list) {
2504         if (hba->phys_dev == phys_dev)
2505             return hba;
2506     }
2507     printk(KERN_ERR PFX "adapter_lookup: hba NULL\n");
2508     return NULL;
2509 }
2510 
2511 /**
2512  * bnx2fc_ulp_exit - shuts down adapter instance and frees all resources
2513  *
2514  * @dev:    cnic device handle
2515  */
2516 static void bnx2fc_ulp_exit(struct cnic_dev *dev)
2517 {
2518     struct bnx2fc_hba *hba;
2519     struct bnx2fc_interface *interface, *tmp;
2520 
2521     BNX2FC_MISC_DBG("Entered bnx2fc_ulp_exit\n");
2522 
2523     if (!test_bit(CNIC_F_BNX2X_CLASS, &dev->flags)) {
2524         printk(KERN_ERR PFX "bnx2fc port check: %s, flags: %lx\n",
2525             dev->netdev->name, dev->flags);
2526         return;
2527     }
2528 
2529     mutex_lock(&bnx2fc_dev_lock);
2530     hba = bnx2fc_find_hba_for_cnic(dev);
2531     if (!hba) {
2532         printk(KERN_ERR PFX "bnx2fc_ulp_exit: hba not found, dev 0%p\n",
2533                dev);
2534         mutex_unlock(&bnx2fc_dev_lock);
2535         return;
2536     }
2537 
2538     list_del_init(&hba->list);
2539     adapter_count--;
2540 
2541     list_for_each_entry_safe(interface, tmp, &if_list, list)
2542         /* destroy not called yet, move to quiesced list */
2543         if (interface->hba == hba)
2544             __bnx2fc_destroy(interface);
2545     mutex_unlock(&bnx2fc_dev_lock);
2546 
2547     bnx2fc_ulp_stop(hba);
2548     /* unregister cnic device */
2549     if (test_and_clear_bit(BNX2FC_CNIC_REGISTERED, &hba->reg_with_cnic))
2550         hba->cnic->unregister_device(hba->cnic, CNIC_ULP_FCOE);
2551     bnx2fc_hba_destroy(hba);
2552 }
2553 
2554 static void bnx2fc_rport_terminate_io(struct fc_rport *rport)
2555 {
2556     /* This is a no-op */
2557 }
2558 
2559 /**
2560  * bnx2fc_fcoe_reset - Resets the fcoe
2561  *
2562  * @shost: shost the reset is from
2563  *
2564  * Returns: always 0
2565  */
2566 static int bnx2fc_fcoe_reset(struct Scsi_Host *shost)
2567 {
2568     struct fc_lport *lport = shost_priv(shost);
2569     fc_lport_reset(lport);
2570     return 0;
2571 }
2572 
2573 
2574 static bool bnx2fc_match(struct net_device *netdev)
2575 {
2576     struct net_device *phys_dev = netdev;
2577 
2578     mutex_lock(&bnx2fc_dev_lock);
2579     if (is_vlan_dev(netdev))
2580         phys_dev = vlan_dev_real_dev(netdev);
2581 
2582     if (bnx2fc_hba_lookup(phys_dev)) {
2583         mutex_unlock(&bnx2fc_dev_lock);
2584         return true;
2585     }
2586 
2587     mutex_unlock(&bnx2fc_dev_lock);
2588     return false;
2589 }
2590 
2591 
2592 static struct fcoe_transport bnx2fc_transport = {
2593     .name = {"bnx2fc"},
2594     .attached = false,
2595     .list = LIST_HEAD_INIT(bnx2fc_transport.list),
2596     .alloc = bnx2fc_ctlr_alloc,
2597     .match = bnx2fc_match,
2598     .create = bnx2fc_create,
2599     .destroy = bnx2fc_destroy,
2600     .enable = bnx2fc_enable,
2601     .disable = bnx2fc_disable,
2602 };
2603 
2604 /**
2605  * bnx2fc_cpu_online - Create a receive thread for an  online CPU
2606  *
2607  * @cpu: cpu index for the online cpu
2608  */
2609 static int bnx2fc_cpu_online(unsigned int cpu)
2610 {
2611     struct bnx2fc_percpu_s *p;
2612     struct task_struct *thread;
2613 
2614     p = &per_cpu(bnx2fc_percpu, cpu);
2615 
2616     thread = kthread_create_on_node(bnx2fc_percpu_io_thread,
2617                     (void *)p, cpu_to_node(cpu),
2618                     "bnx2fc_thread/%d", cpu);
2619     if (IS_ERR(thread))
2620         return PTR_ERR(thread);
2621 
2622     /* bind thread to the cpu */
2623     kthread_bind(thread, cpu);
2624     p->iothread = thread;
2625     wake_up_process(thread);
2626     return 0;
2627 }
2628 
2629 static int bnx2fc_cpu_offline(unsigned int cpu)
2630 {
2631     struct bnx2fc_percpu_s *p;
2632     struct task_struct *thread;
2633     struct bnx2fc_work *work, *tmp;
2634 
2635     BNX2FC_MISC_DBG("destroying io thread for CPU %d\n", cpu);
2636 
2637     /* Prevent any new work from being queued for this CPU */
2638     p = &per_cpu(bnx2fc_percpu, cpu);
2639     spin_lock_bh(&p->fp_work_lock);
2640     thread = p->iothread;
2641     p->iothread = NULL;
2642 
2643     /* Free all work in the list */
2644     list_for_each_entry_safe(work, tmp, &p->work_list, list) {
2645         list_del_init(&work->list);
2646         bnx2fc_process_cq_compl(work->tgt, work->wqe, work->rq_data,
2647                     work->num_rq, work->task);
2648         kfree(work);
2649     }
2650 
2651     spin_unlock_bh(&p->fp_work_lock);
2652 
2653     if (thread)
2654         kthread_stop(thread);
2655     return 0;
2656 }
2657 
2658 static int bnx2fc_slave_configure(struct scsi_device *sdev)
2659 {
2660     if (!bnx2fc_queue_depth)
2661         return 0;
2662 
2663     scsi_change_queue_depth(sdev, bnx2fc_queue_depth);
2664     return 0;
2665 }
2666 
2667 static enum cpuhp_state bnx2fc_online_state;
2668 
2669 /**
2670  * bnx2fc_mod_init - module init entry point
2671  *
2672  * Initialize driver wide global data structures, and register
2673  * with cnic module
2674  **/
2675 static int __init bnx2fc_mod_init(void)
2676 {
2677     struct fcoe_percpu_s *bg;
2678     struct task_struct *l2_thread;
2679     int rc = 0;
2680     unsigned int cpu = 0;
2681     struct bnx2fc_percpu_s *p;
2682 
2683     printk(KERN_INFO PFX "%s", version);
2684 
2685     /* register as a fcoe transport */
2686     rc = fcoe_transport_attach(&bnx2fc_transport);
2687     if (rc) {
2688         printk(KERN_ERR "failed to register an fcoe transport, check "
2689             "if libfcoe is loaded\n");
2690         goto out;
2691     }
2692 
2693     INIT_LIST_HEAD(&adapter_list);
2694     INIT_LIST_HEAD(&if_list);
2695     mutex_init(&bnx2fc_dev_lock);
2696     adapter_count = 0;
2697 
2698     /* Attach FC transport template */
2699     rc = bnx2fc_attach_transport();
2700     if (rc)
2701         goto detach_ft;
2702 
2703     bnx2fc_wq = alloc_workqueue("bnx2fc", 0, 0);
2704     if (!bnx2fc_wq) {
2705         rc = -ENOMEM;
2706         goto release_bt;
2707     }
2708 
2709     bg = &bnx2fc_global;
2710     skb_queue_head_init(&bg->fcoe_rx_list);
2711     l2_thread = kthread_run(bnx2fc_l2_rcv_thread,
2712                 (void *)bg,
2713                 "bnx2fc_l2_thread");
2714     if (IS_ERR(l2_thread)) {
2715         rc = PTR_ERR(l2_thread);
2716         goto free_wq;
2717     }
2718     spin_lock_bh(&bg->fcoe_rx_list.lock);
2719     bg->kthread = l2_thread;
2720     spin_unlock_bh(&bg->fcoe_rx_list.lock);
2721 
2722     for_each_possible_cpu(cpu) {
2723         p = &per_cpu(bnx2fc_percpu, cpu);
2724         INIT_LIST_HEAD(&p->work_list);
2725         spin_lock_init(&p->fp_work_lock);
2726     }
2727 
2728     rc = cpuhp_setup_state(CPUHP_AP_ONLINE_DYN, "scsi/bnx2fc:online",
2729                    bnx2fc_cpu_online, bnx2fc_cpu_offline);
2730     if (rc < 0)
2731         goto stop_thread;
2732     bnx2fc_online_state = rc;
2733 
2734     cnic_register_driver(CNIC_ULP_FCOE, &bnx2fc_cnic_cb);
2735     return 0;
2736 
2737 stop_thread:
2738     kthread_stop(l2_thread);
2739 free_wq:
2740     destroy_workqueue(bnx2fc_wq);
2741 release_bt:
2742     bnx2fc_release_transport();
2743 detach_ft:
2744     fcoe_transport_detach(&bnx2fc_transport);
2745 out:
2746     return rc;
2747 }
2748 
2749 static void __exit bnx2fc_mod_exit(void)
2750 {
2751     LIST_HEAD(to_be_deleted);
2752     struct bnx2fc_hba *hba, *next;
2753     struct fcoe_percpu_s *bg;
2754     struct task_struct *l2_thread;
2755     struct sk_buff *skb;
2756 
2757     /*
2758      * NOTE: Since cnic calls register_driver routine rtnl_lock,
2759      * it will have higher precedence than bnx2fc_dev_lock.
2760      * unregister_device() cannot be called with bnx2fc_dev_lock
2761      * held.
2762      */
2763     mutex_lock(&bnx2fc_dev_lock);
2764     list_splice_init(&adapter_list, &to_be_deleted);
2765     adapter_count = 0;
2766     mutex_unlock(&bnx2fc_dev_lock);
2767 
2768     /* Unregister with cnic */
2769     list_for_each_entry_safe(hba, next, &to_be_deleted, list) {
2770         list_del_init(&hba->list);
2771         printk(KERN_ERR PFX "MOD_EXIT:destroy hba = 0x%p\n",
2772                hba);
2773         bnx2fc_ulp_stop(hba);
2774         /* unregister cnic device */
2775         if (test_and_clear_bit(BNX2FC_CNIC_REGISTERED,
2776                        &hba->reg_with_cnic))
2777             hba->cnic->unregister_device(hba->cnic,
2778                              CNIC_ULP_FCOE);
2779         bnx2fc_hba_destroy(hba);
2780     }
2781     cnic_unregister_driver(CNIC_ULP_FCOE);
2782 
2783     /* Destroy global thread */
2784     bg = &bnx2fc_global;
2785     spin_lock_bh(&bg->fcoe_rx_list.lock);
2786     l2_thread = bg->kthread;
2787     bg->kthread = NULL;
2788     while ((skb = __skb_dequeue(&bg->fcoe_rx_list)) != NULL)
2789         kfree_skb(skb);
2790 
2791     spin_unlock_bh(&bg->fcoe_rx_list.lock);
2792 
2793     if (l2_thread)
2794         kthread_stop(l2_thread);
2795 
2796     cpuhp_remove_state(bnx2fc_online_state);
2797 
2798     destroy_workqueue(bnx2fc_wq);
2799     /*
2800      * detach from scsi transport
2801      * must happen after all destroys are done
2802      */
2803     bnx2fc_release_transport();
2804 
2805     /* detach from fcoe transport */
2806     fcoe_transport_detach(&bnx2fc_transport);
2807 }
2808 
2809 module_init(bnx2fc_mod_init);
2810 module_exit(bnx2fc_mod_exit);
2811 
2812 static struct fcoe_sysfs_function_template bnx2fc_fcoe_sysfs_templ = {
2813     .set_fcoe_ctlr_enabled = bnx2fc_ctlr_enabled,
2814     .get_fcoe_ctlr_link_fail = fcoe_ctlr_get_lesb,
2815     .get_fcoe_ctlr_vlink_fail = fcoe_ctlr_get_lesb,
2816     .get_fcoe_ctlr_miss_fka = fcoe_ctlr_get_lesb,
2817     .get_fcoe_ctlr_symb_err = fcoe_ctlr_get_lesb,
2818     .get_fcoe_ctlr_err_block = fcoe_ctlr_get_lesb,
2819     .get_fcoe_ctlr_fcs_error = fcoe_ctlr_get_lesb,
2820 
2821     .get_fcoe_fcf_selected = fcoe_fcf_get_selected,
2822     .get_fcoe_fcf_vlan_id = bnx2fc_fcf_get_vlan_id,
2823 };
2824 
2825 static struct fc_function_template bnx2fc_transport_function = {
2826     .show_host_node_name = 1,
2827     .show_host_port_name = 1,
2828     .show_host_supported_classes = 1,
2829     .show_host_supported_fc4s = 1,
2830     .show_host_active_fc4s = 1,
2831     .show_host_maxframe_size = 1,
2832 
2833     .show_host_port_id = 1,
2834     .show_host_supported_speeds = 1,
2835     .get_host_speed = fc_get_host_speed,
2836     .show_host_speed = 1,
2837     .show_host_port_type = 1,
2838     .get_host_port_state = fc_get_host_port_state,
2839     .show_host_port_state = 1,
2840     .show_host_symbolic_name = 1,
2841 
2842     .dd_fcrport_size = (sizeof(struct fc_rport_libfc_priv) +
2843                 sizeof(struct bnx2fc_rport)),
2844     .show_rport_maxframe_size = 1,
2845     .show_rport_supported_classes = 1,
2846 
2847     .show_host_fabric_name = 1,
2848     .show_starget_node_name = 1,
2849     .show_starget_port_name = 1,
2850     .show_starget_port_id = 1,
2851     .set_rport_dev_loss_tmo = fc_set_rport_loss_tmo,
2852     .show_rport_dev_loss_tmo = 1,
2853     .get_fc_host_stats = bnx2fc_get_host_stats,
2854 
2855     .issue_fc_host_lip = bnx2fc_fcoe_reset,
2856 
2857     .terminate_rport_io = bnx2fc_rport_terminate_io,
2858 
2859     .vport_create = bnx2fc_vport_create,
2860     .vport_delete = bnx2fc_vport_destroy,
2861     .vport_disable = bnx2fc_vport_disable,
2862     .bsg_request = fc_lport_bsg_request,
2863 };
2864 
2865 static struct fc_function_template bnx2fc_vport_xport_function = {
2866     .show_host_node_name = 1,
2867     .show_host_port_name = 1,
2868     .show_host_supported_classes = 1,
2869     .show_host_supported_fc4s = 1,
2870     .show_host_active_fc4s = 1,
2871     .show_host_maxframe_size = 1,
2872 
2873     .show_host_port_id = 1,
2874     .show_host_supported_speeds = 1,
2875     .get_host_speed = fc_get_host_speed,
2876     .show_host_speed = 1,
2877     .show_host_port_type = 1,
2878     .get_host_port_state = fc_get_host_port_state,
2879     .show_host_port_state = 1,
2880     .show_host_symbolic_name = 1,
2881 
2882     .dd_fcrport_size = (sizeof(struct fc_rport_libfc_priv) +
2883                 sizeof(struct bnx2fc_rport)),
2884     .show_rport_maxframe_size = 1,
2885     .show_rport_supported_classes = 1,
2886 
2887     .show_host_fabric_name = 1,
2888     .show_starget_node_name = 1,
2889     .show_starget_port_name = 1,
2890     .show_starget_port_id = 1,
2891     .set_rport_dev_loss_tmo = fc_set_rport_loss_tmo,
2892     .show_rport_dev_loss_tmo = 1,
2893     .get_fc_host_stats = fc_get_host_stats,
2894     .issue_fc_host_lip = bnx2fc_fcoe_reset,
2895     .terminate_rport_io = fc_rport_terminate_io,
2896     .bsg_request = fc_lport_bsg_request,
2897 };
2898 
2899 /*
2900  * Additional scsi_host attributes.
2901  */
2902 static ssize_t
2903 bnx2fc_tm_timeout_show(struct device *dev, struct device_attribute *attr,
2904     char *buf)
2905 {
2906     struct Scsi_Host *shost = class_to_shost(dev);
2907     struct fc_lport *lport = shost_priv(shost);
2908     struct fcoe_port *port = lport_priv(lport);
2909     struct bnx2fc_interface *interface = port->priv;
2910 
2911     sprintf(buf, "%u\n", interface->tm_timeout);
2912     return strlen(buf);
2913 }
2914 
2915 static ssize_t
2916 bnx2fc_tm_timeout_store(struct device *dev,
2917     struct device_attribute *attr, const char *buf, size_t count)
2918 {
2919     struct Scsi_Host *shost = class_to_shost(dev);
2920     struct fc_lport *lport = shost_priv(shost);
2921     struct fcoe_port *port = lport_priv(lport);
2922     struct bnx2fc_interface *interface = port->priv;
2923     int rval, val;
2924 
2925     rval = kstrtouint(buf, 10, &val);
2926     if (rval)
2927         return rval;
2928     if (val > 255)
2929         return -ERANGE;
2930 
2931     interface->tm_timeout = (u8)val;
2932     return strlen(buf);
2933 }
2934 
2935 static DEVICE_ATTR(tm_timeout, S_IRUGO|S_IWUSR, bnx2fc_tm_timeout_show,
2936     bnx2fc_tm_timeout_store);
2937 
2938 static struct attribute *bnx2fc_host_attrs[] = {
2939     &dev_attr_tm_timeout.attr,
2940     NULL,
2941 };
2942 
2943 ATTRIBUTE_GROUPS(bnx2fc_host);
2944 
2945 /*
2946  * scsi_host_template structure used while registering with SCSI-ml
2947  */
2948 static struct scsi_host_template bnx2fc_shost_template = {
2949     .module         = THIS_MODULE,
2950     .name           = "QLogic Offload FCoE Initiator",
2951     .queuecommand       = bnx2fc_queuecommand,
2952     .eh_timed_out       = fc_eh_timed_out,
2953     .eh_abort_handler   = bnx2fc_eh_abort,    /* abts */
2954     .eh_device_reset_handler = bnx2fc_eh_device_reset, /* lun reset */
2955     .eh_target_reset_handler = bnx2fc_eh_target_reset, /* tgt reset */
2956     .eh_host_reset_handler  = fc_eh_host_reset,
2957     .slave_alloc        = fc_slave_alloc,
2958     .change_queue_depth = scsi_change_queue_depth,
2959     .this_id        = -1,
2960     .cmd_per_lun        = 3,
2961     .sg_tablesize       = BNX2FC_MAX_BDS_PER_CMD,
2962     .dma_boundary           = 0x7fff,
2963     .max_sectors        = 0x3fbf,
2964     .track_queue_depth  = 1,
2965     .slave_configure    = bnx2fc_slave_configure,
2966     .shost_groups       = bnx2fc_host_groups,
2967     .cmd_size       = sizeof(struct bnx2fc_priv),
2968 };
2969 
2970 static struct libfc_function_template bnx2fc_libfc_fcn_templ = {
2971     .frame_send     = bnx2fc_xmit,
2972     .elsct_send     = bnx2fc_elsct_send,
2973     .fcp_abort_io       = bnx2fc_abort_io,
2974     .fcp_cleanup        = bnx2fc_cleanup,
2975     .get_lesb       = fcoe_get_lesb,
2976     .rport_event_callback   = bnx2fc_rport_event_handler,
2977 };
2978 
2979 /*
2980  * bnx2fc_cnic_cb - global template of bnx2fc - cnic driver interface
2981  *          structure carrying callback function pointers
2982  */
2983 static struct cnic_ulp_ops bnx2fc_cnic_cb = {
2984     .owner          = THIS_MODULE,
2985     .cnic_init      = bnx2fc_ulp_init,
2986     .cnic_exit      = bnx2fc_ulp_exit,
2987     .cnic_start     = bnx2fc_ulp_start,
2988     .cnic_stop      = bnx2fc_ulp_stop,
2989     .indicate_kcqes     = bnx2fc_indicate_kcqe,
2990     .indicate_netevent  = bnx2fc_indicate_netevent,
2991     .cnic_get_stats     = bnx2fc_ulp_get_stats,
2992 };