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