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 int bnx2fc_mfs_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
;
672 mfs
= netdev
->mtu
- (sizeof(struct fcoe_hdr
) +
673 sizeof(struct fcoe_crc_eof
));
674 max_mfs
= BNX2FC_MAX_PAYLOAD
+ sizeof(struct fc_frame_header
);
675 BNX2FC_HBA_DBG(lport
, "mfs = %d, max_mfs = %d\n", mfs
, max_mfs
);
679 /* Adjust mfs to be a multiple of 256 bytes */
680 mfs
= (((mfs
- sizeof(struct fc_frame_header
)) / BNX2FC_MIN_PAYLOAD
) *
682 mfs
= mfs
+ sizeof(struct fc_frame_header
);
684 BNX2FC_HBA_DBG(lport
, "Set MFS = %d\n", mfs
);
685 if (fc_set_mfs(lport
, mfs
))
689 static void bnx2fc_link_speed_update(struct fc_lport
*lport
)
691 struct fcoe_port
*port
= lport_priv(lport
);
692 struct bnx2fc_hba
*hba
= port
->priv
;
693 struct net_device
*netdev
= hba
->netdev
;
694 struct ethtool_cmd ecmd
= { ETHTOOL_GSET
};
696 if (!dev_ethtool_get_settings(netdev
, &ecmd
)) {
697 lport
->link_supported_speeds
&=
698 ~(FC_PORTSPEED_1GBIT
| FC_PORTSPEED_10GBIT
);
699 if (ecmd
.supported
& (SUPPORTED_1000baseT_Half
|
700 SUPPORTED_1000baseT_Full
))
701 lport
->link_supported_speeds
|= FC_PORTSPEED_1GBIT
;
702 if (ecmd
.supported
& SUPPORTED_10000baseT_Full
)
703 lport
->link_supported_speeds
|= FC_PORTSPEED_10GBIT
;
705 if (ecmd
.speed
== SPEED_1000
)
706 lport
->link_speed
= FC_PORTSPEED_1GBIT
;
707 if (ecmd
.speed
== SPEED_10000
)
708 lport
->link_speed
= FC_PORTSPEED_10GBIT
;
712 static int bnx2fc_link_ok(struct fc_lport
*lport
)
714 struct fcoe_port
*port
= lport_priv(lport
);
715 struct bnx2fc_hba
*hba
= port
->priv
;
716 struct net_device
*dev
= hba
->phys_dev
;
719 if ((dev
->flags
& IFF_UP
) && netif_carrier_ok(dev
))
720 clear_bit(ADAPTER_STATE_LINK_DOWN
, &hba
->adapter_state
);
722 set_bit(ADAPTER_STATE_LINK_DOWN
, &hba
->adapter_state
);
729 * bnx2fc_get_link_state - get network link state
731 * @hba: adapter instance pointer
733 * updates adapter structure flag based on netdev state
735 void bnx2fc_get_link_state(struct bnx2fc_hba
*hba
)
737 if (test_bit(__LINK_STATE_NOCARRIER
, &hba
->netdev
->state
))
738 set_bit(ADAPTER_STATE_LINK_DOWN
, &hba
->adapter_state
);
740 clear_bit(ADAPTER_STATE_LINK_DOWN
, &hba
->adapter_state
);
743 static int bnx2fc_net_config(struct fc_lport
*lport
)
745 struct bnx2fc_hba
*hba
;
746 struct fcoe_port
*port
;
749 port
= lport_priv(lport
);
752 /* require support for get_pauseparam ethtool op. */
753 if (!hba
->phys_dev
->ethtool_ops
||
754 !hba
->phys_dev
->ethtool_ops
->get_pauseparam
)
757 if (bnx2fc_mfs_update(lport
))
760 skb_queue_head_init(&port
->fcoe_pending_queue
);
761 port
->fcoe_pending_queue_active
= 0;
762 setup_timer(&port
->timer
, fcoe_queue_timer
, (unsigned long) lport
);
764 bnx2fc_link_speed_update(lport
);
767 wwnn
= fcoe_wwn_from_mac(hba
->ctlr
.ctl_src_addr
, 1, 0);
768 BNX2FC_HBA_DBG(lport
, "WWNN = 0x%llx\n", wwnn
);
769 fc_set_wwnn(lport
, wwnn
);
771 wwpn
= fcoe_wwn_from_mac(hba
->ctlr
.ctl_src_addr
, 2, 0);
772 BNX2FC_HBA_DBG(lport
, "WWPN = 0x%llx\n", wwpn
);
773 fc_set_wwpn(lport
, wwpn
);
779 static void bnx2fc_destroy_timer(unsigned long data
)
781 struct bnx2fc_hba
*hba
= (struct bnx2fc_hba
*)data
;
783 BNX2FC_HBA_DBG(hba
->ctlr
.lp
, "ERROR:bnx2fc_destroy_timer - "
784 "Destroy compl not received!!\n");
785 hba
->flags
|= BNX2FC_FLAG_DESTROY_CMPL
;
786 wake_up_interruptible(&hba
->destroy_wait
);
790 * bnx2fc_indicate_netevent - Generic netdev event handler
792 * @context: adapter structure pointer
795 * Handles NETDEV_UP, NETDEV_DOWN, NETDEV_GOING_DOWN,NETDEV_CHANGE and
796 * NETDEV_CHANGE_MTU events
798 static void bnx2fc_indicate_netevent(void *context
, unsigned long event
)
800 struct bnx2fc_hba
*hba
= (struct bnx2fc_hba
*)context
;
801 struct fc_lport
*lport
= hba
->ctlr
.lp
;
802 struct fc_lport
*vport
;
803 u32 link_possible
= 1;
805 if (!test_bit(BNX2FC_CREATE_DONE
, &hba
->init_done
)) {
806 BNX2FC_MISC_DBG("driver not ready. event=%s %ld\n",
807 hba
->netdev
->name
, event
);
813 * indicate_netevent cannot be called from cnic unless bnx2fc
814 * does register_device
818 BNX2FC_HBA_DBG(lport
, "enter netevent handler - event=%s %ld\n",
819 hba
->netdev
->name
, event
);
823 BNX2FC_HBA_DBG(lport
, "Port up, adapter_state = %ld\n",
825 if (!test_bit(ADAPTER_STATE_UP
, &hba
->adapter_state
))
826 printk(KERN_ERR
"indicate_netevent: "\
827 "adapter is not UP!!\n");
828 /* fall thru to update mfs if MTU has changed */
829 case NETDEV_CHANGEMTU
:
830 BNX2FC_HBA_DBG(lport
, "NETDEV_CHANGEMTU event\n");
831 bnx2fc_mfs_update(lport
);
832 mutex_lock(&lport
->lp_mutex
);
833 list_for_each_entry(vport
, &lport
->vports
, list
)
834 bnx2fc_mfs_update(vport
);
835 mutex_unlock(&lport
->lp_mutex
);
839 BNX2FC_HBA_DBG(lport
, "Port down\n");
840 clear_bit(ADAPTER_STATE_GOING_DOWN
, &hba
->adapter_state
);
841 clear_bit(ADAPTER_STATE_UP
, &hba
->adapter_state
);
845 case NETDEV_GOING_DOWN
:
846 BNX2FC_HBA_DBG(lport
, "Port going down\n");
847 set_bit(ADAPTER_STATE_GOING_DOWN
, &hba
->adapter_state
);
852 BNX2FC_HBA_DBG(lport
, "NETDEV_CHANGE\n");
856 printk(KERN_ERR PFX
"Unkonwn netevent %ld", event
);
860 bnx2fc_link_speed_update(lport
);
862 if (link_possible
&& !bnx2fc_link_ok(lport
)) {
863 printk(KERN_ERR
"indicate_netevent: call ctlr_link_up\n");
864 fcoe_ctlr_link_up(&hba
->ctlr
);
866 printk(KERN_ERR
"indicate_netevent: call ctlr_link_down\n");
867 if (fcoe_ctlr_link_down(&hba
->ctlr
)) {
868 clear_bit(ADAPTER_STATE_READY
, &hba
->adapter_state
);
869 mutex_lock(&lport
->lp_mutex
);
870 list_for_each_entry(vport
, &lport
->vports
, list
)
871 fc_host_port_type(vport
->host
) =
873 mutex_unlock(&lport
->lp_mutex
);
874 fc_host_port_type(lport
->host
) = FC_PORTTYPE_UNKNOWN
;
875 per_cpu_ptr(lport
->dev_stats
,
876 get_cpu())->LinkFailureCount
++;
878 fcoe_clean_pending_queue(lport
);
880 init_waitqueue_head(&hba
->shutdown_wait
);
881 BNX2FC_HBA_DBG(lport
, "indicate_netevent "
882 "num_ofld_sess = %d\n",
884 hba
->wait_for_link_down
= 1;
885 BNX2FC_HBA_DBG(lport
, "waiting for uploads to "
888 wait_event_interruptible(hba
->shutdown_wait
,
889 (hba
->num_ofld_sess
== 0));
890 BNX2FC_HBA_DBG(lport
, "wakeup - num_ofld_sess = %d\n",
892 hba
->wait_for_link_down
= 0;
894 if (signal_pending(current
))
895 flush_signals(current
);
900 static int bnx2fc_libfc_config(struct fc_lport
*lport
)
903 /* Set the function pointers set by bnx2fc driver */
904 memcpy(&lport
->tt
, &bnx2fc_libfc_fcn_templ
,
905 sizeof(struct libfc_function_template
));
906 fc_elsct_init(lport
);
908 fc_rport_init(lport
);
913 static int bnx2fc_em_config(struct fc_lport
*lport
)
915 struct fcoe_port
*port
= lport_priv(lport
);
916 struct bnx2fc_hba
*hba
= port
->priv
;
918 if (!fc_exch_mgr_alloc(lport
, FC_CLASS_3
, FCOE_MIN_XID
,
919 FCOE_MAX_XID
, NULL
)) {
920 printk(KERN_ERR PFX
"em_config:fc_exch_mgr_alloc failed\n");
924 hba
->cmd_mgr
= bnx2fc_cmd_mgr_alloc(hba
, BNX2FC_MIN_XID
,
928 printk(KERN_ERR PFX
"em_config:bnx2fc_cmd_mgr_alloc failed\n");
929 fc_exch_mgr_free(lport
);
935 static int bnx2fc_lport_config(struct fc_lport
*lport
)
939 lport
->max_retry_count
= 3;
940 lport
->max_rport_retry_count
= 3;
941 lport
->e_d_tov
= 2 * 1000;
942 lport
->r_a_tov
= 10 * 1000;
944 /* REVISIT: enable when supporting tape devices
945 lport->service_params = (FCP_SPPF_INIT_FCN | FCP_SPPF_RD_XRDY_DIS |
946 FCP_SPPF_RETRY | FCP_SPPF_CONF_COMPL);
948 lport
->service_params
= (FCP_SPPF_INIT_FCN
| FCP_SPPF_RD_XRDY_DIS
);
949 lport
->does_npiv
= 1;
951 memset(&lport
->rnid_gen
, 0, sizeof(struct fc_els_rnid_gen
));
952 lport
->rnid_gen
.rnid_atype
= BNX2FC_RNID_HBA
;
954 /* alloc stats structure */
955 if (fc_lport_init_stats(lport
))
958 /* Finish fc_lport configuration */
959 fc_lport_config(lport
);
965 * bnx2fc_fip_recv - handle a received FIP frame.
967 * @skb: the received skb
968 * @dev: associated &net_device
969 * @ptype: the &packet_type structure which was used to register this handler.
970 * @orig_dev: original receive &net_device, in case @ dev is a bond.
972 * Returns: 0 for success
974 static int bnx2fc_fip_recv(struct sk_buff
*skb
, struct net_device
*dev
,
975 struct packet_type
*ptype
,
976 struct net_device
*orig_dev
)
978 struct bnx2fc_hba
*hba
;
979 hba
= container_of(ptype
, struct bnx2fc_hba
, fip_packet_type
);
980 fcoe_ctlr_recv(&hba
->ctlr
, skb
);
985 * bnx2fc_update_src_mac - Update Ethernet MAC filters.
987 * @fip: FCoE controller.
988 * @old: Unicast MAC address to delete if the MAC is non-zero.
989 * @new: Unicast MAC address to add.
991 * Remove any previously-set unicast MAC filter.
992 * Add secondary FCoE MAC address filter for our OUI.
994 static void bnx2fc_update_src_mac(struct fc_lport
*lport
, u8
*addr
)
996 struct fcoe_port
*port
= lport_priv(lport
);
998 memcpy(port
->data_src_addr
, addr
, ETH_ALEN
);
1002 * bnx2fc_get_src_mac - return the ethernet source address for an lport
1004 * @lport: libfc port
1006 static u8
*bnx2fc_get_src_mac(struct fc_lport
*lport
)
1008 struct fcoe_port
*port
;
1010 port
= (struct fcoe_port
*)lport_priv(lport
);
1011 return port
->data_src_addr
;
1015 * bnx2fc_fip_send - send an Ethernet-encapsulated FIP frame.
1017 * @fip: FCoE controller.
1020 static void bnx2fc_fip_send(struct fcoe_ctlr
*fip
, struct sk_buff
*skb
)
1022 skb
->dev
= bnx2fc_from_ctlr(fip
)->netdev
;
1023 dev_queue_xmit(skb
);
1026 static int bnx2fc_vport_create(struct fc_vport
*vport
, bool disabled
)
1028 struct Scsi_Host
*shost
= vport_to_shost(vport
);
1029 struct fc_lport
*n_port
= shost_priv(shost
);
1030 struct fcoe_port
*port
= lport_priv(n_port
);
1031 struct bnx2fc_hba
*hba
= port
->priv
;
1032 struct net_device
*netdev
= hba
->netdev
;
1033 struct fc_lport
*vn_port
;
1035 if (!test_bit(BNX2FC_FW_INIT_DONE
, &hba
->init_done
)) {
1036 printk(KERN_ERR PFX
"vn ports cannot be created on"
1040 mutex_lock(&bnx2fc_dev_lock
);
1041 vn_port
= bnx2fc_if_create(hba
, &vport
->dev
, 1);
1042 mutex_unlock(&bnx2fc_dev_lock
);
1044 if (IS_ERR(vn_port
)) {
1045 printk(KERN_ERR PFX
"bnx2fc_vport_create (%s) failed\n",
1051 fc_vport_set_state(vport
, FC_VPORT_DISABLED
);
1053 vn_port
->boot_time
= jiffies
;
1054 fc_lport_init(vn_port
);
1055 fc_fabric_login(vn_port
);
1056 fc_vport_setlink(vn_port
);
1061 static int bnx2fc_vport_destroy(struct fc_vport
*vport
)
1063 struct Scsi_Host
*shost
= vport_to_shost(vport
);
1064 struct fc_lport
*n_port
= shost_priv(shost
);
1065 struct fc_lport
*vn_port
= vport
->dd_data
;
1066 struct fcoe_port
*port
= lport_priv(vn_port
);
1068 mutex_lock(&n_port
->lp_mutex
);
1069 list_del(&vn_port
->list
);
1070 mutex_unlock(&n_port
->lp_mutex
);
1071 queue_work(bnx2fc_wq
, &port
->destroy_work
);
1075 static int bnx2fc_vport_disable(struct fc_vport
*vport
, bool disable
)
1077 struct fc_lport
*lport
= vport
->dd_data
;
1080 fc_vport_set_state(vport
, FC_VPORT_DISABLED
);
1081 fc_fabric_logoff(lport
);
1083 lport
->boot_time
= jiffies
;
1084 fc_fabric_login(lport
);
1085 fc_vport_setlink(lport
);
1091 static int bnx2fc_netdev_setup(struct bnx2fc_hba
*hba
)
1093 struct net_device
*netdev
= hba
->netdev
;
1094 struct net_device
*physdev
= hba
->phys_dev
;
1095 struct netdev_hw_addr
*ha
;
1096 int sel_san_mac
= 0;
1098 /* Do not support for bonding device */
1099 if ((netdev
->priv_flags
& IFF_MASTER_ALB
) ||
1100 (netdev
->priv_flags
& IFF_SLAVE_INACTIVE
) ||
1101 (netdev
->priv_flags
& IFF_MASTER_8023AD
)) {
1105 /* setup Source MAC Address */
1107 for_each_dev_addr(physdev
, ha
) {
1108 BNX2FC_MISC_DBG("net_config: ha->type = %d, fip_mac = ",
1110 printk(KERN_INFO
"%2x:%2x:%2x:%2x:%2x:%2x\n", ha
->addr
[0],
1111 ha
->addr
[1], ha
->addr
[2], ha
->addr
[3],
1112 ha
->addr
[4], ha
->addr
[5]);
1114 if ((ha
->type
== NETDEV_HW_ADDR_T_SAN
) &&
1115 (is_valid_ether_addr(ha
->addr
))) {
1116 memcpy(hba
->ctlr
.ctl_src_addr
, ha
->addr
, ETH_ALEN
);
1118 BNX2FC_MISC_DBG("Found SAN MAC\n");
1126 hba
->fip_packet_type
.func
= bnx2fc_fip_recv
;
1127 hba
->fip_packet_type
.type
= htons(ETH_P_FIP
);
1128 hba
->fip_packet_type
.dev
= netdev
;
1129 dev_add_pack(&hba
->fip_packet_type
);
1131 hba
->fcoe_packet_type
.func
= bnx2fc_rcv
;
1132 hba
->fcoe_packet_type
.type
= __constant_htons(ETH_P_FCOE
);
1133 hba
->fcoe_packet_type
.dev
= netdev
;
1134 dev_add_pack(&hba
->fcoe_packet_type
);
1139 static int bnx2fc_attach_transport(void)
1141 bnx2fc_transport_template
=
1142 fc_attach_transport(&bnx2fc_transport_function
);
1144 if (bnx2fc_transport_template
== NULL
) {
1145 printk(KERN_ERR PFX
"Failed to attach FC transport\n");
1149 bnx2fc_vport_xport_template
=
1150 fc_attach_transport(&bnx2fc_vport_xport_function
);
1151 if (bnx2fc_vport_xport_template
== NULL
) {
1153 "Failed to attach FC transport for vport\n");
1154 fc_release_transport(bnx2fc_transport_template
);
1155 bnx2fc_transport_template
= NULL
;
1160 static void bnx2fc_release_transport(void)
1162 fc_release_transport(bnx2fc_transport_template
);
1163 fc_release_transport(bnx2fc_vport_xport_template
);
1164 bnx2fc_transport_template
= NULL
;
1165 bnx2fc_vport_xport_template
= NULL
;
1168 static void bnx2fc_interface_release(struct kref
*kref
)
1170 struct bnx2fc_hba
*hba
;
1171 struct net_device
*netdev
;
1172 struct net_device
*phys_dev
;
1174 hba
= container_of(kref
, struct bnx2fc_hba
, kref
);
1175 BNX2FC_HBA_DBG(hba
->ctlr
.lp
, "Interface is being released\n");
1177 netdev
= hba
->netdev
;
1178 phys_dev
= hba
->phys_dev
;
1180 /* tear-down FIP controller */
1181 if (test_and_clear_bit(BNX2FC_CTLR_INIT_DONE
, &hba
->init_done
))
1182 fcoe_ctlr_destroy(&hba
->ctlr
);
1184 /* Free the command manager */
1186 bnx2fc_cmd_mgr_free(hba
->cmd_mgr
);
1187 hba
->cmd_mgr
= NULL
;
1190 module_put(THIS_MODULE
);
1193 static inline void bnx2fc_interface_get(struct bnx2fc_hba
*hba
)
1195 kref_get(&hba
->kref
);
1198 static inline void bnx2fc_interface_put(struct bnx2fc_hba
*hba
)
1200 kref_put(&hba
->kref
, bnx2fc_interface_release
);
1202 static void bnx2fc_interface_destroy(struct bnx2fc_hba
*hba
)
1204 bnx2fc_unbind_pcidev(hba
);
1209 * bnx2fc_interface_create - create a new fcoe instance
1211 * @cnic: pointer to cnic device
1213 * Creates a new FCoE instance on the given device which include allocating
1214 * hba structure, scsi_host and lport structures.
1216 static struct bnx2fc_hba
*bnx2fc_interface_create(struct cnic_dev
*cnic
)
1218 struct bnx2fc_hba
*hba
;
1221 hba
= kzalloc(sizeof(*hba
), GFP_KERNEL
);
1223 printk(KERN_ERR PFX
"Unable to allocate hba structure\n");
1226 spin_lock_init(&hba
->hba_lock
);
1227 mutex_init(&hba
->hba_mutex
);
1230 rc
= bnx2fc_bind_pcidev(hba
);
1233 hba
->phys_dev
= cnic
->netdev
;
1234 /* will get overwritten after we do vlan discovery */
1235 hba
->netdev
= hba
->phys_dev
;
1237 init_waitqueue_head(&hba
->shutdown_wait
);
1238 init_waitqueue_head(&hba
->destroy_wait
);
1242 printk(KERN_ERR PFX
"create_interface: bind error\n");
1247 static int bnx2fc_interface_setup(struct bnx2fc_hba
*hba
,
1248 enum fip_state fip_mode
)
1251 struct net_device
*netdev
= hba
->netdev
;
1252 struct fcoe_ctlr
*fip
= &hba
->ctlr
;
1255 kref_init(&hba
->kref
);
1259 /* Initialize FIP */
1260 memset(fip
, 0, sizeof(*fip
));
1261 fcoe_ctlr_init(fip
, fip_mode
);
1262 hba
->ctlr
.send
= bnx2fc_fip_send
;
1263 hba
->ctlr
.update_mac
= bnx2fc_update_src_mac
;
1264 hba
->ctlr
.get_src_addr
= bnx2fc_get_src_mac
;
1265 set_bit(BNX2FC_CTLR_INIT_DONE
, &hba
->init_done
);
1267 rc
= bnx2fc_netdev_setup(hba
);
1271 hba
->next_conn_id
= 0;
1273 memset(hba
->tgt_ofld_list
, 0, sizeof(hba
->tgt_ofld_list
));
1274 hba
->num_ofld_sess
= 0;
1279 fcoe_ctlr_destroy(&hba
->ctlr
);
1281 bnx2fc_interface_put(hba
);
1286 * bnx2fc_if_create - Create FCoE instance on a given interface
1288 * @hba: FCoE interface to create a local port on
1289 * @parent: Device pointer to be the parent in sysfs for the SCSI host
1290 * @npiv: Indicates if the port is vport or not
1292 * Creates a fc_lport instance and a Scsi_Host instance and configure them.
1294 * Returns: Allocated fc_lport or an error pointer
1296 static struct fc_lport
*bnx2fc_if_create(struct bnx2fc_hba
*hba
,
1297 struct device
*parent
, int npiv
)
1299 struct fc_lport
*lport
= NULL
;
1300 struct fcoe_port
*port
;
1301 struct Scsi_Host
*shost
;
1302 struct fc_vport
*vport
= dev_to_vport(parent
);
1305 /* Allocate Scsi_Host structure */
1307 lport
= libfc_host_alloc(&bnx2fc_shost_template
,
1308 sizeof(struct fcoe_port
));
1310 lport
= libfc_vport_create(vport
,
1311 sizeof(struct fcoe_port
));
1315 printk(KERN_ERR PFX
"could not allocate scsi host structure\n");
1318 shost
= lport
->host
;
1319 port
= lport_priv(lport
);
1320 port
->lport
= lport
;
1322 INIT_WORK(&port
->destroy_work
, bnx2fc_destroy_work
);
1324 /* Configure fcoe_port */
1325 rc
= bnx2fc_lport_config(lport
);
1330 vport
= dev_to_vport(parent
);
1331 printk(KERN_ERR PFX
"Setting vport names, 0x%llX 0x%llX\n",
1332 vport
->node_name
, vport
->port_name
);
1333 fc_set_wwnn(lport
, vport
->node_name
);
1334 fc_set_wwpn(lport
, vport
->port_name
);
1336 /* Configure netdev and networking properties of the lport */
1337 rc
= bnx2fc_net_config(lport
);
1339 printk(KERN_ERR PFX
"Error on bnx2fc_net_config\n");
1343 rc
= bnx2fc_shost_config(lport
, parent
);
1345 printk(KERN_ERR PFX
"Couldnt configure shost for %s\n",
1350 /* Initialize the libfc library */
1351 rc
= bnx2fc_libfc_config(lport
);
1353 printk(KERN_ERR PFX
"Couldnt configure libfc\n");
1356 fc_host_port_type(lport
->host
) = FC_PORTTYPE_UNKNOWN
;
1358 /* Allocate exchange manager */
1360 rc
= bnx2fc_em_config(lport
);
1362 printk(KERN_ERR PFX
"Error on bnx2fc_em_config\n");
1367 bnx2fc_interface_get(hba
);
1371 scsi_remove_host(shost
);
1373 scsi_host_put(lport
->host
);
1377 static void bnx2fc_netdev_cleanup(struct bnx2fc_hba
*hba
)
1379 /* Dont listen for Ethernet packets anymore */
1380 __dev_remove_pack(&hba
->fcoe_packet_type
);
1381 __dev_remove_pack(&hba
->fip_packet_type
);
1385 static void bnx2fc_if_destroy(struct fc_lport
*lport
)
1387 struct fcoe_port
*port
= lport_priv(lport
);
1388 struct bnx2fc_hba
*hba
= port
->priv
;
1390 BNX2FC_HBA_DBG(hba
->ctlr
.lp
, "ENTERED bnx2fc_if_destroy\n");
1391 /* Stop the transmit retry timer */
1392 del_timer_sync(&port
->timer
);
1394 /* Free existing transmit skbs */
1395 fcoe_clean_pending_queue(lport
);
1397 bnx2fc_interface_put(hba
);
1399 /* Free queued packets for the receive thread */
1400 bnx2fc_clean_rx_queue(lport
);
1402 /* Detach from scsi-ml */
1403 fc_remove_host(lport
->host
);
1404 scsi_remove_host(lport
->host
);
1407 * Note that only the physical lport will have the exchange manager.
1408 * for vports, this function is NOP
1410 fc_exch_mgr_free(lport
);
1412 /* Free memory used by statistical counters */
1413 fc_lport_free_stats(lport
);
1415 /* Release Scsi_Host */
1416 scsi_host_put(lport
->host
);
1420 * bnx2fc_destroy - Destroy a bnx2fc FCoE interface
1422 * @buffer: The name of the Ethernet interface to be destroyed
1423 * @kp: The associated kernel parameter
1425 * Called from sysfs.
1427 * Returns: 0 for success
1429 static int bnx2fc_destroy(struct net_device
*netdev
)
1431 struct bnx2fc_hba
*hba
= NULL
;
1432 struct net_device
*phys_dev
;
1437 mutex_lock(&bnx2fc_dev_lock
);
1438 #ifdef CONFIG_SCSI_BNX2X_FCOE_MODULE
1439 if (THIS_MODULE
->state
!= MODULE_STATE_LIVE
) {
1444 /* obtain physical netdev */
1445 if (netdev
->priv_flags
& IFF_802_1Q_VLAN
)
1446 phys_dev
= vlan_dev_real_dev(netdev
);
1448 printk(KERN_ERR PFX
"Not a vlan device\n");
1453 hba
= bnx2fc_hba_lookup(phys_dev
);
1454 if (!hba
|| !hba
->ctlr
.lp
) {
1456 printk(KERN_ERR PFX
"bnx2fc_destroy: hba or lport not found\n");
1460 if (!test_bit(BNX2FC_CREATE_DONE
, &hba
->init_done
)) {
1461 printk(KERN_ERR PFX
"bnx2fc_destroy: Create not called\n");
1465 bnx2fc_netdev_cleanup(hba
);
1469 bnx2fc_if_destroy(hba
->ctlr
.lp
);
1471 destroy_workqueue(hba
->timer_work_queue
);
1473 if (test_bit(BNX2FC_FW_INIT_DONE
, &hba
->init_done
))
1474 bnx2fc_fw_destroy(hba
);
1476 clear_bit(BNX2FC_CREATE_DONE
, &hba
->init_done
);
1478 mutex_unlock(&bnx2fc_dev_lock
);
1483 static void bnx2fc_destroy_work(struct work_struct
*work
)
1485 struct fcoe_port
*port
;
1486 struct fc_lport
*lport
;
1488 port
= container_of(work
, struct fcoe_port
, destroy_work
);
1489 lport
= port
->lport
;
1491 BNX2FC_HBA_DBG(lport
, "Entered bnx2fc_destroy_work\n");
1493 bnx2fc_port_shutdown(lport
);
1495 mutex_lock(&bnx2fc_dev_lock
);
1496 bnx2fc_if_destroy(lport
);
1497 mutex_unlock(&bnx2fc_dev_lock
);
1501 static void bnx2fc_unbind_adapter_devices(struct bnx2fc_hba
*hba
)
1503 bnx2fc_free_fw_resc(hba
);
1504 bnx2fc_free_task_ctx(hba
);
1508 * bnx2fc_bind_adapter_devices - binds bnx2fc adapter with the associated
1511 * @hba: Adapter instance
1513 static int bnx2fc_bind_adapter_devices(struct bnx2fc_hba
*hba
)
1515 if (bnx2fc_setup_task_ctx(hba
))
1518 if (bnx2fc_setup_fw_resc(hba
))
1523 bnx2fc_unbind_adapter_devices(hba
);
1527 static int bnx2fc_bind_pcidev(struct bnx2fc_hba
*hba
)
1529 struct cnic_dev
*cnic
;
1532 printk(KERN_ERR PFX
"cnic is NULL\n");
1536 hba
->pcidev
= cnic
->pcidev
;
1538 pci_dev_get(hba
->pcidev
);
1543 static void bnx2fc_unbind_pcidev(struct bnx2fc_hba
*hba
)
1546 pci_dev_put(hba
->pcidev
);
1553 * bnx2fc_ulp_start - cnic callback to initialize & start adapter instance
1555 * @handle: transport handle pointing to adapter struture
1557 * This function maps adapter structure to pcidev structure and initiates
1558 * firmware handshake to enable/initialize on-chip FCoE components.
1559 * This bnx2fc - cnic interface api callback is used after following
1560 * conditions are met -
1561 * a) underlying network interface is up (marked by event NETDEV_UP
1563 * b) bnx2fc adatper structure is registered.
1565 static void bnx2fc_ulp_start(void *handle
)
1567 struct bnx2fc_hba
*hba
= handle
;
1568 struct fc_lport
*lport
= hba
->ctlr
.lp
;
1570 BNX2FC_MISC_DBG("Entered %s\n", __func__
);
1571 mutex_lock(&bnx2fc_dev_lock
);
1573 if (test_bit(BNX2FC_FW_INIT_DONE
, &hba
->init_done
))
1576 if (test_bit(BNX2FC_CREATE_DONE
, &hba
->init_done
))
1577 bnx2fc_fw_init(hba
);
1580 mutex_unlock(&bnx2fc_dev_lock
);
1582 BNX2FC_MISC_DBG("bnx2fc started.\n");
1584 /* Kick off Fabric discovery*/
1585 if (test_bit(BNX2FC_CREATE_DONE
, &hba
->init_done
)) {
1586 printk(KERN_ERR PFX
"ulp_init: start discovery\n");
1587 lport
->tt
.frame_send
= bnx2fc_xmit
;
1588 bnx2fc_start_disc(hba
);
1592 static void bnx2fc_port_shutdown(struct fc_lport
*lport
)
1594 BNX2FC_MISC_DBG("Entered %s\n", __func__
);
1595 fc_fabric_logoff(lport
);
1596 fc_lport_destroy(lport
);
1599 static void bnx2fc_stop(struct bnx2fc_hba
*hba
)
1601 struct fc_lport
*lport
;
1602 struct fc_lport
*vport
;
1604 BNX2FC_MISC_DBG("ENTERED %s - init_done = %ld\n", __func__
,
1606 if (test_bit(BNX2FC_FW_INIT_DONE
, &hba
->init_done
) &&
1607 test_bit(BNX2FC_CREATE_DONE
, &hba
->init_done
)) {
1608 lport
= hba
->ctlr
.lp
;
1609 bnx2fc_port_shutdown(lport
);
1610 BNX2FC_HBA_DBG(lport
, "bnx2fc_stop: waiting for %d "
1611 "offloaded sessions\n",
1612 hba
->num_ofld_sess
);
1613 wait_event_interruptible(hba
->shutdown_wait
,
1614 (hba
->num_ofld_sess
== 0));
1615 mutex_lock(&lport
->lp_mutex
);
1616 list_for_each_entry(vport
, &lport
->vports
, list
)
1617 fc_host_port_type(vport
->host
) = FC_PORTTYPE_UNKNOWN
;
1618 mutex_unlock(&lport
->lp_mutex
);
1619 fc_host_port_type(lport
->host
) = FC_PORTTYPE_UNKNOWN
;
1620 fcoe_ctlr_link_down(&hba
->ctlr
);
1621 fcoe_clean_pending_queue(lport
);
1623 mutex_lock(&hba
->hba_mutex
);
1624 clear_bit(ADAPTER_STATE_UP
, &hba
->adapter_state
);
1625 clear_bit(ADAPTER_STATE_GOING_DOWN
, &hba
->adapter_state
);
1627 clear_bit(ADAPTER_STATE_READY
, &hba
->adapter_state
);
1628 mutex_unlock(&hba
->hba_mutex
);
1632 static int bnx2fc_fw_init(struct bnx2fc_hba
*hba
)
1634 #define BNX2FC_INIT_POLL_TIME (1000 / HZ)
1638 rc
= bnx2fc_bind_adapter_devices(hba
);
1640 printk(KERN_ALERT PFX
1641 "bnx2fc_bind_adapter_devices failed - rc = %d\n", rc
);
1645 rc
= bnx2fc_send_fw_fcoe_init_msg(hba
);
1647 printk(KERN_ALERT PFX
1648 "bnx2fc_send_fw_fcoe_init_msg failed - rc = %d\n", rc
);
1653 * Wait until the adapter init message is complete, and adapter
1656 while (!test_bit(ADAPTER_STATE_UP
, &hba
->adapter_state
) && i
--)
1657 msleep(BNX2FC_INIT_POLL_TIME
);
1659 if (!test_bit(ADAPTER_STATE_UP
, &hba
->adapter_state
)) {
1660 printk(KERN_ERR PFX
"bnx2fc_start: %s failed to initialize. "
1662 hba
->cnic
->netdev
->name
);
1668 /* Mark HBA to indicate that the FW INIT is done */
1669 set_bit(BNX2FC_FW_INIT_DONE
, &hba
->init_done
);
1673 bnx2fc_unbind_adapter_devices(hba
);
1678 static void bnx2fc_fw_destroy(struct bnx2fc_hba
*hba
)
1680 if (test_and_clear_bit(BNX2FC_FW_INIT_DONE
, &hba
->init_done
)) {
1681 if (bnx2fc_send_fw_fcoe_destroy_msg(hba
) == 0) {
1682 init_timer(&hba
->destroy_timer
);
1683 hba
->destroy_timer
.expires
= BNX2FC_FW_TIMEOUT
+
1685 hba
->destroy_timer
.function
= bnx2fc_destroy_timer
;
1686 hba
->destroy_timer
.data
= (unsigned long)hba
;
1687 add_timer(&hba
->destroy_timer
);
1688 wait_event_interruptible(hba
->destroy_wait
,
1690 BNX2FC_FLAG_DESTROY_CMPL
));
1691 /* This should never happen */
1692 if (signal_pending(current
))
1693 flush_signals(current
);
1695 del_timer_sync(&hba
->destroy_timer
);
1697 bnx2fc_unbind_adapter_devices(hba
);
1702 * bnx2fc_ulp_stop - cnic callback to shutdown adapter instance
1704 * @handle: transport handle pointing to adapter structure
1706 * Driver checks if adapter is already in shutdown mode, if not start
1707 * the shutdown process.
1709 static void bnx2fc_ulp_stop(void *handle
)
1711 struct bnx2fc_hba
*hba
= (struct bnx2fc_hba
*)handle
;
1713 printk(KERN_ERR
"ULP_STOP\n");
1715 mutex_lock(&bnx2fc_dev_lock
);
1717 bnx2fc_fw_destroy(hba
);
1718 mutex_unlock(&bnx2fc_dev_lock
);
1721 static void bnx2fc_start_disc(struct bnx2fc_hba
*hba
)
1723 struct fc_lport
*lport
;
1726 BNX2FC_MISC_DBG("Entered %s\n", __func__
);
1727 /* Kick off FIP/FLOGI */
1728 if (!test_bit(BNX2FC_FW_INIT_DONE
, &hba
->init_done
)) {
1729 printk(KERN_ERR PFX
"Init not done yet\n");
1733 lport
= hba
->ctlr
.lp
;
1734 BNX2FC_HBA_DBG(lport
, "calling fc_fabric_login\n");
1736 if (!bnx2fc_link_ok(lport
)) {
1737 BNX2FC_HBA_DBG(lport
, "ctlr_link_up\n");
1738 fcoe_ctlr_link_up(&hba
->ctlr
);
1739 fc_host_port_type(lport
->host
) = FC_PORTTYPE_NPORT
;
1740 set_bit(ADAPTER_STATE_READY
, &hba
->adapter_state
);
1743 /* wait for the FCF to be selected before issuing FLOGI */
1744 while (!hba
->ctlr
.sel_fcf
) {
1746 /* give up after 3 secs */
1747 if (++wait_cnt
> 12)
1750 fc_lport_init(lport
);
1751 fc_fabric_login(lport
);
1756 * bnx2fc_ulp_init - Initialize an adapter instance
1758 * @dev : cnic device handle
1759 * Called from cnic_register_driver() context to initialize all
1760 * enumerated cnic devices. This routine allocates adapter structure
1761 * and other device specific resources.
1763 static void bnx2fc_ulp_init(struct cnic_dev
*dev
)
1765 struct bnx2fc_hba
*hba
;
1768 BNX2FC_MISC_DBG("Entered %s\n", __func__
);
1769 /* bnx2fc works only when bnx2x is loaded */
1770 if (!test_bit(CNIC_F_BNX2X_CLASS
, &dev
->flags
)) {
1771 printk(KERN_ERR PFX
"bnx2fc FCoE not supported on %s,"
1773 dev
->netdev
->name
, dev
->flags
);
1777 /* Configure FCoE interface */
1778 hba
= bnx2fc_interface_create(dev
);
1780 printk(KERN_ERR PFX
"hba initialization failed\n");
1784 /* Add HBA to the adapter list */
1785 mutex_lock(&bnx2fc_dev_lock
);
1786 list_add_tail(&hba
->link
, &adapter_list
);
1788 mutex_unlock(&bnx2fc_dev_lock
);
1790 clear_bit(BNX2FC_CNIC_REGISTERED
, &hba
->reg_with_cnic
);
1791 rc
= dev
->register_device(dev
, CNIC_ULP_FCOE
,
1794 printk(KERN_ALERT PFX
"register_device failed, rc = %d\n", rc
);
1796 set_bit(BNX2FC_CNIC_REGISTERED
, &hba
->reg_with_cnic
);
1800 static int bnx2fc_disable(struct net_device
*netdev
)
1802 struct bnx2fc_hba
*hba
;
1803 struct net_device
*phys_dev
;
1804 struct ethtool_drvinfo drvinfo
;
1809 mutex_lock(&bnx2fc_dev_lock
);
1811 if (THIS_MODULE
->state
!= MODULE_STATE_LIVE
) {
1816 /* obtain physical netdev */
1817 if (netdev
->priv_flags
& IFF_802_1Q_VLAN
)
1818 phys_dev
= vlan_dev_real_dev(netdev
);
1820 printk(KERN_ERR PFX
"Not a vlan device\n");
1825 /* verify if the physical device is a netxtreme2 device */
1826 if (phys_dev
->ethtool_ops
&& phys_dev
->ethtool_ops
->get_drvinfo
) {
1827 memset(&drvinfo
, 0, sizeof(drvinfo
));
1828 phys_dev
->ethtool_ops
->get_drvinfo(phys_dev
, &drvinfo
);
1829 if (strcmp(drvinfo
.driver
, "bnx2x")) {
1830 printk(KERN_ERR PFX
"Not a netxtreme2 device\n");
1835 printk(KERN_ERR PFX
"unable to obtain drv_info\n");
1840 printk(KERN_ERR PFX
"phys_dev is netxtreme2 device\n");
1842 /* obtain hba and initialize rest of the structure */
1843 hba
= bnx2fc_hba_lookup(phys_dev
);
1844 if (!hba
|| !hba
->ctlr
.lp
) {
1846 printk(KERN_ERR PFX
"bnx2fc_disable: hba or lport not found\n");
1848 fcoe_ctlr_link_down(&hba
->ctlr
);
1849 fcoe_clean_pending_queue(hba
->ctlr
.lp
);
1853 mutex_unlock(&bnx2fc_dev_lock
);
1859 static int bnx2fc_enable(struct net_device
*netdev
)
1861 struct bnx2fc_hba
*hba
;
1862 struct net_device
*phys_dev
;
1863 struct ethtool_drvinfo drvinfo
;
1868 BNX2FC_MISC_DBG("Entered %s\n", __func__
);
1869 mutex_lock(&bnx2fc_dev_lock
);
1871 if (THIS_MODULE
->state
!= MODULE_STATE_LIVE
) {
1876 /* obtain physical netdev */
1877 if (netdev
->priv_flags
& IFF_802_1Q_VLAN
)
1878 phys_dev
= vlan_dev_real_dev(netdev
);
1880 printk(KERN_ERR PFX
"Not a vlan device\n");
1884 /* verify if the physical device is a netxtreme2 device */
1885 if (phys_dev
->ethtool_ops
&& phys_dev
->ethtool_ops
->get_drvinfo
) {
1886 memset(&drvinfo
, 0, sizeof(drvinfo
));
1887 phys_dev
->ethtool_ops
->get_drvinfo(phys_dev
, &drvinfo
);
1888 if (strcmp(drvinfo
.driver
, "bnx2x")) {
1889 printk(KERN_ERR PFX
"Not a netxtreme2 device\n");
1894 printk(KERN_ERR PFX
"unable to obtain drv_info\n");
1899 /* obtain hba and initialize rest of the structure */
1900 hba
= bnx2fc_hba_lookup(phys_dev
);
1901 if (!hba
|| !hba
->ctlr
.lp
) {
1903 printk(KERN_ERR PFX
"bnx2fc_enable: hba or lport not found\n");
1904 } else if (!bnx2fc_link_ok(hba
->ctlr
.lp
))
1905 fcoe_ctlr_link_up(&hba
->ctlr
);
1908 mutex_unlock(&bnx2fc_dev_lock
);
1914 * bnx2fc_create - Create bnx2fc FCoE interface
1916 * @buffer: The name of Ethernet interface to create on
1917 * @kp: The associated kernel param
1919 * Called from sysfs.
1921 * Returns: 0 for success
1923 static int bnx2fc_create(struct net_device
*netdev
, enum fip_state fip_mode
)
1925 struct bnx2fc_hba
*hba
;
1926 struct net_device
*phys_dev
;
1927 struct fc_lport
*lport
;
1928 struct ethtool_drvinfo drvinfo
;
1932 BNX2FC_MISC_DBG("Entered bnx2fc_create\n");
1933 if (fip_mode
!= FIP_MODE_FABRIC
) {
1934 printk(KERN_ERR
"fip mode not FABRIC\n");
1940 mutex_lock(&bnx2fc_dev_lock
);
1942 #ifdef CONFIG_SCSI_BNX2X_FCOE_MODULE
1943 if (THIS_MODULE
->state
!= MODULE_STATE_LIVE
) {
1949 if (!try_module_get(THIS_MODULE
)) {
1954 /* obtain physical netdev */
1955 if (netdev
->priv_flags
& IFF_802_1Q_VLAN
) {
1956 phys_dev
= vlan_dev_real_dev(netdev
);
1957 vlan_id
= vlan_dev_vlan_id(netdev
);
1959 printk(KERN_ERR PFX
"Not a vlan device\n");
1963 /* verify if the physical device is a netxtreme2 device */
1964 if (phys_dev
->ethtool_ops
&& phys_dev
->ethtool_ops
->get_drvinfo
) {
1965 memset(&drvinfo
, 0, sizeof(drvinfo
));
1966 phys_dev
->ethtool_ops
->get_drvinfo(phys_dev
, &drvinfo
);
1967 if (strcmp(drvinfo
.driver
, "bnx2x")) {
1968 printk(KERN_ERR PFX
"Not a netxtreme2 device\n");
1973 printk(KERN_ERR PFX
"unable to obtain drv_info\n");
1978 /* obtain hba and initialize rest of the structure */
1979 hba
= bnx2fc_hba_lookup(phys_dev
);
1982 printk(KERN_ERR PFX
"bnx2fc_create: hba not found\n");
1986 if (!test_bit(BNX2FC_FW_INIT_DONE
, &hba
->init_done
)) {
1987 rc
= bnx2fc_fw_init(hba
);
1992 if (test_bit(BNX2FC_CREATE_DONE
, &hba
->init_done
)) {
1997 /* update netdev with vlan netdev */
1998 hba
->netdev
= netdev
;
1999 hba
->vlan_id
= vlan_id
;
2000 hba
->vlan_enabled
= 1;
2002 rc
= bnx2fc_interface_setup(hba
, fip_mode
);
2004 printk(KERN_ERR PFX
"bnx2fc_interface_setup failed\n");
2008 hba
->timer_work_queue
=
2009 create_singlethread_workqueue("bnx2fc_timer_wq");
2010 if (!hba
->timer_work_queue
) {
2011 printk(KERN_ERR PFX
"ulp_init could not create timer_wq\n");
2016 lport
= bnx2fc_if_create(hba
, &hba
->pcidev
->dev
, 0);
2018 printk(KERN_ERR PFX
"Failed to create interface (%s)\n",
2020 bnx2fc_netdev_cleanup(hba
);
2025 lport
->boot_time
= jiffies
;
2027 /* Make this master N_port */
2028 hba
->ctlr
.lp
= lport
;
2030 set_bit(BNX2FC_CREATE_DONE
, &hba
->init_done
);
2031 printk(KERN_ERR PFX
"create: START DISC\n");
2032 bnx2fc_start_disc(hba
);
2034 * Release from kref_init in bnx2fc_interface_setup, on success
2035 * lport should be holding a reference taken in bnx2fc_if_create
2037 bnx2fc_interface_put(hba
);
2038 /* put netdev that was held while calling dev_get_by_name */
2039 mutex_unlock(&bnx2fc_dev_lock
);
2044 destroy_workqueue(hba
->timer_work_queue
);
2046 bnx2fc_interface_put(hba
);
2048 module_put(THIS_MODULE
);
2050 mutex_unlock(&bnx2fc_dev_lock
);
2056 * bnx2fc_find_hba_for_cnic - maps cnic instance to bnx2fc adapter instance
2058 * @cnic: Pointer to cnic device instance
2061 static struct bnx2fc_hba
*bnx2fc_find_hba_for_cnic(struct cnic_dev
*cnic
)
2063 struct list_head
*list
;
2064 struct list_head
*temp
;
2065 struct bnx2fc_hba
*hba
;
2067 /* Called with bnx2fc_dev_lock held */
2068 list_for_each_safe(list
, temp
, &adapter_list
) {
2069 hba
= (struct bnx2fc_hba
*)list
;
2070 if (hba
->cnic
== cnic
)
2076 static struct bnx2fc_hba
*bnx2fc_hba_lookup(struct net_device
*phys_dev
)
2078 struct list_head
*list
;
2079 struct list_head
*temp
;
2080 struct bnx2fc_hba
*hba
;
2082 /* Called with bnx2fc_dev_lock held */
2083 list_for_each_safe(list
, temp
, &adapter_list
) {
2084 hba
= (struct bnx2fc_hba
*)list
;
2085 if (hba
->phys_dev
== phys_dev
)
2088 printk(KERN_ERR PFX
"hba_lookup: hba NULL\n");
2093 * bnx2fc_ulp_exit - shuts down adapter instance and frees all resources
2095 * @dev cnic device handle
2097 static void bnx2fc_ulp_exit(struct cnic_dev
*dev
)
2099 struct bnx2fc_hba
*hba
;
2101 BNX2FC_MISC_DBG("Entered bnx2fc_ulp_exit\n");
2103 if (!test_bit(CNIC_F_BNX2X_CLASS
, &dev
->flags
)) {
2104 printk(KERN_ERR PFX
"bnx2fc port check: %s, flags: %lx\n",
2105 dev
->netdev
->name
, dev
->flags
);
2109 mutex_lock(&bnx2fc_dev_lock
);
2110 hba
= bnx2fc_find_hba_for_cnic(dev
);
2112 printk(KERN_ERR PFX
"bnx2fc_ulp_exit: hba not found, dev 0%p\n",
2114 mutex_unlock(&bnx2fc_dev_lock
);
2118 list_del_init(&hba
->link
);
2121 if (test_bit(BNX2FC_CREATE_DONE
, &hba
->init_done
)) {
2122 /* destroy not called yet, move to quiesced list */
2123 bnx2fc_netdev_cleanup(hba
);
2124 bnx2fc_if_destroy(hba
->ctlr
.lp
);
2126 mutex_unlock(&bnx2fc_dev_lock
);
2128 bnx2fc_ulp_stop(hba
);
2129 /* unregister cnic device */
2130 if (test_and_clear_bit(BNX2FC_CNIC_REGISTERED
, &hba
->reg_with_cnic
))
2131 hba
->cnic
->unregister_device(hba
->cnic
, CNIC_ULP_FCOE
);
2132 bnx2fc_interface_destroy(hba
);
2136 * bnx2fc_fcoe_reset - Resets the fcoe
2138 * @shost: shost the reset is from
2142 static int bnx2fc_fcoe_reset(struct Scsi_Host
*shost
)
2144 struct fc_lport
*lport
= shost_priv(shost
);
2145 fc_lport_reset(lport
);
2150 static bool bnx2fc_match(struct net_device
*netdev
)
2152 mutex_lock(&bnx2fc_dev_lock
);
2153 if (netdev
->priv_flags
& IFF_802_1Q_VLAN
) {
2154 struct net_device
*phys_dev
= vlan_dev_real_dev(netdev
);
2156 if (bnx2fc_hba_lookup(phys_dev
)) {
2157 mutex_unlock(&bnx2fc_dev_lock
);
2161 mutex_unlock(&bnx2fc_dev_lock
);
2166 static struct fcoe_transport bnx2fc_transport
= {
2169 .list
= LIST_HEAD_INIT(bnx2fc_transport
.list
),
2170 .match
= bnx2fc_match
,
2171 .create
= bnx2fc_create
,
2172 .destroy
= bnx2fc_destroy
,
2173 .enable
= bnx2fc_enable
,
2174 .disable
= bnx2fc_disable
,
2178 * bnx2fc_percpu_thread_create - Create a receive thread for an
2181 * @cpu: cpu index for the online cpu
2183 static void bnx2fc_percpu_thread_create(unsigned int cpu
)
2185 struct bnx2fc_percpu_s
*p
;
2186 struct task_struct
*thread
;
2188 p
= &per_cpu(bnx2fc_percpu
, cpu
);
2190 thread
= kthread_create(bnx2fc_percpu_io_thread
,
2192 "bnx2fc_thread/%d", cpu
);
2193 /* bind thread to the cpu */
2194 if (likely(!IS_ERR(p
->iothread
))) {
2195 kthread_bind(thread
, cpu
);
2196 p
->iothread
= thread
;
2197 wake_up_process(thread
);
2201 static void bnx2fc_percpu_thread_destroy(unsigned int cpu
)
2203 struct bnx2fc_percpu_s
*p
;
2204 struct task_struct
*thread
;
2205 struct bnx2fc_work
*work
, *tmp
;
2206 LIST_HEAD(work_list
);
2208 BNX2FC_MISC_DBG("destroying io thread for CPU %d\n", cpu
);
2210 /* Prevent any new work from being queued for this CPU */
2211 p
= &per_cpu(bnx2fc_percpu
, cpu
);
2212 spin_lock_bh(&p
->fp_work_lock
);
2213 thread
= p
->iothread
;
2217 /* Free all work in the list */
2218 list_for_each_entry_safe(work
, tmp
, &work_list
, list
) {
2219 list_del_init(&work
->list
);
2220 bnx2fc_process_cq_compl(work
->tgt
, work
->wqe
);
2224 spin_unlock_bh(&p
->fp_work_lock
);
2227 kthread_stop(thread
);
2231 * bnx2fc_cpu_callback - Handler for CPU hotplug events
2233 * @nfb: The callback data block
2234 * @action: The event triggering the callback
2235 * @hcpu: The index of the CPU that the event is for
2237 * This creates or destroys per-CPU data for fcoe
2239 * Returns NOTIFY_OK always.
2241 static int bnx2fc_cpu_callback(struct notifier_block
*nfb
,
2242 unsigned long action
, void *hcpu
)
2244 unsigned cpu
= (unsigned long)hcpu
;
2248 case CPU_ONLINE_FROZEN
:
2249 printk(PFX
"CPU %x online: Create Rx thread\n", cpu
);
2250 bnx2fc_percpu_thread_create(cpu
);
2253 case CPU_DEAD_FROZEN
:
2254 printk(PFX
"CPU %x offline: Remove Rx thread\n", cpu
);
2255 bnx2fc_percpu_thread_destroy(cpu
);
2264 * bnx2fc_mod_init - module init entry point
2266 * Initialize driver wide global data structures, and register
2269 static int __init
bnx2fc_mod_init(void)
2271 struct fcoe_percpu_s
*bg
;
2272 struct task_struct
*l2_thread
;
2274 unsigned int cpu
= 0;
2275 struct bnx2fc_percpu_s
*p
;
2277 printk(KERN_INFO PFX
"%s", version
);
2279 /* register as a fcoe transport */
2280 rc
= fcoe_transport_attach(&bnx2fc_transport
);
2282 printk(KERN_ERR
"failed to register an fcoe transport, check "
2283 "if libfcoe is loaded\n");
2287 INIT_LIST_HEAD(&adapter_list
);
2288 mutex_init(&bnx2fc_dev_lock
);
2291 /* Attach FC transport template */
2292 rc
= bnx2fc_attach_transport();
2296 bnx2fc_wq
= alloc_workqueue("bnx2fc", 0, 0);
2302 bg
= &bnx2fc_global
;
2303 skb_queue_head_init(&bg
->fcoe_rx_list
);
2304 l2_thread
= kthread_create(bnx2fc_l2_rcv_thread
,
2306 "bnx2fc_l2_thread");
2307 if (IS_ERR(l2_thread
)) {
2308 rc
= PTR_ERR(l2_thread
);
2311 wake_up_process(l2_thread
);
2312 spin_lock_bh(&bg
->fcoe_rx_list
.lock
);
2313 bg
->thread
= l2_thread
;
2314 spin_unlock_bh(&bg
->fcoe_rx_list
.lock
);
2316 for_each_possible_cpu(cpu
) {
2317 p
= &per_cpu(bnx2fc_percpu
, cpu
);
2318 INIT_LIST_HEAD(&p
->work_list
);
2319 spin_lock_init(&p
->fp_work_lock
);
2322 for_each_online_cpu(cpu
) {
2323 bnx2fc_percpu_thread_create(cpu
);
2326 /* Initialize per CPU interrupt thread */
2327 register_hotcpu_notifier(&bnx2fc_cpu_notifier
);
2329 cnic_register_driver(CNIC_ULP_FCOE
, &bnx2fc_cnic_cb
);
2334 destroy_workqueue(bnx2fc_wq
);
2336 bnx2fc_release_transport();
2338 fcoe_transport_detach(&bnx2fc_transport
);
2343 static void __exit
bnx2fc_mod_exit(void)
2345 LIST_HEAD(to_be_deleted
);
2346 struct bnx2fc_hba
*hba
, *next
;
2347 struct fcoe_percpu_s
*bg
;
2348 struct task_struct
*l2_thread
;
2349 struct sk_buff
*skb
;
2350 unsigned int cpu
= 0;
2353 * NOTE: Since cnic calls register_driver routine rtnl_lock,
2354 * it will have higher precedence than bnx2fc_dev_lock.
2355 * unregister_device() cannot be called with bnx2fc_dev_lock
2358 mutex_lock(&bnx2fc_dev_lock
);
2359 list_splice(&adapter_list
, &to_be_deleted
);
2360 INIT_LIST_HEAD(&adapter_list
);
2362 mutex_unlock(&bnx2fc_dev_lock
);
2364 /* Unregister with cnic */
2365 list_for_each_entry_safe(hba
, next
, &to_be_deleted
, link
) {
2366 list_del_init(&hba
->link
);
2367 printk(KERN_ERR PFX
"MOD_EXIT:destroy hba = 0x%p, kref = %d\n",
2368 hba
, atomic_read(&hba
->kref
.refcount
));
2369 bnx2fc_ulp_stop(hba
);
2370 /* unregister cnic device */
2371 if (test_and_clear_bit(BNX2FC_CNIC_REGISTERED
,
2372 &hba
->reg_with_cnic
))
2373 hba
->cnic
->unregister_device(hba
->cnic
, CNIC_ULP_FCOE
);
2374 bnx2fc_interface_destroy(hba
);
2376 cnic_unregister_driver(CNIC_ULP_FCOE
);
2378 /* Destroy global thread */
2379 bg
= &bnx2fc_global
;
2380 spin_lock_bh(&bg
->fcoe_rx_list
.lock
);
2381 l2_thread
= bg
->thread
;
2383 while ((skb
= __skb_dequeue(&bg
->fcoe_rx_list
)) != NULL
)
2386 spin_unlock_bh(&bg
->fcoe_rx_list
.lock
);
2389 kthread_stop(l2_thread
);
2391 unregister_hotcpu_notifier(&bnx2fc_cpu_notifier
);
2393 /* Destroy per cpu threads */
2394 for_each_online_cpu(cpu
) {
2395 bnx2fc_percpu_thread_destroy(cpu
);
2398 destroy_workqueue(bnx2fc_wq
);
2400 * detach from scsi transport
2401 * must happen after all destroys are done
2403 bnx2fc_release_transport();
2405 /* detach from fcoe transport */
2406 fcoe_transport_detach(&bnx2fc_transport
);
2409 module_init(bnx2fc_mod_init
);
2410 module_exit(bnx2fc_mod_exit
);
2412 static struct fc_function_template bnx2fc_transport_function
= {
2413 .show_host_node_name
= 1,
2414 .show_host_port_name
= 1,
2415 .show_host_supported_classes
= 1,
2416 .show_host_supported_fc4s
= 1,
2417 .show_host_active_fc4s
= 1,
2418 .show_host_maxframe_size
= 1,
2420 .show_host_port_id
= 1,
2421 .show_host_supported_speeds
= 1,
2422 .get_host_speed
= fc_get_host_speed
,
2423 .show_host_speed
= 1,
2424 .show_host_port_type
= 1,
2425 .get_host_port_state
= fc_get_host_port_state
,
2426 .show_host_port_state
= 1,
2427 .show_host_symbolic_name
= 1,
2429 .dd_fcrport_size
= (sizeof(struct fc_rport_libfc_priv
) +
2430 sizeof(struct bnx2fc_rport
)),
2431 .show_rport_maxframe_size
= 1,
2432 .show_rport_supported_classes
= 1,
2434 .show_host_fabric_name
= 1,
2435 .show_starget_node_name
= 1,
2436 .show_starget_port_name
= 1,
2437 .show_starget_port_id
= 1,
2438 .set_rport_dev_loss_tmo
= fc_set_rport_loss_tmo
,
2439 .show_rport_dev_loss_tmo
= 1,
2440 .get_fc_host_stats
= bnx2fc_get_host_stats
,
2442 .issue_fc_host_lip
= bnx2fc_fcoe_reset
,
2444 .terminate_rport_io
= fc_rport_terminate_io
,
2446 .vport_create
= bnx2fc_vport_create
,
2447 .vport_delete
= bnx2fc_vport_destroy
,
2448 .vport_disable
= bnx2fc_vport_disable
,
2451 static struct fc_function_template bnx2fc_vport_xport_function
= {
2452 .show_host_node_name
= 1,
2453 .show_host_port_name
= 1,
2454 .show_host_supported_classes
= 1,
2455 .show_host_supported_fc4s
= 1,
2456 .show_host_active_fc4s
= 1,
2457 .show_host_maxframe_size
= 1,
2459 .show_host_port_id
= 1,
2460 .show_host_supported_speeds
= 1,
2461 .get_host_speed
= fc_get_host_speed
,
2462 .show_host_speed
= 1,
2463 .show_host_port_type
= 1,
2464 .get_host_port_state
= fc_get_host_port_state
,
2465 .show_host_port_state
= 1,
2466 .show_host_symbolic_name
= 1,
2468 .dd_fcrport_size
= (sizeof(struct fc_rport_libfc_priv
) +
2469 sizeof(struct bnx2fc_rport
)),
2470 .show_rport_maxframe_size
= 1,
2471 .show_rport_supported_classes
= 1,
2473 .show_host_fabric_name
= 1,
2474 .show_starget_node_name
= 1,
2475 .show_starget_port_name
= 1,
2476 .show_starget_port_id
= 1,
2477 .set_rport_dev_loss_tmo
= fc_set_rport_loss_tmo
,
2478 .show_rport_dev_loss_tmo
= 1,
2479 .get_fc_host_stats
= fc_get_host_stats
,
2480 .issue_fc_host_lip
= bnx2fc_fcoe_reset
,
2481 .terminate_rport_io
= fc_rport_terminate_io
,
2485 * scsi_host_template structure used while registering with SCSI-ml
2487 static struct scsi_host_template bnx2fc_shost_template
= {
2488 .module
= THIS_MODULE
,
2489 .name
= "Broadcom Offload FCoE Initiator",
2490 .queuecommand
= bnx2fc_queuecommand
,
2491 .eh_abort_handler
= bnx2fc_eh_abort
, /* abts */
2492 .eh_device_reset_handler
= bnx2fc_eh_device_reset
, /* lun reset */
2493 .eh_target_reset_handler
= bnx2fc_eh_target_reset
, /* tgt reset */
2494 .eh_host_reset_handler
= fc_eh_host_reset
,
2495 .slave_alloc
= fc_slave_alloc
,
2496 .change_queue_depth
= fc_change_queue_depth
,
2497 .change_queue_type
= fc_change_queue_type
,
2500 .can_queue
= (BNX2FC_MAX_OUTSTANDING_CMNDS
/2),
2501 .use_clustering
= ENABLE_CLUSTERING
,
2502 .sg_tablesize
= BNX2FC_MAX_BDS_PER_CMD
,
2506 static struct libfc_function_template bnx2fc_libfc_fcn_templ
= {
2507 .frame_send
= bnx2fc_xmit
,
2508 .elsct_send
= bnx2fc_elsct_send
,
2509 .fcp_abort_io
= bnx2fc_abort_io
,
2510 .fcp_cleanup
= bnx2fc_cleanup
,
2511 .rport_event_callback
= bnx2fc_rport_event_handler
,
2515 * bnx2fc_cnic_cb - global template of bnx2fc - cnic driver interface
2516 * structure carrying callback function pointers
2518 static struct cnic_ulp_ops bnx2fc_cnic_cb
= {
2519 .owner
= THIS_MODULE
,
2520 .cnic_init
= bnx2fc_ulp_init
,
2521 .cnic_exit
= bnx2fc_ulp_exit
,
2522 .cnic_start
= bnx2fc_ulp_start
,
2523 .cnic_stop
= bnx2fc_ulp_stop
,
2524 .indicate_kcqes
= bnx2fc_indicate_kcqe
,
2525 .indicate_netevent
= bnx2fc_indicate_netevent
,