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