1 /* bnx2fc_fcoe.c: QLogic Linux FCoE offload driver.
2 * This file contains the code that interacts with libfc, libfcoe,
3 * cnic modules to create FCoE instances, send/receive non-offloaded
4 * FIP/FCoE packets, listen to link events etc.
6 * Copyright (c) 2008-2013 Broadcom Corporation
7 * Copyright (c) 2014-2016 QLogic Corporation
8 * Copyright (c) 2016-2017 Cavium Inc.
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation.
14 * Written by: Bhanu Prakash Gollapudi (bprakash@broadcom.com)
19 static struct list_head adapter_list;
20 static struct list_head if_list;
21 static u32 adapter_count;
22 static DEFINE_MUTEX(bnx2fc_dev_lock);
23 DEFINE_PER_CPU(struct bnx2fc_percpu_s, bnx2fc_percpu);
25 #define DRV_MODULE_NAME "bnx2fc"
26 #define DRV_MODULE_VERSION BNX2FC_VERSION
27 #define DRV_MODULE_RELDATE "October 15, 2015"
30 static char version[] =
31 "QLogic FCoE Driver " DRV_MODULE_NAME \
32 " v" DRV_MODULE_VERSION " (" DRV_MODULE_RELDATE ")\n";
35 MODULE_AUTHOR("Bhanu Prakash Gollapudi <bprakash@broadcom.com>");
36 MODULE_DESCRIPTION("QLogic FCoE Driver");
37 MODULE_LICENSE("GPL");
38 MODULE_VERSION(DRV_MODULE_VERSION);
40 #define BNX2FC_MAX_QUEUE_DEPTH 256
41 #define BNX2FC_MIN_QUEUE_DEPTH 32
42 #define FCOE_WORD_TO_BYTE 4
44 static struct scsi_transport_template *bnx2fc_transport_template;
45 static struct scsi_transport_template *bnx2fc_vport_xport_template;
47 struct workqueue_struct *bnx2fc_wq;
49 /* bnx2fc structure needs only one instance of the fcoe_percpu_s structure.
50 * Here the io threads are per cpu but the l2 thread is just one
52 struct fcoe_percpu_s bnx2fc_global;
53 DEFINE_SPINLOCK(bnx2fc_global_lock);
55 static struct cnic_ulp_ops bnx2fc_cnic_cb;
56 static struct libfc_function_template bnx2fc_libfc_fcn_templ;
57 static struct scsi_host_template bnx2fc_shost_template;
58 static struct fc_function_template bnx2fc_transport_function;
59 static struct fcoe_sysfs_function_template bnx2fc_fcoe_sysfs_templ;
60 static struct fc_function_template bnx2fc_vport_xport_function;
61 static int bnx2fc_create(struct net_device *netdev, enum fip_mode fip_mode);
62 static void __bnx2fc_destroy(struct bnx2fc_interface *interface);
63 static int bnx2fc_destroy(struct net_device *net_device);
64 static int bnx2fc_enable(struct net_device *netdev);
65 static int bnx2fc_disable(struct net_device *netdev);
67 /* fcoe_syfs control interface handlers */
68 static int bnx2fc_ctlr_alloc(struct net_device *netdev);
69 static int bnx2fc_ctlr_enabled(struct fcoe_ctlr_device *cdev);
71 static void bnx2fc_recv_frame(struct sk_buff *skb);
73 static void bnx2fc_start_disc(struct bnx2fc_interface *interface);
74 static int bnx2fc_shost_config(struct fc_lport *lport, struct device *dev);
75 static int bnx2fc_lport_config(struct fc_lport *lport);
76 static int bnx2fc_em_config(struct fc_lport *lport, struct bnx2fc_hba *hba);
77 static int bnx2fc_bind_adapter_devices(struct bnx2fc_hba *hba);
78 static void bnx2fc_unbind_adapter_devices(struct bnx2fc_hba *hba);
79 static int bnx2fc_bind_pcidev(struct bnx2fc_hba *hba);
80 static void bnx2fc_unbind_pcidev(struct bnx2fc_hba *hba);
81 static struct fc_lport *bnx2fc_if_create(struct bnx2fc_interface *interface,
82 struct device *parent, int npiv);
83 static void bnx2fc_port_destroy(struct fcoe_port *port);
85 static struct bnx2fc_hba *bnx2fc_hba_lookup(struct net_device *phys_dev);
86 static struct bnx2fc_interface *bnx2fc_interface_lookup(struct net_device
88 static inline void bnx2fc_interface_put(struct bnx2fc_interface *interface);
89 static struct bnx2fc_hba *bnx2fc_find_hba_for_cnic(struct cnic_dev *cnic);
91 static int bnx2fc_fw_init(struct bnx2fc_hba *hba);
92 static void bnx2fc_fw_destroy(struct bnx2fc_hba *hba);
94 static void bnx2fc_port_shutdown(struct fc_lport *lport);
95 static void bnx2fc_stop(struct bnx2fc_interface *interface);
96 static int __init bnx2fc_mod_init(void);
97 static void __exit bnx2fc_mod_exit(void);
99 unsigned int bnx2fc_debug_level;
100 module_param_named(debug_logging, bnx2fc_debug_level, int, S_IRUGO|S_IWUSR);
101 MODULE_PARM_DESC(debug_logging,
102 "Option to enable extended logging,\n"
103 "\t\tDefault is 0 - no logging.\n"
104 "\t\t0x01 - SCSI cmd error, cleanup.\n"
105 "\t\t0x02 - Session setup, cleanup, etc.\n"
106 "\t\t0x04 - lport events, link, mtu, etc.\n"
107 "\t\t0x08 - ELS logs.\n"
108 "\t\t0x10 - fcoe L2 fame related logs.\n"
109 "\t\t0xff - LOG all messages.");
111 uint bnx2fc_devloss_tmo;
112 module_param_named(devloss_tmo, bnx2fc_devloss_tmo, uint, S_IRUGO);
113 MODULE_PARM_DESC(devloss_tmo, " Change devloss_tmo for the remote ports "
114 "attached via bnx2fc.");
116 uint bnx2fc_max_luns = BNX2FC_MAX_LUN;
117 module_param_named(max_luns, bnx2fc_max_luns, uint, S_IRUGO);
118 MODULE_PARM_DESC(max_luns, " Change the default max_lun per SCSI host. Default "
121 uint bnx2fc_queue_depth;
122 module_param_named(queue_depth, bnx2fc_queue_depth, uint, S_IRUGO);
123 MODULE_PARM_DESC(queue_depth, " Change the default queue depth of SCSI devices "
124 "attached via bnx2fc.");
127 module_param_named(log_fka, bnx2fc_log_fka, uint, S_IRUGO|S_IWUSR);
128 MODULE_PARM_DESC(log_fka, " Print message to kernel log when fcoe is "
129 "initiating a FIP keep alive when debug logging is enabled.");
131 static inline struct net_device *bnx2fc_netdev(const struct fc_lport *lport)
133 return ((struct bnx2fc_interface *)
134 ((struct fcoe_port *)lport_priv(lport))->priv)->netdev;
137 static void bnx2fc_fcf_get_vlan_id(struct fcoe_fcf_device *fcf_dev)
139 struct fcoe_ctlr_device *ctlr_dev =
140 fcoe_fcf_dev_to_ctlr_dev(fcf_dev);
141 struct fcoe_ctlr *ctlr = fcoe_ctlr_device_priv(ctlr_dev);
142 struct bnx2fc_interface *fcoe = fcoe_ctlr_priv(ctlr);
144 fcf_dev->vlan_id = fcoe->vlan_id;
147 static void bnx2fc_clean_rx_queue(struct fc_lport *lp)
149 struct fcoe_percpu_s *bg;
150 struct fcoe_rcv_info *fr;
151 struct sk_buff_head *list;
152 struct sk_buff *skb, *next;
153 struct sk_buff *head;
156 spin_lock_bh(&bg->fcoe_rx_list.lock);
157 list = &bg->fcoe_rx_list;
159 for (skb = head; skb != (struct sk_buff *)list;
162 fr = fcoe_dev_from_skb(skb);
163 if (fr->fr_dev == lp) {
164 __skb_unlink(skb, list);
168 spin_unlock_bh(&bg->fcoe_rx_list.lock);
171 int bnx2fc_get_paged_crc_eof(struct sk_buff *skb, int tlen)
174 spin_lock(&bnx2fc_global_lock);
175 rc = fcoe_get_paged_crc_eof(skb, tlen, &bnx2fc_global);
176 spin_unlock(&bnx2fc_global_lock);
181 static void bnx2fc_abort_io(struct fc_lport *lport)
184 * This function is no-op for bnx2fc, but we do
185 * not want to leave it as NULL either, as libfc
186 * can call the default function which is
191 static void bnx2fc_cleanup(struct fc_lport *lport)
193 struct fcoe_port *port = lport_priv(lport);
194 struct bnx2fc_interface *interface = port->priv;
195 struct bnx2fc_hba *hba = interface->hba;
196 struct bnx2fc_rport *tgt;
199 BNX2FC_MISC_DBG("Entered %s\n", __func__);
200 mutex_lock(&hba->hba_mutex);
201 spin_lock_bh(&hba->hba_lock);
202 for (i = 0; i < BNX2FC_NUM_MAX_SESS; i++) {
203 tgt = hba->tgt_ofld_list[i];
205 /* Cleanup IOs belonging to requested vport */
206 if (tgt->port == port) {
207 spin_unlock_bh(&hba->hba_lock);
208 BNX2FC_TGT_DBG(tgt, "flush/cleanup\n");
209 bnx2fc_flush_active_ios(tgt);
210 spin_lock_bh(&hba->hba_lock);
214 spin_unlock_bh(&hba->hba_lock);
215 mutex_unlock(&hba->hba_mutex);
218 static int bnx2fc_xmit_l2_frame(struct bnx2fc_rport *tgt,
221 struct fc_rport_priv *rdata = tgt->rdata;
222 struct fc_frame_header *fh;
225 fh = fc_frame_header_get(fp);
226 BNX2FC_TGT_DBG(tgt, "Xmit L2 frame rport = 0x%x, oxid = 0x%x, "
227 "r_ctl = 0x%x\n", rdata->ids.port_id,
228 ntohs(fh->fh_ox_id), fh->fh_r_ctl);
229 if ((fh->fh_type == FC_TYPE_ELS) &&
230 (fh->fh_r_ctl == FC_RCTL_ELS_REQ)) {
232 switch (fc_frame_payload_op(fp)) {
234 rc = bnx2fc_send_adisc(tgt, fp);
237 rc = bnx2fc_send_logo(tgt, fp);
240 rc = bnx2fc_send_rls(tgt, fp);
245 } else if ((fh->fh_type == FC_TYPE_BLS) &&
246 (fh->fh_r_ctl == FC_RCTL_BA_ABTS))
247 BNX2FC_TGT_DBG(tgt, "ABTS frame\n");
249 BNX2FC_TGT_DBG(tgt, "Send L2 frame type 0x%x "
250 "rctl 0x%x thru non-offload path\n",
251 fh->fh_type, fh->fh_r_ctl);
261 * bnx2fc_xmit - bnx2fc's FCoE frame transmit function
263 * @lport: the associated local port
264 * @fp: the fc_frame to be transmitted
266 static int bnx2fc_xmit(struct fc_lport *lport, struct fc_frame *fp)
269 struct fcoe_crc_eof *cp;
271 struct fc_frame_header *fh;
272 struct bnx2fc_interface *interface;
273 struct fcoe_ctlr *ctlr;
274 struct bnx2fc_hba *hba;
275 struct fcoe_port *port;
277 struct bnx2fc_rport *tgt;
278 struct fc_stats *stats;
281 unsigned int hlen, tlen, elen;
284 port = (struct fcoe_port *)lport_priv(lport);
285 interface = port->priv;
286 ctlr = bnx2fc_to_ctlr(interface);
287 hba = interface->hba;
289 fh = fc_frame_header_get(fp);
292 if (!lport->link_up) {
293 BNX2FC_HBA_DBG(lport, "bnx2fc_xmit link down\n");
298 if (unlikely(fh->fh_r_ctl == FC_RCTL_ELS_REQ)) {
299 if (!ctlr->sel_fcf) {
300 BNX2FC_HBA_DBG(lport, "FCF not selected yet!\n");
304 if (fcoe_ctlr_els_send(ctlr, lport, skb))
312 * Snoop the frame header to check if the frame is for
313 * an offloaded session
316 * tgt_ofld_list access is synchronized using
317 * both hba mutex and hba lock. Atleast hba mutex or
318 * hba lock needs to be held for read access.
321 spin_lock_bh(&hba->hba_lock);
322 tgt = bnx2fc_tgt_lookup(port, ntoh24(fh->fh_d_id));
323 if (tgt && (test_bit(BNX2FC_FLAG_SESSION_READY, &tgt->flags))) {
324 /* This frame is for offloaded session */
325 BNX2FC_HBA_DBG(lport, "xmit: Frame is for offloaded session "
326 "port_id = 0x%x\n", ntoh24(fh->fh_d_id));
327 spin_unlock_bh(&hba->hba_lock);
328 rc = bnx2fc_xmit_l2_frame(tgt, fp);
334 spin_unlock_bh(&hba->hba_lock);
337 elen = sizeof(struct ethhdr);
338 hlen = sizeof(struct fcoe_hdr);
339 tlen = sizeof(struct fcoe_crc_eof);
340 wlen = (skb->len - tlen + sizeof(crc)) / FCOE_WORD_TO_BYTE;
342 skb->ip_summed = CHECKSUM_NONE;
343 crc = fcoe_fc_crc(fp);
345 /* copy port crc and eof to the skb buff */
346 if (skb_is_nonlinear(skb)) {
348 if (bnx2fc_get_paged_crc_eof(skb, tlen)) {
352 frag = &skb_shinfo(skb)->frags[skb_shinfo(skb)->nr_frags - 1];
353 cp = kmap_atomic(skb_frag_page(frag)) + frag->page_offset;
355 cp = skb_put(skb, tlen);
358 memset(cp, 0, sizeof(*cp));
360 cp->fcoe_crc32 = cpu_to_le32(~crc);
361 if (skb_is_nonlinear(skb)) {
366 /* adjust skb network/transport offsets to match mac/fcoe/port */
367 skb_push(skb, elen + hlen);
368 skb_reset_mac_header(skb);
369 skb_reset_network_header(skb);
371 skb->protocol = htons(ETH_P_FCOE);
372 skb->dev = interface->netdev;
374 /* fill up mac and fcoe headers */
376 eh->h_proto = htons(ETH_P_FCOE);
378 fc_fcoe_set_mac(eh->h_dest, fh->fh_d_id);
380 /* insert GW address */
381 memcpy(eh->h_dest, ctlr->dest_addr, ETH_ALEN);
383 if (unlikely(ctlr->flogi_oxid != FC_XID_UNKNOWN))
384 memcpy(eh->h_source, ctlr->ctl_src_addr, ETH_ALEN);
386 memcpy(eh->h_source, port->data_src_addr, ETH_ALEN);
388 hp = (struct fcoe_hdr *)(eh + 1);
389 memset(hp, 0, sizeof(*hp));
391 FC_FCOE_ENCAPS_VER(hp, FC_FCOE_VER);
394 /* fcoe lso, mss is in max_payload which is non-zero for FCP data */
395 if (lport->seq_offload && fr_max_payload(fp)) {
396 skb_shinfo(skb)->gso_type = SKB_GSO_FCOE;
397 skb_shinfo(skb)->gso_size = fr_max_payload(fp);
399 skb_shinfo(skb)->gso_type = 0;
400 skb_shinfo(skb)->gso_size = 0;
404 stats = per_cpu_ptr(lport->stats, get_cpu());
406 stats->TxWords += wlen;
409 /* send down to lld */
411 if (port->fcoe_pending_queue.qlen)
412 fcoe_check_wait_queue(lport, skb);
413 else if (fcoe_start_io(skb))
414 fcoe_check_wait_queue(lport, skb);
420 * bnx2fc_rcv - This is bnx2fc's receive function called by NET_RX_SOFTIRQ
422 * @skb: the receive socket buffer
423 * @dev: associated net device
425 * @olddev: last device
427 * This function receives the packet and builds FC frame and passes it up
429 static int bnx2fc_rcv(struct sk_buff *skb, struct net_device *dev,
430 struct packet_type *ptype, struct net_device *olddev)
432 struct fc_lport *lport;
433 struct bnx2fc_interface *interface;
434 struct fcoe_ctlr *ctlr;
435 struct fc_frame_header *fh;
436 struct fcoe_rcv_info *fr;
437 struct fcoe_percpu_s *bg;
438 struct sk_buff *tmp_skb;
441 interface = container_of(ptype, struct bnx2fc_interface,
443 ctlr = bnx2fc_to_ctlr(interface);
446 if (unlikely(lport == NULL)) {
447 printk(KERN_ERR PFX "bnx2fc_rcv: lport is NULL\n");
451 tmp_skb = skb_share_check(skb, GFP_ATOMIC);
457 if (unlikely(eth_hdr(skb)->h_proto != htons(ETH_P_FCOE))) {
458 printk(KERN_ERR PFX "bnx2fc_rcv: Wrong FC type frame\n");
463 * Check for minimum frame length, and make sure required FCoE
464 * and FC headers are pulled into the linear data area.
466 if (unlikely((skb->len < FCOE_MIN_FRAME) ||
467 !pskb_may_pull(skb, FCOE_HEADER_LEN)))
470 skb_set_transport_header(skb, sizeof(struct fcoe_hdr));
471 fh = (struct fc_frame_header *) skb_transport_header(skb);
473 oxid = ntohs(fh->fh_ox_id);
475 fr = fcoe_dev_from_skb(skb);
479 spin_lock(&bg->fcoe_rx_list.lock);
481 __skb_queue_tail(&bg->fcoe_rx_list, skb);
482 if (bg->fcoe_rx_list.qlen == 1)
483 wake_up_process(bg->kthread);
485 spin_unlock(&bg->fcoe_rx_list.lock);
493 static int bnx2fc_l2_rcv_thread(void *arg)
495 struct fcoe_percpu_s *bg = arg;
498 set_user_nice(current, MIN_NICE);
499 set_current_state(TASK_INTERRUPTIBLE);
500 while (!kthread_should_stop()) {
502 spin_lock_bh(&bg->fcoe_rx_list.lock);
503 while ((skb = __skb_dequeue(&bg->fcoe_rx_list)) != NULL) {
504 spin_unlock_bh(&bg->fcoe_rx_list.lock);
505 bnx2fc_recv_frame(skb);
506 spin_lock_bh(&bg->fcoe_rx_list.lock);
508 __set_current_state(TASK_INTERRUPTIBLE);
509 spin_unlock_bh(&bg->fcoe_rx_list.lock);
511 __set_current_state(TASK_RUNNING);
516 static void bnx2fc_recv_frame(struct sk_buff *skb)
520 struct fc_lport *lport;
521 struct fcoe_rcv_info *fr;
522 struct fc_stats *stats;
523 struct fc_frame_header *fh;
524 struct fcoe_crc_eof crc_eof;
526 struct fc_lport *vn_port;
527 struct fcoe_port *port, *phys_port;
531 struct bnx2fc_interface *interface;
532 struct fcoe_ctlr *ctlr;
534 fr = fcoe_dev_from_skb(skb);
536 if (unlikely(lport == NULL)) {
537 printk(KERN_ERR PFX "Invalid lport struct\n");
542 if (skb_is_nonlinear(skb))
544 mac = eth_hdr(skb)->h_source;
545 dest_mac = eth_hdr(skb)->h_dest;
547 /* Pull the header */
548 hp = (struct fcoe_hdr *) skb_network_header(skb);
549 fh = (struct fc_frame_header *) skb_transport_header(skb);
550 skb_pull(skb, sizeof(struct fcoe_hdr));
551 fr_len = skb->len - sizeof(struct fcoe_crc_eof);
553 stats = per_cpu_ptr(lport->stats, get_cpu());
555 stats->RxWords += fr_len / FCOE_WORD_TO_BYTE;
558 fp = (struct fc_frame *)skb;
561 fr_sof(fp) = hp->fcoe_sof;
562 if (skb_copy_bits(skb, fr_len, &crc_eof, sizeof(crc_eof))) {
566 fr_eof(fp) = crc_eof.fcoe_eof;
567 fr_crc(fp) = crc_eof.fcoe_crc32;
568 if (pskb_trim(skb, fr_len)) {
573 phys_port = lport_priv(lport);
574 interface = phys_port->priv;
575 ctlr = bnx2fc_to_ctlr(interface);
577 fh = fc_frame_header_get(fp);
579 if (ntoh24(&dest_mac[3]) != ntoh24(fh->fh_d_id)) {
580 BNX2FC_HBA_DBG(lport, "FC frame d_id mismatch with MAC %pM.\n",
586 vn_port = fc_vport_id_lookup(lport, ntoh24(fh->fh_d_id));
588 port = lport_priv(vn_port);
589 if (!ether_addr_equal(port->data_src_addr, dest_mac)) {
590 BNX2FC_HBA_DBG(lport, "fpma mismatch\n");
596 if (!ether_addr_equal(mac, ctlr->dest_addr)) {
597 BNX2FC_HBA_DBG(lport, "Wrong source address: mac:%pM dest_addr:%pM.\n",
598 mac, ctlr->dest_addr);
603 if (fh->fh_r_ctl == FC_RCTL_DD_SOL_DATA &&
604 fh->fh_type == FC_TYPE_FCP) {
605 /* Drop FCP data. We dont this in L2 path */
609 if (fh->fh_r_ctl == FC_RCTL_ELS_REQ &&
610 fh->fh_type == FC_TYPE_ELS) {
611 switch (fc_frame_payload_op(fp)) {
613 if (ntoh24(fh->fh_s_id) == FC_FID_FLOGI) {
614 /* drop non-FIP LOGO */
622 if (fh->fh_r_ctl == FC_RCTL_BA_ABTS) {
623 /* Drop incoming ABTS */
629 * If the destination ID from the frame header does not match what we
630 * have on record for lport and the search for a NPIV port came up
631 * empty then this is not addressed to our port so simply drop it.
633 if (lport->port_id != ntoh24(fh->fh_d_id) && !vn_port) {
634 BNX2FC_HBA_DBG(lport, "Dropping frame due to destination mismatch: lport->port_id=%x fh->d_id=%x.\n",
635 lport->port_id, ntoh24(fh->fh_d_id));
640 fr_crc = le32_to_cpu(fr_crc(fp));
642 if (unlikely(fr_crc != ~crc32(~0, skb->data, fr_len))) {
643 stats = per_cpu_ptr(lport->stats, get_cpu());
644 crc_err = (stats->InvalidCRCCount++);
647 printk(KERN_WARNING PFX "dropping frame with "
652 fc_exch_recv(lport, fp);
656 * bnx2fc_percpu_io_thread - thread per cpu for ios
658 * @arg: ptr to bnx2fc_percpu_info structure
660 static int bnx2fc_percpu_io_thread(void *arg)
662 struct bnx2fc_percpu_s *p = arg;
663 struct bnx2fc_work *work, *tmp;
664 LIST_HEAD(work_list);
666 set_user_nice(current, MIN_NICE);
667 set_current_state(TASK_INTERRUPTIBLE);
668 while (!kthread_should_stop()) {
670 spin_lock_bh(&p->fp_work_lock);
671 while (!list_empty(&p->work_list)) {
672 list_splice_init(&p->work_list, &work_list);
673 spin_unlock_bh(&p->fp_work_lock);
675 list_for_each_entry_safe(work, tmp, &work_list, list) {
676 list_del_init(&work->list);
677 bnx2fc_process_cq_compl(work->tgt, work->wqe);
681 spin_lock_bh(&p->fp_work_lock);
683 __set_current_state(TASK_INTERRUPTIBLE);
684 spin_unlock_bh(&p->fp_work_lock);
686 __set_current_state(TASK_RUNNING);
691 static struct fc_host_statistics *bnx2fc_get_host_stats(struct Scsi_Host *shost)
693 struct fc_host_statistics *bnx2fc_stats;
694 struct fc_lport *lport = shost_priv(shost);
695 struct fcoe_port *port = lport_priv(lport);
696 struct bnx2fc_interface *interface = port->priv;
697 struct bnx2fc_hba *hba = interface->hba;
698 struct fcoe_statistics_params *fw_stats;
701 fw_stats = (struct fcoe_statistics_params *)hba->stats_buffer;
705 mutex_lock(&hba->hba_stats_mutex);
707 bnx2fc_stats = fc_get_host_stats(shost);
709 init_completion(&hba->stat_req_done);
710 if (bnx2fc_send_stat_req(hba))
711 goto unlock_stats_mutex;
712 rc = wait_for_completion_timeout(&hba->stat_req_done, (2 * HZ));
714 BNX2FC_HBA_DBG(lport, "FW stat req timed out\n");
715 goto unlock_stats_mutex;
717 BNX2FC_STATS(hba, rx_stat2, fc_crc_cnt);
718 bnx2fc_stats->invalid_crc_count += hba->bfw_stats.fc_crc_cnt;
719 BNX2FC_STATS(hba, tx_stat, fcoe_tx_pkt_cnt);
720 bnx2fc_stats->tx_frames += hba->bfw_stats.fcoe_tx_pkt_cnt;
721 BNX2FC_STATS(hba, tx_stat, fcoe_tx_byte_cnt);
722 bnx2fc_stats->tx_words += ((hba->bfw_stats.fcoe_tx_byte_cnt) / 4);
723 BNX2FC_STATS(hba, rx_stat0, fcoe_rx_pkt_cnt);
724 bnx2fc_stats->rx_frames += hba->bfw_stats.fcoe_rx_pkt_cnt;
725 BNX2FC_STATS(hba, rx_stat0, fcoe_rx_byte_cnt);
726 bnx2fc_stats->rx_words += ((hba->bfw_stats.fcoe_rx_byte_cnt) / 4);
728 bnx2fc_stats->dumped_frames = 0;
729 bnx2fc_stats->lip_count = 0;
730 bnx2fc_stats->nos_count = 0;
731 bnx2fc_stats->loss_of_sync_count = 0;
732 bnx2fc_stats->loss_of_signal_count = 0;
733 bnx2fc_stats->prim_seq_protocol_err_count = 0;
735 memcpy(&hba->prev_stats, hba->stats_buffer,
736 sizeof(struct fcoe_statistics_params));
739 mutex_unlock(&hba->hba_stats_mutex);
743 static int bnx2fc_shost_config(struct fc_lport *lport, struct device *dev)
745 struct fcoe_port *port = lport_priv(lport);
746 struct bnx2fc_interface *interface = port->priv;
747 struct bnx2fc_hba *hba = interface->hba;
748 struct Scsi_Host *shost = lport->host;
751 shost->max_cmd_len = BNX2FC_MAX_CMD_LEN;
752 shost->max_lun = bnx2fc_max_luns;
753 shost->max_id = BNX2FC_MAX_FCP_TGT;
754 shost->max_channel = 0;
756 shost->transportt = bnx2fc_vport_xport_template;
758 shost->transportt = bnx2fc_transport_template;
760 /* Add the new host to SCSI-ml */
761 rc = scsi_add_host(lport->host, dev);
763 printk(KERN_ERR PFX "Error on scsi_add_host\n");
767 fc_host_max_npiv_vports(lport->host) = USHRT_MAX;
768 snprintf(fc_host_symbolic_name(lport->host), 256,
769 "%s (QLogic %s) v%s over %s",
770 BNX2FC_NAME, hba->chip_num, BNX2FC_VERSION,
771 interface->netdev->name);
776 static int bnx2fc_link_ok(struct fc_lport *lport)
778 struct fcoe_port *port = lport_priv(lport);
779 struct bnx2fc_interface *interface = port->priv;
780 struct bnx2fc_hba *hba = interface->hba;
781 struct net_device *dev = hba->phys_dev;
784 if ((dev->flags & IFF_UP) && netif_carrier_ok(dev))
785 clear_bit(ADAPTER_STATE_LINK_DOWN, &hba->adapter_state);
787 set_bit(ADAPTER_STATE_LINK_DOWN, &hba->adapter_state);
794 * bnx2fc_get_link_state - get network link state
796 * @hba: adapter instance pointer
798 * updates adapter structure flag based on netdev state
800 void bnx2fc_get_link_state(struct bnx2fc_hba *hba)
802 if (test_bit(__LINK_STATE_NOCARRIER, &hba->phys_dev->state))
803 set_bit(ADAPTER_STATE_LINK_DOWN, &hba->adapter_state);
805 clear_bit(ADAPTER_STATE_LINK_DOWN, &hba->adapter_state);
808 static int bnx2fc_net_config(struct fc_lport *lport, struct net_device *netdev)
810 struct bnx2fc_hba *hba;
811 struct bnx2fc_interface *interface;
812 struct fcoe_ctlr *ctlr;
813 struct fcoe_port *port;
816 port = lport_priv(lport);
817 interface = port->priv;
818 ctlr = bnx2fc_to_ctlr(interface);
819 hba = interface->hba;
821 /* require support for get_pauseparam ethtool op. */
822 if (!hba->phys_dev->ethtool_ops ||
823 !hba->phys_dev->ethtool_ops->get_pauseparam)
826 if (fc_set_mfs(lport, BNX2FC_MFS))
829 skb_queue_head_init(&port->fcoe_pending_queue);
830 port->fcoe_pending_queue_active = 0;
831 timer_setup(&port->timer, fcoe_queue_timer, 0);
833 fcoe_link_speed_update(lport);
836 if (fcoe_get_wwn(netdev, &wwnn, NETDEV_FCOE_WWNN))
837 wwnn = fcoe_wwn_from_mac(ctlr->ctl_src_addr,
839 BNX2FC_HBA_DBG(lport, "WWNN = 0x%llx\n", wwnn);
840 fc_set_wwnn(lport, wwnn);
842 if (fcoe_get_wwn(netdev, &wwpn, NETDEV_FCOE_WWPN))
843 wwpn = fcoe_wwn_from_mac(ctlr->ctl_src_addr,
846 BNX2FC_HBA_DBG(lport, "WWPN = 0x%llx\n", wwpn);
847 fc_set_wwpn(lport, wwpn);
853 static void bnx2fc_destroy_timer(struct timer_list *t)
855 struct bnx2fc_hba *hba = from_timer(hba, t, destroy_timer);
857 printk(KERN_ERR PFX "ERROR:bnx2fc_destroy_timer - "
858 "Destroy compl not received!!\n");
859 set_bit(BNX2FC_FLAG_DESTROY_CMPL, &hba->flags);
860 wake_up_interruptible(&hba->destroy_wait);
864 * bnx2fc_indicate_netevent - Generic netdev event handler
866 * @context: adapter structure pointer
868 * @vlan_id: vlan id - associated vlan id with this event
870 * Handles NETDEV_UP, NETDEV_DOWN, NETDEV_GOING_DOWN,NETDEV_CHANGE and
871 * NETDEV_CHANGE_MTU events. Handle NETDEV_UNREGISTER only for vlans.
873 static void bnx2fc_indicate_netevent(void *context, unsigned long event,
876 struct bnx2fc_hba *hba = (struct bnx2fc_hba *)context;
877 struct fcoe_ctlr_device *cdev;
878 struct fc_lport *lport;
879 struct fc_lport *vport;
880 struct bnx2fc_interface *interface, *tmp;
881 struct fcoe_ctlr *ctlr;
882 int wait_for_upload = 0;
883 u32 link_possible = 1;
885 if (vlan_id != 0 && event != NETDEV_UNREGISTER)
890 if (!test_bit(ADAPTER_STATE_UP, &hba->adapter_state))
891 printk(KERN_ERR "indicate_netevent: "\
892 "hba is not UP!!\n");
896 clear_bit(ADAPTER_STATE_GOING_DOWN, &hba->adapter_state);
897 clear_bit(ADAPTER_STATE_UP, &hba->adapter_state);
901 case NETDEV_GOING_DOWN:
902 set_bit(ADAPTER_STATE_GOING_DOWN, &hba->adapter_state);
909 case NETDEV_UNREGISTER:
912 mutex_lock(&bnx2fc_dev_lock);
913 list_for_each_entry_safe(interface, tmp, &if_list, list) {
914 if (interface->hba == hba &&
915 interface->vlan_id == (vlan_id & VLAN_VID_MASK))
916 __bnx2fc_destroy(interface);
918 mutex_unlock(&bnx2fc_dev_lock);
925 mutex_lock(&bnx2fc_dev_lock);
926 list_for_each_entry(interface, &if_list, list) {
928 if (interface->hba != hba)
931 ctlr = bnx2fc_to_ctlr(interface);
933 BNX2FC_HBA_DBG(lport, "netevent handler - event=%s %ld\n",
934 interface->netdev->name, event);
936 fcoe_link_speed_update(lport);
938 cdev = fcoe_ctlr_to_ctlr_dev(ctlr);
940 if (link_possible && !bnx2fc_link_ok(lport)) {
941 switch (cdev->enabled) {
942 case FCOE_CTLR_DISABLED:
943 pr_info("Link up while interface is disabled.\n");
945 case FCOE_CTLR_ENABLED:
946 case FCOE_CTLR_UNUSED:
947 /* Reset max recv frame size to default */
948 fc_set_mfs(lport, BNX2FC_MFS);
950 * ctlr link up will only be handled during
951 * enable to avoid sending discovery
952 * solicitation on a stale vlan
954 if (interface->enabled)
955 fcoe_ctlr_link_up(ctlr);
957 } else if (fcoe_ctlr_link_down(ctlr)) {
958 switch (cdev->enabled) {
959 case FCOE_CTLR_DISABLED:
960 pr_info("Link down while interface is disabled.\n");
962 case FCOE_CTLR_ENABLED:
963 case FCOE_CTLR_UNUSED:
964 mutex_lock(&lport->lp_mutex);
965 list_for_each_entry(vport, &lport->vports, list)
966 fc_host_port_type(vport->host) =
968 mutex_unlock(&lport->lp_mutex);
969 fc_host_port_type(lport->host) =
971 per_cpu_ptr(lport->stats,
972 get_cpu())->LinkFailureCount++;
974 fcoe_clean_pending_queue(lport);
979 mutex_unlock(&bnx2fc_dev_lock);
981 if (wait_for_upload) {
982 clear_bit(ADAPTER_STATE_READY, &hba->adapter_state);
983 init_waitqueue_head(&hba->shutdown_wait);
984 BNX2FC_MISC_DBG("indicate_netevent "
985 "num_ofld_sess = %d\n",
987 hba->wait_for_link_down = 1;
988 wait_event_interruptible(hba->shutdown_wait,
989 (hba->num_ofld_sess == 0));
990 BNX2FC_MISC_DBG("wakeup - num_ofld_sess = %d\n",
992 hba->wait_for_link_down = 0;
994 if (signal_pending(current))
995 flush_signals(current);
999 static int bnx2fc_libfc_config(struct fc_lport *lport)
1002 /* Set the function pointers set by bnx2fc driver */
1003 memcpy(&lport->tt, &bnx2fc_libfc_fcn_templ,
1004 sizeof(struct libfc_function_template));
1005 fc_elsct_init(lport);
1006 fc_exch_init(lport);
1007 fc_disc_init(lport);
1008 fc_disc_config(lport, lport);
1012 static int bnx2fc_em_config(struct fc_lport *lport, struct bnx2fc_hba *hba)
1014 int fcoe_min_xid, fcoe_max_xid;
1016 fcoe_min_xid = hba->max_xid + 1;
1017 if (nr_cpu_ids <= 2)
1018 fcoe_max_xid = hba->max_xid + FCOE_XIDS_PER_CPU_OFFSET;
1020 fcoe_max_xid = hba->max_xid + FCOE_MAX_XID_OFFSET;
1021 if (!fc_exch_mgr_alloc(lport, FC_CLASS_3, fcoe_min_xid,
1022 fcoe_max_xid, NULL)) {
1023 printk(KERN_ERR PFX "em_config:fc_exch_mgr_alloc failed\n");
1030 static int bnx2fc_lport_config(struct fc_lport *lport)
1034 lport->max_retry_count = BNX2FC_MAX_RETRY_CNT;
1035 lport->max_rport_retry_count = BNX2FC_MAX_RPORT_RETRY_CNT;
1036 lport->e_d_tov = 2 * 1000;
1037 lport->r_a_tov = 10 * 1000;
1039 lport->service_params = (FCP_SPPF_INIT_FCN | FCP_SPPF_RD_XRDY_DIS |
1040 FCP_SPPF_RETRY | FCP_SPPF_CONF_COMPL);
1041 lport->does_npiv = 1;
1043 memset(&lport->rnid_gen, 0, sizeof(struct fc_els_rnid_gen));
1044 lport->rnid_gen.rnid_atype = BNX2FC_RNID_HBA;
1046 /* alloc stats structure */
1047 if (fc_lport_init_stats(lport))
1050 /* Finish fc_lport configuration */
1051 fc_lport_config(lport);
1057 * bnx2fc_fip_recv - handle a received FIP frame.
1059 * @skb: the received skb
1060 * @dev: associated &net_device
1061 * @ptype: the &packet_type structure which was used to register this handler.
1062 * @orig_dev: original receive &net_device, in case @ dev is a bond.
1064 * Returns: 0 for success
1066 static int bnx2fc_fip_recv(struct sk_buff *skb, struct net_device *dev,
1067 struct packet_type *ptype,
1068 struct net_device *orig_dev)
1070 struct bnx2fc_interface *interface;
1071 struct fcoe_ctlr *ctlr;
1072 interface = container_of(ptype, struct bnx2fc_interface,
1074 ctlr = bnx2fc_to_ctlr(interface);
1075 fcoe_ctlr_recv(ctlr, skb);
1080 * bnx2fc_update_src_mac - Update Ethernet MAC filters.
1082 * @fip: FCoE controller.
1083 * @old: Unicast MAC address to delete if the MAC is non-zero.
1084 * @new: Unicast MAC address to add.
1086 * Remove any previously-set unicast MAC filter.
1087 * Add secondary FCoE MAC address filter for our OUI.
1089 static void bnx2fc_update_src_mac(struct fc_lport *lport, u8 *addr)
1091 struct fcoe_port *port = lport_priv(lport);
1093 memcpy(port->data_src_addr, addr, ETH_ALEN);
1097 * bnx2fc_get_src_mac - return the ethernet source address for an lport
1099 * @lport: libfc port
1101 static u8 *bnx2fc_get_src_mac(struct fc_lport *lport)
1103 struct fcoe_port *port;
1105 port = (struct fcoe_port *)lport_priv(lport);
1106 return port->data_src_addr;
1110 * bnx2fc_fip_send - send an Ethernet-encapsulated FIP frame.
1112 * @fip: FCoE controller.
1115 static void bnx2fc_fip_send(struct fcoe_ctlr *fip, struct sk_buff *skb)
1117 struct fip_header *fiph;
1118 struct ethhdr *eth_hdr;
1122 fiph = (struct fip_header *) ((void *)skb->data + 2 * ETH_ALEN + 2);
1123 eth_hdr = (struct ethhdr *)skb_mac_header(skb);
1124 op = ntohs(fiph->fip_op);
1125 sub = fiph->fip_subcode;
1127 if (op == FIP_OP_CTRL && sub == FIP_SC_SOL && bnx2fc_log_fka)
1128 BNX2FC_MISC_DBG("Sending FKA from %pM to %pM.\n",
1129 eth_hdr->h_source, eth_hdr->h_dest);
1131 skb->dev = bnx2fc_from_ctlr(fip)->netdev;
1132 dev_queue_xmit(skb);
1135 static int bnx2fc_vport_create(struct fc_vport *vport, bool disabled)
1137 struct Scsi_Host *shost = vport_to_shost(vport);
1138 struct fc_lport *n_port = shost_priv(shost);
1139 struct fcoe_port *port = lport_priv(n_port);
1140 struct bnx2fc_interface *interface = port->priv;
1141 struct net_device *netdev = interface->netdev;
1142 struct fc_lport *vn_port;
1146 rc = fcoe_validate_vport_create(vport);
1148 fcoe_wwn_to_str(vport->port_name, buf, sizeof(buf));
1149 printk(KERN_ERR PFX "Failed to create vport, "
1150 "WWPN (0x%s) already exists\n",
1155 if (!test_bit(BNX2FC_FLAG_FW_INIT_DONE, &interface->hba->flags)) {
1156 printk(KERN_ERR PFX "vn ports cannot be created on"
1157 "this interface\n");
1161 mutex_lock(&bnx2fc_dev_lock);
1162 vn_port = bnx2fc_if_create(interface, &vport->dev, 1);
1163 mutex_unlock(&bnx2fc_dev_lock);
1167 printk(KERN_ERR PFX "bnx2fc_vport_create (%s) failed\n",
1172 if (bnx2fc_devloss_tmo)
1173 fc_host_dev_loss_tmo(vn_port->host) = bnx2fc_devloss_tmo;
1176 fc_vport_set_state(vport, FC_VPORT_DISABLED);
1178 vn_port->boot_time = jiffies;
1179 fc_lport_init(vn_port);
1180 fc_fabric_login(vn_port);
1181 fc_vport_setlink(vn_port);
1186 static void bnx2fc_free_vport(struct bnx2fc_hba *hba, struct fc_lport *lport)
1188 struct bnx2fc_lport *blport, *tmp;
1190 spin_lock_bh(&hba->hba_lock);
1191 list_for_each_entry_safe(blport, tmp, &hba->vports, list) {
1192 if (blport->lport == lport) {
1193 list_del(&blport->list);
1197 spin_unlock_bh(&hba->hba_lock);
1200 static int bnx2fc_vport_destroy(struct fc_vport *vport)
1202 struct Scsi_Host *shost = vport_to_shost(vport);
1203 struct fc_lport *n_port = shost_priv(shost);
1204 struct fc_lport *vn_port = vport->dd_data;
1205 struct fcoe_port *port = lport_priv(vn_port);
1206 struct bnx2fc_interface *interface = port->priv;
1207 struct fc_lport *v_port;
1210 mutex_lock(&n_port->lp_mutex);
1211 list_for_each_entry(v_port, &n_port->vports, list)
1212 if (v_port->vport == vport) {
1218 mutex_unlock(&n_port->lp_mutex);
1221 list_del(&vn_port->list);
1222 mutex_unlock(&n_port->lp_mutex);
1223 bnx2fc_free_vport(interface->hba, port->lport);
1224 bnx2fc_port_shutdown(port->lport);
1225 bnx2fc_port_destroy(port);
1226 bnx2fc_interface_put(interface);
1230 static int bnx2fc_vport_disable(struct fc_vport *vport, bool disable)
1232 struct fc_lport *lport = vport->dd_data;
1235 fc_vport_set_state(vport, FC_VPORT_DISABLED);
1236 fc_fabric_logoff(lport);
1238 lport->boot_time = jiffies;
1239 fc_fabric_login(lport);
1240 fc_vport_setlink(lport);
1246 static int bnx2fc_interface_setup(struct bnx2fc_interface *interface)
1248 struct net_device *netdev = interface->netdev;
1249 struct net_device *physdev = interface->hba->phys_dev;
1250 struct fcoe_ctlr *ctlr = bnx2fc_to_ctlr(interface);
1251 struct netdev_hw_addr *ha;
1252 int sel_san_mac = 0;
1254 /* setup Source MAC Address */
1256 for_each_dev_addr(physdev, ha) {
1257 BNX2FC_MISC_DBG("net_config: ha->type = %d, fip_mac = ",
1259 printk(KERN_INFO "%2x:%2x:%2x:%2x:%2x:%2x\n", ha->addr[0],
1260 ha->addr[1], ha->addr[2], ha->addr[3],
1261 ha->addr[4], ha->addr[5]);
1263 if ((ha->type == NETDEV_HW_ADDR_T_SAN) &&
1264 (is_valid_ether_addr(ha->addr))) {
1265 memcpy(ctlr->ctl_src_addr, ha->addr,
1268 BNX2FC_MISC_DBG("Found SAN MAC\n");
1276 interface->fip_packet_type.func = bnx2fc_fip_recv;
1277 interface->fip_packet_type.type = htons(ETH_P_FIP);
1278 interface->fip_packet_type.dev = netdev;
1279 dev_add_pack(&interface->fip_packet_type);
1281 interface->fcoe_packet_type.func = bnx2fc_rcv;
1282 interface->fcoe_packet_type.type = __constant_htons(ETH_P_FCOE);
1283 interface->fcoe_packet_type.dev = netdev;
1284 dev_add_pack(&interface->fcoe_packet_type);
1289 static int bnx2fc_attach_transport(void)
1291 bnx2fc_transport_template =
1292 fc_attach_transport(&bnx2fc_transport_function);
1294 if (bnx2fc_transport_template == NULL) {
1295 printk(KERN_ERR PFX "Failed to attach FC transport\n");
1299 bnx2fc_vport_xport_template =
1300 fc_attach_transport(&bnx2fc_vport_xport_function);
1301 if (bnx2fc_vport_xport_template == NULL) {
1303 "Failed to attach FC transport for vport\n");
1304 fc_release_transport(bnx2fc_transport_template);
1305 bnx2fc_transport_template = NULL;
1310 static void bnx2fc_release_transport(void)
1312 fc_release_transport(bnx2fc_transport_template);
1313 fc_release_transport(bnx2fc_vport_xport_template);
1314 bnx2fc_transport_template = NULL;
1315 bnx2fc_vport_xport_template = NULL;
1318 static void bnx2fc_interface_release(struct kref *kref)
1320 struct fcoe_ctlr_device *ctlr_dev;
1321 struct bnx2fc_interface *interface;
1322 struct fcoe_ctlr *ctlr;
1323 struct net_device *netdev;
1325 interface = container_of(kref, struct bnx2fc_interface, kref);
1326 BNX2FC_MISC_DBG("Interface is being released\n");
1328 ctlr = bnx2fc_to_ctlr(interface);
1329 ctlr_dev = fcoe_ctlr_to_ctlr_dev(ctlr);
1330 netdev = interface->netdev;
1332 /* tear-down FIP controller */
1333 if (test_and_clear_bit(BNX2FC_CTLR_INIT_DONE, &interface->if_flags))
1334 fcoe_ctlr_destroy(ctlr);
1336 fcoe_ctlr_device_delete(ctlr_dev);
1339 module_put(THIS_MODULE);
1342 static inline void bnx2fc_interface_get(struct bnx2fc_interface *interface)
1344 kref_get(&interface->kref);
1347 static inline void bnx2fc_interface_put(struct bnx2fc_interface *interface)
1349 kref_put(&interface->kref, bnx2fc_interface_release);
1351 static void bnx2fc_hba_destroy(struct bnx2fc_hba *hba)
1353 /* Free the command manager */
1355 bnx2fc_cmd_mgr_free(hba->cmd_mgr);
1356 hba->cmd_mgr = NULL;
1358 kfree(hba->tgt_ofld_list);
1359 bnx2fc_unbind_pcidev(hba);
1364 * bnx2fc_hba_create - create a new bnx2fc hba
1366 * @cnic: pointer to cnic device
1368 * Creates a new FCoE hba on the given device.
1371 static struct bnx2fc_hba *bnx2fc_hba_create(struct cnic_dev *cnic)
1373 struct bnx2fc_hba *hba;
1374 struct fcoe_capabilities *fcoe_cap;
1377 hba = kzalloc(sizeof(*hba), GFP_KERNEL);
1379 printk(KERN_ERR PFX "Unable to allocate hba structure\n");
1382 spin_lock_init(&hba->hba_lock);
1383 mutex_init(&hba->hba_mutex);
1384 mutex_init(&hba->hba_stats_mutex);
1388 hba->max_tasks = cnic->max_fcoe_exchanges;
1389 hba->elstm_xids = (hba->max_tasks / 2);
1390 hba->max_outstanding_cmds = hba->elstm_xids;
1391 hba->max_xid = (hba->max_tasks - 1);
1393 rc = bnx2fc_bind_pcidev(hba);
1395 printk(KERN_ERR PFX "create_adapter: bind error\n");
1398 hba->phys_dev = cnic->netdev;
1399 hba->next_conn_id = 0;
1401 hba->tgt_ofld_list =
1402 kcalloc(BNX2FC_NUM_MAX_SESS, sizeof(struct bnx2fc_rport *),
1404 if (!hba->tgt_ofld_list) {
1405 printk(KERN_ERR PFX "Unable to allocate tgt offload list\n");
1409 hba->num_ofld_sess = 0;
1411 hba->cmd_mgr = bnx2fc_cmd_mgr_alloc(hba);
1412 if (!hba->cmd_mgr) {
1413 printk(KERN_ERR PFX "em_config:bnx2fc_cmd_mgr_alloc failed\n");
1416 fcoe_cap = &hba->fcoe_cap;
1418 fcoe_cap->capability1 = BNX2FC_TM_MAX_SQES <<
1419 FCOE_IOS_PER_CONNECTION_SHIFT;
1420 fcoe_cap->capability1 |= BNX2FC_NUM_MAX_SESS <<
1421 FCOE_LOGINS_PER_PORT_SHIFT;
1422 fcoe_cap->capability2 = hba->max_outstanding_cmds <<
1423 FCOE_NUMBER_OF_EXCHANGES_SHIFT;
1424 fcoe_cap->capability2 |= BNX2FC_MAX_NPIV <<
1425 FCOE_NPIV_WWN_PER_PORT_SHIFT;
1426 fcoe_cap->capability3 = BNX2FC_NUM_MAX_SESS <<
1427 FCOE_TARGETS_SUPPORTED_SHIFT;
1428 fcoe_cap->capability3 |= hba->max_outstanding_cmds <<
1429 FCOE_OUTSTANDING_COMMANDS_SHIFT;
1430 fcoe_cap->capability4 = FCOE_CAPABILITY4_STATEFUL;
1432 init_waitqueue_head(&hba->shutdown_wait);
1433 init_waitqueue_head(&hba->destroy_wait);
1434 INIT_LIST_HEAD(&hba->vports);
1439 kfree(hba->tgt_ofld_list);
1441 bnx2fc_unbind_pcidev(hba);
1447 static struct bnx2fc_interface *
1448 bnx2fc_interface_create(struct bnx2fc_hba *hba,
1449 struct net_device *netdev,
1450 enum fip_mode fip_mode)
1452 struct fcoe_ctlr_device *ctlr_dev;
1453 struct bnx2fc_interface *interface;
1454 struct fcoe_ctlr *ctlr;
1458 size = (sizeof(*interface) + sizeof(struct fcoe_ctlr));
1459 ctlr_dev = fcoe_ctlr_device_add(&netdev->dev, &bnx2fc_fcoe_sysfs_templ,
1462 printk(KERN_ERR PFX "Unable to allocate interface structure\n");
1465 ctlr = fcoe_ctlr_device_priv(ctlr_dev);
1466 ctlr->cdev = ctlr_dev;
1467 interface = fcoe_ctlr_priv(ctlr);
1469 kref_init(&interface->kref);
1470 interface->hba = hba;
1471 interface->netdev = netdev;
1473 /* Initialize FIP */
1474 fcoe_ctlr_init(ctlr, fip_mode);
1475 ctlr->send = bnx2fc_fip_send;
1476 ctlr->update_mac = bnx2fc_update_src_mac;
1477 ctlr->get_src_addr = bnx2fc_get_src_mac;
1478 set_bit(BNX2FC_CTLR_INIT_DONE, &interface->if_flags);
1480 rc = bnx2fc_interface_setup(interface);
1484 fcoe_ctlr_destroy(ctlr);
1486 fcoe_ctlr_device_delete(ctlr_dev);
1491 * bnx2fc_if_create - Create FCoE instance on a given interface
1493 * @interface: FCoE interface to create a local port on
1494 * @parent: Device pointer to be the parent in sysfs for the SCSI host
1495 * @npiv: Indicates if the port is vport or not
1497 * Creates a fc_lport instance and a Scsi_Host instance and configure them.
1499 * Returns: Allocated fc_lport or an error pointer
1501 static struct fc_lport *bnx2fc_if_create(struct bnx2fc_interface *interface,
1502 struct device *parent, int npiv)
1504 struct fcoe_ctlr *ctlr = bnx2fc_to_ctlr(interface);
1505 struct fc_lport *lport, *n_port;
1506 struct fcoe_port *port;
1507 struct Scsi_Host *shost;
1508 struct fc_vport *vport = dev_to_vport(parent);
1509 struct bnx2fc_lport *blport;
1510 struct bnx2fc_hba *hba = interface->hba;
1513 blport = kzalloc(sizeof(struct bnx2fc_lport), GFP_KERNEL);
1515 BNX2FC_HBA_DBG(ctlr->lp, "Unable to alloc blport\n");
1519 /* Allocate Scsi_Host structure */
1520 bnx2fc_shost_template.can_queue = hba->max_outstanding_cmds;
1522 lport = libfc_host_alloc(&bnx2fc_shost_template, sizeof(*port));
1524 lport = libfc_vport_create(vport, sizeof(*port));
1527 printk(KERN_ERR PFX "could not allocate scsi host structure\n");
1530 shost = lport->host;
1531 port = lport_priv(lport);
1532 port->lport = lport;
1533 port->priv = interface;
1534 port->get_netdev = bnx2fc_netdev;
1536 /* Configure fcoe_port */
1537 rc = bnx2fc_lport_config(lport);
1542 printk(KERN_ERR PFX "Setting vport names, 0x%llX 0x%llX\n",
1543 vport->node_name, vport->port_name);
1544 fc_set_wwnn(lport, vport->node_name);
1545 fc_set_wwpn(lport, vport->port_name);
1547 /* Configure netdev and networking properties of the lport */
1548 rc = bnx2fc_net_config(lport, interface->netdev);
1550 printk(KERN_ERR PFX "Error on bnx2fc_net_config\n");
1554 rc = bnx2fc_shost_config(lport, parent);
1556 printk(KERN_ERR PFX "Couldn't configure shost for %s\n",
1557 interface->netdev->name);
1561 /* Initialize the libfc library */
1562 rc = bnx2fc_libfc_config(lport);
1564 printk(KERN_ERR PFX "Couldn't configure libfc\n");
1567 fc_host_port_type(lport->host) = FC_PORTTYPE_UNKNOWN;
1569 if (bnx2fc_devloss_tmo)
1570 fc_host_dev_loss_tmo(shost) = bnx2fc_devloss_tmo;
1572 /* Allocate exchange manager */
1574 rc = bnx2fc_em_config(lport, hba);
1576 shost = vport_to_shost(vport);
1577 n_port = shost_priv(shost);
1578 rc = fc_exch_mgr_list_clone(n_port, lport);
1582 printk(KERN_ERR PFX "Error on bnx2fc_em_config\n");
1586 bnx2fc_interface_get(interface);
1588 spin_lock_bh(&hba->hba_lock);
1589 blport->lport = lport;
1590 list_add_tail(&blport->list, &hba->vports);
1591 spin_unlock_bh(&hba->hba_lock);
1596 scsi_remove_host(shost);
1598 scsi_host_put(lport->host);
1604 static void bnx2fc_net_cleanup(struct bnx2fc_interface *interface)
1606 /* Dont listen for Ethernet packets anymore */
1607 __dev_remove_pack(&interface->fcoe_packet_type);
1608 __dev_remove_pack(&interface->fip_packet_type);
1612 static void bnx2fc_interface_cleanup(struct bnx2fc_interface *interface)
1614 struct fcoe_ctlr *ctlr = bnx2fc_to_ctlr(interface);
1615 struct fc_lport *lport = ctlr->lp;
1616 struct fcoe_port *port = lport_priv(lport);
1617 struct bnx2fc_hba *hba = interface->hba;
1619 /* Stop the transmit retry timer */
1620 del_timer_sync(&port->timer);
1622 /* Free existing transmit skbs */
1623 fcoe_clean_pending_queue(lport);
1625 bnx2fc_net_cleanup(interface);
1627 bnx2fc_free_vport(hba, lport);
1630 static void bnx2fc_if_destroy(struct fc_lport *lport)
1633 /* Free queued packets for the receive thread */
1634 bnx2fc_clean_rx_queue(lport);
1636 /* Detach from scsi-ml */
1637 fc_remove_host(lport->host);
1638 scsi_remove_host(lport->host);
1641 * Note that only the physical lport will have the exchange manager.
1642 * for vports, this function is NOP
1644 fc_exch_mgr_free(lport);
1646 /* Free memory used by statistical counters */
1647 fc_lport_free_stats(lport);
1649 /* Release Scsi_Host */
1650 scsi_host_put(lport->host);
1653 static void __bnx2fc_destroy(struct bnx2fc_interface *interface)
1655 struct fcoe_ctlr *ctlr = bnx2fc_to_ctlr(interface);
1656 struct fc_lport *lport = ctlr->lp;
1657 struct fcoe_port *port = lport_priv(lport);
1659 bnx2fc_interface_cleanup(interface);
1660 bnx2fc_stop(interface);
1661 list_del(&interface->list);
1662 bnx2fc_port_destroy(port);
1663 bnx2fc_interface_put(interface);
1667 * bnx2fc_destroy - Destroy a bnx2fc FCoE interface
1669 * @buffer: The name of the Ethernet interface to be destroyed
1670 * @kp: The associated kernel parameter
1672 * Called from sysfs.
1674 * Returns: 0 for success
1676 static int bnx2fc_destroy(struct net_device *netdev)
1678 struct bnx2fc_interface *interface = NULL;
1679 struct workqueue_struct *timer_work_queue;
1680 struct fcoe_ctlr *ctlr;
1684 mutex_lock(&bnx2fc_dev_lock);
1686 interface = bnx2fc_interface_lookup(netdev);
1687 ctlr = bnx2fc_to_ctlr(interface);
1688 if (!interface || !ctlr->lp) {
1690 printk(KERN_ERR PFX "bnx2fc_destroy: interface or lport not found\n");
1694 timer_work_queue = interface->timer_work_queue;
1695 __bnx2fc_destroy(interface);
1696 destroy_workqueue(timer_work_queue);
1699 mutex_unlock(&bnx2fc_dev_lock);
1704 static void bnx2fc_port_destroy(struct fcoe_port *port)
1706 struct fc_lport *lport;
1708 lport = port->lport;
1709 BNX2FC_HBA_DBG(lport, "Entered %s, destroying lport %p\n", __func__, lport);
1711 bnx2fc_if_destroy(lport);
1714 static void bnx2fc_unbind_adapter_devices(struct bnx2fc_hba *hba)
1716 bnx2fc_free_fw_resc(hba);
1717 bnx2fc_free_task_ctx(hba);
1721 * bnx2fc_bind_adapter_devices - binds bnx2fc adapter with the associated
1724 * @hba: Adapter instance
1726 static int bnx2fc_bind_adapter_devices(struct bnx2fc_hba *hba)
1728 if (bnx2fc_setup_task_ctx(hba))
1731 if (bnx2fc_setup_fw_resc(hba))
1736 bnx2fc_unbind_adapter_devices(hba);
1740 static int bnx2fc_bind_pcidev(struct bnx2fc_hba *hba)
1742 struct cnic_dev *cnic;
1743 struct pci_dev *pdev;
1746 printk(KERN_ERR PFX "cnic is NULL\n");
1750 pdev = hba->pcidev = cnic->pcidev;
1754 switch (pdev->device) {
1755 case PCI_DEVICE_ID_NX2_57710:
1756 strncpy(hba->chip_num, "BCM57710", BCM_CHIP_LEN);
1758 case PCI_DEVICE_ID_NX2_57711:
1759 strncpy(hba->chip_num, "BCM57711", BCM_CHIP_LEN);
1761 case PCI_DEVICE_ID_NX2_57712:
1762 case PCI_DEVICE_ID_NX2_57712_MF:
1763 case PCI_DEVICE_ID_NX2_57712_VF:
1764 strncpy(hba->chip_num, "BCM57712", BCM_CHIP_LEN);
1766 case PCI_DEVICE_ID_NX2_57800:
1767 case PCI_DEVICE_ID_NX2_57800_MF:
1768 case PCI_DEVICE_ID_NX2_57800_VF:
1769 strncpy(hba->chip_num, "BCM57800", BCM_CHIP_LEN);
1771 case PCI_DEVICE_ID_NX2_57810:
1772 case PCI_DEVICE_ID_NX2_57810_MF:
1773 case PCI_DEVICE_ID_NX2_57810_VF:
1774 strncpy(hba->chip_num, "BCM57810", BCM_CHIP_LEN);
1776 case PCI_DEVICE_ID_NX2_57840:
1777 case PCI_DEVICE_ID_NX2_57840_MF:
1778 case PCI_DEVICE_ID_NX2_57840_VF:
1779 case PCI_DEVICE_ID_NX2_57840_2_20:
1780 case PCI_DEVICE_ID_NX2_57840_4_10:
1781 strncpy(hba->chip_num, "BCM57840", BCM_CHIP_LEN);
1784 pr_err(PFX "Unknown device id 0x%x\n", pdev->device);
1787 pci_dev_get(hba->pcidev);
1791 static void bnx2fc_unbind_pcidev(struct bnx2fc_hba *hba)
1794 hba->chip_num[0] = '\0';
1795 pci_dev_put(hba->pcidev);
1801 * bnx2fc_ulp_get_stats - cnic callback to populate FCoE stats
1803 * @handle: transport handle pointing to adapter struture
1805 static int bnx2fc_ulp_get_stats(void *handle)
1807 struct bnx2fc_hba *hba = handle;
1808 struct cnic_dev *cnic;
1809 struct fcoe_stats_info *stats_addr;
1815 stats_addr = &cnic->stats_addr->fcoe_stat;
1819 strncpy(stats_addr->version, BNX2FC_VERSION,
1820 sizeof(stats_addr->version));
1821 stats_addr->txq_size = BNX2FC_SQ_WQES_MAX;
1822 stats_addr->rxq_size = BNX2FC_CQ_WQES_MAX;
1829 * bnx2fc_ulp_start - cnic callback to initialize & start adapter instance
1831 * @handle: transport handle pointing to adapter structure
1833 * This function maps adapter structure to pcidev structure and initiates
1834 * firmware handshake to enable/initialize on-chip FCoE components.
1835 * This bnx2fc - cnic interface api callback is used after following
1836 * conditions are met -
1837 * a) underlying network interface is up (marked by event NETDEV_UP
1839 * b) bnx2fc adatper structure is registered.
1841 static void bnx2fc_ulp_start(void *handle)
1843 struct bnx2fc_hba *hba = handle;
1844 struct bnx2fc_interface *interface;
1845 struct fcoe_ctlr *ctlr;
1846 struct fc_lport *lport;
1848 mutex_lock(&bnx2fc_dev_lock);
1850 if (!test_bit(BNX2FC_FLAG_FW_INIT_DONE, &hba->flags))
1851 bnx2fc_fw_init(hba);
1853 BNX2FC_MISC_DBG("bnx2fc started.\n");
1855 list_for_each_entry(interface, &if_list, list) {
1856 if (interface->hba == hba) {
1857 ctlr = bnx2fc_to_ctlr(interface);
1859 /* Kick off Fabric discovery*/
1860 printk(KERN_ERR PFX "ulp_init: start discovery\n");
1861 lport->tt.frame_send = bnx2fc_xmit;
1862 bnx2fc_start_disc(interface);
1866 mutex_unlock(&bnx2fc_dev_lock);
1869 static void bnx2fc_port_shutdown(struct fc_lport *lport)
1871 BNX2FC_MISC_DBG("Entered %s\n", __func__);
1872 fc_fabric_logoff(lport);
1873 fc_lport_destroy(lport);
1876 static void bnx2fc_stop(struct bnx2fc_interface *interface)
1878 struct fcoe_ctlr *ctlr = bnx2fc_to_ctlr(interface);
1879 struct fc_lport *lport;
1880 struct fc_lport *vport;
1882 if (!test_bit(BNX2FC_FLAG_FW_INIT_DONE, &interface->hba->flags))
1886 bnx2fc_port_shutdown(lport);
1888 mutex_lock(&lport->lp_mutex);
1889 list_for_each_entry(vport, &lport->vports, list)
1890 fc_host_port_type(vport->host) =
1891 FC_PORTTYPE_UNKNOWN;
1892 mutex_unlock(&lport->lp_mutex);
1893 fc_host_port_type(lport->host) = FC_PORTTYPE_UNKNOWN;
1894 fcoe_ctlr_link_down(ctlr);
1895 fcoe_clean_pending_queue(lport);
1898 static int bnx2fc_fw_init(struct bnx2fc_hba *hba)
1900 #define BNX2FC_INIT_POLL_TIME (1000 / HZ)
1904 rc = bnx2fc_bind_adapter_devices(hba);
1906 printk(KERN_ALERT PFX
1907 "bnx2fc_bind_adapter_devices failed - rc = %d\n", rc);
1911 rc = bnx2fc_send_fw_fcoe_init_msg(hba);
1913 printk(KERN_ALERT PFX
1914 "bnx2fc_send_fw_fcoe_init_msg failed - rc = %d\n", rc);
1919 * Wait until the adapter init message is complete, and adapter
1922 while (!test_bit(ADAPTER_STATE_UP, &hba->adapter_state) && i--)
1923 msleep(BNX2FC_INIT_POLL_TIME);
1925 if (!test_bit(ADAPTER_STATE_UP, &hba->adapter_state)) {
1926 printk(KERN_ERR PFX "bnx2fc_start: %s failed to initialize. "
1928 hba->cnic->netdev->name);
1934 set_bit(BNX2FC_FLAG_FW_INIT_DONE, &hba->flags);
1938 bnx2fc_unbind_adapter_devices(hba);
1943 static void bnx2fc_fw_destroy(struct bnx2fc_hba *hba)
1945 if (test_and_clear_bit(BNX2FC_FLAG_FW_INIT_DONE, &hba->flags)) {
1946 if (bnx2fc_send_fw_fcoe_destroy_msg(hba) == 0) {
1947 timer_setup(&hba->destroy_timer, bnx2fc_destroy_timer,
1949 hba->destroy_timer.expires = BNX2FC_FW_TIMEOUT +
1951 add_timer(&hba->destroy_timer);
1952 wait_event_interruptible(hba->destroy_wait,
1953 test_bit(BNX2FC_FLAG_DESTROY_CMPL,
1955 clear_bit(BNX2FC_FLAG_DESTROY_CMPL, &hba->flags);
1956 /* This should never happen */
1957 if (signal_pending(current))
1958 flush_signals(current);
1960 del_timer_sync(&hba->destroy_timer);
1962 bnx2fc_unbind_adapter_devices(hba);
1967 * bnx2fc_ulp_stop - cnic callback to shutdown adapter instance
1969 * @handle: transport handle pointing to adapter structure
1971 * Driver checks if adapter is already in shutdown mode, if not start
1972 * the shutdown process.
1974 static void bnx2fc_ulp_stop(void *handle)
1976 struct bnx2fc_hba *hba = handle;
1977 struct bnx2fc_interface *interface;
1979 printk(KERN_ERR "ULP_STOP\n");
1981 mutex_lock(&bnx2fc_dev_lock);
1982 if (!test_bit(BNX2FC_FLAG_FW_INIT_DONE, &hba->flags))
1984 list_for_each_entry(interface, &if_list, list) {
1985 if (interface->hba == hba)
1986 bnx2fc_stop(interface);
1988 BUG_ON(hba->num_ofld_sess != 0);
1990 mutex_lock(&hba->hba_mutex);
1991 clear_bit(ADAPTER_STATE_UP, &hba->adapter_state);
1992 clear_bit(ADAPTER_STATE_GOING_DOWN,
1993 &hba->adapter_state);
1995 clear_bit(ADAPTER_STATE_READY, &hba->adapter_state);
1996 mutex_unlock(&hba->hba_mutex);
1998 bnx2fc_fw_destroy(hba);
2000 mutex_unlock(&bnx2fc_dev_lock);
2003 static void bnx2fc_start_disc(struct bnx2fc_interface *interface)
2005 struct fcoe_ctlr *ctlr = bnx2fc_to_ctlr(interface);
2006 struct fc_lport *lport;
2009 BNX2FC_MISC_DBG("Entered %s\n", __func__);
2010 /* Kick off FIP/FLOGI */
2011 if (!test_bit(BNX2FC_FLAG_FW_INIT_DONE, &interface->hba->flags)) {
2012 printk(KERN_ERR PFX "Init not done yet\n");
2017 BNX2FC_HBA_DBG(lport, "calling fc_fabric_login\n");
2019 if (!bnx2fc_link_ok(lport) && interface->enabled) {
2020 BNX2FC_HBA_DBG(lport, "ctlr_link_up\n");
2021 fcoe_ctlr_link_up(ctlr);
2022 fc_host_port_type(lport->host) = FC_PORTTYPE_NPORT;
2023 set_bit(ADAPTER_STATE_READY, &interface->hba->adapter_state);
2026 /* wait for the FCF to be selected before issuing FLOGI */
2027 while (!ctlr->sel_fcf) {
2029 /* give up after 3 secs */
2030 if (++wait_cnt > 12)
2034 /* Reset max receive frame size to default */
2035 if (fc_set_mfs(lport, BNX2FC_MFS))
2038 fc_lport_init(lport);
2039 fc_fabric_login(lport);
2044 * bnx2fc_ulp_init - Initialize an adapter instance
2046 * @dev : cnic device handle
2047 * Called from cnic_register_driver() context to initialize all
2048 * enumerated cnic devices. This routine allocates adapter structure
2049 * and other device specific resources.
2051 static void bnx2fc_ulp_init(struct cnic_dev *dev)
2053 struct bnx2fc_hba *hba;
2056 BNX2FC_MISC_DBG("Entered %s\n", __func__);
2057 /* bnx2fc works only when bnx2x is loaded */
2058 if (!test_bit(CNIC_F_BNX2X_CLASS, &dev->flags) ||
2059 (dev->max_fcoe_conn == 0)) {
2060 printk(KERN_ERR PFX "bnx2fc FCoE not supported on %s,"
2061 " flags: %lx fcoe_conn: %d\n",
2062 dev->netdev->name, dev->flags, dev->max_fcoe_conn);
2066 hba = bnx2fc_hba_create(dev);
2068 printk(KERN_ERR PFX "hba initialization failed\n");
2072 pr_info(PFX "FCoE initialized for %s.\n", dev->netdev->name);
2074 /* Add HBA to the adapter list */
2075 mutex_lock(&bnx2fc_dev_lock);
2076 list_add_tail(&hba->list, &adapter_list);
2078 mutex_unlock(&bnx2fc_dev_lock);
2080 dev->fcoe_cap = &hba->fcoe_cap;
2081 clear_bit(BNX2FC_CNIC_REGISTERED, &hba->reg_with_cnic);
2082 rc = dev->register_device(dev, CNIC_ULP_FCOE,
2085 printk(KERN_ERR PFX "register_device failed, rc = %d\n", rc);
2087 set_bit(BNX2FC_CNIC_REGISTERED, &hba->reg_with_cnic);
2090 /* Assumes rtnl_lock and the bnx2fc_dev_lock are already taken */
2091 static int __bnx2fc_disable(struct fcoe_ctlr *ctlr)
2093 struct bnx2fc_interface *interface = fcoe_ctlr_priv(ctlr);
2095 if (interface->enabled == true) {
2097 pr_err(PFX "__bnx2fc_disable: lport not found\n");
2100 interface->enabled = false;
2101 fcoe_ctlr_link_down(ctlr);
2102 fcoe_clean_pending_queue(ctlr->lp);
2109 * Deperecated: Use bnx2fc_enabled()
2111 static int bnx2fc_disable(struct net_device *netdev)
2113 struct bnx2fc_interface *interface;
2114 struct fcoe_ctlr *ctlr;
2118 mutex_lock(&bnx2fc_dev_lock);
2120 interface = bnx2fc_interface_lookup(netdev);
2121 ctlr = bnx2fc_to_ctlr(interface);
2125 pr_err(PFX "bnx2fc_disable: interface not found\n");
2127 rc = __bnx2fc_disable(ctlr);
2129 mutex_unlock(&bnx2fc_dev_lock);
2134 static uint bnx2fc_npiv_create_vports(struct fc_lport *lport,
2135 struct cnic_fc_npiv_tbl *npiv_tbl)
2137 struct fc_vport_identifiers vpid;
2138 uint i, created = 0;
2143 if (npiv_tbl->count > MAX_NPIV_ENTRIES) {
2144 BNX2FC_HBA_DBG(lport, "Exceeded count max of npiv table\n");
2148 /* Sanity check the first entry to make sure it's not 0 */
2149 if (wwn_to_u64(npiv_tbl->wwnn[0]) == 0 &&
2150 wwn_to_u64(npiv_tbl->wwpn[0]) == 0) {
2151 BNX2FC_HBA_DBG(lport, "First NPIV table entries invalid.\n");
2155 vpid.roles = FC_PORT_ROLE_FCP_INITIATOR;
2156 vpid.vport_type = FC_PORTTYPE_NPIV;
2157 vpid.disable = false;
2159 for (i = 0; i < npiv_tbl->count; i++) {
2160 wwnn = wwn_to_u64(npiv_tbl->wwnn[i]);
2163 * If we get a 0 element from for the WWNN then assume
2164 * the WWNN should be the same as the physical port.
2168 vpid.node_name = wwnn;
2169 vpid.port_name = wwn_to_u64(npiv_tbl->wwpn[i]);
2170 scnprintf(vpid.symbolic_name, sizeof(vpid.symbolic_name),
2171 "NPIV[%u]:%016llx-%016llx",
2172 created, vpid.port_name, vpid.node_name);
2173 fcoe_wwn_to_str(vpid.node_name, wwnn_str, sizeof(wwnn_str));
2174 fcoe_wwn_to_str(vpid.port_name, wwpn_str, sizeof(wwpn_str));
2175 BNX2FC_HBA_DBG(lport, "Creating vport %s:%s.\n", wwnn_str,
2177 if (fc_vport_create(lport->host, 0, &vpid))
2180 BNX2FC_HBA_DBG(lport, "Failed to create vport\n");
2186 static int __bnx2fc_enable(struct fcoe_ctlr *ctlr)
2188 struct bnx2fc_interface *interface = fcoe_ctlr_priv(ctlr);
2189 struct bnx2fc_hba *hba;
2190 struct cnic_fc_npiv_tbl *npiv_tbl;
2191 struct fc_lport *lport;
2193 if (interface->enabled == false) {
2195 pr_err(PFX "__bnx2fc_enable: lport not found\n");
2197 } else if (!bnx2fc_link_ok(ctlr->lp)) {
2198 fcoe_ctlr_link_up(ctlr);
2199 interface->enabled = true;
2203 /* Create static NPIV ports if any are contained in NVRAM */
2204 hba = interface->hba;
2219 if (!hba->cnic->get_fc_npiv_tbl)
2222 npiv_tbl = kzalloc(sizeof(struct cnic_fc_npiv_tbl), GFP_KERNEL);
2226 if (hba->cnic->get_fc_npiv_tbl(hba->cnic, npiv_tbl))
2229 bnx2fc_npiv_create_vports(lport, npiv_tbl);
2237 * Deprecated: Use bnx2fc_enabled()
2239 static int bnx2fc_enable(struct net_device *netdev)
2241 struct bnx2fc_interface *interface;
2242 struct fcoe_ctlr *ctlr;
2246 mutex_lock(&bnx2fc_dev_lock);
2248 interface = bnx2fc_interface_lookup(netdev);
2249 ctlr = bnx2fc_to_ctlr(interface);
2252 pr_err(PFX "bnx2fc_enable: interface not found\n");
2254 rc = __bnx2fc_enable(ctlr);
2257 mutex_unlock(&bnx2fc_dev_lock);
2263 * bnx2fc_ctlr_enabled() - Enable or disable an FCoE Controller
2264 * @cdev: The FCoE Controller that is being enabled or disabled
2266 * fcoe_sysfs will ensure that the state of 'enabled' has
2267 * changed, so no checking is necessary here. This routine simply
2268 * calls fcoe_enable or fcoe_disable, both of which are deprecated.
2269 * When those routines are removed the functionality can be merged
2272 static int bnx2fc_ctlr_enabled(struct fcoe_ctlr_device *cdev)
2274 struct fcoe_ctlr *ctlr = fcoe_ctlr_device_priv(cdev);
2276 switch (cdev->enabled) {
2277 case FCOE_CTLR_ENABLED:
2278 return __bnx2fc_enable(ctlr);
2279 case FCOE_CTLR_DISABLED:
2280 return __bnx2fc_disable(ctlr);
2281 case FCOE_CTLR_UNUSED:
2287 enum bnx2fc_create_link_state {
2288 BNX2FC_CREATE_LINK_DOWN,
2289 BNX2FC_CREATE_LINK_UP,
2293 * _bnx2fc_create() - Create bnx2fc FCoE interface
2294 * @netdev : The net_device object the Ethernet interface to create on
2295 * @fip_mode: The FIP mode for this creation
2296 * @link_state: The ctlr link state on creation
2298 * Called from either the libfcoe 'create' module parameter
2299 * via fcoe_create or from fcoe_syfs's ctlr_create file.
2301 * libfcoe's 'create' module parameter is deprecated so some
2302 * consolidation of code can be done when that interface is
2305 * Returns: 0 for success
2307 static int _bnx2fc_create(struct net_device *netdev,
2308 enum fip_mode fip_mode,
2309 enum bnx2fc_create_link_state link_state)
2311 struct fcoe_ctlr_device *cdev;
2312 struct fcoe_ctlr *ctlr;
2313 struct bnx2fc_interface *interface;
2314 struct bnx2fc_hba *hba;
2315 struct net_device *phys_dev = netdev;
2316 struct fc_lport *lport;
2317 struct ethtool_drvinfo drvinfo;
2321 BNX2FC_MISC_DBG("Entered bnx2fc_create\n");
2322 if (fip_mode != FIP_MODE_FABRIC) {
2323 printk(KERN_ERR "fip mode not FABRIC\n");
2329 mutex_lock(&bnx2fc_dev_lock);
2331 if (!try_module_get(THIS_MODULE)) {
2336 /* obtain physical netdev */
2337 if (is_vlan_dev(netdev))
2338 phys_dev = vlan_dev_real_dev(netdev);
2340 /* verify if the physical device is a netxtreme2 device */
2341 if (phys_dev->ethtool_ops && phys_dev->ethtool_ops->get_drvinfo) {
2342 memset(&drvinfo, 0, sizeof(drvinfo));
2343 phys_dev->ethtool_ops->get_drvinfo(phys_dev, &drvinfo);
2344 if (strncmp(drvinfo.driver, "bnx2x", strlen("bnx2x"))) {
2345 printk(KERN_ERR PFX "Not a netxtreme2 device\n");
2350 printk(KERN_ERR PFX "unable to obtain drv_info\n");
2355 /* obtain interface and initialize rest of the structure */
2356 hba = bnx2fc_hba_lookup(phys_dev);
2359 printk(KERN_ERR PFX "bnx2fc_create: hba not found\n");
2363 if (bnx2fc_interface_lookup(netdev)) {
2368 interface = bnx2fc_interface_create(hba, netdev, fip_mode);
2370 printk(KERN_ERR PFX "bnx2fc_interface_create failed\n");
2375 if (is_vlan_dev(netdev)) {
2376 vlan_id = vlan_dev_vlan_id(netdev);
2377 interface->vlan_enabled = 1;
2380 ctlr = bnx2fc_to_ctlr(interface);
2381 cdev = fcoe_ctlr_to_ctlr_dev(ctlr);
2382 interface->vlan_id = vlan_id;
2383 interface->tm_timeout = BNX2FC_TM_TIMEOUT;
2385 interface->timer_work_queue =
2386 create_singlethread_workqueue("bnx2fc_timer_wq");
2387 if (!interface->timer_work_queue) {
2388 printk(KERN_ERR PFX "ulp_init could not create timer_wq\n");
2393 lport = bnx2fc_if_create(interface, &cdev->dev, 0);
2395 printk(KERN_ERR PFX "Failed to create interface (%s)\n",
2401 /* Add interface to if_list */
2402 list_add_tail(&interface->list, &if_list);
2404 lport->boot_time = jiffies;
2406 /* Make this master N_port */
2409 if (link_state == BNX2FC_CREATE_LINK_UP)
2410 cdev->enabled = FCOE_CTLR_ENABLED;
2412 cdev->enabled = FCOE_CTLR_DISABLED;
2414 if (link_state == BNX2FC_CREATE_LINK_UP &&
2415 !bnx2fc_link_ok(lport)) {
2416 fcoe_ctlr_link_up(ctlr);
2417 fc_host_port_type(lport->host) = FC_PORTTYPE_NPORT;
2418 set_bit(ADAPTER_STATE_READY, &interface->hba->adapter_state);
2421 BNX2FC_HBA_DBG(lport, "create: START DISC\n");
2422 bnx2fc_start_disc(interface);
2424 if (link_state == BNX2FC_CREATE_LINK_UP)
2425 interface->enabled = true;
2428 * Release from kref_init in bnx2fc_interface_setup, on success
2429 * lport should be holding a reference taken in bnx2fc_if_create
2431 bnx2fc_interface_put(interface);
2432 /* put netdev that was held while calling dev_get_by_name */
2433 mutex_unlock(&bnx2fc_dev_lock);
2438 destroy_workqueue(interface->timer_work_queue);
2440 bnx2fc_net_cleanup(interface);
2441 bnx2fc_interface_put(interface);
2444 module_put(THIS_MODULE);
2446 mutex_unlock(&bnx2fc_dev_lock);
2452 * bnx2fc_create() - Create a bnx2fc interface
2453 * @netdev : The net_device object the Ethernet interface to create on
2454 * @fip_mode: The FIP mode for this creation
2456 * Called from fcoe transport
2458 * Returns: 0 for success
2460 static int bnx2fc_create(struct net_device *netdev, enum fip_mode fip_mode)
2462 return _bnx2fc_create(netdev, fip_mode, BNX2FC_CREATE_LINK_UP);
2466 * bnx2fc_ctlr_alloc() - Allocate a bnx2fc interface from fcoe_sysfs
2467 * @netdev: The net_device to be used by the allocated FCoE Controller
2469 * This routine is called from fcoe_sysfs. It will start the fcoe_ctlr
2470 * in a link_down state. The allows the user an opportunity to configure
2471 * the FCoE Controller from sysfs before enabling the FCoE Controller.
2473 * Creating in with this routine starts the FCoE Controller in Fabric
2474 * mode. The user can change to VN2VN or another mode before enabling.
2476 static int bnx2fc_ctlr_alloc(struct net_device *netdev)
2478 return _bnx2fc_create(netdev, FIP_MODE_FABRIC,
2479 BNX2FC_CREATE_LINK_DOWN);
2483 * bnx2fc_find_hba_for_cnic - maps cnic instance to bnx2fc hba instance
2485 * @cnic: Pointer to cnic device instance
2488 static struct bnx2fc_hba *bnx2fc_find_hba_for_cnic(struct cnic_dev *cnic)
2490 struct bnx2fc_hba *hba;
2492 /* Called with bnx2fc_dev_lock held */
2493 list_for_each_entry(hba, &adapter_list, list) {
2494 if (hba->cnic == cnic)
2500 static struct bnx2fc_interface *bnx2fc_interface_lookup(struct net_device
2503 struct bnx2fc_interface *interface;
2505 /* Called with bnx2fc_dev_lock held */
2506 list_for_each_entry(interface, &if_list, list) {
2507 if (interface->netdev == netdev)
2513 static struct bnx2fc_hba *bnx2fc_hba_lookup(struct net_device
2516 struct bnx2fc_hba *hba;
2518 /* Called with bnx2fc_dev_lock held */
2519 list_for_each_entry(hba, &adapter_list, list) {
2520 if (hba->phys_dev == phys_dev)
2523 printk(KERN_ERR PFX "adapter_lookup: hba NULL\n");
2528 * bnx2fc_ulp_exit - shuts down adapter instance and frees all resources
2530 * @dev cnic device handle
2532 static void bnx2fc_ulp_exit(struct cnic_dev *dev)
2534 struct bnx2fc_hba *hba;
2535 struct bnx2fc_interface *interface, *tmp;
2537 BNX2FC_MISC_DBG("Entered bnx2fc_ulp_exit\n");
2539 if (!test_bit(CNIC_F_BNX2X_CLASS, &dev->flags)) {
2540 printk(KERN_ERR PFX "bnx2fc port check: %s, flags: %lx\n",
2541 dev->netdev->name, dev->flags);
2545 mutex_lock(&bnx2fc_dev_lock);
2546 hba = bnx2fc_find_hba_for_cnic(dev);
2548 printk(KERN_ERR PFX "bnx2fc_ulp_exit: hba not found, dev 0%p\n",
2550 mutex_unlock(&bnx2fc_dev_lock);
2554 list_del_init(&hba->list);
2557 list_for_each_entry_safe(interface, tmp, &if_list, list)
2558 /* destroy not called yet, move to quiesced list */
2559 if (interface->hba == hba)
2560 __bnx2fc_destroy(interface);
2561 mutex_unlock(&bnx2fc_dev_lock);
2563 bnx2fc_ulp_stop(hba);
2564 /* unregister cnic device */
2565 if (test_and_clear_bit(BNX2FC_CNIC_REGISTERED, &hba->reg_with_cnic))
2566 hba->cnic->unregister_device(hba->cnic, CNIC_ULP_FCOE);
2567 bnx2fc_hba_destroy(hba);
2570 static void bnx2fc_rport_terminate_io(struct fc_rport *rport)
2572 /* This is a no-op */
2576 * bnx2fc_fcoe_reset - Resets the fcoe
2578 * @shost: shost the reset is from
2582 static int bnx2fc_fcoe_reset(struct Scsi_Host *shost)
2584 struct fc_lport *lport = shost_priv(shost);
2585 fc_lport_reset(lport);
2590 static bool bnx2fc_match(struct net_device *netdev)
2592 struct net_device *phys_dev = netdev;
2594 mutex_lock(&bnx2fc_dev_lock);
2595 if (is_vlan_dev(netdev))
2596 phys_dev = vlan_dev_real_dev(netdev);
2598 if (bnx2fc_hba_lookup(phys_dev)) {
2599 mutex_unlock(&bnx2fc_dev_lock);
2603 mutex_unlock(&bnx2fc_dev_lock);
2608 static struct fcoe_transport bnx2fc_transport = {
2611 .list = LIST_HEAD_INIT(bnx2fc_transport.list),
2612 .alloc = bnx2fc_ctlr_alloc,
2613 .match = bnx2fc_match,
2614 .create = bnx2fc_create,
2615 .destroy = bnx2fc_destroy,
2616 .enable = bnx2fc_enable,
2617 .disable = bnx2fc_disable,
2621 * bnx2fc_cpu_online - Create a receive thread for an online CPU
2623 * @cpu: cpu index for the online cpu
2625 static int bnx2fc_cpu_online(unsigned int cpu)
2627 struct bnx2fc_percpu_s *p;
2628 struct task_struct *thread;
2630 p = &per_cpu(bnx2fc_percpu, cpu);
2632 thread = kthread_create_on_node(bnx2fc_percpu_io_thread,
2633 (void *)p, cpu_to_node(cpu),
2634 "bnx2fc_thread/%d", cpu);
2636 return PTR_ERR(thread);
2638 /* bind thread to the cpu */
2639 kthread_bind(thread, cpu);
2640 p->iothread = thread;
2641 wake_up_process(thread);
2645 static int bnx2fc_cpu_offline(unsigned int cpu)
2647 struct bnx2fc_percpu_s *p;
2648 struct task_struct *thread;
2649 struct bnx2fc_work *work, *tmp;
2651 BNX2FC_MISC_DBG("destroying io thread for CPU %d\n", cpu);
2653 /* Prevent any new work from being queued for this CPU */
2654 p = &per_cpu(bnx2fc_percpu, cpu);
2655 spin_lock_bh(&p->fp_work_lock);
2656 thread = p->iothread;
2659 /* Free all work in the list */
2660 list_for_each_entry_safe(work, tmp, &p->work_list, list) {
2661 list_del_init(&work->list);
2662 bnx2fc_process_cq_compl(work->tgt, work->wqe);
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 .use_clustering = ENABLE_CLUSTERING,
2976 .sg_tablesize = BNX2FC_MAX_BDS_PER_CMD,
2977 .max_sectors = 1024,
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,