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