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_state 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
);
101 static int bnx2fc_cpu_callback(struct notifier_block
*nfb
,
102 unsigned long action
, void *hcpu
);
103 /* notification function for CPU hotplug events */
104 static struct notifier_block bnx2fc_cpu_notifier
= {
105 .notifier_call
= bnx2fc_cpu_callback
,
108 static inline struct net_device
*bnx2fc_netdev(const struct fc_lport
*lport
)
110 return ((struct bnx2fc_interface
*)
111 ((struct fcoe_port
*)lport_priv(lport
))->priv
)->netdev
;
114 static void bnx2fc_fcf_get_vlan_id(struct fcoe_fcf_device
*fcf_dev
)
116 struct fcoe_ctlr_device
*ctlr_dev
=
117 fcoe_fcf_dev_to_ctlr_dev(fcf_dev
);
118 struct fcoe_ctlr
*ctlr
= fcoe_ctlr_device_priv(ctlr_dev
);
119 struct bnx2fc_interface
*fcoe
= fcoe_ctlr_priv(ctlr
);
121 fcf_dev
->vlan_id
= fcoe
->vlan_id
;
124 static void bnx2fc_clean_rx_queue(struct fc_lport
*lp
)
126 struct fcoe_percpu_s
*bg
;
127 struct fcoe_rcv_info
*fr
;
128 struct sk_buff_head
*list
;
129 struct sk_buff
*skb
, *next
;
130 struct sk_buff
*head
;
133 spin_lock_bh(&bg
->fcoe_rx_list
.lock
);
134 list
= &bg
->fcoe_rx_list
;
136 for (skb
= head
; skb
!= (struct sk_buff
*)list
;
139 fr
= fcoe_dev_from_skb(skb
);
140 if (fr
->fr_dev
== lp
) {
141 __skb_unlink(skb
, list
);
145 spin_unlock_bh(&bg
->fcoe_rx_list
.lock
);
148 int bnx2fc_get_paged_crc_eof(struct sk_buff
*skb
, int tlen
)
151 spin_lock(&bnx2fc_global_lock
);
152 rc
= fcoe_get_paged_crc_eof(skb
, tlen
, &bnx2fc_global
);
153 spin_unlock(&bnx2fc_global_lock
);
158 static void bnx2fc_abort_io(struct fc_lport
*lport
)
161 * This function is no-op for bnx2fc, but we do
162 * not want to leave it as NULL either, as libfc
163 * can call the default function which is
168 static void bnx2fc_cleanup(struct fc_lport
*lport
)
170 struct fcoe_port
*port
= lport_priv(lport
);
171 struct bnx2fc_interface
*interface
= port
->priv
;
172 struct bnx2fc_hba
*hba
= interface
->hba
;
173 struct bnx2fc_rport
*tgt
;
176 BNX2FC_MISC_DBG("Entered %s\n", __func__
);
177 mutex_lock(&hba
->hba_mutex
);
178 spin_lock_bh(&hba
->hba_lock
);
179 for (i
= 0; i
< BNX2FC_NUM_MAX_SESS
; i
++) {
180 tgt
= hba
->tgt_ofld_list
[i
];
182 /* Cleanup IOs belonging to requested vport */
183 if (tgt
->port
== port
) {
184 spin_unlock_bh(&hba
->hba_lock
);
185 BNX2FC_TGT_DBG(tgt
, "flush/cleanup\n");
186 bnx2fc_flush_active_ios(tgt
);
187 spin_lock_bh(&hba
->hba_lock
);
191 spin_unlock_bh(&hba
->hba_lock
);
192 mutex_unlock(&hba
->hba_mutex
);
195 static int bnx2fc_xmit_l2_frame(struct bnx2fc_rport
*tgt
,
198 struct fc_rport_priv
*rdata
= tgt
->rdata
;
199 struct fc_frame_header
*fh
;
202 fh
= fc_frame_header_get(fp
);
203 BNX2FC_TGT_DBG(tgt
, "Xmit L2 frame rport = 0x%x, oxid = 0x%x, "
204 "r_ctl = 0x%x\n", rdata
->ids
.port_id
,
205 ntohs(fh
->fh_ox_id
), fh
->fh_r_ctl
);
206 if ((fh
->fh_type
== FC_TYPE_ELS
) &&
207 (fh
->fh_r_ctl
== FC_RCTL_ELS_REQ
)) {
209 switch (fc_frame_payload_op(fp
)) {
211 rc
= bnx2fc_send_adisc(tgt
, fp
);
214 rc
= bnx2fc_send_logo(tgt
, fp
);
217 rc
= bnx2fc_send_rls(tgt
, fp
);
222 } else if ((fh
->fh_type
== FC_TYPE_BLS
) &&
223 (fh
->fh_r_ctl
== FC_RCTL_BA_ABTS
))
224 BNX2FC_TGT_DBG(tgt
, "ABTS frame\n");
226 BNX2FC_TGT_DBG(tgt
, "Send L2 frame type 0x%x "
227 "rctl 0x%x thru non-offload path\n",
228 fh
->fh_type
, fh
->fh_r_ctl
);
238 * bnx2fc_xmit - bnx2fc's FCoE frame transmit function
240 * @lport: the associated local port
241 * @fp: the fc_frame to be transmitted
243 static int bnx2fc_xmit(struct fc_lport
*lport
, struct fc_frame
*fp
)
246 struct fcoe_crc_eof
*cp
;
248 struct fc_frame_header
*fh
;
249 struct bnx2fc_interface
*interface
;
250 struct fcoe_ctlr
*ctlr
;
251 struct bnx2fc_hba
*hba
;
252 struct fcoe_port
*port
;
254 struct bnx2fc_rport
*tgt
;
255 struct fc_stats
*stats
;
258 unsigned int hlen
, tlen
, elen
;
261 port
= (struct fcoe_port
*)lport_priv(lport
);
262 interface
= port
->priv
;
263 ctlr
= bnx2fc_to_ctlr(interface
);
264 hba
= interface
->hba
;
266 fh
= fc_frame_header_get(fp
);
269 if (!lport
->link_up
) {
270 BNX2FC_HBA_DBG(lport
, "bnx2fc_xmit link down\n");
275 if (unlikely(fh
->fh_r_ctl
== FC_RCTL_ELS_REQ
)) {
276 if (!ctlr
->sel_fcf
) {
277 BNX2FC_HBA_DBG(lport
, "FCF not selected yet!\n");
281 if (fcoe_ctlr_els_send(ctlr
, lport
, skb
))
289 * Snoop the frame header to check if the frame is for
290 * an offloaded session
293 * tgt_ofld_list access is synchronized using
294 * both hba mutex and hba lock. Atleast hba mutex or
295 * hba lock needs to be held for read access.
298 spin_lock_bh(&hba
->hba_lock
);
299 tgt
= bnx2fc_tgt_lookup(port
, ntoh24(fh
->fh_d_id
));
300 if (tgt
&& (test_bit(BNX2FC_FLAG_SESSION_READY
, &tgt
->flags
))) {
301 /* This frame is for offloaded session */
302 BNX2FC_HBA_DBG(lport
, "xmit: Frame is for offloaded session "
303 "port_id = 0x%x\n", ntoh24(fh
->fh_d_id
));
304 spin_unlock_bh(&hba
->hba_lock
);
305 rc
= bnx2fc_xmit_l2_frame(tgt
, fp
);
311 spin_unlock_bh(&hba
->hba_lock
);
314 elen
= sizeof(struct ethhdr
);
315 hlen
= sizeof(struct fcoe_hdr
);
316 tlen
= sizeof(struct fcoe_crc_eof
);
317 wlen
= (skb
->len
- tlen
+ sizeof(crc
)) / FCOE_WORD_TO_BYTE
;
319 skb
->ip_summed
= CHECKSUM_NONE
;
320 crc
= fcoe_fc_crc(fp
);
322 /* copy port crc and eof to the skb buff */
323 if (skb_is_nonlinear(skb
)) {
325 if (bnx2fc_get_paged_crc_eof(skb
, tlen
)) {
329 frag
= &skb_shinfo(skb
)->frags
[skb_shinfo(skb
)->nr_frags
- 1];
330 cp
= kmap_atomic(skb_frag_page(frag
)) + frag
->page_offset
;
332 cp
= (struct fcoe_crc_eof
*)skb_put(skb
, tlen
);
335 memset(cp
, 0, sizeof(*cp
));
337 cp
->fcoe_crc32
= cpu_to_le32(~crc
);
338 if (skb_is_nonlinear(skb
)) {
343 /* adjust skb network/transport offsets to match mac/fcoe/port */
344 skb_push(skb
, elen
+ hlen
);
345 skb_reset_mac_header(skb
);
346 skb_reset_network_header(skb
);
348 skb
->protocol
= htons(ETH_P_FCOE
);
349 skb
->dev
= interface
->netdev
;
351 /* fill up mac and fcoe headers */
353 eh
->h_proto
= htons(ETH_P_FCOE
);
355 fc_fcoe_set_mac(eh
->h_dest
, fh
->fh_d_id
);
357 /* insert GW address */
358 memcpy(eh
->h_dest
, ctlr
->dest_addr
, ETH_ALEN
);
360 if (unlikely(ctlr
->flogi_oxid
!= FC_XID_UNKNOWN
))
361 memcpy(eh
->h_source
, ctlr
->ctl_src_addr
, ETH_ALEN
);
363 memcpy(eh
->h_source
, port
->data_src_addr
, ETH_ALEN
);
365 hp
= (struct fcoe_hdr
*)(eh
+ 1);
366 memset(hp
, 0, sizeof(*hp
));
368 FC_FCOE_ENCAPS_VER(hp
, FC_FCOE_VER
);
371 /* fcoe lso, mss is in max_payload which is non-zero for FCP data */
372 if (lport
->seq_offload
&& fr_max_payload(fp
)) {
373 skb_shinfo(skb
)->gso_type
= SKB_GSO_FCOE
;
374 skb_shinfo(skb
)->gso_size
= fr_max_payload(fp
);
376 skb_shinfo(skb
)->gso_type
= 0;
377 skb_shinfo(skb
)->gso_size
= 0;
381 stats
= per_cpu_ptr(lport
->stats
, get_cpu());
383 stats
->TxWords
+= wlen
;
386 /* send down to lld */
388 if (port
->fcoe_pending_queue
.qlen
)
389 fcoe_check_wait_queue(lport
, skb
);
390 else if (fcoe_start_io(skb
))
391 fcoe_check_wait_queue(lport
, skb
);
397 * bnx2fc_rcv - This is bnx2fc's receive function called by NET_RX_SOFTIRQ
399 * @skb: the receive socket buffer
400 * @dev: associated net device
402 * @olddev: last device
404 * This function receives the packet and builds FC frame and passes it up
406 static int bnx2fc_rcv(struct sk_buff
*skb
, struct net_device
*dev
,
407 struct packet_type
*ptype
, struct net_device
*olddev
)
409 struct fc_lport
*lport
;
410 struct bnx2fc_interface
*interface
;
411 struct fcoe_ctlr
*ctlr
;
412 struct fc_frame_header
*fh
;
413 struct fcoe_rcv_info
*fr
;
414 struct fcoe_percpu_s
*bg
;
415 struct sk_buff
*tmp_skb
;
418 interface
= container_of(ptype
, struct bnx2fc_interface
,
420 ctlr
= bnx2fc_to_ctlr(interface
);
423 if (unlikely(lport
== NULL
)) {
424 printk(KERN_ERR PFX
"bnx2fc_rcv: lport is NULL\n");
428 tmp_skb
= skb_share_check(skb
, GFP_ATOMIC
);
434 if (unlikely(eth_hdr(skb
)->h_proto
!= htons(ETH_P_FCOE
))) {
435 printk(KERN_ERR PFX
"bnx2fc_rcv: Wrong FC type frame\n");
440 * Check for minimum frame length, and make sure required FCoE
441 * and FC headers are pulled into the linear data area.
443 if (unlikely((skb
->len
< FCOE_MIN_FRAME
) ||
444 !pskb_may_pull(skb
, FCOE_HEADER_LEN
)))
447 skb_set_transport_header(skb
, sizeof(struct fcoe_hdr
));
448 fh
= (struct fc_frame_header
*) skb_transport_header(skb
);
450 oxid
= ntohs(fh
->fh_ox_id
);
452 fr
= fcoe_dev_from_skb(skb
);
456 spin_lock(&bg
->fcoe_rx_list
.lock
);
458 __skb_queue_tail(&bg
->fcoe_rx_list
, skb
);
459 if (bg
->fcoe_rx_list
.qlen
== 1)
460 wake_up_process(bg
->thread
);
462 spin_unlock(&bg
->fcoe_rx_list
.lock
);
470 static int bnx2fc_l2_rcv_thread(void *arg
)
472 struct fcoe_percpu_s
*bg
= arg
;
475 set_user_nice(current
, MIN_NICE
);
476 set_current_state(TASK_INTERRUPTIBLE
);
477 while (!kthread_should_stop()) {
479 spin_lock_bh(&bg
->fcoe_rx_list
.lock
);
480 while ((skb
= __skb_dequeue(&bg
->fcoe_rx_list
)) != NULL
) {
481 spin_unlock_bh(&bg
->fcoe_rx_list
.lock
);
482 bnx2fc_recv_frame(skb
);
483 spin_lock_bh(&bg
->fcoe_rx_list
.lock
);
485 __set_current_state(TASK_INTERRUPTIBLE
);
486 spin_unlock_bh(&bg
->fcoe_rx_list
.lock
);
488 __set_current_state(TASK_RUNNING
);
493 static void bnx2fc_recv_frame(struct sk_buff
*skb
)
496 struct fc_lport
*lport
;
497 struct fcoe_rcv_info
*fr
;
498 struct fc_stats
*stats
;
499 struct fc_frame_header
*fh
;
500 struct fcoe_crc_eof crc_eof
;
502 struct fc_lport
*vn_port
;
503 struct fcoe_port
*port
;
508 fr
= fcoe_dev_from_skb(skb
);
510 if (unlikely(lport
== NULL
)) {
511 printk(KERN_ERR PFX
"Invalid lport struct\n");
516 if (skb_is_nonlinear(skb
))
518 mac
= eth_hdr(skb
)->h_source
;
519 dest_mac
= eth_hdr(skb
)->h_dest
;
521 /* Pull the header */
522 hp
= (struct fcoe_hdr
*) skb_network_header(skb
);
523 fh
= (struct fc_frame_header
*) skb_transport_header(skb
);
524 skb_pull(skb
, sizeof(struct fcoe_hdr
));
525 fr_len
= skb
->len
- sizeof(struct fcoe_crc_eof
);
527 fp
= (struct fc_frame
*)skb
;
530 fr_sof(fp
) = hp
->fcoe_sof
;
531 if (skb_copy_bits(skb
, fr_len
, &crc_eof
, sizeof(crc_eof
))) {
535 fr_eof(fp
) = crc_eof
.fcoe_eof
;
536 fr_crc(fp
) = crc_eof
.fcoe_crc32
;
537 if (pskb_trim(skb
, fr_len
)) {
542 fh
= fc_frame_header_get(fp
);
544 vn_port
= fc_vport_id_lookup(lport
, ntoh24(fh
->fh_d_id
));
546 port
= lport_priv(vn_port
);
547 if (!ether_addr_equal(port
->data_src_addr
, dest_mac
)) {
548 BNX2FC_HBA_DBG(lport
, "fpma mismatch\n");
553 if (fh
->fh_r_ctl
== FC_RCTL_DD_SOL_DATA
&&
554 fh
->fh_type
== FC_TYPE_FCP
) {
555 /* Drop FCP data. We dont this in L2 path */
559 if (fh
->fh_r_ctl
== FC_RCTL_ELS_REQ
&&
560 fh
->fh_type
== FC_TYPE_ELS
) {
561 switch (fc_frame_payload_op(fp
)) {
563 if (ntoh24(fh
->fh_s_id
) == FC_FID_FLOGI
) {
564 /* drop non-FIP LOGO */
572 if (fh
->fh_r_ctl
== FC_RCTL_BA_ABTS
) {
573 /* Drop incoming ABTS */
578 stats
= per_cpu_ptr(lport
->stats
, smp_processor_id());
580 stats
->RxWords
+= fr_len
/ FCOE_WORD_TO_BYTE
;
582 if (le32_to_cpu(fr_crc(fp
)) !=
583 ~crc32(~0, skb
->data
, fr_len
)) {
584 if (stats
->InvalidCRCCount
< 5)
585 printk(KERN_WARNING PFX
"dropping frame with "
587 stats
->InvalidCRCCount
++;
591 fc_exch_recv(lport
, fp
);
595 * bnx2fc_percpu_io_thread - thread per cpu for ios
597 * @arg: ptr to bnx2fc_percpu_info structure
599 int bnx2fc_percpu_io_thread(void *arg
)
601 struct bnx2fc_percpu_s
*p
= arg
;
602 struct bnx2fc_work
*work
, *tmp
;
603 LIST_HEAD(work_list
);
605 set_user_nice(current
, MIN_NICE
);
606 set_current_state(TASK_INTERRUPTIBLE
);
607 while (!kthread_should_stop()) {
609 spin_lock_bh(&p
->fp_work_lock
);
610 while (!list_empty(&p
->work_list
)) {
611 list_splice_init(&p
->work_list
, &work_list
);
612 spin_unlock_bh(&p
->fp_work_lock
);
614 list_for_each_entry_safe(work
, tmp
, &work_list
, list
) {
615 list_del_init(&work
->list
);
616 bnx2fc_process_cq_compl(work
->tgt
, work
->wqe
);
620 spin_lock_bh(&p
->fp_work_lock
);
622 __set_current_state(TASK_INTERRUPTIBLE
);
623 spin_unlock_bh(&p
->fp_work_lock
);
625 __set_current_state(TASK_RUNNING
);
630 static struct fc_host_statistics
*bnx2fc_get_host_stats(struct Scsi_Host
*shost
)
632 struct fc_host_statistics
*bnx2fc_stats
;
633 struct fc_lport
*lport
= shost_priv(shost
);
634 struct fcoe_port
*port
= lport_priv(lport
);
635 struct bnx2fc_interface
*interface
= port
->priv
;
636 struct bnx2fc_hba
*hba
= interface
->hba
;
637 struct fcoe_statistics_params
*fw_stats
;
640 fw_stats
= (struct fcoe_statistics_params
*)hba
->stats_buffer
;
644 bnx2fc_stats
= fc_get_host_stats(shost
);
646 init_completion(&hba
->stat_req_done
);
647 if (bnx2fc_send_stat_req(hba
))
649 rc
= wait_for_completion_timeout(&hba
->stat_req_done
, (2 * HZ
));
651 BNX2FC_HBA_DBG(lport
, "FW stat req timed out\n");
654 BNX2FC_STATS(hba
, rx_stat2
, fc_crc_cnt
);
655 bnx2fc_stats
->invalid_crc_count
+= hba
->bfw_stats
.fc_crc_cnt
;
656 BNX2FC_STATS(hba
, tx_stat
, fcoe_tx_pkt_cnt
);
657 bnx2fc_stats
->tx_frames
+= hba
->bfw_stats
.fcoe_tx_pkt_cnt
;
658 BNX2FC_STATS(hba
, tx_stat
, fcoe_tx_byte_cnt
);
659 bnx2fc_stats
->tx_words
+= ((hba
->bfw_stats
.fcoe_tx_byte_cnt
) / 4);
660 BNX2FC_STATS(hba
, rx_stat0
, fcoe_rx_pkt_cnt
);
661 bnx2fc_stats
->rx_frames
+= hba
->bfw_stats
.fcoe_rx_pkt_cnt
;
662 BNX2FC_STATS(hba
, rx_stat0
, fcoe_rx_byte_cnt
);
663 bnx2fc_stats
->rx_words
+= ((hba
->bfw_stats
.fcoe_rx_byte_cnt
) / 4);
665 bnx2fc_stats
->dumped_frames
= 0;
666 bnx2fc_stats
->lip_count
= 0;
667 bnx2fc_stats
->nos_count
= 0;
668 bnx2fc_stats
->loss_of_sync_count
= 0;
669 bnx2fc_stats
->loss_of_signal_count
= 0;
670 bnx2fc_stats
->prim_seq_protocol_err_count
= 0;
672 memcpy(&hba
->prev_stats
, hba
->stats_buffer
,
673 sizeof(struct fcoe_statistics_params
));
677 static int bnx2fc_shost_config(struct fc_lport
*lport
, struct device
*dev
)
679 struct fcoe_port
*port
= lport_priv(lport
);
680 struct bnx2fc_interface
*interface
= port
->priv
;
681 struct bnx2fc_hba
*hba
= interface
->hba
;
682 struct Scsi_Host
*shost
= lport
->host
;
685 shost
->max_cmd_len
= BNX2FC_MAX_CMD_LEN
;
686 shost
->max_lun
= BNX2FC_MAX_LUN
;
687 shost
->max_id
= BNX2FC_MAX_FCP_TGT
;
688 shost
->max_channel
= 0;
690 shost
->transportt
= bnx2fc_vport_xport_template
;
692 shost
->transportt
= bnx2fc_transport_template
;
694 /* Add the new host to SCSI-ml */
695 rc
= scsi_add_host(lport
->host
, dev
);
697 printk(KERN_ERR PFX
"Error on scsi_add_host\n");
701 fc_host_max_npiv_vports(lport
->host
) = USHRT_MAX
;
702 snprintf(fc_host_symbolic_name(lport
->host
), 256,
703 "%s (QLogic %s) v%s over %s",
704 BNX2FC_NAME
, hba
->chip_num
, BNX2FC_VERSION
,
705 interface
->netdev
->name
);
710 static int bnx2fc_link_ok(struct fc_lport
*lport
)
712 struct fcoe_port
*port
= lport_priv(lport
);
713 struct bnx2fc_interface
*interface
= port
->priv
;
714 struct bnx2fc_hba
*hba
= interface
->hba
;
715 struct net_device
*dev
= hba
->phys_dev
;
718 if ((dev
->flags
& IFF_UP
) && netif_carrier_ok(dev
))
719 clear_bit(ADAPTER_STATE_LINK_DOWN
, &hba
->adapter_state
);
721 set_bit(ADAPTER_STATE_LINK_DOWN
, &hba
->adapter_state
);
728 * bnx2fc_get_link_state - get network link state
730 * @hba: adapter instance pointer
732 * updates adapter structure flag based on netdev state
734 void bnx2fc_get_link_state(struct bnx2fc_hba
*hba
)
736 if (test_bit(__LINK_STATE_NOCARRIER
, &hba
->phys_dev
->state
))
737 set_bit(ADAPTER_STATE_LINK_DOWN
, &hba
->adapter_state
);
739 clear_bit(ADAPTER_STATE_LINK_DOWN
, &hba
->adapter_state
);
742 static int bnx2fc_net_config(struct fc_lport
*lport
, struct net_device
*netdev
)
744 struct bnx2fc_hba
*hba
;
745 struct bnx2fc_interface
*interface
;
746 struct fcoe_ctlr
*ctlr
;
747 struct fcoe_port
*port
;
750 port
= lport_priv(lport
);
751 interface
= port
->priv
;
752 ctlr
= bnx2fc_to_ctlr(interface
);
753 hba
= interface
->hba
;
755 /* require support for get_pauseparam ethtool op. */
756 if (!hba
->phys_dev
->ethtool_ops
||
757 !hba
->phys_dev
->ethtool_ops
->get_pauseparam
)
760 if (fc_set_mfs(lport
, BNX2FC_MFS
))
763 skb_queue_head_init(&port
->fcoe_pending_queue
);
764 port
->fcoe_pending_queue_active
= 0;
765 setup_timer(&port
->timer
, fcoe_queue_timer
, (unsigned long) lport
);
767 fcoe_link_speed_update(lport
);
770 if (fcoe_get_wwn(netdev
, &wwnn
, NETDEV_FCOE_WWNN
))
771 wwnn
= fcoe_wwn_from_mac(ctlr
->ctl_src_addr
,
773 BNX2FC_HBA_DBG(lport
, "WWNN = 0x%llx\n", wwnn
);
774 fc_set_wwnn(lport
, wwnn
);
776 if (fcoe_get_wwn(netdev
, &wwpn
, NETDEV_FCOE_WWPN
))
777 wwpn
= fcoe_wwn_from_mac(ctlr
->ctl_src_addr
,
780 BNX2FC_HBA_DBG(lport
, "WWPN = 0x%llx\n", wwpn
);
781 fc_set_wwpn(lport
, wwpn
);
787 static void bnx2fc_destroy_timer(unsigned long data
)
789 struct bnx2fc_hba
*hba
= (struct bnx2fc_hba
*)data
;
791 printk(KERN_ERR PFX
"ERROR:bnx2fc_destroy_timer - "
792 "Destroy compl not received!!\n");
793 set_bit(BNX2FC_FLAG_DESTROY_CMPL
, &hba
->flags
);
794 wake_up_interruptible(&hba
->destroy_wait
);
798 * bnx2fc_indicate_netevent - Generic netdev event handler
800 * @context: adapter structure pointer
802 * @vlan_id: vlan id - associated vlan id with this event
804 * Handles NETDEV_UP, NETDEV_DOWN, NETDEV_GOING_DOWN,NETDEV_CHANGE and
805 * NETDEV_CHANGE_MTU events. Handle NETDEV_UNREGISTER only for vlans.
807 static void bnx2fc_indicate_netevent(void *context
, unsigned long event
,
810 struct bnx2fc_hba
*hba
= (struct bnx2fc_hba
*)context
;
811 struct fcoe_ctlr_device
*cdev
;
812 struct fc_lport
*lport
;
813 struct fc_lport
*vport
;
814 struct bnx2fc_interface
*interface
, *tmp
;
815 struct fcoe_ctlr
*ctlr
;
816 int wait_for_upload
= 0;
817 u32 link_possible
= 1;
819 if (vlan_id
!= 0 && event
!= NETDEV_UNREGISTER
)
824 if (!test_bit(ADAPTER_STATE_UP
, &hba
->adapter_state
))
825 printk(KERN_ERR
"indicate_netevent: "\
826 "hba is not UP!!\n");
830 clear_bit(ADAPTER_STATE_GOING_DOWN
, &hba
->adapter_state
);
831 clear_bit(ADAPTER_STATE_UP
, &hba
->adapter_state
);
835 case NETDEV_GOING_DOWN
:
836 set_bit(ADAPTER_STATE_GOING_DOWN
, &hba
->adapter_state
);
843 case NETDEV_UNREGISTER
:
846 mutex_lock(&bnx2fc_dev_lock
);
847 list_for_each_entry_safe(interface
, tmp
, &if_list
, list
) {
848 if (interface
->hba
== hba
&&
849 interface
->vlan_id
== (vlan_id
& VLAN_VID_MASK
))
850 __bnx2fc_destroy(interface
);
852 mutex_unlock(&bnx2fc_dev_lock
);
854 /* Ensure ALL destroy work has been completed before return */
855 flush_workqueue(bnx2fc_wq
);
862 mutex_lock(&bnx2fc_dev_lock
);
863 list_for_each_entry(interface
, &if_list
, list
) {
865 if (interface
->hba
!= hba
)
868 ctlr
= bnx2fc_to_ctlr(interface
);
870 BNX2FC_HBA_DBG(lport
, "netevent handler - event=%s %ld\n",
871 interface
->netdev
->name
, event
);
873 fcoe_link_speed_update(lport
);
875 cdev
= fcoe_ctlr_to_ctlr_dev(ctlr
);
877 if (link_possible
&& !bnx2fc_link_ok(lport
)) {
878 switch (cdev
->enabled
) {
879 case FCOE_CTLR_DISABLED
:
880 pr_info("Link up while interface is disabled.\n");
882 case FCOE_CTLR_ENABLED
:
883 case FCOE_CTLR_UNUSED
:
884 /* Reset max recv frame size to default */
885 fc_set_mfs(lport
, BNX2FC_MFS
);
887 * ctlr link up will only be handled during
888 * enable to avoid sending discovery
889 * solicitation on a stale vlan
891 if (interface
->enabled
)
892 fcoe_ctlr_link_up(ctlr
);
894 } else if (fcoe_ctlr_link_down(ctlr
)) {
895 switch (cdev
->enabled
) {
896 case FCOE_CTLR_DISABLED
:
897 pr_info("Link down while interface is disabled.\n");
899 case FCOE_CTLR_ENABLED
:
900 case FCOE_CTLR_UNUSED
:
901 mutex_lock(&lport
->lp_mutex
);
902 list_for_each_entry(vport
, &lport
->vports
, list
)
903 fc_host_port_type(vport
->host
) =
905 mutex_unlock(&lport
->lp_mutex
);
906 fc_host_port_type(lport
->host
) =
908 per_cpu_ptr(lport
->stats
,
909 get_cpu())->LinkFailureCount
++;
911 fcoe_clean_pending_queue(lport
);
916 mutex_unlock(&bnx2fc_dev_lock
);
918 if (wait_for_upload
) {
919 clear_bit(ADAPTER_STATE_READY
, &hba
->adapter_state
);
920 init_waitqueue_head(&hba
->shutdown_wait
);
921 BNX2FC_MISC_DBG("indicate_netevent "
922 "num_ofld_sess = %d\n",
924 hba
->wait_for_link_down
= 1;
925 wait_event_interruptible(hba
->shutdown_wait
,
926 (hba
->num_ofld_sess
== 0));
927 BNX2FC_MISC_DBG("wakeup - num_ofld_sess = %d\n",
929 hba
->wait_for_link_down
= 0;
931 if (signal_pending(current
))
932 flush_signals(current
);
936 static int bnx2fc_libfc_config(struct fc_lport
*lport
)
939 /* Set the function pointers set by bnx2fc driver */
940 memcpy(&lport
->tt
, &bnx2fc_libfc_fcn_templ
,
941 sizeof(struct libfc_function_template
));
942 fc_elsct_init(lport
);
944 fc_rport_init(lport
);
946 fc_disc_config(lport
, lport
);
950 static int bnx2fc_em_config(struct fc_lport
*lport
, struct bnx2fc_hba
*hba
)
952 int fcoe_min_xid
, fcoe_max_xid
;
954 fcoe_min_xid
= hba
->max_xid
+ 1;
956 fcoe_max_xid
= hba
->max_xid
+ FCOE_XIDS_PER_CPU_OFFSET
;
958 fcoe_max_xid
= hba
->max_xid
+ FCOE_MAX_XID_OFFSET
;
959 if (!fc_exch_mgr_alloc(lport
, FC_CLASS_3
, fcoe_min_xid
,
960 fcoe_max_xid
, NULL
)) {
961 printk(KERN_ERR PFX
"em_config:fc_exch_mgr_alloc failed\n");
968 static int bnx2fc_lport_config(struct fc_lport
*lport
)
972 lport
->max_retry_count
= BNX2FC_MAX_RETRY_CNT
;
973 lport
->max_rport_retry_count
= BNX2FC_MAX_RPORT_RETRY_CNT
;
974 lport
->e_d_tov
= 2 * 1000;
975 lport
->r_a_tov
= 10 * 1000;
977 lport
->service_params
= (FCP_SPPF_INIT_FCN
| FCP_SPPF_RD_XRDY_DIS
|
978 FCP_SPPF_RETRY
| FCP_SPPF_CONF_COMPL
);
979 lport
->does_npiv
= 1;
981 memset(&lport
->rnid_gen
, 0, sizeof(struct fc_els_rnid_gen
));
982 lport
->rnid_gen
.rnid_atype
= BNX2FC_RNID_HBA
;
984 /* alloc stats structure */
985 if (fc_lport_init_stats(lport
))
988 /* Finish fc_lport configuration */
989 fc_lport_config(lport
);
995 * bnx2fc_fip_recv - handle a received FIP frame.
997 * @skb: the received skb
998 * @dev: associated &net_device
999 * @ptype: the &packet_type structure which was used to register this handler.
1000 * @orig_dev: original receive &net_device, in case @ dev is a bond.
1002 * Returns: 0 for success
1004 static int bnx2fc_fip_recv(struct sk_buff
*skb
, struct net_device
*dev
,
1005 struct packet_type
*ptype
,
1006 struct net_device
*orig_dev
)
1008 struct bnx2fc_interface
*interface
;
1009 struct fcoe_ctlr
*ctlr
;
1010 interface
= container_of(ptype
, struct bnx2fc_interface
,
1012 ctlr
= bnx2fc_to_ctlr(interface
);
1013 fcoe_ctlr_recv(ctlr
, skb
);
1018 * bnx2fc_update_src_mac - Update Ethernet MAC filters.
1020 * @fip: FCoE controller.
1021 * @old: Unicast MAC address to delete if the MAC is non-zero.
1022 * @new: Unicast MAC address to add.
1024 * Remove any previously-set unicast MAC filter.
1025 * Add secondary FCoE MAC address filter for our OUI.
1027 static void bnx2fc_update_src_mac(struct fc_lport
*lport
, u8
*addr
)
1029 struct fcoe_port
*port
= lport_priv(lport
);
1031 memcpy(port
->data_src_addr
, addr
, ETH_ALEN
);
1035 * bnx2fc_get_src_mac - return the ethernet source address for an lport
1037 * @lport: libfc port
1039 static u8
*bnx2fc_get_src_mac(struct fc_lport
*lport
)
1041 struct fcoe_port
*port
;
1043 port
= (struct fcoe_port
*)lport_priv(lport
);
1044 return port
->data_src_addr
;
1048 * bnx2fc_fip_send - send an Ethernet-encapsulated FIP frame.
1050 * @fip: FCoE controller.
1053 static void bnx2fc_fip_send(struct fcoe_ctlr
*fip
, struct sk_buff
*skb
)
1055 skb
->dev
= bnx2fc_from_ctlr(fip
)->netdev
;
1056 dev_queue_xmit(skb
);
1059 static int bnx2fc_vport_create(struct fc_vport
*vport
, bool disabled
)
1061 struct Scsi_Host
*shost
= vport_to_shost(vport
);
1062 struct fc_lport
*n_port
= shost_priv(shost
);
1063 struct fcoe_port
*port
= lport_priv(n_port
);
1064 struct bnx2fc_interface
*interface
= port
->priv
;
1065 struct net_device
*netdev
= interface
->netdev
;
1066 struct fc_lport
*vn_port
;
1070 rc
= fcoe_validate_vport_create(vport
);
1072 fcoe_wwn_to_str(vport
->port_name
, buf
, sizeof(buf
));
1073 printk(KERN_ERR PFX
"Failed to create vport, "
1074 "WWPN (0x%s) already exists\n",
1079 if (!test_bit(BNX2FC_FLAG_FW_INIT_DONE
, &interface
->hba
->flags
)) {
1080 printk(KERN_ERR PFX
"vn ports cannot be created on"
1081 "this interface\n");
1085 mutex_lock(&bnx2fc_dev_lock
);
1086 vn_port
= bnx2fc_if_create(interface
, &vport
->dev
, 1);
1087 mutex_unlock(&bnx2fc_dev_lock
);
1091 printk(KERN_ERR PFX
"bnx2fc_vport_create (%s) failed\n",
1097 fc_vport_set_state(vport
, FC_VPORT_DISABLED
);
1099 vn_port
->boot_time
= jiffies
;
1100 fc_lport_init(vn_port
);
1101 fc_fabric_login(vn_port
);
1102 fc_vport_setlink(vn_port
);
1107 static void bnx2fc_free_vport(struct bnx2fc_hba
*hba
, struct fc_lport
*lport
)
1109 struct bnx2fc_lport
*blport
, *tmp
;
1111 spin_lock_bh(&hba
->hba_lock
);
1112 list_for_each_entry_safe(blport
, tmp
, &hba
->vports
, list
) {
1113 if (blport
->lport
== lport
) {
1114 list_del(&blport
->list
);
1118 spin_unlock_bh(&hba
->hba_lock
);
1121 static int bnx2fc_vport_destroy(struct fc_vport
*vport
)
1123 struct Scsi_Host
*shost
= vport_to_shost(vport
);
1124 struct fc_lport
*n_port
= shost_priv(shost
);
1125 struct fc_lport
*vn_port
= vport
->dd_data
;
1126 struct fcoe_port
*port
= lport_priv(vn_port
);
1127 struct bnx2fc_interface
*interface
= port
->priv
;
1128 struct fc_lport
*v_port
;
1131 mutex_lock(&n_port
->lp_mutex
);
1132 list_for_each_entry(v_port
, &n_port
->vports
, list
)
1133 if (v_port
->vport
== vport
) {
1139 mutex_unlock(&n_port
->lp_mutex
);
1142 list_del(&vn_port
->list
);
1143 mutex_unlock(&n_port
->lp_mutex
);
1144 bnx2fc_free_vport(interface
->hba
, port
->lport
);
1145 bnx2fc_port_shutdown(port
->lport
);
1146 bnx2fc_interface_put(interface
);
1147 queue_work(bnx2fc_wq
, &port
->destroy_work
);
1151 static int bnx2fc_vport_disable(struct fc_vport
*vport
, bool disable
)
1153 struct fc_lport
*lport
= vport
->dd_data
;
1156 fc_vport_set_state(vport
, FC_VPORT_DISABLED
);
1157 fc_fabric_logoff(lport
);
1159 lport
->boot_time
= jiffies
;
1160 fc_fabric_login(lport
);
1161 fc_vport_setlink(lport
);
1167 static int bnx2fc_interface_setup(struct bnx2fc_interface
*interface
)
1169 struct net_device
*netdev
= interface
->netdev
;
1170 struct net_device
*physdev
= interface
->hba
->phys_dev
;
1171 struct fcoe_ctlr
*ctlr
= bnx2fc_to_ctlr(interface
);
1172 struct netdev_hw_addr
*ha
;
1173 int sel_san_mac
= 0;
1175 /* setup Source MAC Address */
1177 for_each_dev_addr(physdev
, ha
) {
1178 BNX2FC_MISC_DBG("net_config: ha->type = %d, fip_mac = ",
1180 printk(KERN_INFO
"%2x:%2x:%2x:%2x:%2x:%2x\n", ha
->addr
[0],
1181 ha
->addr
[1], ha
->addr
[2], ha
->addr
[3],
1182 ha
->addr
[4], ha
->addr
[5]);
1184 if ((ha
->type
== NETDEV_HW_ADDR_T_SAN
) &&
1185 (is_valid_ether_addr(ha
->addr
))) {
1186 memcpy(ctlr
->ctl_src_addr
, ha
->addr
,
1189 BNX2FC_MISC_DBG("Found SAN MAC\n");
1197 interface
->fip_packet_type
.func
= bnx2fc_fip_recv
;
1198 interface
->fip_packet_type
.type
= htons(ETH_P_FIP
);
1199 interface
->fip_packet_type
.dev
= netdev
;
1200 dev_add_pack(&interface
->fip_packet_type
);
1202 interface
->fcoe_packet_type
.func
= bnx2fc_rcv
;
1203 interface
->fcoe_packet_type
.type
= __constant_htons(ETH_P_FCOE
);
1204 interface
->fcoe_packet_type
.dev
= netdev
;
1205 dev_add_pack(&interface
->fcoe_packet_type
);
1210 static int bnx2fc_attach_transport(void)
1212 bnx2fc_transport_template
=
1213 fc_attach_transport(&bnx2fc_transport_function
);
1215 if (bnx2fc_transport_template
== NULL
) {
1216 printk(KERN_ERR PFX
"Failed to attach FC transport\n");
1220 bnx2fc_vport_xport_template
=
1221 fc_attach_transport(&bnx2fc_vport_xport_function
);
1222 if (bnx2fc_vport_xport_template
== NULL
) {
1224 "Failed to attach FC transport for vport\n");
1225 fc_release_transport(bnx2fc_transport_template
);
1226 bnx2fc_transport_template
= NULL
;
1231 static void bnx2fc_release_transport(void)
1233 fc_release_transport(bnx2fc_transport_template
);
1234 fc_release_transport(bnx2fc_vport_xport_template
);
1235 bnx2fc_transport_template
= NULL
;
1236 bnx2fc_vport_xport_template
= NULL
;
1239 static void bnx2fc_interface_release(struct kref
*kref
)
1241 struct fcoe_ctlr_device
*ctlr_dev
;
1242 struct bnx2fc_interface
*interface
;
1243 struct fcoe_ctlr
*ctlr
;
1244 struct net_device
*netdev
;
1246 interface
= container_of(kref
, struct bnx2fc_interface
, kref
);
1247 BNX2FC_MISC_DBG("Interface is being released\n");
1249 ctlr
= bnx2fc_to_ctlr(interface
);
1250 ctlr_dev
= fcoe_ctlr_to_ctlr_dev(ctlr
);
1251 netdev
= interface
->netdev
;
1253 /* tear-down FIP controller */
1254 if (test_and_clear_bit(BNX2FC_CTLR_INIT_DONE
, &interface
->if_flags
))
1255 fcoe_ctlr_destroy(ctlr
);
1257 fcoe_ctlr_device_delete(ctlr_dev
);
1260 module_put(THIS_MODULE
);
1263 static inline void bnx2fc_interface_get(struct bnx2fc_interface
*interface
)
1265 kref_get(&interface
->kref
);
1268 static inline void bnx2fc_interface_put(struct bnx2fc_interface
*interface
)
1270 kref_put(&interface
->kref
, bnx2fc_interface_release
);
1272 static void bnx2fc_hba_destroy(struct bnx2fc_hba
*hba
)
1274 /* Free the command manager */
1276 bnx2fc_cmd_mgr_free(hba
->cmd_mgr
);
1277 hba
->cmd_mgr
= NULL
;
1279 kfree(hba
->tgt_ofld_list
);
1280 bnx2fc_unbind_pcidev(hba
);
1285 * bnx2fc_hba_create - create a new bnx2fc hba
1287 * @cnic: pointer to cnic device
1289 * Creates a new FCoE hba on the given device.
1292 static struct bnx2fc_hba
*bnx2fc_hba_create(struct cnic_dev
*cnic
)
1294 struct bnx2fc_hba
*hba
;
1295 struct fcoe_capabilities
*fcoe_cap
;
1298 hba
= kzalloc(sizeof(*hba
), GFP_KERNEL
);
1300 printk(KERN_ERR PFX
"Unable to allocate hba structure\n");
1303 spin_lock_init(&hba
->hba_lock
);
1304 mutex_init(&hba
->hba_mutex
);
1308 hba
->max_tasks
= cnic
->max_fcoe_exchanges
;
1309 hba
->elstm_xids
= (hba
->max_tasks
/ 2);
1310 hba
->max_outstanding_cmds
= hba
->elstm_xids
;
1311 hba
->max_xid
= (hba
->max_tasks
- 1);
1313 rc
= bnx2fc_bind_pcidev(hba
);
1315 printk(KERN_ERR PFX
"create_adapter: bind error\n");
1318 hba
->phys_dev
= cnic
->netdev
;
1319 hba
->next_conn_id
= 0;
1321 hba
->tgt_ofld_list
=
1322 kzalloc(sizeof(struct bnx2fc_rport
*) * BNX2FC_NUM_MAX_SESS
,
1324 if (!hba
->tgt_ofld_list
) {
1325 printk(KERN_ERR PFX
"Unable to allocate tgt offload list\n");
1329 hba
->num_ofld_sess
= 0;
1331 hba
->cmd_mgr
= bnx2fc_cmd_mgr_alloc(hba
);
1332 if (!hba
->cmd_mgr
) {
1333 printk(KERN_ERR PFX
"em_config:bnx2fc_cmd_mgr_alloc failed\n");
1336 fcoe_cap
= &hba
->fcoe_cap
;
1338 fcoe_cap
->capability1
= BNX2FC_TM_MAX_SQES
<<
1339 FCOE_IOS_PER_CONNECTION_SHIFT
;
1340 fcoe_cap
->capability1
|= BNX2FC_NUM_MAX_SESS
<<
1341 FCOE_LOGINS_PER_PORT_SHIFT
;
1342 fcoe_cap
->capability2
= hba
->max_outstanding_cmds
<<
1343 FCOE_NUMBER_OF_EXCHANGES_SHIFT
;
1344 fcoe_cap
->capability2
|= BNX2FC_MAX_NPIV
<<
1345 FCOE_NPIV_WWN_PER_PORT_SHIFT
;
1346 fcoe_cap
->capability3
= BNX2FC_NUM_MAX_SESS
<<
1347 FCOE_TARGETS_SUPPORTED_SHIFT
;
1348 fcoe_cap
->capability3
|= hba
->max_outstanding_cmds
<<
1349 FCOE_OUTSTANDING_COMMANDS_SHIFT
;
1350 fcoe_cap
->capability4
= FCOE_CAPABILITY4_STATEFUL
;
1352 init_waitqueue_head(&hba
->shutdown_wait
);
1353 init_waitqueue_head(&hba
->destroy_wait
);
1354 INIT_LIST_HEAD(&hba
->vports
);
1359 kfree(hba
->tgt_ofld_list
);
1361 bnx2fc_unbind_pcidev(hba
);
1367 struct bnx2fc_interface
*bnx2fc_interface_create(struct bnx2fc_hba
*hba
,
1368 struct net_device
*netdev
,
1369 enum fip_state fip_mode
)
1371 struct fcoe_ctlr_device
*ctlr_dev
;
1372 struct bnx2fc_interface
*interface
;
1373 struct fcoe_ctlr
*ctlr
;
1377 size
= (sizeof(*interface
) + sizeof(struct fcoe_ctlr
));
1378 ctlr_dev
= fcoe_ctlr_device_add(&netdev
->dev
, &bnx2fc_fcoe_sysfs_templ
,
1381 printk(KERN_ERR PFX
"Unable to allocate interface structure\n");
1384 ctlr
= fcoe_ctlr_device_priv(ctlr_dev
);
1385 ctlr
->cdev
= ctlr_dev
;
1386 interface
= fcoe_ctlr_priv(ctlr
);
1388 kref_init(&interface
->kref
);
1389 interface
->hba
= hba
;
1390 interface
->netdev
= netdev
;
1392 /* Initialize FIP */
1393 fcoe_ctlr_init(ctlr
, fip_mode
);
1394 ctlr
->send
= bnx2fc_fip_send
;
1395 ctlr
->update_mac
= bnx2fc_update_src_mac
;
1396 ctlr
->get_src_addr
= bnx2fc_get_src_mac
;
1397 set_bit(BNX2FC_CTLR_INIT_DONE
, &interface
->if_flags
);
1399 rc
= bnx2fc_interface_setup(interface
);
1403 fcoe_ctlr_destroy(ctlr
);
1405 fcoe_ctlr_device_delete(ctlr_dev
);
1410 * bnx2fc_if_create - Create FCoE instance on a given interface
1412 * @interface: FCoE interface to create a local port on
1413 * @parent: Device pointer to be the parent in sysfs for the SCSI host
1414 * @npiv: Indicates if the port is vport or not
1416 * Creates a fc_lport instance and a Scsi_Host instance and configure them.
1418 * Returns: Allocated fc_lport or an error pointer
1420 static struct fc_lport
*bnx2fc_if_create(struct bnx2fc_interface
*interface
,
1421 struct device
*parent
, int npiv
)
1423 struct fcoe_ctlr
*ctlr
= bnx2fc_to_ctlr(interface
);
1424 struct fc_lport
*lport
, *n_port
;
1425 struct fcoe_port
*port
;
1426 struct Scsi_Host
*shost
;
1427 struct fc_vport
*vport
= dev_to_vport(parent
);
1428 struct bnx2fc_lport
*blport
;
1429 struct bnx2fc_hba
*hba
= interface
->hba
;
1432 blport
= kzalloc(sizeof(struct bnx2fc_lport
), GFP_KERNEL
);
1434 BNX2FC_HBA_DBG(ctlr
->lp
, "Unable to alloc blport\n");
1438 /* Allocate Scsi_Host structure */
1439 bnx2fc_shost_template
.can_queue
= hba
->max_outstanding_cmds
;
1441 lport
= libfc_host_alloc(&bnx2fc_shost_template
, sizeof(*port
));
1443 lport
= libfc_vport_create(vport
, sizeof(*port
));
1446 printk(KERN_ERR PFX
"could not allocate scsi host structure\n");
1449 shost
= lport
->host
;
1450 port
= lport_priv(lport
);
1451 port
->lport
= lport
;
1452 port
->priv
= interface
;
1453 port
->get_netdev
= bnx2fc_netdev
;
1454 INIT_WORK(&port
->destroy_work
, bnx2fc_destroy_work
);
1456 /* Configure fcoe_port */
1457 rc
= bnx2fc_lport_config(lport
);
1462 printk(KERN_ERR PFX
"Setting vport names, 0x%llX 0x%llX\n",
1463 vport
->node_name
, vport
->port_name
);
1464 fc_set_wwnn(lport
, vport
->node_name
);
1465 fc_set_wwpn(lport
, vport
->port_name
);
1467 /* Configure netdev and networking properties of the lport */
1468 rc
= bnx2fc_net_config(lport
, interface
->netdev
);
1470 printk(KERN_ERR PFX
"Error on bnx2fc_net_config\n");
1474 rc
= bnx2fc_shost_config(lport
, parent
);
1476 printk(KERN_ERR PFX
"Couldnt configure shost for %s\n",
1477 interface
->netdev
->name
);
1481 /* Initialize the libfc library */
1482 rc
= bnx2fc_libfc_config(lport
);
1484 printk(KERN_ERR PFX
"Couldnt configure libfc\n");
1487 fc_host_port_type(lport
->host
) = FC_PORTTYPE_UNKNOWN
;
1489 /* Allocate exchange manager */
1491 rc
= bnx2fc_em_config(lport
, hba
);
1493 shost
= vport_to_shost(vport
);
1494 n_port
= shost_priv(shost
);
1495 rc
= fc_exch_mgr_list_clone(n_port
, lport
);
1499 printk(KERN_ERR PFX
"Error on bnx2fc_em_config\n");
1503 bnx2fc_interface_get(interface
);
1505 spin_lock_bh(&hba
->hba_lock
);
1506 blport
->lport
= lport
;
1507 list_add_tail(&blport
->list
, &hba
->vports
);
1508 spin_unlock_bh(&hba
->hba_lock
);
1513 scsi_remove_host(shost
);
1515 scsi_host_put(lport
->host
);
1521 static void bnx2fc_net_cleanup(struct bnx2fc_interface
*interface
)
1523 /* Dont listen for Ethernet packets anymore */
1524 __dev_remove_pack(&interface
->fcoe_packet_type
);
1525 __dev_remove_pack(&interface
->fip_packet_type
);
1529 static void bnx2fc_interface_cleanup(struct bnx2fc_interface
*interface
)
1531 struct fcoe_ctlr
*ctlr
= bnx2fc_to_ctlr(interface
);
1532 struct fc_lport
*lport
= ctlr
->lp
;
1533 struct fcoe_port
*port
= lport_priv(lport
);
1534 struct bnx2fc_hba
*hba
= interface
->hba
;
1536 /* Stop the transmit retry timer */
1537 del_timer_sync(&port
->timer
);
1539 /* Free existing transmit skbs */
1540 fcoe_clean_pending_queue(lport
);
1542 bnx2fc_net_cleanup(interface
);
1544 bnx2fc_free_vport(hba
, lport
);
1547 static void bnx2fc_if_destroy(struct fc_lport
*lport
)
1550 /* Free queued packets for the receive thread */
1551 bnx2fc_clean_rx_queue(lport
);
1553 /* Detach from scsi-ml */
1554 fc_remove_host(lport
->host
);
1555 scsi_remove_host(lport
->host
);
1558 * Note that only the physical lport will have the exchange manager.
1559 * for vports, this function is NOP
1561 fc_exch_mgr_free(lport
);
1563 /* Free memory used by statistical counters */
1564 fc_lport_free_stats(lport
);
1566 /* Release Scsi_Host */
1567 scsi_host_put(lport
->host
);
1570 static void __bnx2fc_destroy(struct bnx2fc_interface
*interface
)
1572 struct fcoe_ctlr
*ctlr
= bnx2fc_to_ctlr(interface
);
1573 struct fc_lport
*lport
= ctlr
->lp
;
1574 struct fcoe_port
*port
= lport_priv(lport
);
1576 bnx2fc_interface_cleanup(interface
);
1577 bnx2fc_stop(interface
);
1578 list_del(&interface
->list
);
1579 bnx2fc_interface_put(interface
);
1580 queue_work(bnx2fc_wq
, &port
->destroy_work
);
1584 * bnx2fc_destroy - Destroy a bnx2fc FCoE interface
1586 * @buffer: The name of the Ethernet interface to be destroyed
1587 * @kp: The associated kernel parameter
1589 * Called from sysfs.
1591 * Returns: 0 for success
1593 static int bnx2fc_destroy(struct net_device
*netdev
)
1595 struct bnx2fc_interface
*interface
= NULL
;
1596 struct workqueue_struct
*timer_work_queue
;
1597 struct fcoe_ctlr
*ctlr
;
1601 mutex_lock(&bnx2fc_dev_lock
);
1603 interface
= bnx2fc_interface_lookup(netdev
);
1604 ctlr
= bnx2fc_to_ctlr(interface
);
1605 if (!interface
|| !ctlr
->lp
) {
1607 printk(KERN_ERR PFX
"bnx2fc_destroy: interface or lport not found\n");
1611 timer_work_queue
= interface
->timer_work_queue
;
1612 __bnx2fc_destroy(interface
);
1613 destroy_workqueue(timer_work_queue
);
1616 mutex_unlock(&bnx2fc_dev_lock
);
1621 static void bnx2fc_destroy_work(struct work_struct
*work
)
1623 struct fcoe_port
*port
;
1624 struct fc_lport
*lport
;
1626 port
= container_of(work
, struct fcoe_port
, destroy_work
);
1627 lport
= port
->lport
;
1629 BNX2FC_HBA_DBG(lport
, "Entered bnx2fc_destroy_work\n");
1631 bnx2fc_if_destroy(lport
);
1634 static void bnx2fc_unbind_adapter_devices(struct bnx2fc_hba
*hba
)
1636 bnx2fc_free_fw_resc(hba
);
1637 bnx2fc_free_task_ctx(hba
);
1641 * bnx2fc_bind_adapter_devices - binds bnx2fc adapter with the associated
1644 * @hba: Adapter instance
1646 static int bnx2fc_bind_adapter_devices(struct bnx2fc_hba
*hba
)
1648 if (bnx2fc_setup_task_ctx(hba
))
1651 if (bnx2fc_setup_fw_resc(hba
))
1656 bnx2fc_unbind_adapter_devices(hba
);
1660 static int bnx2fc_bind_pcidev(struct bnx2fc_hba
*hba
)
1662 struct cnic_dev
*cnic
;
1663 struct pci_dev
*pdev
;
1666 printk(KERN_ERR PFX
"cnic is NULL\n");
1670 pdev
= hba
->pcidev
= cnic
->pcidev
;
1674 switch (pdev
->device
) {
1675 case PCI_DEVICE_ID_NX2_57710
:
1676 strncpy(hba
->chip_num
, "BCM57710", BCM_CHIP_LEN
);
1678 case PCI_DEVICE_ID_NX2_57711
:
1679 strncpy(hba
->chip_num
, "BCM57711", BCM_CHIP_LEN
);
1681 case PCI_DEVICE_ID_NX2_57712
:
1682 case PCI_DEVICE_ID_NX2_57712_MF
:
1683 case PCI_DEVICE_ID_NX2_57712_VF
:
1684 strncpy(hba
->chip_num
, "BCM57712", BCM_CHIP_LEN
);
1686 case PCI_DEVICE_ID_NX2_57800
:
1687 case PCI_DEVICE_ID_NX2_57800_MF
:
1688 case PCI_DEVICE_ID_NX2_57800_VF
:
1689 strncpy(hba
->chip_num
, "BCM57800", BCM_CHIP_LEN
);
1691 case PCI_DEVICE_ID_NX2_57810
:
1692 case PCI_DEVICE_ID_NX2_57810_MF
:
1693 case PCI_DEVICE_ID_NX2_57810_VF
:
1694 strncpy(hba
->chip_num
, "BCM57810", BCM_CHIP_LEN
);
1696 case PCI_DEVICE_ID_NX2_57840
:
1697 case PCI_DEVICE_ID_NX2_57840_MF
:
1698 case PCI_DEVICE_ID_NX2_57840_VF
:
1699 case PCI_DEVICE_ID_NX2_57840_2_20
:
1700 case PCI_DEVICE_ID_NX2_57840_4_10
:
1701 strncpy(hba
->chip_num
, "BCM57840", BCM_CHIP_LEN
);
1704 pr_err(PFX
"Unknown device id 0x%x\n", pdev
->device
);
1707 pci_dev_get(hba
->pcidev
);
1711 static void bnx2fc_unbind_pcidev(struct bnx2fc_hba
*hba
)
1714 hba
->chip_num
[0] = '\0';
1715 pci_dev_put(hba
->pcidev
);
1721 * bnx2fc_ulp_get_stats - cnic callback to populate FCoE stats
1723 * @handle: transport handle pointing to adapter struture
1725 static int bnx2fc_ulp_get_stats(void *handle
)
1727 struct bnx2fc_hba
*hba
= handle
;
1728 struct cnic_dev
*cnic
;
1729 struct fcoe_stats_info
*stats_addr
;
1735 stats_addr
= &cnic
->stats_addr
->fcoe_stat
;
1739 strncpy(stats_addr
->version
, BNX2FC_VERSION
,
1740 sizeof(stats_addr
->version
));
1741 stats_addr
->txq_size
= BNX2FC_SQ_WQES_MAX
;
1742 stats_addr
->rxq_size
= BNX2FC_CQ_WQES_MAX
;
1749 * bnx2fc_ulp_start - cnic callback to initialize & start adapter instance
1751 * @handle: transport handle pointing to adapter structure
1753 * This function maps adapter structure to pcidev structure and initiates
1754 * firmware handshake to enable/initialize on-chip FCoE components.
1755 * This bnx2fc - cnic interface api callback is used after following
1756 * conditions are met -
1757 * a) underlying network interface is up (marked by event NETDEV_UP
1759 * b) bnx2fc adatper structure is registered.
1761 static void bnx2fc_ulp_start(void *handle
)
1763 struct bnx2fc_hba
*hba
= handle
;
1764 struct bnx2fc_interface
*interface
;
1765 struct fcoe_ctlr
*ctlr
;
1766 struct fc_lport
*lport
;
1768 mutex_lock(&bnx2fc_dev_lock
);
1770 if (!test_bit(BNX2FC_FLAG_FW_INIT_DONE
, &hba
->flags
))
1771 bnx2fc_fw_init(hba
);
1773 BNX2FC_MISC_DBG("bnx2fc started.\n");
1775 list_for_each_entry(interface
, &if_list
, list
) {
1776 if (interface
->hba
== hba
) {
1777 ctlr
= bnx2fc_to_ctlr(interface
);
1779 /* Kick off Fabric discovery*/
1780 printk(KERN_ERR PFX
"ulp_init: start discovery\n");
1781 lport
->tt
.frame_send
= bnx2fc_xmit
;
1782 bnx2fc_start_disc(interface
);
1786 mutex_unlock(&bnx2fc_dev_lock
);
1789 static void bnx2fc_port_shutdown(struct fc_lport
*lport
)
1791 BNX2FC_MISC_DBG("Entered %s\n", __func__
);
1792 fc_fabric_logoff(lport
);
1793 fc_lport_destroy(lport
);
1796 static void bnx2fc_stop(struct bnx2fc_interface
*interface
)
1798 struct fcoe_ctlr
*ctlr
= bnx2fc_to_ctlr(interface
);
1799 struct fc_lport
*lport
;
1800 struct fc_lport
*vport
;
1802 if (!test_bit(BNX2FC_FLAG_FW_INIT_DONE
, &interface
->hba
->flags
))
1806 bnx2fc_port_shutdown(lport
);
1808 mutex_lock(&lport
->lp_mutex
);
1809 list_for_each_entry(vport
, &lport
->vports
, list
)
1810 fc_host_port_type(vport
->host
) =
1811 FC_PORTTYPE_UNKNOWN
;
1812 mutex_unlock(&lport
->lp_mutex
);
1813 fc_host_port_type(lport
->host
) = FC_PORTTYPE_UNKNOWN
;
1814 fcoe_ctlr_link_down(ctlr
);
1815 fcoe_clean_pending_queue(lport
);
1818 static int bnx2fc_fw_init(struct bnx2fc_hba
*hba
)
1820 #define BNX2FC_INIT_POLL_TIME (1000 / HZ)
1824 rc
= bnx2fc_bind_adapter_devices(hba
);
1826 printk(KERN_ALERT PFX
1827 "bnx2fc_bind_adapter_devices failed - rc = %d\n", rc
);
1831 rc
= bnx2fc_send_fw_fcoe_init_msg(hba
);
1833 printk(KERN_ALERT PFX
1834 "bnx2fc_send_fw_fcoe_init_msg failed - rc = %d\n", rc
);
1839 * Wait until the adapter init message is complete, and adapter
1842 while (!test_bit(ADAPTER_STATE_UP
, &hba
->adapter_state
) && i
--)
1843 msleep(BNX2FC_INIT_POLL_TIME
);
1845 if (!test_bit(ADAPTER_STATE_UP
, &hba
->adapter_state
)) {
1846 printk(KERN_ERR PFX
"bnx2fc_start: %s failed to initialize. "
1848 hba
->cnic
->netdev
->name
);
1854 set_bit(BNX2FC_FLAG_FW_INIT_DONE
, &hba
->flags
);
1858 bnx2fc_unbind_adapter_devices(hba
);
1863 static void bnx2fc_fw_destroy(struct bnx2fc_hba
*hba
)
1865 if (test_and_clear_bit(BNX2FC_FLAG_FW_INIT_DONE
, &hba
->flags
)) {
1866 if (bnx2fc_send_fw_fcoe_destroy_msg(hba
) == 0) {
1867 init_timer(&hba
->destroy_timer
);
1868 hba
->destroy_timer
.expires
= BNX2FC_FW_TIMEOUT
+
1870 hba
->destroy_timer
.function
= bnx2fc_destroy_timer
;
1871 hba
->destroy_timer
.data
= (unsigned long)hba
;
1872 add_timer(&hba
->destroy_timer
);
1873 wait_event_interruptible(hba
->destroy_wait
,
1874 test_bit(BNX2FC_FLAG_DESTROY_CMPL
,
1876 clear_bit(BNX2FC_FLAG_DESTROY_CMPL
, &hba
->flags
);
1877 /* This should never happen */
1878 if (signal_pending(current
))
1879 flush_signals(current
);
1881 del_timer_sync(&hba
->destroy_timer
);
1883 bnx2fc_unbind_adapter_devices(hba
);
1888 * bnx2fc_ulp_stop - cnic callback to shutdown adapter instance
1890 * @handle: transport handle pointing to adapter structure
1892 * Driver checks if adapter is already in shutdown mode, if not start
1893 * the shutdown process.
1895 static void bnx2fc_ulp_stop(void *handle
)
1897 struct bnx2fc_hba
*hba
= handle
;
1898 struct bnx2fc_interface
*interface
;
1900 printk(KERN_ERR
"ULP_STOP\n");
1902 mutex_lock(&bnx2fc_dev_lock
);
1903 if (!test_bit(BNX2FC_FLAG_FW_INIT_DONE
, &hba
->flags
))
1905 list_for_each_entry(interface
, &if_list
, list
) {
1906 if (interface
->hba
== hba
)
1907 bnx2fc_stop(interface
);
1909 BUG_ON(hba
->num_ofld_sess
!= 0);
1911 mutex_lock(&hba
->hba_mutex
);
1912 clear_bit(ADAPTER_STATE_UP
, &hba
->adapter_state
);
1913 clear_bit(ADAPTER_STATE_GOING_DOWN
,
1914 &hba
->adapter_state
);
1916 clear_bit(ADAPTER_STATE_READY
, &hba
->adapter_state
);
1917 mutex_unlock(&hba
->hba_mutex
);
1919 bnx2fc_fw_destroy(hba
);
1921 mutex_unlock(&bnx2fc_dev_lock
);
1924 static void bnx2fc_start_disc(struct bnx2fc_interface
*interface
)
1926 struct fcoe_ctlr
*ctlr
= bnx2fc_to_ctlr(interface
);
1927 struct fc_lport
*lport
;
1930 BNX2FC_MISC_DBG("Entered %s\n", __func__
);
1931 /* Kick off FIP/FLOGI */
1932 if (!test_bit(BNX2FC_FLAG_FW_INIT_DONE
, &interface
->hba
->flags
)) {
1933 printk(KERN_ERR PFX
"Init not done yet\n");
1938 BNX2FC_HBA_DBG(lport
, "calling fc_fabric_login\n");
1940 if (!bnx2fc_link_ok(lport
) && interface
->enabled
) {
1941 BNX2FC_HBA_DBG(lport
, "ctlr_link_up\n");
1942 fcoe_ctlr_link_up(ctlr
);
1943 fc_host_port_type(lport
->host
) = FC_PORTTYPE_NPORT
;
1944 set_bit(ADAPTER_STATE_READY
, &interface
->hba
->adapter_state
);
1947 /* wait for the FCF to be selected before issuing FLOGI */
1948 while (!ctlr
->sel_fcf
) {
1950 /* give up after 3 secs */
1951 if (++wait_cnt
> 12)
1955 /* Reset max receive frame size to default */
1956 if (fc_set_mfs(lport
, BNX2FC_MFS
))
1959 fc_lport_init(lport
);
1960 fc_fabric_login(lport
);
1965 * bnx2fc_ulp_init - Initialize an adapter instance
1967 * @dev : cnic device handle
1968 * Called from cnic_register_driver() context to initialize all
1969 * enumerated cnic devices. This routine allocates adapter structure
1970 * and other device specific resources.
1972 static void bnx2fc_ulp_init(struct cnic_dev
*dev
)
1974 struct bnx2fc_hba
*hba
;
1977 BNX2FC_MISC_DBG("Entered %s\n", __func__
);
1978 /* bnx2fc works only when bnx2x is loaded */
1979 if (!test_bit(CNIC_F_BNX2X_CLASS
, &dev
->flags
) ||
1980 (dev
->max_fcoe_conn
== 0)) {
1981 printk(KERN_ERR PFX
"bnx2fc FCoE not supported on %s,"
1982 " flags: %lx fcoe_conn: %d\n",
1983 dev
->netdev
->name
, dev
->flags
, dev
->max_fcoe_conn
);
1987 hba
= bnx2fc_hba_create(dev
);
1989 printk(KERN_ERR PFX
"hba initialization failed\n");
1993 /* Add HBA to the adapter list */
1994 mutex_lock(&bnx2fc_dev_lock
);
1995 list_add_tail(&hba
->list
, &adapter_list
);
1997 mutex_unlock(&bnx2fc_dev_lock
);
1999 dev
->fcoe_cap
= &hba
->fcoe_cap
;
2000 clear_bit(BNX2FC_CNIC_REGISTERED
, &hba
->reg_with_cnic
);
2001 rc
= dev
->register_device(dev
, CNIC_ULP_FCOE
,
2004 printk(KERN_ERR PFX
"register_device failed, rc = %d\n", rc
);
2006 set_bit(BNX2FC_CNIC_REGISTERED
, &hba
->reg_with_cnic
);
2009 /* Assumes rtnl_lock and the bnx2fc_dev_lock are already taken */
2010 static int __bnx2fc_disable(struct fcoe_ctlr
*ctlr
)
2012 struct bnx2fc_interface
*interface
= fcoe_ctlr_priv(ctlr
);
2014 if (interface
->enabled
== true) {
2016 pr_err(PFX
"__bnx2fc_disable: lport not found\n");
2019 interface
->enabled
= false;
2020 fcoe_ctlr_link_down(ctlr
);
2021 fcoe_clean_pending_queue(ctlr
->lp
);
2028 * Deperecated: Use bnx2fc_enabled()
2030 static int bnx2fc_disable(struct net_device
*netdev
)
2032 struct bnx2fc_interface
*interface
;
2033 struct fcoe_ctlr
*ctlr
;
2037 mutex_lock(&bnx2fc_dev_lock
);
2039 interface
= bnx2fc_interface_lookup(netdev
);
2040 ctlr
= bnx2fc_to_ctlr(interface
);
2044 pr_err(PFX
"bnx2fc_disable: interface not found\n");
2046 rc
= __bnx2fc_disable(ctlr
);
2048 mutex_unlock(&bnx2fc_dev_lock
);
2053 static uint
bnx2fc_npiv_create_vports(struct fc_lport
*lport
,
2054 struct cnic_fc_npiv_tbl
*npiv_tbl
)
2056 struct fc_vport_identifiers vpid
;
2057 uint i
, created
= 0;
2059 if (npiv_tbl
->count
> MAX_NPIV_ENTRIES
) {
2060 BNX2FC_HBA_DBG(lport
, "Exceeded count max of npiv table\n");
2064 /* Sanity check the first entry to make sure it's not 0 */
2065 if (wwn_to_u64(npiv_tbl
->wwnn
[0]) == 0 &&
2066 wwn_to_u64(npiv_tbl
->wwpn
[0]) == 0) {
2067 BNX2FC_HBA_DBG(lport
, "First NPIV table entries invalid.\n");
2071 vpid
.roles
= FC_PORT_ROLE_FCP_INITIATOR
;
2072 vpid
.vport_type
= FC_PORTTYPE_NPIV
;
2073 vpid
.disable
= false;
2075 for (i
= 0; i
< npiv_tbl
->count
; i
++) {
2076 vpid
.node_name
= wwn_to_u64(npiv_tbl
->wwnn
[i
]);
2077 vpid
.port_name
= wwn_to_u64(npiv_tbl
->wwpn
[i
]);
2078 scnprintf(vpid
.symbolic_name
, sizeof(vpid
.symbolic_name
),
2079 "NPIV[%u]:%016llx-%016llx",
2080 created
, vpid
.port_name
, vpid
.node_name
);
2081 if (fc_vport_create(lport
->host
, 0, &vpid
))
2084 BNX2FC_HBA_DBG(lport
, "Failed to create vport\n");
2090 static int __bnx2fc_enable(struct fcoe_ctlr
*ctlr
)
2092 struct bnx2fc_interface
*interface
= fcoe_ctlr_priv(ctlr
);
2093 struct bnx2fc_hba
*hba
;
2094 struct cnic_fc_npiv_tbl
*npiv_tbl
;
2095 struct fc_lport
*lport
;
2097 if (interface
->enabled
== false) {
2099 pr_err(PFX
"__bnx2fc_enable: lport not found\n");
2101 } else if (!bnx2fc_link_ok(ctlr
->lp
)) {
2102 fcoe_ctlr_link_up(ctlr
);
2103 interface
->enabled
= true;
2107 /* Create static NPIV ports if any are contained in NVRAM */
2108 hba
= interface
->hba
;
2123 if (!hba
->cnic
->get_fc_npiv_tbl
)
2126 npiv_tbl
= kzalloc(sizeof(struct cnic_fc_npiv_tbl
), GFP_KERNEL
);
2130 if (hba
->cnic
->get_fc_npiv_tbl(hba
->cnic
, npiv_tbl
))
2133 bnx2fc_npiv_create_vports(lport
, npiv_tbl
);
2141 * Deprecated: Use bnx2fc_enabled()
2143 static int bnx2fc_enable(struct net_device
*netdev
)
2145 struct bnx2fc_interface
*interface
;
2146 struct fcoe_ctlr
*ctlr
;
2150 mutex_lock(&bnx2fc_dev_lock
);
2152 interface
= bnx2fc_interface_lookup(netdev
);
2153 ctlr
= bnx2fc_to_ctlr(interface
);
2156 pr_err(PFX
"bnx2fc_enable: interface not found\n");
2158 rc
= __bnx2fc_enable(ctlr
);
2161 mutex_unlock(&bnx2fc_dev_lock
);
2167 * bnx2fc_ctlr_enabled() - Enable or disable an FCoE Controller
2168 * @cdev: The FCoE Controller that is being enabled or disabled
2170 * fcoe_sysfs will ensure that the state of 'enabled' has
2171 * changed, so no checking is necessary here. This routine simply
2172 * calls fcoe_enable or fcoe_disable, both of which are deprecated.
2173 * When those routines are removed the functionality can be merged
2176 static int bnx2fc_ctlr_enabled(struct fcoe_ctlr_device
*cdev
)
2178 struct fcoe_ctlr
*ctlr
= fcoe_ctlr_device_priv(cdev
);
2180 switch (cdev
->enabled
) {
2181 case FCOE_CTLR_ENABLED
:
2182 return __bnx2fc_enable(ctlr
);
2183 case FCOE_CTLR_DISABLED
:
2184 return __bnx2fc_disable(ctlr
);
2185 case FCOE_CTLR_UNUSED
:
2191 enum bnx2fc_create_link_state
{
2192 BNX2FC_CREATE_LINK_DOWN
,
2193 BNX2FC_CREATE_LINK_UP
,
2197 * _bnx2fc_create() - Create bnx2fc FCoE interface
2198 * @netdev : The net_device object the Ethernet interface to create on
2199 * @fip_mode: The FIP mode for this creation
2200 * @link_state: The ctlr link state on creation
2202 * Called from either the libfcoe 'create' module parameter
2203 * via fcoe_create or from fcoe_syfs's ctlr_create file.
2205 * libfcoe's 'create' module parameter is deprecated so some
2206 * consolidation of code can be done when that interface is
2209 * Returns: 0 for success
2211 static int _bnx2fc_create(struct net_device
*netdev
,
2212 enum fip_state fip_mode
,
2213 enum bnx2fc_create_link_state link_state
)
2215 struct fcoe_ctlr_device
*cdev
;
2216 struct fcoe_ctlr
*ctlr
;
2217 struct bnx2fc_interface
*interface
;
2218 struct bnx2fc_hba
*hba
;
2219 struct net_device
*phys_dev
= netdev
;
2220 struct fc_lport
*lport
;
2221 struct ethtool_drvinfo drvinfo
;
2225 BNX2FC_MISC_DBG("Entered bnx2fc_create\n");
2226 if (fip_mode
!= FIP_MODE_FABRIC
) {
2227 printk(KERN_ERR
"fip mode not FABRIC\n");
2233 mutex_lock(&bnx2fc_dev_lock
);
2235 if (!try_module_get(THIS_MODULE
)) {
2240 /* obtain physical netdev */
2241 if (netdev
->priv_flags
& IFF_802_1Q_VLAN
)
2242 phys_dev
= vlan_dev_real_dev(netdev
);
2244 /* verify if the physical device is a netxtreme2 device */
2245 if (phys_dev
->ethtool_ops
&& phys_dev
->ethtool_ops
->get_drvinfo
) {
2246 memset(&drvinfo
, 0, sizeof(drvinfo
));
2247 phys_dev
->ethtool_ops
->get_drvinfo(phys_dev
, &drvinfo
);
2248 if (strncmp(drvinfo
.driver
, "bnx2x", strlen("bnx2x"))) {
2249 printk(KERN_ERR PFX
"Not a netxtreme2 device\n");
2254 printk(KERN_ERR PFX
"unable to obtain drv_info\n");
2259 /* obtain interface and initialize rest of the structure */
2260 hba
= bnx2fc_hba_lookup(phys_dev
);
2263 printk(KERN_ERR PFX
"bnx2fc_create: hba not found\n");
2267 if (bnx2fc_interface_lookup(netdev
)) {
2272 interface
= bnx2fc_interface_create(hba
, netdev
, fip_mode
);
2274 printk(KERN_ERR PFX
"bnx2fc_interface_create failed\n");
2279 if (netdev
->priv_flags
& IFF_802_1Q_VLAN
) {
2280 vlan_id
= vlan_dev_vlan_id(netdev
);
2281 interface
->vlan_enabled
= 1;
2284 ctlr
= bnx2fc_to_ctlr(interface
);
2285 cdev
= fcoe_ctlr_to_ctlr_dev(ctlr
);
2286 interface
->vlan_id
= vlan_id
;
2288 interface
->timer_work_queue
=
2289 create_singlethread_workqueue("bnx2fc_timer_wq");
2290 if (!interface
->timer_work_queue
) {
2291 printk(KERN_ERR PFX
"ulp_init could not create timer_wq\n");
2296 lport
= bnx2fc_if_create(interface
, &cdev
->dev
, 0);
2298 printk(KERN_ERR PFX
"Failed to create interface (%s)\n",
2304 /* Add interface to if_list */
2305 list_add_tail(&interface
->list
, &if_list
);
2307 lport
->boot_time
= jiffies
;
2309 /* Make this master N_port */
2312 if (link_state
== BNX2FC_CREATE_LINK_UP
)
2313 cdev
->enabled
= FCOE_CTLR_ENABLED
;
2315 cdev
->enabled
= FCOE_CTLR_DISABLED
;
2317 if (link_state
== BNX2FC_CREATE_LINK_UP
&&
2318 !bnx2fc_link_ok(lport
)) {
2319 fcoe_ctlr_link_up(ctlr
);
2320 fc_host_port_type(lport
->host
) = FC_PORTTYPE_NPORT
;
2321 set_bit(ADAPTER_STATE_READY
, &interface
->hba
->adapter_state
);
2324 BNX2FC_HBA_DBG(lport
, "create: START DISC\n");
2325 bnx2fc_start_disc(interface
);
2327 if (link_state
== BNX2FC_CREATE_LINK_UP
)
2328 interface
->enabled
= true;
2331 * Release from kref_init in bnx2fc_interface_setup, on success
2332 * lport should be holding a reference taken in bnx2fc_if_create
2334 bnx2fc_interface_put(interface
);
2335 /* put netdev that was held while calling dev_get_by_name */
2336 mutex_unlock(&bnx2fc_dev_lock
);
2341 destroy_workqueue(interface
->timer_work_queue
);
2343 bnx2fc_net_cleanup(interface
);
2344 bnx2fc_interface_put(interface
);
2347 module_put(THIS_MODULE
);
2349 mutex_unlock(&bnx2fc_dev_lock
);
2355 * bnx2fc_create() - Create a bnx2fc interface
2356 * @netdev : The net_device object the Ethernet interface to create on
2357 * @fip_mode: The FIP mode for this creation
2359 * Called from fcoe transport
2361 * Returns: 0 for success
2363 static int bnx2fc_create(struct net_device
*netdev
, enum fip_state fip_mode
)
2365 return _bnx2fc_create(netdev
, fip_mode
, BNX2FC_CREATE_LINK_UP
);
2369 * bnx2fc_ctlr_alloc() - Allocate a bnx2fc interface from fcoe_sysfs
2370 * @netdev: The net_device to be used by the allocated FCoE Controller
2372 * This routine is called from fcoe_sysfs. It will start the fcoe_ctlr
2373 * in a link_down state. The allows the user an opportunity to configure
2374 * the FCoE Controller from sysfs before enabling the FCoE Controller.
2376 * Creating in with this routine starts the FCoE Controller in Fabric
2377 * mode. The user can change to VN2VN or another mode before enabling.
2379 static int bnx2fc_ctlr_alloc(struct net_device
*netdev
)
2381 return _bnx2fc_create(netdev
, FIP_MODE_FABRIC
,
2382 BNX2FC_CREATE_LINK_DOWN
);
2386 * bnx2fc_find_hba_for_cnic - maps cnic instance to bnx2fc hba instance
2388 * @cnic: Pointer to cnic device instance
2391 static struct bnx2fc_hba
*bnx2fc_find_hba_for_cnic(struct cnic_dev
*cnic
)
2393 struct bnx2fc_hba
*hba
;
2395 /* Called with bnx2fc_dev_lock held */
2396 list_for_each_entry(hba
, &adapter_list
, list
) {
2397 if (hba
->cnic
== cnic
)
2403 static struct bnx2fc_interface
*bnx2fc_interface_lookup(struct net_device
2406 struct bnx2fc_interface
*interface
;
2408 /* Called with bnx2fc_dev_lock held */
2409 list_for_each_entry(interface
, &if_list
, list
) {
2410 if (interface
->netdev
== netdev
)
2416 static struct bnx2fc_hba
*bnx2fc_hba_lookup(struct net_device
2419 struct bnx2fc_hba
*hba
;
2421 /* Called with bnx2fc_dev_lock held */
2422 list_for_each_entry(hba
, &adapter_list
, list
) {
2423 if (hba
->phys_dev
== phys_dev
)
2426 printk(KERN_ERR PFX
"adapter_lookup: hba NULL\n");
2431 * bnx2fc_ulp_exit - shuts down adapter instance and frees all resources
2433 * @dev cnic device handle
2435 static void bnx2fc_ulp_exit(struct cnic_dev
*dev
)
2437 struct bnx2fc_hba
*hba
;
2438 struct bnx2fc_interface
*interface
, *tmp
;
2440 BNX2FC_MISC_DBG("Entered bnx2fc_ulp_exit\n");
2442 if (!test_bit(CNIC_F_BNX2X_CLASS
, &dev
->flags
)) {
2443 printk(KERN_ERR PFX
"bnx2fc port check: %s, flags: %lx\n",
2444 dev
->netdev
->name
, dev
->flags
);
2448 mutex_lock(&bnx2fc_dev_lock
);
2449 hba
= bnx2fc_find_hba_for_cnic(dev
);
2451 printk(KERN_ERR PFX
"bnx2fc_ulp_exit: hba not found, dev 0%p\n",
2453 mutex_unlock(&bnx2fc_dev_lock
);
2457 list_del_init(&hba
->list
);
2460 list_for_each_entry_safe(interface
, tmp
, &if_list
, list
)
2461 /* destroy not called yet, move to quiesced list */
2462 if (interface
->hba
== hba
)
2463 __bnx2fc_destroy(interface
);
2464 mutex_unlock(&bnx2fc_dev_lock
);
2466 /* Ensure ALL destroy work has been completed before return */
2467 flush_workqueue(bnx2fc_wq
);
2469 bnx2fc_ulp_stop(hba
);
2470 /* unregister cnic device */
2471 if (test_and_clear_bit(BNX2FC_CNIC_REGISTERED
, &hba
->reg_with_cnic
))
2472 hba
->cnic
->unregister_device(hba
->cnic
, CNIC_ULP_FCOE
);
2473 bnx2fc_hba_destroy(hba
);
2477 * bnx2fc_fcoe_reset - Resets the fcoe
2479 * @shost: shost the reset is from
2483 static int bnx2fc_fcoe_reset(struct Scsi_Host
*shost
)
2485 struct fc_lport
*lport
= shost_priv(shost
);
2486 fc_lport_reset(lport
);
2491 static bool bnx2fc_match(struct net_device
*netdev
)
2493 struct net_device
*phys_dev
= netdev
;
2495 mutex_lock(&bnx2fc_dev_lock
);
2496 if (netdev
->priv_flags
& IFF_802_1Q_VLAN
)
2497 phys_dev
= vlan_dev_real_dev(netdev
);
2499 if (bnx2fc_hba_lookup(phys_dev
)) {
2500 mutex_unlock(&bnx2fc_dev_lock
);
2504 mutex_unlock(&bnx2fc_dev_lock
);
2509 static struct fcoe_transport bnx2fc_transport
= {
2512 .list
= LIST_HEAD_INIT(bnx2fc_transport
.list
),
2513 .alloc
= bnx2fc_ctlr_alloc
,
2514 .match
= bnx2fc_match
,
2515 .create
= bnx2fc_create
,
2516 .destroy
= bnx2fc_destroy
,
2517 .enable
= bnx2fc_enable
,
2518 .disable
= bnx2fc_disable
,
2522 * bnx2fc_percpu_thread_create - Create a receive thread for an
2525 * @cpu: cpu index for the online cpu
2527 static void bnx2fc_percpu_thread_create(unsigned int cpu
)
2529 struct bnx2fc_percpu_s
*p
;
2530 struct task_struct
*thread
;
2532 p
= &per_cpu(bnx2fc_percpu
, cpu
);
2534 thread
= kthread_create_on_node(bnx2fc_percpu_io_thread
,
2535 (void *)p
, cpu_to_node(cpu
),
2536 "bnx2fc_thread/%d", cpu
);
2537 /* bind thread to the cpu */
2538 if (likely(!IS_ERR(thread
))) {
2539 kthread_bind(thread
, cpu
);
2540 p
->iothread
= thread
;
2541 wake_up_process(thread
);
2545 static void bnx2fc_percpu_thread_destroy(unsigned int cpu
)
2547 struct bnx2fc_percpu_s
*p
;
2548 struct task_struct
*thread
;
2549 struct bnx2fc_work
*work
, *tmp
;
2551 BNX2FC_MISC_DBG("destroying io thread for CPU %d\n", cpu
);
2553 /* Prevent any new work from being queued for this CPU */
2554 p
= &per_cpu(bnx2fc_percpu
, cpu
);
2555 spin_lock_bh(&p
->fp_work_lock
);
2556 thread
= p
->iothread
;
2560 /* Free all work in the list */
2561 list_for_each_entry_safe(work
, tmp
, &p
->work_list
, list
) {
2562 list_del_init(&work
->list
);
2563 bnx2fc_process_cq_compl(work
->tgt
, work
->wqe
);
2567 spin_unlock_bh(&p
->fp_work_lock
);
2570 kthread_stop(thread
);
2574 * bnx2fc_cpu_callback - Handler for CPU hotplug events
2576 * @nfb: The callback data block
2577 * @action: The event triggering the callback
2578 * @hcpu: The index of the CPU that the event is for
2580 * This creates or destroys per-CPU data for fcoe
2582 * Returns NOTIFY_OK always.
2584 static int bnx2fc_cpu_callback(struct notifier_block
*nfb
,
2585 unsigned long action
, void *hcpu
)
2587 unsigned cpu
= (unsigned long)hcpu
;
2591 case CPU_ONLINE_FROZEN
:
2592 printk(PFX
"CPU %x online: Create Rx thread\n", cpu
);
2593 bnx2fc_percpu_thread_create(cpu
);
2596 case CPU_DEAD_FROZEN
:
2597 printk(PFX
"CPU %x offline: Remove Rx thread\n", cpu
);
2598 bnx2fc_percpu_thread_destroy(cpu
);
2607 * bnx2fc_mod_init - module init entry point
2609 * Initialize driver wide global data structures, and register
2612 static int __init
bnx2fc_mod_init(void)
2614 struct fcoe_percpu_s
*bg
;
2615 struct task_struct
*l2_thread
;
2617 unsigned int cpu
= 0;
2618 struct bnx2fc_percpu_s
*p
;
2620 printk(KERN_INFO PFX
"%s", version
);
2622 /* register as a fcoe transport */
2623 rc
= fcoe_transport_attach(&bnx2fc_transport
);
2625 printk(KERN_ERR
"failed to register an fcoe transport, check "
2626 "if libfcoe is loaded\n");
2630 INIT_LIST_HEAD(&adapter_list
);
2631 INIT_LIST_HEAD(&if_list
);
2632 mutex_init(&bnx2fc_dev_lock
);
2635 /* Attach FC transport template */
2636 rc
= bnx2fc_attach_transport();
2640 bnx2fc_wq
= alloc_workqueue("bnx2fc", 0, 0);
2646 bg
= &bnx2fc_global
;
2647 skb_queue_head_init(&bg
->fcoe_rx_list
);
2648 l2_thread
= kthread_create(bnx2fc_l2_rcv_thread
,
2650 "bnx2fc_l2_thread");
2651 if (IS_ERR(l2_thread
)) {
2652 rc
= PTR_ERR(l2_thread
);
2655 wake_up_process(l2_thread
);
2656 spin_lock_bh(&bg
->fcoe_rx_list
.lock
);
2657 bg
->thread
= l2_thread
;
2658 spin_unlock_bh(&bg
->fcoe_rx_list
.lock
);
2660 for_each_possible_cpu(cpu
) {
2661 p
= &per_cpu(bnx2fc_percpu
, cpu
);
2662 INIT_LIST_HEAD(&p
->work_list
);
2663 spin_lock_init(&p
->fp_work_lock
);
2666 cpu_notifier_register_begin();
2668 for_each_online_cpu(cpu
) {
2669 bnx2fc_percpu_thread_create(cpu
);
2672 /* Initialize per CPU interrupt thread */
2673 __register_hotcpu_notifier(&bnx2fc_cpu_notifier
);
2675 cpu_notifier_register_done();
2677 cnic_register_driver(CNIC_ULP_FCOE
, &bnx2fc_cnic_cb
);
2682 destroy_workqueue(bnx2fc_wq
);
2684 bnx2fc_release_transport();
2686 fcoe_transport_detach(&bnx2fc_transport
);
2691 static void __exit
bnx2fc_mod_exit(void)
2693 LIST_HEAD(to_be_deleted
);
2694 struct bnx2fc_hba
*hba
, *next
;
2695 struct fcoe_percpu_s
*bg
;
2696 struct task_struct
*l2_thread
;
2697 struct sk_buff
*skb
;
2698 unsigned int cpu
= 0;
2701 * NOTE: Since cnic calls register_driver routine rtnl_lock,
2702 * it will have higher precedence than bnx2fc_dev_lock.
2703 * unregister_device() cannot be called with bnx2fc_dev_lock
2706 mutex_lock(&bnx2fc_dev_lock
);
2707 list_splice(&adapter_list
, &to_be_deleted
);
2708 INIT_LIST_HEAD(&adapter_list
);
2710 mutex_unlock(&bnx2fc_dev_lock
);
2712 /* Unregister with cnic */
2713 list_for_each_entry_safe(hba
, next
, &to_be_deleted
, list
) {
2714 list_del_init(&hba
->list
);
2715 printk(KERN_ERR PFX
"MOD_EXIT:destroy hba = 0x%p\n",
2717 bnx2fc_ulp_stop(hba
);
2718 /* unregister cnic device */
2719 if (test_and_clear_bit(BNX2FC_CNIC_REGISTERED
,
2720 &hba
->reg_with_cnic
))
2721 hba
->cnic
->unregister_device(hba
->cnic
,
2723 bnx2fc_hba_destroy(hba
);
2725 cnic_unregister_driver(CNIC_ULP_FCOE
);
2727 /* Destroy global thread */
2728 bg
= &bnx2fc_global
;
2729 spin_lock_bh(&bg
->fcoe_rx_list
.lock
);
2730 l2_thread
= bg
->thread
;
2732 while ((skb
= __skb_dequeue(&bg
->fcoe_rx_list
)) != NULL
)
2735 spin_unlock_bh(&bg
->fcoe_rx_list
.lock
);
2738 kthread_stop(l2_thread
);
2740 cpu_notifier_register_begin();
2742 /* Destroy per cpu threads */
2743 for_each_online_cpu(cpu
) {
2744 bnx2fc_percpu_thread_destroy(cpu
);
2747 __unregister_hotcpu_notifier(&bnx2fc_cpu_notifier
);
2749 cpu_notifier_register_done();
2751 destroy_workqueue(bnx2fc_wq
);
2753 * detach from scsi transport
2754 * must happen after all destroys are done
2756 bnx2fc_release_transport();
2758 /* detach from fcoe transport */
2759 fcoe_transport_detach(&bnx2fc_transport
);
2762 module_init(bnx2fc_mod_init
);
2763 module_exit(bnx2fc_mod_exit
);
2765 static struct fcoe_sysfs_function_template bnx2fc_fcoe_sysfs_templ
= {
2766 .set_fcoe_ctlr_enabled
= bnx2fc_ctlr_enabled
,
2767 .get_fcoe_ctlr_link_fail
= fcoe_ctlr_get_lesb
,
2768 .get_fcoe_ctlr_vlink_fail
= fcoe_ctlr_get_lesb
,
2769 .get_fcoe_ctlr_miss_fka
= fcoe_ctlr_get_lesb
,
2770 .get_fcoe_ctlr_symb_err
= fcoe_ctlr_get_lesb
,
2771 .get_fcoe_ctlr_err_block
= fcoe_ctlr_get_lesb
,
2772 .get_fcoe_ctlr_fcs_error
= fcoe_ctlr_get_lesb
,
2774 .get_fcoe_fcf_selected
= fcoe_fcf_get_selected
,
2775 .get_fcoe_fcf_vlan_id
= bnx2fc_fcf_get_vlan_id
,
2778 static struct fc_function_template bnx2fc_transport_function
= {
2779 .show_host_node_name
= 1,
2780 .show_host_port_name
= 1,
2781 .show_host_supported_classes
= 1,
2782 .show_host_supported_fc4s
= 1,
2783 .show_host_active_fc4s
= 1,
2784 .show_host_maxframe_size
= 1,
2786 .show_host_port_id
= 1,
2787 .show_host_supported_speeds
= 1,
2788 .get_host_speed
= fc_get_host_speed
,
2789 .show_host_speed
= 1,
2790 .show_host_port_type
= 1,
2791 .get_host_port_state
= fc_get_host_port_state
,
2792 .show_host_port_state
= 1,
2793 .show_host_symbolic_name
= 1,
2795 .dd_fcrport_size
= (sizeof(struct fc_rport_libfc_priv
) +
2796 sizeof(struct bnx2fc_rport
)),
2797 .show_rport_maxframe_size
= 1,
2798 .show_rport_supported_classes
= 1,
2800 .show_host_fabric_name
= 1,
2801 .show_starget_node_name
= 1,
2802 .show_starget_port_name
= 1,
2803 .show_starget_port_id
= 1,
2804 .set_rport_dev_loss_tmo
= fc_set_rport_loss_tmo
,
2805 .show_rport_dev_loss_tmo
= 1,
2806 .get_fc_host_stats
= bnx2fc_get_host_stats
,
2808 .issue_fc_host_lip
= bnx2fc_fcoe_reset
,
2810 .terminate_rport_io
= fc_rport_terminate_io
,
2812 .vport_create
= bnx2fc_vport_create
,
2813 .vport_delete
= bnx2fc_vport_destroy
,
2814 .vport_disable
= bnx2fc_vport_disable
,
2815 .bsg_request
= fc_lport_bsg_request
,
2818 static struct fc_function_template bnx2fc_vport_xport_function
= {
2819 .show_host_node_name
= 1,
2820 .show_host_port_name
= 1,
2821 .show_host_supported_classes
= 1,
2822 .show_host_supported_fc4s
= 1,
2823 .show_host_active_fc4s
= 1,
2824 .show_host_maxframe_size
= 1,
2826 .show_host_port_id
= 1,
2827 .show_host_supported_speeds
= 1,
2828 .get_host_speed
= fc_get_host_speed
,
2829 .show_host_speed
= 1,
2830 .show_host_port_type
= 1,
2831 .get_host_port_state
= fc_get_host_port_state
,
2832 .show_host_port_state
= 1,
2833 .show_host_symbolic_name
= 1,
2835 .dd_fcrport_size
= (sizeof(struct fc_rport_libfc_priv
) +
2836 sizeof(struct bnx2fc_rport
)),
2837 .show_rport_maxframe_size
= 1,
2838 .show_rport_supported_classes
= 1,
2840 .show_host_fabric_name
= 1,
2841 .show_starget_node_name
= 1,
2842 .show_starget_port_name
= 1,
2843 .show_starget_port_id
= 1,
2844 .set_rport_dev_loss_tmo
= fc_set_rport_loss_tmo
,
2845 .show_rport_dev_loss_tmo
= 1,
2846 .get_fc_host_stats
= fc_get_host_stats
,
2847 .issue_fc_host_lip
= bnx2fc_fcoe_reset
,
2848 .terminate_rport_io
= fc_rport_terminate_io
,
2849 .bsg_request
= fc_lport_bsg_request
,
2853 * scsi_host_template structure used while registering with SCSI-ml
2855 static struct scsi_host_template bnx2fc_shost_template
= {
2856 .module
= THIS_MODULE
,
2857 .name
= "QLogic Offload FCoE Initiator",
2858 .queuecommand
= bnx2fc_queuecommand
,
2859 .eh_abort_handler
= bnx2fc_eh_abort
, /* abts */
2860 .eh_device_reset_handler
= bnx2fc_eh_device_reset
, /* lun reset */
2861 .eh_target_reset_handler
= bnx2fc_eh_target_reset
, /* tgt reset */
2862 .eh_host_reset_handler
= fc_eh_host_reset
,
2863 .slave_alloc
= fc_slave_alloc
,
2864 .change_queue_depth
= scsi_change_queue_depth
,
2867 .use_clustering
= ENABLE_CLUSTERING
,
2868 .sg_tablesize
= BNX2FC_MAX_BDS_PER_CMD
,
2869 .max_sectors
= 1024,
2870 .track_queue_depth
= 1,
2873 static struct libfc_function_template bnx2fc_libfc_fcn_templ
= {
2874 .frame_send
= bnx2fc_xmit
,
2875 .elsct_send
= bnx2fc_elsct_send
,
2876 .fcp_abort_io
= bnx2fc_abort_io
,
2877 .fcp_cleanup
= bnx2fc_cleanup
,
2878 .get_lesb
= fcoe_get_lesb
,
2879 .rport_event_callback
= bnx2fc_rport_event_handler
,
2883 * bnx2fc_cnic_cb - global template of bnx2fc - cnic driver interface
2884 * structure carrying callback function pointers
2886 static struct cnic_ulp_ops bnx2fc_cnic_cb
= {
2887 .owner
= THIS_MODULE
,
2888 .cnic_init
= bnx2fc_ulp_init
,
2889 .cnic_exit
= bnx2fc_ulp_exit
,
2890 .cnic_start
= bnx2fc_ulp_start
,
2891 .cnic_stop
= bnx2fc_ulp_stop
,
2892 .indicate_kcqes
= bnx2fc_indicate_kcqe
,
2893 .indicate_netevent
= bnx2fc_indicate_netevent
,
2894 .cnic_get_stats
= bnx2fc_ulp_get_stats
,