blob: f9ddb6156f1499cf2f5b11a00d4bd688b3dce32e [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 Dupuis975860902015-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;
Hannes Reinecke1917d422016-07-04 10:29:19 +020060static int bnx2fc_create(struct net_device *netdev, enum fip_mode 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 Gollapudif72f69792011-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 */
Baoyou Xie3f7d67d2016-09-04 14:52:21 +0800628static int bnx2fc_percpu_io_thread(void *arg)
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800629{
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
Baoyou Xie3f7d67d2016-09-04 14:52:21 +08001413static struct bnx2fc_interface *
1414bnx2fc_interface_create(struct bnx2fc_hba *hba,
1415 struct net_device *netdev,
1416 enum fip_state fip_mode)
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001417{
Robert Love8d55e502012-05-22 19:06:26 -07001418 struct fcoe_ctlr_device *ctlr_dev;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001419 struct bnx2fc_interface *interface;
Robert Lovefd8f8902012-05-22 19:06:16 -07001420 struct fcoe_ctlr *ctlr;
1421 int size;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001422 int rc = 0;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001423
Robert Lovefd8f8902012-05-22 19:06:16 -07001424 size = (sizeof(*interface) + sizeof(struct fcoe_ctlr));
Robert Love8d55e502012-05-22 19:06:26 -07001425 ctlr_dev = fcoe_ctlr_device_add(&netdev->dev, &bnx2fc_fcoe_sysfs_templ,
1426 size);
1427 if (!ctlr_dev) {
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001428 printk(KERN_ERR PFX "Unable to allocate interface structure\n");
1429 return NULL;
1430 }
Robert Love8d55e502012-05-22 19:06:26 -07001431 ctlr = fcoe_ctlr_device_priv(ctlr_dev);
Robert Love9d348762013-09-05 07:47:27 +00001432 ctlr->cdev = ctlr_dev;
Robert Lovefd8f8902012-05-22 19:06:16 -07001433 interface = fcoe_ctlr_priv(ctlr);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001434 dev_hold(netdev);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001435 kref_init(&interface->kref);
1436 interface->hba = hba;
1437 interface->netdev = netdev;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001438
1439 /* Initialize FIP */
Robert Lovefd8f8902012-05-22 19:06:16 -07001440 fcoe_ctlr_init(ctlr, fip_mode);
1441 ctlr->send = bnx2fc_fip_send;
1442 ctlr->update_mac = bnx2fc_update_src_mac;
1443 ctlr->get_src_addr = bnx2fc_get_src_mac;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001444 set_bit(BNX2FC_CTLR_INIT_DONE, &interface->if_flags);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001445
Bhanu Prakash Gollapudi776cebc2011-08-04 17:38:40 -07001446 rc = bnx2fc_interface_setup(interface);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001447 if (!rc)
1448 return interface;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001449
Robert Lovefd8f8902012-05-22 19:06:16 -07001450 fcoe_ctlr_destroy(ctlr);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001451 dev_put(netdev);
Robert Love8d55e502012-05-22 19:06:26 -07001452 fcoe_ctlr_device_delete(ctlr_dev);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001453 return NULL;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001454}
1455
1456/**
1457 * bnx2fc_if_create - Create FCoE instance on a given interface
1458 *
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001459 * @interface: FCoE interface to create a local port on
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001460 * @parent: Device pointer to be the parent in sysfs for the SCSI host
1461 * @npiv: Indicates if the port is vport or not
1462 *
1463 * Creates a fc_lport instance and a Scsi_Host instance and configure them.
1464 *
1465 * Returns: Allocated fc_lport or an error pointer
1466 */
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001467static struct fc_lport *bnx2fc_if_create(struct bnx2fc_interface *interface,
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001468 struct device *parent, int npiv)
1469{
Robert Lovefd8f8902012-05-22 19:06:16 -07001470 struct fcoe_ctlr *ctlr = bnx2fc_to_ctlr(interface);
Vasu Dev134a4e22011-04-28 15:55:44 -07001471 struct fc_lport *lport, *n_port;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001472 struct fcoe_port *port;
1473 struct Scsi_Host *shost;
1474 struct fc_vport *vport = dev_to_vport(parent);
Bhanu Prakash Gollapudid36b3272011-05-27 11:47:27 -07001475 struct bnx2fc_lport *blport;
Bhanu Prakash Gollapudi0eb43b42013-04-22 19:22:30 +00001476 struct bnx2fc_hba *hba = interface->hba;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001477 int rc = 0;
1478
Bhanu Prakash Gollapudid36b3272011-05-27 11:47:27 -07001479 blport = kzalloc(sizeof(struct bnx2fc_lport), GFP_KERNEL);
1480 if (!blport) {
Robert Lovefd8f8902012-05-22 19:06:16 -07001481 BNX2FC_HBA_DBG(ctlr->lp, "Unable to alloc blport\n");
Bhanu Prakash Gollapudid36b3272011-05-27 11:47:27 -07001482 return NULL;
1483 }
1484
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001485 /* Allocate Scsi_Host structure */
Bhanu Prakash Gollapudi0eb43b42013-04-22 19:22:30 +00001486 bnx2fc_shost_template.can_queue = hba->max_outstanding_cmds;
Vasu Dev134a4e22011-04-28 15:55:44 -07001487 if (!npiv)
1488 lport = libfc_host_alloc(&bnx2fc_shost_template, sizeof(*port));
1489 else
1490 lport = libfc_vport_create(vport, sizeof(*port));
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001491
1492 if (!lport) {
1493 printk(KERN_ERR PFX "could not allocate scsi host structure\n");
Bhanu Prakash Gollapudid36b3272011-05-27 11:47:27 -07001494 goto free_blport;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001495 }
1496 shost = lport->host;
1497 port = lport_priv(lport);
1498 port->lport = lport;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001499 port->priv = interface;
Yi Zouc3d79092012-12-06 06:24:29 +00001500 port->get_netdev = bnx2fc_netdev;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001501 INIT_WORK(&port->destroy_work, bnx2fc_destroy_work);
1502
1503 /* Configure fcoe_port */
1504 rc = bnx2fc_lport_config(lport);
1505 if (rc)
1506 goto lp_config_err;
1507
1508 if (npiv) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001509 printk(KERN_ERR PFX "Setting vport names, 0x%llX 0x%llX\n",
1510 vport->node_name, vport->port_name);
1511 fc_set_wwnn(lport, vport->node_name);
1512 fc_set_wwpn(lport, vport->port_name);
1513 }
1514 /* Configure netdev and networking properties of the lport */
Bhanu Prakash Gollapudi52439602011-08-04 17:38:50 -07001515 rc = bnx2fc_net_config(lport, interface->netdev);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001516 if (rc) {
1517 printk(KERN_ERR PFX "Error on bnx2fc_net_config\n");
1518 goto lp_config_err;
1519 }
1520
1521 rc = bnx2fc_shost_config(lport, parent);
1522 if (rc) {
1523 printk(KERN_ERR PFX "Couldnt configure shost for %s\n",
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001524 interface->netdev->name);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001525 goto lp_config_err;
1526 }
1527
1528 /* Initialize the libfc library */
1529 rc = bnx2fc_libfc_config(lport);
1530 if (rc) {
1531 printk(KERN_ERR PFX "Couldnt configure libfc\n");
1532 goto shost_err;
1533 }
1534 fc_host_port_type(lport->host) = FC_PORTTYPE_UNKNOWN;
1535
Joe Carnuccio10755d32016-04-07 09:07:56 -04001536 if (bnx2fc_devloss_tmo)
1537 fc_host_dev_loss_tmo(shost) = bnx2fc_devloss_tmo;
1538
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001539 /* Allocate exchange manager */
Vasu Dev134a4e22011-04-28 15:55:44 -07001540 if (!npiv)
Bhanu Prakash Gollapudi0eb43b42013-04-22 19:22:30 +00001541 rc = bnx2fc_em_config(lport, hba);
Vasu Dev134a4e22011-04-28 15:55:44 -07001542 else {
1543 shost = vport_to_shost(vport);
1544 n_port = shost_priv(shost);
1545 rc = fc_exch_mgr_list_clone(n_port, lport);
1546 }
1547
1548 if (rc) {
1549 printk(KERN_ERR PFX "Error on bnx2fc_em_config\n");
1550 goto shost_err;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001551 }
1552
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001553 bnx2fc_interface_get(interface);
Bhanu Prakash Gollapudid36b3272011-05-27 11:47:27 -07001554
1555 spin_lock_bh(&hba->hba_lock);
1556 blport->lport = lport;
1557 list_add_tail(&blport->list, &hba->vports);
1558 spin_unlock_bh(&hba->hba_lock);
1559
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001560 return lport;
1561
1562shost_err:
1563 scsi_remove_host(shost);
1564lp_config_err:
1565 scsi_host_put(lport->host);
Bhanu Prakash Gollapudid36b3272011-05-27 11:47:27 -07001566free_blport:
1567 kfree(blport);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001568 return NULL;
1569}
1570
Bhanu Prakash Gollapudi013068f2011-08-30 15:54:52 -07001571static void bnx2fc_net_cleanup(struct bnx2fc_interface *interface)
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001572{
1573 /* Dont listen for Ethernet packets anymore */
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001574 __dev_remove_pack(&interface->fcoe_packet_type);
1575 __dev_remove_pack(&interface->fip_packet_type);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001576 synchronize_net();
1577}
1578
Bhanu Prakash Gollapudi776cebc2011-08-04 17:38:40 -07001579static void bnx2fc_interface_cleanup(struct bnx2fc_interface *interface)
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001580{
Robert Lovefd8f8902012-05-22 19:06:16 -07001581 struct fcoe_ctlr *ctlr = bnx2fc_to_ctlr(interface);
1582 struct fc_lport *lport = ctlr->lp;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001583 struct fcoe_port *port = lport_priv(lport);
Bhanu Prakash Gollapudi9be17fc2011-08-04 17:38:41 -07001584 struct bnx2fc_hba *hba = interface->hba;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001585
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001586 /* Stop the transmit retry timer */
1587 del_timer_sync(&port->timer);
1588
1589 /* Free existing transmit skbs */
1590 fcoe_clean_pending_queue(lport);
1591
Bhanu Prakash Gollapudi013068f2011-08-30 15:54:52 -07001592 bnx2fc_net_cleanup(interface);
Bhanu Prakash Gollapudi9be17fc2011-08-04 17:38:41 -07001593
Bhanu Prakash Gollapudiabc49a92011-08-04 17:38:42 -07001594 bnx2fc_free_vport(hba, lport);
Bhanu Prakash Gollapudi9be17fc2011-08-04 17:38:41 -07001595}
1596
1597static void bnx2fc_if_destroy(struct fc_lport *lport)
1598{
1599
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001600 /* Free queued packets for the receive thread */
1601 bnx2fc_clean_rx_queue(lport);
1602
1603 /* Detach from scsi-ml */
1604 fc_remove_host(lport->host);
1605 scsi_remove_host(lport->host);
1606
1607 /*
1608 * Note that only the physical lport will have the exchange manager.
1609 * for vports, this function is NOP
1610 */
1611 fc_exch_mgr_free(lport);
1612
1613 /* Free memory used by statistical counters */
1614 fc_lport_free_stats(lport);
1615
1616 /* Release Scsi_Host */
1617 scsi_host_put(lport->host);
1618}
1619
Bhanu Prakash Gollapudieccdcd02011-08-24 18:56:42 -07001620static void __bnx2fc_destroy(struct bnx2fc_interface *interface)
Bhanu Prakash Gollapudiabc49a92011-08-04 17:38:42 -07001621{
Robert Lovefd8f8902012-05-22 19:06:16 -07001622 struct fcoe_ctlr *ctlr = bnx2fc_to_ctlr(interface);
1623 struct fc_lport *lport = ctlr->lp;
Bhanu Prakash Gollapudi0cbf32e2011-08-30 15:54:51 -07001624 struct fcoe_port *port = lport_priv(lport);
Bhanu Prakash Gollapudiabc49a92011-08-04 17:38:42 -07001625
1626 bnx2fc_interface_cleanup(interface);
1627 bnx2fc_stop(interface);
Bhanu Prakash Gollapudiabc49a92011-08-04 17:38:42 -07001628 list_del(&interface->list);
Bhanu Prakash Gollapudiabc49a92011-08-04 17:38:42 -07001629 bnx2fc_interface_put(interface);
Bhanu Prakash Gollapudi0cbf32e2011-08-30 15:54:51 -07001630 queue_work(bnx2fc_wq, &port->destroy_work);
Bhanu Prakash Gollapudiabc49a92011-08-04 17:38:42 -07001631}
1632
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001633/**
1634 * bnx2fc_destroy - Destroy a bnx2fc FCoE interface
1635 *
1636 * @buffer: The name of the Ethernet interface to be destroyed
1637 * @kp: The associated kernel parameter
1638 *
1639 * Called from sysfs.
1640 *
1641 * Returns: 0 for success
1642 */
1643static int bnx2fc_destroy(struct net_device *netdev)
1644{
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001645 struct bnx2fc_interface *interface = NULL;
Bhanu Prakash Gollapudi2a7b29c2012-01-23 18:00:46 -08001646 struct workqueue_struct *timer_work_queue;
Robert Lovefd8f8902012-05-22 19:06:16 -07001647 struct fcoe_ctlr *ctlr;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001648 int rc = 0;
1649
Nithin Sujir6702ca12011-03-17 17:13:27 -07001650 rtnl_lock();
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001651 mutex_lock(&bnx2fc_dev_lock);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001652
1653 interface = bnx2fc_interface_lookup(netdev);
Robert Lovefd8f8902012-05-22 19:06:16 -07001654 ctlr = bnx2fc_to_ctlr(interface);
1655 if (!interface || !ctlr->lp) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001656 rc = -ENODEV;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001657 printk(KERN_ERR PFX "bnx2fc_destroy: interface or lport not found\n");
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001658 goto netdev_err;
1659 }
1660
Bhanu Prakash Gollapudi2a7b29c2012-01-23 18:00:46 -08001661 timer_work_queue = interface->timer_work_queue;
Bhanu Prakash Gollapudieccdcd02011-08-24 18:56:42 -07001662 __bnx2fc_destroy(interface);
Bhanu Prakash Gollapudi2a7b29c2012-01-23 18:00:46 -08001663 destroy_workqueue(timer_work_queue);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001664
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001665netdev_err:
1666 mutex_unlock(&bnx2fc_dev_lock);
1667 rtnl_unlock();
1668 return rc;
1669}
1670
1671static void bnx2fc_destroy_work(struct work_struct *work)
1672{
1673 struct fcoe_port *port;
1674 struct fc_lport *lport;
1675
1676 port = container_of(work, struct fcoe_port, destroy_work);
1677 lport = port->lport;
1678
1679 BNX2FC_HBA_DBG(lport, "Entered bnx2fc_destroy_work\n");
1680
Bhanu Prakash Gollapudi9be17fc2011-08-04 17:38:41 -07001681 bnx2fc_if_destroy(lport);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001682}
1683
1684static void bnx2fc_unbind_adapter_devices(struct bnx2fc_hba *hba)
1685{
1686 bnx2fc_free_fw_resc(hba);
1687 bnx2fc_free_task_ctx(hba);
1688}
1689
1690/**
1691 * bnx2fc_bind_adapter_devices - binds bnx2fc adapter with the associated
1692 * pci structure
1693 *
1694 * @hba: Adapter instance
1695 */
1696static int bnx2fc_bind_adapter_devices(struct bnx2fc_hba *hba)
1697{
1698 if (bnx2fc_setup_task_ctx(hba))
1699 goto mem_err;
1700
1701 if (bnx2fc_setup_fw_resc(hba))
1702 goto mem_err;
1703
1704 return 0;
1705mem_err:
1706 bnx2fc_unbind_adapter_devices(hba);
1707 return -ENOMEM;
1708}
1709
1710static int bnx2fc_bind_pcidev(struct bnx2fc_hba *hba)
1711{
1712 struct cnic_dev *cnic;
Bhanu Prakash Gollapudic13d2b62013-03-08 13:28:51 -08001713 struct pci_dev *pdev;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001714
1715 if (!hba->cnic) {
1716 printk(KERN_ERR PFX "cnic is NULL\n");
1717 return -ENODEV;
1718 }
1719 cnic = hba->cnic;
Bhanu Prakash Gollapudic13d2b62013-03-08 13:28:51 -08001720 pdev = hba->pcidev = cnic->pcidev;
1721 if (!hba->pcidev)
1722 return -ENODEV;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001723
Bhanu Prakash Gollapudic13d2b62013-03-08 13:28:51 -08001724 switch (pdev->device) {
1725 case PCI_DEVICE_ID_NX2_57710:
1726 strncpy(hba->chip_num, "BCM57710", BCM_CHIP_LEN);
1727 break;
1728 case PCI_DEVICE_ID_NX2_57711:
1729 strncpy(hba->chip_num, "BCM57711", BCM_CHIP_LEN);
1730 break;
1731 case PCI_DEVICE_ID_NX2_57712:
1732 case PCI_DEVICE_ID_NX2_57712_MF:
1733 case PCI_DEVICE_ID_NX2_57712_VF:
1734 strncpy(hba->chip_num, "BCM57712", BCM_CHIP_LEN);
1735 break;
1736 case PCI_DEVICE_ID_NX2_57800:
1737 case PCI_DEVICE_ID_NX2_57800_MF:
1738 case PCI_DEVICE_ID_NX2_57800_VF:
1739 strncpy(hba->chip_num, "BCM57800", BCM_CHIP_LEN);
1740 break;
1741 case PCI_DEVICE_ID_NX2_57810:
1742 case PCI_DEVICE_ID_NX2_57810_MF:
1743 case PCI_DEVICE_ID_NX2_57810_VF:
1744 strncpy(hba->chip_num, "BCM57810", BCM_CHIP_LEN);
1745 break;
1746 case PCI_DEVICE_ID_NX2_57840:
1747 case PCI_DEVICE_ID_NX2_57840_MF:
1748 case PCI_DEVICE_ID_NX2_57840_VF:
1749 case PCI_DEVICE_ID_NX2_57840_2_20:
1750 case PCI_DEVICE_ID_NX2_57840_4_10:
1751 strncpy(hba->chip_num, "BCM57840", BCM_CHIP_LEN);
1752 break;
1753 default:
1754 pr_err(PFX "Unknown device id 0x%x\n", pdev->device);
1755 break;
1756 }
1757 pci_dev_get(hba->pcidev);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001758 return 0;
1759}
1760
1761static void bnx2fc_unbind_pcidev(struct bnx2fc_hba *hba)
1762{
Bhanu Prakash Gollapudic13d2b62013-03-08 13:28:51 -08001763 if (hba->pcidev) {
1764 hba->chip_num[0] = '\0';
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001765 pci_dev_put(hba->pcidev);
Bhanu Prakash Gollapudic13d2b62013-03-08 13:28:51 -08001766 }
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001767 hba->pcidev = NULL;
1768}
1769
Barak Witkowski2e499d32012-06-26 01:31:19 +00001770/**
1771 * bnx2fc_ulp_get_stats - cnic callback to populate FCoE stats
1772 *
1773 * @handle: transport handle pointing to adapter struture
1774 */
1775static int bnx2fc_ulp_get_stats(void *handle)
1776{
1777 struct bnx2fc_hba *hba = handle;
1778 struct cnic_dev *cnic;
1779 struct fcoe_stats_info *stats_addr;
1780
1781 if (!hba)
1782 return -EINVAL;
1783
1784 cnic = hba->cnic;
1785 stats_addr = &cnic->stats_addr->fcoe_stat;
1786 if (!stats_addr)
1787 return -EINVAL;
1788
1789 strncpy(stats_addr->version, BNX2FC_VERSION,
1790 sizeof(stats_addr->version));
1791 stats_addr->txq_size = BNX2FC_SQ_WQES_MAX;
1792 stats_addr->rxq_size = BNX2FC_CQ_WQES_MAX;
1793
1794 return 0;
1795}
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001796
1797
1798/**
1799 * bnx2fc_ulp_start - cnic callback to initialize & start adapter instance
1800 *
Masanari Iida59e13d42012-04-25 00:24:16 +09001801 * @handle: transport handle pointing to adapter structure
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001802 *
1803 * This function maps adapter structure to pcidev structure and initiates
1804 * firmware handshake to enable/initialize on-chip FCoE components.
1805 * This bnx2fc - cnic interface api callback is used after following
1806 * conditions are met -
1807 * a) underlying network interface is up (marked by event NETDEV_UP
1808 * from netdev
1809 * b) bnx2fc adatper structure is registered.
1810 */
1811static void bnx2fc_ulp_start(void *handle)
1812{
1813 struct bnx2fc_hba *hba = handle;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001814 struct bnx2fc_interface *interface;
Robert Lovefd8f8902012-05-22 19:06:16 -07001815 struct fcoe_ctlr *ctlr;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001816 struct fc_lport *lport;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001817
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001818 mutex_lock(&bnx2fc_dev_lock);
1819
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001820 if (!test_bit(BNX2FC_FLAG_FW_INIT_DONE, &hba->flags))
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001821 bnx2fc_fw_init(hba);
1822
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001823 BNX2FC_MISC_DBG("bnx2fc started.\n");
1824
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001825 list_for_each_entry(interface, &if_list, list) {
1826 if (interface->hba == hba) {
Robert Lovefd8f8902012-05-22 19:06:16 -07001827 ctlr = bnx2fc_to_ctlr(interface);
1828 lport = ctlr->lp;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001829 /* Kick off Fabric discovery*/
1830 printk(KERN_ERR PFX "ulp_init: start discovery\n");
1831 lport->tt.frame_send = bnx2fc_xmit;
1832 bnx2fc_start_disc(interface);
1833 }
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001834 }
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001835
1836 mutex_unlock(&bnx2fc_dev_lock);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001837}
1838
1839static void bnx2fc_port_shutdown(struct fc_lport *lport)
1840{
1841 BNX2FC_MISC_DBG("Entered %s\n", __func__);
1842 fc_fabric_logoff(lport);
1843 fc_lport_destroy(lport);
1844}
1845
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001846static void bnx2fc_stop(struct bnx2fc_interface *interface)
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001847{
Robert Lovefd8f8902012-05-22 19:06:16 -07001848 struct fcoe_ctlr *ctlr = bnx2fc_to_ctlr(interface);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001849 struct fc_lport *lport;
1850 struct fc_lport *vport;
1851
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001852 if (!test_bit(BNX2FC_FLAG_FW_INIT_DONE, &interface->hba->flags))
1853 return;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001854
Robert Lovefd8f8902012-05-22 19:06:16 -07001855 lport = ctlr->lp;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001856 bnx2fc_port_shutdown(lport);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001857
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001858 mutex_lock(&lport->lp_mutex);
1859 list_for_each_entry(vport, &lport->vports, list)
1860 fc_host_port_type(vport->host) =
1861 FC_PORTTYPE_UNKNOWN;
1862 mutex_unlock(&lport->lp_mutex);
1863 fc_host_port_type(lport->host) = FC_PORTTYPE_UNKNOWN;
Robert Lovefd8f8902012-05-22 19:06:16 -07001864 fcoe_ctlr_link_down(ctlr);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001865 fcoe_clean_pending_queue(lport);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001866}
1867
1868static int bnx2fc_fw_init(struct bnx2fc_hba *hba)
1869{
1870#define BNX2FC_INIT_POLL_TIME (1000 / HZ)
1871 int rc = -1;
1872 int i = HZ;
1873
1874 rc = bnx2fc_bind_adapter_devices(hba);
1875 if (rc) {
1876 printk(KERN_ALERT PFX
1877 "bnx2fc_bind_adapter_devices failed - rc = %d\n", rc);
1878 goto err_out;
1879 }
1880
1881 rc = bnx2fc_send_fw_fcoe_init_msg(hba);
1882 if (rc) {
1883 printk(KERN_ALERT PFX
1884 "bnx2fc_send_fw_fcoe_init_msg failed - rc = %d\n", rc);
1885 goto err_unbind;
1886 }
1887
1888 /*
1889 * Wait until the adapter init message is complete, and adapter
1890 * state is UP.
1891 */
1892 while (!test_bit(ADAPTER_STATE_UP, &hba->adapter_state) && i--)
1893 msleep(BNX2FC_INIT_POLL_TIME);
1894
1895 if (!test_bit(ADAPTER_STATE_UP, &hba->adapter_state)) {
1896 printk(KERN_ERR PFX "bnx2fc_start: %s failed to initialize. "
1897 "Ignoring...\n",
1898 hba->cnic->netdev->name);
1899 rc = -1;
1900 goto err_unbind;
1901 }
1902
1903
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001904 set_bit(BNX2FC_FLAG_FW_INIT_DONE, &hba->flags);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001905 return 0;
1906
1907err_unbind:
1908 bnx2fc_unbind_adapter_devices(hba);
1909err_out:
1910 return rc;
1911}
1912
1913static void bnx2fc_fw_destroy(struct bnx2fc_hba *hba)
1914{
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001915 if (test_and_clear_bit(BNX2FC_FLAG_FW_INIT_DONE, &hba->flags)) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001916 if (bnx2fc_send_fw_fcoe_destroy_msg(hba) == 0) {
1917 init_timer(&hba->destroy_timer);
1918 hba->destroy_timer.expires = BNX2FC_FW_TIMEOUT +
1919 jiffies;
1920 hba->destroy_timer.function = bnx2fc_destroy_timer;
1921 hba->destroy_timer.data = (unsigned long)hba;
1922 add_timer(&hba->destroy_timer);
1923 wait_event_interruptible(hba->destroy_wait,
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001924 test_bit(BNX2FC_FLAG_DESTROY_CMPL,
1925 &hba->flags));
Bhanu Prakash Gollapudicd703ae2011-08-04 17:38:43 -07001926 clear_bit(BNX2FC_FLAG_DESTROY_CMPL, &hba->flags);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001927 /* This should never happen */
1928 if (signal_pending(current))
1929 flush_signals(current);
1930
1931 del_timer_sync(&hba->destroy_timer);
1932 }
1933 bnx2fc_unbind_adapter_devices(hba);
1934 }
1935}
1936
1937/**
1938 * bnx2fc_ulp_stop - cnic callback to shutdown adapter instance
1939 *
1940 * @handle: transport handle pointing to adapter structure
1941 *
1942 * Driver checks if adapter is already in shutdown mode, if not start
1943 * the shutdown process.
1944 */
1945static void bnx2fc_ulp_stop(void *handle)
1946{
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001947 struct bnx2fc_hba *hba = handle;
1948 struct bnx2fc_interface *interface;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001949
1950 printk(KERN_ERR "ULP_STOP\n");
1951
1952 mutex_lock(&bnx2fc_dev_lock);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001953 if (!test_bit(BNX2FC_FLAG_FW_INIT_DONE, &hba->flags))
1954 goto exit;
1955 list_for_each_entry(interface, &if_list, list) {
1956 if (interface->hba == hba)
1957 bnx2fc_stop(interface);
1958 }
1959 BUG_ON(hba->num_ofld_sess != 0);
1960
1961 mutex_lock(&hba->hba_mutex);
1962 clear_bit(ADAPTER_STATE_UP, &hba->adapter_state);
1963 clear_bit(ADAPTER_STATE_GOING_DOWN,
1964 &hba->adapter_state);
1965
1966 clear_bit(ADAPTER_STATE_READY, &hba->adapter_state);
1967 mutex_unlock(&hba->hba_mutex);
1968
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001969 bnx2fc_fw_destroy(hba);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001970exit:
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001971 mutex_unlock(&bnx2fc_dev_lock);
1972}
1973
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001974static void bnx2fc_start_disc(struct bnx2fc_interface *interface)
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001975{
Robert Lovefd8f8902012-05-22 19:06:16 -07001976 struct fcoe_ctlr *ctlr = bnx2fc_to_ctlr(interface);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001977 struct fc_lport *lport;
1978 int wait_cnt = 0;
1979
1980 BNX2FC_MISC_DBG("Entered %s\n", __func__);
1981 /* Kick off FIP/FLOGI */
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001982 if (!test_bit(BNX2FC_FLAG_FW_INIT_DONE, &interface->hba->flags)) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001983 printk(KERN_ERR PFX "Init not done yet\n");
1984 return;
1985 }
1986
Robert Lovefd8f8902012-05-22 19:06:16 -07001987 lport = ctlr->lp;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001988 BNX2FC_HBA_DBG(lport, "calling fc_fabric_login\n");
1989
Bhanu Prakash Gollapudi8a5badf2011-08-30 15:54:48 -07001990 if (!bnx2fc_link_ok(lport) && interface->enabled) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001991 BNX2FC_HBA_DBG(lport, "ctlr_link_up\n");
Robert Lovefd8f8902012-05-22 19:06:16 -07001992 fcoe_ctlr_link_up(ctlr);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001993 fc_host_port_type(lport->host) = FC_PORTTYPE_NPORT;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001994 set_bit(ADAPTER_STATE_READY, &interface->hba->adapter_state);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001995 }
1996
1997 /* wait for the FCF to be selected before issuing FLOGI */
Robert Lovefd8f8902012-05-22 19:06:16 -07001998 while (!ctlr->sel_fcf) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001999 msleep(250);
2000 /* give up after 3 secs */
2001 if (++wait_cnt > 12)
2002 break;
2003 }
Bhanu Prakash Gollapudi627e6282011-08-04 17:38:35 -07002004
2005 /* Reset max receive frame size to default */
2006 if (fc_set_mfs(lport, BNX2FC_MFS))
2007 return;
2008
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002009 fc_lport_init(lport);
2010 fc_fabric_login(lport);
2011}
2012
2013
2014/**
2015 * bnx2fc_ulp_init - Initialize an adapter instance
2016 *
2017 * @dev : cnic device handle
2018 * Called from cnic_register_driver() context to initialize all
2019 * enumerated cnic devices. This routine allocates adapter structure
2020 * and other device specific resources.
2021 */
2022static void bnx2fc_ulp_init(struct cnic_dev *dev)
2023{
2024 struct bnx2fc_hba *hba;
2025 int rc = 0;
2026
2027 BNX2FC_MISC_DBG("Entered %s\n", __func__);
2028 /* bnx2fc works only when bnx2x is loaded */
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002029 if (!test_bit(CNIC_F_BNX2X_CLASS, &dev->flags) ||
2030 (dev->max_fcoe_conn == 0)) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002031 printk(KERN_ERR PFX "bnx2fc FCoE not supported on %s,"
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002032 " flags: %lx fcoe_conn: %d\n",
2033 dev->netdev->name, dev->flags, dev->max_fcoe_conn);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002034 return;
2035 }
2036
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002037 hba = bnx2fc_hba_create(dev);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002038 if (!hba) {
2039 printk(KERN_ERR PFX "hba initialization failed\n");
2040 return;
2041 }
2042
Chad Dupuisf72464d2016-04-07 09:07:58 -04002043 pr_info(PFX "FCoE initialized for %s.\n", dev->netdev->name);
2044
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002045 /* Add HBA to the adapter list */
2046 mutex_lock(&bnx2fc_dev_lock);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002047 list_add_tail(&hba->list, &adapter_list);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002048 adapter_count++;
2049 mutex_unlock(&bnx2fc_dev_lock);
2050
Barak Witkowski2e499d32012-06-26 01:31:19 +00002051 dev->fcoe_cap = &hba->fcoe_cap;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002052 clear_bit(BNX2FC_CNIC_REGISTERED, &hba->reg_with_cnic);
2053 rc = dev->register_device(dev, CNIC_ULP_FCOE,
2054 (void *) hba);
2055 if (rc)
Bhanu Prakash Gollapudib2a554f2011-06-27 23:30:53 -07002056 printk(KERN_ERR PFX "register_device failed, rc = %d\n", rc);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002057 else
2058 set_bit(BNX2FC_CNIC_REGISTERED, &hba->reg_with_cnic);
2059}
2060
Eddie Wai06808102013-09-25 22:01:20 -07002061/* Assumes rtnl_lock and the bnx2fc_dev_lock are already taken */
2062static int __bnx2fc_disable(struct fcoe_ctlr *ctlr)
2063{
2064 struct bnx2fc_interface *interface = fcoe_ctlr_priv(ctlr);
2065
2066 if (interface->enabled == true) {
2067 if (!ctlr->lp) {
2068 pr_err(PFX "__bnx2fc_disable: lport not found\n");
2069 return -ENODEV;
2070 } else {
2071 interface->enabled = false;
2072 fcoe_ctlr_link_down(ctlr);
2073 fcoe_clean_pending_queue(ctlr->lp);
2074 }
2075 }
2076 return 0;
2077}
2078
Robert Love6e89ea32012-11-27 06:53:40 +00002079/**
2080 * Deperecated: Use bnx2fc_enabled()
2081 */
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002082static int bnx2fc_disable(struct net_device *netdev)
2083{
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002084 struct bnx2fc_interface *interface;
Robert Lovefd8f8902012-05-22 19:06:16 -07002085 struct fcoe_ctlr *ctlr;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002086 int rc = 0;
2087
Nithin Sujir6702ca12011-03-17 17:13:27 -07002088 rtnl_lock();
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002089 mutex_lock(&bnx2fc_dev_lock);
2090
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002091 interface = bnx2fc_interface_lookup(netdev);
Robert Lovefd8f8902012-05-22 19:06:16 -07002092 ctlr = bnx2fc_to_ctlr(interface);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002093
Eddie Wai06808102013-09-25 22:01:20 -07002094 if (!interface) {
2095 rc = -ENODEV;
2096 pr_err(PFX "bnx2fc_disable: interface not found\n");
2097 } else {
2098 rc = __bnx2fc_disable(ctlr);
2099 }
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002100 mutex_unlock(&bnx2fc_dev_lock);
2101 rtnl_unlock();
2102 return rc;
2103}
2104
Joe Carnuccio2971ff62015-08-04 09:37:30 +03002105static uint bnx2fc_npiv_create_vports(struct fc_lport *lport,
2106 struct cnic_fc_npiv_tbl *npiv_tbl)
2107{
2108 struct fc_vport_identifiers vpid;
2109 uint i, created = 0;
2110
2111 if (npiv_tbl->count > MAX_NPIV_ENTRIES) {
2112 BNX2FC_HBA_DBG(lport, "Exceeded count max of npiv table\n");
2113 goto done;
2114 }
2115
2116 /* Sanity check the first entry to make sure it's not 0 */
2117 if (wwn_to_u64(npiv_tbl->wwnn[0]) == 0 &&
2118 wwn_to_u64(npiv_tbl->wwpn[0]) == 0) {
2119 BNX2FC_HBA_DBG(lport, "First NPIV table entries invalid.\n");
2120 goto done;
2121 }
2122
2123 vpid.roles = FC_PORT_ROLE_FCP_INITIATOR;
2124 vpid.vport_type = FC_PORTTYPE_NPIV;
2125 vpid.disable = false;
2126
2127 for (i = 0; i < npiv_tbl->count; i++) {
2128 vpid.node_name = wwn_to_u64(npiv_tbl->wwnn[i]);
2129 vpid.port_name = wwn_to_u64(npiv_tbl->wwpn[i]);
2130 scnprintf(vpid.symbolic_name, sizeof(vpid.symbolic_name),
2131 "NPIV[%u]:%016llx-%016llx",
2132 created, vpid.port_name, vpid.node_name);
2133 if (fc_vport_create(lport->host, 0, &vpid))
2134 created++;
2135 else
2136 BNX2FC_HBA_DBG(lport, "Failed to create vport\n");
2137 }
2138done:
2139 return created;
2140}
2141
Eddie Wai06808102013-09-25 22:01:20 -07002142static int __bnx2fc_enable(struct fcoe_ctlr *ctlr)
2143{
2144 struct bnx2fc_interface *interface = fcoe_ctlr_priv(ctlr);
Joe Carnuccio2971ff62015-08-04 09:37:30 +03002145 struct bnx2fc_hba *hba;
Arnd Bergmann720ba802015-10-07 15:11:04 +02002146 struct cnic_fc_npiv_tbl *npiv_tbl;
Joe Carnuccio2971ff62015-08-04 09:37:30 +03002147 struct fc_lport *lport;
Eddie Wai06808102013-09-25 22:01:20 -07002148
2149 if (interface->enabled == false) {
2150 if (!ctlr->lp) {
2151 pr_err(PFX "__bnx2fc_enable: lport not found\n");
2152 return -ENODEV;
2153 } else if (!bnx2fc_link_ok(ctlr->lp)) {
2154 fcoe_ctlr_link_up(ctlr);
2155 interface->enabled = true;
2156 }
2157 }
Joe Carnuccio2971ff62015-08-04 09:37:30 +03002158
2159 /* Create static NPIV ports if any are contained in NVRAM */
2160 hba = interface->hba;
2161 lport = ctlr->lp;
2162
2163 if (!hba)
2164 goto done;
2165
2166 if (!hba->cnic)
2167 goto done;
2168
2169 if (!lport)
2170 goto done;
2171
2172 if (!lport->host)
2173 goto done;
2174
2175 if (!hba->cnic->get_fc_npiv_tbl)
2176 goto done;
2177
Arnd Bergmann720ba802015-10-07 15:11:04 +02002178 npiv_tbl = kzalloc(sizeof(struct cnic_fc_npiv_tbl), GFP_KERNEL);
2179 if (!npiv_tbl)
Joe Carnuccio2971ff62015-08-04 09:37:30 +03002180 goto done;
2181
Arnd Bergmann720ba802015-10-07 15:11:04 +02002182 if (hba->cnic->get_fc_npiv_tbl(hba->cnic, npiv_tbl))
2183 goto done_free;
2184
2185 bnx2fc_npiv_create_vports(lport, npiv_tbl);
2186done_free:
2187 kfree(npiv_tbl);
Joe Carnuccio2971ff62015-08-04 09:37:30 +03002188done:
Eddie Wai06808102013-09-25 22:01:20 -07002189 return 0;
2190}
2191
Robert Love6e89ea32012-11-27 06:53:40 +00002192/**
2193 * Deprecated: Use bnx2fc_enabled()
2194 */
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002195static int bnx2fc_enable(struct net_device *netdev)
2196{
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002197 struct bnx2fc_interface *interface;
Robert Lovefd8f8902012-05-22 19:06:16 -07002198 struct fcoe_ctlr *ctlr;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002199 int rc = 0;
2200
Nithin Sujir6702ca12011-03-17 17:13:27 -07002201 rtnl_lock();
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002202 mutex_lock(&bnx2fc_dev_lock);
2203
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002204 interface = bnx2fc_interface_lookup(netdev);
Robert Lovefd8f8902012-05-22 19:06:16 -07002205 ctlr = bnx2fc_to_ctlr(interface);
Eddie Wai06808102013-09-25 22:01:20 -07002206 if (!interface) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002207 rc = -ENODEV;
Eddie Wai06808102013-09-25 22:01:20 -07002208 pr_err(PFX "bnx2fc_enable: interface not found\n");
2209 } else {
2210 rc = __bnx2fc_enable(ctlr);
Bhanu Prakash Gollapudi8a5badf2011-08-30 15:54:48 -07002211 }
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002212
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002213 mutex_unlock(&bnx2fc_dev_lock);
2214 rtnl_unlock();
2215 return rc;
2216}
2217
2218/**
Robert Love6e89ea32012-11-27 06:53:40 +00002219 * bnx2fc_ctlr_enabled() - Enable or disable an FCoE Controller
2220 * @cdev: The FCoE Controller that is being enabled or disabled
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002221 *
Robert Love6e89ea32012-11-27 06:53:40 +00002222 * fcoe_sysfs will ensure that the state of 'enabled' has
2223 * changed, so no checking is necessary here. This routine simply
2224 * calls fcoe_enable or fcoe_disable, both of which are deprecated.
2225 * When those routines are removed the functionality can be merged
2226 * here.
2227 */
2228static int bnx2fc_ctlr_enabled(struct fcoe_ctlr_device *cdev)
2229{
2230 struct fcoe_ctlr *ctlr = fcoe_ctlr_device_priv(cdev);
Robert Love6e89ea32012-11-27 06:53:40 +00002231
2232 switch (cdev->enabled) {
2233 case FCOE_CTLR_ENABLED:
Eddie Wai06808102013-09-25 22:01:20 -07002234 return __bnx2fc_enable(ctlr);
Robert Love6e89ea32012-11-27 06:53:40 +00002235 case FCOE_CTLR_DISABLED:
Eddie Wai06808102013-09-25 22:01:20 -07002236 return __bnx2fc_disable(ctlr);
Robert Love6e89ea32012-11-27 06:53:40 +00002237 case FCOE_CTLR_UNUSED:
2238 default:
2239 return -ENOTSUPP;
2240 };
2241}
2242
2243enum bnx2fc_create_link_state {
2244 BNX2FC_CREATE_LINK_DOWN,
2245 BNX2FC_CREATE_LINK_UP,
2246};
2247
2248/**
2249 * _bnx2fc_create() - Create bnx2fc FCoE interface
2250 * @netdev : The net_device object the Ethernet interface to create on
2251 * @fip_mode: The FIP mode for this creation
2252 * @link_state: The ctlr link state on creation
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002253 *
Robert Love6e89ea32012-11-27 06:53:40 +00002254 * Called from either the libfcoe 'create' module parameter
2255 * via fcoe_create or from fcoe_syfs's ctlr_create file.
2256 *
2257 * libfcoe's 'create' module parameter is deprecated so some
2258 * consolidation of code can be done when that interface is
2259 * removed.
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002260 *
2261 * Returns: 0 for success
2262 */
Robert Love6e89ea32012-11-27 06:53:40 +00002263static int _bnx2fc_create(struct net_device *netdev,
Hannes Reinecke1917d422016-07-04 10:29:19 +02002264 enum fip_mode fip_mode,
Robert Love6e89ea32012-11-27 06:53:40 +00002265 enum bnx2fc_create_link_state link_state)
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002266{
Robert Love6e89ea32012-11-27 06:53:40 +00002267 struct fcoe_ctlr_device *cdev;
Robert Lovefd8f8902012-05-22 19:06:16 -07002268 struct fcoe_ctlr *ctlr;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002269 struct bnx2fc_interface *interface;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002270 struct bnx2fc_hba *hba;
Bhanu Prakash Gollapudi7adc5a32012-06-04 16:15:44 -07002271 struct net_device *phys_dev = netdev;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002272 struct fc_lport *lport;
2273 struct ethtool_drvinfo drvinfo;
2274 int rc = 0;
Bhanu Prakash Gollapudi7adc5a32012-06-04 16:15:44 -07002275 int vlan_id = 0;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002276
2277 BNX2FC_MISC_DBG("Entered bnx2fc_create\n");
2278 if (fip_mode != FIP_MODE_FABRIC) {
2279 printk(KERN_ERR "fip mode not FABRIC\n");
2280 return -EIO;
2281 }
2282
Nithin Sujir6702ca12011-03-17 17:13:27 -07002283 rtnl_lock();
2284
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002285 mutex_lock(&bnx2fc_dev_lock);
2286
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002287 if (!try_module_get(THIS_MODULE)) {
2288 rc = -EINVAL;
2289 goto mod_err;
2290 }
2291
2292 /* obtain physical netdev */
Bhanu Prakash Gollapudi7adc5a32012-06-04 16:15:44 -07002293 if (netdev->priv_flags & IFF_802_1Q_VLAN)
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002294 phys_dev = vlan_dev_real_dev(netdev);
Bhanu Prakash Gollapudi7adc5a32012-06-04 16:15:44 -07002295
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002296 /* verify if the physical device is a netxtreme2 device */
2297 if (phys_dev->ethtool_ops && phys_dev->ethtool_ops->get_drvinfo) {
2298 memset(&drvinfo, 0, sizeof(drvinfo));
2299 phys_dev->ethtool_ops->get_drvinfo(phys_dev, &drvinfo);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002300 if (strncmp(drvinfo.driver, "bnx2x", strlen("bnx2x"))) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002301 printk(KERN_ERR PFX "Not a netxtreme2 device\n");
2302 rc = -EINVAL;
2303 goto netdev_err;
2304 }
2305 } else {
2306 printk(KERN_ERR PFX "unable to obtain drv_info\n");
2307 rc = -EINVAL;
2308 goto netdev_err;
2309 }
2310
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002311 /* obtain interface and initialize rest of the structure */
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002312 hba = bnx2fc_hba_lookup(phys_dev);
2313 if (!hba) {
2314 rc = -ENODEV;
2315 printk(KERN_ERR PFX "bnx2fc_create: hba not found\n");
2316 goto netdev_err;
2317 }
2318
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002319 if (bnx2fc_interface_lookup(netdev)) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002320 rc = -EEXIST;
2321 goto netdev_err;
2322 }
2323
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002324 interface = bnx2fc_interface_create(hba, netdev, fip_mode);
2325 if (!interface) {
2326 printk(KERN_ERR PFX "bnx2fc_interface_create failed\n");
Dan Carpenter2043e1f2014-11-04 13:37:59 +03002327 rc = -ENOMEM;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002328 goto ifput_err;
2329 }
2330
Bhanu Prakash Gollapudi7adc5a32012-06-04 16:15:44 -07002331 if (netdev->priv_flags & IFF_802_1Q_VLAN) {
2332 vlan_id = vlan_dev_vlan_id(netdev);
2333 interface->vlan_enabled = 1;
2334 }
2335
Robert Lovefd8f8902012-05-22 19:06:16 -07002336 ctlr = bnx2fc_to_ctlr(interface);
Robert Love01bdcb62013-03-25 11:00:26 -07002337 cdev = fcoe_ctlr_to_ctlr_dev(ctlr);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002338 interface->vlan_id = vlan_id;
Joe Carnuccio10755d32016-04-07 09:07:56 -04002339 interface->tm_timeout = BNX2FC_TM_TIMEOUT;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002340
2341 interface->timer_work_queue =
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002342 create_singlethread_workqueue("bnx2fc_timer_wq");
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002343 if (!interface->timer_work_queue) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002344 printk(KERN_ERR PFX "ulp_init could not create timer_wq\n");
2345 rc = -EINVAL;
2346 goto ifput_err;
2347 }
2348
Robert Love01bdcb62013-03-25 11:00:26 -07002349 lport = bnx2fc_if_create(interface, &cdev->dev, 0);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002350 if (!lport) {
2351 printk(KERN_ERR PFX "Failed to create interface (%s)\n",
2352 netdev->name);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002353 rc = -EINVAL;
2354 goto if_create_err;
2355 }
2356
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002357 /* Add interface to if_list */
2358 list_add_tail(&interface->list, &if_list);
2359
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002360 lport->boot_time = jiffies;
2361
2362 /* Make this master N_port */
Robert Lovefd8f8902012-05-22 19:06:16 -07002363 ctlr->lp = lport;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002364
Robert Love6e89ea32012-11-27 06:53:40 +00002365 if (link_state == BNX2FC_CREATE_LINK_UP)
2366 cdev->enabled = FCOE_CTLR_ENABLED;
2367 else
2368 cdev->enabled = FCOE_CTLR_DISABLED;
2369
2370 if (link_state == BNX2FC_CREATE_LINK_UP &&
2371 !bnx2fc_link_ok(lport)) {
Robert Lovefd8f8902012-05-22 19:06:16 -07002372 fcoe_ctlr_link_up(ctlr);
Bhanu Prakash Gollapudi8a5badf2011-08-30 15:54:48 -07002373 fc_host_port_type(lport->host) = FC_PORTTYPE_NPORT;
2374 set_bit(ADAPTER_STATE_READY, &interface->hba->adapter_state);
2375 }
2376
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002377 BNX2FC_HBA_DBG(lport, "create: START DISC\n");
2378 bnx2fc_start_disc(interface);
Robert Love6e89ea32012-11-27 06:53:40 +00002379
2380 if (link_state == BNX2FC_CREATE_LINK_UP)
2381 interface->enabled = true;
2382
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002383 /*
2384 * Release from kref_init in bnx2fc_interface_setup, on success
2385 * lport should be holding a reference taken in bnx2fc_if_create
2386 */
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002387 bnx2fc_interface_put(interface);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002388 /* put netdev that was held while calling dev_get_by_name */
2389 mutex_unlock(&bnx2fc_dev_lock);
2390 rtnl_unlock();
2391 return 0;
2392
2393if_create_err:
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002394 destroy_workqueue(interface->timer_work_queue);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002395ifput_err:
Bhanu Prakash Gollapudi013068f2011-08-30 15:54:52 -07002396 bnx2fc_net_cleanup(interface);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002397 bnx2fc_interface_put(interface);
Bhanu Prakash Gollapudi7d742f62012-01-23 18:00:48 -08002398 goto mod_err;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002399netdev_err:
2400 module_put(THIS_MODULE);
2401mod_err:
2402 mutex_unlock(&bnx2fc_dev_lock);
2403 rtnl_unlock();
2404 return rc;
2405}
2406
2407/**
Robert Love6e89ea32012-11-27 06:53:40 +00002408 * bnx2fc_create() - Create a bnx2fc interface
2409 * @netdev : The net_device object the Ethernet interface to create on
2410 * @fip_mode: The FIP mode for this creation
2411 *
2412 * Called from fcoe transport
2413 *
2414 * Returns: 0 for success
2415 */
Hannes Reinecke1917d422016-07-04 10:29:19 +02002416static int bnx2fc_create(struct net_device *netdev, enum fip_mode fip_mode)
Robert Love6e89ea32012-11-27 06:53:40 +00002417{
2418 return _bnx2fc_create(netdev, fip_mode, BNX2FC_CREATE_LINK_UP);
2419}
2420
2421/**
2422 * bnx2fc_ctlr_alloc() - Allocate a bnx2fc interface from fcoe_sysfs
2423 * @netdev: The net_device to be used by the allocated FCoE Controller
2424 *
2425 * This routine is called from fcoe_sysfs. It will start the fcoe_ctlr
2426 * in a link_down state. The allows the user an opportunity to configure
2427 * the FCoE Controller from sysfs before enabling the FCoE Controller.
2428 *
2429 * Creating in with this routine starts the FCoE Controller in Fabric
2430 * mode. The user can change to VN2VN or another mode before enabling.
2431 */
2432static int bnx2fc_ctlr_alloc(struct net_device *netdev)
2433{
2434 return _bnx2fc_create(netdev, FIP_MODE_FABRIC,
2435 BNX2FC_CREATE_LINK_DOWN);
2436}
2437
2438/**
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002439 * bnx2fc_find_hba_for_cnic - maps cnic instance to bnx2fc hba instance
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002440 *
2441 * @cnic: Pointer to cnic device instance
2442 *
2443 **/
2444static struct bnx2fc_hba *bnx2fc_find_hba_for_cnic(struct cnic_dev *cnic)
2445{
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002446 struct bnx2fc_hba *hba;
2447
2448 /* Called with bnx2fc_dev_lock held */
Bhanu Prakash Gollapudid71fb3b2012-06-07 02:19:36 -07002449 list_for_each_entry(hba, &adapter_list, list) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002450 if (hba->cnic == cnic)
2451 return hba;
2452 }
2453 return NULL;
2454}
2455
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002456static struct bnx2fc_interface *bnx2fc_interface_lookup(struct net_device
2457 *netdev)
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002458{
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002459 struct bnx2fc_interface *interface;
2460
2461 /* Called with bnx2fc_dev_lock held */
2462 list_for_each_entry(interface, &if_list, list) {
2463 if (interface->netdev == netdev)
2464 return interface;
2465 }
2466 return NULL;
2467}
2468
2469static struct bnx2fc_hba *bnx2fc_hba_lookup(struct net_device
2470 *phys_dev)
2471{
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002472 struct bnx2fc_hba *hba;
2473
2474 /* Called with bnx2fc_dev_lock held */
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002475 list_for_each_entry(hba, &adapter_list, list) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002476 if (hba->phys_dev == phys_dev)
2477 return hba;
2478 }
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002479 printk(KERN_ERR PFX "adapter_lookup: hba NULL\n");
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002480 return NULL;
2481}
2482
2483/**
2484 * bnx2fc_ulp_exit - shuts down adapter instance and frees all resources
2485 *
2486 * @dev cnic device handle
2487 */
2488static void bnx2fc_ulp_exit(struct cnic_dev *dev)
2489{
2490 struct bnx2fc_hba *hba;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002491 struct bnx2fc_interface *interface, *tmp;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002492
2493 BNX2FC_MISC_DBG("Entered bnx2fc_ulp_exit\n");
2494
2495 if (!test_bit(CNIC_F_BNX2X_CLASS, &dev->flags)) {
2496 printk(KERN_ERR PFX "bnx2fc port check: %s, flags: %lx\n",
2497 dev->netdev->name, dev->flags);
2498 return;
2499 }
2500
2501 mutex_lock(&bnx2fc_dev_lock);
2502 hba = bnx2fc_find_hba_for_cnic(dev);
2503 if (!hba) {
2504 printk(KERN_ERR PFX "bnx2fc_ulp_exit: hba not found, dev 0%p\n",
2505 dev);
2506 mutex_unlock(&bnx2fc_dev_lock);
2507 return;
2508 }
2509
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002510 list_del_init(&hba->list);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002511 adapter_count--;
2512
Bhanu Prakash Gollapudiabc49a92011-08-04 17:38:42 -07002513 list_for_each_entry_safe(interface, tmp, &if_list, list)
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002514 /* destroy not called yet, move to quiesced list */
Bhanu Prakash Gollapudiabc49a92011-08-04 17:38:42 -07002515 if (interface->hba == hba)
Bhanu Prakash Gollapudieccdcd02011-08-24 18:56:42 -07002516 __bnx2fc_destroy(interface);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002517 mutex_unlock(&bnx2fc_dev_lock);
2518
Eddie Wai06c4f202013-12-11 15:30:21 -08002519 /* Ensure ALL destroy work has been completed before return */
2520 flush_workqueue(bnx2fc_wq);
2521
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002522 bnx2fc_ulp_stop(hba);
2523 /* unregister cnic device */
2524 if (test_and_clear_bit(BNX2FC_CNIC_REGISTERED, &hba->reg_with_cnic))
2525 hba->cnic->unregister_device(hba->cnic, CNIC_ULP_FCOE);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002526 bnx2fc_hba_destroy(hba);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002527}
2528
2529/**
2530 * bnx2fc_fcoe_reset - Resets the fcoe
2531 *
2532 * @shost: shost the reset is from
2533 *
2534 * Returns: always 0
2535 */
2536static int bnx2fc_fcoe_reset(struct Scsi_Host *shost)
2537{
2538 struct fc_lport *lport = shost_priv(shost);
2539 fc_lport_reset(lport);
2540 return 0;
2541}
2542
2543
2544static bool bnx2fc_match(struct net_device *netdev)
2545{
Bhanu Prakash Gollapudi7adc5a32012-06-04 16:15:44 -07002546 struct net_device *phys_dev = netdev;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002547
Bhanu Prakash Gollapudi7adc5a32012-06-04 16:15:44 -07002548 mutex_lock(&bnx2fc_dev_lock);
2549 if (netdev->priv_flags & IFF_802_1Q_VLAN)
2550 phys_dev = vlan_dev_real_dev(netdev);
2551
2552 if (bnx2fc_hba_lookup(phys_dev)) {
2553 mutex_unlock(&bnx2fc_dev_lock);
2554 return true;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002555 }
Bhanu Prakash Gollapudi7adc5a32012-06-04 16:15:44 -07002556
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002557 mutex_unlock(&bnx2fc_dev_lock);
2558 return false;
2559}
2560
2561
2562static struct fcoe_transport bnx2fc_transport = {
2563 .name = {"bnx2fc"},
2564 .attached = false,
2565 .list = LIST_HEAD_INIT(bnx2fc_transport.list),
Robert Love6e89ea32012-11-27 06:53:40 +00002566 .alloc = bnx2fc_ctlr_alloc,
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002567 .match = bnx2fc_match,
2568 .create = bnx2fc_create,
2569 .destroy = bnx2fc_destroy,
2570 .enable = bnx2fc_enable,
2571 .disable = bnx2fc_disable,
2572};
2573
2574/**
2575 * bnx2fc_percpu_thread_create - Create a receive thread for an
2576 * online CPU
2577 *
2578 * @cpu: cpu index for the online cpu
2579 */
2580static void bnx2fc_percpu_thread_create(unsigned int cpu)
2581{
2582 struct bnx2fc_percpu_s *p;
2583 struct task_struct *thread;
2584
2585 p = &per_cpu(bnx2fc_percpu, cpu);
2586
Eric Dumazet69614272012-06-04 16:15:42 -07002587 thread = kthread_create_on_node(bnx2fc_percpu_io_thread,
2588 (void *)p, cpu_to_node(cpu),
2589 "bnx2fc_thread/%d", cpu);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002590 /* bind thread to the cpu */
Bhanu Prakash Gollapudi32248762011-08-04 17:38:36 -07002591 if (likely(!IS_ERR(thread))) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002592 kthread_bind(thread, cpu);
2593 p->iothread = thread;
2594 wake_up_process(thread);
2595 }
2596}
2597
2598static void bnx2fc_percpu_thread_destroy(unsigned int cpu)
2599{
2600 struct bnx2fc_percpu_s *p;
2601 struct task_struct *thread;
2602 struct bnx2fc_work *work, *tmp;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002603
2604 BNX2FC_MISC_DBG("destroying io thread for CPU %d\n", cpu);
2605
2606 /* Prevent any new work from being queued for this CPU */
2607 p = &per_cpu(bnx2fc_percpu, cpu);
2608 spin_lock_bh(&p->fp_work_lock);
2609 thread = p->iothread;
2610 p->iothread = NULL;
2611
2612
2613 /* Free all work in the list */
Bhanu Prakash Gollapudi32248762011-08-04 17:38:36 -07002614 list_for_each_entry_safe(work, tmp, &p->work_list, list) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002615 list_del_init(&work->list);
2616 bnx2fc_process_cq_compl(work->tgt, work->wqe);
2617 kfree(work);
2618 }
2619
2620 spin_unlock_bh(&p->fp_work_lock);
2621
2622 if (thread)
2623 kthread_stop(thread);
2624}
2625
2626/**
2627 * bnx2fc_cpu_callback - Handler for CPU hotplug events
2628 *
2629 * @nfb: The callback data block
2630 * @action: The event triggering the callback
2631 * @hcpu: The index of the CPU that the event is for
2632 *
2633 * This creates or destroys per-CPU data for fcoe
2634 *
2635 * Returns NOTIFY_OK always.
2636 */
2637static int bnx2fc_cpu_callback(struct notifier_block *nfb,
2638 unsigned long action, void *hcpu)
2639{
2640 unsigned cpu = (unsigned long)hcpu;
2641
2642 switch (action) {
2643 case CPU_ONLINE:
2644 case CPU_ONLINE_FROZEN:
2645 printk(PFX "CPU %x online: Create Rx thread\n", cpu);
2646 bnx2fc_percpu_thread_create(cpu);
2647 break;
2648 case CPU_DEAD:
2649 case CPU_DEAD_FROZEN:
2650 printk(PFX "CPU %x offline: Remove Rx thread\n", cpu);
2651 bnx2fc_percpu_thread_destroy(cpu);
2652 break;
2653 default:
2654 break;
2655 }
2656 return NOTIFY_OK;
2657}
2658
Joe Carnuccio10755d32016-04-07 09:07:56 -04002659static int bnx2fc_slave_configure(struct scsi_device *sdev)
2660{
2661 if (!bnx2fc_queue_depth)
2662 return 0;
2663
2664 scsi_change_queue_depth(sdev, bnx2fc_queue_depth);
2665 return 0;
2666}
2667
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002668/**
2669 * bnx2fc_mod_init - module init entry point
2670 *
2671 * Initialize driver wide global data structures, and register
2672 * with cnic module
2673 **/
2674static int __init bnx2fc_mod_init(void)
2675{
2676 struct fcoe_percpu_s *bg;
2677 struct task_struct *l2_thread;
2678 int rc = 0;
2679 unsigned int cpu = 0;
2680 struct bnx2fc_percpu_s *p;
2681
2682 printk(KERN_INFO PFX "%s", version);
2683
2684 /* register as a fcoe transport */
2685 rc = fcoe_transport_attach(&bnx2fc_transport);
2686 if (rc) {
2687 printk(KERN_ERR "failed to register an fcoe transport, check "
2688 "if libfcoe is loaded\n");
2689 goto out;
2690 }
2691
2692 INIT_LIST_HEAD(&adapter_list);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002693 INIT_LIST_HEAD(&if_list);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002694 mutex_init(&bnx2fc_dev_lock);
2695 adapter_count = 0;
2696
2697 /* Attach FC transport template */
2698 rc = bnx2fc_attach_transport();
2699 if (rc)
2700 goto detach_ft;
2701
2702 bnx2fc_wq = alloc_workqueue("bnx2fc", 0, 0);
2703 if (!bnx2fc_wq) {
2704 rc = -ENOMEM;
2705 goto release_bt;
2706 }
2707
2708 bg = &bnx2fc_global;
2709 skb_queue_head_init(&bg->fcoe_rx_list);
2710 l2_thread = kthread_create(bnx2fc_l2_rcv_thread,
2711 (void *)bg,
2712 "bnx2fc_l2_thread");
2713 if (IS_ERR(l2_thread)) {
2714 rc = PTR_ERR(l2_thread);
2715 goto free_wq;
2716 }
2717 wake_up_process(l2_thread);
2718 spin_lock_bh(&bg->fcoe_rx_list.lock);
Sebastian Andrzej Siewior4b9bc862016-04-12 17:16:54 +02002719 bg->kthread = l2_thread;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002720 spin_unlock_bh(&bg->fcoe_rx_list.lock);
2721
2722 for_each_possible_cpu(cpu) {
2723 p = &per_cpu(bnx2fc_percpu, cpu);
2724 INIT_LIST_HEAD(&p->work_list);
2725 spin_lock_init(&p->fp_work_lock);
2726 }
2727
Srivatsa S. Bhat7229b6d2014-03-11 02:09:45 +05302728 cpu_notifier_register_begin();
2729
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002730 for_each_online_cpu(cpu) {
2731 bnx2fc_percpu_thread_create(cpu);
2732 }
2733
2734 /* Initialize per CPU interrupt thread */
Srivatsa S. Bhat7229b6d2014-03-11 02:09:45 +05302735 __register_hotcpu_notifier(&bnx2fc_cpu_notifier);
2736
2737 cpu_notifier_register_done();
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002738
2739 cnic_register_driver(CNIC_ULP_FCOE, &bnx2fc_cnic_cb);
2740
2741 return 0;
2742
2743free_wq:
2744 destroy_workqueue(bnx2fc_wq);
2745release_bt:
2746 bnx2fc_release_transport();
2747detach_ft:
2748 fcoe_transport_detach(&bnx2fc_transport);
2749out:
2750 return rc;
2751}
2752
2753static void __exit bnx2fc_mod_exit(void)
2754{
2755 LIST_HEAD(to_be_deleted);
2756 struct bnx2fc_hba *hba, *next;
2757 struct fcoe_percpu_s *bg;
2758 struct task_struct *l2_thread;
2759 struct sk_buff *skb;
2760 unsigned int cpu = 0;
2761
2762 /*
2763 * NOTE: Since cnic calls register_driver routine rtnl_lock,
2764 * it will have higher precedence than bnx2fc_dev_lock.
2765 * unregister_device() cannot be called with bnx2fc_dev_lock
2766 * held.
2767 */
2768 mutex_lock(&bnx2fc_dev_lock);
Christophe JAILLET393c8012016-09-03 09:05:48 +02002769 list_splice_init(&adapter_list, &to_be_deleted);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002770 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};