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