blob: a4770d9fc80e3a6b3c83f57731401c132077a1ef [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;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800421
422 bg = &bnx2fc_global;
423 spin_lock_bh(&bg->fcoe_rx_list.lock);
424
425 __skb_queue_tail(&bg->fcoe_rx_list, skb);
426 if (bg->fcoe_rx_list.qlen == 1)
427 wake_up_process(bg->thread);
428
429 spin_unlock_bh(&bg->fcoe_rx_list.lock);
430
431 return 0;
432err:
433 kfree_skb(skb);
434 return -1;
435}
436
437static int bnx2fc_l2_rcv_thread(void *arg)
438{
439 struct fcoe_percpu_s *bg = arg;
440 struct sk_buff *skb;
441
442 set_user_nice(current, -20);
443 set_current_state(TASK_INTERRUPTIBLE);
444 while (!kthread_should_stop()) {
445 schedule();
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800446 spin_lock_bh(&bg->fcoe_rx_list.lock);
447 while ((skb = __skb_dequeue(&bg->fcoe_rx_list)) != NULL) {
448 spin_unlock_bh(&bg->fcoe_rx_list.lock);
449 bnx2fc_recv_frame(skb);
450 spin_lock_bh(&bg->fcoe_rx_list.lock);
451 }
Bhanu Gollapudifee78712011-03-21 18:51:13 -0700452 __set_current_state(TASK_INTERRUPTIBLE);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800453 spin_unlock_bh(&bg->fcoe_rx_list.lock);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800454 }
Bhanu Gollapudifee78712011-03-21 18:51:13 -0700455 __set_current_state(TASK_RUNNING);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800456 return 0;
457}
458
459
460static void bnx2fc_recv_frame(struct sk_buff *skb)
461{
462 u32 fr_len;
463 struct fc_lport *lport;
464 struct fcoe_rcv_info *fr;
465 struct fcoe_dev_stats *stats;
466 struct fc_frame_header *fh;
467 struct fcoe_crc_eof crc_eof;
468 struct fc_frame *fp;
469 struct fc_lport *vn_port;
470 struct fcoe_port *port;
471 u8 *mac = NULL;
472 u8 *dest_mac = NULL;
473 struct fcoe_hdr *hp;
474
475 fr = fcoe_dev_from_skb(skb);
476 lport = fr->fr_dev;
477 if (unlikely(lport == NULL)) {
Bhanu Prakash Gollapudib2a554f2011-06-27 23:30:53 -0700478 printk(KERN_ERR PFX "Invalid lport struct\n");
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800479 kfree_skb(skb);
480 return;
481 }
482
483 if (skb_is_nonlinear(skb))
484 skb_linearize(skb);
485 mac = eth_hdr(skb)->h_source;
486 dest_mac = eth_hdr(skb)->h_dest;
487
488 /* Pull the header */
489 hp = (struct fcoe_hdr *) skb_network_header(skb);
490 fh = (struct fc_frame_header *) skb_transport_header(skb);
491 skb_pull(skb, sizeof(struct fcoe_hdr));
492 fr_len = skb->len - sizeof(struct fcoe_crc_eof);
493
494 stats = per_cpu_ptr(lport->dev_stats, get_cpu());
495 stats->RxFrames++;
496 stats->RxWords += fr_len / FCOE_WORD_TO_BYTE;
497
498 fp = (struct fc_frame *)skb;
499 fc_frame_init(fp);
500 fr_dev(fp) = lport;
501 fr_sof(fp) = hp->fcoe_sof;
502 if (skb_copy_bits(skb, fr_len, &crc_eof, sizeof(crc_eof))) {
503 put_cpu();
504 kfree_skb(skb);
505 return;
506 }
507 fr_eof(fp) = crc_eof.fcoe_eof;
508 fr_crc(fp) = crc_eof.fcoe_crc32;
509 if (pskb_trim(skb, fr_len)) {
510 put_cpu();
511 kfree_skb(skb);
512 return;
513 }
514
515 fh = fc_frame_header_get(fp);
516
517 vn_port = fc_vport_id_lookup(lport, ntoh24(fh->fh_d_id));
518 if (vn_port) {
519 port = lport_priv(vn_port);
520 if (compare_ether_addr(port->data_src_addr, dest_mac)
521 != 0) {
522 BNX2FC_HBA_DBG(lport, "fpma mismatch\n");
523 put_cpu();
524 kfree_skb(skb);
525 return;
526 }
527 }
528 if (fh->fh_r_ctl == FC_RCTL_DD_SOL_DATA &&
529 fh->fh_type == FC_TYPE_FCP) {
530 /* Drop FCP data. We dont this in L2 path */
531 put_cpu();
532 kfree_skb(skb);
533 return;
534 }
535 if (fh->fh_r_ctl == FC_RCTL_ELS_REQ &&
536 fh->fh_type == FC_TYPE_ELS) {
537 switch (fc_frame_payload_op(fp)) {
538 case ELS_LOGO:
539 if (ntoh24(fh->fh_s_id) == FC_FID_FLOGI) {
540 /* drop non-FIP LOGO */
541 put_cpu();
542 kfree_skb(skb);
543 return;
544 }
545 break;
546 }
547 }
548 if (le32_to_cpu(fr_crc(fp)) !=
549 ~crc32(~0, skb->data, fr_len)) {
550 if (stats->InvalidCRCCount < 5)
551 printk(KERN_WARNING PFX "dropping frame with "
552 "CRC error\n");
553 stats->InvalidCRCCount++;
554 put_cpu();
555 kfree_skb(skb);
556 return;
557 }
558 put_cpu();
559 fc_exch_recv(lport, fp);
560}
561
562/**
563 * bnx2fc_percpu_io_thread - thread per cpu for ios
564 *
565 * @arg: ptr to bnx2fc_percpu_info structure
566 */
567int bnx2fc_percpu_io_thread(void *arg)
568{
569 struct bnx2fc_percpu_s *p = arg;
570 struct bnx2fc_work *work, *tmp;
571 LIST_HEAD(work_list);
572
573 set_user_nice(current, -20);
574 set_current_state(TASK_INTERRUPTIBLE);
575 while (!kthread_should_stop()) {
576 schedule();
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800577 spin_lock_bh(&p->fp_work_lock);
578 while (!list_empty(&p->work_list)) {
579 list_splice_init(&p->work_list, &work_list);
580 spin_unlock_bh(&p->fp_work_lock);
581
582 list_for_each_entry_safe(work, tmp, &work_list, list) {
583 list_del_init(&work->list);
584 bnx2fc_process_cq_compl(work->tgt, work->wqe);
585 kfree(work);
586 }
587
588 spin_lock_bh(&p->fp_work_lock);
589 }
Bhanu Gollapudifee78712011-03-21 18:51:13 -0700590 __set_current_state(TASK_INTERRUPTIBLE);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800591 spin_unlock_bh(&p->fp_work_lock);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800592 }
Bhanu Gollapudifee78712011-03-21 18:51:13 -0700593 __set_current_state(TASK_RUNNING);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800594
595 return 0;
596}
597
598static struct fc_host_statistics *bnx2fc_get_host_stats(struct Scsi_Host *shost)
599{
600 struct fc_host_statistics *bnx2fc_stats;
601 struct fc_lport *lport = shost_priv(shost);
602 struct fcoe_port *port = lport_priv(lport);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700603 struct bnx2fc_interface *interface = port->priv;
604 struct bnx2fc_hba *hba = interface->hba;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800605 struct fcoe_statistics_params *fw_stats;
606 int rc = 0;
607
608 fw_stats = (struct fcoe_statistics_params *)hba->stats_buffer;
609 if (!fw_stats)
610 return NULL;
611
612 bnx2fc_stats = fc_get_host_stats(shost);
613
614 init_completion(&hba->stat_req_done);
615 if (bnx2fc_send_stat_req(hba))
616 return bnx2fc_stats;
617 rc = wait_for_completion_timeout(&hba->stat_req_done, (2 * HZ));
618 if (!rc) {
619 BNX2FC_HBA_DBG(lport, "FW stat req timed out\n");
620 return bnx2fc_stats;
621 }
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300622 bnx2fc_stats->invalid_crc_count += fw_stats->rx_stat2.fc_crc_cnt;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800623 bnx2fc_stats->tx_frames += fw_stats->tx_stat.fcoe_tx_pkt_cnt;
624 bnx2fc_stats->tx_words += (fw_stats->tx_stat.fcoe_tx_byte_cnt) / 4;
625 bnx2fc_stats->rx_frames += fw_stats->rx_stat0.fcoe_rx_pkt_cnt;
626 bnx2fc_stats->rx_words += (fw_stats->rx_stat0.fcoe_rx_byte_cnt) / 4;
627
628 bnx2fc_stats->dumped_frames = 0;
629 bnx2fc_stats->lip_count = 0;
630 bnx2fc_stats->nos_count = 0;
631 bnx2fc_stats->loss_of_sync_count = 0;
632 bnx2fc_stats->loss_of_signal_count = 0;
633 bnx2fc_stats->prim_seq_protocol_err_count = 0;
634
635 return bnx2fc_stats;
636}
637
638static int bnx2fc_shost_config(struct fc_lport *lport, struct device *dev)
639{
640 struct fcoe_port *port = lport_priv(lport);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700641 struct bnx2fc_interface *interface = port->priv;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800642 struct Scsi_Host *shost = lport->host;
643 int rc = 0;
644
645 shost->max_cmd_len = BNX2FC_MAX_CMD_LEN;
646 shost->max_lun = BNX2FC_MAX_LUN;
647 shost->max_id = BNX2FC_MAX_FCP_TGT;
648 shost->max_channel = 0;
649 if (lport->vport)
650 shost->transportt = bnx2fc_vport_xport_template;
651 else
652 shost->transportt = bnx2fc_transport_template;
653
654 /* Add the new host to SCSI-ml */
655 rc = scsi_add_host(lport->host, dev);
656 if (rc) {
657 printk(KERN_ERR PFX "Error on scsi_add_host\n");
658 return rc;
659 }
660 if (!lport->vport)
661 fc_host_max_npiv_vports(lport->host) = USHRT_MAX;
662 sprintf(fc_host_symbolic_name(lport->host), "%s v%s over %s",
663 BNX2FC_NAME, BNX2FC_VERSION,
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700664 interface->netdev->name);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800665
666 return 0;
667}
668
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800669static void bnx2fc_link_speed_update(struct fc_lport *lport)
670{
671 struct fcoe_port *port = lport_priv(lport);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700672 struct bnx2fc_interface *interface = port->priv;
673 struct net_device *netdev = interface->netdev;
David Decotigny8ae6dac2011-04-27 18:32:38 +0000674 struct ethtool_cmd ecmd;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800675
676 if (!dev_ethtool_get_settings(netdev, &ecmd)) {
677 lport->link_supported_speeds &=
678 ~(FC_PORTSPEED_1GBIT | FC_PORTSPEED_10GBIT);
679 if (ecmd.supported & (SUPPORTED_1000baseT_Half |
680 SUPPORTED_1000baseT_Full))
681 lport->link_supported_speeds |= FC_PORTSPEED_1GBIT;
682 if (ecmd.supported & SUPPORTED_10000baseT_Full)
683 lport->link_supported_speeds |= FC_PORTSPEED_10GBIT;
684
David Decotigny8ae6dac2011-04-27 18:32:38 +0000685 switch (ethtool_cmd_speed(&ecmd)) {
686 case SPEED_1000:
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800687 lport->link_speed = FC_PORTSPEED_1GBIT;
David Decotigny8ae6dac2011-04-27 18:32:38 +0000688 break;
Bhanu Prakash Gollapudia4dc08c2011-05-27 11:47:25 -0700689 case SPEED_2500:
690 lport->link_speed = FC_PORTSPEED_2GBIT;
691 break;
David Decotigny8ae6dac2011-04-27 18:32:38 +0000692 case SPEED_10000:
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800693 lport->link_speed = FC_PORTSPEED_10GBIT;
David Decotigny8ae6dac2011-04-27 18:32:38 +0000694 break;
695 }
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800696 }
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800697}
698static int bnx2fc_link_ok(struct fc_lport *lport)
699{
700 struct fcoe_port *port = lport_priv(lport);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700701 struct bnx2fc_interface *interface = port->priv;
702 struct bnx2fc_hba *hba = interface->hba;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800703 struct net_device *dev = hba->phys_dev;
704 int rc = 0;
705
706 if ((dev->flags & IFF_UP) && netif_carrier_ok(dev))
707 clear_bit(ADAPTER_STATE_LINK_DOWN, &hba->adapter_state);
708 else {
709 set_bit(ADAPTER_STATE_LINK_DOWN, &hba->adapter_state);
710 rc = -1;
711 }
712 return rc;
713}
714
715/**
716 * bnx2fc_get_link_state - get network link state
717 *
718 * @hba: adapter instance pointer
719 *
720 * updates adapter structure flag based on netdev state
721 */
722void bnx2fc_get_link_state(struct bnx2fc_hba *hba)
723{
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700724 if (test_bit(__LINK_STATE_NOCARRIER, &hba->phys_dev->state))
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800725 set_bit(ADAPTER_STATE_LINK_DOWN, &hba->adapter_state);
726 else
727 clear_bit(ADAPTER_STATE_LINK_DOWN, &hba->adapter_state);
728}
729
730static int bnx2fc_net_config(struct fc_lport *lport)
731{
732 struct bnx2fc_hba *hba;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700733 struct bnx2fc_interface *interface;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800734 struct fcoe_port *port;
735 u64 wwnn, wwpn;
736
737 port = lport_priv(lport);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700738 interface = port->priv;
739 hba = interface->hba;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800740
741 /* require support for get_pauseparam ethtool op. */
742 if (!hba->phys_dev->ethtool_ops ||
743 !hba->phys_dev->ethtool_ops->get_pauseparam)
744 return -EOPNOTSUPP;
745
Bhanu Gollapudi1294bfe2011-03-17 17:13:34 -0700746 if (fc_set_mfs(lport, BNX2FC_MFS))
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800747 return -EINVAL;
748
749 skb_queue_head_init(&port->fcoe_pending_queue);
750 port->fcoe_pending_queue_active = 0;
751 setup_timer(&port->timer, fcoe_queue_timer, (unsigned long) lport);
752
753 bnx2fc_link_speed_update(lport);
754
755 if (!lport->vport) {
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700756 wwnn = fcoe_wwn_from_mac(interface->ctlr.ctl_src_addr, 1, 0);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800757 BNX2FC_HBA_DBG(lport, "WWNN = 0x%llx\n", wwnn);
758 fc_set_wwnn(lport, wwnn);
759
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700760 wwpn = fcoe_wwn_from_mac(interface->ctlr.ctl_src_addr, 2, 0);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800761 BNX2FC_HBA_DBG(lport, "WWPN = 0x%llx\n", wwpn);
762 fc_set_wwpn(lport, wwpn);
763 }
764
765 return 0;
766}
767
768static void bnx2fc_destroy_timer(unsigned long data)
769{
770 struct bnx2fc_hba *hba = (struct bnx2fc_hba *)data;
771
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700772 BNX2FC_MISC_DBG("ERROR:bnx2fc_destroy_timer - "
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800773 "Destroy compl not received!!\n");
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700774 set_bit(BNX2FC_FLAG_DESTROY_CMPL, &hba->flags);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800775 wake_up_interruptible(&hba->destroy_wait);
776}
777
778/**
779 * bnx2fc_indicate_netevent - Generic netdev event handler
780 *
781 * @context: adapter structure pointer
782 * @event: event type
Michael Chan415199f2011-07-20 14:55:24 +0000783 * @vlan_id: vlan id - associated vlan id with this event
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800784 *
785 * Handles NETDEV_UP, NETDEV_DOWN, NETDEV_GOING_DOWN,NETDEV_CHANGE and
786 * NETDEV_CHANGE_MTU events
787 */
Michael Chan415199f2011-07-20 14:55:24 +0000788static void bnx2fc_indicate_netevent(void *context, unsigned long event,
789 u16 vlan_id)
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800790{
791 struct bnx2fc_hba *hba = (struct bnx2fc_hba *)context;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700792 struct fc_lport *lport;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800793 struct fc_lport *vport;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700794 struct bnx2fc_interface *interface;
795 int wait_for_upload = 0;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800796 u32 link_possible = 1;
797
Michael Chan415199f2011-07-20 14:55:24 +0000798 /* Ignore vlans for now */
799 if (vlan_id != 0)
800 return;
801
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800802 switch (event) {
803 case NETDEV_UP:
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800804 if (!test_bit(ADAPTER_STATE_UP, &hba->adapter_state))
805 printk(KERN_ERR "indicate_netevent: "\
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700806 "hba is not UP!!\n");
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800807 break;
808
809 case NETDEV_DOWN:
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800810 clear_bit(ADAPTER_STATE_GOING_DOWN, &hba->adapter_state);
811 clear_bit(ADAPTER_STATE_UP, &hba->adapter_state);
812 link_possible = 0;
813 break;
814
815 case NETDEV_GOING_DOWN:
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800816 set_bit(ADAPTER_STATE_GOING_DOWN, &hba->adapter_state);
817 link_possible = 0;
818 break;
819
820 case NETDEV_CHANGE:
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800821 break;
822
823 default:
824 printk(KERN_ERR PFX "Unkonwn netevent %ld", event);
825 return;
826 }
827
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700828 mutex_lock(&bnx2fc_dev_lock);
829 list_for_each_entry(interface, &if_list, list) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800830
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700831 if (interface->hba != hba)
832 continue;
833
834 lport = interface->ctlr.lp;
835 BNX2FC_HBA_DBG(lport, "netevent handler - event=%s %ld\n",
836 interface->netdev->name, event);
837
838 bnx2fc_link_speed_update(lport);
839
840 if (link_possible && !bnx2fc_link_ok(lport)) {
841 printk(KERN_ERR "indicate_netevent: ctlr_link_up\n");
842 fcoe_ctlr_link_up(&interface->ctlr);
843 } else if (fcoe_ctlr_link_down(&interface->ctlr)) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800844 mutex_lock(&lport->lp_mutex);
845 list_for_each_entry(vport, &lport->vports, list)
846 fc_host_port_type(vport->host) =
847 FC_PORTTYPE_UNKNOWN;
848 mutex_unlock(&lport->lp_mutex);
849 fc_host_port_type(lport->host) = FC_PORTTYPE_UNKNOWN;
850 per_cpu_ptr(lport->dev_stats,
851 get_cpu())->LinkFailureCount++;
852 put_cpu();
853 fcoe_clean_pending_queue(lport);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700854 wait_for_upload = 1;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800855 }
856 }
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700857 mutex_unlock(&bnx2fc_dev_lock);
858
859 if (wait_for_upload) {
860 clear_bit(ADAPTER_STATE_READY, &hba->adapter_state);
861 init_waitqueue_head(&hba->shutdown_wait);
862 BNX2FC_MISC_DBG("indicate_netevent "
863 "num_ofld_sess = %d\n",
864 hba->num_ofld_sess);
865 hba->wait_for_link_down = 1;
866 wait_event_interruptible(hba->shutdown_wait,
867 (hba->num_ofld_sess == 0));
868 BNX2FC_MISC_DBG("wakeup - num_ofld_sess = %d\n",
869 hba->num_ofld_sess);
870 hba->wait_for_link_down = 0;
871
872 if (signal_pending(current))
873 flush_signals(current);
874 }
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800875}
876
877static int bnx2fc_libfc_config(struct fc_lport *lport)
878{
879
880 /* Set the function pointers set by bnx2fc driver */
881 memcpy(&lport->tt, &bnx2fc_libfc_fcn_templ,
882 sizeof(struct libfc_function_template));
883 fc_elsct_init(lport);
884 fc_exch_init(lport);
885 fc_rport_init(lport);
886 fc_disc_init(lport);
887 return 0;
888}
889
890static int bnx2fc_em_config(struct fc_lport *lport)
891{
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800892 if (!fc_exch_mgr_alloc(lport, FC_CLASS_3, FCOE_MIN_XID,
893 FCOE_MAX_XID, NULL)) {
894 printk(KERN_ERR PFX "em_config:fc_exch_mgr_alloc failed\n");
895 return -ENOMEM;
896 }
897
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800898 return 0;
899}
900
901static int bnx2fc_lport_config(struct fc_lport *lport)
902{
903 lport->link_up = 0;
904 lport->qfull = 0;
905 lport->max_retry_count = 3;
906 lport->max_rport_retry_count = 3;
907 lport->e_d_tov = 2 * 1000;
908 lport->r_a_tov = 10 * 1000;
909
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800910 lport->service_params = (FCP_SPPF_INIT_FCN | FCP_SPPF_RD_XRDY_DIS |
911 FCP_SPPF_RETRY | FCP_SPPF_CONF_COMPL);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800912 lport->does_npiv = 1;
913
914 memset(&lport->rnid_gen, 0, sizeof(struct fc_els_rnid_gen));
915 lport->rnid_gen.rnid_atype = BNX2FC_RNID_HBA;
916
917 /* alloc stats structure */
918 if (fc_lport_init_stats(lport))
919 return -ENOMEM;
920
921 /* Finish fc_lport configuration */
922 fc_lport_config(lport);
923
924 return 0;
925}
926
927/**
928 * bnx2fc_fip_recv - handle a received FIP frame.
929 *
930 * @skb: the received skb
931 * @dev: associated &net_device
932 * @ptype: the &packet_type structure which was used to register this handler.
933 * @orig_dev: original receive &net_device, in case @ dev is a bond.
934 *
935 * Returns: 0 for success
936 */
937static int bnx2fc_fip_recv(struct sk_buff *skb, struct net_device *dev,
938 struct packet_type *ptype,
939 struct net_device *orig_dev)
940{
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700941 struct bnx2fc_interface *interface;
942 interface = container_of(ptype, struct bnx2fc_interface,
943 fip_packet_type);
944 fcoe_ctlr_recv(&interface->ctlr, skb);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800945 return 0;
946}
947
948/**
949 * bnx2fc_update_src_mac - Update Ethernet MAC filters.
950 *
951 * @fip: FCoE controller.
952 * @old: Unicast MAC address to delete if the MAC is non-zero.
953 * @new: Unicast MAC address to add.
954 *
955 * Remove any previously-set unicast MAC filter.
956 * Add secondary FCoE MAC address filter for our OUI.
957 */
958static void bnx2fc_update_src_mac(struct fc_lport *lport, u8 *addr)
959{
960 struct fcoe_port *port = lport_priv(lport);
961
962 memcpy(port->data_src_addr, addr, ETH_ALEN);
963}
964
965/**
966 * bnx2fc_get_src_mac - return the ethernet source address for an lport
967 *
968 * @lport: libfc port
969 */
970static u8 *bnx2fc_get_src_mac(struct fc_lport *lport)
971{
972 struct fcoe_port *port;
973
974 port = (struct fcoe_port *)lport_priv(lport);
975 return port->data_src_addr;
976}
977
978/**
979 * bnx2fc_fip_send - send an Ethernet-encapsulated FIP frame.
980 *
981 * @fip: FCoE controller.
982 * @skb: FIP Packet.
983 */
984static void bnx2fc_fip_send(struct fcoe_ctlr *fip, struct sk_buff *skb)
985{
986 skb->dev = bnx2fc_from_ctlr(fip)->netdev;
987 dev_queue_xmit(skb);
988}
989
990static int bnx2fc_vport_create(struct fc_vport *vport, bool disabled)
991{
992 struct Scsi_Host *shost = vport_to_shost(vport);
993 struct fc_lport *n_port = shost_priv(shost);
994 struct fcoe_port *port = lport_priv(n_port);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700995 struct bnx2fc_interface *interface = port->priv;
996 struct net_device *netdev = interface->netdev;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800997 struct fc_lport *vn_port;
998
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700999 if (!test_bit(BNX2FC_FLAG_FW_INIT_DONE, &interface->hba->flags)) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001000 printk(KERN_ERR PFX "vn ports cannot be created on"
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001001 "this interface\n");
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001002 return -EIO;
1003 }
1004 mutex_lock(&bnx2fc_dev_lock);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001005 vn_port = bnx2fc_if_create(interface, &vport->dev, 1);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001006 mutex_unlock(&bnx2fc_dev_lock);
1007
1008 if (IS_ERR(vn_port)) {
1009 printk(KERN_ERR PFX "bnx2fc_vport_create (%s) failed\n",
1010 netdev->name);
1011 return -EIO;
1012 }
1013
1014 if (disabled) {
1015 fc_vport_set_state(vport, FC_VPORT_DISABLED);
1016 } else {
1017 vn_port->boot_time = jiffies;
1018 fc_lport_init(vn_port);
1019 fc_fabric_login(vn_port);
1020 fc_vport_setlink(vn_port);
1021 }
1022 return 0;
1023}
1024
1025static int bnx2fc_vport_destroy(struct fc_vport *vport)
1026{
1027 struct Scsi_Host *shost = vport_to_shost(vport);
1028 struct fc_lport *n_port = shost_priv(shost);
1029 struct fc_lport *vn_port = vport->dd_data;
1030 struct fcoe_port *port = lport_priv(vn_port);
1031
1032 mutex_lock(&n_port->lp_mutex);
1033 list_del(&vn_port->list);
1034 mutex_unlock(&n_port->lp_mutex);
1035 queue_work(bnx2fc_wq, &port->destroy_work);
1036 return 0;
1037}
1038
1039static int bnx2fc_vport_disable(struct fc_vport *vport, bool disable)
1040{
1041 struct fc_lport *lport = vport->dd_data;
1042
1043 if (disable) {
1044 fc_vport_set_state(vport, FC_VPORT_DISABLED);
1045 fc_fabric_logoff(lport);
1046 } else {
1047 lport->boot_time = jiffies;
1048 fc_fabric_login(lport);
1049 fc_vport_setlink(lport);
1050 }
1051 return 0;
1052}
1053
1054
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001055static int bnx2fc_netdev_setup(struct bnx2fc_interface *interface)
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001056{
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001057 struct net_device *netdev = interface->netdev;
1058 struct net_device *physdev = interface->hba->phys_dev;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001059 struct netdev_hw_addr *ha;
1060 int sel_san_mac = 0;
1061
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001062 /* setup Source MAC Address */
1063 rcu_read_lock();
1064 for_each_dev_addr(physdev, ha) {
1065 BNX2FC_MISC_DBG("net_config: ha->type = %d, fip_mac = ",
1066 ha->type);
1067 printk(KERN_INFO "%2x:%2x:%2x:%2x:%2x:%2x\n", ha->addr[0],
1068 ha->addr[1], ha->addr[2], ha->addr[3],
1069 ha->addr[4], ha->addr[5]);
1070
1071 if ((ha->type == NETDEV_HW_ADDR_T_SAN) &&
1072 (is_valid_ether_addr(ha->addr))) {
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001073 memcpy(interface->ctlr.ctl_src_addr, ha->addr,
1074 ETH_ALEN);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001075 sel_san_mac = 1;
1076 BNX2FC_MISC_DBG("Found SAN MAC\n");
1077 }
1078 }
1079 rcu_read_unlock();
1080
1081 if (!sel_san_mac)
1082 return -ENODEV;
1083
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001084 interface->fip_packet_type.func = bnx2fc_fip_recv;
1085 interface->fip_packet_type.type = htons(ETH_P_FIP);
1086 interface->fip_packet_type.dev = netdev;
1087 dev_add_pack(&interface->fip_packet_type);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001088
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001089 interface->fcoe_packet_type.func = bnx2fc_rcv;
1090 interface->fcoe_packet_type.type = __constant_htons(ETH_P_FCOE);
1091 interface->fcoe_packet_type.dev = netdev;
1092 dev_add_pack(&interface->fcoe_packet_type);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001093
1094 return 0;
1095}
1096
1097static int bnx2fc_attach_transport(void)
1098{
1099 bnx2fc_transport_template =
1100 fc_attach_transport(&bnx2fc_transport_function);
1101
1102 if (bnx2fc_transport_template == NULL) {
1103 printk(KERN_ERR PFX "Failed to attach FC transport\n");
1104 return -ENODEV;
1105 }
1106
1107 bnx2fc_vport_xport_template =
1108 fc_attach_transport(&bnx2fc_vport_xport_function);
1109 if (bnx2fc_vport_xport_template == NULL) {
1110 printk(KERN_ERR PFX
1111 "Failed to attach FC transport for vport\n");
1112 fc_release_transport(bnx2fc_transport_template);
1113 bnx2fc_transport_template = NULL;
1114 return -ENODEV;
1115 }
1116 return 0;
1117}
1118static void bnx2fc_release_transport(void)
1119{
1120 fc_release_transport(bnx2fc_transport_template);
1121 fc_release_transport(bnx2fc_vport_xport_template);
1122 bnx2fc_transport_template = NULL;
1123 bnx2fc_vport_xport_template = NULL;
1124}
1125
1126static void bnx2fc_interface_release(struct kref *kref)
1127{
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001128 struct bnx2fc_interface *interface;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001129 struct net_device *netdev;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001130
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001131 interface = container_of(kref, struct bnx2fc_interface, kref);
Nithin Nayak Sujir068bdce2011-04-25 12:30:09 -07001132 BNX2FC_MISC_DBG("Interface is being released\n");
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001133
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001134 netdev = interface->netdev;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001135
1136 /* tear-down FIP controller */
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001137 if (test_and_clear_bit(BNX2FC_CTLR_INIT_DONE, &interface->if_flags))
1138 fcoe_ctlr_destroy(&interface->ctlr);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001139
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001140 kfree(interface);
1141
1142 dev_put(netdev);
1143 module_put(THIS_MODULE);
1144}
1145
1146static inline void bnx2fc_interface_get(struct bnx2fc_interface *interface)
1147{
1148 kref_get(&interface->kref);
1149}
1150
1151static inline void bnx2fc_interface_put(struct bnx2fc_interface *interface)
1152{
1153 kref_put(&interface->kref, bnx2fc_interface_release);
1154}
1155static void bnx2fc_hba_destroy(struct bnx2fc_hba *hba)
1156{
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001157 /* Free the command manager */
1158 if (hba->cmd_mgr) {
1159 bnx2fc_cmd_mgr_free(hba->cmd_mgr);
1160 hba->cmd_mgr = NULL;
1161 }
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001162 kfree(hba->tgt_ofld_list);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001163 bnx2fc_unbind_pcidev(hba);
1164 kfree(hba);
1165}
1166
1167/**
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001168 * bnx2fc_hba_create - create a new bnx2fc hba
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001169 *
1170 * @cnic: pointer to cnic device
1171 *
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001172 * Creates a new FCoE hba on the given device.
1173 *
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001174 */
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001175static struct bnx2fc_hba *bnx2fc_hba_create(struct cnic_dev *cnic)
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001176{
1177 struct bnx2fc_hba *hba;
1178 int rc;
1179
1180 hba = kzalloc(sizeof(*hba), GFP_KERNEL);
1181 if (!hba) {
1182 printk(KERN_ERR PFX "Unable to allocate hba structure\n");
1183 return NULL;
1184 }
1185 spin_lock_init(&hba->hba_lock);
1186 mutex_init(&hba->hba_mutex);
1187
1188 hba->cnic = cnic;
1189 rc = bnx2fc_bind_pcidev(hba);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001190 if (rc) {
1191 printk(KERN_ERR PFX "create_adapter: bind error\n");
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001192 goto bind_err;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001193 }
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001194 hba->phys_dev = cnic->netdev;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001195 hba->next_conn_id = 0;
1196
1197 hba->tgt_ofld_list =
1198 kzalloc(sizeof(struct bnx2fc_rport *) * BNX2FC_NUM_MAX_SESS,
1199 GFP_KERNEL);
1200 if (!hba->tgt_ofld_list) {
1201 printk(KERN_ERR PFX "Unable to allocate tgt offload list\n");
1202 goto tgtofld_err;
1203 }
1204
1205 hba->num_ofld_sess = 0;
1206
1207 hba->cmd_mgr = bnx2fc_cmd_mgr_alloc(hba, BNX2FC_MIN_XID,
1208 BNX2FC_MAX_XID);
1209 if (!hba->cmd_mgr) {
1210 printk(KERN_ERR PFX "em_config:bnx2fc_cmd_mgr_alloc failed\n");
1211 goto cmgr_err;
1212 }
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001213
1214 init_waitqueue_head(&hba->shutdown_wait);
1215 init_waitqueue_head(&hba->destroy_wait);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001216 INIT_LIST_HEAD(&hba->vports);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001217
1218 return hba;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001219
1220cmgr_err:
1221 kfree(hba->tgt_ofld_list);
1222tgtofld_err:
1223 bnx2fc_unbind_pcidev(hba);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001224bind_err:
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001225 kfree(hba);
1226 return NULL;
1227}
1228
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001229struct bnx2fc_interface *bnx2fc_interface_create(struct bnx2fc_hba *hba,
1230 struct net_device *netdev,
1231 enum fip_state fip_mode)
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001232{
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001233 struct bnx2fc_interface *interface;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001234 int rc = 0;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001235
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001236 interface = kzalloc(sizeof(*interface), GFP_KERNEL);
1237 if (!interface) {
1238 printk(KERN_ERR PFX "Unable to allocate interface structure\n");
1239 return NULL;
1240 }
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001241 dev_hold(netdev);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001242 kref_init(&interface->kref);
1243 interface->hba = hba;
1244 interface->netdev = netdev;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001245
1246 /* Initialize FIP */
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001247 fcoe_ctlr_init(&interface->ctlr, fip_mode);
1248 interface->ctlr.send = bnx2fc_fip_send;
1249 interface->ctlr.update_mac = bnx2fc_update_src_mac;
1250 interface->ctlr.get_src_addr = bnx2fc_get_src_mac;
1251 set_bit(BNX2FC_CTLR_INIT_DONE, &interface->if_flags);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001252
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001253 rc = bnx2fc_netdev_setup(interface);
1254 if (!rc)
1255 return interface;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001256
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001257 fcoe_ctlr_destroy(&interface->ctlr);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001258 dev_put(netdev);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001259 kfree(interface);
1260 return NULL;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001261}
1262
1263/**
1264 * bnx2fc_if_create - Create FCoE instance on a given interface
1265 *
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001266 * @interface: FCoE interface to create a local port on
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001267 * @parent: Device pointer to be the parent in sysfs for the SCSI host
1268 * @npiv: Indicates if the port is vport or not
1269 *
1270 * Creates a fc_lport instance and a Scsi_Host instance and configure them.
1271 *
1272 * Returns: Allocated fc_lport or an error pointer
1273 */
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001274static struct fc_lport *bnx2fc_if_create(struct bnx2fc_interface *interface,
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001275 struct device *parent, int npiv)
1276{
Vasu Dev134a4e22011-04-28 15:55:44 -07001277 struct fc_lport *lport, *n_port;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001278 struct fcoe_port *port;
1279 struct Scsi_Host *shost;
1280 struct fc_vport *vport = dev_to_vport(parent);
Bhanu Prakash Gollapudid36b3272011-05-27 11:47:27 -07001281 struct bnx2fc_lport *blport;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001282 struct bnx2fc_hba *hba;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001283 int rc = 0;
1284
Bhanu Prakash Gollapudid36b3272011-05-27 11:47:27 -07001285 blport = kzalloc(sizeof(struct bnx2fc_lport), GFP_KERNEL);
1286 if (!blport) {
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001287 BNX2FC_HBA_DBG(interface->ctlr.lp, "Unable to alloc blport\n");
Bhanu Prakash Gollapudid36b3272011-05-27 11:47:27 -07001288 return NULL;
1289 }
1290
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001291 /* Allocate Scsi_Host structure */
Vasu Dev134a4e22011-04-28 15:55:44 -07001292 if (!npiv)
1293 lport = libfc_host_alloc(&bnx2fc_shost_template, sizeof(*port));
1294 else
1295 lport = libfc_vport_create(vport, sizeof(*port));
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001296
1297 if (!lport) {
1298 printk(KERN_ERR PFX "could not allocate scsi host structure\n");
Bhanu Prakash Gollapudid36b3272011-05-27 11:47:27 -07001299 goto free_blport;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001300 }
1301 shost = lport->host;
1302 port = lport_priv(lport);
1303 port->lport = lport;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001304 port->priv = interface;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001305 INIT_WORK(&port->destroy_work, bnx2fc_destroy_work);
1306
1307 /* Configure fcoe_port */
1308 rc = bnx2fc_lport_config(lport);
1309 if (rc)
1310 goto lp_config_err;
1311
1312 if (npiv) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001313 printk(KERN_ERR PFX "Setting vport names, 0x%llX 0x%llX\n",
1314 vport->node_name, vport->port_name);
1315 fc_set_wwnn(lport, vport->node_name);
1316 fc_set_wwpn(lport, vport->port_name);
1317 }
1318 /* Configure netdev and networking properties of the lport */
1319 rc = bnx2fc_net_config(lport);
1320 if (rc) {
1321 printk(KERN_ERR PFX "Error on bnx2fc_net_config\n");
1322 goto lp_config_err;
1323 }
1324
1325 rc = bnx2fc_shost_config(lport, parent);
1326 if (rc) {
1327 printk(KERN_ERR PFX "Couldnt configure shost for %s\n",
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001328 interface->netdev->name);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001329 goto lp_config_err;
1330 }
1331
1332 /* Initialize the libfc library */
1333 rc = bnx2fc_libfc_config(lport);
1334 if (rc) {
1335 printk(KERN_ERR PFX "Couldnt configure libfc\n");
1336 goto shost_err;
1337 }
1338 fc_host_port_type(lport->host) = FC_PORTTYPE_UNKNOWN;
1339
1340 /* Allocate exchange manager */
Vasu Dev134a4e22011-04-28 15:55:44 -07001341 if (!npiv)
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001342 rc = bnx2fc_em_config(lport);
Vasu Dev134a4e22011-04-28 15:55:44 -07001343 else {
1344 shost = vport_to_shost(vport);
1345 n_port = shost_priv(shost);
1346 rc = fc_exch_mgr_list_clone(n_port, lport);
1347 }
1348
1349 if (rc) {
1350 printk(KERN_ERR PFX "Error on bnx2fc_em_config\n");
1351 goto shost_err;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001352 }
1353
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001354 bnx2fc_interface_get(interface);
Bhanu Prakash Gollapudid36b3272011-05-27 11:47:27 -07001355
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001356 hba = interface->hba;
Bhanu Prakash Gollapudid36b3272011-05-27 11:47:27 -07001357 spin_lock_bh(&hba->hba_lock);
1358 blport->lport = lport;
1359 list_add_tail(&blport->list, &hba->vports);
1360 spin_unlock_bh(&hba->hba_lock);
1361
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001362 return lport;
1363
1364shost_err:
1365 scsi_remove_host(shost);
1366lp_config_err:
1367 scsi_host_put(lport->host);
Bhanu Prakash Gollapudid36b3272011-05-27 11:47:27 -07001368free_blport:
1369 kfree(blport);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001370 return NULL;
1371}
1372
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001373static void bnx2fc_netdev_cleanup(struct bnx2fc_interface *interface)
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001374{
1375 /* Dont listen for Ethernet packets anymore */
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001376 __dev_remove_pack(&interface->fcoe_packet_type);
1377 __dev_remove_pack(&interface->fip_packet_type);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001378 synchronize_net();
1379}
1380
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001381static void bnx2fc_if_destroy(struct fc_lport *lport, struct bnx2fc_hba *hba)
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001382{
1383 struct fcoe_port *port = lport_priv(lport);
Bhanu Prakash Gollapudid36b3272011-05-27 11:47:27 -07001384 struct bnx2fc_lport *blport, *tmp;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001385
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001386 /* Stop the transmit retry timer */
1387 del_timer_sync(&port->timer);
1388
1389 /* Free existing transmit skbs */
1390 fcoe_clean_pending_queue(lport);
1391
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001392 /* Free queued packets for the receive thread */
1393 bnx2fc_clean_rx_queue(lport);
1394
1395 /* Detach from scsi-ml */
1396 fc_remove_host(lport->host);
1397 scsi_remove_host(lport->host);
1398
1399 /*
1400 * Note that only the physical lport will have the exchange manager.
1401 * for vports, this function is NOP
1402 */
1403 fc_exch_mgr_free(lport);
1404
1405 /* Free memory used by statistical counters */
1406 fc_lport_free_stats(lport);
1407
Bhanu Prakash Gollapudid36b3272011-05-27 11:47:27 -07001408 spin_lock_bh(&hba->hba_lock);
1409 list_for_each_entry_safe(blport, tmp, &hba->vports, list) {
1410 if (blport->lport == lport) {
1411 list_del(&blport->list);
1412 kfree(blport);
1413 }
1414 }
1415 spin_unlock_bh(&hba->hba_lock);
1416
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001417 /* Release Scsi_Host */
1418 scsi_host_put(lport->host);
1419}
1420
1421/**
1422 * bnx2fc_destroy - Destroy a bnx2fc FCoE interface
1423 *
1424 * @buffer: The name of the Ethernet interface to be destroyed
1425 * @kp: The associated kernel parameter
1426 *
1427 * Called from sysfs.
1428 *
1429 * Returns: 0 for success
1430 */
1431static int bnx2fc_destroy(struct net_device *netdev)
1432{
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001433 struct bnx2fc_interface *interface = NULL;
1434 struct bnx2fc_hba *hba;
1435 struct fc_lport *lport;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001436 int rc = 0;
1437
Nithin Sujir6702ca12011-03-17 17:13:27 -07001438 rtnl_lock();
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001439 mutex_lock(&bnx2fc_dev_lock);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001440
1441 interface = bnx2fc_interface_lookup(netdev);
1442 if (!interface || !interface->ctlr.lp) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001443 rc = -ENODEV;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001444 printk(KERN_ERR PFX "bnx2fc_destroy: interface or lport not found\n");
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001445 goto netdev_err;
1446 }
1447
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001448 hba = interface->hba;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001449
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001450 bnx2fc_netdev_cleanup(interface);
1451 lport = interface->ctlr.lp;
1452 bnx2fc_stop(interface);
1453 list_del(&interface->list);
1454 destroy_workqueue(interface->timer_work_queue);
1455 bnx2fc_interface_put(interface);
1456 bnx2fc_if_destroy(lport, hba);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001457
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001458netdev_err:
1459 mutex_unlock(&bnx2fc_dev_lock);
1460 rtnl_unlock();
1461 return rc;
1462}
1463
1464static void bnx2fc_destroy_work(struct work_struct *work)
1465{
1466 struct fcoe_port *port;
1467 struct fc_lport *lport;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001468 struct bnx2fc_interface *interface;
1469 struct bnx2fc_hba *hba;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001470
1471 port = container_of(work, struct fcoe_port, destroy_work);
1472 lport = port->lport;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001473 interface = port->priv;
1474 hba = interface->hba;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001475
1476 BNX2FC_HBA_DBG(lport, "Entered bnx2fc_destroy_work\n");
1477
1478 bnx2fc_port_shutdown(lport);
1479 rtnl_lock();
1480 mutex_lock(&bnx2fc_dev_lock);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001481 bnx2fc_if_destroy(lport, hba);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001482 mutex_unlock(&bnx2fc_dev_lock);
1483 rtnl_unlock();
1484}
1485
1486static void bnx2fc_unbind_adapter_devices(struct bnx2fc_hba *hba)
1487{
1488 bnx2fc_free_fw_resc(hba);
1489 bnx2fc_free_task_ctx(hba);
1490}
1491
1492/**
1493 * bnx2fc_bind_adapter_devices - binds bnx2fc adapter with the associated
1494 * pci structure
1495 *
1496 * @hba: Adapter instance
1497 */
1498static int bnx2fc_bind_adapter_devices(struct bnx2fc_hba *hba)
1499{
1500 if (bnx2fc_setup_task_ctx(hba))
1501 goto mem_err;
1502
1503 if (bnx2fc_setup_fw_resc(hba))
1504 goto mem_err;
1505
1506 return 0;
1507mem_err:
1508 bnx2fc_unbind_adapter_devices(hba);
1509 return -ENOMEM;
1510}
1511
1512static int bnx2fc_bind_pcidev(struct bnx2fc_hba *hba)
1513{
1514 struct cnic_dev *cnic;
1515
1516 if (!hba->cnic) {
1517 printk(KERN_ERR PFX "cnic is NULL\n");
1518 return -ENODEV;
1519 }
1520 cnic = hba->cnic;
1521 hba->pcidev = cnic->pcidev;
1522 if (hba->pcidev)
1523 pci_dev_get(hba->pcidev);
1524
1525 return 0;
1526}
1527
1528static void bnx2fc_unbind_pcidev(struct bnx2fc_hba *hba)
1529{
1530 if (hba->pcidev)
1531 pci_dev_put(hba->pcidev);
1532 hba->pcidev = NULL;
1533}
1534
1535
1536
1537/**
1538 * bnx2fc_ulp_start - cnic callback to initialize & start adapter instance
1539 *
1540 * @handle: transport handle pointing to adapter struture
1541 *
1542 * This function maps adapter structure to pcidev structure and initiates
1543 * firmware handshake to enable/initialize on-chip FCoE components.
1544 * This bnx2fc - cnic interface api callback is used after following
1545 * conditions are met -
1546 * a) underlying network interface is up (marked by event NETDEV_UP
1547 * from netdev
1548 * b) bnx2fc adatper structure is registered.
1549 */
1550static void bnx2fc_ulp_start(void *handle)
1551{
1552 struct bnx2fc_hba *hba = handle;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001553 struct bnx2fc_interface *interface;
1554 struct fc_lport *lport;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001555
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001556 mutex_lock(&bnx2fc_dev_lock);
1557
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001558 if (!test_bit(BNX2FC_FLAG_FW_INIT_DONE, &hba->flags))
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001559 bnx2fc_fw_init(hba);
1560
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001561 BNX2FC_MISC_DBG("bnx2fc started.\n");
1562
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001563 list_for_each_entry(interface, &if_list, list) {
1564 if (interface->hba == hba) {
1565 lport = interface->ctlr.lp;
1566 /* Kick off Fabric discovery*/
1567 printk(KERN_ERR PFX "ulp_init: start discovery\n");
1568 lport->tt.frame_send = bnx2fc_xmit;
1569 bnx2fc_start_disc(interface);
1570 }
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001571 }
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001572
1573 mutex_unlock(&bnx2fc_dev_lock);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001574}
1575
1576static void bnx2fc_port_shutdown(struct fc_lport *lport)
1577{
1578 BNX2FC_MISC_DBG("Entered %s\n", __func__);
1579 fc_fabric_logoff(lport);
1580 fc_lport_destroy(lport);
1581}
1582
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001583static void bnx2fc_stop(struct bnx2fc_interface *interface)
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001584{
1585 struct fc_lport *lport;
1586 struct fc_lport *vport;
1587
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001588 if (!test_bit(BNX2FC_FLAG_FW_INIT_DONE, &interface->hba->flags))
1589 return;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001590
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001591 lport = interface->ctlr.lp;
1592 bnx2fc_port_shutdown(lport);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001593
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001594 mutex_lock(&lport->lp_mutex);
1595 list_for_each_entry(vport, &lport->vports, list)
1596 fc_host_port_type(vport->host) =
1597 FC_PORTTYPE_UNKNOWN;
1598 mutex_unlock(&lport->lp_mutex);
1599 fc_host_port_type(lport->host) = FC_PORTTYPE_UNKNOWN;
1600 fcoe_ctlr_link_down(&interface->ctlr);
1601 fcoe_clean_pending_queue(lport);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001602}
1603
1604static int bnx2fc_fw_init(struct bnx2fc_hba *hba)
1605{
1606#define BNX2FC_INIT_POLL_TIME (1000 / HZ)
1607 int rc = -1;
1608 int i = HZ;
1609
1610 rc = bnx2fc_bind_adapter_devices(hba);
1611 if (rc) {
1612 printk(KERN_ALERT PFX
1613 "bnx2fc_bind_adapter_devices failed - rc = %d\n", rc);
1614 goto err_out;
1615 }
1616
1617 rc = bnx2fc_send_fw_fcoe_init_msg(hba);
1618 if (rc) {
1619 printk(KERN_ALERT PFX
1620 "bnx2fc_send_fw_fcoe_init_msg failed - rc = %d\n", rc);
1621 goto err_unbind;
1622 }
1623
1624 /*
1625 * Wait until the adapter init message is complete, and adapter
1626 * state is UP.
1627 */
1628 while (!test_bit(ADAPTER_STATE_UP, &hba->adapter_state) && i--)
1629 msleep(BNX2FC_INIT_POLL_TIME);
1630
1631 if (!test_bit(ADAPTER_STATE_UP, &hba->adapter_state)) {
1632 printk(KERN_ERR PFX "bnx2fc_start: %s failed to initialize. "
1633 "Ignoring...\n",
1634 hba->cnic->netdev->name);
1635 rc = -1;
1636 goto err_unbind;
1637 }
1638
1639
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001640 set_bit(BNX2FC_FLAG_FW_INIT_DONE, &hba->flags);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001641 return 0;
1642
1643err_unbind:
1644 bnx2fc_unbind_adapter_devices(hba);
1645err_out:
1646 return rc;
1647}
1648
1649static void bnx2fc_fw_destroy(struct bnx2fc_hba *hba)
1650{
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001651 if (test_and_clear_bit(BNX2FC_FLAG_FW_INIT_DONE, &hba->flags)) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001652 if (bnx2fc_send_fw_fcoe_destroy_msg(hba) == 0) {
1653 init_timer(&hba->destroy_timer);
1654 hba->destroy_timer.expires = BNX2FC_FW_TIMEOUT +
1655 jiffies;
1656 hba->destroy_timer.function = bnx2fc_destroy_timer;
1657 hba->destroy_timer.data = (unsigned long)hba;
1658 add_timer(&hba->destroy_timer);
1659 wait_event_interruptible(hba->destroy_wait,
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001660 test_bit(BNX2FC_FLAG_DESTROY_CMPL,
1661 &hba->flags));
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001662 /* This should never happen */
1663 if (signal_pending(current))
1664 flush_signals(current);
1665
1666 del_timer_sync(&hba->destroy_timer);
1667 }
1668 bnx2fc_unbind_adapter_devices(hba);
1669 }
1670}
1671
1672/**
1673 * bnx2fc_ulp_stop - cnic callback to shutdown adapter instance
1674 *
1675 * @handle: transport handle pointing to adapter structure
1676 *
1677 * Driver checks if adapter is already in shutdown mode, if not start
1678 * the shutdown process.
1679 */
1680static void bnx2fc_ulp_stop(void *handle)
1681{
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001682 struct bnx2fc_hba *hba = handle;
1683 struct bnx2fc_interface *interface;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001684
1685 printk(KERN_ERR "ULP_STOP\n");
1686
1687 mutex_lock(&bnx2fc_dev_lock);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001688 if (!test_bit(BNX2FC_FLAG_FW_INIT_DONE, &hba->flags))
1689 goto exit;
1690 list_for_each_entry(interface, &if_list, list) {
1691 if (interface->hba == hba)
1692 bnx2fc_stop(interface);
1693 }
1694 BUG_ON(hba->num_ofld_sess != 0);
1695
1696 mutex_lock(&hba->hba_mutex);
1697 clear_bit(ADAPTER_STATE_UP, &hba->adapter_state);
1698 clear_bit(ADAPTER_STATE_GOING_DOWN,
1699 &hba->adapter_state);
1700
1701 clear_bit(ADAPTER_STATE_READY, &hba->adapter_state);
1702 mutex_unlock(&hba->hba_mutex);
1703
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001704 bnx2fc_fw_destroy(hba);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001705exit:
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001706 mutex_unlock(&bnx2fc_dev_lock);
1707}
1708
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001709static void bnx2fc_start_disc(struct bnx2fc_interface *interface)
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001710{
1711 struct fc_lport *lport;
1712 int wait_cnt = 0;
1713
1714 BNX2FC_MISC_DBG("Entered %s\n", __func__);
1715 /* Kick off FIP/FLOGI */
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001716 if (!test_bit(BNX2FC_FLAG_FW_INIT_DONE, &interface->hba->flags)) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001717 printk(KERN_ERR PFX "Init not done yet\n");
1718 return;
1719 }
1720
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001721 lport = interface->ctlr.lp;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001722 BNX2FC_HBA_DBG(lport, "calling fc_fabric_login\n");
1723
1724 if (!bnx2fc_link_ok(lport)) {
1725 BNX2FC_HBA_DBG(lport, "ctlr_link_up\n");
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001726 fcoe_ctlr_link_up(&interface->ctlr);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001727 fc_host_port_type(lport->host) = FC_PORTTYPE_NPORT;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001728 set_bit(ADAPTER_STATE_READY, &interface->hba->adapter_state);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001729 }
1730
1731 /* wait for the FCF to be selected before issuing FLOGI */
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001732 while (!interface->ctlr.sel_fcf) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001733 msleep(250);
1734 /* give up after 3 secs */
1735 if (++wait_cnt > 12)
1736 break;
1737 }
Bhanu Prakash Gollapudi627e6282011-08-04 17:38:35 -07001738
1739 /* Reset max receive frame size to default */
1740 if (fc_set_mfs(lport, BNX2FC_MFS))
1741 return;
1742
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001743 fc_lport_init(lport);
1744 fc_fabric_login(lport);
1745}
1746
1747
1748/**
1749 * bnx2fc_ulp_init - Initialize an adapter instance
1750 *
1751 * @dev : cnic device handle
1752 * Called from cnic_register_driver() context to initialize all
1753 * enumerated cnic devices. This routine allocates adapter structure
1754 * and other device specific resources.
1755 */
1756static void bnx2fc_ulp_init(struct cnic_dev *dev)
1757{
1758 struct bnx2fc_hba *hba;
1759 int rc = 0;
1760
1761 BNX2FC_MISC_DBG("Entered %s\n", __func__);
1762 /* bnx2fc works only when bnx2x is loaded */
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001763 if (!test_bit(CNIC_F_BNX2X_CLASS, &dev->flags) ||
1764 (dev->max_fcoe_conn == 0)) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001765 printk(KERN_ERR PFX "bnx2fc FCoE not supported on %s,"
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001766 " flags: %lx fcoe_conn: %d\n",
1767 dev->netdev->name, dev->flags, dev->max_fcoe_conn);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001768 return;
1769 }
1770
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001771 hba = bnx2fc_hba_create(dev);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001772 if (!hba) {
1773 printk(KERN_ERR PFX "hba initialization failed\n");
1774 return;
1775 }
1776
1777 /* Add HBA to the adapter list */
1778 mutex_lock(&bnx2fc_dev_lock);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001779 list_add_tail(&hba->list, &adapter_list);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001780 adapter_count++;
1781 mutex_unlock(&bnx2fc_dev_lock);
1782
1783 clear_bit(BNX2FC_CNIC_REGISTERED, &hba->reg_with_cnic);
1784 rc = dev->register_device(dev, CNIC_ULP_FCOE,
1785 (void *) hba);
1786 if (rc)
Bhanu Prakash Gollapudib2a554f2011-06-27 23:30:53 -07001787 printk(KERN_ERR PFX "register_device failed, rc = %d\n", rc);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001788 else
1789 set_bit(BNX2FC_CNIC_REGISTERED, &hba->reg_with_cnic);
1790}
1791
1792
1793static int bnx2fc_disable(struct net_device *netdev)
1794{
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001795 struct bnx2fc_interface *interface;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001796 int rc = 0;
1797
Nithin Sujir6702ca12011-03-17 17:13:27 -07001798 rtnl_lock();
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001799 mutex_lock(&bnx2fc_dev_lock);
1800
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001801 interface = bnx2fc_interface_lookup(netdev);
1802 if (!interface || !interface->ctlr.lp) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001803 rc = -ENODEV;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001804 printk(KERN_ERR PFX "bnx2fc_disable: interface or lport not found\n");
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001805 } else {
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001806 fcoe_ctlr_link_down(&interface->ctlr);
1807 fcoe_clean_pending_queue(interface->ctlr.lp);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001808 }
1809
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001810 mutex_unlock(&bnx2fc_dev_lock);
1811 rtnl_unlock();
1812 return rc;
1813}
1814
1815
1816static int bnx2fc_enable(struct net_device *netdev)
1817{
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001818 struct bnx2fc_interface *interface;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001819 int rc = 0;
1820
Nithin Sujir6702ca12011-03-17 17:13:27 -07001821 rtnl_lock();
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001822 mutex_lock(&bnx2fc_dev_lock);
1823
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001824 interface = bnx2fc_interface_lookup(netdev);
1825 if (!interface || !interface->ctlr.lp) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001826 rc = -ENODEV;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001827 printk(KERN_ERR PFX "bnx2fc_enable: interface or lport not found\n");
1828 } else if (!bnx2fc_link_ok(interface->ctlr.lp))
1829 fcoe_ctlr_link_up(&interface->ctlr);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001830
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001831 mutex_unlock(&bnx2fc_dev_lock);
1832 rtnl_unlock();
1833 return rc;
1834}
1835
1836/**
1837 * bnx2fc_create - Create bnx2fc FCoE interface
1838 *
1839 * @buffer: The name of Ethernet interface to create on
1840 * @kp: The associated kernel param
1841 *
1842 * Called from sysfs.
1843 *
1844 * Returns: 0 for success
1845 */
1846static int bnx2fc_create(struct net_device *netdev, enum fip_state fip_mode)
1847{
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001848 struct bnx2fc_interface *interface;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001849 struct bnx2fc_hba *hba;
1850 struct net_device *phys_dev;
1851 struct fc_lport *lport;
1852 struct ethtool_drvinfo drvinfo;
1853 int rc = 0;
1854 int vlan_id;
1855
1856 BNX2FC_MISC_DBG("Entered bnx2fc_create\n");
1857 if (fip_mode != FIP_MODE_FABRIC) {
1858 printk(KERN_ERR "fip mode not FABRIC\n");
1859 return -EIO;
1860 }
1861
Nithin Sujir6702ca12011-03-17 17:13:27 -07001862 rtnl_lock();
1863
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001864 mutex_lock(&bnx2fc_dev_lock);
1865
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001866 if (!try_module_get(THIS_MODULE)) {
1867 rc = -EINVAL;
1868 goto mod_err;
1869 }
1870
1871 /* obtain physical netdev */
1872 if (netdev->priv_flags & IFF_802_1Q_VLAN) {
1873 phys_dev = vlan_dev_real_dev(netdev);
1874 vlan_id = vlan_dev_vlan_id(netdev);
1875 } else {
1876 printk(KERN_ERR PFX "Not a vlan device\n");
1877 rc = -EINVAL;
1878 goto netdev_err;
1879 }
1880 /* verify if the physical device is a netxtreme2 device */
1881 if (phys_dev->ethtool_ops && phys_dev->ethtool_ops->get_drvinfo) {
1882 memset(&drvinfo, 0, sizeof(drvinfo));
1883 phys_dev->ethtool_ops->get_drvinfo(phys_dev, &drvinfo);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001884 if (strncmp(drvinfo.driver, "bnx2x", strlen("bnx2x"))) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001885 printk(KERN_ERR PFX "Not a netxtreme2 device\n");
1886 rc = -EINVAL;
1887 goto netdev_err;
1888 }
1889 } else {
1890 printk(KERN_ERR PFX "unable to obtain drv_info\n");
1891 rc = -EINVAL;
1892 goto netdev_err;
1893 }
1894
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001895 /* obtain interface and initialize rest of the structure */
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001896 hba = bnx2fc_hba_lookup(phys_dev);
1897 if (!hba) {
1898 rc = -ENODEV;
1899 printk(KERN_ERR PFX "bnx2fc_create: hba not found\n");
1900 goto netdev_err;
1901 }
1902
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001903 if (bnx2fc_interface_lookup(netdev)) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001904 rc = -EEXIST;
1905 goto netdev_err;
1906 }
1907
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001908 interface = bnx2fc_interface_create(hba, netdev, fip_mode);
1909 if (!interface) {
1910 printk(KERN_ERR PFX "bnx2fc_interface_create failed\n");
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001911 goto ifput_err;
1912 }
1913
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001914 interface->vlan_id = vlan_id;
1915 interface->vlan_enabled = 1;
1916
1917 interface->timer_work_queue =
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001918 create_singlethread_workqueue("bnx2fc_timer_wq");
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001919 if (!interface->timer_work_queue) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001920 printk(KERN_ERR PFX "ulp_init could not create timer_wq\n");
1921 rc = -EINVAL;
1922 goto ifput_err;
1923 }
1924
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001925 lport = bnx2fc_if_create(interface, &interface->hba->pcidev->dev, 0);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001926 if (!lport) {
1927 printk(KERN_ERR PFX "Failed to create interface (%s)\n",
1928 netdev->name);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001929 bnx2fc_netdev_cleanup(interface);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001930 rc = -EINVAL;
1931 goto if_create_err;
1932 }
1933
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001934 /* Add interface to if_list */
1935 list_add_tail(&interface->list, &if_list);
1936
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001937 lport->boot_time = jiffies;
1938
1939 /* Make this master N_port */
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001940 interface->ctlr.lp = lport;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001941
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001942 BNX2FC_HBA_DBG(lport, "create: START DISC\n");
1943 bnx2fc_start_disc(interface);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001944 /*
1945 * Release from kref_init in bnx2fc_interface_setup, on success
1946 * lport should be holding a reference taken in bnx2fc_if_create
1947 */
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001948 bnx2fc_interface_put(interface);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001949 /* put netdev that was held while calling dev_get_by_name */
1950 mutex_unlock(&bnx2fc_dev_lock);
1951 rtnl_unlock();
1952 return 0;
1953
1954if_create_err:
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001955 destroy_workqueue(interface->timer_work_queue);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001956ifput_err:
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001957 bnx2fc_interface_put(interface);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001958netdev_err:
1959 module_put(THIS_MODULE);
1960mod_err:
1961 mutex_unlock(&bnx2fc_dev_lock);
1962 rtnl_unlock();
1963 return rc;
1964}
1965
1966/**
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001967 * bnx2fc_find_hba_for_cnic - maps cnic instance to bnx2fc hba instance
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001968 *
1969 * @cnic: Pointer to cnic device instance
1970 *
1971 **/
1972static struct bnx2fc_hba *bnx2fc_find_hba_for_cnic(struct cnic_dev *cnic)
1973{
1974 struct list_head *list;
1975 struct list_head *temp;
1976 struct bnx2fc_hba *hba;
1977
1978 /* Called with bnx2fc_dev_lock held */
1979 list_for_each_safe(list, temp, &adapter_list) {
1980 hba = (struct bnx2fc_hba *)list;
1981 if (hba->cnic == cnic)
1982 return hba;
1983 }
1984 return NULL;
1985}
1986
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001987static struct bnx2fc_interface *bnx2fc_interface_lookup(struct net_device
1988 *netdev)
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001989{
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001990 struct bnx2fc_interface *interface;
1991
1992 /* Called with bnx2fc_dev_lock held */
1993 list_for_each_entry(interface, &if_list, list) {
1994 if (interface->netdev == netdev)
1995 return interface;
1996 }
1997 return NULL;
1998}
1999
2000static struct bnx2fc_hba *bnx2fc_hba_lookup(struct net_device
2001 *phys_dev)
2002{
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002003 struct bnx2fc_hba *hba;
2004
2005 /* Called with bnx2fc_dev_lock held */
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002006 list_for_each_entry(hba, &adapter_list, list) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002007 if (hba->phys_dev == phys_dev)
2008 return hba;
2009 }
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002010 printk(KERN_ERR PFX "adapter_lookup: hba NULL\n");
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002011 return NULL;
2012}
2013
2014/**
2015 * bnx2fc_ulp_exit - shuts down adapter instance and frees all resources
2016 *
2017 * @dev cnic device handle
2018 */
2019static void bnx2fc_ulp_exit(struct cnic_dev *dev)
2020{
2021 struct bnx2fc_hba *hba;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002022 struct bnx2fc_interface *interface, *tmp;
2023 struct fc_lport *lport;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002024
2025 BNX2FC_MISC_DBG("Entered bnx2fc_ulp_exit\n");
2026
2027 if (!test_bit(CNIC_F_BNX2X_CLASS, &dev->flags)) {
2028 printk(KERN_ERR PFX "bnx2fc port check: %s, flags: %lx\n",
2029 dev->netdev->name, dev->flags);
2030 return;
2031 }
2032
2033 mutex_lock(&bnx2fc_dev_lock);
2034 hba = bnx2fc_find_hba_for_cnic(dev);
2035 if (!hba) {
2036 printk(KERN_ERR PFX "bnx2fc_ulp_exit: hba not found, dev 0%p\n",
2037 dev);
2038 mutex_unlock(&bnx2fc_dev_lock);
2039 return;
2040 }
2041
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002042 list_del_init(&hba->list);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002043 adapter_count--;
2044
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002045 list_for_each_entry_safe(interface, tmp, &if_list, list) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002046 /* destroy not called yet, move to quiesced list */
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002047 if (interface->hba == hba) {
2048 bnx2fc_netdev_cleanup(interface);
2049 bnx2fc_stop(interface);
2050
2051 list_del(&interface->list);
2052 lport = interface->ctlr.lp;
2053 bnx2fc_interface_put(interface);
2054 bnx2fc_if_destroy(lport, hba);
2055 }
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002056 }
2057 mutex_unlock(&bnx2fc_dev_lock);
2058
2059 bnx2fc_ulp_stop(hba);
2060 /* unregister cnic device */
2061 if (test_and_clear_bit(BNX2FC_CNIC_REGISTERED, &hba->reg_with_cnic))
2062 hba->cnic->unregister_device(hba->cnic, CNIC_ULP_FCOE);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002063 bnx2fc_hba_destroy(hba);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002064}
2065
2066/**
2067 * bnx2fc_fcoe_reset - Resets the fcoe
2068 *
2069 * @shost: shost the reset is from
2070 *
2071 * Returns: always 0
2072 */
2073static int bnx2fc_fcoe_reset(struct Scsi_Host *shost)
2074{
2075 struct fc_lport *lport = shost_priv(shost);
2076 fc_lport_reset(lport);
2077 return 0;
2078}
2079
2080
2081static bool bnx2fc_match(struct net_device *netdev)
2082{
2083 mutex_lock(&bnx2fc_dev_lock);
2084 if (netdev->priv_flags & IFF_802_1Q_VLAN) {
2085 struct net_device *phys_dev = vlan_dev_real_dev(netdev);
2086
2087 if (bnx2fc_hba_lookup(phys_dev)) {
2088 mutex_unlock(&bnx2fc_dev_lock);
2089 return true;
2090 }
2091 }
2092 mutex_unlock(&bnx2fc_dev_lock);
2093 return false;
2094}
2095
2096
2097static struct fcoe_transport bnx2fc_transport = {
2098 .name = {"bnx2fc"},
2099 .attached = false,
2100 .list = LIST_HEAD_INIT(bnx2fc_transport.list),
2101 .match = bnx2fc_match,
2102 .create = bnx2fc_create,
2103 .destroy = bnx2fc_destroy,
2104 .enable = bnx2fc_enable,
2105 .disable = bnx2fc_disable,
2106};
2107
2108/**
2109 * bnx2fc_percpu_thread_create - Create a receive thread for an
2110 * online CPU
2111 *
2112 * @cpu: cpu index for the online cpu
2113 */
2114static void bnx2fc_percpu_thread_create(unsigned int cpu)
2115{
2116 struct bnx2fc_percpu_s *p;
2117 struct task_struct *thread;
2118
2119 p = &per_cpu(bnx2fc_percpu, cpu);
2120
2121 thread = kthread_create(bnx2fc_percpu_io_thread,
2122 (void *)p,
2123 "bnx2fc_thread/%d", cpu);
2124 /* bind thread to the cpu */
Bhanu Prakash Gollapudi32248762011-08-04 17:38:36 -07002125 if (likely(!IS_ERR(thread))) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002126 kthread_bind(thread, cpu);
2127 p->iothread = thread;
2128 wake_up_process(thread);
2129 }
2130}
2131
2132static void bnx2fc_percpu_thread_destroy(unsigned int cpu)
2133{
2134 struct bnx2fc_percpu_s *p;
2135 struct task_struct *thread;
2136 struct bnx2fc_work *work, *tmp;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002137
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 */
Bhanu Prakash Gollapudi32248762011-08-04 17:38:36 -07002148 list_for_each_entry_safe(work, tmp, &p->work_list, list) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002149 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};