blob: 4d5c7215934648f7fa59863cfa18a2b8c8ff7eb0 [file] [log] [blame]
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001/* bnx2fc_fcoe.c: Broadcom NetXtreme II Linux FCoE offload driver.
2 * This file contains the code that interacts with libfc, libfcoe,
3 * cnic modules to create FCoE instances, send/receive non-offloaded
4 * FIP/FCoE packets, listen to link events etc.
5 *
Bhanu Prakash Gollapudi9b35baa2011-07-27 11:32:13 -07006 * Copyright (c) 2008 - 2011 Broadcom Corporation
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08007 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation.
11 *
12 * Written by: Bhanu Prakash Gollapudi (bprakash@broadcom.com)
13 */
14
15#include "bnx2fc.h"
16
17static struct list_head adapter_list;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -070018static struct list_head if_list;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -080019static u32 adapter_count;
20static DEFINE_MUTEX(bnx2fc_dev_lock);
21DEFINE_PER_CPU(struct bnx2fc_percpu_s, bnx2fc_percpu);
22
23#define DRV_MODULE_NAME "bnx2fc"
24#define DRV_MODULE_VERSION BNX2FC_VERSION
Bhanu Prakash Gollapudieb47aa2c2012-06-07 02:19:37 -070025#define DRV_MODULE_RELDATE "Jun 04, 2012"
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -080026
27
28static char version[] __devinitdata =
29 "Broadcom NetXtreme II FCoE Driver " DRV_MODULE_NAME \
30 " v" DRV_MODULE_VERSION " (" DRV_MODULE_RELDATE ")\n";
31
32
33MODULE_AUTHOR("Bhanu Prakash Gollapudi <bprakash@broadcom.com>");
34MODULE_DESCRIPTION("Broadcom NetXtreme II BCM57710 FCoE Driver");
35MODULE_LICENSE("GPL");
36MODULE_VERSION(DRV_MODULE_VERSION);
37
38#define BNX2FC_MAX_QUEUE_DEPTH 256
39#define BNX2FC_MIN_QUEUE_DEPTH 32
40#define FCOE_WORD_TO_BYTE 4
41
42static struct scsi_transport_template *bnx2fc_transport_template;
43static struct scsi_transport_template *bnx2fc_vport_xport_template;
44
45struct workqueue_struct *bnx2fc_wq;
46
47/* bnx2fc structure needs only one instance of the fcoe_percpu_s structure.
48 * Here the io threads are per cpu but the l2 thread is just one
49 */
50struct fcoe_percpu_s bnx2fc_global;
51DEFINE_SPINLOCK(bnx2fc_global_lock);
52
53static struct cnic_ulp_ops bnx2fc_cnic_cb;
54static struct libfc_function_template bnx2fc_libfc_fcn_templ;
55static struct scsi_host_template bnx2fc_shost_template;
56static struct fc_function_template bnx2fc_transport_function;
Robert Love8d55e502012-05-22 19:06:26 -070057static struct fcoe_sysfs_function_template bnx2fc_fcoe_sysfs_templ;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -080058static struct fc_function_template bnx2fc_vport_xport_function;
59static int bnx2fc_create(struct net_device *netdev, enum fip_state fip_mode);
Bhanu Prakash Gollapudieccdcd02011-08-24 18:56:42 -070060static void __bnx2fc_destroy(struct bnx2fc_interface *interface);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -080061static int bnx2fc_destroy(struct net_device *net_device);
62static int bnx2fc_enable(struct net_device *netdev);
63static int bnx2fc_disable(struct net_device *netdev);
64
Robert Love6e89ea32012-11-27 06:53:40 +000065/* fcoe_syfs control interface handlers */
66static int bnx2fc_ctlr_alloc(struct net_device *netdev);
67static int bnx2fc_ctlr_enabled(struct fcoe_ctlr_device *cdev);
68
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -080069static void bnx2fc_recv_frame(struct sk_buff *skb);
70
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -070071static void bnx2fc_start_disc(struct bnx2fc_interface *interface);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -080072static int bnx2fc_shost_config(struct fc_lport *lport, struct device *dev);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -080073static int bnx2fc_lport_config(struct fc_lport *lport);
74static int bnx2fc_em_config(struct fc_lport *lport);
75static int bnx2fc_bind_adapter_devices(struct bnx2fc_hba *hba);
76static void bnx2fc_unbind_adapter_devices(struct bnx2fc_hba *hba);
77static int bnx2fc_bind_pcidev(struct bnx2fc_hba *hba);
78static void bnx2fc_unbind_pcidev(struct bnx2fc_hba *hba);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -070079static struct fc_lport *bnx2fc_if_create(struct bnx2fc_interface *interface,
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -080080 struct device *parent, int npiv);
81static void bnx2fc_destroy_work(struct work_struct *work);
82
83static struct bnx2fc_hba *bnx2fc_hba_lookup(struct net_device *phys_dev);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -070084static struct bnx2fc_interface *bnx2fc_interface_lookup(struct net_device
85 *phys_dev);
Bhanu Prakash Gollapudiabc49a92011-08-04 17:38:42 -070086static inline void bnx2fc_interface_put(struct bnx2fc_interface *interface);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -080087static struct bnx2fc_hba *bnx2fc_find_hba_for_cnic(struct cnic_dev *cnic);
88
89static int bnx2fc_fw_init(struct bnx2fc_hba *hba);
90static void bnx2fc_fw_destroy(struct bnx2fc_hba *hba);
91
92static void bnx2fc_port_shutdown(struct fc_lport *lport);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -070093static void bnx2fc_stop(struct bnx2fc_interface *interface);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -080094static int __init bnx2fc_mod_init(void);
95static void __exit bnx2fc_mod_exit(void);
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 }
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300655 bnx2fc_stats->invalid_crc_count += fw_stats->rx_stat2.fc_crc_cnt;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800656 bnx2fc_stats->tx_frames += fw_stats->tx_stat.fcoe_tx_pkt_cnt;
657 bnx2fc_stats->tx_words += (fw_stats->tx_stat.fcoe_tx_byte_cnt) / 4;
658 bnx2fc_stats->rx_frames += fw_stats->rx_stat0.fcoe_rx_pkt_cnt;
659 bnx2fc_stats->rx_words += (fw_stats->rx_stat0.fcoe_rx_byte_cnt) / 4;
660
661 bnx2fc_stats->dumped_frames = 0;
662 bnx2fc_stats->lip_count = 0;
663 bnx2fc_stats->nos_count = 0;
664 bnx2fc_stats->loss_of_sync_count = 0;
665 bnx2fc_stats->loss_of_signal_count = 0;
666 bnx2fc_stats->prim_seq_protocol_err_count = 0;
667
668 return bnx2fc_stats;
669}
670
671static int bnx2fc_shost_config(struct fc_lport *lport, struct device *dev)
672{
673 struct fcoe_port *port = lport_priv(lport);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700674 struct bnx2fc_interface *interface = port->priv;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800675 struct Scsi_Host *shost = lport->host;
676 int rc = 0;
677
678 shost->max_cmd_len = BNX2FC_MAX_CMD_LEN;
679 shost->max_lun = BNX2FC_MAX_LUN;
680 shost->max_id = BNX2FC_MAX_FCP_TGT;
681 shost->max_channel = 0;
682 if (lport->vport)
683 shost->transportt = bnx2fc_vport_xport_template;
684 else
685 shost->transportt = bnx2fc_transport_template;
686
687 /* Add the new host to SCSI-ml */
688 rc = scsi_add_host(lport->host, dev);
689 if (rc) {
690 printk(KERN_ERR PFX "Error on scsi_add_host\n");
691 return rc;
692 }
693 if (!lport->vport)
694 fc_host_max_npiv_vports(lport->host) = USHRT_MAX;
695 sprintf(fc_host_symbolic_name(lport->host), "%s v%s over %s",
696 BNX2FC_NAME, BNX2FC_VERSION,
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700697 interface->netdev->name);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800698
699 return 0;
700}
701
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800702static int bnx2fc_link_ok(struct fc_lport *lport)
703{
704 struct fcoe_port *port = lport_priv(lport);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700705 struct bnx2fc_interface *interface = port->priv;
706 struct bnx2fc_hba *hba = interface->hba;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800707 struct net_device *dev = hba->phys_dev;
708 int rc = 0;
709
710 if ((dev->flags & IFF_UP) && netif_carrier_ok(dev))
711 clear_bit(ADAPTER_STATE_LINK_DOWN, &hba->adapter_state);
712 else {
713 set_bit(ADAPTER_STATE_LINK_DOWN, &hba->adapter_state);
714 rc = -1;
715 }
716 return rc;
717}
718
719/**
720 * bnx2fc_get_link_state - get network link state
721 *
722 * @hba: adapter instance pointer
723 *
724 * updates adapter structure flag based on netdev state
725 */
726void bnx2fc_get_link_state(struct bnx2fc_hba *hba)
727{
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700728 if (test_bit(__LINK_STATE_NOCARRIER, &hba->phys_dev->state))
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800729 set_bit(ADAPTER_STATE_LINK_DOWN, &hba->adapter_state);
730 else
731 clear_bit(ADAPTER_STATE_LINK_DOWN, &hba->adapter_state);
732}
733
Bhanu Prakash Gollapudi52439602011-08-04 17:38:50 -0700734static int bnx2fc_net_config(struct fc_lport *lport, struct net_device *netdev)
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800735{
736 struct bnx2fc_hba *hba;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700737 struct bnx2fc_interface *interface;
Robert Lovefd8f8902012-05-22 19:06:16 -0700738 struct fcoe_ctlr *ctlr;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800739 struct fcoe_port *port;
740 u64 wwnn, wwpn;
741
742 port = lport_priv(lport);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700743 interface = port->priv;
Robert Lovefd8f8902012-05-22 19:06:16 -0700744 ctlr = bnx2fc_to_ctlr(interface);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700745 hba = interface->hba;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800746
747 /* require support for get_pauseparam ethtool op. */
748 if (!hba->phys_dev->ethtool_ops ||
749 !hba->phys_dev->ethtool_ops->get_pauseparam)
750 return -EOPNOTSUPP;
751
Bhanu Gollapudi1294bfe2011-03-17 17:13:34 -0700752 if (fc_set_mfs(lport, BNX2FC_MFS))
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800753 return -EINVAL;
754
755 skb_queue_head_init(&port->fcoe_pending_queue);
756 port->fcoe_pending_queue_active = 0;
757 setup_timer(&port->timer, fcoe_queue_timer, (unsigned long) lport);
758
Yi Zou0e0f9cd2012-12-06 06:24:44 +0000759 fcoe_link_speed_update(lport);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800760
761 if (!lport->vport) {
Bhanu Prakash Gollapudi52439602011-08-04 17:38:50 -0700762 if (fcoe_get_wwn(netdev, &wwnn, NETDEV_FCOE_WWNN))
Robert Lovefd8f8902012-05-22 19:06:16 -0700763 wwnn = fcoe_wwn_from_mac(ctlr->ctl_src_addr,
Bhanu Prakash Gollapudi52439602011-08-04 17:38:50 -0700764 1, 0);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800765 BNX2FC_HBA_DBG(lport, "WWNN = 0x%llx\n", wwnn);
766 fc_set_wwnn(lport, wwnn);
767
Bhanu Prakash Gollapudi52439602011-08-04 17:38:50 -0700768 if (fcoe_get_wwn(netdev, &wwpn, NETDEV_FCOE_WWPN))
Robert Lovefd8f8902012-05-22 19:06:16 -0700769 wwpn = fcoe_wwn_from_mac(ctlr->ctl_src_addr,
Bhanu Prakash Gollapudi52439602011-08-04 17:38:50 -0700770 2, 0);
771
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800772 BNX2FC_HBA_DBG(lport, "WWPN = 0x%llx\n", wwpn);
773 fc_set_wwpn(lport, wwpn);
774 }
775
776 return 0;
777}
778
779static void bnx2fc_destroy_timer(unsigned long data)
780{
781 struct bnx2fc_hba *hba = (struct bnx2fc_hba *)data;
782
Bhanu Prakash Gollapudicd703ae2011-08-04 17:38:43 -0700783 printk(KERN_ERR PFX "ERROR:bnx2fc_destroy_timer - "
784 "Destroy compl not received!!\n");
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700785 set_bit(BNX2FC_FLAG_DESTROY_CMPL, &hba->flags);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800786 wake_up_interruptible(&hba->destroy_wait);
787}
788
789/**
790 * bnx2fc_indicate_netevent - Generic netdev event handler
791 *
792 * @context: adapter structure pointer
793 * @event: event type
Michael Chan415199f2011-07-20 14:55:24 +0000794 * @vlan_id: vlan id - associated vlan id with this event
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800795 *
796 * Handles NETDEV_UP, NETDEV_DOWN, NETDEV_GOING_DOWN,NETDEV_CHANGE and
Bhanu Prakash Gollapudiabc49a92011-08-04 17:38:42 -0700797 * NETDEV_CHANGE_MTU events. Handle NETDEV_UNREGISTER only for vlans.
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800798 */
Michael Chan415199f2011-07-20 14:55:24 +0000799static void bnx2fc_indicate_netevent(void *context, unsigned long event,
800 u16 vlan_id)
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800801{
802 struct bnx2fc_hba *hba = (struct bnx2fc_hba *)context;
Robert Love6e89ea32012-11-27 06:53:40 +0000803 struct fcoe_ctlr_device *cdev;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700804 struct fc_lport *lport;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800805 struct fc_lport *vport;
Bhanu Prakash Gollapudiabc49a92011-08-04 17:38:42 -0700806 struct bnx2fc_interface *interface, *tmp;
Robert Lovefd8f8902012-05-22 19:06:16 -0700807 struct fcoe_ctlr *ctlr;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700808 int wait_for_upload = 0;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800809 u32 link_possible = 1;
810
Bhanu Prakash Gollapudiabc49a92011-08-04 17:38:42 -0700811 if (vlan_id != 0 && event != NETDEV_UNREGISTER)
Michael Chan415199f2011-07-20 14:55:24 +0000812 return;
813
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800814 switch (event) {
815 case NETDEV_UP:
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800816 if (!test_bit(ADAPTER_STATE_UP, &hba->adapter_state))
817 printk(KERN_ERR "indicate_netevent: "\
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700818 "hba is not UP!!\n");
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800819 break;
820
821 case NETDEV_DOWN:
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800822 clear_bit(ADAPTER_STATE_GOING_DOWN, &hba->adapter_state);
823 clear_bit(ADAPTER_STATE_UP, &hba->adapter_state);
824 link_possible = 0;
825 break;
826
827 case NETDEV_GOING_DOWN:
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800828 set_bit(ADAPTER_STATE_GOING_DOWN, &hba->adapter_state);
829 link_possible = 0;
830 break;
831
832 case NETDEV_CHANGE:
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800833 break;
834
Bhanu Prakash Gollapudiabc49a92011-08-04 17:38:42 -0700835 case NETDEV_UNREGISTER:
836 if (!vlan_id)
837 return;
838 mutex_lock(&bnx2fc_dev_lock);
839 list_for_each_entry_safe(interface, tmp, &if_list, list) {
Nithin Nayak Sujir26b29822011-08-30 15:54:50 -0700840 if (interface->hba == hba &&
841 interface->vlan_id == (vlan_id & VLAN_VID_MASK))
842 __bnx2fc_destroy(interface);
Bhanu Prakash Gollapudiabc49a92011-08-04 17:38:42 -0700843 }
844 mutex_unlock(&bnx2fc_dev_lock);
845 return;
846
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800847 default:
Masanari Iida59e13d42012-04-25 00:24:16 +0900848 printk(KERN_ERR PFX "Unknown netevent %ld", event);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800849 return;
850 }
851
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700852 mutex_lock(&bnx2fc_dev_lock);
853 list_for_each_entry(interface, &if_list, list) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800854
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700855 if (interface->hba != hba)
856 continue;
857
Robert Lovefd8f8902012-05-22 19:06:16 -0700858 ctlr = bnx2fc_to_ctlr(interface);
859 lport = ctlr->lp;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700860 BNX2FC_HBA_DBG(lport, "netevent handler - event=%s %ld\n",
861 interface->netdev->name, event);
862
Yi Zou0e0f9cd2012-12-06 06:24:44 +0000863 fcoe_link_speed_update(lport);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700864
Robert Love6e89ea32012-11-27 06:53:40 +0000865 cdev = fcoe_ctlr_to_ctlr_dev(ctlr);
866
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700867 if (link_possible && !bnx2fc_link_ok(lport)) {
Robert Love6e89ea32012-11-27 06:53:40 +0000868 switch (cdev->enabled) {
869 case FCOE_CTLR_DISABLED:
870 pr_info("Link up while interface is disabled.\n");
871 break;
872 case FCOE_CTLR_ENABLED:
873 case FCOE_CTLR_UNUSED:
874 /* Reset max recv frame size to default */
875 fc_set_mfs(lport, BNX2FC_MFS);
876 /*
877 * ctlr link up will only be handled during
878 * enable to avoid sending discovery
879 * solicitation on a stale vlan
880 */
881 if (interface->enabled)
882 fcoe_ctlr_link_up(ctlr);
883 };
Robert Lovefd8f8902012-05-22 19:06:16 -0700884 } else if (fcoe_ctlr_link_down(ctlr)) {
Robert Love6e89ea32012-11-27 06:53:40 +0000885 switch (cdev->enabled) {
886 case FCOE_CTLR_DISABLED:
887 pr_info("Link down while interface is disabled.\n");
888 break;
889 case FCOE_CTLR_ENABLED:
890 case FCOE_CTLR_UNUSED:
891 mutex_lock(&lport->lp_mutex);
892 list_for_each_entry(vport, &lport->vports, list)
893 fc_host_port_type(vport->host) =
894 FC_PORTTYPE_UNKNOWN;
895 mutex_unlock(&lport->lp_mutex);
896 fc_host_port_type(lport->host) =
897 FC_PORTTYPE_UNKNOWN;
898 per_cpu_ptr(lport->stats,
899 get_cpu())->LinkFailureCount++;
900 put_cpu();
901 fcoe_clean_pending_queue(lport);
902 wait_for_upload = 1;
903 };
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800904 }
905 }
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700906 mutex_unlock(&bnx2fc_dev_lock);
907
908 if (wait_for_upload) {
909 clear_bit(ADAPTER_STATE_READY, &hba->adapter_state);
910 init_waitqueue_head(&hba->shutdown_wait);
911 BNX2FC_MISC_DBG("indicate_netevent "
912 "num_ofld_sess = %d\n",
913 hba->num_ofld_sess);
914 hba->wait_for_link_down = 1;
915 wait_event_interruptible(hba->shutdown_wait,
916 (hba->num_ofld_sess == 0));
917 BNX2FC_MISC_DBG("wakeup - num_ofld_sess = %d\n",
918 hba->num_ofld_sess);
919 hba->wait_for_link_down = 0;
920
921 if (signal_pending(current))
922 flush_signals(current);
923 }
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800924}
925
926static int bnx2fc_libfc_config(struct fc_lport *lport)
927{
928
929 /* Set the function pointers set by bnx2fc driver */
930 memcpy(&lport->tt, &bnx2fc_libfc_fcn_templ,
931 sizeof(struct libfc_function_template));
932 fc_elsct_init(lport);
933 fc_exch_init(lport);
934 fc_rport_init(lport);
935 fc_disc_init(lport);
936 return 0;
937}
938
939static int bnx2fc_em_config(struct fc_lport *lport)
940{
Bhanu Prakash Gollapudi7d742f62012-01-23 18:00:48 -0800941 int max_xid;
942
943 if (nr_cpu_ids <= 2)
944 max_xid = FCOE_XIDS_PER_CPU;
945 else
946 max_xid = FCOE_MAX_XID;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800947 if (!fc_exch_mgr_alloc(lport, FC_CLASS_3, FCOE_MIN_XID,
Bhanu Prakash Gollapudi7d742f62012-01-23 18:00:48 -0800948 max_xid, NULL)) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800949 printk(KERN_ERR PFX "em_config:fc_exch_mgr_alloc failed\n");
950 return -ENOMEM;
951 }
952
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800953 return 0;
954}
955
956static int bnx2fc_lport_config(struct fc_lport *lport)
957{
958 lport->link_up = 0;
959 lport->qfull = 0;
Bhanu Prakash Gollapudi44c570b2012-01-23 18:00:47 -0800960 lport->max_retry_count = BNX2FC_MAX_RETRY_CNT;
961 lport->max_rport_retry_count = BNX2FC_MAX_RPORT_RETRY_CNT;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800962 lport->e_d_tov = 2 * 1000;
963 lport->r_a_tov = 10 * 1000;
964
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800965 lport->service_params = (FCP_SPPF_INIT_FCN | FCP_SPPF_RD_XRDY_DIS |
966 FCP_SPPF_RETRY | FCP_SPPF_CONF_COMPL);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800967 lport->does_npiv = 1;
968
969 memset(&lport->rnid_gen, 0, sizeof(struct fc_els_rnid_gen));
970 lport->rnid_gen.rnid_atype = BNX2FC_RNID_HBA;
971
972 /* alloc stats structure */
973 if (fc_lport_init_stats(lport))
974 return -ENOMEM;
975
976 /* Finish fc_lport configuration */
977 fc_lport_config(lport);
978
979 return 0;
980}
981
982/**
983 * bnx2fc_fip_recv - handle a received FIP frame.
984 *
985 * @skb: the received skb
986 * @dev: associated &net_device
987 * @ptype: the &packet_type structure which was used to register this handler.
988 * @orig_dev: original receive &net_device, in case @ dev is a bond.
989 *
990 * Returns: 0 for success
991 */
992static int bnx2fc_fip_recv(struct sk_buff *skb, struct net_device *dev,
993 struct packet_type *ptype,
994 struct net_device *orig_dev)
995{
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700996 struct bnx2fc_interface *interface;
Robert Lovefd8f8902012-05-22 19:06:16 -0700997 struct fcoe_ctlr *ctlr;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700998 interface = container_of(ptype, struct bnx2fc_interface,
999 fip_packet_type);
Robert Lovefd8f8902012-05-22 19:06:16 -07001000 ctlr = bnx2fc_to_ctlr(interface);
1001 fcoe_ctlr_recv(ctlr, skb);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001002 return 0;
1003}
1004
1005/**
1006 * bnx2fc_update_src_mac - Update Ethernet MAC filters.
1007 *
1008 * @fip: FCoE controller.
1009 * @old: Unicast MAC address to delete if the MAC is non-zero.
1010 * @new: Unicast MAC address to add.
1011 *
1012 * Remove any previously-set unicast MAC filter.
1013 * Add secondary FCoE MAC address filter for our OUI.
1014 */
1015static void bnx2fc_update_src_mac(struct fc_lport *lport, u8 *addr)
1016{
1017 struct fcoe_port *port = lport_priv(lport);
1018
1019 memcpy(port->data_src_addr, addr, ETH_ALEN);
1020}
1021
1022/**
1023 * bnx2fc_get_src_mac - return the ethernet source address for an lport
1024 *
1025 * @lport: libfc port
1026 */
1027static u8 *bnx2fc_get_src_mac(struct fc_lport *lport)
1028{
1029 struct fcoe_port *port;
1030
1031 port = (struct fcoe_port *)lport_priv(lport);
1032 return port->data_src_addr;
1033}
1034
1035/**
1036 * bnx2fc_fip_send - send an Ethernet-encapsulated FIP frame.
1037 *
1038 * @fip: FCoE controller.
1039 * @skb: FIP Packet.
1040 */
1041static void bnx2fc_fip_send(struct fcoe_ctlr *fip, struct sk_buff *skb)
1042{
1043 skb->dev = bnx2fc_from_ctlr(fip)->netdev;
1044 dev_queue_xmit(skb);
1045}
1046
1047static int bnx2fc_vport_create(struct fc_vport *vport, bool disabled)
1048{
1049 struct Scsi_Host *shost = vport_to_shost(vport);
1050 struct fc_lport *n_port = shost_priv(shost);
1051 struct fcoe_port *port = lport_priv(n_port);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001052 struct bnx2fc_interface *interface = port->priv;
1053 struct net_device *netdev = interface->netdev;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001054 struct fc_lport *vn_port;
Bhanu Prakash Gollapudi861efc52011-08-04 17:38:51 -07001055 int rc;
1056 char buf[32];
1057
1058 rc = fcoe_validate_vport_create(vport);
1059 if (rc) {
1060 fcoe_wwn_to_str(vport->port_name, buf, sizeof(buf));
1061 printk(KERN_ERR PFX "Failed to create vport, "
1062 "WWPN (0x%s) already exists\n",
1063 buf);
1064 return rc;
1065 }
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001066
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001067 if (!test_bit(BNX2FC_FLAG_FW_INIT_DONE, &interface->hba->flags)) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001068 printk(KERN_ERR PFX "vn ports cannot be created on"
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001069 "this interface\n");
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001070 return -EIO;
1071 }
Jiri Pirko4bc71cb2011-09-03 03:34:30 +00001072 rtnl_lock();
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001073 mutex_lock(&bnx2fc_dev_lock);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001074 vn_port = bnx2fc_if_create(interface, &vport->dev, 1);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001075 mutex_unlock(&bnx2fc_dev_lock);
Jiri Pirko4bc71cb2011-09-03 03:34:30 +00001076 rtnl_unlock();
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001077
1078 if (IS_ERR(vn_port)) {
1079 printk(KERN_ERR PFX "bnx2fc_vport_create (%s) failed\n",
1080 netdev->name);
1081 return -EIO;
1082 }
1083
1084 if (disabled) {
1085 fc_vport_set_state(vport, FC_VPORT_DISABLED);
1086 } else {
1087 vn_port->boot_time = jiffies;
1088 fc_lport_init(vn_port);
1089 fc_fabric_login(vn_port);
1090 fc_vport_setlink(vn_port);
1091 }
1092 return 0;
1093}
1094
Bhanu Prakash Gollapudiabc49a92011-08-04 17:38:42 -07001095static void bnx2fc_free_vport(struct bnx2fc_hba *hba, struct fc_lport *lport)
1096{
1097 struct bnx2fc_lport *blport, *tmp;
1098
1099 spin_lock_bh(&hba->hba_lock);
1100 list_for_each_entry_safe(blport, tmp, &hba->vports, list) {
1101 if (blport->lport == lport) {
1102 list_del(&blport->list);
1103 kfree(blport);
1104 }
1105 }
1106 spin_unlock_bh(&hba->hba_lock);
1107}
1108
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001109static int bnx2fc_vport_destroy(struct fc_vport *vport)
1110{
1111 struct Scsi_Host *shost = vport_to_shost(vport);
1112 struct fc_lport *n_port = shost_priv(shost);
1113 struct fc_lport *vn_port = vport->dd_data;
1114 struct fcoe_port *port = lport_priv(vn_port);
Bhanu Prakash Gollapudiabc49a92011-08-04 17:38:42 -07001115 struct bnx2fc_interface *interface = port->priv;
Bhanu Prakash Gollapudicdf54662011-08-04 17:38:39 -07001116 struct fc_lport *v_port;
1117 bool found = false;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001118
1119 mutex_lock(&n_port->lp_mutex);
Bhanu Prakash Gollapudicdf54662011-08-04 17:38:39 -07001120 list_for_each_entry(v_port, &n_port->vports, list)
1121 if (v_port->vport == vport) {
1122 found = true;
1123 break;
1124 }
1125
1126 if (!found) {
1127 mutex_unlock(&n_port->lp_mutex);
1128 return -ENOENT;
1129 }
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001130 list_del(&vn_port->list);
1131 mutex_unlock(&n_port->lp_mutex);
Bhanu Prakash Gollapudiabc49a92011-08-04 17:38:42 -07001132 bnx2fc_free_vport(interface->hba, port->lport);
1133 bnx2fc_port_shutdown(port->lport);
1134 bnx2fc_interface_put(interface);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001135 queue_work(bnx2fc_wq, &port->destroy_work);
1136 return 0;
1137}
1138
1139static int bnx2fc_vport_disable(struct fc_vport *vport, bool disable)
1140{
1141 struct fc_lport *lport = vport->dd_data;
1142
1143 if (disable) {
1144 fc_vport_set_state(vport, FC_VPORT_DISABLED);
1145 fc_fabric_logoff(lport);
1146 } else {
1147 lport->boot_time = jiffies;
1148 fc_fabric_login(lport);
1149 fc_vport_setlink(lport);
1150 }
1151 return 0;
1152}
1153
1154
Bhanu Prakash Gollapudi776cebc2011-08-04 17:38:40 -07001155static int bnx2fc_interface_setup(struct bnx2fc_interface *interface)
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001156{
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001157 struct net_device *netdev = interface->netdev;
1158 struct net_device *physdev = interface->hba->phys_dev;
Robert Lovefd8f8902012-05-22 19:06:16 -07001159 struct fcoe_ctlr *ctlr = bnx2fc_to_ctlr(interface);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001160 struct netdev_hw_addr *ha;
1161 int sel_san_mac = 0;
1162
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001163 /* setup Source MAC Address */
1164 rcu_read_lock();
1165 for_each_dev_addr(physdev, ha) {
1166 BNX2FC_MISC_DBG("net_config: ha->type = %d, fip_mac = ",
1167 ha->type);
1168 printk(KERN_INFO "%2x:%2x:%2x:%2x:%2x:%2x\n", ha->addr[0],
1169 ha->addr[1], ha->addr[2], ha->addr[3],
1170 ha->addr[4], ha->addr[5]);
1171
1172 if ((ha->type == NETDEV_HW_ADDR_T_SAN) &&
1173 (is_valid_ether_addr(ha->addr))) {
Robert Lovefd8f8902012-05-22 19:06:16 -07001174 memcpy(ctlr->ctl_src_addr, ha->addr,
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001175 ETH_ALEN);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001176 sel_san_mac = 1;
1177 BNX2FC_MISC_DBG("Found SAN MAC\n");
1178 }
1179 }
1180 rcu_read_unlock();
1181
1182 if (!sel_san_mac)
1183 return -ENODEV;
1184
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001185 interface->fip_packet_type.func = bnx2fc_fip_recv;
1186 interface->fip_packet_type.type = htons(ETH_P_FIP);
1187 interface->fip_packet_type.dev = netdev;
1188 dev_add_pack(&interface->fip_packet_type);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001189
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001190 interface->fcoe_packet_type.func = bnx2fc_rcv;
1191 interface->fcoe_packet_type.type = __constant_htons(ETH_P_FCOE);
1192 interface->fcoe_packet_type.dev = netdev;
1193 dev_add_pack(&interface->fcoe_packet_type);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001194
1195 return 0;
1196}
1197
1198static int bnx2fc_attach_transport(void)
1199{
1200 bnx2fc_transport_template =
1201 fc_attach_transport(&bnx2fc_transport_function);
1202
1203 if (bnx2fc_transport_template == NULL) {
1204 printk(KERN_ERR PFX "Failed to attach FC transport\n");
1205 return -ENODEV;
1206 }
1207
1208 bnx2fc_vport_xport_template =
1209 fc_attach_transport(&bnx2fc_vport_xport_function);
1210 if (bnx2fc_vport_xport_template == NULL) {
1211 printk(KERN_ERR PFX
1212 "Failed to attach FC transport for vport\n");
1213 fc_release_transport(bnx2fc_transport_template);
1214 bnx2fc_transport_template = NULL;
1215 return -ENODEV;
1216 }
1217 return 0;
1218}
1219static void bnx2fc_release_transport(void)
1220{
1221 fc_release_transport(bnx2fc_transport_template);
1222 fc_release_transport(bnx2fc_vport_xport_template);
1223 bnx2fc_transport_template = NULL;
1224 bnx2fc_vport_xport_template = NULL;
1225}
1226
1227static void bnx2fc_interface_release(struct kref *kref)
1228{
Robert Love8d55e502012-05-22 19:06:26 -07001229 struct fcoe_ctlr_device *ctlr_dev;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001230 struct bnx2fc_interface *interface;
Robert Lovefd8f8902012-05-22 19:06:16 -07001231 struct fcoe_ctlr *ctlr;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001232 struct net_device *netdev;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001233
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001234 interface = container_of(kref, struct bnx2fc_interface, kref);
Nithin Nayak Sujir068bdce2011-04-25 12:30:09 -07001235 BNX2FC_MISC_DBG("Interface is being released\n");
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001236
Robert Lovefd8f8902012-05-22 19:06:16 -07001237 ctlr = bnx2fc_to_ctlr(interface);
Robert Love8d55e502012-05-22 19:06:26 -07001238 ctlr_dev = fcoe_ctlr_to_ctlr_dev(ctlr);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001239 netdev = interface->netdev;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001240
1241 /* tear-down FIP controller */
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001242 if (test_and_clear_bit(BNX2FC_CTLR_INIT_DONE, &interface->if_flags))
Robert Lovefd8f8902012-05-22 19:06:16 -07001243 fcoe_ctlr_destroy(ctlr);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001244
Robert Love8d55e502012-05-22 19:06:26 -07001245 fcoe_ctlr_device_delete(ctlr_dev);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001246
1247 dev_put(netdev);
1248 module_put(THIS_MODULE);
1249}
1250
1251static inline void bnx2fc_interface_get(struct bnx2fc_interface *interface)
1252{
1253 kref_get(&interface->kref);
1254}
1255
1256static inline void bnx2fc_interface_put(struct bnx2fc_interface *interface)
1257{
1258 kref_put(&interface->kref, bnx2fc_interface_release);
1259}
1260static void bnx2fc_hba_destroy(struct bnx2fc_hba *hba)
1261{
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001262 /* Free the command manager */
1263 if (hba->cmd_mgr) {
1264 bnx2fc_cmd_mgr_free(hba->cmd_mgr);
1265 hba->cmd_mgr = NULL;
1266 }
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001267 kfree(hba->tgt_ofld_list);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001268 bnx2fc_unbind_pcidev(hba);
1269 kfree(hba);
1270}
1271
1272/**
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001273 * bnx2fc_hba_create - create a new bnx2fc hba
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001274 *
1275 * @cnic: pointer to cnic device
1276 *
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001277 * Creates a new FCoE hba on the given device.
1278 *
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001279 */
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001280static struct bnx2fc_hba *bnx2fc_hba_create(struct cnic_dev *cnic)
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001281{
1282 struct bnx2fc_hba *hba;
Barak Witkowski2e499d32012-06-26 01:31:19 +00001283 struct fcoe_capabilities *fcoe_cap;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001284 int rc;
1285
1286 hba = kzalloc(sizeof(*hba), GFP_KERNEL);
1287 if (!hba) {
1288 printk(KERN_ERR PFX "Unable to allocate hba structure\n");
1289 return NULL;
1290 }
1291 spin_lock_init(&hba->hba_lock);
1292 mutex_init(&hba->hba_mutex);
1293
1294 hba->cnic = cnic;
1295 rc = bnx2fc_bind_pcidev(hba);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001296 if (rc) {
1297 printk(KERN_ERR PFX "create_adapter: bind error\n");
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001298 goto bind_err;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001299 }
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001300 hba->phys_dev = cnic->netdev;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001301 hba->next_conn_id = 0;
1302
1303 hba->tgt_ofld_list =
1304 kzalloc(sizeof(struct bnx2fc_rport *) * BNX2FC_NUM_MAX_SESS,
1305 GFP_KERNEL);
1306 if (!hba->tgt_ofld_list) {
1307 printk(KERN_ERR PFX "Unable to allocate tgt offload list\n");
1308 goto tgtofld_err;
1309 }
1310
1311 hba->num_ofld_sess = 0;
1312
1313 hba->cmd_mgr = bnx2fc_cmd_mgr_alloc(hba, BNX2FC_MIN_XID,
1314 BNX2FC_MAX_XID);
1315 if (!hba->cmd_mgr) {
1316 printk(KERN_ERR PFX "em_config:bnx2fc_cmd_mgr_alloc failed\n");
1317 goto cmgr_err;
1318 }
Barak Witkowski2e499d32012-06-26 01:31:19 +00001319 fcoe_cap = &hba->fcoe_cap;
1320
1321 fcoe_cap->capability1 = BNX2FC_TM_MAX_SQES <<
1322 FCOE_IOS_PER_CONNECTION_SHIFT;
1323 fcoe_cap->capability1 |= BNX2FC_NUM_MAX_SESS <<
1324 FCOE_LOGINS_PER_PORT_SHIFT;
1325 fcoe_cap->capability2 = BNX2FC_MAX_OUTSTANDING_CMNDS <<
1326 FCOE_NUMBER_OF_EXCHANGES_SHIFT;
1327 fcoe_cap->capability2 |= BNX2FC_MAX_NPIV <<
1328 FCOE_NPIV_WWN_PER_PORT_SHIFT;
1329 fcoe_cap->capability3 = BNX2FC_NUM_MAX_SESS <<
1330 FCOE_TARGETS_SUPPORTED_SHIFT;
1331 fcoe_cap->capability3 |= BNX2FC_MAX_OUTSTANDING_CMNDS <<
1332 FCOE_OUTSTANDING_COMMANDS_SHIFT;
1333 fcoe_cap->capability4 = FCOE_CAPABILITY4_STATEFUL;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001334
1335 init_waitqueue_head(&hba->shutdown_wait);
1336 init_waitqueue_head(&hba->destroy_wait);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001337 INIT_LIST_HEAD(&hba->vports);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001338
1339 return hba;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001340
1341cmgr_err:
1342 kfree(hba->tgt_ofld_list);
1343tgtofld_err:
1344 bnx2fc_unbind_pcidev(hba);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001345bind_err:
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001346 kfree(hba);
1347 return NULL;
1348}
1349
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001350struct bnx2fc_interface *bnx2fc_interface_create(struct bnx2fc_hba *hba,
1351 struct net_device *netdev,
1352 enum fip_state fip_mode)
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001353{
Robert Love8d55e502012-05-22 19:06:26 -07001354 struct fcoe_ctlr_device *ctlr_dev;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001355 struct bnx2fc_interface *interface;
Robert Lovefd8f8902012-05-22 19:06:16 -07001356 struct fcoe_ctlr *ctlr;
1357 int size;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001358 int rc = 0;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001359
Robert Lovefd8f8902012-05-22 19:06:16 -07001360 size = (sizeof(*interface) + sizeof(struct fcoe_ctlr));
Robert Love8d55e502012-05-22 19:06:26 -07001361 ctlr_dev = fcoe_ctlr_device_add(&netdev->dev, &bnx2fc_fcoe_sysfs_templ,
1362 size);
1363 if (!ctlr_dev) {
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001364 printk(KERN_ERR PFX "Unable to allocate interface structure\n");
1365 return NULL;
1366 }
Robert Love8d55e502012-05-22 19:06:26 -07001367 ctlr = fcoe_ctlr_device_priv(ctlr_dev);
Robert Lovefd8f8902012-05-22 19:06:16 -07001368 interface = fcoe_ctlr_priv(ctlr);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001369 dev_hold(netdev);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001370 kref_init(&interface->kref);
1371 interface->hba = hba;
1372 interface->netdev = netdev;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001373
1374 /* Initialize FIP */
Robert Lovefd8f8902012-05-22 19:06:16 -07001375 fcoe_ctlr_init(ctlr, fip_mode);
1376 ctlr->send = bnx2fc_fip_send;
1377 ctlr->update_mac = bnx2fc_update_src_mac;
1378 ctlr->get_src_addr = bnx2fc_get_src_mac;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001379 set_bit(BNX2FC_CTLR_INIT_DONE, &interface->if_flags);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001380
Bhanu Prakash Gollapudi776cebc2011-08-04 17:38:40 -07001381 rc = bnx2fc_interface_setup(interface);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001382 if (!rc)
1383 return interface;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001384
Robert Lovefd8f8902012-05-22 19:06:16 -07001385 fcoe_ctlr_destroy(ctlr);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001386 dev_put(netdev);
Robert Love8d55e502012-05-22 19:06:26 -07001387 fcoe_ctlr_device_delete(ctlr_dev);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001388 return NULL;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001389}
1390
1391/**
1392 * bnx2fc_if_create - Create FCoE instance on a given interface
1393 *
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001394 * @interface: FCoE interface to create a local port on
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001395 * @parent: Device pointer to be the parent in sysfs for the SCSI host
1396 * @npiv: Indicates if the port is vport or not
1397 *
1398 * Creates a fc_lport instance and a Scsi_Host instance and configure them.
1399 *
1400 * Returns: Allocated fc_lport or an error pointer
1401 */
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001402static struct fc_lport *bnx2fc_if_create(struct bnx2fc_interface *interface,
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001403 struct device *parent, int npiv)
1404{
Robert Lovefd8f8902012-05-22 19:06:16 -07001405 struct fcoe_ctlr *ctlr = bnx2fc_to_ctlr(interface);
Vasu Dev134a4e22011-04-28 15:55:44 -07001406 struct fc_lport *lport, *n_port;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001407 struct fcoe_port *port;
1408 struct Scsi_Host *shost;
1409 struct fc_vport *vport = dev_to_vport(parent);
Bhanu Prakash Gollapudid36b3272011-05-27 11:47:27 -07001410 struct bnx2fc_lport *blport;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001411 struct bnx2fc_hba *hba;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001412 int rc = 0;
1413
Bhanu Prakash Gollapudid36b3272011-05-27 11:47:27 -07001414 blport = kzalloc(sizeof(struct bnx2fc_lport), GFP_KERNEL);
1415 if (!blport) {
Robert Lovefd8f8902012-05-22 19:06:16 -07001416 BNX2FC_HBA_DBG(ctlr->lp, "Unable to alloc blport\n");
Bhanu Prakash Gollapudid36b3272011-05-27 11:47:27 -07001417 return NULL;
1418 }
1419
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001420 /* Allocate Scsi_Host structure */
Vasu Dev134a4e22011-04-28 15:55:44 -07001421 if (!npiv)
1422 lport = libfc_host_alloc(&bnx2fc_shost_template, sizeof(*port));
1423 else
1424 lport = libfc_vport_create(vport, sizeof(*port));
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001425
1426 if (!lport) {
1427 printk(KERN_ERR PFX "could not allocate scsi host structure\n");
Bhanu Prakash Gollapudid36b3272011-05-27 11:47:27 -07001428 goto free_blport;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001429 }
1430 shost = lport->host;
1431 port = lport_priv(lport);
1432 port->lport = lport;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001433 port->priv = interface;
Yi Zouc3d79092012-12-06 06:24:29 +00001434 port->get_netdev = bnx2fc_netdev;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001435 INIT_WORK(&port->destroy_work, bnx2fc_destroy_work);
1436
1437 /* Configure fcoe_port */
1438 rc = bnx2fc_lport_config(lport);
1439 if (rc)
1440 goto lp_config_err;
1441
1442 if (npiv) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001443 printk(KERN_ERR PFX "Setting vport names, 0x%llX 0x%llX\n",
1444 vport->node_name, vport->port_name);
1445 fc_set_wwnn(lport, vport->node_name);
1446 fc_set_wwpn(lport, vport->port_name);
1447 }
1448 /* Configure netdev and networking properties of the lport */
Bhanu Prakash Gollapudi52439602011-08-04 17:38:50 -07001449 rc = bnx2fc_net_config(lport, interface->netdev);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001450 if (rc) {
1451 printk(KERN_ERR PFX "Error on bnx2fc_net_config\n");
1452 goto lp_config_err;
1453 }
1454
1455 rc = bnx2fc_shost_config(lport, parent);
1456 if (rc) {
1457 printk(KERN_ERR PFX "Couldnt configure shost for %s\n",
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001458 interface->netdev->name);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001459 goto lp_config_err;
1460 }
1461
1462 /* Initialize the libfc library */
1463 rc = bnx2fc_libfc_config(lport);
1464 if (rc) {
1465 printk(KERN_ERR PFX "Couldnt configure libfc\n");
1466 goto shost_err;
1467 }
1468 fc_host_port_type(lport->host) = FC_PORTTYPE_UNKNOWN;
1469
1470 /* Allocate exchange manager */
Vasu Dev134a4e22011-04-28 15:55:44 -07001471 if (!npiv)
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001472 rc = bnx2fc_em_config(lport);
Vasu Dev134a4e22011-04-28 15:55:44 -07001473 else {
1474 shost = vport_to_shost(vport);
1475 n_port = shost_priv(shost);
1476 rc = fc_exch_mgr_list_clone(n_port, lport);
1477 }
1478
1479 if (rc) {
1480 printk(KERN_ERR PFX "Error on bnx2fc_em_config\n");
1481 goto shost_err;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001482 }
1483
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001484 bnx2fc_interface_get(interface);
Bhanu Prakash Gollapudid36b3272011-05-27 11:47:27 -07001485
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001486 hba = interface->hba;
Bhanu Prakash Gollapudid36b3272011-05-27 11:47:27 -07001487 spin_lock_bh(&hba->hba_lock);
1488 blport->lport = lport;
1489 list_add_tail(&blport->list, &hba->vports);
1490 spin_unlock_bh(&hba->hba_lock);
1491
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001492 return lport;
1493
1494shost_err:
1495 scsi_remove_host(shost);
1496lp_config_err:
1497 scsi_host_put(lport->host);
Bhanu Prakash Gollapudid36b3272011-05-27 11:47:27 -07001498free_blport:
1499 kfree(blport);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001500 return NULL;
1501}
1502
Bhanu Prakash Gollapudi013068f2011-08-30 15:54:52 -07001503static void bnx2fc_net_cleanup(struct bnx2fc_interface *interface)
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001504{
1505 /* Dont listen for Ethernet packets anymore */
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001506 __dev_remove_pack(&interface->fcoe_packet_type);
1507 __dev_remove_pack(&interface->fip_packet_type);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001508 synchronize_net();
1509}
1510
Bhanu Prakash Gollapudi776cebc2011-08-04 17:38:40 -07001511static void bnx2fc_interface_cleanup(struct bnx2fc_interface *interface)
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001512{
Robert Lovefd8f8902012-05-22 19:06:16 -07001513 struct fcoe_ctlr *ctlr = bnx2fc_to_ctlr(interface);
1514 struct fc_lport *lport = ctlr->lp;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001515 struct fcoe_port *port = lport_priv(lport);
Bhanu Prakash Gollapudi9be17fc2011-08-04 17:38:41 -07001516 struct bnx2fc_hba *hba = interface->hba;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001517
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001518 /* Stop the transmit retry timer */
1519 del_timer_sync(&port->timer);
1520
1521 /* Free existing transmit skbs */
1522 fcoe_clean_pending_queue(lport);
1523
Bhanu Prakash Gollapudi013068f2011-08-30 15:54:52 -07001524 bnx2fc_net_cleanup(interface);
Bhanu Prakash Gollapudi9be17fc2011-08-04 17:38:41 -07001525
Bhanu Prakash Gollapudiabc49a92011-08-04 17:38:42 -07001526 bnx2fc_free_vport(hba, lport);
Bhanu Prakash Gollapudi9be17fc2011-08-04 17:38:41 -07001527}
1528
1529static void bnx2fc_if_destroy(struct fc_lport *lport)
1530{
1531
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001532 /* Free queued packets for the receive thread */
1533 bnx2fc_clean_rx_queue(lport);
1534
1535 /* Detach from scsi-ml */
1536 fc_remove_host(lport->host);
1537 scsi_remove_host(lport->host);
1538
1539 /*
1540 * Note that only the physical lport will have the exchange manager.
1541 * for vports, this function is NOP
1542 */
1543 fc_exch_mgr_free(lport);
1544
1545 /* Free memory used by statistical counters */
1546 fc_lport_free_stats(lport);
1547
1548 /* Release Scsi_Host */
1549 scsi_host_put(lport->host);
1550}
1551
Bhanu Prakash Gollapudieccdcd02011-08-24 18:56:42 -07001552static void __bnx2fc_destroy(struct bnx2fc_interface *interface)
Bhanu Prakash Gollapudiabc49a92011-08-04 17:38:42 -07001553{
Robert Lovefd8f8902012-05-22 19:06:16 -07001554 struct fcoe_ctlr *ctlr = bnx2fc_to_ctlr(interface);
1555 struct fc_lport *lport = ctlr->lp;
Bhanu Prakash Gollapudi0cbf32e2011-08-30 15:54:51 -07001556 struct fcoe_port *port = lport_priv(lport);
Bhanu Prakash Gollapudiabc49a92011-08-04 17:38:42 -07001557
1558 bnx2fc_interface_cleanup(interface);
1559 bnx2fc_stop(interface);
Bhanu Prakash Gollapudiabc49a92011-08-04 17:38:42 -07001560 list_del(&interface->list);
Bhanu Prakash Gollapudiabc49a92011-08-04 17:38:42 -07001561 bnx2fc_interface_put(interface);
Bhanu Prakash Gollapudi0cbf32e2011-08-30 15:54:51 -07001562 queue_work(bnx2fc_wq, &port->destroy_work);
Bhanu Prakash Gollapudiabc49a92011-08-04 17:38:42 -07001563}
1564
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001565/**
1566 * bnx2fc_destroy - Destroy a bnx2fc FCoE interface
1567 *
1568 * @buffer: The name of the Ethernet interface to be destroyed
1569 * @kp: The associated kernel parameter
1570 *
1571 * Called from sysfs.
1572 *
1573 * Returns: 0 for success
1574 */
1575static int bnx2fc_destroy(struct net_device *netdev)
1576{
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001577 struct bnx2fc_interface *interface = NULL;
Bhanu Prakash Gollapudi2a7b29c2012-01-23 18:00:46 -08001578 struct workqueue_struct *timer_work_queue;
Robert Lovefd8f8902012-05-22 19:06:16 -07001579 struct fcoe_ctlr *ctlr;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001580 int rc = 0;
1581
Nithin Sujir6702ca12011-03-17 17:13:27 -07001582 rtnl_lock();
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001583 mutex_lock(&bnx2fc_dev_lock);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001584
1585 interface = bnx2fc_interface_lookup(netdev);
Robert Lovefd8f8902012-05-22 19:06:16 -07001586 ctlr = bnx2fc_to_ctlr(interface);
1587 if (!interface || !ctlr->lp) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001588 rc = -ENODEV;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001589 printk(KERN_ERR PFX "bnx2fc_destroy: interface or lport not found\n");
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001590 goto netdev_err;
1591 }
1592
Bhanu Prakash Gollapudi2a7b29c2012-01-23 18:00:46 -08001593 timer_work_queue = interface->timer_work_queue;
Bhanu Prakash Gollapudieccdcd02011-08-24 18:56:42 -07001594 __bnx2fc_destroy(interface);
Bhanu Prakash Gollapudi2a7b29c2012-01-23 18:00:46 -08001595 destroy_workqueue(timer_work_queue);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001596
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001597netdev_err:
1598 mutex_unlock(&bnx2fc_dev_lock);
1599 rtnl_unlock();
1600 return rc;
1601}
1602
1603static void bnx2fc_destroy_work(struct work_struct *work)
1604{
1605 struct fcoe_port *port;
1606 struct fc_lport *lport;
1607
1608 port = container_of(work, struct fcoe_port, destroy_work);
1609 lport = port->lport;
1610
1611 BNX2FC_HBA_DBG(lport, "Entered bnx2fc_destroy_work\n");
1612
Bhanu Prakash Gollapudi9be17fc2011-08-04 17:38:41 -07001613 bnx2fc_if_destroy(lport);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001614}
1615
1616static void bnx2fc_unbind_adapter_devices(struct bnx2fc_hba *hba)
1617{
1618 bnx2fc_free_fw_resc(hba);
1619 bnx2fc_free_task_ctx(hba);
1620}
1621
1622/**
1623 * bnx2fc_bind_adapter_devices - binds bnx2fc adapter with the associated
1624 * pci structure
1625 *
1626 * @hba: Adapter instance
1627 */
1628static int bnx2fc_bind_adapter_devices(struct bnx2fc_hba *hba)
1629{
1630 if (bnx2fc_setup_task_ctx(hba))
1631 goto mem_err;
1632
1633 if (bnx2fc_setup_fw_resc(hba))
1634 goto mem_err;
1635
1636 return 0;
1637mem_err:
1638 bnx2fc_unbind_adapter_devices(hba);
1639 return -ENOMEM;
1640}
1641
1642static int bnx2fc_bind_pcidev(struct bnx2fc_hba *hba)
1643{
1644 struct cnic_dev *cnic;
1645
1646 if (!hba->cnic) {
1647 printk(KERN_ERR PFX "cnic is NULL\n");
1648 return -ENODEV;
1649 }
1650 cnic = hba->cnic;
1651 hba->pcidev = cnic->pcidev;
1652 if (hba->pcidev)
1653 pci_dev_get(hba->pcidev);
1654
1655 return 0;
1656}
1657
1658static void bnx2fc_unbind_pcidev(struct bnx2fc_hba *hba)
1659{
1660 if (hba->pcidev)
1661 pci_dev_put(hba->pcidev);
1662 hba->pcidev = NULL;
1663}
1664
Barak Witkowski2e499d32012-06-26 01:31:19 +00001665/**
1666 * bnx2fc_ulp_get_stats - cnic callback to populate FCoE stats
1667 *
1668 * @handle: transport handle pointing to adapter struture
1669 */
1670static int bnx2fc_ulp_get_stats(void *handle)
1671{
1672 struct bnx2fc_hba *hba = handle;
1673 struct cnic_dev *cnic;
1674 struct fcoe_stats_info *stats_addr;
1675
1676 if (!hba)
1677 return -EINVAL;
1678
1679 cnic = hba->cnic;
1680 stats_addr = &cnic->stats_addr->fcoe_stat;
1681 if (!stats_addr)
1682 return -EINVAL;
1683
1684 strncpy(stats_addr->version, BNX2FC_VERSION,
1685 sizeof(stats_addr->version));
1686 stats_addr->txq_size = BNX2FC_SQ_WQES_MAX;
1687 stats_addr->rxq_size = BNX2FC_CQ_WQES_MAX;
1688
1689 return 0;
1690}
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001691
1692
1693/**
1694 * bnx2fc_ulp_start - cnic callback to initialize & start adapter instance
1695 *
Masanari Iida59e13d42012-04-25 00:24:16 +09001696 * @handle: transport handle pointing to adapter structure
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001697 *
1698 * This function maps adapter structure to pcidev structure and initiates
1699 * firmware handshake to enable/initialize on-chip FCoE components.
1700 * This bnx2fc - cnic interface api callback is used after following
1701 * conditions are met -
1702 * a) underlying network interface is up (marked by event NETDEV_UP
1703 * from netdev
1704 * b) bnx2fc adatper structure is registered.
1705 */
1706static void bnx2fc_ulp_start(void *handle)
1707{
1708 struct bnx2fc_hba *hba = handle;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001709 struct bnx2fc_interface *interface;
Robert Lovefd8f8902012-05-22 19:06:16 -07001710 struct fcoe_ctlr *ctlr;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001711 struct fc_lport *lport;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001712
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001713 mutex_lock(&bnx2fc_dev_lock);
1714
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001715 if (!test_bit(BNX2FC_FLAG_FW_INIT_DONE, &hba->flags))
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001716 bnx2fc_fw_init(hba);
1717
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001718 BNX2FC_MISC_DBG("bnx2fc started.\n");
1719
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001720 list_for_each_entry(interface, &if_list, list) {
1721 if (interface->hba == hba) {
Robert Lovefd8f8902012-05-22 19:06:16 -07001722 ctlr = bnx2fc_to_ctlr(interface);
1723 lport = ctlr->lp;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001724 /* Kick off Fabric discovery*/
1725 printk(KERN_ERR PFX "ulp_init: start discovery\n");
1726 lport->tt.frame_send = bnx2fc_xmit;
1727 bnx2fc_start_disc(interface);
1728 }
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001729 }
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001730
1731 mutex_unlock(&bnx2fc_dev_lock);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001732}
1733
1734static void bnx2fc_port_shutdown(struct fc_lport *lport)
1735{
1736 BNX2FC_MISC_DBG("Entered %s\n", __func__);
1737 fc_fabric_logoff(lport);
1738 fc_lport_destroy(lport);
1739}
1740
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001741static void bnx2fc_stop(struct bnx2fc_interface *interface)
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001742{
Robert Lovefd8f8902012-05-22 19:06:16 -07001743 struct fcoe_ctlr *ctlr = bnx2fc_to_ctlr(interface);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001744 struct fc_lport *lport;
1745 struct fc_lport *vport;
1746
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001747 if (!test_bit(BNX2FC_FLAG_FW_INIT_DONE, &interface->hba->flags))
1748 return;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001749
Robert Lovefd8f8902012-05-22 19:06:16 -07001750 lport = ctlr->lp;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001751 bnx2fc_port_shutdown(lport);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001752
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001753 mutex_lock(&lport->lp_mutex);
1754 list_for_each_entry(vport, &lport->vports, list)
1755 fc_host_port_type(vport->host) =
1756 FC_PORTTYPE_UNKNOWN;
1757 mutex_unlock(&lport->lp_mutex);
1758 fc_host_port_type(lport->host) = FC_PORTTYPE_UNKNOWN;
Robert Lovefd8f8902012-05-22 19:06:16 -07001759 fcoe_ctlr_link_down(ctlr);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001760 fcoe_clean_pending_queue(lport);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001761}
1762
1763static int bnx2fc_fw_init(struct bnx2fc_hba *hba)
1764{
1765#define BNX2FC_INIT_POLL_TIME (1000 / HZ)
1766 int rc = -1;
1767 int i = HZ;
1768
1769 rc = bnx2fc_bind_adapter_devices(hba);
1770 if (rc) {
1771 printk(KERN_ALERT PFX
1772 "bnx2fc_bind_adapter_devices failed - rc = %d\n", rc);
1773 goto err_out;
1774 }
1775
1776 rc = bnx2fc_send_fw_fcoe_init_msg(hba);
1777 if (rc) {
1778 printk(KERN_ALERT PFX
1779 "bnx2fc_send_fw_fcoe_init_msg failed - rc = %d\n", rc);
1780 goto err_unbind;
1781 }
1782
1783 /*
1784 * Wait until the adapter init message is complete, and adapter
1785 * state is UP.
1786 */
1787 while (!test_bit(ADAPTER_STATE_UP, &hba->adapter_state) && i--)
1788 msleep(BNX2FC_INIT_POLL_TIME);
1789
1790 if (!test_bit(ADAPTER_STATE_UP, &hba->adapter_state)) {
1791 printk(KERN_ERR PFX "bnx2fc_start: %s failed to initialize. "
1792 "Ignoring...\n",
1793 hba->cnic->netdev->name);
1794 rc = -1;
1795 goto err_unbind;
1796 }
1797
1798
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001799 set_bit(BNX2FC_FLAG_FW_INIT_DONE, &hba->flags);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001800 return 0;
1801
1802err_unbind:
1803 bnx2fc_unbind_adapter_devices(hba);
1804err_out:
1805 return rc;
1806}
1807
1808static void bnx2fc_fw_destroy(struct bnx2fc_hba *hba)
1809{
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001810 if (test_and_clear_bit(BNX2FC_FLAG_FW_INIT_DONE, &hba->flags)) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001811 if (bnx2fc_send_fw_fcoe_destroy_msg(hba) == 0) {
1812 init_timer(&hba->destroy_timer);
1813 hba->destroy_timer.expires = BNX2FC_FW_TIMEOUT +
1814 jiffies;
1815 hba->destroy_timer.function = bnx2fc_destroy_timer;
1816 hba->destroy_timer.data = (unsigned long)hba;
1817 add_timer(&hba->destroy_timer);
1818 wait_event_interruptible(hba->destroy_wait,
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001819 test_bit(BNX2FC_FLAG_DESTROY_CMPL,
1820 &hba->flags));
Bhanu Prakash Gollapudicd703ae2011-08-04 17:38:43 -07001821 clear_bit(BNX2FC_FLAG_DESTROY_CMPL, &hba->flags);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001822 /* This should never happen */
1823 if (signal_pending(current))
1824 flush_signals(current);
1825
1826 del_timer_sync(&hba->destroy_timer);
1827 }
1828 bnx2fc_unbind_adapter_devices(hba);
1829 }
1830}
1831
1832/**
1833 * bnx2fc_ulp_stop - cnic callback to shutdown adapter instance
1834 *
1835 * @handle: transport handle pointing to adapter structure
1836 *
1837 * Driver checks if adapter is already in shutdown mode, if not start
1838 * the shutdown process.
1839 */
1840static void bnx2fc_ulp_stop(void *handle)
1841{
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001842 struct bnx2fc_hba *hba = handle;
1843 struct bnx2fc_interface *interface;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001844
1845 printk(KERN_ERR "ULP_STOP\n");
1846
1847 mutex_lock(&bnx2fc_dev_lock);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001848 if (!test_bit(BNX2FC_FLAG_FW_INIT_DONE, &hba->flags))
1849 goto exit;
1850 list_for_each_entry(interface, &if_list, list) {
1851 if (interface->hba == hba)
1852 bnx2fc_stop(interface);
1853 }
1854 BUG_ON(hba->num_ofld_sess != 0);
1855
1856 mutex_lock(&hba->hba_mutex);
1857 clear_bit(ADAPTER_STATE_UP, &hba->adapter_state);
1858 clear_bit(ADAPTER_STATE_GOING_DOWN,
1859 &hba->adapter_state);
1860
1861 clear_bit(ADAPTER_STATE_READY, &hba->adapter_state);
1862 mutex_unlock(&hba->hba_mutex);
1863
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001864 bnx2fc_fw_destroy(hba);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001865exit:
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001866 mutex_unlock(&bnx2fc_dev_lock);
1867}
1868
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001869static void bnx2fc_start_disc(struct bnx2fc_interface *interface)
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001870{
Robert Lovefd8f8902012-05-22 19:06:16 -07001871 struct fcoe_ctlr *ctlr = bnx2fc_to_ctlr(interface);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001872 struct fc_lport *lport;
1873 int wait_cnt = 0;
1874
1875 BNX2FC_MISC_DBG("Entered %s\n", __func__);
1876 /* Kick off FIP/FLOGI */
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001877 if (!test_bit(BNX2FC_FLAG_FW_INIT_DONE, &interface->hba->flags)) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001878 printk(KERN_ERR PFX "Init not done yet\n");
1879 return;
1880 }
1881
Robert Lovefd8f8902012-05-22 19:06:16 -07001882 lport = ctlr->lp;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001883 BNX2FC_HBA_DBG(lport, "calling fc_fabric_login\n");
1884
Bhanu Prakash Gollapudi8a5badf2011-08-30 15:54:48 -07001885 if (!bnx2fc_link_ok(lport) && interface->enabled) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001886 BNX2FC_HBA_DBG(lport, "ctlr_link_up\n");
Robert Lovefd8f8902012-05-22 19:06:16 -07001887 fcoe_ctlr_link_up(ctlr);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001888 fc_host_port_type(lport->host) = FC_PORTTYPE_NPORT;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001889 set_bit(ADAPTER_STATE_READY, &interface->hba->adapter_state);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001890 }
1891
1892 /* wait for the FCF to be selected before issuing FLOGI */
Robert Lovefd8f8902012-05-22 19:06:16 -07001893 while (!ctlr->sel_fcf) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001894 msleep(250);
1895 /* give up after 3 secs */
1896 if (++wait_cnt > 12)
1897 break;
1898 }
Bhanu Prakash Gollapudi627e6282011-08-04 17:38:35 -07001899
1900 /* Reset max receive frame size to default */
1901 if (fc_set_mfs(lport, BNX2FC_MFS))
1902 return;
1903
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001904 fc_lport_init(lport);
1905 fc_fabric_login(lport);
1906}
1907
1908
1909/**
1910 * bnx2fc_ulp_init - Initialize an adapter instance
1911 *
1912 * @dev : cnic device handle
1913 * Called from cnic_register_driver() context to initialize all
1914 * enumerated cnic devices. This routine allocates adapter structure
1915 * and other device specific resources.
1916 */
1917static void bnx2fc_ulp_init(struct cnic_dev *dev)
1918{
1919 struct bnx2fc_hba *hba;
1920 int rc = 0;
1921
1922 BNX2FC_MISC_DBG("Entered %s\n", __func__);
1923 /* bnx2fc works only when bnx2x is loaded */
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001924 if (!test_bit(CNIC_F_BNX2X_CLASS, &dev->flags) ||
1925 (dev->max_fcoe_conn == 0)) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001926 printk(KERN_ERR PFX "bnx2fc FCoE not supported on %s,"
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001927 " flags: %lx fcoe_conn: %d\n",
1928 dev->netdev->name, dev->flags, dev->max_fcoe_conn);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001929 return;
1930 }
1931
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001932 hba = bnx2fc_hba_create(dev);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001933 if (!hba) {
1934 printk(KERN_ERR PFX "hba initialization failed\n");
1935 return;
1936 }
1937
1938 /* Add HBA to the adapter list */
1939 mutex_lock(&bnx2fc_dev_lock);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001940 list_add_tail(&hba->list, &adapter_list);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001941 adapter_count++;
1942 mutex_unlock(&bnx2fc_dev_lock);
1943
Barak Witkowski2e499d32012-06-26 01:31:19 +00001944 dev->fcoe_cap = &hba->fcoe_cap;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001945 clear_bit(BNX2FC_CNIC_REGISTERED, &hba->reg_with_cnic);
1946 rc = dev->register_device(dev, CNIC_ULP_FCOE,
1947 (void *) hba);
1948 if (rc)
Bhanu Prakash Gollapudib2a554f2011-06-27 23:30:53 -07001949 printk(KERN_ERR PFX "register_device failed, rc = %d\n", rc);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001950 else
1951 set_bit(BNX2FC_CNIC_REGISTERED, &hba->reg_with_cnic);
1952}
1953
Robert Love6e89ea32012-11-27 06:53:40 +00001954/**
1955 * Deperecated: Use bnx2fc_enabled()
1956 */
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001957static int bnx2fc_disable(struct net_device *netdev)
1958{
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001959 struct bnx2fc_interface *interface;
Robert Lovefd8f8902012-05-22 19:06:16 -07001960 struct fcoe_ctlr *ctlr;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001961 int rc = 0;
1962
Nithin Sujir6702ca12011-03-17 17:13:27 -07001963 rtnl_lock();
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001964 mutex_lock(&bnx2fc_dev_lock);
1965
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001966 interface = bnx2fc_interface_lookup(netdev);
Robert Lovefd8f8902012-05-22 19:06:16 -07001967 ctlr = bnx2fc_to_ctlr(interface);
1968 if (!interface || !ctlr->lp) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001969 rc = -ENODEV;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001970 printk(KERN_ERR PFX "bnx2fc_disable: interface or lport not found\n");
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001971 } else {
Bhanu Prakash Gollapudi8a5badf2011-08-30 15:54:48 -07001972 interface->enabled = false;
Robert Lovefd8f8902012-05-22 19:06:16 -07001973 fcoe_ctlr_link_down(ctlr);
1974 fcoe_clean_pending_queue(ctlr->lp);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001975 }
1976
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001977 mutex_unlock(&bnx2fc_dev_lock);
1978 rtnl_unlock();
1979 return rc;
1980}
1981
Robert Love6e89ea32012-11-27 06:53:40 +00001982/**
1983 * Deprecated: Use bnx2fc_enabled()
1984 */
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001985static int bnx2fc_enable(struct net_device *netdev)
1986{
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001987 struct bnx2fc_interface *interface;
Robert Lovefd8f8902012-05-22 19:06:16 -07001988 struct fcoe_ctlr *ctlr;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001989 int rc = 0;
1990
Nithin Sujir6702ca12011-03-17 17:13:27 -07001991 rtnl_lock();
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001992 mutex_lock(&bnx2fc_dev_lock);
1993
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001994 interface = bnx2fc_interface_lookup(netdev);
Robert Lovefd8f8902012-05-22 19:06:16 -07001995 ctlr = bnx2fc_to_ctlr(interface);
1996 if (!interface || !ctlr->lp) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001997 rc = -ENODEV;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001998 printk(KERN_ERR PFX "bnx2fc_enable: interface or lport not found\n");
Robert Lovefd8f8902012-05-22 19:06:16 -07001999 } else if (!bnx2fc_link_ok(ctlr->lp)) {
2000 fcoe_ctlr_link_up(ctlr);
Bhanu Prakash Gollapudi8a5badf2011-08-30 15:54:48 -07002001 interface->enabled = true;
2002 }
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002003
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002004 mutex_unlock(&bnx2fc_dev_lock);
2005 rtnl_unlock();
2006 return rc;
2007}
2008
2009/**
Robert Love6e89ea32012-11-27 06:53:40 +00002010 * bnx2fc_ctlr_enabled() - Enable or disable an FCoE Controller
2011 * @cdev: The FCoE Controller that is being enabled or disabled
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002012 *
Robert Love6e89ea32012-11-27 06:53:40 +00002013 * fcoe_sysfs will ensure that the state of 'enabled' has
2014 * changed, so no checking is necessary here. This routine simply
2015 * calls fcoe_enable or fcoe_disable, both of which are deprecated.
2016 * When those routines are removed the functionality can be merged
2017 * here.
2018 */
2019static int bnx2fc_ctlr_enabled(struct fcoe_ctlr_device *cdev)
2020{
2021 struct fcoe_ctlr *ctlr = fcoe_ctlr_device_priv(cdev);
2022 struct fc_lport *lport = ctlr->lp;
2023 struct net_device *netdev = bnx2fc_netdev(lport);
2024
2025 switch (cdev->enabled) {
2026 case FCOE_CTLR_ENABLED:
2027 return bnx2fc_enable(netdev);
2028 case FCOE_CTLR_DISABLED:
2029 return bnx2fc_disable(netdev);
2030 case FCOE_CTLR_UNUSED:
2031 default:
2032 return -ENOTSUPP;
2033 };
2034}
2035
2036enum bnx2fc_create_link_state {
2037 BNX2FC_CREATE_LINK_DOWN,
2038 BNX2FC_CREATE_LINK_UP,
2039};
2040
2041/**
2042 * _bnx2fc_create() - Create bnx2fc FCoE interface
2043 * @netdev : The net_device object the Ethernet interface to create on
2044 * @fip_mode: The FIP mode for this creation
2045 * @link_state: The ctlr link state on creation
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002046 *
Robert Love6e89ea32012-11-27 06:53:40 +00002047 * Called from either the libfcoe 'create' module parameter
2048 * via fcoe_create or from fcoe_syfs's ctlr_create file.
2049 *
2050 * libfcoe's 'create' module parameter is deprecated so some
2051 * consolidation of code can be done when that interface is
2052 * removed.
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002053 *
2054 * Returns: 0 for success
2055 */
Robert Love6e89ea32012-11-27 06:53:40 +00002056static int _bnx2fc_create(struct net_device *netdev,
2057 enum fip_state fip_mode,
2058 enum bnx2fc_create_link_state link_state)
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002059{
Robert Love6e89ea32012-11-27 06:53:40 +00002060 struct fcoe_ctlr_device *cdev;
Robert Lovefd8f8902012-05-22 19:06:16 -07002061 struct fcoe_ctlr *ctlr;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002062 struct bnx2fc_interface *interface;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002063 struct bnx2fc_hba *hba;
Bhanu Prakash Gollapudi7adc5a32012-06-04 16:15:44 -07002064 struct net_device *phys_dev = netdev;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002065 struct fc_lport *lport;
2066 struct ethtool_drvinfo drvinfo;
2067 int rc = 0;
Bhanu Prakash Gollapudi7adc5a32012-06-04 16:15:44 -07002068 int vlan_id = 0;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002069
2070 BNX2FC_MISC_DBG("Entered bnx2fc_create\n");
2071 if (fip_mode != FIP_MODE_FABRIC) {
2072 printk(KERN_ERR "fip mode not FABRIC\n");
2073 return -EIO;
2074 }
2075
Nithin Sujir6702ca12011-03-17 17:13:27 -07002076 rtnl_lock();
2077
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002078 mutex_lock(&bnx2fc_dev_lock);
2079
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002080 if (!try_module_get(THIS_MODULE)) {
2081 rc = -EINVAL;
2082 goto mod_err;
2083 }
2084
2085 /* obtain physical netdev */
Bhanu Prakash Gollapudi7adc5a32012-06-04 16:15:44 -07002086 if (netdev->priv_flags & IFF_802_1Q_VLAN)
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002087 phys_dev = vlan_dev_real_dev(netdev);
Bhanu Prakash Gollapudi7adc5a32012-06-04 16:15:44 -07002088
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002089 /* verify if the physical device is a netxtreme2 device */
2090 if (phys_dev->ethtool_ops && phys_dev->ethtool_ops->get_drvinfo) {
2091 memset(&drvinfo, 0, sizeof(drvinfo));
2092 phys_dev->ethtool_ops->get_drvinfo(phys_dev, &drvinfo);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002093 if (strncmp(drvinfo.driver, "bnx2x", strlen("bnx2x"))) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002094 printk(KERN_ERR PFX "Not a netxtreme2 device\n");
2095 rc = -EINVAL;
2096 goto netdev_err;
2097 }
2098 } else {
2099 printk(KERN_ERR PFX "unable to obtain drv_info\n");
2100 rc = -EINVAL;
2101 goto netdev_err;
2102 }
2103
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002104 /* obtain interface and initialize rest of the structure */
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002105 hba = bnx2fc_hba_lookup(phys_dev);
2106 if (!hba) {
2107 rc = -ENODEV;
2108 printk(KERN_ERR PFX "bnx2fc_create: hba not found\n");
2109 goto netdev_err;
2110 }
2111
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002112 if (bnx2fc_interface_lookup(netdev)) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002113 rc = -EEXIST;
2114 goto netdev_err;
2115 }
2116
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002117 interface = bnx2fc_interface_create(hba, netdev, fip_mode);
2118 if (!interface) {
2119 printk(KERN_ERR PFX "bnx2fc_interface_create failed\n");
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002120 goto ifput_err;
2121 }
2122
Bhanu Prakash Gollapudi7adc5a32012-06-04 16:15:44 -07002123 if (netdev->priv_flags & IFF_802_1Q_VLAN) {
2124 vlan_id = vlan_dev_vlan_id(netdev);
2125 interface->vlan_enabled = 1;
2126 }
2127
Robert Lovefd8f8902012-05-22 19:06:16 -07002128 ctlr = bnx2fc_to_ctlr(interface);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002129 interface->vlan_id = vlan_id;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002130
2131 interface->timer_work_queue =
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002132 create_singlethread_workqueue("bnx2fc_timer_wq");
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002133 if (!interface->timer_work_queue) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002134 printk(KERN_ERR PFX "ulp_init could not create timer_wq\n");
2135 rc = -EINVAL;
2136 goto ifput_err;
2137 }
2138
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002139 lport = bnx2fc_if_create(interface, &interface->hba->pcidev->dev, 0);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002140 if (!lport) {
2141 printk(KERN_ERR PFX "Failed to create interface (%s)\n",
2142 netdev->name);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002143 rc = -EINVAL;
2144 goto if_create_err;
2145 }
2146
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002147 /* Add interface to if_list */
2148 list_add_tail(&interface->list, &if_list);
2149
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002150 lport->boot_time = jiffies;
2151
2152 /* Make this master N_port */
Robert Lovefd8f8902012-05-22 19:06:16 -07002153 ctlr->lp = lport;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002154
Robert Love6e89ea32012-11-27 06:53:40 +00002155 cdev = fcoe_ctlr_to_ctlr_dev(ctlr);
2156
2157 if (link_state == BNX2FC_CREATE_LINK_UP)
2158 cdev->enabled = FCOE_CTLR_ENABLED;
2159 else
2160 cdev->enabled = FCOE_CTLR_DISABLED;
2161
2162 if (link_state == BNX2FC_CREATE_LINK_UP &&
2163 !bnx2fc_link_ok(lport)) {
Robert Lovefd8f8902012-05-22 19:06:16 -07002164 fcoe_ctlr_link_up(ctlr);
Bhanu Prakash Gollapudi8a5badf2011-08-30 15:54:48 -07002165 fc_host_port_type(lport->host) = FC_PORTTYPE_NPORT;
2166 set_bit(ADAPTER_STATE_READY, &interface->hba->adapter_state);
2167 }
2168
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002169 BNX2FC_HBA_DBG(lport, "create: START DISC\n");
2170 bnx2fc_start_disc(interface);
Robert Love6e89ea32012-11-27 06:53:40 +00002171
2172 if (link_state == BNX2FC_CREATE_LINK_UP)
2173 interface->enabled = true;
2174
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002175 /*
2176 * Release from kref_init in bnx2fc_interface_setup, on success
2177 * lport should be holding a reference taken in bnx2fc_if_create
2178 */
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002179 bnx2fc_interface_put(interface);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002180 /* put netdev that was held while calling dev_get_by_name */
2181 mutex_unlock(&bnx2fc_dev_lock);
2182 rtnl_unlock();
2183 return 0;
2184
2185if_create_err:
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002186 destroy_workqueue(interface->timer_work_queue);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002187ifput_err:
Bhanu Prakash Gollapudi013068f2011-08-30 15:54:52 -07002188 bnx2fc_net_cleanup(interface);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002189 bnx2fc_interface_put(interface);
Bhanu Prakash Gollapudi7d742f62012-01-23 18:00:48 -08002190 goto mod_err;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002191netdev_err:
2192 module_put(THIS_MODULE);
2193mod_err:
2194 mutex_unlock(&bnx2fc_dev_lock);
2195 rtnl_unlock();
2196 return rc;
2197}
2198
2199/**
Robert Love6e89ea32012-11-27 06:53:40 +00002200 * bnx2fc_create() - Create a bnx2fc interface
2201 * @netdev : The net_device object the Ethernet interface to create on
2202 * @fip_mode: The FIP mode for this creation
2203 *
2204 * Called from fcoe transport
2205 *
2206 * Returns: 0 for success
2207 */
2208static int bnx2fc_create(struct net_device *netdev, enum fip_state fip_mode)
2209{
2210 return _bnx2fc_create(netdev, fip_mode, BNX2FC_CREATE_LINK_UP);
2211}
2212
2213/**
2214 * bnx2fc_ctlr_alloc() - Allocate a bnx2fc interface from fcoe_sysfs
2215 * @netdev: The net_device to be used by the allocated FCoE Controller
2216 *
2217 * This routine is called from fcoe_sysfs. It will start the fcoe_ctlr
2218 * in a link_down state. The allows the user an opportunity to configure
2219 * the FCoE Controller from sysfs before enabling the FCoE Controller.
2220 *
2221 * Creating in with this routine starts the FCoE Controller in Fabric
2222 * mode. The user can change to VN2VN or another mode before enabling.
2223 */
2224static int bnx2fc_ctlr_alloc(struct net_device *netdev)
2225{
2226 return _bnx2fc_create(netdev, FIP_MODE_FABRIC,
2227 BNX2FC_CREATE_LINK_DOWN);
2228}
2229
2230/**
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002231 * bnx2fc_find_hba_for_cnic - maps cnic instance to bnx2fc hba instance
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002232 *
2233 * @cnic: Pointer to cnic device instance
2234 *
2235 **/
2236static struct bnx2fc_hba *bnx2fc_find_hba_for_cnic(struct cnic_dev *cnic)
2237{
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002238 struct bnx2fc_hba *hba;
2239
2240 /* Called with bnx2fc_dev_lock held */
Bhanu Prakash Gollapudid71fb3b2012-06-07 02:19:36 -07002241 list_for_each_entry(hba, &adapter_list, list) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002242 if (hba->cnic == cnic)
2243 return hba;
2244 }
2245 return NULL;
2246}
2247
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002248static struct bnx2fc_interface *bnx2fc_interface_lookup(struct net_device
2249 *netdev)
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002250{
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002251 struct bnx2fc_interface *interface;
2252
2253 /* Called with bnx2fc_dev_lock held */
2254 list_for_each_entry(interface, &if_list, list) {
2255 if (interface->netdev == netdev)
2256 return interface;
2257 }
2258 return NULL;
2259}
2260
2261static struct bnx2fc_hba *bnx2fc_hba_lookup(struct net_device
2262 *phys_dev)
2263{
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002264 struct bnx2fc_hba *hba;
2265
2266 /* Called with bnx2fc_dev_lock held */
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002267 list_for_each_entry(hba, &adapter_list, list) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002268 if (hba->phys_dev == phys_dev)
2269 return hba;
2270 }
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002271 printk(KERN_ERR PFX "adapter_lookup: hba NULL\n");
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002272 return NULL;
2273}
2274
2275/**
2276 * bnx2fc_ulp_exit - shuts down adapter instance and frees all resources
2277 *
2278 * @dev cnic device handle
2279 */
2280static void bnx2fc_ulp_exit(struct cnic_dev *dev)
2281{
2282 struct bnx2fc_hba *hba;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002283 struct bnx2fc_interface *interface, *tmp;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002284
2285 BNX2FC_MISC_DBG("Entered bnx2fc_ulp_exit\n");
2286
2287 if (!test_bit(CNIC_F_BNX2X_CLASS, &dev->flags)) {
2288 printk(KERN_ERR PFX "bnx2fc port check: %s, flags: %lx\n",
2289 dev->netdev->name, dev->flags);
2290 return;
2291 }
2292
2293 mutex_lock(&bnx2fc_dev_lock);
2294 hba = bnx2fc_find_hba_for_cnic(dev);
2295 if (!hba) {
2296 printk(KERN_ERR PFX "bnx2fc_ulp_exit: hba not found, dev 0%p\n",
2297 dev);
2298 mutex_unlock(&bnx2fc_dev_lock);
2299 return;
2300 }
2301
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002302 list_del_init(&hba->list);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002303 adapter_count--;
2304
Bhanu Prakash Gollapudiabc49a92011-08-04 17:38:42 -07002305 list_for_each_entry_safe(interface, tmp, &if_list, list)
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002306 /* destroy not called yet, move to quiesced list */
Bhanu Prakash Gollapudiabc49a92011-08-04 17:38:42 -07002307 if (interface->hba == hba)
Bhanu Prakash Gollapudieccdcd02011-08-24 18:56:42 -07002308 __bnx2fc_destroy(interface);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002309 mutex_unlock(&bnx2fc_dev_lock);
2310
2311 bnx2fc_ulp_stop(hba);
2312 /* unregister cnic device */
2313 if (test_and_clear_bit(BNX2FC_CNIC_REGISTERED, &hba->reg_with_cnic))
2314 hba->cnic->unregister_device(hba->cnic, CNIC_ULP_FCOE);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002315 bnx2fc_hba_destroy(hba);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002316}
2317
2318/**
2319 * bnx2fc_fcoe_reset - Resets the fcoe
2320 *
2321 * @shost: shost the reset is from
2322 *
2323 * Returns: always 0
2324 */
2325static int bnx2fc_fcoe_reset(struct Scsi_Host *shost)
2326{
2327 struct fc_lport *lport = shost_priv(shost);
2328 fc_lport_reset(lport);
2329 return 0;
2330}
2331
2332
2333static bool bnx2fc_match(struct net_device *netdev)
2334{
Bhanu Prakash Gollapudi7adc5a32012-06-04 16:15:44 -07002335 struct net_device *phys_dev = netdev;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002336
Bhanu Prakash Gollapudi7adc5a32012-06-04 16:15:44 -07002337 mutex_lock(&bnx2fc_dev_lock);
2338 if (netdev->priv_flags & IFF_802_1Q_VLAN)
2339 phys_dev = vlan_dev_real_dev(netdev);
2340
2341 if (bnx2fc_hba_lookup(phys_dev)) {
2342 mutex_unlock(&bnx2fc_dev_lock);
2343 return true;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002344 }
Bhanu Prakash Gollapudi7adc5a32012-06-04 16:15:44 -07002345
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002346 mutex_unlock(&bnx2fc_dev_lock);
2347 return false;
2348}
2349
2350
2351static struct fcoe_transport bnx2fc_transport = {
2352 .name = {"bnx2fc"},
2353 .attached = false,
2354 .list = LIST_HEAD_INIT(bnx2fc_transport.list),
Robert Love6e89ea32012-11-27 06:53:40 +00002355 .alloc = bnx2fc_ctlr_alloc,
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002356 .match = bnx2fc_match,
2357 .create = bnx2fc_create,
2358 .destroy = bnx2fc_destroy,
2359 .enable = bnx2fc_enable,
2360 .disable = bnx2fc_disable,
2361};
2362
2363/**
2364 * bnx2fc_percpu_thread_create - Create a receive thread for an
2365 * online CPU
2366 *
2367 * @cpu: cpu index for the online cpu
2368 */
2369static void bnx2fc_percpu_thread_create(unsigned int cpu)
2370{
2371 struct bnx2fc_percpu_s *p;
2372 struct task_struct *thread;
2373
2374 p = &per_cpu(bnx2fc_percpu, cpu);
2375
Eric Dumazet69614272012-06-04 16:15:42 -07002376 thread = kthread_create_on_node(bnx2fc_percpu_io_thread,
2377 (void *)p, cpu_to_node(cpu),
2378 "bnx2fc_thread/%d", cpu);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002379 /* bind thread to the cpu */
Bhanu Prakash Gollapudi32248762011-08-04 17:38:36 -07002380 if (likely(!IS_ERR(thread))) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002381 kthread_bind(thread, cpu);
2382 p->iothread = thread;
2383 wake_up_process(thread);
2384 }
2385}
2386
2387static void bnx2fc_percpu_thread_destroy(unsigned int cpu)
2388{
2389 struct bnx2fc_percpu_s *p;
2390 struct task_struct *thread;
2391 struct bnx2fc_work *work, *tmp;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002392
2393 BNX2FC_MISC_DBG("destroying io thread for CPU %d\n", cpu);
2394
2395 /* Prevent any new work from being queued for this CPU */
2396 p = &per_cpu(bnx2fc_percpu, cpu);
2397 spin_lock_bh(&p->fp_work_lock);
2398 thread = p->iothread;
2399 p->iothread = NULL;
2400
2401
2402 /* Free all work in the list */
Bhanu Prakash Gollapudi32248762011-08-04 17:38:36 -07002403 list_for_each_entry_safe(work, tmp, &p->work_list, list) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002404 list_del_init(&work->list);
2405 bnx2fc_process_cq_compl(work->tgt, work->wqe);
2406 kfree(work);
2407 }
2408
2409 spin_unlock_bh(&p->fp_work_lock);
2410
2411 if (thread)
2412 kthread_stop(thread);
2413}
2414
2415/**
2416 * bnx2fc_cpu_callback - Handler for CPU hotplug events
2417 *
2418 * @nfb: The callback data block
2419 * @action: The event triggering the callback
2420 * @hcpu: The index of the CPU that the event is for
2421 *
2422 * This creates or destroys per-CPU data for fcoe
2423 *
2424 * Returns NOTIFY_OK always.
2425 */
2426static int bnx2fc_cpu_callback(struct notifier_block *nfb,
2427 unsigned long action, void *hcpu)
2428{
2429 unsigned cpu = (unsigned long)hcpu;
2430
2431 switch (action) {
2432 case CPU_ONLINE:
2433 case CPU_ONLINE_FROZEN:
2434 printk(PFX "CPU %x online: Create Rx thread\n", cpu);
2435 bnx2fc_percpu_thread_create(cpu);
2436 break;
2437 case CPU_DEAD:
2438 case CPU_DEAD_FROZEN:
2439 printk(PFX "CPU %x offline: Remove Rx thread\n", cpu);
2440 bnx2fc_percpu_thread_destroy(cpu);
2441 break;
2442 default:
2443 break;
2444 }
2445 return NOTIFY_OK;
2446}
2447
2448/**
2449 * bnx2fc_mod_init - module init entry point
2450 *
2451 * Initialize driver wide global data structures, and register
2452 * with cnic module
2453 **/
2454static int __init bnx2fc_mod_init(void)
2455{
2456 struct fcoe_percpu_s *bg;
2457 struct task_struct *l2_thread;
2458 int rc = 0;
2459 unsigned int cpu = 0;
2460 struct bnx2fc_percpu_s *p;
2461
2462 printk(KERN_INFO PFX "%s", version);
2463
2464 /* register as a fcoe transport */
2465 rc = fcoe_transport_attach(&bnx2fc_transport);
2466 if (rc) {
2467 printk(KERN_ERR "failed to register an fcoe transport, check "
2468 "if libfcoe is loaded\n");
2469 goto out;
2470 }
2471
2472 INIT_LIST_HEAD(&adapter_list);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002473 INIT_LIST_HEAD(&if_list);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002474 mutex_init(&bnx2fc_dev_lock);
2475 adapter_count = 0;
2476
2477 /* Attach FC transport template */
2478 rc = bnx2fc_attach_transport();
2479 if (rc)
2480 goto detach_ft;
2481
2482 bnx2fc_wq = alloc_workqueue("bnx2fc", 0, 0);
2483 if (!bnx2fc_wq) {
2484 rc = -ENOMEM;
2485 goto release_bt;
2486 }
2487
2488 bg = &bnx2fc_global;
2489 skb_queue_head_init(&bg->fcoe_rx_list);
2490 l2_thread = kthread_create(bnx2fc_l2_rcv_thread,
2491 (void *)bg,
2492 "bnx2fc_l2_thread");
2493 if (IS_ERR(l2_thread)) {
2494 rc = PTR_ERR(l2_thread);
2495 goto free_wq;
2496 }
2497 wake_up_process(l2_thread);
2498 spin_lock_bh(&bg->fcoe_rx_list.lock);
2499 bg->thread = l2_thread;
2500 spin_unlock_bh(&bg->fcoe_rx_list.lock);
2501
2502 for_each_possible_cpu(cpu) {
2503 p = &per_cpu(bnx2fc_percpu, cpu);
2504 INIT_LIST_HEAD(&p->work_list);
2505 spin_lock_init(&p->fp_work_lock);
2506 }
2507
2508 for_each_online_cpu(cpu) {
2509 bnx2fc_percpu_thread_create(cpu);
2510 }
2511
2512 /* Initialize per CPU interrupt thread */
2513 register_hotcpu_notifier(&bnx2fc_cpu_notifier);
2514
2515 cnic_register_driver(CNIC_ULP_FCOE, &bnx2fc_cnic_cb);
2516
2517 return 0;
2518
2519free_wq:
2520 destroy_workqueue(bnx2fc_wq);
2521release_bt:
2522 bnx2fc_release_transport();
2523detach_ft:
2524 fcoe_transport_detach(&bnx2fc_transport);
2525out:
2526 return rc;
2527}
2528
2529static void __exit bnx2fc_mod_exit(void)
2530{
2531 LIST_HEAD(to_be_deleted);
2532 struct bnx2fc_hba *hba, *next;
2533 struct fcoe_percpu_s *bg;
2534 struct task_struct *l2_thread;
2535 struct sk_buff *skb;
2536 unsigned int cpu = 0;
2537
2538 /*
2539 * NOTE: Since cnic calls register_driver routine rtnl_lock,
2540 * it will have higher precedence than bnx2fc_dev_lock.
2541 * unregister_device() cannot be called with bnx2fc_dev_lock
2542 * held.
2543 */
2544 mutex_lock(&bnx2fc_dev_lock);
2545 list_splice(&adapter_list, &to_be_deleted);
2546 INIT_LIST_HEAD(&adapter_list);
2547 adapter_count = 0;
2548 mutex_unlock(&bnx2fc_dev_lock);
2549
2550 /* Unregister with cnic */
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002551 list_for_each_entry_safe(hba, next, &to_be_deleted, list) {
2552 list_del_init(&hba->list);
2553 printk(KERN_ERR PFX "MOD_EXIT:destroy hba = 0x%p\n",
2554 hba);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002555 bnx2fc_ulp_stop(hba);
2556 /* unregister cnic device */
2557 if (test_and_clear_bit(BNX2FC_CNIC_REGISTERED,
2558 &hba->reg_with_cnic))
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002559 hba->cnic->unregister_device(hba->cnic,
2560 CNIC_ULP_FCOE);
2561 bnx2fc_hba_destroy(hba);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002562 }
2563 cnic_unregister_driver(CNIC_ULP_FCOE);
2564
2565 /* Destroy global thread */
2566 bg = &bnx2fc_global;
2567 spin_lock_bh(&bg->fcoe_rx_list.lock);
2568 l2_thread = bg->thread;
2569 bg->thread = NULL;
2570 while ((skb = __skb_dequeue(&bg->fcoe_rx_list)) != NULL)
2571 kfree_skb(skb);
2572
2573 spin_unlock_bh(&bg->fcoe_rx_list.lock);
2574
2575 if (l2_thread)
2576 kthread_stop(l2_thread);
2577
2578 unregister_hotcpu_notifier(&bnx2fc_cpu_notifier);
2579
2580 /* Destroy per cpu threads */
2581 for_each_online_cpu(cpu) {
2582 bnx2fc_percpu_thread_destroy(cpu);
2583 }
2584
2585 destroy_workqueue(bnx2fc_wq);
2586 /*
2587 * detach from scsi transport
2588 * must happen after all destroys are done
2589 */
2590 bnx2fc_release_transport();
2591
2592 /* detach from fcoe transport */
2593 fcoe_transport_detach(&bnx2fc_transport);
2594}
2595
2596module_init(bnx2fc_mod_init);
2597module_exit(bnx2fc_mod_exit);
2598
Robert Love8d55e502012-05-22 19:06:26 -07002599static struct fcoe_sysfs_function_template bnx2fc_fcoe_sysfs_templ = {
Robert Love6e89ea32012-11-27 06:53:40 +00002600 .set_fcoe_ctlr_enabled = bnx2fc_ctlr_enabled,
Yi Zoub8b3e692012-12-06 06:24:59 +00002601 .get_fcoe_ctlr_link_fail = fcoe_ctlr_get_lesb,
2602 .get_fcoe_ctlr_vlink_fail = fcoe_ctlr_get_lesb,
2603 .get_fcoe_ctlr_miss_fka = fcoe_ctlr_get_lesb,
2604 .get_fcoe_ctlr_symb_err = fcoe_ctlr_get_lesb,
2605 .get_fcoe_ctlr_err_block = fcoe_ctlr_get_lesb,
2606 .get_fcoe_ctlr_fcs_error = fcoe_ctlr_get_lesb,
Robert Love8d55e502012-05-22 19:06:26 -07002607
2608 .get_fcoe_fcf_selected = fcoe_fcf_get_selected,
2609 .get_fcoe_fcf_vlan_id = bnx2fc_fcf_get_vlan_id,
2610};
2611
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002612static struct fc_function_template bnx2fc_transport_function = {
2613 .show_host_node_name = 1,
2614 .show_host_port_name = 1,
2615 .show_host_supported_classes = 1,
2616 .show_host_supported_fc4s = 1,
2617 .show_host_active_fc4s = 1,
2618 .show_host_maxframe_size = 1,
2619
2620 .show_host_port_id = 1,
2621 .show_host_supported_speeds = 1,
2622 .get_host_speed = fc_get_host_speed,
2623 .show_host_speed = 1,
2624 .show_host_port_type = 1,
2625 .get_host_port_state = fc_get_host_port_state,
2626 .show_host_port_state = 1,
2627 .show_host_symbolic_name = 1,
2628
2629 .dd_fcrport_size = (sizeof(struct fc_rport_libfc_priv) +
2630 sizeof(struct bnx2fc_rport)),
2631 .show_rport_maxframe_size = 1,
2632 .show_rport_supported_classes = 1,
2633
2634 .show_host_fabric_name = 1,
2635 .show_starget_node_name = 1,
2636 .show_starget_port_name = 1,
2637 .show_starget_port_id = 1,
2638 .set_rport_dev_loss_tmo = fc_set_rport_loss_tmo,
2639 .show_rport_dev_loss_tmo = 1,
2640 .get_fc_host_stats = bnx2fc_get_host_stats,
2641
2642 .issue_fc_host_lip = bnx2fc_fcoe_reset,
2643
2644 .terminate_rport_io = fc_rport_terminate_io,
2645
2646 .vport_create = bnx2fc_vport_create,
2647 .vport_delete = bnx2fc_vport_destroy,
2648 .vport_disable = bnx2fc_vport_disable,
Bhanu Prakash Gollapudie9a5289c2011-08-04 17:38:37 -07002649 .bsg_request = fc_lport_bsg_request,
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002650};
2651
2652static struct fc_function_template bnx2fc_vport_xport_function = {
2653 .show_host_node_name = 1,
2654 .show_host_port_name = 1,
2655 .show_host_supported_classes = 1,
2656 .show_host_supported_fc4s = 1,
2657 .show_host_active_fc4s = 1,
2658 .show_host_maxframe_size = 1,
2659
2660 .show_host_port_id = 1,
2661 .show_host_supported_speeds = 1,
2662 .get_host_speed = fc_get_host_speed,
2663 .show_host_speed = 1,
2664 .show_host_port_type = 1,
2665 .get_host_port_state = fc_get_host_port_state,
2666 .show_host_port_state = 1,
2667 .show_host_symbolic_name = 1,
2668
2669 .dd_fcrport_size = (sizeof(struct fc_rport_libfc_priv) +
2670 sizeof(struct bnx2fc_rport)),
2671 .show_rport_maxframe_size = 1,
2672 .show_rport_supported_classes = 1,
2673
2674 .show_host_fabric_name = 1,
2675 .show_starget_node_name = 1,
2676 .show_starget_port_name = 1,
2677 .show_starget_port_id = 1,
2678 .set_rport_dev_loss_tmo = fc_set_rport_loss_tmo,
2679 .show_rport_dev_loss_tmo = 1,
2680 .get_fc_host_stats = fc_get_host_stats,
2681 .issue_fc_host_lip = bnx2fc_fcoe_reset,
2682 .terminate_rport_io = fc_rport_terminate_io,
Bhanu Prakash Gollapudie9a5289c2011-08-04 17:38:37 -07002683 .bsg_request = fc_lport_bsg_request,
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002684};
2685
2686/**
2687 * scsi_host_template structure used while registering with SCSI-ml
2688 */
2689static struct scsi_host_template bnx2fc_shost_template = {
2690 .module = THIS_MODULE,
2691 .name = "Broadcom Offload FCoE Initiator",
2692 .queuecommand = bnx2fc_queuecommand,
2693 .eh_abort_handler = bnx2fc_eh_abort, /* abts */
2694 .eh_device_reset_handler = bnx2fc_eh_device_reset, /* lun reset */
2695 .eh_target_reset_handler = bnx2fc_eh_target_reset, /* tgt reset */
2696 .eh_host_reset_handler = fc_eh_host_reset,
2697 .slave_alloc = fc_slave_alloc,
2698 .change_queue_depth = fc_change_queue_depth,
2699 .change_queue_type = fc_change_queue_type,
2700 .this_id = -1,
2701 .cmd_per_lun = 3,
Bhanu Gollapudi0ea5c272011-03-17 17:13:29 -07002702 .can_queue = BNX2FC_CAN_QUEUE,
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002703 .use_clustering = ENABLE_CLUSTERING,
2704 .sg_tablesize = BNX2FC_MAX_BDS_PER_CMD,
2705 .max_sectors = 512,
2706};
2707
2708static struct libfc_function_template bnx2fc_libfc_fcn_templ = {
2709 .frame_send = bnx2fc_xmit,
2710 .elsct_send = bnx2fc_elsct_send,
2711 .fcp_abort_io = bnx2fc_abort_io,
2712 .fcp_cleanup = bnx2fc_cleanup,
Yi Zoub8b3e692012-12-06 06:24:59 +00002713 .get_lesb = fcoe_get_lesb,
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002714 .rport_event_callback = bnx2fc_rport_event_handler,
2715};
2716
2717/**
2718 * bnx2fc_cnic_cb - global template of bnx2fc - cnic driver interface
2719 * structure carrying callback function pointers
2720 */
2721static struct cnic_ulp_ops bnx2fc_cnic_cb = {
2722 .owner = THIS_MODULE,
2723 .cnic_init = bnx2fc_ulp_init,
2724 .cnic_exit = bnx2fc_ulp_exit,
2725 .cnic_start = bnx2fc_ulp_start,
2726 .cnic_stop = bnx2fc_ulp_stop,
2727 .indicate_kcqes = bnx2fc_indicate_kcqe,
2728 .indicate_netevent = bnx2fc_indicate_netevent,
Barak Witkowski2e499d32012-06-26 01:31:19 +00002729 .cnic_get_stats = bnx2fc_ulp_get_stats,
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002730};