blob: d6800afd0232abf2d207162221d64c5f86cb26d3 [file] [log] [blame]
Chad Dupuisde909d82015-10-19 15:40:36 -04001/* bnx2fc_fcoe.c: QLogic Linux FCoE offload driver.
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002 * 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 *
Chad Dupuis97586092015-10-19 15:40:35 -04006 * Copyright (c) 2008-2013 Broadcom Corporation
7 * Copyright (c) 2014-2015 QLogic Corporation
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08008 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation.
12 *
13 * Written by: Bhanu Prakash Gollapudi (bprakash@broadcom.com)
14 */
15
16#include "bnx2fc.h"
17
18static struct list_head adapter_list;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -070019static struct list_head if_list;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -080020static u32 adapter_count;
21static DEFINE_MUTEX(bnx2fc_dev_lock);
22DEFINE_PER_CPU(struct bnx2fc_percpu_s, bnx2fc_percpu);
23
24#define DRV_MODULE_NAME "bnx2fc"
25#define DRV_MODULE_VERSION BNX2FC_VERSION
Chad Dupuisedb394b2015-10-19 15:40:41 -040026#define DRV_MODULE_RELDATE "October 15, 2015"
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -080027
28
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080029static char version[] =
Chad Dupuisde909d82015-10-19 15:40:36 -040030 "QLogic FCoE Driver " DRV_MODULE_NAME \
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -080031 " v" DRV_MODULE_VERSION " (" DRV_MODULE_RELDATE ")\n";
32
33
34MODULE_AUTHOR("Bhanu Prakash Gollapudi <bprakash@broadcom.com>");
Chad Dupuisde909d82015-10-19 15:40:36 -040035MODULE_DESCRIPTION("QLogic FCoE Driver");
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -080036MODULE_LICENSE("GPL");
37MODULE_VERSION(DRV_MODULE_VERSION);
38
39#define BNX2FC_MAX_QUEUE_DEPTH 256
40#define BNX2FC_MIN_QUEUE_DEPTH 32
41#define FCOE_WORD_TO_BYTE 4
42
43static struct scsi_transport_template *bnx2fc_transport_template;
44static struct scsi_transport_template *bnx2fc_vport_xport_template;
45
46struct workqueue_struct *bnx2fc_wq;
47
48/* bnx2fc structure needs only one instance of the fcoe_percpu_s structure.
49 * Here the io threads are per cpu but the l2 thread is just one
50 */
51struct fcoe_percpu_s bnx2fc_global;
52DEFINE_SPINLOCK(bnx2fc_global_lock);
53
54static struct cnic_ulp_ops bnx2fc_cnic_cb;
55static struct libfc_function_template bnx2fc_libfc_fcn_templ;
56static struct scsi_host_template bnx2fc_shost_template;
57static struct fc_function_template bnx2fc_transport_function;
Robert Love8d55e502012-05-22 19:06:26 -070058static struct fcoe_sysfs_function_template bnx2fc_fcoe_sysfs_templ;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -080059static struct fc_function_template bnx2fc_vport_xport_function;
60static int bnx2fc_create(struct net_device *netdev, enum fip_state fip_mode);
Bhanu Prakash Gollapudieccdcd02011-08-24 18:56:42 -070061static void __bnx2fc_destroy(struct bnx2fc_interface *interface);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -080062static int bnx2fc_destroy(struct net_device *net_device);
63static int bnx2fc_enable(struct net_device *netdev);
64static int bnx2fc_disable(struct net_device *netdev);
65
Robert Love6e89ea32012-11-27 06:53:40 +000066/* fcoe_syfs control interface handlers */
67static int bnx2fc_ctlr_alloc(struct net_device *netdev);
68static int bnx2fc_ctlr_enabled(struct fcoe_ctlr_device *cdev);
69
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -080070static void bnx2fc_recv_frame(struct sk_buff *skb);
71
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -070072static void bnx2fc_start_disc(struct bnx2fc_interface *interface);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -080073static int bnx2fc_shost_config(struct fc_lport *lport, struct device *dev);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -080074static int bnx2fc_lport_config(struct fc_lport *lport);
Bhanu Prakash Gollapudi0eb43b42013-04-22 19:22:30 +000075static int bnx2fc_em_config(struct fc_lport *lport, struct bnx2fc_hba *hba);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -080076static int bnx2fc_bind_adapter_devices(struct bnx2fc_hba *hba);
77static void bnx2fc_unbind_adapter_devices(struct bnx2fc_hba *hba);
78static int bnx2fc_bind_pcidev(struct bnx2fc_hba *hba);
79static void bnx2fc_unbind_pcidev(struct bnx2fc_hba *hba);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -070080static struct fc_lport *bnx2fc_if_create(struct bnx2fc_interface *interface,
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -080081 struct device *parent, int npiv);
82static void bnx2fc_destroy_work(struct work_struct *work);
83
84static struct bnx2fc_hba *bnx2fc_hba_lookup(struct net_device *phys_dev);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -070085static struct bnx2fc_interface *bnx2fc_interface_lookup(struct net_device
86 *phys_dev);
Bhanu Prakash Gollapudiabc49a92011-08-04 17:38:42 -070087static inline void bnx2fc_interface_put(struct bnx2fc_interface *interface);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -080088static struct bnx2fc_hba *bnx2fc_find_hba_for_cnic(struct cnic_dev *cnic);
89
90static int bnx2fc_fw_init(struct bnx2fc_hba *hba);
91static void bnx2fc_fw_destroy(struct bnx2fc_hba *hba);
92
93static void bnx2fc_port_shutdown(struct fc_lport *lport);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -070094static void bnx2fc_stop(struct bnx2fc_interface *interface);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -080095static int __init bnx2fc_mod_init(void);
96static void __exit bnx2fc_mod_exit(void);
97
98unsigned int bnx2fc_debug_level;
99module_param_named(debug_logging, bnx2fc_debug_level, int, S_IRUGO|S_IWUSR);
Jose Castillod4faee02016-01-29 14:39:26 +0000100MODULE_PARM_DESC(debug_logging,
101 "Option to enable extended logging,\n"
102 "\t\tDefault is 0 - no logging.\n"
103 "\t\t0x01 - SCSI cmd error, cleanup.\n"
104 "\t\t0x02 - Session setup, cleanup, etc.\n"
105 "\t\t0x04 - lport events, link, mtu, etc.\n"
106 "\t\t0x08 - ELS logs.\n"
107 "\t\t0x10 - fcoe L2 fame related logs.\n"
108 "\t\t0xff - LOG all messages.");
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800109
Joe Carnuccio10755d32016-04-07 09:07:56 -0400110uint bnx2fc_devloss_tmo;
111module_param_named(devloss_tmo, bnx2fc_devloss_tmo, uint, S_IRUGO);
112MODULE_PARM_DESC(devloss_tmo, " Change devloss_tmo for the remote ports "
113 "attached via bnx2fc.");
114
115uint bnx2fc_max_luns = BNX2FC_MAX_LUN;
116module_param_named(max_luns, bnx2fc_max_luns, uint, S_IRUGO);
117MODULE_PARM_DESC(max_luns, " Change the default max_lun per SCSI host. Default "
118 "0xffff.");
119
120uint bnx2fc_queue_depth;
121module_param_named(queue_depth, bnx2fc_queue_depth, uint, S_IRUGO);
122MODULE_PARM_DESC(queue_depth, " Change the default queue depth of SCSI devices "
123 "attached via bnx2fc.");
124
Chad Dupuis3f12f762016-04-07 09:07:57 -0400125uint bnx2fc_log_fka;
126module_param_named(log_fka, bnx2fc_log_fka, uint, S_IRUGO|S_IWUSR);
127MODULE_PARM_DESC(log_fka, " Print message to kernel log when fcoe is "
128 "initiating a FIP keep alive when debug logging is enabled.");
129
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800130static int bnx2fc_cpu_callback(struct notifier_block *nfb,
131 unsigned long action, void *hcpu);
132/* notification function for CPU hotplug events */
133static struct notifier_block bnx2fc_cpu_notifier = {
134 .notifier_call = bnx2fc_cpu_callback,
135};
136
Bhanu Prakash Gollapudif72f6972011-10-03 16:45:02 -0700137static inline struct net_device *bnx2fc_netdev(const struct fc_lport *lport)
138{
139 return ((struct bnx2fc_interface *)
140 ((struct fcoe_port *)lport_priv(lport))->priv)->netdev;
141}
142
Robert Love8d55e502012-05-22 19:06:26 -0700143static void bnx2fc_fcf_get_vlan_id(struct fcoe_fcf_device *fcf_dev)
144{
145 struct fcoe_ctlr_device *ctlr_dev =
146 fcoe_fcf_dev_to_ctlr_dev(fcf_dev);
147 struct fcoe_ctlr *ctlr = fcoe_ctlr_device_priv(ctlr_dev);
148 struct bnx2fc_interface *fcoe = fcoe_ctlr_priv(ctlr);
149
150 fcf_dev->vlan_id = fcoe->vlan_id;
151}
152
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800153static void bnx2fc_clean_rx_queue(struct fc_lport *lp)
154{
155 struct fcoe_percpu_s *bg;
156 struct fcoe_rcv_info *fr;
157 struct sk_buff_head *list;
158 struct sk_buff *skb, *next;
159 struct sk_buff *head;
160
161 bg = &bnx2fc_global;
162 spin_lock_bh(&bg->fcoe_rx_list.lock);
163 list = &bg->fcoe_rx_list;
164 head = list->next;
165 for (skb = head; skb != (struct sk_buff *)list;
166 skb = next) {
167 next = skb->next;
168 fr = fcoe_dev_from_skb(skb);
169 if (fr->fr_dev == lp) {
170 __skb_unlink(skb, list);
171 kfree_skb(skb);
172 }
173 }
174 spin_unlock_bh(&bg->fcoe_rx_list.lock);
175}
176
177int bnx2fc_get_paged_crc_eof(struct sk_buff *skb, int tlen)
178{
179 int rc;
180 spin_lock(&bnx2fc_global_lock);
181 rc = fcoe_get_paged_crc_eof(skb, tlen, &bnx2fc_global);
182 spin_unlock(&bnx2fc_global_lock);
183
184 return rc;
185}
186
187static void bnx2fc_abort_io(struct fc_lport *lport)
188{
189 /*
190 * This function is no-op for bnx2fc, but we do
191 * not want to leave it as NULL either, as libfc
192 * can call the default function which is
193 * fc_fcp_abort_io.
194 */
195}
196
197static void bnx2fc_cleanup(struct fc_lport *lport)
198{
199 struct fcoe_port *port = lport_priv(lport);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700200 struct bnx2fc_interface *interface = port->priv;
201 struct bnx2fc_hba *hba = interface->hba;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800202 struct bnx2fc_rport *tgt;
203 int i;
204
205 BNX2FC_MISC_DBG("Entered %s\n", __func__);
206 mutex_lock(&hba->hba_mutex);
207 spin_lock_bh(&hba->hba_lock);
208 for (i = 0; i < BNX2FC_NUM_MAX_SESS; i++) {
209 tgt = hba->tgt_ofld_list[i];
210 if (tgt) {
211 /* Cleanup IOs belonging to requested vport */
212 if (tgt->port == port) {
213 spin_unlock_bh(&hba->hba_lock);
214 BNX2FC_TGT_DBG(tgt, "flush/cleanup\n");
215 bnx2fc_flush_active_ios(tgt);
216 spin_lock_bh(&hba->hba_lock);
217 }
218 }
219 }
220 spin_unlock_bh(&hba->hba_lock);
221 mutex_unlock(&hba->hba_mutex);
222}
223
224static int bnx2fc_xmit_l2_frame(struct bnx2fc_rport *tgt,
225 struct fc_frame *fp)
226{
227 struct fc_rport_priv *rdata = tgt->rdata;
228 struct fc_frame_header *fh;
229 int rc = 0;
230
231 fh = fc_frame_header_get(fp);
232 BNX2FC_TGT_DBG(tgt, "Xmit L2 frame rport = 0x%x, oxid = 0x%x, "
233 "r_ctl = 0x%x\n", rdata->ids.port_id,
234 ntohs(fh->fh_ox_id), fh->fh_r_ctl);
235 if ((fh->fh_type == FC_TYPE_ELS) &&
236 (fh->fh_r_ctl == FC_RCTL_ELS_REQ)) {
237
238 switch (fc_frame_payload_op(fp)) {
239 case ELS_ADISC:
240 rc = bnx2fc_send_adisc(tgt, fp);
241 break;
242 case ELS_LOGO:
243 rc = bnx2fc_send_logo(tgt, fp);
244 break;
245 case ELS_RLS:
246 rc = bnx2fc_send_rls(tgt, fp);
247 break;
248 default:
249 break;
250 }
251 } else if ((fh->fh_type == FC_TYPE_BLS) &&
252 (fh->fh_r_ctl == FC_RCTL_BA_ABTS))
253 BNX2FC_TGT_DBG(tgt, "ABTS frame\n");
254 else {
255 BNX2FC_TGT_DBG(tgt, "Send L2 frame type 0x%x "
256 "rctl 0x%x thru non-offload path\n",
257 fh->fh_type, fh->fh_r_ctl);
258 return -ENODEV;
259 }
260 if (rc)
261 return -ENOMEM;
262 else
263 return 0;
264}
265
266/**
267 * bnx2fc_xmit - bnx2fc's FCoE frame transmit function
268 *
269 * @lport: the associated local port
270 * @fp: the fc_frame to be transmitted
271 */
272static int bnx2fc_xmit(struct fc_lport *lport, struct fc_frame *fp)
273{
274 struct ethhdr *eh;
275 struct fcoe_crc_eof *cp;
276 struct sk_buff *skb;
277 struct fc_frame_header *fh;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700278 struct bnx2fc_interface *interface;
Robert Lovefd8f8902012-05-22 19:06:16 -0700279 struct fcoe_ctlr *ctlr;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700280 struct bnx2fc_hba *hba;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800281 struct fcoe_port *port;
282 struct fcoe_hdr *hp;
283 struct bnx2fc_rport *tgt;
Vasu Dev1bd49b42012-05-25 10:26:43 -0700284 struct fc_stats *stats;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800285 u8 sof, eof;
286 u32 crc;
287 unsigned int hlen, tlen, elen;
288 int wlen, rc = 0;
289
290 port = (struct fcoe_port *)lport_priv(lport);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700291 interface = port->priv;
Robert Lovefd8f8902012-05-22 19:06:16 -0700292 ctlr = bnx2fc_to_ctlr(interface);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700293 hba = interface->hba;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800294
295 fh = fc_frame_header_get(fp);
296
297 skb = fp_skb(fp);
298 if (!lport->link_up) {
299 BNX2FC_HBA_DBG(lport, "bnx2fc_xmit link down\n");
300 kfree_skb(skb);
301 return 0;
302 }
303
304 if (unlikely(fh->fh_r_ctl == FC_RCTL_ELS_REQ)) {
Robert Lovefd8f8902012-05-22 19:06:16 -0700305 if (!ctlr->sel_fcf) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800306 BNX2FC_HBA_DBG(lport, "FCF not selected yet!\n");
307 kfree_skb(skb);
308 return -EINVAL;
309 }
Robert Lovefd8f8902012-05-22 19:06:16 -0700310 if (fcoe_ctlr_els_send(ctlr, lport, skb))
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800311 return 0;
312 }
313
314 sof = fr_sof(fp);
315 eof = fr_eof(fp);
316
317 /*
318 * Snoop the frame header to check if the frame is for
319 * an offloaded session
320 */
321 /*
322 * tgt_ofld_list access is synchronized using
323 * both hba mutex and hba lock. Atleast hba mutex or
324 * hba lock needs to be held for read access.
325 */
326
327 spin_lock_bh(&hba->hba_lock);
328 tgt = bnx2fc_tgt_lookup(port, ntoh24(fh->fh_d_id));
329 if (tgt && (test_bit(BNX2FC_FLAG_SESSION_READY, &tgt->flags))) {
330 /* This frame is for offloaded session */
331 BNX2FC_HBA_DBG(lport, "xmit: Frame is for offloaded session "
332 "port_id = 0x%x\n", ntoh24(fh->fh_d_id));
333 spin_unlock_bh(&hba->hba_lock);
334 rc = bnx2fc_xmit_l2_frame(tgt, fp);
335 if (rc != -ENODEV) {
336 kfree_skb(skb);
337 return rc;
338 }
339 } else {
340 spin_unlock_bh(&hba->hba_lock);
341 }
342
343 elen = sizeof(struct ethhdr);
344 hlen = sizeof(struct fcoe_hdr);
345 tlen = sizeof(struct fcoe_crc_eof);
346 wlen = (skb->len - tlen + sizeof(crc)) / FCOE_WORD_TO_BYTE;
347
348 skb->ip_summed = CHECKSUM_NONE;
349 crc = fcoe_fc_crc(fp);
350
351 /* copy port crc and eof to the skb buff */
352 if (skb_is_nonlinear(skb)) {
353 skb_frag_t *frag;
354 if (bnx2fc_get_paged_crc_eof(skb, tlen)) {
355 kfree_skb(skb);
356 return -ENOMEM;
357 }
358 frag = &skb_shinfo(skb)->frags[skb_shinfo(skb)->nr_frags - 1];
Cong Wang77dfce02011-11-25 23:14:23 +0800359 cp = kmap_atomic(skb_frag_page(frag)) + frag->page_offset;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800360 } else {
361 cp = (struct fcoe_crc_eof *)skb_put(skb, tlen);
362 }
363
364 memset(cp, 0, sizeof(*cp));
365 cp->fcoe_eof = eof;
366 cp->fcoe_crc32 = cpu_to_le32(~crc);
367 if (skb_is_nonlinear(skb)) {
Cong Wang77dfce02011-11-25 23:14:23 +0800368 kunmap_atomic(cp);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800369 cp = NULL;
370 }
371
372 /* adjust skb network/transport offsets to match mac/fcoe/port */
373 skb_push(skb, elen + hlen);
374 skb_reset_mac_header(skb);
375 skb_reset_network_header(skb);
376 skb->mac_len = elen;
377 skb->protocol = htons(ETH_P_FCOE);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700378 skb->dev = interface->netdev;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800379
380 /* fill up mac and fcoe headers */
381 eh = eth_hdr(skb);
382 eh->h_proto = htons(ETH_P_FCOE);
Robert Lovefd8f8902012-05-22 19:06:16 -0700383 if (ctlr->map_dest)
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800384 fc_fcoe_set_mac(eh->h_dest, fh->fh_d_id);
385 else
386 /* insert GW address */
Robert Lovefd8f8902012-05-22 19:06:16 -0700387 memcpy(eh->h_dest, ctlr->dest_addr, ETH_ALEN);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800388
Robert Lovefd8f8902012-05-22 19:06:16 -0700389 if (unlikely(ctlr->flogi_oxid != FC_XID_UNKNOWN))
390 memcpy(eh->h_source, ctlr->ctl_src_addr, ETH_ALEN);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800391 else
392 memcpy(eh->h_source, port->data_src_addr, ETH_ALEN);
393
394 hp = (struct fcoe_hdr *)(eh + 1);
395 memset(hp, 0, sizeof(*hp));
396 if (FC_FCOE_VER)
397 FC_FCOE_ENCAPS_VER(hp, FC_FCOE_VER);
398 hp->fcoe_sof = sof;
399
400 /* fcoe lso, mss is in max_payload which is non-zero for FCP data */
401 if (lport->seq_offload && fr_max_payload(fp)) {
402 skb_shinfo(skb)->gso_type = SKB_GSO_FCOE;
403 skb_shinfo(skb)->gso_size = fr_max_payload(fp);
404 } else {
405 skb_shinfo(skb)->gso_type = 0;
406 skb_shinfo(skb)->gso_size = 0;
407 }
408
409 /*update tx stats */
Vasu Dev1bd49b42012-05-25 10:26:43 -0700410 stats = per_cpu_ptr(lport->stats, get_cpu());
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800411 stats->TxFrames++;
412 stats->TxWords += wlen;
413 put_cpu();
414
415 /* send down to lld */
416 fr_dev(fp) = lport;
417 if (port->fcoe_pending_queue.qlen)
418 fcoe_check_wait_queue(lport, skb);
419 else if (fcoe_start_io(skb))
420 fcoe_check_wait_queue(lport, skb);
421
422 return 0;
423}
424
425/**
426 * bnx2fc_rcv - This is bnx2fc's receive function called by NET_RX_SOFTIRQ
427 *
428 * @skb: the receive socket buffer
429 * @dev: associated net device
430 * @ptype: context
431 * @olddev: last device
432 *
433 * This function receives the packet and builds FC frame and passes it up
434 */
435static int bnx2fc_rcv(struct sk_buff *skb, struct net_device *dev,
436 struct packet_type *ptype, struct net_device *olddev)
437{
438 struct fc_lport *lport;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700439 struct bnx2fc_interface *interface;
Robert Lovefd8f8902012-05-22 19:06:16 -0700440 struct fcoe_ctlr *ctlr;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800441 struct fc_frame_header *fh;
442 struct fcoe_rcv_info *fr;
443 struct fcoe_percpu_s *bg;
Maurizio Lombardi01a4cc42014-11-20 11:17:33 +0100444 struct sk_buff *tmp_skb;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800445 unsigned short oxid;
446
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700447 interface = container_of(ptype, struct bnx2fc_interface,
448 fcoe_packet_type);
Robert Lovefd8f8902012-05-22 19:06:16 -0700449 ctlr = bnx2fc_to_ctlr(interface);
450 lport = ctlr->lp;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800451
452 if (unlikely(lport == NULL)) {
Bhanu Prakash Gollapudib2a554f2011-06-27 23:30:53 -0700453 printk(KERN_ERR PFX "bnx2fc_rcv: lport is NULL\n");
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800454 goto err;
455 }
456
Maurizio Lombardi01a4cc42014-11-20 11:17:33 +0100457 tmp_skb = skb_share_check(skb, GFP_ATOMIC);
458 if (!tmp_skb)
459 goto err;
460
461 skb = tmp_skb;
462
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800463 if (unlikely(eth_hdr(skb)->h_proto != htons(ETH_P_FCOE))) {
Bhanu Prakash Gollapudib2a554f2011-06-27 23:30:53 -0700464 printk(KERN_ERR PFX "bnx2fc_rcv: Wrong FC type frame\n");
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800465 goto err;
466 }
467
468 /*
469 * Check for minimum frame length, and make sure required FCoE
470 * and FC headers are pulled into the linear data area.
471 */
472 if (unlikely((skb->len < FCOE_MIN_FRAME) ||
473 !pskb_may_pull(skb, FCOE_HEADER_LEN)))
474 goto err;
475
476 skb_set_transport_header(skb, sizeof(struct fcoe_hdr));
477 fh = (struct fc_frame_header *) skb_transport_header(skb);
478
479 oxid = ntohs(fh->fh_ox_id);
480
481 fr = fcoe_dev_from_skb(skb);
482 fr->fr_dev = lport;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800483
484 bg = &bnx2fc_global;
Neil Hormanfc05ab72012-03-09 14:50:13 -0800485 spin_lock(&bg->fcoe_rx_list.lock);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800486
487 __skb_queue_tail(&bg->fcoe_rx_list, skb);
488 if (bg->fcoe_rx_list.qlen == 1)
Sebastian Andrzej Siewior4b9bc862016-04-12 17:16:54 +0200489 wake_up_process(bg->kthread);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800490
Neil Hormanfc05ab72012-03-09 14:50:13 -0800491 spin_unlock(&bg->fcoe_rx_list.lock);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800492
493 return 0;
494err:
495 kfree_skb(skb);
496 return -1;
497}
498
499static int bnx2fc_l2_rcv_thread(void *arg)
500{
501 struct fcoe_percpu_s *bg = arg;
502 struct sk_buff *skb;
503
Dongsheng Yang8698a742014-03-11 18:09:12 +0800504 set_user_nice(current, MIN_NICE);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800505 set_current_state(TASK_INTERRUPTIBLE);
506 while (!kthread_should_stop()) {
507 schedule();
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800508 spin_lock_bh(&bg->fcoe_rx_list.lock);
509 while ((skb = __skb_dequeue(&bg->fcoe_rx_list)) != NULL) {
510 spin_unlock_bh(&bg->fcoe_rx_list.lock);
511 bnx2fc_recv_frame(skb);
512 spin_lock_bh(&bg->fcoe_rx_list.lock);
513 }
Bhanu Gollapudifee78712011-03-21 18:51:13 -0700514 __set_current_state(TASK_INTERRUPTIBLE);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800515 spin_unlock_bh(&bg->fcoe_rx_list.lock);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800516 }
Bhanu Gollapudifee78712011-03-21 18:51:13 -0700517 __set_current_state(TASK_RUNNING);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800518 return 0;
519}
520
521
522static void bnx2fc_recv_frame(struct sk_buff *skb)
523{
524 u32 fr_len;
525 struct fc_lport *lport;
526 struct fcoe_rcv_info *fr;
Vasu Dev1bd49b42012-05-25 10:26:43 -0700527 struct fc_stats *stats;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800528 struct fc_frame_header *fh;
529 struct fcoe_crc_eof crc_eof;
530 struct fc_frame *fp;
531 struct fc_lport *vn_port;
532 struct fcoe_port *port;
533 u8 *mac = NULL;
534 u8 *dest_mac = NULL;
535 struct fcoe_hdr *hp;
536
537 fr = fcoe_dev_from_skb(skb);
538 lport = fr->fr_dev;
539 if (unlikely(lport == NULL)) {
Bhanu Prakash Gollapudib2a554f2011-06-27 23:30:53 -0700540 printk(KERN_ERR PFX "Invalid lport struct\n");
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800541 kfree_skb(skb);
542 return;
543 }
544
545 if (skb_is_nonlinear(skb))
546 skb_linearize(skb);
547 mac = eth_hdr(skb)->h_source;
548 dest_mac = eth_hdr(skb)->h_dest;
549
550 /* Pull the header */
551 hp = (struct fcoe_hdr *) skb_network_header(skb);
552 fh = (struct fc_frame_header *) skb_transport_header(skb);
553 skb_pull(skb, sizeof(struct fcoe_hdr));
554 fr_len = skb->len - sizeof(struct fcoe_crc_eof);
555
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800556 fp = (struct fc_frame *)skb;
557 fc_frame_init(fp);
558 fr_dev(fp) = lport;
559 fr_sof(fp) = hp->fcoe_sof;
560 if (skb_copy_bits(skb, fr_len, &crc_eof, sizeof(crc_eof))) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800561 kfree_skb(skb);
562 return;
563 }
564 fr_eof(fp) = crc_eof.fcoe_eof;
565 fr_crc(fp) = crc_eof.fcoe_crc32;
566 if (pskb_trim(skb, fr_len)) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800567 kfree_skb(skb);
568 return;
569 }
570
571 fh = fc_frame_header_get(fp);
572
573 vn_port = fc_vport_id_lookup(lport, ntoh24(fh->fh_d_id));
574 if (vn_port) {
575 port = lport_priv(vn_port);
Joe Perches6942df72013-09-02 03:32:33 +0000576 if (!ether_addr_equal(port->data_src_addr, dest_mac)) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800577 BNX2FC_HBA_DBG(lport, "fpma mismatch\n");
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800578 kfree_skb(skb);
579 return;
580 }
581 }
582 if (fh->fh_r_ctl == FC_RCTL_DD_SOL_DATA &&
583 fh->fh_type == FC_TYPE_FCP) {
584 /* Drop FCP data. We dont this in L2 path */
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800585 kfree_skb(skb);
586 return;
587 }
588 if (fh->fh_r_ctl == FC_RCTL_ELS_REQ &&
589 fh->fh_type == FC_TYPE_ELS) {
590 switch (fc_frame_payload_op(fp)) {
591 case ELS_LOGO:
592 if (ntoh24(fh->fh_s_id) == FC_FID_FLOGI) {
593 /* drop non-FIP LOGO */
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800594 kfree_skb(skb);
595 return;
596 }
597 break;
598 }
599 }
Bhanu Prakash Gollapudi3f8744d2011-08-04 17:38:48 -0700600
601 if (fh->fh_r_ctl == FC_RCTL_BA_ABTS) {
602 /* Drop incoming ABTS */
Bhanu Prakash Gollapudi3f8744d2011-08-04 17:38:48 -0700603 kfree_skb(skb);
604 return;
605 }
606
Neil Hormand576a5e2014-06-23 10:41:02 -0400607 stats = per_cpu_ptr(lport->stats, smp_processor_id());
608 stats->RxFrames++;
609 stats->RxWords += fr_len / FCOE_WORD_TO_BYTE;
610
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800611 if (le32_to_cpu(fr_crc(fp)) !=
612 ~crc32(~0, skb->data, fr_len)) {
613 if (stats->InvalidCRCCount < 5)
614 printk(KERN_WARNING PFX "dropping frame with "
615 "CRC error\n");
616 stats->InvalidCRCCount++;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800617 kfree_skb(skb);
618 return;
619 }
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800620 fc_exch_recv(lport, fp);
621}
622
623/**
624 * bnx2fc_percpu_io_thread - thread per cpu for ios
625 *
626 * @arg: ptr to bnx2fc_percpu_info structure
627 */
628int bnx2fc_percpu_io_thread(void *arg)
629{
630 struct bnx2fc_percpu_s *p = arg;
631 struct bnx2fc_work *work, *tmp;
632 LIST_HEAD(work_list);
633
Dongsheng Yang8698a742014-03-11 18:09:12 +0800634 set_user_nice(current, MIN_NICE);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800635 set_current_state(TASK_INTERRUPTIBLE);
636 while (!kthread_should_stop()) {
637 schedule();
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800638 spin_lock_bh(&p->fp_work_lock);
639 while (!list_empty(&p->work_list)) {
640 list_splice_init(&p->work_list, &work_list);
641 spin_unlock_bh(&p->fp_work_lock);
642
643 list_for_each_entry_safe(work, tmp, &work_list, list) {
644 list_del_init(&work->list);
645 bnx2fc_process_cq_compl(work->tgt, work->wqe);
646 kfree(work);
647 }
648
649 spin_lock_bh(&p->fp_work_lock);
650 }
Bhanu Gollapudifee78712011-03-21 18:51:13 -0700651 __set_current_state(TASK_INTERRUPTIBLE);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800652 spin_unlock_bh(&p->fp_work_lock);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800653 }
Bhanu Gollapudifee78712011-03-21 18:51:13 -0700654 __set_current_state(TASK_RUNNING);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800655
656 return 0;
657}
658
659static struct fc_host_statistics *bnx2fc_get_host_stats(struct Scsi_Host *shost)
660{
661 struct fc_host_statistics *bnx2fc_stats;
662 struct fc_lport *lport = shost_priv(shost);
663 struct fcoe_port *port = lport_priv(lport);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700664 struct bnx2fc_interface *interface = port->priv;
665 struct bnx2fc_hba *hba = interface->hba;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800666 struct fcoe_statistics_params *fw_stats;
667 int rc = 0;
668
669 fw_stats = (struct fcoe_statistics_params *)hba->stats_buffer;
670 if (!fw_stats)
671 return NULL;
672
673 bnx2fc_stats = fc_get_host_stats(shost);
674
675 init_completion(&hba->stat_req_done);
676 if (bnx2fc_send_stat_req(hba))
677 return bnx2fc_stats;
678 rc = wait_for_completion_timeout(&hba->stat_req_done, (2 * HZ));
679 if (!rc) {
680 BNX2FC_HBA_DBG(lport, "FW stat req timed out\n");
681 return bnx2fc_stats;
682 }
Bhanu Prakash Gollapudif246fe22012-12-21 19:40:32 -0800683 BNX2FC_STATS(hba, rx_stat2, fc_crc_cnt);
684 bnx2fc_stats->invalid_crc_count += hba->bfw_stats.fc_crc_cnt;
685 BNX2FC_STATS(hba, tx_stat, fcoe_tx_pkt_cnt);
686 bnx2fc_stats->tx_frames += hba->bfw_stats.fcoe_tx_pkt_cnt;
687 BNX2FC_STATS(hba, tx_stat, fcoe_tx_byte_cnt);
688 bnx2fc_stats->tx_words += ((hba->bfw_stats.fcoe_tx_byte_cnt) / 4);
689 BNX2FC_STATS(hba, rx_stat0, fcoe_rx_pkt_cnt);
690 bnx2fc_stats->rx_frames += hba->bfw_stats.fcoe_rx_pkt_cnt;
691 BNX2FC_STATS(hba, rx_stat0, fcoe_rx_byte_cnt);
692 bnx2fc_stats->rx_words += ((hba->bfw_stats.fcoe_rx_byte_cnt) / 4);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800693
694 bnx2fc_stats->dumped_frames = 0;
695 bnx2fc_stats->lip_count = 0;
696 bnx2fc_stats->nos_count = 0;
697 bnx2fc_stats->loss_of_sync_count = 0;
698 bnx2fc_stats->loss_of_signal_count = 0;
699 bnx2fc_stats->prim_seq_protocol_err_count = 0;
700
Bhanu Prakash Gollapudif246fe22012-12-21 19:40:32 -0800701 memcpy(&hba->prev_stats, hba->stats_buffer,
702 sizeof(struct fcoe_statistics_params));
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800703 return bnx2fc_stats;
704}
705
706static int bnx2fc_shost_config(struct fc_lport *lport, struct device *dev)
707{
708 struct fcoe_port *port = lport_priv(lport);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700709 struct bnx2fc_interface *interface = port->priv;
Bhanu Prakash Gollapudic13d2b62013-03-08 13:28:51 -0800710 struct bnx2fc_hba *hba = interface->hba;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800711 struct Scsi_Host *shost = lport->host;
712 int rc = 0;
713
714 shost->max_cmd_len = BNX2FC_MAX_CMD_LEN;
Joe Carnuccio10755d32016-04-07 09:07:56 -0400715 shost->max_lun = bnx2fc_max_luns;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800716 shost->max_id = BNX2FC_MAX_FCP_TGT;
717 shost->max_channel = 0;
718 if (lport->vport)
719 shost->transportt = bnx2fc_vport_xport_template;
720 else
721 shost->transportt = bnx2fc_transport_template;
722
723 /* Add the new host to SCSI-ml */
724 rc = scsi_add_host(lport->host, dev);
725 if (rc) {
726 printk(KERN_ERR PFX "Error on scsi_add_host\n");
727 return rc;
728 }
729 if (!lport->vport)
730 fc_host_max_npiv_vports(lport->host) = USHRT_MAX;
Bhanu Prakash Gollapudic13d2b62013-03-08 13:28:51 -0800731 snprintf(fc_host_symbolic_name(lport->host), 256,
Saurav Kashyap17d87c42014-07-03 08:18:28 -0400732 "%s (QLogic %s) v%s over %s",
Bhanu Prakash Gollapudic13d2b62013-03-08 13:28:51 -0800733 BNX2FC_NAME, hba->chip_num, BNX2FC_VERSION,
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700734 interface->netdev->name);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800735
736 return 0;
737}
738
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800739static int bnx2fc_link_ok(struct fc_lport *lport)
740{
741 struct fcoe_port *port = lport_priv(lport);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700742 struct bnx2fc_interface *interface = port->priv;
743 struct bnx2fc_hba *hba = interface->hba;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800744 struct net_device *dev = hba->phys_dev;
745 int rc = 0;
746
747 if ((dev->flags & IFF_UP) && netif_carrier_ok(dev))
748 clear_bit(ADAPTER_STATE_LINK_DOWN, &hba->adapter_state);
749 else {
750 set_bit(ADAPTER_STATE_LINK_DOWN, &hba->adapter_state);
751 rc = -1;
752 }
753 return rc;
754}
755
756/**
757 * bnx2fc_get_link_state - get network link state
758 *
759 * @hba: adapter instance pointer
760 *
761 * updates adapter structure flag based on netdev state
762 */
763void bnx2fc_get_link_state(struct bnx2fc_hba *hba)
764{
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700765 if (test_bit(__LINK_STATE_NOCARRIER, &hba->phys_dev->state))
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800766 set_bit(ADAPTER_STATE_LINK_DOWN, &hba->adapter_state);
767 else
768 clear_bit(ADAPTER_STATE_LINK_DOWN, &hba->adapter_state);
769}
770
Bhanu Prakash Gollapudi52439602011-08-04 17:38:50 -0700771static int bnx2fc_net_config(struct fc_lport *lport, struct net_device *netdev)
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800772{
773 struct bnx2fc_hba *hba;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700774 struct bnx2fc_interface *interface;
Robert Lovefd8f8902012-05-22 19:06:16 -0700775 struct fcoe_ctlr *ctlr;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800776 struct fcoe_port *port;
777 u64 wwnn, wwpn;
778
779 port = lport_priv(lport);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700780 interface = port->priv;
Robert Lovefd8f8902012-05-22 19:06:16 -0700781 ctlr = bnx2fc_to_ctlr(interface);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700782 hba = interface->hba;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800783
784 /* require support for get_pauseparam ethtool op. */
785 if (!hba->phys_dev->ethtool_ops ||
786 !hba->phys_dev->ethtool_ops->get_pauseparam)
787 return -EOPNOTSUPP;
788
Bhanu Gollapudi1294bfe2011-03-17 17:13:34 -0700789 if (fc_set_mfs(lport, BNX2FC_MFS))
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800790 return -EINVAL;
791
792 skb_queue_head_init(&port->fcoe_pending_queue);
793 port->fcoe_pending_queue_active = 0;
794 setup_timer(&port->timer, fcoe_queue_timer, (unsigned long) lport);
795
Yi Zou0e0f9cd2012-12-06 06:24:44 +0000796 fcoe_link_speed_update(lport);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800797
798 if (!lport->vport) {
Bhanu Prakash Gollapudi52439602011-08-04 17:38:50 -0700799 if (fcoe_get_wwn(netdev, &wwnn, NETDEV_FCOE_WWNN))
Robert Lovefd8f8902012-05-22 19:06:16 -0700800 wwnn = fcoe_wwn_from_mac(ctlr->ctl_src_addr,
Bhanu Prakash Gollapudi52439602011-08-04 17:38:50 -0700801 1, 0);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800802 BNX2FC_HBA_DBG(lport, "WWNN = 0x%llx\n", wwnn);
803 fc_set_wwnn(lport, wwnn);
804
Bhanu Prakash Gollapudi52439602011-08-04 17:38:50 -0700805 if (fcoe_get_wwn(netdev, &wwpn, NETDEV_FCOE_WWPN))
Robert Lovefd8f8902012-05-22 19:06:16 -0700806 wwpn = fcoe_wwn_from_mac(ctlr->ctl_src_addr,
Bhanu Prakash Gollapudi52439602011-08-04 17:38:50 -0700807 2, 0);
808
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800809 BNX2FC_HBA_DBG(lport, "WWPN = 0x%llx\n", wwpn);
810 fc_set_wwpn(lport, wwpn);
811 }
812
813 return 0;
814}
815
816static void bnx2fc_destroy_timer(unsigned long data)
817{
818 struct bnx2fc_hba *hba = (struct bnx2fc_hba *)data;
819
Bhanu Prakash Gollapudicd703ae2011-08-04 17:38:43 -0700820 printk(KERN_ERR PFX "ERROR:bnx2fc_destroy_timer - "
821 "Destroy compl not received!!\n");
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700822 set_bit(BNX2FC_FLAG_DESTROY_CMPL, &hba->flags);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800823 wake_up_interruptible(&hba->destroy_wait);
824}
825
826/**
827 * bnx2fc_indicate_netevent - Generic netdev event handler
828 *
829 * @context: adapter structure pointer
830 * @event: event type
Michael Chan415199f2011-07-20 14:55:24 +0000831 * @vlan_id: vlan id - associated vlan id with this event
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800832 *
833 * Handles NETDEV_UP, NETDEV_DOWN, NETDEV_GOING_DOWN,NETDEV_CHANGE and
Bhanu Prakash Gollapudiabc49a92011-08-04 17:38:42 -0700834 * NETDEV_CHANGE_MTU events. Handle NETDEV_UNREGISTER only for vlans.
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800835 */
Michael Chan415199f2011-07-20 14:55:24 +0000836static void bnx2fc_indicate_netevent(void *context, unsigned long event,
837 u16 vlan_id)
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800838{
839 struct bnx2fc_hba *hba = (struct bnx2fc_hba *)context;
Robert Love6e89ea32012-11-27 06:53:40 +0000840 struct fcoe_ctlr_device *cdev;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700841 struct fc_lport *lport;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800842 struct fc_lport *vport;
Bhanu Prakash Gollapudiabc49a92011-08-04 17:38:42 -0700843 struct bnx2fc_interface *interface, *tmp;
Robert Lovefd8f8902012-05-22 19:06:16 -0700844 struct fcoe_ctlr *ctlr;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700845 int wait_for_upload = 0;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800846 u32 link_possible = 1;
847
Bhanu Prakash Gollapudiabc49a92011-08-04 17:38:42 -0700848 if (vlan_id != 0 && event != NETDEV_UNREGISTER)
Michael Chan415199f2011-07-20 14:55:24 +0000849 return;
850
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800851 switch (event) {
852 case NETDEV_UP:
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800853 if (!test_bit(ADAPTER_STATE_UP, &hba->adapter_state))
854 printk(KERN_ERR "indicate_netevent: "\
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700855 "hba is not UP!!\n");
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800856 break;
857
858 case NETDEV_DOWN:
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800859 clear_bit(ADAPTER_STATE_GOING_DOWN, &hba->adapter_state);
860 clear_bit(ADAPTER_STATE_UP, &hba->adapter_state);
861 link_possible = 0;
862 break;
863
864 case NETDEV_GOING_DOWN:
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800865 set_bit(ADAPTER_STATE_GOING_DOWN, &hba->adapter_state);
866 link_possible = 0;
867 break;
868
869 case NETDEV_CHANGE:
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800870 break;
871
Bhanu Prakash Gollapudiabc49a92011-08-04 17:38:42 -0700872 case NETDEV_UNREGISTER:
873 if (!vlan_id)
874 return;
875 mutex_lock(&bnx2fc_dev_lock);
876 list_for_each_entry_safe(interface, tmp, &if_list, list) {
Nithin Nayak Sujir26b29822011-08-30 15:54:50 -0700877 if (interface->hba == hba &&
878 interface->vlan_id == (vlan_id & VLAN_VID_MASK))
879 __bnx2fc_destroy(interface);
Bhanu Prakash Gollapudiabc49a92011-08-04 17:38:42 -0700880 }
881 mutex_unlock(&bnx2fc_dev_lock);
Eddie Wai06c4f202013-12-11 15:30:21 -0800882
883 /* Ensure ALL destroy work has been completed before return */
884 flush_workqueue(bnx2fc_wq);
Bhanu Prakash Gollapudiabc49a92011-08-04 17:38:42 -0700885 return;
886
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800887 default:
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800888 return;
889 }
890
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700891 mutex_lock(&bnx2fc_dev_lock);
892 list_for_each_entry(interface, &if_list, list) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800893
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700894 if (interface->hba != hba)
895 continue;
896
Robert Lovefd8f8902012-05-22 19:06:16 -0700897 ctlr = bnx2fc_to_ctlr(interface);
898 lport = ctlr->lp;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700899 BNX2FC_HBA_DBG(lport, "netevent handler - event=%s %ld\n",
900 interface->netdev->name, event);
901
Yi Zou0e0f9cd2012-12-06 06:24:44 +0000902 fcoe_link_speed_update(lport);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700903
Robert Love6e89ea32012-11-27 06:53:40 +0000904 cdev = fcoe_ctlr_to_ctlr_dev(ctlr);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700905
906 if (link_possible && !bnx2fc_link_ok(lport)) {
Robert Love6e89ea32012-11-27 06:53:40 +0000907 switch (cdev->enabled) {
908 case FCOE_CTLR_DISABLED:
909 pr_info("Link up while interface is disabled.\n");
910 break;
911 case FCOE_CTLR_ENABLED:
912 case FCOE_CTLR_UNUSED:
913 /* Reset max recv frame size to default */
914 fc_set_mfs(lport, BNX2FC_MFS);
915 /*
916 * ctlr link up will only be handled during
917 * enable to avoid sending discovery
918 * solicitation on a stale vlan
919 */
920 if (interface->enabled)
921 fcoe_ctlr_link_up(ctlr);
922 };
Robert Lovefd8f8902012-05-22 19:06:16 -0700923 } else if (fcoe_ctlr_link_down(ctlr)) {
Robert Love6e89ea32012-11-27 06:53:40 +0000924 switch (cdev->enabled) {
925 case FCOE_CTLR_DISABLED:
926 pr_info("Link down while interface is disabled.\n");
927 break;
928 case FCOE_CTLR_ENABLED:
929 case FCOE_CTLR_UNUSED:
930 mutex_lock(&lport->lp_mutex);
931 list_for_each_entry(vport, &lport->vports, list)
932 fc_host_port_type(vport->host) =
933 FC_PORTTYPE_UNKNOWN;
934 mutex_unlock(&lport->lp_mutex);
935 fc_host_port_type(lport->host) =
936 FC_PORTTYPE_UNKNOWN;
937 per_cpu_ptr(lport->stats,
938 get_cpu())->LinkFailureCount++;
939 put_cpu();
940 fcoe_clean_pending_queue(lport);
941 wait_for_upload = 1;
942 };
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800943 }
944 }
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700945 mutex_unlock(&bnx2fc_dev_lock);
946
947 if (wait_for_upload) {
948 clear_bit(ADAPTER_STATE_READY, &hba->adapter_state);
949 init_waitqueue_head(&hba->shutdown_wait);
950 BNX2FC_MISC_DBG("indicate_netevent "
951 "num_ofld_sess = %d\n",
952 hba->num_ofld_sess);
953 hba->wait_for_link_down = 1;
954 wait_event_interruptible(hba->shutdown_wait,
955 (hba->num_ofld_sess == 0));
956 BNX2FC_MISC_DBG("wakeup - num_ofld_sess = %d\n",
957 hba->num_ofld_sess);
958 hba->wait_for_link_down = 0;
959
960 if (signal_pending(current))
961 flush_signals(current);
962 }
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800963}
964
965static int bnx2fc_libfc_config(struct fc_lport *lport)
966{
967
968 /* Set the function pointers set by bnx2fc driver */
969 memcpy(&lport->tt, &bnx2fc_libfc_fcn_templ,
970 sizeof(struct libfc_function_template));
971 fc_elsct_init(lport);
972 fc_exch_init(lport);
973 fc_rport_init(lport);
Robert Love08076192013-03-25 11:00:28 -0700974 fc_disc_init(lport);
975 fc_disc_config(lport, lport);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800976 return 0;
977}
978
Bhanu Prakash Gollapudi0eb43b42013-04-22 19:22:30 +0000979static int bnx2fc_em_config(struct fc_lport *lport, struct bnx2fc_hba *hba)
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800980{
Bhanu Prakash Gollapudi0eb43b42013-04-22 19:22:30 +0000981 int fcoe_min_xid, fcoe_max_xid;
Bhanu Prakash Gollapudi7d742f62012-01-23 18:00:48 -0800982
Bhanu Prakash Gollapudi0eb43b42013-04-22 19:22:30 +0000983 fcoe_min_xid = hba->max_xid + 1;
Bhanu Prakash Gollapudi7d742f62012-01-23 18:00:48 -0800984 if (nr_cpu_ids <= 2)
Bhanu Prakash Gollapudi0eb43b42013-04-22 19:22:30 +0000985 fcoe_max_xid = hba->max_xid + FCOE_XIDS_PER_CPU_OFFSET;
Bhanu Prakash Gollapudi7d742f62012-01-23 18:00:48 -0800986 else
Bhanu Prakash Gollapudi0eb43b42013-04-22 19:22:30 +0000987 fcoe_max_xid = hba->max_xid + FCOE_MAX_XID_OFFSET;
988 if (!fc_exch_mgr_alloc(lport, FC_CLASS_3, fcoe_min_xid,
989 fcoe_max_xid, NULL)) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800990 printk(KERN_ERR PFX "em_config:fc_exch_mgr_alloc failed\n");
991 return -ENOMEM;
992 }
993
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800994 return 0;
995}
996
997static int bnx2fc_lport_config(struct fc_lport *lport)
998{
999 lport->link_up = 0;
1000 lport->qfull = 0;
Bhanu Prakash Gollapudi44c570b2012-01-23 18:00:47 -08001001 lport->max_retry_count = BNX2FC_MAX_RETRY_CNT;
1002 lport->max_rport_retry_count = BNX2FC_MAX_RPORT_RETRY_CNT;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001003 lport->e_d_tov = 2 * 1000;
1004 lport->r_a_tov = 10 * 1000;
1005
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001006 lport->service_params = (FCP_SPPF_INIT_FCN | FCP_SPPF_RD_XRDY_DIS |
1007 FCP_SPPF_RETRY | FCP_SPPF_CONF_COMPL);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001008 lport->does_npiv = 1;
1009
1010 memset(&lport->rnid_gen, 0, sizeof(struct fc_els_rnid_gen));
1011 lport->rnid_gen.rnid_atype = BNX2FC_RNID_HBA;
1012
1013 /* alloc stats structure */
1014 if (fc_lport_init_stats(lport))
1015 return -ENOMEM;
1016
1017 /* Finish fc_lport configuration */
1018 fc_lport_config(lport);
1019
1020 return 0;
1021}
1022
1023/**
1024 * bnx2fc_fip_recv - handle a received FIP frame.
1025 *
1026 * @skb: the received skb
1027 * @dev: associated &net_device
1028 * @ptype: the &packet_type structure which was used to register this handler.
1029 * @orig_dev: original receive &net_device, in case @ dev is a bond.
1030 *
1031 * Returns: 0 for success
1032 */
1033static int bnx2fc_fip_recv(struct sk_buff *skb, struct net_device *dev,
1034 struct packet_type *ptype,
1035 struct net_device *orig_dev)
1036{
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001037 struct bnx2fc_interface *interface;
Robert Lovefd8f8902012-05-22 19:06:16 -07001038 struct fcoe_ctlr *ctlr;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001039 interface = container_of(ptype, struct bnx2fc_interface,
1040 fip_packet_type);
Robert Lovefd8f8902012-05-22 19:06:16 -07001041 ctlr = bnx2fc_to_ctlr(interface);
1042 fcoe_ctlr_recv(ctlr, skb);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001043 return 0;
1044}
1045
1046/**
1047 * bnx2fc_update_src_mac - Update Ethernet MAC filters.
1048 *
1049 * @fip: FCoE controller.
1050 * @old: Unicast MAC address to delete if the MAC is non-zero.
1051 * @new: Unicast MAC address to add.
1052 *
1053 * Remove any previously-set unicast MAC filter.
1054 * Add secondary FCoE MAC address filter for our OUI.
1055 */
1056static void bnx2fc_update_src_mac(struct fc_lport *lport, u8 *addr)
1057{
1058 struct fcoe_port *port = lport_priv(lport);
1059
1060 memcpy(port->data_src_addr, addr, ETH_ALEN);
1061}
1062
1063/**
1064 * bnx2fc_get_src_mac - return the ethernet source address for an lport
1065 *
1066 * @lport: libfc port
1067 */
1068static u8 *bnx2fc_get_src_mac(struct fc_lport *lport)
1069{
1070 struct fcoe_port *port;
1071
1072 port = (struct fcoe_port *)lport_priv(lport);
1073 return port->data_src_addr;
1074}
1075
1076/**
1077 * bnx2fc_fip_send - send an Ethernet-encapsulated FIP frame.
1078 *
1079 * @fip: FCoE controller.
1080 * @skb: FIP Packet.
1081 */
1082static void bnx2fc_fip_send(struct fcoe_ctlr *fip, struct sk_buff *skb)
1083{
Chad Dupuis3f12f762016-04-07 09:07:57 -04001084 struct fip_header *fiph;
1085 struct ethhdr *eth_hdr;
1086 u16 op;
1087 u8 sub;
1088
1089 fiph = (struct fip_header *) ((void *)skb->data + 2 * ETH_ALEN + 2);
1090 eth_hdr = (struct ethhdr *)skb_mac_header(skb);
1091 op = ntohs(fiph->fip_op);
1092 sub = fiph->fip_subcode;
1093
1094 if (op == FIP_OP_CTRL && sub == FIP_SC_SOL && bnx2fc_log_fka)
1095 BNX2FC_MISC_DBG("Sending FKA from %pM to %pM.\n",
1096 eth_hdr->h_source, eth_hdr->h_dest);
1097
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001098 skb->dev = bnx2fc_from_ctlr(fip)->netdev;
1099 dev_queue_xmit(skb);
1100}
1101
1102static int bnx2fc_vport_create(struct fc_vport *vport, bool disabled)
1103{
1104 struct Scsi_Host *shost = vport_to_shost(vport);
1105 struct fc_lport *n_port = shost_priv(shost);
1106 struct fcoe_port *port = lport_priv(n_port);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001107 struct bnx2fc_interface *interface = port->priv;
1108 struct net_device *netdev = interface->netdev;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001109 struct fc_lport *vn_port;
Bhanu Prakash Gollapudi861efc52011-08-04 17:38:51 -07001110 int rc;
1111 char buf[32];
1112
1113 rc = fcoe_validate_vport_create(vport);
1114 if (rc) {
1115 fcoe_wwn_to_str(vport->port_name, buf, sizeof(buf));
1116 printk(KERN_ERR PFX "Failed to create vport, "
1117 "WWPN (0x%s) already exists\n",
1118 buf);
1119 return rc;
1120 }
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001121
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001122 if (!test_bit(BNX2FC_FLAG_FW_INIT_DONE, &interface->hba->flags)) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001123 printk(KERN_ERR PFX "vn ports cannot be created on"
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001124 "this interface\n");
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001125 return -EIO;
1126 }
Jiri Pirko4bc71cb2011-09-03 03:34:30 +00001127 rtnl_lock();
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001128 mutex_lock(&bnx2fc_dev_lock);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001129 vn_port = bnx2fc_if_create(interface, &vport->dev, 1);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001130 mutex_unlock(&bnx2fc_dev_lock);
Jiri Pirko4bc71cb2011-09-03 03:34:30 +00001131 rtnl_unlock();
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001132
Dan Carpenterb6829c72014-11-04 13:37:17 +03001133 if (!vn_port) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001134 printk(KERN_ERR PFX "bnx2fc_vport_create (%s) failed\n",
1135 netdev->name);
1136 return -EIO;
1137 }
1138
Joe Carnuccio10755d32016-04-07 09:07:56 -04001139 if (bnx2fc_devloss_tmo)
1140 fc_host_dev_loss_tmo(vn_port->host) = bnx2fc_devloss_tmo;
1141
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001142 if (disabled) {
1143 fc_vport_set_state(vport, FC_VPORT_DISABLED);
1144 } else {
1145 vn_port->boot_time = jiffies;
1146 fc_lport_init(vn_port);
1147 fc_fabric_login(vn_port);
1148 fc_vport_setlink(vn_port);
1149 }
1150 return 0;
1151}
1152
Bhanu Prakash Gollapudiabc49a92011-08-04 17:38:42 -07001153static void bnx2fc_free_vport(struct bnx2fc_hba *hba, struct fc_lport *lport)
1154{
1155 struct bnx2fc_lport *blport, *tmp;
1156
1157 spin_lock_bh(&hba->hba_lock);
1158 list_for_each_entry_safe(blport, tmp, &hba->vports, list) {
1159 if (blport->lport == lport) {
1160 list_del(&blport->list);
1161 kfree(blport);
1162 }
1163 }
1164 spin_unlock_bh(&hba->hba_lock);
1165}
1166
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001167static int bnx2fc_vport_destroy(struct fc_vport *vport)
1168{
1169 struct Scsi_Host *shost = vport_to_shost(vport);
1170 struct fc_lport *n_port = shost_priv(shost);
1171 struct fc_lport *vn_port = vport->dd_data;
1172 struct fcoe_port *port = lport_priv(vn_port);
Bhanu Prakash Gollapudiabc49a92011-08-04 17:38:42 -07001173 struct bnx2fc_interface *interface = port->priv;
Bhanu Prakash Gollapudicdf54662011-08-04 17:38:39 -07001174 struct fc_lport *v_port;
1175 bool found = false;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001176
1177 mutex_lock(&n_port->lp_mutex);
Bhanu Prakash Gollapudicdf54662011-08-04 17:38:39 -07001178 list_for_each_entry(v_port, &n_port->vports, list)
1179 if (v_port->vport == vport) {
1180 found = true;
1181 break;
1182 }
1183
1184 if (!found) {
1185 mutex_unlock(&n_port->lp_mutex);
1186 return -ENOENT;
1187 }
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001188 list_del(&vn_port->list);
1189 mutex_unlock(&n_port->lp_mutex);
Bhanu Prakash Gollapudiabc49a92011-08-04 17:38:42 -07001190 bnx2fc_free_vport(interface->hba, port->lport);
1191 bnx2fc_port_shutdown(port->lport);
1192 bnx2fc_interface_put(interface);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001193 queue_work(bnx2fc_wq, &port->destroy_work);
1194 return 0;
1195}
1196
1197static int bnx2fc_vport_disable(struct fc_vport *vport, bool disable)
1198{
1199 struct fc_lport *lport = vport->dd_data;
1200
1201 if (disable) {
1202 fc_vport_set_state(vport, FC_VPORT_DISABLED);
1203 fc_fabric_logoff(lport);
1204 } else {
1205 lport->boot_time = jiffies;
1206 fc_fabric_login(lport);
1207 fc_vport_setlink(lport);
1208 }
1209 return 0;
1210}
1211
1212
Bhanu Prakash Gollapudi776cebc2011-08-04 17:38:40 -07001213static int bnx2fc_interface_setup(struct bnx2fc_interface *interface)
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001214{
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001215 struct net_device *netdev = interface->netdev;
1216 struct net_device *physdev = interface->hba->phys_dev;
Robert Lovefd8f8902012-05-22 19:06:16 -07001217 struct fcoe_ctlr *ctlr = bnx2fc_to_ctlr(interface);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001218 struct netdev_hw_addr *ha;
1219 int sel_san_mac = 0;
1220
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001221 /* setup Source MAC Address */
1222 rcu_read_lock();
1223 for_each_dev_addr(physdev, ha) {
1224 BNX2FC_MISC_DBG("net_config: ha->type = %d, fip_mac = ",
1225 ha->type);
1226 printk(KERN_INFO "%2x:%2x:%2x:%2x:%2x:%2x\n", ha->addr[0],
1227 ha->addr[1], ha->addr[2], ha->addr[3],
1228 ha->addr[4], ha->addr[5]);
1229
1230 if ((ha->type == NETDEV_HW_ADDR_T_SAN) &&
1231 (is_valid_ether_addr(ha->addr))) {
Robert Lovefd8f8902012-05-22 19:06:16 -07001232 memcpy(ctlr->ctl_src_addr, ha->addr,
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001233 ETH_ALEN);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001234 sel_san_mac = 1;
1235 BNX2FC_MISC_DBG("Found SAN MAC\n");
1236 }
1237 }
1238 rcu_read_unlock();
1239
1240 if (!sel_san_mac)
1241 return -ENODEV;
1242
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001243 interface->fip_packet_type.func = bnx2fc_fip_recv;
1244 interface->fip_packet_type.type = htons(ETH_P_FIP);
1245 interface->fip_packet_type.dev = netdev;
1246 dev_add_pack(&interface->fip_packet_type);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001247
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001248 interface->fcoe_packet_type.func = bnx2fc_rcv;
1249 interface->fcoe_packet_type.type = __constant_htons(ETH_P_FCOE);
1250 interface->fcoe_packet_type.dev = netdev;
1251 dev_add_pack(&interface->fcoe_packet_type);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001252
1253 return 0;
1254}
1255
1256static int bnx2fc_attach_transport(void)
1257{
1258 bnx2fc_transport_template =
1259 fc_attach_transport(&bnx2fc_transport_function);
1260
1261 if (bnx2fc_transport_template == NULL) {
1262 printk(KERN_ERR PFX "Failed to attach FC transport\n");
1263 return -ENODEV;
1264 }
1265
1266 bnx2fc_vport_xport_template =
1267 fc_attach_transport(&bnx2fc_vport_xport_function);
1268 if (bnx2fc_vport_xport_template == NULL) {
1269 printk(KERN_ERR PFX
1270 "Failed to attach FC transport for vport\n");
1271 fc_release_transport(bnx2fc_transport_template);
1272 bnx2fc_transport_template = NULL;
1273 return -ENODEV;
1274 }
1275 return 0;
1276}
1277static void bnx2fc_release_transport(void)
1278{
1279 fc_release_transport(bnx2fc_transport_template);
1280 fc_release_transport(bnx2fc_vport_xport_template);
1281 bnx2fc_transport_template = NULL;
1282 bnx2fc_vport_xport_template = NULL;
1283}
1284
1285static void bnx2fc_interface_release(struct kref *kref)
1286{
Robert Love8d55e502012-05-22 19:06:26 -07001287 struct fcoe_ctlr_device *ctlr_dev;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001288 struct bnx2fc_interface *interface;
Robert Lovefd8f8902012-05-22 19:06:16 -07001289 struct fcoe_ctlr *ctlr;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001290 struct net_device *netdev;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001291
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001292 interface = container_of(kref, struct bnx2fc_interface, kref);
Nithin Nayak Sujir068bdce2011-04-25 12:30:09 -07001293 BNX2FC_MISC_DBG("Interface is being released\n");
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001294
Robert Lovefd8f8902012-05-22 19:06:16 -07001295 ctlr = bnx2fc_to_ctlr(interface);
Robert Love8d55e502012-05-22 19:06:26 -07001296 ctlr_dev = fcoe_ctlr_to_ctlr_dev(ctlr);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001297 netdev = interface->netdev;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001298
1299 /* tear-down FIP controller */
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001300 if (test_and_clear_bit(BNX2FC_CTLR_INIT_DONE, &interface->if_flags))
Robert Lovefd8f8902012-05-22 19:06:16 -07001301 fcoe_ctlr_destroy(ctlr);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001302
Robert Love8d55e502012-05-22 19:06:26 -07001303 fcoe_ctlr_device_delete(ctlr_dev);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001304
1305 dev_put(netdev);
1306 module_put(THIS_MODULE);
1307}
1308
1309static inline void bnx2fc_interface_get(struct bnx2fc_interface *interface)
1310{
1311 kref_get(&interface->kref);
1312}
1313
1314static inline void bnx2fc_interface_put(struct bnx2fc_interface *interface)
1315{
1316 kref_put(&interface->kref, bnx2fc_interface_release);
1317}
1318static void bnx2fc_hba_destroy(struct bnx2fc_hba *hba)
1319{
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001320 /* Free the command manager */
1321 if (hba->cmd_mgr) {
1322 bnx2fc_cmd_mgr_free(hba->cmd_mgr);
1323 hba->cmd_mgr = NULL;
1324 }
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001325 kfree(hba->tgt_ofld_list);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001326 bnx2fc_unbind_pcidev(hba);
1327 kfree(hba);
1328}
1329
1330/**
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001331 * bnx2fc_hba_create - create a new bnx2fc hba
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001332 *
1333 * @cnic: pointer to cnic device
1334 *
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001335 * Creates a new FCoE hba on the given device.
1336 *
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001337 */
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001338static struct bnx2fc_hba *bnx2fc_hba_create(struct cnic_dev *cnic)
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001339{
1340 struct bnx2fc_hba *hba;
Barak Witkowski2e499d32012-06-26 01:31:19 +00001341 struct fcoe_capabilities *fcoe_cap;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001342 int rc;
1343
1344 hba = kzalloc(sizeof(*hba), GFP_KERNEL);
1345 if (!hba) {
1346 printk(KERN_ERR PFX "Unable to allocate hba structure\n");
1347 return NULL;
1348 }
1349 spin_lock_init(&hba->hba_lock);
1350 mutex_init(&hba->hba_mutex);
1351
1352 hba->cnic = cnic;
Bhanu Prakash Gollapudi0eb43b42013-04-22 19:22:30 +00001353
1354 hba->max_tasks = cnic->max_fcoe_exchanges;
1355 hba->elstm_xids = (hba->max_tasks / 2);
1356 hba->max_outstanding_cmds = hba->elstm_xids;
1357 hba->max_xid = (hba->max_tasks - 1);
1358
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001359 rc = bnx2fc_bind_pcidev(hba);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001360 if (rc) {
1361 printk(KERN_ERR PFX "create_adapter: bind error\n");
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001362 goto bind_err;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001363 }
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001364 hba->phys_dev = cnic->netdev;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001365 hba->next_conn_id = 0;
1366
1367 hba->tgt_ofld_list =
1368 kzalloc(sizeof(struct bnx2fc_rport *) * BNX2FC_NUM_MAX_SESS,
1369 GFP_KERNEL);
1370 if (!hba->tgt_ofld_list) {
1371 printk(KERN_ERR PFX "Unable to allocate tgt offload list\n");
1372 goto tgtofld_err;
1373 }
1374
1375 hba->num_ofld_sess = 0;
1376
Bhanu Prakash Gollapudi0eb43b42013-04-22 19:22:30 +00001377 hba->cmd_mgr = bnx2fc_cmd_mgr_alloc(hba);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001378 if (!hba->cmd_mgr) {
1379 printk(KERN_ERR PFX "em_config:bnx2fc_cmd_mgr_alloc failed\n");
1380 goto cmgr_err;
1381 }
Barak Witkowski2e499d32012-06-26 01:31:19 +00001382 fcoe_cap = &hba->fcoe_cap;
1383
1384 fcoe_cap->capability1 = BNX2FC_TM_MAX_SQES <<
1385 FCOE_IOS_PER_CONNECTION_SHIFT;
1386 fcoe_cap->capability1 |= BNX2FC_NUM_MAX_SESS <<
1387 FCOE_LOGINS_PER_PORT_SHIFT;
Bhanu Prakash Gollapudi0eb43b42013-04-22 19:22:30 +00001388 fcoe_cap->capability2 = hba->max_outstanding_cmds <<
Barak Witkowski2e499d32012-06-26 01:31:19 +00001389 FCOE_NUMBER_OF_EXCHANGES_SHIFT;
1390 fcoe_cap->capability2 |= BNX2FC_MAX_NPIV <<
1391 FCOE_NPIV_WWN_PER_PORT_SHIFT;
1392 fcoe_cap->capability3 = BNX2FC_NUM_MAX_SESS <<
1393 FCOE_TARGETS_SUPPORTED_SHIFT;
Bhanu Prakash Gollapudi0eb43b42013-04-22 19:22:30 +00001394 fcoe_cap->capability3 |= hba->max_outstanding_cmds <<
Barak Witkowski2e499d32012-06-26 01:31:19 +00001395 FCOE_OUTSTANDING_COMMANDS_SHIFT;
1396 fcoe_cap->capability4 = FCOE_CAPABILITY4_STATEFUL;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001397
1398 init_waitqueue_head(&hba->shutdown_wait);
1399 init_waitqueue_head(&hba->destroy_wait);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001400 INIT_LIST_HEAD(&hba->vports);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001401
1402 return hba;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001403
1404cmgr_err:
1405 kfree(hba->tgt_ofld_list);
1406tgtofld_err:
1407 bnx2fc_unbind_pcidev(hba);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001408bind_err:
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001409 kfree(hba);
1410 return NULL;
1411}
1412
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001413struct bnx2fc_interface *bnx2fc_interface_create(struct bnx2fc_hba *hba,
1414 struct net_device *netdev,
1415 enum fip_state fip_mode)
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001416{
Robert Love8d55e502012-05-22 19:06:26 -07001417 struct fcoe_ctlr_device *ctlr_dev;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001418 struct bnx2fc_interface *interface;
Robert Lovefd8f8902012-05-22 19:06:16 -07001419 struct fcoe_ctlr *ctlr;
1420 int size;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001421 int rc = 0;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001422
Robert Lovefd8f8902012-05-22 19:06:16 -07001423 size = (sizeof(*interface) + sizeof(struct fcoe_ctlr));
Robert Love8d55e502012-05-22 19:06:26 -07001424 ctlr_dev = fcoe_ctlr_device_add(&netdev->dev, &bnx2fc_fcoe_sysfs_templ,
1425 size);
1426 if (!ctlr_dev) {
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001427 printk(KERN_ERR PFX "Unable to allocate interface structure\n");
1428 return NULL;
1429 }
Robert Love8d55e502012-05-22 19:06:26 -07001430 ctlr = fcoe_ctlr_device_priv(ctlr_dev);
Robert Love9d348762013-09-05 07:47:27 +00001431 ctlr->cdev = ctlr_dev;
Robert Lovefd8f8902012-05-22 19:06:16 -07001432 interface = fcoe_ctlr_priv(ctlr);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001433 dev_hold(netdev);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001434 kref_init(&interface->kref);
1435 interface->hba = hba;
1436 interface->netdev = netdev;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001437
1438 /* Initialize FIP */
Robert Lovefd8f8902012-05-22 19:06:16 -07001439 fcoe_ctlr_init(ctlr, fip_mode);
1440 ctlr->send = bnx2fc_fip_send;
1441 ctlr->update_mac = bnx2fc_update_src_mac;
1442 ctlr->get_src_addr = bnx2fc_get_src_mac;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001443 set_bit(BNX2FC_CTLR_INIT_DONE, &interface->if_flags);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001444
Bhanu Prakash Gollapudi776cebc2011-08-04 17:38:40 -07001445 rc = bnx2fc_interface_setup(interface);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001446 if (!rc)
1447 return interface;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001448
Robert Lovefd8f8902012-05-22 19:06:16 -07001449 fcoe_ctlr_destroy(ctlr);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001450 dev_put(netdev);
Robert Love8d55e502012-05-22 19:06:26 -07001451 fcoe_ctlr_device_delete(ctlr_dev);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001452 return NULL;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001453}
1454
1455/**
1456 * bnx2fc_if_create - Create FCoE instance on a given interface
1457 *
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001458 * @interface: FCoE interface to create a local port on
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001459 * @parent: Device pointer to be the parent in sysfs for the SCSI host
1460 * @npiv: Indicates if the port is vport or not
1461 *
1462 * Creates a fc_lport instance and a Scsi_Host instance and configure them.
1463 *
1464 * Returns: Allocated fc_lport or an error pointer
1465 */
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001466static struct fc_lport *bnx2fc_if_create(struct bnx2fc_interface *interface,
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001467 struct device *parent, int npiv)
1468{
Robert Lovefd8f8902012-05-22 19:06:16 -07001469 struct fcoe_ctlr *ctlr = bnx2fc_to_ctlr(interface);
Vasu Dev134a4e22011-04-28 15:55:44 -07001470 struct fc_lport *lport, *n_port;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001471 struct fcoe_port *port;
1472 struct Scsi_Host *shost;
1473 struct fc_vport *vport = dev_to_vport(parent);
Bhanu Prakash Gollapudid36b3272011-05-27 11:47:27 -07001474 struct bnx2fc_lport *blport;
Bhanu Prakash Gollapudi0eb43b42013-04-22 19:22:30 +00001475 struct bnx2fc_hba *hba = interface->hba;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001476 int rc = 0;
1477
Bhanu Prakash Gollapudid36b3272011-05-27 11:47:27 -07001478 blport = kzalloc(sizeof(struct bnx2fc_lport), GFP_KERNEL);
1479 if (!blport) {
Robert Lovefd8f8902012-05-22 19:06:16 -07001480 BNX2FC_HBA_DBG(ctlr->lp, "Unable to alloc blport\n");
Bhanu Prakash Gollapudid36b3272011-05-27 11:47:27 -07001481 return NULL;
1482 }
1483
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001484 /* Allocate Scsi_Host structure */
Bhanu Prakash Gollapudi0eb43b42013-04-22 19:22:30 +00001485 bnx2fc_shost_template.can_queue = hba->max_outstanding_cmds;
Vasu Dev134a4e22011-04-28 15:55:44 -07001486 if (!npiv)
1487 lport = libfc_host_alloc(&bnx2fc_shost_template, sizeof(*port));
1488 else
1489 lport = libfc_vport_create(vport, sizeof(*port));
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001490
1491 if (!lport) {
1492 printk(KERN_ERR PFX "could not allocate scsi host structure\n");
Bhanu Prakash Gollapudid36b3272011-05-27 11:47:27 -07001493 goto free_blport;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001494 }
1495 shost = lport->host;
1496 port = lport_priv(lport);
1497 port->lport = lport;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001498 port->priv = interface;
Yi Zouc3d79092012-12-06 06:24:29 +00001499 port->get_netdev = bnx2fc_netdev;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001500 INIT_WORK(&port->destroy_work, bnx2fc_destroy_work);
1501
1502 /* Configure fcoe_port */
1503 rc = bnx2fc_lport_config(lport);
1504 if (rc)
1505 goto lp_config_err;
1506
1507 if (npiv) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001508 printk(KERN_ERR PFX "Setting vport names, 0x%llX 0x%llX\n",
1509 vport->node_name, vport->port_name);
1510 fc_set_wwnn(lport, vport->node_name);
1511 fc_set_wwpn(lport, vport->port_name);
1512 }
1513 /* Configure netdev and networking properties of the lport */
Bhanu Prakash Gollapudi52439602011-08-04 17:38:50 -07001514 rc = bnx2fc_net_config(lport, interface->netdev);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001515 if (rc) {
1516 printk(KERN_ERR PFX "Error on bnx2fc_net_config\n");
1517 goto lp_config_err;
1518 }
1519
1520 rc = bnx2fc_shost_config(lport, parent);
1521 if (rc) {
1522 printk(KERN_ERR PFX "Couldnt configure shost for %s\n",
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001523 interface->netdev->name);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001524 goto lp_config_err;
1525 }
1526
1527 /* Initialize the libfc library */
1528 rc = bnx2fc_libfc_config(lport);
1529 if (rc) {
1530 printk(KERN_ERR PFX "Couldnt configure libfc\n");
1531 goto shost_err;
1532 }
1533 fc_host_port_type(lport->host) = FC_PORTTYPE_UNKNOWN;
1534
Joe Carnuccio10755d32016-04-07 09:07:56 -04001535 if (bnx2fc_devloss_tmo)
1536 fc_host_dev_loss_tmo(shost) = bnx2fc_devloss_tmo;
1537
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001538 /* Allocate exchange manager */
Vasu Dev134a4e22011-04-28 15:55:44 -07001539 if (!npiv)
Bhanu Prakash Gollapudi0eb43b42013-04-22 19:22:30 +00001540 rc = bnx2fc_em_config(lport, hba);
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
1554 spin_lock_bh(&hba->hba_lock);
1555 blport->lport = lport;
1556 list_add_tail(&blport->list, &hba->vports);
1557 spin_unlock_bh(&hba->hba_lock);
1558
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001559 return lport;
1560
1561shost_err:
1562 scsi_remove_host(shost);
1563lp_config_err:
1564 scsi_host_put(lport->host);
Bhanu Prakash Gollapudid36b3272011-05-27 11:47:27 -07001565free_blport:
1566 kfree(blport);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001567 return NULL;
1568}
1569
Bhanu Prakash Gollapudi013068f2011-08-30 15:54:52 -07001570static void bnx2fc_net_cleanup(struct bnx2fc_interface *interface)
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001571{
1572 /* Dont listen for Ethernet packets anymore */
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001573 __dev_remove_pack(&interface->fcoe_packet_type);
1574 __dev_remove_pack(&interface->fip_packet_type);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001575 synchronize_net();
1576}
1577
Bhanu Prakash Gollapudi776cebc2011-08-04 17:38:40 -07001578static void bnx2fc_interface_cleanup(struct bnx2fc_interface *interface)
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001579{
Robert Lovefd8f8902012-05-22 19:06:16 -07001580 struct fcoe_ctlr *ctlr = bnx2fc_to_ctlr(interface);
1581 struct fc_lport *lport = ctlr->lp;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001582 struct fcoe_port *port = lport_priv(lport);
Bhanu Prakash Gollapudi9be17fc2011-08-04 17:38:41 -07001583 struct bnx2fc_hba *hba = interface->hba;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001584
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001585 /* Stop the transmit retry timer */
1586 del_timer_sync(&port->timer);
1587
1588 /* Free existing transmit skbs */
1589 fcoe_clean_pending_queue(lport);
1590
Bhanu Prakash Gollapudi013068f2011-08-30 15:54:52 -07001591 bnx2fc_net_cleanup(interface);
Bhanu Prakash Gollapudi9be17fc2011-08-04 17:38:41 -07001592
Bhanu Prakash Gollapudiabc49a92011-08-04 17:38:42 -07001593 bnx2fc_free_vport(hba, lport);
Bhanu Prakash Gollapudi9be17fc2011-08-04 17:38:41 -07001594}
1595
1596static void bnx2fc_if_destroy(struct fc_lport *lport)
1597{
1598
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001599 /* Free queued packets for the receive thread */
1600 bnx2fc_clean_rx_queue(lport);
1601
1602 /* Detach from scsi-ml */
1603 fc_remove_host(lport->host);
1604 scsi_remove_host(lport->host);
1605
1606 /*
1607 * Note that only the physical lport will have the exchange manager.
1608 * for vports, this function is NOP
1609 */
1610 fc_exch_mgr_free(lport);
1611
1612 /* Free memory used by statistical counters */
1613 fc_lport_free_stats(lport);
1614
1615 /* Release Scsi_Host */
1616 scsi_host_put(lport->host);
1617}
1618
Bhanu Prakash Gollapudieccdcd02011-08-24 18:56:42 -07001619static void __bnx2fc_destroy(struct bnx2fc_interface *interface)
Bhanu Prakash Gollapudiabc49a92011-08-04 17:38:42 -07001620{
Robert Lovefd8f8902012-05-22 19:06:16 -07001621 struct fcoe_ctlr *ctlr = bnx2fc_to_ctlr(interface);
1622 struct fc_lport *lport = ctlr->lp;
Bhanu Prakash Gollapudi0cbf32e2011-08-30 15:54:51 -07001623 struct fcoe_port *port = lport_priv(lport);
Bhanu Prakash Gollapudiabc49a92011-08-04 17:38:42 -07001624
1625 bnx2fc_interface_cleanup(interface);
1626 bnx2fc_stop(interface);
Bhanu Prakash Gollapudiabc49a92011-08-04 17:38:42 -07001627 list_del(&interface->list);
Bhanu Prakash Gollapudiabc49a92011-08-04 17:38:42 -07001628 bnx2fc_interface_put(interface);
Bhanu Prakash Gollapudi0cbf32e2011-08-30 15:54:51 -07001629 queue_work(bnx2fc_wq, &port->destroy_work);
Bhanu Prakash Gollapudiabc49a92011-08-04 17:38:42 -07001630}
1631
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001632/**
1633 * bnx2fc_destroy - Destroy a bnx2fc FCoE interface
1634 *
1635 * @buffer: The name of the Ethernet interface to be destroyed
1636 * @kp: The associated kernel parameter
1637 *
1638 * Called from sysfs.
1639 *
1640 * Returns: 0 for success
1641 */
1642static int bnx2fc_destroy(struct net_device *netdev)
1643{
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001644 struct bnx2fc_interface *interface = NULL;
Bhanu Prakash Gollapudi2a7b29c2012-01-23 18:00:46 -08001645 struct workqueue_struct *timer_work_queue;
Robert Lovefd8f8902012-05-22 19:06:16 -07001646 struct fcoe_ctlr *ctlr;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001647 int rc = 0;
1648
Nithin Sujir6702ca12011-03-17 17:13:27 -07001649 rtnl_lock();
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001650 mutex_lock(&bnx2fc_dev_lock);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001651
1652 interface = bnx2fc_interface_lookup(netdev);
Robert Lovefd8f8902012-05-22 19:06:16 -07001653 ctlr = bnx2fc_to_ctlr(interface);
1654 if (!interface || !ctlr->lp) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001655 rc = -ENODEV;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001656 printk(KERN_ERR PFX "bnx2fc_destroy: interface or lport not found\n");
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001657 goto netdev_err;
1658 }
1659
Bhanu Prakash Gollapudi2a7b29c2012-01-23 18:00:46 -08001660 timer_work_queue = interface->timer_work_queue;
Bhanu Prakash Gollapudieccdcd02011-08-24 18:56:42 -07001661 __bnx2fc_destroy(interface);
Bhanu Prakash Gollapudi2a7b29c2012-01-23 18:00:46 -08001662 destroy_workqueue(timer_work_queue);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001663
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001664netdev_err:
1665 mutex_unlock(&bnx2fc_dev_lock);
1666 rtnl_unlock();
1667 return rc;
1668}
1669
1670static void bnx2fc_destroy_work(struct work_struct *work)
1671{
1672 struct fcoe_port *port;
1673 struct fc_lport *lport;
1674
1675 port = container_of(work, struct fcoe_port, destroy_work);
1676 lport = port->lport;
1677
1678 BNX2FC_HBA_DBG(lport, "Entered bnx2fc_destroy_work\n");
1679
Bhanu Prakash Gollapudi9be17fc2011-08-04 17:38:41 -07001680 bnx2fc_if_destroy(lport);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001681}
1682
1683static void bnx2fc_unbind_adapter_devices(struct bnx2fc_hba *hba)
1684{
1685 bnx2fc_free_fw_resc(hba);
1686 bnx2fc_free_task_ctx(hba);
1687}
1688
1689/**
1690 * bnx2fc_bind_adapter_devices - binds bnx2fc adapter with the associated
1691 * pci structure
1692 *
1693 * @hba: Adapter instance
1694 */
1695static int bnx2fc_bind_adapter_devices(struct bnx2fc_hba *hba)
1696{
1697 if (bnx2fc_setup_task_ctx(hba))
1698 goto mem_err;
1699
1700 if (bnx2fc_setup_fw_resc(hba))
1701 goto mem_err;
1702
1703 return 0;
1704mem_err:
1705 bnx2fc_unbind_adapter_devices(hba);
1706 return -ENOMEM;
1707}
1708
1709static int bnx2fc_bind_pcidev(struct bnx2fc_hba *hba)
1710{
1711 struct cnic_dev *cnic;
Bhanu Prakash Gollapudic13d2b62013-03-08 13:28:51 -08001712 struct pci_dev *pdev;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001713
1714 if (!hba->cnic) {
1715 printk(KERN_ERR PFX "cnic is NULL\n");
1716 return -ENODEV;
1717 }
1718 cnic = hba->cnic;
Bhanu Prakash Gollapudic13d2b62013-03-08 13:28:51 -08001719 pdev = hba->pcidev = cnic->pcidev;
1720 if (!hba->pcidev)
1721 return -ENODEV;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001722
Bhanu Prakash Gollapudic13d2b62013-03-08 13:28:51 -08001723 switch (pdev->device) {
1724 case PCI_DEVICE_ID_NX2_57710:
1725 strncpy(hba->chip_num, "BCM57710", BCM_CHIP_LEN);
1726 break;
1727 case PCI_DEVICE_ID_NX2_57711:
1728 strncpy(hba->chip_num, "BCM57711", BCM_CHIP_LEN);
1729 break;
1730 case PCI_DEVICE_ID_NX2_57712:
1731 case PCI_DEVICE_ID_NX2_57712_MF:
1732 case PCI_DEVICE_ID_NX2_57712_VF:
1733 strncpy(hba->chip_num, "BCM57712", BCM_CHIP_LEN);
1734 break;
1735 case PCI_DEVICE_ID_NX2_57800:
1736 case PCI_DEVICE_ID_NX2_57800_MF:
1737 case PCI_DEVICE_ID_NX2_57800_VF:
1738 strncpy(hba->chip_num, "BCM57800", BCM_CHIP_LEN);
1739 break;
1740 case PCI_DEVICE_ID_NX2_57810:
1741 case PCI_DEVICE_ID_NX2_57810_MF:
1742 case PCI_DEVICE_ID_NX2_57810_VF:
1743 strncpy(hba->chip_num, "BCM57810", BCM_CHIP_LEN);
1744 break;
1745 case PCI_DEVICE_ID_NX2_57840:
1746 case PCI_DEVICE_ID_NX2_57840_MF:
1747 case PCI_DEVICE_ID_NX2_57840_VF:
1748 case PCI_DEVICE_ID_NX2_57840_2_20:
1749 case PCI_DEVICE_ID_NX2_57840_4_10:
1750 strncpy(hba->chip_num, "BCM57840", BCM_CHIP_LEN);
1751 break;
1752 default:
1753 pr_err(PFX "Unknown device id 0x%x\n", pdev->device);
1754 break;
1755 }
1756 pci_dev_get(hba->pcidev);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001757 return 0;
1758}
1759
1760static void bnx2fc_unbind_pcidev(struct bnx2fc_hba *hba)
1761{
Bhanu Prakash Gollapudic13d2b62013-03-08 13:28:51 -08001762 if (hba->pcidev) {
1763 hba->chip_num[0] = '\0';
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001764 pci_dev_put(hba->pcidev);
Bhanu Prakash Gollapudic13d2b62013-03-08 13:28:51 -08001765 }
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001766 hba->pcidev = NULL;
1767}
1768
Barak Witkowski2e499d32012-06-26 01:31:19 +00001769/**
1770 * bnx2fc_ulp_get_stats - cnic callback to populate FCoE stats
1771 *
1772 * @handle: transport handle pointing to adapter struture
1773 */
1774static int bnx2fc_ulp_get_stats(void *handle)
1775{
1776 struct bnx2fc_hba *hba = handle;
1777 struct cnic_dev *cnic;
1778 struct fcoe_stats_info *stats_addr;
1779
1780 if (!hba)
1781 return -EINVAL;
1782
1783 cnic = hba->cnic;
1784 stats_addr = &cnic->stats_addr->fcoe_stat;
1785 if (!stats_addr)
1786 return -EINVAL;
1787
1788 strncpy(stats_addr->version, BNX2FC_VERSION,
1789 sizeof(stats_addr->version));
1790 stats_addr->txq_size = BNX2FC_SQ_WQES_MAX;
1791 stats_addr->rxq_size = BNX2FC_CQ_WQES_MAX;
1792
1793 return 0;
1794}
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001795
1796
1797/**
1798 * bnx2fc_ulp_start - cnic callback to initialize & start adapter instance
1799 *
Masanari Iida59e13d42012-04-25 00:24:16 +09001800 * @handle: transport handle pointing to adapter structure
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001801 *
1802 * This function maps adapter structure to pcidev structure and initiates
1803 * firmware handshake to enable/initialize on-chip FCoE components.
1804 * This bnx2fc - cnic interface api callback is used after following
1805 * conditions are met -
1806 * a) underlying network interface is up (marked by event NETDEV_UP
1807 * from netdev
1808 * b) bnx2fc adatper structure is registered.
1809 */
1810static void bnx2fc_ulp_start(void *handle)
1811{
1812 struct bnx2fc_hba *hba = handle;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001813 struct bnx2fc_interface *interface;
Robert Lovefd8f8902012-05-22 19:06:16 -07001814 struct fcoe_ctlr *ctlr;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001815 struct fc_lport *lport;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001816
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001817 mutex_lock(&bnx2fc_dev_lock);
1818
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001819 if (!test_bit(BNX2FC_FLAG_FW_INIT_DONE, &hba->flags))
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001820 bnx2fc_fw_init(hba);
1821
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001822 BNX2FC_MISC_DBG("bnx2fc started.\n");
1823
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001824 list_for_each_entry(interface, &if_list, list) {
1825 if (interface->hba == hba) {
Robert Lovefd8f8902012-05-22 19:06:16 -07001826 ctlr = bnx2fc_to_ctlr(interface);
1827 lport = ctlr->lp;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001828 /* Kick off Fabric discovery*/
1829 printk(KERN_ERR PFX "ulp_init: start discovery\n");
1830 lport->tt.frame_send = bnx2fc_xmit;
1831 bnx2fc_start_disc(interface);
1832 }
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001833 }
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001834
1835 mutex_unlock(&bnx2fc_dev_lock);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001836}
1837
1838static void bnx2fc_port_shutdown(struct fc_lport *lport)
1839{
1840 BNX2FC_MISC_DBG("Entered %s\n", __func__);
1841 fc_fabric_logoff(lport);
1842 fc_lport_destroy(lport);
1843}
1844
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001845static void bnx2fc_stop(struct bnx2fc_interface *interface)
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001846{
Robert Lovefd8f8902012-05-22 19:06:16 -07001847 struct fcoe_ctlr *ctlr = bnx2fc_to_ctlr(interface);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001848 struct fc_lport *lport;
1849 struct fc_lport *vport;
1850
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001851 if (!test_bit(BNX2FC_FLAG_FW_INIT_DONE, &interface->hba->flags))
1852 return;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001853
Robert Lovefd8f8902012-05-22 19:06:16 -07001854 lport = ctlr->lp;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001855 bnx2fc_port_shutdown(lport);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001856
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001857 mutex_lock(&lport->lp_mutex);
1858 list_for_each_entry(vport, &lport->vports, list)
1859 fc_host_port_type(vport->host) =
1860 FC_PORTTYPE_UNKNOWN;
1861 mutex_unlock(&lport->lp_mutex);
1862 fc_host_port_type(lport->host) = FC_PORTTYPE_UNKNOWN;
Robert Lovefd8f8902012-05-22 19:06:16 -07001863 fcoe_ctlr_link_down(ctlr);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001864 fcoe_clean_pending_queue(lport);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001865}
1866
1867static int bnx2fc_fw_init(struct bnx2fc_hba *hba)
1868{
1869#define BNX2FC_INIT_POLL_TIME (1000 / HZ)
1870 int rc = -1;
1871 int i = HZ;
1872
1873 rc = bnx2fc_bind_adapter_devices(hba);
1874 if (rc) {
1875 printk(KERN_ALERT PFX
1876 "bnx2fc_bind_adapter_devices failed - rc = %d\n", rc);
1877 goto err_out;
1878 }
1879
1880 rc = bnx2fc_send_fw_fcoe_init_msg(hba);
1881 if (rc) {
1882 printk(KERN_ALERT PFX
1883 "bnx2fc_send_fw_fcoe_init_msg failed - rc = %d\n", rc);
1884 goto err_unbind;
1885 }
1886
1887 /*
1888 * Wait until the adapter init message is complete, and adapter
1889 * state is UP.
1890 */
1891 while (!test_bit(ADAPTER_STATE_UP, &hba->adapter_state) && i--)
1892 msleep(BNX2FC_INIT_POLL_TIME);
1893
1894 if (!test_bit(ADAPTER_STATE_UP, &hba->adapter_state)) {
1895 printk(KERN_ERR PFX "bnx2fc_start: %s failed to initialize. "
1896 "Ignoring...\n",
1897 hba->cnic->netdev->name);
1898 rc = -1;
1899 goto err_unbind;
1900 }
1901
1902
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001903 set_bit(BNX2FC_FLAG_FW_INIT_DONE, &hba->flags);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001904 return 0;
1905
1906err_unbind:
1907 bnx2fc_unbind_adapter_devices(hba);
1908err_out:
1909 return rc;
1910}
1911
1912static void bnx2fc_fw_destroy(struct bnx2fc_hba *hba)
1913{
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001914 if (test_and_clear_bit(BNX2FC_FLAG_FW_INIT_DONE, &hba->flags)) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001915 if (bnx2fc_send_fw_fcoe_destroy_msg(hba) == 0) {
1916 init_timer(&hba->destroy_timer);
1917 hba->destroy_timer.expires = BNX2FC_FW_TIMEOUT +
1918 jiffies;
1919 hba->destroy_timer.function = bnx2fc_destroy_timer;
1920 hba->destroy_timer.data = (unsigned long)hba;
1921 add_timer(&hba->destroy_timer);
1922 wait_event_interruptible(hba->destroy_wait,
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001923 test_bit(BNX2FC_FLAG_DESTROY_CMPL,
1924 &hba->flags));
Bhanu Prakash Gollapudicd703ae2011-08-04 17:38:43 -07001925 clear_bit(BNX2FC_FLAG_DESTROY_CMPL, &hba->flags);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001926 /* This should never happen */
1927 if (signal_pending(current))
1928 flush_signals(current);
1929
1930 del_timer_sync(&hba->destroy_timer);
1931 }
1932 bnx2fc_unbind_adapter_devices(hba);
1933 }
1934}
1935
1936/**
1937 * bnx2fc_ulp_stop - cnic callback to shutdown adapter instance
1938 *
1939 * @handle: transport handle pointing to adapter structure
1940 *
1941 * Driver checks if adapter is already in shutdown mode, if not start
1942 * the shutdown process.
1943 */
1944static void bnx2fc_ulp_stop(void *handle)
1945{
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001946 struct bnx2fc_hba *hba = handle;
1947 struct bnx2fc_interface *interface;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001948
1949 printk(KERN_ERR "ULP_STOP\n");
1950
1951 mutex_lock(&bnx2fc_dev_lock);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001952 if (!test_bit(BNX2FC_FLAG_FW_INIT_DONE, &hba->flags))
1953 goto exit;
1954 list_for_each_entry(interface, &if_list, list) {
1955 if (interface->hba == hba)
1956 bnx2fc_stop(interface);
1957 }
1958 BUG_ON(hba->num_ofld_sess != 0);
1959
1960 mutex_lock(&hba->hba_mutex);
1961 clear_bit(ADAPTER_STATE_UP, &hba->adapter_state);
1962 clear_bit(ADAPTER_STATE_GOING_DOWN,
1963 &hba->adapter_state);
1964
1965 clear_bit(ADAPTER_STATE_READY, &hba->adapter_state);
1966 mutex_unlock(&hba->hba_mutex);
1967
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001968 bnx2fc_fw_destroy(hba);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001969exit:
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001970 mutex_unlock(&bnx2fc_dev_lock);
1971}
1972
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001973static void bnx2fc_start_disc(struct bnx2fc_interface *interface)
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001974{
Robert Lovefd8f8902012-05-22 19:06:16 -07001975 struct fcoe_ctlr *ctlr = bnx2fc_to_ctlr(interface);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001976 struct fc_lport *lport;
1977 int wait_cnt = 0;
1978
1979 BNX2FC_MISC_DBG("Entered %s\n", __func__);
1980 /* Kick off FIP/FLOGI */
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001981 if (!test_bit(BNX2FC_FLAG_FW_INIT_DONE, &interface->hba->flags)) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001982 printk(KERN_ERR PFX "Init not done yet\n");
1983 return;
1984 }
1985
Robert Lovefd8f8902012-05-22 19:06:16 -07001986 lport = ctlr->lp;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001987 BNX2FC_HBA_DBG(lport, "calling fc_fabric_login\n");
1988
Bhanu Prakash Gollapudi8a5badf2011-08-30 15:54:48 -07001989 if (!bnx2fc_link_ok(lport) && interface->enabled) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001990 BNX2FC_HBA_DBG(lport, "ctlr_link_up\n");
Robert Lovefd8f8902012-05-22 19:06:16 -07001991 fcoe_ctlr_link_up(ctlr);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001992 fc_host_port_type(lport->host) = FC_PORTTYPE_NPORT;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001993 set_bit(ADAPTER_STATE_READY, &interface->hba->adapter_state);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001994 }
1995
1996 /* wait for the FCF to be selected before issuing FLOGI */
Robert Lovefd8f8902012-05-22 19:06:16 -07001997 while (!ctlr->sel_fcf) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001998 msleep(250);
1999 /* give up after 3 secs */
2000 if (++wait_cnt > 12)
2001 break;
2002 }
Bhanu Prakash Gollapudi627e6282011-08-04 17:38:35 -07002003
2004 /* Reset max receive frame size to default */
2005 if (fc_set_mfs(lport, BNX2FC_MFS))
2006 return;
2007
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002008 fc_lport_init(lport);
2009 fc_fabric_login(lport);
2010}
2011
2012
2013/**
2014 * bnx2fc_ulp_init - Initialize an adapter instance
2015 *
2016 * @dev : cnic device handle
2017 * Called from cnic_register_driver() context to initialize all
2018 * enumerated cnic devices. This routine allocates adapter structure
2019 * and other device specific resources.
2020 */
2021static void bnx2fc_ulp_init(struct cnic_dev *dev)
2022{
2023 struct bnx2fc_hba *hba;
2024 int rc = 0;
2025
2026 BNX2FC_MISC_DBG("Entered %s\n", __func__);
2027 /* bnx2fc works only when bnx2x is loaded */
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002028 if (!test_bit(CNIC_F_BNX2X_CLASS, &dev->flags) ||
2029 (dev->max_fcoe_conn == 0)) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002030 printk(KERN_ERR PFX "bnx2fc FCoE not supported on %s,"
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002031 " flags: %lx fcoe_conn: %d\n",
2032 dev->netdev->name, dev->flags, dev->max_fcoe_conn);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002033 return;
2034 }
2035
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002036 hba = bnx2fc_hba_create(dev);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002037 if (!hba) {
2038 printk(KERN_ERR PFX "hba initialization failed\n");
2039 return;
2040 }
2041
Chad Dupuisf72464d2016-04-07 09:07:58 -04002042 pr_info(PFX "FCoE initialized for %s.\n", dev->netdev->name);
2043
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002044 /* Add HBA to the adapter list */
2045 mutex_lock(&bnx2fc_dev_lock);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002046 list_add_tail(&hba->list, &adapter_list);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002047 adapter_count++;
2048 mutex_unlock(&bnx2fc_dev_lock);
2049
Barak Witkowski2e499d32012-06-26 01:31:19 +00002050 dev->fcoe_cap = &hba->fcoe_cap;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002051 clear_bit(BNX2FC_CNIC_REGISTERED, &hba->reg_with_cnic);
2052 rc = dev->register_device(dev, CNIC_ULP_FCOE,
2053 (void *) hba);
2054 if (rc)
Bhanu Prakash Gollapudib2a554f2011-06-27 23:30:53 -07002055 printk(KERN_ERR PFX "register_device failed, rc = %d\n", rc);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002056 else
2057 set_bit(BNX2FC_CNIC_REGISTERED, &hba->reg_with_cnic);
2058}
2059
Eddie Wai06808102013-09-25 22:01:20 -07002060/* Assumes rtnl_lock and the bnx2fc_dev_lock are already taken */
2061static int __bnx2fc_disable(struct fcoe_ctlr *ctlr)
2062{
2063 struct bnx2fc_interface *interface = fcoe_ctlr_priv(ctlr);
2064
2065 if (interface->enabled == true) {
2066 if (!ctlr->lp) {
2067 pr_err(PFX "__bnx2fc_disable: lport not found\n");
2068 return -ENODEV;
2069 } else {
2070 interface->enabled = false;
2071 fcoe_ctlr_link_down(ctlr);
2072 fcoe_clean_pending_queue(ctlr->lp);
2073 }
2074 }
2075 return 0;
2076}
2077
Robert Love6e89ea32012-11-27 06:53:40 +00002078/**
2079 * Deperecated: Use bnx2fc_enabled()
2080 */
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002081static int bnx2fc_disable(struct net_device *netdev)
2082{
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002083 struct bnx2fc_interface *interface;
Robert Lovefd8f8902012-05-22 19:06:16 -07002084 struct fcoe_ctlr *ctlr;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002085 int rc = 0;
2086
Nithin Sujir6702ca12011-03-17 17:13:27 -07002087 rtnl_lock();
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002088 mutex_lock(&bnx2fc_dev_lock);
2089
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002090 interface = bnx2fc_interface_lookup(netdev);
Robert Lovefd8f8902012-05-22 19:06:16 -07002091 ctlr = bnx2fc_to_ctlr(interface);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002092
Eddie Wai06808102013-09-25 22:01:20 -07002093 if (!interface) {
2094 rc = -ENODEV;
2095 pr_err(PFX "bnx2fc_disable: interface not found\n");
2096 } else {
2097 rc = __bnx2fc_disable(ctlr);
2098 }
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002099 mutex_unlock(&bnx2fc_dev_lock);
2100 rtnl_unlock();
2101 return rc;
2102}
2103
Joe Carnuccio2971ff62015-08-04 09:37:30 +03002104static uint bnx2fc_npiv_create_vports(struct fc_lport *lport,
2105 struct cnic_fc_npiv_tbl *npiv_tbl)
2106{
2107 struct fc_vport_identifiers vpid;
2108 uint i, created = 0;
2109
2110 if (npiv_tbl->count > MAX_NPIV_ENTRIES) {
2111 BNX2FC_HBA_DBG(lport, "Exceeded count max of npiv table\n");
2112 goto done;
2113 }
2114
2115 /* Sanity check the first entry to make sure it's not 0 */
2116 if (wwn_to_u64(npiv_tbl->wwnn[0]) == 0 &&
2117 wwn_to_u64(npiv_tbl->wwpn[0]) == 0) {
2118 BNX2FC_HBA_DBG(lport, "First NPIV table entries invalid.\n");
2119 goto done;
2120 }
2121
2122 vpid.roles = FC_PORT_ROLE_FCP_INITIATOR;
2123 vpid.vport_type = FC_PORTTYPE_NPIV;
2124 vpid.disable = false;
2125
2126 for (i = 0; i < npiv_tbl->count; i++) {
2127 vpid.node_name = wwn_to_u64(npiv_tbl->wwnn[i]);
2128 vpid.port_name = wwn_to_u64(npiv_tbl->wwpn[i]);
2129 scnprintf(vpid.symbolic_name, sizeof(vpid.symbolic_name),
2130 "NPIV[%u]:%016llx-%016llx",
2131 created, vpid.port_name, vpid.node_name);
2132 if (fc_vport_create(lport->host, 0, &vpid))
2133 created++;
2134 else
2135 BNX2FC_HBA_DBG(lport, "Failed to create vport\n");
2136 }
2137done:
2138 return created;
2139}
2140
Eddie Wai06808102013-09-25 22:01:20 -07002141static int __bnx2fc_enable(struct fcoe_ctlr *ctlr)
2142{
2143 struct bnx2fc_interface *interface = fcoe_ctlr_priv(ctlr);
Joe Carnuccio2971ff62015-08-04 09:37:30 +03002144 struct bnx2fc_hba *hba;
Arnd Bergmann720ba802015-10-07 15:11:04 +02002145 struct cnic_fc_npiv_tbl *npiv_tbl;
Joe Carnuccio2971ff62015-08-04 09:37:30 +03002146 struct fc_lport *lport;
Eddie Wai06808102013-09-25 22:01:20 -07002147
2148 if (interface->enabled == false) {
2149 if (!ctlr->lp) {
2150 pr_err(PFX "__bnx2fc_enable: lport not found\n");
2151 return -ENODEV;
2152 } else if (!bnx2fc_link_ok(ctlr->lp)) {
2153 fcoe_ctlr_link_up(ctlr);
2154 interface->enabled = true;
2155 }
2156 }
Joe Carnuccio2971ff62015-08-04 09:37:30 +03002157
2158 /* Create static NPIV ports if any are contained in NVRAM */
2159 hba = interface->hba;
2160 lport = ctlr->lp;
2161
2162 if (!hba)
2163 goto done;
2164
2165 if (!hba->cnic)
2166 goto done;
2167
2168 if (!lport)
2169 goto done;
2170
2171 if (!lport->host)
2172 goto done;
2173
2174 if (!hba->cnic->get_fc_npiv_tbl)
2175 goto done;
2176
Arnd Bergmann720ba802015-10-07 15:11:04 +02002177 npiv_tbl = kzalloc(sizeof(struct cnic_fc_npiv_tbl), GFP_KERNEL);
2178 if (!npiv_tbl)
Joe Carnuccio2971ff62015-08-04 09:37:30 +03002179 goto done;
2180
Arnd Bergmann720ba802015-10-07 15:11:04 +02002181 if (hba->cnic->get_fc_npiv_tbl(hba->cnic, npiv_tbl))
2182 goto done_free;
2183
2184 bnx2fc_npiv_create_vports(lport, npiv_tbl);
2185done_free:
2186 kfree(npiv_tbl);
Joe Carnuccio2971ff62015-08-04 09:37:30 +03002187done:
Eddie Wai06808102013-09-25 22:01:20 -07002188 return 0;
2189}
2190
Robert Love6e89ea32012-11-27 06:53:40 +00002191/**
2192 * Deprecated: Use bnx2fc_enabled()
2193 */
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002194static int bnx2fc_enable(struct net_device *netdev)
2195{
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002196 struct bnx2fc_interface *interface;
Robert Lovefd8f8902012-05-22 19:06:16 -07002197 struct fcoe_ctlr *ctlr;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002198 int rc = 0;
2199
Nithin Sujir6702ca12011-03-17 17:13:27 -07002200 rtnl_lock();
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002201 mutex_lock(&bnx2fc_dev_lock);
2202
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002203 interface = bnx2fc_interface_lookup(netdev);
Robert Lovefd8f8902012-05-22 19:06:16 -07002204 ctlr = bnx2fc_to_ctlr(interface);
Eddie Wai06808102013-09-25 22:01:20 -07002205 if (!interface) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002206 rc = -ENODEV;
Eddie Wai06808102013-09-25 22:01:20 -07002207 pr_err(PFX "bnx2fc_enable: interface not found\n");
2208 } else {
2209 rc = __bnx2fc_enable(ctlr);
Bhanu Prakash Gollapudi8a5badf2011-08-30 15:54:48 -07002210 }
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002211
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002212 mutex_unlock(&bnx2fc_dev_lock);
2213 rtnl_unlock();
2214 return rc;
2215}
2216
2217/**
Robert Love6e89ea32012-11-27 06:53:40 +00002218 * bnx2fc_ctlr_enabled() - Enable or disable an FCoE Controller
2219 * @cdev: The FCoE Controller that is being enabled or disabled
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002220 *
Robert Love6e89ea32012-11-27 06:53:40 +00002221 * fcoe_sysfs will ensure that the state of 'enabled' has
2222 * changed, so no checking is necessary here. This routine simply
2223 * calls fcoe_enable or fcoe_disable, both of which are deprecated.
2224 * When those routines are removed the functionality can be merged
2225 * here.
2226 */
2227static int bnx2fc_ctlr_enabled(struct fcoe_ctlr_device *cdev)
2228{
2229 struct fcoe_ctlr *ctlr = fcoe_ctlr_device_priv(cdev);
Robert Love6e89ea32012-11-27 06:53:40 +00002230
2231 switch (cdev->enabled) {
2232 case FCOE_CTLR_ENABLED:
Eddie Wai06808102013-09-25 22:01:20 -07002233 return __bnx2fc_enable(ctlr);
Robert Love6e89ea32012-11-27 06:53:40 +00002234 case FCOE_CTLR_DISABLED:
Eddie Wai06808102013-09-25 22:01:20 -07002235 return __bnx2fc_disable(ctlr);
Robert Love6e89ea32012-11-27 06:53:40 +00002236 case FCOE_CTLR_UNUSED:
2237 default:
2238 return -ENOTSUPP;
2239 };
2240}
2241
2242enum bnx2fc_create_link_state {
2243 BNX2FC_CREATE_LINK_DOWN,
2244 BNX2FC_CREATE_LINK_UP,
2245};
2246
2247/**
2248 * _bnx2fc_create() - Create bnx2fc FCoE interface
2249 * @netdev : The net_device object the Ethernet interface to create on
2250 * @fip_mode: The FIP mode for this creation
2251 * @link_state: The ctlr link state on creation
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002252 *
Robert Love6e89ea32012-11-27 06:53:40 +00002253 * Called from either the libfcoe 'create' module parameter
2254 * via fcoe_create or from fcoe_syfs's ctlr_create file.
2255 *
2256 * libfcoe's 'create' module parameter is deprecated so some
2257 * consolidation of code can be done when that interface is
2258 * removed.
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002259 *
2260 * Returns: 0 for success
2261 */
Robert Love6e89ea32012-11-27 06:53:40 +00002262static int _bnx2fc_create(struct net_device *netdev,
2263 enum fip_state fip_mode,
2264 enum bnx2fc_create_link_state link_state)
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002265{
Robert Love6e89ea32012-11-27 06:53:40 +00002266 struct fcoe_ctlr_device *cdev;
Robert Lovefd8f8902012-05-22 19:06:16 -07002267 struct fcoe_ctlr *ctlr;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002268 struct bnx2fc_interface *interface;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002269 struct bnx2fc_hba *hba;
Bhanu Prakash Gollapudi7adc5a32012-06-04 16:15:44 -07002270 struct net_device *phys_dev = netdev;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002271 struct fc_lport *lport;
2272 struct ethtool_drvinfo drvinfo;
2273 int rc = 0;
Bhanu Prakash Gollapudi7adc5a32012-06-04 16:15:44 -07002274 int vlan_id = 0;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002275
2276 BNX2FC_MISC_DBG("Entered bnx2fc_create\n");
2277 if (fip_mode != FIP_MODE_FABRIC) {
2278 printk(KERN_ERR "fip mode not FABRIC\n");
2279 return -EIO;
2280 }
2281
Nithin Sujir6702ca12011-03-17 17:13:27 -07002282 rtnl_lock();
2283
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002284 mutex_lock(&bnx2fc_dev_lock);
2285
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002286 if (!try_module_get(THIS_MODULE)) {
2287 rc = -EINVAL;
2288 goto mod_err;
2289 }
2290
2291 /* obtain physical netdev */
Bhanu Prakash Gollapudi7adc5a32012-06-04 16:15:44 -07002292 if (netdev->priv_flags & IFF_802_1Q_VLAN)
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002293 phys_dev = vlan_dev_real_dev(netdev);
Bhanu Prakash Gollapudi7adc5a32012-06-04 16:15:44 -07002294
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002295 /* verify if the physical device is a netxtreme2 device */
2296 if (phys_dev->ethtool_ops && phys_dev->ethtool_ops->get_drvinfo) {
2297 memset(&drvinfo, 0, sizeof(drvinfo));
2298 phys_dev->ethtool_ops->get_drvinfo(phys_dev, &drvinfo);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002299 if (strncmp(drvinfo.driver, "bnx2x", strlen("bnx2x"))) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002300 printk(KERN_ERR PFX "Not a netxtreme2 device\n");
2301 rc = -EINVAL;
2302 goto netdev_err;
2303 }
2304 } else {
2305 printk(KERN_ERR PFX "unable to obtain drv_info\n");
2306 rc = -EINVAL;
2307 goto netdev_err;
2308 }
2309
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002310 /* obtain interface and initialize rest of the structure */
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002311 hba = bnx2fc_hba_lookup(phys_dev);
2312 if (!hba) {
2313 rc = -ENODEV;
2314 printk(KERN_ERR PFX "bnx2fc_create: hba not found\n");
2315 goto netdev_err;
2316 }
2317
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002318 if (bnx2fc_interface_lookup(netdev)) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002319 rc = -EEXIST;
2320 goto netdev_err;
2321 }
2322
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002323 interface = bnx2fc_interface_create(hba, netdev, fip_mode);
2324 if (!interface) {
2325 printk(KERN_ERR PFX "bnx2fc_interface_create failed\n");
Dan Carpenter2043e1f2014-11-04 13:37:59 +03002326 rc = -ENOMEM;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002327 goto ifput_err;
2328 }
2329
Bhanu Prakash Gollapudi7adc5a32012-06-04 16:15:44 -07002330 if (netdev->priv_flags & IFF_802_1Q_VLAN) {
2331 vlan_id = vlan_dev_vlan_id(netdev);
2332 interface->vlan_enabled = 1;
2333 }
2334
Robert Lovefd8f8902012-05-22 19:06:16 -07002335 ctlr = bnx2fc_to_ctlr(interface);
Robert Love01bdcb62013-03-25 11:00:26 -07002336 cdev = fcoe_ctlr_to_ctlr_dev(ctlr);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002337 interface->vlan_id = vlan_id;
Joe Carnuccio10755d32016-04-07 09:07:56 -04002338 interface->tm_timeout = BNX2FC_TM_TIMEOUT;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002339
2340 interface->timer_work_queue =
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002341 create_singlethread_workqueue("bnx2fc_timer_wq");
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002342 if (!interface->timer_work_queue) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002343 printk(KERN_ERR PFX "ulp_init could not create timer_wq\n");
2344 rc = -EINVAL;
2345 goto ifput_err;
2346 }
2347
Robert Love01bdcb62013-03-25 11:00:26 -07002348 lport = bnx2fc_if_create(interface, &cdev->dev, 0);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002349 if (!lport) {
2350 printk(KERN_ERR PFX "Failed to create interface (%s)\n",
2351 netdev->name);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002352 rc = -EINVAL;
2353 goto if_create_err;
2354 }
2355
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002356 /* Add interface to if_list */
2357 list_add_tail(&interface->list, &if_list);
2358
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002359 lport->boot_time = jiffies;
2360
2361 /* Make this master N_port */
Robert Lovefd8f8902012-05-22 19:06:16 -07002362 ctlr->lp = lport;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002363
Robert Love6e89ea32012-11-27 06:53:40 +00002364 if (link_state == BNX2FC_CREATE_LINK_UP)
2365 cdev->enabled = FCOE_CTLR_ENABLED;
2366 else
2367 cdev->enabled = FCOE_CTLR_DISABLED;
2368
2369 if (link_state == BNX2FC_CREATE_LINK_UP &&
2370 !bnx2fc_link_ok(lport)) {
Robert Lovefd8f8902012-05-22 19:06:16 -07002371 fcoe_ctlr_link_up(ctlr);
Bhanu Prakash Gollapudi8a5badf2011-08-30 15:54:48 -07002372 fc_host_port_type(lport->host) = FC_PORTTYPE_NPORT;
2373 set_bit(ADAPTER_STATE_READY, &interface->hba->adapter_state);
2374 }
2375
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002376 BNX2FC_HBA_DBG(lport, "create: START DISC\n");
2377 bnx2fc_start_disc(interface);
Robert Love6e89ea32012-11-27 06:53:40 +00002378
2379 if (link_state == BNX2FC_CREATE_LINK_UP)
2380 interface->enabled = true;
2381
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002382 /*
2383 * Release from kref_init in bnx2fc_interface_setup, on success
2384 * lport should be holding a reference taken in bnx2fc_if_create
2385 */
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002386 bnx2fc_interface_put(interface);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002387 /* put netdev that was held while calling dev_get_by_name */
2388 mutex_unlock(&bnx2fc_dev_lock);
2389 rtnl_unlock();
2390 return 0;
2391
2392if_create_err:
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002393 destroy_workqueue(interface->timer_work_queue);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002394ifput_err:
Bhanu Prakash Gollapudi013068f2011-08-30 15:54:52 -07002395 bnx2fc_net_cleanup(interface);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002396 bnx2fc_interface_put(interface);
Bhanu Prakash Gollapudi7d742f62012-01-23 18:00:48 -08002397 goto mod_err;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002398netdev_err:
2399 module_put(THIS_MODULE);
2400mod_err:
2401 mutex_unlock(&bnx2fc_dev_lock);
2402 rtnl_unlock();
2403 return rc;
2404}
2405
2406/**
Robert Love6e89ea32012-11-27 06:53:40 +00002407 * bnx2fc_create() - Create a bnx2fc interface
2408 * @netdev : The net_device object the Ethernet interface to create on
2409 * @fip_mode: The FIP mode for this creation
2410 *
2411 * Called from fcoe transport
2412 *
2413 * Returns: 0 for success
2414 */
2415static int bnx2fc_create(struct net_device *netdev, enum fip_state fip_mode)
2416{
2417 return _bnx2fc_create(netdev, fip_mode, BNX2FC_CREATE_LINK_UP);
2418}
2419
2420/**
2421 * bnx2fc_ctlr_alloc() - Allocate a bnx2fc interface from fcoe_sysfs
2422 * @netdev: The net_device to be used by the allocated FCoE Controller
2423 *
2424 * This routine is called from fcoe_sysfs. It will start the fcoe_ctlr
2425 * in a link_down state. The allows the user an opportunity to configure
2426 * the FCoE Controller from sysfs before enabling the FCoE Controller.
2427 *
2428 * Creating in with this routine starts the FCoE Controller in Fabric
2429 * mode. The user can change to VN2VN or another mode before enabling.
2430 */
2431static int bnx2fc_ctlr_alloc(struct net_device *netdev)
2432{
2433 return _bnx2fc_create(netdev, FIP_MODE_FABRIC,
2434 BNX2FC_CREATE_LINK_DOWN);
2435}
2436
2437/**
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002438 * bnx2fc_find_hba_for_cnic - maps cnic instance to bnx2fc hba instance
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002439 *
2440 * @cnic: Pointer to cnic device instance
2441 *
2442 **/
2443static struct bnx2fc_hba *bnx2fc_find_hba_for_cnic(struct cnic_dev *cnic)
2444{
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002445 struct bnx2fc_hba *hba;
2446
2447 /* Called with bnx2fc_dev_lock held */
Bhanu Prakash Gollapudid71fb3b2012-06-07 02:19:36 -07002448 list_for_each_entry(hba, &adapter_list, list) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002449 if (hba->cnic == cnic)
2450 return hba;
2451 }
2452 return NULL;
2453}
2454
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002455static struct bnx2fc_interface *bnx2fc_interface_lookup(struct net_device
2456 *netdev)
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002457{
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002458 struct bnx2fc_interface *interface;
2459
2460 /* Called with bnx2fc_dev_lock held */
2461 list_for_each_entry(interface, &if_list, list) {
2462 if (interface->netdev == netdev)
2463 return interface;
2464 }
2465 return NULL;
2466}
2467
2468static struct bnx2fc_hba *bnx2fc_hba_lookup(struct net_device
2469 *phys_dev)
2470{
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002471 struct bnx2fc_hba *hba;
2472
2473 /* Called with bnx2fc_dev_lock held */
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002474 list_for_each_entry(hba, &adapter_list, list) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002475 if (hba->phys_dev == phys_dev)
2476 return hba;
2477 }
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002478 printk(KERN_ERR PFX "adapter_lookup: hba NULL\n");
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002479 return NULL;
2480}
2481
2482/**
2483 * bnx2fc_ulp_exit - shuts down adapter instance and frees all resources
2484 *
2485 * @dev cnic device handle
2486 */
2487static void bnx2fc_ulp_exit(struct cnic_dev *dev)
2488{
2489 struct bnx2fc_hba *hba;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002490 struct bnx2fc_interface *interface, *tmp;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002491
2492 BNX2FC_MISC_DBG("Entered bnx2fc_ulp_exit\n");
2493
2494 if (!test_bit(CNIC_F_BNX2X_CLASS, &dev->flags)) {
2495 printk(KERN_ERR PFX "bnx2fc port check: %s, flags: %lx\n",
2496 dev->netdev->name, dev->flags);
2497 return;
2498 }
2499
2500 mutex_lock(&bnx2fc_dev_lock);
2501 hba = bnx2fc_find_hba_for_cnic(dev);
2502 if (!hba) {
2503 printk(KERN_ERR PFX "bnx2fc_ulp_exit: hba not found, dev 0%p\n",
2504 dev);
2505 mutex_unlock(&bnx2fc_dev_lock);
2506 return;
2507 }
2508
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002509 list_del_init(&hba->list);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002510 adapter_count--;
2511
Bhanu Prakash Gollapudiabc49a92011-08-04 17:38:42 -07002512 list_for_each_entry_safe(interface, tmp, &if_list, list)
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002513 /* destroy not called yet, move to quiesced list */
Bhanu Prakash Gollapudiabc49a92011-08-04 17:38:42 -07002514 if (interface->hba == hba)
Bhanu Prakash Gollapudieccdcd02011-08-24 18:56:42 -07002515 __bnx2fc_destroy(interface);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002516 mutex_unlock(&bnx2fc_dev_lock);
2517
Eddie Wai06c4f202013-12-11 15:30:21 -08002518 /* Ensure ALL destroy work has been completed before return */
2519 flush_workqueue(bnx2fc_wq);
2520
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002521 bnx2fc_ulp_stop(hba);
2522 /* unregister cnic device */
2523 if (test_and_clear_bit(BNX2FC_CNIC_REGISTERED, &hba->reg_with_cnic))
2524 hba->cnic->unregister_device(hba->cnic, CNIC_ULP_FCOE);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002525 bnx2fc_hba_destroy(hba);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002526}
2527
2528/**
2529 * bnx2fc_fcoe_reset - Resets the fcoe
2530 *
2531 * @shost: shost the reset is from
2532 *
2533 * Returns: always 0
2534 */
2535static int bnx2fc_fcoe_reset(struct Scsi_Host *shost)
2536{
2537 struct fc_lport *lport = shost_priv(shost);
2538 fc_lport_reset(lport);
2539 return 0;
2540}
2541
2542
2543static bool bnx2fc_match(struct net_device *netdev)
2544{
Bhanu Prakash Gollapudi7adc5a32012-06-04 16:15:44 -07002545 struct net_device *phys_dev = netdev;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002546
Bhanu Prakash Gollapudi7adc5a32012-06-04 16:15:44 -07002547 mutex_lock(&bnx2fc_dev_lock);
2548 if (netdev->priv_flags & IFF_802_1Q_VLAN)
2549 phys_dev = vlan_dev_real_dev(netdev);
2550
2551 if (bnx2fc_hba_lookup(phys_dev)) {
2552 mutex_unlock(&bnx2fc_dev_lock);
2553 return true;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002554 }
Bhanu Prakash Gollapudi7adc5a32012-06-04 16:15:44 -07002555
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002556 mutex_unlock(&bnx2fc_dev_lock);
2557 return false;
2558}
2559
2560
2561static struct fcoe_transport bnx2fc_transport = {
2562 .name = {"bnx2fc"},
2563 .attached = false,
2564 .list = LIST_HEAD_INIT(bnx2fc_transport.list),
Robert Love6e89ea32012-11-27 06:53:40 +00002565 .alloc = bnx2fc_ctlr_alloc,
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002566 .match = bnx2fc_match,
2567 .create = bnx2fc_create,
2568 .destroy = bnx2fc_destroy,
2569 .enable = bnx2fc_enable,
2570 .disable = bnx2fc_disable,
2571};
2572
2573/**
2574 * bnx2fc_percpu_thread_create - Create a receive thread for an
2575 * online CPU
2576 *
2577 * @cpu: cpu index for the online cpu
2578 */
2579static void bnx2fc_percpu_thread_create(unsigned int cpu)
2580{
2581 struct bnx2fc_percpu_s *p;
2582 struct task_struct *thread;
2583
2584 p = &per_cpu(bnx2fc_percpu, cpu);
2585
Eric Dumazet69614272012-06-04 16:15:42 -07002586 thread = kthread_create_on_node(bnx2fc_percpu_io_thread,
2587 (void *)p, cpu_to_node(cpu),
2588 "bnx2fc_thread/%d", cpu);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002589 /* bind thread to the cpu */
Bhanu Prakash Gollapudi32248762011-08-04 17:38:36 -07002590 if (likely(!IS_ERR(thread))) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002591 kthread_bind(thread, cpu);
2592 p->iothread = thread;
2593 wake_up_process(thread);
2594 }
2595}
2596
2597static void bnx2fc_percpu_thread_destroy(unsigned int cpu)
2598{
2599 struct bnx2fc_percpu_s *p;
2600 struct task_struct *thread;
2601 struct bnx2fc_work *work, *tmp;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002602
2603 BNX2FC_MISC_DBG("destroying io thread for CPU %d\n", cpu);
2604
2605 /* Prevent any new work from being queued for this CPU */
2606 p = &per_cpu(bnx2fc_percpu, cpu);
2607 spin_lock_bh(&p->fp_work_lock);
2608 thread = p->iothread;
2609 p->iothread = NULL;
2610
2611
2612 /* Free all work in the list */
Bhanu Prakash Gollapudi32248762011-08-04 17:38:36 -07002613 list_for_each_entry_safe(work, tmp, &p->work_list, list) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002614 list_del_init(&work->list);
2615 bnx2fc_process_cq_compl(work->tgt, work->wqe);
2616 kfree(work);
2617 }
2618
2619 spin_unlock_bh(&p->fp_work_lock);
2620
2621 if (thread)
2622 kthread_stop(thread);
2623}
2624
2625/**
2626 * bnx2fc_cpu_callback - Handler for CPU hotplug events
2627 *
2628 * @nfb: The callback data block
2629 * @action: The event triggering the callback
2630 * @hcpu: The index of the CPU that the event is for
2631 *
2632 * This creates or destroys per-CPU data for fcoe
2633 *
2634 * Returns NOTIFY_OK always.
2635 */
2636static int bnx2fc_cpu_callback(struct notifier_block *nfb,
2637 unsigned long action, void *hcpu)
2638{
2639 unsigned cpu = (unsigned long)hcpu;
2640
2641 switch (action) {
2642 case CPU_ONLINE:
2643 case CPU_ONLINE_FROZEN:
2644 printk(PFX "CPU %x online: Create Rx thread\n", cpu);
2645 bnx2fc_percpu_thread_create(cpu);
2646 break;
2647 case CPU_DEAD:
2648 case CPU_DEAD_FROZEN:
2649 printk(PFX "CPU %x offline: Remove Rx thread\n", cpu);
2650 bnx2fc_percpu_thread_destroy(cpu);
2651 break;
2652 default:
2653 break;
2654 }
2655 return NOTIFY_OK;
2656}
2657
Joe Carnuccio10755d32016-04-07 09:07:56 -04002658static int bnx2fc_slave_configure(struct scsi_device *sdev)
2659{
2660 if (!bnx2fc_queue_depth)
2661 return 0;
2662
2663 scsi_change_queue_depth(sdev, bnx2fc_queue_depth);
2664 return 0;
2665}
2666
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002667/**
2668 * bnx2fc_mod_init - module init entry point
2669 *
2670 * Initialize driver wide global data structures, and register
2671 * with cnic module
2672 **/
2673static int __init bnx2fc_mod_init(void)
2674{
2675 struct fcoe_percpu_s *bg;
2676 struct task_struct *l2_thread;
2677 int rc = 0;
2678 unsigned int cpu = 0;
2679 struct bnx2fc_percpu_s *p;
2680
2681 printk(KERN_INFO PFX "%s", version);
2682
2683 /* register as a fcoe transport */
2684 rc = fcoe_transport_attach(&bnx2fc_transport);
2685 if (rc) {
2686 printk(KERN_ERR "failed to register an fcoe transport, check "
2687 "if libfcoe is loaded\n");
2688 goto out;
2689 }
2690
2691 INIT_LIST_HEAD(&adapter_list);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002692 INIT_LIST_HEAD(&if_list);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002693 mutex_init(&bnx2fc_dev_lock);
2694 adapter_count = 0;
2695
2696 /* Attach FC transport template */
2697 rc = bnx2fc_attach_transport();
2698 if (rc)
2699 goto detach_ft;
2700
2701 bnx2fc_wq = alloc_workqueue("bnx2fc", 0, 0);
2702 if (!bnx2fc_wq) {
2703 rc = -ENOMEM;
2704 goto release_bt;
2705 }
2706
2707 bg = &bnx2fc_global;
2708 skb_queue_head_init(&bg->fcoe_rx_list);
2709 l2_thread = kthread_create(bnx2fc_l2_rcv_thread,
2710 (void *)bg,
2711 "bnx2fc_l2_thread");
2712 if (IS_ERR(l2_thread)) {
2713 rc = PTR_ERR(l2_thread);
2714 goto free_wq;
2715 }
2716 wake_up_process(l2_thread);
2717 spin_lock_bh(&bg->fcoe_rx_list.lock);
Sebastian Andrzej Siewior4b9bc862016-04-12 17:16:54 +02002718 bg->kthread = l2_thread;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002719 spin_unlock_bh(&bg->fcoe_rx_list.lock);
2720
2721 for_each_possible_cpu(cpu) {
2722 p = &per_cpu(bnx2fc_percpu, cpu);
2723 INIT_LIST_HEAD(&p->work_list);
2724 spin_lock_init(&p->fp_work_lock);
2725 }
2726
Srivatsa S. Bhat7229b6d2014-03-11 02:09:45 +05302727 cpu_notifier_register_begin();
2728
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002729 for_each_online_cpu(cpu) {
2730 bnx2fc_percpu_thread_create(cpu);
2731 }
2732
2733 /* Initialize per CPU interrupt thread */
Srivatsa S. Bhat7229b6d2014-03-11 02:09:45 +05302734 __register_hotcpu_notifier(&bnx2fc_cpu_notifier);
2735
2736 cpu_notifier_register_done();
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002737
2738 cnic_register_driver(CNIC_ULP_FCOE, &bnx2fc_cnic_cb);
2739
2740 return 0;
2741
2742free_wq:
2743 destroy_workqueue(bnx2fc_wq);
2744release_bt:
2745 bnx2fc_release_transport();
2746detach_ft:
2747 fcoe_transport_detach(&bnx2fc_transport);
2748out:
2749 return rc;
2750}
2751
2752static void __exit bnx2fc_mod_exit(void)
2753{
2754 LIST_HEAD(to_be_deleted);
2755 struct bnx2fc_hba *hba, *next;
2756 struct fcoe_percpu_s *bg;
2757 struct task_struct *l2_thread;
2758 struct sk_buff *skb;
2759 unsigned int cpu = 0;
2760
2761 /*
2762 * NOTE: Since cnic calls register_driver routine rtnl_lock,
2763 * it will have higher precedence than bnx2fc_dev_lock.
2764 * unregister_device() cannot be called with bnx2fc_dev_lock
2765 * held.
2766 */
2767 mutex_lock(&bnx2fc_dev_lock);
2768 list_splice(&adapter_list, &to_be_deleted);
2769 INIT_LIST_HEAD(&adapter_list);
2770 adapter_count = 0;
2771 mutex_unlock(&bnx2fc_dev_lock);
2772
2773 /* Unregister with cnic */
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002774 list_for_each_entry_safe(hba, next, &to_be_deleted, list) {
2775 list_del_init(&hba->list);
2776 printk(KERN_ERR PFX "MOD_EXIT:destroy hba = 0x%p\n",
2777 hba);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002778 bnx2fc_ulp_stop(hba);
2779 /* unregister cnic device */
2780 if (test_and_clear_bit(BNX2FC_CNIC_REGISTERED,
2781 &hba->reg_with_cnic))
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002782 hba->cnic->unregister_device(hba->cnic,
2783 CNIC_ULP_FCOE);
2784 bnx2fc_hba_destroy(hba);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002785 }
2786 cnic_unregister_driver(CNIC_ULP_FCOE);
2787
2788 /* Destroy global thread */
2789 bg = &bnx2fc_global;
2790 spin_lock_bh(&bg->fcoe_rx_list.lock);
Sebastian Andrzej Siewior4b9bc862016-04-12 17:16:54 +02002791 l2_thread = bg->kthread;
2792 bg->kthread = NULL;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002793 while ((skb = __skb_dequeue(&bg->fcoe_rx_list)) != NULL)
2794 kfree_skb(skb);
2795
2796 spin_unlock_bh(&bg->fcoe_rx_list.lock);
2797
2798 if (l2_thread)
2799 kthread_stop(l2_thread);
2800
Srivatsa S. Bhat7229b6d2014-03-11 02:09:45 +05302801 cpu_notifier_register_begin();
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002802
2803 /* Destroy per cpu threads */
2804 for_each_online_cpu(cpu) {
2805 bnx2fc_percpu_thread_destroy(cpu);
2806 }
2807
Srivatsa S. Bhat7229b6d2014-03-11 02:09:45 +05302808 __unregister_hotcpu_notifier(&bnx2fc_cpu_notifier);
2809
2810 cpu_notifier_register_done();
2811
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002812 destroy_workqueue(bnx2fc_wq);
2813 /*
2814 * detach from scsi transport
2815 * must happen after all destroys are done
2816 */
2817 bnx2fc_release_transport();
2818
2819 /* detach from fcoe transport */
2820 fcoe_transport_detach(&bnx2fc_transport);
2821}
2822
2823module_init(bnx2fc_mod_init);
2824module_exit(bnx2fc_mod_exit);
2825
Robert Love8d55e502012-05-22 19:06:26 -07002826static struct fcoe_sysfs_function_template bnx2fc_fcoe_sysfs_templ = {
Robert Love6e89ea32012-11-27 06:53:40 +00002827 .set_fcoe_ctlr_enabled = bnx2fc_ctlr_enabled,
Yi Zoub8b3e692012-12-06 06:24:59 +00002828 .get_fcoe_ctlr_link_fail = fcoe_ctlr_get_lesb,
2829 .get_fcoe_ctlr_vlink_fail = fcoe_ctlr_get_lesb,
2830 .get_fcoe_ctlr_miss_fka = fcoe_ctlr_get_lesb,
2831 .get_fcoe_ctlr_symb_err = fcoe_ctlr_get_lesb,
2832 .get_fcoe_ctlr_err_block = fcoe_ctlr_get_lesb,
2833 .get_fcoe_ctlr_fcs_error = fcoe_ctlr_get_lesb,
Robert Love8d55e502012-05-22 19:06:26 -07002834
2835 .get_fcoe_fcf_selected = fcoe_fcf_get_selected,
2836 .get_fcoe_fcf_vlan_id = bnx2fc_fcf_get_vlan_id,
2837};
2838
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002839static struct fc_function_template bnx2fc_transport_function = {
2840 .show_host_node_name = 1,
2841 .show_host_port_name = 1,
2842 .show_host_supported_classes = 1,
2843 .show_host_supported_fc4s = 1,
2844 .show_host_active_fc4s = 1,
2845 .show_host_maxframe_size = 1,
2846
2847 .show_host_port_id = 1,
2848 .show_host_supported_speeds = 1,
2849 .get_host_speed = fc_get_host_speed,
2850 .show_host_speed = 1,
2851 .show_host_port_type = 1,
2852 .get_host_port_state = fc_get_host_port_state,
2853 .show_host_port_state = 1,
2854 .show_host_symbolic_name = 1,
2855
2856 .dd_fcrport_size = (sizeof(struct fc_rport_libfc_priv) +
2857 sizeof(struct bnx2fc_rport)),
2858 .show_rport_maxframe_size = 1,
2859 .show_rport_supported_classes = 1,
2860
2861 .show_host_fabric_name = 1,
2862 .show_starget_node_name = 1,
2863 .show_starget_port_name = 1,
2864 .show_starget_port_id = 1,
2865 .set_rport_dev_loss_tmo = fc_set_rport_loss_tmo,
2866 .show_rport_dev_loss_tmo = 1,
2867 .get_fc_host_stats = bnx2fc_get_host_stats,
2868
2869 .issue_fc_host_lip = bnx2fc_fcoe_reset,
2870
2871 .terminate_rport_io = fc_rport_terminate_io,
2872
2873 .vport_create = bnx2fc_vport_create,
2874 .vport_delete = bnx2fc_vport_destroy,
2875 .vport_disable = bnx2fc_vport_disable,
Bhanu Prakash Gollapudie9a5289c2011-08-04 17:38:37 -07002876 .bsg_request = fc_lport_bsg_request,
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002877};
2878
2879static struct fc_function_template bnx2fc_vport_xport_function = {
2880 .show_host_node_name = 1,
2881 .show_host_port_name = 1,
2882 .show_host_supported_classes = 1,
2883 .show_host_supported_fc4s = 1,
2884 .show_host_active_fc4s = 1,
2885 .show_host_maxframe_size = 1,
2886
2887 .show_host_port_id = 1,
2888 .show_host_supported_speeds = 1,
2889 .get_host_speed = fc_get_host_speed,
2890 .show_host_speed = 1,
2891 .show_host_port_type = 1,
2892 .get_host_port_state = fc_get_host_port_state,
2893 .show_host_port_state = 1,
2894 .show_host_symbolic_name = 1,
2895
2896 .dd_fcrport_size = (sizeof(struct fc_rport_libfc_priv) +
2897 sizeof(struct bnx2fc_rport)),
2898 .show_rport_maxframe_size = 1,
2899 .show_rport_supported_classes = 1,
2900
2901 .show_host_fabric_name = 1,
2902 .show_starget_node_name = 1,
2903 .show_starget_port_name = 1,
2904 .show_starget_port_id = 1,
2905 .set_rport_dev_loss_tmo = fc_set_rport_loss_tmo,
2906 .show_rport_dev_loss_tmo = 1,
2907 .get_fc_host_stats = fc_get_host_stats,
2908 .issue_fc_host_lip = bnx2fc_fcoe_reset,
2909 .terminate_rport_io = fc_rport_terminate_io,
Bhanu Prakash Gollapudie9a5289c2011-08-04 17:38:37 -07002910 .bsg_request = fc_lport_bsg_request,
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002911};
2912
Joe Carnuccio10755d32016-04-07 09:07:56 -04002913/*
2914 * Additional scsi_host attributes.
2915 */
2916static ssize_t
2917bnx2fc_tm_timeout_show(struct device *dev, struct device_attribute *attr,
2918 char *buf)
2919{
2920 struct Scsi_Host *shost = class_to_shost(dev);
2921 struct fc_lport *lport = shost_priv(shost);
2922 struct fcoe_port *port = lport_priv(lport);
2923 struct bnx2fc_interface *interface = port->priv;
2924
2925 sprintf(buf, "%u\n", interface->tm_timeout);
2926 return strlen(buf);
2927}
2928
2929static ssize_t
2930bnx2fc_tm_timeout_store(struct device *dev,
2931 struct device_attribute *attr, const char *buf, size_t count)
2932{
2933 struct Scsi_Host *shost = class_to_shost(dev);
2934 struct fc_lport *lport = shost_priv(shost);
2935 struct fcoe_port *port = lport_priv(lport);
2936 struct bnx2fc_interface *interface = port->priv;
2937 int rval, val;
2938
2939 rval = kstrtouint(buf, 10, &val);
2940 if (rval)
2941 return rval;
2942 if (val > 255)
2943 return -ERANGE;
2944
2945 interface->tm_timeout = (u8)val;
2946 return strlen(buf);
2947}
2948
2949static DEVICE_ATTR(tm_timeout, S_IRUGO|S_IWUSR, bnx2fc_tm_timeout_show,
2950 bnx2fc_tm_timeout_store);
2951
2952static struct device_attribute *bnx2fc_host_attrs[] = {
2953 &dev_attr_tm_timeout,
2954 NULL,
2955};
2956
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002957/**
2958 * scsi_host_template structure used while registering with SCSI-ml
2959 */
2960static struct scsi_host_template bnx2fc_shost_template = {
2961 .module = THIS_MODULE,
Saurav Kashyap17d87c42014-07-03 08:18:28 -04002962 .name = "QLogic Offload FCoE Initiator",
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002963 .queuecommand = bnx2fc_queuecommand,
2964 .eh_abort_handler = bnx2fc_eh_abort, /* abts */
2965 .eh_device_reset_handler = bnx2fc_eh_device_reset, /* lun reset */
2966 .eh_target_reset_handler = bnx2fc_eh_target_reset, /* tgt reset */
2967 .eh_host_reset_handler = fc_eh_host_reset,
2968 .slave_alloc = fc_slave_alloc,
Christoph Hellwigdb5ed4d2014-11-13 15:08:42 +01002969 .change_queue_depth = scsi_change_queue_depth,
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002970 .this_id = -1,
2971 .cmd_per_lun = 3,
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002972 .use_clustering = ENABLE_CLUSTERING,
2973 .sg_tablesize = BNX2FC_MAX_BDS_PER_CMD,
Bhanu Prakash Gollapudid450d772012-12-21 19:40:33 -08002974 .max_sectors = 1024,
Christoph Hellwigc40ecc12014-11-13 14:25:11 +01002975 .track_queue_depth = 1,
Joe Carnuccio10755d32016-04-07 09:07:56 -04002976 .slave_configure = bnx2fc_slave_configure,
2977 .shost_attrs = bnx2fc_host_attrs,
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002978};
2979
2980static struct libfc_function_template bnx2fc_libfc_fcn_templ = {
2981 .frame_send = bnx2fc_xmit,
2982 .elsct_send = bnx2fc_elsct_send,
2983 .fcp_abort_io = bnx2fc_abort_io,
2984 .fcp_cleanup = bnx2fc_cleanup,
Yi Zoub8b3e692012-12-06 06:24:59 +00002985 .get_lesb = fcoe_get_lesb,
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002986 .rport_event_callback = bnx2fc_rport_event_handler,
2987};
2988
2989/**
2990 * bnx2fc_cnic_cb - global template of bnx2fc - cnic driver interface
2991 * structure carrying callback function pointers
2992 */
2993static struct cnic_ulp_ops bnx2fc_cnic_cb = {
2994 .owner = THIS_MODULE,
2995 .cnic_init = bnx2fc_ulp_init,
2996 .cnic_exit = bnx2fc_ulp_exit,
2997 .cnic_start = bnx2fc_ulp_start,
2998 .cnic_stop = bnx2fc_ulp_stop,
2999 .indicate_kcqes = bnx2fc_indicate_kcqe,
3000 .indicate_netevent = bnx2fc_indicate_netevent,
Barak Witkowski2e499d32012-06-26 01:31:19 +00003001 .cnic_get_stats = bnx2fc_ulp_get_stats,
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08003002};