blob: 62c0e94a916f8a8b036678d8a0f8e737b62e62d8 [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);
Bhanu Prakash Gollapudiabc49a92011-08-04 17:38:42 -070059static void __bnx2fc_destroy(struct bnx2fc_interface *interface, bool schedule);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -080060static int bnx2fc_destroy(struct net_device *net_device);
61static int bnx2fc_enable(struct net_device *netdev);
62static int bnx2fc_disable(struct net_device *netdev);
63
64static void bnx2fc_recv_frame(struct sk_buff *skb);
65
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -070066static void bnx2fc_start_disc(struct bnx2fc_interface *interface);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -080067static int bnx2fc_shost_config(struct fc_lport *lport, struct device *dev);
68static int bnx2fc_net_config(struct fc_lport *lp);
69static int bnx2fc_lport_config(struct fc_lport *lport);
70static int bnx2fc_em_config(struct fc_lport *lport);
71static int bnx2fc_bind_adapter_devices(struct bnx2fc_hba *hba);
72static void bnx2fc_unbind_adapter_devices(struct bnx2fc_hba *hba);
73static int bnx2fc_bind_pcidev(struct bnx2fc_hba *hba);
74static void bnx2fc_unbind_pcidev(struct bnx2fc_hba *hba);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -070075static struct fc_lport *bnx2fc_if_create(struct bnx2fc_interface *interface,
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -080076 struct device *parent, int npiv);
77static void bnx2fc_destroy_work(struct work_struct *work);
78
79static struct bnx2fc_hba *bnx2fc_hba_lookup(struct net_device *phys_dev);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -070080static struct bnx2fc_interface *bnx2fc_interface_lookup(struct net_device
81 *phys_dev);
Bhanu Prakash Gollapudiabc49a92011-08-04 17:38:42 -070082static inline void bnx2fc_interface_put(struct bnx2fc_interface *interface);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -080083static struct bnx2fc_hba *bnx2fc_find_hba_for_cnic(struct cnic_dev *cnic);
84
85static int bnx2fc_fw_init(struct bnx2fc_hba *hba);
86static void bnx2fc_fw_destroy(struct bnx2fc_hba *hba);
87
88static void bnx2fc_port_shutdown(struct fc_lport *lport);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -070089static void bnx2fc_stop(struct bnx2fc_interface *interface);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -080090static int __init bnx2fc_mod_init(void);
91static void __exit bnx2fc_mod_exit(void);
92
93unsigned int bnx2fc_debug_level;
94module_param_named(debug_logging, bnx2fc_debug_level, int, S_IRUGO|S_IWUSR);
95
96static int bnx2fc_cpu_callback(struct notifier_block *nfb,
97 unsigned long action, void *hcpu);
98/* notification function for CPU hotplug events */
99static struct notifier_block bnx2fc_cpu_notifier = {
100 .notifier_call = bnx2fc_cpu_callback,
101};
102
103static void bnx2fc_clean_rx_queue(struct fc_lport *lp)
104{
105 struct fcoe_percpu_s *bg;
106 struct fcoe_rcv_info *fr;
107 struct sk_buff_head *list;
108 struct sk_buff *skb, *next;
109 struct sk_buff *head;
110
111 bg = &bnx2fc_global;
112 spin_lock_bh(&bg->fcoe_rx_list.lock);
113 list = &bg->fcoe_rx_list;
114 head = list->next;
115 for (skb = head; skb != (struct sk_buff *)list;
116 skb = next) {
117 next = skb->next;
118 fr = fcoe_dev_from_skb(skb);
119 if (fr->fr_dev == lp) {
120 __skb_unlink(skb, list);
121 kfree_skb(skb);
122 }
123 }
124 spin_unlock_bh(&bg->fcoe_rx_list.lock);
125}
126
127int bnx2fc_get_paged_crc_eof(struct sk_buff *skb, int tlen)
128{
129 int rc;
130 spin_lock(&bnx2fc_global_lock);
131 rc = fcoe_get_paged_crc_eof(skb, tlen, &bnx2fc_global);
132 spin_unlock(&bnx2fc_global_lock);
133
134 return rc;
135}
136
137static void bnx2fc_abort_io(struct fc_lport *lport)
138{
139 /*
140 * This function is no-op for bnx2fc, but we do
141 * not want to leave it as NULL either, as libfc
142 * can call the default function which is
143 * fc_fcp_abort_io.
144 */
145}
146
147static void bnx2fc_cleanup(struct fc_lport *lport)
148{
149 struct fcoe_port *port = lport_priv(lport);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700150 struct bnx2fc_interface *interface = port->priv;
151 struct bnx2fc_hba *hba = interface->hba;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800152 struct bnx2fc_rport *tgt;
153 int i;
154
155 BNX2FC_MISC_DBG("Entered %s\n", __func__);
156 mutex_lock(&hba->hba_mutex);
157 spin_lock_bh(&hba->hba_lock);
158 for (i = 0; i < BNX2FC_NUM_MAX_SESS; i++) {
159 tgt = hba->tgt_ofld_list[i];
160 if (tgt) {
161 /* Cleanup IOs belonging to requested vport */
162 if (tgt->port == port) {
163 spin_unlock_bh(&hba->hba_lock);
164 BNX2FC_TGT_DBG(tgt, "flush/cleanup\n");
165 bnx2fc_flush_active_ios(tgt);
166 spin_lock_bh(&hba->hba_lock);
167 }
168 }
169 }
170 spin_unlock_bh(&hba->hba_lock);
171 mutex_unlock(&hba->hba_mutex);
172}
173
174static int bnx2fc_xmit_l2_frame(struct bnx2fc_rport *tgt,
175 struct fc_frame *fp)
176{
177 struct fc_rport_priv *rdata = tgt->rdata;
178 struct fc_frame_header *fh;
179 int rc = 0;
180
181 fh = fc_frame_header_get(fp);
182 BNX2FC_TGT_DBG(tgt, "Xmit L2 frame rport = 0x%x, oxid = 0x%x, "
183 "r_ctl = 0x%x\n", rdata->ids.port_id,
184 ntohs(fh->fh_ox_id), fh->fh_r_ctl);
185 if ((fh->fh_type == FC_TYPE_ELS) &&
186 (fh->fh_r_ctl == FC_RCTL_ELS_REQ)) {
187
188 switch (fc_frame_payload_op(fp)) {
189 case ELS_ADISC:
190 rc = bnx2fc_send_adisc(tgt, fp);
191 break;
192 case ELS_LOGO:
193 rc = bnx2fc_send_logo(tgt, fp);
194 break;
195 case ELS_RLS:
196 rc = bnx2fc_send_rls(tgt, fp);
197 break;
198 default:
199 break;
200 }
201 } else if ((fh->fh_type == FC_TYPE_BLS) &&
202 (fh->fh_r_ctl == FC_RCTL_BA_ABTS))
203 BNX2FC_TGT_DBG(tgt, "ABTS frame\n");
204 else {
205 BNX2FC_TGT_DBG(tgt, "Send L2 frame type 0x%x "
206 "rctl 0x%x thru non-offload path\n",
207 fh->fh_type, fh->fh_r_ctl);
208 return -ENODEV;
209 }
210 if (rc)
211 return -ENOMEM;
212 else
213 return 0;
214}
215
216/**
217 * bnx2fc_xmit - bnx2fc's FCoE frame transmit function
218 *
219 * @lport: the associated local port
220 * @fp: the fc_frame to be transmitted
221 */
222static int bnx2fc_xmit(struct fc_lport *lport, struct fc_frame *fp)
223{
224 struct ethhdr *eh;
225 struct fcoe_crc_eof *cp;
226 struct sk_buff *skb;
227 struct fc_frame_header *fh;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700228 struct bnx2fc_interface *interface;
229 struct bnx2fc_hba *hba;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800230 struct fcoe_port *port;
231 struct fcoe_hdr *hp;
232 struct bnx2fc_rport *tgt;
233 struct fcoe_dev_stats *stats;
234 u8 sof, eof;
235 u32 crc;
236 unsigned int hlen, tlen, elen;
237 int wlen, rc = 0;
238
239 port = (struct fcoe_port *)lport_priv(lport);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700240 interface = port->priv;
241 hba = interface->hba;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800242
243 fh = fc_frame_header_get(fp);
244
245 skb = fp_skb(fp);
246 if (!lport->link_up) {
247 BNX2FC_HBA_DBG(lport, "bnx2fc_xmit link down\n");
248 kfree_skb(skb);
249 return 0;
250 }
251
252 if (unlikely(fh->fh_r_ctl == FC_RCTL_ELS_REQ)) {
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700253 if (!interface->ctlr.sel_fcf) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800254 BNX2FC_HBA_DBG(lport, "FCF not selected yet!\n");
255 kfree_skb(skb);
256 return -EINVAL;
257 }
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700258 if (fcoe_ctlr_els_send(&interface->ctlr, lport, skb))
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800259 return 0;
260 }
261
262 sof = fr_sof(fp);
263 eof = fr_eof(fp);
264
265 /*
266 * Snoop the frame header to check if the frame is for
267 * an offloaded session
268 */
269 /*
270 * tgt_ofld_list access is synchronized using
271 * both hba mutex and hba lock. Atleast hba mutex or
272 * hba lock needs to be held for read access.
273 */
274
275 spin_lock_bh(&hba->hba_lock);
276 tgt = bnx2fc_tgt_lookup(port, ntoh24(fh->fh_d_id));
277 if (tgt && (test_bit(BNX2FC_FLAG_SESSION_READY, &tgt->flags))) {
278 /* This frame is for offloaded session */
279 BNX2FC_HBA_DBG(lport, "xmit: Frame is for offloaded session "
280 "port_id = 0x%x\n", ntoh24(fh->fh_d_id));
281 spin_unlock_bh(&hba->hba_lock);
282 rc = bnx2fc_xmit_l2_frame(tgt, fp);
283 if (rc != -ENODEV) {
284 kfree_skb(skb);
285 return rc;
286 }
287 } else {
288 spin_unlock_bh(&hba->hba_lock);
289 }
290
291 elen = sizeof(struct ethhdr);
292 hlen = sizeof(struct fcoe_hdr);
293 tlen = sizeof(struct fcoe_crc_eof);
294 wlen = (skb->len - tlen + sizeof(crc)) / FCOE_WORD_TO_BYTE;
295
296 skb->ip_summed = CHECKSUM_NONE;
297 crc = fcoe_fc_crc(fp);
298
299 /* copy port crc and eof to the skb buff */
300 if (skb_is_nonlinear(skb)) {
301 skb_frag_t *frag;
302 if (bnx2fc_get_paged_crc_eof(skb, tlen)) {
303 kfree_skb(skb);
304 return -ENOMEM;
305 }
306 frag = &skb_shinfo(skb)->frags[skb_shinfo(skb)->nr_frags - 1];
307 cp = kmap_atomic(frag->page, KM_SKB_DATA_SOFTIRQ)
308 + frag->page_offset;
309 } else {
310 cp = (struct fcoe_crc_eof *)skb_put(skb, tlen);
311 }
312
313 memset(cp, 0, sizeof(*cp));
314 cp->fcoe_eof = eof;
315 cp->fcoe_crc32 = cpu_to_le32(~crc);
316 if (skb_is_nonlinear(skb)) {
317 kunmap_atomic(cp, KM_SKB_DATA_SOFTIRQ);
318 cp = NULL;
319 }
320
321 /* adjust skb network/transport offsets to match mac/fcoe/port */
322 skb_push(skb, elen + hlen);
323 skb_reset_mac_header(skb);
324 skb_reset_network_header(skb);
325 skb->mac_len = elen;
326 skb->protocol = htons(ETH_P_FCOE);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700327 skb->dev = interface->netdev;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800328
329 /* fill up mac and fcoe headers */
330 eh = eth_hdr(skb);
331 eh->h_proto = htons(ETH_P_FCOE);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700332 if (interface->ctlr.map_dest)
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800333 fc_fcoe_set_mac(eh->h_dest, fh->fh_d_id);
334 else
335 /* insert GW address */
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700336 memcpy(eh->h_dest, interface->ctlr.dest_addr, ETH_ALEN);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800337
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700338 if (unlikely(interface->ctlr.flogi_oxid != FC_XID_UNKNOWN))
339 memcpy(eh->h_source, interface->ctlr.ctl_src_addr, ETH_ALEN);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800340 else
341 memcpy(eh->h_source, port->data_src_addr, ETH_ALEN);
342
343 hp = (struct fcoe_hdr *)(eh + 1);
344 memset(hp, 0, sizeof(*hp));
345 if (FC_FCOE_VER)
346 FC_FCOE_ENCAPS_VER(hp, FC_FCOE_VER);
347 hp->fcoe_sof = sof;
348
349 /* fcoe lso, mss is in max_payload which is non-zero for FCP data */
350 if (lport->seq_offload && fr_max_payload(fp)) {
351 skb_shinfo(skb)->gso_type = SKB_GSO_FCOE;
352 skb_shinfo(skb)->gso_size = fr_max_payload(fp);
353 } else {
354 skb_shinfo(skb)->gso_type = 0;
355 skb_shinfo(skb)->gso_size = 0;
356 }
357
358 /*update tx stats */
359 stats = per_cpu_ptr(lport->dev_stats, get_cpu());
360 stats->TxFrames++;
361 stats->TxWords += wlen;
362 put_cpu();
363
364 /* send down to lld */
365 fr_dev(fp) = lport;
366 if (port->fcoe_pending_queue.qlen)
367 fcoe_check_wait_queue(lport, skb);
368 else if (fcoe_start_io(skb))
369 fcoe_check_wait_queue(lport, skb);
370
371 return 0;
372}
373
374/**
375 * bnx2fc_rcv - This is bnx2fc's receive function called by NET_RX_SOFTIRQ
376 *
377 * @skb: the receive socket buffer
378 * @dev: associated net device
379 * @ptype: context
380 * @olddev: last device
381 *
382 * This function receives the packet and builds FC frame and passes it up
383 */
384static int bnx2fc_rcv(struct sk_buff *skb, struct net_device *dev,
385 struct packet_type *ptype, struct net_device *olddev)
386{
387 struct fc_lport *lport;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700388 struct bnx2fc_interface *interface;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800389 struct fc_frame_header *fh;
390 struct fcoe_rcv_info *fr;
391 struct fcoe_percpu_s *bg;
392 unsigned short oxid;
393
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700394 interface = container_of(ptype, struct bnx2fc_interface,
395 fcoe_packet_type);
396 lport = interface->ctlr.lp;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800397
398 if (unlikely(lport == NULL)) {
Bhanu Prakash Gollapudib2a554f2011-06-27 23:30:53 -0700399 printk(KERN_ERR PFX "bnx2fc_rcv: lport is NULL\n");
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800400 goto err;
401 }
402
403 if (unlikely(eth_hdr(skb)->h_proto != htons(ETH_P_FCOE))) {
Bhanu Prakash Gollapudib2a554f2011-06-27 23:30:53 -0700404 printk(KERN_ERR PFX "bnx2fc_rcv: Wrong FC type frame\n");
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800405 goto err;
406 }
407
408 /*
409 * Check for minimum frame length, and make sure required FCoE
410 * and FC headers are pulled into the linear data area.
411 */
412 if (unlikely((skb->len < FCOE_MIN_FRAME) ||
413 !pskb_may_pull(skb, FCOE_HEADER_LEN)))
414 goto err;
415
416 skb_set_transport_header(skb, sizeof(struct fcoe_hdr));
417 fh = (struct fc_frame_header *) skb_transport_header(skb);
418
419 oxid = ntohs(fh->fh_ox_id);
420
421 fr = fcoe_dev_from_skb(skb);
422 fr->fr_dev = lport;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800423
424 bg = &bnx2fc_global;
425 spin_lock_bh(&bg->fcoe_rx_list.lock);
426
427 __skb_queue_tail(&bg->fcoe_rx_list, skb);
428 if (bg->fcoe_rx_list.qlen == 1)
429 wake_up_process(bg->thread);
430
431 spin_unlock_bh(&bg->fcoe_rx_list.lock);
432
433 return 0;
434err:
435 kfree_skb(skb);
436 return -1;
437}
438
439static int bnx2fc_l2_rcv_thread(void *arg)
440{
441 struct fcoe_percpu_s *bg = arg;
442 struct sk_buff *skb;
443
444 set_user_nice(current, -20);
445 set_current_state(TASK_INTERRUPTIBLE);
446 while (!kthread_should_stop()) {
447 schedule();
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800448 spin_lock_bh(&bg->fcoe_rx_list.lock);
449 while ((skb = __skb_dequeue(&bg->fcoe_rx_list)) != NULL) {
450 spin_unlock_bh(&bg->fcoe_rx_list.lock);
451 bnx2fc_recv_frame(skb);
452 spin_lock_bh(&bg->fcoe_rx_list.lock);
453 }
Bhanu Gollapudifee78712011-03-21 18:51:13 -0700454 __set_current_state(TASK_INTERRUPTIBLE);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800455 spin_unlock_bh(&bg->fcoe_rx_list.lock);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800456 }
Bhanu Gollapudifee78712011-03-21 18:51:13 -0700457 __set_current_state(TASK_RUNNING);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800458 return 0;
459}
460
461
462static void bnx2fc_recv_frame(struct sk_buff *skb)
463{
464 u32 fr_len;
465 struct fc_lport *lport;
466 struct fcoe_rcv_info *fr;
467 struct fcoe_dev_stats *stats;
468 struct fc_frame_header *fh;
469 struct fcoe_crc_eof crc_eof;
470 struct fc_frame *fp;
471 struct fc_lport *vn_port;
472 struct fcoe_port *port;
473 u8 *mac = NULL;
474 u8 *dest_mac = NULL;
475 struct fcoe_hdr *hp;
476
477 fr = fcoe_dev_from_skb(skb);
478 lport = fr->fr_dev;
479 if (unlikely(lport == NULL)) {
Bhanu Prakash Gollapudib2a554f2011-06-27 23:30:53 -0700480 printk(KERN_ERR PFX "Invalid lport struct\n");
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800481 kfree_skb(skb);
482 return;
483 }
484
485 if (skb_is_nonlinear(skb))
486 skb_linearize(skb);
487 mac = eth_hdr(skb)->h_source;
488 dest_mac = eth_hdr(skb)->h_dest;
489
490 /* Pull the header */
491 hp = (struct fcoe_hdr *) skb_network_header(skb);
492 fh = (struct fc_frame_header *) skb_transport_header(skb);
493 skb_pull(skb, sizeof(struct fcoe_hdr));
494 fr_len = skb->len - sizeof(struct fcoe_crc_eof);
495
496 stats = per_cpu_ptr(lport->dev_stats, get_cpu());
497 stats->RxFrames++;
498 stats->RxWords += fr_len / FCOE_WORD_TO_BYTE;
499
500 fp = (struct fc_frame *)skb;
501 fc_frame_init(fp);
502 fr_dev(fp) = lport;
503 fr_sof(fp) = hp->fcoe_sof;
504 if (skb_copy_bits(skb, fr_len, &crc_eof, sizeof(crc_eof))) {
505 put_cpu();
506 kfree_skb(skb);
507 return;
508 }
509 fr_eof(fp) = crc_eof.fcoe_eof;
510 fr_crc(fp) = crc_eof.fcoe_crc32;
511 if (pskb_trim(skb, fr_len)) {
512 put_cpu();
513 kfree_skb(skb);
514 return;
515 }
516
517 fh = fc_frame_header_get(fp);
518
519 vn_port = fc_vport_id_lookup(lport, ntoh24(fh->fh_d_id));
520 if (vn_port) {
521 port = lport_priv(vn_port);
522 if (compare_ether_addr(port->data_src_addr, dest_mac)
523 != 0) {
524 BNX2FC_HBA_DBG(lport, "fpma mismatch\n");
525 put_cpu();
526 kfree_skb(skb);
527 return;
528 }
529 }
530 if (fh->fh_r_ctl == FC_RCTL_DD_SOL_DATA &&
531 fh->fh_type == FC_TYPE_FCP) {
532 /* Drop FCP data. We dont this in L2 path */
533 put_cpu();
534 kfree_skb(skb);
535 return;
536 }
537 if (fh->fh_r_ctl == FC_RCTL_ELS_REQ &&
538 fh->fh_type == FC_TYPE_ELS) {
539 switch (fc_frame_payload_op(fp)) {
540 case ELS_LOGO:
541 if (ntoh24(fh->fh_s_id) == FC_FID_FLOGI) {
542 /* drop non-FIP LOGO */
543 put_cpu();
544 kfree_skb(skb);
545 return;
546 }
547 break;
548 }
549 }
Bhanu Prakash Gollapudi3f8744d2011-08-04 17:38:48 -0700550
551 if (fh->fh_r_ctl == FC_RCTL_BA_ABTS) {
552 /* Drop incoming ABTS */
553 put_cpu();
554 kfree_skb(skb);
555 return;
556 }
557
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800558 if (le32_to_cpu(fr_crc(fp)) !=
559 ~crc32(~0, skb->data, fr_len)) {
560 if (stats->InvalidCRCCount < 5)
561 printk(KERN_WARNING PFX "dropping frame with "
562 "CRC error\n");
563 stats->InvalidCRCCount++;
564 put_cpu();
565 kfree_skb(skb);
566 return;
567 }
568 put_cpu();
569 fc_exch_recv(lport, fp);
570}
571
572/**
573 * bnx2fc_percpu_io_thread - thread per cpu for ios
574 *
575 * @arg: ptr to bnx2fc_percpu_info structure
576 */
577int bnx2fc_percpu_io_thread(void *arg)
578{
579 struct bnx2fc_percpu_s *p = arg;
580 struct bnx2fc_work *work, *tmp;
581 LIST_HEAD(work_list);
582
583 set_user_nice(current, -20);
584 set_current_state(TASK_INTERRUPTIBLE);
585 while (!kthread_should_stop()) {
586 schedule();
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800587 spin_lock_bh(&p->fp_work_lock);
588 while (!list_empty(&p->work_list)) {
589 list_splice_init(&p->work_list, &work_list);
590 spin_unlock_bh(&p->fp_work_lock);
591
592 list_for_each_entry_safe(work, tmp, &work_list, list) {
593 list_del_init(&work->list);
594 bnx2fc_process_cq_compl(work->tgt, work->wqe);
595 kfree(work);
596 }
597
598 spin_lock_bh(&p->fp_work_lock);
599 }
Bhanu Gollapudifee78712011-03-21 18:51:13 -0700600 __set_current_state(TASK_INTERRUPTIBLE);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800601 spin_unlock_bh(&p->fp_work_lock);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800602 }
Bhanu Gollapudifee78712011-03-21 18:51:13 -0700603 __set_current_state(TASK_RUNNING);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800604
605 return 0;
606}
607
608static struct fc_host_statistics *bnx2fc_get_host_stats(struct Scsi_Host *shost)
609{
610 struct fc_host_statistics *bnx2fc_stats;
611 struct fc_lport *lport = shost_priv(shost);
612 struct fcoe_port *port = lport_priv(lport);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700613 struct bnx2fc_interface *interface = port->priv;
614 struct bnx2fc_hba *hba = interface->hba;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800615 struct fcoe_statistics_params *fw_stats;
616 int rc = 0;
617
618 fw_stats = (struct fcoe_statistics_params *)hba->stats_buffer;
619 if (!fw_stats)
620 return NULL;
621
622 bnx2fc_stats = fc_get_host_stats(shost);
623
624 init_completion(&hba->stat_req_done);
625 if (bnx2fc_send_stat_req(hba))
626 return bnx2fc_stats;
627 rc = wait_for_completion_timeout(&hba->stat_req_done, (2 * HZ));
628 if (!rc) {
629 BNX2FC_HBA_DBG(lport, "FW stat req timed out\n");
630 return bnx2fc_stats;
631 }
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300632 bnx2fc_stats->invalid_crc_count += fw_stats->rx_stat2.fc_crc_cnt;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800633 bnx2fc_stats->tx_frames += fw_stats->tx_stat.fcoe_tx_pkt_cnt;
634 bnx2fc_stats->tx_words += (fw_stats->tx_stat.fcoe_tx_byte_cnt) / 4;
635 bnx2fc_stats->rx_frames += fw_stats->rx_stat0.fcoe_rx_pkt_cnt;
636 bnx2fc_stats->rx_words += (fw_stats->rx_stat0.fcoe_rx_byte_cnt) / 4;
637
638 bnx2fc_stats->dumped_frames = 0;
639 bnx2fc_stats->lip_count = 0;
640 bnx2fc_stats->nos_count = 0;
641 bnx2fc_stats->loss_of_sync_count = 0;
642 bnx2fc_stats->loss_of_signal_count = 0;
643 bnx2fc_stats->prim_seq_protocol_err_count = 0;
644
645 return bnx2fc_stats;
646}
647
648static int bnx2fc_shost_config(struct fc_lport *lport, struct device *dev)
649{
650 struct fcoe_port *port = lport_priv(lport);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700651 struct bnx2fc_interface *interface = port->priv;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800652 struct Scsi_Host *shost = lport->host;
653 int rc = 0;
654
655 shost->max_cmd_len = BNX2FC_MAX_CMD_LEN;
656 shost->max_lun = BNX2FC_MAX_LUN;
657 shost->max_id = BNX2FC_MAX_FCP_TGT;
658 shost->max_channel = 0;
659 if (lport->vport)
660 shost->transportt = bnx2fc_vport_xport_template;
661 else
662 shost->transportt = bnx2fc_transport_template;
663
664 /* Add the new host to SCSI-ml */
665 rc = scsi_add_host(lport->host, dev);
666 if (rc) {
667 printk(KERN_ERR PFX "Error on scsi_add_host\n");
668 return rc;
669 }
670 if (!lport->vport)
671 fc_host_max_npiv_vports(lport->host) = USHRT_MAX;
672 sprintf(fc_host_symbolic_name(lport->host), "%s v%s over %s",
673 BNX2FC_NAME, BNX2FC_VERSION,
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700674 interface->netdev->name);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800675
676 return 0;
677}
678
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800679static void bnx2fc_link_speed_update(struct fc_lport *lport)
680{
681 struct fcoe_port *port = lport_priv(lport);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700682 struct bnx2fc_interface *interface = port->priv;
683 struct net_device *netdev = interface->netdev;
David Decotigny8ae6dac2011-04-27 18:32:38 +0000684 struct ethtool_cmd ecmd;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800685
686 if (!dev_ethtool_get_settings(netdev, &ecmd)) {
687 lport->link_supported_speeds &=
688 ~(FC_PORTSPEED_1GBIT | FC_PORTSPEED_10GBIT);
689 if (ecmd.supported & (SUPPORTED_1000baseT_Half |
690 SUPPORTED_1000baseT_Full))
691 lport->link_supported_speeds |= FC_PORTSPEED_1GBIT;
692 if (ecmd.supported & SUPPORTED_10000baseT_Full)
693 lport->link_supported_speeds |= FC_PORTSPEED_10GBIT;
694
David Decotigny8ae6dac2011-04-27 18:32:38 +0000695 switch (ethtool_cmd_speed(&ecmd)) {
696 case SPEED_1000:
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800697 lport->link_speed = FC_PORTSPEED_1GBIT;
David Decotigny8ae6dac2011-04-27 18:32:38 +0000698 break;
Bhanu Prakash Gollapudia4dc08c2011-05-27 11:47:25 -0700699 case SPEED_2500:
700 lport->link_speed = FC_PORTSPEED_2GBIT;
701 break;
David Decotigny8ae6dac2011-04-27 18:32:38 +0000702 case SPEED_10000:
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800703 lport->link_speed = FC_PORTSPEED_10GBIT;
David Decotigny8ae6dac2011-04-27 18:32:38 +0000704 break;
705 }
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800706 }
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800707}
708static int bnx2fc_link_ok(struct fc_lport *lport)
709{
710 struct fcoe_port *port = lport_priv(lport);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700711 struct bnx2fc_interface *interface = port->priv;
712 struct bnx2fc_hba *hba = interface->hba;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800713 struct net_device *dev = hba->phys_dev;
714 int rc = 0;
715
716 if ((dev->flags & IFF_UP) && netif_carrier_ok(dev))
717 clear_bit(ADAPTER_STATE_LINK_DOWN, &hba->adapter_state);
718 else {
719 set_bit(ADAPTER_STATE_LINK_DOWN, &hba->adapter_state);
720 rc = -1;
721 }
722 return rc;
723}
724
725/**
726 * bnx2fc_get_link_state - get network link state
727 *
728 * @hba: adapter instance pointer
729 *
730 * updates adapter structure flag based on netdev state
731 */
732void bnx2fc_get_link_state(struct bnx2fc_hba *hba)
733{
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700734 if (test_bit(__LINK_STATE_NOCARRIER, &hba->phys_dev->state))
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800735 set_bit(ADAPTER_STATE_LINK_DOWN, &hba->adapter_state);
736 else
737 clear_bit(ADAPTER_STATE_LINK_DOWN, &hba->adapter_state);
738}
739
740static int bnx2fc_net_config(struct fc_lport *lport)
741{
742 struct bnx2fc_hba *hba;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700743 struct bnx2fc_interface *interface;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800744 struct fcoe_port *port;
745 u64 wwnn, wwpn;
746
747 port = lport_priv(lport);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700748 interface = port->priv;
749 hba = interface->hba;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800750
751 /* require support for get_pauseparam ethtool op. */
752 if (!hba->phys_dev->ethtool_ops ||
753 !hba->phys_dev->ethtool_ops->get_pauseparam)
754 return -EOPNOTSUPP;
755
Bhanu Gollapudi1294bfe2011-03-17 17:13:34 -0700756 if (fc_set_mfs(lport, BNX2FC_MFS))
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800757 return -EINVAL;
758
759 skb_queue_head_init(&port->fcoe_pending_queue);
760 port->fcoe_pending_queue_active = 0;
761 setup_timer(&port->timer, fcoe_queue_timer, (unsigned long) lport);
762
763 bnx2fc_link_speed_update(lport);
764
765 if (!lport->vport) {
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700766 wwnn = fcoe_wwn_from_mac(interface->ctlr.ctl_src_addr, 1, 0);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800767 BNX2FC_HBA_DBG(lport, "WWNN = 0x%llx\n", wwnn);
768 fc_set_wwnn(lport, wwnn);
769
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700770 wwpn = fcoe_wwn_from_mac(interface->ctlr.ctl_src_addr, 2, 0);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800771 BNX2FC_HBA_DBG(lport, "WWPN = 0x%llx\n", wwpn);
772 fc_set_wwpn(lport, wwpn);
773 }
774
775 return 0;
776}
777
778static void bnx2fc_destroy_timer(unsigned long data)
779{
780 struct bnx2fc_hba *hba = (struct bnx2fc_hba *)data;
781
Bhanu Prakash Gollapudicd703ae2011-08-04 17:38:43 -0700782 printk(KERN_ERR PFX "ERROR:bnx2fc_destroy_timer - "
783 "Destroy compl not received!!\n");
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700784 set_bit(BNX2FC_FLAG_DESTROY_CMPL, &hba->flags);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800785 wake_up_interruptible(&hba->destroy_wait);
786}
787
788/**
789 * bnx2fc_indicate_netevent - Generic netdev event handler
790 *
791 * @context: adapter structure pointer
792 * @event: event type
Michael Chan415199f2011-07-20 14:55:24 +0000793 * @vlan_id: vlan id - associated vlan id with this event
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800794 *
795 * Handles NETDEV_UP, NETDEV_DOWN, NETDEV_GOING_DOWN,NETDEV_CHANGE and
Bhanu Prakash Gollapudiabc49a92011-08-04 17:38:42 -0700796 * NETDEV_CHANGE_MTU events. Handle NETDEV_UNREGISTER only for vlans.
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800797 */
Michael Chan415199f2011-07-20 14:55:24 +0000798static void bnx2fc_indicate_netevent(void *context, unsigned long event,
799 u16 vlan_id)
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800800{
801 struct bnx2fc_hba *hba = (struct bnx2fc_hba *)context;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700802 struct fc_lport *lport;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800803 struct fc_lport *vport;
Bhanu Prakash Gollapudiabc49a92011-08-04 17:38:42 -0700804 struct bnx2fc_interface *interface, *tmp;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700805 int wait_for_upload = 0;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800806 u32 link_possible = 1;
807
Bhanu Prakash Gollapudiabc49a92011-08-04 17:38:42 -0700808 if (vlan_id != 0 && event != NETDEV_UNREGISTER)
Michael Chan415199f2011-07-20 14:55:24 +0000809 return;
810
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800811 switch (event) {
812 case NETDEV_UP:
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800813 if (!test_bit(ADAPTER_STATE_UP, &hba->adapter_state))
814 printk(KERN_ERR "indicate_netevent: "\
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700815 "hba is not UP!!\n");
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800816 break;
817
818 case NETDEV_DOWN:
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800819 clear_bit(ADAPTER_STATE_GOING_DOWN, &hba->adapter_state);
820 clear_bit(ADAPTER_STATE_UP, &hba->adapter_state);
821 link_possible = 0;
822 break;
823
824 case NETDEV_GOING_DOWN:
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800825 set_bit(ADAPTER_STATE_GOING_DOWN, &hba->adapter_state);
826 link_possible = 0;
827 break;
828
829 case NETDEV_CHANGE:
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800830 break;
831
Bhanu Prakash Gollapudiabc49a92011-08-04 17:38:42 -0700832 case NETDEV_UNREGISTER:
833 if (!vlan_id)
834 return;
835 mutex_lock(&bnx2fc_dev_lock);
836 list_for_each_entry_safe(interface, tmp, &if_list, list) {
837 if (interface->hba != hba)
838 continue;
839 __bnx2fc_destroy(interface, true);
840 }
841 mutex_unlock(&bnx2fc_dev_lock);
842 return;
843
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800844 default:
845 printk(KERN_ERR PFX "Unkonwn netevent %ld", event);
846 return;
847 }
848
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700849 mutex_lock(&bnx2fc_dev_lock);
850 list_for_each_entry(interface, &if_list, list) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800851
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700852 if (interface->hba != hba)
853 continue;
854
855 lport = interface->ctlr.lp;
856 BNX2FC_HBA_DBG(lport, "netevent handler - event=%s %ld\n",
857 interface->netdev->name, event);
858
859 bnx2fc_link_speed_update(lport);
860
861 if (link_possible && !bnx2fc_link_ok(lport)) {
862 printk(KERN_ERR "indicate_netevent: ctlr_link_up\n");
863 fcoe_ctlr_link_up(&interface->ctlr);
864 } else if (fcoe_ctlr_link_down(&interface->ctlr)) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800865 mutex_lock(&lport->lp_mutex);
866 list_for_each_entry(vport, &lport->vports, list)
867 fc_host_port_type(vport->host) =
868 FC_PORTTYPE_UNKNOWN;
869 mutex_unlock(&lport->lp_mutex);
870 fc_host_port_type(lport->host) = FC_PORTTYPE_UNKNOWN;
871 per_cpu_ptr(lport->dev_stats,
872 get_cpu())->LinkFailureCount++;
873 put_cpu();
874 fcoe_clean_pending_queue(lport);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700875 wait_for_upload = 1;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800876 }
877 }
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700878 mutex_unlock(&bnx2fc_dev_lock);
879
880 if (wait_for_upload) {
881 clear_bit(ADAPTER_STATE_READY, &hba->adapter_state);
882 init_waitqueue_head(&hba->shutdown_wait);
883 BNX2FC_MISC_DBG("indicate_netevent "
884 "num_ofld_sess = %d\n",
885 hba->num_ofld_sess);
886 hba->wait_for_link_down = 1;
887 wait_event_interruptible(hba->shutdown_wait,
888 (hba->num_ofld_sess == 0));
889 BNX2FC_MISC_DBG("wakeup - num_ofld_sess = %d\n",
890 hba->num_ofld_sess);
891 hba->wait_for_link_down = 0;
892
893 if (signal_pending(current))
894 flush_signals(current);
895 }
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800896}
897
898static int bnx2fc_libfc_config(struct fc_lport *lport)
899{
900
901 /* Set the function pointers set by bnx2fc driver */
902 memcpy(&lport->tt, &bnx2fc_libfc_fcn_templ,
903 sizeof(struct libfc_function_template));
904 fc_elsct_init(lport);
905 fc_exch_init(lport);
906 fc_rport_init(lport);
907 fc_disc_init(lport);
908 return 0;
909}
910
911static int bnx2fc_em_config(struct fc_lport *lport)
912{
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800913 if (!fc_exch_mgr_alloc(lport, FC_CLASS_3, FCOE_MIN_XID,
914 FCOE_MAX_XID, NULL)) {
915 printk(KERN_ERR PFX "em_config:fc_exch_mgr_alloc failed\n");
916 return -ENOMEM;
917 }
918
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800919 return 0;
920}
921
922static int bnx2fc_lport_config(struct fc_lport *lport)
923{
924 lport->link_up = 0;
925 lport->qfull = 0;
926 lport->max_retry_count = 3;
927 lport->max_rport_retry_count = 3;
928 lport->e_d_tov = 2 * 1000;
929 lport->r_a_tov = 10 * 1000;
930
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800931 lport->service_params = (FCP_SPPF_INIT_FCN | FCP_SPPF_RD_XRDY_DIS |
932 FCP_SPPF_RETRY | FCP_SPPF_CONF_COMPL);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800933 lport->does_npiv = 1;
934
935 memset(&lport->rnid_gen, 0, sizeof(struct fc_els_rnid_gen));
936 lport->rnid_gen.rnid_atype = BNX2FC_RNID_HBA;
937
938 /* alloc stats structure */
939 if (fc_lport_init_stats(lport))
940 return -ENOMEM;
941
942 /* Finish fc_lport configuration */
943 fc_lport_config(lport);
944
945 return 0;
946}
947
948/**
949 * bnx2fc_fip_recv - handle a received FIP frame.
950 *
951 * @skb: the received skb
952 * @dev: associated &net_device
953 * @ptype: the &packet_type structure which was used to register this handler.
954 * @orig_dev: original receive &net_device, in case @ dev is a bond.
955 *
956 * Returns: 0 for success
957 */
958static int bnx2fc_fip_recv(struct sk_buff *skb, struct net_device *dev,
959 struct packet_type *ptype,
960 struct net_device *orig_dev)
961{
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700962 struct bnx2fc_interface *interface;
963 interface = container_of(ptype, struct bnx2fc_interface,
964 fip_packet_type);
965 fcoe_ctlr_recv(&interface->ctlr, skb);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800966 return 0;
967}
968
969/**
970 * bnx2fc_update_src_mac - Update Ethernet MAC filters.
971 *
972 * @fip: FCoE controller.
973 * @old: Unicast MAC address to delete if the MAC is non-zero.
974 * @new: Unicast MAC address to add.
975 *
976 * Remove any previously-set unicast MAC filter.
977 * Add secondary FCoE MAC address filter for our OUI.
978 */
979static void bnx2fc_update_src_mac(struct fc_lport *lport, u8 *addr)
980{
981 struct fcoe_port *port = lport_priv(lport);
982
983 memcpy(port->data_src_addr, addr, ETH_ALEN);
984}
985
986/**
987 * bnx2fc_get_src_mac - return the ethernet source address for an lport
988 *
989 * @lport: libfc port
990 */
991static u8 *bnx2fc_get_src_mac(struct fc_lport *lport)
992{
993 struct fcoe_port *port;
994
995 port = (struct fcoe_port *)lport_priv(lport);
996 return port->data_src_addr;
997}
998
999/**
1000 * bnx2fc_fip_send - send an Ethernet-encapsulated FIP frame.
1001 *
1002 * @fip: FCoE controller.
1003 * @skb: FIP Packet.
1004 */
1005static void bnx2fc_fip_send(struct fcoe_ctlr *fip, struct sk_buff *skb)
1006{
1007 skb->dev = bnx2fc_from_ctlr(fip)->netdev;
1008 dev_queue_xmit(skb);
1009}
1010
1011static int bnx2fc_vport_create(struct fc_vport *vport, bool disabled)
1012{
1013 struct Scsi_Host *shost = vport_to_shost(vport);
1014 struct fc_lport *n_port = shost_priv(shost);
1015 struct fcoe_port *port = lport_priv(n_port);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001016 struct bnx2fc_interface *interface = port->priv;
1017 struct net_device *netdev = interface->netdev;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001018 struct fc_lport *vn_port;
1019
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001020 if (!test_bit(BNX2FC_FLAG_FW_INIT_DONE, &interface->hba->flags)) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001021 printk(KERN_ERR PFX "vn ports cannot be created on"
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001022 "this interface\n");
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001023 return -EIO;
1024 }
1025 mutex_lock(&bnx2fc_dev_lock);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001026 vn_port = bnx2fc_if_create(interface, &vport->dev, 1);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001027 mutex_unlock(&bnx2fc_dev_lock);
1028
1029 if (IS_ERR(vn_port)) {
1030 printk(KERN_ERR PFX "bnx2fc_vport_create (%s) failed\n",
1031 netdev->name);
1032 return -EIO;
1033 }
1034
1035 if (disabled) {
1036 fc_vport_set_state(vport, FC_VPORT_DISABLED);
1037 } else {
1038 vn_port->boot_time = jiffies;
1039 fc_lport_init(vn_port);
1040 fc_fabric_login(vn_port);
1041 fc_vport_setlink(vn_port);
1042 }
1043 return 0;
1044}
1045
Bhanu Prakash Gollapudiabc49a92011-08-04 17:38:42 -07001046static void bnx2fc_free_vport(struct bnx2fc_hba *hba, struct fc_lport *lport)
1047{
1048 struct bnx2fc_lport *blport, *tmp;
1049
1050 spin_lock_bh(&hba->hba_lock);
1051 list_for_each_entry_safe(blport, tmp, &hba->vports, list) {
1052 if (blport->lport == lport) {
1053 list_del(&blport->list);
1054 kfree(blport);
1055 }
1056 }
1057 spin_unlock_bh(&hba->hba_lock);
1058}
1059
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001060static int bnx2fc_vport_destroy(struct fc_vport *vport)
1061{
1062 struct Scsi_Host *shost = vport_to_shost(vport);
1063 struct fc_lport *n_port = shost_priv(shost);
1064 struct fc_lport *vn_port = vport->dd_data;
1065 struct fcoe_port *port = lport_priv(vn_port);
Bhanu Prakash Gollapudiabc49a92011-08-04 17:38:42 -07001066 struct bnx2fc_interface *interface = port->priv;
Bhanu Prakash Gollapudicdf54662011-08-04 17:38:39 -07001067 struct fc_lport *v_port;
1068 bool found = false;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001069
1070 mutex_lock(&n_port->lp_mutex);
Bhanu Prakash Gollapudicdf54662011-08-04 17:38:39 -07001071 list_for_each_entry(v_port, &n_port->vports, list)
1072 if (v_port->vport == vport) {
1073 found = true;
1074 break;
1075 }
1076
1077 if (!found) {
1078 mutex_unlock(&n_port->lp_mutex);
1079 return -ENOENT;
1080 }
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001081 list_del(&vn_port->list);
1082 mutex_unlock(&n_port->lp_mutex);
Bhanu Prakash Gollapudiabc49a92011-08-04 17:38:42 -07001083 bnx2fc_free_vport(interface->hba, port->lport);
1084 bnx2fc_port_shutdown(port->lport);
1085 bnx2fc_interface_put(interface);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001086 queue_work(bnx2fc_wq, &port->destroy_work);
1087 return 0;
1088}
1089
1090static int bnx2fc_vport_disable(struct fc_vport *vport, bool disable)
1091{
1092 struct fc_lport *lport = vport->dd_data;
1093
1094 if (disable) {
1095 fc_vport_set_state(vport, FC_VPORT_DISABLED);
1096 fc_fabric_logoff(lport);
1097 } else {
1098 lport->boot_time = jiffies;
1099 fc_fabric_login(lport);
1100 fc_vport_setlink(lport);
1101 }
1102 return 0;
1103}
1104
1105
Bhanu Prakash Gollapudi776cebc2011-08-04 17:38:40 -07001106static int bnx2fc_interface_setup(struct bnx2fc_interface *interface)
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001107{
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001108 struct net_device *netdev = interface->netdev;
1109 struct net_device *physdev = interface->hba->phys_dev;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001110 struct netdev_hw_addr *ha;
1111 int sel_san_mac = 0;
1112
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001113 /* setup Source MAC Address */
1114 rcu_read_lock();
1115 for_each_dev_addr(physdev, ha) {
1116 BNX2FC_MISC_DBG("net_config: ha->type = %d, fip_mac = ",
1117 ha->type);
1118 printk(KERN_INFO "%2x:%2x:%2x:%2x:%2x:%2x\n", ha->addr[0],
1119 ha->addr[1], ha->addr[2], ha->addr[3],
1120 ha->addr[4], ha->addr[5]);
1121
1122 if ((ha->type == NETDEV_HW_ADDR_T_SAN) &&
1123 (is_valid_ether_addr(ha->addr))) {
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001124 memcpy(interface->ctlr.ctl_src_addr, ha->addr,
1125 ETH_ALEN);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001126 sel_san_mac = 1;
1127 BNX2FC_MISC_DBG("Found SAN MAC\n");
1128 }
1129 }
1130 rcu_read_unlock();
1131
1132 if (!sel_san_mac)
1133 return -ENODEV;
1134
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001135 interface->fip_packet_type.func = bnx2fc_fip_recv;
1136 interface->fip_packet_type.type = htons(ETH_P_FIP);
1137 interface->fip_packet_type.dev = netdev;
1138 dev_add_pack(&interface->fip_packet_type);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001139
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001140 interface->fcoe_packet_type.func = bnx2fc_rcv;
1141 interface->fcoe_packet_type.type = __constant_htons(ETH_P_FCOE);
1142 interface->fcoe_packet_type.dev = netdev;
1143 dev_add_pack(&interface->fcoe_packet_type);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001144
1145 return 0;
1146}
1147
1148static int bnx2fc_attach_transport(void)
1149{
1150 bnx2fc_transport_template =
1151 fc_attach_transport(&bnx2fc_transport_function);
1152
1153 if (bnx2fc_transport_template == NULL) {
1154 printk(KERN_ERR PFX "Failed to attach FC transport\n");
1155 return -ENODEV;
1156 }
1157
1158 bnx2fc_vport_xport_template =
1159 fc_attach_transport(&bnx2fc_vport_xport_function);
1160 if (bnx2fc_vport_xport_template == NULL) {
1161 printk(KERN_ERR PFX
1162 "Failed to attach FC transport for vport\n");
1163 fc_release_transport(bnx2fc_transport_template);
1164 bnx2fc_transport_template = NULL;
1165 return -ENODEV;
1166 }
1167 return 0;
1168}
1169static void bnx2fc_release_transport(void)
1170{
1171 fc_release_transport(bnx2fc_transport_template);
1172 fc_release_transport(bnx2fc_vport_xport_template);
1173 bnx2fc_transport_template = NULL;
1174 bnx2fc_vport_xport_template = NULL;
1175}
1176
1177static void bnx2fc_interface_release(struct kref *kref)
1178{
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001179 struct bnx2fc_interface *interface;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001180 struct net_device *netdev;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001181
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001182 interface = container_of(kref, struct bnx2fc_interface, kref);
Nithin Nayak Sujir068bdce2011-04-25 12:30:09 -07001183 BNX2FC_MISC_DBG("Interface is being released\n");
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001184
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001185 netdev = interface->netdev;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001186
1187 /* tear-down FIP controller */
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001188 if (test_and_clear_bit(BNX2FC_CTLR_INIT_DONE, &interface->if_flags))
1189 fcoe_ctlr_destroy(&interface->ctlr);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001190
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001191 kfree(interface);
1192
1193 dev_put(netdev);
1194 module_put(THIS_MODULE);
1195}
1196
1197static inline void bnx2fc_interface_get(struct bnx2fc_interface *interface)
1198{
1199 kref_get(&interface->kref);
1200}
1201
1202static inline void bnx2fc_interface_put(struct bnx2fc_interface *interface)
1203{
1204 kref_put(&interface->kref, bnx2fc_interface_release);
1205}
1206static void bnx2fc_hba_destroy(struct bnx2fc_hba *hba)
1207{
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001208 /* Free the command manager */
1209 if (hba->cmd_mgr) {
1210 bnx2fc_cmd_mgr_free(hba->cmd_mgr);
1211 hba->cmd_mgr = NULL;
1212 }
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001213 kfree(hba->tgt_ofld_list);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001214 bnx2fc_unbind_pcidev(hba);
1215 kfree(hba);
1216}
1217
1218/**
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001219 * bnx2fc_hba_create - create a new bnx2fc hba
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001220 *
1221 * @cnic: pointer to cnic device
1222 *
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001223 * Creates a new FCoE hba on the given device.
1224 *
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001225 */
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001226static struct bnx2fc_hba *bnx2fc_hba_create(struct cnic_dev *cnic)
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001227{
1228 struct bnx2fc_hba *hba;
1229 int rc;
1230
1231 hba = kzalloc(sizeof(*hba), GFP_KERNEL);
1232 if (!hba) {
1233 printk(KERN_ERR PFX "Unable to allocate hba structure\n");
1234 return NULL;
1235 }
1236 spin_lock_init(&hba->hba_lock);
1237 mutex_init(&hba->hba_mutex);
1238
1239 hba->cnic = cnic;
1240 rc = bnx2fc_bind_pcidev(hba);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001241 if (rc) {
1242 printk(KERN_ERR PFX "create_adapter: bind error\n");
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001243 goto bind_err;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001244 }
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001245 hba->phys_dev = cnic->netdev;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001246 hba->next_conn_id = 0;
1247
1248 hba->tgt_ofld_list =
1249 kzalloc(sizeof(struct bnx2fc_rport *) * BNX2FC_NUM_MAX_SESS,
1250 GFP_KERNEL);
1251 if (!hba->tgt_ofld_list) {
1252 printk(KERN_ERR PFX "Unable to allocate tgt offload list\n");
1253 goto tgtofld_err;
1254 }
1255
1256 hba->num_ofld_sess = 0;
1257
1258 hba->cmd_mgr = bnx2fc_cmd_mgr_alloc(hba, BNX2FC_MIN_XID,
1259 BNX2FC_MAX_XID);
1260 if (!hba->cmd_mgr) {
1261 printk(KERN_ERR PFX "em_config:bnx2fc_cmd_mgr_alloc failed\n");
1262 goto cmgr_err;
1263 }
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001264
1265 init_waitqueue_head(&hba->shutdown_wait);
1266 init_waitqueue_head(&hba->destroy_wait);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001267 INIT_LIST_HEAD(&hba->vports);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001268
1269 return hba;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001270
1271cmgr_err:
1272 kfree(hba->tgt_ofld_list);
1273tgtofld_err:
1274 bnx2fc_unbind_pcidev(hba);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001275bind_err:
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001276 kfree(hba);
1277 return NULL;
1278}
1279
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001280struct bnx2fc_interface *bnx2fc_interface_create(struct bnx2fc_hba *hba,
1281 struct net_device *netdev,
1282 enum fip_state fip_mode)
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001283{
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001284 struct bnx2fc_interface *interface;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001285 int rc = 0;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001286
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001287 interface = kzalloc(sizeof(*interface), GFP_KERNEL);
1288 if (!interface) {
1289 printk(KERN_ERR PFX "Unable to allocate interface structure\n");
1290 return NULL;
1291 }
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001292 dev_hold(netdev);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001293 kref_init(&interface->kref);
1294 interface->hba = hba;
1295 interface->netdev = netdev;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001296
1297 /* Initialize FIP */
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001298 fcoe_ctlr_init(&interface->ctlr, fip_mode);
1299 interface->ctlr.send = bnx2fc_fip_send;
1300 interface->ctlr.update_mac = bnx2fc_update_src_mac;
1301 interface->ctlr.get_src_addr = bnx2fc_get_src_mac;
1302 set_bit(BNX2FC_CTLR_INIT_DONE, &interface->if_flags);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001303
Bhanu Prakash Gollapudi776cebc2011-08-04 17:38:40 -07001304 rc = bnx2fc_interface_setup(interface);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001305 if (!rc)
1306 return interface;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001307
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001308 fcoe_ctlr_destroy(&interface->ctlr);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001309 dev_put(netdev);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001310 kfree(interface);
1311 return NULL;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001312}
1313
1314/**
1315 * bnx2fc_if_create - Create FCoE instance on a given interface
1316 *
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001317 * @interface: FCoE interface to create a local port on
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001318 * @parent: Device pointer to be the parent in sysfs for the SCSI host
1319 * @npiv: Indicates if the port is vport or not
1320 *
1321 * Creates a fc_lport instance and a Scsi_Host instance and configure them.
1322 *
1323 * Returns: Allocated fc_lport or an error pointer
1324 */
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001325static struct fc_lport *bnx2fc_if_create(struct bnx2fc_interface *interface,
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001326 struct device *parent, int npiv)
1327{
Vasu Dev134a4e22011-04-28 15:55:44 -07001328 struct fc_lport *lport, *n_port;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001329 struct fcoe_port *port;
1330 struct Scsi_Host *shost;
1331 struct fc_vport *vport = dev_to_vport(parent);
Bhanu Prakash Gollapudid36b3272011-05-27 11:47:27 -07001332 struct bnx2fc_lport *blport;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001333 struct bnx2fc_hba *hba;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001334 int rc = 0;
1335
Bhanu Prakash Gollapudid36b3272011-05-27 11:47:27 -07001336 blport = kzalloc(sizeof(struct bnx2fc_lport), GFP_KERNEL);
1337 if (!blport) {
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001338 BNX2FC_HBA_DBG(interface->ctlr.lp, "Unable to alloc blport\n");
Bhanu Prakash Gollapudid36b3272011-05-27 11:47:27 -07001339 return NULL;
1340 }
1341
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001342 /* Allocate Scsi_Host structure */
Vasu Dev134a4e22011-04-28 15:55:44 -07001343 if (!npiv)
1344 lport = libfc_host_alloc(&bnx2fc_shost_template, sizeof(*port));
1345 else
1346 lport = libfc_vport_create(vport, sizeof(*port));
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001347
1348 if (!lport) {
1349 printk(KERN_ERR PFX "could not allocate scsi host structure\n");
Bhanu Prakash Gollapudid36b3272011-05-27 11:47:27 -07001350 goto free_blport;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001351 }
1352 shost = lport->host;
1353 port = lport_priv(lport);
1354 port->lport = lport;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001355 port->priv = interface;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001356 INIT_WORK(&port->destroy_work, bnx2fc_destroy_work);
1357
1358 /* Configure fcoe_port */
1359 rc = bnx2fc_lport_config(lport);
1360 if (rc)
1361 goto lp_config_err;
1362
1363 if (npiv) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001364 printk(KERN_ERR PFX "Setting vport names, 0x%llX 0x%llX\n",
1365 vport->node_name, vport->port_name);
1366 fc_set_wwnn(lport, vport->node_name);
1367 fc_set_wwpn(lport, vport->port_name);
1368 }
1369 /* Configure netdev and networking properties of the lport */
1370 rc = bnx2fc_net_config(lport);
1371 if (rc) {
1372 printk(KERN_ERR PFX "Error on bnx2fc_net_config\n");
1373 goto lp_config_err;
1374 }
1375
1376 rc = bnx2fc_shost_config(lport, parent);
1377 if (rc) {
1378 printk(KERN_ERR PFX "Couldnt configure shost for %s\n",
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001379 interface->netdev->name);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001380 goto lp_config_err;
1381 }
1382
1383 /* Initialize the libfc library */
1384 rc = bnx2fc_libfc_config(lport);
1385 if (rc) {
1386 printk(KERN_ERR PFX "Couldnt configure libfc\n");
1387 goto shost_err;
1388 }
1389 fc_host_port_type(lport->host) = FC_PORTTYPE_UNKNOWN;
1390
1391 /* Allocate exchange manager */
Vasu Dev134a4e22011-04-28 15:55:44 -07001392 if (!npiv)
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001393 rc = bnx2fc_em_config(lport);
Vasu Dev134a4e22011-04-28 15:55:44 -07001394 else {
1395 shost = vport_to_shost(vport);
1396 n_port = shost_priv(shost);
1397 rc = fc_exch_mgr_list_clone(n_port, lport);
1398 }
1399
1400 if (rc) {
1401 printk(KERN_ERR PFX "Error on bnx2fc_em_config\n");
1402 goto shost_err;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001403 }
1404
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001405 bnx2fc_interface_get(interface);
Bhanu Prakash Gollapudid36b3272011-05-27 11:47:27 -07001406
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001407 hba = interface->hba;
Bhanu Prakash Gollapudid36b3272011-05-27 11:47:27 -07001408 spin_lock_bh(&hba->hba_lock);
1409 blport->lport = lport;
1410 list_add_tail(&blport->list, &hba->vports);
1411 spin_unlock_bh(&hba->hba_lock);
1412
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001413 return lport;
1414
1415shost_err:
1416 scsi_remove_host(shost);
1417lp_config_err:
1418 scsi_host_put(lport->host);
Bhanu Prakash Gollapudid36b3272011-05-27 11:47:27 -07001419free_blport:
1420 kfree(blport);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001421 return NULL;
1422}
1423
Bhanu Prakash Gollapudi776cebc2011-08-04 17:38:40 -07001424static void bnx2fc_interface_cleanup(struct bnx2fc_interface *interface)
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001425{
Bhanu Prakash Gollapudi9be17fc2011-08-04 17:38:41 -07001426 struct fc_lport *lport = interface->ctlr.lp;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001427 struct fcoe_port *port = lport_priv(lport);
Bhanu Prakash Gollapudi9be17fc2011-08-04 17:38:41 -07001428 struct bnx2fc_hba *hba = interface->hba;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001429
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001430 /* Stop the transmit retry timer */
1431 del_timer_sync(&port->timer);
1432
1433 /* Free existing transmit skbs */
1434 fcoe_clean_pending_queue(lport);
1435
Bhanu Prakash Gollapudi9be17fc2011-08-04 17:38:41 -07001436 /* Dont listen for Ethernet packets anymore */
1437 __dev_remove_pack(&interface->fcoe_packet_type);
1438 __dev_remove_pack(&interface->fip_packet_type);
1439 synchronize_net();
1440
Bhanu Prakash Gollapudiabc49a92011-08-04 17:38:42 -07001441 bnx2fc_free_vport(hba, lport);
Bhanu Prakash Gollapudi9be17fc2011-08-04 17:38:41 -07001442}
1443
1444static void bnx2fc_if_destroy(struct fc_lport *lport)
1445{
1446
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001447 /* Free queued packets for the receive thread */
1448 bnx2fc_clean_rx_queue(lport);
1449
1450 /* Detach from scsi-ml */
1451 fc_remove_host(lport->host);
1452 scsi_remove_host(lport->host);
1453
1454 /*
1455 * Note that only the physical lport will have the exchange manager.
1456 * for vports, this function is NOP
1457 */
1458 fc_exch_mgr_free(lport);
1459
1460 /* Free memory used by statistical counters */
1461 fc_lport_free_stats(lport);
1462
1463 /* Release Scsi_Host */
1464 scsi_host_put(lport->host);
1465}
1466
Bhanu Prakash Gollapudiabc49a92011-08-04 17:38:42 -07001467static void __bnx2fc_destroy(struct bnx2fc_interface *interface, bool schedule)
1468{
1469 struct fc_lport *lport = interface->ctlr.lp;
1470 struct fcoe_port *port = lport_priv(lport);
1471
1472 bnx2fc_interface_cleanup(interface);
1473 bnx2fc_stop(interface);
1474
1475 list_del(&interface->list);
1476 lport = interface->ctlr.lp;
1477 bnx2fc_interface_put(interface);
1478 if (schedule)
1479 queue_work(bnx2fc_wq, &port->destroy_work);
1480 else
1481 bnx2fc_if_destroy(lport);
1482}
1483
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001484/**
1485 * bnx2fc_destroy - Destroy a bnx2fc FCoE interface
1486 *
1487 * @buffer: The name of the Ethernet interface to be destroyed
1488 * @kp: The associated kernel parameter
1489 *
1490 * Called from sysfs.
1491 *
1492 * Returns: 0 for success
1493 */
1494static int bnx2fc_destroy(struct net_device *netdev)
1495{
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001496 struct bnx2fc_interface *interface = NULL;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001497 int rc = 0;
1498
Nithin Sujir6702ca12011-03-17 17:13:27 -07001499 rtnl_lock();
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001500 mutex_lock(&bnx2fc_dev_lock);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001501
1502 interface = bnx2fc_interface_lookup(netdev);
1503 if (!interface || !interface->ctlr.lp) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001504 rc = -ENODEV;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001505 printk(KERN_ERR PFX "bnx2fc_destroy: interface or lport not found\n");
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001506 goto netdev_err;
1507 }
1508
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001509
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001510 destroy_workqueue(interface->timer_work_queue);
Bhanu Prakash Gollapudiabc49a92011-08-04 17:38:42 -07001511 __bnx2fc_destroy(interface, false);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001512
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001513netdev_err:
1514 mutex_unlock(&bnx2fc_dev_lock);
1515 rtnl_unlock();
1516 return rc;
1517}
1518
1519static void bnx2fc_destroy_work(struct work_struct *work)
1520{
1521 struct fcoe_port *port;
1522 struct fc_lport *lport;
1523
1524 port = container_of(work, struct fcoe_port, destroy_work);
1525 lport = port->lport;
1526
1527 BNX2FC_HBA_DBG(lport, "Entered bnx2fc_destroy_work\n");
1528
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001529 rtnl_lock();
1530 mutex_lock(&bnx2fc_dev_lock);
Bhanu Prakash Gollapudi9be17fc2011-08-04 17:38:41 -07001531 bnx2fc_if_destroy(lport);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001532 mutex_unlock(&bnx2fc_dev_lock);
1533 rtnl_unlock();
1534}
1535
1536static void bnx2fc_unbind_adapter_devices(struct bnx2fc_hba *hba)
1537{
1538 bnx2fc_free_fw_resc(hba);
1539 bnx2fc_free_task_ctx(hba);
1540}
1541
1542/**
1543 * bnx2fc_bind_adapter_devices - binds bnx2fc adapter with the associated
1544 * pci structure
1545 *
1546 * @hba: Adapter instance
1547 */
1548static int bnx2fc_bind_adapter_devices(struct bnx2fc_hba *hba)
1549{
1550 if (bnx2fc_setup_task_ctx(hba))
1551 goto mem_err;
1552
1553 if (bnx2fc_setup_fw_resc(hba))
1554 goto mem_err;
1555
1556 return 0;
1557mem_err:
1558 bnx2fc_unbind_adapter_devices(hba);
1559 return -ENOMEM;
1560}
1561
1562static int bnx2fc_bind_pcidev(struct bnx2fc_hba *hba)
1563{
1564 struct cnic_dev *cnic;
1565
1566 if (!hba->cnic) {
1567 printk(KERN_ERR PFX "cnic is NULL\n");
1568 return -ENODEV;
1569 }
1570 cnic = hba->cnic;
1571 hba->pcidev = cnic->pcidev;
1572 if (hba->pcidev)
1573 pci_dev_get(hba->pcidev);
1574
1575 return 0;
1576}
1577
1578static void bnx2fc_unbind_pcidev(struct bnx2fc_hba *hba)
1579{
1580 if (hba->pcidev)
1581 pci_dev_put(hba->pcidev);
1582 hba->pcidev = NULL;
1583}
1584
1585
1586
1587/**
1588 * bnx2fc_ulp_start - cnic callback to initialize & start adapter instance
1589 *
1590 * @handle: transport handle pointing to adapter struture
1591 *
1592 * This function maps adapter structure to pcidev structure and initiates
1593 * firmware handshake to enable/initialize on-chip FCoE components.
1594 * This bnx2fc - cnic interface api callback is used after following
1595 * conditions are met -
1596 * a) underlying network interface is up (marked by event NETDEV_UP
1597 * from netdev
1598 * b) bnx2fc adatper structure is registered.
1599 */
1600static void bnx2fc_ulp_start(void *handle)
1601{
1602 struct bnx2fc_hba *hba = handle;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001603 struct bnx2fc_interface *interface;
1604 struct fc_lport *lport;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001605
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001606 mutex_lock(&bnx2fc_dev_lock);
1607
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001608 if (!test_bit(BNX2FC_FLAG_FW_INIT_DONE, &hba->flags))
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001609 bnx2fc_fw_init(hba);
1610
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001611 BNX2FC_MISC_DBG("bnx2fc started.\n");
1612
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001613 list_for_each_entry(interface, &if_list, list) {
1614 if (interface->hba == hba) {
1615 lport = interface->ctlr.lp;
1616 /* Kick off Fabric discovery*/
1617 printk(KERN_ERR PFX "ulp_init: start discovery\n");
1618 lport->tt.frame_send = bnx2fc_xmit;
1619 bnx2fc_start_disc(interface);
1620 }
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001621 }
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001622
1623 mutex_unlock(&bnx2fc_dev_lock);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001624}
1625
1626static void bnx2fc_port_shutdown(struct fc_lport *lport)
1627{
1628 BNX2FC_MISC_DBG("Entered %s\n", __func__);
1629 fc_fabric_logoff(lport);
1630 fc_lport_destroy(lport);
1631}
1632
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001633static void bnx2fc_stop(struct bnx2fc_interface *interface)
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001634{
1635 struct fc_lport *lport;
1636 struct fc_lport *vport;
1637
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001638 if (!test_bit(BNX2FC_FLAG_FW_INIT_DONE, &interface->hba->flags))
1639 return;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001640
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001641 lport = interface->ctlr.lp;
1642 bnx2fc_port_shutdown(lport);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001643
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001644 mutex_lock(&lport->lp_mutex);
1645 list_for_each_entry(vport, &lport->vports, list)
1646 fc_host_port_type(vport->host) =
1647 FC_PORTTYPE_UNKNOWN;
1648 mutex_unlock(&lport->lp_mutex);
1649 fc_host_port_type(lport->host) = FC_PORTTYPE_UNKNOWN;
1650 fcoe_ctlr_link_down(&interface->ctlr);
1651 fcoe_clean_pending_queue(lport);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001652}
1653
1654static int bnx2fc_fw_init(struct bnx2fc_hba *hba)
1655{
1656#define BNX2FC_INIT_POLL_TIME (1000 / HZ)
1657 int rc = -1;
1658 int i = HZ;
1659
1660 rc = bnx2fc_bind_adapter_devices(hba);
1661 if (rc) {
1662 printk(KERN_ALERT PFX
1663 "bnx2fc_bind_adapter_devices failed - rc = %d\n", rc);
1664 goto err_out;
1665 }
1666
1667 rc = bnx2fc_send_fw_fcoe_init_msg(hba);
1668 if (rc) {
1669 printk(KERN_ALERT PFX
1670 "bnx2fc_send_fw_fcoe_init_msg failed - rc = %d\n", rc);
1671 goto err_unbind;
1672 }
1673
1674 /*
1675 * Wait until the adapter init message is complete, and adapter
1676 * state is UP.
1677 */
1678 while (!test_bit(ADAPTER_STATE_UP, &hba->adapter_state) && i--)
1679 msleep(BNX2FC_INIT_POLL_TIME);
1680
1681 if (!test_bit(ADAPTER_STATE_UP, &hba->adapter_state)) {
1682 printk(KERN_ERR PFX "bnx2fc_start: %s failed to initialize. "
1683 "Ignoring...\n",
1684 hba->cnic->netdev->name);
1685 rc = -1;
1686 goto err_unbind;
1687 }
1688
1689
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001690 set_bit(BNX2FC_FLAG_FW_INIT_DONE, &hba->flags);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001691 return 0;
1692
1693err_unbind:
1694 bnx2fc_unbind_adapter_devices(hba);
1695err_out:
1696 return rc;
1697}
1698
1699static void bnx2fc_fw_destroy(struct bnx2fc_hba *hba)
1700{
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001701 if (test_and_clear_bit(BNX2FC_FLAG_FW_INIT_DONE, &hba->flags)) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001702 if (bnx2fc_send_fw_fcoe_destroy_msg(hba) == 0) {
1703 init_timer(&hba->destroy_timer);
1704 hba->destroy_timer.expires = BNX2FC_FW_TIMEOUT +
1705 jiffies;
1706 hba->destroy_timer.function = bnx2fc_destroy_timer;
1707 hba->destroy_timer.data = (unsigned long)hba;
1708 add_timer(&hba->destroy_timer);
1709 wait_event_interruptible(hba->destroy_wait,
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001710 test_bit(BNX2FC_FLAG_DESTROY_CMPL,
1711 &hba->flags));
Bhanu Prakash Gollapudicd703ae2011-08-04 17:38:43 -07001712 clear_bit(BNX2FC_FLAG_DESTROY_CMPL, &hba->flags);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001713 /* This should never happen */
1714 if (signal_pending(current))
1715 flush_signals(current);
1716
1717 del_timer_sync(&hba->destroy_timer);
1718 }
1719 bnx2fc_unbind_adapter_devices(hba);
1720 }
1721}
1722
1723/**
1724 * bnx2fc_ulp_stop - cnic callback to shutdown adapter instance
1725 *
1726 * @handle: transport handle pointing to adapter structure
1727 *
1728 * Driver checks if adapter is already in shutdown mode, if not start
1729 * the shutdown process.
1730 */
1731static void bnx2fc_ulp_stop(void *handle)
1732{
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001733 struct bnx2fc_hba *hba = handle;
1734 struct bnx2fc_interface *interface;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001735
1736 printk(KERN_ERR "ULP_STOP\n");
1737
1738 mutex_lock(&bnx2fc_dev_lock);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001739 if (!test_bit(BNX2FC_FLAG_FW_INIT_DONE, &hba->flags))
1740 goto exit;
1741 list_for_each_entry(interface, &if_list, list) {
1742 if (interface->hba == hba)
1743 bnx2fc_stop(interface);
1744 }
1745 BUG_ON(hba->num_ofld_sess != 0);
1746
1747 mutex_lock(&hba->hba_mutex);
1748 clear_bit(ADAPTER_STATE_UP, &hba->adapter_state);
1749 clear_bit(ADAPTER_STATE_GOING_DOWN,
1750 &hba->adapter_state);
1751
1752 clear_bit(ADAPTER_STATE_READY, &hba->adapter_state);
1753 mutex_unlock(&hba->hba_mutex);
1754
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001755 bnx2fc_fw_destroy(hba);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001756exit:
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001757 mutex_unlock(&bnx2fc_dev_lock);
1758}
1759
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001760static void bnx2fc_start_disc(struct bnx2fc_interface *interface)
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001761{
1762 struct fc_lport *lport;
1763 int wait_cnt = 0;
1764
1765 BNX2FC_MISC_DBG("Entered %s\n", __func__);
1766 /* Kick off FIP/FLOGI */
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001767 if (!test_bit(BNX2FC_FLAG_FW_INIT_DONE, &interface->hba->flags)) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001768 printk(KERN_ERR PFX "Init not done yet\n");
1769 return;
1770 }
1771
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001772 lport = interface->ctlr.lp;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001773 BNX2FC_HBA_DBG(lport, "calling fc_fabric_login\n");
1774
1775 if (!bnx2fc_link_ok(lport)) {
1776 BNX2FC_HBA_DBG(lport, "ctlr_link_up\n");
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001777 fcoe_ctlr_link_up(&interface->ctlr);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001778 fc_host_port_type(lport->host) = FC_PORTTYPE_NPORT;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001779 set_bit(ADAPTER_STATE_READY, &interface->hba->adapter_state);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001780 }
1781
1782 /* wait for the FCF to be selected before issuing FLOGI */
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001783 while (!interface->ctlr.sel_fcf) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001784 msleep(250);
1785 /* give up after 3 secs */
1786 if (++wait_cnt > 12)
1787 break;
1788 }
Bhanu Prakash Gollapudi627e6282011-08-04 17:38:35 -07001789
1790 /* Reset max receive frame size to default */
1791 if (fc_set_mfs(lport, BNX2FC_MFS))
1792 return;
1793
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001794 fc_lport_init(lport);
1795 fc_fabric_login(lport);
1796}
1797
1798
1799/**
1800 * bnx2fc_ulp_init - Initialize an adapter instance
1801 *
1802 * @dev : cnic device handle
1803 * Called from cnic_register_driver() context to initialize all
1804 * enumerated cnic devices. This routine allocates adapter structure
1805 * and other device specific resources.
1806 */
1807static void bnx2fc_ulp_init(struct cnic_dev *dev)
1808{
1809 struct bnx2fc_hba *hba;
1810 int rc = 0;
1811
1812 BNX2FC_MISC_DBG("Entered %s\n", __func__);
1813 /* bnx2fc works only when bnx2x is loaded */
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001814 if (!test_bit(CNIC_F_BNX2X_CLASS, &dev->flags) ||
1815 (dev->max_fcoe_conn == 0)) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001816 printk(KERN_ERR PFX "bnx2fc FCoE not supported on %s,"
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001817 " flags: %lx fcoe_conn: %d\n",
1818 dev->netdev->name, dev->flags, dev->max_fcoe_conn);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001819 return;
1820 }
1821
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001822 hba = bnx2fc_hba_create(dev);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001823 if (!hba) {
1824 printk(KERN_ERR PFX "hba initialization failed\n");
1825 return;
1826 }
1827
1828 /* Add HBA to the adapter list */
1829 mutex_lock(&bnx2fc_dev_lock);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001830 list_add_tail(&hba->list, &adapter_list);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001831 adapter_count++;
1832 mutex_unlock(&bnx2fc_dev_lock);
1833
1834 clear_bit(BNX2FC_CNIC_REGISTERED, &hba->reg_with_cnic);
1835 rc = dev->register_device(dev, CNIC_ULP_FCOE,
1836 (void *) hba);
1837 if (rc)
Bhanu Prakash Gollapudib2a554f2011-06-27 23:30:53 -07001838 printk(KERN_ERR PFX "register_device failed, rc = %d\n", rc);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001839 else
1840 set_bit(BNX2FC_CNIC_REGISTERED, &hba->reg_with_cnic);
1841}
1842
1843
1844static int bnx2fc_disable(struct net_device *netdev)
1845{
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001846 struct bnx2fc_interface *interface;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001847 int rc = 0;
1848
Nithin Sujir6702ca12011-03-17 17:13:27 -07001849 rtnl_lock();
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001850 mutex_lock(&bnx2fc_dev_lock);
1851
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001852 interface = bnx2fc_interface_lookup(netdev);
1853 if (!interface || !interface->ctlr.lp) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001854 rc = -ENODEV;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001855 printk(KERN_ERR PFX "bnx2fc_disable: interface or lport not found\n");
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001856 } else {
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001857 fcoe_ctlr_link_down(&interface->ctlr);
1858 fcoe_clean_pending_queue(interface->ctlr.lp);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001859 }
1860
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001861 mutex_unlock(&bnx2fc_dev_lock);
1862 rtnl_unlock();
1863 return rc;
1864}
1865
1866
1867static int bnx2fc_enable(struct net_device *netdev)
1868{
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001869 struct bnx2fc_interface *interface;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001870 int rc = 0;
1871
Nithin Sujir6702ca12011-03-17 17:13:27 -07001872 rtnl_lock();
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001873 mutex_lock(&bnx2fc_dev_lock);
1874
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001875 interface = bnx2fc_interface_lookup(netdev);
1876 if (!interface || !interface->ctlr.lp) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001877 rc = -ENODEV;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001878 printk(KERN_ERR PFX "bnx2fc_enable: interface or lport not found\n");
1879 } else if (!bnx2fc_link_ok(interface->ctlr.lp))
1880 fcoe_ctlr_link_up(&interface->ctlr);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001881
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001882 mutex_unlock(&bnx2fc_dev_lock);
1883 rtnl_unlock();
1884 return rc;
1885}
1886
1887/**
1888 * bnx2fc_create - Create bnx2fc FCoE interface
1889 *
1890 * @buffer: The name of Ethernet interface to create on
1891 * @kp: The associated kernel param
1892 *
1893 * Called from sysfs.
1894 *
1895 * Returns: 0 for success
1896 */
1897static int bnx2fc_create(struct net_device *netdev, enum fip_state fip_mode)
1898{
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001899 struct bnx2fc_interface *interface;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001900 struct bnx2fc_hba *hba;
1901 struct net_device *phys_dev;
1902 struct fc_lport *lport;
1903 struct ethtool_drvinfo drvinfo;
1904 int rc = 0;
1905 int vlan_id;
1906
1907 BNX2FC_MISC_DBG("Entered bnx2fc_create\n");
1908 if (fip_mode != FIP_MODE_FABRIC) {
1909 printk(KERN_ERR "fip mode not FABRIC\n");
1910 return -EIO;
1911 }
1912
Nithin Sujir6702ca12011-03-17 17:13:27 -07001913 rtnl_lock();
1914
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001915 mutex_lock(&bnx2fc_dev_lock);
1916
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001917 if (!try_module_get(THIS_MODULE)) {
1918 rc = -EINVAL;
1919 goto mod_err;
1920 }
1921
1922 /* obtain physical netdev */
1923 if (netdev->priv_flags & IFF_802_1Q_VLAN) {
1924 phys_dev = vlan_dev_real_dev(netdev);
1925 vlan_id = vlan_dev_vlan_id(netdev);
1926 } else {
1927 printk(KERN_ERR PFX "Not a vlan device\n");
1928 rc = -EINVAL;
1929 goto netdev_err;
1930 }
1931 /* verify if the physical device is a netxtreme2 device */
1932 if (phys_dev->ethtool_ops && phys_dev->ethtool_ops->get_drvinfo) {
1933 memset(&drvinfo, 0, sizeof(drvinfo));
1934 phys_dev->ethtool_ops->get_drvinfo(phys_dev, &drvinfo);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001935 if (strncmp(drvinfo.driver, "bnx2x", strlen("bnx2x"))) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001936 printk(KERN_ERR PFX "Not a netxtreme2 device\n");
1937 rc = -EINVAL;
1938 goto netdev_err;
1939 }
1940 } else {
1941 printk(KERN_ERR PFX "unable to obtain drv_info\n");
1942 rc = -EINVAL;
1943 goto netdev_err;
1944 }
1945
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001946 /* obtain interface and initialize rest of the structure */
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001947 hba = bnx2fc_hba_lookup(phys_dev);
1948 if (!hba) {
1949 rc = -ENODEV;
1950 printk(KERN_ERR PFX "bnx2fc_create: hba not found\n");
1951 goto netdev_err;
1952 }
1953
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001954 if (bnx2fc_interface_lookup(netdev)) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001955 rc = -EEXIST;
1956 goto netdev_err;
1957 }
1958
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001959 interface = bnx2fc_interface_create(hba, netdev, fip_mode);
1960 if (!interface) {
1961 printk(KERN_ERR PFX "bnx2fc_interface_create failed\n");
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001962 goto ifput_err;
1963 }
1964
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001965 interface->vlan_id = vlan_id;
1966 interface->vlan_enabled = 1;
1967
1968 interface->timer_work_queue =
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001969 create_singlethread_workqueue("bnx2fc_timer_wq");
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001970 if (!interface->timer_work_queue) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001971 printk(KERN_ERR PFX "ulp_init could not create timer_wq\n");
1972 rc = -EINVAL;
1973 goto ifput_err;
1974 }
1975
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001976 lport = bnx2fc_if_create(interface, &interface->hba->pcidev->dev, 0);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001977 if (!lport) {
1978 printk(KERN_ERR PFX "Failed to create interface (%s)\n",
1979 netdev->name);
Bhanu Prakash Gollapudi776cebc2011-08-04 17:38:40 -07001980 bnx2fc_interface_cleanup(interface);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001981 rc = -EINVAL;
1982 goto if_create_err;
1983 }
1984
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001985 /* Add interface to if_list */
1986 list_add_tail(&interface->list, &if_list);
1987
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001988 lport->boot_time = jiffies;
1989
1990 /* Make this master N_port */
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001991 interface->ctlr.lp = lport;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001992
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001993 BNX2FC_HBA_DBG(lport, "create: START DISC\n");
1994 bnx2fc_start_disc(interface);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001995 /*
1996 * Release from kref_init in bnx2fc_interface_setup, on success
1997 * lport should be holding a reference taken in bnx2fc_if_create
1998 */
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001999 bnx2fc_interface_put(interface);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002000 /* put netdev that was held while calling dev_get_by_name */
2001 mutex_unlock(&bnx2fc_dev_lock);
2002 rtnl_unlock();
2003 return 0;
2004
2005if_create_err:
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002006 destroy_workqueue(interface->timer_work_queue);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002007ifput_err:
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002008 bnx2fc_interface_put(interface);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002009netdev_err:
2010 module_put(THIS_MODULE);
2011mod_err:
2012 mutex_unlock(&bnx2fc_dev_lock);
2013 rtnl_unlock();
2014 return rc;
2015}
2016
2017/**
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002018 * bnx2fc_find_hba_for_cnic - maps cnic instance to bnx2fc hba instance
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002019 *
2020 * @cnic: Pointer to cnic device instance
2021 *
2022 **/
2023static struct bnx2fc_hba *bnx2fc_find_hba_for_cnic(struct cnic_dev *cnic)
2024{
2025 struct list_head *list;
2026 struct list_head *temp;
2027 struct bnx2fc_hba *hba;
2028
2029 /* Called with bnx2fc_dev_lock held */
2030 list_for_each_safe(list, temp, &adapter_list) {
2031 hba = (struct bnx2fc_hba *)list;
2032 if (hba->cnic == cnic)
2033 return hba;
2034 }
2035 return NULL;
2036}
2037
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002038static struct bnx2fc_interface *bnx2fc_interface_lookup(struct net_device
2039 *netdev)
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002040{
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002041 struct bnx2fc_interface *interface;
2042
2043 /* Called with bnx2fc_dev_lock held */
2044 list_for_each_entry(interface, &if_list, list) {
2045 if (interface->netdev == netdev)
2046 return interface;
2047 }
2048 return NULL;
2049}
2050
2051static struct bnx2fc_hba *bnx2fc_hba_lookup(struct net_device
2052 *phys_dev)
2053{
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002054 struct bnx2fc_hba *hba;
2055
2056 /* Called with bnx2fc_dev_lock held */
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002057 list_for_each_entry(hba, &adapter_list, list) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002058 if (hba->phys_dev == phys_dev)
2059 return hba;
2060 }
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002061 printk(KERN_ERR PFX "adapter_lookup: hba NULL\n");
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002062 return NULL;
2063}
2064
2065/**
2066 * bnx2fc_ulp_exit - shuts down adapter instance and frees all resources
2067 *
2068 * @dev cnic device handle
2069 */
2070static void bnx2fc_ulp_exit(struct cnic_dev *dev)
2071{
2072 struct bnx2fc_hba *hba;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002073 struct bnx2fc_interface *interface, *tmp;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002074
2075 BNX2FC_MISC_DBG("Entered bnx2fc_ulp_exit\n");
2076
2077 if (!test_bit(CNIC_F_BNX2X_CLASS, &dev->flags)) {
2078 printk(KERN_ERR PFX "bnx2fc port check: %s, flags: %lx\n",
2079 dev->netdev->name, dev->flags);
2080 return;
2081 }
2082
2083 mutex_lock(&bnx2fc_dev_lock);
2084 hba = bnx2fc_find_hba_for_cnic(dev);
2085 if (!hba) {
2086 printk(KERN_ERR PFX "bnx2fc_ulp_exit: hba not found, dev 0%p\n",
2087 dev);
2088 mutex_unlock(&bnx2fc_dev_lock);
2089 return;
2090 }
2091
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002092 list_del_init(&hba->list);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002093 adapter_count--;
2094
Bhanu Prakash Gollapudiabc49a92011-08-04 17:38:42 -07002095 list_for_each_entry_safe(interface, tmp, &if_list, list)
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002096 /* destroy not called yet, move to quiesced list */
Bhanu Prakash Gollapudiabc49a92011-08-04 17:38:42 -07002097 if (interface->hba == hba)
2098 __bnx2fc_destroy(interface, false);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002099 mutex_unlock(&bnx2fc_dev_lock);
2100
2101 bnx2fc_ulp_stop(hba);
2102 /* unregister cnic device */
2103 if (test_and_clear_bit(BNX2FC_CNIC_REGISTERED, &hba->reg_with_cnic))
2104 hba->cnic->unregister_device(hba->cnic, CNIC_ULP_FCOE);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002105 bnx2fc_hba_destroy(hba);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002106}
2107
2108/**
2109 * bnx2fc_fcoe_reset - Resets the fcoe
2110 *
2111 * @shost: shost the reset is from
2112 *
2113 * Returns: always 0
2114 */
2115static int bnx2fc_fcoe_reset(struct Scsi_Host *shost)
2116{
2117 struct fc_lport *lport = shost_priv(shost);
2118 fc_lport_reset(lport);
2119 return 0;
2120}
2121
2122
2123static bool bnx2fc_match(struct net_device *netdev)
2124{
2125 mutex_lock(&bnx2fc_dev_lock);
2126 if (netdev->priv_flags & IFF_802_1Q_VLAN) {
2127 struct net_device *phys_dev = vlan_dev_real_dev(netdev);
2128
2129 if (bnx2fc_hba_lookup(phys_dev)) {
2130 mutex_unlock(&bnx2fc_dev_lock);
2131 return true;
2132 }
2133 }
2134 mutex_unlock(&bnx2fc_dev_lock);
2135 return false;
2136}
2137
2138
2139static struct fcoe_transport bnx2fc_transport = {
2140 .name = {"bnx2fc"},
2141 .attached = false,
2142 .list = LIST_HEAD_INIT(bnx2fc_transport.list),
2143 .match = bnx2fc_match,
2144 .create = bnx2fc_create,
2145 .destroy = bnx2fc_destroy,
2146 .enable = bnx2fc_enable,
2147 .disable = bnx2fc_disable,
2148};
2149
2150/**
2151 * bnx2fc_percpu_thread_create - Create a receive thread for an
2152 * online CPU
2153 *
2154 * @cpu: cpu index for the online cpu
2155 */
2156static void bnx2fc_percpu_thread_create(unsigned int cpu)
2157{
2158 struct bnx2fc_percpu_s *p;
2159 struct task_struct *thread;
2160
2161 p = &per_cpu(bnx2fc_percpu, cpu);
2162
2163 thread = kthread_create(bnx2fc_percpu_io_thread,
2164 (void *)p,
2165 "bnx2fc_thread/%d", cpu);
2166 /* bind thread to the cpu */
Bhanu Prakash Gollapudi32248762011-08-04 17:38:36 -07002167 if (likely(!IS_ERR(thread))) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002168 kthread_bind(thread, cpu);
2169 p->iothread = thread;
2170 wake_up_process(thread);
2171 }
2172}
2173
2174static void bnx2fc_percpu_thread_destroy(unsigned int cpu)
2175{
2176 struct bnx2fc_percpu_s *p;
2177 struct task_struct *thread;
2178 struct bnx2fc_work *work, *tmp;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002179
2180 BNX2FC_MISC_DBG("destroying io thread for CPU %d\n", cpu);
2181
2182 /* Prevent any new work from being queued for this CPU */
2183 p = &per_cpu(bnx2fc_percpu, cpu);
2184 spin_lock_bh(&p->fp_work_lock);
2185 thread = p->iothread;
2186 p->iothread = NULL;
2187
2188
2189 /* Free all work in the list */
Bhanu Prakash Gollapudi32248762011-08-04 17:38:36 -07002190 list_for_each_entry_safe(work, tmp, &p->work_list, list) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002191 list_del_init(&work->list);
2192 bnx2fc_process_cq_compl(work->tgt, work->wqe);
2193 kfree(work);
2194 }
2195
2196 spin_unlock_bh(&p->fp_work_lock);
2197
2198 if (thread)
2199 kthread_stop(thread);
2200}
2201
2202/**
2203 * bnx2fc_cpu_callback - Handler for CPU hotplug events
2204 *
2205 * @nfb: The callback data block
2206 * @action: The event triggering the callback
2207 * @hcpu: The index of the CPU that the event is for
2208 *
2209 * This creates or destroys per-CPU data for fcoe
2210 *
2211 * Returns NOTIFY_OK always.
2212 */
2213static int bnx2fc_cpu_callback(struct notifier_block *nfb,
2214 unsigned long action, void *hcpu)
2215{
2216 unsigned cpu = (unsigned long)hcpu;
2217
2218 switch (action) {
2219 case CPU_ONLINE:
2220 case CPU_ONLINE_FROZEN:
2221 printk(PFX "CPU %x online: Create Rx thread\n", cpu);
2222 bnx2fc_percpu_thread_create(cpu);
2223 break;
2224 case CPU_DEAD:
2225 case CPU_DEAD_FROZEN:
2226 printk(PFX "CPU %x offline: Remove Rx thread\n", cpu);
2227 bnx2fc_percpu_thread_destroy(cpu);
2228 break;
2229 default:
2230 break;
2231 }
2232 return NOTIFY_OK;
2233}
2234
2235/**
2236 * bnx2fc_mod_init - module init entry point
2237 *
2238 * Initialize driver wide global data structures, and register
2239 * with cnic module
2240 **/
2241static int __init bnx2fc_mod_init(void)
2242{
2243 struct fcoe_percpu_s *bg;
2244 struct task_struct *l2_thread;
2245 int rc = 0;
2246 unsigned int cpu = 0;
2247 struct bnx2fc_percpu_s *p;
2248
2249 printk(KERN_INFO PFX "%s", version);
2250
2251 /* register as a fcoe transport */
2252 rc = fcoe_transport_attach(&bnx2fc_transport);
2253 if (rc) {
2254 printk(KERN_ERR "failed to register an fcoe transport, check "
2255 "if libfcoe is loaded\n");
2256 goto out;
2257 }
2258
2259 INIT_LIST_HEAD(&adapter_list);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002260 INIT_LIST_HEAD(&if_list);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002261 mutex_init(&bnx2fc_dev_lock);
2262 adapter_count = 0;
2263
2264 /* Attach FC transport template */
2265 rc = bnx2fc_attach_transport();
2266 if (rc)
2267 goto detach_ft;
2268
2269 bnx2fc_wq = alloc_workqueue("bnx2fc", 0, 0);
2270 if (!bnx2fc_wq) {
2271 rc = -ENOMEM;
2272 goto release_bt;
2273 }
2274
2275 bg = &bnx2fc_global;
2276 skb_queue_head_init(&bg->fcoe_rx_list);
2277 l2_thread = kthread_create(bnx2fc_l2_rcv_thread,
2278 (void *)bg,
2279 "bnx2fc_l2_thread");
2280 if (IS_ERR(l2_thread)) {
2281 rc = PTR_ERR(l2_thread);
2282 goto free_wq;
2283 }
2284 wake_up_process(l2_thread);
2285 spin_lock_bh(&bg->fcoe_rx_list.lock);
2286 bg->thread = l2_thread;
2287 spin_unlock_bh(&bg->fcoe_rx_list.lock);
2288
2289 for_each_possible_cpu(cpu) {
2290 p = &per_cpu(bnx2fc_percpu, cpu);
2291 INIT_LIST_HEAD(&p->work_list);
2292 spin_lock_init(&p->fp_work_lock);
2293 }
2294
2295 for_each_online_cpu(cpu) {
2296 bnx2fc_percpu_thread_create(cpu);
2297 }
2298
2299 /* Initialize per CPU interrupt thread */
2300 register_hotcpu_notifier(&bnx2fc_cpu_notifier);
2301
2302 cnic_register_driver(CNIC_ULP_FCOE, &bnx2fc_cnic_cb);
2303
2304 return 0;
2305
2306free_wq:
2307 destroy_workqueue(bnx2fc_wq);
2308release_bt:
2309 bnx2fc_release_transport();
2310detach_ft:
2311 fcoe_transport_detach(&bnx2fc_transport);
2312out:
2313 return rc;
2314}
2315
2316static void __exit bnx2fc_mod_exit(void)
2317{
2318 LIST_HEAD(to_be_deleted);
2319 struct bnx2fc_hba *hba, *next;
2320 struct fcoe_percpu_s *bg;
2321 struct task_struct *l2_thread;
2322 struct sk_buff *skb;
2323 unsigned int cpu = 0;
2324
2325 /*
2326 * NOTE: Since cnic calls register_driver routine rtnl_lock,
2327 * it will have higher precedence than bnx2fc_dev_lock.
2328 * unregister_device() cannot be called with bnx2fc_dev_lock
2329 * held.
2330 */
2331 mutex_lock(&bnx2fc_dev_lock);
2332 list_splice(&adapter_list, &to_be_deleted);
2333 INIT_LIST_HEAD(&adapter_list);
2334 adapter_count = 0;
2335 mutex_unlock(&bnx2fc_dev_lock);
2336
2337 /* Unregister with cnic */
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002338 list_for_each_entry_safe(hba, next, &to_be_deleted, list) {
2339 list_del_init(&hba->list);
2340 printk(KERN_ERR PFX "MOD_EXIT:destroy hba = 0x%p\n",
2341 hba);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002342 bnx2fc_ulp_stop(hba);
2343 /* unregister cnic device */
2344 if (test_and_clear_bit(BNX2FC_CNIC_REGISTERED,
2345 &hba->reg_with_cnic))
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002346 hba->cnic->unregister_device(hba->cnic,
2347 CNIC_ULP_FCOE);
2348 bnx2fc_hba_destroy(hba);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002349 }
2350 cnic_unregister_driver(CNIC_ULP_FCOE);
2351
2352 /* Destroy global thread */
2353 bg = &bnx2fc_global;
2354 spin_lock_bh(&bg->fcoe_rx_list.lock);
2355 l2_thread = bg->thread;
2356 bg->thread = NULL;
2357 while ((skb = __skb_dequeue(&bg->fcoe_rx_list)) != NULL)
2358 kfree_skb(skb);
2359
2360 spin_unlock_bh(&bg->fcoe_rx_list.lock);
2361
2362 if (l2_thread)
2363 kthread_stop(l2_thread);
2364
2365 unregister_hotcpu_notifier(&bnx2fc_cpu_notifier);
2366
2367 /* Destroy per cpu threads */
2368 for_each_online_cpu(cpu) {
2369 bnx2fc_percpu_thread_destroy(cpu);
2370 }
2371
2372 destroy_workqueue(bnx2fc_wq);
2373 /*
2374 * detach from scsi transport
2375 * must happen after all destroys are done
2376 */
2377 bnx2fc_release_transport();
2378
2379 /* detach from fcoe transport */
2380 fcoe_transport_detach(&bnx2fc_transport);
2381}
2382
2383module_init(bnx2fc_mod_init);
2384module_exit(bnx2fc_mod_exit);
2385
2386static struct fc_function_template bnx2fc_transport_function = {
2387 .show_host_node_name = 1,
2388 .show_host_port_name = 1,
2389 .show_host_supported_classes = 1,
2390 .show_host_supported_fc4s = 1,
2391 .show_host_active_fc4s = 1,
2392 .show_host_maxframe_size = 1,
2393
2394 .show_host_port_id = 1,
2395 .show_host_supported_speeds = 1,
2396 .get_host_speed = fc_get_host_speed,
2397 .show_host_speed = 1,
2398 .show_host_port_type = 1,
2399 .get_host_port_state = fc_get_host_port_state,
2400 .show_host_port_state = 1,
2401 .show_host_symbolic_name = 1,
2402
2403 .dd_fcrport_size = (sizeof(struct fc_rport_libfc_priv) +
2404 sizeof(struct bnx2fc_rport)),
2405 .show_rport_maxframe_size = 1,
2406 .show_rport_supported_classes = 1,
2407
2408 .show_host_fabric_name = 1,
2409 .show_starget_node_name = 1,
2410 .show_starget_port_name = 1,
2411 .show_starget_port_id = 1,
2412 .set_rport_dev_loss_tmo = fc_set_rport_loss_tmo,
2413 .show_rport_dev_loss_tmo = 1,
2414 .get_fc_host_stats = bnx2fc_get_host_stats,
2415
2416 .issue_fc_host_lip = bnx2fc_fcoe_reset,
2417
2418 .terminate_rport_io = fc_rport_terminate_io,
2419
2420 .vport_create = bnx2fc_vport_create,
2421 .vport_delete = bnx2fc_vport_destroy,
2422 .vport_disable = bnx2fc_vport_disable,
Bhanu Prakash Gollapudie9a5289c2011-08-04 17:38:37 -07002423 .bsg_request = fc_lport_bsg_request,
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002424};
2425
2426static struct fc_function_template bnx2fc_vport_xport_function = {
2427 .show_host_node_name = 1,
2428 .show_host_port_name = 1,
2429 .show_host_supported_classes = 1,
2430 .show_host_supported_fc4s = 1,
2431 .show_host_active_fc4s = 1,
2432 .show_host_maxframe_size = 1,
2433
2434 .show_host_port_id = 1,
2435 .show_host_supported_speeds = 1,
2436 .get_host_speed = fc_get_host_speed,
2437 .show_host_speed = 1,
2438 .show_host_port_type = 1,
2439 .get_host_port_state = fc_get_host_port_state,
2440 .show_host_port_state = 1,
2441 .show_host_symbolic_name = 1,
2442
2443 .dd_fcrport_size = (sizeof(struct fc_rport_libfc_priv) +
2444 sizeof(struct bnx2fc_rport)),
2445 .show_rport_maxframe_size = 1,
2446 .show_rport_supported_classes = 1,
2447
2448 .show_host_fabric_name = 1,
2449 .show_starget_node_name = 1,
2450 .show_starget_port_name = 1,
2451 .show_starget_port_id = 1,
2452 .set_rport_dev_loss_tmo = fc_set_rport_loss_tmo,
2453 .show_rport_dev_loss_tmo = 1,
2454 .get_fc_host_stats = fc_get_host_stats,
2455 .issue_fc_host_lip = bnx2fc_fcoe_reset,
2456 .terminate_rport_io = fc_rport_terminate_io,
Bhanu Prakash Gollapudie9a5289c2011-08-04 17:38:37 -07002457 .bsg_request = fc_lport_bsg_request,
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002458};
2459
2460/**
2461 * scsi_host_template structure used while registering with SCSI-ml
2462 */
2463static struct scsi_host_template bnx2fc_shost_template = {
2464 .module = THIS_MODULE,
2465 .name = "Broadcom Offload FCoE Initiator",
2466 .queuecommand = bnx2fc_queuecommand,
2467 .eh_abort_handler = bnx2fc_eh_abort, /* abts */
2468 .eh_device_reset_handler = bnx2fc_eh_device_reset, /* lun reset */
2469 .eh_target_reset_handler = bnx2fc_eh_target_reset, /* tgt reset */
2470 .eh_host_reset_handler = fc_eh_host_reset,
2471 .slave_alloc = fc_slave_alloc,
2472 .change_queue_depth = fc_change_queue_depth,
2473 .change_queue_type = fc_change_queue_type,
2474 .this_id = -1,
2475 .cmd_per_lun = 3,
Bhanu Gollapudi0ea5c272011-03-17 17:13:29 -07002476 .can_queue = BNX2FC_CAN_QUEUE,
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002477 .use_clustering = ENABLE_CLUSTERING,
2478 .sg_tablesize = BNX2FC_MAX_BDS_PER_CMD,
2479 .max_sectors = 512,
2480};
2481
2482static struct libfc_function_template bnx2fc_libfc_fcn_templ = {
2483 .frame_send = bnx2fc_xmit,
2484 .elsct_send = bnx2fc_elsct_send,
2485 .fcp_abort_io = bnx2fc_abort_io,
2486 .fcp_cleanup = bnx2fc_cleanup,
2487 .rport_event_callback = bnx2fc_rport_event_handler,
2488};
2489
2490/**
2491 * bnx2fc_cnic_cb - global template of bnx2fc - cnic driver interface
2492 * structure carrying callback function pointers
2493 */
2494static struct cnic_ulp_ops bnx2fc_cnic_cb = {
2495 .owner = THIS_MODULE,
2496 .cnic_init = bnx2fc_ulp_init,
2497 .cnic_exit = bnx2fc_ulp_exit,
2498 .cnic_start = bnx2fc_ulp_start,
2499 .cnic_stop = bnx2fc_ulp_stop,
2500 .indicate_kcqes = bnx2fc_indicate_kcqe,
2501 .indicate_netevent = bnx2fc_indicate_netevent,
2502};