1 /* bnx2fc_fcoe.c: QLogic 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-2013 Broadcom Corporation
7 * Copyright (c) 2014-2015 QLogic Corporation
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation.
13 * Written by: Bhanu Prakash Gollapudi (bprakash@broadcom.com)
18 static struct list_head adapter_list
;
19 static struct list_head if_list
;
20 static u32 adapter_count
;
21 static DEFINE_MUTEX(bnx2fc_dev_lock
);
22 DEFINE_PER_CPU(struct bnx2fc_percpu_s
, bnx2fc_percpu
);
24 #define DRV_MODULE_NAME "bnx2fc"
25 #define DRV_MODULE_VERSION BNX2FC_VERSION
26 #define DRV_MODULE_RELDATE "October 15, 2015"
29 static char version
[] =
30 "QLogic FCoE Driver " DRV_MODULE_NAME \
31 " v" DRV_MODULE_VERSION
" (" DRV_MODULE_RELDATE
")\n";
34 MODULE_AUTHOR("Bhanu Prakash Gollapudi <bprakash@broadcom.com>");
35 MODULE_DESCRIPTION("QLogic FCoE Driver");
36 MODULE_LICENSE("GPL");
37 MODULE_VERSION(DRV_MODULE_VERSION
);
39 #define BNX2FC_MAX_QUEUE_DEPTH 256
40 #define BNX2FC_MIN_QUEUE_DEPTH 32
41 #define FCOE_WORD_TO_BYTE 4
43 static struct scsi_transport_template
*bnx2fc_transport_template
;
44 static struct scsi_transport_template
*bnx2fc_vport_xport_template
;
46 struct workqueue_struct
*bnx2fc_wq
;
48 /* bnx2fc structure needs only one instance of the fcoe_percpu_s structure.
49 * Here the io threads are per cpu but the l2 thread is just one
51 struct fcoe_percpu_s bnx2fc_global
;
52 DEFINE_SPINLOCK(bnx2fc_global_lock
);
54 static struct cnic_ulp_ops bnx2fc_cnic_cb
;
55 static struct libfc_function_template bnx2fc_libfc_fcn_templ
;
56 static struct scsi_host_template bnx2fc_shost_template
;
57 static struct fc_function_template bnx2fc_transport_function
;
58 static struct fcoe_sysfs_function_template bnx2fc_fcoe_sysfs_templ
;
59 static struct fc_function_template bnx2fc_vport_xport_function
;
60 static int bnx2fc_create(struct net_device
*netdev
, enum fip_mode fip_mode
);
61 static void __bnx2fc_destroy(struct bnx2fc_interface
*interface
);
62 static int bnx2fc_destroy(struct net_device
*net_device
);
63 static int bnx2fc_enable(struct net_device
*netdev
);
64 static int bnx2fc_disable(struct net_device
*netdev
);
66 /* fcoe_syfs control interface handlers */
67 static int bnx2fc_ctlr_alloc(struct net_device
*netdev
);
68 static int bnx2fc_ctlr_enabled(struct fcoe_ctlr_device
*cdev
);
70 static void bnx2fc_recv_frame(struct sk_buff
*skb
);
72 static void bnx2fc_start_disc(struct bnx2fc_interface
*interface
);
73 static int bnx2fc_shost_config(struct fc_lport
*lport
, struct device
*dev
);
74 static int bnx2fc_lport_config(struct fc_lport
*lport
);
75 static int bnx2fc_em_config(struct fc_lport
*lport
, struct bnx2fc_hba
*hba
);
76 static int bnx2fc_bind_adapter_devices(struct bnx2fc_hba
*hba
);
77 static void bnx2fc_unbind_adapter_devices(struct bnx2fc_hba
*hba
);
78 static int bnx2fc_bind_pcidev(struct bnx2fc_hba
*hba
);
79 static void bnx2fc_unbind_pcidev(struct bnx2fc_hba
*hba
);
80 static struct fc_lport
*bnx2fc_if_create(struct bnx2fc_interface
*interface
,
81 struct device
*parent
, int npiv
);
82 static void bnx2fc_destroy_work(struct work_struct
*work
);
84 static struct bnx2fc_hba
*bnx2fc_hba_lookup(struct net_device
*phys_dev
);
85 static struct bnx2fc_interface
*bnx2fc_interface_lookup(struct net_device
87 static inline void bnx2fc_interface_put(struct bnx2fc_interface
*interface
);
88 static struct bnx2fc_hba
*bnx2fc_find_hba_for_cnic(struct cnic_dev
*cnic
);
90 static int bnx2fc_fw_init(struct bnx2fc_hba
*hba
);
91 static void bnx2fc_fw_destroy(struct bnx2fc_hba
*hba
);
93 static void bnx2fc_port_shutdown(struct fc_lport
*lport
);
94 static void bnx2fc_stop(struct bnx2fc_interface
*interface
);
95 static int __init
bnx2fc_mod_init(void);
96 static void __exit
bnx2fc_mod_exit(void);
98 unsigned int bnx2fc_debug_level
;
99 module_param_named(debug_logging
, bnx2fc_debug_level
, int, S_IRUGO
|S_IWUSR
);
100 MODULE_PARM_DESC(debug_logging
,
101 "Option to enable extended logging,\n"
102 "\t\tDefault is 0 - no logging.\n"
103 "\t\t0x01 - SCSI cmd error, cleanup.\n"
104 "\t\t0x02 - Session setup, cleanup, etc.\n"
105 "\t\t0x04 - lport events, link, mtu, etc.\n"
106 "\t\t0x08 - ELS logs.\n"
107 "\t\t0x10 - fcoe L2 fame related logs.\n"
108 "\t\t0xff - LOG all messages.");
110 uint bnx2fc_devloss_tmo
;
111 module_param_named(devloss_tmo
, bnx2fc_devloss_tmo
, uint
, S_IRUGO
);
112 MODULE_PARM_DESC(devloss_tmo
, " Change devloss_tmo for the remote ports "
113 "attached via bnx2fc.");
115 uint bnx2fc_max_luns
= BNX2FC_MAX_LUN
;
116 module_param_named(max_luns
, bnx2fc_max_luns
, uint
, S_IRUGO
);
117 MODULE_PARM_DESC(max_luns
, " Change the default max_lun per SCSI host. Default "
120 uint bnx2fc_queue_depth
;
121 module_param_named(queue_depth
, bnx2fc_queue_depth
, uint
, S_IRUGO
);
122 MODULE_PARM_DESC(queue_depth
, " Change the default queue depth of SCSI devices "
123 "attached via bnx2fc.");
126 module_param_named(log_fka
, bnx2fc_log_fka
, uint
, S_IRUGO
|S_IWUSR
);
127 MODULE_PARM_DESC(log_fka
, " Print message to kernel log when fcoe is "
128 "initiating a FIP keep alive when debug logging is enabled.");
130 static inline struct net_device
*bnx2fc_netdev(const struct fc_lport
*lport
)
132 return ((struct bnx2fc_interface
*)
133 ((struct fcoe_port
*)lport_priv(lport
))->priv
)->netdev
;
136 static void bnx2fc_fcf_get_vlan_id(struct fcoe_fcf_device
*fcf_dev
)
138 struct fcoe_ctlr_device
*ctlr_dev
=
139 fcoe_fcf_dev_to_ctlr_dev(fcf_dev
);
140 struct fcoe_ctlr
*ctlr
= fcoe_ctlr_device_priv(ctlr_dev
);
141 struct bnx2fc_interface
*fcoe
= fcoe_ctlr_priv(ctlr
);
143 fcf_dev
->vlan_id
= fcoe
->vlan_id
;
146 static void bnx2fc_clean_rx_queue(struct fc_lport
*lp
)
148 struct fcoe_percpu_s
*bg
;
149 struct fcoe_rcv_info
*fr
;
150 struct sk_buff_head
*list
;
151 struct sk_buff
*skb
, *next
;
152 struct sk_buff
*head
;
155 spin_lock_bh(&bg
->fcoe_rx_list
.lock
);
156 list
= &bg
->fcoe_rx_list
;
158 for (skb
= head
; skb
!= (struct sk_buff
*)list
;
161 fr
= fcoe_dev_from_skb(skb
);
162 if (fr
->fr_dev
== lp
) {
163 __skb_unlink(skb
, list
);
167 spin_unlock_bh(&bg
->fcoe_rx_list
.lock
);
170 int bnx2fc_get_paged_crc_eof(struct sk_buff
*skb
, int tlen
)
173 spin_lock(&bnx2fc_global_lock
);
174 rc
= fcoe_get_paged_crc_eof(skb
, tlen
, &bnx2fc_global
);
175 spin_unlock(&bnx2fc_global_lock
);
180 static void bnx2fc_abort_io(struct fc_lport
*lport
)
183 * This function is no-op for bnx2fc, but we do
184 * not want to leave it as NULL either, as libfc
185 * can call the default function which is
190 static void bnx2fc_cleanup(struct fc_lport
*lport
)
192 struct fcoe_port
*port
= lport_priv(lport
);
193 struct bnx2fc_interface
*interface
= port
->priv
;
194 struct bnx2fc_hba
*hba
= interface
->hba
;
195 struct bnx2fc_rport
*tgt
;
198 BNX2FC_MISC_DBG("Entered %s\n", __func__
);
199 mutex_lock(&hba
->hba_mutex
);
200 spin_lock_bh(&hba
->hba_lock
);
201 for (i
= 0; i
< BNX2FC_NUM_MAX_SESS
; i
++) {
202 tgt
= hba
->tgt_ofld_list
[i
];
204 /* Cleanup IOs belonging to requested vport */
205 if (tgt
->port
== port
) {
206 spin_unlock_bh(&hba
->hba_lock
);
207 BNX2FC_TGT_DBG(tgt
, "flush/cleanup\n");
208 bnx2fc_flush_active_ios(tgt
);
209 spin_lock_bh(&hba
->hba_lock
);
213 spin_unlock_bh(&hba
->hba_lock
);
214 mutex_unlock(&hba
->hba_mutex
);
217 static int bnx2fc_xmit_l2_frame(struct bnx2fc_rport
*tgt
,
220 struct fc_rport_priv
*rdata
= tgt
->rdata
;
221 struct fc_frame_header
*fh
;
224 fh
= fc_frame_header_get(fp
);
225 BNX2FC_TGT_DBG(tgt
, "Xmit L2 frame rport = 0x%x, oxid = 0x%x, "
226 "r_ctl = 0x%x\n", rdata
->ids
.port_id
,
227 ntohs(fh
->fh_ox_id
), fh
->fh_r_ctl
);
228 if ((fh
->fh_type
== FC_TYPE_ELS
) &&
229 (fh
->fh_r_ctl
== FC_RCTL_ELS_REQ
)) {
231 switch (fc_frame_payload_op(fp
)) {
233 rc
= bnx2fc_send_adisc(tgt
, fp
);
236 rc
= bnx2fc_send_logo(tgt
, fp
);
239 rc
= bnx2fc_send_rls(tgt
, fp
);
244 } else if ((fh
->fh_type
== FC_TYPE_BLS
) &&
245 (fh
->fh_r_ctl
== FC_RCTL_BA_ABTS
))
246 BNX2FC_TGT_DBG(tgt
, "ABTS frame\n");
248 BNX2FC_TGT_DBG(tgt
, "Send L2 frame type 0x%x "
249 "rctl 0x%x thru non-offload path\n",
250 fh
->fh_type
, fh
->fh_r_ctl
);
260 * bnx2fc_xmit - bnx2fc's FCoE frame transmit function
262 * @lport: the associated local port
263 * @fp: the fc_frame to be transmitted
265 static int bnx2fc_xmit(struct fc_lport
*lport
, struct fc_frame
*fp
)
268 struct fcoe_crc_eof
*cp
;
270 struct fc_frame_header
*fh
;
271 struct bnx2fc_interface
*interface
;
272 struct fcoe_ctlr
*ctlr
;
273 struct bnx2fc_hba
*hba
;
274 struct fcoe_port
*port
;
276 struct bnx2fc_rport
*tgt
;
277 struct fc_stats
*stats
;
280 unsigned int hlen
, tlen
, elen
;
283 port
= (struct fcoe_port
*)lport_priv(lport
);
284 interface
= port
->priv
;
285 ctlr
= bnx2fc_to_ctlr(interface
);
286 hba
= interface
->hba
;
288 fh
= fc_frame_header_get(fp
);
291 if (!lport
->link_up
) {
292 BNX2FC_HBA_DBG(lport
, "bnx2fc_xmit link down\n");
297 if (unlikely(fh
->fh_r_ctl
== FC_RCTL_ELS_REQ
)) {
298 if (!ctlr
->sel_fcf
) {
299 BNX2FC_HBA_DBG(lport
, "FCF not selected yet!\n");
303 if (fcoe_ctlr_els_send(ctlr
, lport
, skb
))
311 * Snoop the frame header to check if the frame is for
312 * an offloaded session
315 * tgt_ofld_list access is synchronized using
316 * both hba mutex and hba lock. Atleast hba mutex or
317 * hba lock needs to be held for read access.
320 spin_lock_bh(&hba
->hba_lock
);
321 tgt
= bnx2fc_tgt_lookup(port
, ntoh24(fh
->fh_d_id
));
322 if (tgt
&& (test_bit(BNX2FC_FLAG_SESSION_READY
, &tgt
->flags
))) {
323 /* This frame is for offloaded session */
324 BNX2FC_HBA_DBG(lport
, "xmit: Frame is for offloaded session "
325 "port_id = 0x%x\n", ntoh24(fh
->fh_d_id
));
326 spin_unlock_bh(&hba
->hba_lock
);
327 rc
= bnx2fc_xmit_l2_frame(tgt
, fp
);
333 spin_unlock_bh(&hba
->hba_lock
);
336 elen
= sizeof(struct ethhdr
);
337 hlen
= sizeof(struct fcoe_hdr
);
338 tlen
= sizeof(struct fcoe_crc_eof
);
339 wlen
= (skb
->len
- tlen
+ sizeof(crc
)) / FCOE_WORD_TO_BYTE
;
341 skb
->ip_summed
= CHECKSUM_NONE
;
342 crc
= fcoe_fc_crc(fp
);
344 /* copy port crc and eof to the skb buff */
345 if (skb_is_nonlinear(skb
)) {
347 if (bnx2fc_get_paged_crc_eof(skb
, tlen
)) {
351 frag
= &skb_shinfo(skb
)->frags
[skb_shinfo(skb
)->nr_frags
- 1];
352 cp
= kmap_atomic(skb_frag_page(frag
)) + frag
->page_offset
;
354 cp
= (struct fcoe_crc_eof
*)skb_put(skb
, tlen
);
357 memset(cp
, 0, sizeof(*cp
));
359 cp
->fcoe_crc32
= cpu_to_le32(~crc
);
360 if (skb_is_nonlinear(skb
)) {
365 /* adjust skb network/transport offsets to match mac/fcoe/port */
366 skb_push(skb
, elen
+ hlen
);
367 skb_reset_mac_header(skb
);
368 skb_reset_network_header(skb
);
370 skb
->protocol
= htons(ETH_P_FCOE
);
371 skb
->dev
= interface
->netdev
;
373 /* fill up mac and fcoe headers */
375 eh
->h_proto
= htons(ETH_P_FCOE
);
377 fc_fcoe_set_mac(eh
->h_dest
, fh
->fh_d_id
);
379 /* insert GW address */
380 memcpy(eh
->h_dest
, ctlr
->dest_addr
, ETH_ALEN
);
382 if (unlikely(ctlr
->flogi_oxid
!= FC_XID_UNKNOWN
))
383 memcpy(eh
->h_source
, ctlr
->ctl_src_addr
, ETH_ALEN
);
385 memcpy(eh
->h_source
, port
->data_src_addr
, ETH_ALEN
);
387 hp
= (struct fcoe_hdr
*)(eh
+ 1);
388 memset(hp
, 0, sizeof(*hp
));
390 FC_FCOE_ENCAPS_VER(hp
, FC_FCOE_VER
);
393 /* fcoe lso, mss is in max_payload which is non-zero for FCP data */
394 if (lport
->seq_offload
&& fr_max_payload(fp
)) {
395 skb_shinfo(skb
)->gso_type
= SKB_GSO_FCOE
;
396 skb_shinfo(skb
)->gso_size
= fr_max_payload(fp
);
398 skb_shinfo(skb
)->gso_type
= 0;
399 skb_shinfo(skb
)->gso_size
= 0;
403 stats
= per_cpu_ptr(lport
->stats
, get_cpu());
405 stats
->TxWords
+= wlen
;
408 /* send down to lld */
410 if (port
->fcoe_pending_queue
.qlen
)
411 fcoe_check_wait_queue(lport
, skb
);
412 else if (fcoe_start_io(skb
))
413 fcoe_check_wait_queue(lport
, skb
);
419 * bnx2fc_rcv - This is bnx2fc's receive function called by NET_RX_SOFTIRQ
421 * @skb: the receive socket buffer
422 * @dev: associated net device
424 * @olddev: last device
426 * This function receives the packet and builds FC frame and passes it up
428 static int bnx2fc_rcv(struct sk_buff
*skb
, struct net_device
*dev
,
429 struct packet_type
*ptype
, struct net_device
*olddev
)
431 struct fc_lport
*lport
;
432 struct bnx2fc_interface
*interface
;
433 struct fcoe_ctlr
*ctlr
;
434 struct fc_frame_header
*fh
;
435 struct fcoe_rcv_info
*fr
;
436 struct fcoe_percpu_s
*bg
;
437 struct sk_buff
*tmp_skb
;
440 interface
= container_of(ptype
, struct bnx2fc_interface
,
442 ctlr
= bnx2fc_to_ctlr(interface
);
445 if (unlikely(lport
== NULL
)) {
446 printk(KERN_ERR PFX
"bnx2fc_rcv: lport is NULL\n");
450 tmp_skb
= skb_share_check(skb
, GFP_ATOMIC
);
456 if (unlikely(eth_hdr(skb
)->h_proto
!= htons(ETH_P_FCOE
))) {
457 printk(KERN_ERR PFX
"bnx2fc_rcv: Wrong FC type frame\n");
462 * Check for minimum frame length, and make sure required FCoE
463 * and FC headers are pulled into the linear data area.
465 if (unlikely((skb
->len
< FCOE_MIN_FRAME
) ||
466 !pskb_may_pull(skb
, FCOE_HEADER_LEN
)))
469 skb_set_transport_header(skb
, sizeof(struct fcoe_hdr
));
470 fh
= (struct fc_frame_header
*) skb_transport_header(skb
);
472 oxid
= ntohs(fh
->fh_ox_id
);
474 fr
= fcoe_dev_from_skb(skb
);
478 spin_lock(&bg
->fcoe_rx_list
.lock
);
480 __skb_queue_tail(&bg
->fcoe_rx_list
, skb
);
481 if (bg
->fcoe_rx_list
.qlen
== 1)
482 wake_up_process(bg
->kthread
);
484 spin_unlock(&bg
->fcoe_rx_list
.lock
);
492 static int bnx2fc_l2_rcv_thread(void *arg
)
494 struct fcoe_percpu_s
*bg
= arg
;
497 set_user_nice(current
, MIN_NICE
);
498 set_current_state(TASK_INTERRUPTIBLE
);
499 while (!kthread_should_stop()) {
501 spin_lock_bh(&bg
->fcoe_rx_list
.lock
);
502 while ((skb
= __skb_dequeue(&bg
->fcoe_rx_list
)) != NULL
) {
503 spin_unlock_bh(&bg
->fcoe_rx_list
.lock
);
504 bnx2fc_recv_frame(skb
);
505 spin_lock_bh(&bg
->fcoe_rx_list
.lock
);
507 __set_current_state(TASK_INTERRUPTIBLE
);
508 spin_unlock_bh(&bg
->fcoe_rx_list
.lock
);
510 __set_current_state(TASK_RUNNING
);
515 static void bnx2fc_recv_frame(struct sk_buff
*skb
)
518 struct fc_lport
*lport
;
519 struct fcoe_rcv_info
*fr
;
520 struct fc_stats
*stats
;
521 struct fc_frame_header
*fh
;
522 struct fcoe_crc_eof crc_eof
;
524 struct fc_lport
*vn_port
;
525 struct fcoe_port
*port
;
530 fr
= fcoe_dev_from_skb(skb
);
532 if (unlikely(lport
== NULL
)) {
533 printk(KERN_ERR PFX
"Invalid lport struct\n");
538 if (skb_is_nonlinear(skb
))
540 mac
= eth_hdr(skb
)->h_source
;
541 dest_mac
= eth_hdr(skb
)->h_dest
;
543 /* Pull the header */
544 hp
= (struct fcoe_hdr
*) skb_network_header(skb
);
545 fh
= (struct fc_frame_header
*) skb_transport_header(skb
);
546 skb_pull(skb
, sizeof(struct fcoe_hdr
));
547 fr_len
= skb
->len
- sizeof(struct fcoe_crc_eof
);
549 fp
= (struct fc_frame
*)skb
;
552 fr_sof(fp
) = hp
->fcoe_sof
;
553 if (skb_copy_bits(skb
, fr_len
, &crc_eof
, sizeof(crc_eof
))) {
557 fr_eof(fp
) = crc_eof
.fcoe_eof
;
558 fr_crc(fp
) = crc_eof
.fcoe_crc32
;
559 if (pskb_trim(skb
, fr_len
)) {
564 fh
= fc_frame_header_get(fp
);
566 vn_port
= fc_vport_id_lookup(lport
, ntoh24(fh
->fh_d_id
));
568 port
= lport_priv(vn_port
);
569 if (!ether_addr_equal(port
->data_src_addr
, dest_mac
)) {
570 BNX2FC_HBA_DBG(lport
, "fpma mismatch\n");
575 if (fh
->fh_r_ctl
== FC_RCTL_DD_SOL_DATA
&&
576 fh
->fh_type
== FC_TYPE_FCP
) {
577 /* Drop FCP data. We dont this in L2 path */
581 if (fh
->fh_r_ctl
== FC_RCTL_ELS_REQ
&&
582 fh
->fh_type
== FC_TYPE_ELS
) {
583 switch (fc_frame_payload_op(fp
)) {
585 if (ntoh24(fh
->fh_s_id
) == FC_FID_FLOGI
) {
586 /* drop non-FIP LOGO */
594 if (fh
->fh_r_ctl
== FC_RCTL_BA_ABTS
) {
595 /* Drop incoming ABTS */
600 stats
= per_cpu_ptr(lport
->stats
, smp_processor_id());
602 stats
->RxWords
+= fr_len
/ FCOE_WORD_TO_BYTE
;
604 if (le32_to_cpu(fr_crc(fp
)) !=
605 ~crc32(~0, skb
->data
, fr_len
)) {
606 if (stats
->InvalidCRCCount
< 5)
607 printk(KERN_WARNING PFX
"dropping frame with "
609 stats
->InvalidCRCCount
++;
613 fc_exch_recv(lport
, fp
);
617 * bnx2fc_percpu_io_thread - thread per cpu for ios
619 * @arg: ptr to bnx2fc_percpu_info structure
621 static int bnx2fc_percpu_io_thread(void *arg
)
623 struct bnx2fc_percpu_s
*p
= arg
;
624 struct bnx2fc_work
*work
, *tmp
;
625 LIST_HEAD(work_list
);
627 set_user_nice(current
, MIN_NICE
);
628 set_current_state(TASK_INTERRUPTIBLE
);
629 while (!kthread_should_stop()) {
631 spin_lock_bh(&p
->fp_work_lock
);
632 while (!list_empty(&p
->work_list
)) {
633 list_splice_init(&p
->work_list
, &work_list
);
634 spin_unlock_bh(&p
->fp_work_lock
);
636 list_for_each_entry_safe(work
, tmp
, &work_list
, list
) {
637 list_del_init(&work
->list
);
638 bnx2fc_process_cq_compl(work
->tgt
, work
->wqe
);
642 spin_lock_bh(&p
->fp_work_lock
);
644 __set_current_state(TASK_INTERRUPTIBLE
);
645 spin_unlock_bh(&p
->fp_work_lock
);
647 __set_current_state(TASK_RUNNING
);
652 static struct fc_host_statistics
*bnx2fc_get_host_stats(struct Scsi_Host
*shost
)
654 struct fc_host_statistics
*bnx2fc_stats
;
655 struct fc_lport
*lport
= shost_priv(shost
);
656 struct fcoe_port
*port
= lport_priv(lport
);
657 struct bnx2fc_interface
*interface
= port
->priv
;
658 struct bnx2fc_hba
*hba
= interface
->hba
;
659 struct fcoe_statistics_params
*fw_stats
;
662 fw_stats
= (struct fcoe_statistics_params
*)hba
->stats_buffer
;
666 bnx2fc_stats
= fc_get_host_stats(shost
);
668 init_completion(&hba
->stat_req_done
);
669 if (bnx2fc_send_stat_req(hba
))
671 rc
= wait_for_completion_timeout(&hba
->stat_req_done
, (2 * HZ
));
673 BNX2FC_HBA_DBG(lport
, "FW stat req timed out\n");
676 BNX2FC_STATS(hba
, rx_stat2
, fc_crc_cnt
);
677 bnx2fc_stats
->invalid_crc_count
+= hba
->bfw_stats
.fc_crc_cnt
;
678 BNX2FC_STATS(hba
, tx_stat
, fcoe_tx_pkt_cnt
);
679 bnx2fc_stats
->tx_frames
+= hba
->bfw_stats
.fcoe_tx_pkt_cnt
;
680 BNX2FC_STATS(hba
, tx_stat
, fcoe_tx_byte_cnt
);
681 bnx2fc_stats
->tx_words
+= ((hba
->bfw_stats
.fcoe_tx_byte_cnt
) / 4);
682 BNX2FC_STATS(hba
, rx_stat0
, fcoe_rx_pkt_cnt
);
683 bnx2fc_stats
->rx_frames
+= hba
->bfw_stats
.fcoe_rx_pkt_cnt
;
684 BNX2FC_STATS(hba
, rx_stat0
, fcoe_rx_byte_cnt
);
685 bnx2fc_stats
->rx_words
+= ((hba
->bfw_stats
.fcoe_rx_byte_cnt
) / 4);
687 bnx2fc_stats
->dumped_frames
= 0;
688 bnx2fc_stats
->lip_count
= 0;
689 bnx2fc_stats
->nos_count
= 0;
690 bnx2fc_stats
->loss_of_sync_count
= 0;
691 bnx2fc_stats
->loss_of_signal_count
= 0;
692 bnx2fc_stats
->prim_seq_protocol_err_count
= 0;
694 memcpy(&hba
->prev_stats
, hba
->stats_buffer
,
695 sizeof(struct fcoe_statistics_params
));
699 static int bnx2fc_shost_config(struct fc_lport
*lport
, struct device
*dev
)
701 struct fcoe_port
*port
= lport_priv(lport
);
702 struct bnx2fc_interface
*interface
= port
->priv
;
703 struct bnx2fc_hba
*hba
= interface
->hba
;
704 struct Scsi_Host
*shost
= lport
->host
;
707 shost
->max_cmd_len
= BNX2FC_MAX_CMD_LEN
;
708 shost
->max_lun
= bnx2fc_max_luns
;
709 shost
->max_id
= BNX2FC_MAX_FCP_TGT
;
710 shost
->max_channel
= 0;
712 shost
->transportt
= bnx2fc_vport_xport_template
;
714 shost
->transportt
= bnx2fc_transport_template
;
716 /* Add the new host to SCSI-ml */
717 rc
= scsi_add_host(lport
->host
, dev
);
719 printk(KERN_ERR PFX
"Error on scsi_add_host\n");
723 fc_host_max_npiv_vports(lport
->host
) = USHRT_MAX
;
724 snprintf(fc_host_symbolic_name(lport
->host
), 256,
725 "%s (QLogic %s) v%s over %s",
726 BNX2FC_NAME
, hba
->chip_num
, BNX2FC_VERSION
,
727 interface
->netdev
->name
);
732 static int bnx2fc_link_ok(struct fc_lport
*lport
)
734 struct fcoe_port
*port
= lport_priv(lport
);
735 struct bnx2fc_interface
*interface
= port
->priv
;
736 struct bnx2fc_hba
*hba
= interface
->hba
;
737 struct net_device
*dev
= hba
->phys_dev
;
740 if ((dev
->flags
& IFF_UP
) && netif_carrier_ok(dev
))
741 clear_bit(ADAPTER_STATE_LINK_DOWN
, &hba
->adapter_state
);
743 set_bit(ADAPTER_STATE_LINK_DOWN
, &hba
->adapter_state
);
750 * bnx2fc_get_link_state - get network link state
752 * @hba: adapter instance pointer
754 * updates adapter structure flag based on netdev state
756 void bnx2fc_get_link_state(struct bnx2fc_hba
*hba
)
758 if (test_bit(__LINK_STATE_NOCARRIER
, &hba
->phys_dev
->state
))
759 set_bit(ADAPTER_STATE_LINK_DOWN
, &hba
->adapter_state
);
761 clear_bit(ADAPTER_STATE_LINK_DOWN
, &hba
->adapter_state
);
764 static int bnx2fc_net_config(struct fc_lport
*lport
, struct net_device
*netdev
)
766 struct bnx2fc_hba
*hba
;
767 struct bnx2fc_interface
*interface
;
768 struct fcoe_ctlr
*ctlr
;
769 struct fcoe_port
*port
;
772 port
= lport_priv(lport
);
773 interface
= port
->priv
;
774 ctlr
= bnx2fc_to_ctlr(interface
);
775 hba
= interface
->hba
;
777 /* require support for get_pauseparam ethtool op. */
778 if (!hba
->phys_dev
->ethtool_ops
||
779 !hba
->phys_dev
->ethtool_ops
->get_pauseparam
)
782 if (fc_set_mfs(lport
, BNX2FC_MFS
))
785 skb_queue_head_init(&port
->fcoe_pending_queue
);
786 port
->fcoe_pending_queue_active
= 0;
787 setup_timer(&port
->timer
, fcoe_queue_timer
, (unsigned long) lport
);
789 fcoe_link_speed_update(lport
);
792 if (fcoe_get_wwn(netdev
, &wwnn
, NETDEV_FCOE_WWNN
))
793 wwnn
= fcoe_wwn_from_mac(ctlr
->ctl_src_addr
,
795 BNX2FC_HBA_DBG(lport
, "WWNN = 0x%llx\n", wwnn
);
796 fc_set_wwnn(lport
, wwnn
);
798 if (fcoe_get_wwn(netdev
, &wwpn
, NETDEV_FCOE_WWPN
))
799 wwpn
= fcoe_wwn_from_mac(ctlr
->ctl_src_addr
,
802 BNX2FC_HBA_DBG(lport
, "WWPN = 0x%llx\n", wwpn
);
803 fc_set_wwpn(lport
, wwpn
);
809 static void bnx2fc_destroy_timer(unsigned long data
)
811 struct bnx2fc_hba
*hba
= (struct bnx2fc_hba
*)data
;
813 printk(KERN_ERR PFX
"ERROR:bnx2fc_destroy_timer - "
814 "Destroy compl not received!!\n");
815 set_bit(BNX2FC_FLAG_DESTROY_CMPL
, &hba
->flags
);
816 wake_up_interruptible(&hba
->destroy_wait
);
820 * bnx2fc_indicate_netevent - Generic netdev event handler
822 * @context: adapter structure pointer
824 * @vlan_id: vlan id - associated vlan id with this event
826 * Handles NETDEV_UP, NETDEV_DOWN, NETDEV_GOING_DOWN,NETDEV_CHANGE and
827 * NETDEV_CHANGE_MTU events. Handle NETDEV_UNREGISTER only for vlans.
829 static void bnx2fc_indicate_netevent(void *context
, unsigned long event
,
832 struct bnx2fc_hba
*hba
= (struct bnx2fc_hba
*)context
;
833 struct fcoe_ctlr_device
*cdev
;
834 struct fc_lport
*lport
;
835 struct fc_lport
*vport
;
836 struct bnx2fc_interface
*interface
, *tmp
;
837 struct fcoe_ctlr
*ctlr
;
838 int wait_for_upload
= 0;
839 u32 link_possible
= 1;
841 if (vlan_id
!= 0 && event
!= NETDEV_UNREGISTER
)
846 if (!test_bit(ADAPTER_STATE_UP
, &hba
->adapter_state
))
847 printk(KERN_ERR
"indicate_netevent: "\
848 "hba is not UP!!\n");
852 clear_bit(ADAPTER_STATE_GOING_DOWN
, &hba
->adapter_state
);
853 clear_bit(ADAPTER_STATE_UP
, &hba
->adapter_state
);
857 case NETDEV_GOING_DOWN
:
858 set_bit(ADAPTER_STATE_GOING_DOWN
, &hba
->adapter_state
);
865 case NETDEV_UNREGISTER
:
868 mutex_lock(&bnx2fc_dev_lock
);
869 list_for_each_entry_safe(interface
, tmp
, &if_list
, list
) {
870 if (interface
->hba
== hba
&&
871 interface
->vlan_id
== (vlan_id
& VLAN_VID_MASK
))
872 __bnx2fc_destroy(interface
);
874 mutex_unlock(&bnx2fc_dev_lock
);
876 /* Ensure ALL destroy work has been completed before return */
877 flush_workqueue(bnx2fc_wq
);
884 mutex_lock(&bnx2fc_dev_lock
);
885 list_for_each_entry(interface
, &if_list
, list
) {
887 if (interface
->hba
!= hba
)
890 ctlr
= bnx2fc_to_ctlr(interface
);
892 BNX2FC_HBA_DBG(lport
, "netevent handler - event=%s %ld\n",
893 interface
->netdev
->name
, event
);
895 fcoe_link_speed_update(lport
);
897 cdev
= fcoe_ctlr_to_ctlr_dev(ctlr
);
899 if (link_possible
&& !bnx2fc_link_ok(lport
)) {
900 switch (cdev
->enabled
) {
901 case FCOE_CTLR_DISABLED
:
902 pr_info("Link up while interface is disabled.\n");
904 case FCOE_CTLR_ENABLED
:
905 case FCOE_CTLR_UNUSED
:
906 /* Reset max recv frame size to default */
907 fc_set_mfs(lport
, BNX2FC_MFS
);
909 * ctlr link up will only be handled during
910 * enable to avoid sending discovery
911 * solicitation on a stale vlan
913 if (interface
->enabled
)
914 fcoe_ctlr_link_up(ctlr
);
916 } else if (fcoe_ctlr_link_down(ctlr
)) {
917 switch (cdev
->enabled
) {
918 case FCOE_CTLR_DISABLED
:
919 pr_info("Link down while interface is disabled.\n");
921 case FCOE_CTLR_ENABLED
:
922 case FCOE_CTLR_UNUSED
:
923 mutex_lock(&lport
->lp_mutex
);
924 list_for_each_entry(vport
, &lport
->vports
, list
)
925 fc_host_port_type(vport
->host
) =
927 mutex_unlock(&lport
->lp_mutex
);
928 fc_host_port_type(lport
->host
) =
930 per_cpu_ptr(lport
->stats
,
931 get_cpu())->LinkFailureCount
++;
933 fcoe_clean_pending_queue(lport
);
938 mutex_unlock(&bnx2fc_dev_lock
);
940 if (wait_for_upload
) {
941 clear_bit(ADAPTER_STATE_READY
, &hba
->adapter_state
);
942 init_waitqueue_head(&hba
->shutdown_wait
);
943 BNX2FC_MISC_DBG("indicate_netevent "
944 "num_ofld_sess = %d\n",
946 hba
->wait_for_link_down
= 1;
947 wait_event_interruptible(hba
->shutdown_wait
,
948 (hba
->num_ofld_sess
== 0));
949 BNX2FC_MISC_DBG("wakeup - num_ofld_sess = %d\n",
951 hba
->wait_for_link_down
= 0;
953 if (signal_pending(current
))
954 flush_signals(current
);
958 static int bnx2fc_libfc_config(struct fc_lport
*lport
)
961 /* Set the function pointers set by bnx2fc driver */
962 memcpy(&lport
->tt
, &bnx2fc_libfc_fcn_templ
,
963 sizeof(struct libfc_function_template
));
964 fc_elsct_init(lport
);
967 fc_disc_config(lport
, lport
);
971 static int bnx2fc_em_config(struct fc_lport
*lport
, struct bnx2fc_hba
*hba
)
973 int fcoe_min_xid
, fcoe_max_xid
;
975 fcoe_min_xid
= hba
->max_xid
+ 1;
977 fcoe_max_xid
= hba
->max_xid
+ FCOE_XIDS_PER_CPU_OFFSET
;
979 fcoe_max_xid
= hba
->max_xid
+ FCOE_MAX_XID_OFFSET
;
980 if (!fc_exch_mgr_alloc(lport
, FC_CLASS_3
, fcoe_min_xid
,
981 fcoe_max_xid
, NULL
)) {
982 printk(KERN_ERR PFX
"em_config:fc_exch_mgr_alloc failed\n");
989 static int bnx2fc_lport_config(struct fc_lport
*lport
)
993 lport
->max_retry_count
= BNX2FC_MAX_RETRY_CNT
;
994 lport
->max_rport_retry_count
= BNX2FC_MAX_RPORT_RETRY_CNT
;
995 lport
->e_d_tov
= 2 * 1000;
996 lport
->r_a_tov
= 10 * 1000;
998 lport
->service_params
= (FCP_SPPF_INIT_FCN
| FCP_SPPF_RD_XRDY_DIS
|
999 FCP_SPPF_RETRY
| FCP_SPPF_CONF_COMPL
);
1000 lport
->does_npiv
= 1;
1002 memset(&lport
->rnid_gen
, 0, sizeof(struct fc_els_rnid_gen
));
1003 lport
->rnid_gen
.rnid_atype
= BNX2FC_RNID_HBA
;
1005 /* alloc stats structure */
1006 if (fc_lport_init_stats(lport
))
1009 /* Finish fc_lport configuration */
1010 fc_lport_config(lport
);
1016 * bnx2fc_fip_recv - handle a received FIP frame.
1018 * @skb: the received skb
1019 * @dev: associated &net_device
1020 * @ptype: the &packet_type structure which was used to register this handler.
1021 * @orig_dev: original receive &net_device, in case @ dev is a bond.
1023 * Returns: 0 for success
1025 static int bnx2fc_fip_recv(struct sk_buff
*skb
, struct net_device
*dev
,
1026 struct packet_type
*ptype
,
1027 struct net_device
*orig_dev
)
1029 struct bnx2fc_interface
*interface
;
1030 struct fcoe_ctlr
*ctlr
;
1031 interface
= container_of(ptype
, struct bnx2fc_interface
,
1033 ctlr
= bnx2fc_to_ctlr(interface
);
1034 fcoe_ctlr_recv(ctlr
, skb
);
1039 * bnx2fc_update_src_mac - Update Ethernet MAC filters.
1041 * @fip: FCoE controller.
1042 * @old: Unicast MAC address to delete if the MAC is non-zero.
1043 * @new: Unicast MAC address to add.
1045 * Remove any previously-set unicast MAC filter.
1046 * Add secondary FCoE MAC address filter for our OUI.
1048 static void bnx2fc_update_src_mac(struct fc_lport
*lport
, u8
*addr
)
1050 struct fcoe_port
*port
= lport_priv(lport
);
1052 memcpy(port
->data_src_addr
, addr
, ETH_ALEN
);
1056 * bnx2fc_get_src_mac - return the ethernet source address for an lport
1058 * @lport: libfc port
1060 static u8
*bnx2fc_get_src_mac(struct fc_lport
*lport
)
1062 struct fcoe_port
*port
;
1064 port
= (struct fcoe_port
*)lport_priv(lport
);
1065 return port
->data_src_addr
;
1069 * bnx2fc_fip_send - send an Ethernet-encapsulated FIP frame.
1071 * @fip: FCoE controller.
1074 static void bnx2fc_fip_send(struct fcoe_ctlr
*fip
, struct sk_buff
*skb
)
1076 struct fip_header
*fiph
;
1077 struct ethhdr
*eth_hdr
;
1081 fiph
= (struct fip_header
*) ((void *)skb
->data
+ 2 * ETH_ALEN
+ 2);
1082 eth_hdr
= (struct ethhdr
*)skb_mac_header(skb
);
1083 op
= ntohs(fiph
->fip_op
);
1084 sub
= fiph
->fip_subcode
;
1086 if (op
== FIP_OP_CTRL
&& sub
== FIP_SC_SOL
&& bnx2fc_log_fka
)
1087 BNX2FC_MISC_DBG("Sending FKA from %pM to %pM.\n",
1088 eth_hdr
->h_source
, eth_hdr
->h_dest
);
1090 skb
->dev
= bnx2fc_from_ctlr(fip
)->netdev
;
1091 dev_queue_xmit(skb
);
1094 static int bnx2fc_vport_create(struct fc_vport
*vport
, bool disabled
)
1096 struct Scsi_Host
*shost
= vport_to_shost(vport
);
1097 struct fc_lport
*n_port
= shost_priv(shost
);
1098 struct fcoe_port
*port
= lport_priv(n_port
);
1099 struct bnx2fc_interface
*interface
= port
->priv
;
1100 struct net_device
*netdev
= interface
->netdev
;
1101 struct fc_lport
*vn_port
;
1105 rc
= fcoe_validate_vport_create(vport
);
1107 fcoe_wwn_to_str(vport
->port_name
, buf
, sizeof(buf
));
1108 printk(KERN_ERR PFX
"Failed to create vport, "
1109 "WWPN (0x%s) already exists\n",
1114 if (!test_bit(BNX2FC_FLAG_FW_INIT_DONE
, &interface
->hba
->flags
)) {
1115 printk(KERN_ERR PFX
"vn ports cannot be created on"
1116 "this interface\n");
1120 mutex_lock(&bnx2fc_dev_lock
);
1121 vn_port
= bnx2fc_if_create(interface
, &vport
->dev
, 1);
1122 mutex_unlock(&bnx2fc_dev_lock
);
1126 printk(KERN_ERR PFX
"bnx2fc_vport_create (%s) failed\n",
1131 if (bnx2fc_devloss_tmo
)
1132 fc_host_dev_loss_tmo(vn_port
->host
) = bnx2fc_devloss_tmo
;
1135 fc_vport_set_state(vport
, FC_VPORT_DISABLED
);
1137 vn_port
->boot_time
= jiffies
;
1138 fc_lport_init(vn_port
);
1139 fc_fabric_login(vn_port
);
1140 fc_vport_setlink(vn_port
);
1145 static void bnx2fc_free_vport(struct bnx2fc_hba
*hba
, struct fc_lport
*lport
)
1147 struct bnx2fc_lport
*blport
, *tmp
;
1149 spin_lock_bh(&hba
->hba_lock
);
1150 list_for_each_entry_safe(blport
, tmp
, &hba
->vports
, list
) {
1151 if (blport
->lport
== lport
) {
1152 list_del(&blport
->list
);
1156 spin_unlock_bh(&hba
->hba_lock
);
1159 static int bnx2fc_vport_destroy(struct fc_vport
*vport
)
1161 struct Scsi_Host
*shost
= vport_to_shost(vport
);
1162 struct fc_lport
*n_port
= shost_priv(shost
);
1163 struct fc_lport
*vn_port
= vport
->dd_data
;
1164 struct fcoe_port
*port
= lport_priv(vn_port
);
1165 struct bnx2fc_interface
*interface
= port
->priv
;
1166 struct fc_lport
*v_port
;
1169 mutex_lock(&n_port
->lp_mutex
);
1170 list_for_each_entry(v_port
, &n_port
->vports
, list
)
1171 if (v_port
->vport
== vport
) {
1177 mutex_unlock(&n_port
->lp_mutex
);
1180 list_del(&vn_port
->list
);
1181 mutex_unlock(&n_port
->lp_mutex
);
1182 bnx2fc_free_vport(interface
->hba
, port
->lport
);
1183 bnx2fc_port_shutdown(port
->lport
);
1184 bnx2fc_interface_put(interface
);
1185 queue_work(bnx2fc_wq
, &port
->destroy_work
);
1189 static int bnx2fc_vport_disable(struct fc_vport
*vport
, bool disable
)
1191 struct fc_lport
*lport
= vport
->dd_data
;
1194 fc_vport_set_state(vport
, FC_VPORT_DISABLED
);
1195 fc_fabric_logoff(lport
);
1197 lport
->boot_time
= jiffies
;
1198 fc_fabric_login(lport
);
1199 fc_vport_setlink(lport
);
1205 static int bnx2fc_interface_setup(struct bnx2fc_interface
*interface
)
1207 struct net_device
*netdev
= interface
->netdev
;
1208 struct net_device
*physdev
= interface
->hba
->phys_dev
;
1209 struct fcoe_ctlr
*ctlr
= bnx2fc_to_ctlr(interface
);
1210 struct netdev_hw_addr
*ha
;
1211 int sel_san_mac
= 0;
1213 /* setup Source MAC Address */
1215 for_each_dev_addr(physdev
, ha
) {
1216 BNX2FC_MISC_DBG("net_config: ha->type = %d, fip_mac = ",
1218 printk(KERN_INFO
"%2x:%2x:%2x:%2x:%2x:%2x\n", ha
->addr
[0],
1219 ha
->addr
[1], ha
->addr
[2], ha
->addr
[3],
1220 ha
->addr
[4], ha
->addr
[5]);
1222 if ((ha
->type
== NETDEV_HW_ADDR_T_SAN
) &&
1223 (is_valid_ether_addr(ha
->addr
))) {
1224 memcpy(ctlr
->ctl_src_addr
, ha
->addr
,
1227 BNX2FC_MISC_DBG("Found SAN MAC\n");
1235 interface
->fip_packet_type
.func
= bnx2fc_fip_recv
;
1236 interface
->fip_packet_type
.type
= htons(ETH_P_FIP
);
1237 interface
->fip_packet_type
.dev
= netdev
;
1238 dev_add_pack(&interface
->fip_packet_type
);
1240 interface
->fcoe_packet_type
.func
= bnx2fc_rcv
;
1241 interface
->fcoe_packet_type
.type
= __constant_htons(ETH_P_FCOE
);
1242 interface
->fcoe_packet_type
.dev
= netdev
;
1243 dev_add_pack(&interface
->fcoe_packet_type
);
1248 static int bnx2fc_attach_transport(void)
1250 bnx2fc_transport_template
=
1251 fc_attach_transport(&bnx2fc_transport_function
);
1253 if (bnx2fc_transport_template
== NULL
) {
1254 printk(KERN_ERR PFX
"Failed to attach FC transport\n");
1258 bnx2fc_vport_xport_template
=
1259 fc_attach_transport(&bnx2fc_vport_xport_function
);
1260 if (bnx2fc_vport_xport_template
== NULL
) {
1262 "Failed to attach FC transport for vport\n");
1263 fc_release_transport(bnx2fc_transport_template
);
1264 bnx2fc_transport_template
= NULL
;
1269 static void bnx2fc_release_transport(void)
1271 fc_release_transport(bnx2fc_transport_template
);
1272 fc_release_transport(bnx2fc_vport_xport_template
);
1273 bnx2fc_transport_template
= NULL
;
1274 bnx2fc_vport_xport_template
= NULL
;
1277 static void bnx2fc_interface_release(struct kref
*kref
)
1279 struct fcoe_ctlr_device
*ctlr_dev
;
1280 struct bnx2fc_interface
*interface
;
1281 struct fcoe_ctlr
*ctlr
;
1282 struct net_device
*netdev
;
1284 interface
= container_of(kref
, struct bnx2fc_interface
, kref
);
1285 BNX2FC_MISC_DBG("Interface is being released\n");
1287 ctlr
= bnx2fc_to_ctlr(interface
);
1288 ctlr_dev
= fcoe_ctlr_to_ctlr_dev(ctlr
);
1289 netdev
= interface
->netdev
;
1291 /* tear-down FIP controller */
1292 if (test_and_clear_bit(BNX2FC_CTLR_INIT_DONE
, &interface
->if_flags
))
1293 fcoe_ctlr_destroy(ctlr
);
1295 fcoe_ctlr_device_delete(ctlr_dev
);
1298 module_put(THIS_MODULE
);
1301 static inline void bnx2fc_interface_get(struct bnx2fc_interface
*interface
)
1303 kref_get(&interface
->kref
);
1306 static inline void bnx2fc_interface_put(struct bnx2fc_interface
*interface
)
1308 kref_put(&interface
->kref
, bnx2fc_interface_release
);
1310 static void bnx2fc_hba_destroy(struct bnx2fc_hba
*hba
)
1312 /* Free the command manager */
1314 bnx2fc_cmd_mgr_free(hba
->cmd_mgr
);
1315 hba
->cmd_mgr
= NULL
;
1317 kfree(hba
->tgt_ofld_list
);
1318 bnx2fc_unbind_pcidev(hba
);
1323 * bnx2fc_hba_create - create a new bnx2fc hba
1325 * @cnic: pointer to cnic device
1327 * Creates a new FCoE hba on the given device.
1330 static struct bnx2fc_hba
*bnx2fc_hba_create(struct cnic_dev
*cnic
)
1332 struct bnx2fc_hba
*hba
;
1333 struct fcoe_capabilities
*fcoe_cap
;
1336 hba
= kzalloc(sizeof(*hba
), GFP_KERNEL
);
1338 printk(KERN_ERR PFX
"Unable to allocate hba structure\n");
1341 spin_lock_init(&hba
->hba_lock
);
1342 mutex_init(&hba
->hba_mutex
);
1346 hba
->max_tasks
= cnic
->max_fcoe_exchanges
;
1347 hba
->elstm_xids
= (hba
->max_tasks
/ 2);
1348 hba
->max_outstanding_cmds
= hba
->elstm_xids
;
1349 hba
->max_xid
= (hba
->max_tasks
- 1);
1351 rc
= bnx2fc_bind_pcidev(hba
);
1353 printk(KERN_ERR PFX
"create_adapter: bind error\n");
1356 hba
->phys_dev
= cnic
->netdev
;
1357 hba
->next_conn_id
= 0;
1359 hba
->tgt_ofld_list
=
1360 kzalloc(sizeof(struct bnx2fc_rport
*) * BNX2FC_NUM_MAX_SESS
,
1362 if (!hba
->tgt_ofld_list
) {
1363 printk(KERN_ERR PFX
"Unable to allocate tgt offload list\n");
1367 hba
->num_ofld_sess
= 0;
1369 hba
->cmd_mgr
= bnx2fc_cmd_mgr_alloc(hba
);
1370 if (!hba
->cmd_mgr
) {
1371 printk(KERN_ERR PFX
"em_config:bnx2fc_cmd_mgr_alloc failed\n");
1374 fcoe_cap
= &hba
->fcoe_cap
;
1376 fcoe_cap
->capability1
= BNX2FC_TM_MAX_SQES
<<
1377 FCOE_IOS_PER_CONNECTION_SHIFT
;
1378 fcoe_cap
->capability1
|= BNX2FC_NUM_MAX_SESS
<<
1379 FCOE_LOGINS_PER_PORT_SHIFT
;
1380 fcoe_cap
->capability2
= hba
->max_outstanding_cmds
<<
1381 FCOE_NUMBER_OF_EXCHANGES_SHIFT
;
1382 fcoe_cap
->capability2
|= BNX2FC_MAX_NPIV
<<
1383 FCOE_NPIV_WWN_PER_PORT_SHIFT
;
1384 fcoe_cap
->capability3
= BNX2FC_NUM_MAX_SESS
<<
1385 FCOE_TARGETS_SUPPORTED_SHIFT
;
1386 fcoe_cap
->capability3
|= hba
->max_outstanding_cmds
<<
1387 FCOE_OUTSTANDING_COMMANDS_SHIFT
;
1388 fcoe_cap
->capability4
= FCOE_CAPABILITY4_STATEFUL
;
1390 init_waitqueue_head(&hba
->shutdown_wait
);
1391 init_waitqueue_head(&hba
->destroy_wait
);
1392 INIT_LIST_HEAD(&hba
->vports
);
1397 kfree(hba
->tgt_ofld_list
);
1399 bnx2fc_unbind_pcidev(hba
);
1405 static struct bnx2fc_interface
*
1406 bnx2fc_interface_create(struct bnx2fc_hba
*hba
,
1407 struct net_device
*netdev
,
1408 enum fip_state fip_mode
)
1410 struct fcoe_ctlr_device
*ctlr_dev
;
1411 struct bnx2fc_interface
*interface
;
1412 struct fcoe_ctlr
*ctlr
;
1416 size
= (sizeof(*interface
) + sizeof(struct fcoe_ctlr
));
1417 ctlr_dev
= fcoe_ctlr_device_add(&netdev
->dev
, &bnx2fc_fcoe_sysfs_templ
,
1420 printk(KERN_ERR PFX
"Unable to allocate interface structure\n");
1423 ctlr
= fcoe_ctlr_device_priv(ctlr_dev
);
1424 ctlr
->cdev
= ctlr_dev
;
1425 interface
= fcoe_ctlr_priv(ctlr
);
1427 kref_init(&interface
->kref
);
1428 interface
->hba
= hba
;
1429 interface
->netdev
= netdev
;
1431 /* Initialize FIP */
1432 fcoe_ctlr_init(ctlr
, fip_mode
);
1433 ctlr
->send
= bnx2fc_fip_send
;
1434 ctlr
->update_mac
= bnx2fc_update_src_mac
;
1435 ctlr
->get_src_addr
= bnx2fc_get_src_mac
;
1436 set_bit(BNX2FC_CTLR_INIT_DONE
, &interface
->if_flags
);
1438 rc
= bnx2fc_interface_setup(interface
);
1442 fcoe_ctlr_destroy(ctlr
);
1444 fcoe_ctlr_device_delete(ctlr_dev
);
1449 * bnx2fc_if_create - Create FCoE instance on a given interface
1451 * @interface: FCoE interface to create a local port on
1452 * @parent: Device pointer to be the parent in sysfs for the SCSI host
1453 * @npiv: Indicates if the port is vport or not
1455 * Creates a fc_lport instance and a Scsi_Host instance and configure them.
1457 * Returns: Allocated fc_lport or an error pointer
1459 static struct fc_lport
*bnx2fc_if_create(struct bnx2fc_interface
*interface
,
1460 struct device
*parent
, int npiv
)
1462 struct fcoe_ctlr
*ctlr
= bnx2fc_to_ctlr(interface
);
1463 struct fc_lport
*lport
, *n_port
;
1464 struct fcoe_port
*port
;
1465 struct Scsi_Host
*shost
;
1466 struct fc_vport
*vport
= dev_to_vport(parent
);
1467 struct bnx2fc_lport
*blport
;
1468 struct bnx2fc_hba
*hba
= interface
->hba
;
1471 blport
= kzalloc(sizeof(struct bnx2fc_lport
), GFP_KERNEL
);
1473 BNX2FC_HBA_DBG(ctlr
->lp
, "Unable to alloc blport\n");
1477 /* Allocate Scsi_Host structure */
1478 bnx2fc_shost_template
.can_queue
= hba
->max_outstanding_cmds
;
1480 lport
= libfc_host_alloc(&bnx2fc_shost_template
, sizeof(*port
));
1482 lport
= libfc_vport_create(vport
, sizeof(*port
));
1485 printk(KERN_ERR PFX
"could not allocate scsi host structure\n");
1488 shost
= lport
->host
;
1489 port
= lport_priv(lport
);
1490 port
->lport
= lport
;
1491 port
->priv
= interface
;
1492 port
->get_netdev
= bnx2fc_netdev
;
1493 INIT_WORK(&port
->destroy_work
, bnx2fc_destroy_work
);
1495 /* Configure fcoe_port */
1496 rc
= bnx2fc_lport_config(lport
);
1501 printk(KERN_ERR PFX
"Setting vport names, 0x%llX 0x%llX\n",
1502 vport
->node_name
, vport
->port_name
);
1503 fc_set_wwnn(lport
, vport
->node_name
);
1504 fc_set_wwpn(lport
, vport
->port_name
);
1506 /* Configure netdev and networking properties of the lport */
1507 rc
= bnx2fc_net_config(lport
, interface
->netdev
);
1509 printk(KERN_ERR PFX
"Error on bnx2fc_net_config\n");
1513 rc
= bnx2fc_shost_config(lport
, parent
);
1515 printk(KERN_ERR PFX
"Couldnt configure shost for %s\n",
1516 interface
->netdev
->name
);
1520 /* Initialize the libfc library */
1521 rc
= bnx2fc_libfc_config(lport
);
1523 printk(KERN_ERR PFX
"Couldnt configure libfc\n");
1526 fc_host_port_type(lport
->host
) = FC_PORTTYPE_UNKNOWN
;
1528 if (bnx2fc_devloss_tmo
)
1529 fc_host_dev_loss_tmo(shost
) = bnx2fc_devloss_tmo
;
1531 /* Allocate exchange manager */
1533 rc
= bnx2fc_em_config(lport
, hba
);
1535 shost
= vport_to_shost(vport
);
1536 n_port
= shost_priv(shost
);
1537 rc
= fc_exch_mgr_list_clone(n_port
, lport
);
1541 printk(KERN_ERR PFX
"Error on bnx2fc_em_config\n");
1545 bnx2fc_interface_get(interface
);
1547 spin_lock_bh(&hba
->hba_lock
);
1548 blport
->lport
= lport
;
1549 list_add_tail(&blport
->list
, &hba
->vports
);
1550 spin_unlock_bh(&hba
->hba_lock
);
1555 scsi_remove_host(shost
);
1557 scsi_host_put(lport
->host
);
1563 static void bnx2fc_net_cleanup(struct bnx2fc_interface
*interface
)
1565 /* Dont listen for Ethernet packets anymore */
1566 __dev_remove_pack(&interface
->fcoe_packet_type
);
1567 __dev_remove_pack(&interface
->fip_packet_type
);
1571 static void bnx2fc_interface_cleanup(struct bnx2fc_interface
*interface
)
1573 struct fcoe_ctlr
*ctlr
= bnx2fc_to_ctlr(interface
);
1574 struct fc_lport
*lport
= ctlr
->lp
;
1575 struct fcoe_port
*port
= lport_priv(lport
);
1576 struct bnx2fc_hba
*hba
= interface
->hba
;
1578 /* Stop the transmit retry timer */
1579 del_timer_sync(&port
->timer
);
1581 /* Free existing transmit skbs */
1582 fcoe_clean_pending_queue(lport
);
1584 bnx2fc_net_cleanup(interface
);
1586 bnx2fc_free_vport(hba
, lport
);
1589 static void bnx2fc_if_destroy(struct fc_lport
*lport
)
1592 /* Free queued packets for the receive thread */
1593 bnx2fc_clean_rx_queue(lport
);
1595 /* Detach from scsi-ml */
1596 fc_remove_host(lport
->host
);
1597 scsi_remove_host(lport
->host
);
1600 * Note that only the physical lport will have the exchange manager.
1601 * for vports, this function is NOP
1603 fc_exch_mgr_free(lport
);
1605 /* Free memory used by statistical counters */
1606 fc_lport_free_stats(lport
);
1608 /* Release Scsi_Host */
1609 scsi_host_put(lport
->host
);
1612 static void __bnx2fc_destroy(struct bnx2fc_interface
*interface
)
1614 struct fcoe_ctlr
*ctlr
= bnx2fc_to_ctlr(interface
);
1615 struct fc_lport
*lport
= ctlr
->lp
;
1616 struct fcoe_port
*port
= lport_priv(lport
);
1618 bnx2fc_interface_cleanup(interface
);
1619 bnx2fc_stop(interface
);
1620 list_del(&interface
->list
);
1621 bnx2fc_interface_put(interface
);
1622 queue_work(bnx2fc_wq
, &port
->destroy_work
);
1626 * bnx2fc_destroy - Destroy a bnx2fc FCoE interface
1628 * @buffer: The name of the Ethernet interface to be destroyed
1629 * @kp: The associated kernel parameter
1631 * Called from sysfs.
1633 * Returns: 0 for success
1635 static int bnx2fc_destroy(struct net_device
*netdev
)
1637 struct bnx2fc_interface
*interface
= NULL
;
1638 struct workqueue_struct
*timer_work_queue
;
1639 struct fcoe_ctlr
*ctlr
;
1643 mutex_lock(&bnx2fc_dev_lock
);
1645 interface
= bnx2fc_interface_lookup(netdev
);
1646 ctlr
= bnx2fc_to_ctlr(interface
);
1647 if (!interface
|| !ctlr
->lp
) {
1649 printk(KERN_ERR PFX
"bnx2fc_destroy: interface or lport not found\n");
1653 timer_work_queue
= interface
->timer_work_queue
;
1654 __bnx2fc_destroy(interface
);
1655 destroy_workqueue(timer_work_queue
);
1658 mutex_unlock(&bnx2fc_dev_lock
);
1663 static void bnx2fc_destroy_work(struct work_struct
*work
)
1665 struct fcoe_port
*port
;
1666 struct fc_lport
*lport
;
1668 port
= container_of(work
, struct fcoe_port
, destroy_work
);
1669 lport
= port
->lport
;
1671 BNX2FC_HBA_DBG(lport
, "Entered bnx2fc_destroy_work\n");
1673 bnx2fc_if_destroy(lport
);
1676 static void bnx2fc_unbind_adapter_devices(struct bnx2fc_hba
*hba
)
1678 bnx2fc_free_fw_resc(hba
);
1679 bnx2fc_free_task_ctx(hba
);
1683 * bnx2fc_bind_adapter_devices - binds bnx2fc adapter with the associated
1686 * @hba: Adapter instance
1688 static int bnx2fc_bind_adapter_devices(struct bnx2fc_hba
*hba
)
1690 if (bnx2fc_setup_task_ctx(hba
))
1693 if (bnx2fc_setup_fw_resc(hba
))
1698 bnx2fc_unbind_adapter_devices(hba
);
1702 static int bnx2fc_bind_pcidev(struct bnx2fc_hba
*hba
)
1704 struct cnic_dev
*cnic
;
1705 struct pci_dev
*pdev
;
1708 printk(KERN_ERR PFX
"cnic is NULL\n");
1712 pdev
= hba
->pcidev
= cnic
->pcidev
;
1716 switch (pdev
->device
) {
1717 case PCI_DEVICE_ID_NX2_57710
:
1718 strncpy(hba
->chip_num
, "BCM57710", BCM_CHIP_LEN
);
1720 case PCI_DEVICE_ID_NX2_57711
:
1721 strncpy(hba
->chip_num
, "BCM57711", BCM_CHIP_LEN
);
1723 case PCI_DEVICE_ID_NX2_57712
:
1724 case PCI_DEVICE_ID_NX2_57712_MF
:
1725 case PCI_DEVICE_ID_NX2_57712_VF
:
1726 strncpy(hba
->chip_num
, "BCM57712", BCM_CHIP_LEN
);
1728 case PCI_DEVICE_ID_NX2_57800
:
1729 case PCI_DEVICE_ID_NX2_57800_MF
:
1730 case PCI_DEVICE_ID_NX2_57800_VF
:
1731 strncpy(hba
->chip_num
, "BCM57800", BCM_CHIP_LEN
);
1733 case PCI_DEVICE_ID_NX2_57810
:
1734 case PCI_DEVICE_ID_NX2_57810_MF
:
1735 case PCI_DEVICE_ID_NX2_57810_VF
:
1736 strncpy(hba
->chip_num
, "BCM57810", BCM_CHIP_LEN
);
1738 case PCI_DEVICE_ID_NX2_57840
:
1739 case PCI_DEVICE_ID_NX2_57840_MF
:
1740 case PCI_DEVICE_ID_NX2_57840_VF
:
1741 case PCI_DEVICE_ID_NX2_57840_2_20
:
1742 case PCI_DEVICE_ID_NX2_57840_4_10
:
1743 strncpy(hba
->chip_num
, "BCM57840", BCM_CHIP_LEN
);
1746 pr_err(PFX
"Unknown device id 0x%x\n", pdev
->device
);
1749 pci_dev_get(hba
->pcidev
);
1753 static void bnx2fc_unbind_pcidev(struct bnx2fc_hba
*hba
)
1756 hba
->chip_num
[0] = '\0';
1757 pci_dev_put(hba
->pcidev
);
1763 * bnx2fc_ulp_get_stats - cnic callback to populate FCoE stats
1765 * @handle: transport handle pointing to adapter struture
1767 static int bnx2fc_ulp_get_stats(void *handle
)
1769 struct bnx2fc_hba
*hba
= handle
;
1770 struct cnic_dev
*cnic
;
1771 struct fcoe_stats_info
*stats_addr
;
1777 stats_addr
= &cnic
->stats_addr
->fcoe_stat
;
1781 strncpy(stats_addr
->version
, BNX2FC_VERSION
,
1782 sizeof(stats_addr
->version
));
1783 stats_addr
->txq_size
= BNX2FC_SQ_WQES_MAX
;
1784 stats_addr
->rxq_size
= BNX2FC_CQ_WQES_MAX
;
1791 * bnx2fc_ulp_start - cnic callback to initialize & start adapter instance
1793 * @handle: transport handle pointing to adapter structure
1795 * This function maps adapter structure to pcidev structure and initiates
1796 * firmware handshake to enable/initialize on-chip FCoE components.
1797 * This bnx2fc - cnic interface api callback is used after following
1798 * conditions are met -
1799 * a) underlying network interface is up (marked by event NETDEV_UP
1801 * b) bnx2fc adatper structure is registered.
1803 static void bnx2fc_ulp_start(void *handle
)
1805 struct bnx2fc_hba
*hba
= handle
;
1806 struct bnx2fc_interface
*interface
;
1807 struct fcoe_ctlr
*ctlr
;
1808 struct fc_lport
*lport
;
1810 mutex_lock(&bnx2fc_dev_lock
);
1812 if (!test_bit(BNX2FC_FLAG_FW_INIT_DONE
, &hba
->flags
))
1813 bnx2fc_fw_init(hba
);
1815 BNX2FC_MISC_DBG("bnx2fc started.\n");
1817 list_for_each_entry(interface
, &if_list
, list
) {
1818 if (interface
->hba
== hba
) {
1819 ctlr
= bnx2fc_to_ctlr(interface
);
1821 /* Kick off Fabric discovery*/
1822 printk(KERN_ERR PFX
"ulp_init: start discovery\n");
1823 lport
->tt
.frame_send
= bnx2fc_xmit
;
1824 bnx2fc_start_disc(interface
);
1828 mutex_unlock(&bnx2fc_dev_lock
);
1831 static void bnx2fc_port_shutdown(struct fc_lport
*lport
)
1833 BNX2FC_MISC_DBG("Entered %s\n", __func__
);
1834 fc_fabric_logoff(lport
);
1835 fc_lport_destroy(lport
);
1838 static void bnx2fc_stop(struct bnx2fc_interface
*interface
)
1840 struct fcoe_ctlr
*ctlr
= bnx2fc_to_ctlr(interface
);
1841 struct fc_lport
*lport
;
1842 struct fc_lport
*vport
;
1844 if (!test_bit(BNX2FC_FLAG_FW_INIT_DONE
, &interface
->hba
->flags
))
1848 bnx2fc_port_shutdown(lport
);
1850 mutex_lock(&lport
->lp_mutex
);
1851 list_for_each_entry(vport
, &lport
->vports
, list
)
1852 fc_host_port_type(vport
->host
) =
1853 FC_PORTTYPE_UNKNOWN
;
1854 mutex_unlock(&lport
->lp_mutex
);
1855 fc_host_port_type(lport
->host
) = FC_PORTTYPE_UNKNOWN
;
1856 fcoe_ctlr_link_down(ctlr
);
1857 fcoe_clean_pending_queue(lport
);
1860 static int bnx2fc_fw_init(struct bnx2fc_hba
*hba
)
1862 #define BNX2FC_INIT_POLL_TIME (1000 / HZ)
1866 rc
= bnx2fc_bind_adapter_devices(hba
);
1868 printk(KERN_ALERT PFX
1869 "bnx2fc_bind_adapter_devices failed - rc = %d\n", rc
);
1873 rc
= bnx2fc_send_fw_fcoe_init_msg(hba
);
1875 printk(KERN_ALERT PFX
1876 "bnx2fc_send_fw_fcoe_init_msg failed - rc = %d\n", rc
);
1881 * Wait until the adapter init message is complete, and adapter
1884 while (!test_bit(ADAPTER_STATE_UP
, &hba
->adapter_state
) && i
--)
1885 msleep(BNX2FC_INIT_POLL_TIME
);
1887 if (!test_bit(ADAPTER_STATE_UP
, &hba
->adapter_state
)) {
1888 printk(KERN_ERR PFX
"bnx2fc_start: %s failed to initialize. "
1890 hba
->cnic
->netdev
->name
);
1896 set_bit(BNX2FC_FLAG_FW_INIT_DONE
, &hba
->flags
);
1900 bnx2fc_unbind_adapter_devices(hba
);
1905 static void bnx2fc_fw_destroy(struct bnx2fc_hba
*hba
)
1907 if (test_and_clear_bit(BNX2FC_FLAG_FW_INIT_DONE
, &hba
->flags
)) {
1908 if (bnx2fc_send_fw_fcoe_destroy_msg(hba
) == 0) {
1909 init_timer(&hba
->destroy_timer
);
1910 hba
->destroy_timer
.expires
= BNX2FC_FW_TIMEOUT
+
1912 hba
->destroy_timer
.function
= bnx2fc_destroy_timer
;
1913 hba
->destroy_timer
.data
= (unsigned long)hba
;
1914 add_timer(&hba
->destroy_timer
);
1915 wait_event_interruptible(hba
->destroy_wait
,
1916 test_bit(BNX2FC_FLAG_DESTROY_CMPL
,
1918 clear_bit(BNX2FC_FLAG_DESTROY_CMPL
, &hba
->flags
);
1919 /* This should never happen */
1920 if (signal_pending(current
))
1921 flush_signals(current
);
1923 del_timer_sync(&hba
->destroy_timer
);
1925 bnx2fc_unbind_adapter_devices(hba
);
1930 * bnx2fc_ulp_stop - cnic callback to shutdown adapter instance
1932 * @handle: transport handle pointing to adapter structure
1934 * Driver checks if adapter is already in shutdown mode, if not start
1935 * the shutdown process.
1937 static void bnx2fc_ulp_stop(void *handle
)
1939 struct bnx2fc_hba
*hba
= handle
;
1940 struct bnx2fc_interface
*interface
;
1942 printk(KERN_ERR
"ULP_STOP\n");
1944 mutex_lock(&bnx2fc_dev_lock
);
1945 if (!test_bit(BNX2FC_FLAG_FW_INIT_DONE
, &hba
->flags
))
1947 list_for_each_entry(interface
, &if_list
, list
) {
1948 if (interface
->hba
== hba
)
1949 bnx2fc_stop(interface
);
1951 BUG_ON(hba
->num_ofld_sess
!= 0);
1953 mutex_lock(&hba
->hba_mutex
);
1954 clear_bit(ADAPTER_STATE_UP
, &hba
->adapter_state
);
1955 clear_bit(ADAPTER_STATE_GOING_DOWN
,
1956 &hba
->adapter_state
);
1958 clear_bit(ADAPTER_STATE_READY
, &hba
->adapter_state
);
1959 mutex_unlock(&hba
->hba_mutex
);
1961 bnx2fc_fw_destroy(hba
);
1963 mutex_unlock(&bnx2fc_dev_lock
);
1966 static void bnx2fc_start_disc(struct bnx2fc_interface
*interface
)
1968 struct fcoe_ctlr
*ctlr
= bnx2fc_to_ctlr(interface
);
1969 struct fc_lport
*lport
;
1972 BNX2FC_MISC_DBG("Entered %s\n", __func__
);
1973 /* Kick off FIP/FLOGI */
1974 if (!test_bit(BNX2FC_FLAG_FW_INIT_DONE
, &interface
->hba
->flags
)) {
1975 printk(KERN_ERR PFX
"Init not done yet\n");
1980 BNX2FC_HBA_DBG(lport
, "calling fc_fabric_login\n");
1982 if (!bnx2fc_link_ok(lport
) && interface
->enabled
) {
1983 BNX2FC_HBA_DBG(lport
, "ctlr_link_up\n");
1984 fcoe_ctlr_link_up(ctlr
);
1985 fc_host_port_type(lport
->host
) = FC_PORTTYPE_NPORT
;
1986 set_bit(ADAPTER_STATE_READY
, &interface
->hba
->adapter_state
);
1989 /* wait for the FCF to be selected before issuing FLOGI */
1990 while (!ctlr
->sel_fcf
) {
1992 /* give up after 3 secs */
1993 if (++wait_cnt
> 12)
1997 /* Reset max receive frame size to default */
1998 if (fc_set_mfs(lport
, BNX2FC_MFS
))
2001 fc_lport_init(lport
);
2002 fc_fabric_login(lport
);
2007 * bnx2fc_ulp_init - Initialize an adapter instance
2009 * @dev : cnic device handle
2010 * Called from cnic_register_driver() context to initialize all
2011 * enumerated cnic devices. This routine allocates adapter structure
2012 * and other device specific resources.
2014 static void bnx2fc_ulp_init(struct cnic_dev
*dev
)
2016 struct bnx2fc_hba
*hba
;
2019 BNX2FC_MISC_DBG("Entered %s\n", __func__
);
2020 /* bnx2fc works only when bnx2x is loaded */
2021 if (!test_bit(CNIC_F_BNX2X_CLASS
, &dev
->flags
) ||
2022 (dev
->max_fcoe_conn
== 0)) {
2023 printk(KERN_ERR PFX
"bnx2fc FCoE not supported on %s,"
2024 " flags: %lx fcoe_conn: %d\n",
2025 dev
->netdev
->name
, dev
->flags
, dev
->max_fcoe_conn
);
2029 hba
= bnx2fc_hba_create(dev
);
2031 printk(KERN_ERR PFX
"hba initialization failed\n");
2035 pr_info(PFX
"FCoE initialized for %s.\n", dev
->netdev
->name
);
2037 /* Add HBA to the adapter list */
2038 mutex_lock(&bnx2fc_dev_lock
);
2039 list_add_tail(&hba
->list
, &adapter_list
);
2041 mutex_unlock(&bnx2fc_dev_lock
);
2043 dev
->fcoe_cap
= &hba
->fcoe_cap
;
2044 clear_bit(BNX2FC_CNIC_REGISTERED
, &hba
->reg_with_cnic
);
2045 rc
= dev
->register_device(dev
, CNIC_ULP_FCOE
,
2048 printk(KERN_ERR PFX
"register_device failed, rc = %d\n", rc
);
2050 set_bit(BNX2FC_CNIC_REGISTERED
, &hba
->reg_with_cnic
);
2053 /* Assumes rtnl_lock and the bnx2fc_dev_lock are already taken */
2054 static int __bnx2fc_disable(struct fcoe_ctlr
*ctlr
)
2056 struct bnx2fc_interface
*interface
= fcoe_ctlr_priv(ctlr
);
2058 if (interface
->enabled
== true) {
2060 pr_err(PFX
"__bnx2fc_disable: lport not found\n");
2063 interface
->enabled
= false;
2064 fcoe_ctlr_link_down(ctlr
);
2065 fcoe_clean_pending_queue(ctlr
->lp
);
2072 * Deperecated: Use bnx2fc_enabled()
2074 static int bnx2fc_disable(struct net_device
*netdev
)
2076 struct bnx2fc_interface
*interface
;
2077 struct fcoe_ctlr
*ctlr
;
2081 mutex_lock(&bnx2fc_dev_lock
);
2083 interface
= bnx2fc_interface_lookup(netdev
);
2084 ctlr
= bnx2fc_to_ctlr(interface
);
2088 pr_err(PFX
"bnx2fc_disable: interface not found\n");
2090 rc
= __bnx2fc_disable(ctlr
);
2092 mutex_unlock(&bnx2fc_dev_lock
);
2097 static uint
bnx2fc_npiv_create_vports(struct fc_lport
*lport
,
2098 struct cnic_fc_npiv_tbl
*npiv_tbl
)
2100 struct fc_vport_identifiers vpid
;
2101 uint i
, created
= 0;
2103 if (npiv_tbl
->count
> MAX_NPIV_ENTRIES
) {
2104 BNX2FC_HBA_DBG(lport
, "Exceeded count max of npiv table\n");
2108 /* Sanity check the first entry to make sure it's not 0 */
2109 if (wwn_to_u64(npiv_tbl
->wwnn
[0]) == 0 &&
2110 wwn_to_u64(npiv_tbl
->wwpn
[0]) == 0) {
2111 BNX2FC_HBA_DBG(lport
, "First NPIV table entries invalid.\n");
2115 vpid
.roles
= FC_PORT_ROLE_FCP_INITIATOR
;
2116 vpid
.vport_type
= FC_PORTTYPE_NPIV
;
2117 vpid
.disable
= false;
2119 for (i
= 0; i
< npiv_tbl
->count
; i
++) {
2120 vpid
.node_name
= wwn_to_u64(npiv_tbl
->wwnn
[i
]);
2121 vpid
.port_name
= wwn_to_u64(npiv_tbl
->wwpn
[i
]);
2122 scnprintf(vpid
.symbolic_name
, sizeof(vpid
.symbolic_name
),
2123 "NPIV[%u]:%016llx-%016llx",
2124 created
, vpid
.port_name
, vpid
.node_name
);
2125 if (fc_vport_create(lport
->host
, 0, &vpid
))
2128 BNX2FC_HBA_DBG(lport
, "Failed to create vport\n");
2134 static int __bnx2fc_enable(struct fcoe_ctlr
*ctlr
)
2136 struct bnx2fc_interface
*interface
= fcoe_ctlr_priv(ctlr
);
2137 struct bnx2fc_hba
*hba
;
2138 struct cnic_fc_npiv_tbl
*npiv_tbl
;
2139 struct fc_lport
*lport
;
2141 if (interface
->enabled
== false) {
2143 pr_err(PFX
"__bnx2fc_enable: lport not found\n");
2145 } else if (!bnx2fc_link_ok(ctlr
->lp
)) {
2146 fcoe_ctlr_link_up(ctlr
);
2147 interface
->enabled
= true;
2151 /* Create static NPIV ports if any are contained in NVRAM */
2152 hba
= interface
->hba
;
2167 if (!hba
->cnic
->get_fc_npiv_tbl
)
2170 npiv_tbl
= kzalloc(sizeof(struct cnic_fc_npiv_tbl
), GFP_KERNEL
);
2174 if (hba
->cnic
->get_fc_npiv_tbl(hba
->cnic
, npiv_tbl
))
2177 bnx2fc_npiv_create_vports(lport
, npiv_tbl
);
2185 * Deprecated: Use bnx2fc_enabled()
2187 static int bnx2fc_enable(struct net_device
*netdev
)
2189 struct bnx2fc_interface
*interface
;
2190 struct fcoe_ctlr
*ctlr
;
2194 mutex_lock(&bnx2fc_dev_lock
);
2196 interface
= bnx2fc_interface_lookup(netdev
);
2197 ctlr
= bnx2fc_to_ctlr(interface
);
2200 pr_err(PFX
"bnx2fc_enable: interface not found\n");
2202 rc
= __bnx2fc_enable(ctlr
);
2205 mutex_unlock(&bnx2fc_dev_lock
);
2211 * bnx2fc_ctlr_enabled() - Enable or disable an FCoE Controller
2212 * @cdev: The FCoE Controller that is being enabled or disabled
2214 * fcoe_sysfs will ensure that the state of 'enabled' has
2215 * changed, so no checking is necessary here. This routine simply
2216 * calls fcoe_enable or fcoe_disable, both of which are deprecated.
2217 * When those routines are removed the functionality can be merged
2220 static int bnx2fc_ctlr_enabled(struct fcoe_ctlr_device
*cdev
)
2222 struct fcoe_ctlr
*ctlr
= fcoe_ctlr_device_priv(cdev
);
2224 switch (cdev
->enabled
) {
2225 case FCOE_CTLR_ENABLED
:
2226 return __bnx2fc_enable(ctlr
);
2227 case FCOE_CTLR_DISABLED
:
2228 return __bnx2fc_disable(ctlr
);
2229 case FCOE_CTLR_UNUSED
:
2235 enum bnx2fc_create_link_state
{
2236 BNX2FC_CREATE_LINK_DOWN
,
2237 BNX2FC_CREATE_LINK_UP
,
2241 * _bnx2fc_create() - Create bnx2fc FCoE interface
2242 * @netdev : The net_device object the Ethernet interface to create on
2243 * @fip_mode: The FIP mode for this creation
2244 * @link_state: The ctlr link state on creation
2246 * Called from either the libfcoe 'create' module parameter
2247 * via fcoe_create or from fcoe_syfs's ctlr_create file.
2249 * libfcoe's 'create' module parameter is deprecated so some
2250 * consolidation of code can be done when that interface is
2253 * Returns: 0 for success
2255 static int _bnx2fc_create(struct net_device
*netdev
,
2256 enum fip_mode fip_mode
,
2257 enum bnx2fc_create_link_state link_state
)
2259 struct fcoe_ctlr_device
*cdev
;
2260 struct fcoe_ctlr
*ctlr
;
2261 struct bnx2fc_interface
*interface
;
2262 struct bnx2fc_hba
*hba
;
2263 struct net_device
*phys_dev
= netdev
;
2264 struct fc_lport
*lport
;
2265 struct ethtool_drvinfo drvinfo
;
2269 BNX2FC_MISC_DBG("Entered bnx2fc_create\n");
2270 if (fip_mode
!= FIP_MODE_FABRIC
) {
2271 printk(KERN_ERR
"fip mode not FABRIC\n");
2277 mutex_lock(&bnx2fc_dev_lock
);
2279 if (!try_module_get(THIS_MODULE
)) {
2284 /* obtain physical netdev */
2285 if (netdev
->priv_flags
& IFF_802_1Q_VLAN
)
2286 phys_dev
= vlan_dev_real_dev(netdev
);
2288 /* verify if the physical device is a netxtreme2 device */
2289 if (phys_dev
->ethtool_ops
&& phys_dev
->ethtool_ops
->get_drvinfo
) {
2290 memset(&drvinfo
, 0, sizeof(drvinfo
));
2291 phys_dev
->ethtool_ops
->get_drvinfo(phys_dev
, &drvinfo
);
2292 if (strncmp(drvinfo
.driver
, "bnx2x", strlen("bnx2x"))) {
2293 printk(KERN_ERR PFX
"Not a netxtreme2 device\n");
2298 printk(KERN_ERR PFX
"unable to obtain drv_info\n");
2303 /* obtain interface and initialize rest of the structure */
2304 hba
= bnx2fc_hba_lookup(phys_dev
);
2307 printk(KERN_ERR PFX
"bnx2fc_create: hba not found\n");
2311 if (bnx2fc_interface_lookup(netdev
)) {
2316 interface
= bnx2fc_interface_create(hba
, netdev
, fip_mode
);
2318 printk(KERN_ERR PFX
"bnx2fc_interface_create failed\n");
2323 if (netdev
->priv_flags
& IFF_802_1Q_VLAN
) {
2324 vlan_id
= vlan_dev_vlan_id(netdev
);
2325 interface
->vlan_enabled
= 1;
2328 ctlr
= bnx2fc_to_ctlr(interface
);
2329 cdev
= fcoe_ctlr_to_ctlr_dev(ctlr
);
2330 interface
->vlan_id
= vlan_id
;
2331 interface
->tm_timeout
= BNX2FC_TM_TIMEOUT
;
2333 interface
->timer_work_queue
=
2334 create_singlethread_workqueue("bnx2fc_timer_wq");
2335 if (!interface
->timer_work_queue
) {
2336 printk(KERN_ERR PFX
"ulp_init could not create timer_wq\n");
2341 lport
= bnx2fc_if_create(interface
, &cdev
->dev
, 0);
2343 printk(KERN_ERR PFX
"Failed to create interface (%s)\n",
2349 /* Add interface to if_list */
2350 list_add_tail(&interface
->list
, &if_list
);
2352 lport
->boot_time
= jiffies
;
2354 /* Make this master N_port */
2357 if (link_state
== BNX2FC_CREATE_LINK_UP
)
2358 cdev
->enabled
= FCOE_CTLR_ENABLED
;
2360 cdev
->enabled
= FCOE_CTLR_DISABLED
;
2362 if (link_state
== BNX2FC_CREATE_LINK_UP
&&
2363 !bnx2fc_link_ok(lport
)) {
2364 fcoe_ctlr_link_up(ctlr
);
2365 fc_host_port_type(lport
->host
) = FC_PORTTYPE_NPORT
;
2366 set_bit(ADAPTER_STATE_READY
, &interface
->hba
->adapter_state
);
2369 BNX2FC_HBA_DBG(lport
, "create: START DISC\n");
2370 bnx2fc_start_disc(interface
);
2372 if (link_state
== BNX2FC_CREATE_LINK_UP
)
2373 interface
->enabled
= true;
2376 * Release from kref_init in bnx2fc_interface_setup, on success
2377 * lport should be holding a reference taken in bnx2fc_if_create
2379 bnx2fc_interface_put(interface
);
2380 /* put netdev that was held while calling dev_get_by_name */
2381 mutex_unlock(&bnx2fc_dev_lock
);
2386 destroy_workqueue(interface
->timer_work_queue
);
2388 bnx2fc_net_cleanup(interface
);
2389 bnx2fc_interface_put(interface
);
2392 module_put(THIS_MODULE
);
2394 mutex_unlock(&bnx2fc_dev_lock
);
2400 * bnx2fc_create() - Create a bnx2fc interface
2401 * @netdev : The net_device object the Ethernet interface to create on
2402 * @fip_mode: The FIP mode for this creation
2404 * Called from fcoe transport
2406 * Returns: 0 for success
2408 static int bnx2fc_create(struct net_device
*netdev
, enum fip_mode fip_mode
)
2410 return _bnx2fc_create(netdev
, fip_mode
, BNX2FC_CREATE_LINK_UP
);
2414 * bnx2fc_ctlr_alloc() - Allocate a bnx2fc interface from fcoe_sysfs
2415 * @netdev: The net_device to be used by the allocated FCoE Controller
2417 * This routine is called from fcoe_sysfs. It will start the fcoe_ctlr
2418 * in a link_down state. The allows the user an opportunity to configure
2419 * the FCoE Controller from sysfs before enabling the FCoE Controller.
2421 * Creating in with this routine starts the FCoE Controller in Fabric
2422 * mode. The user can change to VN2VN or another mode before enabling.
2424 static int bnx2fc_ctlr_alloc(struct net_device
*netdev
)
2426 return _bnx2fc_create(netdev
, FIP_MODE_FABRIC
,
2427 BNX2FC_CREATE_LINK_DOWN
);
2431 * bnx2fc_find_hba_for_cnic - maps cnic instance to bnx2fc hba instance
2433 * @cnic: Pointer to cnic device instance
2436 static struct bnx2fc_hba
*bnx2fc_find_hba_for_cnic(struct cnic_dev
*cnic
)
2438 struct bnx2fc_hba
*hba
;
2440 /* Called with bnx2fc_dev_lock held */
2441 list_for_each_entry(hba
, &adapter_list
, list
) {
2442 if (hba
->cnic
== cnic
)
2448 static struct bnx2fc_interface
*bnx2fc_interface_lookup(struct net_device
2451 struct bnx2fc_interface
*interface
;
2453 /* Called with bnx2fc_dev_lock held */
2454 list_for_each_entry(interface
, &if_list
, list
) {
2455 if (interface
->netdev
== netdev
)
2461 static struct bnx2fc_hba
*bnx2fc_hba_lookup(struct net_device
2464 struct bnx2fc_hba
*hba
;
2466 /* Called with bnx2fc_dev_lock held */
2467 list_for_each_entry(hba
, &adapter_list
, list
) {
2468 if (hba
->phys_dev
== phys_dev
)
2471 printk(KERN_ERR PFX
"adapter_lookup: hba NULL\n");
2476 * bnx2fc_ulp_exit - shuts down adapter instance and frees all resources
2478 * @dev cnic device handle
2480 static void bnx2fc_ulp_exit(struct cnic_dev
*dev
)
2482 struct bnx2fc_hba
*hba
;
2483 struct bnx2fc_interface
*interface
, *tmp
;
2485 BNX2FC_MISC_DBG("Entered bnx2fc_ulp_exit\n");
2487 if (!test_bit(CNIC_F_BNX2X_CLASS
, &dev
->flags
)) {
2488 printk(KERN_ERR PFX
"bnx2fc port check: %s, flags: %lx\n",
2489 dev
->netdev
->name
, dev
->flags
);
2493 mutex_lock(&bnx2fc_dev_lock
);
2494 hba
= bnx2fc_find_hba_for_cnic(dev
);
2496 printk(KERN_ERR PFX
"bnx2fc_ulp_exit: hba not found, dev 0%p\n",
2498 mutex_unlock(&bnx2fc_dev_lock
);
2502 list_del_init(&hba
->list
);
2505 list_for_each_entry_safe(interface
, tmp
, &if_list
, list
)
2506 /* destroy not called yet, move to quiesced list */
2507 if (interface
->hba
== hba
)
2508 __bnx2fc_destroy(interface
);
2509 mutex_unlock(&bnx2fc_dev_lock
);
2511 /* Ensure ALL destroy work has been completed before return */
2512 flush_workqueue(bnx2fc_wq
);
2514 bnx2fc_ulp_stop(hba
);
2515 /* unregister cnic device */
2516 if (test_and_clear_bit(BNX2FC_CNIC_REGISTERED
, &hba
->reg_with_cnic
))
2517 hba
->cnic
->unregister_device(hba
->cnic
, CNIC_ULP_FCOE
);
2518 bnx2fc_hba_destroy(hba
);
2522 * bnx2fc_fcoe_reset - Resets the fcoe
2524 * @shost: shost the reset is from
2528 static int bnx2fc_fcoe_reset(struct Scsi_Host
*shost
)
2530 struct fc_lport
*lport
= shost_priv(shost
);
2531 fc_lport_reset(lport
);
2536 static bool bnx2fc_match(struct net_device
*netdev
)
2538 struct net_device
*phys_dev
= netdev
;
2540 mutex_lock(&bnx2fc_dev_lock
);
2541 if (netdev
->priv_flags
& IFF_802_1Q_VLAN
)
2542 phys_dev
= vlan_dev_real_dev(netdev
);
2544 if (bnx2fc_hba_lookup(phys_dev
)) {
2545 mutex_unlock(&bnx2fc_dev_lock
);
2549 mutex_unlock(&bnx2fc_dev_lock
);
2554 static struct fcoe_transport bnx2fc_transport
= {
2557 .list
= LIST_HEAD_INIT(bnx2fc_transport
.list
),
2558 .alloc
= bnx2fc_ctlr_alloc
,
2559 .match
= bnx2fc_match
,
2560 .create
= bnx2fc_create
,
2561 .destroy
= bnx2fc_destroy
,
2562 .enable
= bnx2fc_enable
,
2563 .disable
= bnx2fc_disable
,
2567 * bnx2fc_percpu_thread_create - Create a receive thread for an
2570 * @cpu: cpu index for the online cpu
2572 static void bnx2fc_percpu_thread_create(unsigned int cpu
)
2574 struct bnx2fc_percpu_s
*p
;
2575 struct task_struct
*thread
;
2577 p
= &per_cpu(bnx2fc_percpu
, cpu
);
2579 thread
= kthread_create_on_node(bnx2fc_percpu_io_thread
,
2580 (void *)p
, cpu_to_node(cpu
),
2581 "bnx2fc_thread/%d", cpu
);
2582 /* bind thread to the cpu */
2583 if (likely(!IS_ERR(thread
))) {
2584 kthread_bind(thread
, cpu
);
2585 p
->iothread
= thread
;
2586 wake_up_process(thread
);
2590 static void bnx2fc_percpu_thread_destroy(unsigned int cpu
)
2592 struct bnx2fc_percpu_s
*p
;
2593 struct task_struct
*thread
;
2594 struct bnx2fc_work
*work
, *tmp
;
2596 BNX2FC_MISC_DBG("destroying io thread for CPU %d\n", cpu
);
2598 /* Prevent any new work from being queued for this CPU */
2599 p
= &per_cpu(bnx2fc_percpu
, cpu
);
2600 spin_lock_bh(&p
->fp_work_lock
);
2601 thread
= p
->iothread
;
2605 /* Free all work in the list */
2606 list_for_each_entry_safe(work
, tmp
, &p
->work_list
, list
) {
2607 list_del_init(&work
->list
);
2608 bnx2fc_process_cq_compl(work
->tgt
, work
->wqe
);
2612 spin_unlock_bh(&p
->fp_work_lock
);
2615 kthread_stop(thread
);
2619 static int bnx2fc_cpu_online(unsigned int cpu
)
2621 printk(PFX
"CPU %x online: Create Rx thread\n", cpu
);
2622 bnx2fc_percpu_thread_create(cpu
);
2626 static int bnx2fc_cpu_dead(unsigned int cpu
)
2628 printk(PFX
"CPU %x offline: Remove Rx thread\n", cpu
);
2629 bnx2fc_percpu_thread_destroy(cpu
);
2633 static int bnx2fc_slave_configure(struct scsi_device
*sdev
)
2635 if (!bnx2fc_queue_depth
)
2638 scsi_change_queue_depth(sdev
, bnx2fc_queue_depth
);
2642 static enum cpuhp_state bnx2fc_online_state
;
2645 * bnx2fc_mod_init - module init entry point
2647 * Initialize driver wide global data structures, and register
2650 static int __init
bnx2fc_mod_init(void)
2652 struct fcoe_percpu_s
*bg
;
2653 struct task_struct
*l2_thread
;
2655 unsigned int cpu
= 0;
2656 struct bnx2fc_percpu_s
*p
;
2658 printk(KERN_INFO PFX
"%s", version
);
2660 /* register as a fcoe transport */
2661 rc
= fcoe_transport_attach(&bnx2fc_transport
);
2663 printk(KERN_ERR
"failed to register an fcoe transport, check "
2664 "if libfcoe is loaded\n");
2668 INIT_LIST_HEAD(&adapter_list
);
2669 INIT_LIST_HEAD(&if_list
);
2670 mutex_init(&bnx2fc_dev_lock
);
2673 /* Attach FC transport template */
2674 rc
= bnx2fc_attach_transport();
2678 bnx2fc_wq
= alloc_workqueue("bnx2fc", 0, 0);
2684 bg
= &bnx2fc_global
;
2685 skb_queue_head_init(&bg
->fcoe_rx_list
);
2686 l2_thread
= kthread_create(bnx2fc_l2_rcv_thread
,
2688 "bnx2fc_l2_thread");
2689 if (IS_ERR(l2_thread
)) {
2690 rc
= PTR_ERR(l2_thread
);
2693 wake_up_process(l2_thread
);
2694 spin_lock_bh(&bg
->fcoe_rx_list
.lock
);
2695 bg
->kthread
= l2_thread
;
2696 spin_unlock_bh(&bg
->fcoe_rx_list
.lock
);
2698 for_each_possible_cpu(cpu
) {
2699 p
= &per_cpu(bnx2fc_percpu
, cpu
);
2700 INIT_LIST_HEAD(&p
->work_list
);
2701 spin_lock_init(&p
->fp_work_lock
);
2706 for_each_online_cpu(cpu
)
2707 bnx2fc_percpu_thread_create(cpu
);
2709 rc
= cpuhp_setup_state_nocalls(CPUHP_AP_ONLINE_DYN
,
2710 "scsi/bnx2fc:online",
2711 bnx2fc_cpu_online
, NULL
);
2714 bnx2fc_online_state
= rc
;
2716 cpuhp_setup_state_nocalls(CPUHP_SCSI_BNX2FC_DEAD
, "scsi/bnx2fc:dead",
2717 NULL
, bnx2fc_cpu_dead
);
2720 cnic_register_driver(CNIC_ULP_FCOE
, &bnx2fc_cnic_cb
);
2725 for_each_online_cpu(cpu
)
2726 bnx2fc_percpu_thread_destroy(cpu
);
2728 kthread_stop(l2_thread
);
2730 destroy_workqueue(bnx2fc_wq
);
2732 bnx2fc_release_transport();
2734 fcoe_transport_detach(&bnx2fc_transport
);
2739 static void __exit
bnx2fc_mod_exit(void)
2741 LIST_HEAD(to_be_deleted
);
2742 struct bnx2fc_hba
*hba
, *next
;
2743 struct fcoe_percpu_s
*bg
;
2744 struct task_struct
*l2_thread
;
2745 struct sk_buff
*skb
;
2746 unsigned int cpu
= 0;
2749 * NOTE: Since cnic calls register_driver routine rtnl_lock,
2750 * it will have higher precedence than bnx2fc_dev_lock.
2751 * unregister_device() cannot be called with bnx2fc_dev_lock
2754 mutex_lock(&bnx2fc_dev_lock
);
2755 list_splice_init(&adapter_list
, &to_be_deleted
);
2757 mutex_unlock(&bnx2fc_dev_lock
);
2759 /* Unregister with cnic */
2760 list_for_each_entry_safe(hba
, next
, &to_be_deleted
, list
) {
2761 list_del_init(&hba
->list
);
2762 printk(KERN_ERR PFX
"MOD_EXIT:destroy hba = 0x%p\n",
2764 bnx2fc_ulp_stop(hba
);
2765 /* unregister cnic device */
2766 if (test_and_clear_bit(BNX2FC_CNIC_REGISTERED
,
2767 &hba
->reg_with_cnic
))
2768 hba
->cnic
->unregister_device(hba
->cnic
,
2770 bnx2fc_hba_destroy(hba
);
2772 cnic_unregister_driver(CNIC_ULP_FCOE
);
2774 /* Destroy global thread */
2775 bg
= &bnx2fc_global
;
2776 spin_lock_bh(&bg
->fcoe_rx_list
.lock
);
2777 l2_thread
= bg
->kthread
;
2779 while ((skb
= __skb_dequeue(&bg
->fcoe_rx_list
)) != NULL
)
2782 spin_unlock_bh(&bg
->fcoe_rx_list
.lock
);
2785 kthread_stop(l2_thread
);
2788 /* Destroy per cpu threads */
2789 for_each_online_cpu(cpu
) {
2790 bnx2fc_percpu_thread_destroy(cpu
);
2793 cpuhp_remove_state_nocalls(bnx2fc_online_state
);
2794 cpuhp_remove_state_nocalls(CPUHP_SCSI_BNX2FC_DEAD
);
2798 destroy_workqueue(bnx2fc_wq
);
2800 * detach from scsi transport
2801 * must happen after all destroys are done
2803 bnx2fc_release_transport();
2805 /* detach from fcoe transport */
2806 fcoe_transport_detach(&bnx2fc_transport
);
2809 module_init(bnx2fc_mod_init
);
2810 module_exit(bnx2fc_mod_exit
);
2812 static struct fcoe_sysfs_function_template bnx2fc_fcoe_sysfs_templ
= {
2813 .set_fcoe_ctlr_enabled
= bnx2fc_ctlr_enabled
,
2814 .get_fcoe_ctlr_link_fail
= fcoe_ctlr_get_lesb
,
2815 .get_fcoe_ctlr_vlink_fail
= fcoe_ctlr_get_lesb
,
2816 .get_fcoe_ctlr_miss_fka
= fcoe_ctlr_get_lesb
,
2817 .get_fcoe_ctlr_symb_err
= fcoe_ctlr_get_lesb
,
2818 .get_fcoe_ctlr_err_block
= fcoe_ctlr_get_lesb
,
2819 .get_fcoe_ctlr_fcs_error
= fcoe_ctlr_get_lesb
,
2821 .get_fcoe_fcf_selected
= fcoe_fcf_get_selected
,
2822 .get_fcoe_fcf_vlan_id
= bnx2fc_fcf_get_vlan_id
,
2825 static struct fc_function_template bnx2fc_transport_function
= {
2826 .show_host_node_name
= 1,
2827 .show_host_port_name
= 1,
2828 .show_host_supported_classes
= 1,
2829 .show_host_supported_fc4s
= 1,
2830 .show_host_active_fc4s
= 1,
2831 .show_host_maxframe_size
= 1,
2833 .show_host_port_id
= 1,
2834 .show_host_supported_speeds
= 1,
2835 .get_host_speed
= fc_get_host_speed
,
2836 .show_host_speed
= 1,
2837 .show_host_port_type
= 1,
2838 .get_host_port_state
= fc_get_host_port_state
,
2839 .show_host_port_state
= 1,
2840 .show_host_symbolic_name
= 1,
2842 .dd_fcrport_size
= (sizeof(struct fc_rport_libfc_priv
) +
2843 sizeof(struct bnx2fc_rport
)),
2844 .show_rport_maxframe_size
= 1,
2845 .show_rport_supported_classes
= 1,
2847 .show_host_fabric_name
= 1,
2848 .show_starget_node_name
= 1,
2849 .show_starget_port_name
= 1,
2850 .show_starget_port_id
= 1,
2851 .set_rport_dev_loss_tmo
= fc_set_rport_loss_tmo
,
2852 .show_rport_dev_loss_tmo
= 1,
2853 .get_fc_host_stats
= bnx2fc_get_host_stats
,
2855 .issue_fc_host_lip
= bnx2fc_fcoe_reset
,
2857 .terminate_rport_io
= fc_rport_terminate_io
,
2859 .vport_create
= bnx2fc_vport_create
,
2860 .vport_delete
= bnx2fc_vport_destroy
,
2861 .vport_disable
= bnx2fc_vport_disable
,
2862 .bsg_request
= fc_lport_bsg_request
,
2865 static struct fc_function_template bnx2fc_vport_xport_function
= {
2866 .show_host_node_name
= 1,
2867 .show_host_port_name
= 1,
2868 .show_host_supported_classes
= 1,
2869 .show_host_supported_fc4s
= 1,
2870 .show_host_active_fc4s
= 1,
2871 .show_host_maxframe_size
= 1,
2873 .show_host_port_id
= 1,
2874 .show_host_supported_speeds
= 1,
2875 .get_host_speed
= fc_get_host_speed
,
2876 .show_host_speed
= 1,
2877 .show_host_port_type
= 1,
2878 .get_host_port_state
= fc_get_host_port_state
,
2879 .show_host_port_state
= 1,
2880 .show_host_symbolic_name
= 1,
2882 .dd_fcrport_size
= (sizeof(struct fc_rport_libfc_priv
) +
2883 sizeof(struct bnx2fc_rport
)),
2884 .show_rport_maxframe_size
= 1,
2885 .show_rport_supported_classes
= 1,
2887 .show_host_fabric_name
= 1,
2888 .show_starget_node_name
= 1,
2889 .show_starget_port_name
= 1,
2890 .show_starget_port_id
= 1,
2891 .set_rport_dev_loss_tmo
= fc_set_rport_loss_tmo
,
2892 .show_rport_dev_loss_tmo
= 1,
2893 .get_fc_host_stats
= fc_get_host_stats
,
2894 .issue_fc_host_lip
= bnx2fc_fcoe_reset
,
2895 .terminate_rport_io
= fc_rport_terminate_io
,
2896 .bsg_request
= fc_lport_bsg_request
,
2900 * Additional scsi_host attributes.
2903 bnx2fc_tm_timeout_show(struct device
*dev
, struct device_attribute
*attr
,
2906 struct Scsi_Host
*shost
= class_to_shost(dev
);
2907 struct fc_lport
*lport
= shost_priv(shost
);
2908 struct fcoe_port
*port
= lport_priv(lport
);
2909 struct bnx2fc_interface
*interface
= port
->priv
;
2911 sprintf(buf
, "%u\n", interface
->tm_timeout
);
2916 bnx2fc_tm_timeout_store(struct device
*dev
,
2917 struct device_attribute
*attr
, const char *buf
, size_t count
)
2919 struct Scsi_Host
*shost
= class_to_shost(dev
);
2920 struct fc_lport
*lport
= shost_priv(shost
);
2921 struct fcoe_port
*port
= lport_priv(lport
);
2922 struct bnx2fc_interface
*interface
= port
->priv
;
2925 rval
= kstrtouint(buf
, 10, &val
);
2931 interface
->tm_timeout
= (u8
)val
;
2935 static DEVICE_ATTR(tm_timeout
, S_IRUGO
|S_IWUSR
, bnx2fc_tm_timeout_show
,
2936 bnx2fc_tm_timeout_store
);
2938 static struct device_attribute
*bnx2fc_host_attrs
[] = {
2939 &dev_attr_tm_timeout
,
2944 * scsi_host_template structure used while registering with SCSI-ml
2946 static struct scsi_host_template bnx2fc_shost_template
= {
2947 .module
= THIS_MODULE
,
2948 .name
= "QLogic Offload FCoE Initiator",
2949 .queuecommand
= bnx2fc_queuecommand
,
2950 .eh_timed_out
= fc_eh_timed_out
,
2951 .eh_abort_handler
= bnx2fc_eh_abort
, /* abts */
2952 .eh_device_reset_handler
= bnx2fc_eh_device_reset
, /* lun reset */
2953 .eh_target_reset_handler
= bnx2fc_eh_target_reset
, /* tgt reset */
2954 .eh_host_reset_handler
= fc_eh_host_reset
,
2955 .slave_alloc
= fc_slave_alloc
,
2956 .change_queue_depth
= scsi_change_queue_depth
,
2959 .use_clustering
= ENABLE_CLUSTERING
,
2960 .sg_tablesize
= BNX2FC_MAX_BDS_PER_CMD
,
2961 .max_sectors
= 1024,
2962 .track_queue_depth
= 1,
2963 .slave_configure
= bnx2fc_slave_configure
,
2964 .shost_attrs
= bnx2fc_host_attrs
,
2967 static struct libfc_function_template bnx2fc_libfc_fcn_templ
= {
2968 .frame_send
= bnx2fc_xmit
,
2969 .elsct_send
= bnx2fc_elsct_send
,
2970 .fcp_abort_io
= bnx2fc_abort_io
,
2971 .fcp_cleanup
= bnx2fc_cleanup
,
2972 .get_lesb
= fcoe_get_lesb
,
2973 .rport_event_callback
= bnx2fc_rport_event_handler
,
2977 * bnx2fc_cnic_cb - global template of bnx2fc - cnic driver interface
2978 * structure carrying callback function pointers
2980 static struct cnic_ulp_ops bnx2fc_cnic_cb
= {
2981 .owner
= THIS_MODULE
,
2982 .cnic_init
= bnx2fc_ulp_init
,
2983 .cnic_exit
= bnx2fc_ulp_exit
,
2984 .cnic_start
= bnx2fc_ulp_start
,
2985 .cnic_stop
= bnx2fc_ulp_stop
,
2986 .indicate_kcqes
= bnx2fc_indicate_kcqe
,
2987 .indicate_netevent
= bnx2fc_indicate_netevent
,
2988 .cnic_get_stats
= bnx2fc_ulp_get_stats
,