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 "Jun 23, 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 int bnx2fc_destroy(struct net_device
*net_device
);
60 static int bnx2fc_enable(struct net_device
*netdev
);
61 static int bnx2fc_disable(struct net_device
*netdev
);
63 static void bnx2fc_recv_frame(struct sk_buff
*skb
);
65 static void bnx2fc_start_disc(struct bnx2fc_interface
*interface
);
66 static int bnx2fc_shost_config(struct fc_lport
*lport
, struct device
*dev
);
67 static int bnx2fc_net_config(struct fc_lport
*lp
);
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 struct bnx2fc_hba
*bnx2fc_find_hba_for_cnic(struct cnic_dev
*cnic
);
83 static int bnx2fc_fw_init(struct bnx2fc_hba
*hba
);
84 static void bnx2fc_fw_destroy(struct bnx2fc_hba
*hba
);
86 static void bnx2fc_port_shutdown(struct fc_lport
*lport
);
87 static void bnx2fc_stop(struct bnx2fc_interface
*interface
);
88 static int __init
bnx2fc_mod_init(void);
89 static void __exit
bnx2fc_mod_exit(void);
91 unsigned int bnx2fc_debug_level
;
92 module_param_named(debug_logging
, bnx2fc_debug_level
, int, S_IRUGO
|S_IWUSR
);
94 static int bnx2fc_cpu_callback(struct notifier_block
*nfb
,
95 unsigned long action
, void *hcpu
);
96 /* notification function for CPU hotplug events */
97 static struct notifier_block bnx2fc_cpu_notifier
= {
98 .notifier_call
= bnx2fc_cpu_callback
,
101 static void bnx2fc_clean_rx_queue(struct fc_lport
*lp
)
103 struct fcoe_percpu_s
*bg
;
104 struct fcoe_rcv_info
*fr
;
105 struct sk_buff_head
*list
;
106 struct sk_buff
*skb
, *next
;
107 struct sk_buff
*head
;
110 spin_lock_bh(&bg
->fcoe_rx_list
.lock
);
111 list
= &bg
->fcoe_rx_list
;
113 for (skb
= head
; skb
!= (struct sk_buff
*)list
;
116 fr
= fcoe_dev_from_skb(skb
);
117 if (fr
->fr_dev
== lp
) {
118 __skb_unlink(skb
, list
);
122 spin_unlock_bh(&bg
->fcoe_rx_list
.lock
);
125 int bnx2fc_get_paged_crc_eof(struct sk_buff
*skb
, int tlen
)
128 spin_lock(&bnx2fc_global_lock
);
129 rc
= fcoe_get_paged_crc_eof(skb
, tlen
, &bnx2fc_global
);
130 spin_unlock(&bnx2fc_global_lock
);
135 static void bnx2fc_abort_io(struct fc_lport
*lport
)
138 * This function is no-op for bnx2fc, but we do
139 * not want to leave it as NULL either, as libfc
140 * can call the default function which is
145 static void bnx2fc_cleanup(struct fc_lport
*lport
)
147 struct fcoe_port
*port
= lport_priv(lport
);
148 struct bnx2fc_interface
*interface
= port
->priv
;
149 struct bnx2fc_hba
*hba
= interface
->hba
;
150 struct bnx2fc_rport
*tgt
;
153 BNX2FC_MISC_DBG("Entered %s\n", __func__
);
154 mutex_lock(&hba
->hba_mutex
);
155 spin_lock_bh(&hba
->hba_lock
);
156 for (i
= 0; i
< BNX2FC_NUM_MAX_SESS
; i
++) {
157 tgt
= hba
->tgt_ofld_list
[i
];
159 /* Cleanup IOs belonging to requested vport */
160 if (tgt
->port
== port
) {
161 spin_unlock_bh(&hba
->hba_lock
);
162 BNX2FC_TGT_DBG(tgt
, "flush/cleanup\n");
163 bnx2fc_flush_active_ios(tgt
);
164 spin_lock_bh(&hba
->hba_lock
);
168 spin_unlock_bh(&hba
->hba_lock
);
169 mutex_unlock(&hba
->hba_mutex
);
172 static int bnx2fc_xmit_l2_frame(struct bnx2fc_rport
*tgt
,
175 struct fc_rport_priv
*rdata
= tgt
->rdata
;
176 struct fc_frame_header
*fh
;
179 fh
= fc_frame_header_get(fp
);
180 BNX2FC_TGT_DBG(tgt
, "Xmit L2 frame rport = 0x%x, oxid = 0x%x, "
181 "r_ctl = 0x%x\n", rdata
->ids
.port_id
,
182 ntohs(fh
->fh_ox_id
), fh
->fh_r_ctl
);
183 if ((fh
->fh_type
== FC_TYPE_ELS
) &&
184 (fh
->fh_r_ctl
== FC_RCTL_ELS_REQ
)) {
186 switch (fc_frame_payload_op(fp
)) {
188 rc
= bnx2fc_send_adisc(tgt
, fp
);
191 rc
= bnx2fc_send_logo(tgt
, fp
);
194 rc
= bnx2fc_send_rls(tgt
, fp
);
199 } else if ((fh
->fh_type
== FC_TYPE_BLS
) &&
200 (fh
->fh_r_ctl
== FC_RCTL_BA_ABTS
))
201 BNX2FC_TGT_DBG(tgt
, "ABTS frame\n");
203 BNX2FC_TGT_DBG(tgt
, "Send L2 frame type 0x%x "
204 "rctl 0x%x thru non-offload path\n",
205 fh
->fh_type
, fh
->fh_r_ctl
);
215 * bnx2fc_xmit - bnx2fc's FCoE frame transmit function
217 * @lport: the associated local port
218 * @fp: the fc_frame to be transmitted
220 static int bnx2fc_xmit(struct fc_lport
*lport
, struct fc_frame
*fp
)
223 struct fcoe_crc_eof
*cp
;
225 struct fc_frame_header
*fh
;
226 struct bnx2fc_interface
*interface
;
227 struct bnx2fc_hba
*hba
;
228 struct fcoe_port
*port
;
230 struct bnx2fc_rport
*tgt
;
231 struct fcoe_dev_stats
*stats
;
234 unsigned int hlen
, tlen
, elen
;
237 port
= (struct fcoe_port
*)lport_priv(lport
);
238 interface
= port
->priv
;
239 hba
= interface
->hba
;
241 fh
= fc_frame_header_get(fp
);
244 if (!lport
->link_up
) {
245 BNX2FC_HBA_DBG(lport
, "bnx2fc_xmit link down\n");
250 if (unlikely(fh
->fh_r_ctl
== FC_RCTL_ELS_REQ
)) {
251 if (!interface
->ctlr
.sel_fcf
) {
252 BNX2FC_HBA_DBG(lport
, "FCF not selected yet!\n");
256 if (fcoe_ctlr_els_send(&interface
->ctlr
, lport
, skb
))
264 * Snoop the frame header to check if the frame is for
265 * an offloaded session
268 * tgt_ofld_list access is synchronized using
269 * both hba mutex and hba lock. Atleast hba mutex or
270 * hba lock needs to be held for read access.
273 spin_lock_bh(&hba
->hba_lock
);
274 tgt
= bnx2fc_tgt_lookup(port
, ntoh24(fh
->fh_d_id
));
275 if (tgt
&& (test_bit(BNX2FC_FLAG_SESSION_READY
, &tgt
->flags
))) {
276 /* This frame is for offloaded session */
277 BNX2FC_HBA_DBG(lport
, "xmit: Frame is for offloaded session "
278 "port_id = 0x%x\n", ntoh24(fh
->fh_d_id
));
279 spin_unlock_bh(&hba
->hba_lock
);
280 rc
= bnx2fc_xmit_l2_frame(tgt
, fp
);
286 spin_unlock_bh(&hba
->hba_lock
);
289 elen
= sizeof(struct ethhdr
);
290 hlen
= sizeof(struct fcoe_hdr
);
291 tlen
= sizeof(struct fcoe_crc_eof
);
292 wlen
= (skb
->len
- tlen
+ sizeof(crc
)) / FCOE_WORD_TO_BYTE
;
294 skb
->ip_summed
= CHECKSUM_NONE
;
295 crc
= fcoe_fc_crc(fp
);
297 /* copy port crc and eof to the skb buff */
298 if (skb_is_nonlinear(skb
)) {
300 if (bnx2fc_get_paged_crc_eof(skb
, tlen
)) {
304 frag
= &skb_shinfo(skb
)->frags
[skb_shinfo(skb
)->nr_frags
- 1];
305 cp
= kmap_atomic(skb_frag_page(frag
), KM_SKB_DATA_SOFTIRQ
)
308 cp
= (struct fcoe_crc_eof
*)skb_put(skb
, tlen
);
311 memset(cp
, 0, sizeof(*cp
));
313 cp
->fcoe_crc32
= cpu_to_le32(~crc
);
314 if (skb_is_nonlinear(skb
)) {
315 kunmap_atomic(cp
, KM_SKB_DATA_SOFTIRQ
);
319 /* adjust skb network/transport offsets to match mac/fcoe/port */
320 skb_push(skb
, elen
+ hlen
);
321 skb_reset_mac_header(skb
);
322 skb_reset_network_header(skb
);
324 skb
->protocol
= htons(ETH_P_FCOE
);
325 skb
->dev
= interface
->netdev
;
327 /* fill up mac and fcoe headers */
329 eh
->h_proto
= htons(ETH_P_FCOE
);
330 if (interface
->ctlr
.map_dest
)
331 fc_fcoe_set_mac(eh
->h_dest
, fh
->fh_d_id
);
333 /* insert GW address */
334 memcpy(eh
->h_dest
, interface
->ctlr
.dest_addr
, ETH_ALEN
);
336 if (unlikely(interface
->ctlr
.flogi_oxid
!= FC_XID_UNKNOWN
))
337 memcpy(eh
->h_source
, interface
->ctlr
.ctl_src_addr
, ETH_ALEN
);
339 memcpy(eh
->h_source
, port
->data_src_addr
, ETH_ALEN
);
341 hp
= (struct fcoe_hdr
*)(eh
+ 1);
342 memset(hp
, 0, sizeof(*hp
));
344 FC_FCOE_ENCAPS_VER(hp
, FC_FCOE_VER
);
347 /* fcoe lso, mss is in max_payload which is non-zero for FCP data */
348 if (lport
->seq_offload
&& fr_max_payload(fp
)) {
349 skb_shinfo(skb
)->gso_type
= SKB_GSO_FCOE
;
350 skb_shinfo(skb
)->gso_size
= fr_max_payload(fp
);
352 skb_shinfo(skb
)->gso_type
= 0;
353 skb_shinfo(skb
)->gso_size
= 0;
357 stats
= per_cpu_ptr(lport
->dev_stats
, get_cpu());
359 stats
->TxWords
+= wlen
;
362 /* send down to lld */
364 if (port
->fcoe_pending_queue
.qlen
)
365 fcoe_check_wait_queue(lport
, skb
);
366 else if (fcoe_start_io(skb
))
367 fcoe_check_wait_queue(lport
, skb
);
373 * bnx2fc_rcv - This is bnx2fc's receive function called by NET_RX_SOFTIRQ
375 * @skb: the receive socket buffer
376 * @dev: associated net device
378 * @olddev: last device
380 * This function receives the packet and builds FC frame and passes it up
382 static int bnx2fc_rcv(struct sk_buff
*skb
, struct net_device
*dev
,
383 struct packet_type
*ptype
, struct net_device
*olddev
)
385 struct fc_lport
*lport
;
386 struct bnx2fc_interface
*interface
;
387 struct fc_frame_header
*fh
;
388 struct fcoe_rcv_info
*fr
;
389 struct fcoe_percpu_s
*bg
;
392 interface
= container_of(ptype
, struct bnx2fc_interface
,
394 lport
= interface
->ctlr
.lp
;
396 if (unlikely(lport
== NULL
)) {
397 printk(KERN_ERR PFX
"bnx2fc_rcv: lport is NULL\n");
401 if (unlikely(eth_hdr(skb
)->h_proto
!= htons(ETH_P_FCOE
))) {
402 printk(KERN_ERR PFX
"bnx2fc_rcv: Wrong FC type frame\n");
407 * Check for minimum frame length, and make sure required FCoE
408 * and FC headers are pulled into the linear data area.
410 if (unlikely((skb
->len
< FCOE_MIN_FRAME
) ||
411 !pskb_may_pull(skb
, FCOE_HEADER_LEN
)))
414 skb_set_transport_header(skb
, sizeof(struct fcoe_hdr
));
415 fh
= (struct fc_frame_header
*) skb_transport_header(skb
);
417 oxid
= ntohs(fh
->fh_ox_id
);
419 fr
= fcoe_dev_from_skb(skb
);
423 spin_lock_bh(&bg
->fcoe_rx_list
.lock
);
425 __skb_queue_tail(&bg
->fcoe_rx_list
, skb
);
426 if (bg
->fcoe_rx_list
.qlen
== 1)
427 wake_up_process(bg
->thread
);
429 spin_unlock_bh(&bg
->fcoe_rx_list
.lock
);
437 static int bnx2fc_l2_rcv_thread(void *arg
)
439 struct fcoe_percpu_s
*bg
= arg
;
442 set_user_nice(current
, -20);
443 set_current_state(TASK_INTERRUPTIBLE
);
444 while (!kthread_should_stop()) {
446 spin_lock_bh(&bg
->fcoe_rx_list
.lock
);
447 while ((skb
= __skb_dequeue(&bg
->fcoe_rx_list
)) != NULL
) {
448 spin_unlock_bh(&bg
->fcoe_rx_list
.lock
);
449 bnx2fc_recv_frame(skb
);
450 spin_lock_bh(&bg
->fcoe_rx_list
.lock
);
452 __set_current_state(TASK_INTERRUPTIBLE
);
453 spin_unlock_bh(&bg
->fcoe_rx_list
.lock
);
455 __set_current_state(TASK_RUNNING
);
460 static void bnx2fc_recv_frame(struct sk_buff
*skb
)
463 struct fc_lport
*lport
;
464 struct fcoe_rcv_info
*fr
;
465 struct fcoe_dev_stats
*stats
;
466 struct fc_frame_header
*fh
;
467 struct fcoe_crc_eof crc_eof
;
469 struct fc_lport
*vn_port
;
470 struct fcoe_port
*port
;
475 fr
= fcoe_dev_from_skb(skb
);
477 if (unlikely(lport
== NULL
)) {
478 printk(KERN_ERR PFX
"Invalid lport struct\n");
483 if (skb_is_nonlinear(skb
))
485 mac
= eth_hdr(skb
)->h_source
;
486 dest_mac
= eth_hdr(skb
)->h_dest
;
488 /* Pull the header */
489 hp
= (struct fcoe_hdr
*) skb_network_header(skb
);
490 fh
= (struct fc_frame_header
*) skb_transport_header(skb
);
491 skb_pull(skb
, sizeof(struct fcoe_hdr
));
492 fr_len
= skb
->len
- sizeof(struct fcoe_crc_eof
);
494 stats
= per_cpu_ptr(lport
->dev_stats
, get_cpu());
496 stats
->RxWords
+= fr_len
/ FCOE_WORD_TO_BYTE
;
498 fp
= (struct fc_frame
*)skb
;
501 fr_sof(fp
) = hp
->fcoe_sof
;
502 if (skb_copy_bits(skb
, fr_len
, &crc_eof
, sizeof(crc_eof
))) {
507 fr_eof(fp
) = crc_eof
.fcoe_eof
;
508 fr_crc(fp
) = crc_eof
.fcoe_crc32
;
509 if (pskb_trim(skb
, fr_len
)) {
515 fh
= fc_frame_header_get(fp
);
517 vn_port
= fc_vport_id_lookup(lport
, ntoh24(fh
->fh_d_id
));
519 port
= lport_priv(vn_port
);
520 if (compare_ether_addr(port
->data_src_addr
, dest_mac
)
522 BNX2FC_HBA_DBG(lport
, "fpma mismatch\n");
528 if (fh
->fh_r_ctl
== FC_RCTL_DD_SOL_DATA
&&
529 fh
->fh_type
== FC_TYPE_FCP
) {
530 /* Drop FCP data. We dont this in L2 path */
535 if (fh
->fh_r_ctl
== FC_RCTL_ELS_REQ
&&
536 fh
->fh_type
== FC_TYPE_ELS
) {
537 switch (fc_frame_payload_op(fp
)) {
539 if (ntoh24(fh
->fh_s_id
) == FC_FID_FLOGI
) {
540 /* drop non-FIP LOGO */
548 if (le32_to_cpu(fr_crc(fp
)) !=
549 ~crc32(~0, skb
->data
, fr_len
)) {
550 if (stats
->InvalidCRCCount
< 5)
551 printk(KERN_WARNING PFX
"dropping frame with "
553 stats
->InvalidCRCCount
++;
559 fc_exch_recv(lport
, fp
);
563 * bnx2fc_percpu_io_thread - thread per cpu for ios
565 * @arg: ptr to bnx2fc_percpu_info structure
567 int bnx2fc_percpu_io_thread(void *arg
)
569 struct bnx2fc_percpu_s
*p
= arg
;
570 struct bnx2fc_work
*work
, *tmp
;
571 LIST_HEAD(work_list
);
573 set_user_nice(current
, -20);
574 set_current_state(TASK_INTERRUPTIBLE
);
575 while (!kthread_should_stop()) {
577 spin_lock_bh(&p
->fp_work_lock
);
578 while (!list_empty(&p
->work_list
)) {
579 list_splice_init(&p
->work_list
, &work_list
);
580 spin_unlock_bh(&p
->fp_work_lock
);
582 list_for_each_entry_safe(work
, tmp
, &work_list
, list
) {
583 list_del_init(&work
->list
);
584 bnx2fc_process_cq_compl(work
->tgt
, work
->wqe
);
588 spin_lock_bh(&p
->fp_work_lock
);
590 __set_current_state(TASK_INTERRUPTIBLE
);
591 spin_unlock_bh(&p
->fp_work_lock
);
593 __set_current_state(TASK_RUNNING
);
598 static struct fc_host_statistics
*bnx2fc_get_host_stats(struct Scsi_Host
*shost
)
600 struct fc_host_statistics
*bnx2fc_stats
;
601 struct fc_lport
*lport
= shost_priv(shost
);
602 struct fcoe_port
*port
= lport_priv(lport
);
603 struct bnx2fc_interface
*interface
= port
->priv
;
604 struct bnx2fc_hba
*hba
= interface
->hba
;
605 struct fcoe_statistics_params
*fw_stats
;
608 fw_stats
= (struct fcoe_statistics_params
*)hba
->stats_buffer
;
612 bnx2fc_stats
= fc_get_host_stats(shost
);
614 init_completion(&hba
->stat_req_done
);
615 if (bnx2fc_send_stat_req(hba
))
617 rc
= wait_for_completion_timeout(&hba
->stat_req_done
, (2 * HZ
));
619 BNX2FC_HBA_DBG(lport
, "FW stat req timed out\n");
622 bnx2fc_stats
->invalid_crc_count
+= fw_stats
->rx_stat2
.fc_crc_cnt
;
623 bnx2fc_stats
->tx_frames
+= fw_stats
->tx_stat
.fcoe_tx_pkt_cnt
;
624 bnx2fc_stats
->tx_words
+= (fw_stats
->tx_stat
.fcoe_tx_byte_cnt
) / 4;
625 bnx2fc_stats
->rx_frames
+= fw_stats
->rx_stat0
.fcoe_rx_pkt_cnt
;
626 bnx2fc_stats
->rx_words
+= (fw_stats
->rx_stat0
.fcoe_rx_byte_cnt
) / 4;
628 bnx2fc_stats
->dumped_frames
= 0;
629 bnx2fc_stats
->lip_count
= 0;
630 bnx2fc_stats
->nos_count
= 0;
631 bnx2fc_stats
->loss_of_sync_count
= 0;
632 bnx2fc_stats
->loss_of_signal_count
= 0;
633 bnx2fc_stats
->prim_seq_protocol_err_count
= 0;
638 static int bnx2fc_shost_config(struct fc_lport
*lport
, struct device
*dev
)
640 struct fcoe_port
*port
= lport_priv(lport
);
641 struct bnx2fc_interface
*interface
= port
->priv
;
642 struct Scsi_Host
*shost
= lport
->host
;
645 shost
->max_cmd_len
= BNX2FC_MAX_CMD_LEN
;
646 shost
->max_lun
= BNX2FC_MAX_LUN
;
647 shost
->max_id
= BNX2FC_MAX_FCP_TGT
;
648 shost
->max_channel
= 0;
650 shost
->transportt
= bnx2fc_vport_xport_template
;
652 shost
->transportt
= bnx2fc_transport_template
;
654 /* Add the new host to SCSI-ml */
655 rc
= scsi_add_host(lport
->host
, dev
);
657 printk(KERN_ERR PFX
"Error on scsi_add_host\n");
661 fc_host_max_npiv_vports(lport
->host
) = USHRT_MAX
;
662 sprintf(fc_host_symbolic_name(lport
->host
), "%s v%s over %s",
663 BNX2FC_NAME
, BNX2FC_VERSION
,
664 interface
->netdev
->name
);
669 static void bnx2fc_link_speed_update(struct fc_lport
*lport
)
671 struct fcoe_port
*port
= lport_priv(lport
);
672 struct bnx2fc_interface
*interface
= port
->priv
;
673 struct net_device
*netdev
= interface
->netdev
;
674 struct ethtool_cmd ecmd
;
676 if (!__ethtool_get_settings(netdev
, &ecmd
)) {
677 lport
->link_supported_speeds
&=
678 ~(FC_PORTSPEED_1GBIT
| FC_PORTSPEED_10GBIT
);
679 if (ecmd
.supported
& (SUPPORTED_1000baseT_Half
|
680 SUPPORTED_1000baseT_Full
))
681 lport
->link_supported_speeds
|= FC_PORTSPEED_1GBIT
;
682 if (ecmd
.supported
& SUPPORTED_10000baseT_Full
)
683 lport
->link_supported_speeds
|= FC_PORTSPEED_10GBIT
;
685 switch (ethtool_cmd_speed(&ecmd
)) {
687 lport
->link_speed
= FC_PORTSPEED_1GBIT
;
690 lport
->link_speed
= FC_PORTSPEED_2GBIT
;
693 lport
->link_speed
= FC_PORTSPEED_10GBIT
;
698 static int bnx2fc_link_ok(struct fc_lport
*lport
)
700 struct fcoe_port
*port
= lport_priv(lport
);
701 struct bnx2fc_interface
*interface
= port
->priv
;
702 struct bnx2fc_hba
*hba
= interface
->hba
;
703 struct net_device
*dev
= hba
->phys_dev
;
706 if ((dev
->flags
& IFF_UP
) && netif_carrier_ok(dev
))
707 clear_bit(ADAPTER_STATE_LINK_DOWN
, &hba
->adapter_state
);
709 set_bit(ADAPTER_STATE_LINK_DOWN
, &hba
->adapter_state
);
716 * bnx2fc_get_link_state - get network link state
718 * @hba: adapter instance pointer
720 * updates adapter structure flag based on netdev state
722 void bnx2fc_get_link_state(struct bnx2fc_hba
*hba
)
724 if (test_bit(__LINK_STATE_NOCARRIER
, &hba
->phys_dev
->state
))
725 set_bit(ADAPTER_STATE_LINK_DOWN
, &hba
->adapter_state
);
727 clear_bit(ADAPTER_STATE_LINK_DOWN
, &hba
->adapter_state
);
730 static int bnx2fc_net_config(struct fc_lport
*lport
)
732 struct bnx2fc_hba
*hba
;
733 struct bnx2fc_interface
*interface
;
734 struct fcoe_port
*port
;
737 port
= lport_priv(lport
);
738 interface
= port
->priv
;
739 hba
= interface
->hba
;
741 /* require support for get_pauseparam ethtool op. */
742 if (!hba
->phys_dev
->ethtool_ops
||
743 !hba
->phys_dev
->ethtool_ops
->get_pauseparam
)
746 if (fc_set_mfs(lport
, BNX2FC_MFS
))
749 skb_queue_head_init(&port
->fcoe_pending_queue
);
750 port
->fcoe_pending_queue_active
= 0;
751 setup_timer(&port
->timer
, fcoe_queue_timer
, (unsigned long) lport
);
753 bnx2fc_link_speed_update(lport
);
756 wwnn
= fcoe_wwn_from_mac(interface
->ctlr
.ctl_src_addr
, 1, 0);
757 BNX2FC_HBA_DBG(lport
, "WWNN = 0x%llx\n", wwnn
);
758 fc_set_wwnn(lport
, wwnn
);
760 wwpn
= fcoe_wwn_from_mac(interface
->ctlr
.ctl_src_addr
, 2, 0);
761 BNX2FC_HBA_DBG(lport
, "WWPN = 0x%llx\n", wwpn
);
762 fc_set_wwpn(lport
, wwpn
);
768 static void bnx2fc_destroy_timer(unsigned long data
)
770 struct bnx2fc_hba
*hba
= (struct bnx2fc_hba
*)data
;
772 BNX2FC_MISC_DBG("ERROR:bnx2fc_destroy_timer - "
773 "Destroy compl not received!!\n");
774 set_bit(BNX2FC_FLAG_DESTROY_CMPL
, &hba
->flags
);
775 wake_up_interruptible(&hba
->destroy_wait
);
779 * bnx2fc_indicate_netevent - Generic netdev event handler
781 * @context: adapter structure pointer
783 * @vlan_id: vlan id - associated vlan id with this event
785 * Handles NETDEV_UP, NETDEV_DOWN, NETDEV_GOING_DOWN,NETDEV_CHANGE and
786 * NETDEV_CHANGE_MTU events
788 static void bnx2fc_indicate_netevent(void *context
, unsigned long event
,
791 struct bnx2fc_hba
*hba
= (struct bnx2fc_hba
*)context
;
792 struct fc_lport
*lport
;
793 struct fc_lport
*vport
;
794 struct bnx2fc_interface
*interface
;
795 int wait_for_upload
= 0;
796 u32 link_possible
= 1;
798 /* Ignore vlans for now */
804 if (!test_bit(ADAPTER_STATE_UP
, &hba
->adapter_state
))
805 printk(KERN_ERR
"indicate_netevent: "\
806 "hba is not UP!!\n");
810 clear_bit(ADAPTER_STATE_GOING_DOWN
, &hba
->adapter_state
);
811 clear_bit(ADAPTER_STATE_UP
, &hba
->adapter_state
);
815 case NETDEV_GOING_DOWN
:
816 set_bit(ADAPTER_STATE_GOING_DOWN
, &hba
->adapter_state
);
824 printk(KERN_ERR PFX
"Unkonwn netevent %ld", event
);
828 mutex_lock(&bnx2fc_dev_lock
);
829 list_for_each_entry(interface
, &if_list
, list
) {
831 if (interface
->hba
!= hba
)
834 lport
= interface
->ctlr
.lp
;
835 BNX2FC_HBA_DBG(lport
, "netevent handler - event=%s %ld\n",
836 interface
->netdev
->name
, event
);
838 bnx2fc_link_speed_update(lport
);
840 if (link_possible
&& !bnx2fc_link_ok(lport
)) {
841 printk(KERN_ERR
"indicate_netevent: ctlr_link_up\n");
842 fcoe_ctlr_link_up(&interface
->ctlr
);
843 } else if (fcoe_ctlr_link_down(&interface
->ctlr
)) {
844 mutex_lock(&lport
->lp_mutex
);
845 list_for_each_entry(vport
, &lport
->vports
, list
)
846 fc_host_port_type(vport
->host
) =
848 mutex_unlock(&lport
->lp_mutex
);
849 fc_host_port_type(lport
->host
) = FC_PORTTYPE_UNKNOWN
;
850 per_cpu_ptr(lport
->dev_stats
,
851 get_cpu())->LinkFailureCount
++;
853 fcoe_clean_pending_queue(lport
);
857 mutex_unlock(&bnx2fc_dev_lock
);
859 if (wait_for_upload
) {
860 clear_bit(ADAPTER_STATE_READY
, &hba
->adapter_state
);
861 init_waitqueue_head(&hba
->shutdown_wait
);
862 BNX2FC_MISC_DBG("indicate_netevent "
863 "num_ofld_sess = %d\n",
865 hba
->wait_for_link_down
= 1;
866 wait_event_interruptible(hba
->shutdown_wait
,
867 (hba
->num_ofld_sess
== 0));
868 BNX2FC_MISC_DBG("wakeup - num_ofld_sess = %d\n",
870 hba
->wait_for_link_down
= 0;
872 if (signal_pending(current
))
873 flush_signals(current
);
877 static int bnx2fc_libfc_config(struct fc_lport
*lport
)
880 /* Set the function pointers set by bnx2fc driver */
881 memcpy(&lport
->tt
, &bnx2fc_libfc_fcn_templ
,
882 sizeof(struct libfc_function_template
));
883 fc_elsct_init(lport
);
885 fc_rport_init(lport
);
890 static int bnx2fc_em_config(struct fc_lport
*lport
)
892 if (!fc_exch_mgr_alloc(lport
, FC_CLASS_3
, FCOE_MIN_XID
,
893 FCOE_MAX_XID
, NULL
)) {
894 printk(KERN_ERR PFX
"em_config:fc_exch_mgr_alloc failed\n");
901 static int bnx2fc_lport_config(struct fc_lport
*lport
)
905 lport
->max_retry_count
= 3;
906 lport
->max_rport_retry_count
= 3;
907 lport
->e_d_tov
= 2 * 1000;
908 lport
->r_a_tov
= 10 * 1000;
910 lport
->service_params
= (FCP_SPPF_INIT_FCN
| FCP_SPPF_RD_XRDY_DIS
|
911 FCP_SPPF_RETRY
| FCP_SPPF_CONF_COMPL
);
912 lport
->does_npiv
= 1;
914 memset(&lport
->rnid_gen
, 0, sizeof(struct fc_els_rnid_gen
));
915 lport
->rnid_gen
.rnid_atype
= BNX2FC_RNID_HBA
;
917 /* alloc stats structure */
918 if (fc_lport_init_stats(lport
))
921 /* Finish fc_lport configuration */
922 fc_lport_config(lport
);
928 * bnx2fc_fip_recv - handle a received FIP frame.
930 * @skb: the received skb
931 * @dev: associated &net_device
932 * @ptype: the &packet_type structure which was used to register this handler.
933 * @orig_dev: original receive &net_device, in case @ dev is a bond.
935 * Returns: 0 for success
937 static int bnx2fc_fip_recv(struct sk_buff
*skb
, struct net_device
*dev
,
938 struct packet_type
*ptype
,
939 struct net_device
*orig_dev
)
941 struct bnx2fc_interface
*interface
;
942 interface
= container_of(ptype
, struct bnx2fc_interface
,
944 fcoe_ctlr_recv(&interface
->ctlr
, skb
);
949 * bnx2fc_update_src_mac - Update Ethernet MAC filters.
951 * @fip: FCoE controller.
952 * @old: Unicast MAC address to delete if the MAC is non-zero.
953 * @new: Unicast MAC address to add.
955 * Remove any previously-set unicast MAC filter.
956 * Add secondary FCoE MAC address filter for our OUI.
958 static void bnx2fc_update_src_mac(struct fc_lport
*lport
, u8
*addr
)
960 struct fcoe_port
*port
= lport_priv(lport
);
962 memcpy(port
->data_src_addr
, addr
, ETH_ALEN
);
966 * bnx2fc_get_src_mac - return the ethernet source address for an lport
970 static u8
*bnx2fc_get_src_mac(struct fc_lport
*lport
)
972 struct fcoe_port
*port
;
974 port
= (struct fcoe_port
*)lport_priv(lport
);
975 return port
->data_src_addr
;
979 * bnx2fc_fip_send - send an Ethernet-encapsulated FIP frame.
981 * @fip: FCoE controller.
984 static void bnx2fc_fip_send(struct fcoe_ctlr
*fip
, struct sk_buff
*skb
)
986 skb
->dev
= bnx2fc_from_ctlr(fip
)->netdev
;
990 static int bnx2fc_vport_create(struct fc_vport
*vport
, bool disabled
)
992 struct Scsi_Host
*shost
= vport_to_shost(vport
);
993 struct fc_lport
*n_port
= shost_priv(shost
);
994 struct fcoe_port
*port
= lport_priv(n_port
);
995 struct bnx2fc_interface
*interface
= port
->priv
;
996 struct net_device
*netdev
= interface
->netdev
;
997 struct fc_lport
*vn_port
;
999 if (!test_bit(BNX2FC_FLAG_FW_INIT_DONE
, &interface
->hba
->flags
)) {
1000 printk(KERN_ERR PFX
"vn ports cannot be created on"
1001 "this interface\n");
1005 mutex_lock(&bnx2fc_dev_lock
);
1006 vn_port
= bnx2fc_if_create(interface
, &vport
->dev
, 1);
1007 mutex_unlock(&bnx2fc_dev_lock
);
1010 if (IS_ERR(vn_port
)) {
1011 printk(KERN_ERR PFX
"bnx2fc_vport_create (%s) failed\n",
1017 fc_vport_set_state(vport
, FC_VPORT_DISABLED
);
1019 vn_port
->boot_time
= jiffies
;
1020 fc_lport_init(vn_port
);
1021 fc_fabric_login(vn_port
);
1022 fc_vport_setlink(vn_port
);
1027 static int bnx2fc_vport_destroy(struct fc_vport
*vport
)
1029 struct Scsi_Host
*shost
= vport_to_shost(vport
);
1030 struct fc_lport
*n_port
= shost_priv(shost
);
1031 struct fc_lport
*vn_port
= vport
->dd_data
;
1032 struct fcoe_port
*port
= lport_priv(vn_port
);
1034 mutex_lock(&n_port
->lp_mutex
);
1035 list_del(&vn_port
->list
);
1036 mutex_unlock(&n_port
->lp_mutex
);
1037 queue_work(bnx2fc_wq
, &port
->destroy_work
);
1041 static int bnx2fc_vport_disable(struct fc_vport
*vport
, bool disable
)
1043 struct fc_lport
*lport
= vport
->dd_data
;
1046 fc_vport_set_state(vport
, FC_VPORT_DISABLED
);
1047 fc_fabric_logoff(lport
);
1049 lport
->boot_time
= jiffies
;
1050 fc_fabric_login(lport
);
1051 fc_vport_setlink(lport
);
1057 static int bnx2fc_netdev_setup(struct bnx2fc_interface
*interface
)
1059 struct net_device
*netdev
= interface
->netdev
;
1060 struct net_device
*physdev
= interface
->hba
->phys_dev
;
1061 struct netdev_hw_addr
*ha
;
1062 int sel_san_mac
= 0;
1064 /* setup Source MAC Address */
1066 for_each_dev_addr(physdev
, ha
) {
1067 BNX2FC_MISC_DBG("net_config: ha->type = %d, fip_mac = ",
1069 printk(KERN_INFO
"%2x:%2x:%2x:%2x:%2x:%2x\n", ha
->addr
[0],
1070 ha
->addr
[1], ha
->addr
[2], ha
->addr
[3],
1071 ha
->addr
[4], ha
->addr
[5]);
1073 if ((ha
->type
== NETDEV_HW_ADDR_T_SAN
) &&
1074 (is_valid_ether_addr(ha
->addr
))) {
1075 memcpy(interface
->ctlr
.ctl_src_addr
, ha
->addr
,
1078 BNX2FC_MISC_DBG("Found SAN MAC\n");
1086 interface
->fip_packet_type
.func
= bnx2fc_fip_recv
;
1087 interface
->fip_packet_type
.type
= htons(ETH_P_FIP
);
1088 interface
->fip_packet_type
.dev
= netdev
;
1089 dev_add_pack(&interface
->fip_packet_type
);
1091 interface
->fcoe_packet_type
.func
= bnx2fc_rcv
;
1092 interface
->fcoe_packet_type
.type
= __constant_htons(ETH_P_FCOE
);
1093 interface
->fcoe_packet_type
.dev
= netdev
;
1094 dev_add_pack(&interface
->fcoe_packet_type
);
1099 static int bnx2fc_attach_transport(void)
1101 bnx2fc_transport_template
=
1102 fc_attach_transport(&bnx2fc_transport_function
);
1104 if (bnx2fc_transport_template
== NULL
) {
1105 printk(KERN_ERR PFX
"Failed to attach FC transport\n");
1109 bnx2fc_vport_xport_template
=
1110 fc_attach_transport(&bnx2fc_vport_xport_function
);
1111 if (bnx2fc_vport_xport_template
== NULL
) {
1113 "Failed to attach FC transport for vport\n");
1114 fc_release_transport(bnx2fc_transport_template
);
1115 bnx2fc_transport_template
= NULL
;
1120 static void bnx2fc_release_transport(void)
1122 fc_release_transport(bnx2fc_transport_template
);
1123 fc_release_transport(bnx2fc_vport_xport_template
);
1124 bnx2fc_transport_template
= NULL
;
1125 bnx2fc_vport_xport_template
= NULL
;
1128 static void bnx2fc_interface_release(struct kref
*kref
)
1130 struct bnx2fc_interface
*interface
;
1131 struct net_device
*netdev
;
1133 interface
= container_of(kref
, struct bnx2fc_interface
, kref
);
1134 BNX2FC_MISC_DBG("Interface is being released\n");
1136 netdev
= interface
->netdev
;
1138 /* tear-down FIP controller */
1139 if (test_and_clear_bit(BNX2FC_CTLR_INIT_DONE
, &interface
->if_flags
))
1140 fcoe_ctlr_destroy(&interface
->ctlr
);
1145 module_put(THIS_MODULE
);
1148 static inline void bnx2fc_interface_get(struct bnx2fc_interface
*interface
)
1150 kref_get(&interface
->kref
);
1153 static inline void bnx2fc_interface_put(struct bnx2fc_interface
*interface
)
1155 kref_put(&interface
->kref
, bnx2fc_interface_release
);
1157 static void bnx2fc_hba_destroy(struct bnx2fc_hba
*hba
)
1159 /* Free the command manager */
1161 bnx2fc_cmd_mgr_free(hba
->cmd_mgr
);
1162 hba
->cmd_mgr
= NULL
;
1164 kfree(hba
->tgt_ofld_list
);
1165 bnx2fc_unbind_pcidev(hba
);
1170 * bnx2fc_hba_create - create a new bnx2fc hba
1172 * @cnic: pointer to cnic device
1174 * Creates a new FCoE hba on the given device.
1177 static struct bnx2fc_hba
*bnx2fc_hba_create(struct cnic_dev
*cnic
)
1179 struct bnx2fc_hba
*hba
;
1182 hba
= kzalloc(sizeof(*hba
), GFP_KERNEL
);
1184 printk(KERN_ERR PFX
"Unable to allocate hba structure\n");
1187 spin_lock_init(&hba
->hba_lock
);
1188 mutex_init(&hba
->hba_mutex
);
1191 rc
= bnx2fc_bind_pcidev(hba
);
1193 printk(KERN_ERR PFX
"create_adapter: bind error\n");
1196 hba
->phys_dev
= cnic
->netdev
;
1197 hba
->next_conn_id
= 0;
1199 hba
->tgt_ofld_list
=
1200 kzalloc(sizeof(struct bnx2fc_rport
*) * BNX2FC_NUM_MAX_SESS
,
1202 if (!hba
->tgt_ofld_list
) {
1203 printk(KERN_ERR PFX
"Unable to allocate tgt offload list\n");
1207 hba
->num_ofld_sess
= 0;
1209 hba
->cmd_mgr
= bnx2fc_cmd_mgr_alloc(hba
, BNX2FC_MIN_XID
,
1211 if (!hba
->cmd_mgr
) {
1212 printk(KERN_ERR PFX
"em_config:bnx2fc_cmd_mgr_alloc failed\n");
1216 init_waitqueue_head(&hba
->shutdown_wait
);
1217 init_waitqueue_head(&hba
->destroy_wait
);
1218 INIT_LIST_HEAD(&hba
->vports
);
1223 kfree(hba
->tgt_ofld_list
);
1225 bnx2fc_unbind_pcidev(hba
);
1231 struct bnx2fc_interface
*bnx2fc_interface_create(struct bnx2fc_hba
*hba
,
1232 struct net_device
*netdev
,
1233 enum fip_state fip_mode
)
1235 struct bnx2fc_interface
*interface
;
1238 interface
= kzalloc(sizeof(*interface
), GFP_KERNEL
);
1240 printk(KERN_ERR PFX
"Unable to allocate interface structure\n");
1244 kref_init(&interface
->kref
);
1245 interface
->hba
= hba
;
1246 interface
->netdev
= netdev
;
1248 /* Initialize FIP */
1249 fcoe_ctlr_init(&interface
->ctlr
, fip_mode
);
1250 interface
->ctlr
.send
= bnx2fc_fip_send
;
1251 interface
->ctlr
.update_mac
= bnx2fc_update_src_mac
;
1252 interface
->ctlr
.get_src_addr
= bnx2fc_get_src_mac
;
1253 set_bit(BNX2FC_CTLR_INIT_DONE
, &interface
->if_flags
);
1255 rc
= bnx2fc_netdev_setup(interface
);
1259 fcoe_ctlr_destroy(&interface
->ctlr
);
1266 * bnx2fc_if_create - Create FCoE instance on a given interface
1268 * @interface: FCoE interface to create a local port on
1269 * @parent: Device pointer to be the parent in sysfs for the SCSI host
1270 * @npiv: Indicates if the port is vport or not
1272 * Creates a fc_lport instance and a Scsi_Host instance and configure them.
1274 * Returns: Allocated fc_lport or an error pointer
1276 static struct fc_lport
*bnx2fc_if_create(struct bnx2fc_interface
*interface
,
1277 struct device
*parent
, int npiv
)
1279 struct fc_lport
*lport
, *n_port
;
1280 struct fcoe_port
*port
;
1281 struct Scsi_Host
*shost
;
1282 struct fc_vport
*vport
= dev_to_vport(parent
);
1283 struct bnx2fc_lport
*blport
;
1284 struct bnx2fc_hba
*hba
;
1287 blport
= kzalloc(sizeof(struct bnx2fc_lport
), GFP_KERNEL
);
1289 BNX2FC_HBA_DBG(interface
->ctlr
.lp
, "Unable to alloc blport\n");
1293 /* Allocate Scsi_Host structure */
1295 lport
= libfc_host_alloc(&bnx2fc_shost_template
, sizeof(*port
));
1297 lport
= libfc_vport_create(vport
, sizeof(*port
));
1300 printk(KERN_ERR PFX
"could not allocate scsi host structure\n");
1303 shost
= lport
->host
;
1304 port
= lport_priv(lport
);
1305 port
->lport
= lport
;
1306 port
->priv
= interface
;
1307 INIT_WORK(&port
->destroy_work
, bnx2fc_destroy_work
);
1309 /* Configure fcoe_port */
1310 rc
= bnx2fc_lport_config(lport
);
1315 printk(KERN_ERR PFX
"Setting vport names, 0x%llX 0x%llX\n",
1316 vport
->node_name
, vport
->port_name
);
1317 fc_set_wwnn(lport
, vport
->node_name
);
1318 fc_set_wwpn(lport
, vport
->port_name
);
1320 /* Configure netdev and networking properties of the lport */
1321 rc
= bnx2fc_net_config(lport
);
1323 printk(KERN_ERR PFX
"Error on bnx2fc_net_config\n");
1327 rc
= bnx2fc_shost_config(lport
, parent
);
1329 printk(KERN_ERR PFX
"Couldnt configure shost for %s\n",
1330 interface
->netdev
->name
);
1334 /* Initialize the libfc library */
1335 rc
= bnx2fc_libfc_config(lport
);
1337 printk(KERN_ERR PFX
"Couldnt configure libfc\n");
1340 fc_host_port_type(lport
->host
) = FC_PORTTYPE_UNKNOWN
;
1342 /* Allocate exchange manager */
1344 rc
= bnx2fc_em_config(lport
);
1346 shost
= vport_to_shost(vport
);
1347 n_port
= shost_priv(shost
);
1348 rc
= fc_exch_mgr_list_clone(n_port
, lport
);
1352 printk(KERN_ERR PFX
"Error on bnx2fc_em_config\n");
1356 bnx2fc_interface_get(interface
);
1358 hba
= interface
->hba
;
1359 spin_lock_bh(&hba
->hba_lock
);
1360 blport
->lport
= lport
;
1361 list_add_tail(&blport
->list
, &hba
->vports
);
1362 spin_unlock_bh(&hba
->hba_lock
);
1367 scsi_remove_host(shost
);
1369 scsi_host_put(lport
->host
);
1375 static void bnx2fc_netdev_cleanup(struct bnx2fc_interface
*interface
)
1377 /* Dont listen for Ethernet packets anymore */
1378 __dev_remove_pack(&interface
->fcoe_packet_type
);
1379 __dev_remove_pack(&interface
->fip_packet_type
);
1383 static void bnx2fc_if_destroy(struct fc_lport
*lport
, struct bnx2fc_hba
*hba
)
1385 struct fcoe_port
*port
= lport_priv(lport
);
1386 struct bnx2fc_lport
*blport
, *tmp
;
1388 /* Stop the transmit retry timer */
1389 del_timer_sync(&port
->timer
);
1391 /* Free existing transmit skbs */
1392 fcoe_clean_pending_queue(lport
);
1394 /* Free queued packets for the receive thread */
1395 bnx2fc_clean_rx_queue(lport
);
1397 /* Detach from scsi-ml */
1398 fc_remove_host(lport
->host
);
1399 scsi_remove_host(lport
->host
);
1402 * Note that only the physical lport will have the exchange manager.
1403 * for vports, this function is NOP
1405 fc_exch_mgr_free(lport
);
1407 /* Free memory used by statistical counters */
1408 fc_lport_free_stats(lport
);
1410 spin_lock_bh(&hba
->hba_lock
);
1411 list_for_each_entry_safe(blport
, tmp
, &hba
->vports
, list
) {
1412 if (blport
->lport
== lport
) {
1413 list_del(&blport
->list
);
1417 spin_unlock_bh(&hba
->hba_lock
);
1419 /* Release Scsi_Host */
1420 scsi_host_put(lport
->host
);
1424 * bnx2fc_destroy - Destroy a bnx2fc FCoE interface
1426 * @buffer: The name of the Ethernet interface to be destroyed
1427 * @kp: The associated kernel parameter
1429 * Called from sysfs.
1431 * Returns: 0 for success
1433 static int bnx2fc_destroy(struct net_device
*netdev
)
1435 struct bnx2fc_interface
*interface
= NULL
;
1436 struct bnx2fc_hba
*hba
;
1437 struct fc_lport
*lport
;
1441 mutex_lock(&bnx2fc_dev_lock
);
1443 interface
= bnx2fc_interface_lookup(netdev
);
1444 if (!interface
|| !interface
->ctlr
.lp
) {
1446 printk(KERN_ERR PFX
"bnx2fc_destroy: interface or lport not found\n");
1450 hba
= interface
->hba
;
1452 bnx2fc_netdev_cleanup(interface
);
1453 lport
= interface
->ctlr
.lp
;
1454 bnx2fc_stop(interface
);
1455 list_del(&interface
->list
);
1456 destroy_workqueue(interface
->timer_work_queue
);
1457 bnx2fc_interface_put(interface
);
1458 bnx2fc_if_destroy(lport
, hba
);
1461 mutex_unlock(&bnx2fc_dev_lock
);
1466 static void bnx2fc_destroy_work(struct work_struct
*work
)
1468 struct fcoe_port
*port
;
1469 struct fc_lport
*lport
;
1470 struct bnx2fc_interface
*interface
;
1471 struct bnx2fc_hba
*hba
;
1473 port
= container_of(work
, struct fcoe_port
, destroy_work
);
1474 lport
= port
->lport
;
1475 interface
= port
->priv
;
1476 hba
= interface
->hba
;
1478 BNX2FC_HBA_DBG(lport
, "Entered bnx2fc_destroy_work\n");
1480 bnx2fc_port_shutdown(lport
);
1482 mutex_lock(&bnx2fc_dev_lock
);
1483 bnx2fc_if_destroy(lport
, hba
);
1484 mutex_unlock(&bnx2fc_dev_lock
);
1488 static void bnx2fc_unbind_adapter_devices(struct bnx2fc_hba
*hba
)
1490 bnx2fc_free_fw_resc(hba
);
1491 bnx2fc_free_task_ctx(hba
);
1495 * bnx2fc_bind_adapter_devices - binds bnx2fc adapter with the associated
1498 * @hba: Adapter instance
1500 static int bnx2fc_bind_adapter_devices(struct bnx2fc_hba
*hba
)
1502 if (bnx2fc_setup_task_ctx(hba
))
1505 if (bnx2fc_setup_fw_resc(hba
))
1510 bnx2fc_unbind_adapter_devices(hba
);
1514 static int bnx2fc_bind_pcidev(struct bnx2fc_hba
*hba
)
1516 struct cnic_dev
*cnic
;
1519 printk(KERN_ERR PFX
"cnic is NULL\n");
1523 hba
->pcidev
= cnic
->pcidev
;
1525 pci_dev_get(hba
->pcidev
);
1530 static void bnx2fc_unbind_pcidev(struct bnx2fc_hba
*hba
)
1533 pci_dev_put(hba
->pcidev
);
1540 * bnx2fc_ulp_start - cnic callback to initialize & start adapter instance
1542 * @handle: transport handle pointing to adapter struture
1544 * This function maps adapter structure to pcidev structure and initiates
1545 * firmware handshake to enable/initialize on-chip FCoE components.
1546 * This bnx2fc - cnic interface api callback is used after following
1547 * conditions are met -
1548 * a) underlying network interface is up (marked by event NETDEV_UP
1550 * b) bnx2fc adatper structure is registered.
1552 static void bnx2fc_ulp_start(void *handle
)
1554 struct bnx2fc_hba
*hba
= handle
;
1555 struct bnx2fc_interface
*interface
;
1556 struct fc_lport
*lport
;
1558 mutex_lock(&bnx2fc_dev_lock
);
1560 if (!test_bit(BNX2FC_FLAG_FW_INIT_DONE
, &hba
->flags
))
1561 bnx2fc_fw_init(hba
);
1563 BNX2FC_MISC_DBG("bnx2fc started.\n");
1565 list_for_each_entry(interface
, &if_list
, list
) {
1566 if (interface
->hba
== hba
) {
1567 lport
= interface
->ctlr
.lp
;
1568 /* Kick off Fabric discovery*/
1569 printk(KERN_ERR PFX
"ulp_init: start discovery\n");
1570 lport
->tt
.frame_send
= bnx2fc_xmit
;
1571 bnx2fc_start_disc(interface
);
1575 mutex_unlock(&bnx2fc_dev_lock
);
1578 static void bnx2fc_port_shutdown(struct fc_lport
*lport
)
1580 BNX2FC_MISC_DBG("Entered %s\n", __func__
);
1581 fc_fabric_logoff(lport
);
1582 fc_lport_destroy(lport
);
1585 static void bnx2fc_stop(struct bnx2fc_interface
*interface
)
1587 struct fc_lport
*lport
;
1588 struct fc_lport
*vport
;
1590 if (!test_bit(BNX2FC_FLAG_FW_INIT_DONE
, &interface
->hba
->flags
))
1593 lport
= interface
->ctlr
.lp
;
1594 bnx2fc_port_shutdown(lport
);
1596 mutex_lock(&lport
->lp_mutex
);
1597 list_for_each_entry(vport
, &lport
->vports
, list
)
1598 fc_host_port_type(vport
->host
) =
1599 FC_PORTTYPE_UNKNOWN
;
1600 mutex_unlock(&lport
->lp_mutex
);
1601 fc_host_port_type(lport
->host
) = FC_PORTTYPE_UNKNOWN
;
1602 fcoe_ctlr_link_down(&interface
->ctlr
);
1603 fcoe_clean_pending_queue(lport
);
1606 static int bnx2fc_fw_init(struct bnx2fc_hba
*hba
)
1608 #define BNX2FC_INIT_POLL_TIME (1000 / HZ)
1612 rc
= bnx2fc_bind_adapter_devices(hba
);
1614 printk(KERN_ALERT PFX
1615 "bnx2fc_bind_adapter_devices failed - rc = %d\n", rc
);
1619 rc
= bnx2fc_send_fw_fcoe_init_msg(hba
);
1621 printk(KERN_ALERT PFX
1622 "bnx2fc_send_fw_fcoe_init_msg failed - rc = %d\n", rc
);
1627 * Wait until the adapter init message is complete, and adapter
1630 while (!test_bit(ADAPTER_STATE_UP
, &hba
->adapter_state
) && i
--)
1631 msleep(BNX2FC_INIT_POLL_TIME
);
1633 if (!test_bit(ADAPTER_STATE_UP
, &hba
->adapter_state
)) {
1634 printk(KERN_ERR PFX
"bnx2fc_start: %s failed to initialize. "
1636 hba
->cnic
->netdev
->name
);
1642 set_bit(BNX2FC_FLAG_FW_INIT_DONE
, &hba
->flags
);
1646 bnx2fc_unbind_adapter_devices(hba
);
1651 static void bnx2fc_fw_destroy(struct bnx2fc_hba
*hba
)
1653 if (test_and_clear_bit(BNX2FC_FLAG_FW_INIT_DONE
, &hba
->flags
)) {
1654 if (bnx2fc_send_fw_fcoe_destroy_msg(hba
) == 0) {
1655 init_timer(&hba
->destroy_timer
);
1656 hba
->destroy_timer
.expires
= BNX2FC_FW_TIMEOUT
+
1658 hba
->destroy_timer
.function
= bnx2fc_destroy_timer
;
1659 hba
->destroy_timer
.data
= (unsigned long)hba
;
1660 add_timer(&hba
->destroy_timer
);
1661 wait_event_interruptible(hba
->destroy_wait
,
1662 test_bit(BNX2FC_FLAG_DESTROY_CMPL
,
1664 /* This should never happen */
1665 if (signal_pending(current
))
1666 flush_signals(current
);
1668 del_timer_sync(&hba
->destroy_timer
);
1670 bnx2fc_unbind_adapter_devices(hba
);
1675 * bnx2fc_ulp_stop - cnic callback to shutdown adapter instance
1677 * @handle: transport handle pointing to adapter structure
1679 * Driver checks if adapter is already in shutdown mode, if not start
1680 * the shutdown process.
1682 static void bnx2fc_ulp_stop(void *handle
)
1684 struct bnx2fc_hba
*hba
= handle
;
1685 struct bnx2fc_interface
*interface
;
1687 printk(KERN_ERR
"ULP_STOP\n");
1689 mutex_lock(&bnx2fc_dev_lock
);
1690 if (!test_bit(BNX2FC_FLAG_FW_INIT_DONE
, &hba
->flags
))
1692 list_for_each_entry(interface
, &if_list
, list
) {
1693 if (interface
->hba
== hba
)
1694 bnx2fc_stop(interface
);
1696 BUG_ON(hba
->num_ofld_sess
!= 0);
1698 mutex_lock(&hba
->hba_mutex
);
1699 clear_bit(ADAPTER_STATE_UP
, &hba
->adapter_state
);
1700 clear_bit(ADAPTER_STATE_GOING_DOWN
,
1701 &hba
->adapter_state
);
1703 clear_bit(ADAPTER_STATE_READY
, &hba
->adapter_state
);
1704 mutex_unlock(&hba
->hba_mutex
);
1706 bnx2fc_fw_destroy(hba
);
1708 mutex_unlock(&bnx2fc_dev_lock
);
1711 static void bnx2fc_start_disc(struct bnx2fc_interface
*interface
)
1713 struct fc_lport
*lport
;
1716 BNX2FC_MISC_DBG("Entered %s\n", __func__
);
1717 /* Kick off FIP/FLOGI */
1718 if (!test_bit(BNX2FC_FLAG_FW_INIT_DONE
, &interface
->hba
->flags
)) {
1719 printk(KERN_ERR PFX
"Init not done yet\n");
1723 lport
= interface
->ctlr
.lp
;
1724 BNX2FC_HBA_DBG(lport
, "calling fc_fabric_login\n");
1726 if (!bnx2fc_link_ok(lport
)) {
1727 BNX2FC_HBA_DBG(lport
, "ctlr_link_up\n");
1728 fcoe_ctlr_link_up(&interface
->ctlr
);
1729 fc_host_port_type(lport
->host
) = FC_PORTTYPE_NPORT
;
1730 set_bit(ADAPTER_STATE_READY
, &interface
->hba
->adapter_state
);
1733 /* wait for the FCF to be selected before issuing FLOGI */
1734 while (!interface
->ctlr
.sel_fcf
) {
1736 /* give up after 3 secs */
1737 if (++wait_cnt
> 12)
1740 fc_lport_init(lport
);
1741 fc_fabric_login(lport
);
1746 * bnx2fc_ulp_init - Initialize an adapter instance
1748 * @dev : cnic device handle
1749 * Called from cnic_register_driver() context to initialize all
1750 * enumerated cnic devices. This routine allocates adapter structure
1751 * and other device specific resources.
1753 static void bnx2fc_ulp_init(struct cnic_dev
*dev
)
1755 struct bnx2fc_hba
*hba
;
1758 BNX2FC_MISC_DBG("Entered %s\n", __func__
);
1759 /* bnx2fc works only when bnx2x is loaded */
1760 if (!test_bit(CNIC_F_BNX2X_CLASS
, &dev
->flags
) ||
1761 (dev
->max_fcoe_conn
== 0)) {
1762 printk(KERN_ERR PFX
"bnx2fc FCoE not supported on %s,"
1763 " flags: %lx fcoe_conn: %d\n",
1764 dev
->netdev
->name
, dev
->flags
, dev
->max_fcoe_conn
);
1768 hba
= bnx2fc_hba_create(dev
);
1770 printk(KERN_ERR PFX
"hba initialization failed\n");
1774 /* Add HBA to the adapter list */
1775 mutex_lock(&bnx2fc_dev_lock
);
1776 list_add_tail(&hba
->list
, &adapter_list
);
1778 mutex_unlock(&bnx2fc_dev_lock
);
1780 clear_bit(BNX2FC_CNIC_REGISTERED
, &hba
->reg_with_cnic
);
1781 rc
= dev
->register_device(dev
, CNIC_ULP_FCOE
,
1784 printk(KERN_ERR PFX
"register_device failed, rc = %d\n", rc
);
1786 set_bit(BNX2FC_CNIC_REGISTERED
, &hba
->reg_with_cnic
);
1790 static int bnx2fc_disable(struct net_device
*netdev
)
1792 struct bnx2fc_interface
*interface
;
1796 mutex_lock(&bnx2fc_dev_lock
);
1798 interface
= bnx2fc_interface_lookup(netdev
);
1799 if (!interface
|| !interface
->ctlr
.lp
) {
1801 printk(KERN_ERR PFX
"bnx2fc_disable: interface or lport not found\n");
1803 fcoe_ctlr_link_down(&interface
->ctlr
);
1804 fcoe_clean_pending_queue(interface
->ctlr
.lp
);
1807 mutex_unlock(&bnx2fc_dev_lock
);
1813 static int bnx2fc_enable(struct net_device
*netdev
)
1815 struct bnx2fc_interface
*interface
;
1819 mutex_lock(&bnx2fc_dev_lock
);
1821 interface
= bnx2fc_interface_lookup(netdev
);
1822 if (!interface
|| !interface
->ctlr
.lp
) {
1824 printk(KERN_ERR PFX
"bnx2fc_enable: interface or lport not found\n");
1825 } else if (!bnx2fc_link_ok(interface
->ctlr
.lp
))
1826 fcoe_ctlr_link_up(&interface
->ctlr
);
1828 mutex_unlock(&bnx2fc_dev_lock
);
1834 * bnx2fc_create - Create bnx2fc FCoE interface
1836 * @buffer: The name of Ethernet interface to create on
1837 * @kp: The associated kernel param
1839 * Called from sysfs.
1841 * Returns: 0 for success
1843 static int bnx2fc_create(struct net_device
*netdev
, enum fip_state fip_mode
)
1845 struct bnx2fc_interface
*interface
;
1846 struct bnx2fc_hba
*hba
;
1847 struct net_device
*phys_dev
;
1848 struct fc_lport
*lport
;
1849 struct ethtool_drvinfo drvinfo
;
1853 BNX2FC_MISC_DBG("Entered bnx2fc_create\n");
1854 if (fip_mode
!= FIP_MODE_FABRIC
) {
1855 printk(KERN_ERR
"fip mode not FABRIC\n");
1861 mutex_lock(&bnx2fc_dev_lock
);
1863 if (!try_module_get(THIS_MODULE
)) {
1868 /* obtain physical netdev */
1869 if (netdev
->priv_flags
& IFF_802_1Q_VLAN
) {
1870 phys_dev
= vlan_dev_real_dev(netdev
);
1871 vlan_id
= vlan_dev_vlan_id(netdev
);
1873 printk(KERN_ERR PFX
"Not a vlan device\n");
1877 /* verify if the physical device is a netxtreme2 device */
1878 if (phys_dev
->ethtool_ops
&& phys_dev
->ethtool_ops
->get_drvinfo
) {
1879 memset(&drvinfo
, 0, sizeof(drvinfo
));
1880 phys_dev
->ethtool_ops
->get_drvinfo(phys_dev
, &drvinfo
);
1881 if (strncmp(drvinfo
.driver
, "bnx2x", strlen("bnx2x"))) {
1882 printk(KERN_ERR PFX
"Not a netxtreme2 device\n");
1887 printk(KERN_ERR PFX
"unable to obtain drv_info\n");
1892 /* obtain interface and initialize rest of the structure */
1893 hba
= bnx2fc_hba_lookup(phys_dev
);
1896 printk(KERN_ERR PFX
"bnx2fc_create: hba not found\n");
1900 if (bnx2fc_interface_lookup(netdev
)) {
1905 interface
= bnx2fc_interface_create(hba
, netdev
, fip_mode
);
1907 printk(KERN_ERR PFX
"bnx2fc_interface_create failed\n");
1911 interface
->vlan_id
= vlan_id
;
1912 interface
->vlan_enabled
= 1;
1914 interface
->timer_work_queue
=
1915 create_singlethread_workqueue("bnx2fc_timer_wq");
1916 if (!interface
->timer_work_queue
) {
1917 printk(KERN_ERR PFX
"ulp_init could not create timer_wq\n");
1922 lport
= bnx2fc_if_create(interface
, &interface
->hba
->pcidev
->dev
, 0);
1924 printk(KERN_ERR PFX
"Failed to create interface (%s)\n",
1926 bnx2fc_netdev_cleanup(interface
);
1931 /* Add interface to if_list */
1932 list_add_tail(&interface
->list
, &if_list
);
1934 lport
->boot_time
= jiffies
;
1936 /* Make this master N_port */
1937 interface
->ctlr
.lp
= lport
;
1939 BNX2FC_HBA_DBG(lport
, "create: START DISC\n");
1940 bnx2fc_start_disc(interface
);
1942 * Release from kref_init in bnx2fc_interface_setup, on success
1943 * lport should be holding a reference taken in bnx2fc_if_create
1945 bnx2fc_interface_put(interface
);
1946 /* put netdev that was held while calling dev_get_by_name */
1947 mutex_unlock(&bnx2fc_dev_lock
);
1952 destroy_workqueue(interface
->timer_work_queue
);
1954 bnx2fc_interface_put(interface
);
1956 module_put(THIS_MODULE
);
1958 mutex_unlock(&bnx2fc_dev_lock
);
1964 * bnx2fc_find_hba_for_cnic - maps cnic instance to bnx2fc hba instance
1966 * @cnic: Pointer to cnic device instance
1969 static struct bnx2fc_hba
*bnx2fc_find_hba_for_cnic(struct cnic_dev
*cnic
)
1971 struct list_head
*list
;
1972 struct list_head
*temp
;
1973 struct bnx2fc_hba
*hba
;
1975 /* Called with bnx2fc_dev_lock held */
1976 list_for_each_safe(list
, temp
, &adapter_list
) {
1977 hba
= (struct bnx2fc_hba
*)list
;
1978 if (hba
->cnic
== cnic
)
1984 static struct bnx2fc_interface
*bnx2fc_interface_lookup(struct net_device
1987 struct bnx2fc_interface
*interface
;
1989 /* Called with bnx2fc_dev_lock held */
1990 list_for_each_entry(interface
, &if_list
, list
) {
1991 if (interface
->netdev
== netdev
)
1997 static struct bnx2fc_hba
*bnx2fc_hba_lookup(struct net_device
2000 struct bnx2fc_hba
*hba
;
2002 /* Called with bnx2fc_dev_lock held */
2003 list_for_each_entry(hba
, &adapter_list
, list
) {
2004 if (hba
->phys_dev
== phys_dev
)
2007 printk(KERN_ERR PFX
"adapter_lookup: hba NULL\n");
2012 * bnx2fc_ulp_exit - shuts down adapter instance and frees all resources
2014 * @dev cnic device handle
2016 static void bnx2fc_ulp_exit(struct cnic_dev
*dev
)
2018 struct bnx2fc_hba
*hba
;
2019 struct bnx2fc_interface
*interface
, *tmp
;
2020 struct fc_lport
*lport
;
2022 BNX2FC_MISC_DBG("Entered bnx2fc_ulp_exit\n");
2024 if (!test_bit(CNIC_F_BNX2X_CLASS
, &dev
->flags
)) {
2025 printk(KERN_ERR PFX
"bnx2fc port check: %s, flags: %lx\n",
2026 dev
->netdev
->name
, dev
->flags
);
2030 mutex_lock(&bnx2fc_dev_lock
);
2031 hba
= bnx2fc_find_hba_for_cnic(dev
);
2033 printk(KERN_ERR PFX
"bnx2fc_ulp_exit: hba not found, dev 0%p\n",
2035 mutex_unlock(&bnx2fc_dev_lock
);
2039 list_del_init(&hba
->list
);
2042 list_for_each_entry_safe(interface
, tmp
, &if_list
, list
) {
2043 /* destroy not called yet, move to quiesced list */
2044 if (interface
->hba
== hba
) {
2045 bnx2fc_netdev_cleanup(interface
);
2046 bnx2fc_stop(interface
);
2048 list_del(&interface
->list
);
2049 lport
= interface
->ctlr
.lp
;
2050 bnx2fc_interface_put(interface
);
2051 bnx2fc_if_destroy(lport
, hba
);
2054 mutex_unlock(&bnx2fc_dev_lock
);
2056 bnx2fc_ulp_stop(hba
);
2057 /* unregister cnic device */
2058 if (test_and_clear_bit(BNX2FC_CNIC_REGISTERED
, &hba
->reg_with_cnic
))
2059 hba
->cnic
->unregister_device(hba
->cnic
, CNIC_ULP_FCOE
);
2060 bnx2fc_hba_destroy(hba
);
2064 * bnx2fc_fcoe_reset - Resets the fcoe
2066 * @shost: shost the reset is from
2070 static int bnx2fc_fcoe_reset(struct Scsi_Host
*shost
)
2072 struct fc_lport
*lport
= shost_priv(shost
);
2073 fc_lport_reset(lport
);
2078 static bool bnx2fc_match(struct net_device
*netdev
)
2080 mutex_lock(&bnx2fc_dev_lock
);
2081 if (netdev
->priv_flags
& IFF_802_1Q_VLAN
) {
2082 struct net_device
*phys_dev
= vlan_dev_real_dev(netdev
);
2084 if (bnx2fc_hba_lookup(phys_dev
)) {
2085 mutex_unlock(&bnx2fc_dev_lock
);
2089 mutex_unlock(&bnx2fc_dev_lock
);
2094 static struct fcoe_transport bnx2fc_transport
= {
2097 .list
= LIST_HEAD_INIT(bnx2fc_transport
.list
),
2098 .match
= bnx2fc_match
,
2099 .create
= bnx2fc_create
,
2100 .destroy
= bnx2fc_destroy
,
2101 .enable
= bnx2fc_enable
,
2102 .disable
= bnx2fc_disable
,
2106 * bnx2fc_percpu_thread_create - Create a receive thread for an
2109 * @cpu: cpu index for the online cpu
2111 static void bnx2fc_percpu_thread_create(unsigned int cpu
)
2113 struct bnx2fc_percpu_s
*p
;
2114 struct task_struct
*thread
;
2116 p
= &per_cpu(bnx2fc_percpu
, cpu
);
2118 thread
= kthread_create(bnx2fc_percpu_io_thread
,
2120 "bnx2fc_thread/%d", cpu
);
2121 /* bind thread to the cpu */
2122 if (likely(!IS_ERR(p
->iothread
))) {
2123 kthread_bind(thread
, cpu
);
2124 p
->iothread
= thread
;
2125 wake_up_process(thread
);
2129 static void bnx2fc_percpu_thread_destroy(unsigned int cpu
)
2131 struct bnx2fc_percpu_s
*p
;
2132 struct task_struct
*thread
;
2133 struct bnx2fc_work
*work
, *tmp
;
2134 LIST_HEAD(work_list
);
2136 BNX2FC_MISC_DBG("destroying io thread for CPU %d\n", cpu
);
2138 /* Prevent any new work from being queued for this CPU */
2139 p
= &per_cpu(bnx2fc_percpu
, cpu
);
2140 spin_lock_bh(&p
->fp_work_lock
);
2141 thread
= p
->iothread
;
2145 /* Free all work in the list */
2146 list_for_each_entry_safe(work
, tmp
, &work_list
, list
) {
2147 list_del_init(&work
->list
);
2148 bnx2fc_process_cq_compl(work
->tgt
, work
->wqe
);
2152 spin_unlock_bh(&p
->fp_work_lock
);
2155 kthread_stop(thread
);
2159 * bnx2fc_cpu_callback - Handler for CPU hotplug events
2161 * @nfb: The callback data block
2162 * @action: The event triggering the callback
2163 * @hcpu: The index of the CPU that the event is for
2165 * This creates or destroys per-CPU data for fcoe
2167 * Returns NOTIFY_OK always.
2169 static int bnx2fc_cpu_callback(struct notifier_block
*nfb
,
2170 unsigned long action
, void *hcpu
)
2172 unsigned cpu
= (unsigned long)hcpu
;
2176 case CPU_ONLINE_FROZEN
:
2177 printk(PFX
"CPU %x online: Create Rx thread\n", cpu
);
2178 bnx2fc_percpu_thread_create(cpu
);
2181 case CPU_DEAD_FROZEN
:
2182 printk(PFX
"CPU %x offline: Remove Rx thread\n", cpu
);
2183 bnx2fc_percpu_thread_destroy(cpu
);
2192 * bnx2fc_mod_init - module init entry point
2194 * Initialize driver wide global data structures, and register
2197 static int __init
bnx2fc_mod_init(void)
2199 struct fcoe_percpu_s
*bg
;
2200 struct task_struct
*l2_thread
;
2202 unsigned int cpu
= 0;
2203 struct bnx2fc_percpu_s
*p
;
2205 printk(KERN_INFO PFX
"%s", version
);
2207 /* register as a fcoe transport */
2208 rc
= fcoe_transport_attach(&bnx2fc_transport
);
2210 printk(KERN_ERR
"failed to register an fcoe transport, check "
2211 "if libfcoe is loaded\n");
2215 INIT_LIST_HEAD(&adapter_list
);
2216 INIT_LIST_HEAD(&if_list
);
2217 mutex_init(&bnx2fc_dev_lock
);
2220 /* Attach FC transport template */
2221 rc
= bnx2fc_attach_transport();
2225 bnx2fc_wq
= alloc_workqueue("bnx2fc", 0, 0);
2231 bg
= &bnx2fc_global
;
2232 skb_queue_head_init(&bg
->fcoe_rx_list
);
2233 l2_thread
= kthread_create(bnx2fc_l2_rcv_thread
,
2235 "bnx2fc_l2_thread");
2236 if (IS_ERR(l2_thread
)) {
2237 rc
= PTR_ERR(l2_thread
);
2240 wake_up_process(l2_thread
);
2241 spin_lock_bh(&bg
->fcoe_rx_list
.lock
);
2242 bg
->thread
= l2_thread
;
2243 spin_unlock_bh(&bg
->fcoe_rx_list
.lock
);
2245 for_each_possible_cpu(cpu
) {
2246 p
= &per_cpu(bnx2fc_percpu
, cpu
);
2247 INIT_LIST_HEAD(&p
->work_list
);
2248 spin_lock_init(&p
->fp_work_lock
);
2251 for_each_online_cpu(cpu
) {
2252 bnx2fc_percpu_thread_create(cpu
);
2255 /* Initialize per CPU interrupt thread */
2256 register_hotcpu_notifier(&bnx2fc_cpu_notifier
);
2258 cnic_register_driver(CNIC_ULP_FCOE
, &bnx2fc_cnic_cb
);
2263 destroy_workqueue(bnx2fc_wq
);
2265 bnx2fc_release_transport();
2267 fcoe_transport_detach(&bnx2fc_transport
);
2272 static void __exit
bnx2fc_mod_exit(void)
2274 LIST_HEAD(to_be_deleted
);
2275 struct bnx2fc_hba
*hba
, *next
;
2276 struct fcoe_percpu_s
*bg
;
2277 struct task_struct
*l2_thread
;
2278 struct sk_buff
*skb
;
2279 unsigned int cpu
= 0;
2282 * NOTE: Since cnic calls register_driver routine rtnl_lock,
2283 * it will have higher precedence than bnx2fc_dev_lock.
2284 * unregister_device() cannot be called with bnx2fc_dev_lock
2287 mutex_lock(&bnx2fc_dev_lock
);
2288 list_splice(&adapter_list
, &to_be_deleted
);
2289 INIT_LIST_HEAD(&adapter_list
);
2291 mutex_unlock(&bnx2fc_dev_lock
);
2293 /* Unregister with cnic */
2294 list_for_each_entry_safe(hba
, next
, &to_be_deleted
, list
) {
2295 list_del_init(&hba
->list
);
2296 printk(KERN_ERR PFX
"MOD_EXIT:destroy hba = 0x%p\n",
2298 bnx2fc_ulp_stop(hba
);
2299 /* unregister cnic device */
2300 if (test_and_clear_bit(BNX2FC_CNIC_REGISTERED
,
2301 &hba
->reg_with_cnic
))
2302 hba
->cnic
->unregister_device(hba
->cnic
,
2304 bnx2fc_hba_destroy(hba
);
2306 cnic_unregister_driver(CNIC_ULP_FCOE
);
2308 /* Destroy global thread */
2309 bg
= &bnx2fc_global
;
2310 spin_lock_bh(&bg
->fcoe_rx_list
.lock
);
2311 l2_thread
= bg
->thread
;
2313 while ((skb
= __skb_dequeue(&bg
->fcoe_rx_list
)) != NULL
)
2316 spin_unlock_bh(&bg
->fcoe_rx_list
.lock
);
2319 kthread_stop(l2_thread
);
2321 unregister_hotcpu_notifier(&bnx2fc_cpu_notifier
);
2323 /* Destroy per cpu threads */
2324 for_each_online_cpu(cpu
) {
2325 bnx2fc_percpu_thread_destroy(cpu
);
2328 destroy_workqueue(bnx2fc_wq
);
2330 * detach from scsi transport
2331 * must happen after all destroys are done
2333 bnx2fc_release_transport();
2335 /* detach from fcoe transport */
2336 fcoe_transport_detach(&bnx2fc_transport
);
2339 module_init(bnx2fc_mod_init
);
2340 module_exit(bnx2fc_mod_exit
);
2342 static struct fc_function_template bnx2fc_transport_function
= {
2343 .show_host_node_name
= 1,
2344 .show_host_port_name
= 1,
2345 .show_host_supported_classes
= 1,
2346 .show_host_supported_fc4s
= 1,
2347 .show_host_active_fc4s
= 1,
2348 .show_host_maxframe_size
= 1,
2350 .show_host_port_id
= 1,
2351 .show_host_supported_speeds
= 1,
2352 .get_host_speed
= fc_get_host_speed
,
2353 .show_host_speed
= 1,
2354 .show_host_port_type
= 1,
2355 .get_host_port_state
= fc_get_host_port_state
,
2356 .show_host_port_state
= 1,
2357 .show_host_symbolic_name
= 1,
2359 .dd_fcrport_size
= (sizeof(struct fc_rport_libfc_priv
) +
2360 sizeof(struct bnx2fc_rport
)),
2361 .show_rport_maxframe_size
= 1,
2362 .show_rport_supported_classes
= 1,
2364 .show_host_fabric_name
= 1,
2365 .show_starget_node_name
= 1,
2366 .show_starget_port_name
= 1,
2367 .show_starget_port_id
= 1,
2368 .set_rport_dev_loss_tmo
= fc_set_rport_loss_tmo
,
2369 .show_rport_dev_loss_tmo
= 1,
2370 .get_fc_host_stats
= bnx2fc_get_host_stats
,
2372 .issue_fc_host_lip
= bnx2fc_fcoe_reset
,
2374 .terminate_rport_io
= fc_rport_terminate_io
,
2376 .vport_create
= bnx2fc_vport_create
,
2377 .vport_delete
= bnx2fc_vport_destroy
,
2378 .vport_disable
= bnx2fc_vport_disable
,
2381 static struct fc_function_template bnx2fc_vport_xport_function
= {
2382 .show_host_node_name
= 1,
2383 .show_host_port_name
= 1,
2384 .show_host_supported_classes
= 1,
2385 .show_host_supported_fc4s
= 1,
2386 .show_host_active_fc4s
= 1,
2387 .show_host_maxframe_size
= 1,
2389 .show_host_port_id
= 1,
2390 .show_host_supported_speeds
= 1,
2391 .get_host_speed
= fc_get_host_speed
,
2392 .show_host_speed
= 1,
2393 .show_host_port_type
= 1,
2394 .get_host_port_state
= fc_get_host_port_state
,
2395 .show_host_port_state
= 1,
2396 .show_host_symbolic_name
= 1,
2398 .dd_fcrport_size
= (sizeof(struct fc_rport_libfc_priv
) +
2399 sizeof(struct bnx2fc_rport
)),
2400 .show_rport_maxframe_size
= 1,
2401 .show_rport_supported_classes
= 1,
2403 .show_host_fabric_name
= 1,
2404 .show_starget_node_name
= 1,
2405 .show_starget_port_name
= 1,
2406 .show_starget_port_id
= 1,
2407 .set_rport_dev_loss_tmo
= fc_set_rport_loss_tmo
,
2408 .show_rport_dev_loss_tmo
= 1,
2409 .get_fc_host_stats
= fc_get_host_stats
,
2410 .issue_fc_host_lip
= bnx2fc_fcoe_reset
,
2411 .terminate_rport_io
= fc_rport_terminate_io
,
2415 * scsi_host_template structure used while registering with SCSI-ml
2417 static struct scsi_host_template bnx2fc_shost_template
= {
2418 .module
= THIS_MODULE
,
2419 .name
= "Broadcom Offload FCoE Initiator",
2420 .queuecommand
= bnx2fc_queuecommand
,
2421 .eh_abort_handler
= bnx2fc_eh_abort
, /* abts */
2422 .eh_device_reset_handler
= bnx2fc_eh_device_reset
, /* lun reset */
2423 .eh_target_reset_handler
= bnx2fc_eh_target_reset
, /* tgt reset */
2424 .eh_host_reset_handler
= fc_eh_host_reset
,
2425 .slave_alloc
= fc_slave_alloc
,
2426 .change_queue_depth
= fc_change_queue_depth
,
2427 .change_queue_type
= fc_change_queue_type
,
2430 .can_queue
= BNX2FC_CAN_QUEUE
,
2431 .use_clustering
= ENABLE_CLUSTERING
,
2432 .sg_tablesize
= BNX2FC_MAX_BDS_PER_CMD
,
2436 static struct libfc_function_template bnx2fc_libfc_fcn_templ
= {
2437 .frame_send
= bnx2fc_xmit
,
2438 .elsct_send
= bnx2fc_elsct_send
,
2439 .fcp_abort_io
= bnx2fc_abort_io
,
2440 .fcp_cleanup
= bnx2fc_cleanup
,
2441 .rport_event_callback
= bnx2fc_rport_event_handler
,
2445 * bnx2fc_cnic_cb - global template of bnx2fc - cnic driver interface
2446 * structure carrying callback function pointers
2448 static struct cnic_ulp_ops bnx2fc_cnic_cb
= {
2449 .owner
= THIS_MODULE
,
2450 .cnic_init
= bnx2fc_ulp_init
,
2451 .cnic_exit
= bnx2fc_ulp_exit
,
2452 .cnic_start
= bnx2fc_ulp_start
,
2453 .cnic_stop
= bnx2fc_ulp_stop
,
2454 .indicate_kcqes
= bnx2fc_indicate_kcqe
,
2455 .indicate_netevent
= bnx2fc_indicate_netevent
,