blob: 65561fcaad03c4016502273dd6129ec75ecbe5d0 [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;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -070018static struct list_head if_list;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -080019static u32 adapter_count;
20static DEFINE_MUTEX(bnx2fc_dev_lock);
21DEFINE_PER_CPU(struct bnx2fc_percpu_s, bnx2fc_percpu);
22
23#define DRV_MODULE_NAME "bnx2fc"
24#define DRV_MODULE_VERSION BNX2FC_VERSION
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030025#define DRV_MODULE_RELDATE "Jun 10, 2011"
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -080026
27
28static char version[] __devinitdata =
29 "Broadcom NetXtreme II FCoE Driver " DRV_MODULE_NAME \
30 " v" DRV_MODULE_VERSION " (" DRV_MODULE_RELDATE ")\n";
31
32
33MODULE_AUTHOR("Bhanu Prakash Gollapudi <bprakash@broadcom.com>");
34MODULE_DESCRIPTION("Broadcom NetXtreme II BCM57710 FCoE Driver");
35MODULE_LICENSE("GPL");
36MODULE_VERSION(DRV_MODULE_VERSION);
37
38#define BNX2FC_MAX_QUEUE_DEPTH 256
39#define BNX2FC_MIN_QUEUE_DEPTH 32
40#define FCOE_WORD_TO_BYTE 4
41
42static struct scsi_transport_template *bnx2fc_transport_template;
43static struct scsi_transport_template *bnx2fc_vport_xport_template;
44
45struct workqueue_struct *bnx2fc_wq;
46
47/* bnx2fc structure needs only one instance of the fcoe_percpu_s structure.
48 * Here the io threads are per cpu but the l2 thread is just one
49 */
50struct fcoe_percpu_s bnx2fc_global;
51DEFINE_SPINLOCK(bnx2fc_global_lock);
52
53static struct cnic_ulp_ops bnx2fc_cnic_cb;
54static struct libfc_function_template bnx2fc_libfc_fcn_templ;
55static struct scsi_host_template bnx2fc_shost_template;
56static struct fc_function_template bnx2fc_transport_function;
57static struct fc_function_template bnx2fc_vport_xport_function;
58static int bnx2fc_create(struct net_device *netdev, enum fip_state fip_mode);
59static int bnx2fc_destroy(struct net_device *net_device);
60static int bnx2fc_enable(struct net_device *netdev);
61static int bnx2fc_disable(struct net_device *netdev);
62
63static void bnx2fc_recv_frame(struct sk_buff *skb);
64
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -070065static void bnx2fc_start_disc(struct bnx2fc_interface *interface);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -080066static int bnx2fc_shost_config(struct fc_lport *lport, struct device *dev);
67static int bnx2fc_net_config(struct fc_lport *lp);
68static int bnx2fc_lport_config(struct fc_lport *lport);
69static int bnx2fc_em_config(struct fc_lport *lport);
70static int bnx2fc_bind_adapter_devices(struct bnx2fc_hba *hba);
71static void bnx2fc_unbind_adapter_devices(struct bnx2fc_hba *hba);
72static int bnx2fc_bind_pcidev(struct bnx2fc_hba *hba);
73static void bnx2fc_unbind_pcidev(struct bnx2fc_hba *hba);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -070074static struct fc_lport *bnx2fc_if_create(struct bnx2fc_interface *interface,
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -080075 struct device *parent, int npiv);
76static void bnx2fc_destroy_work(struct work_struct *work);
77
78static struct bnx2fc_hba *bnx2fc_hba_lookup(struct net_device *phys_dev);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -070079static struct bnx2fc_interface *bnx2fc_interface_lookup(struct net_device
80 *phys_dev);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -080081static struct bnx2fc_hba *bnx2fc_find_hba_for_cnic(struct cnic_dev *cnic);
82
83static int bnx2fc_fw_init(struct bnx2fc_hba *hba);
84static void bnx2fc_fw_destroy(struct bnx2fc_hba *hba);
85
86static void bnx2fc_port_shutdown(struct fc_lport *lport);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -070087static void bnx2fc_stop(struct bnx2fc_interface *interface);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -080088static int __init bnx2fc_mod_init(void);
89static void __exit bnx2fc_mod_exit(void);
90
91unsigned int bnx2fc_debug_level;
92module_param_named(debug_logging, bnx2fc_debug_level, int, S_IRUGO|S_IWUSR);
93
94static int bnx2fc_cpu_callback(struct notifier_block *nfb,
95 unsigned long action, void *hcpu);
96/* notification function for CPU hotplug events */
97static struct notifier_block bnx2fc_cpu_notifier = {
98 .notifier_call = bnx2fc_cpu_callback,
99};
100
101static void bnx2fc_clean_rx_queue(struct fc_lport *lp)
102{
103 struct fcoe_percpu_s *bg;
104 struct fcoe_rcv_info *fr;
105 struct sk_buff_head *list;
106 struct sk_buff *skb, *next;
107 struct sk_buff *head;
108
109 bg = &bnx2fc_global;
110 spin_lock_bh(&bg->fcoe_rx_list.lock);
111 list = &bg->fcoe_rx_list;
112 head = list->next;
113 for (skb = head; skb != (struct sk_buff *)list;
114 skb = next) {
115 next = skb->next;
116 fr = fcoe_dev_from_skb(skb);
117 if (fr->fr_dev == lp) {
118 __skb_unlink(skb, list);
119 kfree_skb(skb);
120 }
121 }
122 spin_unlock_bh(&bg->fcoe_rx_list.lock);
123}
124
125int bnx2fc_get_paged_crc_eof(struct sk_buff *skb, int tlen)
126{
127 int rc;
128 spin_lock(&bnx2fc_global_lock);
129 rc = fcoe_get_paged_crc_eof(skb, tlen, &bnx2fc_global);
130 spin_unlock(&bnx2fc_global_lock);
131
132 return rc;
133}
134
135static void bnx2fc_abort_io(struct fc_lport *lport)
136{
137 /*
138 * This function is no-op for bnx2fc, but we do
139 * not want to leave it as NULL either, as libfc
140 * can call the default function which is
141 * fc_fcp_abort_io.
142 */
143}
144
145static void bnx2fc_cleanup(struct fc_lport *lport)
146{
147 struct fcoe_port *port = lport_priv(lport);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700148 struct bnx2fc_interface *interface = port->priv;
149 struct bnx2fc_hba *hba = interface->hba;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800150 struct bnx2fc_rport *tgt;
151 int i;
152
153 BNX2FC_MISC_DBG("Entered %s\n", __func__);
154 mutex_lock(&hba->hba_mutex);
155 spin_lock_bh(&hba->hba_lock);
156 for (i = 0; i < BNX2FC_NUM_MAX_SESS; i++) {
157 tgt = hba->tgt_ofld_list[i];
158 if (tgt) {
159 /* Cleanup IOs belonging to requested vport */
160 if (tgt->port == port) {
161 spin_unlock_bh(&hba->hba_lock);
162 BNX2FC_TGT_DBG(tgt, "flush/cleanup\n");
163 bnx2fc_flush_active_ios(tgt);
164 spin_lock_bh(&hba->hba_lock);
165 }
166 }
167 }
168 spin_unlock_bh(&hba->hba_lock);
169 mutex_unlock(&hba->hba_mutex);
170}
171
172static int bnx2fc_xmit_l2_frame(struct bnx2fc_rport *tgt,
173 struct fc_frame *fp)
174{
175 struct fc_rport_priv *rdata = tgt->rdata;
176 struct fc_frame_header *fh;
177 int rc = 0;
178
179 fh = fc_frame_header_get(fp);
180 BNX2FC_TGT_DBG(tgt, "Xmit L2 frame rport = 0x%x, oxid = 0x%x, "
181 "r_ctl = 0x%x\n", rdata->ids.port_id,
182 ntohs(fh->fh_ox_id), fh->fh_r_ctl);
183 if ((fh->fh_type == FC_TYPE_ELS) &&
184 (fh->fh_r_ctl == FC_RCTL_ELS_REQ)) {
185
186 switch (fc_frame_payload_op(fp)) {
187 case ELS_ADISC:
188 rc = bnx2fc_send_adisc(tgt, fp);
189 break;
190 case ELS_LOGO:
191 rc = bnx2fc_send_logo(tgt, fp);
192 break;
193 case ELS_RLS:
194 rc = bnx2fc_send_rls(tgt, fp);
195 break;
196 default:
197 break;
198 }
199 } else if ((fh->fh_type == FC_TYPE_BLS) &&
200 (fh->fh_r_ctl == FC_RCTL_BA_ABTS))
201 BNX2FC_TGT_DBG(tgt, "ABTS frame\n");
202 else {
203 BNX2FC_TGT_DBG(tgt, "Send L2 frame type 0x%x "
204 "rctl 0x%x thru non-offload path\n",
205 fh->fh_type, fh->fh_r_ctl);
206 return -ENODEV;
207 }
208 if (rc)
209 return -ENOMEM;
210 else
211 return 0;
212}
213
214/**
215 * bnx2fc_xmit - bnx2fc's FCoE frame transmit function
216 *
217 * @lport: the associated local port
218 * @fp: the fc_frame to be transmitted
219 */
220static int bnx2fc_xmit(struct fc_lport *lport, struct fc_frame *fp)
221{
222 struct ethhdr *eh;
223 struct fcoe_crc_eof *cp;
224 struct sk_buff *skb;
225 struct fc_frame_header *fh;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700226 struct bnx2fc_interface *interface;
227 struct bnx2fc_hba *hba;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800228 struct fcoe_port *port;
229 struct fcoe_hdr *hp;
230 struct bnx2fc_rport *tgt;
231 struct fcoe_dev_stats *stats;
232 u8 sof, eof;
233 u32 crc;
234 unsigned int hlen, tlen, elen;
235 int wlen, rc = 0;
236
237 port = (struct fcoe_port *)lport_priv(lport);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700238 interface = port->priv;
239 hba = interface->hba;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800240
241 fh = fc_frame_header_get(fp);
242
243 skb = fp_skb(fp);
244 if (!lport->link_up) {
245 BNX2FC_HBA_DBG(lport, "bnx2fc_xmit link down\n");
246 kfree_skb(skb);
247 return 0;
248 }
249
250 if (unlikely(fh->fh_r_ctl == FC_RCTL_ELS_REQ)) {
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700251 if (!interface->ctlr.sel_fcf) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800252 BNX2FC_HBA_DBG(lport, "FCF not selected yet!\n");
253 kfree_skb(skb);
254 return -EINVAL;
255 }
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700256 if (fcoe_ctlr_els_send(&interface->ctlr, lport, skb))
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800257 return 0;
258 }
259
260 sof = fr_sof(fp);
261 eof = fr_eof(fp);
262
263 /*
264 * Snoop the frame header to check if the frame is for
265 * an offloaded session
266 */
267 /*
268 * tgt_ofld_list access is synchronized using
269 * both hba mutex and hba lock. Atleast hba mutex or
270 * hba lock needs to be held for read access.
271 */
272
273 spin_lock_bh(&hba->hba_lock);
274 tgt = bnx2fc_tgt_lookup(port, ntoh24(fh->fh_d_id));
275 if (tgt && (test_bit(BNX2FC_FLAG_SESSION_READY, &tgt->flags))) {
276 /* This frame is for offloaded session */
277 BNX2FC_HBA_DBG(lport, "xmit: Frame is for offloaded session "
278 "port_id = 0x%x\n", ntoh24(fh->fh_d_id));
279 spin_unlock_bh(&hba->hba_lock);
280 rc = bnx2fc_xmit_l2_frame(tgt, fp);
281 if (rc != -ENODEV) {
282 kfree_skb(skb);
283 return rc;
284 }
285 } else {
286 spin_unlock_bh(&hba->hba_lock);
287 }
288
289 elen = sizeof(struct ethhdr);
290 hlen = sizeof(struct fcoe_hdr);
291 tlen = sizeof(struct fcoe_crc_eof);
292 wlen = (skb->len - tlen + sizeof(crc)) / FCOE_WORD_TO_BYTE;
293
294 skb->ip_summed = CHECKSUM_NONE;
295 crc = fcoe_fc_crc(fp);
296
297 /* copy port crc and eof to the skb buff */
298 if (skb_is_nonlinear(skb)) {
299 skb_frag_t *frag;
300 if (bnx2fc_get_paged_crc_eof(skb, tlen)) {
301 kfree_skb(skb);
302 return -ENOMEM;
303 }
304 frag = &skb_shinfo(skb)->frags[skb_shinfo(skb)->nr_frags - 1];
305 cp = kmap_atomic(frag->page, KM_SKB_DATA_SOFTIRQ)
306 + frag->page_offset;
307 } else {
308 cp = (struct fcoe_crc_eof *)skb_put(skb, tlen);
309 }
310
311 memset(cp, 0, sizeof(*cp));
312 cp->fcoe_eof = eof;
313 cp->fcoe_crc32 = cpu_to_le32(~crc);
314 if (skb_is_nonlinear(skb)) {
315 kunmap_atomic(cp, KM_SKB_DATA_SOFTIRQ);
316 cp = NULL;
317 }
318
319 /* adjust skb network/transport offsets to match mac/fcoe/port */
320 skb_push(skb, elen + hlen);
321 skb_reset_mac_header(skb);
322 skb_reset_network_header(skb);
323 skb->mac_len = elen;
324 skb->protocol = htons(ETH_P_FCOE);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700325 skb->dev = interface->netdev;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800326
327 /* fill up mac and fcoe headers */
328 eh = eth_hdr(skb);
329 eh->h_proto = htons(ETH_P_FCOE);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700330 if (interface->ctlr.map_dest)
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800331 fc_fcoe_set_mac(eh->h_dest, fh->fh_d_id);
332 else
333 /* insert GW address */
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700334 memcpy(eh->h_dest, interface->ctlr.dest_addr, ETH_ALEN);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800335
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700336 if (unlikely(interface->ctlr.flogi_oxid != FC_XID_UNKNOWN))
337 memcpy(eh->h_source, interface->ctlr.ctl_src_addr, ETH_ALEN);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800338 else
339 memcpy(eh->h_source, port->data_src_addr, ETH_ALEN);
340
341 hp = (struct fcoe_hdr *)(eh + 1);
342 memset(hp, 0, sizeof(*hp));
343 if (FC_FCOE_VER)
344 FC_FCOE_ENCAPS_VER(hp, FC_FCOE_VER);
345 hp->fcoe_sof = sof;
346
347 /* fcoe lso, mss is in max_payload which is non-zero for FCP data */
348 if (lport->seq_offload && fr_max_payload(fp)) {
349 skb_shinfo(skb)->gso_type = SKB_GSO_FCOE;
350 skb_shinfo(skb)->gso_size = fr_max_payload(fp);
351 } else {
352 skb_shinfo(skb)->gso_type = 0;
353 skb_shinfo(skb)->gso_size = 0;
354 }
355
356 /*update tx stats */
357 stats = per_cpu_ptr(lport->dev_stats, get_cpu());
358 stats->TxFrames++;
359 stats->TxWords += wlen;
360 put_cpu();
361
362 /* send down to lld */
363 fr_dev(fp) = lport;
364 if (port->fcoe_pending_queue.qlen)
365 fcoe_check_wait_queue(lport, skb);
366 else if (fcoe_start_io(skb))
367 fcoe_check_wait_queue(lport, skb);
368
369 return 0;
370}
371
372/**
373 * bnx2fc_rcv - This is bnx2fc's receive function called by NET_RX_SOFTIRQ
374 *
375 * @skb: the receive socket buffer
376 * @dev: associated net device
377 * @ptype: context
378 * @olddev: last device
379 *
380 * This function receives the packet and builds FC frame and passes it up
381 */
382static int bnx2fc_rcv(struct sk_buff *skb, struct net_device *dev,
383 struct packet_type *ptype, struct net_device *olddev)
384{
385 struct fc_lport *lport;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700386 struct bnx2fc_interface *interface;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800387 struct fc_frame_header *fh;
388 struct fcoe_rcv_info *fr;
389 struct fcoe_percpu_s *bg;
390 unsigned short oxid;
391
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700392 interface = container_of(ptype, struct bnx2fc_interface,
393 fcoe_packet_type);
394 lport = interface->ctlr.lp;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800395
396 if (unlikely(lport == NULL)) {
Bhanu Prakash Gollapudib2a554f2011-06-27 23:30:53 -0700397 printk(KERN_ERR PFX "bnx2fc_rcv: lport is NULL\n");
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800398 goto err;
399 }
400
401 if (unlikely(eth_hdr(skb)->h_proto != htons(ETH_P_FCOE))) {
Bhanu Prakash Gollapudib2a554f2011-06-27 23:30:53 -0700402 printk(KERN_ERR PFX "bnx2fc_rcv: Wrong FC type frame\n");
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800403 goto err;
404 }
405
406 /*
407 * Check for minimum frame length, and make sure required FCoE
408 * and FC headers are pulled into the linear data area.
409 */
410 if (unlikely((skb->len < FCOE_MIN_FRAME) ||
411 !pskb_may_pull(skb, FCOE_HEADER_LEN)))
412 goto err;
413
414 skb_set_transport_header(skb, sizeof(struct fcoe_hdr));
415 fh = (struct fc_frame_header *) skb_transport_header(skb);
416
417 oxid = ntohs(fh->fh_ox_id);
418
419 fr = fcoe_dev_from_skb(skb);
420 fr->fr_dev = lport;
421 fr->ptype = ptype;
422
423 bg = &bnx2fc_global;
424 spin_lock_bh(&bg->fcoe_rx_list.lock);
425
426 __skb_queue_tail(&bg->fcoe_rx_list, skb);
427 if (bg->fcoe_rx_list.qlen == 1)
428 wake_up_process(bg->thread);
429
430 spin_unlock_bh(&bg->fcoe_rx_list.lock);
431
432 return 0;
433err:
434 kfree_skb(skb);
435 return -1;
436}
437
438static int bnx2fc_l2_rcv_thread(void *arg)
439{
440 struct fcoe_percpu_s *bg = arg;
441 struct sk_buff *skb;
442
443 set_user_nice(current, -20);
444 set_current_state(TASK_INTERRUPTIBLE);
445 while (!kthread_should_stop()) {
446 schedule();
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800447 spin_lock_bh(&bg->fcoe_rx_list.lock);
448 while ((skb = __skb_dequeue(&bg->fcoe_rx_list)) != NULL) {
449 spin_unlock_bh(&bg->fcoe_rx_list.lock);
450 bnx2fc_recv_frame(skb);
451 spin_lock_bh(&bg->fcoe_rx_list.lock);
452 }
Bhanu Gollapudifee78712011-03-21 18:51:13 -0700453 __set_current_state(TASK_INTERRUPTIBLE);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800454 spin_unlock_bh(&bg->fcoe_rx_list.lock);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800455 }
Bhanu Gollapudifee78712011-03-21 18:51:13 -0700456 __set_current_state(TASK_RUNNING);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800457 return 0;
458}
459
460
461static void bnx2fc_recv_frame(struct sk_buff *skb)
462{
463 u32 fr_len;
464 struct fc_lport *lport;
465 struct fcoe_rcv_info *fr;
466 struct fcoe_dev_stats *stats;
467 struct fc_frame_header *fh;
468 struct fcoe_crc_eof crc_eof;
469 struct fc_frame *fp;
470 struct fc_lport *vn_port;
471 struct fcoe_port *port;
472 u8 *mac = NULL;
473 u8 *dest_mac = NULL;
474 struct fcoe_hdr *hp;
475
476 fr = fcoe_dev_from_skb(skb);
477 lport = fr->fr_dev;
478 if (unlikely(lport == NULL)) {
Bhanu Prakash Gollapudib2a554f2011-06-27 23:30:53 -0700479 printk(KERN_ERR PFX "Invalid lport struct\n");
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800480 kfree_skb(skb);
481 return;
482 }
483
484 if (skb_is_nonlinear(skb))
485 skb_linearize(skb);
486 mac = eth_hdr(skb)->h_source;
487 dest_mac = eth_hdr(skb)->h_dest;
488
489 /* Pull the header */
490 hp = (struct fcoe_hdr *) skb_network_header(skb);
491 fh = (struct fc_frame_header *) skb_transport_header(skb);
492 skb_pull(skb, sizeof(struct fcoe_hdr));
493 fr_len = skb->len - sizeof(struct fcoe_crc_eof);
494
495 stats = per_cpu_ptr(lport->dev_stats, get_cpu());
496 stats->RxFrames++;
497 stats->RxWords += fr_len / FCOE_WORD_TO_BYTE;
498
499 fp = (struct fc_frame *)skb;
500 fc_frame_init(fp);
501 fr_dev(fp) = lport;
502 fr_sof(fp) = hp->fcoe_sof;
503 if (skb_copy_bits(skb, fr_len, &crc_eof, sizeof(crc_eof))) {
504 put_cpu();
505 kfree_skb(skb);
506 return;
507 }
508 fr_eof(fp) = crc_eof.fcoe_eof;
509 fr_crc(fp) = crc_eof.fcoe_crc32;
510 if (pskb_trim(skb, fr_len)) {
511 put_cpu();
512 kfree_skb(skb);
513 return;
514 }
515
516 fh = fc_frame_header_get(fp);
517
518 vn_port = fc_vport_id_lookup(lport, ntoh24(fh->fh_d_id));
519 if (vn_port) {
520 port = lport_priv(vn_port);
521 if (compare_ether_addr(port->data_src_addr, dest_mac)
522 != 0) {
523 BNX2FC_HBA_DBG(lport, "fpma mismatch\n");
524 put_cpu();
525 kfree_skb(skb);
526 return;
527 }
528 }
529 if (fh->fh_r_ctl == FC_RCTL_DD_SOL_DATA &&
530 fh->fh_type == FC_TYPE_FCP) {
531 /* Drop FCP data. We dont this in L2 path */
532 put_cpu();
533 kfree_skb(skb);
534 return;
535 }
536 if (fh->fh_r_ctl == FC_RCTL_ELS_REQ &&
537 fh->fh_type == FC_TYPE_ELS) {
538 switch (fc_frame_payload_op(fp)) {
539 case ELS_LOGO:
540 if (ntoh24(fh->fh_s_id) == FC_FID_FLOGI) {
541 /* drop non-FIP LOGO */
542 put_cpu();
543 kfree_skb(skb);
544 return;
545 }
546 break;
547 }
548 }
549 if (le32_to_cpu(fr_crc(fp)) !=
550 ~crc32(~0, skb->data, fr_len)) {
551 if (stats->InvalidCRCCount < 5)
552 printk(KERN_WARNING PFX "dropping frame with "
553 "CRC error\n");
554 stats->InvalidCRCCount++;
555 put_cpu();
556 kfree_skb(skb);
557 return;
558 }
559 put_cpu();
560 fc_exch_recv(lport, fp);
561}
562
563/**
564 * bnx2fc_percpu_io_thread - thread per cpu for ios
565 *
566 * @arg: ptr to bnx2fc_percpu_info structure
567 */
568int bnx2fc_percpu_io_thread(void *arg)
569{
570 struct bnx2fc_percpu_s *p = arg;
571 struct bnx2fc_work *work, *tmp;
572 LIST_HEAD(work_list);
573
574 set_user_nice(current, -20);
575 set_current_state(TASK_INTERRUPTIBLE);
576 while (!kthread_should_stop()) {
577 schedule();
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800578 spin_lock_bh(&p->fp_work_lock);
579 while (!list_empty(&p->work_list)) {
580 list_splice_init(&p->work_list, &work_list);
581 spin_unlock_bh(&p->fp_work_lock);
582
583 list_for_each_entry_safe(work, tmp, &work_list, list) {
584 list_del_init(&work->list);
585 bnx2fc_process_cq_compl(work->tgt, work->wqe);
586 kfree(work);
587 }
588
589 spin_lock_bh(&p->fp_work_lock);
590 }
Bhanu Gollapudifee78712011-03-21 18:51:13 -0700591 __set_current_state(TASK_INTERRUPTIBLE);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800592 spin_unlock_bh(&p->fp_work_lock);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800593 }
Bhanu Gollapudifee78712011-03-21 18:51:13 -0700594 __set_current_state(TASK_RUNNING);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800595
596 return 0;
597}
598
599static struct fc_host_statistics *bnx2fc_get_host_stats(struct Scsi_Host *shost)
600{
601 struct fc_host_statistics *bnx2fc_stats;
602 struct fc_lport *lport = shost_priv(shost);
603 struct fcoe_port *port = lport_priv(lport);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700604 struct bnx2fc_interface *interface = port->priv;
605 struct bnx2fc_hba *hba = interface->hba;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800606 struct fcoe_statistics_params *fw_stats;
607 int rc = 0;
608
609 fw_stats = (struct fcoe_statistics_params *)hba->stats_buffer;
610 if (!fw_stats)
611 return NULL;
612
613 bnx2fc_stats = fc_get_host_stats(shost);
614
615 init_completion(&hba->stat_req_done);
616 if (bnx2fc_send_stat_req(hba))
617 return bnx2fc_stats;
618 rc = wait_for_completion_timeout(&hba->stat_req_done, (2 * HZ));
619 if (!rc) {
620 BNX2FC_HBA_DBG(lport, "FW stat req timed out\n");
621 return bnx2fc_stats;
622 }
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300623 bnx2fc_stats->invalid_crc_count += fw_stats->rx_stat2.fc_crc_cnt;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800624 bnx2fc_stats->tx_frames += fw_stats->tx_stat.fcoe_tx_pkt_cnt;
625 bnx2fc_stats->tx_words += (fw_stats->tx_stat.fcoe_tx_byte_cnt) / 4;
626 bnx2fc_stats->rx_frames += fw_stats->rx_stat0.fcoe_rx_pkt_cnt;
627 bnx2fc_stats->rx_words += (fw_stats->rx_stat0.fcoe_rx_byte_cnt) / 4;
628
629 bnx2fc_stats->dumped_frames = 0;
630 bnx2fc_stats->lip_count = 0;
631 bnx2fc_stats->nos_count = 0;
632 bnx2fc_stats->loss_of_sync_count = 0;
633 bnx2fc_stats->loss_of_signal_count = 0;
634 bnx2fc_stats->prim_seq_protocol_err_count = 0;
635
636 return bnx2fc_stats;
637}
638
639static int bnx2fc_shost_config(struct fc_lport *lport, struct device *dev)
640{
641 struct fcoe_port *port = lport_priv(lport);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700642 struct bnx2fc_interface *interface = port->priv;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800643 struct Scsi_Host *shost = lport->host;
644 int rc = 0;
645
646 shost->max_cmd_len = BNX2FC_MAX_CMD_LEN;
647 shost->max_lun = BNX2FC_MAX_LUN;
648 shost->max_id = BNX2FC_MAX_FCP_TGT;
649 shost->max_channel = 0;
650 if (lport->vport)
651 shost->transportt = bnx2fc_vport_xport_template;
652 else
653 shost->transportt = bnx2fc_transport_template;
654
655 /* Add the new host to SCSI-ml */
656 rc = scsi_add_host(lport->host, dev);
657 if (rc) {
658 printk(KERN_ERR PFX "Error on scsi_add_host\n");
659 return rc;
660 }
661 if (!lport->vport)
662 fc_host_max_npiv_vports(lport->host) = USHRT_MAX;
663 sprintf(fc_host_symbolic_name(lport->host), "%s v%s over %s",
664 BNX2FC_NAME, BNX2FC_VERSION,
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700665 interface->netdev->name);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800666
667 return 0;
668}
669
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800670static void bnx2fc_link_speed_update(struct fc_lport *lport)
671{
672 struct fcoe_port *port = lport_priv(lport);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700673 struct bnx2fc_interface *interface = port->priv;
674 struct net_device *netdev = interface->netdev;
David Decotigny8ae6daca2011-04-27 18:32:38 +0000675 struct ethtool_cmd ecmd;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800676
677 if (!dev_ethtool_get_settings(netdev, &ecmd)) {
678 lport->link_supported_speeds &=
679 ~(FC_PORTSPEED_1GBIT | FC_PORTSPEED_10GBIT);
680 if (ecmd.supported & (SUPPORTED_1000baseT_Half |
681 SUPPORTED_1000baseT_Full))
682 lport->link_supported_speeds |= FC_PORTSPEED_1GBIT;
683 if (ecmd.supported & SUPPORTED_10000baseT_Full)
684 lport->link_supported_speeds |= FC_PORTSPEED_10GBIT;
685
David Decotigny8ae6daca2011-04-27 18:32:38 +0000686 switch (ethtool_cmd_speed(&ecmd)) {
687 case SPEED_1000:
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800688 lport->link_speed = FC_PORTSPEED_1GBIT;
David Decotigny8ae6daca2011-04-27 18:32:38 +0000689 break;
Bhanu Prakash Gollapudia4dc08c2011-05-27 11:47:25 -0700690 case SPEED_2500:
691 lport->link_speed = FC_PORTSPEED_2GBIT;
692 break;
David Decotigny8ae6daca2011-04-27 18:32:38 +0000693 case SPEED_10000:
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800694 lport->link_speed = FC_PORTSPEED_10GBIT;
David Decotigny8ae6daca2011-04-27 18:32:38 +0000695 break;
696 }
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800697 }
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800698}
699static int bnx2fc_link_ok(struct fc_lport *lport)
700{
701 struct fcoe_port *port = lport_priv(lport);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700702 struct bnx2fc_interface *interface = port->priv;
703 struct bnx2fc_hba *hba = interface->hba;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800704 struct net_device *dev = hba->phys_dev;
705 int rc = 0;
706
707 if ((dev->flags & IFF_UP) && netif_carrier_ok(dev))
708 clear_bit(ADAPTER_STATE_LINK_DOWN, &hba->adapter_state);
709 else {
710 set_bit(ADAPTER_STATE_LINK_DOWN, &hba->adapter_state);
711 rc = -1;
712 }
713 return rc;
714}
715
716/**
717 * bnx2fc_get_link_state - get network link state
718 *
719 * @hba: adapter instance pointer
720 *
721 * updates adapter structure flag based on netdev state
722 */
723void bnx2fc_get_link_state(struct bnx2fc_hba *hba)
724{
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700725 if (test_bit(__LINK_STATE_NOCARRIER, &hba->phys_dev->state))
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800726 set_bit(ADAPTER_STATE_LINK_DOWN, &hba->adapter_state);
727 else
728 clear_bit(ADAPTER_STATE_LINK_DOWN, &hba->adapter_state);
729}
730
731static int bnx2fc_net_config(struct fc_lport *lport)
732{
733 struct bnx2fc_hba *hba;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700734 struct bnx2fc_interface *interface;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800735 struct fcoe_port *port;
736 u64 wwnn, wwpn;
737
738 port = lport_priv(lport);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700739 interface = port->priv;
740 hba = interface->hba;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800741
742 /* require support for get_pauseparam ethtool op. */
743 if (!hba->phys_dev->ethtool_ops ||
744 !hba->phys_dev->ethtool_ops->get_pauseparam)
745 return -EOPNOTSUPP;
746
Bhanu Gollapudi1294bfe2011-03-17 17:13:34 -0700747 if (fc_set_mfs(lport, BNX2FC_MFS))
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800748 return -EINVAL;
749
750 skb_queue_head_init(&port->fcoe_pending_queue);
751 port->fcoe_pending_queue_active = 0;
752 setup_timer(&port->timer, fcoe_queue_timer, (unsigned long) lport);
753
754 bnx2fc_link_speed_update(lport);
755
756 if (!lport->vport) {
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700757 wwnn = fcoe_wwn_from_mac(interface->ctlr.ctl_src_addr, 1, 0);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800758 BNX2FC_HBA_DBG(lport, "WWNN = 0x%llx\n", wwnn);
759 fc_set_wwnn(lport, wwnn);
760
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700761 wwpn = fcoe_wwn_from_mac(interface->ctlr.ctl_src_addr, 2, 0);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800762 BNX2FC_HBA_DBG(lport, "WWPN = 0x%llx\n", wwpn);
763 fc_set_wwpn(lport, wwpn);
764 }
765
766 return 0;
767}
768
769static void bnx2fc_destroy_timer(unsigned long data)
770{
771 struct bnx2fc_hba *hba = (struct bnx2fc_hba *)data;
772
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700773 BNX2FC_MISC_DBG("ERROR:bnx2fc_destroy_timer - "
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800774 "Destroy compl not received!!\n");
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700775 set_bit(BNX2FC_FLAG_DESTROY_CMPL, &hba->flags);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800776 wake_up_interruptible(&hba->destroy_wait);
777}
778
779/**
780 * bnx2fc_indicate_netevent - Generic netdev event handler
781 *
782 * @context: adapter structure pointer
783 * @event: event type
Michael Chan415199f2011-07-20 14:55:24 +0000784 * @vlan_id: vlan id - associated vlan id with this event
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800785 *
786 * Handles NETDEV_UP, NETDEV_DOWN, NETDEV_GOING_DOWN,NETDEV_CHANGE and
787 * NETDEV_CHANGE_MTU events
788 */
Michael Chan415199f2011-07-20 14:55:24 +0000789static void bnx2fc_indicate_netevent(void *context, unsigned long event,
790 u16 vlan_id)
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800791{
792 struct bnx2fc_hba *hba = (struct bnx2fc_hba *)context;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700793 struct fc_lport *lport;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800794 struct fc_lport *vport;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700795 struct bnx2fc_interface *interface;
796 int wait_for_upload = 0;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800797 u32 link_possible = 1;
798
Michael Chan415199f2011-07-20 14:55:24 +0000799 /* Ignore vlans for now */
800 if (vlan_id != 0)
801 return;
802
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800803 switch (event) {
804 case NETDEV_UP:
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800805 if (!test_bit(ADAPTER_STATE_UP, &hba->adapter_state))
806 printk(KERN_ERR "indicate_netevent: "\
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700807 "hba is not UP!!\n");
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800808 break;
809
810 case NETDEV_DOWN:
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800811 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:
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800817 set_bit(ADAPTER_STATE_GOING_DOWN, &hba->adapter_state);
818 link_possible = 0;
819 break;
820
821 case NETDEV_CHANGE:
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800822 break;
823
824 default:
825 printk(KERN_ERR PFX "Unkonwn netevent %ld", event);
826 return;
827 }
828
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700829 mutex_lock(&bnx2fc_dev_lock);
830 list_for_each_entry(interface, &if_list, list) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800831
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700832 if (interface->hba != hba)
833 continue;
834
835 lport = interface->ctlr.lp;
836 BNX2FC_HBA_DBG(lport, "netevent handler - event=%s %ld\n",
837 interface->netdev->name, event);
838
839 bnx2fc_link_speed_update(lport);
840
841 if (link_possible && !bnx2fc_link_ok(lport)) {
842 printk(KERN_ERR "indicate_netevent: ctlr_link_up\n");
843 fcoe_ctlr_link_up(&interface->ctlr);
844 } else if (fcoe_ctlr_link_down(&interface->ctlr)) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800845 mutex_lock(&lport->lp_mutex);
846 list_for_each_entry(vport, &lport->vports, list)
847 fc_host_port_type(vport->host) =
848 FC_PORTTYPE_UNKNOWN;
849 mutex_unlock(&lport->lp_mutex);
850 fc_host_port_type(lport->host) = FC_PORTTYPE_UNKNOWN;
851 per_cpu_ptr(lport->dev_stats,
852 get_cpu())->LinkFailureCount++;
853 put_cpu();
854 fcoe_clean_pending_queue(lport);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700855 wait_for_upload = 1;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800856 }
857 }
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700858 mutex_unlock(&bnx2fc_dev_lock);
859
860 if (wait_for_upload) {
861 clear_bit(ADAPTER_STATE_READY, &hba->adapter_state);
862 init_waitqueue_head(&hba->shutdown_wait);
863 BNX2FC_MISC_DBG("indicate_netevent "
864 "num_ofld_sess = %d\n",
865 hba->num_ofld_sess);
866 hba->wait_for_link_down = 1;
867 wait_event_interruptible(hba->shutdown_wait,
868 (hba->num_ofld_sess == 0));
869 BNX2FC_MISC_DBG("wakeup - num_ofld_sess = %d\n",
870 hba->num_ofld_sess);
871 hba->wait_for_link_down = 0;
872
873 if (signal_pending(current))
874 flush_signals(current);
875 }
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800876}
877
878static int bnx2fc_libfc_config(struct fc_lport *lport)
879{
880
881 /* Set the function pointers set by bnx2fc driver */
882 memcpy(&lport->tt, &bnx2fc_libfc_fcn_templ,
883 sizeof(struct libfc_function_template));
884 fc_elsct_init(lport);
885 fc_exch_init(lport);
886 fc_rport_init(lport);
887 fc_disc_init(lport);
888 return 0;
889}
890
891static int bnx2fc_em_config(struct fc_lport *lport)
892{
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800893 if (!fc_exch_mgr_alloc(lport, FC_CLASS_3, FCOE_MIN_XID,
894 FCOE_MAX_XID, NULL)) {
895 printk(KERN_ERR PFX "em_config:fc_exch_mgr_alloc failed\n");
896 return -ENOMEM;
897 }
898
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800899 return 0;
900}
901
902static int bnx2fc_lport_config(struct fc_lport *lport)
903{
904 lport->link_up = 0;
905 lport->qfull = 0;
906 lport->max_retry_count = 3;
907 lport->max_rport_retry_count = 3;
908 lport->e_d_tov = 2 * 1000;
909 lport->r_a_tov = 10 * 1000;
910
911 /* REVISIT: enable when supporting tape devices
912 lport->service_params = (FCP_SPPF_INIT_FCN | FCP_SPPF_RD_XRDY_DIS |
913 FCP_SPPF_RETRY | FCP_SPPF_CONF_COMPL);
914 */
915 lport->service_params = (FCP_SPPF_INIT_FCN | FCP_SPPF_RD_XRDY_DIS);
916 lport->does_npiv = 1;
917
918 memset(&lport->rnid_gen, 0, sizeof(struct fc_els_rnid_gen));
919 lport->rnid_gen.rnid_atype = BNX2FC_RNID_HBA;
920
921 /* alloc stats structure */
922 if (fc_lport_init_stats(lport))
923 return -ENOMEM;
924
925 /* Finish fc_lport configuration */
926 fc_lport_config(lport);
927
928 return 0;
929}
930
931/**
932 * bnx2fc_fip_recv - handle a received FIP frame.
933 *
934 * @skb: the received skb
935 * @dev: associated &net_device
936 * @ptype: the &packet_type structure which was used to register this handler.
937 * @orig_dev: original receive &net_device, in case @ dev is a bond.
938 *
939 * Returns: 0 for success
940 */
941static int bnx2fc_fip_recv(struct sk_buff *skb, struct net_device *dev,
942 struct packet_type *ptype,
943 struct net_device *orig_dev)
944{
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700945 struct bnx2fc_interface *interface;
946 interface = container_of(ptype, struct bnx2fc_interface,
947 fip_packet_type);
948 fcoe_ctlr_recv(&interface->ctlr, skb);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800949 return 0;
950}
951
952/**
953 * bnx2fc_update_src_mac - Update Ethernet MAC filters.
954 *
955 * @fip: FCoE controller.
956 * @old: Unicast MAC address to delete if the MAC is non-zero.
957 * @new: Unicast MAC address to add.
958 *
959 * Remove any previously-set unicast MAC filter.
960 * Add secondary FCoE MAC address filter for our OUI.
961 */
962static void bnx2fc_update_src_mac(struct fc_lport *lport, u8 *addr)
963{
964 struct fcoe_port *port = lport_priv(lport);
965
966 memcpy(port->data_src_addr, addr, ETH_ALEN);
967}
968
969/**
970 * bnx2fc_get_src_mac - return the ethernet source address for an lport
971 *
972 * @lport: libfc port
973 */
974static u8 *bnx2fc_get_src_mac(struct fc_lport *lport)
975{
976 struct fcoe_port *port;
977
978 port = (struct fcoe_port *)lport_priv(lport);
979 return port->data_src_addr;
980}
981
982/**
983 * bnx2fc_fip_send - send an Ethernet-encapsulated FIP frame.
984 *
985 * @fip: FCoE controller.
986 * @skb: FIP Packet.
987 */
988static void bnx2fc_fip_send(struct fcoe_ctlr *fip, struct sk_buff *skb)
989{
990 skb->dev = bnx2fc_from_ctlr(fip)->netdev;
991 dev_queue_xmit(skb);
992}
993
994static int bnx2fc_vport_create(struct fc_vport *vport, bool disabled)
995{
996 struct Scsi_Host *shost = vport_to_shost(vport);
997 struct fc_lport *n_port = shost_priv(shost);
998 struct fcoe_port *port = lport_priv(n_port);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700999 struct bnx2fc_interface *interface = port->priv;
1000 struct net_device *netdev = interface->netdev;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001001 struct fc_lport *vn_port;
1002
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001003 if (!test_bit(BNX2FC_FLAG_FW_INIT_DONE, &interface->hba->flags)) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001004 printk(KERN_ERR PFX "vn ports cannot be created on"
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001005 "this interface\n");
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001006 return -EIO;
1007 }
1008 mutex_lock(&bnx2fc_dev_lock);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001009 vn_port = bnx2fc_if_create(interface, &vport->dev, 1);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001010 mutex_unlock(&bnx2fc_dev_lock);
1011
1012 if (IS_ERR(vn_port)) {
1013 printk(KERN_ERR PFX "bnx2fc_vport_create (%s) failed\n",
1014 netdev->name);
1015 return -EIO;
1016 }
1017
1018 if (disabled) {
1019 fc_vport_set_state(vport, FC_VPORT_DISABLED);
1020 } else {
1021 vn_port->boot_time = jiffies;
1022 fc_lport_init(vn_port);
1023 fc_fabric_login(vn_port);
1024 fc_vport_setlink(vn_port);
1025 }
1026 return 0;
1027}
1028
1029static int bnx2fc_vport_destroy(struct fc_vport *vport)
1030{
1031 struct Scsi_Host *shost = vport_to_shost(vport);
1032 struct fc_lport *n_port = shost_priv(shost);
1033 struct fc_lport *vn_port = vport->dd_data;
1034 struct fcoe_port *port = lport_priv(vn_port);
1035
1036 mutex_lock(&n_port->lp_mutex);
1037 list_del(&vn_port->list);
1038 mutex_unlock(&n_port->lp_mutex);
1039 queue_work(bnx2fc_wq, &port->destroy_work);
1040 return 0;
1041}
1042
1043static int bnx2fc_vport_disable(struct fc_vport *vport, bool disable)
1044{
1045 struct fc_lport *lport = vport->dd_data;
1046
1047 if (disable) {
1048 fc_vport_set_state(vport, FC_VPORT_DISABLED);
1049 fc_fabric_logoff(lport);
1050 } else {
1051 lport->boot_time = jiffies;
1052 fc_fabric_login(lport);
1053 fc_vport_setlink(lport);
1054 }
1055 return 0;
1056}
1057
1058
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001059static int bnx2fc_netdev_setup(struct bnx2fc_interface *interface)
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001060{
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001061 struct net_device *netdev = interface->netdev;
1062 struct net_device *physdev = interface->hba->phys_dev;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001063 struct netdev_hw_addr *ha;
1064 int sel_san_mac = 0;
1065
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001066 /* setup Source MAC Address */
1067 rcu_read_lock();
1068 for_each_dev_addr(physdev, ha) {
1069 BNX2FC_MISC_DBG("net_config: ha->type = %d, fip_mac = ",
1070 ha->type);
1071 printk(KERN_INFO "%2x:%2x:%2x:%2x:%2x:%2x\n", ha->addr[0],
1072 ha->addr[1], ha->addr[2], ha->addr[3],
1073 ha->addr[4], ha->addr[5]);
1074
1075 if ((ha->type == NETDEV_HW_ADDR_T_SAN) &&
1076 (is_valid_ether_addr(ha->addr))) {
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001077 memcpy(interface->ctlr.ctl_src_addr, ha->addr,
1078 ETH_ALEN);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001079 sel_san_mac = 1;
1080 BNX2FC_MISC_DBG("Found SAN MAC\n");
1081 }
1082 }
1083 rcu_read_unlock();
1084
1085 if (!sel_san_mac)
1086 return -ENODEV;
1087
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001088 interface->fip_packet_type.func = bnx2fc_fip_recv;
1089 interface->fip_packet_type.type = htons(ETH_P_FIP);
1090 interface->fip_packet_type.dev = netdev;
1091 dev_add_pack(&interface->fip_packet_type);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001092
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001093 interface->fcoe_packet_type.func = bnx2fc_rcv;
1094 interface->fcoe_packet_type.type = __constant_htons(ETH_P_FCOE);
1095 interface->fcoe_packet_type.dev = netdev;
1096 dev_add_pack(&interface->fcoe_packet_type);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001097
1098 return 0;
1099}
1100
1101static int bnx2fc_attach_transport(void)
1102{
1103 bnx2fc_transport_template =
1104 fc_attach_transport(&bnx2fc_transport_function);
1105
1106 if (bnx2fc_transport_template == NULL) {
1107 printk(KERN_ERR PFX "Failed to attach FC transport\n");
1108 return -ENODEV;
1109 }
1110
1111 bnx2fc_vport_xport_template =
1112 fc_attach_transport(&bnx2fc_vport_xport_function);
1113 if (bnx2fc_vport_xport_template == NULL) {
1114 printk(KERN_ERR PFX
1115 "Failed to attach FC transport for vport\n");
1116 fc_release_transport(bnx2fc_transport_template);
1117 bnx2fc_transport_template = NULL;
1118 return -ENODEV;
1119 }
1120 return 0;
1121}
1122static void bnx2fc_release_transport(void)
1123{
1124 fc_release_transport(bnx2fc_transport_template);
1125 fc_release_transport(bnx2fc_vport_xport_template);
1126 bnx2fc_transport_template = NULL;
1127 bnx2fc_vport_xport_template = NULL;
1128}
1129
1130static void bnx2fc_interface_release(struct kref *kref)
1131{
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001132 struct bnx2fc_interface *interface;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001133 struct net_device *netdev;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001134
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001135 interface = container_of(kref, struct bnx2fc_interface, kref);
Nithin Nayak Sujir068bdce2011-04-25 12:30:09 -07001136 BNX2FC_MISC_DBG("Interface is being released\n");
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001137
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001138 netdev = interface->netdev;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001139
1140 /* tear-down FIP controller */
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001141 if (test_and_clear_bit(BNX2FC_CTLR_INIT_DONE, &interface->if_flags))
1142 fcoe_ctlr_destroy(&interface->ctlr);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001143
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001144 kfree(interface);
1145
1146 dev_put(netdev);
1147 module_put(THIS_MODULE);
1148}
1149
1150static inline void bnx2fc_interface_get(struct bnx2fc_interface *interface)
1151{
1152 kref_get(&interface->kref);
1153}
1154
1155static inline void bnx2fc_interface_put(struct bnx2fc_interface *interface)
1156{
1157 kref_put(&interface->kref, bnx2fc_interface_release);
1158}
1159static void bnx2fc_hba_destroy(struct bnx2fc_hba *hba)
1160{
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001161 /* Free the command manager */
1162 if (hba->cmd_mgr) {
1163 bnx2fc_cmd_mgr_free(hba->cmd_mgr);
1164 hba->cmd_mgr = NULL;
1165 }
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001166 kfree(hba->tgt_ofld_list);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001167 bnx2fc_unbind_pcidev(hba);
1168 kfree(hba);
1169}
1170
1171/**
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001172 * bnx2fc_hba_create - create a new bnx2fc hba
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001173 *
1174 * @cnic: pointer to cnic device
1175 *
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001176 * Creates a new FCoE hba on the given device.
1177 *
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001178 */
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001179static struct bnx2fc_hba *bnx2fc_hba_create(struct cnic_dev *cnic)
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001180{
1181 struct bnx2fc_hba *hba;
1182 int rc;
1183
1184 hba = kzalloc(sizeof(*hba), GFP_KERNEL);
1185 if (!hba) {
1186 printk(KERN_ERR PFX "Unable to allocate hba structure\n");
1187 return NULL;
1188 }
1189 spin_lock_init(&hba->hba_lock);
1190 mutex_init(&hba->hba_mutex);
1191
1192 hba->cnic = cnic;
1193 rc = bnx2fc_bind_pcidev(hba);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001194 if (rc) {
1195 printk(KERN_ERR PFX "create_adapter: bind error\n");
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001196 goto bind_err;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001197 }
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001198 hba->phys_dev = cnic->netdev;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001199 hba->next_conn_id = 0;
1200
1201 hba->tgt_ofld_list =
1202 kzalloc(sizeof(struct bnx2fc_rport *) * BNX2FC_NUM_MAX_SESS,
1203 GFP_KERNEL);
1204 if (!hba->tgt_ofld_list) {
1205 printk(KERN_ERR PFX "Unable to allocate tgt offload list\n");
1206 goto tgtofld_err;
1207 }
1208
1209 hba->num_ofld_sess = 0;
1210
1211 hba->cmd_mgr = bnx2fc_cmd_mgr_alloc(hba, BNX2FC_MIN_XID,
1212 BNX2FC_MAX_XID);
1213 if (!hba->cmd_mgr) {
1214 printk(KERN_ERR PFX "em_config:bnx2fc_cmd_mgr_alloc failed\n");
1215 goto cmgr_err;
1216 }
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001217
1218 init_waitqueue_head(&hba->shutdown_wait);
1219 init_waitqueue_head(&hba->destroy_wait);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001220 INIT_LIST_HEAD(&hba->vports);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001221
1222 return hba;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001223
1224cmgr_err:
1225 kfree(hba->tgt_ofld_list);
1226tgtofld_err:
1227 bnx2fc_unbind_pcidev(hba);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001228bind_err:
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001229 kfree(hba);
1230 return NULL;
1231}
1232
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001233struct bnx2fc_interface *bnx2fc_interface_create(struct bnx2fc_hba *hba,
1234 struct net_device *netdev,
1235 enum fip_state fip_mode)
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001236{
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001237 struct bnx2fc_interface *interface;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001238 int rc = 0;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001239
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001240 interface = kzalloc(sizeof(*interface), GFP_KERNEL);
1241 if (!interface) {
1242 printk(KERN_ERR PFX "Unable to allocate interface structure\n");
1243 return NULL;
1244 }
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001245 dev_hold(netdev);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001246 kref_init(&interface->kref);
1247 interface->hba = hba;
1248 interface->netdev = netdev;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001249
1250 /* Initialize FIP */
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001251 fcoe_ctlr_init(&interface->ctlr, fip_mode);
1252 interface->ctlr.send = bnx2fc_fip_send;
1253 interface->ctlr.update_mac = bnx2fc_update_src_mac;
1254 interface->ctlr.get_src_addr = bnx2fc_get_src_mac;
1255 set_bit(BNX2FC_CTLR_INIT_DONE, &interface->if_flags);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001256
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001257 rc = bnx2fc_netdev_setup(interface);
1258 if (!rc)
1259 return interface;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001260
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001261 fcoe_ctlr_destroy(&interface->ctlr);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001262 dev_put(netdev);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001263 kfree(interface);
1264 return NULL;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001265}
1266
1267/**
1268 * bnx2fc_if_create - Create FCoE instance on a given interface
1269 *
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001270 * @interface: FCoE interface to create a local port on
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001271 * @parent: Device pointer to be the parent in sysfs for the SCSI host
1272 * @npiv: Indicates if the port is vport or not
1273 *
1274 * Creates a fc_lport instance and a Scsi_Host instance and configure them.
1275 *
1276 * Returns: Allocated fc_lport or an error pointer
1277 */
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001278static struct fc_lport *bnx2fc_if_create(struct bnx2fc_interface *interface,
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001279 struct device *parent, int npiv)
1280{
Vasu Dev134a4e22011-04-28 15:55:44 -07001281 struct fc_lport *lport, *n_port;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001282 struct fcoe_port *port;
1283 struct Scsi_Host *shost;
1284 struct fc_vport *vport = dev_to_vport(parent);
Bhanu Prakash Gollapudid36b3272011-05-27 11:47:27 -07001285 struct bnx2fc_lport *blport;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001286 struct bnx2fc_hba *hba;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001287 int rc = 0;
1288
Bhanu Prakash Gollapudid36b3272011-05-27 11:47:27 -07001289 blport = kzalloc(sizeof(struct bnx2fc_lport), GFP_KERNEL);
1290 if (!blport) {
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001291 BNX2FC_HBA_DBG(interface->ctlr.lp, "Unable to alloc blport\n");
Bhanu Prakash Gollapudid36b3272011-05-27 11:47:27 -07001292 return NULL;
1293 }
1294
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001295 /* Allocate Scsi_Host structure */
Vasu Dev134a4e22011-04-28 15:55:44 -07001296 if (!npiv)
1297 lport = libfc_host_alloc(&bnx2fc_shost_template, sizeof(*port));
1298 else
1299 lport = libfc_vport_create(vport, sizeof(*port));
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001300
1301 if (!lport) {
1302 printk(KERN_ERR PFX "could not allocate scsi host structure\n");
Bhanu Prakash Gollapudid36b3272011-05-27 11:47:27 -07001303 goto free_blport;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001304 }
1305 shost = lport->host;
1306 port = lport_priv(lport);
1307 port->lport = lport;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001308 port->priv = interface;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001309 INIT_WORK(&port->destroy_work, bnx2fc_destroy_work);
1310
1311 /* Configure fcoe_port */
1312 rc = bnx2fc_lport_config(lport);
1313 if (rc)
1314 goto lp_config_err;
1315
1316 if (npiv) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001317 printk(KERN_ERR PFX "Setting vport names, 0x%llX 0x%llX\n",
1318 vport->node_name, vport->port_name);
1319 fc_set_wwnn(lport, vport->node_name);
1320 fc_set_wwpn(lport, vport->port_name);
1321 }
1322 /* Configure netdev and networking properties of the lport */
1323 rc = bnx2fc_net_config(lport);
1324 if (rc) {
1325 printk(KERN_ERR PFX "Error on bnx2fc_net_config\n");
1326 goto lp_config_err;
1327 }
1328
1329 rc = bnx2fc_shost_config(lport, parent);
1330 if (rc) {
1331 printk(KERN_ERR PFX "Couldnt configure shost for %s\n",
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001332 interface->netdev->name);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001333 goto lp_config_err;
1334 }
1335
1336 /* Initialize the libfc library */
1337 rc = bnx2fc_libfc_config(lport);
1338 if (rc) {
1339 printk(KERN_ERR PFX "Couldnt configure libfc\n");
1340 goto shost_err;
1341 }
1342 fc_host_port_type(lport->host) = FC_PORTTYPE_UNKNOWN;
1343
1344 /* Allocate exchange manager */
Vasu Dev134a4e22011-04-28 15:55:44 -07001345 if (!npiv)
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001346 rc = bnx2fc_em_config(lport);
Vasu Dev134a4e22011-04-28 15:55:44 -07001347 else {
1348 shost = vport_to_shost(vport);
1349 n_port = shost_priv(shost);
1350 rc = fc_exch_mgr_list_clone(n_port, lport);
1351 }
1352
1353 if (rc) {
1354 printk(KERN_ERR PFX "Error on bnx2fc_em_config\n");
1355 goto shost_err;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001356 }
1357
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001358 bnx2fc_interface_get(interface);
Bhanu Prakash Gollapudid36b3272011-05-27 11:47:27 -07001359
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001360 hba = interface->hba;
Bhanu Prakash Gollapudid36b3272011-05-27 11:47:27 -07001361 spin_lock_bh(&hba->hba_lock);
1362 blport->lport = lport;
1363 list_add_tail(&blport->list, &hba->vports);
1364 spin_unlock_bh(&hba->hba_lock);
1365
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001366 return lport;
1367
1368shost_err:
1369 scsi_remove_host(shost);
1370lp_config_err:
1371 scsi_host_put(lport->host);
Bhanu Prakash Gollapudid36b3272011-05-27 11:47:27 -07001372free_blport:
1373 kfree(blport);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001374 return NULL;
1375}
1376
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001377static void bnx2fc_netdev_cleanup(struct bnx2fc_interface *interface)
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001378{
1379 /* Dont listen for Ethernet packets anymore */
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001380 __dev_remove_pack(&interface->fcoe_packet_type);
1381 __dev_remove_pack(&interface->fip_packet_type);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001382 synchronize_net();
1383}
1384
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001385static void bnx2fc_if_destroy(struct fc_lport *lport, struct bnx2fc_hba *hba)
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001386{
1387 struct fcoe_port *port = lport_priv(lport);
Bhanu Prakash Gollapudid36b3272011-05-27 11:47:27 -07001388 struct bnx2fc_lport *blport, *tmp;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001389
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001390 /* Stop the transmit retry timer */
1391 del_timer_sync(&port->timer);
1392
1393 /* Free existing transmit skbs */
1394 fcoe_clean_pending_queue(lport);
1395
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001396 /* Free queued packets for the receive thread */
1397 bnx2fc_clean_rx_queue(lport);
1398
1399 /* Detach from scsi-ml */
1400 fc_remove_host(lport->host);
1401 scsi_remove_host(lport->host);
1402
1403 /*
1404 * Note that only the physical lport will have the exchange manager.
1405 * for vports, this function is NOP
1406 */
1407 fc_exch_mgr_free(lport);
1408
1409 /* Free memory used by statistical counters */
1410 fc_lport_free_stats(lport);
1411
Bhanu Prakash Gollapudid36b3272011-05-27 11:47:27 -07001412 spin_lock_bh(&hba->hba_lock);
1413 list_for_each_entry_safe(blport, tmp, &hba->vports, list) {
1414 if (blport->lport == lport) {
1415 list_del(&blport->list);
1416 kfree(blport);
1417 }
1418 }
1419 spin_unlock_bh(&hba->hba_lock);
1420
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001421 /* Release Scsi_Host */
1422 scsi_host_put(lport->host);
1423}
1424
1425/**
1426 * bnx2fc_destroy - Destroy a bnx2fc FCoE interface
1427 *
1428 * @buffer: The name of the Ethernet interface to be destroyed
1429 * @kp: The associated kernel parameter
1430 *
1431 * Called from sysfs.
1432 *
1433 * Returns: 0 for success
1434 */
1435static int bnx2fc_destroy(struct net_device *netdev)
1436{
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001437 struct bnx2fc_interface *interface = NULL;
1438 struct bnx2fc_hba *hba;
1439 struct fc_lport *lport;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001440 int rc = 0;
1441
Nithin Sujir6702ca12011-03-17 17:13:27 -07001442 rtnl_lock();
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001443 mutex_lock(&bnx2fc_dev_lock);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001444
1445 interface = bnx2fc_interface_lookup(netdev);
1446 if (!interface || !interface->ctlr.lp) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001447 rc = -ENODEV;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001448 printk(KERN_ERR PFX "bnx2fc_destroy: interface or lport not found\n");
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001449 goto netdev_err;
1450 }
1451
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001452 hba = interface->hba;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001453
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001454 bnx2fc_netdev_cleanup(interface);
1455 lport = interface->ctlr.lp;
1456 bnx2fc_stop(interface);
1457 list_del(&interface->list);
1458 destroy_workqueue(interface->timer_work_queue);
1459 bnx2fc_interface_put(interface);
1460 bnx2fc_if_destroy(lport, hba);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001461
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001462netdev_err:
1463 mutex_unlock(&bnx2fc_dev_lock);
1464 rtnl_unlock();
1465 return rc;
1466}
1467
1468static void bnx2fc_destroy_work(struct work_struct *work)
1469{
1470 struct fcoe_port *port;
1471 struct fc_lport *lport;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001472 struct bnx2fc_interface *interface;
1473 struct bnx2fc_hba *hba;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001474
1475 port = container_of(work, struct fcoe_port, destroy_work);
1476 lport = port->lport;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001477 interface = port->priv;
1478 hba = interface->hba;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001479
1480 BNX2FC_HBA_DBG(lport, "Entered bnx2fc_destroy_work\n");
1481
1482 bnx2fc_port_shutdown(lport);
1483 rtnl_lock();
1484 mutex_lock(&bnx2fc_dev_lock);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001485 bnx2fc_if_destroy(lport, hba);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001486 mutex_unlock(&bnx2fc_dev_lock);
1487 rtnl_unlock();
1488}
1489
1490static void bnx2fc_unbind_adapter_devices(struct bnx2fc_hba *hba)
1491{
1492 bnx2fc_free_fw_resc(hba);
1493 bnx2fc_free_task_ctx(hba);
1494}
1495
1496/**
1497 * bnx2fc_bind_adapter_devices - binds bnx2fc adapter with the associated
1498 * pci structure
1499 *
1500 * @hba: Adapter instance
1501 */
1502static int bnx2fc_bind_adapter_devices(struct bnx2fc_hba *hba)
1503{
1504 if (bnx2fc_setup_task_ctx(hba))
1505 goto mem_err;
1506
1507 if (bnx2fc_setup_fw_resc(hba))
1508 goto mem_err;
1509
1510 return 0;
1511mem_err:
1512 bnx2fc_unbind_adapter_devices(hba);
1513 return -ENOMEM;
1514}
1515
1516static int bnx2fc_bind_pcidev(struct bnx2fc_hba *hba)
1517{
1518 struct cnic_dev *cnic;
1519
1520 if (!hba->cnic) {
1521 printk(KERN_ERR PFX "cnic is NULL\n");
1522 return -ENODEV;
1523 }
1524 cnic = hba->cnic;
1525 hba->pcidev = cnic->pcidev;
1526 if (hba->pcidev)
1527 pci_dev_get(hba->pcidev);
1528
1529 return 0;
1530}
1531
1532static void bnx2fc_unbind_pcidev(struct bnx2fc_hba *hba)
1533{
1534 if (hba->pcidev)
1535 pci_dev_put(hba->pcidev);
1536 hba->pcidev = NULL;
1537}
1538
1539
1540
1541/**
1542 * bnx2fc_ulp_start - cnic callback to initialize & start adapter instance
1543 *
1544 * @handle: transport handle pointing to adapter struture
1545 *
1546 * This function maps adapter structure to pcidev structure and initiates
1547 * firmware handshake to enable/initialize on-chip FCoE components.
1548 * This bnx2fc - cnic interface api callback is used after following
1549 * conditions are met -
1550 * a) underlying network interface is up (marked by event NETDEV_UP
1551 * from netdev
1552 * b) bnx2fc adatper structure is registered.
1553 */
1554static void bnx2fc_ulp_start(void *handle)
1555{
1556 struct bnx2fc_hba *hba = handle;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001557 struct bnx2fc_interface *interface;
1558 struct fc_lport *lport;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001559
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001560 mutex_lock(&bnx2fc_dev_lock);
1561
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001562 if (!test_bit(BNX2FC_FLAG_FW_INIT_DONE, &hba->flags))
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001563 bnx2fc_fw_init(hba);
1564
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001565 BNX2FC_MISC_DBG("bnx2fc started.\n");
1566
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001567 list_for_each_entry(interface, &if_list, list) {
1568 if (interface->hba == hba) {
1569 lport = interface->ctlr.lp;
1570 /* Kick off Fabric discovery*/
1571 printk(KERN_ERR PFX "ulp_init: start discovery\n");
1572 lport->tt.frame_send = bnx2fc_xmit;
1573 bnx2fc_start_disc(interface);
1574 }
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001575 }
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001576
1577 mutex_unlock(&bnx2fc_dev_lock);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001578}
1579
1580static void bnx2fc_port_shutdown(struct fc_lport *lport)
1581{
1582 BNX2FC_MISC_DBG("Entered %s\n", __func__);
1583 fc_fabric_logoff(lport);
1584 fc_lport_destroy(lport);
1585}
1586
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001587static void bnx2fc_stop(struct bnx2fc_interface *interface)
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001588{
1589 struct fc_lport *lport;
1590 struct fc_lport *vport;
1591
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001592 if (!test_bit(BNX2FC_FLAG_FW_INIT_DONE, &interface->hba->flags))
1593 return;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001594
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001595 lport = interface->ctlr.lp;
1596 bnx2fc_port_shutdown(lport);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001597
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001598 mutex_lock(&lport->lp_mutex);
1599 list_for_each_entry(vport, &lport->vports, list)
1600 fc_host_port_type(vport->host) =
1601 FC_PORTTYPE_UNKNOWN;
1602 mutex_unlock(&lport->lp_mutex);
1603 fc_host_port_type(lport->host) = FC_PORTTYPE_UNKNOWN;
1604 fcoe_ctlr_link_down(&interface->ctlr);
1605 fcoe_clean_pending_queue(lport);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001606}
1607
1608static int bnx2fc_fw_init(struct bnx2fc_hba *hba)
1609{
1610#define BNX2FC_INIT_POLL_TIME (1000 / HZ)
1611 int rc = -1;
1612 int i = HZ;
1613
1614 rc = bnx2fc_bind_adapter_devices(hba);
1615 if (rc) {
1616 printk(KERN_ALERT PFX
1617 "bnx2fc_bind_adapter_devices failed - rc = %d\n", rc);
1618 goto err_out;
1619 }
1620
1621 rc = bnx2fc_send_fw_fcoe_init_msg(hba);
1622 if (rc) {
1623 printk(KERN_ALERT PFX
1624 "bnx2fc_send_fw_fcoe_init_msg failed - rc = %d\n", rc);
1625 goto err_unbind;
1626 }
1627
1628 /*
1629 * Wait until the adapter init message is complete, and adapter
1630 * state is UP.
1631 */
1632 while (!test_bit(ADAPTER_STATE_UP, &hba->adapter_state) && i--)
1633 msleep(BNX2FC_INIT_POLL_TIME);
1634
1635 if (!test_bit(ADAPTER_STATE_UP, &hba->adapter_state)) {
1636 printk(KERN_ERR PFX "bnx2fc_start: %s failed to initialize. "
1637 "Ignoring...\n",
1638 hba->cnic->netdev->name);
1639 rc = -1;
1640 goto err_unbind;
1641 }
1642
1643
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001644 set_bit(BNX2FC_FLAG_FW_INIT_DONE, &hba->flags);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001645 return 0;
1646
1647err_unbind:
1648 bnx2fc_unbind_adapter_devices(hba);
1649err_out:
1650 return rc;
1651}
1652
1653static void bnx2fc_fw_destroy(struct bnx2fc_hba *hba)
1654{
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001655 if (test_and_clear_bit(BNX2FC_FLAG_FW_INIT_DONE, &hba->flags)) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001656 if (bnx2fc_send_fw_fcoe_destroy_msg(hba) == 0) {
1657 init_timer(&hba->destroy_timer);
1658 hba->destroy_timer.expires = BNX2FC_FW_TIMEOUT +
1659 jiffies;
1660 hba->destroy_timer.function = bnx2fc_destroy_timer;
1661 hba->destroy_timer.data = (unsigned long)hba;
1662 add_timer(&hba->destroy_timer);
1663 wait_event_interruptible(hba->destroy_wait,
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001664 test_bit(BNX2FC_FLAG_DESTROY_CMPL,
1665 &hba->flags));
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001666 /* This should never happen */
1667 if (signal_pending(current))
1668 flush_signals(current);
1669
1670 del_timer_sync(&hba->destroy_timer);
1671 }
1672 bnx2fc_unbind_adapter_devices(hba);
1673 }
1674}
1675
1676/**
1677 * bnx2fc_ulp_stop - cnic callback to shutdown adapter instance
1678 *
1679 * @handle: transport handle pointing to adapter structure
1680 *
1681 * Driver checks if adapter is already in shutdown mode, if not start
1682 * the shutdown process.
1683 */
1684static void bnx2fc_ulp_stop(void *handle)
1685{
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001686 struct bnx2fc_hba *hba = handle;
1687 struct bnx2fc_interface *interface;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001688
1689 printk(KERN_ERR "ULP_STOP\n");
1690
1691 mutex_lock(&bnx2fc_dev_lock);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001692 if (!test_bit(BNX2FC_FLAG_FW_INIT_DONE, &hba->flags))
1693 goto exit;
1694 list_for_each_entry(interface, &if_list, list) {
1695 if (interface->hba == hba)
1696 bnx2fc_stop(interface);
1697 }
1698 BUG_ON(hba->num_ofld_sess != 0);
1699
1700 mutex_lock(&hba->hba_mutex);
1701 clear_bit(ADAPTER_STATE_UP, &hba->adapter_state);
1702 clear_bit(ADAPTER_STATE_GOING_DOWN,
1703 &hba->adapter_state);
1704
1705 clear_bit(ADAPTER_STATE_READY, &hba->adapter_state);
1706 mutex_unlock(&hba->hba_mutex);
1707
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001708 bnx2fc_fw_destroy(hba);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001709exit:
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001710 mutex_unlock(&bnx2fc_dev_lock);
1711}
1712
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001713static void bnx2fc_start_disc(struct bnx2fc_interface *interface)
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001714{
1715 struct fc_lport *lport;
1716 int wait_cnt = 0;
1717
1718 BNX2FC_MISC_DBG("Entered %s\n", __func__);
1719 /* Kick off FIP/FLOGI */
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001720 if (!test_bit(BNX2FC_FLAG_FW_INIT_DONE, &interface->hba->flags)) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001721 printk(KERN_ERR PFX "Init not done yet\n");
1722 return;
1723 }
1724
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001725 lport = interface->ctlr.lp;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001726 BNX2FC_HBA_DBG(lport, "calling fc_fabric_login\n");
1727
1728 if (!bnx2fc_link_ok(lport)) {
1729 BNX2FC_HBA_DBG(lport, "ctlr_link_up\n");
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001730 fcoe_ctlr_link_up(&interface->ctlr);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001731 fc_host_port_type(lport->host) = FC_PORTTYPE_NPORT;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001732 set_bit(ADAPTER_STATE_READY, &interface->hba->adapter_state);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001733 }
1734
1735 /* wait for the FCF to be selected before issuing FLOGI */
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001736 while (!interface->ctlr.sel_fcf) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001737 msleep(250);
1738 /* give up after 3 secs */
1739 if (++wait_cnt > 12)
1740 break;
1741 }
1742 fc_lport_init(lport);
1743 fc_fabric_login(lport);
1744}
1745
1746
1747/**
1748 * bnx2fc_ulp_init - Initialize an adapter instance
1749 *
1750 * @dev : cnic device handle
1751 * Called from cnic_register_driver() context to initialize all
1752 * enumerated cnic devices. This routine allocates adapter structure
1753 * and other device specific resources.
1754 */
1755static void bnx2fc_ulp_init(struct cnic_dev *dev)
1756{
1757 struct bnx2fc_hba *hba;
1758 int rc = 0;
1759
1760 BNX2FC_MISC_DBG("Entered %s\n", __func__);
1761 /* bnx2fc works only when bnx2x is loaded */
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001762 if (!test_bit(CNIC_F_BNX2X_CLASS, &dev->flags) ||
1763 (dev->max_fcoe_conn == 0)) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001764 printk(KERN_ERR PFX "bnx2fc FCoE not supported on %s,"
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001765 " flags: %lx fcoe_conn: %d\n",
1766 dev->netdev->name, dev->flags, dev->max_fcoe_conn);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001767 return;
1768 }
1769
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001770 hba = bnx2fc_hba_create(dev);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001771 if (!hba) {
1772 printk(KERN_ERR PFX "hba initialization failed\n");
1773 return;
1774 }
1775
1776 /* Add HBA to the adapter list */
1777 mutex_lock(&bnx2fc_dev_lock);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001778 list_add_tail(&hba->list, &adapter_list);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001779 adapter_count++;
1780 mutex_unlock(&bnx2fc_dev_lock);
1781
1782 clear_bit(BNX2FC_CNIC_REGISTERED, &hba->reg_with_cnic);
1783 rc = dev->register_device(dev, CNIC_ULP_FCOE,
1784 (void *) hba);
1785 if (rc)
Bhanu Prakash Gollapudib2a554f2011-06-27 23:30:53 -07001786 printk(KERN_ERR PFX "register_device failed, rc = %d\n", rc);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001787 else
1788 set_bit(BNX2FC_CNIC_REGISTERED, &hba->reg_with_cnic);
1789}
1790
1791
1792static int bnx2fc_disable(struct net_device *netdev)
1793{
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001794 struct bnx2fc_interface *interface;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001795 int rc = 0;
1796
Nithin Sujir6702ca12011-03-17 17:13:27 -07001797 rtnl_lock();
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001798 mutex_lock(&bnx2fc_dev_lock);
1799
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001800 interface = bnx2fc_interface_lookup(netdev);
1801 if (!interface || !interface->ctlr.lp) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001802 rc = -ENODEV;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001803 printk(KERN_ERR PFX "bnx2fc_disable: interface or lport not found\n");
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001804 } else {
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001805 fcoe_ctlr_link_down(&interface->ctlr);
1806 fcoe_clean_pending_queue(interface->ctlr.lp);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001807 }
1808
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001809 mutex_unlock(&bnx2fc_dev_lock);
1810 rtnl_unlock();
1811 return rc;
1812}
1813
1814
1815static int bnx2fc_enable(struct net_device *netdev)
1816{
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001817 struct bnx2fc_interface *interface;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001818 int rc = 0;
1819
Nithin Sujir6702ca12011-03-17 17:13:27 -07001820 rtnl_lock();
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001821 mutex_lock(&bnx2fc_dev_lock);
1822
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001823 interface = bnx2fc_interface_lookup(netdev);
1824 if (!interface || !interface->ctlr.lp) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001825 rc = -ENODEV;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001826 printk(KERN_ERR PFX "bnx2fc_enable: interface or lport not found\n");
1827 } else if (!bnx2fc_link_ok(interface->ctlr.lp))
1828 fcoe_ctlr_link_up(&interface->ctlr);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001829
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001830 mutex_unlock(&bnx2fc_dev_lock);
1831 rtnl_unlock();
1832 return rc;
1833}
1834
1835/**
1836 * bnx2fc_create - Create bnx2fc FCoE interface
1837 *
1838 * @buffer: The name of Ethernet interface to create on
1839 * @kp: The associated kernel param
1840 *
1841 * Called from sysfs.
1842 *
1843 * Returns: 0 for success
1844 */
1845static int bnx2fc_create(struct net_device *netdev, enum fip_state fip_mode)
1846{
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001847 struct bnx2fc_interface *interface;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001848 struct bnx2fc_hba *hba;
1849 struct net_device *phys_dev;
1850 struct fc_lport *lport;
1851 struct ethtool_drvinfo drvinfo;
1852 int rc = 0;
1853 int vlan_id;
1854
1855 BNX2FC_MISC_DBG("Entered bnx2fc_create\n");
1856 if (fip_mode != FIP_MODE_FABRIC) {
1857 printk(KERN_ERR "fip mode not FABRIC\n");
1858 return -EIO;
1859 }
1860
Nithin Sujir6702ca12011-03-17 17:13:27 -07001861 rtnl_lock();
1862
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001863 mutex_lock(&bnx2fc_dev_lock);
1864
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001865 if (!try_module_get(THIS_MODULE)) {
1866 rc = -EINVAL;
1867 goto mod_err;
1868 }
1869
1870 /* obtain physical netdev */
1871 if (netdev->priv_flags & IFF_802_1Q_VLAN) {
1872 phys_dev = vlan_dev_real_dev(netdev);
1873 vlan_id = vlan_dev_vlan_id(netdev);
1874 } else {
1875 printk(KERN_ERR PFX "Not a vlan device\n");
1876 rc = -EINVAL;
1877 goto netdev_err;
1878 }
1879 /* verify if the physical device is a netxtreme2 device */
1880 if (phys_dev->ethtool_ops && phys_dev->ethtool_ops->get_drvinfo) {
1881 memset(&drvinfo, 0, sizeof(drvinfo));
1882 phys_dev->ethtool_ops->get_drvinfo(phys_dev, &drvinfo);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001883 if (strncmp(drvinfo.driver, "bnx2x", strlen("bnx2x"))) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001884 printk(KERN_ERR PFX "Not a netxtreme2 device\n");
1885 rc = -EINVAL;
1886 goto netdev_err;
1887 }
1888 } else {
1889 printk(KERN_ERR PFX "unable to obtain drv_info\n");
1890 rc = -EINVAL;
1891 goto netdev_err;
1892 }
1893
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001894 /* obtain interface and initialize rest of the structure */
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001895 hba = bnx2fc_hba_lookup(phys_dev);
1896 if (!hba) {
1897 rc = -ENODEV;
1898 printk(KERN_ERR PFX "bnx2fc_create: hba not found\n");
1899 goto netdev_err;
1900 }
1901
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001902 if (bnx2fc_interface_lookup(netdev)) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001903 rc = -EEXIST;
1904 goto netdev_err;
1905 }
1906
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001907 interface = bnx2fc_interface_create(hba, netdev, fip_mode);
1908 if (!interface) {
1909 printk(KERN_ERR PFX "bnx2fc_interface_create failed\n");
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001910 goto ifput_err;
1911 }
1912
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001913 interface->vlan_id = vlan_id;
1914 interface->vlan_enabled = 1;
1915
1916 interface->timer_work_queue =
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001917 create_singlethread_workqueue("bnx2fc_timer_wq");
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001918 if (!interface->timer_work_queue) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001919 printk(KERN_ERR PFX "ulp_init could not create timer_wq\n");
1920 rc = -EINVAL;
1921 goto ifput_err;
1922 }
1923
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001924 lport = bnx2fc_if_create(interface, &interface->hba->pcidev->dev, 0);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001925 if (!lport) {
1926 printk(KERN_ERR PFX "Failed to create interface (%s)\n",
1927 netdev->name);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001928 bnx2fc_netdev_cleanup(interface);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001929 rc = -EINVAL;
1930 goto if_create_err;
1931 }
1932
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001933 /* Add interface to if_list */
1934 list_add_tail(&interface->list, &if_list);
1935
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001936 lport->boot_time = jiffies;
1937
1938 /* Make this master N_port */
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001939 interface->ctlr.lp = lport;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001940
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001941 BNX2FC_HBA_DBG(lport, "create: START DISC\n");
1942 bnx2fc_start_disc(interface);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001943 /*
1944 * Release from kref_init in bnx2fc_interface_setup, on success
1945 * lport should be holding a reference taken in bnx2fc_if_create
1946 */
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001947 bnx2fc_interface_put(interface);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001948 /* put netdev that was held while calling dev_get_by_name */
1949 mutex_unlock(&bnx2fc_dev_lock);
1950 rtnl_unlock();
1951 return 0;
1952
1953if_create_err:
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001954 destroy_workqueue(interface->timer_work_queue);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001955ifput_err:
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001956 bnx2fc_interface_put(interface);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001957netdev_err:
1958 module_put(THIS_MODULE);
1959mod_err:
1960 mutex_unlock(&bnx2fc_dev_lock);
1961 rtnl_unlock();
1962 return rc;
1963}
1964
1965/**
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001966 * bnx2fc_find_hba_for_cnic - maps cnic instance to bnx2fc hba instance
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001967 *
1968 * @cnic: Pointer to cnic device instance
1969 *
1970 **/
1971static struct bnx2fc_hba *bnx2fc_find_hba_for_cnic(struct cnic_dev *cnic)
1972{
1973 struct list_head *list;
1974 struct list_head *temp;
1975 struct bnx2fc_hba *hba;
1976
1977 /* Called with bnx2fc_dev_lock held */
1978 list_for_each_safe(list, temp, &adapter_list) {
1979 hba = (struct bnx2fc_hba *)list;
1980 if (hba->cnic == cnic)
1981 return hba;
1982 }
1983 return NULL;
1984}
1985
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001986static struct bnx2fc_interface *bnx2fc_interface_lookup(struct net_device
1987 *netdev)
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001988{
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001989 struct bnx2fc_interface *interface;
1990
1991 /* Called with bnx2fc_dev_lock held */
1992 list_for_each_entry(interface, &if_list, list) {
1993 if (interface->netdev == netdev)
1994 return interface;
1995 }
1996 return NULL;
1997}
1998
1999static struct bnx2fc_hba *bnx2fc_hba_lookup(struct net_device
2000 *phys_dev)
2001{
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002002 struct bnx2fc_hba *hba;
2003
2004 /* Called with bnx2fc_dev_lock held */
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002005 list_for_each_entry(hba, &adapter_list, list) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002006 if (hba->phys_dev == phys_dev)
2007 return hba;
2008 }
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002009 printk(KERN_ERR PFX "adapter_lookup: hba NULL\n");
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002010 return NULL;
2011}
2012
2013/**
2014 * bnx2fc_ulp_exit - shuts down adapter instance and frees all resources
2015 *
2016 * @dev cnic device handle
2017 */
2018static void bnx2fc_ulp_exit(struct cnic_dev *dev)
2019{
2020 struct bnx2fc_hba *hba;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002021 struct bnx2fc_interface *interface, *tmp;
2022 struct fc_lport *lport;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002023
2024 BNX2FC_MISC_DBG("Entered bnx2fc_ulp_exit\n");
2025
2026 if (!test_bit(CNIC_F_BNX2X_CLASS, &dev->flags)) {
2027 printk(KERN_ERR PFX "bnx2fc port check: %s, flags: %lx\n",
2028 dev->netdev->name, dev->flags);
2029 return;
2030 }
2031
2032 mutex_lock(&bnx2fc_dev_lock);
2033 hba = bnx2fc_find_hba_for_cnic(dev);
2034 if (!hba) {
2035 printk(KERN_ERR PFX "bnx2fc_ulp_exit: hba not found, dev 0%p\n",
2036 dev);
2037 mutex_unlock(&bnx2fc_dev_lock);
2038 return;
2039 }
2040
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002041 list_del_init(&hba->list);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002042 adapter_count--;
2043
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002044 list_for_each_entry_safe(interface, tmp, &if_list, list) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002045 /* destroy not called yet, move to quiesced list */
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002046 if (interface->hba == hba) {
2047 bnx2fc_netdev_cleanup(interface);
2048 bnx2fc_stop(interface);
2049
2050 list_del(&interface->list);
2051 lport = interface->ctlr.lp;
2052 bnx2fc_interface_put(interface);
2053 bnx2fc_if_destroy(lport, hba);
2054 }
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002055 }
2056 mutex_unlock(&bnx2fc_dev_lock);
2057
2058 bnx2fc_ulp_stop(hba);
2059 /* unregister cnic device */
2060 if (test_and_clear_bit(BNX2FC_CNIC_REGISTERED, &hba->reg_with_cnic))
2061 hba->cnic->unregister_device(hba->cnic, CNIC_ULP_FCOE);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002062 bnx2fc_hba_destroy(hba);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002063}
2064
2065/**
2066 * bnx2fc_fcoe_reset - Resets the fcoe
2067 *
2068 * @shost: shost the reset is from
2069 *
2070 * Returns: always 0
2071 */
2072static int bnx2fc_fcoe_reset(struct Scsi_Host *shost)
2073{
2074 struct fc_lport *lport = shost_priv(shost);
2075 fc_lport_reset(lport);
2076 return 0;
2077}
2078
2079
2080static bool bnx2fc_match(struct net_device *netdev)
2081{
2082 mutex_lock(&bnx2fc_dev_lock);
2083 if (netdev->priv_flags & IFF_802_1Q_VLAN) {
2084 struct net_device *phys_dev = vlan_dev_real_dev(netdev);
2085
2086 if (bnx2fc_hba_lookup(phys_dev)) {
2087 mutex_unlock(&bnx2fc_dev_lock);
2088 return true;
2089 }
2090 }
2091 mutex_unlock(&bnx2fc_dev_lock);
2092 return false;
2093}
2094
2095
2096static struct fcoe_transport bnx2fc_transport = {
2097 .name = {"bnx2fc"},
2098 .attached = false,
2099 .list = LIST_HEAD_INIT(bnx2fc_transport.list),
2100 .match = bnx2fc_match,
2101 .create = bnx2fc_create,
2102 .destroy = bnx2fc_destroy,
2103 .enable = bnx2fc_enable,
2104 .disable = bnx2fc_disable,
2105};
2106
2107/**
2108 * bnx2fc_percpu_thread_create - Create a receive thread for an
2109 * online CPU
2110 *
2111 * @cpu: cpu index for the online cpu
2112 */
2113static void bnx2fc_percpu_thread_create(unsigned int cpu)
2114{
2115 struct bnx2fc_percpu_s *p;
2116 struct task_struct *thread;
2117
2118 p = &per_cpu(bnx2fc_percpu, cpu);
2119
2120 thread = kthread_create(bnx2fc_percpu_io_thread,
2121 (void *)p,
2122 "bnx2fc_thread/%d", cpu);
2123 /* bind thread to the cpu */
2124 if (likely(!IS_ERR(p->iothread))) {
2125 kthread_bind(thread, cpu);
2126 p->iothread = thread;
2127 wake_up_process(thread);
2128 }
2129}
2130
2131static void bnx2fc_percpu_thread_destroy(unsigned int cpu)
2132{
2133 struct bnx2fc_percpu_s *p;
2134 struct task_struct *thread;
2135 struct bnx2fc_work *work, *tmp;
2136 LIST_HEAD(work_list);
2137
2138 BNX2FC_MISC_DBG("destroying io thread for CPU %d\n", cpu);
2139
2140 /* Prevent any new work from being queued for this CPU */
2141 p = &per_cpu(bnx2fc_percpu, cpu);
2142 spin_lock_bh(&p->fp_work_lock);
2143 thread = p->iothread;
2144 p->iothread = NULL;
2145
2146
2147 /* Free all work in the list */
2148 list_for_each_entry_safe(work, tmp, &work_list, list) {
2149 list_del_init(&work->list);
2150 bnx2fc_process_cq_compl(work->tgt, work->wqe);
2151 kfree(work);
2152 }
2153
2154 spin_unlock_bh(&p->fp_work_lock);
2155
2156 if (thread)
2157 kthread_stop(thread);
2158}
2159
2160/**
2161 * bnx2fc_cpu_callback - Handler for CPU hotplug events
2162 *
2163 * @nfb: The callback data block
2164 * @action: The event triggering the callback
2165 * @hcpu: The index of the CPU that the event is for
2166 *
2167 * This creates or destroys per-CPU data for fcoe
2168 *
2169 * Returns NOTIFY_OK always.
2170 */
2171static int bnx2fc_cpu_callback(struct notifier_block *nfb,
2172 unsigned long action, void *hcpu)
2173{
2174 unsigned cpu = (unsigned long)hcpu;
2175
2176 switch (action) {
2177 case CPU_ONLINE:
2178 case CPU_ONLINE_FROZEN:
2179 printk(PFX "CPU %x online: Create Rx thread\n", cpu);
2180 bnx2fc_percpu_thread_create(cpu);
2181 break;
2182 case CPU_DEAD:
2183 case CPU_DEAD_FROZEN:
2184 printk(PFX "CPU %x offline: Remove Rx thread\n", cpu);
2185 bnx2fc_percpu_thread_destroy(cpu);
2186 break;
2187 default:
2188 break;
2189 }
2190 return NOTIFY_OK;
2191}
2192
2193/**
2194 * bnx2fc_mod_init - module init entry point
2195 *
2196 * Initialize driver wide global data structures, and register
2197 * with cnic module
2198 **/
2199static int __init bnx2fc_mod_init(void)
2200{
2201 struct fcoe_percpu_s *bg;
2202 struct task_struct *l2_thread;
2203 int rc = 0;
2204 unsigned int cpu = 0;
2205 struct bnx2fc_percpu_s *p;
2206
2207 printk(KERN_INFO PFX "%s", version);
2208
2209 /* register as a fcoe transport */
2210 rc = fcoe_transport_attach(&bnx2fc_transport);
2211 if (rc) {
2212 printk(KERN_ERR "failed to register an fcoe transport, check "
2213 "if libfcoe is loaded\n");
2214 goto out;
2215 }
2216
2217 INIT_LIST_HEAD(&adapter_list);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002218 INIT_LIST_HEAD(&if_list);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002219 mutex_init(&bnx2fc_dev_lock);
2220 adapter_count = 0;
2221
2222 /* Attach FC transport template */
2223 rc = bnx2fc_attach_transport();
2224 if (rc)
2225 goto detach_ft;
2226
2227 bnx2fc_wq = alloc_workqueue("bnx2fc", 0, 0);
2228 if (!bnx2fc_wq) {
2229 rc = -ENOMEM;
2230 goto release_bt;
2231 }
2232
2233 bg = &bnx2fc_global;
2234 skb_queue_head_init(&bg->fcoe_rx_list);
2235 l2_thread = kthread_create(bnx2fc_l2_rcv_thread,
2236 (void *)bg,
2237 "bnx2fc_l2_thread");
2238 if (IS_ERR(l2_thread)) {
2239 rc = PTR_ERR(l2_thread);
2240 goto free_wq;
2241 }
2242 wake_up_process(l2_thread);
2243 spin_lock_bh(&bg->fcoe_rx_list.lock);
2244 bg->thread = l2_thread;
2245 spin_unlock_bh(&bg->fcoe_rx_list.lock);
2246
2247 for_each_possible_cpu(cpu) {
2248 p = &per_cpu(bnx2fc_percpu, cpu);
2249 INIT_LIST_HEAD(&p->work_list);
2250 spin_lock_init(&p->fp_work_lock);
2251 }
2252
2253 for_each_online_cpu(cpu) {
2254 bnx2fc_percpu_thread_create(cpu);
2255 }
2256
2257 /* Initialize per CPU interrupt thread */
2258 register_hotcpu_notifier(&bnx2fc_cpu_notifier);
2259
2260 cnic_register_driver(CNIC_ULP_FCOE, &bnx2fc_cnic_cb);
2261
2262 return 0;
2263
2264free_wq:
2265 destroy_workqueue(bnx2fc_wq);
2266release_bt:
2267 bnx2fc_release_transport();
2268detach_ft:
2269 fcoe_transport_detach(&bnx2fc_transport);
2270out:
2271 return rc;
2272}
2273
2274static void __exit bnx2fc_mod_exit(void)
2275{
2276 LIST_HEAD(to_be_deleted);
2277 struct bnx2fc_hba *hba, *next;
2278 struct fcoe_percpu_s *bg;
2279 struct task_struct *l2_thread;
2280 struct sk_buff *skb;
2281 unsigned int cpu = 0;
2282
2283 /*
2284 * NOTE: Since cnic calls register_driver routine rtnl_lock,
2285 * it will have higher precedence than bnx2fc_dev_lock.
2286 * unregister_device() cannot be called with bnx2fc_dev_lock
2287 * held.
2288 */
2289 mutex_lock(&bnx2fc_dev_lock);
2290 list_splice(&adapter_list, &to_be_deleted);
2291 INIT_LIST_HEAD(&adapter_list);
2292 adapter_count = 0;
2293 mutex_unlock(&bnx2fc_dev_lock);
2294
2295 /* Unregister with cnic */
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002296 list_for_each_entry_safe(hba, next, &to_be_deleted, list) {
2297 list_del_init(&hba->list);
2298 printk(KERN_ERR PFX "MOD_EXIT:destroy hba = 0x%p\n",
2299 hba);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002300 bnx2fc_ulp_stop(hba);
2301 /* unregister cnic device */
2302 if (test_and_clear_bit(BNX2FC_CNIC_REGISTERED,
2303 &hba->reg_with_cnic))
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002304 hba->cnic->unregister_device(hba->cnic,
2305 CNIC_ULP_FCOE);
2306 bnx2fc_hba_destroy(hba);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002307 }
2308 cnic_unregister_driver(CNIC_ULP_FCOE);
2309
2310 /* Destroy global thread */
2311 bg = &bnx2fc_global;
2312 spin_lock_bh(&bg->fcoe_rx_list.lock);
2313 l2_thread = bg->thread;
2314 bg->thread = NULL;
2315 while ((skb = __skb_dequeue(&bg->fcoe_rx_list)) != NULL)
2316 kfree_skb(skb);
2317
2318 spin_unlock_bh(&bg->fcoe_rx_list.lock);
2319
2320 if (l2_thread)
2321 kthread_stop(l2_thread);
2322
2323 unregister_hotcpu_notifier(&bnx2fc_cpu_notifier);
2324
2325 /* Destroy per cpu threads */
2326 for_each_online_cpu(cpu) {
2327 bnx2fc_percpu_thread_destroy(cpu);
2328 }
2329
2330 destroy_workqueue(bnx2fc_wq);
2331 /*
2332 * detach from scsi transport
2333 * must happen after all destroys are done
2334 */
2335 bnx2fc_release_transport();
2336
2337 /* detach from fcoe transport */
2338 fcoe_transport_detach(&bnx2fc_transport);
2339}
2340
2341module_init(bnx2fc_mod_init);
2342module_exit(bnx2fc_mod_exit);
2343
2344static struct fc_function_template bnx2fc_transport_function = {
2345 .show_host_node_name = 1,
2346 .show_host_port_name = 1,
2347 .show_host_supported_classes = 1,
2348 .show_host_supported_fc4s = 1,
2349 .show_host_active_fc4s = 1,
2350 .show_host_maxframe_size = 1,
2351
2352 .show_host_port_id = 1,
2353 .show_host_supported_speeds = 1,
2354 .get_host_speed = fc_get_host_speed,
2355 .show_host_speed = 1,
2356 .show_host_port_type = 1,
2357 .get_host_port_state = fc_get_host_port_state,
2358 .show_host_port_state = 1,
2359 .show_host_symbolic_name = 1,
2360
2361 .dd_fcrport_size = (sizeof(struct fc_rport_libfc_priv) +
2362 sizeof(struct bnx2fc_rport)),
2363 .show_rport_maxframe_size = 1,
2364 .show_rport_supported_classes = 1,
2365
2366 .show_host_fabric_name = 1,
2367 .show_starget_node_name = 1,
2368 .show_starget_port_name = 1,
2369 .show_starget_port_id = 1,
2370 .set_rport_dev_loss_tmo = fc_set_rport_loss_tmo,
2371 .show_rport_dev_loss_tmo = 1,
2372 .get_fc_host_stats = bnx2fc_get_host_stats,
2373
2374 .issue_fc_host_lip = bnx2fc_fcoe_reset,
2375
2376 .terminate_rport_io = fc_rport_terminate_io,
2377
2378 .vport_create = bnx2fc_vport_create,
2379 .vport_delete = bnx2fc_vport_destroy,
2380 .vport_disable = bnx2fc_vport_disable,
2381};
2382
2383static struct fc_function_template bnx2fc_vport_xport_function = {
2384 .show_host_node_name = 1,
2385 .show_host_port_name = 1,
2386 .show_host_supported_classes = 1,
2387 .show_host_supported_fc4s = 1,
2388 .show_host_active_fc4s = 1,
2389 .show_host_maxframe_size = 1,
2390
2391 .show_host_port_id = 1,
2392 .show_host_supported_speeds = 1,
2393 .get_host_speed = fc_get_host_speed,
2394 .show_host_speed = 1,
2395 .show_host_port_type = 1,
2396 .get_host_port_state = fc_get_host_port_state,
2397 .show_host_port_state = 1,
2398 .show_host_symbolic_name = 1,
2399
2400 .dd_fcrport_size = (sizeof(struct fc_rport_libfc_priv) +
2401 sizeof(struct bnx2fc_rport)),
2402 .show_rport_maxframe_size = 1,
2403 .show_rport_supported_classes = 1,
2404
2405 .show_host_fabric_name = 1,
2406 .show_starget_node_name = 1,
2407 .show_starget_port_name = 1,
2408 .show_starget_port_id = 1,
2409 .set_rport_dev_loss_tmo = fc_set_rport_loss_tmo,
2410 .show_rport_dev_loss_tmo = 1,
2411 .get_fc_host_stats = fc_get_host_stats,
2412 .issue_fc_host_lip = bnx2fc_fcoe_reset,
2413 .terminate_rport_io = fc_rport_terminate_io,
2414};
2415
2416/**
2417 * scsi_host_template structure used while registering with SCSI-ml
2418 */
2419static struct scsi_host_template bnx2fc_shost_template = {
2420 .module = THIS_MODULE,
2421 .name = "Broadcom Offload FCoE Initiator",
2422 .queuecommand = bnx2fc_queuecommand,
2423 .eh_abort_handler = bnx2fc_eh_abort, /* abts */
2424 .eh_device_reset_handler = bnx2fc_eh_device_reset, /* lun reset */
2425 .eh_target_reset_handler = bnx2fc_eh_target_reset, /* tgt reset */
2426 .eh_host_reset_handler = fc_eh_host_reset,
2427 .slave_alloc = fc_slave_alloc,
2428 .change_queue_depth = fc_change_queue_depth,
2429 .change_queue_type = fc_change_queue_type,
2430 .this_id = -1,
2431 .cmd_per_lun = 3,
Bhanu Gollapudi0ea5c272011-03-17 17:13:29 -07002432 .can_queue = BNX2FC_CAN_QUEUE,
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002433 .use_clustering = ENABLE_CLUSTERING,
2434 .sg_tablesize = BNX2FC_MAX_BDS_PER_CMD,
2435 .max_sectors = 512,
2436};
2437
2438static struct libfc_function_template bnx2fc_libfc_fcn_templ = {
2439 .frame_send = bnx2fc_xmit,
2440 .elsct_send = bnx2fc_elsct_send,
2441 .fcp_abort_io = bnx2fc_abort_io,
2442 .fcp_cleanup = bnx2fc_cleanup,
2443 .rport_event_callback = bnx2fc_rport_event_handler,
2444};
2445
2446/**
2447 * bnx2fc_cnic_cb - global template of bnx2fc - cnic driver interface
2448 * structure carrying callback function pointers
2449 */
2450static struct cnic_ulp_ops bnx2fc_cnic_cb = {
2451 .owner = THIS_MODULE,
2452 .cnic_init = bnx2fc_ulp_init,
2453 .cnic_exit = bnx2fc_ulp_exit,
2454 .cnic_start = bnx2fc_ulp_start,
2455 .cnic_stop = bnx2fc_ulp_stop,
2456 .indicate_kcqes = bnx2fc_indicate_kcqe,
2457 .indicate_netevent = bnx2fc_indicate_netevent,
2458};