blob: 8f894e410b5d0178f74f63169809fa243d911031 [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;
David Decotigny8ae6daca2011-04-27 18:32:38 +0000667 struct ethtool_cmd ecmd;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800668
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
David Decotigny8ae6daca2011-04-27 18:32:38 +0000678 switch (ethtool_cmd_speed(&ecmd)) {
679 case SPEED_1000:
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800680 lport->link_speed = FC_PORTSPEED_1GBIT;
David Decotigny8ae6daca2011-04-27 18:32:38 +0000681 break;
Bhanu Prakash Gollapudia4dc08c2011-05-27 11:47:25 -0700682 case SPEED_2500:
683 lport->link_speed = FC_PORTSPEED_2GBIT;
684 break;
David Decotigny8ae6daca2011-04-27 18:32:38 +0000685 case SPEED_10000:
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800686 lport->link_speed = FC_PORTSPEED_10GBIT;
David Decotigny8ae6daca2011-04-27 18:32:38 +0000687 break;
688 }
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800689 }
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800690}
691static int bnx2fc_link_ok(struct fc_lport *lport)
692{
693 struct fcoe_port *port = lport_priv(lport);
694 struct bnx2fc_hba *hba = port->priv;
695 struct net_device *dev = hba->phys_dev;
696 int rc = 0;
697
698 if ((dev->flags & IFF_UP) && netif_carrier_ok(dev))
699 clear_bit(ADAPTER_STATE_LINK_DOWN, &hba->adapter_state);
700 else {
701 set_bit(ADAPTER_STATE_LINK_DOWN, &hba->adapter_state);
702 rc = -1;
703 }
704 return rc;
705}
706
707/**
708 * bnx2fc_get_link_state - get network link state
709 *
710 * @hba: adapter instance pointer
711 *
712 * updates adapter structure flag based on netdev state
713 */
714void bnx2fc_get_link_state(struct bnx2fc_hba *hba)
715{
716 if (test_bit(__LINK_STATE_NOCARRIER, &hba->netdev->state))
717 set_bit(ADAPTER_STATE_LINK_DOWN, &hba->adapter_state);
718 else
719 clear_bit(ADAPTER_STATE_LINK_DOWN, &hba->adapter_state);
720}
721
722static int bnx2fc_net_config(struct fc_lport *lport)
723{
724 struct bnx2fc_hba *hba;
725 struct fcoe_port *port;
726 u64 wwnn, wwpn;
727
728 port = lport_priv(lport);
729 hba = port->priv;
730
731 /* require support for get_pauseparam ethtool op. */
732 if (!hba->phys_dev->ethtool_ops ||
733 !hba->phys_dev->ethtool_ops->get_pauseparam)
734 return -EOPNOTSUPP;
735
Bhanu Gollapudi1294bfe2011-03-17 17:13:34 -0700736 if (fc_set_mfs(lport, BNX2FC_MFS))
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800737 return -EINVAL;
738
739 skb_queue_head_init(&port->fcoe_pending_queue);
740 port->fcoe_pending_queue_active = 0;
741 setup_timer(&port->timer, fcoe_queue_timer, (unsigned long) lport);
742
743 bnx2fc_link_speed_update(lport);
744
745 if (!lport->vport) {
746 wwnn = fcoe_wwn_from_mac(hba->ctlr.ctl_src_addr, 1, 0);
747 BNX2FC_HBA_DBG(lport, "WWNN = 0x%llx\n", wwnn);
748 fc_set_wwnn(lport, wwnn);
749
750 wwpn = fcoe_wwn_from_mac(hba->ctlr.ctl_src_addr, 2, 0);
751 BNX2FC_HBA_DBG(lport, "WWPN = 0x%llx\n", wwpn);
752 fc_set_wwpn(lport, wwpn);
753 }
754
755 return 0;
756}
757
758static void bnx2fc_destroy_timer(unsigned long data)
759{
760 struct bnx2fc_hba *hba = (struct bnx2fc_hba *)data;
761
762 BNX2FC_HBA_DBG(hba->ctlr.lp, "ERROR:bnx2fc_destroy_timer - "
763 "Destroy compl not received!!\n");
764 hba->flags |= BNX2FC_FLAG_DESTROY_CMPL;
765 wake_up_interruptible(&hba->destroy_wait);
766}
767
768/**
769 * bnx2fc_indicate_netevent - Generic netdev event handler
770 *
771 * @context: adapter structure pointer
772 * @event: event type
773 *
774 * Handles NETDEV_UP, NETDEV_DOWN, NETDEV_GOING_DOWN,NETDEV_CHANGE and
775 * NETDEV_CHANGE_MTU events
776 */
777static void bnx2fc_indicate_netevent(void *context, unsigned long event)
778{
779 struct bnx2fc_hba *hba = (struct bnx2fc_hba *)context;
780 struct fc_lport *lport = hba->ctlr.lp;
781 struct fc_lport *vport;
782 u32 link_possible = 1;
783
784 if (!test_bit(BNX2FC_CREATE_DONE, &hba->init_done)) {
785 BNX2FC_MISC_DBG("driver not ready. event=%s %ld\n",
786 hba->netdev->name, event);
787 return;
788 }
789
790 /*
791 * ASSUMPTION:
792 * indicate_netevent cannot be called from cnic unless bnx2fc
793 * does register_device
794 */
795 BUG_ON(!lport);
796
797 BNX2FC_HBA_DBG(lport, "enter netevent handler - event=%s %ld\n",
798 hba->netdev->name, event);
799
800 switch (event) {
801 case NETDEV_UP:
802 BNX2FC_HBA_DBG(lport, "Port up, adapter_state = %ld\n",
803 hba->adapter_state);
804 if (!test_bit(ADAPTER_STATE_UP, &hba->adapter_state))
805 printk(KERN_ERR "indicate_netevent: "\
806 "adapter is not UP!!\n");
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800807 break;
808
809 case NETDEV_DOWN:
810 BNX2FC_HBA_DBG(lport, "Port down\n");
811 clear_bit(ADAPTER_STATE_GOING_DOWN, &hba->adapter_state);
812 clear_bit(ADAPTER_STATE_UP, &hba->adapter_state);
813 link_possible = 0;
814 break;
815
816 case NETDEV_GOING_DOWN:
817 BNX2FC_HBA_DBG(lport, "Port going down\n");
818 set_bit(ADAPTER_STATE_GOING_DOWN, &hba->adapter_state);
819 link_possible = 0;
820 break;
821
822 case NETDEV_CHANGE:
823 BNX2FC_HBA_DBG(lport, "NETDEV_CHANGE\n");
824 break;
825
826 default:
827 printk(KERN_ERR PFX "Unkonwn netevent %ld", event);
828 return;
829 }
830
831 bnx2fc_link_speed_update(lport);
832
833 if (link_possible && !bnx2fc_link_ok(lport)) {
834 printk(KERN_ERR "indicate_netevent: call ctlr_link_up\n");
835 fcoe_ctlr_link_up(&hba->ctlr);
836 } else {
837 printk(KERN_ERR "indicate_netevent: call ctlr_link_down\n");
838 if (fcoe_ctlr_link_down(&hba->ctlr)) {
839 clear_bit(ADAPTER_STATE_READY, &hba->adapter_state);
840 mutex_lock(&lport->lp_mutex);
841 list_for_each_entry(vport, &lport->vports, list)
842 fc_host_port_type(vport->host) =
843 FC_PORTTYPE_UNKNOWN;
844 mutex_unlock(&lport->lp_mutex);
845 fc_host_port_type(lport->host) = FC_PORTTYPE_UNKNOWN;
846 per_cpu_ptr(lport->dev_stats,
847 get_cpu())->LinkFailureCount++;
848 put_cpu();
849 fcoe_clean_pending_queue(lport);
850
851 init_waitqueue_head(&hba->shutdown_wait);
852 BNX2FC_HBA_DBG(lport, "indicate_netevent "
853 "num_ofld_sess = %d\n",
854 hba->num_ofld_sess);
855 hba->wait_for_link_down = 1;
856 BNX2FC_HBA_DBG(lport, "waiting for uploads to "
857 "compl proc = %s\n",
858 current->comm);
859 wait_event_interruptible(hba->shutdown_wait,
860 (hba->num_ofld_sess == 0));
861 BNX2FC_HBA_DBG(lport, "wakeup - num_ofld_sess = %d\n",
862 hba->num_ofld_sess);
863 hba->wait_for_link_down = 0;
864
865 if (signal_pending(current))
866 flush_signals(current);
867 }
868 }
869}
870
871static int bnx2fc_libfc_config(struct fc_lport *lport)
872{
873
874 /* Set the function pointers set by bnx2fc driver */
875 memcpy(&lport->tt, &bnx2fc_libfc_fcn_templ,
876 sizeof(struct libfc_function_template));
877 fc_elsct_init(lport);
878 fc_exch_init(lport);
879 fc_rport_init(lport);
880 fc_disc_init(lport);
881 return 0;
882}
883
884static int bnx2fc_em_config(struct fc_lport *lport)
885{
886 struct fcoe_port *port = lport_priv(lport);
887 struct bnx2fc_hba *hba = port->priv;
888
889 if (!fc_exch_mgr_alloc(lport, FC_CLASS_3, FCOE_MIN_XID,
890 FCOE_MAX_XID, NULL)) {
891 printk(KERN_ERR PFX "em_config:fc_exch_mgr_alloc failed\n");
892 return -ENOMEM;
893 }
894
895 hba->cmd_mgr = bnx2fc_cmd_mgr_alloc(hba, BNX2FC_MIN_XID,
896 BNX2FC_MAX_XID);
897
898 if (!hba->cmd_mgr) {
899 printk(KERN_ERR PFX "em_config:bnx2fc_cmd_mgr_alloc failed\n");
900 fc_exch_mgr_free(lport);
901 return -ENOMEM;
902 }
903 return 0;
904}
905
906static int bnx2fc_lport_config(struct fc_lport *lport)
907{
908 lport->link_up = 0;
909 lport->qfull = 0;
910 lport->max_retry_count = 3;
911 lport->max_rport_retry_count = 3;
912 lport->e_d_tov = 2 * 1000;
913 lport->r_a_tov = 10 * 1000;
914
915 /* REVISIT: enable when supporting tape devices
916 lport->service_params = (FCP_SPPF_INIT_FCN | FCP_SPPF_RD_XRDY_DIS |
917 FCP_SPPF_RETRY | FCP_SPPF_CONF_COMPL);
918 */
919 lport->service_params = (FCP_SPPF_INIT_FCN | FCP_SPPF_RD_XRDY_DIS);
920 lport->does_npiv = 1;
921
922 memset(&lport->rnid_gen, 0, sizeof(struct fc_els_rnid_gen));
923 lport->rnid_gen.rnid_atype = BNX2FC_RNID_HBA;
924
925 /* alloc stats structure */
926 if (fc_lport_init_stats(lport))
927 return -ENOMEM;
928
929 /* Finish fc_lport configuration */
930 fc_lport_config(lport);
931
932 return 0;
933}
934
935/**
936 * bnx2fc_fip_recv - handle a received FIP frame.
937 *
938 * @skb: the received skb
939 * @dev: associated &net_device
940 * @ptype: the &packet_type structure which was used to register this handler.
941 * @orig_dev: original receive &net_device, in case @ dev is a bond.
942 *
943 * Returns: 0 for success
944 */
945static int bnx2fc_fip_recv(struct sk_buff *skb, struct net_device *dev,
946 struct packet_type *ptype,
947 struct net_device *orig_dev)
948{
949 struct bnx2fc_hba *hba;
950 hba = container_of(ptype, struct bnx2fc_hba, fip_packet_type);
951 fcoe_ctlr_recv(&hba->ctlr, skb);
952 return 0;
953}
954
955/**
956 * bnx2fc_update_src_mac - Update Ethernet MAC filters.
957 *
958 * @fip: FCoE controller.
959 * @old: Unicast MAC address to delete if the MAC is non-zero.
960 * @new: Unicast MAC address to add.
961 *
962 * Remove any previously-set unicast MAC filter.
963 * Add secondary FCoE MAC address filter for our OUI.
964 */
965static void bnx2fc_update_src_mac(struct fc_lport *lport, u8 *addr)
966{
967 struct fcoe_port *port = lport_priv(lport);
968
969 memcpy(port->data_src_addr, addr, ETH_ALEN);
970}
971
972/**
973 * bnx2fc_get_src_mac - return the ethernet source address for an lport
974 *
975 * @lport: libfc port
976 */
977static u8 *bnx2fc_get_src_mac(struct fc_lport *lport)
978{
979 struct fcoe_port *port;
980
981 port = (struct fcoe_port *)lport_priv(lport);
982 return port->data_src_addr;
983}
984
985/**
986 * bnx2fc_fip_send - send an Ethernet-encapsulated FIP frame.
987 *
988 * @fip: FCoE controller.
989 * @skb: FIP Packet.
990 */
991static void bnx2fc_fip_send(struct fcoe_ctlr *fip, struct sk_buff *skb)
992{
993 skb->dev = bnx2fc_from_ctlr(fip)->netdev;
994 dev_queue_xmit(skb);
995}
996
997static int bnx2fc_vport_create(struct fc_vport *vport, bool disabled)
998{
999 struct Scsi_Host *shost = vport_to_shost(vport);
1000 struct fc_lport *n_port = shost_priv(shost);
1001 struct fcoe_port *port = lport_priv(n_port);
1002 struct bnx2fc_hba *hba = port->priv;
1003 struct net_device *netdev = hba->netdev;
1004 struct fc_lport *vn_port;
1005
1006 if (!test_bit(BNX2FC_FW_INIT_DONE, &hba->init_done)) {
1007 printk(KERN_ERR PFX "vn ports cannot be created on"
1008 "this hba\n");
1009 return -EIO;
1010 }
1011 mutex_lock(&bnx2fc_dev_lock);
1012 vn_port = bnx2fc_if_create(hba, &vport->dev, 1);
1013 mutex_unlock(&bnx2fc_dev_lock);
1014
1015 if (IS_ERR(vn_port)) {
1016 printk(KERN_ERR PFX "bnx2fc_vport_create (%s) failed\n",
1017 netdev->name);
1018 return -EIO;
1019 }
1020
1021 if (disabled) {
1022 fc_vport_set_state(vport, FC_VPORT_DISABLED);
1023 } else {
1024 vn_port->boot_time = jiffies;
1025 fc_lport_init(vn_port);
1026 fc_fabric_login(vn_port);
1027 fc_vport_setlink(vn_port);
1028 }
1029 return 0;
1030}
1031
1032static int bnx2fc_vport_destroy(struct fc_vport *vport)
1033{
1034 struct Scsi_Host *shost = vport_to_shost(vport);
1035 struct fc_lport *n_port = shost_priv(shost);
1036 struct fc_lport *vn_port = vport->dd_data;
1037 struct fcoe_port *port = lport_priv(vn_port);
1038
1039 mutex_lock(&n_port->lp_mutex);
1040 list_del(&vn_port->list);
1041 mutex_unlock(&n_port->lp_mutex);
1042 queue_work(bnx2fc_wq, &port->destroy_work);
1043 return 0;
1044}
1045
1046static int bnx2fc_vport_disable(struct fc_vport *vport, bool disable)
1047{
1048 struct fc_lport *lport = vport->dd_data;
1049
1050 if (disable) {
1051 fc_vport_set_state(vport, FC_VPORT_DISABLED);
1052 fc_fabric_logoff(lport);
1053 } else {
1054 lport->boot_time = jiffies;
1055 fc_fabric_login(lport);
1056 fc_vport_setlink(lport);
1057 }
1058 return 0;
1059}
1060
1061
1062static int bnx2fc_netdev_setup(struct bnx2fc_hba *hba)
1063{
1064 struct net_device *netdev = hba->netdev;
1065 struct net_device *physdev = hba->phys_dev;
1066 struct netdev_hw_addr *ha;
1067 int sel_san_mac = 0;
1068
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001069 /* setup Source MAC Address */
1070 rcu_read_lock();
1071 for_each_dev_addr(physdev, ha) {
1072 BNX2FC_MISC_DBG("net_config: ha->type = %d, fip_mac = ",
1073 ha->type);
1074 printk(KERN_INFO "%2x:%2x:%2x:%2x:%2x:%2x\n", ha->addr[0],
1075 ha->addr[1], ha->addr[2], ha->addr[3],
1076 ha->addr[4], ha->addr[5]);
1077
1078 if ((ha->type == NETDEV_HW_ADDR_T_SAN) &&
1079 (is_valid_ether_addr(ha->addr))) {
1080 memcpy(hba->ctlr.ctl_src_addr, ha->addr, ETH_ALEN);
1081 sel_san_mac = 1;
1082 BNX2FC_MISC_DBG("Found SAN MAC\n");
1083 }
1084 }
1085 rcu_read_unlock();
1086
1087 if (!sel_san_mac)
1088 return -ENODEV;
1089
1090 hba->fip_packet_type.func = bnx2fc_fip_recv;
1091 hba->fip_packet_type.type = htons(ETH_P_FIP);
1092 hba->fip_packet_type.dev = netdev;
1093 dev_add_pack(&hba->fip_packet_type);
1094
1095 hba->fcoe_packet_type.func = bnx2fc_rcv;
1096 hba->fcoe_packet_type.type = __constant_htons(ETH_P_FCOE);
1097 hba->fcoe_packet_type.dev = netdev;
1098 dev_add_pack(&hba->fcoe_packet_type);
1099
1100 return 0;
1101}
1102
1103static int bnx2fc_attach_transport(void)
1104{
1105 bnx2fc_transport_template =
1106 fc_attach_transport(&bnx2fc_transport_function);
1107
1108 if (bnx2fc_transport_template == NULL) {
1109 printk(KERN_ERR PFX "Failed to attach FC transport\n");
1110 return -ENODEV;
1111 }
1112
1113 bnx2fc_vport_xport_template =
1114 fc_attach_transport(&bnx2fc_vport_xport_function);
1115 if (bnx2fc_vport_xport_template == NULL) {
1116 printk(KERN_ERR PFX
1117 "Failed to attach FC transport for vport\n");
1118 fc_release_transport(bnx2fc_transport_template);
1119 bnx2fc_transport_template = NULL;
1120 return -ENODEV;
1121 }
1122 return 0;
1123}
1124static void bnx2fc_release_transport(void)
1125{
1126 fc_release_transport(bnx2fc_transport_template);
1127 fc_release_transport(bnx2fc_vport_xport_template);
1128 bnx2fc_transport_template = NULL;
1129 bnx2fc_vport_xport_template = NULL;
1130}
1131
1132static void bnx2fc_interface_release(struct kref *kref)
1133{
1134 struct bnx2fc_hba *hba;
1135 struct net_device *netdev;
1136 struct net_device *phys_dev;
1137
1138 hba = container_of(kref, struct bnx2fc_hba, kref);
Nithin Nayak Sujir068bdce2011-04-25 12:30:09 -07001139 BNX2FC_MISC_DBG("Interface is being released\n");
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001140
1141 netdev = hba->netdev;
1142 phys_dev = hba->phys_dev;
1143
1144 /* tear-down FIP controller */
1145 if (test_and_clear_bit(BNX2FC_CTLR_INIT_DONE, &hba->init_done))
1146 fcoe_ctlr_destroy(&hba->ctlr);
1147
1148 /* Free the command manager */
1149 if (hba->cmd_mgr) {
1150 bnx2fc_cmd_mgr_free(hba->cmd_mgr);
1151 hba->cmd_mgr = NULL;
1152 }
1153 dev_put(netdev);
1154 module_put(THIS_MODULE);
1155}
1156
1157static inline void bnx2fc_interface_get(struct bnx2fc_hba *hba)
1158{
1159 kref_get(&hba->kref);
1160}
1161
1162static inline void bnx2fc_interface_put(struct bnx2fc_hba *hba)
1163{
1164 kref_put(&hba->kref, bnx2fc_interface_release);
1165}
1166static void bnx2fc_interface_destroy(struct bnx2fc_hba *hba)
1167{
1168 bnx2fc_unbind_pcidev(hba);
1169 kfree(hba);
1170}
1171
1172/**
1173 * bnx2fc_interface_create - create a new fcoe instance
1174 *
1175 * @cnic: pointer to cnic device
1176 *
1177 * Creates a new FCoE instance on the given device which include allocating
1178 * hba structure, scsi_host and lport structures.
1179 */
1180static struct bnx2fc_hba *bnx2fc_interface_create(struct cnic_dev *cnic)
1181{
1182 struct bnx2fc_hba *hba;
1183 int rc;
1184
1185 hba = kzalloc(sizeof(*hba), GFP_KERNEL);
1186 if (!hba) {
1187 printk(KERN_ERR PFX "Unable to allocate hba structure\n");
1188 return NULL;
1189 }
1190 spin_lock_init(&hba->hba_lock);
1191 mutex_init(&hba->hba_mutex);
1192
1193 hba->cnic = cnic;
1194 rc = bnx2fc_bind_pcidev(hba);
1195 if (rc)
1196 goto bind_err;
1197 hba->phys_dev = cnic->netdev;
1198 /* will get overwritten after we do vlan discovery */
1199 hba->netdev = hba->phys_dev;
1200
1201 init_waitqueue_head(&hba->shutdown_wait);
1202 init_waitqueue_head(&hba->destroy_wait);
1203
1204 return hba;
1205bind_err:
1206 printk(KERN_ERR PFX "create_interface: bind error\n");
1207 kfree(hba);
1208 return NULL;
1209}
1210
1211static int bnx2fc_interface_setup(struct bnx2fc_hba *hba,
1212 enum fip_state fip_mode)
1213{
1214 int rc = 0;
1215 struct net_device *netdev = hba->netdev;
1216 struct fcoe_ctlr *fip = &hba->ctlr;
1217
1218 dev_hold(netdev);
1219 kref_init(&hba->kref);
1220
1221 hba->flags = 0;
1222
1223 /* Initialize FIP */
1224 memset(fip, 0, sizeof(*fip));
1225 fcoe_ctlr_init(fip, fip_mode);
1226 hba->ctlr.send = bnx2fc_fip_send;
1227 hba->ctlr.update_mac = bnx2fc_update_src_mac;
1228 hba->ctlr.get_src_addr = bnx2fc_get_src_mac;
1229 set_bit(BNX2FC_CTLR_INIT_DONE, &hba->init_done);
1230
1231 rc = bnx2fc_netdev_setup(hba);
1232 if (rc)
1233 goto setup_err;
1234
1235 hba->next_conn_id = 0;
1236
1237 memset(hba->tgt_ofld_list, 0, sizeof(hba->tgt_ofld_list));
1238 hba->num_ofld_sess = 0;
1239
1240 return 0;
1241
1242setup_err:
1243 fcoe_ctlr_destroy(&hba->ctlr);
1244 dev_put(netdev);
1245 bnx2fc_interface_put(hba);
1246 return rc;
1247}
1248
1249/**
1250 * bnx2fc_if_create - Create FCoE instance on a given interface
1251 *
1252 * @hba: FCoE interface to create a local port on
1253 * @parent: Device pointer to be the parent in sysfs for the SCSI host
1254 * @npiv: Indicates if the port is vport or not
1255 *
1256 * Creates a fc_lport instance and a Scsi_Host instance and configure them.
1257 *
1258 * Returns: Allocated fc_lport or an error pointer
1259 */
1260static struct fc_lport *bnx2fc_if_create(struct bnx2fc_hba *hba,
1261 struct device *parent, int npiv)
1262{
Vasu Dev134a4e22011-04-28 15:55:44 -07001263 struct fc_lport *lport, *n_port;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001264 struct fcoe_port *port;
1265 struct Scsi_Host *shost;
1266 struct fc_vport *vport = dev_to_vport(parent);
1267 int rc = 0;
1268
1269 /* Allocate Scsi_Host structure */
Vasu Dev134a4e22011-04-28 15:55:44 -07001270 if (!npiv)
1271 lport = libfc_host_alloc(&bnx2fc_shost_template, sizeof(*port));
1272 else
1273 lport = libfc_vport_create(vport, sizeof(*port));
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001274
1275 if (!lport) {
1276 printk(KERN_ERR PFX "could not allocate scsi host structure\n");
1277 return NULL;
1278 }
1279 shost = lport->host;
1280 port = lport_priv(lport);
1281 port->lport = lport;
1282 port->priv = hba;
1283 INIT_WORK(&port->destroy_work, bnx2fc_destroy_work);
1284
1285 /* Configure fcoe_port */
1286 rc = bnx2fc_lport_config(lport);
1287 if (rc)
1288 goto lp_config_err;
1289
1290 if (npiv) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001291 printk(KERN_ERR PFX "Setting vport names, 0x%llX 0x%llX\n",
1292 vport->node_name, vport->port_name);
1293 fc_set_wwnn(lport, vport->node_name);
1294 fc_set_wwpn(lport, vport->port_name);
1295 }
1296 /* Configure netdev and networking properties of the lport */
1297 rc = bnx2fc_net_config(lport);
1298 if (rc) {
1299 printk(KERN_ERR PFX "Error on bnx2fc_net_config\n");
1300 goto lp_config_err;
1301 }
1302
1303 rc = bnx2fc_shost_config(lport, parent);
1304 if (rc) {
1305 printk(KERN_ERR PFX "Couldnt configure shost for %s\n",
1306 hba->netdev->name);
1307 goto lp_config_err;
1308 }
1309
1310 /* Initialize the libfc library */
1311 rc = bnx2fc_libfc_config(lport);
1312 if (rc) {
1313 printk(KERN_ERR PFX "Couldnt configure libfc\n");
1314 goto shost_err;
1315 }
1316 fc_host_port_type(lport->host) = FC_PORTTYPE_UNKNOWN;
1317
1318 /* Allocate exchange manager */
Vasu Dev134a4e22011-04-28 15:55:44 -07001319 if (!npiv)
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001320 rc = bnx2fc_em_config(lport);
Vasu Dev134a4e22011-04-28 15:55:44 -07001321 else {
1322 shost = vport_to_shost(vport);
1323 n_port = shost_priv(shost);
1324 rc = fc_exch_mgr_list_clone(n_port, lport);
1325 }
1326
1327 if (rc) {
1328 printk(KERN_ERR PFX "Error on bnx2fc_em_config\n");
1329 goto shost_err;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001330 }
1331
1332 bnx2fc_interface_get(hba);
1333 return lport;
1334
1335shost_err:
1336 scsi_remove_host(shost);
1337lp_config_err:
1338 scsi_host_put(lport->host);
1339 return NULL;
1340}
1341
1342static void bnx2fc_netdev_cleanup(struct bnx2fc_hba *hba)
1343{
1344 /* Dont listen for Ethernet packets anymore */
1345 __dev_remove_pack(&hba->fcoe_packet_type);
1346 __dev_remove_pack(&hba->fip_packet_type);
1347 synchronize_net();
1348}
1349
1350static void bnx2fc_if_destroy(struct fc_lport *lport)
1351{
1352 struct fcoe_port *port = lport_priv(lport);
1353 struct bnx2fc_hba *hba = port->priv;
1354
1355 BNX2FC_HBA_DBG(hba->ctlr.lp, "ENTERED bnx2fc_if_destroy\n");
1356 /* Stop the transmit retry timer */
1357 del_timer_sync(&port->timer);
1358
1359 /* Free existing transmit skbs */
1360 fcoe_clean_pending_queue(lport);
1361
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001362 /* Free queued packets for the receive thread */
1363 bnx2fc_clean_rx_queue(lport);
1364
1365 /* Detach from scsi-ml */
1366 fc_remove_host(lport->host);
1367 scsi_remove_host(lport->host);
1368
1369 /*
1370 * Note that only the physical lport will have the exchange manager.
1371 * for vports, this function is NOP
1372 */
1373 fc_exch_mgr_free(lport);
1374
1375 /* Free memory used by statistical counters */
1376 fc_lport_free_stats(lport);
1377
1378 /* Release Scsi_Host */
1379 scsi_host_put(lport->host);
Nithin Nayak Sujir0117ddb2011-04-25 12:30:07 -07001380
1381 bnx2fc_interface_put(hba);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001382}
1383
1384/**
1385 * bnx2fc_destroy - Destroy a bnx2fc FCoE interface
1386 *
1387 * @buffer: The name of the Ethernet interface to be destroyed
1388 * @kp: The associated kernel parameter
1389 *
1390 * Called from sysfs.
1391 *
1392 * Returns: 0 for success
1393 */
1394static int bnx2fc_destroy(struct net_device *netdev)
1395{
1396 struct bnx2fc_hba *hba = NULL;
1397 struct net_device *phys_dev;
1398 int rc = 0;
1399
Nithin Sujir6702ca12011-03-17 17:13:27 -07001400 rtnl_lock();
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001401
1402 mutex_lock(&bnx2fc_dev_lock);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001403 /* obtain physical netdev */
1404 if (netdev->priv_flags & IFF_802_1Q_VLAN)
1405 phys_dev = vlan_dev_real_dev(netdev);
1406 else {
1407 printk(KERN_ERR PFX "Not a vlan device\n");
1408 rc = -ENODEV;
1409 goto netdev_err;
1410 }
1411
1412 hba = bnx2fc_hba_lookup(phys_dev);
1413 if (!hba || !hba->ctlr.lp) {
1414 rc = -ENODEV;
1415 printk(KERN_ERR PFX "bnx2fc_destroy: hba or lport not found\n");
1416 goto netdev_err;
1417 }
1418
1419 if (!test_bit(BNX2FC_CREATE_DONE, &hba->init_done)) {
1420 printk(KERN_ERR PFX "bnx2fc_destroy: Create not called\n");
1421 goto netdev_err;
1422 }
1423
1424 bnx2fc_netdev_cleanup(hba);
1425
1426 bnx2fc_stop(hba);
1427
1428 bnx2fc_if_destroy(hba->ctlr.lp);
1429
1430 destroy_workqueue(hba->timer_work_queue);
1431
1432 if (test_bit(BNX2FC_FW_INIT_DONE, &hba->init_done))
1433 bnx2fc_fw_destroy(hba);
1434
1435 clear_bit(BNX2FC_CREATE_DONE, &hba->init_done);
1436netdev_err:
1437 mutex_unlock(&bnx2fc_dev_lock);
1438 rtnl_unlock();
1439 return rc;
1440}
1441
1442static void bnx2fc_destroy_work(struct work_struct *work)
1443{
1444 struct fcoe_port *port;
1445 struct fc_lport *lport;
1446
1447 port = container_of(work, struct fcoe_port, destroy_work);
1448 lport = port->lport;
1449
1450 BNX2FC_HBA_DBG(lport, "Entered bnx2fc_destroy_work\n");
1451
1452 bnx2fc_port_shutdown(lport);
1453 rtnl_lock();
1454 mutex_lock(&bnx2fc_dev_lock);
1455 bnx2fc_if_destroy(lport);
1456 mutex_unlock(&bnx2fc_dev_lock);
1457 rtnl_unlock();
1458}
1459
1460static void bnx2fc_unbind_adapter_devices(struct bnx2fc_hba *hba)
1461{
1462 bnx2fc_free_fw_resc(hba);
1463 bnx2fc_free_task_ctx(hba);
1464}
1465
1466/**
1467 * bnx2fc_bind_adapter_devices - binds bnx2fc adapter with the associated
1468 * pci structure
1469 *
1470 * @hba: Adapter instance
1471 */
1472static int bnx2fc_bind_adapter_devices(struct bnx2fc_hba *hba)
1473{
1474 if (bnx2fc_setup_task_ctx(hba))
1475 goto mem_err;
1476
1477 if (bnx2fc_setup_fw_resc(hba))
1478 goto mem_err;
1479
1480 return 0;
1481mem_err:
1482 bnx2fc_unbind_adapter_devices(hba);
1483 return -ENOMEM;
1484}
1485
1486static int bnx2fc_bind_pcidev(struct bnx2fc_hba *hba)
1487{
1488 struct cnic_dev *cnic;
1489
1490 if (!hba->cnic) {
1491 printk(KERN_ERR PFX "cnic is NULL\n");
1492 return -ENODEV;
1493 }
1494 cnic = hba->cnic;
1495 hba->pcidev = cnic->pcidev;
1496 if (hba->pcidev)
1497 pci_dev_get(hba->pcidev);
1498
1499 return 0;
1500}
1501
1502static void bnx2fc_unbind_pcidev(struct bnx2fc_hba *hba)
1503{
1504 if (hba->pcidev)
1505 pci_dev_put(hba->pcidev);
1506 hba->pcidev = NULL;
1507}
1508
1509
1510
1511/**
1512 * bnx2fc_ulp_start - cnic callback to initialize & start adapter instance
1513 *
1514 * @handle: transport handle pointing to adapter struture
1515 *
1516 * This function maps adapter structure to pcidev structure and initiates
1517 * firmware handshake to enable/initialize on-chip FCoE components.
1518 * This bnx2fc - cnic interface api callback is used after following
1519 * conditions are met -
1520 * a) underlying network interface is up (marked by event NETDEV_UP
1521 * from netdev
1522 * b) bnx2fc adatper structure is registered.
1523 */
1524static void bnx2fc_ulp_start(void *handle)
1525{
1526 struct bnx2fc_hba *hba = handle;
1527 struct fc_lport *lport = hba->ctlr.lp;
1528
1529 BNX2FC_MISC_DBG("Entered %s\n", __func__);
1530 mutex_lock(&bnx2fc_dev_lock);
1531
1532 if (test_bit(BNX2FC_FW_INIT_DONE, &hba->init_done))
1533 goto start_disc;
1534
1535 if (test_bit(BNX2FC_CREATE_DONE, &hba->init_done))
1536 bnx2fc_fw_init(hba);
1537
1538start_disc:
1539 mutex_unlock(&bnx2fc_dev_lock);
1540
1541 BNX2FC_MISC_DBG("bnx2fc started.\n");
1542
1543 /* Kick off Fabric discovery*/
1544 if (test_bit(BNX2FC_CREATE_DONE, &hba->init_done)) {
1545 printk(KERN_ERR PFX "ulp_init: start discovery\n");
1546 lport->tt.frame_send = bnx2fc_xmit;
1547 bnx2fc_start_disc(hba);
1548 }
1549}
1550
1551static void bnx2fc_port_shutdown(struct fc_lport *lport)
1552{
1553 BNX2FC_MISC_DBG("Entered %s\n", __func__);
1554 fc_fabric_logoff(lport);
1555 fc_lport_destroy(lport);
1556}
1557
1558static void bnx2fc_stop(struct bnx2fc_hba *hba)
1559{
1560 struct fc_lport *lport;
1561 struct fc_lport *vport;
1562
1563 BNX2FC_MISC_DBG("ENTERED %s - init_done = %ld\n", __func__,
1564 hba->init_done);
1565 if (test_bit(BNX2FC_FW_INIT_DONE, &hba->init_done) &&
1566 test_bit(BNX2FC_CREATE_DONE, &hba->init_done)) {
1567 lport = hba->ctlr.lp;
1568 bnx2fc_port_shutdown(lport);
1569 BNX2FC_HBA_DBG(lport, "bnx2fc_stop: waiting for %d "
1570 "offloaded sessions\n",
1571 hba->num_ofld_sess);
1572 wait_event_interruptible(hba->shutdown_wait,
1573 (hba->num_ofld_sess == 0));
1574 mutex_lock(&lport->lp_mutex);
1575 list_for_each_entry(vport, &lport->vports, list)
1576 fc_host_port_type(vport->host) = FC_PORTTYPE_UNKNOWN;
1577 mutex_unlock(&lport->lp_mutex);
1578 fc_host_port_type(lport->host) = FC_PORTTYPE_UNKNOWN;
1579 fcoe_ctlr_link_down(&hba->ctlr);
1580 fcoe_clean_pending_queue(lport);
1581
1582 mutex_lock(&hba->hba_mutex);
1583 clear_bit(ADAPTER_STATE_UP, &hba->adapter_state);
1584 clear_bit(ADAPTER_STATE_GOING_DOWN, &hba->adapter_state);
1585
1586 clear_bit(ADAPTER_STATE_READY, &hba->adapter_state);
1587 mutex_unlock(&hba->hba_mutex);
1588 }
1589}
1590
1591static int bnx2fc_fw_init(struct bnx2fc_hba *hba)
1592{
1593#define BNX2FC_INIT_POLL_TIME (1000 / HZ)
1594 int rc = -1;
1595 int i = HZ;
1596
1597 rc = bnx2fc_bind_adapter_devices(hba);
1598 if (rc) {
1599 printk(KERN_ALERT PFX
1600 "bnx2fc_bind_adapter_devices failed - rc = %d\n", rc);
1601 goto err_out;
1602 }
1603
1604 rc = bnx2fc_send_fw_fcoe_init_msg(hba);
1605 if (rc) {
1606 printk(KERN_ALERT PFX
1607 "bnx2fc_send_fw_fcoe_init_msg failed - rc = %d\n", rc);
1608 goto err_unbind;
1609 }
1610
1611 /*
1612 * Wait until the adapter init message is complete, and adapter
1613 * state is UP.
1614 */
1615 while (!test_bit(ADAPTER_STATE_UP, &hba->adapter_state) && i--)
1616 msleep(BNX2FC_INIT_POLL_TIME);
1617
1618 if (!test_bit(ADAPTER_STATE_UP, &hba->adapter_state)) {
1619 printk(KERN_ERR PFX "bnx2fc_start: %s failed to initialize. "
1620 "Ignoring...\n",
1621 hba->cnic->netdev->name);
1622 rc = -1;
1623 goto err_unbind;
1624 }
1625
1626
1627 /* Mark HBA to indicate that the FW INIT is done */
1628 set_bit(BNX2FC_FW_INIT_DONE, &hba->init_done);
1629 return 0;
1630
1631err_unbind:
1632 bnx2fc_unbind_adapter_devices(hba);
1633err_out:
1634 return rc;
1635}
1636
1637static void bnx2fc_fw_destroy(struct bnx2fc_hba *hba)
1638{
1639 if (test_and_clear_bit(BNX2FC_FW_INIT_DONE, &hba->init_done)) {
1640 if (bnx2fc_send_fw_fcoe_destroy_msg(hba) == 0) {
1641 init_timer(&hba->destroy_timer);
1642 hba->destroy_timer.expires = BNX2FC_FW_TIMEOUT +
1643 jiffies;
1644 hba->destroy_timer.function = bnx2fc_destroy_timer;
1645 hba->destroy_timer.data = (unsigned long)hba;
1646 add_timer(&hba->destroy_timer);
1647 wait_event_interruptible(hba->destroy_wait,
1648 (hba->flags &
1649 BNX2FC_FLAG_DESTROY_CMPL));
1650 /* This should never happen */
1651 if (signal_pending(current))
1652 flush_signals(current);
1653
1654 del_timer_sync(&hba->destroy_timer);
1655 }
1656 bnx2fc_unbind_adapter_devices(hba);
1657 }
1658}
1659
1660/**
1661 * bnx2fc_ulp_stop - cnic callback to shutdown adapter instance
1662 *
1663 * @handle: transport handle pointing to adapter structure
1664 *
1665 * Driver checks if adapter is already in shutdown mode, if not start
1666 * the shutdown process.
1667 */
1668static void bnx2fc_ulp_stop(void *handle)
1669{
1670 struct bnx2fc_hba *hba = (struct bnx2fc_hba *)handle;
1671
1672 printk(KERN_ERR "ULP_STOP\n");
1673
1674 mutex_lock(&bnx2fc_dev_lock);
1675 bnx2fc_stop(hba);
1676 bnx2fc_fw_destroy(hba);
1677 mutex_unlock(&bnx2fc_dev_lock);
1678}
1679
1680static void bnx2fc_start_disc(struct bnx2fc_hba *hba)
1681{
1682 struct fc_lport *lport;
1683 int wait_cnt = 0;
1684
1685 BNX2FC_MISC_DBG("Entered %s\n", __func__);
1686 /* Kick off FIP/FLOGI */
1687 if (!test_bit(BNX2FC_FW_INIT_DONE, &hba->init_done)) {
1688 printk(KERN_ERR PFX "Init not done yet\n");
1689 return;
1690 }
1691
1692 lport = hba->ctlr.lp;
1693 BNX2FC_HBA_DBG(lport, "calling fc_fabric_login\n");
1694
1695 if (!bnx2fc_link_ok(lport)) {
1696 BNX2FC_HBA_DBG(lport, "ctlr_link_up\n");
1697 fcoe_ctlr_link_up(&hba->ctlr);
1698 fc_host_port_type(lport->host) = FC_PORTTYPE_NPORT;
1699 set_bit(ADAPTER_STATE_READY, &hba->adapter_state);
1700 }
1701
1702 /* wait for the FCF to be selected before issuing FLOGI */
1703 while (!hba->ctlr.sel_fcf) {
1704 msleep(250);
1705 /* give up after 3 secs */
1706 if (++wait_cnt > 12)
1707 break;
1708 }
1709 fc_lport_init(lport);
1710 fc_fabric_login(lport);
1711}
1712
1713
1714/**
1715 * bnx2fc_ulp_init - Initialize an adapter instance
1716 *
1717 * @dev : cnic device handle
1718 * Called from cnic_register_driver() context to initialize all
1719 * enumerated cnic devices. This routine allocates adapter structure
1720 * and other device specific resources.
1721 */
1722static void bnx2fc_ulp_init(struct cnic_dev *dev)
1723{
1724 struct bnx2fc_hba *hba;
1725 int rc = 0;
1726
1727 BNX2FC_MISC_DBG("Entered %s\n", __func__);
1728 /* bnx2fc works only when bnx2x is loaded */
1729 if (!test_bit(CNIC_F_BNX2X_CLASS, &dev->flags)) {
1730 printk(KERN_ERR PFX "bnx2fc FCoE not supported on %s,"
1731 " flags: %lx\n",
1732 dev->netdev->name, dev->flags);
1733 return;
1734 }
1735
1736 /* Configure FCoE interface */
1737 hba = bnx2fc_interface_create(dev);
1738 if (!hba) {
1739 printk(KERN_ERR PFX "hba initialization failed\n");
1740 return;
1741 }
1742
1743 /* Add HBA to the adapter list */
1744 mutex_lock(&bnx2fc_dev_lock);
1745 list_add_tail(&hba->link, &adapter_list);
1746 adapter_count++;
1747 mutex_unlock(&bnx2fc_dev_lock);
1748
1749 clear_bit(BNX2FC_CNIC_REGISTERED, &hba->reg_with_cnic);
1750 rc = dev->register_device(dev, CNIC_ULP_FCOE,
1751 (void *) hba);
1752 if (rc)
1753 printk(KERN_ALERT PFX "register_device failed, rc = %d\n", rc);
1754 else
1755 set_bit(BNX2FC_CNIC_REGISTERED, &hba->reg_with_cnic);
1756}
1757
1758
1759static int bnx2fc_disable(struct net_device *netdev)
1760{
1761 struct bnx2fc_hba *hba;
1762 struct net_device *phys_dev;
1763 struct ethtool_drvinfo drvinfo;
1764 int rc = 0;
1765
Nithin Sujir6702ca12011-03-17 17:13:27 -07001766 rtnl_lock();
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001767
1768 mutex_lock(&bnx2fc_dev_lock);
1769
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001770 /* obtain physical netdev */
1771 if (netdev->priv_flags & IFF_802_1Q_VLAN)
1772 phys_dev = vlan_dev_real_dev(netdev);
1773 else {
1774 printk(KERN_ERR PFX "Not a vlan device\n");
1775 rc = -ENODEV;
1776 goto nodev;
1777 }
1778
1779 /* verify if the physical device is a netxtreme2 device */
1780 if (phys_dev->ethtool_ops && phys_dev->ethtool_ops->get_drvinfo) {
1781 memset(&drvinfo, 0, sizeof(drvinfo));
1782 phys_dev->ethtool_ops->get_drvinfo(phys_dev, &drvinfo);
1783 if (strcmp(drvinfo.driver, "bnx2x")) {
1784 printk(KERN_ERR PFX "Not a netxtreme2 device\n");
1785 rc = -ENODEV;
1786 goto nodev;
1787 }
1788 } else {
1789 printk(KERN_ERR PFX "unable to obtain drv_info\n");
1790 rc = -ENODEV;
1791 goto nodev;
1792 }
1793
1794 printk(KERN_ERR PFX "phys_dev is netxtreme2 device\n");
1795
1796 /* obtain hba and initialize rest of the structure */
1797 hba = bnx2fc_hba_lookup(phys_dev);
1798 if (!hba || !hba->ctlr.lp) {
1799 rc = -ENODEV;
1800 printk(KERN_ERR PFX "bnx2fc_disable: hba or lport not found\n");
1801 } else {
1802 fcoe_ctlr_link_down(&hba->ctlr);
1803 fcoe_clean_pending_queue(hba->ctlr.lp);
1804 }
1805
1806nodev:
1807 mutex_unlock(&bnx2fc_dev_lock);
1808 rtnl_unlock();
1809 return rc;
1810}
1811
1812
1813static int bnx2fc_enable(struct net_device *netdev)
1814{
1815 struct bnx2fc_hba *hba;
1816 struct net_device *phys_dev;
1817 struct ethtool_drvinfo drvinfo;
1818 int rc = 0;
1819
Nithin Sujir6702ca12011-03-17 17:13:27 -07001820 rtnl_lock();
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001821
1822 BNX2FC_MISC_DBG("Entered %s\n", __func__);
1823 mutex_lock(&bnx2fc_dev_lock);
1824
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001825 /* obtain physical netdev */
1826 if (netdev->priv_flags & IFF_802_1Q_VLAN)
1827 phys_dev = vlan_dev_real_dev(netdev);
1828 else {
1829 printk(KERN_ERR PFX "Not a vlan device\n");
1830 rc = -ENODEV;
1831 goto nodev;
1832 }
1833 /* verify if the physical device is a netxtreme2 device */
1834 if (phys_dev->ethtool_ops && phys_dev->ethtool_ops->get_drvinfo) {
1835 memset(&drvinfo, 0, sizeof(drvinfo));
1836 phys_dev->ethtool_ops->get_drvinfo(phys_dev, &drvinfo);
1837 if (strcmp(drvinfo.driver, "bnx2x")) {
1838 printk(KERN_ERR PFX "Not a netxtreme2 device\n");
1839 rc = -ENODEV;
1840 goto nodev;
1841 }
1842 } else {
1843 printk(KERN_ERR PFX "unable to obtain drv_info\n");
1844 rc = -ENODEV;
1845 goto nodev;
1846 }
1847
1848 /* obtain hba and initialize rest of the structure */
1849 hba = bnx2fc_hba_lookup(phys_dev);
1850 if (!hba || !hba->ctlr.lp) {
1851 rc = -ENODEV;
1852 printk(KERN_ERR PFX "bnx2fc_enable: hba or lport not found\n");
1853 } else if (!bnx2fc_link_ok(hba->ctlr.lp))
1854 fcoe_ctlr_link_up(&hba->ctlr);
1855
1856nodev:
1857 mutex_unlock(&bnx2fc_dev_lock);
1858 rtnl_unlock();
1859 return rc;
1860}
1861
1862/**
1863 * bnx2fc_create - Create bnx2fc FCoE interface
1864 *
1865 * @buffer: The name of Ethernet interface to create on
1866 * @kp: The associated kernel param
1867 *
1868 * Called from sysfs.
1869 *
1870 * Returns: 0 for success
1871 */
1872static int bnx2fc_create(struct net_device *netdev, enum fip_state fip_mode)
1873{
1874 struct bnx2fc_hba *hba;
1875 struct net_device *phys_dev;
1876 struct fc_lport *lport;
1877 struct ethtool_drvinfo drvinfo;
1878 int rc = 0;
1879 int vlan_id;
1880
1881 BNX2FC_MISC_DBG("Entered bnx2fc_create\n");
1882 if (fip_mode != FIP_MODE_FABRIC) {
1883 printk(KERN_ERR "fip mode not FABRIC\n");
1884 return -EIO;
1885 }
1886
Nithin Sujir6702ca12011-03-17 17:13:27 -07001887 rtnl_lock();
1888
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001889 mutex_lock(&bnx2fc_dev_lock);
1890
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001891 if (!try_module_get(THIS_MODULE)) {
1892 rc = -EINVAL;
1893 goto mod_err;
1894 }
1895
1896 /* obtain physical netdev */
1897 if (netdev->priv_flags & IFF_802_1Q_VLAN) {
1898 phys_dev = vlan_dev_real_dev(netdev);
1899 vlan_id = vlan_dev_vlan_id(netdev);
1900 } else {
1901 printk(KERN_ERR PFX "Not a vlan device\n");
1902 rc = -EINVAL;
1903 goto netdev_err;
1904 }
1905 /* verify if the physical device is a netxtreme2 device */
1906 if (phys_dev->ethtool_ops && phys_dev->ethtool_ops->get_drvinfo) {
1907 memset(&drvinfo, 0, sizeof(drvinfo));
1908 phys_dev->ethtool_ops->get_drvinfo(phys_dev, &drvinfo);
1909 if (strcmp(drvinfo.driver, "bnx2x")) {
1910 printk(KERN_ERR PFX "Not a netxtreme2 device\n");
1911 rc = -EINVAL;
1912 goto netdev_err;
1913 }
1914 } else {
1915 printk(KERN_ERR PFX "unable to obtain drv_info\n");
1916 rc = -EINVAL;
1917 goto netdev_err;
1918 }
1919
1920 /* obtain hba and initialize rest of the structure */
1921 hba = bnx2fc_hba_lookup(phys_dev);
1922 if (!hba) {
1923 rc = -ENODEV;
1924 printk(KERN_ERR PFX "bnx2fc_create: hba not found\n");
1925 goto netdev_err;
1926 }
1927
1928 if (!test_bit(BNX2FC_FW_INIT_DONE, &hba->init_done)) {
1929 rc = bnx2fc_fw_init(hba);
1930 if (rc)
1931 goto netdev_err;
1932 }
1933
1934 if (test_bit(BNX2FC_CREATE_DONE, &hba->init_done)) {
1935 rc = -EEXIST;
1936 goto netdev_err;
1937 }
1938
1939 /* update netdev with vlan netdev */
1940 hba->netdev = netdev;
1941 hba->vlan_id = vlan_id;
1942 hba->vlan_enabled = 1;
1943
1944 rc = bnx2fc_interface_setup(hba, fip_mode);
1945 if (rc) {
1946 printk(KERN_ERR PFX "bnx2fc_interface_setup failed\n");
1947 goto ifput_err;
1948 }
1949
1950 hba->timer_work_queue =
1951 create_singlethread_workqueue("bnx2fc_timer_wq");
1952 if (!hba->timer_work_queue) {
1953 printk(KERN_ERR PFX "ulp_init could not create timer_wq\n");
1954 rc = -EINVAL;
1955 goto ifput_err;
1956 }
1957
1958 lport = bnx2fc_if_create(hba, &hba->pcidev->dev, 0);
1959 if (!lport) {
1960 printk(KERN_ERR PFX "Failed to create interface (%s)\n",
1961 netdev->name);
1962 bnx2fc_netdev_cleanup(hba);
1963 rc = -EINVAL;
1964 goto if_create_err;
1965 }
1966
1967 lport->boot_time = jiffies;
1968
1969 /* Make this master N_port */
1970 hba->ctlr.lp = lport;
1971
1972 set_bit(BNX2FC_CREATE_DONE, &hba->init_done);
1973 printk(KERN_ERR PFX "create: START DISC\n");
1974 bnx2fc_start_disc(hba);
1975 /*
1976 * Release from kref_init in bnx2fc_interface_setup, on success
1977 * lport should be holding a reference taken in bnx2fc_if_create
1978 */
1979 bnx2fc_interface_put(hba);
1980 /* put netdev that was held while calling dev_get_by_name */
1981 mutex_unlock(&bnx2fc_dev_lock);
1982 rtnl_unlock();
1983 return 0;
1984
1985if_create_err:
1986 destroy_workqueue(hba->timer_work_queue);
1987ifput_err:
1988 bnx2fc_interface_put(hba);
1989netdev_err:
1990 module_put(THIS_MODULE);
1991mod_err:
1992 mutex_unlock(&bnx2fc_dev_lock);
1993 rtnl_unlock();
1994 return rc;
1995}
1996
1997/**
1998 * bnx2fc_find_hba_for_cnic - maps cnic instance to bnx2fc adapter instance
1999 *
2000 * @cnic: Pointer to cnic device instance
2001 *
2002 **/
2003static struct bnx2fc_hba *bnx2fc_find_hba_for_cnic(struct cnic_dev *cnic)
2004{
2005 struct list_head *list;
2006 struct list_head *temp;
2007 struct bnx2fc_hba *hba;
2008
2009 /* Called with bnx2fc_dev_lock held */
2010 list_for_each_safe(list, temp, &adapter_list) {
2011 hba = (struct bnx2fc_hba *)list;
2012 if (hba->cnic == cnic)
2013 return hba;
2014 }
2015 return NULL;
2016}
2017
2018static struct bnx2fc_hba *bnx2fc_hba_lookup(struct net_device *phys_dev)
2019{
2020 struct list_head *list;
2021 struct list_head *temp;
2022 struct bnx2fc_hba *hba;
2023
2024 /* Called with bnx2fc_dev_lock held */
2025 list_for_each_safe(list, temp, &adapter_list) {
2026 hba = (struct bnx2fc_hba *)list;
2027 if (hba->phys_dev == phys_dev)
2028 return hba;
2029 }
2030 printk(KERN_ERR PFX "hba_lookup: hba NULL\n");
2031 return NULL;
2032}
2033
2034/**
2035 * bnx2fc_ulp_exit - shuts down adapter instance and frees all resources
2036 *
2037 * @dev cnic device handle
2038 */
2039static void bnx2fc_ulp_exit(struct cnic_dev *dev)
2040{
2041 struct bnx2fc_hba *hba;
2042
2043 BNX2FC_MISC_DBG("Entered bnx2fc_ulp_exit\n");
2044
2045 if (!test_bit(CNIC_F_BNX2X_CLASS, &dev->flags)) {
2046 printk(KERN_ERR PFX "bnx2fc port check: %s, flags: %lx\n",
2047 dev->netdev->name, dev->flags);
2048 return;
2049 }
2050
2051 mutex_lock(&bnx2fc_dev_lock);
2052 hba = bnx2fc_find_hba_for_cnic(dev);
2053 if (!hba) {
2054 printk(KERN_ERR PFX "bnx2fc_ulp_exit: hba not found, dev 0%p\n",
2055 dev);
2056 mutex_unlock(&bnx2fc_dev_lock);
2057 return;
2058 }
2059
2060 list_del_init(&hba->link);
2061 adapter_count--;
2062
2063 if (test_bit(BNX2FC_CREATE_DONE, &hba->init_done)) {
2064 /* destroy not called yet, move to quiesced list */
2065 bnx2fc_netdev_cleanup(hba);
2066 bnx2fc_if_destroy(hba->ctlr.lp);
2067 }
2068 mutex_unlock(&bnx2fc_dev_lock);
2069
2070 bnx2fc_ulp_stop(hba);
2071 /* unregister cnic device */
2072 if (test_and_clear_bit(BNX2FC_CNIC_REGISTERED, &hba->reg_with_cnic))
2073 hba->cnic->unregister_device(hba->cnic, CNIC_ULP_FCOE);
2074 bnx2fc_interface_destroy(hba);
2075}
2076
2077/**
2078 * bnx2fc_fcoe_reset - Resets the fcoe
2079 *
2080 * @shost: shost the reset is from
2081 *
2082 * Returns: always 0
2083 */
2084static int bnx2fc_fcoe_reset(struct Scsi_Host *shost)
2085{
2086 struct fc_lport *lport = shost_priv(shost);
2087 fc_lport_reset(lport);
2088 return 0;
2089}
2090
2091
2092static bool bnx2fc_match(struct net_device *netdev)
2093{
2094 mutex_lock(&bnx2fc_dev_lock);
2095 if (netdev->priv_flags & IFF_802_1Q_VLAN) {
2096 struct net_device *phys_dev = vlan_dev_real_dev(netdev);
2097
2098 if (bnx2fc_hba_lookup(phys_dev)) {
2099 mutex_unlock(&bnx2fc_dev_lock);
2100 return true;
2101 }
2102 }
2103 mutex_unlock(&bnx2fc_dev_lock);
2104 return false;
2105}
2106
2107
2108static struct fcoe_transport bnx2fc_transport = {
2109 .name = {"bnx2fc"},
2110 .attached = false,
2111 .list = LIST_HEAD_INIT(bnx2fc_transport.list),
2112 .match = bnx2fc_match,
2113 .create = bnx2fc_create,
2114 .destroy = bnx2fc_destroy,
2115 .enable = bnx2fc_enable,
2116 .disable = bnx2fc_disable,
2117};
2118
2119/**
2120 * bnx2fc_percpu_thread_create - Create a receive thread for an
2121 * online CPU
2122 *
2123 * @cpu: cpu index for the online cpu
2124 */
2125static void bnx2fc_percpu_thread_create(unsigned int cpu)
2126{
2127 struct bnx2fc_percpu_s *p;
2128 struct task_struct *thread;
2129
2130 p = &per_cpu(bnx2fc_percpu, cpu);
2131
2132 thread = kthread_create(bnx2fc_percpu_io_thread,
2133 (void *)p,
2134 "bnx2fc_thread/%d", cpu);
2135 /* bind thread to the cpu */
2136 if (likely(!IS_ERR(p->iothread))) {
2137 kthread_bind(thread, cpu);
2138 p->iothread = thread;
2139 wake_up_process(thread);
2140 }
2141}
2142
2143static void bnx2fc_percpu_thread_destroy(unsigned int cpu)
2144{
2145 struct bnx2fc_percpu_s *p;
2146 struct task_struct *thread;
2147 struct bnx2fc_work *work, *tmp;
2148 LIST_HEAD(work_list);
2149
2150 BNX2FC_MISC_DBG("destroying io thread for CPU %d\n", cpu);
2151
2152 /* Prevent any new work from being queued for this CPU */
2153 p = &per_cpu(bnx2fc_percpu, cpu);
2154 spin_lock_bh(&p->fp_work_lock);
2155 thread = p->iothread;
2156 p->iothread = NULL;
2157
2158
2159 /* Free all work in the list */
2160 list_for_each_entry_safe(work, tmp, &work_list, list) {
2161 list_del_init(&work->list);
2162 bnx2fc_process_cq_compl(work->tgt, work->wqe);
2163 kfree(work);
2164 }
2165
2166 spin_unlock_bh(&p->fp_work_lock);
2167
2168 if (thread)
2169 kthread_stop(thread);
2170}
2171
2172/**
2173 * bnx2fc_cpu_callback - Handler for CPU hotplug events
2174 *
2175 * @nfb: The callback data block
2176 * @action: The event triggering the callback
2177 * @hcpu: The index of the CPU that the event is for
2178 *
2179 * This creates or destroys per-CPU data for fcoe
2180 *
2181 * Returns NOTIFY_OK always.
2182 */
2183static int bnx2fc_cpu_callback(struct notifier_block *nfb,
2184 unsigned long action, void *hcpu)
2185{
2186 unsigned cpu = (unsigned long)hcpu;
2187
2188 switch (action) {
2189 case CPU_ONLINE:
2190 case CPU_ONLINE_FROZEN:
2191 printk(PFX "CPU %x online: Create Rx thread\n", cpu);
2192 bnx2fc_percpu_thread_create(cpu);
2193 break;
2194 case CPU_DEAD:
2195 case CPU_DEAD_FROZEN:
2196 printk(PFX "CPU %x offline: Remove Rx thread\n", cpu);
2197 bnx2fc_percpu_thread_destroy(cpu);
2198 break;
2199 default:
2200 break;
2201 }
2202 return NOTIFY_OK;
2203}
2204
2205/**
2206 * bnx2fc_mod_init - module init entry point
2207 *
2208 * Initialize driver wide global data structures, and register
2209 * with cnic module
2210 **/
2211static int __init bnx2fc_mod_init(void)
2212{
2213 struct fcoe_percpu_s *bg;
2214 struct task_struct *l2_thread;
2215 int rc = 0;
2216 unsigned int cpu = 0;
2217 struct bnx2fc_percpu_s *p;
2218
2219 printk(KERN_INFO PFX "%s", version);
2220
2221 /* register as a fcoe transport */
2222 rc = fcoe_transport_attach(&bnx2fc_transport);
2223 if (rc) {
2224 printk(KERN_ERR "failed to register an fcoe transport, check "
2225 "if libfcoe is loaded\n");
2226 goto out;
2227 }
2228
2229 INIT_LIST_HEAD(&adapter_list);
2230 mutex_init(&bnx2fc_dev_lock);
2231 adapter_count = 0;
2232
2233 /* Attach FC transport template */
2234 rc = bnx2fc_attach_transport();
2235 if (rc)
2236 goto detach_ft;
2237
2238 bnx2fc_wq = alloc_workqueue("bnx2fc", 0, 0);
2239 if (!bnx2fc_wq) {
2240 rc = -ENOMEM;
2241 goto release_bt;
2242 }
2243
2244 bg = &bnx2fc_global;
2245 skb_queue_head_init(&bg->fcoe_rx_list);
2246 l2_thread = kthread_create(bnx2fc_l2_rcv_thread,
2247 (void *)bg,
2248 "bnx2fc_l2_thread");
2249 if (IS_ERR(l2_thread)) {
2250 rc = PTR_ERR(l2_thread);
2251 goto free_wq;
2252 }
2253 wake_up_process(l2_thread);
2254 spin_lock_bh(&bg->fcoe_rx_list.lock);
2255 bg->thread = l2_thread;
2256 spin_unlock_bh(&bg->fcoe_rx_list.lock);
2257
2258 for_each_possible_cpu(cpu) {
2259 p = &per_cpu(bnx2fc_percpu, cpu);
2260 INIT_LIST_HEAD(&p->work_list);
2261 spin_lock_init(&p->fp_work_lock);
2262 }
2263
2264 for_each_online_cpu(cpu) {
2265 bnx2fc_percpu_thread_create(cpu);
2266 }
2267
2268 /* Initialize per CPU interrupt thread */
2269 register_hotcpu_notifier(&bnx2fc_cpu_notifier);
2270
2271 cnic_register_driver(CNIC_ULP_FCOE, &bnx2fc_cnic_cb);
2272
2273 return 0;
2274
2275free_wq:
2276 destroy_workqueue(bnx2fc_wq);
2277release_bt:
2278 bnx2fc_release_transport();
2279detach_ft:
2280 fcoe_transport_detach(&bnx2fc_transport);
2281out:
2282 return rc;
2283}
2284
2285static void __exit bnx2fc_mod_exit(void)
2286{
2287 LIST_HEAD(to_be_deleted);
2288 struct bnx2fc_hba *hba, *next;
2289 struct fcoe_percpu_s *bg;
2290 struct task_struct *l2_thread;
2291 struct sk_buff *skb;
2292 unsigned int cpu = 0;
2293
2294 /*
2295 * NOTE: Since cnic calls register_driver routine rtnl_lock,
2296 * it will have higher precedence than bnx2fc_dev_lock.
2297 * unregister_device() cannot be called with bnx2fc_dev_lock
2298 * held.
2299 */
2300 mutex_lock(&bnx2fc_dev_lock);
2301 list_splice(&adapter_list, &to_be_deleted);
2302 INIT_LIST_HEAD(&adapter_list);
2303 adapter_count = 0;
2304 mutex_unlock(&bnx2fc_dev_lock);
2305
2306 /* Unregister with cnic */
2307 list_for_each_entry_safe(hba, next, &to_be_deleted, link) {
2308 list_del_init(&hba->link);
2309 printk(KERN_ERR PFX "MOD_EXIT:destroy hba = 0x%p, kref = %d\n",
2310 hba, atomic_read(&hba->kref.refcount));
2311 bnx2fc_ulp_stop(hba);
2312 /* unregister cnic device */
2313 if (test_and_clear_bit(BNX2FC_CNIC_REGISTERED,
2314 &hba->reg_with_cnic))
2315 hba->cnic->unregister_device(hba->cnic, CNIC_ULP_FCOE);
2316 bnx2fc_interface_destroy(hba);
2317 }
2318 cnic_unregister_driver(CNIC_ULP_FCOE);
2319
2320 /* Destroy global thread */
2321 bg = &bnx2fc_global;
2322 spin_lock_bh(&bg->fcoe_rx_list.lock);
2323 l2_thread = bg->thread;
2324 bg->thread = NULL;
2325 while ((skb = __skb_dequeue(&bg->fcoe_rx_list)) != NULL)
2326 kfree_skb(skb);
2327
2328 spin_unlock_bh(&bg->fcoe_rx_list.lock);
2329
2330 if (l2_thread)
2331 kthread_stop(l2_thread);
2332
2333 unregister_hotcpu_notifier(&bnx2fc_cpu_notifier);
2334
2335 /* Destroy per cpu threads */
2336 for_each_online_cpu(cpu) {
2337 bnx2fc_percpu_thread_destroy(cpu);
2338 }
2339
2340 destroy_workqueue(bnx2fc_wq);
2341 /*
2342 * detach from scsi transport
2343 * must happen after all destroys are done
2344 */
2345 bnx2fc_release_transport();
2346
2347 /* detach from fcoe transport */
2348 fcoe_transport_detach(&bnx2fc_transport);
2349}
2350
2351module_init(bnx2fc_mod_init);
2352module_exit(bnx2fc_mod_exit);
2353
2354static struct fc_function_template bnx2fc_transport_function = {
2355 .show_host_node_name = 1,
2356 .show_host_port_name = 1,
2357 .show_host_supported_classes = 1,
2358 .show_host_supported_fc4s = 1,
2359 .show_host_active_fc4s = 1,
2360 .show_host_maxframe_size = 1,
2361
2362 .show_host_port_id = 1,
2363 .show_host_supported_speeds = 1,
2364 .get_host_speed = fc_get_host_speed,
2365 .show_host_speed = 1,
2366 .show_host_port_type = 1,
2367 .get_host_port_state = fc_get_host_port_state,
2368 .show_host_port_state = 1,
2369 .show_host_symbolic_name = 1,
2370
2371 .dd_fcrport_size = (sizeof(struct fc_rport_libfc_priv) +
2372 sizeof(struct bnx2fc_rport)),
2373 .show_rport_maxframe_size = 1,
2374 .show_rport_supported_classes = 1,
2375
2376 .show_host_fabric_name = 1,
2377 .show_starget_node_name = 1,
2378 .show_starget_port_name = 1,
2379 .show_starget_port_id = 1,
2380 .set_rport_dev_loss_tmo = fc_set_rport_loss_tmo,
2381 .show_rport_dev_loss_tmo = 1,
2382 .get_fc_host_stats = bnx2fc_get_host_stats,
2383
2384 .issue_fc_host_lip = bnx2fc_fcoe_reset,
2385
2386 .terminate_rport_io = fc_rport_terminate_io,
2387
2388 .vport_create = bnx2fc_vport_create,
2389 .vport_delete = bnx2fc_vport_destroy,
2390 .vport_disable = bnx2fc_vport_disable,
2391};
2392
2393static struct fc_function_template bnx2fc_vport_xport_function = {
2394 .show_host_node_name = 1,
2395 .show_host_port_name = 1,
2396 .show_host_supported_classes = 1,
2397 .show_host_supported_fc4s = 1,
2398 .show_host_active_fc4s = 1,
2399 .show_host_maxframe_size = 1,
2400
2401 .show_host_port_id = 1,
2402 .show_host_supported_speeds = 1,
2403 .get_host_speed = fc_get_host_speed,
2404 .show_host_speed = 1,
2405 .show_host_port_type = 1,
2406 .get_host_port_state = fc_get_host_port_state,
2407 .show_host_port_state = 1,
2408 .show_host_symbolic_name = 1,
2409
2410 .dd_fcrport_size = (sizeof(struct fc_rport_libfc_priv) +
2411 sizeof(struct bnx2fc_rport)),
2412 .show_rport_maxframe_size = 1,
2413 .show_rport_supported_classes = 1,
2414
2415 .show_host_fabric_name = 1,
2416 .show_starget_node_name = 1,
2417 .show_starget_port_name = 1,
2418 .show_starget_port_id = 1,
2419 .set_rport_dev_loss_tmo = fc_set_rport_loss_tmo,
2420 .show_rport_dev_loss_tmo = 1,
2421 .get_fc_host_stats = fc_get_host_stats,
2422 .issue_fc_host_lip = bnx2fc_fcoe_reset,
2423 .terminate_rport_io = fc_rport_terminate_io,
2424};
2425
2426/**
2427 * scsi_host_template structure used while registering with SCSI-ml
2428 */
2429static struct scsi_host_template bnx2fc_shost_template = {
2430 .module = THIS_MODULE,
2431 .name = "Broadcom Offload FCoE Initiator",
2432 .queuecommand = bnx2fc_queuecommand,
2433 .eh_abort_handler = bnx2fc_eh_abort, /* abts */
2434 .eh_device_reset_handler = bnx2fc_eh_device_reset, /* lun reset */
2435 .eh_target_reset_handler = bnx2fc_eh_target_reset, /* tgt reset */
2436 .eh_host_reset_handler = fc_eh_host_reset,
2437 .slave_alloc = fc_slave_alloc,
2438 .change_queue_depth = fc_change_queue_depth,
2439 .change_queue_type = fc_change_queue_type,
2440 .this_id = -1,
2441 .cmd_per_lun = 3,
Bhanu Gollapudi0ea5c272011-03-17 17:13:29 -07002442 .can_queue = BNX2FC_CAN_QUEUE,
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002443 .use_clustering = ENABLE_CLUSTERING,
2444 .sg_tablesize = BNX2FC_MAX_BDS_PER_CMD,
2445 .max_sectors = 512,
2446};
2447
2448static struct libfc_function_template bnx2fc_libfc_fcn_templ = {
2449 .frame_send = bnx2fc_xmit,
2450 .elsct_send = bnx2fc_elsct_send,
2451 .fcp_abort_io = bnx2fc_abort_io,
2452 .fcp_cleanup = bnx2fc_cleanup,
2453 .rport_event_callback = bnx2fc_rport_event_handler,
2454};
2455
2456/**
2457 * bnx2fc_cnic_cb - global template of bnx2fc - cnic driver interface
2458 * structure carrying callback function pointers
2459 */
2460static struct cnic_ulp_ops bnx2fc_cnic_cb = {
2461 .owner = THIS_MODULE,
2462 .cnic_init = bnx2fc_ulp_init,
2463 .cnic_exit = bnx2fc_ulp_exit,
2464 .cnic_start = bnx2fc_ulp_start,
2465 .cnic_stop = bnx2fc_ulp_stop,
2466 .indicate_kcqes = bnx2fc_indicate_kcqe,
2467 .indicate_netevent = bnx2fc_indicate_netevent,
2468};