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