blob: 9be273c320e2199abed79fe9b3c87925b9d81b04 [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
Chad Dupuis21144b82017-06-26 08:59:34 -07007 * Copyright (c) 2014-2016 QLogic Corporation
8 * Copyright (c) 2016-2017 Cavium Inc.
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08009 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation.
13 *
14 * Written by: Bhanu Prakash Gollapudi (bprakash@broadcom.com)
15 */
16
17#include "bnx2fc.h"
18
Jakub Kicinskicc698372020-11-20 14:50:52 -080019#include <linux/ethtool.h>
20
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -080021static struct list_head adapter_list;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -070022static struct list_head if_list;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -080023static u32 adapter_count;
24static DEFINE_MUTEX(bnx2fc_dev_lock);
25DEFINE_PER_CPU(struct bnx2fc_percpu_s, bnx2fc_percpu);
26
27#define DRV_MODULE_NAME "bnx2fc"
28#define DRV_MODULE_VERSION BNX2FC_VERSION
Chad Dupuisedb394b2015-10-19 15:40:41 -040029#define DRV_MODULE_RELDATE "October 15, 2015"
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -080030
31
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080032static char version[] =
Chad Dupuisde909d82015-10-19 15:40:36 -040033 "QLogic FCoE Driver " DRV_MODULE_NAME \
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -080034 " v" DRV_MODULE_VERSION " (" DRV_MODULE_RELDATE ")\n";
35
36
37MODULE_AUTHOR("Bhanu Prakash Gollapudi <bprakash@broadcom.com>");
Chad Dupuisde909d82015-10-19 15:40:36 -040038MODULE_DESCRIPTION("QLogic FCoE Driver");
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -080039MODULE_LICENSE("GPL");
40MODULE_VERSION(DRV_MODULE_VERSION);
41
42#define BNX2FC_MAX_QUEUE_DEPTH 256
43#define BNX2FC_MIN_QUEUE_DEPTH 32
44#define FCOE_WORD_TO_BYTE 4
45
46static struct scsi_transport_template *bnx2fc_transport_template;
47static struct scsi_transport_template *bnx2fc_vport_xport_template;
48
49struct workqueue_struct *bnx2fc_wq;
50
51/* bnx2fc structure needs only one instance of the fcoe_percpu_s structure.
52 * Here the io threads are per cpu but the l2 thread is just one
53 */
54struct fcoe_percpu_s bnx2fc_global;
Jason Yan5c2ef012020-09-12 11:37:58 +080055static DEFINE_SPINLOCK(bnx2fc_global_lock);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -080056
57static struct cnic_ulp_ops bnx2fc_cnic_cb;
58static struct libfc_function_template bnx2fc_libfc_fcn_templ;
59static struct scsi_host_template bnx2fc_shost_template;
60static struct fc_function_template bnx2fc_transport_function;
Robert Love8d55e502012-05-22 19:06:26 -070061static struct fcoe_sysfs_function_template bnx2fc_fcoe_sysfs_templ;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -080062static struct fc_function_template bnx2fc_vport_xport_function;
Hannes Reinecke1917d422016-07-04 10:29:19 +020063static int bnx2fc_create(struct net_device *netdev, enum fip_mode fip_mode);
Bhanu Prakash Gollapudieccdcd02011-08-24 18:56:42 -070064static void __bnx2fc_destroy(struct bnx2fc_interface *interface);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -080065static int bnx2fc_destroy(struct net_device *net_device);
66static int bnx2fc_enable(struct net_device *netdev);
67static int bnx2fc_disable(struct net_device *netdev);
68
Robert Love6e89ea32012-11-27 06:53:40 +000069/* fcoe_syfs control interface handlers */
70static int bnx2fc_ctlr_alloc(struct net_device *netdev);
71static int bnx2fc_ctlr_enabled(struct fcoe_ctlr_device *cdev);
72
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -080073static void bnx2fc_recv_frame(struct sk_buff *skb);
74
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -070075static void bnx2fc_start_disc(struct bnx2fc_interface *interface);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -080076static int bnx2fc_shost_config(struct fc_lport *lport, struct device *dev);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -080077static int bnx2fc_lport_config(struct fc_lport *lport);
Bhanu Prakash Gollapudi0eb43b42013-04-22 19:22:30 +000078static int bnx2fc_em_config(struct fc_lport *lport, struct bnx2fc_hba *hba);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -080079static int bnx2fc_bind_adapter_devices(struct bnx2fc_hba *hba);
80static void bnx2fc_unbind_adapter_devices(struct bnx2fc_hba *hba);
81static int bnx2fc_bind_pcidev(struct bnx2fc_hba *hba);
82static void bnx2fc_unbind_pcidev(struct bnx2fc_hba *hba);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -070083static struct fc_lport *bnx2fc_if_create(struct bnx2fc_interface *interface,
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -080084 struct device *parent, int npiv);
John Meneghini847f9ea2022-01-14 23:00:44 -050085static void bnx2fc_port_destroy(struct fcoe_port *port);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -080086
87static struct bnx2fc_hba *bnx2fc_hba_lookup(struct net_device *phys_dev);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -070088static struct bnx2fc_interface *bnx2fc_interface_lookup(struct net_device
89 *phys_dev);
Bhanu Prakash Gollapudiabc49a92011-08-04 17:38:42 -070090static inline void bnx2fc_interface_put(struct bnx2fc_interface *interface);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -080091static struct bnx2fc_hba *bnx2fc_find_hba_for_cnic(struct cnic_dev *cnic);
92
93static int bnx2fc_fw_init(struct bnx2fc_hba *hba);
94static void bnx2fc_fw_destroy(struct bnx2fc_hba *hba);
95
96static void bnx2fc_port_shutdown(struct fc_lport *lport);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -070097static void bnx2fc_stop(struct bnx2fc_interface *interface);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -080098static int __init bnx2fc_mod_init(void);
99static void __exit bnx2fc_mod_exit(void);
100
101unsigned int bnx2fc_debug_level;
102module_param_named(debug_logging, bnx2fc_debug_level, int, S_IRUGO|S_IWUSR);
Jose Castillod4faee02016-01-29 14:39:26 +0000103MODULE_PARM_DESC(debug_logging,
104 "Option to enable extended logging,\n"
105 "\t\tDefault is 0 - no logging.\n"
106 "\t\t0x01 - SCSI cmd error, cleanup.\n"
107 "\t\t0x02 - Session setup, cleanup, etc.\n"
108 "\t\t0x04 - lport events, link, mtu, etc.\n"
109 "\t\t0x08 - ELS logs.\n"
110 "\t\t0x10 - fcoe L2 fame related logs.\n"
111 "\t\t0xff - LOG all messages.");
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800112
Jason Yan5c2ef012020-09-12 11:37:58 +0800113static uint bnx2fc_devloss_tmo;
Joe Carnuccio10755d32016-04-07 09:07:56 -0400114module_param_named(devloss_tmo, bnx2fc_devloss_tmo, uint, S_IRUGO);
115MODULE_PARM_DESC(devloss_tmo, " Change devloss_tmo for the remote ports "
116 "attached via bnx2fc.");
117
Jason Yan5c2ef012020-09-12 11:37:58 +0800118static uint bnx2fc_max_luns = BNX2FC_MAX_LUN;
Joe Carnuccio10755d32016-04-07 09:07:56 -0400119module_param_named(max_luns, bnx2fc_max_luns, uint, S_IRUGO);
120MODULE_PARM_DESC(max_luns, " Change the default max_lun per SCSI host. Default "
121 "0xffff.");
122
Jason Yan5c2ef012020-09-12 11:37:58 +0800123static uint bnx2fc_queue_depth;
Joe Carnuccio10755d32016-04-07 09:07:56 -0400124module_param_named(queue_depth, bnx2fc_queue_depth, uint, S_IRUGO);
125MODULE_PARM_DESC(queue_depth, " Change the default queue depth of SCSI devices "
126 "attached via bnx2fc.");
127
Jason Yan5c2ef012020-09-12 11:37:58 +0800128static uint bnx2fc_log_fka;
Chad Dupuis3f12f762016-04-07 09:07:57 -0400129module_param_named(log_fka, bnx2fc_log_fka, uint, S_IRUGO|S_IWUSR);
130MODULE_PARM_DESC(log_fka, " Print message to kernel log when fcoe is "
131 "initiating a FIP keep alive when debug logging is enabled.");
132
Bhanu Prakash Gollapudif72f69792011-10-03 16:45:02 -0700133static inline struct net_device *bnx2fc_netdev(const struct fc_lport *lport)
134{
135 return ((struct bnx2fc_interface *)
136 ((struct fcoe_port *)lport_priv(lport))->priv)->netdev;
137}
138
Robert Love8d55e502012-05-22 19:06:26 -0700139static void bnx2fc_fcf_get_vlan_id(struct fcoe_fcf_device *fcf_dev)
140{
141 struct fcoe_ctlr_device *ctlr_dev =
142 fcoe_fcf_dev_to_ctlr_dev(fcf_dev);
143 struct fcoe_ctlr *ctlr = fcoe_ctlr_device_priv(ctlr_dev);
144 struct bnx2fc_interface *fcoe = fcoe_ctlr_priv(ctlr);
145
146 fcf_dev->vlan_id = fcoe->vlan_id;
147}
148
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800149static void bnx2fc_clean_rx_queue(struct fc_lport *lp)
150{
151 struct fcoe_percpu_s *bg;
152 struct fcoe_rcv_info *fr;
153 struct sk_buff_head *list;
154 struct sk_buff *skb, *next;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800155
156 bg = &bnx2fc_global;
157 spin_lock_bh(&bg->fcoe_rx_list.lock);
158 list = &bg->fcoe_rx_list;
David S. Miller1173ab72018-08-07 23:43:51 -0700159 skb_queue_walk_safe(list, skb, next) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800160 fr = fcoe_dev_from_skb(skb);
161 if (fr->fr_dev == lp) {
162 __skb_unlink(skb, list);
163 kfree_skb(skb);
164 }
165 }
166 spin_unlock_bh(&bg->fcoe_rx_list.lock);
167}
168
169int bnx2fc_get_paged_crc_eof(struct sk_buff *skb, int tlen)
170{
171 int rc;
172 spin_lock(&bnx2fc_global_lock);
173 rc = fcoe_get_paged_crc_eof(skb, tlen, &bnx2fc_global);
174 spin_unlock(&bnx2fc_global_lock);
175
176 return rc;
177}
178
179static void bnx2fc_abort_io(struct fc_lport *lport)
180{
181 /*
182 * This function is no-op for bnx2fc, but we do
183 * not want to leave it as NULL either, as libfc
184 * can call the default function which is
185 * fc_fcp_abort_io.
186 */
187}
188
189static void bnx2fc_cleanup(struct fc_lport *lport)
190{
191 struct fcoe_port *port = lport_priv(lport);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700192 struct bnx2fc_interface *interface = port->priv;
193 struct bnx2fc_hba *hba = interface->hba;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800194 struct bnx2fc_rport *tgt;
195 int i;
196
197 BNX2FC_MISC_DBG("Entered %s\n", __func__);
198 mutex_lock(&hba->hba_mutex);
199 spin_lock_bh(&hba->hba_lock);
200 for (i = 0; i < BNX2FC_NUM_MAX_SESS; i++) {
201 tgt = hba->tgt_ofld_list[i];
202 if (tgt) {
203 /* Cleanup IOs belonging to requested vport */
204 if (tgt->port == port) {
205 spin_unlock_bh(&hba->hba_lock);
206 BNX2FC_TGT_DBG(tgt, "flush/cleanup\n");
207 bnx2fc_flush_active_ios(tgt);
208 spin_lock_bh(&hba->hba_lock);
209 }
210 }
211 }
212 spin_unlock_bh(&hba->hba_lock);
213 mutex_unlock(&hba->hba_mutex);
214}
215
216static int bnx2fc_xmit_l2_frame(struct bnx2fc_rport *tgt,
217 struct fc_frame *fp)
218{
219 struct fc_rport_priv *rdata = tgt->rdata;
220 struct fc_frame_header *fh;
221 int rc = 0;
222
223 fh = fc_frame_header_get(fp);
224 BNX2FC_TGT_DBG(tgt, "Xmit L2 frame rport = 0x%x, oxid = 0x%x, "
225 "r_ctl = 0x%x\n", rdata->ids.port_id,
226 ntohs(fh->fh_ox_id), fh->fh_r_ctl);
227 if ((fh->fh_type == FC_TYPE_ELS) &&
228 (fh->fh_r_ctl == FC_RCTL_ELS_REQ)) {
229
230 switch (fc_frame_payload_op(fp)) {
231 case ELS_ADISC:
232 rc = bnx2fc_send_adisc(tgt, fp);
233 break;
234 case ELS_LOGO:
235 rc = bnx2fc_send_logo(tgt, fp);
236 break;
237 case ELS_RLS:
238 rc = bnx2fc_send_rls(tgt, fp);
239 break;
240 default:
241 break;
242 }
243 } else if ((fh->fh_type == FC_TYPE_BLS) &&
244 (fh->fh_r_ctl == FC_RCTL_BA_ABTS))
245 BNX2FC_TGT_DBG(tgt, "ABTS frame\n");
246 else {
247 BNX2FC_TGT_DBG(tgt, "Send L2 frame type 0x%x "
248 "rctl 0x%x thru non-offload path\n",
249 fh->fh_type, fh->fh_r_ctl);
250 return -ENODEV;
251 }
252 if (rc)
253 return -ENOMEM;
254 else
255 return 0;
256}
257
258/**
259 * bnx2fc_xmit - bnx2fc's FCoE frame transmit function
260 *
261 * @lport: the associated local port
262 * @fp: the fc_frame to be transmitted
263 */
264static int bnx2fc_xmit(struct fc_lport *lport, struct fc_frame *fp)
265{
266 struct ethhdr *eh;
267 struct fcoe_crc_eof *cp;
268 struct sk_buff *skb;
269 struct fc_frame_header *fh;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700270 struct bnx2fc_interface *interface;
Robert Lovefd8f8902012-05-22 19:06:16 -0700271 struct fcoe_ctlr *ctlr;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700272 struct bnx2fc_hba *hba;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800273 struct fcoe_port *port;
274 struct fcoe_hdr *hp;
275 struct bnx2fc_rport *tgt;
Vasu Dev1bd49b42012-05-25 10:26:43 -0700276 struct fc_stats *stats;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800277 u8 sof, eof;
278 u32 crc;
279 unsigned int hlen, tlen, elen;
280 int wlen, rc = 0;
281
282 port = (struct fcoe_port *)lport_priv(lport);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700283 interface = port->priv;
Robert Lovefd8f8902012-05-22 19:06:16 -0700284 ctlr = bnx2fc_to_ctlr(interface);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700285 hba = interface->hba;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800286
287 fh = fc_frame_header_get(fp);
288
289 skb = fp_skb(fp);
290 if (!lport->link_up) {
291 BNX2FC_HBA_DBG(lport, "bnx2fc_xmit link down\n");
292 kfree_skb(skb);
293 return 0;
294 }
295
296 if (unlikely(fh->fh_r_ctl == FC_RCTL_ELS_REQ)) {
Robert Lovefd8f8902012-05-22 19:06:16 -0700297 if (!ctlr->sel_fcf) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800298 BNX2FC_HBA_DBG(lport, "FCF not selected yet!\n");
299 kfree_skb(skb);
300 return -EINVAL;
301 }
Robert Lovefd8f8902012-05-22 19:06:16 -0700302 if (fcoe_ctlr_els_send(ctlr, lport, skb))
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800303 return 0;
304 }
305
306 sof = fr_sof(fp);
307 eof = fr_eof(fp);
308
309 /*
310 * Snoop the frame header to check if the frame is for
311 * an offloaded session
312 */
313 /*
314 * tgt_ofld_list access is synchronized using
315 * both hba mutex and hba lock. Atleast hba mutex or
316 * hba lock needs to be held for read access.
317 */
318
319 spin_lock_bh(&hba->hba_lock);
320 tgt = bnx2fc_tgt_lookup(port, ntoh24(fh->fh_d_id));
321 if (tgt && (test_bit(BNX2FC_FLAG_SESSION_READY, &tgt->flags))) {
322 /* This frame is for offloaded session */
323 BNX2FC_HBA_DBG(lport, "xmit: Frame is for offloaded session "
324 "port_id = 0x%x\n", ntoh24(fh->fh_d_id));
325 spin_unlock_bh(&hba->hba_lock);
326 rc = bnx2fc_xmit_l2_frame(tgt, fp);
327 if (rc != -ENODEV) {
328 kfree_skb(skb);
329 return rc;
330 }
331 } else {
332 spin_unlock_bh(&hba->hba_lock);
333 }
334
335 elen = sizeof(struct ethhdr);
336 hlen = sizeof(struct fcoe_hdr);
337 tlen = sizeof(struct fcoe_crc_eof);
338 wlen = (skb->len - tlen + sizeof(crc)) / FCOE_WORD_TO_BYTE;
339
340 skb->ip_summed = CHECKSUM_NONE;
341 crc = fcoe_fc_crc(fp);
342
343 /* copy port crc and eof to the skb buff */
344 if (skb_is_nonlinear(skb)) {
345 skb_frag_t *frag;
346 if (bnx2fc_get_paged_crc_eof(skb, tlen)) {
347 kfree_skb(skb);
348 return -ENOMEM;
349 }
350 frag = &skb_shinfo(skb)->frags[skb_shinfo(skb)->nr_frags - 1];
Jonathan Lemonb54c9d52019-07-30 07:40:33 -0700351 cp = kmap_atomic(skb_frag_page(frag)) + skb_frag_off(frag);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800352 } else {
Johannes Berg4df864c2017-06-16 14:29:21 +0200353 cp = skb_put(skb, tlen);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800354 }
355
356 memset(cp, 0, sizeof(*cp));
357 cp->fcoe_eof = eof;
358 cp->fcoe_crc32 = cpu_to_le32(~crc);
359 if (skb_is_nonlinear(skb)) {
Cong Wang77dfce02011-11-25 23:14:23 +0800360 kunmap_atomic(cp);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800361 cp = NULL;
362 }
363
364 /* adjust skb network/transport offsets to match mac/fcoe/port */
365 skb_push(skb, elen + hlen);
366 skb_reset_mac_header(skb);
367 skb_reset_network_header(skb);
368 skb->mac_len = elen;
369 skb->protocol = htons(ETH_P_FCOE);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700370 skb->dev = interface->netdev;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800371
372 /* fill up mac and fcoe headers */
373 eh = eth_hdr(skb);
374 eh->h_proto = htons(ETH_P_FCOE);
Robert Lovefd8f8902012-05-22 19:06:16 -0700375 if (ctlr->map_dest)
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800376 fc_fcoe_set_mac(eh->h_dest, fh->fh_d_id);
377 else
378 /* insert GW address */
Robert Lovefd8f8902012-05-22 19:06:16 -0700379 memcpy(eh->h_dest, ctlr->dest_addr, ETH_ALEN);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800380
Robert Lovefd8f8902012-05-22 19:06:16 -0700381 if (unlikely(ctlr->flogi_oxid != FC_XID_UNKNOWN))
382 memcpy(eh->h_source, ctlr->ctl_src_addr, ETH_ALEN);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800383 else
384 memcpy(eh->h_source, port->data_src_addr, ETH_ALEN);
385
386 hp = (struct fcoe_hdr *)(eh + 1);
387 memset(hp, 0, sizeof(*hp));
388 if (FC_FCOE_VER)
389 FC_FCOE_ENCAPS_VER(hp, FC_FCOE_VER);
390 hp->fcoe_sof = sof;
391
392 /* fcoe lso, mss is in max_payload which is non-zero for FCP data */
393 if (lport->seq_offload && fr_max_payload(fp)) {
394 skb_shinfo(skb)->gso_type = SKB_GSO_FCOE;
395 skb_shinfo(skb)->gso_size = fr_max_payload(fp);
396 } else {
397 skb_shinfo(skb)->gso_type = 0;
398 skb_shinfo(skb)->gso_size = 0;
399 }
400
401 /*update tx stats */
Vasu Dev1bd49b42012-05-25 10:26:43 -0700402 stats = per_cpu_ptr(lport->stats, get_cpu());
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800403 stats->TxFrames++;
404 stats->TxWords += wlen;
405 put_cpu();
406
407 /* send down to lld */
408 fr_dev(fp) = lport;
409 if (port->fcoe_pending_queue.qlen)
410 fcoe_check_wait_queue(lport, skb);
411 else if (fcoe_start_io(skb))
412 fcoe_check_wait_queue(lport, skb);
413
414 return 0;
415}
416
417/**
418 * bnx2fc_rcv - This is bnx2fc's receive function called by NET_RX_SOFTIRQ
419 *
420 * @skb: the receive socket buffer
421 * @dev: associated net device
422 * @ptype: context
423 * @olddev: last device
424 *
425 * This function receives the packet and builds FC frame and passes it up
426 */
427static int bnx2fc_rcv(struct sk_buff *skb, struct net_device *dev,
428 struct packet_type *ptype, struct net_device *olddev)
429{
430 struct fc_lport *lport;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700431 struct bnx2fc_interface *interface;
Robert Lovefd8f8902012-05-22 19:06:16 -0700432 struct fcoe_ctlr *ctlr;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800433 struct fcoe_rcv_info *fr;
434 struct fcoe_percpu_s *bg;
Maurizio Lombardi01a4cc42014-11-20 11:17:33 +0100435 struct sk_buff *tmp_skb;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800436
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700437 interface = container_of(ptype, struct bnx2fc_interface,
438 fcoe_packet_type);
Robert Lovefd8f8902012-05-22 19:06:16 -0700439 ctlr = bnx2fc_to_ctlr(interface);
440 lport = ctlr->lp;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800441
442 if (unlikely(lport == NULL)) {
Bhanu Prakash Gollapudib2a554f2011-06-27 23:30:53 -0700443 printk(KERN_ERR PFX "bnx2fc_rcv: lport is NULL\n");
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800444 goto err;
445 }
446
Maurizio Lombardi01a4cc42014-11-20 11:17:33 +0100447 tmp_skb = skb_share_check(skb, GFP_ATOMIC);
448 if (!tmp_skb)
449 goto err;
450
451 skb = tmp_skb;
452
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800453 if (unlikely(eth_hdr(skb)->h_proto != htons(ETH_P_FCOE))) {
Bhanu Prakash Gollapudib2a554f2011-06-27 23:30:53 -0700454 printk(KERN_ERR PFX "bnx2fc_rcv: Wrong FC type frame\n");
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800455 goto err;
456 }
457
458 /*
459 * Check for minimum frame length, and make sure required FCoE
460 * and FC headers are pulled into the linear data area.
461 */
462 if (unlikely((skb->len < FCOE_MIN_FRAME) ||
463 !pskb_may_pull(skb, FCOE_HEADER_LEN)))
464 goto err;
465
466 skb_set_transport_header(skb, sizeof(struct fcoe_hdr));
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800467
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800468 fr = fcoe_dev_from_skb(skb);
469 fr->fr_dev = lport;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800470
471 bg = &bnx2fc_global;
Neil Hormanfc05ab72012-03-09 14:50:13 -0800472 spin_lock(&bg->fcoe_rx_list.lock);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800473
474 __skb_queue_tail(&bg->fcoe_rx_list, skb);
475 if (bg->fcoe_rx_list.qlen == 1)
Sebastian Andrzej Siewior4b9bc862016-04-12 17:16:54 +0200476 wake_up_process(bg->kthread);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800477
Neil Hormanfc05ab72012-03-09 14:50:13 -0800478 spin_unlock(&bg->fcoe_rx_list.lock);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800479
480 return 0;
481err:
482 kfree_skb(skb);
483 return -1;
484}
485
486static int bnx2fc_l2_rcv_thread(void *arg)
487{
488 struct fcoe_percpu_s *bg = arg;
489 struct sk_buff *skb;
490
Dongsheng Yang8698a742014-03-11 18:09:12 +0800491 set_user_nice(current, MIN_NICE);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800492 set_current_state(TASK_INTERRUPTIBLE);
493 while (!kthread_should_stop()) {
494 schedule();
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800495 spin_lock_bh(&bg->fcoe_rx_list.lock);
496 while ((skb = __skb_dequeue(&bg->fcoe_rx_list)) != NULL) {
497 spin_unlock_bh(&bg->fcoe_rx_list.lock);
498 bnx2fc_recv_frame(skb);
499 spin_lock_bh(&bg->fcoe_rx_list.lock);
500 }
Bhanu Gollapudifee78712011-03-21 18:51:13 -0700501 __set_current_state(TASK_INTERRUPTIBLE);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800502 spin_unlock_bh(&bg->fcoe_rx_list.lock);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800503 }
Bhanu Gollapudifee78712011-03-21 18:51:13 -0700504 __set_current_state(TASK_RUNNING);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800505 return 0;
506}
507
508
509static void bnx2fc_recv_frame(struct sk_buff *skb)
510{
511 u32 fr_len;
512 struct fc_lport *lport;
513 struct fcoe_rcv_info *fr;
Vasu Dev1bd49b42012-05-25 10:26:43 -0700514 struct fc_stats *stats;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800515 struct fc_frame_header *fh;
516 struct fcoe_crc_eof crc_eof;
517 struct fc_frame *fp;
518 struct fc_lport *vn_port;
Chad Dupuis56ffd3a2017-06-26 08:59:32 -0700519 struct fcoe_port *port, *phys_port;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800520 u8 *mac = NULL;
521 u8 *dest_mac = NULL;
522 struct fcoe_hdr *hp;
Chad Dupuis56ffd3a2017-06-26 08:59:32 -0700523 struct bnx2fc_interface *interface;
524 struct fcoe_ctlr *ctlr;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800525
526 fr = fcoe_dev_from_skb(skb);
527 lport = fr->fr_dev;
528 if (unlikely(lport == NULL)) {
Bhanu Prakash Gollapudib2a554f2011-06-27 23:30:53 -0700529 printk(KERN_ERR PFX "Invalid lport struct\n");
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800530 kfree_skb(skb);
531 return;
532 }
533
534 if (skb_is_nonlinear(skb))
535 skb_linearize(skb);
536 mac = eth_hdr(skb)->h_source;
537 dest_mac = eth_hdr(skb)->h_dest;
538
539 /* Pull the header */
540 hp = (struct fcoe_hdr *) skb_network_header(skb);
541 fh = (struct fc_frame_header *) skb_transport_header(skb);
542 skb_pull(skb, sizeof(struct fcoe_hdr));
543 fr_len = skb->len - sizeof(struct fcoe_crc_eof);
544
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800545 fp = (struct fc_frame *)skb;
546 fc_frame_init(fp);
547 fr_dev(fp) = lport;
548 fr_sof(fp) = hp->fcoe_sof;
549 if (skb_copy_bits(skb, fr_len, &crc_eof, sizeof(crc_eof))) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800550 kfree_skb(skb);
551 return;
552 }
553 fr_eof(fp) = crc_eof.fcoe_eof;
554 fr_crc(fp) = crc_eof.fcoe_crc32;
555 if (pskb_trim(skb, fr_len)) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800556 kfree_skb(skb);
557 return;
558 }
559
Chad Dupuis56ffd3a2017-06-26 08:59:32 -0700560 phys_port = lport_priv(lport);
561 interface = phys_port->priv;
562 ctlr = bnx2fc_to_ctlr(interface);
563
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800564 fh = fc_frame_header_get(fp);
565
Chad Dupuis56ffd3a2017-06-26 08:59:32 -0700566 if (ntoh24(&dest_mac[3]) != ntoh24(fh->fh_d_id)) {
567 BNX2FC_HBA_DBG(lport, "FC frame d_id mismatch with MAC %pM.\n",
568 dest_mac);
569 kfree_skb(skb);
570 return;
571 }
572
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800573 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 }
Chad Dupuis56ffd3a2017-06-26 08:59:32 -0700582 if (ctlr->state) {
583 if (!ether_addr_equal(mac, ctlr->dest_addr)) {
584 BNX2FC_HBA_DBG(lport, "Wrong source address: mac:%pM dest_addr:%pM.\n",
585 mac, ctlr->dest_addr);
586 kfree_skb(skb);
587 return;
588 }
589 }
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800590 if (fh->fh_r_ctl == FC_RCTL_DD_SOL_DATA &&
591 fh->fh_type == FC_TYPE_FCP) {
592 /* Drop FCP data. We dont this in L2 path */
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800593 kfree_skb(skb);
594 return;
595 }
596 if (fh->fh_r_ctl == FC_RCTL_ELS_REQ &&
597 fh->fh_type == FC_TYPE_ELS) {
598 switch (fc_frame_payload_op(fp)) {
599 case ELS_LOGO:
600 if (ntoh24(fh->fh_s_id) == FC_FID_FLOGI) {
601 /* drop non-FIP LOGO */
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800602 kfree_skb(skb);
603 return;
604 }
605 break;
606 }
607 }
Bhanu Prakash Gollapudi3f8744d2011-08-04 17:38:48 -0700608
609 if (fh->fh_r_ctl == FC_RCTL_BA_ABTS) {
610 /* Drop incoming ABTS */
Bhanu Prakash Gollapudi3f8744d2011-08-04 17:38:48 -0700611 kfree_skb(skb);
612 return;
613 }
614
Chad Dupuis56ffd3a2017-06-26 08:59:32 -0700615 /*
616 * If the destination ID from the frame header does not match what we
617 * have on record for lport and the search for a NPIV port came up
618 * empty then this is not addressed to our port so simply drop it.
619 */
620 if (lport->port_id != ntoh24(fh->fh_d_id) && !vn_port) {
621 BNX2FC_HBA_DBG(lport, "Dropping frame due to destination mismatch: lport->port_id=%x fh->d_id=%x.\n",
622 lport->port_id, ntoh24(fh->fh_d_id));
623 kfree_skb(skb);
624 return;
625 }
626
Neil Hormand576a5e2014-06-23 10:41:02 -0400627 stats = per_cpu_ptr(lport->stats, smp_processor_id());
628 stats->RxFrames++;
629 stats->RxWords += fr_len / FCOE_WORD_TO_BYTE;
630
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800631 if (le32_to_cpu(fr_crc(fp)) !=
632 ~crc32(~0, skb->data, fr_len)) {
633 if (stats->InvalidCRCCount < 5)
634 printk(KERN_WARNING PFX "dropping frame with "
635 "CRC error\n");
636 stats->InvalidCRCCount++;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800637 kfree_skb(skb);
638 return;
639 }
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800640 fc_exch_recv(lport, fp);
641}
642
643/**
644 * bnx2fc_percpu_io_thread - thread per cpu for ios
645 *
646 * @arg: ptr to bnx2fc_percpu_info structure
647 */
Baoyou Xie3f7d67d2016-09-04 14:52:21 +0800648static int bnx2fc_percpu_io_thread(void *arg)
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800649{
650 struct bnx2fc_percpu_s *p = arg;
651 struct bnx2fc_work *work, *tmp;
652 LIST_HEAD(work_list);
653
Dongsheng Yang8698a742014-03-11 18:09:12 +0800654 set_user_nice(current, MIN_NICE);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800655 set_current_state(TASK_INTERRUPTIBLE);
656 while (!kthread_should_stop()) {
657 schedule();
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800658 spin_lock_bh(&p->fp_work_lock);
659 while (!list_empty(&p->work_list)) {
660 list_splice_init(&p->work_list, &work_list);
661 spin_unlock_bh(&p->fp_work_lock);
662
663 list_for_each_entry_safe(work, tmp, &work_list, list) {
664 list_del_init(&work->list);
Javed Hasan77331112020-03-26 22:48:47 -0700665 bnx2fc_process_cq_compl(work->tgt, work->wqe,
666 work->rq_data,
667 work->num_rq,
668 work->task);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800669 kfree(work);
670 }
671
672 spin_lock_bh(&p->fp_work_lock);
673 }
Bhanu Gollapudifee78712011-03-21 18:51:13 -0700674 __set_current_state(TASK_INTERRUPTIBLE);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800675 spin_unlock_bh(&p->fp_work_lock);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800676 }
Bhanu Gollapudifee78712011-03-21 18:51:13 -0700677 __set_current_state(TASK_RUNNING);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800678
679 return 0;
680}
681
682static struct fc_host_statistics *bnx2fc_get_host_stats(struct Scsi_Host *shost)
683{
684 struct fc_host_statistics *bnx2fc_stats;
685 struct fc_lport *lport = shost_priv(shost);
686 struct fcoe_port *port = lport_priv(lport);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700687 struct bnx2fc_interface *interface = port->priv;
688 struct bnx2fc_hba *hba = interface->hba;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800689 struct fcoe_statistics_params *fw_stats;
690 int rc = 0;
691
692 fw_stats = (struct fcoe_statistics_params *)hba->stats_buffer;
693 if (!fw_stats)
694 return NULL;
695
Maurizio Lombardic2dd8932017-05-24 14:09:44 +0200696 mutex_lock(&hba->hba_stats_mutex);
697
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800698 bnx2fc_stats = fc_get_host_stats(shost);
699
700 init_completion(&hba->stat_req_done);
701 if (bnx2fc_send_stat_req(hba))
Maurizio Lombardic2dd8932017-05-24 14:09:44 +0200702 goto unlock_stats_mutex;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800703 rc = wait_for_completion_timeout(&hba->stat_req_done, (2 * HZ));
704 if (!rc) {
705 BNX2FC_HBA_DBG(lport, "FW stat req timed out\n");
Maurizio Lombardic2dd8932017-05-24 14:09:44 +0200706 goto unlock_stats_mutex;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800707 }
Bhanu Prakash Gollapudif246fe22012-12-21 19:40:32 -0800708 BNX2FC_STATS(hba, rx_stat2, fc_crc_cnt);
709 bnx2fc_stats->invalid_crc_count += hba->bfw_stats.fc_crc_cnt;
710 BNX2FC_STATS(hba, tx_stat, fcoe_tx_pkt_cnt);
711 bnx2fc_stats->tx_frames += hba->bfw_stats.fcoe_tx_pkt_cnt;
712 BNX2FC_STATS(hba, tx_stat, fcoe_tx_byte_cnt);
713 bnx2fc_stats->tx_words += ((hba->bfw_stats.fcoe_tx_byte_cnt) / 4);
714 BNX2FC_STATS(hba, rx_stat0, fcoe_rx_pkt_cnt);
715 bnx2fc_stats->rx_frames += hba->bfw_stats.fcoe_rx_pkt_cnt;
716 BNX2FC_STATS(hba, rx_stat0, fcoe_rx_byte_cnt);
717 bnx2fc_stats->rx_words += ((hba->bfw_stats.fcoe_rx_byte_cnt) / 4);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800718
719 bnx2fc_stats->dumped_frames = 0;
720 bnx2fc_stats->lip_count = 0;
721 bnx2fc_stats->nos_count = 0;
722 bnx2fc_stats->loss_of_sync_count = 0;
723 bnx2fc_stats->loss_of_signal_count = 0;
724 bnx2fc_stats->prim_seq_protocol_err_count = 0;
725
Bhanu Prakash Gollapudif246fe22012-12-21 19:40:32 -0800726 memcpy(&hba->prev_stats, hba->stats_buffer,
727 sizeof(struct fcoe_statistics_params));
Maurizio Lombardic2dd8932017-05-24 14:09:44 +0200728
729unlock_stats_mutex:
730 mutex_unlock(&hba->hba_stats_mutex);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800731 return bnx2fc_stats;
732}
733
734static int bnx2fc_shost_config(struct fc_lport *lport, struct device *dev)
735{
736 struct fcoe_port *port = lport_priv(lport);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700737 struct bnx2fc_interface *interface = port->priv;
Bhanu Prakash Gollapudic13d2b62013-03-08 13:28:51 -0800738 struct bnx2fc_hba *hba = interface->hba;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800739 struct Scsi_Host *shost = lport->host;
740 int rc = 0;
741
742 shost->max_cmd_len = BNX2FC_MAX_CMD_LEN;
Joe Carnuccio10755d32016-04-07 09:07:56 -0400743 shost->max_lun = bnx2fc_max_luns;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800744 shost->max_id = BNX2FC_MAX_FCP_TGT;
745 shost->max_channel = 0;
746 if (lport->vport)
747 shost->transportt = bnx2fc_vport_xport_template;
748 else
749 shost->transportt = bnx2fc_transport_template;
750
751 /* Add the new host to SCSI-ml */
752 rc = scsi_add_host(lport->host, dev);
753 if (rc) {
754 printk(KERN_ERR PFX "Error on scsi_add_host\n");
755 return rc;
756 }
757 if (!lport->vport)
758 fc_host_max_npiv_vports(lport->host) = USHRT_MAX;
Bhanu Prakash Gollapudic13d2b62013-03-08 13:28:51 -0800759 snprintf(fc_host_symbolic_name(lport->host), 256,
Saurav Kashyap17d87c42014-07-03 08:18:28 -0400760 "%s (QLogic %s) v%s over %s",
Bhanu Prakash Gollapudic13d2b62013-03-08 13:28:51 -0800761 BNX2FC_NAME, hba->chip_num, BNX2FC_VERSION,
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700762 interface->netdev->name);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800763
764 return 0;
765}
766
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800767static int bnx2fc_link_ok(struct fc_lport *lport)
768{
769 struct fcoe_port *port = lport_priv(lport);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700770 struct bnx2fc_interface *interface = port->priv;
771 struct bnx2fc_hba *hba = interface->hba;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800772 struct net_device *dev = hba->phys_dev;
773 int rc = 0;
774
775 if ((dev->flags & IFF_UP) && netif_carrier_ok(dev))
776 clear_bit(ADAPTER_STATE_LINK_DOWN, &hba->adapter_state);
777 else {
778 set_bit(ADAPTER_STATE_LINK_DOWN, &hba->adapter_state);
779 rc = -1;
780 }
781 return rc;
782}
783
784/**
785 * bnx2fc_get_link_state - get network link state
786 *
787 * @hba: adapter instance pointer
788 *
789 * updates adapter structure flag based on netdev state
790 */
791void bnx2fc_get_link_state(struct bnx2fc_hba *hba)
792{
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700793 if (test_bit(__LINK_STATE_NOCARRIER, &hba->phys_dev->state))
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800794 set_bit(ADAPTER_STATE_LINK_DOWN, &hba->adapter_state);
795 else
796 clear_bit(ADAPTER_STATE_LINK_DOWN, &hba->adapter_state);
797}
798
Bhanu Prakash Gollapudi52439602011-08-04 17:38:50 -0700799static int bnx2fc_net_config(struct fc_lport *lport, struct net_device *netdev)
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800800{
801 struct bnx2fc_hba *hba;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700802 struct bnx2fc_interface *interface;
Robert Lovefd8f8902012-05-22 19:06:16 -0700803 struct fcoe_ctlr *ctlr;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800804 struct fcoe_port *port;
805 u64 wwnn, wwpn;
806
807 port = lport_priv(lport);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700808 interface = port->priv;
Robert Lovefd8f8902012-05-22 19:06:16 -0700809 ctlr = bnx2fc_to_ctlr(interface);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700810 hba = interface->hba;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800811
812 /* require support for get_pauseparam ethtool op. */
813 if (!hba->phys_dev->ethtool_ops ||
814 !hba->phys_dev->ethtool_ops->get_pauseparam)
815 return -EOPNOTSUPP;
816
Bhanu Gollapudi1294bfe2011-03-17 17:13:34 -0700817 if (fc_set_mfs(lport, BNX2FC_MFS))
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800818 return -EINVAL;
819
820 skb_queue_head_init(&port->fcoe_pending_queue);
821 port->fcoe_pending_queue_active = 0;
Kees Cook13059102017-09-21 13:12:15 -0700822 timer_setup(&port->timer, fcoe_queue_timer, 0);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800823
Yi Zou0e0f9cd2012-12-06 06:24:44 +0000824 fcoe_link_speed_update(lport);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800825
826 if (!lport->vport) {
Bhanu Prakash Gollapudi52439602011-08-04 17:38:50 -0700827 if (fcoe_get_wwn(netdev, &wwnn, NETDEV_FCOE_WWNN))
Robert Lovefd8f8902012-05-22 19:06:16 -0700828 wwnn = fcoe_wwn_from_mac(ctlr->ctl_src_addr,
Bhanu Prakash Gollapudi52439602011-08-04 17:38:50 -0700829 1, 0);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800830 BNX2FC_HBA_DBG(lport, "WWNN = 0x%llx\n", wwnn);
831 fc_set_wwnn(lport, wwnn);
832
Bhanu Prakash Gollapudi52439602011-08-04 17:38:50 -0700833 if (fcoe_get_wwn(netdev, &wwpn, NETDEV_FCOE_WWPN))
Robert Lovefd8f8902012-05-22 19:06:16 -0700834 wwpn = fcoe_wwn_from_mac(ctlr->ctl_src_addr,
Bhanu Prakash Gollapudi52439602011-08-04 17:38:50 -0700835 2, 0);
836
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800837 BNX2FC_HBA_DBG(lport, "WWPN = 0x%llx\n", wwpn);
838 fc_set_wwpn(lport, wwpn);
839 }
840
841 return 0;
842}
843
Kees Cook13059102017-09-21 13:12:15 -0700844static void bnx2fc_destroy_timer(struct timer_list *t)
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800845{
Kees Cook13059102017-09-21 13:12:15 -0700846 struct bnx2fc_hba *hba = from_timer(hba, t, destroy_timer);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800847
Bhanu Prakash Gollapudicd703ae2011-08-04 17:38:43 -0700848 printk(KERN_ERR PFX "ERROR:bnx2fc_destroy_timer - "
849 "Destroy compl not received!!\n");
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700850 set_bit(BNX2FC_FLAG_DESTROY_CMPL, &hba->flags);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800851 wake_up_interruptible(&hba->destroy_wait);
852}
853
854/**
855 * bnx2fc_indicate_netevent - Generic netdev event handler
856 *
857 * @context: adapter structure pointer
858 * @event: event type
Michael Chan415199f2011-07-20 14:55:24 +0000859 * @vlan_id: vlan id - associated vlan id with this event
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800860 *
861 * Handles NETDEV_UP, NETDEV_DOWN, NETDEV_GOING_DOWN,NETDEV_CHANGE and
Bhanu Prakash Gollapudiabc49a92011-08-04 17:38:42 -0700862 * NETDEV_CHANGE_MTU events. Handle NETDEV_UNREGISTER only for vlans.
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800863 */
Michael Chan415199f2011-07-20 14:55:24 +0000864static void bnx2fc_indicate_netevent(void *context, unsigned long event,
865 u16 vlan_id)
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800866{
867 struct bnx2fc_hba *hba = (struct bnx2fc_hba *)context;
Robert Love6e89ea32012-11-27 06:53:40 +0000868 struct fcoe_ctlr_device *cdev;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700869 struct fc_lport *lport;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800870 struct fc_lport *vport;
Bhanu Prakash Gollapudiabc49a92011-08-04 17:38:42 -0700871 struct bnx2fc_interface *interface, *tmp;
Robert Lovefd8f8902012-05-22 19:06:16 -0700872 struct fcoe_ctlr *ctlr;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700873 int wait_for_upload = 0;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800874 u32 link_possible = 1;
875
Bhanu Prakash Gollapudiabc49a92011-08-04 17:38:42 -0700876 if (vlan_id != 0 && event != NETDEV_UNREGISTER)
Michael Chan415199f2011-07-20 14:55:24 +0000877 return;
878
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800879 switch (event) {
880 case NETDEV_UP:
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800881 if (!test_bit(ADAPTER_STATE_UP, &hba->adapter_state))
882 printk(KERN_ERR "indicate_netevent: "\
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700883 "hba is not UP!!\n");
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800884 break;
885
886 case NETDEV_DOWN:
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800887 clear_bit(ADAPTER_STATE_GOING_DOWN, &hba->adapter_state);
888 clear_bit(ADAPTER_STATE_UP, &hba->adapter_state);
889 link_possible = 0;
890 break;
891
892 case NETDEV_GOING_DOWN:
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800893 set_bit(ADAPTER_STATE_GOING_DOWN, &hba->adapter_state);
894 link_possible = 0;
895 break;
896
897 case NETDEV_CHANGE:
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800898 break;
899
Bhanu Prakash Gollapudiabc49a92011-08-04 17:38:42 -0700900 case NETDEV_UNREGISTER:
901 if (!vlan_id)
902 return;
903 mutex_lock(&bnx2fc_dev_lock);
904 list_for_each_entry_safe(interface, tmp, &if_list, list) {
Nithin Nayak Sujir26b29822011-08-30 15:54:50 -0700905 if (interface->hba == hba &&
906 interface->vlan_id == (vlan_id & VLAN_VID_MASK))
907 __bnx2fc_destroy(interface);
Bhanu Prakash Gollapudiabc49a92011-08-04 17:38:42 -0700908 }
909 mutex_unlock(&bnx2fc_dev_lock);
910 return;
911
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800912 default:
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800913 return;
914 }
915
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700916 mutex_lock(&bnx2fc_dev_lock);
917 list_for_each_entry(interface, &if_list, list) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800918
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700919 if (interface->hba != hba)
920 continue;
921
Robert Lovefd8f8902012-05-22 19:06:16 -0700922 ctlr = bnx2fc_to_ctlr(interface);
923 lport = ctlr->lp;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700924 BNX2FC_HBA_DBG(lport, "netevent handler - event=%s %ld\n",
925 interface->netdev->name, event);
926
Yi Zou0e0f9cd2012-12-06 06:24:44 +0000927 fcoe_link_speed_update(lport);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700928
Robert Love6e89ea32012-11-27 06:53:40 +0000929 cdev = fcoe_ctlr_to_ctlr_dev(ctlr);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700930
931 if (link_possible && !bnx2fc_link_ok(lport)) {
Robert Love6e89ea32012-11-27 06:53:40 +0000932 switch (cdev->enabled) {
933 case FCOE_CTLR_DISABLED:
934 pr_info("Link up while interface is disabled.\n");
935 break;
936 case FCOE_CTLR_ENABLED:
937 case FCOE_CTLR_UNUSED:
938 /* Reset max recv frame size to default */
939 fc_set_mfs(lport, BNX2FC_MFS);
940 /*
941 * ctlr link up will only be handled during
942 * enable to avoid sending discovery
943 * solicitation on a stale vlan
944 */
945 if (interface->enabled)
946 fcoe_ctlr_link_up(ctlr);
Jason Yanacfcb722020-04-21 11:40:19 +0800947 }
Robert Lovefd8f8902012-05-22 19:06:16 -0700948 } else if (fcoe_ctlr_link_down(ctlr)) {
Robert Love6e89ea32012-11-27 06:53:40 +0000949 switch (cdev->enabled) {
950 case FCOE_CTLR_DISABLED:
951 pr_info("Link down while interface is disabled.\n");
952 break;
953 case FCOE_CTLR_ENABLED:
954 case FCOE_CTLR_UNUSED:
955 mutex_lock(&lport->lp_mutex);
956 list_for_each_entry(vport, &lport->vports, list)
957 fc_host_port_type(vport->host) =
958 FC_PORTTYPE_UNKNOWN;
959 mutex_unlock(&lport->lp_mutex);
960 fc_host_port_type(lport->host) =
961 FC_PORTTYPE_UNKNOWN;
962 per_cpu_ptr(lport->stats,
963 get_cpu())->LinkFailureCount++;
964 put_cpu();
965 fcoe_clean_pending_queue(lport);
966 wait_for_upload = 1;
Jason Yanacfcb722020-04-21 11:40:19 +0800967 }
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800968 }
969 }
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700970 mutex_unlock(&bnx2fc_dev_lock);
971
972 if (wait_for_upload) {
973 clear_bit(ADAPTER_STATE_READY, &hba->adapter_state);
974 init_waitqueue_head(&hba->shutdown_wait);
975 BNX2FC_MISC_DBG("indicate_netevent "
976 "num_ofld_sess = %d\n",
977 hba->num_ofld_sess);
978 hba->wait_for_link_down = 1;
979 wait_event_interruptible(hba->shutdown_wait,
980 (hba->num_ofld_sess == 0));
981 BNX2FC_MISC_DBG("wakeup - num_ofld_sess = %d\n",
982 hba->num_ofld_sess);
983 hba->wait_for_link_down = 0;
984
985 if (signal_pending(current))
986 flush_signals(current);
987 }
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800988}
989
990static int bnx2fc_libfc_config(struct fc_lport *lport)
991{
992
993 /* Set the function pointers set by bnx2fc driver */
994 memcpy(&lport->tt, &bnx2fc_libfc_fcn_templ,
995 sizeof(struct libfc_function_template));
996 fc_elsct_init(lport);
997 fc_exch_init(lport);
Robert Love08076192013-03-25 11:00:28 -0700998 fc_disc_init(lport);
999 fc_disc_config(lport, lport);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001000 return 0;
1001}
1002
Bhanu Prakash Gollapudi0eb43b42013-04-22 19:22:30 +00001003static int bnx2fc_em_config(struct fc_lport *lport, struct bnx2fc_hba *hba)
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001004{
Bhanu Prakash Gollapudi0eb43b42013-04-22 19:22:30 +00001005 int fcoe_min_xid, fcoe_max_xid;
Bhanu Prakash Gollapudi7d742f62012-01-23 18:00:48 -08001006
Bhanu Prakash Gollapudi0eb43b42013-04-22 19:22:30 +00001007 fcoe_min_xid = hba->max_xid + 1;
Bhanu Prakash Gollapudi7d742f62012-01-23 18:00:48 -08001008 if (nr_cpu_ids <= 2)
Bhanu Prakash Gollapudi0eb43b42013-04-22 19:22:30 +00001009 fcoe_max_xid = hba->max_xid + FCOE_XIDS_PER_CPU_OFFSET;
Bhanu Prakash Gollapudi7d742f62012-01-23 18:00:48 -08001010 else
Bhanu Prakash Gollapudi0eb43b42013-04-22 19:22:30 +00001011 fcoe_max_xid = hba->max_xid + FCOE_MAX_XID_OFFSET;
1012 if (!fc_exch_mgr_alloc(lport, FC_CLASS_3, fcoe_min_xid,
1013 fcoe_max_xid, NULL)) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001014 printk(KERN_ERR PFX "em_config:fc_exch_mgr_alloc failed\n");
1015 return -ENOMEM;
1016 }
1017
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001018 return 0;
1019}
1020
1021static int bnx2fc_lport_config(struct fc_lport *lport)
1022{
1023 lport->link_up = 0;
1024 lport->qfull = 0;
Bhanu Prakash Gollapudi44c570b2012-01-23 18:00:47 -08001025 lport->max_retry_count = BNX2FC_MAX_RETRY_CNT;
1026 lport->max_rport_retry_count = BNX2FC_MAX_RPORT_RETRY_CNT;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001027 lport->e_d_tov = 2 * 1000;
1028 lport->r_a_tov = 10 * 1000;
1029
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001030 lport->service_params = (FCP_SPPF_INIT_FCN | FCP_SPPF_RD_XRDY_DIS |
1031 FCP_SPPF_RETRY | FCP_SPPF_CONF_COMPL);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001032 lport->does_npiv = 1;
1033
1034 memset(&lport->rnid_gen, 0, sizeof(struct fc_els_rnid_gen));
1035 lport->rnid_gen.rnid_atype = BNX2FC_RNID_HBA;
1036
1037 /* alloc stats structure */
1038 if (fc_lport_init_stats(lport))
1039 return -ENOMEM;
1040
1041 /* Finish fc_lport configuration */
1042 fc_lport_config(lport);
1043
1044 return 0;
1045}
1046
1047/**
1048 * bnx2fc_fip_recv - handle a received FIP frame.
1049 *
1050 * @skb: the received skb
1051 * @dev: associated &net_device
1052 * @ptype: the &packet_type structure which was used to register this handler.
1053 * @orig_dev: original receive &net_device, in case @ dev is a bond.
1054 *
1055 * Returns: 0 for success
1056 */
1057static int bnx2fc_fip_recv(struct sk_buff *skb, struct net_device *dev,
1058 struct packet_type *ptype,
1059 struct net_device *orig_dev)
1060{
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001061 struct bnx2fc_interface *interface;
Robert Lovefd8f8902012-05-22 19:06:16 -07001062 struct fcoe_ctlr *ctlr;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001063 interface = container_of(ptype, struct bnx2fc_interface,
1064 fip_packet_type);
Robert Lovefd8f8902012-05-22 19:06:16 -07001065 ctlr = bnx2fc_to_ctlr(interface);
1066 fcoe_ctlr_recv(ctlr, skb);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001067 return 0;
1068}
1069
1070/**
1071 * bnx2fc_update_src_mac - Update Ethernet MAC filters.
1072 *
Lee Jonesca63d8e2020-07-13 08:46:23 +01001073 * @lport: The local port
1074 * @addr: Location of data to copy
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001075 *
1076 * Remove any previously-set unicast MAC filter.
1077 * Add secondary FCoE MAC address filter for our OUI.
1078 */
1079static void bnx2fc_update_src_mac(struct fc_lport *lport, u8 *addr)
1080{
1081 struct fcoe_port *port = lport_priv(lport);
1082
1083 memcpy(port->data_src_addr, addr, ETH_ALEN);
1084}
1085
1086/**
1087 * bnx2fc_get_src_mac - return the ethernet source address for an lport
1088 *
1089 * @lport: libfc port
1090 */
1091static u8 *bnx2fc_get_src_mac(struct fc_lport *lport)
1092{
1093 struct fcoe_port *port;
1094
1095 port = (struct fcoe_port *)lport_priv(lport);
1096 return port->data_src_addr;
1097}
1098
1099/**
1100 * bnx2fc_fip_send - send an Ethernet-encapsulated FIP frame.
1101 *
1102 * @fip: FCoE controller.
1103 * @skb: FIP Packet.
1104 */
1105static void bnx2fc_fip_send(struct fcoe_ctlr *fip, struct sk_buff *skb)
1106{
Chad Dupuis3f12f762016-04-07 09:07:57 -04001107 struct fip_header *fiph;
1108 struct ethhdr *eth_hdr;
1109 u16 op;
1110 u8 sub;
1111
1112 fiph = (struct fip_header *) ((void *)skb->data + 2 * ETH_ALEN + 2);
1113 eth_hdr = (struct ethhdr *)skb_mac_header(skb);
1114 op = ntohs(fiph->fip_op);
1115 sub = fiph->fip_subcode;
1116
1117 if (op == FIP_OP_CTRL && sub == FIP_SC_SOL && bnx2fc_log_fka)
1118 BNX2FC_MISC_DBG("Sending FKA from %pM to %pM.\n",
1119 eth_hdr->h_source, eth_hdr->h_dest);
1120
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001121 skb->dev = bnx2fc_from_ctlr(fip)->netdev;
1122 dev_queue_xmit(skb);
1123}
1124
1125static int bnx2fc_vport_create(struct fc_vport *vport, bool disabled)
1126{
1127 struct Scsi_Host *shost = vport_to_shost(vport);
1128 struct fc_lport *n_port = shost_priv(shost);
1129 struct fcoe_port *port = lport_priv(n_port);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001130 struct bnx2fc_interface *interface = port->priv;
1131 struct net_device *netdev = interface->netdev;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001132 struct fc_lport *vn_port;
Bhanu Prakash Gollapudi861efc52011-08-04 17:38:51 -07001133 int rc;
1134 char buf[32];
1135
1136 rc = fcoe_validate_vport_create(vport);
1137 if (rc) {
1138 fcoe_wwn_to_str(vport->port_name, buf, sizeof(buf));
1139 printk(KERN_ERR PFX "Failed to create vport, "
1140 "WWPN (0x%s) already exists\n",
1141 buf);
1142 return rc;
1143 }
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001144
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001145 if (!test_bit(BNX2FC_FLAG_FW_INIT_DONE, &interface->hba->flags)) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001146 printk(KERN_ERR PFX "vn ports cannot be created on"
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001147 "this interface\n");
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001148 return -EIO;
1149 }
Jiri Pirko4bc71cb2011-09-03 03:34:30 +00001150 rtnl_lock();
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001151 mutex_lock(&bnx2fc_dev_lock);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001152 vn_port = bnx2fc_if_create(interface, &vport->dev, 1);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001153 mutex_unlock(&bnx2fc_dev_lock);
Jiri Pirko4bc71cb2011-09-03 03:34:30 +00001154 rtnl_unlock();
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001155
Dan Carpenterb6829c72014-11-04 13:37:17 +03001156 if (!vn_port) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001157 printk(KERN_ERR PFX "bnx2fc_vport_create (%s) failed\n",
1158 netdev->name);
1159 return -EIO;
1160 }
1161
Joe Carnuccio10755d32016-04-07 09:07:56 -04001162 if (bnx2fc_devloss_tmo)
1163 fc_host_dev_loss_tmo(vn_port->host) = bnx2fc_devloss_tmo;
1164
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001165 if (disabled) {
1166 fc_vport_set_state(vport, FC_VPORT_DISABLED);
1167 } else {
1168 vn_port->boot_time = jiffies;
1169 fc_lport_init(vn_port);
1170 fc_fabric_login(vn_port);
1171 fc_vport_setlink(vn_port);
1172 }
1173 return 0;
1174}
1175
Bhanu Prakash Gollapudiabc49a92011-08-04 17:38:42 -07001176static void bnx2fc_free_vport(struct bnx2fc_hba *hba, struct fc_lport *lport)
1177{
1178 struct bnx2fc_lport *blport, *tmp;
1179
1180 spin_lock_bh(&hba->hba_lock);
1181 list_for_each_entry_safe(blport, tmp, &hba->vports, list) {
1182 if (blport->lport == lport) {
1183 list_del(&blport->list);
1184 kfree(blport);
1185 }
1186 }
1187 spin_unlock_bh(&hba->hba_lock);
1188}
1189
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001190static int bnx2fc_vport_destroy(struct fc_vport *vport)
1191{
1192 struct Scsi_Host *shost = vport_to_shost(vport);
1193 struct fc_lport *n_port = shost_priv(shost);
1194 struct fc_lport *vn_port = vport->dd_data;
1195 struct fcoe_port *port = lport_priv(vn_port);
Bhanu Prakash Gollapudiabc49a92011-08-04 17:38:42 -07001196 struct bnx2fc_interface *interface = port->priv;
Bhanu Prakash Gollapudicdf54662011-08-04 17:38:39 -07001197 struct fc_lport *v_port;
1198 bool found = false;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001199
1200 mutex_lock(&n_port->lp_mutex);
Bhanu Prakash Gollapudicdf54662011-08-04 17:38:39 -07001201 list_for_each_entry(v_port, &n_port->vports, list)
1202 if (v_port->vport == vport) {
1203 found = true;
1204 break;
1205 }
1206
1207 if (!found) {
1208 mutex_unlock(&n_port->lp_mutex);
1209 return -ENOENT;
1210 }
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001211 list_del(&vn_port->list);
1212 mutex_unlock(&n_port->lp_mutex);
Bhanu Prakash Gollapudiabc49a92011-08-04 17:38:42 -07001213 bnx2fc_free_vport(interface->hba, port->lport);
1214 bnx2fc_port_shutdown(port->lport);
John Meneghini847f9ea2022-01-14 23:00:44 -05001215 bnx2fc_port_destroy(port);
Bhanu Prakash Gollapudiabc49a92011-08-04 17:38:42 -07001216 bnx2fc_interface_put(interface);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001217 return 0;
1218}
1219
1220static int bnx2fc_vport_disable(struct fc_vport *vport, bool disable)
1221{
1222 struct fc_lport *lport = vport->dd_data;
1223
1224 if (disable) {
1225 fc_vport_set_state(vport, FC_VPORT_DISABLED);
1226 fc_fabric_logoff(lport);
1227 } else {
1228 lport->boot_time = jiffies;
1229 fc_fabric_login(lport);
1230 fc_vport_setlink(lport);
1231 }
1232 return 0;
1233}
1234
1235
Bhanu Prakash Gollapudi776cebc2011-08-04 17:38:40 -07001236static int bnx2fc_interface_setup(struct bnx2fc_interface *interface)
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001237{
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001238 struct net_device *netdev = interface->netdev;
1239 struct net_device *physdev = interface->hba->phys_dev;
Robert Lovefd8f8902012-05-22 19:06:16 -07001240 struct fcoe_ctlr *ctlr = bnx2fc_to_ctlr(interface);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001241 struct netdev_hw_addr *ha;
1242 int sel_san_mac = 0;
1243
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001244 /* setup Source MAC Address */
1245 rcu_read_lock();
1246 for_each_dev_addr(physdev, ha) {
1247 BNX2FC_MISC_DBG("net_config: ha->type = %d, fip_mac = ",
1248 ha->type);
1249 printk(KERN_INFO "%2x:%2x:%2x:%2x:%2x:%2x\n", ha->addr[0],
1250 ha->addr[1], ha->addr[2], ha->addr[3],
1251 ha->addr[4], ha->addr[5]);
1252
1253 if ((ha->type == NETDEV_HW_ADDR_T_SAN) &&
1254 (is_valid_ether_addr(ha->addr))) {
Robert Lovefd8f8902012-05-22 19:06:16 -07001255 memcpy(ctlr->ctl_src_addr, ha->addr,
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001256 ETH_ALEN);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001257 sel_san_mac = 1;
1258 BNX2FC_MISC_DBG("Found SAN MAC\n");
1259 }
1260 }
1261 rcu_read_unlock();
1262
1263 if (!sel_san_mac)
1264 return -ENODEV;
1265
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001266 interface->fip_packet_type.func = bnx2fc_fip_recv;
1267 interface->fip_packet_type.type = htons(ETH_P_FIP);
1268 interface->fip_packet_type.dev = netdev;
1269 dev_add_pack(&interface->fip_packet_type);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001270
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001271 interface->fcoe_packet_type.func = bnx2fc_rcv;
1272 interface->fcoe_packet_type.type = __constant_htons(ETH_P_FCOE);
1273 interface->fcoe_packet_type.dev = netdev;
1274 dev_add_pack(&interface->fcoe_packet_type);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001275
1276 return 0;
1277}
1278
1279static int bnx2fc_attach_transport(void)
1280{
1281 bnx2fc_transport_template =
1282 fc_attach_transport(&bnx2fc_transport_function);
1283
1284 if (bnx2fc_transport_template == NULL) {
1285 printk(KERN_ERR PFX "Failed to attach FC transport\n");
1286 return -ENODEV;
1287 }
1288
1289 bnx2fc_vport_xport_template =
1290 fc_attach_transport(&bnx2fc_vport_xport_function);
1291 if (bnx2fc_vport_xport_template == NULL) {
1292 printk(KERN_ERR PFX
1293 "Failed to attach FC transport for vport\n");
1294 fc_release_transport(bnx2fc_transport_template);
1295 bnx2fc_transport_template = NULL;
1296 return -ENODEV;
1297 }
1298 return 0;
1299}
1300static void bnx2fc_release_transport(void)
1301{
1302 fc_release_transport(bnx2fc_transport_template);
1303 fc_release_transport(bnx2fc_vport_xport_template);
1304 bnx2fc_transport_template = NULL;
1305 bnx2fc_vport_xport_template = NULL;
1306}
1307
1308static void bnx2fc_interface_release(struct kref *kref)
1309{
Robert Love8d55e502012-05-22 19:06:26 -07001310 struct fcoe_ctlr_device *ctlr_dev;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001311 struct bnx2fc_interface *interface;
Robert Lovefd8f8902012-05-22 19:06:16 -07001312 struct fcoe_ctlr *ctlr;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001313 struct net_device *netdev;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001314
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001315 interface = container_of(kref, struct bnx2fc_interface, kref);
Nithin Nayak Sujir068bdce2011-04-25 12:30:09 -07001316 BNX2FC_MISC_DBG("Interface is being released\n");
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001317
Robert Lovefd8f8902012-05-22 19:06:16 -07001318 ctlr = bnx2fc_to_ctlr(interface);
Robert Love8d55e502012-05-22 19:06:26 -07001319 ctlr_dev = fcoe_ctlr_to_ctlr_dev(ctlr);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001320 netdev = interface->netdev;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001321
1322 /* tear-down FIP controller */
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001323 if (test_and_clear_bit(BNX2FC_CTLR_INIT_DONE, &interface->if_flags))
Robert Lovefd8f8902012-05-22 19:06:16 -07001324 fcoe_ctlr_destroy(ctlr);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001325
Robert Love8d55e502012-05-22 19:06:26 -07001326 fcoe_ctlr_device_delete(ctlr_dev);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001327
1328 dev_put(netdev);
1329 module_put(THIS_MODULE);
1330}
1331
1332static inline void bnx2fc_interface_get(struct bnx2fc_interface *interface)
1333{
1334 kref_get(&interface->kref);
1335}
1336
1337static inline void bnx2fc_interface_put(struct bnx2fc_interface *interface)
1338{
1339 kref_put(&interface->kref, bnx2fc_interface_release);
1340}
1341static void bnx2fc_hba_destroy(struct bnx2fc_hba *hba)
1342{
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001343 /* Free the command manager */
1344 if (hba->cmd_mgr) {
1345 bnx2fc_cmd_mgr_free(hba->cmd_mgr);
1346 hba->cmd_mgr = NULL;
1347 }
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001348 kfree(hba->tgt_ofld_list);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001349 bnx2fc_unbind_pcidev(hba);
1350 kfree(hba);
1351}
1352
1353/**
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001354 * bnx2fc_hba_create - create a new bnx2fc hba
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001355 *
1356 * @cnic: pointer to cnic device
1357 *
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001358 * Creates a new FCoE hba on the given device.
1359 *
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001360 */
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001361static struct bnx2fc_hba *bnx2fc_hba_create(struct cnic_dev *cnic)
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001362{
1363 struct bnx2fc_hba *hba;
Barak Witkowski2e499d32012-06-26 01:31:19 +00001364 struct fcoe_capabilities *fcoe_cap;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001365 int rc;
1366
1367 hba = kzalloc(sizeof(*hba), GFP_KERNEL);
1368 if (!hba) {
1369 printk(KERN_ERR PFX "Unable to allocate hba structure\n");
1370 return NULL;
1371 }
1372 spin_lock_init(&hba->hba_lock);
1373 mutex_init(&hba->hba_mutex);
Maurizio Lombardic2dd8932017-05-24 14:09:44 +02001374 mutex_init(&hba->hba_stats_mutex);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001375
1376 hba->cnic = cnic;
Bhanu Prakash Gollapudi0eb43b42013-04-22 19:22:30 +00001377
1378 hba->max_tasks = cnic->max_fcoe_exchanges;
1379 hba->elstm_xids = (hba->max_tasks / 2);
1380 hba->max_outstanding_cmds = hba->elstm_xids;
1381 hba->max_xid = (hba->max_tasks - 1);
1382
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001383 rc = bnx2fc_bind_pcidev(hba);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001384 if (rc) {
1385 printk(KERN_ERR PFX "create_adapter: bind error\n");
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001386 goto bind_err;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001387 }
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001388 hba->phys_dev = cnic->netdev;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001389 hba->next_conn_id = 0;
1390
1391 hba->tgt_ofld_list =
Kees Cook6396bb22018-06-12 14:03:40 -07001392 kcalloc(BNX2FC_NUM_MAX_SESS, sizeof(struct bnx2fc_rport *),
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001393 GFP_KERNEL);
1394 if (!hba->tgt_ofld_list) {
1395 printk(KERN_ERR PFX "Unable to allocate tgt offload list\n");
1396 goto tgtofld_err;
1397 }
1398
1399 hba->num_ofld_sess = 0;
1400
Bhanu Prakash Gollapudi0eb43b42013-04-22 19:22:30 +00001401 hba->cmd_mgr = bnx2fc_cmd_mgr_alloc(hba);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001402 if (!hba->cmd_mgr) {
1403 printk(KERN_ERR PFX "em_config:bnx2fc_cmd_mgr_alloc failed\n");
1404 goto cmgr_err;
1405 }
Barak Witkowski2e499d32012-06-26 01:31:19 +00001406 fcoe_cap = &hba->fcoe_cap;
1407
1408 fcoe_cap->capability1 = BNX2FC_TM_MAX_SQES <<
1409 FCOE_IOS_PER_CONNECTION_SHIFT;
1410 fcoe_cap->capability1 |= BNX2FC_NUM_MAX_SESS <<
1411 FCOE_LOGINS_PER_PORT_SHIFT;
Bhanu Prakash Gollapudi0eb43b42013-04-22 19:22:30 +00001412 fcoe_cap->capability2 = hba->max_outstanding_cmds <<
Barak Witkowski2e499d32012-06-26 01:31:19 +00001413 FCOE_NUMBER_OF_EXCHANGES_SHIFT;
1414 fcoe_cap->capability2 |= BNX2FC_MAX_NPIV <<
1415 FCOE_NPIV_WWN_PER_PORT_SHIFT;
1416 fcoe_cap->capability3 = BNX2FC_NUM_MAX_SESS <<
1417 FCOE_TARGETS_SUPPORTED_SHIFT;
Bhanu Prakash Gollapudi0eb43b42013-04-22 19:22:30 +00001418 fcoe_cap->capability3 |= hba->max_outstanding_cmds <<
Barak Witkowski2e499d32012-06-26 01:31:19 +00001419 FCOE_OUTSTANDING_COMMANDS_SHIFT;
1420 fcoe_cap->capability4 = FCOE_CAPABILITY4_STATEFUL;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001421
1422 init_waitqueue_head(&hba->shutdown_wait);
1423 init_waitqueue_head(&hba->destroy_wait);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001424 INIT_LIST_HEAD(&hba->vports);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001425
1426 return hba;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001427
1428cmgr_err:
1429 kfree(hba->tgt_ofld_list);
1430tgtofld_err:
1431 bnx2fc_unbind_pcidev(hba);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001432bind_err:
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001433 kfree(hba);
1434 return NULL;
1435}
1436
Baoyou Xie3f7d67d2016-09-04 14:52:21 +08001437static struct bnx2fc_interface *
1438bnx2fc_interface_create(struct bnx2fc_hba *hba,
1439 struct net_device *netdev,
Sedat Dilek8beb90a2019-02-15 13:19:20 +01001440 enum fip_mode fip_mode)
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001441{
Robert Love8d55e502012-05-22 19:06:26 -07001442 struct fcoe_ctlr_device *ctlr_dev;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001443 struct bnx2fc_interface *interface;
Robert Lovefd8f8902012-05-22 19:06:16 -07001444 struct fcoe_ctlr *ctlr;
1445 int size;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001446 int rc = 0;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001447
Robert Lovefd8f8902012-05-22 19:06:16 -07001448 size = (sizeof(*interface) + sizeof(struct fcoe_ctlr));
Robert Love8d55e502012-05-22 19:06:26 -07001449 ctlr_dev = fcoe_ctlr_device_add(&netdev->dev, &bnx2fc_fcoe_sysfs_templ,
1450 size);
1451 if (!ctlr_dev) {
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001452 printk(KERN_ERR PFX "Unable to allocate interface structure\n");
1453 return NULL;
1454 }
Robert Love8d55e502012-05-22 19:06:26 -07001455 ctlr = fcoe_ctlr_device_priv(ctlr_dev);
Robert Love9d348762013-09-05 07:47:27 +00001456 ctlr->cdev = ctlr_dev;
Robert Lovefd8f8902012-05-22 19:06:16 -07001457 interface = fcoe_ctlr_priv(ctlr);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001458 dev_hold(netdev);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001459 kref_init(&interface->kref);
1460 interface->hba = hba;
1461 interface->netdev = netdev;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001462
1463 /* Initialize FIP */
Robert Lovefd8f8902012-05-22 19:06:16 -07001464 fcoe_ctlr_init(ctlr, fip_mode);
1465 ctlr->send = bnx2fc_fip_send;
1466 ctlr->update_mac = bnx2fc_update_src_mac;
1467 ctlr->get_src_addr = bnx2fc_get_src_mac;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001468 set_bit(BNX2FC_CTLR_INIT_DONE, &interface->if_flags);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001469
Bhanu Prakash Gollapudi776cebc2011-08-04 17:38:40 -07001470 rc = bnx2fc_interface_setup(interface);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001471 if (!rc)
1472 return interface;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001473
Robert Lovefd8f8902012-05-22 19:06:16 -07001474 fcoe_ctlr_destroy(ctlr);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001475 dev_put(netdev);
Robert Love8d55e502012-05-22 19:06:26 -07001476 fcoe_ctlr_device_delete(ctlr_dev);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001477 return NULL;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001478}
1479
1480/**
1481 * bnx2fc_if_create - Create FCoE instance on a given interface
1482 *
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001483 * @interface: FCoE interface to create a local port on
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001484 * @parent: Device pointer to be the parent in sysfs for the SCSI host
1485 * @npiv: Indicates if the port is vport or not
1486 *
1487 * Creates a fc_lport instance and a Scsi_Host instance and configure them.
1488 *
1489 * Returns: Allocated fc_lport or an error pointer
1490 */
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001491static struct fc_lport *bnx2fc_if_create(struct bnx2fc_interface *interface,
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001492 struct device *parent, int npiv)
1493{
Robert Lovefd8f8902012-05-22 19:06:16 -07001494 struct fcoe_ctlr *ctlr = bnx2fc_to_ctlr(interface);
Vasu Dev134a4e22011-04-28 15:55:44 -07001495 struct fc_lport *lport, *n_port;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001496 struct fcoe_port *port;
1497 struct Scsi_Host *shost;
1498 struct fc_vport *vport = dev_to_vport(parent);
Bhanu Prakash Gollapudid36b3272011-05-27 11:47:27 -07001499 struct bnx2fc_lport *blport;
Bhanu Prakash Gollapudi0eb43b42013-04-22 19:22:30 +00001500 struct bnx2fc_hba *hba = interface->hba;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001501 int rc = 0;
1502
Bhanu Prakash Gollapudid36b3272011-05-27 11:47:27 -07001503 blport = kzalloc(sizeof(struct bnx2fc_lport), GFP_KERNEL);
1504 if (!blport) {
Robert Lovefd8f8902012-05-22 19:06:16 -07001505 BNX2FC_HBA_DBG(ctlr->lp, "Unable to alloc blport\n");
Bhanu Prakash Gollapudid36b3272011-05-27 11:47:27 -07001506 return NULL;
1507 }
1508
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001509 /* Allocate Scsi_Host structure */
Bhanu Prakash Gollapudi0eb43b42013-04-22 19:22:30 +00001510 bnx2fc_shost_template.can_queue = hba->max_outstanding_cmds;
Vasu Dev134a4e22011-04-28 15:55:44 -07001511 if (!npiv)
1512 lport = libfc_host_alloc(&bnx2fc_shost_template, sizeof(*port));
1513 else
1514 lport = libfc_vport_create(vport, sizeof(*port));
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001515
1516 if (!lport) {
1517 printk(KERN_ERR PFX "could not allocate scsi host structure\n");
Bhanu Prakash Gollapudid36b3272011-05-27 11:47:27 -07001518 goto free_blport;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001519 }
1520 shost = lport->host;
1521 port = lport_priv(lport);
1522 port->lport = lport;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001523 port->priv = interface;
Yi Zouc3d79092012-12-06 06:24:29 +00001524 port->get_netdev = bnx2fc_netdev;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001525
1526 /* Configure fcoe_port */
1527 rc = bnx2fc_lport_config(lport);
1528 if (rc)
1529 goto lp_config_err;
1530
1531 if (npiv) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001532 printk(KERN_ERR PFX "Setting vport names, 0x%llX 0x%llX\n",
1533 vport->node_name, vport->port_name);
1534 fc_set_wwnn(lport, vport->node_name);
1535 fc_set_wwpn(lport, vport->port_name);
1536 }
1537 /* Configure netdev and networking properties of the lport */
Bhanu Prakash Gollapudi52439602011-08-04 17:38:50 -07001538 rc = bnx2fc_net_config(lport, interface->netdev);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001539 if (rc) {
1540 printk(KERN_ERR PFX "Error on bnx2fc_net_config\n");
1541 goto lp_config_err;
1542 }
1543
1544 rc = bnx2fc_shost_config(lport, parent);
1545 if (rc) {
Colin Ian Kingab9dd492017-12-01 09:37:25 +00001546 printk(KERN_ERR PFX "Couldn't configure shost for %s\n",
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001547 interface->netdev->name);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001548 goto lp_config_err;
1549 }
1550
1551 /* Initialize the libfc library */
1552 rc = bnx2fc_libfc_config(lport);
1553 if (rc) {
Colin Ian Kingab9dd492017-12-01 09:37:25 +00001554 printk(KERN_ERR PFX "Couldn't configure libfc\n");
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001555 goto shost_err;
1556 }
1557 fc_host_port_type(lport->host) = FC_PORTTYPE_UNKNOWN;
1558
Joe Carnuccio10755d32016-04-07 09:07:56 -04001559 if (bnx2fc_devloss_tmo)
1560 fc_host_dev_loss_tmo(shost) = bnx2fc_devloss_tmo;
1561
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001562 /* Allocate exchange manager */
Vasu Dev134a4e22011-04-28 15:55:44 -07001563 if (!npiv)
Bhanu Prakash Gollapudi0eb43b42013-04-22 19:22:30 +00001564 rc = bnx2fc_em_config(lport, hba);
Vasu Dev134a4e22011-04-28 15:55:44 -07001565 else {
1566 shost = vport_to_shost(vport);
1567 n_port = shost_priv(shost);
1568 rc = fc_exch_mgr_list_clone(n_port, lport);
1569 }
1570
1571 if (rc) {
1572 printk(KERN_ERR PFX "Error on bnx2fc_em_config\n");
1573 goto shost_err;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001574 }
1575
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001576 bnx2fc_interface_get(interface);
Bhanu Prakash Gollapudid36b3272011-05-27 11:47:27 -07001577
1578 spin_lock_bh(&hba->hba_lock);
1579 blport->lport = lport;
1580 list_add_tail(&blport->list, &hba->vports);
1581 spin_unlock_bh(&hba->hba_lock);
1582
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001583 return lport;
1584
1585shost_err:
1586 scsi_remove_host(shost);
1587lp_config_err:
1588 scsi_host_put(lport->host);
Bhanu Prakash Gollapudid36b3272011-05-27 11:47:27 -07001589free_blport:
1590 kfree(blport);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001591 return NULL;
1592}
1593
Bhanu Prakash Gollapudi013068f2011-08-30 15:54:52 -07001594static void bnx2fc_net_cleanup(struct bnx2fc_interface *interface)
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001595{
1596 /* Dont listen for Ethernet packets anymore */
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001597 __dev_remove_pack(&interface->fcoe_packet_type);
1598 __dev_remove_pack(&interface->fip_packet_type);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001599 synchronize_net();
1600}
1601
Bhanu Prakash Gollapudi776cebc2011-08-04 17:38:40 -07001602static void bnx2fc_interface_cleanup(struct bnx2fc_interface *interface)
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001603{
Robert Lovefd8f8902012-05-22 19:06:16 -07001604 struct fcoe_ctlr *ctlr = bnx2fc_to_ctlr(interface);
1605 struct fc_lport *lport = ctlr->lp;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001606 struct fcoe_port *port = lport_priv(lport);
Bhanu Prakash Gollapudi9be17fc2011-08-04 17:38:41 -07001607 struct bnx2fc_hba *hba = interface->hba;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001608
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001609 /* Stop the transmit retry timer */
1610 del_timer_sync(&port->timer);
1611
1612 /* Free existing transmit skbs */
1613 fcoe_clean_pending_queue(lport);
1614
Bhanu Prakash Gollapudi013068f2011-08-30 15:54:52 -07001615 bnx2fc_net_cleanup(interface);
Bhanu Prakash Gollapudi9be17fc2011-08-04 17:38:41 -07001616
Bhanu Prakash Gollapudiabc49a92011-08-04 17:38:42 -07001617 bnx2fc_free_vport(hba, lport);
Bhanu Prakash Gollapudi9be17fc2011-08-04 17:38:41 -07001618}
1619
1620static void bnx2fc_if_destroy(struct fc_lport *lport)
1621{
1622
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001623 /* Free queued packets for the receive thread */
1624 bnx2fc_clean_rx_queue(lport);
1625
1626 /* Detach from scsi-ml */
1627 fc_remove_host(lport->host);
1628 scsi_remove_host(lport->host);
1629
1630 /*
1631 * Note that only the physical lport will have the exchange manager.
1632 * for vports, this function is NOP
1633 */
1634 fc_exch_mgr_free(lport);
1635
1636 /* Free memory used by statistical counters */
1637 fc_lport_free_stats(lport);
1638
1639 /* Release Scsi_Host */
1640 scsi_host_put(lport->host);
1641}
1642
Bhanu Prakash Gollapudieccdcd02011-08-24 18:56:42 -07001643static void __bnx2fc_destroy(struct bnx2fc_interface *interface)
Bhanu Prakash Gollapudiabc49a92011-08-04 17:38:42 -07001644{
Robert Lovefd8f8902012-05-22 19:06:16 -07001645 struct fcoe_ctlr *ctlr = bnx2fc_to_ctlr(interface);
1646 struct fc_lport *lport = ctlr->lp;
Bhanu Prakash Gollapudi0cbf32e2011-08-30 15:54:51 -07001647 struct fcoe_port *port = lport_priv(lport);
Bhanu Prakash Gollapudiabc49a92011-08-04 17:38:42 -07001648
1649 bnx2fc_interface_cleanup(interface);
1650 bnx2fc_stop(interface);
Bhanu Prakash Gollapudiabc49a92011-08-04 17:38:42 -07001651 list_del(&interface->list);
John Meneghini847f9ea2022-01-14 23:00:44 -05001652 bnx2fc_port_destroy(port);
Bhanu Prakash Gollapudiabc49a92011-08-04 17:38:42 -07001653 bnx2fc_interface_put(interface);
Bhanu Prakash Gollapudiabc49a92011-08-04 17:38:42 -07001654}
1655
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001656/**
1657 * bnx2fc_destroy - Destroy a bnx2fc FCoE interface
1658 *
Lee Jonesca63d8e2020-07-13 08:46:23 +01001659 * @netdev: The net device that the FCoE interface is on
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001660 *
1661 * Called from sysfs.
1662 *
1663 * Returns: 0 for success
1664 */
1665static int bnx2fc_destroy(struct net_device *netdev)
1666{
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001667 struct bnx2fc_interface *interface = NULL;
Bhanu Prakash Gollapudi2a7b29c2012-01-23 18:00:46 -08001668 struct workqueue_struct *timer_work_queue;
Robert Lovefd8f8902012-05-22 19:06:16 -07001669 struct fcoe_ctlr *ctlr;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001670 int rc = 0;
1671
Nithin Sujir6702ca12011-03-17 17:13:27 -07001672 rtnl_lock();
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001673 mutex_lock(&bnx2fc_dev_lock);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001674
1675 interface = bnx2fc_interface_lookup(netdev);
Robert Lovefd8f8902012-05-22 19:06:16 -07001676 ctlr = bnx2fc_to_ctlr(interface);
1677 if (!interface || !ctlr->lp) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001678 rc = -ENODEV;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001679 printk(KERN_ERR PFX "bnx2fc_destroy: interface or lport not found\n");
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001680 goto netdev_err;
1681 }
1682
Bhanu Prakash Gollapudi2a7b29c2012-01-23 18:00:46 -08001683 timer_work_queue = interface->timer_work_queue;
Bhanu Prakash Gollapudieccdcd02011-08-24 18:56:42 -07001684 __bnx2fc_destroy(interface);
Bhanu Prakash Gollapudi2a7b29c2012-01-23 18:00:46 -08001685 destroy_workqueue(timer_work_queue);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001686
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001687netdev_err:
1688 mutex_unlock(&bnx2fc_dev_lock);
1689 rtnl_unlock();
1690 return rc;
1691}
1692
John Meneghini847f9ea2022-01-14 23:00:44 -05001693static void bnx2fc_port_destroy(struct fcoe_port *port)
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001694{
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001695 struct fc_lport *lport;
1696
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001697 lport = port->lport;
John Meneghini847f9ea2022-01-14 23:00:44 -05001698 BNX2FC_HBA_DBG(lport, "Entered %s, destroying lport %p\n", __func__, lport);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001699
Bhanu Prakash Gollapudi9be17fc2011-08-04 17:38:41 -07001700 bnx2fc_if_destroy(lport);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001701}
1702
1703static void bnx2fc_unbind_adapter_devices(struct bnx2fc_hba *hba)
1704{
1705 bnx2fc_free_fw_resc(hba);
1706 bnx2fc_free_task_ctx(hba);
1707}
1708
1709/**
1710 * bnx2fc_bind_adapter_devices - binds bnx2fc adapter with the associated
1711 * pci structure
1712 *
1713 * @hba: Adapter instance
1714 */
1715static int bnx2fc_bind_adapter_devices(struct bnx2fc_hba *hba)
1716{
1717 if (bnx2fc_setup_task_ctx(hba))
1718 goto mem_err;
1719
1720 if (bnx2fc_setup_fw_resc(hba))
1721 goto mem_err;
1722
1723 return 0;
1724mem_err:
1725 bnx2fc_unbind_adapter_devices(hba);
1726 return -ENOMEM;
1727}
1728
1729static int bnx2fc_bind_pcidev(struct bnx2fc_hba *hba)
1730{
1731 struct cnic_dev *cnic;
Bhanu Prakash Gollapudic13d2b62013-03-08 13:28:51 -08001732 struct pci_dev *pdev;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001733
1734 if (!hba->cnic) {
1735 printk(KERN_ERR PFX "cnic is NULL\n");
1736 return -ENODEV;
1737 }
1738 cnic = hba->cnic;
Bhanu Prakash Gollapudic13d2b62013-03-08 13:28:51 -08001739 pdev = hba->pcidev = cnic->pcidev;
1740 if (!hba->pcidev)
1741 return -ENODEV;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001742
Bhanu Prakash Gollapudic13d2b62013-03-08 13:28:51 -08001743 switch (pdev->device) {
1744 case PCI_DEVICE_ID_NX2_57710:
1745 strncpy(hba->chip_num, "BCM57710", BCM_CHIP_LEN);
1746 break;
1747 case PCI_DEVICE_ID_NX2_57711:
1748 strncpy(hba->chip_num, "BCM57711", BCM_CHIP_LEN);
1749 break;
1750 case PCI_DEVICE_ID_NX2_57712:
1751 case PCI_DEVICE_ID_NX2_57712_MF:
1752 case PCI_DEVICE_ID_NX2_57712_VF:
1753 strncpy(hba->chip_num, "BCM57712", BCM_CHIP_LEN);
1754 break;
1755 case PCI_DEVICE_ID_NX2_57800:
1756 case PCI_DEVICE_ID_NX2_57800_MF:
1757 case PCI_DEVICE_ID_NX2_57800_VF:
1758 strncpy(hba->chip_num, "BCM57800", BCM_CHIP_LEN);
1759 break;
1760 case PCI_DEVICE_ID_NX2_57810:
1761 case PCI_DEVICE_ID_NX2_57810_MF:
1762 case PCI_DEVICE_ID_NX2_57810_VF:
1763 strncpy(hba->chip_num, "BCM57810", BCM_CHIP_LEN);
1764 break;
1765 case PCI_DEVICE_ID_NX2_57840:
1766 case PCI_DEVICE_ID_NX2_57840_MF:
1767 case PCI_DEVICE_ID_NX2_57840_VF:
1768 case PCI_DEVICE_ID_NX2_57840_2_20:
1769 case PCI_DEVICE_ID_NX2_57840_4_10:
1770 strncpy(hba->chip_num, "BCM57840", BCM_CHIP_LEN);
1771 break;
1772 default:
1773 pr_err(PFX "Unknown device id 0x%x\n", pdev->device);
1774 break;
1775 }
1776 pci_dev_get(hba->pcidev);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001777 return 0;
1778}
1779
1780static void bnx2fc_unbind_pcidev(struct bnx2fc_hba *hba)
1781{
Bhanu Prakash Gollapudic13d2b62013-03-08 13:28:51 -08001782 if (hba->pcidev) {
1783 hba->chip_num[0] = '\0';
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001784 pci_dev_put(hba->pcidev);
Bhanu Prakash Gollapudic13d2b62013-03-08 13:28:51 -08001785 }
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001786 hba->pcidev = NULL;
1787}
1788
Barak Witkowski2e499d32012-06-26 01:31:19 +00001789/**
1790 * bnx2fc_ulp_get_stats - cnic callback to populate FCoE stats
1791 *
Bhaskar Chowdhury5fae8092021-03-22 12:05:30 +05301792 * @handle: transport handle pointing to adapter structure
Barak Witkowski2e499d32012-06-26 01:31:19 +00001793 */
1794static int bnx2fc_ulp_get_stats(void *handle)
1795{
1796 struct bnx2fc_hba *hba = handle;
1797 struct cnic_dev *cnic;
1798 struct fcoe_stats_info *stats_addr;
1799
1800 if (!hba)
1801 return -EINVAL;
1802
1803 cnic = hba->cnic;
1804 stats_addr = &cnic->stats_addr->fcoe_stat;
1805 if (!stats_addr)
1806 return -EINVAL;
1807
1808 strncpy(stats_addr->version, BNX2FC_VERSION,
1809 sizeof(stats_addr->version));
1810 stats_addr->txq_size = BNX2FC_SQ_WQES_MAX;
1811 stats_addr->rxq_size = BNX2FC_CQ_WQES_MAX;
1812
1813 return 0;
1814}
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001815
1816
1817/**
1818 * bnx2fc_ulp_start - cnic callback to initialize & start adapter instance
1819 *
Masanari Iida59e13d42012-04-25 00:24:16 +09001820 * @handle: transport handle pointing to adapter structure
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001821 *
1822 * This function maps adapter structure to pcidev structure and initiates
1823 * firmware handshake to enable/initialize on-chip FCoE components.
1824 * This bnx2fc - cnic interface api callback is used after following
1825 * conditions are met -
1826 * a) underlying network interface is up (marked by event NETDEV_UP
1827 * from netdev
1828 * b) bnx2fc adatper structure is registered.
1829 */
1830static void bnx2fc_ulp_start(void *handle)
1831{
1832 struct bnx2fc_hba *hba = handle;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001833 struct bnx2fc_interface *interface;
Robert Lovefd8f8902012-05-22 19:06:16 -07001834 struct fcoe_ctlr *ctlr;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001835 struct fc_lport *lport;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001836
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001837 mutex_lock(&bnx2fc_dev_lock);
1838
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001839 if (!test_bit(BNX2FC_FLAG_FW_INIT_DONE, &hba->flags))
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001840 bnx2fc_fw_init(hba);
1841
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001842 BNX2FC_MISC_DBG("bnx2fc started.\n");
1843
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001844 list_for_each_entry(interface, &if_list, list) {
1845 if (interface->hba == hba) {
Robert Lovefd8f8902012-05-22 19:06:16 -07001846 ctlr = bnx2fc_to_ctlr(interface);
1847 lport = ctlr->lp;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001848 /* Kick off Fabric discovery*/
1849 printk(KERN_ERR PFX "ulp_init: start discovery\n");
1850 lport->tt.frame_send = bnx2fc_xmit;
1851 bnx2fc_start_disc(interface);
1852 }
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001853 }
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001854
1855 mutex_unlock(&bnx2fc_dev_lock);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001856}
1857
1858static void bnx2fc_port_shutdown(struct fc_lport *lport)
1859{
1860 BNX2FC_MISC_DBG("Entered %s\n", __func__);
1861 fc_fabric_logoff(lport);
1862 fc_lport_destroy(lport);
1863}
1864
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001865static void bnx2fc_stop(struct bnx2fc_interface *interface)
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001866{
Robert Lovefd8f8902012-05-22 19:06:16 -07001867 struct fcoe_ctlr *ctlr = bnx2fc_to_ctlr(interface);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001868 struct fc_lport *lport;
1869 struct fc_lport *vport;
1870
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001871 if (!test_bit(BNX2FC_FLAG_FW_INIT_DONE, &interface->hba->flags))
1872 return;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001873
Robert Lovefd8f8902012-05-22 19:06:16 -07001874 lport = ctlr->lp;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001875 bnx2fc_port_shutdown(lport);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001876
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001877 mutex_lock(&lport->lp_mutex);
1878 list_for_each_entry(vport, &lport->vports, list)
1879 fc_host_port_type(vport->host) =
1880 FC_PORTTYPE_UNKNOWN;
1881 mutex_unlock(&lport->lp_mutex);
1882 fc_host_port_type(lport->host) = FC_PORTTYPE_UNKNOWN;
Robert Lovefd8f8902012-05-22 19:06:16 -07001883 fcoe_ctlr_link_down(ctlr);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001884 fcoe_clean_pending_queue(lport);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001885}
1886
1887static int bnx2fc_fw_init(struct bnx2fc_hba *hba)
1888{
1889#define BNX2FC_INIT_POLL_TIME (1000 / HZ)
1890 int rc = -1;
1891 int i = HZ;
1892
1893 rc = bnx2fc_bind_adapter_devices(hba);
1894 if (rc) {
1895 printk(KERN_ALERT PFX
1896 "bnx2fc_bind_adapter_devices failed - rc = %d\n", rc);
1897 goto err_out;
1898 }
1899
1900 rc = bnx2fc_send_fw_fcoe_init_msg(hba);
1901 if (rc) {
1902 printk(KERN_ALERT PFX
1903 "bnx2fc_send_fw_fcoe_init_msg failed - rc = %d\n", rc);
1904 goto err_unbind;
1905 }
1906
1907 /*
1908 * Wait until the adapter init message is complete, and adapter
1909 * state is UP.
1910 */
1911 while (!test_bit(ADAPTER_STATE_UP, &hba->adapter_state) && i--)
1912 msleep(BNX2FC_INIT_POLL_TIME);
1913
1914 if (!test_bit(ADAPTER_STATE_UP, &hba->adapter_state)) {
1915 printk(KERN_ERR PFX "bnx2fc_start: %s failed to initialize. "
1916 "Ignoring...\n",
1917 hba->cnic->netdev->name);
1918 rc = -1;
1919 goto err_unbind;
1920 }
1921
1922
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001923 set_bit(BNX2FC_FLAG_FW_INIT_DONE, &hba->flags);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001924 return 0;
1925
1926err_unbind:
1927 bnx2fc_unbind_adapter_devices(hba);
1928err_out:
1929 return rc;
1930}
1931
1932static void bnx2fc_fw_destroy(struct bnx2fc_hba *hba)
1933{
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001934 if (test_and_clear_bit(BNX2FC_FLAG_FW_INIT_DONE, &hba->flags)) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001935 if (bnx2fc_send_fw_fcoe_destroy_msg(hba) == 0) {
Kees Cook13059102017-09-21 13:12:15 -07001936 timer_setup(&hba->destroy_timer, bnx2fc_destroy_timer,
1937 0);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001938 hba->destroy_timer.expires = BNX2FC_FW_TIMEOUT +
1939 jiffies;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001940 add_timer(&hba->destroy_timer);
1941 wait_event_interruptible(hba->destroy_wait,
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001942 test_bit(BNX2FC_FLAG_DESTROY_CMPL,
1943 &hba->flags));
Bhanu Prakash Gollapudicd703ae2011-08-04 17:38:43 -07001944 clear_bit(BNX2FC_FLAG_DESTROY_CMPL, &hba->flags);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001945 /* This should never happen */
1946 if (signal_pending(current))
1947 flush_signals(current);
1948
1949 del_timer_sync(&hba->destroy_timer);
1950 }
1951 bnx2fc_unbind_adapter_devices(hba);
1952 }
1953}
1954
1955/**
1956 * bnx2fc_ulp_stop - cnic callback to shutdown adapter instance
1957 *
1958 * @handle: transport handle pointing to adapter structure
1959 *
1960 * Driver checks if adapter is already in shutdown mode, if not start
1961 * the shutdown process.
1962 */
1963static void bnx2fc_ulp_stop(void *handle)
1964{
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001965 struct bnx2fc_hba *hba = handle;
1966 struct bnx2fc_interface *interface;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001967
1968 printk(KERN_ERR "ULP_STOP\n");
1969
1970 mutex_lock(&bnx2fc_dev_lock);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001971 if (!test_bit(BNX2FC_FLAG_FW_INIT_DONE, &hba->flags))
1972 goto exit;
1973 list_for_each_entry(interface, &if_list, list) {
1974 if (interface->hba == hba)
1975 bnx2fc_stop(interface);
1976 }
1977 BUG_ON(hba->num_ofld_sess != 0);
1978
1979 mutex_lock(&hba->hba_mutex);
1980 clear_bit(ADAPTER_STATE_UP, &hba->adapter_state);
1981 clear_bit(ADAPTER_STATE_GOING_DOWN,
1982 &hba->adapter_state);
1983
1984 clear_bit(ADAPTER_STATE_READY, &hba->adapter_state);
1985 mutex_unlock(&hba->hba_mutex);
1986
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001987 bnx2fc_fw_destroy(hba);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001988exit:
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001989 mutex_unlock(&bnx2fc_dev_lock);
1990}
1991
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001992static void bnx2fc_start_disc(struct bnx2fc_interface *interface)
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001993{
Robert Lovefd8f8902012-05-22 19:06:16 -07001994 struct fcoe_ctlr *ctlr = bnx2fc_to_ctlr(interface);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001995 struct fc_lport *lport;
1996 int wait_cnt = 0;
1997
1998 BNX2FC_MISC_DBG("Entered %s\n", __func__);
1999 /* Kick off FIP/FLOGI */
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002000 if (!test_bit(BNX2FC_FLAG_FW_INIT_DONE, &interface->hba->flags)) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002001 printk(KERN_ERR PFX "Init not done yet\n");
2002 return;
2003 }
2004
Robert Lovefd8f8902012-05-22 19:06:16 -07002005 lport = ctlr->lp;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002006 BNX2FC_HBA_DBG(lport, "calling fc_fabric_login\n");
2007
Bhanu Prakash Gollapudi8a5badf2011-08-30 15:54:48 -07002008 if (!bnx2fc_link_ok(lport) && interface->enabled) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002009 BNX2FC_HBA_DBG(lport, "ctlr_link_up\n");
Robert Lovefd8f8902012-05-22 19:06:16 -07002010 fcoe_ctlr_link_up(ctlr);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002011 fc_host_port_type(lport->host) = FC_PORTTYPE_NPORT;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002012 set_bit(ADAPTER_STATE_READY, &interface->hba->adapter_state);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002013 }
2014
2015 /* wait for the FCF to be selected before issuing FLOGI */
Robert Lovefd8f8902012-05-22 19:06:16 -07002016 while (!ctlr->sel_fcf) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002017 msleep(250);
2018 /* give up after 3 secs */
2019 if (++wait_cnt > 12)
2020 break;
2021 }
Bhanu Prakash Gollapudi627e6282011-08-04 17:38:35 -07002022
2023 /* Reset max receive frame size to default */
2024 if (fc_set_mfs(lport, BNX2FC_MFS))
2025 return;
2026
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002027 fc_lport_init(lport);
2028 fc_fabric_login(lport);
2029}
2030
2031
2032/**
2033 * bnx2fc_ulp_init - Initialize an adapter instance
2034 *
2035 * @dev : cnic device handle
2036 * Called from cnic_register_driver() context to initialize all
2037 * enumerated cnic devices. This routine allocates adapter structure
2038 * and other device specific resources.
2039 */
2040static void bnx2fc_ulp_init(struct cnic_dev *dev)
2041{
2042 struct bnx2fc_hba *hba;
2043 int rc = 0;
2044
2045 BNX2FC_MISC_DBG("Entered %s\n", __func__);
2046 /* bnx2fc works only when bnx2x is loaded */
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002047 if (!test_bit(CNIC_F_BNX2X_CLASS, &dev->flags) ||
2048 (dev->max_fcoe_conn == 0)) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002049 printk(KERN_ERR PFX "bnx2fc FCoE not supported on %s,"
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002050 " flags: %lx fcoe_conn: %d\n",
2051 dev->netdev->name, dev->flags, dev->max_fcoe_conn);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002052 return;
2053 }
2054
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002055 hba = bnx2fc_hba_create(dev);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002056 if (!hba) {
2057 printk(KERN_ERR PFX "hba initialization failed\n");
2058 return;
2059 }
2060
Chad Dupuisf72464d2016-04-07 09:07:58 -04002061 pr_info(PFX "FCoE initialized for %s.\n", dev->netdev->name);
2062
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002063 /* Add HBA to the adapter list */
2064 mutex_lock(&bnx2fc_dev_lock);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002065 list_add_tail(&hba->list, &adapter_list);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002066 adapter_count++;
2067 mutex_unlock(&bnx2fc_dev_lock);
2068
Barak Witkowski2e499d32012-06-26 01:31:19 +00002069 dev->fcoe_cap = &hba->fcoe_cap;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002070 clear_bit(BNX2FC_CNIC_REGISTERED, &hba->reg_with_cnic);
2071 rc = dev->register_device(dev, CNIC_ULP_FCOE,
2072 (void *) hba);
2073 if (rc)
Bhanu Prakash Gollapudib2a554f2011-06-27 23:30:53 -07002074 printk(KERN_ERR PFX "register_device failed, rc = %d\n", rc);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002075 else
2076 set_bit(BNX2FC_CNIC_REGISTERED, &hba->reg_with_cnic);
2077}
2078
Eddie Wai06808102013-09-25 22:01:20 -07002079/* Assumes rtnl_lock and the bnx2fc_dev_lock are already taken */
2080static int __bnx2fc_disable(struct fcoe_ctlr *ctlr)
2081{
2082 struct bnx2fc_interface *interface = fcoe_ctlr_priv(ctlr);
2083
Kaixu Xiacb2b4e82020-11-08 00:52:00 +08002084 if (interface->enabled) {
Eddie Wai06808102013-09-25 22:01:20 -07002085 if (!ctlr->lp) {
2086 pr_err(PFX "__bnx2fc_disable: lport not found\n");
2087 return -ENODEV;
2088 } else {
2089 interface->enabled = false;
2090 fcoe_ctlr_link_down(ctlr);
2091 fcoe_clean_pending_queue(ctlr->lp);
2092 }
2093 }
2094 return 0;
2095}
2096
Lee Jonesca63d8e2020-07-13 08:46:23 +01002097/*
Robert Love6e89ea32012-11-27 06:53:40 +00002098 * Deperecated: Use bnx2fc_enabled()
2099 */
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002100static int bnx2fc_disable(struct net_device *netdev)
2101{
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002102 struct bnx2fc_interface *interface;
Robert Lovefd8f8902012-05-22 19:06:16 -07002103 struct fcoe_ctlr *ctlr;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002104 int rc = 0;
2105
Nithin Sujir6702ca12011-03-17 17:13:27 -07002106 rtnl_lock();
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002107 mutex_lock(&bnx2fc_dev_lock);
2108
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002109 interface = bnx2fc_interface_lookup(netdev);
Robert Lovefd8f8902012-05-22 19:06:16 -07002110 ctlr = bnx2fc_to_ctlr(interface);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002111
Eddie Wai06808102013-09-25 22:01:20 -07002112 if (!interface) {
2113 rc = -ENODEV;
2114 pr_err(PFX "bnx2fc_disable: interface not found\n");
2115 } else {
2116 rc = __bnx2fc_disable(ctlr);
2117 }
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002118 mutex_unlock(&bnx2fc_dev_lock);
2119 rtnl_unlock();
2120 return rc;
2121}
2122
Joe Carnuccio2971ff62015-08-04 09:37:30 +03002123static uint bnx2fc_npiv_create_vports(struct fc_lport *lport,
2124 struct cnic_fc_npiv_tbl *npiv_tbl)
2125{
2126 struct fc_vport_identifiers vpid;
2127 uint i, created = 0;
Chad Dupuis59fb8702017-06-26 08:59:35 -07002128 u64 wwnn = 0;
2129 char wwpn_str[32];
2130 char wwnn_str[32];
Joe Carnuccio2971ff62015-08-04 09:37:30 +03002131
2132 if (npiv_tbl->count > MAX_NPIV_ENTRIES) {
2133 BNX2FC_HBA_DBG(lport, "Exceeded count max of npiv table\n");
2134 goto done;
2135 }
2136
2137 /* Sanity check the first entry to make sure it's not 0 */
2138 if (wwn_to_u64(npiv_tbl->wwnn[0]) == 0 &&
2139 wwn_to_u64(npiv_tbl->wwpn[0]) == 0) {
2140 BNX2FC_HBA_DBG(lport, "First NPIV table entries invalid.\n");
2141 goto done;
2142 }
2143
2144 vpid.roles = FC_PORT_ROLE_FCP_INITIATOR;
2145 vpid.vport_type = FC_PORTTYPE_NPIV;
2146 vpid.disable = false;
2147
2148 for (i = 0; i < npiv_tbl->count; i++) {
Chad Dupuis59fb8702017-06-26 08:59:35 -07002149 wwnn = wwn_to_u64(npiv_tbl->wwnn[i]);
2150 if (wwnn == 0) {
2151 /*
2152 * If we get a 0 element from for the WWNN then assume
2153 * the WWNN should be the same as the physical port.
2154 */
2155 wwnn = lport->wwnn;
2156 }
2157 vpid.node_name = wwnn;
Joe Carnuccio2971ff62015-08-04 09:37:30 +03002158 vpid.port_name = wwn_to_u64(npiv_tbl->wwpn[i]);
2159 scnprintf(vpid.symbolic_name, sizeof(vpid.symbolic_name),
2160 "NPIV[%u]:%016llx-%016llx",
2161 created, vpid.port_name, vpid.node_name);
Chad Dupuis59fb8702017-06-26 08:59:35 -07002162 fcoe_wwn_to_str(vpid.node_name, wwnn_str, sizeof(wwnn_str));
2163 fcoe_wwn_to_str(vpid.port_name, wwpn_str, sizeof(wwpn_str));
2164 BNX2FC_HBA_DBG(lport, "Creating vport %s:%s.\n", wwnn_str,
2165 wwpn_str);
Joe Carnuccio2971ff62015-08-04 09:37:30 +03002166 if (fc_vport_create(lport->host, 0, &vpid))
2167 created++;
2168 else
2169 BNX2FC_HBA_DBG(lport, "Failed to create vport\n");
2170 }
2171done:
2172 return created;
2173}
2174
Eddie Wai06808102013-09-25 22:01:20 -07002175static int __bnx2fc_enable(struct fcoe_ctlr *ctlr)
2176{
2177 struct bnx2fc_interface *interface = fcoe_ctlr_priv(ctlr);
Joe Carnuccio2971ff62015-08-04 09:37:30 +03002178 struct bnx2fc_hba *hba;
Arnd Bergmann720ba802015-10-07 15:11:04 +02002179 struct cnic_fc_npiv_tbl *npiv_tbl;
Joe Carnuccio2971ff62015-08-04 09:37:30 +03002180 struct fc_lport *lport;
Eddie Wai06808102013-09-25 22:01:20 -07002181
Kaixu Xiacb2b4e82020-11-08 00:52:00 +08002182 if (!interface->enabled) {
Eddie Wai06808102013-09-25 22:01:20 -07002183 if (!ctlr->lp) {
2184 pr_err(PFX "__bnx2fc_enable: lport not found\n");
2185 return -ENODEV;
2186 } else if (!bnx2fc_link_ok(ctlr->lp)) {
2187 fcoe_ctlr_link_up(ctlr);
2188 interface->enabled = true;
2189 }
2190 }
Joe Carnuccio2971ff62015-08-04 09:37:30 +03002191
2192 /* Create static NPIV ports if any are contained in NVRAM */
2193 hba = interface->hba;
2194 lport = ctlr->lp;
2195
2196 if (!hba)
2197 goto done;
2198
2199 if (!hba->cnic)
2200 goto done;
2201
2202 if (!lport)
2203 goto done;
2204
2205 if (!lport->host)
2206 goto done;
2207
2208 if (!hba->cnic->get_fc_npiv_tbl)
2209 goto done;
2210
Arnd Bergmann720ba802015-10-07 15:11:04 +02002211 npiv_tbl = kzalloc(sizeof(struct cnic_fc_npiv_tbl), GFP_KERNEL);
2212 if (!npiv_tbl)
Joe Carnuccio2971ff62015-08-04 09:37:30 +03002213 goto done;
2214
Arnd Bergmann720ba802015-10-07 15:11:04 +02002215 if (hba->cnic->get_fc_npiv_tbl(hba->cnic, npiv_tbl))
2216 goto done_free;
2217
2218 bnx2fc_npiv_create_vports(lport, npiv_tbl);
2219done_free:
2220 kfree(npiv_tbl);
Joe Carnuccio2971ff62015-08-04 09:37:30 +03002221done:
Eddie Wai06808102013-09-25 22:01:20 -07002222 return 0;
2223}
2224
Lee Jonesca63d8e2020-07-13 08:46:23 +01002225/*
Robert Love6e89ea32012-11-27 06:53:40 +00002226 * Deprecated: Use bnx2fc_enabled()
2227 */
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002228static int bnx2fc_enable(struct net_device *netdev)
2229{
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002230 struct bnx2fc_interface *interface;
Robert Lovefd8f8902012-05-22 19:06:16 -07002231 struct fcoe_ctlr *ctlr;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002232 int rc = 0;
2233
Nithin Sujir6702ca12011-03-17 17:13:27 -07002234 rtnl_lock();
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002235 mutex_lock(&bnx2fc_dev_lock);
2236
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002237 interface = bnx2fc_interface_lookup(netdev);
Robert Lovefd8f8902012-05-22 19:06:16 -07002238 ctlr = bnx2fc_to_ctlr(interface);
Eddie Wai06808102013-09-25 22:01:20 -07002239 if (!interface) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002240 rc = -ENODEV;
Eddie Wai06808102013-09-25 22:01:20 -07002241 pr_err(PFX "bnx2fc_enable: interface not found\n");
2242 } else {
2243 rc = __bnx2fc_enable(ctlr);
Bhanu Prakash Gollapudi8a5badf2011-08-30 15:54:48 -07002244 }
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002245
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002246 mutex_unlock(&bnx2fc_dev_lock);
2247 rtnl_unlock();
2248 return rc;
2249}
2250
2251/**
Robert Love6e89ea32012-11-27 06:53:40 +00002252 * bnx2fc_ctlr_enabled() - Enable or disable an FCoE Controller
2253 * @cdev: The FCoE Controller that is being enabled or disabled
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002254 *
Robert Love6e89ea32012-11-27 06:53:40 +00002255 * fcoe_sysfs will ensure that the state of 'enabled' has
2256 * changed, so no checking is necessary here. This routine simply
2257 * calls fcoe_enable or fcoe_disable, both of which are deprecated.
2258 * When those routines are removed the functionality can be merged
2259 * here.
2260 */
2261static int bnx2fc_ctlr_enabled(struct fcoe_ctlr_device *cdev)
2262{
2263 struct fcoe_ctlr *ctlr = fcoe_ctlr_device_priv(cdev);
Robert Love6e89ea32012-11-27 06:53:40 +00002264
2265 switch (cdev->enabled) {
2266 case FCOE_CTLR_ENABLED:
Eddie Wai06808102013-09-25 22:01:20 -07002267 return __bnx2fc_enable(ctlr);
Robert Love6e89ea32012-11-27 06:53:40 +00002268 case FCOE_CTLR_DISABLED:
Eddie Wai06808102013-09-25 22:01:20 -07002269 return __bnx2fc_disable(ctlr);
Robert Love6e89ea32012-11-27 06:53:40 +00002270 case FCOE_CTLR_UNUSED:
2271 default:
2272 return -ENOTSUPP;
Tom Rix4a9435b2020-11-01 06:38:12 -08002273 }
Robert Love6e89ea32012-11-27 06:53:40 +00002274}
2275
2276enum bnx2fc_create_link_state {
2277 BNX2FC_CREATE_LINK_DOWN,
2278 BNX2FC_CREATE_LINK_UP,
2279};
2280
2281/**
2282 * _bnx2fc_create() - Create bnx2fc FCoE interface
2283 * @netdev : The net_device object the Ethernet interface to create on
2284 * @fip_mode: The FIP mode for this creation
2285 * @link_state: The ctlr link state on creation
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002286 *
Robert Love6e89ea32012-11-27 06:53:40 +00002287 * Called from either the libfcoe 'create' module parameter
2288 * via fcoe_create or from fcoe_syfs's ctlr_create file.
2289 *
2290 * libfcoe's 'create' module parameter is deprecated so some
2291 * consolidation of code can be done when that interface is
2292 * removed.
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002293 *
2294 * Returns: 0 for success
2295 */
Robert Love6e89ea32012-11-27 06:53:40 +00002296static int _bnx2fc_create(struct net_device *netdev,
Hannes Reinecke1917d422016-07-04 10:29:19 +02002297 enum fip_mode fip_mode,
Robert Love6e89ea32012-11-27 06:53:40 +00002298 enum bnx2fc_create_link_state link_state)
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002299{
Robert Love6e89ea32012-11-27 06:53:40 +00002300 struct fcoe_ctlr_device *cdev;
Robert Lovefd8f8902012-05-22 19:06:16 -07002301 struct fcoe_ctlr *ctlr;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002302 struct bnx2fc_interface *interface;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002303 struct bnx2fc_hba *hba;
Bhanu Prakash Gollapudi7adc5a32012-06-04 16:15:44 -07002304 struct net_device *phys_dev = netdev;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002305 struct fc_lport *lport;
2306 struct ethtool_drvinfo drvinfo;
2307 int rc = 0;
Bhanu Prakash Gollapudi7adc5a32012-06-04 16:15:44 -07002308 int vlan_id = 0;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002309
2310 BNX2FC_MISC_DBG("Entered bnx2fc_create\n");
2311 if (fip_mode != FIP_MODE_FABRIC) {
2312 printk(KERN_ERR "fip mode not FABRIC\n");
2313 return -EIO;
2314 }
2315
Nithin Sujir6702ca12011-03-17 17:13:27 -07002316 rtnl_lock();
2317
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002318 mutex_lock(&bnx2fc_dev_lock);
2319
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002320 if (!try_module_get(THIS_MODULE)) {
2321 rc = -EINVAL;
2322 goto mod_err;
2323 }
2324
2325 /* obtain physical netdev */
Parav Panditd0d7b102017-02-04 11:00:49 -06002326 if (is_vlan_dev(netdev))
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002327 phys_dev = vlan_dev_real_dev(netdev);
Bhanu Prakash Gollapudi7adc5a32012-06-04 16:15:44 -07002328
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002329 /* verify if the physical device is a netxtreme2 device */
2330 if (phys_dev->ethtool_ops && phys_dev->ethtool_ops->get_drvinfo) {
2331 memset(&drvinfo, 0, sizeof(drvinfo));
2332 phys_dev->ethtool_ops->get_drvinfo(phys_dev, &drvinfo);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002333 if (strncmp(drvinfo.driver, "bnx2x", strlen("bnx2x"))) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002334 printk(KERN_ERR PFX "Not a netxtreme2 device\n");
2335 rc = -EINVAL;
2336 goto netdev_err;
2337 }
2338 } else {
2339 printk(KERN_ERR PFX "unable to obtain drv_info\n");
2340 rc = -EINVAL;
2341 goto netdev_err;
2342 }
2343
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002344 /* obtain interface and initialize rest of the structure */
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002345 hba = bnx2fc_hba_lookup(phys_dev);
2346 if (!hba) {
2347 rc = -ENODEV;
2348 printk(KERN_ERR PFX "bnx2fc_create: hba not found\n");
2349 goto netdev_err;
2350 }
2351
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002352 if (bnx2fc_interface_lookup(netdev)) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002353 rc = -EEXIST;
2354 goto netdev_err;
2355 }
2356
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002357 interface = bnx2fc_interface_create(hba, netdev, fip_mode);
2358 if (!interface) {
2359 printk(KERN_ERR PFX "bnx2fc_interface_create failed\n");
Dan Carpenter2043e1f2014-11-04 13:37:59 +03002360 rc = -ENOMEM;
Dan Carpenter9ae4f842018-11-01 08:25:30 +03002361 goto netdev_err;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002362 }
2363
Parav Panditd0d7b102017-02-04 11:00:49 -06002364 if (is_vlan_dev(netdev)) {
Bhanu Prakash Gollapudi7adc5a32012-06-04 16:15:44 -07002365 vlan_id = vlan_dev_vlan_id(netdev);
2366 interface->vlan_enabled = 1;
2367 }
2368
Robert Lovefd8f8902012-05-22 19:06:16 -07002369 ctlr = bnx2fc_to_ctlr(interface);
Robert Love01bdcb62013-03-25 11:00:26 -07002370 cdev = fcoe_ctlr_to_ctlr_dev(ctlr);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002371 interface->vlan_id = vlan_id;
Joe Carnuccio10755d32016-04-07 09:07:56 -04002372 interface->tm_timeout = BNX2FC_TM_TIMEOUT;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002373
2374 interface->timer_work_queue =
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002375 create_singlethread_workqueue("bnx2fc_timer_wq");
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002376 if (!interface->timer_work_queue) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002377 printk(KERN_ERR PFX "ulp_init could not create timer_wq\n");
2378 rc = -EINVAL;
2379 goto ifput_err;
2380 }
2381
Robert Love01bdcb62013-03-25 11:00:26 -07002382 lport = bnx2fc_if_create(interface, &cdev->dev, 0);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002383 if (!lport) {
2384 printk(KERN_ERR PFX "Failed to create interface (%s)\n",
2385 netdev->name);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002386 rc = -EINVAL;
2387 goto if_create_err;
2388 }
2389
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002390 /* Add interface to if_list */
2391 list_add_tail(&interface->list, &if_list);
2392
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002393 lport->boot_time = jiffies;
2394
2395 /* Make this master N_port */
Robert Lovefd8f8902012-05-22 19:06:16 -07002396 ctlr->lp = lport;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002397
Robert Love6e89ea32012-11-27 06:53:40 +00002398 if (link_state == BNX2FC_CREATE_LINK_UP)
2399 cdev->enabled = FCOE_CTLR_ENABLED;
2400 else
2401 cdev->enabled = FCOE_CTLR_DISABLED;
2402
2403 if (link_state == BNX2FC_CREATE_LINK_UP &&
2404 !bnx2fc_link_ok(lport)) {
Robert Lovefd8f8902012-05-22 19:06:16 -07002405 fcoe_ctlr_link_up(ctlr);
Bhanu Prakash Gollapudi8a5badf2011-08-30 15:54:48 -07002406 fc_host_port_type(lport->host) = FC_PORTTYPE_NPORT;
2407 set_bit(ADAPTER_STATE_READY, &interface->hba->adapter_state);
2408 }
2409
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002410 BNX2FC_HBA_DBG(lport, "create: START DISC\n");
2411 bnx2fc_start_disc(interface);
Robert Love6e89ea32012-11-27 06:53:40 +00002412
2413 if (link_state == BNX2FC_CREATE_LINK_UP)
2414 interface->enabled = true;
2415
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002416 /*
2417 * Release from kref_init in bnx2fc_interface_setup, on success
2418 * lport should be holding a reference taken in bnx2fc_if_create
2419 */
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002420 bnx2fc_interface_put(interface);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002421 /* put netdev that was held while calling dev_get_by_name */
2422 mutex_unlock(&bnx2fc_dev_lock);
2423 rtnl_unlock();
2424 return 0;
2425
2426if_create_err:
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002427 destroy_workqueue(interface->timer_work_queue);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002428ifput_err:
Bhanu Prakash Gollapudi013068f2011-08-30 15:54:52 -07002429 bnx2fc_net_cleanup(interface);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002430 bnx2fc_interface_put(interface);
Bhanu Prakash Gollapudi7d742f62012-01-23 18:00:48 -08002431 goto mod_err;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002432netdev_err:
2433 module_put(THIS_MODULE);
2434mod_err:
2435 mutex_unlock(&bnx2fc_dev_lock);
2436 rtnl_unlock();
2437 return rc;
2438}
2439
2440/**
Robert Love6e89ea32012-11-27 06:53:40 +00002441 * bnx2fc_create() - Create a bnx2fc interface
2442 * @netdev : The net_device object the Ethernet interface to create on
2443 * @fip_mode: The FIP mode for this creation
2444 *
2445 * Called from fcoe transport
2446 *
2447 * Returns: 0 for success
2448 */
Hannes Reinecke1917d422016-07-04 10:29:19 +02002449static int bnx2fc_create(struct net_device *netdev, enum fip_mode fip_mode)
Robert Love6e89ea32012-11-27 06:53:40 +00002450{
2451 return _bnx2fc_create(netdev, fip_mode, BNX2FC_CREATE_LINK_UP);
2452}
2453
2454/**
2455 * bnx2fc_ctlr_alloc() - Allocate a bnx2fc interface from fcoe_sysfs
2456 * @netdev: The net_device to be used by the allocated FCoE Controller
2457 *
2458 * This routine is called from fcoe_sysfs. It will start the fcoe_ctlr
2459 * in a link_down state. The allows the user an opportunity to configure
2460 * the FCoE Controller from sysfs before enabling the FCoE Controller.
2461 *
2462 * Creating in with this routine starts the FCoE Controller in Fabric
2463 * mode. The user can change to VN2VN or another mode before enabling.
2464 */
2465static int bnx2fc_ctlr_alloc(struct net_device *netdev)
2466{
2467 return _bnx2fc_create(netdev, FIP_MODE_FABRIC,
2468 BNX2FC_CREATE_LINK_DOWN);
2469}
2470
2471/**
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002472 * bnx2fc_find_hba_for_cnic - maps cnic instance to bnx2fc hba instance
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002473 *
2474 * @cnic: Pointer to cnic device instance
2475 *
2476 **/
2477static struct bnx2fc_hba *bnx2fc_find_hba_for_cnic(struct cnic_dev *cnic)
2478{
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002479 struct bnx2fc_hba *hba;
2480
2481 /* Called with bnx2fc_dev_lock held */
Bhanu Prakash Gollapudid71fb3b2012-06-07 02:19:36 -07002482 list_for_each_entry(hba, &adapter_list, list) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002483 if (hba->cnic == cnic)
2484 return hba;
2485 }
2486 return NULL;
2487}
2488
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002489static struct bnx2fc_interface *bnx2fc_interface_lookup(struct net_device
2490 *netdev)
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002491{
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002492 struct bnx2fc_interface *interface;
2493
2494 /* Called with bnx2fc_dev_lock held */
2495 list_for_each_entry(interface, &if_list, list) {
2496 if (interface->netdev == netdev)
2497 return interface;
2498 }
2499 return NULL;
2500}
2501
2502static struct bnx2fc_hba *bnx2fc_hba_lookup(struct net_device
2503 *phys_dev)
2504{
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002505 struct bnx2fc_hba *hba;
2506
2507 /* Called with bnx2fc_dev_lock held */
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002508 list_for_each_entry(hba, &adapter_list, list) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002509 if (hba->phys_dev == phys_dev)
2510 return hba;
2511 }
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002512 printk(KERN_ERR PFX "adapter_lookup: hba NULL\n");
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002513 return NULL;
2514}
2515
2516/**
2517 * bnx2fc_ulp_exit - shuts down adapter instance and frees all resources
2518 *
Lee Jonesca63d8e2020-07-13 08:46:23 +01002519 * @dev: cnic device handle
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002520 */
2521static void bnx2fc_ulp_exit(struct cnic_dev *dev)
2522{
2523 struct bnx2fc_hba *hba;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002524 struct bnx2fc_interface *interface, *tmp;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002525
2526 BNX2FC_MISC_DBG("Entered bnx2fc_ulp_exit\n");
2527
2528 if (!test_bit(CNIC_F_BNX2X_CLASS, &dev->flags)) {
2529 printk(KERN_ERR PFX "bnx2fc port check: %s, flags: %lx\n",
2530 dev->netdev->name, dev->flags);
2531 return;
2532 }
2533
2534 mutex_lock(&bnx2fc_dev_lock);
2535 hba = bnx2fc_find_hba_for_cnic(dev);
2536 if (!hba) {
2537 printk(KERN_ERR PFX "bnx2fc_ulp_exit: hba not found, dev 0%p\n",
2538 dev);
2539 mutex_unlock(&bnx2fc_dev_lock);
2540 return;
2541 }
2542
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002543 list_del_init(&hba->list);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002544 adapter_count--;
2545
Bhanu Prakash Gollapudiabc49a92011-08-04 17:38:42 -07002546 list_for_each_entry_safe(interface, tmp, &if_list, list)
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002547 /* destroy not called yet, move to quiesced list */
Bhanu Prakash Gollapudiabc49a92011-08-04 17:38:42 -07002548 if (interface->hba == hba)
Bhanu Prakash Gollapudieccdcd02011-08-24 18:56:42 -07002549 __bnx2fc_destroy(interface);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002550 mutex_unlock(&bnx2fc_dev_lock);
2551
2552 bnx2fc_ulp_stop(hba);
2553 /* unregister cnic device */
2554 if (test_and_clear_bit(BNX2FC_CNIC_REGISTERED, &hba->reg_with_cnic))
2555 hba->cnic->unregister_device(hba->cnic, CNIC_ULP_FCOE);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002556 bnx2fc_hba_destroy(hba);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002557}
2558
Chad Dupuis5eddc332017-06-26 08:59:37 -07002559static void bnx2fc_rport_terminate_io(struct fc_rport *rport)
2560{
2561 /* This is a no-op */
2562}
2563
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002564/**
2565 * bnx2fc_fcoe_reset - Resets the fcoe
2566 *
2567 * @shost: shost the reset is from
2568 *
2569 * Returns: always 0
2570 */
2571static int bnx2fc_fcoe_reset(struct Scsi_Host *shost)
2572{
2573 struct fc_lport *lport = shost_priv(shost);
2574 fc_lport_reset(lport);
2575 return 0;
2576}
2577
2578
2579static bool bnx2fc_match(struct net_device *netdev)
2580{
Bhanu Prakash Gollapudi7adc5a32012-06-04 16:15:44 -07002581 struct net_device *phys_dev = netdev;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002582
Bhanu Prakash Gollapudi7adc5a32012-06-04 16:15:44 -07002583 mutex_lock(&bnx2fc_dev_lock);
Parav Panditd0d7b102017-02-04 11:00:49 -06002584 if (is_vlan_dev(netdev))
Bhanu Prakash Gollapudi7adc5a32012-06-04 16:15:44 -07002585 phys_dev = vlan_dev_real_dev(netdev);
2586
2587 if (bnx2fc_hba_lookup(phys_dev)) {
2588 mutex_unlock(&bnx2fc_dev_lock);
2589 return true;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002590 }
Bhanu Prakash Gollapudi7adc5a32012-06-04 16:15:44 -07002591
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002592 mutex_unlock(&bnx2fc_dev_lock);
2593 return false;
2594}
2595
2596
2597static struct fcoe_transport bnx2fc_transport = {
2598 .name = {"bnx2fc"},
2599 .attached = false,
2600 .list = LIST_HEAD_INIT(bnx2fc_transport.list),
Robert Love6e89ea32012-11-27 06:53:40 +00002601 .alloc = bnx2fc_ctlr_alloc,
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002602 .match = bnx2fc_match,
2603 .create = bnx2fc_create,
2604 .destroy = bnx2fc_destroy,
2605 .enable = bnx2fc_enable,
2606 .disable = bnx2fc_disable,
2607};
2608
2609/**
Thomas Gleixner1937f8a2017-07-24 12:52:59 +02002610 * bnx2fc_cpu_online - Create a receive thread for an online CPU
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002611 *
2612 * @cpu: cpu index for the online cpu
2613 */
Thomas Gleixner1937f8a2017-07-24 12:52:59 +02002614static int bnx2fc_cpu_online(unsigned int cpu)
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002615{
2616 struct bnx2fc_percpu_s *p;
2617 struct task_struct *thread;
2618
2619 p = &per_cpu(bnx2fc_percpu, cpu);
2620
Eric Dumazet69614272012-06-04 16:15:42 -07002621 thread = kthread_create_on_node(bnx2fc_percpu_io_thread,
2622 (void *)p, cpu_to_node(cpu),
2623 "bnx2fc_thread/%d", cpu);
Thomas Gleixner1937f8a2017-07-24 12:52:59 +02002624 if (IS_ERR(thread))
2625 return PTR_ERR(thread);
2626
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002627 /* bind thread to the cpu */
Thomas Gleixner1937f8a2017-07-24 12:52:59 +02002628 kthread_bind(thread, cpu);
2629 p->iothread = thread;
2630 wake_up_process(thread);
2631 return 0;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002632}
2633
Thomas Gleixner1937f8a2017-07-24 12:52:59 +02002634static int bnx2fc_cpu_offline(unsigned int cpu)
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002635{
2636 struct bnx2fc_percpu_s *p;
2637 struct task_struct *thread;
2638 struct bnx2fc_work *work, *tmp;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002639
2640 BNX2FC_MISC_DBG("destroying io thread for CPU %d\n", cpu);
2641
2642 /* Prevent any new work from being queued for this CPU */
2643 p = &per_cpu(bnx2fc_percpu, cpu);
2644 spin_lock_bh(&p->fp_work_lock);
2645 thread = p->iothread;
2646 p->iothread = NULL;
2647
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002648 /* Free all work in the list */
Bhanu Prakash Gollapudi32248762011-08-04 17:38:36 -07002649 list_for_each_entry_safe(work, tmp, &p->work_list, list) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002650 list_del_init(&work->list);
Javed Hasan77331112020-03-26 22:48:47 -07002651 bnx2fc_process_cq_compl(work->tgt, work->wqe, work->rq_data,
2652 work->num_rq, work->task);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002653 kfree(work);
2654 }
2655
2656 spin_unlock_bh(&p->fp_work_lock);
2657
2658 if (thread)
2659 kthread_stop(thread);
Sebastian Andrzej Siewiorc53b0052016-12-21 20:19:50 +01002660 return 0;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002661}
2662
Joe Carnuccio10755d32016-04-07 09:07:56 -04002663static int bnx2fc_slave_configure(struct scsi_device *sdev)
2664{
2665 if (!bnx2fc_queue_depth)
2666 return 0;
2667
2668 scsi_change_queue_depth(sdev, bnx2fc_queue_depth);
2669 return 0;
2670}
2671
Sebastian Andrzej Siewiorc53b0052016-12-21 20:19:50 +01002672static enum cpuhp_state bnx2fc_online_state;
2673
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002674/**
2675 * bnx2fc_mod_init - module init entry point
2676 *
2677 * Initialize driver wide global data structures, and register
2678 * with cnic module
2679 **/
2680static int __init bnx2fc_mod_init(void)
2681{
2682 struct fcoe_percpu_s *bg;
2683 struct task_struct *l2_thread;
2684 int rc = 0;
2685 unsigned int cpu = 0;
2686 struct bnx2fc_percpu_s *p;
2687
2688 printk(KERN_INFO PFX "%s", version);
2689
2690 /* register as a fcoe transport */
2691 rc = fcoe_transport_attach(&bnx2fc_transport);
2692 if (rc) {
2693 printk(KERN_ERR "failed to register an fcoe transport, check "
2694 "if libfcoe is loaded\n");
2695 goto out;
2696 }
2697
2698 INIT_LIST_HEAD(&adapter_list);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002699 INIT_LIST_HEAD(&if_list);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002700 mutex_init(&bnx2fc_dev_lock);
2701 adapter_count = 0;
2702
2703 /* Attach FC transport template */
2704 rc = bnx2fc_attach_transport();
2705 if (rc)
2706 goto detach_ft;
2707
2708 bnx2fc_wq = alloc_workqueue("bnx2fc", 0, 0);
2709 if (!bnx2fc_wq) {
2710 rc = -ENOMEM;
2711 goto release_bt;
2712 }
2713
2714 bg = &bnx2fc_global;
2715 skb_queue_head_init(&bg->fcoe_rx_list);
2716 l2_thread = kthread_create(bnx2fc_l2_rcv_thread,
2717 (void *)bg,
2718 "bnx2fc_l2_thread");
2719 if (IS_ERR(l2_thread)) {
2720 rc = PTR_ERR(l2_thread);
2721 goto free_wq;
2722 }
2723 wake_up_process(l2_thread);
2724 spin_lock_bh(&bg->fcoe_rx_list.lock);
Sebastian Andrzej Siewior4b9bc862016-04-12 17:16:54 +02002725 bg->kthread = l2_thread;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002726 spin_unlock_bh(&bg->fcoe_rx_list.lock);
2727
2728 for_each_possible_cpu(cpu) {
2729 p = &per_cpu(bnx2fc_percpu, cpu);
2730 INIT_LIST_HEAD(&p->work_list);
2731 spin_lock_init(&p->fp_work_lock);
2732 }
2733
Thomas Gleixner1937f8a2017-07-24 12:52:59 +02002734 rc = cpuhp_setup_state(CPUHP_AP_ONLINE_DYN, "scsi/bnx2fc:online",
2735 bnx2fc_cpu_online, bnx2fc_cpu_offline);
Sebastian Andrzej Siewiorc53b0052016-12-21 20:19:50 +01002736 if (rc < 0)
Thomas Gleixner1937f8a2017-07-24 12:52:59 +02002737 goto stop_thread;
Sebastian Andrzej Siewiorc53b0052016-12-21 20:19:50 +01002738 bnx2fc_online_state = rc;
Srivatsa S. Bhat7229b6d2014-03-11 02:09:45 +05302739
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002740 cnic_register_driver(CNIC_ULP_FCOE, &bnx2fc_cnic_cb);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002741 return 0;
2742
Thomas Gleixner1937f8a2017-07-24 12:52:59 +02002743stop_thread:
Sebastian Andrzej Siewiorc53b0052016-12-21 20:19:50 +01002744 kthread_stop(l2_thread);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002745free_wq:
2746 destroy_workqueue(bnx2fc_wq);
2747release_bt:
2748 bnx2fc_release_transport();
2749detach_ft:
2750 fcoe_transport_detach(&bnx2fc_transport);
2751out:
2752 return rc;
2753}
2754
2755static void __exit bnx2fc_mod_exit(void)
2756{
2757 LIST_HEAD(to_be_deleted);
2758 struct bnx2fc_hba *hba, *next;
2759 struct fcoe_percpu_s *bg;
2760 struct task_struct *l2_thread;
2761 struct sk_buff *skb;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002762
2763 /*
2764 * NOTE: Since cnic calls register_driver routine rtnl_lock,
2765 * it will have higher precedence than bnx2fc_dev_lock.
2766 * unregister_device() cannot be called with bnx2fc_dev_lock
2767 * held.
2768 */
2769 mutex_lock(&bnx2fc_dev_lock);
Christophe JAILLET393c8012016-09-03 09:05:48 +02002770 list_splice_init(&adapter_list, &to_be_deleted);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002771 adapter_count = 0;
2772 mutex_unlock(&bnx2fc_dev_lock);
2773
2774 /* Unregister with cnic */
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002775 list_for_each_entry_safe(hba, next, &to_be_deleted, list) {
2776 list_del_init(&hba->list);
2777 printk(KERN_ERR PFX "MOD_EXIT:destroy hba = 0x%p\n",
2778 hba);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002779 bnx2fc_ulp_stop(hba);
2780 /* unregister cnic device */
2781 if (test_and_clear_bit(BNX2FC_CNIC_REGISTERED,
2782 &hba->reg_with_cnic))
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002783 hba->cnic->unregister_device(hba->cnic,
2784 CNIC_ULP_FCOE);
2785 bnx2fc_hba_destroy(hba);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002786 }
2787 cnic_unregister_driver(CNIC_ULP_FCOE);
2788
2789 /* Destroy global thread */
2790 bg = &bnx2fc_global;
2791 spin_lock_bh(&bg->fcoe_rx_list.lock);
Sebastian Andrzej Siewior4b9bc862016-04-12 17:16:54 +02002792 l2_thread = bg->kthread;
2793 bg->kthread = NULL;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002794 while ((skb = __skb_dequeue(&bg->fcoe_rx_list)) != NULL)
2795 kfree_skb(skb);
2796
2797 spin_unlock_bh(&bg->fcoe_rx_list.lock);
2798
2799 if (l2_thread)
2800 kthread_stop(l2_thread);
2801
Thomas Gleixner1937f8a2017-07-24 12:52:59 +02002802 cpuhp_remove_state(bnx2fc_online_state);
Srivatsa S. Bhat7229b6d2014-03-11 02:09:45 +05302803
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002804 destroy_workqueue(bnx2fc_wq);
2805 /*
2806 * detach from scsi transport
2807 * must happen after all destroys are done
2808 */
2809 bnx2fc_release_transport();
2810
2811 /* detach from fcoe transport */
2812 fcoe_transport_detach(&bnx2fc_transport);
2813}
2814
2815module_init(bnx2fc_mod_init);
2816module_exit(bnx2fc_mod_exit);
2817
Robert Love8d55e502012-05-22 19:06:26 -07002818static struct fcoe_sysfs_function_template bnx2fc_fcoe_sysfs_templ = {
Robert Love6e89ea32012-11-27 06:53:40 +00002819 .set_fcoe_ctlr_enabled = bnx2fc_ctlr_enabled,
Yi Zoub8b3e692012-12-06 06:24:59 +00002820 .get_fcoe_ctlr_link_fail = fcoe_ctlr_get_lesb,
2821 .get_fcoe_ctlr_vlink_fail = fcoe_ctlr_get_lesb,
2822 .get_fcoe_ctlr_miss_fka = fcoe_ctlr_get_lesb,
2823 .get_fcoe_ctlr_symb_err = fcoe_ctlr_get_lesb,
2824 .get_fcoe_ctlr_err_block = fcoe_ctlr_get_lesb,
2825 .get_fcoe_ctlr_fcs_error = fcoe_ctlr_get_lesb,
Robert Love8d55e502012-05-22 19:06:26 -07002826
2827 .get_fcoe_fcf_selected = fcoe_fcf_get_selected,
2828 .get_fcoe_fcf_vlan_id = bnx2fc_fcf_get_vlan_id,
2829};
2830
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002831static struct fc_function_template bnx2fc_transport_function = {
2832 .show_host_node_name = 1,
2833 .show_host_port_name = 1,
2834 .show_host_supported_classes = 1,
2835 .show_host_supported_fc4s = 1,
2836 .show_host_active_fc4s = 1,
2837 .show_host_maxframe_size = 1,
2838
2839 .show_host_port_id = 1,
2840 .show_host_supported_speeds = 1,
2841 .get_host_speed = fc_get_host_speed,
2842 .show_host_speed = 1,
2843 .show_host_port_type = 1,
2844 .get_host_port_state = fc_get_host_port_state,
2845 .show_host_port_state = 1,
2846 .show_host_symbolic_name = 1,
2847
2848 .dd_fcrport_size = (sizeof(struct fc_rport_libfc_priv) +
2849 sizeof(struct bnx2fc_rport)),
2850 .show_rport_maxframe_size = 1,
2851 .show_rport_supported_classes = 1,
2852
2853 .show_host_fabric_name = 1,
2854 .show_starget_node_name = 1,
2855 .show_starget_port_name = 1,
2856 .show_starget_port_id = 1,
2857 .set_rport_dev_loss_tmo = fc_set_rport_loss_tmo,
2858 .show_rport_dev_loss_tmo = 1,
2859 .get_fc_host_stats = bnx2fc_get_host_stats,
2860
2861 .issue_fc_host_lip = bnx2fc_fcoe_reset,
2862
Chad Dupuis5eddc332017-06-26 08:59:37 -07002863 .terminate_rport_io = bnx2fc_rport_terminate_io,
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002864
2865 .vport_create = bnx2fc_vport_create,
2866 .vport_delete = bnx2fc_vport_destroy,
2867 .vport_disable = bnx2fc_vport_disable,
Bhanu Prakash Gollapudie9a5289c2011-08-04 17:38:37 -07002868 .bsg_request = fc_lport_bsg_request,
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002869};
2870
2871static struct fc_function_template bnx2fc_vport_xport_function = {
2872 .show_host_node_name = 1,
2873 .show_host_port_name = 1,
2874 .show_host_supported_classes = 1,
2875 .show_host_supported_fc4s = 1,
2876 .show_host_active_fc4s = 1,
2877 .show_host_maxframe_size = 1,
2878
2879 .show_host_port_id = 1,
2880 .show_host_supported_speeds = 1,
2881 .get_host_speed = fc_get_host_speed,
2882 .show_host_speed = 1,
2883 .show_host_port_type = 1,
2884 .get_host_port_state = fc_get_host_port_state,
2885 .show_host_port_state = 1,
2886 .show_host_symbolic_name = 1,
2887
2888 .dd_fcrport_size = (sizeof(struct fc_rport_libfc_priv) +
2889 sizeof(struct bnx2fc_rport)),
2890 .show_rport_maxframe_size = 1,
2891 .show_rport_supported_classes = 1,
2892
2893 .show_host_fabric_name = 1,
2894 .show_starget_node_name = 1,
2895 .show_starget_port_name = 1,
2896 .show_starget_port_id = 1,
2897 .set_rport_dev_loss_tmo = fc_set_rport_loss_tmo,
2898 .show_rport_dev_loss_tmo = 1,
2899 .get_fc_host_stats = fc_get_host_stats,
2900 .issue_fc_host_lip = bnx2fc_fcoe_reset,
2901 .terminate_rport_io = fc_rport_terminate_io,
Bhanu Prakash Gollapudie9a5289c2011-08-04 17:38:37 -07002902 .bsg_request = fc_lport_bsg_request,
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002903};
2904
Joe Carnuccio10755d32016-04-07 09:07:56 -04002905/*
2906 * Additional scsi_host attributes.
2907 */
2908static ssize_t
2909bnx2fc_tm_timeout_show(struct device *dev, struct device_attribute *attr,
2910 char *buf)
2911{
2912 struct Scsi_Host *shost = class_to_shost(dev);
2913 struct fc_lport *lport = shost_priv(shost);
2914 struct fcoe_port *port = lport_priv(lport);
2915 struct bnx2fc_interface *interface = port->priv;
2916
2917 sprintf(buf, "%u\n", interface->tm_timeout);
2918 return strlen(buf);
2919}
2920
2921static ssize_t
2922bnx2fc_tm_timeout_store(struct device *dev,
2923 struct device_attribute *attr, const char *buf, size_t count)
2924{
2925 struct Scsi_Host *shost = class_to_shost(dev);
2926 struct fc_lport *lport = shost_priv(shost);
2927 struct fcoe_port *port = lport_priv(lport);
2928 struct bnx2fc_interface *interface = port->priv;
2929 int rval, val;
2930
2931 rval = kstrtouint(buf, 10, &val);
2932 if (rval)
2933 return rval;
2934 if (val > 255)
2935 return -ERANGE;
2936
2937 interface->tm_timeout = (u8)val;
2938 return strlen(buf);
2939}
2940
2941static DEVICE_ATTR(tm_timeout, S_IRUGO|S_IWUSR, bnx2fc_tm_timeout_show,
2942 bnx2fc_tm_timeout_store);
2943
Bart Van Asschec3dd11d2021-10-12 16:35:27 -07002944static struct attribute *bnx2fc_host_attrs[] = {
2945 &dev_attr_tm_timeout.attr,
Joe Carnuccio10755d32016-04-07 09:07:56 -04002946 NULL,
2947};
2948
Bart Van Asschec3dd11d2021-10-12 16:35:27 -07002949ATTRIBUTE_GROUPS(bnx2fc_host);
2950
Lee Jonesca63d8e2020-07-13 08:46:23 +01002951/*
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002952 * scsi_host_template structure used while registering with SCSI-ml
2953 */
2954static struct scsi_host_template bnx2fc_shost_template = {
2955 .module = THIS_MODULE,
Saurav Kashyap17d87c42014-07-03 08:18:28 -04002956 .name = "QLogic Offload FCoE Initiator",
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002957 .queuecommand = bnx2fc_queuecommand,
Christoph Hellwigb6a05c82017-01-30 13:18:58 +01002958 .eh_timed_out = fc_eh_timed_out,
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002959 .eh_abort_handler = bnx2fc_eh_abort, /* abts */
2960 .eh_device_reset_handler = bnx2fc_eh_device_reset, /* lun reset */
2961 .eh_target_reset_handler = bnx2fc_eh_target_reset, /* tgt reset */
2962 .eh_host_reset_handler = fc_eh_host_reset,
2963 .slave_alloc = fc_slave_alloc,
Christoph Hellwigdb5ed4d2014-11-13 15:08:42 +01002964 .change_queue_depth = scsi_change_queue_depth,
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002965 .this_id = -1,
2966 .cmd_per_lun = 3,
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002967 .sg_tablesize = BNX2FC_MAX_BDS_PER_CMD,
Saurav Kashyap3c97b562019-06-24 01:29:59 -07002968 .dma_boundary = 0x7fff,
2969 .max_sectors = 0x3fbf,
Christoph Hellwigc40ecc12014-11-13 14:25:11 +01002970 .track_queue_depth = 1,
Joe Carnuccio10755d32016-04-07 09:07:56 -04002971 .slave_configure = bnx2fc_slave_configure,
Bart Van Asschec3dd11d2021-10-12 16:35:27 -07002972 .shost_groups = bnx2fc_host_groups,
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002973};
2974
2975static struct libfc_function_template bnx2fc_libfc_fcn_templ = {
2976 .frame_send = bnx2fc_xmit,
2977 .elsct_send = bnx2fc_elsct_send,
2978 .fcp_abort_io = bnx2fc_abort_io,
2979 .fcp_cleanup = bnx2fc_cleanup,
Yi Zoub8b3e692012-12-06 06:24:59 +00002980 .get_lesb = fcoe_get_lesb,
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002981 .rport_event_callback = bnx2fc_rport_event_handler,
2982};
2983
Lee Jonesca63d8e2020-07-13 08:46:23 +01002984/*
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002985 * bnx2fc_cnic_cb - global template of bnx2fc - cnic driver interface
2986 * structure carrying callback function pointers
2987 */
2988static struct cnic_ulp_ops bnx2fc_cnic_cb = {
2989 .owner = THIS_MODULE,
2990 .cnic_init = bnx2fc_ulp_init,
2991 .cnic_exit = bnx2fc_ulp_exit,
2992 .cnic_start = bnx2fc_ulp_start,
2993 .cnic_stop = bnx2fc_ulp_stop,
2994 .indicate_kcqes = bnx2fc_indicate_kcqe,
2995 .indicate_netevent = bnx2fc_indicate_netevent,
Barak Witkowski2e499d32012-06-26 01:31:19 +00002996 .cnic_get_stats = bnx2fc_ulp_get_stats,
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002997};