blob: e0558656c6462ed30b3ef1b67816b128f4a4f584 [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
65static void bnx2fc_recv_frame(struct sk_buff *skb);
66
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -070067static void bnx2fc_start_disc(struct bnx2fc_interface *interface);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -080068static int bnx2fc_shost_config(struct fc_lport *lport, struct device *dev);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -080069static int bnx2fc_lport_config(struct fc_lport *lport);
70static int bnx2fc_em_config(struct fc_lport *lport);
71static int bnx2fc_bind_adapter_devices(struct bnx2fc_hba *hba);
72static void bnx2fc_unbind_adapter_devices(struct bnx2fc_hba *hba);
73static int bnx2fc_bind_pcidev(struct bnx2fc_hba *hba);
74static void bnx2fc_unbind_pcidev(struct bnx2fc_hba *hba);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -070075static struct fc_lport *bnx2fc_if_create(struct bnx2fc_interface *interface,
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -080076 struct device *parent, int npiv);
77static void bnx2fc_destroy_work(struct work_struct *work);
78
79static struct bnx2fc_hba *bnx2fc_hba_lookup(struct net_device *phys_dev);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -070080static struct bnx2fc_interface *bnx2fc_interface_lookup(struct net_device
81 *phys_dev);
Bhanu Prakash Gollapudiabc49a92011-08-04 17:38:42 -070082static inline void bnx2fc_interface_put(struct bnx2fc_interface *interface);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -080083static struct bnx2fc_hba *bnx2fc_find_hba_for_cnic(struct cnic_dev *cnic);
84
85static int bnx2fc_fw_init(struct bnx2fc_hba *hba);
86static void bnx2fc_fw_destroy(struct bnx2fc_hba *hba);
87
88static void bnx2fc_port_shutdown(struct fc_lport *lport);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -070089static void bnx2fc_stop(struct bnx2fc_interface *interface);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -080090static int __init bnx2fc_mod_init(void);
91static void __exit bnx2fc_mod_exit(void);
Robert Love8d55e502012-05-22 19:06:26 -070092static void bnx2fc_ctlr_get_lesb(struct fcoe_ctlr_device *ctlr_dev);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -080093
94unsigned int bnx2fc_debug_level;
95module_param_named(debug_logging, bnx2fc_debug_level, int, S_IRUGO|S_IWUSR);
96
97static int bnx2fc_cpu_callback(struct notifier_block *nfb,
98 unsigned long action, void *hcpu);
99/* notification function for CPU hotplug events */
100static struct notifier_block bnx2fc_cpu_notifier = {
101 .notifier_call = bnx2fc_cpu_callback,
102};
103
Bhanu Prakash Gollapudif72f6972011-10-03 16:45:02 -0700104static inline struct net_device *bnx2fc_netdev(const struct fc_lport *lport)
105{
106 return ((struct bnx2fc_interface *)
107 ((struct fcoe_port *)lport_priv(lport))->priv)->netdev;
108}
109
110/**
111 * bnx2fc_get_lesb() - Fill the FCoE Link Error Status Block
112 * @lport: the local port
113 * @fc_lesb: the link error status block
114 */
115static void bnx2fc_get_lesb(struct fc_lport *lport,
116 struct fc_els_lesb *fc_lesb)
117{
118 struct net_device *netdev = bnx2fc_netdev(lport);
119
120 __fcoe_get_lesb(lport, fc_lesb, netdev);
121}
122
Robert Love8d55e502012-05-22 19:06:26 -0700123static void bnx2fc_ctlr_get_lesb(struct fcoe_ctlr_device *ctlr_dev)
124{
125 struct fcoe_ctlr *fip = fcoe_ctlr_device_priv(ctlr_dev);
126 struct net_device *netdev = bnx2fc_netdev(fip->lp);
127 struct fcoe_fc_els_lesb *fcoe_lesb;
128 struct fc_els_lesb fc_lesb;
129
130 __fcoe_get_lesb(fip->lp, &fc_lesb, netdev);
131 fcoe_lesb = (struct fcoe_fc_els_lesb *)(&fc_lesb);
132
133 ctlr_dev->lesb.lesb_link_fail =
134 ntohl(fcoe_lesb->lesb_link_fail);
135 ctlr_dev->lesb.lesb_vlink_fail =
136 ntohl(fcoe_lesb->lesb_vlink_fail);
137 ctlr_dev->lesb.lesb_miss_fka =
138 ntohl(fcoe_lesb->lesb_miss_fka);
139 ctlr_dev->lesb.lesb_symb_err =
140 ntohl(fcoe_lesb->lesb_symb_err);
141 ctlr_dev->lesb.lesb_err_block =
142 ntohl(fcoe_lesb->lesb_err_block);
143 ctlr_dev->lesb.lesb_fcs_error =
144 ntohl(fcoe_lesb->lesb_fcs_error);
145}
146EXPORT_SYMBOL(bnx2fc_ctlr_get_lesb);
147
148static void bnx2fc_fcf_get_vlan_id(struct fcoe_fcf_device *fcf_dev)
149{
150 struct fcoe_ctlr_device *ctlr_dev =
151 fcoe_fcf_dev_to_ctlr_dev(fcf_dev);
152 struct fcoe_ctlr *ctlr = fcoe_ctlr_device_priv(ctlr_dev);
153 struct bnx2fc_interface *fcoe = fcoe_ctlr_priv(ctlr);
154
155 fcf_dev->vlan_id = fcoe->vlan_id;
156}
157
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800158static void bnx2fc_clean_rx_queue(struct fc_lport *lp)
159{
160 struct fcoe_percpu_s *bg;
161 struct fcoe_rcv_info *fr;
162 struct sk_buff_head *list;
163 struct sk_buff *skb, *next;
164 struct sk_buff *head;
165
166 bg = &bnx2fc_global;
167 spin_lock_bh(&bg->fcoe_rx_list.lock);
168 list = &bg->fcoe_rx_list;
169 head = list->next;
170 for (skb = head; skb != (struct sk_buff *)list;
171 skb = next) {
172 next = skb->next;
173 fr = fcoe_dev_from_skb(skb);
174 if (fr->fr_dev == lp) {
175 __skb_unlink(skb, list);
176 kfree_skb(skb);
177 }
178 }
179 spin_unlock_bh(&bg->fcoe_rx_list.lock);
180}
181
182int bnx2fc_get_paged_crc_eof(struct sk_buff *skb, int tlen)
183{
184 int rc;
185 spin_lock(&bnx2fc_global_lock);
186 rc = fcoe_get_paged_crc_eof(skb, tlen, &bnx2fc_global);
187 spin_unlock(&bnx2fc_global_lock);
188
189 return rc;
190}
191
192static void bnx2fc_abort_io(struct fc_lport *lport)
193{
194 /*
195 * This function is no-op for bnx2fc, but we do
196 * not want to leave it as NULL either, as libfc
197 * can call the default function which is
198 * fc_fcp_abort_io.
199 */
200}
201
202static void bnx2fc_cleanup(struct fc_lport *lport)
203{
204 struct fcoe_port *port = lport_priv(lport);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700205 struct bnx2fc_interface *interface = port->priv;
206 struct bnx2fc_hba *hba = interface->hba;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800207 struct bnx2fc_rport *tgt;
208 int i;
209
210 BNX2FC_MISC_DBG("Entered %s\n", __func__);
211 mutex_lock(&hba->hba_mutex);
212 spin_lock_bh(&hba->hba_lock);
213 for (i = 0; i < BNX2FC_NUM_MAX_SESS; i++) {
214 tgt = hba->tgt_ofld_list[i];
215 if (tgt) {
216 /* Cleanup IOs belonging to requested vport */
217 if (tgt->port == port) {
218 spin_unlock_bh(&hba->hba_lock);
219 BNX2FC_TGT_DBG(tgt, "flush/cleanup\n");
220 bnx2fc_flush_active_ios(tgt);
221 spin_lock_bh(&hba->hba_lock);
222 }
223 }
224 }
225 spin_unlock_bh(&hba->hba_lock);
226 mutex_unlock(&hba->hba_mutex);
227}
228
229static int bnx2fc_xmit_l2_frame(struct bnx2fc_rport *tgt,
230 struct fc_frame *fp)
231{
232 struct fc_rport_priv *rdata = tgt->rdata;
233 struct fc_frame_header *fh;
234 int rc = 0;
235
236 fh = fc_frame_header_get(fp);
237 BNX2FC_TGT_DBG(tgt, "Xmit L2 frame rport = 0x%x, oxid = 0x%x, "
238 "r_ctl = 0x%x\n", rdata->ids.port_id,
239 ntohs(fh->fh_ox_id), fh->fh_r_ctl);
240 if ((fh->fh_type == FC_TYPE_ELS) &&
241 (fh->fh_r_ctl == FC_RCTL_ELS_REQ)) {
242
243 switch (fc_frame_payload_op(fp)) {
244 case ELS_ADISC:
245 rc = bnx2fc_send_adisc(tgt, fp);
246 break;
247 case ELS_LOGO:
248 rc = bnx2fc_send_logo(tgt, fp);
249 break;
250 case ELS_RLS:
251 rc = bnx2fc_send_rls(tgt, fp);
252 break;
253 default:
254 break;
255 }
256 } else if ((fh->fh_type == FC_TYPE_BLS) &&
257 (fh->fh_r_ctl == FC_RCTL_BA_ABTS))
258 BNX2FC_TGT_DBG(tgt, "ABTS frame\n");
259 else {
260 BNX2FC_TGT_DBG(tgt, "Send L2 frame type 0x%x "
261 "rctl 0x%x thru non-offload path\n",
262 fh->fh_type, fh->fh_r_ctl);
263 return -ENODEV;
264 }
265 if (rc)
266 return -ENOMEM;
267 else
268 return 0;
269}
270
271/**
272 * bnx2fc_xmit - bnx2fc's FCoE frame transmit function
273 *
274 * @lport: the associated local port
275 * @fp: the fc_frame to be transmitted
276 */
277static int bnx2fc_xmit(struct fc_lport *lport, struct fc_frame *fp)
278{
279 struct ethhdr *eh;
280 struct fcoe_crc_eof *cp;
281 struct sk_buff *skb;
282 struct fc_frame_header *fh;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700283 struct bnx2fc_interface *interface;
Robert Lovefd8f8902012-05-22 19:06:16 -0700284 struct fcoe_ctlr *ctlr;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700285 struct bnx2fc_hba *hba;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800286 struct fcoe_port *port;
287 struct fcoe_hdr *hp;
288 struct bnx2fc_rport *tgt;
Vasu Dev1bd49b42012-05-25 10:26:43 -0700289 struct fc_stats *stats;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800290 u8 sof, eof;
291 u32 crc;
292 unsigned int hlen, tlen, elen;
293 int wlen, rc = 0;
294
295 port = (struct fcoe_port *)lport_priv(lport);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700296 interface = port->priv;
Robert Lovefd8f8902012-05-22 19:06:16 -0700297 ctlr = bnx2fc_to_ctlr(interface);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700298 hba = interface->hba;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800299
300 fh = fc_frame_header_get(fp);
301
302 skb = fp_skb(fp);
303 if (!lport->link_up) {
304 BNX2FC_HBA_DBG(lport, "bnx2fc_xmit link down\n");
305 kfree_skb(skb);
306 return 0;
307 }
308
309 if (unlikely(fh->fh_r_ctl == FC_RCTL_ELS_REQ)) {
Robert Lovefd8f8902012-05-22 19:06:16 -0700310 if (!ctlr->sel_fcf) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800311 BNX2FC_HBA_DBG(lport, "FCF not selected yet!\n");
312 kfree_skb(skb);
313 return -EINVAL;
314 }
Robert Lovefd8f8902012-05-22 19:06:16 -0700315 if (fcoe_ctlr_els_send(ctlr, lport, skb))
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800316 return 0;
317 }
318
319 sof = fr_sof(fp);
320 eof = fr_eof(fp);
321
322 /*
323 * Snoop the frame header to check if the frame is for
324 * an offloaded session
325 */
326 /*
327 * tgt_ofld_list access is synchronized using
328 * both hba mutex and hba lock. Atleast hba mutex or
329 * hba lock needs to be held for read access.
330 */
331
332 spin_lock_bh(&hba->hba_lock);
333 tgt = bnx2fc_tgt_lookup(port, ntoh24(fh->fh_d_id));
334 if (tgt && (test_bit(BNX2FC_FLAG_SESSION_READY, &tgt->flags))) {
335 /* This frame is for offloaded session */
336 BNX2FC_HBA_DBG(lport, "xmit: Frame is for offloaded session "
337 "port_id = 0x%x\n", ntoh24(fh->fh_d_id));
338 spin_unlock_bh(&hba->hba_lock);
339 rc = bnx2fc_xmit_l2_frame(tgt, fp);
340 if (rc != -ENODEV) {
341 kfree_skb(skb);
342 return rc;
343 }
344 } else {
345 spin_unlock_bh(&hba->hba_lock);
346 }
347
348 elen = sizeof(struct ethhdr);
349 hlen = sizeof(struct fcoe_hdr);
350 tlen = sizeof(struct fcoe_crc_eof);
351 wlen = (skb->len - tlen + sizeof(crc)) / FCOE_WORD_TO_BYTE;
352
353 skb->ip_summed = CHECKSUM_NONE;
354 crc = fcoe_fc_crc(fp);
355
356 /* copy port crc and eof to the skb buff */
357 if (skb_is_nonlinear(skb)) {
358 skb_frag_t *frag;
359 if (bnx2fc_get_paged_crc_eof(skb, tlen)) {
360 kfree_skb(skb);
361 return -ENOMEM;
362 }
363 frag = &skb_shinfo(skb)->frags[skb_shinfo(skb)->nr_frags - 1];
Cong Wang77dfce02011-11-25 23:14:23 +0800364 cp = kmap_atomic(skb_frag_page(frag)) + frag->page_offset;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800365 } else {
366 cp = (struct fcoe_crc_eof *)skb_put(skb, tlen);
367 }
368
369 memset(cp, 0, sizeof(*cp));
370 cp->fcoe_eof = eof;
371 cp->fcoe_crc32 = cpu_to_le32(~crc);
372 if (skb_is_nonlinear(skb)) {
Cong Wang77dfce02011-11-25 23:14:23 +0800373 kunmap_atomic(cp);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800374 cp = NULL;
375 }
376
377 /* adjust skb network/transport offsets to match mac/fcoe/port */
378 skb_push(skb, elen + hlen);
379 skb_reset_mac_header(skb);
380 skb_reset_network_header(skb);
381 skb->mac_len = elen;
382 skb->protocol = htons(ETH_P_FCOE);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700383 skb->dev = interface->netdev;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800384
385 /* fill up mac and fcoe headers */
386 eh = eth_hdr(skb);
387 eh->h_proto = htons(ETH_P_FCOE);
Robert Lovefd8f8902012-05-22 19:06:16 -0700388 if (ctlr->map_dest)
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800389 fc_fcoe_set_mac(eh->h_dest, fh->fh_d_id);
390 else
391 /* insert GW address */
Robert Lovefd8f8902012-05-22 19:06:16 -0700392 memcpy(eh->h_dest, ctlr->dest_addr, ETH_ALEN);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800393
Robert Lovefd8f8902012-05-22 19:06:16 -0700394 if (unlikely(ctlr->flogi_oxid != FC_XID_UNKNOWN))
395 memcpy(eh->h_source, ctlr->ctl_src_addr, ETH_ALEN);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800396 else
397 memcpy(eh->h_source, port->data_src_addr, ETH_ALEN);
398
399 hp = (struct fcoe_hdr *)(eh + 1);
400 memset(hp, 0, sizeof(*hp));
401 if (FC_FCOE_VER)
402 FC_FCOE_ENCAPS_VER(hp, FC_FCOE_VER);
403 hp->fcoe_sof = sof;
404
405 /* fcoe lso, mss is in max_payload which is non-zero for FCP data */
406 if (lport->seq_offload && fr_max_payload(fp)) {
407 skb_shinfo(skb)->gso_type = SKB_GSO_FCOE;
408 skb_shinfo(skb)->gso_size = fr_max_payload(fp);
409 } else {
410 skb_shinfo(skb)->gso_type = 0;
411 skb_shinfo(skb)->gso_size = 0;
412 }
413
414 /*update tx stats */
Vasu Dev1bd49b42012-05-25 10:26:43 -0700415 stats = per_cpu_ptr(lport->stats, get_cpu());
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800416 stats->TxFrames++;
417 stats->TxWords += wlen;
418 put_cpu();
419
420 /* send down to lld */
421 fr_dev(fp) = lport;
422 if (port->fcoe_pending_queue.qlen)
423 fcoe_check_wait_queue(lport, skb);
424 else if (fcoe_start_io(skb))
425 fcoe_check_wait_queue(lport, skb);
426
427 return 0;
428}
429
430/**
431 * bnx2fc_rcv - This is bnx2fc's receive function called by NET_RX_SOFTIRQ
432 *
433 * @skb: the receive socket buffer
434 * @dev: associated net device
435 * @ptype: context
436 * @olddev: last device
437 *
438 * This function receives the packet and builds FC frame and passes it up
439 */
440static int bnx2fc_rcv(struct sk_buff *skb, struct net_device *dev,
441 struct packet_type *ptype, struct net_device *olddev)
442{
443 struct fc_lport *lport;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700444 struct bnx2fc_interface *interface;
Robert Lovefd8f8902012-05-22 19:06:16 -0700445 struct fcoe_ctlr *ctlr;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800446 struct fc_frame_header *fh;
447 struct fcoe_rcv_info *fr;
448 struct fcoe_percpu_s *bg;
449 unsigned short oxid;
450
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700451 interface = container_of(ptype, struct bnx2fc_interface,
452 fcoe_packet_type);
Robert Lovefd8f8902012-05-22 19:06:16 -0700453 ctlr = bnx2fc_to_ctlr(interface);
454 lport = ctlr->lp;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800455
456 if (unlikely(lport == NULL)) {
Bhanu Prakash Gollapudib2a554f2011-06-27 23:30:53 -0700457 printk(KERN_ERR PFX "bnx2fc_rcv: lport is NULL\n");
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800458 goto err;
459 }
460
461 if (unlikely(eth_hdr(skb)->h_proto != htons(ETH_P_FCOE))) {
Bhanu Prakash Gollapudib2a554f2011-06-27 23:30:53 -0700462 printk(KERN_ERR PFX "bnx2fc_rcv: Wrong FC type frame\n");
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800463 goto err;
464 }
465
466 /*
467 * Check for minimum frame length, and make sure required FCoE
468 * and FC headers are pulled into the linear data area.
469 */
470 if (unlikely((skb->len < FCOE_MIN_FRAME) ||
471 !pskb_may_pull(skb, FCOE_HEADER_LEN)))
472 goto err;
473
474 skb_set_transport_header(skb, sizeof(struct fcoe_hdr));
475 fh = (struct fc_frame_header *) skb_transport_header(skb);
476
477 oxid = ntohs(fh->fh_ox_id);
478
479 fr = fcoe_dev_from_skb(skb);
480 fr->fr_dev = lport;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800481
482 bg = &bnx2fc_global;
Neil Hormanfc05ab72012-03-09 14:50:13 -0800483 spin_lock(&bg->fcoe_rx_list.lock);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800484
485 __skb_queue_tail(&bg->fcoe_rx_list, skb);
486 if (bg->fcoe_rx_list.qlen == 1)
487 wake_up_process(bg->thread);
488
Neil Hormanfc05ab72012-03-09 14:50:13 -0800489 spin_unlock(&bg->fcoe_rx_list.lock);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800490
491 return 0;
492err:
493 kfree_skb(skb);
494 return -1;
495}
496
497static int bnx2fc_l2_rcv_thread(void *arg)
498{
499 struct fcoe_percpu_s *bg = arg;
500 struct sk_buff *skb;
501
502 set_user_nice(current, -20);
503 set_current_state(TASK_INTERRUPTIBLE);
504 while (!kthread_should_stop()) {
505 schedule();
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800506 spin_lock_bh(&bg->fcoe_rx_list.lock);
507 while ((skb = __skb_dequeue(&bg->fcoe_rx_list)) != NULL) {
508 spin_unlock_bh(&bg->fcoe_rx_list.lock);
509 bnx2fc_recv_frame(skb);
510 spin_lock_bh(&bg->fcoe_rx_list.lock);
511 }
Bhanu Gollapudifee78712011-03-21 18:51:13 -0700512 __set_current_state(TASK_INTERRUPTIBLE);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800513 spin_unlock_bh(&bg->fcoe_rx_list.lock);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800514 }
Bhanu Gollapudifee78712011-03-21 18:51:13 -0700515 __set_current_state(TASK_RUNNING);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800516 return 0;
517}
518
519
520static void bnx2fc_recv_frame(struct sk_buff *skb)
521{
522 u32 fr_len;
523 struct fc_lport *lport;
524 struct fcoe_rcv_info *fr;
Vasu Dev1bd49b42012-05-25 10:26:43 -0700525 struct fc_stats *stats;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800526 struct fc_frame_header *fh;
527 struct fcoe_crc_eof crc_eof;
528 struct fc_frame *fp;
529 struct fc_lport *vn_port;
530 struct fcoe_port *port;
531 u8 *mac = NULL;
532 u8 *dest_mac = NULL;
533 struct fcoe_hdr *hp;
534
535 fr = fcoe_dev_from_skb(skb);
536 lport = fr->fr_dev;
537 if (unlikely(lport == NULL)) {
Bhanu Prakash Gollapudib2a554f2011-06-27 23:30:53 -0700538 printk(KERN_ERR PFX "Invalid lport struct\n");
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800539 kfree_skb(skb);
540 return;
541 }
542
543 if (skb_is_nonlinear(skb))
544 skb_linearize(skb);
545 mac = eth_hdr(skb)->h_source;
546 dest_mac = eth_hdr(skb)->h_dest;
547
548 /* Pull the header */
549 hp = (struct fcoe_hdr *) skb_network_header(skb);
550 fh = (struct fc_frame_header *) skb_transport_header(skb);
551 skb_pull(skb, sizeof(struct fcoe_hdr));
552 fr_len = skb->len - sizeof(struct fcoe_crc_eof);
553
Vasu Dev1bd49b42012-05-25 10:26:43 -0700554 stats = per_cpu_ptr(lport->stats, get_cpu());
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800555 stats->RxFrames++;
556 stats->RxWords += fr_len / FCOE_WORD_TO_BYTE;
557
558 fp = (struct fc_frame *)skb;
559 fc_frame_init(fp);
560 fr_dev(fp) = lport;
561 fr_sof(fp) = hp->fcoe_sof;
562 if (skb_copy_bits(skb, fr_len, &crc_eof, sizeof(crc_eof))) {
563 put_cpu();
564 kfree_skb(skb);
565 return;
566 }
567 fr_eof(fp) = crc_eof.fcoe_eof;
568 fr_crc(fp) = crc_eof.fcoe_crc32;
569 if (pskb_trim(skb, fr_len)) {
570 put_cpu();
571 kfree_skb(skb);
572 return;
573 }
574
575 fh = fc_frame_header_get(fp);
576
577 vn_port = fc_vport_id_lookup(lport, ntoh24(fh->fh_d_id));
578 if (vn_port) {
579 port = lport_priv(vn_port);
580 if (compare_ether_addr(port->data_src_addr, dest_mac)
581 != 0) {
582 BNX2FC_HBA_DBG(lport, "fpma mismatch\n");
583 put_cpu();
584 kfree_skb(skb);
585 return;
586 }
587 }
588 if (fh->fh_r_ctl == FC_RCTL_DD_SOL_DATA &&
589 fh->fh_type == FC_TYPE_FCP) {
590 /* Drop FCP data. We dont this in L2 path */
591 put_cpu();
592 kfree_skb(skb);
593 return;
594 }
595 if (fh->fh_r_ctl == FC_RCTL_ELS_REQ &&
596 fh->fh_type == FC_TYPE_ELS) {
597 switch (fc_frame_payload_op(fp)) {
598 case ELS_LOGO:
599 if (ntoh24(fh->fh_s_id) == FC_FID_FLOGI) {
600 /* drop non-FIP LOGO */
601 put_cpu();
602 kfree_skb(skb);
603 return;
604 }
605 break;
606 }
607 }
Bhanu Prakash Gollapudi3f8744d2011-08-04 17:38:48 -0700608
609 if (fh->fh_r_ctl == FC_RCTL_BA_ABTS) {
610 /* Drop incoming ABTS */
611 put_cpu();
612 kfree_skb(skb);
613 return;
614 }
615
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800616 if (le32_to_cpu(fr_crc(fp)) !=
617 ~crc32(~0, skb->data, fr_len)) {
618 if (stats->InvalidCRCCount < 5)
619 printk(KERN_WARNING PFX "dropping frame with "
620 "CRC error\n");
621 stats->InvalidCRCCount++;
622 put_cpu();
623 kfree_skb(skb);
624 return;
625 }
626 put_cpu();
627 fc_exch_recv(lport, fp);
628}
629
630/**
631 * bnx2fc_percpu_io_thread - thread per cpu for ios
632 *
633 * @arg: ptr to bnx2fc_percpu_info structure
634 */
635int bnx2fc_percpu_io_thread(void *arg)
636{
637 struct bnx2fc_percpu_s *p = arg;
638 struct bnx2fc_work *work, *tmp;
639 LIST_HEAD(work_list);
640
641 set_user_nice(current, -20);
642 set_current_state(TASK_INTERRUPTIBLE);
643 while (!kthread_should_stop()) {
644 schedule();
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800645 spin_lock_bh(&p->fp_work_lock);
646 while (!list_empty(&p->work_list)) {
647 list_splice_init(&p->work_list, &work_list);
648 spin_unlock_bh(&p->fp_work_lock);
649
650 list_for_each_entry_safe(work, tmp, &work_list, list) {
651 list_del_init(&work->list);
652 bnx2fc_process_cq_compl(work->tgt, work->wqe);
653 kfree(work);
654 }
655
656 spin_lock_bh(&p->fp_work_lock);
657 }
Bhanu Gollapudifee78712011-03-21 18:51:13 -0700658 __set_current_state(TASK_INTERRUPTIBLE);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800659 spin_unlock_bh(&p->fp_work_lock);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800660 }
Bhanu Gollapudifee78712011-03-21 18:51:13 -0700661 __set_current_state(TASK_RUNNING);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800662
663 return 0;
664}
665
666static struct fc_host_statistics *bnx2fc_get_host_stats(struct Scsi_Host *shost)
667{
668 struct fc_host_statistics *bnx2fc_stats;
669 struct fc_lport *lport = shost_priv(shost);
670 struct fcoe_port *port = lport_priv(lport);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700671 struct bnx2fc_interface *interface = port->priv;
672 struct bnx2fc_hba *hba = interface->hba;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800673 struct fcoe_statistics_params *fw_stats;
674 int rc = 0;
675
676 fw_stats = (struct fcoe_statistics_params *)hba->stats_buffer;
677 if (!fw_stats)
678 return NULL;
679
680 bnx2fc_stats = fc_get_host_stats(shost);
681
682 init_completion(&hba->stat_req_done);
683 if (bnx2fc_send_stat_req(hba))
684 return bnx2fc_stats;
685 rc = wait_for_completion_timeout(&hba->stat_req_done, (2 * HZ));
686 if (!rc) {
687 BNX2FC_HBA_DBG(lport, "FW stat req timed out\n");
688 return bnx2fc_stats;
689 }
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300690 bnx2fc_stats->invalid_crc_count += fw_stats->rx_stat2.fc_crc_cnt;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800691 bnx2fc_stats->tx_frames += fw_stats->tx_stat.fcoe_tx_pkt_cnt;
692 bnx2fc_stats->tx_words += (fw_stats->tx_stat.fcoe_tx_byte_cnt) / 4;
693 bnx2fc_stats->rx_frames += fw_stats->rx_stat0.fcoe_rx_pkt_cnt;
694 bnx2fc_stats->rx_words += (fw_stats->rx_stat0.fcoe_rx_byte_cnt) / 4;
695
696 bnx2fc_stats->dumped_frames = 0;
697 bnx2fc_stats->lip_count = 0;
698 bnx2fc_stats->nos_count = 0;
699 bnx2fc_stats->loss_of_sync_count = 0;
700 bnx2fc_stats->loss_of_signal_count = 0;
701 bnx2fc_stats->prim_seq_protocol_err_count = 0;
702
703 return bnx2fc_stats;
704}
705
706static int bnx2fc_shost_config(struct fc_lport *lport, struct device *dev)
707{
708 struct fcoe_port *port = lport_priv(lport);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700709 struct bnx2fc_interface *interface = port->priv;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800710 struct Scsi_Host *shost = lport->host;
711 int rc = 0;
712
713 shost->max_cmd_len = BNX2FC_MAX_CMD_LEN;
714 shost->max_lun = BNX2FC_MAX_LUN;
715 shost->max_id = BNX2FC_MAX_FCP_TGT;
716 shost->max_channel = 0;
717 if (lport->vport)
718 shost->transportt = bnx2fc_vport_xport_template;
719 else
720 shost->transportt = bnx2fc_transport_template;
721
722 /* Add the new host to SCSI-ml */
723 rc = scsi_add_host(lport->host, dev);
724 if (rc) {
725 printk(KERN_ERR PFX "Error on scsi_add_host\n");
726 return rc;
727 }
728 if (!lport->vport)
729 fc_host_max_npiv_vports(lport->host) = USHRT_MAX;
730 sprintf(fc_host_symbolic_name(lport->host), "%s v%s over %s",
731 BNX2FC_NAME, BNX2FC_VERSION,
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700732 interface->netdev->name);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800733
734 return 0;
735}
736
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800737static void bnx2fc_link_speed_update(struct fc_lport *lport)
738{
739 struct fcoe_port *port = lport_priv(lport);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700740 struct bnx2fc_interface *interface = port->priv;
741 struct net_device *netdev = interface->netdev;
David Decotigny8ae6dac2011-04-27 18:32:38 +0000742 struct ethtool_cmd ecmd;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800743
Jiri Pirko4bc71cb2011-09-03 03:34:30 +0000744 if (!__ethtool_get_settings(netdev, &ecmd)) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800745 lport->link_supported_speeds &=
746 ~(FC_PORTSPEED_1GBIT | FC_PORTSPEED_10GBIT);
747 if (ecmd.supported & (SUPPORTED_1000baseT_Half |
748 SUPPORTED_1000baseT_Full))
749 lport->link_supported_speeds |= FC_PORTSPEED_1GBIT;
750 if (ecmd.supported & SUPPORTED_10000baseT_Full)
751 lport->link_supported_speeds |= FC_PORTSPEED_10GBIT;
752
David Decotigny8ae6dac2011-04-27 18:32:38 +0000753 switch (ethtool_cmd_speed(&ecmd)) {
754 case SPEED_1000:
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800755 lport->link_speed = FC_PORTSPEED_1GBIT;
David Decotigny8ae6dac2011-04-27 18:32:38 +0000756 break;
Bhanu Prakash Gollapudia4dc08c2011-05-27 11:47:25 -0700757 case SPEED_2500:
758 lport->link_speed = FC_PORTSPEED_2GBIT;
759 break;
David Decotigny8ae6dac2011-04-27 18:32:38 +0000760 case SPEED_10000:
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800761 lport->link_speed = FC_PORTSPEED_10GBIT;
David Decotigny8ae6dac2011-04-27 18:32:38 +0000762 break;
763 }
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800764 }
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800765}
766static int bnx2fc_link_ok(struct fc_lport *lport)
767{
768 struct fcoe_port *port = lport_priv(lport);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700769 struct bnx2fc_interface *interface = port->priv;
770 struct bnx2fc_hba *hba = interface->hba;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800771 struct net_device *dev = hba->phys_dev;
772 int rc = 0;
773
774 if ((dev->flags & IFF_UP) && netif_carrier_ok(dev))
775 clear_bit(ADAPTER_STATE_LINK_DOWN, &hba->adapter_state);
776 else {
777 set_bit(ADAPTER_STATE_LINK_DOWN, &hba->adapter_state);
778 rc = -1;
779 }
780 return rc;
781}
782
783/**
784 * bnx2fc_get_link_state - get network link state
785 *
786 * @hba: adapter instance pointer
787 *
788 * updates adapter structure flag based on netdev state
789 */
790void bnx2fc_get_link_state(struct bnx2fc_hba *hba)
791{
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700792 if (test_bit(__LINK_STATE_NOCARRIER, &hba->phys_dev->state))
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800793 set_bit(ADAPTER_STATE_LINK_DOWN, &hba->adapter_state);
794 else
795 clear_bit(ADAPTER_STATE_LINK_DOWN, &hba->adapter_state);
796}
797
Bhanu Prakash Gollapudi52439602011-08-04 17:38:50 -0700798static int bnx2fc_net_config(struct fc_lport *lport, struct net_device *netdev)
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800799{
800 struct bnx2fc_hba *hba;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700801 struct bnx2fc_interface *interface;
Robert Lovefd8f8902012-05-22 19:06:16 -0700802 struct fcoe_ctlr *ctlr;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800803 struct fcoe_port *port;
804 u64 wwnn, wwpn;
805
806 port = lport_priv(lport);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700807 interface = port->priv;
Robert Lovefd8f8902012-05-22 19:06:16 -0700808 ctlr = bnx2fc_to_ctlr(interface);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700809 hba = interface->hba;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800810
811 /* require support for get_pauseparam ethtool op. */
812 if (!hba->phys_dev->ethtool_ops ||
813 !hba->phys_dev->ethtool_ops->get_pauseparam)
814 return -EOPNOTSUPP;
815
Bhanu Gollapudi1294bfe2011-03-17 17:13:34 -0700816 if (fc_set_mfs(lport, BNX2FC_MFS))
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800817 return -EINVAL;
818
819 skb_queue_head_init(&port->fcoe_pending_queue);
820 port->fcoe_pending_queue_active = 0;
821 setup_timer(&port->timer, fcoe_queue_timer, (unsigned long) lport);
822
823 bnx2fc_link_speed_update(lport);
824
825 if (!lport->vport) {
Bhanu Prakash Gollapudi52439602011-08-04 17:38:50 -0700826 if (fcoe_get_wwn(netdev, &wwnn, NETDEV_FCOE_WWNN))
Robert Lovefd8f8902012-05-22 19:06:16 -0700827 wwnn = fcoe_wwn_from_mac(ctlr->ctl_src_addr,
Bhanu Prakash Gollapudi52439602011-08-04 17:38:50 -0700828 1, 0);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800829 BNX2FC_HBA_DBG(lport, "WWNN = 0x%llx\n", wwnn);
830 fc_set_wwnn(lport, wwnn);
831
Bhanu Prakash Gollapudi52439602011-08-04 17:38:50 -0700832 if (fcoe_get_wwn(netdev, &wwpn, NETDEV_FCOE_WWPN))
Robert Lovefd8f8902012-05-22 19:06:16 -0700833 wwpn = fcoe_wwn_from_mac(ctlr->ctl_src_addr,
Bhanu Prakash Gollapudi52439602011-08-04 17:38:50 -0700834 2, 0);
835
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800836 BNX2FC_HBA_DBG(lport, "WWPN = 0x%llx\n", wwpn);
837 fc_set_wwpn(lport, wwpn);
838 }
839
840 return 0;
841}
842
843static void bnx2fc_destroy_timer(unsigned long data)
844{
845 struct bnx2fc_hba *hba = (struct bnx2fc_hba *)data;
846
Bhanu Prakash Gollapudicd703ae2011-08-04 17:38:43 -0700847 printk(KERN_ERR PFX "ERROR:bnx2fc_destroy_timer - "
848 "Destroy compl not received!!\n");
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700849 set_bit(BNX2FC_FLAG_DESTROY_CMPL, &hba->flags);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800850 wake_up_interruptible(&hba->destroy_wait);
851}
852
853/**
854 * bnx2fc_indicate_netevent - Generic netdev event handler
855 *
856 * @context: adapter structure pointer
857 * @event: event type
Michael Chan415199f2011-07-20 14:55:24 +0000858 * @vlan_id: vlan id - associated vlan id with this event
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800859 *
860 * Handles NETDEV_UP, NETDEV_DOWN, NETDEV_GOING_DOWN,NETDEV_CHANGE and
Bhanu Prakash Gollapudiabc49a92011-08-04 17:38:42 -0700861 * NETDEV_CHANGE_MTU events. Handle NETDEV_UNREGISTER only for vlans.
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800862 */
Michael Chan415199f2011-07-20 14:55:24 +0000863static void bnx2fc_indicate_netevent(void *context, unsigned long event,
864 u16 vlan_id)
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800865{
866 struct bnx2fc_hba *hba = (struct bnx2fc_hba *)context;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700867 struct fc_lport *lport;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800868 struct fc_lport *vport;
Bhanu Prakash Gollapudiabc49a92011-08-04 17:38:42 -0700869 struct bnx2fc_interface *interface, *tmp;
Robert Lovefd8f8902012-05-22 19:06:16 -0700870 struct fcoe_ctlr *ctlr;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700871 int wait_for_upload = 0;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800872 u32 link_possible = 1;
873
Bhanu Prakash Gollapudiabc49a92011-08-04 17:38:42 -0700874 if (vlan_id != 0 && event != NETDEV_UNREGISTER)
Michael Chan415199f2011-07-20 14:55:24 +0000875 return;
876
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800877 switch (event) {
878 case NETDEV_UP:
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800879 if (!test_bit(ADAPTER_STATE_UP, &hba->adapter_state))
880 printk(KERN_ERR "indicate_netevent: "\
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700881 "hba is not UP!!\n");
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800882 break;
883
884 case NETDEV_DOWN:
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800885 clear_bit(ADAPTER_STATE_GOING_DOWN, &hba->adapter_state);
886 clear_bit(ADAPTER_STATE_UP, &hba->adapter_state);
887 link_possible = 0;
888 break;
889
890 case NETDEV_GOING_DOWN:
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800891 set_bit(ADAPTER_STATE_GOING_DOWN, &hba->adapter_state);
892 link_possible = 0;
893 break;
894
895 case NETDEV_CHANGE:
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800896 break;
897
Bhanu Prakash Gollapudiabc49a92011-08-04 17:38:42 -0700898 case NETDEV_UNREGISTER:
899 if (!vlan_id)
900 return;
901 mutex_lock(&bnx2fc_dev_lock);
902 list_for_each_entry_safe(interface, tmp, &if_list, list) {
Nithin Nayak Sujir26b29822011-08-30 15:54:50 -0700903 if (interface->hba == hba &&
904 interface->vlan_id == (vlan_id & VLAN_VID_MASK))
905 __bnx2fc_destroy(interface);
Bhanu Prakash Gollapudiabc49a92011-08-04 17:38:42 -0700906 }
907 mutex_unlock(&bnx2fc_dev_lock);
908 return;
909
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800910 default:
Masanari Iida59e13d42012-04-25 00:24:16 +0900911 printk(KERN_ERR PFX "Unknown netevent %ld", event);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800912 return;
913 }
914
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700915 mutex_lock(&bnx2fc_dev_lock);
916 list_for_each_entry(interface, &if_list, list) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800917
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700918 if (interface->hba != hba)
919 continue;
920
Robert Lovefd8f8902012-05-22 19:06:16 -0700921 ctlr = bnx2fc_to_ctlr(interface);
922 lport = ctlr->lp;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700923 BNX2FC_HBA_DBG(lport, "netevent handler - event=%s %ld\n",
924 interface->netdev->name, event);
925
926 bnx2fc_link_speed_update(lport);
927
928 if (link_possible && !bnx2fc_link_ok(lport)) {
Bhanu Prakash Gollapudic7806732011-08-30 15:54:47 -0700929 /* Reset max recv frame size to default */
930 fc_set_mfs(lport, BNX2FC_MFS);
Bhanu Prakash Gollapudi8a5badf2011-08-30 15:54:48 -0700931 /*
932 * ctlr link up will only be handled during
933 * enable to avoid sending discovery solicitation
934 * on a stale vlan
935 */
Bhanu Prakash Gollapudifd8fa902011-10-03 16:45:00 -0700936 if (interface->enabled)
Robert Lovefd8f8902012-05-22 19:06:16 -0700937 fcoe_ctlr_link_up(ctlr);
938 } else if (fcoe_ctlr_link_down(ctlr)) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800939 mutex_lock(&lport->lp_mutex);
940 list_for_each_entry(vport, &lport->vports, list)
941 fc_host_port_type(vport->host) =
942 FC_PORTTYPE_UNKNOWN;
943 mutex_unlock(&lport->lp_mutex);
944 fc_host_port_type(lport->host) = FC_PORTTYPE_UNKNOWN;
Vasu Dev1bd49b42012-05-25 10:26:43 -0700945 per_cpu_ptr(lport->stats,
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800946 get_cpu())->LinkFailureCount++;
947 put_cpu();
948 fcoe_clean_pending_queue(lport);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700949 wait_for_upload = 1;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800950 }
951 }
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700952 mutex_unlock(&bnx2fc_dev_lock);
953
954 if (wait_for_upload) {
955 clear_bit(ADAPTER_STATE_READY, &hba->adapter_state);
956 init_waitqueue_head(&hba->shutdown_wait);
957 BNX2FC_MISC_DBG("indicate_netevent "
958 "num_ofld_sess = %d\n",
959 hba->num_ofld_sess);
960 hba->wait_for_link_down = 1;
961 wait_event_interruptible(hba->shutdown_wait,
962 (hba->num_ofld_sess == 0));
963 BNX2FC_MISC_DBG("wakeup - num_ofld_sess = %d\n",
964 hba->num_ofld_sess);
965 hba->wait_for_link_down = 0;
966
967 if (signal_pending(current))
968 flush_signals(current);
969 }
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800970}
971
972static int bnx2fc_libfc_config(struct fc_lport *lport)
973{
974
975 /* Set the function pointers set by bnx2fc driver */
976 memcpy(&lport->tt, &bnx2fc_libfc_fcn_templ,
977 sizeof(struct libfc_function_template));
978 fc_elsct_init(lport);
979 fc_exch_init(lport);
980 fc_rport_init(lport);
981 fc_disc_init(lport);
982 return 0;
983}
984
985static int bnx2fc_em_config(struct fc_lport *lport)
986{
Bhanu Prakash Gollapudi7d742f62012-01-23 18:00:48 -0800987 int max_xid;
988
989 if (nr_cpu_ids <= 2)
990 max_xid = FCOE_XIDS_PER_CPU;
991 else
992 max_xid = FCOE_MAX_XID;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800993 if (!fc_exch_mgr_alloc(lport, FC_CLASS_3, FCOE_MIN_XID,
Bhanu Prakash Gollapudi7d742f62012-01-23 18:00:48 -0800994 max_xid, NULL)) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800995 printk(KERN_ERR PFX "em_config:fc_exch_mgr_alloc failed\n");
996 return -ENOMEM;
997 }
998
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800999 return 0;
1000}
1001
1002static int bnx2fc_lport_config(struct fc_lport *lport)
1003{
1004 lport->link_up = 0;
1005 lport->qfull = 0;
Bhanu Prakash Gollapudi44c570b2012-01-23 18:00:47 -08001006 lport->max_retry_count = BNX2FC_MAX_RETRY_CNT;
1007 lport->max_rport_retry_count = BNX2FC_MAX_RPORT_RETRY_CNT;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001008 lport->e_d_tov = 2 * 1000;
1009 lport->r_a_tov = 10 * 1000;
1010
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001011 lport->service_params = (FCP_SPPF_INIT_FCN | FCP_SPPF_RD_XRDY_DIS |
1012 FCP_SPPF_RETRY | FCP_SPPF_CONF_COMPL);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001013 lport->does_npiv = 1;
1014
1015 memset(&lport->rnid_gen, 0, sizeof(struct fc_els_rnid_gen));
1016 lport->rnid_gen.rnid_atype = BNX2FC_RNID_HBA;
1017
1018 /* alloc stats structure */
1019 if (fc_lport_init_stats(lport))
1020 return -ENOMEM;
1021
1022 /* Finish fc_lport configuration */
1023 fc_lport_config(lport);
1024
1025 return 0;
1026}
1027
1028/**
1029 * bnx2fc_fip_recv - handle a received FIP frame.
1030 *
1031 * @skb: the received skb
1032 * @dev: associated &net_device
1033 * @ptype: the &packet_type structure which was used to register this handler.
1034 * @orig_dev: original receive &net_device, in case @ dev is a bond.
1035 *
1036 * Returns: 0 for success
1037 */
1038static int bnx2fc_fip_recv(struct sk_buff *skb, struct net_device *dev,
1039 struct packet_type *ptype,
1040 struct net_device *orig_dev)
1041{
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001042 struct bnx2fc_interface *interface;
Robert Lovefd8f8902012-05-22 19:06:16 -07001043 struct fcoe_ctlr *ctlr;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001044 interface = container_of(ptype, struct bnx2fc_interface,
1045 fip_packet_type);
Robert Lovefd8f8902012-05-22 19:06:16 -07001046 ctlr = bnx2fc_to_ctlr(interface);
1047 fcoe_ctlr_recv(ctlr, skb);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001048 return 0;
1049}
1050
1051/**
1052 * bnx2fc_update_src_mac - Update Ethernet MAC filters.
1053 *
1054 * @fip: FCoE controller.
1055 * @old: Unicast MAC address to delete if the MAC is non-zero.
1056 * @new: Unicast MAC address to add.
1057 *
1058 * Remove any previously-set unicast MAC filter.
1059 * Add secondary FCoE MAC address filter for our OUI.
1060 */
1061static void bnx2fc_update_src_mac(struct fc_lport *lport, u8 *addr)
1062{
1063 struct fcoe_port *port = lport_priv(lport);
1064
1065 memcpy(port->data_src_addr, addr, ETH_ALEN);
1066}
1067
1068/**
1069 * bnx2fc_get_src_mac - return the ethernet source address for an lport
1070 *
1071 * @lport: libfc port
1072 */
1073static u8 *bnx2fc_get_src_mac(struct fc_lport *lport)
1074{
1075 struct fcoe_port *port;
1076
1077 port = (struct fcoe_port *)lport_priv(lport);
1078 return port->data_src_addr;
1079}
1080
1081/**
1082 * bnx2fc_fip_send - send an Ethernet-encapsulated FIP frame.
1083 *
1084 * @fip: FCoE controller.
1085 * @skb: FIP Packet.
1086 */
1087static void bnx2fc_fip_send(struct fcoe_ctlr *fip, struct sk_buff *skb)
1088{
1089 skb->dev = bnx2fc_from_ctlr(fip)->netdev;
1090 dev_queue_xmit(skb);
1091}
1092
1093static int bnx2fc_vport_create(struct fc_vport *vport, bool disabled)
1094{
1095 struct Scsi_Host *shost = vport_to_shost(vport);
1096 struct fc_lport *n_port = shost_priv(shost);
1097 struct fcoe_port *port = lport_priv(n_port);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001098 struct bnx2fc_interface *interface = port->priv;
1099 struct net_device *netdev = interface->netdev;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001100 struct fc_lport *vn_port;
Bhanu Prakash Gollapudi861efc52011-08-04 17:38:51 -07001101 int rc;
1102 char buf[32];
1103
1104 rc = fcoe_validate_vport_create(vport);
1105 if (rc) {
1106 fcoe_wwn_to_str(vport->port_name, buf, sizeof(buf));
1107 printk(KERN_ERR PFX "Failed to create vport, "
1108 "WWPN (0x%s) already exists\n",
1109 buf);
1110 return rc;
1111 }
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001112
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001113 if (!test_bit(BNX2FC_FLAG_FW_INIT_DONE, &interface->hba->flags)) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001114 printk(KERN_ERR PFX "vn ports cannot be created on"
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001115 "this interface\n");
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001116 return -EIO;
1117 }
Jiri Pirko4bc71cb2011-09-03 03:34:30 +00001118 rtnl_lock();
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001119 mutex_lock(&bnx2fc_dev_lock);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001120 vn_port = bnx2fc_if_create(interface, &vport->dev, 1);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001121 mutex_unlock(&bnx2fc_dev_lock);
Jiri Pirko4bc71cb2011-09-03 03:34:30 +00001122 rtnl_unlock();
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001123
1124 if (IS_ERR(vn_port)) {
1125 printk(KERN_ERR PFX "bnx2fc_vport_create (%s) failed\n",
1126 netdev->name);
1127 return -EIO;
1128 }
1129
1130 if (disabled) {
1131 fc_vport_set_state(vport, FC_VPORT_DISABLED);
1132 } else {
1133 vn_port->boot_time = jiffies;
1134 fc_lport_init(vn_port);
1135 fc_fabric_login(vn_port);
1136 fc_vport_setlink(vn_port);
1137 }
1138 return 0;
1139}
1140
Bhanu Prakash Gollapudiabc49a92011-08-04 17:38:42 -07001141static void bnx2fc_free_vport(struct bnx2fc_hba *hba, struct fc_lport *lport)
1142{
1143 struct bnx2fc_lport *blport, *tmp;
1144
1145 spin_lock_bh(&hba->hba_lock);
1146 list_for_each_entry_safe(blport, tmp, &hba->vports, list) {
1147 if (blport->lport == lport) {
1148 list_del(&blport->list);
1149 kfree(blport);
1150 }
1151 }
1152 spin_unlock_bh(&hba->hba_lock);
1153}
1154
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001155static int bnx2fc_vport_destroy(struct fc_vport *vport)
1156{
1157 struct Scsi_Host *shost = vport_to_shost(vport);
1158 struct fc_lport *n_port = shost_priv(shost);
1159 struct fc_lport *vn_port = vport->dd_data;
1160 struct fcoe_port *port = lport_priv(vn_port);
Bhanu Prakash Gollapudiabc49a92011-08-04 17:38:42 -07001161 struct bnx2fc_interface *interface = port->priv;
Bhanu Prakash Gollapudicdf54662011-08-04 17:38:39 -07001162 struct fc_lport *v_port;
1163 bool found = false;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001164
1165 mutex_lock(&n_port->lp_mutex);
Bhanu Prakash Gollapudicdf54662011-08-04 17:38:39 -07001166 list_for_each_entry(v_port, &n_port->vports, list)
1167 if (v_port->vport == vport) {
1168 found = true;
1169 break;
1170 }
1171
1172 if (!found) {
1173 mutex_unlock(&n_port->lp_mutex);
1174 return -ENOENT;
1175 }
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001176 list_del(&vn_port->list);
1177 mutex_unlock(&n_port->lp_mutex);
Bhanu Prakash Gollapudiabc49a92011-08-04 17:38:42 -07001178 bnx2fc_free_vport(interface->hba, port->lport);
1179 bnx2fc_port_shutdown(port->lport);
1180 bnx2fc_interface_put(interface);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001181 queue_work(bnx2fc_wq, &port->destroy_work);
1182 return 0;
1183}
1184
1185static int bnx2fc_vport_disable(struct fc_vport *vport, bool disable)
1186{
1187 struct fc_lport *lport = vport->dd_data;
1188
1189 if (disable) {
1190 fc_vport_set_state(vport, FC_VPORT_DISABLED);
1191 fc_fabric_logoff(lport);
1192 } else {
1193 lport->boot_time = jiffies;
1194 fc_fabric_login(lport);
1195 fc_vport_setlink(lport);
1196 }
1197 return 0;
1198}
1199
1200
Bhanu Prakash Gollapudi776cebc2011-08-04 17:38:40 -07001201static int bnx2fc_interface_setup(struct bnx2fc_interface *interface)
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001202{
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001203 struct net_device *netdev = interface->netdev;
1204 struct net_device *physdev = interface->hba->phys_dev;
Robert Lovefd8f8902012-05-22 19:06:16 -07001205 struct fcoe_ctlr *ctlr = bnx2fc_to_ctlr(interface);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001206 struct netdev_hw_addr *ha;
1207 int sel_san_mac = 0;
1208
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001209 /* setup Source MAC Address */
1210 rcu_read_lock();
1211 for_each_dev_addr(physdev, ha) {
1212 BNX2FC_MISC_DBG("net_config: ha->type = %d, fip_mac = ",
1213 ha->type);
1214 printk(KERN_INFO "%2x:%2x:%2x:%2x:%2x:%2x\n", ha->addr[0],
1215 ha->addr[1], ha->addr[2], ha->addr[3],
1216 ha->addr[4], ha->addr[5]);
1217
1218 if ((ha->type == NETDEV_HW_ADDR_T_SAN) &&
1219 (is_valid_ether_addr(ha->addr))) {
Robert Lovefd8f8902012-05-22 19:06:16 -07001220 memcpy(ctlr->ctl_src_addr, ha->addr,
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001221 ETH_ALEN);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001222 sel_san_mac = 1;
1223 BNX2FC_MISC_DBG("Found SAN MAC\n");
1224 }
1225 }
1226 rcu_read_unlock();
1227
1228 if (!sel_san_mac)
1229 return -ENODEV;
1230
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001231 interface->fip_packet_type.func = bnx2fc_fip_recv;
1232 interface->fip_packet_type.type = htons(ETH_P_FIP);
1233 interface->fip_packet_type.dev = netdev;
1234 dev_add_pack(&interface->fip_packet_type);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001235
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001236 interface->fcoe_packet_type.func = bnx2fc_rcv;
1237 interface->fcoe_packet_type.type = __constant_htons(ETH_P_FCOE);
1238 interface->fcoe_packet_type.dev = netdev;
1239 dev_add_pack(&interface->fcoe_packet_type);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001240
1241 return 0;
1242}
1243
1244static int bnx2fc_attach_transport(void)
1245{
1246 bnx2fc_transport_template =
1247 fc_attach_transport(&bnx2fc_transport_function);
1248
1249 if (bnx2fc_transport_template == NULL) {
1250 printk(KERN_ERR PFX "Failed to attach FC transport\n");
1251 return -ENODEV;
1252 }
1253
1254 bnx2fc_vport_xport_template =
1255 fc_attach_transport(&bnx2fc_vport_xport_function);
1256 if (bnx2fc_vport_xport_template == NULL) {
1257 printk(KERN_ERR PFX
1258 "Failed to attach FC transport for vport\n");
1259 fc_release_transport(bnx2fc_transport_template);
1260 bnx2fc_transport_template = NULL;
1261 return -ENODEV;
1262 }
1263 return 0;
1264}
1265static void bnx2fc_release_transport(void)
1266{
1267 fc_release_transport(bnx2fc_transport_template);
1268 fc_release_transport(bnx2fc_vport_xport_template);
1269 bnx2fc_transport_template = NULL;
1270 bnx2fc_vport_xport_template = NULL;
1271}
1272
1273static void bnx2fc_interface_release(struct kref *kref)
1274{
Robert Love8d55e502012-05-22 19:06:26 -07001275 struct fcoe_ctlr_device *ctlr_dev;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001276 struct bnx2fc_interface *interface;
Robert Lovefd8f8902012-05-22 19:06:16 -07001277 struct fcoe_ctlr *ctlr;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001278 struct net_device *netdev;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001279
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001280 interface = container_of(kref, struct bnx2fc_interface, kref);
Nithin Nayak Sujir068bdce2011-04-25 12:30:09 -07001281 BNX2FC_MISC_DBG("Interface is being released\n");
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001282
Robert Lovefd8f8902012-05-22 19:06:16 -07001283 ctlr = bnx2fc_to_ctlr(interface);
Robert Love8d55e502012-05-22 19:06:26 -07001284 ctlr_dev = fcoe_ctlr_to_ctlr_dev(ctlr);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001285 netdev = interface->netdev;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001286
1287 /* tear-down FIP controller */
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001288 if (test_and_clear_bit(BNX2FC_CTLR_INIT_DONE, &interface->if_flags))
Robert Lovefd8f8902012-05-22 19:06:16 -07001289 fcoe_ctlr_destroy(ctlr);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001290
Robert Love8d55e502012-05-22 19:06:26 -07001291 fcoe_ctlr_device_delete(ctlr_dev);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001292
1293 dev_put(netdev);
1294 module_put(THIS_MODULE);
1295}
1296
1297static inline void bnx2fc_interface_get(struct bnx2fc_interface *interface)
1298{
1299 kref_get(&interface->kref);
1300}
1301
1302static inline void bnx2fc_interface_put(struct bnx2fc_interface *interface)
1303{
1304 kref_put(&interface->kref, bnx2fc_interface_release);
1305}
1306static void bnx2fc_hba_destroy(struct bnx2fc_hba *hba)
1307{
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001308 /* Free the command manager */
1309 if (hba->cmd_mgr) {
1310 bnx2fc_cmd_mgr_free(hba->cmd_mgr);
1311 hba->cmd_mgr = NULL;
1312 }
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001313 kfree(hba->tgt_ofld_list);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001314 bnx2fc_unbind_pcidev(hba);
1315 kfree(hba);
1316}
1317
1318/**
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001319 * bnx2fc_hba_create - create a new bnx2fc hba
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001320 *
1321 * @cnic: pointer to cnic device
1322 *
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001323 * Creates a new FCoE hba on the given device.
1324 *
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001325 */
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001326static struct bnx2fc_hba *bnx2fc_hba_create(struct cnic_dev *cnic)
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001327{
1328 struct bnx2fc_hba *hba;
Barak Witkowski2e499d32012-06-26 01:31:19 +00001329 struct fcoe_capabilities *fcoe_cap;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001330 int rc;
1331
1332 hba = kzalloc(sizeof(*hba), GFP_KERNEL);
1333 if (!hba) {
1334 printk(KERN_ERR PFX "Unable to allocate hba structure\n");
1335 return NULL;
1336 }
1337 spin_lock_init(&hba->hba_lock);
1338 mutex_init(&hba->hba_mutex);
1339
1340 hba->cnic = cnic;
1341 rc = bnx2fc_bind_pcidev(hba);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001342 if (rc) {
1343 printk(KERN_ERR PFX "create_adapter: bind error\n");
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001344 goto bind_err;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001345 }
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001346 hba->phys_dev = cnic->netdev;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001347 hba->next_conn_id = 0;
1348
1349 hba->tgt_ofld_list =
1350 kzalloc(sizeof(struct bnx2fc_rport *) * BNX2FC_NUM_MAX_SESS,
1351 GFP_KERNEL);
1352 if (!hba->tgt_ofld_list) {
1353 printk(KERN_ERR PFX "Unable to allocate tgt offload list\n");
1354 goto tgtofld_err;
1355 }
1356
1357 hba->num_ofld_sess = 0;
1358
1359 hba->cmd_mgr = bnx2fc_cmd_mgr_alloc(hba, BNX2FC_MIN_XID,
1360 BNX2FC_MAX_XID);
1361 if (!hba->cmd_mgr) {
1362 printk(KERN_ERR PFX "em_config:bnx2fc_cmd_mgr_alloc failed\n");
1363 goto cmgr_err;
1364 }
Barak Witkowski2e499d32012-06-26 01:31:19 +00001365 fcoe_cap = &hba->fcoe_cap;
1366
1367 fcoe_cap->capability1 = BNX2FC_TM_MAX_SQES <<
1368 FCOE_IOS_PER_CONNECTION_SHIFT;
1369 fcoe_cap->capability1 |= BNX2FC_NUM_MAX_SESS <<
1370 FCOE_LOGINS_PER_PORT_SHIFT;
1371 fcoe_cap->capability2 = BNX2FC_MAX_OUTSTANDING_CMNDS <<
1372 FCOE_NUMBER_OF_EXCHANGES_SHIFT;
1373 fcoe_cap->capability2 |= BNX2FC_MAX_NPIV <<
1374 FCOE_NPIV_WWN_PER_PORT_SHIFT;
1375 fcoe_cap->capability3 = BNX2FC_NUM_MAX_SESS <<
1376 FCOE_TARGETS_SUPPORTED_SHIFT;
1377 fcoe_cap->capability3 |= BNX2FC_MAX_OUTSTANDING_CMNDS <<
1378 FCOE_OUTSTANDING_COMMANDS_SHIFT;
1379 fcoe_cap->capability4 = FCOE_CAPABILITY4_STATEFUL;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001380
1381 init_waitqueue_head(&hba->shutdown_wait);
1382 init_waitqueue_head(&hba->destroy_wait);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001383 INIT_LIST_HEAD(&hba->vports);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001384
1385 return hba;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001386
1387cmgr_err:
1388 kfree(hba->tgt_ofld_list);
1389tgtofld_err:
1390 bnx2fc_unbind_pcidev(hba);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001391bind_err:
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001392 kfree(hba);
1393 return NULL;
1394}
1395
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001396struct bnx2fc_interface *bnx2fc_interface_create(struct bnx2fc_hba *hba,
1397 struct net_device *netdev,
1398 enum fip_state fip_mode)
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001399{
Robert Love8d55e502012-05-22 19:06:26 -07001400 struct fcoe_ctlr_device *ctlr_dev;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001401 struct bnx2fc_interface *interface;
Robert Lovefd8f8902012-05-22 19:06:16 -07001402 struct fcoe_ctlr *ctlr;
1403 int size;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001404 int rc = 0;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001405
Robert Lovefd8f8902012-05-22 19:06:16 -07001406 size = (sizeof(*interface) + sizeof(struct fcoe_ctlr));
Robert Love8d55e502012-05-22 19:06:26 -07001407 ctlr_dev = fcoe_ctlr_device_add(&netdev->dev, &bnx2fc_fcoe_sysfs_templ,
1408 size);
1409 if (!ctlr_dev) {
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001410 printk(KERN_ERR PFX "Unable to allocate interface structure\n");
1411 return NULL;
1412 }
Robert Love8d55e502012-05-22 19:06:26 -07001413 ctlr = fcoe_ctlr_device_priv(ctlr_dev);
Robert Lovefd8f8902012-05-22 19:06:16 -07001414 interface = fcoe_ctlr_priv(ctlr);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001415 dev_hold(netdev);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001416 kref_init(&interface->kref);
1417 interface->hba = hba;
1418 interface->netdev = netdev;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001419
1420 /* Initialize FIP */
Robert Lovefd8f8902012-05-22 19:06:16 -07001421 fcoe_ctlr_init(ctlr, fip_mode);
1422 ctlr->send = bnx2fc_fip_send;
1423 ctlr->update_mac = bnx2fc_update_src_mac;
1424 ctlr->get_src_addr = bnx2fc_get_src_mac;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001425 set_bit(BNX2FC_CTLR_INIT_DONE, &interface->if_flags);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001426
Bhanu Prakash Gollapudi776cebc2011-08-04 17:38:40 -07001427 rc = bnx2fc_interface_setup(interface);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001428 if (!rc)
1429 return interface;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001430
Robert Lovefd8f8902012-05-22 19:06:16 -07001431 fcoe_ctlr_destroy(ctlr);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001432 dev_put(netdev);
Robert Love8d55e502012-05-22 19:06:26 -07001433 fcoe_ctlr_device_delete(ctlr_dev);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001434 return NULL;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001435}
1436
1437/**
1438 * bnx2fc_if_create - Create FCoE instance on a given interface
1439 *
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001440 * @interface: FCoE interface to create a local port on
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001441 * @parent: Device pointer to be the parent in sysfs for the SCSI host
1442 * @npiv: Indicates if the port is vport or not
1443 *
1444 * Creates a fc_lport instance and a Scsi_Host instance and configure them.
1445 *
1446 * Returns: Allocated fc_lport or an error pointer
1447 */
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001448static struct fc_lport *bnx2fc_if_create(struct bnx2fc_interface *interface,
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001449 struct device *parent, int npiv)
1450{
Robert Lovefd8f8902012-05-22 19:06:16 -07001451 struct fcoe_ctlr *ctlr = bnx2fc_to_ctlr(interface);
Vasu Dev134a4e22011-04-28 15:55:44 -07001452 struct fc_lport *lport, *n_port;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001453 struct fcoe_port *port;
1454 struct Scsi_Host *shost;
1455 struct fc_vport *vport = dev_to_vport(parent);
Bhanu Prakash Gollapudid36b3272011-05-27 11:47:27 -07001456 struct bnx2fc_lport *blport;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001457 struct bnx2fc_hba *hba;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001458 int rc = 0;
1459
Bhanu Prakash Gollapudid36b3272011-05-27 11:47:27 -07001460 blport = kzalloc(sizeof(struct bnx2fc_lport), GFP_KERNEL);
1461 if (!blport) {
Robert Lovefd8f8902012-05-22 19:06:16 -07001462 BNX2FC_HBA_DBG(ctlr->lp, "Unable to alloc blport\n");
Bhanu Prakash Gollapudid36b3272011-05-27 11:47:27 -07001463 return NULL;
1464 }
1465
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001466 /* Allocate Scsi_Host structure */
Vasu Dev134a4e22011-04-28 15:55:44 -07001467 if (!npiv)
1468 lport = libfc_host_alloc(&bnx2fc_shost_template, sizeof(*port));
1469 else
1470 lport = libfc_vport_create(vport, sizeof(*port));
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001471
1472 if (!lport) {
1473 printk(KERN_ERR PFX "could not allocate scsi host structure\n");
Bhanu Prakash Gollapudid36b3272011-05-27 11:47:27 -07001474 goto free_blport;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001475 }
1476 shost = lport->host;
1477 port = lport_priv(lport);
1478 port->lport = lport;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001479 port->priv = interface;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001480 INIT_WORK(&port->destroy_work, bnx2fc_destroy_work);
1481
1482 /* Configure fcoe_port */
1483 rc = bnx2fc_lport_config(lport);
1484 if (rc)
1485 goto lp_config_err;
1486
1487 if (npiv) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001488 printk(KERN_ERR PFX "Setting vport names, 0x%llX 0x%llX\n",
1489 vport->node_name, vport->port_name);
1490 fc_set_wwnn(lport, vport->node_name);
1491 fc_set_wwpn(lport, vport->port_name);
1492 }
1493 /* Configure netdev and networking properties of the lport */
Bhanu Prakash Gollapudi52439602011-08-04 17:38:50 -07001494 rc = bnx2fc_net_config(lport, interface->netdev);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001495 if (rc) {
1496 printk(KERN_ERR PFX "Error on bnx2fc_net_config\n");
1497 goto lp_config_err;
1498 }
1499
1500 rc = bnx2fc_shost_config(lport, parent);
1501 if (rc) {
1502 printk(KERN_ERR PFX "Couldnt configure shost for %s\n",
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001503 interface->netdev->name);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001504 goto lp_config_err;
1505 }
1506
1507 /* Initialize the libfc library */
1508 rc = bnx2fc_libfc_config(lport);
1509 if (rc) {
1510 printk(KERN_ERR PFX "Couldnt configure libfc\n");
1511 goto shost_err;
1512 }
1513 fc_host_port_type(lport->host) = FC_PORTTYPE_UNKNOWN;
1514
1515 /* Allocate exchange manager */
Vasu Dev134a4e22011-04-28 15:55:44 -07001516 if (!npiv)
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001517 rc = bnx2fc_em_config(lport);
Vasu Dev134a4e22011-04-28 15:55:44 -07001518 else {
1519 shost = vport_to_shost(vport);
1520 n_port = shost_priv(shost);
1521 rc = fc_exch_mgr_list_clone(n_port, lport);
1522 }
1523
1524 if (rc) {
1525 printk(KERN_ERR PFX "Error on bnx2fc_em_config\n");
1526 goto shost_err;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001527 }
1528
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001529 bnx2fc_interface_get(interface);
Bhanu Prakash Gollapudid36b3272011-05-27 11:47:27 -07001530
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001531 hba = interface->hba;
Bhanu Prakash Gollapudid36b3272011-05-27 11:47:27 -07001532 spin_lock_bh(&hba->hba_lock);
1533 blport->lport = lport;
1534 list_add_tail(&blport->list, &hba->vports);
1535 spin_unlock_bh(&hba->hba_lock);
1536
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001537 return lport;
1538
1539shost_err:
1540 scsi_remove_host(shost);
1541lp_config_err:
1542 scsi_host_put(lport->host);
Bhanu Prakash Gollapudid36b3272011-05-27 11:47:27 -07001543free_blport:
1544 kfree(blport);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001545 return NULL;
1546}
1547
Bhanu Prakash Gollapudi013068f2011-08-30 15:54:52 -07001548static void bnx2fc_net_cleanup(struct bnx2fc_interface *interface)
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001549{
1550 /* Dont listen for Ethernet packets anymore */
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001551 __dev_remove_pack(&interface->fcoe_packet_type);
1552 __dev_remove_pack(&interface->fip_packet_type);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001553 synchronize_net();
1554}
1555
Bhanu Prakash Gollapudi776cebc2011-08-04 17:38:40 -07001556static void bnx2fc_interface_cleanup(struct bnx2fc_interface *interface)
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001557{
Robert Lovefd8f8902012-05-22 19:06:16 -07001558 struct fcoe_ctlr *ctlr = bnx2fc_to_ctlr(interface);
1559 struct fc_lport *lport = ctlr->lp;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001560 struct fcoe_port *port = lport_priv(lport);
Bhanu Prakash Gollapudi9be17fc2011-08-04 17:38:41 -07001561 struct bnx2fc_hba *hba = interface->hba;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001562
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001563 /* Stop the transmit retry timer */
1564 del_timer_sync(&port->timer);
1565
1566 /* Free existing transmit skbs */
1567 fcoe_clean_pending_queue(lport);
1568
Bhanu Prakash Gollapudi013068f2011-08-30 15:54:52 -07001569 bnx2fc_net_cleanup(interface);
Bhanu Prakash Gollapudi9be17fc2011-08-04 17:38:41 -07001570
Bhanu Prakash Gollapudiabc49a92011-08-04 17:38:42 -07001571 bnx2fc_free_vport(hba, lport);
Bhanu Prakash Gollapudi9be17fc2011-08-04 17:38:41 -07001572}
1573
1574static void bnx2fc_if_destroy(struct fc_lport *lport)
1575{
1576
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001577 /* Free queued packets for the receive thread */
1578 bnx2fc_clean_rx_queue(lport);
1579
1580 /* Detach from scsi-ml */
1581 fc_remove_host(lport->host);
1582 scsi_remove_host(lport->host);
1583
1584 /*
1585 * Note that only the physical lport will have the exchange manager.
1586 * for vports, this function is NOP
1587 */
1588 fc_exch_mgr_free(lport);
1589
1590 /* Free memory used by statistical counters */
1591 fc_lport_free_stats(lport);
1592
1593 /* Release Scsi_Host */
1594 scsi_host_put(lport->host);
1595}
1596
Bhanu Prakash Gollapudieccdcd02011-08-24 18:56:42 -07001597static void __bnx2fc_destroy(struct bnx2fc_interface *interface)
Bhanu Prakash Gollapudiabc49a92011-08-04 17:38:42 -07001598{
Robert Lovefd8f8902012-05-22 19:06:16 -07001599 struct fcoe_ctlr *ctlr = bnx2fc_to_ctlr(interface);
1600 struct fc_lport *lport = ctlr->lp;
Bhanu Prakash Gollapudi0cbf32e2011-08-30 15:54:51 -07001601 struct fcoe_port *port = lport_priv(lport);
Bhanu Prakash Gollapudiabc49a92011-08-04 17:38:42 -07001602
1603 bnx2fc_interface_cleanup(interface);
1604 bnx2fc_stop(interface);
Bhanu Prakash Gollapudiabc49a92011-08-04 17:38:42 -07001605 list_del(&interface->list);
Bhanu Prakash Gollapudiabc49a92011-08-04 17:38:42 -07001606 bnx2fc_interface_put(interface);
Bhanu Prakash Gollapudi0cbf32e2011-08-30 15:54:51 -07001607 queue_work(bnx2fc_wq, &port->destroy_work);
Bhanu Prakash Gollapudiabc49a92011-08-04 17:38:42 -07001608}
1609
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001610/**
1611 * bnx2fc_destroy - Destroy a bnx2fc FCoE interface
1612 *
1613 * @buffer: The name of the Ethernet interface to be destroyed
1614 * @kp: The associated kernel parameter
1615 *
1616 * Called from sysfs.
1617 *
1618 * Returns: 0 for success
1619 */
1620static int bnx2fc_destroy(struct net_device *netdev)
1621{
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001622 struct bnx2fc_interface *interface = NULL;
Bhanu Prakash Gollapudi2a7b29c2012-01-23 18:00:46 -08001623 struct workqueue_struct *timer_work_queue;
Robert Lovefd8f8902012-05-22 19:06:16 -07001624 struct fcoe_ctlr *ctlr;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001625 int rc = 0;
1626
Nithin Sujir6702ca12011-03-17 17:13:27 -07001627 rtnl_lock();
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001628 mutex_lock(&bnx2fc_dev_lock);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001629
1630 interface = bnx2fc_interface_lookup(netdev);
Robert Lovefd8f8902012-05-22 19:06:16 -07001631 ctlr = bnx2fc_to_ctlr(interface);
1632 if (!interface || !ctlr->lp) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001633 rc = -ENODEV;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001634 printk(KERN_ERR PFX "bnx2fc_destroy: interface or lport not found\n");
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001635 goto netdev_err;
1636 }
1637
Bhanu Prakash Gollapudi2a7b29c2012-01-23 18:00:46 -08001638 timer_work_queue = interface->timer_work_queue;
Bhanu Prakash Gollapudieccdcd02011-08-24 18:56:42 -07001639 __bnx2fc_destroy(interface);
Bhanu Prakash Gollapudi2a7b29c2012-01-23 18:00:46 -08001640 destroy_workqueue(timer_work_queue);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001641
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001642netdev_err:
1643 mutex_unlock(&bnx2fc_dev_lock);
1644 rtnl_unlock();
1645 return rc;
1646}
1647
1648static void bnx2fc_destroy_work(struct work_struct *work)
1649{
1650 struct fcoe_port *port;
1651 struct fc_lport *lport;
1652
1653 port = container_of(work, struct fcoe_port, destroy_work);
1654 lport = port->lport;
1655
1656 BNX2FC_HBA_DBG(lport, "Entered bnx2fc_destroy_work\n");
1657
Bhanu Prakash Gollapudi9be17fc2011-08-04 17:38:41 -07001658 bnx2fc_if_destroy(lport);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001659}
1660
1661static void bnx2fc_unbind_adapter_devices(struct bnx2fc_hba *hba)
1662{
1663 bnx2fc_free_fw_resc(hba);
1664 bnx2fc_free_task_ctx(hba);
1665}
1666
1667/**
1668 * bnx2fc_bind_adapter_devices - binds bnx2fc adapter with the associated
1669 * pci structure
1670 *
1671 * @hba: Adapter instance
1672 */
1673static int bnx2fc_bind_adapter_devices(struct bnx2fc_hba *hba)
1674{
1675 if (bnx2fc_setup_task_ctx(hba))
1676 goto mem_err;
1677
1678 if (bnx2fc_setup_fw_resc(hba))
1679 goto mem_err;
1680
1681 return 0;
1682mem_err:
1683 bnx2fc_unbind_adapter_devices(hba);
1684 return -ENOMEM;
1685}
1686
1687static int bnx2fc_bind_pcidev(struct bnx2fc_hba *hba)
1688{
1689 struct cnic_dev *cnic;
1690
1691 if (!hba->cnic) {
1692 printk(KERN_ERR PFX "cnic is NULL\n");
1693 return -ENODEV;
1694 }
1695 cnic = hba->cnic;
1696 hba->pcidev = cnic->pcidev;
1697 if (hba->pcidev)
1698 pci_dev_get(hba->pcidev);
1699
1700 return 0;
1701}
1702
1703static void bnx2fc_unbind_pcidev(struct bnx2fc_hba *hba)
1704{
1705 if (hba->pcidev)
1706 pci_dev_put(hba->pcidev);
1707 hba->pcidev = NULL;
1708}
1709
Barak Witkowski2e499d32012-06-26 01:31:19 +00001710/**
1711 * bnx2fc_ulp_get_stats - cnic callback to populate FCoE stats
1712 *
1713 * @handle: transport handle pointing to adapter struture
1714 */
1715static int bnx2fc_ulp_get_stats(void *handle)
1716{
1717 struct bnx2fc_hba *hba = handle;
1718 struct cnic_dev *cnic;
1719 struct fcoe_stats_info *stats_addr;
1720
1721 if (!hba)
1722 return -EINVAL;
1723
1724 cnic = hba->cnic;
1725 stats_addr = &cnic->stats_addr->fcoe_stat;
1726 if (!stats_addr)
1727 return -EINVAL;
1728
1729 strncpy(stats_addr->version, BNX2FC_VERSION,
1730 sizeof(stats_addr->version));
1731 stats_addr->txq_size = BNX2FC_SQ_WQES_MAX;
1732 stats_addr->rxq_size = BNX2FC_CQ_WQES_MAX;
1733
1734 return 0;
1735}
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001736
1737
1738/**
1739 * bnx2fc_ulp_start - cnic callback to initialize & start adapter instance
1740 *
Masanari Iida59e13d42012-04-25 00:24:16 +09001741 * @handle: transport handle pointing to adapter structure
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001742 *
1743 * This function maps adapter structure to pcidev structure and initiates
1744 * firmware handshake to enable/initialize on-chip FCoE components.
1745 * This bnx2fc - cnic interface api callback is used after following
1746 * conditions are met -
1747 * a) underlying network interface is up (marked by event NETDEV_UP
1748 * from netdev
1749 * b) bnx2fc adatper structure is registered.
1750 */
1751static void bnx2fc_ulp_start(void *handle)
1752{
1753 struct bnx2fc_hba *hba = handle;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001754 struct bnx2fc_interface *interface;
Robert Lovefd8f8902012-05-22 19:06:16 -07001755 struct fcoe_ctlr *ctlr;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001756 struct fc_lport *lport;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001757
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001758 mutex_lock(&bnx2fc_dev_lock);
1759
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001760 if (!test_bit(BNX2FC_FLAG_FW_INIT_DONE, &hba->flags))
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001761 bnx2fc_fw_init(hba);
1762
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001763 BNX2FC_MISC_DBG("bnx2fc started.\n");
1764
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001765 list_for_each_entry(interface, &if_list, list) {
1766 if (interface->hba == hba) {
Robert Lovefd8f8902012-05-22 19:06:16 -07001767 ctlr = bnx2fc_to_ctlr(interface);
1768 lport = ctlr->lp;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001769 /* Kick off Fabric discovery*/
1770 printk(KERN_ERR PFX "ulp_init: start discovery\n");
1771 lport->tt.frame_send = bnx2fc_xmit;
1772 bnx2fc_start_disc(interface);
1773 }
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001774 }
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001775
1776 mutex_unlock(&bnx2fc_dev_lock);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001777}
1778
1779static void bnx2fc_port_shutdown(struct fc_lport *lport)
1780{
1781 BNX2FC_MISC_DBG("Entered %s\n", __func__);
1782 fc_fabric_logoff(lport);
1783 fc_lport_destroy(lport);
1784}
1785
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001786static void bnx2fc_stop(struct bnx2fc_interface *interface)
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001787{
Robert Lovefd8f8902012-05-22 19:06:16 -07001788 struct fcoe_ctlr *ctlr = bnx2fc_to_ctlr(interface);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001789 struct fc_lport *lport;
1790 struct fc_lport *vport;
1791
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001792 if (!test_bit(BNX2FC_FLAG_FW_INIT_DONE, &interface->hba->flags))
1793 return;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001794
Robert Lovefd8f8902012-05-22 19:06:16 -07001795 lport = ctlr->lp;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001796 bnx2fc_port_shutdown(lport);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001797
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001798 mutex_lock(&lport->lp_mutex);
1799 list_for_each_entry(vport, &lport->vports, list)
1800 fc_host_port_type(vport->host) =
1801 FC_PORTTYPE_UNKNOWN;
1802 mutex_unlock(&lport->lp_mutex);
1803 fc_host_port_type(lport->host) = FC_PORTTYPE_UNKNOWN;
Robert Lovefd8f8902012-05-22 19:06:16 -07001804 fcoe_ctlr_link_down(ctlr);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001805 fcoe_clean_pending_queue(lport);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001806}
1807
1808static int bnx2fc_fw_init(struct bnx2fc_hba *hba)
1809{
1810#define BNX2FC_INIT_POLL_TIME (1000 / HZ)
1811 int rc = -1;
1812 int i = HZ;
1813
1814 rc = bnx2fc_bind_adapter_devices(hba);
1815 if (rc) {
1816 printk(KERN_ALERT PFX
1817 "bnx2fc_bind_adapter_devices failed - rc = %d\n", rc);
1818 goto err_out;
1819 }
1820
1821 rc = bnx2fc_send_fw_fcoe_init_msg(hba);
1822 if (rc) {
1823 printk(KERN_ALERT PFX
1824 "bnx2fc_send_fw_fcoe_init_msg failed - rc = %d\n", rc);
1825 goto err_unbind;
1826 }
1827
1828 /*
1829 * Wait until the adapter init message is complete, and adapter
1830 * state is UP.
1831 */
1832 while (!test_bit(ADAPTER_STATE_UP, &hba->adapter_state) && i--)
1833 msleep(BNX2FC_INIT_POLL_TIME);
1834
1835 if (!test_bit(ADAPTER_STATE_UP, &hba->adapter_state)) {
1836 printk(KERN_ERR PFX "bnx2fc_start: %s failed to initialize. "
1837 "Ignoring...\n",
1838 hba->cnic->netdev->name);
1839 rc = -1;
1840 goto err_unbind;
1841 }
1842
1843
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001844 set_bit(BNX2FC_FLAG_FW_INIT_DONE, &hba->flags);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001845 return 0;
1846
1847err_unbind:
1848 bnx2fc_unbind_adapter_devices(hba);
1849err_out:
1850 return rc;
1851}
1852
1853static void bnx2fc_fw_destroy(struct bnx2fc_hba *hba)
1854{
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001855 if (test_and_clear_bit(BNX2FC_FLAG_FW_INIT_DONE, &hba->flags)) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001856 if (bnx2fc_send_fw_fcoe_destroy_msg(hba) == 0) {
1857 init_timer(&hba->destroy_timer);
1858 hba->destroy_timer.expires = BNX2FC_FW_TIMEOUT +
1859 jiffies;
1860 hba->destroy_timer.function = bnx2fc_destroy_timer;
1861 hba->destroy_timer.data = (unsigned long)hba;
1862 add_timer(&hba->destroy_timer);
1863 wait_event_interruptible(hba->destroy_wait,
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001864 test_bit(BNX2FC_FLAG_DESTROY_CMPL,
1865 &hba->flags));
Bhanu Prakash Gollapudicd703ae2011-08-04 17:38:43 -07001866 clear_bit(BNX2FC_FLAG_DESTROY_CMPL, &hba->flags);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001867 /* This should never happen */
1868 if (signal_pending(current))
1869 flush_signals(current);
1870
1871 del_timer_sync(&hba->destroy_timer);
1872 }
1873 bnx2fc_unbind_adapter_devices(hba);
1874 }
1875}
1876
1877/**
1878 * bnx2fc_ulp_stop - cnic callback to shutdown adapter instance
1879 *
1880 * @handle: transport handle pointing to adapter structure
1881 *
1882 * Driver checks if adapter is already in shutdown mode, if not start
1883 * the shutdown process.
1884 */
1885static void bnx2fc_ulp_stop(void *handle)
1886{
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001887 struct bnx2fc_hba *hba = handle;
1888 struct bnx2fc_interface *interface;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001889
1890 printk(KERN_ERR "ULP_STOP\n");
1891
1892 mutex_lock(&bnx2fc_dev_lock);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001893 if (!test_bit(BNX2FC_FLAG_FW_INIT_DONE, &hba->flags))
1894 goto exit;
1895 list_for_each_entry(interface, &if_list, list) {
1896 if (interface->hba == hba)
1897 bnx2fc_stop(interface);
1898 }
1899 BUG_ON(hba->num_ofld_sess != 0);
1900
1901 mutex_lock(&hba->hba_mutex);
1902 clear_bit(ADAPTER_STATE_UP, &hba->adapter_state);
1903 clear_bit(ADAPTER_STATE_GOING_DOWN,
1904 &hba->adapter_state);
1905
1906 clear_bit(ADAPTER_STATE_READY, &hba->adapter_state);
1907 mutex_unlock(&hba->hba_mutex);
1908
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001909 bnx2fc_fw_destroy(hba);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001910exit:
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001911 mutex_unlock(&bnx2fc_dev_lock);
1912}
1913
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001914static void bnx2fc_start_disc(struct bnx2fc_interface *interface)
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001915{
Robert Lovefd8f8902012-05-22 19:06:16 -07001916 struct fcoe_ctlr *ctlr = bnx2fc_to_ctlr(interface);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001917 struct fc_lport *lport;
1918 int wait_cnt = 0;
1919
1920 BNX2FC_MISC_DBG("Entered %s\n", __func__);
1921 /* Kick off FIP/FLOGI */
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001922 if (!test_bit(BNX2FC_FLAG_FW_INIT_DONE, &interface->hba->flags)) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001923 printk(KERN_ERR PFX "Init not done yet\n");
1924 return;
1925 }
1926
Robert Lovefd8f8902012-05-22 19:06:16 -07001927 lport = ctlr->lp;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001928 BNX2FC_HBA_DBG(lport, "calling fc_fabric_login\n");
1929
Bhanu Prakash Gollapudi8a5badf2011-08-30 15:54:48 -07001930 if (!bnx2fc_link_ok(lport) && interface->enabled) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001931 BNX2FC_HBA_DBG(lport, "ctlr_link_up\n");
Robert Lovefd8f8902012-05-22 19:06:16 -07001932 fcoe_ctlr_link_up(ctlr);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001933 fc_host_port_type(lport->host) = FC_PORTTYPE_NPORT;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001934 set_bit(ADAPTER_STATE_READY, &interface->hba->adapter_state);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001935 }
1936
1937 /* wait for the FCF to be selected before issuing FLOGI */
Robert Lovefd8f8902012-05-22 19:06:16 -07001938 while (!ctlr->sel_fcf) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001939 msleep(250);
1940 /* give up after 3 secs */
1941 if (++wait_cnt > 12)
1942 break;
1943 }
Bhanu Prakash Gollapudi627e6282011-08-04 17:38:35 -07001944
1945 /* Reset max receive frame size to default */
1946 if (fc_set_mfs(lport, BNX2FC_MFS))
1947 return;
1948
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001949 fc_lport_init(lport);
1950 fc_fabric_login(lport);
1951}
1952
1953
1954/**
1955 * bnx2fc_ulp_init - Initialize an adapter instance
1956 *
1957 * @dev : cnic device handle
1958 * Called from cnic_register_driver() context to initialize all
1959 * enumerated cnic devices. This routine allocates adapter structure
1960 * and other device specific resources.
1961 */
1962static void bnx2fc_ulp_init(struct cnic_dev *dev)
1963{
1964 struct bnx2fc_hba *hba;
1965 int rc = 0;
1966
1967 BNX2FC_MISC_DBG("Entered %s\n", __func__);
1968 /* bnx2fc works only when bnx2x is loaded */
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001969 if (!test_bit(CNIC_F_BNX2X_CLASS, &dev->flags) ||
1970 (dev->max_fcoe_conn == 0)) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001971 printk(KERN_ERR PFX "bnx2fc FCoE not supported on %s,"
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001972 " flags: %lx fcoe_conn: %d\n",
1973 dev->netdev->name, dev->flags, dev->max_fcoe_conn);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001974 return;
1975 }
1976
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001977 hba = bnx2fc_hba_create(dev);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001978 if (!hba) {
1979 printk(KERN_ERR PFX "hba initialization failed\n");
1980 return;
1981 }
1982
1983 /* Add HBA to the adapter list */
1984 mutex_lock(&bnx2fc_dev_lock);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001985 list_add_tail(&hba->list, &adapter_list);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001986 adapter_count++;
1987 mutex_unlock(&bnx2fc_dev_lock);
1988
Barak Witkowski2e499d32012-06-26 01:31:19 +00001989 dev->fcoe_cap = &hba->fcoe_cap;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001990 clear_bit(BNX2FC_CNIC_REGISTERED, &hba->reg_with_cnic);
1991 rc = dev->register_device(dev, CNIC_ULP_FCOE,
1992 (void *) hba);
1993 if (rc)
Bhanu Prakash Gollapudib2a554f2011-06-27 23:30:53 -07001994 printk(KERN_ERR PFX "register_device failed, rc = %d\n", rc);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001995 else
1996 set_bit(BNX2FC_CNIC_REGISTERED, &hba->reg_with_cnic);
1997}
1998
1999
2000static int bnx2fc_disable(struct net_device *netdev)
2001{
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002002 struct bnx2fc_interface *interface;
Robert Lovefd8f8902012-05-22 19:06:16 -07002003 struct fcoe_ctlr *ctlr;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002004 int rc = 0;
2005
Nithin Sujir6702ca12011-03-17 17:13:27 -07002006 rtnl_lock();
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002007 mutex_lock(&bnx2fc_dev_lock);
2008
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002009 interface = bnx2fc_interface_lookup(netdev);
Robert Lovefd8f8902012-05-22 19:06:16 -07002010 ctlr = bnx2fc_to_ctlr(interface);
2011 if (!interface || !ctlr->lp) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002012 rc = -ENODEV;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002013 printk(KERN_ERR PFX "bnx2fc_disable: interface or lport not found\n");
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002014 } else {
Bhanu Prakash Gollapudi8a5badf2011-08-30 15:54:48 -07002015 interface->enabled = false;
Robert Lovefd8f8902012-05-22 19:06:16 -07002016 fcoe_ctlr_link_down(ctlr);
2017 fcoe_clean_pending_queue(ctlr->lp);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002018 }
2019
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002020 mutex_unlock(&bnx2fc_dev_lock);
2021 rtnl_unlock();
2022 return rc;
2023}
2024
2025
2026static int bnx2fc_enable(struct net_device *netdev)
2027{
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002028 struct bnx2fc_interface *interface;
Robert Lovefd8f8902012-05-22 19:06:16 -07002029 struct fcoe_ctlr *ctlr;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002030 int rc = 0;
2031
Nithin Sujir6702ca12011-03-17 17:13:27 -07002032 rtnl_lock();
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002033 mutex_lock(&bnx2fc_dev_lock);
2034
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002035 interface = bnx2fc_interface_lookup(netdev);
Robert Lovefd8f8902012-05-22 19:06:16 -07002036 ctlr = bnx2fc_to_ctlr(interface);
2037 if (!interface || !ctlr->lp) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002038 rc = -ENODEV;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002039 printk(KERN_ERR PFX "bnx2fc_enable: interface or lport not found\n");
Robert Lovefd8f8902012-05-22 19:06:16 -07002040 } else if (!bnx2fc_link_ok(ctlr->lp)) {
2041 fcoe_ctlr_link_up(ctlr);
Bhanu Prakash Gollapudi8a5badf2011-08-30 15:54:48 -07002042 interface->enabled = true;
2043 }
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002044
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002045 mutex_unlock(&bnx2fc_dev_lock);
2046 rtnl_unlock();
2047 return rc;
2048}
2049
2050/**
2051 * bnx2fc_create - Create bnx2fc FCoE interface
2052 *
2053 * @buffer: The name of Ethernet interface to create on
2054 * @kp: The associated kernel param
2055 *
2056 * Called from sysfs.
2057 *
2058 * Returns: 0 for success
2059 */
2060static int bnx2fc_create(struct net_device *netdev, enum fip_state fip_mode)
2061{
Robert Lovefd8f8902012-05-22 19:06:16 -07002062 struct fcoe_ctlr *ctlr;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002063 struct bnx2fc_interface *interface;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002064 struct bnx2fc_hba *hba;
Bhanu Prakash Gollapudi7adc5a32012-06-04 16:15:44 -07002065 struct net_device *phys_dev = netdev;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002066 struct fc_lport *lport;
2067 struct ethtool_drvinfo drvinfo;
2068 int rc = 0;
Bhanu Prakash Gollapudi7adc5a32012-06-04 16:15:44 -07002069 int vlan_id = 0;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002070
2071 BNX2FC_MISC_DBG("Entered bnx2fc_create\n");
2072 if (fip_mode != FIP_MODE_FABRIC) {
2073 printk(KERN_ERR "fip mode not FABRIC\n");
2074 return -EIO;
2075 }
2076
Nithin Sujir6702ca12011-03-17 17:13:27 -07002077 rtnl_lock();
2078
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002079 mutex_lock(&bnx2fc_dev_lock);
2080
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002081 if (!try_module_get(THIS_MODULE)) {
2082 rc = -EINVAL;
2083 goto mod_err;
2084 }
2085
2086 /* obtain physical netdev */
Bhanu Prakash Gollapudi7adc5a32012-06-04 16:15:44 -07002087 if (netdev->priv_flags & IFF_802_1Q_VLAN)
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002088 phys_dev = vlan_dev_real_dev(netdev);
Bhanu Prakash Gollapudi7adc5a32012-06-04 16:15:44 -07002089
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002090 /* verify if the physical device is a netxtreme2 device */
2091 if (phys_dev->ethtool_ops && phys_dev->ethtool_ops->get_drvinfo) {
2092 memset(&drvinfo, 0, sizeof(drvinfo));
2093 phys_dev->ethtool_ops->get_drvinfo(phys_dev, &drvinfo);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002094 if (strncmp(drvinfo.driver, "bnx2x", strlen("bnx2x"))) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002095 printk(KERN_ERR PFX "Not a netxtreme2 device\n");
2096 rc = -EINVAL;
2097 goto netdev_err;
2098 }
2099 } else {
2100 printk(KERN_ERR PFX "unable to obtain drv_info\n");
2101 rc = -EINVAL;
2102 goto netdev_err;
2103 }
2104
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002105 /* obtain interface and initialize rest of the structure */
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002106 hba = bnx2fc_hba_lookup(phys_dev);
2107 if (!hba) {
2108 rc = -ENODEV;
2109 printk(KERN_ERR PFX "bnx2fc_create: hba not found\n");
2110 goto netdev_err;
2111 }
2112
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002113 if (bnx2fc_interface_lookup(netdev)) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002114 rc = -EEXIST;
2115 goto netdev_err;
2116 }
2117
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002118 interface = bnx2fc_interface_create(hba, netdev, fip_mode);
2119 if (!interface) {
2120 printk(KERN_ERR PFX "bnx2fc_interface_create failed\n");
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002121 goto ifput_err;
2122 }
2123
Bhanu Prakash Gollapudi7adc5a32012-06-04 16:15:44 -07002124 if (netdev->priv_flags & IFF_802_1Q_VLAN) {
2125 vlan_id = vlan_dev_vlan_id(netdev);
2126 interface->vlan_enabled = 1;
2127 }
2128
Robert Lovefd8f8902012-05-22 19:06:16 -07002129 ctlr = bnx2fc_to_ctlr(interface);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002130 interface->vlan_id = vlan_id;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002131
2132 interface->timer_work_queue =
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002133 create_singlethread_workqueue("bnx2fc_timer_wq");
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002134 if (!interface->timer_work_queue) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002135 printk(KERN_ERR PFX "ulp_init could not create timer_wq\n");
2136 rc = -EINVAL;
2137 goto ifput_err;
2138 }
2139
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002140 lport = bnx2fc_if_create(interface, &interface->hba->pcidev->dev, 0);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002141 if (!lport) {
2142 printk(KERN_ERR PFX "Failed to create interface (%s)\n",
2143 netdev->name);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002144 rc = -EINVAL;
2145 goto if_create_err;
2146 }
2147
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002148 /* Add interface to if_list */
2149 list_add_tail(&interface->list, &if_list);
2150
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002151 lport->boot_time = jiffies;
2152
2153 /* Make this master N_port */
Robert Lovefd8f8902012-05-22 19:06:16 -07002154 ctlr->lp = lport;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002155
Bhanu Prakash Gollapudi8a5badf2011-08-30 15:54:48 -07002156 if (!bnx2fc_link_ok(lport)) {
Robert Lovefd8f8902012-05-22 19:06:16 -07002157 fcoe_ctlr_link_up(ctlr);
Bhanu Prakash Gollapudi8a5badf2011-08-30 15:54:48 -07002158 fc_host_port_type(lport->host) = FC_PORTTYPE_NPORT;
2159 set_bit(ADAPTER_STATE_READY, &interface->hba->adapter_state);
2160 }
2161
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002162 BNX2FC_HBA_DBG(lport, "create: START DISC\n");
2163 bnx2fc_start_disc(interface);
Bhanu Prakash Gollapudi8a5badf2011-08-30 15:54:48 -07002164 interface->enabled = true;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002165 /*
2166 * Release from kref_init in bnx2fc_interface_setup, on success
2167 * lport should be holding a reference taken in bnx2fc_if_create
2168 */
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002169 bnx2fc_interface_put(interface);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002170 /* put netdev that was held while calling dev_get_by_name */
2171 mutex_unlock(&bnx2fc_dev_lock);
2172 rtnl_unlock();
2173 return 0;
2174
2175if_create_err:
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002176 destroy_workqueue(interface->timer_work_queue);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002177ifput_err:
Bhanu Prakash Gollapudi013068f2011-08-30 15:54:52 -07002178 bnx2fc_net_cleanup(interface);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002179 bnx2fc_interface_put(interface);
Bhanu Prakash Gollapudi7d742f62012-01-23 18:00:48 -08002180 goto mod_err;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002181netdev_err:
2182 module_put(THIS_MODULE);
2183mod_err:
2184 mutex_unlock(&bnx2fc_dev_lock);
2185 rtnl_unlock();
2186 return rc;
2187}
2188
2189/**
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002190 * bnx2fc_find_hba_for_cnic - maps cnic instance to bnx2fc hba instance
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002191 *
2192 * @cnic: Pointer to cnic device instance
2193 *
2194 **/
2195static struct bnx2fc_hba *bnx2fc_find_hba_for_cnic(struct cnic_dev *cnic)
2196{
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002197 struct bnx2fc_hba *hba;
2198
2199 /* Called with bnx2fc_dev_lock held */
Bhanu Prakash Gollapudid71fb3b2012-06-07 02:19:36 -07002200 list_for_each_entry(hba, &adapter_list, list) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002201 if (hba->cnic == cnic)
2202 return hba;
2203 }
2204 return NULL;
2205}
2206
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002207static struct bnx2fc_interface *bnx2fc_interface_lookup(struct net_device
2208 *netdev)
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002209{
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002210 struct bnx2fc_interface *interface;
2211
2212 /* Called with bnx2fc_dev_lock held */
2213 list_for_each_entry(interface, &if_list, list) {
2214 if (interface->netdev == netdev)
2215 return interface;
2216 }
2217 return NULL;
2218}
2219
2220static struct bnx2fc_hba *bnx2fc_hba_lookup(struct net_device
2221 *phys_dev)
2222{
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002223 struct bnx2fc_hba *hba;
2224
2225 /* Called with bnx2fc_dev_lock held */
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002226 list_for_each_entry(hba, &adapter_list, list) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002227 if (hba->phys_dev == phys_dev)
2228 return hba;
2229 }
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002230 printk(KERN_ERR PFX "adapter_lookup: hba NULL\n");
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002231 return NULL;
2232}
2233
2234/**
2235 * bnx2fc_ulp_exit - shuts down adapter instance and frees all resources
2236 *
2237 * @dev cnic device handle
2238 */
2239static void bnx2fc_ulp_exit(struct cnic_dev *dev)
2240{
2241 struct bnx2fc_hba *hba;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002242 struct bnx2fc_interface *interface, *tmp;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002243
2244 BNX2FC_MISC_DBG("Entered bnx2fc_ulp_exit\n");
2245
2246 if (!test_bit(CNIC_F_BNX2X_CLASS, &dev->flags)) {
2247 printk(KERN_ERR PFX "bnx2fc port check: %s, flags: %lx\n",
2248 dev->netdev->name, dev->flags);
2249 return;
2250 }
2251
2252 mutex_lock(&bnx2fc_dev_lock);
2253 hba = bnx2fc_find_hba_for_cnic(dev);
2254 if (!hba) {
2255 printk(KERN_ERR PFX "bnx2fc_ulp_exit: hba not found, dev 0%p\n",
2256 dev);
2257 mutex_unlock(&bnx2fc_dev_lock);
2258 return;
2259 }
2260
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002261 list_del_init(&hba->list);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002262 adapter_count--;
2263
Bhanu Prakash Gollapudiabc49a92011-08-04 17:38:42 -07002264 list_for_each_entry_safe(interface, tmp, &if_list, list)
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002265 /* destroy not called yet, move to quiesced list */
Bhanu Prakash Gollapudiabc49a92011-08-04 17:38:42 -07002266 if (interface->hba == hba)
Bhanu Prakash Gollapudieccdcd02011-08-24 18:56:42 -07002267 __bnx2fc_destroy(interface);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002268 mutex_unlock(&bnx2fc_dev_lock);
2269
2270 bnx2fc_ulp_stop(hba);
2271 /* unregister cnic device */
2272 if (test_and_clear_bit(BNX2FC_CNIC_REGISTERED, &hba->reg_with_cnic))
2273 hba->cnic->unregister_device(hba->cnic, CNIC_ULP_FCOE);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002274 bnx2fc_hba_destroy(hba);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002275}
2276
2277/**
2278 * bnx2fc_fcoe_reset - Resets the fcoe
2279 *
2280 * @shost: shost the reset is from
2281 *
2282 * Returns: always 0
2283 */
2284static int bnx2fc_fcoe_reset(struct Scsi_Host *shost)
2285{
2286 struct fc_lport *lport = shost_priv(shost);
2287 fc_lport_reset(lport);
2288 return 0;
2289}
2290
2291
2292static bool bnx2fc_match(struct net_device *netdev)
2293{
Bhanu Prakash Gollapudi7adc5a32012-06-04 16:15:44 -07002294 struct net_device *phys_dev = netdev;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002295
Bhanu Prakash Gollapudi7adc5a32012-06-04 16:15:44 -07002296 mutex_lock(&bnx2fc_dev_lock);
2297 if (netdev->priv_flags & IFF_802_1Q_VLAN)
2298 phys_dev = vlan_dev_real_dev(netdev);
2299
2300 if (bnx2fc_hba_lookup(phys_dev)) {
2301 mutex_unlock(&bnx2fc_dev_lock);
2302 return true;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002303 }
Bhanu Prakash Gollapudi7adc5a32012-06-04 16:15:44 -07002304
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002305 mutex_unlock(&bnx2fc_dev_lock);
2306 return false;
2307}
2308
2309
2310static struct fcoe_transport bnx2fc_transport = {
2311 .name = {"bnx2fc"},
2312 .attached = false,
2313 .list = LIST_HEAD_INIT(bnx2fc_transport.list),
2314 .match = bnx2fc_match,
2315 .create = bnx2fc_create,
2316 .destroy = bnx2fc_destroy,
2317 .enable = bnx2fc_enable,
2318 .disable = bnx2fc_disable,
2319};
2320
2321/**
2322 * bnx2fc_percpu_thread_create - Create a receive thread for an
2323 * online CPU
2324 *
2325 * @cpu: cpu index for the online cpu
2326 */
2327static void bnx2fc_percpu_thread_create(unsigned int cpu)
2328{
2329 struct bnx2fc_percpu_s *p;
2330 struct task_struct *thread;
2331
2332 p = &per_cpu(bnx2fc_percpu, cpu);
2333
Eric Dumazet69614272012-06-04 16:15:42 -07002334 thread = kthread_create_on_node(bnx2fc_percpu_io_thread,
2335 (void *)p, cpu_to_node(cpu),
2336 "bnx2fc_thread/%d", cpu);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002337 /* bind thread to the cpu */
Bhanu Prakash Gollapudi32248762011-08-04 17:38:36 -07002338 if (likely(!IS_ERR(thread))) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002339 kthread_bind(thread, cpu);
2340 p->iothread = thread;
2341 wake_up_process(thread);
2342 }
2343}
2344
2345static void bnx2fc_percpu_thread_destroy(unsigned int cpu)
2346{
2347 struct bnx2fc_percpu_s *p;
2348 struct task_struct *thread;
2349 struct bnx2fc_work *work, *tmp;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002350
2351 BNX2FC_MISC_DBG("destroying io thread for CPU %d\n", cpu);
2352
2353 /* Prevent any new work from being queued for this CPU */
2354 p = &per_cpu(bnx2fc_percpu, cpu);
2355 spin_lock_bh(&p->fp_work_lock);
2356 thread = p->iothread;
2357 p->iothread = NULL;
2358
2359
2360 /* Free all work in the list */
Bhanu Prakash Gollapudi32248762011-08-04 17:38:36 -07002361 list_for_each_entry_safe(work, tmp, &p->work_list, list) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002362 list_del_init(&work->list);
2363 bnx2fc_process_cq_compl(work->tgt, work->wqe);
2364 kfree(work);
2365 }
2366
2367 spin_unlock_bh(&p->fp_work_lock);
2368
2369 if (thread)
2370 kthread_stop(thread);
2371}
2372
2373/**
2374 * bnx2fc_cpu_callback - Handler for CPU hotplug events
2375 *
2376 * @nfb: The callback data block
2377 * @action: The event triggering the callback
2378 * @hcpu: The index of the CPU that the event is for
2379 *
2380 * This creates or destroys per-CPU data for fcoe
2381 *
2382 * Returns NOTIFY_OK always.
2383 */
2384static int bnx2fc_cpu_callback(struct notifier_block *nfb,
2385 unsigned long action, void *hcpu)
2386{
2387 unsigned cpu = (unsigned long)hcpu;
2388
2389 switch (action) {
2390 case CPU_ONLINE:
2391 case CPU_ONLINE_FROZEN:
2392 printk(PFX "CPU %x online: Create Rx thread\n", cpu);
2393 bnx2fc_percpu_thread_create(cpu);
2394 break;
2395 case CPU_DEAD:
2396 case CPU_DEAD_FROZEN:
2397 printk(PFX "CPU %x offline: Remove Rx thread\n", cpu);
2398 bnx2fc_percpu_thread_destroy(cpu);
2399 break;
2400 default:
2401 break;
2402 }
2403 return NOTIFY_OK;
2404}
2405
2406/**
2407 * bnx2fc_mod_init - module init entry point
2408 *
2409 * Initialize driver wide global data structures, and register
2410 * with cnic module
2411 **/
2412static int __init bnx2fc_mod_init(void)
2413{
2414 struct fcoe_percpu_s *bg;
2415 struct task_struct *l2_thread;
2416 int rc = 0;
2417 unsigned int cpu = 0;
2418 struct bnx2fc_percpu_s *p;
2419
2420 printk(KERN_INFO PFX "%s", version);
2421
2422 /* register as a fcoe transport */
2423 rc = fcoe_transport_attach(&bnx2fc_transport);
2424 if (rc) {
2425 printk(KERN_ERR "failed to register an fcoe transport, check "
2426 "if libfcoe is loaded\n");
2427 goto out;
2428 }
2429
2430 INIT_LIST_HEAD(&adapter_list);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002431 INIT_LIST_HEAD(&if_list);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002432 mutex_init(&bnx2fc_dev_lock);
2433 adapter_count = 0;
2434
2435 /* Attach FC transport template */
2436 rc = bnx2fc_attach_transport();
2437 if (rc)
2438 goto detach_ft;
2439
2440 bnx2fc_wq = alloc_workqueue("bnx2fc", 0, 0);
2441 if (!bnx2fc_wq) {
2442 rc = -ENOMEM;
2443 goto release_bt;
2444 }
2445
2446 bg = &bnx2fc_global;
2447 skb_queue_head_init(&bg->fcoe_rx_list);
2448 l2_thread = kthread_create(bnx2fc_l2_rcv_thread,
2449 (void *)bg,
2450 "bnx2fc_l2_thread");
2451 if (IS_ERR(l2_thread)) {
2452 rc = PTR_ERR(l2_thread);
2453 goto free_wq;
2454 }
2455 wake_up_process(l2_thread);
2456 spin_lock_bh(&bg->fcoe_rx_list.lock);
2457 bg->thread = l2_thread;
2458 spin_unlock_bh(&bg->fcoe_rx_list.lock);
2459
2460 for_each_possible_cpu(cpu) {
2461 p = &per_cpu(bnx2fc_percpu, cpu);
2462 INIT_LIST_HEAD(&p->work_list);
2463 spin_lock_init(&p->fp_work_lock);
2464 }
2465
2466 for_each_online_cpu(cpu) {
2467 bnx2fc_percpu_thread_create(cpu);
2468 }
2469
2470 /* Initialize per CPU interrupt thread */
2471 register_hotcpu_notifier(&bnx2fc_cpu_notifier);
2472
2473 cnic_register_driver(CNIC_ULP_FCOE, &bnx2fc_cnic_cb);
2474
2475 return 0;
2476
2477free_wq:
2478 destroy_workqueue(bnx2fc_wq);
2479release_bt:
2480 bnx2fc_release_transport();
2481detach_ft:
2482 fcoe_transport_detach(&bnx2fc_transport);
2483out:
2484 return rc;
2485}
2486
2487static void __exit bnx2fc_mod_exit(void)
2488{
2489 LIST_HEAD(to_be_deleted);
2490 struct bnx2fc_hba *hba, *next;
2491 struct fcoe_percpu_s *bg;
2492 struct task_struct *l2_thread;
2493 struct sk_buff *skb;
2494 unsigned int cpu = 0;
2495
2496 /*
2497 * NOTE: Since cnic calls register_driver routine rtnl_lock,
2498 * it will have higher precedence than bnx2fc_dev_lock.
2499 * unregister_device() cannot be called with bnx2fc_dev_lock
2500 * held.
2501 */
2502 mutex_lock(&bnx2fc_dev_lock);
2503 list_splice(&adapter_list, &to_be_deleted);
2504 INIT_LIST_HEAD(&adapter_list);
2505 adapter_count = 0;
2506 mutex_unlock(&bnx2fc_dev_lock);
2507
2508 /* Unregister with cnic */
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002509 list_for_each_entry_safe(hba, next, &to_be_deleted, list) {
2510 list_del_init(&hba->list);
2511 printk(KERN_ERR PFX "MOD_EXIT:destroy hba = 0x%p\n",
2512 hba);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002513 bnx2fc_ulp_stop(hba);
2514 /* unregister cnic device */
2515 if (test_and_clear_bit(BNX2FC_CNIC_REGISTERED,
2516 &hba->reg_with_cnic))
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002517 hba->cnic->unregister_device(hba->cnic,
2518 CNIC_ULP_FCOE);
2519 bnx2fc_hba_destroy(hba);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002520 }
2521 cnic_unregister_driver(CNIC_ULP_FCOE);
2522
2523 /* Destroy global thread */
2524 bg = &bnx2fc_global;
2525 spin_lock_bh(&bg->fcoe_rx_list.lock);
2526 l2_thread = bg->thread;
2527 bg->thread = NULL;
2528 while ((skb = __skb_dequeue(&bg->fcoe_rx_list)) != NULL)
2529 kfree_skb(skb);
2530
2531 spin_unlock_bh(&bg->fcoe_rx_list.lock);
2532
2533 if (l2_thread)
2534 kthread_stop(l2_thread);
2535
2536 unregister_hotcpu_notifier(&bnx2fc_cpu_notifier);
2537
2538 /* Destroy per cpu threads */
2539 for_each_online_cpu(cpu) {
2540 bnx2fc_percpu_thread_destroy(cpu);
2541 }
2542
2543 destroy_workqueue(bnx2fc_wq);
2544 /*
2545 * detach from scsi transport
2546 * must happen after all destroys are done
2547 */
2548 bnx2fc_release_transport();
2549
2550 /* detach from fcoe transport */
2551 fcoe_transport_detach(&bnx2fc_transport);
2552}
2553
2554module_init(bnx2fc_mod_init);
2555module_exit(bnx2fc_mod_exit);
2556
Robert Love8d55e502012-05-22 19:06:26 -07002557static struct fcoe_sysfs_function_template bnx2fc_fcoe_sysfs_templ = {
2558 .get_fcoe_ctlr_mode = fcoe_ctlr_get_fip_mode,
2559 .get_fcoe_ctlr_link_fail = bnx2fc_ctlr_get_lesb,
2560 .get_fcoe_ctlr_vlink_fail = bnx2fc_ctlr_get_lesb,
2561 .get_fcoe_ctlr_miss_fka = bnx2fc_ctlr_get_lesb,
2562 .get_fcoe_ctlr_symb_err = bnx2fc_ctlr_get_lesb,
2563 .get_fcoe_ctlr_err_block = bnx2fc_ctlr_get_lesb,
2564 .get_fcoe_ctlr_fcs_error = bnx2fc_ctlr_get_lesb,
2565
2566 .get_fcoe_fcf_selected = fcoe_fcf_get_selected,
2567 .get_fcoe_fcf_vlan_id = bnx2fc_fcf_get_vlan_id,
2568};
2569
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002570static struct fc_function_template bnx2fc_transport_function = {
2571 .show_host_node_name = 1,
2572 .show_host_port_name = 1,
2573 .show_host_supported_classes = 1,
2574 .show_host_supported_fc4s = 1,
2575 .show_host_active_fc4s = 1,
2576 .show_host_maxframe_size = 1,
2577
2578 .show_host_port_id = 1,
2579 .show_host_supported_speeds = 1,
2580 .get_host_speed = fc_get_host_speed,
2581 .show_host_speed = 1,
2582 .show_host_port_type = 1,
2583 .get_host_port_state = fc_get_host_port_state,
2584 .show_host_port_state = 1,
2585 .show_host_symbolic_name = 1,
2586
2587 .dd_fcrport_size = (sizeof(struct fc_rport_libfc_priv) +
2588 sizeof(struct bnx2fc_rport)),
2589 .show_rport_maxframe_size = 1,
2590 .show_rport_supported_classes = 1,
2591
2592 .show_host_fabric_name = 1,
2593 .show_starget_node_name = 1,
2594 .show_starget_port_name = 1,
2595 .show_starget_port_id = 1,
2596 .set_rport_dev_loss_tmo = fc_set_rport_loss_tmo,
2597 .show_rport_dev_loss_tmo = 1,
2598 .get_fc_host_stats = bnx2fc_get_host_stats,
2599
2600 .issue_fc_host_lip = bnx2fc_fcoe_reset,
2601
2602 .terminate_rport_io = fc_rport_terminate_io,
2603
2604 .vport_create = bnx2fc_vport_create,
2605 .vport_delete = bnx2fc_vport_destroy,
2606 .vport_disable = bnx2fc_vport_disable,
Bhanu Prakash Gollapudie9a5289c2011-08-04 17:38:37 -07002607 .bsg_request = fc_lport_bsg_request,
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002608};
2609
2610static struct fc_function_template bnx2fc_vport_xport_function = {
2611 .show_host_node_name = 1,
2612 .show_host_port_name = 1,
2613 .show_host_supported_classes = 1,
2614 .show_host_supported_fc4s = 1,
2615 .show_host_active_fc4s = 1,
2616 .show_host_maxframe_size = 1,
2617
2618 .show_host_port_id = 1,
2619 .show_host_supported_speeds = 1,
2620 .get_host_speed = fc_get_host_speed,
2621 .show_host_speed = 1,
2622 .show_host_port_type = 1,
2623 .get_host_port_state = fc_get_host_port_state,
2624 .show_host_port_state = 1,
2625 .show_host_symbolic_name = 1,
2626
2627 .dd_fcrport_size = (sizeof(struct fc_rport_libfc_priv) +
2628 sizeof(struct bnx2fc_rport)),
2629 .show_rport_maxframe_size = 1,
2630 .show_rport_supported_classes = 1,
2631
2632 .show_host_fabric_name = 1,
2633 .show_starget_node_name = 1,
2634 .show_starget_port_name = 1,
2635 .show_starget_port_id = 1,
2636 .set_rport_dev_loss_tmo = fc_set_rport_loss_tmo,
2637 .show_rport_dev_loss_tmo = 1,
2638 .get_fc_host_stats = fc_get_host_stats,
2639 .issue_fc_host_lip = bnx2fc_fcoe_reset,
2640 .terminate_rport_io = fc_rport_terminate_io,
Bhanu Prakash Gollapudie9a5289c2011-08-04 17:38:37 -07002641 .bsg_request = fc_lport_bsg_request,
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002642};
2643
2644/**
2645 * scsi_host_template structure used while registering with SCSI-ml
2646 */
2647static struct scsi_host_template bnx2fc_shost_template = {
2648 .module = THIS_MODULE,
2649 .name = "Broadcom Offload FCoE Initiator",
2650 .queuecommand = bnx2fc_queuecommand,
2651 .eh_abort_handler = bnx2fc_eh_abort, /* abts */
2652 .eh_device_reset_handler = bnx2fc_eh_device_reset, /* lun reset */
2653 .eh_target_reset_handler = bnx2fc_eh_target_reset, /* tgt reset */
2654 .eh_host_reset_handler = fc_eh_host_reset,
2655 .slave_alloc = fc_slave_alloc,
2656 .change_queue_depth = fc_change_queue_depth,
2657 .change_queue_type = fc_change_queue_type,
2658 .this_id = -1,
2659 .cmd_per_lun = 3,
Bhanu Gollapudi0ea5c272011-03-17 17:13:29 -07002660 .can_queue = BNX2FC_CAN_QUEUE,
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002661 .use_clustering = ENABLE_CLUSTERING,
2662 .sg_tablesize = BNX2FC_MAX_BDS_PER_CMD,
2663 .max_sectors = 512,
2664};
2665
2666static struct libfc_function_template bnx2fc_libfc_fcn_templ = {
2667 .frame_send = bnx2fc_xmit,
2668 .elsct_send = bnx2fc_elsct_send,
2669 .fcp_abort_io = bnx2fc_abort_io,
2670 .fcp_cleanup = bnx2fc_cleanup,
Bhanu Prakash Gollapudif72f6972011-10-03 16:45:02 -07002671 .get_lesb = bnx2fc_get_lesb,
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002672 .rport_event_callback = bnx2fc_rport_event_handler,
2673};
2674
2675/**
2676 * bnx2fc_cnic_cb - global template of bnx2fc - cnic driver interface
2677 * structure carrying callback function pointers
2678 */
2679static struct cnic_ulp_ops bnx2fc_cnic_cb = {
2680 .owner = THIS_MODULE,
2681 .cnic_init = bnx2fc_ulp_init,
2682 .cnic_exit = bnx2fc_ulp_exit,
2683 .cnic_start = bnx2fc_ulp_start,
2684 .cnic_stop = bnx2fc_ulp_stop,
2685 .indicate_kcqes = bnx2fc_indicate_kcqe,
2686 .indicate_netevent = bnx2fc_indicate_netevent,
Barak Witkowski2e499d32012-06-26 01:31:19 +00002687 .cnic_get_stats = bnx2fc_ulp_get_stats,
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002688};