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 "Oct 21, 2011"
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 fc_function_template bnx2fc_vport_xport_function
;
58 static int bnx2fc_create(struct net_device
*netdev
, enum fip_state fip_mode
);
59 static void __bnx2fc_destroy(struct bnx2fc_interface
*interface
);
60 static int bnx2fc_destroy(struct net_device
*net_device
);
61 static int bnx2fc_enable(struct net_device
*netdev
);
62 static int bnx2fc_disable(struct net_device
*netdev
);
64 static void bnx2fc_recv_frame(struct sk_buff
*skb
);
66 static void bnx2fc_start_disc(struct bnx2fc_interface
*interface
);
67 static int bnx2fc_shost_config(struct fc_lport
*lport
, struct device
*dev
);
68 static int bnx2fc_lport_config(struct fc_lport
*lport
);
69 static int bnx2fc_em_config(struct fc_lport
*lport
);
70 static int bnx2fc_bind_adapter_devices(struct bnx2fc_hba
*hba
);
71 static void bnx2fc_unbind_adapter_devices(struct bnx2fc_hba
*hba
);
72 static int bnx2fc_bind_pcidev(struct bnx2fc_hba
*hba
);
73 static void bnx2fc_unbind_pcidev(struct bnx2fc_hba
*hba
);
74 static struct fc_lport
*bnx2fc_if_create(struct bnx2fc_interface
*interface
,
75 struct device
*parent
, int npiv
);
76 static void bnx2fc_destroy_work(struct work_struct
*work
);
78 static struct bnx2fc_hba
*bnx2fc_hba_lookup(struct net_device
*phys_dev
);
79 static struct bnx2fc_interface
*bnx2fc_interface_lookup(struct net_device
81 static inline void bnx2fc_interface_put(struct bnx2fc_interface
*interface
);
82 static struct bnx2fc_hba
*bnx2fc_find_hba_for_cnic(struct cnic_dev
*cnic
);
84 static int bnx2fc_fw_init(struct bnx2fc_hba
*hba
);
85 static void bnx2fc_fw_destroy(struct bnx2fc_hba
*hba
);
87 static void bnx2fc_port_shutdown(struct fc_lport
*lport
);
88 static void bnx2fc_stop(struct bnx2fc_interface
*interface
);
89 static int __init
bnx2fc_mod_init(void);
90 static void __exit
bnx2fc_mod_exit(void);
92 unsigned int bnx2fc_debug_level
;
93 module_param_named(debug_logging
, bnx2fc_debug_level
, int, S_IRUGO
|S_IWUSR
);
95 static int bnx2fc_cpu_callback(struct notifier_block
*nfb
,
96 unsigned long action
, void *hcpu
);
97 /* notification function for CPU hotplug events */
98 static struct notifier_block bnx2fc_cpu_notifier
= {
99 .notifier_call
= bnx2fc_cpu_callback
,
102 static inline struct net_device
*bnx2fc_netdev(const struct fc_lport
*lport
)
104 return ((struct bnx2fc_interface
*)
105 ((struct fcoe_port
*)lport_priv(lport
))->priv
)->netdev
;
109 * bnx2fc_get_lesb() - Fill the FCoE Link Error Status Block
110 * @lport: the local port
111 * @fc_lesb: the link error status block
113 static void bnx2fc_get_lesb(struct fc_lport
*lport
,
114 struct fc_els_lesb
*fc_lesb
)
116 struct net_device
*netdev
= bnx2fc_netdev(lport
);
118 __fcoe_get_lesb(lport
, fc_lesb
, netdev
);
121 static void bnx2fc_clean_rx_queue(struct fc_lport
*lp
)
123 struct fcoe_percpu_s
*bg
;
124 struct fcoe_rcv_info
*fr
;
125 struct sk_buff_head
*list
;
126 struct sk_buff
*skb
, *next
;
127 struct sk_buff
*head
;
130 spin_lock_bh(&bg
->fcoe_rx_list
.lock
);
131 list
= &bg
->fcoe_rx_list
;
133 for (skb
= head
; skb
!= (struct sk_buff
*)list
;
136 fr
= fcoe_dev_from_skb(skb
);
137 if (fr
->fr_dev
== lp
) {
138 __skb_unlink(skb
, list
);
142 spin_unlock_bh(&bg
->fcoe_rx_list
.lock
);
145 int bnx2fc_get_paged_crc_eof(struct sk_buff
*skb
, int tlen
)
148 spin_lock(&bnx2fc_global_lock
);
149 rc
= fcoe_get_paged_crc_eof(skb
, tlen
, &bnx2fc_global
);
150 spin_unlock(&bnx2fc_global_lock
);
155 static void bnx2fc_abort_io(struct fc_lport
*lport
)
158 * This function is no-op for bnx2fc, but we do
159 * not want to leave it as NULL either, as libfc
160 * can call the default function which is
165 static void bnx2fc_cleanup(struct fc_lport
*lport
)
167 struct fcoe_port
*port
= lport_priv(lport
);
168 struct bnx2fc_interface
*interface
= port
->priv
;
169 struct bnx2fc_hba
*hba
= interface
->hba
;
170 struct bnx2fc_rport
*tgt
;
173 BNX2FC_MISC_DBG("Entered %s\n", __func__
);
174 mutex_lock(&hba
->hba_mutex
);
175 spin_lock_bh(&hba
->hba_lock
);
176 for (i
= 0; i
< BNX2FC_NUM_MAX_SESS
; i
++) {
177 tgt
= hba
->tgt_ofld_list
[i
];
179 /* Cleanup IOs belonging to requested vport */
180 if (tgt
->port
== port
) {
181 spin_unlock_bh(&hba
->hba_lock
);
182 BNX2FC_TGT_DBG(tgt
, "flush/cleanup\n");
183 bnx2fc_flush_active_ios(tgt
);
184 spin_lock_bh(&hba
->hba_lock
);
188 spin_unlock_bh(&hba
->hba_lock
);
189 mutex_unlock(&hba
->hba_mutex
);
192 static int bnx2fc_xmit_l2_frame(struct bnx2fc_rport
*tgt
,
195 struct fc_rport_priv
*rdata
= tgt
->rdata
;
196 struct fc_frame_header
*fh
;
199 fh
= fc_frame_header_get(fp
);
200 BNX2FC_TGT_DBG(tgt
, "Xmit L2 frame rport = 0x%x, oxid = 0x%x, "
201 "r_ctl = 0x%x\n", rdata
->ids
.port_id
,
202 ntohs(fh
->fh_ox_id
), fh
->fh_r_ctl
);
203 if ((fh
->fh_type
== FC_TYPE_ELS
) &&
204 (fh
->fh_r_ctl
== FC_RCTL_ELS_REQ
)) {
206 switch (fc_frame_payload_op(fp
)) {
208 rc
= bnx2fc_send_adisc(tgt
, fp
);
211 rc
= bnx2fc_send_logo(tgt
, fp
);
214 rc
= bnx2fc_send_rls(tgt
, fp
);
219 } else if ((fh
->fh_type
== FC_TYPE_BLS
) &&
220 (fh
->fh_r_ctl
== FC_RCTL_BA_ABTS
))
221 BNX2FC_TGT_DBG(tgt
, "ABTS frame\n");
223 BNX2FC_TGT_DBG(tgt
, "Send L2 frame type 0x%x "
224 "rctl 0x%x thru non-offload path\n",
225 fh
->fh_type
, fh
->fh_r_ctl
);
235 * bnx2fc_xmit - bnx2fc's FCoE frame transmit function
237 * @lport: the associated local port
238 * @fp: the fc_frame to be transmitted
240 static int bnx2fc_xmit(struct fc_lport
*lport
, struct fc_frame
*fp
)
243 struct fcoe_crc_eof
*cp
;
245 struct fc_frame_header
*fh
;
246 struct bnx2fc_interface
*interface
;
247 struct bnx2fc_hba
*hba
;
248 struct fcoe_port
*port
;
250 struct bnx2fc_rport
*tgt
;
251 struct fcoe_dev_stats
*stats
;
254 unsigned int hlen
, tlen
, elen
;
257 port
= (struct fcoe_port
*)lport_priv(lport
);
258 interface
= port
->priv
;
259 hba
= interface
->hba
;
261 fh
= fc_frame_header_get(fp
);
264 if (!lport
->link_up
) {
265 BNX2FC_HBA_DBG(lport
, "bnx2fc_xmit link down\n");
270 if (unlikely(fh
->fh_r_ctl
== FC_RCTL_ELS_REQ
)) {
271 if (!interface
->ctlr
.sel_fcf
) {
272 BNX2FC_HBA_DBG(lport
, "FCF not selected yet!\n");
276 if (fcoe_ctlr_els_send(&interface
->ctlr
, lport
, skb
))
284 * Snoop the frame header to check if the frame is for
285 * an offloaded session
288 * tgt_ofld_list access is synchronized using
289 * both hba mutex and hba lock. Atleast hba mutex or
290 * hba lock needs to be held for read access.
293 spin_lock_bh(&hba
->hba_lock
);
294 tgt
= bnx2fc_tgt_lookup(port
, ntoh24(fh
->fh_d_id
));
295 if (tgt
&& (test_bit(BNX2FC_FLAG_SESSION_READY
, &tgt
->flags
))) {
296 /* This frame is for offloaded session */
297 BNX2FC_HBA_DBG(lport
, "xmit: Frame is for offloaded session "
298 "port_id = 0x%x\n", ntoh24(fh
->fh_d_id
));
299 spin_unlock_bh(&hba
->hba_lock
);
300 rc
= bnx2fc_xmit_l2_frame(tgt
, fp
);
306 spin_unlock_bh(&hba
->hba_lock
);
309 elen
= sizeof(struct ethhdr
);
310 hlen
= sizeof(struct fcoe_hdr
);
311 tlen
= sizeof(struct fcoe_crc_eof
);
312 wlen
= (skb
->len
- tlen
+ sizeof(crc
)) / FCOE_WORD_TO_BYTE
;
314 skb
->ip_summed
= CHECKSUM_NONE
;
315 crc
= fcoe_fc_crc(fp
);
317 /* copy port crc and eof to the skb buff */
318 if (skb_is_nonlinear(skb
)) {
320 if (bnx2fc_get_paged_crc_eof(skb
, tlen
)) {
324 frag
= &skb_shinfo(skb
)->frags
[skb_shinfo(skb
)->nr_frags
- 1];
325 cp
= kmap_atomic(skb_frag_page(frag
)) + frag
->page_offset
;
327 cp
= (struct fcoe_crc_eof
*)skb_put(skb
, tlen
);
330 memset(cp
, 0, sizeof(*cp
));
332 cp
->fcoe_crc32
= cpu_to_le32(~crc
);
333 if (skb_is_nonlinear(skb
)) {
338 /* adjust skb network/transport offsets to match mac/fcoe/port */
339 skb_push(skb
, elen
+ hlen
);
340 skb_reset_mac_header(skb
);
341 skb_reset_network_header(skb
);
343 skb
->protocol
= htons(ETH_P_FCOE
);
344 skb
->dev
= interface
->netdev
;
346 /* fill up mac and fcoe headers */
348 eh
->h_proto
= htons(ETH_P_FCOE
);
349 if (interface
->ctlr
.map_dest
)
350 fc_fcoe_set_mac(eh
->h_dest
, fh
->fh_d_id
);
352 /* insert GW address */
353 memcpy(eh
->h_dest
, interface
->ctlr
.dest_addr
, ETH_ALEN
);
355 if (unlikely(interface
->ctlr
.flogi_oxid
!= FC_XID_UNKNOWN
))
356 memcpy(eh
->h_source
, interface
->ctlr
.ctl_src_addr
, ETH_ALEN
);
358 memcpy(eh
->h_source
, port
->data_src_addr
, ETH_ALEN
);
360 hp
= (struct fcoe_hdr
*)(eh
+ 1);
361 memset(hp
, 0, sizeof(*hp
));
363 FC_FCOE_ENCAPS_VER(hp
, FC_FCOE_VER
);
366 /* fcoe lso, mss is in max_payload which is non-zero for FCP data */
367 if (lport
->seq_offload
&& fr_max_payload(fp
)) {
368 skb_shinfo(skb
)->gso_type
= SKB_GSO_FCOE
;
369 skb_shinfo(skb
)->gso_size
= fr_max_payload(fp
);
371 skb_shinfo(skb
)->gso_type
= 0;
372 skb_shinfo(skb
)->gso_size
= 0;
376 stats
= per_cpu_ptr(lport
->dev_stats
, get_cpu());
378 stats
->TxWords
+= wlen
;
381 /* send down to lld */
383 if (port
->fcoe_pending_queue
.qlen
)
384 fcoe_check_wait_queue(lport
, skb
);
385 else if (fcoe_start_io(skb
))
386 fcoe_check_wait_queue(lport
, skb
);
392 * bnx2fc_rcv - This is bnx2fc's receive function called by NET_RX_SOFTIRQ
394 * @skb: the receive socket buffer
395 * @dev: associated net device
397 * @olddev: last device
399 * This function receives the packet and builds FC frame and passes it up
401 static int bnx2fc_rcv(struct sk_buff
*skb
, struct net_device
*dev
,
402 struct packet_type
*ptype
, struct net_device
*olddev
)
404 struct fc_lport
*lport
;
405 struct bnx2fc_interface
*interface
;
406 struct fc_frame_header
*fh
;
407 struct fcoe_rcv_info
*fr
;
408 struct fcoe_percpu_s
*bg
;
411 interface
= container_of(ptype
, struct bnx2fc_interface
,
413 lport
= interface
->ctlr
.lp
;
415 if (unlikely(lport
== NULL
)) {
416 printk(KERN_ERR PFX
"bnx2fc_rcv: lport is NULL\n");
420 if (unlikely(eth_hdr(skb
)->h_proto
!= htons(ETH_P_FCOE
))) {
421 printk(KERN_ERR PFX
"bnx2fc_rcv: Wrong FC type frame\n");
426 * Check for minimum frame length, and make sure required FCoE
427 * and FC headers are pulled into the linear data area.
429 if (unlikely((skb
->len
< FCOE_MIN_FRAME
) ||
430 !pskb_may_pull(skb
, FCOE_HEADER_LEN
)))
433 skb_set_transport_header(skb
, sizeof(struct fcoe_hdr
));
434 fh
= (struct fc_frame_header
*) skb_transport_header(skb
);
436 oxid
= ntohs(fh
->fh_ox_id
);
438 fr
= fcoe_dev_from_skb(skb
);
442 spin_lock_bh(&bg
->fcoe_rx_list
.lock
);
444 __skb_queue_tail(&bg
->fcoe_rx_list
, skb
);
445 if (bg
->fcoe_rx_list
.qlen
== 1)
446 wake_up_process(bg
->thread
);
448 spin_unlock_bh(&bg
->fcoe_rx_list
.lock
);
456 static int bnx2fc_l2_rcv_thread(void *arg
)
458 struct fcoe_percpu_s
*bg
= arg
;
461 set_user_nice(current
, -20);
462 set_current_state(TASK_INTERRUPTIBLE
);
463 while (!kthread_should_stop()) {
465 spin_lock_bh(&bg
->fcoe_rx_list
.lock
);
466 while ((skb
= __skb_dequeue(&bg
->fcoe_rx_list
)) != NULL
) {
467 spin_unlock_bh(&bg
->fcoe_rx_list
.lock
);
468 bnx2fc_recv_frame(skb
);
469 spin_lock_bh(&bg
->fcoe_rx_list
.lock
);
471 __set_current_state(TASK_INTERRUPTIBLE
);
472 spin_unlock_bh(&bg
->fcoe_rx_list
.lock
);
474 __set_current_state(TASK_RUNNING
);
479 static void bnx2fc_recv_frame(struct sk_buff
*skb
)
482 struct fc_lport
*lport
;
483 struct fcoe_rcv_info
*fr
;
484 struct fcoe_dev_stats
*stats
;
485 struct fc_frame_header
*fh
;
486 struct fcoe_crc_eof crc_eof
;
488 struct fc_lport
*vn_port
;
489 struct fcoe_port
*port
;
494 fr
= fcoe_dev_from_skb(skb
);
496 if (unlikely(lport
== NULL
)) {
497 printk(KERN_ERR PFX
"Invalid lport struct\n");
502 if (skb_is_nonlinear(skb
))
504 mac
= eth_hdr(skb
)->h_source
;
505 dest_mac
= eth_hdr(skb
)->h_dest
;
507 /* Pull the header */
508 hp
= (struct fcoe_hdr
*) skb_network_header(skb
);
509 fh
= (struct fc_frame_header
*) skb_transport_header(skb
);
510 skb_pull(skb
, sizeof(struct fcoe_hdr
));
511 fr_len
= skb
->len
- sizeof(struct fcoe_crc_eof
);
513 stats
= per_cpu_ptr(lport
->dev_stats
, get_cpu());
515 stats
->RxWords
+= fr_len
/ FCOE_WORD_TO_BYTE
;
517 fp
= (struct fc_frame
*)skb
;
520 fr_sof(fp
) = hp
->fcoe_sof
;
521 if (skb_copy_bits(skb
, fr_len
, &crc_eof
, sizeof(crc_eof
))) {
526 fr_eof(fp
) = crc_eof
.fcoe_eof
;
527 fr_crc(fp
) = crc_eof
.fcoe_crc32
;
528 if (pskb_trim(skb
, fr_len
)) {
534 fh
= fc_frame_header_get(fp
);
536 vn_port
= fc_vport_id_lookup(lport
, ntoh24(fh
->fh_d_id
));
538 port
= lport_priv(vn_port
);
539 if (compare_ether_addr(port
->data_src_addr
, dest_mac
)
541 BNX2FC_HBA_DBG(lport
, "fpma mismatch\n");
547 if (fh
->fh_r_ctl
== FC_RCTL_DD_SOL_DATA
&&
548 fh
->fh_type
== FC_TYPE_FCP
) {
549 /* Drop FCP data. We dont this in L2 path */
554 if (fh
->fh_r_ctl
== FC_RCTL_ELS_REQ
&&
555 fh
->fh_type
== FC_TYPE_ELS
) {
556 switch (fc_frame_payload_op(fp
)) {
558 if (ntoh24(fh
->fh_s_id
) == FC_FID_FLOGI
) {
559 /* drop non-FIP LOGO */
568 if (fh
->fh_r_ctl
== FC_RCTL_BA_ABTS
) {
569 /* Drop incoming ABTS */
575 if (le32_to_cpu(fr_crc(fp
)) !=
576 ~crc32(~0, skb
->data
, fr_len
)) {
577 if (stats
->InvalidCRCCount
< 5)
578 printk(KERN_WARNING PFX
"dropping frame with "
580 stats
->InvalidCRCCount
++;
586 fc_exch_recv(lport
, fp
);
590 * bnx2fc_percpu_io_thread - thread per cpu for ios
592 * @arg: ptr to bnx2fc_percpu_info structure
594 int bnx2fc_percpu_io_thread(void *arg
)
596 struct bnx2fc_percpu_s
*p
= arg
;
597 struct bnx2fc_work
*work
, *tmp
;
598 LIST_HEAD(work_list
);
600 set_user_nice(current
, -20);
601 set_current_state(TASK_INTERRUPTIBLE
);
602 while (!kthread_should_stop()) {
604 spin_lock_bh(&p
->fp_work_lock
);
605 while (!list_empty(&p
->work_list
)) {
606 list_splice_init(&p
->work_list
, &work_list
);
607 spin_unlock_bh(&p
->fp_work_lock
);
609 list_for_each_entry_safe(work
, tmp
, &work_list
, list
) {
610 list_del_init(&work
->list
);
611 bnx2fc_process_cq_compl(work
->tgt
, work
->wqe
);
615 spin_lock_bh(&p
->fp_work_lock
);
617 __set_current_state(TASK_INTERRUPTIBLE
);
618 spin_unlock_bh(&p
->fp_work_lock
);
620 __set_current_state(TASK_RUNNING
);
625 static struct fc_host_statistics
*bnx2fc_get_host_stats(struct Scsi_Host
*shost
)
627 struct fc_host_statistics
*bnx2fc_stats
;
628 struct fc_lport
*lport
= shost_priv(shost
);
629 struct fcoe_port
*port
= lport_priv(lport
);
630 struct bnx2fc_interface
*interface
= port
->priv
;
631 struct bnx2fc_hba
*hba
= interface
->hba
;
632 struct fcoe_statistics_params
*fw_stats
;
635 fw_stats
= (struct fcoe_statistics_params
*)hba
->stats_buffer
;
639 bnx2fc_stats
= fc_get_host_stats(shost
);
641 init_completion(&hba
->stat_req_done
);
642 if (bnx2fc_send_stat_req(hba
))
644 rc
= wait_for_completion_timeout(&hba
->stat_req_done
, (2 * HZ
));
646 BNX2FC_HBA_DBG(lport
, "FW stat req timed out\n");
649 bnx2fc_stats
->invalid_crc_count
+= fw_stats
->rx_stat2
.fc_crc_cnt
;
650 bnx2fc_stats
->tx_frames
+= fw_stats
->tx_stat
.fcoe_tx_pkt_cnt
;
651 bnx2fc_stats
->tx_words
+= (fw_stats
->tx_stat
.fcoe_tx_byte_cnt
) / 4;
652 bnx2fc_stats
->rx_frames
+= fw_stats
->rx_stat0
.fcoe_rx_pkt_cnt
;
653 bnx2fc_stats
->rx_words
+= (fw_stats
->rx_stat0
.fcoe_rx_byte_cnt
) / 4;
655 bnx2fc_stats
->dumped_frames
= 0;
656 bnx2fc_stats
->lip_count
= 0;
657 bnx2fc_stats
->nos_count
= 0;
658 bnx2fc_stats
->loss_of_sync_count
= 0;
659 bnx2fc_stats
->loss_of_signal_count
= 0;
660 bnx2fc_stats
->prim_seq_protocol_err_count
= 0;
665 static int bnx2fc_shost_config(struct fc_lport
*lport
, struct device
*dev
)
667 struct fcoe_port
*port
= lport_priv(lport
);
668 struct bnx2fc_interface
*interface
= port
->priv
;
669 struct Scsi_Host
*shost
= lport
->host
;
672 shost
->max_cmd_len
= BNX2FC_MAX_CMD_LEN
;
673 shost
->max_lun
= BNX2FC_MAX_LUN
;
674 shost
->max_id
= BNX2FC_MAX_FCP_TGT
;
675 shost
->max_channel
= 0;
677 shost
->transportt
= bnx2fc_vport_xport_template
;
679 shost
->transportt
= bnx2fc_transport_template
;
681 /* Add the new host to SCSI-ml */
682 rc
= scsi_add_host(lport
->host
, dev
);
684 printk(KERN_ERR PFX
"Error on scsi_add_host\n");
688 fc_host_max_npiv_vports(lport
->host
) = USHRT_MAX
;
689 sprintf(fc_host_symbolic_name(lport
->host
), "%s v%s over %s",
690 BNX2FC_NAME
, BNX2FC_VERSION
,
691 interface
->netdev
->name
);
696 static void bnx2fc_link_speed_update(struct fc_lport
*lport
)
698 struct fcoe_port
*port
= lport_priv(lport
);
699 struct bnx2fc_interface
*interface
= port
->priv
;
700 struct net_device
*netdev
= interface
->netdev
;
701 struct ethtool_cmd ecmd
;
703 if (!__ethtool_get_settings(netdev
, &ecmd
)) {
704 lport
->link_supported_speeds
&=
705 ~(FC_PORTSPEED_1GBIT
| FC_PORTSPEED_10GBIT
);
706 if (ecmd
.supported
& (SUPPORTED_1000baseT_Half
|
707 SUPPORTED_1000baseT_Full
))
708 lport
->link_supported_speeds
|= FC_PORTSPEED_1GBIT
;
709 if (ecmd
.supported
& SUPPORTED_10000baseT_Full
)
710 lport
->link_supported_speeds
|= FC_PORTSPEED_10GBIT
;
712 switch (ethtool_cmd_speed(&ecmd
)) {
714 lport
->link_speed
= FC_PORTSPEED_1GBIT
;
717 lport
->link_speed
= FC_PORTSPEED_2GBIT
;
720 lport
->link_speed
= FC_PORTSPEED_10GBIT
;
725 static int bnx2fc_link_ok(struct fc_lport
*lport
)
727 struct fcoe_port
*port
= lport_priv(lport
);
728 struct bnx2fc_interface
*interface
= port
->priv
;
729 struct bnx2fc_hba
*hba
= interface
->hba
;
730 struct net_device
*dev
= hba
->phys_dev
;
733 if ((dev
->flags
& IFF_UP
) && netif_carrier_ok(dev
))
734 clear_bit(ADAPTER_STATE_LINK_DOWN
, &hba
->adapter_state
);
736 set_bit(ADAPTER_STATE_LINK_DOWN
, &hba
->adapter_state
);
743 * bnx2fc_get_link_state - get network link state
745 * @hba: adapter instance pointer
747 * updates adapter structure flag based on netdev state
749 void bnx2fc_get_link_state(struct bnx2fc_hba
*hba
)
751 if (test_bit(__LINK_STATE_NOCARRIER
, &hba
->phys_dev
->state
))
752 set_bit(ADAPTER_STATE_LINK_DOWN
, &hba
->adapter_state
);
754 clear_bit(ADAPTER_STATE_LINK_DOWN
, &hba
->adapter_state
);
757 static int bnx2fc_net_config(struct fc_lport
*lport
, struct net_device
*netdev
)
759 struct bnx2fc_hba
*hba
;
760 struct bnx2fc_interface
*interface
;
761 struct fcoe_port
*port
;
764 port
= lport_priv(lport
);
765 interface
= port
->priv
;
766 hba
= interface
->hba
;
768 /* require support for get_pauseparam ethtool op. */
769 if (!hba
->phys_dev
->ethtool_ops
||
770 !hba
->phys_dev
->ethtool_ops
->get_pauseparam
)
773 if (fc_set_mfs(lport
, BNX2FC_MFS
))
776 skb_queue_head_init(&port
->fcoe_pending_queue
);
777 port
->fcoe_pending_queue_active
= 0;
778 setup_timer(&port
->timer
, fcoe_queue_timer
, (unsigned long) lport
);
780 bnx2fc_link_speed_update(lport
);
783 if (fcoe_get_wwn(netdev
, &wwnn
, NETDEV_FCOE_WWNN
))
784 wwnn
= fcoe_wwn_from_mac(interface
->ctlr
.ctl_src_addr
,
786 BNX2FC_HBA_DBG(lport
, "WWNN = 0x%llx\n", wwnn
);
787 fc_set_wwnn(lport
, wwnn
);
789 if (fcoe_get_wwn(netdev
, &wwpn
, NETDEV_FCOE_WWPN
))
790 wwpn
= fcoe_wwn_from_mac(interface
->ctlr
.ctl_src_addr
,
793 BNX2FC_HBA_DBG(lport
, "WWPN = 0x%llx\n", wwpn
);
794 fc_set_wwpn(lport
, wwpn
);
800 static void bnx2fc_destroy_timer(unsigned long data
)
802 struct bnx2fc_hba
*hba
= (struct bnx2fc_hba
*)data
;
804 printk(KERN_ERR PFX
"ERROR:bnx2fc_destroy_timer - "
805 "Destroy compl not received!!\n");
806 set_bit(BNX2FC_FLAG_DESTROY_CMPL
, &hba
->flags
);
807 wake_up_interruptible(&hba
->destroy_wait
);
811 * bnx2fc_indicate_netevent - Generic netdev event handler
813 * @context: adapter structure pointer
815 * @vlan_id: vlan id - associated vlan id with this event
817 * Handles NETDEV_UP, NETDEV_DOWN, NETDEV_GOING_DOWN,NETDEV_CHANGE and
818 * NETDEV_CHANGE_MTU events. Handle NETDEV_UNREGISTER only for vlans.
820 static void bnx2fc_indicate_netevent(void *context
, unsigned long event
,
823 struct bnx2fc_hba
*hba
= (struct bnx2fc_hba
*)context
;
824 struct fc_lport
*lport
;
825 struct fc_lport
*vport
;
826 struct bnx2fc_interface
*interface
, *tmp
;
827 int wait_for_upload
= 0;
828 u32 link_possible
= 1;
830 if (vlan_id
!= 0 && event
!= NETDEV_UNREGISTER
)
835 if (!test_bit(ADAPTER_STATE_UP
, &hba
->adapter_state
))
836 printk(KERN_ERR
"indicate_netevent: "\
837 "hba is not UP!!\n");
841 clear_bit(ADAPTER_STATE_GOING_DOWN
, &hba
->adapter_state
);
842 clear_bit(ADAPTER_STATE_UP
, &hba
->adapter_state
);
846 case NETDEV_GOING_DOWN
:
847 set_bit(ADAPTER_STATE_GOING_DOWN
, &hba
->adapter_state
);
854 case NETDEV_UNREGISTER
:
857 mutex_lock(&bnx2fc_dev_lock
);
858 list_for_each_entry_safe(interface
, tmp
, &if_list
, list
) {
859 if (interface
->hba
== hba
&&
860 interface
->vlan_id
== (vlan_id
& VLAN_VID_MASK
))
861 __bnx2fc_destroy(interface
);
863 mutex_unlock(&bnx2fc_dev_lock
);
867 printk(KERN_ERR PFX
"Unkonwn netevent %ld", event
);
871 mutex_lock(&bnx2fc_dev_lock
);
872 list_for_each_entry(interface
, &if_list
, list
) {
874 if (interface
->hba
!= hba
)
877 lport
= interface
->ctlr
.lp
;
878 BNX2FC_HBA_DBG(lport
, "netevent handler - event=%s %ld\n",
879 interface
->netdev
->name
, event
);
881 bnx2fc_link_speed_update(lport
);
883 if (link_possible
&& !bnx2fc_link_ok(lport
)) {
884 /* Reset max recv frame size to default */
885 fc_set_mfs(lport
, BNX2FC_MFS
);
887 * ctlr link up will only be handled during
888 * enable to avoid sending discovery solicitation
891 if (interface
->enabled
)
892 fcoe_ctlr_link_up(&interface
->ctlr
);
893 } else if (fcoe_ctlr_link_down(&interface
->ctlr
)) {
894 mutex_lock(&lport
->lp_mutex
);
895 list_for_each_entry(vport
, &lport
->vports
, list
)
896 fc_host_port_type(vport
->host
) =
898 mutex_unlock(&lport
->lp_mutex
);
899 fc_host_port_type(lport
->host
) = FC_PORTTYPE_UNKNOWN
;
900 per_cpu_ptr(lport
->dev_stats
,
901 get_cpu())->LinkFailureCount
++;
903 fcoe_clean_pending_queue(lport
);
907 mutex_unlock(&bnx2fc_dev_lock
);
909 if (wait_for_upload
) {
910 clear_bit(ADAPTER_STATE_READY
, &hba
->adapter_state
);
911 init_waitqueue_head(&hba
->shutdown_wait
);
912 BNX2FC_MISC_DBG("indicate_netevent "
913 "num_ofld_sess = %d\n",
915 hba
->wait_for_link_down
= 1;
916 wait_event_interruptible(hba
->shutdown_wait
,
917 (hba
->num_ofld_sess
== 0));
918 BNX2FC_MISC_DBG("wakeup - num_ofld_sess = %d\n",
920 hba
->wait_for_link_down
= 0;
922 if (signal_pending(current
))
923 flush_signals(current
);
927 static int bnx2fc_libfc_config(struct fc_lport
*lport
)
930 /* Set the function pointers set by bnx2fc driver */
931 memcpy(&lport
->tt
, &bnx2fc_libfc_fcn_templ
,
932 sizeof(struct libfc_function_template
));
933 fc_elsct_init(lport
);
935 fc_rport_init(lport
);
940 static int bnx2fc_em_config(struct fc_lport
*lport
)
942 if (!fc_exch_mgr_alloc(lport
, FC_CLASS_3
, FCOE_MIN_XID
,
943 FCOE_MAX_XID
, NULL
)) {
944 printk(KERN_ERR PFX
"em_config:fc_exch_mgr_alloc failed\n");
951 static int bnx2fc_lport_config(struct fc_lport
*lport
)
955 lport
->max_retry_count
= 3;
956 lport
->max_rport_retry_count
= 3;
957 lport
->e_d_tov
= 2 * 1000;
958 lport
->r_a_tov
= 10 * 1000;
960 lport
->service_params
= (FCP_SPPF_INIT_FCN
| FCP_SPPF_RD_XRDY_DIS
|
961 FCP_SPPF_RETRY
| FCP_SPPF_CONF_COMPL
);
962 lport
->does_npiv
= 1;
964 memset(&lport
->rnid_gen
, 0, sizeof(struct fc_els_rnid_gen
));
965 lport
->rnid_gen
.rnid_atype
= BNX2FC_RNID_HBA
;
967 /* alloc stats structure */
968 if (fc_lport_init_stats(lport
))
971 /* Finish fc_lport configuration */
972 fc_lport_config(lport
);
978 * bnx2fc_fip_recv - handle a received FIP frame.
980 * @skb: the received skb
981 * @dev: associated &net_device
982 * @ptype: the &packet_type structure which was used to register this handler.
983 * @orig_dev: original receive &net_device, in case @ dev is a bond.
985 * Returns: 0 for success
987 static int bnx2fc_fip_recv(struct sk_buff
*skb
, struct net_device
*dev
,
988 struct packet_type
*ptype
,
989 struct net_device
*orig_dev
)
991 struct bnx2fc_interface
*interface
;
992 interface
= container_of(ptype
, struct bnx2fc_interface
,
994 fcoe_ctlr_recv(&interface
->ctlr
, skb
);
999 * bnx2fc_update_src_mac - Update Ethernet MAC filters.
1001 * @fip: FCoE controller.
1002 * @old: Unicast MAC address to delete if the MAC is non-zero.
1003 * @new: Unicast MAC address to add.
1005 * Remove any previously-set unicast MAC filter.
1006 * Add secondary FCoE MAC address filter for our OUI.
1008 static void bnx2fc_update_src_mac(struct fc_lport
*lport
, u8
*addr
)
1010 struct fcoe_port
*port
= lport_priv(lport
);
1012 memcpy(port
->data_src_addr
, addr
, ETH_ALEN
);
1016 * bnx2fc_get_src_mac - return the ethernet source address for an lport
1018 * @lport: libfc port
1020 static u8
*bnx2fc_get_src_mac(struct fc_lport
*lport
)
1022 struct fcoe_port
*port
;
1024 port
= (struct fcoe_port
*)lport_priv(lport
);
1025 return port
->data_src_addr
;
1029 * bnx2fc_fip_send - send an Ethernet-encapsulated FIP frame.
1031 * @fip: FCoE controller.
1034 static void bnx2fc_fip_send(struct fcoe_ctlr
*fip
, struct sk_buff
*skb
)
1036 skb
->dev
= bnx2fc_from_ctlr(fip
)->netdev
;
1037 dev_queue_xmit(skb
);
1040 static int bnx2fc_vport_create(struct fc_vport
*vport
, bool disabled
)
1042 struct Scsi_Host
*shost
= vport_to_shost(vport
);
1043 struct fc_lport
*n_port
= shost_priv(shost
);
1044 struct fcoe_port
*port
= lport_priv(n_port
);
1045 struct bnx2fc_interface
*interface
= port
->priv
;
1046 struct net_device
*netdev
= interface
->netdev
;
1047 struct fc_lport
*vn_port
;
1051 rc
= fcoe_validate_vport_create(vport
);
1053 fcoe_wwn_to_str(vport
->port_name
, buf
, sizeof(buf
));
1054 printk(KERN_ERR PFX
"Failed to create vport, "
1055 "WWPN (0x%s) already exists\n",
1060 if (!test_bit(BNX2FC_FLAG_FW_INIT_DONE
, &interface
->hba
->flags
)) {
1061 printk(KERN_ERR PFX
"vn ports cannot be created on"
1062 "this interface\n");
1066 mutex_lock(&bnx2fc_dev_lock
);
1067 vn_port
= bnx2fc_if_create(interface
, &vport
->dev
, 1);
1068 mutex_unlock(&bnx2fc_dev_lock
);
1071 if (IS_ERR(vn_port
)) {
1072 printk(KERN_ERR PFX
"bnx2fc_vport_create (%s) failed\n",
1078 fc_vport_set_state(vport
, FC_VPORT_DISABLED
);
1080 vn_port
->boot_time
= jiffies
;
1081 fc_lport_init(vn_port
);
1082 fc_fabric_login(vn_port
);
1083 fc_vport_setlink(vn_port
);
1088 static void bnx2fc_free_vport(struct bnx2fc_hba
*hba
, struct fc_lport
*lport
)
1090 struct bnx2fc_lport
*blport
, *tmp
;
1092 spin_lock_bh(&hba
->hba_lock
);
1093 list_for_each_entry_safe(blport
, tmp
, &hba
->vports
, list
) {
1094 if (blport
->lport
== lport
) {
1095 list_del(&blport
->list
);
1099 spin_unlock_bh(&hba
->hba_lock
);
1102 static int bnx2fc_vport_destroy(struct fc_vport
*vport
)
1104 struct Scsi_Host
*shost
= vport_to_shost(vport
);
1105 struct fc_lport
*n_port
= shost_priv(shost
);
1106 struct fc_lport
*vn_port
= vport
->dd_data
;
1107 struct fcoe_port
*port
= lport_priv(vn_port
);
1108 struct bnx2fc_interface
*interface
= port
->priv
;
1109 struct fc_lport
*v_port
;
1112 mutex_lock(&n_port
->lp_mutex
);
1113 list_for_each_entry(v_port
, &n_port
->vports
, list
)
1114 if (v_port
->vport
== vport
) {
1120 mutex_unlock(&n_port
->lp_mutex
);
1123 list_del(&vn_port
->list
);
1124 mutex_unlock(&n_port
->lp_mutex
);
1125 bnx2fc_free_vport(interface
->hba
, port
->lport
);
1126 bnx2fc_port_shutdown(port
->lport
);
1127 bnx2fc_interface_put(interface
);
1128 queue_work(bnx2fc_wq
, &port
->destroy_work
);
1132 static int bnx2fc_vport_disable(struct fc_vport
*vport
, bool disable
)
1134 struct fc_lport
*lport
= vport
->dd_data
;
1137 fc_vport_set_state(vport
, FC_VPORT_DISABLED
);
1138 fc_fabric_logoff(lport
);
1140 lport
->boot_time
= jiffies
;
1141 fc_fabric_login(lport
);
1142 fc_vport_setlink(lport
);
1148 static int bnx2fc_interface_setup(struct bnx2fc_interface
*interface
)
1150 struct net_device
*netdev
= interface
->netdev
;
1151 struct net_device
*physdev
= interface
->hba
->phys_dev
;
1152 struct netdev_hw_addr
*ha
;
1153 int sel_san_mac
= 0;
1155 /* setup Source MAC Address */
1157 for_each_dev_addr(physdev
, ha
) {
1158 BNX2FC_MISC_DBG("net_config: ha->type = %d, fip_mac = ",
1160 printk(KERN_INFO
"%2x:%2x:%2x:%2x:%2x:%2x\n", ha
->addr
[0],
1161 ha
->addr
[1], ha
->addr
[2], ha
->addr
[3],
1162 ha
->addr
[4], ha
->addr
[5]);
1164 if ((ha
->type
== NETDEV_HW_ADDR_T_SAN
) &&
1165 (is_valid_ether_addr(ha
->addr
))) {
1166 memcpy(interface
->ctlr
.ctl_src_addr
, ha
->addr
,
1169 BNX2FC_MISC_DBG("Found SAN MAC\n");
1177 interface
->fip_packet_type
.func
= bnx2fc_fip_recv
;
1178 interface
->fip_packet_type
.type
= htons(ETH_P_FIP
);
1179 interface
->fip_packet_type
.dev
= netdev
;
1180 dev_add_pack(&interface
->fip_packet_type
);
1182 interface
->fcoe_packet_type
.func
= bnx2fc_rcv
;
1183 interface
->fcoe_packet_type
.type
= __constant_htons(ETH_P_FCOE
);
1184 interface
->fcoe_packet_type
.dev
= netdev
;
1185 dev_add_pack(&interface
->fcoe_packet_type
);
1190 static int bnx2fc_attach_transport(void)
1192 bnx2fc_transport_template
=
1193 fc_attach_transport(&bnx2fc_transport_function
);
1195 if (bnx2fc_transport_template
== NULL
) {
1196 printk(KERN_ERR PFX
"Failed to attach FC transport\n");
1200 bnx2fc_vport_xport_template
=
1201 fc_attach_transport(&bnx2fc_vport_xport_function
);
1202 if (bnx2fc_vport_xport_template
== NULL
) {
1204 "Failed to attach FC transport for vport\n");
1205 fc_release_transport(bnx2fc_transport_template
);
1206 bnx2fc_transport_template
= NULL
;
1211 static void bnx2fc_release_transport(void)
1213 fc_release_transport(bnx2fc_transport_template
);
1214 fc_release_transport(bnx2fc_vport_xport_template
);
1215 bnx2fc_transport_template
= NULL
;
1216 bnx2fc_vport_xport_template
= NULL
;
1219 static void bnx2fc_interface_release(struct kref
*kref
)
1221 struct bnx2fc_interface
*interface
;
1222 struct net_device
*netdev
;
1224 interface
= container_of(kref
, struct bnx2fc_interface
, kref
);
1225 BNX2FC_MISC_DBG("Interface is being released\n");
1227 netdev
= interface
->netdev
;
1229 /* tear-down FIP controller */
1230 if (test_and_clear_bit(BNX2FC_CTLR_INIT_DONE
, &interface
->if_flags
))
1231 fcoe_ctlr_destroy(&interface
->ctlr
);
1236 module_put(THIS_MODULE
);
1239 static inline void bnx2fc_interface_get(struct bnx2fc_interface
*interface
)
1241 kref_get(&interface
->kref
);
1244 static inline void bnx2fc_interface_put(struct bnx2fc_interface
*interface
)
1246 kref_put(&interface
->kref
, bnx2fc_interface_release
);
1248 static void bnx2fc_hba_destroy(struct bnx2fc_hba
*hba
)
1250 /* Free the command manager */
1252 bnx2fc_cmd_mgr_free(hba
->cmd_mgr
);
1253 hba
->cmd_mgr
= NULL
;
1255 kfree(hba
->tgt_ofld_list
);
1256 bnx2fc_unbind_pcidev(hba
);
1261 * bnx2fc_hba_create - create a new bnx2fc hba
1263 * @cnic: pointer to cnic device
1265 * Creates a new FCoE hba on the given device.
1268 static struct bnx2fc_hba
*bnx2fc_hba_create(struct cnic_dev
*cnic
)
1270 struct bnx2fc_hba
*hba
;
1273 hba
= kzalloc(sizeof(*hba
), GFP_KERNEL
);
1275 printk(KERN_ERR PFX
"Unable to allocate hba structure\n");
1278 spin_lock_init(&hba
->hba_lock
);
1279 mutex_init(&hba
->hba_mutex
);
1282 rc
= bnx2fc_bind_pcidev(hba
);
1284 printk(KERN_ERR PFX
"create_adapter: bind error\n");
1287 hba
->phys_dev
= cnic
->netdev
;
1288 hba
->next_conn_id
= 0;
1290 hba
->tgt_ofld_list
=
1291 kzalloc(sizeof(struct bnx2fc_rport
*) * BNX2FC_NUM_MAX_SESS
,
1293 if (!hba
->tgt_ofld_list
) {
1294 printk(KERN_ERR PFX
"Unable to allocate tgt offload list\n");
1298 hba
->num_ofld_sess
= 0;
1300 hba
->cmd_mgr
= bnx2fc_cmd_mgr_alloc(hba
, BNX2FC_MIN_XID
,
1302 if (!hba
->cmd_mgr
) {
1303 printk(KERN_ERR PFX
"em_config:bnx2fc_cmd_mgr_alloc failed\n");
1307 init_waitqueue_head(&hba
->shutdown_wait
);
1308 init_waitqueue_head(&hba
->destroy_wait
);
1309 INIT_LIST_HEAD(&hba
->vports
);
1314 kfree(hba
->tgt_ofld_list
);
1316 bnx2fc_unbind_pcidev(hba
);
1322 struct bnx2fc_interface
*bnx2fc_interface_create(struct bnx2fc_hba
*hba
,
1323 struct net_device
*netdev
,
1324 enum fip_state fip_mode
)
1326 struct bnx2fc_interface
*interface
;
1329 interface
= kzalloc(sizeof(*interface
), GFP_KERNEL
);
1331 printk(KERN_ERR PFX
"Unable to allocate interface structure\n");
1335 kref_init(&interface
->kref
);
1336 interface
->hba
= hba
;
1337 interface
->netdev
= netdev
;
1339 /* Initialize FIP */
1340 fcoe_ctlr_init(&interface
->ctlr
, fip_mode
);
1341 interface
->ctlr
.send
= bnx2fc_fip_send
;
1342 interface
->ctlr
.update_mac
= bnx2fc_update_src_mac
;
1343 interface
->ctlr
.get_src_addr
= bnx2fc_get_src_mac
;
1344 set_bit(BNX2FC_CTLR_INIT_DONE
, &interface
->if_flags
);
1346 rc
= bnx2fc_interface_setup(interface
);
1350 fcoe_ctlr_destroy(&interface
->ctlr
);
1357 * bnx2fc_if_create - Create FCoE instance on a given interface
1359 * @interface: FCoE interface to create a local port on
1360 * @parent: Device pointer to be the parent in sysfs for the SCSI host
1361 * @npiv: Indicates if the port is vport or not
1363 * Creates a fc_lport instance and a Scsi_Host instance and configure them.
1365 * Returns: Allocated fc_lport or an error pointer
1367 static struct fc_lport
*bnx2fc_if_create(struct bnx2fc_interface
*interface
,
1368 struct device
*parent
, int npiv
)
1370 struct fc_lport
*lport
, *n_port
;
1371 struct fcoe_port
*port
;
1372 struct Scsi_Host
*shost
;
1373 struct fc_vport
*vport
= dev_to_vport(parent
);
1374 struct bnx2fc_lport
*blport
;
1375 struct bnx2fc_hba
*hba
;
1378 blport
= kzalloc(sizeof(struct bnx2fc_lport
), GFP_KERNEL
);
1380 BNX2FC_HBA_DBG(interface
->ctlr
.lp
, "Unable to alloc blport\n");
1384 /* Allocate Scsi_Host structure */
1386 lport
= libfc_host_alloc(&bnx2fc_shost_template
, sizeof(*port
));
1388 lport
= libfc_vport_create(vport
, sizeof(*port
));
1391 printk(KERN_ERR PFX
"could not allocate scsi host structure\n");
1394 shost
= lport
->host
;
1395 port
= lport_priv(lport
);
1396 port
->lport
= lport
;
1397 port
->priv
= interface
;
1398 INIT_WORK(&port
->destroy_work
, bnx2fc_destroy_work
);
1400 /* Configure fcoe_port */
1401 rc
= bnx2fc_lport_config(lport
);
1406 printk(KERN_ERR PFX
"Setting vport names, 0x%llX 0x%llX\n",
1407 vport
->node_name
, vport
->port_name
);
1408 fc_set_wwnn(lport
, vport
->node_name
);
1409 fc_set_wwpn(lport
, vport
->port_name
);
1411 /* Configure netdev and networking properties of the lport */
1412 rc
= bnx2fc_net_config(lport
, interface
->netdev
);
1414 printk(KERN_ERR PFX
"Error on bnx2fc_net_config\n");
1418 rc
= bnx2fc_shost_config(lport
, parent
);
1420 printk(KERN_ERR PFX
"Couldnt configure shost for %s\n",
1421 interface
->netdev
->name
);
1425 /* Initialize the libfc library */
1426 rc
= bnx2fc_libfc_config(lport
);
1428 printk(KERN_ERR PFX
"Couldnt configure libfc\n");
1431 fc_host_port_type(lport
->host
) = FC_PORTTYPE_UNKNOWN
;
1433 /* Allocate exchange manager */
1435 rc
= bnx2fc_em_config(lport
);
1437 shost
= vport_to_shost(vport
);
1438 n_port
= shost_priv(shost
);
1439 rc
= fc_exch_mgr_list_clone(n_port
, lport
);
1443 printk(KERN_ERR PFX
"Error on bnx2fc_em_config\n");
1447 bnx2fc_interface_get(interface
);
1449 hba
= interface
->hba
;
1450 spin_lock_bh(&hba
->hba_lock
);
1451 blport
->lport
= lport
;
1452 list_add_tail(&blport
->list
, &hba
->vports
);
1453 spin_unlock_bh(&hba
->hba_lock
);
1458 scsi_remove_host(shost
);
1460 scsi_host_put(lport
->host
);
1466 static void bnx2fc_net_cleanup(struct bnx2fc_interface
*interface
)
1468 /* Dont listen for Ethernet packets anymore */
1469 __dev_remove_pack(&interface
->fcoe_packet_type
);
1470 __dev_remove_pack(&interface
->fip_packet_type
);
1474 static void bnx2fc_interface_cleanup(struct bnx2fc_interface
*interface
)
1476 struct fc_lport
*lport
= interface
->ctlr
.lp
;
1477 struct fcoe_port
*port
= lport_priv(lport
);
1478 struct bnx2fc_hba
*hba
= interface
->hba
;
1480 /* Stop the transmit retry timer */
1481 del_timer_sync(&port
->timer
);
1483 /* Free existing transmit skbs */
1484 fcoe_clean_pending_queue(lport
);
1486 bnx2fc_net_cleanup(interface
);
1488 bnx2fc_free_vport(hba
, lport
);
1491 static void bnx2fc_if_destroy(struct fc_lport
*lport
)
1494 /* Free queued packets for the receive thread */
1495 bnx2fc_clean_rx_queue(lport
);
1497 /* Detach from scsi-ml */
1498 fc_remove_host(lport
->host
);
1499 scsi_remove_host(lport
->host
);
1502 * Note that only the physical lport will have the exchange manager.
1503 * for vports, this function is NOP
1505 fc_exch_mgr_free(lport
);
1507 /* Free memory used by statistical counters */
1508 fc_lport_free_stats(lport
);
1510 /* Release Scsi_Host */
1511 scsi_host_put(lport
->host
);
1514 static void __bnx2fc_destroy(struct bnx2fc_interface
*interface
)
1516 struct fc_lport
*lport
= interface
->ctlr
.lp
;
1517 struct fcoe_port
*port
= lport_priv(lport
);
1519 bnx2fc_interface_cleanup(interface
);
1520 bnx2fc_stop(interface
);
1521 list_del(&interface
->list
);
1522 bnx2fc_interface_put(interface
);
1523 queue_work(bnx2fc_wq
, &port
->destroy_work
);
1527 * bnx2fc_destroy - Destroy a bnx2fc FCoE interface
1529 * @buffer: The name of the Ethernet interface to be destroyed
1530 * @kp: The associated kernel parameter
1532 * Called from sysfs.
1534 * Returns: 0 for success
1536 static int bnx2fc_destroy(struct net_device
*netdev
)
1538 struct bnx2fc_interface
*interface
= NULL
;
1542 mutex_lock(&bnx2fc_dev_lock
);
1544 interface
= bnx2fc_interface_lookup(netdev
);
1545 if (!interface
|| !interface
->ctlr
.lp
) {
1547 printk(KERN_ERR PFX
"bnx2fc_destroy: interface or lport not found\n");
1552 destroy_workqueue(interface
->timer_work_queue
);
1553 __bnx2fc_destroy(interface
);
1556 mutex_unlock(&bnx2fc_dev_lock
);
1561 static void bnx2fc_destroy_work(struct work_struct
*work
)
1563 struct fcoe_port
*port
;
1564 struct fc_lport
*lport
;
1566 port
= container_of(work
, struct fcoe_port
, destroy_work
);
1567 lport
= port
->lport
;
1569 BNX2FC_HBA_DBG(lport
, "Entered bnx2fc_destroy_work\n");
1571 bnx2fc_if_destroy(lport
);
1574 static void bnx2fc_unbind_adapter_devices(struct bnx2fc_hba
*hba
)
1576 bnx2fc_free_fw_resc(hba
);
1577 bnx2fc_free_task_ctx(hba
);
1581 * bnx2fc_bind_adapter_devices - binds bnx2fc adapter with the associated
1584 * @hba: Adapter instance
1586 static int bnx2fc_bind_adapter_devices(struct bnx2fc_hba
*hba
)
1588 if (bnx2fc_setup_task_ctx(hba
))
1591 if (bnx2fc_setup_fw_resc(hba
))
1596 bnx2fc_unbind_adapter_devices(hba
);
1600 static int bnx2fc_bind_pcidev(struct bnx2fc_hba
*hba
)
1602 struct cnic_dev
*cnic
;
1605 printk(KERN_ERR PFX
"cnic is NULL\n");
1609 hba
->pcidev
= cnic
->pcidev
;
1611 pci_dev_get(hba
->pcidev
);
1616 static void bnx2fc_unbind_pcidev(struct bnx2fc_hba
*hba
)
1619 pci_dev_put(hba
->pcidev
);
1626 * bnx2fc_ulp_start - cnic callback to initialize & start adapter instance
1628 * @handle: transport handle pointing to adapter struture
1630 * This function maps adapter structure to pcidev structure and initiates
1631 * firmware handshake to enable/initialize on-chip FCoE components.
1632 * This bnx2fc - cnic interface api callback is used after following
1633 * conditions are met -
1634 * a) underlying network interface is up (marked by event NETDEV_UP
1636 * b) bnx2fc adatper structure is registered.
1638 static void bnx2fc_ulp_start(void *handle
)
1640 struct bnx2fc_hba
*hba
= handle
;
1641 struct bnx2fc_interface
*interface
;
1642 struct fc_lport
*lport
;
1644 mutex_lock(&bnx2fc_dev_lock
);
1646 if (!test_bit(BNX2FC_FLAG_FW_INIT_DONE
, &hba
->flags
))
1647 bnx2fc_fw_init(hba
);
1649 BNX2FC_MISC_DBG("bnx2fc started.\n");
1651 list_for_each_entry(interface
, &if_list
, list
) {
1652 if (interface
->hba
== hba
) {
1653 lport
= interface
->ctlr
.lp
;
1654 /* Kick off Fabric discovery*/
1655 printk(KERN_ERR PFX
"ulp_init: start discovery\n");
1656 lport
->tt
.frame_send
= bnx2fc_xmit
;
1657 bnx2fc_start_disc(interface
);
1661 mutex_unlock(&bnx2fc_dev_lock
);
1664 static void bnx2fc_port_shutdown(struct fc_lport
*lport
)
1666 BNX2FC_MISC_DBG("Entered %s\n", __func__
);
1667 fc_fabric_logoff(lport
);
1668 fc_lport_destroy(lport
);
1671 static void bnx2fc_stop(struct bnx2fc_interface
*interface
)
1673 struct fc_lport
*lport
;
1674 struct fc_lport
*vport
;
1676 if (!test_bit(BNX2FC_FLAG_FW_INIT_DONE
, &interface
->hba
->flags
))
1679 lport
= interface
->ctlr
.lp
;
1680 bnx2fc_port_shutdown(lport
);
1682 mutex_lock(&lport
->lp_mutex
);
1683 list_for_each_entry(vport
, &lport
->vports
, list
)
1684 fc_host_port_type(vport
->host
) =
1685 FC_PORTTYPE_UNKNOWN
;
1686 mutex_unlock(&lport
->lp_mutex
);
1687 fc_host_port_type(lport
->host
) = FC_PORTTYPE_UNKNOWN
;
1688 fcoe_ctlr_link_down(&interface
->ctlr
);
1689 fcoe_clean_pending_queue(lport
);
1692 static int bnx2fc_fw_init(struct bnx2fc_hba
*hba
)
1694 #define BNX2FC_INIT_POLL_TIME (1000 / HZ)
1698 rc
= bnx2fc_bind_adapter_devices(hba
);
1700 printk(KERN_ALERT PFX
1701 "bnx2fc_bind_adapter_devices failed - rc = %d\n", rc
);
1705 rc
= bnx2fc_send_fw_fcoe_init_msg(hba
);
1707 printk(KERN_ALERT PFX
1708 "bnx2fc_send_fw_fcoe_init_msg failed - rc = %d\n", rc
);
1713 * Wait until the adapter init message is complete, and adapter
1716 while (!test_bit(ADAPTER_STATE_UP
, &hba
->adapter_state
) && i
--)
1717 msleep(BNX2FC_INIT_POLL_TIME
);
1719 if (!test_bit(ADAPTER_STATE_UP
, &hba
->adapter_state
)) {
1720 printk(KERN_ERR PFX
"bnx2fc_start: %s failed to initialize. "
1722 hba
->cnic
->netdev
->name
);
1728 set_bit(BNX2FC_FLAG_FW_INIT_DONE
, &hba
->flags
);
1732 bnx2fc_unbind_adapter_devices(hba
);
1737 static void bnx2fc_fw_destroy(struct bnx2fc_hba
*hba
)
1739 if (test_and_clear_bit(BNX2FC_FLAG_FW_INIT_DONE
, &hba
->flags
)) {
1740 if (bnx2fc_send_fw_fcoe_destroy_msg(hba
) == 0) {
1741 init_timer(&hba
->destroy_timer
);
1742 hba
->destroy_timer
.expires
= BNX2FC_FW_TIMEOUT
+
1744 hba
->destroy_timer
.function
= bnx2fc_destroy_timer
;
1745 hba
->destroy_timer
.data
= (unsigned long)hba
;
1746 add_timer(&hba
->destroy_timer
);
1747 wait_event_interruptible(hba
->destroy_wait
,
1748 test_bit(BNX2FC_FLAG_DESTROY_CMPL
,
1750 clear_bit(BNX2FC_FLAG_DESTROY_CMPL
, &hba
->flags
);
1751 /* This should never happen */
1752 if (signal_pending(current
))
1753 flush_signals(current
);
1755 del_timer_sync(&hba
->destroy_timer
);
1757 bnx2fc_unbind_adapter_devices(hba
);
1762 * bnx2fc_ulp_stop - cnic callback to shutdown adapter instance
1764 * @handle: transport handle pointing to adapter structure
1766 * Driver checks if adapter is already in shutdown mode, if not start
1767 * the shutdown process.
1769 static void bnx2fc_ulp_stop(void *handle
)
1771 struct bnx2fc_hba
*hba
= handle
;
1772 struct bnx2fc_interface
*interface
;
1774 printk(KERN_ERR
"ULP_STOP\n");
1776 mutex_lock(&bnx2fc_dev_lock
);
1777 if (!test_bit(BNX2FC_FLAG_FW_INIT_DONE
, &hba
->flags
))
1779 list_for_each_entry(interface
, &if_list
, list
) {
1780 if (interface
->hba
== hba
)
1781 bnx2fc_stop(interface
);
1783 BUG_ON(hba
->num_ofld_sess
!= 0);
1785 mutex_lock(&hba
->hba_mutex
);
1786 clear_bit(ADAPTER_STATE_UP
, &hba
->adapter_state
);
1787 clear_bit(ADAPTER_STATE_GOING_DOWN
,
1788 &hba
->adapter_state
);
1790 clear_bit(ADAPTER_STATE_READY
, &hba
->adapter_state
);
1791 mutex_unlock(&hba
->hba_mutex
);
1793 bnx2fc_fw_destroy(hba
);
1795 mutex_unlock(&bnx2fc_dev_lock
);
1798 static void bnx2fc_start_disc(struct bnx2fc_interface
*interface
)
1800 struct fc_lport
*lport
;
1803 BNX2FC_MISC_DBG("Entered %s\n", __func__
);
1804 /* Kick off FIP/FLOGI */
1805 if (!test_bit(BNX2FC_FLAG_FW_INIT_DONE
, &interface
->hba
->flags
)) {
1806 printk(KERN_ERR PFX
"Init not done yet\n");
1810 lport
= interface
->ctlr
.lp
;
1811 BNX2FC_HBA_DBG(lport
, "calling fc_fabric_login\n");
1813 if (!bnx2fc_link_ok(lport
) && interface
->enabled
) {
1814 BNX2FC_HBA_DBG(lport
, "ctlr_link_up\n");
1815 fcoe_ctlr_link_up(&interface
->ctlr
);
1816 fc_host_port_type(lport
->host
) = FC_PORTTYPE_NPORT
;
1817 set_bit(ADAPTER_STATE_READY
, &interface
->hba
->adapter_state
);
1820 /* wait for the FCF to be selected before issuing FLOGI */
1821 while (!interface
->ctlr
.sel_fcf
) {
1823 /* give up after 3 secs */
1824 if (++wait_cnt
> 12)
1828 /* Reset max receive frame size to default */
1829 if (fc_set_mfs(lport
, BNX2FC_MFS
))
1832 fc_lport_init(lport
);
1833 fc_fabric_login(lport
);
1838 * bnx2fc_ulp_init - Initialize an adapter instance
1840 * @dev : cnic device handle
1841 * Called from cnic_register_driver() context to initialize all
1842 * enumerated cnic devices. This routine allocates adapter structure
1843 * and other device specific resources.
1845 static void bnx2fc_ulp_init(struct cnic_dev
*dev
)
1847 struct bnx2fc_hba
*hba
;
1850 BNX2FC_MISC_DBG("Entered %s\n", __func__
);
1851 /* bnx2fc works only when bnx2x is loaded */
1852 if (!test_bit(CNIC_F_BNX2X_CLASS
, &dev
->flags
) ||
1853 (dev
->max_fcoe_conn
== 0)) {
1854 printk(KERN_ERR PFX
"bnx2fc FCoE not supported on %s,"
1855 " flags: %lx fcoe_conn: %d\n",
1856 dev
->netdev
->name
, dev
->flags
, dev
->max_fcoe_conn
);
1860 hba
= bnx2fc_hba_create(dev
);
1862 printk(KERN_ERR PFX
"hba initialization failed\n");
1866 /* Add HBA to the adapter list */
1867 mutex_lock(&bnx2fc_dev_lock
);
1868 list_add_tail(&hba
->list
, &adapter_list
);
1870 mutex_unlock(&bnx2fc_dev_lock
);
1872 clear_bit(BNX2FC_CNIC_REGISTERED
, &hba
->reg_with_cnic
);
1873 rc
= dev
->register_device(dev
, CNIC_ULP_FCOE
,
1876 printk(KERN_ERR PFX
"register_device failed, rc = %d\n", rc
);
1878 set_bit(BNX2FC_CNIC_REGISTERED
, &hba
->reg_with_cnic
);
1882 static int bnx2fc_disable(struct net_device
*netdev
)
1884 struct bnx2fc_interface
*interface
;
1888 mutex_lock(&bnx2fc_dev_lock
);
1890 interface
= bnx2fc_interface_lookup(netdev
);
1891 if (!interface
|| !interface
->ctlr
.lp
) {
1893 printk(KERN_ERR PFX
"bnx2fc_disable: interface or lport not found\n");
1895 interface
->enabled
= false;
1896 fcoe_ctlr_link_down(&interface
->ctlr
);
1897 fcoe_clean_pending_queue(interface
->ctlr
.lp
);
1900 mutex_unlock(&bnx2fc_dev_lock
);
1906 static int bnx2fc_enable(struct net_device
*netdev
)
1908 struct bnx2fc_interface
*interface
;
1912 mutex_lock(&bnx2fc_dev_lock
);
1914 interface
= bnx2fc_interface_lookup(netdev
);
1915 if (!interface
|| !interface
->ctlr
.lp
) {
1917 printk(KERN_ERR PFX
"bnx2fc_enable: interface or lport not found\n");
1918 } else if (!bnx2fc_link_ok(interface
->ctlr
.lp
)) {
1919 fcoe_ctlr_link_up(&interface
->ctlr
);
1920 interface
->enabled
= true;
1923 mutex_unlock(&bnx2fc_dev_lock
);
1929 * bnx2fc_create - Create bnx2fc FCoE interface
1931 * @buffer: The name of Ethernet interface to create on
1932 * @kp: The associated kernel param
1934 * Called from sysfs.
1936 * Returns: 0 for success
1938 static int bnx2fc_create(struct net_device
*netdev
, enum fip_state fip_mode
)
1940 struct bnx2fc_interface
*interface
;
1941 struct bnx2fc_hba
*hba
;
1942 struct net_device
*phys_dev
;
1943 struct fc_lport
*lport
;
1944 struct ethtool_drvinfo drvinfo
;
1948 BNX2FC_MISC_DBG("Entered bnx2fc_create\n");
1949 if (fip_mode
!= FIP_MODE_FABRIC
) {
1950 printk(KERN_ERR
"fip mode not FABRIC\n");
1956 mutex_lock(&bnx2fc_dev_lock
);
1958 if (!try_module_get(THIS_MODULE
)) {
1963 /* obtain physical netdev */
1964 if (netdev
->priv_flags
& IFF_802_1Q_VLAN
) {
1965 phys_dev
= vlan_dev_real_dev(netdev
);
1966 vlan_id
= vlan_dev_vlan_id(netdev
);
1968 printk(KERN_ERR PFX
"Not a vlan device\n");
1972 /* verify if the physical device is a netxtreme2 device */
1973 if (phys_dev
->ethtool_ops
&& phys_dev
->ethtool_ops
->get_drvinfo
) {
1974 memset(&drvinfo
, 0, sizeof(drvinfo
));
1975 phys_dev
->ethtool_ops
->get_drvinfo(phys_dev
, &drvinfo
);
1976 if (strncmp(drvinfo
.driver
, "bnx2x", strlen("bnx2x"))) {
1977 printk(KERN_ERR PFX
"Not a netxtreme2 device\n");
1982 printk(KERN_ERR PFX
"unable to obtain drv_info\n");
1987 /* obtain interface and initialize rest of the structure */
1988 hba
= bnx2fc_hba_lookup(phys_dev
);
1991 printk(KERN_ERR PFX
"bnx2fc_create: hba not found\n");
1995 if (bnx2fc_interface_lookup(netdev
)) {
2000 interface
= bnx2fc_interface_create(hba
, netdev
, fip_mode
);
2002 printk(KERN_ERR PFX
"bnx2fc_interface_create failed\n");
2006 interface
->vlan_id
= vlan_id
;
2007 interface
->vlan_enabled
= 1;
2009 interface
->timer_work_queue
=
2010 create_singlethread_workqueue("bnx2fc_timer_wq");
2011 if (!interface
->timer_work_queue
) {
2012 printk(KERN_ERR PFX
"ulp_init could not create timer_wq\n");
2017 lport
= bnx2fc_if_create(interface
, &interface
->hba
->pcidev
->dev
, 0);
2019 printk(KERN_ERR PFX
"Failed to create interface (%s)\n",
2025 /* Add interface to if_list */
2026 list_add_tail(&interface
->list
, &if_list
);
2028 lport
->boot_time
= jiffies
;
2030 /* Make this master N_port */
2031 interface
->ctlr
.lp
= lport
;
2033 if (!bnx2fc_link_ok(lport
)) {
2034 fcoe_ctlr_link_up(&interface
->ctlr
);
2035 fc_host_port_type(lport
->host
) = FC_PORTTYPE_NPORT
;
2036 set_bit(ADAPTER_STATE_READY
, &interface
->hba
->adapter_state
);
2039 BNX2FC_HBA_DBG(lport
, "create: START DISC\n");
2040 bnx2fc_start_disc(interface
);
2041 interface
->enabled
= true;
2043 * Release from kref_init in bnx2fc_interface_setup, on success
2044 * lport should be holding a reference taken in bnx2fc_if_create
2046 bnx2fc_interface_put(interface
);
2047 /* put netdev that was held while calling dev_get_by_name */
2048 mutex_unlock(&bnx2fc_dev_lock
);
2053 destroy_workqueue(interface
->timer_work_queue
);
2055 bnx2fc_net_cleanup(interface
);
2056 bnx2fc_interface_put(interface
);
2058 module_put(THIS_MODULE
);
2060 mutex_unlock(&bnx2fc_dev_lock
);
2066 * bnx2fc_find_hba_for_cnic - maps cnic instance to bnx2fc hba instance
2068 * @cnic: Pointer to cnic device instance
2071 static struct bnx2fc_hba
*bnx2fc_find_hba_for_cnic(struct cnic_dev
*cnic
)
2073 struct list_head
*list
;
2074 struct list_head
*temp
;
2075 struct bnx2fc_hba
*hba
;
2077 /* Called with bnx2fc_dev_lock held */
2078 list_for_each_safe(list
, temp
, &adapter_list
) {
2079 hba
= (struct bnx2fc_hba
*)list
;
2080 if (hba
->cnic
== cnic
)
2086 static struct bnx2fc_interface
*bnx2fc_interface_lookup(struct net_device
2089 struct bnx2fc_interface
*interface
;
2091 /* Called with bnx2fc_dev_lock held */
2092 list_for_each_entry(interface
, &if_list
, list
) {
2093 if (interface
->netdev
== netdev
)
2099 static struct bnx2fc_hba
*bnx2fc_hba_lookup(struct net_device
2102 struct bnx2fc_hba
*hba
;
2104 /* Called with bnx2fc_dev_lock held */
2105 list_for_each_entry(hba
, &adapter_list
, list
) {
2106 if (hba
->phys_dev
== phys_dev
)
2109 printk(KERN_ERR PFX
"adapter_lookup: hba NULL\n");
2114 * bnx2fc_ulp_exit - shuts down adapter instance and frees all resources
2116 * @dev cnic device handle
2118 static void bnx2fc_ulp_exit(struct cnic_dev
*dev
)
2120 struct bnx2fc_hba
*hba
;
2121 struct bnx2fc_interface
*interface
, *tmp
;
2123 BNX2FC_MISC_DBG("Entered bnx2fc_ulp_exit\n");
2125 if (!test_bit(CNIC_F_BNX2X_CLASS
, &dev
->flags
)) {
2126 printk(KERN_ERR PFX
"bnx2fc port check: %s, flags: %lx\n",
2127 dev
->netdev
->name
, dev
->flags
);
2131 mutex_lock(&bnx2fc_dev_lock
);
2132 hba
= bnx2fc_find_hba_for_cnic(dev
);
2134 printk(KERN_ERR PFX
"bnx2fc_ulp_exit: hba not found, dev 0%p\n",
2136 mutex_unlock(&bnx2fc_dev_lock
);
2140 list_del_init(&hba
->list
);
2143 list_for_each_entry_safe(interface
, tmp
, &if_list
, list
)
2144 /* destroy not called yet, move to quiesced list */
2145 if (interface
->hba
== hba
)
2146 __bnx2fc_destroy(interface
);
2147 mutex_unlock(&bnx2fc_dev_lock
);
2149 bnx2fc_ulp_stop(hba
);
2150 /* unregister cnic device */
2151 if (test_and_clear_bit(BNX2FC_CNIC_REGISTERED
, &hba
->reg_with_cnic
))
2152 hba
->cnic
->unregister_device(hba
->cnic
, CNIC_ULP_FCOE
);
2153 bnx2fc_hba_destroy(hba
);
2157 * bnx2fc_fcoe_reset - Resets the fcoe
2159 * @shost: shost the reset is from
2163 static int bnx2fc_fcoe_reset(struct Scsi_Host
*shost
)
2165 struct fc_lport
*lport
= shost_priv(shost
);
2166 fc_lport_reset(lport
);
2171 static bool bnx2fc_match(struct net_device
*netdev
)
2173 mutex_lock(&bnx2fc_dev_lock
);
2174 if (netdev
->priv_flags
& IFF_802_1Q_VLAN
) {
2175 struct net_device
*phys_dev
= vlan_dev_real_dev(netdev
);
2177 if (bnx2fc_hba_lookup(phys_dev
)) {
2178 mutex_unlock(&bnx2fc_dev_lock
);
2182 mutex_unlock(&bnx2fc_dev_lock
);
2187 static struct fcoe_transport bnx2fc_transport
= {
2190 .list
= LIST_HEAD_INIT(bnx2fc_transport
.list
),
2191 .match
= bnx2fc_match
,
2192 .create
= bnx2fc_create
,
2193 .destroy
= bnx2fc_destroy
,
2194 .enable
= bnx2fc_enable
,
2195 .disable
= bnx2fc_disable
,
2199 * bnx2fc_percpu_thread_create - Create a receive thread for an
2202 * @cpu: cpu index for the online cpu
2204 static void bnx2fc_percpu_thread_create(unsigned int cpu
)
2206 struct bnx2fc_percpu_s
*p
;
2207 struct task_struct
*thread
;
2209 p
= &per_cpu(bnx2fc_percpu
, cpu
);
2211 thread
= kthread_create(bnx2fc_percpu_io_thread
,
2213 "bnx2fc_thread/%d", cpu
);
2214 /* bind thread to the cpu */
2215 if (likely(!IS_ERR(thread
))) {
2216 kthread_bind(thread
, cpu
);
2217 p
->iothread
= thread
;
2218 wake_up_process(thread
);
2222 static void bnx2fc_percpu_thread_destroy(unsigned int cpu
)
2224 struct bnx2fc_percpu_s
*p
;
2225 struct task_struct
*thread
;
2226 struct bnx2fc_work
*work
, *tmp
;
2228 BNX2FC_MISC_DBG("destroying io thread for CPU %d\n", cpu
);
2230 /* Prevent any new work from being queued for this CPU */
2231 p
= &per_cpu(bnx2fc_percpu
, cpu
);
2232 spin_lock_bh(&p
->fp_work_lock
);
2233 thread
= p
->iothread
;
2237 /* Free all work in the list */
2238 list_for_each_entry_safe(work
, tmp
, &p
->work_list
, list
) {
2239 list_del_init(&work
->list
);
2240 bnx2fc_process_cq_compl(work
->tgt
, work
->wqe
);
2244 spin_unlock_bh(&p
->fp_work_lock
);
2247 kthread_stop(thread
);
2251 * bnx2fc_cpu_callback - Handler for CPU hotplug events
2253 * @nfb: The callback data block
2254 * @action: The event triggering the callback
2255 * @hcpu: The index of the CPU that the event is for
2257 * This creates or destroys per-CPU data for fcoe
2259 * Returns NOTIFY_OK always.
2261 static int bnx2fc_cpu_callback(struct notifier_block
*nfb
,
2262 unsigned long action
, void *hcpu
)
2264 unsigned cpu
= (unsigned long)hcpu
;
2268 case CPU_ONLINE_FROZEN
:
2269 printk(PFX
"CPU %x online: Create Rx thread\n", cpu
);
2270 bnx2fc_percpu_thread_create(cpu
);
2273 case CPU_DEAD_FROZEN
:
2274 printk(PFX
"CPU %x offline: Remove Rx thread\n", cpu
);
2275 bnx2fc_percpu_thread_destroy(cpu
);
2284 * bnx2fc_mod_init - module init entry point
2286 * Initialize driver wide global data structures, and register
2289 static int __init
bnx2fc_mod_init(void)
2291 struct fcoe_percpu_s
*bg
;
2292 struct task_struct
*l2_thread
;
2294 unsigned int cpu
= 0;
2295 struct bnx2fc_percpu_s
*p
;
2297 printk(KERN_INFO PFX
"%s", version
);
2299 /* register as a fcoe transport */
2300 rc
= fcoe_transport_attach(&bnx2fc_transport
);
2302 printk(KERN_ERR
"failed to register an fcoe transport, check "
2303 "if libfcoe is loaded\n");
2307 INIT_LIST_HEAD(&adapter_list
);
2308 INIT_LIST_HEAD(&if_list
);
2309 mutex_init(&bnx2fc_dev_lock
);
2312 /* Attach FC transport template */
2313 rc
= bnx2fc_attach_transport();
2317 bnx2fc_wq
= alloc_workqueue("bnx2fc", 0, 0);
2323 bg
= &bnx2fc_global
;
2324 skb_queue_head_init(&bg
->fcoe_rx_list
);
2325 l2_thread
= kthread_create(bnx2fc_l2_rcv_thread
,
2327 "bnx2fc_l2_thread");
2328 if (IS_ERR(l2_thread
)) {
2329 rc
= PTR_ERR(l2_thread
);
2332 wake_up_process(l2_thread
);
2333 spin_lock_bh(&bg
->fcoe_rx_list
.lock
);
2334 bg
->thread
= l2_thread
;
2335 spin_unlock_bh(&bg
->fcoe_rx_list
.lock
);
2337 for_each_possible_cpu(cpu
) {
2338 p
= &per_cpu(bnx2fc_percpu
, cpu
);
2339 INIT_LIST_HEAD(&p
->work_list
);
2340 spin_lock_init(&p
->fp_work_lock
);
2343 for_each_online_cpu(cpu
) {
2344 bnx2fc_percpu_thread_create(cpu
);
2347 /* Initialize per CPU interrupt thread */
2348 register_hotcpu_notifier(&bnx2fc_cpu_notifier
);
2350 cnic_register_driver(CNIC_ULP_FCOE
, &bnx2fc_cnic_cb
);
2355 destroy_workqueue(bnx2fc_wq
);
2357 bnx2fc_release_transport();
2359 fcoe_transport_detach(&bnx2fc_transport
);
2364 static void __exit
bnx2fc_mod_exit(void)
2366 LIST_HEAD(to_be_deleted
);
2367 struct bnx2fc_hba
*hba
, *next
;
2368 struct fcoe_percpu_s
*bg
;
2369 struct task_struct
*l2_thread
;
2370 struct sk_buff
*skb
;
2371 unsigned int cpu
= 0;
2374 * NOTE: Since cnic calls register_driver routine rtnl_lock,
2375 * it will have higher precedence than bnx2fc_dev_lock.
2376 * unregister_device() cannot be called with bnx2fc_dev_lock
2379 mutex_lock(&bnx2fc_dev_lock
);
2380 list_splice(&adapter_list
, &to_be_deleted
);
2381 INIT_LIST_HEAD(&adapter_list
);
2383 mutex_unlock(&bnx2fc_dev_lock
);
2385 /* Unregister with cnic */
2386 list_for_each_entry_safe(hba
, next
, &to_be_deleted
, list
) {
2387 list_del_init(&hba
->list
);
2388 printk(KERN_ERR PFX
"MOD_EXIT:destroy hba = 0x%p\n",
2390 bnx2fc_ulp_stop(hba
);
2391 /* unregister cnic device */
2392 if (test_and_clear_bit(BNX2FC_CNIC_REGISTERED
,
2393 &hba
->reg_with_cnic
))
2394 hba
->cnic
->unregister_device(hba
->cnic
,
2396 bnx2fc_hba_destroy(hba
);
2398 cnic_unregister_driver(CNIC_ULP_FCOE
);
2400 /* Destroy global thread */
2401 bg
= &bnx2fc_global
;
2402 spin_lock_bh(&bg
->fcoe_rx_list
.lock
);
2403 l2_thread
= bg
->thread
;
2405 while ((skb
= __skb_dequeue(&bg
->fcoe_rx_list
)) != NULL
)
2408 spin_unlock_bh(&bg
->fcoe_rx_list
.lock
);
2411 kthread_stop(l2_thread
);
2413 unregister_hotcpu_notifier(&bnx2fc_cpu_notifier
);
2415 /* Destroy per cpu threads */
2416 for_each_online_cpu(cpu
) {
2417 bnx2fc_percpu_thread_destroy(cpu
);
2420 destroy_workqueue(bnx2fc_wq
);
2422 * detach from scsi transport
2423 * must happen after all destroys are done
2425 bnx2fc_release_transport();
2427 /* detach from fcoe transport */
2428 fcoe_transport_detach(&bnx2fc_transport
);
2431 module_init(bnx2fc_mod_init
);
2432 module_exit(bnx2fc_mod_exit
);
2434 static struct fc_function_template bnx2fc_transport_function
= {
2435 .show_host_node_name
= 1,
2436 .show_host_port_name
= 1,
2437 .show_host_supported_classes
= 1,
2438 .show_host_supported_fc4s
= 1,
2439 .show_host_active_fc4s
= 1,
2440 .show_host_maxframe_size
= 1,
2442 .show_host_port_id
= 1,
2443 .show_host_supported_speeds
= 1,
2444 .get_host_speed
= fc_get_host_speed
,
2445 .show_host_speed
= 1,
2446 .show_host_port_type
= 1,
2447 .get_host_port_state
= fc_get_host_port_state
,
2448 .show_host_port_state
= 1,
2449 .show_host_symbolic_name
= 1,
2451 .dd_fcrport_size
= (sizeof(struct fc_rport_libfc_priv
) +
2452 sizeof(struct bnx2fc_rport
)),
2453 .show_rport_maxframe_size
= 1,
2454 .show_rport_supported_classes
= 1,
2456 .show_host_fabric_name
= 1,
2457 .show_starget_node_name
= 1,
2458 .show_starget_port_name
= 1,
2459 .show_starget_port_id
= 1,
2460 .set_rport_dev_loss_tmo
= fc_set_rport_loss_tmo
,
2461 .show_rport_dev_loss_tmo
= 1,
2462 .get_fc_host_stats
= bnx2fc_get_host_stats
,
2464 .issue_fc_host_lip
= bnx2fc_fcoe_reset
,
2466 .terminate_rport_io
= fc_rport_terminate_io
,
2468 .vport_create
= bnx2fc_vport_create
,
2469 .vport_delete
= bnx2fc_vport_destroy
,
2470 .vport_disable
= bnx2fc_vport_disable
,
2471 .bsg_request
= fc_lport_bsg_request
,
2474 static struct fc_function_template bnx2fc_vport_xport_function
= {
2475 .show_host_node_name
= 1,
2476 .show_host_port_name
= 1,
2477 .show_host_supported_classes
= 1,
2478 .show_host_supported_fc4s
= 1,
2479 .show_host_active_fc4s
= 1,
2480 .show_host_maxframe_size
= 1,
2482 .show_host_port_id
= 1,
2483 .show_host_supported_speeds
= 1,
2484 .get_host_speed
= fc_get_host_speed
,
2485 .show_host_speed
= 1,
2486 .show_host_port_type
= 1,
2487 .get_host_port_state
= fc_get_host_port_state
,
2488 .show_host_port_state
= 1,
2489 .show_host_symbolic_name
= 1,
2491 .dd_fcrport_size
= (sizeof(struct fc_rport_libfc_priv
) +
2492 sizeof(struct bnx2fc_rport
)),
2493 .show_rport_maxframe_size
= 1,
2494 .show_rport_supported_classes
= 1,
2496 .show_host_fabric_name
= 1,
2497 .show_starget_node_name
= 1,
2498 .show_starget_port_name
= 1,
2499 .show_starget_port_id
= 1,
2500 .set_rport_dev_loss_tmo
= fc_set_rport_loss_tmo
,
2501 .show_rport_dev_loss_tmo
= 1,
2502 .get_fc_host_stats
= fc_get_host_stats
,
2503 .issue_fc_host_lip
= bnx2fc_fcoe_reset
,
2504 .terminate_rport_io
= fc_rport_terminate_io
,
2505 .bsg_request
= fc_lport_bsg_request
,
2509 * scsi_host_template structure used while registering with SCSI-ml
2511 static struct scsi_host_template bnx2fc_shost_template
= {
2512 .module
= THIS_MODULE
,
2513 .name
= "Broadcom Offload FCoE Initiator",
2514 .queuecommand
= bnx2fc_queuecommand
,
2515 .eh_abort_handler
= bnx2fc_eh_abort
, /* abts */
2516 .eh_device_reset_handler
= bnx2fc_eh_device_reset
, /* lun reset */
2517 .eh_target_reset_handler
= bnx2fc_eh_target_reset
, /* tgt reset */
2518 .eh_host_reset_handler
= fc_eh_host_reset
,
2519 .slave_alloc
= fc_slave_alloc
,
2520 .change_queue_depth
= fc_change_queue_depth
,
2521 .change_queue_type
= fc_change_queue_type
,
2524 .can_queue
= BNX2FC_CAN_QUEUE
,
2525 .use_clustering
= ENABLE_CLUSTERING
,
2526 .sg_tablesize
= BNX2FC_MAX_BDS_PER_CMD
,
2530 static struct libfc_function_template bnx2fc_libfc_fcn_templ
= {
2531 .frame_send
= bnx2fc_xmit
,
2532 .elsct_send
= bnx2fc_elsct_send
,
2533 .fcp_abort_io
= bnx2fc_abort_io
,
2534 .fcp_cleanup
= bnx2fc_cleanup
,
2535 .get_lesb
= bnx2fc_get_lesb
,
2536 .rport_event_callback
= bnx2fc_rport_event_handler
,
2540 * bnx2fc_cnic_cb - global template of bnx2fc - cnic driver interface
2541 * structure carrying callback function pointers
2543 static struct cnic_ulp_ops bnx2fc_cnic_cb
= {
2544 .owner
= THIS_MODULE
,
2545 .cnic_init
= bnx2fc_ulp_init
,
2546 .cnic_exit
= bnx2fc_ulp_exit
,
2547 .cnic_start
= bnx2fc_ulp_start
,
2548 .cnic_stop
= bnx2fc_ulp_stop
,
2549 .indicate_kcqes
= bnx2fc_indicate_kcqe
,
2550 .indicate_netevent
= bnx2fc_indicate_netevent
,