]> git.proxmox.com Git - mirror_ubuntu-zesty-kernel.git/blame - drivers/scsi/bnx2fc/bnx2fc_fcoe.c
scsi: don't allow setting of queue_depth bigger than can_queue
[mirror_ubuntu-zesty-kernel.git] / drivers / scsi / bnx2fc / bnx2fc_fcoe.c
CommitLineData
17d87c45 1/* bnx2fc_fcoe.c: QLogic NetXtreme II Linux FCoE offload driver.
853e2bd2
BG
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.
5 *
cf122191 6 * Copyright (c) 2008 - 2013 Broadcom Corporation
17d87c45 7 * Copyright (c) 2014, QLogic Corporation
853e2bd2
BG
8 *
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.
12 *
13 * Written by: Bhanu Prakash Gollapudi (bprakash@broadcom.com)
14 */
15
16#include "bnx2fc.h"
17
18static struct list_head adapter_list;
aea71a02 19static struct list_head if_list;
853e2bd2
BG
20static u32 adapter_count;
21static DEFINE_MUTEX(bnx2fc_dev_lock);
22DEFINE_PER_CPU(struct bnx2fc_percpu_s, bnx2fc_percpu);
23
24#define DRV_MODULE_NAME "bnx2fc"
25#define DRV_MODULE_VERSION BNX2FC_VERSION
38e83bff 26#define DRV_MODULE_RELDATE "Dec 11, 2013"
853e2bd2
BG
27
28
6f039790 29static char version[] =
17d87c45 30 "QLogic NetXtreme II FCoE Driver " DRV_MODULE_NAME \
853e2bd2
BG
31 " v" DRV_MODULE_VERSION " (" DRV_MODULE_RELDATE ")\n";
32
33
34MODULE_AUTHOR("Bhanu Prakash Gollapudi <bprakash@broadcom.com>");
17d87c45 35MODULE_DESCRIPTION("QLogic NetXtreme II BCM57710 FCoE Driver");
853e2bd2
BG
36MODULE_LICENSE("GPL");
37MODULE_VERSION(DRV_MODULE_VERSION);
38
39#define BNX2FC_MAX_QUEUE_DEPTH 256
40#define BNX2FC_MIN_QUEUE_DEPTH 32
41#define FCOE_WORD_TO_BYTE 4
42
43static struct scsi_transport_template *bnx2fc_transport_template;
44static struct scsi_transport_template *bnx2fc_vport_xport_template;
45
46struct workqueue_struct *bnx2fc_wq;
47
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
50 */
51struct fcoe_percpu_s bnx2fc_global;
52DEFINE_SPINLOCK(bnx2fc_global_lock);
53
54static struct cnic_ulp_ops bnx2fc_cnic_cb;
55static struct libfc_function_template bnx2fc_libfc_fcn_templ;
56static struct scsi_host_template bnx2fc_shost_template;
57static struct fc_function_template bnx2fc_transport_function;
8d55e507 58static struct fcoe_sysfs_function_template bnx2fc_fcoe_sysfs_templ;
853e2bd2
BG
59static struct fc_function_template bnx2fc_vport_xport_function;
60static int bnx2fc_create(struct net_device *netdev, enum fip_state fip_mode);
eccdcd02 61static void __bnx2fc_destroy(struct bnx2fc_interface *interface);
853e2bd2
BG
62static int bnx2fc_destroy(struct net_device *net_device);
63static int bnx2fc_enable(struct net_device *netdev);
64static int bnx2fc_disable(struct net_device *netdev);
65
6e89ea3f
RL
66/* fcoe_syfs control interface handlers */
67static int bnx2fc_ctlr_alloc(struct net_device *netdev);
68static int bnx2fc_ctlr_enabled(struct fcoe_ctlr_device *cdev);
69
853e2bd2
BG
70static void bnx2fc_recv_frame(struct sk_buff *skb);
71
aea71a02 72static void bnx2fc_start_disc(struct bnx2fc_interface *interface);
853e2bd2 73static int bnx2fc_shost_config(struct fc_lport *lport, struct device *dev);
853e2bd2 74static int bnx2fc_lport_config(struct fc_lport *lport);
0eb43b4b 75static int bnx2fc_em_config(struct fc_lport *lport, struct bnx2fc_hba *hba);
853e2bd2
BG
76static int bnx2fc_bind_adapter_devices(struct bnx2fc_hba *hba);
77static void bnx2fc_unbind_adapter_devices(struct bnx2fc_hba *hba);
78static int bnx2fc_bind_pcidev(struct bnx2fc_hba *hba);
79static void bnx2fc_unbind_pcidev(struct bnx2fc_hba *hba);
aea71a02 80static struct fc_lport *bnx2fc_if_create(struct bnx2fc_interface *interface,
853e2bd2
BG
81 struct device *parent, int npiv);
82static void bnx2fc_destroy_work(struct work_struct *work);
83
84static struct bnx2fc_hba *bnx2fc_hba_lookup(struct net_device *phys_dev);
aea71a02
BPG
85static struct bnx2fc_interface *bnx2fc_interface_lookup(struct net_device
86 *phys_dev);
abc49a93 87static inline void bnx2fc_interface_put(struct bnx2fc_interface *interface);
853e2bd2
BG
88static struct bnx2fc_hba *bnx2fc_find_hba_for_cnic(struct cnic_dev *cnic);
89
90static int bnx2fc_fw_init(struct bnx2fc_hba *hba);
91static void bnx2fc_fw_destroy(struct bnx2fc_hba *hba);
92
93static void bnx2fc_port_shutdown(struct fc_lport *lport);
aea71a02 94static void bnx2fc_stop(struct bnx2fc_interface *interface);
853e2bd2
BG
95static int __init bnx2fc_mod_init(void);
96static void __exit bnx2fc_mod_exit(void);
97
98unsigned int bnx2fc_debug_level;
99module_param_named(debug_logging, bnx2fc_debug_level, int, S_IRUGO|S_IWUSR);
100
101static int bnx2fc_cpu_callback(struct notifier_block *nfb,
102 unsigned long action, void *hcpu);
103/* notification function for CPU hotplug events */
104static struct notifier_block bnx2fc_cpu_notifier = {
105 .notifier_call = bnx2fc_cpu_callback,
106};
107
f72f6979
BPG
108static inline struct net_device *bnx2fc_netdev(const struct fc_lport *lport)
109{
110 return ((struct bnx2fc_interface *)
111 ((struct fcoe_port *)lport_priv(lport))->priv)->netdev;
112}
113
8d55e507
RL
114static void bnx2fc_fcf_get_vlan_id(struct fcoe_fcf_device *fcf_dev)
115{
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);
120
121 fcf_dev->vlan_id = fcoe->vlan_id;
122}
123
853e2bd2
BG
124static void bnx2fc_clean_rx_queue(struct fc_lport *lp)
125{
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;
131
132 bg = &bnx2fc_global;
133 spin_lock_bh(&bg->fcoe_rx_list.lock);
134 list = &bg->fcoe_rx_list;
135 head = list->next;
136 for (skb = head; skb != (struct sk_buff *)list;
137 skb = next) {
138 next = skb->next;
139 fr = fcoe_dev_from_skb(skb);
140 if (fr->fr_dev == lp) {
141 __skb_unlink(skb, list);
142 kfree_skb(skb);
143 }
144 }
145 spin_unlock_bh(&bg->fcoe_rx_list.lock);
146}
147
148int bnx2fc_get_paged_crc_eof(struct sk_buff *skb, int tlen)
149{
150 int rc;
151 spin_lock(&bnx2fc_global_lock);
152 rc = fcoe_get_paged_crc_eof(skb, tlen, &bnx2fc_global);
153 spin_unlock(&bnx2fc_global_lock);
154
155 return rc;
156}
157
158static void bnx2fc_abort_io(struct fc_lport *lport)
159{
160 /*
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
164 * fc_fcp_abort_io.
165 */
166}
167
168static void bnx2fc_cleanup(struct fc_lport *lport)
169{
170 struct fcoe_port *port = lport_priv(lport);
aea71a02
BPG
171 struct bnx2fc_interface *interface = port->priv;
172 struct bnx2fc_hba *hba = interface->hba;
853e2bd2
BG
173 struct bnx2fc_rport *tgt;
174 int i;
175
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];
181 if (tgt) {
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);
188 }
189 }
190 }
191 spin_unlock_bh(&hba->hba_lock);
192 mutex_unlock(&hba->hba_mutex);
193}
194
195static int bnx2fc_xmit_l2_frame(struct bnx2fc_rport *tgt,
196 struct fc_frame *fp)
197{
198 struct fc_rport_priv *rdata = tgt->rdata;
199 struct fc_frame_header *fh;
200 int rc = 0;
201
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)) {
208
209 switch (fc_frame_payload_op(fp)) {
210 case ELS_ADISC:
211 rc = bnx2fc_send_adisc(tgt, fp);
212 break;
213 case ELS_LOGO:
214 rc = bnx2fc_send_logo(tgt, fp);
215 break;
216 case ELS_RLS:
217 rc = bnx2fc_send_rls(tgt, fp);
218 break;
219 default:
220 break;
221 }
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");
225 else {
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);
229 return -ENODEV;
230 }
231 if (rc)
232 return -ENOMEM;
233 else
234 return 0;
235}
236
237/**
238 * bnx2fc_xmit - bnx2fc's FCoE frame transmit function
239 *
240 * @lport: the associated local port
241 * @fp: the fc_frame to be transmitted
242 */
243static int bnx2fc_xmit(struct fc_lport *lport, struct fc_frame *fp)
244{
245 struct ethhdr *eh;
246 struct fcoe_crc_eof *cp;
247 struct sk_buff *skb;
248 struct fc_frame_header *fh;
aea71a02 249 struct bnx2fc_interface *interface;
fd8f8902 250 struct fcoe_ctlr *ctlr;
aea71a02 251 struct bnx2fc_hba *hba;
853e2bd2
BG
252 struct fcoe_port *port;
253 struct fcoe_hdr *hp;
254 struct bnx2fc_rport *tgt;
1bd49b48 255 struct fc_stats *stats;
853e2bd2
BG
256 u8 sof, eof;
257 u32 crc;
258 unsigned int hlen, tlen, elen;
259 int wlen, rc = 0;
260
261 port = (struct fcoe_port *)lport_priv(lport);
aea71a02 262 interface = port->priv;
fd8f8902 263 ctlr = bnx2fc_to_ctlr(interface);
aea71a02 264 hba = interface->hba;
853e2bd2
BG
265
266 fh = fc_frame_header_get(fp);
267
268 skb = fp_skb(fp);
269 if (!lport->link_up) {
270 BNX2FC_HBA_DBG(lport, "bnx2fc_xmit link down\n");
271 kfree_skb(skb);
272 return 0;
273 }
274
275 if (unlikely(fh->fh_r_ctl == FC_RCTL_ELS_REQ)) {
fd8f8902 276 if (!ctlr->sel_fcf) {
853e2bd2
BG
277 BNX2FC_HBA_DBG(lport, "FCF not selected yet!\n");
278 kfree_skb(skb);
279 return -EINVAL;
280 }
fd8f8902 281 if (fcoe_ctlr_els_send(ctlr, lport, skb))
853e2bd2
BG
282 return 0;
283 }
284
285 sof = fr_sof(fp);
286 eof = fr_eof(fp);
287
288 /*
289 * Snoop the frame header to check if the frame is for
290 * an offloaded session
291 */
292 /*
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.
296 */
297
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);
306 if (rc != -ENODEV) {
307 kfree_skb(skb);
308 return rc;
309 }
310 } else {
311 spin_unlock_bh(&hba->hba_lock);
312 }
313
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;
318
319 skb->ip_summed = CHECKSUM_NONE;
320 crc = fcoe_fc_crc(fp);
321
322 /* copy port crc and eof to the skb buff */
323 if (skb_is_nonlinear(skb)) {
324 skb_frag_t *frag;
325 if (bnx2fc_get_paged_crc_eof(skb, tlen)) {
326 kfree_skb(skb);
327 return -ENOMEM;
328 }
329 frag = &skb_shinfo(skb)->frags[skb_shinfo(skb)->nr_frags - 1];
77dfce07 330 cp = kmap_atomic(skb_frag_page(frag)) + frag->page_offset;
853e2bd2
BG
331 } else {
332 cp = (struct fcoe_crc_eof *)skb_put(skb, tlen);
333 }
334
335 memset(cp, 0, sizeof(*cp));
336 cp->fcoe_eof = eof;
337 cp->fcoe_crc32 = cpu_to_le32(~crc);
338 if (skb_is_nonlinear(skb)) {
77dfce07 339 kunmap_atomic(cp);
853e2bd2
BG
340 cp = NULL;
341 }
342
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);
347 skb->mac_len = elen;
348 skb->protocol = htons(ETH_P_FCOE);
aea71a02 349 skb->dev = interface->netdev;
853e2bd2
BG
350
351 /* fill up mac and fcoe headers */
352 eh = eth_hdr(skb);
353 eh->h_proto = htons(ETH_P_FCOE);
fd8f8902 354 if (ctlr->map_dest)
853e2bd2
BG
355 fc_fcoe_set_mac(eh->h_dest, fh->fh_d_id);
356 else
357 /* insert GW address */
fd8f8902 358 memcpy(eh->h_dest, ctlr->dest_addr, ETH_ALEN);
853e2bd2 359
fd8f8902
RL
360 if (unlikely(ctlr->flogi_oxid != FC_XID_UNKNOWN))
361 memcpy(eh->h_source, ctlr->ctl_src_addr, ETH_ALEN);
853e2bd2
BG
362 else
363 memcpy(eh->h_source, port->data_src_addr, ETH_ALEN);
364
365 hp = (struct fcoe_hdr *)(eh + 1);
366 memset(hp, 0, sizeof(*hp));
367 if (FC_FCOE_VER)
368 FC_FCOE_ENCAPS_VER(hp, FC_FCOE_VER);
369 hp->fcoe_sof = sof;
370
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);
375 } else {
376 skb_shinfo(skb)->gso_type = 0;
377 skb_shinfo(skb)->gso_size = 0;
378 }
379
380 /*update tx stats */
1bd49b48 381 stats = per_cpu_ptr(lport->stats, get_cpu());
853e2bd2
BG
382 stats->TxFrames++;
383 stats->TxWords += wlen;
384 put_cpu();
385
386 /* send down to lld */
387 fr_dev(fp) = lport;
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);
392
393 return 0;
394}
395
396/**
397 * bnx2fc_rcv - This is bnx2fc's receive function called by NET_RX_SOFTIRQ
398 *
399 * @skb: the receive socket buffer
400 * @dev: associated net device
401 * @ptype: context
402 * @olddev: last device
403 *
404 * This function receives the packet and builds FC frame and passes it up
405 */
406static int bnx2fc_rcv(struct sk_buff *skb, struct net_device *dev,
407 struct packet_type *ptype, struct net_device *olddev)
408{
409 struct fc_lport *lport;
aea71a02 410 struct bnx2fc_interface *interface;
fd8f8902 411 struct fcoe_ctlr *ctlr;
853e2bd2
BG
412 struct fc_frame_header *fh;
413 struct fcoe_rcv_info *fr;
414 struct fcoe_percpu_s *bg;
415 unsigned short oxid;
416
aea71a02
BPG
417 interface = container_of(ptype, struct bnx2fc_interface,
418 fcoe_packet_type);
fd8f8902
RL
419 ctlr = bnx2fc_to_ctlr(interface);
420 lport = ctlr->lp;
853e2bd2
BG
421
422 if (unlikely(lport == NULL)) {
b2a554ff 423 printk(KERN_ERR PFX "bnx2fc_rcv: lport is NULL\n");
853e2bd2
BG
424 goto err;
425 }
426
427 if (unlikely(eth_hdr(skb)->h_proto != htons(ETH_P_FCOE))) {
b2a554ff 428 printk(KERN_ERR PFX "bnx2fc_rcv: Wrong FC type frame\n");
853e2bd2
BG
429 goto err;
430 }
431
432 /*
433 * Check for minimum frame length, and make sure required FCoE
434 * and FC headers are pulled into the linear data area.
435 */
436 if (unlikely((skb->len < FCOE_MIN_FRAME) ||
437 !pskb_may_pull(skb, FCOE_HEADER_LEN)))
438 goto err;
439
440 skb_set_transport_header(skb, sizeof(struct fcoe_hdr));
441 fh = (struct fc_frame_header *) skb_transport_header(skb);
442
443 oxid = ntohs(fh->fh_ox_id);
444
445 fr = fcoe_dev_from_skb(skb);
446 fr->fr_dev = lport;
853e2bd2
BG
447
448 bg = &bnx2fc_global;
fc05ab74 449 spin_lock(&bg->fcoe_rx_list.lock);
853e2bd2
BG
450
451 __skb_queue_tail(&bg->fcoe_rx_list, skb);
452 if (bg->fcoe_rx_list.qlen == 1)
453 wake_up_process(bg->thread);
454
fc05ab74 455 spin_unlock(&bg->fcoe_rx_list.lock);
853e2bd2
BG
456
457 return 0;
458err:
459 kfree_skb(skb);
460 return -1;
461}
462
463static int bnx2fc_l2_rcv_thread(void *arg)
464{
465 struct fcoe_percpu_s *bg = arg;
466 struct sk_buff *skb;
467
8698a745 468 set_user_nice(current, MIN_NICE);
853e2bd2
BG
469 set_current_state(TASK_INTERRUPTIBLE);
470 while (!kthread_should_stop()) {
471 schedule();
853e2bd2
BG
472 spin_lock_bh(&bg->fcoe_rx_list.lock);
473 while ((skb = __skb_dequeue(&bg->fcoe_rx_list)) != NULL) {
474 spin_unlock_bh(&bg->fcoe_rx_list.lock);
475 bnx2fc_recv_frame(skb);
476 spin_lock_bh(&bg->fcoe_rx_list.lock);
477 }
fee78712 478 __set_current_state(TASK_INTERRUPTIBLE);
853e2bd2 479 spin_unlock_bh(&bg->fcoe_rx_list.lock);
853e2bd2 480 }
fee78712 481 __set_current_state(TASK_RUNNING);
853e2bd2
BG
482 return 0;
483}
484
485
486static void bnx2fc_recv_frame(struct sk_buff *skb)
487{
488 u32 fr_len;
489 struct fc_lport *lport;
490 struct fcoe_rcv_info *fr;
1bd49b48 491 struct fc_stats *stats;
853e2bd2
BG
492 struct fc_frame_header *fh;
493 struct fcoe_crc_eof crc_eof;
494 struct fc_frame *fp;
495 struct fc_lport *vn_port;
496 struct fcoe_port *port;
497 u8 *mac = NULL;
498 u8 *dest_mac = NULL;
499 struct fcoe_hdr *hp;
500
501 fr = fcoe_dev_from_skb(skb);
502 lport = fr->fr_dev;
503 if (unlikely(lport == NULL)) {
b2a554ff 504 printk(KERN_ERR PFX "Invalid lport struct\n");
853e2bd2
BG
505 kfree_skb(skb);
506 return;
507 }
508
509 if (skb_is_nonlinear(skb))
510 skb_linearize(skb);
511 mac = eth_hdr(skb)->h_source;
512 dest_mac = eth_hdr(skb)->h_dest;
513
514 /* Pull the header */
515 hp = (struct fcoe_hdr *) skb_network_header(skb);
516 fh = (struct fc_frame_header *) skb_transport_header(skb);
517 skb_pull(skb, sizeof(struct fcoe_hdr));
518 fr_len = skb->len - sizeof(struct fcoe_crc_eof);
519
853e2bd2
BG
520 fp = (struct fc_frame *)skb;
521 fc_frame_init(fp);
522 fr_dev(fp) = lport;
523 fr_sof(fp) = hp->fcoe_sof;
524 if (skb_copy_bits(skb, fr_len, &crc_eof, sizeof(crc_eof))) {
853e2bd2
BG
525 kfree_skb(skb);
526 return;
527 }
528 fr_eof(fp) = crc_eof.fcoe_eof;
529 fr_crc(fp) = crc_eof.fcoe_crc32;
530 if (pskb_trim(skb, fr_len)) {
853e2bd2
BG
531 kfree_skb(skb);
532 return;
533 }
534
535 fh = fc_frame_header_get(fp);
536
537 vn_port = fc_vport_id_lookup(lport, ntoh24(fh->fh_d_id));
538 if (vn_port) {
539 port = lport_priv(vn_port);
6942df7f 540 if (!ether_addr_equal(port->data_src_addr, dest_mac)) {
853e2bd2 541 BNX2FC_HBA_DBG(lport, "fpma mismatch\n");
853e2bd2
BG
542 kfree_skb(skb);
543 return;
544 }
545 }
546 if (fh->fh_r_ctl == FC_RCTL_DD_SOL_DATA &&
547 fh->fh_type == FC_TYPE_FCP) {
548 /* Drop FCP data. We dont this in L2 path */
853e2bd2
BG
549 kfree_skb(skb);
550 return;
551 }
552 if (fh->fh_r_ctl == FC_RCTL_ELS_REQ &&
553 fh->fh_type == FC_TYPE_ELS) {
554 switch (fc_frame_payload_op(fp)) {
555 case ELS_LOGO:
556 if (ntoh24(fh->fh_s_id) == FC_FID_FLOGI) {
557 /* drop non-FIP LOGO */
853e2bd2
BG
558 kfree_skb(skb);
559 return;
560 }
561 break;
562 }
563 }
3f8744d1
BPG
564
565 if (fh->fh_r_ctl == FC_RCTL_BA_ABTS) {
566 /* Drop incoming ABTS */
3f8744d1
BPG
567 kfree_skb(skb);
568 return;
569 }
570
d576a5e8
NH
571 stats = per_cpu_ptr(lport->stats, smp_processor_id());
572 stats->RxFrames++;
573 stats->RxWords += fr_len / FCOE_WORD_TO_BYTE;
574
853e2bd2
BG
575 if (le32_to_cpu(fr_crc(fp)) !=
576 ~crc32(~0, skb->data, fr_len)) {
577 if (stats->InvalidCRCCount < 5)
578 printk(KERN_WARNING PFX "dropping frame with "
579 "CRC error\n");
580 stats->InvalidCRCCount++;
853e2bd2
BG
581 kfree_skb(skb);
582 return;
583 }
853e2bd2
BG
584 fc_exch_recv(lport, fp);
585}
586
587/**
588 * bnx2fc_percpu_io_thread - thread per cpu for ios
589 *
590 * @arg: ptr to bnx2fc_percpu_info structure
591 */
592int bnx2fc_percpu_io_thread(void *arg)
593{
594 struct bnx2fc_percpu_s *p = arg;
595 struct bnx2fc_work *work, *tmp;
596 LIST_HEAD(work_list);
597
8698a745 598 set_user_nice(current, MIN_NICE);
853e2bd2
BG
599 set_current_state(TASK_INTERRUPTIBLE);
600 while (!kthread_should_stop()) {
601 schedule();
853e2bd2
BG
602 spin_lock_bh(&p->fp_work_lock);
603 while (!list_empty(&p->work_list)) {
604 list_splice_init(&p->work_list, &work_list);
605 spin_unlock_bh(&p->fp_work_lock);
606
607 list_for_each_entry_safe(work, tmp, &work_list, list) {
608 list_del_init(&work->list);
609 bnx2fc_process_cq_compl(work->tgt, work->wqe);
610 kfree(work);
611 }
612
613 spin_lock_bh(&p->fp_work_lock);
614 }
fee78712 615 __set_current_state(TASK_INTERRUPTIBLE);
853e2bd2 616 spin_unlock_bh(&p->fp_work_lock);
853e2bd2 617 }
fee78712 618 __set_current_state(TASK_RUNNING);
853e2bd2
BG
619
620 return 0;
621}
622
623static struct fc_host_statistics *bnx2fc_get_host_stats(struct Scsi_Host *shost)
624{
625 struct fc_host_statistics *bnx2fc_stats;
626 struct fc_lport *lport = shost_priv(shost);
627 struct fcoe_port *port = lport_priv(lport);
aea71a02
BPG
628 struct bnx2fc_interface *interface = port->priv;
629 struct bnx2fc_hba *hba = interface->hba;
853e2bd2
BG
630 struct fcoe_statistics_params *fw_stats;
631 int rc = 0;
632
633 fw_stats = (struct fcoe_statistics_params *)hba->stats_buffer;
634 if (!fw_stats)
635 return NULL;
636
637 bnx2fc_stats = fc_get_host_stats(shost);
638
639 init_completion(&hba->stat_req_done);
640 if (bnx2fc_send_stat_req(hba))
641 return bnx2fc_stats;
642 rc = wait_for_completion_timeout(&hba->stat_req_done, (2 * HZ));
643 if (!rc) {
644 BNX2FC_HBA_DBG(lport, "FW stat req timed out\n");
645 return bnx2fc_stats;
646 }
f246fe2a
BPG
647 BNX2FC_STATS(hba, rx_stat2, fc_crc_cnt);
648 bnx2fc_stats->invalid_crc_count += hba->bfw_stats.fc_crc_cnt;
649 BNX2FC_STATS(hba, tx_stat, fcoe_tx_pkt_cnt);
650 bnx2fc_stats->tx_frames += hba->bfw_stats.fcoe_tx_pkt_cnt;
651 BNX2FC_STATS(hba, tx_stat, fcoe_tx_byte_cnt);
652 bnx2fc_stats->tx_words += ((hba->bfw_stats.fcoe_tx_byte_cnt) / 4);
653 BNX2FC_STATS(hba, rx_stat0, fcoe_rx_pkt_cnt);
654 bnx2fc_stats->rx_frames += hba->bfw_stats.fcoe_rx_pkt_cnt;
655 BNX2FC_STATS(hba, rx_stat0, fcoe_rx_byte_cnt);
656 bnx2fc_stats->rx_words += ((hba->bfw_stats.fcoe_rx_byte_cnt) / 4);
853e2bd2
BG
657
658 bnx2fc_stats->dumped_frames = 0;
659 bnx2fc_stats->lip_count = 0;
660 bnx2fc_stats->nos_count = 0;
661 bnx2fc_stats->loss_of_sync_count = 0;
662 bnx2fc_stats->loss_of_signal_count = 0;
663 bnx2fc_stats->prim_seq_protocol_err_count = 0;
664
f246fe2a
BPG
665 memcpy(&hba->prev_stats, hba->stats_buffer,
666 sizeof(struct fcoe_statistics_params));
853e2bd2
BG
667 return bnx2fc_stats;
668}
669
670static int bnx2fc_shost_config(struct fc_lport *lport, struct device *dev)
671{
672 struct fcoe_port *port = lport_priv(lport);
aea71a02 673 struct bnx2fc_interface *interface = port->priv;
c13d2b6d 674 struct bnx2fc_hba *hba = interface->hba;
853e2bd2
BG
675 struct Scsi_Host *shost = lport->host;
676 int rc = 0;
677
678 shost->max_cmd_len = BNX2FC_MAX_CMD_LEN;
679 shost->max_lun = BNX2FC_MAX_LUN;
680 shost->max_id = BNX2FC_MAX_FCP_TGT;
681 shost->max_channel = 0;
682 if (lport->vport)
683 shost->transportt = bnx2fc_vport_xport_template;
684 else
685 shost->transportt = bnx2fc_transport_template;
686
687 /* Add the new host to SCSI-ml */
688 rc = scsi_add_host(lport->host, dev);
689 if (rc) {
690 printk(KERN_ERR PFX "Error on scsi_add_host\n");
691 return rc;
692 }
693 if (!lport->vport)
694 fc_host_max_npiv_vports(lport->host) = USHRT_MAX;
c13d2b6d 695 snprintf(fc_host_symbolic_name(lport->host), 256,
17d87c45 696 "%s (QLogic %s) v%s over %s",
c13d2b6d 697 BNX2FC_NAME, hba->chip_num, BNX2FC_VERSION,
aea71a02 698 interface->netdev->name);
853e2bd2
BG
699
700 return 0;
701}
702
853e2bd2
BG
703static int bnx2fc_link_ok(struct fc_lport *lport)
704{
705 struct fcoe_port *port = lport_priv(lport);
aea71a02
BPG
706 struct bnx2fc_interface *interface = port->priv;
707 struct bnx2fc_hba *hba = interface->hba;
853e2bd2
BG
708 struct net_device *dev = hba->phys_dev;
709 int rc = 0;
710
711 if ((dev->flags & IFF_UP) && netif_carrier_ok(dev))
712 clear_bit(ADAPTER_STATE_LINK_DOWN, &hba->adapter_state);
713 else {
714 set_bit(ADAPTER_STATE_LINK_DOWN, &hba->adapter_state);
715 rc = -1;
716 }
717 return rc;
718}
719
720/**
721 * bnx2fc_get_link_state - get network link state
722 *
723 * @hba: adapter instance pointer
724 *
725 * updates adapter structure flag based on netdev state
726 */
727void bnx2fc_get_link_state(struct bnx2fc_hba *hba)
728{
aea71a02 729 if (test_bit(__LINK_STATE_NOCARRIER, &hba->phys_dev->state))
853e2bd2
BG
730 set_bit(ADAPTER_STATE_LINK_DOWN, &hba->adapter_state);
731 else
732 clear_bit(ADAPTER_STATE_LINK_DOWN, &hba->adapter_state);
733}
734
52439607 735static int bnx2fc_net_config(struct fc_lport *lport, struct net_device *netdev)
853e2bd2
BG
736{
737 struct bnx2fc_hba *hba;
aea71a02 738 struct bnx2fc_interface *interface;
fd8f8902 739 struct fcoe_ctlr *ctlr;
853e2bd2
BG
740 struct fcoe_port *port;
741 u64 wwnn, wwpn;
742
743 port = lport_priv(lport);
aea71a02 744 interface = port->priv;
fd8f8902 745 ctlr = bnx2fc_to_ctlr(interface);
aea71a02 746 hba = interface->hba;
853e2bd2
BG
747
748 /* require support for get_pauseparam ethtool op. */
749 if (!hba->phys_dev->ethtool_ops ||
750 !hba->phys_dev->ethtool_ops->get_pauseparam)
751 return -EOPNOTSUPP;
752
1294bfe6 753 if (fc_set_mfs(lport, BNX2FC_MFS))
853e2bd2
BG
754 return -EINVAL;
755
756 skb_queue_head_init(&port->fcoe_pending_queue);
757 port->fcoe_pending_queue_active = 0;
758 setup_timer(&port->timer, fcoe_queue_timer, (unsigned long) lport);
759
0e0f9cd6 760 fcoe_link_speed_update(lport);
853e2bd2
BG
761
762 if (!lport->vport) {
52439607 763 if (fcoe_get_wwn(netdev, &wwnn, NETDEV_FCOE_WWNN))
fd8f8902 764 wwnn = fcoe_wwn_from_mac(ctlr->ctl_src_addr,
52439607 765 1, 0);
853e2bd2
BG
766 BNX2FC_HBA_DBG(lport, "WWNN = 0x%llx\n", wwnn);
767 fc_set_wwnn(lport, wwnn);
768
52439607 769 if (fcoe_get_wwn(netdev, &wwpn, NETDEV_FCOE_WWPN))
fd8f8902 770 wwpn = fcoe_wwn_from_mac(ctlr->ctl_src_addr,
52439607
BPG
771 2, 0);
772
853e2bd2
BG
773 BNX2FC_HBA_DBG(lport, "WWPN = 0x%llx\n", wwpn);
774 fc_set_wwpn(lport, wwpn);
775 }
776
777 return 0;
778}
779
780static void bnx2fc_destroy_timer(unsigned long data)
781{
782 struct bnx2fc_hba *hba = (struct bnx2fc_hba *)data;
783
cd703ae7
BPG
784 printk(KERN_ERR PFX "ERROR:bnx2fc_destroy_timer - "
785 "Destroy compl not received!!\n");
aea71a02 786 set_bit(BNX2FC_FLAG_DESTROY_CMPL, &hba->flags);
853e2bd2
BG
787 wake_up_interruptible(&hba->destroy_wait);
788}
789
790/**
791 * bnx2fc_indicate_netevent - Generic netdev event handler
792 *
793 * @context: adapter structure pointer
794 * @event: event type
415199f2 795 * @vlan_id: vlan id - associated vlan id with this event
853e2bd2
BG
796 *
797 * Handles NETDEV_UP, NETDEV_DOWN, NETDEV_GOING_DOWN,NETDEV_CHANGE and
abc49a93 798 * NETDEV_CHANGE_MTU events. Handle NETDEV_UNREGISTER only for vlans.
853e2bd2 799 */
415199f2
MC
800static void bnx2fc_indicate_netevent(void *context, unsigned long event,
801 u16 vlan_id)
853e2bd2
BG
802{
803 struct bnx2fc_hba *hba = (struct bnx2fc_hba *)context;
6e89ea3f 804 struct fcoe_ctlr_device *cdev;
aea71a02 805 struct fc_lport *lport;
853e2bd2 806 struct fc_lport *vport;
abc49a93 807 struct bnx2fc_interface *interface, *tmp;
fd8f8902 808 struct fcoe_ctlr *ctlr;
aea71a02 809 int wait_for_upload = 0;
853e2bd2
BG
810 u32 link_possible = 1;
811
abc49a93 812 if (vlan_id != 0 && event != NETDEV_UNREGISTER)
415199f2
MC
813 return;
814
853e2bd2
BG
815 switch (event) {
816 case NETDEV_UP:
853e2bd2
BG
817 if (!test_bit(ADAPTER_STATE_UP, &hba->adapter_state))
818 printk(KERN_ERR "indicate_netevent: "\
aea71a02 819 "hba is not UP!!\n");
853e2bd2
BG
820 break;
821
822 case NETDEV_DOWN:
853e2bd2
BG
823 clear_bit(ADAPTER_STATE_GOING_DOWN, &hba->adapter_state);
824 clear_bit(ADAPTER_STATE_UP, &hba->adapter_state);
825 link_possible = 0;
826 break;
827
828 case NETDEV_GOING_DOWN:
853e2bd2
BG
829 set_bit(ADAPTER_STATE_GOING_DOWN, &hba->adapter_state);
830 link_possible = 0;
831 break;
832
833 case NETDEV_CHANGE:
853e2bd2
BG
834 break;
835
abc49a93
BPG
836 case NETDEV_UNREGISTER:
837 if (!vlan_id)
838 return;
839 mutex_lock(&bnx2fc_dev_lock);
840 list_for_each_entry_safe(interface, tmp, &if_list, list) {
26b2982f
NNS
841 if (interface->hba == hba &&
842 interface->vlan_id == (vlan_id & VLAN_VID_MASK))
843 __bnx2fc_destroy(interface);
abc49a93
BPG
844 }
845 mutex_unlock(&bnx2fc_dev_lock);
06c4f20d
EW
846
847 /* Ensure ALL destroy work has been completed before return */
848 flush_workqueue(bnx2fc_wq);
abc49a93
BPG
849 return;
850
853e2bd2 851 default:
59e13d48 852 printk(KERN_ERR PFX "Unknown netevent %ld", event);
853e2bd2
BG
853 return;
854 }
855
aea71a02
BPG
856 mutex_lock(&bnx2fc_dev_lock);
857 list_for_each_entry(interface, &if_list, list) {
853e2bd2 858
aea71a02
BPG
859 if (interface->hba != hba)
860 continue;
861
fd8f8902
RL
862 ctlr = bnx2fc_to_ctlr(interface);
863 lport = ctlr->lp;
aea71a02
BPG
864 BNX2FC_HBA_DBG(lport, "netevent handler - event=%s %ld\n",
865 interface->netdev->name, event);
866
0e0f9cd6 867 fcoe_link_speed_update(lport);
aea71a02 868
6e89ea3f 869 cdev = fcoe_ctlr_to_ctlr_dev(ctlr);
aea71a02
BPG
870
871 if (link_possible && !bnx2fc_link_ok(lport)) {
6e89ea3f
RL
872 switch (cdev->enabled) {
873 case FCOE_CTLR_DISABLED:
874 pr_info("Link up while interface is disabled.\n");
875 break;
876 case FCOE_CTLR_ENABLED:
877 case FCOE_CTLR_UNUSED:
878 /* Reset max recv frame size to default */
879 fc_set_mfs(lport, BNX2FC_MFS);
880 /*
881 * ctlr link up will only be handled during
882 * enable to avoid sending discovery
883 * solicitation on a stale vlan
884 */
885 if (interface->enabled)
886 fcoe_ctlr_link_up(ctlr);
887 };
fd8f8902 888 } else if (fcoe_ctlr_link_down(ctlr)) {
6e89ea3f
RL
889 switch (cdev->enabled) {
890 case FCOE_CTLR_DISABLED:
891 pr_info("Link down while interface is disabled.\n");
892 break;
893 case FCOE_CTLR_ENABLED:
894 case FCOE_CTLR_UNUSED:
895 mutex_lock(&lport->lp_mutex);
896 list_for_each_entry(vport, &lport->vports, list)
897 fc_host_port_type(vport->host) =
898 FC_PORTTYPE_UNKNOWN;
899 mutex_unlock(&lport->lp_mutex);
900 fc_host_port_type(lport->host) =
901 FC_PORTTYPE_UNKNOWN;
902 per_cpu_ptr(lport->stats,
903 get_cpu())->LinkFailureCount++;
904 put_cpu();
905 fcoe_clean_pending_queue(lport);
906 wait_for_upload = 1;
907 };
aea71a02
BPG
908 }
909 }
910 mutex_unlock(&bnx2fc_dev_lock);
853e2bd2 911
aea71a02
BPG
912 if (wait_for_upload) {
913 clear_bit(ADAPTER_STATE_READY, &hba->adapter_state);
914 init_waitqueue_head(&hba->shutdown_wait);
915 BNX2FC_MISC_DBG("indicate_netevent "
916 "num_ofld_sess = %d\n",
917 hba->num_ofld_sess);
918 hba->wait_for_link_down = 1;
919 wait_event_interruptible(hba->shutdown_wait,
920 (hba->num_ofld_sess == 0));
921 BNX2FC_MISC_DBG("wakeup - num_ofld_sess = %d\n",
853e2bd2 922 hba->num_ofld_sess);
aea71a02 923 hba->wait_for_link_down = 0;
853e2bd2 924
aea71a02
BPG
925 if (signal_pending(current))
926 flush_signals(current);
853e2bd2
BG
927 }
928}
929
930static int bnx2fc_libfc_config(struct fc_lport *lport)
931{
932
933 /* Set the function pointers set by bnx2fc driver */
934 memcpy(&lport->tt, &bnx2fc_libfc_fcn_templ,
935 sizeof(struct libfc_function_template));
936 fc_elsct_init(lport);
937 fc_exch_init(lport);
938 fc_rport_init(lport);
0807619d
RL
939 fc_disc_init(lport);
940 fc_disc_config(lport, lport);
853e2bd2
BG
941 return 0;
942}
943
0eb43b4b 944static int bnx2fc_em_config(struct fc_lport *lport, struct bnx2fc_hba *hba)
853e2bd2 945{
0eb43b4b 946 int fcoe_min_xid, fcoe_max_xid;
7d742f65 947
0eb43b4b 948 fcoe_min_xid = hba->max_xid + 1;
7d742f65 949 if (nr_cpu_ids <= 2)
0eb43b4b 950 fcoe_max_xid = hba->max_xid + FCOE_XIDS_PER_CPU_OFFSET;
7d742f65 951 else
0eb43b4b
BPG
952 fcoe_max_xid = hba->max_xid + FCOE_MAX_XID_OFFSET;
953 if (!fc_exch_mgr_alloc(lport, FC_CLASS_3, fcoe_min_xid,
954 fcoe_max_xid, NULL)) {
853e2bd2
BG
955 printk(KERN_ERR PFX "em_config:fc_exch_mgr_alloc failed\n");
956 return -ENOMEM;
957 }
958
853e2bd2
BG
959 return 0;
960}
961
962static int bnx2fc_lport_config(struct fc_lport *lport)
963{
964 lport->link_up = 0;
965 lport->qfull = 0;
44c570b5
BPG
966 lport->max_retry_count = BNX2FC_MAX_RETRY_CNT;
967 lport->max_rport_retry_count = BNX2FC_MAX_RPORT_RETRY_CNT;
853e2bd2
BG
968 lport->e_d_tov = 2 * 1000;
969 lport->r_a_tov = 10 * 1000;
970
853e2bd2
BG
971 lport->service_params = (FCP_SPPF_INIT_FCN | FCP_SPPF_RD_XRDY_DIS |
972 FCP_SPPF_RETRY | FCP_SPPF_CONF_COMPL);
853e2bd2
BG
973 lport->does_npiv = 1;
974
975 memset(&lport->rnid_gen, 0, sizeof(struct fc_els_rnid_gen));
976 lport->rnid_gen.rnid_atype = BNX2FC_RNID_HBA;
977
978 /* alloc stats structure */
979 if (fc_lport_init_stats(lport))
980 return -ENOMEM;
981
982 /* Finish fc_lport configuration */
983 fc_lport_config(lport);
984
985 return 0;
986}
987
988/**
989 * bnx2fc_fip_recv - handle a received FIP frame.
990 *
991 * @skb: the received skb
992 * @dev: associated &net_device
993 * @ptype: the &packet_type structure which was used to register this handler.
994 * @orig_dev: original receive &net_device, in case @ dev is a bond.
995 *
996 * Returns: 0 for success
997 */
998static int bnx2fc_fip_recv(struct sk_buff *skb, struct net_device *dev,
999 struct packet_type *ptype,
1000 struct net_device *orig_dev)
1001{
aea71a02 1002 struct bnx2fc_interface *interface;
fd8f8902 1003 struct fcoe_ctlr *ctlr;
aea71a02
BPG
1004 interface = container_of(ptype, struct bnx2fc_interface,
1005 fip_packet_type);
fd8f8902
RL
1006 ctlr = bnx2fc_to_ctlr(interface);
1007 fcoe_ctlr_recv(ctlr, skb);
853e2bd2
BG
1008 return 0;
1009}
1010
1011/**
1012 * bnx2fc_update_src_mac - Update Ethernet MAC filters.
1013 *
1014 * @fip: FCoE controller.
1015 * @old: Unicast MAC address to delete if the MAC is non-zero.
1016 * @new: Unicast MAC address to add.
1017 *
1018 * Remove any previously-set unicast MAC filter.
1019 * Add secondary FCoE MAC address filter for our OUI.
1020 */
1021static void bnx2fc_update_src_mac(struct fc_lport *lport, u8 *addr)
1022{
1023 struct fcoe_port *port = lport_priv(lport);
1024
1025 memcpy(port->data_src_addr, addr, ETH_ALEN);
1026}
1027
1028/**
1029 * bnx2fc_get_src_mac - return the ethernet source address for an lport
1030 *
1031 * @lport: libfc port
1032 */
1033static u8 *bnx2fc_get_src_mac(struct fc_lport *lport)
1034{
1035 struct fcoe_port *port;
1036
1037 port = (struct fcoe_port *)lport_priv(lport);
1038 return port->data_src_addr;
1039}
1040
1041/**
1042 * bnx2fc_fip_send - send an Ethernet-encapsulated FIP frame.
1043 *
1044 * @fip: FCoE controller.
1045 * @skb: FIP Packet.
1046 */
1047static void bnx2fc_fip_send(struct fcoe_ctlr *fip, struct sk_buff *skb)
1048{
1049 skb->dev = bnx2fc_from_ctlr(fip)->netdev;
1050 dev_queue_xmit(skb);
1051}
1052
1053static int bnx2fc_vport_create(struct fc_vport *vport, bool disabled)
1054{
1055 struct Scsi_Host *shost = vport_to_shost(vport);
1056 struct fc_lport *n_port = shost_priv(shost);
1057 struct fcoe_port *port = lport_priv(n_port);
aea71a02
BPG
1058 struct bnx2fc_interface *interface = port->priv;
1059 struct net_device *netdev = interface->netdev;
853e2bd2 1060 struct fc_lport *vn_port;
861efc54
BPG
1061 int rc;
1062 char buf[32];
1063
1064 rc = fcoe_validate_vport_create(vport);
1065 if (rc) {
1066 fcoe_wwn_to_str(vport->port_name, buf, sizeof(buf));
1067 printk(KERN_ERR PFX "Failed to create vport, "
1068 "WWPN (0x%s) already exists\n",
1069 buf);
1070 return rc;
1071 }
853e2bd2 1072
aea71a02 1073 if (!test_bit(BNX2FC_FLAG_FW_INIT_DONE, &interface->hba->flags)) {
853e2bd2 1074 printk(KERN_ERR PFX "vn ports cannot be created on"
aea71a02 1075 "this interface\n");
853e2bd2
BG
1076 return -EIO;
1077 }
4bc71cb9 1078 rtnl_lock();
853e2bd2 1079 mutex_lock(&bnx2fc_dev_lock);
aea71a02 1080 vn_port = bnx2fc_if_create(interface, &vport->dev, 1);
853e2bd2 1081 mutex_unlock(&bnx2fc_dev_lock);
4bc71cb9 1082 rtnl_unlock();
853e2bd2 1083
b6829c72 1084 if (!vn_port) {
853e2bd2
BG
1085 printk(KERN_ERR PFX "bnx2fc_vport_create (%s) failed\n",
1086 netdev->name);
1087 return -EIO;
1088 }
1089
1090 if (disabled) {
1091 fc_vport_set_state(vport, FC_VPORT_DISABLED);
1092 } else {
1093 vn_port->boot_time = jiffies;
1094 fc_lport_init(vn_port);
1095 fc_fabric_login(vn_port);
1096 fc_vport_setlink(vn_port);
1097 }
1098 return 0;
1099}
1100
abc49a93
BPG
1101static void bnx2fc_free_vport(struct bnx2fc_hba *hba, struct fc_lport *lport)
1102{
1103 struct bnx2fc_lport *blport, *tmp;
1104
1105 spin_lock_bh(&hba->hba_lock);
1106 list_for_each_entry_safe(blport, tmp, &hba->vports, list) {
1107 if (blport->lport == lport) {
1108 list_del(&blport->list);
1109 kfree(blport);
1110 }
1111 }
1112 spin_unlock_bh(&hba->hba_lock);
1113}
1114
853e2bd2
BG
1115static int bnx2fc_vport_destroy(struct fc_vport *vport)
1116{
1117 struct Scsi_Host *shost = vport_to_shost(vport);
1118 struct fc_lport *n_port = shost_priv(shost);
1119 struct fc_lport *vn_port = vport->dd_data;
1120 struct fcoe_port *port = lport_priv(vn_port);
abc49a93 1121 struct bnx2fc_interface *interface = port->priv;
cdf54668
BPG
1122 struct fc_lport *v_port;
1123 bool found = false;
853e2bd2
BG
1124
1125 mutex_lock(&n_port->lp_mutex);
cdf54668
BPG
1126 list_for_each_entry(v_port, &n_port->vports, list)
1127 if (v_port->vport == vport) {
1128 found = true;
1129 break;
1130 }
1131
1132 if (!found) {
1133 mutex_unlock(&n_port->lp_mutex);
1134 return -ENOENT;
1135 }
853e2bd2
BG
1136 list_del(&vn_port->list);
1137 mutex_unlock(&n_port->lp_mutex);
abc49a93
BPG
1138 bnx2fc_free_vport(interface->hba, port->lport);
1139 bnx2fc_port_shutdown(port->lport);
1140 bnx2fc_interface_put(interface);
853e2bd2
BG
1141 queue_work(bnx2fc_wq, &port->destroy_work);
1142 return 0;
1143}
1144
1145static int bnx2fc_vport_disable(struct fc_vport *vport, bool disable)
1146{
1147 struct fc_lport *lport = vport->dd_data;
1148
1149 if (disable) {
1150 fc_vport_set_state(vport, FC_VPORT_DISABLED);
1151 fc_fabric_logoff(lport);
1152 } else {
1153 lport->boot_time = jiffies;
1154 fc_fabric_login(lport);
1155 fc_vport_setlink(lport);
1156 }
1157 return 0;
1158}
1159
1160
776cebca 1161static int bnx2fc_interface_setup(struct bnx2fc_interface *interface)
853e2bd2 1162{
aea71a02
BPG
1163 struct net_device *netdev = interface->netdev;
1164 struct net_device *physdev = interface->hba->phys_dev;
fd8f8902 1165 struct fcoe_ctlr *ctlr = bnx2fc_to_ctlr(interface);
853e2bd2
BG
1166 struct netdev_hw_addr *ha;
1167 int sel_san_mac = 0;
1168
853e2bd2
BG
1169 /* setup Source MAC Address */
1170 rcu_read_lock();
1171 for_each_dev_addr(physdev, ha) {
1172 BNX2FC_MISC_DBG("net_config: ha->type = %d, fip_mac = ",
1173 ha->type);
1174 printk(KERN_INFO "%2x:%2x:%2x:%2x:%2x:%2x\n", ha->addr[0],
1175 ha->addr[1], ha->addr[2], ha->addr[3],
1176 ha->addr[4], ha->addr[5]);
1177
1178 if ((ha->type == NETDEV_HW_ADDR_T_SAN) &&
1179 (is_valid_ether_addr(ha->addr))) {
fd8f8902 1180 memcpy(ctlr->ctl_src_addr, ha->addr,
aea71a02 1181 ETH_ALEN);
853e2bd2
BG
1182 sel_san_mac = 1;
1183 BNX2FC_MISC_DBG("Found SAN MAC\n");
1184 }
1185 }
1186 rcu_read_unlock();
1187
1188 if (!sel_san_mac)
1189 return -ENODEV;
1190
aea71a02
BPG
1191 interface->fip_packet_type.func = bnx2fc_fip_recv;
1192 interface->fip_packet_type.type = htons(ETH_P_FIP);
1193 interface->fip_packet_type.dev = netdev;
1194 dev_add_pack(&interface->fip_packet_type);
853e2bd2 1195
aea71a02
BPG
1196 interface->fcoe_packet_type.func = bnx2fc_rcv;
1197 interface->fcoe_packet_type.type = __constant_htons(ETH_P_FCOE);
1198 interface->fcoe_packet_type.dev = netdev;
1199 dev_add_pack(&interface->fcoe_packet_type);
853e2bd2
BG
1200
1201 return 0;
1202}
1203
1204static int bnx2fc_attach_transport(void)
1205{
1206 bnx2fc_transport_template =
1207 fc_attach_transport(&bnx2fc_transport_function);
1208
1209 if (bnx2fc_transport_template == NULL) {
1210 printk(KERN_ERR PFX "Failed to attach FC transport\n");
1211 return -ENODEV;
1212 }
1213
1214 bnx2fc_vport_xport_template =
1215 fc_attach_transport(&bnx2fc_vport_xport_function);
1216 if (bnx2fc_vport_xport_template == NULL) {
1217 printk(KERN_ERR PFX
1218 "Failed to attach FC transport for vport\n");
1219 fc_release_transport(bnx2fc_transport_template);
1220 bnx2fc_transport_template = NULL;
1221 return -ENODEV;
1222 }
1223 return 0;
1224}
1225static void bnx2fc_release_transport(void)
1226{
1227 fc_release_transport(bnx2fc_transport_template);
1228 fc_release_transport(bnx2fc_vport_xport_template);
1229 bnx2fc_transport_template = NULL;
1230 bnx2fc_vport_xport_template = NULL;
1231}
1232
1233static void bnx2fc_interface_release(struct kref *kref)
1234{
8d55e507 1235 struct fcoe_ctlr_device *ctlr_dev;
aea71a02 1236 struct bnx2fc_interface *interface;
fd8f8902 1237 struct fcoe_ctlr *ctlr;
853e2bd2 1238 struct net_device *netdev;
853e2bd2 1239
aea71a02 1240 interface = container_of(kref, struct bnx2fc_interface, kref);
068bdce4 1241 BNX2FC_MISC_DBG("Interface is being released\n");
853e2bd2 1242
fd8f8902 1243 ctlr = bnx2fc_to_ctlr(interface);
8d55e507 1244 ctlr_dev = fcoe_ctlr_to_ctlr_dev(ctlr);
aea71a02 1245 netdev = interface->netdev;
853e2bd2
BG
1246
1247 /* tear-down FIP controller */
aea71a02 1248 if (test_and_clear_bit(BNX2FC_CTLR_INIT_DONE, &interface->if_flags))
fd8f8902 1249 fcoe_ctlr_destroy(ctlr);
aea71a02 1250
8d55e507 1251 fcoe_ctlr_device_delete(ctlr_dev);
853e2bd2 1252
853e2bd2
BG
1253 dev_put(netdev);
1254 module_put(THIS_MODULE);
1255}
1256
aea71a02 1257static inline void bnx2fc_interface_get(struct bnx2fc_interface *interface)
853e2bd2 1258{
aea71a02 1259 kref_get(&interface->kref);
853e2bd2
BG
1260}
1261
aea71a02 1262static inline void bnx2fc_interface_put(struct bnx2fc_interface *interface)
853e2bd2 1263{
aea71a02 1264 kref_put(&interface->kref, bnx2fc_interface_release);
853e2bd2 1265}
aea71a02 1266static void bnx2fc_hba_destroy(struct bnx2fc_hba *hba)
853e2bd2 1267{
aea71a02
BPG
1268 /* Free the command manager */
1269 if (hba->cmd_mgr) {
1270 bnx2fc_cmd_mgr_free(hba->cmd_mgr);
1271 hba->cmd_mgr = NULL;
1272 }
1273 kfree(hba->tgt_ofld_list);
853e2bd2
BG
1274 bnx2fc_unbind_pcidev(hba);
1275 kfree(hba);
1276}
1277
1278/**
aea71a02 1279 * bnx2fc_hba_create - create a new bnx2fc hba
853e2bd2
BG
1280 *
1281 * @cnic: pointer to cnic device
1282 *
aea71a02
BPG
1283 * Creates a new FCoE hba on the given device.
1284 *
853e2bd2 1285 */
aea71a02 1286static struct bnx2fc_hba *bnx2fc_hba_create(struct cnic_dev *cnic)
853e2bd2
BG
1287{
1288 struct bnx2fc_hba *hba;
2e499d3c 1289 struct fcoe_capabilities *fcoe_cap;
853e2bd2
BG
1290 int rc;
1291
1292 hba = kzalloc(sizeof(*hba), GFP_KERNEL);
1293 if (!hba) {
1294 printk(KERN_ERR PFX "Unable to allocate hba structure\n");
1295 return NULL;
1296 }
1297 spin_lock_init(&hba->hba_lock);
1298 mutex_init(&hba->hba_mutex);
1299
1300 hba->cnic = cnic;
0eb43b4b
BPG
1301
1302 hba->max_tasks = cnic->max_fcoe_exchanges;
1303 hba->elstm_xids = (hba->max_tasks / 2);
1304 hba->max_outstanding_cmds = hba->elstm_xids;
1305 hba->max_xid = (hba->max_tasks - 1);
1306
853e2bd2 1307 rc = bnx2fc_bind_pcidev(hba);
aea71a02
BPG
1308 if (rc) {
1309 printk(KERN_ERR PFX "create_adapter: bind error\n");
853e2bd2 1310 goto bind_err;
aea71a02 1311 }
853e2bd2 1312 hba->phys_dev = cnic->netdev;
aea71a02
BPG
1313 hba->next_conn_id = 0;
1314
1315 hba->tgt_ofld_list =
1316 kzalloc(sizeof(struct bnx2fc_rport *) * BNX2FC_NUM_MAX_SESS,
1317 GFP_KERNEL);
1318 if (!hba->tgt_ofld_list) {
1319 printk(KERN_ERR PFX "Unable to allocate tgt offload list\n");
1320 goto tgtofld_err;
1321 }
1322
1323 hba->num_ofld_sess = 0;
1324
0eb43b4b 1325 hba->cmd_mgr = bnx2fc_cmd_mgr_alloc(hba);
aea71a02
BPG
1326 if (!hba->cmd_mgr) {
1327 printk(KERN_ERR PFX "em_config:bnx2fc_cmd_mgr_alloc failed\n");
1328 goto cmgr_err;
1329 }
2e499d3c
BW
1330 fcoe_cap = &hba->fcoe_cap;
1331
1332 fcoe_cap->capability1 = BNX2FC_TM_MAX_SQES <<
1333 FCOE_IOS_PER_CONNECTION_SHIFT;
1334 fcoe_cap->capability1 |= BNX2FC_NUM_MAX_SESS <<
1335 FCOE_LOGINS_PER_PORT_SHIFT;
0eb43b4b 1336 fcoe_cap->capability2 = hba->max_outstanding_cmds <<
2e499d3c
BW
1337 FCOE_NUMBER_OF_EXCHANGES_SHIFT;
1338 fcoe_cap->capability2 |= BNX2FC_MAX_NPIV <<
1339 FCOE_NPIV_WWN_PER_PORT_SHIFT;
1340 fcoe_cap->capability3 = BNX2FC_NUM_MAX_SESS <<
1341 FCOE_TARGETS_SUPPORTED_SHIFT;
0eb43b4b 1342 fcoe_cap->capability3 |= hba->max_outstanding_cmds <<
2e499d3c
BW
1343 FCOE_OUTSTANDING_COMMANDS_SHIFT;
1344 fcoe_cap->capability4 = FCOE_CAPABILITY4_STATEFUL;
853e2bd2
BG
1345
1346 init_waitqueue_head(&hba->shutdown_wait);
1347 init_waitqueue_head(&hba->destroy_wait);
aea71a02 1348 INIT_LIST_HEAD(&hba->vports);
853e2bd2
BG
1349
1350 return hba;
aea71a02
BPG
1351
1352cmgr_err:
1353 kfree(hba->tgt_ofld_list);
1354tgtofld_err:
1355 bnx2fc_unbind_pcidev(hba);
853e2bd2 1356bind_err:
853e2bd2
BG
1357 kfree(hba);
1358 return NULL;
1359}
1360
aea71a02
BPG
1361struct bnx2fc_interface *bnx2fc_interface_create(struct bnx2fc_hba *hba,
1362 struct net_device *netdev,
1363 enum fip_state fip_mode)
853e2bd2 1364{
8d55e507 1365 struct fcoe_ctlr_device *ctlr_dev;
aea71a02 1366 struct bnx2fc_interface *interface;
fd8f8902
RL
1367 struct fcoe_ctlr *ctlr;
1368 int size;
853e2bd2 1369 int rc = 0;
853e2bd2 1370
fd8f8902 1371 size = (sizeof(*interface) + sizeof(struct fcoe_ctlr));
8d55e507
RL
1372 ctlr_dev = fcoe_ctlr_device_add(&netdev->dev, &bnx2fc_fcoe_sysfs_templ,
1373 size);
1374 if (!ctlr_dev) {
aea71a02
BPG
1375 printk(KERN_ERR PFX "Unable to allocate interface structure\n");
1376 return NULL;
1377 }
8d55e507 1378 ctlr = fcoe_ctlr_device_priv(ctlr_dev);
9d34876f 1379 ctlr->cdev = ctlr_dev;
fd8f8902 1380 interface = fcoe_ctlr_priv(ctlr);
853e2bd2 1381 dev_hold(netdev);
aea71a02
BPG
1382 kref_init(&interface->kref);
1383 interface->hba = hba;
1384 interface->netdev = netdev;
853e2bd2
BG
1385
1386 /* Initialize FIP */
fd8f8902
RL
1387 fcoe_ctlr_init(ctlr, fip_mode);
1388 ctlr->send = bnx2fc_fip_send;
1389 ctlr->update_mac = bnx2fc_update_src_mac;
1390 ctlr->get_src_addr = bnx2fc_get_src_mac;
aea71a02 1391 set_bit(BNX2FC_CTLR_INIT_DONE, &interface->if_flags);
853e2bd2 1392
776cebca 1393 rc = bnx2fc_interface_setup(interface);
aea71a02
BPG
1394 if (!rc)
1395 return interface;
853e2bd2 1396
fd8f8902 1397 fcoe_ctlr_destroy(ctlr);
853e2bd2 1398 dev_put(netdev);
8d55e507 1399 fcoe_ctlr_device_delete(ctlr_dev);
aea71a02 1400 return NULL;
853e2bd2
BG
1401}
1402
1403/**
1404 * bnx2fc_if_create - Create FCoE instance on a given interface
1405 *
aea71a02 1406 * @interface: FCoE interface to create a local port on
853e2bd2
BG
1407 * @parent: Device pointer to be the parent in sysfs for the SCSI host
1408 * @npiv: Indicates if the port is vport or not
1409 *
1410 * Creates a fc_lport instance and a Scsi_Host instance and configure them.
1411 *
1412 * Returns: Allocated fc_lport or an error pointer
1413 */
aea71a02 1414static struct fc_lport *bnx2fc_if_create(struct bnx2fc_interface *interface,
853e2bd2
BG
1415 struct device *parent, int npiv)
1416{
fd8f8902 1417 struct fcoe_ctlr *ctlr = bnx2fc_to_ctlr(interface);
134a4e27 1418 struct fc_lport *lport, *n_port;
853e2bd2
BG
1419 struct fcoe_port *port;
1420 struct Scsi_Host *shost;
1421 struct fc_vport *vport = dev_to_vport(parent);
d36b3279 1422 struct bnx2fc_lport *blport;
0eb43b4b 1423 struct bnx2fc_hba *hba = interface->hba;
853e2bd2
BG
1424 int rc = 0;
1425
d36b3279
BPG
1426 blport = kzalloc(sizeof(struct bnx2fc_lport), GFP_KERNEL);
1427 if (!blport) {
fd8f8902 1428 BNX2FC_HBA_DBG(ctlr->lp, "Unable to alloc blport\n");
d36b3279
BPG
1429 return NULL;
1430 }
1431
853e2bd2 1432 /* Allocate Scsi_Host structure */
0eb43b4b 1433 bnx2fc_shost_template.can_queue = hba->max_outstanding_cmds;
134a4e27
VD
1434 if (!npiv)
1435 lport = libfc_host_alloc(&bnx2fc_shost_template, sizeof(*port));
1436 else
1437 lport = libfc_vport_create(vport, sizeof(*port));
853e2bd2
BG
1438
1439 if (!lport) {
1440 printk(KERN_ERR PFX "could not allocate scsi host structure\n");
d36b3279 1441 goto free_blport;
853e2bd2
BG
1442 }
1443 shost = lport->host;
1444 port = lport_priv(lport);
1445 port->lport = lport;
aea71a02 1446 port->priv = interface;
c3d7909b 1447 port->get_netdev = bnx2fc_netdev;
853e2bd2
BG
1448 INIT_WORK(&port->destroy_work, bnx2fc_destroy_work);
1449
1450 /* Configure fcoe_port */
1451 rc = bnx2fc_lport_config(lport);
1452 if (rc)
1453 goto lp_config_err;
1454
1455 if (npiv) {
853e2bd2
BG
1456 printk(KERN_ERR PFX "Setting vport names, 0x%llX 0x%llX\n",
1457 vport->node_name, vport->port_name);
1458 fc_set_wwnn(lport, vport->node_name);
1459 fc_set_wwpn(lport, vport->port_name);
1460 }
1461 /* Configure netdev and networking properties of the lport */
52439607 1462 rc = bnx2fc_net_config(lport, interface->netdev);
853e2bd2
BG
1463 if (rc) {
1464 printk(KERN_ERR PFX "Error on bnx2fc_net_config\n");
1465 goto lp_config_err;
1466 }
1467
1468 rc = bnx2fc_shost_config(lport, parent);
1469 if (rc) {
1470 printk(KERN_ERR PFX "Couldnt configure shost for %s\n",
aea71a02 1471 interface->netdev->name);
853e2bd2
BG
1472 goto lp_config_err;
1473 }
1474
1475 /* Initialize the libfc library */
1476 rc = bnx2fc_libfc_config(lport);
1477 if (rc) {
1478 printk(KERN_ERR PFX "Couldnt configure libfc\n");
1479 goto shost_err;
1480 }
1481 fc_host_port_type(lport->host) = FC_PORTTYPE_UNKNOWN;
1482
1483 /* Allocate exchange manager */
134a4e27 1484 if (!npiv)
0eb43b4b 1485 rc = bnx2fc_em_config(lport, hba);
134a4e27
VD
1486 else {
1487 shost = vport_to_shost(vport);
1488 n_port = shost_priv(shost);
1489 rc = fc_exch_mgr_list_clone(n_port, lport);
1490 }
1491
1492 if (rc) {
1493 printk(KERN_ERR PFX "Error on bnx2fc_em_config\n");
1494 goto shost_err;
853e2bd2
BG
1495 }
1496
aea71a02 1497 bnx2fc_interface_get(interface);
d36b3279
BPG
1498
1499 spin_lock_bh(&hba->hba_lock);
1500 blport->lport = lport;
1501 list_add_tail(&blport->list, &hba->vports);
1502 spin_unlock_bh(&hba->hba_lock);
1503
853e2bd2
BG
1504 return lport;
1505
1506shost_err:
1507 scsi_remove_host(shost);
1508lp_config_err:
1509 scsi_host_put(lport->host);
d36b3279
BPG
1510free_blport:
1511 kfree(blport);
853e2bd2
BG
1512 return NULL;
1513}
1514
013068fa 1515static void bnx2fc_net_cleanup(struct bnx2fc_interface *interface)
853e2bd2
BG
1516{
1517 /* Dont listen for Ethernet packets anymore */
aea71a02
BPG
1518 __dev_remove_pack(&interface->fcoe_packet_type);
1519 __dev_remove_pack(&interface->fip_packet_type);
853e2bd2
BG
1520 synchronize_net();
1521}
1522
776cebca 1523static void bnx2fc_interface_cleanup(struct bnx2fc_interface *interface)
853e2bd2 1524{
fd8f8902
RL
1525 struct fcoe_ctlr *ctlr = bnx2fc_to_ctlr(interface);
1526 struct fc_lport *lport = ctlr->lp;
853e2bd2 1527 struct fcoe_port *port = lport_priv(lport);
9be17fc4 1528 struct bnx2fc_hba *hba = interface->hba;
853e2bd2 1529
853e2bd2
BG
1530 /* Stop the transmit retry timer */
1531 del_timer_sync(&port->timer);
1532
1533 /* Free existing transmit skbs */
1534 fcoe_clean_pending_queue(lport);
1535
013068fa 1536 bnx2fc_net_cleanup(interface);
9be17fc4 1537
abc49a93 1538 bnx2fc_free_vport(hba, lport);
9be17fc4
BPG
1539}
1540
1541static void bnx2fc_if_destroy(struct fc_lport *lport)
1542{
1543
853e2bd2
BG
1544 /* Free queued packets for the receive thread */
1545 bnx2fc_clean_rx_queue(lport);
1546
1547 /* Detach from scsi-ml */
1548 fc_remove_host(lport->host);
1549 scsi_remove_host(lport->host);
1550
1551 /*
1552 * Note that only the physical lport will have the exchange manager.
1553 * for vports, this function is NOP
1554 */
1555 fc_exch_mgr_free(lport);
1556
1557 /* Free memory used by statistical counters */
1558 fc_lport_free_stats(lport);
1559
1560 /* Release Scsi_Host */
1561 scsi_host_put(lport->host);
1562}
1563
eccdcd02 1564static void __bnx2fc_destroy(struct bnx2fc_interface *interface)
abc49a93 1565{
fd8f8902
RL
1566 struct fcoe_ctlr *ctlr = bnx2fc_to_ctlr(interface);
1567 struct fc_lport *lport = ctlr->lp;
0cbf32e1 1568 struct fcoe_port *port = lport_priv(lport);
abc49a93
BPG
1569
1570 bnx2fc_interface_cleanup(interface);
1571 bnx2fc_stop(interface);
abc49a93 1572 list_del(&interface->list);
abc49a93 1573 bnx2fc_interface_put(interface);
0cbf32e1 1574 queue_work(bnx2fc_wq, &port->destroy_work);
abc49a93
BPG
1575}
1576
853e2bd2
BG
1577/**
1578 * bnx2fc_destroy - Destroy a bnx2fc FCoE interface
1579 *
1580 * @buffer: The name of the Ethernet interface to be destroyed
1581 * @kp: The associated kernel parameter
1582 *
1583 * Called from sysfs.
1584 *
1585 * Returns: 0 for success
1586 */
1587static int bnx2fc_destroy(struct net_device *netdev)
1588{
aea71a02 1589 struct bnx2fc_interface *interface = NULL;
2a7b29c5 1590 struct workqueue_struct *timer_work_queue;
fd8f8902 1591 struct fcoe_ctlr *ctlr;
853e2bd2
BG
1592 int rc = 0;
1593
6702ca1d 1594 rtnl_lock();
853e2bd2 1595 mutex_lock(&bnx2fc_dev_lock);
853e2bd2 1596
aea71a02 1597 interface = bnx2fc_interface_lookup(netdev);
fd8f8902
RL
1598 ctlr = bnx2fc_to_ctlr(interface);
1599 if (!interface || !ctlr->lp) {
853e2bd2 1600 rc = -ENODEV;
aea71a02 1601 printk(KERN_ERR PFX "bnx2fc_destroy: interface or lport not found\n");
853e2bd2
BG
1602 goto netdev_err;
1603 }
1604
2a7b29c5 1605 timer_work_queue = interface->timer_work_queue;
eccdcd02 1606 __bnx2fc_destroy(interface);
2a7b29c5 1607 destroy_workqueue(timer_work_queue);
853e2bd2 1608
853e2bd2
BG
1609netdev_err:
1610 mutex_unlock(&bnx2fc_dev_lock);
1611 rtnl_unlock();
1612 return rc;
1613}
1614
1615static void bnx2fc_destroy_work(struct work_struct *work)
1616{
1617 struct fcoe_port *port;
1618 struct fc_lport *lport;
1619
1620 port = container_of(work, struct fcoe_port, destroy_work);
1621 lport = port->lport;
1622
1623 BNX2FC_HBA_DBG(lport, "Entered bnx2fc_destroy_work\n");
1624
9be17fc4 1625 bnx2fc_if_destroy(lport);
853e2bd2
BG
1626}
1627
1628static void bnx2fc_unbind_adapter_devices(struct bnx2fc_hba *hba)
1629{
1630 bnx2fc_free_fw_resc(hba);
1631 bnx2fc_free_task_ctx(hba);
1632}
1633
1634/**
1635 * bnx2fc_bind_adapter_devices - binds bnx2fc adapter with the associated
1636 * pci structure
1637 *
1638 * @hba: Adapter instance
1639 */
1640static int bnx2fc_bind_adapter_devices(struct bnx2fc_hba *hba)
1641{
1642 if (bnx2fc_setup_task_ctx(hba))
1643 goto mem_err;
1644
1645 if (bnx2fc_setup_fw_resc(hba))
1646 goto mem_err;
1647
1648 return 0;
1649mem_err:
1650 bnx2fc_unbind_adapter_devices(hba);
1651 return -ENOMEM;
1652}
1653
1654static int bnx2fc_bind_pcidev(struct bnx2fc_hba *hba)
1655{
1656 struct cnic_dev *cnic;
c13d2b6d 1657 struct pci_dev *pdev;
853e2bd2
BG
1658
1659 if (!hba->cnic) {
1660 printk(KERN_ERR PFX "cnic is NULL\n");
1661 return -ENODEV;
1662 }
1663 cnic = hba->cnic;
c13d2b6d
BPG
1664 pdev = hba->pcidev = cnic->pcidev;
1665 if (!hba->pcidev)
1666 return -ENODEV;
853e2bd2 1667
c13d2b6d
BPG
1668 switch (pdev->device) {
1669 case PCI_DEVICE_ID_NX2_57710:
1670 strncpy(hba->chip_num, "BCM57710", BCM_CHIP_LEN);
1671 break;
1672 case PCI_DEVICE_ID_NX2_57711:
1673 strncpy(hba->chip_num, "BCM57711", BCM_CHIP_LEN);
1674 break;
1675 case PCI_DEVICE_ID_NX2_57712:
1676 case PCI_DEVICE_ID_NX2_57712_MF:
1677 case PCI_DEVICE_ID_NX2_57712_VF:
1678 strncpy(hba->chip_num, "BCM57712", BCM_CHIP_LEN);
1679 break;
1680 case PCI_DEVICE_ID_NX2_57800:
1681 case PCI_DEVICE_ID_NX2_57800_MF:
1682 case PCI_DEVICE_ID_NX2_57800_VF:
1683 strncpy(hba->chip_num, "BCM57800", BCM_CHIP_LEN);
1684 break;
1685 case PCI_DEVICE_ID_NX2_57810:
1686 case PCI_DEVICE_ID_NX2_57810_MF:
1687 case PCI_DEVICE_ID_NX2_57810_VF:
1688 strncpy(hba->chip_num, "BCM57810", BCM_CHIP_LEN);
1689 break;
1690 case PCI_DEVICE_ID_NX2_57840:
1691 case PCI_DEVICE_ID_NX2_57840_MF:
1692 case PCI_DEVICE_ID_NX2_57840_VF:
1693 case PCI_DEVICE_ID_NX2_57840_2_20:
1694 case PCI_DEVICE_ID_NX2_57840_4_10:
1695 strncpy(hba->chip_num, "BCM57840", BCM_CHIP_LEN);
1696 break;
1697 default:
1698 pr_err(PFX "Unknown device id 0x%x\n", pdev->device);
1699 break;
1700 }
1701 pci_dev_get(hba->pcidev);
853e2bd2
BG
1702 return 0;
1703}
1704
1705static void bnx2fc_unbind_pcidev(struct bnx2fc_hba *hba)
1706{
c13d2b6d
BPG
1707 if (hba->pcidev) {
1708 hba->chip_num[0] = '\0';
853e2bd2 1709 pci_dev_put(hba->pcidev);
c13d2b6d 1710 }
853e2bd2
BG
1711 hba->pcidev = NULL;
1712}
1713
2e499d3c
BW
1714/**
1715 * bnx2fc_ulp_get_stats - cnic callback to populate FCoE stats
1716 *
1717 * @handle: transport handle pointing to adapter struture
1718 */
1719static int bnx2fc_ulp_get_stats(void *handle)
1720{
1721 struct bnx2fc_hba *hba = handle;
1722 struct cnic_dev *cnic;
1723 struct fcoe_stats_info *stats_addr;
1724
1725 if (!hba)
1726 return -EINVAL;
1727
1728 cnic = hba->cnic;
1729 stats_addr = &cnic->stats_addr->fcoe_stat;
1730 if (!stats_addr)
1731 return -EINVAL;
1732
1733 strncpy(stats_addr->version, BNX2FC_VERSION,
1734 sizeof(stats_addr->version));
1735 stats_addr->txq_size = BNX2FC_SQ_WQES_MAX;
1736 stats_addr->rxq_size = BNX2FC_CQ_WQES_MAX;
1737
1738 return 0;
1739}
853e2bd2
BG
1740
1741
1742/**
1743 * bnx2fc_ulp_start - cnic callback to initialize & start adapter instance
1744 *
59e13d48 1745 * @handle: transport handle pointing to adapter structure
853e2bd2
BG
1746 *
1747 * This function maps adapter structure to pcidev structure and initiates
1748 * firmware handshake to enable/initialize on-chip FCoE components.
1749 * This bnx2fc - cnic interface api callback is used after following
1750 * conditions are met -
1751 * a) underlying network interface is up (marked by event NETDEV_UP
1752 * from netdev
1753 * b) bnx2fc adatper structure is registered.
1754 */
1755static void bnx2fc_ulp_start(void *handle)
1756{
1757 struct bnx2fc_hba *hba = handle;
aea71a02 1758 struct bnx2fc_interface *interface;
fd8f8902 1759 struct fcoe_ctlr *ctlr;
aea71a02 1760 struct fc_lport *lport;
853e2bd2 1761
853e2bd2
BG
1762 mutex_lock(&bnx2fc_dev_lock);
1763
aea71a02 1764 if (!test_bit(BNX2FC_FLAG_FW_INIT_DONE, &hba->flags))
853e2bd2
BG
1765 bnx2fc_fw_init(hba);
1766
853e2bd2
BG
1767 BNX2FC_MISC_DBG("bnx2fc started.\n");
1768
aea71a02
BPG
1769 list_for_each_entry(interface, &if_list, list) {
1770 if (interface->hba == hba) {
fd8f8902
RL
1771 ctlr = bnx2fc_to_ctlr(interface);
1772 lport = ctlr->lp;
aea71a02
BPG
1773 /* Kick off Fabric discovery*/
1774 printk(KERN_ERR PFX "ulp_init: start discovery\n");
1775 lport->tt.frame_send = bnx2fc_xmit;
1776 bnx2fc_start_disc(interface);
1777 }
853e2bd2 1778 }
aea71a02
BPG
1779
1780 mutex_unlock(&bnx2fc_dev_lock);
853e2bd2
BG
1781}
1782
1783static void bnx2fc_port_shutdown(struct fc_lport *lport)
1784{
1785 BNX2FC_MISC_DBG("Entered %s\n", __func__);
1786 fc_fabric_logoff(lport);
1787 fc_lport_destroy(lport);
1788}
1789
aea71a02 1790static void bnx2fc_stop(struct bnx2fc_interface *interface)
853e2bd2 1791{
fd8f8902 1792 struct fcoe_ctlr *ctlr = bnx2fc_to_ctlr(interface);
853e2bd2
BG
1793 struct fc_lport *lport;
1794 struct fc_lport *vport;
1795
aea71a02
BPG
1796 if (!test_bit(BNX2FC_FLAG_FW_INIT_DONE, &interface->hba->flags))
1797 return;
853e2bd2 1798
fd8f8902 1799 lport = ctlr->lp;
aea71a02
BPG
1800 bnx2fc_port_shutdown(lport);
1801
1802 mutex_lock(&lport->lp_mutex);
1803 list_for_each_entry(vport, &lport->vports, list)
1804 fc_host_port_type(vport->host) =
1805 FC_PORTTYPE_UNKNOWN;
1806 mutex_unlock(&lport->lp_mutex);
1807 fc_host_port_type(lport->host) = FC_PORTTYPE_UNKNOWN;
fd8f8902 1808 fcoe_ctlr_link_down(ctlr);
aea71a02 1809 fcoe_clean_pending_queue(lport);
853e2bd2
BG
1810}
1811
1812static int bnx2fc_fw_init(struct bnx2fc_hba *hba)
1813{
1814#define BNX2FC_INIT_POLL_TIME (1000 / HZ)
1815 int rc = -1;
1816 int i = HZ;
1817
1818 rc = bnx2fc_bind_adapter_devices(hba);
1819 if (rc) {
1820 printk(KERN_ALERT PFX
1821 "bnx2fc_bind_adapter_devices failed - rc = %d\n", rc);
1822 goto err_out;
1823 }
1824
1825 rc = bnx2fc_send_fw_fcoe_init_msg(hba);
1826 if (rc) {
1827 printk(KERN_ALERT PFX
1828 "bnx2fc_send_fw_fcoe_init_msg failed - rc = %d\n", rc);
1829 goto err_unbind;
1830 }
1831
1832 /*
1833 * Wait until the adapter init message is complete, and adapter
1834 * state is UP.
1835 */
1836 while (!test_bit(ADAPTER_STATE_UP, &hba->adapter_state) && i--)
1837 msleep(BNX2FC_INIT_POLL_TIME);
1838
1839 if (!test_bit(ADAPTER_STATE_UP, &hba->adapter_state)) {
1840 printk(KERN_ERR PFX "bnx2fc_start: %s failed to initialize. "
1841 "Ignoring...\n",
1842 hba->cnic->netdev->name);
1843 rc = -1;
1844 goto err_unbind;
1845 }
1846
1847
aea71a02 1848 set_bit(BNX2FC_FLAG_FW_INIT_DONE, &hba->flags);
853e2bd2
BG
1849 return 0;
1850
1851err_unbind:
1852 bnx2fc_unbind_adapter_devices(hba);
1853err_out:
1854 return rc;
1855}
1856
1857static void bnx2fc_fw_destroy(struct bnx2fc_hba *hba)
1858{
aea71a02 1859 if (test_and_clear_bit(BNX2FC_FLAG_FW_INIT_DONE, &hba->flags)) {
853e2bd2
BG
1860 if (bnx2fc_send_fw_fcoe_destroy_msg(hba) == 0) {
1861 init_timer(&hba->destroy_timer);
1862 hba->destroy_timer.expires = BNX2FC_FW_TIMEOUT +
1863 jiffies;
1864 hba->destroy_timer.function = bnx2fc_destroy_timer;
1865 hba->destroy_timer.data = (unsigned long)hba;
1866 add_timer(&hba->destroy_timer);
1867 wait_event_interruptible(hba->destroy_wait,
aea71a02
BPG
1868 test_bit(BNX2FC_FLAG_DESTROY_CMPL,
1869 &hba->flags));
cd703ae7 1870 clear_bit(BNX2FC_FLAG_DESTROY_CMPL, &hba->flags);
853e2bd2
BG
1871 /* This should never happen */
1872 if (signal_pending(current))
1873 flush_signals(current);
1874
1875 del_timer_sync(&hba->destroy_timer);
1876 }
1877 bnx2fc_unbind_adapter_devices(hba);
1878 }
1879}
1880
1881/**
1882 * bnx2fc_ulp_stop - cnic callback to shutdown adapter instance
1883 *
1884 * @handle: transport handle pointing to adapter structure
1885 *
1886 * Driver checks if adapter is already in shutdown mode, if not start
1887 * the shutdown process.
1888 */
1889static void bnx2fc_ulp_stop(void *handle)
1890{
aea71a02
BPG
1891 struct bnx2fc_hba *hba = handle;
1892 struct bnx2fc_interface *interface;
853e2bd2
BG
1893
1894 printk(KERN_ERR "ULP_STOP\n");
1895
1896 mutex_lock(&bnx2fc_dev_lock);
aea71a02
BPG
1897 if (!test_bit(BNX2FC_FLAG_FW_INIT_DONE, &hba->flags))
1898 goto exit;
1899 list_for_each_entry(interface, &if_list, list) {
1900 if (interface->hba == hba)
1901 bnx2fc_stop(interface);
1902 }
1903 BUG_ON(hba->num_ofld_sess != 0);
1904
1905 mutex_lock(&hba->hba_mutex);
1906 clear_bit(ADAPTER_STATE_UP, &hba->adapter_state);
1907 clear_bit(ADAPTER_STATE_GOING_DOWN,
1908 &hba->adapter_state);
1909
1910 clear_bit(ADAPTER_STATE_READY, &hba->adapter_state);
1911 mutex_unlock(&hba->hba_mutex);
1912
853e2bd2 1913 bnx2fc_fw_destroy(hba);
aea71a02 1914exit:
853e2bd2
BG
1915 mutex_unlock(&bnx2fc_dev_lock);
1916}
1917
aea71a02 1918static void bnx2fc_start_disc(struct bnx2fc_interface *interface)
853e2bd2 1919{
fd8f8902 1920 struct fcoe_ctlr *ctlr = bnx2fc_to_ctlr(interface);
853e2bd2
BG
1921 struct fc_lport *lport;
1922 int wait_cnt = 0;
1923
1924 BNX2FC_MISC_DBG("Entered %s\n", __func__);
1925 /* Kick off FIP/FLOGI */
aea71a02 1926 if (!test_bit(BNX2FC_FLAG_FW_INIT_DONE, &interface->hba->flags)) {
853e2bd2
BG
1927 printk(KERN_ERR PFX "Init not done yet\n");
1928 return;
1929 }
1930
fd8f8902 1931 lport = ctlr->lp;
853e2bd2
BG
1932 BNX2FC_HBA_DBG(lport, "calling fc_fabric_login\n");
1933
8a5badf1 1934 if (!bnx2fc_link_ok(lport) && interface->enabled) {
853e2bd2 1935 BNX2FC_HBA_DBG(lport, "ctlr_link_up\n");
fd8f8902 1936 fcoe_ctlr_link_up(ctlr);
853e2bd2 1937 fc_host_port_type(lport->host) = FC_PORTTYPE_NPORT;
aea71a02 1938 set_bit(ADAPTER_STATE_READY, &interface->hba->adapter_state);
853e2bd2
BG
1939 }
1940
1941 /* wait for the FCF to be selected before issuing FLOGI */
fd8f8902 1942 while (!ctlr->sel_fcf) {
853e2bd2
BG
1943 msleep(250);
1944 /* give up after 3 secs */
1945 if (++wait_cnt > 12)
1946 break;
1947 }
627e628f
BPG
1948
1949 /* Reset max receive frame size to default */
1950 if (fc_set_mfs(lport, BNX2FC_MFS))
1951 return;
1952
853e2bd2
BG
1953 fc_lport_init(lport);
1954 fc_fabric_login(lport);
1955}
1956
1957
1958/**
1959 * bnx2fc_ulp_init - Initialize an adapter instance
1960 *
1961 * @dev : cnic device handle
1962 * Called from cnic_register_driver() context to initialize all
1963 * enumerated cnic devices. This routine allocates adapter structure
1964 * and other device specific resources.
1965 */
1966static void bnx2fc_ulp_init(struct cnic_dev *dev)
1967{
1968 struct bnx2fc_hba *hba;
1969 int rc = 0;
1970
1971 BNX2FC_MISC_DBG("Entered %s\n", __func__);
1972 /* bnx2fc works only when bnx2x is loaded */
aea71a02
BPG
1973 if (!test_bit(CNIC_F_BNX2X_CLASS, &dev->flags) ||
1974 (dev->max_fcoe_conn == 0)) {
853e2bd2 1975 printk(KERN_ERR PFX "bnx2fc FCoE not supported on %s,"
aea71a02
BPG
1976 " flags: %lx fcoe_conn: %d\n",
1977 dev->netdev->name, dev->flags, dev->max_fcoe_conn);
853e2bd2
BG
1978 return;
1979 }
1980
aea71a02 1981 hba = bnx2fc_hba_create(dev);
853e2bd2
BG
1982 if (!hba) {
1983 printk(KERN_ERR PFX "hba initialization failed\n");
1984 return;
1985 }
1986
1987 /* Add HBA to the adapter list */
1988 mutex_lock(&bnx2fc_dev_lock);
aea71a02 1989 list_add_tail(&hba->list, &adapter_list);
853e2bd2
BG
1990 adapter_count++;
1991 mutex_unlock(&bnx2fc_dev_lock);
1992
2e499d3c 1993 dev->fcoe_cap = &hba->fcoe_cap;
853e2bd2
BG
1994 clear_bit(BNX2FC_CNIC_REGISTERED, &hba->reg_with_cnic);
1995 rc = dev->register_device(dev, CNIC_ULP_FCOE,
1996 (void *) hba);
1997 if (rc)
b2a554ff 1998 printk(KERN_ERR PFX "register_device failed, rc = %d\n", rc);
853e2bd2
BG
1999 else
2000 set_bit(BNX2FC_CNIC_REGISTERED, &hba->reg_with_cnic);
2001}
2002
0680810c
EW
2003/* Assumes rtnl_lock and the bnx2fc_dev_lock are already taken */
2004static int __bnx2fc_disable(struct fcoe_ctlr *ctlr)
2005{
2006 struct bnx2fc_interface *interface = fcoe_ctlr_priv(ctlr);
2007
2008 if (interface->enabled == true) {
2009 if (!ctlr->lp) {
2010 pr_err(PFX "__bnx2fc_disable: lport not found\n");
2011 return -ENODEV;
2012 } else {
2013 interface->enabled = false;
2014 fcoe_ctlr_link_down(ctlr);
2015 fcoe_clean_pending_queue(ctlr->lp);
2016 }
2017 }
2018 return 0;
2019}
2020
6e89ea3f
RL
2021/**
2022 * Deperecated: Use bnx2fc_enabled()
2023 */
853e2bd2
BG
2024static int bnx2fc_disable(struct net_device *netdev)
2025{
aea71a02 2026 struct bnx2fc_interface *interface;
fd8f8902 2027 struct fcoe_ctlr *ctlr;
853e2bd2
BG
2028 int rc = 0;
2029
6702ca1d 2030 rtnl_lock();
853e2bd2
BG
2031 mutex_lock(&bnx2fc_dev_lock);
2032
aea71a02 2033 interface = bnx2fc_interface_lookup(netdev);
fd8f8902 2034 ctlr = bnx2fc_to_ctlr(interface);
0680810c
EW
2035
2036 if (!interface) {
853e2bd2 2037 rc = -ENODEV;
0680810c 2038 pr_err(PFX "bnx2fc_disable: interface not found\n");
853e2bd2 2039 } else {
0680810c 2040 rc = __bnx2fc_disable(ctlr);
853e2bd2 2041 }
853e2bd2
BG
2042 mutex_unlock(&bnx2fc_dev_lock);
2043 rtnl_unlock();
2044 return rc;
2045}
2046
0680810c
EW
2047static int __bnx2fc_enable(struct fcoe_ctlr *ctlr)
2048{
2049 struct bnx2fc_interface *interface = fcoe_ctlr_priv(ctlr);
2050
2051 if (interface->enabled == false) {
2052 if (!ctlr->lp) {
2053 pr_err(PFX "__bnx2fc_enable: lport not found\n");
2054 return -ENODEV;
2055 } else if (!bnx2fc_link_ok(ctlr->lp)) {
2056 fcoe_ctlr_link_up(ctlr);
2057 interface->enabled = true;
2058 }
2059 }
2060 return 0;
2061}
2062
6e89ea3f
RL
2063/**
2064 * Deprecated: Use bnx2fc_enabled()
2065 */
853e2bd2
BG
2066static int bnx2fc_enable(struct net_device *netdev)
2067{
aea71a02 2068 struct bnx2fc_interface *interface;
fd8f8902 2069 struct fcoe_ctlr *ctlr;
853e2bd2
BG
2070 int rc = 0;
2071
6702ca1d 2072 rtnl_lock();
853e2bd2
BG
2073 mutex_lock(&bnx2fc_dev_lock);
2074
aea71a02 2075 interface = bnx2fc_interface_lookup(netdev);
fd8f8902 2076 ctlr = bnx2fc_to_ctlr(interface);
0680810c 2077 if (!interface) {
853e2bd2 2078 rc = -ENODEV;
0680810c
EW
2079 pr_err(PFX "bnx2fc_enable: interface not found\n");
2080 } else {
2081 rc = __bnx2fc_enable(ctlr);
8a5badf1 2082 }
853e2bd2 2083
853e2bd2
BG
2084 mutex_unlock(&bnx2fc_dev_lock);
2085 rtnl_unlock();
2086 return rc;
2087}
2088
2089/**
6e89ea3f
RL
2090 * bnx2fc_ctlr_enabled() - Enable or disable an FCoE Controller
2091 * @cdev: The FCoE Controller that is being enabled or disabled
853e2bd2 2092 *
6e89ea3f
RL
2093 * fcoe_sysfs will ensure that the state of 'enabled' has
2094 * changed, so no checking is necessary here. This routine simply
2095 * calls fcoe_enable or fcoe_disable, both of which are deprecated.
2096 * When those routines are removed the functionality can be merged
2097 * here.
2098 */
2099static int bnx2fc_ctlr_enabled(struct fcoe_ctlr_device *cdev)
2100{
2101 struct fcoe_ctlr *ctlr = fcoe_ctlr_device_priv(cdev);
6e89ea3f
RL
2102
2103 switch (cdev->enabled) {
2104 case FCOE_CTLR_ENABLED:
0680810c 2105 return __bnx2fc_enable(ctlr);
6e89ea3f 2106 case FCOE_CTLR_DISABLED:
0680810c 2107 return __bnx2fc_disable(ctlr);
6e89ea3f
RL
2108 case FCOE_CTLR_UNUSED:
2109 default:
2110 return -ENOTSUPP;
2111 };
2112}
2113
2114enum bnx2fc_create_link_state {
2115 BNX2FC_CREATE_LINK_DOWN,
2116 BNX2FC_CREATE_LINK_UP,
2117};
2118
2119/**
2120 * _bnx2fc_create() - Create bnx2fc FCoE interface
2121 * @netdev : The net_device object the Ethernet interface to create on
2122 * @fip_mode: The FIP mode for this creation
2123 * @link_state: The ctlr link state on creation
853e2bd2 2124 *
6e89ea3f
RL
2125 * Called from either the libfcoe 'create' module parameter
2126 * via fcoe_create or from fcoe_syfs's ctlr_create file.
853e2bd2 2127 *
6e89ea3f
RL
2128 * libfcoe's 'create' module parameter is deprecated so some
2129 * consolidation of code can be done when that interface is
2130 * removed.
853e2bd2
BG
2131 *
2132 * Returns: 0 for success
2133 */
6e89ea3f
RL
2134static int _bnx2fc_create(struct net_device *netdev,
2135 enum fip_state fip_mode,
2136 enum bnx2fc_create_link_state link_state)
853e2bd2 2137{
6e89ea3f 2138 struct fcoe_ctlr_device *cdev;
fd8f8902 2139 struct fcoe_ctlr *ctlr;
aea71a02 2140 struct bnx2fc_interface *interface;
853e2bd2 2141 struct bnx2fc_hba *hba;
7adc5a37 2142 struct net_device *phys_dev = netdev;
853e2bd2
BG
2143 struct fc_lport *lport;
2144 struct ethtool_drvinfo drvinfo;
2145 int rc = 0;
7adc5a37 2146 int vlan_id = 0;
853e2bd2
BG
2147
2148 BNX2FC_MISC_DBG("Entered bnx2fc_create\n");
2149 if (fip_mode != FIP_MODE_FABRIC) {
2150 printk(KERN_ERR "fip mode not FABRIC\n");
2151 return -EIO;
2152 }
2153
6702ca1d
NS
2154 rtnl_lock();
2155
853e2bd2
BG
2156 mutex_lock(&bnx2fc_dev_lock);
2157
853e2bd2
BG
2158 if (!try_module_get(THIS_MODULE)) {
2159 rc = -EINVAL;
2160 goto mod_err;
2161 }
2162
2163 /* obtain physical netdev */
7adc5a37 2164 if (netdev->priv_flags & IFF_802_1Q_VLAN)
853e2bd2 2165 phys_dev = vlan_dev_real_dev(netdev);
7adc5a37 2166
853e2bd2
BG
2167 /* verify if the physical device is a netxtreme2 device */
2168 if (phys_dev->ethtool_ops && phys_dev->ethtool_ops->get_drvinfo) {
2169 memset(&drvinfo, 0, sizeof(drvinfo));
2170 phys_dev->ethtool_ops->get_drvinfo(phys_dev, &drvinfo);
aea71a02 2171 if (strncmp(drvinfo.driver, "bnx2x", strlen("bnx2x"))) {
853e2bd2
BG
2172 printk(KERN_ERR PFX "Not a netxtreme2 device\n");
2173 rc = -EINVAL;
2174 goto netdev_err;
2175 }
2176 } else {
2177 printk(KERN_ERR PFX "unable to obtain drv_info\n");
2178 rc = -EINVAL;
2179 goto netdev_err;
2180 }
2181
aea71a02 2182 /* obtain interface and initialize rest of the structure */
853e2bd2
BG
2183 hba = bnx2fc_hba_lookup(phys_dev);
2184 if (!hba) {
2185 rc = -ENODEV;
2186 printk(KERN_ERR PFX "bnx2fc_create: hba not found\n");
2187 goto netdev_err;
2188 }
2189
aea71a02 2190 if (bnx2fc_interface_lookup(netdev)) {
853e2bd2
BG
2191 rc = -EEXIST;
2192 goto netdev_err;
2193 }
2194
aea71a02
BPG
2195 interface = bnx2fc_interface_create(hba, netdev, fip_mode);
2196 if (!interface) {
2197 printk(KERN_ERR PFX "bnx2fc_interface_create failed\n");
2043e1fd 2198 rc = -ENOMEM;
853e2bd2
BG
2199 goto ifput_err;
2200 }
2201
7adc5a37
BPG
2202 if (netdev->priv_flags & IFF_802_1Q_VLAN) {
2203 vlan_id = vlan_dev_vlan_id(netdev);
2204 interface->vlan_enabled = 1;
2205 }
2206
fd8f8902 2207 ctlr = bnx2fc_to_ctlr(interface);
01bdcb62 2208 cdev = fcoe_ctlr_to_ctlr_dev(ctlr);
aea71a02 2209 interface->vlan_id = vlan_id;
aea71a02
BPG
2210
2211 interface->timer_work_queue =
853e2bd2 2212 create_singlethread_workqueue("bnx2fc_timer_wq");
aea71a02 2213 if (!interface->timer_work_queue) {
853e2bd2
BG
2214 printk(KERN_ERR PFX "ulp_init could not create timer_wq\n");
2215 rc = -EINVAL;
2216 goto ifput_err;
2217 }
2218
01bdcb62 2219 lport = bnx2fc_if_create(interface, &cdev->dev, 0);
853e2bd2
BG
2220 if (!lport) {
2221 printk(KERN_ERR PFX "Failed to create interface (%s)\n",
2222 netdev->name);
853e2bd2
BG
2223 rc = -EINVAL;
2224 goto if_create_err;
2225 }
2226
aea71a02
BPG
2227 /* Add interface to if_list */
2228 list_add_tail(&interface->list, &if_list);
2229
853e2bd2
BG
2230 lport->boot_time = jiffies;
2231
2232 /* Make this master N_port */
fd8f8902 2233 ctlr->lp = lport;
853e2bd2 2234
6e89ea3f
RL
2235 if (link_state == BNX2FC_CREATE_LINK_UP)
2236 cdev->enabled = FCOE_CTLR_ENABLED;
2237 else
2238 cdev->enabled = FCOE_CTLR_DISABLED;
2239
2240 if (link_state == BNX2FC_CREATE_LINK_UP &&
2241 !bnx2fc_link_ok(lport)) {
fd8f8902 2242 fcoe_ctlr_link_up(ctlr);
8a5badf1
BPG
2243 fc_host_port_type(lport->host) = FC_PORTTYPE_NPORT;
2244 set_bit(ADAPTER_STATE_READY, &interface->hba->adapter_state);
2245 }
2246
aea71a02
BPG
2247 BNX2FC_HBA_DBG(lport, "create: START DISC\n");
2248 bnx2fc_start_disc(interface);
6e89ea3f
RL
2249
2250 if (link_state == BNX2FC_CREATE_LINK_UP)
2251 interface->enabled = true;
2252
853e2bd2
BG
2253 /*
2254 * Release from kref_init in bnx2fc_interface_setup, on success
2255 * lport should be holding a reference taken in bnx2fc_if_create
2256 */
aea71a02 2257 bnx2fc_interface_put(interface);
853e2bd2
BG
2258 /* put netdev that was held while calling dev_get_by_name */
2259 mutex_unlock(&bnx2fc_dev_lock);
2260 rtnl_unlock();
2261 return 0;
2262
2263if_create_err:
aea71a02 2264 destroy_workqueue(interface->timer_work_queue);
853e2bd2 2265ifput_err:
013068fa 2266 bnx2fc_net_cleanup(interface);
aea71a02 2267 bnx2fc_interface_put(interface);
7d742f65 2268 goto mod_err;
853e2bd2
BG
2269netdev_err:
2270 module_put(THIS_MODULE);
2271mod_err:
2272 mutex_unlock(&bnx2fc_dev_lock);
2273 rtnl_unlock();
2274 return rc;
2275}
2276
6e89ea3f
RL
2277/**
2278 * bnx2fc_create() - Create a bnx2fc interface
2279 * @netdev : The net_device object the Ethernet interface to create on
2280 * @fip_mode: The FIP mode for this creation
2281 *
2282 * Called from fcoe transport
2283 *
2284 * Returns: 0 for success
2285 */
2286static int bnx2fc_create(struct net_device *netdev, enum fip_state fip_mode)
2287{
2288 return _bnx2fc_create(netdev, fip_mode, BNX2FC_CREATE_LINK_UP);
2289}
2290
2291/**
2292 * bnx2fc_ctlr_alloc() - Allocate a bnx2fc interface from fcoe_sysfs
2293 * @netdev: The net_device to be used by the allocated FCoE Controller
2294 *
2295 * This routine is called from fcoe_sysfs. It will start the fcoe_ctlr
2296 * in a link_down state. The allows the user an opportunity to configure
2297 * the FCoE Controller from sysfs before enabling the FCoE Controller.
2298 *
2299 * Creating in with this routine starts the FCoE Controller in Fabric
2300 * mode. The user can change to VN2VN or another mode before enabling.
2301 */
2302static int bnx2fc_ctlr_alloc(struct net_device *netdev)
2303{
2304 return _bnx2fc_create(netdev, FIP_MODE_FABRIC,
2305 BNX2FC_CREATE_LINK_DOWN);
2306}
2307
853e2bd2 2308/**
aea71a02 2309 * bnx2fc_find_hba_for_cnic - maps cnic instance to bnx2fc hba instance
853e2bd2
BG
2310 *
2311 * @cnic: Pointer to cnic device instance
2312 *
2313 **/
2314static struct bnx2fc_hba *bnx2fc_find_hba_for_cnic(struct cnic_dev *cnic)
2315{
853e2bd2
BG
2316 struct bnx2fc_hba *hba;
2317
2318 /* Called with bnx2fc_dev_lock held */
d71fb3bd 2319 list_for_each_entry(hba, &adapter_list, list) {
853e2bd2
BG
2320 if (hba->cnic == cnic)
2321 return hba;
2322 }
2323 return NULL;
2324}
2325
aea71a02
BPG
2326static struct bnx2fc_interface *bnx2fc_interface_lookup(struct net_device
2327 *netdev)
2328{
2329 struct bnx2fc_interface *interface;
2330
2331 /* Called with bnx2fc_dev_lock held */
2332 list_for_each_entry(interface, &if_list, list) {
2333 if (interface->netdev == netdev)
2334 return interface;
2335 }
2336 return NULL;
2337}
2338
2339static struct bnx2fc_hba *bnx2fc_hba_lookup(struct net_device
2340 *phys_dev)
853e2bd2 2341{
853e2bd2
BG
2342 struct bnx2fc_hba *hba;
2343
2344 /* Called with bnx2fc_dev_lock held */
aea71a02 2345 list_for_each_entry(hba, &adapter_list, list) {
853e2bd2
BG
2346 if (hba->phys_dev == phys_dev)
2347 return hba;
2348 }
aea71a02 2349 printk(KERN_ERR PFX "adapter_lookup: hba NULL\n");
853e2bd2
BG
2350 return NULL;
2351}
2352
2353/**
2354 * bnx2fc_ulp_exit - shuts down adapter instance and frees all resources
2355 *
2356 * @dev cnic device handle
2357 */
2358static void bnx2fc_ulp_exit(struct cnic_dev *dev)
2359{
2360 struct bnx2fc_hba *hba;
aea71a02 2361 struct bnx2fc_interface *interface, *tmp;
853e2bd2
BG
2362
2363 BNX2FC_MISC_DBG("Entered bnx2fc_ulp_exit\n");
2364
2365 if (!test_bit(CNIC_F_BNX2X_CLASS, &dev->flags)) {
2366 printk(KERN_ERR PFX "bnx2fc port check: %s, flags: %lx\n",
2367 dev->netdev->name, dev->flags);
2368 return;
2369 }
2370
2371 mutex_lock(&bnx2fc_dev_lock);
2372 hba = bnx2fc_find_hba_for_cnic(dev);
2373 if (!hba) {
2374 printk(KERN_ERR PFX "bnx2fc_ulp_exit: hba not found, dev 0%p\n",
2375 dev);
2376 mutex_unlock(&bnx2fc_dev_lock);
2377 return;
2378 }
2379
aea71a02 2380 list_del_init(&hba->list);
853e2bd2
BG
2381 adapter_count--;
2382
abc49a93 2383 list_for_each_entry_safe(interface, tmp, &if_list, list)
853e2bd2 2384 /* destroy not called yet, move to quiesced list */
abc49a93 2385 if (interface->hba == hba)
eccdcd02 2386 __bnx2fc_destroy(interface);
853e2bd2
BG
2387 mutex_unlock(&bnx2fc_dev_lock);
2388
06c4f20d
EW
2389 /* Ensure ALL destroy work has been completed before return */
2390 flush_workqueue(bnx2fc_wq);
2391
853e2bd2
BG
2392 bnx2fc_ulp_stop(hba);
2393 /* unregister cnic device */
2394 if (test_and_clear_bit(BNX2FC_CNIC_REGISTERED, &hba->reg_with_cnic))
2395 hba->cnic->unregister_device(hba->cnic, CNIC_ULP_FCOE);
aea71a02 2396 bnx2fc_hba_destroy(hba);
853e2bd2
BG
2397}
2398
2399/**
2400 * bnx2fc_fcoe_reset - Resets the fcoe
2401 *
2402 * @shost: shost the reset is from
2403 *
2404 * Returns: always 0
2405 */
2406static int bnx2fc_fcoe_reset(struct Scsi_Host *shost)
2407{
2408 struct fc_lport *lport = shost_priv(shost);
2409 fc_lport_reset(lport);
2410 return 0;
2411}
2412
2413
2414static bool bnx2fc_match(struct net_device *netdev)
2415{
7adc5a37
BPG
2416 struct net_device *phys_dev = netdev;
2417
853e2bd2 2418 mutex_lock(&bnx2fc_dev_lock);
7adc5a37
BPG
2419 if (netdev->priv_flags & IFF_802_1Q_VLAN)
2420 phys_dev = vlan_dev_real_dev(netdev);
853e2bd2 2421
7adc5a37
BPG
2422 if (bnx2fc_hba_lookup(phys_dev)) {
2423 mutex_unlock(&bnx2fc_dev_lock);
2424 return true;
853e2bd2 2425 }
7adc5a37 2426
853e2bd2
BG
2427 mutex_unlock(&bnx2fc_dev_lock);
2428 return false;
2429}
2430
2431
2432static struct fcoe_transport bnx2fc_transport = {
2433 .name = {"bnx2fc"},
2434 .attached = false,
2435 .list = LIST_HEAD_INIT(bnx2fc_transport.list),
6e89ea3f 2436 .alloc = bnx2fc_ctlr_alloc,
853e2bd2
BG
2437 .match = bnx2fc_match,
2438 .create = bnx2fc_create,
2439 .destroy = bnx2fc_destroy,
2440 .enable = bnx2fc_enable,
2441 .disable = bnx2fc_disable,
2442};
2443
2444/**
2445 * bnx2fc_percpu_thread_create - Create a receive thread for an
2446 * online CPU
2447 *
2448 * @cpu: cpu index for the online cpu
2449 */
2450static void bnx2fc_percpu_thread_create(unsigned int cpu)
2451{
2452 struct bnx2fc_percpu_s *p;
2453 struct task_struct *thread;
2454
2455 p = &per_cpu(bnx2fc_percpu, cpu);
2456
69614270
ED
2457 thread = kthread_create_on_node(bnx2fc_percpu_io_thread,
2458 (void *)p, cpu_to_node(cpu),
2459 "bnx2fc_thread/%d", cpu);
853e2bd2 2460 /* bind thread to the cpu */
32248763 2461 if (likely(!IS_ERR(thread))) {
853e2bd2
BG
2462 kthread_bind(thread, cpu);
2463 p->iothread = thread;
2464 wake_up_process(thread);
2465 }
2466}
2467
2468static void bnx2fc_percpu_thread_destroy(unsigned int cpu)
2469{
2470 struct bnx2fc_percpu_s *p;
2471 struct task_struct *thread;
2472 struct bnx2fc_work *work, *tmp;
853e2bd2
BG
2473
2474 BNX2FC_MISC_DBG("destroying io thread for CPU %d\n", cpu);
2475
2476 /* Prevent any new work from being queued for this CPU */
2477 p = &per_cpu(bnx2fc_percpu, cpu);
2478 spin_lock_bh(&p->fp_work_lock);
2479 thread = p->iothread;
2480 p->iothread = NULL;
2481
2482
2483 /* Free all work in the list */
32248763 2484 list_for_each_entry_safe(work, tmp, &p->work_list, list) {
853e2bd2
BG
2485 list_del_init(&work->list);
2486 bnx2fc_process_cq_compl(work->tgt, work->wqe);
2487 kfree(work);
2488 }
2489
2490 spin_unlock_bh(&p->fp_work_lock);
2491
2492 if (thread)
2493 kthread_stop(thread);
2494}
2495
2496/**
2497 * bnx2fc_cpu_callback - Handler for CPU hotplug events
2498 *
2499 * @nfb: The callback data block
2500 * @action: The event triggering the callback
2501 * @hcpu: The index of the CPU that the event is for
2502 *
2503 * This creates or destroys per-CPU data for fcoe
2504 *
2505 * Returns NOTIFY_OK always.
2506 */
2507static int bnx2fc_cpu_callback(struct notifier_block *nfb,
2508 unsigned long action, void *hcpu)
2509{
2510 unsigned cpu = (unsigned long)hcpu;
2511
2512 switch (action) {
2513 case CPU_ONLINE:
2514 case CPU_ONLINE_FROZEN:
2515 printk(PFX "CPU %x online: Create Rx thread\n", cpu);
2516 bnx2fc_percpu_thread_create(cpu);
2517 break;
2518 case CPU_DEAD:
2519 case CPU_DEAD_FROZEN:
2520 printk(PFX "CPU %x offline: Remove Rx thread\n", cpu);
2521 bnx2fc_percpu_thread_destroy(cpu);
2522 break;
2523 default:
2524 break;
2525 }
2526 return NOTIFY_OK;
2527}
2528
2529/**
2530 * bnx2fc_mod_init - module init entry point
2531 *
2532 * Initialize driver wide global data structures, and register
2533 * with cnic module
2534 **/
2535static int __init bnx2fc_mod_init(void)
2536{
2537 struct fcoe_percpu_s *bg;
2538 struct task_struct *l2_thread;
2539 int rc = 0;
2540 unsigned int cpu = 0;
2541 struct bnx2fc_percpu_s *p;
2542
2543 printk(KERN_INFO PFX "%s", version);
2544
2545 /* register as a fcoe transport */
2546 rc = fcoe_transport_attach(&bnx2fc_transport);
2547 if (rc) {
2548 printk(KERN_ERR "failed to register an fcoe transport, check "
2549 "if libfcoe is loaded\n");
2550 goto out;
2551 }
2552
2553 INIT_LIST_HEAD(&adapter_list);
aea71a02 2554 INIT_LIST_HEAD(&if_list);
853e2bd2
BG
2555 mutex_init(&bnx2fc_dev_lock);
2556 adapter_count = 0;
2557
2558 /* Attach FC transport template */
2559 rc = bnx2fc_attach_transport();
2560 if (rc)
2561 goto detach_ft;
2562
2563 bnx2fc_wq = alloc_workqueue("bnx2fc", 0, 0);
2564 if (!bnx2fc_wq) {
2565 rc = -ENOMEM;
2566 goto release_bt;
2567 }
2568
2569 bg = &bnx2fc_global;
2570 skb_queue_head_init(&bg->fcoe_rx_list);
2571 l2_thread = kthread_create(bnx2fc_l2_rcv_thread,
2572 (void *)bg,
2573 "bnx2fc_l2_thread");
2574 if (IS_ERR(l2_thread)) {
2575 rc = PTR_ERR(l2_thread);
2576 goto free_wq;
2577 }
2578 wake_up_process(l2_thread);
2579 spin_lock_bh(&bg->fcoe_rx_list.lock);
2580 bg->thread = l2_thread;
2581 spin_unlock_bh(&bg->fcoe_rx_list.lock);
2582
2583 for_each_possible_cpu(cpu) {
2584 p = &per_cpu(bnx2fc_percpu, cpu);
2585 INIT_LIST_HEAD(&p->work_list);
2586 spin_lock_init(&p->fp_work_lock);
2587 }
2588
7229b6d0
SB
2589 cpu_notifier_register_begin();
2590
853e2bd2
BG
2591 for_each_online_cpu(cpu) {
2592 bnx2fc_percpu_thread_create(cpu);
2593 }
2594
2595 /* Initialize per CPU interrupt thread */
7229b6d0
SB
2596 __register_hotcpu_notifier(&bnx2fc_cpu_notifier);
2597
2598 cpu_notifier_register_done();
853e2bd2
BG
2599
2600 cnic_register_driver(CNIC_ULP_FCOE, &bnx2fc_cnic_cb);
2601
2602 return 0;
2603
2604free_wq:
2605 destroy_workqueue(bnx2fc_wq);
2606release_bt:
2607 bnx2fc_release_transport();
2608detach_ft:
2609 fcoe_transport_detach(&bnx2fc_transport);
2610out:
2611 return rc;
2612}
2613
2614static void __exit bnx2fc_mod_exit(void)
2615{
2616 LIST_HEAD(to_be_deleted);
2617 struct bnx2fc_hba *hba, *next;
2618 struct fcoe_percpu_s *bg;
2619 struct task_struct *l2_thread;
2620 struct sk_buff *skb;
2621 unsigned int cpu = 0;
2622
2623 /*
2624 * NOTE: Since cnic calls register_driver routine rtnl_lock,
2625 * it will have higher precedence than bnx2fc_dev_lock.
2626 * unregister_device() cannot be called with bnx2fc_dev_lock
2627 * held.
2628 */
2629 mutex_lock(&bnx2fc_dev_lock);
2630 list_splice(&adapter_list, &to_be_deleted);
2631 INIT_LIST_HEAD(&adapter_list);
2632 adapter_count = 0;
2633 mutex_unlock(&bnx2fc_dev_lock);
2634
2635 /* Unregister with cnic */
aea71a02
BPG
2636 list_for_each_entry_safe(hba, next, &to_be_deleted, list) {
2637 list_del_init(&hba->list);
2638 printk(KERN_ERR PFX "MOD_EXIT:destroy hba = 0x%p\n",
2639 hba);
853e2bd2
BG
2640 bnx2fc_ulp_stop(hba);
2641 /* unregister cnic device */
2642 if (test_and_clear_bit(BNX2FC_CNIC_REGISTERED,
2643 &hba->reg_with_cnic))
aea71a02
BPG
2644 hba->cnic->unregister_device(hba->cnic,
2645 CNIC_ULP_FCOE);
2646 bnx2fc_hba_destroy(hba);
853e2bd2
BG
2647 }
2648 cnic_unregister_driver(CNIC_ULP_FCOE);
2649
2650 /* Destroy global thread */
2651 bg = &bnx2fc_global;
2652 spin_lock_bh(&bg->fcoe_rx_list.lock);
2653 l2_thread = bg->thread;
2654 bg->thread = NULL;
2655 while ((skb = __skb_dequeue(&bg->fcoe_rx_list)) != NULL)
2656 kfree_skb(skb);
2657
2658 spin_unlock_bh(&bg->fcoe_rx_list.lock);
2659
2660 if (l2_thread)
2661 kthread_stop(l2_thread);
2662
7229b6d0 2663 cpu_notifier_register_begin();
853e2bd2
BG
2664
2665 /* Destroy per cpu threads */
2666 for_each_online_cpu(cpu) {
2667 bnx2fc_percpu_thread_destroy(cpu);
2668 }
2669
7229b6d0
SB
2670 __unregister_hotcpu_notifier(&bnx2fc_cpu_notifier);
2671
2672 cpu_notifier_register_done();
2673
853e2bd2
BG
2674 destroy_workqueue(bnx2fc_wq);
2675 /*
2676 * detach from scsi transport
2677 * must happen after all destroys are done
2678 */
2679 bnx2fc_release_transport();
2680
2681 /* detach from fcoe transport */
2682 fcoe_transport_detach(&bnx2fc_transport);
2683}
2684
2685module_init(bnx2fc_mod_init);
2686module_exit(bnx2fc_mod_exit);
2687
8d55e507 2688static struct fcoe_sysfs_function_template bnx2fc_fcoe_sysfs_templ = {
6e89ea3f 2689 .set_fcoe_ctlr_enabled = bnx2fc_ctlr_enabled,
b8b3e697
YZ
2690 .get_fcoe_ctlr_link_fail = fcoe_ctlr_get_lesb,
2691 .get_fcoe_ctlr_vlink_fail = fcoe_ctlr_get_lesb,
2692 .get_fcoe_ctlr_miss_fka = fcoe_ctlr_get_lesb,
2693 .get_fcoe_ctlr_symb_err = fcoe_ctlr_get_lesb,
2694 .get_fcoe_ctlr_err_block = fcoe_ctlr_get_lesb,
2695 .get_fcoe_ctlr_fcs_error = fcoe_ctlr_get_lesb,
8d55e507
RL
2696
2697 .get_fcoe_fcf_selected = fcoe_fcf_get_selected,
2698 .get_fcoe_fcf_vlan_id = bnx2fc_fcf_get_vlan_id,
2699};
2700
853e2bd2
BG
2701static struct fc_function_template bnx2fc_transport_function = {
2702 .show_host_node_name = 1,
2703 .show_host_port_name = 1,
2704 .show_host_supported_classes = 1,
2705 .show_host_supported_fc4s = 1,
2706 .show_host_active_fc4s = 1,
2707 .show_host_maxframe_size = 1,
2708
2709 .show_host_port_id = 1,
2710 .show_host_supported_speeds = 1,
2711 .get_host_speed = fc_get_host_speed,
2712 .show_host_speed = 1,
2713 .show_host_port_type = 1,
2714 .get_host_port_state = fc_get_host_port_state,
2715 .show_host_port_state = 1,
2716 .show_host_symbolic_name = 1,
2717
2718 .dd_fcrport_size = (sizeof(struct fc_rport_libfc_priv) +
2719 sizeof(struct bnx2fc_rport)),
2720 .show_rport_maxframe_size = 1,
2721 .show_rport_supported_classes = 1,
2722
2723 .show_host_fabric_name = 1,
2724 .show_starget_node_name = 1,
2725 .show_starget_port_name = 1,
2726 .show_starget_port_id = 1,
2727 .set_rport_dev_loss_tmo = fc_set_rport_loss_tmo,
2728 .show_rport_dev_loss_tmo = 1,
2729 .get_fc_host_stats = bnx2fc_get_host_stats,
2730
2731 .issue_fc_host_lip = bnx2fc_fcoe_reset,
2732
2733 .terminate_rport_io = fc_rport_terminate_io,
2734
2735 .vport_create = bnx2fc_vport_create,
2736 .vport_delete = bnx2fc_vport_destroy,
2737 .vport_disable = bnx2fc_vport_disable,
e9a5289c 2738 .bsg_request = fc_lport_bsg_request,
853e2bd2
BG
2739};
2740
2741static struct fc_function_template bnx2fc_vport_xport_function = {
2742 .show_host_node_name = 1,
2743 .show_host_port_name = 1,
2744 .show_host_supported_classes = 1,
2745 .show_host_supported_fc4s = 1,
2746 .show_host_active_fc4s = 1,
2747 .show_host_maxframe_size = 1,
2748
2749 .show_host_port_id = 1,
2750 .show_host_supported_speeds = 1,
2751 .get_host_speed = fc_get_host_speed,
2752 .show_host_speed = 1,
2753 .show_host_port_type = 1,
2754 .get_host_port_state = fc_get_host_port_state,
2755 .show_host_port_state = 1,
2756 .show_host_symbolic_name = 1,
2757
2758 .dd_fcrport_size = (sizeof(struct fc_rport_libfc_priv) +
2759 sizeof(struct bnx2fc_rport)),
2760 .show_rport_maxframe_size = 1,
2761 .show_rport_supported_classes = 1,
2762
2763 .show_host_fabric_name = 1,
2764 .show_starget_node_name = 1,
2765 .show_starget_port_name = 1,
2766 .show_starget_port_id = 1,
2767 .set_rport_dev_loss_tmo = fc_set_rport_loss_tmo,
2768 .show_rport_dev_loss_tmo = 1,
2769 .get_fc_host_stats = fc_get_host_stats,
2770 .issue_fc_host_lip = bnx2fc_fcoe_reset,
2771 .terminate_rport_io = fc_rport_terminate_io,
e9a5289c 2772 .bsg_request = fc_lport_bsg_request,
853e2bd2
BG
2773};
2774
2775/**
2776 * scsi_host_template structure used while registering with SCSI-ml
2777 */
2778static struct scsi_host_template bnx2fc_shost_template = {
2779 .module = THIS_MODULE,
17d87c45 2780 .name = "QLogic Offload FCoE Initiator",
853e2bd2
BG
2781 .queuecommand = bnx2fc_queuecommand,
2782 .eh_abort_handler = bnx2fc_eh_abort, /* abts */
2783 .eh_device_reset_handler = bnx2fc_eh_device_reset, /* lun reset */
2784 .eh_target_reset_handler = bnx2fc_eh_target_reset, /* tgt reset */
2785 .eh_host_reset_handler = fc_eh_host_reset,
2786 .slave_alloc = fc_slave_alloc,
2787 .change_queue_depth = fc_change_queue_depth,
a62182f3 2788 .change_queue_type = scsi_change_queue_type,
853e2bd2
BG
2789 .this_id = -1,
2790 .cmd_per_lun = 3,
853e2bd2
BG
2791 .use_clustering = ENABLE_CLUSTERING,
2792 .sg_tablesize = BNX2FC_MAX_BDS_PER_CMD,
d450d778 2793 .max_sectors = 1024,
2ecb204d 2794 .use_blk_tags = 1,
c40ecc12 2795 .track_queue_depth = 1,
853e2bd2
BG
2796};
2797
2798static struct libfc_function_template bnx2fc_libfc_fcn_templ = {
2799 .frame_send = bnx2fc_xmit,
2800 .elsct_send = bnx2fc_elsct_send,
2801 .fcp_abort_io = bnx2fc_abort_io,
2802 .fcp_cleanup = bnx2fc_cleanup,
b8b3e697 2803 .get_lesb = fcoe_get_lesb,
853e2bd2
BG
2804 .rport_event_callback = bnx2fc_rport_event_handler,
2805};
2806
2807/**
2808 * bnx2fc_cnic_cb - global template of bnx2fc - cnic driver interface
2809 * structure carrying callback function pointers
2810 */
2811static struct cnic_ulp_ops bnx2fc_cnic_cb = {
2812 .owner = THIS_MODULE,
2813 .cnic_init = bnx2fc_ulp_init,
2814 .cnic_exit = bnx2fc_ulp_exit,
2815 .cnic_start = bnx2fc_ulp_start,
2816 .cnic_stop = bnx2fc_ulp_stop,
2817 .indicate_kcqes = bnx2fc_indicate_kcqe,
2818 .indicate_netevent = bnx2fc_indicate_netevent,
2e499d3c 2819 .cnic_get_stats = bnx2fc_ulp_get_stats,
853e2bd2 2820};