1 /* bnx2fc_fcoe.c: QLogic NetXtreme II Linux FCoE offload driver.
2 * This file contains the code that interacts with libfc, libfcoe,
3 * cnic modules to create FCoE instances, send/receive non-offloaded
4 * FIP/FCoE packets, listen to link events etc.
6 * Copyright (c) 2008 - 2013 Broadcom Corporation
7 * Copyright (c) 2014, 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 "Dec 11, 2013"
29 static char version
[] =
30 "QLogic NetXtreme II 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 NetXtreme II BCM57710 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
);
859 printk(KERN_ERR PFX
"Unknown netevent %ld", event
);
863 mutex_lock(&bnx2fc_dev_lock
);
864 list_for_each_entry(interface
, &if_list
, list
) {
866 if (interface
->hba
!= hba
)
869 ctlr
= bnx2fc_to_ctlr(interface
);
871 BNX2FC_HBA_DBG(lport
, "netevent handler - event=%s %ld\n",
872 interface
->netdev
->name
, event
);
874 fcoe_link_speed_update(lport
);
876 cdev
= fcoe_ctlr_to_ctlr_dev(ctlr
);
878 if (link_possible
&& !bnx2fc_link_ok(lport
)) {
879 switch (cdev
->enabled
) {
880 case FCOE_CTLR_DISABLED
:
881 pr_info("Link up while interface is disabled.\n");
883 case FCOE_CTLR_ENABLED
:
884 case FCOE_CTLR_UNUSED
:
885 /* Reset max recv frame size to default */
886 fc_set_mfs(lport
, BNX2FC_MFS
);
888 * ctlr link up will only be handled during
889 * enable to avoid sending discovery
890 * solicitation on a stale vlan
892 if (interface
->enabled
)
893 fcoe_ctlr_link_up(ctlr
);
895 } else if (fcoe_ctlr_link_down(ctlr
)) {
896 switch (cdev
->enabled
) {
897 case FCOE_CTLR_DISABLED
:
898 pr_info("Link down while interface is disabled.\n");
900 case FCOE_CTLR_ENABLED
:
901 case FCOE_CTLR_UNUSED
:
902 mutex_lock(&lport
->lp_mutex
);
903 list_for_each_entry(vport
, &lport
->vports
, list
)
904 fc_host_port_type(vport
->host
) =
906 mutex_unlock(&lport
->lp_mutex
);
907 fc_host_port_type(lport
->host
) =
909 per_cpu_ptr(lport
->stats
,
910 get_cpu())->LinkFailureCount
++;
912 fcoe_clean_pending_queue(lport
);
917 mutex_unlock(&bnx2fc_dev_lock
);
919 if (wait_for_upload
) {
920 clear_bit(ADAPTER_STATE_READY
, &hba
->adapter_state
);
921 init_waitqueue_head(&hba
->shutdown_wait
);
922 BNX2FC_MISC_DBG("indicate_netevent "
923 "num_ofld_sess = %d\n",
925 hba
->wait_for_link_down
= 1;
926 wait_event_interruptible(hba
->shutdown_wait
,
927 (hba
->num_ofld_sess
== 0));
928 BNX2FC_MISC_DBG("wakeup - num_ofld_sess = %d\n",
930 hba
->wait_for_link_down
= 0;
932 if (signal_pending(current
))
933 flush_signals(current
);
937 static int bnx2fc_libfc_config(struct fc_lport
*lport
)
940 /* Set the function pointers set by bnx2fc driver */
941 memcpy(&lport
->tt
, &bnx2fc_libfc_fcn_templ
,
942 sizeof(struct libfc_function_template
));
943 fc_elsct_init(lport
);
945 fc_rport_init(lport
);
947 fc_disc_config(lport
, lport
);
951 static int bnx2fc_em_config(struct fc_lport
*lport
, struct bnx2fc_hba
*hba
)
953 int fcoe_min_xid
, fcoe_max_xid
;
955 fcoe_min_xid
= hba
->max_xid
+ 1;
957 fcoe_max_xid
= hba
->max_xid
+ FCOE_XIDS_PER_CPU_OFFSET
;
959 fcoe_max_xid
= hba
->max_xid
+ FCOE_MAX_XID_OFFSET
;
960 if (!fc_exch_mgr_alloc(lport
, FC_CLASS_3
, fcoe_min_xid
,
961 fcoe_max_xid
, NULL
)) {
962 printk(KERN_ERR PFX
"em_config:fc_exch_mgr_alloc failed\n");
969 static int bnx2fc_lport_config(struct fc_lport
*lport
)
973 lport
->max_retry_count
= BNX2FC_MAX_RETRY_CNT
;
974 lport
->max_rport_retry_count
= BNX2FC_MAX_RPORT_RETRY_CNT
;
975 lport
->e_d_tov
= 2 * 1000;
976 lport
->r_a_tov
= 10 * 1000;
978 lport
->service_params
= (FCP_SPPF_INIT_FCN
| FCP_SPPF_RD_XRDY_DIS
|
979 FCP_SPPF_RETRY
| FCP_SPPF_CONF_COMPL
);
980 lport
->does_npiv
= 1;
982 memset(&lport
->rnid_gen
, 0, sizeof(struct fc_els_rnid_gen
));
983 lport
->rnid_gen
.rnid_atype
= BNX2FC_RNID_HBA
;
985 /* alloc stats structure */
986 if (fc_lport_init_stats(lport
))
989 /* Finish fc_lport configuration */
990 fc_lport_config(lport
);
996 * bnx2fc_fip_recv - handle a received FIP frame.
998 * @skb: the received skb
999 * @dev: associated &net_device
1000 * @ptype: the &packet_type structure which was used to register this handler.
1001 * @orig_dev: original receive &net_device, in case @ dev is a bond.
1003 * Returns: 0 for success
1005 static int bnx2fc_fip_recv(struct sk_buff
*skb
, struct net_device
*dev
,
1006 struct packet_type
*ptype
,
1007 struct net_device
*orig_dev
)
1009 struct bnx2fc_interface
*interface
;
1010 struct fcoe_ctlr
*ctlr
;
1011 interface
= container_of(ptype
, struct bnx2fc_interface
,
1013 ctlr
= bnx2fc_to_ctlr(interface
);
1014 fcoe_ctlr_recv(ctlr
, skb
);
1019 * bnx2fc_update_src_mac - Update Ethernet MAC filters.
1021 * @fip: FCoE controller.
1022 * @old: Unicast MAC address to delete if the MAC is non-zero.
1023 * @new: Unicast MAC address to add.
1025 * Remove any previously-set unicast MAC filter.
1026 * Add secondary FCoE MAC address filter for our OUI.
1028 static void bnx2fc_update_src_mac(struct fc_lport
*lport
, u8
*addr
)
1030 struct fcoe_port
*port
= lport_priv(lport
);
1032 memcpy(port
->data_src_addr
, addr
, ETH_ALEN
);
1036 * bnx2fc_get_src_mac - return the ethernet source address for an lport
1038 * @lport: libfc port
1040 static u8
*bnx2fc_get_src_mac(struct fc_lport
*lport
)
1042 struct fcoe_port
*port
;
1044 port
= (struct fcoe_port
*)lport_priv(lport
);
1045 return port
->data_src_addr
;
1049 * bnx2fc_fip_send - send an Ethernet-encapsulated FIP frame.
1051 * @fip: FCoE controller.
1054 static void bnx2fc_fip_send(struct fcoe_ctlr
*fip
, struct sk_buff
*skb
)
1056 skb
->dev
= bnx2fc_from_ctlr(fip
)->netdev
;
1057 dev_queue_xmit(skb
);
1060 static int bnx2fc_vport_create(struct fc_vport
*vport
, bool disabled
)
1062 struct Scsi_Host
*shost
= vport_to_shost(vport
);
1063 struct fc_lport
*n_port
= shost_priv(shost
);
1064 struct fcoe_port
*port
= lport_priv(n_port
);
1065 struct bnx2fc_interface
*interface
= port
->priv
;
1066 struct net_device
*netdev
= interface
->netdev
;
1067 struct fc_lport
*vn_port
;
1071 rc
= fcoe_validate_vport_create(vport
);
1073 fcoe_wwn_to_str(vport
->port_name
, buf
, sizeof(buf
));
1074 printk(KERN_ERR PFX
"Failed to create vport, "
1075 "WWPN (0x%s) already exists\n",
1080 if (!test_bit(BNX2FC_FLAG_FW_INIT_DONE
, &interface
->hba
->flags
)) {
1081 printk(KERN_ERR PFX
"vn ports cannot be created on"
1082 "this interface\n");
1086 mutex_lock(&bnx2fc_dev_lock
);
1087 vn_port
= bnx2fc_if_create(interface
, &vport
->dev
, 1);
1088 mutex_unlock(&bnx2fc_dev_lock
);
1092 printk(KERN_ERR PFX
"bnx2fc_vport_create (%s) failed\n",
1098 fc_vport_set_state(vport
, FC_VPORT_DISABLED
);
1100 vn_port
->boot_time
= jiffies
;
1101 fc_lport_init(vn_port
);
1102 fc_fabric_login(vn_port
);
1103 fc_vport_setlink(vn_port
);
1108 static void bnx2fc_free_vport(struct bnx2fc_hba
*hba
, struct fc_lport
*lport
)
1110 struct bnx2fc_lport
*blport
, *tmp
;
1112 spin_lock_bh(&hba
->hba_lock
);
1113 list_for_each_entry_safe(blport
, tmp
, &hba
->vports
, list
) {
1114 if (blport
->lport
== lport
) {
1115 list_del(&blport
->list
);
1119 spin_unlock_bh(&hba
->hba_lock
);
1122 static int bnx2fc_vport_destroy(struct fc_vport
*vport
)
1124 struct Scsi_Host
*shost
= vport_to_shost(vport
);
1125 struct fc_lport
*n_port
= shost_priv(shost
);
1126 struct fc_lport
*vn_port
= vport
->dd_data
;
1127 struct fcoe_port
*port
= lport_priv(vn_port
);
1128 struct bnx2fc_interface
*interface
= port
->priv
;
1129 struct fc_lport
*v_port
;
1132 mutex_lock(&n_port
->lp_mutex
);
1133 list_for_each_entry(v_port
, &n_port
->vports
, list
)
1134 if (v_port
->vport
== vport
) {
1140 mutex_unlock(&n_port
->lp_mutex
);
1143 list_del(&vn_port
->list
);
1144 mutex_unlock(&n_port
->lp_mutex
);
1145 bnx2fc_free_vport(interface
->hba
, port
->lport
);
1146 bnx2fc_port_shutdown(port
->lport
);
1147 bnx2fc_interface_put(interface
);
1148 queue_work(bnx2fc_wq
, &port
->destroy_work
);
1152 static int bnx2fc_vport_disable(struct fc_vport
*vport
, bool disable
)
1154 struct fc_lport
*lport
= vport
->dd_data
;
1157 fc_vport_set_state(vport
, FC_VPORT_DISABLED
);
1158 fc_fabric_logoff(lport
);
1160 lport
->boot_time
= jiffies
;
1161 fc_fabric_login(lport
);
1162 fc_vport_setlink(lport
);
1168 static int bnx2fc_interface_setup(struct bnx2fc_interface
*interface
)
1170 struct net_device
*netdev
= interface
->netdev
;
1171 struct net_device
*physdev
= interface
->hba
->phys_dev
;
1172 struct fcoe_ctlr
*ctlr
= bnx2fc_to_ctlr(interface
);
1173 struct netdev_hw_addr
*ha
;
1174 int sel_san_mac
= 0;
1176 /* setup Source MAC Address */
1178 for_each_dev_addr(physdev
, ha
) {
1179 BNX2FC_MISC_DBG("net_config: ha->type = %d, fip_mac = ",
1181 printk(KERN_INFO
"%2x:%2x:%2x:%2x:%2x:%2x\n", ha
->addr
[0],
1182 ha
->addr
[1], ha
->addr
[2], ha
->addr
[3],
1183 ha
->addr
[4], ha
->addr
[5]);
1185 if ((ha
->type
== NETDEV_HW_ADDR_T_SAN
) &&
1186 (is_valid_ether_addr(ha
->addr
))) {
1187 memcpy(ctlr
->ctl_src_addr
, ha
->addr
,
1190 BNX2FC_MISC_DBG("Found SAN MAC\n");
1198 interface
->fip_packet_type
.func
= bnx2fc_fip_recv
;
1199 interface
->fip_packet_type
.type
= htons(ETH_P_FIP
);
1200 interface
->fip_packet_type
.dev
= netdev
;
1201 dev_add_pack(&interface
->fip_packet_type
);
1203 interface
->fcoe_packet_type
.func
= bnx2fc_rcv
;
1204 interface
->fcoe_packet_type
.type
= __constant_htons(ETH_P_FCOE
);
1205 interface
->fcoe_packet_type
.dev
= netdev
;
1206 dev_add_pack(&interface
->fcoe_packet_type
);
1211 static int bnx2fc_attach_transport(void)
1213 bnx2fc_transport_template
=
1214 fc_attach_transport(&bnx2fc_transport_function
);
1216 if (bnx2fc_transport_template
== NULL
) {
1217 printk(KERN_ERR PFX
"Failed to attach FC transport\n");
1221 bnx2fc_vport_xport_template
=
1222 fc_attach_transport(&bnx2fc_vport_xport_function
);
1223 if (bnx2fc_vport_xport_template
== NULL
) {
1225 "Failed to attach FC transport for vport\n");
1226 fc_release_transport(bnx2fc_transport_template
);
1227 bnx2fc_transport_template
= NULL
;
1232 static void bnx2fc_release_transport(void)
1234 fc_release_transport(bnx2fc_transport_template
);
1235 fc_release_transport(bnx2fc_vport_xport_template
);
1236 bnx2fc_transport_template
= NULL
;
1237 bnx2fc_vport_xport_template
= NULL
;
1240 static void bnx2fc_interface_release(struct kref
*kref
)
1242 struct fcoe_ctlr_device
*ctlr_dev
;
1243 struct bnx2fc_interface
*interface
;
1244 struct fcoe_ctlr
*ctlr
;
1245 struct net_device
*netdev
;
1247 interface
= container_of(kref
, struct bnx2fc_interface
, kref
);
1248 BNX2FC_MISC_DBG("Interface is being released\n");
1250 ctlr
= bnx2fc_to_ctlr(interface
);
1251 ctlr_dev
= fcoe_ctlr_to_ctlr_dev(ctlr
);
1252 netdev
= interface
->netdev
;
1254 /* tear-down FIP controller */
1255 if (test_and_clear_bit(BNX2FC_CTLR_INIT_DONE
, &interface
->if_flags
))
1256 fcoe_ctlr_destroy(ctlr
);
1258 fcoe_ctlr_device_delete(ctlr_dev
);
1261 module_put(THIS_MODULE
);
1264 static inline void bnx2fc_interface_get(struct bnx2fc_interface
*interface
)
1266 kref_get(&interface
->kref
);
1269 static inline void bnx2fc_interface_put(struct bnx2fc_interface
*interface
)
1271 kref_put(&interface
->kref
, bnx2fc_interface_release
);
1273 static void bnx2fc_hba_destroy(struct bnx2fc_hba
*hba
)
1275 /* Free the command manager */
1277 bnx2fc_cmd_mgr_free(hba
->cmd_mgr
);
1278 hba
->cmd_mgr
= NULL
;
1280 kfree(hba
->tgt_ofld_list
);
1281 bnx2fc_unbind_pcidev(hba
);
1286 * bnx2fc_hba_create - create a new bnx2fc hba
1288 * @cnic: pointer to cnic device
1290 * Creates a new FCoE hba on the given device.
1293 static struct bnx2fc_hba
*bnx2fc_hba_create(struct cnic_dev
*cnic
)
1295 struct bnx2fc_hba
*hba
;
1296 struct fcoe_capabilities
*fcoe_cap
;
1299 hba
= kzalloc(sizeof(*hba
), GFP_KERNEL
);
1301 printk(KERN_ERR PFX
"Unable to allocate hba structure\n");
1304 spin_lock_init(&hba
->hba_lock
);
1305 mutex_init(&hba
->hba_mutex
);
1309 hba
->max_tasks
= cnic
->max_fcoe_exchanges
;
1310 hba
->elstm_xids
= (hba
->max_tasks
/ 2);
1311 hba
->max_outstanding_cmds
= hba
->elstm_xids
;
1312 hba
->max_xid
= (hba
->max_tasks
- 1);
1314 rc
= bnx2fc_bind_pcidev(hba
);
1316 printk(KERN_ERR PFX
"create_adapter: bind error\n");
1319 hba
->phys_dev
= cnic
->netdev
;
1320 hba
->next_conn_id
= 0;
1322 hba
->tgt_ofld_list
=
1323 kzalloc(sizeof(struct bnx2fc_rport
*) * BNX2FC_NUM_MAX_SESS
,
1325 if (!hba
->tgt_ofld_list
) {
1326 printk(KERN_ERR PFX
"Unable to allocate tgt offload list\n");
1330 hba
->num_ofld_sess
= 0;
1332 hba
->cmd_mgr
= bnx2fc_cmd_mgr_alloc(hba
);
1333 if (!hba
->cmd_mgr
) {
1334 printk(KERN_ERR PFX
"em_config:bnx2fc_cmd_mgr_alloc failed\n");
1337 fcoe_cap
= &hba
->fcoe_cap
;
1339 fcoe_cap
->capability1
= BNX2FC_TM_MAX_SQES
<<
1340 FCOE_IOS_PER_CONNECTION_SHIFT
;
1341 fcoe_cap
->capability1
|= BNX2FC_NUM_MAX_SESS
<<
1342 FCOE_LOGINS_PER_PORT_SHIFT
;
1343 fcoe_cap
->capability2
= hba
->max_outstanding_cmds
<<
1344 FCOE_NUMBER_OF_EXCHANGES_SHIFT
;
1345 fcoe_cap
->capability2
|= BNX2FC_MAX_NPIV
<<
1346 FCOE_NPIV_WWN_PER_PORT_SHIFT
;
1347 fcoe_cap
->capability3
= BNX2FC_NUM_MAX_SESS
<<
1348 FCOE_TARGETS_SUPPORTED_SHIFT
;
1349 fcoe_cap
->capability3
|= hba
->max_outstanding_cmds
<<
1350 FCOE_OUTSTANDING_COMMANDS_SHIFT
;
1351 fcoe_cap
->capability4
= FCOE_CAPABILITY4_STATEFUL
;
1353 init_waitqueue_head(&hba
->shutdown_wait
);
1354 init_waitqueue_head(&hba
->destroy_wait
);
1355 INIT_LIST_HEAD(&hba
->vports
);
1360 kfree(hba
->tgt_ofld_list
);
1362 bnx2fc_unbind_pcidev(hba
);
1368 struct bnx2fc_interface
*bnx2fc_interface_create(struct bnx2fc_hba
*hba
,
1369 struct net_device
*netdev
,
1370 enum fip_state fip_mode
)
1372 struct fcoe_ctlr_device
*ctlr_dev
;
1373 struct bnx2fc_interface
*interface
;
1374 struct fcoe_ctlr
*ctlr
;
1378 size
= (sizeof(*interface
) + sizeof(struct fcoe_ctlr
));
1379 ctlr_dev
= fcoe_ctlr_device_add(&netdev
->dev
, &bnx2fc_fcoe_sysfs_templ
,
1382 printk(KERN_ERR PFX
"Unable to allocate interface structure\n");
1385 ctlr
= fcoe_ctlr_device_priv(ctlr_dev
);
1386 ctlr
->cdev
= ctlr_dev
;
1387 interface
= fcoe_ctlr_priv(ctlr
);
1389 kref_init(&interface
->kref
);
1390 interface
->hba
= hba
;
1391 interface
->netdev
= netdev
;
1393 /* Initialize FIP */
1394 fcoe_ctlr_init(ctlr
, fip_mode
);
1395 ctlr
->send
= bnx2fc_fip_send
;
1396 ctlr
->update_mac
= bnx2fc_update_src_mac
;
1397 ctlr
->get_src_addr
= bnx2fc_get_src_mac
;
1398 set_bit(BNX2FC_CTLR_INIT_DONE
, &interface
->if_flags
);
1400 rc
= bnx2fc_interface_setup(interface
);
1404 fcoe_ctlr_destroy(ctlr
);
1406 fcoe_ctlr_device_delete(ctlr_dev
);
1411 * bnx2fc_if_create - Create FCoE instance on a given interface
1413 * @interface: FCoE interface to create a local port on
1414 * @parent: Device pointer to be the parent in sysfs for the SCSI host
1415 * @npiv: Indicates if the port is vport or not
1417 * Creates a fc_lport instance and a Scsi_Host instance and configure them.
1419 * Returns: Allocated fc_lport or an error pointer
1421 static struct fc_lport
*bnx2fc_if_create(struct bnx2fc_interface
*interface
,
1422 struct device
*parent
, int npiv
)
1424 struct fcoe_ctlr
*ctlr
= bnx2fc_to_ctlr(interface
);
1425 struct fc_lport
*lport
, *n_port
;
1426 struct fcoe_port
*port
;
1427 struct Scsi_Host
*shost
;
1428 struct fc_vport
*vport
= dev_to_vport(parent
);
1429 struct bnx2fc_lport
*blport
;
1430 struct bnx2fc_hba
*hba
= interface
->hba
;
1433 blport
= kzalloc(sizeof(struct bnx2fc_lport
), GFP_KERNEL
);
1435 BNX2FC_HBA_DBG(ctlr
->lp
, "Unable to alloc blport\n");
1439 /* Allocate Scsi_Host structure */
1440 bnx2fc_shost_template
.can_queue
= hba
->max_outstanding_cmds
;
1442 lport
= libfc_host_alloc(&bnx2fc_shost_template
, sizeof(*port
));
1444 lport
= libfc_vport_create(vport
, sizeof(*port
));
1447 printk(KERN_ERR PFX
"could not allocate scsi host structure\n");
1450 shost
= lport
->host
;
1451 port
= lport_priv(lport
);
1452 port
->lport
= lport
;
1453 port
->priv
= interface
;
1454 port
->get_netdev
= bnx2fc_netdev
;
1455 INIT_WORK(&port
->destroy_work
, bnx2fc_destroy_work
);
1457 /* Configure fcoe_port */
1458 rc
= bnx2fc_lport_config(lport
);
1463 printk(KERN_ERR PFX
"Setting vport names, 0x%llX 0x%llX\n",
1464 vport
->node_name
, vport
->port_name
);
1465 fc_set_wwnn(lport
, vport
->node_name
);
1466 fc_set_wwpn(lport
, vport
->port_name
);
1468 /* Configure netdev and networking properties of the lport */
1469 rc
= bnx2fc_net_config(lport
, interface
->netdev
);
1471 printk(KERN_ERR PFX
"Error on bnx2fc_net_config\n");
1475 rc
= bnx2fc_shost_config(lport
, parent
);
1477 printk(KERN_ERR PFX
"Couldnt configure shost for %s\n",
1478 interface
->netdev
->name
);
1482 /* Initialize the libfc library */
1483 rc
= bnx2fc_libfc_config(lport
);
1485 printk(KERN_ERR PFX
"Couldnt configure libfc\n");
1488 fc_host_port_type(lport
->host
) = FC_PORTTYPE_UNKNOWN
;
1490 /* Allocate exchange manager */
1492 rc
= bnx2fc_em_config(lport
, hba
);
1494 shost
= vport_to_shost(vport
);
1495 n_port
= shost_priv(shost
);
1496 rc
= fc_exch_mgr_list_clone(n_port
, lport
);
1500 printk(KERN_ERR PFX
"Error on bnx2fc_em_config\n");
1504 bnx2fc_interface_get(interface
);
1506 spin_lock_bh(&hba
->hba_lock
);
1507 blport
->lport
= lport
;
1508 list_add_tail(&blport
->list
, &hba
->vports
);
1509 spin_unlock_bh(&hba
->hba_lock
);
1514 scsi_remove_host(shost
);
1516 scsi_host_put(lport
->host
);
1522 static void bnx2fc_net_cleanup(struct bnx2fc_interface
*interface
)
1524 /* Dont listen for Ethernet packets anymore */
1525 __dev_remove_pack(&interface
->fcoe_packet_type
);
1526 __dev_remove_pack(&interface
->fip_packet_type
);
1530 static void bnx2fc_interface_cleanup(struct bnx2fc_interface
*interface
)
1532 struct fcoe_ctlr
*ctlr
= bnx2fc_to_ctlr(interface
);
1533 struct fc_lport
*lport
= ctlr
->lp
;
1534 struct fcoe_port
*port
= lport_priv(lport
);
1535 struct bnx2fc_hba
*hba
= interface
->hba
;
1537 /* Stop the transmit retry timer */
1538 del_timer_sync(&port
->timer
);
1540 /* Free existing transmit skbs */
1541 fcoe_clean_pending_queue(lport
);
1543 bnx2fc_net_cleanup(interface
);
1545 bnx2fc_free_vport(hba
, lport
);
1548 static void bnx2fc_if_destroy(struct fc_lport
*lport
)
1551 /* Free queued packets for the receive thread */
1552 bnx2fc_clean_rx_queue(lport
);
1554 /* Detach from scsi-ml */
1555 fc_remove_host(lport
->host
);
1556 scsi_remove_host(lport
->host
);
1559 * Note that only the physical lport will have the exchange manager.
1560 * for vports, this function is NOP
1562 fc_exch_mgr_free(lport
);
1564 /* Free memory used by statistical counters */
1565 fc_lport_free_stats(lport
);
1567 /* Release Scsi_Host */
1568 scsi_host_put(lport
->host
);
1571 static void __bnx2fc_destroy(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
);
1577 bnx2fc_interface_cleanup(interface
);
1578 bnx2fc_stop(interface
);
1579 list_del(&interface
->list
);
1580 bnx2fc_interface_put(interface
);
1581 queue_work(bnx2fc_wq
, &port
->destroy_work
);
1585 * bnx2fc_destroy - Destroy a bnx2fc FCoE interface
1587 * @buffer: The name of the Ethernet interface to be destroyed
1588 * @kp: The associated kernel parameter
1590 * Called from sysfs.
1592 * Returns: 0 for success
1594 static int bnx2fc_destroy(struct net_device
*netdev
)
1596 struct bnx2fc_interface
*interface
= NULL
;
1597 struct workqueue_struct
*timer_work_queue
;
1598 struct fcoe_ctlr
*ctlr
;
1602 mutex_lock(&bnx2fc_dev_lock
);
1604 interface
= bnx2fc_interface_lookup(netdev
);
1605 ctlr
= bnx2fc_to_ctlr(interface
);
1606 if (!interface
|| !ctlr
->lp
) {
1608 printk(KERN_ERR PFX
"bnx2fc_destroy: interface or lport not found\n");
1612 timer_work_queue
= interface
->timer_work_queue
;
1613 __bnx2fc_destroy(interface
);
1614 destroy_workqueue(timer_work_queue
);
1617 mutex_unlock(&bnx2fc_dev_lock
);
1622 static void bnx2fc_destroy_work(struct work_struct
*work
)
1624 struct fcoe_port
*port
;
1625 struct fc_lport
*lport
;
1627 port
= container_of(work
, struct fcoe_port
, destroy_work
);
1628 lport
= port
->lport
;
1630 BNX2FC_HBA_DBG(lport
, "Entered bnx2fc_destroy_work\n");
1632 bnx2fc_if_destroy(lport
);
1635 static void bnx2fc_unbind_adapter_devices(struct bnx2fc_hba
*hba
)
1637 bnx2fc_free_fw_resc(hba
);
1638 bnx2fc_free_task_ctx(hba
);
1642 * bnx2fc_bind_adapter_devices - binds bnx2fc adapter with the associated
1645 * @hba: Adapter instance
1647 static int bnx2fc_bind_adapter_devices(struct bnx2fc_hba
*hba
)
1649 if (bnx2fc_setup_task_ctx(hba
))
1652 if (bnx2fc_setup_fw_resc(hba
))
1657 bnx2fc_unbind_adapter_devices(hba
);
1661 static int bnx2fc_bind_pcidev(struct bnx2fc_hba
*hba
)
1663 struct cnic_dev
*cnic
;
1664 struct pci_dev
*pdev
;
1667 printk(KERN_ERR PFX
"cnic is NULL\n");
1671 pdev
= hba
->pcidev
= cnic
->pcidev
;
1675 switch (pdev
->device
) {
1676 case PCI_DEVICE_ID_NX2_57710
:
1677 strncpy(hba
->chip_num
, "BCM57710", BCM_CHIP_LEN
);
1679 case PCI_DEVICE_ID_NX2_57711
:
1680 strncpy(hba
->chip_num
, "BCM57711", BCM_CHIP_LEN
);
1682 case PCI_DEVICE_ID_NX2_57712
:
1683 case PCI_DEVICE_ID_NX2_57712_MF
:
1684 case PCI_DEVICE_ID_NX2_57712_VF
:
1685 strncpy(hba
->chip_num
, "BCM57712", BCM_CHIP_LEN
);
1687 case PCI_DEVICE_ID_NX2_57800
:
1688 case PCI_DEVICE_ID_NX2_57800_MF
:
1689 case PCI_DEVICE_ID_NX2_57800_VF
:
1690 strncpy(hba
->chip_num
, "BCM57800", BCM_CHIP_LEN
);
1692 case PCI_DEVICE_ID_NX2_57810
:
1693 case PCI_DEVICE_ID_NX2_57810_MF
:
1694 case PCI_DEVICE_ID_NX2_57810_VF
:
1695 strncpy(hba
->chip_num
, "BCM57810", BCM_CHIP_LEN
);
1697 case PCI_DEVICE_ID_NX2_57840
:
1698 case PCI_DEVICE_ID_NX2_57840_MF
:
1699 case PCI_DEVICE_ID_NX2_57840_VF
:
1700 case PCI_DEVICE_ID_NX2_57840_2_20
:
1701 case PCI_DEVICE_ID_NX2_57840_4_10
:
1702 strncpy(hba
->chip_num
, "BCM57840", BCM_CHIP_LEN
);
1705 pr_err(PFX
"Unknown device id 0x%x\n", pdev
->device
);
1708 pci_dev_get(hba
->pcidev
);
1712 static void bnx2fc_unbind_pcidev(struct bnx2fc_hba
*hba
)
1715 hba
->chip_num
[0] = '\0';
1716 pci_dev_put(hba
->pcidev
);
1722 * bnx2fc_ulp_get_stats - cnic callback to populate FCoE stats
1724 * @handle: transport handle pointing to adapter struture
1726 static int bnx2fc_ulp_get_stats(void *handle
)
1728 struct bnx2fc_hba
*hba
= handle
;
1729 struct cnic_dev
*cnic
;
1730 struct fcoe_stats_info
*stats_addr
;
1736 stats_addr
= &cnic
->stats_addr
->fcoe_stat
;
1740 strncpy(stats_addr
->version
, BNX2FC_VERSION
,
1741 sizeof(stats_addr
->version
));
1742 stats_addr
->txq_size
= BNX2FC_SQ_WQES_MAX
;
1743 stats_addr
->rxq_size
= BNX2FC_CQ_WQES_MAX
;
1750 * bnx2fc_ulp_start - cnic callback to initialize & start adapter instance
1752 * @handle: transport handle pointing to adapter structure
1754 * This function maps adapter structure to pcidev structure and initiates
1755 * firmware handshake to enable/initialize on-chip FCoE components.
1756 * This bnx2fc - cnic interface api callback is used after following
1757 * conditions are met -
1758 * a) underlying network interface is up (marked by event NETDEV_UP
1760 * b) bnx2fc adatper structure is registered.
1762 static void bnx2fc_ulp_start(void *handle
)
1764 struct bnx2fc_hba
*hba
= handle
;
1765 struct bnx2fc_interface
*interface
;
1766 struct fcoe_ctlr
*ctlr
;
1767 struct fc_lport
*lport
;
1769 mutex_lock(&bnx2fc_dev_lock
);
1771 if (!test_bit(BNX2FC_FLAG_FW_INIT_DONE
, &hba
->flags
))
1772 bnx2fc_fw_init(hba
);
1774 BNX2FC_MISC_DBG("bnx2fc started.\n");
1776 list_for_each_entry(interface
, &if_list
, list
) {
1777 if (interface
->hba
== hba
) {
1778 ctlr
= bnx2fc_to_ctlr(interface
);
1780 /* Kick off Fabric discovery*/
1781 printk(KERN_ERR PFX
"ulp_init: start discovery\n");
1782 lport
->tt
.frame_send
= bnx2fc_xmit
;
1783 bnx2fc_start_disc(interface
);
1787 mutex_unlock(&bnx2fc_dev_lock
);
1790 static void bnx2fc_port_shutdown(struct fc_lport
*lport
)
1792 BNX2FC_MISC_DBG("Entered %s\n", __func__
);
1793 fc_fabric_logoff(lport
);
1794 fc_lport_destroy(lport
);
1797 static void bnx2fc_stop(struct bnx2fc_interface
*interface
)
1799 struct fcoe_ctlr
*ctlr
= bnx2fc_to_ctlr(interface
);
1800 struct fc_lport
*lport
;
1801 struct fc_lport
*vport
;
1803 if (!test_bit(BNX2FC_FLAG_FW_INIT_DONE
, &interface
->hba
->flags
))
1807 bnx2fc_port_shutdown(lport
);
1809 mutex_lock(&lport
->lp_mutex
);
1810 list_for_each_entry(vport
, &lport
->vports
, list
)
1811 fc_host_port_type(vport
->host
) =
1812 FC_PORTTYPE_UNKNOWN
;
1813 mutex_unlock(&lport
->lp_mutex
);
1814 fc_host_port_type(lport
->host
) = FC_PORTTYPE_UNKNOWN
;
1815 fcoe_ctlr_link_down(ctlr
);
1816 fcoe_clean_pending_queue(lport
);
1819 static int bnx2fc_fw_init(struct bnx2fc_hba
*hba
)
1821 #define BNX2FC_INIT_POLL_TIME (1000 / HZ)
1825 rc
= bnx2fc_bind_adapter_devices(hba
);
1827 printk(KERN_ALERT PFX
1828 "bnx2fc_bind_adapter_devices failed - rc = %d\n", rc
);
1832 rc
= bnx2fc_send_fw_fcoe_init_msg(hba
);
1834 printk(KERN_ALERT PFX
1835 "bnx2fc_send_fw_fcoe_init_msg failed - rc = %d\n", rc
);
1840 * Wait until the adapter init message is complete, and adapter
1843 while (!test_bit(ADAPTER_STATE_UP
, &hba
->adapter_state
) && i
--)
1844 msleep(BNX2FC_INIT_POLL_TIME
);
1846 if (!test_bit(ADAPTER_STATE_UP
, &hba
->adapter_state
)) {
1847 printk(KERN_ERR PFX
"bnx2fc_start: %s failed to initialize. "
1849 hba
->cnic
->netdev
->name
);
1855 set_bit(BNX2FC_FLAG_FW_INIT_DONE
, &hba
->flags
);
1859 bnx2fc_unbind_adapter_devices(hba
);
1864 static void bnx2fc_fw_destroy(struct bnx2fc_hba
*hba
)
1866 if (test_and_clear_bit(BNX2FC_FLAG_FW_INIT_DONE
, &hba
->flags
)) {
1867 if (bnx2fc_send_fw_fcoe_destroy_msg(hba
) == 0) {
1868 init_timer(&hba
->destroy_timer
);
1869 hba
->destroy_timer
.expires
= BNX2FC_FW_TIMEOUT
+
1871 hba
->destroy_timer
.function
= bnx2fc_destroy_timer
;
1872 hba
->destroy_timer
.data
= (unsigned long)hba
;
1873 add_timer(&hba
->destroy_timer
);
1874 wait_event_interruptible(hba
->destroy_wait
,
1875 test_bit(BNX2FC_FLAG_DESTROY_CMPL
,
1877 clear_bit(BNX2FC_FLAG_DESTROY_CMPL
, &hba
->flags
);
1878 /* This should never happen */
1879 if (signal_pending(current
))
1880 flush_signals(current
);
1882 del_timer_sync(&hba
->destroy_timer
);
1884 bnx2fc_unbind_adapter_devices(hba
);
1889 * bnx2fc_ulp_stop - cnic callback to shutdown adapter instance
1891 * @handle: transport handle pointing to adapter structure
1893 * Driver checks if adapter is already in shutdown mode, if not start
1894 * the shutdown process.
1896 static void bnx2fc_ulp_stop(void *handle
)
1898 struct bnx2fc_hba
*hba
= handle
;
1899 struct bnx2fc_interface
*interface
;
1901 printk(KERN_ERR
"ULP_STOP\n");
1903 mutex_lock(&bnx2fc_dev_lock
);
1904 if (!test_bit(BNX2FC_FLAG_FW_INIT_DONE
, &hba
->flags
))
1906 list_for_each_entry(interface
, &if_list
, list
) {
1907 if (interface
->hba
== hba
)
1908 bnx2fc_stop(interface
);
1910 BUG_ON(hba
->num_ofld_sess
!= 0);
1912 mutex_lock(&hba
->hba_mutex
);
1913 clear_bit(ADAPTER_STATE_UP
, &hba
->adapter_state
);
1914 clear_bit(ADAPTER_STATE_GOING_DOWN
,
1915 &hba
->adapter_state
);
1917 clear_bit(ADAPTER_STATE_READY
, &hba
->adapter_state
);
1918 mutex_unlock(&hba
->hba_mutex
);
1920 bnx2fc_fw_destroy(hba
);
1922 mutex_unlock(&bnx2fc_dev_lock
);
1925 static void bnx2fc_start_disc(struct bnx2fc_interface
*interface
)
1927 struct fcoe_ctlr
*ctlr
= bnx2fc_to_ctlr(interface
);
1928 struct fc_lport
*lport
;
1931 BNX2FC_MISC_DBG("Entered %s\n", __func__
);
1932 /* Kick off FIP/FLOGI */
1933 if (!test_bit(BNX2FC_FLAG_FW_INIT_DONE
, &interface
->hba
->flags
)) {
1934 printk(KERN_ERR PFX
"Init not done yet\n");
1939 BNX2FC_HBA_DBG(lport
, "calling fc_fabric_login\n");
1941 if (!bnx2fc_link_ok(lport
) && interface
->enabled
) {
1942 BNX2FC_HBA_DBG(lport
, "ctlr_link_up\n");
1943 fcoe_ctlr_link_up(ctlr
);
1944 fc_host_port_type(lport
->host
) = FC_PORTTYPE_NPORT
;
1945 set_bit(ADAPTER_STATE_READY
, &interface
->hba
->adapter_state
);
1948 /* wait for the FCF to be selected before issuing FLOGI */
1949 while (!ctlr
->sel_fcf
) {
1951 /* give up after 3 secs */
1952 if (++wait_cnt
> 12)
1956 /* Reset max receive frame size to default */
1957 if (fc_set_mfs(lport
, BNX2FC_MFS
))
1960 fc_lport_init(lport
);
1961 fc_fabric_login(lport
);
1966 * bnx2fc_ulp_init - Initialize an adapter instance
1968 * @dev : cnic device handle
1969 * Called from cnic_register_driver() context to initialize all
1970 * enumerated cnic devices. This routine allocates adapter structure
1971 * and other device specific resources.
1973 static void bnx2fc_ulp_init(struct cnic_dev
*dev
)
1975 struct bnx2fc_hba
*hba
;
1978 BNX2FC_MISC_DBG("Entered %s\n", __func__
);
1979 /* bnx2fc works only when bnx2x is loaded */
1980 if (!test_bit(CNIC_F_BNX2X_CLASS
, &dev
->flags
) ||
1981 (dev
->max_fcoe_conn
== 0)) {
1982 printk(KERN_ERR PFX
"bnx2fc FCoE not supported on %s,"
1983 " flags: %lx fcoe_conn: %d\n",
1984 dev
->netdev
->name
, dev
->flags
, dev
->max_fcoe_conn
);
1988 hba
= bnx2fc_hba_create(dev
);
1990 printk(KERN_ERR PFX
"hba initialization failed\n");
1994 /* Add HBA to the adapter list */
1995 mutex_lock(&bnx2fc_dev_lock
);
1996 list_add_tail(&hba
->list
, &adapter_list
);
1998 mutex_unlock(&bnx2fc_dev_lock
);
2000 dev
->fcoe_cap
= &hba
->fcoe_cap
;
2001 clear_bit(BNX2FC_CNIC_REGISTERED
, &hba
->reg_with_cnic
);
2002 rc
= dev
->register_device(dev
, CNIC_ULP_FCOE
,
2005 printk(KERN_ERR PFX
"register_device failed, rc = %d\n", rc
);
2007 set_bit(BNX2FC_CNIC_REGISTERED
, &hba
->reg_with_cnic
);
2010 /* Assumes rtnl_lock and the bnx2fc_dev_lock are already taken */
2011 static int __bnx2fc_disable(struct fcoe_ctlr
*ctlr
)
2013 struct bnx2fc_interface
*interface
= fcoe_ctlr_priv(ctlr
);
2015 if (interface
->enabled
== true) {
2017 pr_err(PFX
"__bnx2fc_disable: lport not found\n");
2020 interface
->enabled
= false;
2021 fcoe_ctlr_link_down(ctlr
);
2022 fcoe_clean_pending_queue(ctlr
->lp
);
2029 * Deperecated: Use bnx2fc_enabled()
2031 static int bnx2fc_disable(struct net_device
*netdev
)
2033 struct bnx2fc_interface
*interface
;
2034 struct fcoe_ctlr
*ctlr
;
2038 mutex_lock(&bnx2fc_dev_lock
);
2040 interface
= bnx2fc_interface_lookup(netdev
);
2041 ctlr
= bnx2fc_to_ctlr(interface
);
2045 pr_err(PFX
"bnx2fc_disable: interface not found\n");
2047 rc
= __bnx2fc_disable(ctlr
);
2049 mutex_unlock(&bnx2fc_dev_lock
);
2054 static uint
bnx2fc_npiv_create_vports(struct fc_lport
*lport
,
2055 struct cnic_fc_npiv_tbl
*npiv_tbl
)
2057 struct fc_vport_identifiers vpid
;
2058 uint i
, created
= 0;
2060 if (npiv_tbl
->count
> MAX_NPIV_ENTRIES
) {
2061 BNX2FC_HBA_DBG(lport
, "Exceeded count max of npiv table\n");
2065 /* Sanity check the first entry to make sure it's not 0 */
2066 if (wwn_to_u64(npiv_tbl
->wwnn
[0]) == 0 &&
2067 wwn_to_u64(npiv_tbl
->wwpn
[0]) == 0) {
2068 BNX2FC_HBA_DBG(lport
, "First NPIV table entries invalid.\n");
2072 vpid
.roles
= FC_PORT_ROLE_FCP_INITIATOR
;
2073 vpid
.vport_type
= FC_PORTTYPE_NPIV
;
2074 vpid
.disable
= false;
2076 for (i
= 0; i
< npiv_tbl
->count
; i
++) {
2077 vpid
.node_name
= wwn_to_u64(npiv_tbl
->wwnn
[i
]);
2078 vpid
.port_name
= wwn_to_u64(npiv_tbl
->wwpn
[i
]);
2079 scnprintf(vpid
.symbolic_name
, sizeof(vpid
.symbolic_name
),
2080 "NPIV[%u]:%016llx-%016llx",
2081 created
, vpid
.port_name
, vpid
.node_name
);
2082 if (fc_vport_create(lport
->host
, 0, &vpid
))
2085 BNX2FC_HBA_DBG(lport
, "Failed to create vport\n");
2091 static int __bnx2fc_enable(struct fcoe_ctlr
*ctlr
)
2093 struct bnx2fc_interface
*interface
= fcoe_ctlr_priv(ctlr
);
2094 struct bnx2fc_hba
*hba
;
2095 struct cnic_fc_npiv_tbl npiv_tbl
;
2096 struct fc_lport
*lport
;
2098 if (interface
->enabled
== false) {
2100 pr_err(PFX
"__bnx2fc_enable: lport not found\n");
2102 } else if (!bnx2fc_link_ok(ctlr
->lp
)) {
2103 fcoe_ctlr_link_up(ctlr
);
2104 interface
->enabled
= true;
2108 /* Create static NPIV ports if any are contained in NVRAM */
2109 hba
= interface
->hba
;
2124 if (!hba
->cnic
->get_fc_npiv_tbl
)
2127 memset(&npiv_tbl
, 0, sizeof(npiv_tbl
));
2128 if (hba
->cnic
->get_fc_npiv_tbl(hba
->cnic
, &npiv_tbl
))
2131 bnx2fc_npiv_create_vports(lport
, &npiv_tbl
);
2137 * Deprecated: Use bnx2fc_enabled()
2139 static int bnx2fc_enable(struct net_device
*netdev
)
2141 struct bnx2fc_interface
*interface
;
2142 struct fcoe_ctlr
*ctlr
;
2146 mutex_lock(&bnx2fc_dev_lock
);
2148 interface
= bnx2fc_interface_lookup(netdev
);
2149 ctlr
= bnx2fc_to_ctlr(interface
);
2152 pr_err(PFX
"bnx2fc_enable: interface not found\n");
2154 rc
= __bnx2fc_enable(ctlr
);
2157 mutex_unlock(&bnx2fc_dev_lock
);
2163 * bnx2fc_ctlr_enabled() - Enable or disable an FCoE Controller
2164 * @cdev: The FCoE Controller that is being enabled or disabled
2166 * fcoe_sysfs will ensure that the state of 'enabled' has
2167 * changed, so no checking is necessary here. This routine simply
2168 * calls fcoe_enable or fcoe_disable, both of which are deprecated.
2169 * When those routines are removed the functionality can be merged
2172 static int bnx2fc_ctlr_enabled(struct fcoe_ctlr_device
*cdev
)
2174 struct fcoe_ctlr
*ctlr
= fcoe_ctlr_device_priv(cdev
);
2176 switch (cdev
->enabled
) {
2177 case FCOE_CTLR_ENABLED
:
2178 return __bnx2fc_enable(ctlr
);
2179 case FCOE_CTLR_DISABLED
:
2180 return __bnx2fc_disable(ctlr
);
2181 case FCOE_CTLR_UNUSED
:
2187 enum bnx2fc_create_link_state
{
2188 BNX2FC_CREATE_LINK_DOWN
,
2189 BNX2FC_CREATE_LINK_UP
,
2193 * _bnx2fc_create() - Create bnx2fc FCoE interface
2194 * @netdev : The net_device object the Ethernet interface to create on
2195 * @fip_mode: The FIP mode for this creation
2196 * @link_state: The ctlr link state on creation
2198 * Called from either the libfcoe 'create' module parameter
2199 * via fcoe_create or from fcoe_syfs's ctlr_create file.
2201 * libfcoe's 'create' module parameter is deprecated so some
2202 * consolidation of code can be done when that interface is
2205 * Returns: 0 for success
2207 static int _bnx2fc_create(struct net_device
*netdev
,
2208 enum fip_state fip_mode
,
2209 enum bnx2fc_create_link_state link_state
)
2211 struct fcoe_ctlr_device
*cdev
;
2212 struct fcoe_ctlr
*ctlr
;
2213 struct bnx2fc_interface
*interface
;
2214 struct bnx2fc_hba
*hba
;
2215 struct net_device
*phys_dev
= netdev
;
2216 struct fc_lport
*lport
;
2217 struct ethtool_drvinfo drvinfo
;
2221 BNX2FC_MISC_DBG("Entered bnx2fc_create\n");
2222 if (fip_mode
!= FIP_MODE_FABRIC
) {
2223 printk(KERN_ERR
"fip mode not FABRIC\n");
2229 mutex_lock(&bnx2fc_dev_lock
);
2231 if (!try_module_get(THIS_MODULE
)) {
2236 /* obtain physical netdev */
2237 if (netdev
->priv_flags
& IFF_802_1Q_VLAN
)
2238 phys_dev
= vlan_dev_real_dev(netdev
);
2240 /* verify if the physical device is a netxtreme2 device */
2241 if (phys_dev
->ethtool_ops
&& phys_dev
->ethtool_ops
->get_drvinfo
) {
2242 memset(&drvinfo
, 0, sizeof(drvinfo
));
2243 phys_dev
->ethtool_ops
->get_drvinfo(phys_dev
, &drvinfo
);
2244 if (strncmp(drvinfo
.driver
, "bnx2x", strlen("bnx2x"))) {
2245 printk(KERN_ERR PFX
"Not a netxtreme2 device\n");
2250 printk(KERN_ERR PFX
"unable to obtain drv_info\n");
2255 /* obtain interface and initialize rest of the structure */
2256 hba
= bnx2fc_hba_lookup(phys_dev
);
2259 printk(KERN_ERR PFX
"bnx2fc_create: hba not found\n");
2263 if (bnx2fc_interface_lookup(netdev
)) {
2268 interface
= bnx2fc_interface_create(hba
, netdev
, fip_mode
);
2270 printk(KERN_ERR PFX
"bnx2fc_interface_create failed\n");
2275 if (netdev
->priv_flags
& IFF_802_1Q_VLAN
) {
2276 vlan_id
= vlan_dev_vlan_id(netdev
);
2277 interface
->vlan_enabled
= 1;
2280 ctlr
= bnx2fc_to_ctlr(interface
);
2281 cdev
= fcoe_ctlr_to_ctlr_dev(ctlr
);
2282 interface
->vlan_id
= vlan_id
;
2284 interface
->timer_work_queue
=
2285 create_singlethread_workqueue("bnx2fc_timer_wq");
2286 if (!interface
->timer_work_queue
) {
2287 printk(KERN_ERR PFX
"ulp_init could not create timer_wq\n");
2292 lport
= bnx2fc_if_create(interface
, &cdev
->dev
, 0);
2294 printk(KERN_ERR PFX
"Failed to create interface (%s)\n",
2300 /* Add interface to if_list */
2301 list_add_tail(&interface
->list
, &if_list
);
2303 lport
->boot_time
= jiffies
;
2305 /* Make this master N_port */
2308 if (link_state
== BNX2FC_CREATE_LINK_UP
)
2309 cdev
->enabled
= FCOE_CTLR_ENABLED
;
2311 cdev
->enabled
= FCOE_CTLR_DISABLED
;
2313 if (link_state
== BNX2FC_CREATE_LINK_UP
&&
2314 !bnx2fc_link_ok(lport
)) {
2315 fcoe_ctlr_link_up(ctlr
);
2316 fc_host_port_type(lport
->host
) = FC_PORTTYPE_NPORT
;
2317 set_bit(ADAPTER_STATE_READY
, &interface
->hba
->adapter_state
);
2320 BNX2FC_HBA_DBG(lport
, "create: START DISC\n");
2321 bnx2fc_start_disc(interface
);
2323 if (link_state
== BNX2FC_CREATE_LINK_UP
)
2324 interface
->enabled
= true;
2327 * Release from kref_init in bnx2fc_interface_setup, on success
2328 * lport should be holding a reference taken in bnx2fc_if_create
2330 bnx2fc_interface_put(interface
);
2331 /* put netdev that was held while calling dev_get_by_name */
2332 mutex_unlock(&bnx2fc_dev_lock
);
2337 destroy_workqueue(interface
->timer_work_queue
);
2339 bnx2fc_net_cleanup(interface
);
2340 bnx2fc_interface_put(interface
);
2343 module_put(THIS_MODULE
);
2345 mutex_unlock(&bnx2fc_dev_lock
);
2351 * bnx2fc_create() - Create a bnx2fc interface
2352 * @netdev : The net_device object the Ethernet interface to create on
2353 * @fip_mode: The FIP mode for this creation
2355 * Called from fcoe transport
2357 * Returns: 0 for success
2359 static int bnx2fc_create(struct net_device
*netdev
, enum fip_state fip_mode
)
2361 return _bnx2fc_create(netdev
, fip_mode
, BNX2FC_CREATE_LINK_UP
);
2365 * bnx2fc_ctlr_alloc() - Allocate a bnx2fc interface from fcoe_sysfs
2366 * @netdev: The net_device to be used by the allocated FCoE Controller
2368 * This routine is called from fcoe_sysfs. It will start the fcoe_ctlr
2369 * in a link_down state. The allows the user an opportunity to configure
2370 * the FCoE Controller from sysfs before enabling the FCoE Controller.
2372 * Creating in with this routine starts the FCoE Controller in Fabric
2373 * mode. The user can change to VN2VN or another mode before enabling.
2375 static int bnx2fc_ctlr_alloc(struct net_device
*netdev
)
2377 return _bnx2fc_create(netdev
, FIP_MODE_FABRIC
,
2378 BNX2FC_CREATE_LINK_DOWN
);
2382 * bnx2fc_find_hba_for_cnic - maps cnic instance to bnx2fc hba instance
2384 * @cnic: Pointer to cnic device instance
2387 static struct bnx2fc_hba
*bnx2fc_find_hba_for_cnic(struct cnic_dev
*cnic
)
2389 struct bnx2fc_hba
*hba
;
2391 /* Called with bnx2fc_dev_lock held */
2392 list_for_each_entry(hba
, &adapter_list
, list
) {
2393 if (hba
->cnic
== cnic
)
2399 static struct bnx2fc_interface
*bnx2fc_interface_lookup(struct net_device
2402 struct bnx2fc_interface
*interface
;
2404 /* Called with bnx2fc_dev_lock held */
2405 list_for_each_entry(interface
, &if_list
, list
) {
2406 if (interface
->netdev
== netdev
)
2412 static struct bnx2fc_hba
*bnx2fc_hba_lookup(struct net_device
2415 struct bnx2fc_hba
*hba
;
2417 /* Called with bnx2fc_dev_lock held */
2418 list_for_each_entry(hba
, &adapter_list
, list
) {
2419 if (hba
->phys_dev
== phys_dev
)
2422 printk(KERN_ERR PFX
"adapter_lookup: hba NULL\n");
2427 * bnx2fc_ulp_exit - shuts down adapter instance and frees all resources
2429 * @dev cnic device handle
2431 static void bnx2fc_ulp_exit(struct cnic_dev
*dev
)
2433 struct bnx2fc_hba
*hba
;
2434 struct bnx2fc_interface
*interface
, *tmp
;
2436 BNX2FC_MISC_DBG("Entered bnx2fc_ulp_exit\n");
2438 if (!test_bit(CNIC_F_BNX2X_CLASS
, &dev
->flags
)) {
2439 printk(KERN_ERR PFX
"bnx2fc port check: %s, flags: %lx\n",
2440 dev
->netdev
->name
, dev
->flags
);
2444 mutex_lock(&bnx2fc_dev_lock
);
2445 hba
= bnx2fc_find_hba_for_cnic(dev
);
2447 printk(KERN_ERR PFX
"bnx2fc_ulp_exit: hba not found, dev 0%p\n",
2449 mutex_unlock(&bnx2fc_dev_lock
);
2453 list_del_init(&hba
->list
);
2456 list_for_each_entry_safe(interface
, tmp
, &if_list
, list
)
2457 /* destroy not called yet, move to quiesced list */
2458 if (interface
->hba
== hba
)
2459 __bnx2fc_destroy(interface
);
2460 mutex_unlock(&bnx2fc_dev_lock
);
2462 /* Ensure ALL destroy work has been completed before return */
2463 flush_workqueue(bnx2fc_wq
);
2465 bnx2fc_ulp_stop(hba
);
2466 /* unregister cnic device */
2467 if (test_and_clear_bit(BNX2FC_CNIC_REGISTERED
, &hba
->reg_with_cnic
))
2468 hba
->cnic
->unregister_device(hba
->cnic
, CNIC_ULP_FCOE
);
2469 bnx2fc_hba_destroy(hba
);
2473 * bnx2fc_fcoe_reset - Resets the fcoe
2475 * @shost: shost the reset is from
2479 static int bnx2fc_fcoe_reset(struct Scsi_Host
*shost
)
2481 struct fc_lport
*lport
= shost_priv(shost
);
2482 fc_lport_reset(lport
);
2487 static bool bnx2fc_match(struct net_device
*netdev
)
2489 struct net_device
*phys_dev
= netdev
;
2491 mutex_lock(&bnx2fc_dev_lock
);
2492 if (netdev
->priv_flags
& IFF_802_1Q_VLAN
)
2493 phys_dev
= vlan_dev_real_dev(netdev
);
2495 if (bnx2fc_hba_lookup(phys_dev
)) {
2496 mutex_unlock(&bnx2fc_dev_lock
);
2500 mutex_unlock(&bnx2fc_dev_lock
);
2505 static struct fcoe_transport bnx2fc_transport
= {
2508 .list
= LIST_HEAD_INIT(bnx2fc_transport
.list
),
2509 .alloc
= bnx2fc_ctlr_alloc
,
2510 .match
= bnx2fc_match
,
2511 .create
= bnx2fc_create
,
2512 .destroy
= bnx2fc_destroy
,
2513 .enable
= bnx2fc_enable
,
2514 .disable
= bnx2fc_disable
,
2518 * bnx2fc_percpu_thread_create - Create a receive thread for an
2521 * @cpu: cpu index for the online cpu
2523 static void bnx2fc_percpu_thread_create(unsigned int cpu
)
2525 struct bnx2fc_percpu_s
*p
;
2526 struct task_struct
*thread
;
2528 p
= &per_cpu(bnx2fc_percpu
, cpu
);
2530 thread
= kthread_create_on_node(bnx2fc_percpu_io_thread
,
2531 (void *)p
, cpu_to_node(cpu
),
2532 "bnx2fc_thread/%d", cpu
);
2533 /* bind thread to the cpu */
2534 if (likely(!IS_ERR(thread
))) {
2535 kthread_bind(thread
, cpu
);
2536 p
->iothread
= thread
;
2537 wake_up_process(thread
);
2541 static void bnx2fc_percpu_thread_destroy(unsigned int cpu
)
2543 struct bnx2fc_percpu_s
*p
;
2544 struct task_struct
*thread
;
2545 struct bnx2fc_work
*work
, *tmp
;
2547 BNX2FC_MISC_DBG("destroying io thread for CPU %d\n", cpu
);
2549 /* Prevent any new work from being queued for this CPU */
2550 p
= &per_cpu(bnx2fc_percpu
, cpu
);
2551 spin_lock_bh(&p
->fp_work_lock
);
2552 thread
= p
->iothread
;
2556 /* Free all work in the list */
2557 list_for_each_entry_safe(work
, tmp
, &p
->work_list
, list
) {
2558 list_del_init(&work
->list
);
2559 bnx2fc_process_cq_compl(work
->tgt
, work
->wqe
);
2563 spin_unlock_bh(&p
->fp_work_lock
);
2566 kthread_stop(thread
);
2570 * bnx2fc_cpu_callback - Handler for CPU hotplug events
2572 * @nfb: The callback data block
2573 * @action: The event triggering the callback
2574 * @hcpu: The index of the CPU that the event is for
2576 * This creates or destroys per-CPU data for fcoe
2578 * Returns NOTIFY_OK always.
2580 static int bnx2fc_cpu_callback(struct notifier_block
*nfb
,
2581 unsigned long action
, void *hcpu
)
2583 unsigned cpu
= (unsigned long)hcpu
;
2587 case CPU_ONLINE_FROZEN
:
2588 printk(PFX
"CPU %x online: Create Rx thread\n", cpu
);
2589 bnx2fc_percpu_thread_create(cpu
);
2592 case CPU_DEAD_FROZEN
:
2593 printk(PFX
"CPU %x offline: Remove Rx thread\n", cpu
);
2594 bnx2fc_percpu_thread_destroy(cpu
);
2603 * bnx2fc_mod_init - module init entry point
2605 * Initialize driver wide global data structures, and register
2608 static int __init
bnx2fc_mod_init(void)
2610 struct fcoe_percpu_s
*bg
;
2611 struct task_struct
*l2_thread
;
2613 unsigned int cpu
= 0;
2614 struct bnx2fc_percpu_s
*p
;
2616 printk(KERN_INFO PFX
"%s", version
);
2618 /* register as a fcoe transport */
2619 rc
= fcoe_transport_attach(&bnx2fc_transport
);
2621 printk(KERN_ERR
"failed to register an fcoe transport, check "
2622 "if libfcoe is loaded\n");
2626 INIT_LIST_HEAD(&adapter_list
);
2627 INIT_LIST_HEAD(&if_list
);
2628 mutex_init(&bnx2fc_dev_lock
);
2631 /* Attach FC transport template */
2632 rc
= bnx2fc_attach_transport();
2636 bnx2fc_wq
= alloc_workqueue("bnx2fc", 0, 0);
2642 bg
= &bnx2fc_global
;
2643 skb_queue_head_init(&bg
->fcoe_rx_list
);
2644 l2_thread
= kthread_create(bnx2fc_l2_rcv_thread
,
2646 "bnx2fc_l2_thread");
2647 if (IS_ERR(l2_thread
)) {
2648 rc
= PTR_ERR(l2_thread
);
2651 wake_up_process(l2_thread
);
2652 spin_lock_bh(&bg
->fcoe_rx_list
.lock
);
2653 bg
->thread
= l2_thread
;
2654 spin_unlock_bh(&bg
->fcoe_rx_list
.lock
);
2656 for_each_possible_cpu(cpu
) {
2657 p
= &per_cpu(bnx2fc_percpu
, cpu
);
2658 INIT_LIST_HEAD(&p
->work_list
);
2659 spin_lock_init(&p
->fp_work_lock
);
2662 cpu_notifier_register_begin();
2664 for_each_online_cpu(cpu
) {
2665 bnx2fc_percpu_thread_create(cpu
);
2668 /* Initialize per CPU interrupt thread */
2669 __register_hotcpu_notifier(&bnx2fc_cpu_notifier
);
2671 cpu_notifier_register_done();
2673 cnic_register_driver(CNIC_ULP_FCOE
, &bnx2fc_cnic_cb
);
2678 destroy_workqueue(bnx2fc_wq
);
2680 bnx2fc_release_transport();
2682 fcoe_transport_detach(&bnx2fc_transport
);
2687 static void __exit
bnx2fc_mod_exit(void)
2689 LIST_HEAD(to_be_deleted
);
2690 struct bnx2fc_hba
*hba
, *next
;
2691 struct fcoe_percpu_s
*bg
;
2692 struct task_struct
*l2_thread
;
2693 struct sk_buff
*skb
;
2694 unsigned int cpu
= 0;
2697 * NOTE: Since cnic calls register_driver routine rtnl_lock,
2698 * it will have higher precedence than bnx2fc_dev_lock.
2699 * unregister_device() cannot be called with bnx2fc_dev_lock
2702 mutex_lock(&bnx2fc_dev_lock
);
2703 list_splice(&adapter_list
, &to_be_deleted
);
2704 INIT_LIST_HEAD(&adapter_list
);
2706 mutex_unlock(&bnx2fc_dev_lock
);
2708 /* Unregister with cnic */
2709 list_for_each_entry_safe(hba
, next
, &to_be_deleted
, list
) {
2710 list_del_init(&hba
->list
);
2711 printk(KERN_ERR PFX
"MOD_EXIT:destroy hba = 0x%p\n",
2713 bnx2fc_ulp_stop(hba
);
2714 /* unregister cnic device */
2715 if (test_and_clear_bit(BNX2FC_CNIC_REGISTERED
,
2716 &hba
->reg_with_cnic
))
2717 hba
->cnic
->unregister_device(hba
->cnic
,
2719 bnx2fc_hba_destroy(hba
);
2721 cnic_unregister_driver(CNIC_ULP_FCOE
);
2723 /* Destroy global thread */
2724 bg
= &bnx2fc_global
;
2725 spin_lock_bh(&bg
->fcoe_rx_list
.lock
);
2726 l2_thread
= bg
->thread
;
2728 while ((skb
= __skb_dequeue(&bg
->fcoe_rx_list
)) != NULL
)
2731 spin_unlock_bh(&bg
->fcoe_rx_list
.lock
);
2734 kthread_stop(l2_thread
);
2736 cpu_notifier_register_begin();
2738 /* Destroy per cpu threads */
2739 for_each_online_cpu(cpu
) {
2740 bnx2fc_percpu_thread_destroy(cpu
);
2743 __unregister_hotcpu_notifier(&bnx2fc_cpu_notifier
);
2745 cpu_notifier_register_done();
2747 destroy_workqueue(bnx2fc_wq
);
2749 * detach from scsi transport
2750 * must happen after all destroys are done
2752 bnx2fc_release_transport();
2754 /* detach from fcoe transport */
2755 fcoe_transport_detach(&bnx2fc_transport
);
2758 module_init(bnx2fc_mod_init
);
2759 module_exit(bnx2fc_mod_exit
);
2761 static struct fcoe_sysfs_function_template bnx2fc_fcoe_sysfs_templ
= {
2762 .set_fcoe_ctlr_enabled
= bnx2fc_ctlr_enabled
,
2763 .get_fcoe_ctlr_link_fail
= fcoe_ctlr_get_lesb
,
2764 .get_fcoe_ctlr_vlink_fail
= fcoe_ctlr_get_lesb
,
2765 .get_fcoe_ctlr_miss_fka
= fcoe_ctlr_get_lesb
,
2766 .get_fcoe_ctlr_symb_err
= fcoe_ctlr_get_lesb
,
2767 .get_fcoe_ctlr_err_block
= fcoe_ctlr_get_lesb
,
2768 .get_fcoe_ctlr_fcs_error
= fcoe_ctlr_get_lesb
,
2770 .get_fcoe_fcf_selected
= fcoe_fcf_get_selected
,
2771 .get_fcoe_fcf_vlan_id
= bnx2fc_fcf_get_vlan_id
,
2774 static struct fc_function_template bnx2fc_transport_function
= {
2775 .show_host_node_name
= 1,
2776 .show_host_port_name
= 1,
2777 .show_host_supported_classes
= 1,
2778 .show_host_supported_fc4s
= 1,
2779 .show_host_active_fc4s
= 1,
2780 .show_host_maxframe_size
= 1,
2782 .show_host_port_id
= 1,
2783 .show_host_supported_speeds
= 1,
2784 .get_host_speed
= fc_get_host_speed
,
2785 .show_host_speed
= 1,
2786 .show_host_port_type
= 1,
2787 .get_host_port_state
= fc_get_host_port_state
,
2788 .show_host_port_state
= 1,
2789 .show_host_symbolic_name
= 1,
2791 .dd_fcrport_size
= (sizeof(struct fc_rport_libfc_priv
) +
2792 sizeof(struct bnx2fc_rport
)),
2793 .show_rport_maxframe_size
= 1,
2794 .show_rport_supported_classes
= 1,
2796 .show_host_fabric_name
= 1,
2797 .show_starget_node_name
= 1,
2798 .show_starget_port_name
= 1,
2799 .show_starget_port_id
= 1,
2800 .set_rport_dev_loss_tmo
= fc_set_rport_loss_tmo
,
2801 .show_rport_dev_loss_tmo
= 1,
2802 .get_fc_host_stats
= bnx2fc_get_host_stats
,
2804 .issue_fc_host_lip
= bnx2fc_fcoe_reset
,
2806 .terminate_rport_io
= fc_rport_terminate_io
,
2808 .vport_create
= bnx2fc_vport_create
,
2809 .vport_delete
= bnx2fc_vport_destroy
,
2810 .vport_disable
= bnx2fc_vport_disable
,
2811 .bsg_request
= fc_lport_bsg_request
,
2814 static struct fc_function_template bnx2fc_vport_xport_function
= {
2815 .show_host_node_name
= 1,
2816 .show_host_port_name
= 1,
2817 .show_host_supported_classes
= 1,
2818 .show_host_supported_fc4s
= 1,
2819 .show_host_active_fc4s
= 1,
2820 .show_host_maxframe_size
= 1,
2822 .show_host_port_id
= 1,
2823 .show_host_supported_speeds
= 1,
2824 .get_host_speed
= fc_get_host_speed
,
2825 .show_host_speed
= 1,
2826 .show_host_port_type
= 1,
2827 .get_host_port_state
= fc_get_host_port_state
,
2828 .show_host_port_state
= 1,
2829 .show_host_symbolic_name
= 1,
2831 .dd_fcrport_size
= (sizeof(struct fc_rport_libfc_priv
) +
2832 sizeof(struct bnx2fc_rport
)),
2833 .show_rport_maxframe_size
= 1,
2834 .show_rport_supported_classes
= 1,
2836 .show_host_fabric_name
= 1,
2837 .show_starget_node_name
= 1,
2838 .show_starget_port_name
= 1,
2839 .show_starget_port_id
= 1,
2840 .set_rport_dev_loss_tmo
= fc_set_rport_loss_tmo
,
2841 .show_rport_dev_loss_tmo
= 1,
2842 .get_fc_host_stats
= fc_get_host_stats
,
2843 .issue_fc_host_lip
= bnx2fc_fcoe_reset
,
2844 .terminate_rport_io
= fc_rport_terminate_io
,
2845 .bsg_request
= fc_lport_bsg_request
,
2849 * scsi_host_template structure used while registering with SCSI-ml
2851 static struct scsi_host_template bnx2fc_shost_template
= {
2852 .module
= THIS_MODULE
,
2853 .name
= "QLogic Offload FCoE Initiator",
2854 .queuecommand
= bnx2fc_queuecommand
,
2855 .eh_abort_handler
= bnx2fc_eh_abort
, /* abts */
2856 .eh_device_reset_handler
= bnx2fc_eh_device_reset
, /* lun reset */
2857 .eh_target_reset_handler
= bnx2fc_eh_target_reset
, /* tgt reset */
2858 .eh_host_reset_handler
= fc_eh_host_reset
,
2859 .slave_alloc
= fc_slave_alloc
,
2860 .change_queue_depth
= scsi_change_queue_depth
,
2863 .use_clustering
= ENABLE_CLUSTERING
,
2864 .sg_tablesize
= BNX2FC_MAX_BDS_PER_CMD
,
2865 .max_sectors
= 1024,
2867 .track_queue_depth
= 1,
2870 static struct libfc_function_template bnx2fc_libfc_fcn_templ
= {
2871 .frame_send
= bnx2fc_xmit
,
2872 .elsct_send
= bnx2fc_elsct_send
,
2873 .fcp_abort_io
= bnx2fc_abort_io
,
2874 .fcp_cleanup
= bnx2fc_cleanup
,
2875 .get_lesb
= fcoe_get_lesb
,
2876 .rport_event_callback
= bnx2fc_rport_event_handler
,
2880 * bnx2fc_cnic_cb - global template of bnx2fc - cnic driver interface
2881 * structure carrying callback function pointers
2883 static struct cnic_ulp_ops bnx2fc_cnic_cb
= {
2884 .owner
= THIS_MODULE
,
2885 .cnic_init
= bnx2fc_ulp_init
,
2886 .cnic_exit
= bnx2fc_ulp_exit
,
2887 .cnic_start
= bnx2fc_ulp_start
,
2888 .cnic_stop
= bnx2fc_ulp_stop
,
2889 .indicate_kcqes
= bnx2fc_indicate_kcqe
,
2890 .indicate_netevent
= bnx2fc_indicate_netevent
,
2891 .cnic_get_stats
= bnx2fc_ulp_get_stats
,