1 /* bnx2fc_fcoe.c: QLogic Linux FCoE offload driver.
2 * This file contains the code that interacts with libfc, libfcoe,
3 * cnic modules to create FCoE instances, send/receive non-offloaded
4 * FIP/FCoE packets, listen to link events etc.
6 * Copyright (c) 2008-2013 Broadcom Corporation
7 * Copyright (c) 2014-2016 QLogic Corporation
8 * Copyright (c) 2016-2017 Cavium Inc.
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation.
14 * Written by: Bhanu Prakash Gollapudi (bprakash@broadcom.com)
19 static struct list_head adapter_list;
20 static struct list_head if_list;
21 static u32 adapter_count;
22 static DEFINE_MUTEX(bnx2fc_dev_lock);
23 DEFINE_PER_CPU(struct bnx2fc_percpu_s, bnx2fc_percpu);
25 #define DRV_MODULE_NAME "bnx2fc"
26 #define DRV_MODULE_VERSION BNX2FC_VERSION
27 #define DRV_MODULE_RELDATE "October 15, 2015"
30 static char version[] =
31 "QLogic FCoE Driver " DRV_MODULE_NAME \
32 " v" DRV_MODULE_VERSION " (" DRV_MODULE_RELDATE ")\n";
35 MODULE_AUTHOR("Bhanu Prakash Gollapudi <bprakash@broadcom.com>");
36 MODULE_DESCRIPTION("QLogic FCoE Driver");
37 MODULE_LICENSE("GPL");
38 MODULE_VERSION(DRV_MODULE_VERSION);
40 #define BNX2FC_MAX_QUEUE_DEPTH 256
41 #define BNX2FC_MIN_QUEUE_DEPTH 32
42 #define FCOE_WORD_TO_BYTE 4
44 static struct scsi_transport_template *bnx2fc_transport_template;
45 static struct scsi_transport_template *bnx2fc_vport_xport_template;
47 struct workqueue_struct *bnx2fc_wq;
49 /* bnx2fc structure needs only one instance of the fcoe_percpu_s structure.
50 * Here the io threads are per cpu but the l2 thread is just one
52 struct fcoe_percpu_s bnx2fc_global;
53 static DEFINE_SPINLOCK(bnx2fc_global_lock);
55 static struct cnic_ulp_ops bnx2fc_cnic_cb;
56 static struct libfc_function_template bnx2fc_libfc_fcn_templ;
57 static struct scsi_host_template bnx2fc_shost_template;
58 static struct fc_function_template bnx2fc_transport_function;
59 static struct fcoe_sysfs_function_template bnx2fc_fcoe_sysfs_templ;
60 static struct fc_function_template bnx2fc_vport_xport_function;
61 static int bnx2fc_create(struct net_device *netdev, enum fip_mode fip_mode);
62 static void __bnx2fc_destroy(struct bnx2fc_interface *interface);
63 static int bnx2fc_destroy(struct net_device *net_device);
64 static int bnx2fc_enable(struct net_device *netdev);
65 static int bnx2fc_disable(struct net_device *netdev);
67 /* fcoe_syfs control interface handlers */
68 static int bnx2fc_ctlr_alloc(struct net_device *netdev);
69 static int bnx2fc_ctlr_enabled(struct fcoe_ctlr_device *cdev);
71 static void bnx2fc_recv_frame(struct sk_buff *skb);
73 static void bnx2fc_start_disc(struct bnx2fc_interface *interface);
74 static int bnx2fc_shost_config(struct fc_lport *lport, struct device *dev);
75 static int bnx2fc_lport_config(struct fc_lport *lport);
76 static int bnx2fc_em_config(struct fc_lport *lport, struct bnx2fc_hba *hba);
77 static int bnx2fc_bind_adapter_devices(struct bnx2fc_hba *hba);
78 static void bnx2fc_unbind_adapter_devices(struct bnx2fc_hba *hba);
79 static int bnx2fc_bind_pcidev(struct bnx2fc_hba *hba);
80 static void bnx2fc_unbind_pcidev(struct bnx2fc_hba *hba);
81 static struct fc_lport *bnx2fc_if_create(struct bnx2fc_interface *interface,
82 struct device *parent, int npiv);
83 static void bnx2fc_port_destroy(struct fcoe_port *port);
85 static struct bnx2fc_hba *bnx2fc_hba_lookup(struct net_device *phys_dev);
86 static struct bnx2fc_interface *bnx2fc_interface_lookup(struct net_device
88 static inline void bnx2fc_interface_put(struct bnx2fc_interface *interface);
89 static struct bnx2fc_hba *bnx2fc_find_hba_for_cnic(struct cnic_dev *cnic);
91 static int bnx2fc_fw_init(struct bnx2fc_hba *hba);
92 static void bnx2fc_fw_destroy(struct bnx2fc_hba *hba);
94 static void bnx2fc_port_shutdown(struct fc_lport *lport);
95 static void bnx2fc_stop(struct bnx2fc_interface *interface);
96 static int __init bnx2fc_mod_init(void);
97 static void __exit bnx2fc_mod_exit(void);
99 unsigned int bnx2fc_debug_level;
100 module_param_named(debug_logging, bnx2fc_debug_level, int, S_IRUGO|S_IWUSR);
101 MODULE_PARM_DESC(debug_logging,
102 "Option to enable extended logging,\n"
103 "\t\tDefault is 0 - no logging.\n"
104 "\t\t0x01 - SCSI cmd error, cleanup.\n"
105 "\t\t0x02 - Session setup, cleanup, etc.\n"
106 "\t\t0x04 - lport events, link, mtu, etc.\n"
107 "\t\t0x08 - ELS logs.\n"
108 "\t\t0x10 - fcoe L2 fame related logs.\n"
109 "\t\t0xff - LOG all messages.");
111 static uint bnx2fc_devloss_tmo;
112 module_param_named(devloss_tmo, bnx2fc_devloss_tmo, uint, S_IRUGO);
113 MODULE_PARM_DESC(devloss_tmo, " Change devloss_tmo for the remote ports "
114 "attached via bnx2fc.");
116 static uint bnx2fc_max_luns = BNX2FC_MAX_LUN;
117 module_param_named(max_luns, bnx2fc_max_luns, uint, S_IRUGO);
118 MODULE_PARM_DESC(max_luns, " Change the default max_lun per SCSI host. Default "
121 static uint bnx2fc_queue_depth;
122 module_param_named(queue_depth, bnx2fc_queue_depth, uint, S_IRUGO);
123 MODULE_PARM_DESC(queue_depth, " Change the default queue depth of SCSI devices "
124 "attached via bnx2fc.");
126 static uint bnx2fc_log_fka;
127 module_param_named(log_fka, bnx2fc_log_fka, uint, S_IRUGO|S_IWUSR);
128 MODULE_PARM_DESC(log_fka, " Print message to kernel log when fcoe is "
129 "initiating a FIP keep alive when debug logging is enabled.");
131 static inline struct net_device *bnx2fc_netdev(const struct fc_lport *lport)
133 return ((struct bnx2fc_interface *)
134 ((struct fcoe_port *)lport_priv(lport))->priv)->netdev;
137 static void bnx2fc_fcf_get_vlan_id(struct fcoe_fcf_device *fcf_dev)
139 struct fcoe_ctlr_device *ctlr_dev =
140 fcoe_fcf_dev_to_ctlr_dev(fcf_dev);
141 struct fcoe_ctlr *ctlr = fcoe_ctlr_device_priv(ctlr_dev);
142 struct bnx2fc_interface *fcoe = fcoe_ctlr_priv(ctlr);
144 fcf_dev->vlan_id = fcoe->vlan_id;
147 static void bnx2fc_clean_rx_queue(struct fc_lport *lp)
149 struct fcoe_percpu_s *bg;
150 struct fcoe_rcv_info *fr;
151 struct sk_buff_head *list;
152 struct sk_buff *skb, *next;
155 spin_lock_bh(&bg->fcoe_rx_list.lock);
156 list = &bg->fcoe_rx_list;
157 skb_queue_walk_safe(list, skb, next) {
158 fr = fcoe_dev_from_skb(skb);
159 if (fr->fr_dev == lp) {
160 __skb_unlink(skb, list);
164 spin_unlock_bh(&bg->fcoe_rx_list.lock);
167 int bnx2fc_get_paged_crc_eof(struct sk_buff *skb, int tlen)
170 spin_lock(&bnx2fc_global_lock);
171 rc = fcoe_get_paged_crc_eof(skb, tlen, &bnx2fc_global);
172 spin_unlock(&bnx2fc_global_lock);
177 static void bnx2fc_abort_io(struct fc_lport *lport)
180 * This function is no-op for bnx2fc, but we do
181 * not want to leave it as NULL either, as libfc
182 * can call the default function which is
187 static void bnx2fc_cleanup(struct fc_lport *lport)
189 struct fcoe_port *port = lport_priv(lport);
190 struct bnx2fc_interface *interface = port->priv;
191 struct bnx2fc_hba *hba = interface->hba;
192 struct bnx2fc_rport *tgt;
195 BNX2FC_MISC_DBG("Entered %s\n", __func__);
196 mutex_lock(&hba->hba_mutex);
197 spin_lock_bh(&hba->hba_lock);
198 for (i = 0; i < BNX2FC_NUM_MAX_SESS; i++) {
199 tgt = hba->tgt_ofld_list[i];
201 /* Cleanup IOs belonging to requested vport */
202 if (tgt->port == port) {
203 spin_unlock_bh(&hba->hba_lock);
204 BNX2FC_TGT_DBG(tgt, "flush/cleanup\n");
205 bnx2fc_flush_active_ios(tgt);
206 spin_lock_bh(&hba->hba_lock);
210 spin_unlock_bh(&hba->hba_lock);
211 mutex_unlock(&hba->hba_mutex);
214 static int bnx2fc_xmit_l2_frame(struct bnx2fc_rport *tgt,
217 struct fc_rport_priv *rdata = tgt->rdata;
218 struct fc_frame_header *fh;
221 fh = fc_frame_header_get(fp);
222 BNX2FC_TGT_DBG(tgt, "Xmit L2 frame rport = 0x%x, oxid = 0x%x, "
223 "r_ctl = 0x%x\n", rdata->ids.port_id,
224 ntohs(fh->fh_ox_id), fh->fh_r_ctl);
225 if ((fh->fh_type == FC_TYPE_ELS) &&
226 (fh->fh_r_ctl == FC_RCTL_ELS_REQ)) {
228 switch (fc_frame_payload_op(fp)) {
230 rc = bnx2fc_send_adisc(tgt, fp);
233 rc = bnx2fc_send_logo(tgt, fp);
236 rc = bnx2fc_send_rls(tgt, fp);
241 } else if ((fh->fh_type == FC_TYPE_BLS) &&
242 (fh->fh_r_ctl == FC_RCTL_BA_ABTS))
243 BNX2FC_TGT_DBG(tgt, "ABTS frame\n");
245 BNX2FC_TGT_DBG(tgt, "Send L2 frame type 0x%x "
246 "rctl 0x%x thru non-offload path\n",
247 fh->fh_type, fh->fh_r_ctl);
257 * bnx2fc_xmit - bnx2fc's FCoE frame transmit function
259 * @lport: the associated local port
260 * @fp: the fc_frame to be transmitted
262 static int bnx2fc_xmit(struct fc_lport *lport, struct fc_frame *fp)
265 struct fcoe_crc_eof *cp;
267 struct fc_frame_header *fh;
268 struct bnx2fc_interface *interface;
269 struct fcoe_ctlr *ctlr;
270 struct bnx2fc_hba *hba;
271 struct fcoe_port *port;
273 struct bnx2fc_rport *tgt;
274 struct fc_stats *stats;
277 unsigned int hlen, tlen, elen;
280 port = (struct fcoe_port *)lport_priv(lport);
281 interface = port->priv;
282 ctlr = bnx2fc_to_ctlr(interface);
283 hba = interface->hba;
285 fh = fc_frame_header_get(fp);
288 if (!lport->link_up) {
289 BNX2FC_HBA_DBG(lport, "bnx2fc_xmit link down\n");
294 if (unlikely(fh->fh_r_ctl == FC_RCTL_ELS_REQ)) {
295 if (!ctlr->sel_fcf) {
296 BNX2FC_HBA_DBG(lport, "FCF not selected yet!\n");
300 if (fcoe_ctlr_els_send(ctlr, lport, skb))
308 * Snoop the frame header to check if the frame is for
309 * an offloaded session
312 * tgt_ofld_list access is synchronized using
313 * both hba mutex and hba lock. Atleast hba mutex or
314 * hba lock needs to be held for read access.
317 spin_lock_bh(&hba->hba_lock);
318 tgt = bnx2fc_tgt_lookup(port, ntoh24(fh->fh_d_id));
319 if (tgt && (test_bit(BNX2FC_FLAG_SESSION_READY, &tgt->flags))) {
320 /* This frame is for offloaded session */
321 BNX2FC_HBA_DBG(lport, "xmit: Frame is for offloaded session "
322 "port_id = 0x%x\n", ntoh24(fh->fh_d_id));
323 spin_unlock_bh(&hba->hba_lock);
324 rc = bnx2fc_xmit_l2_frame(tgt, fp);
330 spin_unlock_bh(&hba->hba_lock);
333 elen = sizeof(struct ethhdr);
334 hlen = sizeof(struct fcoe_hdr);
335 tlen = sizeof(struct fcoe_crc_eof);
336 wlen = (skb->len - tlen + sizeof(crc)) / FCOE_WORD_TO_BYTE;
338 skb->ip_summed = CHECKSUM_NONE;
339 crc = fcoe_fc_crc(fp);
341 /* copy port crc and eof to the skb buff */
342 if (skb_is_nonlinear(skb)) {
344 if (bnx2fc_get_paged_crc_eof(skb, tlen)) {
348 frag = &skb_shinfo(skb)->frags[skb_shinfo(skb)->nr_frags - 1];
349 cp = kmap_atomic(skb_frag_page(frag)) + skb_frag_off(frag);
351 cp = skb_put(skb, tlen);
354 memset(cp, 0, sizeof(*cp));
356 cp->fcoe_crc32 = cpu_to_le32(~crc);
357 if (skb_is_nonlinear(skb)) {
362 /* adjust skb network/transport offsets to match mac/fcoe/port */
363 skb_push(skb, elen + hlen);
364 skb_reset_mac_header(skb);
365 skb_reset_network_header(skb);
367 skb->protocol = htons(ETH_P_FCOE);
368 skb->dev = interface->netdev;
370 /* fill up mac and fcoe headers */
372 eh->h_proto = htons(ETH_P_FCOE);
374 fc_fcoe_set_mac(eh->h_dest, fh->fh_d_id);
376 /* insert GW address */
377 memcpy(eh->h_dest, ctlr->dest_addr, ETH_ALEN);
379 if (unlikely(ctlr->flogi_oxid != FC_XID_UNKNOWN))
380 memcpy(eh->h_source, ctlr->ctl_src_addr, ETH_ALEN);
382 memcpy(eh->h_source, port->data_src_addr, ETH_ALEN);
384 hp = (struct fcoe_hdr *)(eh + 1);
385 memset(hp, 0, sizeof(*hp));
387 FC_FCOE_ENCAPS_VER(hp, FC_FCOE_VER);
390 /* fcoe lso, mss is in max_payload which is non-zero for FCP data */
391 if (lport->seq_offload && fr_max_payload(fp)) {
392 skb_shinfo(skb)->gso_type = SKB_GSO_FCOE;
393 skb_shinfo(skb)->gso_size = fr_max_payload(fp);
395 skb_shinfo(skb)->gso_type = 0;
396 skb_shinfo(skb)->gso_size = 0;
400 stats = per_cpu_ptr(lport->stats, get_cpu());
402 stats->TxWords += wlen;
405 /* send down to lld */
407 if (port->fcoe_pending_queue.qlen)
408 fcoe_check_wait_queue(lport, skb);
409 else if (fcoe_start_io(skb))
410 fcoe_check_wait_queue(lport, skb);
416 * bnx2fc_rcv - This is bnx2fc's receive function called by NET_RX_SOFTIRQ
418 * @skb: the receive socket buffer
419 * @dev: associated net device
421 * @olddev: last device
423 * This function receives the packet and builds FC frame and passes it up
425 static int bnx2fc_rcv(struct sk_buff *skb, struct net_device *dev,
426 struct packet_type *ptype, struct net_device *olddev)
428 struct fc_lport *lport;
429 struct bnx2fc_interface *interface;
430 struct fcoe_ctlr *ctlr;
431 struct fcoe_rcv_info *fr;
432 struct fcoe_percpu_s *bg;
434 interface = container_of(ptype, struct bnx2fc_interface,
436 ctlr = bnx2fc_to_ctlr(interface);
439 if (unlikely(lport == NULL)) {
440 printk(KERN_ERR PFX "bnx2fc_rcv: lport is NULL\n");
444 skb = skb_share_check(skb, GFP_ATOMIC);
448 if (unlikely(eth_hdr(skb)->h_proto != htons(ETH_P_FCOE))) {
449 printk(KERN_ERR PFX "bnx2fc_rcv: Wrong FC type frame\n");
454 * Check for minimum frame length, and make sure required FCoE
455 * and FC headers are pulled into the linear data area.
457 if (unlikely((skb->len < FCOE_MIN_FRAME) ||
458 !pskb_may_pull(skb, FCOE_HEADER_LEN)))
461 skb_set_transport_header(skb, sizeof(struct fcoe_hdr));
463 fr = fcoe_dev_from_skb(skb);
467 spin_lock(&bg->fcoe_rx_list.lock);
469 __skb_queue_tail(&bg->fcoe_rx_list, skb);
470 if (bg->fcoe_rx_list.qlen == 1)
471 wake_up_process(bg->kthread);
473 spin_unlock(&bg->fcoe_rx_list.lock);
481 static int bnx2fc_l2_rcv_thread(void *arg)
483 struct fcoe_percpu_s *bg = arg;
486 set_user_nice(current, MIN_NICE);
487 set_current_state(TASK_INTERRUPTIBLE);
488 while (!kthread_should_stop()) {
490 spin_lock_bh(&bg->fcoe_rx_list.lock);
491 while ((skb = __skb_dequeue(&bg->fcoe_rx_list)) != NULL) {
492 spin_unlock_bh(&bg->fcoe_rx_list.lock);
493 bnx2fc_recv_frame(skb);
494 spin_lock_bh(&bg->fcoe_rx_list.lock);
496 __set_current_state(TASK_INTERRUPTIBLE);
497 spin_unlock_bh(&bg->fcoe_rx_list.lock);
499 __set_current_state(TASK_RUNNING);
504 static void bnx2fc_recv_frame(struct sk_buff *skb)
508 struct fc_lport *lport;
509 struct fcoe_rcv_info *fr;
510 struct fc_stats *stats;
511 struct fc_frame_header *fh;
512 struct fcoe_crc_eof crc_eof;
514 struct fc_lport *vn_port;
515 struct fcoe_port *port, *phys_port;
519 struct bnx2fc_interface *interface;
520 struct fcoe_ctlr *ctlr;
522 fr = fcoe_dev_from_skb(skb);
524 if (unlikely(lport == NULL)) {
525 printk(KERN_ERR PFX "Invalid lport struct\n");
530 if (skb_is_nonlinear(skb))
532 mac = eth_hdr(skb)->h_source;
533 dest_mac = eth_hdr(skb)->h_dest;
535 /* Pull the header */
536 hp = (struct fcoe_hdr *) skb_network_header(skb);
537 fh = (struct fc_frame_header *) skb_transport_header(skb);
538 skb_pull(skb, sizeof(struct fcoe_hdr));
539 fr_len = skb->len - sizeof(struct fcoe_crc_eof);
541 stats = per_cpu_ptr(lport->stats, get_cpu());
543 stats->RxWords += fr_len / FCOE_WORD_TO_BYTE;
546 fp = (struct fc_frame *)skb;
549 fr_sof(fp) = hp->fcoe_sof;
550 if (skb_copy_bits(skb, fr_len, &crc_eof, sizeof(crc_eof))) {
554 fr_eof(fp) = crc_eof.fcoe_eof;
555 fr_crc(fp) = crc_eof.fcoe_crc32;
556 if (pskb_trim(skb, fr_len)) {
561 phys_port = lport_priv(lport);
562 interface = phys_port->priv;
563 ctlr = bnx2fc_to_ctlr(interface);
565 fh = fc_frame_header_get(fp);
567 if (ntoh24(&dest_mac[3]) != ntoh24(fh->fh_d_id)) {
568 BNX2FC_HBA_DBG(lport, "FC frame d_id mismatch with MAC %pM.\n",
574 vn_port = fc_vport_id_lookup(lport, ntoh24(fh->fh_d_id));
576 port = lport_priv(vn_port);
577 if (!ether_addr_equal(port->data_src_addr, dest_mac)) {
578 BNX2FC_HBA_DBG(lport, "fpma mismatch\n");
584 if (!ether_addr_equal(mac, ctlr->dest_addr)) {
585 BNX2FC_HBA_DBG(lport, "Wrong source address: mac:%pM dest_addr:%pM.\n",
586 mac, ctlr->dest_addr);
591 if (fh->fh_r_ctl == FC_RCTL_DD_SOL_DATA &&
592 fh->fh_type == FC_TYPE_FCP) {
593 /* Drop FCP data. We dont this in L2 path */
597 if (fh->fh_r_ctl == FC_RCTL_ELS_REQ &&
598 fh->fh_type == FC_TYPE_ELS) {
599 switch (fc_frame_payload_op(fp)) {
601 if (ntoh24(fh->fh_s_id) == FC_FID_FLOGI) {
602 /* drop non-FIP LOGO */
610 if (fh->fh_r_ctl == FC_RCTL_BA_ABTS) {
611 /* Drop incoming ABTS */
617 * If the destination ID from the frame header does not match what we
618 * have on record for lport and the search for a NPIV port came up
619 * empty then this is not addressed to our port so simply drop it.
621 if (lport->port_id != ntoh24(fh->fh_d_id) && !vn_port) {
622 BNX2FC_HBA_DBG(lport, "Dropping frame due to destination mismatch: lport->port_id=%x fh->d_id=%x.\n",
623 lport->port_id, ntoh24(fh->fh_d_id));
628 fr_crc = le32_to_cpu(fr_crc(fp));
630 if (unlikely(fr_crc != ~crc32(~0, skb->data, fr_len))) {
631 stats = per_cpu_ptr(lport->stats, get_cpu());
632 crc_err = (stats->InvalidCRCCount++);
635 printk(KERN_WARNING PFX "dropping frame with "
640 fc_exch_recv(lport, fp);
644 * bnx2fc_percpu_io_thread - thread per cpu for ios
646 * @arg: ptr to bnx2fc_percpu_info structure
648 static int bnx2fc_percpu_io_thread(void *arg)
650 struct bnx2fc_percpu_s *p = arg;
651 struct bnx2fc_work *work, *tmp;
652 LIST_HEAD(work_list);
654 set_user_nice(current, MIN_NICE);
655 set_current_state(TASK_INTERRUPTIBLE);
656 while (!kthread_should_stop()) {
658 spin_lock_bh(&p->fp_work_lock);
659 while (!list_empty(&p->work_list)) {
660 list_splice_init(&p->work_list, &work_list);
661 spin_unlock_bh(&p->fp_work_lock);
663 list_for_each_entry_safe(work, tmp, &work_list, list) {
664 list_del_init(&work->list);
665 bnx2fc_process_cq_compl(work->tgt, work->wqe,
672 spin_lock_bh(&p->fp_work_lock);
674 __set_current_state(TASK_INTERRUPTIBLE);
675 spin_unlock_bh(&p->fp_work_lock);
677 __set_current_state(TASK_RUNNING);
682 static struct fc_host_statistics *bnx2fc_get_host_stats(struct Scsi_Host *shost)
684 struct fc_host_statistics *bnx2fc_stats;
685 struct fc_lport *lport = shost_priv(shost);
686 struct fcoe_port *port = lport_priv(lport);
687 struct bnx2fc_interface *interface = port->priv;
688 struct bnx2fc_hba *hba = interface->hba;
689 struct fcoe_statistics_params *fw_stats;
692 fw_stats = (struct fcoe_statistics_params *)hba->stats_buffer;
696 mutex_lock(&hba->hba_stats_mutex);
698 bnx2fc_stats = fc_get_host_stats(shost);
700 init_completion(&hba->stat_req_done);
701 if (bnx2fc_send_stat_req(hba))
702 goto unlock_stats_mutex;
703 rc = wait_for_completion_timeout(&hba->stat_req_done, (2 * HZ));
705 BNX2FC_HBA_DBG(lport, "FW stat req timed out\n");
706 goto unlock_stats_mutex;
708 BNX2FC_STATS(hba, rx_stat2, fc_crc_cnt);
709 bnx2fc_stats->invalid_crc_count += hba->bfw_stats.fc_crc_cnt;
710 BNX2FC_STATS(hba, tx_stat, fcoe_tx_pkt_cnt);
711 bnx2fc_stats->tx_frames += hba->bfw_stats.fcoe_tx_pkt_cnt;
712 BNX2FC_STATS(hba, tx_stat, fcoe_tx_byte_cnt);
713 bnx2fc_stats->tx_words += ((hba->bfw_stats.fcoe_tx_byte_cnt) / 4);
714 BNX2FC_STATS(hba, rx_stat0, fcoe_rx_pkt_cnt);
715 bnx2fc_stats->rx_frames += hba->bfw_stats.fcoe_rx_pkt_cnt;
716 BNX2FC_STATS(hba, rx_stat0, fcoe_rx_byte_cnt);
717 bnx2fc_stats->rx_words += ((hba->bfw_stats.fcoe_rx_byte_cnt) / 4);
719 bnx2fc_stats->dumped_frames = 0;
720 bnx2fc_stats->lip_count = 0;
721 bnx2fc_stats->nos_count = 0;
722 bnx2fc_stats->loss_of_sync_count = 0;
723 bnx2fc_stats->loss_of_signal_count = 0;
724 bnx2fc_stats->prim_seq_protocol_err_count = 0;
726 memcpy(&hba->prev_stats, hba->stats_buffer,
727 sizeof(struct fcoe_statistics_params));
730 mutex_unlock(&hba->hba_stats_mutex);
734 static int bnx2fc_shost_config(struct fc_lport *lport, struct device *dev)
736 struct fcoe_port *port = lport_priv(lport);
737 struct bnx2fc_interface *interface = port->priv;
738 struct bnx2fc_hba *hba = interface->hba;
739 struct Scsi_Host *shost = lport->host;
742 shost->max_cmd_len = BNX2FC_MAX_CMD_LEN;
743 shost->max_lun = bnx2fc_max_luns;
744 shost->max_id = BNX2FC_MAX_FCP_TGT;
745 shost->max_channel = 0;
747 shost->transportt = bnx2fc_vport_xport_template;
749 shost->transportt = bnx2fc_transport_template;
751 /* Add the new host to SCSI-ml */
752 rc = scsi_add_host(lport->host, dev);
754 printk(KERN_ERR PFX "Error on scsi_add_host\n");
758 fc_host_max_npiv_vports(lport->host) = USHRT_MAX;
759 snprintf(fc_host_symbolic_name(lport->host), 256,
760 "%s (QLogic %s) v%s over %s",
761 BNX2FC_NAME, hba->chip_num, BNX2FC_VERSION,
762 interface->netdev->name);
767 static int bnx2fc_link_ok(struct fc_lport *lport)
769 struct fcoe_port *port = lport_priv(lport);
770 struct bnx2fc_interface *interface = port->priv;
771 struct bnx2fc_hba *hba = interface->hba;
772 struct net_device *dev = hba->phys_dev;
775 if ((dev->flags & IFF_UP) && netif_carrier_ok(dev))
776 clear_bit(ADAPTER_STATE_LINK_DOWN, &hba->adapter_state);
778 set_bit(ADAPTER_STATE_LINK_DOWN, &hba->adapter_state);
785 * bnx2fc_get_link_state - get network link state
787 * @hba: adapter instance pointer
789 * updates adapter structure flag based on netdev state
791 void bnx2fc_get_link_state(struct bnx2fc_hba *hba)
793 if (test_bit(__LINK_STATE_NOCARRIER, &hba->phys_dev->state))
794 set_bit(ADAPTER_STATE_LINK_DOWN, &hba->adapter_state);
796 clear_bit(ADAPTER_STATE_LINK_DOWN, &hba->adapter_state);
799 static int bnx2fc_net_config(struct fc_lport *lport, struct net_device *netdev)
801 struct bnx2fc_hba *hba;
802 struct bnx2fc_interface *interface;
803 struct fcoe_ctlr *ctlr;
804 struct fcoe_port *port;
807 port = lport_priv(lport);
808 interface = port->priv;
809 ctlr = bnx2fc_to_ctlr(interface);
810 hba = interface->hba;
812 /* require support for get_pauseparam ethtool op. */
813 if (!hba->phys_dev->ethtool_ops ||
814 !hba->phys_dev->ethtool_ops->get_pauseparam)
817 if (fc_set_mfs(lport, BNX2FC_MFS))
820 skb_queue_head_init(&port->fcoe_pending_queue);
821 port->fcoe_pending_queue_active = 0;
822 timer_setup(&port->timer, fcoe_queue_timer, 0);
824 fcoe_link_speed_update(lport);
827 if (fcoe_get_wwn(netdev, &wwnn, NETDEV_FCOE_WWNN))
828 wwnn = fcoe_wwn_from_mac(ctlr->ctl_src_addr,
830 BNX2FC_HBA_DBG(lport, "WWNN = 0x%llx\n", wwnn);
831 fc_set_wwnn(lport, wwnn);
833 if (fcoe_get_wwn(netdev, &wwpn, NETDEV_FCOE_WWPN))
834 wwpn = fcoe_wwn_from_mac(ctlr->ctl_src_addr,
837 BNX2FC_HBA_DBG(lport, "WWPN = 0x%llx\n", wwpn);
838 fc_set_wwpn(lport, wwpn);
844 static void bnx2fc_destroy_timer(struct timer_list *t)
846 struct bnx2fc_hba *hba = from_timer(hba, t, destroy_timer);
848 printk(KERN_ERR PFX "ERROR:bnx2fc_destroy_timer - "
849 "Destroy compl not received!!\n");
850 set_bit(BNX2FC_FLAG_DESTROY_CMPL, &hba->flags);
851 wake_up_interruptible(&hba->destroy_wait);
855 * bnx2fc_indicate_netevent - Generic netdev event handler
857 * @context: adapter structure pointer
859 * @vlan_id: vlan id - associated vlan id with this event
861 * Handles NETDEV_UP, NETDEV_DOWN, NETDEV_GOING_DOWN,NETDEV_CHANGE and
862 * NETDEV_CHANGE_MTU events. Handle NETDEV_UNREGISTER only for vlans.
864 static void bnx2fc_indicate_netevent(void *context, unsigned long event,
867 struct bnx2fc_hba *hba = (struct bnx2fc_hba *)context;
868 struct fcoe_ctlr_device *cdev;
869 struct fc_lport *lport;
870 struct fc_lport *vport;
871 struct bnx2fc_interface *interface, *tmp;
872 struct fcoe_ctlr *ctlr;
873 int wait_for_upload = 0;
874 u32 link_possible = 1;
876 if (vlan_id != 0 && event != NETDEV_UNREGISTER)
881 if (!test_bit(ADAPTER_STATE_UP, &hba->adapter_state))
882 printk(KERN_ERR "indicate_netevent: "\
883 "hba is not UP!!\n");
887 clear_bit(ADAPTER_STATE_GOING_DOWN, &hba->adapter_state);
888 clear_bit(ADAPTER_STATE_UP, &hba->adapter_state);
892 case NETDEV_GOING_DOWN:
893 set_bit(ADAPTER_STATE_GOING_DOWN, &hba->adapter_state);
900 case NETDEV_UNREGISTER:
903 mutex_lock(&bnx2fc_dev_lock);
904 list_for_each_entry_safe(interface, tmp, &if_list, list) {
905 if (interface->hba == hba &&
906 interface->vlan_id == (vlan_id & VLAN_VID_MASK))
907 __bnx2fc_destroy(interface);
909 mutex_unlock(&bnx2fc_dev_lock);
916 mutex_lock(&bnx2fc_dev_lock);
917 list_for_each_entry(interface, &if_list, list) {
919 if (interface->hba != hba)
922 ctlr = bnx2fc_to_ctlr(interface);
924 BNX2FC_HBA_DBG(lport, "netevent handler - event=%s %ld\n",
925 interface->netdev->name, event);
927 fcoe_link_speed_update(lport);
929 cdev = fcoe_ctlr_to_ctlr_dev(ctlr);
931 if (link_possible && !bnx2fc_link_ok(lport)) {
932 switch (cdev->enabled) {
933 case FCOE_CTLR_DISABLED:
934 pr_info("Link up while interface is disabled.\n");
936 case FCOE_CTLR_ENABLED:
937 case FCOE_CTLR_UNUSED:
938 /* Reset max recv frame size to default */
939 fc_set_mfs(lport, BNX2FC_MFS);
941 * ctlr link up will only be handled during
942 * enable to avoid sending discovery
943 * solicitation on a stale vlan
945 if (interface->enabled)
946 fcoe_ctlr_link_up(ctlr);
948 } else if (fcoe_ctlr_link_down(ctlr)) {
949 switch (cdev->enabled) {
950 case FCOE_CTLR_DISABLED:
951 pr_info("Link down while interface is disabled.\n");
953 case FCOE_CTLR_ENABLED:
954 case FCOE_CTLR_UNUSED:
955 mutex_lock(&lport->lp_mutex);
956 list_for_each_entry(vport, &lport->vports, list)
957 fc_host_port_type(vport->host) =
959 mutex_unlock(&lport->lp_mutex);
960 fc_host_port_type(lport->host) =
962 per_cpu_ptr(lport->stats,
963 get_cpu())->LinkFailureCount++;
965 fcoe_clean_pending_queue(lport);
970 mutex_unlock(&bnx2fc_dev_lock);
972 if (wait_for_upload) {
973 clear_bit(ADAPTER_STATE_READY, &hba->adapter_state);
974 init_waitqueue_head(&hba->shutdown_wait);
975 BNX2FC_MISC_DBG("indicate_netevent "
976 "num_ofld_sess = %d\n",
978 hba->wait_for_link_down = 1;
979 wait_event_interruptible(hba->shutdown_wait,
980 (hba->num_ofld_sess == 0));
981 BNX2FC_MISC_DBG("wakeup - num_ofld_sess = %d\n",
983 hba->wait_for_link_down = 0;
985 if (signal_pending(current))
986 flush_signals(current);
990 static int bnx2fc_libfc_config(struct fc_lport *lport)
993 /* Set the function pointers set by bnx2fc driver */
994 memcpy(&lport->tt, &bnx2fc_libfc_fcn_templ,
995 sizeof(struct libfc_function_template));
996 fc_elsct_init(lport);
999 fc_disc_config(lport, lport);
1003 static int bnx2fc_em_config(struct fc_lport *lport, struct bnx2fc_hba *hba)
1005 int fcoe_min_xid, fcoe_max_xid;
1007 fcoe_min_xid = hba->max_xid + 1;
1008 if (nr_cpu_ids <= 2)
1009 fcoe_max_xid = hba->max_xid + FCOE_XIDS_PER_CPU_OFFSET;
1011 fcoe_max_xid = hba->max_xid + FCOE_MAX_XID_OFFSET;
1012 if (!fc_exch_mgr_alloc(lport, FC_CLASS_3, fcoe_min_xid,
1013 fcoe_max_xid, NULL)) {
1014 printk(KERN_ERR PFX "em_config:fc_exch_mgr_alloc failed\n");
1021 static int bnx2fc_lport_config(struct fc_lport *lport)
1025 lport->max_retry_count = BNX2FC_MAX_RETRY_CNT;
1026 lport->max_rport_retry_count = BNX2FC_MAX_RPORT_RETRY_CNT;
1027 lport->e_d_tov = 2 * 1000;
1028 lport->r_a_tov = 10 * 1000;
1030 lport->service_params = (FCP_SPPF_INIT_FCN | FCP_SPPF_RD_XRDY_DIS |
1031 FCP_SPPF_RETRY | FCP_SPPF_CONF_COMPL);
1032 lport->does_npiv = 1;
1034 memset(&lport->rnid_gen, 0, sizeof(struct fc_els_rnid_gen));
1035 lport->rnid_gen.rnid_atype = BNX2FC_RNID_HBA;
1037 /* alloc stats structure */
1038 if (fc_lport_init_stats(lport))
1041 /* Finish fc_lport configuration */
1042 fc_lport_config(lport);
1048 * bnx2fc_fip_recv - handle a received FIP frame.
1050 * @skb: the received skb
1051 * @dev: associated &net_device
1052 * @ptype: the &packet_type structure which was used to register this handler.
1053 * @orig_dev: original receive &net_device, in case @ dev is a bond.
1055 * Returns: 0 for success
1057 static int bnx2fc_fip_recv(struct sk_buff *skb, struct net_device *dev,
1058 struct packet_type *ptype,
1059 struct net_device *orig_dev)
1061 struct bnx2fc_interface *interface;
1062 struct fcoe_ctlr *ctlr;
1063 interface = container_of(ptype, struct bnx2fc_interface,
1065 ctlr = bnx2fc_to_ctlr(interface);
1066 fcoe_ctlr_recv(ctlr, skb);
1071 * bnx2fc_update_src_mac - Update Ethernet MAC filters.
1073 * @lport: The local port
1074 * @addr: Location of data to copy
1076 * Remove any previously-set unicast MAC filter.
1077 * Add secondary FCoE MAC address filter for our OUI.
1079 static void bnx2fc_update_src_mac(struct fc_lport *lport, u8 *addr)
1081 struct fcoe_port *port = lport_priv(lport);
1083 memcpy(port->data_src_addr, addr, ETH_ALEN);
1087 * bnx2fc_get_src_mac - return the ethernet source address for an lport
1089 * @lport: libfc port
1091 static u8 *bnx2fc_get_src_mac(struct fc_lport *lport)
1093 struct fcoe_port *port;
1095 port = (struct fcoe_port *)lport_priv(lport);
1096 return port->data_src_addr;
1100 * bnx2fc_fip_send - send an Ethernet-encapsulated FIP frame.
1102 * @fip: FCoE controller.
1105 static void bnx2fc_fip_send(struct fcoe_ctlr *fip, struct sk_buff *skb)
1107 struct fip_header *fiph;
1108 struct ethhdr *eth_hdr;
1112 fiph = (struct fip_header *) ((void *)skb->data + 2 * ETH_ALEN + 2);
1113 eth_hdr = (struct ethhdr *)skb_mac_header(skb);
1114 op = ntohs(fiph->fip_op);
1115 sub = fiph->fip_subcode;
1117 if (op == FIP_OP_CTRL && sub == FIP_SC_SOL && bnx2fc_log_fka)
1118 BNX2FC_MISC_DBG("Sending FKA from %pM to %pM.\n",
1119 eth_hdr->h_source, eth_hdr->h_dest);
1121 skb->dev = bnx2fc_from_ctlr(fip)->netdev;
1122 dev_queue_xmit(skb);
1125 static int bnx2fc_vport_create(struct fc_vport *vport, bool disabled)
1127 struct Scsi_Host *shost = vport_to_shost(vport);
1128 struct fc_lport *n_port = shost_priv(shost);
1129 struct fcoe_port *port = lport_priv(n_port);
1130 struct bnx2fc_interface *interface = port->priv;
1131 struct net_device *netdev = interface->netdev;
1132 struct fc_lport *vn_port;
1136 rc = fcoe_validate_vport_create(vport);
1138 fcoe_wwn_to_str(vport->port_name, buf, sizeof(buf));
1139 printk(KERN_ERR PFX "Failed to create vport, "
1140 "WWPN (0x%s) already exists\n",
1145 if (!test_bit(BNX2FC_FLAG_FW_INIT_DONE, &interface->hba->flags)) {
1146 printk(KERN_ERR PFX "vn ports cannot be created on"
1147 "this interface\n");
1151 mutex_lock(&bnx2fc_dev_lock);
1152 vn_port = bnx2fc_if_create(interface, &vport->dev, 1);
1153 mutex_unlock(&bnx2fc_dev_lock);
1157 printk(KERN_ERR PFX "bnx2fc_vport_create (%s) failed\n",
1162 if (bnx2fc_devloss_tmo)
1163 fc_host_dev_loss_tmo(vn_port->host) = bnx2fc_devloss_tmo;
1166 fc_vport_set_state(vport, FC_VPORT_DISABLED);
1168 vn_port->boot_time = jiffies;
1169 fc_lport_init(vn_port);
1170 fc_fabric_login(vn_port);
1171 fc_vport_setlink(vn_port);
1176 static void bnx2fc_free_vport(struct bnx2fc_hba *hba, struct fc_lport *lport)
1178 struct bnx2fc_lport *blport, *tmp;
1180 spin_lock_bh(&hba->hba_lock);
1181 list_for_each_entry_safe(blport, tmp, &hba->vports, list) {
1182 if (blport->lport == lport) {
1183 list_del(&blport->list);
1187 spin_unlock_bh(&hba->hba_lock);
1190 static int bnx2fc_vport_destroy(struct fc_vport *vport)
1192 struct Scsi_Host *shost = vport_to_shost(vport);
1193 struct fc_lport *n_port = shost_priv(shost);
1194 struct fc_lport *vn_port = vport->dd_data;
1195 struct fcoe_port *port = lport_priv(vn_port);
1196 struct bnx2fc_interface *interface = port->priv;
1197 struct fc_lport *v_port;
1200 mutex_lock(&n_port->lp_mutex);
1201 list_for_each_entry(v_port, &n_port->vports, list)
1202 if (v_port->vport == vport) {
1208 mutex_unlock(&n_port->lp_mutex);
1211 list_del(&vn_port->list);
1212 mutex_unlock(&n_port->lp_mutex);
1213 bnx2fc_free_vport(interface->hba, port->lport);
1214 bnx2fc_port_shutdown(port->lport);
1215 bnx2fc_port_destroy(port);
1216 bnx2fc_interface_put(interface);
1220 static int bnx2fc_vport_disable(struct fc_vport *vport, bool disable)
1222 struct fc_lport *lport = vport->dd_data;
1225 fc_vport_set_state(vport, FC_VPORT_DISABLED);
1226 fc_fabric_logoff(lport);
1228 lport->boot_time = jiffies;
1229 fc_fabric_login(lport);
1230 fc_vport_setlink(lport);
1236 static int bnx2fc_interface_setup(struct bnx2fc_interface *interface)
1238 struct net_device *netdev = interface->netdev;
1239 struct net_device *physdev = interface->hba->phys_dev;
1240 struct fcoe_ctlr *ctlr = bnx2fc_to_ctlr(interface);
1241 struct netdev_hw_addr *ha;
1242 int sel_san_mac = 0;
1244 /* setup Source MAC Address */
1246 for_each_dev_addr(physdev, ha) {
1247 BNX2FC_MISC_DBG("net_config: ha->type = %d, fip_mac = ",
1249 printk(KERN_INFO "%2x:%2x:%2x:%2x:%2x:%2x\n", ha->addr[0],
1250 ha->addr[1], ha->addr[2], ha->addr[3],
1251 ha->addr[4], ha->addr[5]);
1253 if ((ha->type == NETDEV_HW_ADDR_T_SAN) &&
1254 (is_valid_ether_addr(ha->addr))) {
1255 memcpy(ctlr->ctl_src_addr, ha->addr,
1258 BNX2FC_MISC_DBG("Found SAN MAC\n");
1266 interface->fip_packet_type.func = bnx2fc_fip_recv;
1267 interface->fip_packet_type.type = htons(ETH_P_FIP);
1268 interface->fip_packet_type.dev = netdev;
1269 dev_add_pack(&interface->fip_packet_type);
1271 interface->fcoe_packet_type.func = bnx2fc_rcv;
1272 interface->fcoe_packet_type.type = __constant_htons(ETH_P_FCOE);
1273 interface->fcoe_packet_type.dev = netdev;
1274 dev_add_pack(&interface->fcoe_packet_type);
1279 static int bnx2fc_attach_transport(void)
1281 bnx2fc_transport_template =
1282 fc_attach_transport(&bnx2fc_transport_function);
1284 if (bnx2fc_transport_template == NULL) {
1285 printk(KERN_ERR PFX "Failed to attach FC transport\n");
1289 bnx2fc_vport_xport_template =
1290 fc_attach_transport(&bnx2fc_vport_xport_function);
1291 if (bnx2fc_vport_xport_template == NULL) {
1293 "Failed to attach FC transport for vport\n");
1294 fc_release_transport(bnx2fc_transport_template);
1295 bnx2fc_transport_template = NULL;
1300 static void bnx2fc_release_transport(void)
1302 fc_release_transport(bnx2fc_transport_template);
1303 fc_release_transport(bnx2fc_vport_xport_template);
1304 bnx2fc_transport_template = NULL;
1305 bnx2fc_vport_xport_template = NULL;
1308 static void bnx2fc_interface_release(struct kref *kref)
1310 struct fcoe_ctlr_device *ctlr_dev;
1311 struct bnx2fc_interface *interface;
1312 struct fcoe_ctlr *ctlr;
1313 struct net_device *netdev;
1315 interface = container_of(kref, struct bnx2fc_interface, kref);
1316 BNX2FC_MISC_DBG("Interface is being released\n");
1318 ctlr = bnx2fc_to_ctlr(interface);
1319 ctlr_dev = fcoe_ctlr_to_ctlr_dev(ctlr);
1320 netdev = interface->netdev;
1322 /* tear-down FIP controller */
1323 if (test_and_clear_bit(BNX2FC_CTLR_INIT_DONE, &interface->if_flags))
1324 fcoe_ctlr_destroy(ctlr);
1326 fcoe_ctlr_device_delete(ctlr_dev);
1329 module_put(THIS_MODULE);
1332 static inline void bnx2fc_interface_get(struct bnx2fc_interface *interface)
1334 kref_get(&interface->kref);
1337 static inline void bnx2fc_interface_put(struct bnx2fc_interface *interface)
1339 kref_put(&interface->kref, bnx2fc_interface_release);
1341 static void bnx2fc_hba_destroy(struct bnx2fc_hba *hba)
1343 /* Free the command manager */
1345 bnx2fc_cmd_mgr_free(hba->cmd_mgr);
1346 hba->cmd_mgr = NULL;
1348 kfree(hba->tgt_ofld_list);
1349 bnx2fc_unbind_pcidev(hba);
1354 * bnx2fc_hba_create - create a new bnx2fc hba
1356 * @cnic: pointer to cnic device
1358 * Creates a new FCoE hba on the given device.
1361 static struct bnx2fc_hba *bnx2fc_hba_create(struct cnic_dev *cnic)
1363 struct bnx2fc_hba *hba;
1364 struct fcoe_capabilities *fcoe_cap;
1367 hba = kzalloc(sizeof(*hba), GFP_KERNEL);
1369 printk(KERN_ERR PFX "Unable to allocate hba structure\n");
1372 spin_lock_init(&hba->hba_lock);
1373 mutex_init(&hba->hba_mutex);
1374 mutex_init(&hba->hba_stats_mutex);
1378 hba->max_tasks = cnic->max_fcoe_exchanges;
1379 hba->elstm_xids = (hba->max_tasks / 2);
1380 hba->max_outstanding_cmds = hba->elstm_xids;
1381 hba->max_xid = (hba->max_tasks - 1);
1383 rc = bnx2fc_bind_pcidev(hba);
1385 printk(KERN_ERR PFX "create_adapter: bind error\n");
1388 hba->phys_dev = cnic->netdev;
1389 hba->next_conn_id = 0;
1391 hba->tgt_ofld_list =
1392 kcalloc(BNX2FC_NUM_MAX_SESS, sizeof(struct bnx2fc_rport *),
1394 if (!hba->tgt_ofld_list) {
1395 printk(KERN_ERR PFX "Unable to allocate tgt offload list\n");
1399 hba->num_ofld_sess = 0;
1401 hba->cmd_mgr = bnx2fc_cmd_mgr_alloc(hba);
1402 if (!hba->cmd_mgr) {
1403 printk(KERN_ERR PFX "em_config:bnx2fc_cmd_mgr_alloc failed\n");
1406 fcoe_cap = &hba->fcoe_cap;
1408 fcoe_cap->capability1 = BNX2FC_TM_MAX_SQES <<
1409 FCOE_IOS_PER_CONNECTION_SHIFT;
1410 fcoe_cap->capability1 |= BNX2FC_NUM_MAX_SESS <<
1411 FCOE_LOGINS_PER_PORT_SHIFT;
1412 fcoe_cap->capability2 = hba->max_outstanding_cmds <<
1413 FCOE_NUMBER_OF_EXCHANGES_SHIFT;
1414 fcoe_cap->capability2 |= BNX2FC_MAX_NPIV <<
1415 FCOE_NPIV_WWN_PER_PORT_SHIFT;
1416 fcoe_cap->capability3 = BNX2FC_NUM_MAX_SESS <<
1417 FCOE_TARGETS_SUPPORTED_SHIFT;
1418 fcoe_cap->capability3 |= hba->max_outstanding_cmds <<
1419 FCOE_OUTSTANDING_COMMANDS_SHIFT;
1420 fcoe_cap->capability4 = FCOE_CAPABILITY4_STATEFUL;
1422 init_waitqueue_head(&hba->shutdown_wait);
1423 init_waitqueue_head(&hba->destroy_wait);
1424 INIT_LIST_HEAD(&hba->vports);
1429 kfree(hba->tgt_ofld_list);
1431 bnx2fc_unbind_pcidev(hba);
1437 static struct bnx2fc_interface *
1438 bnx2fc_interface_create(struct bnx2fc_hba *hba,
1439 struct net_device *netdev,
1440 enum fip_mode fip_mode)
1442 struct fcoe_ctlr_device *ctlr_dev;
1443 struct bnx2fc_interface *interface;
1444 struct fcoe_ctlr *ctlr;
1448 size = (sizeof(*interface) + sizeof(struct fcoe_ctlr));
1449 ctlr_dev = fcoe_ctlr_device_add(&netdev->dev, &bnx2fc_fcoe_sysfs_templ,
1452 printk(KERN_ERR PFX "Unable to allocate interface structure\n");
1455 ctlr = fcoe_ctlr_device_priv(ctlr_dev);
1456 ctlr->cdev = ctlr_dev;
1457 interface = fcoe_ctlr_priv(ctlr);
1459 kref_init(&interface->kref);
1460 interface->hba = hba;
1461 interface->netdev = netdev;
1463 /* Initialize FIP */
1464 fcoe_ctlr_init(ctlr, fip_mode);
1465 ctlr->send = bnx2fc_fip_send;
1466 ctlr->update_mac = bnx2fc_update_src_mac;
1467 ctlr->get_src_addr = bnx2fc_get_src_mac;
1468 set_bit(BNX2FC_CTLR_INIT_DONE, &interface->if_flags);
1470 rc = bnx2fc_interface_setup(interface);
1474 fcoe_ctlr_destroy(ctlr);
1476 fcoe_ctlr_device_delete(ctlr_dev);
1481 * bnx2fc_if_create - Create FCoE instance on a given interface
1483 * @interface: FCoE interface to create a local port on
1484 * @parent: Device pointer to be the parent in sysfs for the SCSI host
1485 * @npiv: Indicates if the port is vport or not
1487 * Creates a fc_lport instance and a Scsi_Host instance and configure them.
1489 * Returns: Allocated fc_lport or an error pointer
1491 static struct fc_lport *bnx2fc_if_create(struct bnx2fc_interface *interface,
1492 struct device *parent, int npiv)
1494 struct fcoe_ctlr *ctlr = bnx2fc_to_ctlr(interface);
1495 struct fc_lport *lport, *n_port;
1496 struct fcoe_port *port;
1497 struct Scsi_Host *shost;
1498 struct fc_vport *vport = dev_to_vport(parent);
1499 struct bnx2fc_lport *blport;
1500 struct bnx2fc_hba *hba = interface->hba;
1503 blport = kzalloc(sizeof(struct bnx2fc_lport), GFP_KERNEL);
1505 BNX2FC_HBA_DBG(ctlr->lp, "Unable to alloc blport\n");
1509 /* Allocate Scsi_Host structure */
1510 bnx2fc_shost_template.can_queue = hba->max_outstanding_cmds;
1512 lport = libfc_host_alloc(&bnx2fc_shost_template, sizeof(*port));
1514 lport = libfc_vport_create(vport, sizeof(*port));
1517 printk(KERN_ERR PFX "could not allocate scsi host structure\n");
1520 shost = lport->host;
1521 port = lport_priv(lport);
1522 port->lport = lport;
1523 port->priv = interface;
1524 port->get_netdev = bnx2fc_netdev;
1526 /* Configure fcoe_port */
1527 rc = bnx2fc_lport_config(lport);
1532 printk(KERN_ERR PFX "Setting vport names, 0x%llX 0x%llX\n",
1533 vport->node_name, vport->port_name);
1534 fc_set_wwnn(lport, vport->node_name);
1535 fc_set_wwpn(lport, vport->port_name);
1537 /* Configure netdev and networking properties of the lport */
1538 rc = bnx2fc_net_config(lport, interface->netdev);
1540 printk(KERN_ERR PFX "Error on bnx2fc_net_config\n");
1544 rc = bnx2fc_shost_config(lport, parent);
1546 printk(KERN_ERR PFX "Couldn't configure shost for %s\n",
1547 interface->netdev->name);
1551 /* Initialize the libfc library */
1552 rc = bnx2fc_libfc_config(lport);
1554 printk(KERN_ERR PFX "Couldn't configure libfc\n");
1557 fc_host_port_type(lport->host) = FC_PORTTYPE_UNKNOWN;
1559 if (bnx2fc_devloss_tmo)
1560 fc_host_dev_loss_tmo(shost) = bnx2fc_devloss_tmo;
1562 /* Allocate exchange manager */
1564 rc = bnx2fc_em_config(lport, hba);
1566 shost = vport_to_shost(vport);
1567 n_port = shost_priv(shost);
1568 rc = fc_exch_mgr_list_clone(n_port, lport);
1572 printk(KERN_ERR PFX "Error on bnx2fc_em_config\n");
1576 bnx2fc_interface_get(interface);
1578 spin_lock_bh(&hba->hba_lock);
1579 blport->lport = lport;
1580 list_add_tail(&blport->list, &hba->vports);
1581 spin_unlock_bh(&hba->hba_lock);
1586 scsi_remove_host(shost);
1588 scsi_host_put(lport->host);
1594 static void bnx2fc_net_cleanup(struct bnx2fc_interface *interface)
1596 /* Dont listen for Ethernet packets anymore */
1597 __dev_remove_pack(&interface->fcoe_packet_type);
1598 __dev_remove_pack(&interface->fip_packet_type);
1602 static void bnx2fc_interface_cleanup(struct bnx2fc_interface *interface)
1604 struct fcoe_ctlr *ctlr = bnx2fc_to_ctlr(interface);
1605 struct fc_lport *lport = ctlr->lp;
1606 struct fcoe_port *port = lport_priv(lport);
1607 struct bnx2fc_hba *hba = interface->hba;
1609 /* Stop the transmit retry timer */
1610 del_timer_sync(&port->timer);
1612 /* Free existing transmit skbs */
1613 fcoe_clean_pending_queue(lport);
1615 bnx2fc_net_cleanup(interface);
1617 bnx2fc_free_vport(hba, lport);
1620 static void bnx2fc_if_destroy(struct fc_lport *lport)
1623 /* Free queued packets for the receive thread */
1624 bnx2fc_clean_rx_queue(lport);
1626 /* Detach from scsi-ml */
1627 fc_remove_host(lport->host);
1628 scsi_remove_host(lport->host);
1631 * Note that only the physical lport will have the exchange manager.
1632 * for vports, this function is NOP
1634 fc_exch_mgr_free(lport);
1636 /* Free memory used by statistical counters */
1637 fc_lport_free_stats(lport);
1639 /* Release Scsi_Host */
1640 scsi_host_put(lport->host);
1643 static void __bnx2fc_destroy(struct bnx2fc_interface *interface)
1645 struct fcoe_ctlr *ctlr = bnx2fc_to_ctlr(interface);
1646 struct fc_lport *lport = ctlr->lp;
1647 struct fcoe_port *port = lport_priv(lport);
1649 bnx2fc_interface_cleanup(interface);
1650 bnx2fc_stop(interface);
1651 list_del(&interface->list);
1652 bnx2fc_port_destroy(port);
1653 bnx2fc_interface_put(interface);
1657 * bnx2fc_destroy - Destroy a bnx2fc FCoE interface
1659 * @netdev: The net device that the FCoE interface is on
1661 * Called from sysfs.
1663 * Returns: 0 for success
1665 static int bnx2fc_destroy(struct net_device *netdev)
1667 struct bnx2fc_interface *interface = NULL;
1668 struct workqueue_struct *timer_work_queue;
1669 struct fcoe_ctlr *ctlr;
1673 mutex_lock(&bnx2fc_dev_lock);
1675 interface = bnx2fc_interface_lookup(netdev);
1676 ctlr = bnx2fc_to_ctlr(interface);
1677 if (!interface || !ctlr->lp) {
1679 printk(KERN_ERR PFX "bnx2fc_destroy: interface or lport not found\n");
1683 timer_work_queue = interface->timer_work_queue;
1684 __bnx2fc_destroy(interface);
1685 destroy_workqueue(timer_work_queue);
1688 mutex_unlock(&bnx2fc_dev_lock);
1693 static void bnx2fc_port_destroy(struct fcoe_port *port)
1695 struct fc_lport *lport;
1697 lport = port->lport;
1698 BNX2FC_HBA_DBG(lport, "Entered %s, destroying lport %p\n", __func__, lport);
1700 bnx2fc_if_destroy(lport);
1703 static void bnx2fc_unbind_adapter_devices(struct bnx2fc_hba *hba)
1705 bnx2fc_free_fw_resc(hba);
1706 bnx2fc_free_task_ctx(hba);
1710 * bnx2fc_bind_adapter_devices - binds bnx2fc adapter with the associated
1713 * @hba: Adapter instance
1715 static int bnx2fc_bind_adapter_devices(struct bnx2fc_hba *hba)
1717 if (bnx2fc_setup_task_ctx(hba))
1720 if (bnx2fc_setup_fw_resc(hba))
1725 bnx2fc_unbind_adapter_devices(hba);
1729 static int bnx2fc_bind_pcidev(struct bnx2fc_hba *hba)
1731 struct cnic_dev *cnic;
1732 struct pci_dev *pdev;
1735 printk(KERN_ERR PFX "cnic is NULL\n");
1739 pdev = hba->pcidev = cnic->pcidev;
1743 switch (pdev->device) {
1744 case PCI_DEVICE_ID_NX2_57710:
1745 strncpy(hba->chip_num, "BCM57710", BCM_CHIP_LEN);
1747 case PCI_DEVICE_ID_NX2_57711:
1748 strncpy(hba->chip_num, "BCM57711", BCM_CHIP_LEN);
1750 case PCI_DEVICE_ID_NX2_57712:
1751 case PCI_DEVICE_ID_NX2_57712_MF:
1752 case PCI_DEVICE_ID_NX2_57712_VF:
1753 strncpy(hba->chip_num, "BCM57712", BCM_CHIP_LEN);
1755 case PCI_DEVICE_ID_NX2_57800:
1756 case PCI_DEVICE_ID_NX2_57800_MF:
1757 case PCI_DEVICE_ID_NX2_57800_VF:
1758 strncpy(hba->chip_num, "BCM57800", BCM_CHIP_LEN);
1760 case PCI_DEVICE_ID_NX2_57810:
1761 case PCI_DEVICE_ID_NX2_57810_MF:
1762 case PCI_DEVICE_ID_NX2_57810_VF:
1763 strncpy(hba->chip_num, "BCM57810", BCM_CHIP_LEN);
1765 case PCI_DEVICE_ID_NX2_57840:
1766 case PCI_DEVICE_ID_NX2_57840_MF:
1767 case PCI_DEVICE_ID_NX2_57840_VF:
1768 case PCI_DEVICE_ID_NX2_57840_2_20:
1769 case PCI_DEVICE_ID_NX2_57840_4_10:
1770 strncpy(hba->chip_num, "BCM57840", BCM_CHIP_LEN);
1773 pr_err(PFX "Unknown device id 0x%x\n", pdev->device);
1776 pci_dev_get(hba->pcidev);
1780 static void bnx2fc_unbind_pcidev(struct bnx2fc_hba *hba)
1783 hba->chip_num[0] = '\0';
1784 pci_dev_put(hba->pcidev);
1790 * bnx2fc_ulp_get_stats - cnic callback to populate FCoE stats
1792 * @handle: transport handle pointing to adapter struture
1794 static int bnx2fc_ulp_get_stats(void *handle)
1796 struct bnx2fc_hba *hba = handle;
1797 struct cnic_dev *cnic;
1798 struct fcoe_stats_info *stats_addr;
1804 stats_addr = &cnic->stats_addr->fcoe_stat;
1808 strncpy(stats_addr->version, BNX2FC_VERSION,
1809 sizeof(stats_addr->version));
1810 stats_addr->txq_size = BNX2FC_SQ_WQES_MAX;
1811 stats_addr->rxq_size = BNX2FC_CQ_WQES_MAX;
1818 * bnx2fc_ulp_start - cnic callback to initialize & start adapter instance
1820 * @handle: transport handle pointing to adapter structure
1822 * This function maps adapter structure to pcidev structure and initiates
1823 * firmware handshake to enable/initialize on-chip FCoE components.
1824 * This bnx2fc - cnic interface api callback is used after following
1825 * conditions are met -
1826 * a) underlying network interface is up (marked by event NETDEV_UP
1828 * b) bnx2fc adatper structure is registered.
1830 static void bnx2fc_ulp_start(void *handle)
1832 struct bnx2fc_hba *hba = handle;
1833 struct bnx2fc_interface *interface;
1834 struct fcoe_ctlr *ctlr;
1835 struct fc_lport *lport;
1837 mutex_lock(&bnx2fc_dev_lock);
1839 if (!test_bit(BNX2FC_FLAG_FW_INIT_DONE, &hba->flags))
1840 bnx2fc_fw_init(hba);
1842 BNX2FC_MISC_DBG("bnx2fc started.\n");
1844 list_for_each_entry(interface, &if_list, list) {
1845 if (interface->hba == hba) {
1846 ctlr = bnx2fc_to_ctlr(interface);
1848 /* Kick off Fabric discovery*/
1849 printk(KERN_ERR PFX "ulp_init: start discovery\n");
1850 lport->tt.frame_send = bnx2fc_xmit;
1851 bnx2fc_start_disc(interface);
1855 mutex_unlock(&bnx2fc_dev_lock);
1858 static void bnx2fc_port_shutdown(struct fc_lport *lport)
1860 BNX2FC_MISC_DBG("Entered %s\n", __func__);
1861 fc_fabric_logoff(lport);
1862 fc_lport_destroy(lport);
1865 static void bnx2fc_stop(struct bnx2fc_interface *interface)
1867 struct fcoe_ctlr *ctlr = bnx2fc_to_ctlr(interface);
1868 struct fc_lport *lport;
1869 struct fc_lport *vport;
1871 if (!test_bit(BNX2FC_FLAG_FW_INIT_DONE, &interface->hba->flags))
1875 bnx2fc_port_shutdown(lport);
1877 mutex_lock(&lport->lp_mutex);
1878 list_for_each_entry(vport, &lport->vports, list)
1879 fc_host_port_type(vport->host) =
1880 FC_PORTTYPE_UNKNOWN;
1881 mutex_unlock(&lport->lp_mutex);
1882 fc_host_port_type(lport->host) = FC_PORTTYPE_UNKNOWN;
1883 fcoe_ctlr_link_down(ctlr);
1884 fcoe_clean_pending_queue(lport);
1887 static int bnx2fc_fw_init(struct bnx2fc_hba *hba)
1889 #define BNX2FC_INIT_POLL_TIME (1000 / HZ)
1893 rc = bnx2fc_bind_adapter_devices(hba);
1895 printk(KERN_ALERT PFX
1896 "bnx2fc_bind_adapter_devices failed - rc = %d\n", rc);
1900 rc = bnx2fc_send_fw_fcoe_init_msg(hba);
1902 printk(KERN_ALERT PFX
1903 "bnx2fc_send_fw_fcoe_init_msg failed - rc = %d\n", rc);
1908 * Wait until the adapter init message is complete, and adapter
1911 while (!test_bit(ADAPTER_STATE_UP, &hba->adapter_state) && i--)
1912 msleep(BNX2FC_INIT_POLL_TIME);
1914 if (!test_bit(ADAPTER_STATE_UP, &hba->adapter_state)) {
1915 printk(KERN_ERR PFX "bnx2fc_start: %s failed to initialize. "
1917 hba->cnic->netdev->name);
1923 set_bit(BNX2FC_FLAG_FW_INIT_DONE, &hba->flags);
1927 bnx2fc_unbind_adapter_devices(hba);
1932 static void bnx2fc_fw_destroy(struct bnx2fc_hba *hba)
1934 if (test_and_clear_bit(BNX2FC_FLAG_FW_INIT_DONE, &hba->flags)) {
1935 if (bnx2fc_send_fw_fcoe_destroy_msg(hba) == 0) {
1936 timer_setup(&hba->destroy_timer, bnx2fc_destroy_timer,
1938 hba->destroy_timer.expires = BNX2FC_FW_TIMEOUT +
1940 add_timer(&hba->destroy_timer);
1941 wait_event_interruptible(hba->destroy_wait,
1942 test_bit(BNX2FC_FLAG_DESTROY_CMPL,
1944 clear_bit(BNX2FC_FLAG_DESTROY_CMPL, &hba->flags);
1945 /* This should never happen */
1946 if (signal_pending(current))
1947 flush_signals(current);
1949 del_timer_sync(&hba->destroy_timer);
1951 bnx2fc_unbind_adapter_devices(hba);
1956 * bnx2fc_ulp_stop - cnic callback to shutdown adapter instance
1958 * @handle: transport handle pointing to adapter structure
1960 * Driver checks if adapter is already in shutdown mode, if not start
1961 * the shutdown process.
1963 static void bnx2fc_ulp_stop(void *handle)
1965 struct bnx2fc_hba *hba = handle;
1966 struct bnx2fc_interface *interface;
1968 printk(KERN_ERR "ULP_STOP\n");
1970 mutex_lock(&bnx2fc_dev_lock);
1971 if (!test_bit(BNX2FC_FLAG_FW_INIT_DONE, &hba->flags))
1973 list_for_each_entry(interface, &if_list, list) {
1974 if (interface->hba == hba)
1975 bnx2fc_stop(interface);
1977 BUG_ON(hba->num_ofld_sess != 0);
1979 mutex_lock(&hba->hba_mutex);
1980 clear_bit(ADAPTER_STATE_UP, &hba->adapter_state);
1981 clear_bit(ADAPTER_STATE_GOING_DOWN,
1982 &hba->adapter_state);
1984 clear_bit(ADAPTER_STATE_READY, &hba->adapter_state);
1985 mutex_unlock(&hba->hba_mutex);
1987 bnx2fc_fw_destroy(hba);
1989 mutex_unlock(&bnx2fc_dev_lock);
1992 static void bnx2fc_start_disc(struct bnx2fc_interface *interface)
1994 struct fcoe_ctlr *ctlr = bnx2fc_to_ctlr(interface);
1995 struct fc_lport *lport;
1998 BNX2FC_MISC_DBG("Entered %s\n", __func__);
1999 /* Kick off FIP/FLOGI */
2000 if (!test_bit(BNX2FC_FLAG_FW_INIT_DONE, &interface->hba->flags)) {
2001 printk(KERN_ERR PFX "Init not done yet\n");
2006 BNX2FC_HBA_DBG(lport, "calling fc_fabric_login\n");
2008 if (!bnx2fc_link_ok(lport) && interface->enabled) {
2009 BNX2FC_HBA_DBG(lport, "ctlr_link_up\n");
2010 fcoe_ctlr_link_up(ctlr);
2011 fc_host_port_type(lport->host) = FC_PORTTYPE_NPORT;
2012 set_bit(ADAPTER_STATE_READY, &interface->hba->adapter_state);
2015 /* wait for the FCF to be selected before issuing FLOGI */
2016 while (!ctlr->sel_fcf) {
2018 /* give up after 3 secs */
2019 if (++wait_cnt > 12)
2023 /* Reset max receive frame size to default */
2024 if (fc_set_mfs(lport, BNX2FC_MFS))
2027 fc_lport_init(lport);
2028 fc_fabric_login(lport);
2033 * bnx2fc_ulp_init - Initialize an adapter instance
2035 * @dev : cnic device handle
2036 * Called from cnic_register_driver() context to initialize all
2037 * enumerated cnic devices. This routine allocates adapter structure
2038 * and other device specific resources.
2040 static void bnx2fc_ulp_init(struct cnic_dev *dev)
2042 struct bnx2fc_hba *hba;
2045 BNX2FC_MISC_DBG("Entered %s\n", __func__);
2046 /* bnx2fc works only when bnx2x is loaded */
2047 if (!test_bit(CNIC_F_BNX2X_CLASS, &dev->flags) ||
2048 (dev->max_fcoe_conn == 0)) {
2049 printk(KERN_ERR PFX "bnx2fc FCoE not supported on %s,"
2050 " flags: %lx fcoe_conn: %d\n",
2051 dev->netdev->name, dev->flags, dev->max_fcoe_conn);
2055 hba = bnx2fc_hba_create(dev);
2057 printk(KERN_ERR PFX "hba initialization failed\n");
2061 pr_info(PFX "FCoE initialized for %s.\n", dev->netdev->name);
2063 /* Add HBA to the adapter list */
2064 mutex_lock(&bnx2fc_dev_lock);
2065 list_add_tail(&hba->list, &adapter_list);
2067 mutex_unlock(&bnx2fc_dev_lock);
2069 dev->fcoe_cap = &hba->fcoe_cap;
2070 clear_bit(BNX2FC_CNIC_REGISTERED, &hba->reg_with_cnic);
2071 rc = dev->register_device(dev, CNIC_ULP_FCOE,
2074 printk(KERN_ERR PFX "register_device failed, rc = %d\n", rc);
2076 set_bit(BNX2FC_CNIC_REGISTERED, &hba->reg_with_cnic);
2079 /* Assumes rtnl_lock and the bnx2fc_dev_lock are already taken */
2080 static int __bnx2fc_disable(struct fcoe_ctlr *ctlr)
2082 struct bnx2fc_interface *interface = fcoe_ctlr_priv(ctlr);
2084 if (interface->enabled == true) {
2086 pr_err(PFX "__bnx2fc_disable: lport not found\n");
2089 interface->enabled = false;
2090 fcoe_ctlr_link_down(ctlr);
2091 fcoe_clean_pending_queue(ctlr->lp);
2098 * Deperecated: Use bnx2fc_enabled()
2100 static int bnx2fc_disable(struct net_device *netdev)
2102 struct bnx2fc_interface *interface;
2103 struct fcoe_ctlr *ctlr;
2107 mutex_lock(&bnx2fc_dev_lock);
2109 interface = bnx2fc_interface_lookup(netdev);
2110 ctlr = bnx2fc_to_ctlr(interface);
2114 pr_err(PFX "bnx2fc_disable: interface not found\n");
2116 rc = __bnx2fc_disable(ctlr);
2118 mutex_unlock(&bnx2fc_dev_lock);
2123 static uint bnx2fc_npiv_create_vports(struct fc_lport *lport,
2124 struct cnic_fc_npiv_tbl *npiv_tbl)
2126 struct fc_vport_identifiers vpid;
2127 uint i, created = 0;
2132 if (npiv_tbl->count > MAX_NPIV_ENTRIES) {
2133 BNX2FC_HBA_DBG(lport, "Exceeded count max of npiv table\n");
2137 /* Sanity check the first entry to make sure it's not 0 */
2138 if (wwn_to_u64(npiv_tbl->wwnn[0]) == 0 &&
2139 wwn_to_u64(npiv_tbl->wwpn[0]) == 0) {
2140 BNX2FC_HBA_DBG(lport, "First NPIV table entries invalid.\n");
2144 vpid.roles = FC_PORT_ROLE_FCP_INITIATOR;
2145 vpid.vport_type = FC_PORTTYPE_NPIV;
2146 vpid.disable = false;
2148 for (i = 0; i < npiv_tbl->count; i++) {
2149 wwnn = wwn_to_u64(npiv_tbl->wwnn[i]);
2152 * If we get a 0 element from for the WWNN then assume
2153 * the WWNN should be the same as the physical port.
2157 vpid.node_name = wwnn;
2158 vpid.port_name = wwn_to_u64(npiv_tbl->wwpn[i]);
2159 scnprintf(vpid.symbolic_name, sizeof(vpid.symbolic_name),
2160 "NPIV[%u]:%016llx-%016llx",
2161 created, vpid.port_name, vpid.node_name);
2162 fcoe_wwn_to_str(vpid.node_name, wwnn_str, sizeof(wwnn_str));
2163 fcoe_wwn_to_str(vpid.port_name, wwpn_str, sizeof(wwpn_str));
2164 BNX2FC_HBA_DBG(lport, "Creating vport %s:%s.\n", wwnn_str,
2166 if (fc_vport_create(lport->host, 0, &vpid))
2169 BNX2FC_HBA_DBG(lport, "Failed to create vport\n");
2175 static int __bnx2fc_enable(struct fcoe_ctlr *ctlr)
2177 struct bnx2fc_interface *interface = fcoe_ctlr_priv(ctlr);
2178 struct bnx2fc_hba *hba;
2179 struct cnic_fc_npiv_tbl *npiv_tbl;
2180 struct fc_lport *lport;
2182 if (interface->enabled == false) {
2184 pr_err(PFX "__bnx2fc_enable: lport not found\n");
2186 } else if (!bnx2fc_link_ok(ctlr->lp)) {
2187 fcoe_ctlr_link_up(ctlr);
2188 interface->enabled = true;
2192 /* Create static NPIV ports if any are contained in NVRAM */
2193 hba = interface->hba;
2208 if (!hba->cnic->get_fc_npiv_tbl)
2211 npiv_tbl = kzalloc(sizeof(struct cnic_fc_npiv_tbl), GFP_KERNEL);
2215 if (hba->cnic->get_fc_npiv_tbl(hba->cnic, npiv_tbl))
2218 bnx2fc_npiv_create_vports(lport, npiv_tbl);
2226 * Deprecated: Use bnx2fc_enabled()
2228 static int bnx2fc_enable(struct net_device *netdev)
2230 struct bnx2fc_interface *interface;
2231 struct fcoe_ctlr *ctlr;
2235 mutex_lock(&bnx2fc_dev_lock);
2237 interface = bnx2fc_interface_lookup(netdev);
2238 ctlr = bnx2fc_to_ctlr(interface);
2241 pr_err(PFX "bnx2fc_enable: interface not found\n");
2243 rc = __bnx2fc_enable(ctlr);
2246 mutex_unlock(&bnx2fc_dev_lock);
2252 * bnx2fc_ctlr_enabled() - Enable or disable an FCoE Controller
2253 * @cdev: The FCoE Controller that is being enabled or disabled
2255 * fcoe_sysfs will ensure that the state of 'enabled' has
2256 * changed, so no checking is necessary here. This routine simply
2257 * calls fcoe_enable or fcoe_disable, both of which are deprecated.
2258 * When those routines are removed the functionality can be merged
2261 static int bnx2fc_ctlr_enabled(struct fcoe_ctlr_device *cdev)
2263 struct fcoe_ctlr *ctlr = fcoe_ctlr_device_priv(cdev);
2265 switch (cdev->enabled) {
2266 case FCOE_CTLR_ENABLED:
2267 return __bnx2fc_enable(ctlr);
2268 case FCOE_CTLR_DISABLED:
2269 return __bnx2fc_disable(ctlr);
2270 case FCOE_CTLR_UNUSED:
2276 enum bnx2fc_create_link_state {
2277 BNX2FC_CREATE_LINK_DOWN,
2278 BNX2FC_CREATE_LINK_UP,
2282 * _bnx2fc_create() - Create bnx2fc FCoE interface
2283 * @netdev : The net_device object the Ethernet interface to create on
2284 * @fip_mode: The FIP mode for this creation
2285 * @link_state: The ctlr link state on creation
2287 * Called from either the libfcoe 'create' module parameter
2288 * via fcoe_create or from fcoe_syfs's ctlr_create file.
2290 * libfcoe's 'create' module parameter is deprecated so some
2291 * consolidation of code can be done when that interface is
2294 * Returns: 0 for success
2296 static int _bnx2fc_create(struct net_device *netdev,
2297 enum fip_mode fip_mode,
2298 enum bnx2fc_create_link_state link_state)
2300 struct fcoe_ctlr_device *cdev;
2301 struct fcoe_ctlr *ctlr;
2302 struct bnx2fc_interface *interface;
2303 struct bnx2fc_hba *hba;
2304 struct net_device *phys_dev = netdev;
2305 struct fc_lport *lport;
2306 struct ethtool_drvinfo drvinfo;
2310 BNX2FC_MISC_DBG("Entered bnx2fc_create\n");
2311 if (fip_mode != FIP_MODE_FABRIC) {
2312 printk(KERN_ERR "fip mode not FABRIC\n");
2318 mutex_lock(&bnx2fc_dev_lock);
2320 if (!try_module_get(THIS_MODULE)) {
2325 /* obtain physical netdev */
2326 if (is_vlan_dev(netdev))
2327 phys_dev = vlan_dev_real_dev(netdev);
2329 /* verify if the physical device is a netxtreme2 device */
2330 if (phys_dev->ethtool_ops && phys_dev->ethtool_ops->get_drvinfo) {
2331 memset(&drvinfo, 0, sizeof(drvinfo));
2332 phys_dev->ethtool_ops->get_drvinfo(phys_dev, &drvinfo);
2333 if (strncmp(drvinfo.driver, "bnx2x", strlen("bnx2x"))) {
2334 printk(KERN_ERR PFX "Not a netxtreme2 device\n");
2339 printk(KERN_ERR PFX "unable to obtain drv_info\n");
2344 /* obtain interface and initialize rest of the structure */
2345 hba = bnx2fc_hba_lookup(phys_dev);
2348 printk(KERN_ERR PFX "bnx2fc_create: hba not found\n");
2352 if (bnx2fc_interface_lookup(netdev)) {
2357 interface = bnx2fc_interface_create(hba, netdev, fip_mode);
2359 printk(KERN_ERR PFX "bnx2fc_interface_create failed\n");
2364 if (is_vlan_dev(netdev)) {
2365 vlan_id = vlan_dev_vlan_id(netdev);
2366 interface->vlan_enabled = 1;
2369 ctlr = bnx2fc_to_ctlr(interface);
2370 cdev = fcoe_ctlr_to_ctlr_dev(ctlr);
2371 interface->vlan_id = vlan_id;
2372 interface->tm_timeout = BNX2FC_TM_TIMEOUT;
2374 interface->timer_work_queue =
2375 create_singlethread_workqueue("bnx2fc_timer_wq");
2376 if (!interface->timer_work_queue) {
2377 printk(KERN_ERR PFX "ulp_init could not create timer_wq\n");
2382 lport = bnx2fc_if_create(interface, &cdev->dev, 0);
2384 printk(KERN_ERR PFX "Failed to create interface (%s)\n",
2390 /* Add interface to if_list */
2391 list_add_tail(&interface->list, &if_list);
2393 lport->boot_time = jiffies;
2395 /* Make this master N_port */
2398 if (link_state == BNX2FC_CREATE_LINK_UP)
2399 cdev->enabled = FCOE_CTLR_ENABLED;
2401 cdev->enabled = FCOE_CTLR_DISABLED;
2403 if (link_state == BNX2FC_CREATE_LINK_UP &&
2404 !bnx2fc_link_ok(lport)) {
2405 fcoe_ctlr_link_up(ctlr);
2406 fc_host_port_type(lport->host) = FC_PORTTYPE_NPORT;
2407 set_bit(ADAPTER_STATE_READY, &interface->hba->adapter_state);
2410 BNX2FC_HBA_DBG(lport, "create: START DISC\n");
2411 bnx2fc_start_disc(interface);
2413 if (link_state == BNX2FC_CREATE_LINK_UP)
2414 interface->enabled = true;
2417 * Release from kref_init in bnx2fc_interface_setup, on success
2418 * lport should be holding a reference taken in bnx2fc_if_create
2420 bnx2fc_interface_put(interface);
2421 /* put netdev that was held while calling dev_get_by_name */
2422 mutex_unlock(&bnx2fc_dev_lock);
2427 destroy_workqueue(interface->timer_work_queue);
2429 bnx2fc_net_cleanup(interface);
2430 bnx2fc_interface_put(interface);
2433 module_put(THIS_MODULE);
2435 mutex_unlock(&bnx2fc_dev_lock);
2441 * bnx2fc_create() - Create a bnx2fc interface
2442 * @netdev : The net_device object the Ethernet interface to create on
2443 * @fip_mode: The FIP mode for this creation
2445 * Called from fcoe transport
2447 * Returns: 0 for success
2449 static int bnx2fc_create(struct net_device *netdev, enum fip_mode fip_mode)
2451 return _bnx2fc_create(netdev, fip_mode, BNX2FC_CREATE_LINK_UP);
2455 * bnx2fc_ctlr_alloc() - Allocate a bnx2fc interface from fcoe_sysfs
2456 * @netdev: The net_device to be used by the allocated FCoE Controller
2458 * This routine is called from fcoe_sysfs. It will start the fcoe_ctlr
2459 * in a link_down state. The allows the user an opportunity to configure
2460 * the FCoE Controller from sysfs before enabling the FCoE Controller.
2462 * Creating in with this routine starts the FCoE Controller in Fabric
2463 * mode. The user can change to VN2VN or another mode before enabling.
2465 static int bnx2fc_ctlr_alloc(struct net_device *netdev)
2467 return _bnx2fc_create(netdev, FIP_MODE_FABRIC,
2468 BNX2FC_CREATE_LINK_DOWN);
2472 * bnx2fc_find_hba_for_cnic - maps cnic instance to bnx2fc hba instance
2474 * @cnic: Pointer to cnic device instance
2477 static struct bnx2fc_hba *bnx2fc_find_hba_for_cnic(struct cnic_dev *cnic)
2479 struct bnx2fc_hba *hba;
2481 /* Called with bnx2fc_dev_lock held */
2482 list_for_each_entry(hba, &adapter_list, list) {
2483 if (hba->cnic == cnic)
2489 static struct bnx2fc_interface *bnx2fc_interface_lookup(struct net_device
2492 struct bnx2fc_interface *interface;
2494 /* Called with bnx2fc_dev_lock held */
2495 list_for_each_entry(interface, &if_list, list) {
2496 if (interface->netdev == netdev)
2502 static struct bnx2fc_hba *bnx2fc_hba_lookup(struct net_device
2505 struct bnx2fc_hba *hba;
2507 /* Called with bnx2fc_dev_lock held */
2508 list_for_each_entry(hba, &adapter_list, list) {
2509 if (hba->phys_dev == phys_dev)
2512 printk(KERN_ERR PFX "adapter_lookup: hba NULL\n");
2517 * bnx2fc_ulp_exit - shuts down adapter instance and frees all resources
2519 * @dev: cnic device handle
2521 static void bnx2fc_ulp_exit(struct cnic_dev *dev)
2523 struct bnx2fc_hba *hba;
2524 struct bnx2fc_interface *interface, *tmp;
2526 BNX2FC_MISC_DBG("Entered bnx2fc_ulp_exit\n");
2528 if (!test_bit(CNIC_F_BNX2X_CLASS, &dev->flags)) {
2529 printk(KERN_ERR PFX "bnx2fc port check: %s, flags: %lx\n",
2530 dev->netdev->name, dev->flags);
2534 mutex_lock(&bnx2fc_dev_lock);
2535 hba = bnx2fc_find_hba_for_cnic(dev);
2537 printk(KERN_ERR PFX "bnx2fc_ulp_exit: hba not found, dev 0%p\n",
2539 mutex_unlock(&bnx2fc_dev_lock);
2543 list_del_init(&hba->list);
2546 list_for_each_entry_safe(interface, tmp, &if_list, list)
2547 /* destroy not called yet, move to quiesced list */
2548 if (interface->hba == hba)
2549 __bnx2fc_destroy(interface);
2550 mutex_unlock(&bnx2fc_dev_lock);
2552 bnx2fc_ulp_stop(hba);
2553 /* unregister cnic device */
2554 if (test_and_clear_bit(BNX2FC_CNIC_REGISTERED, &hba->reg_with_cnic))
2555 hba->cnic->unregister_device(hba->cnic, CNIC_ULP_FCOE);
2556 bnx2fc_hba_destroy(hba);
2559 static void bnx2fc_rport_terminate_io(struct fc_rport *rport)
2561 /* This is a no-op */
2565 * bnx2fc_fcoe_reset - Resets the fcoe
2567 * @shost: shost the reset is from
2571 static int bnx2fc_fcoe_reset(struct Scsi_Host *shost)
2573 struct fc_lport *lport = shost_priv(shost);
2574 fc_lport_reset(lport);
2579 static bool bnx2fc_match(struct net_device *netdev)
2581 struct net_device *phys_dev = netdev;
2583 mutex_lock(&bnx2fc_dev_lock);
2584 if (is_vlan_dev(netdev))
2585 phys_dev = vlan_dev_real_dev(netdev);
2587 if (bnx2fc_hba_lookup(phys_dev)) {
2588 mutex_unlock(&bnx2fc_dev_lock);
2592 mutex_unlock(&bnx2fc_dev_lock);
2597 static struct fcoe_transport bnx2fc_transport = {
2600 .list = LIST_HEAD_INIT(bnx2fc_transport.list),
2601 .alloc = bnx2fc_ctlr_alloc,
2602 .match = bnx2fc_match,
2603 .create = bnx2fc_create,
2604 .destroy = bnx2fc_destroy,
2605 .enable = bnx2fc_enable,
2606 .disable = bnx2fc_disable,
2610 * bnx2fc_cpu_online - Create a receive thread for an online CPU
2612 * @cpu: cpu index for the online cpu
2614 static int bnx2fc_cpu_online(unsigned int cpu)
2616 struct bnx2fc_percpu_s *p;
2617 struct task_struct *thread;
2619 p = &per_cpu(bnx2fc_percpu, cpu);
2621 thread = kthread_create_on_node(bnx2fc_percpu_io_thread,
2622 (void *)p, cpu_to_node(cpu),
2623 "bnx2fc_thread/%d", cpu);
2625 return PTR_ERR(thread);
2627 /* bind thread to the cpu */
2628 kthread_bind(thread, cpu);
2629 p->iothread = thread;
2630 wake_up_process(thread);
2634 static int bnx2fc_cpu_offline(unsigned int cpu)
2636 struct bnx2fc_percpu_s *p;
2637 struct task_struct *thread;
2638 struct bnx2fc_work *work, *tmp;
2640 BNX2FC_MISC_DBG("destroying io thread for CPU %d\n", cpu);
2642 /* Prevent any new work from being queued for this CPU */
2643 p = &per_cpu(bnx2fc_percpu, cpu);
2644 spin_lock_bh(&p->fp_work_lock);
2645 thread = p->iothread;
2648 /* Free all work in the list */
2649 list_for_each_entry_safe(work, tmp, &p->work_list, list) {
2650 list_del_init(&work->list);
2651 bnx2fc_process_cq_compl(work->tgt, work->wqe, work->rq_data,
2652 work->num_rq, work->task);
2656 spin_unlock_bh(&p->fp_work_lock);
2659 kthread_stop(thread);
2663 static int bnx2fc_slave_configure(struct scsi_device *sdev)
2665 if (!bnx2fc_queue_depth)
2668 scsi_change_queue_depth(sdev, bnx2fc_queue_depth);
2672 static enum cpuhp_state bnx2fc_online_state;
2675 * bnx2fc_mod_init - module init entry point
2677 * Initialize driver wide global data structures, and register
2680 static int __init bnx2fc_mod_init(void)
2682 struct fcoe_percpu_s *bg;
2683 struct task_struct *l2_thread;
2685 unsigned int cpu = 0;
2686 struct bnx2fc_percpu_s *p;
2688 printk(KERN_INFO PFX "%s", version);
2690 /* register as a fcoe transport */
2691 rc = fcoe_transport_attach(&bnx2fc_transport);
2693 printk(KERN_ERR "failed to register an fcoe transport, check "
2694 "if libfcoe is loaded\n");
2698 INIT_LIST_HEAD(&adapter_list);
2699 INIT_LIST_HEAD(&if_list);
2700 mutex_init(&bnx2fc_dev_lock);
2703 /* Attach FC transport template */
2704 rc = bnx2fc_attach_transport();
2708 bnx2fc_wq = alloc_workqueue("bnx2fc", 0, 0);
2714 bg = &bnx2fc_global;
2715 skb_queue_head_init(&bg->fcoe_rx_list);
2716 l2_thread = kthread_create(bnx2fc_l2_rcv_thread,
2718 "bnx2fc_l2_thread");
2719 if (IS_ERR(l2_thread)) {
2720 rc = PTR_ERR(l2_thread);
2723 wake_up_process(l2_thread);
2724 spin_lock_bh(&bg->fcoe_rx_list.lock);
2725 bg->kthread = l2_thread;
2726 spin_unlock_bh(&bg->fcoe_rx_list.lock);
2728 for_each_possible_cpu(cpu) {
2729 p = &per_cpu(bnx2fc_percpu, cpu);
2730 INIT_LIST_HEAD(&p->work_list);
2731 spin_lock_init(&p->fp_work_lock);
2734 rc = cpuhp_setup_state(CPUHP_AP_ONLINE_DYN, "scsi/bnx2fc:online",
2735 bnx2fc_cpu_online, bnx2fc_cpu_offline);
2738 bnx2fc_online_state = rc;
2740 cnic_register_driver(CNIC_ULP_FCOE, &bnx2fc_cnic_cb);
2744 kthread_stop(l2_thread);
2746 destroy_workqueue(bnx2fc_wq);
2748 bnx2fc_release_transport();
2750 fcoe_transport_detach(&bnx2fc_transport);
2755 static void __exit bnx2fc_mod_exit(void)
2757 LIST_HEAD(to_be_deleted);
2758 struct bnx2fc_hba *hba, *next;
2759 struct fcoe_percpu_s *bg;
2760 struct task_struct *l2_thread;
2761 struct sk_buff *skb;
2764 * NOTE: Since cnic calls register_driver routine rtnl_lock,
2765 * it will have higher precedence than bnx2fc_dev_lock.
2766 * unregister_device() cannot be called with bnx2fc_dev_lock
2769 mutex_lock(&bnx2fc_dev_lock);
2770 list_splice_init(&adapter_list, &to_be_deleted);
2772 mutex_unlock(&bnx2fc_dev_lock);
2774 /* Unregister with cnic */
2775 list_for_each_entry_safe(hba, next, &to_be_deleted, list) {
2776 list_del_init(&hba->list);
2777 printk(KERN_ERR PFX "MOD_EXIT:destroy hba = 0x%p\n",
2779 bnx2fc_ulp_stop(hba);
2780 /* unregister cnic device */
2781 if (test_and_clear_bit(BNX2FC_CNIC_REGISTERED,
2782 &hba->reg_with_cnic))
2783 hba->cnic->unregister_device(hba->cnic,
2785 bnx2fc_hba_destroy(hba);
2787 cnic_unregister_driver(CNIC_ULP_FCOE);
2789 /* Destroy global thread */
2790 bg = &bnx2fc_global;
2791 spin_lock_bh(&bg->fcoe_rx_list.lock);
2792 l2_thread = bg->kthread;
2794 while ((skb = __skb_dequeue(&bg->fcoe_rx_list)) != NULL)
2797 spin_unlock_bh(&bg->fcoe_rx_list.lock);
2800 kthread_stop(l2_thread);
2802 cpuhp_remove_state(bnx2fc_online_state);
2804 destroy_workqueue(bnx2fc_wq);
2806 * detach from scsi transport
2807 * must happen after all destroys are done
2809 bnx2fc_release_transport();
2811 /* detach from fcoe transport */
2812 fcoe_transport_detach(&bnx2fc_transport);
2815 module_init(bnx2fc_mod_init);
2816 module_exit(bnx2fc_mod_exit);
2818 static struct fcoe_sysfs_function_template bnx2fc_fcoe_sysfs_templ = {
2819 .set_fcoe_ctlr_enabled = bnx2fc_ctlr_enabled,
2820 .get_fcoe_ctlr_link_fail = fcoe_ctlr_get_lesb,
2821 .get_fcoe_ctlr_vlink_fail = fcoe_ctlr_get_lesb,
2822 .get_fcoe_ctlr_miss_fka = fcoe_ctlr_get_lesb,
2823 .get_fcoe_ctlr_symb_err = fcoe_ctlr_get_lesb,
2824 .get_fcoe_ctlr_err_block = fcoe_ctlr_get_lesb,
2825 .get_fcoe_ctlr_fcs_error = fcoe_ctlr_get_lesb,
2827 .get_fcoe_fcf_selected = fcoe_fcf_get_selected,
2828 .get_fcoe_fcf_vlan_id = bnx2fc_fcf_get_vlan_id,
2831 static struct fc_function_template bnx2fc_transport_function = {
2832 .show_host_node_name = 1,
2833 .show_host_port_name = 1,
2834 .show_host_supported_classes = 1,
2835 .show_host_supported_fc4s = 1,
2836 .show_host_active_fc4s = 1,
2837 .show_host_maxframe_size = 1,
2839 .show_host_port_id = 1,
2840 .show_host_supported_speeds = 1,
2841 .get_host_speed = fc_get_host_speed,
2842 .show_host_speed = 1,
2843 .show_host_port_type = 1,
2844 .get_host_port_state = fc_get_host_port_state,
2845 .show_host_port_state = 1,
2846 .show_host_symbolic_name = 1,
2848 .dd_fcrport_size = (sizeof(struct fc_rport_libfc_priv) +
2849 sizeof(struct bnx2fc_rport)),
2850 .show_rport_maxframe_size = 1,
2851 .show_rport_supported_classes = 1,
2853 .show_host_fabric_name = 1,
2854 .show_starget_node_name = 1,
2855 .show_starget_port_name = 1,
2856 .show_starget_port_id = 1,
2857 .set_rport_dev_loss_tmo = fc_set_rport_loss_tmo,
2858 .show_rport_dev_loss_tmo = 1,
2859 .get_fc_host_stats = bnx2fc_get_host_stats,
2861 .issue_fc_host_lip = bnx2fc_fcoe_reset,
2863 .terminate_rport_io = bnx2fc_rport_terminate_io,
2865 .vport_create = bnx2fc_vport_create,
2866 .vport_delete = bnx2fc_vport_destroy,
2867 .vport_disable = bnx2fc_vport_disable,
2868 .bsg_request = fc_lport_bsg_request,
2871 static struct fc_function_template bnx2fc_vport_xport_function = {
2872 .show_host_node_name = 1,
2873 .show_host_port_name = 1,
2874 .show_host_supported_classes = 1,
2875 .show_host_supported_fc4s = 1,
2876 .show_host_active_fc4s = 1,
2877 .show_host_maxframe_size = 1,
2879 .show_host_port_id = 1,
2880 .show_host_supported_speeds = 1,
2881 .get_host_speed = fc_get_host_speed,
2882 .show_host_speed = 1,
2883 .show_host_port_type = 1,
2884 .get_host_port_state = fc_get_host_port_state,
2885 .show_host_port_state = 1,
2886 .show_host_symbolic_name = 1,
2888 .dd_fcrport_size = (sizeof(struct fc_rport_libfc_priv) +
2889 sizeof(struct bnx2fc_rport)),
2890 .show_rport_maxframe_size = 1,
2891 .show_rport_supported_classes = 1,
2893 .show_host_fabric_name = 1,
2894 .show_starget_node_name = 1,
2895 .show_starget_port_name = 1,
2896 .show_starget_port_id = 1,
2897 .set_rport_dev_loss_tmo = fc_set_rport_loss_tmo,
2898 .show_rport_dev_loss_tmo = 1,
2899 .get_fc_host_stats = fc_get_host_stats,
2900 .issue_fc_host_lip = bnx2fc_fcoe_reset,
2901 .terminate_rport_io = fc_rport_terminate_io,
2902 .bsg_request = fc_lport_bsg_request,
2906 * Additional scsi_host attributes.
2909 bnx2fc_tm_timeout_show(struct device *dev, struct device_attribute *attr,
2912 struct Scsi_Host *shost = class_to_shost(dev);
2913 struct fc_lport *lport = shost_priv(shost);
2914 struct fcoe_port *port = lport_priv(lport);
2915 struct bnx2fc_interface *interface = port->priv;
2917 sprintf(buf, "%u\n", interface->tm_timeout);
2922 bnx2fc_tm_timeout_store(struct device *dev,
2923 struct device_attribute *attr, const char *buf, size_t count)
2925 struct Scsi_Host *shost = class_to_shost(dev);
2926 struct fc_lport *lport = shost_priv(shost);
2927 struct fcoe_port *port = lport_priv(lport);
2928 struct bnx2fc_interface *interface = port->priv;
2931 rval = kstrtouint(buf, 10, &val);
2937 interface->tm_timeout = (u8)val;
2941 static DEVICE_ATTR(tm_timeout, S_IRUGO|S_IWUSR, bnx2fc_tm_timeout_show,
2942 bnx2fc_tm_timeout_store);
2944 static struct device_attribute *bnx2fc_host_attrs[] = {
2945 &dev_attr_tm_timeout,
2950 * scsi_host_template structure used while registering with SCSI-ml
2952 static struct scsi_host_template bnx2fc_shost_template = {
2953 .module = THIS_MODULE,
2954 .name = "QLogic Offload FCoE Initiator",
2955 .queuecommand = bnx2fc_queuecommand,
2956 .eh_timed_out = fc_eh_timed_out,
2957 .eh_abort_handler = bnx2fc_eh_abort, /* abts */
2958 .eh_device_reset_handler = bnx2fc_eh_device_reset, /* lun reset */
2959 .eh_target_reset_handler = bnx2fc_eh_target_reset, /* tgt reset */
2960 .eh_host_reset_handler = fc_eh_host_reset,
2961 .slave_alloc = fc_slave_alloc,
2962 .change_queue_depth = scsi_change_queue_depth,
2965 .sg_tablesize = BNX2FC_MAX_BDS_PER_CMD,
2966 .dma_boundary = 0x7fff,
2967 .max_sectors = 0x3fbf,
2968 .track_queue_depth = 1,
2969 .slave_configure = bnx2fc_slave_configure,
2970 .shost_attrs = bnx2fc_host_attrs,
2973 static struct libfc_function_template bnx2fc_libfc_fcn_templ = {
2974 .frame_send = bnx2fc_xmit,
2975 .elsct_send = bnx2fc_elsct_send,
2976 .fcp_abort_io = bnx2fc_abort_io,
2977 .fcp_cleanup = bnx2fc_cleanup,
2978 .get_lesb = fcoe_get_lesb,
2979 .rport_event_callback = bnx2fc_rport_event_handler,
2983 * bnx2fc_cnic_cb - global template of bnx2fc - cnic driver interface
2984 * structure carrying callback function pointers
2986 static struct cnic_ulp_ops bnx2fc_cnic_cb = {
2987 .owner = THIS_MODULE,
2988 .cnic_init = bnx2fc_ulp_init,
2989 .cnic_exit = bnx2fc_ulp_exit,
2990 .cnic_start = bnx2fc_ulp_start,
2991 .cnic_stop = bnx2fc_ulp_stop,
2992 .indicate_kcqes = bnx2fc_indicate_kcqe,
2993 .indicate_netevent = bnx2fc_indicate_netevent,
2994 .cnic_get_stats = bnx2fc_ulp_get_stats,