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