]>
Commit | Line | Data |
---|---|---|
de909d87 | 1 | /* bnx2fc_fcoe.c: QLogic Linux FCoE offload driver. |
853e2bd2 BG |
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 | * | |
97586090 CD |
6 | * Copyright (c) 2008-2013 Broadcom Corporation |
7 | * Copyright (c) 2014-2015 QLogic Corporation | |
853e2bd2 BG |
8 | * |
9 | * This program is free software; you can redistribute it and/or modify | |
10 | * it under the terms of the GNU General Public License as published by | |
11 | * the Free Software Foundation. | |
12 | * | |
13 | * Written by: Bhanu Prakash Gollapudi (bprakash@broadcom.com) | |
14 | */ | |
15 | ||
16 | #include "bnx2fc.h" | |
17 | ||
18 | static struct list_head adapter_list; | |
aea71a02 | 19 | static struct list_head if_list; |
853e2bd2 BG |
20 | static u32 adapter_count; |
21 | static DEFINE_MUTEX(bnx2fc_dev_lock); | |
22 | DEFINE_PER_CPU(struct bnx2fc_percpu_s, bnx2fc_percpu); | |
23 | ||
24 | #define DRV_MODULE_NAME "bnx2fc" | |
25 | #define DRV_MODULE_VERSION BNX2FC_VERSION | |
edb394b5 | 26 | #define DRV_MODULE_RELDATE "October 15, 2015" |
853e2bd2 BG |
27 | |
28 | ||
6f039790 | 29 | static char version[] = |
de909d87 | 30 | "QLogic FCoE Driver " DRV_MODULE_NAME \ |
853e2bd2 BG |
31 | " v" DRV_MODULE_VERSION " (" DRV_MODULE_RELDATE ")\n"; |
32 | ||
33 | ||
34 | MODULE_AUTHOR("Bhanu Prakash Gollapudi <bprakash@broadcom.com>"); | |
de909d87 | 35 | MODULE_DESCRIPTION("QLogic FCoE Driver"); |
853e2bd2 BG |
36 | MODULE_LICENSE("GPL"); |
37 | MODULE_VERSION(DRV_MODULE_VERSION); | |
38 | ||
39 | #define BNX2FC_MAX_QUEUE_DEPTH 256 | |
40 | #define BNX2FC_MIN_QUEUE_DEPTH 32 | |
41 | #define FCOE_WORD_TO_BYTE 4 | |
42 | ||
43 | static struct scsi_transport_template *bnx2fc_transport_template; | |
44 | static struct scsi_transport_template *bnx2fc_vport_xport_template; | |
45 | ||
46 | struct workqueue_struct *bnx2fc_wq; | |
47 | ||
48 | /* bnx2fc structure needs only one instance of the fcoe_percpu_s structure. | |
49 | * Here the io threads are per cpu but the l2 thread is just one | |
50 | */ | |
51 | struct fcoe_percpu_s bnx2fc_global; | |
52 | DEFINE_SPINLOCK(bnx2fc_global_lock); | |
53 | ||
54 | static struct cnic_ulp_ops bnx2fc_cnic_cb; | |
55 | static struct libfc_function_template bnx2fc_libfc_fcn_templ; | |
56 | static struct scsi_host_template bnx2fc_shost_template; | |
57 | static struct fc_function_template bnx2fc_transport_function; | |
8d55e507 | 58 | static struct fcoe_sysfs_function_template bnx2fc_fcoe_sysfs_templ; |
853e2bd2 BG |
59 | static struct fc_function_template bnx2fc_vport_xport_function; |
60 | static int bnx2fc_create(struct net_device *netdev, enum fip_state fip_mode); | |
eccdcd02 | 61 | static void __bnx2fc_destroy(struct bnx2fc_interface *interface); |
853e2bd2 BG |
62 | static int bnx2fc_destroy(struct net_device *net_device); |
63 | static int bnx2fc_enable(struct net_device *netdev); | |
64 | static int bnx2fc_disable(struct net_device *netdev); | |
65 | ||
6e89ea3f RL |
66 | /* fcoe_syfs control interface handlers */ |
67 | static int bnx2fc_ctlr_alloc(struct net_device *netdev); | |
68 | static int bnx2fc_ctlr_enabled(struct fcoe_ctlr_device *cdev); | |
69 | ||
853e2bd2 BG |
70 | static void bnx2fc_recv_frame(struct sk_buff *skb); |
71 | ||
aea71a02 | 72 | static void bnx2fc_start_disc(struct bnx2fc_interface *interface); |
853e2bd2 | 73 | static int bnx2fc_shost_config(struct fc_lport *lport, struct device *dev); |
853e2bd2 | 74 | static int bnx2fc_lport_config(struct fc_lport *lport); |
0eb43b4b | 75 | static int bnx2fc_em_config(struct fc_lport *lport, struct bnx2fc_hba *hba); |
853e2bd2 BG |
76 | static int bnx2fc_bind_adapter_devices(struct bnx2fc_hba *hba); |
77 | static void bnx2fc_unbind_adapter_devices(struct bnx2fc_hba *hba); | |
78 | static int bnx2fc_bind_pcidev(struct bnx2fc_hba *hba); | |
79 | static void bnx2fc_unbind_pcidev(struct bnx2fc_hba *hba); | |
aea71a02 | 80 | static struct fc_lport *bnx2fc_if_create(struct bnx2fc_interface *interface, |
853e2bd2 BG |
81 | struct device *parent, int npiv); |
82 | static void bnx2fc_destroy_work(struct work_struct *work); | |
83 | ||
84 | static struct bnx2fc_hba *bnx2fc_hba_lookup(struct net_device *phys_dev); | |
aea71a02 BPG |
85 | static struct bnx2fc_interface *bnx2fc_interface_lookup(struct net_device |
86 | *phys_dev); | |
abc49a93 | 87 | static inline void bnx2fc_interface_put(struct bnx2fc_interface *interface); |
853e2bd2 BG |
88 | static struct bnx2fc_hba *bnx2fc_find_hba_for_cnic(struct cnic_dev *cnic); |
89 | ||
90 | static int bnx2fc_fw_init(struct bnx2fc_hba *hba); | |
91 | static void bnx2fc_fw_destroy(struct bnx2fc_hba *hba); | |
92 | ||
93 | static void bnx2fc_port_shutdown(struct fc_lport *lport); | |
aea71a02 | 94 | static void bnx2fc_stop(struct bnx2fc_interface *interface); |
853e2bd2 BG |
95 | static int __init bnx2fc_mod_init(void); |
96 | static void __exit bnx2fc_mod_exit(void); | |
97 | ||
98 | unsigned int bnx2fc_debug_level; | |
99 | module_param_named(debug_logging, bnx2fc_debug_level, int, S_IRUGO|S_IWUSR); | |
d4faee08 JC |
100 | MODULE_PARM_DESC(debug_logging, |
101 | "Option to enable extended logging,\n" | |
102 | "\t\tDefault is 0 - no logging.\n" | |
103 | "\t\t0x01 - SCSI cmd error, cleanup.\n" | |
104 | "\t\t0x02 - Session setup, cleanup, etc.\n" | |
105 | "\t\t0x04 - lport events, link, mtu, etc.\n" | |
106 | "\t\t0x08 - ELS logs.\n" | |
107 | "\t\t0x10 - fcoe L2 fame related logs.\n" | |
108 | "\t\t0xff - LOG all messages."); | |
853e2bd2 | 109 | |
10755d3f JC |
110 | uint bnx2fc_devloss_tmo; |
111 | module_param_named(devloss_tmo, bnx2fc_devloss_tmo, uint, S_IRUGO); | |
112 | MODULE_PARM_DESC(devloss_tmo, " Change devloss_tmo for the remote ports " | |
113 | "attached via bnx2fc."); | |
114 | ||
115 | uint bnx2fc_max_luns = BNX2FC_MAX_LUN; | |
116 | module_param_named(max_luns, bnx2fc_max_luns, uint, S_IRUGO); | |
117 | MODULE_PARM_DESC(max_luns, " Change the default max_lun per SCSI host. Default " | |
118 | "0xffff."); | |
119 | ||
120 | uint bnx2fc_queue_depth; | |
121 | module_param_named(queue_depth, bnx2fc_queue_depth, uint, S_IRUGO); | |
122 | MODULE_PARM_DESC(queue_depth, " Change the default queue depth of SCSI devices " | |
123 | "attached via bnx2fc."); | |
124 | ||
853e2bd2 BG |
125 | static int bnx2fc_cpu_callback(struct notifier_block *nfb, |
126 | unsigned long action, void *hcpu); | |
127 | /* notification function for CPU hotplug events */ | |
128 | static struct notifier_block bnx2fc_cpu_notifier = { | |
129 | .notifier_call = bnx2fc_cpu_callback, | |
130 | }; | |
131 | ||
f72f6979 BPG |
132 | static inline struct net_device *bnx2fc_netdev(const struct fc_lport *lport) |
133 | { | |
134 | return ((struct bnx2fc_interface *) | |
135 | ((struct fcoe_port *)lport_priv(lport))->priv)->netdev; | |
136 | } | |
137 | ||
8d55e507 RL |
138 | static void bnx2fc_fcf_get_vlan_id(struct fcoe_fcf_device *fcf_dev) |
139 | { | |
140 | struct fcoe_ctlr_device *ctlr_dev = | |
141 | fcoe_fcf_dev_to_ctlr_dev(fcf_dev); | |
142 | struct fcoe_ctlr *ctlr = fcoe_ctlr_device_priv(ctlr_dev); | |
143 | struct bnx2fc_interface *fcoe = fcoe_ctlr_priv(ctlr); | |
144 | ||
145 | fcf_dev->vlan_id = fcoe->vlan_id; | |
146 | } | |
147 | ||
853e2bd2 BG |
148 | static void bnx2fc_clean_rx_queue(struct fc_lport *lp) |
149 | { | |
150 | struct fcoe_percpu_s *bg; | |
151 | struct fcoe_rcv_info *fr; | |
152 | struct sk_buff_head *list; | |
153 | struct sk_buff *skb, *next; | |
154 | struct sk_buff *head; | |
155 | ||
156 | bg = &bnx2fc_global; | |
157 | spin_lock_bh(&bg->fcoe_rx_list.lock); | |
158 | list = &bg->fcoe_rx_list; | |
159 | head = list->next; | |
160 | for (skb = head; skb != (struct sk_buff *)list; | |
161 | skb = next) { | |
162 | next = skb->next; | |
163 | fr = fcoe_dev_from_skb(skb); | |
164 | if (fr->fr_dev == lp) { | |
165 | __skb_unlink(skb, list); | |
166 | kfree_skb(skb); | |
167 | } | |
168 | } | |
169 | spin_unlock_bh(&bg->fcoe_rx_list.lock); | |
170 | } | |
171 | ||
172 | int bnx2fc_get_paged_crc_eof(struct sk_buff *skb, int tlen) | |
173 | { | |
174 | int rc; | |
175 | spin_lock(&bnx2fc_global_lock); | |
176 | rc = fcoe_get_paged_crc_eof(skb, tlen, &bnx2fc_global); | |
177 | spin_unlock(&bnx2fc_global_lock); | |
178 | ||
179 | return rc; | |
180 | } | |
181 | ||
182 | static void bnx2fc_abort_io(struct fc_lport *lport) | |
183 | { | |
184 | /* | |
185 | * This function is no-op for bnx2fc, but we do | |
186 | * not want to leave it as NULL either, as libfc | |
187 | * can call the default function which is | |
188 | * fc_fcp_abort_io. | |
189 | */ | |
190 | } | |
191 | ||
192 | static void bnx2fc_cleanup(struct fc_lport *lport) | |
193 | { | |
194 | struct fcoe_port *port = lport_priv(lport); | |
aea71a02 BPG |
195 | struct bnx2fc_interface *interface = port->priv; |
196 | struct bnx2fc_hba *hba = interface->hba; | |
853e2bd2 BG |
197 | struct bnx2fc_rport *tgt; |
198 | int i; | |
199 | ||
200 | BNX2FC_MISC_DBG("Entered %s\n", __func__); | |
201 | mutex_lock(&hba->hba_mutex); | |
202 | spin_lock_bh(&hba->hba_lock); | |
203 | for (i = 0; i < BNX2FC_NUM_MAX_SESS; i++) { | |
204 | tgt = hba->tgt_ofld_list[i]; | |
205 | if (tgt) { | |
206 | /* Cleanup IOs belonging to requested vport */ | |
207 | if (tgt->port == port) { | |
208 | spin_unlock_bh(&hba->hba_lock); | |
209 | BNX2FC_TGT_DBG(tgt, "flush/cleanup\n"); | |
210 | bnx2fc_flush_active_ios(tgt); | |
211 | spin_lock_bh(&hba->hba_lock); | |
212 | } | |
213 | } | |
214 | } | |
215 | spin_unlock_bh(&hba->hba_lock); | |
216 | mutex_unlock(&hba->hba_mutex); | |
217 | } | |
218 | ||
219 | static int bnx2fc_xmit_l2_frame(struct bnx2fc_rport *tgt, | |
220 | struct fc_frame *fp) | |
221 | { | |
222 | struct fc_rport_priv *rdata = tgt->rdata; | |
223 | struct fc_frame_header *fh; | |
224 | int rc = 0; | |
225 | ||
226 | fh = fc_frame_header_get(fp); | |
227 | BNX2FC_TGT_DBG(tgt, "Xmit L2 frame rport = 0x%x, oxid = 0x%x, " | |
228 | "r_ctl = 0x%x\n", rdata->ids.port_id, | |
229 | ntohs(fh->fh_ox_id), fh->fh_r_ctl); | |
230 | if ((fh->fh_type == FC_TYPE_ELS) && | |
231 | (fh->fh_r_ctl == FC_RCTL_ELS_REQ)) { | |
232 | ||
233 | switch (fc_frame_payload_op(fp)) { | |
234 | case ELS_ADISC: | |
235 | rc = bnx2fc_send_adisc(tgt, fp); | |
236 | break; | |
237 | case ELS_LOGO: | |
238 | rc = bnx2fc_send_logo(tgt, fp); | |
239 | break; | |
240 | case ELS_RLS: | |
241 | rc = bnx2fc_send_rls(tgt, fp); | |
242 | break; | |
243 | default: | |
244 | break; | |
245 | } | |
246 | } else if ((fh->fh_type == FC_TYPE_BLS) && | |
247 | (fh->fh_r_ctl == FC_RCTL_BA_ABTS)) | |
248 | BNX2FC_TGT_DBG(tgt, "ABTS frame\n"); | |
249 | else { | |
250 | BNX2FC_TGT_DBG(tgt, "Send L2 frame type 0x%x " | |
251 | "rctl 0x%x thru non-offload path\n", | |
252 | fh->fh_type, fh->fh_r_ctl); | |
253 | return -ENODEV; | |
254 | } | |
255 | if (rc) | |
256 | return -ENOMEM; | |
257 | else | |
258 | return 0; | |
259 | } | |
260 | ||
261 | /** | |
262 | * bnx2fc_xmit - bnx2fc's FCoE frame transmit function | |
263 | * | |
264 | * @lport: the associated local port | |
265 | * @fp: the fc_frame to be transmitted | |
266 | */ | |
267 | static int bnx2fc_xmit(struct fc_lport *lport, struct fc_frame *fp) | |
268 | { | |
269 | struct ethhdr *eh; | |
270 | struct fcoe_crc_eof *cp; | |
271 | struct sk_buff *skb; | |
272 | struct fc_frame_header *fh; | |
aea71a02 | 273 | struct bnx2fc_interface *interface; |
fd8f8902 | 274 | struct fcoe_ctlr *ctlr; |
aea71a02 | 275 | struct bnx2fc_hba *hba; |
853e2bd2 BG |
276 | struct fcoe_port *port; |
277 | struct fcoe_hdr *hp; | |
278 | struct bnx2fc_rport *tgt; | |
1bd49b48 | 279 | struct fc_stats *stats; |
853e2bd2 BG |
280 | u8 sof, eof; |
281 | u32 crc; | |
282 | unsigned int hlen, tlen, elen; | |
283 | int wlen, rc = 0; | |
284 | ||
285 | port = (struct fcoe_port *)lport_priv(lport); | |
aea71a02 | 286 | interface = port->priv; |
fd8f8902 | 287 | ctlr = bnx2fc_to_ctlr(interface); |
aea71a02 | 288 | hba = interface->hba; |
853e2bd2 BG |
289 | |
290 | fh = fc_frame_header_get(fp); | |
291 | ||
292 | skb = fp_skb(fp); | |
293 | if (!lport->link_up) { | |
294 | BNX2FC_HBA_DBG(lport, "bnx2fc_xmit link down\n"); | |
295 | kfree_skb(skb); | |
296 | return 0; | |
297 | } | |
298 | ||
299 | if (unlikely(fh->fh_r_ctl == FC_RCTL_ELS_REQ)) { | |
fd8f8902 | 300 | if (!ctlr->sel_fcf) { |
853e2bd2 BG |
301 | BNX2FC_HBA_DBG(lport, "FCF not selected yet!\n"); |
302 | kfree_skb(skb); | |
303 | return -EINVAL; | |
304 | } | |
fd8f8902 | 305 | if (fcoe_ctlr_els_send(ctlr, lport, skb)) |
853e2bd2 BG |
306 | return 0; |
307 | } | |
308 | ||
309 | sof = fr_sof(fp); | |
310 | eof = fr_eof(fp); | |
311 | ||
312 | /* | |
313 | * Snoop the frame header to check if the frame is for | |
314 | * an offloaded session | |
315 | */ | |
316 | /* | |
317 | * tgt_ofld_list access is synchronized using | |
318 | * both hba mutex and hba lock. Atleast hba mutex or | |
319 | * hba lock needs to be held for read access. | |
320 | */ | |
321 | ||
322 | spin_lock_bh(&hba->hba_lock); | |
323 | tgt = bnx2fc_tgt_lookup(port, ntoh24(fh->fh_d_id)); | |
324 | if (tgt && (test_bit(BNX2FC_FLAG_SESSION_READY, &tgt->flags))) { | |
325 | /* This frame is for offloaded session */ | |
326 | BNX2FC_HBA_DBG(lport, "xmit: Frame is for offloaded session " | |
327 | "port_id = 0x%x\n", ntoh24(fh->fh_d_id)); | |
328 | spin_unlock_bh(&hba->hba_lock); | |
329 | rc = bnx2fc_xmit_l2_frame(tgt, fp); | |
330 | if (rc != -ENODEV) { | |
331 | kfree_skb(skb); | |
332 | return rc; | |
333 | } | |
334 | } else { | |
335 | spin_unlock_bh(&hba->hba_lock); | |
336 | } | |
337 | ||
338 | elen = sizeof(struct ethhdr); | |
339 | hlen = sizeof(struct fcoe_hdr); | |
340 | tlen = sizeof(struct fcoe_crc_eof); | |
341 | wlen = (skb->len - tlen + sizeof(crc)) / FCOE_WORD_TO_BYTE; | |
342 | ||
343 | skb->ip_summed = CHECKSUM_NONE; | |
344 | crc = fcoe_fc_crc(fp); | |
345 | ||
346 | /* copy port crc and eof to the skb buff */ | |
347 | if (skb_is_nonlinear(skb)) { | |
348 | skb_frag_t *frag; | |
349 | if (bnx2fc_get_paged_crc_eof(skb, tlen)) { | |
350 | kfree_skb(skb); | |
351 | return -ENOMEM; | |
352 | } | |
353 | frag = &skb_shinfo(skb)->frags[skb_shinfo(skb)->nr_frags - 1]; | |
77dfce07 | 354 | cp = kmap_atomic(skb_frag_page(frag)) + frag->page_offset; |
853e2bd2 BG |
355 | } else { |
356 | cp = (struct fcoe_crc_eof *)skb_put(skb, tlen); | |
357 | } | |
358 | ||
359 | memset(cp, 0, sizeof(*cp)); | |
360 | cp->fcoe_eof = eof; | |
361 | cp->fcoe_crc32 = cpu_to_le32(~crc); | |
362 | if (skb_is_nonlinear(skb)) { | |
77dfce07 | 363 | kunmap_atomic(cp); |
853e2bd2 BG |
364 | cp = NULL; |
365 | } | |
366 | ||
367 | /* adjust skb network/transport offsets to match mac/fcoe/port */ | |
368 | skb_push(skb, elen + hlen); | |
369 | skb_reset_mac_header(skb); | |
370 | skb_reset_network_header(skb); | |
371 | skb->mac_len = elen; | |
372 | skb->protocol = htons(ETH_P_FCOE); | |
aea71a02 | 373 | skb->dev = interface->netdev; |
853e2bd2 BG |
374 | |
375 | /* fill up mac and fcoe headers */ | |
376 | eh = eth_hdr(skb); | |
377 | eh->h_proto = htons(ETH_P_FCOE); | |
fd8f8902 | 378 | if (ctlr->map_dest) |
853e2bd2 BG |
379 | fc_fcoe_set_mac(eh->h_dest, fh->fh_d_id); |
380 | else | |
381 | /* insert GW address */ | |
fd8f8902 | 382 | memcpy(eh->h_dest, ctlr->dest_addr, ETH_ALEN); |
853e2bd2 | 383 | |
fd8f8902 RL |
384 | if (unlikely(ctlr->flogi_oxid != FC_XID_UNKNOWN)) |
385 | memcpy(eh->h_source, ctlr->ctl_src_addr, ETH_ALEN); | |
853e2bd2 BG |
386 | else |
387 | memcpy(eh->h_source, port->data_src_addr, ETH_ALEN); | |
388 | ||
389 | hp = (struct fcoe_hdr *)(eh + 1); | |
390 | memset(hp, 0, sizeof(*hp)); | |
391 | if (FC_FCOE_VER) | |
392 | FC_FCOE_ENCAPS_VER(hp, FC_FCOE_VER); | |
393 | hp->fcoe_sof = sof; | |
394 | ||
395 | /* fcoe lso, mss is in max_payload which is non-zero for FCP data */ | |
396 | if (lport->seq_offload && fr_max_payload(fp)) { | |
397 | skb_shinfo(skb)->gso_type = SKB_GSO_FCOE; | |
398 | skb_shinfo(skb)->gso_size = fr_max_payload(fp); | |
399 | } else { | |
400 | skb_shinfo(skb)->gso_type = 0; | |
401 | skb_shinfo(skb)->gso_size = 0; | |
402 | } | |
403 | ||
404 | /*update tx stats */ | |
1bd49b48 | 405 | stats = per_cpu_ptr(lport->stats, get_cpu()); |
853e2bd2 BG |
406 | stats->TxFrames++; |
407 | stats->TxWords += wlen; | |
408 | put_cpu(); | |
409 | ||
410 | /* send down to lld */ | |
411 | fr_dev(fp) = lport; | |
412 | if (port->fcoe_pending_queue.qlen) | |
413 | fcoe_check_wait_queue(lport, skb); | |
414 | else if (fcoe_start_io(skb)) | |
415 | fcoe_check_wait_queue(lport, skb); | |
416 | ||
417 | return 0; | |
418 | } | |
419 | ||
420 | /** | |
421 | * bnx2fc_rcv - This is bnx2fc's receive function called by NET_RX_SOFTIRQ | |
422 | * | |
423 | * @skb: the receive socket buffer | |
424 | * @dev: associated net device | |
425 | * @ptype: context | |
426 | * @olddev: last device | |
427 | * | |
428 | * This function receives the packet and builds FC frame and passes it up | |
429 | */ | |
430 | static int bnx2fc_rcv(struct sk_buff *skb, struct net_device *dev, | |
431 | struct packet_type *ptype, struct net_device *olddev) | |
432 | { | |
433 | struct fc_lport *lport; | |
aea71a02 | 434 | struct bnx2fc_interface *interface; |
fd8f8902 | 435 | struct fcoe_ctlr *ctlr; |
853e2bd2 BG |
436 | struct fc_frame_header *fh; |
437 | struct fcoe_rcv_info *fr; | |
438 | struct fcoe_percpu_s *bg; | |
01a4cc4d | 439 | struct sk_buff *tmp_skb; |
853e2bd2 BG |
440 | unsigned short oxid; |
441 | ||
aea71a02 BPG |
442 | interface = container_of(ptype, struct bnx2fc_interface, |
443 | fcoe_packet_type); | |
fd8f8902 RL |
444 | ctlr = bnx2fc_to_ctlr(interface); |
445 | lport = ctlr->lp; | |
853e2bd2 BG |
446 | |
447 | if (unlikely(lport == NULL)) { | |
b2a554ff | 448 | printk(KERN_ERR PFX "bnx2fc_rcv: lport is NULL\n"); |
853e2bd2 BG |
449 | goto err; |
450 | } | |
451 | ||
01a4cc4d ML |
452 | tmp_skb = skb_share_check(skb, GFP_ATOMIC); |
453 | if (!tmp_skb) | |
454 | goto err; | |
455 | ||
456 | skb = tmp_skb; | |
457 | ||
853e2bd2 | 458 | if (unlikely(eth_hdr(skb)->h_proto != htons(ETH_P_FCOE))) { |
b2a554ff | 459 | printk(KERN_ERR PFX "bnx2fc_rcv: Wrong FC type frame\n"); |
853e2bd2 BG |
460 | goto err; |
461 | } | |
462 | ||
463 | /* | |
464 | * Check for minimum frame length, and make sure required FCoE | |
465 | * and FC headers are pulled into the linear data area. | |
466 | */ | |
467 | if (unlikely((skb->len < FCOE_MIN_FRAME) || | |
468 | !pskb_may_pull(skb, FCOE_HEADER_LEN))) | |
469 | goto err; | |
470 | ||
471 | skb_set_transport_header(skb, sizeof(struct fcoe_hdr)); | |
472 | fh = (struct fc_frame_header *) skb_transport_header(skb); | |
473 | ||
474 | oxid = ntohs(fh->fh_ox_id); | |
475 | ||
476 | fr = fcoe_dev_from_skb(skb); | |
477 | fr->fr_dev = lport; | |
853e2bd2 BG |
478 | |
479 | bg = &bnx2fc_global; | |
fc05ab74 | 480 | spin_lock(&bg->fcoe_rx_list.lock); |
853e2bd2 BG |
481 | |
482 | __skb_queue_tail(&bg->fcoe_rx_list, skb); | |
483 | if (bg->fcoe_rx_list.qlen == 1) | |
484 | wake_up_process(bg->thread); | |
485 | ||
fc05ab74 | 486 | spin_unlock(&bg->fcoe_rx_list.lock); |
853e2bd2 BG |
487 | |
488 | return 0; | |
489 | err: | |
490 | kfree_skb(skb); | |
491 | return -1; | |
492 | } | |
493 | ||
494 | static int bnx2fc_l2_rcv_thread(void *arg) | |
495 | { | |
496 | struct fcoe_percpu_s *bg = arg; | |
497 | struct sk_buff *skb; | |
498 | ||
8698a745 | 499 | set_user_nice(current, MIN_NICE); |
853e2bd2 BG |
500 | set_current_state(TASK_INTERRUPTIBLE); |
501 | while (!kthread_should_stop()) { | |
502 | schedule(); | |
853e2bd2 BG |
503 | spin_lock_bh(&bg->fcoe_rx_list.lock); |
504 | while ((skb = __skb_dequeue(&bg->fcoe_rx_list)) != NULL) { | |
505 | spin_unlock_bh(&bg->fcoe_rx_list.lock); | |
506 | bnx2fc_recv_frame(skb); | |
507 | spin_lock_bh(&bg->fcoe_rx_list.lock); | |
508 | } | |
fee78712 | 509 | __set_current_state(TASK_INTERRUPTIBLE); |
853e2bd2 | 510 | spin_unlock_bh(&bg->fcoe_rx_list.lock); |
853e2bd2 | 511 | } |
fee78712 | 512 | __set_current_state(TASK_RUNNING); |
853e2bd2 BG |
513 | return 0; |
514 | } | |
515 | ||
516 | ||
517 | static void bnx2fc_recv_frame(struct sk_buff *skb) | |
518 | { | |
519 | u32 fr_len; | |
520 | struct fc_lport *lport; | |
521 | struct fcoe_rcv_info *fr; | |
1bd49b48 | 522 | struct fc_stats *stats; |
853e2bd2 BG |
523 | struct fc_frame_header *fh; |
524 | struct fcoe_crc_eof crc_eof; | |
525 | struct fc_frame *fp; | |
526 | struct fc_lport *vn_port; | |
527 | struct fcoe_port *port; | |
528 | u8 *mac = NULL; | |
529 | u8 *dest_mac = NULL; | |
530 | struct fcoe_hdr *hp; | |
531 | ||
532 | fr = fcoe_dev_from_skb(skb); | |
533 | lport = fr->fr_dev; | |
534 | if (unlikely(lport == NULL)) { | |
b2a554ff | 535 | printk(KERN_ERR PFX "Invalid lport struct\n"); |
853e2bd2 BG |
536 | kfree_skb(skb); |
537 | return; | |
538 | } | |
539 | ||
540 | if (skb_is_nonlinear(skb)) | |
541 | skb_linearize(skb); | |
542 | mac = eth_hdr(skb)->h_source; | |
543 | dest_mac = eth_hdr(skb)->h_dest; | |
544 | ||
545 | /* Pull the header */ | |
546 | hp = (struct fcoe_hdr *) skb_network_header(skb); | |
547 | fh = (struct fc_frame_header *) skb_transport_header(skb); | |
548 | skb_pull(skb, sizeof(struct fcoe_hdr)); | |
549 | fr_len = skb->len - sizeof(struct fcoe_crc_eof); | |
550 | ||
853e2bd2 BG |
551 | fp = (struct fc_frame *)skb; |
552 | fc_frame_init(fp); | |
553 | fr_dev(fp) = lport; | |
554 | fr_sof(fp) = hp->fcoe_sof; | |
555 | if (skb_copy_bits(skb, fr_len, &crc_eof, sizeof(crc_eof))) { | |
853e2bd2 BG |
556 | kfree_skb(skb); |
557 | return; | |
558 | } | |
559 | fr_eof(fp) = crc_eof.fcoe_eof; | |
560 | fr_crc(fp) = crc_eof.fcoe_crc32; | |
561 | if (pskb_trim(skb, fr_len)) { | |
853e2bd2 BG |
562 | kfree_skb(skb); |
563 | return; | |
564 | } | |
565 | ||
566 | fh = fc_frame_header_get(fp); | |
567 | ||
568 | vn_port = fc_vport_id_lookup(lport, ntoh24(fh->fh_d_id)); | |
569 | if (vn_port) { | |
570 | port = lport_priv(vn_port); | |
6942df7f | 571 | if (!ether_addr_equal(port->data_src_addr, dest_mac)) { |
853e2bd2 | 572 | BNX2FC_HBA_DBG(lport, "fpma mismatch\n"); |
853e2bd2 BG |
573 | kfree_skb(skb); |
574 | return; | |
575 | } | |
576 | } | |
577 | if (fh->fh_r_ctl == FC_RCTL_DD_SOL_DATA && | |
578 | fh->fh_type == FC_TYPE_FCP) { | |
579 | /* Drop FCP data. We dont this in L2 path */ | |
853e2bd2 BG |
580 | kfree_skb(skb); |
581 | return; | |
582 | } | |
583 | if (fh->fh_r_ctl == FC_RCTL_ELS_REQ && | |
584 | fh->fh_type == FC_TYPE_ELS) { | |
585 | switch (fc_frame_payload_op(fp)) { | |
586 | case ELS_LOGO: | |
587 | if (ntoh24(fh->fh_s_id) == FC_FID_FLOGI) { | |
588 | /* drop non-FIP LOGO */ | |
853e2bd2 BG |
589 | kfree_skb(skb); |
590 | return; | |
591 | } | |
592 | break; | |
593 | } | |
594 | } | |
3f8744d1 BPG |
595 | |
596 | if (fh->fh_r_ctl == FC_RCTL_BA_ABTS) { | |
597 | /* Drop incoming ABTS */ | |
3f8744d1 BPG |
598 | kfree_skb(skb); |
599 | return; | |
600 | } | |
601 | ||
d576a5e8 NH |
602 | stats = per_cpu_ptr(lport->stats, smp_processor_id()); |
603 | stats->RxFrames++; | |
604 | stats->RxWords += fr_len / FCOE_WORD_TO_BYTE; | |
605 | ||
853e2bd2 BG |
606 | if (le32_to_cpu(fr_crc(fp)) != |
607 | ~crc32(~0, skb->data, fr_len)) { | |
608 | if (stats->InvalidCRCCount < 5) | |
609 | printk(KERN_WARNING PFX "dropping frame with " | |
610 | "CRC error\n"); | |
611 | stats->InvalidCRCCount++; | |
853e2bd2 BG |
612 | kfree_skb(skb); |
613 | return; | |
614 | } | |
853e2bd2 BG |
615 | fc_exch_recv(lport, fp); |
616 | } | |
617 | ||
618 | /** | |
619 | * bnx2fc_percpu_io_thread - thread per cpu for ios | |
620 | * | |
621 | * @arg: ptr to bnx2fc_percpu_info structure | |
622 | */ | |
623 | int bnx2fc_percpu_io_thread(void *arg) | |
624 | { | |
625 | struct bnx2fc_percpu_s *p = arg; | |
626 | struct bnx2fc_work *work, *tmp; | |
627 | LIST_HEAD(work_list); | |
628 | ||
8698a745 | 629 | set_user_nice(current, MIN_NICE); |
853e2bd2 BG |
630 | set_current_state(TASK_INTERRUPTIBLE); |
631 | while (!kthread_should_stop()) { | |
632 | schedule(); | |
853e2bd2 BG |
633 | spin_lock_bh(&p->fp_work_lock); |
634 | while (!list_empty(&p->work_list)) { | |
635 | list_splice_init(&p->work_list, &work_list); | |
636 | spin_unlock_bh(&p->fp_work_lock); | |
637 | ||
638 | list_for_each_entry_safe(work, tmp, &work_list, list) { | |
639 | list_del_init(&work->list); | |
640 | bnx2fc_process_cq_compl(work->tgt, work->wqe); | |
641 | kfree(work); | |
642 | } | |
643 | ||
644 | spin_lock_bh(&p->fp_work_lock); | |
645 | } | |
fee78712 | 646 | __set_current_state(TASK_INTERRUPTIBLE); |
853e2bd2 | 647 | spin_unlock_bh(&p->fp_work_lock); |
853e2bd2 | 648 | } |
fee78712 | 649 | __set_current_state(TASK_RUNNING); |
853e2bd2 BG |
650 | |
651 | return 0; | |
652 | } | |
653 | ||
654 | static struct fc_host_statistics *bnx2fc_get_host_stats(struct Scsi_Host *shost) | |
655 | { | |
656 | struct fc_host_statistics *bnx2fc_stats; | |
657 | struct fc_lport *lport = shost_priv(shost); | |
658 | struct fcoe_port *port = lport_priv(lport); | |
aea71a02 BPG |
659 | struct bnx2fc_interface *interface = port->priv; |
660 | struct bnx2fc_hba *hba = interface->hba; | |
853e2bd2 BG |
661 | struct fcoe_statistics_params *fw_stats; |
662 | int rc = 0; | |
663 | ||
664 | fw_stats = (struct fcoe_statistics_params *)hba->stats_buffer; | |
665 | if (!fw_stats) | |
666 | return NULL; | |
667 | ||
668 | bnx2fc_stats = fc_get_host_stats(shost); | |
669 | ||
670 | init_completion(&hba->stat_req_done); | |
671 | if (bnx2fc_send_stat_req(hba)) | |
672 | return bnx2fc_stats; | |
673 | rc = wait_for_completion_timeout(&hba->stat_req_done, (2 * HZ)); | |
674 | if (!rc) { | |
675 | BNX2FC_HBA_DBG(lport, "FW stat req timed out\n"); | |
676 | return bnx2fc_stats; | |
677 | } | |
f246fe2a BPG |
678 | BNX2FC_STATS(hba, rx_stat2, fc_crc_cnt); |
679 | bnx2fc_stats->invalid_crc_count += hba->bfw_stats.fc_crc_cnt; | |
680 | BNX2FC_STATS(hba, tx_stat, fcoe_tx_pkt_cnt); | |
681 | bnx2fc_stats->tx_frames += hba->bfw_stats.fcoe_tx_pkt_cnt; | |
682 | BNX2FC_STATS(hba, tx_stat, fcoe_tx_byte_cnt); | |
683 | bnx2fc_stats->tx_words += ((hba->bfw_stats.fcoe_tx_byte_cnt) / 4); | |
684 | BNX2FC_STATS(hba, rx_stat0, fcoe_rx_pkt_cnt); | |
685 | bnx2fc_stats->rx_frames += hba->bfw_stats.fcoe_rx_pkt_cnt; | |
686 | BNX2FC_STATS(hba, rx_stat0, fcoe_rx_byte_cnt); | |
687 | bnx2fc_stats->rx_words += ((hba->bfw_stats.fcoe_rx_byte_cnt) / 4); | |
853e2bd2 BG |
688 | |
689 | bnx2fc_stats->dumped_frames = 0; | |
690 | bnx2fc_stats->lip_count = 0; | |
691 | bnx2fc_stats->nos_count = 0; | |
692 | bnx2fc_stats->loss_of_sync_count = 0; | |
693 | bnx2fc_stats->loss_of_signal_count = 0; | |
694 | bnx2fc_stats->prim_seq_protocol_err_count = 0; | |
695 | ||
f246fe2a BPG |
696 | memcpy(&hba->prev_stats, hba->stats_buffer, |
697 | sizeof(struct fcoe_statistics_params)); | |
853e2bd2 BG |
698 | return bnx2fc_stats; |
699 | } | |
700 | ||
701 | static int bnx2fc_shost_config(struct fc_lport *lport, struct device *dev) | |
702 | { | |
703 | struct fcoe_port *port = lport_priv(lport); | |
aea71a02 | 704 | struct bnx2fc_interface *interface = port->priv; |
c13d2b6d | 705 | struct bnx2fc_hba *hba = interface->hba; |
853e2bd2 BG |
706 | struct Scsi_Host *shost = lport->host; |
707 | int rc = 0; | |
708 | ||
709 | shost->max_cmd_len = BNX2FC_MAX_CMD_LEN; | |
10755d3f | 710 | shost->max_lun = bnx2fc_max_luns; |
853e2bd2 BG |
711 | shost->max_id = BNX2FC_MAX_FCP_TGT; |
712 | shost->max_channel = 0; | |
713 | if (lport->vport) | |
714 | shost->transportt = bnx2fc_vport_xport_template; | |
715 | else | |
716 | shost->transportt = bnx2fc_transport_template; | |
717 | ||
718 | /* Add the new host to SCSI-ml */ | |
719 | rc = scsi_add_host(lport->host, dev); | |
720 | if (rc) { | |
721 | printk(KERN_ERR PFX "Error on scsi_add_host\n"); | |
722 | return rc; | |
723 | } | |
724 | if (!lport->vport) | |
725 | fc_host_max_npiv_vports(lport->host) = USHRT_MAX; | |
c13d2b6d | 726 | snprintf(fc_host_symbolic_name(lport->host), 256, |
17d87c45 | 727 | "%s (QLogic %s) v%s over %s", |
c13d2b6d | 728 | BNX2FC_NAME, hba->chip_num, BNX2FC_VERSION, |
aea71a02 | 729 | interface->netdev->name); |
853e2bd2 BG |
730 | |
731 | return 0; | |
732 | } | |
733 | ||
853e2bd2 BG |
734 | static int bnx2fc_link_ok(struct fc_lport *lport) |
735 | { | |
736 | struct fcoe_port *port = lport_priv(lport); | |
aea71a02 BPG |
737 | struct bnx2fc_interface *interface = port->priv; |
738 | struct bnx2fc_hba *hba = interface->hba; | |
853e2bd2 BG |
739 | struct net_device *dev = hba->phys_dev; |
740 | int rc = 0; | |
741 | ||
742 | if ((dev->flags & IFF_UP) && netif_carrier_ok(dev)) | |
743 | clear_bit(ADAPTER_STATE_LINK_DOWN, &hba->adapter_state); | |
744 | else { | |
745 | set_bit(ADAPTER_STATE_LINK_DOWN, &hba->adapter_state); | |
746 | rc = -1; | |
747 | } | |
748 | return rc; | |
749 | } | |
750 | ||
751 | /** | |
752 | * bnx2fc_get_link_state - get network link state | |
753 | * | |
754 | * @hba: adapter instance pointer | |
755 | * | |
756 | * updates adapter structure flag based on netdev state | |
757 | */ | |
758 | void bnx2fc_get_link_state(struct bnx2fc_hba *hba) | |
759 | { | |
aea71a02 | 760 | if (test_bit(__LINK_STATE_NOCARRIER, &hba->phys_dev->state)) |
853e2bd2 BG |
761 | set_bit(ADAPTER_STATE_LINK_DOWN, &hba->adapter_state); |
762 | else | |
763 | clear_bit(ADAPTER_STATE_LINK_DOWN, &hba->adapter_state); | |
764 | } | |
765 | ||
52439607 | 766 | static int bnx2fc_net_config(struct fc_lport *lport, struct net_device *netdev) |
853e2bd2 BG |
767 | { |
768 | struct bnx2fc_hba *hba; | |
aea71a02 | 769 | struct bnx2fc_interface *interface; |
fd8f8902 | 770 | struct fcoe_ctlr *ctlr; |
853e2bd2 BG |
771 | struct fcoe_port *port; |
772 | u64 wwnn, wwpn; | |
773 | ||
774 | port = lport_priv(lport); | |
aea71a02 | 775 | interface = port->priv; |
fd8f8902 | 776 | ctlr = bnx2fc_to_ctlr(interface); |
aea71a02 | 777 | hba = interface->hba; |
853e2bd2 BG |
778 | |
779 | /* require support for get_pauseparam ethtool op. */ | |
780 | if (!hba->phys_dev->ethtool_ops || | |
781 | !hba->phys_dev->ethtool_ops->get_pauseparam) | |
782 | return -EOPNOTSUPP; | |
783 | ||
1294bfe6 | 784 | if (fc_set_mfs(lport, BNX2FC_MFS)) |
853e2bd2 BG |
785 | return -EINVAL; |
786 | ||
787 | skb_queue_head_init(&port->fcoe_pending_queue); | |
788 | port->fcoe_pending_queue_active = 0; | |
789 | setup_timer(&port->timer, fcoe_queue_timer, (unsigned long) lport); | |
790 | ||
0e0f9cd6 | 791 | fcoe_link_speed_update(lport); |
853e2bd2 BG |
792 | |
793 | if (!lport->vport) { | |
52439607 | 794 | if (fcoe_get_wwn(netdev, &wwnn, NETDEV_FCOE_WWNN)) |
fd8f8902 | 795 | wwnn = fcoe_wwn_from_mac(ctlr->ctl_src_addr, |
52439607 | 796 | 1, 0); |
853e2bd2 BG |
797 | BNX2FC_HBA_DBG(lport, "WWNN = 0x%llx\n", wwnn); |
798 | fc_set_wwnn(lport, wwnn); | |
799 | ||
52439607 | 800 | if (fcoe_get_wwn(netdev, &wwpn, NETDEV_FCOE_WWPN)) |
fd8f8902 | 801 | wwpn = fcoe_wwn_from_mac(ctlr->ctl_src_addr, |
52439607 BPG |
802 | 2, 0); |
803 | ||
853e2bd2 BG |
804 | BNX2FC_HBA_DBG(lport, "WWPN = 0x%llx\n", wwpn); |
805 | fc_set_wwpn(lport, wwpn); | |
806 | } | |
807 | ||
808 | return 0; | |
809 | } | |
810 | ||
811 | static void bnx2fc_destroy_timer(unsigned long data) | |
812 | { | |
813 | struct bnx2fc_hba *hba = (struct bnx2fc_hba *)data; | |
814 | ||
cd703ae7 BPG |
815 | printk(KERN_ERR PFX "ERROR:bnx2fc_destroy_timer - " |
816 | "Destroy compl not received!!\n"); | |
aea71a02 | 817 | set_bit(BNX2FC_FLAG_DESTROY_CMPL, &hba->flags); |
853e2bd2 BG |
818 | wake_up_interruptible(&hba->destroy_wait); |
819 | } | |
820 | ||
821 | /** | |
822 | * bnx2fc_indicate_netevent - Generic netdev event handler | |
823 | * | |
824 | * @context: adapter structure pointer | |
825 | * @event: event type | |
415199f2 | 826 | * @vlan_id: vlan id - associated vlan id with this event |
853e2bd2 BG |
827 | * |
828 | * Handles NETDEV_UP, NETDEV_DOWN, NETDEV_GOING_DOWN,NETDEV_CHANGE and | |
abc49a93 | 829 | * NETDEV_CHANGE_MTU events. Handle NETDEV_UNREGISTER only for vlans. |
853e2bd2 | 830 | */ |
415199f2 MC |
831 | static void bnx2fc_indicate_netevent(void *context, unsigned long event, |
832 | u16 vlan_id) | |
853e2bd2 BG |
833 | { |
834 | struct bnx2fc_hba *hba = (struct bnx2fc_hba *)context; | |
6e89ea3f | 835 | struct fcoe_ctlr_device *cdev; |
aea71a02 | 836 | struct fc_lport *lport; |
853e2bd2 | 837 | struct fc_lport *vport; |
abc49a93 | 838 | struct bnx2fc_interface *interface, *tmp; |
fd8f8902 | 839 | struct fcoe_ctlr *ctlr; |
aea71a02 | 840 | int wait_for_upload = 0; |
853e2bd2 BG |
841 | u32 link_possible = 1; |
842 | ||
abc49a93 | 843 | if (vlan_id != 0 && event != NETDEV_UNREGISTER) |
415199f2 MC |
844 | return; |
845 | ||
853e2bd2 BG |
846 | switch (event) { |
847 | case NETDEV_UP: | |
853e2bd2 BG |
848 | if (!test_bit(ADAPTER_STATE_UP, &hba->adapter_state)) |
849 | printk(KERN_ERR "indicate_netevent: "\ | |
aea71a02 | 850 | "hba is not UP!!\n"); |
853e2bd2 BG |
851 | break; |
852 | ||
853 | case NETDEV_DOWN: | |
853e2bd2 BG |
854 | clear_bit(ADAPTER_STATE_GOING_DOWN, &hba->adapter_state); |
855 | clear_bit(ADAPTER_STATE_UP, &hba->adapter_state); | |
856 | link_possible = 0; | |
857 | break; | |
858 | ||
859 | case NETDEV_GOING_DOWN: | |
853e2bd2 BG |
860 | set_bit(ADAPTER_STATE_GOING_DOWN, &hba->adapter_state); |
861 | link_possible = 0; | |
862 | break; | |
863 | ||
864 | case NETDEV_CHANGE: | |
853e2bd2 BG |
865 | break; |
866 | ||
abc49a93 BPG |
867 | case NETDEV_UNREGISTER: |
868 | if (!vlan_id) | |
869 | return; | |
870 | mutex_lock(&bnx2fc_dev_lock); | |
871 | list_for_each_entry_safe(interface, tmp, &if_list, list) { | |
26b2982f NNS |
872 | if (interface->hba == hba && |
873 | interface->vlan_id == (vlan_id & VLAN_VID_MASK)) | |
874 | __bnx2fc_destroy(interface); | |
abc49a93 BPG |
875 | } |
876 | mutex_unlock(&bnx2fc_dev_lock); | |
06c4f20d EW |
877 | |
878 | /* Ensure ALL destroy work has been completed before return */ | |
879 | flush_workqueue(bnx2fc_wq); | |
abc49a93 BPG |
880 | return; |
881 | ||
853e2bd2 | 882 | default: |
853e2bd2 BG |
883 | return; |
884 | } | |
885 | ||
aea71a02 BPG |
886 | mutex_lock(&bnx2fc_dev_lock); |
887 | list_for_each_entry(interface, &if_list, list) { | |
853e2bd2 | 888 | |
aea71a02 BPG |
889 | if (interface->hba != hba) |
890 | continue; | |
891 | ||
fd8f8902 RL |
892 | ctlr = bnx2fc_to_ctlr(interface); |
893 | lport = ctlr->lp; | |
aea71a02 BPG |
894 | BNX2FC_HBA_DBG(lport, "netevent handler - event=%s %ld\n", |
895 | interface->netdev->name, event); | |
896 | ||
0e0f9cd6 | 897 | fcoe_link_speed_update(lport); |
aea71a02 | 898 | |
6e89ea3f | 899 | cdev = fcoe_ctlr_to_ctlr_dev(ctlr); |
aea71a02 BPG |
900 | |
901 | if (link_possible && !bnx2fc_link_ok(lport)) { | |
6e89ea3f RL |
902 | switch (cdev->enabled) { |
903 | case FCOE_CTLR_DISABLED: | |
904 | pr_info("Link up while interface is disabled.\n"); | |
905 | break; | |
906 | case FCOE_CTLR_ENABLED: | |
907 | case FCOE_CTLR_UNUSED: | |
908 | /* Reset max recv frame size to default */ | |
909 | fc_set_mfs(lport, BNX2FC_MFS); | |
910 | /* | |
911 | * ctlr link up will only be handled during | |
912 | * enable to avoid sending discovery | |
913 | * solicitation on a stale vlan | |
914 | */ | |
915 | if (interface->enabled) | |
916 | fcoe_ctlr_link_up(ctlr); | |
917 | }; | |
fd8f8902 | 918 | } else if (fcoe_ctlr_link_down(ctlr)) { |
6e89ea3f RL |
919 | switch (cdev->enabled) { |
920 | case FCOE_CTLR_DISABLED: | |
921 | pr_info("Link down while interface is disabled.\n"); | |
922 | break; | |
923 | case FCOE_CTLR_ENABLED: | |
924 | case FCOE_CTLR_UNUSED: | |
925 | mutex_lock(&lport->lp_mutex); | |
926 | list_for_each_entry(vport, &lport->vports, list) | |
927 | fc_host_port_type(vport->host) = | |
928 | FC_PORTTYPE_UNKNOWN; | |
929 | mutex_unlock(&lport->lp_mutex); | |
930 | fc_host_port_type(lport->host) = | |
931 | FC_PORTTYPE_UNKNOWN; | |
932 | per_cpu_ptr(lport->stats, | |
933 | get_cpu())->LinkFailureCount++; | |
934 | put_cpu(); | |
935 | fcoe_clean_pending_queue(lport); | |
936 | wait_for_upload = 1; | |
937 | }; | |
aea71a02 BPG |
938 | } |
939 | } | |
940 | mutex_unlock(&bnx2fc_dev_lock); | |
853e2bd2 | 941 | |
aea71a02 BPG |
942 | if (wait_for_upload) { |
943 | clear_bit(ADAPTER_STATE_READY, &hba->adapter_state); | |
944 | init_waitqueue_head(&hba->shutdown_wait); | |
945 | BNX2FC_MISC_DBG("indicate_netevent " | |
946 | "num_ofld_sess = %d\n", | |
947 | hba->num_ofld_sess); | |
948 | hba->wait_for_link_down = 1; | |
949 | wait_event_interruptible(hba->shutdown_wait, | |
950 | (hba->num_ofld_sess == 0)); | |
951 | BNX2FC_MISC_DBG("wakeup - num_ofld_sess = %d\n", | |
853e2bd2 | 952 | hba->num_ofld_sess); |
aea71a02 | 953 | hba->wait_for_link_down = 0; |
853e2bd2 | 954 | |
aea71a02 BPG |
955 | if (signal_pending(current)) |
956 | flush_signals(current); | |
853e2bd2 BG |
957 | } |
958 | } | |
959 | ||
960 | static int bnx2fc_libfc_config(struct fc_lport *lport) | |
961 | { | |
962 | ||
963 | /* Set the function pointers set by bnx2fc driver */ | |
964 | memcpy(&lport->tt, &bnx2fc_libfc_fcn_templ, | |
965 | sizeof(struct libfc_function_template)); | |
966 | fc_elsct_init(lport); | |
967 | fc_exch_init(lport); | |
968 | fc_rport_init(lport); | |
0807619d RL |
969 | fc_disc_init(lport); |
970 | fc_disc_config(lport, lport); | |
853e2bd2 BG |
971 | return 0; |
972 | } | |
973 | ||
0eb43b4b | 974 | static int bnx2fc_em_config(struct fc_lport *lport, struct bnx2fc_hba *hba) |
853e2bd2 | 975 | { |
0eb43b4b | 976 | int fcoe_min_xid, fcoe_max_xid; |
7d742f65 | 977 | |
0eb43b4b | 978 | fcoe_min_xid = hba->max_xid + 1; |
7d742f65 | 979 | if (nr_cpu_ids <= 2) |
0eb43b4b | 980 | fcoe_max_xid = hba->max_xid + FCOE_XIDS_PER_CPU_OFFSET; |
7d742f65 | 981 | else |
0eb43b4b BPG |
982 | fcoe_max_xid = hba->max_xid + FCOE_MAX_XID_OFFSET; |
983 | if (!fc_exch_mgr_alloc(lport, FC_CLASS_3, fcoe_min_xid, | |
984 | fcoe_max_xid, NULL)) { | |
853e2bd2 BG |
985 | printk(KERN_ERR PFX "em_config:fc_exch_mgr_alloc failed\n"); |
986 | return -ENOMEM; | |
987 | } | |
988 | ||
853e2bd2 BG |
989 | return 0; |
990 | } | |
991 | ||
992 | static int bnx2fc_lport_config(struct fc_lport *lport) | |
993 | { | |
994 | lport->link_up = 0; | |
995 | lport->qfull = 0; | |
44c570b5 BPG |
996 | lport->max_retry_count = BNX2FC_MAX_RETRY_CNT; |
997 | lport->max_rport_retry_count = BNX2FC_MAX_RPORT_RETRY_CNT; | |
853e2bd2 BG |
998 | lport->e_d_tov = 2 * 1000; |
999 | lport->r_a_tov = 10 * 1000; | |
1000 | ||
853e2bd2 BG |
1001 | lport->service_params = (FCP_SPPF_INIT_FCN | FCP_SPPF_RD_XRDY_DIS | |
1002 | FCP_SPPF_RETRY | FCP_SPPF_CONF_COMPL); | |
853e2bd2 BG |
1003 | lport->does_npiv = 1; |
1004 | ||
1005 | memset(&lport->rnid_gen, 0, sizeof(struct fc_els_rnid_gen)); | |
1006 | lport->rnid_gen.rnid_atype = BNX2FC_RNID_HBA; | |
1007 | ||
1008 | /* alloc stats structure */ | |
1009 | if (fc_lport_init_stats(lport)) | |
1010 | return -ENOMEM; | |
1011 | ||
1012 | /* Finish fc_lport configuration */ | |
1013 | fc_lport_config(lport); | |
1014 | ||
1015 | return 0; | |
1016 | } | |
1017 | ||
1018 | /** | |
1019 | * bnx2fc_fip_recv - handle a received FIP frame. | |
1020 | * | |
1021 | * @skb: the received skb | |
1022 | * @dev: associated &net_device | |
1023 | * @ptype: the &packet_type structure which was used to register this handler. | |
1024 | * @orig_dev: original receive &net_device, in case @ dev is a bond. | |
1025 | * | |
1026 | * Returns: 0 for success | |
1027 | */ | |
1028 | static int bnx2fc_fip_recv(struct sk_buff *skb, struct net_device *dev, | |
1029 | struct packet_type *ptype, | |
1030 | struct net_device *orig_dev) | |
1031 | { | |
aea71a02 | 1032 | struct bnx2fc_interface *interface; |
fd8f8902 | 1033 | struct fcoe_ctlr *ctlr; |
aea71a02 BPG |
1034 | interface = container_of(ptype, struct bnx2fc_interface, |
1035 | fip_packet_type); | |
fd8f8902 RL |
1036 | ctlr = bnx2fc_to_ctlr(interface); |
1037 | fcoe_ctlr_recv(ctlr, skb); | |
853e2bd2 BG |
1038 | return 0; |
1039 | } | |
1040 | ||
1041 | /** | |
1042 | * bnx2fc_update_src_mac - Update Ethernet MAC filters. | |
1043 | * | |
1044 | * @fip: FCoE controller. | |
1045 | * @old: Unicast MAC address to delete if the MAC is non-zero. | |
1046 | * @new: Unicast MAC address to add. | |
1047 | * | |
1048 | * Remove any previously-set unicast MAC filter. | |
1049 | * Add secondary FCoE MAC address filter for our OUI. | |
1050 | */ | |
1051 | static void bnx2fc_update_src_mac(struct fc_lport *lport, u8 *addr) | |
1052 | { | |
1053 | struct fcoe_port *port = lport_priv(lport); | |
1054 | ||
1055 | memcpy(port->data_src_addr, addr, ETH_ALEN); | |
1056 | } | |
1057 | ||
1058 | /** | |
1059 | * bnx2fc_get_src_mac - return the ethernet source address for an lport | |
1060 | * | |
1061 | * @lport: libfc port | |
1062 | */ | |
1063 | static u8 *bnx2fc_get_src_mac(struct fc_lport *lport) | |
1064 | { | |
1065 | struct fcoe_port *port; | |
1066 | ||
1067 | port = (struct fcoe_port *)lport_priv(lport); | |
1068 | return port->data_src_addr; | |
1069 | } | |
1070 | ||
1071 | /** | |
1072 | * bnx2fc_fip_send - send an Ethernet-encapsulated FIP frame. | |
1073 | * | |
1074 | * @fip: FCoE controller. | |
1075 | * @skb: FIP Packet. | |
1076 | */ | |
1077 | static void bnx2fc_fip_send(struct fcoe_ctlr *fip, struct sk_buff *skb) | |
1078 | { | |
1079 | skb->dev = bnx2fc_from_ctlr(fip)->netdev; | |
1080 | dev_queue_xmit(skb); | |
1081 | } | |
1082 | ||
1083 | static int bnx2fc_vport_create(struct fc_vport *vport, bool disabled) | |
1084 | { | |
1085 | struct Scsi_Host *shost = vport_to_shost(vport); | |
1086 | struct fc_lport *n_port = shost_priv(shost); | |
1087 | struct fcoe_port *port = lport_priv(n_port); | |
aea71a02 BPG |
1088 | struct bnx2fc_interface *interface = port->priv; |
1089 | struct net_device *netdev = interface->netdev; | |
853e2bd2 | 1090 | struct fc_lport *vn_port; |
861efc54 BPG |
1091 | int rc; |
1092 | char buf[32]; | |
1093 | ||
1094 | rc = fcoe_validate_vport_create(vport); | |
1095 | if (rc) { | |
1096 | fcoe_wwn_to_str(vport->port_name, buf, sizeof(buf)); | |
1097 | printk(KERN_ERR PFX "Failed to create vport, " | |
1098 | "WWPN (0x%s) already exists\n", | |
1099 | buf); | |
1100 | return rc; | |
1101 | } | |
853e2bd2 | 1102 | |
aea71a02 | 1103 | if (!test_bit(BNX2FC_FLAG_FW_INIT_DONE, &interface->hba->flags)) { |
853e2bd2 | 1104 | printk(KERN_ERR PFX "vn ports cannot be created on" |
aea71a02 | 1105 | "this interface\n"); |
853e2bd2 BG |
1106 | return -EIO; |
1107 | } | |
4bc71cb9 | 1108 | rtnl_lock(); |
853e2bd2 | 1109 | mutex_lock(&bnx2fc_dev_lock); |
aea71a02 | 1110 | vn_port = bnx2fc_if_create(interface, &vport->dev, 1); |
853e2bd2 | 1111 | mutex_unlock(&bnx2fc_dev_lock); |
4bc71cb9 | 1112 | rtnl_unlock(); |
853e2bd2 | 1113 | |
b6829c72 | 1114 | if (!vn_port) { |
853e2bd2 BG |
1115 | printk(KERN_ERR PFX "bnx2fc_vport_create (%s) failed\n", |
1116 | netdev->name); | |
1117 | return -EIO; | |
1118 | } | |
1119 | ||
10755d3f JC |
1120 | if (bnx2fc_devloss_tmo) |
1121 | fc_host_dev_loss_tmo(vn_port->host) = bnx2fc_devloss_tmo; | |
1122 | ||
853e2bd2 BG |
1123 | if (disabled) { |
1124 | fc_vport_set_state(vport, FC_VPORT_DISABLED); | |
1125 | } else { | |
1126 | vn_port->boot_time = jiffies; | |
1127 | fc_lport_init(vn_port); | |
1128 | fc_fabric_login(vn_port); | |
1129 | fc_vport_setlink(vn_port); | |
1130 | } | |
1131 | return 0; | |
1132 | } | |
1133 | ||
abc49a93 BPG |
1134 | static void bnx2fc_free_vport(struct bnx2fc_hba *hba, struct fc_lport *lport) |
1135 | { | |
1136 | struct bnx2fc_lport *blport, *tmp; | |
1137 | ||
1138 | spin_lock_bh(&hba->hba_lock); | |
1139 | list_for_each_entry_safe(blport, tmp, &hba->vports, list) { | |
1140 | if (blport->lport == lport) { | |
1141 | list_del(&blport->list); | |
1142 | kfree(blport); | |
1143 | } | |
1144 | } | |
1145 | spin_unlock_bh(&hba->hba_lock); | |
1146 | } | |
1147 | ||
853e2bd2 BG |
1148 | static int bnx2fc_vport_destroy(struct fc_vport *vport) |
1149 | { | |
1150 | struct Scsi_Host *shost = vport_to_shost(vport); | |
1151 | struct fc_lport *n_port = shost_priv(shost); | |
1152 | struct fc_lport *vn_port = vport->dd_data; | |
1153 | struct fcoe_port *port = lport_priv(vn_port); | |
abc49a93 | 1154 | struct bnx2fc_interface *interface = port->priv; |
cdf54668 BPG |
1155 | struct fc_lport *v_port; |
1156 | bool found = false; | |
853e2bd2 BG |
1157 | |
1158 | mutex_lock(&n_port->lp_mutex); | |
cdf54668 BPG |
1159 | list_for_each_entry(v_port, &n_port->vports, list) |
1160 | if (v_port->vport == vport) { | |
1161 | found = true; | |
1162 | break; | |
1163 | } | |
1164 | ||
1165 | if (!found) { | |
1166 | mutex_unlock(&n_port->lp_mutex); | |
1167 | return -ENOENT; | |
1168 | } | |
853e2bd2 BG |
1169 | list_del(&vn_port->list); |
1170 | mutex_unlock(&n_port->lp_mutex); | |
abc49a93 BPG |
1171 | bnx2fc_free_vport(interface->hba, port->lport); |
1172 | bnx2fc_port_shutdown(port->lport); | |
1173 | bnx2fc_interface_put(interface); | |
853e2bd2 BG |
1174 | queue_work(bnx2fc_wq, &port->destroy_work); |
1175 | return 0; | |
1176 | } | |
1177 | ||
1178 | static int bnx2fc_vport_disable(struct fc_vport *vport, bool disable) | |
1179 | { | |
1180 | struct fc_lport *lport = vport->dd_data; | |
1181 | ||
1182 | if (disable) { | |
1183 | fc_vport_set_state(vport, FC_VPORT_DISABLED); | |
1184 | fc_fabric_logoff(lport); | |
1185 | } else { | |
1186 | lport->boot_time = jiffies; | |
1187 | fc_fabric_login(lport); | |
1188 | fc_vport_setlink(lport); | |
1189 | } | |
1190 | return 0; | |
1191 | } | |
1192 | ||
1193 | ||
776cebca | 1194 | static int bnx2fc_interface_setup(struct bnx2fc_interface *interface) |
853e2bd2 | 1195 | { |
aea71a02 BPG |
1196 | struct net_device *netdev = interface->netdev; |
1197 | struct net_device *physdev = interface->hba->phys_dev; | |
fd8f8902 | 1198 | struct fcoe_ctlr *ctlr = bnx2fc_to_ctlr(interface); |
853e2bd2 BG |
1199 | struct netdev_hw_addr *ha; |
1200 | int sel_san_mac = 0; | |
1201 | ||
853e2bd2 BG |
1202 | /* setup Source MAC Address */ |
1203 | rcu_read_lock(); | |
1204 | for_each_dev_addr(physdev, ha) { | |
1205 | BNX2FC_MISC_DBG("net_config: ha->type = %d, fip_mac = ", | |
1206 | ha->type); | |
1207 | printk(KERN_INFO "%2x:%2x:%2x:%2x:%2x:%2x\n", ha->addr[0], | |
1208 | ha->addr[1], ha->addr[2], ha->addr[3], | |
1209 | ha->addr[4], ha->addr[5]); | |
1210 | ||
1211 | if ((ha->type == NETDEV_HW_ADDR_T_SAN) && | |
1212 | (is_valid_ether_addr(ha->addr))) { | |
fd8f8902 | 1213 | memcpy(ctlr->ctl_src_addr, ha->addr, |
aea71a02 | 1214 | ETH_ALEN); |
853e2bd2 BG |
1215 | sel_san_mac = 1; |
1216 | BNX2FC_MISC_DBG("Found SAN MAC\n"); | |
1217 | } | |
1218 | } | |
1219 | rcu_read_unlock(); | |
1220 | ||
1221 | if (!sel_san_mac) | |
1222 | return -ENODEV; | |
1223 | ||
aea71a02 BPG |
1224 | interface->fip_packet_type.func = bnx2fc_fip_recv; |
1225 | interface->fip_packet_type.type = htons(ETH_P_FIP); | |
1226 | interface->fip_packet_type.dev = netdev; | |
1227 | dev_add_pack(&interface->fip_packet_type); | |
853e2bd2 | 1228 | |
aea71a02 BPG |
1229 | interface->fcoe_packet_type.func = bnx2fc_rcv; |
1230 | interface->fcoe_packet_type.type = __constant_htons(ETH_P_FCOE); | |
1231 | interface->fcoe_packet_type.dev = netdev; | |
1232 | dev_add_pack(&interface->fcoe_packet_type); | |
853e2bd2 BG |
1233 | |
1234 | return 0; | |
1235 | } | |
1236 | ||
1237 | static int bnx2fc_attach_transport(void) | |
1238 | { | |
1239 | bnx2fc_transport_template = | |
1240 | fc_attach_transport(&bnx2fc_transport_function); | |
1241 | ||
1242 | if (bnx2fc_transport_template == NULL) { | |
1243 | printk(KERN_ERR PFX "Failed to attach FC transport\n"); | |
1244 | return -ENODEV; | |
1245 | } | |
1246 | ||
1247 | bnx2fc_vport_xport_template = | |
1248 | fc_attach_transport(&bnx2fc_vport_xport_function); | |
1249 | if (bnx2fc_vport_xport_template == NULL) { | |
1250 | printk(KERN_ERR PFX | |
1251 | "Failed to attach FC transport for vport\n"); | |
1252 | fc_release_transport(bnx2fc_transport_template); | |
1253 | bnx2fc_transport_template = NULL; | |
1254 | return -ENODEV; | |
1255 | } | |
1256 | return 0; | |
1257 | } | |
1258 | static void bnx2fc_release_transport(void) | |
1259 | { | |
1260 | fc_release_transport(bnx2fc_transport_template); | |
1261 | fc_release_transport(bnx2fc_vport_xport_template); | |
1262 | bnx2fc_transport_template = NULL; | |
1263 | bnx2fc_vport_xport_template = NULL; | |
1264 | } | |
1265 | ||
1266 | static void bnx2fc_interface_release(struct kref *kref) | |
1267 | { | |
8d55e507 | 1268 | struct fcoe_ctlr_device *ctlr_dev; |
aea71a02 | 1269 | struct bnx2fc_interface *interface; |
fd8f8902 | 1270 | struct fcoe_ctlr *ctlr; |
853e2bd2 | 1271 | struct net_device *netdev; |
853e2bd2 | 1272 | |
aea71a02 | 1273 | interface = container_of(kref, struct bnx2fc_interface, kref); |
068bdce4 | 1274 | BNX2FC_MISC_DBG("Interface is being released\n"); |
853e2bd2 | 1275 | |
fd8f8902 | 1276 | ctlr = bnx2fc_to_ctlr(interface); |
8d55e507 | 1277 | ctlr_dev = fcoe_ctlr_to_ctlr_dev(ctlr); |
aea71a02 | 1278 | netdev = interface->netdev; |
853e2bd2 BG |
1279 | |
1280 | /* tear-down FIP controller */ | |
aea71a02 | 1281 | if (test_and_clear_bit(BNX2FC_CTLR_INIT_DONE, &interface->if_flags)) |
fd8f8902 | 1282 | fcoe_ctlr_destroy(ctlr); |
aea71a02 | 1283 | |
8d55e507 | 1284 | fcoe_ctlr_device_delete(ctlr_dev); |
853e2bd2 | 1285 | |
853e2bd2 BG |
1286 | dev_put(netdev); |
1287 | module_put(THIS_MODULE); | |
1288 | } | |
1289 | ||
aea71a02 | 1290 | static inline void bnx2fc_interface_get(struct bnx2fc_interface *interface) |
853e2bd2 | 1291 | { |
aea71a02 | 1292 | kref_get(&interface->kref); |
853e2bd2 BG |
1293 | } |
1294 | ||
aea71a02 | 1295 | static inline void bnx2fc_interface_put(struct bnx2fc_interface *interface) |
853e2bd2 | 1296 | { |
aea71a02 | 1297 | kref_put(&interface->kref, bnx2fc_interface_release); |
853e2bd2 | 1298 | } |
aea71a02 | 1299 | static void bnx2fc_hba_destroy(struct bnx2fc_hba *hba) |
853e2bd2 | 1300 | { |
aea71a02 BPG |
1301 | /* Free the command manager */ |
1302 | if (hba->cmd_mgr) { | |
1303 | bnx2fc_cmd_mgr_free(hba->cmd_mgr); | |
1304 | hba->cmd_mgr = NULL; | |
1305 | } | |
1306 | kfree(hba->tgt_ofld_list); | |
853e2bd2 BG |
1307 | bnx2fc_unbind_pcidev(hba); |
1308 | kfree(hba); | |
1309 | } | |
1310 | ||
1311 | /** | |
aea71a02 | 1312 | * bnx2fc_hba_create - create a new bnx2fc hba |
853e2bd2 BG |
1313 | * |
1314 | * @cnic: pointer to cnic device | |
1315 | * | |
aea71a02 BPG |
1316 | * Creates a new FCoE hba on the given device. |
1317 | * | |
853e2bd2 | 1318 | */ |
aea71a02 | 1319 | static struct bnx2fc_hba *bnx2fc_hba_create(struct cnic_dev *cnic) |
853e2bd2 BG |
1320 | { |
1321 | struct bnx2fc_hba *hba; | |
2e499d3c | 1322 | struct fcoe_capabilities *fcoe_cap; |
853e2bd2 BG |
1323 | int rc; |
1324 | ||
1325 | hba = kzalloc(sizeof(*hba), GFP_KERNEL); | |
1326 | if (!hba) { | |
1327 | printk(KERN_ERR PFX "Unable to allocate hba structure\n"); | |
1328 | return NULL; | |
1329 | } | |
1330 | spin_lock_init(&hba->hba_lock); | |
1331 | mutex_init(&hba->hba_mutex); | |
1332 | ||
1333 | hba->cnic = cnic; | |
0eb43b4b BPG |
1334 | |
1335 | hba->max_tasks = cnic->max_fcoe_exchanges; | |
1336 | hba->elstm_xids = (hba->max_tasks / 2); | |
1337 | hba->max_outstanding_cmds = hba->elstm_xids; | |
1338 | hba->max_xid = (hba->max_tasks - 1); | |
1339 | ||
853e2bd2 | 1340 | rc = bnx2fc_bind_pcidev(hba); |
aea71a02 BPG |
1341 | if (rc) { |
1342 | printk(KERN_ERR PFX "create_adapter: bind error\n"); | |
853e2bd2 | 1343 | goto bind_err; |
aea71a02 | 1344 | } |
853e2bd2 | 1345 | hba->phys_dev = cnic->netdev; |
aea71a02 BPG |
1346 | hba->next_conn_id = 0; |
1347 | ||
1348 | hba->tgt_ofld_list = | |
1349 | kzalloc(sizeof(struct bnx2fc_rport *) * BNX2FC_NUM_MAX_SESS, | |
1350 | GFP_KERNEL); | |
1351 | if (!hba->tgt_ofld_list) { | |
1352 | printk(KERN_ERR PFX "Unable to allocate tgt offload list\n"); | |
1353 | goto tgtofld_err; | |
1354 | } | |
1355 | ||
1356 | hba->num_ofld_sess = 0; | |
1357 | ||
0eb43b4b | 1358 | hba->cmd_mgr = bnx2fc_cmd_mgr_alloc(hba); |
aea71a02 BPG |
1359 | if (!hba->cmd_mgr) { |
1360 | printk(KERN_ERR PFX "em_config:bnx2fc_cmd_mgr_alloc failed\n"); | |
1361 | goto cmgr_err; | |
1362 | } | |
2e499d3c BW |
1363 | fcoe_cap = &hba->fcoe_cap; |
1364 | ||
1365 | fcoe_cap->capability1 = BNX2FC_TM_MAX_SQES << | |
1366 | FCOE_IOS_PER_CONNECTION_SHIFT; | |
1367 | fcoe_cap->capability1 |= BNX2FC_NUM_MAX_SESS << | |
1368 | FCOE_LOGINS_PER_PORT_SHIFT; | |
0eb43b4b | 1369 | fcoe_cap->capability2 = hba->max_outstanding_cmds << |
2e499d3c BW |
1370 | FCOE_NUMBER_OF_EXCHANGES_SHIFT; |
1371 | fcoe_cap->capability2 |= BNX2FC_MAX_NPIV << | |
1372 | FCOE_NPIV_WWN_PER_PORT_SHIFT; | |
1373 | fcoe_cap->capability3 = BNX2FC_NUM_MAX_SESS << | |
1374 | FCOE_TARGETS_SUPPORTED_SHIFT; | |
0eb43b4b | 1375 | fcoe_cap->capability3 |= hba->max_outstanding_cmds << |
2e499d3c BW |
1376 | FCOE_OUTSTANDING_COMMANDS_SHIFT; |
1377 | fcoe_cap->capability4 = FCOE_CAPABILITY4_STATEFUL; | |
853e2bd2 BG |
1378 | |
1379 | init_waitqueue_head(&hba->shutdown_wait); | |
1380 | init_waitqueue_head(&hba->destroy_wait); | |
aea71a02 | 1381 | INIT_LIST_HEAD(&hba->vports); |
853e2bd2 BG |
1382 | |
1383 | return hba; | |
aea71a02 BPG |
1384 | |
1385 | cmgr_err: | |
1386 | kfree(hba->tgt_ofld_list); | |
1387 | tgtofld_err: | |
1388 | bnx2fc_unbind_pcidev(hba); | |
853e2bd2 | 1389 | bind_err: |
853e2bd2 BG |
1390 | kfree(hba); |
1391 | return NULL; | |
1392 | } | |
1393 | ||
aea71a02 BPG |
1394 | struct bnx2fc_interface *bnx2fc_interface_create(struct bnx2fc_hba *hba, |
1395 | struct net_device *netdev, | |
1396 | enum fip_state fip_mode) | |
853e2bd2 | 1397 | { |
8d55e507 | 1398 | struct fcoe_ctlr_device *ctlr_dev; |
aea71a02 | 1399 | struct bnx2fc_interface *interface; |
fd8f8902 RL |
1400 | struct fcoe_ctlr *ctlr; |
1401 | int size; | |
853e2bd2 | 1402 | int rc = 0; |
853e2bd2 | 1403 | |
fd8f8902 | 1404 | size = (sizeof(*interface) + sizeof(struct fcoe_ctlr)); |
8d55e507 RL |
1405 | ctlr_dev = fcoe_ctlr_device_add(&netdev->dev, &bnx2fc_fcoe_sysfs_templ, |
1406 | size); | |
1407 | if (!ctlr_dev) { | |
aea71a02 BPG |
1408 | printk(KERN_ERR PFX "Unable to allocate interface structure\n"); |
1409 | return NULL; | |
1410 | } | |
8d55e507 | 1411 | ctlr = fcoe_ctlr_device_priv(ctlr_dev); |
9d34876f | 1412 | ctlr->cdev = ctlr_dev; |
fd8f8902 | 1413 | interface = fcoe_ctlr_priv(ctlr); |
853e2bd2 | 1414 | dev_hold(netdev); |
aea71a02 BPG |
1415 | kref_init(&interface->kref); |
1416 | interface->hba = hba; | |
1417 | interface->netdev = netdev; | |
853e2bd2 BG |
1418 | |
1419 | /* Initialize FIP */ | |
fd8f8902 RL |
1420 | fcoe_ctlr_init(ctlr, fip_mode); |
1421 | ctlr->send = bnx2fc_fip_send; | |
1422 | ctlr->update_mac = bnx2fc_update_src_mac; | |
1423 | ctlr->get_src_addr = bnx2fc_get_src_mac; | |
aea71a02 | 1424 | set_bit(BNX2FC_CTLR_INIT_DONE, &interface->if_flags); |
853e2bd2 | 1425 | |
776cebca | 1426 | rc = bnx2fc_interface_setup(interface); |
aea71a02 BPG |
1427 | if (!rc) |
1428 | return interface; | |
853e2bd2 | 1429 | |
fd8f8902 | 1430 | fcoe_ctlr_destroy(ctlr); |
853e2bd2 | 1431 | dev_put(netdev); |
8d55e507 | 1432 | fcoe_ctlr_device_delete(ctlr_dev); |
aea71a02 | 1433 | return NULL; |
853e2bd2 BG |
1434 | } |
1435 | ||
1436 | /** | |
1437 | * bnx2fc_if_create - Create FCoE instance on a given interface | |
1438 | * | |
aea71a02 | 1439 | * @interface: FCoE interface to create a local port on |
853e2bd2 BG |
1440 | * @parent: Device pointer to be the parent in sysfs for the SCSI host |
1441 | * @npiv: Indicates if the port is vport or not | |
1442 | * | |
1443 | * Creates a fc_lport instance and a Scsi_Host instance and configure them. | |
1444 | * | |
1445 | * Returns: Allocated fc_lport or an error pointer | |
1446 | */ | |
aea71a02 | 1447 | static struct fc_lport *bnx2fc_if_create(struct bnx2fc_interface *interface, |
853e2bd2 BG |
1448 | struct device *parent, int npiv) |
1449 | { | |
fd8f8902 | 1450 | struct fcoe_ctlr *ctlr = bnx2fc_to_ctlr(interface); |
134a4e27 | 1451 | struct fc_lport *lport, *n_port; |
853e2bd2 BG |
1452 | struct fcoe_port *port; |
1453 | struct Scsi_Host *shost; | |
1454 | struct fc_vport *vport = dev_to_vport(parent); | |
d36b3279 | 1455 | struct bnx2fc_lport *blport; |
0eb43b4b | 1456 | struct bnx2fc_hba *hba = interface->hba; |
853e2bd2 BG |
1457 | int rc = 0; |
1458 | ||
d36b3279 BPG |
1459 | blport = kzalloc(sizeof(struct bnx2fc_lport), GFP_KERNEL); |
1460 | if (!blport) { | |
fd8f8902 | 1461 | BNX2FC_HBA_DBG(ctlr->lp, "Unable to alloc blport\n"); |
d36b3279 BPG |
1462 | return NULL; |
1463 | } | |
1464 | ||
853e2bd2 | 1465 | /* Allocate Scsi_Host structure */ |
0eb43b4b | 1466 | bnx2fc_shost_template.can_queue = hba->max_outstanding_cmds; |
134a4e27 VD |
1467 | if (!npiv) |
1468 | lport = libfc_host_alloc(&bnx2fc_shost_template, sizeof(*port)); | |
1469 | else | |
1470 | lport = libfc_vport_create(vport, sizeof(*port)); | |
853e2bd2 BG |
1471 | |
1472 | if (!lport) { | |
1473 | printk(KERN_ERR PFX "could not allocate scsi host structure\n"); | |
d36b3279 | 1474 | goto free_blport; |
853e2bd2 BG |
1475 | } |
1476 | shost = lport->host; | |
1477 | port = lport_priv(lport); | |
1478 | port->lport = lport; | |
aea71a02 | 1479 | port->priv = interface; |
c3d7909b | 1480 | port->get_netdev = bnx2fc_netdev; |
853e2bd2 BG |
1481 | INIT_WORK(&port->destroy_work, bnx2fc_destroy_work); |
1482 | ||
1483 | /* Configure fcoe_port */ | |
1484 | rc = bnx2fc_lport_config(lport); | |
1485 | if (rc) | |
1486 | goto lp_config_err; | |
1487 | ||
1488 | if (npiv) { | |
853e2bd2 BG |
1489 | printk(KERN_ERR PFX "Setting vport names, 0x%llX 0x%llX\n", |
1490 | vport->node_name, vport->port_name); | |
1491 | fc_set_wwnn(lport, vport->node_name); | |
1492 | fc_set_wwpn(lport, vport->port_name); | |
1493 | } | |
1494 | /* Configure netdev and networking properties of the lport */ | |
52439607 | 1495 | rc = bnx2fc_net_config(lport, interface->netdev); |
853e2bd2 BG |
1496 | if (rc) { |
1497 | printk(KERN_ERR PFX "Error on bnx2fc_net_config\n"); | |
1498 | goto lp_config_err; | |
1499 | } | |
1500 | ||
1501 | rc = bnx2fc_shost_config(lport, parent); | |
1502 | if (rc) { | |
1503 | printk(KERN_ERR PFX "Couldnt configure shost for %s\n", | |
aea71a02 | 1504 | interface->netdev->name); |
853e2bd2 BG |
1505 | goto lp_config_err; |
1506 | } | |
1507 | ||
1508 | /* Initialize the libfc library */ | |
1509 | rc = bnx2fc_libfc_config(lport); | |
1510 | if (rc) { | |
1511 | printk(KERN_ERR PFX "Couldnt configure libfc\n"); | |
1512 | goto shost_err; | |
1513 | } | |
1514 | fc_host_port_type(lport->host) = FC_PORTTYPE_UNKNOWN; | |
1515 | ||
10755d3f JC |
1516 | if (bnx2fc_devloss_tmo) |
1517 | fc_host_dev_loss_tmo(shost) = bnx2fc_devloss_tmo; | |
1518 | ||
853e2bd2 | 1519 | /* Allocate exchange manager */ |
134a4e27 | 1520 | if (!npiv) |
0eb43b4b | 1521 | rc = bnx2fc_em_config(lport, hba); |
134a4e27 VD |
1522 | else { |
1523 | shost = vport_to_shost(vport); | |
1524 | n_port = shost_priv(shost); | |
1525 | rc = fc_exch_mgr_list_clone(n_port, lport); | |
1526 | } | |
1527 | ||
1528 | if (rc) { | |
1529 | printk(KERN_ERR PFX "Error on bnx2fc_em_config\n"); | |
1530 | goto shost_err; | |
853e2bd2 BG |
1531 | } |
1532 | ||
aea71a02 | 1533 | bnx2fc_interface_get(interface); |
d36b3279 BPG |
1534 | |
1535 | spin_lock_bh(&hba->hba_lock); | |
1536 | blport->lport = lport; | |
1537 | list_add_tail(&blport->list, &hba->vports); | |
1538 | spin_unlock_bh(&hba->hba_lock); | |
1539 | ||
853e2bd2 BG |
1540 | return lport; |
1541 | ||
1542 | shost_err: | |
1543 | scsi_remove_host(shost); | |
1544 | lp_config_err: | |
1545 | scsi_host_put(lport->host); | |
d36b3279 BPG |
1546 | free_blport: |
1547 | kfree(blport); | |
853e2bd2 BG |
1548 | return NULL; |
1549 | } | |
1550 | ||
013068fa | 1551 | static void bnx2fc_net_cleanup(struct bnx2fc_interface *interface) |
853e2bd2 BG |
1552 | { |
1553 | /* Dont listen for Ethernet packets anymore */ | |
aea71a02 BPG |
1554 | __dev_remove_pack(&interface->fcoe_packet_type); |
1555 | __dev_remove_pack(&interface->fip_packet_type); | |
853e2bd2 BG |
1556 | synchronize_net(); |
1557 | } | |
1558 | ||
776cebca | 1559 | static void bnx2fc_interface_cleanup(struct bnx2fc_interface *interface) |
853e2bd2 | 1560 | { |
fd8f8902 RL |
1561 | struct fcoe_ctlr *ctlr = bnx2fc_to_ctlr(interface); |
1562 | struct fc_lport *lport = ctlr->lp; | |
853e2bd2 | 1563 | struct fcoe_port *port = lport_priv(lport); |
9be17fc4 | 1564 | struct bnx2fc_hba *hba = interface->hba; |
853e2bd2 | 1565 | |
853e2bd2 BG |
1566 | /* Stop the transmit retry timer */ |
1567 | del_timer_sync(&port->timer); | |
1568 | ||
1569 | /* Free existing transmit skbs */ | |
1570 | fcoe_clean_pending_queue(lport); | |
1571 | ||
013068fa | 1572 | bnx2fc_net_cleanup(interface); |
9be17fc4 | 1573 | |
abc49a93 | 1574 | bnx2fc_free_vport(hba, lport); |
9be17fc4 BPG |
1575 | } |
1576 | ||
1577 | static void bnx2fc_if_destroy(struct fc_lport *lport) | |
1578 | { | |
1579 | ||
853e2bd2 BG |
1580 | /* Free queued packets for the receive thread */ |
1581 | bnx2fc_clean_rx_queue(lport); | |
1582 | ||
1583 | /* Detach from scsi-ml */ | |
1584 | fc_remove_host(lport->host); | |
1585 | scsi_remove_host(lport->host); | |
1586 | ||
1587 | /* | |
1588 | * Note that only the physical lport will have the exchange manager. | |
1589 | * for vports, this function is NOP | |
1590 | */ | |
1591 | fc_exch_mgr_free(lport); | |
1592 | ||
1593 | /* Free memory used by statistical counters */ | |
1594 | fc_lport_free_stats(lport); | |
1595 | ||
1596 | /* Release Scsi_Host */ | |
1597 | scsi_host_put(lport->host); | |
1598 | } | |
1599 | ||
eccdcd02 | 1600 | static void __bnx2fc_destroy(struct bnx2fc_interface *interface) |
abc49a93 | 1601 | { |
fd8f8902 RL |
1602 | struct fcoe_ctlr *ctlr = bnx2fc_to_ctlr(interface); |
1603 | struct fc_lport *lport = ctlr->lp; | |
0cbf32e1 | 1604 | struct fcoe_port *port = lport_priv(lport); |
abc49a93 BPG |
1605 | |
1606 | bnx2fc_interface_cleanup(interface); | |
1607 | bnx2fc_stop(interface); | |
abc49a93 | 1608 | list_del(&interface->list); |
abc49a93 | 1609 | bnx2fc_interface_put(interface); |
0cbf32e1 | 1610 | queue_work(bnx2fc_wq, &port->destroy_work); |
abc49a93 BPG |
1611 | } |
1612 | ||
853e2bd2 BG |
1613 | /** |
1614 | * bnx2fc_destroy - Destroy a bnx2fc FCoE interface | |
1615 | * | |
1616 | * @buffer: The name of the Ethernet interface to be destroyed | |
1617 | * @kp: The associated kernel parameter | |
1618 | * | |
1619 | * Called from sysfs. | |
1620 | * | |
1621 | * Returns: 0 for success | |
1622 | */ | |
1623 | static int bnx2fc_destroy(struct net_device *netdev) | |
1624 | { | |
aea71a02 | 1625 | struct bnx2fc_interface *interface = NULL; |
2a7b29c5 | 1626 | struct workqueue_struct *timer_work_queue; |
fd8f8902 | 1627 | struct fcoe_ctlr *ctlr; |
853e2bd2 BG |
1628 | int rc = 0; |
1629 | ||
6702ca1d | 1630 | rtnl_lock(); |
853e2bd2 | 1631 | mutex_lock(&bnx2fc_dev_lock); |
853e2bd2 | 1632 | |
aea71a02 | 1633 | interface = bnx2fc_interface_lookup(netdev); |
fd8f8902 RL |
1634 | ctlr = bnx2fc_to_ctlr(interface); |
1635 | if (!interface || !ctlr->lp) { | |
853e2bd2 | 1636 | rc = -ENODEV; |
aea71a02 | 1637 | printk(KERN_ERR PFX "bnx2fc_destroy: interface or lport not found\n"); |
853e2bd2 BG |
1638 | goto netdev_err; |
1639 | } | |
1640 | ||
2a7b29c5 | 1641 | timer_work_queue = interface->timer_work_queue; |
eccdcd02 | 1642 | __bnx2fc_destroy(interface); |
2a7b29c5 | 1643 | destroy_workqueue(timer_work_queue); |
853e2bd2 | 1644 | |
853e2bd2 BG |
1645 | netdev_err: |
1646 | mutex_unlock(&bnx2fc_dev_lock); | |
1647 | rtnl_unlock(); | |
1648 | return rc; | |
1649 | } | |
1650 | ||
1651 | static void bnx2fc_destroy_work(struct work_struct *work) | |
1652 | { | |
1653 | struct fcoe_port *port; | |
1654 | struct fc_lport *lport; | |
1655 | ||
1656 | port = container_of(work, struct fcoe_port, destroy_work); | |
1657 | lport = port->lport; | |
1658 | ||
1659 | BNX2FC_HBA_DBG(lport, "Entered bnx2fc_destroy_work\n"); | |
1660 | ||
9be17fc4 | 1661 | bnx2fc_if_destroy(lport); |
853e2bd2 BG |
1662 | } |
1663 | ||
1664 | static void bnx2fc_unbind_adapter_devices(struct bnx2fc_hba *hba) | |
1665 | { | |
1666 | bnx2fc_free_fw_resc(hba); | |
1667 | bnx2fc_free_task_ctx(hba); | |
1668 | } | |
1669 | ||
1670 | /** | |
1671 | * bnx2fc_bind_adapter_devices - binds bnx2fc adapter with the associated | |
1672 | * pci structure | |
1673 | * | |
1674 | * @hba: Adapter instance | |
1675 | */ | |
1676 | static int bnx2fc_bind_adapter_devices(struct bnx2fc_hba *hba) | |
1677 | { | |
1678 | if (bnx2fc_setup_task_ctx(hba)) | |
1679 | goto mem_err; | |
1680 | ||
1681 | if (bnx2fc_setup_fw_resc(hba)) | |
1682 | goto mem_err; | |
1683 | ||
1684 | return 0; | |
1685 | mem_err: | |
1686 | bnx2fc_unbind_adapter_devices(hba); | |
1687 | return -ENOMEM; | |
1688 | } | |
1689 | ||
1690 | static int bnx2fc_bind_pcidev(struct bnx2fc_hba *hba) | |
1691 | { | |
1692 | struct cnic_dev *cnic; | |
c13d2b6d | 1693 | struct pci_dev *pdev; |
853e2bd2 BG |
1694 | |
1695 | if (!hba->cnic) { | |
1696 | printk(KERN_ERR PFX "cnic is NULL\n"); | |
1697 | return -ENODEV; | |
1698 | } | |
1699 | cnic = hba->cnic; | |
c13d2b6d BPG |
1700 | pdev = hba->pcidev = cnic->pcidev; |
1701 | if (!hba->pcidev) | |
1702 | return -ENODEV; | |
853e2bd2 | 1703 | |
c13d2b6d BPG |
1704 | switch (pdev->device) { |
1705 | case PCI_DEVICE_ID_NX2_57710: | |
1706 | strncpy(hba->chip_num, "BCM57710", BCM_CHIP_LEN); | |
1707 | break; | |
1708 | case PCI_DEVICE_ID_NX2_57711: | |
1709 | strncpy(hba->chip_num, "BCM57711", BCM_CHIP_LEN); | |
1710 | break; | |
1711 | case PCI_DEVICE_ID_NX2_57712: | |
1712 | case PCI_DEVICE_ID_NX2_57712_MF: | |
1713 | case PCI_DEVICE_ID_NX2_57712_VF: | |
1714 | strncpy(hba->chip_num, "BCM57712", BCM_CHIP_LEN); | |
1715 | break; | |
1716 | case PCI_DEVICE_ID_NX2_57800: | |
1717 | case PCI_DEVICE_ID_NX2_57800_MF: | |
1718 | case PCI_DEVICE_ID_NX2_57800_VF: | |
1719 | strncpy(hba->chip_num, "BCM57800", BCM_CHIP_LEN); | |
1720 | break; | |
1721 | case PCI_DEVICE_ID_NX2_57810: | |
1722 | case PCI_DEVICE_ID_NX2_57810_MF: | |
1723 | case PCI_DEVICE_ID_NX2_57810_VF: | |
1724 | strncpy(hba->chip_num, "BCM57810", BCM_CHIP_LEN); | |
1725 | break; | |
1726 | case PCI_DEVICE_ID_NX2_57840: | |
1727 | case PCI_DEVICE_ID_NX2_57840_MF: | |
1728 | case PCI_DEVICE_ID_NX2_57840_VF: | |
1729 | case PCI_DEVICE_ID_NX2_57840_2_20: | |
1730 | case PCI_DEVICE_ID_NX2_57840_4_10: | |
1731 | strncpy(hba->chip_num, "BCM57840", BCM_CHIP_LEN); | |
1732 | break; | |
1733 | default: | |
1734 | pr_err(PFX "Unknown device id 0x%x\n", pdev->device); | |
1735 | break; | |
1736 | } | |
1737 | pci_dev_get(hba->pcidev); | |
853e2bd2 BG |
1738 | return 0; |
1739 | } | |
1740 | ||
1741 | static void bnx2fc_unbind_pcidev(struct bnx2fc_hba *hba) | |
1742 | { | |
c13d2b6d BPG |
1743 | if (hba->pcidev) { |
1744 | hba->chip_num[0] = '\0'; | |
853e2bd2 | 1745 | pci_dev_put(hba->pcidev); |
c13d2b6d | 1746 | } |
853e2bd2 BG |
1747 | hba->pcidev = NULL; |
1748 | } | |
1749 | ||
2e499d3c BW |
1750 | /** |
1751 | * bnx2fc_ulp_get_stats - cnic callback to populate FCoE stats | |
1752 | * | |
1753 | * @handle: transport handle pointing to adapter struture | |
1754 | */ | |
1755 | static int bnx2fc_ulp_get_stats(void *handle) | |
1756 | { | |
1757 | struct bnx2fc_hba *hba = handle; | |
1758 | struct cnic_dev *cnic; | |
1759 | struct fcoe_stats_info *stats_addr; | |
1760 | ||
1761 | if (!hba) | |
1762 | return -EINVAL; | |
1763 | ||
1764 | cnic = hba->cnic; | |
1765 | stats_addr = &cnic->stats_addr->fcoe_stat; | |
1766 | if (!stats_addr) | |
1767 | return -EINVAL; | |
1768 | ||
1769 | strncpy(stats_addr->version, BNX2FC_VERSION, | |
1770 | sizeof(stats_addr->version)); | |
1771 | stats_addr->txq_size = BNX2FC_SQ_WQES_MAX; | |
1772 | stats_addr->rxq_size = BNX2FC_CQ_WQES_MAX; | |
1773 | ||
1774 | return 0; | |
1775 | } | |
853e2bd2 BG |
1776 | |
1777 | ||
1778 | /** | |
1779 | * bnx2fc_ulp_start - cnic callback to initialize & start adapter instance | |
1780 | * | |
59e13d48 | 1781 | * @handle: transport handle pointing to adapter structure |
853e2bd2 BG |
1782 | * |
1783 | * This function maps adapter structure to pcidev structure and initiates | |
1784 | * firmware handshake to enable/initialize on-chip FCoE components. | |
1785 | * This bnx2fc - cnic interface api callback is used after following | |
1786 | * conditions are met - | |
1787 | * a) underlying network interface is up (marked by event NETDEV_UP | |
1788 | * from netdev | |
1789 | * b) bnx2fc adatper structure is registered. | |
1790 | */ | |
1791 | static void bnx2fc_ulp_start(void *handle) | |
1792 | { | |
1793 | struct bnx2fc_hba *hba = handle; | |
aea71a02 | 1794 | struct bnx2fc_interface *interface; |
fd8f8902 | 1795 | struct fcoe_ctlr *ctlr; |
aea71a02 | 1796 | struct fc_lport *lport; |
853e2bd2 | 1797 | |
853e2bd2 BG |
1798 | mutex_lock(&bnx2fc_dev_lock); |
1799 | ||
aea71a02 | 1800 | if (!test_bit(BNX2FC_FLAG_FW_INIT_DONE, &hba->flags)) |
853e2bd2 BG |
1801 | bnx2fc_fw_init(hba); |
1802 | ||
853e2bd2 BG |
1803 | BNX2FC_MISC_DBG("bnx2fc started.\n"); |
1804 | ||
aea71a02 BPG |
1805 | list_for_each_entry(interface, &if_list, list) { |
1806 | if (interface->hba == hba) { | |
fd8f8902 RL |
1807 | ctlr = bnx2fc_to_ctlr(interface); |
1808 | lport = ctlr->lp; | |
aea71a02 BPG |
1809 | /* Kick off Fabric discovery*/ |
1810 | printk(KERN_ERR PFX "ulp_init: start discovery\n"); | |
1811 | lport->tt.frame_send = bnx2fc_xmit; | |
1812 | bnx2fc_start_disc(interface); | |
1813 | } | |
853e2bd2 | 1814 | } |
aea71a02 BPG |
1815 | |
1816 | mutex_unlock(&bnx2fc_dev_lock); | |
853e2bd2 BG |
1817 | } |
1818 | ||
1819 | static void bnx2fc_port_shutdown(struct fc_lport *lport) | |
1820 | { | |
1821 | BNX2FC_MISC_DBG("Entered %s\n", __func__); | |
1822 | fc_fabric_logoff(lport); | |
1823 | fc_lport_destroy(lport); | |
1824 | } | |
1825 | ||
aea71a02 | 1826 | static void bnx2fc_stop(struct bnx2fc_interface *interface) |
853e2bd2 | 1827 | { |
fd8f8902 | 1828 | struct fcoe_ctlr *ctlr = bnx2fc_to_ctlr(interface); |
853e2bd2 BG |
1829 | struct fc_lport *lport; |
1830 | struct fc_lport *vport; | |
1831 | ||
aea71a02 BPG |
1832 | if (!test_bit(BNX2FC_FLAG_FW_INIT_DONE, &interface->hba->flags)) |
1833 | return; | |
853e2bd2 | 1834 | |
fd8f8902 | 1835 | lport = ctlr->lp; |
aea71a02 BPG |
1836 | bnx2fc_port_shutdown(lport); |
1837 | ||
1838 | mutex_lock(&lport->lp_mutex); | |
1839 | list_for_each_entry(vport, &lport->vports, list) | |
1840 | fc_host_port_type(vport->host) = | |
1841 | FC_PORTTYPE_UNKNOWN; | |
1842 | mutex_unlock(&lport->lp_mutex); | |
1843 | fc_host_port_type(lport->host) = FC_PORTTYPE_UNKNOWN; | |
fd8f8902 | 1844 | fcoe_ctlr_link_down(ctlr); |
aea71a02 | 1845 | fcoe_clean_pending_queue(lport); |
853e2bd2 BG |
1846 | } |
1847 | ||
1848 | static int bnx2fc_fw_init(struct bnx2fc_hba *hba) | |
1849 | { | |
1850 | #define BNX2FC_INIT_POLL_TIME (1000 / HZ) | |
1851 | int rc = -1; | |
1852 | int i = HZ; | |
1853 | ||
1854 | rc = bnx2fc_bind_adapter_devices(hba); | |
1855 | if (rc) { | |
1856 | printk(KERN_ALERT PFX | |
1857 | "bnx2fc_bind_adapter_devices failed - rc = %d\n", rc); | |
1858 | goto err_out; | |
1859 | } | |
1860 | ||
1861 | rc = bnx2fc_send_fw_fcoe_init_msg(hba); | |
1862 | if (rc) { | |
1863 | printk(KERN_ALERT PFX | |
1864 | "bnx2fc_send_fw_fcoe_init_msg failed - rc = %d\n", rc); | |
1865 | goto err_unbind; | |
1866 | } | |
1867 | ||
1868 | /* | |
1869 | * Wait until the adapter init message is complete, and adapter | |
1870 | * state is UP. | |
1871 | */ | |
1872 | while (!test_bit(ADAPTER_STATE_UP, &hba->adapter_state) && i--) | |
1873 | msleep(BNX2FC_INIT_POLL_TIME); | |
1874 | ||
1875 | if (!test_bit(ADAPTER_STATE_UP, &hba->adapter_state)) { | |
1876 | printk(KERN_ERR PFX "bnx2fc_start: %s failed to initialize. " | |
1877 | "Ignoring...\n", | |
1878 | hba->cnic->netdev->name); | |
1879 | rc = -1; | |
1880 | goto err_unbind; | |
1881 | } | |
1882 | ||
1883 | ||
aea71a02 | 1884 | set_bit(BNX2FC_FLAG_FW_INIT_DONE, &hba->flags); |
853e2bd2 BG |
1885 | return 0; |
1886 | ||
1887 | err_unbind: | |
1888 | bnx2fc_unbind_adapter_devices(hba); | |
1889 | err_out: | |
1890 | return rc; | |
1891 | } | |
1892 | ||
1893 | static void bnx2fc_fw_destroy(struct bnx2fc_hba *hba) | |
1894 | { | |
aea71a02 | 1895 | if (test_and_clear_bit(BNX2FC_FLAG_FW_INIT_DONE, &hba->flags)) { |
853e2bd2 BG |
1896 | if (bnx2fc_send_fw_fcoe_destroy_msg(hba) == 0) { |
1897 | init_timer(&hba->destroy_timer); | |
1898 | hba->destroy_timer.expires = BNX2FC_FW_TIMEOUT + | |
1899 | jiffies; | |
1900 | hba->destroy_timer.function = bnx2fc_destroy_timer; | |
1901 | hba->destroy_timer.data = (unsigned long)hba; | |
1902 | add_timer(&hba->destroy_timer); | |
1903 | wait_event_interruptible(hba->destroy_wait, | |
aea71a02 BPG |
1904 | test_bit(BNX2FC_FLAG_DESTROY_CMPL, |
1905 | &hba->flags)); | |
cd703ae7 | 1906 | clear_bit(BNX2FC_FLAG_DESTROY_CMPL, &hba->flags); |
853e2bd2 BG |
1907 | /* This should never happen */ |
1908 | if (signal_pending(current)) | |
1909 | flush_signals(current); | |
1910 | ||
1911 | del_timer_sync(&hba->destroy_timer); | |
1912 | } | |
1913 | bnx2fc_unbind_adapter_devices(hba); | |
1914 | } | |
1915 | } | |
1916 | ||
1917 | /** | |
1918 | * bnx2fc_ulp_stop - cnic callback to shutdown adapter instance | |
1919 | * | |
1920 | * @handle: transport handle pointing to adapter structure | |
1921 | * | |
1922 | * Driver checks if adapter is already in shutdown mode, if not start | |
1923 | * the shutdown process. | |
1924 | */ | |
1925 | static void bnx2fc_ulp_stop(void *handle) | |
1926 | { | |
aea71a02 BPG |
1927 | struct bnx2fc_hba *hba = handle; |
1928 | struct bnx2fc_interface *interface; | |
853e2bd2 BG |
1929 | |
1930 | printk(KERN_ERR "ULP_STOP\n"); | |
1931 | ||
1932 | mutex_lock(&bnx2fc_dev_lock); | |
aea71a02 BPG |
1933 | if (!test_bit(BNX2FC_FLAG_FW_INIT_DONE, &hba->flags)) |
1934 | goto exit; | |
1935 | list_for_each_entry(interface, &if_list, list) { | |
1936 | if (interface->hba == hba) | |
1937 | bnx2fc_stop(interface); | |
1938 | } | |
1939 | BUG_ON(hba->num_ofld_sess != 0); | |
1940 | ||
1941 | mutex_lock(&hba->hba_mutex); | |
1942 | clear_bit(ADAPTER_STATE_UP, &hba->adapter_state); | |
1943 | clear_bit(ADAPTER_STATE_GOING_DOWN, | |
1944 | &hba->adapter_state); | |
1945 | ||
1946 | clear_bit(ADAPTER_STATE_READY, &hba->adapter_state); | |
1947 | mutex_unlock(&hba->hba_mutex); | |
1948 | ||
853e2bd2 | 1949 | bnx2fc_fw_destroy(hba); |
aea71a02 | 1950 | exit: |
853e2bd2 BG |
1951 | mutex_unlock(&bnx2fc_dev_lock); |
1952 | } | |
1953 | ||
aea71a02 | 1954 | static void bnx2fc_start_disc(struct bnx2fc_interface *interface) |
853e2bd2 | 1955 | { |
fd8f8902 | 1956 | struct fcoe_ctlr *ctlr = bnx2fc_to_ctlr(interface); |
853e2bd2 BG |
1957 | struct fc_lport *lport; |
1958 | int wait_cnt = 0; | |
1959 | ||
1960 | BNX2FC_MISC_DBG("Entered %s\n", __func__); | |
1961 | /* Kick off FIP/FLOGI */ | |
aea71a02 | 1962 | if (!test_bit(BNX2FC_FLAG_FW_INIT_DONE, &interface->hba->flags)) { |
853e2bd2 BG |
1963 | printk(KERN_ERR PFX "Init not done yet\n"); |
1964 | return; | |
1965 | } | |
1966 | ||
fd8f8902 | 1967 | lport = ctlr->lp; |
853e2bd2 BG |
1968 | BNX2FC_HBA_DBG(lport, "calling fc_fabric_login\n"); |
1969 | ||
8a5badf1 | 1970 | if (!bnx2fc_link_ok(lport) && interface->enabled) { |
853e2bd2 | 1971 | BNX2FC_HBA_DBG(lport, "ctlr_link_up\n"); |
fd8f8902 | 1972 | fcoe_ctlr_link_up(ctlr); |
853e2bd2 | 1973 | fc_host_port_type(lport->host) = FC_PORTTYPE_NPORT; |
aea71a02 | 1974 | set_bit(ADAPTER_STATE_READY, &interface->hba->adapter_state); |
853e2bd2 BG |
1975 | } |
1976 | ||
1977 | /* wait for the FCF to be selected before issuing FLOGI */ | |
fd8f8902 | 1978 | while (!ctlr->sel_fcf) { |
853e2bd2 BG |
1979 | msleep(250); |
1980 | /* give up after 3 secs */ | |
1981 | if (++wait_cnt > 12) | |
1982 | break; | |
1983 | } | |
627e628f BPG |
1984 | |
1985 | /* Reset max receive frame size to default */ | |
1986 | if (fc_set_mfs(lport, BNX2FC_MFS)) | |
1987 | return; | |
1988 | ||
853e2bd2 BG |
1989 | fc_lport_init(lport); |
1990 | fc_fabric_login(lport); | |
1991 | } | |
1992 | ||
1993 | ||
1994 | /** | |
1995 | * bnx2fc_ulp_init - Initialize an adapter instance | |
1996 | * | |
1997 | * @dev : cnic device handle | |
1998 | * Called from cnic_register_driver() context to initialize all | |
1999 | * enumerated cnic devices. This routine allocates adapter structure | |
2000 | * and other device specific resources. | |
2001 | */ | |
2002 | static void bnx2fc_ulp_init(struct cnic_dev *dev) | |
2003 | { | |
2004 | struct bnx2fc_hba *hba; | |
2005 | int rc = 0; | |
2006 | ||
2007 | BNX2FC_MISC_DBG("Entered %s\n", __func__); | |
2008 | /* bnx2fc works only when bnx2x is loaded */ | |
aea71a02 BPG |
2009 | if (!test_bit(CNIC_F_BNX2X_CLASS, &dev->flags) || |
2010 | (dev->max_fcoe_conn == 0)) { | |
853e2bd2 | 2011 | printk(KERN_ERR PFX "bnx2fc FCoE not supported on %s," |
aea71a02 BPG |
2012 | " flags: %lx fcoe_conn: %d\n", |
2013 | dev->netdev->name, dev->flags, dev->max_fcoe_conn); | |
853e2bd2 BG |
2014 | return; |
2015 | } | |
2016 | ||
aea71a02 | 2017 | hba = bnx2fc_hba_create(dev); |
853e2bd2 BG |
2018 | if (!hba) { |
2019 | printk(KERN_ERR PFX "hba initialization failed\n"); | |
2020 | return; | |
2021 | } | |
2022 | ||
2023 | /* Add HBA to the adapter list */ | |
2024 | mutex_lock(&bnx2fc_dev_lock); | |
aea71a02 | 2025 | list_add_tail(&hba->list, &adapter_list); |
853e2bd2 BG |
2026 | adapter_count++; |
2027 | mutex_unlock(&bnx2fc_dev_lock); | |
2028 | ||
2e499d3c | 2029 | dev->fcoe_cap = &hba->fcoe_cap; |
853e2bd2 BG |
2030 | clear_bit(BNX2FC_CNIC_REGISTERED, &hba->reg_with_cnic); |
2031 | rc = dev->register_device(dev, CNIC_ULP_FCOE, | |
2032 | (void *) hba); | |
2033 | if (rc) | |
b2a554ff | 2034 | printk(KERN_ERR PFX "register_device failed, rc = %d\n", rc); |
853e2bd2 BG |
2035 | else |
2036 | set_bit(BNX2FC_CNIC_REGISTERED, &hba->reg_with_cnic); | |
2037 | } | |
2038 | ||
0680810c EW |
2039 | /* Assumes rtnl_lock and the bnx2fc_dev_lock are already taken */ |
2040 | static int __bnx2fc_disable(struct fcoe_ctlr *ctlr) | |
2041 | { | |
2042 | struct bnx2fc_interface *interface = fcoe_ctlr_priv(ctlr); | |
2043 | ||
2044 | if (interface->enabled == true) { | |
2045 | if (!ctlr->lp) { | |
2046 | pr_err(PFX "__bnx2fc_disable: lport not found\n"); | |
2047 | return -ENODEV; | |
2048 | } else { | |
2049 | interface->enabled = false; | |
2050 | fcoe_ctlr_link_down(ctlr); | |
2051 | fcoe_clean_pending_queue(ctlr->lp); | |
2052 | } | |
2053 | } | |
2054 | return 0; | |
2055 | } | |
2056 | ||
6e89ea3f RL |
2057 | /** |
2058 | * Deperecated: Use bnx2fc_enabled() | |
2059 | */ | |
853e2bd2 BG |
2060 | static int bnx2fc_disable(struct net_device *netdev) |
2061 | { | |
aea71a02 | 2062 | struct bnx2fc_interface *interface; |
fd8f8902 | 2063 | struct fcoe_ctlr *ctlr; |
853e2bd2 BG |
2064 | int rc = 0; |
2065 | ||
6702ca1d | 2066 | rtnl_lock(); |
853e2bd2 BG |
2067 | mutex_lock(&bnx2fc_dev_lock); |
2068 | ||
aea71a02 | 2069 | interface = bnx2fc_interface_lookup(netdev); |
fd8f8902 | 2070 | ctlr = bnx2fc_to_ctlr(interface); |
0680810c EW |
2071 | |
2072 | if (!interface) { | |
853e2bd2 | 2073 | rc = -ENODEV; |
0680810c | 2074 | pr_err(PFX "bnx2fc_disable: interface not found\n"); |
853e2bd2 | 2075 | } else { |
0680810c | 2076 | rc = __bnx2fc_disable(ctlr); |
853e2bd2 | 2077 | } |
853e2bd2 BG |
2078 | mutex_unlock(&bnx2fc_dev_lock); |
2079 | rtnl_unlock(); | |
2080 | return rc; | |
2081 | } | |
2082 | ||
2971ff67 JC |
2083 | static uint bnx2fc_npiv_create_vports(struct fc_lport *lport, |
2084 | struct cnic_fc_npiv_tbl *npiv_tbl) | |
2085 | { | |
2086 | struct fc_vport_identifiers vpid; | |
2087 | uint i, created = 0; | |
2088 | ||
2089 | if (npiv_tbl->count > MAX_NPIV_ENTRIES) { | |
2090 | BNX2FC_HBA_DBG(lport, "Exceeded count max of npiv table\n"); | |
2091 | goto done; | |
2092 | } | |
2093 | ||
2094 | /* Sanity check the first entry to make sure it's not 0 */ | |
2095 | if (wwn_to_u64(npiv_tbl->wwnn[0]) == 0 && | |
2096 | wwn_to_u64(npiv_tbl->wwpn[0]) == 0) { | |
2097 | BNX2FC_HBA_DBG(lport, "First NPIV table entries invalid.\n"); | |
2098 | goto done; | |
2099 | } | |
2100 | ||
2101 | vpid.roles = FC_PORT_ROLE_FCP_INITIATOR; | |
2102 | vpid.vport_type = FC_PORTTYPE_NPIV; | |
2103 | vpid.disable = false; | |
2104 | ||
2105 | for (i = 0; i < npiv_tbl->count; i++) { | |
2106 | vpid.node_name = wwn_to_u64(npiv_tbl->wwnn[i]); | |
2107 | vpid.port_name = wwn_to_u64(npiv_tbl->wwpn[i]); | |
2108 | scnprintf(vpid.symbolic_name, sizeof(vpid.symbolic_name), | |
2109 | "NPIV[%u]:%016llx-%016llx", | |
2110 | created, vpid.port_name, vpid.node_name); | |
2111 | if (fc_vport_create(lport->host, 0, &vpid)) | |
2112 | created++; | |
2113 | else | |
2114 | BNX2FC_HBA_DBG(lport, "Failed to create vport\n"); | |
2115 | } | |
2116 | done: | |
2117 | return created; | |
2118 | } | |
2119 | ||
0680810c EW |
2120 | static int __bnx2fc_enable(struct fcoe_ctlr *ctlr) |
2121 | { | |
2122 | struct bnx2fc_interface *interface = fcoe_ctlr_priv(ctlr); | |
2971ff67 | 2123 | struct bnx2fc_hba *hba; |
720ba808 | 2124 | struct cnic_fc_npiv_tbl *npiv_tbl; |
2971ff67 | 2125 | struct fc_lport *lport; |
0680810c EW |
2126 | |
2127 | if (interface->enabled == false) { | |
2128 | if (!ctlr->lp) { | |
2129 | pr_err(PFX "__bnx2fc_enable: lport not found\n"); | |
2130 | return -ENODEV; | |
2131 | } else if (!bnx2fc_link_ok(ctlr->lp)) { | |
2132 | fcoe_ctlr_link_up(ctlr); | |
2133 | interface->enabled = true; | |
2134 | } | |
2135 | } | |
2971ff67 JC |
2136 | |
2137 | /* Create static NPIV ports if any are contained in NVRAM */ | |
2138 | hba = interface->hba; | |
2139 | lport = ctlr->lp; | |
2140 | ||
2141 | if (!hba) | |
2142 | goto done; | |
2143 | ||
2144 | if (!hba->cnic) | |
2145 | goto done; | |
2146 | ||
2147 | if (!lport) | |
2148 | goto done; | |
2149 | ||
2150 | if (!lport->host) | |
2151 | goto done; | |
2152 | ||
2153 | if (!hba->cnic->get_fc_npiv_tbl) | |
2154 | goto done; | |
2155 | ||
720ba808 AB |
2156 | npiv_tbl = kzalloc(sizeof(struct cnic_fc_npiv_tbl), GFP_KERNEL); |
2157 | if (!npiv_tbl) | |
2971ff67 JC |
2158 | goto done; |
2159 | ||
720ba808 AB |
2160 | if (hba->cnic->get_fc_npiv_tbl(hba->cnic, npiv_tbl)) |
2161 | goto done_free; | |
2162 | ||
2163 | bnx2fc_npiv_create_vports(lport, npiv_tbl); | |
2164 | done_free: | |
2165 | kfree(npiv_tbl); | |
2971ff67 | 2166 | done: |
0680810c EW |
2167 | return 0; |
2168 | } | |
2169 | ||
6e89ea3f RL |
2170 | /** |
2171 | * Deprecated: Use bnx2fc_enabled() | |
2172 | */ | |
853e2bd2 BG |
2173 | static int bnx2fc_enable(struct net_device *netdev) |
2174 | { | |
aea71a02 | 2175 | struct bnx2fc_interface *interface; |
fd8f8902 | 2176 | struct fcoe_ctlr *ctlr; |
853e2bd2 BG |
2177 | int rc = 0; |
2178 | ||
6702ca1d | 2179 | rtnl_lock(); |
853e2bd2 BG |
2180 | mutex_lock(&bnx2fc_dev_lock); |
2181 | ||
aea71a02 | 2182 | interface = bnx2fc_interface_lookup(netdev); |
fd8f8902 | 2183 | ctlr = bnx2fc_to_ctlr(interface); |
0680810c | 2184 | if (!interface) { |
853e2bd2 | 2185 | rc = -ENODEV; |
0680810c EW |
2186 | pr_err(PFX "bnx2fc_enable: interface not found\n"); |
2187 | } else { | |
2188 | rc = __bnx2fc_enable(ctlr); | |
8a5badf1 | 2189 | } |
853e2bd2 | 2190 | |
853e2bd2 BG |
2191 | mutex_unlock(&bnx2fc_dev_lock); |
2192 | rtnl_unlock(); | |
2193 | return rc; | |
2194 | } | |
2195 | ||
2196 | /** | |
6e89ea3f RL |
2197 | * bnx2fc_ctlr_enabled() - Enable or disable an FCoE Controller |
2198 | * @cdev: The FCoE Controller that is being enabled or disabled | |
853e2bd2 | 2199 | * |
6e89ea3f RL |
2200 | * fcoe_sysfs will ensure that the state of 'enabled' has |
2201 | * changed, so no checking is necessary here. This routine simply | |
2202 | * calls fcoe_enable or fcoe_disable, both of which are deprecated. | |
2203 | * When those routines are removed the functionality can be merged | |
2204 | * here. | |
2205 | */ | |
2206 | static int bnx2fc_ctlr_enabled(struct fcoe_ctlr_device *cdev) | |
2207 | { | |
2208 | struct fcoe_ctlr *ctlr = fcoe_ctlr_device_priv(cdev); | |
6e89ea3f RL |
2209 | |
2210 | switch (cdev->enabled) { | |
2211 | case FCOE_CTLR_ENABLED: | |
0680810c | 2212 | return __bnx2fc_enable(ctlr); |
6e89ea3f | 2213 | case FCOE_CTLR_DISABLED: |
0680810c | 2214 | return __bnx2fc_disable(ctlr); |
6e89ea3f RL |
2215 | case FCOE_CTLR_UNUSED: |
2216 | default: | |
2217 | return -ENOTSUPP; | |
2218 | }; | |
2219 | } | |
2220 | ||
2221 | enum bnx2fc_create_link_state { | |
2222 | BNX2FC_CREATE_LINK_DOWN, | |
2223 | BNX2FC_CREATE_LINK_UP, | |
2224 | }; | |
2225 | ||
2226 | /** | |
2227 | * _bnx2fc_create() - Create bnx2fc FCoE interface | |
2228 | * @netdev : The net_device object the Ethernet interface to create on | |
2229 | * @fip_mode: The FIP mode for this creation | |
2230 | * @link_state: The ctlr link state on creation | |
853e2bd2 | 2231 | * |
6e89ea3f RL |
2232 | * Called from either the libfcoe 'create' module parameter |
2233 | * via fcoe_create or from fcoe_syfs's ctlr_create file. | |
853e2bd2 | 2234 | * |
6e89ea3f RL |
2235 | * libfcoe's 'create' module parameter is deprecated so some |
2236 | * consolidation of code can be done when that interface is | |
2237 | * removed. | |
853e2bd2 BG |
2238 | * |
2239 | * Returns: 0 for success | |
2240 | */ | |
6e89ea3f RL |
2241 | static int _bnx2fc_create(struct net_device *netdev, |
2242 | enum fip_state fip_mode, | |
2243 | enum bnx2fc_create_link_state link_state) | |
853e2bd2 | 2244 | { |
6e89ea3f | 2245 | struct fcoe_ctlr_device *cdev; |
fd8f8902 | 2246 | struct fcoe_ctlr *ctlr; |
aea71a02 | 2247 | struct bnx2fc_interface *interface; |
853e2bd2 | 2248 | struct bnx2fc_hba *hba; |
7adc5a37 | 2249 | struct net_device *phys_dev = netdev; |
853e2bd2 BG |
2250 | struct fc_lport *lport; |
2251 | struct ethtool_drvinfo drvinfo; | |
2252 | int rc = 0; | |
7adc5a37 | 2253 | int vlan_id = 0; |
853e2bd2 BG |
2254 | |
2255 | BNX2FC_MISC_DBG("Entered bnx2fc_create\n"); | |
2256 | if (fip_mode != FIP_MODE_FABRIC) { | |
2257 | printk(KERN_ERR "fip mode not FABRIC\n"); | |
2258 | return -EIO; | |
2259 | } | |
2260 | ||
6702ca1d NS |
2261 | rtnl_lock(); |
2262 | ||
853e2bd2 BG |
2263 | mutex_lock(&bnx2fc_dev_lock); |
2264 | ||
853e2bd2 BG |
2265 | if (!try_module_get(THIS_MODULE)) { |
2266 | rc = -EINVAL; | |
2267 | goto mod_err; | |
2268 | } | |
2269 | ||
2270 | /* obtain physical netdev */ | |
7adc5a37 | 2271 | if (netdev->priv_flags & IFF_802_1Q_VLAN) |
853e2bd2 | 2272 | phys_dev = vlan_dev_real_dev(netdev); |
7adc5a37 | 2273 | |
853e2bd2 BG |
2274 | /* verify if the physical device is a netxtreme2 device */ |
2275 | if (phys_dev->ethtool_ops && phys_dev->ethtool_ops->get_drvinfo) { | |
2276 | memset(&drvinfo, 0, sizeof(drvinfo)); | |
2277 | phys_dev->ethtool_ops->get_drvinfo(phys_dev, &drvinfo); | |
aea71a02 | 2278 | if (strncmp(drvinfo.driver, "bnx2x", strlen("bnx2x"))) { |
853e2bd2 BG |
2279 | printk(KERN_ERR PFX "Not a netxtreme2 device\n"); |
2280 | rc = -EINVAL; | |
2281 | goto netdev_err; | |
2282 | } | |
2283 | } else { | |
2284 | printk(KERN_ERR PFX "unable to obtain drv_info\n"); | |
2285 | rc = -EINVAL; | |
2286 | goto netdev_err; | |
2287 | } | |
2288 | ||
aea71a02 | 2289 | /* obtain interface and initialize rest of the structure */ |
853e2bd2 BG |
2290 | hba = bnx2fc_hba_lookup(phys_dev); |
2291 | if (!hba) { | |
2292 | rc = -ENODEV; | |
2293 | printk(KERN_ERR PFX "bnx2fc_create: hba not found\n"); | |
2294 | goto netdev_err; | |
2295 | } | |
2296 | ||
aea71a02 | 2297 | if (bnx2fc_interface_lookup(netdev)) { |
853e2bd2 BG |
2298 | rc = -EEXIST; |
2299 | goto netdev_err; | |
2300 | } | |
2301 | ||
aea71a02 BPG |
2302 | interface = bnx2fc_interface_create(hba, netdev, fip_mode); |
2303 | if (!interface) { | |
2304 | printk(KERN_ERR PFX "bnx2fc_interface_create failed\n"); | |
2043e1fd | 2305 | rc = -ENOMEM; |
853e2bd2 BG |
2306 | goto ifput_err; |
2307 | } | |
2308 | ||
7adc5a37 BPG |
2309 | if (netdev->priv_flags & IFF_802_1Q_VLAN) { |
2310 | vlan_id = vlan_dev_vlan_id(netdev); | |
2311 | interface->vlan_enabled = 1; | |
2312 | } | |
2313 | ||
fd8f8902 | 2314 | ctlr = bnx2fc_to_ctlr(interface); |
01bdcb62 | 2315 | cdev = fcoe_ctlr_to_ctlr_dev(ctlr); |
aea71a02 | 2316 | interface->vlan_id = vlan_id; |
10755d3f | 2317 | interface->tm_timeout = BNX2FC_TM_TIMEOUT; |
aea71a02 BPG |
2318 | |
2319 | interface->timer_work_queue = | |
853e2bd2 | 2320 | create_singlethread_workqueue("bnx2fc_timer_wq"); |
aea71a02 | 2321 | if (!interface->timer_work_queue) { |
853e2bd2 BG |
2322 | printk(KERN_ERR PFX "ulp_init could not create timer_wq\n"); |
2323 | rc = -EINVAL; | |
2324 | goto ifput_err; | |
2325 | } | |
2326 | ||
01bdcb62 | 2327 | lport = bnx2fc_if_create(interface, &cdev->dev, 0); |
853e2bd2 BG |
2328 | if (!lport) { |
2329 | printk(KERN_ERR PFX "Failed to create interface (%s)\n", | |
2330 | netdev->name); | |
853e2bd2 BG |
2331 | rc = -EINVAL; |
2332 | goto if_create_err; | |
2333 | } | |
2334 | ||
aea71a02 BPG |
2335 | /* Add interface to if_list */ |
2336 | list_add_tail(&interface->list, &if_list); | |
2337 | ||
853e2bd2 BG |
2338 | lport->boot_time = jiffies; |
2339 | ||
2340 | /* Make this master N_port */ | |
fd8f8902 | 2341 | ctlr->lp = lport; |
853e2bd2 | 2342 | |
6e89ea3f RL |
2343 | if (link_state == BNX2FC_CREATE_LINK_UP) |
2344 | cdev->enabled = FCOE_CTLR_ENABLED; | |
2345 | else | |
2346 | cdev->enabled = FCOE_CTLR_DISABLED; | |
2347 | ||
2348 | if (link_state == BNX2FC_CREATE_LINK_UP && | |
2349 | !bnx2fc_link_ok(lport)) { | |
fd8f8902 | 2350 | fcoe_ctlr_link_up(ctlr); |
8a5badf1 BPG |
2351 | fc_host_port_type(lport->host) = FC_PORTTYPE_NPORT; |
2352 | set_bit(ADAPTER_STATE_READY, &interface->hba->adapter_state); | |
2353 | } | |
2354 | ||
aea71a02 BPG |
2355 | BNX2FC_HBA_DBG(lport, "create: START DISC\n"); |
2356 | bnx2fc_start_disc(interface); | |
6e89ea3f RL |
2357 | |
2358 | if (link_state == BNX2FC_CREATE_LINK_UP) | |
2359 | interface->enabled = true; | |
2360 | ||
853e2bd2 BG |
2361 | /* |
2362 | * Release from kref_init in bnx2fc_interface_setup, on success | |
2363 | * lport should be holding a reference taken in bnx2fc_if_create | |
2364 | */ | |
aea71a02 | 2365 | bnx2fc_interface_put(interface); |
853e2bd2 BG |
2366 | /* put netdev that was held while calling dev_get_by_name */ |
2367 | mutex_unlock(&bnx2fc_dev_lock); | |
2368 | rtnl_unlock(); | |
2369 | return 0; | |
2370 | ||
2371 | if_create_err: | |
aea71a02 | 2372 | destroy_workqueue(interface->timer_work_queue); |
853e2bd2 | 2373 | ifput_err: |
013068fa | 2374 | bnx2fc_net_cleanup(interface); |
aea71a02 | 2375 | bnx2fc_interface_put(interface); |
7d742f65 | 2376 | goto mod_err; |
853e2bd2 BG |
2377 | netdev_err: |
2378 | module_put(THIS_MODULE); | |
2379 | mod_err: | |
2380 | mutex_unlock(&bnx2fc_dev_lock); | |
2381 | rtnl_unlock(); | |
2382 | return rc; | |
2383 | } | |
2384 | ||
6e89ea3f RL |
2385 | /** |
2386 | * bnx2fc_create() - Create a bnx2fc interface | |
2387 | * @netdev : The net_device object the Ethernet interface to create on | |
2388 | * @fip_mode: The FIP mode for this creation | |
2389 | * | |
2390 | * Called from fcoe transport | |
2391 | * | |
2392 | * Returns: 0 for success | |
2393 | */ | |
2394 | static int bnx2fc_create(struct net_device *netdev, enum fip_state fip_mode) | |
2395 | { | |
2396 | return _bnx2fc_create(netdev, fip_mode, BNX2FC_CREATE_LINK_UP); | |
2397 | } | |
2398 | ||
2399 | /** | |
2400 | * bnx2fc_ctlr_alloc() - Allocate a bnx2fc interface from fcoe_sysfs | |
2401 | * @netdev: The net_device to be used by the allocated FCoE Controller | |
2402 | * | |
2403 | * This routine is called from fcoe_sysfs. It will start the fcoe_ctlr | |
2404 | * in a link_down state. The allows the user an opportunity to configure | |
2405 | * the FCoE Controller from sysfs before enabling the FCoE Controller. | |
2406 | * | |
2407 | * Creating in with this routine starts the FCoE Controller in Fabric | |
2408 | * mode. The user can change to VN2VN or another mode before enabling. | |
2409 | */ | |
2410 | static int bnx2fc_ctlr_alloc(struct net_device *netdev) | |
2411 | { | |
2412 | return _bnx2fc_create(netdev, FIP_MODE_FABRIC, | |
2413 | BNX2FC_CREATE_LINK_DOWN); | |
2414 | } | |
2415 | ||
853e2bd2 | 2416 | /** |
aea71a02 | 2417 | * bnx2fc_find_hba_for_cnic - maps cnic instance to bnx2fc hba instance |
853e2bd2 BG |
2418 | * |
2419 | * @cnic: Pointer to cnic device instance | |
2420 | * | |
2421 | **/ | |
2422 | static struct bnx2fc_hba *bnx2fc_find_hba_for_cnic(struct cnic_dev *cnic) | |
2423 | { | |
853e2bd2 BG |
2424 | struct bnx2fc_hba *hba; |
2425 | ||
2426 | /* Called with bnx2fc_dev_lock held */ | |
d71fb3bd | 2427 | list_for_each_entry(hba, &adapter_list, list) { |
853e2bd2 BG |
2428 | if (hba->cnic == cnic) |
2429 | return hba; | |
2430 | } | |
2431 | return NULL; | |
2432 | } | |
2433 | ||
aea71a02 BPG |
2434 | static struct bnx2fc_interface *bnx2fc_interface_lookup(struct net_device |
2435 | *netdev) | |
2436 | { | |
2437 | struct bnx2fc_interface *interface; | |
2438 | ||
2439 | /* Called with bnx2fc_dev_lock held */ | |
2440 | list_for_each_entry(interface, &if_list, list) { | |
2441 | if (interface->netdev == netdev) | |
2442 | return interface; | |
2443 | } | |
2444 | return NULL; | |
2445 | } | |
2446 | ||
2447 | static struct bnx2fc_hba *bnx2fc_hba_lookup(struct net_device | |
2448 | *phys_dev) | |
853e2bd2 | 2449 | { |
853e2bd2 BG |
2450 | struct bnx2fc_hba *hba; |
2451 | ||
2452 | /* Called with bnx2fc_dev_lock held */ | |
aea71a02 | 2453 | list_for_each_entry(hba, &adapter_list, list) { |
853e2bd2 BG |
2454 | if (hba->phys_dev == phys_dev) |
2455 | return hba; | |
2456 | } | |
aea71a02 | 2457 | printk(KERN_ERR PFX "adapter_lookup: hba NULL\n"); |
853e2bd2 BG |
2458 | return NULL; |
2459 | } | |
2460 | ||
2461 | /** | |
2462 | * bnx2fc_ulp_exit - shuts down adapter instance and frees all resources | |
2463 | * | |
2464 | * @dev cnic device handle | |
2465 | */ | |
2466 | static void bnx2fc_ulp_exit(struct cnic_dev *dev) | |
2467 | { | |
2468 | struct bnx2fc_hba *hba; | |
aea71a02 | 2469 | struct bnx2fc_interface *interface, *tmp; |
853e2bd2 BG |
2470 | |
2471 | BNX2FC_MISC_DBG("Entered bnx2fc_ulp_exit\n"); | |
2472 | ||
2473 | if (!test_bit(CNIC_F_BNX2X_CLASS, &dev->flags)) { | |
2474 | printk(KERN_ERR PFX "bnx2fc port check: %s, flags: %lx\n", | |
2475 | dev->netdev->name, dev->flags); | |
2476 | return; | |
2477 | } | |
2478 | ||
2479 | mutex_lock(&bnx2fc_dev_lock); | |
2480 | hba = bnx2fc_find_hba_for_cnic(dev); | |
2481 | if (!hba) { | |
2482 | printk(KERN_ERR PFX "bnx2fc_ulp_exit: hba not found, dev 0%p\n", | |
2483 | dev); | |
2484 | mutex_unlock(&bnx2fc_dev_lock); | |
2485 | return; | |
2486 | } | |
2487 | ||
aea71a02 | 2488 | list_del_init(&hba->list); |
853e2bd2 BG |
2489 | adapter_count--; |
2490 | ||
abc49a93 | 2491 | list_for_each_entry_safe(interface, tmp, &if_list, list) |
853e2bd2 | 2492 | /* destroy not called yet, move to quiesced list */ |
abc49a93 | 2493 | if (interface->hba == hba) |
eccdcd02 | 2494 | __bnx2fc_destroy(interface); |
853e2bd2 BG |
2495 | mutex_unlock(&bnx2fc_dev_lock); |
2496 | ||
06c4f20d EW |
2497 | /* Ensure ALL destroy work has been completed before return */ |
2498 | flush_workqueue(bnx2fc_wq); | |
2499 | ||
853e2bd2 BG |
2500 | bnx2fc_ulp_stop(hba); |
2501 | /* unregister cnic device */ | |
2502 | if (test_and_clear_bit(BNX2FC_CNIC_REGISTERED, &hba->reg_with_cnic)) | |
2503 | hba->cnic->unregister_device(hba->cnic, CNIC_ULP_FCOE); | |
aea71a02 | 2504 | bnx2fc_hba_destroy(hba); |
853e2bd2 BG |
2505 | } |
2506 | ||
2507 | /** | |
2508 | * bnx2fc_fcoe_reset - Resets the fcoe | |
2509 | * | |
2510 | * @shost: shost the reset is from | |
2511 | * | |
2512 | * Returns: always 0 | |
2513 | */ | |
2514 | static int bnx2fc_fcoe_reset(struct Scsi_Host *shost) | |
2515 | { | |
2516 | struct fc_lport *lport = shost_priv(shost); | |
2517 | fc_lport_reset(lport); | |
2518 | return 0; | |
2519 | } | |
2520 | ||
2521 | ||
2522 | static bool bnx2fc_match(struct net_device *netdev) | |
2523 | { | |
7adc5a37 BPG |
2524 | struct net_device *phys_dev = netdev; |
2525 | ||
853e2bd2 | 2526 | mutex_lock(&bnx2fc_dev_lock); |
7adc5a37 BPG |
2527 | if (netdev->priv_flags & IFF_802_1Q_VLAN) |
2528 | phys_dev = vlan_dev_real_dev(netdev); | |
853e2bd2 | 2529 | |
7adc5a37 BPG |
2530 | if (bnx2fc_hba_lookup(phys_dev)) { |
2531 | mutex_unlock(&bnx2fc_dev_lock); | |
2532 | return true; | |
853e2bd2 | 2533 | } |
7adc5a37 | 2534 | |
853e2bd2 BG |
2535 | mutex_unlock(&bnx2fc_dev_lock); |
2536 | return false; | |
2537 | } | |
2538 | ||
2539 | ||
2540 | static struct fcoe_transport bnx2fc_transport = { | |
2541 | .name = {"bnx2fc"}, | |
2542 | .attached = false, | |
2543 | .list = LIST_HEAD_INIT(bnx2fc_transport.list), | |
6e89ea3f | 2544 | .alloc = bnx2fc_ctlr_alloc, |
853e2bd2 BG |
2545 | .match = bnx2fc_match, |
2546 | .create = bnx2fc_create, | |
2547 | .destroy = bnx2fc_destroy, | |
2548 | .enable = bnx2fc_enable, | |
2549 | .disable = bnx2fc_disable, | |
2550 | }; | |
2551 | ||
2552 | /** | |
2553 | * bnx2fc_percpu_thread_create - Create a receive thread for an | |
2554 | * online CPU | |
2555 | * | |
2556 | * @cpu: cpu index for the online cpu | |
2557 | */ | |
2558 | static void bnx2fc_percpu_thread_create(unsigned int cpu) | |
2559 | { | |
2560 | struct bnx2fc_percpu_s *p; | |
2561 | struct task_struct *thread; | |
2562 | ||
2563 | p = &per_cpu(bnx2fc_percpu, cpu); | |
2564 | ||
69614270 ED |
2565 | thread = kthread_create_on_node(bnx2fc_percpu_io_thread, |
2566 | (void *)p, cpu_to_node(cpu), | |
2567 | "bnx2fc_thread/%d", cpu); | |
853e2bd2 | 2568 | /* bind thread to the cpu */ |
32248763 | 2569 | if (likely(!IS_ERR(thread))) { |
853e2bd2 BG |
2570 | kthread_bind(thread, cpu); |
2571 | p->iothread = thread; | |
2572 | wake_up_process(thread); | |
2573 | } | |
2574 | } | |
2575 | ||
2576 | static void bnx2fc_percpu_thread_destroy(unsigned int cpu) | |
2577 | { | |
2578 | struct bnx2fc_percpu_s *p; | |
2579 | struct task_struct *thread; | |
2580 | struct bnx2fc_work *work, *tmp; | |
853e2bd2 BG |
2581 | |
2582 | BNX2FC_MISC_DBG("destroying io thread for CPU %d\n", cpu); | |
2583 | ||
2584 | /* Prevent any new work from being queued for this CPU */ | |
2585 | p = &per_cpu(bnx2fc_percpu, cpu); | |
2586 | spin_lock_bh(&p->fp_work_lock); | |
2587 | thread = p->iothread; | |
2588 | p->iothread = NULL; | |
2589 | ||
2590 | ||
2591 | /* Free all work in the list */ | |
32248763 | 2592 | list_for_each_entry_safe(work, tmp, &p->work_list, list) { |
853e2bd2 BG |
2593 | list_del_init(&work->list); |
2594 | bnx2fc_process_cq_compl(work->tgt, work->wqe); | |
2595 | kfree(work); | |
2596 | } | |
2597 | ||
2598 | spin_unlock_bh(&p->fp_work_lock); | |
2599 | ||
2600 | if (thread) | |
2601 | kthread_stop(thread); | |
2602 | } | |
2603 | ||
2604 | /** | |
2605 | * bnx2fc_cpu_callback - Handler for CPU hotplug events | |
2606 | * | |
2607 | * @nfb: The callback data block | |
2608 | * @action: The event triggering the callback | |
2609 | * @hcpu: The index of the CPU that the event is for | |
2610 | * | |
2611 | * This creates or destroys per-CPU data for fcoe | |
2612 | * | |
2613 | * Returns NOTIFY_OK always. | |
2614 | */ | |
2615 | static int bnx2fc_cpu_callback(struct notifier_block *nfb, | |
2616 | unsigned long action, void *hcpu) | |
2617 | { | |
2618 | unsigned cpu = (unsigned long)hcpu; | |
2619 | ||
2620 | switch (action) { | |
2621 | case CPU_ONLINE: | |
2622 | case CPU_ONLINE_FROZEN: | |
2623 | printk(PFX "CPU %x online: Create Rx thread\n", cpu); | |
2624 | bnx2fc_percpu_thread_create(cpu); | |
2625 | break; | |
2626 | case CPU_DEAD: | |
2627 | case CPU_DEAD_FROZEN: | |
2628 | printk(PFX "CPU %x offline: Remove Rx thread\n", cpu); | |
2629 | bnx2fc_percpu_thread_destroy(cpu); | |
2630 | break; | |
2631 | default: | |
2632 | break; | |
2633 | } | |
2634 | return NOTIFY_OK; | |
2635 | } | |
2636 | ||
10755d3f JC |
2637 | static int bnx2fc_slave_configure(struct scsi_device *sdev) |
2638 | { | |
2639 | if (!bnx2fc_queue_depth) | |
2640 | return 0; | |
2641 | ||
2642 | scsi_change_queue_depth(sdev, bnx2fc_queue_depth); | |
2643 | return 0; | |
2644 | } | |
2645 | ||
853e2bd2 BG |
2646 | /** |
2647 | * bnx2fc_mod_init - module init entry point | |
2648 | * | |
2649 | * Initialize driver wide global data structures, and register | |
2650 | * with cnic module | |
2651 | **/ | |
2652 | static int __init bnx2fc_mod_init(void) | |
2653 | { | |
2654 | struct fcoe_percpu_s *bg; | |
2655 | struct task_struct *l2_thread; | |
2656 | int rc = 0; | |
2657 | unsigned int cpu = 0; | |
2658 | struct bnx2fc_percpu_s *p; | |
2659 | ||
2660 | printk(KERN_INFO PFX "%s", version); | |
2661 | ||
2662 | /* register as a fcoe transport */ | |
2663 | rc = fcoe_transport_attach(&bnx2fc_transport); | |
2664 | if (rc) { | |
2665 | printk(KERN_ERR "failed to register an fcoe transport, check " | |
2666 | "if libfcoe is loaded\n"); | |
2667 | goto out; | |
2668 | } | |
2669 | ||
2670 | INIT_LIST_HEAD(&adapter_list); | |
aea71a02 | 2671 | INIT_LIST_HEAD(&if_list); |
853e2bd2 BG |
2672 | mutex_init(&bnx2fc_dev_lock); |
2673 | adapter_count = 0; | |
2674 | ||
2675 | /* Attach FC transport template */ | |
2676 | rc = bnx2fc_attach_transport(); | |
2677 | if (rc) | |
2678 | goto detach_ft; | |
2679 | ||
2680 | bnx2fc_wq = alloc_workqueue("bnx2fc", 0, 0); | |
2681 | if (!bnx2fc_wq) { | |
2682 | rc = -ENOMEM; | |
2683 | goto release_bt; | |
2684 | } | |
2685 | ||
2686 | bg = &bnx2fc_global; | |
2687 | skb_queue_head_init(&bg->fcoe_rx_list); | |
2688 | l2_thread = kthread_create(bnx2fc_l2_rcv_thread, | |
2689 | (void *)bg, | |
2690 | "bnx2fc_l2_thread"); | |
2691 | if (IS_ERR(l2_thread)) { | |
2692 | rc = PTR_ERR(l2_thread); | |
2693 | goto free_wq; | |
2694 | } | |
2695 | wake_up_process(l2_thread); | |
2696 | spin_lock_bh(&bg->fcoe_rx_list.lock); | |
2697 | bg->thread = l2_thread; | |
2698 | spin_unlock_bh(&bg->fcoe_rx_list.lock); | |
2699 | ||
2700 | for_each_possible_cpu(cpu) { | |
2701 | p = &per_cpu(bnx2fc_percpu, cpu); | |
2702 | INIT_LIST_HEAD(&p->work_list); | |
2703 | spin_lock_init(&p->fp_work_lock); | |
2704 | } | |
2705 | ||
7229b6d0 SB |
2706 | cpu_notifier_register_begin(); |
2707 | ||
853e2bd2 BG |
2708 | for_each_online_cpu(cpu) { |
2709 | bnx2fc_percpu_thread_create(cpu); | |
2710 | } | |
2711 | ||
2712 | /* Initialize per CPU interrupt thread */ | |
7229b6d0 SB |
2713 | __register_hotcpu_notifier(&bnx2fc_cpu_notifier); |
2714 | ||
2715 | cpu_notifier_register_done(); | |
853e2bd2 BG |
2716 | |
2717 | cnic_register_driver(CNIC_ULP_FCOE, &bnx2fc_cnic_cb); | |
2718 | ||
2719 | return 0; | |
2720 | ||
2721 | free_wq: | |
2722 | destroy_workqueue(bnx2fc_wq); | |
2723 | release_bt: | |
2724 | bnx2fc_release_transport(); | |
2725 | detach_ft: | |
2726 | fcoe_transport_detach(&bnx2fc_transport); | |
2727 | out: | |
2728 | return rc; | |
2729 | } | |
2730 | ||
2731 | static void __exit bnx2fc_mod_exit(void) | |
2732 | { | |
2733 | LIST_HEAD(to_be_deleted); | |
2734 | struct bnx2fc_hba *hba, *next; | |
2735 | struct fcoe_percpu_s *bg; | |
2736 | struct task_struct *l2_thread; | |
2737 | struct sk_buff *skb; | |
2738 | unsigned int cpu = 0; | |
2739 | ||
2740 | /* | |
2741 | * NOTE: Since cnic calls register_driver routine rtnl_lock, | |
2742 | * it will have higher precedence than bnx2fc_dev_lock. | |
2743 | * unregister_device() cannot be called with bnx2fc_dev_lock | |
2744 | * held. | |
2745 | */ | |
2746 | mutex_lock(&bnx2fc_dev_lock); | |
2747 | list_splice(&adapter_list, &to_be_deleted); | |
2748 | INIT_LIST_HEAD(&adapter_list); | |
2749 | adapter_count = 0; | |
2750 | mutex_unlock(&bnx2fc_dev_lock); | |
2751 | ||
2752 | /* Unregister with cnic */ | |
aea71a02 BPG |
2753 | list_for_each_entry_safe(hba, next, &to_be_deleted, list) { |
2754 | list_del_init(&hba->list); | |
2755 | printk(KERN_ERR PFX "MOD_EXIT:destroy hba = 0x%p\n", | |
2756 | hba); | |
853e2bd2 BG |
2757 | bnx2fc_ulp_stop(hba); |
2758 | /* unregister cnic device */ | |
2759 | if (test_and_clear_bit(BNX2FC_CNIC_REGISTERED, | |
2760 | &hba->reg_with_cnic)) | |
aea71a02 BPG |
2761 | hba->cnic->unregister_device(hba->cnic, |
2762 | CNIC_ULP_FCOE); | |
2763 | bnx2fc_hba_destroy(hba); | |
853e2bd2 BG |
2764 | } |
2765 | cnic_unregister_driver(CNIC_ULP_FCOE); | |
2766 | ||
2767 | /* Destroy global thread */ | |
2768 | bg = &bnx2fc_global; | |
2769 | spin_lock_bh(&bg->fcoe_rx_list.lock); | |
2770 | l2_thread = bg->thread; | |
2771 | bg->thread = NULL; | |
2772 | while ((skb = __skb_dequeue(&bg->fcoe_rx_list)) != NULL) | |
2773 | kfree_skb(skb); | |
2774 | ||
2775 | spin_unlock_bh(&bg->fcoe_rx_list.lock); | |
2776 | ||
2777 | if (l2_thread) | |
2778 | kthread_stop(l2_thread); | |
2779 | ||
7229b6d0 | 2780 | cpu_notifier_register_begin(); |
853e2bd2 BG |
2781 | |
2782 | /* Destroy per cpu threads */ | |
2783 | for_each_online_cpu(cpu) { | |
2784 | bnx2fc_percpu_thread_destroy(cpu); | |
2785 | } | |
2786 | ||
7229b6d0 SB |
2787 | __unregister_hotcpu_notifier(&bnx2fc_cpu_notifier); |
2788 | ||
2789 | cpu_notifier_register_done(); | |
2790 | ||
853e2bd2 BG |
2791 | destroy_workqueue(bnx2fc_wq); |
2792 | /* | |
2793 | * detach from scsi transport | |
2794 | * must happen after all destroys are done | |
2795 | */ | |
2796 | bnx2fc_release_transport(); | |
2797 | ||
2798 | /* detach from fcoe transport */ | |
2799 | fcoe_transport_detach(&bnx2fc_transport); | |
2800 | } | |
2801 | ||
2802 | module_init(bnx2fc_mod_init); | |
2803 | module_exit(bnx2fc_mod_exit); | |
2804 | ||
8d55e507 | 2805 | static struct fcoe_sysfs_function_template bnx2fc_fcoe_sysfs_templ = { |
6e89ea3f | 2806 | .set_fcoe_ctlr_enabled = bnx2fc_ctlr_enabled, |
b8b3e697 YZ |
2807 | .get_fcoe_ctlr_link_fail = fcoe_ctlr_get_lesb, |
2808 | .get_fcoe_ctlr_vlink_fail = fcoe_ctlr_get_lesb, | |
2809 | .get_fcoe_ctlr_miss_fka = fcoe_ctlr_get_lesb, | |
2810 | .get_fcoe_ctlr_symb_err = fcoe_ctlr_get_lesb, | |
2811 | .get_fcoe_ctlr_err_block = fcoe_ctlr_get_lesb, | |
2812 | .get_fcoe_ctlr_fcs_error = fcoe_ctlr_get_lesb, | |
8d55e507 RL |
2813 | |
2814 | .get_fcoe_fcf_selected = fcoe_fcf_get_selected, | |
2815 | .get_fcoe_fcf_vlan_id = bnx2fc_fcf_get_vlan_id, | |
2816 | }; | |
2817 | ||
853e2bd2 BG |
2818 | static struct fc_function_template bnx2fc_transport_function = { |
2819 | .show_host_node_name = 1, | |
2820 | .show_host_port_name = 1, | |
2821 | .show_host_supported_classes = 1, | |
2822 | .show_host_supported_fc4s = 1, | |
2823 | .show_host_active_fc4s = 1, | |
2824 | .show_host_maxframe_size = 1, | |
2825 | ||
2826 | .show_host_port_id = 1, | |
2827 | .show_host_supported_speeds = 1, | |
2828 | .get_host_speed = fc_get_host_speed, | |
2829 | .show_host_speed = 1, | |
2830 | .show_host_port_type = 1, | |
2831 | .get_host_port_state = fc_get_host_port_state, | |
2832 | .show_host_port_state = 1, | |
2833 | .show_host_symbolic_name = 1, | |
2834 | ||
2835 | .dd_fcrport_size = (sizeof(struct fc_rport_libfc_priv) + | |
2836 | sizeof(struct bnx2fc_rport)), | |
2837 | .show_rport_maxframe_size = 1, | |
2838 | .show_rport_supported_classes = 1, | |
2839 | ||
2840 | .show_host_fabric_name = 1, | |
2841 | .show_starget_node_name = 1, | |
2842 | .show_starget_port_name = 1, | |
2843 | .show_starget_port_id = 1, | |
2844 | .set_rport_dev_loss_tmo = fc_set_rport_loss_tmo, | |
2845 | .show_rport_dev_loss_tmo = 1, | |
2846 | .get_fc_host_stats = bnx2fc_get_host_stats, | |
2847 | ||
2848 | .issue_fc_host_lip = bnx2fc_fcoe_reset, | |
2849 | ||
2850 | .terminate_rport_io = fc_rport_terminate_io, | |
2851 | ||
2852 | .vport_create = bnx2fc_vport_create, | |
2853 | .vport_delete = bnx2fc_vport_destroy, | |
2854 | .vport_disable = bnx2fc_vport_disable, | |
e9a5289c | 2855 | .bsg_request = fc_lport_bsg_request, |
853e2bd2 BG |
2856 | }; |
2857 | ||
2858 | static struct fc_function_template bnx2fc_vport_xport_function = { | |
2859 | .show_host_node_name = 1, | |
2860 | .show_host_port_name = 1, | |
2861 | .show_host_supported_classes = 1, | |
2862 | .show_host_supported_fc4s = 1, | |
2863 | .show_host_active_fc4s = 1, | |
2864 | .show_host_maxframe_size = 1, | |
2865 | ||
2866 | .show_host_port_id = 1, | |
2867 | .show_host_supported_speeds = 1, | |
2868 | .get_host_speed = fc_get_host_speed, | |
2869 | .show_host_speed = 1, | |
2870 | .show_host_port_type = 1, | |
2871 | .get_host_port_state = fc_get_host_port_state, | |
2872 | .show_host_port_state = 1, | |
2873 | .show_host_symbolic_name = 1, | |
2874 | ||
2875 | .dd_fcrport_size = (sizeof(struct fc_rport_libfc_priv) + | |
2876 | sizeof(struct bnx2fc_rport)), | |
2877 | .show_rport_maxframe_size = 1, | |
2878 | .show_rport_supported_classes = 1, | |
2879 | ||
2880 | .show_host_fabric_name = 1, | |
2881 | .show_starget_node_name = 1, | |
2882 | .show_starget_port_name = 1, | |
2883 | .show_starget_port_id = 1, | |
2884 | .set_rport_dev_loss_tmo = fc_set_rport_loss_tmo, | |
2885 | .show_rport_dev_loss_tmo = 1, | |
2886 | .get_fc_host_stats = fc_get_host_stats, | |
2887 | .issue_fc_host_lip = bnx2fc_fcoe_reset, | |
2888 | .terminate_rport_io = fc_rport_terminate_io, | |
e9a5289c | 2889 | .bsg_request = fc_lport_bsg_request, |
853e2bd2 BG |
2890 | }; |
2891 | ||
10755d3f JC |
2892 | /* |
2893 | * Additional scsi_host attributes. | |
2894 | */ | |
2895 | static ssize_t | |
2896 | bnx2fc_tm_timeout_show(struct device *dev, struct device_attribute *attr, | |
2897 | char *buf) | |
2898 | { | |
2899 | struct Scsi_Host *shost = class_to_shost(dev); | |
2900 | struct fc_lport *lport = shost_priv(shost); | |
2901 | struct fcoe_port *port = lport_priv(lport); | |
2902 | struct bnx2fc_interface *interface = port->priv; | |
2903 | ||
2904 | sprintf(buf, "%u\n", interface->tm_timeout); | |
2905 | return strlen(buf); | |
2906 | } | |
2907 | ||
2908 | static ssize_t | |
2909 | bnx2fc_tm_timeout_store(struct device *dev, | |
2910 | struct device_attribute *attr, const char *buf, size_t count) | |
2911 | { | |
2912 | struct Scsi_Host *shost = class_to_shost(dev); | |
2913 | struct fc_lport *lport = shost_priv(shost); | |
2914 | struct fcoe_port *port = lport_priv(lport); | |
2915 | struct bnx2fc_interface *interface = port->priv; | |
2916 | int rval, val; | |
2917 | ||
2918 | rval = kstrtouint(buf, 10, &val); | |
2919 | if (rval) | |
2920 | return rval; | |
2921 | if (val > 255) | |
2922 | return -ERANGE; | |
2923 | ||
2924 | interface->tm_timeout = (u8)val; | |
2925 | return strlen(buf); | |
2926 | } | |
2927 | ||
2928 | static DEVICE_ATTR(tm_timeout, S_IRUGO|S_IWUSR, bnx2fc_tm_timeout_show, | |
2929 | bnx2fc_tm_timeout_store); | |
2930 | ||
2931 | static struct device_attribute *bnx2fc_host_attrs[] = { | |
2932 | &dev_attr_tm_timeout, | |
2933 | NULL, | |
2934 | }; | |
2935 | ||
853e2bd2 BG |
2936 | /** |
2937 | * scsi_host_template structure used while registering with SCSI-ml | |
2938 | */ | |
2939 | static struct scsi_host_template bnx2fc_shost_template = { | |
2940 | .module = THIS_MODULE, | |
17d87c45 | 2941 | .name = "QLogic Offload FCoE Initiator", |
853e2bd2 BG |
2942 | .queuecommand = bnx2fc_queuecommand, |
2943 | .eh_abort_handler = bnx2fc_eh_abort, /* abts */ | |
2944 | .eh_device_reset_handler = bnx2fc_eh_device_reset, /* lun reset */ | |
2945 | .eh_target_reset_handler = bnx2fc_eh_target_reset, /* tgt reset */ | |
2946 | .eh_host_reset_handler = fc_eh_host_reset, | |
2947 | .slave_alloc = fc_slave_alloc, | |
db5ed4df | 2948 | .change_queue_depth = scsi_change_queue_depth, |
853e2bd2 BG |
2949 | .this_id = -1, |
2950 | .cmd_per_lun = 3, | |
853e2bd2 BG |
2951 | .use_clustering = ENABLE_CLUSTERING, |
2952 | .sg_tablesize = BNX2FC_MAX_BDS_PER_CMD, | |
d450d778 | 2953 | .max_sectors = 1024, |
c40ecc12 | 2954 | .track_queue_depth = 1, |
10755d3f JC |
2955 | .slave_configure = bnx2fc_slave_configure, |
2956 | .shost_attrs = bnx2fc_host_attrs, | |
853e2bd2 BG |
2957 | }; |
2958 | ||
2959 | static struct libfc_function_template bnx2fc_libfc_fcn_templ = { | |
2960 | .frame_send = bnx2fc_xmit, | |
2961 | .elsct_send = bnx2fc_elsct_send, | |
2962 | .fcp_abort_io = bnx2fc_abort_io, | |
2963 | .fcp_cleanup = bnx2fc_cleanup, | |
b8b3e697 | 2964 | .get_lesb = fcoe_get_lesb, |
853e2bd2 BG |
2965 | .rport_event_callback = bnx2fc_rport_event_handler, |
2966 | }; | |
2967 | ||
2968 | /** | |
2969 | * bnx2fc_cnic_cb - global template of bnx2fc - cnic driver interface | |
2970 | * structure carrying callback function pointers | |
2971 | */ | |
2972 | static struct cnic_ulp_ops bnx2fc_cnic_cb = { | |
2973 | .owner = THIS_MODULE, | |
2974 | .cnic_init = bnx2fc_ulp_init, | |
2975 | .cnic_exit = bnx2fc_ulp_exit, | |
2976 | .cnic_start = bnx2fc_ulp_start, | |
2977 | .cnic_stop = bnx2fc_ulp_stop, | |
2978 | .indicate_kcqes = bnx2fc_indicate_kcqe, | |
2979 | .indicate_netevent = bnx2fc_indicate_netevent, | |
2e499d3c | 2980 | .cnic_get_stats = bnx2fc_ulp_get_stats, |
853e2bd2 | 2981 | }; |