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 - 2011 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 struct list_head if_list
;
19 static u32 adapter_count
;
20 static DEFINE_MUTEX(bnx2fc_dev_lock
);
21 DEFINE_PER_CPU(struct bnx2fc_percpu_s
, bnx2fc_percpu
);
23 #define DRV_MODULE_NAME "bnx2fc"
24 #define DRV_MODULE_VERSION BNX2FC_VERSION
25 #define DRV_MODULE_RELDATE "Apr 24, 2012"
28 static char version
[] __devinitdata
=
29 "Broadcom NetXtreme II FCoE Driver " DRV_MODULE_NAME \
30 " v" DRV_MODULE_VERSION
" (" DRV_MODULE_RELDATE
")\n";
33 MODULE_AUTHOR("Bhanu Prakash Gollapudi <bprakash@broadcom.com>");
34 MODULE_DESCRIPTION("Broadcom NetXtreme II BCM57710 FCoE Driver");
35 MODULE_LICENSE("GPL");
36 MODULE_VERSION(DRV_MODULE_VERSION
);
38 #define BNX2FC_MAX_QUEUE_DEPTH 256
39 #define BNX2FC_MIN_QUEUE_DEPTH 32
40 #define FCOE_WORD_TO_BYTE 4
42 static struct scsi_transport_template
*bnx2fc_transport_template
;
43 static struct scsi_transport_template
*bnx2fc_vport_xport_template
;
45 struct workqueue_struct
*bnx2fc_wq
;
47 /* bnx2fc structure needs only one instance of the fcoe_percpu_s structure.
48 * Here the io threads are per cpu but the l2 thread is just one
50 struct fcoe_percpu_s bnx2fc_global
;
51 DEFINE_SPINLOCK(bnx2fc_global_lock
);
53 static struct cnic_ulp_ops bnx2fc_cnic_cb
;
54 static struct libfc_function_template bnx2fc_libfc_fcn_templ
;
55 static struct scsi_host_template bnx2fc_shost_template
;
56 static struct fc_function_template bnx2fc_transport_function
;
57 static struct fcoe_sysfs_function_template bnx2fc_fcoe_sysfs_templ
;
58 static struct fc_function_template bnx2fc_vport_xport_function
;
59 static int bnx2fc_create(struct net_device
*netdev
, enum fip_state fip_mode
);
60 static void __bnx2fc_destroy(struct bnx2fc_interface
*interface
);
61 static int bnx2fc_destroy(struct net_device
*net_device
);
62 static int bnx2fc_enable(struct net_device
*netdev
);
63 static int bnx2fc_disable(struct net_device
*netdev
);
65 static void bnx2fc_recv_frame(struct sk_buff
*skb
);
67 static void bnx2fc_start_disc(struct bnx2fc_interface
*interface
);
68 static int bnx2fc_shost_config(struct fc_lport
*lport
, struct device
*dev
);
69 static int bnx2fc_lport_config(struct fc_lport
*lport
);
70 static int bnx2fc_em_config(struct fc_lport
*lport
);
71 static int bnx2fc_bind_adapter_devices(struct bnx2fc_hba
*hba
);
72 static void bnx2fc_unbind_adapter_devices(struct bnx2fc_hba
*hba
);
73 static int bnx2fc_bind_pcidev(struct bnx2fc_hba
*hba
);
74 static void bnx2fc_unbind_pcidev(struct bnx2fc_hba
*hba
);
75 static struct fc_lport
*bnx2fc_if_create(struct bnx2fc_interface
*interface
,
76 struct device
*parent
, int npiv
);
77 static void bnx2fc_destroy_work(struct work_struct
*work
);
79 static struct bnx2fc_hba
*bnx2fc_hba_lookup(struct net_device
*phys_dev
);
80 static struct bnx2fc_interface
*bnx2fc_interface_lookup(struct net_device
82 static inline void bnx2fc_interface_put(struct bnx2fc_interface
*interface
);
83 static struct bnx2fc_hba
*bnx2fc_find_hba_for_cnic(struct cnic_dev
*cnic
);
85 static int bnx2fc_fw_init(struct bnx2fc_hba
*hba
);
86 static void bnx2fc_fw_destroy(struct bnx2fc_hba
*hba
);
88 static void bnx2fc_port_shutdown(struct fc_lport
*lport
);
89 static void bnx2fc_stop(struct bnx2fc_interface
*interface
);
90 static int __init
bnx2fc_mod_init(void);
91 static void __exit
bnx2fc_mod_exit(void);
92 static void bnx2fc_ctlr_get_lesb(struct fcoe_ctlr_device
*ctlr_dev
);
94 unsigned int bnx2fc_debug_level
;
95 module_param_named(debug_logging
, bnx2fc_debug_level
, int, S_IRUGO
|S_IWUSR
);
97 static int bnx2fc_cpu_callback(struct notifier_block
*nfb
,
98 unsigned long action
, void *hcpu
);
99 /* notification function for CPU hotplug events */
100 static struct notifier_block bnx2fc_cpu_notifier
= {
101 .notifier_call
= bnx2fc_cpu_callback
,
104 static inline struct net_device
*bnx2fc_netdev(const struct fc_lport
*lport
)
106 return ((struct bnx2fc_interface
*)
107 ((struct fcoe_port
*)lport_priv(lport
))->priv
)->netdev
;
111 * bnx2fc_get_lesb() - Fill the FCoE Link Error Status Block
112 * @lport: the local port
113 * @fc_lesb: the link error status block
115 static void bnx2fc_get_lesb(struct fc_lport
*lport
,
116 struct fc_els_lesb
*fc_lesb
)
118 struct net_device
*netdev
= bnx2fc_netdev(lport
);
120 __fcoe_get_lesb(lport
, fc_lesb
, netdev
);
123 static void bnx2fc_ctlr_get_lesb(struct fcoe_ctlr_device
*ctlr_dev
)
125 struct fcoe_ctlr
*fip
= fcoe_ctlr_device_priv(ctlr_dev
);
126 struct net_device
*netdev
= bnx2fc_netdev(fip
->lp
);
127 struct fcoe_fc_els_lesb
*fcoe_lesb
;
128 struct fc_els_lesb fc_lesb
;
130 __fcoe_get_lesb(fip
->lp
, &fc_lesb
, netdev
);
131 fcoe_lesb
= (struct fcoe_fc_els_lesb
*)(&fc_lesb
);
133 ctlr_dev
->lesb
.lesb_link_fail
=
134 ntohl(fcoe_lesb
->lesb_link_fail
);
135 ctlr_dev
->lesb
.lesb_vlink_fail
=
136 ntohl(fcoe_lesb
->lesb_vlink_fail
);
137 ctlr_dev
->lesb
.lesb_miss_fka
=
138 ntohl(fcoe_lesb
->lesb_miss_fka
);
139 ctlr_dev
->lesb
.lesb_symb_err
=
140 ntohl(fcoe_lesb
->lesb_symb_err
);
141 ctlr_dev
->lesb
.lesb_err_block
=
142 ntohl(fcoe_lesb
->lesb_err_block
);
143 ctlr_dev
->lesb
.lesb_fcs_error
=
144 ntohl(fcoe_lesb
->lesb_fcs_error
);
146 EXPORT_SYMBOL(bnx2fc_ctlr_get_lesb
);
148 static void bnx2fc_fcf_get_vlan_id(struct fcoe_fcf_device
*fcf_dev
)
150 struct fcoe_ctlr_device
*ctlr_dev
=
151 fcoe_fcf_dev_to_ctlr_dev(fcf_dev
);
152 struct fcoe_ctlr
*ctlr
= fcoe_ctlr_device_priv(ctlr_dev
);
153 struct bnx2fc_interface
*fcoe
= fcoe_ctlr_priv(ctlr
);
155 fcf_dev
->vlan_id
= fcoe
->vlan_id
;
158 static void bnx2fc_clean_rx_queue(struct fc_lport
*lp
)
160 struct fcoe_percpu_s
*bg
;
161 struct fcoe_rcv_info
*fr
;
162 struct sk_buff_head
*list
;
163 struct sk_buff
*skb
, *next
;
164 struct sk_buff
*head
;
167 spin_lock_bh(&bg
->fcoe_rx_list
.lock
);
168 list
= &bg
->fcoe_rx_list
;
170 for (skb
= head
; skb
!= (struct sk_buff
*)list
;
173 fr
= fcoe_dev_from_skb(skb
);
174 if (fr
->fr_dev
== lp
) {
175 __skb_unlink(skb
, list
);
179 spin_unlock_bh(&bg
->fcoe_rx_list
.lock
);
182 int bnx2fc_get_paged_crc_eof(struct sk_buff
*skb
, int tlen
)
185 spin_lock(&bnx2fc_global_lock
);
186 rc
= fcoe_get_paged_crc_eof(skb
, tlen
, &bnx2fc_global
);
187 spin_unlock(&bnx2fc_global_lock
);
192 static void bnx2fc_abort_io(struct fc_lport
*lport
)
195 * This function is no-op for bnx2fc, but we do
196 * not want to leave it as NULL either, as libfc
197 * can call the default function which is
202 static void bnx2fc_cleanup(struct fc_lport
*lport
)
204 struct fcoe_port
*port
= lport_priv(lport
);
205 struct bnx2fc_interface
*interface
= port
->priv
;
206 struct bnx2fc_hba
*hba
= interface
->hba
;
207 struct bnx2fc_rport
*tgt
;
210 BNX2FC_MISC_DBG("Entered %s\n", __func__
);
211 mutex_lock(&hba
->hba_mutex
);
212 spin_lock_bh(&hba
->hba_lock
);
213 for (i
= 0; i
< BNX2FC_NUM_MAX_SESS
; i
++) {
214 tgt
= hba
->tgt_ofld_list
[i
];
216 /* Cleanup IOs belonging to requested vport */
217 if (tgt
->port
== port
) {
218 spin_unlock_bh(&hba
->hba_lock
);
219 BNX2FC_TGT_DBG(tgt
, "flush/cleanup\n");
220 bnx2fc_flush_active_ios(tgt
);
221 spin_lock_bh(&hba
->hba_lock
);
225 spin_unlock_bh(&hba
->hba_lock
);
226 mutex_unlock(&hba
->hba_mutex
);
229 static int bnx2fc_xmit_l2_frame(struct bnx2fc_rport
*tgt
,
232 struct fc_rport_priv
*rdata
= tgt
->rdata
;
233 struct fc_frame_header
*fh
;
236 fh
= fc_frame_header_get(fp
);
237 BNX2FC_TGT_DBG(tgt
, "Xmit L2 frame rport = 0x%x, oxid = 0x%x, "
238 "r_ctl = 0x%x\n", rdata
->ids
.port_id
,
239 ntohs(fh
->fh_ox_id
), fh
->fh_r_ctl
);
240 if ((fh
->fh_type
== FC_TYPE_ELS
) &&
241 (fh
->fh_r_ctl
== FC_RCTL_ELS_REQ
)) {
243 switch (fc_frame_payload_op(fp
)) {
245 rc
= bnx2fc_send_adisc(tgt
, fp
);
248 rc
= bnx2fc_send_logo(tgt
, fp
);
251 rc
= bnx2fc_send_rls(tgt
, fp
);
256 } else if ((fh
->fh_type
== FC_TYPE_BLS
) &&
257 (fh
->fh_r_ctl
== FC_RCTL_BA_ABTS
))
258 BNX2FC_TGT_DBG(tgt
, "ABTS frame\n");
260 BNX2FC_TGT_DBG(tgt
, "Send L2 frame type 0x%x "
261 "rctl 0x%x thru non-offload path\n",
262 fh
->fh_type
, fh
->fh_r_ctl
);
272 * bnx2fc_xmit - bnx2fc's FCoE frame transmit function
274 * @lport: the associated local port
275 * @fp: the fc_frame to be transmitted
277 static int bnx2fc_xmit(struct fc_lport
*lport
, struct fc_frame
*fp
)
280 struct fcoe_crc_eof
*cp
;
282 struct fc_frame_header
*fh
;
283 struct bnx2fc_interface
*interface
;
284 struct fcoe_ctlr
*ctlr
;
285 struct bnx2fc_hba
*hba
;
286 struct fcoe_port
*port
;
288 struct bnx2fc_rport
*tgt
;
289 struct fcoe_dev_stats
*stats
;
292 unsigned int hlen
, tlen
, elen
;
295 port
= (struct fcoe_port
*)lport_priv(lport
);
296 interface
= port
->priv
;
297 ctlr
= bnx2fc_to_ctlr(interface
);
298 hba
= interface
->hba
;
300 fh
= fc_frame_header_get(fp
);
303 if (!lport
->link_up
) {
304 BNX2FC_HBA_DBG(lport
, "bnx2fc_xmit link down\n");
309 if (unlikely(fh
->fh_r_ctl
== FC_RCTL_ELS_REQ
)) {
310 if (!ctlr
->sel_fcf
) {
311 BNX2FC_HBA_DBG(lport
, "FCF not selected yet!\n");
315 if (fcoe_ctlr_els_send(ctlr
, lport
, skb
))
323 * Snoop the frame header to check if the frame is for
324 * an offloaded session
327 * tgt_ofld_list access is synchronized using
328 * both hba mutex and hba lock. Atleast hba mutex or
329 * hba lock needs to be held for read access.
332 spin_lock_bh(&hba
->hba_lock
);
333 tgt
= bnx2fc_tgt_lookup(port
, ntoh24(fh
->fh_d_id
));
334 if (tgt
&& (test_bit(BNX2FC_FLAG_SESSION_READY
, &tgt
->flags
))) {
335 /* This frame is for offloaded session */
336 BNX2FC_HBA_DBG(lport
, "xmit: Frame is for offloaded session "
337 "port_id = 0x%x\n", ntoh24(fh
->fh_d_id
));
338 spin_unlock_bh(&hba
->hba_lock
);
339 rc
= bnx2fc_xmit_l2_frame(tgt
, fp
);
345 spin_unlock_bh(&hba
->hba_lock
);
348 elen
= sizeof(struct ethhdr
);
349 hlen
= sizeof(struct fcoe_hdr
);
350 tlen
= sizeof(struct fcoe_crc_eof
);
351 wlen
= (skb
->len
- tlen
+ sizeof(crc
)) / FCOE_WORD_TO_BYTE
;
353 skb
->ip_summed
= CHECKSUM_NONE
;
354 crc
= fcoe_fc_crc(fp
);
356 /* copy port crc and eof to the skb buff */
357 if (skb_is_nonlinear(skb
)) {
359 if (bnx2fc_get_paged_crc_eof(skb
, tlen
)) {
363 frag
= &skb_shinfo(skb
)->frags
[skb_shinfo(skb
)->nr_frags
- 1];
364 cp
= kmap_atomic(skb_frag_page(frag
)) + frag
->page_offset
;
366 cp
= (struct fcoe_crc_eof
*)skb_put(skb
, tlen
);
369 memset(cp
, 0, sizeof(*cp
));
371 cp
->fcoe_crc32
= cpu_to_le32(~crc
);
372 if (skb_is_nonlinear(skb
)) {
377 /* adjust skb network/transport offsets to match mac/fcoe/port */
378 skb_push(skb
, elen
+ hlen
);
379 skb_reset_mac_header(skb
);
380 skb_reset_network_header(skb
);
382 skb
->protocol
= htons(ETH_P_FCOE
);
383 skb
->dev
= interface
->netdev
;
385 /* fill up mac and fcoe headers */
387 eh
->h_proto
= htons(ETH_P_FCOE
);
389 fc_fcoe_set_mac(eh
->h_dest
, fh
->fh_d_id
);
391 /* insert GW address */
392 memcpy(eh
->h_dest
, ctlr
->dest_addr
, ETH_ALEN
);
394 if (unlikely(ctlr
->flogi_oxid
!= FC_XID_UNKNOWN
))
395 memcpy(eh
->h_source
, ctlr
->ctl_src_addr
, ETH_ALEN
);
397 memcpy(eh
->h_source
, port
->data_src_addr
, ETH_ALEN
);
399 hp
= (struct fcoe_hdr
*)(eh
+ 1);
400 memset(hp
, 0, sizeof(*hp
));
402 FC_FCOE_ENCAPS_VER(hp
, FC_FCOE_VER
);
405 /* fcoe lso, mss is in max_payload which is non-zero for FCP data */
406 if (lport
->seq_offload
&& fr_max_payload(fp
)) {
407 skb_shinfo(skb
)->gso_type
= SKB_GSO_FCOE
;
408 skb_shinfo(skb
)->gso_size
= fr_max_payload(fp
);
410 skb_shinfo(skb
)->gso_type
= 0;
411 skb_shinfo(skb
)->gso_size
= 0;
415 stats
= per_cpu_ptr(lport
->dev_stats
, get_cpu());
417 stats
->TxWords
+= wlen
;
420 /* send down to lld */
422 if (port
->fcoe_pending_queue
.qlen
)
423 fcoe_check_wait_queue(lport
, skb
);
424 else if (fcoe_start_io(skb
))
425 fcoe_check_wait_queue(lport
, skb
);
431 * bnx2fc_rcv - This is bnx2fc's receive function called by NET_RX_SOFTIRQ
433 * @skb: the receive socket buffer
434 * @dev: associated net device
436 * @olddev: last device
438 * This function receives the packet and builds FC frame and passes it up
440 static int bnx2fc_rcv(struct sk_buff
*skb
, struct net_device
*dev
,
441 struct packet_type
*ptype
, struct net_device
*olddev
)
443 struct fc_lport
*lport
;
444 struct bnx2fc_interface
*interface
;
445 struct fcoe_ctlr
*ctlr
;
446 struct fc_frame_header
*fh
;
447 struct fcoe_rcv_info
*fr
;
448 struct fcoe_percpu_s
*bg
;
451 interface
= container_of(ptype
, struct bnx2fc_interface
,
453 ctlr
= bnx2fc_to_ctlr(interface
);
456 if (unlikely(lport
== NULL
)) {
457 printk(KERN_ERR PFX
"bnx2fc_rcv: lport is NULL\n");
461 if (unlikely(eth_hdr(skb
)->h_proto
!= htons(ETH_P_FCOE
))) {
462 printk(KERN_ERR PFX
"bnx2fc_rcv: Wrong FC type frame\n");
467 * Check for minimum frame length, and make sure required FCoE
468 * and FC headers are pulled into the linear data area.
470 if (unlikely((skb
->len
< FCOE_MIN_FRAME
) ||
471 !pskb_may_pull(skb
, FCOE_HEADER_LEN
)))
474 skb_set_transport_header(skb
, sizeof(struct fcoe_hdr
));
475 fh
= (struct fc_frame_header
*) skb_transport_header(skb
);
477 oxid
= ntohs(fh
->fh_ox_id
);
479 fr
= fcoe_dev_from_skb(skb
);
483 spin_lock(&bg
->fcoe_rx_list
.lock
);
485 __skb_queue_tail(&bg
->fcoe_rx_list
, skb
);
486 if (bg
->fcoe_rx_list
.qlen
== 1)
487 wake_up_process(bg
->thread
);
489 spin_unlock(&bg
->fcoe_rx_list
.lock
);
497 static int bnx2fc_l2_rcv_thread(void *arg
)
499 struct fcoe_percpu_s
*bg
= arg
;
502 set_user_nice(current
, -20);
503 set_current_state(TASK_INTERRUPTIBLE
);
504 while (!kthread_should_stop()) {
506 spin_lock_bh(&bg
->fcoe_rx_list
.lock
);
507 while ((skb
= __skb_dequeue(&bg
->fcoe_rx_list
)) != NULL
) {
508 spin_unlock_bh(&bg
->fcoe_rx_list
.lock
);
509 bnx2fc_recv_frame(skb
);
510 spin_lock_bh(&bg
->fcoe_rx_list
.lock
);
512 __set_current_state(TASK_INTERRUPTIBLE
);
513 spin_unlock_bh(&bg
->fcoe_rx_list
.lock
);
515 __set_current_state(TASK_RUNNING
);
520 static void bnx2fc_recv_frame(struct sk_buff
*skb
)
523 struct fc_lport
*lport
;
524 struct fcoe_rcv_info
*fr
;
525 struct fcoe_dev_stats
*stats
;
526 struct fc_frame_header
*fh
;
527 struct fcoe_crc_eof crc_eof
;
529 struct fc_lport
*vn_port
;
530 struct fcoe_port
*port
;
535 fr
= fcoe_dev_from_skb(skb
);
537 if (unlikely(lport
== NULL
)) {
538 printk(KERN_ERR PFX
"Invalid lport struct\n");
543 if (skb_is_nonlinear(skb
))
545 mac
= eth_hdr(skb
)->h_source
;
546 dest_mac
= eth_hdr(skb
)->h_dest
;
548 /* Pull the header */
549 hp
= (struct fcoe_hdr
*) skb_network_header(skb
);
550 fh
= (struct fc_frame_header
*) skb_transport_header(skb
);
551 skb_pull(skb
, sizeof(struct fcoe_hdr
));
552 fr_len
= skb
->len
- sizeof(struct fcoe_crc_eof
);
554 stats
= per_cpu_ptr(lport
->dev_stats
, get_cpu());
556 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
))) {
567 fr_eof(fp
) = crc_eof
.fcoe_eof
;
568 fr_crc(fp
) = crc_eof
.fcoe_crc32
;
569 if (pskb_trim(skb
, fr_len
)) {
575 fh
= fc_frame_header_get(fp
);
577 vn_port
= fc_vport_id_lookup(lport
, ntoh24(fh
->fh_d_id
));
579 port
= lport_priv(vn_port
);
580 if (compare_ether_addr(port
->data_src_addr
, dest_mac
)
582 BNX2FC_HBA_DBG(lport
, "fpma mismatch\n");
588 if (fh
->fh_r_ctl
== FC_RCTL_DD_SOL_DATA
&&
589 fh
->fh_type
== FC_TYPE_FCP
) {
590 /* Drop FCP data. We dont this in L2 path */
595 if (fh
->fh_r_ctl
== FC_RCTL_ELS_REQ
&&
596 fh
->fh_type
== FC_TYPE_ELS
) {
597 switch (fc_frame_payload_op(fp
)) {
599 if (ntoh24(fh
->fh_s_id
) == FC_FID_FLOGI
) {
600 /* drop non-FIP LOGO */
609 if (fh
->fh_r_ctl
== FC_RCTL_BA_ABTS
) {
610 /* Drop incoming ABTS */
616 if (le32_to_cpu(fr_crc(fp
)) !=
617 ~crc32(~0, skb
->data
, fr_len
)) {
618 if (stats
->InvalidCRCCount
< 5)
619 printk(KERN_WARNING PFX
"dropping frame with "
621 stats
->InvalidCRCCount
++;
627 fc_exch_recv(lport
, fp
);
631 * bnx2fc_percpu_io_thread - thread per cpu for ios
633 * @arg: ptr to bnx2fc_percpu_info structure
635 int bnx2fc_percpu_io_thread(void *arg
)
637 struct bnx2fc_percpu_s
*p
= arg
;
638 struct bnx2fc_work
*work
, *tmp
;
639 LIST_HEAD(work_list
);
641 set_user_nice(current
, -20);
642 set_current_state(TASK_INTERRUPTIBLE
);
643 while (!kthread_should_stop()) {
645 spin_lock_bh(&p
->fp_work_lock
);
646 while (!list_empty(&p
->work_list
)) {
647 list_splice_init(&p
->work_list
, &work_list
);
648 spin_unlock_bh(&p
->fp_work_lock
);
650 list_for_each_entry_safe(work
, tmp
, &work_list
, list
) {
651 list_del_init(&work
->list
);
652 bnx2fc_process_cq_compl(work
->tgt
, work
->wqe
);
656 spin_lock_bh(&p
->fp_work_lock
);
658 __set_current_state(TASK_INTERRUPTIBLE
);
659 spin_unlock_bh(&p
->fp_work_lock
);
661 __set_current_state(TASK_RUNNING
);
666 static struct fc_host_statistics
*bnx2fc_get_host_stats(struct Scsi_Host
*shost
)
668 struct fc_host_statistics
*bnx2fc_stats
;
669 struct fc_lport
*lport
= shost_priv(shost
);
670 struct fcoe_port
*port
= lport_priv(lport
);
671 struct bnx2fc_interface
*interface
= port
->priv
;
672 struct bnx2fc_hba
*hba
= interface
->hba
;
673 struct fcoe_statistics_params
*fw_stats
;
676 fw_stats
= (struct fcoe_statistics_params
*)hba
->stats_buffer
;
680 bnx2fc_stats
= fc_get_host_stats(shost
);
682 init_completion(&hba
->stat_req_done
);
683 if (bnx2fc_send_stat_req(hba
))
685 rc
= wait_for_completion_timeout(&hba
->stat_req_done
, (2 * HZ
));
687 BNX2FC_HBA_DBG(lport
, "FW stat req timed out\n");
690 bnx2fc_stats
->invalid_crc_count
+= fw_stats
->rx_stat2
.fc_crc_cnt
;
691 bnx2fc_stats
->tx_frames
+= fw_stats
->tx_stat
.fcoe_tx_pkt_cnt
;
692 bnx2fc_stats
->tx_words
+= (fw_stats
->tx_stat
.fcoe_tx_byte_cnt
) / 4;
693 bnx2fc_stats
->rx_frames
+= fw_stats
->rx_stat0
.fcoe_rx_pkt_cnt
;
694 bnx2fc_stats
->rx_words
+= (fw_stats
->rx_stat0
.fcoe_rx_byte_cnt
) / 4;
696 bnx2fc_stats
->dumped_frames
= 0;
697 bnx2fc_stats
->lip_count
= 0;
698 bnx2fc_stats
->nos_count
= 0;
699 bnx2fc_stats
->loss_of_sync_count
= 0;
700 bnx2fc_stats
->loss_of_signal_count
= 0;
701 bnx2fc_stats
->prim_seq_protocol_err_count
= 0;
706 static int bnx2fc_shost_config(struct fc_lport
*lport
, struct device
*dev
)
708 struct fcoe_port
*port
= lport_priv(lport
);
709 struct bnx2fc_interface
*interface
= port
->priv
;
710 struct Scsi_Host
*shost
= lport
->host
;
713 shost
->max_cmd_len
= BNX2FC_MAX_CMD_LEN
;
714 shost
->max_lun
= BNX2FC_MAX_LUN
;
715 shost
->max_id
= BNX2FC_MAX_FCP_TGT
;
716 shost
->max_channel
= 0;
718 shost
->transportt
= bnx2fc_vport_xport_template
;
720 shost
->transportt
= bnx2fc_transport_template
;
722 /* Add the new host to SCSI-ml */
723 rc
= scsi_add_host(lport
->host
, dev
);
725 printk(KERN_ERR PFX
"Error on scsi_add_host\n");
729 fc_host_max_npiv_vports(lport
->host
) = USHRT_MAX
;
730 sprintf(fc_host_symbolic_name(lport
->host
), "%s v%s over %s",
731 BNX2FC_NAME
, BNX2FC_VERSION
,
732 interface
->netdev
->name
);
737 static void bnx2fc_link_speed_update(struct fc_lport
*lport
)
739 struct fcoe_port
*port
= lport_priv(lport
);
740 struct bnx2fc_interface
*interface
= port
->priv
;
741 struct net_device
*netdev
= interface
->netdev
;
742 struct ethtool_cmd ecmd
;
744 if (!__ethtool_get_settings(netdev
, &ecmd
)) {
745 lport
->link_supported_speeds
&=
746 ~(FC_PORTSPEED_1GBIT
| FC_PORTSPEED_10GBIT
);
747 if (ecmd
.supported
& (SUPPORTED_1000baseT_Half
|
748 SUPPORTED_1000baseT_Full
))
749 lport
->link_supported_speeds
|= FC_PORTSPEED_1GBIT
;
750 if (ecmd
.supported
& SUPPORTED_10000baseT_Full
)
751 lport
->link_supported_speeds
|= FC_PORTSPEED_10GBIT
;
753 switch (ethtool_cmd_speed(&ecmd
)) {
755 lport
->link_speed
= FC_PORTSPEED_1GBIT
;
758 lport
->link_speed
= FC_PORTSPEED_2GBIT
;
761 lport
->link_speed
= FC_PORTSPEED_10GBIT
;
766 static int bnx2fc_link_ok(struct fc_lport
*lport
)
768 struct fcoe_port
*port
= lport_priv(lport
);
769 struct bnx2fc_interface
*interface
= port
->priv
;
770 struct bnx2fc_hba
*hba
= interface
->hba
;
771 struct net_device
*dev
= hba
->phys_dev
;
774 if ((dev
->flags
& IFF_UP
) && netif_carrier_ok(dev
))
775 clear_bit(ADAPTER_STATE_LINK_DOWN
, &hba
->adapter_state
);
777 set_bit(ADAPTER_STATE_LINK_DOWN
, &hba
->adapter_state
);
784 * bnx2fc_get_link_state - get network link state
786 * @hba: adapter instance pointer
788 * updates adapter structure flag based on netdev state
790 void bnx2fc_get_link_state(struct bnx2fc_hba
*hba
)
792 if (test_bit(__LINK_STATE_NOCARRIER
, &hba
->phys_dev
->state
))
793 set_bit(ADAPTER_STATE_LINK_DOWN
, &hba
->adapter_state
);
795 clear_bit(ADAPTER_STATE_LINK_DOWN
, &hba
->adapter_state
);
798 static int bnx2fc_net_config(struct fc_lport
*lport
, struct net_device
*netdev
)
800 struct bnx2fc_hba
*hba
;
801 struct bnx2fc_interface
*interface
;
802 struct fcoe_ctlr
*ctlr
;
803 struct fcoe_port
*port
;
806 port
= lport_priv(lport
);
807 interface
= port
->priv
;
808 ctlr
= bnx2fc_to_ctlr(interface
);
809 hba
= interface
->hba
;
811 /* require support for get_pauseparam ethtool op. */
812 if (!hba
->phys_dev
->ethtool_ops
||
813 !hba
->phys_dev
->ethtool_ops
->get_pauseparam
)
816 if (fc_set_mfs(lport
, BNX2FC_MFS
))
819 skb_queue_head_init(&port
->fcoe_pending_queue
);
820 port
->fcoe_pending_queue_active
= 0;
821 setup_timer(&port
->timer
, fcoe_queue_timer
, (unsigned long) lport
);
823 bnx2fc_link_speed_update(lport
);
826 if (fcoe_get_wwn(netdev
, &wwnn
, NETDEV_FCOE_WWNN
))
827 wwnn
= fcoe_wwn_from_mac(ctlr
->ctl_src_addr
,
829 BNX2FC_HBA_DBG(lport
, "WWNN = 0x%llx\n", wwnn
);
830 fc_set_wwnn(lport
, wwnn
);
832 if (fcoe_get_wwn(netdev
, &wwpn
, NETDEV_FCOE_WWPN
))
833 wwpn
= fcoe_wwn_from_mac(ctlr
->ctl_src_addr
,
836 BNX2FC_HBA_DBG(lport
, "WWPN = 0x%llx\n", wwpn
);
837 fc_set_wwpn(lport
, wwpn
);
843 static void bnx2fc_destroy_timer(unsigned long data
)
845 struct bnx2fc_hba
*hba
= (struct bnx2fc_hba
*)data
;
847 printk(KERN_ERR PFX
"ERROR:bnx2fc_destroy_timer - "
848 "Destroy compl not received!!\n");
849 set_bit(BNX2FC_FLAG_DESTROY_CMPL
, &hba
->flags
);
850 wake_up_interruptible(&hba
->destroy_wait
);
854 * bnx2fc_indicate_netevent - Generic netdev event handler
856 * @context: adapter structure pointer
858 * @vlan_id: vlan id - associated vlan id with this event
860 * Handles NETDEV_UP, NETDEV_DOWN, NETDEV_GOING_DOWN,NETDEV_CHANGE and
861 * NETDEV_CHANGE_MTU events. Handle NETDEV_UNREGISTER only for vlans.
863 static void bnx2fc_indicate_netevent(void *context
, unsigned long event
,
866 struct bnx2fc_hba
*hba
= (struct bnx2fc_hba
*)context
;
867 struct fc_lport
*lport
;
868 struct fc_lport
*vport
;
869 struct bnx2fc_interface
*interface
, *tmp
;
870 struct fcoe_ctlr
*ctlr
;
871 int wait_for_upload
= 0;
872 u32 link_possible
= 1;
874 if (vlan_id
!= 0 && event
!= NETDEV_UNREGISTER
)
879 if (!test_bit(ADAPTER_STATE_UP
, &hba
->adapter_state
))
880 printk(KERN_ERR
"indicate_netevent: "\
881 "hba is not UP!!\n");
885 clear_bit(ADAPTER_STATE_GOING_DOWN
, &hba
->adapter_state
);
886 clear_bit(ADAPTER_STATE_UP
, &hba
->adapter_state
);
890 case NETDEV_GOING_DOWN
:
891 set_bit(ADAPTER_STATE_GOING_DOWN
, &hba
->adapter_state
);
898 case NETDEV_UNREGISTER
:
901 mutex_lock(&bnx2fc_dev_lock
);
902 list_for_each_entry_safe(interface
, tmp
, &if_list
, list
) {
903 if (interface
->hba
== hba
&&
904 interface
->vlan_id
== (vlan_id
& VLAN_VID_MASK
))
905 __bnx2fc_destroy(interface
);
907 mutex_unlock(&bnx2fc_dev_lock
);
911 printk(KERN_ERR PFX
"Unkonwn netevent %ld", event
);
915 mutex_lock(&bnx2fc_dev_lock
);
916 list_for_each_entry(interface
, &if_list
, list
) {
918 if (interface
->hba
!= hba
)
921 ctlr
= bnx2fc_to_ctlr(interface
);
923 BNX2FC_HBA_DBG(lport
, "netevent handler - event=%s %ld\n",
924 interface
->netdev
->name
, event
);
926 bnx2fc_link_speed_update(lport
);
928 if (link_possible
&& !bnx2fc_link_ok(lport
)) {
929 /* Reset max recv frame size to default */
930 fc_set_mfs(lport
, BNX2FC_MFS
);
932 * ctlr link up will only be handled during
933 * enable to avoid sending discovery solicitation
936 if (interface
->enabled
)
937 fcoe_ctlr_link_up(ctlr
);
938 } else if (fcoe_ctlr_link_down(ctlr
)) {
939 mutex_lock(&lport
->lp_mutex
);
940 list_for_each_entry(vport
, &lport
->vports
, list
)
941 fc_host_port_type(vport
->host
) =
943 mutex_unlock(&lport
->lp_mutex
);
944 fc_host_port_type(lport
->host
) = FC_PORTTYPE_UNKNOWN
;
945 per_cpu_ptr(lport
->dev_stats
,
946 get_cpu())->LinkFailureCount
++;
948 fcoe_clean_pending_queue(lport
);
952 mutex_unlock(&bnx2fc_dev_lock
);
954 if (wait_for_upload
) {
955 clear_bit(ADAPTER_STATE_READY
, &hba
->adapter_state
);
956 init_waitqueue_head(&hba
->shutdown_wait
);
957 BNX2FC_MISC_DBG("indicate_netevent "
958 "num_ofld_sess = %d\n",
960 hba
->wait_for_link_down
= 1;
961 wait_event_interruptible(hba
->shutdown_wait
,
962 (hba
->num_ofld_sess
== 0));
963 BNX2FC_MISC_DBG("wakeup - num_ofld_sess = %d\n",
965 hba
->wait_for_link_down
= 0;
967 if (signal_pending(current
))
968 flush_signals(current
);
972 static int bnx2fc_libfc_config(struct fc_lport
*lport
)
975 /* Set the function pointers set by bnx2fc driver */
976 memcpy(&lport
->tt
, &bnx2fc_libfc_fcn_templ
,
977 sizeof(struct libfc_function_template
));
978 fc_elsct_init(lport
);
980 fc_rport_init(lport
);
985 static int bnx2fc_em_config(struct fc_lport
*lport
)
990 max_xid
= FCOE_XIDS_PER_CPU
;
992 max_xid
= FCOE_MAX_XID
;
993 if (!fc_exch_mgr_alloc(lport
, FC_CLASS_3
, FCOE_MIN_XID
,
995 printk(KERN_ERR PFX
"em_config:fc_exch_mgr_alloc failed\n");
1002 static int bnx2fc_lport_config(struct fc_lport
*lport
)
1006 lport
->max_retry_count
= BNX2FC_MAX_RETRY_CNT
;
1007 lport
->max_rport_retry_count
= BNX2FC_MAX_RPORT_RETRY_CNT
;
1008 lport
->e_d_tov
= 2 * 1000;
1009 lport
->r_a_tov
= 10 * 1000;
1011 lport
->service_params
= (FCP_SPPF_INIT_FCN
| FCP_SPPF_RD_XRDY_DIS
|
1012 FCP_SPPF_RETRY
| FCP_SPPF_CONF_COMPL
);
1013 lport
->does_npiv
= 1;
1015 memset(&lport
->rnid_gen
, 0, sizeof(struct fc_els_rnid_gen
));
1016 lport
->rnid_gen
.rnid_atype
= BNX2FC_RNID_HBA
;
1018 /* alloc stats structure */
1019 if (fc_lport_init_stats(lport
))
1022 /* Finish fc_lport configuration */
1023 fc_lport_config(lport
);
1029 * bnx2fc_fip_recv - handle a received FIP frame.
1031 * @skb: the received skb
1032 * @dev: associated &net_device
1033 * @ptype: the &packet_type structure which was used to register this handler.
1034 * @orig_dev: original receive &net_device, in case @ dev is a bond.
1036 * Returns: 0 for success
1038 static int bnx2fc_fip_recv(struct sk_buff
*skb
, struct net_device
*dev
,
1039 struct packet_type
*ptype
,
1040 struct net_device
*orig_dev
)
1042 struct bnx2fc_interface
*interface
;
1043 struct fcoe_ctlr
*ctlr
;
1044 interface
= container_of(ptype
, struct bnx2fc_interface
,
1046 ctlr
= bnx2fc_to_ctlr(interface
);
1047 fcoe_ctlr_recv(ctlr
, skb
);
1052 * bnx2fc_update_src_mac - Update Ethernet MAC filters.
1054 * @fip: FCoE controller.
1055 * @old: Unicast MAC address to delete if the MAC is non-zero.
1056 * @new: Unicast MAC address to add.
1058 * Remove any previously-set unicast MAC filter.
1059 * Add secondary FCoE MAC address filter for our OUI.
1061 static void bnx2fc_update_src_mac(struct fc_lport
*lport
, u8
*addr
)
1063 struct fcoe_port
*port
= lport_priv(lport
);
1065 memcpy(port
->data_src_addr
, addr
, ETH_ALEN
);
1069 * bnx2fc_get_src_mac - return the ethernet source address for an lport
1071 * @lport: libfc port
1073 static u8
*bnx2fc_get_src_mac(struct fc_lport
*lport
)
1075 struct fcoe_port
*port
;
1077 port
= (struct fcoe_port
*)lport_priv(lport
);
1078 return port
->data_src_addr
;
1082 * bnx2fc_fip_send - send an Ethernet-encapsulated FIP frame.
1084 * @fip: FCoE controller.
1087 static void bnx2fc_fip_send(struct fcoe_ctlr
*fip
, struct sk_buff
*skb
)
1089 skb
->dev
= bnx2fc_from_ctlr(fip
)->netdev
;
1090 dev_queue_xmit(skb
);
1093 static int bnx2fc_vport_create(struct fc_vport
*vport
, bool disabled
)
1095 struct Scsi_Host
*shost
= vport_to_shost(vport
);
1096 struct fc_lport
*n_port
= shost_priv(shost
);
1097 struct fcoe_port
*port
= lport_priv(n_port
);
1098 struct bnx2fc_interface
*interface
= port
->priv
;
1099 struct net_device
*netdev
= interface
->netdev
;
1100 struct fc_lport
*vn_port
;
1104 rc
= fcoe_validate_vport_create(vport
);
1106 fcoe_wwn_to_str(vport
->port_name
, buf
, sizeof(buf
));
1107 printk(KERN_ERR PFX
"Failed to create vport, "
1108 "WWPN (0x%s) already exists\n",
1113 if (!test_bit(BNX2FC_FLAG_FW_INIT_DONE
, &interface
->hba
->flags
)) {
1114 printk(KERN_ERR PFX
"vn ports cannot be created on"
1115 "this interface\n");
1119 mutex_lock(&bnx2fc_dev_lock
);
1120 vn_port
= bnx2fc_if_create(interface
, &vport
->dev
, 1);
1121 mutex_unlock(&bnx2fc_dev_lock
);
1124 if (IS_ERR(vn_port
)) {
1125 printk(KERN_ERR PFX
"bnx2fc_vport_create (%s) failed\n",
1131 fc_vport_set_state(vport
, FC_VPORT_DISABLED
);
1133 vn_port
->boot_time
= jiffies
;
1134 fc_lport_init(vn_port
);
1135 fc_fabric_login(vn_port
);
1136 fc_vport_setlink(vn_port
);
1141 static void bnx2fc_free_vport(struct bnx2fc_hba
*hba
, struct fc_lport
*lport
)
1143 struct bnx2fc_lport
*blport
, *tmp
;
1145 spin_lock_bh(&hba
->hba_lock
);
1146 list_for_each_entry_safe(blport
, tmp
, &hba
->vports
, list
) {
1147 if (blport
->lport
== lport
) {
1148 list_del(&blport
->list
);
1152 spin_unlock_bh(&hba
->hba_lock
);
1155 static int bnx2fc_vport_destroy(struct fc_vport
*vport
)
1157 struct Scsi_Host
*shost
= vport_to_shost(vport
);
1158 struct fc_lport
*n_port
= shost_priv(shost
);
1159 struct fc_lport
*vn_port
= vport
->dd_data
;
1160 struct fcoe_port
*port
= lport_priv(vn_port
);
1161 struct bnx2fc_interface
*interface
= port
->priv
;
1162 struct fc_lport
*v_port
;
1165 mutex_lock(&n_port
->lp_mutex
);
1166 list_for_each_entry(v_port
, &n_port
->vports
, list
)
1167 if (v_port
->vport
== vport
) {
1173 mutex_unlock(&n_port
->lp_mutex
);
1176 list_del(&vn_port
->list
);
1177 mutex_unlock(&n_port
->lp_mutex
);
1178 bnx2fc_free_vport(interface
->hba
, port
->lport
);
1179 bnx2fc_port_shutdown(port
->lport
);
1180 bnx2fc_interface_put(interface
);
1181 queue_work(bnx2fc_wq
, &port
->destroy_work
);
1185 static int bnx2fc_vport_disable(struct fc_vport
*vport
, bool disable
)
1187 struct fc_lport
*lport
= vport
->dd_data
;
1190 fc_vport_set_state(vport
, FC_VPORT_DISABLED
);
1191 fc_fabric_logoff(lport
);
1193 lport
->boot_time
= jiffies
;
1194 fc_fabric_login(lport
);
1195 fc_vport_setlink(lport
);
1201 static int bnx2fc_interface_setup(struct bnx2fc_interface
*interface
)
1203 struct net_device
*netdev
= interface
->netdev
;
1204 struct net_device
*physdev
= interface
->hba
->phys_dev
;
1205 struct fcoe_ctlr
*ctlr
= bnx2fc_to_ctlr(interface
);
1206 struct netdev_hw_addr
*ha
;
1207 int sel_san_mac
= 0;
1209 /* setup Source MAC Address */
1211 for_each_dev_addr(physdev
, ha
) {
1212 BNX2FC_MISC_DBG("net_config: ha->type = %d, fip_mac = ",
1214 printk(KERN_INFO
"%2x:%2x:%2x:%2x:%2x:%2x\n", ha
->addr
[0],
1215 ha
->addr
[1], ha
->addr
[2], ha
->addr
[3],
1216 ha
->addr
[4], ha
->addr
[5]);
1218 if ((ha
->type
== NETDEV_HW_ADDR_T_SAN
) &&
1219 (is_valid_ether_addr(ha
->addr
))) {
1220 memcpy(ctlr
->ctl_src_addr
, ha
->addr
,
1223 BNX2FC_MISC_DBG("Found SAN MAC\n");
1231 interface
->fip_packet_type
.func
= bnx2fc_fip_recv
;
1232 interface
->fip_packet_type
.type
= htons(ETH_P_FIP
);
1233 interface
->fip_packet_type
.dev
= netdev
;
1234 dev_add_pack(&interface
->fip_packet_type
);
1236 interface
->fcoe_packet_type
.func
= bnx2fc_rcv
;
1237 interface
->fcoe_packet_type
.type
= __constant_htons(ETH_P_FCOE
);
1238 interface
->fcoe_packet_type
.dev
= netdev
;
1239 dev_add_pack(&interface
->fcoe_packet_type
);
1244 static int bnx2fc_attach_transport(void)
1246 bnx2fc_transport_template
=
1247 fc_attach_transport(&bnx2fc_transport_function
);
1249 if (bnx2fc_transport_template
== NULL
) {
1250 printk(KERN_ERR PFX
"Failed to attach FC transport\n");
1254 bnx2fc_vport_xport_template
=
1255 fc_attach_transport(&bnx2fc_vport_xport_function
);
1256 if (bnx2fc_vport_xport_template
== NULL
) {
1258 "Failed to attach FC transport for vport\n");
1259 fc_release_transport(bnx2fc_transport_template
);
1260 bnx2fc_transport_template
= NULL
;
1265 static void bnx2fc_release_transport(void)
1267 fc_release_transport(bnx2fc_transport_template
);
1268 fc_release_transport(bnx2fc_vport_xport_template
);
1269 bnx2fc_transport_template
= NULL
;
1270 bnx2fc_vport_xport_template
= NULL
;
1273 static void bnx2fc_interface_release(struct kref
*kref
)
1275 struct fcoe_ctlr_device
*ctlr_dev
;
1276 struct bnx2fc_interface
*interface
;
1277 struct fcoe_ctlr
*ctlr
;
1278 struct net_device
*netdev
;
1280 interface
= container_of(kref
, struct bnx2fc_interface
, kref
);
1281 BNX2FC_MISC_DBG("Interface is being released\n");
1283 ctlr
= bnx2fc_to_ctlr(interface
);
1284 ctlr_dev
= fcoe_ctlr_to_ctlr_dev(ctlr
);
1285 netdev
= interface
->netdev
;
1287 /* tear-down FIP controller */
1288 if (test_and_clear_bit(BNX2FC_CTLR_INIT_DONE
, &interface
->if_flags
))
1289 fcoe_ctlr_destroy(ctlr
);
1291 fcoe_ctlr_device_delete(ctlr_dev
);
1294 module_put(THIS_MODULE
);
1297 static inline void bnx2fc_interface_get(struct bnx2fc_interface
*interface
)
1299 kref_get(&interface
->kref
);
1302 static inline void bnx2fc_interface_put(struct bnx2fc_interface
*interface
)
1304 kref_put(&interface
->kref
, bnx2fc_interface_release
);
1306 static void bnx2fc_hba_destroy(struct bnx2fc_hba
*hba
)
1308 /* Free the command manager */
1310 bnx2fc_cmd_mgr_free(hba
->cmd_mgr
);
1311 hba
->cmd_mgr
= NULL
;
1313 kfree(hba
->tgt_ofld_list
);
1314 bnx2fc_unbind_pcidev(hba
);
1319 * bnx2fc_hba_create - create a new bnx2fc hba
1321 * @cnic: pointer to cnic device
1323 * Creates a new FCoE hba on the given device.
1326 static struct bnx2fc_hba
*bnx2fc_hba_create(struct cnic_dev
*cnic
)
1328 struct bnx2fc_hba
*hba
;
1331 hba
= kzalloc(sizeof(*hba
), GFP_KERNEL
);
1333 printk(KERN_ERR PFX
"Unable to allocate hba structure\n");
1336 spin_lock_init(&hba
->hba_lock
);
1337 mutex_init(&hba
->hba_mutex
);
1340 rc
= bnx2fc_bind_pcidev(hba
);
1342 printk(KERN_ERR PFX
"create_adapter: bind error\n");
1345 hba
->phys_dev
= cnic
->netdev
;
1346 hba
->next_conn_id
= 0;
1348 hba
->tgt_ofld_list
=
1349 kzalloc(sizeof(struct bnx2fc_rport
*) * BNX2FC_NUM_MAX_SESS
,
1351 if (!hba
->tgt_ofld_list
) {
1352 printk(KERN_ERR PFX
"Unable to allocate tgt offload list\n");
1356 hba
->num_ofld_sess
= 0;
1358 hba
->cmd_mgr
= bnx2fc_cmd_mgr_alloc(hba
, BNX2FC_MIN_XID
,
1360 if (!hba
->cmd_mgr
) {
1361 printk(KERN_ERR PFX
"em_config:bnx2fc_cmd_mgr_alloc failed\n");
1365 init_waitqueue_head(&hba
->shutdown_wait
);
1366 init_waitqueue_head(&hba
->destroy_wait
);
1367 INIT_LIST_HEAD(&hba
->vports
);
1372 kfree(hba
->tgt_ofld_list
);
1374 bnx2fc_unbind_pcidev(hba
);
1380 struct bnx2fc_interface
*bnx2fc_interface_create(struct bnx2fc_hba
*hba
,
1381 struct net_device
*netdev
,
1382 enum fip_state fip_mode
)
1384 struct fcoe_ctlr_device
*ctlr_dev
;
1385 struct bnx2fc_interface
*interface
;
1386 struct fcoe_ctlr
*ctlr
;
1390 size
= (sizeof(*interface
) + sizeof(struct fcoe_ctlr
));
1391 ctlr_dev
= fcoe_ctlr_device_add(&netdev
->dev
, &bnx2fc_fcoe_sysfs_templ
,
1394 printk(KERN_ERR PFX
"Unable to allocate interface structure\n");
1397 ctlr
= fcoe_ctlr_device_priv(ctlr_dev
);
1398 interface
= fcoe_ctlr_priv(ctlr
);
1400 kref_init(&interface
->kref
);
1401 interface
->hba
= hba
;
1402 interface
->netdev
= netdev
;
1404 /* Initialize FIP */
1405 fcoe_ctlr_init(ctlr
, fip_mode
);
1406 ctlr
->send
= bnx2fc_fip_send
;
1407 ctlr
->update_mac
= bnx2fc_update_src_mac
;
1408 ctlr
->get_src_addr
= bnx2fc_get_src_mac
;
1409 set_bit(BNX2FC_CTLR_INIT_DONE
, &interface
->if_flags
);
1411 rc
= bnx2fc_interface_setup(interface
);
1415 fcoe_ctlr_destroy(ctlr
);
1417 fcoe_ctlr_device_delete(ctlr_dev
);
1422 * bnx2fc_if_create - Create FCoE instance on a given interface
1424 * @interface: FCoE interface to create a local port on
1425 * @parent: Device pointer to be the parent in sysfs for the SCSI host
1426 * @npiv: Indicates if the port is vport or not
1428 * Creates a fc_lport instance and a Scsi_Host instance and configure them.
1430 * Returns: Allocated fc_lport or an error pointer
1432 static struct fc_lport
*bnx2fc_if_create(struct bnx2fc_interface
*interface
,
1433 struct device
*parent
, int npiv
)
1435 struct fcoe_ctlr
*ctlr
= bnx2fc_to_ctlr(interface
);
1436 struct fc_lport
*lport
, *n_port
;
1437 struct fcoe_port
*port
;
1438 struct Scsi_Host
*shost
;
1439 struct fc_vport
*vport
= dev_to_vport(parent
);
1440 struct bnx2fc_lport
*blport
;
1441 struct bnx2fc_hba
*hba
;
1444 blport
= kzalloc(sizeof(struct bnx2fc_lport
), GFP_KERNEL
);
1446 BNX2FC_HBA_DBG(ctlr
->lp
, "Unable to alloc blport\n");
1450 /* Allocate Scsi_Host structure */
1452 lport
= libfc_host_alloc(&bnx2fc_shost_template
, sizeof(*port
));
1454 lport
= libfc_vport_create(vport
, sizeof(*port
));
1457 printk(KERN_ERR PFX
"could not allocate scsi host structure\n");
1460 shost
= lport
->host
;
1461 port
= lport_priv(lport
);
1462 port
->lport
= lport
;
1463 port
->priv
= interface
;
1464 INIT_WORK(&port
->destroy_work
, bnx2fc_destroy_work
);
1466 /* Configure fcoe_port */
1467 rc
= bnx2fc_lport_config(lport
);
1472 printk(KERN_ERR PFX
"Setting vport names, 0x%llX 0x%llX\n",
1473 vport
->node_name
, vport
->port_name
);
1474 fc_set_wwnn(lport
, vport
->node_name
);
1475 fc_set_wwpn(lport
, vport
->port_name
);
1477 /* Configure netdev and networking properties of the lport */
1478 rc
= bnx2fc_net_config(lport
, interface
->netdev
);
1480 printk(KERN_ERR PFX
"Error on bnx2fc_net_config\n");
1484 rc
= bnx2fc_shost_config(lport
, parent
);
1486 printk(KERN_ERR PFX
"Couldnt configure shost for %s\n",
1487 interface
->netdev
->name
);
1491 /* Initialize the libfc library */
1492 rc
= bnx2fc_libfc_config(lport
);
1494 printk(KERN_ERR PFX
"Couldnt configure libfc\n");
1497 fc_host_port_type(lport
->host
) = FC_PORTTYPE_UNKNOWN
;
1499 /* Allocate exchange manager */
1501 rc
= bnx2fc_em_config(lport
);
1503 shost
= vport_to_shost(vport
);
1504 n_port
= shost_priv(shost
);
1505 rc
= fc_exch_mgr_list_clone(n_port
, lport
);
1509 printk(KERN_ERR PFX
"Error on bnx2fc_em_config\n");
1513 bnx2fc_interface_get(interface
);
1515 hba
= interface
->hba
;
1516 spin_lock_bh(&hba
->hba_lock
);
1517 blport
->lport
= lport
;
1518 list_add_tail(&blport
->list
, &hba
->vports
);
1519 spin_unlock_bh(&hba
->hba_lock
);
1524 scsi_remove_host(shost
);
1526 scsi_host_put(lport
->host
);
1532 static void bnx2fc_net_cleanup(struct bnx2fc_interface
*interface
)
1534 /* Dont listen for Ethernet packets anymore */
1535 __dev_remove_pack(&interface
->fcoe_packet_type
);
1536 __dev_remove_pack(&interface
->fip_packet_type
);
1540 static void bnx2fc_interface_cleanup(struct bnx2fc_interface
*interface
)
1542 struct fcoe_ctlr
*ctlr
= bnx2fc_to_ctlr(interface
);
1543 struct fc_lport
*lport
= ctlr
->lp
;
1544 struct fcoe_port
*port
= lport_priv(lport
);
1545 struct bnx2fc_hba
*hba
= interface
->hba
;
1547 /* Stop the transmit retry timer */
1548 del_timer_sync(&port
->timer
);
1550 /* Free existing transmit skbs */
1551 fcoe_clean_pending_queue(lport
);
1553 bnx2fc_net_cleanup(interface
);
1555 bnx2fc_free_vport(hba
, lport
);
1558 static void bnx2fc_if_destroy(struct fc_lport
*lport
)
1561 /* Free queued packets for the receive thread */
1562 bnx2fc_clean_rx_queue(lport
);
1564 /* Detach from scsi-ml */
1565 fc_remove_host(lport
->host
);
1566 scsi_remove_host(lport
->host
);
1569 * Note that only the physical lport will have the exchange manager.
1570 * for vports, this function is NOP
1572 fc_exch_mgr_free(lport
);
1574 /* Free memory used by statistical counters */
1575 fc_lport_free_stats(lport
);
1577 /* Release Scsi_Host */
1578 scsi_host_put(lport
->host
);
1581 static void __bnx2fc_destroy(struct bnx2fc_interface
*interface
)
1583 struct fcoe_ctlr
*ctlr
= bnx2fc_to_ctlr(interface
);
1584 struct fc_lport
*lport
= ctlr
->lp
;
1585 struct fcoe_port
*port
= lport_priv(lport
);
1587 bnx2fc_interface_cleanup(interface
);
1588 bnx2fc_stop(interface
);
1589 list_del(&interface
->list
);
1590 bnx2fc_interface_put(interface
);
1591 queue_work(bnx2fc_wq
, &port
->destroy_work
);
1595 * bnx2fc_destroy - Destroy a bnx2fc FCoE interface
1597 * @buffer: The name of the Ethernet interface to be destroyed
1598 * @kp: The associated kernel parameter
1600 * Called from sysfs.
1602 * Returns: 0 for success
1604 static int bnx2fc_destroy(struct net_device
*netdev
)
1606 struct bnx2fc_interface
*interface
= NULL
;
1607 struct workqueue_struct
*timer_work_queue
;
1608 struct fcoe_ctlr
*ctlr
;
1612 mutex_lock(&bnx2fc_dev_lock
);
1614 interface
= bnx2fc_interface_lookup(netdev
);
1615 ctlr
= bnx2fc_to_ctlr(interface
);
1616 if (!interface
|| !ctlr
->lp
) {
1618 printk(KERN_ERR PFX
"bnx2fc_destroy: interface or lport not found\n");
1622 timer_work_queue
= interface
->timer_work_queue
;
1623 __bnx2fc_destroy(interface
);
1624 destroy_workqueue(timer_work_queue
);
1627 mutex_unlock(&bnx2fc_dev_lock
);
1632 static void bnx2fc_destroy_work(struct work_struct
*work
)
1634 struct fcoe_port
*port
;
1635 struct fc_lport
*lport
;
1637 port
= container_of(work
, struct fcoe_port
, destroy_work
);
1638 lport
= port
->lport
;
1640 BNX2FC_HBA_DBG(lport
, "Entered bnx2fc_destroy_work\n");
1642 bnx2fc_if_destroy(lport
);
1645 static void bnx2fc_unbind_adapter_devices(struct bnx2fc_hba
*hba
)
1647 bnx2fc_free_fw_resc(hba
);
1648 bnx2fc_free_task_ctx(hba
);
1652 * bnx2fc_bind_adapter_devices - binds bnx2fc adapter with the associated
1655 * @hba: Adapter instance
1657 static int bnx2fc_bind_adapter_devices(struct bnx2fc_hba
*hba
)
1659 if (bnx2fc_setup_task_ctx(hba
))
1662 if (bnx2fc_setup_fw_resc(hba
))
1667 bnx2fc_unbind_adapter_devices(hba
);
1671 static int bnx2fc_bind_pcidev(struct bnx2fc_hba
*hba
)
1673 struct cnic_dev
*cnic
;
1676 printk(KERN_ERR PFX
"cnic is NULL\n");
1680 hba
->pcidev
= cnic
->pcidev
;
1682 pci_dev_get(hba
->pcidev
);
1687 static void bnx2fc_unbind_pcidev(struct bnx2fc_hba
*hba
)
1690 pci_dev_put(hba
->pcidev
);
1697 * bnx2fc_ulp_start - cnic callback to initialize & start adapter instance
1699 * @handle: transport handle pointing to adapter struture
1701 * This function maps adapter structure to pcidev structure and initiates
1702 * firmware handshake to enable/initialize on-chip FCoE components.
1703 * This bnx2fc - cnic interface api callback is used after following
1704 * conditions are met -
1705 * a) underlying network interface is up (marked by event NETDEV_UP
1707 * b) bnx2fc adatper structure is registered.
1709 static void bnx2fc_ulp_start(void *handle
)
1711 struct bnx2fc_hba
*hba
= handle
;
1712 struct bnx2fc_interface
*interface
;
1713 struct fcoe_ctlr
*ctlr
;
1714 struct fc_lport
*lport
;
1716 mutex_lock(&bnx2fc_dev_lock
);
1718 if (!test_bit(BNX2FC_FLAG_FW_INIT_DONE
, &hba
->flags
))
1719 bnx2fc_fw_init(hba
);
1721 BNX2FC_MISC_DBG("bnx2fc started.\n");
1723 list_for_each_entry(interface
, &if_list
, list
) {
1724 if (interface
->hba
== hba
) {
1725 ctlr
= bnx2fc_to_ctlr(interface
);
1727 /* Kick off Fabric discovery*/
1728 printk(KERN_ERR PFX
"ulp_init: start discovery\n");
1729 lport
->tt
.frame_send
= bnx2fc_xmit
;
1730 bnx2fc_start_disc(interface
);
1734 mutex_unlock(&bnx2fc_dev_lock
);
1737 static void bnx2fc_port_shutdown(struct fc_lport
*lport
)
1739 BNX2FC_MISC_DBG("Entered %s\n", __func__
);
1740 fc_fabric_logoff(lport
);
1741 fc_lport_destroy(lport
);
1744 static void bnx2fc_stop(struct bnx2fc_interface
*interface
)
1746 struct fcoe_ctlr
*ctlr
= bnx2fc_to_ctlr(interface
);
1747 struct fc_lport
*lport
;
1748 struct fc_lport
*vport
;
1750 if (!test_bit(BNX2FC_FLAG_FW_INIT_DONE
, &interface
->hba
->flags
))
1754 bnx2fc_port_shutdown(lport
);
1756 mutex_lock(&lport
->lp_mutex
);
1757 list_for_each_entry(vport
, &lport
->vports
, list
)
1758 fc_host_port_type(vport
->host
) =
1759 FC_PORTTYPE_UNKNOWN
;
1760 mutex_unlock(&lport
->lp_mutex
);
1761 fc_host_port_type(lport
->host
) = FC_PORTTYPE_UNKNOWN
;
1762 fcoe_ctlr_link_down(ctlr
);
1763 fcoe_clean_pending_queue(lport
);
1766 static int bnx2fc_fw_init(struct bnx2fc_hba
*hba
)
1768 #define BNX2FC_INIT_POLL_TIME (1000 / HZ)
1772 rc
= bnx2fc_bind_adapter_devices(hba
);
1774 printk(KERN_ALERT PFX
1775 "bnx2fc_bind_adapter_devices failed - rc = %d\n", rc
);
1779 rc
= bnx2fc_send_fw_fcoe_init_msg(hba
);
1781 printk(KERN_ALERT PFX
1782 "bnx2fc_send_fw_fcoe_init_msg failed - rc = %d\n", rc
);
1787 * Wait until the adapter init message is complete, and adapter
1790 while (!test_bit(ADAPTER_STATE_UP
, &hba
->adapter_state
) && i
--)
1791 msleep(BNX2FC_INIT_POLL_TIME
);
1793 if (!test_bit(ADAPTER_STATE_UP
, &hba
->adapter_state
)) {
1794 printk(KERN_ERR PFX
"bnx2fc_start: %s failed to initialize. "
1796 hba
->cnic
->netdev
->name
);
1802 set_bit(BNX2FC_FLAG_FW_INIT_DONE
, &hba
->flags
);
1806 bnx2fc_unbind_adapter_devices(hba
);
1811 static void bnx2fc_fw_destroy(struct bnx2fc_hba
*hba
)
1813 if (test_and_clear_bit(BNX2FC_FLAG_FW_INIT_DONE
, &hba
->flags
)) {
1814 if (bnx2fc_send_fw_fcoe_destroy_msg(hba
) == 0) {
1815 init_timer(&hba
->destroy_timer
);
1816 hba
->destroy_timer
.expires
= BNX2FC_FW_TIMEOUT
+
1818 hba
->destroy_timer
.function
= bnx2fc_destroy_timer
;
1819 hba
->destroy_timer
.data
= (unsigned long)hba
;
1820 add_timer(&hba
->destroy_timer
);
1821 wait_event_interruptible(hba
->destroy_wait
,
1822 test_bit(BNX2FC_FLAG_DESTROY_CMPL
,
1824 clear_bit(BNX2FC_FLAG_DESTROY_CMPL
, &hba
->flags
);
1825 /* This should never happen */
1826 if (signal_pending(current
))
1827 flush_signals(current
);
1829 del_timer_sync(&hba
->destroy_timer
);
1831 bnx2fc_unbind_adapter_devices(hba
);
1836 * bnx2fc_ulp_stop - cnic callback to shutdown adapter instance
1838 * @handle: transport handle pointing to adapter structure
1840 * Driver checks if adapter is already in shutdown mode, if not start
1841 * the shutdown process.
1843 static void bnx2fc_ulp_stop(void *handle
)
1845 struct bnx2fc_hba
*hba
= handle
;
1846 struct bnx2fc_interface
*interface
;
1848 printk(KERN_ERR
"ULP_STOP\n");
1850 mutex_lock(&bnx2fc_dev_lock
);
1851 if (!test_bit(BNX2FC_FLAG_FW_INIT_DONE
, &hba
->flags
))
1853 list_for_each_entry(interface
, &if_list
, list
) {
1854 if (interface
->hba
== hba
)
1855 bnx2fc_stop(interface
);
1857 BUG_ON(hba
->num_ofld_sess
!= 0);
1859 mutex_lock(&hba
->hba_mutex
);
1860 clear_bit(ADAPTER_STATE_UP
, &hba
->adapter_state
);
1861 clear_bit(ADAPTER_STATE_GOING_DOWN
,
1862 &hba
->adapter_state
);
1864 clear_bit(ADAPTER_STATE_READY
, &hba
->adapter_state
);
1865 mutex_unlock(&hba
->hba_mutex
);
1867 bnx2fc_fw_destroy(hba
);
1869 mutex_unlock(&bnx2fc_dev_lock
);
1872 static void bnx2fc_start_disc(struct bnx2fc_interface
*interface
)
1874 struct fcoe_ctlr
*ctlr
= bnx2fc_to_ctlr(interface
);
1875 struct fc_lport
*lport
;
1878 BNX2FC_MISC_DBG("Entered %s\n", __func__
);
1879 /* Kick off FIP/FLOGI */
1880 if (!test_bit(BNX2FC_FLAG_FW_INIT_DONE
, &interface
->hba
->flags
)) {
1881 printk(KERN_ERR PFX
"Init not done yet\n");
1886 BNX2FC_HBA_DBG(lport
, "calling fc_fabric_login\n");
1888 if (!bnx2fc_link_ok(lport
) && interface
->enabled
) {
1889 BNX2FC_HBA_DBG(lport
, "ctlr_link_up\n");
1890 fcoe_ctlr_link_up(ctlr
);
1891 fc_host_port_type(lport
->host
) = FC_PORTTYPE_NPORT
;
1892 set_bit(ADAPTER_STATE_READY
, &interface
->hba
->adapter_state
);
1895 /* wait for the FCF to be selected before issuing FLOGI */
1896 while (!ctlr
->sel_fcf
) {
1898 /* give up after 3 secs */
1899 if (++wait_cnt
> 12)
1903 /* Reset max receive frame size to default */
1904 if (fc_set_mfs(lport
, BNX2FC_MFS
))
1907 fc_lport_init(lport
);
1908 fc_fabric_login(lport
);
1913 * bnx2fc_ulp_init - Initialize an adapter instance
1915 * @dev : cnic device handle
1916 * Called from cnic_register_driver() context to initialize all
1917 * enumerated cnic devices. This routine allocates adapter structure
1918 * and other device specific resources.
1920 static void bnx2fc_ulp_init(struct cnic_dev
*dev
)
1922 struct bnx2fc_hba
*hba
;
1925 BNX2FC_MISC_DBG("Entered %s\n", __func__
);
1926 /* bnx2fc works only when bnx2x is loaded */
1927 if (!test_bit(CNIC_F_BNX2X_CLASS
, &dev
->flags
) ||
1928 (dev
->max_fcoe_conn
== 0)) {
1929 printk(KERN_ERR PFX
"bnx2fc FCoE not supported on %s,"
1930 " flags: %lx fcoe_conn: %d\n",
1931 dev
->netdev
->name
, dev
->flags
, dev
->max_fcoe_conn
);
1935 hba
= bnx2fc_hba_create(dev
);
1937 printk(KERN_ERR PFX
"hba initialization failed\n");
1941 /* Add HBA to the adapter list */
1942 mutex_lock(&bnx2fc_dev_lock
);
1943 list_add_tail(&hba
->list
, &adapter_list
);
1945 mutex_unlock(&bnx2fc_dev_lock
);
1947 clear_bit(BNX2FC_CNIC_REGISTERED
, &hba
->reg_with_cnic
);
1948 rc
= dev
->register_device(dev
, CNIC_ULP_FCOE
,
1951 printk(KERN_ERR PFX
"register_device failed, rc = %d\n", rc
);
1953 set_bit(BNX2FC_CNIC_REGISTERED
, &hba
->reg_with_cnic
);
1957 static int bnx2fc_disable(struct net_device
*netdev
)
1959 struct bnx2fc_interface
*interface
;
1960 struct fcoe_ctlr
*ctlr
;
1964 mutex_lock(&bnx2fc_dev_lock
);
1966 interface
= bnx2fc_interface_lookup(netdev
);
1967 ctlr
= bnx2fc_to_ctlr(interface
);
1968 if (!interface
|| !ctlr
->lp
) {
1970 printk(KERN_ERR PFX
"bnx2fc_disable: interface or lport not found\n");
1972 interface
->enabled
= false;
1973 fcoe_ctlr_link_down(ctlr
);
1974 fcoe_clean_pending_queue(ctlr
->lp
);
1977 mutex_unlock(&bnx2fc_dev_lock
);
1983 static int bnx2fc_enable(struct net_device
*netdev
)
1985 struct bnx2fc_interface
*interface
;
1986 struct fcoe_ctlr
*ctlr
;
1990 mutex_lock(&bnx2fc_dev_lock
);
1992 interface
= bnx2fc_interface_lookup(netdev
);
1993 ctlr
= bnx2fc_to_ctlr(interface
);
1994 if (!interface
|| !ctlr
->lp
) {
1996 printk(KERN_ERR PFX
"bnx2fc_enable: interface or lport not found\n");
1997 } else if (!bnx2fc_link_ok(ctlr
->lp
)) {
1998 fcoe_ctlr_link_up(ctlr
);
1999 interface
->enabled
= true;
2002 mutex_unlock(&bnx2fc_dev_lock
);
2008 * bnx2fc_create - Create bnx2fc FCoE interface
2010 * @buffer: The name of Ethernet interface to create on
2011 * @kp: The associated kernel param
2013 * Called from sysfs.
2015 * Returns: 0 for success
2017 static int bnx2fc_create(struct net_device
*netdev
, enum fip_state fip_mode
)
2019 struct fcoe_ctlr
*ctlr
;
2020 struct bnx2fc_interface
*interface
;
2021 struct bnx2fc_hba
*hba
;
2022 struct net_device
*phys_dev
;
2023 struct fc_lport
*lport
;
2024 struct ethtool_drvinfo drvinfo
;
2028 BNX2FC_MISC_DBG("Entered bnx2fc_create\n");
2029 if (fip_mode
!= FIP_MODE_FABRIC
) {
2030 printk(KERN_ERR
"fip mode not FABRIC\n");
2036 mutex_lock(&bnx2fc_dev_lock
);
2038 if (!try_module_get(THIS_MODULE
)) {
2043 /* obtain physical netdev */
2044 if (netdev
->priv_flags
& IFF_802_1Q_VLAN
) {
2045 phys_dev
= vlan_dev_real_dev(netdev
);
2046 vlan_id
= vlan_dev_vlan_id(netdev
);
2048 printk(KERN_ERR PFX
"Not a vlan device\n");
2052 /* verify if the physical device is a netxtreme2 device */
2053 if (phys_dev
->ethtool_ops
&& phys_dev
->ethtool_ops
->get_drvinfo
) {
2054 memset(&drvinfo
, 0, sizeof(drvinfo
));
2055 phys_dev
->ethtool_ops
->get_drvinfo(phys_dev
, &drvinfo
);
2056 if (strncmp(drvinfo
.driver
, "bnx2x", strlen("bnx2x"))) {
2057 printk(KERN_ERR PFX
"Not a netxtreme2 device\n");
2062 printk(KERN_ERR PFX
"unable to obtain drv_info\n");
2067 /* obtain interface and initialize rest of the structure */
2068 hba
= bnx2fc_hba_lookup(phys_dev
);
2071 printk(KERN_ERR PFX
"bnx2fc_create: hba not found\n");
2075 if (bnx2fc_interface_lookup(netdev
)) {
2080 interface
= bnx2fc_interface_create(hba
, netdev
, fip_mode
);
2082 printk(KERN_ERR PFX
"bnx2fc_interface_create failed\n");
2086 ctlr
= bnx2fc_to_ctlr(interface
);
2087 interface
->vlan_id
= vlan_id
;
2088 interface
->vlan_enabled
= 1;
2090 interface
->timer_work_queue
=
2091 create_singlethread_workqueue("bnx2fc_timer_wq");
2092 if (!interface
->timer_work_queue
) {
2093 printk(KERN_ERR PFX
"ulp_init could not create timer_wq\n");
2098 lport
= bnx2fc_if_create(interface
, &interface
->hba
->pcidev
->dev
, 0);
2100 printk(KERN_ERR PFX
"Failed to create interface (%s)\n",
2106 /* Add interface to if_list */
2107 list_add_tail(&interface
->list
, &if_list
);
2109 lport
->boot_time
= jiffies
;
2111 /* Make this master N_port */
2114 if (!bnx2fc_link_ok(lport
)) {
2115 fcoe_ctlr_link_up(ctlr
);
2116 fc_host_port_type(lport
->host
) = FC_PORTTYPE_NPORT
;
2117 set_bit(ADAPTER_STATE_READY
, &interface
->hba
->adapter_state
);
2120 BNX2FC_HBA_DBG(lport
, "create: START DISC\n");
2121 bnx2fc_start_disc(interface
);
2122 interface
->enabled
= true;
2124 * Release from kref_init in bnx2fc_interface_setup, on success
2125 * lport should be holding a reference taken in bnx2fc_if_create
2127 bnx2fc_interface_put(interface
);
2128 /* put netdev that was held while calling dev_get_by_name */
2129 mutex_unlock(&bnx2fc_dev_lock
);
2134 destroy_workqueue(interface
->timer_work_queue
);
2136 bnx2fc_net_cleanup(interface
);
2137 bnx2fc_interface_put(interface
);
2140 module_put(THIS_MODULE
);
2142 mutex_unlock(&bnx2fc_dev_lock
);
2148 * bnx2fc_find_hba_for_cnic - maps cnic instance to bnx2fc hba instance
2150 * @cnic: Pointer to cnic device instance
2153 static struct bnx2fc_hba
*bnx2fc_find_hba_for_cnic(struct cnic_dev
*cnic
)
2155 struct list_head
*list
;
2156 struct list_head
*temp
;
2157 struct bnx2fc_hba
*hba
;
2159 /* Called with bnx2fc_dev_lock held */
2160 list_for_each_safe(list
, temp
, &adapter_list
) {
2161 hba
= (struct bnx2fc_hba
*)list
;
2162 if (hba
->cnic
== cnic
)
2168 static struct bnx2fc_interface
*bnx2fc_interface_lookup(struct net_device
2171 struct bnx2fc_interface
*interface
;
2173 /* Called with bnx2fc_dev_lock held */
2174 list_for_each_entry(interface
, &if_list
, list
) {
2175 if (interface
->netdev
== netdev
)
2181 static struct bnx2fc_hba
*bnx2fc_hba_lookup(struct net_device
2184 struct bnx2fc_hba
*hba
;
2186 /* Called with bnx2fc_dev_lock held */
2187 list_for_each_entry(hba
, &adapter_list
, list
) {
2188 if (hba
->phys_dev
== phys_dev
)
2191 printk(KERN_ERR PFX
"adapter_lookup: hba NULL\n");
2196 * bnx2fc_ulp_exit - shuts down adapter instance and frees all resources
2198 * @dev cnic device handle
2200 static void bnx2fc_ulp_exit(struct cnic_dev
*dev
)
2202 struct bnx2fc_hba
*hba
;
2203 struct bnx2fc_interface
*interface
, *tmp
;
2205 BNX2FC_MISC_DBG("Entered bnx2fc_ulp_exit\n");
2207 if (!test_bit(CNIC_F_BNX2X_CLASS
, &dev
->flags
)) {
2208 printk(KERN_ERR PFX
"bnx2fc port check: %s, flags: %lx\n",
2209 dev
->netdev
->name
, dev
->flags
);
2213 mutex_lock(&bnx2fc_dev_lock
);
2214 hba
= bnx2fc_find_hba_for_cnic(dev
);
2216 printk(KERN_ERR PFX
"bnx2fc_ulp_exit: hba not found, dev 0%p\n",
2218 mutex_unlock(&bnx2fc_dev_lock
);
2222 list_del_init(&hba
->list
);
2225 list_for_each_entry_safe(interface
, tmp
, &if_list
, list
)
2226 /* destroy not called yet, move to quiesced list */
2227 if (interface
->hba
== hba
)
2228 __bnx2fc_destroy(interface
);
2229 mutex_unlock(&bnx2fc_dev_lock
);
2231 bnx2fc_ulp_stop(hba
);
2232 /* unregister cnic device */
2233 if (test_and_clear_bit(BNX2FC_CNIC_REGISTERED
, &hba
->reg_with_cnic
))
2234 hba
->cnic
->unregister_device(hba
->cnic
, CNIC_ULP_FCOE
);
2235 bnx2fc_hba_destroy(hba
);
2239 * bnx2fc_fcoe_reset - Resets the fcoe
2241 * @shost: shost the reset is from
2245 static int bnx2fc_fcoe_reset(struct Scsi_Host
*shost
)
2247 struct fc_lport
*lport
= shost_priv(shost
);
2248 fc_lport_reset(lport
);
2253 static bool bnx2fc_match(struct net_device
*netdev
)
2255 mutex_lock(&bnx2fc_dev_lock
);
2256 if (netdev
->priv_flags
& IFF_802_1Q_VLAN
) {
2257 struct net_device
*phys_dev
= vlan_dev_real_dev(netdev
);
2259 if (bnx2fc_hba_lookup(phys_dev
)) {
2260 mutex_unlock(&bnx2fc_dev_lock
);
2264 mutex_unlock(&bnx2fc_dev_lock
);
2269 static struct fcoe_transport bnx2fc_transport
= {
2272 .list
= LIST_HEAD_INIT(bnx2fc_transport
.list
),
2273 .match
= bnx2fc_match
,
2274 .create
= bnx2fc_create
,
2275 .destroy
= bnx2fc_destroy
,
2276 .enable
= bnx2fc_enable
,
2277 .disable
= bnx2fc_disable
,
2281 * bnx2fc_percpu_thread_create - Create a receive thread for an
2284 * @cpu: cpu index for the online cpu
2286 static void bnx2fc_percpu_thread_create(unsigned int cpu
)
2288 struct bnx2fc_percpu_s
*p
;
2289 struct task_struct
*thread
;
2291 p
= &per_cpu(bnx2fc_percpu
, cpu
);
2293 thread
= kthread_create(bnx2fc_percpu_io_thread
,
2295 "bnx2fc_thread/%d", cpu
);
2296 /* bind thread to the cpu */
2297 if (likely(!IS_ERR(thread
))) {
2298 kthread_bind(thread
, cpu
);
2299 p
->iothread
= thread
;
2300 wake_up_process(thread
);
2304 static void bnx2fc_percpu_thread_destroy(unsigned int cpu
)
2306 struct bnx2fc_percpu_s
*p
;
2307 struct task_struct
*thread
;
2308 struct bnx2fc_work
*work
, *tmp
;
2310 BNX2FC_MISC_DBG("destroying io thread for CPU %d\n", cpu
);
2312 /* Prevent any new work from being queued for this CPU */
2313 p
= &per_cpu(bnx2fc_percpu
, cpu
);
2314 spin_lock_bh(&p
->fp_work_lock
);
2315 thread
= p
->iothread
;
2319 /* Free all work in the list */
2320 list_for_each_entry_safe(work
, tmp
, &p
->work_list
, list
) {
2321 list_del_init(&work
->list
);
2322 bnx2fc_process_cq_compl(work
->tgt
, work
->wqe
);
2326 spin_unlock_bh(&p
->fp_work_lock
);
2329 kthread_stop(thread
);
2333 * bnx2fc_cpu_callback - Handler for CPU hotplug events
2335 * @nfb: The callback data block
2336 * @action: The event triggering the callback
2337 * @hcpu: The index of the CPU that the event is for
2339 * This creates or destroys per-CPU data for fcoe
2341 * Returns NOTIFY_OK always.
2343 static int bnx2fc_cpu_callback(struct notifier_block
*nfb
,
2344 unsigned long action
, void *hcpu
)
2346 unsigned cpu
= (unsigned long)hcpu
;
2350 case CPU_ONLINE_FROZEN
:
2351 printk(PFX
"CPU %x online: Create Rx thread\n", cpu
);
2352 bnx2fc_percpu_thread_create(cpu
);
2355 case CPU_DEAD_FROZEN
:
2356 printk(PFX
"CPU %x offline: Remove Rx thread\n", cpu
);
2357 bnx2fc_percpu_thread_destroy(cpu
);
2366 * bnx2fc_mod_init - module init entry point
2368 * Initialize driver wide global data structures, and register
2371 static int __init
bnx2fc_mod_init(void)
2373 struct fcoe_percpu_s
*bg
;
2374 struct task_struct
*l2_thread
;
2376 unsigned int cpu
= 0;
2377 struct bnx2fc_percpu_s
*p
;
2379 printk(KERN_INFO PFX
"%s", version
);
2381 /* register as a fcoe transport */
2382 rc
= fcoe_transport_attach(&bnx2fc_transport
);
2384 printk(KERN_ERR
"failed to register an fcoe transport, check "
2385 "if libfcoe is loaded\n");
2389 INIT_LIST_HEAD(&adapter_list
);
2390 INIT_LIST_HEAD(&if_list
);
2391 mutex_init(&bnx2fc_dev_lock
);
2394 /* Attach FC transport template */
2395 rc
= bnx2fc_attach_transport();
2399 bnx2fc_wq
= alloc_workqueue("bnx2fc", 0, 0);
2405 bg
= &bnx2fc_global
;
2406 skb_queue_head_init(&bg
->fcoe_rx_list
);
2407 l2_thread
= kthread_create(bnx2fc_l2_rcv_thread
,
2409 "bnx2fc_l2_thread");
2410 if (IS_ERR(l2_thread
)) {
2411 rc
= PTR_ERR(l2_thread
);
2414 wake_up_process(l2_thread
);
2415 spin_lock_bh(&bg
->fcoe_rx_list
.lock
);
2416 bg
->thread
= l2_thread
;
2417 spin_unlock_bh(&bg
->fcoe_rx_list
.lock
);
2419 for_each_possible_cpu(cpu
) {
2420 p
= &per_cpu(bnx2fc_percpu
, cpu
);
2421 INIT_LIST_HEAD(&p
->work_list
);
2422 spin_lock_init(&p
->fp_work_lock
);
2425 for_each_online_cpu(cpu
) {
2426 bnx2fc_percpu_thread_create(cpu
);
2429 /* Initialize per CPU interrupt thread */
2430 register_hotcpu_notifier(&bnx2fc_cpu_notifier
);
2432 cnic_register_driver(CNIC_ULP_FCOE
, &bnx2fc_cnic_cb
);
2437 destroy_workqueue(bnx2fc_wq
);
2439 bnx2fc_release_transport();
2441 fcoe_transport_detach(&bnx2fc_transport
);
2446 static void __exit
bnx2fc_mod_exit(void)
2448 LIST_HEAD(to_be_deleted
);
2449 struct bnx2fc_hba
*hba
, *next
;
2450 struct fcoe_percpu_s
*bg
;
2451 struct task_struct
*l2_thread
;
2452 struct sk_buff
*skb
;
2453 unsigned int cpu
= 0;
2456 * NOTE: Since cnic calls register_driver routine rtnl_lock,
2457 * it will have higher precedence than bnx2fc_dev_lock.
2458 * unregister_device() cannot be called with bnx2fc_dev_lock
2461 mutex_lock(&bnx2fc_dev_lock
);
2462 list_splice(&adapter_list
, &to_be_deleted
);
2463 INIT_LIST_HEAD(&adapter_list
);
2465 mutex_unlock(&bnx2fc_dev_lock
);
2467 /* Unregister with cnic */
2468 list_for_each_entry_safe(hba
, next
, &to_be_deleted
, list
) {
2469 list_del_init(&hba
->list
);
2470 printk(KERN_ERR PFX
"MOD_EXIT:destroy hba = 0x%p\n",
2472 bnx2fc_ulp_stop(hba
);
2473 /* unregister cnic device */
2474 if (test_and_clear_bit(BNX2FC_CNIC_REGISTERED
,
2475 &hba
->reg_with_cnic
))
2476 hba
->cnic
->unregister_device(hba
->cnic
,
2478 bnx2fc_hba_destroy(hba
);
2480 cnic_unregister_driver(CNIC_ULP_FCOE
);
2482 /* Destroy global thread */
2483 bg
= &bnx2fc_global
;
2484 spin_lock_bh(&bg
->fcoe_rx_list
.lock
);
2485 l2_thread
= bg
->thread
;
2487 while ((skb
= __skb_dequeue(&bg
->fcoe_rx_list
)) != NULL
)
2490 spin_unlock_bh(&bg
->fcoe_rx_list
.lock
);
2493 kthread_stop(l2_thread
);
2495 unregister_hotcpu_notifier(&bnx2fc_cpu_notifier
);
2497 /* Destroy per cpu threads */
2498 for_each_online_cpu(cpu
) {
2499 bnx2fc_percpu_thread_destroy(cpu
);
2502 destroy_workqueue(bnx2fc_wq
);
2504 * detach from scsi transport
2505 * must happen after all destroys are done
2507 bnx2fc_release_transport();
2509 /* detach from fcoe transport */
2510 fcoe_transport_detach(&bnx2fc_transport
);
2513 module_init(bnx2fc_mod_init
);
2514 module_exit(bnx2fc_mod_exit
);
2516 static struct fcoe_sysfs_function_template bnx2fc_fcoe_sysfs_templ
= {
2517 .get_fcoe_ctlr_mode
= fcoe_ctlr_get_fip_mode
,
2518 .get_fcoe_ctlr_link_fail
= bnx2fc_ctlr_get_lesb
,
2519 .get_fcoe_ctlr_vlink_fail
= bnx2fc_ctlr_get_lesb
,
2520 .get_fcoe_ctlr_miss_fka
= bnx2fc_ctlr_get_lesb
,
2521 .get_fcoe_ctlr_symb_err
= bnx2fc_ctlr_get_lesb
,
2522 .get_fcoe_ctlr_err_block
= bnx2fc_ctlr_get_lesb
,
2523 .get_fcoe_ctlr_fcs_error
= bnx2fc_ctlr_get_lesb
,
2525 .get_fcoe_fcf_selected
= fcoe_fcf_get_selected
,
2526 .get_fcoe_fcf_vlan_id
= bnx2fc_fcf_get_vlan_id
,
2529 static struct fc_function_template bnx2fc_transport_function
= {
2530 .show_host_node_name
= 1,
2531 .show_host_port_name
= 1,
2532 .show_host_supported_classes
= 1,
2533 .show_host_supported_fc4s
= 1,
2534 .show_host_active_fc4s
= 1,
2535 .show_host_maxframe_size
= 1,
2537 .show_host_port_id
= 1,
2538 .show_host_supported_speeds
= 1,
2539 .get_host_speed
= fc_get_host_speed
,
2540 .show_host_speed
= 1,
2541 .show_host_port_type
= 1,
2542 .get_host_port_state
= fc_get_host_port_state
,
2543 .show_host_port_state
= 1,
2544 .show_host_symbolic_name
= 1,
2546 .dd_fcrport_size
= (sizeof(struct fc_rport_libfc_priv
) +
2547 sizeof(struct bnx2fc_rport
)),
2548 .show_rport_maxframe_size
= 1,
2549 .show_rport_supported_classes
= 1,
2551 .show_host_fabric_name
= 1,
2552 .show_starget_node_name
= 1,
2553 .show_starget_port_name
= 1,
2554 .show_starget_port_id
= 1,
2555 .set_rport_dev_loss_tmo
= fc_set_rport_loss_tmo
,
2556 .show_rport_dev_loss_tmo
= 1,
2557 .get_fc_host_stats
= bnx2fc_get_host_stats
,
2559 .issue_fc_host_lip
= bnx2fc_fcoe_reset
,
2561 .terminate_rport_io
= fc_rport_terminate_io
,
2563 .vport_create
= bnx2fc_vport_create
,
2564 .vport_delete
= bnx2fc_vport_destroy
,
2565 .vport_disable
= bnx2fc_vport_disable
,
2566 .bsg_request
= fc_lport_bsg_request
,
2569 static struct fc_function_template bnx2fc_vport_xport_function
= {
2570 .show_host_node_name
= 1,
2571 .show_host_port_name
= 1,
2572 .show_host_supported_classes
= 1,
2573 .show_host_supported_fc4s
= 1,
2574 .show_host_active_fc4s
= 1,
2575 .show_host_maxframe_size
= 1,
2577 .show_host_port_id
= 1,
2578 .show_host_supported_speeds
= 1,
2579 .get_host_speed
= fc_get_host_speed
,
2580 .show_host_speed
= 1,
2581 .show_host_port_type
= 1,
2582 .get_host_port_state
= fc_get_host_port_state
,
2583 .show_host_port_state
= 1,
2584 .show_host_symbolic_name
= 1,
2586 .dd_fcrport_size
= (sizeof(struct fc_rport_libfc_priv
) +
2587 sizeof(struct bnx2fc_rport
)),
2588 .show_rport_maxframe_size
= 1,
2589 .show_rport_supported_classes
= 1,
2591 .show_host_fabric_name
= 1,
2592 .show_starget_node_name
= 1,
2593 .show_starget_port_name
= 1,
2594 .show_starget_port_id
= 1,
2595 .set_rport_dev_loss_tmo
= fc_set_rport_loss_tmo
,
2596 .show_rport_dev_loss_tmo
= 1,
2597 .get_fc_host_stats
= fc_get_host_stats
,
2598 .issue_fc_host_lip
= bnx2fc_fcoe_reset
,
2599 .terminate_rport_io
= fc_rport_terminate_io
,
2600 .bsg_request
= fc_lport_bsg_request
,
2604 * scsi_host_template structure used while registering with SCSI-ml
2606 static struct scsi_host_template bnx2fc_shost_template
= {
2607 .module
= THIS_MODULE
,
2608 .name
= "Broadcom Offload FCoE Initiator",
2609 .queuecommand
= bnx2fc_queuecommand
,
2610 .eh_abort_handler
= bnx2fc_eh_abort
, /* abts */
2611 .eh_device_reset_handler
= bnx2fc_eh_device_reset
, /* lun reset */
2612 .eh_target_reset_handler
= bnx2fc_eh_target_reset
, /* tgt reset */
2613 .eh_host_reset_handler
= fc_eh_host_reset
,
2614 .slave_alloc
= fc_slave_alloc
,
2615 .change_queue_depth
= fc_change_queue_depth
,
2616 .change_queue_type
= fc_change_queue_type
,
2619 .can_queue
= BNX2FC_CAN_QUEUE
,
2620 .use_clustering
= ENABLE_CLUSTERING
,
2621 .sg_tablesize
= BNX2FC_MAX_BDS_PER_CMD
,
2625 static struct libfc_function_template bnx2fc_libfc_fcn_templ
= {
2626 .frame_send
= bnx2fc_xmit
,
2627 .elsct_send
= bnx2fc_elsct_send
,
2628 .fcp_abort_io
= bnx2fc_abort_io
,
2629 .fcp_cleanup
= bnx2fc_cleanup
,
2630 .get_lesb
= bnx2fc_get_lesb
,
2631 .rport_event_callback
= bnx2fc_rport_event_handler
,
2635 * bnx2fc_cnic_cb - global template of bnx2fc - cnic driver interface
2636 * structure carrying callback function pointers
2638 static struct cnic_ulp_ops bnx2fc_cnic_cb
= {
2639 .owner
= THIS_MODULE
,
2640 .cnic_init
= bnx2fc_ulp_init
,
2641 .cnic_exit
= bnx2fc_ulp_exit
,
2642 .cnic_start
= bnx2fc_ulp_start
,
2643 .cnic_stop
= bnx2fc_ulp_stop
,
2644 .indicate_kcqes
= bnx2fc_indicate_kcqe
,
2645 .indicate_netevent
= bnx2fc_indicate_netevent
,