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