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_port_destroy(struct fcoe_port *port);
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 int bnx2fc_cpu_callback(struct notifier_block *nfb,
131 unsigned long action, void *hcpu);
132 /* notification function for CPU hotplug events */
133 static struct notifier_block bnx2fc_cpu_notifier = {
134 .notifier_call = bnx2fc_cpu_callback,
137 static inline struct net_device *bnx2fc_netdev(const struct fc_lport *lport)
139 return ((struct bnx2fc_interface *)
140 ((struct fcoe_port *)lport_priv(lport))->priv)->netdev;
143 static void bnx2fc_fcf_get_vlan_id(struct fcoe_fcf_device *fcf_dev)
145 struct fcoe_ctlr_device *ctlr_dev =
146 fcoe_fcf_dev_to_ctlr_dev(fcf_dev);
147 struct fcoe_ctlr *ctlr = fcoe_ctlr_device_priv(ctlr_dev);
148 struct bnx2fc_interface *fcoe = fcoe_ctlr_priv(ctlr);
150 fcf_dev->vlan_id = fcoe->vlan_id;
153 static void bnx2fc_clean_rx_queue(struct fc_lport *lp)
155 struct fcoe_percpu_s *bg;
156 struct fcoe_rcv_info *fr;
157 struct sk_buff_head *list;
158 struct sk_buff *skb, *next;
159 struct sk_buff *head;
162 spin_lock_bh(&bg->fcoe_rx_list.lock);
163 list = &bg->fcoe_rx_list;
165 for (skb = head; skb != (struct sk_buff *)list;
168 fr = fcoe_dev_from_skb(skb);
169 if (fr->fr_dev == lp) {
170 __skb_unlink(skb, list);
174 spin_unlock_bh(&bg->fcoe_rx_list.lock);
177 int bnx2fc_get_paged_crc_eof(struct sk_buff *skb, int tlen)
180 spin_lock(&bnx2fc_global_lock);
181 rc = fcoe_get_paged_crc_eof(skb, tlen, &bnx2fc_global);
182 spin_unlock(&bnx2fc_global_lock);
187 static void bnx2fc_abort_io(struct fc_lport *lport)
190 * This function is no-op for bnx2fc, but we do
191 * not want to leave it as NULL either, as libfc
192 * can call the default function which is
197 static void bnx2fc_cleanup(struct fc_lport *lport)
199 struct fcoe_port *port = lport_priv(lport);
200 struct bnx2fc_interface *interface = port->priv;
201 struct bnx2fc_hba *hba = interface->hba;
202 struct bnx2fc_rport *tgt;
205 BNX2FC_MISC_DBG("Entered %s\n", __func__);
206 mutex_lock(&hba->hba_mutex);
207 spin_lock_bh(&hba->hba_lock);
208 for (i = 0; i < BNX2FC_NUM_MAX_SESS; i++) {
209 tgt = hba->tgt_ofld_list[i];
211 /* Cleanup IOs belonging to requested vport */
212 if (tgt->port == port) {
213 spin_unlock_bh(&hba->hba_lock);
214 BNX2FC_TGT_DBG(tgt, "flush/cleanup\n");
215 bnx2fc_flush_active_ios(tgt);
216 spin_lock_bh(&hba->hba_lock);
220 spin_unlock_bh(&hba->hba_lock);
221 mutex_unlock(&hba->hba_mutex);
224 static int bnx2fc_xmit_l2_frame(struct bnx2fc_rport *tgt,
227 struct fc_rport_priv *rdata = tgt->rdata;
228 struct fc_frame_header *fh;
231 fh = fc_frame_header_get(fp);
232 BNX2FC_TGT_DBG(tgt, "Xmit L2 frame rport = 0x%x, oxid = 0x%x, "
233 "r_ctl = 0x%x\n", rdata->ids.port_id,
234 ntohs(fh->fh_ox_id), fh->fh_r_ctl);
235 if ((fh->fh_type == FC_TYPE_ELS) &&
236 (fh->fh_r_ctl == FC_RCTL_ELS_REQ)) {
238 switch (fc_frame_payload_op(fp)) {
240 rc = bnx2fc_send_adisc(tgt, fp);
243 rc = bnx2fc_send_logo(tgt, fp);
246 rc = bnx2fc_send_rls(tgt, fp);
251 } else if ((fh->fh_type == FC_TYPE_BLS) &&
252 (fh->fh_r_ctl == FC_RCTL_BA_ABTS))
253 BNX2FC_TGT_DBG(tgt, "ABTS frame\n");
255 BNX2FC_TGT_DBG(tgt, "Send L2 frame type 0x%x "
256 "rctl 0x%x thru non-offload path\n",
257 fh->fh_type, fh->fh_r_ctl);
267 * bnx2fc_xmit - bnx2fc's FCoE frame transmit function
269 * @lport: the associated local port
270 * @fp: the fc_frame to be transmitted
272 static int bnx2fc_xmit(struct fc_lport *lport, struct fc_frame *fp)
275 struct fcoe_crc_eof *cp;
277 struct fc_frame_header *fh;
278 struct bnx2fc_interface *interface;
279 struct fcoe_ctlr *ctlr;
280 struct bnx2fc_hba *hba;
281 struct fcoe_port *port;
283 struct bnx2fc_rport *tgt;
284 struct fc_stats *stats;
287 unsigned int hlen, tlen, elen;
290 port = (struct fcoe_port *)lport_priv(lport);
291 interface = port->priv;
292 ctlr = bnx2fc_to_ctlr(interface);
293 hba = interface->hba;
295 fh = fc_frame_header_get(fp);
298 if (!lport->link_up) {
299 BNX2FC_HBA_DBG(lport, "bnx2fc_xmit link down\n");
304 if (unlikely(fh->fh_r_ctl == FC_RCTL_ELS_REQ)) {
305 if (!ctlr->sel_fcf) {
306 BNX2FC_HBA_DBG(lport, "FCF not selected yet!\n");
310 if (fcoe_ctlr_els_send(ctlr, lport, skb))
318 * Snoop the frame header to check if the frame is for
319 * an offloaded session
322 * tgt_ofld_list access is synchronized using
323 * both hba mutex and hba lock. Atleast hba mutex or
324 * hba lock needs to be held for read access.
327 spin_lock_bh(&hba->hba_lock);
328 tgt = bnx2fc_tgt_lookup(port, ntoh24(fh->fh_d_id));
329 if (tgt && (test_bit(BNX2FC_FLAG_SESSION_READY, &tgt->flags))) {
330 /* This frame is for offloaded session */
331 BNX2FC_HBA_DBG(lport, "xmit: Frame is for offloaded session "
332 "port_id = 0x%x\n", ntoh24(fh->fh_d_id));
333 spin_unlock_bh(&hba->hba_lock);
334 rc = bnx2fc_xmit_l2_frame(tgt, fp);
340 spin_unlock_bh(&hba->hba_lock);
343 elen = sizeof(struct ethhdr);
344 hlen = sizeof(struct fcoe_hdr);
345 tlen = sizeof(struct fcoe_crc_eof);
346 wlen = (skb->len - tlen + sizeof(crc)) / FCOE_WORD_TO_BYTE;
348 skb->ip_summed = CHECKSUM_NONE;
349 crc = fcoe_fc_crc(fp);
351 /* copy port crc and eof to the skb buff */
352 if (skb_is_nonlinear(skb)) {
354 if (bnx2fc_get_paged_crc_eof(skb, tlen)) {
358 frag = &skb_shinfo(skb)->frags[skb_shinfo(skb)->nr_frags - 1];
359 cp = kmap_atomic(skb_frag_page(frag)) + frag->page_offset;
361 cp = (struct fcoe_crc_eof *)skb_put(skb, tlen);
364 memset(cp, 0, sizeof(*cp));
366 cp->fcoe_crc32 = cpu_to_le32(~crc);
367 if (skb_is_nonlinear(skb)) {
372 /* adjust skb network/transport offsets to match mac/fcoe/port */
373 skb_push(skb, elen + hlen);
374 skb_reset_mac_header(skb);
375 skb_reset_network_header(skb);
377 skb->protocol = htons(ETH_P_FCOE);
378 skb->dev = interface->netdev;
380 /* fill up mac and fcoe headers */
382 eh->h_proto = htons(ETH_P_FCOE);
384 fc_fcoe_set_mac(eh->h_dest, fh->fh_d_id);
386 /* insert GW address */
387 memcpy(eh->h_dest, ctlr->dest_addr, ETH_ALEN);
389 if (unlikely(ctlr->flogi_oxid != FC_XID_UNKNOWN))
390 memcpy(eh->h_source, ctlr->ctl_src_addr, ETH_ALEN);
392 memcpy(eh->h_source, port->data_src_addr, ETH_ALEN);
394 hp = (struct fcoe_hdr *)(eh + 1);
395 memset(hp, 0, sizeof(*hp));
397 FC_FCOE_ENCAPS_VER(hp, FC_FCOE_VER);
400 /* fcoe lso, mss is in max_payload which is non-zero for FCP data */
401 if (lport->seq_offload && fr_max_payload(fp)) {
402 skb_shinfo(skb)->gso_type = SKB_GSO_FCOE;
403 skb_shinfo(skb)->gso_size = fr_max_payload(fp);
405 skb_shinfo(skb)->gso_type = 0;
406 skb_shinfo(skb)->gso_size = 0;
410 stats = per_cpu_ptr(lport->stats, get_cpu());
412 stats->TxWords += wlen;
415 /* send down to lld */
417 if (port->fcoe_pending_queue.qlen)
418 fcoe_check_wait_queue(lport, skb);
419 else if (fcoe_start_io(skb))
420 fcoe_check_wait_queue(lport, skb);
426 * bnx2fc_rcv - This is bnx2fc's receive function called by NET_RX_SOFTIRQ
428 * @skb: the receive socket buffer
429 * @dev: associated net device
431 * @olddev: last device
433 * This function receives the packet and builds FC frame and passes it up
435 static int bnx2fc_rcv(struct sk_buff *skb, struct net_device *dev,
436 struct packet_type *ptype, struct net_device *olddev)
438 struct fc_lport *lport;
439 struct bnx2fc_interface *interface;
440 struct fcoe_ctlr *ctlr;
441 struct fc_frame_header *fh;
442 struct fcoe_rcv_info *fr;
443 struct fcoe_percpu_s *bg;
444 struct sk_buff *tmp_skb;
447 interface = container_of(ptype, struct bnx2fc_interface,
449 ctlr = bnx2fc_to_ctlr(interface);
452 if (unlikely(lport == NULL)) {
453 printk(KERN_ERR PFX "bnx2fc_rcv: lport is NULL\n");
457 tmp_skb = skb_share_check(skb, GFP_ATOMIC);
463 if (unlikely(eth_hdr(skb)->h_proto != htons(ETH_P_FCOE))) {
464 printk(KERN_ERR PFX "bnx2fc_rcv: Wrong FC type frame\n");
469 * Check for minimum frame length, and make sure required FCoE
470 * and FC headers are pulled into the linear data area.
472 if (unlikely((skb->len < FCOE_MIN_FRAME) ||
473 !pskb_may_pull(skb, FCOE_HEADER_LEN)))
476 skb_set_transport_header(skb, sizeof(struct fcoe_hdr));
477 fh = (struct fc_frame_header *) skb_transport_header(skb);
479 oxid = ntohs(fh->fh_ox_id);
481 fr = fcoe_dev_from_skb(skb);
485 spin_lock(&bg->fcoe_rx_list.lock);
487 __skb_queue_tail(&bg->fcoe_rx_list, skb);
488 if (bg->fcoe_rx_list.qlen == 1)
489 wake_up_process(bg->kthread);
491 spin_unlock(&bg->fcoe_rx_list.lock);
499 static int bnx2fc_l2_rcv_thread(void *arg)
501 struct fcoe_percpu_s *bg = arg;
504 set_user_nice(current, MIN_NICE);
505 set_current_state(TASK_INTERRUPTIBLE);
506 while (!kthread_should_stop()) {
508 spin_lock_bh(&bg->fcoe_rx_list.lock);
509 while ((skb = __skb_dequeue(&bg->fcoe_rx_list)) != NULL) {
510 spin_unlock_bh(&bg->fcoe_rx_list.lock);
511 bnx2fc_recv_frame(skb);
512 spin_lock_bh(&bg->fcoe_rx_list.lock);
514 __set_current_state(TASK_INTERRUPTIBLE);
515 spin_unlock_bh(&bg->fcoe_rx_list.lock);
517 __set_current_state(TASK_RUNNING);
522 static void bnx2fc_recv_frame(struct sk_buff *skb)
526 struct fc_lport *lport;
527 struct fcoe_rcv_info *fr;
528 struct fc_stats *stats;
529 struct fc_frame_header *fh;
530 struct fcoe_crc_eof crc_eof;
532 struct fc_lport *vn_port;
533 struct fcoe_port *port;
538 fr = fcoe_dev_from_skb(skb);
540 if (unlikely(lport == NULL)) {
541 printk(KERN_ERR PFX "Invalid lport struct\n");
546 if (skb_is_nonlinear(skb))
548 mac = eth_hdr(skb)->h_source;
549 dest_mac = eth_hdr(skb)->h_dest;
551 /* Pull the header */
552 hp = (struct fcoe_hdr *) skb_network_header(skb);
553 fh = (struct fc_frame_header *) skb_transport_header(skb);
554 skb_pull(skb, sizeof(struct fcoe_hdr));
555 fr_len = skb->len - sizeof(struct fcoe_crc_eof);
557 stats = per_cpu_ptr(lport->stats, get_cpu());
559 stats->RxWords += fr_len / FCOE_WORD_TO_BYTE;
562 fp = (struct fc_frame *)skb;
565 fr_sof(fp) = hp->fcoe_sof;
566 if (skb_copy_bits(skb, fr_len, &crc_eof, sizeof(crc_eof))) {
570 fr_eof(fp) = crc_eof.fcoe_eof;
571 fr_crc(fp) = crc_eof.fcoe_crc32;
572 if (pskb_trim(skb, fr_len)) {
577 fh = fc_frame_header_get(fp);
579 vn_port = fc_vport_id_lookup(lport, ntoh24(fh->fh_d_id));
581 port = lport_priv(vn_port);
582 if (!ether_addr_equal(port->data_src_addr, dest_mac)) {
583 BNX2FC_HBA_DBG(lport, "fpma mismatch\n");
588 if (fh->fh_r_ctl == FC_RCTL_DD_SOL_DATA &&
589 fh->fh_type == FC_TYPE_FCP) {
590 /* Drop FCP data. We dont this in L2 path */
594 if (fh->fh_r_ctl == FC_RCTL_ELS_REQ &&
595 fh->fh_type == FC_TYPE_ELS) {
596 switch (fc_frame_payload_op(fp)) {
598 if (ntoh24(fh->fh_s_id) == FC_FID_FLOGI) {
599 /* drop non-FIP LOGO */
607 if (fh->fh_r_ctl == FC_RCTL_BA_ABTS) {
608 /* Drop incoming ABTS */
613 fr_crc = le32_to_cpu(fr_crc(fp));
615 if (unlikely(fr_crc != ~crc32(~0, skb->data, fr_len))) {
616 stats = per_cpu_ptr(lport->stats, get_cpu());
617 crc_err = (stats->InvalidCRCCount++);
620 printk(KERN_WARNING PFX "dropping frame with "
625 fc_exch_recv(lport, fp);
629 * bnx2fc_percpu_io_thread - thread per cpu for ios
631 * @arg: ptr to bnx2fc_percpu_info structure
633 static int bnx2fc_percpu_io_thread(void *arg)
635 struct bnx2fc_percpu_s *p = arg;
636 struct bnx2fc_work *work, *tmp;
637 LIST_HEAD(work_list);
639 set_user_nice(current, MIN_NICE);
640 set_current_state(TASK_INTERRUPTIBLE);
641 while (!kthread_should_stop()) {
643 spin_lock_bh(&p->fp_work_lock);
644 while (!list_empty(&p->work_list)) {
645 list_splice_init(&p->work_list, &work_list);
646 spin_unlock_bh(&p->fp_work_lock);
648 list_for_each_entry_safe(work, tmp, &work_list, list) {
649 list_del_init(&work->list);
650 bnx2fc_process_cq_compl(work->tgt, work->wqe);
654 spin_lock_bh(&p->fp_work_lock);
656 __set_current_state(TASK_INTERRUPTIBLE);
657 spin_unlock_bh(&p->fp_work_lock);
659 __set_current_state(TASK_RUNNING);
664 static struct fc_host_statistics *bnx2fc_get_host_stats(struct Scsi_Host *shost)
666 struct fc_host_statistics *bnx2fc_stats;
667 struct fc_lport *lport = shost_priv(shost);
668 struct fcoe_port *port = lport_priv(lport);
669 struct bnx2fc_interface *interface = port->priv;
670 struct bnx2fc_hba *hba = interface->hba;
671 struct fcoe_statistics_params *fw_stats;
674 fw_stats = (struct fcoe_statistics_params *)hba->stats_buffer;
678 mutex_lock(&hba->hba_stats_mutex);
680 bnx2fc_stats = fc_get_host_stats(shost);
682 init_completion(&hba->stat_req_done);
683 if (bnx2fc_send_stat_req(hba))
684 goto unlock_stats_mutex;
685 rc = wait_for_completion_timeout(&hba->stat_req_done, (2 * HZ));
687 BNX2FC_HBA_DBG(lport, "FW stat req timed out\n");
688 goto unlock_stats_mutex;
690 BNX2FC_STATS(hba, rx_stat2, fc_crc_cnt);
691 bnx2fc_stats->invalid_crc_count += hba->bfw_stats.fc_crc_cnt;
692 BNX2FC_STATS(hba, tx_stat, fcoe_tx_pkt_cnt);
693 bnx2fc_stats->tx_frames += hba->bfw_stats.fcoe_tx_pkt_cnt;
694 BNX2FC_STATS(hba, tx_stat, fcoe_tx_byte_cnt);
695 bnx2fc_stats->tx_words += ((hba->bfw_stats.fcoe_tx_byte_cnt) / 4);
696 BNX2FC_STATS(hba, rx_stat0, fcoe_rx_pkt_cnt);
697 bnx2fc_stats->rx_frames += hba->bfw_stats.fcoe_rx_pkt_cnt;
698 BNX2FC_STATS(hba, rx_stat0, fcoe_rx_byte_cnt);
699 bnx2fc_stats->rx_words += ((hba->bfw_stats.fcoe_rx_byte_cnt) / 4);
701 bnx2fc_stats->dumped_frames = 0;
702 bnx2fc_stats->lip_count = 0;
703 bnx2fc_stats->nos_count = 0;
704 bnx2fc_stats->loss_of_sync_count = 0;
705 bnx2fc_stats->loss_of_signal_count = 0;
706 bnx2fc_stats->prim_seq_protocol_err_count = 0;
708 memcpy(&hba->prev_stats, hba->stats_buffer,
709 sizeof(struct fcoe_statistics_params));
712 mutex_unlock(&hba->hba_stats_mutex);
716 static int bnx2fc_shost_config(struct fc_lport *lport, struct device *dev)
718 struct fcoe_port *port = lport_priv(lport);
719 struct bnx2fc_interface *interface = port->priv;
720 struct bnx2fc_hba *hba = interface->hba;
721 struct Scsi_Host *shost = lport->host;
724 shost->max_cmd_len = BNX2FC_MAX_CMD_LEN;
725 shost->max_lun = bnx2fc_max_luns;
726 shost->max_id = BNX2FC_MAX_FCP_TGT;
727 shost->max_channel = 0;
729 shost->transportt = bnx2fc_vport_xport_template;
731 shost->transportt = bnx2fc_transport_template;
733 /* Add the new host to SCSI-ml */
734 rc = scsi_add_host(lport->host, dev);
736 printk(KERN_ERR PFX "Error on scsi_add_host\n");
740 fc_host_max_npiv_vports(lport->host) = USHRT_MAX;
741 snprintf(fc_host_symbolic_name(lport->host), 256,
742 "%s (QLogic %s) v%s over %s",
743 BNX2FC_NAME, hba->chip_num, BNX2FC_VERSION,
744 interface->netdev->name);
749 static int bnx2fc_link_ok(struct fc_lport *lport)
751 struct fcoe_port *port = lport_priv(lport);
752 struct bnx2fc_interface *interface = port->priv;
753 struct bnx2fc_hba *hba = interface->hba;
754 struct net_device *dev = hba->phys_dev;
757 if ((dev->flags & IFF_UP) && netif_carrier_ok(dev))
758 clear_bit(ADAPTER_STATE_LINK_DOWN, &hba->adapter_state);
760 set_bit(ADAPTER_STATE_LINK_DOWN, &hba->adapter_state);
767 * bnx2fc_get_link_state - get network link state
769 * @hba: adapter instance pointer
771 * updates adapter structure flag based on netdev state
773 void bnx2fc_get_link_state(struct bnx2fc_hba *hba)
775 if (test_bit(__LINK_STATE_NOCARRIER, &hba->phys_dev->state))
776 set_bit(ADAPTER_STATE_LINK_DOWN, &hba->adapter_state);
778 clear_bit(ADAPTER_STATE_LINK_DOWN, &hba->adapter_state);
781 static int bnx2fc_net_config(struct fc_lport *lport, struct net_device *netdev)
783 struct bnx2fc_hba *hba;
784 struct bnx2fc_interface *interface;
785 struct fcoe_ctlr *ctlr;
786 struct fcoe_port *port;
789 port = lport_priv(lport);
790 interface = port->priv;
791 ctlr = bnx2fc_to_ctlr(interface);
792 hba = interface->hba;
794 /* require support for get_pauseparam ethtool op. */
795 if (!hba->phys_dev->ethtool_ops ||
796 !hba->phys_dev->ethtool_ops->get_pauseparam)
799 if (fc_set_mfs(lport, BNX2FC_MFS))
802 skb_queue_head_init(&port->fcoe_pending_queue);
803 port->fcoe_pending_queue_active = 0;
804 setup_timer(&port->timer, fcoe_queue_timer, (unsigned long) lport);
806 fcoe_link_speed_update(lport);
809 if (fcoe_get_wwn(netdev, &wwnn, NETDEV_FCOE_WWNN))
810 wwnn = fcoe_wwn_from_mac(ctlr->ctl_src_addr,
812 BNX2FC_HBA_DBG(lport, "WWNN = 0x%llx\n", wwnn);
813 fc_set_wwnn(lport, wwnn);
815 if (fcoe_get_wwn(netdev, &wwpn, NETDEV_FCOE_WWPN))
816 wwpn = fcoe_wwn_from_mac(ctlr->ctl_src_addr,
819 BNX2FC_HBA_DBG(lport, "WWPN = 0x%llx\n", wwpn);
820 fc_set_wwpn(lport, wwpn);
826 static void bnx2fc_destroy_timer(unsigned long data)
828 struct bnx2fc_hba *hba = (struct bnx2fc_hba *)data;
830 printk(KERN_ERR PFX "ERROR:bnx2fc_destroy_timer - "
831 "Destroy compl not received!!\n");
832 set_bit(BNX2FC_FLAG_DESTROY_CMPL, &hba->flags);
833 wake_up_interruptible(&hba->destroy_wait);
837 * bnx2fc_indicate_netevent - Generic netdev event handler
839 * @context: adapter structure pointer
841 * @vlan_id: vlan id - associated vlan id with this event
843 * Handles NETDEV_UP, NETDEV_DOWN, NETDEV_GOING_DOWN,NETDEV_CHANGE and
844 * NETDEV_CHANGE_MTU events. Handle NETDEV_UNREGISTER only for vlans.
846 static void bnx2fc_indicate_netevent(void *context, unsigned long event,
849 struct bnx2fc_hba *hba = (struct bnx2fc_hba *)context;
850 struct fcoe_ctlr_device *cdev;
851 struct fc_lport *lport;
852 struct fc_lport *vport;
853 struct bnx2fc_interface *interface, *tmp;
854 struct fcoe_ctlr *ctlr;
855 int wait_for_upload = 0;
856 u32 link_possible = 1;
858 if (vlan_id != 0 && event != NETDEV_UNREGISTER)
863 if (!test_bit(ADAPTER_STATE_UP, &hba->adapter_state))
864 printk(KERN_ERR "indicate_netevent: "\
865 "hba is not UP!!\n");
869 clear_bit(ADAPTER_STATE_GOING_DOWN, &hba->adapter_state);
870 clear_bit(ADAPTER_STATE_UP, &hba->adapter_state);
874 case NETDEV_GOING_DOWN:
875 set_bit(ADAPTER_STATE_GOING_DOWN, &hba->adapter_state);
882 case NETDEV_UNREGISTER:
885 mutex_lock(&bnx2fc_dev_lock);
886 list_for_each_entry_safe(interface, tmp, &if_list, list) {
887 if (interface->hba == hba &&
888 interface->vlan_id == (vlan_id & VLAN_VID_MASK))
889 __bnx2fc_destroy(interface);
891 mutex_unlock(&bnx2fc_dev_lock);
898 mutex_lock(&bnx2fc_dev_lock);
899 list_for_each_entry(interface, &if_list, list) {
901 if (interface->hba != hba)
904 ctlr = bnx2fc_to_ctlr(interface);
906 BNX2FC_HBA_DBG(lport, "netevent handler - event=%s %ld\n",
907 interface->netdev->name, event);
909 fcoe_link_speed_update(lport);
911 cdev = fcoe_ctlr_to_ctlr_dev(ctlr);
913 if (link_possible && !bnx2fc_link_ok(lport)) {
914 switch (cdev->enabled) {
915 case FCOE_CTLR_DISABLED:
916 pr_info("Link up while interface is disabled.\n");
918 case FCOE_CTLR_ENABLED:
919 case FCOE_CTLR_UNUSED:
920 /* Reset max recv frame size to default */
921 fc_set_mfs(lport, BNX2FC_MFS);
923 * ctlr link up will only be handled during
924 * enable to avoid sending discovery
925 * solicitation on a stale vlan
927 if (interface->enabled)
928 fcoe_ctlr_link_up(ctlr);
930 } else if (fcoe_ctlr_link_down(ctlr)) {
931 switch (cdev->enabled) {
932 case FCOE_CTLR_DISABLED:
933 pr_info("Link down while interface is disabled.\n");
935 case FCOE_CTLR_ENABLED:
936 case FCOE_CTLR_UNUSED:
937 mutex_lock(&lport->lp_mutex);
938 list_for_each_entry(vport, &lport->vports, list)
939 fc_host_port_type(vport->host) =
941 mutex_unlock(&lport->lp_mutex);
942 fc_host_port_type(lport->host) =
944 per_cpu_ptr(lport->stats,
945 get_cpu())->LinkFailureCount++;
947 fcoe_clean_pending_queue(lport);
952 mutex_unlock(&bnx2fc_dev_lock);
954 if (wait_for_upload) {
955 clear_bit(ADAPTER_STATE_READY, &hba->adapter_state);
956 init_waitqueue_head(&hba->shutdown_wait);
957 BNX2FC_MISC_DBG("indicate_netevent "
958 "num_ofld_sess = %d\n",
960 hba->wait_for_link_down = 1;
961 wait_event_interruptible(hba->shutdown_wait,
962 (hba->num_ofld_sess == 0));
963 BNX2FC_MISC_DBG("wakeup - num_ofld_sess = %d\n",
965 hba->wait_for_link_down = 0;
967 if (signal_pending(current))
968 flush_signals(current);
972 static int bnx2fc_libfc_config(struct fc_lport *lport)
975 /* Set the function pointers set by bnx2fc driver */
976 memcpy(&lport->tt, &bnx2fc_libfc_fcn_templ,
977 sizeof(struct libfc_function_template));
978 fc_elsct_init(lport);
980 fc_rport_init(lport);
982 fc_disc_config(lport, lport);
986 static int bnx2fc_em_config(struct fc_lport *lport, struct bnx2fc_hba *hba)
988 int fcoe_min_xid, fcoe_max_xid;
990 fcoe_min_xid = hba->max_xid + 1;
992 fcoe_max_xid = hba->max_xid + FCOE_XIDS_PER_CPU_OFFSET;
994 fcoe_max_xid = hba->max_xid + FCOE_MAX_XID_OFFSET;
995 if (!fc_exch_mgr_alloc(lport, FC_CLASS_3, fcoe_min_xid,
996 fcoe_max_xid, NULL)) {
997 printk(KERN_ERR PFX "em_config:fc_exch_mgr_alloc failed\n");
1004 static int bnx2fc_lport_config(struct fc_lport *lport)
1008 lport->max_retry_count = BNX2FC_MAX_RETRY_CNT;
1009 lport->max_rport_retry_count = BNX2FC_MAX_RPORT_RETRY_CNT;
1010 lport->e_d_tov = 2 * 1000;
1011 lport->r_a_tov = 10 * 1000;
1013 lport->service_params = (FCP_SPPF_INIT_FCN | FCP_SPPF_RD_XRDY_DIS |
1014 FCP_SPPF_RETRY | FCP_SPPF_CONF_COMPL);
1015 lport->does_npiv = 1;
1017 memset(&lport->rnid_gen, 0, sizeof(struct fc_els_rnid_gen));
1018 lport->rnid_gen.rnid_atype = BNX2FC_RNID_HBA;
1020 /* alloc stats structure */
1021 if (fc_lport_init_stats(lport))
1024 /* Finish fc_lport configuration */
1025 fc_lport_config(lport);
1031 * bnx2fc_fip_recv - handle a received FIP frame.
1033 * @skb: the received skb
1034 * @dev: associated &net_device
1035 * @ptype: the &packet_type structure which was used to register this handler.
1036 * @orig_dev: original receive &net_device, in case @ dev is a bond.
1038 * Returns: 0 for success
1040 static int bnx2fc_fip_recv(struct sk_buff *skb, struct net_device *dev,
1041 struct packet_type *ptype,
1042 struct net_device *orig_dev)
1044 struct bnx2fc_interface *interface;
1045 struct fcoe_ctlr *ctlr;
1046 interface = container_of(ptype, struct bnx2fc_interface,
1048 ctlr = bnx2fc_to_ctlr(interface);
1049 fcoe_ctlr_recv(ctlr, skb);
1054 * bnx2fc_update_src_mac - Update Ethernet MAC filters.
1056 * @fip: FCoE controller.
1057 * @old: Unicast MAC address to delete if the MAC is non-zero.
1058 * @new: Unicast MAC address to add.
1060 * Remove any previously-set unicast MAC filter.
1061 * Add secondary FCoE MAC address filter for our OUI.
1063 static void bnx2fc_update_src_mac(struct fc_lport *lport, u8 *addr)
1065 struct fcoe_port *port = lport_priv(lport);
1067 memcpy(port->data_src_addr, addr, ETH_ALEN);
1071 * bnx2fc_get_src_mac - return the ethernet source address for an lport
1073 * @lport: libfc port
1075 static u8 *bnx2fc_get_src_mac(struct fc_lport *lport)
1077 struct fcoe_port *port;
1079 port = (struct fcoe_port *)lport_priv(lport);
1080 return port->data_src_addr;
1084 * bnx2fc_fip_send - send an Ethernet-encapsulated FIP frame.
1086 * @fip: FCoE controller.
1089 static void bnx2fc_fip_send(struct fcoe_ctlr *fip, struct sk_buff *skb)
1091 struct fip_header *fiph;
1092 struct ethhdr *eth_hdr;
1096 fiph = (struct fip_header *) ((void *)skb->data + 2 * ETH_ALEN + 2);
1097 eth_hdr = (struct ethhdr *)skb_mac_header(skb);
1098 op = ntohs(fiph->fip_op);
1099 sub = fiph->fip_subcode;
1101 if (op == FIP_OP_CTRL && sub == FIP_SC_SOL && bnx2fc_log_fka)
1102 BNX2FC_MISC_DBG("Sending FKA from %pM to %pM.\n",
1103 eth_hdr->h_source, eth_hdr->h_dest);
1105 skb->dev = bnx2fc_from_ctlr(fip)->netdev;
1106 dev_queue_xmit(skb);
1109 static int bnx2fc_vport_create(struct fc_vport *vport, bool disabled)
1111 struct Scsi_Host *shost = vport_to_shost(vport);
1112 struct fc_lport *n_port = shost_priv(shost);
1113 struct fcoe_port *port = lport_priv(n_port);
1114 struct bnx2fc_interface *interface = port->priv;
1115 struct net_device *netdev = interface->netdev;
1116 struct fc_lport *vn_port;
1120 rc = fcoe_validate_vport_create(vport);
1122 fcoe_wwn_to_str(vport->port_name, buf, sizeof(buf));
1123 printk(KERN_ERR PFX "Failed to create vport, "
1124 "WWPN (0x%s) already exists\n",
1129 if (!test_bit(BNX2FC_FLAG_FW_INIT_DONE, &interface->hba->flags)) {
1130 printk(KERN_ERR PFX "vn ports cannot be created on"
1131 "this interface\n");
1135 mutex_lock(&bnx2fc_dev_lock);
1136 vn_port = bnx2fc_if_create(interface, &vport->dev, 1);
1137 mutex_unlock(&bnx2fc_dev_lock);
1141 printk(KERN_ERR PFX "bnx2fc_vport_create (%s) failed\n",
1146 if (bnx2fc_devloss_tmo)
1147 fc_host_dev_loss_tmo(vn_port->host) = bnx2fc_devloss_tmo;
1150 fc_vport_set_state(vport, FC_VPORT_DISABLED);
1152 vn_port->boot_time = jiffies;
1153 fc_lport_init(vn_port);
1154 fc_fabric_login(vn_port);
1155 fc_vport_setlink(vn_port);
1160 static void bnx2fc_free_vport(struct bnx2fc_hba *hba, struct fc_lport *lport)
1162 struct bnx2fc_lport *blport, *tmp;
1164 spin_lock_bh(&hba->hba_lock);
1165 list_for_each_entry_safe(blport, tmp, &hba->vports, list) {
1166 if (blport->lport == lport) {
1167 list_del(&blport->list);
1171 spin_unlock_bh(&hba->hba_lock);
1174 static int bnx2fc_vport_destroy(struct fc_vport *vport)
1176 struct Scsi_Host *shost = vport_to_shost(vport);
1177 struct fc_lport *n_port = shost_priv(shost);
1178 struct fc_lport *vn_port = vport->dd_data;
1179 struct fcoe_port *port = lport_priv(vn_port);
1180 struct bnx2fc_interface *interface = port->priv;
1181 struct fc_lport *v_port;
1184 mutex_lock(&n_port->lp_mutex);
1185 list_for_each_entry(v_port, &n_port->vports, list)
1186 if (v_port->vport == vport) {
1192 mutex_unlock(&n_port->lp_mutex);
1195 list_del(&vn_port->list);
1196 mutex_unlock(&n_port->lp_mutex);
1197 bnx2fc_free_vport(interface->hba, port->lport);
1198 bnx2fc_port_shutdown(port->lport);
1199 bnx2fc_port_destroy(port);
1200 bnx2fc_interface_put(interface);
1204 static int bnx2fc_vport_disable(struct fc_vport *vport, bool disable)
1206 struct fc_lport *lport = vport->dd_data;
1209 fc_vport_set_state(vport, FC_VPORT_DISABLED);
1210 fc_fabric_logoff(lport);
1212 lport->boot_time = jiffies;
1213 fc_fabric_login(lport);
1214 fc_vport_setlink(lport);
1220 static int bnx2fc_interface_setup(struct bnx2fc_interface *interface)
1222 struct net_device *netdev = interface->netdev;
1223 struct net_device *physdev = interface->hba->phys_dev;
1224 struct fcoe_ctlr *ctlr = bnx2fc_to_ctlr(interface);
1225 struct netdev_hw_addr *ha;
1226 int sel_san_mac = 0;
1228 /* setup Source MAC Address */
1230 for_each_dev_addr(physdev, ha) {
1231 BNX2FC_MISC_DBG("net_config: ha->type = %d, fip_mac = ",
1233 printk(KERN_INFO "%2x:%2x:%2x:%2x:%2x:%2x\n", ha->addr[0],
1234 ha->addr[1], ha->addr[2], ha->addr[3],
1235 ha->addr[4], ha->addr[5]);
1237 if ((ha->type == NETDEV_HW_ADDR_T_SAN) &&
1238 (is_valid_ether_addr(ha->addr))) {
1239 memcpy(ctlr->ctl_src_addr, ha->addr,
1242 BNX2FC_MISC_DBG("Found SAN MAC\n");
1250 interface->fip_packet_type.func = bnx2fc_fip_recv;
1251 interface->fip_packet_type.type = htons(ETH_P_FIP);
1252 interface->fip_packet_type.dev = netdev;
1253 dev_add_pack(&interface->fip_packet_type);
1255 interface->fcoe_packet_type.func = bnx2fc_rcv;
1256 interface->fcoe_packet_type.type = __constant_htons(ETH_P_FCOE);
1257 interface->fcoe_packet_type.dev = netdev;
1258 dev_add_pack(&interface->fcoe_packet_type);
1263 static int bnx2fc_attach_transport(void)
1265 bnx2fc_transport_template =
1266 fc_attach_transport(&bnx2fc_transport_function);
1268 if (bnx2fc_transport_template == NULL) {
1269 printk(KERN_ERR PFX "Failed to attach FC transport\n");
1273 bnx2fc_vport_xport_template =
1274 fc_attach_transport(&bnx2fc_vport_xport_function);
1275 if (bnx2fc_vport_xport_template == NULL) {
1277 "Failed to attach FC transport for vport\n");
1278 fc_release_transport(bnx2fc_transport_template);
1279 bnx2fc_transport_template = NULL;
1284 static void bnx2fc_release_transport(void)
1286 fc_release_transport(bnx2fc_transport_template);
1287 fc_release_transport(bnx2fc_vport_xport_template);
1288 bnx2fc_transport_template = NULL;
1289 bnx2fc_vport_xport_template = NULL;
1292 static void bnx2fc_interface_release(struct kref *kref)
1294 struct fcoe_ctlr_device *ctlr_dev;
1295 struct bnx2fc_interface *interface;
1296 struct fcoe_ctlr *ctlr;
1297 struct net_device *netdev;
1299 interface = container_of(kref, struct bnx2fc_interface, kref);
1300 BNX2FC_MISC_DBG("Interface is being released\n");
1302 ctlr = bnx2fc_to_ctlr(interface);
1303 ctlr_dev = fcoe_ctlr_to_ctlr_dev(ctlr);
1304 netdev = interface->netdev;
1306 /* tear-down FIP controller */
1307 if (test_and_clear_bit(BNX2FC_CTLR_INIT_DONE, &interface->if_flags))
1308 fcoe_ctlr_destroy(ctlr);
1310 fcoe_ctlr_device_delete(ctlr_dev);
1313 module_put(THIS_MODULE);
1316 static inline void bnx2fc_interface_get(struct bnx2fc_interface *interface)
1318 kref_get(&interface->kref);
1321 static inline void bnx2fc_interface_put(struct bnx2fc_interface *interface)
1323 kref_put(&interface->kref, bnx2fc_interface_release);
1325 static void bnx2fc_hba_destroy(struct bnx2fc_hba *hba)
1327 /* Free the command manager */
1329 bnx2fc_cmd_mgr_free(hba->cmd_mgr);
1330 hba->cmd_mgr = NULL;
1332 kfree(hba->tgt_ofld_list);
1333 bnx2fc_unbind_pcidev(hba);
1338 * bnx2fc_hba_create - create a new bnx2fc hba
1340 * @cnic: pointer to cnic device
1342 * Creates a new FCoE hba on the given device.
1345 static struct bnx2fc_hba *bnx2fc_hba_create(struct cnic_dev *cnic)
1347 struct bnx2fc_hba *hba;
1348 struct fcoe_capabilities *fcoe_cap;
1351 hba = kzalloc(sizeof(*hba), GFP_KERNEL);
1353 printk(KERN_ERR PFX "Unable to allocate hba structure\n");
1356 spin_lock_init(&hba->hba_lock);
1357 mutex_init(&hba->hba_mutex);
1358 mutex_init(&hba->hba_stats_mutex);
1362 hba->max_tasks = cnic->max_fcoe_exchanges;
1363 hba->elstm_xids = (hba->max_tasks / 2);
1364 hba->max_outstanding_cmds = hba->elstm_xids;
1365 hba->max_xid = (hba->max_tasks - 1);
1367 rc = bnx2fc_bind_pcidev(hba);
1369 printk(KERN_ERR PFX "create_adapter: bind error\n");
1372 hba->phys_dev = cnic->netdev;
1373 hba->next_conn_id = 0;
1375 hba->tgt_ofld_list =
1376 kzalloc(sizeof(struct bnx2fc_rport *) * BNX2FC_NUM_MAX_SESS,
1378 if (!hba->tgt_ofld_list) {
1379 printk(KERN_ERR PFX "Unable to allocate tgt offload list\n");
1383 hba->num_ofld_sess = 0;
1385 hba->cmd_mgr = bnx2fc_cmd_mgr_alloc(hba);
1386 if (!hba->cmd_mgr) {
1387 printk(KERN_ERR PFX "em_config:bnx2fc_cmd_mgr_alloc failed\n");
1390 fcoe_cap = &hba->fcoe_cap;
1392 fcoe_cap->capability1 = BNX2FC_TM_MAX_SQES <<
1393 FCOE_IOS_PER_CONNECTION_SHIFT;
1394 fcoe_cap->capability1 |= BNX2FC_NUM_MAX_SESS <<
1395 FCOE_LOGINS_PER_PORT_SHIFT;
1396 fcoe_cap->capability2 = hba->max_outstanding_cmds <<
1397 FCOE_NUMBER_OF_EXCHANGES_SHIFT;
1398 fcoe_cap->capability2 |= BNX2FC_MAX_NPIV <<
1399 FCOE_NPIV_WWN_PER_PORT_SHIFT;
1400 fcoe_cap->capability3 = BNX2FC_NUM_MAX_SESS <<
1401 FCOE_TARGETS_SUPPORTED_SHIFT;
1402 fcoe_cap->capability3 |= hba->max_outstanding_cmds <<
1403 FCOE_OUTSTANDING_COMMANDS_SHIFT;
1404 fcoe_cap->capability4 = FCOE_CAPABILITY4_STATEFUL;
1406 init_waitqueue_head(&hba->shutdown_wait);
1407 init_waitqueue_head(&hba->destroy_wait);
1408 INIT_LIST_HEAD(&hba->vports);
1413 kfree(hba->tgt_ofld_list);
1415 bnx2fc_unbind_pcidev(hba);
1421 static struct bnx2fc_interface *
1422 bnx2fc_interface_create(struct bnx2fc_hba *hba,
1423 struct net_device *netdev,
1424 enum fip_state fip_mode)
1426 struct fcoe_ctlr_device *ctlr_dev;
1427 struct bnx2fc_interface *interface;
1428 struct fcoe_ctlr *ctlr;
1432 size = (sizeof(*interface) + sizeof(struct fcoe_ctlr));
1433 ctlr_dev = fcoe_ctlr_device_add(&netdev->dev, &bnx2fc_fcoe_sysfs_templ,
1436 printk(KERN_ERR PFX "Unable to allocate interface structure\n");
1439 ctlr = fcoe_ctlr_device_priv(ctlr_dev);
1440 ctlr->cdev = ctlr_dev;
1441 interface = fcoe_ctlr_priv(ctlr);
1443 kref_init(&interface->kref);
1444 interface->hba = hba;
1445 interface->netdev = netdev;
1447 /* Initialize FIP */
1448 fcoe_ctlr_init(ctlr, fip_mode);
1449 ctlr->send = bnx2fc_fip_send;
1450 ctlr->update_mac = bnx2fc_update_src_mac;
1451 ctlr->get_src_addr = bnx2fc_get_src_mac;
1452 set_bit(BNX2FC_CTLR_INIT_DONE, &interface->if_flags);
1454 rc = bnx2fc_interface_setup(interface);
1458 fcoe_ctlr_destroy(ctlr);
1460 fcoe_ctlr_device_delete(ctlr_dev);
1465 * bnx2fc_if_create - Create FCoE instance on a given interface
1467 * @interface: FCoE interface to create a local port on
1468 * @parent: Device pointer to be the parent in sysfs for the SCSI host
1469 * @npiv: Indicates if the port is vport or not
1471 * Creates a fc_lport instance and a Scsi_Host instance and configure them.
1473 * Returns: Allocated fc_lport or an error pointer
1475 static struct fc_lport *bnx2fc_if_create(struct bnx2fc_interface *interface,
1476 struct device *parent, int npiv)
1478 struct fcoe_ctlr *ctlr = bnx2fc_to_ctlr(interface);
1479 struct fc_lport *lport, *n_port;
1480 struct fcoe_port *port;
1481 struct Scsi_Host *shost;
1482 struct fc_vport *vport = dev_to_vport(parent);
1483 struct bnx2fc_lport *blport;
1484 struct bnx2fc_hba *hba = interface->hba;
1487 blport = kzalloc(sizeof(struct bnx2fc_lport), GFP_KERNEL);
1489 BNX2FC_HBA_DBG(ctlr->lp, "Unable to alloc blport\n");
1493 /* Allocate Scsi_Host structure */
1494 bnx2fc_shost_template.can_queue = hba->max_outstanding_cmds;
1496 lport = libfc_host_alloc(&bnx2fc_shost_template, sizeof(*port));
1498 lport = libfc_vport_create(vport, sizeof(*port));
1501 printk(KERN_ERR PFX "could not allocate scsi host structure\n");
1504 shost = lport->host;
1505 port = lport_priv(lport);
1506 port->lport = lport;
1507 port->priv = interface;
1508 port->get_netdev = bnx2fc_netdev;
1510 /* Configure fcoe_port */
1511 rc = bnx2fc_lport_config(lport);
1516 printk(KERN_ERR PFX "Setting vport names, 0x%llX 0x%llX\n",
1517 vport->node_name, vport->port_name);
1518 fc_set_wwnn(lport, vport->node_name);
1519 fc_set_wwpn(lport, vport->port_name);
1521 /* Configure netdev and networking properties of the lport */
1522 rc = bnx2fc_net_config(lport, interface->netdev);
1524 printk(KERN_ERR PFX "Error on bnx2fc_net_config\n");
1528 rc = bnx2fc_shost_config(lport, parent);
1530 printk(KERN_ERR PFX "Couldnt configure shost for %s\n",
1531 interface->netdev->name);
1535 /* Initialize the libfc library */
1536 rc = bnx2fc_libfc_config(lport);
1538 printk(KERN_ERR PFX "Couldnt configure libfc\n");
1541 fc_host_port_type(lport->host) = FC_PORTTYPE_UNKNOWN;
1543 if (bnx2fc_devloss_tmo)
1544 fc_host_dev_loss_tmo(shost) = bnx2fc_devloss_tmo;
1546 /* Allocate exchange manager */
1548 rc = bnx2fc_em_config(lport, hba);
1550 shost = vport_to_shost(vport);
1551 n_port = shost_priv(shost);
1552 rc = fc_exch_mgr_list_clone(n_port, lport);
1556 printk(KERN_ERR PFX "Error on bnx2fc_em_config\n");
1560 bnx2fc_interface_get(interface);
1562 spin_lock_bh(&hba->hba_lock);
1563 blport->lport = lport;
1564 list_add_tail(&blport->list, &hba->vports);
1565 spin_unlock_bh(&hba->hba_lock);
1570 scsi_remove_host(shost);
1572 scsi_host_put(lport->host);
1578 static void bnx2fc_net_cleanup(struct bnx2fc_interface *interface)
1580 /* Dont listen for Ethernet packets anymore */
1581 __dev_remove_pack(&interface->fcoe_packet_type);
1582 __dev_remove_pack(&interface->fip_packet_type);
1586 static void bnx2fc_interface_cleanup(struct bnx2fc_interface *interface)
1588 struct fcoe_ctlr *ctlr = bnx2fc_to_ctlr(interface);
1589 struct fc_lport *lport = ctlr->lp;
1590 struct fcoe_port *port = lport_priv(lport);
1591 struct bnx2fc_hba *hba = interface->hba;
1593 /* Stop the transmit retry timer */
1594 del_timer_sync(&port->timer);
1596 /* Free existing transmit skbs */
1597 fcoe_clean_pending_queue(lport);
1599 bnx2fc_net_cleanup(interface);
1601 bnx2fc_free_vport(hba, lport);
1604 static void bnx2fc_if_destroy(struct fc_lport *lport)
1607 /* Free queued packets for the receive thread */
1608 bnx2fc_clean_rx_queue(lport);
1610 /* Detach from scsi-ml */
1611 fc_remove_host(lport->host);
1612 scsi_remove_host(lport->host);
1615 * Note that only the physical lport will have the exchange manager.
1616 * for vports, this function is NOP
1618 fc_exch_mgr_free(lport);
1620 /* Free memory used by statistical counters */
1621 fc_lport_free_stats(lport);
1623 /* Release Scsi_Host */
1624 scsi_host_put(lport->host);
1627 static void __bnx2fc_destroy(struct bnx2fc_interface *interface)
1629 struct fcoe_ctlr *ctlr = bnx2fc_to_ctlr(interface);
1630 struct fc_lport *lport = ctlr->lp;
1631 struct fcoe_port *port = lport_priv(lport);
1633 bnx2fc_interface_cleanup(interface);
1634 bnx2fc_stop(interface);
1635 list_del(&interface->list);
1636 bnx2fc_port_destroy(port);
1637 bnx2fc_interface_put(interface);
1641 * bnx2fc_destroy - Destroy a bnx2fc FCoE interface
1643 * @buffer: The name of the Ethernet interface to be destroyed
1644 * @kp: The associated kernel parameter
1646 * Called from sysfs.
1648 * Returns: 0 for success
1650 static int bnx2fc_destroy(struct net_device *netdev)
1652 struct bnx2fc_interface *interface = NULL;
1653 struct workqueue_struct *timer_work_queue;
1654 struct fcoe_ctlr *ctlr;
1658 mutex_lock(&bnx2fc_dev_lock);
1660 interface = bnx2fc_interface_lookup(netdev);
1661 ctlr = bnx2fc_to_ctlr(interface);
1662 if (!interface || !ctlr->lp) {
1664 printk(KERN_ERR PFX "bnx2fc_destroy: interface or lport not found\n");
1668 timer_work_queue = interface->timer_work_queue;
1669 __bnx2fc_destroy(interface);
1670 destroy_workqueue(timer_work_queue);
1673 mutex_unlock(&bnx2fc_dev_lock);
1678 static void bnx2fc_port_destroy(struct fcoe_port *port)
1680 struct fc_lport *lport;
1682 lport = port->lport;
1683 BNX2FC_HBA_DBG(lport, "Entered %s, destroying lport %p\n", __func__, lport);
1685 bnx2fc_if_destroy(lport);
1688 static void bnx2fc_unbind_adapter_devices(struct bnx2fc_hba *hba)
1690 bnx2fc_free_fw_resc(hba);
1691 bnx2fc_free_task_ctx(hba);
1695 * bnx2fc_bind_adapter_devices - binds bnx2fc adapter with the associated
1698 * @hba: Adapter instance
1700 static int bnx2fc_bind_adapter_devices(struct bnx2fc_hba *hba)
1702 if (bnx2fc_setup_task_ctx(hba))
1705 if (bnx2fc_setup_fw_resc(hba))
1710 bnx2fc_unbind_adapter_devices(hba);
1714 static int bnx2fc_bind_pcidev(struct bnx2fc_hba *hba)
1716 struct cnic_dev *cnic;
1717 struct pci_dev *pdev;
1720 printk(KERN_ERR PFX "cnic is NULL\n");
1724 pdev = hba->pcidev = cnic->pcidev;
1728 switch (pdev->device) {
1729 case PCI_DEVICE_ID_NX2_57710:
1730 strncpy(hba->chip_num, "BCM57710", BCM_CHIP_LEN);
1732 case PCI_DEVICE_ID_NX2_57711:
1733 strncpy(hba->chip_num, "BCM57711", BCM_CHIP_LEN);
1735 case PCI_DEVICE_ID_NX2_57712:
1736 case PCI_DEVICE_ID_NX2_57712_MF:
1737 case PCI_DEVICE_ID_NX2_57712_VF:
1738 strncpy(hba->chip_num, "BCM57712", BCM_CHIP_LEN);
1740 case PCI_DEVICE_ID_NX2_57800:
1741 case PCI_DEVICE_ID_NX2_57800_MF:
1742 case PCI_DEVICE_ID_NX2_57800_VF:
1743 strncpy(hba->chip_num, "BCM57800", BCM_CHIP_LEN);
1745 case PCI_DEVICE_ID_NX2_57810:
1746 case PCI_DEVICE_ID_NX2_57810_MF:
1747 case PCI_DEVICE_ID_NX2_57810_VF:
1748 strncpy(hba->chip_num, "BCM57810", BCM_CHIP_LEN);
1750 case PCI_DEVICE_ID_NX2_57840:
1751 case PCI_DEVICE_ID_NX2_57840_MF:
1752 case PCI_DEVICE_ID_NX2_57840_VF:
1753 case PCI_DEVICE_ID_NX2_57840_2_20:
1754 case PCI_DEVICE_ID_NX2_57840_4_10:
1755 strncpy(hba->chip_num, "BCM57840", BCM_CHIP_LEN);
1758 pr_err(PFX "Unknown device id 0x%x\n", pdev->device);
1761 pci_dev_get(hba->pcidev);
1765 static void bnx2fc_unbind_pcidev(struct bnx2fc_hba *hba)
1768 hba->chip_num[0] = '\0';
1769 pci_dev_put(hba->pcidev);
1775 * bnx2fc_ulp_get_stats - cnic callback to populate FCoE stats
1777 * @handle: transport handle pointing to adapter struture
1779 static int bnx2fc_ulp_get_stats(void *handle)
1781 struct bnx2fc_hba *hba = handle;
1782 struct cnic_dev *cnic;
1783 struct fcoe_stats_info *stats_addr;
1789 stats_addr = &cnic->stats_addr->fcoe_stat;
1793 strncpy(stats_addr->version, BNX2FC_VERSION,
1794 sizeof(stats_addr->version));
1795 stats_addr->txq_size = BNX2FC_SQ_WQES_MAX;
1796 stats_addr->rxq_size = BNX2FC_CQ_WQES_MAX;
1803 * bnx2fc_ulp_start - cnic callback to initialize & start adapter instance
1805 * @handle: transport handle pointing to adapter structure
1807 * This function maps adapter structure to pcidev structure and initiates
1808 * firmware handshake to enable/initialize on-chip FCoE components.
1809 * This bnx2fc - cnic interface api callback is used after following
1810 * conditions are met -
1811 * a) underlying network interface is up (marked by event NETDEV_UP
1813 * b) bnx2fc adatper structure is registered.
1815 static void bnx2fc_ulp_start(void *handle)
1817 struct bnx2fc_hba *hba = handle;
1818 struct bnx2fc_interface *interface;
1819 struct fcoe_ctlr *ctlr;
1820 struct fc_lport *lport;
1822 mutex_lock(&bnx2fc_dev_lock);
1824 if (!test_bit(BNX2FC_FLAG_FW_INIT_DONE, &hba->flags))
1825 bnx2fc_fw_init(hba);
1827 BNX2FC_MISC_DBG("bnx2fc started.\n");
1829 list_for_each_entry(interface, &if_list, list) {
1830 if (interface->hba == hba) {
1831 ctlr = bnx2fc_to_ctlr(interface);
1833 /* Kick off Fabric discovery*/
1834 printk(KERN_ERR PFX "ulp_init: start discovery\n");
1835 lport->tt.frame_send = bnx2fc_xmit;
1836 bnx2fc_start_disc(interface);
1840 mutex_unlock(&bnx2fc_dev_lock);
1843 static void bnx2fc_port_shutdown(struct fc_lport *lport)
1845 BNX2FC_MISC_DBG("Entered %s\n", __func__);
1846 fc_fabric_logoff(lport);
1847 fc_lport_destroy(lport);
1850 static void bnx2fc_stop(struct bnx2fc_interface *interface)
1852 struct fcoe_ctlr *ctlr = bnx2fc_to_ctlr(interface);
1853 struct fc_lport *lport;
1854 struct fc_lport *vport;
1856 if (!test_bit(BNX2FC_FLAG_FW_INIT_DONE, &interface->hba->flags))
1860 bnx2fc_port_shutdown(lport);
1862 mutex_lock(&lport->lp_mutex);
1863 list_for_each_entry(vport, &lport->vports, list)
1864 fc_host_port_type(vport->host) =
1865 FC_PORTTYPE_UNKNOWN;
1866 mutex_unlock(&lport->lp_mutex);
1867 fc_host_port_type(lport->host) = FC_PORTTYPE_UNKNOWN;
1868 fcoe_ctlr_link_down(ctlr);
1869 fcoe_clean_pending_queue(lport);
1872 static int bnx2fc_fw_init(struct bnx2fc_hba *hba)
1874 #define BNX2FC_INIT_POLL_TIME (1000 / HZ)
1878 rc = bnx2fc_bind_adapter_devices(hba);
1880 printk(KERN_ALERT PFX
1881 "bnx2fc_bind_adapter_devices failed - rc = %d\n", rc);
1885 rc = bnx2fc_send_fw_fcoe_init_msg(hba);
1887 printk(KERN_ALERT PFX
1888 "bnx2fc_send_fw_fcoe_init_msg failed - rc = %d\n", rc);
1893 * Wait until the adapter init message is complete, and adapter
1896 while (!test_bit(ADAPTER_STATE_UP, &hba->adapter_state) && i--)
1897 msleep(BNX2FC_INIT_POLL_TIME);
1899 if (!test_bit(ADAPTER_STATE_UP, &hba->adapter_state)) {
1900 printk(KERN_ERR PFX "bnx2fc_start: %s failed to initialize. "
1902 hba->cnic->netdev->name);
1908 set_bit(BNX2FC_FLAG_FW_INIT_DONE, &hba->flags);
1912 bnx2fc_unbind_adapter_devices(hba);
1917 static void bnx2fc_fw_destroy(struct bnx2fc_hba *hba)
1919 if (test_and_clear_bit(BNX2FC_FLAG_FW_INIT_DONE, &hba->flags)) {
1920 if (bnx2fc_send_fw_fcoe_destroy_msg(hba) == 0) {
1921 init_timer(&hba->destroy_timer);
1922 hba->destroy_timer.expires = BNX2FC_FW_TIMEOUT +
1924 hba->destroy_timer.function = bnx2fc_destroy_timer;
1925 hba->destroy_timer.data = (unsigned long)hba;
1926 add_timer(&hba->destroy_timer);
1927 wait_event_interruptible(hba->destroy_wait,
1928 test_bit(BNX2FC_FLAG_DESTROY_CMPL,
1930 clear_bit(BNX2FC_FLAG_DESTROY_CMPL, &hba->flags);
1931 /* This should never happen */
1932 if (signal_pending(current))
1933 flush_signals(current);
1935 del_timer_sync(&hba->destroy_timer);
1937 bnx2fc_unbind_adapter_devices(hba);
1942 * bnx2fc_ulp_stop - cnic callback to shutdown adapter instance
1944 * @handle: transport handle pointing to adapter structure
1946 * Driver checks if adapter is already in shutdown mode, if not start
1947 * the shutdown process.
1949 static void bnx2fc_ulp_stop(void *handle)
1951 struct bnx2fc_hba *hba = handle;
1952 struct bnx2fc_interface *interface;
1954 printk(KERN_ERR "ULP_STOP\n");
1956 mutex_lock(&bnx2fc_dev_lock);
1957 if (!test_bit(BNX2FC_FLAG_FW_INIT_DONE, &hba->flags))
1959 list_for_each_entry(interface, &if_list, list) {
1960 if (interface->hba == hba)
1961 bnx2fc_stop(interface);
1963 BUG_ON(hba->num_ofld_sess != 0);
1965 mutex_lock(&hba->hba_mutex);
1966 clear_bit(ADAPTER_STATE_UP, &hba->adapter_state);
1967 clear_bit(ADAPTER_STATE_GOING_DOWN,
1968 &hba->adapter_state);
1970 clear_bit(ADAPTER_STATE_READY, &hba->adapter_state);
1971 mutex_unlock(&hba->hba_mutex);
1973 bnx2fc_fw_destroy(hba);
1975 mutex_unlock(&bnx2fc_dev_lock);
1978 static void bnx2fc_start_disc(struct bnx2fc_interface *interface)
1980 struct fcoe_ctlr *ctlr = bnx2fc_to_ctlr(interface);
1981 struct fc_lport *lport;
1984 BNX2FC_MISC_DBG("Entered %s\n", __func__);
1985 /* Kick off FIP/FLOGI */
1986 if (!test_bit(BNX2FC_FLAG_FW_INIT_DONE, &interface->hba->flags)) {
1987 printk(KERN_ERR PFX "Init not done yet\n");
1992 BNX2FC_HBA_DBG(lport, "calling fc_fabric_login\n");
1994 if (!bnx2fc_link_ok(lport) && interface->enabled) {
1995 BNX2FC_HBA_DBG(lport, "ctlr_link_up\n");
1996 fcoe_ctlr_link_up(ctlr);
1997 fc_host_port_type(lport->host) = FC_PORTTYPE_NPORT;
1998 set_bit(ADAPTER_STATE_READY, &interface->hba->adapter_state);
2001 /* wait for the FCF to be selected before issuing FLOGI */
2002 while (!ctlr->sel_fcf) {
2004 /* give up after 3 secs */
2005 if (++wait_cnt > 12)
2009 /* Reset max receive frame size to default */
2010 if (fc_set_mfs(lport, BNX2FC_MFS))
2013 fc_lport_init(lport);
2014 fc_fabric_login(lport);
2019 * bnx2fc_ulp_init - Initialize an adapter instance
2021 * @dev : cnic device handle
2022 * Called from cnic_register_driver() context to initialize all
2023 * enumerated cnic devices. This routine allocates adapter structure
2024 * and other device specific resources.
2026 static void bnx2fc_ulp_init(struct cnic_dev *dev)
2028 struct bnx2fc_hba *hba;
2031 BNX2FC_MISC_DBG("Entered %s\n", __func__);
2032 /* bnx2fc works only when bnx2x is loaded */
2033 if (!test_bit(CNIC_F_BNX2X_CLASS, &dev->flags) ||
2034 (dev->max_fcoe_conn == 0)) {
2035 printk(KERN_ERR PFX "bnx2fc FCoE not supported on %s,"
2036 " flags: %lx fcoe_conn: %d\n",
2037 dev->netdev->name, dev->flags, dev->max_fcoe_conn);
2041 hba = bnx2fc_hba_create(dev);
2043 printk(KERN_ERR PFX "hba initialization failed\n");
2047 pr_info(PFX "FCoE initialized for %s.\n", dev->netdev->name);
2049 /* Add HBA to the adapter list */
2050 mutex_lock(&bnx2fc_dev_lock);
2051 list_add_tail(&hba->list, &adapter_list);
2053 mutex_unlock(&bnx2fc_dev_lock);
2055 dev->fcoe_cap = &hba->fcoe_cap;
2056 clear_bit(BNX2FC_CNIC_REGISTERED, &hba->reg_with_cnic);
2057 rc = dev->register_device(dev, CNIC_ULP_FCOE,
2060 printk(KERN_ERR PFX "register_device failed, rc = %d\n", rc);
2062 set_bit(BNX2FC_CNIC_REGISTERED, &hba->reg_with_cnic);
2065 /* Assumes rtnl_lock and the bnx2fc_dev_lock are already taken */
2066 static int __bnx2fc_disable(struct fcoe_ctlr *ctlr)
2068 struct bnx2fc_interface *interface = fcoe_ctlr_priv(ctlr);
2070 if (interface->enabled == true) {
2072 pr_err(PFX "__bnx2fc_disable: lport not found\n");
2075 interface->enabled = false;
2076 fcoe_ctlr_link_down(ctlr);
2077 fcoe_clean_pending_queue(ctlr->lp);
2084 * Deperecated: Use bnx2fc_enabled()
2086 static int bnx2fc_disable(struct net_device *netdev)
2088 struct bnx2fc_interface *interface;
2089 struct fcoe_ctlr *ctlr;
2093 mutex_lock(&bnx2fc_dev_lock);
2095 interface = bnx2fc_interface_lookup(netdev);
2096 ctlr = bnx2fc_to_ctlr(interface);
2100 pr_err(PFX "bnx2fc_disable: interface not found\n");
2102 rc = __bnx2fc_disable(ctlr);
2104 mutex_unlock(&bnx2fc_dev_lock);
2109 static uint bnx2fc_npiv_create_vports(struct fc_lport *lport,
2110 struct cnic_fc_npiv_tbl *npiv_tbl)
2112 struct fc_vport_identifiers vpid;
2113 uint i, created = 0;
2115 if (npiv_tbl->count > MAX_NPIV_ENTRIES) {
2116 BNX2FC_HBA_DBG(lport, "Exceeded count max of npiv table\n");
2120 /* Sanity check the first entry to make sure it's not 0 */
2121 if (wwn_to_u64(npiv_tbl->wwnn[0]) == 0 &&
2122 wwn_to_u64(npiv_tbl->wwpn[0]) == 0) {
2123 BNX2FC_HBA_DBG(lport, "First NPIV table entries invalid.\n");
2127 vpid.roles = FC_PORT_ROLE_FCP_INITIATOR;
2128 vpid.vport_type = FC_PORTTYPE_NPIV;
2129 vpid.disable = false;
2131 for (i = 0; i < npiv_tbl->count; i++) {
2132 vpid.node_name = wwn_to_u64(npiv_tbl->wwnn[i]);
2133 vpid.port_name = wwn_to_u64(npiv_tbl->wwpn[i]);
2134 scnprintf(vpid.symbolic_name, sizeof(vpid.symbolic_name),
2135 "NPIV[%u]:%016llx-%016llx",
2136 created, vpid.port_name, vpid.node_name);
2137 if (fc_vport_create(lport->host, 0, &vpid))
2140 BNX2FC_HBA_DBG(lport, "Failed to create vport\n");
2146 static int __bnx2fc_enable(struct fcoe_ctlr *ctlr)
2148 struct bnx2fc_interface *interface = fcoe_ctlr_priv(ctlr);
2149 struct bnx2fc_hba *hba;
2150 struct cnic_fc_npiv_tbl *npiv_tbl;
2151 struct fc_lport *lport;
2153 if (interface->enabled == false) {
2155 pr_err(PFX "__bnx2fc_enable: lport not found\n");
2157 } else if (!bnx2fc_link_ok(ctlr->lp)) {
2158 fcoe_ctlr_link_up(ctlr);
2159 interface->enabled = true;
2163 /* Create static NPIV ports if any are contained in NVRAM */
2164 hba = interface->hba;
2179 if (!hba->cnic->get_fc_npiv_tbl)
2182 npiv_tbl = kzalloc(sizeof(struct cnic_fc_npiv_tbl), GFP_KERNEL);
2186 if (hba->cnic->get_fc_npiv_tbl(hba->cnic, npiv_tbl))
2189 bnx2fc_npiv_create_vports(lport, npiv_tbl);
2197 * Deprecated: Use bnx2fc_enabled()
2199 static int bnx2fc_enable(struct net_device *netdev)
2201 struct bnx2fc_interface *interface;
2202 struct fcoe_ctlr *ctlr;
2206 mutex_lock(&bnx2fc_dev_lock);
2208 interface = bnx2fc_interface_lookup(netdev);
2209 ctlr = bnx2fc_to_ctlr(interface);
2212 pr_err(PFX "bnx2fc_enable: interface not found\n");
2214 rc = __bnx2fc_enable(ctlr);
2217 mutex_unlock(&bnx2fc_dev_lock);
2223 * bnx2fc_ctlr_enabled() - Enable or disable an FCoE Controller
2224 * @cdev: The FCoE Controller that is being enabled or disabled
2226 * fcoe_sysfs will ensure that the state of 'enabled' has
2227 * changed, so no checking is necessary here. This routine simply
2228 * calls fcoe_enable or fcoe_disable, both of which are deprecated.
2229 * When those routines are removed the functionality can be merged
2232 static int bnx2fc_ctlr_enabled(struct fcoe_ctlr_device *cdev)
2234 struct fcoe_ctlr *ctlr = fcoe_ctlr_device_priv(cdev);
2236 switch (cdev->enabled) {
2237 case FCOE_CTLR_ENABLED:
2238 return __bnx2fc_enable(ctlr);
2239 case FCOE_CTLR_DISABLED:
2240 return __bnx2fc_disable(ctlr);
2241 case FCOE_CTLR_UNUSED:
2247 enum bnx2fc_create_link_state {
2248 BNX2FC_CREATE_LINK_DOWN,
2249 BNX2FC_CREATE_LINK_UP,
2253 * _bnx2fc_create() - Create bnx2fc FCoE interface
2254 * @netdev : The net_device object the Ethernet interface to create on
2255 * @fip_mode: The FIP mode for this creation
2256 * @link_state: The ctlr link state on creation
2258 * Called from either the libfcoe 'create' module parameter
2259 * via fcoe_create or from fcoe_syfs's ctlr_create file.
2261 * libfcoe's 'create' module parameter is deprecated so some
2262 * consolidation of code can be done when that interface is
2265 * Returns: 0 for success
2267 static int _bnx2fc_create(struct net_device *netdev,
2268 enum fip_mode fip_mode,
2269 enum bnx2fc_create_link_state link_state)
2271 struct fcoe_ctlr_device *cdev;
2272 struct fcoe_ctlr *ctlr;
2273 struct bnx2fc_interface *interface;
2274 struct bnx2fc_hba *hba;
2275 struct net_device *phys_dev = netdev;
2276 struct fc_lport *lport;
2277 struct ethtool_drvinfo drvinfo;
2281 BNX2FC_MISC_DBG("Entered bnx2fc_create\n");
2282 if (fip_mode != FIP_MODE_FABRIC) {
2283 printk(KERN_ERR "fip mode not FABRIC\n");
2289 mutex_lock(&bnx2fc_dev_lock);
2291 if (!try_module_get(THIS_MODULE)) {
2296 /* obtain physical netdev */
2297 if (netdev->priv_flags & IFF_802_1Q_VLAN)
2298 phys_dev = vlan_dev_real_dev(netdev);
2300 /* verify if the physical device is a netxtreme2 device */
2301 if (phys_dev->ethtool_ops && phys_dev->ethtool_ops->get_drvinfo) {
2302 memset(&drvinfo, 0, sizeof(drvinfo));
2303 phys_dev->ethtool_ops->get_drvinfo(phys_dev, &drvinfo);
2304 if (strncmp(drvinfo.driver, "bnx2x", strlen("bnx2x"))) {
2305 printk(KERN_ERR PFX "Not a netxtreme2 device\n");
2310 printk(KERN_ERR PFX "unable to obtain drv_info\n");
2315 /* obtain interface and initialize rest of the structure */
2316 hba = bnx2fc_hba_lookup(phys_dev);
2319 printk(KERN_ERR PFX "bnx2fc_create: hba not found\n");
2323 if (bnx2fc_interface_lookup(netdev)) {
2328 interface = bnx2fc_interface_create(hba, netdev, fip_mode);
2330 printk(KERN_ERR PFX "bnx2fc_interface_create failed\n");
2335 if (netdev->priv_flags & IFF_802_1Q_VLAN) {
2336 vlan_id = vlan_dev_vlan_id(netdev);
2337 interface->vlan_enabled = 1;
2340 ctlr = bnx2fc_to_ctlr(interface);
2341 cdev = fcoe_ctlr_to_ctlr_dev(ctlr);
2342 interface->vlan_id = vlan_id;
2343 interface->tm_timeout = BNX2FC_TM_TIMEOUT;
2345 interface->timer_work_queue =
2346 create_singlethread_workqueue("bnx2fc_timer_wq");
2347 if (!interface->timer_work_queue) {
2348 printk(KERN_ERR PFX "ulp_init could not create timer_wq\n");
2353 lport = bnx2fc_if_create(interface, &cdev->dev, 0);
2355 printk(KERN_ERR PFX "Failed to create interface (%s)\n",
2361 /* Add interface to if_list */
2362 list_add_tail(&interface->list, &if_list);
2364 lport->boot_time = jiffies;
2366 /* Make this master N_port */
2369 if (link_state == BNX2FC_CREATE_LINK_UP)
2370 cdev->enabled = FCOE_CTLR_ENABLED;
2372 cdev->enabled = FCOE_CTLR_DISABLED;
2374 if (link_state == BNX2FC_CREATE_LINK_UP &&
2375 !bnx2fc_link_ok(lport)) {
2376 fcoe_ctlr_link_up(ctlr);
2377 fc_host_port_type(lport->host) = FC_PORTTYPE_NPORT;
2378 set_bit(ADAPTER_STATE_READY, &interface->hba->adapter_state);
2381 BNX2FC_HBA_DBG(lport, "create: START DISC\n");
2382 bnx2fc_start_disc(interface);
2384 if (link_state == BNX2FC_CREATE_LINK_UP)
2385 interface->enabled = true;
2388 * Release from kref_init in bnx2fc_interface_setup, on success
2389 * lport should be holding a reference taken in bnx2fc_if_create
2391 bnx2fc_interface_put(interface);
2392 /* put netdev that was held while calling dev_get_by_name */
2393 mutex_unlock(&bnx2fc_dev_lock);
2398 destroy_workqueue(interface->timer_work_queue);
2400 bnx2fc_net_cleanup(interface);
2401 bnx2fc_interface_put(interface);
2404 module_put(THIS_MODULE);
2406 mutex_unlock(&bnx2fc_dev_lock);
2412 * bnx2fc_create() - Create a bnx2fc interface
2413 * @netdev : The net_device object the Ethernet interface to create on
2414 * @fip_mode: The FIP mode for this creation
2416 * Called from fcoe transport
2418 * Returns: 0 for success
2420 static int bnx2fc_create(struct net_device *netdev, enum fip_mode fip_mode)
2422 return _bnx2fc_create(netdev, fip_mode, BNX2FC_CREATE_LINK_UP);
2426 * bnx2fc_ctlr_alloc() - Allocate a bnx2fc interface from fcoe_sysfs
2427 * @netdev: The net_device to be used by the allocated FCoE Controller
2429 * This routine is called from fcoe_sysfs. It will start the fcoe_ctlr
2430 * in a link_down state. The allows the user an opportunity to configure
2431 * the FCoE Controller from sysfs before enabling the FCoE Controller.
2433 * Creating in with this routine starts the FCoE Controller in Fabric
2434 * mode. The user can change to VN2VN or another mode before enabling.
2436 static int bnx2fc_ctlr_alloc(struct net_device *netdev)
2438 return _bnx2fc_create(netdev, FIP_MODE_FABRIC,
2439 BNX2FC_CREATE_LINK_DOWN);
2443 * bnx2fc_find_hba_for_cnic - maps cnic instance to bnx2fc hba instance
2445 * @cnic: Pointer to cnic device instance
2448 static struct bnx2fc_hba *bnx2fc_find_hba_for_cnic(struct cnic_dev *cnic)
2450 struct bnx2fc_hba *hba;
2452 /* Called with bnx2fc_dev_lock held */
2453 list_for_each_entry(hba, &adapter_list, list) {
2454 if (hba->cnic == cnic)
2460 static struct bnx2fc_interface *bnx2fc_interface_lookup(struct net_device
2463 struct bnx2fc_interface *interface;
2465 /* Called with bnx2fc_dev_lock held */
2466 list_for_each_entry(interface, &if_list, list) {
2467 if (interface->netdev == netdev)
2473 static struct bnx2fc_hba *bnx2fc_hba_lookup(struct net_device
2476 struct bnx2fc_hba *hba;
2478 /* Called with bnx2fc_dev_lock held */
2479 list_for_each_entry(hba, &adapter_list, list) {
2480 if (hba->phys_dev == phys_dev)
2483 printk(KERN_ERR PFX "adapter_lookup: hba NULL\n");
2488 * bnx2fc_ulp_exit - shuts down adapter instance and frees all resources
2490 * @dev cnic device handle
2492 static void bnx2fc_ulp_exit(struct cnic_dev *dev)
2494 struct bnx2fc_hba *hba;
2495 struct bnx2fc_interface *interface, *tmp;
2497 BNX2FC_MISC_DBG("Entered bnx2fc_ulp_exit\n");
2499 if (!test_bit(CNIC_F_BNX2X_CLASS, &dev->flags)) {
2500 printk(KERN_ERR PFX "bnx2fc port check: %s, flags: %lx\n",
2501 dev->netdev->name, dev->flags);
2505 mutex_lock(&bnx2fc_dev_lock);
2506 hba = bnx2fc_find_hba_for_cnic(dev);
2508 printk(KERN_ERR PFX "bnx2fc_ulp_exit: hba not found, dev 0%p\n",
2510 mutex_unlock(&bnx2fc_dev_lock);
2514 list_del_init(&hba->list);
2517 list_for_each_entry_safe(interface, tmp, &if_list, list)
2518 /* destroy not called yet, move to quiesced list */
2519 if (interface->hba == hba)
2520 __bnx2fc_destroy(interface);
2521 mutex_unlock(&bnx2fc_dev_lock);
2523 bnx2fc_ulp_stop(hba);
2524 /* unregister cnic device */
2525 if (test_and_clear_bit(BNX2FC_CNIC_REGISTERED, &hba->reg_with_cnic))
2526 hba->cnic->unregister_device(hba->cnic, CNIC_ULP_FCOE);
2527 bnx2fc_hba_destroy(hba);
2531 * bnx2fc_fcoe_reset - Resets the fcoe
2533 * @shost: shost the reset is from
2537 static int bnx2fc_fcoe_reset(struct Scsi_Host *shost)
2539 struct fc_lport *lport = shost_priv(shost);
2540 fc_lport_reset(lport);
2545 static bool bnx2fc_match(struct net_device *netdev)
2547 struct net_device *phys_dev = netdev;
2549 mutex_lock(&bnx2fc_dev_lock);
2550 if (netdev->priv_flags & IFF_802_1Q_VLAN)
2551 phys_dev = vlan_dev_real_dev(netdev);
2553 if (bnx2fc_hba_lookup(phys_dev)) {
2554 mutex_unlock(&bnx2fc_dev_lock);
2558 mutex_unlock(&bnx2fc_dev_lock);
2563 static struct fcoe_transport bnx2fc_transport = {
2566 .list = LIST_HEAD_INIT(bnx2fc_transport.list),
2567 .alloc = bnx2fc_ctlr_alloc,
2568 .match = bnx2fc_match,
2569 .create = bnx2fc_create,
2570 .destroy = bnx2fc_destroy,
2571 .enable = bnx2fc_enable,
2572 .disable = bnx2fc_disable,
2576 * bnx2fc_percpu_thread_create - Create a receive thread for an
2579 * @cpu: cpu index for the online cpu
2581 static void bnx2fc_percpu_thread_create(unsigned int cpu)
2583 struct bnx2fc_percpu_s *p;
2584 struct task_struct *thread;
2586 p = &per_cpu(bnx2fc_percpu, cpu);
2588 thread = kthread_create_on_node(bnx2fc_percpu_io_thread,
2589 (void *)p, cpu_to_node(cpu),
2590 "bnx2fc_thread/%d", cpu);
2591 /* bind thread to the cpu */
2592 if (likely(!IS_ERR(thread))) {
2593 kthread_bind(thread, cpu);
2594 p->iothread = thread;
2595 wake_up_process(thread);
2599 static void bnx2fc_percpu_thread_destroy(unsigned int cpu)
2601 struct bnx2fc_percpu_s *p;
2602 struct task_struct *thread;
2603 struct bnx2fc_work *work, *tmp;
2605 BNX2FC_MISC_DBG("destroying io thread for CPU %d\n", cpu);
2607 /* Prevent any new work from being queued for this CPU */
2608 p = &per_cpu(bnx2fc_percpu, cpu);
2609 spin_lock_bh(&p->fp_work_lock);
2610 thread = p->iothread;
2614 /* Free all work in the list */
2615 list_for_each_entry_safe(work, tmp, &p->work_list, list) {
2616 list_del_init(&work->list);
2617 bnx2fc_process_cq_compl(work->tgt, work->wqe);
2621 spin_unlock_bh(&p->fp_work_lock);
2624 kthread_stop(thread);
2628 * bnx2fc_cpu_callback - Handler for CPU hotplug events
2630 * @nfb: The callback data block
2631 * @action: The event triggering the callback
2632 * @hcpu: The index of the CPU that the event is for
2634 * This creates or destroys per-CPU data for fcoe
2636 * Returns NOTIFY_OK always.
2638 static int bnx2fc_cpu_callback(struct notifier_block *nfb,
2639 unsigned long action, void *hcpu)
2641 unsigned cpu = (unsigned long)hcpu;
2645 case CPU_ONLINE_FROZEN:
2646 printk(PFX "CPU %x online: Create Rx thread\n", cpu);
2647 bnx2fc_percpu_thread_create(cpu);
2650 case CPU_DEAD_FROZEN:
2651 printk(PFX "CPU %x offline: Remove Rx thread\n", cpu);
2652 bnx2fc_percpu_thread_destroy(cpu);
2660 static int bnx2fc_slave_configure(struct scsi_device *sdev)
2662 if (!bnx2fc_queue_depth)
2665 scsi_change_queue_depth(sdev, bnx2fc_queue_depth);
2670 * bnx2fc_mod_init - module init entry point
2672 * Initialize driver wide global data structures, and register
2675 static int __init bnx2fc_mod_init(void)
2677 struct fcoe_percpu_s *bg;
2678 struct task_struct *l2_thread;
2680 unsigned int cpu = 0;
2681 struct bnx2fc_percpu_s *p;
2683 printk(KERN_INFO PFX "%s", version);
2685 /* register as a fcoe transport */
2686 rc = fcoe_transport_attach(&bnx2fc_transport);
2688 printk(KERN_ERR "failed to register an fcoe transport, check "
2689 "if libfcoe is loaded\n");
2693 INIT_LIST_HEAD(&adapter_list);
2694 INIT_LIST_HEAD(&if_list);
2695 mutex_init(&bnx2fc_dev_lock);
2698 /* Attach FC transport template */
2699 rc = bnx2fc_attach_transport();
2703 bnx2fc_wq = alloc_workqueue("bnx2fc", 0, 0);
2709 bg = &bnx2fc_global;
2710 skb_queue_head_init(&bg->fcoe_rx_list);
2711 l2_thread = kthread_create(bnx2fc_l2_rcv_thread,
2713 "bnx2fc_l2_thread");
2714 if (IS_ERR(l2_thread)) {
2715 rc = PTR_ERR(l2_thread);
2718 wake_up_process(l2_thread);
2719 spin_lock_bh(&bg->fcoe_rx_list.lock);
2720 bg->kthread = l2_thread;
2721 spin_unlock_bh(&bg->fcoe_rx_list.lock);
2723 for_each_possible_cpu(cpu) {
2724 p = &per_cpu(bnx2fc_percpu, cpu);
2725 INIT_LIST_HEAD(&p->work_list);
2726 spin_lock_init(&p->fp_work_lock);
2729 cpu_notifier_register_begin();
2731 for_each_online_cpu(cpu) {
2732 bnx2fc_percpu_thread_create(cpu);
2735 /* Initialize per CPU interrupt thread */
2736 __register_hotcpu_notifier(&bnx2fc_cpu_notifier);
2738 cpu_notifier_register_done();
2740 cnic_register_driver(CNIC_ULP_FCOE, &bnx2fc_cnic_cb);
2745 destroy_workqueue(bnx2fc_wq);
2747 bnx2fc_release_transport();
2749 fcoe_transport_detach(&bnx2fc_transport);
2754 static void __exit bnx2fc_mod_exit(void)
2756 LIST_HEAD(to_be_deleted);
2757 struct bnx2fc_hba *hba, *next;
2758 struct fcoe_percpu_s *bg;
2759 struct task_struct *l2_thread;
2760 struct sk_buff *skb;
2761 unsigned int cpu = 0;
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 cpu_notifier_register_begin();
2804 /* Destroy per cpu threads */
2805 for_each_online_cpu(cpu) {
2806 bnx2fc_percpu_thread_destroy(cpu);
2809 __unregister_hotcpu_notifier(&bnx2fc_cpu_notifier);
2811 cpu_notifier_register_done();
2813 destroy_workqueue(bnx2fc_wq);
2815 * detach from scsi transport
2816 * must happen after all destroys are done
2818 bnx2fc_release_transport();
2820 /* detach from fcoe transport */
2821 fcoe_transport_detach(&bnx2fc_transport);
2824 module_init(bnx2fc_mod_init);
2825 module_exit(bnx2fc_mod_exit);
2827 static struct fcoe_sysfs_function_template bnx2fc_fcoe_sysfs_templ = {
2828 .set_fcoe_ctlr_enabled = bnx2fc_ctlr_enabled,
2829 .get_fcoe_ctlr_link_fail = fcoe_ctlr_get_lesb,
2830 .get_fcoe_ctlr_vlink_fail = fcoe_ctlr_get_lesb,
2831 .get_fcoe_ctlr_miss_fka = fcoe_ctlr_get_lesb,
2832 .get_fcoe_ctlr_symb_err = fcoe_ctlr_get_lesb,
2833 .get_fcoe_ctlr_err_block = fcoe_ctlr_get_lesb,
2834 .get_fcoe_ctlr_fcs_error = fcoe_ctlr_get_lesb,
2836 .get_fcoe_fcf_selected = fcoe_fcf_get_selected,
2837 .get_fcoe_fcf_vlan_id = bnx2fc_fcf_get_vlan_id,
2840 static struct fc_function_template bnx2fc_transport_function = {
2841 .show_host_node_name = 1,
2842 .show_host_port_name = 1,
2843 .show_host_supported_classes = 1,
2844 .show_host_supported_fc4s = 1,
2845 .show_host_active_fc4s = 1,
2846 .show_host_maxframe_size = 1,
2848 .show_host_port_id = 1,
2849 .show_host_supported_speeds = 1,
2850 .get_host_speed = fc_get_host_speed,
2851 .show_host_speed = 1,
2852 .show_host_port_type = 1,
2853 .get_host_port_state = fc_get_host_port_state,
2854 .show_host_port_state = 1,
2855 .show_host_symbolic_name = 1,
2857 .dd_fcrport_size = (sizeof(struct fc_rport_libfc_priv) +
2858 sizeof(struct bnx2fc_rport)),
2859 .show_rport_maxframe_size = 1,
2860 .show_rport_supported_classes = 1,
2862 .show_host_fabric_name = 1,
2863 .show_starget_node_name = 1,
2864 .show_starget_port_name = 1,
2865 .show_starget_port_id = 1,
2866 .set_rport_dev_loss_tmo = fc_set_rport_loss_tmo,
2867 .show_rport_dev_loss_tmo = 1,
2868 .get_fc_host_stats = bnx2fc_get_host_stats,
2870 .issue_fc_host_lip = bnx2fc_fcoe_reset,
2872 .terminate_rport_io = fc_rport_terminate_io,
2874 .vport_create = bnx2fc_vport_create,
2875 .vport_delete = bnx2fc_vport_destroy,
2876 .vport_disable = bnx2fc_vport_disable,
2877 .bsg_request = fc_lport_bsg_request,
2880 static struct fc_function_template bnx2fc_vport_xport_function = {
2881 .show_host_node_name = 1,
2882 .show_host_port_name = 1,
2883 .show_host_supported_classes = 1,
2884 .show_host_supported_fc4s = 1,
2885 .show_host_active_fc4s = 1,
2886 .show_host_maxframe_size = 1,
2888 .show_host_port_id = 1,
2889 .show_host_supported_speeds = 1,
2890 .get_host_speed = fc_get_host_speed,
2891 .show_host_speed = 1,
2892 .show_host_port_type = 1,
2893 .get_host_port_state = fc_get_host_port_state,
2894 .show_host_port_state = 1,
2895 .show_host_symbolic_name = 1,
2897 .dd_fcrport_size = (sizeof(struct fc_rport_libfc_priv) +
2898 sizeof(struct bnx2fc_rport)),
2899 .show_rport_maxframe_size = 1,
2900 .show_rport_supported_classes = 1,
2902 .show_host_fabric_name = 1,
2903 .show_starget_node_name = 1,
2904 .show_starget_port_name = 1,
2905 .show_starget_port_id = 1,
2906 .set_rport_dev_loss_tmo = fc_set_rport_loss_tmo,
2907 .show_rport_dev_loss_tmo = 1,
2908 .get_fc_host_stats = fc_get_host_stats,
2909 .issue_fc_host_lip = bnx2fc_fcoe_reset,
2910 .terminate_rport_io = fc_rport_terminate_io,
2911 .bsg_request = fc_lport_bsg_request,
2915 * Additional scsi_host attributes.
2918 bnx2fc_tm_timeout_show(struct device *dev, struct device_attribute *attr,
2921 struct Scsi_Host *shost = class_to_shost(dev);
2922 struct fc_lport *lport = shost_priv(shost);
2923 struct fcoe_port *port = lport_priv(lport);
2924 struct bnx2fc_interface *interface = port->priv;
2926 sprintf(buf, "%u\n", interface->tm_timeout);
2931 bnx2fc_tm_timeout_store(struct device *dev,
2932 struct device_attribute *attr, const char *buf, size_t count)
2934 struct Scsi_Host *shost = class_to_shost(dev);
2935 struct fc_lport *lport = shost_priv(shost);
2936 struct fcoe_port *port = lport_priv(lport);
2937 struct bnx2fc_interface *interface = port->priv;
2940 rval = kstrtouint(buf, 10, &val);
2946 interface->tm_timeout = (u8)val;
2950 static DEVICE_ATTR(tm_timeout, S_IRUGO|S_IWUSR, bnx2fc_tm_timeout_show,
2951 bnx2fc_tm_timeout_store);
2953 static struct device_attribute *bnx2fc_host_attrs[] = {
2954 &dev_attr_tm_timeout,
2959 * scsi_host_template structure used while registering with SCSI-ml
2961 static struct scsi_host_template bnx2fc_shost_template = {
2962 .module = THIS_MODULE,
2963 .name = "QLogic Offload FCoE Initiator",
2964 .queuecommand = bnx2fc_queuecommand,
2965 .eh_abort_handler = bnx2fc_eh_abort, /* abts */
2966 .eh_device_reset_handler = bnx2fc_eh_device_reset, /* lun reset */
2967 .eh_target_reset_handler = bnx2fc_eh_target_reset, /* tgt reset */
2968 .eh_host_reset_handler = fc_eh_host_reset,
2969 .slave_alloc = fc_slave_alloc,
2970 .change_queue_depth = scsi_change_queue_depth,
2973 .use_clustering = ENABLE_CLUSTERING,
2974 .sg_tablesize = BNX2FC_MAX_BDS_PER_CMD,
2975 .max_sectors = 1024,
2976 .track_queue_depth = 1,
2977 .slave_configure = bnx2fc_slave_configure,
2978 .shost_attrs = bnx2fc_host_attrs,
2981 static struct libfc_function_template bnx2fc_libfc_fcn_templ = {
2982 .frame_send = bnx2fc_xmit,
2983 .elsct_send = bnx2fc_elsct_send,
2984 .fcp_abort_io = bnx2fc_abort_io,
2985 .fcp_cleanup = bnx2fc_cleanup,
2986 .get_lesb = fcoe_get_lesb,
2987 .rport_event_callback = bnx2fc_rport_event_handler,
2991 * bnx2fc_cnic_cb - global template of bnx2fc - cnic driver interface
2992 * structure carrying callback function pointers
2994 static struct cnic_ulp_ops bnx2fc_cnic_cb = {
2995 .owner = THIS_MODULE,
2996 .cnic_init = bnx2fc_ulp_init,
2997 .cnic_exit = bnx2fc_ulp_exit,
2998 .cnic_start = bnx2fc_ulp_start,
2999 .cnic_stop = bnx2fc_ulp_stop,
3000 .indicate_kcqes = bnx2fc_indicate_kcqe,
3001 .indicate_netevent = bnx2fc_indicate_netevent,
3002 .cnic_get_stats = bnx2fc_ulp_get_stats,