blob: cc4791cf575b30f1e716c04339cb6fc007cd20a5 [file] [log] [blame]
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001/* bnx2fc_fcoe.c: Broadcom NetXtreme II Linux FCoE offload driver.
2 * This file contains the code that interacts with libfc, libfcoe,
3 * cnic modules to create FCoE instances, send/receive non-offloaded
4 * FIP/FCoE packets, listen to link events etc.
5 *
Bhanu Prakash Gollapudi9b35baa2011-07-27 11:32:13 -07006 * Copyright (c) 2008 - 2011 Broadcom Corporation
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08007 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation.
11 *
12 * Written by: Bhanu Prakash Gollapudi (bprakash@broadcom.com)
13 */
14
15#include "bnx2fc.h"
16
17static struct list_head adapter_list;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -070018static struct list_head if_list;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -080019static u32 adapter_count;
20static DEFINE_MUTEX(bnx2fc_dev_lock);
21DEFINE_PER_CPU(struct bnx2fc_percpu_s, bnx2fc_percpu);
22
23#define DRV_MODULE_NAME "bnx2fc"
24#define DRV_MODULE_VERSION BNX2FC_VERSION
Bhanu Prakash Gollapudi2b82d822012-12-21 19:40:34 -080025#define DRV_MODULE_RELDATE "Dec 21, 2012"
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -080026
27
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080028static char version[] =
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -080029 "Broadcom NetXtreme II FCoE Driver " DRV_MODULE_NAME \
30 " v" DRV_MODULE_VERSION " (" DRV_MODULE_RELDATE ")\n";
31
32
33MODULE_AUTHOR("Bhanu Prakash Gollapudi <bprakash@broadcom.com>");
34MODULE_DESCRIPTION("Broadcom NetXtreme II BCM57710 FCoE Driver");
35MODULE_LICENSE("GPL");
36MODULE_VERSION(DRV_MODULE_VERSION);
37
38#define BNX2FC_MAX_QUEUE_DEPTH 256
39#define BNX2FC_MIN_QUEUE_DEPTH 32
40#define FCOE_WORD_TO_BYTE 4
41
42static struct scsi_transport_template *bnx2fc_transport_template;
43static struct scsi_transport_template *bnx2fc_vport_xport_template;
44
45struct workqueue_struct *bnx2fc_wq;
46
47/* bnx2fc structure needs only one instance of the fcoe_percpu_s structure.
48 * Here the io threads are per cpu but the l2 thread is just one
49 */
50struct fcoe_percpu_s bnx2fc_global;
51DEFINE_SPINLOCK(bnx2fc_global_lock);
52
53static struct cnic_ulp_ops bnx2fc_cnic_cb;
54static struct libfc_function_template bnx2fc_libfc_fcn_templ;
55static struct scsi_host_template bnx2fc_shost_template;
56static struct fc_function_template bnx2fc_transport_function;
Robert Love8d55e502012-05-22 19:06:26 -070057static struct fcoe_sysfs_function_template bnx2fc_fcoe_sysfs_templ;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -080058static struct fc_function_template bnx2fc_vport_xport_function;
59static int bnx2fc_create(struct net_device *netdev, enum fip_state fip_mode);
Bhanu Prakash Gollapudieccdcd02011-08-24 18:56:42 -070060static void __bnx2fc_destroy(struct bnx2fc_interface *interface);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -080061static int bnx2fc_destroy(struct net_device *net_device);
62static int bnx2fc_enable(struct net_device *netdev);
63static int bnx2fc_disable(struct net_device *netdev);
64
Robert Love6e89ea32012-11-27 06:53:40 +000065/* fcoe_syfs control interface handlers */
66static int bnx2fc_ctlr_alloc(struct net_device *netdev);
67static int bnx2fc_ctlr_enabled(struct fcoe_ctlr_device *cdev);
68
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -080069static void bnx2fc_recv_frame(struct sk_buff *skb);
70
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -070071static void bnx2fc_start_disc(struct bnx2fc_interface *interface);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -080072static int bnx2fc_shost_config(struct fc_lport *lport, struct device *dev);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -080073static int bnx2fc_lport_config(struct fc_lport *lport);
74static int bnx2fc_em_config(struct fc_lport *lport);
75static int bnx2fc_bind_adapter_devices(struct bnx2fc_hba *hba);
76static void bnx2fc_unbind_adapter_devices(struct bnx2fc_hba *hba);
77static int bnx2fc_bind_pcidev(struct bnx2fc_hba *hba);
78static void bnx2fc_unbind_pcidev(struct bnx2fc_hba *hba);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -070079static struct fc_lport *bnx2fc_if_create(struct bnx2fc_interface *interface,
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -080080 struct device *parent, int npiv);
81static void bnx2fc_destroy_work(struct work_struct *work);
82
83static struct bnx2fc_hba *bnx2fc_hba_lookup(struct net_device *phys_dev);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -070084static struct bnx2fc_interface *bnx2fc_interface_lookup(struct net_device
85 *phys_dev);
Bhanu Prakash Gollapudiabc49a92011-08-04 17:38:42 -070086static inline void bnx2fc_interface_put(struct bnx2fc_interface *interface);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -080087static struct bnx2fc_hba *bnx2fc_find_hba_for_cnic(struct cnic_dev *cnic);
88
89static int bnx2fc_fw_init(struct bnx2fc_hba *hba);
90static void bnx2fc_fw_destroy(struct bnx2fc_hba *hba);
91
92static void bnx2fc_port_shutdown(struct fc_lport *lport);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -070093static void bnx2fc_stop(struct bnx2fc_interface *interface);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -080094static int __init bnx2fc_mod_init(void);
95static void __exit bnx2fc_mod_exit(void);
96
97unsigned int bnx2fc_debug_level;
98module_param_named(debug_logging, bnx2fc_debug_level, int, S_IRUGO|S_IWUSR);
99
100static int bnx2fc_cpu_callback(struct notifier_block *nfb,
101 unsigned long action, void *hcpu);
102/* notification function for CPU hotplug events */
103static struct notifier_block bnx2fc_cpu_notifier = {
104 .notifier_call = bnx2fc_cpu_callback,
105};
106
Bhanu Prakash Gollapudif72f6972011-10-03 16:45:02 -0700107static inline struct net_device *bnx2fc_netdev(const struct fc_lport *lport)
108{
109 return ((struct bnx2fc_interface *)
110 ((struct fcoe_port *)lport_priv(lport))->priv)->netdev;
111}
112
Robert Love8d55e502012-05-22 19:06:26 -0700113static void bnx2fc_fcf_get_vlan_id(struct fcoe_fcf_device *fcf_dev)
114{
115 struct fcoe_ctlr_device *ctlr_dev =
116 fcoe_fcf_dev_to_ctlr_dev(fcf_dev);
117 struct fcoe_ctlr *ctlr = fcoe_ctlr_device_priv(ctlr_dev);
118 struct bnx2fc_interface *fcoe = fcoe_ctlr_priv(ctlr);
119
120 fcf_dev->vlan_id = fcoe->vlan_id;
121}
122
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800123static void bnx2fc_clean_rx_queue(struct fc_lport *lp)
124{
125 struct fcoe_percpu_s *bg;
126 struct fcoe_rcv_info *fr;
127 struct sk_buff_head *list;
128 struct sk_buff *skb, *next;
129 struct sk_buff *head;
130
131 bg = &bnx2fc_global;
132 spin_lock_bh(&bg->fcoe_rx_list.lock);
133 list = &bg->fcoe_rx_list;
134 head = list->next;
135 for (skb = head; skb != (struct sk_buff *)list;
136 skb = next) {
137 next = skb->next;
138 fr = fcoe_dev_from_skb(skb);
139 if (fr->fr_dev == lp) {
140 __skb_unlink(skb, list);
141 kfree_skb(skb);
142 }
143 }
144 spin_unlock_bh(&bg->fcoe_rx_list.lock);
145}
146
147int bnx2fc_get_paged_crc_eof(struct sk_buff *skb, int tlen)
148{
149 int rc;
150 spin_lock(&bnx2fc_global_lock);
151 rc = fcoe_get_paged_crc_eof(skb, tlen, &bnx2fc_global);
152 spin_unlock(&bnx2fc_global_lock);
153
154 return rc;
155}
156
157static void bnx2fc_abort_io(struct fc_lport *lport)
158{
159 /*
160 * This function is no-op for bnx2fc, but we do
161 * not want to leave it as NULL either, as libfc
162 * can call the default function which is
163 * fc_fcp_abort_io.
164 */
165}
166
167static void bnx2fc_cleanup(struct fc_lport *lport)
168{
169 struct fcoe_port *port = lport_priv(lport);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700170 struct bnx2fc_interface *interface = port->priv;
171 struct bnx2fc_hba *hba = interface->hba;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800172 struct bnx2fc_rport *tgt;
173 int i;
174
175 BNX2FC_MISC_DBG("Entered %s\n", __func__);
176 mutex_lock(&hba->hba_mutex);
177 spin_lock_bh(&hba->hba_lock);
178 for (i = 0; i < BNX2FC_NUM_MAX_SESS; i++) {
179 tgt = hba->tgt_ofld_list[i];
180 if (tgt) {
181 /* Cleanup IOs belonging to requested vport */
182 if (tgt->port == port) {
183 spin_unlock_bh(&hba->hba_lock);
184 BNX2FC_TGT_DBG(tgt, "flush/cleanup\n");
185 bnx2fc_flush_active_ios(tgt);
186 spin_lock_bh(&hba->hba_lock);
187 }
188 }
189 }
190 spin_unlock_bh(&hba->hba_lock);
191 mutex_unlock(&hba->hba_mutex);
192}
193
194static int bnx2fc_xmit_l2_frame(struct bnx2fc_rport *tgt,
195 struct fc_frame *fp)
196{
197 struct fc_rport_priv *rdata = tgt->rdata;
198 struct fc_frame_header *fh;
199 int rc = 0;
200
201 fh = fc_frame_header_get(fp);
202 BNX2FC_TGT_DBG(tgt, "Xmit L2 frame rport = 0x%x, oxid = 0x%x, "
203 "r_ctl = 0x%x\n", rdata->ids.port_id,
204 ntohs(fh->fh_ox_id), fh->fh_r_ctl);
205 if ((fh->fh_type == FC_TYPE_ELS) &&
206 (fh->fh_r_ctl == FC_RCTL_ELS_REQ)) {
207
208 switch (fc_frame_payload_op(fp)) {
209 case ELS_ADISC:
210 rc = bnx2fc_send_adisc(tgt, fp);
211 break;
212 case ELS_LOGO:
213 rc = bnx2fc_send_logo(tgt, fp);
214 break;
215 case ELS_RLS:
216 rc = bnx2fc_send_rls(tgt, fp);
217 break;
218 default:
219 break;
220 }
221 } else if ((fh->fh_type == FC_TYPE_BLS) &&
222 (fh->fh_r_ctl == FC_RCTL_BA_ABTS))
223 BNX2FC_TGT_DBG(tgt, "ABTS frame\n");
224 else {
225 BNX2FC_TGT_DBG(tgt, "Send L2 frame type 0x%x "
226 "rctl 0x%x thru non-offload path\n",
227 fh->fh_type, fh->fh_r_ctl);
228 return -ENODEV;
229 }
230 if (rc)
231 return -ENOMEM;
232 else
233 return 0;
234}
235
236/**
237 * bnx2fc_xmit - bnx2fc's FCoE frame transmit function
238 *
239 * @lport: the associated local port
240 * @fp: the fc_frame to be transmitted
241 */
242static int bnx2fc_xmit(struct fc_lport *lport, struct fc_frame *fp)
243{
244 struct ethhdr *eh;
245 struct fcoe_crc_eof *cp;
246 struct sk_buff *skb;
247 struct fc_frame_header *fh;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700248 struct bnx2fc_interface *interface;
Robert Lovefd8f8902012-05-22 19:06:16 -0700249 struct fcoe_ctlr *ctlr;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700250 struct bnx2fc_hba *hba;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800251 struct fcoe_port *port;
252 struct fcoe_hdr *hp;
253 struct bnx2fc_rport *tgt;
Vasu Dev1bd49b42012-05-25 10:26:43 -0700254 struct fc_stats *stats;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800255 u8 sof, eof;
256 u32 crc;
257 unsigned int hlen, tlen, elen;
258 int wlen, rc = 0;
259
260 port = (struct fcoe_port *)lport_priv(lport);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700261 interface = port->priv;
Robert Lovefd8f8902012-05-22 19:06:16 -0700262 ctlr = bnx2fc_to_ctlr(interface);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700263 hba = interface->hba;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800264
265 fh = fc_frame_header_get(fp);
266
267 skb = fp_skb(fp);
268 if (!lport->link_up) {
269 BNX2FC_HBA_DBG(lport, "bnx2fc_xmit link down\n");
270 kfree_skb(skb);
271 return 0;
272 }
273
274 if (unlikely(fh->fh_r_ctl == FC_RCTL_ELS_REQ)) {
Robert Lovefd8f8902012-05-22 19:06:16 -0700275 if (!ctlr->sel_fcf) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800276 BNX2FC_HBA_DBG(lport, "FCF not selected yet!\n");
277 kfree_skb(skb);
278 return -EINVAL;
279 }
Robert Lovefd8f8902012-05-22 19:06:16 -0700280 if (fcoe_ctlr_els_send(ctlr, lport, skb))
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800281 return 0;
282 }
283
284 sof = fr_sof(fp);
285 eof = fr_eof(fp);
286
287 /*
288 * Snoop the frame header to check if the frame is for
289 * an offloaded session
290 */
291 /*
292 * tgt_ofld_list access is synchronized using
293 * both hba mutex and hba lock. Atleast hba mutex or
294 * hba lock needs to be held for read access.
295 */
296
297 spin_lock_bh(&hba->hba_lock);
298 tgt = bnx2fc_tgt_lookup(port, ntoh24(fh->fh_d_id));
299 if (tgt && (test_bit(BNX2FC_FLAG_SESSION_READY, &tgt->flags))) {
300 /* This frame is for offloaded session */
301 BNX2FC_HBA_DBG(lport, "xmit: Frame is for offloaded session "
302 "port_id = 0x%x\n", ntoh24(fh->fh_d_id));
303 spin_unlock_bh(&hba->hba_lock);
304 rc = bnx2fc_xmit_l2_frame(tgt, fp);
305 if (rc != -ENODEV) {
306 kfree_skb(skb);
307 return rc;
308 }
309 } else {
310 spin_unlock_bh(&hba->hba_lock);
311 }
312
313 elen = sizeof(struct ethhdr);
314 hlen = sizeof(struct fcoe_hdr);
315 tlen = sizeof(struct fcoe_crc_eof);
316 wlen = (skb->len - tlen + sizeof(crc)) / FCOE_WORD_TO_BYTE;
317
318 skb->ip_summed = CHECKSUM_NONE;
319 crc = fcoe_fc_crc(fp);
320
321 /* copy port crc and eof to the skb buff */
322 if (skb_is_nonlinear(skb)) {
323 skb_frag_t *frag;
324 if (bnx2fc_get_paged_crc_eof(skb, tlen)) {
325 kfree_skb(skb);
326 return -ENOMEM;
327 }
328 frag = &skb_shinfo(skb)->frags[skb_shinfo(skb)->nr_frags - 1];
Cong Wang77dfce02011-11-25 23:14:23 +0800329 cp = kmap_atomic(skb_frag_page(frag)) + frag->page_offset;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800330 } else {
331 cp = (struct fcoe_crc_eof *)skb_put(skb, tlen);
332 }
333
334 memset(cp, 0, sizeof(*cp));
335 cp->fcoe_eof = eof;
336 cp->fcoe_crc32 = cpu_to_le32(~crc);
337 if (skb_is_nonlinear(skb)) {
Cong Wang77dfce02011-11-25 23:14:23 +0800338 kunmap_atomic(cp);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800339 cp = NULL;
340 }
341
342 /* adjust skb network/transport offsets to match mac/fcoe/port */
343 skb_push(skb, elen + hlen);
344 skb_reset_mac_header(skb);
345 skb_reset_network_header(skb);
346 skb->mac_len = elen;
347 skb->protocol = htons(ETH_P_FCOE);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700348 skb->dev = interface->netdev;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800349
350 /* fill up mac and fcoe headers */
351 eh = eth_hdr(skb);
352 eh->h_proto = htons(ETH_P_FCOE);
Robert Lovefd8f8902012-05-22 19:06:16 -0700353 if (ctlr->map_dest)
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800354 fc_fcoe_set_mac(eh->h_dest, fh->fh_d_id);
355 else
356 /* insert GW address */
Robert Lovefd8f8902012-05-22 19:06:16 -0700357 memcpy(eh->h_dest, ctlr->dest_addr, ETH_ALEN);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800358
Robert Lovefd8f8902012-05-22 19:06:16 -0700359 if (unlikely(ctlr->flogi_oxid != FC_XID_UNKNOWN))
360 memcpy(eh->h_source, ctlr->ctl_src_addr, ETH_ALEN);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800361 else
362 memcpy(eh->h_source, port->data_src_addr, ETH_ALEN);
363
364 hp = (struct fcoe_hdr *)(eh + 1);
365 memset(hp, 0, sizeof(*hp));
366 if (FC_FCOE_VER)
367 FC_FCOE_ENCAPS_VER(hp, FC_FCOE_VER);
368 hp->fcoe_sof = sof;
369
370 /* fcoe lso, mss is in max_payload which is non-zero for FCP data */
371 if (lport->seq_offload && fr_max_payload(fp)) {
372 skb_shinfo(skb)->gso_type = SKB_GSO_FCOE;
373 skb_shinfo(skb)->gso_size = fr_max_payload(fp);
374 } else {
375 skb_shinfo(skb)->gso_type = 0;
376 skb_shinfo(skb)->gso_size = 0;
377 }
378
379 /*update tx stats */
Vasu Dev1bd49b42012-05-25 10:26:43 -0700380 stats = per_cpu_ptr(lport->stats, get_cpu());
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800381 stats->TxFrames++;
382 stats->TxWords += wlen;
383 put_cpu();
384
385 /* send down to lld */
386 fr_dev(fp) = lport;
387 if (port->fcoe_pending_queue.qlen)
388 fcoe_check_wait_queue(lport, skb);
389 else if (fcoe_start_io(skb))
390 fcoe_check_wait_queue(lport, skb);
391
392 return 0;
393}
394
395/**
396 * bnx2fc_rcv - This is bnx2fc's receive function called by NET_RX_SOFTIRQ
397 *
398 * @skb: the receive socket buffer
399 * @dev: associated net device
400 * @ptype: context
401 * @olddev: last device
402 *
403 * This function receives the packet and builds FC frame and passes it up
404 */
405static int bnx2fc_rcv(struct sk_buff *skb, struct net_device *dev,
406 struct packet_type *ptype, struct net_device *olddev)
407{
408 struct fc_lport *lport;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700409 struct bnx2fc_interface *interface;
Robert Lovefd8f8902012-05-22 19:06:16 -0700410 struct fcoe_ctlr *ctlr;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800411 struct fc_frame_header *fh;
412 struct fcoe_rcv_info *fr;
413 struct fcoe_percpu_s *bg;
414 unsigned short oxid;
415
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700416 interface = container_of(ptype, struct bnx2fc_interface,
417 fcoe_packet_type);
Robert Lovefd8f8902012-05-22 19:06:16 -0700418 ctlr = bnx2fc_to_ctlr(interface);
419 lport = ctlr->lp;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800420
421 if (unlikely(lport == NULL)) {
Bhanu Prakash Gollapudib2a554f2011-06-27 23:30:53 -0700422 printk(KERN_ERR PFX "bnx2fc_rcv: lport is NULL\n");
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800423 goto err;
424 }
425
426 if (unlikely(eth_hdr(skb)->h_proto != htons(ETH_P_FCOE))) {
Bhanu Prakash Gollapudib2a554f2011-06-27 23:30:53 -0700427 printk(KERN_ERR PFX "bnx2fc_rcv: Wrong FC type frame\n");
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800428 goto err;
429 }
430
431 /*
432 * Check for minimum frame length, and make sure required FCoE
433 * and FC headers are pulled into the linear data area.
434 */
435 if (unlikely((skb->len < FCOE_MIN_FRAME) ||
436 !pskb_may_pull(skb, FCOE_HEADER_LEN)))
437 goto err;
438
439 skb_set_transport_header(skb, sizeof(struct fcoe_hdr));
440 fh = (struct fc_frame_header *) skb_transport_header(skb);
441
442 oxid = ntohs(fh->fh_ox_id);
443
444 fr = fcoe_dev_from_skb(skb);
445 fr->fr_dev = lport;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800446
447 bg = &bnx2fc_global;
Neil Hormanfc05ab72012-03-09 14:50:13 -0800448 spin_lock(&bg->fcoe_rx_list.lock);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800449
450 __skb_queue_tail(&bg->fcoe_rx_list, skb);
451 if (bg->fcoe_rx_list.qlen == 1)
452 wake_up_process(bg->thread);
453
Neil Hormanfc05ab72012-03-09 14:50:13 -0800454 spin_unlock(&bg->fcoe_rx_list.lock);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800455
456 return 0;
457err:
458 kfree_skb(skb);
459 return -1;
460}
461
462static int bnx2fc_l2_rcv_thread(void *arg)
463{
464 struct fcoe_percpu_s *bg = arg;
465 struct sk_buff *skb;
466
467 set_user_nice(current, -20);
468 set_current_state(TASK_INTERRUPTIBLE);
469 while (!kthread_should_stop()) {
470 schedule();
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800471 spin_lock_bh(&bg->fcoe_rx_list.lock);
472 while ((skb = __skb_dequeue(&bg->fcoe_rx_list)) != NULL) {
473 spin_unlock_bh(&bg->fcoe_rx_list.lock);
474 bnx2fc_recv_frame(skb);
475 spin_lock_bh(&bg->fcoe_rx_list.lock);
476 }
Bhanu Gollapudifee78712011-03-21 18:51:13 -0700477 __set_current_state(TASK_INTERRUPTIBLE);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800478 spin_unlock_bh(&bg->fcoe_rx_list.lock);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800479 }
Bhanu Gollapudifee78712011-03-21 18:51:13 -0700480 __set_current_state(TASK_RUNNING);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800481 return 0;
482}
483
484
485static void bnx2fc_recv_frame(struct sk_buff *skb)
486{
487 u32 fr_len;
488 struct fc_lport *lport;
489 struct fcoe_rcv_info *fr;
Vasu Dev1bd49b42012-05-25 10:26:43 -0700490 struct fc_stats *stats;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800491 struct fc_frame_header *fh;
492 struct fcoe_crc_eof crc_eof;
493 struct fc_frame *fp;
494 struct fc_lport *vn_port;
495 struct fcoe_port *port;
496 u8 *mac = NULL;
497 u8 *dest_mac = NULL;
498 struct fcoe_hdr *hp;
499
500 fr = fcoe_dev_from_skb(skb);
501 lport = fr->fr_dev;
502 if (unlikely(lport == NULL)) {
Bhanu Prakash Gollapudib2a554f2011-06-27 23:30:53 -0700503 printk(KERN_ERR PFX "Invalid lport struct\n");
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800504 kfree_skb(skb);
505 return;
506 }
507
508 if (skb_is_nonlinear(skb))
509 skb_linearize(skb);
510 mac = eth_hdr(skb)->h_source;
511 dest_mac = eth_hdr(skb)->h_dest;
512
513 /* Pull the header */
514 hp = (struct fcoe_hdr *) skb_network_header(skb);
515 fh = (struct fc_frame_header *) skb_transport_header(skb);
516 skb_pull(skb, sizeof(struct fcoe_hdr));
517 fr_len = skb->len - sizeof(struct fcoe_crc_eof);
518
Vasu Dev1bd49b42012-05-25 10:26:43 -0700519 stats = per_cpu_ptr(lport->stats, get_cpu());
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800520 stats->RxFrames++;
521 stats->RxWords += fr_len / FCOE_WORD_TO_BYTE;
522
523 fp = (struct fc_frame *)skb;
524 fc_frame_init(fp);
525 fr_dev(fp) = lport;
526 fr_sof(fp) = hp->fcoe_sof;
527 if (skb_copy_bits(skb, fr_len, &crc_eof, sizeof(crc_eof))) {
528 put_cpu();
529 kfree_skb(skb);
530 return;
531 }
532 fr_eof(fp) = crc_eof.fcoe_eof;
533 fr_crc(fp) = crc_eof.fcoe_crc32;
534 if (pskb_trim(skb, fr_len)) {
535 put_cpu();
536 kfree_skb(skb);
537 return;
538 }
539
540 fh = fc_frame_header_get(fp);
541
542 vn_port = fc_vport_id_lookup(lport, ntoh24(fh->fh_d_id));
543 if (vn_port) {
544 port = lport_priv(vn_port);
545 if (compare_ether_addr(port->data_src_addr, dest_mac)
546 != 0) {
547 BNX2FC_HBA_DBG(lport, "fpma mismatch\n");
548 put_cpu();
549 kfree_skb(skb);
550 return;
551 }
552 }
553 if (fh->fh_r_ctl == FC_RCTL_DD_SOL_DATA &&
554 fh->fh_type == FC_TYPE_FCP) {
555 /* Drop FCP data. We dont this in L2 path */
556 put_cpu();
557 kfree_skb(skb);
558 return;
559 }
560 if (fh->fh_r_ctl == FC_RCTL_ELS_REQ &&
561 fh->fh_type == FC_TYPE_ELS) {
562 switch (fc_frame_payload_op(fp)) {
563 case ELS_LOGO:
564 if (ntoh24(fh->fh_s_id) == FC_FID_FLOGI) {
565 /* drop non-FIP LOGO */
566 put_cpu();
567 kfree_skb(skb);
568 return;
569 }
570 break;
571 }
572 }
Bhanu Prakash Gollapudi3f8744d2011-08-04 17:38:48 -0700573
574 if (fh->fh_r_ctl == FC_RCTL_BA_ABTS) {
575 /* Drop incoming ABTS */
576 put_cpu();
577 kfree_skb(skb);
578 return;
579 }
580
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800581 if (le32_to_cpu(fr_crc(fp)) !=
582 ~crc32(~0, skb->data, fr_len)) {
583 if (stats->InvalidCRCCount < 5)
584 printk(KERN_WARNING PFX "dropping frame with "
585 "CRC error\n");
586 stats->InvalidCRCCount++;
587 put_cpu();
588 kfree_skb(skb);
589 return;
590 }
591 put_cpu();
592 fc_exch_recv(lport, fp);
593}
594
595/**
596 * bnx2fc_percpu_io_thread - thread per cpu for ios
597 *
598 * @arg: ptr to bnx2fc_percpu_info structure
599 */
600int bnx2fc_percpu_io_thread(void *arg)
601{
602 struct bnx2fc_percpu_s *p = arg;
603 struct bnx2fc_work *work, *tmp;
604 LIST_HEAD(work_list);
605
606 set_user_nice(current, -20);
607 set_current_state(TASK_INTERRUPTIBLE);
608 while (!kthread_should_stop()) {
609 schedule();
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800610 spin_lock_bh(&p->fp_work_lock);
611 while (!list_empty(&p->work_list)) {
612 list_splice_init(&p->work_list, &work_list);
613 spin_unlock_bh(&p->fp_work_lock);
614
615 list_for_each_entry_safe(work, tmp, &work_list, list) {
616 list_del_init(&work->list);
617 bnx2fc_process_cq_compl(work->tgt, work->wqe);
618 kfree(work);
619 }
620
621 spin_lock_bh(&p->fp_work_lock);
622 }
Bhanu Gollapudifee78712011-03-21 18:51:13 -0700623 __set_current_state(TASK_INTERRUPTIBLE);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800624 spin_unlock_bh(&p->fp_work_lock);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800625 }
Bhanu Gollapudifee78712011-03-21 18:51:13 -0700626 __set_current_state(TASK_RUNNING);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800627
628 return 0;
629}
630
631static struct fc_host_statistics *bnx2fc_get_host_stats(struct Scsi_Host *shost)
632{
633 struct fc_host_statistics *bnx2fc_stats;
634 struct fc_lport *lport = shost_priv(shost);
635 struct fcoe_port *port = lport_priv(lport);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700636 struct bnx2fc_interface *interface = port->priv;
637 struct bnx2fc_hba *hba = interface->hba;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800638 struct fcoe_statistics_params *fw_stats;
639 int rc = 0;
640
641 fw_stats = (struct fcoe_statistics_params *)hba->stats_buffer;
642 if (!fw_stats)
643 return NULL;
644
645 bnx2fc_stats = fc_get_host_stats(shost);
646
647 init_completion(&hba->stat_req_done);
648 if (bnx2fc_send_stat_req(hba))
649 return bnx2fc_stats;
650 rc = wait_for_completion_timeout(&hba->stat_req_done, (2 * HZ));
651 if (!rc) {
652 BNX2FC_HBA_DBG(lport, "FW stat req timed out\n");
653 return bnx2fc_stats;
654 }
Bhanu Prakash Gollapudif246fe22012-12-21 19:40:32 -0800655 BNX2FC_STATS(hba, rx_stat2, fc_crc_cnt);
656 bnx2fc_stats->invalid_crc_count += hba->bfw_stats.fc_crc_cnt;
657 BNX2FC_STATS(hba, tx_stat, fcoe_tx_pkt_cnt);
658 bnx2fc_stats->tx_frames += hba->bfw_stats.fcoe_tx_pkt_cnt;
659 BNX2FC_STATS(hba, tx_stat, fcoe_tx_byte_cnt);
660 bnx2fc_stats->tx_words += ((hba->bfw_stats.fcoe_tx_byte_cnt) / 4);
661 BNX2FC_STATS(hba, rx_stat0, fcoe_rx_pkt_cnt);
662 bnx2fc_stats->rx_frames += hba->bfw_stats.fcoe_rx_pkt_cnt;
663 BNX2FC_STATS(hba, rx_stat0, fcoe_rx_byte_cnt);
664 bnx2fc_stats->rx_words += ((hba->bfw_stats.fcoe_rx_byte_cnt) / 4);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800665
666 bnx2fc_stats->dumped_frames = 0;
667 bnx2fc_stats->lip_count = 0;
668 bnx2fc_stats->nos_count = 0;
669 bnx2fc_stats->loss_of_sync_count = 0;
670 bnx2fc_stats->loss_of_signal_count = 0;
671 bnx2fc_stats->prim_seq_protocol_err_count = 0;
672
Bhanu Prakash Gollapudif246fe22012-12-21 19:40:32 -0800673 memcpy(&hba->prev_stats, hba->stats_buffer,
674 sizeof(struct fcoe_statistics_params));
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800675 return bnx2fc_stats;
676}
677
678static int bnx2fc_shost_config(struct fc_lport *lport, struct device *dev)
679{
680 struct fcoe_port *port = lport_priv(lport);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700681 struct bnx2fc_interface *interface = port->priv;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800682 struct Scsi_Host *shost = lport->host;
683 int rc = 0;
684
685 shost->max_cmd_len = BNX2FC_MAX_CMD_LEN;
686 shost->max_lun = BNX2FC_MAX_LUN;
687 shost->max_id = BNX2FC_MAX_FCP_TGT;
688 shost->max_channel = 0;
689 if (lport->vport)
690 shost->transportt = bnx2fc_vport_xport_template;
691 else
692 shost->transportt = bnx2fc_transport_template;
693
694 /* Add the new host to SCSI-ml */
695 rc = scsi_add_host(lport->host, dev);
696 if (rc) {
697 printk(KERN_ERR PFX "Error on scsi_add_host\n");
698 return rc;
699 }
700 if (!lport->vport)
701 fc_host_max_npiv_vports(lport->host) = USHRT_MAX;
702 sprintf(fc_host_symbolic_name(lport->host), "%s v%s over %s",
703 BNX2FC_NAME, BNX2FC_VERSION,
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700704 interface->netdev->name);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800705
706 return 0;
707}
708
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800709static int bnx2fc_link_ok(struct fc_lport *lport)
710{
711 struct fcoe_port *port = lport_priv(lport);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700712 struct bnx2fc_interface *interface = port->priv;
713 struct bnx2fc_hba *hba = interface->hba;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800714 struct net_device *dev = hba->phys_dev;
715 int rc = 0;
716
717 if ((dev->flags & IFF_UP) && netif_carrier_ok(dev))
718 clear_bit(ADAPTER_STATE_LINK_DOWN, &hba->adapter_state);
719 else {
720 set_bit(ADAPTER_STATE_LINK_DOWN, &hba->adapter_state);
721 rc = -1;
722 }
723 return rc;
724}
725
726/**
727 * bnx2fc_get_link_state - get network link state
728 *
729 * @hba: adapter instance pointer
730 *
731 * updates adapter structure flag based on netdev state
732 */
733void bnx2fc_get_link_state(struct bnx2fc_hba *hba)
734{
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700735 if (test_bit(__LINK_STATE_NOCARRIER, &hba->phys_dev->state))
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800736 set_bit(ADAPTER_STATE_LINK_DOWN, &hba->adapter_state);
737 else
738 clear_bit(ADAPTER_STATE_LINK_DOWN, &hba->adapter_state);
739}
740
Bhanu Prakash Gollapudi52439602011-08-04 17:38:50 -0700741static int bnx2fc_net_config(struct fc_lport *lport, struct net_device *netdev)
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800742{
743 struct bnx2fc_hba *hba;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700744 struct bnx2fc_interface *interface;
Robert Lovefd8f8902012-05-22 19:06:16 -0700745 struct fcoe_ctlr *ctlr;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800746 struct fcoe_port *port;
747 u64 wwnn, wwpn;
748
749 port = lport_priv(lport);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700750 interface = port->priv;
Robert Lovefd8f8902012-05-22 19:06:16 -0700751 ctlr = bnx2fc_to_ctlr(interface);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700752 hba = interface->hba;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800753
754 /* require support for get_pauseparam ethtool op. */
755 if (!hba->phys_dev->ethtool_ops ||
756 !hba->phys_dev->ethtool_ops->get_pauseparam)
757 return -EOPNOTSUPP;
758
Bhanu Gollapudi1294bfe2011-03-17 17:13:34 -0700759 if (fc_set_mfs(lport, BNX2FC_MFS))
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800760 return -EINVAL;
761
762 skb_queue_head_init(&port->fcoe_pending_queue);
763 port->fcoe_pending_queue_active = 0;
764 setup_timer(&port->timer, fcoe_queue_timer, (unsigned long) lport);
765
Yi Zou0e0f9cd2012-12-06 06:24:44 +0000766 fcoe_link_speed_update(lport);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800767
768 if (!lport->vport) {
Bhanu Prakash Gollapudi52439602011-08-04 17:38:50 -0700769 if (fcoe_get_wwn(netdev, &wwnn, NETDEV_FCOE_WWNN))
Robert Lovefd8f8902012-05-22 19:06:16 -0700770 wwnn = fcoe_wwn_from_mac(ctlr->ctl_src_addr,
Bhanu Prakash Gollapudi52439602011-08-04 17:38:50 -0700771 1, 0);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800772 BNX2FC_HBA_DBG(lport, "WWNN = 0x%llx\n", wwnn);
773 fc_set_wwnn(lport, wwnn);
774
Bhanu Prakash Gollapudi52439602011-08-04 17:38:50 -0700775 if (fcoe_get_wwn(netdev, &wwpn, NETDEV_FCOE_WWPN))
Robert Lovefd8f8902012-05-22 19:06:16 -0700776 wwpn = fcoe_wwn_from_mac(ctlr->ctl_src_addr,
Bhanu Prakash Gollapudi52439602011-08-04 17:38:50 -0700777 2, 0);
778
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800779 BNX2FC_HBA_DBG(lport, "WWPN = 0x%llx\n", wwpn);
780 fc_set_wwpn(lport, wwpn);
781 }
782
783 return 0;
784}
785
786static void bnx2fc_destroy_timer(unsigned long data)
787{
788 struct bnx2fc_hba *hba = (struct bnx2fc_hba *)data;
789
Bhanu Prakash Gollapudicd703ae2011-08-04 17:38:43 -0700790 printk(KERN_ERR PFX "ERROR:bnx2fc_destroy_timer - "
791 "Destroy compl not received!!\n");
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700792 set_bit(BNX2FC_FLAG_DESTROY_CMPL, &hba->flags);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800793 wake_up_interruptible(&hba->destroy_wait);
794}
795
796/**
797 * bnx2fc_indicate_netevent - Generic netdev event handler
798 *
799 * @context: adapter structure pointer
800 * @event: event type
Michael Chan415199f2011-07-20 14:55:24 +0000801 * @vlan_id: vlan id - associated vlan id with this event
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800802 *
803 * Handles NETDEV_UP, NETDEV_DOWN, NETDEV_GOING_DOWN,NETDEV_CHANGE and
Bhanu Prakash Gollapudiabc49a92011-08-04 17:38:42 -0700804 * NETDEV_CHANGE_MTU events. Handle NETDEV_UNREGISTER only for vlans.
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800805 */
Michael Chan415199f2011-07-20 14:55:24 +0000806static void bnx2fc_indicate_netevent(void *context, unsigned long event,
807 u16 vlan_id)
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800808{
809 struct bnx2fc_hba *hba = (struct bnx2fc_hba *)context;
Robert Love6e89ea32012-11-27 06:53:40 +0000810 struct fcoe_ctlr_device *cdev;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700811 struct fc_lport *lport;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800812 struct fc_lport *vport;
Bhanu Prakash Gollapudiabc49a92011-08-04 17:38:42 -0700813 struct bnx2fc_interface *interface, *tmp;
Robert Lovefd8f8902012-05-22 19:06:16 -0700814 struct fcoe_ctlr *ctlr;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700815 int wait_for_upload = 0;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800816 u32 link_possible = 1;
817
Bhanu Prakash Gollapudiabc49a92011-08-04 17:38:42 -0700818 if (vlan_id != 0 && event != NETDEV_UNREGISTER)
Michael Chan415199f2011-07-20 14:55:24 +0000819 return;
820
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800821 switch (event) {
822 case NETDEV_UP:
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800823 if (!test_bit(ADAPTER_STATE_UP, &hba->adapter_state))
824 printk(KERN_ERR "indicate_netevent: "\
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700825 "hba is not UP!!\n");
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800826 break;
827
828 case NETDEV_DOWN:
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800829 clear_bit(ADAPTER_STATE_GOING_DOWN, &hba->adapter_state);
830 clear_bit(ADAPTER_STATE_UP, &hba->adapter_state);
831 link_possible = 0;
832 break;
833
834 case NETDEV_GOING_DOWN:
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800835 set_bit(ADAPTER_STATE_GOING_DOWN, &hba->adapter_state);
836 link_possible = 0;
837 break;
838
839 case NETDEV_CHANGE:
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800840 break;
841
Bhanu Prakash Gollapudiabc49a92011-08-04 17:38:42 -0700842 case NETDEV_UNREGISTER:
843 if (!vlan_id)
844 return;
845 mutex_lock(&bnx2fc_dev_lock);
846 list_for_each_entry_safe(interface, tmp, &if_list, list) {
Nithin Nayak Sujir26b29822011-08-30 15:54:50 -0700847 if (interface->hba == hba &&
848 interface->vlan_id == (vlan_id & VLAN_VID_MASK))
849 __bnx2fc_destroy(interface);
Bhanu Prakash Gollapudiabc49a92011-08-04 17:38:42 -0700850 }
851 mutex_unlock(&bnx2fc_dev_lock);
852 return;
853
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800854 default:
Masanari Iida59e13d42012-04-25 00:24:16 +0900855 printk(KERN_ERR PFX "Unknown netevent %ld", event);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800856 return;
857 }
858
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700859 mutex_lock(&bnx2fc_dev_lock);
860 list_for_each_entry(interface, &if_list, list) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800861
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700862 if (interface->hba != hba)
863 continue;
864
Robert Lovefd8f8902012-05-22 19:06:16 -0700865 ctlr = bnx2fc_to_ctlr(interface);
866 lport = ctlr->lp;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700867 BNX2FC_HBA_DBG(lport, "netevent handler - event=%s %ld\n",
868 interface->netdev->name, event);
869
Yi Zou0e0f9cd2012-12-06 06:24:44 +0000870 fcoe_link_speed_update(lport);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700871
Robert Love6e89ea32012-11-27 06:53:40 +0000872 cdev = fcoe_ctlr_to_ctlr_dev(ctlr);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700873
874 if (link_possible && !bnx2fc_link_ok(lport)) {
Robert Love6e89ea32012-11-27 06:53:40 +0000875 switch (cdev->enabled) {
876 case FCOE_CTLR_DISABLED:
877 pr_info("Link up while interface is disabled.\n");
878 break;
879 case FCOE_CTLR_ENABLED:
880 case FCOE_CTLR_UNUSED:
881 /* Reset max recv frame size to default */
882 fc_set_mfs(lport, BNX2FC_MFS);
883 /*
884 * ctlr link up will only be handled during
885 * enable to avoid sending discovery
886 * solicitation on a stale vlan
887 */
888 if (interface->enabled)
889 fcoe_ctlr_link_up(ctlr);
890 };
Robert Lovefd8f8902012-05-22 19:06:16 -0700891 } else if (fcoe_ctlr_link_down(ctlr)) {
Robert Love6e89ea32012-11-27 06:53:40 +0000892 switch (cdev->enabled) {
893 case FCOE_CTLR_DISABLED:
894 pr_info("Link down while interface is disabled.\n");
895 break;
896 case FCOE_CTLR_ENABLED:
897 case FCOE_CTLR_UNUSED:
898 mutex_lock(&lport->lp_mutex);
899 list_for_each_entry(vport, &lport->vports, list)
900 fc_host_port_type(vport->host) =
901 FC_PORTTYPE_UNKNOWN;
902 mutex_unlock(&lport->lp_mutex);
903 fc_host_port_type(lport->host) =
904 FC_PORTTYPE_UNKNOWN;
905 per_cpu_ptr(lport->stats,
906 get_cpu())->LinkFailureCount++;
907 put_cpu();
908 fcoe_clean_pending_queue(lport);
909 wait_for_upload = 1;
910 };
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800911 }
912 }
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700913 mutex_unlock(&bnx2fc_dev_lock);
914
915 if (wait_for_upload) {
916 clear_bit(ADAPTER_STATE_READY, &hba->adapter_state);
917 init_waitqueue_head(&hba->shutdown_wait);
918 BNX2FC_MISC_DBG("indicate_netevent "
919 "num_ofld_sess = %d\n",
920 hba->num_ofld_sess);
921 hba->wait_for_link_down = 1;
922 wait_event_interruptible(hba->shutdown_wait,
923 (hba->num_ofld_sess == 0));
924 BNX2FC_MISC_DBG("wakeup - num_ofld_sess = %d\n",
925 hba->num_ofld_sess);
926 hba->wait_for_link_down = 0;
927
928 if (signal_pending(current))
929 flush_signals(current);
930 }
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800931}
932
933static int bnx2fc_libfc_config(struct fc_lport *lport)
934{
935
936 /* Set the function pointers set by bnx2fc driver */
937 memcpy(&lport->tt, &bnx2fc_libfc_fcn_templ,
938 sizeof(struct libfc_function_template));
939 fc_elsct_init(lport);
940 fc_exch_init(lport);
941 fc_rport_init(lport);
942 fc_disc_init(lport);
943 return 0;
944}
945
946static int bnx2fc_em_config(struct fc_lport *lport)
947{
Bhanu Prakash Gollapudi7d742f62012-01-23 18:00:48 -0800948 int max_xid;
949
950 if (nr_cpu_ids <= 2)
951 max_xid = FCOE_XIDS_PER_CPU;
952 else
953 max_xid = FCOE_MAX_XID;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800954 if (!fc_exch_mgr_alloc(lport, FC_CLASS_3, FCOE_MIN_XID,
Bhanu Prakash Gollapudi7d742f62012-01-23 18:00:48 -0800955 max_xid, NULL)) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800956 printk(KERN_ERR PFX "em_config:fc_exch_mgr_alloc failed\n");
957 return -ENOMEM;
958 }
959
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800960 return 0;
961}
962
963static int bnx2fc_lport_config(struct fc_lport *lport)
964{
965 lport->link_up = 0;
966 lport->qfull = 0;
Bhanu Prakash Gollapudi44c570b2012-01-23 18:00:47 -0800967 lport->max_retry_count = BNX2FC_MAX_RETRY_CNT;
968 lport->max_rport_retry_count = BNX2FC_MAX_RPORT_RETRY_CNT;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800969 lport->e_d_tov = 2 * 1000;
970 lport->r_a_tov = 10 * 1000;
971
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800972 lport->service_params = (FCP_SPPF_INIT_FCN | FCP_SPPF_RD_XRDY_DIS |
973 FCP_SPPF_RETRY | FCP_SPPF_CONF_COMPL);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800974 lport->does_npiv = 1;
975
976 memset(&lport->rnid_gen, 0, sizeof(struct fc_els_rnid_gen));
977 lport->rnid_gen.rnid_atype = BNX2FC_RNID_HBA;
978
979 /* alloc stats structure */
980 if (fc_lport_init_stats(lport))
981 return -ENOMEM;
982
983 /* Finish fc_lport configuration */
984 fc_lport_config(lport);
985
986 return 0;
987}
988
989/**
990 * bnx2fc_fip_recv - handle a received FIP frame.
991 *
992 * @skb: the received skb
993 * @dev: associated &net_device
994 * @ptype: the &packet_type structure which was used to register this handler.
995 * @orig_dev: original receive &net_device, in case @ dev is a bond.
996 *
997 * Returns: 0 for success
998 */
999static int bnx2fc_fip_recv(struct sk_buff *skb, struct net_device *dev,
1000 struct packet_type *ptype,
1001 struct net_device *orig_dev)
1002{
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001003 struct bnx2fc_interface *interface;
Robert Lovefd8f8902012-05-22 19:06:16 -07001004 struct fcoe_ctlr *ctlr;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001005 interface = container_of(ptype, struct bnx2fc_interface,
1006 fip_packet_type);
Robert Lovefd8f8902012-05-22 19:06:16 -07001007 ctlr = bnx2fc_to_ctlr(interface);
1008 fcoe_ctlr_recv(ctlr, skb);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001009 return 0;
1010}
1011
1012/**
1013 * bnx2fc_update_src_mac - Update Ethernet MAC filters.
1014 *
1015 * @fip: FCoE controller.
1016 * @old: Unicast MAC address to delete if the MAC is non-zero.
1017 * @new: Unicast MAC address to add.
1018 *
1019 * Remove any previously-set unicast MAC filter.
1020 * Add secondary FCoE MAC address filter for our OUI.
1021 */
1022static void bnx2fc_update_src_mac(struct fc_lport *lport, u8 *addr)
1023{
1024 struct fcoe_port *port = lport_priv(lport);
1025
1026 memcpy(port->data_src_addr, addr, ETH_ALEN);
1027}
1028
1029/**
1030 * bnx2fc_get_src_mac - return the ethernet source address for an lport
1031 *
1032 * @lport: libfc port
1033 */
1034static u8 *bnx2fc_get_src_mac(struct fc_lport *lport)
1035{
1036 struct fcoe_port *port;
1037
1038 port = (struct fcoe_port *)lport_priv(lport);
1039 return port->data_src_addr;
1040}
1041
1042/**
1043 * bnx2fc_fip_send - send an Ethernet-encapsulated FIP frame.
1044 *
1045 * @fip: FCoE controller.
1046 * @skb: FIP Packet.
1047 */
1048static void bnx2fc_fip_send(struct fcoe_ctlr *fip, struct sk_buff *skb)
1049{
1050 skb->dev = bnx2fc_from_ctlr(fip)->netdev;
1051 dev_queue_xmit(skb);
1052}
1053
1054static int bnx2fc_vport_create(struct fc_vport *vport, bool disabled)
1055{
1056 struct Scsi_Host *shost = vport_to_shost(vport);
1057 struct fc_lport *n_port = shost_priv(shost);
1058 struct fcoe_port *port = lport_priv(n_port);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001059 struct bnx2fc_interface *interface = port->priv;
1060 struct net_device *netdev = interface->netdev;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001061 struct fc_lport *vn_port;
Bhanu Prakash Gollapudi861efc52011-08-04 17:38:51 -07001062 int rc;
1063 char buf[32];
1064
1065 rc = fcoe_validate_vport_create(vport);
1066 if (rc) {
1067 fcoe_wwn_to_str(vport->port_name, buf, sizeof(buf));
1068 printk(KERN_ERR PFX "Failed to create vport, "
1069 "WWPN (0x%s) already exists\n",
1070 buf);
1071 return rc;
1072 }
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001073
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001074 if (!test_bit(BNX2FC_FLAG_FW_INIT_DONE, &interface->hba->flags)) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001075 printk(KERN_ERR PFX "vn ports cannot be created on"
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001076 "this interface\n");
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001077 return -EIO;
1078 }
Jiri Pirko4bc71cb2011-09-03 03:34:30 +00001079 rtnl_lock();
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001080 mutex_lock(&bnx2fc_dev_lock);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001081 vn_port = bnx2fc_if_create(interface, &vport->dev, 1);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001082 mutex_unlock(&bnx2fc_dev_lock);
Jiri Pirko4bc71cb2011-09-03 03:34:30 +00001083 rtnl_unlock();
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001084
1085 if (IS_ERR(vn_port)) {
1086 printk(KERN_ERR PFX "bnx2fc_vport_create (%s) failed\n",
1087 netdev->name);
1088 return -EIO;
1089 }
1090
1091 if (disabled) {
1092 fc_vport_set_state(vport, FC_VPORT_DISABLED);
1093 } else {
1094 vn_port->boot_time = jiffies;
1095 fc_lport_init(vn_port);
1096 fc_fabric_login(vn_port);
1097 fc_vport_setlink(vn_port);
1098 }
1099 return 0;
1100}
1101
Bhanu Prakash Gollapudiabc49a92011-08-04 17:38:42 -07001102static void bnx2fc_free_vport(struct bnx2fc_hba *hba, struct fc_lport *lport)
1103{
1104 struct bnx2fc_lport *blport, *tmp;
1105
1106 spin_lock_bh(&hba->hba_lock);
1107 list_for_each_entry_safe(blport, tmp, &hba->vports, list) {
1108 if (blport->lport == lport) {
1109 list_del(&blport->list);
1110 kfree(blport);
1111 }
1112 }
1113 spin_unlock_bh(&hba->hba_lock);
1114}
1115
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001116static int bnx2fc_vport_destroy(struct fc_vport *vport)
1117{
1118 struct Scsi_Host *shost = vport_to_shost(vport);
1119 struct fc_lport *n_port = shost_priv(shost);
1120 struct fc_lport *vn_port = vport->dd_data;
1121 struct fcoe_port *port = lport_priv(vn_port);
Bhanu Prakash Gollapudiabc49a92011-08-04 17:38:42 -07001122 struct bnx2fc_interface *interface = port->priv;
Bhanu Prakash Gollapudicdf54662011-08-04 17:38:39 -07001123 struct fc_lport *v_port;
1124 bool found = false;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001125
1126 mutex_lock(&n_port->lp_mutex);
Bhanu Prakash Gollapudicdf54662011-08-04 17:38:39 -07001127 list_for_each_entry(v_port, &n_port->vports, list)
1128 if (v_port->vport == vport) {
1129 found = true;
1130 break;
1131 }
1132
1133 if (!found) {
1134 mutex_unlock(&n_port->lp_mutex);
1135 return -ENOENT;
1136 }
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001137 list_del(&vn_port->list);
1138 mutex_unlock(&n_port->lp_mutex);
Bhanu Prakash Gollapudiabc49a92011-08-04 17:38:42 -07001139 bnx2fc_free_vport(interface->hba, port->lport);
1140 bnx2fc_port_shutdown(port->lport);
1141 bnx2fc_interface_put(interface);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001142 queue_work(bnx2fc_wq, &port->destroy_work);
1143 return 0;
1144}
1145
1146static int bnx2fc_vport_disable(struct fc_vport *vport, bool disable)
1147{
1148 struct fc_lport *lport = vport->dd_data;
1149
1150 if (disable) {
1151 fc_vport_set_state(vport, FC_VPORT_DISABLED);
1152 fc_fabric_logoff(lport);
1153 } else {
1154 lport->boot_time = jiffies;
1155 fc_fabric_login(lport);
1156 fc_vport_setlink(lport);
1157 }
1158 return 0;
1159}
1160
1161
Bhanu Prakash Gollapudi776cebc2011-08-04 17:38:40 -07001162static int bnx2fc_interface_setup(struct bnx2fc_interface *interface)
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001163{
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001164 struct net_device *netdev = interface->netdev;
1165 struct net_device *physdev = interface->hba->phys_dev;
Robert Lovefd8f8902012-05-22 19:06:16 -07001166 struct fcoe_ctlr *ctlr = bnx2fc_to_ctlr(interface);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001167 struct netdev_hw_addr *ha;
1168 int sel_san_mac = 0;
1169
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001170 /* setup Source MAC Address */
1171 rcu_read_lock();
1172 for_each_dev_addr(physdev, ha) {
1173 BNX2FC_MISC_DBG("net_config: ha->type = %d, fip_mac = ",
1174 ha->type);
1175 printk(KERN_INFO "%2x:%2x:%2x:%2x:%2x:%2x\n", ha->addr[0],
1176 ha->addr[1], ha->addr[2], ha->addr[3],
1177 ha->addr[4], ha->addr[5]);
1178
1179 if ((ha->type == NETDEV_HW_ADDR_T_SAN) &&
1180 (is_valid_ether_addr(ha->addr))) {
Robert Lovefd8f8902012-05-22 19:06:16 -07001181 memcpy(ctlr->ctl_src_addr, ha->addr,
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001182 ETH_ALEN);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001183 sel_san_mac = 1;
1184 BNX2FC_MISC_DBG("Found SAN MAC\n");
1185 }
1186 }
1187 rcu_read_unlock();
1188
1189 if (!sel_san_mac)
1190 return -ENODEV;
1191
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001192 interface->fip_packet_type.func = bnx2fc_fip_recv;
1193 interface->fip_packet_type.type = htons(ETH_P_FIP);
1194 interface->fip_packet_type.dev = netdev;
1195 dev_add_pack(&interface->fip_packet_type);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001196
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001197 interface->fcoe_packet_type.func = bnx2fc_rcv;
1198 interface->fcoe_packet_type.type = __constant_htons(ETH_P_FCOE);
1199 interface->fcoe_packet_type.dev = netdev;
1200 dev_add_pack(&interface->fcoe_packet_type);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001201
1202 return 0;
1203}
1204
1205static int bnx2fc_attach_transport(void)
1206{
1207 bnx2fc_transport_template =
1208 fc_attach_transport(&bnx2fc_transport_function);
1209
1210 if (bnx2fc_transport_template == NULL) {
1211 printk(KERN_ERR PFX "Failed to attach FC transport\n");
1212 return -ENODEV;
1213 }
1214
1215 bnx2fc_vport_xport_template =
1216 fc_attach_transport(&bnx2fc_vport_xport_function);
1217 if (bnx2fc_vport_xport_template == NULL) {
1218 printk(KERN_ERR PFX
1219 "Failed to attach FC transport for vport\n");
1220 fc_release_transport(bnx2fc_transport_template);
1221 bnx2fc_transport_template = NULL;
1222 return -ENODEV;
1223 }
1224 return 0;
1225}
1226static void bnx2fc_release_transport(void)
1227{
1228 fc_release_transport(bnx2fc_transport_template);
1229 fc_release_transport(bnx2fc_vport_xport_template);
1230 bnx2fc_transport_template = NULL;
1231 bnx2fc_vport_xport_template = NULL;
1232}
1233
1234static void bnx2fc_interface_release(struct kref *kref)
1235{
Robert Love8d55e502012-05-22 19:06:26 -07001236 struct fcoe_ctlr_device *ctlr_dev;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001237 struct bnx2fc_interface *interface;
Robert Lovefd8f8902012-05-22 19:06:16 -07001238 struct fcoe_ctlr *ctlr;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001239 struct net_device *netdev;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001240
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001241 interface = container_of(kref, struct bnx2fc_interface, kref);
Nithin Nayak Sujir068bdce2011-04-25 12:30:09 -07001242 BNX2FC_MISC_DBG("Interface is being released\n");
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001243
Robert Lovefd8f8902012-05-22 19:06:16 -07001244 ctlr = bnx2fc_to_ctlr(interface);
Robert Love8d55e502012-05-22 19:06:26 -07001245 ctlr_dev = fcoe_ctlr_to_ctlr_dev(ctlr);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001246 netdev = interface->netdev;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001247
1248 /* tear-down FIP controller */
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001249 if (test_and_clear_bit(BNX2FC_CTLR_INIT_DONE, &interface->if_flags))
Robert Lovefd8f8902012-05-22 19:06:16 -07001250 fcoe_ctlr_destroy(ctlr);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001251
Robert Love8d55e502012-05-22 19:06:26 -07001252 fcoe_ctlr_device_delete(ctlr_dev);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001253
1254 dev_put(netdev);
1255 module_put(THIS_MODULE);
1256}
1257
1258static inline void bnx2fc_interface_get(struct bnx2fc_interface *interface)
1259{
1260 kref_get(&interface->kref);
1261}
1262
1263static inline void bnx2fc_interface_put(struct bnx2fc_interface *interface)
1264{
1265 kref_put(&interface->kref, bnx2fc_interface_release);
1266}
1267static void bnx2fc_hba_destroy(struct bnx2fc_hba *hba)
1268{
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001269 /* Free the command manager */
1270 if (hba->cmd_mgr) {
1271 bnx2fc_cmd_mgr_free(hba->cmd_mgr);
1272 hba->cmd_mgr = NULL;
1273 }
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001274 kfree(hba->tgt_ofld_list);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001275 bnx2fc_unbind_pcidev(hba);
1276 kfree(hba);
1277}
1278
1279/**
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001280 * bnx2fc_hba_create - create a new bnx2fc hba
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001281 *
1282 * @cnic: pointer to cnic device
1283 *
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001284 * Creates a new FCoE hba on the given device.
1285 *
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001286 */
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001287static struct bnx2fc_hba *bnx2fc_hba_create(struct cnic_dev *cnic)
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001288{
1289 struct bnx2fc_hba *hba;
Barak Witkowski2e499d32012-06-26 01:31:19 +00001290 struct fcoe_capabilities *fcoe_cap;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001291 int rc;
1292
1293 hba = kzalloc(sizeof(*hba), GFP_KERNEL);
1294 if (!hba) {
1295 printk(KERN_ERR PFX "Unable to allocate hba structure\n");
1296 return NULL;
1297 }
1298 spin_lock_init(&hba->hba_lock);
1299 mutex_init(&hba->hba_mutex);
1300
1301 hba->cnic = cnic;
1302 rc = bnx2fc_bind_pcidev(hba);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001303 if (rc) {
1304 printk(KERN_ERR PFX "create_adapter: bind error\n");
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001305 goto bind_err;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001306 }
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001307 hba->phys_dev = cnic->netdev;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001308 hba->next_conn_id = 0;
1309
1310 hba->tgt_ofld_list =
1311 kzalloc(sizeof(struct bnx2fc_rport *) * BNX2FC_NUM_MAX_SESS,
1312 GFP_KERNEL);
1313 if (!hba->tgt_ofld_list) {
1314 printk(KERN_ERR PFX "Unable to allocate tgt offload list\n");
1315 goto tgtofld_err;
1316 }
1317
1318 hba->num_ofld_sess = 0;
1319
1320 hba->cmd_mgr = bnx2fc_cmd_mgr_alloc(hba, BNX2FC_MIN_XID,
1321 BNX2FC_MAX_XID);
1322 if (!hba->cmd_mgr) {
1323 printk(KERN_ERR PFX "em_config:bnx2fc_cmd_mgr_alloc failed\n");
1324 goto cmgr_err;
1325 }
Barak Witkowski2e499d32012-06-26 01:31:19 +00001326 fcoe_cap = &hba->fcoe_cap;
1327
1328 fcoe_cap->capability1 = BNX2FC_TM_MAX_SQES <<
1329 FCOE_IOS_PER_CONNECTION_SHIFT;
1330 fcoe_cap->capability1 |= BNX2FC_NUM_MAX_SESS <<
1331 FCOE_LOGINS_PER_PORT_SHIFT;
1332 fcoe_cap->capability2 = BNX2FC_MAX_OUTSTANDING_CMNDS <<
1333 FCOE_NUMBER_OF_EXCHANGES_SHIFT;
1334 fcoe_cap->capability2 |= BNX2FC_MAX_NPIV <<
1335 FCOE_NPIV_WWN_PER_PORT_SHIFT;
1336 fcoe_cap->capability3 = BNX2FC_NUM_MAX_SESS <<
1337 FCOE_TARGETS_SUPPORTED_SHIFT;
1338 fcoe_cap->capability3 |= BNX2FC_MAX_OUTSTANDING_CMNDS <<
1339 FCOE_OUTSTANDING_COMMANDS_SHIFT;
1340 fcoe_cap->capability4 = FCOE_CAPABILITY4_STATEFUL;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001341
1342 init_waitqueue_head(&hba->shutdown_wait);
1343 init_waitqueue_head(&hba->destroy_wait);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001344 INIT_LIST_HEAD(&hba->vports);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001345
1346 return hba;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001347
1348cmgr_err:
1349 kfree(hba->tgt_ofld_list);
1350tgtofld_err:
1351 bnx2fc_unbind_pcidev(hba);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001352bind_err:
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001353 kfree(hba);
1354 return NULL;
1355}
1356
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001357struct bnx2fc_interface *bnx2fc_interface_create(struct bnx2fc_hba *hba,
1358 struct net_device *netdev,
1359 enum fip_state fip_mode)
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001360{
Robert Love8d55e502012-05-22 19:06:26 -07001361 struct fcoe_ctlr_device *ctlr_dev;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001362 struct bnx2fc_interface *interface;
Robert Lovefd8f8902012-05-22 19:06:16 -07001363 struct fcoe_ctlr *ctlr;
1364 int size;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001365 int rc = 0;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001366
Robert Lovefd8f8902012-05-22 19:06:16 -07001367 size = (sizeof(*interface) + sizeof(struct fcoe_ctlr));
Robert Love8d55e502012-05-22 19:06:26 -07001368 ctlr_dev = fcoe_ctlr_device_add(&netdev->dev, &bnx2fc_fcoe_sysfs_templ,
1369 size);
1370 if (!ctlr_dev) {
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001371 printk(KERN_ERR PFX "Unable to allocate interface structure\n");
1372 return NULL;
1373 }
Robert Love8d55e502012-05-22 19:06:26 -07001374 ctlr = fcoe_ctlr_device_priv(ctlr_dev);
Robert Lovefd8f8902012-05-22 19:06:16 -07001375 interface = fcoe_ctlr_priv(ctlr);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001376 dev_hold(netdev);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001377 kref_init(&interface->kref);
1378 interface->hba = hba;
1379 interface->netdev = netdev;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001380
1381 /* Initialize FIP */
Robert Lovefd8f8902012-05-22 19:06:16 -07001382 fcoe_ctlr_init(ctlr, fip_mode);
1383 ctlr->send = bnx2fc_fip_send;
1384 ctlr->update_mac = bnx2fc_update_src_mac;
1385 ctlr->get_src_addr = bnx2fc_get_src_mac;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001386 set_bit(BNX2FC_CTLR_INIT_DONE, &interface->if_flags);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001387
Bhanu Prakash Gollapudi776cebc2011-08-04 17:38:40 -07001388 rc = bnx2fc_interface_setup(interface);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001389 if (!rc)
1390 return interface;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001391
Robert Lovefd8f8902012-05-22 19:06:16 -07001392 fcoe_ctlr_destroy(ctlr);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001393 dev_put(netdev);
Robert Love8d55e502012-05-22 19:06:26 -07001394 fcoe_ctlr_device_delete(ctlr_dev);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001395 return NULL;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001396}
1397
1398/**
1399 * bnx2fc_if_create - Create FCoE instance on a given interface
1400 *
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001401 * @interface: FCoE interface to create a local port on
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001402 * @parent: Device pointer to be the parent in sysfs for the SCSI host
1403 * @npiv: Indicates if the port is vport or not
1404 *
1405 * Creates a fc_lport instance and a Scsi_Host instance and configure them.
1406 *
1407 * Returns: Allocated fc_lport or an error pointer
1408 */
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001409static struct fc_lport *bnx2fc_if_create(struct bnx2fc_interface *interface,
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001410 struct device *parent, int npiv)
1411{
Robert Lovefd8f8902012-05-22 19:06:16 -07001412 struct fcoe_ctlr *ctlr = bnx2fc_to_ctlr(interface);
Vasu Dev134a4e22011-04-28 15:55:44 -07001413 struct fc_lport *lport, *n_port;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001414 struct fcoe_port *port;
1415 struct Scsi_Host *shost;
1416 struct fc_vport *vport = dev_to_vport(parent);
Bhanu Prakash Gollapudid36b3272011-05-27 11:47:27 -07001417 struct bnx2fc_lport *blport;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001418 struct bnx2fc_hba *hba;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001419 int rc = 0;
1420
Bhanu Prakash Gollapudid36b3272011-05-27 11:47:27 -07001421 blport = kzalloc(sizeof(struct bnx2fc_lport), GFP_KERNEL);
1422 if (!blport) {
Robert Lovefd8f8902012-05-22 19:06:16 -07001423 BNX2FC_HBA_DBG(ctlr->lp, "Unable to alloc blport\n");
Bhanu Prakash Gollapudid36b3272011-05-27 11:47:27 -07001424 return NULL;
1425 }
1426
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001427 /* Allocate Scsi_Host structure */
Vasu Dev134a4e22011-04-28 15:55:44 -07001428 if (!npiv)
1429 lport = libfc_host_alloc(&bnx2fc_shost_template, sizeof(*port));
1430 else
1431 lport = libfc_vport_create(vport, sizeof(*port));
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001432
1433 if (!lport) {
1434 printk(KERN_ERR PFX "could not allocate scsi host structure\n");
Bhanu Prakash Gollapudid36b3272011-05-27 11:47:27 -07001435 goto free_blport;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001436 }
1437 shost = lport->host;
1438 port = lport_priv(lport);
1439 port->lport = lport;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001440 port->priv = interface;
Yi Zouc3d79092012-12-06 06:24:29 +00001441 port->get_netdev = bnx2fc_netdev;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001442 INIT_WORK(&port->destroy_work, bnx2fc_destroy_work);
1443
1444 /* Configure fcoe_port */
1445 rc = bnx2fc_lport_config(lport);
1446 if (rc)
1447 goto lp_config_err;
1448
1449 if (npiv) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001450 printk(KERN_ERR PFX "Setting vport names, 0x%llX 0x%llX\n",
1451 vport->node_name, vport->port_name);
1452 fc_set_wwnn(lport, vport->node_name);
1453 fc_set_wwpn(lport, vport->port_name);
1454 }
1455 /* Configure netdev and networking properties of the lport */
Bhanu Prakash Gollapudi52439602011-08-04 17:38:50 -07001456 rc = bnx2fc_net_config(lport, interface->netdev);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001457 if (rc) {
1458 printk(KERN_ERR PFX "Error on bnx2fc_net_config\n");
1459 goto lp_config_err;
1460 }
1461
1462 rc = bnx2fc_shost_config(lport, parent);
1463 if (rc) {
1464 printk(KERN_ERR PFX "Couldnt configure shost for %s\n",
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001465 interface->netdev->name);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001466 goto lp_config_err;
1467 }
1468
1469 /* Initialize the libfc library */
1470 rc = bnx2fc_libfc_config(lport);
1471 if (rc) {
1472 printk(KERN_ERR PFX "Couldnt configure libfc\n");
1473 goto shost_err;
1474 }
1475 fc_host_port_type(lport->host) = FC_PORTTYPE_UNKNOWN;
1476
1477 /* Allocate exchange manager */
Vasu Dev134a4e22011-04-28 15:55:44 -07001478 if (!npiv)
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001479 rc = bnx2fc_em_config(lport);
Vasu Dev134a4e22011-04-28 15:55:44 -07001480 else {
1481 shost = vport_to_shost(vport);
1482 n_port = shost_priv(shost);
1483 rc = fc_exch_mgr_list_clone(n_port, lport);
1484 }
1485
1486 if (rc) {
1487 printk(KERN_ERR PFX "Error on bnx2fc_em_config\n");
1488 goto shost_err;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001489 }
1490
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001491 bnx2fc_interface_get(interface);
Bhanu Prakash Gollapudid36b3272011-05-27 11:47:27 -07001492
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001493 hba = interface->hba;
Bhanu Prakash Gollapudid36b3272011-05-27 11:47:27 -07001494 spin_lock_bh(&hba->hba_lock);
1495 blport->lport = lport;
1496 list_add_tail(&blport->list, &hba->vports);
1497 spin_unlock_bh(&hba->hba_lock);
1498
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001499 return lport;
1500
1501shost_err:
1502 scsi_remove_host(shost);
1503lp_config_err:
1504 scsi_host_put(lport->host);
Bhanu Prakash Gollapudid36b3272011-05-27 11:47:27 -07001505free_blport:
1506 kfree(blport);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001507 return NULL;
1508}
1509
Bhanu Prakash Gollapudi013068f2011-08-30 15:54:52 -07001510static void bnx2fc_net_cleanup(struct bnx2fc_interface *interface)
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001511{
1512 /* Dont listen for Ethernet packets anymore */
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001513 __dev_remove_pack(&interface->fcoe_packet_type);
1514 __dev_remove_pack(&interface->fip_packet_type);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001515 synchronize_net();
1516}
1517
Bhanu Prakash Gollapudi776cebc2011-08-04 17:38:40 -07001518static void bnx2fc_interface_cleanup(struct bnx2fc_interface *interface)
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001519{
Robert Lovefd8f8902012-05-22 19:06:16 -07001520 struct fcoe_ctlr *ctlr = bnx2fc_to_ctlr(interface);
1521 struct fc_lport *lport = ctlr->lp;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001522 struct fcoe_port *port = lport_priv(lport);
Bhanu Prakash Gollapudi9be17fc2011-08-04 17:38:41 -07001523 struct bnx2fc_hba *hba = interface->hba;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001524
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001525 /* Stop the transmit retry timer */
1526 del_timer_sync(&port->timer);
1527
1528 /* Free existing transmit skbs */
1529 fcoe_clean_pending_queue(lport);
1530
Bhanu Prakash Gollapudi013068f2011-08-30 15:54:52 -07001531 bnx2fc_net_cleanup(interface);
Bhanu Prakash Gollapudi9be17fc2011-08-04 17:38:41 -07001532
Bhanu Prakash Gollapudiabc49a92011-08-04 17:38:42 -07001533 bnx2fc_free_vport(hba, lport);
Bhanu Prakash Gollapudi9be17fc2011-08-04 17:38:41 -07001534}
1535
1536static void bnx2fc_if_destroy(struct fc_lport *lport)
1537{
1538
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001539 /* Free queued packets for the receive thread */
1540 bnx2fc_clean_rx_queue(lport);
1541
1542 /* Detach from scsi-ml */
1543 fc_remove_host(lport->host);
1544 scsi_remove_host(lport->host);
1545
1546 /*
1547 * Note that only the physical lport will have the exchange manager.
1548 * for vports, this function is NOP
1549 */
1550 fc_exch_mgr_free(lport);
1551
1552 /* Free memory used by statistical counters */
1553 fc_lport_free_stats(lport);
1554
1555 /* Release Scsi_Host */
1556 scsi_host_put(lport->host);
1557}
1558
Bhanu Prakash Gollapudieccdcd02011-08-24 18:56:42 -07001559static void __bnx2fc_destroy(struct bnx2fc_interface *interface)
Bhanu Prakash Gollapudiabc49a92011-08-04 17:38:42 -07001560{
Robert Lovefd8f8902012-05-22 19:06:16 -07001561 struct fcoe_ctlr *ctlr = bnx2fc_to_ctlr(interface);
1562 struct fc_lport *lport = ctlr->lp;
Bhanu Prakash Gollapudi0cbf32e2011-08-30 15:54:51 -07001563 struct fcoe_port *port = lport_priv(lport);
Bhanu Prakash Gollapudiabc49a92011-08-04 17:38:42 -07001564
1565 bnx2fc_interface_cleanup(interface);
1566 bnx2fc_stop(interface);
Bhanu Prakash Gollapudiabc49a92011-08-04 17:38:42 -07001567 list_del(&interface->list);
Bhanu Prakash Gollapudiabc49a92011-08-04 17:38:42 -07001568 bnx2fc_interface_put(interface);
Bhanu Prakash Gollapudi0cbf32e2011-08-30 15:54:51 -07001569 queue_work(bnx2fc_wq, &port->destroy_work);
Bhanu Prakash Gollapudiabc49a92011-08-04 17:38:42 -07001570}
1571
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001572/**
1573 * bnx2fc_destroy - Destroy a bnx2fc FCoE interface
1574 *
1575 * @buffer: The name of the Ethernet interface to be destroyed
1576 * @kp: The associated kernel parameter
1577 *
1578 * Called from sysfs.
1579 *
1580 * Returns: 0 for success
1581 */
1582static int bnx2fc_destroy(struct net_device *netdev)
1583{
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001584 struct bnx2fc_interface *interface = NULL;
Bhanu Prakash Gollapudi2a7b29c2012-01-23 18:00:46 -08001585 struct workqueue_struct *timer_work_queue;
Robert Lovefd8f8902012-05-22 19:06:16 -07001586 struct fcoe_ctlr *ctlr;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001587 int rc = 0;
1588
Nithin Sujir6702ca12011-03-17 17:13:27 -07001589 rtnl_lock();
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001590 mutex_lock(&bnx2fc_dev_lock);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001591
1592 interface = bnx2fc_interface_lookup(netdev);
Robert Lovefd8f8902012-05-22 19:06:16 -07001593 ctlr = bnx2fc_to_ctlr(interface);
1594 if (!interface || !ctlr->lp) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001595 rc = -ENODEV;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001596 printk(KERN_ERR PFX "bnx2fc_destroy: interface or lport not found\n");
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001597 goto netdev_err;
1598 }
1599
Bhanu Prakash Gollapudi2a7b29c2012-01-23 18:00:46 -08001600 timer_work_queue = interface->timer_work_queue;
Bhanu Prakash Gollapudieccdcd02011-08-24 18:56:42 -07001601 __bnx2fc_destroy(interface);
Bhanu Prakash Gollapudi2a7b29c2012-01-23 18:00:46 -08001602 destroy_workqueue(timer_work_queue);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001603
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001604netdev_err:
1605 mutex_unlock(&bnx2fc_dev_lock);
1606 rtnl_unlock();
1607 return rc;
1608}
1609
1610static void bnx2fc_destroy_work(struct work_struct *work)
1611{
1612 struct fcoe_port *port;
1613 struct fc_lport *lport;
1614
1615 port = container_of(work, struct fcoe_port, destroy_work);
1616 lport = port->lport;
1617
1618 BNX2FC_HBA_DBG(lport, "Entered bnx2fc_destroy_work\n");
1619
Bhanu Prakash Gollapudi9be17fc2011-08-04 17:38:41 -07001620 bnx2fc_if_destroy(lport);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001621}
1622
1623static void bnx2fc_unbind_adapter_devices(struct bnx2fc_hba *hba)
1624{
1625 bnx2fc_free_fw_resc(hba);
1626 bnx2fc_free_task_ctx(hba);
1627}
1628
1629/**
1630 * bnx2fc_bind_adapter_devices - binds bnx2fc adapter with the associated
1631 * pci structure
1632 *
1633 * @hba: Adapter instance
1634 */
1635static int bnx2fc_bind_adapter_devices(struct bnx2fc_hba *hba)
1636{
1637 if (bnx2fc_setup_task_ctx(hba))
1638 goto mem_err;
1639
1640 if (bnx2fc_setup_fw_resc(hba))
1641 goto mem_err;
1642
1643 return 0;
1644mem_err:
1645 bnx2fc_unbind_adapter_devices(hba);
1646 return -ENOMEM;
1647}
1648
1649static int bnx2fc_bind_pcidev(struct bnx2fc_hba *hba)
1650{
1651 struct cnic_dev *cnic;
1652
1653 if (!hba->cnic) {
1654 printk(KERN_ERR PFX "cnic is NULL\n");
1655 return -ENODEV;
1656 }
1657 cnic = hba->cnic;
1658 hba->pcidev = cnic->pcidev;
1659 if (hba->pcidev)
1660 pci_dev_get(hba->pcidev);
1661
1662 return 0;
1663}
1664
1665static void bnx2fc_unbind_pcidev(struct bnx2fc_hba *hba)
1666{
1667 if (hba->pcidev)
1668 pci_dev_put(hba->pcidev);
1669 hba->pcidev = NULL;
1670}
1671
Barak Witkowski2e499d32012-06-26 01:31:19 +00001672/**
1673 * bnx2fc_ulp_get_stats - cnic callback to populate FCoE stats
1674 *
1675 * @handle: transport handle pointing to adapter struture
1676 */
1677static int bnx2fc_ulp_get_stats(void *handle)
1678{
1679 struct bnx2fc_hba *hba = handle;
1680 struct cnic_dev *cnic;
1681 struct fcoe_stats_info *stats_addr;
1682
1683 if (!hba)
1684 return -EINVAL;
1685
1686 cnic = hba->cnic;
1687 stats_addr = &cnic->stats_addr->fcoe_stat;
1688 if (!stats_addr)
1689 return -EINVAL;
1690
1691 strncpy(stats_addr->version, BNX2FC_VERSION,
1692 sizeof(stats_addr->version));
1693 stats_addr->txq_size = BNX2FC_SQ_WQES_MAX;
1694 stats_addr->rxq_size = BNX2FC_CQ_WQES_MAX;
1695
1696 return 0;
1697}
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001698
1699
1700/**
1701 * bnx2fc_ulp_start - cnic callback to initialize & start adapter instance
1702 *
Masanari Iida59e13d42012-04-25 00:24:16 +09001703 * @handle: transport handle pointing to adapter structure
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001704 *
1705 * This function maps adapter structure to pcidev structure and initiates
1706 * firmware handshake to enable/initialize on-chip FCoE components.
1707 * This bnx2fc - cnic interface api callback is used after following
1708 * conditions are met -
1709 * a) underlying network interface is up (marked by event NETDEV_UP
1710 * from netdev
1711 * b) bnx2fc adatper structure is registered.
1712 */
1713static void bnx2fc_ulp_start(void *handle)
1714{
1715 struct bnx2fc_hba *hba = handle;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001716 struct bnx2fc_interface *interface;
Robert Lovefd8f8902012-05-22 19:06:16 -07001717 struct fcoe_ctlr *ctlr;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001718 struct fc_lport *lport;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001719
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001720 mutex_lock(&bnx2fc_dev_lock);
1721
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001722 if (!test_bit(BNX2FC_FLAG_FW_INIT_DONE, &hba->flags))
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001723 bnx2fc_fw_init(hba);
1724
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001725 BNX2FC_MISC_DBG("bnx2fc started.\n");
1726
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001727 list_for_each_entry(interface, &if_list, list) {
1728 if (interface->hba == hba) {
Robert Lovefd8f8902012-05-22 19:06:16 -07001729 ctlr = bnx2fc_to_ctlr(interface);
1730 lport = ctlr->lp;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001731 /* Kick off Fabric discovery*/
1732 printk(KERN_ERR PFX "ulp_init: start discovery\n");
1733 lport->tt.frame_send = bnx2fc_xmit;
1734 bnx2fc_start_disc(interface);
1735 }
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001736 }
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001737
1738 mutex_unlock(&bnx2fc_dev_lock);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001739}
1740
1741static void bnx2fc_port_shutdown(struct fc_lport *lport)
1742{
1743 BNX2FC_MISC_DBG("Entered %s\n", __func__);
1744 fc_fabric_logoff(lport);
1745 fc_lport_destroy(lport);
1746}
1747
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001748static void bnx2fc_stop(struct bnx2fc_interface *interface)
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001749{
Robert Lovefd8f8902012-05-22 19:06:16 -07001750 struct fcoe_ctlr *ctlr = bnx2fc_to_ctlr(interface);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001751 struct fc_lport *lport;
1752 struct fc_lport *vport;
1753
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001754 if (!test_bit(BNX2FC_FLAG_FW_INIT_DONE, &interface->hba->flags))
1755 return;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001756
Robert Lovefd8f8902012-05-22 19:06:16 -07001757 lport = ctlr->lp;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001758 bnx2fc_port_shutdown(lport);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001759
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001760 mutex_lock(&lport->lp_mutex);
1761 list_for_each_entry(vport, &lport->vports, list)
1762 fc_host_port_type(vport->host) =
1763 FC_PORTTYPE_UNKNOWN;
1764 mutex_unlock(&lport->lp_mutex);
1765 fc_host_port_type(lport->host) = FC_PORTTYPE_UNKNOWN;
Robert Lovefd8f8902012-05-22 19:06:16 -07001766 fcoe_ctlr_link_down(ctlr);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001767 fcoe_clean_pending_queue(lport);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001768}
1769
1770static int bnx2fc_fw_init(struct bnx2fc_hba *hba)
1771{
1772#define BNX2FC_INIT_POLL_TIME (1000 / HZ)
1773 int rc = -1;
1774 int i = HZ;
1775
1776 rc = bnx2fc_bind_adapter_devices(hba);
1777 if (rc) {
1778 printk(KERN_ALERT PFX
1779 "bnx2fc_bind_adapter_devices failed - rc = %d\n", rc);
1780 goto err_out;
1781 }
1782
1783 rc = bnx2fc_send_fw_fcoe_init_msg(hba);
1784 if (rc) {
1785 printk(KERN_ALERT PFX
1786 "bnx2fc_send_fw_fcoe_init_msg failed - rc = %d\n", rc);
1787 goto err_unbind;
1788 }
1789
1790 /*
1791 * Wait until the adapter init message is complete, and adapter
1792 * state is UP.
1793 */
1794 while (!test_bit(ADAPTER_STATE_UP, &hba->adapter_state) && i--)
1795 msleep(BNX2FC_INIT_POLL_TIME);
1796
1797 if (!test_bit(ADAPTER_STATE_UP, &hba->adapter_state)) {
1798 printk(KERN_ERR PFX "bnx2fc_start: %s failed to initialize. "
1799 "Ignoring...\n",
1800 hba->cnic->netdev->name);
1801 rc = -1;
1802 goto err_unbind;
1803 }
1804
1805
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001806 set_bit(BNX2FC_FLAG_FW_INIT_DONE, &hba->flags);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001807 return 0;
1808
1809err_unbind:
1810 bnx2fc_unbind_adapter_devices(hba);
1811err_out:
1812 return rc;
1813}
1814
1815static void bnx2fc_fw_destroy(struct bnx2fc_hba *hba)
1816{
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001817 if (test_and_clear_bit(BNX2FC_FLAG_FW_INIT_DONE, &hba->flags)) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001818 if (bnx2fc_send_fw_fcoe_destroy_msg(hba) == 0) {
1819 init_timer(&hba->destroy_timer);
1820 hba->destroy_timer.expires = BNX2FC_FW_TIMEOUT +
1821 jiffies;
1822 hba->destroy_timer.function = bnx2fc_destroy_timer;
1823 hba->destroy_timer.data = (unsigned long)hba;
1824 add_timer(&hba->destroy_timer);
1825 wait_event_interruptible(hba->destroy_wait,
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001826 test_bit(BNX2FC_FLAG_DESTROY_CMPL,
1827 &hba->flags));
Bhanu Prakash Gollapudicd703ae2011-08-04 17:38:43 -07001828 clear_bit(BNX2FC_FLAG_DESTROY_CMPL, &hba->flags);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001829 /* This should never happen */
1830 if (signal_pending(current))
1831 flush_signals(current);
1832
1833 del_timer_sync(&hba->destroy_timer);
1834 }
1835 bnx2fc_unbind_adapter_devices(hba);
1836 }
1837}
1838
1839/**
1840 * bnx2fc_ulp_stop - cnic callback to shutdown adapter instance
1841 *
1842 * @handle: transport handle pointing to adapter structure
1843 *
1844 * Driver checks if adapter is already in shutdown mode, if not start
1845 * the shutdown process.
1846 */
1847static void bnx2fc_ulp_stop(void *handle)
1848{
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001849 struct bnx2fc_hba *hba = handle;
1850 struct bnx2fc_interface *interface;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001851
1852 printk(KERN_ERR "ULP_STOP\n");
1853
1854 mutex_lock(&bnx2fc_dev_lock);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001855 if (!test_bit(BNX2FC_FLAG_FW_INIT_DONE, &hba->flags))
1856 goto exit;
1857 list_for_each_entry(interface, &if_list, list) {
1858 if (interface->hba == hba)
1859 bnx2fc_stop(interface);
1860 }
1861 BUG_ON(hba->num_ofld_sess != 0);
1862
1863 mutex_lock(&hba->hba_mutex);
1864 clear_bit(ADAPTER_STATE_UP, &hba->adapter_state);
1865 clear_bit(ADAPTER_STATE_GOING_DOWN,
1866 &hba->adapter_state);
1867
1868 clear_bit(ADAPTER_STATE_READY, &hba->adapter_state);
1869 mutex_unlock(&hba->hba_mutex);
1870
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001871 bnx2fc_fw_destroy(hba);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001872exit:
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001873 mutex_unlock(&bnx2fc_dev_lock);
1874}
1875
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001876static void bnx2fc_start_disc(struct bnx2fc_interface *interface)
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001877{
Robert Lovefd8f8902012-05-22 19:06:16 -07001878 struct fcoe_ctlr *ctlr = bnx2fc_to_ctlr(interface);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001879 struct fc_lport *lport;
1880 int wait_cnt = 0;
1881
1882 BNX2FC_MISC_DBG("Entered %s\n", __func__);
1883 /* Kick off FIP/FLOGI */
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001884 if (!test_bit(BNX2FC_FLAG_FW_INIT_DONE, &interface->hba->flags)) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001885 printk(KERN_ERR PFX "Init not done yet\n");
1886 return;
1887 }
1888
Robert Lovefd8f8902012-05-22 19:06:16 -07001889 lport = ctlr->lp;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001890 BNX2FC_HBA_DBG(lport, "calling fc_fabric_login\n");
1891
Bhanu Prakash Gollapudi8a5badf2011-08-30 15:54:48 -07001892 if (!bnx2fc_link_ok(lport) && interface->enabled) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001893 BNX2FC_HBA_DBG(lport, "ctlr_link_up\n");
Robert Lovefd8f8902012-05-22 19:06:16 -07001894 fcoe_ctlr_link_up(ctlr);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001895 fc_host_port_type(lport->host) = FC_PORTTYPE_NPORT;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001896 set_bit(ADAPTER_STATE_READY, &interface->hba->adapter_state);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001897 }
1898
1899 /* wait for the FCF to be selected before issuing FLOGI */
Robert Lovefd8f8902012-05-22 19:06:16 -07001900 while (!ctlr->sel_fcf) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001901 msleep(250);
1902 /* give up after 3 secs */
1903 if (++wait_cnt > 12)
1904 break;
1905 }
Bhanu Prakash Gollapudi627e6282011-08-04 17:38:35 -07001906
1907 /* Reset max receive frame size to default */
1908 if (fc_set_mfs(lport, BNX2FC_MFS))
1909 return;
1910
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001911 fc_lport_init(lport);
1912 fc_fabric_login(lport);
1913}
1914
1915
1916/**
1917 * bnx2fc_ulp_init - Initialize an adapter instance
1918 *
1919 * @dev : cnic device handle
1920 * Called from cnic_register_driver() context to initialize all
1921 * enumerated cnic devices. This routine allocates adapter structure
1922 * and other device specific resources.
1923 */
1924static void bnx2fc_ulp_init(struct cnic_dev *dev)
1925{
1926 struct bnx2fc_hba *hba;
1927 int rc = 0;
1928
1929 BNX2FC_MISC_DBG("Entered %s\n", __func__);
1930 /* bnx2fc works only when bnx2x is loaded */
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001931 if (!test_bit(CNIC_F_BNX2X_CLASS, &dev->flags) ||
1932 (dev->max_fcoe_conn == 0)) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001933 printk(KERN_ERR PFX "bnx2fc FCoE not supported on %s,"
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001934 " flags: %lx fcoe_conn: %d\n",
1935 dev->netdev->name, dev->flags, dev->max_fcoe_conn);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001936 return;
1937 }
1938
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001939 hba = bnx2fc_hba_create(dev);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001940 if (!hba) {
1941 printk(KERN_ERR PFX "hba initialization failed\n");
1942 return;
1943 }
1944
1945 /* Add HBA to the adapter list */
1946 mutex_lock(&bnx2fc_dev_lock);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001947 list_add_tail(&hba->list, &adapter_list);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001948 adapter_count++;
1949 mutex_unlock(&bnx2fc_dev_lock);
1950
Barak Witkowski2e499d32012-06-26 01:31:19 +00001951 dev->fcoe_cap = &hba->fcoe_cap;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001952 clear_bit(BNX2FC_CNIC_REGISTERED, &hba->reg_with_cnic);
1953 rc = dev->register_device(dev, CNIC_ULP_FCOE,
1954 (void *) hba);
1955 if (rc)
Bhanu Prakash Gollapudib2a554f2011-06-27 23:30:53 -07001956 printk(KERN_ERR PFX "register_device failed, rc = %d\n", rc);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001957 else
1958 set_bit(BNX2FC_CNIC_REGISTERED, &hba->reg_with_cnic);
1959}
1960
Robert Love6e89ea32012-11-27 06:53:40 +00001961/**
1962 * Deperecated: Use bnx2fc_enabled()
1963 */
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001964static int bnx2fc_disable(struct net_device *netdev)
1965{
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001966 struct bnx2fc_interface *interface;
Robert Lovefd8f8902012-05-22 19:06:16 -07001967 struct fcoe_ctlr *ctlr;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001968 int rc = 0;
1969
Nithin Sujir6702ca12011-03-17 17:13:27 -07001970 rtnl_lock();
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001971 mutex_lock(&bnx2fc_dev_lock);
1972
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001973 interface = bnx2fc_interface_lookup(netdev);
Robert Lovefd8f8902012-05-22 19:06:16 -07001974 ctlr = bnx2fc_to_ctlr(interface);
1975 if (!interface || !ctlr->lp) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001976 rc = -ENODEV;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001977 printk(KERN_ERR PFX "bnx2fc_disable: interface or lport not found\n");
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001978 } else {
Bhanu Prakash Gollapudi8a5badf2011-08-30 15:54:48 -07001979 interface->enabled = false;
Robert Lovefd8f8902012-05-22 19:06:16 -07001980 fcoe_ctlr_link_down(ctlr);
1981 fcoe_clean_pending_queue(ctlr->lp);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001982 }
1983
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001984 mutex_unlock(&bnx2fc_dev_lock);
1985 rtnl_unlock();
1986 return rc;
1987}
1988
Robert Love6e89ea32012-11-27 06:53:40 +00001989/**
1990 * Deprecated: Use bnx2fc_enabled()
1991 */
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001992static int bnx2fc_enable(struct net_device *netdev)
1993{
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001994 struct bnx2fc_interface *interface;
Robert Lovefd8f8902012-05-22 19:06:16 -07001995 struct fcoe_ctlr *ctlr;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001996 int rc = 0;
1997
Nithin Sujir6702ca12011-03-17 17:13:27 -07001998 rtnl_lock();
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001999 mutex_lock(&bnx2fc_dev_lock);
2000
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002001 interface = bnx2fc_interface_lookup(netdev);
Robert Lovefd8f8902012-05-22 19:06:16 -07002002 ctlr = bnx2fc_to_ctlr(interface);
2003 if (!interface || !ctlr->lp) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002004 rc = -ENODEV;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002005 printk(KERN_ERR PFX "bnx2fc_enable: interface or lport not found\n");
Robert Lovefd8f8902012-05-22 19:06:16 -07002006 } else if (!bnx2fc_link_ok(ctlr->lp)) {
2007 fcoe_ctlr_link_up(ctlr);
Bhanu Prakash Gollapudi8a5badf2011-08-30 15:54:48 -07002008 interface->enabled = true;
2009 }
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002010
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002011 mutex_unlock(&bnx2fc_dev_lock);
2012 rtnl_unlock();
2013 return rc;
2014}
2015
2016/**
Robert Love6e89ea32012-11-27 06:53:40 +00002017 * bnx2fc_ctlr_enabled() - Enable or disable an FCoE Controller
2018 * @cdev: The FCoE Controller that is being enabled or disabled
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002019 *
Robert Love6e89ea32012-11-27 06:53:40 +00002020 * fcoe_sysfs will ensure that the state of 'enabled' has
2021 * changed, so no checking is necessary here. This routine simply
2022 * calls fcoe_enable or fcoe_disable, both of which are deprecated.
2023 * When those routines are removed the functionality can be merged
2024 * here.
2025 */
2026static int bnx2fc_ctlr_enabled(struct fcoe_ctlr_device *cdev)
2027{
2028 struct fcoe_ctlr *ctlr = fcoe_ctlr_device_priv(cdev);
2029 struct fc_lport *lport = ctlr->lp;
2030 struct net_device *netdev = bnx2fc_netdev(lport);
2031
2032 switch (cdev->enabled) {
2033 case FCOE_CTLR_ENABLED:
2034 return bnx2fc_enable(netdev);
2035 case FCOE_CTLR_DISABLED:
2036 return bnx2fc_disable(netdev);
2037 case FCOE_CTLR_UNUSED:
2038 default:
2039 return -ENOTSUPP;
2040 };
2041}
2042
2043enum bnx2fc_create_link_state {
2044 BNX2FC_CREATE_LINK_DOWN,
2045 BNX2FC_CREATE_LINK_UP,
2046};
2047
2048/**
2049 * _bnx2fc_create() - Create bnx2fc FCoE interface
2050 * @netdev : The net_device object the Ethernet interface to create on
2051 * @fip_mode: The FIP mode for this creation
2052 * @link_state: The ctlr link state on creation
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002053 *
Robert Love6e89ea32012-11-27 06:53:40 +00002054 * Called from either the libfcoe 'create' module parameter
2055 * via fcoe_create or from fcoe_syfs's ctlr_create file.
2056 *
2057 * libfcoe's 'create' module parameter is deprecated so some
2058 * consolidation of code can be done when that interface is
2059 * removed.
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002060 *
2061 * Returns: 0 for success
2062 */
Robert Love6e89ea32012-11-27 06:53:40 +00002063static int _bnx2fc_create(struct net_device *netdev,
2064 enum fip_state fip_mode,
2065 enum bnx2fc_create_link_state link_state)
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002066{
Robert Love6e89ea32012-11-27 06:53:40 +00002067 struct fcoe_ctlr_device *cdev;
Robert Lovefd8f8902012-05-22 19:06:16 -07002068 struct fcoe_ctlr *ctlr;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002069 struct bnx2fc_interface *interface;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002070 struct bnx2fc_hba *hba;
Bhanu Prakash Gollapudi7adc5a32012-06-04 16:15:44 -07002071 struct net_device *phys_dev = netdev;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002072 struct fc_lport *lport;
2073 struct ethtool_drvinfo drvinfo;
2074 int rc = 0;
Bhanu Prakash Gollapudi7adc5a32012-06-04 16:15:44 -07002075 int vlan_id = 0;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002076
2077 BNX2FC_MISC_DBG("Entered bnx2fc_create\n");
2078 if (fip_mode != FIP_MODE_FABRIC) {
2079 printk(KERN_ERR "fip mode not FABRIC\n");
2080 return -EIO;
2081 }
2082
Nithin Sujir6702ca12011-03-17 17:13:27 -07002083 rtnl_lock();
2084
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002085 mutex_lock(&bnx2fc_dev_lock);
2086
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002087 if (!try_module_get(THIS_MODULE)) {
2088 rc = -EINVAL;
2089 goto mod_err;
2090 }
2091
2092 /* obtain physical netdev */
Bhanu Prakash Gollapudi7adc5a32012-06-04 16:15:44 -07002093 if (netdev->priv_flags & IFF_802_1Q_VLAN)
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002094 phys_dev = vlan_dev_real_dev(netdev);
Bhanu Prakash Gollapudi7adc5a32012-06-04 16:15:44 -07002095
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002096 /* verify if the physical device is a netxtreme2 device */
2097 if (phys_dev->ethtool_ops && phys_dev->ethtool_ops->get_drvinfo) {
2098 memset(&drvinfo, 0, sizeof(drvinfo));
2099 phys_dev->ethtool_ops->get_drvinfo(phys_dev, &drvinfo);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002100 if (strncmp(drvinfo.driver, "bnx2x", strlen("bnx2x"))) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002101 printk(KERN_ERR PFX "Not a netxtreme2 device\n");
2102 rc = -EINVAL;
2103 goto netdev_err;
2104 }
2105 } else {
2106 printk(KERN_ERR PFX "unable to obtain drv_info\n");
2107 rc = -EINVAL;
2108 goto netdev_err;
2109 }
2110
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002111 /* obtain interface and initialize rest of the structure */
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002112 hba = bnx2fc_hba_lookup(phys_dev);
2113 if (!hba) {
2114 rc = -ENODEV;
2115 printk(KERN_ERR PFX "bnx2fc_create: hba not found\n");
2116 goto netdev_err;
2117 }
2118
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002119 if (bnx2fc_interface_lookup(netdev)) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002120 rc = -EEXIST;
2121 goto netdev_err;
2122 }
2123
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002124 interface = bnx2fc_interface_create(hba, netdev, fip_mode);
2125 if (!interface) {
2126 printk(KERN_ERR PFX "bnx2fc_interface_create failed\n");
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002127 goto ifput_err;
2128 }
2129
Bhanu Prakash Gollapudi7adc5a32012-06-04 16:15:44 -07002130 if (netdev->priv_flags & IFF_802_1Q_VLAN) {
2131 vlan_id = vlan_dev_vlan_id(netdev);
2132 interface->vlan_enabled = 1;
2133 }
2134
Robert Lovefd8f8902012-05-22 19:06:16 -07002135 ctlr = bnx2fc_to_ctlr(interface);
Robert Love01bdcb62013-03-25 11:00:26 -07002136 cdev = fcoe_ctlr_to_ctlr_dev(ctlr);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002137 interface->vlan_id = vlan_id;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002138
2139 interface->timer_work_queue =
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002140 create_singlethread_workqueue("bnx2fc_timer_wq");
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002141 if (!interface->timer_work_queue) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002142 printk(KERN_ERR PFX "ulp_init could not create timer_wq\n");
2143 rc = -EINVAL;
2144 goto ifput_err;
2145 }
2146
Robert Love01bdcb62013-03-25 11:00:26 -07002147 lport = bnx2fc_if_create(interface, &cdev->dev, 0);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002148 if (!lport) {
2149 printk(KERN_ERR PFX "Failed to create interface (%s)\n",
2150 netdev->name);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002151 rc = -EINVAL;
2152 goto if_create_err;
2153 }
2154
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002155 /* Add interface to if_list */
2156 list_add_tail(&interface->list, &if_list);
2157
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002158 lport->boot_time = jiffies;
2159
2160 /* Make this master N_port */
Robert Lovefd8f8902012-05-22 19:06:16 -07002161 ctlr->lp = lport;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002162
Robert Love6e89ea32012-11-27 06:53:40 +00002163 if (link_state == BNX2FC_CREATE_LINK_UP)
2164 cdev->enabled = FCOE_CTLR_ENABLED;
2165 else
2166 cdev->enabled = FCOE_CTLR_DISABLED;
2167
2168 if (link_state == BNX2FC_CREATE_LINK_UP &&
2169 !bnx2fc_link_ok(lport)) {
Robert Lovefd8f8902012-05-22 19:06:16 -07002170 fcoe_ctlr_link_up(ctlr);
Bhanu Prakash Gollapudi8a5badf2011-08-30 15:54:48 -07002171 fc_host_port_type(lport->host) = FC_PORTTYPE_NPORT;
2172 set_bit(ADAPTER_STATE_READY, &interface->hba->adapter_state);
2173 }
2174
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002175 BNX2FC_HBA_DBG(lport, "create: START DISC\n");
2176 bnx2fc_start_disc(interface);
Robert Love6e89ea32012-11-27 06:53:40 +00002177
2178 if (link_state == BNX2FC_CREATE_LINK_UP)
2179 interface->enabled = true;
2180
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002181 /*
2182 * Release from kref_init in bnx2fc_interface_setup, on success
2183 * lport should be holding a reference taken in bnx2fc_if_create
2184 */
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002185 bnx2fc_interface_put(interface);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002186 /* put netdev that was held while calling dev_get_by_name */
2187 mutex_unlock(&bnx2fc_dev_lock);
2188 rtnl_unlock();
2189 return 0;
2190
2191if_create_err:
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002192 destroy_workqueue(interface->timer_work_queue);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002193ifput_err:
Bhanu Prakash Gollapudi013068f2011-08-30 15:54:52 -07002194 bnx2fc_net_cleanup(interface);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002195 bnx2fc_interface_put(interface);
Bhanu Prakash Gollapudi7d742f62012-01-23 18:00:48 -08002196 goto mod_err;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002197netdev_err:
2198 module_put(THIS_MODULE);
2199mod_err:
2200 mutex_unlock(&bnx2fc_dev_lock);
2201 rtnl_unlock();
2202 return rc;
2203}
2204
2205/**
Robert Love6e89ea32012-11-27 06:53:40 +00002206 * bnx2fc_create() - Create a bnx2fc interface
2207 * @netdev : The net_device object the Ethernet interface to create on
2208 * @fip_mode: The FIP mode for this creation
2209 *
2210 * Called from fcoe transport
2211 *
2212 * Returns: 0 for success
2213 */
2214static int bnx2fc_create(struct net_device *netdev, enum fip_state fip_mode)
2215{
2216 return _bnx2fc_create(netdev, fip_mode, BNX2FC_CREATE_LINK_UP);
2217}
2218
2219/**
2220 * bnx2fc_ctlr_alloc() - Allocate a bnx2fc interface from fcoe_sysfs
2221 * @netdev: The net_device to be used by the allocated FCoE Controller
2222 *
2223 * This routine is called from fcoe_sysfs. It will start the fcoe_ctlr
2224 * in a link_down state. The allows the user an opportunity to configure
2225 * the FCoE Controller from sysfs before enabling the FCoE Controller.
2226 *
2227 * Creating in with this routine starts the FCoE Controller in Fabric
2228 * mode. The user can change to VN2VN or another mode before enabling.
2229 */
2230static int bnx2fc_ctlr_alloc(struct net_device *netdev)
2231{
2232 return _bnx2fc_create(netdev, FIP_MODE_FABRIC,
2233 BNX2FC_CREATE_LINK_DOWN);
2234}
2235
2236/**
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002237 * bnx2fc_find_hba_for_cnic - maps cnic instance to bnx2fc hba instance
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002238 *
2239 * @cnic: Pointer to cnic device instance
2240 *
2241 **/
2242static struct bnx2fc_hba *bnx2fc_find_hba_for_cnic(struct cnic_dev *cnic)
2243{
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002244 struct bnx2fc_hba *hba;
2245
2246 /* Called with bnx2fc_dev_lock held */
Bhanu Prakash Gollapudid71fb3b2012-06-07 02:19:36 -07002247 list_for_each_entry(hba, &adapter_list, list) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002248 if (hba->cnic == cnic)
2249 return hba;
2250 }
2251 return NULL;
2252}
2253
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002254static struct bnx2fc_interface *bnx2fc_interface_lookup(struct net_device
2255 *netdev)
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002256{
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002257 struct bnx2fc_interface *interface;
2258
2259 /* Called with bnx2fc_dev_lock held */
2260 list_for_each_entry(interface, &if_list, list) {
2261 if (interface->netdev == netdev)
2262 return interface;
2263 }
2264 return NULL;
2265}
2266
2267static struct bnx2fc_hba *bnx2fc_hba_lookup(struct net_device
2268 *phys_dev)
2269{
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002270 struct bnx2fc_hba *hba;
2271
2272 /* Called with bnx2fc_dev_lock held */
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002273 list_for_each_entry(hba, &adapter_list, list) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002274 if (hba->phys_dev == phys_dev)
2275 return hba;
2276 }
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002277 printk(KERN_ERR PFX "adapter_lookup: hba NULL\n");
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002278 return NULL;
2279}
2280
2281/**
2282 * bnx2fc_ulp_exit - shuts down adapter instance and frees all resources
2283 *
2284 * @dev cnic device handle
2285 */
2286static void bnx2fc_ulp_exit(struct cnic_dev *dev)
2287{
2288 struct bnx2fc_hba *hba;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002289 struct bnx2fc_interface *interface, *tmp;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002290
2291 BNX2FC_MISC_DBG("Entered bnx2fc_ulp_exit\n");
2292
2293 if (!test_bit(CNIC_F_BNX2X_CLASS, &dev->flags)) {
2294 printk(KERN_ERR PFX "bnx2fc port check: %s, flags: %lx\n",
2295 dev->netdev->name, dev->flags);
2296 return;
2297 }
2298
2299 mutex_lock(&bnx2fc_dev_lock);
2300 hba = bnx2fc_find_hba_for_cnic(dev);
2301 if (!hba) {
2302 printk(KERN_ERR PFX "bnx2fc_ulp_exit: hba not found, dev 0%p\n",
2303 dev);
2304 mutex_unlock(&bnx2fc_dev_lock);
2305 return;
2306 }
2307
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002308 list_del_init(&hba->list);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002309 adapter_count--;
2310
Bhanu Prakash Gollapudiabc49a92011-08-04 17:38:42 -07002311 list_for_each_entry_safe(interface, tmp, &if_list, list)
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002312 /* destroy not called yet, move to quiesced list */
Bhanu Prakash Gollapudiabc49a92011-08-04 17:38:42 -07002313 if (interface->hba == hba)
Bhanu Prakash Gollapudieccdcd02011-08-24 18:56:42 -07002314 __bnx2fc_destroy(interface);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002315 mutex_unlock(&bnx2fc_dev_lock);
2316
2317 bnx2fc_ulp_stop(hba);
2318 /* unregister cnic device */
2319 if (test_and_clear_bit(BNX2FC_CNIC_REGISTERED, &hba->reg_with_cnic))
2320 hba->cnic->unregister_device(hba->cnic, CNIC_ULP_FCOE);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002321 bnx2fc_hba_destroy(hba);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002322}
2323
2324/**
2325 * bnx2fc_fcoe_reset - Resets the fcoe
2326 *
2327 * @shost: shost the reset is from
2328 *
2329 * Returns: always 0
2330 */
2331static int bnx2fc_fcoe_reset(struct Scsi_Host *shost)
2332{
2333 struct fc_lport *lport = shost_priv(shost);
2334 fc_lport_reset(lport);
2335 return 0;
2336}
2337
2338
2339static bool bnx2fc_match(struct net_device *netdev)
2340{
Bhanu Prakash Gollapudi7adc5a32012-06-04 16:15:44 -07002341 struct net_device *phys_dev = netdev;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002342
Bhanu Prakash Gollapudi7adc5a32012-06-04 16:15:44 -07002343 mutex_lock(&bnx2fc_dev_lock);
2344 if (netdev->priv_flags & IFF_802_1Q_VLAN)
2345 phys_dev = vlan_dev_real_dev(netdev);
2346
2347 if (bnx2fc_hba_lookup(phys_dev)) {
2348 mutex_unlock(&bnx2fc_dev_lock);
2349 return true;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002350 }
Bhanu Prakash Gollapudi7adc5a32012-06-04 16:15:44 -07002351
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002352 mutex_unlock(&bnx2fc_dev_lock);
2353 return false;
2354}
2355
2356
2357static struct fcoe_transport bnx2fc_transport = {
2358 .name = {"bnx2fc"},
2359 .attached = false,
2360 .list = LIST_HEAD_INIT(bnx2fc_transport.list),
Robert Love6e89ea32012-11-27 06:53:40 +00002361 .alloc = bnx2fc_ctlr_alloc,
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002362 .match = bnx2fc_match,
2363 .create = bnx2fc_create,
2364 .destroy = bnx2fc_destroy,
2365 .enable = bnx2fc_enable,
2366 .disable = bnx2fc_disable,
2367};
2368
2369/**
2370 * bnx2fc_percpu_thread_create - Create a receive thread for an
2371 * online CPU
2372 *
2373 * @cpu: cpu index for the online cpu
2374 */
2375static void bnx2fc_percpu_thread_create(unsigned int cpu)
2376{
2377 struct bnx2fc_percpu_s *p;
2378 struct task_struct *thread;
2379
2380 p = &per_cpu(bnx2fc_percpu, cpu);
2381
Eric Dumazet69614272012-06-04 16:15:42 -07002382 thread = kthread_create_on_node(bnx2fc_percpu_io_thread,
2383 (void *)p, cpu_to_node(cpu),
2384 "bnx2fc_thread/%d", cpu);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002385 /* bind thread to the cpu */
Bhanu Prakash Gollapudi32248762011-08-04 17:38:36 -07002386 if (likely(!IS_ERR(thread))) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002387 kthread_bind(thread, cpu);
2388 p->iothread = thread;
2389 wake_up_process(thread);
2390 }
2391}
2392
2393static void bnx2fc_percpu_thread_destroy(unsigned int cpu)
2394{
2395 struct bnx2fc_percpu_s *p;
2396 struct task_struct *thread;
2397 struct bnx2fc_work *work, *tmp;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002398
2399 BNX2FC_MISC_DBG("destroying io thread for CPU %d\n", cpu);
2400
2401 /* Prevent any new work from being queued for this CPU */
2402 p = &per_cpu(bnx2fc_percpu, cpu);
2403 spin_lock_bh(&p->fp_work_lock);
2404 thread = p->iothread;
2405 p->iothread = NULL;
2406
2407
2408 /* Free all work in the list */
Bhanu Prakash Gollapudi32248762011-08-04 17:38:36 -07002409 list_for_each_entry_safe(work, tmp, &p->work_list, list) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002410 list_del_init(&work->list);
2411 bnx2fc_process_cq_compl(work->tgt, work->wqe);
2412 kfree(work);
2413 }
2414
2415 spin_unlock_bh(&p->fp_work_lock);
2416
2417 if (thread)
2418 kthread_stop(thread);
2419}
2420
2421/**
2422 * bnx2fc_cpu_callback - Handler for CPU hotplug events
2423 *
2424 * @nfb: The callback data block
2425 * @action: The event triggering the callback
2426 * @hcpu: The index of the CPU that the event is for
2427 *
2428 * This creates or destroys per-CPU data for fcoe
2429 *
2430 * Returns NOTIFY_OK always.
2431 */
2432static int bnx2fc_cpu_callback(struct notifier_block *nfb,
2433 unsigned long action, void *hcpu)
2434{
2435 unsigned cpu = (unsigned long)hcpu;
2436
2437 switch (action) {
2438 case CPU_ONLINE:
2439 case CPU_ONLINE_FROZEN:
2440 printk(PFX "CPU %x online: Create Rx thread\n", cpu);
2441 bnx2fc_percpu_thread_create(cpu);
2442 break;
2443 case CPU_DEAD:
2444 case CPU_DEAD_FROZEN:
2445 printk(PFX "CPU %x offline: Remove Rx thread\n", cpu);
2446 bnx2fc_percpu_thread_destroy(cpu);
2447 break;
2448 default:
2449 break;
2450 }
2451 return NOTIFY_OK;
2452}
2453
2454/**
2455 * bnx2fc_mod_init - module init entry point
2456 *
2457 * Initialize driver wide global data structures, and register
2458 * with cnic module
2459 **/
2460static int __init bnx2fc_mod_init(void)
2461{
2462 struct fcoe_percpu_s *bg;
2463 struct task_struct *l2_thread;
2464 int rc = 0;
2465 unsigned int cpu = 0;
2466 struct bnx2fc_percpu_s *p;
2467
2468 printk(KERN_INFO PFX "%s", version);
2469
2470 /* register as a fcoe transport */
2471 rc = fcoe_transport_attach(&bnx2fc_transport);
2472 if (rc) {
2473 printk(KERN_ERR "failed to register an fcoe transport, check "
2474 "if libfcoe is loaded\n");
2475 goto out;
2476 }
2477
2478 INIT_LIST_HEAD(&adapter_list);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002479 INIT_LIST_HEAD(&if_list);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002480 mutex_init(&bnx2fc_dev_lock);
2481 adapter_count = 0;
2482
2483 /* Attach FC transport template */
2484 rc = bnx2fc_attach_transport();
2485 if (rc)
2486 goto detach_ft;
2487
2488 bnx2fc_wq = alloc_workqueue("bnx2fc", 0, 0);
2489 if (!bnx2fc_wq) {
2490 rc = -ENOMEM;
2491 goto release_bt;
2492 }
2493
2494 bg = &bnx2fc_global;
2495 skb_queue_head_init(&bg->fcoe_rx_list);
2496 l2_thread = kthread_create(bnx2fc_l2_rcv_thread,
2497 (void *)bg,
2498 "bnx2fc_l2_thread");
2499 if (IS_ERR(l2_thread)) {
2500 rc = PTR_ERR(l2_thread);
2501 goto free_wq;
2502 }
2503 wake_up_process(l2_thread);
2504 spin_lock_bh(&bg->fcoe_rx_list.lock);
2505 bg->thread = l2_thread;
2506 spin_unlock_bh(&bg->fcoe_rx_list.lock);
2507
2508 for_each_possible_cpu(cpu) {
2509 p = &per_cpu(bnx2fc_percpu, cpu);
2510 INIT_LIST_HEAD(&p->work_list);
2511 spin_lock_init(&p->fp_work_lock);
2512 }
2513
2514 for_each_online_cpu(cpu) {
2515 bnx2fc_percpu_thread_create(cpu);
2516 }
2517
2518 /* Initialize per CPU interrupt thread */
2519 register_hotcpu_notifier(&bnx2fc_cpu_notifier);
2520
2521 cnic_register_driver(CNIC_ULP_FCOE, &bnx2fc_cnic_cb);
2522
2523 return 0;
2524
2525free_wq:
2526 destroy_workqueue(bnx2fc_wq);
2527release_bt:
2528 bnx2fc_release_transport();
2529detach_ft:
2530 fcoe_transport_detach(&bnx2fc_transport);
2531out:
2532 return rc;
2533}
2534
2535static void __exit bnx2fc_mod_exit(void)
2536{
2537 LIST_HEAD(to_be_deleted);
2538 struct bnx2fc_hba *hba, *next;
2539 struct fcoe_percpu_s *bg;
2540 struct task_struct *l2_thread;
2541 struct sk_buff *skb;
2542 unsigned int cpu = 0;
2543
2544 /*
2545 * NOTE: Since cnic calls register_driver routine rtnl_lock,
2546 * it will have higher precedence than bnx2fc_dev_lock.
2547 * unregister_device() cannot be called with bnx2fc_dev_lock
2548 * held.
2549 */
2550 mutex_lock(&bnx2fc_dev_lock);
2551 list_splice(&adapter_list, &to_be_deleted);
2552 INIT_LIST_HEAD(&adapter_list);
2553 adapter_count = 0;
2554 mutex_unlock(&bnx2fc_dev_lock);
2555
2556 /* Unregister with cnic */
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002557 list_for_each_entry_safe(hba, next, &to_be_deleted, list) {
2558 list_del_init(&hba->list);
2559 printk(KERN_ERR PFX "MOD_EXIT:destroy hba = 0x%p\n",
2560 hba);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002561 bnx2fc_ulp_stop(hba);
2562 /* unregister cnic device */
2563 if (test_and_clear_bit(BNX2FC_CNIC_REGISTERED,
2564 &hba->reg_with_cnic))
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002565 hba->cnic->unregister_device(hba->cnic,
2566 CNIC_ULP_FCOE);
2567 bnx2fc_hba_destroy(hba);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002568 }
2569 cnic_unregister_driver(CNIC_ULP_FCOE);
2570
2571 /* Destroy global thread */
2572 bg = &bnx2fc_global;
2573 spin_lock_bh(&bg->fcoe_rx_list.lock);
2574 l2_thread = bg->thread;
2575 bg->thread = NULL;
2576 while ((skb = __skb_dequeue(&bg->fcoe_rx_list)) != NULL)
2577 kfree_skb(skb);
2578
2579 spin_unlock_bh(&bg->fcoe_rx_list.lock);
2580
2581 if (l2_thread)
2582 kthread_stop(l2_thread);
2583
2584 unregister_hotcpu_notifier(&bnx2fc_cpu_notifier);
2585
2586 /* Destroy per cpu threads */
2587 for_each_online_cpu(cpu) {
2588 bnx2fc_percpu_thread_destroy(cpu);
2589 }
2590
2591 destroy_workqueue(bnx2fc_wq);
2592 /*
2593 * detach from scsi transport
2594 * must happen after all destroys are done
2595 */
2596 bnx2fc_release_transport();
2597
2598 /* detach from fcoe transport */
2599 fcoe_transport_detach(&bnx2fc_transport);
2600}
2601
2602module_init(bnx2fc_mod_init);
2603module_exit(bnx2fc_mod_exit);
2604
Robert Love8d55e502012-05-22 19:06:26 -07002605static struct fcoe_sysfs_function_template bnx2fc_fcoe_sysfs_templ = {
Robert Love6e89ea32012-11-27 06:53:40 +00002606 .set_fcoe_ctlr_enabled = bnx2fc_ctlr_enabled,
Yi Zoub8b3e692012-12-06 06:24:59 +00002607 .get_fcoe_ctlr_link_fail = fcoe_ctlr_get_lesb,
2608 .get_fcoe_ctlr_vlink_fail = fcoe_ctlr_get_lesb,
2609 .get_fcoe_ctlr_miss_fka = fcoe_ctlr_get_lesb,
2610 .get_fcoe_ctlr_symb_err = fcoe_ctlr_get_lesb,
2611 .get_fcoe_ctlr_err_block = fcoe_ctlr_get_lesb,
2612 .get_fcoe_ctlr_fcs_error = fcoe_ctlr_get_lesb,
Robert Love8d55e502012-05-22 19:06:26 -07002613
2614 .get_fcoe_fcf_selected = fcoe_fcf_get_selected,
2615 .get_fcoe_fcf_vlan_id = bnx2fc_fcf_get_vlan_id,
2616};
2617
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002618static struct fc_function_template bnx2fc_transport_function = {
2619 .show_host_node_name = 1,
2620 .show_host_port_name = 1,
2621 .show_host_supported_classes = 1,
2622 .show_host_supported_fc4s = 1,
2623 .show_host_active_fc4s = 1,
2624 .show_host_maxframe_size = 1,
2625
2626 .show_host_port_id = 1,
2627 .show_host_supported_speeds = 1,
2628 .get_host_speed = fc_get_host_speed,
2629 .show_host_speed = 1,
2630 .show_host_port_type = 1,
2631 .get_host_port_state = fc_get_host_port_state,
2632 .show_host_port_state = 1,
2633 .show_host_symbolic_name = 1,
2634
2635 .dd_fcrport_size = (sizeof(struct fc_rport_libfc_priv) +
2636 sizeof(struct bnx2fc_rport)),
2637 .show_rport_maxframe_size = 1,
2638 .show_rport_supported_classes = 1,
2639
2640 .show_host_fabric_name = 1,
2641 .show_starget_node_name = 1,
2642 .show_starget_port_name = 1,
2643 .show_starget_port_id = 1,
2644 .set_rport_dev_loss_tmo = fc_set_rport_loss_tmo,
2645 .show_rport_dev_loss_tmo = 1,
2646 .get_fc_host_stats = bnx2fc_get_host_stats,
2647
2648 .issue_fc_host_lip = bnx2fc_fcoe_reset,
2649
2650 .terminate_rport_io = fc_rport_terminate_io,
2651
2652 .vport_create = bnx2fc_vport_create,
2653 .vport_delete = bnx2fc_vport_destroy,
2654 .vport_disable = bnx2fc_vport_disable,
Bhanu Prakash Gollapudie9a5289c2011-08-04 17:38:37 -07002655 .bsg_request = fc_lport_bsg_request,
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002656};
2657
2658static struct fc_function_template bnx2fc_vport_xport_function = {
2659 .show_host_node_name = 1,
2660 .show_host_port_name = 1,
2661 .show_host_supported_classes = 1,
2662 .show_host_supported_fc4s = 1,
2663 .show_host_active_fc4s = 1,
2664 .show_host_maxframe_size = 1,
2665
2666 .show_host_port_id = 1,
2667 .show_host_supported_speeds = 1,
2668 .get_host_speed = fc_get_host_speed,
2669 .show_host_speed = 1,
2670 .show_host_port_type = 1,
2671 .get_host_port_state = fc_get_host_port_state,
2672 .show_host_port_state = 1,
2673 .show_host_symbolic_name = 1,
2674
2675 .dd_fcrport_size = (sizeof(struct fc_rport_libfc_priv) +
2676 sizeof(struct bnx2fc_rport)),
2677 .show_rport_maxframe_size = 1,
2678 .show_rport_supported_classes = 1,
2679
2680 .show_host_fabric_name = 1,
2681 .show_starget_node_name = 1,
2682 .show_starget_port_name = 1,
2683 .show_starget_port_id = 1,
2684 .set_rport_dev_loss_tmo = fc_set_rport_loss_tmo,
2685 .show_rport_dev_loss_tmo = 1,
2686 .get_fc_host_stats = fc_get_host_stats,
2687 .issue_fc_host_lip = bnx2fc_fcoe_reset,
2688 .terminate_rport_io = fc_rport_terminate_io,
Bhanu Prakash Gollapudie9a5289c2011-08-04 17:38:37 -07002689 .bsg_request = fc_lport_bsg_request,
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002690};
2691
2692/**
2693 * scsi_host_template structure used while registering with SCSI-ml
2694 */
2695static struct scsi_host_template bnx2fc_shost_template = {
2696 .module = THIS_MODULE,
2697 .name = "Broadcom Offload FCoE Initiator",
2698 .queuecommand = bnx2fc_queuecommand,
2699 .eh_abort_handler = bnx2fc_eh_abort, /* abts */
2700 .eh_device_reset_handler = bnx2fc_eh_device_reset, /* lun reset */
2701 .eh_target_reset_handler = bnx2fc_eh_target_reset, /* tgt reset */
2702 .eh_host_reset_handler = fc_eh_host_reset,
2703 .slave_alloc = fc_slave_alloc,
2704 .change_queue_depth = fc_change_queue_depth,
2705 .change_queue_type = fc_change_queue_type,
2706 .this_id = -1,
2707 .cmd_per_lun = 3,
Bhanu Gollapudi0ea5c272011-03-17 17:13:29 -07002708 .can_queue = BNX2FC_CAN_QUEUE,
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002709 .use_clustering = ENABLE_CLUSTERING,
2710 .sg_tablesize = BNX2FC_MAX_BDS_PER_CMD,
Bhanu Prakash Gollapudid450d772012-12-21 19:40:33 -08002711 .max_sectors = 1024,
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002712};
2713
2714static struct libfc_function_template bnx2fc_libfc_fcn_templ = {
2715 .frame_send = bnx2fc_xmit,
2716 .elsct_send = bnx2fc_elsct_send,
2717 .fcp_abort_io = bnx2fc_abort_io,
2718 .fcp_cleanup = bnx2fc_cleanup,
Yi Zoub8b3e692012-12-06 06:24:59 +00002719 .get_lesb = fcoe_get_lesb,
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002720 .rport_event_callback = bnx2fc_rport_event_handler,
2721};
2722
2723/**
2724 * bnx2fc_cnic_cb - global template of bnx2fc - cnic driver interface
2725 * structure carrying callback function pointers
2726 */
2727static struct cnic_ulp_ops bnx2fc_cnic_cb = {
2728 .owner = THIS_MODULE,
2729 .cnic_init = bnx2fc_ulp_init,
2730 .cnic_exit = bnx2fc_ulp_exit,
2731 .cnic_start = bnx2fc_ulp_start,
2732 .cnic_stop = bnx2fc_ulp_stop,
2733 .indicate_kcqes = bnx2fc_indicate_kcqe,
2734 .indicate_netevent = bnx2fc_indicate_netevent,
Barak Witkowski2e499d32012-06-26 01:31:19 +00002735 .cnic_get_stats = bnx2fc_ulp_get_stats,
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002736};