1 /* bnx2fc_fcoe.c: QLogic Linux FCoE offload driver.
2 * This file contains the code that interacts with libfc, libfcoe,
3 * cnic modules to create FCoE instances, send/receive non-offloaded
4 * FIP/FCoE packets, listen to link events etc.
6 * Copyright (c) 2008-2013 Broadcom Corporation
7 * Copyright (c) 2014-2016 QLogic Corporation
8 * Copyright (c) 2016-2017 Cavium Inc.
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation.
19 #include <linux/ethtool.h>
21 static struct list_head adapter_list;
22 static struct list_head if_list;
23 static u32 adapter_count;
24 static DEFINE_MUTEX(bnx2fc_dev_lock);
25 DEFINE_PER_CPU(struct bnx2fc_percpu_s, bnx2fc_percpu);
27 #define DRV_MODULE_NAME "bnx2fc"
28 #define DRV_MODULE_VERSION BNX2FC_VERSION
29 #define DRV_MODULE_RELDATE "October 15, 2015"
32 static char version[] =
33 "QLogic FCoE Driver " DRV_MODULE_NAME \
34 " v" DRV_MODULE_VERSION " (" DRV_MODULE_RELDATE ")\n";
38 MODULE_DESCRIPTION("QLogic FCoE Driver");
39 MODULE_LICENSE("GPL");
40 MODULE_VERSION(DRV_MODULE_VERSION);
42 #define BNX2FC_MAX_QUEUE_DEPTH 256
43 #define BNX2FC_MIN_QUEUE_DEPTH 32
44 #define FCOE_WORD_TO_BYTE 4
46 static struct scsi_transport_template *bnx2fc_transport_template;
47 static struct scsi_transport_template *bnx2fc_vport_xport_template;
49 struct workqueue_struct *bnx2fc_wq;
51 /* bnx2fc structure needs only one instance of the fcoe_percpu_s structure.
52 * Here the io threads are per cpu but the l2 thread is just one
54 struct fcoe_percpu_s bnx2fc_global;
55 static DEFINE_SPINLOCK(bnx2fc_global_lock);
57 static struct cnic_ulp_ops bnx2fc_cnic_cb;
58 static struct libfc_function_template bnx2fc_libfc_fcn_templ;
59 static struct scsi_host_template bnx2fc_shost_template;
60 static struct fc_function_template bnx2fc_transport_function;
61 static struct fcoe_sysfs_function_template bnx2fc_fcoe_sysfs_templ;
62 static struct fc_function_template bnx2fc_vport_xport_function;
63 static int bnx2fc_create(struct net_device *netdev, enum fip_mode fip_mode);
64 static void __bnx2fc_destroy(struct bnx2fc_interface *interface);
65 static int bnx2fc_destroy(struct net_device *net_device);
66 static int bnx2fc_enable(struct net_device *netdev);
67 static int bnx2fc_disable(struct net_device *netdev);
69 /* fcoe_syfs control interface handlers */
70 static int bnx2fc_ctlr_alloc(struct net_device *netdev);
71 static int bnx2fc_ctlr_enabled(struct fcoe_ctlr_device *cdev);
73 static void bnx2fc_recv_frame(struct sk_buff *skb);
75 static void bnx2fc_start_disc(struct bnx2fc_interface *interface);
76 static int bnx2fc_shost_config(struct fc_lport *lport, struct device *dev);
77 static int bnx2fc_lport_config(struct fc_lport *lport);
78 static int bnx2fc_em_config(struct fc_lport *lport, struct bnx2fc_hba *hba);
79 static int bnx2fc_bind_adapter_devices(struct bnx2fc_hba *hba);
80 static void bnx2fc_unbind_adapter_devices(struct bnx2fc_hba *hba);
81 static int bnx2fc_bind_pcidev(struct bnx2fc_hba *hba);
82 static void bnx2fc_unbind_pcidev(struct bnx2fc_hba *hba);
83 static struct fc_lport *bnx2fc_if_create(struct bnx2fc_interface *interface,
84 struct device *parent, int npiv);
85 static void bnx2fc_destroy_work(struct work_struct *work);
87 static struct bnx2fc_hba *bnx2fc_hba_lookup(struct net_device *phys_dev);
88 static struct bnx2fc_interface *bnx2fc_interface_lookup(struct net_device
90 static inline void bnx2fc_interface_put(struct bnx2fc_interface *interface);
91 static struct bnx2fc_hba *bnx2fc_find_hba_for_cnic(struct cnic_dev *cnic);
93 static int bnx2fc_fw_init(struct bnx2fc_hba *hba);
94 static void bnx2fc_fw_destroy(struct bnx2fc_hba *hba);
96 static void bnx2fc_port_shutdown(struct fc_lport *lport);
97 static void bnx2fc_stop(struct bnx2fc_interface *interface);
98 static int __init bnx2fc_mod_init(void);
99 static void __exit bnx2fc_mod_exit(void);
101 unsigned int bnx2fc_debug_level;
102 module_param_named(debug_logging, bnx2fc_debug_level, int, S_IRUGO|S_IWUSR);
103 MODULE_PARM_DESC(debug_logging,
104 "Option to enable extended logging,\n"
105 "\t\tDefault is 0 - no logging.\n"
106 "\t\t0x01 - SCSI cmd error, cleanup.\n"
107 "\t\t0x02 - Session setup, cleanup, etc.\n"
108 "\t\t0x04 - lport events, link, mtu, etc.\n"
109 "\t\t0x08 - ELS logs.\n"
110 "\t\t0x10 - fcoe L2 fame related logs.\n"
111 "\t\t0xff - LOG all messages.");
113 static uint bnx2fc_devloss_tmo;
114 module_param_named(devloss_tmo, bnx2fc_devloss_tmo, uint, S_IRUGO);
115 MODULE_PARM_DESC(devloss_tmo, " Change devloss_tmo for the remote ports "
116 "attached via bnx2fc.");
118 static uint bnx2fc_max_luns = BNX2FC_MAX_LUN;
119 module_param_named(max_luns, bnx2fc_max_luns, uint, S_IRUGO);
120 MODULE_PARM_DESC(max_luns, " Change the default max_lun per SCSI host. Default "
123 static uint bnx2fc_queue_depth;
124 module_param_named(queue_depth, bnx2fc_queue_depth, uint, S_IRUGO);
125 MODULE_PARM_DESC(queue_depth, " Change the default queue depth of SCSI devices "
126 "attached via bnx2fc.");
128 static uint bnx2fc_log_fka;
129 module_param_named(log_fka, bnx2fc_log_fka, uint, S_IRUGO|S_IWUSR);
130 MODULE_PARM_DESC(log_fka, " Print message to kernel log when fcoe is "
131 "initiating a FIP keep alive when debug logging is enabled.");
133 static inline struct net_device *bnx2fc_netdev(const struct fc_lport *lport)
135 return ((struct bnx2fc_interface *)
136 ((struct fcoe_port *)lport_priv(lport))->priv)->netdev;
139 static void bnx2fc_fcf_get_vlan_id(struct fcoe_fcf_device *fcf_dev)
141 struct fcoe_ctlr_device *ctlr_dev =
142 fcoe_fcf_dev_to_ctlr_dev(fcf_dev);
143 struct fcoe_ctlr *ctlr = fcoe_ctlr_device_priv(ctlr_dev);
144 struct bnx2fc_interface *fcoe = fcoe_ctlr_priv(ctlr);
146 fcf_dev->vlan_id = fcoe->vlan_id;
149 static void bnx2fc_clean_rx_queue(struct fc_lport *lp)
151 struct fcoe_percpu_s *bg;
152 struct fcoe_rcv_info *fr;
153 struct sk_buff_head *list;
154 struct sk_buff *skb, *next;
157 spin_lock_bh(&bg->fcoe_rx_list.lock);
158 list = &bg->fcoe_rx_list;
159 skb_queue_walk_safe(list, skb, next) {
160 fr = fcoe_dev_from_skb(skb);
161 if (fr->fr_dev == lp) {
162 __skb_unlink(skb, list);
166 spin_unlock_bh(&bg->fcoe_rx_list.lock);
169 int bnx2fc_get_paged_crc_eof(struct sk_buff *skb, int tlen)
172 spin_lock(&bnx2fc_global_lock);
173 rc = fcoe_get_paged_crc_eof(skb, tlen, &bnx2fc_global);
174 spin_unlock(&bnx2fc_global_lock);
179 static void bnx2fc_abort_io(struct fc_lport *lport)
182 * This function is no-op for bnx2fc, but we do
183 * not want to leave it as NULL either, as libfc
184 * can call the default function which is
189 static void bnx2fc_cleanup(struct fc_lport *lport)
191 struct fcoe_port *port = lport_priv(lport);
192 struct bnx2fc_interface *interface = port->priv;
193 struct bnx2fc_hba *hba = interface->hba;
194 struct bnx2fc_rport *tgt;
197 BNX2FC_MISC_DBG("Entered %s\n", __func__);
198 mutex_lock(&hba->hba_mutex);
199 spin_lock_bh(&hba->hba_lock);
200 for (i = 0; i < BNX2FC_NUM_MAX_SESS; i++) {
201 tgt = hba->tgt_ofld_list[i];
203 /* Cleanup IOs belonging to requested vport */
204 if (tgt->port == port) {
205 spin_unlock_bh(&hba->hba_lock);
206 BNX2FC_TGT_DBG(tgt, "flush/cleanup\n");
207 bnx2fc_flush_active_ios(tgt);
208 spin_lock_bh(&hba->hba_lock);
212 spin_unlock_bh(&hba->hba_lock);
213 mutex_unlock(&hba->hba_mutex);
216 static int bnx2fc_xmit_l2_frame(struct bnx2fc_rport *tgt,
219 struct fc_rport_priv *rdata = tgt->rdata;
220 struct fc_frame_header *fh;
223 fh = fc_frame_header_get(fp);
224 BNX2FC_TGT_DBG(tgt, "Xmit L2 frame rport = 0x%x, oxid = 0x%x, "
225 "r_ctl = 0x%x\n", rdata->ids.port_id,
226 ntohs(fh->fh_ox_id), fh->fh_r_ctl);
227 if ((fh->fh_type == FC_TYPE_ELS) &&
228 (fh->fh_r_ctl == FC_RCTL_ELS_REQ)) {
230 switch (fc_frame_payload_op(fp)) {
232 rc = bnx2fc_send_adisc(tgt, fp);
235 rc = bnx2fc_send_logo(tgt, fp);
238 rc = bnx2fc_send_rls(tgt, fp);
243 } else if ((fh->fh_type == FC_TYPE_BLS) &&
244 (fh->fh_r_ctl == FC_RCTL_BA_ABTS))
245 BNX2FC_TGT_DBG(tgt, "ABTS frame\n");
247 BNX2FC_TGT_DBG(tgt, "Send L2 frame type 0x%x "
248 "rctl 0x%x thru non-offload path\n",
249 fh->fh_type, fh->fh_r_ctl);
259 * bnx2fc_xmit - bnx2fc's FCoE frame transmit function
261 * @lport: the associated local port
262 * @fp: the fc_frame to be transmitted
264 static int bnx2fc_xmit(struct fc_lport *lport, struct fc_frame *fp)
267 struct fcoe_crc_eof *cp;
269 struct fc_frame_header *fh;
270 struct bnx2fc_interface *interface;
271 struct fcoe_ctlr *ctlr;
272 struct bnx2fc_hba *hba;
273 struct fcoe_port *port;
275 struct bnx2fc_rport *tgt;
276 struct fc_stats *stats;
279 unsigned int hlen, tlen, elen;
282 port = (struct fcoe_port *)lport_priv(lport);
283 interface = port->priv;
284 ctlr = bnx2fc_to_ctlr(interface);
285 hba = interface->hba;
287 fh = fc_frame_header_get(fp);
290 if (!lport->link_up) {
291 BNX2FC_HBA_DBG(lport, "bnx2fc_xmit link down\n");
296 if (unlikely(fh->fh_r_ctl == FC_RCTL_ELS_REQ)) {
297 if (!ctlr->sel_fcf) {
298 BNX2FC_HBA_DBG(lport, "FCF not selected yet!\n");
302 if (fcoe_ctlr_els_send(ctlr, lport, skb))
310 * Snoop the frame header to check if the frame is for
311 * an offloaded session
314 * tgt_ofld_list access is synchronized using
315 * both hba mutex and hba lock. Atleast hba mutex or
316 * hba lock needs to be held for read access.
319 spin_lock_bh(&hba->hba_lock);
320 tgt = bnx2fc_tgt_lookup(port, ntoh24(fh->fh_d_id));
321 if (tgt && (test_bit(BNX2FC_FLAG_SESSION_READY, &tgt->flags))) {
322 /* This frame is for offloaded session */
323 BNX2FC_HBA_DBG(lport, "xmit: Frame is for offloaded session "
324 "port_id = 0x%x\n", ntoh24(fh->fh_d_id));
325 spin_unlock_bh(&hba->hba_lock);
326 rc = bnx2fc_xmit_l2_frame(tgt, fp);
332 spin_unlock_bh(&hba->hba_lock);
335 elen = sizeof(struct ethhdr);
336 hlen = sizeof(struct fcoe_hdr);
337 tlen = sizeof(struct fcoe_crc_eof);
338 wlen = (skb->len - tlen + sizeof(crc)) / FCOE_WORD_TO_BYTE;
340 skb->ip_summed = CHECKSUM_NONE;
341 crc = fcoe_fc_crc(fp);
343 /* copy port crc and eof to the skb buff */
344 if (skb_is_nonlinear(skb)) {
346 if (bnx2fc_get_paged_crc_eof(skb, tlen)) {
350 frag = &skb_shinfo(skb)->frags[skb_shinfo(skb)->nr_frags - 1];
351 cp = kmap_atomic(skb_frag_page(frag)) + skb_frag_off(frag);
353 cp = skb_put(skb, tlen);
356 memset(cp, 0, sizeof(*cp));
358 cp->fcoe_crc32 = cpu_to_le32(~crc);
359 if (skb_is_nonlinear(skb)) {
364 /* adjust skb network/transport offsets to match mac/fcoe/port */
365 skb_push(skb, elen + hlen);
366 skb_reset_mac_header(skb);
367 skb_reset_network_header(skb);
369 skb->protocol = htons(ETH_P_FCOE);
370 skb->dev = interface->netdev;
372 /* fill up mac and fcoe headers */
374 eh->h_proto = htons(ETH_P_FCOE);
376 fc_fcoe_set_mac(eh->h_dest, fh->fh_d_id);
378 /* insert GW address */
379 memcpy(eh->h_dest, ctlr->dest_addr, ETH_ALEN);
381 if (unlikely(ctlr->flogi_oxid != FC_XID_UNKNOWN))
382 memcpy(eh->h_source, ctlr->ctl_src_addr, ETH_ALEN);
384 memcpy(eh->h_source, port->data_src_addr, ETH_ALEN);
386 hp = (struct fcoe_hdr *)(eh + 1);
387 memset(hp, 0, sizeof(*hp));
389 FC_FCOE_ENCAPS_VER(hp, FC_FCOE_VER);
392 /* fcoe lso, mss is in max_payload which is non-zero for FCP data */
393 if (lport->seq_offload && fr_max_payload(fp)) {
394 skb_shinfo(skb)->gso_type = SKB_GSO_FCOE;
395 skb_shinfo(skb)->gso_size = fr_max_payload(fp);
397 skb_shinfo(skb)->gso_type = 0;
398 skb_shinfo(skb)->gso_size = 0;
402 stats = per_cpu_ptr(lport->stats, get_cpu());
404 stats->TxWords += wlen;
407 /* send down to lld */
409 if (port->fcoe_pending_queue.qlen)
410 fcoe_check_wait_queue(lport, skb);
411 else if (fcoe_start_io(skb))
412 fcoe_check_wait_queue(lport, skb);
418 * bnx2fc_rcv - This is bnx2fc's receive function called by NET_RX_SOFTIRQ
420 * @skb: the receive socket buffer
421 * @dev: associated net device
423 * @olddev: last device
425 * This function receives the packet and builds FC frame and passes it up
427 static int bnx2fc_rcv(struct sk_buff *skb, struct net_device *dev,
428 struct packet_type *ptype, struct net_device *olddev)
430 struct fc_lport *lport;
431 struct bnx2fc_interface *interface;
432 struct fcoe_ctlr *ctlr;
433 struct fcoe_rcv_info *fr;
434 struct fcoe_percpu_s *bg;
435 struct sk_buff *tmp_skb;
437 interface = container_of(ptype, struct bnx2fc_interface,
439 ctlr = bnx2fc_to_ctlr(interface);
442 if (unlikely(lport == NULL)) {
443 printk(KERN_ERR PFX "bnx2fc_rcv: lport is NULL\n");
447 tmp_skb = skb_share_check(skb, GFP_ATOMIC);
453 if (unlikely(eth_hdr(skb)->h_proto != htons(ETH_P_FCOE))) {
454 printk(KERN_ERR PFX "bnx2fc_rcv: Wrong FC type frame\n");
459 * Check for minimum frame length, and make sure required FCoE
460 * and FC headers are pulled into the linear data area.
462 if (unlikely((skb->len < FCOE_MIN_FRAME) ||
463 !pskb_may_pull(skb, FCOE_HEADER_LEN)))
466 skb_set_transport_header(skb, sizeof(struct fcoe_hdr));
468 fr = fcoe_dev_from_skb(skb);
472 spin_lock(&bg->fcoe_rx_list.lock);
474 __skb_queue_tail(&bg->fcoe_rx_list, skb);
475 if (bg->fcoe_rx_list.qlen == 1)
476 wake_up_process(bg->kthread);
478 spin_unlock(&bg->fcoe_rx_list.lock);
486 static int bnx2fc_l2_rcv_thread(void *arg)
488 struct fcoe_percpu_s *bg = arg;
491 set_user_nice(current, MIN_NICE);
492 set_current_state(TASK_INTERRUPTIBLE);
493 while (!kthread_should_stop()) {
495 spin_lock_bh(&bg->fcoe_rx_list.lock);
496 while ((skb = __skb_dequeue(&bg->fcoe_rx_list)) != NULL) {
497 spin_unlock_bh(&bg->fcoe_rx_list.lock);
498 bnx2fc_recv_frame(skb);
499 spin_lock_bh(&bg->fcoe_rx_list.lock);
501 __set_current_state(TASK_INTERRUPTIBLE);
502 spin_unlock_bh(&bg->fcoe_rx_list.lock);
504 __set_current_state(TASK_RUNNING);
509 static void bnx2fc_recv_frame(struct sk_buff *skb)
512 struct fc_lport *lport;
513 struct fcoe_rcv_info *fr;
514 struct fc_stats *stats;
515 struct fc_frame_header *fh;
516 struct fcoe_crc_eof crc_eof;
518 struct fc_lport *vn_port;
519 struct fcoe_port *port, *phys_port;
523 struct bnx2fc_interface *interface;
524 struct fcoe_ctlr *ctlr;
526 fr = fcoe_dev_from_skb(skb);
528 if (unlikely(lport == NULL)) {
529 printk(KERN_ERR PFX "Invalid lport struct\n");
534 if (skb_is_nonlinear(skb))
536 mac = eth_hdr(skb)->h_source;
537 dest_mac = eth_hdr(skb)->h_dest;
539 /* Pull the header */
540 hp = (struct fcoe_hdr *) skb_network_header(skb);
541 fh = (struct fc_frame_header *) skb_transport_header(skb);
542 skb_pull(skb, sizeof(struct fcoe_hdr));
543 fr_len = skb->len - sizeof(struct fcoe_crc_eof);
545 fp = (struct fc_frame *)skb;
548 fr_sof(fp) = hp->fcoe_sof;
549 if (skb_copy_bits(skb, fr_len, &crc_eof, sizeof(crc_eof))) {
553 fr_eof(fp) = crc_eof.fcoe_eof;
554 fr_crc(fp) = crc_eof.fcoe_crc32;
555 if (pskb_trim(skb, fr_len)) {
560 phys_port = lport_priv(lport);
561 interface = phys_port->priv;
562 ctlr = bnx2fc_to_ctlr(interface);
564 fh = fc_frame_header_get(fp);
566 if (ntoh24(&dest_mac[3]) != ntoh24(fh->fh_d_id)) {
567 BNX2FC_HBA_DBG(lport, "FC frame d_id mismatch with MAC %pM.\n",
573 vn_port = fc_vport_id_lookup(lport, ntoh24(fh->fh_d_id));
575 port = lport_priv(vn_port);
576 if (!ether_addr_equal(port->data_src_addr, dest_mac)) {
577 BNX2FC_HBA_DBG(lport, "fpma mismatch\n");
583 if (!ether_addr_equal(mac, ctlr->dest_addr)) {
584 BNX2FC_HBA_DBG(lport, "Wrong source address: mac:%pM dest_addr:%pM.\n",
585 mac, ctlr->dest_addr);
590 if (fh->fh_r_ctl == FC_RCTL_DD_SOL_DATA &&
591 fh->fh_type == FC_TYPE_FCP) {
592 /* Drop FCP data. We dont this in L2 path */
596 if (fh->fh_r_ctl == FC_RCTL_ELS_REQ &&
597 fh->fh_type == FC_TYPE_ELS) {
598 switch (fc_frame_payload_op(fp)) {
600 if (ntoh24(fh->fh_s_id) == FC_FID_FLOGI) {
601 /* drop non-FIP LOGO */
609 if (fh->fh_r_ctl == FC_RCTL_BA_ABTS) {
610 /* Drop incoming ABTS */
616 * If the destination ID from the frame header does not match what we
617 * have on record for lport and the search for a NPIV port came up
618 * empty then this is not addressed to our port so simply drop it.
620 if (lport->port_id != ntoh24(fh->fh_d_id) && !vn_port) {
621 BNX2FC_HBA_DBG(lport, "Dropping frame due to destination mismatch: lport->port_id=%x fh->d_id=%x.\n",
622 lport->port_id, ntoh24(fh->fh_d_id));
627 stats = per_cpu_ptr(lport->stats, smp_processor_id());
629 stats->RxWords += fr_len / FCOE_WORD_TO_BYTE;
631 if (le32_to_cpu(fr_crc(fp)) !=
632 ~crc32(~0, skb->data, fr_len)) {
633 if (stats->InvalidCRCCount < 5)
634 printk(KERN_WARNING PFX "dropping frame with "
636 stats->InvalidCRCCount++;
640 fc_exch_recv(lport, fp);
644 * bnx2fc_percpu_io_thread - thread per cpu for ios
646 * @arg: ptr to bnx2fc_percpu_info structure
648 static int bnx2fc_percpu_io_thread(void *arg)
650 struct bnx2fc_percpu_s *p = arg;
651 struct bnx2fc_work *work, *tmp;
652 LIST_HEAD(work_list);
654 set_user_nice(current, MIN_NICE);
655 set_current_state(TASK_INTERRUPTIBLE);
656 while (!kthread_should_stop()) {
658 spin_lock_bh(&p->fp_work_lock);
659 while (!list_empty(&p->work_list)) {
660 list_splice_init(&p->work_list, &work_list);
661 spin_unlock_bh(&p->fp_work_lock);
663 list_for_each_entry_safe(work, tmp, &work_list, list) {
664 list_del_init(&work->list);
665 bnx2fc_process_cq_compl(work->tgt, work->wqe,
672 spin_lock_bh(&p->fp_work_lock);
674 __set_current_state(TASK_INTERRUPTIBLE);
675 spin_unlock_bh(&p->fp_work_lock);
677 __set_current_state(TASK_RUNNING);
682 static struct fc_host_statistics *bnx2fc_get_host_stats(struct Scsi_Host *shost)
684 struct fc_host_statistics *bnx2fc_stats;
685 struct fc_lport *lport = shost_priv(shost);
686 struct fcoe_port *port = lport_priv(lport);
687 struct bnx2fc_interface *interface = port->priv;
688 struct bnx2fc_hba *hba = interface->hba;
689 struct fcoe_statistics_params *fw_stats;
692 fw_stats = (struct fcoe_statistics_params *)hba->stats_buffer;
696 mutex_lock(&hba->hba_stats_mutex);
698 bnx2fc_stats = fc_get_host_stats(shost);
700 init_completion(&hba->stat_req_done);
701 if (bnx2fc_send_stat_req(hba))
702 goto unlock_stats_mutex;
703 rc = wait_for_completion_timeout(&hba->stat_req_done, (2 * HZ));
705 BNX2FC_HBA_DBG(lport, "FW stat req timed out\n");
706 goto unlock_stats_mutex;
708 BNX2FC_STATS(hba, rx_stat2, fc_crc_cnt);
709 bnx2fc_stats->invalid_crc_count += hba->bfw_stats.fc_crc_cnt;
710 BNX2FC_STATS(hba, tx_stat, fcoe_tx_pkt_cnt);
711 bnx2fc_stats->tx_frames += hba->bfw_stats.fcoe_tx_pkt_cnt;
712 BNX2FC_STATS(hba, tx_stat, fcoe_tx_byte_cnt);
713 bnx2fc_stats->tx_words += ((hba->bfw_stats.fcoe_tx_byte_cnt) / 4);
714 BNX2FC_STATS(hba, rx_stat0, fcoe_rx_pkt_cnt);
715 bnx2fc_stats->rx_frames += hba->bfw_stats.fcoe_rx_pkt_cnt;
716 BNX2FC_STATS(hba, rx_stat0, fcoe_rx_byte_cnt);
717 bnx2fc_stats->rx_words += ((hba->bfw_stats.fcoe_rx_byte_cnt) / 4);
719 bnx2fc_stats->dumped_frames = 0;
720 bnx2fc_stats->lip_count = 0;
721 bnx2fc_stats->nos_count = 0;
722 bnx2fc_stats->loss_of_sync_count = 0;
723 bnx2fc_stats->loss_of_signal_count = 0;
724 bnx2fc_stats->prim_seq_protocol_err_count = 0;
726 memcpy(&hba->prev_stats, hba->stats_buffer,
727 sizeof(struct fcoe_statistics_params));
730 mutex_unlock(&hba->hba_stats_mutex);
734 static int bnx2fc_shost_config(struct fc_lport *lport, struct device *dev)
736 struct fcoe_port *port = lport_priv(lport);
737 struct bnx2fc_interface *interface = port->priv;
738 struct bnx2fc_hba *hba = interface->hba;
739 struct Scsi_Host *shost = lport->host;
742 shost->max_cmd_len = BNX2FC_MAX_CMD_LEN;
743 shost->max_lun = bnx2fc_max_luns;
744 shost->max_id = BNX2FC_MAX_FCP_TGT;
745 shost->max_channel = 0;
747 shost->transportt = bnx2fc_vport_xport_template;
749 shost->transportt = bnx2fc_transport_template;
751 /* Add the new host to SCSI-ml */
752 rc = scsi_add_host(lport->host, dev);
754 printk(KERN_ERR PFX "Error on scsi_add_host\n");
758 fc_host_max_npiv_vports(lport->host) = USHRT_MAX;
759 snprintf(fc_host_symbolic_name(lport->host), 256,
760 "%s (QLogic %s) v%s over %s",
761 BNX2FC_NAME, hba->chip_num, BNX2FC_VERSION,
762 interface->netdev->name);
767 static int bnx2fc_link_ok(struct fc_lport *lport)
769 struct fcoe_port *port = lport_priv(lport);
770 struct bnx2fc_interface *interface = port->priv;
771 struct bnx2fc_hba *hba = interface->hba;
772 struct net_device *dev = hba->phys_dev;
775 if ((dev->flags & IFF_UP) && netif_carrier_ok(dev))
776 clear_bit(ADAPTER_STATE_LINK_DOWN, &hba->adapter_state);
778 set_bit(ADAPTER_STATE_LINK_DOWN, &hba->adapter_state);
785 * bnx2fc_get_link_state - get network link state
787 * @hba: adapter instance pointer
789 * updates adapter structure flag based on netdev state
791 void bnx2fc_get_link_state(struct bnx2fc_hba *hba)
793 if (test_bit(__LINK_STATE_NOCARRIER, &hba->phys_dev->state))
794 set_bit(ADAPTER_STATE_LINK_DOWN, &hba->adapter_state);
796 clear_bit(ADAPTER_STATE_LINK_DOWN, &hba->adapter_state);
799 static int bnx2fc_net_config(struct fc_lport *lport, struct net_device *netdev)
801 struct bnx2fc_hba *hba;
802 struct bnx2fc_interface *interface;
803 struct fcoe_ctlr *ctlr;
804 struct fcoe_port *port;
807 port = lport_priv(lport);
808 interface = port->priv;
809 ctlr = bnx2fc_to_ctlr(interface);
810 hba = interface->hba;
812 /* require support for get_pauseparam ethtool op. */
813 if (!hba->phys_dev->ethtool_ops ||
814 !hba->phys_dev->ethtool_ops->get_pauseparam)
817 if (fc_set_mfs(lport, BNX2FC_MFS))
820 skb_queue_head_init(&port->fcoe_pending_queue);
821 port->fcoe_pending_queue_active = 0;
822 timer_setup(&port->timer, fcoe_queue_timer, 0);
824 fcoe_link_speed_update(lport);
827 if (fcoe_get_wwn(netdev, &wwnn, NETDEV_FCOE_WWNN))
828 wwnn = fcoe_wwn_from_mac(ctlr->ctl_src_addr,
830 BNX2FC_HBA_DBG(lport, "WWNN = 0x%llx\n", wwnn);
831 fc_set_wwnn(lport, wwnn);
833 if (fcoe_get_wwn(netdev, &wwpn, NETDEV_FCOE_WWPN))
834 wwpn = fcoe_wwn_from_mac(ctlr->ctl_src_addr,
837 BNX2FC_HBA_DBG(lport, "WWPN = 0x%llx\n", wwpn);
838 fc_set_wwpn(lport, wwpn);
844 static void bnx2fc_destroy_timer(struct timer_list *t)
846 struct bnx2fc_hba *hba = from_timer(hba, t, destroy_timer);
848 printk(KERN_ERR PFX "ERROR:bnx2fc_destroy_timer - "
849 "Destroy compl not received!!\n");
850 set_bit(BNX2FC_FLAG_DESTROY_CMPL, &hba->flags);
851 wake_up_interruptible(&hba->destroy_wait);
855 * bnx2fc_indicate_netevent - Generic netdev event handler
857 * @context: adapter structure pointer
859 * @vlan_id: vlan id - associated vlan id with this event
861 * Handles NETDEV_UP, NETDEV_DOWN, NETDEV_GOING_DOWN,NETDEV_CHANGE and
862 * NETDEV_CHANGE_MTU events. Handle NETDEV_UNREGISTER only for vlans.
864 static void bnx2fc_indicate_netevent(void *context, unsigned long event,
867 struct bnx2fc_hba *hba = (struct bnx2fc_hba *)context;
868 struct fcoe_ctlr_device *cdev;
869 struct fc_lport *lport;
870 struct fc_lport *vport;
871 struct bnx2fc_interface *interface, *tmp;
872 struct fcoe_ctlr *ctlr;
873 int wait_for_upload = 0;
874 u32 link_possible = 1;
876 if (vlan_id != 0 && event != NETDEV_UNREGISTER)
881 if (!test_bit(ADAPTER_STATE_UP, &hba->adapter_state))
882 printk(KERN_ERR "indicate_netevent: "\
883 "hba is not UP!!\n");
887 clear_bit(ADAPTER_STATE_GOING_DOWN, &hba->adapter_state);
888 clear_bit(ADAPTER_STATE_UP, &hba->adapter_state);
892 case NETDEV_GOING_DOWN:
893 set_bit(ADAPTER_STATE_GOING_DOWN, &hba->adapter_state);
900 case NETDEV_UNREGISTER:
903 mutex_lock(&bnx2fc_dev_lock);
904 list_for_each_entry_safe(interface, tmp, &if_list, list) {
905 if (interface->hba == hba &&
906 interface->vlan_id == (vlan_id & VLAN_VID_MASK))
907 __bnx2fc_destroy(interface);
909 mutex_unlock(&bnx2fc_dev_lock);
911 /* Ensure ALL destroy work has been completed before return */
912 flush_workqueue(bnx2fc_wq);
919 mutex_lock(&bnx2fc_dev_lock);
920 list_for_each_entry(interface, &if_list, list) {
922 if (interface->hba != hba)
925 ctlr = bnx2fc_to_ctlr(interface);
927 BNX2FC_HBA_DBG(lport, "netevent handler - event=%s %ld\n",
928 interface->netdev->name, event);
930 fcoe_link_speed_update(lport);
932 cdev = fcoe_ctlr_to_ctlr_dev(ctlr);
934 if (link_possible && !bnx2fc_link_ok(lport)) {
935 switch (cdev->enabled) {
936 case FCOE_CTLR_DISABLED:
937 pr_info("Link up while interface is disabled.\n");
939 case FCOE_CTLR_ENABLED:
940 case FCOE_CTLR_UNUSED:
941 /* Reset max recv frame size to default */
942 fc_set_mfs(lport, BNX2FC_MFS);
944 * ctlr link up will only be handled during
945 * enable to avoid sending discovery
946 * solicitation on a stale vlan
948 if (interface->enabled)
949 fcoe_ctlr_link_up(ctlr);
951 } else if (fcoe_ctlr_link_down(ctlr)) {
952 switch (cdev->enabled) {
953 case FCOE_CTLR_DISABLED:
954 pr_info("Link down while interface is disabled.\n");
956 case FCOE_CTLR_ENABLED:
957 case FCOE_CTLR_UNUSED:
958 mutex_lock(&lport->lp_mutex);
959 list_for_each_entry(vport, &lport->vports, list)
960 fc_host_port_type(vport->host) =
962 mutex_unlock(&lport->lp_mutex);
963 fc_host_port_type(lport->host) =
965 per_cpu_ptr(lport->stats,
966 get_cpu())->LinkFailureCount++;
968 fcoe_clean_pending_queue(lport);
973 mutex_unlock(&bnx2fc_dev_lock);
975 if (wait_for_upload) {
976 clear_bit(ADAPTER_STATE_READY, &hba->adapter_state);
977 init_waitqueue_head(&hba->shutdown_wait);
978 BNX2FC_MISC_DBG("indicate_netevent "
979 "num_ofld_sess = %d\n",
981 hba->wait_for_link_down = 1;
982 wait_event_interruptible(hba->shutdown_wait,
983 (hba->num_ofld_sess == 0));
984 BNX2FC_MISC_DBG("wakeup - num_ofld_sess = %d\n",
986 hba->wait_for_link_down = 0;
988 if (signal_pending(current))
989 flush_signals(current);
993 static int bnx2fc_libfc_config(struct fc_lport *lport)
996 /* Set the function pointers set by bnx2fc driver */
997 memcpy(&lport->tt, &bnx2fc_libfc_fcn_templ,
998 sizeof(struct libfc_function_template));
999 fc_elsct_init(lport);
1000 fc_exch_init(lport);
1001 fc_disc_init(lport);
1002 fc_disc_config(lport, lport);
1006 static int bnx2fc_em_config(struct fc_lport *lport, struct bnx2fc_hba *hba)
1008 int fcoe_min_xid, fcoe_max_xid;
1010 fcoe_min_xid = hba->max_xid + 1;
1011 if (nr_cpu_ids <= 2)
1012 fcoe_max_xid = hba->max_xid + FCOE_XIDS_PER_CPU_OFFSET;
1014 fcoe_max_xid = hba->max_xid + FCOE_MAX_XID_OFFSET;
1015 if (!fc_exch_mgr_alloc(lport, FC_CLASS_3, fcoe_min_xid,
1016 fcoe_max_xid, NULL)) {
1017 printk(KERN_ERR PFX "em_config:fc_exch_mgr_alloc failed\n");
1024 static int bnx2fc_lport_config(struct fc_lport *lport)
1028 lport->max_retry_count = BNX2FC_MAX_RETRY_CNT;
1029 lport->max_rport_retry_count = BNX2FC_MAX_RPORT_RETRY_CNT;
1030 lport->e_d_tov = 2 * 1000;
1031 lport->r_a_tov = 10 * 1000;
1033 lport->service_params = (FCP_SPPF_INIT_FCN | FCP_SPPF_RD_XRDY_DIS |
1034 FCP_SPPF_RETRY | FCP_SPPF_CONF_COMPL);
1035 lport->does_npiv = 1;
1037 memset(&lport->rnid_gen, 0, sizeof(struct fc_els_rnid_gen));
1038 lport->rnid_gen.rnid_atype = BNX2FC_RNID_HBA;
1040 /* alloc stats structure */
1041 if (fc_lport_init_stats(lport))
1044 /* Finish fc_lport configuration */
1045 fc_lport_config(lport);
1051 * bnx2fc_fip_recv - handle a received FIP frame.
1053 * @skb: the received skb
1054 * @dev: associated &net_device
1055 * @ptype: the &packet_type structure which was used to register this handler.
1056 * @orig_dev: original receive &net_device, in case @ dev is a bond.
1058 * Returns: 0 for success
1060 static int bnx2fc_fip_recv(struct sk_buff *skb, struct net_device *dev,
1061 struct packet_type *ptype,
1062 struct net_device *orig_dev)
1064 struct bnx2fc_interface *interface;
1065 struct fcoe_ctlr *ctlr;
1066 interface = container_of(ptype, struct bnx2fc_interface,
1068 ctlr = bnx2fc_to_ctlr(interface);
1069 fcoe_ctlr_recv(ctlr, skb);
1074 * bnx2fc_update_src_mac - Update Ethernet MAC filters.
1076 * @lport: The local port
1077 * @addr: Location of data to copy
1079 * Remove any previously-set unicast MAC filter.
1080 * Add secondary FCoE MAC address filter for our OUI.
1082 static void bnx2fc_update_src_mac(struct fc_lport *lport, u8 *addr)
1084 struct fcoe_port *port = lport_priv(lport);
1086 memcpy(port->data_src_addr, addr, ETH_ALEN);
1090 * bnx2fc_get_src_mac - return the ethernet source address for an lport
1092 * @lport: libfc port
1094 static u8 *bnx2fc_get_src_mac(struct fc_lport *lport)
1096 struct fcoe_port *port;
1098 port = (struct fcoe_port *)lport_priv(lport);
1099 return port->data_src_addr;
1103 * bnx2fc_fip_send - send an Ethernet-encapsulated FIP frame.
1105 * @fip: FCoE controller.
1108 static void bnx2fc_fip_send(struct fcoe_ctlr *fip, struct sk_buff *skb)
1110 struct fip_header *fiph;
1111 struct ethhdr *eth_hdr;
1115 fiph = (struct fip_header *) ((void *)skb->data + 2 * ETH_ALEN + 2);
1116 eth_hdr = (struct ethhdr *)skb_mac_header(skb);
1117 op = ntohs(fiph->fip_op);
1118 sub = fiph->fip_subcode;
1120 if (op == FIP_OP_CTRL && sub == FIP_SC_SOL && bnx2fc_log_fka)
1121 BNX2FC_MISC_DBG("Sending FKA from %pM to %pM.\n",
1122 eth_hdr->h_source, eth_hdr->h_dest);
1124 skb->dev = bnx2fc_from_ctlr(fip)->netdev;
1125 dev_queue_xmit(skb);
1128 static int bnx2fc_vport_create(struct fc_vport *vport, bool disabled)
1130 struct Scsi_Host *shost = vport_to_shost(vport);
1131 struct fc_lport *n_port = shost_priv(shost);
1132 struct fcoe_port *port = lport_priv(n_port);
1133 struct bnx2fc_interface *interface = port->priv;
1134 struct net_device *netdev = interface->netdev;
1135 struct fc_lport *vn_port;
1139 rc = fcoe_validate_vport_create(vport);
1141 fcoe_wwn_to_str(vport->port_name, buf, sizeof(buf));
1142 printk(KERN_ERR PFX "Failed to create vport, "
1143 "WWPN (0x%s) already exists\n",
1148 if (!test_bit(BNX2FC_FLAG_FW_INIT_DONE, &interface->hba->flags)) {
1149 printk(KERN_ERR PFX "vn ports cannot be created on"
1150 "this interface\n");
1154 mutex_lock(&bnx2fc_dev_lock);
1155 vn_port = bnx2fc_if_create(interface, &vport->dev, 1);
1156 mutex_unlock(&bnx2fc_dev_lock);
1160 printk(KERN_ERR PFX "bnx2fc_vport_create (%s) failed\n",
1165 if (bnx2fc_devloss_tmo)
1166 fc_host_dev_loss_tmo(vn_port->host) = bnx2fc_devloss_tmo;
1169 fc_vport_set_state(vport, FC_VPORT_DISABLED);
1171 vn_port->boot_time = jiffies;
1172 fc_lport_init(vn_port);
1173 fc_fabric_login(vn_port);
1174 fc_vport_setlink(vn_port);
1179 static void bnx2fc_free_vport(struct bnx2fc_hba *hba, struct fc_lport *lport)
1181 struct bnx2fc_lport *blport, *tmp;
1183 spin_lock_bh(&hba->hba_lock);
1184 list_for_each_entry_safe(blport, tmp, &hba->vports, list) {
1185 if (blport->lport == lport) {
1186 list_del(&blport->list);
1190 spin_unlock_bh(&hba->hba_lock);
1193 static int bnx2fc_vport_destroy(struct fc_vport *vport)
1195 struct Scsi_Host *shost = vport_to_shost(vport);
1196 struct fc_lport *n_port = shost_priv(shost);
1197 struct fc_lport *vn_port = vport->dd_data;
1198 struct fcoe_port *port = lport_priv(vn_port);
1199 struct bnx2fc_interface *interface = port->priv;
1200 struct fc_lport *v_port;
1203 mutex_lock(&n_port->lp_mutex);
1204 list_for_each_entry(v_port, &n_port->vports, list)
1205 if (v_port->vport == vport) {
1211 mutex_unlock(&n_port->lp_mutex);
1214 list_del(&vn_port->list);
1215 mutex_unlock(&n_port->lp_mutex);
1216 bnx2fc_free_vport(interface->hba, port->lport);
1217 bnx2fc_port_shutdown(port->lport);
1218 bnx2fc_interface_put(interface);
1219 queue_work(bnx2fc_wq, &port->destroy_work);
1223 static int bnx2fc_vport_disable(struct fc_vport *vport, bool disable)
1225 struct fc_lport *lport = vport->dd_data;
1228 fc_vport_set_state(vport, FC_VPORT_DISABLED);
1229 fc_fabric_logoff(lport);
1231 lport->boot_time = jiffies;
1232 fc_fabric_login(lport);
1233 fc_vport_setlink(lport);
1239 static int bnx2fc_interface_setup(struct bnx2fc_interface *interface)
1241 struct net_device *netdev = interface->netdev;
1242 struct net_device *physdev = interface->hba->phys_dev;
1243 struct fcoe_ctlr *ctlr = bnx2fc_to_ctlr(interface);
1244 struct netdev_hw_addr *ha;
1245 int sel_san_mac = 0;
1247 /* setup Source MAC Address */
1249 for_each_dev_addr(physdev, ha) {
1250 BNX2FC_MISC_DBG("net_config: ha->type = %d, fip_mac = ",
1252 printk(KERN_INFO "%2x:%2x:%2x:%2x:%2x:%2x\n", ha->addr[0],
1253 ha->addr[1], ha->addr[2], ha->addr[3],
1254 ha->addr[4], ha->addr[5]);
1256 if ((ha->type == NETDEV_HW_ADDR_T_SAN) &&
1257 (is_valid_ether_addr(ha->addr))) {
1258 memcpy(ctlr->ctl_src_addr, ha->addr,
1261 BNX2FC_MISC_DBG("Found SAN MAC\n");
1269 interface->fip_packet_type.func = bnx2fc_fip_recv;
1270 interface->fip_packet_type.type = htons(ETH_P_FIP);
1271 interface->fip_packet_type.dev = netdev;
1272 dev_add_pack(&interface->fip_packet_type);
1274 interface->fcoe_packet_type.func = bnx2fc_rcv;
1275 interface->fcoe_packet_type.type = __constant_htons(ETH_P_FCOE);
1276 interface->fcoe_packet_type.dev = netdev;
1277 dev_add_pack(&interface->fcoe_packet_type);
1282 static int bnx2fc_attach_transport(void)
1284 bnx2fc_transport_template =
1285 fc_attach_transport(&bnx2fc_transport_function);
1287 if (bnx2fc_transport_template == NULL) {
1288 printk(KERN_ERR PFX "Failed to attach FC transport\n");
1292 bnx2fc_vport_xport_template =
1293 fc_attach_transport(&bnx2fc_vport_xport_function);
1294 if (bnx2fc_vport_xport_template == NULL) {
1296 "Failed to attach FC transport for vport\n");
1297 fc_release_transport(bnx2fc_transport_template);
1298 bnx2fc_transport_template = NULL;
1303 static void bnx2fc_release_transport(void)
1305 fc_release_transport(bnx2fc_transport_template);
1306 fc_release_transport(bnx2fc_vport_xport_template);
1307 bnx2fc_transport_template = NULL;
1308 bnx2fc_vport_xport_template = NULL;
1311 static void bnx2fc_interface_release(struct kref *kref)
1313 struct fcoe_ctlr_device *ctlr_dev;
1314 struct bnx2fc_interface *interface;
1315 struct fcoe_ctlr *ctlr;
1316 struct net_device *netdev;
1318 interface = container_of(kref, struct bnx2fc_interface, kref);
1319 BNX2FC_MISC_DBG("Interface is being released\n");
1321 ctlr = bnx2fc_to_ctlr(interface);
1322 ctlr_dev = fcoe_ctlr_to_ctlr_dev(ctlr);
1323 netdev = interface->netdev;
1325 /* tear-down FIP controller */
1326 if (test_and_clear_bit(BNX2FC_CTLR_INIT_DONE, &interface->if_flags))
1327 fcoe_ctlr_destroy(ctlr);
1329 fcoe_ctlr_device_delete(ctlr_dev);
1332 module_put(THIS_MODULE);
1335 static inline void bnx2fc_interface_get(struct bnx2fc_interface *interface)
1337 kref_get(&interface->kref);
1340 static inline void bnx2fc_interface_put(struct bnx2fc_interface *interface)
1342 kref_put(&interface->kref, bnx2fc_interface_release);
1344 static void bnx2fc_hba_destroy(struct bnx2fc_hba *hba)
1346 /* Free the command manager */
1348 bnx2fc_cmd_mgr_free(hba->cmd_mgr);
1349 hba->cmd_mgr = NULL;
1351 kfree(hba->tgt_ofld_list);
1352 bnx2fc_unbind_pcidev(hba);
1357 * bnx2fc_hba_create - create a new bnx2fc hba
1359 * @cnic: pointer to cnic device
1361 * Creates a new FCoE hba on the given device.
1364 static struct bnx2fc_hba *bnx2fc_hba_create(struct cnic_dev *cnic)
1366 struct bnx2fc_hba *hba;
1367 struct fcoe_capabilities *fcoe_cap;
1370 hba = kzalloc(sizeof(*hba), GFP_KERNEL);
1372 printk(KERN_ERR PFX "Unable to allocate hba structure\n");
1375 spin_lock_init(&hba->hba_lock);
1376 mutex_init(&hba->hba_mutex);
1377 mutex_init(&hba->hba_stats_mutex);
1381 hba->max_tasks = cnic->max_fcoe_exchanges;
1382 hba->elstm_xids = (hba->max_tasks / 2);
1383 hba->max_outstanding_cmds = hba->elstm_xids;
1384 hba->max_xid = (hba->max_tasks - 1);
1386 rc = bnx2fc_bind_pcidev(hba);
1388 printk(KERN_ERR PFX "create_adapter: bind error\n");
1391 hba->phys_dev = cnic->netdev;
1392 hba->next_conn_id = 0;
1394 hba->tgt_ofld_list =
1395 kcalloc(BNX2FC_NUM_MAX_SESS, sizeof(struct bnx2fc_rport *),
1397 if (!hba->tgt_ofld_list) {
1398 printk(KERN_ERR PFX "Unable to allocate tgt offload list\n");
1402 hba->num_ofld_sess = 0;
1404 hba->cmd_mgr = bnx2fc_cmd_mgr_alloc(hba);
1405 if (!hba->cmd_mgr) {
1406 printk(KERN_ERR PFX "em_config:bnx2fc_cmd_mgr_alloc failed\n");
1409 fcoe_cap = &hba->fcoe_cap;
1411 fcoe_cap->capability1 = BNX2FC_TM_MAX_SQES <<
1412 FCOE_IOS_PER_CONNECTION_SHIFT;
1413 fcoe_cap->capability1 |= BNX2FC_NUM_MAX_SESS <<
1414 FCOE_LOGINS_PER_PORT_SHIFT;
1415 fcoe_cap->capability2 = hba->max_outstanding_cmds <<
1416 FCOE_NUMBER_OF_EXCHANGES_SHIFT;
1417 fcoe_cap->capability2 |= BNX2FC_MAX_NPIV <<
1418 FCOE_NPIV_WWN_PER_PORT_SHIFT;
1419 fcoe_cap->capability3 = BNX2FC_NUM_MAX_SESS <<
1420 FCOE_TARGETS_SUPPORTED_SHIFT;
1421 fcoe_cap->capability3 |= hba->max_outstanding_cmds <<
1422 FCOE_OUTSTANDING_COMMANDS_SHIFT;
1423 fcoe_cap->capability4 = FCOE_CAPABILITY4_STATEFUL;
1425 init_waitqueue_head(&hba->shutdown_wait);
1426 init_waitqueue_head(&hba->destroy_wait);
1427 INIT_LIST_HEAD(&hba->vports);
1432 kfree(hba->tgt_ofld_list);
1434 bnx2fc_unbind_pcidev(hba);
1440 static struct bnx2fc_interface *
1441 bnx2fc_interface_create(struct bnx2fc_hba *hba,
1442 struct net_device *netdev,
1443 enum fip_mode fip_mode)
1445 struct fcoe_ctlr_device *ctlr_dev;
1446 struct bnx2fc_interface *interface;
1447 struct fcoe_ctlr *ctlr;
1451 size = (sizeof(*interface) + sizeof(struct fcoe_ctlr));
1452 ctlr_dev = fcoe_ctlr_device_add(&netdev->dev, &bnx2fc_fcoe_sysfs_templ,
1455 printk(KERN_ERR PFX "Unable to allocate interface structure\n");
1458 ctlr = fcoe_ctlr_device_priv(ctlr_dev);
1459 ctlr->cdev = ctlr_dev;
1460 interface = fcoe_ctlr_priv(ctlr);
1462 kref_init(&interface->kref);
1463 interface->hba = hba;
1464 interface->netdev = netdev;
1466 /* Initialize FIP */
1467 fcoe_ctlr_init(ctlr, fip_mode);
1468 ctlr->send = bnx2fc_fip_send;
1469 ctlr->update_mac = bnx2fc_update_src_mac;
1470 ctlr->get_src_addr = bnx2fc_get_src_mac;
1471 set_bit(BNX2FC_CTLR_INIT_DONE, &interface->if_flags);
1473 rc = bnx2fc_interface_setup(interface);
1477 fcoe_ctlr_destroy(ctlr);
1479 fcoe_ctlr_device_delete(ctlr_dev);
1484 * bnx2fc_if_create - Create FCoE instance on a given interface
1486 * @interface: FCoE interface to create a local port on
1487 * @parent: Device pointer to be the parent in sysfs for the SCSI host
1488 * @npiv: Indicates if the port is vport or not
1490 * Creates a fc_lport instance and a Scsi_Host instance and configure them.
1492 * Returns: Allocated fc_lport or an error pointer
1494 static struct fc_lport *bnx2fc_if_create(struct bnx2fc_interface *interface,
1495 struct device *parent, int npiv)
1497 struct fcoe_ctlr *ctlr = bnx2fc_to_ctlr(interface);
1498 struct fc_lport *lport, *n_port;
1499 struct fcoe_port *port;
1500 struct Scsi_Host *shost;
1501 struct fc_vport *vport = dev_to_vport(parent);
1502 struct bnx2fc_lport *blport;
1503 struct bnx2fc_hba *hba = interface->hba;
1506 blport = kzalloc(sizeof(struct bnx2fc_lport), GFP_KERNEL);
1508 BNX2FC_HBA_DBG(ctlr->lp, "Unable to alloc blport\n");
1512 /* Allocate Scsi_Host structure */
1513 bnx2fc_shost_template.can_queue = hba->max_outstanding_cmds;
1515 lport = libfc_host_alloc(&bnx2fc_shost_template, sizeof(*port));
1517 lport = libfc_vport_create(vport, sizeof(*port));
1520 printk(KERN_ERR PFX "could not allocate scsi host structure\n");
1523 shost = lport->host;
1524 port = lport_priv(lport);
1525 port->lport = lport;
1526 port->priv = interface;
1527 port->get_netdev = bnx2fc_netdev;
1528 INIT_WORK(&port->destroy_work, bnx2fc_destroy_work);
1530 /* Configure fcoe_port */
1531 rc = bnx2fc_lport_config(lport);
1536 printk(KERN_ERR PFX "Setting vport names, 0x%llX 0x%llX\n",
1537 vport->node_name, vport->port_name);
1538 fc_set_wwnn(lport, vport->node_name);
1539 fc_set_wwpn(lport, vport->port_name);
1541 /* Configure netdev and networking properties of the lport */
1542 rc = bnx2fc_net_config(lport, interface->netdev);
1544 printk(KERN_ERR PFX "Error on bnx2fc_net_config\n");
1548 rc = bnx2fc_shost_config(lport, parent);
1550 printk(KERN_ERR PFX "Couldn't configure shost for %s\n",
1551 interface->netdev->name);
1555 /* Initialize the libfc library */
1556 rc = bnx2fc_libfc_config(lport);
1558 printk(KERN_ERR PFX "Couldn't configure libfc\n");
1561 fc_host_port_type(lport->host) = FC_PORTTYPE_UNKNOWN;
1563 if (bnx2fc_devloss_tmo)
1564 fc_host_dev_loss_tmo(shost) = bnx2fc_devloss_tmo;
1566 /* Allocate exchange manager */
1568 rc = bnx2fc_em_config(lport, hba);
1570 shost = vport_to_shost(vport);
1571 n_port = shost_priv(shost);
1572 rc = fc_exch_mgr_list_clone(n_port, lport);
1576 printk(KERN_ERR PFX "Error on bnx2fc_em_config\n");
1580 bnx2fc_interface_get(interface);
1582 spin_lock_bh(&hba->hba_lock);
1583 blport->lport = lport;
1584 list_add_tail(&blport->list, &hba->vports);
1585 spin_unlock_bh(&hba->hba_lock);
1590 scsi_remove_host(shost);
1592 scsi_host_put(lport->host);
1598 static void bnx2fc_net_cleanup(struct bnx2fc_interface *interface)
1600 /* Dont listen for Ethernet packets anymore */
1601 __dev_remove_pack(&interface->fcoe_packet_type);
1602 __dev_remove_pack(&interface->fip_packet_type);
1606 static void bnx2fc_interface_cleanup(struct bnx2fc_interface *interface)
1608 struct fcoe_ctlr *ctlr = bnx2fc_to_ctlr(interface);
1609 struct fc_lport *lport = ctlr->lp;
1610 struct fcoe_port *port = lport_priv(lport);
1611 struct bnx2fc_hba *hba = interface->hba;
1613 /* Stop the transmit retry timer */
1614 del_timer_sync(&port->timer);
1616 /* Free existing transmit skbs */
1617 fcoe_clean_pending_queue(lport);
1619 bnx2fc_net_cleanup(interface);
1621 bnx2fc_free_vport(hba, lport);
1624 static void bnx2fc_if_destroy(struct fc_lport *lport)
1627 /* Free queued packets for the receive thread */
1628 bnx2fc_clean_rx_queue(lport);
1630 /* Detach from scsi-ml */
1631 fc_remove_host(lport->host);
1632 scsi_remove_host(lport->host);
1635 * Note that only the physical lport will have the exchange manager.
1636 * for vports, this function is NOP
1638 fc_exch_mgr_free(lport);
1640 /* Free memory used by statistical counters */
1641 fc_lport_free_stats(lport);
1643 /* Release Scsi_Host */
1644 scsi_host_put(lport->host);
1647 static void __bnx2fc_destroy(struct bnx2fc_interface *interface)
1649 struct fcoe_ctlr *ctlr = bnx2fc_to_ctlr(interface);
1650 struct fc_lport *lport = ctlr->lp;
1651 struct fcoe_port *port = lport_priv(lport);
1653 bnx2fc_interface_cleanup(interface);
1654 bnx2fc_stop(interface);
1655 list_del(&interface->list);
1656 bnx2fc_interface_put(interface);
1657 queue_work(bnx2fc_wq, &port->destroy_work);
1661 * bnx2fc_destroy - Destroy a bnx2fc FCoE interface
1663 * @netdev: The net device that the FCoE interface is on
1665 * Called from sysfs.
1667 * Returns: 0 for success
1669 static int bnx2fc_destroy(struct net_device *netdev)
1671 struct bnx2fc_interface *interface = NULL;
1672 struct workqueue_struct *timer_work_queue;
1673 struct fcoe_ctlr *ctlr;
1677 mutex_lock(&bnx2fc_dev_lock);
1679 interface = bnx2fc_interface_lookup(netdev);
1680 ctlr = bnx2fc_to_ctlr(interface);
1681 if (!interface || !ctlr->lp) {
1683 printk(KERN_ERR PFX "bnx2fc_destroy: interface or lport not found\n");
1687 timer_work_queue = interface->timer_work_queue;
1688 __bnx2fc_destroy(interface);
1689 destroy_workqueue(timer_work_queue);
1692 mutex_unlock(&bnx2fc_dev_lock);
1697 static void bnx2fc_destroy_work(struct work_struct *work)
1699 struct fcoe_port *port;
1700 struct fc_lport *lport;
1702 port = container_of(work, struct fcoe_port, destroy_work);
1703 lport = port->lport;
1705 BNX2FC_HBA_DBG(lport, "Entered bnx2fc_destroy_work\n");
1707 bnx2fc_if_destroy(lport);
1710 static void bnx2fc_unbind_adapter_devices(struct bnx2fc_hba *hba)
1712 bnx2fc_free_fw_resc(hba);
1713 bnx2fc_free_task_ctx(hba);
1717 * bnx2fc_bind_adapter_devices - binds bnx2fc adapter with the associated
1720 * @hba: Adapter instance
1722 static int bnx2fc_bind_adapter_devices(struct bnx2fc_hba *hba)
1724 if (bnx2fc_setup_task_ctx(hba))
1727 if (bnx2fc_setup_fw_resc(hba))
1732 bnx2fc_unbind_adapter_devices(hba);
1736 static int bnx2fc_bind_pcidev(struct bnx2fc_hba *hba)
1738 struct cnic_dev *cnic;
1739 struct pci_dev *pdev;
1742 printk(KERN_ERR PFX "cnic is NULL\n");
1746 pdev = hba->pcidev = cnic->pcidev;
1750 switch (pdev->device) {
1751 case PCI_DEVICE_ID_NX2_57710:
1752 strncpy(hba->chip_num, "BCM57710", BCM_CHIP_LEN);
1754 case PCI_DEVICE_ID_NX2_57711:
1755 strncpy(hba->chip_num, "BCM57711", BCM_CHIP_LEN);
1757 case PCI_DEVICE_ID_NX2_57712:
1758 case PCI_DEVICE_ID_NX2_57712_MF:
1759 case PCI_DEVICE_ID_NX2_57712_VF:
1760 strncpy(hba->chip_num, "BCM57712", BCM_CHIP_LEN);
1762 case PCI_DEVICE_ID_NX2_57800:
1763 case PCI_DEVICE_ID_NX2_57800_MF:
1764 case PCI_DEVICE_ID_NX2_57800_VF:
1765 strncpy(hba->chip_num, "BCM57800", BCM_CHIP_LEN);
1767 case PCI_DEVICE_ID_NX2_57810:
1768 case PCI_DEVICE_ID_NX2_57810_MF:
1769 case PCI_DEVICE_ID_NX2_57810_VF:
1770 strncpy(hba->chip_num, "BCM57810", BCM_CHIP_LEN);
1772 case PCI_DEVICE_ID_NX2_57840:
1773 case PCI_DEVICE_ID_NX2_57840_MF:
1774 case PCI_DEVICE_ID_NX2_57840_VF:
1775 case PCI_DEVICE_ID_NX2_57840_2_20:
1776 case PCI_DEVICE_ID_NX2_57840_4_10:
1777 strncpy(hba->chip_num, "BCM57840", BCM_CHIP_LEN);
1780 pr_err(PFX "Unknown device id 0x%x\n", pdev->device);
1783 pci_dev_get(hba->pcidev);
1787 static void bnx2fc_unbind_pcidev(struct bnx2fc_hba *hba)
1790 hba->chip_num[0] = '\0';
1791 pci_dev_put(hba->pcidev);
1797 * bnx2fc_ulp_get_stats - cnic callback to populate FCoE stats
1799 * @handle: transport handle pointing to adapter struture
1801 static int bnx2fc_ulp_get_stats(void *handle)
1803 struct bnx2fc_hba *hba = handle;
1804 struct cnic_dev *cnic;
1805 struct fcoe_stats_info *stats_addr;
1811 stats_addr = &cnic->stats_addr->fcoe_stat;
1815 strncpy(stats_addr->version, BNX2FC_VERSION,
1816 sizeof(stats_addr->version));
1817 stats_addr->txq_size = BNX2FC_SQ_WQES_MAX;
1818 stats_addr->rxq_size = BNX2FC_CQ_WQES_MAX;
1825 * bnx2fc_ulp_start - cnic callback to initialize & start adapter instance
1827 * @handle: transport handle pointing to adapter structure
1829 * This function maps adapter structure to pcidev structure and initiates
1830 * firmware handshake to enable/initialize on-chip FCoE components.
1831 * This bnx2fc - cnic interface api callback is used after following
1832 * conditions are met -
1833 * a) underlying network interface is up (marked by event NETDEV_UP
1835 * b) bnx2fc adatper structure is registered.
1837 static void bnx2fc_ulp_start(void *handle)
1839 struct bnx2fc_hba *hba = handle;
1840 struct bnx2fc_interface *interface;
1841 struct fcoe_ctlr *ctlr;
1842 struct fc_lport *lport;
1844 mutex_lock(&bnx2fc_dev_lock);
1846 if (!test_bit(BNX2FC_FLAG_FW_INIT_DONE, &hba->flags))
1847 bnx2fc_fw_init(hba);
1849 BNX2FC_MISC_DBG("bnx2fc started.\n");
1851 list_for_each_entry(interface, &if_list, list) {
1852 if (interface->hba == hba) {
1853 ctlr = bnx2fc_to_ctlr(interface);
1855 /* Kick off Fabric discovery*/
1856 printk(KERN_ERR PFX "ulp_init: start discovery\n");
1857 lport->tt.frame_send = bnx2fc_xmit;
1858 bnx2fc_start_disc(interface);
1862 mutex_unlock(&bnx2fc_dev_lock);
1865 static void bnx2fc_port_shutdown(struct fc_lport *lport)
1867 BNX2FC_MISC_DBG("Entered %s\n", __func__);
1868 fc_fabric_logoff(lport);
1869 fc_lport_destroy(lport);
1872 static void bnx2fc_stop(struct bnx2fc_interface *interface)
1874 struct fcoe_ctlr *ctlr = bnx2fc_to_ctlr(interface);
1875 struct fc_lport *lport;
1876 struct fc_lport *vport;
1878 if (!test_bit(BNX2FC_FLAG_FW_INIT_DONE, &interface->hba->flags))
1882 bnx2fc_port_shutdown(lport);
1884 mutex_lock(&lport->lp_mutex);
1885 list_for_each_entry(vport, &lport->vports, list)
1886 fc_host_port_type(vport->host) =
1887 FC_PORTTYPE_UNKNOWN;
1888 mutex_unlock(&lport->lp_mutex);
1889 fc_host_port_type(lport->host) = FC_PORTTYPE_UNKNOWN;
1890 fcoe_ctlr_link_down(ctlr);
1891 fcoe_clean_pending_queue(lport);
1894 static int bnx2fc_fw_init(struct bnx2fc_hba *hba)
1896 #define BNX2FC_INIT_POLL_TIME (1000 / HZ)
1900 rc = bnx2fc_bind_adapter_devices(hba);
1902 printk(KERN_ALERT PFX
1903 "bnx2fc_bind_adapter_devices failed - rc = %d\n", rc);
1907 rc = bnx2fc_send_fw_fcoe_init_msg(hba);
1909 printk(KERN_ALERT PFX
1910 "bnx2fc_send_fw_fcoe_init_msg failed - rc = %d\n", rc);
1915 * Wait until the adapter init message is complete, and adapter
1918 while (!test_bit(ADAPTER_STATE_UP, &hba->adapter_state) && i--)
1919 msleep(BNX2FC_INIT_POLL_TIME);
1921 if (!test_bit(ADAPTER_STATE_UP, &hba->adapter_state)) {
1922 printk(KERN_ERR PFX "bnx2fc_start: %s failed to initialize. "
1924 hba->cnic->netdev->name);
1930 set_bit(BNX2FC_FLAG_FW_INIT_DONE, &hba->flags);
1934 bnx2fc_unbind_adapter_devices(hba);
1939 static void bnx2fc_fw_destroy(struct bnx2fc_hba *hba)
1941 if (test_and_clear_bit(BNX2FC_FLAG_FW_INIT_DONE, &hba->flags)) {
1942 if (bnx2fc_send_fw_fcoe_destroy_msg(hba) == 0) {
1943 timer_setup(&hba->destroy_timer, bnx2fc_destroy_timer,
1945 hba->destroy_timer.expires = BNX2FC_FW_TIMEOUT +
1947 add_timer(&hba->destroy_timer);
1948 wait_event_interruptible(hba->destroy_wait,
1949 test_bit(BNX2FC_FLAG_DESTROY_CMPL,
1951 clear_bit(BNX2FC_FLAG_DESTROY_CMPL, &hba->flags);
1952 /* This should never happen */
1953 if (signal_pending(current))
1954 flush_signals(current);
1956 del_timer_sync(&hba->destroy_timer);
1958 bnx2fc_unbind_adapter_devices(hba);
1963 * bnx2fc_ulp_stop - cnic callback to shutdown adapter instance
1965 * @handle: transport handle pointing to adapter structure
1967 * Driver checks if adapter is already in shutdown mode, if not start
1968 * the shutdown process.
1970 static void bnx2fc_ulp_stop(void *handle)
1972 struct bnx2fc_hba *hba = handle;
1973 struct bnx2fc_interface *interface;
1975 printk(KERN_ERR "ULP_STOP\n");
1977 mutex_lock(&bnx2fc_dev_lock);
1978 if (!test_bit(BNX2FC_FLAG_FW_INIT_DONE, &hba->flags))
1980 list_for_each_entry(interface, &if_list, list) {
1981 if (interface->hba == hba)
1982 bnx2fc_stop(interface);
1984 BUG_ON(hba->num_ofld_sess != 0);
1986 mutex_lock(&hba->hba_mutex);
1987 clear_bit(ADAPTER_STATE_UP, &hba->adapter_state);
1988 clear_bit(ADAPTER_STATE_GOING_DOWN,
1989 &hba->adapter_state);
1991 clear_bit(ADAPTER_STATE_READY, &hba->adapter_state);
1992 mutex_unlock(&hba->hba_mutex);
1994 bnx2fc_fw_destroy(hba);
1996 mutex_unlock(&bnx2fc_dev_lock);
1999 static void bnx2fc_start_disc(struct bnx2fc_interface *interface)
2001 struct fcoe_ctlr *ctlr = bnx2fc_to_ctlr(interface);
2002 struct fc_lport *lport;
2005 BNX2FC_MISC_DBG("Entered %s\n", __func__);
2006 /* Kick off FIP/FLOGI */
2007 if (!test_bit(BNX2FC_FLAG_FW_INIT_DONE, &interface->hba->flags)) {
2008 printk(KERN_ERR PFX "Init not done yet\n");
2013 BNX2FC_HBA_DBG(lport, "calling fc_fabric_login\n");
2015 if (!bnx2fc_link_ok(lport) && interface->enabled) {
2016 BNX2FC_HBA_DBG(lport, "ctlr_link_up\n");
2017 fcoe_ctlr_link_up(ctlr);
2018 fc_host_port_type(lport->host) = FC_PORTTYPE_NPORT;
2019 set_bit(ADAPTER_STATE_READY, &interface->hba->adapter_state);
2022 /* wait for the FCF to be selected before issuing FLOGI */
2023 while (!ctlr->sel_fcf) {
2025 /* give up after 3 secs */
2026 if (++wait_cnt > 12)
2030 /* Reset max receive frame size to default */
2031 if (fc_set_mfs(lport, BNX2FC_MFS))
2034 fc_lport_init(lport);
2035 fc_fabric_login(lport);
2040 * bnx2fc_ulp_init - Initialize an adapter instance
2042 * @dev : cnic device handle
2043 * Called from cnic_register_driver() context to initialize all
2044 * enumerated cnic devices. This routine allocates adapter structure
2045 * and other device specific resources.
2047 static void bnx2fc_ulp_init(struct cnic_dev *dev)
2049 struct bnx2fc_hba *hba;
2052 BNX2FC_MISC_DBG("Entered %s\n", __func__);
2053 /* bnx2fc works only when bnx2x is loaded */
2054 if (!test_bit(CNIC_F_BNX2X_CLASS, &dev->flags) ||
2055 (dev->max_fcoe_conn == 0)) {
2056 printk(KERN_ERR PFX "bnx2fc FCoE not supported on %s,"
2057 " flags: %lx fcoe_conn: %d\n",
2058 dev->netdev->name, dev->flags, dev->max_fcoe_conn);
2062 hba = bnx2fc_hba_create(dev);
2064 printk(KERN_ERR PFX "hba initialization failed\n");
2068 pr_info(PFX "FCoE initialized for %s.\n", dev->netdev->name);
2070 /* Add HBA to the adapter list */
2071 mutex_lock(&bnx2fc_dev_lock);
2072 list_add_tail(&hba->list, &adapter_list);
2074 mutex_unlock(&bnx2fc_dev_lock);
2076 dev->fcoe_cap = &hba->fcoe_cap;
2077 clear_bit(BNX2FC_CNIC_REGISTERED, &hba->reg_with_cnic);
2078 rc = dev->register_device(dev, CNIC_ULP_FCOE,
2081 printk(KERN_ERR PFX "register_device failed, rc = %d\n", rc);
2083 set_bit(BNX2FC_CNIC_REGISTERED, &hba->reg_with_cnic);
2086 /* Assumes rtnl_lock and the bnx2fc_dev_lock are already taken */
2087 static int __bnx2fc_disable(struct fcoe_ctlr *ctlr)
2089 struct bnx2fc_interface *interface = fcoe_ctlr_priv(ctlr);
2091 if (interface->enabled == true) {
2093 pr_err(PFX "__bnx2fc_disable: lport not found\n");
2096 interface->enabled = false;
2097 fcoe_ctlr_link_down(ctlr);
2098 fcoe_clean_pending_queue(ctlr->lp);
2105 * Deperecated: Use bnx2fc_enabled()
2107 static int bnx2fc_disable(struct net_device *netdev)
2109 struct bnx2fc_interface *interface;
2110 struct fcoe_ctlr *ctlr;
2114 mutex_lock(&bnx2fc_dev_lock);
2116 interface = bnx2fc_interface_lookup(netdev);
2117 ctlr = bnx2fc_to_ctlr(interface);
2121 pr_err(PFX "bnx2fc_disable: interface not found\n");
2123 rc = __bnx2fc_disable(ctlr);
2125 mutex_unlock(&bnx2fc_dev_lock);
2130 static uint bnx2fc_npiv_create_vports(struct fc_lport *lport,
2131 struct cnic_fc_npiv_tbl *npiv_tbl)
2133 struct fc_vport_identifiers vpid;
2134 uint i, created = 0;
2139 if (npiv_tbl->count > MAX_NPIV_ENTRIES) {
2140 BNX2FC_HBA_DBG(lport, "Exceeded count max of npiv table\n");
2144 /* Sanity check the first entry to make sure it's not 0 */
2145 if (wwn_to_u64(npiv_tbl->wwnn[0]) == 0 &&
2146 wwn_to_u64(npiv_tbl->wwpn[0]) == 0) {
2147 BNX2FC_HBA_DBG(lport, "First NPIV table entries invalid.\n");
2151 vpid.roles = FC_PORT_ROLE_FCP_INITIATOR;
2152 vpid.vport_type = FC_PORTTYPE_NPIV;
2153 vpid.disable = false;
2155 for (i = 0; i < npiv_tbl->count; i++) {
2156 wwnn = wwn_to_u64(npiv_tbl->wwnn[i]);
2159 * If we get a 0 element from for the WWNN then assume
2160 * the WWNN should be the same as the physical port.
2164 vpid.node_name = wwnn;
2165 vpid.port_name = wwn_to_u64(npiv_tbl->wwpn[i]);
2166 scnprintf(vpid.symbolic_name, sizeof(vpid.symbolic_name),
2167 "NPIV[%u]:%016llx-%016llx",
2168 created, vpid.port_name, vpid.node_name);
2169 fcoe_wwn_to_str(vpid.node_name, wwnn_str, sizeof(wwnn_str));
2170 fcoe_wwn_to_str(vpid.port_name, wwpn_str, sizeof(wwpn_str));
2171 BNX2FC_HBA_DBG(lport, "Creating vport %s:%s.\n", wwnn_str,
2173 if (fc_vport_create(lport->host, 0, &vpid))
2176 BNX2FC_HBA_DBG(lport, "Failed to create vport\n");
2182 static int __bnx2fc_enable(struct fcoe_ctlr *ctlr)
2184 struct bnx2fc_interface *interface = fcoe_ctlr_priv(ctlr);
2185 struct bnx2fc_hba *hba;
2186 struct cnic_fc_npiv_tbl *npiv_tbl;
2187 struct fc_lport *lport;
2189 if (interface->enabled == false) {
2191 pr_err(PFX "__bnx2fc_enable: lport not found\n");
2193 } else if (!bnx2fc_link_ok(ctlr->lp)) {
2194 fcoe_ctlr_link_up(ctlr);
2195 interface->enabled = true;
2199 /* Create static NPIV ports if any are contained in NVRAM */
2200 hba = interface->hba;
2215 if (!hba->cnic->get_fc_npiv_tbl)
2218 npiv_tbl = kzalloc(sizeof(struct cnic_fc_npiv_tbl), GFP_KERNEL);
2222 if (hba->cnic->get_fc_npiv_tbl(hba->cnic, npiv_tbl))
2225 bnx2fc_npiv_create_vports(lport, npiv_tbl);
2233 * Deprecated: Use bnx2fc_enabled()
2235 static int bnx2fc_enable(struct net_device *netdev)
2237 struct bnx2fc_interface *interface;
2238 struct fcoe_ctlr *ctlr;
2242 mutex_lock(&bnx2fc_dev_lock);
2244 interface = bnx2fc_interface_lookup(netdev);
2245 ctlr = bnx2fc_to_ctlr(interface);
2248 pr_err(PFX "bnx2fc_enable: interface not found\n");
2250 rc = __bnx2fc_enable(ctlr);
2253 mutex_unlock(&bnx2fc_dev_lock);
2259 * bnx2fc_ctlr_enabled() - Enable or disable an FCoE Controller
2260 * @cdev: The FCoE Controller that is being enabled or disabled
2262 * fcoe_sysfs will ensure that the state of 'enabled' has
2263 * changed, so no checking is necessary here. This routine simply
2264 * calls fcoe_enable or fcoe_disable, both of which are deprecated.
2265 * When those routines are removed the functionality can be merged
2268 static int bnx2fc_ctlr_enabled(struct fcoe_ctlr_device *cdev)
2270 struct fcoe_ctlr *ctlr = fcoe_ctlr_device_priv(cdev);
2272 switch (cdev->enabled) {
2273 case FCOE_CTLR_ENABLED:
2274 return __bnx2fc_enable(ctlr);
2275 case FCOE_CTLR_DISABLED:
2276 return __bnx2fc_disable(ctlr);
2277 case FCOE_CTLR_UNUSED:
2283 enum bnx2fc_create_link_state {
2284 BNX2FC_CREATE_LINK_DOWN,
2285 BNX2FC_CREATE_LINK_UP,
2289 * _bnx2fc_create() - Create bnx2fc FCoE interface
2290 * @netdev : The net_device object the Ethernet interface to create on
2291 * @fip_mode: The FIP mode for this creation
2292 * @link_state: The ctlr link state on creation
2294 * Called from either the libfcoe 'create' module parameter
2295 * via fcoe_create or from fcoe_syfs's ctlr_create file.
2297 * libfcoe's 'create' module parameter is deprecated so some
2298 * consolidation of code can be done when that interface is
2301 * Returns: 0 for success
2303 static int _bnx2fc_create(struct net_device *netdev,
2304 enum fip_mode fip_mode,
2305 enum bnx2fc_create_link_state link_state)
2307 struct fcoe_ctlr_device *cdev;
2308 struct fcoe_ctlr *ctlr;
2309 struct bnx2fc_interface *interface;
2310 struct bnx2fc_hba *hba;
2311 struct net_device *phys_dev = netdev;
2312 struct fc_lport *lport;
2313 struct ethtool_drvinfo drvinfo;
2317 BNX2FC_MISC_DBG("Entered bnx2fc_create\n");
2318 if (fip_mode != FIP_MODE_FABRIC) {
2319 printk(KERN_ERR "fip mode not FABRIC\n");
2325 mutex_lock(&bnx2fc_dev_lock);
2327 if (!try_module_get(THIS_MODULE)) {
2332 /* obtain physical netdev */
2333 if (is_vlan_dev(netdev))
2334 phys_dev = vlan_dev_real_dev(netdev);
2336 /* verify if the physical device is a netxtreme2 device */
2337 if (phys_dev->ethtool_ops && phys_dev->ethtool_ops->get_drvinfo) {
2338 memset(&drvinfo, 0, sizeof(drvinfo));
2339 phys_dev->ethtool_ops->get_drvinfo(phys_dev, &drvinfo);
2340 if (strncmp(drvinfo.driver, "bnx2x", strlen("bnx2x"))) {
2341 printk(KERN_ERR PFX "Not a netxtreme2 device\n");
2346 printk(KERN_ERR PFX "unable to obtain drv_info\n");
2351 /* obtain interface and initialize rest of the structure */
2352 hba = bnx2fc_hba_lookup(phys_dev);
2355 printk(KERN_ERR PFX "bnx2fc_create: hba not found\n");
2359 if (bnx2fc_interface_lookup(netdev)) {
2364 interface = bnx2fc_interface_create(hba, netdev, fip_mode);
2366 printk(KERN_ERR PFX "bnx2fc_interface_create failed\n");
2371 if (is_vlan_dev(netdev)) {
2372 vlan_id = vlan_dev_vlan_id(netdev);
2373 interface->vlan_enabled = 1;
2376 ctlr = bnx2fc_to_ctlr(interface);
2377 cdev = fcoe_ctlr_to_ctlr_dev(ctlr);
2378 interface->vlan_id = vlan_id;
2379 interface->tm_timeout = BNX2FC_TM_TIMEOUT;
2381 interface->timer_work_queue =
2382 create_singlethread_workqueue("bnx2fc_timer_wq");
2383 if (!interface->timer_work_queue) {
2384 printk(KERN_ERR PFX "ulp_init could not create timer_wq\n");
2389 lport = bnx2fc_if_create(interface, &cdev->dev, 0);
2391 printk(KERN_ERR PFX "Failed to create interface (%s)\n",
2397 /* Add interface to if_list */
2398 list_add_tail(&interface->list, &if_list);
2400 lport->boot_time = jiffies;
2402 /* Make this master N_port */
2405 if (link_state == BNX2FC_CREATE_LINK_UP)
2406 cdev->enabled = FCOE_CTLR_ENABLED;
2408 cdev->enabled = FCOE_CTLR_DISABLED;
2410 if (link_state == BNX2FC_CREATE_LINK_UP &&
2411 !bnx2fc_link_ok(lport)) {
2412 fcoe_ctlr_link_up(ctlr);
2413 fc_host_port_type(lport->host) = FC_PORTTYPE_NPORT;
2414 set_bit(ADAPTER_STATE_READY, &interface->hba->adapter_state);
2417 BNX2FC_HBA_DBG(lport, "create: START DISC\n");
2418 bnx2fc_start_disc(interface);
2420 if (link_state == BNX2FC_CREATE_LINK_UP)
2421 interface->enabled = true;
2424 * Release from kref_init in bnx2fc_interface_setup, on success
2425 * lport should be holding a reference taken in bnx2fc_if_create
2427 bnx2fc_interface_put(interface);
2428 /* put netdev that was held while calling dev_get_by_name */
2429 mutex_unlock(&bnx2fc_dev_lock);
2434 destroy_workqueue(interface->timer_work_queue);
2436 bnx2fc_net_cleanup(interface);
2437 bnx2fc_interface_put(interface);
2440 module_put(THIS_MODULE);
2442 mutex_unlock(&bnx2fc_dev_lock);
2448 * bnx2fc_create() - Create a bnx2fc interface
2449 * @netdev : The net_device object the Ethernet interface to create on
2450 * @fip_mode: The FIP mode for this creation
2452 * Called from fcoe transport
2454 * Returns: 0 for success
2456 static int bnx2fc_create(struct net_device *netdev, enum fip_mode fip_mode)
2458 return _bnx2fc_create(netdev, fip_mode, BNX2FC_CREATE_LINK_UP);
2462 * bnx2fc_ctlr_alloc() - Allocate a bnx2fc interface from fcoe_sysfs
2463 * @netdev: The net_device to be used by the allocated FCoE Controller
2465 * This routine is called from fcoe_sysfs. It will start the fcoe_ctlr
2466 * in a link_down state. The allows the user an opportunity to configure
2467 * the FCoE Controller from sysfs before enabling the FCoE Controller.
2469 * Creating in with this routine starts the FCoE Controller in Fabric
2470 * mode. The user can change to VN2VN or another mode before enabling.
2472 static int bnx2fc_ctlr_alloc(struct net_device *netdev)
2474 return _bnx2fc_create(netdev, FIP_MODE_FABRIC,
2475 BNX2FC_CREATE_LINK_DOWN);
2479 * bnx2fc_find_hba_for_cnic - maps cnic instance to bnx2fc hba instance
2481 * @cnic: Pointer to cnic device instance
2484 static struct bnx2fc_hba *bnx2fc_find_hba_for_cnic(struct cnic_dev *cnic)
2486 struct bnx2fc_hba *hba;
2488 /* Called with bnx2fc_dev_lock held */
2489 list_for_each_entry(hba, &adapter_list, list) {
2490 if (hba->cnic == cnic)
2496 static struct bnx2fc_interface *bnx2fc_interface_lookup(struct net_device
2499 struct bnx2fc_interface *interface;
2501 /* Called with bnx2fc_dev_lock held */
2502 list_for_each_entry(interface, &if_list, list) {
2503 if (interface->netdev == netdev)
2509 static struct bnx2fc_hba *bnx2fc_hba_lookup(struct net_device
2512 struct bnx2fc_hba *hba;
2514 /* Called with bnx2fc_dev_lock held */
2515 list_for_each_entry(hba, &adapter_list, list) {
2516 if (hba->phys_dev == phys_dev)
2519 printk(KERN_ERR PFX "adapter_lookup: hba NULL\n");
2524 * bnx2fc_ulp_exit - shuts down adapter instance and frees all resources
2526 * @dev: cnic device handle
2528 static void bnx2fc_ulp_exit(struct cnic_dev *dev)
2530 struct bnx2fc_hba *hba;
2531 struct bnx2fc_interface *interface, *tmp;
2533 BNX2FC_MISC_DBG("Entered bnx2fc_ulp_exit\n");
2535 if (!test_bit(CNIC_F_BNX2X_CLASS, &dev->flags)) {
2536 printk(KERN_ERR PFX "bnx2fc port check: %s, flags: %lx\n",
2537 dev->netdev->name, dev->flags);
2541 mutex_lock(&bnx2fc_dev_lock);
2542 hba = bnx2fc_find_hba_for_cnic(dev);
2544 printk(KERN_ERR PFX "bnx2fc_ulp_exit: hba not found, dev 0%p\n",
2546 mutex_unlock(&bnx2fc_dev_lock);
2550 list_del_init(&hba->list);
2553 list_for_each_entry_safe(interface, tmp, &if_list, list)
2554 /* destroy not called yet, move to quiesced list */
2555 if (interface->hba == hba)
2556 __bnx2fc_destroy(interface);
2557 mutex_unlock(&bnx2fc_dev_lock);
2559 /* Ensure ALL destroy work has been completed before return */
2560 flush_workqueue(bnx2fc_wq);
2562 bnx2fc_ulp_stop(hba);
2563 /* unregister cnic device */
2564 if (test_and_clear_bit(BNX2FC_CNIC_REGISTERED, &hba->reg_with_cnic))
2565 hba->cnic->unregister_device(hba->cnic, CNIC_ULP_FCOE);
2566 bnx2fc_hba_destroy(hba);
2569 static void bnx2fc_rport_terminate_io(struct fc_rport *rport)
2571 /* This is a no-op */
2575 * bnx2fc_fcoe_reset - Resets the fcoe
2577 * @shost: shost the reset is from
2581 static int bnx2fc_fcoe_reset(struct Scsi_Host *shost)
2583 struct fc_lport *lport = shost_priv(shost);
2584 fc_lport_reset(lport);
2589 static bool bnx2fc_match(struct net_device *netdev)
2591 struct net_device *phys_dev = netdev;
2593 mutex_lock(&bnx2fc_dev_lock);
2594 if (is_vlan_dev(netdev))
2595 phys_dev = vlan_dev_real_dev(netdev);
2597 if (bnx2fc_hba_lookup(phys_dev)) {
2598 mutex_unlock(&bnx2fc_dev_lock);
2602 mutex_unlock(&bnx2fc_dev_lock);
2607 static struct fcoe_transport bnx2fc_transport = {
2610 .list = LIST_HEAD_INIT(bnx2fc_transport.list),
2611 .alloc = bnx2fc_ctlr_alloc,
2612 .match = bnx2fc_match,
2613 .create = bnx2fc_create,
2614 .destroy = bnx2fc_destroy,
2615 .enable = bnx2fc_enable,
2616 .disable = bnx2fc_disable,
2620 * bnx2fc_cpu_online - Create a receive thread for an online CPU
2622 * @cpu: cpu index for the online cpu
2624 static int bnx2fc_cpu_online(unsigned int cpu)
2626 struct bnx2fc_percpu_s *p;
2627 struct task_struct *thread;
2629 p = &per_cpu(bnx2fc_percpu, cpu);
2631 thread = kthread_create_on_node(bnx2fc_percpu_io_thread,
2632 (void *)p, cpu_to_node(cpu),
2633 "bnx2fc_thread/%d", cpu);
2635 return PTR_ERR(thread);
2637 /* bind thread to the cpu */
2638 kthread_bind(thread, cpu);
2639 p->iothread = thread;
2640 wake_up_process(thread);
2644 static int bnx2fc_cpu_offline(unsigned int cpu)
2646 struct bnx2fc_percpu_s *p;
2647 struct task_struct *thread;
2648 struct bnx2fc_work *work, *tmp;
2650 BNX2FC_MISC_DBG("destroying io thread for CPU %d\n", cpu);
2652 /* Prevent any new work from being queued for this CPU */
2653 p = &per_cpu(bnx2fc_percpu, cpu);
2654 spin_lock_bh(&p->fp_work_lock);
2655 thread = p->iothread;
2658 /* Free all work in the list */
2659 list_for_each_entry_safe(work, tmp, &p->work_list, list) {
2660 list_del_init(&work->list);
2661 bnx2fc_process_cq_compl(work->tgt, work->wqe, work->rq_data,
2662 work->num_rq, work->task);
2666 spin_unlock_bh(&p->fp_work_lock);
2669 kthread_stop(thread);
2673 static int bnx2fc_slave_configure(struct scsi_device *sdev)
2675 if (!bnx2fc_queue_depth)
2678 scsi_change_queue_depth(sdev, bnx2fc_queue_depth);
2682 static enum cpuhp_state bnx2fc_online_state;
2685 * bnx2fc_mod_init - module init entry point
2687 * Initialize driver wide global data structures, and register
2690 static int __init bnx2fc_mod_init(void)
2692 struct fcoe_percpu_s *bg;
2693 struct task_struct *l2_thread;
2695 unsigned int cpu = 0;
2696 struct bnx2fc_percpu_s *p;
2698 printk(KERN_INFO PFX "%s", version);
2700 /* register as a fcoe transport */
2701 rc = fcoe_transport_attach(&bnx2fc_transport);
2703 printk(KERN_ERR "failed to register an fcoe transport, check "
2704 "if libfcoe is loaded\n");
2708 INIT_LIST_HEAD(&adapter_list);
2709 INIT_LIST_HEAD(&if_list);
2710 mutex_init(&bnx2fc_dev_lock);
2713 /* Attach FC transport template */
2714 rc = bnx2fc_attach_transport();
2718 bnx2fc_wq = alloc_workqueue("bnx2fc", 0, 0);
2724 bg = &bnx2fc_global;
2725 skb_queue_head_init(&bg->fcoe_rx_list);
2726 l2_thread = kthread_create(bnx2fc_l2_rcv_thread,
2728 "bnx2fc_l2_thread");
2729 if (IS_ERR(l2_thread)) {
2730 rc = PTR_ERR(l2_thread);
2733 wake_up_process(l2_thread);
2734 spin_lock_bh(&bg->fcoe_rx_list.lock);
2735 bg->kthread = l2_thread;
2736 spin_unlock_bh(&bg->fcoe_rx_list.lock);
2738 for_each_possible_cpu(cpu) {
2739 p = &per_cpu(bnx2fc_percpu, cpu);
2740 INIT_LIST_HEAD(&p->work_list);
2741 spin_lock_init(&p->fp_work_lock);
2744 rc = cpuhp_setup_state(CPUHP_AP_ONLINE_DYN, "scsi/bnx2fc:online",
2745 bnx2fc_cpu_online, bnx2fc_cpu_offline);
2748 bnx2fc_online_state = rc;
2750 cnic_register_driver(CNIC_ULP_FCOE, &bnx2fc_cnic_cb);
2754 kthread_stop(l2_thread);
2756 destroy_workqueue(bnx2fc_wq);
2758 bnx2fc_release_transport();
2760 fcoe_transport_detach(&bnx2fc_transport);
2765 static void __exit bnx2fc_mod_exit(void)
2767 LIST_HEAD(to_be_deleted);
2768 struct bnx2fc_hba *hba, *next;
2769 struct fcoe_percpu_s *bg;
2770 struct task_struct *l2_thread;
2771 struct sk_buff *skb;
2774 * NOTE: Since cnic calls register_driver routine rtnl_lock,
2775 * it will have higher precedence than bnx2fc_dev_lock.
2776 * unregister_device() cannot be called with bnx2fc_dev_lock
2779 mutex_lock(&bnx2fc_dev_lock);
2780 list_splice_init(&adapter_list, &to_be_deleted);
2782 mutex_unlock(&bnx2fc_dev_lock);
2784 /* Unregister with cnic */
2785 list_for_each_entry_safe(hba, next, &to_be_deleted, list) {
2786 list_del_init(&hba->list);
2787 printk(KERN_ERR PFX "MOD_EXIT:destroy hba = 0x%p\n",
2789 bnx2fc_ulp_stop(hba);
2790 /* unregister cnic device */
2791 if (test_and_clear_bit(BNX2FC_CNIC_REGISTERED,
2792 &hba->reg_with_cnic))
2793 hba->cnic->unregister_device(hba->cnic,
2795 bnx2fc_hba_destroy(hba);
2797 cnic_unregister_driver(CNIC_ULP_FCOE);
2799 /* Destroy global thread */
2800 bg = &bnx2fc_global;
2801 spin_lock_bh(&bg->fcoe_rx_list.lock);
2802 l2_thread = bg->kthread;
2804 while ((skb = __skb_dequeue(&bg->fcoe_rx_list)) != NULL)
2807 spin_unlock_bh(&bg->fcoe_rx_list.lock);
2810 kthread_stop(l2_thread);
2812 cpuhp_remove_state(bnx2fc_online_state);
2814 destroy_workqueue(bnx2fc_wq);
2816 * detach from scsi transport
2817 * must happen after all destroys are done
2819 bnx2fc_release_transport();
2821 /* detach from fcoe transport */
2822 fcoe_transport_detach(&bnx2fc_transport);
2825 module_init(bnx2fc_mod_init);
2826 module_exit(bnx2fc_mod_exit);
2828 static struct fcoe_sysfs_function_template bnx2fc_fcoe_sysfs_templ = {
2829 .set_fcoe_ctlr_enabled = bnx2fc_ctlr_enabled,
2830 .get_fcoe_ctlr_link_fail = fcoe_ctlr_get_lesb,
2831 .get_fcoe_ctlr_vlink_fail = fcoe_ctlr_get_lesb,
2832 .get_fcoe_ctlr_miss_fka = fcoe_ctlr_get_lesb,
2833 .get_fcoe_ctlr_symb_err = fcoe_ctlr_get_lesb,
2834 .get_fcoe_ctlr_err_block = fcoe_ctlr_get_lesb,
2835 .get_fcoe_ctlr_fcs_error = fcoe_ctlr_get_lesb,
2837 .get_fcoe_fcf_selected = fcoe_fcf_get_selected,
2838 .get_fcoe_fcf_vlan_id = bnx2fc_fcf_get_vlan_id,
2841 static struct fc_function_template bnx2fc_transport_function = {
2842 .show_host_node_name = 1,
2843 .show_host_port_name = 1,
2844 .show_host_supported_classes = 1,
2845 .show_host_supported_fc4s = 1,
2846 .show_host_active_fc4s = 1,
2847 .show_host_maxframe_size = 1,
2849 .show_host_port_id = 1,
2850 .show_host_supported_speeds = 1,
2851 .get_host_speed = fc_get_host_speed,
2852 .show_host_speed = 1,
2853 .show_host_port_type = 1,
2854 .get_host_port_state = fc_get_host_port_state,
2855 .show_host_port_state = 1,
2856 .show_host_symbolic_name = 1,
2858 .dd_fcrport_size = (sizeof(struct fc_rport_libfc_priv) +
2859 sizeof(struct bnx2fc_rport)),
2860 .show_rport_maxframe_size = 1,
2861 .show_rport_supported_classes = 1,
2863 .show_host_fabric_name = 1,
2864 .show_starget_node_name = 1,
2865 .show_starget_port_name = 1,
2866 .show_starget_port_id = 1,
2867 .set_rport_dev_loss_tmo = fc_set_rport_loss_tmo,
2868 .show_rport_dev_loss_tmo = 1,
2869 .get_fc_host_stats = bnx2fc_get_host_stats,
2871 .issue_fc_host_lip = bnx2fc_fcoe_reset,
2873 .terminate_rport_io = bnx2fc_rport_terminate_io,
2875 .vport_create = bnx2fc_vport_create,
2876 .vport_delete = bnx2fc_vport_destroy,
2877 .vport_disable = bnx2fc_vport_disable,
2878 .bsg_request = fc_lport_bsg_request,
2881 static struct fc_function_template bnx2fc_vport_xport_function = {
2882 .show_host_node_name = 1,
2883 .show_host_port_name = 1,
2884 .show_host_supported_classes = 1,
2885 .show_host_supported_fc4s = 1,
2886 .show_host_active_fc4s = 1,
2887 .show_host_maxframe_size = 1,
2889 .show_host_port_id = 1,
2890 .show_host_supported_speeds = 1,
2891 .get_host_speed = fc_get_host_speed,
2892 .show_host_speed = 1,
2893 .show_host_port_type = 1,
2894 .get_host_port_state = fc_get_host_port_state,
2895 .show_host_port_state = 1,
2896 .show_host_symbolic_name = 1,
2898 .dd_fcrport_size = (sizeof(struct fc_rport_libfc_priv) +
2899 sizeof(struct bnx2fc_rport)),
2900 .show_rport_maxframe_size = 1,
2901 .show_rport_supported_classes = 1,
2903 .show_host_fabric_name = 1,
2904 .show_starget_node_name = 1,
2905 .show_starget_port_name = 1,
2906 .show_starget_port_id = 1,
2907 .set_rport_dev_loss_tmo = fc_set_rport_loss_tmo,
2908 .show_rport_dev_loss_tmo = 1,
2909 .get_fc_host_stats = fc_get_host_stats,
2910 .issue_fc_host_lip = bnx2fc_fcoe_reset,
2911 .terminate_rport_io = fc_rport_terminate_io,
2912 .bsg_request = fc_lport_bsg_request,
2916 * Additional scsi_host attributes.
2919 bnx2fc_tm_timeout_show(struct device *dev, struct device_attribute *attr,
2922 struct Scsi_Host *shost = class_to_shost(dev);
2923 struct fc_lport *lport = shost_priv(shost);
2924 struct fcoe_port *port = lport_priv(lport);
2925 struct bnx2fc_interface *interface = port->priv;
2927 sprintf(buf, "%u\n", interface->tm_timeout);
2932 bnx2fc_tm_timeout_store(struct device *dev,
2933 struct device_attribute *attr, const char *buf, size_t count)
2935 struct Scsi_Host *shost = class_to_shost(dev);
2936 struct fc_lport *lport = shost_priv(shost);
2937 struct fcoe_port *port = lport_priv(lport);
2938 struct bnx2fc_interface *interface = port->priv;
2941 rval = kstrtouint(buf, 10, &val);
2947 interface->tm_timeout = (u8)val;
2951 static DEVICE_ATTR(tm_timeout, S_IRUGO|S_IWUSR, bnx2fc_tm_timeout_show,
2952 bnx2fc_tm_timeout_store);
2954 static struct device_attribute *bnx2fc_host_attrs[] = {
2955 &dev_attr_tm_timeout,
2960 * scsi_host_template structure used while registering with SCSI-ml
2962 static struct scsi_host_template bnx2fc_shost_template = {
2963 .module = THIS_MODULE,
2964 .name = "QLogic Offload FCoE Initiator",
2965 .queuecommand = bnx2fc_queuecommand,
2966 .eh_timed_out = fc_eh_timed_out,
2967 .eh_abort_handler = bnx2fc_eh_abort, /* abts */
2968 .eh_device_reset_handler = bnx2fc_eh_device_reset, /* lun reset */
2969 .eh_target_reset_handler = bnx2fc_eh_target_reset, /* tgt reset */
2970 .eh_host_reset_handler = fc_eh_host_reset,
2971 .slave_alloc = fc_slave_alloc,
2972 .change_queue_depth = scsi_change_queue_depth,
2975 .sg_tablesize = BNX2FC_MAX_BDS_PER_CMD,
2976 .dma_boundary = 0x7fff,
2977 .max_sectors = 0x3fbf,
2978 .track_queue_depth = 1,
2979 .slave_configure = bnx2fc_slave_configure,
2980 .shost_attrs = bnx2fc_host_attrs,
2983 static struct libfc_function_template bnx2fc_libfc_fcn_templ = {
2984 .frame_send = bnx2fc_xmit,
2985 .elsct_send = bnx2fc_elsct_send,
2986 .fcp_abort_io = bnx2fc_abort_io,
2987 .fcp_cleanup = bnx2fc_cleanup,
2988 .get_lesb = fcoe_get_lesb,
2989 .rport_event_callback = bnx2fc_rport_event_handler,
2993 * bnx2fc_cnic_cb - global template of bnx2fc - cnic driver interface
2994 * structure carrying callback function pointers
2996 static struct cnic_ulp_ops bnx2fc_cnic_cb = {
2997 .owner = THIS_MODULE,
2998 .cnic_init = bnx2fc_ulp_init,
2999 .cnic_exit = bnx2fc_ulp_exit,
3000 .cnic_start = bnx2fc_ulp_start,
3001 .cnic_stop = bnx2fc_ulp_stop,
3002 .indicate_kcqes = bnx2fc_indicate_kcqe,
3003 .indicate_netevent = bnx2fc_indicate_netevent,
3004 .cnic_get_stats = bnx2fc_ulp_get_stats,