blob: e9d49bd7a6944249cd83270844367074b519dd17 [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
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080028static char version[] =
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -080029 "Broadcom NetXtreme II FCoE Driver " DRV_MODULE_NAME \
30 " v" DRV_MODULE_VERSION " (" DRV_MODULE_RELDATE ")\n";
31
32
33MODULE_AUTHOR("Bhanu Prakash Gollapudi <bprakash@broadcom.com>");
34MODULE_DESCRIPTION("Broadcom NetXtreme II BCM57710 FCoE Driver");
35MODULE_LICENSE("GPL");
36MODULE_VERSION(DRV_MODULE_VERSION);
37
38#define BNX2FC_MAX_QUEUE_DEPTH 256
39#define BNX2FC_MIN_QUEUE_DEPTH 32
40#define FCOE_WORD_TO_BYTE 4
41
42static struct scsi_transport_template *bnx2fc_transport_template;
43static struct scsi_transport_template *bnx2fc_vport_xport_template;
44
45struct workqueue_struct *bnx2fc_wq;
46
47/* bnx2fc structure needs only one instance of the fcoe_percpu_s structure.
48 * Here the io threads are per cpu but the l2 thread is just one
49 */
50struct fcoe_percpu_s bnx2fc_global;
51DEFINE_SPINLOCK(bnx2fc_global_lock);
52
53static struct cnic_ulp_ops bnx2fc_cnic_cb;
54static struct libfc_function_template bnx2fc_libfc_fcn_templ;
55static struct scsi_host_template bnx2fc_shost_template;
56static struct fc_function_template bnx2fc_transport_function;
Robert Love8d55e502012-05-22 19:06:26 -070057static struct fcoe_sysfs_function_template bnx2fc_fcoe_sysfs_templ;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -080058static struct fc_function_template bnx2fc_vport_xport_function;
59static int bnx2fc_create(struct net_device *netdev, enum fip_state fip_mode);
Bhanu Prakash Gollapudieccdcd02011-08-24 18:56:42 -070060static void __bnx2fc_destroy(struct bnx2fc_interface *interface);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -080061static int bnx2fc_destroy(struct net_device *net_device);
62static int bnx2fc_enable(struct net_device *netdev);
63static int bnx2fc_disable(struct net_device *netdev);
64
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 }
Bhanu Prakash Gollapudif246fe22012-12-21 19:40:32 -0800690 BNX2FC_STATS(hba, rx_stat2, fc_crc_cnt);
691 bnx2fc_stats->invalid_crc_count += hba->bfw_stats.fc_crc_cnt;
692 BNX2FC_STATS(hba, tx_stat, fcoe_tx_pkt_cnt);
693 bnx2fc_stats->tx_frames += hba->bfw_stats.fcoe_tx_pkt_cnt;
694 BNX2FC_STATS(hba, tx_stat, fcoe_tx_byte_cnt);
695 bnx2fc_stats->tx_words += ((hba->bfw_stats.fcoe_tx_byte_cnt) / 4);
696 BNX2FC_STATS(hba, rx_stat0, fcoe_rx_pkt_cnt);
697 bnx2fc_stats->rx_frames += hba->bfw_stats.fcoe_rx_pkt_cnt;
698 BNX2FC_STATS(hba, rx_stat0, fcoe_rx_byte_cnt);
699 bnx2fc_stats->rx_words += ((hba->bfw_stats.fcoe_rx_byte_cnt) / 4);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800700
701 bnx2fc_stats->dumped_frames = 0;
702 bnx2fc_stats->lip_count = 0;
703 bnx2fc_stats->nos_count = 0;
704 bnx2fc_stats->loss_of_sync_count = 0;
705 bnx2fc_stats->loss_of_signal_count = 0;
706 bnx2fc_stats->prim_seq_protocol_err_count = 0;
707
Bhanu Prakash Gollapudif246fe22012-12-21 19:40:32 -0800708 memcpy(&hba->prev_stats, hba->stats_buffer,
709 sizeof(struct fcoe_statistics_params));
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800710 return bnx2fc_stats;
711}
712
713static int bnx2fc_shost_config(struct fc_lport *lport, struct device *dev)
714{
715 struct fcoe_port *port = lport_priv(lport);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700716 struct bnx2fc_interface *interface = port->priv;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800717 struct Scsi_Host *shost = lport->host;
718 int rc = 0;
719
720 shost->max_cmd_len = BNX2FC_MAX_CMD_LEN;
721 shost->max_lun = BNX2FC_MAX_LUN;
722 shost->max_id = BNX2FC_MAX_FCP_TGT;
723 shost->max_channel = 0;
724 if (lport->vport)
725 shost->transportt = bnx2fc_vport_xport_template;
726 else
727 shost->transportt = bnx2fc_transport_template;
728
729 /* Add the new host to SCSI-ml */
730 rc = scsi_add_host(lport->host, dev);
731 if (rc) {
732 printk(KERN_ERR PFX "Error on scsi_add_host\n");
733 return rc;
734 }
735 if (!lport->vport)
736 fc_host_max_npiv_vports(lport->host) = USHRT_MAX;
737 sprintf(fc_host_symbolic_name(lport->host), "%s v%s over %s",
738 BNX2FC_NAME, BNX2FC_VERSION,
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700739 interface->netdev->name);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800740
741 return 0;
742}
743
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800744static void bnx2fc_link_speed_update(struct fc_lport *lport)
745{
746 struct fcoe_port *port = lport_priv(lport);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700747 struct bnx2fc_interface *interface = port->priv;
748 struct net_device *netdev = interface->netdev;
David Decotigny8ae6dac2011-04-27 18:32:38 +0000749 struct ethtool_cmd ecmd;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800750
Jiri Pirko4bc71cb2011-09-03 03:34:30 +0000751 if (!__ethtool_get_settings(netdev, &ecmd)) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800752 lport->link_supported_speeds &=
753 ~(FC_PORTSPEED_1GBIT | FC_PORTSPEED_10GBIT);
754 if (ecmd.supported & (SUPPORTED_1000baseT_Half |
755 SUPPORTED_1000baseT_Full))
756 lport->link_supported_speeds |= FC_PORTSPEED_1GBIT;
757 if (ecmd.supported & SUPPORTED_10000baseT_Full)
758 lport->link_supported_speeds |= FC_PORTSPEED_10GBIT;
759
David Decotigny8ae6dac2011-04-27 18:32:38 +0000760 switch (ethtool_cmd_speed(&ecmd)) {
761 case SPEED_1000:
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800762 lport->link_speed = FC_PORTSPEED_1GBIT;
David Decotigny8ae6dac2011-04-27 18:32:38 +0000763 break;
Bhanu Prakash Gollapudia4dc08c2011-05-27 11:47:25 -0700764 case SPEED_2500:
765 lport->link_speed = FC_PORTSPEED_2GBIT;
766 break;
David Decotigny8ae6dac2011-04-27 18:32:38 +0000767 case SPEED_10000:
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800768 lport->link_speed = FC_PORTSPEED_10GBIT;
David Decotigny8ae6dac2011-04-27 18:32:38 +0000769 break;
770 }
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800771 }
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800772}
773static int bnx2fc_link_ok(struct fc_lport *lport)
774{
775 struct fcoe_port *port = lport_priv(lport);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700776 struct bnx2fc_interface *interface = port->priv;
777 struct bnx2fc_hba *hba = interface->hba;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800778 struct net_device *dev = hba->phys_dev;
779 int rc = 0;
780
781 if ((dev->flags & IFF_UP) && netif_carrier_ok(dev))
782 clear_bit(ADAPTER_STATE_LINK_DOWN, &hba->adapter_state);
783 else {
784 set_bit(ADAPTER_STATE_LINK_DOWN, &hba->adapter_state);
785 rc = -1;
786 }
787 return rc;
788}
789
790/**
791 * bnx2fc_get_link_state - get network link state
792 *
793 * @hba: adapter instance pointer
794 *
795 * updates adapter structure flag based on netdev state
796 */
797void bnx2fc_get_link_state(struct bnx2fc_hba *hba)
798{
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700799 if (test_bit(__LINK_STATE_NOCARRIER, &hba->phys_dev->state))
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800800 set_bit(ADAPTER_STATE_LINK_DOWN, &hba->adapter_state);
801 else
802 clear_bit(ADAPTER_STATE_LINK_DOWN, &hba->adapter_state);
803}
804
Bhanu Prakash Gollapudi52439602011-08-04 17:38:50 -0700805static int bnx2fc_net_config(struct fc_lport *lport, struct net_device *netdev)
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800806{
807 struct bnx2fc_hba *hba;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700808 struct bnx2fc_interface *interface;
Robert Lovefd8f8902012-05-22 19:06:16 -0700809 struct fcoe_ctlr *ctlr;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800810 struct fcoe_port *port;
811 u64 wwnn, wwpn;
812
813 port = lport_priv(lport);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700814 interface = port->priv;
Robert Lovefd8f8902012-05-22 19:06:16 -0700815 ctlr = bnx2fc_to_ctlr(interface);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700816 hba = interface->hba;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800817
818 /* require support for get_pauseparam ethtool op. */
819 if (!hba->phys_dev->ethtool_ops ||
820 !hba->phys_dev->ethtool_ops->get_pauseparam)
821 return -EOPNOTSUPP;
822
Bhanu Gollapudi1294bfe2011-03-17 17:13:34 -0700823 if (fc_set_mfs(lport, BNX2FC_MFS))
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800824 return -EINVAL;
825
826 skb_queue_head_init(&port->fcoe_pending_queue);
827 port->fcoe_pending_queue_active = 0;
828 setup_timer(&port->timer, fcoe_queue_timer, (unsigned long) lport);
829
830 bnx2fc_link_speed_update(lport);
831
832 if (!lport->vport) {
Bhanu Prakash Gollapudi52439602011-08-04 17:38:50 -0700833 if (fcoe_get_wwn(netdev, &wwnn, NETDEV_FCOE_WWNN))
Robert Lovefd8f8902012-05-22 19:06:16 -0700834 wwnn = fcoe_wwn_from_mac(ctlr->ctl_src_addr,
Bhanu Prakash Gollapudi52439602011-08-04 17:38:50 -0700835 1, 0);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800836 BNX2FC_HBA_DBG(lport, "WWNN = 0x%llx\n", wwnn);
837 fc_set_wwnn(lport, wwnn);
838
Bhanu Prakash Gollapudi52439602011-08-04 17:38:50 -0700839 if (fcoe_get_wwn(netdev, &wwpn, NETDEV_FCOE_WWPN))
Robert Lovefd8f8902012-05-22 19:06:16 -0700840 wwpn = fcoe_wwn_from_mac(ctlr->ctl_src_addr,
Bhanu Prakash Gollapudi52439602011-08-04 17:38:50 -0700841 2, 0);
842
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800843 BNX2FC_HBA_DBG(lport, "WWPN = 0x%llx\n", wwpn);
844 fc_set_wwpn(lport, wwpn);
845 }
846
847 return 0;
848}
849
850static void bnx2fc_destroy_timer(unsigned long data)
851{
852 struct bnx2fc_hba *hba = (struct bnx2fc_hba *)data;
853
Bhanu Prakash Gollapudicd703ae2011-08-04 17:38:43 -0700854 printk(KERN_ERR PFX "ERROR:bnx2fc_destroy_timer - "
855 "Destroy compl not received!!\n");
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700856 set_bit(BNX2FC_FLAG_DESTROY_CMPL, &hba->flags);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800857 wake_up_interruptible(&hba->destroy_wait);
858}
859
860/**
861 * bnx2fc_indicate_netevent - Generic netdev event handler
862 *
863 * @context: adapter structure pointer
864 * @event: event type
Michael Chan415199f2011-07-20 14:55:24 +0000865 * @vlan_id: vlan id - associated vlan id with this event
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800866 *
867 * Handles NETDEV_UP, NETDEV_DOWN, NETDEV_GOING_DOWN,NETDEV_CHANGE and
Bhanu Prakash Gollapudiabc49a92011-08-04 17:38:42 -0700868 * NETDEV_CHANGE_MTU events. Handle NETDEV_UNREGISTER only for vlans.
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800869 */
Michael Chan415199f2011-07-20 14:55:24 +0000870static void bnx2fc_indicate_netevent(void *context, unsigned long event,
871 u16 vlan_id)
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800872{
873 struct bnx2fc_hba *hba = (struct bnx2fc_hba *)context;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700874 struct fc_lport *lport;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800875 struct fc_lport *vport;
Bhanu Prakash Gollapudiabc49a92011-08-04 17:38:42 -0700876 struct bnx2fc_interface *interface, *tmp;
Robert Lovefd8f8902012-05-22 19:06:16 -0700877 struct fcoe_ctlr *ctlr;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700878 int wait_for_upload = 0;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800879 u32 link_possible = 1;
880
Bhanu Prakash Gollapudiabc49a92011-08-04 17:38:42 -0700881 if (vlan_id != 0 && event != NETDEV_UNREGISTER)
Michael Chan415199f2011-07-20 14:55:24 +0000882 return;
883
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800884 switch (event) {
885 case NETDEV_UP:
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800886 if (!test_bit(ADAPTER_STATE_UP, &hba->adapter_state))
887 printk(KERN_ERR "indicate_netevent: "\
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700888 "hba is not UP!!\n");
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800889 break;
890
891 case NETDEV_DOWN:
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800892 clear_bit(ADAPTER_STATE_GOING_DOWN, &hba->adapter_state);
893 clear_bit(ADAPTER_STATE_UP, &hba->adapter_state);
894 link_possible = 0;
895 break;
896
897 case NETDEV_GOING_DOWN:
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800898 set_bit(ADAPTER_STATE_GOING_DOWN, &hba->adapter_state);
899 link_possible = 0;
900 break;
901
902 case NETDEV_CHANGE:
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800903 break;
904
Bhanu Prakash Gollapudiabc49a92011-08-04 17:38:42 -0700905 case NETDEV_UNREGISTER:
906 if (!vlan_id)
907 return;
908 mutex_lock(&bnx2fc_dev_lock);
909 list_for_each_entry_safe(interface, tmp, &if_list, list) {
Nithin Nayak Sujir26b29822011-08-30 15:54:50 -0700910 if (interface->hba == hba &&
911 interface->vlan_id == (vlan_id & VLAN_VID_MASK))
912 __bnx2fc_destroy(interface);
Bhanu Prakash Gollapudiabc49a92011-08-04 17:38:42 -0700913 }
914 mutex_unlock(&bnx2fc_dev_lock);
915 return;
916
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800917 default:
Masanari Iida59e13d42012-04-25 00:24:16 +0900918 printk(KERN_ERR PFX "Unknown netevent %ld", event);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800919 return;
920 }
921
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700922 mutex_lock(&bnx2fc_dev_lock);
923 list_for_each_entry(interface, &if_list, list) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800924
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700925 if (interface->hba != hba)
926 continue;
927
Robert Lovefd8f8902012-05-22 19:06:16 -0700928 ctlr = bnx2fc_to_ctlr(interface);
929 lport = ctlr->lp;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700930 BNX2FC_HBA_DBG(lport, "netevent handler - event=%s %ld\n",
931 interface->netdev->name, event);
932
933 bnx2fc_link_speed_update(lport);
934
935 if (link_possible && !bnx2fc_link_ok(lport)) {
Bhanu Prakash Gollapudic7806732011-08-30 15:54:47 -0700936 /* Reset max recv frame size to default */
937 fc_set_mfs(lport, BNX2FC_MFS);
Bhanu Prakash Gollapudi8a5badf2011-08-30 15:54:48 -0700938 /*
939 * ctlr link up will only be handled during
940 * enable to avoid sending discovery solicitation
941 * on a stale vlan
942 */
Bhanu Prakash Gollapudifd8fa902011-10-03 16:45:00 -0700943 if (interface->enabled)
Robert Lovefd8f8902012-05-22 19:06:16 -0700944 fcoe_ctlr_link_up(ctlr);
945 } else if (fcoe_ctlr_link_down(ctlr)) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800946 mutex_lock(&lport->lp_mutex);
947 list_for_each_entry(vport, &lport->vports, list)
948 fc_host_port_type(vport->host) =
949 FC_PORTTYPE_UNKNOWN;
950 mutex_unlock(&lport->lp_mutex);
951 fc_host_port_type(lport->host) = FC_PORTTYPE_UNKNOWN;
Vasu Dev1bd49b42012-05-25 10:26:43 -0700952 per_cpu_ptr(lport->stats,
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800953 get_cpu())->LinkFailureCount++;
954 put_cpu();
955 fcoe_clean_pending_queue(lport);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700956 wait_for_upload = 1;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800957 }
958 }
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -0700959 mutex_unlock(&bnx2fc_dev_lock);
960
961 if (wait_for_upload) {
962 clear_bit(ADAPTER_STATE_READY, &hba->adapter_state);
963 init_waitqueue_head(&hba->shutdown_wait);
964 BNX2FC_MISC_DBG("indicate_netevent "
965 "num_ofld_sess = %d\n",
966 hba->num_ofld_sess);
967 hba->wait_for_link_down = 1;
968 wait_event_interruptible(hba->shutdown_wait,
969 (hba->num_ofld_sess == 0));
970 BNX2FC_MISC_DBG("wakeup - num_ofld_sess = %d\n",
971 hba->num_ofld_sess);
972 hba->wait_for_link_down = 0;
973
974 if (signal_pending(current))
975 flush_signals(current);
976 }
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -0800977}
978
979static int bnx2fc_libfc_config(struct fc_lport *lport)
980{
981
982 /* Set the function pointers set by bnx2fc driver */
983 memcpy(&lport->tt, &bnx2fc_libfc_fcn_templ,
984 sizeof(struct libfc_function_template));
985 fc_elsct_init(lport);
986 fc_exch_init(lport);
987 fc_rport_init(lport);
988 fc_disc_init(lport);
989 return 0;
990}
991
992static int bnx2fc_em_config(struct fc_lport *lport)
993{
Bhanu Prakash Gollapudi7d742f62012-01-23 18:00:48 -0800994 int max_xid;
995
996 if (nr_cpu_ids <= 2)
997 max_xid = FCOE_XIDS_PER_CPU;
998 else
999 max_xid = FCOE_MAX_XID;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001000 if (!fc_exch_mgr_alloc(lport, FC_CLASS_3, FCOE_MIN_XID,
Bhanu Prakash Gollapudi7d742f62012-01-23 18:00:48 -08001001 max_xid, NULL)) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001002 printk(KERN_ERR PFX "em_config:fc_exch_mgr_alloc failed\n");
1003 return -ENOMEM;
1004 }
1005
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001006 return 0;
1007}
1008
1009static int bnx2fc_lport_config(struct fc_lport *lport)
1010{
1011 lport->link_up = 0;
1012 lport->qfull = 0;
Bhanu Prakash Gollapudi44c570b2012-01-23 18:00:47 -08001013 lport->max_retry_count = BNX2FC_MAX_RETRY_CNT;
1014 lport->max_rport_retry_count = BNX2FC_MAX_RPORT_RETRY_CNT;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001015 lport->e_d_tov = 2 * 1000;
1016 lport->r_a_tov = 10 * 1000;
1017
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001018 lport->service_params = (FCP_SPPF_INIT_FCN | FCP_SPPF_RD_XRDY_DIS |
1019 FCP_SPPF_RETRY | FCP_SPPF_CONF_COMPL);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001020 lport->does_npiv = 1;
1021
1022 memset(&lport->rnid_gen, 0, sizeof(struct fc_els_rnid_gen));
1023 lport->rnid_gen.rnid_atype = BNX2FC_RNID_HBA;
1024
1025 /* alloc stats structure */
1026 if (fc_lport_init_stats(lport))
1027 return -ENOMEM;
1028
1029 /* Finish fc_lport configuration */
1030 fc_lport_config(lport);
1031
1032 return 0;
1033}
1034
1035/**
1036 * bnx2fc_fip_recv - handle a received FIP frame.
1037 *
1038 * @skb: the received skb
1039 * @dev: associated &net_device
1040 * @ptype: the &packet_type structure which was used to register this handler.
1041 * @orig_dev: original receive &net_device, in case @ dev is a bond.
1042 *
1043 * Returns: 0 for success
1044 */
1045static int bnx2fc_fip_recv(struct sk_buff *skb, struct net_device *dev,
1046 struct packet_type *ptype,
1047 struct net_device *orig_dev)
1048{
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001049 struct bnx2fc_interface *interface;
Robert Lovefd8f8902012-05-22 19:06:16 -07001050 struct fcoe_ctlr *ctlr;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001051 interface = container_of(ptype, struct bnx2fc_interface,
1052 fip_packet_type);
Robert Lovefd8f8902012-05-22 19:06:16 -07001053 ctlr = bnx2fc_to_ctlr(interface);
1054 fcoe_ctlr_recv(ctlr, skb);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001055 return 0;
1056}
1057
1058/**
1059 * bnx2fc_update_src_mac - Update Ethernet MAC filters.
1060 *
1061 * @fip: FCoE controller.
1062 * @old: Unicast MAC address to delete if the MAC is non-zero.
1063 * @new: Unicast MAC address to add.
1064 *
1065 * Remove any previously-set unicast MAC filter.
1066 * Add secondary FCoE MAC address filter for our OUI.
1067 */
1068static void bnx2fc_update_src_mac(struct fc_lport *lport, u8 *addr)
1069{
1070 struct fcoe_port *port = lport_priv(lport);
1071
1072 memcpy(port->data_src_addr, addr, ETH_ALEN);
1073}
1074
1075/**
1076 * bnx2fc_get_src_mac - return the ethernet source address for an lport
1077 *
1078 * @lport: libfc port
1079 */
1080static u8 *bnx2fc_get_src_mac(struct fc_lport *lport)
1081{
1082 struct fcoe_port *port;
1083
1084 port = (struct fcoe_port *)lport_priv(lport);
1085 return port->data_src_addr;
1086}
1087
1088/**
1089 * bnx2fc_fip_send - send an Ethernet-encapsulated FIP frame.
1090 *
1091 * @fip: FCoE controller.
1092 * @skb: FIP Packet.
1093 */
1094static void bnx2fc_fip_send(struct fcoe_ctlr *fip, struct sk_buff *skb)
1095{
1096 skb->dev = bnx2fc_from_ctlr(fip)->netdev;
1097 dev_queue_xmit(skb);
1098}
1099
1100static int bnx2fc_vport_create(struct fc_vport *vport, bool disabled)
1101{
1102 struct Scsi_Host *shost = vport_to_shost(vport);
1103 struct fc_lport *n_port = shost_priv(shost);
1104 struct fcoe_port *port = lport_priv(n_port);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001105 struct bnx2fc_interface *interface = port->priv;
1106 struct net_device *netdev = interface->netdev;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001107 struct fc_lport *vn_port;
Bhanu Prakash Gollapudi861efc52011-08-04 17:38:51 -07001108 int rc;
1109 char buf[32];
1110
1111 rc = fcoe_validate_vport_create(vport);
1112 if (rc) {
1113 fcoe_wwn_to_str(vport->port_name, buf, sizeof(buf));
1114 printk(KERN_ERR PFX "Failed to create vport, "
1115 "WWPN (0x%s) already exists\n",
1116 buf);
1117 return rc;
1118 }
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001119
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001120 if (!test_bit(BNX2FC_FLAG_FW_INIT_DONE, &interface->hba->flags)) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001121 printk(KERN_ERR PFX "vn ports cannot be created on"
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001122 "this interface\n");
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001123 return -EIO;
1124 }
Jiri Pirko4bc71cb2011-09-03 03:34:30 +00001125 rtnl_lock();
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001126 mutex_lock(&bnx2fc_dev_lock);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001127 vn_port = bnx2fc_if_create(interface, &vport->dev, 1);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001128 mutex_unlock(&bnx2fc_dev_lock);
Jiri Pirko4bc71cb2011-09-03 03:34:30 +00001129 rtnl_unlock();
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001130
1131 if (IS_ERR(vn_port)) {
1132 printk(KERN_ERR PFX "bnx2fc_vport_create (%s) failed\n",
1133 netdev->name);
1134 return -EIO;
1135 }
1136
1137 if (disabled) {
1138 fc_vport_set_state(vport, FC_VPORT_DISABLED);
1139 } else {
1140 vn_port->boot_time = jiffies;
1141 fc_lport_init(vn_port);
1142 fc_fabric_login(vn_port);
1143 fc_vport_setlink(vn_port);
1144 }
1145 return 0;
1146}
1147
Bhanu Prakash Gollapudiabc49a92011-08-04 17:38:42 -07001148static void bnx2fc_free_vport(struct bnx2fc_hba *hba, struct fc_lport *lport)
1149{
1150 struct bnx2fc_lport *blport, *tmp;
1151
1152 spin_lock_bh(&hba->hba_lock);
1153 list_for_each_entry_safe(blport, tmp, &hba->vports, list) {
1154 if (blport->lport == lport) {
1155 list_del(&blport->list);
1156 kfree(blport);
1157 }
1158 }
1159 spin_unlock_bh(&hba->hba_lock);
1160}
1161
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001162static int bnx2fc_vport_destroy(struct fc_vport *vport)
1163{
1164 struct Scsi_Host *shost = vport_to_shost(vport);
1165 struct fc_lport *n_port = shost_priv(shost);
1166 struct fc_lport *vn_port = vport->dd_data;
1167 struct fcoe_port *port = lport_priv(vn_port);
Bhanu Prakash Gollapudiabc49a92011-08-04 17:38:42 -07001168 struct bnx2fc_interface *interface = port->priv;
Bhanu Prakash Gollapudicdf54662011-08-04 17:38:39 -07001169 struct fc_lport *v_port;
1170 bool found = false;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001171
1172 mutex_lock(&n_port->lp_mutex);
Bhanu Prakash Gollapudicdf54662011-08-04 17:38:39 -07001173 list_for_each_entry(v_port, &n_port->vports, list)
1174 if (v_port->vport == vport) {
1175 found = true;
1176 break;
1177 }
1178
1179 if (!found) {
1180 mutex_unlock(&n_port->lp_mutex);
1181 return -ENOENT;
1182 }
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001183 list_del(&vn_port->list);
1184 mutex_unlock(&n_port->lp_mutex);
Bhanu Prakash Gollapudiabc49a92011-08-04 17:38:42 -07001185 bnx2fc_free_vport(interface->hba, port->lport);
1186 bnx2fc_port_shutdown(port->lport);
1187 bnx2fc_interface_put(interface);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001188 queue_work(bnx2fc_wq, &port->destroy_work);
1189 return 0;
1190}
1191
1192static int bnx2fc_vport_disable(struct fc_vport *vport, bool disable)
1193{
1194 struct fc_lport *lport = vport->dd_data;
1195
1196 if (disable) {
1197 fc_vport_set_state(vport, FC_VPORT_DISABLED);
1198 fc_fabric_logoff(lport);
1199 } else {
1200 lport->boot_time = jiffies;
1201 fc_fabric_login(lport);
1202 fc_vport_setlink(lport);
1203 }
1204 return 0;
1205}
1206
1207
Bhanu Prakash Gollapudi776cebc2011-08-04 17:38:40 -07001208static int bnx2fc_interface_setup(struct bnx2fc_interface *interface)
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001209{
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001210 struct net_device *netdev = interface->netdev;
1211 struct net_device *physdev = interface->hba->phys_dev;
Robert Lovefd8f8902012-05-22 19:06:16 -07001212 struct fcoe_ctlr *ctlr = bnx2fc_to_ctlr(interface);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001213 struct netdev_hw_addr *ha;
1214 int sel_san_mac = 0;
1215
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001216 /* setup Source MAC Address */
1217 rcu_read_lock();
1218 for_each_dev_addr(physdev, ha) {
1219 BNX2FC_MISC_DBG("net_config: ha->type = %d, fip_mac = ",
1220 ha->type);
1221 printk(KERN_INFO "%2x:%2x:%2x:%2x:%2x:%2x\n", ha->addr[0],
1222 ha->addr[1], ha->addr[2], ha->addr[3],
1223 ha->addr[4], ha->addr[5]);
1224
1225 if ((ha->type == NETDEV_HW_ADDR_T_SAN) &&
1226 (is_valid_ether_addr(ha->addr))) {
Robert Lovefd8f8902012-05-22 19:06:16 -07001227 memcpy(ctlr->ctl_src_addr, ha->addr,
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001228 ETH_ALEN);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001229 sel_san_mac = 1;
1230 BNX2FC_MISC_DBG("Found SAN MAC\n");
1231 }
1232 }
1233 rcu_read_unlock();
1234
1235 if (!sel_san_mac)
1236 return -ENODEV;
1237
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001238 interface->fip_packet_type.func = bnx2fc_fip_recv;
1239 interface->fip_packet_type.type = htons(ETH_P_FIP);
1240 interface->fip_packet_type.dev = netdev;
1241 dev_add_pack(&interface->fip_packet_type);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001242
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001243 interface->fcoe_packet_type.func = bnx2fc_rcv;
1244 interface->fcoe_packet_type.type = __constant_htons(ETH_P_FCOE);
1245 interface->fcoe_packet_type.dev = netdev;
1246 dev_add_pack(&interface->fcoe_packet_type);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001247
1248 return 0;
1249}
1250
1251static int bnx2fc_attach_transport(void)
1252{
1253 bnx2fc_transport_template =
1254 fc_attach_transport(&bnx2fc_transport_function);
1255
1256 if (bnx2fc_transport_template == NULL) {
1257 printk(KERN_ERR PFX "Failed to attach FC transport\n");
1258 return -ENODEV;
1259 }
1260
1261 bnx2fc_vport_xport_template =
1262 fc_attach_transport(&bnx2fc_vport_xport_function);
1263 if (bnx2fc_vport_xport_template == NULL) {
1264 printk(KERN_ERR PFX
1265 "Failed to attach FC transport for vport\n");
1266 fc_release_transport(bnx2fc_transport_template);
1267 bnx2fc_transport_template = NULL;
1268 return -ENODEV;
1269 }
1270 return 0;
1271}
1272static void bnx2fc_release_transport(void)
1273{
1274 fc_release_transport(bnx2fc_transport_template);
1275 fc_release_transport(bnx2fc_vport_xport_template);
1276 bnx2fc_transport_template = NULL;
1277 bnx2fc_vport_xport_template = NULL;
1278}
1279
1280static void bnx2fc_interface_release(struct kref *kref)
1281{
Robert Love8d55e502012-05-22 19:06:26 -07001282 struct fcoe_ctlr_device *ctlr_dev;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001283 struct bnx2fc_interface *interface;
Robert Lovefd8f8902012-05-22 19:06:16 -07001284 struct fcoe_ctlr *ctlr;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001285 struct net_device *netdev;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001286
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001287 interface = container_of(kref, struct bnx2fc_interface, kref);
Nithin Nayak Sujir068bdce2011-04-25 12:30:09 -07001288 BNX2FC_MISC_DBG("Interface is being released\n");
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001289
Robert Lovefd8f8902012-05-22 19:06:16 -07001290 ctlr = bnx2fc_to_ctlr(interface);
Robert Love8d55e502012-05-22 19:06:26 -07001291 ctlr_dev = fcoe_ctlr_to_ctlr_dev(ctlr);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001292 netdev = interface->netdev;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001293
1294 /* tear-down FIP controller */
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001295 if (test_and_clear_bit(BNX2FC_CTLR_INIT_DONE, &interface->if_flags))
Robert Lovefd8f8902012-05-22 19:06:16 -07001296 fcoe_ctlr_destroy(ctlr);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001297
Robert Love8d55e502012-05-22 19:06:26 -07001298 fcoe_ctlr_device_delete(ctlr_dev);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001299
1300 dev_put(netdev);
1301 module_put(THIS_MODULE);
1302}
1303
1304static inline void bnx2fc_interface_get(struct bnx2fc_interface *interface)
1305{
1306 kref_get(&interface->kref);
1307}
1308
1309static inline void bnx2fc_interface_put(struct bnx2fc_interface *interface)
1310{
1311 kref_put(&interface->kref, bnx2fc_interface_release);
1312}
1313static void bnx2fc_hba_destroy(struct bnx2fc_hba *hba)
1314{
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001315 /* Free the command manager */
1316 if (hba->cmd_mgr) {
1317 bnx2fc_cmd_mgr_free(hba->cmd_mgr);
1318 hba->cmd_mgr = NULL;
1319 }
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001320 kfree(hba->tgt_ofld_list);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001321 bnx2fc_unbind_pcidev(hba);
1322 kfree(hba);
1323}
1324
1325/**
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001326 * bnx2fc_hba_create - create a new bnx2fc hba
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001327 *
1328 * @cnic: pointer to cnic device
1329 *
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001330 * Creates a new FCoE hba on the given device.
1331 *
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001332 */
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001333static struct bnx2fc_hba *bnx2fc_hba_create(struct cnic_dev *cnic)
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001334{
1335 struct bnx2fc_hba *hba;
Barak Witkowski2e499d32012-06-26 01:31:19 +00001336 struct fcoe_capabilities *fcoe_cap;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001337 int rc;
1338
1339 hba = kzalloc(sizeof(*hba), GFP_KERNEL);
1340 if (!hba) {
1341 printk(KERN_ERR PFX "Unable to allocate hba structure\n");
1342 return NULL;
1343 }
1344 spin_lock_init(&hba->hba_lock);
1345 mutex_init(&hba->hba_mutex);
1346
1347 hba->cnic = cnic;
1348 rc = bnx2fc_bind_pcidev(hba);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001349 if (rc) {
1350 printk(KERN_ERR PFX "create_adapter: bind error\n");
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001351 goto bind_err;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001352 }
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001353 hba->phys_dev = cnic->netdev;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001354 hba->next_conn_id = 0;
1355
1356 hba->tgt_ofld_list =
1357 kzalloc(sizeof(struct bnx2fc_rport *) * BNX2FC_NUM_MAX_SESS,
1358 GFP_KERNEL);
1359 if (!hba->tgt_ofld_list) {
1360 printk(KERN_ERR PFX "Unable to allocate tgt offload list\n");
1361 goto tgtofld_err;
1362 }
1363
1364 hba->num_ofld_sess = 0;
1365
1366 hba->cmd_mgr = bnx2fc_cmd_mgr_alloc(hba, BNX2FC_MIN_XID,
1367 BNX2FC_MAX_XID);
1368 if (!hba->cmd_mgr) {
1369 printk(KERN_ERR PFX "em_config:bnx2fc_cmd_mgr_alloc failed\n");
1370 goto cmgr_err;
1371 }
Barak Witkowski2e499d32012-06-26 01:31:19 +00001372 fcoe_cap = &hba->fcoe_cap;
1373
1374 fcoe_cap->capability1 = BNX2FC_TM_MAX_SQES <<
1375 FCOE_IOS_PER_CONNECTION_SHIFT;
1376 fcoe_cap->capability1 |= BNX2FC_NUM_MAX_SESS <<
1377 FCOE_LOGINS_PER_PORT_SHIFT;
1378 fcoe_cap->capability2 = BNX2FC_MAX_OUTSTANDING_CMNDS <<
1379 FCOE_NUMBER_OF_EXCHANGES_SHIFT;
1380 fcoe_cap->capability2 |= BNX2FC_MAX_NPIV <<
1381 FCOE_NPIV_WWN_PER_PORT_SHIFT;
1382 fcoe_cap->capability3 = BNX2FC_NUM_MAX_SESS <<
1383 FCOE_TARGETS_SUPPORTED_SHIFT;
1384 fcoe_cap->capability3 |= BNX2FC_MAX_OUTSTANDING_CMNDS <<
1385 FCOE_OUTSTANDING_COMMANDS_SHIFT;
1386 fcoe_cap->capability4 = FCOE_CAPABILITY4_STATEFUL;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001387
1388 init_waitqueue_head(&hba->shutdown_wait);
1389 init_waitqueue_head(&hba->destroy_wait);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001390 INIT_LIST_HEAD(&hba->vports);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001391
1392 return hba;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001393
1394cmgr_err:
1395 kfree(hba->tgt_ofld_list);
1396tgtofld_err:
1397 bnx2fc_unbind_pcidev(hba);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001398bind_err:
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001399 kfree(hba);
1400 return NULL;
1401}
1402
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001403struct bnx2fc_interface *bnx2fc_interface_create(struct bnx2fc_hba *hba,
1404 struct net_device *netdev,
1405 enum fip_state fip_mode)
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001406{
Robert Love8d55e502012-05-22 19:06:26 -07001407 struct fcoe_ctlr_device *ctlr_dev;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001408 struct bnx2fc_interface *interface;
Robert Lovefd8f8902012-05-22 19:06:16 -07001409 struct fcoe_ctlr *ctlr;
1410 int size;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001411 int rc = 0;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001412
Robert Lovefd8f8902012-05-22 19:06:16 -07001413 size = (sizeof(*interface) + sizeof(struct fcoe_ctlr));
Robert Love8d55e502012-05-22 19:06:26 -07001414 ctlr_dev = fcoe_ctlr_device_add(&netdev->dev, &bnx2fc_fcoe_sysfs_templ,
1415 size);
1416 if (!ctlr_dev) {
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001417 printk(KERN_ERR PFX "Unable to allocate interface structure\n");
1418 return NULL;
1419 }
Robert Love8d55e502012-05-22 19:06:26 -07001420 ctlr = fcoe_ctlr_device_priv(ctlr_dev);
Robert Lovefd8f8902012-05-22 19:06:16 -07001421 interface = fcoe_ctlr_priv(ctlr);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001422 dev_hold(netdev);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001423 kref_init(&interface->kref);
1424 interface->hba = hba;
1425 interface->netdev = netdev;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001426
1427 /* Initialize FIP */
Robert Lovefd8f8902012-05-22 19:06:16 -07001428 fcoe_ctlr_init(ctlr, fip_mode);
1429 ctlr->send = bnx2fc_fip_send;
1430 ctlr->update_mac = bnx2fc_update_src_mac;
1431 ctlr->get_src_addr = bnx2fc_get_src_mac;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001432 set_bit(BNX2FC_CTLR_INIT_DONE, &interface->if_flags);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001433
Bhanu Prakash Gollapudi776cebc2011-08-04 17:38:40 -07001434 rc = bnx2fc_interface_setup(interface);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001435 if (!rc)
1436 return interface;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001437
Robert Lovefd8f8902012-05-22 19:06:16 -07001438 fcoe_ctlr_destroy(ctlr);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001439 dev_put(netdev);
Robert Love8d55e502012-05-22 19:06:26 -07001440 fcoe_ctlr_device_delete(ctlr_dev);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001441 return NULL;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001442}
1443
1444/**
1445 * bnx2fc_if_create - Create FCoE instance on a given interface
1446 *
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001447 * @interface: FCoE interface to create a local port on
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001448 * @parent: Device pointer to be the parent in sysfs for the SCSI host
1449 * @npiv: Indicates if the port is vport or not
1450 *
1451 * Creates a fc_lport instance and a Scsi_Host instance and configure them.
1452 *
1453 * Returns: Allocated fc_lport or an error pointer
1454 */
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001455static struct fc_lport *bnx2fc_if_create(struct bnx2fc_interface *interface,
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001456 struct device *parent, int npiv)
1457{
Robert Lovefd8f8902012-05-22 19:06:16 -07001458 struct fcoe_ctlr *ctlr = bnx2fc_to_ctlr(interface);
Vasu Dev134a4e22011-04-28 15:55:44 -07001459 struct fc_lport *lport, *n_port;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001460 struct fcoe_port *port;
1461 struct Scsi_Host *shost;
1462 struct fc_vport *vport = dev_to_vport(parent);
Bhanu Prakash Gollapudid36b3272011-05-27 11:47:27 -07001463 struct bnx2fc_lport *blport;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001464 struct bnx2fc_hba *hba;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001465 int rc = 0;
1466
Bhanu Prakash Gollapudid36b3272011-05-27 11:47:27 -07001467 blport = kzalloc(sizeof(struct bnx2fc_lport), GFP_KERNEL);
1468 if (!blport) {
Robert Lovefd8f8902012-05-22 19:06:16 -07001469 BNX2FC_HBA_DBG(ctlr->lp, "Unable to alloc blport\n");
Bhanu Prakash Gollapudid36b3272011-05-27 11:47:27 -07001470 return NULL;
1471 }
1472
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001473 /* Allocate Scsi_Host structure */
Vasu Dev134a4e22011-04-28 15:55:44 -07001474 if (!npiv)
1475 lport = libfc_host_alloc(&bnx2fc_shost_template, sizeof(*port));
1476 else
1477 lport = libfc_vport_create(vport, sizeof(*port));
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001478
1479 if (!lport) {
1480 printk(KERN_ERR PFX "could not allocate scsi host structure\n");
Bhanu Prakash Gollapudid36b3272011-05-27 11:47:27 -07001481 goto free_blport;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001482 }
1483 shost = lport->host;
1484 port = lport_priv(lport);
1485 port->lport = lport;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001486 port->priv = interface;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001487 INIT_WORK(&port->destroy_work, bnx2fc_destroy_work);
1488
1489 /* Configure fcoe_port */
1490 rc = bnx2fc_lport_config(lport);
1491 if (rc)
1492 goto lp_config_err;
1493
1494 if (npiv) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001495 printk(KERN_ERR PFX "Setting vport names, 0x%llX 0x%llX\n",
1496 vport->node_name, vport->port_name);
1497 fc_set_wwnn(lport, vport->node_name);
1498 fc_set_wwpn(lport, vport->port_name);
1499 }
1500 /* Configure netdev and networking properties of the lport */
Bhanu Prakash Gollapudi52439602011-08-04 17:38:50 -07001501 rc = bnx2fc_net_config(lport, interface->netdev);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001502 if (rc) {
1503 printk(KERN_ERR PFX "Error on bnx2fc_net_config\n");
1504 goto lp_config_err;
1505 }
1506
1507 rc = bnx2fc_shost_config(lport, parent);
1508 if (rc) {
1509 printk(KERN_ERR PFX "Couldnt configure shost for %s\n",
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001510 interface->netdev->name);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001511 goto lp_config_err;
1512 }
1513
1514 /* Initialize the libfc library */
1515 rc = bnx2fc_libfc_config(lport);
1516 if (rc) {
1517 printk(KERN_ERR PFX "Couldnt configure libfc\n");
1518 goto shost_err;
1519 }
1520 fc_host_port_type(lport->host) = FC_PORTTYPE_UNKNOWN;
1521
1522 /* Allocate exchange manager */
Vasu Dev134a4e22011-04-28 15:55:44 -07001523 if (!npiv)
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001524 rc = bnx2fc_em_config(lport);
Vasu Dev134a4e22011-04-28 15:55:44 -07001525 else {
1526 shost = vport_to_shost(vport);
1527 n_port = shost_priv(shost);
1528 rc = fc_exch_mgr_list_clone(n_port, lport);
1529 }
1530
1531 if (rc) {
1532 printk(KERN_ERR PFX "Error on bnx2fc_em_config\n");
1533 goto shost_err;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001534 }
1535
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001536 bnx2fc_interface_get(interface);
Bhanu Prakash Gollapudid36b3272011-05-27 11:47:27 -07001537
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001538 hba = interface->hba;
Bhanu Prakash Gollapudid36b3272011-05-27 11:47:27 -07001539 spin_lock_bh(&hba->hba_lock);
1540 blport->lport = lport;
1541 list_add_tail(&blport->list, &hba->vports);
1542 spin_unlock_bh(&hba->hba_lock);
1543
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001544 return lport;
1545
1546shost_err:
1547 scsi_remove_host(shost);
1548lp_config_err:
1549 scsi_host_put(lport->host);
Bhanu Prakash Gollapudid36b3272011-05-27 11:47:27 -07001550free_blport:
1551 kfree(blport);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001552 return NULL;
1553}
1554
Bhanu Prakash Gollapudi013068f2011-08-30 15:54:52 -07001555static void bnx2fc_net_cleanup(struct bnx2fc_interface *interface)
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001556{
1557 /* Dont listen for Ethernet packets anymore */
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001558 __dev_remove_pack(&interface->fcoe_packet_type);
1559 __dev_remove_pack(&interface->fip_packet_type);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001560 synchronize_net();
1561}
1562
Bhanu Prakash Gollapudi776cebc2011-08-04 17:38:40 -07001563static void bnx2fc_interface_cleanup(struct bnx2fc_interface *interface)
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001564{
Robert Lovefd8f8902012-05-22 19:06:16 -07001565 struct fcoe_ctlr *ctlr = bnx2fc_to_ctlr(interface);
1566 struct fc_lport *lport = ctlr->lp;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001567 struct fcoe_port *port = lport_priv(lport);
Bhanu Prakash Gollapudi9be17fc2011-08-04 17:38:41 -07001568 struct bnx2fc_hba *hba = interface->hba;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001569
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001570 /* Stop the transmit retry timer */
1571 del_timer_sync(&port->timer);
1572
1573 /* Free existing transmit skbs */
1574 fcoe_clean_pending_queue(lport);
1575
Bhanu Prakash Gollapudi013068f2011-08-30 15:54:52 -07001576 bnx2fc_net_cleanup(interface);
Bhanu Prakash Gollapudi9be17fc2011-08-04 17:38:41 -07001577
Bhanu Prakash Gollapudiabc49a92011-08-04 17:38:42 -07001578 bnx2fc_free_vport(hba, lport);
Bhanu Prakash Gollapudi9be17fc2011-08-04 17:38:41 -07001579}
1580
1581static void bnx2fc_if_destroy(struct fc_lport *lport)
1582{
1583
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001584 /* Free queued packets for the receive thread */
1585 bnx2fc_clean_rx_queue(lport);
1586
1587 /* Detach from scsi-ml */
1588 fc_remove_host(lport->host);
1589 scsi_remove_host(lport->host);
1590
1591 /*
1592 * Note that only the physical lport will have the exchange manager.
1593 * for vports, this function is NOP
1594 */
1595 fc_exch_mgr_free(lport);
1596
1597 /* Free memory used by statistical counters */
1598 fc_lport_free_stats(lport);
1599
1600 /* Release Scsi_Host */
1601 scsi_host_put(lport->host);
1602}
1603
Bhanu Prakash Gollapudieccdcd02011-08-24 18:56:42 -07001604static void __bnx2fc_destroy(struct bnx2fc_interface *interface)
Bhanu Prakash Gollapudiabc49a92011-08-04 17:38:42 -07001605{
Robert Lovefd8f8902012-05-22 19:06:16 -07001606 struct fcoe_ctlr *ctlr = bnx2fc_to_ctlr(interface);
1607 struct fc_lport *lport = ctlr->lp;
Bhanu Prakash Gollapudi0cbf32e2011-08-30 15:54:51 -07001608 struct fcoe_port *port = lport_priv(lport);
Bhanu Prakash Gollapudiabc49a92011-08-04 17:38:42 -07001609
1610 bnx2fc_interface_cleanup(interface);
1611 bnx2fc_stop(interface);
Bhanu Prakash Gollapudiabc49a92011-08-04 17:38:42 -07001612 list_del(&interface->list);
Bhanu Prakash Gollapudiabc49a92011-08-04 17:38:42 -07001613 bnx2fc_interface_put(interface);
Bhanu Prakash Gollapudi0cbf32e2011-08-30 15:54:51 -07001614 queue_work(bnx2fc_wq, &port->destroy_work);
Bhanu Prakash Gollapudiabc49a92011-08-04 17:38:42 -07001615}
1616
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001617/**
1618 * bnx2fc_destroy - Destroy a bnx2fc FCoE interface
1619 *
1620 * @buffer: The name of the Ethernet interface to be destroyed
1621 * @kp: The associated kernel parameter
1622 *
1623 * Called from sysfs.
1624 *
1625 * Returns: 0 for success
1626 */
1627static int bnx2fc_destroy(struct net_device *netdev)
1628{
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001629 struct bnx2fc_interface *interface = NULL;
Bhanu Prakash Gollapudi2a7b29c2012-01-23 18:00:46 -08001630 struct workqueue_struct *timer_work_queue;
Robert Lovefd8f8902012-05-22 19:06:16 -07001631 struct fcoe_ctlr *ctlr;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001632 int rc = 0;
1633
Nithin Sujir6702ca12011-03-17 17:13:27 -07001634 rtnl_lock();
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001635 mutex_lock(&bnx2fc_dev_lock);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001636
1637 interface = bnx2fc_interface_lookup(netdev);
Robert Lovefd8f8902012-05-22 19:06:16 -07001638 ctlr = bnx2fc_to_ctlr(interface);
1639 if (!interface || !ctlr->lp) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001640 rc = -ENODEV;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001641 printk(KERN_ERR PFX "bnx2fc_destroy: interface or lport not found\n");
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001642 goto netdev_err;
1643 }
1644
Bhanu Prakash Gollapudi2a7b29c2012-01-23 18:00:46 -08001645 timer_work_queue = interface->timer_work_queue;
Bhanu Prakash Gollapudieccdcd02011-08-24 18:56:42 -07001646 __bnx2fc_destroy(interface);
Bhanu Prakash Gollapudi2a7b29c2012-01-23 18:00:46 -08001647 destroy_workqueue(timer_work_queue);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001648
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001649netdev_err:
1650 mutex_unlock(&bnx2fc_dev_lock);
1651 rtnl_unlock();
1652 return rc;
1653}
1654
1655static void bnx2fc_destroy_work(struct work_struct *work)
1656{
1657 struct fcoe_port *port;
1658 struct fc_lport *lport;
1659
1660 port = container_of(work, struct fcoe_port, destroy_work);
1661 lport = port->lport;
1662
1663 BNX2FC_HBA_DBG(lport, "Entered bnx2fc_destroy_work\n");
1664
Bhanu Prakash Gollapudi9be17fc2011-08-04 17:38:41 -07001665 bnx2fc_if_destroy(lport);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001666}
1667
1668static void bnx2fc_unbind_adapter_devices(struct bnx2fc_hba *hba)
1669{
1670 bnx2fc_free_fw_resc(hba);
1671 bnx2fc_free_task_ctx(hba);
1672}
1673
1674/**
1675 * bnx2fc_bind_adapter_devices - binds bnx2fc adapter with the associated
1676 * pci structure
1677 *
1678 * @hba: Adapter instance
1679 */
1680static int bnx2fc_bind_adapter_devices(struct bnx2fc_hba *hba)
1681{
1682 if (bnx2fc_setup_task_ctx(hba))
1683 goto mem_err;
1684
1685 if (bnx2fc_setup_fw_resc(hba))
1686 goto mem_err;
1687
1688 return 0;
1689mem_err:
1690 bnx2fc_unbind_adapter_devices(hba);
1691 return -ENOMEM;
1692}
1693
1694static int bnx2fc_bind_pcidev(struct bnx2fc_hba *hba)
1695{
1696 struct cnic_dev *cnic;
1697
1698 if (!hba->cnic) {
1699 printk(KERN_ERR PFX "cnic is NULL\n");
1700 return -ENODEV;
1701 }
1702 cnic = hba->cnic;
1703 hba->pcidev = cnic->pcidev;
1704 if (hba->pcidev)
1705 pci_dev_get(hba->pcidev);
1706
1707 return 0;
1708}
1709
1710static void bnx2fc_unbind_pcidev(struct bnx2fc_hba *hba)
1711{
1712 if (hba->pcidev)
1713 pci_dev_put(hba->pcidev);
1714 hba->pcidev = NULL;
1715}
1716
Barak Witkowski2e499d32012-06-26 01:31:19 +00001717/**
1718 * bnx2fc_ulp_get_stats - cnic callback to populate FCoE stats
1719 *
1720 * @handle: transport handle pointing to adapter struture
1721 */
1722static int bnx2fc_ulp_get_stats(void *handle)
1723{
1724 struct bnx2fc_hba *hba = handle;
1725 struct cnic_dev *cnic;
1726 struct fcoe_stats_info *stats_addr;
1727
1728 if (!hba)
1729 return -EINVAL;
1730
1731 cnic = hba->cnic;
1732 stats_addr = &cnic->stats_addr->fcoe_stat;
1733 if (!stats_addr)
1734 return -EINVAL;
1735
1736 strncpy(stats_addr->version, BNX2FC_VERSION,
1737 sizeof(stats_addr->version));
1738 stats_addr->txq_size = BNX2FC_SQ_WQES_MAX;
1739 stats_addr->rxq_size = BNX2FC_CQ_WQES_MAX;
1740
1741 return 0;
1742}
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001743
1744
1745/**
1746 * bnx2fc_ulp_start - cnic callback to initialize & start adapter instance
1747 *
Masanari Iida59e13d42012-04-25 00:24:16 +09001748 * @handle: transport handle pointing to adapter structure
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001749 *
1750 * This function maps adapter structure to pcidev structure and initiates
1751 * firmware handshake to enable/initialize on-chip FCoE components.
1752 * This bnx2fc - cnic interface api callback is used after following
1753 * conditions are met -
1754 * a) underlying network interface is up (marked by event NETDEV_UP
1755 * from netdev
1756 * b) bnx2fc adatper structure is registered.
1757 */
1758static void bnx2fc_ulp_start(void *handle)
1759{
1760 struct bnx2fc_hba *hba = handle;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001761 struct bnx2fc_interface *interface;
Robert Lovefd8f8902012-05-22 19:06:16 -07001762 struct fcoe_ctlr *ctlr;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001763 struct fc_lport *lport;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001764
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001765 mutex_lock(&bnx2fc_dev_lock);
1766
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001767 if (!test_bit(BNX2FC_FLAG_FW_INIT_DONE, &hba->flags))
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001768 bnx2fc_fw_init(hba);
1769
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001770 BNX2FC_MISC_DBG("bnx2fc started.\n");
1771
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001772 list_for_each_entry(interface, &if_list, list) {
1773 if (interface->hba == hba) {
Robert Lovefd8f8902012-05-22 19:06:16 -07001774 ctlr = bnx2fc_to_ctlr(interface);
1775 lport = ctlr->lp;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001776 /* Kick off Fabric discovery*/
1777 printk(KERN_ERR PFX "ulp_init: start discovery\n");
1778 lport->tt.frame_send = bnx2fc_xmit;
1779 bnx2fc_start_disc(interface);
1780 }
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001781 }
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001782
1783 mutex_unlock(&bnx2fc_dev_lock);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001784}
1785
1786static void bnx2fc_port_shutdown(struct fc_lport *lport)
1787{
1788 BNX2FC_MISC_DBG("Entered %s\n", __func__);
1789 fc_fabric_logoff(lport);
1790 fc_lport_destroy(lport);
1791}
1792
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001793static void bnx2fc_stop(struct bnx2fc_interface *interface)
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001794{
Robert Lovefd8f8902012-05-22 19:06:16 -07001795 struct fcoe_ctlr *ctlr = bnx2fc_to_ctlr(interface);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001796 struct fc_lport *lport;
1797 struct fc_lport *vport;
1798
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001799 if (!test_bit(BNX2FC_FLAG_FW_INIT_DONE, &interface->hba->flags))
1800 return;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001801
Robert Lovefd8f8902012-05-22 19:06:16 -07001802 lport = ctlr->lp;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001803 bnx2fc_port_shutdown(lport);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001804
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001805 mutex_lock(&lport->lp_mutex);
1806 list_for_each_entry(vport, &lport->vports, list)
1807 fc_host_port_type(vport->host) =
1808 FC_PORTTYPE_UNKNOWN;
1809 mutex_unlock(&lport->lp_mutex);
1810 fc_host_port_type(lport->host) = FC_PORTTYPE_UNKNOWN;
Robert Lovefd8f8902012-05-22 19:06:16 -07001811 fcoe_ctlr_link_down(ctlr);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001812 fcoe_clean_pending_queue(lport);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001813}
1814
1815static int bnx2fc_fw_init(struct bnx2fc_hba *hba)
1816{
1817#define BNX2FC_INIT_POLL_TIME (1000 / HZ)
1818 int rc = -1;
1819 int i = HZ;
1820
1821 rc = bnx2fc_bind_adapter_devices(hba);
1822 if (rc) {
1823 printk(KERN_ALERT PFX
1824 "bnx2fc_bind_adapter_devices failed - rc = %d\n", rc);
1825 goto err_out;
1826 }
1827
1828 rc = bnx2fc_send_fw_fcoe_init_msg(hba);
1829 if (rc) {
1830 printk(KERN_ALERT PFX
1831 "bnx2fc_send_fw_fcoe_init_msg failed - rc = %d\n", rc);
1832 goto err_unbind;
1833 }
1834
1835 /*
1836 * Wait until the adapter init message is complete, and adapter
1837 * state is UP.
1838 */
1839 while (!test_bit(ADAPTER_STATE_UP, &hba->adapter_state) && i--)
1840 msleep(BNX2FC_INIT_POLL_TIME);
1841
1842 if (!test_bit(ADAPTER_STATE_UP, &hba->adapter_state)) {
1843 printk(KERN_ERR PFX "bnx2fc_start: %s failed to initialize. "
1844 "Ignoring...\n",
1845 hba->cnic->netdev->name);
1846 rc = -1;
1847 goto err_unbind;
1848 }
1849
1850
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001851 set_bit(BNX2FC_FLAG_FW_INIT_DONE, &hba->flags);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001852 return 0;
1853
1854err_unbind:
1855 bnx2fc_unbind_adapter_devices(hba);
1856err_out:
1857 return rc;
1858}
1859
1860static void bnx2fc_fw_destroy(struct bnx2fc_hba *hba)
1861{
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001862 if (test_and_clear_bit(BNX2FC_FLAG_FW_INIT_DONE, &hba->flags)) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001863 if (bnx2fc_send_fw_fcoe_destroy_msg(hba) == 0) {
1864 init_timer(&hba->destroy_timer);
1865 hba->destroy_timer.expires = BNX2FC_FW_TIMEOUT +
1866 jiffies;
1867 hba->destroy_timer.function = bnx2fc_destroy_timer;
1868 hba->destroy_timer.data = (unsigned long)hba;
1869 add_timer(&hba->destroy_timer);
1870 wait_event_interruptible(hba->destroy_wait,
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001871 test_bit(BNX2FC_FLAG_DESTROY_CMPL,
1872 &hba->flags));
Bhanu Prakash Gollapudicd703ae2011-08-04 17:38:43 -07001873 clear_bit(BNX2FC_FLAG_DESTROY_CMPL, &hba->flags);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001874 /* This should never happen */
1875 if (signal_pending(current))
1876 flush_signals(current);
1877
1878 del_timer_sync(&hba->destroy_timer);
1879 }
1880 bnx2fc_unbind_adapter_devices(hba);
1881 }
1882}
1883
1884/**
1885 * bnx2fc_ulp_stop - cnic callback to shutdown adapter instance
1886 *
1887 * @handle: transport handle pointing to adapter structure
1888 *
1889 * Driver checks if adapter is already in shutdown mode, if not start
1890 * the shutdown process.
1891 */
1892static void bnx2fc_ulp_stop(void *handle)
1893{
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001894 struct bnx2fc_hba *hba = handle;
1895 struct bnx2fc_interface *interface;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001896
1897 printk(KERN_ERR "ULP_STOP\n");
1898
1899 mutex_lock(&bnx2fc_dev_lock);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001900 if (!test_bit(BNX2FC_FLAG_FW_INIT_DONE, &hba->flags))
1901 goto exit;
1902 list_for_each_entry(interface, &if_list, list) {
1903 if (interface->hba == hba)
1904 bnx2fc_stop(interface);
1905 }
1906 BUG_ON(hba->num_ofld_sess != 0);
1907
1908 mutex_lock(&hba->hba_mutex);
1909 clear_bit(ADAPTER_STATE_UP, &hba->adapter_state);
1910 clear_bit(ADAPTER_STATE_GOING_DOWN,
1911 &hba->adapter_state);
1912
1913 clear_bit(ADAPTER_STATE_READY, &hba->adapter_state);
1914 mutex_unlock(&hba->hba_mutex);
1915
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001916 bnx2fc_fw_destroy(hba);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001917exit:
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001918 mutex_unlock(&bnx2fc_dev_lock);
1919}
1920
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001921static void bnx2fc_start_disc(struct bnx2fc_interface *interface)
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001922{
Robert Lovefd8f8902012-05-22 19:06:16 -07001923 struct fcoe_ctlr *ctlr = bnx2fc_to_ctlr(interface);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001924 struct fc_lport *lport;
1925 int wait_cnt = 0;
1926
1927 BNX2FC_MISC_DBG("Entered %s\n", __func__);
1928 /* Kick off FIP/FLOGI */
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001929 if (!test_bit(BNX2FC_FLAG_FW_INIT_DONE, &interface->hba->flags)) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001930 printk(KERN_ERR PFX "Init not done yet\n");
1931 return;
1932 }
1933
Robert Lovefd8f8902012-05-22 19:06:16 -07001934 lport = ctlr->lp;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001935 BNX2FC_HBA_DBG(lport, "calling fc_fabric_login\n");
1936
Bhanu Prakash Gollapudi8a5badf2011-08-30 15:54:48 -07001937 if (!bnx2fc_link_ok(lport) && interface->enabled) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001938 BNX2FC_HBA_DBG(lport, "ctlr_link_up\n");
Robert Lovefd8f8902012-05-22 19:06:16 -07001939 fcoe_ctlr_link_up(ctlr);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001940 fc_host_port_type(lport->host) = FC_PORTTYPE_NPORT;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001941 set_bit(ADAPTER_STATE_READY, &interface->hba->adapter_state);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001942 }
1943
1944 /* wait for the FCF to be selected before issuing FLOGI */
Robert Lovefd8f8902012-05-22 19:06:16 -07001945 while (!ctlr->sel_fcf) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001946 msleep(250);
1947 /* give up after 3 secs */
1948 if (++wait_cnt > 12)
1949 break;
1950 }
Bhanu Prakash Gollapudi627e6282011-08-04 17:38:35 -07001951
1952 /* Reset max receive frame size to default */
1953 if (fc_set_mfs(lport, BNX2FC_MFS))
1954 return;
1955
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001956 fc_lport_init(lport);
1957 fc_fabric_login(lport);
1958}
1959
1960
1961/**
1962 * bnx2fc_ulp_init - Initialize an adapter instance
1963 *
1964 * @dev : cnic device handle
1965 * Called from cnic_register_driver() context to initialize all
1966 * enumerated cnic devices. This routine allocates adapter structure
1967 * and other device specific resources.
1968 */
1969static void bnx2fc_ulp_init(struct cnic_dev *dev)
1970{
1971 struct bnx2fc_hba *hba;
1972 int rc = 0;
1973
1974 BNX2FC_MISC_DBG("Entered %s\n", __func__);
1975 /* bnx2fc works only when bnx2x is loaded */
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001976 if (!test_bit(CNIC_F_BNX2X_CLASS, &dev->flags) ||
1977 (dev->max_fcoe_conn == 0)) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001978 printk(KERN_ERR PFX "bnx2fc FCoE not supported on %s,"
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001979 " flags: %lx fcoe_conn: %d\n",
1980 dev->netdev->name, dev->flags, dev->max_fcoe_conn);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001981 return;
1982 }
1983
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001984 hba = bnx2fc_hba_create(dev);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001985 if (!hba) {
1986 printk(KERN_ERR PFX "hba initialization failed\n");
1987 return;
1988 }
1989
1990 /* Add HBA to the adapter list */
1991 mutex_lock(&bnx2fc_dev_lock);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07001992 list_add_tail(&hba->list, &adapter_list);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001993 adapter_count++;
1994 mutex_unlock(&bnx2fc_dev_lock);
1995
Barak Witkowski2e499d32012-06-26 01:31:19 +00001996 dev->fcoe_cap = &hba->fcoe_cap;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08001997 clear_bit(BNX2FC_CNIC_REGISTERED, &hba->reg_with_cnic);
1998 rc = dev->register_device(dev, CNIC_ULP_FCOE,
1999 (void *) hba);
2000 if (rc)
Bhanu Prakash Gollapudib2a554f2011-06-27 23:30:53 -07002001 printk(KERN_ERR PFX "register_device failed, rc = %d\n", rc);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002002 else
2003 set_bit(BNX2FC_CNIC_REGISTERED, &hba->reg_with_cnic);
2004}
2005
2006
2007static int bnx2fc_disable(struct net_device *netdev)
2008{
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002009 struct bnx2fc_interface *interface;
Robert Lovefd8f8902012-05-22 19:06:16 -07002010 struct fcoe_ctlr *ctlr;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002011 int rc = 0;
2012
Nithin Sujir6702ca12011-03-17 17:13:27 -07002013 rtnl_lock();
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002014 mutex_lock(&bnx2fc_dev_lock);
2015
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002016 interface = bnx2fc_interface_lookup(netdev);
Robert Lovefd8f8902012-05-22 19:06:16 -07002017 ctlr = bnx2fc_to_ctlr(interface);
2018 if (!interface || !ctlr->lp) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002019 rc = -ENODEV;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002020 printk(KERN_ERR PFX "bnx2fc_disable: interface or lport not found\n");
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002021 } else {
Bhanu Prakash Gollapudi8a5badf2011-08-30 15:54:48 -07002022 interface->enabled = false;
Robert Lovefd8f8902012-05-22 19:06:16 -07002023 fcoe_ctlr_link_down(ctlr);
2024 fcoe_clean_pending_queue(ctlr->lp);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002025 }
2026
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002027 mutex_unlock(&bnx2fc_dev_lock);
2028 rtnl_unlock();
2029 return rc;
2030}
2031
2032
2033static int bnx2fc_enable(struct net_device *netdev)
2034{
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002035 struct bnx2fc_interface *interface;
Robert Lovefd8f8902012-05-22 19:06:16 -07002036 struct fcoe_ctlr *ctlr;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002037 int rc = 0;
2038
Nithin Sujir6702ca12011-03-17 17:13:27 -07002039 rtnl_lock();
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002040 mutex_lock(&bnx2fc_dev_lock);
2041
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002042 interface = bnx2fc_interface_lookup(netdev);
Robert Lovefd8f8902012-05-22 19:06:16 -07002043 ctlr = bnx2fc_to_ctlr(interface);
2044 if (!interface || !ctlr->lp) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002045 rc = -ENODEV;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002046 printk(KERN_ERR PFX "bnx2fc_enable: interface or lport not found\n");
Robert Lovefd8f8902012-05-22 19:06:16 -07002047 } else if (!bnx2fc_link_ok(ctlr->lp)) {
2048 fcoe_ctlr_link_up(ctlr);
Bhanu Prakash Gollapudi8a5badf2011-08-30 15:54:48 -07002049 interface->enabled = true;
2050 }
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002051
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002052 mutex_unlock(&bnx2fc_dev_lock);
2053 rtnl_unlock();
2054 return rc;
2055}
2056
2057/**
2058 * bnx2fc_create - Create bnx2fc FCoE interface
2059 *
2060 * @buffer: The name of Ethernet interface to create on
2061 * @kp: The associated kernel param
2062 *
2063 * Called from sysfs.
2064 *
2065 * Returns: 0 for success
2066 */
2067static int bnx2fc_create(struct net_device *netdev, enum fip_state fip_mode)
2068{
Robert Lovefd8f8902012-05-22 19:06:16 -07002069 struct fcoe_ctlr *ctlr;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002070 struct bnx2fc_interface *interface;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002071 struct bnx2fc_hba *hba;
Bhanu Prakash Gollapudi7adc5a32012-06-04 16:15:44 -07002072 struct net_device *phys_dev = netdev;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002073 struct fc_lport *lport;
2074 struct ethtool_drvinfo drvinfo;
2075 int rc = 0;
Bhanu Prakash Gollapudi7adc5a32012-06-04 16:15:44 -07002076 int vlan_id = 0;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002077
2078 BNX2FC_MISC_DBG("Entered bnx2fc_create\n");
2079 if (fip_mode != FIP_MODE_FABRIC) {
2080 printk(KERN_ERR "fip mode not FABRIC\n");
2081 return -EIO;
2082 }
2083
Nithin Sujir6702ca12011-03-17 17:13:27 -07002084 rtnl_lock();
2085
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002086 mutex_lock(&bnx2fc_dev_lock);
2087
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002088 if (!try_module_get(THIS_MODULE)) {
2089 rc = -EINVAL;
2090 goto mod_err;
2091 }
2092
2093 /* obtain physical netdev */
Bhanu Prakash Gollapudi7adc5a32012-06-04 16:15:44 -07002094 if (netdev->priv_flags & IFF_802_1Q_VLAN)
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002095 phys_dev = vlan_dev_real_dev(netdev);
Bhanu Prakash Gollapudi7adc5a32012-06-04 16:15:44 -07002096
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002097 /* verify if the physical device is a netxtreme2 device */
2098 if (phys_dev->ethtool_ops && phys_dev->ethtool_ops->get_drvinfo) {
2099 memset(&drvinfo, 0, sizeof(drvinfo));
2100 phys_dev->ethtool_ops->get_drvinfo(phys_dev, &drvinfo);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002101 if (strncmp(drvinfo.driver, "bnx2x", strlen("bnx2x"))) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002102 printk(KERN_ERR PFX "Not a netxtreme2 device\n");
2103 rc = -EINVAL;
2104 goto netdev_err;
2105 }
2106 } else {
2107 printk(KERN_ERR PFX "unable to obtain drv_info\n");
2108 rc = -EINVAL;
2109 goto netdev_err;
2110 }
2111
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002112 /* obtain interface and initialize rest of the structure */
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002113 hba = bnx2fc_hba_lookup(phys_dev);
2114 if (!hba) {
2115 rc = -ENODEV;
2116 printk(KERN_ERR PFX "bnx2fc_create: hba not found\n");
2117 goto netdev_err;
2118 }
2119
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002120 if (bnx2fc_interface_lookup(netdev)) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002121 rc = -EEXIST;
2122 goto netdev_err;
2123 }
2124
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002125 interface = bnx2fc_interface_create(hba, netdev, fip_mode);
2126 if (!interface) {
2127 printk(KERN_ERR PFX "bnx2fc_interface_create failed\n");
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002128 goto ifput_err;
2129 }
2130
Bhanu Prakash Gollapudi7adc5a32012-06-04 16:15:44 -07002131 if (netdev->priv_flags & IFF_802_1Q_VLAN) {
2132 vlan_id = vlan_dev_vlan_id(netdev);
2133 interface->vlan_enabled = 1;
2134 }
2135
Robert Lovefd8f8902012-05-22 19:06:16 -07002136 ctlr = bnx2fc_to_ctlr(interface);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002137 interface->vlan_id = vlan_id;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002138
2139 interface->timer_work_queue =
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002140 create_singlethread_workqueue("bnx2fc_timer_wq");
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002141 if (!interface->timer_work_queue) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002142 printk(KERN_ERR PFX "ulp_init could not create timer_wq\n");
2143 rc = -EINVAL;
2144 goto ifput_err;
2145 }
2146
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002147 lport = bnx2fc_if_create(interface, &interface->hba->pcidev->dev, 0);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002148 if (!lport) {
2149 printk(KERN_ERR PFX "Failed to create interface (%s)\n",
2150 netdev->name);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002151 rc = -EINVAL;
2152 goto if_create_err;
2153 }
2154
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002155 /* Add interface to if_list */
2156 list_add_tail(&interface->list, &if_list);
2157
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002158 lport->boot_time = jiffies;
2159
2160 /* Make this master N_port */
Robert Lovefd8f8902012-05-22 19:06:16 -07002161 ctlr->lp = lport;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002162
Bhanu Prakash Gollapudi8a5badf2011-08-30 15:54:48 -07002163 if (!bnx2fc_link_ok(lport)) {
Robert Lovefd8f8902012-05-22 19:06:16 -07002164 fcoe_ctlr_link_up(ctlr);
Bhanu Prakash Gollapudi8a5badf2011-08-30 15:54:48 -07002165 fc_host_port_type(lport->host) = FC_PORTTYPE_NPORT;
2166 set_bit(ADAPTER_STATE_READY, &interface->hba->adapter_state);
2167 }
2168
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002169 BNX2FC_HBA_DBG(lport, "create: START DISC\n");
2170 bnx2fc_start_disc(interface);
Bhanu Prakash Gollapudi8a5badf2011-08-30 15:54:48 -07002171 interface->enabled = true;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002172 /*
2173 * Release from kref_init in bnx2fc_interface_setup, on success
2174 * lport should be holding a reference taken in bnx2fc_if_create
2175 */
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002176 bnx2fc_interface_put(interface);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002177 /* put netdev that was held while calling dev_get_by_name */
2178 mutex_unlock(&bnx2fc_dev_lock);
2179 rtnl_unlock();
2180 return 0;
2181
2182if_create_err:
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002183 destroy_workqueue(interface->timer_work_queue);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002184ifput_err:
Bhanu Prakash Gollapudi013068f2011-08-30 15:54:52 -07002185 bnx2fc_net_cleanup(interface);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002186 bnx2fc_interface_put(interface);
Bhanu Prakash Gollapudi7d742f62012-01-23 18:00:48 -08002187 goto mod_err;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002188netdev_err:
2189 module_put(THIS_MODULE);
2190mod_err:
2191 mutex_unlock(&bnx2fc_dev_lock);
2192 rtnl_unlock();
2193 return rc;
2194}
2195
2196/**
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002197 * bnx2fc_find_hba_for_cnic - maps cnic instance to bnx2fc hba instance
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002198 *
2199 * @cnic: Pointer to cnic device instance
2200 *
2201 **/
2202static struct bnx2fc_hba *bnx2fc_find_hba_for_cnic(struct cnic_dev *cnic)
2203{
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002204 struct bnx2fc_hba *hba;
2205
2206 /* Called with bnx2fc_dev_lock held */
Bhanu Prakash Gollapudid71fb3b2012-06-07 02:19:36 -07002207 list_for_each_entry(hba, &adapter_list, list) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002208 if (hba->cnic == cnic)
2209 return hba;
2210 }
2211 return NULL;
2212}
2213
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002214static struct bnx2fc_interface *bnx2fc_interface_lookup(struct net_device
2215 *netdev)
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002216{
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002217 struct bnx2fc_interface *interface;
2218
2219 /* Called with bnx2fc_dev_lock held */
2220 list_for_each_entry(interface, &if_list, list) {
2221 if (interface->netdev == netdev)
2222 return interface;
2223 }
2224 return NULL;
2225}
2226
2227static struct bnx2fc_hba *bnx2fc_hba_lookup(struct net_device
2228 *phys_dev)
2229{
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002230 struct bnx2fc_hba *hba;
2231
2232 /* Called with bnx2fc_dev_lock held */
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002233 list_for_each_entry(hba, &adapter_list, list) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002234 if (hba->phys_dev == phys_dev)
2235 return hba;
2236 }
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002237 printk(KERN_ERR PFX "adapter_lookup: hba NULL\n");
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002238 return NULL;
2239}
2240
2241/**
2242 * bnx2fc_ulp_exit - shuts down adapter instance and frees all resources
2243 *
2244 * @dev cnic device handle
2245 */
2246static void bnx2fc_ulp_exit(struct cnic_dev *dev)
2247{
2248 struct bnx2fc_hba *hba;
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002249 struct bnx2fc_interface *interface, *tmp;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002250
2251 BNX2FC_MISC_DBG("Entered bnx2fc_ulp_exit\n");
2252
2253 if (!test_bit(CNIC_F_BNX2X_CLASS, &dev->flags)) {
2254 printk(KERN_ERR PFX "bnx2fc port check: %s, flags: %lx\n",
2255 dev->netdev->name, dev->flags);
2256 return;
2257 }
2258
2259 mutex_lock(&bnx2fc_dev_lock);
2260 hba = bnx2fc_find_hba_for_cnic(dev);
2261 if (!hba) {
2262 printk(KERN_ERR PFX "bnx2fc_ulp_exit: hba not found, dev 0%p\n",
2263 dev);
2264 mutex_unlock(&bnx2fc_dev_lock);
2265 return;
2266 }
2267
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002268 list_del_init(&hba->list);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002269 adapter_count--;
2270
Bhanu Prakash Gollapudiabc49a92011-08-04 17:38:42 -07002271 list_for_each_entry_safe(interface, tmp, &if_list, list)
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002272 /* destroy not called yet, move to quiesced list */
Bhanu Prakash Gollapudiabc49a92011-08-04 17:38:42 -07002273 if (interface->hba == hba)
Bhanu Prakash Gollapudieccdcd02011-08-24 18:56:42 -07002274 __bnx2fc_destroy(interface);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002275 mutex_unlock(&bnx2fc_dev_lock);
2276
2277 bnx2fc_ulp_stop(hba);
2278 /* unregister cnic device */
2279 if (test_and_clear_bit(BNX2FC_CNIC_REGISTERED, &hba->reg_with_cnic))
2280 hba->cnic->unregister_device(hba->cnic, CNIC_ULP_FCOE);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002281 bnx2fc_hba_destroy(hba);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002282}
2283
2284/**
2285 * bnx2fc_fcoe_reset - Resets the fcoe
2286 *
2287 * @shost: shost the reset is from
2288 *
2289 * Returns: always 0
2290 */
2291static int bnx2fc_fcoe_reset(struct Scsi_Host *shost)
2292{
2293 struct fc_lport *lport = shost_priv(shost);
2294 fc_lport_reset(lport);
2295 return 0;
2296}
2297
2298
2299static bool bnx2fc_match(struct net_device *netdev)
2300{
Bhanu Prakash Gollapudi7adc5a32012-06-04 16:15:44 -07002301 struct net_device *phys_dev = netdev;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002302
Bhanu Prakash Gollapudi7adc5a32012-06-04 16:15:44 -07002303 mutex_lock(&bnx2fc_dev_lock);
2304 if (netdev->priv_flags & IFF_802_1Q_VLAN)
2305 phys_dev = vlan_dev_real_dev(netdev);
2306
2307 if (bnx2fc_hba_lookup(phys_dev)) {
2308 mutex_unlock(&bnx2fc_dev_lock);
2309 return true;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002310 }
Bhanu Prakash Gollapudi7adc5a32012-06-04 16:15:44 -07002311
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002312 mutex_unlock(&bnx2fc_dev_lock);
2313 return false;
2314}
2315
2316
2317static struct fcoe_transport bnx2fc_transport = {
2318 .name = {"bnx2fc"},
2319 .attached = false,
2320 .list = LIST_HEAD_INIT(bnx2fc_transport.list),
2321 .match = bnx2fc_match,
2322 .create = bnx2fc_create,
2323 .destroy = bnx2fc_destroy,
2324 .enable = bnx2fc_enable,
2325 .disable = bnx2fc_disable,
2326};
2327
2328/**
2329 * bnx2fc_percpu_thread_create - Create a receive thread for an
2330 * online CPU
2331 *
2332 * @cpu: cpu index for the online cpu
2333 */
2334static void bnx2fc_percpu_thread_create(unsigned int cpu)
2335{
2336 struct bnx2fc_percpu_s *p;
2337 struct task_struct *thread;
2338
2339 p = &per_cpu(bnx2fc_percpu, cpu);
2340
Eric Dumazet69614272012-06-04 16:15:42 -07002341 thread = kthread_create_on_node(bnx2fc_percpu_io_thread,
2342 (void *)p, cpu_to_node(cpu),
2343 "bnx2fc_thread/%d", cpu);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002344 /* bind thread to the cpu */
Bhanu Prakash Gollapudi32248762011-08-04 17:38:36 -07002345 if (likely(!IS_ERR(thread))) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002346 kthread_bind(thread, cpu);
2347 p->iothread = thread;
2348 wake_up_process(thread);
2349 }
2350}
2351
2352static void bnx2fc_percpu_thread_destroy(unsigned int cpu)
2353{
2354 struct bnx2fc_percpu_s *p;
2355 struct task_struct *thread;
2356 struct bnx2fc_work *work, *tmp;
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002357
2358 BNX2FC_MISC_DBG("destroying io thread for CPU %d\n", cpu);
2359
2360 /* Prevent any new work from being queued for this CPU */
2361 p = &per_cpu(bnx2fc_percpu, cpu);
2362 spin_lock_bh(&p->fp_work_lock);
2363 thread = p->iothread;
2364 p->iothread = NULL;
2365
2366
2367 /* Free all work in the list */
Bhanu Prakash Gollapudi32248762011-08-04 17:38:36 -07002368 list_for_each_entry_safe(work, tmp, &p->work_list, list) {
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002369 list_del_init(&work->list);
2370 bnx2fc_process_cq_compl(work->tgt, work->wqe);
2371 kfree(work);
2372 }
2373
2374 spin_unlock_bh(&p->fp_work_lock);
2375
2376 if (thread)
2377 kthread_stop(thread);
2378}
2379
2380/**
2381 * bnx2fc_cpu_callback - Handler for CPU hotplug events
2382 *
2383 * @nfb: The callback data block
2384 * @action: The event triggering the callback
2385 * @hcpu: The index of the CPU that the event is for
2386 *
2387 * This creates or destroys per-CPU data for fcoe
2388 *
2389 * Returns NOTIFY_OK always.
2390 */
2391static int bnx2fc_cpu_callback(struct notifier_block *nfb,
2392 unsigned long action, void *hcpu)
2393{
2394 unsigned cpu = (unsigned long)hcpu;
2395
2396 switch (action) {
2397 case CPU_ONLINE:
2398 case CPU_ONLINE_FROZEN:
2399 printk(PFX "CPU %x online: Create Rx thread\n", cpu);
2400 bnx2fc_percpu_thread_create(cpu);
2401 break;
2402 case CPU_DEAD:
2403 case CPU_DEAD_FROZEN:
2404 printk(PFX "CPU %x offline: Remove Rx thread\n", cpu);
2405 bnx2fc_percpu_thread_destroy(cpu);
2406 break;
2407 default:
2408 break;
2409 }
2410 return NOTIFY_OK;
2411}
2412
2413/**
2414 * bnx2fc_mod_init - module init entry point
2415 *
2416 * Initialize driver wide global data structures, and register
2417 * with cnic module
2418 **/
2419static int __init bnx2fc_mod_init(void)
2420{
2421 struct fcoe_percpu_s *bg;
2422 struct task_struct *l2_thread;
2423 int rc = 0;
2424 unsigned int cpu = 0;
2425 struct bnx2fc_percpu_s *p;
2426
2427 printk(KERN_INFO PFX "%s", version);
2428
2429 /* register as a fcoe transport */
2430 rc = fcoe_transport_attach(&bnx2fc_transport);
2431 if (rc) {
2432 printk(KERN_ERR "failed to register an fcoe transport, check "
2433 "if libfcoe is loaded\n");
2434 goto out;
2435 }
2436
2437 INIT_LIST_HEAD(&adapter_list);
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002438 INIT_LIST_HEAD(&if_list);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002439 mutex_init(&bnx2fc_dev_lock);
2440 adapter_count = 0;
2441
2442 /* Attach FC transport template */
2443 rc = bnx2fc_attach_transport();
2444 if (rc)
2445 goto detach_ft;
2446
2447 bnx2fc_wq = alloc_workqueue("bnx2fc", 0, 0);
2448 if (!bnx2fc_wq) {
2449 rc = -ENOMEM;
2450 goto release_bt;
2451 }
2452
2453 bg = &bnx2fc_global;
2454 skb_queue_head_init(&bg->fcoe_rx_list);
2455 l2_thread = kthread_create(bnx2fc_l2_rcv_thread,
2456 (void *)bg,
2457 "bnx2fc_l2_thread");
2458 if (IS_ERR(l2_thread)) {
2459 rc = PTR_ERR(l2_thread);
2460 goto free_wq;
2461 }
2462 wake_up_process(l2_thread);
2463 spin_lock_bh(&bg->fcoe_rx_list.lock);
2464 bg->thread = l2_thread;
2465 spin_unlock_bh(&bg->fcoe_rx_list.lock);
2466
2467 for_each_possible_cpu(cpu) {
2468 p = &per_cpu(bnx2fc_percpu, cpu);
2469 INIT_LIST_HEAD(&p->work_list);
2470 spin_lock_init(&p->fp_work_lock);
2471 }
2472
2473 for_each_online_cpu(cpu) {
2474 bnx2fc_percpu_thread_create(cpu);
2475 }
2476
2477 /* Initialize per CPU interrupt thread */
2478 register_hotcpu_notifier(&bnx2fc_cpu_notifier);
2479
2480 cnic_register_driver(CNIC_ULP_FCOE, &bnx2fc_cnic_cb);
2481
2482 return 0;
2483
2484free_wq:
2485 destroy_workqueue(bnx2fc_wq);
2486release_bt:
2487 bnx2fc_release_transport();
2488detach_ft:
2489 fcoe_transport_detach(&bnx2fc_transport);
2490out:
2491 return rc;
2492}
2493
2494static void __exit bnx2fc_mod_exit(void)
2495{
2496 LIST_HEAD(to_be_deleted);
2497 struct bnx2fc_hba *hba, *next;
2498 struct fcoe_percpu_s *bg;
2499 struct task_struct *l2_thread;
2500 struct sk_buff *skb;
2501 unsigned int cpu = 0;
2502
2503 /*
2504 * NOTE: Since cnic calls register_driver routine rtnl_lock,
2505 * it will have higher precedence than bnx2fc_dev_lock.
2506 * unregister_device() cannot be called with bnx2fc_dev_lock
2507 * held.
2508 */
2509 mutex_lock(&bnx2fc_dev_lock);
2510 list_splice(&adapter_list, &to_be_deleted);
2511 INIT_LIST_HEAD(&adapter_list);
2512 adapter_count = 0;
2513 mutex_unlock(&bnx2fc_dev_lock);
2514
2515 /* Unregister with cnic */
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002516 list_for_each_entry_safe(hba, next, &to_be_deleted, list) {
2517 list_del_init(&hba->list);
2518 printk(KERN_ERR PFX "MOD_EXIT:destroy hba = 0x%p\n",
2519 hba);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002520 bnx2fc_ulp_stop(hba);
2521 /* unregister cnic device */
2522 if (test_and_clear_bit(BNX2FC_CNIC_REGISTERED,
2523 &hba->reg_with_cnic))
Bhanu Prakash Gollapudiaea71a02011-07-26 14:51:39 -07002524 hba->cnic->unregister_device(hba->cnic,
2525 CNIC_ULP_FCOE);
2526 bnx2fc_hba_destroy(hba);
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002527 }
2528 cnic_unregister_driver(CNIC_ULP_FCOE);
2529
2530 /* Destroy global thread */
2531 bg = &bnx2fc_global;
2532 spin_lock_bh(&bg->fcoe_rx_list.lock);
2533 l2_thread = bg->thread;
2534 bg->thread = NULL;
2535 while ((skb = __skb_dequeue(&bg->fcoe_rx_list)) != NULL)
2536 kfree_skb(skb);
2537
2538 spin_unlock_bh(&bg->fcoe_rx_list.lock);
2539
2540 if (l2_thread)
2541 kthread_stop(l2_thread);
2542
2543 unregister_hotcpu_notifier(&bnx2fc_cpu_notifier);
2544
2545 /* Destroy per cpu threads */
2546 for_each_online_cpu(cpu) {
2547 bnx2fc_percpu_thread_destroy(cpu);
2548 }
2549
2550 destroy_workqueue(bnx2fc_wq);
2551 /*
2552 * detach from scsi transport
2553 * must happen after all destroys are done
2554 */
2555 bnx2fc_release_transport();
2556
2557 /* detach from fcoe transport */
2558 fcoe_transport_detach(&bnx2fc_transport);
2559}
2560
2561module_init(bnx2fc_mod_init);
2562module_exit(bnx2fc_mod_exit);
2563
Robert Love8d55e502012-05-22 19:06:26 -07002564static struct fcoe_sysfs_function_template bnx2fc_fcoe_sysfs_templ = {
2565 .get_fcoe_ctlr_mode = fcoe_ctlr_get_fip_mode,
2566 .get_fcoe_ctlr_link_fail = bnx2fc_ctlr_get_lesb,
2567 .get_fcoe_ctlr_vlink_fail = bnx2fc_ctlr_get_lesb,
2568 .get_fcoe_ctlr_miss_fka = bnx2fc_ctlr_get_lesb,
2569 .get_fcoe_ctlr_symb_err = bnx2fc_ctlr_get_lesb,
2570 .get_fcoe_ctlr_err_block = bnx2fc_ctlr_get_lesb,
2571 .get_fcoe_ctlr_fcs_error = bnx2fc_ctlr_get_lesb,
2572
2573 .get_fcoe_fcf_selected = fcoe_fcf_get_selected,
2574 .get_fcoe_fcf_vlan_id = bnx2fc_fcf_get_vlan_id,
2575};
2576
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002577static struct fc_function_template bnx2fc_transport_function = {
2578 .show_host_node_name = 1,
2579 .show_host_port_name = 1,
2580 .show_host_supported_classes = 1,
2581 .show_host_supported_fc4s = 1,
2582 .show_host_active_fc4s = 1,
2583 .show_host_maxframe_size = 1,
2584
2585 .show_host_port_id = 1,
2586 .show_host_supported_speeds = 1,
2587 .get_host_speed = fc_get_host_speed,
2588 .show_host_speed = 1,
2589 .show_host_port_type = 1,
2590 .get_host_port_state = fc_get_host_port_state,
2591 .show_host_port_state = 1,
2592 .show_host_symbolic_name = 1,
2593
2594 .dd_fcrport_size = (sizeof(struct fc_rport_libfc_priv) +
2595 sizeof(struct bnx2fc_rport)),
2596 .show_rport_maxframe_size = 1,
2597 .show_rport_supported_classes = 1,
2598
2599 .show_host_fabric_name = 1,
2600 .show_starget_node_name = 1,
2601 .show_starget_port_name = 1,
2602 .show_starget_port_id = 1,
2603 .set_rport_dev_loss_tmo = fc_set_rport_loss_tmo,
2604 .show_rport_dev_loss_tmo = 1,
2605 .get_fc_host_stats = bnx2fc_get_host_stats,
2606
2607 .issue_fc_host_lip = bnx2fc_fcoe_reset,
2608
2609 .terminate_rport_io = fc_rport_terminate_io,
2610
2611 .vport_create = bnx2fc_vport_create,
2612 .vport_delete = bnx2fc_vport_destroy,
2613 .vport_disable = bnx2fc_vport_disable,
Bhanu Prakash Gollapudie9a5289c2011-08-04 17:38:37 -07002614 .bsg_request = fc_lport_bsg_request,
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002615};
2616
2617static struct fc_function_template bnx2fc_vport_xport_function = {
2618 .show_host_node_name = 1,
2619 .show_host_port_name = 1,
2620 .show_host_supported_classes = 1,
2621 .show_host_supported_fc4s = 1,
2622 .show_host_active_fc4s = 1,
2623 .show_host_maxframe_size = 1,
2624
2625 .show_host_port_id = 1,
2626 .show_host_supported_speeds = 1,
2627 .get_host_speed = fc_get_host_speed,
2628 .show_host_speed = 1,
2629 .show_host_port_type = 1,
2630 .get_host_port_state = fc_get_host_port_state,
2631 .show_host_port_state = 1,
2632 .show_host_symbolic_name = 1,
2633
2634 .dd_fcrport_size = (sizeof(struct fc_rport_libfc_priv) +
2635 sizeof(struct bnx2fc_rport)),
2636 .show_rport_maxframe_size = 1,
2637 .show_rport_supported_classes = 1,
2638
2639 .show_host_fabric_name = 1,
2640 .show_starget_node_name = 1,
2641 .show_starget_port_name = 1,
2642 .show_starget_port_id = 1,
2643 .set_rport_dev_loss_tmo = fc_set_rport_loss_tmo,
2644 .show_rport_dev_loss_tmo = 1,
2645 .get_fc_host_stats = fc_get_host_stats,
2646 .issue_fc_host_lip = bnx2fc_fcoe_reset,
2647 .terminate_rport_io = fc_rport_terminate_io,
Bhanu Prakash Gollapudie9a5289c2011-08-04 17:38:37 -07002648 .bsg_request = fc_lport_bsg_request,
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002649};
2650
2651/**
2652 * scsi_host_template structure used while registering with SCSI-ml
2653 */
2654static struct scsi_host_template bnx2fc_shost_template = {
2655 .module = THIS_MODULE,
2656 .name = "Broadcom Offload FCoE Initiator",
2657 .queuecommand = bnx2fc_queuecommand,
2658 .eh_abort_handler = bnx2fc_eh_abort, /* abts */
2659 .eh_device_reset_handler = bnx2fc_eh_device_reset, /* lun reset */
2660 .eh_target_reset_handler = bnx2fc_eh_target_reset, /* tgt reset */
2661 .eh_host_reset_handler = fc_eh_host_reset,
2662 .slave_alloc = fc_slave_alloc,
2663 .change_queue_depth = fc_change_queue_depth,
2664 .change_queue_type = fc_change_queue_type,
2665 .this_id = -1,
2666 .cmd_per_lun = 3,
Bhanu Gollapudi0ea5c272011-03-17 17:13:29 -07002667 .can_queue = BNX2FC_CAN_QUEUE,
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002668 .use_clustering = ENABLE_CLUSTERING,
2669 .sg_tablesize = BNX2FC_MAX_BDS_PER_CMD,
Bhanu Prakash Gollapudid450d772012-12-21 19:40:33 -08002670 .max_sectors = 1024,
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002671};
2672
2673static struct libfc_function_template bnx2fc_libfc_fcn_templ = {
2674 .frame_send = bnx2fc_xmit,
2675 .elsct_send = bnx2fc_elsct_send,
2676 .fcp_abort_io = bnx2fc_abort_io,
2677 .fcp_cleanup = bnx2fc_cleanup,
Bhanu Prakash Gollapudif72f6972011-10-03 16:45:02 -07002678 .get_lesb = bnx2fc_get_lesb,
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002679 .rport_event_callback = bnx2fc_rport_event_handler,
2680};
2681
2682/**
2683 * bnx2fc_cnic_cb - global template of bnx2fc - cnic driver interface
2684 * structure carrying callback function pointers
2685 */
2686static struct cnic_ulp_ops bnx2fc_cnic_cb = {
2687 .owner = THIS_MODULE,
2688 .cnic_init = bnx2fc_ulp_init,
2689 .cnic_exit = bnx2fc_ulp_exit,
2690 .cnic_start = bnx2fc_ulp_start,
2691 .cnic_stop = bnx2fc_ulp_stop,
2692 .indicate_kcqes = bnx2fc_indicate_kcqe,
2693 .indicate_netevent = bnx2fc_indicate_netevent,
Barak Witkowski2e499d32012-06-26 01:31:19 +00002694 .cnic_get_stats = bnx2fc_ulp_get_stats,
Bhanu Gollapudi853e2bd2011-02-04 12:10:34 -08002695};