1 /* bnx2fc_fcoe.c: Broadcom NetXtreme II Linux FCoE offload driver.
2 * This file contains the code that interacts with libfc, libfcoe,
3 * cnic modules to create FCoE instances, send/receive non-offloaded
4 * FIP/FCoE packets, listen to link events etc.
6 * Copyright (c) 2008 - 2010 Broadcom Corporation
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation.
12 * Written by: Bhanu Prakash Gollapudi (bprakash@broadcom.com)
17 static struct list_head adapter_list
;
18 static u32 adapter_count
;
19 static DEFINE_MUTEX(bnx2fc_dev_lock
);
20 DEFINE_PER_CPU(struct bnx2fc_percpu_s
, bnx2fc_percpu
);
22 #define DRV_MODULE_NAME "bnx2fc"
23 #define DRV_MODULE_VERSION BNX2FC_VERSION
24 #define DRV_MODULE_RELDATE "Jan 25, 2011"
27 static char version
[] __devinitdata
=
28 "Broadcom NetXtreme II FCoE Driver " DRV_MODULE_NAME \
29 " v" DRV_MODULE_VERSION
" (" DRV_MODULE_RELDATE
")\n";
32 MODULE_AUTHOR("Bhanu Prakash Gollapudi <bprakash@broadcom.com>");
33 MODULE_DESCRIPTION("Broadcom NetXtreme II BCM57710 FCoE Driver");
34 MODULE_LICENSE("GPL");
35 MODULE_VERSION(DRV_MODULE_VERSION
);
37 #define BNX2FC_MAX_QUEUE_DEPTH 256
38 #define BNX2FC_MIN_QUEUE_DEPTH 32
39 #define FCOE_WORD_TO_BYTE 4
41 static struct scsi_transport_template
*bnx2fc_transport_template
;
42 static struct scsi_transport_template
*bnx2fc_vport_xport_template
;
44 struct workqueue_struct
*bnx2fc_wq
;
46 /* bnx2fc structure needs only one instance of the fcoe_percpu_s structure.
47 * Here the io threads are per cpu but the l2 thread is just one
49 struct fcoe_percpu_s bnx2fc_global
;
50 DEFINE_SPINLOCK(bnx2fc_global_lock
);
52 static struct cnic_ulp_ops bnx2fc_cnic_cb
;
53 static struct libfc_function_template bnx2fc_libfc_fcn_templ
;
54 static struct scsi_host_template bnx2fc_shost_template
;
55 static struct fc_function_template bnx2fc_transport_function
;
56 static struct fc_function_template bnx2fc_vport_xport_function
;
57 static int bnx2fc_create(struct net_device
*netdev
, enum fip_state fip_mode
);
58 static int bnx2fc_destroy(struct net_device
*net_device
);
59 static int bnx2fc_enable(struct net_device
*netdev
);
60 static int bnx2fc_disable(struct net_device
*netdev
);
62 static void bnx2fc_recv_frame(struct sk_buff
*skb
);
64 static void bnx2fc_start_disc(struct bnx2fc_hba
*hba
);
65 static int bnx2fc_shost_config(struct fc_lport
*lport
, struct device
*dev
);
66 static int bnx2fc_net_config(struct fc_lport
*lp
);
67 static int bnx2fc_lport_config(struct fc_lport
*lport
);
68 static int bnx2fc_em_config(struct fc_lport
*lport
);
69 static int bnx2fc_bind_adapter_devices(struct bnx2fc_hba
*hba
);
70 static void bnx2fc_unbind_adapter_devices(struct bnx2fc_hba
*hba
);
71 static int bnx2fc_bind_pcidev(struct bnx2fc_hba
*hba
);
72 static void bnx2fc_unbind_pcidev(struct bnx2fc_hba
*hba
);
73 static struct fc_lport
*bnx2fc_if_create(struct bnx2fc_hba
*hba
,
74 struct device
*parent
, int npiv
);
75 static void bnx2fc_destroy_work(struct work_struct
*work
);
77 static struct bnx2fc_hba
*bnx2fc_hba_lookup(struct net_device
*phys_dev
);
78 static struct bnx2fc_hba
*bnx2fc_find_hba_for_cnic(struct cnic_dev
*cnic
);
80 static int bnx2fc_fw_init(struct bnx2fc_hba
*hba
);
81 static void bnx2fc_fw_destroy(struct bnx2fc_hba
*hba
);
83 static void bnx2fc_port_shutdown(struct fc_lport
*lport
);
84 static void bnx2fc_stop(struct bnx2fc_hba
*hba
);
85 static int __init
bnx2fc_mod_init(void);
86 static void __exit
bnx2fc_mod_exit(void);
88 unsigned int bnx2fc_debug_level
;
89 module_param_named(debug_logging
, bnx2fc_debug_level
, int, S_IRUGO
|S_IWUSR
);
91 static int bnx2fc_cpu_callback(struct notifier_block
*nfb
,
92 unsigned long action
, void *hcpu
);
93 /* notification function for CPU hotplug events */
94 static struct notifier_block bnx2fc_cpu_notifier
= {
95 .notifier_call
= bnx2fc_cpu_callback
,
98 static void bnx2fc_clean_rx_queue(struct fc_lport
*lp
)
100 struct fcoe_percpu_s
*bg
;
101 struct fcoe_rcv_info
*fr
;
102 struct sk_buff_head
*list
;
103 struct sk_buff
*skb
, *next
;
104 struct sk_buff
*head
;
107 spin_lock_bh(&bg
->fcoe_rx_list
.lock
);
108 list
= &bg
->fcoe_rx_list
;
110 for (skb
= head
; skb
!= (struct sk_buff
*)list
;
113 fr
= fcoe_dev_from_skb(skb
);
114 if (fr
->fr_dev
== lp
) {
115 __skb_unlink(skb
, list
);
119 spin_unlock_bh(&bg
->fcoe_rx_list
.lock
);
122 int bnx2fc_get_paged_crc_eof(struct sk_buff
*skb
, int tlen
)
125 spin_lock(&bnx2fc_global_lock
);
126 rc
= fcoe_get_paged_crc_eof(skb
, tlen
, &bnx2fc_global
);
127 spin_unlock(&bnx2fc_global_lock
);
132 static void bnx2fc_abort_io(struct fc_lport
*lport
)
135 * This function is no-op for bnx2fc, but we do
136 * not want to leave it as NULL either, as libfc
137 * can call the default function which is
142 static void bnx2fc_cleanup(struct fc_lport
*lport
)
144 struct fcoe_port
*port
= lport_priv(lport
);
145 struct bnx2fc_hba
*hba
= port
->priv
;
146 struct bnx2fc_rport
*tgt
;
149 BNX2FC_MISC_DBG("Entered %s\n", __func__
);
150 mutex_lock(&hba
->hba_mutex
);
151 spin_lock_bh(&hba
->hba_lock
);
152 for (i
= 0; i
< BNX2FC_NUM_MAX_SESS
; i
++) {
153 tgt
= hba
->tgt_ofld_list
[i
];
155 /* Cleanup IOs belonging to requested vport */
156 if (tgt
->port
== port
) {
157 spin_unlock_bh(&hba
->hba_lock
);
158 BNX2FC_TGT_DBG(tgt
, "flush/cleanup\n");
159 bnx2fc_flush_active_ios(tgt
);
160 spin_lock_bh(&hba
->hba_lock
);
164 spin_unlock_bh(&hba
->hba_lock
);
165 mutex_unlock(&hba
->hba_mutex
);
168 static int bnx2fc_xmit_l2_frame(struct bnx2fc_rport
*tgt
,
171 struct fc_rport_priv
*rdata
= tgt
->rdata
;
172 struct fc_frame_header
*fh
;
175 fh
= fc_frame_header_get(fp
);
176 BNX2FC_TGT_DBG(tgt
, "Xmit L2 frame rport = 0x%x, oxid = 0x%x, "
177 "r_ctl = 0x%x\n", rdata
->ids
.port_id
,
178 ntohs(fh
->fh_ox_id
), fh
->fh_r_ctl
);
179 if ((fh
->fh_type
== FC_TYPE_ELS
) &&
180 (fh
->fh_r_ctl
== FC_RCTL_ELS_REQ
)) {
182 switch (fc_frame_payload_op(fp
)) {
184 rc
= bnx2fc_send_adisc(tgt
, fp
);
187 rc
= bnx2fc_send_logo(tgt
, fp
);
190 rc
= bnx2fc_send_rls(tgt
, fp
);
195 } else if ((fh
->fh_type
== FC_TYPE_BLS
) &&
196 (fh
->fh_r_ctl
== FC_RCTL_BA_ABTS
))
197 BNX2FC_TGT_DBG(tgt
, "ABTS frame\n");
199 BNX2FC_TGT_DBG(tgt
, "Send L2 frame type 0x%x "
200 "rctl 0x%x thru non-offload path\n",
201 fh
->fh_type
, fh
->fh_r_ctl
);
211 * bnx2fc_xmit - bnx2fc's FCoE frame transmit function
213 * @lport: the associated local port
214 * @fp: the fc_frame to be transmitted
216 static int bnx2fc_xmit(struct fc_lport
*lport
, struct fc_frame
*fp
)
219 struct fcoe_crc_eof
*cp
;
221 struct fc_frame_header
*fh
;
222 struct bnx2fc_hba
*hba
;
223 struct fcoe_port
*port
;
225 struct bnx2fc_rport
*tgt
;
226 struct fcoe_dev_stats
*stats
;
229 unsigned int hlen
, tlen
, elen
;
232 port
= (struct fcoe_port
*)lport_priv(lport
);
235 fh
= fc_frame_header_get(fp
);
238 if (!lport
->link_up
) {
239 BNX2FC_HBA_DBG(lport
, "bnx2fc_xmit link down\n");
244 if (unlikely(fh
->fh_r_ctl
== FC_RCTL_ELS_REQ
)) {
245 if (!hba
->ctlr
.sel_fcf
) {
246 BNX2FC_HBA_DBG(lport
, "FCF not selected yet!\n");
250 if (fcoe_ctlr_els_send(&hba
->ctlr
, lport
, skb
))
258 * Snoop the frame header to check if the frame is for
259 * an offloaded session
262 * tgt_ofld_list access is synchronized using
263 * both hba mutex and hba lock. Atleast hba mutex or
264 * hba lock needs to be held for read access.
267 spin_lock_bh(&hba
->hba_lock
);
268 tgt
= bnx2fc_tgt_lookup(port
, ntoh24(fh
->fh_d_id
));
269 if (tgt
&& (test_bit(BNX2FC_FLAG_SESSION_READY
, &tgt
->flags
))) {
270 /* This frame is for offloaded session */
271 BNX2FC_HBA_DBG(lport
, "xmit: Frame is for offloaded session "
272 "port_id = 0x%x\n", ntoh24(fh
->fh_d_id
));
273 spin_unlock_bh(&hba
->hba_lock
);
274 rc
= bnx2fc_xmit_l2_frame(tgt
, fp
);
280 spin_unlock_bh(&hba
->hba_lock
);
283 elen
= sizeof(struct ethhdr
);
284 hlen
= sizeof(struct fcoe_hdr
);
285 tlen
= sizeof(struct fcoe_crc_eof
);
286 wlen
= (skb
->len
- tlen
+ sizeof(crc
)) / FCOE_WORD_TO_BYTE
;
288 skb
->ip_summed
= CHECKSUM_NONE
;
289 crc
= fcoe_fc_crc(fp
);
291 /* copy port crc and eof to the skb buff */
292 if (skb_is_nonlinear(skb
)) {
294 if (bnx2fc_get_paged_crc_eof(skb
, tlen
)) {
298 frag
= &skb_shinfo(skb
)->frags
[skb_shinfo(skb
)->nr_frags
- 1];
299 cp
= kmap_atomic(frag
->page
, KM_SKB_DATA_SOFTIRQ
)
302 cp
= (struct fcoe_crc_eof
*)skb_put(skb
, tlen
);
305 memset(cp
, 0, sizeof(*cp
));
307 cp
->fcoe_crc32
= cpu_to_le32(~crc
);
308 if (skb_is_nonlinear(skb
)) {
309 kunmap_atomic(cp
, KM_SKB_DATA_SOFTIRQ
);
313 /* adjust skb network/transport offsets to match mac/fcoe/port */
314 skb_push(skb
, elen
+ hlen
);
315 skb_reset_mac_header(skb
);
316 skb_reset_network_header(skb
);
318 skb
->protocol
= htons(ETH_P_FCOE
);
319 skb
->dev
= hba
->netdev
;
321 /* fill up mac and fcoe headers */
323 eh
->h_proto
= htons(ETH_P_FCOE
);
324 if (hba
->ctlr
.map_dest
)
325 fc_fcoe_set_mac(eh
->h_dest
, fh
->fh_d_id
);
327 /* insert GW address */
328 memcpy(eh
->h_dest
, hba
->ctlr
.dest_addr
, ETH_ALEN
);
330 if (unlikely(hba
->ctlr
.flogi_oxid
!= FC_XID_UNKNOWN
))
331 memcpy(eh
->h_source
, hba
->ctlr
.ctl_src_addr
, ETH_ALEN
);
333 memcpy(eh
->h_source
, port
->data_src_addr
, ETH_ALEN
);
335 hp
= (struct fcoe_hdr
*)(eh
+ 1);
336 memset(hp
, 0, sizeof(*hp
));
338 FC_FCOE_ENCAPS_VER(hp
, FC_FCOE_VER
);
341 /* fcoe lso, mss is in max_payload which is non-zero for FCP data */
342 if (lport
->seq_offload
&& fr_max_payload(fp
)) {
343 skb_shinfo(skb
)->gso_type
= SKB_GSO_FCOE
;
344 skb_shinfo(skb
)->gso_size
= fr_max_payload(fp
);
346 skb_shinfo(skb
)->gso_type
= 0;
347 skb_shinfo(skb
)->gso_size
= 0;
351 stats
= per_cpu_ptr(lport
->dev_stats
, get_cpu());
353 stats
->TxWords
+= wlen
;
356 /* send down to lld */
358 if (port
->fcoe_pending_queue
.qlen
)
359 fcoe_check_wait_queue(lport
, skb
);
360 else if (fcoe_start_io(skb
))
361 fcoe_check_wait_queue(lport
, skb
);
367 * bnx2fc_rcv - This is bnx2fc's receive function called by NET_RX_SOFTIRQ
369 * @skb: the receive socket buffer
370 * @dev: associated net device
372 * @olddev: last device
374 * This function receives the packet and builds FC frame and passes it up
376 static int bnx2fc_rcv(struct sk_buff
*skb
, struct net_device
*dev
,
377 struct packet_type
*ptype
, struct net_device
*olddev
)
379 struct fc_lport
*lport
;
380 struct bnx2fc_hba
*hba
;
381 struct fc_frame_header
*fh
;
382 struct fcoe_rcv_info
*fr
;
383 struct fcoe_percpu_s
*bg
;
386 hba
= container_of(ptype
, struct bnx2fc_hba
, fcoe_packet_type
);
387 lport
= hba
->ctlr
.lp
;
389 if (unlikely(lport
== NULL
)) {
390 printk(KERN_ALERT PFX
"bnx2fc_rcv: lport is NULL\n");
394 if (unlikely(eth_hdr(skb
)->h_proto
!= htons(ETH_P_FCOE
))) {
395 printk(KERN_ALERT PFX
"bnx2fc_rcv: Wrong FC type frame\n");
400 * Check for minimum frame length, and make sure required FCoE
401 * and FC headers are pulled into the linear data area.
403 if (unlikely((skb
->len
< FCOE_MIN_FRAME
) ||
404 !pskb_may_pull(skb
, FCOE_HEADER_LEN
)))
407 skb_set_transport_header(skb
, sizeof(struct fcoe_hdr
));
408 fh
= (struct fc_frame_header
*) skb_transport_header(skb
);
410 oxid
= ntohs(fh
->fh_ox_id
);
412 fr
= fcoe_dev_from_skb(skb
);
417 spin_lock_bh(&bg
->fcoe_rx_list
.lock
);
419 __skb_queue_tail(&bg
->fcoe_rx_list
, skb
);
420 if (bg
->fcoe_rx_list
.qlen
== 1)
421 wake_up_process(bg
->thread
);
423 spin_unlock_bh(&bg
->fcoe_rx_list
.lock
);
431 static int bnx2fc_l2_rcv_thread(void *arg
)
433 struct fcoe_percpu_s
*bg
= arg
;
436 set_user_nice(current
, -20);
437 set_current_state(TASK_INTERRUPTIBLE
);
438 while (!kthread_should_stop()) {
440 set_current_state(TASK_RUNNING
);
441 spin_lock_bh(&bg
->fcoe_rx_list
.lock
);
442 while ((skb
= __skb_dequeue(&bg
->fcoe_rx_list
)) != NULL
) {
443 spin_unlock_bh(&bg
->fcoe_rx_list
.lock
);
444 bnx2fc_recv_frame(skb
);
445 spin_lock_bh(&bg
->fcoe_rx_list
.lock
);
447 spin_unlock_bh(&bg
->fcoe_rx_list
.lock
);
448 set_current_state(TASK_INTERRUPTIBLE
);
450 set_current_state(TASK_RUNNING
);
455 static void bnx2fc_recv_frame(struct sk_buff
*skb
)
458 struct fc_lport
*lport
;
459 struct fcoe_rcv_info
*fr
;
460 struct fcoe_dev_stats
*stats
;
461 struct fc_frame_header
*fh
;
462 struct fcoe_crc_eof crc_eof
;
464 struct fc_lport
*vn_port
;
465 struct fcoe_port
*port
;
470 fr
= fcoe_dev_from_skb(skb
);
472 if (unlikely(lport
== NULL
)) {
473 printk(KERN_ALERT PFX
"Invalid lport struct\n");
478 if (skb_is_nonlinear(skb
))
480 mac
= eth_hdr(skb
)->h_source
;
481 dest_mac
= eth_hdr(skb
)->h_dest
;
483 /* Pull the header */
484 hp
= (struct fcoe_hdr
*) skb_network_header(skb
);
485 fh
= (struct fc_frame_header
*) skb_transport_header(skb
);
486 skb_pull(skb
, sizeof(struct fcoe_hdr
));
487 fr_len
= skb
->len
- sizeof(struct fcoe_crc_eof
);
489 stats
= per_cpu_ptr(lport
->dev_stats
, get_cpu());
491 stats
->RxWords
+= fr_len
/ FCOE_WORD_TO_BYTE
;
493 fp
= (struct fc_frame
*)skb
;
496 fr_sof(fp
) = hp
->fcoe_sof
;
497 if (skb_copy_bits(skb
, fr_len
, &crc_eof
, sizeof(crc_eof
))) {
502 fr_eof(fp
) = crc_eof
.fcoe_eof
;
503 fr_crc(fp
) = crc_eof
.fcoe_crc32
;
504 if (pskb_trim(skb
, fr_len
)) {
510 fh
= fc_frame_header_get(fp
);
512 vn_port
= fc_vport_id_lookup(lport
, ntoh24(fh
->fh_d_id
));
514 port
= lport_priv(vn_port
);
515 if (compare_ether_addr(port
->data_src_addr
, dest_mac
)
517 BNX2FC_HBA_DBG(lport
, "fpma mismatch\n");
523 if (fh
->fh_r_ctl
== FC_RCTL_DD_SOL_DATA
&&
524 fh
->fh_type
== FC_TYPE_FCP
) {
525 /* Drop FCP data. We dont this in L2 path */
530 if (fh
->fh_r_ctl
== FC_RCTL_ELS_REQ
&&
531 fh
->fh_type
== FC_TYPE_ELS
) {
532 switch (fc_frame_payload_op(fp
)) {
534 if (ntoh24(fh
->fh_s_id
) == FC_FID_FLOGI
) {
535 /* drop non-FIP LOGO */
543 if (le32_to_cpu(fr_crc(fp
)) !=
544 ~crc32(~0, skb
->data
, fr_len
)) {
545 if (stats
->InvalidCRCCount
< 5)
546 printk(KERN_WARNING PFX
"dropping frame with "
548 stats
->InvalidCRCCount
++;
554 fc_exch_recv(lport
, fp
);
558 * bnx2fc_percpu_io_thread - thread per cpu for ios
560 * @arg: ptr to bnx2fc_percpu_info structure
562 int bnx2fc_percpu_io_thread(void *arg
)
564 struct bnx2fc_percpu_s
*p
= arg
;
565 struct bnx2fc_work
*work
, *tmp
;
566 LIST_HEAD(work_list
);
568 set_user_nice(current
, -20);
569 set_current_state(TASK_INTERRUPTIBLE
);
570 while (!kthread_should_stop()) {
572 set_current_state(TASK_RUNNING
);
573 spin_lock_bh(&p
->fp_work_lock
);
574 while (!list_empty(&p
->work_list
)) {
575 list_splice_init(&p
->work_list
, &work_list
);
576 spin_unlock_bh(&p
->fp_work_lock
);
578 list_for_each_entry_safe(work
, tmp
, &work_list
, list
) {
579 list_del_init(&work
->list
);
580 bnx2fc_process_cq_compl(work
->tgt
, work
->wqe
);
584 spin_lock_bh(&p
->fp_work_lock
);
586 spin_unlock_bh(&p
->fp_work_lock
);
587 set_current_state(TASK_INTERRUPTIBLE
);
589 set_current_state(TASK_RUNNING
);
594 static struct fc_host_statistics
*bnx2fc_get_host_stats(struct Scsi_Host
*shost
)
596 struct fc_host_statistics
*bnx2fc_stats
;
597 struct fc_lport
*lport
= shost_priv(shost
);
598 struct fcoe_port
*port
= lport_priv(lport
);
599 struct bnx2fc_hba
*hba
= port
->priv
;
600 struct fcoe_statistics_params
*fw_stats
;
603 fw_stats
= (struct fcoe_statistics_params
*)hba
->stats_buffer
;
607 bnx2fc_stats
= fc_get_host_stats(shost
);
609 init_completion(&hba
->stat_req_done
);
610 if (bnx2fc_send_stat_req(hba
))
612 rc
= wait_for_completion_timeout(&hba
->stat_req_done
, (2 * HZ
));
614 BNX2FC_HBA_DBG(lport
, "FW stat req timed out\n");
617 bnx2fc_stats
->invalid_crc_count
+= fw_stats
->rx_stat1
.fc_crc_cnt
;
618 bnx2fc_stats
->tx_frames
+= fw_stats
->tx_stat
.fcoe_tx_pkt_cnt
;
619 bnx2fc_stats
->tx_words
+= (fw_stats
->tx_stat
.fcoe_tx_byte_cnt
) / 4;
620 bnx2fc_stats
->rx_frames
+= fw_stats
->rx_stat0
.fcoe_rx_pkt_cnt
;
621 bnx2fc_stats
->rx_words
+= (fw_stats
->rx_stat0
.fcoe_rx_byte_cnt
) / 4;
623 bnx2fc_stats
->dumped_frames
= 0;
624 bnx2fc_stats
->lip_count
= 0;
625 bnx2fc_stats
->nos_count
= 0;
626 bnx2fc_stats
->loss_of_sync_count
= 0;
627 bnx2fc_stats
->loss_of_signal_count
= 0;
628 bnx2fc_stats
->prim_seq_protocol_err_count
= 0;
633 static int bnx2fc_shost_config(struct fc_lport
*lport
, struct device
*dev
)
635 struct fcoe_port
*port
= lport_priv(lport
);
636 struct bnx2fc_hba
*hba
= port
->priv
;
637 struct Scsi_Host
*shost
= lport
->host
;
640 shost
->max_cmd_len
= BNX2FC_MAX_CMD_LEN
;
641 shost
->max_lun
= BNX2FC_MAX_LUN
;
642 shost
->max_id
= BNX2FC_MAX_FCP_TGT
;
643 shost
->max_channel
= 0;
645 shost
->transportt
= bnx2fc_vport_xport_template
;
647 shost
->transportt
= bnx2fc_transport_template
;
649 /* Add the new host to SCSI-ml */
650 rc
= scsi_add_host(lport
->host
, dev
);
652 printk(KERN_ERR PFX
"Error on scsi_add_host\n");
656 fc_host_max_npiv_vports(lport
->host
) = USHRT_MAX
;
657 sprintf(fc_host_symbolic_name(lport
->host
), "%s v%s over %s",
658 BNX2FC_NAME
, BNX2FC_VERSION
,
664 static void bnx2fc_link_speed_update(struct fc_lport
*lport
)
666 struct fcoe_port
*port
= lport_priv(lport
);
667 struct bnx2fc_hba
*hba
= port
->priv
;
668 struct net_device
*netdev
= hba
->netdev
;
669 struct ethtool_cmd ecmd
= { ETHTOOL_GSET
};
671 if (!dev_ethtool_get_settings(netdev
, &ecmd
)) {
672 lport
->link_supported_speeds
&=
673 ~(FC_PORTSPEED_1GBIT
| FC_PORTSPEED_10GBIT
);
674 if (ecmd
.supported
& (SUPPORTED_1000baseT_Half
|
675 SUPPORTED_1000baseT_Full
))
676 lport
->link_supported_speeds
|= FC_PORTSPEED_1GBIT
;
677 if (ecmd
.supported
& SUPPORTED_10000baseT_Full
)
678 lport
->link_supported_speeds
|= FC_PORTSPEED_10GBIT
;
680 if (ecmd
.speed
== SPEED_1000
)
681 lport
->link_speed
= FC_PORTSPEED_1GBIT
;
682 if (ecmd
.speed
== SPEED_10000
)
683 lport
->link_speed
= FC_PORTSPEED_10GBIT
;
687 static int bnx2fc_link_ok(struct fc_lport
*lport
)
689 struct fcoe_port
*port
= lport_priv(lport
);
690 struct bnx2fc_hba
*hba
= port
->priv
;
691 struct net_device
*dev
= hba
->phys_dev
;
694 if ((dev
->flags
& IFF_UP
) && netif_carrier_ok(dev
))
695 clear_bit(ADAPTER_STATE_LINK_DOWN
, &hba
->adapter_state
);
697 set_bit(ADAPTER_STATE_LINK_DOWN
, &hba
->adapter_state
);
704 * bnx2fc_get_link_state - get network link state
706 * @hba: adapter instance pointer
708 * updates adapter structure flag based on netdev state
710 void bnx2fc_get_link_state(struct bnx2fc_hba
*hba
)
712 if (test_bit(__LINK_STATE_NOCARRIER
, &hba
->netdev
->state
))
713 set_bit(ADAPTER_STATE_LINK_DOWN
, &hba
->adapter_state
);
715 clear_bit(ADAPTER_STATE_LINK_DOWN
, &hba
->adapter_state
);
718 static int bnx2fc_net_config(struct fc_lport
*lport
)
720 struct bnx2fc_hba
*hba
;
721 struct fcoe_port
*port
;
724 port
= lport_priv(lport
);
727 /* require support for get_pauseparam ethtool op. */
728 if (!hba
->phys_dev
->ethtool_ops
||
729 !hba
->phys_dev
->ethtool_ops
->get_pauseparam
)
732 if (fc_set_mfs(lport
, BNX2FC_MFS
))
735 skb_queue_head_init(&port
->fcoe_pending_queue
);
736 port
->fcoe_pending_queue_active
= 0;
737 setup_timer(&port
->timer
, fcoe_queue_timer
, (unsigned long) lport
);
739 bnx2fc_link_speed_update(lport
);
742 wwnn
= fcoe_wwn_from_mac(hba
->ctlr
.ctl_src_addr
, 1, 0);
743 BNX2FC_HBA_DBG(lport
, "WWNN = 0x%llx\n", wwnn
);
744 fc_set_wwnn(lport
, wwnn
);
746 wwpn
= fcoe_wwn_from_mac(hba
->ctlr
.ctl_src_addr
, 2, 0);
747 BNX2FC_HBA_DBG(lport
, "WWPN = 0x%llx\n", wwpn
);
748 fc_set_wwpn(lport
, wwpn
);
754 static void bnx2fc_destroy_timer(unsigned long data
)
756 struct bnx2fc_hba
*hba
= (struct bnx2fc_hba
*)data
;
758 BNX2FC_HBA_DBG(hba
->ctlr
.lp
, "ERROR:bnx2fc_destroy_timer - "
759 "Destroy compl not received!!\n");
760 hba
->flags
|= BNX2FC_FLAG_DESTROY_CMPL
;
761 wake_up_interruptible(&hba
->destroy_wait
);
765 * bnx2fc_indicate_netevent - Generic netdev event handler
767 * @context: adapter structure pointer
770 * Handles NETDEV_UP, NETDEV_DOWN, NETDEV_GOING_DOWN,NETDEV_CHANGE and
771 * NETDEV_CHANGE_MTU events
773 static void bnx2fc_indicate_netevent(void *context
, unsigned long event
)
775 struct bnx2fc_hba
*hba
= (struct bnx2fc_hba
*)context
;
776 struct fc_lport
*lport
= hba
->ctlr
.lp
;
777 struct fc_lport
*vport
;
778 u32 link_possible
= 1;
780 if (!test_bit(BNX2FC_CREATE_DONE
, &hba
->init_done
)) {
781 BNX2FC_MISC_DBG("driver not ready. event=%s %ld\n",
782 hba
->netdev
->name
, event
);
788 * indicate_netevent cannot be called from cnic unless bnx2fc
789 * does register_device
793 BNX2FC_HBA_DBG(lport
, "enter netevent handler - event=%s %ld\n",
794 hba
->netdev
->name
, event
);
798 BNX2FC_HBA_DBG(lport
, "Port up, adapter_state = %ld\n",
800 if (!test_bit(ADAPTER_STATE_UP
, &hba
->adapter_state
))
801 printk(KERN_ERR
"indicate_netevent: "\
802 "adapter is not UP!!\n");
806 BNX2FC_HBA_DBG(lport
, "Port down\n");
807 clear_bit(ADAPTER_STATE_GOING_DOWN
, &hba
->adapter_state
);
808 clear_bit(ADAPTER_STATE_UP
, &hba
->adapter_state
);
812 case NETDEV_GOING_DOWN
:
813 BNX2FC_HBA_DBG(lport
, "Port going down\n");
814 set_bit(ADAPTER_STATE_GOING_DOWN
, &hba
->adapter_state
);
819 BNX2FC_HBA_DBG(lport
, "NETDEV_CHANGE\n");
823 printk(KERN_ERR PFX
"Unkonwn netevent %ld", event
);
827 bnx2fc_link_speed_update(lport
);
829 if (link_possible
&& !bnx2fc_link_ok(lport
)) {
830 printk(KERN_ERR
"indicate_netevent: call ctlr_link_up\n");
831 fcoe_ctlr_link_up(&hba
->ctlr
);
833 printk(KERN_ERR
"indicate_netevent: call ctlr_link_down\n");
834 if (fcoe_ctlr_link_down(&hba
->ctlr
)) {
835 clear_bit(ADAPTER_STATE_READY
, &hba
->adapter_state
);
836 mutex_lock(&lport
->lp_mutex
);
837 list_for_each_entry(vport
, &lport
->vports
, list
)
838 fc_host_port_type(vport
->host
) =
840 mutex_unlock(&lport
->lp_mutex
);
841 fc_host_port_type(lport
->host
) = FC_PORTTYPE_UNKNOWN
;
842 per_cpu_ptr(lport
->dev_stats
,
843 get_cpu())->LinkFailureCount
++;
845 fcoe_clean_pending_queue(lport
);
847 init_waitqueue_head(&hba
->shutdown_wait
);
848 BNX2FC_HBA_DBG(lport
, "indicate_netevent "
849 "num_ofld_sess = %d\n",
851 hba
->wait_for_link_down
= 1;
852 BNX2FC_HBA_DBG(lport
, "waiting for uploads to "
855 wait_event_interruptible(hba
->shutdown_wait
,
856 (hba
->num_ofld_sess
== 0));
857 BNX2FC_HBA_DBG(lport
, "wakeup - num_ofld_sess = %d\n",
859 hba
->wait_for_link_down
= 0;
861 if (signal_pending(current
))
862 flush_signals(current
);
867 static int bnx2fc_libfc_config(struct fc_lport
*lport
)
870 /* Set the function pointers set by bnx2fc driver */
871 memcpy(&lport
->tt
, &bnx2fc_libfc_fcn_templ
,
872 sizeof(struct libfc_function_template
));
873 fc_elsct_init(lport
);
875 fc_rport_init(lport
);
880 static int bnx2fc_em_config(struct fc_lport
*lport
)
882 struct fcoe_port
*port
= lport_priv(lport
);
883 struct bnx2fc_hba
*hba
= port
->priv
;
885 if (!fc_exch_mgr_alloc(lport
, FC_CLASS_3
, FCOE_MIN_XID
,
886 FCOE_MAX_XID
, NULL
)) {
887 printk(KERN_ERR PFX
"em_config:fc_exch_mgr_alloc failed\n");
891 hba
->cmd_mgr
= bnx2fc_cmd_mgr_alloc(hba
, BNX2FC_MIN_XID
,
895 printk(KERN_ERR PFX
"em_config:bnx2fc_cmd_mgr_alloc failed\n");
896 fc_exch_mgr_free(lport
);
902 static int bnx2fc_lport_config(struct fc_lport
*lport
)
906 lport
->max_retry_count
= 3;
907 lport
->max_rport_retry_count
= 3;
908 lport
->e_d_tov
= 2 * 1000;
909 lport
->r_a_tov
= 10 * 1000;
911 /* REVISIT: enable when supporting tape devices
912 lport->service_params = (FCP_SPPF_INIT_FCN | FCP_SPPF_RD_XRDY_DIS |
913 FCP_SPPF_RETRY | FCP_SPPF_CONF_COMPL);
915 lport
->service_params
= (FCP_SPPF_INIT_FCN
| FCP_SPPF_RD_XRDY_DIS
);
916 lport
->does_npiv
= 1;
918 memset(&lport
->rnid_gen
, 0, sizeof(struct fc_els_rnid_gen
));
919 lport
->rnid_gen
.rnid_atype
= BNX2FC_RNID_HBA
;
921 /* alloc stats structure */
922 if (fc_lport_init_stats(lport
))
925 /* Finish fc_lport configuration */
926 fc_lport_config(lport
);
932 * bnx2fc_fip_recv - handle a received FIP frame.
934 * @skb: the received skb
935 * @dev: associated &net_device
936 * @ptype: the &packet_type structure which was used to register this handler.
937 * @orig_dev: original receive &net_device, in case @ dev is a bond.
939 * Returns: 0 for success
941 static int bnx2fc_fip_recv(struct sk_buff
*skb
, struct net_device
*dev
,
942 struct packet_type
*ptype
,
943 struct net_device
*orig_dev
)
945 struct bnx2fc_hba
*hba
;
946 hba
= container_of(ptype
, struct bnx2fc_hba
, fip_packet_type
);
947 fcoe_ctlr_recv(&hba
->ctlr
, skb
);
952 * bnx2fc_update_src_mac - Update Ethernet MAC filters.
954 * @fip: FCoE controller.
955 * @old: Unicast MAC address to delete if the MAC is non-zero.
956 * @new: Unicast MAC address to add.
958 * Remove any previously-set unicast MAC filter.
959 * Add secondary FCoE MAC address filter for our OUI.
961 static void bnx2fc_update_src_mac(struct fc_lport
*lport
, u8
*addr
)
963 struct fcoe_port
*port
= lport_priv(lport
);
965 memcpy(port
->data_src_addr
, addr
, ETH_ALEN
);
969 * bnx2fc_get_src_mac - return the ethernet source address for an lport
973 static u8
*bnx2fc_get_src_mac(struct fc_lport
*lport
)
975 struct fcoe_port
*port
;
977 port
= (struct fcoe_port
*)lport_priv(lport
);
978 return port
->data_src_addr
;
982 * bnx2fc_fip_send - send an Ethernet-encapsulated FIP frame.
984 * @fip: FCoE controller.
987 static void bnx2fc_fip_send(struct fcoe_ctlr
*fip
, struct sk_buff
*skb
)
989 skb
->dev
= bnx2fc_from_ctlr(fip
)->netdev
;
993 static int bnx2fc_vport_create(struct fc_vport
*vport
, bool disabled
)
995 struct Scsi_Host
*shost
= vport_to_shost(vport
);
996 struct fc_lport
*n_port
= shost_priv(shost
);
997 struct fcoe_port
*port
= lport_priv(n_port
);
998 struct bnx2fc_hba
*hba
= port
->priv
;
999 struct net_device
*netdev
= hba
->netdev
;
1000 struct fc_lport
*vn_port
;
1002 if (!test_bit(BNX2FC_FW_INIT_DONE
, &hba
->init_done
)) {
1003 printk(KERN_ERR PFX
"vn ports cannot be created on"
1007 mutex_lock(&bnx2fc_dev_lock
);
1008 vn_port
= bnx2fc_if_create(hba
, &vport
->dev
, 1);
1009 mutex_unlock(&bnx2fc_dev_lock
);
1011 if (IS_ERR(vn_port
)) {
1012 printk(KERN_ERR PFX
"bnx2fc_vport_create (%s) failed\n",
1018 fc_vport_set_state(vport
, FC_VPORT_DISABLED
);
1020 vn_port
->boot_time
= jiffies
;
1021 fc_lport_init(vn_port
);
1022 fc_fabric_login(vn_port
);
1023 fc_vport_setlink(vn_port
);
1028 static int bnx2fc_vport_destroy(struct fc_vport
*vport
)
1030 struct Scsi_Host
*shost
= vport_to_shost(vport
);
1031 struct fc_lport
*n_port
= shost_priv(shost
);
1032 struct fc_lport
*vn_port
= vport
->dd_data
;
1033 struct fcoe_port
*port
= lport_priv(vn_port
);
1035 mutex_lock(&n_port
->lp_mutex
);
1036 list_del(&vn_port
->list
);
1037 mutex_unlock(&n_port
->lp_mutex
);
1038 queue_work(bnx2fc_wq
, &port
->destroy_work
);
1042 static int bnx2fc_vport_disable(struct fc_vport
*vport
, bool disable
)
1044 struct fc_lport
*lport
= vport
->dd_data
;
1047 fc_vport_set_state(vport
, FC_VPORT_DISABLED
);
1048 fc_fabric_logoff(lport
);
1050 lport
->boot_time
= jiffies
;
1051 fc_fabric_login(lport
);
1052 fc_vport_setlink(lport
);
1058 static int bnx2fc_netdev_setup(struct bnx2fc_hba
*hba
)
1060 struct net_device
*netdev
= hba
->netdev
;
1061 struct net_device
*physdev
= hba
->phys_dev
;
1062 struct netdev_hw_addr
*ha
;
1063 int sel_san_mac
= 0;
1065 /* setup Source MAC Address */
1067 for_each_dev_addr(physdev
, ha
) {
1068 BNX2FC_MISC_DBG("net_config: ha->type = %d, fip_mac = ",
1070 printk(KERN_INFO
"%2x:%2x:%2x:%2x:%2x:%2x\n", ha
->addr
[0],
1071 ha
->addr
[1], ha
->addr
[2], ha
->addr
[3],
1072 ha
->addr
[4], ha
->addr
[5]);
1074 if ((ha
->type
== NETDEV_HW_ADDR_T_SAN
) &&
1075 (is_valid_ether_addr(ha
->addr
))) {
1076 memcpy(hba
->ctlr
.ctl_src_addr
, ha
->addr
, ETH_ALEN
);
1078 BNX2FC_MISC_DBG("Found SAN MAC\n");
1086 hba
->fip_packet_type
.func
= bnx2fc_fip_recv
;
1087 hba
->fip_packet_type
.type
= htons(ETH_P_FIP
);
1088 hba
->fip_packet_type
.dev
= netdev
;
1089 dev_add_pack(&hba
->fip_packet_type
);
1091 hba
->fcoe_packet_type
.func
= bnx2fc_rcv
;
1092 hba
->fcoe_packet_type
.type
= __constant_htons(ETH_P_FCOE
);
1093 hba
->fcoe_packet_type
.dev
= netdev
;
1094 dev_add_pack(&hba
->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_hba
*hba
;
1131 struct net_device
*netdev
;
1132 struct net_device
*phys_dev
;
1134 hba
= container_of(kref
, struct bnx2fc_hba
, kref
);
1135 BNX2FC_HBA_DBG(hba
->ctlr
.lp
, "Interface is being released\n");
1137 netdev
= hba
->netdev
;
1138 phys_dev
= hba
->phys_dev
;
1140 /* tear-down FIP controller */
1141 if (test_and_clear_bit(BNX2FC_CTLR_INIT_DONE
, &hba
->init_done
))
1142 fcoe_ctlr_destroy(&hba
->ctlr
);
1144 /* Free the command manager */
1146 bnx2fc_cmd_mgr_free(hba
->cmd_mgr
);
1147 hba
->cmd_mgr
= NULL
;
1150 module_put(THIS_MODULE
);
1153 static inline void bnx2fc_interface_get(struct bnx2fc_hba
*hba
)
1155 kref_get(&hba
->kref
);
1158 static inline void bnx2fc_interface_put(struct bnx2fc_hba
*hba
)
1160 kref_put(&hba
->kref
, bnx2fc_interface_release
);
1162 static void bnx2fc_interface_destroy(struct bnx2fc_hba
*hba
)
1164 bnx2fc_unbind_pcidev(hba
);
1169 * bnx2fc_interface_create - create a new fcoe instance
1171 * @cnic: pointer to cnic device
1173 * Creates a new FCoE instance on the given device which include allocating
1174 * hba structure, scsi_host and lport structures.
1176 static struct bnx2fc_hba
*bnx2fc_interface_create(struct cnic_dev
*cnic
)
1178 struct bnx2fc_hba
*hba
;
1181 hba
= kzalloc(sizeof(*hba
), GFP_KERNEL
);
1183 printk(KERN_ERR PFX
"Unable to allocate hba structure\n");
1186 spin_lock_init(&hba
->hba_lock
);
1187 mutex_init(&hba
->hba_mutex
);
1190 rc
= bnx2fc_bind_pcidev(hba
);
1193 hba
->phys_dev
= cnic
->netdev
;
1194 /* will get overwritten after we do vlan discovery */
1195 hba
->netdev
= hba
->phys_dev
;
1197 init_waitqueue_head(&hba
->shutdown_wait
);
1198 init_waitqueue_head(&hba
->destroy_wait
);
1202 printk(KERN_ERR PFX
"create_interface: bind error\n");
1207 static int bnx2fc_interface_setup(struct bnx2fc_hba
*hba
,
1208 enum fip_state fip_mode
)
1211 struct net_device
*netdev
= hba
->netdev
;
1212 struct fcoe_ctlr
*fip
= &hba
->ctlr
;
1215 kref_init(&hba
->kref
);
1219 /* Initialize FIP */
1220 memset(fip
, 0, sizeof(*fip
));
1221 fcoe_ctlr_init(fip
, fip_mode
);
1222 hba
->ctlr
.send
= bnx2fc_fip_send
;
1223 hba
->ctlr
.update_mac
= bnx2fc_update_src_mac
;
1224 hba
->ctlr
.get_src_addr
= bnx2fc_get_src_mac
;
1225 set_bit(BNX2FC_CTLR_INIT_DONE
, &hba
->init_done
);
1227 rc
= bnx2fc_netdev_setup(hba
);
1231 hba
->next_conn_id
= 0;
1233 memset(hba
->tgt_ofld_list
, 0, sizeof(hba
->tgt_ofld_list
));
1234 hba
->num_ofld_sess
= 0;
1239 fcoe_ctlr_destroy(&hba
->ctlr
);
1241 bnx2fc_interface_put(hba
);
1246 * bnx2fc_if_create - Create FCoE instance on a given interface
1248 * @hba: FCoE interface to create a local port on
1249 * @parent: Device pointer to be the parent in sysfs for the SCSI host
1250 * @npiv: Indicates if the port is vport or not
1252 * Creates a fc_lport instance and a Scsi_Host instance and configure them.
1254 * Returns: Allocated fc_lport or an error pointer
1256 static struct fc_lport
*bnx2fc_if_create(struct bnx2fc_hba
*hba
,
1257 struct device
*parent
, int npiv
)
1259 struct fc_lport
*lport
= NULL
;
1260 struct fcoe_port
*port
;
1261 struct Scsi_Host
*shost
;
1262 struct fc_vport
*vport
= dev_to_vport(parent
);
1265 /* Allocate Scsi_Host structure */
1267 lport
= libfc_host_alloc(&bnx2fc_shost_template
,
1268 sizeof(struct fcoe_port
));
1270 lport
= libfc_vport_create(vport
,
1271 sizeof(struct fcoe_port
));
1275 printk(KERN_ERR PFX
"could not allocate scsi host structure\n");
1278 shost
= lport
->host
;
1279 port
= lport_priv(lport
);
1280 port
->lport
= lport
;
1282 INIT_WORK(&port
->destroy_work
, bnx2fc_destroy_work
);
1284 /* Configure fcoe_port */
1285 rc
= bnx2fc_lport_config(lport
);
1290 vport
= dev_to_vport(parent
);
1291 printk(KERN_ERR PFX
"Setting vport names, 0x%llX 0x%llX\n",
1292 vport
->node_name
, vport
->port_name
);
1293 fc_set_wwnn(lport
, vport
->node_name
);
1294 fc_set_wwpn(lport
, vport
->port_name
);
1296 /* Configure netdev and networking properties of the lport */
1297 rc
= bnx2fc_net_config(lport
);
1299 printk(KERN_ERR PFX
"Error on bnx2fc_net_config\n");
1303 rc
= bnx2fc_shost_config(lport
, parent
);
1305 printk(KERN_ERR PFX
"Couldnt configure shost for %s\n",
1310 /* Initialize the libfc library */
1311 rc
= bnx2fc_libfc_config(lport
);
1313 printk(KERN_ERR PFX
"Couldnt configure libfc\n");
1316 fc_host_port_type(lport
->host
) = FC_PORTTYPE_UNKNOWN
;
1318 /* Allocate exchange manager */
1320 rc
= bnx2fc_em_config(lport
);
1322 printk(KERN_ERR PFX
"Error on bnx2fc_em_config\n");
1327 bnx2fc_interface_get(hba
);
1331 scsi_remove_host(shost
);
1333 scsi_host_put(lport
->host
);
1337 static void bnx2fc_netdev_cleanup(struct bnx2fc_hba
*hba
)
1339 /* Dont listen for Ethernet packets anymore */
1340 __dev_remove_pack(&hba
->fcoe_packet_type
);
1341 __dev_remove_pack(&hba
->fip_packet_type
);
1345 static void bnx2fc_if_destroy(struct fc_lport
*lport
)
1347 struct fcoe_port
*port
= lport_priv(lport
);
1348 struct bnx2fc_hba
*hba
= port
->priv
;
1350 BNX2FC_HBA_DBG(hba
->ctlr
.lp
, "ENTERED bnx2fc_if_destroy\n");
1351 /* Stop the transmit retry timer */
1352 del_timer_sync(&port
->timer
);
1354 /* Free existing transmit skbs */
1355 fcoe_clean_pending_queue(lport
);
1357 bnx2fc_interface_put(hba
);
1359 /* Free queued packets for the receive thread */
1360 bnx2fc_clean_rx_queue(lport
);
1362 /* Detach from scsi-ml */
1363 fc_remove_host(lport
->host
);
1364 scsi_remove_host(lport
->host
);
1367 * Note that only the physical lport will have the exchange manager.
1368 * for vports, this function is NOP
1370 fc_exch_mgr_free(lport
);
1372 /* Free memory used by statistical counters */
1373 fc_lport_free_stats(lport
);
1375 /* Release Scsi_Host */
1376 scsi_host_put(lport
->host
);
1380 * bnx2fc_destroy - Destroy a bnx2fc FCoE interface
1382 * @buffer: The name of the Ethernet interface to be destroyed
1383 * @kp: The associated kernel parameter
1385 * Called from sysfs.
1387 * Returns: 0 for success
1389 static int bnx2fc_destroy(struct net_device
*netdev
)
1391 struct bnx2fc_hba
*hba
= NULL
;
1392 struct net_device
*phys_dev
;
1397 mutex_lock(&bnx2fc_dev_lock
);
1398 #ifdef CONFIG_SCSI_BNX2X_FCOE_MODULE
1399 if (THIS_MODULE
->state
!= MODULE_STATE_LIVE
) {
1404 /* obtain physical netdev */
1405 if (netdev
->priv_flags
& IFF_802_1Q_VLAN
)
1406 phys_dev
= vlan_dev_real_dev(netdev
);
1408 printk(KERN_ERR PFX
"Not a vlan device\n");
1413 hba
= bnx2fc_hba_lookup(phys_dev
);
1414 if (!hba
|| !hba
->ctlr
.lp
) {
1416 printk(KERN_ERR PFX
"bnx2fc_destroy: hba or lport not found\n");
1420 if (!test_bit(BNX2FC_CREATE_DONE
, &hba
->init_done
)) {
1421 printk(KERN_ERR PFX
"bnx2fc_destroy: Create not called\n");
1425 bnx2fc_netdev_cleanup(hba
);
1429 bnx2fc_if_destroy(hba
->ctlr
.lp
);
1431 destroy_workqueue(hba
->timer_work_queue
);
1433 if (test_bit(BNX2FC_FW_INIT_DONE
, &hba
->init_done
))
1434 bnx2fc_fw_destroy(hba
);
1436 clear_bit(BNX2FC_CREATE_DONE
, &hba
->init_done
);
1438 mutex_unlock(&bnx2fc_dev_lock
);
1443 static void bnx2fc_destroy_work(struct work_struct
*work
)
1445 struct fcoe_port
*port
;
1446 struct fc_lport
*lport
;
1448 port
= container_of(work
, struct fcoe_port
, destroy_work
);
1449 lport
= port
->lport
;
1451 BNX2FC_HBA_DBG(lport
, "Entered bnx2fc_destroy_work\n");
1453 bnx2fc_port_shutdown(lport
);
1455 mutex_lock(&bnx2fc_dev_lock
);
1456 bnx2fc_if_destroy(lport
);
1457 mutex_unlock(&bnx2fc_dev_lock
);
1461 static void bnx2fc_unbind_adapter_devices(struct bnx2fc_hba
*hba
)
1463 bnx2fc_free_fw_resc(hba
);
1464 bnx2fc_free_task_ctx(hba
);
1468 * bnx2fc_bind_adapter_devices - binds bnx2fc adapter with the associated
1471 * @hba: Adapter instance
1473 static int bnx2fc_bind_adapter_devices(struct bnx2fc_hba
*hba
)
1475 if (bnx2fc_setup_task_ctx(hba
))
1478 if (bnx2fc_setup_fw_resc(hba
))
1483 bnx2fc_unbind_adapter_devices(hba
);
1487 static int bnx2fc_bind_pcidev(struct bnx2fc_hba
*hba
)
1489 struct cnic_dev
*cnic
;
1492 printk(KERN_ERR PFX
"cnic is NULL\n");
1496 hba
->pcidev
= cnic
->pcidev
;
1498 pci_dev_get(hba
->pcidev
);
1503 static void bnx2fc_unbind_pcidev(struct bnx2fc_hba
*hba
)
1506 pci_dev_put(hba
->pcidev
);
1513 * bnx2fc_ulp_start - cnic callback to initialize & start adapter instance
1515 * @handle: transport handle pointing to adapter struture
1517 * This function maps adapter structure to pcidev structure and initiates
1518 * firmware handshake to enable/initialize on-chip FCoE components.
1519 * This bnx2fc - cnic interface api callback is used after following
1520 * conditions are met -
1521 * a) underlying network interface is up (marked by event NETDEV_UP
1523 * b) bnx2fc adatper structure is registered.
1525 static void bnx2fc_ulp_start(void *handle
)
1527 struct bnx2fc_hba
*hba
= handle
;
1528 struct fc_lport
*lport
= hba
->ctlr
.lp
;
1530 BNX2FC_MISC_DBG("Entered %s\n", __func__
);
1531 mutex_lock(&bnx2fc_dev_lock
);
1533 if (test_bit(BNX2FC_FW_INIT_DONE
, &hba
->init_done
))
1536 if (test_bit(BNX2FC_CREATE_DONE
, &hba
->init_done
))
1537 bnx2fc_fw_init(hba
);
1540 mutex_unlock(&bnx2fc_dev_lock
);
1542 BNX2FC_MISC_DBG("bnx2fc started.\n");
1544 /* Kick off Fabric discovery*/
1545 if (test_bit(BNX2FC_CREATE_DONE
, &hba
->init_done
)) {
1546 printk(KERN_ERR PFX
"ulp_init: start discovery\n");
1547 lport
->tt
.frame_send
= bnx2fc_xmit
;
1548 bnx2fc_start_disc(hba
);
1552 static void bnx2fc_port_shutdown(struct fc_lport
*lport
)
1554 BNX2FC_MISC_DBG("Entered %s\n", __func__
);
1555 fc_fabric_logoff(lport
);
1556 fc_lport_destroy(lport
);
1559 static void bnx2fc_stop(struct bnx2fc_hba
*hba
)
1561 struct fc_lport
*lport
;
1562 struct fc_lport
*vport
;
1564 BNX2FC_MISC_DBG("ENTERED %s - init_done = %ld\n", __func__
,
1566 if (test_bit(BNX2FC_FW_INIT_DONE
, &hba
->init_done
) &&
1567 test_bit(BNX2FC_CREATE_DONE
, &hba
->init_done
)) {
1568 lport
= hba
->ctlr
.lp
;
1569 bnx2fc_port_shutdown(lport
);
1570 BNX2FC_HBA_DBG(lport
, "bnx2fc_stop: waiting for %d "
1571 "offloaded sessions\n",
1572 hba
->num_ofld_sess
);
1573 wait_event_interruptible(hba
->shutdown_wait
,
1574 (hba
->num_ofld_sess
== 0));
1575 mutex_lock(&lport
->lp_mutex
);
1576 list_for_each_entry(vport
, &lport
->vports
, list
)
1577 fc_host_port_type(vport
->host
) = FC_PORTTYPE_UNKNOWN
;
1578 mutex_unlock(&lport
->lp_mutex
);
1579 fc_host_port_type(lport
->host
) = FC_PORTTYPE_UNKNOWN
;
1580 fcoe_ctlr_link_down(&hba
->ctlr
);
1581 fcoe_clean_pending_queue(lport
);
1583 mutex_lock(&hba
->hba_mutex
);
1584 clear_bit(ADAPTER_STATE_UP
, &hba
->adapter_state
);
1585 clear_bit(ADAPTER_STATE_GOING_DOWN
, &hba
->adapter_state
);
1587 clear_bit(ADAPTER_STATE_READY
, &hba
->adapter_state
);
1588 mutex_unlock(&hba
->hba_mutex
);
1592 static int bnx2fc_fw_init(struct bnx2fc_hba
*hba
)
1594 #define BNX2FC_INIT_POLL_TIME (1000 / HZ)
1598 rc
= bnx2fc_bind_adapter_devices(hba
);
1600 printk(KERN_ALERT PFX
1601 "bnx2fc_bind_adapter_devices failed - rc = %d\n", rc
);
1605 rc
= bnx2fc_send_fw_fcoe_init_msg(hba
);
1607 printk(KERN_ALERT PFX
1608 "bnx2fc_send_fw_fcoe_init_msg failed - rc = %d\n", rc
);
1613 * Wait until the adapter init message is complete, and adapter
1616 while (!test_bit(ADAPTER_STATE_UP
, &hba
->adapter_state
) && i
--)
1617 msleep(BNX2FC_INIT_POLL_TIME
);
1619 if (!test_bit(ADAPTER_STATE_UP
, &hba
->adapter_state
)) {
1620 printk(KERN_ERR PFX
"bnx2fc_start: %s failed to initialize. "
1622 hba
->cnic
->netdev
->name
);
1628 /* Mark HBA to indicate that the FW INIT is done */
1629 set_bit(BNX2FC_FW_INIT_DONE
, &hba
->init_done
);
1633 bnx2fc_unbind_adapter_devices(hba
);
1638 static void bnx2fc_fw_destroy(struct bnx2fc_hba
*hba
)
1640 if (test_and_clear_bit(BNX2FC_FW_INIT_DONE
, &hba
->init_done
)) {
1641 if (bnx2fc_send_fw_fcoe_destroy_msg(hba
) == 0) {
1642 init_timer(&hba
->destroy_timer
);
1643 hba
->destroy_timer
.expires
= BNX2FC_FW_TIMEOUT
+
1645 hba
->destroy_timer
.function
= bnx2fc_destroy_timer
;
1646 hba
->destroy_timer
.data
= (unsigned long)hba
;
1647 add_timer(&hba
->destroy_timer
);
1648 wait_event_interruptible(hba
->destroy_wait
,
1650 BNX2FC_FLAG_DESTROY_CMPL
));
1651 /* This should never happen */
1652 if (signal_pending(current
))
1653 flush_signals(current
);
1655 del_timer_sync(&hba
->destroy_timer
);
1657 bnx2fc_unbind_adapter_devices(hba
);
1662 * bnx2fc_ulp_stop - cnic callback to shutdown adapter instance
1664 * @handle: transport handle pointing to adapter structure
1666 * Driver checks if adapter is already in shutdown mode, if not start
1667 * the shutdown process.
1669 static void bnx2fc_ulp_stop(void *handle
)
1671 struct bnx2fc_hba
*hba
= (struct bnx2fc_hba
*)handle
;
1673 printk(KERN_ERR
"ULP_STOP\n");
1675 mutex_lock(&bnx2fc_dev_lock
);
1677 bnx2fc_fw_destroy(hba
);
1678 mutex_unlock(&bnx2fc_dev_lock
);
1681 static void bnx2fc_start_disc(struct bnx2fc_hba
*hba
)
1683 struct fc_lport
*lport
;
1686 BNX2FC_MISC_DBG("Entered %s\n", __func__
);
1687 /* Kick off FIP/FLOGI */
1688 if (!test_bit(BNX2FC_FW_INIT_DONE
, &hba
->init_done
)) {
1689 printk(KERN_ERR PFX
"Init not done yet\n");
1693 lport
= hba
->ctlr
.lp
;
1694 BNX2FC_HBA_DBG(lport
, "calling fc_fabric_login\n");
1696 if (!bnx2fc_link_ok(lport
)) {
1697 BNX2FC_HBA_DBG(lport
, "ctlr_link_up\n");
1698 fcoe_ctlr_link_up(&hba
->ctlr
);
1699 fc_host_port_type(lport
->host
) = FC_PORTTYPE_NPORT
;
1700 set_bit(ADAPTER_STATE_READY
, &hba
->adapter_state
);
1703 /* wait for the FCF to be selected before issuing FLOGI */
1704 while (!hba
->ctlr
.sel_fcf
) {
1706 /* give up after 3 secs */
1707 if (++wait_cnt
> 12)
1710 fc_lport_init(lport
);
1711 fc_fabric_login(lport
);
1716 * bnx2fc_ulp_init - Initialize an adapter instance
1718 * @dev : cnic device handle
1719 * Called from cnic_register_driver() context to initialize all
1720 * enumerated cnic devices. This routine allocates adapter structure
1721 * and other device specific resources.
1723 static void bnx2fc_ulp_init(struct cnic_dev
*dev
)
1725 struct bnx2fc_hba
*hba
;
1728 BNX2FC_MISC_DBG("Entered %s\n", __func__
);
1729 /* bnx2fc works only when bnx2x is loaded */
1730 if (!test_bit(CNIC_F_BNX2X_CLASS
, &dev
->flags
)) {
1731 printk(KERN_ERR PFX
"bnx2fc FCoE not supported on %s,"
1733 dev
->netdev
->name
, dev
->flags
);
1737 /* Configure FCoE interface */
1738 hba
= bnx2fc_interface_create(dev
);
1740 printk(KERN_ERR PFX
"hba initialization failed\n");
1744 /* Add HBA to the adapter list */
1745 mutex_lock(&bnx2fc_dev_lock
);
1746 list_add_tail(&hba
->link
, &adapter_list
);
1748 mutex_unlock(&bnx2fc_dev_lock
);
1750 clear_bit(BNX2FC_CNIC_REGISTERED
, &hba
->reg_with_cnic
);
1751 rc
= dev
->register_device(dev
, CNIC_ULP_FCOE
,
1754 printk(KERN_ALERT PFX
"register_device failed, rc = %d\n", rc
);
1756 set_bit(BNX2FC_CNIC_REGISTERED
, &hba
->reg_with_cnic
);
1760 static int bnx2fc_disable(struct net_device
*netdev
)
1762 struct bnx2fc_hba
*hba
;
1763 struct net_device
*phys_dev
;
1764 struct ethtool_drvinfo drvinfo
;
1769 mutex_lock(&bnx2fc_dev_lock
);
1771 if (THIS_MODULE
->state
!= MODULE_STATE_LIVE
) {
1776 /* obtain physical netdev */
1777 if (netdev
->priv_flags
& IFF_802_1Q_VLAN
)
1778 phys_dev
= vlan_dev_real_dev(netdev
);
1780 printk(KERN_ERR PFX
"Not a vlan device\n");
1785 /* verify if the physical device is a netxtreme2 device */
1786 if (phys_dev
->ethtool_ops
&& phys_dev
->ethtool_ops
->get_drvinfo
) {
1787 memset(&drvinfo
, 0, sizeof(drvinfo
));
1788 phys_dev
->ethtool_ops
->get_drvinfo(phys_dev
, &drvinfo
);
1789 if (strcmp(drvinfo
.driver
, "bnx2x")) {
1790 printk(KERN_ERR PFX
"Not a netxtreme2 device\n");
1795 printk(KERN_ERR PFX
"unable to obtain drv_info\n");
1800 printk(KERN_ERR PFX
"phys_dev is netxtreme2 device\n");
1802 /* obtain hba and initialize rest of the structure */
1803 hba
= bnx2fc_hba_lookup(phys_dev
);
1804 if (!hba
|| !hba
->ctlr
.lp
) {
1806 printk(KERN_ERR PFX
"bnx2fc_disable: hba or lport not found\n");
1808 fcoe_ctlr_link_down(&hba
->ctlr
);
1809 fcoe_clean_pending_queue(hba
->ctlr
.lp
);
1813 mutex_unlock(&bnx2fc_dev_lock
);
1819 static int bnx2fc_enable(struct net_device
*netdev
)
1821 struct bnx2fc_hba
*hba
;
1822 struct net_device
*phys_dev
;
1823 struct ethtool_drvinfo drvinfo
;
1828 BNX2FC_MISC_DBG("Entered %s\n", __func__
);
1829 mutex_lock(&bnx2fc_dev_lock
);
1831 if (THIS_MODULE
->state
!= MODULE_STATE_LIVE
) {
1836 /* obtain physical netdev */
1837 if (netdev
->priv_flags
& IFF_802_1Q_VLAN
)
1838 phys_dev
= vlan_dev_real_dev(netdev
);
1840 printk(KERN_ERR PFX
"Not a vlan device\n");
1844 /* verify if the physical device is a netxtreme2 device */
1845 if (phys_dev
->ethtool_ops
&& phys_dev
->ethtool_ops
->get_drvinfo
) {
1846 memset(&drvinfo
, 0, sizeof(drvinfo
));
1847 phys_dev
->ethtool_ops
->get_drvinfo(phys_dev
, &drvinfo
);
1848 if (strcmp(drvinfo
.driver
, "bnx2x")) {
1849 printk(KERN_ERR PFX
"Not a netxtreme2 device\n");
1854 printk(KERN_ERR PFX
"unable to obtain drv_info\n");
1859 /* obtain hba and initialize rest of the structure */
1860 hba
= bnx2fc_hba_lookup(phys_dev
);
1861 if (!hba
|| !hba
->ctlr
.lp
) {
1863 printk(KERN_ERR PFX
"bnx2fc_enable: hba or lport not found\n");
1864 } else if (!bnx2fc_link_ok(hba
->ctlr
.lp
))
1865 fcoe_ctlr_link_up(&hba
->ctlr
);
1868 mutex_unlock(&bnx2fc_dev_lock
);
1874 * bnx2fc_create - Create bnx2fc FCoE interface
1876 * @buffer: The name of Ethernet interface to create on
1877 * @kp: The associated kernel param
1879 * Called from sysfs.
1881 * Returns: 0 for success
1883 static int bnx2fc_create(struct net_device
*netdev
, enum fip_state fip_mode
)
1885 struct bnx2fc_hba
*hba
;
1886 struct net_device
*phys_dev
;
1887 struct fc_lport
*lport
;
1888 struct ethtool_drvinfo drvinfo
;
1892 BNX2FC_MISC_DBG("Entered bnx2fc_create\n");
1893 if (fip_mode
!= FIP_MODE_FABRIC
) {
1894 printk(KERN_ERR
"fip mode not FABRIC\n");
1900 mutex_lock(&bnx2fc_dev_lock
);
1902 #ifdef CONFIG_SCSI_BNX2X_FCOE_MODULE
1903 if (THIS_MODULE
->state
!= MODULE_STATE_LIVE
) {
1909 if (!try_module_get(THIS_MODULE
)) {
1914 /* obtain physical netdev */
1915 if (netdev
->priv_flags
& IFF_802_1Q_VLAN
) {
1916 phys_dev
= vlan_dev_real_dev(netdev
);
1917 vlan_id
= vlan_dev_vlan_id(netdev
);
1919 printk(KERN_ERR PFX
"Not a vlan device\n");
1923 /* verify if the physical device is a netxtreme2 device */
1924 if (phys_dev
->ethtool_ops
&& phys_dev
->ethtool_ops
->get_drvinfo
) {
1925 memset(&drvinfo
, 0, sizeof(drvinfo
));
1926 phys_dev
->ethtool_ops
->get_drvinfo(phys_dev
, &drvinfo
);
1927 if (strcmp(drvinfo
.driver
, "bnx2x")) {
1928 printk(KERN_ERR PFX
"Not a netxtreme2 device\n");
1933 printk(KERN_ERR PFX
"unable to obtain drv_info\n");
1938 /* obtain hba and initialize rest of the structure */
1939 hba
= bnx2fc_hba_lookup(phys_dev
);
1942 printk(KERN_ERR PFX
"bnx2fc_create: hba not found\n");
1946 if (!test_bit(BNX2FC_FW_INIT_DONE
, &hba
->init_done
)) {
1947 rc
= bnx2fc_fw_init(hba
);
1952 if (test_bit(BNX2FC_CREATE_DONE
, &hba
->init_done
)) {
1957 /* update netdev with vlan netdev */
1958 hba
->netdev
= netdev
;
1959 hba
->vlan_id
= vlan_id
;
1960 hba
->vlan_enabled
= 1;
1962 rc
= bnx2fc_interface_setup(hba
, fip_mode
);
1964 printk(KERN_ERR PFX
"bnx2fc_interface_setup failed\n");
1968 hba
->timer_work_queue
=
1969 create_singlethread_workqueue("bnx2fc_timer_wq");
1970 if (!hba
->timer_work_queue
) {
1971 printk(KERN_ERR PFX
"ulp_init could not create timer_wq\n");
1976 lport
= bnx2fc_if_create(hba
, &hba
->pcidev
->dev
, 0);
1978 printk(KERN_ERR PFX
"Failed to create interface (%s)\n",
1980 bnx2fc_netdev_cleanup(hba
);
1985 lport
->boot_time
= jiffies
;
1987 /* Make this master N_port */
1988 hba
->ctlr
.lp
= lport
;
1990 set_bit(BNX2FC_CREATE_DONE
, &hba
->init_done
);
1991 printk(KERN_ERR PFX
"create: START DISC\n");
1992 bnx2fc_start_disc(hba
);
1994 * Release from kref_init in bnx2fc_interface_setup, on success
1995 * lport should be holding a reference taken in bnx2fc_if_create
1997 bnx2fc_interface_put(hba
);
1998 /* put netdev that was held while calling dev_get_by_name */
1999 mutex_unlock(&bnx2fc_dev_lock
);
2004 destroy_workqueue(hba
->timer_work_queue
);
2006 bnx2fc_interface_put(hba
);
2008 module_put(THIS_MODULE
);
2010 mutex_unlock(&bnx2fc_dev_lock
);
2016 * bnx2fc_find_hba_for_cnic - maps cnic instance to bnx2fc adapter instance
2018 * @cnic: Pointer to cnic device instance
2021 static struct bnx2fc_hba
*bnx2fc_find_hba_for_cnic(struct cnic_dev
*cnic
)
2023 struct list_head
*list
;
2024 struct list_head
*temp
;
2025 struct bnx2fc_hba
*hba
;
2027 /* Called with bnx2fc_dev_lock held */
2028 list_for_each_safe(list
, temp
, &adapter_list
) {
2029 hba
= (struct bnx2fc_hba
*)list
;
2030 if (hba
->cnic
== cnic
)
2036 static struct bnx2fc_hba
*bnx2fc_hba_lookup(struct net_device
*phys_dev
)
2038 struct list_head
*list
;
2039 struct list_head
*temp
;
2040 struct bnx2fc_hba
*hba
;
2042 /* Called with bnx2fc_dev_lock held */
2043 list_for_each_safe(list
, temp
, &adapter_list
) {
2044 hba
= (struct bnx2fc_hba
*)list
;
2045 if (hba
->phys_dev
== phys_dev
)
2048 printk(KERN_ERR PFX
"hba_lookup: hba NULL\n");
2053 * bnx2fc_ulp_exit - shuts down adapter instance and frees all resources
2055 * @dev cnic device handle
2057 static void bnx2fc_ulp_exit(struct cnic_dev
*dev
)
2059 struct bnx2fc_hba
*hba
;
2061 BNX2FC_MISC_DBG("Entered bnx2fc_ulp_exit\n");
2063 if (!test_bit(CNIC_F_BNX2X_CLASS
, &dev
->flags
)) {
2064 printk(KERN_ERR PFX
"bnx2fc port check: %s, flags: %lx\n",
2065 dev
->netdev
->name
, dev
->flags
);
2069 mutex_lock(&bnx2fc_dev_lock
);
2070 hba
= bnx2fc_find_hba_for_cnic(dev
);
2072 printk(KERN_ERR PFX
"bnx2fc_ulp_exit: hba not found, dev 0%p\n",
2074 mutex_unlock(&bnx2fc_dev_lock
);
2078 list_del_init(&hba
->link
);
2081 if (test_bit(BNX2FC_CREATE_DONE
, &hba
->init_done
)) {
2082 /* destroy not called yet, move to quiesced list */
2083 bnx2fc_netdev_cleanup(hba
);
2084 bnx2fc_if_destroy(hba
->ctlr
.lp
);
2086 mutex_unlock(&bnx2fc_dev_lock
);
2088 bnx2fc_ulp_stop(hba
);
2089 /* unregister cnic device */
2090 if (test_and_clear_bit(BNX2FC_CNIC_REGISTERED
, &hba
->reg_with_cnic
))
2091 hba
->cnic
->unregister_device(hba
->cnic
, CNIC_ULP_FCOE
);
2092 bnx2fc_interface_destroy(hba
);
2096 * bnx2fc_fcoe_reset - Resets the fcoe
2098 * @shost: shost the reset is from
2102 static int bnx2fc_fcoe_reset(struct Scsi_Host
*shost
)
2104 struct fc_lport
*lport
= shost_priv(shost
);
2105 fc_lport_reset(lport
);
2110 static bool bnx2fc_match(struct net_device
*netdev
)
2112 mutex_lock(&bnx2fc_dev_lock
);
2113 if (netdev
->priv_flags
& IFF_802_1Q_VLAN
) {
2114 struct net_device
*phys_dev
= vlan_dev_real_dev(netdev
);
2116 if (bnx2fc_hba_lookup(phys_dev
)) {
2117 mutex_unlock(&bnx2fc_dev_lock
);
2121 mutex_unlock(&bnx2fc_dev_lock
);
2126 static struct fcoe_transport bnx2fc_transport
= {
2129 .list
= LIST_HEAD_INIT(bnx2fc_transport
.list
),
2130 .match
= bnx2fc_match
,
2131 .create
= bnx2fc_create
,
2132 .destroy
= bnx2fc_destroy
,
2133 .enable
= bnx2fc_enable
,
2134 .disable
= bnx2fc_disable
,
2138 * bnx2fc_percpu_thread_create - Create a receive thread for an
2141 * @cpu: cpu index for the online cpu
2143 static void bnx2fc_percpu_thread_create(unsigned int cpu
)
2145 struct bnx2fc_percpu_s
*p
;
2146 struct task_struct
*thread
;
2148 p
= &per_cpu(bnx2fc_percpu
, cpu
);
2150 thread
= kthread_create(bnx2fc_percpu_io_thread
,
2152 "bnx2fc_thread/%d", cpu
);
2153 /* bind thread to the cpu */
2154 if (likely(!IS_ERR(p
->iothread
))) {
2155 kthread_bind(thread
, cpu
);
2156 p
->iothread
= thread
;
2157 wake_up_process(thread
);
2161 static void bnx2fc_percpu_thread_destroy(unsigned int cpu
)
2163 struct bnx2fc_percpu_s
*p
;
2164 struct task_struct
*thread
;
2165 struct bnx2fc_work
*work
, *tmp
;
2166 LIST_HEAD(work_list
);
2168 BNX2FC_MISC_DBG("destroying io thread for CPU %d\n", cpu
);
2170 /* Prevent any new work from being queued for this CPU */
2171 p
= &per_cpu(bnx2fc_percpu
, cpu
);
2172 spin_lock_bh(&p
->fp_work_lock
);
2173 thread
= p
->iothread
;
2177 /* Free all work in the list */
2178 list_for_each_entry_safe(work
, tmp
, &work_list
, list
) {
2179 list_del_init(&work
->list
);
2180 bnx2fc_process_cq_compl(work
->tgt
, work
->wqe
);
2184 spin_unlock_bh(&p
->fp_work_lock
);
2187 kthread_stop(thread
);
2191 * bnx2fc_cpu_callback - Handler for CPU hotplug events
2193 * @nfb: The callback data block
2194 * @action: The event triggering the callback
2195 * @hcpu: The index of the CPU that the event is for
2197 * This creates or destroys per-CPU data for fcoe
2199 * Returns NOTIFY_OK always.
2201 static int bnx2fc_cpu_callback(struct notifier_block
*nfb
,
2202 unsigned long action
, void *hcpu
)
2204 unsigned cpu
= (unsigned long)hcpu
;
2208 case CPU_ONLINE_FROZEN
:
2209 printk(PFX
"CPU %x online: Create Rx thread\n", cpu
);
2210 bnx2fc_percpu_thread_create(cpu
);
2213 case CPU_DEAD_FROZEN
:
2214 printk(PFX
"CPU %x offline: Remove Rx thread\n", cpu
);
2215 bnx2fc_percpu_thread_destroy(cpu
);
2224 * bnx2fc_mod_init - module init entry point
2226 * Initialize driver wide global data structures, and register
2229 static int __init
bnx2fc_mod_init(void)
2231 struct fcoe_percpu_s
*bg
;
2232 struct task_struct
*l2_thread
;
2234 unsigned int cpu
= 0;
2235 struct bnx2fc_percpu_s
*p
;
2237 printk(KERN_INFO PFX
"%s", version
);
2239 /* register as a fcoe transport */
2240 rc
= fcoe_transport_attach(&bnx2fc_transport
);
2242 printk(KERN_ERR
"failed to register an fcoe transport, check "
2243 "if libfcoe is loaded\n");
2247 INIT_LIST_HEAD(&adapter_list
);
2248 mutex_init(&bnx2fc_dev_lock
);
2251 /* Attach FC transport template */
2252 rc
= bnx2fc_attach_transport();
2256 bnx2fc_wq
= alloc_workqueue("bnx2fc", 0, 0);
2262 bg
= &bnx2fc_global
;
2263 skb_queue_head_init(&bg
->fcoe_rx_list
);
2264 l2_thread
= kthread_create(bnx2fc_l2_rcv_thread
,
2266 "bnx2fc_l2_thread");
2267 if (IS_ERR(l2_thread
)) {
2268 rc
= PTR_ERR(l2_thread
);
2271 wake_up_process(l2_thread
);
2272 spin_lock_bh(&bg
->fcoe_rx_list
.lock
);
2273 bg
->thread
= l2_thread
;
2274 spin_unlock_bh(&bg
->fcoe_rx_list
.lock
);
2276 for_each_possible_cpu(cpu
) {
2277 p
= &per_cpu(bnx2fc_percpu
, cpu
);
2278 INIT_LIST_HEAD(&p
->work_list
);
2279 spin_lock_init(&p
->fp_work_lock
);
2282 for_each_online_cpu(cpu
) {
2283 bnx2fc_percpu_thread_create(cpu
);
2286 /* Initialize per CPU interrupt thread */
2287 register_hotcpu_notifier(&bnx2fc_cpu_notifier
);
2289 cnic_register_driver(CNIC_ULP_FCOE
, &bnx2fc_cnic_cb
);
2294 destroy_workqueue(bnx2fc_wq
);
2296 bnx2fc_release_transport();
2298 fcoe_transport_detach(&bnx2fc_transport
);
2303 static void __exit
bnx2fc_mod_exit(void)
2305 LIST_HEAD(to_be_deleted
);
2306 struct bnx2fc_hba
*hba
, *next
;
2307 struct fcoe_percpu_s
*bg
;
2308 struct task_struct
*l2_thread
;
2309 struct sk_buff
*skb
;
2310 unsigned int cpu
= 0;
2313 * NOTE: Since cnic calls register_driver routine rtnl_lock,
2314 * it will have higher precedence than bnx2fc_dev_lock.
2315 * unregister_device() cannot be called with bnx2fc_dev_lock
2318 mutex_lock(&bnx2fc_dev_lock
);
2319 list_splice(&adapter_list
, &to_be_deleted
);
2320 INIT_LIST_HEAD(&adapter_list
);
2322 mutex_unlock(&bnx2fc_dev_lock
);
2324 /* Unregister with cnic */
2325 list_for_each_entry_safe(hba
, next
, &to_be_deleted
, link
) {
2326 list_del_init(&hba
->link
);
2327 printk(KERN_ERR PFX
"MOD_EXIT:destroy hba = 0x%p, kref = %d\n",
2328 hba
, atomic_read(&hba
->kref
.refcount
));
2329 bnx2fc_ulp_stop(hba
);
2330 /* unregister cnic device */
2331 if (test_and_clear_bit(BNX2FC_CNIC_REGISTERED
,
2332 &hba
->reg_with_cnic
))
2333 hba
->cnic
->unregister_device(hba
->cnic
, CNIC_ULP_FCOE
);
2334 bnx2fc_interface_destroy(hba
);
2336 cnic_unregister_driver(CNIC_ULP_FCOE
);
2338 /* Destroy global thread */
2339 bg
= &bnx2fc_global
;
2340 spin_lock_bh(&bg
->fcoe_rx_list
.lock
);
2341 l2_thread
= bg
->thread
;
2343 while ((skb
= __skb_dequeue(&bg
->fcoe_rx_list
)) != NULL
)
2346 spin_unlock_bh(&bg
->fcoe_rx_list
.lock
);
2349 kthread_stop(l2_thread
);
2351 unregister_hotcpu_notifier(&bnx2fc_cpu_notifier
);
2353 /* Destroy per cpu threads */
2354 for_each_online_cpu(cpu
) {
2355 bnx2fc_percpu_thread_destroy(cpu
);
2358 destroy_workqueue(bnx2fc_wq
);
2360 * detach from scsi transport
2361 * must happen after all destroys are done
2363 bnx2fc_release_transport();
2365 /* detach from fcoe transport */
2366 fcoe_transport_detach(&bnx2fc_transport
);
2369 module_init(bnx2fc_mod_init
);
2370 module_exit(bnx2fc_mod_exit
);
2372 static struct fc_function_template bnx2fc_transport_function
= {
2373 .show_host_node_name
= 1,
2374 .show_host_port_name
= 1,
2375 .show_host_supported_classes
= 1,
2376 .show_host_supported_fc4s
= 1,
2377 .show_host_active_fc4s
= 1,
2378 .show_host_maxframe_size
= 1,
2380 .show_host_port_id
= 1,
2381 .show_host_supported_speeds
= 1,
2382 .get_host_speed
= fc_get_host_speed
,
2383 .show_host_speed
= 1,
2384 .show_host_port_type
= 1,
2385 .get_host_port_state
= fc_get_host_port_state
,
2386 .show_host_port_state
= 1,
2387 .show_host_symbolic_name
= 1,
2389 .dd_fcrport_size
= (sizeof(struct fc_rport_libfc_priv
) +
2390 sizeof(struct bnx2fc_rport
)),
2391 .show_rport_maxframe_size
= 1,
2392 .show_rport_supported_classes
= 1,
2394 .show_host_fabric_name
= 1,
2395 .show_starget_node_name
= 1,
2396 .show_starget_port_name
= 1,
2397 .show_starget_port_id
= 1,
2398 .set_rport_dev_loss_tmo
= fc_set_rport_loss_tmo
,
2399 .show_rport_dev_loss_tmo
= 1,
2400 .get_fc_host_stats
= bnx2fc_get_host_stats
,
2402 .issue_fc_host_lip
= bnx2fc_fcoe_reset
,
2404 .terminate_rport_io
= fc_rport_terminate_io
,
2406 .vport_create
= bnx2fc_vport_create
,
2407 .vport_delete
= bnx2fc_vport_destroy
,
2408 .vport_disable
= bnx2fc_vport_disable
,
2411 static struct fc_function_template bnx2fc_vport_xport_function
= {
2412 .show_host_node_name
= 1,
2413 .show_host_port_name
= 1,
2414 .show_host_supported_classes
= 1,
2415 .show_host_supported_fc4s
= 1,
2416 .show_host_active_fc4s
= 1,
2417 .show_host_maxframe_size
= 1,
2419 .show_host_port_id
= 1,
2420 .show_host_supported_speeds
= 1,
2421 .get_host_speed
= fc_get_host_speed
,
2422 .show_host_speed
= 1,
2423 .show_host_port_type
= 1,
2424 .get_host_port_state
= fc_get_host_port_state
,
2425 .show_host_port_state
= 1,
2426 .show_host_symbolic_name
= 1,
2428 .dd_fcrport_size
= (sizeof(struct fc_rport_libfc_priv
) +
2429 sizeof(struct bnx2fc_rport
)),
2430 .show_rport_maxframe_size
= 1,
2431 .show_rport_supported_classes
= 1,
2433 .show_host_fabric_name
= 1,
2434 .show_starget_node_name
= 1,
2435 .show_starget_port_name
= 1,
2436 .show_starget_port_id
= 1,
2437 .set_rport_dev_loss_tmo
= fc_set_rport_loss_tmo
,
2438 .show_rport_dev_loss_tmo
= 1,
2439 .get_fc_host_stats
= fc_get_host_stats
,
2440 .issue_fc_host_lip
= bnx2fc_fcoe_reset
,
2441 .terminate_rport_io
= fc_rport_terminate_io
,
2445 * scsi_host_template structure used while registering with SCSI-ml
2447 static struct scsi_host_template bnx2fc_shost_template
= {
2448 .module
= THIS_MODULE
,
2449 .name
= "Broadcom Offload FCoE Initiator",
2450 .queuecommand
= bnx2fc_queuecommand
,
2451 .eh_abort_handler
= bnx2fc_eh_abort
, /* abts */
2452 .eh_device_reset_handler
= bnx2fc_eh_device_reset
, /* lun reset */
2453 .eh_target_reset_handler
= bnx2fc_eh_target_reset
, /* tgt reset */
2454 .eh_host_reset_handler
= fc_eh_host_reset
,
2455 .slave_alloc
= fc_slave_alloc
,
2456 .change_queue_depth
= fc_change_queue_depth
,
2457 .change_queue_type
= fc_change_queue_type
,
2460 .can_queue
= BNX2FC_CAN_QUEUE
,
2461 .use_clustering
= ENABLE_CLUSTERING
,
2462 .sg_tablesize
= BNX2FC_MAX_BDS_PER_CMD
,
2466 static struct libfc_function_template bnx2fc_libfc_fcn_templ
= {
2467 .frame_send
= bnx2fc_xmit
,
2468 .elsct_send
= bnx2fc_elsct_send
,
2469 .fcp_abort_io
= bnx2fc_abort_io
,
2470 .fcp_cleanup
= bnx2fc_cleanup
,
2471 .rport_event_callback
= bnx2fc_rport_event_handler
,
2475 * bnx2fc_cnic_cb - global template of bnx2fc - cnic driver interface
2476 * structure carrying callback function pointers
2478 static struct cnic_ulp_ops bnx2fc_cnic_cb
= {
2479 .owner
= THIS_MODULE
,
2480 .cnic_init
= bnx2fc_ulp_init
,
2481 .cnic_exit
= bnx2fc_ulp_exit
,
2482 .cnic_start
= bnx2fc_ulp_start
,
2483 .cnic_stop
= bnx2fc_ulp_stop
,
2484 .indicate_kcqes
= bnx2fc_indicate_kcqe
,
2485 .indicate_netevent
= bnx2fc_indicate_netevent
,