blob: a1c687c699ee468443d022a2d2abd5df5c3fb87d [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);
Robert Love8d55e502012-05-22 19:06:26 -070096static void bnx2fc_ctlr_get_lesb(struct fcoe_ctlr_device *ctlr_dev);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -080097
98unsigned int bnx2fc_debug_level;
99module_param_named(debug_logging, bnx2fc_debug_level, int, S_IRUGO|S_IWUSR);
100
101static int bnx2fc_cpu_callback(struct notifier_block *nfb,
102 unsigned long action, void *hcpu);
103/* notification function for CPU hotplug events */
104static struct notifier_block bnx2fc_cpu_notifier = {
105 .notifier_call = bnx2fc_cpu_callback,
106};
107
Bhanu Prakash Gollapudif72f6972011-10-03 16:45:02 -0700108static inline struct net_device *bnx2fc_netdev(const struct fc_lport *lport)
109{
110 return ((struct bnx2fc_interface *)
111 ((struct fcoe_port *)lport_priv(lport))->priv)->netdev;
112}
113
114/**
115 * bnx2fc_get_lesb() - Fill the FCoE Link Error Status Block
116 * @lport: the local port
117 * @fc_lesb: the link error status block
118 */
119static void bnx2fc_get_lesb(struct fc_lport *lport,
120 struct fc_els_lesb *fc_lesb)
121{
Yi Zouc3d79092012-12-06 06:24:29 +0000122 struct net_device *netdev = fcoe_get_netdev(lport);
Bhanu Prakash Gollapudif72f6972011-10-03 16:45:02 -0700123
124 __fcoe_get_lesb(lport, fc_lesb, netdev);
125}
126
Robert Love8d55e502012-05-22 19:06:26 -0700127static void bnx2fc_ctlr_get_lesb(struct fcoe_ctlr_device *ctlr_dev)
128{
129 struct fcoe_ctlr *fip = fcoe_ctlr_device_priv(ctlr_dev);
Yi Zouc3d79092012-12-06 06:24:29 +0000130 struct net_device *netdev = fcoe_get_netdev(fip->lp);
Robert Love8d55e502012-05-22 19:06:26 -0700131 struct fcoe_fc_els_lesb *fcoe_lesb;
132 struct fc_els_lesb fc_lesb;
133
134 __fcoe_get_lesb(fip->lp, &fc_lesb, netdev);
135 fcoe_lesb = (struct fcoe_fc_els_lesb *)(&fc_lesb);
136
137 ctlr_dev->lesb.lesb_link_fail =
138 ntohl(fcoe_lesb->lesb_link_fail);
139 ctlr_dev->lesb.lesb_vlink_fail =
140 ntohl(fcoe_lesb->lesb_vlink_fail);
141 ctlr_dev->lesb.lesb_miss_fka =
142 ntohl(fcoe_lesb->lesb_miss_fka);
143 ctlr_dev->lesb.lesb_symb_err =
144 ntohl(fcoe_lesb->lesb_symb_err);
145 ctlr_dev->lesb.lesb_err_block =
146 ntohl(fcoe_lesb->lesb_err_block);
147 ctlr_dev->lesb.lesb_fcs_error =
148 ntohl(fcoe_lesb->lesb_fcs_error);
149}
150EXPORT_SYMBOL(bnx2fc_ctlr_get_lesb);
151
152static void bnx2fc_fcf_get_vlan_id(struct fcoe_fcf_device *fcf_dev)
153{
154 struct fcoe_ctlr_device *ctlr_dev =
155 fcoe_fcf_dev_to_ctlr_dev(fcf_dev);
156 struct fcoe_ctlr *ctlr = fcoe_ctlr_device_priv(ctlr_dev);
157 struct bnx2fc_interface *fcoe = fcoe_ctlr_priv(ctlr);
158
159 fcf_dev->vlan_id = fcoe->vlan_id;
160}
161
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800162static void bnx2fc_clean_rx_queue(struct fc_lport *lp)
163{
164 struct fcoe_percpu_s *bg;
165 struct fcoe_rcv_info *fr;
166 struct sk_buff_head *list;
167 struct sk_buff *skb, *next;
168 struct sk_buff *head;
169
170 bg = &bnx2fc_global;
171 spin_lock_bh(&bg->fcoe_rx_list.lock);
172 list = &bg->fcoe_rx_list;
173 head = list->next;
174 for (skb = head; skb != (struct sk_buff *)list;
175 skb = next) {
176 next = skb->next;
177 fr = fcoe_dev_from_skb(skb);
178 if (fr->fr_dev == lp) {
179 __skb_unlink(skb, list);
180 kfree_skb(skb);
181 }
182 }
183 spin_unlock_bh(&bg->fcoe_rx_list.lock);
184}
185
186int bnx2fc_get_paged_crc_eof(struct sk_buff *skb, int tlen)
187{
188 int rc;
189 spin_lock(&bnx2fc_global_lock);
190 rc = fcoe_get_paged_crc_eof(skb, tlen, &bnx2fc_global);
191 spin_unlock(&bnx2fc_global_lock);
192
193 return rc;
194}
195
196static void bnx2fc_abort_io(struct fc_lport *lport)
197{
198 /*
199 * This function is no-op for bnx2fc, but we do
200 * not want to leave it as NULL either, as libfc
201 * can call the default function which is
202 * fc_fcp_abort_io.
203 */
204}
205
206static void bnx2fc_cleanup(struct fc_lport *lport)
207{
208 struct fcoe_port *port = lport_priv(lport);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700209 struct bnx2fc_interface *interface = port->priv;
210 struct bnx2fc_hba *hba = interface->hba;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800211 struct bnx2fc_rport *tgt;
212 int i;
213
214 BNX2FC_MISC_DBG("Entered %s\n", __func__);
215 mutex_lock(&hba->hba_mutex);
216 spin_lock_bh(&hba->hba_lock);
217 for (i = 0; i < BNX2FC_NUM_MAX_SESS; i++) {
218 tgt = hba->tgt_ofld_list[i];
219 if (tgt) {
220 /* Cleanup IOs belonging to requested vport */
221 if (tgt->port == port) {
222 spin_unlock_bh(&hba->hba_lock);
223 BNX2FC_TGT_DBG(tgt, "flush/cleanup\n");
224 bnx2fc_flush_active_ios(tgt);
225 spin_lock_bh(&hba->hba_lock);
226 }
227 }
228 }
229 spin_unlock_bh(&hba->hba_lock);
230 mutex_unlock(&hba->hba_mutex);
231}
232
233static int bnx2fc_xmit_l2_frame(struct bnx2fc_rport *tgt,
234 struct fc_frame *fp)
235{
236 struct fc_rport_priv *rdata = tgt->rdata;
237 struct fc_frame_header *fh;
238 int rc = 0;
239
240 fh = fc_frame_header_get(fp);
241 BNX2FC_TGT_DBG(tgt, "Xmit L2 frame rport = 0x%x, oxid = 0x%x, "
242 "r_ctl = 0x%x\n", rdata->ids.port_id,
243 ntohs(fh->fh_ox_id), fh->fh_r_ctl);
244 if ((fh->fh_type == FC_TYPE_ELS) &&
245 (fh->fh_r_ctl == FC_RCTL_ELS_REQ)) {
246
247 switch (fc_frame_payload_op(fp)) {
248 case ELS_ADISC:
249 rc = bnx2fc_send_adisc(tgt, fp);
250 break;
251 case ELS_LOGO:
252 rc = bnx2fc_send_logo(tgt, fp);
253 break;
254 case ELS_RLS:
255 rc = bnx2fc_send_rls(tgt, fp);
256 break;
257 default:
258 break;
259 }
260 } else if ((fh->fh_type == FC_TYPE_BLS) &&
261 (fh->fh_r_ctl == FC_RCTL_BA_ABTS))
262 BNX2FC_TGT_DBG(tgt, "ABTS frame\n");
263 else {
264 BNX2FC_TGT_DBG(tgt, "Send L2 frame type 0x%x "
265 "rctl 0x%x thru non-offload path\n",
266 fh->fh_type, fh->fh_r_ctl);
267 return -ENODEV;
268 }
269 if (rc)
270 return -ENOMEM;
271 else
272 return 0;
273}
274
275/**
276 * bnx2fc_xmit - bnx2fc's FCoE frame transmit function
277 *
278 * @lport: the associated local port
279 * @fp: the fc_frame to be transmitted
280 */
281static int bnx2fc_xmit(struct fc_lport *lport, struct fc_frame *fp)
282{
283 struct ethhdr *eh;
284 struct fcoe_crc_eof *cp;
285 struct sk_buff *skb;
286 struct fc_frame_header *fh;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700287 struct bnx2fc_interface *interface;
Robert Lovefd8f8902012-05-22 19:06:16 -0700288 struct fcoe_ctlr *ctlr;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700289 struct bnx2fc_hba *hba;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800290 struct fcoe_port *port;
291 struct fcoe_hdr *hp;
292 struct bnx2fc_rport *tgt;
Vasu Dev1bd49b42012-05-25 10:26:43 -0700293 struct fc_stats *stats;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800294 u8 sof, eof;
295 u32 crc;
296 unsigned int hlen, tlen, elen;
297 int wlen, rc = 0;
298
299 port = (struct fcoe_port *)lport_priv(lport);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700300 interface = port->priv;
Robert Lovefd8f8902012-05-22 19:06:16 -0700301 ctlr = bnx2fc_to_ctlr(interface);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700302 hba = interface->hba;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800303
304 fh = fc_frame_header_get(fp);
305
306 skb = fp_skb(fp);
307 if (!lport->link_up) {
308 BNX2FC_HBA_DBG(lport, "bnx2fc_xmit link down\n");
309 kfree_skb(skb);
310 return 0;
311 }
312
313 if (unlikely(fh->fh_r_ctl == FC_RCTL_ELS_REQ)) {
Robert Lovefd8f8902012-05-22 19:06:16 -0700314 if (!ctlr->sel_fcf) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800315 BNX2FC_HBA_DBG(lport, "FCF not selected yet!\n");
316 kfree_skb(skb);
317 return -EINVAL;
318 }
Robert Lovefd8f8902012-05-22 19:06:16 -0700319 if (fcoe_ctlr_els_send(ctlr, lport, skb))
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800320 return 0;
321 }
322
323 sof = fr_sof(fp);
324 eof = fr_eof(fp);
325
326 /*
327 * Snoop the frame header to check if the frame is for
328 * an offloaded session
329 */
330 /*
331 * tgt_ofld_list access is synchronized using
332 * both hba mutex and hba lock. Atleast hba mutex or
333 * hba lock needs to be held for read access.
334 */
335
336 spin_lock_bh(&hba->hba_lock);
337 tgt = bnx2fc_tgt_lookup(port, ntoh24(fh->fh_d_id));
338 if (tgt && (test_bit(BNX2FC_FLAG_SESSION_READY, &tgt->flags))) {
339 /* This frame is for offloaded session */
340 BNX2FC_HBA_DBG(lport, "xmit: Frame is for offloaded session "
341 "port_id = 0x%x\n", ntoh24(fh->fh_d_id));
342 spin_unlock_bh(&hba->hba_lock);
343 rc = bnx2fc_xmit_l2_frame(tgt, fp);
344 if (rc != -ENODEV) {
345 kfree_skb(skb);
346 return rc;
347 }
348 } else {
349 spin_unlock_bh(&hba->hba_lock);
350 }
351
352 elen = sizeof(struct ethhdr);
353 hlen = sizeof(struct fcoe_hdr);
354 tlen = sizeof(struct fcoe_crc_eof);
355 wlen = (skb->len - tlen + sizeof(crc)) / FCOE_WORD_TO_BYTE;
356
357 skb->ip_summed = CHECKSUM_NONE;
358 crc = fcoe_fc_crc(fp);
359
360 /* copy port crc and eof to the skb buff */
361 if (skb_is_nonlinear(skb)) {
362 skb_frag_t *frag;
363 if (bnx2fc_get_paged_crc_eof(skb, tlen)) {
364 kfree_skb(skb);
365 return -ENOMEM;
366 }
367 frag = &skb_shinfo(skb)->frags[skb_shinfo(skb)->nr_frags - 1];
Cong Wang77dfce02011-11-25 23:14:23 +0800368 cp = kmap_atomic(skb_frag_page(frag)) + frag->page_offset;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800369 } else {
370 cp = (struct fcoe_crc_eof *)skb_put(skb, tlen);
371 }
372
373 memset(cp, 0, sizeof(*cp));
374 cp->fcoe_eof = eof;
375 cp->fcoe_crc32 = cpu_to_le32(~crc);
376 if (skb_is_nonlinear(skb)) {
Cong Wang77dfce02011-11-25 23:14:23 +0800377 kunmap_atomic(cp);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800378 cp = NULL;
379 }
380
381 /* adjust skb network/transport offsets to match mac/fcoe/port */
382 skb_push(skb, elen + hlen);
383 skb_reset_mac_header(skb);
384 skb_reset_network_header(skb);
385 skb->mac_len = elen;
386 skb->protocol = htons(ETH_P_FCOE);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700387 skb->dev = interface->netdev;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800388
389 /* fill up mac and fcoe headers */
390 eh = eth_hdr(skb);
391 eh->h_proto = htons(ETH_P_FCOE);
Robert Lovefd8f8902012-05-22 19:06:16 -0700392 if (ctlr->map_dest)
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800393 fc_fcoe_set_mac(eh->h_dest, fh->fh_d_id);
394 else
395 /* insert GW address */
Robert Lovefd8f8902012-05-22 19:06:16 -0700396 memcpy(eh->h_dest, ctlr->dest_addr, ETH_ALEN);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800397
Robert Lovefd8f8902012-05-22 19:06:16 -0700398 if (unlikely(ctlr->flogi_oxid != FC_XID_UNKNOWN))
399 memcpy(eh->h_source, ctlr->ctl_src_addr, ETH_ALEN);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800400 else
401 memcpy(eh->h_source, port->data_src_addr, ETH_ALEN);
402
403 hp = (struct fcoe_hdr *)(eh + 1);
404 memset(hp, 0, sizeof(*hp));
405 if (FC_FCOE_VER)
406 FC_FCOE_ENCAPS_VER(hp, FC_FCOE_VER);
407 hp->fcoe_sof = sof;
408
409 /* fcoe lso, mss is in max_payload which is non-zero for FCP data */
410 if (lport->seq_offload && fr_max_payload(fp)) {
411 skb_shinfo(skb)->gso_type = SKB_GSO_FCOE;
412 skb_shinfo(skb)->gso_size = fr_max_payload(fp);
413 } else {
414 skb_shinfo(skb)->gso_type = 0;
415 skb_shinfo(skb)->gso_size = 0;
416 }
417
418 /*update tx stats */
Vasu Dev1bd49b42012-05-25 10:26:43 -0700419 stats = per_cpu_ptr(lport->stats, get_cpu());
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800420 stats->TxFrames++;
421 stats->TxWords += wlen;
422 put_cpu();
423
424 /* send down to lld */
425 fr_dev(fp) = lport;
426 if (port->fcoe_pending_queue.qlen)
427 fcoe_check_wait_queue(lport, skb);
428 else if (fcoe_start_io(skb))
429 fcoe_check_wait_queue(lport, skb);
430
431 return 0;
432}
433
434/**
435 * bnx2fc_rcv - This is bnx2fc's receive function called by NET_RX_SOFTIRQ
436 *
437 * @skb: the receive socket buffer
438 * @dev: associated net device
439 * @ptype: context
440 * @olddev: last device
441 *
442 * This function receives the packet and builds FC frame and passes it up
443 */
444static int bnx2fc_rcv(struct sk_buff *skb, struct net_device *dev,
445 struct packet_type *ptype, struct net_device *olddev)
446{
447 struct fc_lport *lport;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700448 struct bnx2fc_interface *interface;
Robert Lovefd8f8902012-05-22 19:06:16 -0700449 struct fcoe_ctlr *ctlr;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800450 struct fc_frame_header *fh;
451 struct fcoe_rcv_info *fr;
452 struct fcoe_percpu_s *bg;
453 unsigned short oxid;
454
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700455 interface = container_of(ptype, struct bnx2fc_interface,
456 fcoe_packet_type);
Robert Lovefd8f8902012-05-22 19:06:16 -0700457 ctlr = bnx2fc_to_ctlr(interface);
458 lport = ctlr->lp;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800459
460 if (unlikely(lport == NULL)) {
Bhanu Prakash Gollapudib2a554f2011-06-27 23:30:53 -0700461 printk(KERN_ERR PFX "bnx2fc_rcv: lport is NULL\n");
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800462 goto err;
463 }
464
465 if (unlikely(eth_hdr(skb)->h_proto != htons(ETH_P_FCOE))) {
Bhanu Prakash Gollapudib2a554f2011-06-27 23:30:53 -0700466 printk(KERN_ERR PFX "bnx2fc_rcv: Wrong FC type frame\n");
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800467 goto err;
468 }
469
470 /*
471 * Check for minimum frame length, and make sure required FCoE
472 * and FC headers are pulled into the linear data area.
473 */
474 if (unlikely((skb->len < FCOE_MIN_FRAME) ||
475 !pskb_may_pull(skb, FCOE_HEADER_LEN)))
476 goto err;
477
478 skb_set_transport_header(skb, sizeof(struct fcoe_hdr));
479 fh = (struct fc_frame_header *) skb_transport_header(skb);
480
481 oxid = ntohs(fh->fh_ox_id);
482
483 fr = fcoe_dev_from_skb(skb);
484 fr->fr_dev = lport;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800485
486 bg = &bnx2fc_global;
Neil Hormanfc05ab72012-03-09 14:50:13 -0800487 spin_lock(&bg->fcoe_rx_list.lock);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800488
489 __skb_queue_tail(&bg->fcoe_rx_list, skb);
490 if (bg->fcoe_rx_list.qlen == 1)
491 wake_up_process(bg->thread);
492
Neil Hormanfc05ab72012-03-09 14:50:13 -0800493 spin_unlock(&bg->fcoe_rx_list.lock);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800494
495 return 0;
496err:
497 kfree_skb(skb);
498 return -1;
499}
500
501static int bnx2fc_l2_rcv_thread(void *arg)
502{
503 struct fcoe_percpu_s *bg = arg;
504 struct sk_buff *skb;
505
506 set_user_nice(current, -20);
507 set_current_state(TASK_INTERRUPTIBLE);
508 while (!kthread_should_stop()) {
509 schedule();
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800510 spin_lock_bh(&bg->fcoe_rx_list.lock);
511 while ((skb = __skb_dequeue(&bg->fcoe_rx_list)) != NULL) {
512 spin_unlock_bh(&bg->fcoe_rx_list.lock);
513 bnx2fc_recv_frame(skb);
514 spin_lock_bh(&bg->fcoe_rx_list.lock);
515 }
Bhanu Gollapudifee78712011-03-21 18:51:13 -0700516 __set_current_state(TASK_INTERRUPTIBLE);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800517 spin_unlock_bh(&bg->fcoe_rx_list.lock);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800518 }
Bhanu Gollapudifee78712011-03-21 18:51:13 -0700519 __set_current_state(TASK_RUNNING);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800520 return 0;
521}
522
523
524static void bnx2fc_recv_frame(struct sk_buff *skb)
525{
526 u32 fr_len;
527 struct fc_lport *lport;
528 struct fcoe_rcv_info *fr;
Vasu Dev1bd49b42012-05-25 10:26:43 -0700529 struct fc_stats *stats;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800530 struct fc_frame_header *fh;
531 struct fcoe_crc_eof crc_eof;
532 struct fc_frame *fp;
533 struct fc_lport *vn_port;
534 struct fcoe_port *port;
535 u8 *mac = NULL;
536 u8 *dest_mac = NULL;
537 struct fcoe_hdr *hp;
538
539 fr = fcoe_dev_from_skb(skb);
540 lport = fr->fr_dev;
541 if (unlikely(lport == NULL)) {
Bhanu Prakash Gollapudib2a554f2011-06-27 23:30:53 -0700542 printk(KERN_ERR PFX "Invalid lport struct\n");
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800543 kfree_skb(skb);
544 return;
545 }
546
547 if (skb_is_nonlinear(skb))
548 skb_linearize(skb);
549 mac = eth_hdr(skb)->h_source;
550 dest_mac = eth_hdr(skb)->h_dest;
551
552 /* Pull the header */
553 hp = (struct fcoe_hdr *) skb_network_header(skb);
554 fh = (struct fc_frame_header *) skb_transport_header(skb);
555 skb_pull(skb, sizeof(struct fcoe_hdr));
556 fr_len = skb->len - sizeof(struct fcoe_crc_eof);
557
Vasu Dev1bd49b42012-05-25 10:26:43 -0700558 stats = per_cpu_ptr(lport->stats, get_cpu());
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800559 stats->RxFrames++;
560 stats->RxWords += fr_len / FCOE_WORD_TO_BYTE;
561
562 fp = (struct fc_frame *)skb;
563 fc_frame_init(fp);
564 fr_dev(fp) = lport;
565 fr_sof(fp) = hp->fcoe_sof;
566 if (skb_copy_bits(skb, fr_len, &crc_eof, sizeof(crc_eof))) {
567 put_cpu();
568 kfree_skb(skb);
569 return;
570 }
571 fr_eof(fp) = crc_eof.fcoe_eof;
572 fr_crc(fp) = crc_eof.fcoe_crc32;
573 if (pskb_trim(skb, fr_len)) {
574 put_cpu();
575 kfree_skb(skb);
576 return;
577 }
578
579 fh = fc_frame_header_get(fp);
580
581 vn_port = fc_vport_id_lookup(lport, ntoh24(fh->fh_d_id));
582 if (vn_port) {
583 port = lport_priv(vn_port);
584 if (compare_ether_addr(port->data_src_addr, dest_mac)
585 != 0) {
586 BNX2FC_HBA_DBG(lport, "fpma mismatch\n");
587 put_cpu();
588 kfree_skb(skb);
589 return;
590 }
591 }
592 if (fh->fh_r_ctl == FC_RCTL_DD_SOL_DATA &&
593 fh->fh_type == FC_TYPE_FCP) {
594 /* Drop FCP data. We dont this in L2 path */
595 put_cpu();
596 kfree_skb(skb);
597 return;
598 }
599 if (fh->fh_r_ctl == FC_RCTL_ELS_REQ &&
600 fh->fh_type == FC_TYPE_ELS) {
601 switch (fc_frame_payload_op(fp)) {
602 case ELS_LOGO:
603 if (ntoh24(fh->fh_s_id) == FC_FID_FLOGI) {
604 /* drop non-FIP LOGO */
605 put_cpu();
606 kfree_skb(skb);
607 return;
608 }
609 break;
610 }
611 }
Bhanu Prakash Gollapudi3f8744d2011-08-04 17:38:48 -0700612
613 if (fh->fh_r_ctl == FC_RCTL_BA_ABTS) {
614 /* Drop incoming ABTS */
615 put_cpu();
616 kfree_skb(skb);
617 return;
618 }
619
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800620 if (le32_to_cpu(fr_crc(fp)) !=
621 ~crc32(~0, skb->data, fr_len)) {
622 if (stats->InvalidCRCCount < 5)
623 printk(KERN_WARNING PFX "dropping frame with "
624 "CRC error\n");
625 stats->InvalidCRCCount++;
626 put_cpu();
627 kfree_skb(skb);
628 return;
629 }
630 put_cpu();
631 fc_exch_recv(lport, fp);
632}
633
634/**
635 * bnx2fc_percpu_io_thread - thread per cpu for ios
636 *
637 * @arg: ptr to bnx2fc_percpu_info structure
638 */
639int bnx2fc_percpu_io_thread(void *arg)
640{
641 struct bnx2fc_percpu_s *p = arg;
642 struct bnx2fc_work *work, *tmp;
643 LIST_HEAD(work_list);
644
645 set_user_nice(current, -20);
646 set_current_state(TASK_INTERRUPTIBLE);
647 while (!kthread_should_stop()) {
648 schedule();
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800649 spin_lock_bh(&p->fp_work_lock);
650 while (!list_empty(&p->work_list)) {
651 list_splice_init(&p->work_list, &work_list);
652 spin_unlock_bh(&p->fp_work_lock);
653
654 list_for_each_entry_safe(work, tmp, &work_list, list) {
655 list_del_init(&work->list);
656 bnx2fc_process_cq_compl(work->tgt, work->wqe);
657 kfree(work);
658 }
659
660 spin_lock_bh(&p->fp_work_lock);
661 }
Bhanu Gollapudifee78712011-03-21 18:51:13 -0700662 __set_current_state(TASK_INTERRUPTIBLE);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800663 spin_unlock_bh(&p->fp_work_lock);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800664 }
Bhanu Gollapudifee78712011-03-21 18:51:13 -0700665 __set_current_state(TASK_RUNNING);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800666
667 return 0;
668}
669
670static struct fc_host_statistics *bnx2fc_get_host_stats(struct Scsi_Host *shost)
671{
672 struct fc_host_statistics *bnx2fc_stats;
673 struct fc_lport *lport = shost_priv(shost);
674 struct fcoe_port *port = lport_priv(lport);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700675 struct bnx2fc_interface *interface = port->priv;
676 struct bnx2fc_hba *hba = interface->hba;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800677 struct fcoe_statistics_params *fw_stats;
678 int rc = 0;
679
680 fw_stats = (struct fcoe_statistics_params *)hba->stats_buffer;
681 if (!fw_stats)
682 return NULL;
683
684 bnx2fc_stats = fc_get_host_stats(shost);
685
686 init_completion(&hba->stat_req_done);
687 if (bnx2fc_send_stat_req(hba))
688 return bnx2fc_stats;
689 rc = wait_for_completion_timeout(&hba->stat_req_done, (2 * HZ));
690 if (!rc) {
691 BNX2FC_HBA_DBG(lport, "FW stat req timed out\n");
692 return bnx2fc_stats;
693 }
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300694 bnx2fc_stats->invalid_crc_count += fw_stats->rx_stat2.fc_crc_cnt;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800695 bnx2fc_stats->tx_frames += fw_stats->tx_stat.fcoe_tx_pkt_cnt;
696 bnx2fc_stats->tx_words += (fw_stats->tx_stat.fcoe_tx_byte_cnt) / 4;
697 bnx2fc_stats->rx_frames += fw_stats->rx_stat0.fcoe_rx_pkt_cnt;
698 bnx2fc_stats->rx_words += (fw_stats->rx_stat0.fcoe_rx_byte_cnt) / 4;
699
700 bnx2fc_stats->dumped_frames = 0;
701 bnx2fc_stats->lip_count = 0;
702 bnx2fc_stats->nos_count = 0;
703 bnx2fc_stats->loss_of_sync_count = 0;
704 bnx2fc_stats->loss_of_signal_count = 0;
705 bnx2fc_stats->prim_seq_protocol_err_count = 0;
706
707 return bnx2fc_stats;
708}
709
710static int bnx2fc_shost_config(struct fc_lport *lport, struct device *dev)
711{
712 struct fcoe_port *port = lport_priv(lport);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700713 struct bnx2fc_interface *interface = port->priv;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800714 struct Scsi_Host *shost = lport->host;
715 int rc = 0;
716
717 shost->max_cmd_len = BNX2FC_MAX_CMD_LEN;
718 shost->max_lun = BNX2FC_MAX_LUN;
719 shost->max_id = BNX2FC_MAX_FCP_TGT;
720 shost->max_channel = 0;
721 if (lport->vport)
722 shost->transportt = bnx2fc_vport_xport_template;
723 else
724 shost->transportt = bnx2fc_transport_template;
725
726 /* Add the new host to SCSI-ml */
727 rc = scsi_add_host(lport->host, dev);
728 if (rc) {
729 printk(KERN_ERR PFX "Error on scsi_add_host\n");
730 return rc;
731 }
732 if (!lport->vport)
733 fc_host_max_npiv_vports(lport->host) = USHRT_MAX;
734 sprintf(fc_host_symbolic_name(lport->host), "%s v%s over %s",
735 BNX2FC_NAME, BNX2FC_VERSION,
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700736 interface->netdev->name);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800737
738 return 0;
739}
740
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800741static int bnx2fc_link_ok(struct fc_lport *lport)
742{
743 struct fcoe_port *port = lport_priv(lport);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700744 struct bnx2fc_interface *interface = port->priv;
745 struct bnx2fc_hba *hba = interface->hba;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800746 struct net_device *dev = hba->phys_dev;
747 int rc = 0;
748
749 if ((dev->flags & IFF_UP) && netif_carrier_ok(dev))
750 clear_bit(ADAPTER_STATE_LINK_DOWN, &hba->adapter_state);
751 else {
752 set_bit(ADAPTER_STATE_LINK_DOWN, &hba->adapter_state);
753 rc = -1;
754 }
755 return rc;
756}
757
758/**
759 * bnx2fc_get_link_state - get network link state
760 *
761 * @hba: adapter instance pointer
762 *
763 * updates adapter structure flag based on netdev state
764 */
765void bnx2fc_get_link_state(struct bnx2fc_hba *hba)
766{
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700767 if (test_bit(__LINK_STATE_NOCARRIER, &hba->phys_dev->state))
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800768 set_bit(ADAPTER_STATE_LINK_DOWN, &hba->adapter_state);
769 else
770 clear_bit(ADAPTER_STATE_LINK_DOWN, &hba->adapter_state);
771}
772
Bhanu Prakash Gollapudi52439602011-08-04 17:38:50 -0700773static int bnx2fc_net_config(struct fc_lport *lport, struct net_device *netdev)
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800774{
775 struct bnx2fc_hba *hba;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700776 struct bnx2fc_interface *interface;
Robert Lovefd8f8902012-05-22 19:06:16 -0700777 struct fcoe_ctlr *ctlr;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800778 struct fcoe_port *port;
779 u64 wwnn, wwpn;
780
781 port = lport_priv(lport);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700782 interface = port->priv;
Robert Lovefd8f8902012-05-22 19:06:16 -0700783 ctlr = bnx2fc_to_ctlr(interface);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700784 hba = interface->hba;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800785
786 /* require support for get_pauseparam ethtool op. */
787 if (!hba->phys_dev->ethtool_ops ||
788 !hba->phys_dev->ethtool_ops->get_pauseparam)
789 return -EOPNOTSUPP;
790
Bhanu Gollapudi1294bfe2011-03-17 17:13:34 -0700791 if (fc_set_mfs(lport, BNX2FC_MFS))
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800792 return -EINVAL;
793
794 skb_queue_head_init(&port->fcoe_pending_queue);
795 port->fcoe_pending_queue_active = 0;
796 setup_timer(&port->timer, fcoe_queue_timer, (unsigned long) lport);
797
Yi Zou0e0f9cd2012-12-06 06:24:44 +0000798 fcoe_link_speed_update(lport);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800799
800 if (!lport->vport) {
Bhanu Prakash Gollapudi52439602011-08-04 17:38:50 -0700801 if (fcoe_get_wwn(netdev, &wwnn, NETDEV_FCOE_WWNN))
Robert Lovefd8f8902012-05-22 19:06:16 -0700802 wwnn = fcoe_wwn_from_mac(ctlr->ctl_src_addr,
Bhanu Prakash Gollapudi52439602011-08-04 17:38:50 -0700803 1, 0);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800804 BNX2FC_HBA_DBG(lport, "WWNN = 0x%llx\n", wwnn);
805 fc_set_wwnn(lport, wwnn);
806
Bhanu Prakash Gollapudi52439602011-08-04 17:38:50 -0700807 if (fcoe_get_wwn(netdev, &wwpn, NETDEV_FCOE_WWPN))
Robert Lovefd8f8902012-05-22 19:06:16 -0700808 wwpn = fcoe_wwn_from_mac(ctlr->ctl_src_addr,
Bhanu Prakash Gollapudi52439602011-08-04 17:38:50 -0700809 2, 0);
810
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800811 BNX2FC_HBA_DBG(lport, "WWPN = 0x%llx\n", wwpn);
812 fc_set_wwpn(lport, wwpn);
813 }
814
815 return 0;
816}
817
818static void bnx2fc_destroy_timer(unsigned long data)
819{
820 struct bnx2fc_hba *hba = (struct bnx2fc_hba *)data;
821
Bhanu Prakash Gollapudicd703ae2011-08-04 17:38:43 -0700822 printk(KERN_ERR PFX "ERROR:bnx2fc_destroy_timer - "
823 "Destroy compl not received!!\n");
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700824 set_bit(BNX2FC_FLAG_DESTROY_CMPL, &hba->flags);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800825 wake_up_interruptible(&hba->destroy_wait);
826}
827
828/**
829 * bnx2fc_indicate_netevent - Generic netdev event handler
830 *
831 * @context: adapter structure pointer
832 * @event: event type
Michael Chan415199f2011-07-20 14:55:24 +0000833 * @vlan_id: vlan id - associated vlan id with this event
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800834 *
835 * Handles NETDEV_UP, NETDEV_DOWN, NETDEV_GOING_DOWN,NETDEV_CHANGE and
Bhanu Prakash Gollapudiabc49a92011-08-04 17:38:42 -0700836 * NETDEV_CHANGE_MTU events. Handle NETDEV_UNREGISTER only for vlans.
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800837 */
Michael Chan415199f2011-07-20 14:55:24 +0000838static void bnx2fc_indicate_netevent(void *context, unsigned long event,
839 u16 vlan_id)
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800840{
841 struct bnx2fc_hba *hba = (struct bnx2fc_hba *)context;
Robert Love6e89ea32012-11-27 06:53:40 +0000842 struct fcoe_ctlr_device *cdev;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700843 struct fc_lport *lport;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800844 struct fc_lport *vport;
Bhanu Prakash Gollapudiabc49a92011-08-04 17:38:42 -0700845 struct bnx2fc_interface *interface, *tmp;
Robert Lovefd8f8902012-05-22 19:06:16 -0700846 struct fcoe_ctlr *ctlr;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700847 int wait_for_upload = 0;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800848 u32 link_possible = 1;
849
Bhanu Prakash Gollapudiabc49a92011-08-04 17:38:42 -0700850 if (vlan_id != 0 && event != NETDEV_UNREGISTER)
Michael Chan415199f2011-07-20 14:55:24 +0000851 return;
852
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800853 switch (event) {
854 case NETDEV_UP:
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800855 if (!test_bit(ADAPTER_STATE_UP, &hba->adapter_state))
856 printk(KERN_ERR "indicate_netevent: "\
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700857 "hba is not UP!!\n");
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800858 break;
859
860 case NETDEV_DOWN:
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800861 clear_bit(ADAPTER_STATE_GOING_DOWN, &hba->adapter_state);
862 clear_bit(ADAPTER_STATE_UP, &hba->adapter_state);
863 link_possible = 0;
864 break;
865
866 case NETDEV_GOING_DOWN:
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800867 set_bit(ADAPTER_STATE_GOING_DOWN, &hba->adapter_state);
868 link_possible = 0;
869 break;
870
871 case NETDEV_CHANGE:
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800872 break;
873
Bhanu Prakash Gollapudiabc49a92011-08-04 17:38:42 -0700874 case NETDEV_UNREGISTER:
875 if (!vlan_id)
876 return;
877 mutex_lock(&bnx2fc_dev_lock);
878 list_for_each_entry_safe(interface, tmp, &if_list, list) {
Nithin Nayak Sujir26b29822011-08-30 15:54:50 -0700879 if (interface->hba == hba &&
880 interface->vlan_id == (vlan_id & VLAN_VID_MASK))
881 __bnx2fc_destroy(interface);
Bhanu Prakash Gollapudiabc49a92011-08-04 17:38:42 -0700882 }
883 mutex_unlock(&bnx2fc_dev_lock);
884 return;
885
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800886 default:
Masanari Iida59e13d42012-04-25 00:24:16 +0900887 printk(KERN_ERR PFX "Unknown netevent %ld", event);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800888 return;
889 }
890
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700891 mutex_lock(&bnx2fc_dev_lock);
892 list_for_each_entry(interface, &if_list, list) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800893
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700894 if (interface->hba != hba)
895 continue;
896
Robert Lovefd8f8902012-05-22 19:06:16 -0700897 ctlr = bnx2fc_to_ctlr(interface);
898 lport = ctlr->lp;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700899 BNX2FC_HBA_DBG(lport, "netevent handler - event=%s %ld\n",
900 interface->netdev->name, event);
901
Yi Zou0e0f9cd2012-12-06 06:24:44 +0000902 fcoe_link_speed_update(lport);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700903
Robert Love6e89ea32012-11-27 06:53:40 +0000904 cdev = fcoe_ctlr_to_ctlr_dev(ctlr);
905
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700906 if (link_possible && !bnx2fc_link_ok(lport)) {
Robert Love6e89ea32012-11-27 06:53:40 +0000907 switch (cdev->enabled) {
908 case FCOE_CTLR_DISABLED:
909 pr_info("Link up while interface is disabled.\n");
910 break;
911 case FCOE_CTLR_ENABLED:
912 case FCOE_CTLR_UNUSED:
913 /* Reset max recv frame size to default */
914 fc_set_mfs(lport, BNX2FC_MFS);
915 /*
916 * ctlr link up will only be handled during
917 * enable to avoid sending discovery
918 * solicitation on a stale vlan
919 */
920 if (interface->enabled)
921 fcoe_ctlr_link_up(ctlr);
922 };
Robert Lovefd8f8902012-05-22 19:06:16 -0700923 } else if (fcoe_ctlr_link_down(ctlr)) {
Robert Love6e89ea32012-11-27 06:53:40 +0000924 switch (cdev->enabled) {
925 case FCOE_CTLR_DISABLED:
926 pr_info("Link down while interface is disabled.\n");
927 break;
928 case FCOE_CTLR_ENABLED:
929 case FCOE_CTLR_UNUSED:
930 mutex_lock(&lport->lp_mutex);
931 list_for_each_entry(vport, &lport->vports, list)
932 fc_host_port_type(vport->host) =
933 FC_PORTTYPE_UNKNOWN;
934 mutex_unlock(&lport->lp_mutex);
935 fc_host_port_type(lport->host) =
936 FC_PORTTYPE_UNKNOWN;
937 per_cpu_ptr(lport->stats,
938 get_cpu())->LinkFailureCount++;
939 put_cpu();
940 fcoe_clean_pending_queue(lport);
941 wait_for_upload = 1;
942 };
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800943 }
944 }
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700945 mutex_unlock(&bnx2fc_dev_lock);
946
947 if (wait_for_upload) {
948 clear_bit(ADAPTER_STATE_READY, &hba->adapter_state);
949 init_waitqueue_head(&hba->shutdown_wait);
950 BNX2FC_MISC_DBG("indicate_netevent "
951 "num_ofld_sess = %d\n",
952 hba->num_ofld_sess);
953 hba->wait_for_link_down = 1;
954 wait_event_interruptible(hba->shutdown_wait,
955 (hba->num_ofld_sess == 0));
956 BNX2FC_MISC_DBG("wakeup - num_ofld_sess = %d\n",
957 hba->num_ofld_sess);
958 hba->wait_for_link_down = 0;
959
960 if (signal_pending(current))
961 flush_signals(current);
962 }
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800963}
964
965static int bnx2fc_libfc_config(struct fc_lport *lport)
966{
967
968 /* Set the function pointers set by bnx2fc driver */
969 memcpy(&lport->tt, &bnx2fc_libfc_fcn_templ,
970 sizeof(struct libfc_function_template));
971 fc_elsct_init(lport);
972 fc_exch_init(lport);
973 fc_rport_init(lport);
974 fc_disc_init(lport);
975 return 0;
976}
977
978static int bnx2fc_em_config(struct fc_lport *lport)
979{
Bhanu Prakash Gollapudi7d742f62012-01-23 18:00:48 -0800980 int max_xid;
981
982 if (nr_cpu_ids <= 2)
983 max_xid = FCOE_XIDS_PER_CPU;
984 else
985 max_xid = FCOE_MAX_XID;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800986 if (!fc_exch_mgr_alloc(lport, FC_CLASS_3, FCOE_MIN_XID,
Bhanu Prakash Gollapudi7d742f62012-01-23 18:00:48 -0800987 max_xid, NULL)) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800988 printk(KERN_ERR PFX "em_config:fc_exch_mgr_alloc failed\n");
989 return -ENOMEM;
990 }
991
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800992 return 0;
993}
994
995static int bnx2fc_lport_config(struct fc_lport *lport)
996{
997 lport->link_up = 0;
998 lport->qfull = 0;
Bhanu Prakash Gollapudi44c570b2012-01-23 18:00:47 -0800999 lport->max_retry_count = BNX2FC_MAX_RETRY_CNT;
1000 lport->max_rport_retry_count = BNX2FC_MAX_RPORT_RETRY_CNT;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001001 lport->e_d_tov = 2 * 1000;
1002 lport->r_a_tov = 10 * 1000;
1003
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001004 lport->service_params = (FCP_SPPF_INIT_FCN | FCP_SPPF_RD_XRDY_DIS |
1005 FCP_SPPF_RETRY | FCP_SPPF_CONF_COMPL);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001006 lport->does_npiv = 1;
1007
1008 memset(&lport->rnid_gen, 0, sizeof(struct fc_els_rnid_gen));
1009 lport->rnid_gen.rnid_atype = BNX2FC_RNID_HBA;
1010
1011 /* alloc stats structure */
1012 if (fc_lport_init_stats(lport))
1013 return -ENOMEM;
1014
1015 /* Finish fc_lport configuration */
1016 fc_lport_config(lport);
1017
1018 return 0;
1019}
1020
1021/**
1022 * bnx2fc_fip_recv - handle a received FIP frame.
1023 *
1024 * @skb: the received skb
1025 * @dev: associated &net_device
1026 * @ptype: the &packet_type structure which was used to register this handler.
1027 * @orig_dev: original receive &net_device, in case @ dev is a bond.
1028 *
1029 * Returns: 0 for success
1030 */
1031static int bnx2fc_fip_recv(struct sk_buff *skb, struct net_device *dev,
1032 struct packet_type *ptype,
1033 struct net_device *orig_dev)
1034{
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001035 struct bnx2fc_interface *interface;
Robert Lovefd8f8902012-05-22 19:06:16 -07001036 struct fcoe_ctlr *ctlr;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001037 interface = container_of(ptype, struct bnx2fc_interface,
1038 fip_packet_type);
Robert Lovefd8f8902012-05-22 19:06:16 -07001039 ctlr = bnx2fc_to_ctlr(interface);
1040 fcoe_ctlr_recv(ctlr, skb);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001041 return 0;
1042}
1043
1044/**
1045 * bnx2fc_update_src_mac - Update Ethernet MAC filters.
1046 *
1047 * @fip: FCoE controller.
1048 * @old: Unicast MAC address to delete if the MAC is non-zero.
1049 * @new: Unicast MAC address to add.
1050 *
1051 * Remove any previously-set unicast MAC filter.
1052 * Add secondary FCoE MAC address filter for our OUI.
1053 */
1054static void bnx2fc_update_src_mac(struct fc_lport *lport, u8 *addr)
1055{
1056 struct fcoe_port *port = lport_priv(lport);
1057
1058 memcpy(port->data_src_addr, addr, ETH_ALEN);
1059}
1060
1061/**
1062 * bnx2fc_get_src_mac - return the ethernet source address for an lport
1063 *
1064 * @lport: libfc port
1065 */
1066static u8 *bnx2fc_get_src_mac(struct fc_lport *lport)
1067{
1068 struct fcoe_port *port;
1069
1070 port = (struct fcoe_port *)lport_priv(lport);
1071 return port->data_src_addr;
1072}
1073
1074/**
1075 * bnx2fc_fip_send - send an Ethernet-encapsulated FIP frame.
1076 *
1077 * @fip: FCoE controller.
1078 * @skb: FIP Packet.
1079 */
1080static void bnx2fc_fip_send(struct fcoe_ctlr *fip, struct sk_buff *skb)
1081{
1082 skb->dev = bnx2fc_from_ctlr(fip)->netdev;
1083 dev_queue_xmit(skb);
1084}
1085
1086static int bnx2fc_vport_create(struct fc_vport *vport, bool disabled)
1087{
1088 struct Scsi_Host *shost = vport_to_shost(vport);
1089 struct fc_lport *n_port = shost_priv(shost);
1090 struct fcoe_port *port = lport_priv(n_port);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001091 struct bnx2fc_interface *interface = port->priv;
1092 struct net_device *netdev = interface->netdev;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001093 struct fc_lport *vn_port;
Bhanu Prakash Gollapudi861efc52011-08-04 17:38:51 -07001094 int rc;
1095 char buf[32];
1096
1097 rc = fcoe_validate_vport_create(vport);
1098 if (rc) {
1099 fcoe_wwn_to_str(vport->port_name, buf, sizeof(buf));
1100 printk(KERN_ERR PFX "Failed to create vport, "
1101 "WWPN (0x%s) already exists\n",
1102 buf);
1103 return rc;
1104 }
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001105
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001106 if (!test_bit(BNX2FC_FLAG_FW_INIT_DONE, &interface->hba->flags)) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001107 printk(KERN_ERR PFX "vn ports cannot be created on"
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001108 "this interface\n");
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001109 return -EIO;
1110 }
Jiri Pirko4bc71cb2011-09-03 03:34:30 +00001111 rtnl_lock();
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001112 mutex_lock(&bnx2fc_dev_lock);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001113 vn_port = bnx2fc_if_create(interface, &vport->dev, 1);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001114 mutex_unlock(&bnx2fc_dev_lock);
Jiri Pirko4bc71cb2011-09-03 03:34:30 +00001115 rtnl_unlock();
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001116
1117 if (IS_ERR(vn_port)) {
1118 printk(KERN_ERR PFX "bnx2fc_vport_create (%s) failed\n",
1119 netdev->name);
1120 return -EIO;
1121 }
1122
1123 if (disabled) {
1124 fc_vport_set_state(vport, FC_VPORT_DISABLED);
1125 } else {
1126 vn_port->boot_time = jiffies;
1127 fc_lport_init(vn_port);
1128 fc_fabric_login(vn_port);
1129 fc_vport_setlink(vn_port);
1130 }
1131 return 0;
1132}
1133
Bhanu Prakash Gollapudiabc49a92011-08-04 17:38:42 -07001134static void bnx2fc_free_vport(struct bnx2fc_hba *hba, struct fc_lport *lport)
1135{
1136 struct bnx2fc_lport *blport, *tmp;
1137
1138 spin_lock_bh(&hba->hba_lock);
1139 list_for_each_entry_safe(blport, tmp, &hba->vports, list) {
1140 if (blport->lport == lport) {
1141 list_del(&blport->list);
1142 kfree(blport);
1143 }
1144 }
1145 spin_unlock_bh(&hba->hba_lock);
1146}
1147
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001148static int bnx2fc_vport_destroy(struct fc_vport *vport)
1149{
1150 struct Scsi_Host *shost = vport_to_shost(vport);
1151 struct fc_lport *n_port = shost_priv(shost);
1152 struct fc_lport *vn_port = vport->dd_data;
1153 struct fcoe_port *port = lport_priv(vn_port);
Bhanu Prakash Gollapudiabc49a92011-08-04 17:38:42 -07001154 struct bnx2fc_interface *interface = port->priv;
Bhanu Prakash Gollapudicdf54662011-08-04 17:38:39 -07001155 struct fc_lport *v_port;
1156 bool found = false;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001157
1158 mutex_lock(&n_port->lp_mutex);
Bhanu Prakash Gollapudicdf54662011-08-04 17:38:39 -07001159 list_for_each_entry(v_port, &n_port->vports, list)
1160 if (v_port->vport == vport) {
1161 found = true;
1162 break;
1163 }
1164
1165 if (!found) {
1166 mutex_unlock(&n_port->lp_mutex);
1167 return -ENOENT;
1168 }
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001169 list_del(&vn_port->list);
1170 mutex_unlock(&n_port->lp_mutex);
Bhanu Prakash Gollapudiabc49a92011-08-04 17:38:42 -07001171 bnx2fc_free_vport(interface->hba, port->lport);
1172 bnx2fc_port_shutdown(port->lport);
1173 bnx2fc_interface_put(interface);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001174 queue_work(bnx2fc_wq, &port->destroy_work);
1175 return 0;
1176}
1177
1178static int bnx2fc_vport_disable(struct fc_vport *vport, bool disable)
1179{
1180 struct fc_lport *lport = vport->dd_data;
1181
1182 if (disable) {
1183 fc_vport_set_state(vport, FC_VPORT_DISABLED);
1184 fc_fabric_logoff(lport);
1185 } else {
1186 lport->boot_time = jiffies;
1187 fc_fabric_login(lport);
1188 fc_vport_setlink(lport);
1189 }
1190 return 0;
1191}
1192
1193
Bhanu Prakash Gollapudi776cebc2011-08-04 17:38:40 -07001194static int bnx2fc_interface_setup(struct bnx2fc_interface *interface)
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001195{
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001196 struct net_device *netdev = interface->netdev;
1197 struct net_device *physdev = interface->hba->phys_dev;
Robert Lovefd8f8902012-05-22 19:06:16 -07001198 struct fcoe_ctlr *ctlr = bnx2fc_to_ctlr(interface);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001199 struct netdev_hw_addr *ha;
1200 int sel_san_mac = 0;
1201
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001202 /* setup Source MAC Address */
1203 rcu_read_lock();
1204 for_each_dev_addr(physdev, ha) {
1205 BNX2FC_MISC_DBG("net_config: ha->type = %d, fip_mac = ",
1206 ha->type);
1207 printk(KERN_INFO "%2x:%2x:%2x:%2x:%2x:%2x\n", ha->addr[0],
1208 ha->addr[1], ha->addr[2], ha->addr[3],
1209 ha->addr[4], ha->addr[5]);
1210
1211 if ((ha->type == NETDEV_HW_ADDR_T_SAN) &&
1212 (is_valid_ether_addr(ha->addr))) {
Robert Lovefd8f8902012-05-22 19:06:16 -07001213 memcpy(ctlr->ctl_src_addr, ha->addr,
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001214 ETH_ALEN);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001215 sel_san_mac = 1;
1216 BNX2FC_MISC_DBG("Found SAN MAC\n");
1217 }
1218 }
1219 rcu_read_unlock();
1220
1221 if (!sel_san_mac)
1222 return -ENODEV;
1223
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001224 interface->fip_packet_type.func = bnx2fc_fip_recv;
1225 interface->fip_packet_type.type = htons(ETH_P_FIP);
1226 interface->fip_packet_type.dev = netdev;
1227 dev_add_pack(&interface->fip_packet_type);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001228
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001229 interface->fcoe_packet_type.func = bnx2fc_rcv;
1230 interface->fcoe_packet_type.type = __constant_htons(ETH_P_FCOE);
1231 interface->fcoe_packet_type.dev = netdev;
1232 dev_add_pack(&interface->fcoe_packet_type);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001233
1234 return 0;
1235}
1236
1237static int bnx2fc_attach_transport(void)
1238{
1239 bnx2fc_transport_template =
1240 fc_attach_transport(&bnx2fc_transport_function);
1241
1242 if (bnx2fc_transport_template == NULL) {
1243 printk(KERN_ERR PFX "Failed to attach FC transport\n");
1244 return -ENODEV;
1245 }
1246
1247 bnx2fc_vport_xport_template =
1248 fc_attach_transport(&bnx2fc_vport_xport_function);
1249 if (bnx2fc_vport_xport_template == NULL) {
1250 printk(KERN_ERR PFX
1251 "Failed to attach FC transport for vport\n");
1252 fc_release_transport(bnx2fc_transport_template);
1253 bnx2fc_transport_template = NULL;
1254 return -ENODEV;
1255 }
1256 return 0;
1257}
1258static void bnx2fc_release_transport(void)
1259{
1260 fc_release_transport(bnx2fc_transport_template);
1261 fc_release_transport(bnx2fc_vport_xport_template);
1262 bnx2fc_transport_template = NULL;
1263 bnx2fc_vport_xport_template = NULL;
1264}
1265
1266static void bnx2fc_interface_release(struct kref *kref)
1267{
Robert Love8d55e502012-05-22 19:06:26 -07001268 struct fcoe_ctlr_device *ctlr_dev;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001269 struct bnx2fc_interface *interface;
Robert Lovefd8f8902012-05-22 19:06:16 -07001270 struct fcoe_ctlr *ctlr;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001271 struct net_device *netdev;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001272
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001273 interface = container_of(kref, struct bnx2fc_interface, kref);
Nithin Nayak Sujir068bdce2011-04-25 12:30:09 -07001274 BNX2FC_MISC_DBG("Interface is being released\n");
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001275
Robert Lovefd8f8902012-05-22 19:06:16 -07001276 ctlr = bnx2fc_to_ctlr(interface);
Robert Love8d55e502012-05-22 19:06:26 -07001277 ctlr_dev = fcoe_ctlr_to_ctlr_dev(ctlr);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001278 netdev = interface->netdev;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001279
1280 /* tear-down FIP controller */
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001281 if (test_and_clear_bit(BNX2FC_CTLR_INIT_DONE, &interface->if_flags))
Robert Lovefd8f8902012-05-22 19:06:16 -07001282 fcoe_ctlr_destroy(ctlr);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001283
Robert Love8d55e502012-05-22 19:06:26 -07001284 fcoe_ctlr_device_delete(ctlr_dev);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001285
1286 dev_put(netdev);
1287 module_put(THIS_MODULE);
1288}
1289
1290static inline void bnx2fc_interface_get(struct bnx2fc_interface *interface)
1291{
1292 kref_get(&interface->kref);
1293}
1294
1295static inline void bnx2fc_interface_put(struct bnx2fc_interface *interface)
1296{
1297 kref_put(&interface->kref, bnx2fc_interface_release);
1298}
1299static void bnx2fc_hba_destroy(struct bnx2fc_hba *hba)
1300{
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001301 /* Free the command manager */
1302 if (hba->cmd_mgr) {
1303 bnx2fc_cmd_mgr_free(hba->cmd_mgr);
1304 hba->cmd_mgr = NULL;
1305 }
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001306 kfree(hba->tgt_ofld_list);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001307 bnx2fc_unbind_pcidev(hba);
1308 kfree(hba);
1309}
1310
1311/**
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001312 * bnx2fc_hba_create - create a new bnx2fc hba
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001313 *
1314 * @cnic: pointer to cnic device
1315 *
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001316 * Creates a new FCoE hba on the given device.
1317 *
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001318 */
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001319static struct bnx2fc_hba *bnx2fc_hba_create(struct cnic_dev *cnic)
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001320{
1321 struct bnx2fc_hba *hba;
Barak Witkowski2e499d32012-06-26 01:31:19 +00001322 struct fcoe_capabilities *fcoe_cap;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001323 int rc;
1324
1325 hba = kzalloc(sizeof(*hba), GFP_KERNEL);
1326 if (!hba) {
1327 printk(KERN_ERR PFX "Unable to allocate hba structure\n");
1328 return NULL;
1329 }
1330 spin_lock_init(&hba->hba_lock);
1331 mutex_init(&hba->hba_mutex);
1332
1333 hba->cnic = cnic;
1334 rc = bnx2fc_bind_pcidev(hba);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001335 if (rc) {
1336 printk(KERN_ERR PFX "create_adapter: bind error\n");
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001337 goto bind_err;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001338 }
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001339 hba->phys_dev = cnic->netdev;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001340 hba->next_conn_id = 0;
1341
1342 hba->tgt_ofld_list =
1343 kzalloc(sizeof(struct bnx2fc_rport *) * BNX2FC_NUM_MAX_SESS,
1344 GFP_KERNEL);
1345 if (!hba->tgt_ofld_list) {
1346 printk(KERN_ERR PFX "Unable to allocate tgt offload list\n");
1347 goto tgtofld_err;
1348 }
1349
1350 hba->num_ofld_sess = 0;
1351
1352 hba->cmd_mgr = bnx2fc_cmd_mgr_alloc(hba, BNX2FC_MIN_XID,
1353 BNX2FC_MAX_XID);
1354 if (!hba->cmd_mgr) {
1355 printk(KERN_ERR PFX "em_config:bnx2fc_cmd_mgr_alloc failed\n");
1356 goto cmgr_err;
1357 }
Barak Witkowski2e499d32012-06-26 01:31:19 +00001358 fcoe_cap = &hba->fcoe_cap;
1359
1360 fcoe_cap->capability1 = BNX2FC_TM_MAX_SQES <<
1361 FCOE_IOS_PER_CONNECTION_SHIFT;
1362 fcoe_cap->capability1 |= BNX2FC_NUM_MAX_SESS <<
1363 FCOE_LOGINS_PER_PORT_SHIFT;
1364 fcoe_cap->capability2 = BNX2FC_MAX_OUTSTANDING_CMNDS <<
1365 FCOE_NUMBER_OF_EXCHANGES_SHIFT;
1366 fcoe_cap->capability2 |= BNX2FC_MAX_NPIV <<
1367 FCOE_NPIV_WWN_PER_PORT_SHIFT;
1368 fcoe_cap->capability3 = BNX2FC_NUM_MAX_SESS <<
1369 FCOE_TARGETS_SUPPORTED_SHIFT;
1370 fcoe_cap->capability3 |= BNX2FC_MAX_OUTSTANDING_CMNDS <<
1371 FCOE_OUTSTANDING_COMMANDS_SHIFT;
1372 fcoe_cap->capability4 = FCOE_CAPABILITY4_STATEFUL;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001373
1374 init_waitqueue_head(&hba->shutdown_wait);
1375 init_waitqueue_head(&hba->destroy_wait);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001376 INIT_LIST_HEAD(&hba->vports);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001377
1378 return hba;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001379
1380cmgr_err:
1381 kfree(hba->tgt_ofld_list);
1382tgtofld_err:
1383 bnx2fc_unbind_pcidev(hba);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001384bind_err:
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001385 kfree(hba);
1386 return NULL;
1387}
1388
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001389struct bnx2fc_interface *bnx2fc_interface_create(struct bnx2fc_hba *hba,
1390 struct net_device *netdev,
1391 enum fip_state fip_mode)
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001392{
Robert Love8d55e502012-05-22 19:06:26 -07001393 struct fcoe_ctlr_device *ctlr_dev;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001394 struct bnx2fc_interface *interface;
Robert Lovefd8f8902012-05-22 19:06:16 -07001395 struct fcoe_ctlr *ctlr;
1396 int size;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001397 int rc = 0;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001398
Robert Lovefd8f8902012-05-22 19:06:16 -07001399 size = (sizeof(*interface) + sizeof(struct fcoe_ctlr));
Robert Love8d55e502012-05-22 19:06:26 -07001400 ctlr_dev = fcoe_ctlr_device_add(&netdev->dev, &bnx2fc_fcoe_sysfs_templ,
1401 size);
1402 if (!ctlr_dev) {
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001403 printk(KERN_ERR PFX "Unable to allocate interface structure\n");
1404 return NULL;
1405 }
Robert Love8d55e502012-05-22 19:06:26 -07001406 ctlr = fcoe_ctlr_device_priv(ctlr_dev);
Robert Lovefd8f8902012-05-22 19:06:16 -07001407 interface = fcoe_ctlr_priv(ctlr);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001408 dev_hold(netdev);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001409 kref_init(&interface->kref);
1410 interface->hba = hba;
1411 interface->netdev = netdev;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001412
1413 /* Initialize FIP */
Robert Lovefd8f8902012-05-22 19:06:16 -07001414 fcoe_ctlr_init(ctlr, fip_mode);
1415 ctlr->send = bnx2fc_fip_send;
1416 ctlr->update_mac = bnx2fc_update_src_mac;
1417 ctlr->get_src_addr = bnx2fc_get_src_mac;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001418 set_bit(BNX2FC_CTLR_INIT_DONE, &interface->if_flags);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001419
Bhanu Prakash Gollapudi776cebc2011-08-04 17:38:40 -07001420 rc = bnx2fc_interface_setup(interface);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001421 if (!rc)
1422 return interface;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001423
Robert Lovefd8f8902012-05-22 19:06:16 -07001424 fcoe_ctlr_destroy(ctlr);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001425 dev_put(netdev);
Robert Love8d55e502012-05-22 19:06:26 -07001426 fcoe_ctlr_device_delete(ctlr_dev);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001427 return NULL;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001428}
1429
1430/**
1431 * bnx2fc_if_create - Create FCoE instance on a given interface
1432 *
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001433 * @interface: FCoE interface to create a local port on
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001434 * @parent: Device pointer to be the parent in sysfs for the SCSI host
1435 * @npiv: Indicates if the port is vport or not
1436 *
1437 * Creates a fc_lport instance and a Scsi_Host instance and configure them.
1438 *
1439 * Returns: Allocated fc_lport or an error pointer
1440 */
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001441static struct fc_lport *bnx2fc_if_create(struct bnx2fc_interface *interface,
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001442 struct device *parent, int npiv)
1443{
Robert Lovefd8f8902012-05-22 19:06:16 -07001444 struct fcoe_ctlr *ctlr = bnx2fc_to_ctlr(interface);
Vasu Dev134a4e22011-04-28 15:55:44 -07001445 struct fc_lport *lport, *n_port;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001446 struct fcoe_port *port;
1447 struct Scsi_Host *shost;
1448 struct fc_vport *vport = dev_to_vport(parent);
Bhanu Prakash Gollapudid36b3272011-05-27 11:47:27 -07001449 struct bnx2fc_lport *blport;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001450 struct bnx2fc_hba *hba;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001451 int rc = 0;
1452
Bhanu Prakash Gollapudid36b3272011-05-27 11:47:27 -07001453 blport = kzalloc(sizeof(struct bnx2fc_lport), GFP_KERNEL);
1454 if (!blport) {
Robert Lovefd8f8902012-05-22 19:06:16 -07001455 BNX2FC_HBA_DBG(ctlr->lp, "Unable to alloc blport\n");
Bhanu Prakash Gollapudid36b3272011-05-27 11:47:27 -07001456 return NULL;
1457 }
1458
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001459 /* Allocate Scsi_Host structure */
Vasu Dev134a4e22011-04-28 15:55:44 -07001460 if (!npiv)
1461 lport = libfc_host_alloc(&bnx2fc_shost_template, sizeof(*port));
1462 else
1463 lport = libfc_vport_create(vport, sizeof(*port));
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001464
1465 if (!lport) {
1466 printk(KERN_ERR PFX "could not allocate scsi host structure\n");
Bhanu Prakash Gollapudid36b3272011-05-27 11:47:27 -07001467 goto free_blport;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001468 }
1469 shost = lport->host;
1470 port = lport_priv(lport);
1471 port->lport = lport;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001472 port->priv = interface;
Yi Zouc3d79092012-12-06 06:24:29 +00001473 port->get_netdev = bnx2fc_netdev;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001474 INIT_WORK(&port->destroy_work, bnx2fc_destroy_work);
1475
1476 /* Configure fcoe_port */
1477 rc = bnx2fc_lport_config(lport);
1478 if (rc)
1479 goto lp_config_err;
1480
1481 if (npiv) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001482 printk(KERN_ERR PFX "Setting vport names, 0x%llX 0x%llX\n",
1483 vport->node_name, vport->port_name);
1484 fc_set_wwnn(lport, vport->node_name);
1485 fc_set_wwpn(lport, vport->port_name);
1486 }
1487 /* Configure netdev and networking properties of the lport */
Bhanu Prakash Gollapudi52439602011-08-04 17:38:50 -07001488 rc = bnx2fc_net_config(lport, interface->netdev);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001489 if (rc) {
1490 printk(KERN_ERR PFX "Error on bnx2fc_net_config\n");
1491 goto lp_config_err;
1492 }
1493
1494 rc = bnx2fc_shost_config(lport, parent);
1495 if (rc) {
1496 printk(KERN_ERR PFX "Couldnt configure shost for %s\n",
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001497 interface->netdev->name);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001498 goto lp_config_err;
1499 }
1500
1501 /* Initialize the libfc library */
1502 rc = bnx2fc_libfc_config(lport);
1503 if (rc) {
1504 printk(KERN_ERR PFX "Couldnt configure libfc\n");
1505 goto shost_err;
1506 }
1507 fc_host_port_type(lport->host) = FC_PORTTYPE_UNKNOWN;
1508
1509 /* Allocate exchange manager */
Vasu Dev134a4e22011-04-28 15:55:44 -07001510 if (!npiv)
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001511 rc = bnx2fc_em_config(lport);
Vasu Dev134a4e22011-04-28 15:55:44 -07001512 else {
1513 shost = vport_to_shost(vport);
1514 n_port = shost_priv(shost);
1515 rc = fc_exch_mgr_list_clone(n_port, lport);
1516 }
1517
1518 if (rc) {
1519 printk(KERN_ERR PFX "Error on bnx2fc_em_config\n");
1520 goto shost_err;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001521 }
1522
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001523 bnx2fc_interface_get(interface);
Bhanu Prakash Gollapudid36b3272011-05-27 11:47:27 -07001524
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001525 hba = interface->hba;
Bhanu Prakash Gollapudid36b3272011-05-27 11:47:27 -07001526 spin_lock_bh(&hba->hba_lock);
1527 blport->lport = lport;
1528 list_add_tail(&blport->list, &hba->vports);
1529 spin_unlock_bh(&hba->hba_lock);
1530
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001531 return lport;
1532
1533shost_err:
1534 scsi_remove_host(shost);
1535lp_config_err:
1536 scsi_host_put(lport->host);
Bhanu Prakash Gollapudid36b3272011-05-27 11:47:27 -07001537free_blport:
1538 kfree(blport);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001539 return NULL;
1540}
1541
Bhanu Prakash Gollapudi013068f2011-08-30 15:54:52 -07001542static void bnx2fc_net_cleanup(struct bnx2fc_interface *interface)
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001543{
1544 /* Dont listen for Ethernet packets anymore */
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001545 __dev_remove_pack(&interface->fcoe_packet_type);
1546 __dev_remove_pack(&interface->fip_packet_type);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001547 synchronize_net();
1548}
1549
Bhanu Prakash Gollapudi776cebc2011-08-04 17:38:40 -07001550static void bnx2fc_interface_cleanup(struct bnx2fc_interface *interface)
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001551{
Robert Lovefd8f8902012-05-22 19:06:16 -07001552 struct fcoe_ctlr *ctlr = bnx2fc_to_ctlr(interface);
1553 struct fc_lport *lport = ctlr->lp;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001554 struct fcoe_port *port = lport_priv(lport);
Bhanu Prakash Gollapudi9be17fc2011-08-04 17:38:41 -07001555 struct bnx2fc_hba *hba = interface->hba;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001556
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001557 /* Stop the transmit retry timer */
1558 del_timer_sync(&port->timer);
1559
1560 /* Free existing transmit skbs */
1561 fcoe_clean_pending_queue(lport);
1562
Bhanu Prakash Gollapudi013068f2011-08-30 15:54:52 -07001563 bnx2fc_net_cleanup(interface);
Bhanu Prakash Gollapudi9be17fc2011-08-04 17:38:41 -07001564
Bhanu Prakash Gollapudiabc49a92011-08-04 17:38:42 -07001565 bnx2fc_free_vport(hba, lport);
Bhanu Prakash Gollapudi9be17fc2011-08-04 17:38:41 -07001566}
1567
1568static void bnx2fc_if_destroy(struct fc_lport *lport)
1569{
1570
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001571 /* Free queued packets for the receive thread */
1572 bnx2fc_clean_rx_queue(lport);
1573
1574 /* Detach from scsi-ml */
1575 fc_remove_host(lport->host);
1576 scsi_remove_host(lport->host);
1577
1578 /*
1579 * Note that only the physical lport will have the exchange manager.
1580 * for vports, this function is NOP
1581 */
1582 fc_exch_mgr_free(lport);
1583
1584 /* Free memory used by statistical counters */
1585 fc_lport_free_stats(lport);
1586
1587 /* Release Scsi_Host */
1588 scsi_host_put(lport->host);
1589}
1590
Bhanu Prakash Gollapudieccdcd02011-08-24 18:56:42 -07001591static void __bnx2fc_destroy(struct bnx2fc_interface *interface)
Bhanu Prakash Gollapudiabc49a92011-08-04 17:38:42 -07001592{
Robert Lovefd8f8902012-05-22 19:06:16 -07001593 struct fcoe_ctlr *ctlr = bnx2fc_to_ctlr(interface);
1594 struct fc_lport *lport = ctlr->lp;
Bhanu Prakash Gollapudi0cbf32e2011-08-30 15:54:51 -07001595 struct fcoe_port *port = lport_priv(lport);
Bhanu Prakash Gollapudiabc49a92011-08-04 17:38:42 -07001596
1597 bnx2fc_interface_cleanup(interface);
1598 bnx2fc_stop(interface);
Bhanu Prakash Gollapudiabc49a92011-08-04 17:38:42 -07001599 list_del(&interface->list);
Bhanu Prakash Gollapudiabc49a92011-08-04 17:38:42 -07001600 bnx2fc_interface_put(interface);
Bhanu Prakash Gollapudi0cbf32e2011-08-30 15:54:51 -07001601 queue_work(bnx2fc_wq, &port->destroy_work);
Bhanu Prakash Gollapudiabc49a92011-08-04 17:38:42 -07001602}
1603
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001604/**
1605 * bnx2fc_destroy - Destroy a bnx2fc FCoE interface
1606 *
1607 * @buffer: The name of the Ethernet interface to be destroyed
1608 * @kp: The associated kernel parameter
1609 *
1610 * Called from sysfs.
1611 *
1612 * Returns: 0 for success
1613 */
1614static int bnx2fc_destroy(struct net_device *netdev)
1615{
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001616 struct bnx2fc_interface *interface = NULL;
Bhanu Prakash Gollapudi2a7b29c2012-01-23 18:00:46 -08001617 struct workqueue_struct *timer_work_queue;
Robert Lovefd8f8902012-05-22 19:06:16 -07001618 struct fcoe_ctlr *ctlr;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001619 int rc = 0;
1620
Nithin Sujir6702ca12011-03-17 17:13:27 -07001621 rtnl_lock();
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001622 mutex_lock(&bnx2fc_dev_lock);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001623
1624 interface = bnx2fc_interface_lookup(netdev);
Robert Lovefd8f8902012-05-22 19:06:16 -07001625 ctlr = bnx2fc_to_ctlr(interface);
1626 if (!interface || !ctlr->lp) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001627 rc = -ENODEV;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001628 printk(KERN_ERR PFX "bnx2fc_destroy: interface or lport not found\n");
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001629 goto netdev_err;
1630 }
1631
Bhanu Prakash Gollapudi2a7b29c2012-01-23 18:00:46 -08001632 timer_work_queue = interface->timer_work_queue;
Bhanu Prakash Gollapudieccdcd02011-08-24 18:56:42 -07001633 __bnx2fc_destroy(interface);
Bhanu Prakash Gollapudi2a7b29c2012-01-23 18:00:46 -08001634 destroy_workqueue(timer_work_queue);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001635
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001636netdev_err:
1637 mutex_unlock(&bnx2fc_dev_lock);
1638 rtnl_unlock();
1639 return rc;
1640}
1641
1642static void bnx2fc_destroy_work(struct work_struct *work)
1643{
1644 struct fcoe_port *port;
1645 struct fc_lport *lport;
1646
1647 port = container_of(work, struct fcoe_port, destroy_work);
1648 lport = port->lport;
1649
1650 BNX2FC_HBA_DBG(lport, "Entered bnx2fc_destroy_work\n");
1651
Bhanu Prakash Gollapudi9be17fc2011-08-04 17:38:41 -07001652 bnx2fc_if_destroy(lport);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001653}
1654
1655static void bnx2fc_unbind_adapter_devices(struct bnx2fc_hba *hba)
1656{
1657 bnx2fc_free_fw_resc(hba);
1658 bnx2fc_free_task_ctx(hba);
1659}
1660
1661/**
1662 * bnx2fc_bind_adapter_devices - binds bnx2fc adapter with the associated
1663 * pci structure
1664 *
1665 * @hba: Adapter instance
1666 */
1667static int bnx2fc_bind_adapter_devices(struct bnx2fc_hba *hba)
1668{
1669 if (bnx2fc_setup_task_ctx(hba))
1670 goto mem_err;
1671
1672 if (bnx2fc_setup_fw_resc(hba))
1673 goto mem_err;
1674
1675 return 0;
1676mem_err:
1677 bnx2fc_unbind_adapter_devices(hba);
1678 return -ENOMEM;
1679}
1680
1681static int bnx2fc_bind_pcidev(struct bnx2fc_hba *hba)
1682{
1683 struct cnic_dev *cnic;
1684
1685 if (!hba->cnic) {
1686 printk(KERN_ERR PFX "cnic is NULL\n");
1687 return -ENODEV;
1688 }
1689 cnic = hba->cnic;
1690 hba->pcidev = cnic->pcidev;
1691 if (hba->pcidev)
1692 pci_dev_get(hba->pcidev);
1693
1694 return 0;
1695}
1696
1697static void bnx2fc_unbind_pcidev(struct bnx2fc_hba *hba)
1698{
1699 if (hba->pcidev)
1700 pci_dev_put(hba->pcidev);
1701 hba->pcidev = NULL;
1702}
1703
Barak Witkowski2e499d32012-06-26 01:31:19 +00001704/**
1705 * bnx2fc_ulp_get_stats - cnic callback to populate FCoE stats
1706 *
1707 * @handle: transport handle pointing to adapter struture
1708 */
1709static int bnx2fc_ulp_get_stats(void *handle)
1710{
1711 struct bnx2fc_hba *hba = handle;
1712 struct cnic_dev *cnic;
1713 struct fcoe_stats_info *stats_addr;
1714
1715 if (!hba)
1716 return -EINVAL;
1717
1718 cnic = hba->cnic;
1719 stats_addr = &cnic->stats_addr->fcoe_stat;
1720 if (!stats_addr)
1721 return -EINVAL;
1722
1723 strncpy(stats_addr->version, BNX2FC_VERSION,
1724 sizeof(stats_addr->version));
1725 stats_addr->txq_size = BNX2FC_SQ_WQES_MAX;
1726 stats_addr->rxq_size = BNX2FC_CQ_WQES_MAX;
1727
1728 return 0;
1729}
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001730
1731
1732/**
1733 * bnx2fc_ulp_start - cnic callback to initialize & start adapter instance
1734 *
Masanari Iida59e13d42012-04-25 00:24:16 +09001735 * @handle: transport handle pointing to adapter structure
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001736 *
1737 * This function maps adapter structure to pcidev structure and initiates
1738 * firmware handshake to enable/initialize on-chip FCoE components.
1739 * This bnx2fc - cnic interface api callback is used after following
1740 * conditions are met -
1741 * a) underlying network interface is up (marked by event NETDEV_UP
1742 * from netdev
1743 * b) bnx2fc adatper structure is registered.
1744 */
1745static void bnx2fc_ulp_start(void *handle)
1746{
1747 struct bnx2fc_hba *hba = handle;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001748 struct bnx2fc_interface *interface;
Robert Lovefd8f8902012-05-22 19:06:16 -07001749 struct fcoe_ctlr *ctlr;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001750 struct fc_lport *lport;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001751
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001752 mutex_lock(&bnx2fc_dev_lock);
1753
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001754 if (!test_bit(BNX2FC_FLAG_FW_INIT_DONE, &hba->flags))
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001755 bnx2fc_fw_init(hba);
1756
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001757 BNX2FC_MISC_DBG("bnx2fc started.\n");
1758
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001759 list_for_each_entry(interface, &if_list, list) {
1760 if (interface->hba == hba) {
Robert Lovefd8f8902012-05-22 19:06:16 -07001761 ctlr = bnx2fc_to_ctlr(interface);
1762 lport = ctlr->lp;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001763 /* Kick off Fabric discovery*/
1764 printk(KERN_ERR PFX "ulp_init: start discovery\n");
1765 lport->tt.frame_send = bnx2fc_xmit;
1766 bnx2fc_start_disc(interface);
1767 }
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001768 }
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001769
1770 mutex_unlock(&bnx2fc_dev_lock);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001771}
1772
1773static void bnx2fc_port_shutdown(struct fc_lport *lport)
1774{
1775 BNX2FC_MISC_DBG("Entered %s\n", __func__);
1776 fc_fabric_logoff(lport);
1777 fc_lport_destroy(lport);
1778}
1779
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001780static void bnx2fc_stop(struct bnx2fc_interface *interface)
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001781{
Robert Lovefd8f8902012-05-22 19:06:16 -07001782 struct fcoe_ctlr *ctlr = bnx2fc_to_ctlr(interface);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001783 struct fc_lport *lport;
1784 struct fc_lport *vport;
1785
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001786 if (!test_bit(BNX2FC_FLAG_FW_INIT_DONE, &interface->hba->flags))
1787 return;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001788
Robert Lovefd8f8902012-05-22 19:06:16 -07001789 lport = ctlr->lp;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001790 bnx2fc_port_shutdown(lport);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001791
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001792 mutex_lock(&lport->lp_mutex);
1793 list_for_each_entry(vport, &lport->vports, list)
1794 fc_host_port_type(vport->host) =
1795 FC_PORTTYPE_UNKNOWN;
1796 mutex_unlock(&lport->lp_mutex);
1797 fc_host_port_type(lport->host) = FC_PORTTYPE_UNKNOWN;
Robert Lovefd8f8902012-05-22 19:06:16 -07001798 fcoe_ctlr_link_down(ctlr);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001799 fcoe_clean_pending_queue(lport);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001800}
1801
1802static int bnx2fc_fw_init(struct bnx2fc_hba *hba)
1803{
1804#define BNX2FC_INIT_POLL_TIME (1000 / HZ)
1805 int rc = -1;
1806 int i = HZ;
1807
1808 rc = bnx2fc_bind_adapter_devices(hba);
1809 if (rc) {
1810 printk(KERN_ALERT PFX
1811 "bnx2fc_bind_adapter_devices failed - rc = %d\n", rc);
1812 goto err_out;
1813 }
1814
1815 rc = bnx2fc_send_fw_fcoe_init_msg(hba);
1816 if (rc) {
1817 printk(KERN_ALERT PFX
1818 "bnx2fc_send_fw_fcoe_init_msg failed - rc = %d\n", rc);
1819 goto err_unbind;
1820 }
1821
1822 /*
1823 * Wait until the adapter init message is complete, and adapter
1824 * state is UP.
1825 */
1826 while (!test_bit(ADAPTER_STATE_UP, &hba->adapter_state) && i--)
1827 msleep(BNX2FC_INIT_POLL_TIME);
1828
1829 if (!test_bit(ADAPTER_STATE_UP, &hba->adapter_state)) {
1830 printk(KERN_ERR PFX "bnx2fc_start: %s failed to initialize. "
1831 "Ignoring...\n",
1832 hba->cnic->netdev->name);
1833 rc = -1;
1834 goto err_unbind;
1835 }
1836
1837
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001838 set_bit(BNX2FC_FLAG_FW_INIT_DONE, &hba->flags);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001839 return 0;
1840
1841err_unbind:
1842 bnx2fc_unbind_adapter_devices(hba);
1843err_out:
1844 return rc;
1845}
1846
1847static void bnx2fc_fw_destroy(struct bnx2fc_hba *hba)
1848{
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001849 if (test_and_clear_bit(BNX2FC_FLAG_FW_INIT_DONE, &hba->flags)) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001850 if (bnx2fc_send_fw_fcoe_destroy_msg(hba) == 0) {
1851 init_timer(&hba->destroy_timer);
1852 hba->destroy_timer.expires = BNX2FC_FW_TIMEOUT +
1853 jiffies;
1854 hba->destroy_timer.function = bnx2fc_destroy_timer;
1855 hba->destroy_timer.data = (unsigned long)hba;
1856 add_timer(&hba->destroy_timer);
1857 wait_event_interruptible(hba->destroy_wait,
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001858 test_bit(BNX2FC_FLAG_DESTROY_CMPL,
1859 &hba->flags));
Bhanu Prakash Gollapudicd703ae2011-08-04 17:38:43 -07001860 clear_bit(BNX2FC_FLAG_DESTROY_CMPL, &hba->flags);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001861 /* This should never happen */
1862 if (signal_pending(current))
1863 flush_signals(current);
1864
1865 del_timer_sync(&hba->destroy_timer);
1866 }
1867 bnx2fc_unbind_adapter_devices(hba);
1868 }
1869}
1870
1871/**
1872 * bnx2fc_ulp_stop - cnic callback to shutdown adapter instance
1873 *
1874 * @handle: transport handle pointing to adapter structure
1875 *
1876 * Driver checks if adapter is already in shutdown mode, if not start
1877 * the shutdown process.
1878 */
1879static void bnx2fc_ulp_stop(void *handle)
1880{
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001881 struct bnx2fc_hba *hba = handle;
1882 struct bnx2fc_interface *interface;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001883
1884 printk(KERN_ERR "ULP_STOP\n");
1885
1886 mutex_lock(&bnx2fc_dev_lock);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001887 if (!test_bit(BNX2FC_FLAG_FW_INIT_DONE, &hba->flags))
1888 goto exit;
1889 list_for_each_entry(interface, &if_list, list) {
1890 if (interface->hba == hba)
1891 bnx2fc_stop(interface);
1892 }
1893 BUG_ON(hba->num_ofld_sess != 0);
1894
1895 mutex_lock(&hba->hba_mutex);
1896 clear_bit(ADAPTER_STATE_UP, &hba->adapter_state);
1897 clear_bit(ADAPTER_STATE_GOING_DOWN,
1898 &hba->adapter_state);
1899
1900 clear_bit(ADAPTER_STATE_READY, &hba->adapter_state);
1901 mutex_unlock(&hba->hba_mutex);
1902
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001903 bnx2fc_fw_destroy(hba);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001904exit:
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001905 mutex_unlock(&bnx2fc_dev_lock);
1906}
1907
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001908static void bnx2fc_start_disc(struct bnx2fc_interface *interface)
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001909{
Robert Lovefd8f8902012-05-22 19:06:16 -07001910 struct fcoe_ctlr *ctlr = bnx2fc_to_ctlr(interface);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001911 struct fc_lport *lport;
1912 int wait_cnt = 0;
1913
1914 BNX2FC_MISC_DBG("Entered %s\n", __func__);
1915 /* Kick off FIP/FLOGI */
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001916 if (!test_bit(BNX2FC_FLAG_FW_INIT_DONE, &interface->hba->flags)) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001917 printk(KERN_ERR PFX "Init not done yet\n");
1918 return;
1919 }
1920
Robert Lovefd8f8902012-05-22 19:06:16 -07001921 lport = ctlr->lp;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001922 BNX2FC_HBA_DBG(lport, "calling fc_fabric_login\n");
1923
Bhanu Prakash Gollapudi8a5badf2011-08-30 15:54:48 -07001924 if (!bnx2fc_link_ok(lport) && interface->enabled) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001925 BNX2FC_HBA_DBG(lport, "ctlr_link_up\n");
Robert Lovefd8f8902012-05-22 19:06:16 -07001926 fcoe_ctlr_link_up(ctlr);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001927 fc_host_port_type(lport->host) = FC_PORTTYPE_NPORT;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001928 set_bit(ADAPTER_STATE_READY, &interface->hba->adapter_state);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001929 }
1930
1931 /* wait for the FCF to be selected before issuing FLOGI */
Robert Lovefd8f8902012-05-22 19:06:16 -07001932 while (!ctlr->sel_fcf) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001933 msleep(250);
1934 /* give up after 3 secs */
1935 if (++wait_cnt > 12)
1936 break;
1937 }
Bhanu Prakash Gollapudi627e6282011-08-04 17:38:35 -07001938
1939 /* Reset max receive frame size to default */
1940 if (fc_set_mfs(lport, BNX2FC_MFS))
1941 return;
1942
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001943 fc_lport_init(lport);
1944 fc_fabric_login(lport);
1945}
1946
1947
1948/**
1949 * bnx2fc_ulp_init - Initialize an adapter instance
1950 *
1951 * @dev : cnic device handle
1952 * Called from cnic_register_driver() context to initialize all
1953 * enumerated cnic devices. This routine allocates adapter structure
1954 * and other device specific resources.
1955 */
1956static void bnx2fc_ulp_init(struct cnic_dev *dev)
1957{
1958 struct bnx2fc_hba *hba;
1959 int rc = 0;
1960
1961 BNX2FC_MISC_DBG("Entered %s\n", __func__);
1962 /* bnx2fc works only when bnx2x is loaded */
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001963 if (!test_bit(CNIC_F_BNX2X_CLASS, &dev->flags) ||
1964 (dev->max_fcoe_conn == 0)) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001965 printk(KERN_ERR PFX "bnx2fc FCoE not supported on %s,"
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001966 " flags: %lx fcoe_conn: %d\n",
1967 dev->netdev->name, dev->flags, dev->max_fcoe_conn);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001968 return;
1969 }
1970
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001971 hba = bnx2fc_hba_create(dev);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001972 if (!hba) {
1973 printk(KERN_ERR PFX "hba initialization failed\n");
1974 return;
1975 }
1976
1977 /* Add HBA to the adapter list */
1978 mutex_lock(&bnx2fc_dev_lock);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001979 list_add_tail(&hba->list, &adapter_list);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001980 adapter_count++;
1981 mutex_unlock(&bnx2fc_dev_lock);
1982
Barak Witkowski2e499d32012-06-26 01:31:19 +00001983 dev->fcoe_cap = &hba->fcoe_cap;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001984 clear_bit(BNX2FC_CNIC_REGISTERED, &hba->reg_with_cnic);
1985 rc = dev->register_device(dev, CNIC_ULP_FCOE,
1986 (void *) hba);
1987 if (rc)
Bhanu Prakash Gollapudib2a554f2011-06-27 23:30:53 -07001988 printk(KERN_ERR PFX "register_device failed, rc = %d\n", rc);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001989 else
1990 set_bit(BNX2FC_CNIC_REGISTERED, &hba->reg_with_cnic);
1991}
1992
Robert Love6e89ea32012-11-27 06:53:40 +00001993/**
1994 * Deperecated: Use bnx2fc_enabled()
1995 */
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001996static int bnx2fc_disable(struct net_device *netdev)
1997{
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001998 struct bnx2fc_interface *interface;
Robert Lovefd8f8902012-05-22 19:06:16 -07001999 struct fcoe_ctlr *ctlr;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002000 int rc = 0;
2001
Nithin Sujir6702ca12011-03-17 17:13:27 -07002002 rtnl_lock();
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002003 mutex_lock(&bnx2fc_dev_lock);
2004
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002005 interface = bnx2fc_interface_lookup(netdev);
Robert Lovefd8f8902012-05-22 19:06:16 -07002006 ctlr = bnx2fc_to_ctlr(interface);
2007 if (!interface || !ctlr->lp) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002008 rc = -ENODEV;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002009 printk(KERN_ERR PFX "bnx2fc_disable: interface or lport not found\n");
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002010 } else {
Bhanu Prakash Gollapudi8a5badf2011-08-30 15:54:48 -07002011 interface->enabled = false;
Robert Lovefd8f8902012-05-22 19:06:16 -07002012 fcoe_ctlr_link_down(ctlr);
2013 fcoe_clean_pending_queue(ctlr->lp);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002014 }
2015
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002016 mutex_unlock(&bnx2fc_dev_lock);
2017 rtnl_unlock();
2018 return rc;
2019}
2020
Robert Love6e89ea32012-11-27 06:53:40 +00002021/**
2022 * Deprecated: Use bnx2fc_enabled()
2023 */
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002024static int bnx2fc_enable(struct net_device *netdev)
2025{
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002026 struct bnx2fc_interface *interface;
Robert Lovefd8f8902012-05-22 19:06:16 -07002027 struct fcoe_ctlr *ctlr;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002028 int rc = 0;
2029
Nithin Sujir6702ca12011-03-17 17:13:27 -07002030 rtnl_lock();
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002031 mutex_lock(&bnx2fc_dev_lock);
2032
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002033 interface = bnx2fc_interface_lookup(netdev);
Robert Lovefd8f8902012-05-22 19:06:16 -07002034 ctlr = bnx2fc_to_ctlr(interface);
2035 if (!interface || !ctlr->lp) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002036 rc = -ENODEV;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002037 printk(KERN_ERR PFX "bnx2fc_enable: interface or lport not found\n");
Robert Lovefd8f8902012-05-22 19:06:16 -07002038 } else if (!bnx2fc_link_ok(ctlr->lp)) {
2039 fcoe_ctlr_link_up(ctlr);
Bhanu Prakash Gollapudi8a5badf2011-08-30 15:54:48 -07002040 interface->enabled = true;
2041 }
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002042
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002043 mutex_unlock(&bnx2fc_dev_lock);
2044 rtnl_unlock();
2045 return rc;
2046}
2047
2048/**
Robert Love6e89ea32012-11-27 06:53:40 +00002049 * bnx2fc_ctlr_enabled() - Enable or disable an FCoE Controller
2050 * @cdev: The FCoE Controller that is being enabled or disabled
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002051 *
Robert Love6e89ea32012-11-27 06:53:40 +00002052 * fcoe_sysfs will ensure that the state of 'enabled' has
2053 * changed, so no checking is necessary here. This routine simply
2054 * calls fcoe_enable or fcoe_disable, both of which are deprecated.
2055 * When those routines are removed the functionality can be merged
2056 * here.
2057 */
2058static int bnx2fc_ctlr_enabled(struct fcoe_ctlr_device *cdev)
2059{
2060 struct fcoe_ctlr *ctlr = fcoe_ctlr_device_priv(cdev);
2061 struct fc_lport *lport = ctlr->lp;
2062 struct net_device *netdev = bnx2fc_netdev(lport);
2063
2064 switch (cdev->enabled) {
2065 case FCOE_CTLR_ENABLED:
2066 return bnx2fc_enable(netdev);
2067 case FCOE_CTLR_DISABLED:
2068 return bnx2fc_disable(netdev);
2069 case FCOE_CTLR_UNUSED:
2070 default:
2071 return -ENOTSUPP;
2072 };
2073}
2074
2075enum bnx2fc_create_link_state {
2076 BNX2FC_CREATE_LINK_DOWN,
2077 BNX2FC_CREATE_LINK_UP,
2078};
2079
2080/**
2081 * _bnx2fc_create() - Create bnx2fc FCoE interface
2082 * @netdev : The net_device object the Ethernet interface to create on
2083 * @fip_mode: The FIP mode for this creation
2084 * @link_state: The ctlr link state on creation
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002085 *
Robert Love6e89ea32012-11-27 06:53:40 +00002086 * Called from either the libfcoe 'create' module parameter
2087 * via fcoe_create or from fcoe_syfs's ctlr_create file.
2088 *
2089 * libfcoe's 'create' module parameter is deprecated so some
2090 * consolidation of code can be done when that interface is
2091 * removed.
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002092 *
2093 * Returns: 0 for success
2094 */
Robert Love6e89ea32012-11-27 06:53:40 +00002095static int _bnx2fc_create(struct net_device *netdev,
2096 enum fip_state fip_mode,
2097 enum bnx2fc_create_link_state link_state)
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002098{
Robert Love6e89ea32012-11-27 06:53:40 +00002099 struct fcoe_ctlr_device *cdev;
Robert Lovefd8f8902012-05-22 19:06:16 -07002100 struct fcoe_ctlr *ctlr;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002101 struct bnx2fc_interface *interface;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002102 struct bnx2fc_hba *hba;
Bhanu Prakash Gollapudi7adc5a32012-06-04 16:15:44 -07002103 struct net_device *phys_dev = netdev;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002104 struct fc_lport *lport;
2105 struct ethtool_drvinfo drvinfo;
2106 int rc = 0;
Bhanu Prakash Gollapudi7adc5a32012-06-04 16:15:44 -07002107 int vlan_id = 0;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002108
2109 BNX2FC_MISC_DBG("Entered bnx2fc_create\n");
2110 if (fip_mode != FIP_MODE_FABRIC) {
2111 printk(KERN_ERR "fip mode not FABRIC\n");
2112 return -EIO;
2113 }
2114
Nithin Sujir6702ca12011-03-17 17:13:27 -07002115 rtnl_lock();
2116
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002117 mutex_lock(&bnx2fc_dev_lock);
2118
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002119 if (!try_module_get(THIS_MODULE)) {
2120 rc = -EINVAL;
2121 goto mod_err;
2122 }
2123
2124 /* obtain physical netdev */
Bhanu Prakash Gollapudi7adc5a32012-06-04 16:15:44 -07002125 if (netdev->priv_flags & IFF_802_1Q_VLAN)
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002126 phys_dev = vlan_dev_real_dev(netdev);
Bhanu Prakash Gollapudi7adc5a32012-06-04 16:15:44 -07002127
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002128 /* verify if the physical device is a netxtreme2 device */
2129 if (phys_dev->ethtool_ops && phys_dev->ethtool_ops->get_drvinfo) {
2130 memset(&drvinfo, 0, sizeof(drvinfo));
2131 phys_dev->ethtool_ops->get_drvinfo(phys_dev, &drvinfo);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002132 if (strncmp(drvinfo.driver, "bnx2x", strlen("bnx2x"))) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002133 printk(KERN_ERR PFX "Not a netxtreme2 device\n");
2134 rc = -EINVAL;
2135 goto netdev_err;
2136 }
2137 } else {
2138 printk(KERN_ERR PFX "unable to obtain drv_info\n");
2139 rc = -EINVAL;
2140 goto netdev_err;
2141 }
2142
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002143 /* obtain interface and initialize rest of the structure */
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002144 hba = bnx2fc_hba_lookup(phys_dev);
2145 if (!hba) {
2146 rc = -ENODEV;
2147 printk(KERN_ERR PFX "bnx2fc_create: hba not found\n");
2148 goto netdev_err;
2149 }
2150
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002151 if (bnx2fc_interface_lookup(netdev)) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002152 rc = -EEXIST;
2153 goto netdev_err;
2154 }
2155
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002156 interface = bnx2fc_interface_create(hba, netdev, fip_mode);
2157 if (!interface) {
2158 printk(KERN_ERR PFX "bnx2fc_interface_create failed\n");
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002159 goto ifput_err;
2160 }
2161
Bhanu Prakash Gollapudi7adc5a32012-06-04 16:15:44 -07002162 if (netdev->priv_flags & IFF_802_1Q_VLAN) {
2163 vlan_id = vlan_dev_vlan_id(netdev);
2164 interface->vlan_enabled = 1;
2165 }
2166
Robert Lovefd8f8902012-05-22 19:06:16 -07002167 ctlr = bnx2fc_to_ctlr(interface);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002168 interface->vlan_id = vlan_id;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002169
2170 interface->timer_work_queue =
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002171 create_singlethread_workqueue("bnx2fc_timer_wq");
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002172 if (!interface->timer_work_queue) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002173 printk(KERN_ERR PFX "ulp_init could not create timer_wq\n");
2174 rc = -EINVAL;
2175 goto ifput_err;
2176 }
2177
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002178 lport = bnx2fc_if_create(interface, &interface->hba->pcidev->dev, 0);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002179 if (!lport) {
2180 printk(KERN_ERR PFX "Failed to create interface (%s)\n",
2181 netdev->name);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002182 rc = -EINVAL;
2183 goto if_create_err;
2184 }
2185
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002186 /* Add interface to if_list */
2187 list_add_tail(&interface->list, &if_list);
2188
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002189 lport->boot_time = jiffies;
2190
2191 /* Make this master N_port */
Robert Lovefd8f8902012-05-22 19:06:16 -07002192 ctlr->lp = lport;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002193
Robert Love6e89ea32012-11-27 06:53:40 +00002194 cdev = fcoe_ctlr_to_ctlr_dev(ctlr);
2195
2196 if (link_state == BNX2FC_CREATE_LINK_UP)
2197 cdev->enabled = FCOE_CTLR_ENABLED;
2198 else
2199 cdev->enabled = FCOE_CTLR_DISABLED;
2200
2201 if (link_state == BNX2FC_CREATE_LINK_UP &&
2202 !bnx2fc_link_ok(lport)) {
Robert Lovefd8f8902012-05-22 19:06:16 -07002203 fcoe_ctlr_link_up(ctlr);
Bhanu Prakash Gollapudi8a5badf2011-08-30 15:54:48 -07002204 fc_host_port_type(lport->host) = FC_PORTTYPE_NPORT;
2205 set_bit(ADAPTER_STATE_READY, &interface->hba->adapter_state);
2206 }
2207
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002208 BNX2FC_HBA_DBG(lport, "create: START DISC\n");
2209 bnx2fc_start_disc(interface);
Robert Love6e89ea32012-11-27 06:53:40 +00002210
2211 if (link_state == BNX2FC_CREATE_LINK_UP)
2212 interface->enabled = true;
2213
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002214 /*
2215 * Release from kref_init in bnx2fc_interface_setup, on success
2216 * lport should be holding a reference taken in bnx2fc_if_create
2217 */
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002218 bnx2fc_interface_put(interface);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002219 /* put netdev that was held while calling dev_get_by_name */
2220 mutex_unlock(&bnx2fc_dev_lock);
2221 rtnl_unlock();
2222 return 0;
2223
2224if_create_err:
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002225 destroy_workqueue(interface->timer_work_queue);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002226ifput_err:
Bhanu Prakash Gollapudi013068f2011-08-30 15:54:52 -07002227 bnx2fc_net_cleanup(interface);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002228 bnx2fc_interface_put(interface);
Bhanu Prakash Gollapudi7d742f62012-01-23 18:00:48 -08002229 goto mod_err;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002230netdev_err:
2231 module_put(THIS_MODULE);
2232mod_err:
2233 mutex_unlock(&bnx2fc_dev_lock);
2234 rtnl_unlock();
2235 return rc;
2236}
2237
2238/**
Robert Love6e89ea32012-11-27 06:53:40 +00002239 * bnx2fc_create() - Create a bnx2fc interface
2240 * @netdev : The net_device object the Ethernet interface to create on
2241 * @fip_mode: The FIP mode for this creation
2242 *
2243 * Called from fcoe transport
2244 *
2245 * Returns: 0 for success
2246 */
2247static int bnx2fc_create(struct net_device *netdev, enum fip_state fip_mode)
2248{
2249 return _bnx2fc_create(netdev, fip_mode, BNX2FC_CREATE_LINK_UP);
2250}
2251
2252/**
2253 * bnx2fc_ctlr_alloc() - Allocate a bnx2fc interface from fcoe_sysfs
2254 * @netdev: The net_device to be used by the allocated FCoE Controller
2255 *
2256 * This routine is called from fcoe_sysfs. It will start the fcoe_ctlr
2257 * in a link_down state. The allows the user an opportunity to configure
2258 * the FCoE Controller from sysfs before enabling the FCoE Controller.
2259 *
2260 * Creating in with this routine starts the FCoE Controller in Fabric
2261 * mode. The user can change to VN2VN or another mode before enabling.
2262 */
2263static int bnx2fc_ctlr_alloc(struct net_device *netdev)
2264{
2265 return _bnx2fc_create(netdev, FIP_MODE_FABRIC,
2266 BNX2FC_CREATE_LINK_DOWN);
2267}
2268
2269/**
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002270 * bnx2fc_find_hba_for_cnic - maps cnic instance to bnx2fc hba instance
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002271 *
2272 * @cnic: Pointer to cnic device instance
2273 *
2274 **/
2275static struct bnx2fc_hba *bnx2fc_find_hba_for_cnic(struct cnic_dev *cnic)
2276{
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002277 struct bnx2fc_hba *hba;
2278
2279 /* Called with bnx2fc_dev_lock held */
Bhanu Prakash Gollapudid71fb3b2012-06-07 02:19:36 -07002280 list_for_each_entry(hba, &adapter_list, list) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002281 if (hba->cnic == cnic)
2282 return hba;
2283 }
2284 return NULL;
2285}
2286
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002287static struct bnx2fc_interface *bnx2fc_interface_lookup(struct net_device
2288 *netdev)
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002289{
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002290 struct bnx2fc_interface *interface;
2291
2292 /* Called with bnx2fc_dev_lock held */
2293 list_for_each_entry(interface, &if_list, list) {
2294 if (interface->netdev == netdev)
2295 return interface;
2296 }
2297 return NULL;
2298}
2299
2300static struct bnx2fc_hba *bnx2fc_hba_lookup(struct net_device
2301 *phys_dev)
2302{
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002303 struct bnx2fc_hba *hba;
2304
2305 /* Called with bnx2fc_dev_lock held */
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002306 list_for_each_entry(hba, &adapter_list, list) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002307 if (hba->phys_dev == phys_dev)
2308 return hba;
2309 }
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002310 printk(KERN_ERR PFX "adapter_lookup: hba NULL\n");
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002311 return NULL;
2312}
2313
2314/**
2315 * bnx2fc_ulp_exit - shuts down adapter instance and frees all resources
2316 *
2317 * @dev cnic device handle
2318 */
2319static void bnx2fc_ulp_exit(struct cnic_dev *dev)
2320{
2321 struct bnx2fc_hba *hba;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002322 struct bnx2fc_interface *interface, *tmp;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002323
2324 BNX2FC_MISC_DBG("Entered bnx2fc_ulp_exit\n");
2325
2326 if (!test_bit(CNIC_F_BNX2X_CLASS, &dev->flags)) {
2327 printk(KERN_ERR PFX "bnx2fc port check: %s, flags: %lx\n",
2328 dev->netdev->name, dev->flags);
2329 return;
2330 }
2331
2332 mutex_lock(&bnx2fc_dev_lock);
2333 hba = bnx2fc_find_hba_for_cnic(dev);
2334 if (!hba) {
2335 printk(KERN_ERR PFX "bnx2fc_ulp_exit: hba not found, dev 0%p\n",
2336 dev);
2337 mutex_unlock(&bnx2fc_dev_lock);
2338 return;
2339 }
2340
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002341 list_del_init(&hba->list);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002342 adapter_count--;
2343
Bhanu Prakash Gollapudiabc49a92011-08-04 17:38:42 -07002344 list_for_each_entry_safe(interface, tmp, &if_list, list)
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002345 /* destroy not called yet, move to quiesced list */
Bhanu Prakash Gollapudiabc49a92011-08-04 17:38:42 -07002346 if (interface->hba == hba)
Bhanu Prakash Gollapudieccdcd02011-08-24 18:56:42 -07002347 __bnx2fc_destroy(interface);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002348 mutex_unlock(&bnx2fc_dev_lock);
2349
2350 bnx2fc_ulp_stop(hba);
2351 /* unregister cnic device */
2352 if (test_and_clear_bit(BNX2FC_CNIC_REGISTERED, &hba->reg_with_cnic))
2353 hba->cnic->unregister_device(hba->cnic, CNIC_ULP_FCOE);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002354 bnx2fc_hba_destroy(hba);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002355}
2356
2357/**
2358 * bnx2fc_fcoe_reset - Resets the fcoe
2359 *
2360 * @shost: shost the reset is from
2361 *
2362 * Returns: always 0
2363 */
2364static int bnx2fc_fcoe_reset(struct Scsi_Host *shost)
2365{
2366 struct fc_lport *lport = shost_priv(shost);
2367 fc_lport_reset(lport);
2368 return 0;
2369}
2370
2371
2372static bool bnx2fc_match(struct net_device *netdev)
2373{
Bhanu Prakash Gollapudi7adc5a32012-06-04 16:15:44 -07002374 struct net_device *phys_dev = netdev;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002375
Bhanu Prakash Gollapudi7adc5a32012-06-04 16:15:44 -07002376 mutex_lock(&bnx2fc_dev_lock);
2377 if (netdev->priv_flags & IFF_802_1Q_VLAN)
2378 phys_dev = vlan_dev_real_dev(netdev);
2379
2380 if (bnx2fc_hba_lookup(phys_dev)) {
2381 mutex_unlock(&bnx2fc_dev_lock);
2382 return true;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002383 }
Bhanu Prakash Gollapudi7adc5a32012-06-04 16:15:44 -07002384
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002385 mutex_unlock(&bnx2fc_dev_lock);
2386 return false;
2387}
2388
2389
2390static struct fcoe_transport bnx2fc_transport = {
2391 .name = {"bnx2fc"},
2392 .attached = false,
2393 .list = LIST_HEAD_INIT(bnx2fc_transport.list),
Robert Love6e89ea32012-11-27 06:53:40 +00002394 .alloc = bnx2fc_ctlr_alloc,
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002395 .match = bnx2fc_match,
2396 .create = bnx2fc_create,
2397 .destroy = bnx2fc_destroy,
2398 .enable = bnx2fc_enable,
2399 .disable = bnx2fc_disable,
2400};
2401
2402/**
2403 * bnx2fc_percpu_thread_create - Create a receive thread for an
2404 * online CPU
2405 *
2406 * @cpu: cpu index for the online cpu
2407 */
2408static void bnx2fc_percpu_thread_create(unsigned int cpu)
2409{
2410 struct bnx2fc_percpu_s *p;
2411 struct task_struct *thread;
2412
2413 p = &per_cpu(bnx2fc_percpu, cpu);
2414
Eric Dumazet69614272012-06-04 16:15:42 -07002415 thread = kthread_create_on_node(bnx2fc_percpu_io_thread,
2416 (void *)p, cpu_to_node(cpu),
2417 "bnx2fc_thread/%d", cpu);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002418 /* bind thread to the cpu */
Bhanu Prakash Gollapudi32248762011-08-04 17:38:36 -07002419 if (likely(!IS_ERR(thread))) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002420 kthread_bind(thread, cpu);
2421 p->iothread = thread;
2422 wake_up_process(thread);
2423 }
2424}
2425
2426static void bnx2fc_percpu_thread_destroy(unsigned int cpu)
2427{
2428 struct bnx2fc_percpu_s *p;
2429 struct task_struct *thread;
2430 struct bnx2fc_work *work, *tmp;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002431
2432 BNX2FC_MISC_DBG("destroying io thread for CPU %d\n", cpu);
2433
2434 /* Prevent any new work from being queued for this CPU */
2435 p = &per_cpu(bnx2fc_percpu, cpu);
2436 spin_lock_bh(&p->fp_work_lock);
2437 thread = p->iothread;
2438 p->iothread = NULL;
2439
2440
2441 /* Free all work in the list */
Bhanu Prakash Gollapudi32248762011-08-04 17:38:36 -07002442 list_for_each_entry_safe(work, tmp, &p->work_list, list) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002443 list_del_init(&work->list);
2444 bnx2fc_process_cq_compl(work->tgt, work->wqe);
2445 kfree(work);
2446 }
2447
2448 spin_unlock_bh(&p->fp_work_lock);
2449
2450 if (thread)
2451 kthread_stop(thread);
2452}
2453
2454/**
2455 * bnx2fc_cpu_callback - Handler for CPU hotplug events
2456 *
2457 * @nfb: The callback data block
2458 * @action: The event triggering the callback
2459 * @hcpu: The index of the CPU that the event is for
2460 *
2461 * This creates or destroys per-CPU data for fcoe
2462 *
2463 * Returns NOTIFY_OK always.
2464 */
2465static int bnx2fc_cpu_callback(struct notifier_block *nfb,
2466 unsigned long action, void *hcpu)
2467{
2468 unsigned cpu = (unsigned long)hcpu;
2469
2470 switch (action) {
2471 case CPU_ONLINE:
2472 case CPU_ONLINE_FROZEN:
2473 printk(PFX "CPU %x online: Create Rx thread\n", cpu);
2474 bnx2fc_percpu_thread_create(cpu);
2475 break;
2476 case CPU_DEAD:
2477 case CPU_DEAD_FROZEN:
2478 printk(PFX "CPU %x offline: Remove Rx thread\n", cpu);
2479 bnx2fc_percpu_thread_destroy(cpu);
2480 break;
2481 default:
2482 break;
2483 }
2484 return NOTIFY_OK;
2485}
2486
2487/**
2488 * bnx2fc_mod_init - module init entry point
2489 *
2490 * Initialize driver wide global data structures, and register
2491 * with cnic module
2492 **/
2493static int __init bnx2fc_mod_init(void)
2494{
2495 struct fcoe_percpu_s *bg;
2496 struct task_struct *l2_thread;
2497 int rc = 0;
2498 unsigned int cpu = 0;
2499 struct bnx2fc_percpu_s *p;
2500
2501 printk(KERN_INFO PFX "%s", version);
2502
2503 /* register as a fcoe transport */
2504 rc = fcoe_transport_attach(&bnx2fc_transport);
2505 if (rc) {
2506 printk(KERN_ERR "failed to register an fcoe transport, check "
2507 "if libfcoe is loaded\n");
2508 goto out;
2509 }
2510
2511 INIT_LIST_HEAD(&adapter_list);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002512 INIT_LIST_HEAD(&if_list);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002513 mutex_init(&bnx2fc_dev_lock);
2514 adapter_count = 0;
2515
2516 /* Attach FC transport template */
2517 rc = bnx2fc_attach_transport();
2518 if (rc)
2519 goto detach_ft;
2520
2521 bnx2fc_wq = alloc_workqueue("bnx2fc", 0, 0);
2522 if (!bnx2fc_wq) {
2523 rc = -ENOMEM;
2524 goto release_bt;
2525 }
2526
2527 bg = &bnx2fc_global;
2528 skb_queue_head_init(&bg->fcoe_rx_list);
2529 l2_thread = kthread_create(bnx2fc_l2_rcv_thread,
2530 (void *)bg,
2531 "bnx2fc_l2_thread");
2532 if (IS_ERR(l2_thread)) {
2533 rc = PTR_ERR(l2_thread);
2534 goto free_wq;
2535 }
2536 wake_up_process(l2_thread);
2537 spin_lock_bh(&bg->fcoe_rx_list.lock);
2538 bg->thread = l2_thread;
2539 spin_unlock_bh(&bg->fcoe_rx_list.lock);
2540
2541 for_each_possible_cpu(cpu) {
2542 p = &per_cpu(bnx2fc_percpu, cpu);
2543 INIT_LIST_HEAD(&p->work_list);
2544 spin_lock_init(&p->fp_work_lock);
2545 }
2546
2547 for_each_online_cpu(cpu) {
2548 bnx2fc_percpu_thread_create(cpu);
2549 }
2550
2551 /* Initialize per CPU interrupt thread */
2552 register_hotcpu_notifier(&bnx2fc_cpu_notifier);
2553
2554 cnic_register_driver(CNIC_ULP_FCOE, &bnx2fc_cnic_cb);
2555
2556 return 0;
2557
2558free_wq:
2559 destroy_workqueue(bnx2fc_wq);
2560release_bt:
2561 bnx2fc_release_transport();
2562detach_ft:
2563 fcoe_transport_detach(&bnx2fc_transport);
2564out:
2565 return rc;
2566}
2567
2568static void __exit bnx2fc_mod_exit(void)
2569{
2570 LIST_HEAD(to_be_deleted);
2571 struct bnx2fc_hba *hba, *next;
2572 struct fcoe_percpu_s *bg;
2573 struct task_struct *l2_thread;
2574 struct sk_buff *skb;
2575 unsigned int cpu = 0;
2576
2577 /*
2578 * NOTE: Since cnic calls register_driver routine rtnl_lock,
2579 * it will have higher precedence than bnx2fc_dev_lock.
2580 * unregister_device() cannot be called with bnx2fc_dev_lock
2581 * held.
2582 */
2583 mutex_lock(&bnx2fc_dev_lock);
2584 list_splice(&adapter_list, &to_be_deleted);
2585 INIT_LIST_HEAD(&adapter_list);
2586 adapter_count = 0;
2587 mutex_unlock(&bnx2fc_dev_lock);
2588
2589 /* Unregister with cnic */
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002590 list_for_each_entry_safe(hba, next, &to_be_deleted, list) {
2591 list_del_init(&hba->list);
2592 printk(KERN_ERR PFX "MOD_EXIT:destroy hba = 0x%p\n",
2593 hba);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002594 bnx2fc_ulp_stop(hba);
2595 /* unregister cnic device */
2596 if (test_and_clear_bit(BNX2FC_CNIC_REGISTERED,
2597 &hba->reg_with_cnic))
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002598 hba->cnic->unregister_device(hba->cnic,
2599 CNIC_ULP_FCOE);
2600 bnx2fc_hba_destroy(hba);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002601 }
2602 cnic_unregister_driver(CNIC_ULP_FCOE);
2603
2604 /* Destroy global thread */
2605 bg = &bnx2fc_global;
2606 spin_lock_bh(&bg->fcoe_rx_list.lock);
2607 l2_thread = bg->thread;
2608 bg->thread = NULL;
2609 while ((skb = __skb_dequeue(&bg->fcoe_rx_list)) != NULL)
2610 kfree_skb(skb);
2611
2612 spin_unlock_bh(&bg->fcoe_rx_list.lock);
2613
2614 if (l2_thread)
2615 kthread_stop(l2_thread);
2616
2617 unregister_hotcpu_notifier(&bnx2fc_cpu_notifier);
2618
2619 /* Destroy per cpu threads */
2620 for_each_online_cpu(cpu) {
2621 bnx2fc_percpu_thread_destroy(cpu);
2622 }
2623
2624 destroy_workqueue(bnx2fc_wq);
2625 /*
2626 * detach from scsi transport
2627 * must happen after all destroys are done
2628 */
2629 bnx2fc_release_transport();
2630
2631 /* detach from fcoe transport */
2632 fcoe_transport_detach(&bnx2fc_transport);
2633}
2634
2635module_init(bnx2fc_mod_init);
2636module_exit(bnx2fc_mod_exit);
2637
Robert Love8d55e502012-05-22 19:06:26 -07002638static struct fcoe_sysfs_function_template bnx2fc_fcoe_sysfs_templ = {
Robert Love6e89ea32012-11-27 06:53:40 +00002639 .set_fcoe_ctlr_enabled = bnx2fc_ctlr_enabled,
Robert Love8d55e502012-05-22 19:06:26 -07002640 .get_fcoe_ctlr_link_fail = bnx2fc_ctlr_get_lesb,
2641 .get_fcoe_ctlr_vlink_fail = bnx2fc_ctlr_get_lesb,
2642 .get_fcoe_ctlr_miss_fka = bnx2fc_ctlr_get_lesb,
2643 .get_fcoe_ctlr_symb_err = bnx2fc_ctlr_get_lesb,
2644 .get_fcoe_ctlr_err_block = bnx2fc_ctlr_get_lesb,
2645 .get_fcoe_ctlr_fcs_error = bnx2fc_ctlr_get_lesb,
2646
2647 .get_fcoe_fcf_selected = fcoe_fcf_get_selected,
2648 .get_fcoe_fcf_vlan_id = bnx2fc_fcf_get_vlan_id,
2649};
2650
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002651static struct fc_function_template bnx2fc_transport_function = {
2652 .show_host_node_name = 1,
2653 .show_host_port_name = 1,
2654 .show_host_supported_classes = 1,
2655 .show_host_supported_fc4s = 1,
2656 .show_host_active_fc4s = 1,
2657 .show_host_maxframe_size = 1,
2658
2659 .show_host_port_id = 1,
2660 .show_host_supported_speeds = 1,
2661 .get_host_speed = fc_get_host_speed,
2662 .show_host_speed = 1,
2663 .show_host_port_type = 1,
2664 .get_host_port_state = fc_get_host_port_state,
2665 .show_host_port_state = 1,
2666 .show_host_symbolic_name = 1,
2667
2668 .dd_fcrport_size = (sizeof(struct fc_rport_libfc_priv) +
2669 sizeof(struct bnx2fc_rport)),
2670 .show_rport_maxframe_size = 1,
2671 .show_rport_supported_classes = 1,
2672
2673 .show_host_fabric_name = 1,
2674 .show_starget_node_name = 1,
2675 .show_starget_port_name = 1,
2676 .show_starget_port_id = 1,
2677 .set_rport_dev_loss_tmo = fc_set_rport_loss_tmo,
2678 .show_rport_dev_loss_tmo = 1,
2679 .get_fc_host_stats = bnx2fc_get_host_stats,
2680
2681 .issue_fc_host_lip = bnx2fc_fcoe_reset,
2682
2683 .terminate_rport_io = fc_rport_terminate_io,
2684
2685 .vport_create = bnx2fc_vport_create,
2686 .vport_delete = bnx2fc_vport_destroy,
2687 .vport_disable = bnx2fc_vport_disable,
Bhanu Prakash Gollapudie9a5289c2011-08-04 17:38:37 -07002688 .bsg_request = fc_lport_bsg_request,
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002689};
2690
2691static struct fc_function_template bnx2fc_vport_xport_function = {
2692 .show_host_node_name = 1,
2693 .show_host_port_name = 1,
2694 .show_host_supported_classes = 1,
2695 .show_host_supported_fc4s = 1,
2696 .show_host_active_fc4s = 1,
2697 .show_host_maxframe_size = 1,
2698
2699 .show_host_port_id = 1,
2700 .show_host_supported_speeds = 1,
2701 .get_host_speed = fc_get_host_speed,
2702 .show_host_speed = 1,
2703 .show_host_port_type = 1,
2704 .get_host_port_state = fc_get_host_port_state,
2705 .show_host_port_state = 1,
2706 .show_host_symbolic_name = 1,
2707
2708 .dd_fcrport_size = (sizeof(struct fc_rport_libfc_priv) +
2709 sizeof(struct bnx2fc_rport)),
2710 .show_rport_maxframe_size = 1,
2711 .show_rport_supported_classes = 1,
2712
2713 .show_host_fabric_name = 1,
2714 .show_starget_node_name = 1,
2715 .show_starget_port_name = 1,
2716 .show_starget_port_id = 1,
2717 .set_rport_dev_loss_tmo = fc_set_rport_loss_tmo,
2718 .show_rport_dev_loss_tmo = 1,
2719 .get_fc_host_stats = fc_get_host_stats,
2720 .issue_fc_host_lip = bnx2fc_fcoe_reset,
2721 .terminate_rport_io = fc_rport_terminate_io,
Bhanu Prakash Gollapudie9a5289c2011-08-04 17:38:37 -07002722 .bsg_request = fc_lport_bsg_request,
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002723};
2724
2725/**
2726 * scsi_host_template structure used while registering with SCSI-ml
2727 */
2728static struct scsi_host_template bnx2fc_shost_template = {
2729 .module = THIS_MODULE,
2730 .name = "Broadcom Offload FCoE Initiator",
2731 .queuecommand = bnx2fc_queuecommand,
2732 .eh_abort_handler = bnx2fc_eh_abort, /* abts */
2733 .eh_device_reset_handler = bnx2fc_eh_device_reset, /* lun reset */
2734 .eh_target_reset_handler = bnx2fc_eh_target_reset, /* tgt reset */
2735 .eh_host_reset_handler = fc_eh_host_reset,
2736 .slave_alloc = fc_slave_alloc,
2737 .change_queue_depth = fc_change_queue_depth,
2738 .change_queue_type = fc_change_queue_type,
2739 .this_id = -1,
2740 .cmd_per_lun = 3,
Bhanu Gollapudi0ea5c272011-03-17 17:13:29 -07002741 .can_queue = BNX2FC_CAN_QUEUE,
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002742 .use_clustering = ENABLE_CLUSTERING,
2743 .sg_tablesize = BNX2FC_MAX_BDS_PER_CMD,
2744 .max_sectors = 512,
2745};
2746
2747static struct libfc_function_template bnx2fc_libfc_fcn_templ = {
2748 .frame_send = bnx2fc_xmit,
2749 .elsct_send = bnx2fc_elsct_send,
2750 .fcp_abort_io = bnx2fc_abort_io,
2751 .fcp_cleanup = bnx2fc_cleanup,
Bhanu Prakash Gollapudif72f6972011-10-03 16:45:02 -07002752 .get_lesb = bnx2fc_get_lesb,
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002753 .rport_event_callback = bnx2fc_rport_event_handler,
2754};
2755
2756/**
2757 * bnx2fc_cnic_cb - global template of bnx2fc - cnic driver interface
2758 * structure carrying callback function pointers
2759 */
2760static struct cnic_ulp_ops bnx2fc_cnic_cb = {
2761 .owner = THIS_MODULE,
2762 .cnic_init = bnx2fc_ulp_init,
2763 .cnic_exit = bnx2fc_ulp_exit,
2764 .cnic_start = bnx2fc_ulp_start,
2765 .cnic_stop = bnx2fc_ulp_stop,
2766 .indicate_kcqes = bnx2fc_indicate_kcqe,
2767 .indicate_netevent = bnx2fc_indicate_netevent,
Barak Witkowski2e499d32012-06-26 01:31:19 +00002768 .cnic_get_stats = bnx2fc_ulp_get_stats,
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002769};