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-2015 QLogic Corporation
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation.
13 * Written by: Bhanu Prakash Gollapudi (bprakash@broadcom.com)
18 static struct list_head adapter_list;
19 static struct list_head if_list;
20 static u32 adapter_count;
21 static DEFINE_MUTEX(bnx2fc_dev_lock);
22 DEFINE_PER_CPU(struct bnx2fc_percpu_s, bnx2fc_percpu);
24 #define DRV_MODULE_NAME "bnx2fc"
25 #define DRV_MODULE_VERSION BNX2FC_VERSION
26 #define DRV_MODULE_RELDATE "October 15, 2015"
29 static char version[] =
30 "QLogic FCoE Driver " DRV_MODULE_NAME \
31 " v" DRV_MODULE_VERSION " (" DRV_MODULE_RELDATE ")\n";
34 MODULE_AUTHOR("Bhanu Prakash Gollapudi <bprakash@broadcom.com>");
35 MODULE_DESCRIPTION("QLogic FCoE Driver");
36 MODULE_LICENSE("GPL");
37 MODULE_VERSION(DRV_MODULE_VERSION);
39 #define BNX2FC_MAX_QUEUE_DEPTH 256
40 #define BNX2FC_MIN_QUEUE_DEPTH 32
41 #define FCOE_WORD_TO_BYTE 4
43 static struct scsi_transport_template *bnx2fc_transport_template;
44 static struct scsi_transport_template *bnx2fc_vport_xport_template;
46 struct workqueue_struct *bnx2fc_wq;
48 /* bnx2fc structure needs only one instance of the fcoe_percpu_s structure.
49 * Here the io threads are per cpu but the l2 thread is just one
51 struct fcoe_percpu_s bnx2fc_global;
52 DEFINE_SPINLOCK(bnx2fc_global_lock);
54 static struct cnic_ulp_ops bnx2fc_cnic_cb;
55 static struct libfc_function_template bnx2fc_libfc_fcn_templ;
56 static struct scsi_host_template bnx2fc_shost_template;
57 static struct fc_function_template bnx2fc_transport_function;
58 static struct fcoe_sysfs_function_template bnx2fc_fcoe_sysfs_templ;
59 static struct fc_function_template bnx2fc_vport_xport_function;
60 static int bnx2fc_create(struct net_device *netdev, enum fip_mode fip_mode);
61 static void __bnx2fc_destroy(struct bnx2fc_interface *interface);
62 static int bnx2fc_destroy(struct net_device *net_device);
63 static int bnx2fc_enable(struct net_device *netdev);
64 static int bnx2fc_disable(struct net_device *netdev);
66 /* fcoe_syfs control interface handlers */
67 static int bnx2fc_ctlr_alloc(struct net_device *netdev);
68 static int bnx2fc_ctlr_enabled(struct fcoe_ctlr_device *cdev);
70 static void bnx2fc_recv_frame(struct sk_buff *skb);
72 static void bnx2fc_start_disc(struct bnx2fc_interface *interface);
73 static int bnx2fc_shost_config(struct fc_lport *lport, struct device *dev);
74 static int bnx2fc_lport_config(struct fc_lport *lport);
75 static int bnx2fc_em_config(struct fc_lport *lport, struct bnx2fc_hba *hba);
76 static int bnx2fc_bind_adapter_devices(struct bnx2fc_hba *hba);
77 static void bnx2fc_unbind_adapter_devices(struct bnx2fc_hba *hba);
78 static int bnx2fc_bind_pcidev(struct bnx2fc_hba *hba);
79 static void bnx2fc_unbind_pcidev(struct bnx2fc_hba *hba);
80 static struct fc_lport *bnx2fc_if_create(struct bnx2fc_interface *interface,
81 struct device *parent, int npiv);
82 static void bnx2fc_destroy_work(struct work_struct *work);
84 static struct bnx2fc_hba *bnx2fc_hba_lookup(struct net_device *phys_dev);
85 static struct bnx2fc_interface *bnx2fc_interface_lookup(struct net_device
87 static inline void bnx2fc_interface_put(struct bnx2fc_interface *interface);
88 static struct bnx2fc_hba *bnx2fc_find_hba_for_cnic(struct cnic_dev *cnic);
90 static int bnx2fc_fw_init(struct bnx2fc_hba *hba);
91 static void bnx2fc_fw_destroy(struct bnx2fc_hba *hba);
93 static void bnx2fc_port_shutdown(struct fc_lport *lport);
94 static void bnx2fc_stop(struct bnx2fc_interface *interface);
95 static int __init bnx2fc_mod_init(void);
96 static void __exit bnx2fc_mod_exit(void);
98 unsigned int bnx2fc_debug_level;
99 module_param_named(debug_logging, bnx2fc_debug_level, int, S_IRUGO|S_IWUSR);
100 MODULE_PARM_DESC(debug_logging,
101 "Option to enable extended logging,\n"
102 "\t\tDefault is 0 - no logging.\n"
103 "\t\t0x01 - SCSI cmd error, cleanup.\n"
104 "\t\t0x02 - Session setup, cleanup, etc.\n"
105 "\t\t0x04 - lport events, link, mtu, etc.\n"
106 "\t\t0x08 - ELS logs.\n"
107 "\t\t0x10 - fcoe L2 fame related logs.\n"
108 "\t\t0xff - LOG all messages.");
110 uint bnx2fc_devloss_tmo;
111 module_param_named(devloss_tmo, bnx2fc_devloss_tmo, uint, S_IRUGO);
112 MODULE_PARM_DESC(devloss_tmo, " Change devloss_tmo for the remote ports "
113 "attached via bnx2fc.");
115 uint bnx2fc_max_luns = BNX2FC_MAX_LUN;
116 module_param_named(max_luns, bnx2fc_max_luns, uint, S_IRUGO);
117 MODULE_PARM_DESC(max_luns, " Change the default max_lun per SCSI host. Default "
120 uint bnx2fc_queue_depth;
121 module_param_named(queue_depth, bnx2fc_queue_depth, uint, S_IRUGO);
122 MODULE_PARM_DESC(queue_depth, " Change the default queue depth of SCSI devices "
123 "attached via bnx2fc.");
126 module_param_named(log_fka, bnx2fc_log_fka, uint, S_IRUGO|S_IWUSR);
127 MODULE_PARM_DESC(log_fka, " Print message to kernel log when fcoe is "
128 "initiating a FIP keep alive when debug logging is enabled.");
130 static inline struct net_device *bnx2fc_netdev(const struct fc_lport *lport)
132 return ((struct bnx2fc_interface *)
133 ((struct fcoe_port *)lport_priv(lport))->priv)->netdev;
136 static void bnx2fc_fcf_get_vlan_id(struct fcoe_fcf_device *fcf_dev)
138 struct fcoe_ctlr_device *ctlr_dev =
139 fcoe_fcf_dev_to_ctlr_dev(fcf_dev);
140 struct fcoe_ctlr *ctlr = fcoe_ctlr_device_priv(ctlr_dev);
141 struct bnx2fc_interface *fcoe = fcoe_ctlr_priv(ctlr);
143 fcf_dev->vlan_id = fcoe->vlan_id;
146 static void bnx2fc_clean_rx_queue(struct fc_lport *lp)
148 struct fcoe_percpu_s *bg;
149 struct fcoe_rcv_info *fr;
150 struct sk_buff_head *list;
151 struct sk_buff *skb, *next;
152 struct sk_buff *head;
155 spin_lock_bh(&bg->fcoe_rx_list.lock);
156 list = &bg->fcoe_rx_list;
158 for (skb = head; skb != (struct sk_buff *)list;
161 fr = fcoe_dev_from_skb(skb);
162 if (fr->fr_dev == lp) {
163 __skb_unlink(skb, list);
167 spin_unlock_bh(&bg->fcoe_rx_list.lock);
170 int bnx2fc_get_paged_crc_eof(struct sk_buff *skb, int tlen)
173 spin_lock(&bnx2fc_global_lock);
174 rc = fcoe_get_paged_crc_eof(skb, tlen, &bnx2fc_global);
175 spin_unlock(&bnx2fc_global_lock);
180 static void bnx2fc_abort_io(struct fc_lport *lport)
183 * This function is no-op for bnx2fc, but we do
184 * not want to leave it as NULL either, as libfc
185 * can call the default function which is
190 static void bnx2fc_cleanup(struct fc_lport *lport)
192 struct fcoe_port *port = lport_priv(lport);
193 struct bnx2fc_interface *interface = port->priv;
194 struct bnx2fc_hba *hba = interface->hba;
195 struct bnx2fc_rport *tgt;
198 BNX2FC_MISC_DBG("Entered %s\n", __func__);
199 mutex_lock(&hba->hba_mutex);
200 spin_lock_bh(&hba->hba_lock);
201 for (i = 0; i < BNX2FC_NUM_MAX_SESS; i++) {
202 tgt = hba->tgt_ofld_list[i];
204 /* Cleanup IOs belonging to requested vport */
205 if (tgt->port == port) {
206 spin_unlock_bh(&hba->hba_lock);
207 BNX2FC_TGT_DBG(tgt, "flush/cleanup\n");
208 bnx2fc_flush_active_ios(tgt);
209 spin_lock_bh(&hba->hba_lock);
213 spin_unlock_bh(&hba->hba_lock);
214 mutex_unlock(&hba->hba_mutex);
217 static int bnx2fc_xmit_l2_frame(struct bnx2fc_rport *tgt,
220 struct fc_rport_priv *rdata = tgt->rdata;
221 struct fc_frame_header *fh;
224 fh = fc_frame_header_get(fp);
225 BNX2FC_TGT_DBG(tgt, "Xmit L2 frame rport = 0x%x, oxid = 0x%x, "
226 "r_ctl = 0x%x\n", rdata->ids.port_id,
227 ntohs(fh->fh_ox_id), fh->fh_r_ctl);
228 if ((fh->fh_type == FC_TYPE_ELS) &&
229 (fh->fh_r_ctl == FC_RCTL_ELS_REQ)) {
231 switch (fc_frame_payload_op(fp)) {
233 rc = bnx2fc_send_adisc(tgt, fp);
236 rc = bnx2fc_send_logo(tgt, fp);
239 rc = bnx2fc_send_rls(tgt, fp);
244 } else if ((fh->fh_type == FC_TYPE_BLS) &&
245 (fh->fh_r_ctl == FC_RCTL_BA_ABTS))
246 BNX2FC_TGT_DBG(tgt, "ABTS frame\n");
248 BNX2FC_TGT_DBG(tgt, "Send L2 frame type 0x%x "
249 "rctl 0x%x thru non-offload path\n",
250 fh->fh_type, fh->fh_r_ctl);
260 * bnx2fc_xmit - bnx2fc's FCoE frame transmit function
262 * @lport: the associated local port
263 * @fp: the fc_frame to be transmitted
265 static int bnx2fc_xmit(struct fc_lport *lport, struct fc_frame *fp)
268 struct fcoe_crc_eof *cp;
270 struct fc_frame_header *fh;
271 struct bnx2fc_interface *interface;
272 struct fcoe_ctlr *ctlr;
273 struct bnx2fc_hba *hba;
274 struct fcoe_port *port;
276 struct bnx2fc_rport *tgt;
277 struct fc_stats *stats;
280 unsigned int hlen, tlen, elen;
283 port = (struct fcoe_port *)lport_priv(lport);
284 interface = port->priv;
285 ctlr = bnx2fc_to_ctlr(interface);
286 hba = interface->hba;
288 fh = fc_frame_header_get(fp);
291 if (!lport->link_up) {
292 BNX2FC_HBA_DBG(lport, "bnx2fc_xmit link down\n");
297 if (unlikely(fh->fh_r_ctl == FC_RCTL_ELS_REQ)) {
298 if (!ctlr->sel_fcf) {
299 BNX2FC_HBA_DBG(lport, "FCF not selected yet!\n");
303 if (fcoe_ctlr_els_send(ctlr, lport, skb))
311 * Snoop the frame header to check if the frame is for
312 * an offloaded session
315 * tgt_ofld_list access is synchronized using
316 * both hba mutex and hba lock. Atleast hba mutex or
317 * hba lock needs to be held for read access.
320 spin_lock_bh(&hba->hba_lock);
321 tgt = bnx2fc_tgt_lookup(port, ntoh24(fh->fh_d_id));
322 if (tgt && (test_bit(BNX2FC_FLAG_SESSION_READY, &tgt->flags))) {
323 /* This frame is for offloaded session */
324 BNX2FC_HBA_DBG(lport, "xmit: Frame is for offloaded session "
325 "port_id = 0x%x\n", ntoh24(fh->fh_d_id));
326 spin_unlock_bh(&hba->hba_lock);
327 rc = bnx2fc_xmit_l2_frame(tgt, fp);
333 spin_unlock_bh(&hba->hba_lock);
336 elen = sizeof(struct ethhdr);
337 hlen = sizeof(struct fcoe_hdr);
338 tlen = sizeof(struct fcoe_crc_eof);
339 wlen = (skb->len - tlen + sizeof(crc)) / FCOE_WORD_TO_BYTE;
341 skb->ip_summed = CHECKSUM_NONE;
342 crc = fcoe_fc_crc(fp);
344 /* copy port crc and eof to the skb buff */
345 if (skb_is_nonlinear(skb)) {
347 if (bnx2fc_get_paged_crc_eof(skb, tlen)) {
351 frag = &skb_shinfo(skb)->frags[skb_shinfo(skb)->nr_frags - 1];
352 cp = kmap_atomic(skb_frag_page(frag)) + frag->page_offset;
354 cp = (struct fcoe_crc_eof *)skb_put(skb, tlen);
357 memset(cp, 0, sizeof(*cp));
359 cp->fcoe_crc32 = cpu_to_le32(~crc);
360 if (skb_is_nonlinear(skb)) {
365 /* adjust skb network/transport offsets to match mac/fcoe/port */
366 skb_push(skb, elen + hlen);
367 skb_reset_mac_header(skb);
368 skb_reset_network_header(skb);
370 skb->protocol = htons(ETH_P_FCOE);
371 skb->dev = interface->netdev;
373 /* fill up mac and fcoe headers */
375 eh->h_proto = htons(ETH_P_FCOE);
377 fc_fcoe_set_mac(eh->h_dest, fh->fh_d_id);
379 /* insert GW address */
380 memcpy(eh->h_dest, ctlr->dest_addr, ETH_ALEN);
382 if (unlikely(ctlr->flogi_oxid != FC_XID_UNKNOWN))
383 memcpy(eh->h_source, ctlr->ctl_src_addr, ETH_ALEN);
385 memcpy(eh->h_source, port->data_src_addr, ETH_ALEN);
387 hp = (struct fcoe_hdr *)(eh + 1);
388 memset(hp, 0, sizeof(*hp));
390 FC_FCOE_ENCAPS_VER(hp, FC_FCOE_VER);
393 /* fcoe lso, mss is in max_payload which is non-zero for FCP data */
394 if (lport->seq_offload && fr_max_payload(fp)) {
395 skb_shinfo(skb)->gso_type = SKB_GSO_FCOE;
396 skb_shinfo(skb)->gso_size = fr_max_payload(fp);
398 skb_shinfo(skb)->gso_type = 0;
399 skb_shinfo(skb)->gso_size = 0;
403 stats = per_cpu_ptr(lport->stats, get_cpu());
405 stats->TxWords += wlen;
408 /* send down to lld */
410 if (port->fcoe_pending_queue.qlen)
411 fcoe_check_wait_queue(lport, skb);
412 else if (fcoe_start_io(skb))
413 fcoe_check_wait_queue(lport, skb);
419 * bnx2fc_rcv - This is bnx2fc's receive function called by NET_RX_SOFTIRQ
421 * @skb: the receive socket buffer
422 * @dev: associated net device
424 * @olddev: last device
426 * This function receives the packet and builds FC frame and passes it up
428 static int bnx2fc_rcv(struct sk_buff *skb, struct net_device *dev,
429 struct packet_type *ptype, struct net_device *olddev)
431 struct fc_lport *lport;
432 struct bnx2fc_interface *interface;
433 struct fcoe_ctlr *ctlr;
434 struct fc_frame_header *fh;
435 struct fcoe_rcv_info *fr;
436 struct fcoe_percpu_s *bg;
437 struct sk_buff *tmp_skb;
440 interface = container_of(ptype, struct bnx2fc_interface,
442 ctlr = bnx2fc_to_ctlr(interface);
445 if (unlikely(lport == NULL)) {
446 printk(KERN_ERR PFX "bnx2fc_rcv: lport is NULL\n");
450 tmp_skb = skb_share_check(skb, GFP_ATOMIC);
456 if (unlikely(eth_hdr(skb)->h_proto != htons(ETH_P_FCOE))) {
457 printk(KERN_ERR PFX "bnx2fc_rcv: Wrong FC type frame\n");
462 * Check for minimum frame length, and make sure required FCoE
463 * and FC headers are pulled into the linear data area.
465 if (unlikely((skb->len < FCOE_MIN_FRAME) ||
466 !pskb_may_pull(skb, FCOE_HEADER_LEN)))
469 skb_set_transport_header(skb, sizeof(struct fcoe_hdr));
470 fh = (struct fc_frame_header *) skb_transport_header(skb);
472 oxid = ntohs(fh->fh_ox_id);
474 fr = fcoe_dev_from_skb(skb);
478 spin_lock(&bg->fcoe_rx_list.lock);
480 __skb_queue_tail(&bg->fcoe_rx_list, skb);
481 if (bg->fcoe_rx_list.qlen == 1)
482 wake_up_process(bg->kthread);
484 spin_unlock(&bg->fcoe_rx_list.lock);
492 static int bnx2fc_l2_rcv_thread(void *arg)
494 struct fcoe_percpu_s *bg = arg;
497 set_user_nice(current, MIN_NICE);
498 set_current_state(TASK_INTERRUPTIBLE);
499 while (!kthread_should_stop()) {
501 spin_lock_bh(&bg->fcoe_rx_list.lock);
502 while ((skb = __skb_dequeue(&bg->fcoe_rx_list)) != NULL) {
503 spin_unlock_bh(&bg->fcoe_rx_list.lock);
504 bnx2fc_recv_frame(skb);
505 spin_lock_bh(&bg->fcoe_rx_list.lock);
507 __set_current_state(TASK_INTERRUPTIBLE);
508 spin_unlock_bh(&bg->fcoe_rx_list.lock);
510 __set_current_state(TASK_RUNNING);
515 static void bnx2fc_recv_frame(struct sk_buff *skb)
518 struct fc_lport *lport;
519 struct fcoe_rcv_info *fr;
520 struct fc_stats *stats;
521 struct fc_frame_header *fh;
522 struct fcoe_crc_eof crc_eof;
524 struct fc_lport *vn_port;
525 struct fcoe_port *port;
530 fr = fcoe_dev_from_skb(skb);
532 if (unlikely(lport == NULL)) {
533 printk(KERN_ERR PFX "Invalid lport struct\n");
538 if (skb_is_nonlinear(skb))
540 mac = eth_hdr(skb)->h_source;
541 dest_mac = eth_hdr(skb)->h_dest;
543 /* Pull the header */
544 hp = (struct fcoe_hdr *) skb_network_header(skb);
545 fh = (struct fc_frame_header *) skb_transport_header(skb);
546 skb_pull(skb, sizeof(struct fcoe_hdr));
547 fr_len = skb->len - sizeof(struct fcoe_crc_eof);
549 fp = (struct fc_frame *)skb;
552 fr_sof(fp) = hp->fcoe_sof;
553 if (skb_copy_bits(skb, fr_len, &crc_eof, sizeof(crc_eof))) {
557 fr_eof(fp) = crc_eof.fcoe_eof;
558 fr_crc(fp) = crc_eof.fcoe_crc32;
559 if (pskb_trim(skb, fr_len)) {
564 fh = fc_frame_header_get(fp);
566 vn_port = fc_vport_id_lookup(lport, ntoh24(fh->fh_d_id));
568 port = lport_priv(vn_port);
569 if (!ether_addr_equal(port->data_src_addr, dest_mac)) {
570 BNX2FC_HBA_DBG(lport, "fpma mismatch\n");
575 if (fh->fh_r_ctl == FC_RCTL_DD_SOL_DATA &&
576 fh->fh_type == FC_TYPE_FCP) {
577 /* Drop FCP data. We dont this in L2 path */
581 if (fh->fh_r_ctl == FC_RCTL_ELS_REQ &&
582 fh->fh_type == FC_TYPE_ELS) {
583 switch (fc_frame_payload_op(fp)) {
585 if (ntoh24(fh->fh_s_id) == FC_FID_FLOGI) {
586 /* drop non-FIP LOGO */
594 if (fh->fh_r_ctl == FC_RCTL_BA_ABTS) {
595 /* Drop incoming ABTS */
600 stats = per_cpu_ptr(lport->stats, smp_processor_id());
602 stats->RxWords += fr_len / FCOE_WORD_TO_BYTE;
604 if (le32_to_cpu(fr_crc(fp)) !=
605 ~crc32(~0, skb->data, fr_len)) {
606 if (stats->InvalidCRCCount < 5)
607 printk(KERN_WARNING PFX "dropping frame with "
609 stats->InvalidCRCCount++;
613 fc_exch_recv(lport, fp);
617 * bnx2fc_percpu_io_thread - thread per cpu for ios
619 * @arg: ptr to bnx2fc_percpu_info structure
621 static int bnx2fc_percpu_io_thread(void *arg)
623 struct bnx2fc_percpu_s *p = arg;
624 struct bnx2fc_work *work, *tmp;
625 LIST_HEAD(work_list);
627 set_user_nice(current, MIN_NICE);
628 set_current_state(TASK_INTERRUPTIBLE);
629 while (!kthread_should_stop()) {
631 spin_lock_bh(&p->fp_work_lock);
632 while (!list_empty(&p->work_list)) {
633 list_splice_init(&p->work_list, &work_list);
634 spin_unlock_bh(&p->fp_work_lock);
636 list_for_each_entry_safe(work, tmp, &work_list, list) {
637 list_del_init(&work->list);
638 bnx2fc_process_cq_compl(work->tgt, work->wqe);
642 spin_lock_bh(&p->fp_work_lock);
644 __set_current_state(TASK_INTERRUPTIBLE);
645 spin_unlock_bh(&p->fp_work_lock);
647 __set_current_state(TASK_RUNNING);
652 static struct fc_host_statistics *bnx2fc_get_host_stats(struct Scsi_Host *shost)
654 struct fc_host_statistics *bnx2fc_stats;
655 struct fc_lport *lport = shost_priv(shost);
656 struct fcoe_port *port = lport_priv(lport);
657 struct bnx2fc_interface *interface = port->priv;
658 struct bnx2fc_hba *hba = interface->hba;
659 struct fcoe_statistics_params *fw_stats;
662 fw_stats = (struct fcoe_statistics_params *)hba->stats_buffer;
666 mutex_lock(&hba->hba_stats_mutex);
668 bnx2fc_stats = fc_get_host_stats(shost);
670 init_completion(&hba->stat_req_done);
671 if (bnx2fc_send_stat_req(hba))
672 goto unlock_stats_mutex;
673 rc = wait_for_completion_timeout(&hba->stat_req_done, (2 * HZ));
675 BNX2FC_HBA_DBG(lport, "FW stat req timed out\n");
676 goto unlock_stats_mutex;
678 BNX2FC_STATS(hba, rx_stat2, fc_crc_cnt);
679 bnx2fc_stats->invalid_crc_count += hba->bfw_stats.fc_crc_cnt;
680 BNX2FC_STATS(hba, tx_stat, fcoe_tx_pkt_cnt);
681 bnx2fc_stats->tx_frames += hba->bfw_stats.fcoe_tx_pkt_cnt;
682 BNX2FC_STATS(hba, tx_stat, fcoe_tx_byte_cnt);
683 bnx2fc_stats->tx_words += ((hba->bfw_stats.fcoe_tx_byte_cnt) / 4);
684 BNX2FC_STATS(hba, rx_stat0, fcoe_rx_pkt_cnt);
685 bnx2fc_stats->rx_frames += hba->bfw_stats.fcoe_rx_pkt_cnt;
686 BNX2FC_STATS(hba, rx_stat0, fcoe_rx_byte_cnt);
687 bnx2fc_stats->rx_words += ((hba->bfw_stats.fcoe_rx_byte_cnt) / 4);
689 bnx2fc_stats->dumped_frames = 0;
690 bnx2fc_stats->lip_count = 0;
691 bnx2fc_stats->nos_count = 0;
692 bnx2fc_stats->loss_of_sync_count = 0;
693 bnx2fc_stats->loss_of_signal_count = 0;
694 bnx2fc_stats->prim_seq_protocol_err_count = 0;
696 memcpy(&hba->prev_stats, hba->stats_buffer,
697 sizeof(struct fcoe_statistics_params));
700 mutex_unlock(&hba->hba_stats_mutex);
704 static int bnx2fc_shost_config(struct fc_lport *lport, struct device *dev)
706 struct fcoe_port *port = lport_priv(lport);
707 struct bnx2fc_interface *interface = port->priv;
708 struct bnx2fc_hba *hba = interface->hba;
709 struct Scsi_Host *shost = lport->host;
712 shost->max_cmd_len = BNX2FC_MAX_CMD_LEN;
713 shost->max_lun = bnx2fc_max_luns;
714 shost->max_id = BNX2FC_MAX_FCP_TGT;
715 shost->max_channel = 0;
717 shost->transportt = bnx2fc_vport_xport_template;
719 shost->transportt = bnx2fc_transport_template;
721 /* Add the new host to SCSI-ml */
722 rc = scsi_add_host(lport->host, dev);
724 printk(KERN_ERR PFX "Error on scsi_add_host\n");
728 fc_host_max_npiv_vports(lport->host) = USHRT_MAX;
729 snprintf(fc_host_symbolic_name(lport->host), 256,
730 "%s (QLogic %s) v%s over %s",
731 BNX2FC_NAME, hba->chip_num, BNX2FC_VERSION,
732 interface->netdev->name);
737 static int bnx2fc_link_ok(struct fc_lport *lport)
739 struct fcoe_port *port = lport_priv(lport);
740 struct bnx2fc_interface *interface = port->priv;
741 struct bnx2fc_hba *hba = interface->hba;
742 struct net_device *dev = hba->phys_dev;
745 if ((dev->flags & IFF_UP) && netif_carrier_ok(dev))
746 clear_bit(ADAPTER_STATE_LINK_DOWN, &hba->adapter_state);
748 set_bit(ADAPTER_STATE_LINK_DOWN, &hba->adapter_state);
755 * bnx2fc_get_link_state - get network link state
757 * @hba: adapter instance pointer
759 * updates adapter structure flag based on netdev state
761 void bnx2fc_get_link_state(struct bnx2fc_hba *hba)
763 if (test_bit(__LINK_STATE_NOCARRIER, &hba->phys_dev->state))
764 set_bit(ADAPTER_STATE_LINK_DOWN, &hba->adapter_state);
766 clear_bit(ADAPTER_STATE_LINK_DOWN, &hba->adapter_state);
769 static int bnx2fc_net_config(struct fc_lport *lport, struct net_device *netdev)
771 struct bnx2fc_hba *hba;
772 struct bnx2fc_interface *interface;
773 struct fcoe_ctlr *ctlr;
774 struct fcoe_port *port;
777 port = lport_priv(lport);
778 interface = port->priv;
779 ctlr = bnx2fc_to_ctlr(interface);
780 hba = interface->hba;
782 /* require support for get_pauseparam ethtool op. */
783 if (!hba->phys_dev->ethtool_ops ||
784 !hba->phys_dev->ethtool_ops->get_pauseparam)
787 if (fc_set_mfs(lport, BNX2FC_MFS))
790 skb_queue_head_init(&port->fcoe_pending_queue);
791 port->fcoe_pending_queue_active = 0;
792 setup_timer(&port->timer, fcoe_queue_timer, (unsigned long) lport);
794 fcoe_link_speed_update(lport);
797 if (fcoe_get_wwn(netdev, &wwnn, NETDEV_FCOE_WWNN))
798 wwnn = fcoe_wwn_from_mac(ctlr->ctl_src_addr,
800 BNX2FC_HBA_DBG(lport, "WWNN = 0x%llx\n", wwnn);
801 fc_set_wwnn(lport, wwnn);
803 if (fcoe_get_wwn(netdev, &wwpn, NETDEV_FCOE_WWPN))
804 wwpn = fcoe_wwn_from_mac(ctlr->ctl_src_addr,
807 BNX2FC_HBA_DBG(lport, "WWPN = 0x%llx\n", wwpn);
808 fc_set_wwpn(lport, wwpn);
814 static void bnx2fc_destroy_timer(unsigned long data)
816 struct bnx2fc_hba *hba = (struct bnx2fc_hba *)data;
818 printk(KERN_ERR PFX "ERROR:bnx2fc_destroy_timer - "
819 "Destroy compl not received!!\n");
820 set_bit(BNX2FC_FLAG_DESTROY_CMPL, &hba->flags);
821 wake_up_interruptible(&hba->destroy_wait);
825 * bnx2fc_indicate_netevent - Generic netdev event handler
827 * @context: adapter structure pointer
829 * @vlan_id: vlan id - associated vlan id with this event
831 * Handles NETDEV_UP, NETDEV_DOWN, NETDEV_GOING_DOWN,NETDEV_CHANGE and
832 * NETDEV_CHANGE_MTU events. Handle NETDEV_UNREGISTER only for vlans.
834 static void bnx2fc_indicate_netevent(void *context, unsigned long event,
837 struct bnx2fc_hba *hba = (struct bnx2fc_hba *)context;
838 struct fcoe_ctlr_device *cdev;
839 struct fc_lport *lport;
840 struct fc_lport *vport;
841 struct bnx2fc_interface *interface, *tmp;
842 struct fcoe_ctlr *ctlr;
843 int wait_for_upload = 0;
844 u32 link_possible = 1;
846 if (vlan_id != 0 && event != NETDEV_UNREGISTER)
851 if (!test_bit(ADAPTER_STATE_UP, &hba->adapter_state))
852 printk(KERN_ERR "indicate_netevent: "\
853 "hba is not UP!!\n");
857 clear_bit(ADAPTER_STATE_GOING_DOWN, &hba->adapter_state);
858 clear_bit(ADAPTER_STATE_UP, &hba->adapter_state);
862 case NETDEV_GOING_DOWN:
863 set_bit(ADAPTER_STATE_GOING_DOWN, &hba->adapter_state);
870 case NETDEV_UNREGISTER:
873 mutex_lock(&bnx2fc_dev_lock);
874 list_for_each_entry_safe(interface, tmp, &if_list, list) {
875 if (interface->hba == hba &&
876 interface->vlan_id == (vlan_id & VLAN_VID_MASK))
877 __bnx2fc_destroy(interface);
879 mutex_unlock(&bnx2fc_dev_lock);
881 /* Ensure ALL destroy work has been completed before return */
882 flush_workqueue(bnx2fc_wq);
889 mutex_lock(&bnx2fc_dev_lock);
890 list_for_each_entry(interface, &if_list, list) {
892 if (interface->hba != hba)
895 ctlr = bnx2fc_to_ctlr(interface);
897 BNX2FC_HBA_DBG(lport, "netevent handler - event=%s %ld\n",
898 interface->netdev->name, event);
900 fcoe_link_speed_update(lport);
902 cdev = fcoe_ctlr_to_ctlr_dev(ctlr);
904 if (link_possible && !bnx2fc_link_ok(lport)) {
905 switch (cdev->enabled) {
906 case FCOE_CTLR_DISABLED:
907 pr_info("Link up while interface is disabled.\n");
909 case FCOE_CTLR_ENABLED:
910 case FCOE_CTLR_UNUSED:
911 /* Reset max recv frame size to default */
912 fc_set_mfs(lport, BNX2FC_MFS);
914 * ctlr link up will only be handled during
915 * enable to avoid sending discovery
916 * solicitation on a stale vlan
918 if (interface->enabled)
919 fcoe_ctlr_link_up(ctlr);
921 } else if (fcoe_ctlr_link_down(ctlr)) {
922 switch (cdev->enabled) {
923 case FCOE_CTLR_DISABLED:
924 pr_info("Link down while interface is disabled.\n");
926 case FCOE_CTLR_ENABLED:
927 case FCOE_CTLR_UNUSED:
928 mutex_lock(&lport->lp_mutex);
929 list_for_each_entry(vport, &lport->vports, list)
930 fc_host_port_type(vport->host) =
932 mutex_unlock(&lport->lp_mutex);
933 fc_host_port_type(lport->host) =
935 per_cpu_ptr(lport->stats,
936 get_cpu())->LinkFailureCount++;
938 fcoe_clean_pending_queue(lport);
943 mutex_unlock(&bnx2fc_dev_lock);
945 if (wait_for_upload) {
946 clear_bit(ADAPTER_STATE_READY, &hba->adapter_state);
947 init_waitqueue_head(&hba->shutdown_wait);
948 BNX2FC_MISC_DBG("indicate_netevent "
949 "num_ofld_sess = %d\n",
951 hba->wait_for_link_down = 1;
952 wait_event_interruptible(hba->shutdown_wait,
953 (hba->num_ofld_sess == 0));
954 BNX2FC_MISC_DBG("wakeup - num_ofld_sess = %d\n",
956 hba->wait_for_link_down = 0;
958 if (signal_pending(current))
959 flush_signals(current);
963 static int bnx2fc_libfc_config(struct fc_lport *lport)
966 /* Set the function pointers set by bnx2fc driver */
967 memcpy(&lport->tt, &bnx2fc_libfc_fcn_templ,
968 sizeof(struct libfc_function_template));
969 fc_elsct_init(lport);
972 fc_disc_config(lport, lport);
976 static int bnx2fc_em_config(struct fc_lport *lport, struct bnx2fc_hba *hba)
978 int fcoe_min_xid, fcoe_max_xid;
980 fcoe_min_xid = hba->max_xid + 1;
982 fcoe_max_xid = hba->max_xid + FCOE_XIDS_PER_CPU_OFFSET;
984 fcoe_max_xid = hba->max_xid + FCOE_MAX_XID_OFFSET;
985 if (!fc_exch_mgr_alloc(lport, FC_CLASS_3, fcoe_min_xid,
986 fcoe_max_xid, NULL)) {
987 printk(KERN_ERR PFX "em_config:fc_exch_mgr_alloc failed\n");
994 static int bnx2fc_lport_config(struct fc_lport *lport)
998 lport->max_retry_count = BNX2FC_MAX_RETRY_CNT;
999 lport->max_rport_retry_count = BNX2FC_MAX_RPORT_RETRY_CNT;
1000 lport->e_d_tov = 2 * 1000;
1001 lport->r_a_tov = 10 * 1000;
1003 lport->service_params = (FCP_SPPF_INIT_FCN | FCP_SPPF_RD_XRDY_DIS |
1004 FCP_SPPF_RETRY | FCP_SPPF_CONF_COMPL);
1005 lport->does_npiv = 1;
1007 memset(&lport->rnid_gen, 0, sizeof(struct fc_els_rnid_gen));
1008 lport->rnid_gen.rnid_atype = BNX2FC_RNID_HBA;
1010 /* alloc stats structure */
1011 if (fc_lport_init_stats(lport))
1014 /* Finish fc_lport configuration */
1015 fc_lport_config(lport);
1021 * bnx2fc_fip_recv - handle a received FIP frame.
1023 * @skb: the received skb
1024 * @dev: associated &net_device
1025 * @ptype: the &packet_type structure which was used to register this handler.
1026 * @orig_dev: original receive &net_device, in case @ dev is a bond.
1028 * Returns: 0 for success
1030 static int bnx2fc_fip_recv(struct sk_buff *skb, struct net_device *dev,
1031 struct packet_type *ptype,
1032 struct net_device *orig_dev)
1034 struct bnx2fc_interface *interface;
1035 struct fcoe_ctlr *ctlr;
1036 interface = container_of(ptype, struct bnx2fc_interface,
1038 ctlr = bnx2fc_to_ctlr(interface);
1039 fcoe_ctlr_recv(ctlr, skb);
1044 * bnx2fc_update_src_mac - Update Ethernet MAC filters.
1046 * @fip: FCoE controller.
1047 * @old: Unicast MAC address to delete if the MAC is non-zero.
1048 * @new: Unicast MAC address to add.
1050 * Remove any previously-set unicast MAC filter.
1051 * Add secondary FCoE MAC address filter for our OUI.
1053 static void bnx2fc_update_src_mac(struct fc_lport *lport, u8 *addr)
1055 struct fcoe_port *port = lport_priv(lport);
1057 memcpy(port->data_src_addr, addr, ETH_ALEN);
1061 * bnx2fc_get_src_mac - return the ethernet source address for an lport
1063 * @lport: libfc port
1065 static u8 *bnx2fc_get_src_mac(struct fc_lport *lport)
1067 struct fcoe_port *port;
1069 port = (struct fcoe_port *)lport_priv(lport);
1070 return port->data_src_addr;
1074 * bnx2fc_fip_send - send an Ethernet-encapsulated FIP frame.
1076 * @fip: FCoE controller.
1079 static void bnx2fc_fip_send(struct fcoe_ctlr *fip, struct sk_buff *skb)
1081 struct fip_header *fiph;
1082 struct ethhdr *eth_hdr;
1086 fiph = (struct fip_header *) ((void *)skb->data + 2 * ETH_ALEN + 2);
1087 eth_hdr = (struct ethhdr *)skb_mac_header(skb);
1088 op = ntohs(fiph->fip_op);
1089 sub = fiph->fip_subcode;
1091 if (op == FIP_OP_CTRL && sub == FIP_SC_SOL && bnx2fc_log_fka)
1092 BNX2FC_MISC_DBG("Sending FKA from %pM to %pM.\n",
1093 eth_hdr->h_source, eth_hdr->h_dest);
1095 skb->dev = bnx2fc_from_ctlr(fip)->netdev;
1096 dev_queue_xmit(skb);
1099 static int bnx2fc_vport_create(struct fc_vport *vport, bool disabled)
1101 struct Scsi_Host *shost = vport_to_shost(vport);
1102 struct fc_lport *n_port = shost_priv(shost);
1103 struct fcoe_port *port = lport_priv(n_port);
1104 struct bnx2fc_interface *interface = port->priv;
1105 struct net_device *netdev = interface->netdev;
1106 struct fc_lport *vn_port;
1110 rc = fcoe_validate_vport_create(vport);
1112 fcoe_wwn_to_str(vport->port_name, buf, sizeof(buf));
1113 printk(KERN_ERR PFX "Failed to create vport, "
1114 "WWPN (0x%s) already exists\n",
1119 if (!test_bit(BNX2FC_FLAG_FW_INIT_DONE, &interface->hba->flags)) {
1120 printk(KERN_ERR PFX "vn ports cannot be created on"
1121 "this interface\n");
1125 mutex_lock(&bnx2fc_dev_lock);
1126 vn_port = bnx2fc_if_create(interface, &vport->dev, 1);
1127 mutex_unlock(&bnx2fc_dev_lock);
1131 printk(KERN_ERR PFX "bnx2fc_vport_create (%s) failed\n",
1136 if (bnx2fc_devloss_tmo)
1137 fc_host_dev_loss_tmo(vn_port->host) = bnx2fc_devloss_tmo;
1140 fc_vport_set_state(vport, FC_VPORT_DISABLED);
1142 vn_port->boot_time = jiffies;
1143 fc_lport_init(vn_port);
1144 fc_fabric_login(vn_port);
1145 fc_vport_setlink(vn_port);
1150 static void bnx2fc_free_vport(struct bnx2fc_hba *hba, struct fc_lport *lport)
1152 struct bnx2fc_lport *blport, *tmp;
1154 spin_lock_bh(&hba->hba_lock);
1155 list_for_each_entry_safe(blport, tmp, &hba->vports, list) {
1156 if (blport->lport == lport) {
1157 list_del(&blport->list);
1161 spin_unlock_bh(&hba->hba_lock);
1164 static int bnx2fc_vport_destroy(struct fc_vport *vport)
1166 struct Scsi_Host *shost = vport_to_shost(vport);
1167 struct fc_lport *n_port = shost_priv(shost);
1168 struct fc_lport *vn_port = vport->dd_data;
1169 struct fcoe_port *port = lport_priv(vn_port);
1170 struct bnx2fc_interface *interface = port->priv;
1171 struct fc_lport *v_port;
1174 mutex_lock(&n_port->lp_mutex);
1175 list_for_each_entry(v_port, &n_port->vports, list)
1176 if (v_port->vport == vport) {
1182 mutex_unlock(&n_port->lp_mutex);
1185 list_del(&vn_port->list);
1186 mutex_unlock(&n_port->lp_mutex);
1187 bnx2fc_free_vport(interface->hba, port->lport);
1188 bnx2fc_port_shutdown(port->lport);
1189 bnx2fc_interface_put(interface);
1190 queue_work(bnx2fc_wq, &port->destroy_work);
1194 static int bnx2fc_vport_disable(struct fc_vport *vport, bool disable)
1196 struct fc_lport *lport = vport->dd_data;
1199 fc_vport_set_state(vport, FC_VPORT_DISABLED);
1200 fc_fabric_logoff(lport);
1202 lport->boot_time = jiffies;
1203 fc_fabric_login(lport);
1204 fc_vport_setlink(lport);
1210 static int bnx2fc_interface_setup(struct bnx2fc_interface *interface)
1212 struct net_device *netdev = interface->netdev;
1213 struct net_device *physdev = interface->hba->phys_dev;
1214 struct fcoe_ctlr *ctlr = bnx2fc_to_ctlr(interface);
1215 struct netdev_hw_addr *ha;
1216 int sel_san_mac = 0;
1218 /* setup Source MAC Address */
1220 for_each_dev_addr(physdev, ha) {
1221 BNX2FC_MISC_DBG("net_config: ha->type = %d, fip_mac = ",
1223 printk(KERN_INFO "%2x:%2x:%2x:%2x:%2x:%2x\n", ha->addr[0],
1224 ha->addr[1], ha->addr[2], ha->addr[3],
1225 ha->addr[4], ha->addr[5]);
1227 if ((ha->type == NETDEV_HW_ADDR_T_SAN) &&
1228 (is_valid_ether_addr(ha->addr))) {
1229 memcpy(ctlr->ctl_src_addr, ha->addr,
1232 BNX2FC_MISC_DBG("Found SAN MAC\n");
1240 interface->fip_packet_type.func = bnx2fc_fip_recv;
1241 interface->fip_packet_type.type = htons(ETH_P_FIP);
1242 interface->fip_packet_type.dev = netdev;
1243 dev_add_pack(&interface->fip_packet_type);
1245 interface->fcoe_packet_type.func = bnx2fc_rcv;
1246 interface->fcoe_packet_type.type = __constant_htons(ETH_P_FCOE);
1247 interface->fcoe_packet_type.dev = netdev;
1248 dev_add_pack(&interface->fcoe_packet_type);
1253 static int bnx2fc_attach_transport(void)
1255 bnx2fc_transport_template =
1256 fc_attach_transport(&bnx2fc_transport_function);
1258 if (bnx2fc_transport_template == NULL) {
1259 printk(KERN_ERR PFX "Failed to attach FC transport\n");
1263 bnx2fc_vport_xport_template =
1264 fc_attach_transport(&bnx2fc_vport_xport_function);
1265 if (bnx2fc_vport_xport_template == NULL) {
1267 "Failed to attach FC transport for vport\n");
1268 fc_release_transport(bnx2fc_transport_template);
1269 bnx2fc_transport_template = NULL;
1274 static void bnx2fc_release_transport(void)
1276 fc_release_transport(bnx2fc_transport_template);
1277 fc_release_transport(bnx2fc_vport_xport_template);
1278 bnx2fc_transport_template = NULL;
1279 bnx2fc_vport_xport_template = NULL;
1282 static void bnx2fc_interface_release(struct kref *kref)
1284 struct fcoe_ctlr_device *ctlr_dev;
1285 struct bnx2fc_interface *interface;
1286 struct fcoe_ctlr *ctlr;
1287 struct net_device *netdev;
1289 interface = container_of(kref, struct bnx2fc_interface, kref);
1290 BNX2FC_MISC_DBG("Interface is being released\n");
1292 ctlr = bnx2fc_to_ctlr(interface);
1293 ctlr_dev = fcoe_ctlr_to_ctlr_dev(ctlr);
1294 netdev = interface->netdev;
1296 /* tear-down FIP controller */
1297 if (test_and_clear_bit(BNX2FC_CTLR_INIT_DONE, &interface->if_flags))
1298 fcoe_ctlr_destroy(ctlr);
1300 fcoe_ctlr_device_delete(ctlr_dev);
1303 module_put(THIS_MODULE);
1306 static inline void bnx2fc_interface_get(struct bnx2fc_interface *interface)
1308 kref_get(&interface->kref);
1311 static inline void bnx2fc_interface_put(struct bnx2fc_interface *interface)
1313 kref_put(&interface->kref, bnx2fc_interface_release);
1315 static void bnx2fc_hba_destroy(struct bnx2fc_hba *hba)
1317 /* Free the command manager */
1319 bnx2fc_cmd_mgr_free(hba->cmd_mgr);
1320 hba->cmd_mgr = NULL;
1322 kfree(hba->tgt_ofld_list);
1323 bnx2fc_unbind_pcidev(hba);
1328 * bnx2fc_hba_create - create a new bnx2fc hba
1330 * @cnic: pointer to cnic device
1332 * Creates a new FCoE hba on the given device.
1335 static struct bnx2fc_hba *bnx2fc_hba_create(struct cnic_dev *cnic)
1337 struct bnx2fc_hba *hba;
1338 struct fcoe_capabilities *fcoe_cap;
1341 hba = kzalloc(sizeof(*hba), GFP_KERNEL);
1343 printk(KERN_ERR PFX "Unable to allocate hba structure\n");
1346 spin_lock_init(&hba->hba_lock);
1347 mutex_init(&hba->hba_mutex);
1348 mutex_init(&hba->hba_stats_mutex);
1352 hba->max_tasks = cnic->max_fcoe_exchanges;
1353 hba->elstm_xids = (hba->max_tasks / 2);
1354 hba->max_outstanding_cmds = hba->elstm_xids;
1355 hba->max_xid = (hba->max_tasks - 1);
1357 rc = bnx2fc_bind_pcidev(hba);
1359 printk(KERN_ERR PFX "create_adapter: bind error\n");
1362 hba->phys_dev = cnic->netdev;
1363 hba->next_conn_id = 0;
1365 hba->tgt_ofld_list =
1366 kzalloc(sizeof(struct bnx2fc_rport *) * BNX2FC_NUM_MAX_SESS,
1368 if (!hba->tgt_ofld_list) {
1369 printk(KERN_ERR PFX "Unable to allocate tgt offload list\n");
1373 hba->num_ofld_sess = 0;
1375 hba->cmd_mgr = bnx2fc_cmd_mgr_alloc(hba);
1376 if (!hba->cmd_mgr) {
1377 printk(KERN_ERR PFX "em_config:bnx2fc_cmd_mgr_alloc failed\n");
1380 fcoe_cap = &hba->fcoe_cap;
1382 fcoe_cap->capability1 = BNX2FC_TM_MAX_SQES <<
1383 FCOE_IOS_PER_CONNECTION_SHIFT;
1384 fcoe_cap->capability1 |= BNX2FC_NUM_MAX_SESS <<
1385 FCOE_LOGINS_PER_PORT_SHIFT;
1386 fcoe_cap->capability2 = hba->max_outstanding_cmds <<
1387 FCOE_NUMBER_OF_EXCHANGES_SHIFT;
1388 fcoe_cap->capability2 |= BNX2FC_MAX_NPIV <<
1389 FCOE_NPIV_WWN_PER_PORT_SHIFT;
1390 fcoe_cap->capability3 = BNX2FC_NUM_MAX_SESS <<
1391 FCOE_TARGETS_SUPPORTED_SHIFT;
1392 fcoe_cap->capability3 |= hba->max_outstanding_cmds <<
1393 FCOE_OUTSTANDING_COMMANDS_SHIFT;
1394 fcoe_cap->capability4 = FCOE_CAPABILITY4_STATEFUL;
1396 init_waitqueue_head(&hba->shutdown_wait);
1397 init_waitqueue_head(&hba->destroy_wait);
1398 INIT_LIST_HEAD(&hba->vports);
1403 kfree(hba->tgt_ofld_list);
1405 bnx2fc_unbind_pcidev(hba);
1411 static struct bnx2fc_interface *
1412 bnx2fc_interface_create(struct bnx2fc_hba *hba,
1413 struct net_device *netdev,
1414 enum fip_state fip_mode)
1416 struct fcoe_ctlr_device *ctlr_dev;
1417 struct bnx2fc_interface *interface;
1418 struct fcoe_ctlr *ctlr;
1422 size = (sizeof(*interface) + sizeof(struct fcoe_ctlr));
1423 ctlr_dev = fcoe_ctlr_device_add(&netdev->dev, &bnx2fc_fcoe_sysfs_templ,
1426 printk(KERN_ERR PFX "Unable to allocate interface structure\n");
1429 ctlr = fcoe_ctlr_device_priv(ctlr_dev);
1430 ctlr->cdev = ctlr_dev;
1431 interface = fcoe_ctlr_priv(ctlr);
1433 kref_init(&interface->kref);
1434 interface->hba = hba;
1435 interface->netdev = netdev;
1437 /* Initialize FIP */
1438 fcoe_ctlr_init(ctlr, fip_mode);
1439 ctlr->send = bnx2fc_fip_send;
1440 ctlr->update_mac = bnx2fc_update_src_mac;
1441 ctlr->get_src_addr = bnx2fc_get_src_mac;
1442 set_bit(BNX2FC_CTLR_INIT_DONE, &interface->if_flags);
1444 rc = bnx2fc_interface_setup(interface);
1448 fcoe_ctlr_destroy(ctlr);
1450 fcoe_ctlr_device_delete(ctlr_dev);
1455 * bnx2fc_if_create - Create FCoE instance on a given interface
1457 * @interface: FCoE interface to create a local port on
1458 * @parent: Device pointer to be the parent in sysfs for the SCSI host
1459 * @npiv: Indicates if the port is vport or not
1461 * Creates a fc_lport instance and a Scsi_Host instance and configure them.
1463 * Returns: Allocated fc_lport or an error pointer
1465 static struct fc_lport *bnx2fc_if_create(struct bnx2fc_interface *interface,
1466 struct device *parent, int npiv)
1468 struct fcoe_ctlr *ctlr = bnx2fc_to_ctlr(interface);
1469 struct fc_lport *lport, *n_port;
1470 struct fcoe_port *port;
1471 struct Scsi_Host *shost;
1472 struct fc_vport *vport = dev_to_vport(parent);
1473 struct bnx2fc_lport *blport;
1474 struct bnx2fc_hba *hba = interface->hba;
1477 blport = kzalloc(sizeof(struct bnx2fc_lport), GFP_KERNEL);
1479 BNX2FC_HBA_DBG(ctlr->lp, "Unable to alloc blport\n");
1483 /* Allocate Scsi_Host structure */
1484 bnx2fc_shost_template.can_queue = hba->max_outstanding_cmds;
1486 lport = libfc_host_alloc(&bnx2fc_shost_template, sizeof(*port));
1488 lport = libfc_vport_create(vport, sizeof(*port));
1491 printk(KERN_ERR PFX "could not allocate scsi host structure\n");
1494 shost = lport->host;
1495 port = lport_priv(lport);
1496 port->lport = lport;
1497 port->priv = interface;
1498 port->get_netdev = bnx2fc_netdev;
1499 INIT_WORK(&port->destroy_work, bnx2fc_destroy_work);
1501 /* Configure fcoe_port */
1502 rc = bnx2fc_lport_config(lport);
1507 printk(KERN_ERR PFX "Setting vport names, 0x%llX 0x%llX\n",
1508 vport->node_name, vport->port_name);
1509 fc_set_wwnn(lport, vport->node_name);
1510 fc_set_wwpn(lport, vport->port_name);
1512 /* Configure netdev and networking properties of the lport */
1513 rc = bnx2fc_net_config(lport, interface->netdev);
1515 printk(KERN_ERR PFX "Error on bnx2fc_net_config\n");
1519 rc = bnx2fc_shost_config(lport, parent);
1521 printk(KERN_ERR PFX "Couldnt configure shost for %s\n",
1522 interface->netdev->name);
1526 /* Initialize the libfc library */
1527 rc = bnx2fc_libfc_config(lport);
1529 printk(KERN_ERR PFX "Couldnt configure libfc\n");
1532 fc_host_port_type(lport->host) = FC_PORTTYPE_UNKNOWN;
1534 if (bnx2fc_devloss_tmo)
1535 fc_host_dev_loss_tmo(shost) = bnx2fc_devloss_tmo;
1537 /* Allocate exchange manager */
1539 rc = bnx2fc_em_config(lport, hba);
1541 shost = vport_to_shost(vport);
1542 n_port = shost_priv(shost);
1543 rc = fc_exch_mgr_list_clone(n_port, lport);
1547 printk(KERN_ERR PFX "Error on bnx2fc_em_config\n");
1551 bnx2fc_interface_get(interface);
1553 spin_lock_bh(&hba->hba_lock);
1554 blport->lport = lport;
1555 list_add_tail(&blport->list, &hba->vports);
1556 spin_unlock_bh(&hba->hba_lock);
1561 scsi_remove_host(shost);
1563 scsi_host_put(lport->host);
1569 static void bnx2fc_net_cleanup(struct bnx2fc_interface *interface)
1571 /* Dont listen for Ethernet packets anymore */
1572 __dev_remove_pack(&interface->fcoe_packet_type);
1573 __dev_remove_pack(&interface->fip_packet_type);
1577 static void bnx2fc_interface_cleanup(struct bnx2fc_interface *interface)
1579 struct fcoe_ctlr *ctlr = bnx2fc_to_ctlr(interface);
1580 struct fc_lport *lport = ctlr->lp;
1581 struct fcoe_port *port = lport_priv(lport);
1582 struct bnx2fc_hba *hba = interface->hba;
1584 /* Stop the transmit retry timer */
1585 del_timer_sync(&port->timer);
1587 /* Free existing transmit skbs */
1588 fcoe_clean_pending_queue(lport);
1590 bnx2fc_net_cleanup(interface);
1592 bnx2fc_free_vport(hba, lport);
1595 static void bnx2fc_if_destroy(struct fc_lport *lport)
1598 /* Free queued packets for the receive thread */
1599 bnx2fc_clean_rx_queue(lport);
1601 /* Detach from scsi-ml */
1602 fc_remove_host(lport->host);
1603 scsi_remove_host(lport->host);
1606 * Note that only the physical lport will have the exchange manager.
1607 * for vports, this function is NOP
1609 fc_exch_mgr_free(lport);
1611 /* Free memory used by statistical counters */
1612 fc_lport_free_stats(lport);
1614 /* Release Scsi_Host */
1615 scsi_host_put(lport->host);
1618 static void __bnx2fc_destroy(struct bnx2fc_interface *interface)
1620 struct fcoe_ctlr *ctlr = bnx2fc_to_ctlr(interface);
1621 struct fc_lport *lport = ctlr->lp;
1622 struct fcoe_port *port = lport_priv(lport);
1624 bnx2fc_interface_cleanup(interface);
1625 bnx2fc_stop(interface);
1626 list_del(&interface->list);
1627 bnx2fc_interface_put(interface);
1628 queue_work(bnx2fc_wq, &port->destroy_work);
1632 * bnx2fc_destroy - Destroy a bnx2fc FCoE interface
1634 * @buffer: The name of the Ethernet interface to be destroyed
1635 * @kp: The associated kernel parameter
1637 * Called from sysfs.
1639 * Returns: 0 for success
1641 static int bnx2fc_destroy(struct net_device *netdev)
1643 struct bnx2fc_interface *interface = NULL;
1644 struct workqueue_struct *timer_work_queue;
1645 struct fcoe_ctlr *ctlr;
1649 mutex_lock(&bnx2fc_dev_lock);
1651 interface = bnx2fc_interface_lookup(netdev);
1652 ctlr = bnx2fc_to_ctlr(interface);
1653 if (!interface || !ctlr->lp) {
1655 printk(KERN_ERR PFX "bnx2fc_destroy: interface or lport not found\n");
1659 timer_work_queue = interface->timer_work_queue;
1660 __bnx2fc_destroy(interface);
1661 destroy_workqueue(timer_work_queue);
1664 mutex_unlock(&bnx2fc_dev_lock);
1669 static void bnx2fc_destroy_work(struct work_struct *work)
1671 struct fcoe_port *port;
1672 struct fc_lport *lport;
1674 port = container_of(work, struct fcoe_port, destroy_work);
1675 lport = port->lport;
1677 BNX2FC_HBA_DBG(lport, "Entered bnx2fc_destroy_work\n");
1679 bnx2fc_if_destroy(lport);
1682 static void bnx2fc_unbind_adapter_devices(struct bnx2fc_hba *hba)
1684 bnx2fc_free_fw_resc(hba);
1685 bnx2fc_free_task_ctx(hba);
1689 * bnx2fc_bind_adapter_devices - binds bnx2fc adapter with the associated
1692 * @hba: Adapter instance
1694 static int bnx2fc_bind_adapter_devices(struct bnx2fc_hba *hba)
1696 if (bnx2fc_setup_task_ctx(hba))
1699 if (bnx2fc_setup_fw_resc(hba))
1704 bnx2fc_unbind_adapter_devices(hba);
1708 static int bnx2fc_bind_pcidev(struct bnx2fc_hba *hba)
1710 struct cnic_dev *cnic;
1711 struct pci_dev *pdev;
1714 printk(KERN_ERR PFX "cnic is NULL\n");
1718 pdev = hba->pcidev = cnic->pcidev;
1722 switch (pdev->device) {
1723 case PCI_DEVICE_ID_NX2_57710:
1724 strncpy(hba->chip_num, "BCM57710", BCM_CHIP_LEN);
1726 case PCI_DEVICE_ID_NX2_57711:
1727 strncpy(hba->chip_num, "BCM57711", BCM_CHIP_LEN);
1729 case PCI_DEVICE_ID_NX2_57712:
1730 case PCI_DEVICE_ID_NX2_57712_MF:
1731 case PCI_DEVICE_ID_NX2_57712_VF:
1732 strncpy(hba->chip_num, "BCM57712", BCM_CHIP_LEN);
1734 case PCI_DEVICE_ID_NX2_57800:
1735 case PCI_DEVICE_ID_NX2_57800_MF:
1736 case PCI_DEVICE_ID_NX2_57800_VF:
1737 strncpy(hba->chip_num, "BCM57800", BCM_CHIP_LEN);
1739 case PCI_DEVICE_ID_NX2_57810:
1740 case PCI_DEVICE_ID_NX2_57810_MF:
1741 case PCI_DEVICE_ID_NX2_57810_VF:
1742 strncpy(hba->chip_num, "BCM57810", BCM_CHIP_LEN);
1744 case PCI_DEVICE_ID_NX2_57840:
1745 case PCI_DEVICE_ID_NX2_57840_MF:
1746 case PCI_DEVICE_ID_NX2_57840_VF:
1747 case PCI_DEVICE_ID_NX2_57840_2_20:
1748 case PCI_DEVICE_ID_NX2_57840_4_10:
1749 strncpy(hba->chip_num, "BCM57840", BCM_CHIP_LEN);
1752 pr_err(PFX "Unknown device id 0x%x\n", pdev->device);
1755 pci_dev_get(hba->pcidev);
1759 static void bnx2fc_unbind_pcidev(struct bnx2fc_hba *hba)
1762 hba->chip_num[0] = '\0';
1763 pci_dev_put(hba->pcidev);
1769 * bnx2fc_ulp_get_stats - cnic callback to populate FCoE stats
1771 * @handle: transport handle pointing to adapter struture
1773 static int bnx2fc_ulp_get_stats(void *handle)
1775 struct bnx2fc_hba *hba = handle;
1776 struct cnic_dev *cnic;
1777 struct fcoe_stats_info *stats_addr;
1783 stats_addr = &cnic->stats_addr->fcoe_stat;
1787 strncpy(stats_addr->version, BNX2FC_VERSION,
1788 sizeof(stats_addr->version));
1789 stats_addr->txq_size = BNX2FC_SQ_WQES_MAX;
1790 stats_addr->rxq_size = BNX2FC_CQ_WQES_MAX;
1797 * bnx2fc_ulp_start - cnic callback to initialize & start adapter instance
1799 * @handle: transport handle pointing to adapter structure
1801 * This function maps adapter structure to pcidev structure and initiates
1802 * firmware handshake to enable/initialize on-chip FCoE components.
1803 * This bnx2fc - cnic interface api callback is used after following
1804 * conditions are met -
1805 * a) underlying network interface is up (marked by event NETDEV_UP
1807 * b) bnx2fc adatper structure is registered.
1809 static void bnx2fc_ulp_start(void *handle)
1811 struct bnx2fc_hba *hba = handle;
1812 struct bnx2fc_interface *interface;
1813 struct fcoe_ctlr *ctlr;
1814 struct fc_lport *lport;
1816 mutex_lock(&bnx2fc_dev_lock);
1818 if (!test_bit(BNX2FC_FLAG_FW_INIT_DONE, &hba->flags))
1819 bnx2fc_fw_init(hba);
1821 BNX2FC_MISC_DBG("bnx2fc started.\n");
1823 list_for_each_entry(interface, &if_list, list) {
1824 if (interface->hba == hba) {
1825 ctlr = bnx2fc_to_ctlr(interface);
1827 /* Kick off Fabric discovery*/
1828 printk(KERN_ERR PFX "ulp_init: start discovery\n");
1829 lport->tt.frame_send = bnx2fc_xmit;
1830 bnx2fc_start_disc(interface);
1834 mutex_unlock(&bnx2fc_dev_lock);
1837 static void bnx2fc_port_shutdown(struct fc_lport *lport)
1839 BNX2FC_MISC_DBG("Entered %s\n", __func__);
1840 fc_fabric_logoff(lport);
1841 fc_lport_destroy(lport);
1844 static void bnx2fc_stop(struct bnx2fc_interface *interface)
1846 struct fcoe_ctlr *ctlr = bnx2fc_to_ctlr(interface);
1847 struct fc_lport *lport;
1848 struct fc_lport *vport;
1850 if (!test_bit(BNX2FC_FLAG_FW_INIT_DONE, &interface->hba->flags))
1854 bnx2fc_port_shutdown(lport);
1856 mutex_lock(&lport->lp_mutex);
1857 list_for_each_entry(vport, &lport->vports, list)
1858 fc_host_port_type(vport->host) =
1859 FC_PORTTYPE_UNKNOWN;
1860 mutex_unlock(&lport->lp_mutex);
1861 fc_host_port_type(lport->host) = FC_PORTTYPE_UNKNOWN;
1862 fcoe_ctlr_link_down(ctlr);
1863 fcoe_clean_pending_queue(lport);
1866 static int bnx2fc_fw_init(struct bnx2fc_hba *hba)
1868 #define BNX2FC_INIT_POLL_TIME (1000 / HZ)
1872 rc = bnx2fc_bind_adapter_devices(hba);
1874 printk(KERN_ALERT PFX
1875 "bnx2fc_bind_adapter_devices failed - rc = %d\n", rc);
1879 rc = bnx2fc_send_fw_fcoe_init_msg(hba);
1881 printk(KERN_ALERT PFX
1882 "bnx2fc_send_fw_fcoe_init_msg failed - rc = %d\n", rc);
1887 * Wait until the adapter init message is complete, and adapter
1890 while (!test_bit(ADAPTER_STATE_UP, &hba->adapter_state) && i--)
1891 msleep(BNX2FC_INIT_POLL_TIME);
1893 if (!test_bit(ADAPTER_STATE_UP, &hba->adapter_state)) {
1894 printk(KERN_ERR PFX "bnx2fc_start: %s failed to initialize. "
1896 hba->cnic->netdev->name);
1902 set_bit(BNX2FC_FLAG_FW_INIT_DONE, &hba->flags);
1906 bnx2fc_unbind_adapter_devices(hba);
1911 static void bnx2fc_fw_destroy(struct bnx2fc_hba *hba)
1913 if (test_and_clear_bit(BNX2FC_FLAG_FW_INIT_DONE, &hba->flags)) {
1914 if (bnx2fc_send_fw_fcoe_destroy_msg(hba) == 0) {
1915 init_timer(&hba->destroy_timer);
1916 hba->destroy_timer.expires = BNX2FC_FW_TIMEOUT +
1918 hba->destroy_timer.function = bnx2fc_destroy_timer;
1919 hba->destroy_timer.data = (unsigned long)hba;
1920 add_timer(&hba->destroy_timer);
1921 wait_event_interruptible(hba->destroy_wait,
1922 test_bit(BNX2FC_FLAG_DESTROY_CMPL,
1924 clear_bit(BNX2FC_FLAG_DESTROY_CMPL, &hba->flags);
1925 /* This should never happen */
1926 if (signal_pending(current))
1927 flush_signals(current);
1929 del_timer_sync(&hba->destroy_timer);
1931 bnx2fc_unbind_adapter_devices(hba);
1936 * bnx2fc_ulp_stop - cnic callback to shutdown adapter instance
1938 * @handle: transport handle pointing to adapter structure
1940 * Driver checks if adapter is already in shutdown mode, if not start
1941 * the shutdown process.
1943 static void bnx2fc_ulp_stop(void *handle)
1945 struct bnx2fc_hba *hba = handle;
1946 struct bnx2fc_interface *interface;
1948 printk(KERN_ERR "ULP_STOP\n");
1950 mutex_lock(&bnx2fc_dev_lock);
1951 if (!test_bit(BNX2FC_FLAG_FW_INIT_DONE, &hba->flags))
1953 list_for_each_entry(interface, &if_list, list) {
1954 if (interface->hba == hba)
1955 bnx2fc_stop(interface);
1957 BUG_ON(hba->num_ofld_sess != 0);
1959 mutex_lock(&hba->hba_mutex);
1960 clear_bit(ADAPTER_STATE_UP, &hba->adapter_state);
1961 clear_bit(ADAPTER_STATE_GOING_DOWN,
1962 &hba->adapter_state);
1964 clear_bit(ADAPTER_STATE_READY, &hba->adapter_state);
1965 mutex_unlock(&hba->hba_mutex);
1967 bnx2fc_fw_destroy(hba);
1969 mutex_unlock(&bnx2fc_dev_lock);
1972 static void bnx2fc_start_disc(struct bnx2fc_interface *interface)
1974 struct fcoe_ctlr *ctlr = bnx2fc_to_ctlr(interface);
1975 struct fc_lport *lport;
1978 BNX2FC_MISC_DBG("Entered %s\n", __func__);
1979 /* Kick off FIP/FLOGI */
1980 if (!test_bit(BNX2FC_FLAG_FW_INIT_DONE, &interface->hba->flags)) {
1981 printk(KERN_ERR PFX "Init not done yet\n");
1986 BNX2FC_HBA_DBG(lport, "calling fc_fabric_login\n");
1988 if (!bnx2fc_link_ok(lport) && interface->enabled) {
1989 BNX2FC_HBA_DBG(lport, "ctlr_link_up\n");
1990 fcoe_ctlr_link_up(ctlr);
1991 fc_host_port_type(lport->host) = FC_PORTTYPE_NPORT;
1992 set_bit(ADAPTER_STATE_READY, &interface->hba->adapter_state);
1995 /* wait for the FCF to be selected before issuing FLOGI */
1996 while (!ctlr->sel_fcf) {
1998 /* give up after 3 secs */
1999 if (++wait_cnt > 12)
2003 /* Reset max receive frame size to default */
2004 if (fc_set_mfs(lport, BNX2FC_MFS))
2007 fc_lport_init(lport);
2008 fc_fabric_login(lport);
2013 * bnx2fc_ulp_init - Initialize an adapter instance
2015 * @dev : cnic device handle
2016 * Called from cnic_register_driver() context to initialize all
2017 * enumerated cnic devices. This routine allocates adapter structure
2018 * and other device specific resources.
2020 static void bnx2fc_ulp_init(struct cnic_dev *dev)
2022 struct bnx2fc_hba *hba;
2025 BNX2FC_MISC_DBG("Entered %s\n", __func__);
2026 /* bnx2fc works only when bnx2x is loaded */
2027 if (!test_bit(CNIC_F_BNX2X_CLASS, &dev->flags) ||
2028 (dev->max_fcoe_conn == 0)) {
2029 printk(KERN_ERR PFX "bnx2fc FCoE not supported on %s,"
2030 " flags: %lx fcoe_conn: %d\n",
2031 dev->netdev->name, dev->flags, dev->max_fcoe_conn);
2035 hba = bnx2fc_hba_create(dev);
2037 printk(KERN_ERR PFX "hba initialization failed\n");
2041 pr_info(PFX "FCoE initialized for %s.\n", dev->netdev->name);
2043 /* Add HBA to the adapter list */
2044 mutex_lock(&bnx2fc_dev_lock);
2045 list_add_tail(&hba->list, &adapter_list);
2047 mutex_unlock(&bnx2fc_dev_lock);
2049 dev->fcoe_cap = &hba->fcoe_cap;
2050 clear_bit(BNX2FC_CNIC_REGISTERED, &hba->reg_with_cnic);
2051 rc = dev->register_device(dev, CNIC_ULP_FCOE,
2054 printk(KERN_ERR PFX "register_device failed, rc = %d\n", rc);
2056 set_bit(BNX2FC_CNIC_REGISTERED, &hba->reg_with_cnic);
2059 /* Assumes rtnl_lock and the bnx2fc_dev_lock are already taken */
2060 static int __bnx2fc_disable(struct fcoe_ctlr *ctlr)
2062 struct bnx2fc_interface *interface = fcoe_ctlr_priv(ctlr);
2064 if (interface->enabled == true) {
2066 pr_err(PFX "__bnx2fc_disable: lport not found\n");
2069 interface->enabled = false;
2070 fcoe_ctlr_link_down(ctlr);
2071 fcoe_clean_pending_queue(ctlr->lp);
2078 * Deperecated: Use bnx2fc_enabled()
2080 static int bnx2fc_disable(struct net_device *netdev)
2082 struct bnx2fc_interface *interface;
2083 struct fcoe_ctlr *ctlr;
2087 mutex_lock(&bnx2fc_dev_lock);
2089 interface = bnx2fc_interface_lookup(netdev);
2090 ctlr = bnx2fc_to_ctlr(interface);
2094 pr_err(PFX "bnx2fc_disable: interface not found\n");
2096 rc = __bnx2fc_disable(ctlr);
2098 mutex_unlock(&bnx2fc_dev_lock);
2103 static uint bnx2fc_npiv_create_vports(struct fc_lport *lport,
2104 struct cnic_fc_npiv_tbl *npiv_tbl)
2106 struct fc_vport_identifiers vpid;
2107 uint i, created = 0;
2109 if (npiv_tbl->count > MAX_NPIV_ENTRIES) {
2110 BNX2FC_HBA_DBG(lport, "Exceeded count max of npiv table\n");
2114 /* Sanity check the first entry to make sure it's not 0 */
2115 if (wwn_to_u64(npiv_tbl->wwnn[0]) == 0 &&
2116 wwn_to_u64(npiv_tbl->wwpn[0]) == 0) {
2117 BNX2FC_HBA_DBG(lport, "First NPIV table entries invalid.\n");
2121 vpid.roles = FC_PORT_ROLE_FCP_INITIATOR;
2122 vpid.vport_type = FC_PORTTYPE_NPIV;
2123 vpid.disable = false;
2125 for (i = 0; i < npiv_tbl->count; i++) {
2126 vpid.node_name = wwn_to_u64(npiv_tbl->wwnn[i]);
2127 vpid.port_name = wwn_to_u64(npiv_tbl->wwpn[i]);
2128 scnprintf(vpid.symbolic_name, sizeof(vpid.symbolic_name),
2129 "NPIV[%u]:%016llx-%016llx",
2130 created, vpid.port_name, vpid.node_name);
2131 if (fc_vport_create(lport->host, 0, &vpid))
2134 BNX2FC_HBA_DBG(lport, "Failed to create vport\n");
2140 static int __bnx2fc_enable(struct fcoe_ctlr *ctlr)
2142 struct bnx2fc_interface *interface = fcoe_ctlr_priv(ctlr);
2143 struct bnx2fc_hba *hba;
2144 struct cnic_fc_npiv_tbl *npiv_tbl;
2145 struct fc_lport *lport;
2147 if (interface->enabled == false) {
2149 pr_err(PFX "__bnx2fc_enable: lport not found\n");
2151 } else if (!bnx2fc_link_ok(ctlr->lp)) {
2152 fcoe_ctlr_link_up(ctlr);
2153 interface->enabled = true;
2157 /* Create static NPIV ports if any are contained in NVRAM */
2158 hba = interface->hba;
2173 if (!hba->cnic->get_fc_npiv_tbl)
2176 npiv_tbl = kzalloc(sizeof(struct cnic_fc_npiv_tbl), GFP_KERNEL);
2180 if (hba->cnic->get_fc_npiv_tbl(hba->cnic, npiv_tbl))
2183 bnx2fc_npiv_create_vports(lport, npiv_tbl);
2191 * Deprecated: Use bnx2fc_enabled()
2193 static int bnx2fc_enable(struct net_device *netdev)
2195 struct bnx2fc_interface *interface;
2196 struct fcoe_ctlr *ctlr;
2200 mutex_lock(&bnx2fc_dev_lock);
2202 interface = bnx2fc_interface_lookup(netdev);
2203 ctlr = bnx2fc_to_ctlr(interface);
2206 pr_err(PFX "bnx2fc_enable: interface not found\n");
2208 rc = __bnx2fc_enable(ctlr);
2211 mutex_unlock(&bnx2fc_dev_lock);
2217 * bnx2fc_ctlr_enabled() - Enable or disable an FCoE Controller
2218 * @cdev: The FCoE Controller that is being enabled or disabled
2220 * fcoe_sysfs will ensure that the state of 'enabled' has
2221 * changed, so no checking is necessary here. This routine simply
2222 * calls fcoe_enable or fcoe_disable, both of which are deprecated.
2223 * When those routines are removed the functionality can be merged
2226 static int bnx2fc_ctlr_enabled(struct fcoe_ctlr_device *cdev)
2228 struct fcoe_ctlr *ctlr = fcoe_ctlr_device_priv(cdev);
2230 switch (cdev->enabled) {
2231 case FCOE_CTLR_ENABLED:
2232 return __bnx2fc_enable(ctlr);
2233 case FCOE_CTLR_DISABLED:
2234 return __bnx2fc_disable(ctlr);
2235 case FCOE_CTLR_UNUSED:
2241 enum bnx2fc_create_link_state {
2242 BNX2FC_CREATE_LINK_DOWN,
2243 BNX2FC_CREATE_LINK_UP,
2247 * _bnx2fc_create() - Create bnx2fc FCoE interface
2248 * @netdev : The net_device object the Ethernet interface to create on
2249 * @fip_mode: The FIP mode for this creation
2250 * @link_state: The ctlr link state on creation
2252 * Called from either the libfcoe 'create' module parameter
2253 * via fcoe_create or from fcoe_syfs's ctlr_create file.
2255 * libfcoe's 'create' module parameter is deprecated so some
2256 * consolidation of code can be done when that interface is
2259 * Returns: 0 for success
2261 static int _bnx2fc_create(struct net_device *netdev,
2262 enum fip_mode fip_mode,
2263 enum bnx2fc_create_link_state link_state)
2265 struct fcoe_ctlr_device *cdev;
2266 struct fcoe_ctlr *ctlr;
2267 struct bnx2fc_interface *interface;
2268 struct bnx2fc_hba *hba;
2269 struct net_device *phys_dev = netdev;
2270 struct fc_lport *lport;
2271 struct ethtool_drvinfo drvinfo;
2275 BNX2FC_MISC_DBG("Entered bnx2fc_create\n");
2276 if (fip_mode != FIP_MODE_FABRIC) {
2277 printk(KERN_ERR "fip mode not FABRIC\n");
2283 mutex_lock(&bnx2fc_dev_lock);
2285 if (!try_module_get(THIS_MODULE)) {
2290 /* obtain physical netdev */
2291 if (is_vlan_dev(netdev))
2292 phys_dev = vlan_dev_real_dev(netdev);
2294 /* verify if the physical device is a netxtreme2 device */
2295 if (phys_dev->ethtool_ops && phys_dev->ethtool_ops->get_drvinfo) {
2296 memset(&drvinfo, 0, sizeof(drvinfo));
2297 phys_dev->ethtool_ops->get_drvinfo(phys_dev, &drvinfo);
2298 if (strncmp(drvinfo.driver, "bnx2x", strlen("bnx2x"))) {
2299 printk(KERN_ERR PFX "Not a netxtreme2 device\n");
2304 printk(KERN_ERR PFX "unable to obtain drv_info\n");
2309 /* obtain interface and initialize rest of the structure */
2310 hba = bnx2fc_hba_lookup(phys_dev);
2313 printk(KERN_ERR PFX "bnx2fc_create: hba not found\n");
2317 if (bnx2fc_interface_lookup(netdev)) {
2322 interface = bnx2fc_interface_create(hba, netdev, fip_mode);
2324 printk(KERN_ERR PFX "bnx2fc_interface_create failed\n");
2329 if (is_vlan_dev(netdev)) {
2330 vlan_id = vlan_dev_vlan_id(netdev);
2331 interface->vlan_enabled = 1;
2334 ctlr = bnx2fc_to_ctlr(interface);
2335 cdev = fcoe_ctlr_to_ctlr_dev(ctlr);
2336 interface->vlan_id = vlan_id;
2337 interface->tm_timeout = BNX2FC_TM_TIMEOUT;
2339 interface->timer_work_queue =
2340 create_singlethread_workqueue("bnx2fc_timer_wq");
2341 if (!interface->timer_work_queue) {
2342 printk(KERN_ERR PFX "ulp_init could not create timer_wq\n");
2347 lport = bnx2fc_if_create(interface, &cdev->dev, 0);
2349 printk(KERN_ERR PFX "Failed to create interface (%s)\n",
2355 /* Add interface to if_list */
2356 list_add_tail(&interface->list, &if_list);
2358 lport->boot_time = jiffies;
2360 /* Make this master N_port */
2363 if (link_state == BNX2FC_CREATE_LINK_UP)
2364 cdev->enabled = FCOE_CTLR_ENABLED;
2366 cdev->enabled = FCOE_CTLR_DISABLED;
2368 if (link_state == BNX2FC_CREATE_LINK_UP &&
2369 !bnx2fc_link_ok(lport)) {
2370 fcoe_ctlr_link_up(ctlr);
2371 fc_host_port_type(lport->host) = FC_PORTTYPE_NPORT;
2372 set_bit(ADAPTER_STATE_READY, &interface->hba->adapter_state);
2375 BNX2FC_HBA_DBG(lport, "create: START DISC\n");
2376 bnx2fc_start_disc(interface);
2378 if (link_state == BNX2FC_CREATE_LINK_UP)
2379 interface->enabled = true;
2382 * Release from kref_init in bnx2fc_interface_setup, on success
2383 * lport should be holding a reference taken in bnx2fc_if_create
2385 bnx2fc_interface_put(interface);
2386 /* put netdev that was held while calling dev_get_by_name */
2387 mutex_unlock(&bnx2fc_dev_lock);
2392 destroy_workqueue(interface->timer_work_queue);
2394 bnx2fc_net_cleanup(interface);
2395 bnx2fc_interface_put(interface);
2398 module_put(THIS_MODULE);
2400 mutex_unlock(&bnx2fc_dev_lock);
2406 * bnx2fc_create() - Create a bnx2fc interface
2407 * @netdev : The net_device object the Ethernet interface to create on
2408 * @fip_mode: The FIP mode for this creation
2410 * Called from fcoe transport
2412 * Returns: 0 for success
2414 static int bnx2fc_create(struct net_device *netdev, enum fip_mode fip_mode)
2416 return _bnx2fc_create(netdev, fip_mode, BNX2FC_CREATE_LINK_UP);
2420 * bnx2fc_ctlr_alloc() - Allocate a bnx2fc interface from fcoe_sysfs
2421 * @netdev: The net_device to be used by the allocated FCoE Controller
2423 * This routine is called from fcoe_sysfs. It will start the fcoe_ctlr
2424 * in a link_down state. The allows the user an opportunity to configure
2425 * the FCoE Controller from sysfs before enabling the FCoE Controller.
2427 * Creating in with this routine starts the FCoE Controller in Fabric
2428 * mode. The user can change to VN2VN or another mode before enabling.
2430 static int bnx2fc_ctlr_alloc(struct net_device *netdev)
2432 return _bnx2fc_create(netdev, FIP_MODE_FABRIC,
2433 BNX2FC_CREATE_LINK_DOWN);
2437 * bnx2fc_find_hba_for_cnic - maps cnic instance to bnx2fc hba instance
2439 * @cnic: Pointer to cnic device instance
2442 static struct bnx2fc_hba *bnx2fc_find_hba_for_cnic(struct cnic_dev *cnic)
2444 struct bnx2fc_hba *hba;
2446 /* Called with bnx2fc_dev_lock held */
2447 list_for_each_entry(hba, &adapter_list, list) {
2448 if (hba->cnic == cnic)
2454 static struct bnx2fc_interface *bnx2fc_interface_lookup(struct net_device
2457 struct bnx2fc_interface *interface;
2459 /* Called with bnx2fc_dev_lock held */
2460 list_for_each_entry(interface, &if_list, list) {
2461 if (interface->netdev == netdev)
2467 static struct bnx2fc_hba *bnx2fc_hba_lookup(struct net_device
2470 struct bnx2fc_hba *hba;
2472 /* Called with bnx2fc_dev_lock held */
2473 list_for_each_entry(hba, &adapter_list, list) {
2474 if (hba->phys_dev == phys_dev)
2477 printk(KERN_ERR PFX "adapter_lookup: hba NULL\n");
2482 * bnx2fc_ulp_exit - shuts down adapter instance and frees all resources
2484 * @dev cnic device handle
2486 static void bnx2fc_ulp_exit(struct cnic_dev *dev)
2488 struct bnx2fc_hba *hba;
2489 struct bnx2fc_interface *interface, *tmp;
2491 BNX2FC_MISC_DBG("Entered bnx2fc_ulp_exit\n");
2493 if (!test_bit(CNIC_F_BNX2X_CLASS, &dev->flags)) {
2494 printk(KERN_ERR PFX "bnx2fc port check: %s, flags: %lx\n",
2495 dev->netdev->name, dev->flags);
2499 mutex_lock(&bnx2fc_dev_lock);
2500 hba = bnx2fc_find_hba_for_cnic(dev);
2502 printk(KERN_ERR PFX "bnx2fc_ulp_exit: hba not found, dev 0%p\n",
2504 mutex_unlock(&bnx2fc_dev_lock);
2508 list_del_init(&hba->list);
2511 list_for_each_entry_safe(interface, tmp, &if_list, list)
2512 /* destroy not called yet, move to quiesced list */
2513 if (interface->hba == hba)
2514 __bnx2fc_destroy(interface);
2515 mutex_unlock(&bnx2fc_dev_lock);
2517 /* Ensure ALL destroy work has been completed before return */
2518 flush_workqueue(bnx2fc_wq);
2520 bnx2fc_ulp_stop(hba);
2521 /* unregister cnic device */
2522 if (test_and_clear_bit(BNX2FC_CNIC_REGISTERED, &hba->reg_with_cnic))
2523 hba->cnic->unregister_device(hba->cnic, CNIC_ULP_FCOE);
2524 bnx2fc_hba_destroy(hba);
2528 * bnx2fc_fcoe_reset - Resets the fcoe
2530 * @shost: shost the reset is from
2534 static int bnx2fc_fcoe_reset(struct Scsi_Host *shost)
2536 struct fc_lport *lport = shost_priv(shost);
2537 fc_lport_reset(lport);
2542 static bool bnx2fc_match(struct net_device *netdev)
2544 struct net_device *phys_dev = netdev;
2546 mutex_lock(&bnx2fc_dev_lock);
2547 if (is_vlan_dev(netdev))
2548 phys_dev = vlan_dev_real_dev(netdev);
2550 if (bnx2fc_hba_lookup(phys_dev)) {
2551 mutex_unlock(&bnx2fc_dev_lock);
2555 mutex_unlock(&bnx2fc_dev_lock);
2560 static struct fcoe_transport bnx2fc_transport = {
2563 .list = LIST_HEAD_INIT(bnx2fc_transport.list),
2564 .alloc = bnx2fc_ctlr_alloc,
2565 .match = bnx2fc_match,
2566 .create = bnx2fc_create,
2567 .destroy = bnx2fc_destroy,
2568 .enable = bnx2fc_enable,
2569 .disable = bnx2fc_disable,
2573 * bnx2fc_percpu_thread_create - Create a receive thread for an
2576 * @cpu: cpu index for the online cpu
2578 static void bnx2fc_percpu_thread_create(unsigned int cpu)
2580 struct bnx2fc_percpu_s *p;
2581 struct task_struct *thread;
2583 p = &per_cpu(bnx2fc_percpu, cpu);
2585 thread = kthread_create_on_node(bnx2fc_percpu_io_thread,
2586 (void *)p, cpu_to_node(cpu),
2587 "bnx2fc_thread/%d", cpu);
2588 /* bind thread to the cpu */
2589 if (likely(!IS_ERR(thread))) {
2590 kthread_bind(thread, cpu);
2591 p->iothread = thread;
2592 wake_up_process(thread);
2596 static void bnx2fc_percpu_thread_destroy(unsigned int cpu)
2598 struct bnx2fc_percpu_s *p;
2599 struct task_struct *thread;
2600 struct bnx2fc_work *work, *tmp;
2602 BNX2FC_MISC_DBG("destroying io thread for CPU %d\n", cpu);
2604 /* Prevent any new work from being queued for this CPU */
2605 p = &per_cpu(bnx2fc_percpu, cpu);
2606 spin_lock_bh(&p->fp_work_lock);
2607 thread = p->iothread;
2611 /* Free all work in the list */
2612 list_for_each_entry_safe(work, tmp, &p->work_list, list) {
2613 list_del_init(&work->list);
2614 bnx2fc_process_cq_compl(work->tgt, work->wqe);
2618 spin_unlock_bh(&p->fp_work_lock);
2621 kthread_stop(thread);
2625 static int bnx2fc_cpu_online(unsigned int cpu)
2627 printk(PFX "CPU %x online: Create Rx thread\n", cpu);
2628 bnx2fc_percpu_thread_create(cpu);
2632 static int bnx2fc_cpu_dead(unsigned int cpu)
2634 printk(PFX "CPU %x offline: Remove Rx thread\n", cpu);
2635 bnx2fc_percpu_thread_destroy(cpu);
2639 static int bnx2fc_slave_configure(struct scsi_device *sdev)
2641 if (!bnx2fc_queue_depth)
2644 scsi_change_queue_depth(sdev, bnx2fc_queue_depth);
2648 static enum cpuhp_state bnx2fc_online_state;
2651 * bnx2fc_mod_init - module init entry point
2653 * Initialize driver wide global data structures, and register
2656 static int __init bnx2fc_mod_init(void)
2658 struct fcoe_percpu_s *bg;
2659 struct task_struct *l2_thread;
2661 unsigned int cpu = 0;
2662 struct bnx2fc_percpu_s *p;
2664 printk(KERN_INFO PFX "%s", version);
2666 /* register as a fcoe transport */
2667 rc = fcoe_transport_attach(&bnx2fc_transport);
2669 printk(KERN_ERR "failed to register an fcoe transport, check "
2670 "if libfcoe is loaded\n");
2674 INIT_LIST_HEAD(&adapter_list);
2675 INIT_LIST_HEAD(&if_list);
2676 mutex_init(&bnx2fc_dev_lock);
2679 /* Attach FC transport template */
2680 rc = bnx2fc_attach_transport();
2684 bnx2fc_wq = alloc_workqueue("bnx2fc", 0, 0);
2690 bg = &bnx2fc_global;
2691 skb_queue_head_init(&bg->fcoe_rx_list);
2692 l2_thread = kthread_create(bnx2fc_l2_rcv_thread,
2694 "bnx2fc_l2_thread");
2695 if (IS_ERR(l2_thread)) {
2696 rc = PTR_ERR(l2_thread);
2699 wake_up_process(l2_thread);
2700 spin_lock_bh(&bg->fcoe_rx_list.lock);
2701 bg->kthread = l2_thread;
2702 spin_unlock_bh(&bg->fcoe_rx_list.lock);
2704 for_each_possible_cpu(cpu) {
2705 p = &per_cpu(bnx2fc_percpu, cpu);
2706 INIT_LIST_HEAD(&p->work_list);
2707 spin_lock_init(&p->fp_work_lock);
2712 for_each_online_cpu(cpu)
2713 bnx2fc_percpu_thread_create(cpu);
2715 rc = cpuhp_setup_state_nocalls(CPUHP_AP_ONLINE_DYN,
2716 "scsi/bnx2fc:online",
2717 bnx2fc_cpu_online, NULL);
2720 bnx2fc_online_state = rc;
2722 cpuhp_setup_state_nocalls(CPUHP_SCSI_BNX2FC_DEAD, "scsi/bnx2fc:dead",
2723 NULL, bnx2fc_cpu_dead);
2726 cnic_register_driver(CNIC_ULP_FCOE, &bnx2fc_cnic_cb);
2731 for_each_online_cpu(cpu)
2732 bnx2fc_percpu_thread_destroy(cpu);
2734 kthread_stop(l2_thread);
2736 destroy_workqueue(bnx2fc_wq);
2738 bnx2fc_release_transport();
2740 fcoe_transport_detach(&bnx2fc_transport);
2745 static void __exit bnx2fc_mod_exit(void)
2747 LIST_HEAD(to_be_deleted);
2748 struct bnx2fc_hba *hba, *next;
2749 struct fcoe_percpu_s *bg;
2750 struct task_struct *l2_thread;
2751 struct sk_buff *skb;
2752 unsigned int cpu = 0;
2755 * NOTE: Since cnic calls register_driver routine rtnl_lock,
2756 * it will have higher precedence than bnx2fc_dev_lock.
2757 * unregister_device() cannot be called with bnx2fc_dev_lock
2760 mutex_lock(&bnx2fc_dev_lock);
2761 list_splice_init(&adapter_list, &to_be_deleted);
2763 mutex_unlock(&bnx2fc_dev_lock);
2765 /* Unregister with cnic */
2766 list_for_each_entry_safe(hba, next, &to_be_deleted, list) {
2767 list_del_init(&hba->list);
2768 printk(KERN_ERR PFX "MOD_EXIT:destroy hba = 0x%p\n",
2770 bnx2fc_ulp_stop(hba);
2771 /* unregister cnic device */
2772 if (test_and_clear_bit(BNX2FC_CNIC_REGISTERED,
2773 &hba->reg_with_cnic))
2774 hba->cnic->unregister_device(hba->cnic,
2776 bnx2fc_hba_destroy(hba);
2778 cnic_unregister_driver(CNIC_ULP_FCOE);
2780 /* Destroy global thread */
2781 bg = &bnx2fc_global;
2782 spin_lock_bh(&bg->fcoe_rx_list.lock);
2783 l2_thread = bg->kthread;
2785 while ((skb = __skb_dequeue(&bg->fcoe_rx_list)) != NULL)
2788 spin_unlock_bh(&bg->fcoe_rx_list.lock);
2791 kthread_stop(l2_thread);
2794 /* Destroy per cpu threads */
2795 for_each_online_cpu(cpu) {
2796 bnx2fc_percpu_thread_destroy(cpu);
2799 cpuhp_remove_state_nocalls(bnx2fc_online_state);
2800 cpuhp_remove_state_nocalls(CPUHP_SCSI_BNX2FC_DEAD);
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 = fc_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 .use_clustering = ENABLE_CLUSTERING,
2966 .sg_tablesize = BNX2FC_MAX_BDS_PER_CMD,
2967 .max_sectors = 1024,
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,