1 /* bnx2fc_fcoe.c: Broadcom NetXtreme II 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 - 2010 Broadcom Corporation
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation.
12 * Written by: Bhanu Prakash Gollapudi (bprakash@broadcom.com)
17 static struct list_head adapter_list;
18 static u32 adapter_count;
19 static DEFINE_MUTEX(bnx2fc_dev_lock);
20 DEFINE_PER_CPU(struct bnx2fc_percpu_s, bnx2fc_percpu);
22 #define DRV_MODULE_NAME "bnx2fc"
23 #define DRV_MODULE_VERSION BNX2FC_VERSION
24 #define DRV_MODULE_RELDATE "Mar 17, 2011"
27 static char version[] __devinitdata =
28 "Broadcom NetXtreme II FCoE Driver " DRV_MODULE_NAME \
29 " v" DRV_MODULE_VERSION " (" DRV_MODULE_RELDATE ")\n";
32 MODULE_AUTHOR("Bhanu Prakash Gollapudi <bprakash@broadcom.com>");
33 MODULE_DESCRIPTION("Broadcom NetXtreme II BCM57710 FCoE Driver");
34 MODULE_LICENSE("GPL");
35 MODULE_VERSION(DRV_MODULE_VERSION);
37 #define BNX2FC_MAX_QUEUE_DEPTH 256
38 #define BNX2FC_MIN_QUEUE_DEPTH 32
39 #define FCOE_WORD_TO_BYTE 4
41 static struct scsi_transport_template *bnx2fc_transport_template;
42 static struct scsi_transport_template *bnx2fc_vport_xport_template;
44 struct workqueue_struct *bnx2fc_wq;
46 /* bnx2fc structure needs only one instance of the fcoe_percpu_s structure.
47 * Here the io threads are per cpu but the l2 thread is just one
49 struct fcoe_percpu_s bnx2fc_global;
50 DEFINE_SPINLOCK(bnx2fc_global_lock);
52 static struct cnic_ulp_ops bnx2fc_cnic_cb;
53 static struct libfc_function_template bnx2fc_libfc_fcn_templ;
54 static struct scsi_host_template bnx2fc_shost_template;
55 static struct fc_function_template bnx2fc_transport_function;
56 static struct fc_function_template bnx2fc_vport_xport_function;
57 static int bnx2fc_create(struct net_device *netdev, enum fip_state fip_mode);
58 static int bnx2fc_destroy(struct net_device *net_device);
59 static int bnx2fc_enable(struct net_device *netdev);
60 static int bnx2fc_disable(struct net_device *netdev);
62 static void bnx2fc_recv_frame(struct sk_buff *skb);
64 static void bnx2fc_start_disc(struct bnx2fc_hba *hba);
65 static int bnx2fc_shost_config(struct fc_lport *lport, struct device *dev);
66 static int bnx2fc_net_config(struct fc_lport *lp);
67 static int bnx2fc_lport_config(struct fc_lport *lport);
68 static int bnx2fc_em_config(struct fc_lport *lport);
69 static int bnx2fc_bind_adapter_devices(struct bnx2fc_hba *hba);
70 static void bnx2fc_unbind_adapter_devices(struct bnx2fc_hba *hba);
71 static int bnx2fc_bind_pcidev(struct bnx2fc_hba *hba);
72 static void bnx2fc_unbind_pcidev(struct bnx2fc_hba *hba);
73 static struct fc_lport *bnx2fc_if_create(struct bnx2fc_hba *hba,
74 struct device *parent, int npiv);
75 static void bnx2fc_destroy_work(struct work_struct *work);
77 static struct bnx2fc_hba *bnx2fc_hba_lookup(struct net_device *phys_dev);
78 static struct bnx2fc_hba *bnx2fc_find_hba_for_cnic(struct cnic_dev *cnic);
80 static int bnx2fc_fw_init(struct bnx2fc_hba *hba);
81 static void bnx2fc_fw_destroy(struct bnx2fc_hba *hba);
83 static void bnx2fc_port_shutdown(struct fc_lport *lport);
84 static void bnx2fc_stop(struct bnx2fc_hba *hba);
85 static int __init bnx2fc_mod_init(void);
86 static void __exit bnx2fc_mod_exit(void);
88 unsigned int bnx2fc_debug_level;
89 module_param_named(debug_logging, bnx2fc_debug_level, int, S_IRUGO|S_IWUSR);
91 static int bnx2fc_cpu_callback(struct notifier_block *nfb,
92 unsigned long action, void *hcpu);
93 /* notification function for CPU hotplug events */
94 static struct notifier_block bnx2fc_cpu_notifier = {
95 .notifier_call = bnx2fc_cpu_callback,
98 static void bnx2fc_clean_rx_queue(struct fc_lport *lp)
100 struct fcoe_percpu_s *bg;
101 struct fcoe_rcv_info *fr;
102 struct sk_buff_head *list;
103 struct sk_buff *skb, *next;
104 struct sk_buff *head;
107 spin_lock_bh(&bg->fcoe_rx_list.lock);
108 list = &bg->fcoe_rx_list;
110 for (skb = head; skb != (struct sk_buff *)list;
113 fr = fcoe_dev_from_skb(skb);
114 if (fr->fr_dev == lp) {
115 __skb_unlink(skb, list);
119 spin_unlock_bh(&bg->fcoe_rx_list.lock);
122 int bnx2fc_get_paged_crc_eof(struct sk_buff *skb, int tlen)
125 spin_lock(&bnx2fc_global_lock);
126 rc = fcoe_get_paged_crc_eof(skb, tlen, &bnx2fc_global);
127 spin_unlock(&bnx2fc_global_lock);
132 static void bnx2fc_abort_io(struct fc_lport *lport)
135 * This function is no-op for bnx2fc, but we do
136 * not want to leave it as NULL either, as libfc
137 * can call the default function which is
142 static void bnx2fc_cleanup(struct fc_lport *lport)
144 struct fcoe_port *port = lport_priv(lport);
145 struct bnx2fc_hba *hba = port->priv;
146 struct bnx2fc_rport *tgt;
149 BNX2FC_MISC_DBG("Entered %s\n", __func__);
150 mutex_lock(&hba->hba_mutex);
151 spin_lock_bh(&hba->hba_lock);
152 for (i = 0; i < BNX2FC_NUM_MAX_SESS; i++) {
153 tgt = hba->tgt_ofld_list[i];
155 /* Cleanup IOs belonging to requested vport */
156 if (tgt->port == port) {
157 spin_unlock_bh(&hba->hba_lock);
158 BNX2FC_TGT_DBG(tgt, "flush/cleanup\n");
159 bnx2fc_flush_active_ios(tgt);
160 spin_lock_bh(&hba->hba_lock);
164 spin_unlock_bh(&hba->hba_lock);
165 mutex_unlock(&hba->hba_mutex);
168 static int bnx2fc_xmit_l2_frame(struct bnx2fc_rport *tgt,
171 struct fc_rport_priv *rdata = tgt->rdata;
172 struct fc_frame_header *fh;
175 fh = fc_frame_header_get(fp);
176 BNX2FC_TGT_DBG(tgt, "Xmit L2 frame rport = 0x%x, oxid = 0x%x, "
177 "r_ctl = 0x%x\n", rdata->ids.port_id,
178 ntohs(fh->fh_ox_id), fh->fh_r_ctl);
179 if ((fh->fh_type == FC_TYPE_ELS) &&
180 (fh->fh_r_ctl == FC_RCTL_ELS_REQ)) {
182 switch (fc_frame_payload_op(fp)) {
184 rc = bnx2fc_send_adisc(tgt, fp);
187 rc = bnx2fc_send_logo(tgt, fp);
190 rc = bnx2fc_send_rls(tgt, fp);
195 } else if ((fh->fh_type == FC_TYPE_BLS) &&
196 (fh->fh_r_ctl == FC_RCTL_BA_ABTS))
197 BNX2FC_TGT_DBG(tgt, "ABTS frame\n");
199 BNX2FC_TGT_DBG(tgt, "Send L2 frame type 0x%x "
200 "rctl 0x%x thru non-offload path\n",
201 fh->fh_type, fh->fh_r_ctl);
211 * bnx2fc_xmit - bnx2fc's FCoE frame transmit function
213 * @lport: the associated local port
214 * @fp: the fc_frame to be transmitted
216 static int bnx2fc_xmit(struct fc_lport *lport, struct fc_frame *fp)
219 struct fcoe_crc_eof *cp;
221 struct fc_frame_header *fh;
222 struct bnx2fc_hba *hba;
223 struct fcoe_port *port;
225 struct bnx2fc_rport *tgt;
226 struct fcoe_dev_stats *stats;
229 unsigned int hlen, tlen, elen;
232 port = (struct fcoe_port *)lport_priv(lport);
235 fh = fc_frame_header_get(fp);
238 if (!lport->link_up) {
239 BNX2FC_HBA_DBG(lport, "bnx2fc_xmit link down\n");
244 if (unlikely(fh->fh_r_ctl == FC_RCTL_ELS_REQ)) {
245 if (!hba->ctlr.sel_fcf) {
246 BNX2FC_HBA_DBG(lport, "FCF not selected yet!\n");
250 if (fcoe_ctlr_els_send(&hba->ctlr, lport, skb))
258 * Snoop the frame header to check if the frame is for
259 * an offloaded session
262 * tgt_ofld_list access is synchronized using
263 * both hba mutex and hba lock. Atleast hba mutex or
264 * hba lock needs to be held for read access.
267 spin_lock_bh(&hba->hba_lock);
268 tgt = bnx2fc_tgt_lookup(port, ntoh24(fh->fh_d_id));
269 if (tgt && (test_bit(BNX2FC_FLAG_SESSION_READY, &tgt->flags))) {
270 /* This frame is for offloaded session */
271 BNX2FC_HBA_DBG(lport, "xmit: Frame is for offloaded session "
272 "port_id = 0x%x\n", ntoh24(fh->fh_d_id));
273 spin_unlock_bh(&hba->hba_lock);
274 rc = bnx2fc_xmit_l2_frame(tgt, fp);
280 spin_unlock_bh(&hba->hba_lock);
283 elen = sizeof(struct ethhdr);
284 hlen = sizeof(struct fcoe_hdr);
285 tlen = sizeof(struct fcoe_crc_eof);
286 wlen = (skb->len - tlen + sizeof(crc)) / FCOE_WORD_TO_BYTE;
288 skb->ip_summed = CHECKSUM_NONE;
289 crc = fcoe_fc_crc(fp);
291 /* copy port crc and eof to the skb buff */
292 if (skb_is_nonlinear(skb)) {
294 if (bnx2fc_get_paged_crc_eof(skb, tlen)) {
298 frag = &skb_shinfo(skb)->frags[skb_shinfo(skb)->nr_frags - 1];
299 cp = kmap_atomic(frag->page, KM_SKB_DATA_SOFTIRQ)
302 cp = (struct fcoe_crc_eof *)skb_put(skb, tlen);
305 memset(cp, 0, sizeof(*cp));
307 cp->fcoe_crc32 = cpu_to_le32(~crc);
308 if (skb_is_nonlinear(skb)) {
309 kunmap_atomic(cp, KM_SKB_DATA_SOFTIRQ);
313 /* adjust skb network/transport offsets to match mac/fcoe/port */
314 skb_push(skb, elen + hlen);
315 skb_reset_mac_header(skb);
316 skb_reset_network_header(skb);
318 skb->protocol = htons(ETH_P_FCOE);
319 skb->dev = hba->netdev;
321 /* fill up mac and fcoe headers */
323 eh->h_proto = htons(ETH_P_FCOE);
324 if (hba->ctlr.map_dest)
325 fc_fcoe_set_mac(eh->h_dest, fh->fh_d_id);
327 /* insert GW address */
328 memcpy(eh->h_dest, hba->ctlr.dest_addr, ETH_ALEN);
330 if (unlikely(hba->ctlr.flogi_oxid != FC_XID_UNKNOWN))
331 memcpy(eh->h_source, hba->ctlr.ctl_src_addr, ETH_ALEN);
333 memcpy(eh->h_source, port->data_src_addr, ETH_ALEN);
335 hp = (struct fcoe_hdr *)(eh + 1);
336 memset(hp, 0, sizeof(*hp));
338 FC_FCOE_ENCAPS_VER(hp, FC_FCOE_VER);
341 /* fcoe lso, mss is in max_payload which is non-zero for FCP data */
342 if (lport->seq_offload && fr_max_payload(fp)) {
343 skb_shinfo(skb)->gso_type = SKB_GSO_FCOE;
344 skb_shinfo(skb)->gso_size = fr_max_payload(fp);
346 skb_shinfo(skb)->gso_type = 0;
347 skb_shinfo(skb)->gso_size = 0;
351 stats = per_cpu_ptr(lport->dev_stats, get_cpu());
353 stats->TxWords += wlen;
356 /* send down to lld */
358 if (port->fcoe_pending_queue.qlen)
359 fcoe_check_wait_queue(lport, skb);
360 else if (fcoe_start_io(skb))
361 fcoe_check_wait_queue(lport, skb);
367 * bnx2fc_rcv - This is bnx2fc's receive function called by NET_RX_SOFTIRQ
369 * @skb: the receive socket buffer
370 * @dev: associated net device
372 * @olddev: last device
374 * This function receives the packet and builds FC frame and passes it up
376 static int bnx2fc_rcv(struct sk_buff *skb, struct net_device *dev,
377 struct packet_type *ptype, struct net_device *olddev)
379 struct fc_lport *lport;
380 struct bnx2fc_hba *hba;
381 struct fc_frame_header *fh;
382 struct fcoe_rcv_info *fr;
383 struct fcoe_percpu_s *bg;
386 hba = container_of(ptype, struct bnx2fc_hba, fcoe_packet_type);
387 lport = hba->ctlr.lp;
389 if (unlikely(lport == NULL)) {
390 printk(KERN_ALERT PFX "bnx2fc_rcv: lport is NULL\n");
394 if (unlikely(eth_hdr(skb)->h_proto != htons(ETH_P_FCOE))) {
395 printk(KERN_ALERT PFX "bnx2fc_rcv: Wrong FC type frame\n");
400 * Check for minimum frame length, and make sure required FCoE
401 * and FC headers are pulled into the linear data area.
403 if (unlikely((skb->len < FCOE_MIN_FRAME) ||
404 !pskb_may_pull(skb, FCOE_HEADER_LEN)))
407 skb_set_transport_header(skb, sizeof(struct fcoe_hdr));
408 fh = (struct fc_frame_header *) skb_transport_header(skb);
410 oxid = ntohs(fh->fh_ox_id);
412 fr = fcoe_dev_from_skb(skb);
417 spin_lock_bh(&bg->fcoe_rx_list.lock);
419 __skb_queue_tail(&bg->fcoe_rx_list, skb);
420 if (bg->fcoe_rx_list.qlen == 1)
421 wake_up_process(bg->thread);
423 spin_unlock_bh(&bg->fcoe_rx_list.lock);
431 static int bnx2fc_l2_rcv_thread(void *arg)
433 struct fcoe_percpu_s *bg = arg;
436 set_user_nice(current, -20);
437 set_current_state(TASK_INTERRUPTIBLE);
438 while (!kthread_should_stop()) {
440 spin_lock_bh(&bg->fcoe_rx_list.lock);
441 while ((skb = __skb_dequeue(&bg->fcoe_rx_list)) != NULL) {
442 spin_unlock_bh(&bg->fcoe_rx_list.lock);
443 bnx2fc_recv_frame(skb);
444 spin_lock_bh(&bg->fcoe_rx_list.lock);
446 __set_current_state(TASK_INTERRUPTIBLE);
447 spin_unlock_bh(&bg->fcoe_rx_list.lock);
449 __set_current_state(TASK_RUNNING);
454 static void bnx2fc_recv_frame(struct sk_buff *skb)
457 struct fc_lport *lport;
458 struct fcoe_rcv_info *fr;
459 struct fcoe_dev_stats *stats;
460 struct fc_frame_header *fh;
461 struct fcoe_crc_eof crc_eof;
463 struct fc_lport *vn_port;
464 struct fcoe_port *port;
469 fr = fcoe_dev_from_skb(skb);
471 if (unlikely(lport == NULL)) {
472 printk(KERN_ALERT PFX "Invalid lport struct\n");
477 if (skb_is_nonlinear(skb))
479 mac = eth_hdr(skb)->h_source;
480 dest_mac = eth_hdr(skb)->h_dest;
482 /* Pull the header */
483 hp = (struct fcoe_hdr *) skb_network_header(skb);
484 fh = (struct fc_frame_header *) skb_transport_header(skb);
485 skb_pull(skb, sizeof(struct fcoe_hdr));
486 fr_len = skb->len - sizeof(struct fcoe_crc_eof);
488 stats = per_cpu_ptr(lport->dev_stats, get_cpu());
490 stats->RxWords += fr_len / FCOE_WORD_TO_BYTE;
492 fp = (struct fc_frame *)skb;
495 fr_sof(fp) = hp->fcoe_sof;
496 if (skb_copy_bits(skb, fr_len, &crc_eof, sizeof(crc_eof))) {
501 fr_eof(fp) = crc_eof.fcoe_eof;
502 fr_crc(fp) = crc_eof.fcoe_crc32;
503 if (pskb_trim(skb, fr_len)) {
509 fh = fc_frame_header_get(fp);
511 vn_port = fc_vport_id_lookup(lport, ntoh24(fh->fh_d_id));
513 port = lport_priv(vn_port);
514 if (compare_ether_addr(port->data_src_addr, dest_mac)
516 BNX2FC_HBA_DBG(lport, "fpma mismatch\n");
522 if (fh->fh_r_ctl == FC_RCTL_DD_SOL_DATA &&
523 fh->fh_type == FC_TYPE_FCP) {
524 /* Drop FCP data. We dont this in L2 path */
529 if (fh->fh_r_ctl == FC_RCTL_ELS_REQ &&
530 fh->fh_type == FC_TYPE_ELS) {
531 switch (fc_frame_payload_op(fp)) {
533 if (ntoh24(fh->fh_s_id) == FC_FID_FLOGI) {
534 /* drop non-FIP LOGO */
542 if (le32_to_cpu(fr_crc(fp)) !=
543 ~crc32(~0, skb->data, fr_len)) {
544 if (stats->InvalidCRCCount < 5)
545 printk(KERN_WARNING PFX "dropping frame with "
547 stats->InvalidCRCCount++;
553 fc_exch_recv(lport, fp);
557 * bnx2fc_percpu_io_thread - thread per cpu for ios
559 * @arg: ptr to bnx2fc_percpu_info structure
561 int bnx2fc_percpu_io_thread(void *arg)
563 struct bnx2fc_percpu_s *p = arg;
564 struct bnx2fc_work *work, *tmp;
565 LIST_HEAD(work_list);
567 set_user_nice(current, -20);
568 set_current_state(TASK_INTERRUPTIBLE);
569 while (!kthread_should_stop()) {
571 spin_lock_bh(&p->fp_work_lock);
572 while (!list_empty(&p->work_list)) {
573 list_splice_init(&p->work_list, &work_list);
574 spin_unlock_bh(&p->fp_work_lock);
576 list_for_each_entry_safe(work, tmp, &work_list, list) {
577 list_del_init(&work->list);
578 bnx2fc_process_cq_compl(work->tgt, work->wqe);
582 spin_lock_bh(&p->fp_work_lock);
584 __set_current_state(TASK_INTERRUPTIBLE);
585 spin_unlock_bh(&p->fp_work_lock);
587 __set_current_state(TASK_RUNNING);
592 static struct fc_host_statistics *bnx2fc_get_host_stats(struct Scsi_Host *shost)
594 struct fc_host_statistics *bnx2fc_stats;
595 struct fc_lport *lport = shost_priv(shost);
596 struct fcoe_port *port = lport_priv(lport);
597 struct bnx2fc_hba *hba = port->priv;
598 struct fcoe_statistics_params *fw_stats;
601 fw_stats = (struct fcoe_statistics_params *)hba->stats_buffer;
605 bnx2fc_stats = fc_get_host_stats(shost);
607 init_completion(&hba->stat_req_done);
608 if (bnx2fc_send_stat_req(hba))
610 rc = wait_for_completion_timeout(&hba->stat_req_done, (2 * HZ));
612 BNX2FC_HBA_DBG(lport, "FW stat req timed out\n");
615 bnx2fc_stats->invalid_crc_count += fw_stats->rx_stat1.fc_crc_cnt;
616 bnx2fc_stats->tx_frames += fw_stats->tx_stat.fcoe_tx_pkt_cnt;
617 bnx2fc_stats->tx_words += (fw_stats->tx_stat.fcoe_tx_byte_cnt) / 4;
618 bnx2fc_stats->rx_frames += fw_stats->rx_stat0.fcoe_rx_pkt_cnt;
619 bnx2fc_stats->rx_words += (fw_stats->rx_stat0.fcoe_rx_byte_cnt) / 4;
621 bnx2fc_stats->dumped_frames = 0;
622 bnx2fc_stats->lip_count = 0;
623 bnx2fc_stats->nos_count = 0;
624 bnx2fc_stats->loss_of_sync_count = 0;
625 bnx2fc_stats->loss_of_signal_count = 0;
626 bnx2fc_stats->prim_seq_protocol_err_count = 0;
631 static int bnx2fc_shost_config(struct fc_lport *lport, struct device *dev)
633 struct fcoe_port *port = lport_priv(lport);
634 struct bnx2fc_hba *hba = port->priv;
635 struct Scsi_Host *shost = lport->host;
638 shost->max_cmd_len = BNX2FC_MAX_CMD_LEN;
639 shost->max_lun = BNX2FC_MAX_LUN;
640 shost->max_id = BNX2FC_MAX_FCP_TGT;
641 shost->max_channel = 0;
643 shost->transportt = bnx2fc_vport_xport_template;
645 shost->transportt = bnx2fc_transport_template;
647 /* Add the new host to SCSI-ml */
648 rc = scsi_add_host(lport->host, dev);
650 printk(KERN_ERR PFX "Error on scsi_add_host\n");
654 fc_host_max_npiv_vports(lport->host) = USHRT_MAX;
655 sprintf(fc_host_symbolic_name(lport->host), "%s v%s over %s",
656 BNX2FC_NAME, BNX2FC_VERSION,
662 static void bnx2fc_link_speed_update(struct fc_lport *lport)
664 struct fcoe_port *port = lport_priv(lport);
665 struct bnx2fc_hba *hba = port->priv;
666 struct net_device *netdev = hba->netdev;
667 struct ethtool_cmd ecmd;
669 if (!dev_ethtool_get_settings(netdev, &ecmd)) {
670 lport->link_supported_speeds &=
671 ~(FC_PORTSPEED_1GBIT | FC_PORTSPEED_10GBIT);
672 if (ecmd.supported & (SUPPORTED_1000baseT_Half |
673 SUPPORTED_1000baseT_Full))
674 lport->link_supported_speeds |= FC_PORTSPEED_1GBIT;
675 if (ecmd.supported & SUPPORTED_10000baseT_Full)
676 lport->link_supported_speeds |= FC_PORTSPEED_10GBIT;
678 switch (ethtool_cmd_speed(&ecmd)) {
680 lport->link_speed = FC_PORTSPEED_1GBIT;
683 lport->link_speed = FC_PORTSPEED_2GBIT;
686 lport->link_speed = FC_PORTSPEED_10GBIT;
691 static int bnx2fc_link_ok(struct fc_lport *lport)
693 struct fcoe_port *port = lport_priv(lport);
694 struct bnx2fc_hba *hba = port->priv;
695 struct net_device *dev = hba->phys_dev;
698 if ((dev->flags & IFF_UP) && netif_carrier_ok(dev))
699 clear_bit(ADAPTER_STATE_LINK_DOWN, &hba->adapter_state);
701 set_bit(ADAPTER_STATE_LINK_DOWN, &hba->adapter_state);
708 * bnx2fc_get_link_state - get network link state
710 * @hba: adapter instance pointer
712 * updates adapter structure flag based on netdev state
714 void bnx2fc_get_link_state(struct bnx2fc_hba *hba)
716 if (test_bit(__LINK_STATE_NOCARRIER, &hba->netdev->state))
717 set_bit(ADAPTER_STATE_LINK_DOWN, &hba->adapter_state);
719 clear_bit(ADAPTER_STATE_LINK_DOWN, &hba->adapter_state);
722 static int bnx2fc_net_config(struct fc_lport *lport)
724 struct bnx2fc_hba *hba;
725 struct fcoe_port *port;
728 port = lport_priv(lport);
731 /* require support for get_pauseparam ethtool op. */
732 if (!hba->phys_dev->ethtool_ops ||
733 !hba->phys_dev->ethtool_ops->get_pauseparam)
736 if (fc_set_mfs(lport, BNX2FC_MFS))
739 skb_queue_head_init(&port->fcoe_pending_queue);
740 port->fcoe_pending_queue_active = 0;
741 setup_timer(&port->timer, fcoe_queue_timer, (unsigned long) lport);
743 bnx2fc_link_speed_update(lport);
746 wwnn = fcoe_wwn_from_mac(hba->ctlr.ctl_src_addr, 1, 0);
747 BNX2FC_HBA_DBG(lport, "WWNN = 0x%llx\n", wwnn);
748 fc_set_wwnn(lport, wwnn);
750 wwpn = fcoe_wwn_from_mac(hba->ctlr.ctl_src_addr, 2, 0);
751 BNX2FC_HBA_DBG(lport, "WWPN = 0x%llx\n", wwpn);
752 fc_set_wwpn(lport, wwpn);
758 static void bnx2fc_destroy_timer(unsigned long data)
760 struct bnx2fc_hba *hba = (struct bnx2fc_hba *)data;
762 BNX2FC_HBA_DBG(hba->ctlr.lp, "ERROR:bnx2fc_destroy_timer - "
763 "Destroy compl not received!!\n");
764 hba->flags |= BNX2FC_FLAG_DESTROY_CMPL;
765 wake_up_interruptible(&hba->destroy_wait);
769 * bnx2fc_indicate_netevent - Generic netdev event handler
771 * @context: adapter structure pointer
774 * Handles NETDEV_UP, NETDEV_DOWN, NETDEV_GOING_DOWN,NETDEV_CHANGE and
775 * NETDEV_CHANGE_MTU events
777 static void bnx2fc_indicate_netevent(void *context, unsigned long event)
779 struct bnx2fc_hba *hba = (struct bnx2fc_hba *)context;
780 struct fc_lport *lport = hba->ctlr.lp;
781 struct fc_lport *vport;
782 u32 link_possible = 1;
784 if (!test_bit(BNX2FC_CREATE_DONE, &hba->init_done)) {
785 BNX2FC_MISC_DBG("driver not ready. event=%s %ld\n",
786 hba->netdev->name, event);
792 * indicate_netevent cannot be called from cnic unless bnx2fc
793 * does register_device
797 BNX2FC_HBA_DBG(lport, "enter netevent handler - event=%s %ld\n",
798 hba->netdev->name, event);
802 BNX2FC_HBA_DBG(lport, "Port up, adapter_state = %ld\n",
804 if (!test_bit(ADAPTER_STATE_UP, &hba->adapter_state))
805 printk(KERN_ERR "indicate_netevent: "\
806 "adapter is not UP!!\n");
810 BNX2FC_HBA_DBG(lport, "Port down\n");
811 clear_bit(ADAPTER_STATE_GOING_DOWN, &hba->adapter_state);
812 clear_bit(ADAPTER_STATE_UP, &hba->adapter_state);
816 case NETDEV_GOING_DOWN:
817 BNX2FC_HBA_DBG(lport, "Port going down\n");
818 set_bit(ADAPTER_STATE_GOING_DOWN, &hba->adapter_state);
823 BNX2FC_HBA_DBG(lport, "NETDEV_CHANGE\n");
827 printk(KERN_ERR PFX "Unkonwn netevent %ld", event);
831 bnx2fc_link_speed_update(lport);
833 if (link_possible && !bnx2fc_link_ok(lport)) {
834 printk(KERN_ERR "indicate_netevent: call ctlr_link_up\n");
835 fcoe_ctlr_link_up(&hba->ctlr);
837 printk(KERN_ERR "indicate_netevent: call ctlr_link_down\n");
838 if (fcoe_ctlr_link_down(&hba->ctlr)) {
839 clear_bit(ADAPTER_STATE_READY, &hba->adapter_state);
840 mutex_lock(&lport->lp_mutex);
841 list_for_each_entry(vport, &lport->vports, list)
842 fc_host_port_type(vport->host) =
844 mutex_unlock(&lport->lp_mutex);
845 fc_host_port_type(lport->host) = FC_PORTTYPE_UNKNOWN;
846 per_cpu_ptr(lport->dev_stats,
847 get_cpu())->LinkFailureCount++;
849 fcoe_clean_pending_queue(lport);
851 init_waitqueue_head(&hba->shutdown_wait);
852 BNX2FC_HBA_DBG(lport, "indicate_netevent "
853 "num_ofld_sess = %d\n",
855 hba->wait_for_link_down = 1;
856 BNX2FC_HBA_DBG(lport, "waiting for uploads to "
859 wait_event_interruptible(hba->shutdown_wait,
860 (hba->num_ofld_sess == 0));
861 BNX2FC_HBA_DBG(lport, "wakeup - num_ofld_sess = %d\n",
863 hba->wait_for_link_down = 0;
865 if (signal_pending(current))
866 flush_signals(current);
871 static int bnx2fc_libfc_config(struct fc_lport *lport)
874 /* Set the function pointers set by bnx2fc driver */
875 memcpy(&lport->tt, &bnx2fc_libfc_fcn_templ,
876 sizeof(struct libfc_function_template));
877 fc_elsct_init(lport);
879 fc_rport_init(lport);
884 static int bnx2fc_em_config(struct fc_lport *lport)
886 struct fcoe_port *port = lport_priv(lport);
887 struct bnx2fc_hba *hba = port->priv;
889 if (!fc_exch_mgr_alloc(lport, FC_CLASS_3, FCOE_MIN_XID,
890 FCOE_MAX_XID, NULL)) {
891 printk(KERN_ERR PFX "em_config:fc_exch_mgr_alloc failed\n");
895 hba->cmd_mgr = bnx2fc_cmd_mgr_alloc(hba, BNX2FC_MIN_XID,
899 printk(KERN_ERR PFX "em_config:bnx2fc_cmd_mgr_alloc failed\n");
900 fc_exch_mgr_free(lport);
906 static int bnx2fc_lport_config(struct fc_lport *lport)
910 lport->max_retry_count = 3;
911 lport->max_rport_retry_count = 3;
912 lport->e_d_tov = 2 * 1000;
913 lport->r_a_tov = 10 * 1000;
915 /* REVISIT: enable when supporting tape devices
916 lport->service_params = (FCP_SPPF_INIT_FCN | FCP_SPPF_RD_XRDY_DIS |
917 FCP_SPPF_RETRY | FCP_SPPF_CONF_COMPL);
919 lport->service_params = (FCP_SPPF_INIT_FCN | FCP_SPPF_RD_XRDY_DIS);
920 lport->does_npiv = 1;
922 memset(&lport->rnid_gen, 0, sizeof(struct fc_els_rnid_gen));
923 lport->rnid_gen.rnid_atype = BNX2FC_RNID_HBA;
925 /* alloc stats structure */
926 if (fc_lport_init_stats(lport))
929 /* Finish fc_lport configuration */
930 fc_lport_config(lport);
936 * bnx2fc_fip_recv - handle a received FIP frame.
938 * @skb: the received skb
939 * @dev: associated &net_device
940 * @ptype: the &packet_type structure which was used to register this handler.
941 * @orig_dev: original receive &net_device, in case @ dev is a bond.
943 * Returns: 0 for success
945 static int bnx2fc_fip_recv(struct sk_buff *skb, struct net_device *dev,
946 struct packet_type *ptype,
947 struct net_device *orig_dev)
949 struct bnx2fc_hba *hba;
950 hba = container_of(ptype, struct bnx2fc_hba, fip_packet_type);
951 fcoe_ctlr_recv(&hba->ctlr, skb);
956 * bnx2fc_update_src_mac - Update Ethernet MAC filters.
958 * @fip: FCoE controller.
959 * @old: Unicast MAC address to delete if the MAC is non-zero.
960 * @new: Unicast MAC address to add.
962 * Remove any previously-set unicast MAC filter.
963 * Add secondary FCoE MAC address filter for our OUI.
965 static void bnx2fc_update_src_mac(struct fc_lport *lport, u8 *addr)
967 struct fcoe_port *port = lport_priv(lport);
969 memcpy(port->data_src_addr, addr, ETH_ALEN);
973 * bnx2fc_get_src_mac - return the ethernet source address for an lport
977 static u8 *bnx2fc_get_src_mac(struct fc_lport *lport)
979 struct fcoe_port *port;
981 port = (struct fcoe_port *)lport_priv(lport);
982 return port->data_src_addr;
986 * bnx2fc_fip_send - send an Ethernet-encapsulated FIP frame.
988 * @fip: FCoE controller.
991 static void bnx2fc_fip_send(struct fcoe_ctlr *fip, struct sk_buff *skb)
993 skb->dev = bnx2fc_from_ctlr(fip)->netdev;
997 static int bnx2fc_vport_create(struct fc_vport *vport, bool disabled)
999 struct Scsi_Host *shost = vport_to_shost(vport);
1000 struct fc_lport *n_port = shost_priv(shost);
1001 struct fcoe_port *port = lport_priv(n_port);
1002 struct bnx2fc_hba *hba = port->priv;
1003 struct net_device *netdev = hba->netdev;
1004 struct fc_lport *vn_port;
1006 if (!test_bit(BNX2FC_FW_INIT_DONE, &hba->init_done)) {
1007 printk(KERN_ERR PFX "vn ports cannot be created on"
1011 mutex_lock(&bnx2fc_dev_lock);
1012 vn_port = bnx2fc_if_create(hba, &vport->dev, 1);
1013 mutex_unlock(&bnx2fc_dev_lock);
1015 if (IS_ERR(vn_port)) {
1016 printk(KERN_ERR PFX "bnx2fc_vport_create (%s) failed\n",
1022 fc_vport_set_state(vport, FC_VPORT_DISABLED);
1024 vn_port->boot_time = jiffies;
1025 fc_lport_init(vn_port);
1026 fc_fabric_login(vn_port);
1027 fc_vport_setlink(vn_port);
1032 static int bnx2fc_vport_destroy(struct fc_vport *vport)
1034 struct Scsi_Host *shost = vport_to_shost(vport);
1035 struct fc_lport *n_port = shost_priv(shost);
1036 struct fc_lport *vn_port = vport->dd_data;
1037 struct fcoe_port *port = lport_priv(vn_port);
1039 mutex_lock(&n_port->lp_mutex);
1040 list_del(&vn_port->list);
1041 mutex_unlock(&n_port->lp_mutex);
1042 queue_work(bnx2fc_wq, &port->destroy_work);
1046 static int bnx2fc_vport_disable(struct fc_vport *vport, bool disable)
1048 struct fc_lport *lport = vport->dd_data;
1051 fc_vport_set_state(vport, FC_VPORT_DISABLED);
1052 fc_fabric_logoff(lport);
1054 lport->boot_time = jiffies;
1055 fc_fabric_login(lport);
1056 fc_vport_setlink(lport);
1062 static int bnx2fc_netdev_setup(struct bnx2fc_hba *hba)
1064 struct net_device *netdev = hba->netdev;
1065 struct net_device *physdev = hba->phys_dev;
1066 struct netdev_hw_addr *ha;
1067 int sel_san_mac = 0;
1069 /* setup Source MAC Address */
1071 for_each_dev_addr(physdev, ha) {
1072 BNX2FC_MISC_DBG("net_config: ha->type = %d, fip_mac = ",
1074 printk(KERN_INFO "%2x:%2x:%2x:%2x:%2x:%2x\n", ha->addr[0],
1075 ha->addr[1], ha->addr[2], ha->addr[3],
1076 ha->addr[4], ha->addr[5]);
1078 if ((ha->type == NETDEV_HW_ADDR_T_SAN) &&
1079 (is_valid_ether_addr(ha->addr))) {
1080 memcpy(hba->ctlr.ctl_src_addr, ha->addr, ETH_ALEN);
1082 BNX2FC_MISC_DBG("Found SAN MAC\n");
1090 hba->fip_packet_type.func = bnx2fc_fip_recv;
1091 hba->fip_packet_type.type = htons(ETH_P_FIP);
1092 hba->fip_packet_type.dev = netdev;
1093 dev_add_pack(&hba->fip_packet_type);
1095 hba->fcoe_packet_type.func = bnx2fc_rcv;
1096 hba->fcoe_packet_type.type = __constant_htons(ETH_P_FCOE);
1097 hba->fcoe_packet_type.dev = netdev;
1098 dev_add_pack(&hba->fcoe_packet_type);
1103 static int bnx2fc_attach_transport(void)
1105 bnx2fc_transport_template =
1106 fc_attach_transport(&bnx2fc_transport_function);
1108 if (bnx2fc_transport_template == NULL) {
1109 printk(KERN_ERR PFX "Failed to attach FC transport\n");
1113 bnx2fc_vport_xport_template =
1114 fc_attach_transport(&bnx2fc_vport_xport_function);
1115 if (bnx2fc_vport_xport_template == NULL) {
1117 "Failed to attach FC transport for vport\n");
1118 fc_release_transport(bnx2fc_transport_template);
1119 bnx2fc_transport_template = NULL;
1124 static void bnx2fc_release_transport(void)
1126 fc_release_transport(bnx2fc_transport_template);
1127 fc_release_transport(bnx2fc_vport_xport_template);
1128 bnx2fc_transport_template = NULL;
1129 bnx2fc_vport_xport_template = NULL;
1132 static void bnx2fc_interface_release(struct kref *kref)
1134 struct bnx2fc_hba *hba;
1135 struct net_device *netdev;
1136 struct net_device *phys_dev;
1138 hba = container_of(kref, struct bnx2fc_hba, kref);
1139 BNX2FC_MISC_DBG("Interface is being released\n");
1141 netdev = hba->netdev;
1142 phys_dev = hba->phys_dev;
1144 /* tear-down FIP controller */
1145 if (test_and_clear_bit(BNX2FC_CTLR_INIT_DONE, &hba->init_done))
1146 fcoe_ctlr_destroy(&hba->ctlr);
1148 /* Free the command manager */
1150 bnx2fc_cmd_mgr_free(hba->cmd_mgr);
1151 hba->cmd_mgr = NULL;
1154 module_put(THIS_MODULE);
1157 static inline void bnx2fc_interface_get(struct bnx2fc_hba *hba)
1159 kref_get(&hba->kref);
1162 static inline void bnx2fc_interface_put(struct bnx2fc_hba *hba)
1164 kref_put(&hba->kref, bnx2fc_interface_release);
1166 static void bnx2fc_interface_destroy(struct bnx2fc_hba *hba)
1168 bnx2fc_unbind_pcidev(hba);
1173 * bnx2fc_interface_create - create a new fcoe instance
1175 * @cnic: pointer to cnic device
1177 * Creates a new FCoE instance on the given device which include allocating
1178 * hba structure, scsi_host and lport structures.
1180 static struct bnx2fc_hba *bnx2fc_interface_create(struct cnic_dev *cnic)
1182 struct bnx2fc_hba *hba;
1185 hba = kzalloc(sizeof(*hba), GFP_KERNEL);
1187 printk(KERN_ERR PFX "Unable to allocate hba structure\n");
1190 spin_lock_init(&hba->hba_lock);
1191 mutex_init(&hba->hba_mutex);
1194 rc = bnx2fc_bind_pcidev(hba);
1197 hba->phys_dev = cnic->netdev;
1198 /* will get overwritten after we do vlan discovery */
1199 hba->netdev = hba->phys_dev;
1201 init_waitqueue_head(&hba->shutdown_wait);
1202 init_waitqueue_head(&hba->destroy_wait);
1206 printk(KERN_ERR PFX "create_interface: bind error\n");
1211 static int bnx2fc_interface_setup(struct bnx2fc_hba *hba,
1212 enum fip_state fip_mode)
1215 struct net_device *netdev = hba->netdev;
1216 struct fcoe_ctlr *fip = &hba->ctlr;
1219 kref_init(&hba->kref);
1223 /* Initialize FIP */
1224 memset(fip, 0, sizeof(*fip));
1225 fcoe_ctlr_init(fip, fip_mode);
1226 hba->ctlr.send = bnx2fc_fip_send;
1227 hba->ctlr.update_mac = bnx2fc_update_src_mac;
1228 hba->ctlr.get_src_addr = bnx2fc_get_src_mac;
1229 set_bit(BNX2FC_CTLR_INIT_DONE, &hba->init_done);
1231 INIT_LIST_HEAD(&hba->vports);
1232 rc = bnx2fc_netdev_setup(hba);
1236 hba->next_conn_id = 0;
1238 memset(hba->tgt_ofld_list, 0, sizeof(hba->tgt_ofld_list));
1239 hba->num_ofld_sess = 0;
1244 fcoe_ctlr_destroy(&hba->ctlr);
1246 bnx2fc_interface_put(hba);
1251 * bnx2fc_if_create - Create FCoE instance on a given interface
1253 * @hba: FCoE interface to create a local port on
1254 * @parent: Device pointer to be the parent in sysfs for the SCSI host
1255 * @npiv: Indicates if the port is vport or not
1257 * Creates a fc_lport instance and a Scsi_Host instance and configure them.
1259 * Returns: Allocated fc_lport or an error pointer
1261 static struct fc_lport *bnx2fc_if_create(struct bnx2fc_hba *hba,
1262 struct device *parent, int npiv)
1264 struct fc_lport *lport, *n_port;
1265 struct fcoe_port *port;
1266 struct Scsi_Host *shost;
1267 struct fc_vport *vport = dev_to_vport(parent);
1268 struct bnx2fc_lport *blport;
1271 blport = kzalloc(sizeof(struct bnx2fc_lport), GFP_KERNEL);
1273 BNX2FC_HBA_DBG(hba->ctlr.lp, "Unable to alloc bnx2fc_lport\n");
1277 /* Allocate Scsi_Host structure */
1279 lport = libfc_host_alloc(&bnx2fc_shost_template, sizeof(*port));
1281 lport = libfc_vport_create(vport, sizeof(*port));
1284 printk(KERN_ERR PFX "could not allocate scsi host structure\n");
1287 shost = lport->host;
1288 port = lport_priv(lport);
1289 port->lport = lport;
1291 INIT_WORK(&port->destroy_work, bnx2fc_destroy_work);
1293 /* Configure fcoe_port */
1294 rc = bnx2fc_lport_config(lport);
1299 printk(KERN_ERR PFX "Setting vport names, 0x%llX 0x%llX\n",
1300 vport->node_name, vport->port_name);
1301 fc_set_wwnn(lport, vport->node_name);
1302 fc_set_wwpn(lport, vport->port_name);
1304 /* Configure netdev and networking properties of the lport */
1305 rc = bnx2fc_net_config(lport);
1307 printk(KERN_ERR PFX "Error on bnx2fc_net_config\n");
1311 rc = bnx2fc_shost_config(lport, parent);
1313 printk(KERN_ERR PFX "Couldnt configure shost for %s\n",
1318 /* Initialize the libfc library */
1319 rc = bnx2fc_libfc_config(lport);
1321 printk(KERN_ERR PFX "Couldnt configure libfc\n");
1324 fc_host_port_type(lport->host) = FC_PORTTYPE_UNKNOWN;
1326 /* Allocate exchange manager */
1328 rc = bnx2fc_em_config(lport);
1330 shost = vport_to_shost(vport);
1331 n_port = shost_priv(shost);
1332 rc = fc_exch_mgr_list_clone(n_port, lport);
1336 printk(KERN_ERR PFX "Error on bnx2fc_em_config\n");
1340 bnx2fc_interface_get(hba);
1342 spin_lock_bh(&hba->hba_lock);
1343 blport->lport = lport;
1344 list_add_tail(&blport->list, &hba->vports);
1345 spin_unlock_bh(&hba->hba_lock);
1350 scsi_remove_host(shost);
1352 scsi_host_put(lport->host);
1358 static void bnx2fc_netdev_cleanup(struct bnx2fc_hba *hba)
1360 /* Dont listen for Ethernet packets anymore */
1361 __dev_remove_pack(&hba->fcoe_packet_type);
1362 __dev_remove_pack(&hba->fip_packet_type);
1366 static void bnx2fc_if_destroy(struct fc_lport *lport)
1368 struct fcoe_port *port = lport_priv(lport);
1369 struct bnx2fc_hba *hba = port->priv;
1370 struct bnx2fc_lport *blport, *tmp;
1372 BNX2FC_HBA_DBG(hba->ctlr.lp, "ENTERED bnx2fc_if_destroy\n");
1373 /* Stop the transmit retry timer */
1374 del_timer_sync(&port->timer);
1376 /* Free existing transmit skbs */
1377 fcoe_clean_pending_queue(lport);
1379 /* Free queued packets for the receive thread */
1380 bnx2fc_clean_rx_queue(lport);
1382 /* Detach from scsi-ml */
1383 fc_remove_host(lport->host);
1384 scsi_remove_host(lport->host);
1387 * Note that only the physical lport will have the exchange manager.
1388 * for vports, this function is NOP
1390 fc_exch_mgr_free(lport);
1392 /* Free memory used by statistical counters */
1393 fc_lport_free_stats(lport);
1395 spin_lock_bh(&hba->hba_lock);
1396 list_for_each_entry_safe(blport, tmp, &hba->vports, list) {
1397 if (blport->lport == lport) {
1398 list_del(&blport->list);
1402 spin_unlock_bh(&hba->hba_lock);
1404 /* Release Scsi_Host */
1405 scsi_host_put(lport->host);
1407 bnx2fc_interface_put(hba);
1411 * bnx2fc_destroy - Destroy a bnx2fc FCoE interface
1413 * @buffer: The name of the Ethernet interface to be destroyed
1414 * @kp: The associated kernel parameter
1416 * Called from sysfs.
1418 * Returns: 0 for success
1420 static int bnx2fc_destroy(struct net_device *netdev)
1422 struct bnx2fc_hba *hba = NULL;
1423 struct net_device *phys_dev;
1428 mutex_lock(&bnx2fc_dev_lock);
1429 /* obtain physical netdev */
1430 if (netdev->priv_flags & IFF_802_1Q_VLAN)
1431 phys_dev = vlan_dev_real_dev(netdev);
1433 printk(KERN_ERR PFX "Not a vlan device\n");
1438 hba = bnx2fc_hba_lookup(phys_dev);
1439 if (!hba || !hba->ctlr.lp) {
1441 printk(KERN_ERR PFX "bnx2fc_destroy: hba or lport not found\n");
1445 if (!test_bit(BNX2FC_CREATE_DONE, &hba->init_done)) {
1446 printk(KERN_ERR PFX "bnx2fc_destroy: Create not called\n");
1450 bnx2fc_netdev_cleanup(hba);
1454 bnx2fc_if_destroy(hba->ctlr.lp);
1456 destroy_workqueue(hba->timer_work_queue);
1458 if (test_bit(BNX2FC_FW_INIT_DONE, &hba->init_done))
1459 bnx2fc_fw_destroy(hba);
1461 clear_bit(BNX2FC_CREATE_DONE, &hba->init_done);
1463 mutex_unlock(&bnx2fc_dev_lock);
1468 static void bnx2fc_destroy_work(struct work_struct *work)
1470 struct fcoe_port *port;
1471 struct fc_lport *lport;
1473 port = container_of(work, struct fcoe_port, destroy_work);
1474 lport = port->lport;
1476 BNX2FC_HBA_DBG(lport, "Entered bnx2fc_destroy_work\n");
1478 bnx2fc_port_shutdown(lport);
1480 mutex_lock(&bnx2fc_dev_lock);
1481 bnx2fc_if_destroy(lport);
1482 mutex_unlock(&bnx2fc_dev_lock);
1486 static void bnx2fc_unbind_adapter_devices(struct bnx2fc_hba *hba)
1488 bnx2fc_free_fw_resc(hba);
1489 bnx2fc_free_task_ctx(hba);
1493 * bnx2fc_bind_adapter_devices - binds bnx2fc adapter with the associated
1496 * @hba: Adapter instance
1498 static int bnx2fc_bind_adapter_devices(struct bnx2fc_hba *hba)
1500 if (bnx2fc_setup_task_ctx(hba))
1503 if (bnx2fc_setup_fw_resc(hba))
1508 bnx2fc_unbind_adapter_devices(hba);
1512 static int bnx2fc_bind_pcidev(struct bnx2fc_hba *hba)
1514 struct cnic_dev *cnic;
1517 printk(KERN_ERR PFX "cnic is NULL\n");
1521 hba->pcidev = cnic->pcidev;
1523 pci_dev_get(hba->pcidev);
1528 static void bnx2fc_unbind_pcidev(struct bnx2fc_hba *hba)
1531 pci_dev_put(hba->pcidev);
1538 * bnx2fc_ulp_start - cnic callback to initialize & start adapter instance
1540 * @handle: transport handle pointing to adapter struture
1542 * This function maps adapter structure to pcidev structure and initiates
1543 * firmware handshake to enable/initialize on-chip FCoE components.
1544 * This bnx2fc - cnic interface api callback is used after following
1545 * conditions are met -
1546 * a) underlying network interface is up (marked by event NETDEV_UP
1548 * b) bnx2fc adatper structure is registered.
1550 static void bnx2fc_ulp_start(void *handle)
1552 struct bnx2fc_hba *hba = handle;
1553 struct fc_lport *lport = hba->ctlr.lp;
1555 BNX2FC_MISC_DBG("Entered %s\n", __func__);
1556 mutex_lock(&bnx2fc_dev_lock);
1558 if (test_bit(BNX2FC_FW_INIT_DONE, &hba->init_done))
1561 if (test_bit(BNX2FC_CREATE_DONE, &hba->init_done))
1562 bnx2fc_fw_init(hba);
1565 mutex_unlock(&bnx2fc_dev_lock);
1567 BNX2FC_MISC_DBG("bnx2fc started.\n");
1569 /* Kick off Fabric discovery*/
1570 if (test_bit(BNX2FC_CREATE_DONE, &hba->init_done)) {
1571 printk(KERN_ERR PFX "ulp_init: start discovery\n");
1572 lport->tt.frame_send = bnx2fc_xmit;
1573 bnx2fc_start_disc(hba);
1577 static void bnx2fc_port_shutdown(struct fc_lport *lport)
1579 BNX2FC_MISC_DBG("Entered %s\n", __func__);
1580 fc_fabric_logoff(lport);
1581 fc_lport_destroy(lport);
1584 static void bnx2fc_stop(struct bnx2fc_hba *hba)
1586 struct fc_lport *lport;
1587 struct fc_lport *vport;
1589 BNX2FC_MISC_DBG("ENTERED %s - init_done = %ld\n", __func__,
1591 if (test_bit(BNX2FC_FW_INIT_DONE, &hba->init_done) &&
1592 test_bit(BNX2FC_CREATE_DONE, &hba->init_done)) {
1593 lport = hba->ctlr.lp;
1594 bnx2fc_port_shutdown(lport);
1595 BNX2FC_HBA_DBG(lport, "bnx2fc_stop: waiting for %d "
1596 "offloaded sessions\n",
1597 hba->num_ofld_sess);
1598 wait_event_interruptible(hba->shutdown_wait,
1599 (hba->num_ofld_sess == 0));
1600 mutex_lock(&lport->lp_mutex);
1601 list_for_each_entry(vport, &lport->vports, list)
1602 fc_host_port_type(vport->host) = FC_PORTTYPE_UNKNOWN;
1603 mutex_unlock(&lport->lp_mutex);
1604 fc_host_port_type(lport->host) = FC_PORTTYPE_UNKNOWN;
1605 fcoe_ctlr_link_down(&hba->ctlr);
1606 fcoe_clean_pending_queue(lport);
1608 mutex_lock(&hba->hba_mutex);
1609 clear_bit(ADAPTER_STATE_UP, &hba->adapter_state);
1610 clear_bit(ADAPTER_STATE_GOING_DOWN, &hba->adapter_state);
1612 clear_bit(ADAPTER_STATE_READY, &hba->adapter_state);
1613 mutex_unlock(&hba->hba_mutex);
1617 static int bnx2fc_fw_init(struct bnx2fc_hba *hba)
1619 #define BNX2FC_INIT_POLL_TIME (1000 / HZ)
1623 rc = bnx2fc_bind_adapter_devices(hba);
1625 printk(KERN_ALERT PFX
1626 "bnx2fc_bind_adapter_devices failed - rc = %d\n", rc);
1630 rc = bnx2fc_send_fw_fcoe_init_msg(hba);
1632 printk(KERN_ALERT PFX
1633 "bnx2fc_send_fw_fcoe_init_msg failed - rc = %d\n", rc);
1638 * Wait until the adapter init message is complete, and adapter
1641 while (!test_bit(ADAPTER_STATE_UP, &hba->adapter_state) && i--)
1642 msleep(BNX2FC_INIT_POLL_TIME);
1644 if (!test_bit(ADAPTER_STATE_UP, &hba->adapter_state)) {
1645 printk(KERN_ERR PFX "bnx2fc_start: %s failed to initialize. "
1647 hba->cnic->netdev->name);
1653 /* Mark HBA to indicate that the FW INIT is done */
1654 set_bit(BNX2FC_FW_INIT_DONE, &hba->init_done);
1658 bnx2fc_unbind_adapter_devices(hba);
1663 static void bnx2fc_fw_destroy(struct bnx2fc_hba *hba)
1665 if (test_and_clear_bit(BNX2FC_FW_INIT_DONE, &hba->init_done)) {
1666 if (bnx2fc_send_fw_fcoe_destroy_msg(hba) == 0) {
1667 init_timer(&hba->destroy_timer);
1668 hba->destroy_timer.expires = BNX2FC_FW_TIMEOUT +
1670 hba->destroy_timer.function = bnx2fc_destroy_timer;
1671 hba->destroy_timer.data = (unsigned long)hba;
1672 add_timer(&hba->destroy_timer);
1673 wait_event_interruptible(hba->destroy_wait,
1675 BNX2FC_FLAG_DESTROY_CMPL));
1676 /* This should never happen */
1677 if (signal_pending(current))
1678 flush_signals(current);
1680 del_timer_sync(&hba->destroy_timer);
1682 bnx2fc_unbind_adapter_devices(hba);
1687 * bnx2fc_ulp_stop - cnic callback to shutdown adapter instance
1689 * @handle: transport handle pointing to adapter structure
1691 * Driver checks if adapter is already in shutdown mode, if not start
1692 * the shutdown process.
1694 static void bnx2fc_ulp_stop(void *handle)
1696 struct bnx2fc_hba *hba = (struct bnx2fc_hba *)handle;
1698 printk(KERN_ERR "ULP_STOP\n");
1700 mutex_lock(&bnx2fc_dev_lock);
1702 bnx2fc_fw_destroy(hba);
1703 mutex_unlock(&bnx2fc_dev_lock);
1706 static void bnx2fc_start_disc(struct bnx2fc_hba *hba)
1708 struct fc_lport *lport;
1711 BNX2FC_MISC_DBG("Entered %s\n", __func__);
1712 /* Kick off FIP/FLOGI */
1713 if (!test_bit(BNX2FC_FW_INIT_DONE, &hba->init_done)) {
1714 printk(KERN_ERR PFX "Init not done yet\n");
1718 lport = hba->ctlr.lp;
1719 BNX2FC_HBA_DBG(lport, "calling fc_fabric_login\n");
1721 if (!bnx2fc_link_ok(lport)) {
1722 BNX2FC_HBA_DBG(lport, "ctlr_link_up\n");
1723 fcoe_ctlr_link_up(&hba->ctlr);
1724 fc_host_port_type(lport->host) = FC_PORTTYPE_NPORT;
1725 set_bit(ADAPTER_STATE_READY, &hba->adapter_state);
1728 /* wait for the FCF to be selected before issuing FLOGI */
1729 while (!hba->ctlr.sel_fcf) {
1731 /* give up after 3 secs */
1732 if (++wait_cnt > 12)
1735 fc_lport_init(lport);
1736 fc_fabric_login(lport);
1741 * bnx2fc_ulp_init - Initialize an adapter instance
1743 * @dev : cnic device handle
1744 * Called from cnic_register_driver() context to initialize all
1745 * enumerated cnic devices. This routine allocates adapter structure
1746 * and other device specific resources.
1748 static void bnx2fc_ulp_init(struct cnic_dev *dev)
1750 struct bnx2fc_hba *hba;
1753 BNX2FC_MISC_DBG("Entered %s\n", __func__);
1754 /* bnx2fc works only when bnx2x is loaded */
1755 if (!test_bit(CNIC_F_BNX2X_CLASS, &dev->flags)) {
1756 printk(KERN_ERR PFX "bnx2fc FCoE not supported on %s,"
1758 dev->netdev->name, dev->flags);
1762 /* Configure FCoE interface */
1763 hba = bnx2fc_interface_create(dev);
1765 printk(KERN_ERR PFX "hba initialization failed\n");
1769 /* Add HBA to the adapter list */
1770 mutex_lock(&bnx2fc_dev_lock);
1771 list_add_tail(&hba->link, &adapter_list);
1773 mutex_unlock(&bnx2fc_dev_lock);
1775 clear_bit(BNX2FC_CNIC_REGISTERED, &hba->reg_with_cnic);
1776 rc = dev->register_device(dev, CNIC_ULP_FCOE,
1779 printk(KERN_ALERT PFX "register_device failed, rc = %d\n", rc);
1781 set_bit(BNX2FC_CNIC_REGISTERED, &hba->reg_with_cnic);
1785 static int bnx2fc_disable(struct net_device *netdev)
1787 struct bnx2fc_hba *hba;
1788 struct net_device *phys_dev;
1789 struct ethtool_drvinfo drvinfo;
1794 mutex_lock(&bnx2fc_dev_lock);
1796 /* obtain physical netdev */
1797 if (netdev->priv_flags & IFF_802_1Q_VLAN)
1798 phys_dev = vlan_dev_real_dev(netdev);
1800 printk(KERN_ERR PFX "Not a vlan device\n");
1805 /* verify if the physical device is a netxtreme2 device */
1806 if (phys_dev->ethtool_ops && phys_dev->ethtool_ops->get_drvinfo) {
1807 memset(&drvinfo, 0, sizeof(drvinfo));
1808 phys_dev->ethtool_ops->get_drvinfo(phys_dev, &drvinfo);
1809 if (strcmp(drvinfo.driver, "bnx2x")) {
1810 printk(KERN_ERR PFX "Not a netxtreme2 device\n");
1815 printk(KERN_ERR PFX "unable to obtain drv_info\n");
1820 printk(KERN_ERR PFX "phys_dev is netxtreme2 device\n");
1822 /* obtain hba and initialize rest of the structure */
1823 hba = bnx2fc_hba_lookup(phys_dev);
1824 if (!hba || !hba->ctlr.lp) {
1826 printk(KERN_ERR PFX "bnx2fc_disable: hba or lport not found\n");
1828 fcoe_ctlr_link_down(&hba->ctlr);
1829 fcoe_clean_pending_queue(hba->ctlr.lp);
1833 mutex_unlock(&bnx2fc_dev_lock);
1839 static int bnx2fc_enable(struct net_device *netdev)
1841 struct bnx2fc_hba *hba;
1842 struct net_device *phys_dev;
1843 struct ethtool_drvinfo drvinfo;
1848 BNX2FC_MISC_DBG("Entered %s\n", __func__);
1849 mutex_lock(&bnx2fc_dev_lock);
1851 /* obtain physical netdev */
1852 if (netdev->priv_flags & IFF_802_1Q_VLAN)
1853 phys_dev = vlan_dev_real_dev(netdev);
1855 printk(KERN_ERR PFX "Not a vlan device\n");
1859 /* verify if the physical device is a netxtreme2 device */
1860 if (phys_dev->ethtool_ops && phys_dev->ethtool_ops->get_drvinfo) {
1861 memset(&drvinfo, 0, sizeof(drvinfo));
1862 phys_dev->ethtool_ops->get_drvinfo(phys_dev, &drvinfo);
1863 if (strcmp(drvinfo.driver, "bnx2x")) {
1864 printk(KERN_ERR PFX "Not a netxtreme2 device\n");
1869 printk(KERN_ERR PFX "unable to obtain drv_info\n");
1874 /* obtain hba and initialize rest of the structure */
1875 hba = bnx2fc_hba_lookup(phys_dev);
1876 if (!hba || !hba->ctlr.lp) {
1878 printk(KERN_ERR PFX "bnx2fc_enable: hba or lport not found\n");
1879 } else if (!bnx2fc_link_ok(hba->ctlr.lp))
1880 fcoe_ctlr_link_up(&hba->ctlr);
1883 mutex_unlock(&bnx2fc_dev_lock);
1889 * bnx2fc_create - Create bnx2fc FCoE interface
1891 * @buffer: The name of Ethernet interface to create on
1892 * @kp: The associated kernel param
1894 * Called from sysfs.
1896 * Returns: 0 for success
1898 static int bnx2fc_create(struct net_device *netdev, enum fip_state fip_mode)
1900 struct bnx2fc_hba *hba;
1901 struct net_device *phys_dev;
1902 struct fc_lport *lport;
1903 struct ethtool_drvinfo drvinfo;
1907 BNX2FC_MISC_DBG("Entered bnx2fc_create\n");
1908 if (fip_mode != FIP_MODE_FABRIC) {
1909 printk(KERN_ERR "fip mode not FABRIC\n");
1915 mutex_lock(&bnx2fc_dev_lock);
1917 if (!try_module_get(THIS_MODULE)) {
1922 /* obtain physical netdev */
1923 if (netdev->priv_flags & IFF_802_1Q_VLAN) {
1924 phys_dev = vlan_dev_real_dev(netdev);
1925 vlan_id = vlan_dev_vlan_id(netdev);
1927 printk(KERN_ERR PFX "Not a vlan device\n");
1931 /* verify if the physical device is a netxtreme2 device */
1932 if (phys_dev->ethtool_ops && phys_dev->ethtool_ops->get_drvinfo) {
1933 memset(&drvinfo, 0, sizeof(drvinfo));
1934 phys_dev->ethtool_ops->get_drvinfo(phys_dev, &drvinfo);
1935 if (strcmp(drvinfo.driver, "bnx2x")) {
1936 printk(KERN_ERR PFX "Not a netxtreme2 device\n");
1941 printk(KERN_ERR PFX "unable to obtain drv_info\n");
1946 /* obtain hba and initialize rest of the structure */
1947 hba = bnx2fc_hba_lookup(phys_dev);
1950 printk(KERN_ERR PFX "bnx2fc_create: hba not found\n");
1954 if (!test_bit(BNX2FC_FW_INIT_DONE, &hba->init_done)) {
1955 rc = bnx2fc_fw_init(hba);
1960 if (test_bit(BNX2FC_CREATE_DONE, &hba->init_done)) {
1965 /* update netdev with vlan netdev */
1966 hba->netdev = netdev;
1967 hba->vlan_id = vlan_id;
1968 hba->vlan_enabled = 1;
1970 rc = bnx2fc_interface_setup(hba, fip_mode);
1972 printk(KERN_ERR PFX "bnx2fc_interface_setup failed\n");
1976 hba->timer_work_queue =
1977 create_singlethread_workqueue("bnx2fc_timer_wq");
1978 if (!hba->timer_work_queue) {
1979 printk(KERN_ERR PFX "ulp_init could not create timer_wq\n");
1984 lport = bnx2fc_if_create(hba, &hba->pcidev->dev, 0);
1986 printk(KERN_ERR PFX "Failed to create interface (%s)\n",
1988 bnx2fc_netdev_cleanup(hba);
1993 lport->boot_time = jiffies;
1995 /* Make this master N_port */
1996 hba->ctlr.lp = lport;
1998 set_bit(BNX2FC_CREATE_DONE, &hba->init_done);
1999 printk(KERN_ERR PFX "create: START DISC\n");
2000 bnx2fc_start_disc(hba);
2002 * Release from kref_init in bnx2fc_interface_setup, on success
2003 * lport should be holding a reference taken in bnx2fc_if_create
2005 bnx2fc_interface_put(hba);
2006 /* put netdev that was held while calling dev_get_by_name */
2007 mutex_unlock(&bnx2fc_dev_lock);
2012 destroy_workqueue(hba->timer_work_queue);
2014 bnx2fc_interface_put(hba);
2016 module_put(THIS_MODULE);
2018 mutex_unlock(&bnx2fc_dev_lock);
2024 * bnx2fc_find_hba_for_cnic - maps cnic instance to bnx2fc adapter instance
2026 * @cnic: Pointer to cnic device instance
2029 static struct bnx2fc_hba *bnx2fc_find_hba_for_cnic(struct cnic_dev *cnic)
2031 struct list_head *list;
2032 struct list_head *temp;
2033 struct bnx2fc_hba *hba;
2035 /* Called with bnx2fc_dev_lock held */
2036 list_for_each_safe(list, temp, &adapter_list) {
2037 hba = (struct bnx2fc_hba *)list;
2038 if (hba->cnic == cnic)
2044 static struct bnx2fc_hba *bnx2fc_hba_lookup(struct net_device *phys_dev)
2046 struct list_head *list;
2047 struct list_head *temp;
2048 struct bnx2fc_hba *hba;
2050 /* Called with bnx2fc_dev_lock held */
2051 list_for_each_safe(list, temp, &adapter_list) {
2052 hba = (struct bnx2fc_hba *)list;
2053 if (hba->phys_dev == phys_dev)
2056 printk(KERN_ERR PFX "hba_lookup: hba NULL\n");
2061 * bnx2fc_ulp_exit - shuts down adapter instance and frees all resources
2063 * @dev cnic device handle
2065 static void bnx2fc_ulp_exit(struct cnic_dev *dev)
2067 struct bnx2fc_hba *hba;
2069 BNX2FC_MISC_DBG("Entered bnx2fc_ulp_exit\n");
2071 if (!test_bit(CNIC_F_BNX2X_CLASS, &dev->flags)) {
2072 printk(KERN_ERR PFX "bnx2fc port check: %s, flags: %lx\n",
2073 dev->netdev->name, dev->flags);
2077 mutex_lock(&bnx2fc_dev_lock);
2078 hba = bnx2fc_find_hba_for_cnic(dev);
2080 printk(KERN_ERR PFX "bnx2fc_ulp_exit: hba not found, dev 0%p\n",
2082 mutex_unlock(&bnx2fc_dev_lock);
2086 list_del_init(&hba->link);
2089 if (test_bit(BNX2FC_CREATE_DONE, &hba->init_done)) {
2090 /* destroy not called yet, move to quiesced list */
2091 bnx2fc_netdev_cleanup(hba);
2092 bnx2fc_if_destroy(hba->ctlr.lp);
2094 mutex_unlock(&bnx2fc_dev_lock);
2096 bnx2fc_ulp_stop(hba);
2097 /* unregister cnic device */
2098 if (test_and_clear_bit(BNX2FC_CNIC_REGISTERED, &hba->reg_with_cnic))
2099 hba->cnic->unregister_device(hba->cnic, CNIC_ULP_FCOE);
2100 bnx2fc_interface_destroy(hba);
2104 * bnx2fc_fcoe_reset - Resets the fcoe
2106 * @shost: shost the reset is from
2110 static int bnx2fc_fcoe_reset(struct Scsi_Host *shost)
2112 struct fc_lport *lport = shost_priv(shost);
2113 fc_lport_reset(lport);
2118 static bool bnx2fc_match(struct net_device *netdev)
2120 mutex_lock(&bnx2fc_dev_lock);
2121 if (netdev->priv_flags & IFF_802_1Q_VLAN) {
2122 struct net_device *phys_dev = vlan_dev_real_dev(netdev);
2124 if (bnx2fc_hba_lookup(phys_dev)) {
2125 mutex_unlock(&bnx2fc_dev_lock);
2129 mutex_unlock(&bnx2fc_dev_lock);
2134 static struct fcoe_transport bnx2fc_transport = {
2137 .list = LIST_HEAD_INIT(bnx2fc_transport.list),
2138 .match = bnx2fc_match,
2139 .create = bnx2fc_create,
2140 .destroy = bnx2fc_destroy,
2141 .enable = bnx2fc_enable,
2142 .disable = bnx2fc_disable,
2146 * bnx2fc_percpu_thread_create - Create a receive thread for an
2149 * @cpu: cpu index for the online cpu
2151 static void bnx2fc_percpu_thread_create(unsigned int cpu)
2153 struct bnx2fc_percpu_s *p;
2154 struct task_struct *thread;
2156 p = &per_cpu(bnx2fc_percpu, cpu);
2158 thread = kthread_create(bnx2fc_percpu_io_thread,
2160 "bnx2fc_thread/%d", cpu);
2161 /* bind thread to the cpu */
2162 if (likely(!IS_ERR(p->iothread))) {
2163 kthread_bind(thread, cpu);
2164 p->iothread = thread;
2165 wake_up_process(thread);
2169 static void bnx2fc_percpu_thread_destroy(unsigned int cpu)
2171 struct bnx2fc_percpu_s *p;
2172 struct task_struct *thread;
2173 struct bnx2fc_work *work, *tmp;
2174 LIST_HEAD(work_list);
2176 BNX2FC_MISC_DBG("destroying io thread for CPU %d\n", cpu);
2178 /* Prevent any new work from being queued for this CPU */
2179 p = &per_cpu(bnx2fc_percpu, cpu);
2180 spin_lock_bh(&p->fp_work_lock);
2181 thread = p->iothread;
2185 /* Free all work in the list */
2186 list_for_each_entry_safe(work, tmp, &work_list, list) {
2187 list_del_init(&work->list);
2188 bnx2fc_process_cq_compl(work->tgt, work->wqe);
2192 spin_unlock_bh(&p->fp_work_lock);
2195 kthread_stop(thread);
2199 * bnx2fc_cpu_callback - Handler for CPU hotplug events
2201 * @nfb: The callback data block
2202 * @action: The event triggering the callback
2203 * @hcpu: The index of the CPU that the event is for
2205 * This creates or destroys per-CPU data for fcoe
2207 * Returns NOTIFY_OK always.
2209 static int bnx2fc_cpu_callback(struct notifier_block *nfb,
2210 unsigned long action, void *hcpu)
2212 unsigned cpu = (unsigned long)hcpu;
2216 case CPU_ONLINE_FROZEN:
2217 printk(PFX "CPU %x online: Create Rx thread\n", cpu);
2218 bnx2fc_percpu_thread_create(cpu);
2221 case CPU_DEAD_FROZEN:
2222 printk(PFX "CPU %x offline: Remove Rx thread\n", cpu);
2223 bnx2fc_percpu_thread_destroy(cpu);
2232 * bnx2fc_mod_init - module init entry point
2234 * Initialize driver wide global data structures, and register
2237 static int __init bnx2fc_mod_init(void)
2239 struct fcoe_percpu_s *bg;
2240 struct task_struct *l2_thread;
2242 unsigned int cpu = 0;
2243 struct bnx2fc_percpu_s *p;
2245 printk(KERN_INFO PFX "%s", version);
2247 /* register as a fcoe transport */
2248 rc = fcoe_transport_attach(&bnx2fc_transport);
2250 printk(KERN_ERR "failed to register an fcoe transport, check "
2251 "if libfcoe is loaded\n");
2255 INIT_LIST_HEAD(&adapter_list);
2256 mutex_init(&bnx2fc_dev_lock);
2259 /* Attach FC transport template */
2260 rc = bnx2fc_attach_transport();
2264 bnx2fc_wq = alloc_workqueue("bnx2fc", 0, 0);
2270 bg = &bnx2fc_global;
2271 skb_queue_head_init(&bg->fcoe_rx_list);
2272 l2_thread = kthread_create(bnx2fc_l2_rcv_thread,
2274 "bnx2fc_l2_thread");
2275 if (IS_ERR(l2_thread)) {
2276 rc = PTR_ERR(l2_thread);
2279 wake_up_process(l2_thread);
2280 spin_lock_bh(&bg->fcoe_rx_list.lock);
2281 bg->thread = l2_thread;
2282 spin_unlock_bh(&bg->fcoe_rx_list.lock);
2284 for_each_possible_cpu(cpu) {
2285 p = &per_cpu(bnx2fc_percpu, cpu);
2286 INIT_LIST_HEAD(&p->work_list);
2287 spin_lock_init(&p->fp_work_lock);
2290 for_each_online_cpu(cpu) {
2291 bnx2fc_percpu_thread_create(cpu);
2294 /* Initialize per CPU interrupt thread */
2295 register_hotcpu_notifier(&bnx2fc_cpu_notifier);
2297 cnic_register_driver(CNIC_ULP_FCOE, &bnx2fc_cnic_cb);
2302 destroy_workqueue(bnx2fc_wq);
2304 bnx2fc_release_transport();
2306 fcoe_transport_detach(&bnx2fc_transport);
2311 static void __exit bnx2fc_mod_exit(void)
2313 LIST_HEAD(to_be_deleted);
2314 struct bnx2fc_hba *hba, *next;
2315 struct fcoe_percpu_s *bg;
2316 struct task_struct *l2_thread;
2317 struct sk_buff *skb;
2318 unsigned int cpu = 0;
2321 * NOTE: Since cnic calls register_driver routine rtnl_lock,
2322 * it will have higher precedence than bnx2fc_dev_lock.
2323 * unregister_device() cannot be called with bnx2fc_dev_lock
2326 mutex_lock(&bnx2fc_dev_lock);
2327 list_splice(&adapter_list, &to_be_deleted);
2328 INIT_LIST_HEAD(&adapter_list);
2330 mutex_unlock(&bnx2fc_dev_lock);
2332 /* Unregister with cnic */
2333 list_for_each_entry_safe(hba, next, &to_be_deleted, link) {
2334 list_del_init(&hba->link);
2335 printk(KERN_ERR PFX "MOD_EXIT:destroy hba = 0x%p, kref = %d\n",
2336 hba, atomic_read(&hba->kref.refcount));
2337 bnx2fc_ulp_stop(hba);
2338 /* unregister cnic device */
2339 if (test_and_clear_bit(BNX2FC_CNIC_REGISTERED,
2340 &hba->reg_with_cnic))
2341 hba->cnic->unregister_device(hba->cnic, CNIC_ULP_FCOE);
2342 bnx2fc_interface_destroy(hba);
2344 cnic_unregister_driver(CNIC_ULP_FCOE);
2346 /* Destroy global thread */
2347 bg = &bnx2fc_global;
2348 spin_lock_bh(&bg->fcoe_rx_list.lock);
2349 l2_thread = bg->thread;
2351 while ((skb = __skb_dequeue(&bg->fcoe_rx_list)) != NULL)
2354 spin_unlock_bh(&bg->fcoe_rx_list.lock);
2357 kthread_stop(l2_thread);
2359 unregister_hotcpu_notifier(&bnx2fc_cpu_notifier);
2361 /* Destroy per cpu threads */
2362 for_each_online_cpu(cpu) {
2363 bnx2fc_percpu_thread_destroy(cpu);
2366 destroy_workqueue(bnx2fc_wq);
2368 * detach from scsi transport
2369 * must happen after all destroys are done
2371 bnx2fc_release_transport();
2373 /* detach from fcoe transport */
2374 fcoe_transport_detach(&bnx2fc_transport);
2377 module_init(bnx2fc_mod_init);
2378 module_exit(bnx2fc_mod_exit);
2380 static struct fc_function_template bnx2fc_transport_function = {
2381 .show_host_node_name = 1,
2382 .show_host_port_name = 1,
2383 .show_host_supported_classes = 1,
2384 .show_host_supported_fc4s = 1,
2385 .show_host_active_fc4s = 1,
2386 .show_host_maxframe_size = 1,
2388 .show_host_port_id = 1,
2389 .show_host_supported_speeds = 1,
2390 .get_host_speed = fc_get_host_speed,
2391 .show_host_speed = 1,
2392 .show_host_port_type = 1,
2393 .get_host_port_state = fc_get_host_port_state,
2394 .show_host_port_state = 1,
2395 .show_host_symbolic_name = 1,
2397 .dd_fcrport_size = (sizeof(struct fc_rport_libfc_priv) +
2398 sizeof(struct bnx2fc_rport)),
2399 .show_rport_maxframe_size = 1,
2400 .show_rport_supported_classes = 1,
2402 .show_host_fabric_name = 1,
2403 .show_starget_node_name = 1,
2404 .show_starget_port_name = 1,
2405 .show_starget_port_id = 1,
2406 .set_rport_dev_loss_tmo = fc_set_rport_loss_tmo,
2407 .show_rport_dev_loss_tmo = 1,
2408 .get_fc_host_stats = bnx2fc_get_host_stats,
2410 .issue_fc_host_lip = bnx2fc_fcoe_reset,
2412 .terminate_rport_io = fc_rport_terminate_io,
2414 .vport_create = bnx2fc_vport_create,
2415 .vport_delete = bnx2fc_vport_destroy,
2416 .vport_disable = bnx2fc_vport_disable,
2419 static struct fc_function_template bnx2fc_vport_xport_function = {
2420 .show_host_node_name = 1,
2421 .show_host_port_name = 1,
2422 .show_host_supported_classes = 1,
2423 .show_host_supported_fc4s = 1,
2424 .show_host_active_fc4s = 1,
2425 .show_host_maxframe_size = 1,
2427 .show_host_port_id = 1,
2428 .show_host_supported_speeds = 1,
2429 .get_host_speed = fc_get_host_speed,
2430 .show_host_speed = 1,
2431 .show_host_port_type = 1,
2432 .get_host_port_state = fc_get_host_port_state,
2433 .show_host_port_state = 1,
2434 .show_host_symbolic_name = 1,
2436 .dd_fcrport_size = (sizeof(struct fc_rport_libfc_priv) +
2437 sizeof(struct bnx2fc_rport)),
2438 .show_rport_maxframe_size = 1,
2439 .show_rport_supported_classes = 1,
2441 .show_host_fabric_name = 1,
2442 .show_starget_node_name = 1,
2443 .show_starget_port_name = 1,
2444 .show_starget_port_id = 1,
2445 .set_rport_dev_loss_tmo = fc_set_rport_loss_tmo,
2446 .show_rport_dev_loss_tmo = 1,
2447 .get_fc_host_stats = fc_get_host_stats,
2448 .issue_fc_host_lip = bnx2fc_fcoe_reset,
2449 .terminate_rport_io = fc_rport_terminate_io,
2453 * scsi_host_template structure used while registering with SCSI-ml
2455 static struct scsi_host_template bnx2fc_shost_template = {
2456 .module = THIS_MODULE,
2457 .name = "Broadcom Offload FCoE Initiator",
2458 .queuecommand = bnx2fc_queuecommand,
2459 .eh_abort_handler = bnx2fc_eh_abort, /* abts */
2460 .eh_device_reset_handler = bnx2fc_eh_device_reset, /* lun reset */
2461 .eh_target_reset_handler = bnx2fc_eh_target_reset, /* tgt reset */
2462 .eh_host_reset_handler = fc_eh_host_reset,
2463 .slave_alloc = fc_slave_alloc,
2464 .change_queue_depth = fc_change_queue_depth,
2465 .change_queue_type = fc_change_queue_type,
2468 .can_queue = BNX2FC_CAN_QUEUE,
2469 .use_clustering = ENABLE_CLUSTERING,
2470 .sg_tablesize = BNX2FC_MAX_BDS_PER_CMD,
2474 static struct libfc_function_template bnx2fc_libfc_fcn_templ = {
2475 .frame_send = bnx2fc_xmit,
2476 .elsct_send = bnx2fc_elsct_send,
2477 .fcp_abort_io = bnx2fc_abort_io,
2478 .fcp_cleanup = bnx2fc_cleanup,
2479 .rport_event_callback = bnx2fc_rport_event_handler,
2483 * bnx2fc_cnic_cb - global template of bnx2fc - cnic driver interface
2484 * structure carrying callback function pointers
2486 static struct cnic_ulp_ops bnx2fc_cnic_cb = {
2487 .owner = THIS_MODULE,
2488 .cnic_init = bnx2fc_ulp_init,
2489 .cnic_exit = bnx2fc_ulp_exit,
2490 .cnic_start = bnx2fc_ulp_start,
2491 .cnic_stop = bnx2fc_ulp_stop,
2492 .indicate_kcqes = bnx2fc_indicate_kcqe,
2493 .indicate_netevent = bnx2fc_indicate_netevent,