blob: 833e9122e0189e2f8b7ebe1cf2c30ecf238d1d7c [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 *
Bhanu Prakash Gollapudi9b35baa2011-07-27 11:32:13 -07006 * Copyright (c) 2008 - 2011 Broadcom Corporation
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08007 *
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
Bhanu Prakash Gollapudi9b35baa2011-07-27 11:32:13 -070025#define DRV_MODULE_RELDATE "Jun 23, 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 Decotigny8ae6dac2011-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 Decotigny8ae6dac2011-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 Decotigny8ae6dac2011-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 Decotigny8ae6dac2011-04-27 18:32:38 +0000693 case SPEED_10000:
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800694 lport->link_speed = FC_PORTSPEED_10GBIT;
David Decotigny8ae6dac2011-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
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800911 lport->service_params = (FCP_SPPF_INIT_FCN | FCP_SPPF_RD_XRDY_DIS |
912 FCP_SPPF_RETRY | FCP_SPPF_CONF_COMPL);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800913 lport->does_npiv = 1;
914
915 memset(&lport->rnid_gen, 0, sizeof(struct fc_els_rnid_gen));
916 lport->rnid_gen.rnid_atype = BNX2FC_RNID_HBA;
917
918 /* alloc stats structure */
919 if (fc_lport_init_stats(lport))
920 return -ENOMEM;
921
922 /* Finish fc_lport configuration */
923 fc_lport_config(lport);
924
925 return 0;
926}
927
928/**
929 * bnx2fc_fip_recv - handle a received FIP frame.
930 *
931 * @skb: the received skb
932 * @dev: associated &net_device
933 * @ptype: the &packet_type structure which was used to register this handler.
934 * @orig_dev: original receive &net_device, in case @ dev is a bond.
935 *
936 * Returns: 0 for success
937 */
938static int bnx2fc_fip_recv(struct sk_buff *skb, struct net_device *dev,
939 struct packet_type *ptype,
940 struct net_device *orig_dev)
941{
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700942 struct bnx2fc_interface *interface;
943 interface = container_of(ptype, struct bnx2fc_interface,
944 fip_packet_type);
945 fcoe_ctlr_recv(&interface->ctlr, skb);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800946 return 0;
947}
948
949/**
950 * bnx2fc_update_src_mac - Update Ethernet MAC filters.
951 *
952 * @fip: FCoE controller.
953 * @old: Unicast MAC address to delete if the MAC is non-zero.
954 * @new: Unicast MAC address to add.
955 *
956 * Remove any previously-set unicast MAC filter.
957 * Add secondary FCoE MAC address filter for our OUI.
958 */
959static void bnx2fc_update_src_mac(struct fc_lport *lport, u8 *addr)
960{
961 struct fcoe_port *port = lport_priv(lport);
962
963 memcpy(port->data_src_addr, addr, ETH_ALEN);
964}
965
966/**
967 * bnx2fc_get_src_mac - return the ethernet source address for an lport
968 *
969 * @lport: libfc port
970 */
971static u8 *bnx2fc_get_src_mac(struct fc_lport *lport)
972{
973 struct fcoe_port *port;
974
975 port = (struct fcoe_port *)lport_priv(lport);
976 return port->data_src_addr;
977}
978
979/**
980 * bnx2fc_fip_send - send an Ethernet-encapsulated FIP frame.
981 *
982 * @fip: FCoE controller.
983 * @skb: FIP Packet.
984 */
985static void bnx2fc_fip_send(struct fcoe_ctlr *fip, struct sk_buff *skb)
986{
987 skb->dev = bnx2fc_from_ctlr(fip)->netdev;
988 dev_queue_xmit(skb);
989}
990
991static int bnx2fc_vport_create(struct fc_vport *vport, bool disabled)
992{
993 struct Scsi_Host *shost = vport_to_shost(vport);
994 struct fc_lport *n_port = shost_priv(shost);
995 struct fcoe_port *port = lport_priv(n_port);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700996 struct bnx2fc_interface *interface = port->priv;
997 struct net_device *netdev = interface->netdev;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800998 struct fc_lport *vn_port;
999
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001000 if (!test_bit(BNX2FC_FLAG_FW_INIT_DONE, &interface->hba->flags)) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001001 printk(KERN_ERR PFX "vn ports cannot be created on"
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001002 "this interface\n");
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001003 return -EIO;
1004 }
1005 mutex_lock(&bnx2fc_dev_lock);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001006 vn_port = bnx2fc_if_create(interface, &vport->dev, 1);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001007 mutex_unlock(&bnx2fc_dev_lock);
1008
1009 if (IS_ERR(vn_port)) {
1010 printk(KERN_ERR PFX "bnx2fc_vport_create (%s) failed\n",
1011 netdev->name);
1012 return -EIO;
1013 }
1014
1015 if (disabled) {
1016 fc_vport_set_state(vport, FC_VPORT_DISABLED);
1017 } else {
1018 vn_port->boot_time = jiffies;
1019 fc_lport_init(vn_port);
1020 fc_fabric_login(vn_port);
1021 fc_vport_setlink(vn_port);
1022 }
1023 return 0;
1024}
1025
1026static int bnx2fc_vport_destroy(struct fc_vport *vport)
1027{
1028 struct Scsi_Host *shost = vport_to_shost(vport);
1029 struct fc_lport *n_port = shost_priv(shost);
1030 struct fc_lport *vn_port = vport->dd_data;
1031 struct fcoe_port *port = lport_priv(vn_port);
1032
1033 mutex_lock(&n_port->lp_mutex);
1034 list_del(&vn_port->list);
1035 mutex_unlock(&n_port->lp_mutex);
1036 queue_work(bnx2fc_wq, &port->destroy_work);
1037 return 0;
1038}
1039
1040static int bnx2fc_vport_disable(struct fc_vport *vport, bool disable)
1041{
1042 struct fc_lport *lport = vport->dd_data;
1043
1044 if (disable) {
1045 fc_vport_set_state(vport, FC_VPORT_DISABLED);
1046 fc_fabric_logoff(lport);
1047 } else {
1048 lport->boot_time = jiffies;
1049 fc_fabric_login(lport);
1050 fc_vport_setlink(lport);
1051 }
1052 return 0;
1053}
1054
1055
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001056static int bnx2fc_netdev_setup(struct bnx2fc_interface *interface)
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001057{
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001058 struct net_device *netdev = interface->netdev;
1059 struct net_device *physdev = interface->hba->phys_dev;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001060 struct netdev_hw_addr *ha;
1061 int sel_san_mac = 0;
1062
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001063 /* setup Source MAC Address */
1064 rcu_read_lock();
1065 for_each_dev_addr(physdev, ha) {
1066 BNX2FC_MISC_DBG("net_config: ha->type = %d, fip_mac = ",
1067 ha->type);
1068 printk(KERN_INFO "%2x:%2x:%2x:%2x:%2x:%2x\n", ha->addr[0],
1069 ha->addr[1], ha->addr[2], ha->addr[3],
1070 ha->addr[4], ha->addr[5]);
1071
1072 if ((ha->type == NETDEV_HW_ADDR_T_SAN) &&
1073 (is_valid_ether_addr(ha->addr))) {
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001074 memcpy(interface->ctlr.ctl_src_addr, ha->addr,
1075 ETH_ALEN);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001076 sel_san_mac = 1;
1077 BNX2FC_MISC_DBG("Found SAN MAC\n");
1078 }
1079 }
1080 rcu_read_unlock();
1081
1082 if (!sel_san_mac)
1083 return -ENODEV;
1084
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001085 interface->fip_packet_type.func = bnx2fc_fip_recv;
1086 interface->fip_packet_type.type = htons(ETH_P_FIP);
1087 interface->fip_packet_type.dev = netdev;
1088 dev_add_pack(&interface->fip_packet_type);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001089
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001090 interface->fcoe_packet_type.func = bnx2fc_rcv;
1091 interface->fcoe_packet_type.type = __constant_htons(ETH_P_FCOE);
1092 interface->fcoe_packet_type.dev = netdev;
1093 dev_add_pack(&interface->fcoe_packet_type);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001094
1095 return 0;
1096}
1097
1098static int bnx2fc_attach_transport(void)
1099{
1100 bnx2fc_transport_template =
1101 fc_attach_transport(&bnx2fc_transport_function);
1102
1103 if (bnx2fc_transport_template == NULL) {
1104 printk(KERN_ERR PFX "Failed to attach FC transport\n");
1105 return -ENODEV;
1106 }
1107
1108 bnx2fc_vport_xport_template =
1109 fc_attach_transport(&bnx2fc_vport_xport_function);
1110 if (bnx2fc_vport_xport_template == NULL) {
1111 printk(KERN_ERR PFX
1112 "Failed to attach FC transport for vport\n");
1113 fc_release_transport(bnx2fc_transport_template);
1114 bnx2fc_transport_template = NULL;
1115 return -ENODEV;
1116 }
1117 return 0;
1118}
1119static void bnx2fc_release_transport(void)
1120{
1121 fc_release_transport(bnx2fc_transport_template);
1122 fc_release_transport(bnx2fc_vport_xport_template);
1123 bnx2fc_transport_template = NULL;
1124 bnx2fc_vport_xport_template = NULL;
1125}
1126
1127static void bnx2fc_interface_release(struct kref *kref)
1128{
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001129 struct bnx2fc_interface *interface;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001130 struct net_device *netdev;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001131
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001132 interface = container_of(kref, struct bnx2fc_interface, kref);
Nithin Nayak Sujir068bdce2011-04-25 12:30:09 -07001133 BNX2FC_MISC_DBG("Interface is being released\n");
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001134
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001135 netdev = interface->netdev;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001136
1137 /* tear-down FIP controller */
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001138 if (test_and_clear_bit(BNX2FC_CTLR_INIT_DONE, &interface->if_flags))
1139 fcoe_ctlr_destroy(&interface->ctlr);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001140
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001141 kfree(interface);
1142
1143 dev_put(netdev);
1144 module_put(THIS_MODULE);
1145}
1146
1147static inline void bnx2fc_interface_get(struct bnx2fc_interface *interface)
1148{
1149 kref_get(&interface->kref);
1150}
1151
1152static inline void bnx2fc_interface_put(struct bnx2fc_interface *interface)
1153{
1154 kref_put(&interface->kref, bnx2fc_interface_release);
1155}
1156static void bnx2fc_hba_destroy(struct bnx2fc_hba *hba)
1157{
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001158 /* Free the command manager */
1159 if (hba->cmd_mgr) {
1160 bnx2fc_cmd_mgr_free(hba->cmd_mgr);
1161 hba->cmd_mgr = NULL;
1162 }
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001163 kfree(hba->tgt_ofld_list);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001164 bnx2fc_unbind_pcidev(hba);
1165 kfree(hba);
1166}
1167
1168/**
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001169 * bnx2fc_hba_create - create a new bnx2fc hba
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001170 *
1171 * @cnic: pointer to cnic device
1172 *
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001173 * Creates a new FCoE hba on the given device.
1174 *
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001175 */
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001176static struct bnx2fc_hba *bnx2fc_hba_create(struct cnic_dev *cnic)
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001177{
1178 struct bnx2fc_hba *hba;
1179 int rc;
1180
1181 hba = kzalloc(sizeof(*hba), GFP_KERNEL);
1182 if (!hba) {
1183 printk(KERN_ERR PFX "Unable to allocate hba structure\n");
1184 return NULL;
1185 }
1186 spin_lock_init(&hba->hba_lock);
1187 mutex_init(&hba->hba_mutex);
1188
1189 hba->cnic = cnic;
1190 rc = bnx2fc_bind_pcidev(hba);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001191 if (rc) {
1192 printk(KERN_ERR PFX "create_adapter: bind error\n");
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001193 goto bind_err;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001194 }
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001195 hba->phys_dev = cnic->netdev;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001196 hba->next_conn_id = 0;
1197
1198 hba->tgt_ofld_list =
1199 kzalloc(sizeof(struct bnx2fc_rport *) * BNX2FC_NUM_MAX_SESS,
1200 GFP_KERNEL);
1201 if (!hba->tgt_ofld_list) {
1202 printk(KERN_ERR PFX "Unable to allocate tgt offload list\n");
1203 goto tgtofld_err;
1204 }
1205
1206 hba->num_ofld_sess = 0;
1207
1208 hba->cmd_mgr = bnx2fc_cmd_mgr_alloc(hba, BNX2FC_MIN_XID,
1209 BNX2FC_MAX_XID);
1210 if (!hba->cmd_mgr) {
1211 printk(KERN_ERR PFX "em_config:bnx2fc_cmd_mgr_alloc failed\n");
1212 goto cmgr_err;
1213 }
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001214
1215 init_waitqueue_head(&hba->shutdown_wait);
1216 init_waitqueue_head(&hba->destroy_wait);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001217 INIT_LIST_HEAD(&hba->vports);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001218
1219 return hba;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001220
1221cmgr_err:
1222 kfree(hba->tgt_ofld_list);
1223tgtofld_err:
1224 bnx2fc_unbind_pcidev(hba);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001225bind_err:
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001226 kfree(hba);
1227 return NULL;
1228}
1229
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001230struct bnx2fc_interface *bnx2fc_interface_create(struct bnx2fc_hba *hba,
1231 struct net_device *netdev,
1232 enum fip_state fip_mode)
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001233{
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001234 struct bnx2fc_interface *interface;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001235 int rc = 0;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001236
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001237 interface = kzalloc(sizeof(*interface), GFP_KERNEL);
1238 if (!interface) {
1239 printk(KERN_ERR PFX "Unable to allocate interface structure\n");
1240 return NULL;
1241 }
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001242 dev_hold(netdev);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001243 kref_init(&interface->kref);
1244 interface->hba = hba;
1245 interface->netdev = netdev;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001246
1247 /* Initialize FIP */
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001248 fcoe_ctlr_init(&interface->ctlr, fip_mode);
1249 interface->ctlr.send = bnx2fc_fip_send;
1250 interface->ctlr.update_mac = bnx2fc_update_src_mac;
1251 interface->ctlr.get_src_addr = bnx2fc_get_src_mac;
1252 set_bit(BNX2FC_CTLR_INIT_DONE, &interface->if_flags);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001253
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001254 rc = bnx2fc_netdev_setup(interface);
1255 if (!rc)
1256 return interface;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001257
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001258 fcoe_ctlr_destroy(&interface->ctlr);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001259 dev_put(netdev);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001260 kfree(interface);
1261 return NULL;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001262}
1263
1264/**
1265 * bnx2fc_if_create - Create FCoE instance on a given interface
1266 *
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001267 * @interface: FCoE interface to create a local port on
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001268 * @parent: Device pointer to be the parent in sysfs for the SCSI host
1269 * @npiv: Indicates if the port is vport or not
1270 *
1271 * Creates a fc_lport instance and a Scsi_Host instance and configure them.
1272 *
1273 * Returns: Allocated fc_lport or an error pointer
1274 */
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001275static struct fc_lport *bnx2fc_if_create(struct bnx2fc_interface *interface,
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001276 struct device *parent, int npiv)
1277{
Vasu Dev134a4e22011-04-28 15:55:44 -07001278 struct fc_lport *lport, *n_port;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001279 struct fcoe_port *port;
1280 struct Scsi_Host *shost;
1281 struct fc_vport *vport = dev_to_vport(parent);
Bhanu Prakash Gollapudid36b3272011-05-27 11:47:27 -07001282 struct bnx2fc_lport *blport;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001283 struct bnx2fc_hba *hba;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001284 int rc = 0;
1285
Bhanu Prakash Gollapudid36b3272011-05-27 11:47:27 -07001286 blport = kzalloc(sizeof(struct bnx2fc_lport), GFP_KERNEL);
1287 if (!blport) {
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001288 BNX2FC_HBA_DBG(interface->ctlr.lp, "Unable to alloc blport\n");
Bhanu Prakash Gollapudid36b3272011-05-27 11:47:27 -07001289 return NULL;
1290 }
1291
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001292 /* Allocate Scsi_Host structure */
Vasu Dev134a4e22011-04-28 15:55:44 -07001293 if (!npiv)
1294 lport = libfc_host_alloc(&bnx2fc_shost_template, sizeof(*port));
1295 else
1296 lport = libfc_vport_create(vport, sizeof(*port));
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001297
1298 if (!lport) {
1299 printk(KERN_ERR PFX "could not allocate scsi host structure\n");
Bhanu Prakash Gollapudid36b3272011-05-27 11:47:27 -07001300 goto free_blport;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001301 }
1302 shost = lport->host;
1303 port = lport_priv(lport);
1304 port->lport = lport;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001305 port->priv = interface;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001306 INIT_WORK(&port->destroy_work, bnx2fc_destroy_work);
1307
1308 /* Configure fcoe_port */
1309 rc = bnx2fc_lport_config(lport);
1310 if (rc)
1311 goto lp_config_err;
1312
1313 if (npiv) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001314 printk(KERN_ERR PFX "Setting vport names, 0x%llX 0x%llX\n",
1315 vport->node_name, vport->port_name);
1316 fc_set_wwnn(lport, vport->node_name);
1317 fc_set_wwpn(lport, vport->port_name);
1318 }
1319 /* Configure netdev and networking properties of the lport */
1320 rc = bnx2fc_net_config(lport);
1321 if (rc) {
1322 printk(KERN_ERR PFX "Error on bnx2fc_net_config\n");
1323 goto lp_config_err;
1324 }
1325
1326 rc = bnx2fc_shost_config(lport, parent);
1327 if (rc) {
1328 printk(KERN_ERR PFX "Couldnt configure shost for %s\n",
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001329 interface->netdev->name);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001330 goto lp_config_err;
1331 }
1332
1333 /* Initialize the libfc library */
1334 rc = bnx2fc_libfc_config(lport);
1335 if (rc) {
1336 printk(KERN_ERR PFX "Couldnt configure libfc\n");
1337 goto shost_err;
1338 }
1339 fc_host_port_type(lport->host) = FC_PORTTYPE_UNKNOWN;
1340
1341 /* Allocate exchange manager */
Vasu Dev134a4e22011-04-28 15:55:44 -07001342 if (!npiv)
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001343 rc = bnx2fc_em_config(lport);
Vasu Dev134a4e22011-04-28 15:55:44 -07001344 else {
1345 shost = vport_to_shost(vport);
1346 n_port = shost_priv(shost);
1347 rc = fc_exch_mgr_list_clone(n_port, lport);
1348 }
1349
1350 if (rc) {
1351 printk(KERN_ERR PFX "Error on bnx2fc_em_config\n");
1352 goto shost_err;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001353 }
1354
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001355 bnx2fc_interface_get(interface);
Bhanu Prakash Gollapudid36b3272011-05-27 11:47:27 -07001356
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001357 hba = interface->hba;
Bhanu Prakash Gollapudid36b3272011-05-27 11:47:27 -07001358 spin_lock_bh(&hba->hba_lock);
1359 blport->lport = lport;
1360 list_add_tail(&blport->list, &hba->vports);
1361 spin_unlock_bh(&hba->hba_lock);
1362
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001363 return lport;
1364
1365shost_err:
1366 scsi_remove_host(shost);
1367lp_config_err:
1368 scsi_host_put(lport->host);
Bhanu Prakash Gollapudid36b3272011-05-27 11:47:27 -07001369free_blport:
1370 kfree(blport);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001371 return NULL;
1372}
1373
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001374static void bnx2fc_netdev_cleanup(struct bnx2fc_interface *interface)
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001375{
1376 /* Dont listen for Ethernet packets anymore */
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001377 __dev_remove_pack(&interface->fcoe_packet_type);
1378 __dev_remove_pack(&interface->fip_packet_type);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001379 synchronize_net();
1380}
1381
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001382static void bnx2fc_if_destroy(struct fc_lport *lport, struct bnx2fc_hba *hba)
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001383{
1384 struct fcoe_port *port = lport_priv(lport);
Bhanu Prakash Gollapudid36b3272011-05-27 11:47:27 -07001385 struct bnx2fc_lport *blport, *tmp;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001386
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001387 /* Stop the transmit retry timer */
1388 del_timer_sync(&port->timer);
1389
1390 /* Free existing transmit skbs */
1391 fcoe_clean_pending_queue(lport);
1392
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001393 /* Free queued packets for the receive thread */
1394 bnx2fc_clean_rx_queue(lport);
1395
1396 /* Detach from scsi-ml */
1397 fc_remove_host(lport->host);
1398 scsi_remove_host(lport->host);
1399
1400 /*
1401 * Note that only the physical lport will have the exchange manager.
1402 * for vports, this function is NOP
1403 */
1404 fc_exch_mgr_free(lport);
1405
1406 /* Free memory used by statistical counters */
1407 fc_lport_free_stats(lport);
1408
Bhanu Prakash Gollapudid36b3272011-05-27 11:47:27 -07001409 spin_lock_bh(&hba->hba_lock);
1410 list_for_each_entry_safe(blport, tmp, &hba->vports, list) {
1411 if (blport->lport == lport) {
1412 list_del(&blport->list);
1413 kfree(blport);
1414 }
1415 }
1416 spin_unlock_bh(&hba->hba_lock);
1417
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001418 /* Release Scsi_Host */
1419 scsi_host_put(lport->host);
1420}
1421
1422/**
1423 * bnx2fc_destroy - Destroy a bnx2fc FCoE interface
1424 *
1425 * @buffer: The name of the Ethernet interface to be destroyed
1426 * @kp: The associated kernel parameter
1427 *
1428 * Called from sysfs.
1429 *
1430 * Returns: 0 for success
1431 */
1432static int bnx2fc_destroy(struct net_device *netdev)
1433{
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001434 struct bnx2fc_interface *interface = NULL;
1435 struct bnx2fc_hba *hba;
1436 struct fc_lport *lport;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001437 int rc = 0;
1438
Nithin Sujir6702ca12011-03-17 17:13:27 -07001439 rtnl_lock();
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001440 mutex_lock(&bnx2fc_dev_lock);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001441
1442 interface = bnx2fc_interface_lookup(netdev);
1443 if (!interface || !interface->ctlr.lp) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001444 rc = -ENODEV;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001445 printk(KERN_ERR PFX "bnx2fc_destroy: interface or lport not found\n");
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001446 goto netdev_err;
1447 }
1448
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001449 hba = interface->hba;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001450
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001451 bnx2fc_netdev_cleanup(interface);
1452 lport = interface->ctlr.lp;
1453 bnx2fc_stop(interface);
1454 list_del(&interface->list);
1455 destroy_workqueue(interface->timer_work_queue);
1456 bnx2fc_interface_put(interface);
1457 bnx2fc_if_destroy(lport, hba);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001458
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001459netdev_err:
1460 mutex_unlock(&bnx2fc_dev_lock);
1461 rtnl_unlock();
1462 return rc;
1463}
1464
1465static void bnx2fc_destroy_work(struct work_struct *work)
1466{
1467 struct fcoe_port *port;
1468 struct fc_lport *lport;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001469 struct bnx2fc_interface *interface;
1470 struct bnx2fc_hba *hba;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001471
1472 port = container_of(work, struct fcoe_port, destroy_work);
1473 lport = port->lport;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001474 interface = port->priv;
1475 hba = interface->hba;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001476
1477 BNX2FC_HBA_DBG(lport, "Entered bnx2fc_destroy_work\n");
1478
1479 bnx2fc_port_shutdown(lport);
1480 rtnl_lock();
1481 mutex_lock(&bnx2fc_dev_lock);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001482 bnx2fc_if_destroy(lport, hba);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001483 mutex_unlock(&bnx2fc_dev_lock);
1484 rtnl_unlock();
1485}
1486
1487static void bnx2fc_unbind_adapter_devices(struct bnx2fc_hba *hba)
1488{
1489 bnx2fc_free_fw_resc(hba);
1490 bnx2fc_free_task_ctx(hba);
1491}
1492
1493/**
1494 * bnx2fc_bind_adapter_devices - binds bnx2fc adapter with the associated
1495 * pci structure
1496 *
1497 * @hba: Adapter instance
1498 */
1499static int bnx2fc_bind_adapter_devices(struct bnx2fc_hba *hba)
1500{
1501 if (bnx2fc_setup_task_ctx(hba))
1502 goto mem_err;
1503
1504 if (bnx2fc_setup_fw_resc(hba))
1505 goto mem_err;
1506
1507 return 0;
1508mem_err:
1509 bnx2fc_unbind_adapter_devices(hba);
1510 return -ENOMEM;
1511}
1512
1513static int bnx2fc_bind_pcidev(struct bnx2fc_hba *hba)
1514{
1515 struct cnic_dev *cnic;
1516
1517 if (!hba->cnic) {
1518 printk(KERN_ERR PFX "cnic is NULL\n");
1519 return -ENODEV;
1520 }
1521 cnic = hba->cnic;
1522 hba->pcidev = cnic->pcidev;
1523 if (hba->pcidev)
1524 pci_dev_get(hba->pcidev);
1525
1526 return 0;
1527}
1528
1529static void bnx2fc_unbind_pcidev(struct bnx2fc_hba *hba)
1530{
1531 if (hba->pcidev)
1532 pci_dev_put(hba->pcidev);
1533 hba->pcidev = NULL;
1534}
1535
1536
1537
1538/**
1539 * bnx2fc_ulp_start - cnic callback to initialize & start adapter instance
1540 *
1541 * @handle: transport handle pointing to adapter struture
1542 *
1543 * This function maps adapter structure to pcidev structure and initiates
1544 * firmware handshake to enable/initialize on-chip FCoE components.
1545 * This bnx2fc - cnic interface api callback is used after following
1546 * conditions are met -
1547 * a) underlying network interface is up (marked by event NETDEV_UP
1548 * from netdev
1549 * b) bnx2fc adatper structure is registered.
1550 */
1551static void bnx2fc_ulp_start(void *handle)
1552{
1553 struct bnx2fc_hba *hba = handle;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001554 struct bnx2fc_interface *interface;
1555 struct fc_lport *lport;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001556
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001557 mutex_lock(&bnx2fc_dev_lock);
1558
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001559 if (!test_bit(BNX2FC_FLAG_FW_INIT_DONE, &hba->flags))
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001560 bnx2fc_fw_init(hba);
1561
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001562 BNX2FC_MISC_DBG("bnx2fc started.\n");
1563
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001564 list_for_each_entry(interface, &if_list, list) {
1565 if (interface->hba == hba) {
1566 lport = interface->ctlr.lp;
1567 /* Kick off Fabric discovery*/
1568 printk(KERN_ERR PFX "ulp_init: start discovery\n");
1569 lport->tt.frame_send = bnx2fc_xmit;
1570 bnx2fc_start_disc(interface);
1571 }
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001572 }
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001573
1574 mutex_unlock(&bnx2fc_dev_lock);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001575}
1576
1577static void bnx2fc_port_shutdown(struct fc_lport *lport)
1578{
1579 BNX2FC_MISC_DBG("Entered %s\n", __func__);
1580 fc_fabric_logoff(lport);
1581 fc_lport_destroy(lport);
1582}
1583
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001584static void bnx2fc_stop(struct bnx2fc_interface *interface)
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001585{
1586 struct fc_lport *lport;
1587 struct fc_lport *vport;
1588
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001589 if (!test_bit(BNX2FC_FLAG_FW_INIT_DONE, &interface->hba->flags))
1590 return;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001591
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001592 lport = interface->ctlr.lp;
1593 bnx2fc_port_shutdown(lport);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001594
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001595 mutex_lock(&lport->lp_mutex);
1596 list_for_each_entry(vport, &lport->vports, list)
1597 fc_host_port_type(vport->host) =
1598 FC_PORTTYPE_UNKNOWN;
1599 mutex_unlock(&lport->lp_mutex);
1600 fc_host_port_type(lport->host) = FC_PORTTYPE_UNKNOWN;
1601 fcoe_ctlr_link_down(&interface->ctlr);
1602 fcoe_clean_pending_queue(lport);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001603}
1604
1605static int bnx2fc_fw_init(struct bnx2fc_hba *hba)
1606{
1607#define BNX2FC_INIT_POLL_TIME (1000 / HZ)
1608 int rc = -1;
1609 int i = HZ;
1610
1611 rc = bnx2fc_bind_adapter_devices(hba);
1612 if (rc) {
1613 printk(KERN_ALERT PFX
1614 "bnx2fc_bind_adapter_devices failed - rc = %d\n", rc);
1615 goto err_out;
1616 }
1617
1618 rc = bnx2fc_send_fw_fcoe_init_msg(hba);
1619 if (rc) {
1620 printk(KERN_ALERT PFX
1621 "bnx2fc_send_fw_fcoe_init_msg failed - rc = %d\n", rc);
1622 goto err_unbind;
1623 }
1624
1625 /*
1626 * Wait until the adapter init message is complete, and adapter
1627 * state is UP.
1628 */
1629 while (!test_bit(ADAPTER_STATE_UP, &hba->adapter_state) && i--)
1630 msleep(BNX2FC_INIT_POLL_TIME);
1631
1632 if (!test_bit(ADAPTER_STATE_UP, &hba->adapter_state)) {
1633 printk(KERN_ERR PFX "bnx2fc_start: %s failed to initialize. "
1634 "Ignoring...\n",
1635 hba->cnic->netdev->name);
1636 rc = -1;
1637 goto err_unbind;
1638 }
1639
1640
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001641 set_bit(BNX2FC_FLAG_FW_INIT_DONE, &hba->flags);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001642 return 0;
1643
1644err_unbind:
1645 bnx2fc_unbind_adapter_devices(hba);
1646err_out:
1647 return rc;
1648}
1649
1650static void bnx2fc_fw_destroy(struct bnx2fc_hba *hba)
1651{
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001652 if (test_and_clear_bit(BNX2FC_FLAG_FW_INIT_DONE, &hba->flags)) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001653 if (bnx2fc_send_fw_fcoe_destroy_msg(hba) == 0) {
1654 init_timer(&hba->destroy_timer);
1655 hba->destroy_timer.expires = BNX2FC_FW_TIMEOUT +
1656 jiffies;
1657 hba->destroy_timer.function = bnx2fc_destroy_timer;
1658 hba->destroy_timer.data = (unsigned long)hba;
1659 add_timer(&hba->destroy_timer);
1660 wait_event_interruptible(hba->destroy_wait,
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001661 test_bit(BNX2FC_FLAG_DESTROY_CMPL,
1662 &hba->flags));
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001663 /* This should never happen */
1664 if (signal_pending(current))
1665 flush_signals(current);
1666
1667 del_timer_sync(&hba->destroy_timer);
1668 }
1669 bnx2fc_unbind_adapter_devices(hba);
1670 }
1671}
1672
1673/**
1674 * bnx2fc_ulp_stop - cnic callback to shutdown adapter instance
1675 *
1676 * @handle: transport handle pointing to adapter structure
1677 *
1678 * Driver checks if adapter is already in shutdown mode, if not start
1679 * the shutdown process.
1680 */
1681static void bnx2fc_ulp_stop(void *handle)
1682{
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001683 struct bnx2fc_hba *hba = handle;
1684 struct bnx2fc_interface *interface;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001685
1686 printk(KERN_ERR "ULP_STOP\n");
1687
1688 mutex_lock(&bnx2fc_dev_lock);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001689 if (!test_bit(BNX2FC_FLAG_FW_INIT_DONE, &hba->flags))
1690 goto exit;
1691 list_for_each_entry(interface, &if_list, list) {
1692 if (interface->hba == hba)
1693 bnx2fc_stop(interface);
1694 }
1695 BUG_ON(hba->num_ofld_sess != 0);
1696
1697 mutex_lock(&hba->hba_mutex);
1698 clear_bit(ADAPTER_STATE_UP, &hba->adapter_state);
1699 clear_bit(ADAPTER_STATE_GOING_DOWN,
1700 &hba->adapter_state);
1701
1702 clear_bit(ADAPTER_STATE_READY, &hba->adapter_state);
1703 mutex_unlock(&hba->hba_mutex);
1704
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001705 bnx2fc_fw_destroy(hba);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001706exit:
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001707 mutex_unlock(&bnx2fc_dev_lock);
1708}
1709
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001710static void bnx2fc_start_disc(struct bnx2fc_interface *interface)
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001711{
1712 struct fc_lport *lport;
1713 int wait_cnt = 0;
1714
1715 BNX2FC_MISC_DBG("Entered %s\n", __func__);
1716 /* Kick off FIP/FLOGI */
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001717 if (!test_bit(BNX2FC_FLAG_FW_INIT_DONE, &interface->hba->flags)) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001718 printk(KERN_ERR PFX "Init not done yet\n");
1719 return;
1720 }
1721
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001722 lport = interface->ctlr.lp;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001723 BNX2FC_HBA_DBG(lport, "calling fc_fabric_login\n");
1724
1725 if (!bnx2fc_link_ok(lport)) {
1726 BNX2FC_HBA_DBG(lport, "ctlr_link_up\n");
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001727 fcoe_ctlr_link_up(&interface->ctlr);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001728 fc_host_port_type(lport->host) = FC_PORTTYPE_NPORT;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001729 set_bit(ADAPTER_STATE_READY, &interface->hba->adapter_state);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001730 }
1731
1732 /* wait for the FCF to be selected before issuing FLOGI */
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001733 while (!interface->ctlr.sel_fcf) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001734 msleep(250);
1735 /* give up after 3 secs */
1736 if (++wait_cnt > 12)
1737 break;
1738 }
1739 fc_lport_init(lport);
1740 fc_fabric_login(lport);
1741}
1742
1743
1744/**
1745 * bnx2fc_ulp_init - Initialize an adapter instance
1746 *
1747 * @dev : cnic device handle
1748 * Called from cnic_register_driver() context to initialize all
1749 * enumerated cnic devices. This routine allocates adapter structure
1750 * and other device specific resources.
1751 */
1752static void bnx2fc_ulp_init(struct cnic_dev *dev)
1753{
1754 struct bnx2fc_hba *hba;
1755 int rc = 0;
1756
1757 BNX2FC_MISC_DBG("Entered %s\n", __func__);
1758 /* bnx2fc works only when bnx2x is loaded */
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001759 if (!test_bit(CNIC_F_BNX2X_CLASS, &dev->flags) ||
1760 (dev->max_fcoe_conn == 0)) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001761 printk(KERN_ERR PFX "bnx2fc FCoE not supported on %s,"
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001762 " flags: %lx fcoe_conn: %d\n",
1763 dev->netdev->name, dev->flags, dev->max_fcoe_conn);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001764 return;
1765 }
1766
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001767 hba = bnx2fc_hba_create(dev);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001768 if (!hba) {
1769 printk(KERN_ERR PFX "hba initialization failed\n");
1770 return;
1771 }
1772
1773 /* Add HBA to the adapter list */
1774 mutex_lock(&bnx2fc_dev_lock);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001775 list_add_tail(&hba->list, &adapter_list);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001776 adapter_count++;
1777 mutex_unlock(&bnx2fc_dev_lock);
1778
1779 clear_bit(BNX2FC_CNIC_REGISTERED, &hba->reg_with_cnic);
1780 rc = dev->register_device(dev, CNIC_ULP_FCOE,
1781 (void *) hba);
1782 if (rc)
Bhanu Prakash Gollapudib2a554f2011-06-27 23:30:53 -07001783 printk(KERN_ERR PFX "register_device failed, rc = %d\n", rc);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001784 else
1785 set_bit(BNX2FC_CNIC_REGISTERED, &hba->reg_with_cnic);
1786}
1787
1788
1789static int bnx2fc_disable(struct net_device *netdev)
1790{
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001791 struct bnx2fc_interface *interface;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001792 int rc = 0;
1793
Nithin Sujir6702ca12011-03-17 17:13:27 -07001794 rtnl_lock();
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001795 mutex_lock(&bnx2fc_dev_lock);
1796
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001797 interface = bnx2fc_interface_lookup(netdev);
1798 if (!interface || !interface->ctlr.lp) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001799 rc = -ENODEV;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001800 printk(KERN_ERR PFX "bnx2fc_disable: interface or lport not found\n");
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001801 } else {
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001802 fcoe_ctlr_link_down(&interface->ctlr);
1803 fcoe_clean_pending_queue(interface->ctlr.lp);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001804 }
1805
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001806 mutex_unlock(&bnx2fc_dev_lock);
1807 rtnl_unlock();
1808 return rc;
1809}
1810
1811
1812static int bnx2fc_enable(struct net_device *netdev)
1813{
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001814 struct bnx2fc_interface *interface;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001815 int rc = 0;
1816
Nithin Sujir6702ca12011-03-17 17:13:27 -07001817 rtnl_lock();
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001818 mutex_lock(&bnx2fc_dev_lock);
1819
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001820 interface = bnx2fc_interface_lookup(netdev);
1821 if (!interface || !interface->ctlr.lp) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001822 rc = -ENODEV;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001823 printk(KERN_ERR PFX "bnx2fc_enable: interface or lport not found\n");
1824 } else if (!bnx2fc_link_ok(interface->ctlr.lp))
1825 fcoe_ctlr_link_up(&interface->ctlr);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001826
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001827 mutex_unlock(&bnx2fc_dev_lock);
1828 rtnl_unlock();
1829 return rc;
1830}
1831
1832/**
1833 * bnx2fc_create - Create bnx2fc FCoE interface
1834 *
1835 * @buffer: The name of Ethernet interface to create on
1836 * @kp: The associated kernel param
1837 *
1838 * Called from sysfs.
1839 *
1840 * Returns: 0 for success
1841 */
1842static int bnx2fc_create(struct net_device *netdev, enum fip_state fip_mode)
1843{
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001844 struct bnx2fc_interface *interface;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001845 struct bnx2fc_hba *hba;
1846 struct net_device *phys_dev;
1847 struct fc_lport *lport;
1848 struct ethtool_drvinfo drvinfo;
1849 int rc = 0;
1850 int vlan_id;
1851
1852 BNX2FC_MISC_DBG("Entered bnx2fc_create\n");
1853 if (fip_mode != FIP_MODE_FABRIC) {
1854 printk(KERN_ERR "fip mode not FABRIC\n");
1855 return -EIO;
1856 }
1857
Nithin Sujir6702ca12011-03-17 17:13:27 -07001858 rtnl_lock();
1859
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001860 mutex_lock(&bnx2fc_dev_lock);
1861
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001862 if (!try_module_get(THIS_MODULE)) {
1863 rc = -EINVAL;
1864 goto mod_err;
1865 }
1866
1867 /* obtain physical netdev */
1868 if (netdev->priv_flags & IFF_802_1Q_VLAN) {
1869 phys_dev = vlan_dev_real_dev(netdev);
1870 vlan_id = vlan_dev_vlan_id(netdev);
1871 } else {
1872 printk(KERN_ERR PFX "Not a vlan device\n");
1873 rc = -EINVAL;
1874 goto netdev_err;
1875 }
1876 /* verify if the physical device is a netxtreme2 device */
1877 if (phys_dev->ethtool_ops && phys_dev->ethtool_ops->get_drvinfo) {
1878 memset(&drvinfo, 0, sizeof(drvinfo));
1879 phys_dev->ethtool_ops->get_drvinfo(phys_dev, &drvinfo);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001880 if (strncmp(drvinfo.driver, "bnx2x", strlen("bnx2x"))) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001881 printk(KERN_ERR PFX "Not a netxtreme2 device\n");
1882 rc = -EINVAL;
1883 goto netdev_err;
1884 }
1885 } else {
1886 printk(KERN_ERR PFX "unable to obtain drv_info\n");
1887 rc = -EINVAL;
1888 goto netdev_err;
1889 }
1890
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001891 /* obtain interface and initialize rest of the structure */
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001892 hba = bnx2fc_hba_lookup(phys_dev);
1893 if (!hba) {
1894 rc = -ENODEV;
1895 printk(KERN_ERR PFX "bnx2fc_create: hba not found\n");
1896 goto netdev_err;
1897 }
1898
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001899 if (bnx2fc_interface_lookup(netdev)) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001900 rc = -EEXIST;
1901 goto netdev_err;
1902 }
1903
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001904 interface = bnx2fc_interface_create(hba, netdev, fip_mode);
1905 if (!interface) {
1906 printk(KERN_ERR PFX "bnx2fc_interface_create failed\n");
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001907 goto ifput_err;
1908 }
1909
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001910 interface->vlan_id = vlan_id;
1911 interface->vlan_enabled = 1;
1912
1913 interface->timer_work_queue =
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001914 create_singlethread_workqueue("bnx2fc_timer_wq");
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001915 if (!interface->timer_work_queue) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001916 printk(KERN_ERR PFX "ulp_init could not create timer_wq\n");
1917 rc = -EINVAL;
1918 goto ifput_err;
1919 }
1920
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001921 lport = bnx2fc_if_create(interface, &interface->hba->pcidev->dev, 0);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001922 if (!lport) {
1923 printk(KERN_ERR PFX "Failed to create interface (%s)\n",
1924 netdev->name);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001925 bnx2fc_netdev_cleanup(interface);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001926 rc = -EINVAL;
1927 goto if_create_err;
1928 }
1929
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001930 /* Add interface to if_list */
1931 list_add_tail(&interface->list, &if_list);
1932
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001933 lport->boot_time = jiffies;
1934
1935 /* Make this master N_port */
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001936 interface->ctlr.lp = lport;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001937
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001938 BNX2FC_HBA_DBG(lport, "create: START DISC\n");
1939 bnx2fc_start_disc(interface);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001940 /*
1941 * Release from kref_init in bnx2fc_interface_setup, on success
1942 * lport should be holding a reference taken in bnx2fc_if_create
1943 */
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001944 bnx2fc_interface_put(interface);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001945 /* put netdev that was held while calling dev_get_by_name */
1946 mutex_unlock(&bnx2fc_dev_lock);
1947 rtnl_unlock();
1948 return 0;
1949
1950if_create_err:
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001951 destroy_workqueue(interface->timer_work_queue);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001952ifput_err:
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001953 bnx2fc_interface_put(interface);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001954netdev_err:
1955 module_put(THIS_MODULE);
1956mod_err:
1957 mutex_unlock(&bnx2fc_dev_lock);
1958 rtnl_unlock();
1959 return rc;
1960}
1961
1962/**
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001963 * bnx2fc_find_hba_for_cnic - maps cnic instance to bnx2fc hba instance
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001964 *
1965 * @cnic: Pointer to cnic device instance
1966 *
1967 **/
1968static struct bnx2fc_hba *bnx2fc_find_hba_for_cnic(struct cnic_dev *cnic)
1969{
1970 struct list_head *list;
1971 struct list_head *temp;
1972 struct bnx2fc_hba *hba;
1973
1974 /* Called with bnx2fc_dev_lock held */
1975 list_for_each_safe(list, temp, &adapter_list) {
1976 hba = (struct bnx2fc_hba *)list;
1977 if (hba->cnic == cnic)
1978 return hba;
1979 }
1980 return NULL;
1981}
1982
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001983static struct bnx2fc_interface *bnx2fc_interface_lookup(struct net_device
1984 *netdev)
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001985{
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001986 struct bnx2fc_interface *interface;
1987
1988 /* Called with bnx2fc_dev_lock held */
1989 list_for_each_entry(interface, &if_list, list) {
1990 if (interface->netdev == netdev)
1991 return interface;
1992 }
1993 return NULL;
1994}
1995
1996static struct bnx2fc_hba *bnx2fc_hba_lookup(struct net_device
1997 *phys_dev)
1998{
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001999 struct bnx2fc_hba *hba;
2000
2001 /* Called with bnx2fc_dev_lock held */
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002002 list_for_each_entry(hba, &adapter_list, list) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002003 if (hba->phys_dev == phys_dev)
2004 return hba;
2005 }
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002006 printk(KERN_ERR PFX "adapter_lookup: hba NULL\n");
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002007 return NULL;
2008}
2009
2010/**
2011 * bnx2fc_ulp_exit - shuts down adapter instance and frees all resources
2012 *
2013 * @dev cnic device handle
2014 */
2015static void bnx2fc_ulp_exit(struct cnic_dev *dev)
2016{
2017 struct bnx2fc_hba *hba;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002018 struct bnx2fc_interface *interface, *tmp;
2019 struct fc_lport *lport;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002020
2021 BNX2FC_MISC_DBG("Entered bnx2fc_ulp_exit\n");
2022
2023 if (!test_bit(CNIC_F_BNX2X_CLASS, &dev->flags)) {
2024 printk(KERN_ERR PFX "bnx2fc port check: %s, flags: %lx\n",
2025 dev->netdev->name, dev->flags);
2026 return;
2027 }
2028
2029 mutex_lock(&bnx2fc_dev_lock);
2030 hba = bnx2fc_find_hba_for_cnic(dev);
2031 if (!hba) {
2032 printk(KERN_ERR PFX "bnx2fc_ulp_exit: hba not found, dev 0%p\n",
2033 dev);
2034 mutex_unlock(&bnx2fc_dev_lock);
2035 return;
2036 }
2037
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002038 list_del_init(&hba->list);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002039 adapter_count--;
2040
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002041 list_for_each_entry_safe(interface, tmp, &if_list, list) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002042 /* destroy not called yet, move to quiesced list */
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002043 if (interface->hba == hba) {
2044 bnx2fc_netdev_cleanup(interface);
2045 bnx2fc_stop(interface);
2046
2047 list_del(&interface->list);
2048 lport = interface->ctlr.lp;
2049 bnx2fc_interface_put(interface);
2050 bnx2fc_if_destroy(lport, hba);
2051 }
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002052 }
2053 mutex_unlock(&bnx2fc_dev_lock);
2054
2055 bnx2fc_ulp_stop(hba);
2056 /* unregister cnic device */
2057 if (test_and_clear_bit(BNX2FC_CNIC_REGISTERED, &hba->reg_with_cnic))
2058 hba->cnic->unregister_device(hba->cnic, CNIC_ULP_FCOE);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002059 bnx2fc_hba_destroy(hba);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002060}
2061
2062/**
2063 * bnx2fc_fcoe_reset - Resets the fcoe
2064 *
2065 * @shost: shost the reset is from
2066 *
2067 * Returns: always 0
2068 */
2069static int bnx2fc_fcoe_reset(struct Scsi_Host *shost)
2070{
2071 struct fc_lport *lport = shost_priv(shost);
2072 fc_lport_reset(lport);
2073 return 0;
2074}
2075
2076
2077static bool bnx2fc_match(struct net_device *netdev)
2078{
2079 mutex_lock(&bnx2fc_dev_lock);
2080 if (netdev->priv_flags & IFF_802_1Q_VLAN) {
2081 struct net_device *phys_dev = vlan_dev_real_dev(netdev);
2082
2083 if (bnx2fc_hba_lookup(phys_dev)) {
2084 mutex_unlock(&bnx2fc_dev_lock);
2085 return true;
2086 }
2087 }
2088 mutex_unlock(&bnx2fc_dev_lock);
2089 return false;
2090}
2091
2092
2093static struct fcoe_transport bnx2fc_transport = {
2094 .name = {"bnx2fc"},
2095 .attached = false,
2096 .list = LIST_HEAD_INIT(bnx2fc_transport.list),
2097 .match = bnx2fc_match,
2098 .create = bnx2fc_create,
2099 .destroy = bnx2fc_destroy,
2100 .enable = bnx2fc_enable,
2101 .disable = bnx2fc_disable,
2102};
2103
2104/**
2105 * bnx2fc_percpu_thread_create - Create a receive thread for an
2106 * online CPU
2107 *
2108 * @cpu: cpu index for the online cpu
2109 */
2110static void bnx2fc_percpu_thread_create(unsigned int cpu)
2111{
2112 struct bnx2fc_percpu_s *p;
2113 struct task_struct *thread;
2114
2115 p = &per_cpu(bnx2fc_percpu, cpu);
2116
2117 thread = kthread_create(bnx2fc_percpu_io_thread,
2118 (void *)p,
2119 "bnx2fc_thread/%d", cpu);
2120 /* bind thread to the cpu */
2121 if (likely(!IS_ERR(p->iothread))) {
2122 kthread_bind(thread, cpu);
2123 p->iothread = thread;
2124 wake_up_process(thread);
2125 }
2126}
2127
2128static void bnx2fc_percpu_thread_destroy(unsigned int cpu)
2129{
2130 struct bnx2fc_percpu_s *p;
2131 struct task_struct *thread;
2132 struct bnx2fc_work *work, *tmp;
2133 LIST_HEAD(work_list);
2134
2135 BNX2FC_MISC_DBG("destroying io thread for CPU %d\n", cpu);
2136
2137 /* Prevent any new work from being queued for this CPU */
2138 p = &per_cpu(bnx2fc_percpu, cpu);
2139 spin_lock_bh(&p->fp_work_lock);
2140 thread = p->iothread;
2141 p->iothread = NULL;
2142
2143
2144 /* Free all work in the list */
2145 list_for_each_entry_safe(work, tmp, &work_list, list) {
2146 list_del_init(&work->list);
2147 bnx2fc_process_cq_compl(work->tgt, work->wqe);
2148 kfree(work);
2149 }
2150
2151 spin_unlock_bh(&p->fp_work_lock);
2152
2153 if (thread)
2154 kthread_stop(thread);
2155}
2156
2157/**
2158 * bnx2fc_cpu_callback - Handler for CPU hotplug events
2159 *
2160 * @nfb: The callback data block
2161 * @action: The event triggering the callback
2162 * @hcpu: The index of the CPU that the event is for
2163 *
2164 * This creates or destroys per-CPU data for fcoe
2165 *
2166 * Returns NOTIFY_OK always.
2167 */
2168static int bnx2fc_cpu_callback(struct notifier_block *nfb,
2169 unsigned long action, void *hcpu)
2170{
2171 unsigned cpu = (unsigned long)hcpu;
2172
2173 switch (action) {
2174 case CPU_ONLINE:
2175 case CPU_ONLINE_FROZEN:
2176 printk(PFX "CPU %x online: Create Rx thread\n", cpu);
2177 bnx2fc_percpu_thread_create(cpu);
2178 break;
2179 case CPU_DEAD:
2180 case CPU_DEAD_FROZEN:
2181 printk(PFX "CPU %x offline: Remove Rx thread\n", cpu);
2182 bnx2fc_percpu_thread_destroy(cpu);
2183 break;
2184 default:
2185 break;
2186 }
2187 return NOTIFY_OK;
2188}
2189
2190/**
2191 * bnx2fc_mod_init - module init entry point
2192 *
2193 * Initialize driver wide global data structures, and register
2194 * with cnic module
2195 **/
2196static int __init bnx2fc_mod_init(void)
2197{
2198 struct fcoe_percpu_s *bg;
2199 struct task_struct *l2_thread;
2200 int rc = 0;
2201 unsigned int cpu = 0;
2202 struct bnx2fc_percpu_s *p;
2203
2204 printk(KERN_INFO PFX "%s", version);
2205
2206 /* register as a fcoe transport */
2207 rc = fcoe_transport_attach(&bnx2fc_transport);
2208 if (rc) {
2209 printk(KERN_ERR "failed to register an fcoe transport, check "
2210 "if libfcoe is loaded\n");
2211 goto out;
2212 }
2213
2214 INIT_LIST_HEAD(&adapter_list);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002215 INIT_LIST_HEAD(&if_list);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002216 mutex_init(&bnx2fc_dev_lock);
2217 adapter_count = 0;
2218
2219 /* Attach FC transport template */
2220 rc = bnx2fc_attach_transport();
2221 if (rc)
2222 goto detach_ft;
2223
2224 bnx2fc_wq = alloc_workqueue("bnx2fc", 0, 0);
2225 if (!bnx2fc_wq) {
2226 rc = -ENOMEM;
2227 goto release_bt;
2228 }
2229
2230 bg = &bnx2fc_global;
2231 skb_queue_head_init(&bg->fcoe_rx_list);
2232 l2_thread = kthread_create(bnx2fc_l2_rcv_thread,
2233 (void *)bg,
2234 "bnx2fc_l2_thread");
2235 if (IS_ERR(l2_thread)) {
2236 rc = PTR_ERR(l2_thread);
2237 goto free_wq;
2238 }
2239 wake_up_process(l2_thread);
2240 spin_lock_bh(&bg->fcoe_rx_list.lock);
2241 bg->thread = l2_thread;
2242 spin_unlock_bh(&bg->fcoe_rx_list.lock);
2243
2244 for_each_possible_cpu(cpu) {
2245 p = &per_cpu(bnx2fc_percpu, cpu);
2246 INIT_LIST_HEAD(&p->work_list);
2247 spin_lock_init(&p->fp_work_lock);
2248 }
2249
2250 for_each_online_cpu(cpu) {
2251 bnx2fc_percpu_thread_create(cpu);
2252 }
2253
2254 /* Initialize per CPU interrupt thread */
2255 register_hotcpu_notifier(&bnx2fc_cpu_notifier);
2256
2257 cnic_register_driver(CNIC_ULP_FCOE, &bnx2fc_cnic_cb);
2258
2259 return 0;
2260
2261free_wq:
2262 destroy_workqueue(bnx2fc_wq);
2263release_bt:
2264 bnx2fc_release_transport();
2265detach_ft:
2266 fcoe_transport_detach(&bnx2fc_transport);
2267out:
2268 return rc;
2269}
2270
2271static void __exit bnx2fc_mod_exit(void)
2272{
2273 LIST_HEAD(to_be_deleted);
2274 struct bnx2fc_hba *hba, *next;
2275 struct fcoe_percpu_s *bg;
2276 struct task_struct *l2_thread;
2277 struct sk_buff *skb;
2278 unsigned int cpu = 0;
2279
2280 /*
2281 * NOTE: Since cnic calls register_driver routine rtnl_lock,
2282 * it will have higher precedence than bnx2fc_dev_lock.
2283 * unregister_device() cannot be called with bnx2fc_dev_lock
2284 * held.
2285 */
2286 mutex_lock(&bnx2fc_dev_lock);
2287 list_splice(&adapter_list, &to_be_deleted);
2288 INIT_LIST_HEAD(&adapter_list);
2289 adapter_count = 0;
2290 mutex_unlock(&bnx2fc_dev_lock);
2291
2292 /* Unregister with cnic */
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002293 list_for_each_entry_safe(hba, next, &to_be_deleted, list) {
2294 list_del_init(&hba->list);
2295 printk(KERN_ERR PFX "MOD_EXIT:destroy hba = 0x%p\n",
2296 hba);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002297 bnx2fc_ulp_stop(hba);
2298 /* unregister cnic device */
2299 if (test_and_clear_bit(BNX2FC_CNIC_REGISTERED,
2300 &hba->reg_with_cnic))
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002301 hba->cnic->unregister_device(hba->cnic,
2302 CNIC_ULP_FCOE);
2303 bnx2fc_hba_destroy(hba);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002304 }
2305 cnic_unregister_driver(CNIC_ULP_FCOE);
2306
2307 /* Destroy global thread */
2308 bg = &bnx2fc_global;
2309 spin_lock_bh(&bg->fcoe_rx_list.lock);
2310 l2_thread = bg->thread;
2311 bg->thread = NULL;
2312 while ((skb = __skb_dequeue(&bg->fcoe_rx_list)) != NULL)
2313 kfree_skb(skb);
2314
2315 spin_unlock_bh(&bg->fcoe_rx_list.lock);
2316
2317 if (l2_thread)
2318 kthread_stop(l2_thread);
2319
2320 unregister_hotcpu_notifier(&bnx2fc_cpu_notifier);
2321
2322 /* Destroy per cpu threads */
2323 for_each_online_cpu(cpu) {
2324 bnx2fc_percpu_thread_destroy(cpu);
2325 }
2326
2327 destroy_workqueue(bnx2fc_wq);
2328 /*
2329 * detach from scsi transport
2330 * must happen after all destroys are done
2331 */
2332 bnx2fc_release_transport();
2333
2334 /* detach from fcoe transport */
2335 fcoe_transport_detach(&bnx2fc_transport);
2336}
2337
2338module_init(bnx2fc_mod_init);
2339module_exit(bnx2fc_mod_exit);
2340
2341static struct fc_function_template bnx2fc_transport_function = {
2342 .show_host_node_name = 1,
2343 .show_host_port_name = 1,
2344 .show_host_supported_classes = 1,
2345 .show_host_supported_fc4s = 1,
2346 .show_host_active_fc4s = 1,
2347 .show_host_maxframe_size = 1,
2348
2349 .show_host_port_id = 1,
2350 .show_host_supported_speeds = 1,
2351 .get_host_speed = fc_get_host_speed,
2352 .show_host_speed = 1,
2353 .show_host_port_type = 1,
2354 .get_host_port_state = fc_get_host_port_state,
2355 .show_host_port_state = 1,
2356 .show_host_symbolic_name = 1,
2357
2358 .dd_fcrport_size = (sizeof(struct fc_rport_libfc_priv) +
2359 sizeof(struct bnx2fc_rport)),
2360 .show_rport_maxframe_size = 1,
2361 .show_rport_supported_classes = 1,
2362
2363 .show_host_fabric_name = 1,
2364 .show_starget_node_name = 1,
2365 .show_starget_port_name = 1,
2366 .show_starget_port_id = 1,
2367 .set_rport_dev_loss_tmo = fc_set_rport_loss_tmo,
2368 .show_rport_dev_loss_tmo = 1,
2369 .get_fc_host_stats = bnx2fc_get_host_stats,
2370
2371 .issue_fc_host_lip = bnx2fc_fcoe_reset,
2372
2373 .terminate_rport_io = fc_rport_terminate_io,
2374
2375 .vport_create = bnx2fc_vport_create,
2376 .vport_delete = bnx2fc_vport_destroy,
2377 .vport_disable = bnx2fc_vport_disable,
2378};
2379
2380static struct fc_function_template bnx2fc_vport_xport_function = {
2381 .show_host_node_name = 1,
2382 .show_host_port_name = 1,
2383 .show_host_supported_classes = 1,
2384 .show_host_supported_fc4s = 1,
2385 .show_host_active_fc4s = 1,
2386 .show_host_maxframe_size = 1,
2387
2388 .show_host_port_id = 1,
2389 .show_host_supported_speeds = 1,
2390 .get_host_speed = fc_get_host_speed,
2391 .show_host_speed = 1,
2392 .show_host_port_type = 1,
2393 .get_host_port_state = fc_get_host_port_state,
2394 .show_host_port_state = 1,
2395 .show_host_symbolic_name = 1,
2396
2397 .dd_fcrport_size = (sizeof(struct fc_rport_libfc_priv) +
2398 sizeof(struct bnx2fc_rport)),
2399 .show_rport_maxframe_size = 1,
2400 .show_rport_supported_classes = 1,
2401
2402 .show_host_fabric_name = 1,
2403 .show_starget_node_name = 1,
2404 .show_starget_port_name = 1,
2405 .show_starget_port_id = 1,
2406 .set_rport_dev_loss_tmo = fc_set_rport_loss_tmo,
2407 .show_rport_dev_loss_tmo = 1,
2408 .get_fc_host_stats = fc_get_host_stats,
2409 .issue_fc_host_lip = bnx2fc_fcoe_reset,
2410 .terminate_rport_io = fc_rport_terminate_io,
2411};
2412
2413/**
2414 * scsi_host_template structure used while registering with SCSI-ml
2415 */
2416static struct scsi_host_template bnx2fc_shost_template = {
2417 .module = THIS_MODULE,
2418 .name = "Broadcom Offload FCoE Initiator",
2419 .queuecommand = bnx2fc_queuecommand,
2420 .eh_abort_handler = bnx2fc_eh_abort, /* abts */
2421 .eh_device_reset_handler = bnx2fc_eh_device_reset, /* lun reset */
2422 .eh_target_reset_handler = bnx2fc_eh_target_reset, /* tgt reset */
2423 .eh_host_reset_handler = fc_eh_host_reset,
2424 .slave_alloc = fc_slave_alloc,
2425 .change_queue_depth = fc_change_queue_depth,
2426 .change_queue_type = fc_change_queue_type,
2427 .this_id = -1,
2428 .cmd_per_lun = 3,
Bhanu Gollapudi0ea5c272011-03-17 17:13:29 -07002429 .can_queue = BNX2FC_CAN_QUEUE,
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002430 .use_clustering = ENABLE_CLUSTERING,
2431 .sg_tablesize = BNX2FC_MAX_BDS_PER_CMD,
2432 .max_sectors = 512,
2433};
2434
2435static struct libfc_function_template bnx2fc_libfc_fcn_templ = {
2436 .frame_send = bnx2fc_xmit,
2437 .elsct_send = bnx2fc_elsct_send,
2438 .fcp_abort_io = bnx2fc_abort_io,
2439 .fcp_cleanup = bnx2fc_cleanup,
2440 .rport_event_callback = bnx2fc_rport_event_handler,
2441};
2442
2443/**
2444 * bnx2fc_cnic_cb - global template of bnx2fc - cnic driver interface
2445 * structure carrying callback function pointers
2446 */
2447static struct cnic_ulp_ops bnx2fc_cnic_cb = {
2448 .owner = THIS_MODULE,
2449 .cnic_init = bnx2fc_ulp_init,
2450 .cnic_exit = bnx2fc_ulp_exit,
2451 .cnic_start = bnx2fc_ulp_start,
2452 .cnic_stop = bnx2fc_ulp_stop,
2453 .indicate_kcqes = bnx2fc_indicate_kcqe,
2454 .indicate_netevent = bnx2fc_indicate_netevent,
2455};