blob: 9b9ccc94e7ae3646a81f9b3294a78166614d99a6 [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 Gollapudieb47aa2c2012-06-07 02:19:37 -070025#define DRV_MODULE_RELDATE "Jun 04, 2012"
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;
Robert Love8d55e502012-05-22 19:06:26 -070057static struct fcoe_sysfs_function_template bnx2fc_fcoe_sysfs_templ;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -080058static struct fc_function_template bnx2fc_vport_xport_function;
59static int bnx2fc_create(struct net_device *netdev, enum fip_state fip_mode);
Bhanu Prakash Gollapudieccdcd02011-08-24 18:56:42 -070060static void __bnx2fc_destroy(struct bnx2fc_interface *interface);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -080061static int bnx2fc_destroy(struct net_device *net_device);
62static int bnx2fc_enable(struct net_device *netdev);
63static int bnx2fc_disable(struct net_device *netdev);
64
Robert Love6e89ea32012-11-27 06:53:40 +000065/* fcoe_syfs control interface handlers */
66static int bnx2fc_ctlr_alloc(struct net_device *netdev);
67static int bnx2fc_ctlr_enabled(struct fcoe_ctlr_device *cdev);
68
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -080069static void bnx2fc_recv_frame(struct sk_buff *skb);
70
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -070071static void bnx2fc_start_disc(struct bnx2fc_interface *interface);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -080072static int bnx2fc_shost_config(struct fc_lport *lport, struct device *dev);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -080073static int bnx2fc_lport_config(struct fc_lport *lport);
74static int bnx2fc_em_config(struct fc_lport *lport);
75static int bnx2fc_bind_adapter_devices(struct bnx2fc_hba *hba);
76static void bnx2fc_unbind_adapter_devices(struct bnx2fc_hba *hba);
77static int bnx2fc_bind_pcidev(struct bnx2fc_hba *hba);
78static void bnx2fc_unbind_pcidev(struct bnx2fc_hba *hba);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -070079static struct fc_lport *bnx2fc_if_create(struct bnx2fc_interface *interface,
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -080080 struct device *parent, int npiv);
81static void bnx2fc_destroy_work(struct work_struct *work);
82
83static struct bnx2fc_hba *bnx2fc_hba_lookup(struct net_device *phys_dev);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -070084static struct bnx2fc_interface *bnx2fc_interface_lookup(struct net_device
85 *phys_dev);
Bhanu Prakash Gollapudiabc49a92011-08-04 17:38:42 -070086static inline void bnx2fc_interface_put(struct bnx2fc_interface *interface);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -080087static struct bnx2fc_hba *bnx2fc_find_hba_for_cnic(struct cnic_dev *cnic);
88
89static int bnx2fc_fw_init(struct bnx2fc_hba *hba);
90static void bnx2fc_fw_destroy(struct bnx2fc_hba *hba);
91
92static void bnx2fc_port_shutdown(struct fc_lport *lport);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -070093static void bnx2fc_stop(struct bnx2fc_interface *interface);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -080094static int __init bnx2fc_mod_init(void);
95static void __exit bnx2fc_mod_exit(void);
Robert Love8d55e502012-05-22 19:06:26 -070096static void bnx2fc_ctlr_get_lesb(struct fcoe_ctlr_device *ctlr_dev);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -080097
98unsigned int bnx2fc_debug_level;
99module_param_named(debug_logging, bnx2fc_debug_level, int, S_IRUGO|S_IWUSR);
100
101static int bnx2fc_cpu_callback(struct notifier_block *nfb,
102 unsigned long action, void *hcpu);
103/* notification function for CPU hotplug events */
104static struct notifier_block bnx2fc_cpu_notifier = {
105 .notifier_call = bnx2fc_cpu_callback,
106};
107
Bhanu Prakash Gollapudif72f6972011-10-03 16:45:02 -0700108static inline struct net_device *bnx2fc_netdev(const struct fc_lport *lport)
109{
110 return ((struct bnx2fc_interface *)
111 ((struct fcoe_port *)lport_priv(lport))->priv)->netdev;
112}
113
114/**
115 * bnx2fc_get_lesb() - Fill the FCoE Link Error Status Block
116 * @lport: the local port
117 * @fc_lesb: the link error status block
118 */
119static void bnx2fc_get_lesb(struct fc_lport *lport,
120 struct fc_els_lesb *fc_lesb)
121{
Yi Zouc3d79092012-12-06 06:24:29 +0000122 struct net_device *netdev = fcoe_get_netdev(lport);
Bhanu Prakash Gollapudif72f6972011-10-03 16:45:02 -0700123
124 __fcoe_get_lesb(lport, fc_lesb, netdev);
125}
126
Robert Love8d55e502012-05-22 19:06:26 -0700127static void bnx2fc_ctlr_get_lesb(struct fcoe_ctlr_device *ctlr_dev)
128{
129 struct fcoe_ctlr *fip = fcoe_ctlr_device_priv(ctlr_dev);
Yi Zouc3d79092012-12-06 06:24:29 +0000130 struct net_device *netdev = fcoe_get_netdev(fip->lp);
Robert Love8d55e502012-05-22 19:06:26 -0700131 struct fcoe_fc_els_lesb *fcoe_lesb;
132 struct fc_els_lesb fc_lesb;
133
134 __fcoe_get_lesb(fip->lp, &fc_lesb, netdev);
135 fcoe_lesb = (struct fcoe_fc_els_lesb *)(&fc_lesb);
136
137 ctlr_dev->lesb.lesb_link_fail =
138 ntohl(fcoe_lesb->lesb_link_fail);
139 ctlr_dev->lesb.lesb_vlink_fail =
140 ntohl(fcoe_lesb->lesb_vlink_fail);
141 ctlr_dev->lesb.lesb_miss_fka =
142 ntohl(fcoe_lesb->lesb_miss_fka);
143 ctlr_dev->lesb.lesb_symb_err =
144 ntohl(fcoe_lesb->lesb_symb_err);
145 ctlr_dev->lesb.lesb_err_block =
146 ntohl(fcoe_lesb->lesb_err_block);
147 ctlr_dev->lesb.lesb_fcs_error =
148 ntohl(fcoe_lesb->lesb_fcs_error);
149}
150EXPORT_SYMBOL(bnx2fc_ctlr_get_lesb);
151
152static void bnx2fc_fcf_get_vlan_id(struct fcoe_fcf_device *fcf_dev)
153{
154 struct fcoe_ctlr_device *ctlr_dev =
155 fcoe_fcf_dev_to_ctlr_dev(fcf_dev);
156 struct fcoe_ctlr *ctlr = fcoe_ctlr_device_priv(ctlr_dev);
157 struct bnx2fc_interface *fcoe = fcoe_ctlr_priv(ctlr);
158
159 fcf_dev->vlan_id = fcoe->vlan_id;
160}
161
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800162static void bnx2fc_clean_rx_queue(struct fc_lport *lp)
163{
164 struct fcoe_percpu_s *bg;
165 struct fcoe_rcv_info *fr;
166 struct sk_buff_head *list;
167 struct sk_buff *skb, *next;
168 struct sk_buff *head;
169
170 bg = &bnx2fc_global;
171 spin_lock_bh(&bg->fcoe_rx_list.lock);
172 list = &bg->fcoe_rx_list;
173 head = list->next;
174 for (skb = head; skb != (struct sk_buff *)list;
175 skb = next) {
176 next = skb->next;
177 fr = fcoe_dev_from_skb(skb);
178 if (fr->fr_dev == lp) {
179 __skb_unlink(skb, list);
180 kfree_skb(skb);
181 }
182 }
183 spin_unlock_bh(&bg->fcoe_rx_list.lock);
184}
185
186int bnx2fc_get_paged_crc_eof(struct sk_buff *skb, int tlen)
187{
188 int rc;
189 spin_lock(&bnx2fc_global_lock);
190 rc = fcoe_get_paged_crc_eof(skb, tlen, &bnx2fc_global);
191 spin_unlock(&bnx2fc_global_lock);
192
193 return rc;
194}
195
196static void bnx2fc_abort_io(struct fc_lport *lport)
197{
198 /*
199 * This function is no-op for bnx2fc, but we do
200 * not want to leave it as NULL either, as libfc
201 * can call the default function which is
202 * fc_fcp_abort_io.
203 */
204}
205
206static void bnx2fc_cleanup(struct fc_lport *lport)
207{
208 struct fcoe_port *port = lport_priv(lport);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700209 struct bnx2fc_interface *interface = port->priv;
210 struct bnx2fc_hba *hba = interface->hba;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800211 struct bnx2fc_rport *tgt;
212 int i;
213
214 BNX2FC_MISC_DBG("Entered %s\n", __func__);
215 mutex_lock(&hba->hba_mutex);
216 spin_lock_bh(&hba->hba_lock);
217 for (i = 0; i < BNX2FC_NUM_MAX_SESS; i++) {
218 tgt = hba->tgt_ofld_list[i];
219 if (tgt) {
220 /* Cleanup IOs belonging to requested vport */
221 if (tgt->port == port) {
222 spin_unlock_bh(&hba->hba_lock);
223 BNX2FC_TGT_DBG(tgt, "flush/cleanup\n");
224 bnx2fc_flush_active_ios(tgt);
225 spin_lock_bh(&hba->hba_lock);
226 }
227 }
228 }
229 spin_unlock_bh(&hba->hba_lock);
230 mutex_unlock(&hba->hba_mutex);
231}
232
233static int bnx2fc_xmit_l2_frame(struct bnx2fc_rport *tgt,
234 struct fc_frame *fp)
235{
236 struct fc_rport_priv *rdata = tgt->rdata;
237 struct fc_frame_header *fh;
238 int rc = 0;
239
240 fh = fc_frame_header_get(fp);
241 BNX2FC_TGT_DBG(tgt, "Xmit L2 frame rport = 0x%x, oxid = 0x%x, "
242 "r_ctl = 0x%x\n", rdata->ids.port_id,
243 ntohs(fh->fh_ox_id), fh->fh_r_ctl);
244 if ((fh->fh_type == FC_TYPE_ELS) &&
245 (fh->fh_r_ctl == FC_RCTL_ELS_REQ)) {
246
247 switch (fc_frame_payload_op(fp)) {
248 case ELS_ADISC:
249 rc = bnx2fc_send_adisc(tgt, fp);
250 break;
251 case ELS_LOGO:
252 rc = bnx2fc_send_logo(tgt, fp);
253 break;
254 case ELS_RLS:
255 rc = bnx2fc_send_rls(tgt, fp);
256 break;
257 default:
258 break;
259 }
260 } else if ((fh->fh_type == FC_TYPE_BLS) &&
261 (fh->fh_r_ctl == FC_RCTL_BA_ABTS))
262 BNX2FC_TGT_DBG(tgt, "ABTS frame\n");
263 else {
264 BNX2FC_TGT_DBG(tgt, "Send L2 frame type 0x%x "
265 "rctl 0x%x thru non-offload path\n",
266 fh->fh_type, fh->fh_r_ctl);
267 return -ENODEV;
268 }
269 if (rc)
270 return -ENOMEM;
271 else
272 return 0;
273}
274
275/**
276 * bnx2fc_xmit - bnx2fc's FCoE frame transmit function
277 *
278 * @lport: the associated local port
279 * @fp: the fc_frame to be transmitted
280 */
281static int bnx2fc_xmit(struct fc_lport *lport, struct fc_frame *fp)
282{
283 struct ethhdr *eh;
284 struct fcoe_crc_eof *cp;
285 struct sk_buff *skb;
286 struct fc_frame_header *fh;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700287 struct bnx2fc_interface *interface;
Robert Lovefd8f8902012-05-22 19:06:16 -0700288 struct fcoe_ctlr *ctlr;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700289 struct bnx2fc_hba *hba;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800290 struct fcoe_port *port;
291 struct fcoe_hdr *hp;
292 struct bnx2fc_rport *tgt;
Vasu Dev1bd49b42012-05-25 10:26:43 -0700293 struct fc_stats *stats;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800294 u8 sof, eof;
295 u32 crc;
296 unsigned int hlen, tlen, elen;
297 int wlen, rc = 0;
298
299 port = (struct fcoe_port *)lport_priv(lport);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700300 interface = port->priv;
Robert Lovefd8f8902012-05-22 19:06:16 -0700301 ctlr = bnx2fc_to_ctlr(interface);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700302 hba = interface->hba;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800303
304 fh = fc_frame_header_get(fp);
305
306 skb = fp_skb(fp);
307 if (!lport->link_up) {
308 BNX2FC_HBA_DBG(lport, "bnx2fc_xmit link down\n");
309 kfree_skb(skb);
310 return 0;
311 }
312
313 if (unlikely(fh->fh_r_ctl == FC_RCTL_ELS_REQ)) {
Robert Lovefd8f8902012-05-22 19:06:16 -0700314 if (!ctlr->sel_fcf) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800315 BNX2FC_HBA_DBG(lport, "FCF not selected yet!\n");
316 kfree_skb(skb);
317 return -EINVAL;
318 }
Robert Lovefd8f8902012-05-22 19:06:16 -0700319 if (fcoe_ctlr_els_send(ctlr, lport, skb))
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800320 return 0;
321 }
322
323 sof = fr_sof(fp);
324 eof = fr_eof(fp);
325
326 /*
327 * Snoop the frame header to check if the frame is for
328 * an offloaded session
329 */
330 /*
331 * tgt_ofld_list access is synchronized using
332 * both hba mutex and hba lock. Atleast hba mutex or
333 * hba lock needs to be held for read access.
334 */
335
336 spin_lock_bh(&hba->hba_lock);
337 tgt = bnx2fc_tgt_lookup(port, ntoh24(fh->fh_d_id));
338 if (tgt && (test_bit(BNX2FC_FLAG_SESSION_READY, &tgt->flags))) {
339 /* This frame is for offloaded session */
340 BNX2FC_HBA_DBG(lport, "xmit: Frame is for offloaded session "
341 "port_id = 0x%x\n", ntoh24(fh->fh_d_id));
342 spin_unlock_bh(&hba->hba_lock);
343 rc = bnx2fc_xmit_l2_frame(tgt, fp);
344 if (rc != -ENODEV) {
345 kfree_skb(skb);
346 return rc;
347 }
348 } else {
349 spin_unlock_bh(&hba->hba_lock);
350 }
351
352 elen = sizeof(struct ethhdr);
353 hlen = sizeof(struct fcoe_hdr);
354 tlen = sizeof(struct fcoe_crc_eof);
355 wlen = (skb->len - tlen + sizeof(crc)) / FCOE_WORD_TO_BYTE;
356
357 skb->ip_summed = CHECKSUM_NONE;
358 crc = fcoe_fc_crc(fp);
359
360 /* copy port crc and eof to the skb buff */
361 if (skb_is_nonlinear(skb)) {
362 skb_frag_t *frag;
363 if (bnx2fc_get_paged_crc_eof(skb, tlen)) {
364 kfree_skb(skb);
365 return -ENOMEM;
366 }
367 frag = &skb_shinfo(skb)->frags[skb_shinfo(skb)->nr_frags - 1];
Cong Wang77dfce02011-11-25 23:14:23 +0800368 cp = kmap_atomic(skb_frag_page(frag)) + frag->page_offset;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800369 } else {
370 cp = (struct fcoe_crc_eof *)skb_put(skb, tlen);
371 }
372
373 memset(cp, 0, sizeof(*cp));
374 cp->fcoe_eof = eof;
375 cp->fcoe_crc32 = cpu_to_le32(~crc);
376 if (skb_is_nonlinear(skb)) {
Cong Wang77dfce02011-11-25 23:14:23 +0800377 kunmap_atomic(cp);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800378 cp = NULL;
379 }
380
381 /* adjust skb network/transport offsets to match mac/fcoe/port */
382 skb_push(skb, elen + hlen);
383 skb_reset_mac_header(skb);
384 skb_reset_network_header(skb);
385 skb->mac_len = elen;
386 skb->protocol = htons(ETH_P_FCOE);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700387 skb->dev = interface->netdev;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800388
389 /* fill up mac and fcoe headers */
390 eh = eth_hdr(skb);
391 eh->h_proto = htons(ETH_P_FCOE);
Robert Lovefd8f8902012-05-22 19:06:16 -0700392 if (ctlr->map_dest)
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800393 fc_fcoe_set_mac(eh->h_dest, fh->fh_d_id);
394 else
395 /* insert GW address */
Robert Lovefd8f8902012-05-22 19:06:16 -0700396 memcpy(eh->h_dest, ctlr->dest_addr, ETH_ALEN);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800397
Robert Lovefd8f8902012-05-22 19:06:16 -0700398 if (unlikely(ctlr->flogi_oxid != FC_XID_UNKNOWN))
399 memcpy(eh->h_source, ctlr->ctl_src_addr, ETH_ALEN);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800400 else
401 memcpy(eh->h_source, port->data_src_addr, ETH_ALEN);
402
403 hp = (struct fcoe_hdr *)(eh + 1);
404 memset(hp, 0, sizeof(*hp));
405 if (FC_FCOE_VER)
406 FC_FCOE_ENCAPS_VER(hp, FC_FCOE_VER);
407 hp->fcoe_sof = sof;
408
409 /* fcoe lso, mss is in max_payload which is non-zero for FCP data */
410 if (lport->seq_offload && fr_max_payload(fp)) {
411 skb_shinfo(skb)->gso_type = SKB_GSO_FCOE;
412 skb_shinfo(skb)->gso_size = fr_max_payload(fp);
413 } else {
414 skb_shinfo(skb)->gso_type = 0;
415 skb_shinfo(skb)->gso_size = 0;
416 }
417
418 /*update tx stats */
Vasu Dev1bd49b42012-05-25 10:26:43 -0700419 stats = per_cpu_ptr(lport->stats, get_cpu());
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800420 stats->TxFrames++;
421 stats->TxWords += wlen;
422 put_cpu();
423
424 /* send down to lld */
425 fr_dev(fp) = lport;
426 if (port->fcoe_pending_queue.qlen)
427 fcoe_check_wait_queue(lport, skb);
428 else if (fcoe_start_io(skb))
429 fcoe_check_wait_queue(lport, skb);
430
431 return 0;
432}
433
434/**
435 * bnx2fc_rcv - This is bnx2fc's receive function called by NET_RX_SOFTIRQ
436 *
437 * @skb: the receive socket buffer
438 * @dev: associated net device
439 * @ptype: context
440 * @olddev: last device
441 *
442 * This function receives the packet and builds FC frame and passes it up
443 */
444static int bnx2fc_rcv(struct sk_buff *skb, struct net_device *dev,
445 struct packet_type *ptype, struct net_device *olddev)
446{
447 struct fc_lport *lport;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700448 struct bnx2fc_interface *interface;
Robert Lovefd8f8902012-05-22 19:06:16 -0700449 struct fcoe_ctlr *ctlr;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800450 struct fc_frame_header *fh;
451 struct fcoe_rcv_info *fr;
452 struct fcoe_percpu_s *bg;
453 unsigned short oxid;
454
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700455 interface = container_of(ptype, struct bnx2fc_interface,
456 fcoe_packet_type);
Robert Lovefd8f8902012-05-22 19:06:16 -0700457 ctlr = bnx2fc_to_ctlr(interface);
458 lport = ctlr->lp;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800459
460 if (unlikely(lport == NULL)) {
Bhanu Prakash Gollapudib2a554f2011-06-27 23:30:53 -0700461 printk(KERN_ERR PFX "bnx2fc_rcv: lport is NULL\n");
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800462 goto err;
463 }
464
465 if (unlikely(eth_hdr(skb)->h_proto != htons(ETH_P_FCOE))) {
Bhanu Prakash Gollapudib2a554f2011-06-27 23:30:53 -0700466 printk(KERN_ERR PFX "bnx2fc_rcv: Wrong FC type frame\n");
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800467 goto err;
468 }
469
470 /*
471 * Check for minimum frame length, and make sure required FCoE
472 * and FC headers are pulled into the linear data area.
473 */
474 if (unlikely((skb->len < FCOE_MIN_FRAME) ||
475 !pskb_may_pull(skb, FCOE_HEADER_LEN)))
476 goto err;
477
478 skb_set_transport_header(skb, sizeof(struct fcoe_hdr));
479 fh = (struct fc_frame_header *) skb_transport_header(skb);
480
481 oxid = ntohs(fh->fh_ox_id);
482
483 fr = fcoe_dev_from_skb(skb);
484 fr->fr_dev = lport;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800485
486 bg = &bnx2fc_global;
Neil Hormanfc05ab72012-03-09 14:50:13 -0800487 spin_lock(&bg->fcoe_rx_list.lock);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800488
489 __skb_queue_tail(&bg->fcoe_rx_list, skb);
490 if (bg->fcoe_rx_list.qlen == 1)
491 wake_up_process(bg->thread);
492
Neil Hormanfc05ab72012-03-09 14:50:13 -0800493 spin_unlock(&bg->fcoe_rx_list.lock);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800494
495 return 0;
496err:
497 kfree_skb(skb);
498 return -1;
499}
500
501static int bnx2fc_l2_rcv_thread(void *arg)
502{
503 struct fcoe_percpu_s *bg = arg;
504 struct sk_buff *skb;
505
506 set_user_nice(current, -20);
507 set_current_state(TASK_INTERRUPTIBLE);
508 while (!kthread_should_stop()) {
509 schedule();
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800510 spin_lock_bh(&bg->fcoe_rx_list.lock);
511 while ((skb = __skb_dequeue(&bg->fcoe_rx_list)) != NULL) {
512 spin_unlock_bh(&bg->fcoe_rx_list.lock);
513 bnx2fc_recv_frame(skb);
514 spin_lock_bh(&bg->fcoe_rx_list.lock);
515 }
Bhanu Gollapudifee78712011-03-21 18:51:13 -0700516 __set_current_state(TASK_INTERRUPTIBLE);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800517 spin_unlock_bh(&bg->fcoe_rx_list.lock);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800518 }
Bhanu Gollapudifee78712011-03-21 18:51:13 -0700519 __set_current_state(TASK_RUNNING);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800520 return 0;
521}
522
523
524static void bnx2fc_recv_frame(struct sk_buff *skb)
525{
526 u32 fr_len;
527 struct fc_lport *lport;
528 struct fcoe_rcv_info *fr;
Vasu Dev1bd49b42012-05-25 10:26:43 -0700529 struct fc_stats *stats;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800530 struct fc_frame_header *fh;
531 struct fcoe_crc_eof crc_eof;
532 struct fc_frame *fp;
533 struct fc_lport *vn_port;
534 struct fcoe_port *port;
535 u8 *mac = NULL;
536 u8 *dest_mac = NULL;
537 struct fcoe_hdr *hp;
538
539 fr = fcoe_dev_from_skb(skb);
540 lport = fr->fr_dev;
541 if (unlikely(lport == NULL)) {
Bhanu Prakash Gollapudib2a554f2011-06-27 23:30:53 -0700542 printk(KERN_ERR PFX "Invalid lport struct\n");
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800543 kfree_skb(skb);
544 return;
545 }
546
547 if (skb_is_nonlinear(skb))
548 skb_linearize(skb);
549 mac = eth_hdr(skb)->h_source;
550 dest_mac = eth_hdr(skb)->h_dest;
551
552 /* Pull the header */
553 hp = (struct fcoe_hdr *) skb_network_header(skb);
554 fh = (struct fc_frame_header *) skb_transport_header(skb);
555 skb_pull(skb, sizeof(struct fcoe_hdr));
556 fr_len = skb->len - sizeof(struct fcoe_crc_eof);
557
Vasu Dev1bd49b42012-05-25 10:26:43 -0700558 stats = per_cpu_ptr(lport->stats, get_cpu());
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800559 stats->RxFrames++;
560 stats->RxWords += fr_len / FCOE_WORD_TO_BYTE;
561
562 fp = (struct fc_frame *)skb;
563 fc_frame_init(fp);
564 fr_dev(fp) = lport;
565 fr_sof(fp) = hp->fcoe_sof;
566 if (skb_copy_bits(skb, fr_len, &crc_eof, sizeof(crc_eof))) {
567 put_cpu();
568 kfree_skb(skb);
569 return;
570 }
571 fr_eof(fp) = crc_eof.fcoe_eof;
572 fr_crc(fp) = crc_eof.fcoe_crc32;
573 if (pskb_trim(skb, fr_len)) {
574 put_cpu();
575 kfree_skb(skb);
576 return;
577 }
578
579 fh = fc_frame_header_get(fp);
580
581 vn_port = fc_vport_id_lookup(lport, ntoh24(fh->fh_d_id));
582 if (vn_port) {
583 port = lport_priv(vn_port);
584 if (compare_ether_addr(port->data_src_addr, dest_mac)
585 != 0) {
586 BNX2FC_HBA_DBG(lport, "fpma mismatch\n");
587 put_cpu();
588 kfree_skb(skb);
589 return;
590 }
591 }
592 if (fh->fh_r_ctl == FC_RCTL_DD_SOL_DATA &&
593 fh->fh_type == FC_TYPE_FCP) {
594 /* Drop FCP data. We dont this in L2 path */
595 put_cpu();
596 kfree_skb(skb);
597 return;
598 }
599 if (fh->fh_r_ctl == FC_RCTL_ELS_REQ &&
600 fh->fh_type == FC_TYPE_ELS) {
601 switch (fc_frame_payload_op(fp)) {
602 case ELS_LOGO:
603 if (ntoh24(fh->fh_s_id) == FC_FID_FLOGI) {
604 /* drop non-FIP LOGO */
605 put_cpu();
606 kfree_skb(skb);
607 return;
608 }
609 break;
610 }
611 }
Bhanu Prakash Gollapudi3f8744d2011-08-04 17:38:48 -0700612
613 if (fh->fh_r_ctl == FC_RCTL_BA_ABTS) {
614 /* Drop incoming ABTS */
615 put_cpu();
616 kfree_skb(skb);
617 return;
618 }
619
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800620 if (le32_to_cpu(fr_crc(fp)) !=
621 ~crc32(~0, skb->data, fr_len)) {
622 if (stats->InvalidCRCCount < 5)
623 printk(KERN_WARNING PFX "dropping frame with "
624 "CRC error\n");
625 stats->InvalidCRCCount++;
626 put_cpu();
627 kfree_skb(skb);
628 return;
629 }
630 put_cpu();
631 fc_exch_recv(lport, fp);
632}
633
634/**
635 * bnx2fc_percpu_io_thread - thread per cpu for ios
636 *
637 * @arg: ptr to bnx2fc_percpu_info structure
638 */
639int bnx2fc_percpu_io_thread(void *arg)
640{
641 struct bnx2fc_percpu_s *p = arg;
642 struct bnx2fc_work *work, *tmp;
643 LIST_HEAD(work_list);
644
645 set_user_nice(current, -20);
646 set_current_state(TASK_INTERRUPTIBLE);
647 while (!kthread_should_stop()) {
648 schedule();
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800649 spin_lock_bh(&p->fp_work_lock);
650 while (!list_empty(&p->work_list)) {
651 list_splice_init(&p->work_list, &work_list);
652 spin_unlock_bh(&p->fp_work_lock);
653
654 list_for_each_entry_safe(work, tmp, &work_list, list) {
655 list_del_init(&work->list);
656 bnx2fc_process_cq_compl(work->tgt, work->wqe);
657 kfree(work);
658 }
659
660 spin_lock_bh(&p->fp_work_lock);
661 }
Bhanu Gollapudifee78712011-03-21 18:51:13 -0700662 __set_current_state(TASK_INTERRUPTIBLE);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800663 spin_unlock_bh(&p->fp_work_lock);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800664 }
Bhanu Gollapudifee78712011-03-21 18:51:13 -0700665 __set_current_state(TASK_RUNNING);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800666
667 return 0;
668}
669
670static struct fc_host_statistics *bnx2fc_get_host_stats(struct Scsi_Host *shost)
671{
672 struct fc_host_statistics *bnx2fc_stats;
673 struct fc_lport *lport = shost_priv(shost);
674 struct fcoe_port *port = lport_priv(lport);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700675 struct bnx2fc_interface *interface = port->priv;
676 struct bnx2fc_hba *hba = interface->hba;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800677 struct fcoe_statistics_params *fw_stats;
678 int rc = 0;
679
680 fw_stats = (struct fcoe_statistics_params *)hba->stats_buffer;
681 if (!fw_stats)
682 return NULL;
683
684 bnx2fc_stats = fc_get_host_stats(shost);
685
686 init_completion(&hba->stat_req_done);
687 if (bnx2fc_send_stat_req(hba))
688 return bnx2fc_stats;
689 rc = wait_for_completion_timeout(&hba->stat_req_done, (2 * HZ));
690 if (!rc) {
691 BNX2FC_HBA_DBG(lport, "FW stat req timed out\n");
692 return bnx2fc_stats;
693 }
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300694 bnx2fc_stats->invalid_crc_count += fw_stats->rx_stat2.fc_crc_cnt;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800695 bnx2fc_stats->tx_frames += fw_stats->tx_stat.fcoe_tx_pkt_cnt;
696 bnx2fc_stats->tx_words += (fw_stats->tx_stat.fcoe_tx_byte_cnt) / 4;
697 bnx2fc_stats->rx_frames += fw_stats->rx_stat0.fcoe_rx_pkt_cnt;
698 bnx2fc_stats->rx_words += (fw_stats->rx_stat0.fcoe_rx_byte_cnt) / 4;
699
700 bnx2fc_stats->dumped_frames = 0;
701 bnx2fc_stats->lip_count = 0;
702 bnx2fc_stats->nos_count = 0;
703 bnx2fc_stats->loss_of_sync_count = 0;
704 bnx2fc_stats->loss_of_signal_count = 0;
705 bnx2fc_stats->prim_seq_protocol_err_count = 0;
706
707 return bnx2fc_stats;
708}
709
710static int bnx2fc_shost_config(struct fc_lport *lport, struct device *dev)
711{
712 struct fcoe_port *port = lport_priv(lport);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700713 struct bnx2fc_interface *interface = port->priv;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800714 struct Scsi_Host *shost = lport->host;
715 int rc = 0;
716
717 shost->max_cmd_len = BNX2FC_MAX_CMD_LEN;
718 shost->max_lun = BNX2FC_MAX_LUN;
719 shost->max_id = BNX2FC_MAX_FCP_TGT;
720 shost->max_channel = 0;
721 if (lport->vport)
722 shost->transportt = bnx2fc_vport_xport_template;
723 else
724 shost->transportt = bnx2fc_transport_template;
725
726 /* Add the new host to SCSI-ml */
727 rc = scsi_add_host(lport->host, dev);
728 if (rc) {
729 printk(KERN_ERR PFX "Error on scsi_add_host\n");
730 return rc;
731 }
732 if (!lport->vport)
733 fc_host_max_npiv_vports(lport->host) = USHRT_MAX;
734 sprintf(fc_host_symbolic_name(lport->host), "%s v%s over %s",
735 BNX2FC_NAME, BNX2FC_VERSION,
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700736 interface->netdev->name);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800737
738 return 0;
739}
740
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800741static void bnx2fc_link_speed_update(struct fc_lport *lport)
742{
743 struct fcoe_port *port = lport_priv(lport);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700744 struct bnx2fc_interface *interface = port->priv;
745 struct net_device *netdev = interface->netdev;
David Decotigny8ae6dac2011-04-27 18:32:38 +0000746 struct ethtool_cmd ecmd;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800747
Jiri Pirko4bc71cb2011-09-03 03:34:30 +0000748 if (!__ethtool_get_settings(netdev, &ecmd)) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800749 lport->link_supported_speeds &=
750 ~(FC_PORTSPEED_1GBIT | FC_PORTSPEED_10GBIT);
751 if (ecmd.supported & (SUPPORTED_1000baseT_Half |
752 SUPPORTED_1000baseT_Full))
753 lport->link_supported_speeds |= FC_PORTSPEED_1GBIT;
754 if (ecmd.supported & SUPPORTED_10000baseT_Full)
755 lport->link_supported_speeds |= FC_PORTSPEED_10GBIT;
756
David Decotigny8ae6dac2011-04-27 18:32:38 +0000757 switch (ethtool_cmd_speed(&ecmd)) {
758 case SPEED_1000:
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800759 lport->link_speed = FC_PORTSPEED_1GBIT;
David Decotigny8ae6dac2011-04-27 18:32:38 +0000760 break;
Bhanu Prakash Gollapudia4dc08c2011-05-27 11:47:25 -0700761 case SPEED_2500:
762 lport->link_speed = FC_PORTSPEED_2GBIT;
763 break;
David Decotigny8ae6dac2011-04-27 18:32:38 +0000764 case SPEED_10000:
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800765 lport->link_speed = FC_PORTSPEED_10GBIT;
David Decotigny8ae6dac2011-04-27 18:32:38 +0000766 break;
767 }
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800768 }
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800769}
770static int bnx2fc_link_ok(struct fc_lport *lport)
771{
772 struct fcoe_port *port = lport_priv(lport);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700773 struct bnx2fc_interface *interface = port->priv;
774 struct bnx2fc_hba *hba = interface->hba;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800775 struct net_device *dev = hba->phys_dev;
776 int rc = 0;
777
778 if ((dev->flags & IFF_UP) && netif_carrier_ok(dev))
779 clear_bit(ADAPTER_STATE_LINK_DOWN, &hba->adapter_state);
780 else {
781 set_bit(ADAPTER_STATE_LINK_DOWN, &hba->adapter_state);
782 rc = -1;
783 }
784 return rc;
785}
786
787/**
788 * bnx2fc_get_link_state - get network link state
789 *
790 * @hba: adapter instance pointer
791 *
792 * updates adapter structure flag based on netdev state
793 */
794void bnx2fc_get_link_state(struct bnx2fc_hba *hba)
795{
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700796 if (test_bit(__LINK_STATE_NOCARRIER, &hba->phys_dev->state))
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800797 set_bit(ADAPTER_STATE_LINK_DOWN, &hba->adapter_state);
798 else
799 clear_bit(ADAPTER_STATE_LINK_DOWN, &hba->adapter_state);
800}
801
Bhanu Prakash Gollapudi52439602011-08-04 17:38:50 -0700802static int bnx2fc_net_config(struct fc_lport *lport, struct net_device *netdev)
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800803{
804 struct bnx2fc_hba *hba;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700805 struct bnx2fc_interface *interface;
Robert Lovefd8f8902012-05-22 19:06:16 -0700806 struct fcoe_ctlr *ctlr;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800807 struct fcoe_port *port;
808 u64 wwnn, wwpn;
809
810 port = lport_priv(lport);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700811 interface = port->priv;
Robert Lovefd8f8902012-05-22 19:06:16 -0700812 ctlr = bnx2fc_to_ctlr(interface);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700813 hba = interface->hba;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800814
815 /* require support for get_pauseparam ethtool op. */
816 if (!hba->phys_dev->ethtool_ops ||
817 !hba->phys_dev->ethtool_ops->get_pauseparam)
818 return -EOPNOTSUPP;
819
Bhanu Gollapudi1294bfe2011-03-17 17:13:34 -0700820 if (fc_set_mfs(lport, BNX2FC_MFS))
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800821 return -EINVAL;
822
823 skb_queue_head_init(&port->fcoe_pending_queue);
824 port->fcoe_pending_queue_active = 0;
825 setup_timer(&port->timer, fcoe_queue_timer, (unsigned long) lport);
826
827 bnx2fc_link_speed_update(lport);
828
829 if (!lport->vport) {
Bhanu Prakash Gollapudi52439602011-08-04 17:38:50 -0700830 if (fcoe_get_wwn(netdev, &wwnn, NETDEV_FCOE_WWNN))
Robert Lovefd8f8902012-05-22 19:06:16 -0700831 wwnn = fcoe_wwn_from_mac(ctlr->ctl_src_addr,
Bhanu Prakash Gollapudi52439602011-08-04 17:38:50 -0700832 1, 0);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800833 BNX2FC_HBA_DBG(lport, "WWNN = 0x%llx\n", wwnn);
834 fc_set_wwnn(lport, wwnn);
835
Bhanu Prakash Gollapudi52439602011-08-04 17:38:50 -0700836 if (fcoe_get_wwn(netdev, &wwpn, NETDEV_FCOE_WWPN))
Robert Lovefd8f8902012-05-22 19:06:16 -0700837 wwpn = fcoe_wwn_from_mac(ctlr->ctl_src_addr,
Bhanu Prakash Gollapudi52439602011-08-04 17:38:50 -0700838 2, 0);
839
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800840 BNX2FC_HBA_DBG(lport, "WWPN = 0x%llx\n", wwpn);
841 fc_set_wwpn(lport, wwpn);
842 }
843
844 return 0;
845}
846
847static void bnx2fc_destroy_timer(unsigned long data)
848{
849 struct bnx2fc_hba *hba = (struct bnx2fc_hba *)data;
850
Bhanu Prakash Gollapudicd703ae2011-08-04 17:38:43 -0700851 printk(KERN_ERR PFX "ERROR:bnx2fc_destroy_timer - "
852 "Destroy compl not received!!\n");
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700853 set_bit(BNX2FC_FLAG_DESTROY_CMPL, &hba->flags);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800854 wake_up_interruptible(&hba->destroy_wait);
855}
856
857/**
858 * bnx2fc_indicate_netevent - Generic netdev event handler
859 *
860 * @context: adapter structure pointer
861 * @event: event type
Michael Chan415199f2011-07-20 14:55:24 +0000862 * @vlan_id: vlan id - associated vlan id with this event
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800863 *
864 * Handles NETDEV_UP, NETDEV_DOWN, NETDEV_GOING_DOWN,NETDEV_CHANGE and
Bhanu Prakash Gollapudiabc49a92011-08-04 17:38:42 -0700865 * NETDEV_CHANGE_MTU events. Handle NETDEV_UNREGISTER only for vlans.
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800866 */
Michael Chan415199f2011-07-20 14:55:24 +0000867static void bnx2fc_indicate_netevent(void *context, unsigned long event,
868 u16 vlan_id)
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800869{
870 struct bnx2fc_hba *hba = (struct bnx2fc_hba *)context;
Robert Love6e89ea32012-11-27 06:53:40 +0000871 struct fcoe_ctlr_device *cdev;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700872 struct fc_lport *lport;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800873 struct fc_lport *vport;
Bhanu Prakash Gollapudiabc49a92011-08-04 17:38:42 -0700874 struct bnx2fc_interface *interface, *tmp;
Robert Lovefd8f8902012-05-22 19:06:16 -0700875 struct fcoe_ctlr *ctlr;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700876 int wait_for_upload = 0;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800877 u32 link_possible = 1;
878
Bhanu Prakash Gollapudiabc49a92011-08-04 17:38:42 -0700879 if (vlan_id != 0 && event != NETDEV_UNREGISTER)
Michael Chan415199f2011-07-20 14:55:24 +0000880 return;
881
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800882 switch (event) {
883 case NETDEV_UP:
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800884 if (!test_bit(ADAPTER_STATE_UP, &hba->adapter_state))
885 printk(KERN_ERR "indicate_netevent: "\
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700886 "hba is not UP!!\n");
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800887 break;
888
889 case NETDEV_DOWN:
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800890 clear_bit(ADAPTER_STATE_GOING_DOWN, &hba->adapter_state);
891 clear_bit(ADAPTER_STATE_UP, &hba->adapter_state);
892 link_possible = 0;
893 break;
894
895 case NETDEV_GOING_DOWN:
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800896 set_bit(ADAPTER_STATE_GOING_DOWN, &hba->adapter_state);
897 link_possible = 0;
898 break;
899
900 case NETDEV_CHANGE:
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800901 break;
902
Bhanu Prakash Gollapudiabc49a92011-08-04 17:38:42 -0700903 case NETDEV_UNREGISTER:
904 if (!vlan_id)
905 return;
906 mutex_lock(&bnx2fc_dev_lock);
907 list_for_each_entry_safe(interface, tmp, &if_list, list) {
Nithin Nayak Sujir26b29822011-08-30 15:54:50 -0700908 if (interface->hba == hba &&
909 interface->vlan_id == (vlan_id & VLAN_VID_MASK))
910 __bnx2fc_destroy(interface);
Bhanu Prakash Gollapudiabc49a92011-08-04 17:38:42 -0700911 }
912 mutex_unlock(&bnx2fc_dev_lock);
913 return;
914
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800915 default:
Masanari Iida59e13d42012-04-25 00:24:16 +0900916 printk(KERN_ERR PFX "Unknown netevent %ld", event);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800917 return;
918 }
919
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700920 mutex_lock(&bnx2fc_dev_lock);
921 list_for_each_entry(interface, &if_list, list) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800922
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700923 if (interface->hba != hba)
924 continue;
925
Robert Lovefd8f8902012-05-22 19:06:16 -0700926 ctlr = bnx2fc_to_ctlr(interface);
927 lport = ctlr->lp;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700928 BNX2FC_HBA_DBG(lport, "netevent handler - event=%s %ld\n",
929 interface->netdev->name, event);
930
931 bnx2fc_link_speed_update(lport);
932
Robert Love6e89ea32012-11-27 06:53:40 +0000933 cdev = fcoe_ctlr_to_ctlr_dev(ctlr);
934
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700935 if (link_possible && !bnx2fc_link_ok(lport)) {
Robert Love6e89ea32012-11-27 06:53:40 +0000936 switch (cdev->enabled) {
937 case FCOE_CTLR_DISABLED:
938 pr_info("Link up while interface is disabled.\n");
939 break;
940 case FCOE_CTLR_ENABLED:
941 case FCOE_CTLR_UNUSED:
942 /* Reset max recv frame size to default */
943 fc_set_mfs(lport, BNX2FC_MFS);
944 /*
945 * ctlr link up will only be handled during
946 * enable to avoid sending discovery
947 * solicitation on a stale vlan
948 */
949 if (interface->enabled)
950 fcoe_ctlr_link_up(ctlr);
951 };
Robert Lovefd8f8902012-05-22 19:06:16 -0700952 } else if (fcoe_ctlr_link_down(ctlr)) {
Robert Love6e89ea32012-11-27 06:53:40 +0000953 switch (cdev->enabled) {
954 case FCOE_CTLR_DISABLED:
955 pr_info("Link down while interface is disabled.\n");
956 break;
957 case FCOE_CTLR_ENABLED:
958 case FCOE_CTLR_UNUSED:
959 mutex_lock(&lport->lp_mutex);
960 list_for_each_entry(vport, &lport->vports, list)
961 fc_host_port_type(vport->host) =
962 FC_PORTTYPE_UNKNOWN;
963 mutex_unlock(&lport->lp_mutex);
964 fc_host_port_type(lport->host) =
965 FC_PORTTYPE_UNKNOWN;
966 per_cpu_ptr(lport->stats,
967 get_cpu())->LinkFailureCount++;
968 put_cpu();
969 fcoe_clean_pending_queue(lport);
970 wait_for_upload = 1;
971 };
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800972 }
973 }
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700974 mutex_unlock(&bnx2fc_dev_lock);
975
976 if (wait_for_upload) {
977 clear_bit(ADAPTER_STATE_READY, &hba->adapter_state);
978 init_waitqueue_head(&hba->shutdown_wait);
979 BNX2FC_MISC_DBG("indicate_netevent "
980 "num_ofld_sess = %d\n",
981 hba->num_ofld_sess);
982 hba->wait_for_link_down = 1;
983 wait_event_interruptible(hba->shutdown_wait,
984 (hba->num_ofld_sess == 0));
985 BNX2FC_MISC_DBG("wakeup - num_ofld_sess = %d\n",
986 hba->num_ofld_sess);
987 hba->wait_for_link_down = 0;
988
989 if (signal_pending(current))
990 flush_signals(current);
991 }
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800992}
993
994static int bnx2fc_libfc_config(struct fc_lport *lport)
995{
996
997 /* Set the function pointers set by bnx2fc driver */
998 memcpy(&lport->tt, &bnx2fc_libfc_fcn_templ,
999 sizeof(struct libfc_function_template));
1000 fc_elsct_init(lport);
1001 fc_exch_init(lport);
1002 fc_rport_init(lport);
1003 fc_disc_init(lport);
1004 return 0;
1005}
1006
1007static int bnx2fc_em_config(struct fc_lport *lport)
1008{
Bhanu Prakash Gollapudi7d742f62012-01-23 18:00:48 -08001009 int max_xid;
1010
1011 if (nr_cpu_ids <= 2)
1012 max_xid = FCOE_XIDS_PER_CPU;
1013 else
1014 max_xid = FCOE_MAX_XID;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001015 if (!fc_exch_mgr_alloc(lport, FC_CLASS_3, FCOE_MIN_XID,
Bhanu Prakash Gollapudi7d742f62012-01-23 18:00:48 -08001016 max_xid, NULL)) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001017 printk(KERN_ERR PFX "em_config:fc_exch_mgr_alloc failed\n");
1018 return -ENOMEM;
1019 }
1020
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001021 return 0;
1022}
1023
1024static int bnx2fc_lport_config(struct fc_lport *lport)
1025{
1026 lport->link_up = 0;
1027 lport->qfull = 0;
Bhanu Prakash Gollapudi44c570b2012-01-23 18:00:47 -08001028 lport->max_retry_count = BNX2FC_MAX_RETRY_CNT;
1029 lport->max_rport_retry_count = BNX2FC_MAX_RPORT_RETRY_CNT;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001030 lport->e_d_tov = 2 * 1000;
1031 lport->r_a_tov = 10 * 1000;
1032
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001033 lport->service_params = (FCP_SPPF_INIT_FCN | FCP_SPPF_RD_XRDY_DIS |
1034 FCP_SPPF_RETRY | FCP_SPPF_CONF_COMPL);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001035 lport->does_npiv = 1;
1036
1037 memset(&lport->rnid_gen, 0, sizeof(struct fc_els_rnid_gen));
1038 lport->rnid_gen.rnid_atype = BNX2FC_RNID_HBA;
1039
1040 /* alloc stats structure */
1041 if (fc_lport_init_stats(lport))
1042 return -ENOMEM;
1043
1044 /* Finish fc_lport configuration */
1045 fc_lport_config(lport);
1046
1047 return 0;
1048}
1049
1050/**
1051 * bnx2fc_fip_recv - handle a received FIP frame.
1052 *
1053 * @skb: the received skb
1054 * @dev: associated &net_device
1055 * @ptype: the &packet_type structure which was used to register this handler.
1056 * @orig_dev: original receive &net_device, in case @ dev is a bond.
1057 *
1058 * Returns: 0 for success
1059 */
1060static int bnx2fc_fip_recv(struct sk_buff *skb, struct net_device *dev,
1061 struct packet_type *ptype,
1062 struct net_device *orig_dev)
1063{
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001064 struct bnx2fc_interface *interface;
Robert Lovefd8f8902012-05-22 19:06:16 -07001065 struct fcoe_ctlr *ctlr;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001066 interface = container_of(ptype, struct bnx2fc_interface,
1067 fip_packet_type);
Robert Lovefd8f8902012-05-22 19:06:16 -07001068 ctlr = bnx2fc_to_ctlr(interface);
1069 fcoe_ctlr_recv(ctlr, skb);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001070 return 0;
1071}
1072
1073/**
1074 * bnx2fc_update_src_mac - Update Ethernet MAC filters.
1075 *
1076 * @fip: FCoE controller.
1077 * @old: Unicast MAC address to delete if the MAC is non-zero.
1078 * @new: Unicast MAC address to add.
1079 *
1080 * Remove any previously-set unicast MAC filter.
1081 * Add secondary FCoE MAC address filter for our OUI.
1082 */
1083static void bnx2fc_update_src_mac(struct fc_lport *lport, u8 *addr)
1084{
1085 struct fcoe_port *port = lport_priv(lport);
1086
1087 memcpy(port->data_src_addr, addr, ETH_ALEN);
1088}
1089
1090/**
1091 * bnx2fc_get_src_mac - return the ethernet source address for an lport
1092 *
1093 * @lport: libfc port
1094 */
1095static u8 *bnx2fc_get_src_mac(struct fc_lport *lport)
1096{
1097 struct fcoe_port *port;
1098
1099 port = (struct fcoe_port *)lport_priv(lport);
1100 return port->data_src_addr;
1101}
1102
1103/**
1104 * bnx2fc_fip_send - send an Ethernet-encapsulated FIP frame.
1105 *
1106 * @fip: FCoE controller.
1107 * @skb: FIP Packet.
1108 */
1109static void bnx2fc_fip_send(struct fcoe_ctlr *fip, struct sk_buff *skb)
1110{
1111 skb->dev = bnx2fc_from_ctlr(fip)->netdev;
1112 dev_queue_xmit(skb);
1113}
1114
1115static int bnx2fc_vport_create(struct fc_vport *vport, bool disabled)
1116{
1117 struct Scsi_Host *shost = vport_to_shost(vport);
1118 struct fc_lport *n_port = shost_priv(shost);
1119 struct fcoe_port *port = lport_priv(n_port);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001120 struct bnx2fc_interface *interface = port->priv;
1121 struct net_device *netdev = interface->netdev;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001122 struct fc_lport *vn_port;
Bhanu Prakash Gollapudi861efc52011-08-04 17:38:51 -07001123 int rc;
1124 char buf[32];
1125
1126 rc = fcoe_validate_vport_create(vport);
1127 if (rc) {
1128 fcoe_wwn_to_str(vport->port_name, buf, sizeof(buf));
1129 printk(KERN_ERR PFX "Failed to create vport, "
1130 "WWPN (0x%s) already exists\n",
1131 buf);
1132 return rc;
1133 }
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001134
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001135 if (!test_bit(BNX2FC_FLAG_FW_INIT_DONE, &interface->hba->flags)) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001136 printk(KERN_ERR PFX "vn ports cannot be created on"
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001137 "this interface\n");
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001138 return -EIO;
1139 }
Jiri Pirko4bc71cb2011-09-03 03:34:30 +00001140 rtnl_lock();
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001141 mutex_lock(&bnx2fc_dev_lock);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001142 vn_port = bnx2fc_if_create(interface, &vport->dev, 1);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001143 mutex_unlock(&bnx2fc_dev_lock);
Jiri Pirko4bc71cb2011-09-03 03:34:30 +00001144 rtnl_unlock();
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001145
1146 if (IS_ERR(vn_port)) {
1147 printk(KERN_ERR PFX "bnx2fc_vport_create (%s) failed\n",
1148 netdev->name);
1149 return -EIO;
1150 }
1151
1152 if (disabled) {
1153 fc_vport_set_state(vport, FC_VPORT_DISABLED);
1154 } else {
1155 vn_port->boot_time = jiffies;
1156 fc_lport_init(vn_port);
1157 fc_fabric_login(vn_port);
1158 fc_vport_setlink(vn_port);
1159 }
1160 return 0;
1161}
1162
Bhanu Prakash Gollapudiabc49a92011-08-04 17:38:42 -07001163static void bnx2fc_free_vport(struct bnx2fc_hba *hba, struct fc_lport *lport)
1164{
1165 struct bnx2fc_lport *blport, *tmp;
1166
1167 spin_lock_bh(&hba->hba_lock);
1168 list_for_each_entry_safe(blport, tmp, &hba->vports, list) {
1169 if (blport->lport == lport) {
1170 list_del(&blport->list);
1171 kfree(blport);
1172 }
1173 }
1174 spin_unlock_bh(&hba->hba_lock);
1175}
1176
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001177static int bnx2fc_vport_destroy(struct fc_vport *vport)
1178{
1179 struct Scsi_Host *shost = vport_to_shost(vport);
1180 struct fc_lport *n_port = shost_priv(shost);
1181 struct fc_lport *vn_port = vport->dd_data;
1182 struct fcoe_port *port = lport_priv(vn_port);
Bhanu Prakash Gollapudiabc49a92011-08-04 17:38:42 -07001183 struct bnx2fc_interface *interface = port->priv;
Bhanu Prakash Gollapudicdf54662011-08-04 17:38:39 -07001184 struct fc_lport *v_port;
1185 bool found = false;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001186
1187 mutex_lock(&n_port->lp_mutex);
Bhanu Prakash Gollapudicdf54662011-08-04 17:38:39 -07001188 list_for_each_entry(v_port, &n_port->vports, list)
1189 if (v_port->vport == vport) {
1190 found = true;
1191 break;
1192 }
1193
1194 if (!found) {
1195 mutex_unlock(&n_port->lp_mutex);
1196 return -ENOENT;
1197 }
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001198 list_del(&vn_port->list);
1199 mutex_unlock(&n_port->lp_mutex);
Bhanu Prakash Gollapudiabc49a92011-08-04 17:38:42 -07001200 bnx2fc_free_vport(interface->hba, port->lport);
1201 bnx2fc_port_shutdown(port->lport);
1202 bnx2fc_interface_put(interface);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001203 queue_work(bnx2fc_wq, &port->destroy_work);
1204 return 0;
1205}
1206
1207static int bnx2fc_vport_disable(struct fc_vport *vport, bool disable)
1208{
1209 struct fc_lport *lport = vport->dd_data;
1210
1211 if (disable) {
1212 fc_vport_set_state(vport, FC_VPORT_DISABLED);
1213 fc_fabric_logoff(lport);
1214 } else {
1215 lport->boot_time = jiffies;
1216 fc_fabric_login(lport);
1217 fc_vport_setlink(lport);
1218 }
1219 return 0;
1220}
1221
1222
Bhanu Prakash Gollapudi776cebc2011-08-04 17:38:40 -07001223static int bnx2fc_interface_setup(struct bnx2fc_interface *interface)
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001224{
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001225 struct net_device *netdev = interface->netdev;
1226 struct net_device *physdev = interface->hba->phys_dev;
Robert Lovefd8f8902012-05-22 19:06:16 -07001227 struct fcoe_ctlr *ctlr = bnx2fc_to_ctlr(interface);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001228 struct netdev_hw_addr *ha;
1229 int sel_san_mac = 0;
1230
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001231 /* setup Source MAC Address */
1232 rcu_read_lock();
1233 for_each_dev_addr(physdev, ha) {
1234 BNX2FC_MISC_DBG("net_config: ha->type = %d, fip_mac = ",
1235 ha->type);
1236 printk(KERN_INFO "%2x:%2x:%2x:%2x:%2x:%2x\n", ha->addr[0],
1237 ha->addr[1], ha->addr[2], ha->addr[3],
1238 ha->addr[4], ha->addr[5]);
1239
1240 if ((ha->type == NETDEV_HW_ADDR_T_SAN) &&
1241 (is_valid_ether_addr(ha->addr))) {
Robert Lovefd8f8902012-05-22 19:06:16 -07001242 memcpy(ctlr->ctl_src_addr, ha->addr,
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001243 ETH_ALEN);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001244 sel_san_mac = 1;
1245 BNX2FC_MISC_DBG("Found SAN MAC\n");
1246 }
1247 }
1248 rcu_read_unlock();
1249
1250 if (!sel_san_mac)
1251 return -ENODEV;
1252
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001253 interface->fip_packet_type.func = bnx2fc_fip_recv;
1254 interface->fip_packet_type.type = htons(ETH_P_FIP);
1255 interface->fip_packet_type.dev = netdev;
1256 dev_add_pack(&interface->fip_packet_type);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001257
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001258 interface->fcoe_packet_type.func = bnx2fc_rcv;
1259 interface->fcoe_packet_type.type = __constant_htons(ETH_P_FCOE);
1260 interface->fcoe_packet_type.dev = netdev;
1261 dev_add_pack(&interface->fcoe_packet_type);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001262
1263 return 0;
1264}
1265
1266static int bnx2fc_attach_transport(void)
1267{
1268 bnx2fc_transport_template =
1269 fc_attach_transport(&bnx2fc_transport_function);
1270
1271 if (bnx2fc_transport_template == NULL) {
1272 printk(KERN_ERR PFX "Failed to attach FC transport\n");
1273 return -ENODEV;
1274 }
1275
1276 bnx2fc_vport_xport_template =
1277 fc_attach_transport(&bnx2fc_vport_xport_function);
1278 if (bnx2fc_vport_xport_template == NULL) {
1279 printk(KERN_ERR PFX
1280 "Failed to attach FC transport for vport\n");
1281 fc_release_transport(bnx2fc_transport_template);
1282 bnx2fc_transport_template = NULL;
1283 return -ENODEV;
1284 }
1285 return 0;
1286}
1287static void bnx2fc_release_transport(void)
1288{
1289 fc_release_transport(bnx2fc_transport_template);
1290 fc_release_transport(bnx2fc_vport_xport_template);
1291 bnx2fc_transport_template = NULL;
1292 bnx2fc_vport_xport_template = NULL;
1293}
1294
1295static void bnx2fc_interface_release(struct kref *kref)
1296{
Robert Love8d55e502012-05-22 19:06:26 -07001297 struct fcoe_ctlr_device *ctlr_dev;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001298 struct bnx2fc_interface *interface;
Robert Lovefd8f8902012-05-22 19:06:16 -07001299 struct fcoe_ctlr *ctlr;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001300 struct net_device *netdev;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001301
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001302 interface = container_of(kref, struct bnx2fc_interface, kref);
Nithin Nayak Sujir068bdce2011-04-25 12:30:09 -07001303 BNX2FC_MISC_DBG("Interface is being released\n");
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001304
Robert Lovefd8f8902012-05-22 19:06:16 -07001305 ctlr = bnx2fc_to_ctlr(interface);
Robert Love8d55e502012-05-22 19:06:26 -07001306 ctlr_dev = fcoe_ctlr_to_ctlr_dev(ctlr);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001307 netdev = interface->netdev;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001308
1309 /* tear-down FIP controller */
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001310 if (test_and_clear_bit(BNX2FC_CTLR_INIT_DONE, &interface->if_flags))
Robert Lovefd8f8902012-05-22 19:06:16 -07001311 fcoe_ctlr_destroy(ctlr);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001312
Robert Love8d55e502012-05-22 19:06:26 -07001313 fcoe_ctlr_device_delete(ctlr_dev);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001314
1315 dev_put(netdev);
1316 module_put(THIS_MODULE);
1317}
1318
1319static inline void bnx2fc_interface_get(struct bnx2fc_interface *interface)
1320{
1321 kref_get(&interface->kref);
1322}
1323
1324static inline void bnx2fc_interface_put(struct bnx2fc_interface *interface)
1325{
1326 kref_put(&interface->kref, bnx2fc_interface_release);
1327}
1328static void bnx2fc_hba_destroy(struct bnx2fc_hba *hba)
1329{
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001330 /* Free the command manager */
1331 if (hba->cmd_mgr) {
1332 bnx2fc_cmd_mgr_free(hba->cmd_mgr);
1333 hba->cmd_mgr = NULL;
1334 }
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001335 kfree(hba->tgt_ofld_list);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001336 bnx2fc_unbind_pcidev(hba);
1337 kfree(hba);
1338}
1339
1340/**
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001341 * bnx2fc_hba_create - create a new bnx2fc hba
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001342 *
1343 * @cnic: pointer to cnic device
1344 *
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001345 * Creates a new FCoE hba on the given device.
1346 *
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001347 */
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001348static struct bnx2fc_hba *bnx2fc_hba_create(struct cnic_dev *cnic)
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001349{
1350 struct bnx2fc_hba *hba;
Barak Witkowski2e499d32012-06-26 01:31:19 +00001351 struct fcoe_capabilities *fcoe_cap;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001352 int rc;
1353
1354 hba = kzalloc(sizeof(*hba), GFP_KERNEL);
1355 if (!hba) {
1356 printk(KERN_ERR PFX "Unable to allocate hba structure\n");
1357 return NULL;
1358 }
1359 spin_lock_init(&hba->hba_lock);
1360 mutex_init(&hba->hba_mutex);
1361
1362 hba->cnic = cnic;
1363 rc = bnx2fc_bind_pcidev(hba);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001364 if (rc) {
1365 printk(KERN_ERR PFX "create_adapter: bind error\n");
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001366 goto bind_err;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001367 }
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001368 hba->phys_dev = cnic->netdev;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001369 hba->next_conn_id = 0;
1370
1371 hba->tgt_ofld_list =
1372 kzalloc(sizeof(struct bnx2fc_rport *) * BNX2FC_NUM_MAX_SESS,
1373 GFP_KERNEL);
1374 if (!hba->tgt_ofld_list) {
1375 printk(KERN_ERR PFX "Unable to allocate tgt offload list\n");
1376 goto tgtofld_err;
1377 }
1378
1379 hba->num_ofld_sess = 0;
1380
1381 hba->cmd_mgr = bnx2fc_cmd_mgr_alloc(hba, BNX2FC_MIN_XID,
1382 BNX2FC_MAX_XID);
1383 if (!hba->cmd_mgr) {
1384 printk(KERN_ERR PFX "em_config:bnx2fc_cmd_mgr_alloc failed\n");
1385 goto cmgr_err;
1386 }
Barak Witkowski2e499d32012-06-26 01:31:19 +00001387 fcoe_cap = &hba->fcoe_cap;
1388
1389 fcoe_cap->capability1 = BNX2FC_TM_MAX_SQES <<
1390 FCOE_IOS_PER_CONNECTION_SHIFT;
1391 fcoe_cap->capability1 |= BNX2FC_NUM_MAX_SESS <<
1392 FCOE_LOGINS_PER_PORT_SHIFT;
1393 fcoe_cap->capability2 = BNX2FC_MAX_OUTSTANDING_CMNDS <<
1394 FCOE_NUMBER_OF_EXCHANGES_SHIFT;
1395 fcoe_cap->capability2 |= BNX2FC_MAX_NPIV <<
1396 FCOE_NPIV_WWN_PER_PORT_SHIFT;
1397 fcoe_cap->capability3 = BNX2FC_NUM_MAX_SESS <<
1398 FCOE_TARGETS_SUPPORTED_SHIFT;
1399 fcoe_cap->capability3 |= BNX2FC_MAX_OUTSTANDING_CMNDS <<
1400 FCOE_OUTSTANDING_COMMANDS_SHIFT;
1401 fcoe_cap->capability4 = FCOE_CAPABILITY4_STATEFUL;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001402
1403 init_waitqueue_head(&hba->shutdown_wait);
1404 init_waitqueue_head(&hba->destroy_wait);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001405 INIT_LIST_HEAD(&hba->vports);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001406
1407 return hba;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001408
1409cmgr_err:
1410 kfree(hba->tgt_ofld_list);
1411tgtofld_err:
1412 bnx2fc_unbind_pcidev(hba);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001413bind_err:
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001414 kfree(hba);
1415 return NULL;
1416}
1417
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001418struct bnx2fc_interface *bnx2fc_interface_create(struct bnx2fc_hba *hba,
1419 struct net_device *netdev,
1420 enum fip_state fip_mode)
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001421{
Robert Love8d55e502012-05-22 19:06:26 -07001422 struct fcoe_ctlr_device *ctlr_dev;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001423 struct bnx2fc_interface *interface;
Robert Lovefd8f8902012-05-22 19:06:16 -07001424 struct fcoe_ctlr *ctlr;
1425 int size;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001426 int rc = 0;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001427
Robert Lovefd8f8902012-05-22 19:06:16 -07001428 size = (sizeof(*interface) + sizeof(struct fcoe_ctlr));
Robert Love8d55e502012-05-22 19:06:26 -07001429 ctlr_dev = fcoe_ctlr_device_add(&netdev->dev, &bnx2fc_fcoe_sysfs_templ,
1430 size);
1431 if (!ctlr_dev) {
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001432 printk(KERN_ERR PFX "Unable to allocate interface structure\n");
1433 return NULL;
1434 }
Robert Love8d55e502012-05-22 19:06:26 -07001435 ctlr = fcoe_ctlr_device_priv(ctlr_dev);
Robert Lovefd8f8902012-05-22 19:06:16 -07001436 interface = fcoe_ctlr_priv(ctlr);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001437 dev_hold(netdev);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001438 kref_init(&interface->kref);
1439 interface->hba = hba;
1440 interface->netdev = netdev;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001441
1442 /* Initialize FIP */
Robert Lovefd8f8902012-05-22 19:06:16 -07001443 fcoe_ctlr_init(ctlr, fip_mode);
1444 ctlr->send = bnx2fc_fip_send;
1445 ctlr->update_mac = bnx2fc_update_src_mac;
1446 ctlr->get_src_addr = bnx2fc_get_src_mac;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001447 set_bit(BNX2FC_CTLR_INIT_DONE, &interface->if_flags);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001448
Bhanu Prakash Gollapudi776cebc2011-08-04 17:38:40 -07001449 rc = bnx2fc_interface_setup(interface);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001450 if (!rc)
1451 return interface;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001452
Robert Lovefd8f8902012-05-22 19:06:16 -07001453 fcoe_ctlr_destroy(ctlr);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001454 dev_put(netdev);
Robert Love8d55e502012-05-22 19:06:26 -07001455 fcoe_ctlr_device_delete(ctlr_dev);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001456 return NULL;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001457}
1458
1459/**
1460 * bnx2fc_if_create - Create FCoE instance on a given interface
1461 *
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001462 * @interface: FCoE interface to create a local port on
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001463 * @parent: Device pointer to be the parent in sysfs for the SCSI host
1464 * @npiv: Indicates if the port is vport or not
1465 *
1466 * Creates a fc_lport instance and a Scsi_Host instance and configure them.
1467 *
1468 * Returns: Allocated fc_lport or an error pointer
1469 */
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001470static struct fc_lport *bnx2fc_if_create(struct bnx2fc_interface *interface,
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001471 struct device *parent, int npiv)
1472{
Robert Lovefd8f8902012-05-22 19:06:16 -07001473 struct fcoe_ctlr *ctlr = bnx2fc_to_ctlr(interface);
Vasu Dev134a4e22011-04-28 15:55:44 -07001474 struct fc_lport *lport, *n_port;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001475 struct fcoe_port *port;
1476 struct Scsi_Host *shost;
1477 struct fc_vport *vport = dev_to_vport(parent);
Bhanu Prakash Gollapudid36b3272011-05-27 11:47:27 -07001478 struct bnx2fc_lport *blport;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001479 struct bnx2fc_hba *hba;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001480 int rc = 0;
1481
Bhanu Prakash Gollapudid36b3272011-05-27 11:47:27 -07001482 blport = kzalloc(sizeof(struct bnx2fc_lport), GFP_KERNEL);
1483 if (!blport) {
Robert Lovefd8f8902012-05-22 19:06:16 -07001484 BNX2FC_HBA_DBG(ctlr->lp, "Unable to alloc blport\n");
Bhanu Prakash Gollapudid36b3272011-05-27 11:47:27 -07001485 return NULL;
1486 }
1487
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001488 /* Allocate Scsi_Host structure */
Vasu Dev134a4e22011-04-28 15:55:44 -07001489 if (!npiv)
1490 lport = libfc_host_alloc(&bnx2fc_shost_template, sizeof(*port));
1491 else
1492 lport = libfc_vport_create(vport, sizeof(*port));
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001493
1494 if (!lport) {
1495 printk(KERN_ERR PFX "could not allocate scsi host structure\n");
Bhanu Prakash Gollapudid36b3272011-05-27 11:47:27 -07001496 goto free_blport;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001497 }
1498 shost = lport->host;
1499 port = lport_priv(lport);
1500 port->lport = lport;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001501 port->priv = interface;
Yi Zouc3d79092012-12-06 06:24:29 +00001502 port->get_netdev = bnx2fc_netdev;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001503 INIT_WORK(&port->destroy_work, bnx2fc_destroy_work);
1504
1505 /* Configure fcoe_port */
1506 rc = bnx2fc_lport_config(lport);
1507 if (rc)
1508 goto lp_config_err;
1509
1510 if (npiv) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001511 printk(KERN_ERR PFX "Setting vport names, 0x%llX 0x%llX\n",
1512 vport->node_name, vport->port_name);
1513 fc_set_wwnn(lport, vport->node_name);
1514 fc_set_wwpn(lport, vport->port_name);
1515 }
1516 /* Configure netdev and networking properties of the lport */
Bhanu Prakash Gollapudi52439602011-08-04 17:38:50 -07001517 rc = bnx2fc_net_config(lport, interface->netdev);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001518 if (rc) {
1519 printk(KERN_ERR PFX "Error on bnx2fc_net_config\n");
1520 goto lp_config_err;
1521 }
1522
1523 rc = bnx2fc_shost_config(lport, parent);
1524 if (rc) {
1525 printk(KERN_ERR PFX "Couldnt configure shost for %s\n",
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001526 interface->netdev->name);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001527 goto lp_config_err;
1528 }
1529
1530 /* Initialize the libfc library */
1531 rc = bnx2fc_libfc_config(lport);
1532 if (rc) {
1533 printk(KERN_ERR PFX "Couldnt configure libfc\n");
1534 goto shost_err;
1535 }
1536 fc_host_port_type(lport->host) = FC_PORTTYPE_UNKNOWN;
1537
1538 /* Allocate exchange manager */
Vasu Dev134a4e22011-04-28 15:55:44 -07001539 if (!npiv)
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001540 rc = bnx2fc_em_config(lport);
Vasu Dev134a4e22011-04-28 15:55:44 -07001541 else {
1542 shost = vport_to_shost(vport);
1543 n_port = shost_priv(shost);
1544 rc = fc_exch_mgr_list_clone(n_port, lport);
1545 }
1546
1547 if (rc) {
1548 printk(KERN_ERR PFX "Error on bnx2fc_em_config\n");
1549 goto shost_err;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001550 }
1551
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001552 bnx2fc_interface_get(interface);
Bhanu Prakash Gollapudid36b3272011-05-27 11:47:27 -07001553
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001554 hba = interface->hba;
Bhanu Prakash Gollapudid36b3272011-05-27 11:47:27 -07001555 spin_lock_bh(&hba->hba_lock);
1556 blport->lport = lport;
1557 list_add_tail(&blport->list, &hba->vports);
1558 spin_unlock_bh(&hba->hba_lock);
1559
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001560 return lport;
1561
1562shost_err:
1563 scsi_remove_host(shost);
1564lp_config_err:
1565 scsi_host_put(lport->host);
Bhanu Prakash Gollapudid36b3272011-05-27 11:47:27 -07001566free_blport:
1567 kfree(blport);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001568 return NULL;
1569}
1570
Bhanu Prakash Gollapudi013068f2011-08-30 15:54:52 -07001571static void bnx2fc_net_cleanup(struct bnx2fc_interface *interface)
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001572{
1573 /* Dont listen for Ethernet packets anymore */
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001574 __dev_remove_pack(&interface->fcoe_packet_type);
1575 __dev_remove_pack(&interface->fip_packet_type);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001576 synchronize_net();
1577}
1578
Bhanu Prakash Gollapudi776cebc2011-08-04 17:38:40 -07001579static void bnx2fc_interface_cleanup(struct bnx2fc_interface *interface)
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001580{
Robert Lovefd8f8902012-05-22 19:06:16 -07001581 struct fcoe_ctlr *ctlr = bnx2fc_to_ctlr(interface);
1582 struct fc_lport *lport = ctlr->lp;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001583 struct fcoe_port *port = lport_priv(lport);
Bhanu Prakash Gollapudi9be17fc2011-08-04 17:38:41 -07001584 struct bnx2fc_hba *hba = interface->hba;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001585
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001586 /* Stop the transmit retry timer */
1587 del_timer_sync(&port->timer);
1588
1589 /* Free existing transmit skbs */
1590 fcoe_clean_pending_queue(lport);
1591
Bhanu Prakash Gollapudi013068f2011-08-30 15:54:52 -07001592 bnx2fc_net_cleanup(interface);
Bhanu Prakash Gollapudi9be17fc2011-08-04 17:38:41 -07001593
Bhanu Prakash Gollapudiabc49a92011-08-04 17:38:42 -07001594 bnx2fc_free_vport(hba, lport);
Bhanu Prakash Gollapudi9be17fc2011-08-04 17:38:41 -07001595}
1596
1597static void bnx2fc_if_destroy(struct fc_lport *lport)
1598{
1599
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001600 /* Free queued packets for the receive thread */
1601 bnx2fc_clean_rx_queue(lport);
1602
1603 /* Detach from scsi-ml */
1604 fc_remove_host(lport->host);
1605 scsi_remove_host(lport->host);
1606
1607 /*
1608 * Note that only the physical lport will have the exchange manager.
1609 * for vports, this function is NOP
1610 */
1611 fc_exch_mgr_free(lport);
1612
1613 /* Free memory used by statistical counters */
1614 fc_lport_free_stats(lport);
1615
1616 /* Release Scsi_Host */
1617 scsi_host_put(lport->host);
1618}
1619
Bhanu Prakash Gollapudieccdcd02011-08-24 18:56:42 -07001620static void __bnx2fc_destroy(struct bnx2fc_interface *interface)
Bhanu Prakash Gollapudiabc49a92011-08-04 17:38:42 -07001621{
Robert Lovefd8f8902012-05-22 19:06:16 -07001622 struct fcoe_ctlr *ctlr = bnx2fc_to_ctlr(interface);
1623 struct fc_lport *lport = ctlr->lp;
Bhanu Prakash Gollapudi0cbf32e2011-08-30 15:54:51 -07001624 struct fcoe_port *port = lport_priv(lport);
Bhanu Prakash Gollapudiabc49a92011-08-04 17:38:42 -07001625
1626 bnx2fc_interface_cleanup(interface);
1627 bnx2fc_stop(interface);
Bhanu Prakash Gollapudiabc49a92011-08-04 17:38:42 -07001628 list_del(&interface->list);
Bhanu Prakash Gollapudiabc49a92011-08-04 17:38:42 -07001629 bnx2fc_interface_put(interface);
Bhanu Prakash Gollapudi0cbf32e2011-08-30 15:54:51 -07001630 queue_work(bnx2fc_wq, &port->destroy_work);
Bhanu Prakash Gollapudiabc49a92011-08-04 17:38:42 -07001631}
1632
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001633/**
1634 * bnx2fc_destroy - Destroy a bnx2fc FCoE interface
1635 *
1636 * @buffer: The name of the Ethernet interface to be destroyed
1637 * @kp: The associated kernel parameter
1638 *
1639 * Called from sysfs.
1640 *
1641 * Returns: 0 for success
1642 */
1643static int bnx2fc_destroy(struct net_device *netdev)
1644{
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001645 struct bnx2fc_interface *interface = NULL;
Bhanu Prakash Gollapudi2a7b29c2012-01-23 18:00:46 -08001646 struct workqueue_struct *timer_work_queue;
Robert Lovefd8f8902012-05-22 19:06:16 -07001647 struct fcoe_ctlr *ctlr;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001648 int rc = 0;
1649
Nithin Sujir6702ca12011-03-17 17:13:27 -07001650 rtnl_lock();
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001651 mutex_lock(&bnx2fc_dev_lock);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001652
1653 interface = bnx2fc_interface_lookup(netdev);
Robert Lovefd8f8902012-05-22 19:06:16 -07001654 ctlr = bnx2fc_to_ctlr(interface);
1655 if (!interface || !ctlr->lp) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001656 rc = -ENODEV;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001657 printk(KERN_ERR PFX "bnx2fc_destroy: interface or lport not found\n");
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001658 goto netdev_err;
1659 }
1660
Bhanu Prakash Gollapudi2a7b29c2012-01-23 18:00:46 -08001661 timer_work_queue = interface->timer_work_queue;
Bhanu Prakash Gollapudieccdcd02011-08-24 18:56:42 -07001662 __bnx2fc_destroy(interface);
Bhanu Prakash Gollapudi2a7b29c2012-01-23 18:00:46 -08001663 destroy_workqueue(timer_work_queue);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001664
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001665netdev_err:
1666 mutex_unlock(&bnx2fc_dev_lock);
1667 rtnl_unlock();
1668 return rc;
1669}
1670
1671static void bnx2fc_destroy_work(struct work_struct *work)
1672{
1673 struct fcoe_port *port;
1674 struct fc_lport *lport;
1675
1676 port = container_of(work, struct fcoe_port, destroy_work);
1677 lport = port->lport;
1678
1679 BNX2FC_HBA_DBG(lport, "Entered bnx2fc_destroy_work\n");
1680
Bhanu Prakash Gollapudi9be17fc2011-08-04 17:38:41 -07001681 bnx2fc_if_destroy(lport);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001682}
1683
1684static void bnx2fc_unbind_adapter_devices(struct bnx2fc_hba *hba)
1685{
1686 bnx2fc_free_fw_resc(hba);
1687 bnx2fc_free_task_ctx(hba);
1688}
1689
1690/**
1691 * bnx2fc_bind_adapter_devices - binds bnx2fc adapter with the associated
1692 * pci structure
1693 *
1694 * @hba: Adapter instance
1695 */
1696static int bnx2fc_bind_adapter_devices(struct bnx2fc_hba *hba)
1697{
1698 if (bnx2fc_setup_task_ctx(hba))
1699 goto mem_err;
1700
1701 if (bnx2fc_setup_fw_resc(hba))
1702 goto mem_err;
1703
1704 return 0;
1705mem_err:
1706 bnx2fc_unbind_adapter_devices(hba);
1707 return -ENOMEM;
1708}
1709
1710static int bnx2fc_bind_pcidev(struct bnx2fc_hba *hba)
1711{
1712 struct cnic_dev *cnic;
1713
1714 if (!hba->cnic) {
1715 printk(KERN_ERR PFX "cnic is NULL\n");
1716 return -ENODEV;
1717 }
1718 cnic = hba->cnic;
1719 hba->pcidev = cnic->pcidev;
1720 if (hba->pcidev)
1721 pci_dev_get(hba->pcidev);
1722
1723 return 0;
1724}
1725
1726static void bnx2fc_unbind_pcidev(struct bnx2fc_hba *hba)
1727{
1728 if (hba->pcidev)
1729 pci_dev_put(hba->pcidev);
1730 hba->pcidev = NULL;
1731}
1732
Barak Witkowski2e499d32012-06-26 01:31:19 +00001733/**
1734 * bnx2fc_ulp_get_stats - cnic callback to populate FCoE stats
1735 *
1736 * @handle: transport handle pointing to adapter struture
1737 */
1738static int bnx2fc_ulp_get_stats(void *handle)
1739{
1740 struct bnx2fc_hba *hba = handle;
1741 struct cnic_dev *cnic;
1742 struct fcoe_stats_info *stats_addr;
1743
1744 if (!hba)
1745 return -EINVAL;
1746
1747 cnic = hba->cnic;
1748 stats_addr = &cnic->stats_addr->fcoe_stat;
1749 if (!stats_addr)
1750 return -EINVAL;
1751
1752 strncpy(stats_addr->version, BNX2FC_VERSION,
1753 sizeof(stats_addr->version));
1754 stats_addr->txq_size = BNX2FC_SQ_WQES_MAX;
1755 stats_addr->rxq_size = BNX2FC_CQ_WQES_MAX;
1756
1757 return 0;
1758}
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001759
1760
1761/**
1762 * bnx2fc_ulp_start - cnic callback to initialize & start adapter instance
1763 *
Masanari Iida59e13d42012-04-25 00:24:16 +09001764 * @handle: transport handle pointing to adapter structure
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001765 *
1766 * This function maps adapter structure to pcidev structure and initiates
1767 * firmware handshake to enable/initialize on-chip FCoE components.
1768 * This bnx2fc - cnic interface api callback is used after following
1769 * conditions are met -
1770 * a) underlying network interface is up (marked by event NETDEV_UP
1771 * from netdev
1772 * b) bnx2fc adatper structure is registered.
1773 */
1774static void bnx2fc_ulp_start(void *handle)
1775{
1776 struct bnx2fc_hba *hba = handle;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001777 struct bnx2fc_interface *interface;
Robert Lovefd8f8902012-05-22 19:06:16 -07001778 struct fcoe_ctlr *ctlr;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001779 struct fc_lport *lport;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001780
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001781 mutex_lock(&bnx2fc_dev_lock);
1782
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001783 if (!test_bit(BNX2FC_FLAG_FW_INIT_DONE, &hba->flags))
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001784 bnx2fc_fw_init(hba);
1785
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001786 BNX2FC_MISC_DBG("bnx2fc started.\n");
1787
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001788 list_for_each_entry(interface, &if_list, list) {
1789 if (interface->hba == hba) {
Robert Lovefd8f8902012-05-22 19:06:16 -07001790 ctlr = bnx2fc_to_ctlr(interface);
1791 lport = ctlr->lp;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001792 /* Kick off Fabric discovery*/
1793 printk(KERN_ERR PFX "ulp_init: start discovery\n");
1794 lport->tt.frame_send = bnx2fc_xmit;
1795 bnx2fc_start_disc(interface);
1796 }
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001797 }
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001798
1799 mutex_unlock(&bnx2fc_dev_lock);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001800}
1801
1802static void bnx2fc_port_shutdown(struct fc_lport *lport)
1803{
1804 BNX2FC_MISC_DBG("Entered %s\n", __func__);
1805 fc_fabric_logoff(lport);
1806 fc_lport_destroy(lport);
1807}
1808
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001809static void bnx2fc_stop(struct bnx2fc_interface *interface)
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001810{
Robert Lovefd8f8902012-05-22 19:06:16 -07001811 struct fcoe_ctlr *ctlr = bnx2fc_to_ctlr(interface);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001812 struct fc_lport *lport;
1813 struct fc_lport *vport;
1814
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001815 if (!test_bit(BNX2FC_FLAG_FW_INIT_DONE, &interface->hba->flags))
1816 return;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001817
Robert Lovefd8f8902012-05-22 19:06:16 -07001818 lport = ctlr->lp;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001819 bnx2fc_port_shutdown(lport);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001820
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001821 mutex_lock(&lport->lp_mutex);
1822 list_for_each_entry(vport, &lport->vports, list)
1823 fc_host_port_type(vport->host) =
1824 FC_PORTTYPE_UNKNOWN;
1825 mutex_unlock(&lport->lp_mutex);
1826 fc_host_port_type(lport->host) = FC_PORTTYPE_UNKNOWN;
Robert Lovefd8f8902012-05-22 19:06:16 -07001827 fcoe_ctlr_link_down(ctlr);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001828 fcoe_clean_pending_queue(lport);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001829}
1830
1831static int bnx2fc_fw_init(struct bnx2fc_hba *hba)
1832{
1833#define BNX2FC_INIT_POLL_TIME (1000 / HZ)
1834 int rc = -1;
1835 int i = HZ;
1836
1837 rc = bnx2fc_bind_adapter_devices(hba);
1838 if (rc) {
1839 printk(KERN_ALERT PFX
1840 "bnx2fc_bind_adapter_devices failed - rc = %d\n", rc);
1841 goto err_out;
1842 }
1843
1844 rc = bnx2fc_send_fw_fcoe_init_msg(hba);
1845 if (rc) {
1846 printk(KERN_ALERT PFX
1847 "bnx2fc_send_fw_fcoe_init_msg failed - rc = %d\n", rc);
1848 goto err_unbind;
1849 }
1850
1851 /*
1852 * Wait until the adapter init message is complete, and adapter
1853 * state is UP.
1854 */
1855 while (!test_bit(ADAPTER_STATE_UP, &hba->adapter_state) && i--)
1856 msleep(BNX2FC_INIT_POLL_TIME);
1857
1858 if (!test_bit(ADAPTER_STATE_UP, &hba->adapter_state)) {
1859 printk(KERN_ERR PFX "bnx2fc_start: %s failed to initialize. "
1860 "Ignoring...\n",
1861 hba->cnic->netdev->name);
1862 rc = -1;
1863 goto err_unbind;
1864 }
1865
1866
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001867 set_bit(BNX2FC_FLAG_FW_INIT_DONE, &hba->flags);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001868 return 0;
1869
1870err_unbind:
1871 bnx2fc_unbind_adapter_devices(hba);
1872err_out:
1873 return rc;
1874}
1875
1876static void bnx2fc_fw_destroy(struct bnx2fc_hba *hba)
1877{
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001878 if (test_and_clear_bit(BNX2FC_FLAG_FW_INIT_DONE, &hba->flags)) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001879 if (bnx2fc_send_fw_fcoe_destroy_msg(hba) == 0) {
1880 init_timer(&hba->destroy_timer);
1881 hba->destroy_timer.expires = BNX2FC_FW_TIMEOUT +
1882 jiffies;
1883 hba->destroy_timer.function = bnx2fc_destroy_timer;
1884 hba->destroy_timer.data = (unsigned long)hba;
1885 add_timer(&hba->destroy_timer);
1886 wait_event_interruptible(hba->destroy_wait,
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001887 test_bit(BNX2FC_FLAG_DESTROY_CMPL,
1888 &hba->flags));
Bhanu Prakash Gollapudicd703ae2011-08-04 17:38:43 -07001889 clear_bit(BNX2FC_FLAG_DESTROY_CMPL, &hba->flags);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001890 /* This should never happen */
1891 if (signal_pending(current))
1892 flush_signals(current);
1893
1894 del_timer_sync(&hba->destroy_timer);
1895 }
1896 bnx2fc_unbind_adapter_devices(hba);
1897 }
1898}
1899
1900/**
1901 * bnx2fc_ulp_stop - cnic callback to shutdown adapter instance
1902 *
1903 * @handle: transport handle pointing to adapter structure
1904 *
1905 * Driver checks if adapter is already in shutdown mode, if not start
1906 * the shutdown process.
1907 */
1908static void bnx2fc_ulp_stop(void *handle)
1909{
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001910 struct bnx2fc_hba *hba = handle;
1911 struct bnx2fc_interface *interface;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001912
1913 printk(KERN_ERR "ULP_STOP\n");
1914
1915 mutex_lock(&bnx2fc_dev_lock);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001916 if (!test_bit(BNX2FC_FLAG_FW_INIT_DONE, &hba->flags))
1917 goto exit;
1918 list_for_each_entry(interface, &if_list, list) {
1919 if (interface->hba == hba)
1920 bnx2fc_stop(interface);
1921 }
1922 BUG_ON(hba->num_ofld_sess != 0);
1923
1924 mutex_lock(&hba->hba_mutex);
1925 clear_bit(ADAPTER_STATE_UP, &hba->adapter_state);
1926 clear_bit(ADAPTER_STATE_GOING_DOWN,
1927 &hba->adapter_state);
1928
1929 clear_bit(ADAPTER_STATE_READY, &hba->adapter_state);
1930 mutex_unlock(&hba->hba_mutex);
1931
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001932 bnx2fc_fw_destroy(hba);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001933exit:
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001934 mutex_unlock(&bnx2fc_dev_lock);
1935}
1936
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001937static void bnx2fc_start_disc(struct bnx2fc_interface *interface)
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001938{
Robert Lovefd8f8902012-05-22 19:06:16 -07001939 struct fcoe_ctlr *ctlr = bnx2fc_to_ctlr(interface);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001940 struct fc_lport *lport;
1941 int wait_cnt = 0;
1942
1943 BNX2FC_MISC_DBG("Entered %s\n", __func__);
1944 /* Kick off FIP/FLOGI */
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001945 if (!test_bit(BNX2FC_FLAG_FW_INIT_DONE, &interface->hba->flags)) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001946 printk(KERN_ERR PFX "Init not done yet\n");
1947 return;
1948 }
1949
Robert Lovefd8f8902012-05-22 19:06:16 -07001950 lport = ctlr->lp;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001951 BNX2FC_HBA_DBG(lport, "calling fc_fabric_login\n");
1952
Bhanu Prakash Gollapudi8a5badf2011-08-30 15:54:48 -07001953 if (!bnx2fc_link_ok(lport) && interface->enabled) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001954 BNX2FC_HBA_DBG(lport, "ctlr_link_up\n");
Robert Lovefd8f8902012-05-22 19:06:16 -07001955 fcoe_ctlr_link_up(ctlr);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001956 fc_host_port_type(lport->host) = FC_PORTTYPE_NPORT;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001957 set_bit(ADAPTER_STATE_READY, &interface->hba->adapter_state);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001958 }
1959
1960 /* wait for the FCF to be selected before issuing FLOGI */
Robert Lovefd8f8902012-05-22 19:06:16 -07001961 while (!ctlr->sel_fcf) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001962 msleep(250);
1963 /* give up after 3 secs */
1964 if (++wait_cnt > 12)
1965 break;
1966 }
Bhanu Prakash Gollapudi627e6282011-08-04 17:38:35 -07001967
1968 /* Reset max receive frame size to default */
1969 if (fc_set_mfs(lport, BNX2FC_MFS))
1970 return;
1971
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001972 fc_lport_init(lport);
1973 fc_fabric_login(lport);
1974}
1975
1976
1977/**
1978 * bnx2fc_ulp_init - Initialize an adapter instance
1979 *
1980 * @dev : cnic device handle
1981 * Called from cnic_register_driver() context to initialize all
1982 * enumerated cnic devices. This routine allocates adapter structure
1983 * and other device specific resources.
1984 */
1985static void bnx2fc_ulp_init(struct cnic_dev *dev)
1986{
1987 struct bnx2fc_hba *hba;
1988 int rc = 0;
1989
1990 BNX2FC_MISC_DBG("Entered %s\n", __func__);
1991 /* bnx2fc works only when bnx2x is loaded */
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001992 if (!test_bit(CNIC_F_BNX2X_CLASS, &dev->flags) ||
1993 (dev->max_fcoe_conn == 0)) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001994 printk(KERN_ERR PFX "bnx2fc FCoE not supported on %s,"
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001995 " flags: %lx fcoe_conn: %d\n",
1996 dev->netdev->name, dev->flags, dev->max_fcoe_conn);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001997 return;
1998 }
1999
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002000 hba = bnx2fc_hba_create(dev);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002001 if (!hba) {
2002 printk(KERN_ERR PFX "hba initialization failed\n");
2003 return;
2004 }
2005
2006 /* Add HBA to the adapter list */
2007 mutex_lock(&bnx2fc_dev_lock);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002008 list_add_tail(&hba->list, &adapter_list);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002009 adapter_count++;
2010 mutex_unlock(&bnx2fc_dev_lock);
2011
Barak Witkowski2e499d32012-06-26 01:31:19 +00002012 dev->fcoe_cap = &hba->fcoe_cap;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002013 clear_bit(BNX2FC_CNIC_REGISTERED, &hba->reg_with_cnic);
2014 rc = dev->register_device(dev, CNIC_ULP_FCOE,
2015 (void *) hba);
2016 if (rc)
Bhanu Prakash Gollapudib2a554f2011-06-27 23:30:53 -07002017 printk(KERN_ERR PFX "register_device failed, rc = %d\n", rc);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002018 else
2019 set_bit(BNX2FC_CNIC_REGISTERED, &hba->reg_with_cnic);
2020}
2021
Robert Love6e89ea32012-11-27 06:53:40 +00002022/**
2023 * Deperecated: Use bnx2fc_enabled()
2024 */
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002025static int bnx2fc_disable(struct net_device *netdev)
2026{
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002027 struct bnx2fc_interface *interface;
Robert Lovefd8f8902012-05-22 19:06:16 -07002028 struct fcoe_ctlr *ctlr;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002029 int rc = 0;
2030
Nithin Sujir6702ca12011-03-17 17:13:27 -07002031 rtnl_lock();
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002032 mutex_lock(&bnx2fc_dev_lock);
2033
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002034 interface = bnx2fc_interface_lookup(netdev);
Robert Lovefd8f8902012-05-22 19:06:16 -07002035 ctlr = bnx2fc_to_ctlr(interface);
2036 if (!interface || !ctlr->lp) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002037 rc = -ENODEV;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002038 printk(KERN_ERR PFX "bnx2fc_disable: interface or lport not found\n");
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002039 } else {
Bhanu Prakash Gollapudi8a5badf2011-08-30 15:54:48 -07002040 interface->enabled = false;
Robert Lovefd8f8902012-05-22 19:06:16 -07002041 fcoe_ctlr_link_down(ctlr);
2042 fcoe_clean_pending_queue(ctlr->lp);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002043 }
2044
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002045 mutex_unlock(&bnx2fc_dev_lock);
2046 rtnl_unlock();
2047 return rc;
2048}
2049
Robert Love6e89ea32012-11-27 06:53:40 +00002050/**
2051 * Deprecated: Use bnx2fc_enabled()
2052 */
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002053static int bnx2fc_enable(struct net_device *netdev)
2054{
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002055 struct bnx2fc_interface *interface;
Robert Lovefd8f8902012-05-22 19:06:16 -07002056 struct fcoe_ctlr *ctlr;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002057 int rc = 0;
2058
Nithin Sujir6702ca12011-03-17 17:13:27 -07002059 rtnl_lock();
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002060 mutex_lock(&bnx2fc_dev_lock);
2061
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002062 interface = bnx2fc_interface_lookup(netdev);
Robert Lovefd8f8902012-05-22 19:06:16 -07002063 ctlr = bnx2fc_to_ctlr(interface);
2064 if (!interface || !ctlr->lp) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002065 rc = -ENODEV;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002066 printk(KERN_ERR PFX "bnx2fc_enable: interface or lport not found\n");
Robert Lovefd8f8902012-05-22 19:06:16 -07002067 } else if (!bnx2fc_link_ok(ctlr->lp)) {
2068 fcoe_ctlr_link_up(ctlr);
Bhanu Prakash Gollapudi8a5badf2011-08-30 15:54:48 -07002069 interface->enabled = true;
2070 }
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002071
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002072 mutex_unlock(&bnx2fc_dev_lock);
2073 rtnl_unlock();
2074 return rc;
2075}
2076
2077/**
Robert Love6e89ea32012-11-27 06:53:40 +00002078 * bnx2fc_ctlr_enabled() - Enable or disable an FCoE Controller
2079 * @cdev: The FCoE Controller that is being enabled or disabled
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002080 *
Robert Love6e89ea32012-11-27 06:53:40 +00002081 * fcoe_sysfs will ensure that the state of 'enabled' has
2082 * changed, so no checking is necessary here. This routine simply
2083 * calls fcoe_enable or fcoe_disable, both of which are deprecated.
2084 * When those routines are removed the functionality can be merged
2085 * here.
2086 */
2087static int bnx2fc_ctlr_enabled(struct fcoe_ctlr_device *cdev)
2088{
2089 struct fcoe_ctlr *ctlr = fcoe_ctlr_device_priv(cdev);
2090 struct fc_lport *lport = ctlr->lp;
2091 struct net_device *netdev = bnx2fc_netdev(lport);
2092
2093 switch (cdev->enabled) {
2094 case FCOE_CTLR_ENABLED:
2095 return bnx2fc_enable(netdev);
2096 case FCOE_CTLR_DISABLED:
2097 return bnx2fc_disable(netdev);
2098 case FCOE_CTLR_UNUSED:
2099 default:
2100 return -ENOTSUPP;
2101 };
2102}
2103
2104enum bnx2fc_create_link_state {
2105 BNX2FC_CREATE_LINK_DOWN,
2106 BNX2FC_CREATE_LINK_UP,
2107};
2108
2109/**
2110 * _bnx2fc_create() - Create bnx2fc FCoE interface
2111 * @netdev : The net_device object the Ethernet interface to create on
2112 * @fip_mode: The FIP mode for this creation
2113 * @link_state: The ctlr link state on creation
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002114 *
Robert Love6e89ea32012-11-27 06:53:40 +00002115 * Called from either the libfcoe 'create' module parameter
2116 * via fcoe_create or from fcoe_syfs's ctlr_create file.
2117 *
2118 * libfcoe's 'create' module parameter is deprecated so some
2119 * consolidation of code can be done when that interface is
2120 * removed.
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002121 *
2122 * Returns: 0 for success
2123 */
Robert Love6e89ea32012-11-27 06:53:40 +00002124static int _bnx2fc_create(struct net_device *netdev,
2125 enum fip_state fip_mode,
2126 enum bnx2fc_create_link_state link_state)
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002127{
Robert Love6e89ea32012-11-27 06:53:40 +00002128 struct fcoe_ctlr_device *cdev;
Robert Lovefd8f8902012-05-22 19:06:16 -07002129 struct fcoe_ctlr *ctlr;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002130 struct bnx2fc_interface *interface;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002131 struct bnx2fc_hba *hba;
Bhanu Prakash Gollapudi7adc5a32012-06-04 16:15:44 -07002132 struct net_device *phys_dev = netdev;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002133 struct fc_lport *lport;
2134 struct ethtool_drvinfo drvinfo;
2135 int rc = 0;
Bhanu Prakash Gollapudi7adc5a32012-06-04 16:15:44 -07002136 int vlan_id = 0;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002137
2138 BNX2FC_MISC_DBG("Entered bnx2fc_create\n");
2139 if (fip_mode != FIP_MODE_FABRIC) {
2140 printk(KERN_ERR "fip mode not FABRIC\n");
2141 return -EIO;
2142 }
2143
Nithin Sujir6702ca12011-03-17 17:13:27 -07002144 rtnl_lock();
2145
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002146 mutex_lock(&bnx2fc_dev_lock);
2147
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002148 if (!try_module_get(THIS_MODULE)) {
2149 rc = -EINVAL;
2150 goto mod_err;
2151 }
2152
2153 /* obtain physical netdev */
Bhanu Prakash Gollapudi7adc5a32012-06-04 16:15:44 -07002154 if (netdev->priv_flags & IFF_802_1Q_VLAN)
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002155 phys_dev = vlan_dev_real_dev(netdev);
Bhanu Prakash Gollapudi7adc5a32012-06-04 16:15:44 -07002156
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002157 /* verify if the physical device is a netxtreme2 device */
2158 if (phys_dev->ethtool_ops && phys_dev->ethtool_ops->get_drvinfo) {
2159 memset(&drvinfo, 0, sizeof(drvinfo));
2160 phys_dev->ethtool_ops->get_drvinfo(phys_dev, &drvinfo);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002161 if (strncmp(drvinfo.driver, "bnx2x", strlen("bnx2x"))) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002162 printk(KERN_ERR PFX "Not a netxtreme2 device\n");
2163 rc = -EINVAL;
2164 goto netdev_err;
2165 }
2166 } else {
2167 printk(KERN_ERR PFX "unable to obtain drv_info\n");
2168 rc = -EINVAL;
2169 goto netdev_err;
2170 }
2171
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002172 /* obtain interface and initialize rest of the structure */
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002173 hba = bnx2fc_hba_lookup(phys_dev);
2174 if (!hba) {
2175 rc = -ENODEV;
2176 printk(KERN_ERR PFX "bnx2fc_create: hba not found\n");
2177 goto netdev_err;
2178 }
2179
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002180 if (bnx2fc_interface_lookup(netdev)) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002181 rc = -EEXIST;
2182 goto netdev_err;
2183 }
2184
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002185 interface = bnx2fc_interface_create(hba, netdev, fip_mode);
2186 if (!interface) {
2187 printk(KERN_ERR PFX "bnx2fc_interface_create failed\n");
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002188 goto ifput_err;
2189 }
2190
Bhanu Prakash Gollapudi7adc5a32012-06-04 16:15:44 -07002191 if (netdev->priv_flags & IFF_802_1Q_VLAN) {
2192 vlan_id = vlan_dev_vlan_id(netdev);
2193 interface->vlan_enabled = 1;
2194 }
2195
Robert Lovefd8f8902012-05-22 19:06:16 -07002196 ctlr = bnx2fc_to_ctlr(interface);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002197 interface->vlan_id = vlan_id;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002198
2199 interface->timer_work_queue =
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002200 create_singlethread_workqueue("bnx2fc_timer_wq");
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002201 if (!interface->timer_work_queue) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002202 printk(KERN_ERR PFX "ulp_init could not create timer_wq\n");
2203 rc = -EINVAL;
2204 goto ifput_err;
2205 }
2206
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002207 lport = bnx2fc_if_create(interface, &interface->hba->pcidev->dev, 0);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002208 if (!lport) {
2209 printk(KERN_ERR PFX "Failed to create interface (%s)\n",
2210 netdev->name);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002211 rc = -EINVAL;
2212 goto if_create_err;
2213 }
2214
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002215 /* Add interface to if_list */
2216 list_add_tail(&interface->list, &if_list);
2217
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002218 lport->boot_time = jiffies;
2219
2220 /* Make this master N_port */
Robert Lovefd8f8902012-05-22 19:06:16 -07002221 ctlr->lp = lport;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002222
Robert Love6e89ea32012-11-27 06:53:40 +00002223 cdev = fcoe_ctlr_to_ctlr_dev(ctlr);
2224
2225 if (link_state == BNX2FC_CREATE_LINK_UP)
2226 cdev->enabled = FCOE_CTLR_ENABLED;
2227 else
2228 cdev->enabled = FCOE_CTLR_DISABLED;
2229
2230 if (link_state == BNX2FC_CREATE_LINK_UP &&
2231 !bnx2fc_link_ok(lport)) {
Robert Lovefd8f8902012-05-22 19:06:16 -07002232 fcoe_ctlr_link_up(ctlr);
Bhanu Prakash Gollapudi8a5badf2011-08-30 15:54:48 -07002233 fc_host_port_type(lport->host) = FC_PORTTYPE_NPORT;
2234 set_bit(ADAPTER_STATE_READY, &interface->hba->adapter_state);
2235 }
2236
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002237 BNX2FC_HBA_DBG(lport, "create: START DISC\n");
2238 bnx2fc_start_disc(interface);
Robert Love6e89ea32012-11-27 06:53:40 +00002239
2240 if (link_state == BNX2FC_CREATE_LINK_UP)
2241 interface->enabled = true;
2242
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002243 /*
2244 * Release from kref_init in bnx2fc_interface_setup, on success
2245 * lport should be holding a reference taken in bnx2fc_if_create
2246 */
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002247 bnx2fc_interface_put(interface);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002248 /* put netdev that was held while calling dev_get_by_name */
2249 mutex_unlock(&bnx2fc_dev_lock);
2250 rtnl_unlock();
2251 return 0;
2252
2253if_create_err:
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002254 destroy_workqueue(interface->timer_work_queue);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002255ifput_err:
Bhanu Prakash Gollapudi013068f2011-08-30 15:54:52 -07002256 bnx2fc_net_cleanup(interface);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002257 bnx2fc_interface_put(interface);
Bhanu Prakash Gollapudi7d742f62012-01-23 18:00:48 -08002258 goto mod_err;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002259netdev_err:
2260 module_put(THIS_MODULE);
2261mod_err:
2262 mutex_unlock(&bnx2fc_dev_lock);
2263 rtnl_unlock();
2264 return rc;
2265}
2266
2267/**
Robert Love6e89ea32012-11-27 06:53:40 +00002268 * bnx2fc_create() - Create a bnx2fc interface
2269 * @netdev : The net_device object the Ethernet interface to create on
2270 * @fip_mode: The FIP mode for this creation
2271 *
2272 * Called from fcoe transport
2273 *
2274 * Returns: 0 for success
2275 */
2276static int bnx2fc_create(struct net_device *netdev, enum fip_state fip_mode)
2277{
2278 return _bnx2fc_create(netdev, fip_mode, BNX2FC_CREATE_LINK_UP);
2279}
2280
2281/**
2282 * bnx2fc_ctlr_alloc() - Allocate a bnx2fc interface from fcoe_sysfs
2283 * @netdev: The net_device to be used by the allocated FCoE Controller
2284 *
2285 * This routine is called from fcoe_sysfs. It will start the fcoe_ctlr
2286 * in a link_down state. The allows the user an opportunity to configure
2287 * the FCoE Controller from sysfs before enabling the FCoE Controller.
2288 *
2289 * Creating in with this routine starts the FCoE Controller in Fabric
2290 * mode. The user can change to VN2VN or another mode before enabling.
2291 */
2292static int bnx2fc_ctlr_alloc(struct net_device *netdev)
2293{
2294 return _bnx2fc_create(netdev, FIP_MODE_FABRIC,
2295 BNX2FC_CREATE_LINK_DOWN);
2296}
2297
2298/**
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002299 * bnx2fc_find_hba_for_cnic - maps cnic instance to bnx2fc hba instance
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002300 *
2301 * @cnic: Pointer to cnic device instance
2302 *
2303 **/
2304static struct bnx2fc_hba *bnx2fc_find_hba_for_cnic(struct cnic_dev *cnic)
2305{
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002306 struct bnx2fc_hba *hba;
2307
2308 /* Called with bnx2fc_dev_lock held */
Bhanu Prakash Gollapudid71fb3b2012-06-07 02:19:36 -07002309 list_for_each_entry(hba, &adapter_list, list) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002310 if (hba->cnic == cnic)
2311 return hba;
2312 }
2313 return NULL;
2314}
2315
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002316static struct bnx2fc_interface *bnx2fc_interface_lookup(struct net_device
2317 *netdev)
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002318{
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002319 struct bnx2fc_interface *interface;
2320
2321 /* Called with bnx2fc_dev_lock held */
2322 list_for_each_entry(interface, &if_list, list) {
2323 if (interface->netdev == netdev)
2324 return interface;
2325 }
2326 return NULL;
2327}
2328
2329static struct bnx2fc_hba *bnx2fc_hba_lookup(struct net_device
2330 *phys_dev)
2331{
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002332 struct bnx2fc_hba *hba;
2333
2334 /* Called with bnx2fc_dev_lock held */
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002335 list_for_each_entry(hba, &adapter_list, list) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002336 if (hba->phys_dev == phys_dev)
2337 return hba;
2338 }
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002339 printk(KERN_ERR PFX "adapter_lookup: hba NULL\n");
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002340 return NULL;
2341}
2342
2343/**
2344 * bnx2fc_ulp_exit - shuts down adapter instance and frees all resources
2345 *
2346 * @dev cnic device handle
2347 */
2348static void bnx2fc_ulp_exit(struct cnic_dev *dev)
2349{
2350 struct bnx2fc_hba *hba;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002351 struct bnx2fc_interface *interface, *tmp;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002352
2353 BNX2FC_MISC_DBG("Entered bnx2fc_ulp_exit\n");
2354
2355 if (!test_bit(CNIC_F_BNX2X_CLASS, &dev->flags)) {
2356 printk(KERN_ERR PFX "bnx2fc port check: %s, flags: %lx\n",
2357 dev->netdev->name, dev->flags);
2358 return;
2359 }
2360
2361 mutex_lock(&bnx2fc_dev_lock);
2362 hba = bnx2fc_find_hba_for_cnic(dev);
2363 if (!hba) {
2364 printk(KERN_ERR PFX "bnx2fc_ulp_exit: hba not found, dev 0%p\n",
2365 dev);
2366 mutex_unlock(&bnx2fc_dev_lock);
2367 return;
2368 }
2369
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002370 list_del_init(&hba->list);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002371 adapter_count--;
2372
Bhanu Prakash Gollapudiabc49a92011-08-04 17:38:42 -07002373 list_for_each_entry_safe(interface, tmp, &if_list, list)
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002374 /* destroy not called yet, move to quiesced list */
Bhanu Prakash Gollapudiabc49a92011-08-04 17:38:42 -07002375 if (interface->hba == hba)
Bhanu Prakash Gollapudieccdcd02011-08-24 18:56:42 -07002376 __bnx2fc_destroy(interface);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002377 mutex_unlock(&bnx2fc_dev_lock);
2378
2379 bnx2fc_ulp_stop(hba);
2380 /* unregister cnic device */
2381 if (test_and_clear_bit(BNX2FC_CNIC_REGISTERED, &hba->reg_with_cnic))
2382 hba->cnic->unregister_device(hba->cnic, CNIC_ULP_FCOE);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002383 bnx2fc_hba_destroy(hba);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002384}
2385
2386/**
2387 * bnx2fc_fcoe_reset - Resets the fcoe
2388 *
2389 * @shost: shost the reset is from
2390 *
2391 * Returns: always 0
2392 */
2393static int bnx2fc_fcoe_reset(struct Scsi_Host *shost)
2394{
2395 struct fc_lport *lport = shost_priv(shost);
2396 fc_lport_reset(lport);
2397 return 0;
2398}
2399
2400
2401static bool bnx2fc_match(struct net_device *netdev)
2402{
Bhanu Prakash Gollapudi7adc5a32012-06-04 16:15:44 -07002403 struct net_device *phys_dev = netdev;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002404
Bhanu Prakash Gollapudi7adc5a32012-06-04 16:15:44 -07002405 mutex_lock(&bnx2fc_dev_lock);
2406 if (netdev->priv_flags & IFF_802_1Q_VLAN)
2407 phys_dev = vlan_dev_real_dev(netdev);
2408
2409 if (bnx2fc_hba_lookup(phys_dev)) {
2410 mutex_unlock(&bnx2fc_dev_lock);
2411 return true;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002412 }
Bhanu Prakash Gollapudi7adc5a32012-06-04 16:15:44 -07002413
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002414 mutex_unlock(&bnx2fc_dev_lock);
2415 return false;
2416}
2417
2418
2419static struct fcoe_transport bnx2fc_transport = {
2420 .name = {"bnx2fc"},
2421 .attached = false,
2422 .list = LIST_HEAD_INIT(bnx2fc_transport.list),
Robert Love6e89ea32012-11-27 06:53:40 +00002423 .alloc = bnx2fc_ctlr_alloc,
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002424 .match = bnx2fc_match,
2425 .create = bnx2fc_create,
2426 .destroy = bnx2fc_destroy,
2427 .enable = bnx2fc_enable,
2428 .disable = bnx2fc_disable,
2429};
2430
2431/**
2432 * bnx2fc_percpu_thread_create - Create a receive thread for an
2433 * online CPU
2434 *
2435 * @cpu: cpu index for the online cpu
2436 */
2437static void bnx2fc_percpu_thread_create(unsigned int cpu)
2438{
2439 struct bnx2fc_percpu_s *p;
2440 struct task_struct *thread;
2441
2442 p = &per_cpu(bnx2fc_percpu, cpu);
2443
Eric Dumazet69614272012-06-04 16:15:42 -07002444 thread = kthread_create_on_node(bnx2fc_percpu_io_thread,
2445 (void *)p, cpu_to_node(cpu),
2446 "bnx2fc_thread/%d", cpu);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002447 /* bind thread to the cpu */
Bhanu Prakash Gollapudi32248762011-08-04 17:38:36 -07002448 if (likely(!IS_ERR(thread))) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002449 kthread_bind(thread, cpu);
2450 p->iothread = thread;
2451 wake_up_process(thread);
2452 }
2453}
2454
2455static void bnx2fc_percpu_thread_destroy(unsigned int cpu)
2456{
2457 struct bnx2fc_percpu_s *p;
2458 struct task_struct *thread;
2459 struct bnx2fc_work *work, *tmp;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002460
2461 BNX2FC_MISC_DBG("destroying io thread for CPU %d\n", cpu);
2462
2463 /* Prevent any new work from being queued for this CPU */
2464 p = &per_cpu(bnx2fc_percpu, cpu);
2465 spin_lock_bh(&p->fp_work_lock);
2466 thread = p->iothread;
2467 p->iothread = NULL;
2468
2469
2470 /* Free all work in the list */
Bhanu Prakash Gollapudi32248762011-08-04 17:38:36 -07002471 list_for_each_entry_safe(work, tmp, &p->work_list, list) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002472 list_del_init(&work->list);
2473 bnx2fc_process_cq_compl(work->tgt, work->wqe);
2474 kfree(work);
2475 }
2476
2477 spin_unlock_bh(&p->fp_work_lock);
2478
2479 if (thread)
2480 kthread_stop(thread);
2481}
2482
2483/**
2484 * bnx2fc_cpu_callback - Handler for CPU hotplug events
2485 *
2486 * @nfb: The callback data block
2487 * @action: The event triggering the callback
2488 * @hcpu: The index of the CPU that the event is for
2489 *
2490 * This creates or destroys per-CPU data for fcoe
2491 *
2492 * Returns NOTIFY_OK always.
2493 */
2494static int bnx2fc_cpu_callback(struct notifier_block *nfb,
2495 unsigned long action, void *hcpu)
2496{
2497 unsigned cpu = (unsigned long)hcpu;
2498
2499 switch (action) {
2500 case CPU_ONLINE:
2501 case CPU_ONLINE_FROZEN:
2502 printk(PFX "CPU %x online: Create Rx thread\n", cpu);
2503 bnx2fc_percpu_thread_create(cpu);
2504 break;
2505 case CPU_DEAD:
2506 case CPU_DEAD_FROZEN:
2507 printk(PFX "CPU %x offline: Remove Rx thread\n", cpu);
2508 bnx2fc_percpu_thread_destroy(cpu);
2509 break;
2510 default:
2511 break;
2512 }
2513 return NOTIFY_OK;
2514}
2515
2516/**
2517 * bnx2fc_mod_init - module init entry point
2518 *
2519 * Initialize driver wide global data structures, and register
2520 * with cnic module
2521 **/
2522static int __init bnx2fc_mod_init(void)
2523{
2524 struct fcoe_percpu_s *bg;
2525 struct task_struct *l2_thread;
2526 int rc = 0;
2527 unsigned int cpu = 0;
2528 struct bnx2fc_percpu_s *p;
2529
2530 printk(KERN_INFO PFX "%s", version);
2531
2532 /* register as a fcoe transport */
2533 rc = fcoe_transport_attach(&bnx2fc_transport);
2534 if (rc) {
2535 printk(KERN_ERR "failed to register an fcoe transport, check "
2536 "if libfcoe is loaded\n");
2537 goto out;
2538 }
2539
2540 INIT_LIST_HEAD(&adapter_list);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002541 INIT_LIST_HEAD(&if_list);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002542 mutex_init(&bnx2fc_dev_lock);
2543 adapter_count = 0;
2544
2545 /* Attach FC transport template */
2546 rc = bnx2fc_attach_transport();
2547 if (rc)
2548 goto detach_ft;
2549
2550 bnx2fc_wq = alloc_workqueue("bnx2fc", 0, 0);
2551 if (!bnx2fc_wq) {
2552 rc = -ENOMEM;
2553 goto release_bt;
2554 }
2555
2556 bg = &bnx2fc_global;
2557 skb_queue_head_init(&bg->fcoe_rx_list);
2558 l2_thread = kthread_create(bnx2fc_l2_rcv_thread,
2559 (void *)bg,
2560 "bnx2fc_l2_thread");
2561 if (IS_ERR(l2_thread)) {
2562 rc = PTR_ERR(l2_thread);
2563 goto free_wq;
2564 }
2565 wake_up_process(l2_thread);
2566 spin_lock_bh(&bg->fcoe_rx_list.lock);
2567 bg->thread = l2_thread;
2568 spin_unlock_bh(&bg->fcoe_rx_list.lock);
2569
2570 for_each_possible_cpu(cpu) {
2571 p = &per_cpu(bnx2fc_percpu, cpu);
2572 INIT_LIST_HEAD(&p->work_list);
2573 spin_lock_init(&p->fp_work_lock);
2574 }
2575
2576 for_each_online_cpu(cpu) {
2577 bnx2fc_percpu_thread_create(cpu);
2578 }
2579
2580 /* Initialize per CPU interrupt thread */
2581 register_hotcpu_notifier(&bnx2fc_cpu_notifier);
2582
2583 cnic_register_driver(CNIC_ULP_FCOE, &bnx2fc_cnic_cb);
2584
2585 return 0;
2586
2587free_wq:
2588 destroy_workqueue(bnx2fc_wq);
2589release_bt:
2590 bnx2fc_release_transport();
2591detach_ft:
2592 fcoe_transport_detach(&bnx2fc_transport);
2593out:
2594 return rc;
2595}
2596
2597static void __exit bnx2fc_mod_exit(void)
2598{
2599 LIST_HEAD(to_be_deleted);
2600 struct bnx2fc_hba *hba, *next;
2601 struct fcoe_percpu_s *bg;
2602 struct task_struct *l2_thread;
2603 struct sk_buff *skb;
2604 unsigned int cpu = 0;
2605
2606 /*
2607 * NOTE: Since cnic calls register_driver routine rtnl_lock,
2608 * it will have higher precedence than bnx2fc_dev_lock.
2609 * unregister_device() cannot be called with bnx2fc_dev_lock
2610 * held.
2611 */
2612 mutex_lock(&bnx2fc_dev_lock);
2613 list_splice(&adapter_list, &to_be_deleted);
2614 INIT_LIST_HEAD(&adapter_list);
2615 adapter_count = 0;
2616 mutex_unlock(&bnx2fc_dev_lock);
2617
2618 /* Unregister with cnic */
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002619 list_for_each_entry_safe(hba, next, &to_be_deleted, list) {
2620 list_del_init(&hba->list);
2621 printk(KERN_ERR PFX "MOD_EXIT:destroy hba = 0x%p\n",
2622 hba);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002623 bnx2fc_ulp_stop(hba);
2624 /* unregister cnic device */
2625 if (test_and_clear_bit(BNX2FC_CNIC_REGISTERED,
2626 &hba->reg_with_cnic))
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002627 hba->cnic->unregister_device(hba->cnic,
2628 CNIC_ULP_FCOE);
2629 bnx2fc_hba_destroy(hba);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002630 }
2631 cnic_unregister_driver(CNIC_ULP_FCOE);
2632
2633 /* Destroy global thread */
2634 bg = &bnx2fc_global;
2635 spin_lock_bh(&bg->fcoe_rx_list.lock);
2636 l2_thread = bg->thread;
2637 bg->thread = NULL;
2638 while ((skb = __skb_dequeue(&bg->fcoe_rx_list)) != NULL)
2639 kfree_skb(skb);
2640
2641 spin_unlock_bh(&bg->fcoe_rx_list.lock);
2642
2643 if (l2_thread)
2644 kthread_stop(l2_thread);
2645
2646 unregister_hotcpu_notifier(&bnx2fc_cpu_notifier);
2647
2648 /* Destroy per cpu threads */
2649 for_each_online_cpu(cpu) {
2650 bnx2fc_percpu_thread_destroy(cpu);
2651 }
2652
2653 destroy_workqueue(bnx2fc_wq);
2654 /*
2655 * detach from scsi transport
2656 * must happen after all destroys are done
2657 */
2658 bnx2fc_release_transport();
2659
2660 /* detach from fcoe transport */
2661 fcoe_transport_detach(&bnx2fc_transport);
2662}
2663
2664module_init(bnx2fc_mod_init);
2665module_exit(bnx2fc_mod_exit);
2666
Robert Love8d55e502012-05-22 19:06:26 -07002667static struct fcoe_sysfs_function_template bnx2fc_fcoe_sysfs_templ = {
Robert Love6e89ea32012-11-27 06:53:40 +00002668 .set_fcoe_ctlr_enabled = bnx2fc_ctlr_enabled,
Robert Love8d55e502012-05-22 19:06:26 -07002669 .get_fcoe_ctlr_link_fail = bnx2fc_ctlr_get_lesb,
2670 .get_fcoe_ctlr_vlink_fail = bnx2fc_ctlr_get_lesb,
2671 .get_fcoe_ctlr_miss_fka = bnx2fc_ctlr_get_lesb,
2672 .get_fcoe_ctlr_symb_err = bnx2fc_ctlr_get_lesb,
2673 .get_fcoe_ctlr_err_block = bnx2fc_ctlr_get_lesb,
2674 .get_fcoe_ctlr_fcs_error = bnx2fc_ctlr_get_lesb,
2675
2676 .get_fcoe_fcf_selected = fcoe_fcf_get_selected,
2677 .get_fcoe_fcf_vlan_id = bnx2fc_fcf_get_vlan_id,
2678};
2679
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002680static struct fc_function_template bnx2fc_transport_function = {
2681 .show_host_node_name = 1,
2682 .show_host_port_name = 1,
2683 .show_host_supported_classes = 1,
2684 .show_host_supported_fc4s = 1,
2685 .show_host_active_fc4s = 1,
2686 .show_host_maxframe_size = 1,
2687
2688 .show_host_port_id = 1,
2689 .show_host_supported_speeds = 1,
2690 .get_host_speed = fc_get_host_speed,
2691 .show_host_speed = 1,
2692 .show_host_port_type = 1,
2693 .get_host_port_state = fc_get_host_port_state,
2694 .show_host_port_state = 1,
2695 .show_host_symbolic_name = 1,
2696
2697 .dd_fcrport_size = (sizeof(struct fc_rport_libfc_priv) +
2698 sizeof(struct bnx2fc_rport)),
2699 .show_rport_maxframe_size = 1,
2700 .show_rport_supported_classes = 1,
2701
2702 .show_host_fabric_name = 1,
2703 .show_starget_node_name = 1,
2704 .show_starget_port_name = 1,
2705 .show_starget_port_id = 1,
2706 .set_rport_dev_loss_tmo = fc_set_rport_loss_tmo,
2707 .show_rport_dev_loss_tmo = 1,
2708 .get_fc_host_stats = bnx2fc_get_host_stats,
2709
2710 .issue_fc_host_lip = bnx2fc_fcoe_reset,
2711
2712 .terminate_rport_io = fc_rport_terminate_io,
2713
2714 .vport_create = bnx2fc_vport_create,
2715 .vport_delete = bnx2fc_vport_destroy,
2716 .vport_disable = bnx2fc_vport_disable,
Bhanu Prakash Gollapudie9a5289c2011-08-04 17:38:37 -07002717 .bsg_request = fc_lport_bsg_request,
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002718};
2719
2720static struct fc_function_template bnx2fc_vport_xport_function = {
2721 .show_host_node_name = 1,
2722 .show_host_port_name = 1,
2723 .show_host_supported_classes = 1,
2724 .show_host_supported_fc4s = 1,
2725 .show_host_active_fc4s = 1,
2726 .show_host_maxframe_size = 1,
2727
2728 .show_host_port_id = 1,
2729 .show_host_supported_speeds = 1,
2730 .get_host_speed = fc_get_host_speed,
2731 .show_host_speed = 1,
2732 .show_host_port_type = 1,
2733 .get_host_port_state = fc_get_host_port_state,
2734 .show_host_port_state = 1,
2735 .show_host_symbolic_name = 1,
2736
2737 .dd_fcrport_size = (sizeof(struct fc_rport_libfc_priv) +
2738 sizeof(struct bnx2fc_rport)),
2739 .show_rport_maxframe_size = 1,
2740 .show_rport_supported_classes = 1,
2741
2742 .show_host_fabric_name = 1,
2743 .show_starget_node_name = 1,
2744 .show_starget_port_name = 1,
2745 .show_starget_port_id = 1,
2746 .set_rport_dev_loss_tmo = fc_set_rport_loss_tmo,
2747 .show_rport_dev_loss_tmo = 1,
2748 .get_fc_host_stats = fc_get_host_stats,
2749 .issue_fc_host_lip = bnx2fc_fcoe_reset,
2750 .terminate_rport_io = fc_rport_terminate_io,
Bhanu Prakash Gollapudie9a5289c2011-08-04 17:38:37 -07002751 .bsg_request = fc_lport_bsg_request,
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002752};
2753
2754/**
2755 * scsi_host_template structure used while registering with SCSI-ml
2756 */
2757static struct scsi_host_template bnx2fc_shost_template = {
2758 .module = THIS_MODULE,
2759 .name = "Broadcom Offload FCoE Initiator",
2760 .queuecommand = bnx2fc_queuecommand,
2761 .eh_abort_handler = bnx2fc_eh_abort, /* abts */
2762 .eh_device_reset_handler = bnx2fc_eh_device_reset, /* lun reset */
2763 .eh_target_reset_handler = bnx2fc_eh_target_reset, /* tgt reset */
2764 .eh_host_reset_handler = fc_eh_host_reset,
2765 .slave_alloc = fc_slave_alloc,
2766 .change_queue_depth = fc_change_queue_depth,
2767 .change_queue_type = fc_change_queue_type,
2768 .this_id = -1,
2769 .cmd_per_lun = 3,
Bhanu Gollapudi0ea5c272011-03-17 17:13:29 -07002770 .can_queue = BNX2FC_CAN_QUEUE,
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002771 .use_clustering = ENABLE_CLUSTERING,
2772 .sg_tablesize = BNX2FC_MAX_BDS_PER_CMD,
2773 .max_sectors = 512,
2774};
2775
2776static struct libfc_function_template bnx2fc_libfc_fcn_templ = {
2777 .frame_send = bnx2fc_xmit,
2778 .elsct_send = bnx2fc_elsct_send,
2779 .fcp_abort_io = bnx2fc_abort_io,
2780 .fcp_cleanup = bnx2fc_cleanup,
Bhanu Prakash Gollapudif72f6972011-10-03 16:45:02 -07002781 .get_lesb = bnx2fc_get_lesb,
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002782 .rport_event_callback = bnx2fc_rport_event_handler,
2783};
2784
2785/**
2786 * bnx2fc_cnic_cb - global template of bnx2fc - cnic driver interface
2787 * structure carrying callback function pointers
2788 */
2789static struct cnic_ulp_ops bnx2fc_cnic_cb = {
2790 .owner = THIS_MODULE,
2791 .cnic_init = bnx2fc_ulp_init,
2792 .cnic_exit = bnx2fc_ulp_exit,
2793 .cnic_start = bnx2fc_ulp_start,
2794 .cnic_stop = bnx2fc_ulp_stop,
2795 .indicate_kcqes = bnx2fc_indicate_kcqe,
2796 .indicate_netevent = bnx2fc_indicate_netevent,
Barak Witkowski2e499d32012-06-26 01:31:19 +00002797 .cnic_get_stats = bnx2fc_ulp_get_stats,
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002798};