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