]>
Commit | Line | Data |
---|---|---|
853e2bd2 BG |
1 | /* bnx2fc_fcoe.c: Broadcom NetXtreme II Linux FCoE offload driver. |
2 | * This file contains the code that interacts with libfc, libfcoe, | |
3 | * cnic modules to create FCoE instances, send/receive non-offloaded | |
4 | * FIP/FCoE packets, listen to link events etc. | |
5 | * | |
6 | * Copyright (c) 2008 - 2010 Broadcom Corporation | |
7 | * | |
8 | * This program is free software; you can redistribute it and/or modify | |
9 | * it under the terms of the GNU General Public License as published by | |
10 | * the Free Software Foundation. | |
11 | * | |
12 | * Written by: Bhanu Prakash Gollapudi (bprakash@broadcom.com) | |
13 | */ | |
14 | ||
15 | #include "bnx2fc.h" | |
16 | ||
17 | static struct list_head adapter_list; | |
18 | static u32 adapter_count; | |
19 | static DEFINE_MUTEX(bnx2fc_dev_lock); | |
20 | DEFINE_PER_CPU(struct bnx2fc_percpu_s, bnx2fc_percpu); | |
21 | ||
22 | #define DRV_MODULE_NAME "bnx2fc" | |
23 | #define DRV_MODULE_VERSION BNX2FC_VERSION | |
24 | #define DRV_MODULE_RELDATE "Jan 25, 2011" | |
25 | ||
26 | ||
27 | static char version[] __devinitdata = | |
28 | "Broadcom NetXtreme II FCoE Driver " DRV_MODULE_NAME \ | |
29 | " v" DRV_MODULE_VERSION " (" DRV_MODULE_RELDATE ")\n"; | |
30 | ||
31 | ||
32 | MODULE_AUTHOR("Bhanu Prakash Gollapudi <bprakash@broadcom.com>"); | |
33 | MODULE_DESCRIPTION("Broadcom NetXtreme II BCM57710 FCoE Driver"); | |
34 | MODULE_LICENSE("GPL"); | |
35 | MODULE_VERSION(DRV_MODULE_VERSION); | |
36 | ||
37 | #define BNX2FC_MAX_QUEUE_DEPTH 256 | |
38 | #define BNX2FC_MIN_QUEUE_DEPTH 32 | |
39 | #define FCOE_WORD_TO_BYTE 4 | |
40 | ||
41 | static struct scsi_transport_template *bnx2fc_transport_template; | |
42 | static struct scsi_transport_template *bnx2fc_vport_xport_template; | |
43 | ||
44 | struct workqueue_struct *bnx2fc_wq; | |
45 | ||
46 | /* bnx2fc structure needs only one instance of the fcoe_percpu_s structure. | |
47 | * Here the io threads are per cpu but the l2 thread is just one | |
48 | */ | |
49 | struct fcoe_percpu_s bnx2fc_global; | |
50 | DEFINE_SPINLOCK(bnx2fc_global_lock); | |
51 | ||
52 | static struct cnic_ulp_ops bnx2fc_cnic_cb; | |
53 | static struct libfc_function_template bnx2fc_libfc_fcn_templ; | |
54 | static struct scsi_host_template bnx2fc_shost_template; | |
55 | static struct fc_function_template bnx2fc_transport_function; | |
56 | static struct fc_function_template bnx2fc_vport_xport_function; | |
57 | static int bnx2fc_create(struct net_device *netdev, enum fip_state fip_mode); | |
58 | static int bnx2fc_destroy(struct net_device *net_device); | |
59 | static int bnx2fc_enable(struct net_device *netdev); | |
60 | static int bnx2fc_disable(struct net_device *netdev); | |
61 | ||
62 | static void bnx2fc_recv_frame(struct sk_buff *skb); | |
63 | ||
64 | static void bnx2fc_start_disc(struct bnx2fc_hba *hba); | |
65 | static int bnx2fc_shost_config(struct fc_lport *lport, struct device *dev); | |
66 | static int bnx2fc_net_config(struct fc_lport *lp); | |
67 | static int bnx2fc_lport_config(struct fc_lport *lport); | |
68 | static int bnx2fc_em_config(struct fc_lport *lport); | |
69 | static int bnx2fc_bind_adapter_devices(struct bnx2fc_hba *hba); | |
70 | static void bnx2fc_unbind_adapter_devices(struct bnx2fc_hba *hba); | |
71 | static int bnx2fc_bind_pcidev(struct bnx2fc_hba *hba); | |
72 | static void bnx2fc_unbind_pcidev(struct bnx2fc_hba *hba); | |
73 | static struct fc_lport *bnx2fc_if_create(struct bnx2fc_hba *hba, | |
74 | struct device *parent, int npiv); | |
75 | static void bnx2fc_destroy_work(struct work_struct *work); | |
76 | ||
77 | static struct bnx2fc_hba *bnx2fc_hba_lookup(struct net_device *phys_dev); | |
78 | static struct bnx2fc_hba *bnx2fc_find_hba_for_cnic(struct cnic_dev *cnic); | |
79 | ||
80 | static int bnx2fc_fw_init(struct bnx2fc_hba *hba); | |
81 | static void bnx2fc_fw_destroy(struct bnx2fc_hba *hba); | |
82 | ||
83 | static void bnx2fc_port_shutdown(struct fc_lport *lport); | |
84 | static void bnx2fc_stop(struct bnx2fc_hba *hba); | |
85 | static int __init bnx2fc_mod_init(void); | |
86 | static void __exit bnx2fc_mod_exit(void); | |
87 | ||
88 | unsigned int bnx2fc_debug_level; | |
89 | module_param_named(debug_logging, bnx2fc_debug_level, int, S_IRUGO|S_IWUSR); | |
90 | ||
91 | static int bnx2fc_cpu_callback(struct notifier_block *nfb, | |
92 | unsigned long action, void *hcpu); | |
93 | /* notification function for CPU hotplug events */ | |
94 | static struct notifier_block bnx2fc_cpu_notifier = { | |
95 | .notifier_call = bnx2fc_cpu_callback, | |
96 | }; | |
97 | ||
98 | static void bnx2fc_clean_rx_queue(struct fc_lport *lp) | |
99 | { | |
100 | struct fcoe_percpu_s *bg; | |
101 | struct fcoe_rcv_info *fr; | |
102 | struct sk_buff_head *list; | |
103 | struct sk_buff *skb, *next; | |
104 | struct sk_buff *head; | |
105 | ||
106 | bg = &bnx2fc_global; | |
107 | spin_lock_bh(&bg->fcoe_rx_list.lock); | |
108 | list = &bg->fcoe_rx_list; | |
109 | head = list->next; | |
110 | for (skb = head; skb != (struct sk_buff *)list; | |
111 | skb = next) { | |
112 | next = skb->next; | |
113 | fr = fcoe_dev_from_skb(skb); | |
114 | if (fr->fr_dev == lp) { | |
115 | __skb_unlink(skb, list); | |
116 | kfree_skb(skb); | |
117 | } | |
118 | } | |
119 | spin_unlock_bh(&bg->fcoe_rx_list.lock); | |
120 | } | |
121 | ||
122 | int bnx2fc_get_paged_crc_eof(struct sk_buff *skb, int tlen) | |
123 | { | |
124 | int rc; | |
125 | spin_lock(&bnx2fc_global_lock); | |
126 | rc = fcoe_get_paged_crc_eof(skb, tlen, &bnx2fc_global); | |
127 | spin_unlock(&bnx2fc_global_lock); | |
128 | ||
129 | return rc; | |
130 | } | |
131 | ||
132 | static void bnx2fc_abort_io(struct fc_lport *lport) | |
133 | { | |
134 | /* | |
135 | * This function is no-op for bnx2fc, but we do | |
136 | * not want to leave it as NULL either, as libfc | |
137 | * can call the default function which is | |
138 | * fc_fcp_abort_io. | |
139 | */ | |
140 | } | |
141 | ||
142 | static void bnx2fc_cleanup(struct fc_lport *lport) | |
143 | { | |
144 | struct fcoe_port *port = lport_priv(lport); | |
145 | struct bnx2fc_hba *hba = port->priv; | |
146 | struct bnx2fc_rport *tgt; | |
147 | int i; | |
148 | ||
149 | BNX2FC_MISC_DBG("Entered %s\n", __func__); | |
150 | mutex_lock(&hba->hba_mutex); | |
151 | spin_lock_bh(&hba->hba_lock); | |
152 | for (i = 0; i < BNX2FC_NUM_MAX_SESS; i++) { | |
153 | tgt = hba->tgt_ofld_list[i]; | |
154 | if (tgt) { | |
155 | /* Cleanup IOs belonging to requested vport */ | |
156 | if (tgt->port == port) { | |
157 | spin_unlock_bh(&hba->hba_lock); | |
158 | BNX2FC_TGT_DBG(tgt, "flush/cleanup\n"); | |
159 | bnx2fc_flush_active_ios(tgt); | |
160 | spin_lock_bh(&hba->hba_lock); | |
161 | } | |
162 | } | |
163 | } | |
164 | spin_unlock_bh(&hba->hba_lock); | |
165 | mutex_unlock(&hba->hba_mutex); | |
166 | } | |
167 | ||
168 | static int bnx2fc_xmit_l2_frame(struct bnx2fc_rport *tgt, | |
169 | struct fc_frame *fp) | |
170 | { | |
171 | struct fc_rport_priv *rdata = tgt->rdata; | |
172 | struct fc_frame_header *fh; | |
173 | int rc = 0; | |
174 | ||
175 | fh = fc_frame_header_get(fp); | |
176 | BNX2FC_TGT_DBG(tgt, "Xmit L2 frame rport = 0x%x, oxid = 0x%x, " | |
177 | "r_ctl = 0x%x\n", rdata->ids.port_id, | |
178 | ntohs(fh->fh_ox_id), fh->fh_r_ctl); | |
179 | if ((fh->fh_type == FC_TYPE_ELS) && | |
180 | (fh->fh_r_ctl == FC_RCTL_ELS_REQ)) { | |
181 | ||
182 | switch (fc_frame_payload_op(fp)) { | |
183 | case ELS_ADISC: | |
184 | rc = bnx2fc_send_adisc(tgt, fp); | |
185 | break; | |
186 | case ELS_LOGO: | |
187 | rc = bnx2fc_send_logo(tgt, fp); | |
188 | break; | |
189 | case ELS_RLS: | |
190 | rc = bnx2fc_send_rls(tgt, fp); | |
191 | break; | |
192 | default: | |
193 | break; | |
194 | } | |
195 | } else if ((fh->fh_type == FC_TYPE_BLS) && | |
196 | (fh->fh_r_ctl == FC_RCTL_BA_ABTS)) | |
197 | BNX2FC_TGT_DBG(tgt, "ABTS frame\n"); | |
198 | else { | |
199 | BNX2FC_TGT_DBG(tgt, "Send L2 frame type 0x%x " | |
200 | "rctl 0x%x thru non-offload path\n", | |
201 | fh->fh_type, fh->fh_r_ctl); | |
202 | return -ENODEV; | |
203 | } | |
204 | if (rc) | |
205 | return -ENOMEM; | |
206 | else | |
207 | return 0; | |
208 | } | |
209 | ||
210 | /** | |
211 | * bnx2fc_xmit - bnx2fc's FCoE frame transmit function | |
212 | * | |
213 | * @lport: the associated local port | |
214 | * @fp: the fc_frame to be transmitted | |
215 | */ | |
216 | static int bnx2fc_xmit(struct fc_lport *lport, struct fc_frame *fp) | |
217 | { | |
218 | struct ethhdr *eh; | |
219 | struct fcoe_crc_eof *cp; | |
220 | struct sk_buff *skb; | |
221 | struct fc_frame_header *fh; | |
222 | struct bnx2fc_hba *hba; | |
223 | struct fcoe_port *port; | |
224 | struct fcoe_hdr *hp; | |
225 | struct bnx2fc_rport *tgt; | |
226 | struct fcoe_dev_stats *stats; | |
227 | u8 sof, eof; | |
228 | u32 crc; | |
229 | unsigned int hlen, tlen, elen; | |
230 | int wlen, rc = 0; | |
231 | ||
232 | port = (struct fcoe_port *)lport_priv(lport); | |
233 | hba = port->priv; | |
234 | ||
235 | fh = fc_frame_header_get(fp); | |
236 | ||
237 | skb = fp_skb(fp); | |
238 | if (!lport->link_up) { | |
239 | BNX2FC_HBA_DBG(lport, "bnx2fc_xmit link down\n"); | |
240 | kfree_skb(skb); | |
241 | return 0; | |
242 | } | |
243 | ||
244 | if (unlikely(fh->fh_r_ctl == FC_RCTL_ELS_REQ)) { | |
245 | if (!hba->ctlr.sel_fcf) { | |
246 | BNX2FC_HBA_DBG(lport, "FCF not selected yet!\n"); | |
247 | kfree_skb(skb); | |
248 | return -EINVAL; | |
249 | } | |
250 | if (fcoe_ctlr_els_send(&hba->ctlr, lport, skb)) | |
251 | return 0; | |
252 | } | |
253 | ||
254 | sof = fr_sof(fp); | |
255 | eof = fr_eof(fp); | |
256 | ||
257 | /* | |
258 | * Snoop the frame header to check if the frame is for | |
259 | * an offloaded session | |
260 | */ | |
261 | /* | |
262 | * tgt_ofld_list access is synchronized using | |
263 | * both hba mutex and hba lock. Atleast hba mutex or | |
264 | * hba lock needs to be held for read access. | |
265 | */ | |
266 | ||
267 | spin_lock_bh(&hba->hba_lock); | |
268 | tgt = bnx2fc_tgt_lookup(port, ntoh24(fh->fh_d_id)); | |
269 | if (tgt && (test_bit(BNX2FC_FLAG_SESSION_READY, &tgt->flags))) { | |
270 | /* This frame is for offloaded session */ | |
271 | BNX2FC_HBA_DBG(lport, "xmit: Frame is for offloaded session " | |
272 | "port_id = 0x%x\n", ntoh24(fh->fh_d_id)); | |
273 | spin_unlock_bh(&hba->hba_lock); | |
274 | rc = bnx2fc_xmit_l2_frame(tgt, fp); | |
275 | if (rc != -ENODEV) { | |
276 | kfree_skb(skb); | |
277 | return rc; | |
278 | } | |
279 | } else { | |
280 | spin_unlock_bh(&hba->hba_lock); | |
281 | } | |
282 | ||
283 | elen = sizeof(struct ethhdr); | |
284 | hlen = sizeof(struct fcoe_hdr); | |
285 | tlen = sizeof(struct fcoe_crc_eof); | |
286 | wlen = (skb->len - tlen + sizeof(crc)) / FCOE_WORD_TO_BYTE; | |
287 | ||
288 | skb->ip_summed = CHECKSUM_NONE; | |
289 | crc = fcoe_fc_crc(fp); | |
290 | ||
291 | /* copy port crc and eof to the skb buff */ | |
292 | if (skb_is_nonlinear(skb)) { | |
293 | skb_frag_t *frag; | |
294 | if (bnx2fc_get_paged_crc_eof(skb, tlen)) { | |
295 | kfree_skb(skb); | |
296 | return -ENOMEM; | |
297 | } | |
298 | frag = &skb_shinfo(skb)->frags[skb_shinfo(skb)->nr_frags - 1]; | |
299 | cp = kmap_atomic(frag->page, KM_SKB_DATA_SOFTIRQ) | |
300 | + frag->page_offset; | |
301 | } else { | |
302 | cp = (struct fcoe_crc_eof *)skb_put(skb, tlen); | |
303 | } | |
304 | ||
305 | memset(cp, 0, sizeof(*cp)); | |
306 | cp->fcoe_eof = eof; | |
307 | cp->fcoe_crc32 = cpu_to_le32(~crc); | |
308 | if (skb_is_nonlinear(skb)) { | |
309 | kunmap_atomic(cp, KM_SKB_DATA_SOFTIRQ); | |
310 | cp = NULL; | |
311 | } | |
312 | ||
313 | /* adjust skb network/transport offsets to match mac/fcoe/port */ | |
314 | skb_push(skb, elen + hlen); | |
315 | skb_reset_mac_header(skb); | |
316 | skb_reset_network_header(skb); | |
317 | skb->mac_len = elen; | |
318 | skb->protocol = htons(ETH_P_FCOE); | |
319 | skb->dev = hba->netdev; | |
320 | ||
321 | /* fill up mac and fcoe headers */ | |
322 | eh = eth_hdr(skb); | |
323 | eh->h_proto = htons(ETH_P_FCOE); | |
324 | if (hba->ctlr.map_dest) | |
325 | fc_fcoe_set_mac(eh->h_dest, fh->fh_d_id); | |
326 | else | |
327 | /* insert GW address */ | |
328 | memcpy(eh->h_dest, hba->ctlr.dest_addr, ETH_ALEN); | |
329 | ||
330 | if (unlikely(hba->ctlr.flogi_oxid != FC_XID_UNKNOWN)) | |
331 | memcpy(eh->h_source, hba->ctlr.ctl_src_addr, ETH_ALEN); | |
332 | else | |
333 | memcpy(eh->h_source, port->data_src_addr, ETH_ALEN); | |
334 | ||
335 | hp = (struct fcoe_hdr *)(eh + 1); | |
336 | memset(hp, 0, sizeof(*hp)); | |
337 | if (FC_FCOE_VER) | |
338 | FC_FCOE_ENCAPS_VER(hp, FC_FCOE_VER); | |
339 | hp->fcoe_sof = sof; | |
340 | ||
341 | /* fcoe lso, mss is in max_payload which is non-zero for FCP data */ | |
342 | if (lport->seq_offload && fr_max_payload(fp)) { | |
343 | skb_shinfo(skb)->gso_type = SKB_GSO_FCOE; | |
344 | skb_shinfo(skb)->gso_size = fr_max_payload(fp); | |
345 | } else { | |
346 | skb_shinfo(skb)->gso_type = 0; | |
347 | skb_shinfo(skb)->gso_size = 0; | |
348 | } | |
349 | ||
350 | /*update tx stats */ | |
351 | stats = per_cpu_ptr(lport->dev_stats, get_cpu()); | |
352 | stats->TxFrames++; | |
353 | stats->TxWords += wlen; | |
354 | put_cpu(); | |
355 | ||
356 | /* send down to lld */ | |
357 | fr_dev(fp) = lport; | |
358 | if (port->fcoe_pending_queue.qlen) | |
359 | fcoe_check_wait_queue(lport, skb); | |
360 | else if (fcoe_start_io(skb)) | |
361 | fcoe_check_wait_queue(lport, skb); | |
362 | ||
363 | return 0; | |
364 | } | |
365 | ||
366 | /** | |
367 | * bnx2fc_rcv - This is bnx2fc's receive function called by NET_RX_SOFTIRQ | |
368 | * | |
369 | * @skb: the receive socket buffer | |
370 | * @dev: associated net device | |
371 | * @ptype: context | |
372 | * @olddev: last device | |
373 | * | |
374 | * This function receives the packet and builds FC frame and passes it up | |
375 | */ | |
376 | static int bnx2fc_rcv(struct sk_buff *skb, struct net_device *dev, | |
377 | struct packet_type *ptype, struct net_device *olddev) | |
378 | { | |
379 | struct fc_lport *lport; | |
380 | struct bnx2fc_hba *hba; | |
381 | struct fc_frame_header *fh; | |
382 | struct fcoe_rcv_info *fr; | |
383 | struct fcoe_percpu_s *bg; | |
384 | unsigned short oxid; | |
385 | ||
386 | hba = container_of(ptype, struct bnx2fc_hba, fcoe_packet_type); | |
387 | lport = hba->ctlr.lp; | |
388 | ||
389 | if (unlikely(lport == NULL)) { | |
390 | printk(KERN_ALERT PFX "bnx2fc_rcv: lport is NULL\n"); | |
391 | goto err; | |
392 | } | |
393 | ||
394 | if (unlikely(eth_hdr(skb)->h_proto != htons(ETH_P_FCOE))) { | |
395 | printk(KERN_ALERT PFX "bnx2fc_rcv: Wrong FC type frame\n"); | |
396 | goto err; | |
397 | } | |
398 | ||
399 | /* | |
400 | * Check for minimum frame length, and make sure required FCoE | |
401 | * and FC headers are pulled into the linear data area. | |
402 | */ | |
403 | if (unlikely((skb->len < FCOE_MIN_FRAME) || | |
404 | !pskb_may_pull(skb, FCOE_HEADER_LEN))) | |
405 | goto err; | |
406 | ||
407 | skb_set_transport_header(skb, sizeof(struct fcoe_hdr)); | |
408 | fh = (struct fc_frame_header *) skb_transport_header(skb); | |
409 | ||
410 | oxid = ntohs(fh->fh_ox_id); | |
411 | ||
412 | fr = fcoe_dev_from_skb(skb); | |
413 | fr->fr_dev = lport; | |
414 | fr->ptype = ptype; | |
415 | ||
416 | bg = &bnx2fc_global; | |
417 | spin_lock_bh(&bg->fcoe_rx_list.lock); | |
418 | ||
419 | __skb_queue_tail(&bg->fcoe_rx_list, skb); | |
420 | if (bg->fcoe_rx_list.qlen == 1) | |
421 | wake_up_process(bg->thread); | |
422 | ||
423 | spin_unlock_bh(&bg->fcoe_rx_list.lock); | |
424 | ||
425 | return 0; | |
426 | err: | |
427 | kfree_skb(skb); | |
428 | return -1; | |
429 | } | |
430 | ||
431 | static int bnx2fc_l2_rcv_thread(void *arg) | |
432 | { | |
433 | struct fcoe_percpu_s *bg = arg; | |
434 | struct sk_buff *skb; | |
435 | ||
436 | set_user_nice(current, -20); | |
437 | set_current_state(TASK_INTERRUPTIBLE); | |
438 | while (!kthread_should_stop()) { | |
439 | schedule(); | |
440 | set_current_state(TASK_RUNNING); | |
441 | spin_lock_bh(&bg->fcoe_rx_list.lock); | |
442 | while ((skb = __skb_dequeue(&bg->fcoe_rx_list)) != NULL) { | |
443 | spin_unlock_bh(&bg->fcoe_rx_list.lock); | |
444 | bnx2fc_recv_frame(skb); | |
445 | spin_lock_bh(&bg->fcoe_rx_list.lock); | |
446 | } | |
447 | spin_unlock_bh(&bg->fcoe_rx_list.lock); | |
448 | set_current_state(TASK_INTERRUPTIBLE); | |
449 | } | |
450 | set_current_state(TASK_RUNNING); | |
451 | return 0; | |
452 | } | |
453 | ||
454 | ||
455 | static void bnx2fc_recv_frame(struct sk_buff *skb) | |
456 | { | |
457 | u32 fr_len; | |
458 | struct fc_lport *lport; | |
459 | struct fcoe_rcv_info *fr; | |
460 | struct fcoe_dev_stats *stats; | |
461 | struct fc_frame_header *fh; | |
462 | struct fcoe_crc_eof crc_eof; | |
463 | struct fc_frame *fp; | |
464 | struct fc_lport *vn_port; | |
465 | struct fcoe_port *port; | |
466 | u8 *mac = NULL; | |
467 | u8 *dest_mac = NULL; | |
468 | struct fcoe_hdr *hp; | |
469 | ||
470 | fr = fcoe_dev_from_skb(skb); | |
471 | lport = fr->fr_dev; | |
472 | if (unlikely(lport == NULL)) { | |
473 | printk(KERN_ALERT PFX "Invalid lport struct\n"); | |
474 | kfree_skb(skb); | |
475 | return; | |
476 | } | |
477 | ||
478 | if (skb_is_nonlinear(skb)) | |
479 | skb_linearize(skb); | |
480 | mac = eth_hdr(skb)->h_source; | |
481 | dest_mac = eth_hdr(skb)->h_dest; | |
482 | ||
483 | /* Pull the header */ | |
484 | hp = (struct fcoe_hdr *) skb_network_header(skb); | |
485 | fh = (struct fc_frame_header *) skb_transport_header(skb); | |
486 | skb_pull(skb, sizeof(struct fcoe_hdr)); | |
487 | fr_len = skb->len - sizeof(struct fcoe_crc_eof); | |
488 | ||
489 | stats = per_cpu_ptr(lport->dev_stats, get_cpu()); | |
490 | stats->RxFrames++; | |
491 | stats->RxWords += fr_len / FCOE_WORD_TO_BYTE; | |
492 | ||
493 | fp = (struct fc_frame *)skb; | |
494 | fc_frame_init(fp); | |
495 | fr_dev(fp) = lport; | |
496 | fr_sof(fp) = hp->fcoe_sof; | |
497 | if (skb_copy_bits(skb, fr_len, &crc_eof, sizeof(crc_eof))) { | |
498 | put_cpu(); | |
499 | kfree_skb(skb); | |
500 | return; | |
501 | } | |
502 | fr_eof(fp) = crc_eof.fcoe_eof; | |
503 | fr_crc(fp) = crc_eof.fcoe_crc32; | |
504 | if (pskb_trim(skb, fr_len)) { | |
505 | put_cpu(); | |
506 | kfree_skb(skb); | |
507 | return; | |
508 | } | |
509 | ||
510 | fh = fc_frame_header_get(fp); | |
511 | ||
512 | vn_port = fc_vport_id_lookup(lport, ntoh24(fh->fh_d_id)); | |
513 | if (vn_port) { | |
514 | port = lport_priv(vn_port); | |
515 | if (compare_ether_addr(port->data_src_addr, dest_mac) | |
516 | != 0) { | |
517 | BNX2FC_HBA_DBG(lport, "fpma mismatch\n"); | |
518 | put_cpu(); | |
519 | kfree_skb(skb); | |
520 | return; | |
521 | } | |
522 | } | |
523 | if (fh->fh_r_ctl == FC_RCTL_DD_SOL_DATA && | |
524 | fh->fh_type == FC_TYPE_FCP) { | |
525 | /* Drop FCP data. We dont this in L2 path */ | |
526 | put_cpu(); | |
527 | kfree_skb(skb); | |
528 | return; | |
529 | } | |
530 | if (fh->fh_r_ctl == FC_RCTL_ELS_REQ && | |
531 | fh->fh_type == FC_TYPE_ELS) { | |
532 | switch (fc_frame_payload_op(fp)) { | |
533 | case ELS_LOGO: | |
534 | if (ntoh24(fh->fh_s_id) == FC_FID_FLOGI) { | |
535 | /* drop non-FIP LOGO */ | |
536 | put_cpu(); | |
537 | kfree_skb(skb); | |
538 | return; | |
539 | } | |
540 | break; | |
541 | } | |
542 | } | |
543 | if (le32_to_cpu(fr_crc(fp)) != | |
544 | ~crc32(~0, skb->data, fr_len)) { | |
545 | if (stats->InvalidCRCCount < 5) | |
546 | printk(KERN_WARNING PFX "dropping frame with " | |
547 | "CRC error\n"); | |
548 | stats->InvalidCRCCount++; | |
549 | put_cpu(); | |
550 | kfree_skb(skb); | |
551 | return; | |
552 | } | |
553 | put_cpu(); | |
554 | fc_exch_recv(lport, fp); | |
555 | } | |
556 | ||
557 | /** | |
558 | * bnx2fc_percpu_io_thread - thread per cpu for ios | |
559 | * | |
560 | * @arg: ptr to bnx2fc_percpu_info structure | |
561 | */ | |
562 | int bnx2fc_percpu_io_thread(void *arg) | |
563 | { | |
564 | struct bnx2fc_percpu_s *p = arg; | |
565 | struct bnx2fc_work *work, *tmp; | |
566 | LIST_HEAD(work_list); | |
567 | ||
568 | set_user_nice(current, -20); | |
569 | set_current_state(TASK_INTERRUPTIBLE); | |
570 | while (!kthread_should_stop()) { | |
571 | schedule(); | |
572 | set_current_state(TASK_RUNNING); | |
573 | spin_lock_bh(&p->fp_work_lock); | |
574 | while (!list_empty(&p->work_list)) { | |
575 | list_splice_init(&p->work_list, &work_list); | |
576 | spin_unlock_bh(&p->fp_work_lock); | |
577 | ||
578 | list_for_each_entry_safe(work, tmp, &work_list, list) { | |
579 | list_del_init(&work->list); | |
580 | bnx2fc_process_cq_compl(work->tgt, work->wqe); | |
581 | kfree(work); | |
582 | } | |
583 | ||
584 | spin_lock_bh(&p->fp_work_lock); | |
585 | } | |
586 | spin_unlock_bh(&p->fp_work_lock); | |
587 | set_current_state(TASK_INTERRUPTIBLE); | |
588 | } | |
589 | set_current_state(TASK_RUNNING); | |
590 | ||
591 | return 0; | |
592 | } | |
593 | ||
594 | static struct fc_host_statistics *bnx2fc_get_host_stats(struct Scsi_Host *shost) | |
595 | { | |
596 | struct fc_host_statistics *bnx2fc_stats; | |
597 | struct fc_lport *lport = shost_priv(shost); | |
598 | struct fcoe_port *port = lport_priv(lport); | |
599 | struct bnx2fc_hba *hba = port->priv; | |
600 | struct fcoe_statistics_params *fw_stats; | |
601 | int rc = 0; | |
602 | ||
603 | fw_stats = (struct fcoe_statistics_params *)hba->stats_buffer; | |
604 | if (!fw_stats) | |
605 | return NULL; | |
606 | ||
607 | bnx2fc_stats = fc_get_host_stats(shost); | |
608 | ||
609 | init_completion(&hba->stat_req_done); | |
610 | if (bnx2fc_send_stat_req(hba)) | |
611 | return bnx2fc_stats; | |
612 | rc = wait_for_completion_timeout(&hba->stat_req_done, (2 * HZ)); | |
613 | if (!rc) { | |
614 | BNX2FC_HBA_DBG(lport, "FW stat req timed out\n"); | |
615 | return bnx2fc_stats; | |
616 | } | |
617 | bnx2fc_stats->invalid_crc_count += fw_stats->rx_stat1.fc_crc_cnt; | |
618 | bnx2fc_stats->tx_frames += fw_stats->tx_stat.fcoe_tx_pkt_cnt; | |
619 | bnx2fc_stats->tx_words += (fw_stats->tx_stat.fcoe_tx_byte_cnt) / 4; | |
620 | bnx2fc_stats->rx_frames += fw_stats->rx_stat0.fcoe_rx_pkt_cnt; | |
621 | bnx2fc_stats->rx_words += (fw_stats->rx_stat0.fcoe_rx_byte_cnt) / 4; | |
622 | ||
623 | bnx2fc_stats->dumped_frames = 0; | |
624 | bnx2fc_stats->lip_count = 0; | |
625 | bnx2fc_stats->nos_count = 0; | |
626 | bnx2fc_stats->loss_of_sync_count = 0; | |
627 | bnx2fc_stats->loss_of_signal_count = 0; | |
628 | bnx2fc_stats->prim_seq_protocol_err_count = 0; | |
629 | ||
630 | return bnx2fc_stats; | |
631 | } | |
632 | ||
633 | static int bnx2fc_shost_config(struct fc_lport *lport, struct device *dev) | |
634 | { | |
635 | struct fcoe_port *port = lport_priv(lport); | |
636 | struct bnx2fc_hba *hba = port->priv; | |
637 | struct Scsi_Host *shost = lport->host; | |
638 | int rc = 0; | |
639 | ||
640 | shost->max_cmd_len = BNX2FC_MAX_CMD_LEN; | |
641 | shost->max_lun = BNX2FC_MAX_LUN; | |
642 | shost->max_id = BNX2FC_MAX_FCP_TGT; | |
643 | shost->max_channel = 0; | |
644 | if (lport->vport) | |
645 | shost->transportt = bnx2fc_vport_xport_template; | |
646 | else | |
647 | shost->transportt = bnx2fc_transport_template; | |
648 | ||
649 | /* Add the new host to SCSI-ml */ | |
650 | rc = scsi_add_host(lport->host, dev); | |
651 | if (rc) { | |
652 | printk(KERN_ERR PFX "Error on scsi_add_host\n"); | |
653 | return rc; | |
654 | } | |
655 | if (!lport->vport) | |
656 | fc_host_max_npiv_vports(lport->host) = USHRT_MAX; | |
657 | sprintf(fc_host_symbolic_name(lport->host), "%s v%s over %s", | |
658 | BNX2FC_NAME, BNX2FC_VERSION, | |
659 | hba->netdev->name); | |
660 | ||
661 | return 0; | |
662 | } | |
663 | ||
664 | static int bnx2fc_mfs_update(struct fc_lport *lport) | |
665 | { | |
666 | struct fcoe_port *port = lport_priv(lport); | |
667 | struct bnx2fc_hba *hba = port->priv; | |
668 | struct net_device *netdev = hba->netdev; | |
669 | u32 mfs; | |
670 | u32 max_mfs; | |
671 | ||
672 | mfs = netdev->mtu - (sizeof(struct fcoe_hdr) + | |
673 | sizeof(struct fcoe_crc_eof)); | |
674 | max_mfs = BNX2FC_MAX_PAYLOAD + sizeof(struct fc_frame_header); | |
675 | BNX2FC_HBA_DBG(lport, "mfs = %d, max_mfs = %d\n", mfs, max_mfs); | |
676 | if (mfs > max_mfs) | |
677 | mfs = max_mfs; | |
678 | ||
679 | /* Adjust mfs to be a multiple of 256 bytes */ | |
680 | mfs = (((mfs - sizeof(struct fc_frame_header)) / BNX2FC_MIN_PAYLOAD) * | |
681 | BNX2FC_MIN_PAYLOAD); | |
682 | mfs = mfs + sizeof(struct fc_frame_header); | |
683 | ||
684 | BNX2FC_HBA_DBG(lport, "Set MFS = %d\n", mfs); | |
685 | if (fc_set_mfs(lport, mfs)) | |
686 | return -EINVAL; | |
687 | return 0; | |
688 | } | |
689 | static void bnx2fc_link_speed_update(struct fc_lport *lport) | |
690 | { | |
691 | struct fcoe_port *port = lport_priv(lport); | |
692 | struct bnx2fc_hba *hba = port->priv; | |
693 | struct net_device *netdev = hba->netdev; | |
694 | struct ethtool_cmd ecmd = { ETHTOOL_GSET }; | |
695 | ||
696 | if (!dev_ethtool_get_settings(netdev, &ecmd)) { | |
697 | lport->link_supported_speeds &= | |
698 | ~(FC_PORTSPEED_1GBIT | FC_PORTSPEED_10GBIT); | |
699 | if (ecmd.supported & (SUPPORTED_1000baseT_Half | | |
700 | SUPPORTED_1000baseT_Full)) | |
701 | lport->link_supported_speeds |= FC_PORTSPEED_1GBIT; | |
702 | if (ecmd.supported & SUPPORTED_10000baseT_Full) | |
703 | lport->link_supported_speeds |= FC_PORTSPEED_10GBIT; | |
704 | ||
705 | if (ecmd.speed == SPEED_1000) | |
706 | lport->link_speed = FC_PORTSPEED_1GBIT; | |
707 | if (ecmd.speed == SPEED_10000) | |
708 | lport->link_speed = FC_PORTSPEED_10GBIT; | |
709 | } | |
710 | return; | |
711 | } | |
712 | static int bnx2fc_link_ok(struct fc_lport *lport) | |
713 | { | |
714 | struct fcoe_port *port = lport_priv(lport); | |
715 | struct bnx2fc_hba *hba = port->priv; | |
716 | struct net_device *dev = hba->phys_dev; | |
717 | int rc = 0; | |
718 | ||
719 | if ((dev->flags & IFF_UP) && netif_carrier_ok(dev)) | |
720 | clear_bit(ADAPTER_STATE_LINK_DOWN, &hba->adapter_state); | |
721 | else { | |
722 | set_bit(ADAPTER_STATE_LINK_DOWN, &hba->adapter_state); | |
723 | rc = -1; | |
724 | } | |
725 | return rc; | |
726 | } | |
727 | ||
728 | /** | |
729 | * bnx2fc_get_link_state - get network link state | |
730 | * | |
731 | * @hba: adapter instance pointer | |
732 | * | |
733 | * updates adapter structure flag based on netdev state | |
734 | */ | |
735 | void bnx2fc_get_link_state(struct bnx2fc_hba *hba) | |
736 | { | |
737 | if (test_bit(__LINK_STATE_NOCARRIER, &hba->netdev->state)) | |
738 | set_bit(ADAPTER_STATE_LINK_DOWN, &hba->adapter_state); | |
739 | else | |
740 | clear_bit(ADAPTER_STATE_LINK_DOWN, &hba->adapter_state); | |
741 | } | |
742 | ||
743 | static int bnx2fc_net_config(struct fc_lport *lport) | |
744 | { | |
745 | struct bnx2fc_hba *hba; | |
746 | struct fcoe_port *port; | |
747 | u64 wwnn, wwpn; | |
748 | ||
749 | port = lport_priv(lport); | |
750 | hba = port->priv; | |
751 | ||
752 | /* require support for get_pauseparam ethtool op. */ | |
753 | if (!hba->phys_dev->ethtool_ops || | |
754 | !hba->phys_dev->ethtool_ops->get_pauseparam) | |
755 | return -EOPNOTSUPP; | |
756 | ||
757 | if (bnx2fc_mfs_update(lport)) | |
758 | return -EINVAL; | |
759 | ||
760 | skb_queue_head_init(&port->fcoe_pending_queue); | |
761 | port->fcoe_pending_queue_active = 0; | |
762 | setup_timer(&port->timer, fcoe_queue_timer, (unsigned long) lport); | |
763 | ||
764 | bnx2fc_link_speed_update(lport); | |
765 | ||
766 | if (!lport->vport) { | |
767 | wwnn = fcoe_wwn_from_mac(hba->ctlr.ctl_src_addr, 1, 0); | |
768 | BNX2FC_HBA_DBG(lport, "WWNN = 0x%llx\n", wwnn); | |
769 | fc_set_wwnn(lport, wwnn); | |
770 | ||
771 | wwpn = fcoe_wwn_from_mac(hba->ctlr.ctl_src_addr, 2, 0); | |
772 | BNX2FC_HBA_DBG(lport, "WWPN = 0x%llx\n", wwpn); | |
773 | fc_set_wwpn(lport, wwpn); | |
774 | } | |
775 | ||
776 | return 0; | |
777 | } | |
778 | ||
779 | static void bnx2fc_destroy_timer(unsigned long data) | |
780 | { | |
781 | struct bnx2fc_hba *hba = (struct bnx2fc_hba *)data; | |
782 | ||
783 | BNX2FC_HBA_DBG(hba->ctlr.lp, "ERROR:bnx2fc_destroy_timer - " | |
784 | "Destroy compl not received!!\n"); | |
785 | hba->flags |= BNX2FC_FLAG_DESTROY_CMPL; | |
786 | wake_up_interruptible(&hba->destroy_wait); | |
787 | } | |
788 | ||
789 | /** | |
790 | * bnx2fc_indicate_netevent - Generic netdev event handler | |
791 | * | |
792 | * @context: adapter structure pointer | |
793 | * @event: event type | |
794 | * | |
795 | * Handles NETDEV_UP, NETDEV_DOWN, NETDEV_GOING_DOWN,NETDEV_CHANGE and | |
796 | * NETDEV_CHANGE_MTU events | |
797 | */ | |
798 | static void bnx2fc_indicate_netevent(void *context, unsigned long event) | |
799 | { | |
800 | struct bnx2fc_hba *hba = (struct bnx2fc_hba *)context; | |
801 | struct fc_lport *lport = hba->ctlr.lp; | |
802 | struct fc_lport *vport; | |
803 | u32 link_possible = 1; | |
804 | ||
805 | if (!test_bit(BNX2FC_CREATE_DONE, &hba->init_done)) { | |
806 | BNX2FC_MISC_DBG("driver not ready. event=%s %ld\n", | |
807 | hba->netdev->name, event); | |
808 | return; | |
809 | } | |
810 | ||
811 | /* | |
812 | * ASSUMPTION: | |
813 | * indicate_netevent cannot be called from cnic unless bnx2fc | |
814 | * does register_device | |
815 | */ | |
816 | BUG_ON(!lport); | |
817 | ||
818 | BNX2FC_HBA_DBG(lport, "enter netevent handler - event=%s %ld\n", | |
819 | hba->netdev->name, event); | |
820 | ||
821 | switch (event) { | |
822 | case NETDEV_UP: | |
823 | BNX2FC_HBA_DBG(lport, "Port up, adapter_state = %ld\n", | |
824 | hba->adapter_state); | |
825 | if (!test_bit(ADAPTER_STATE_UP, &hba->adapter_state)) | |
826 | printk(KERN_ERR "indicate_netevent: "\ | |
827 | "adapter is not UP!!\n"); | |
828 | /* fall thru to update mfs if MTU has changed */ | |
829 | case NETDEV_CHANGEMTU: | |
830 | BNX2FC_HBA_DBG(lport, "NETDEV_CHANGEMTU event\n"); | |
831 | bnx2fc_mfs_update(lport); | |
832 | mutex_lock(&lport->lp_mutex); | |
833 | list_for_each_entry(vport, &lport->vports, list) | |
834 | bnx2fc_mfs_update(vport); | |
835 | mutex_unlock(&lport->lp_mutex); | |
836 | break; | |
837 | ||
838 | case NETDEV_DOWN: | |
839 | BNX2FC_HBA_DBG(lport, "Port down\n"); | |
840 | clear_bit(ADAPTER_STATE_GOING_DOWN, &hba->adapter_state); | |
841 | clear_bit(ADAPTER_STATE_UP, &hba->adapter_state); | |
842 | link_possible = 0; | |
843 | break; | |
844 | ||
845 | case NETDEV_GOING_DOWN: | |
846 | BNX2FC_HBA_DBG(lport, "Port going down\n"); | |
847 | set_bit(ADAPTER_STATE_GOING_DOWN, &hba->adapter_state); | |
848 | link_possible = 0; | |
849 | break; | |
850 | ||
851 | case NETDEV_CHANGE: | |
852 | BNX2FC_HBA_DBG(lport, "NETDEV_CHANGE\n"); | |
853 | break; | |
854 | ||
855 | default: | |
856 | printk(KERN_ERR PFX "Unkonwn netevent %ld", event); | |
857 | return; | |
858 | } | |
859 | ||
860 | bnx2fc_link_speed_update(lport); | |
861 | ||
862 | if (link_possible && !bnx2fc_link_ok(lport)) { | |
863 | printk(KERN_ERR "indicate_netevent: call ctlr_link_up\n"); | |
864 | fcoe_ctlr_link_up(&hba->ctlr); | |
865 | } else { | |
866 | printk(KERN_ERR "indicate_netevent: call ctlr_link_down\n"); | |
867 | if (fcoe_ctlr_link_down(&hba->ctlr)) { | |
868 | clear_bit(ADAPTER_STATE_READY, &hba->adapter_state); | |
869 | mutex_lock(&lport->lp_mutex); | |
870 | list_for_each_entry(vport, &lport->vports, list) | |
871 | fc_host_port_type(vport->host) = | |
872 | FC_PORTTYPE_UNKNOWN; | |
873 | mutex_unlock(&lport->lp_mutex); | |
874 | fc_host_port_type(lport->host) = FC_PORTTYPE_UNKNOWN; | |
875 | per_cpu_ptr(lport->dev_stats, | |
876 | get_cpu())->LinkFailureCount++; | |
877 | put_cpu(); | |
878 | fcoe_clean_pending_queue(lport); | |
879 | ||
880 | init_waitqueue_head(&hba->shutdown_wait); | |
881 | BNX2FC_HBA_DBG(lport, "indicate_netevent " | |
882 | "num_ofld_sess = %d\n", | |
883 | hba->num_ofld_sess); | |
884 | hba->wait_for_link_down = 1; | |
885 | BNX2FC_HBA_DBG(lport, "waiting for uploads to " | |
886 | "compl proc = %s\n", | |
887 | current->comm); | |
888 | wait_event_interruptible(hba->shutdown_wait, | |
889 | (hba->num_ofld_sess == 0)); | |
890 | BNX2FC_HBA_DBG(lport, "wakeup - num_ofld_sess = %d\n", | |
891 | hba->num_ofld_sess); | |
892 | hba->wait_for_link_down = 0; | |
893 | ||
894 | if (signal_pending(current)) | |
895 | flush_signals(current); | |
896 | } | |
897 | } | |
898 | } | |
899 | ||
900 | static int bnx2fc_libfc_config(struct fc_lport *lport) | |
901 | { | |
902 | ||
903 | /* Set the function pointers set by bnx2fc driver */ | |
904 | memcpy(&lport->tt, &bnx2fc_libfc_fcn_templ, | |
905 | sizeof(struct libfc_function_template)); | |
906 | fc_elsct_init(lport); | |
907 | fc_exch_init(lport); | |
908 | fc_rport_init(lport); | |
909 | fc_disc_init(lport); | |
910 | return 0; | |
911 | } | |
912 | ||
913 | static int bnx2fc_em_config(struct fc_lport *lport) | |
914 | { | |
915 | struct fcoe_port *port = lport_priv(lport); | |
916 | struct bnx2fc_hba *hba = port->priv; | |
917 | ||
918 | if (!fc_exch_mgr_alloc(lport, FC_CLASS_3, FCOE_MIN_XID, | |
919 | FCOE_MAX_XID, NULL)) { | |
920 | printk(KERN_ERR PFX "em_config:fc_exch_mgr_alloc failed\n"); | |
921 | return -ENOMEM; | |
922 | } | |
923 | ||
924 | hba->cmd_mgr = bnx2fc_cmd_mgr_alloc(hba, BNX2FC_MIN_XID, | |
925 | BNX2FC_MAX_XID); | |
926 | ||
927 | if (!hba->cmd_mgr) { | |
928 | printk(KERN_ERR PFX "em_config:bnx2fc_cmd_mgr_alloc failed\n"); | |
929 | fc_exch_mgr_free(lport); | |
930 | return -ENOMEM; | |
931 | } | |
932 | return 0; | |
933 | } | |
934 | ||
935 | static int bnx2fc_lport_config(struct fc_lport *lport) | |
936 | { | |
937 | lport->link_up = 0; | |
938 | lport->qfull = 0; | |
939 | lport->max_retry_count = 3; | |
940 | lport->max_rport_retry_count = 3; | |
941 | lport->e_d_tov = 2 * 1000; | |
942 | lport->r_a_tov = 10 * 1000; | |
943 | ||
944 | /* REVISIT: enable when supporting tape devices | |
945 | lport->service_params = (FCP_SPPF_INIT_FCN | FCP_SPPF_RD_XRDY_DIS | | |
946 | FCP_SPPF_RETRY | FCP_SPPF_CONF_COMPL); | |
947 | */ | |
948 | lport->service_params = (FCP_SPPF_INIT_FCN | FCP_SPPF_RD_XRDY_DIS); | |
949 | lport->does_npiv = 1; | |
950 | ||
951 | memset(&lport->rnid_gen, 0, sizeof(struct fc_els_rnid_gen)); | |
952 | lport->rnid_gen.rnid_atype = BNX2FC_RNID_HBA; | |
953 | ||
954 | /* alloc stats structure */ | |
955 | if (fc_lport_init_stats(lport)) | |
956 | return -ENOMEM; | |
957 | ||
958 | /* Finish fc_lport configuration */ | |
959 | fc_lport_config(lport); | |
960 | ||
961 | return 0; | |
962 | } | |
963 | ||
964 | /** | |
965 | * bnx2fc_fip_recv - handle a received FIP frame. | |
966 | * | |
967 | * @skb: the received skb | |
968 | * @dev: associated &net_device | |
969 | * @ptype: the &packet_type structure which was used to register this handler. | |
970 | * @orig_dev: original receive &net_device, in case @ dev is a bond. | |
971 | * | |
972 | * Returns: 0 for success | |
973 | */ | |
974 | static int bnx2fc_fip_recv(struct sk_buff *skb, struct net_device *dev, | |
975 | struct packet_type *ptype, | |
976 | struct net_device *orig_dev) | |
977 | { | |
978 | struct bnx2fc_hba *hba; | |
979 | hba = container_of(ptype, struct bnx2fc_hba, fip_packet_type); | |
980 | fcoe_ctlr_recv(&hba->ctlr, skb); | |
981 | return 0; | |
982 | } | |
983 | ||
984 | /** | |
985 | * bnx2fc_update_src_mac - Update Ethernet MAC filters. | |
986 | * | |
987 | * @fip: FCoE controller. | |
988 | * @old: Unicast MAC address to delete if the MAC is non-zero. | |
989 | * @new: Unicast MAC address to add. | |
990 | * | |
991 | * Remove any previously-set unicast MAC filter. | |
992 | * Add secondary FCoE MAC address filter for our OUI. | |
993 | */ | |
994 | static void bnx2fc_update_src_mac(struct fc_lport *lport, u8 *addr) | |
995 | { | |
996 | struct fcoe_port *port = lport_priv(lport); | |
997 | ||
998 | memcpy(port->data_src_addr, addr, ETH_ALEN); | |
999 | } | |
1000 | ||
1001 | /** | |
1002 | * bnx2fc_get_src_mac - return the ethernet source address for an lport | |
1003 | * | |
1004 | * @lport: libfc port | |
1005 | */ | |
1006 | static u8 *bnx2fc_get_src_mac(struct fc_lport *lport) | |
1007 | { | |
1008 | struct fcoe_port *port; | |
1009 | ||
1010 | port = (struct fcoe_port *)lport_priv(lport); | |
1011 | return port->data_src_addr; | |
1012 | } | |
1013 | ||
1014 | /** | |
1015 | * bnx2fc_fip_send - send an Ethernet-encapsulated FIP frame. | |
1016 | * | |
1017 | * @fip: FCoE controller. | |
1018 | * @skb: FIP Packet. | |
1019 | */ | |
1020 | static void bnx2fc_fip_send(struct fcoe_ctlr *fip, struct sk_buff *skb) | |
1021 | { | |
1022 | skb->dev = bnx2fc_from_ctlr(fip)->netdev; | |
1023 | dev_queue_xmit(skb); | |
1024 | } | |
1025 | ||
1026 | static int bnx2fc_vport_create(struct fc_vport *vport, bool disabled) | |
1027 | { | |
1028 | struct Scsi_Host *shost = vport_to_shost(vport); | |
1029 | struct fc_lport *n_port = shost_priv(shost); | |
1030 | struct fcoe_port *port = lport_priv(n_port); | |
1031 | struct bnx2fc_hba *hba = port->priv; | |
1032 | struct net_device *netdev = hba->netdev; | |
1033 | struct fc_lport *vn_port; | |
1034 | ||
1035 | if (!test_bit(BNX2FC_FW_INIT_DONE, &hba->init_done)) { | |
1036 | printk(KERN_ERR PFX "vn ports cannot be created on" | |
1037 | "this hba\n"); | |
1038 | return -EIO; | |
1039 | } | |
1040 | mutex_lock(&bnx2fc_dev_lock); | |
1041 | vn_port = bnx2fc_if_create(hba, &vport->dev, 1); | |
1042 | mutex_unlock(&bnx2fc_dev_lock); | |
1043 | ||
1044 | if (IS_ERR(vn_port)) { | |
1045 | printk(KERN_ERR PFX "bnx2fc_vport_create (%s) failed\n", | |
1046 | netdev->name); | |
1047 | return -EIO; | |
1048 | } | |
1049 | ||
1050 | if (disabled) { | |
1051 | fc_vport_set_state(vport, FC_VPORT_DISABLED); | |
1052 | } else { | |
1053 | vn_port->boot_time = jiffies; | |
1054 | fc_lport_init(vn_port); | |
1055 | fc_fabric_login(vn_port); | |
1056 | fc_vport_setlink(vn_port); | |
1057 | } | |
1058 | return 0; | |
1059 | } | |
1060 | ||
1061 | static int bnx2fc_vport_destroy(struct fc_vport *vport) | |
1062 | { | |
1063 | struct Scsi_Host *shost = vport_to_shost(vport); | |
1064 | struct fc_lport *n_port = shost_priv(shost); | |
1065 | struct fc_lport *vn_port = vport->dd_data; | |
1066 | struct fcoe_port *port = lport_priv(vn_port); | |
1067 | ||
1068 | mutex_lock(&n_port->lp_mutex); | |
1069 | list_del(&vn_port->list); | |
1070 | mutex_unlock(&n_port->lp_mutex); | |
1071 | queue_work(bnx2fc_wq, &port->destroy_work); | |
1072 | return 0; | |
1073 | } | |
1074 | ||
1075 | static int bnx2fc_vport_disable(struct fc_vport *vport, bool disable) | |
1076 | { | |
1077 | struct fc_lport *lport = vport->dd_data; | |
1078 | ||
1079 | if (disable) { | |
1080 | fc_vport_set_state(vport, FC_VPORT_DISABLED); | |
1081 | fc_fabric_logoff(lport); | |
1082 | } else { | |
1083 | lport->boot_time = jiffies; | |
1084 | fc_fabric_login(lport); | |
1085 | fc_vport_setlink(lport); | |
1086 | } | |
1087 | return 0; | |
1088 | } | |
1089 | ||
1090 | ||
1091 | static int bnx2fc_netdev_setup(struct bnx2fc_hba *hba) | |
1092 | { | |
1093 | struct net_device *netdev = hba->netdev; | |
1094 | struct net_device *physdev = hba->phys_dev; | |
1095 | struct netdev_hw_addr *ha; | |
1096 | int sel_san_mac = 0; | |
1097 | ||
853e2bd2 BG |
1098 | /* setup Source MAC Address */ |
1099 | rcu_read_lock(); | |
1100 | for_each_dev_addr(physdev, ha) { | |
1101 | BNX2FC_MISC_DBG("net_config: ha->type = %d, fip_mac = ", | |
1102 | ha->type); | |
1103 | printk(KERN_INFO "%2x:%2x:%2x:%2x:%2x:%2x\n", ha->addr[0], | |
1104 | ha->addr[1], ha->addr[2], ha->addr[3], | |
1105 | ha->addr[4], ha->addr[5]); | |
1106 | ||
1107 | if ((ha->type == NETDEV_HW_ADDR_T_SAN) && | |
1108 | (is_valid_ether_addr(ha->addr))) { | |
1109 | memcpy(hba->ctlr.ctl_src_addr, ha->addr, ETH_ALEN); | |
1110 | sel_san_mac = 1; | |
1111 | BNX2FC_MISC_DBG("Found SAN MAC\n"); | |
1112 | } | |
1113 | } | |
1114 | rcu_read_unlock(); | |
1115 | ||
1116 | if (!sel_san_mac) | |
1117 | return -ENODEV; | |
1118 | ||
1119 | hba->fip_packet_type.func = bnx2fc_fip_recv; | |
1120 | hba->fip_packet_type.type = htons(ETH_P_FIP); | |
1121 | hba->fip_packet_type.dev = netdev; | |
1122 | dev_add_pack(&hba->fip_packet_type); | |
1123 | ||
1124 | hba->fcoe_packet_type.func = bnx2fc_rcv; | |
1125 | hba->fcoe_packet_type.type = __constant_htons(ETH_P_FCOE); | |
1126 | hba->fcoe_packet_type.dev = netdev; | |
1127 | dev_add_pack(&hba->fcoe_packet_type); | |
1128 | ||
1129 | return 0; | |
1130 | } | |
1131 | ||
1132 | static int bnx2fc_attach_transport(void) | |
1133 | { | |
1134 | bnx2fc_transport_template = | |
1135 | fc_attach_transport(&bnx2fc_transport_function); | |
1136 | ||
1137 | if (bnx2fc_transport_template == NULL) { | |
1138 | printk(KERN_ERR PFX "Failed to attach FC transport\n"); | |
1139 | return -ENODEV; | |
1140 | } | |
1141 | ||
1142 | bnx2fc_vport_xport_template = | |
1143 | fc_attach_transport(&bnx2fc_vport_xport_function); | |
1144 | if (bnx2fc_vport_xport_template == NULL) { | |
1145 | printk(KERN_ERR PFX | |
1146 | "Failed to attach FC transport for vport\n"); | |
1147 | fc_release_transport(bnx2fc_transport_template); | |
1148 | bnx2fc_transport_template = NULL; | |
1149 | return -ENODEV; | |
1150 | } | |
1151 | return 0; | |
1152 | } | |
1153 | static void bnx2fc_release_transport(void) | |
1154 | { | |
1155 | fc_release_transport(bnx2fc_transport_template); | |
1156 | fc_release_transport(bnx2fc_vport_xport_template); | |
1157 | bnx2fc_transport_template = NULL; | |
1158 | bnx2fc_vport_xport_template = NULL; | |
1159 | } | |
1160 | ||
1161 | static void bnx2fc_interface_release(struct kref *kref) | |
1162 | { | |
1163 | struct bnx2fc_hba *hba; | |
1164 | struct net_device *netdev; | |
1165 | struct net_device *phys_dev; | |
1166 | ||
1167 | hba = container_of(kref, struct bnx2fc_hba, kref); | |
1168 | BNX2FC_HBA_DBG(hba->ctlr.lp, "Interface is being released\n"); | |
1169 | ||
1170 | netdev = hba->netdev; | |
1171 | phys_dev = hba->phys_dev; | |
1172 | ||
1173 | /* tear-down FIP controller */ | |
1174 | if (test_and_clear_bit(BNX2FC_CTLR_INIT_DONE, &hba->init_done)) | |
1175 | fcoe_ctlr_destroy(&hba->ctlr); | |
1176 | ||
1177 | /* Free the command manager */ | |
1178 | if (hba->cmd_mgr) { | |
1179 | bnx2fc_cmd_mgr_free(hba->cmd_mgr); | |
1180 | hba->cmd_mgr = NULL; | |
1181 | } | |
1182 | dev_put(netdev); | |
1183 | module_put(THIS_MODULE); | |
1184 | } | |
1185 | ||
1186 | static inline void bnx2fc_interface_get(struct bnx2fc_hba *hba) | |
1187 | { | |
1188 | kref_get(&hba->kref); | |
1189 | } | |
1190 | ||
1191 | static inline void bnx2fc_interface_put(struct bnx2fc_hba *hba) | |
1192 | { | |
1193 | kref_put(&hba->kref, bnx2fc_interface_release); | |
1194 | } | |
1195 | static void bnx2fc_interface_destroy(struct bnx2fc_hba *hba) | |
1196 | { | |
1197 | bnx2fc_unbind_pcidev(hba); | |
1198 | kfree(hba); | |
1199 | } | |
1200 | ||
1201 | /** | |
1202 | * bnx2fc_interface_create - create a new fcoe instance | |
1203 | * | |
1204 | * @cnic: pointer to cnic device | |
1205 | * | |
1206 | * Creates a new FCoE instance on the given device which include allocating | |
1207 | * hba structure, scsi_host and lport structures. | |
1208 | */ | |
1209 | static struct bnx2fc_hba *bnx2fc_interface_create(struct cnic_dev *cnic) | |
1210 | { | |
1211 | struct bnx2fc_hba *hba; | |
1212 | int rc; | |
1213 | ||
1214 | hba = kzalloc(sizeof(*hba), GFP_KERNEL); | |
1215 | if (!hba) { | |
1216 | printk(KERN_ERR PFX "Unable to allocate hba structure\n"); | |
1217 | return NULL; | |
1218 | } | |
1219 | spin_lock_init(&hba->hba_lock); | |
1220 | mutex_init(&hba->hba_mutex); | |
1221 | ||
1222 | hba->cnic = cnic; | |
1223 | rc = bnx2fc_bind_pcidev(hba); | |
1224 | if (rc) | |
1225 | goto bind_err; | |
1226 | hba->phys_dev = cnic->netdev; | |
1227 | /* will get overwritten after we do vlan discovery */ | |
1228 | hba->netdev = hba->phys_dev; | |
1229 | ||
1230 | init_waitqueue_head(&hba->shutdown_wait); | |
1231 | init_waitqueue_head(&hba->destroy_wait); | |
1232 | ||
1233 | return hba; | |
1234 | bind_err: | |
1235 | printk(KERN_ERR PFX "create_interface: bind error\n"); | |
1236 | kfree(hba); | |
1237 | return NULL; | |
1238 | } | |
1239 | ||
1240 | static int bnx2fc_interface_setup(struct bnx2fc_hba *hba, | |
1241 | enum fip_state fip_mode) | |
1242 | { | |
1243 | int rc = 0; | |
1244 | struct net_device *netdev = hba->netdev; | |
1245 | struct fcoe_ctlr *fip = &hba->ctlr; | |
1246 | ||
1247 | dev_hold(netdev); | |
1248 | kref_init(&hba->kref); | |
1249 | ||
1250 | hba->flags = 0; | |
1251 | ||
1252 | /* Initialize FIP */ | |
1253 | memset(fip, 0, sizeof(*fip)); | |
1254 | fcoe_ctlr_init(fip, fip_mode); | |
1255 | hba->ctlr.send = bnx2fc_fip_send; | |
1256 | hba->ctlr.update_mac = bnx2fc_update_src_mac; | |
1257 | hba->ctlr.get_src_addr = bnx2fc_get_src_mac; | |
1258 | set_bit(BNX2FC_CTLR_INIT_DONE, &hba->init_done); | |
1259 | ||
1260 | rc = bnx2fc_netdev_setup(hba); | |
1261 | if (rc) | |
1262 | goto setup_err; | |
1263 | ||
1264 | hba->next_conn_id = 0; | |
1265 | ||
1266 | memset(hba->tgt_ofld_list, 0, sizeof(hba->tgt_ofld_list)); | |
1267 | hba->num_ofld_sess = 0; | |
1268 | ||
1269 | return 0; | |
1270 | ||
1271 | setup_err: | |
1272 | fcoe_ctlr_destroy(&hba->ctlr); | |
1273 | dev_put(netdev); | |
1274 | bnx2fc_interface_put(hba); | |
1275 | return rc; | |
1276 | } | |
1277 | ||
1278 | /** | |
1279 | * bnx2fc_if_create - Create FCoE instance on a given interface | |
1280 | * | |
1281 | * @hba: FCoE interface to create a local port on | |
1282 | * @parent: Device pointer to be the parent in sysfs for the SCSI host | |
1283 | * @npiv: Indicates if the port is vport or not | |
1284 | * | |
1285 | * Creates a fc_lport instance and a Scsi_Host instance and configure them. | |
1286 | * | |
1287 | * Returns: Allocated fc_lport or an error pointer | |
1288 | */ | |
1289 | static struct fc_lport *bnx2fc_if_create(struct bnx2fc_hba *hba, | |
1290 | struct device *parent, int npiv) | |
1291 | { | |
1292 | struct fc_lport *lport = NULL; | |
1293 | struct fcoe_port *port; | |
1294 | struct Scsi_Host *shost; | |
1295 | struct fc_vport *vport = dev_to_vport(parent); | |
1296 | int rc = 0; | |
1297 | ||
1298 | /* Allocate Scsi_Host structure */ | |
1299 | if (!npiv) { | |
1300 | lport = libfc_host_alloc(&bnx2fc_shost_template, | |
1301 | sizeof(struct fcoe_port)); | |
1302 | } else { | |
1303 | lport = libfc_vport_create(vport, | |
1304 | sizeof(struct fcoe_port)); | |
1305 | } | |
1306 | ||
1307 | if (!lport) { | |
1308 | printk(KERN_ERR PFX "could not allocate scsi host structure\n"); | |
1309 | return NULL; | |
1310 | } | |
1311 | shost = lport->host; | |
1312 | port = lport_priv(lport); | |
1313 | port->lport = lport; | |
1314 | port->priv = hba; | |
1315 | INIT_WORK(&port->destroy_work, bnx2fc_destroy_work); | |
1316 | ||
1317 | /* Configure fcoe_port */ | |
1318 | rc = bnx2fc_lport_config(lport); | |
1319 | if (rc) | |
1320 | goto lp_config_err; | |
1321 | ||
1322 | if (npiv) { | |
1323 | vport = dev_to_vport(parent); | |
1324 | printk(KERN_ERR PFX "Setting vport names, 0x%llX 0x%llX\n", | |
1325 | vport->node_name, vport->port_name); | |
1326 | fc_set_wwnn(lport, vport->node_name); | |
1327 | fc_set_wwpn(lport, vport->port_name); | |
1328 | } | |
1329 | /* Configure netdev and networking properties of the lport */ | |
1330 | rc = bnx2fc_net_config(lport); | |
1331 | if (rc) { | |
1332 | printk(KERN_ERR PFX "Error on bnx2fc_net_config\n"); | |
1333 | goto lp_config_err; | |
1334 | } | |
1335 | ||
1336 | rc = bnx2fc_shost_config(lport, parent); | |
1337 | if (rc) { | |
1338 | printk(KERN_ERR PFX "Couldnt configure shost for %s\n", | |
1339 | hba->netdev->name); | |
1340 | goto lp_config_err; | |
1341 | } | |
1342 | ||
1343 | /* Initialize the libfc library */ | |
1344 | rc = bnx2fc_libfc_config(lport); | |
1345 | if (rc) { | |
1346 | printk(KERN_ERR PFX "Couldnt configure libfc\n"); | |
1347 | goto shost_err; | |
1348 | } | |
1349 | fc_host_port_type(lport->host) = FC_PORTTYPE_UNKNOWN; | |
1350 | ||
1351 | /* Allocate exchange manager */ | |
1352 | if (!npiv) { | |
1353 | rc = bnx2fc_em_config(lport); | |
1354 | if (rc) { | |
1355 | printk(KERN_ERR PFX "Error on bnx2fc_em_config\n"); | |
1356 | goto shost_err; | |
1357 | } | |
1358 | } | |
1359 | ||
1360 | bnx2fc_interface_get(hba); | |
1361 | return lport; | |
1362 | ||
1363 | shost_err: | |
1364 | scsi_remove_host(shost); | |
1365 | lp_config_err: | |
1366 | scsi_host_put(lport->host); | |
1367 | return NULL; | |
1368 | } | |
1369 | ||
1370 | static void bnx2fc_netdev_cleanup(struct bnx2fc_hba *hba) | |
1371 | { | |
1372 | /* Dont listen for Ethernet packets anymore */ | |
1373 | __dev_remove_pack(&hba->fcoe_packet_type); | |
1374 | __dev_remove_pack(&hba->fip_packet_type); | |
1375 | synchronize_net(); | |
1376 | } | |
1377 | ||
1378 | static void bnx2fc_if_destroy(struct fc_lport *lport) | |
1379 | { | |
1380 | struct fcoe_port *port = lport_priv(lport); | |
1381 | struct bnx2fc_hba *hba = port->priv; | |
1382 | ||
1383 | BNX2FC_HBA_DBG(hba->ctlr.lp, "ENTERED bnx2fc_if_destroy\n"); | |
1384 | /* Stop the transmit retry timer */ | |
1385 | del_timer_sync(&port->timer); | |
1386 | ||
1387 | /* Free existing transmit skbs */ | |
1388 | fcoe_clean_pending_queue(lport); | |
1389 | ||
1390 | bnx2fc_interface_put(hba); | |
1391 | ||
1392 | /* Free queued packets for the receive thread */ | |
1393 | bnx2fc_clean_rx_queue(lport); | |
1394 | ||
1395 | /* Detach from scsi-ml */ | |
1396 | fc_remove_host(lport->host); | |
1397 | scsi_remove_host(lport->host); | |
1398 | ||
1399 | /* | |
1400 | * Note that only the physical lport will have the exchange manager. | |
1401 | * for vports, this function is NOP | |
1402 | */ | |
1403 | fc_exch_mgr_free(lport); | |
1404 | ||
1405 | /* Free memory used by statistical counters */ | |
1406 | fc_lport_free_stats(lport); | |
1407 | ||
1408 | /* Release Scsi_Host */ | |
1409 | scsi_host_put(lport->host); | |
1410 | } | |
1411 | ||
1412 | /** | |
1413 | * bnx2fc_destroy - Destroy a bnx2fc FCoE interface | |
1414 | * | |
1415 | * @buffer: The name of the Ethernet interface to be destroyed | |
1416 | * @kp: The associated kernel parameter | |
1417 | * | |
1418 | * Called from sysfs. | |
1419 | * | |
1420 | * Returns: 0 for success | |
1421 | */ | |
1422 | static int bnx2fc_destroy(struct net_device *netdev) | |
1423 | { | |
1424 | struct bnx2fc_hba *hba = NULL; | |
1425 | struct net_device *phys_dev; | |
1426 | int rc = 0; | |
1427 | ||
6702ca1d | 1428 | rtnl_lock(); |
853e2bd2 BG |
1429 | |
1430 | mutex_lock(&bnx2fc_dev_lock); | |
1431 | #ifdef CONFIG_SCSI_BNX2X_FCOE_MODULE | |
1432 | if (THIS_MODULE->state != MODULE_STATE_LIVE) { | |
1433 | rc = -ENODEV; | |
1434 | goto netdev_err; | |
1435 | } | |
1436 | #endif | |
1437 | /* obtain physical netdev */ | |
1438 | if (netdev->priv_flags & IFF_802_1Q_VLAN) | |
1439 | phys_dev = vlan_dev_real_dev(netdev); | |
1440 | else { | |
1441 | printk(KERN_ERR PFX "Not a vlan device\n"); | |
1442 | rc = -ENODEV; | |
1443 | goto netdev_err; | |
1444 | } | |
1445 | ||
1446 | hba = bnx2fc_hba_lookup(phys_dev); | |
1447 | if (!hba || !hba->ctlr.lp) { | |
1448 | rc = -ENODEV; | |
1449 | printk(KERN_ERR PFX "bnx2fc_destroy: hba or lport not found\n"); | |
1450 | goto netdev_err; | |
1451 | } | |
1452 | ||
1453 | if (!test_bit(BNX2FC_CREATE_DONE, &hba->init_done)) { | |
1454 | printk(KERN_ERR PFX "bnx2fc_destroy: Create not called\n"); | |
1455 | goto netdev_err; | |
1456 | } | |
1457 | ||
1458 | bnx2fc_netdev_cleanup(hba); | |
1459 | ||
1460 | bnx2fc_stop(hba); | |
1461 | ||
1462 | bnx2fc_if_destroy(hba->ctlr.lp); | |
1463 | ||
1464 | destroy_workqueue(hba->timer_work_queue); | |
1465 | ||
1466 | if (test_bit(BNX2FC_FW_INIT_DONE, &hba->init_done)) | |
1467 | bnx2fc_fw_destroy(hba); | |
1468 | ||
1469 | clear_bit(BNX2FC_CREATE_DONE, &hba->init_done); | |
1470 | netdev_err: | |
1471 | mutex_unlock(&bnx2fc_dev_lock); | |
1472 | rtnl_unlock(); | |
1473 | return rc; | |
1474 | } | |
1475 | ||
1476 | static void bnx2fc_destroy_work(struct work_struct *work) | |
1477 | { | |
1478 | struct fcoe_port *port; | |
1479 | struct fc_lport *lport; | |
1480 | ||
1481 | port = container_of(work, struct fcoe_port, destroy_work); | |
1482 | lport = port->lport; | |
1483 | ||
1484 | BNX2FC_HBA_DBG(lport, "Entered bnx2fc_destroy_work\n"); | |
1485 | ||
1486 | bnx2fc_port_shutdown(lport); | |
1487 | rtnl_lock(); | |
1488 | mutex_lock(&bnx2fc_dev_lock); | |
1489 | bnx2fc_if_destroy(lport); | |
1490 | mutex_unlock(&bnx2fc_dev_lock); | |
1491 | rtnl_unlock(); | |
1492 | } | |
1493 | ||
1494 | static void bnx2fc_unbind_adapter_devices(struct bnx2fc_hba *hba) | |
1495 | { | |
1496 | bnx2fc_free_fw_resc(hba); | |
1497 | bnx2fc_free_task_ctx(hba); | |
1498 | } | |
1499 | ||
1500 | /** | |
1501 | * bnx2fc_bind_adapter_devices - binds bnx2fc adapter with the associated | |
1502 | * pci structure | |
1503 | * | |
1504 | * @hba: Adapter instance | |
1505 | */ | |
1506 | static int bnx2fc_bind_adapter_devices(struct bnx2fc_hba *hba) | |
1507 | { | |
1508 | if (bnx2fc_setup_task_ctx(hba)) | |
1509 | goto mem_err; | |
1510 | ||
1511 | if (bnx2fc_setup_fw_resc(hba)) | |
1512 | goto mem_err; | |
1513 | ||
1514 | return 0; | |
1515 | mem_err: | |
1516 | bnx2fc_unbind_adapter_devices(hba); | |
1517 | return -ENOMEM; | |
1518 | } | |
1519 | ||
1520 | static int bnx2fc_bind_pcidev(struct bnx2fc_hba *hba) | |
1521 | { | |
1522 | struct cnic_dev *cnic; | |
1523 | ||
1524 | if (!hba->cnic) { | |
1525 | printk(KERN_ERR PFX "cnic is NULL\n"); | |
1526 | return -ENODEV; | |
1527 | } | |
1528 | cnic = hba->cnic; | |
1529 | hba->pcidev = cnic->pcidev; | |
1530 | if (hba->pcidev) | |
1531 | pci_dev_get(hba->pcidev); | |
1532 | ||
1533 | return 0; | |
1534 | } | |
1535 | ||
1536 | static void bnx2fc_unbind_pcidev(struct bnx2fc_hba *hba) | |
1537 | { | |
1538 | if (hba->pcidev) | |
1539 | pci_dev_put(hba->pcidev); | |
1540 | hba->pcidev = NULL; | |
1541 | } | |
1542 | ||
1543 | ||
1544 | ||
1545 | /** | |
1546 | * bnx2fc_ulp_start - cnic callback to initialize & start adapter instance | |
1547 | * | |
1548 | * @handle: transport handle pointing to adapter struture | |
1549 | * | |
1550 | * This function maps adapter structure to pcidev structure and initiates | |
1551 | * firmware handshake to enable/initialize on-chip FCoE components. | |
1552 | * This bnx2fc - cnic interface api callback is used after following | |
1553 | * conditions are met - | |
1554 | * a) underlying network interface is up (marked by event NETDEV_UP | |
1555 | * from netdev | |
1556 | * b) bnx2fc adatper structure is registered. | |
1557 | */ | |
1558 | static void bnx2fc_ulp_start(void *handle) | |
1559 | { | |
1560 | struct bnx2fc_hba *hba = handle; | |
1561 | struct fc_lport *lport = hba->ctlr.lp; | |
1562 | ||
1563 | BNX2FC_MISC_DBG("Entered %s\n", __func__); | |
1564 | mutex_lock(&bnx2fc_dev_lock); | |
1565 | ||
1566 | if (test_bit(BNX2FC_FW_INIT_DONE, &hba->init_done)) | |
1567 | goto start_disc; | |
1568 | ||
1569 | if (test_bit(BNX2FC_CREATE_DONE, &hba->init_done)) | |
1570 | bnx2fc_fw_init(hba); | |
1571 | ||
1572 | start_disc: | |
1573 | mutex_unlock(&bnx2fc_dev_lock); | |
1574 | ||
1575 | BNX2FC_MISC_DBG("bnx2fc started.\n"); | |
1576 | ||
1577 | /* Kick off Fabric discovery*/ | |
1578 | if (test_bit(BNX2FC_CREATE_DONE, &hba->init_done)) { | |
1579 | printk(KERN_ERR PFX "ulp_init: start discovery\n"); | |
1580 | lport->tt.frame_send = bnx2fc_xmit; | |
1581 | bnx2fc_start_disc(hba); | |
1582 | } | |
1583 | } | |
1584 | ||
1585 | static void bnx2fc_port_shutdown(struct fc_lport *lport) | |
1586 | { | |
1587 | BNX2FC_MISC_DBG("Entered %s\n", __func__); | |
1588 | fc_fabric_logoff(lport); | |
1589 | fc_lport_destroy(lport); | |
1590 | } | |
1591 | ||
1592 | static void bnx2fc_stop(struct bnx2fc_hba *hba) | |
1593 | { | |
1594 | struct fc_lport *lport; | |
1595 | struct fc_lport *vport; | |
1596 | ||
1597 | BNX2FC_MISC_DBG("ENTERED %s - init_done = %ld\n", __func__, | |
1598 | hba->init_done); | |
1599 | if (test_bit(BNX2FC_FW_INIT_DONE, &hba->init_done) && | |
1600 | test_bit(BNX2FC_CREATE_DONE, &hba->init_done)) { | |
1601 | lport = hba->ctlr.lp; | |
1602 | bnx2fc_port_shutdown(lport); | |
1603 | BNX2FC_HBA_DBG(lport, "bnx2fc_stop: waiting for %d " | |
1604 | "offloaded sessions\n", | |
1605 | hba->num_ofld_sess); | |
1606 | wait_event_interruptible(hba->shutdown_wait, | |
1607 | (hba->num_ofld_sess == 0)); | |
1608 | mutex_lock(&lport->lp_mutex); | |
1609 | list_for_each_entry(vport, &lport->vports, list) | |
1610 | fc_host_port_type(vport->host) = FC_PORTTYPE_UNKNOWN; | |
1611 | mutex_unlock(&lport->lp_mutex); | |
1612 | fc_host_port_type(lport->host) = FC_PORTTYPE_UNKNOWN; | |
1613 | fcoe_ctlr_link_down(&hba->ctlr); | |
1614 | fcoe_clean_pending_queue(lport); | |
1615 | ||
1616 | mutex_lock(&hba->hba_mutex); | |
1617 | clear_bit(ADAPTER_STATE_UP, &hba->adapter_state); | |
1618 | clear_bit(ADAPTER_STATE_GOING_DOWN, &hba->adapter_state); | |
1619 | ||
1620 | clear_bit(ADAPTER_STATE_READY, &hba->adapter_state); | |
1621 | mutex_unlock(&hba->hba_mutex); | |
1622 | } | |
1623 | } | |
1624 | ||
1625 | static int bnx2fc_fw_init(struct bnx2fc_hba *hba) | |
1626 | { | |
1627 | #define BNX2FC_INIT_POLL_TIME (1000 / HZ) | |
1628 | int rc = -1; | |
1629 | int i = HZ; | |
1630 | ||
1631 | rc = bnx2fc_bind_adapter_devices(hba); | |
1632 | if (rc) { | |
1633 | printk(KERN_ALERT PFX | |
1634 | "bnx2fc_bind_adapter_devices failed - rc = %d\n", rc); | |
1635 | goto err_out; | |
1636 | } | |
1637 | ||
1638 | rc = bnx2fc_send_fw_fcoe_init_msg(hba); | |
1639 | if (rc) { | |
1640 | printk(KERN_ALERT PFX | |
1641 | "bnx2fc_send_fw_fcoe_init_msg failed - rc = %d\n", rc); | |
1642 | goto err_unbind; | |
1643 | } | |
1644 | ||
1645 | /* | |
1646 | * Wait until the adapter init message is complete, and adapter | |
1647 | * state is UP. | |
1648 | */ | |
1649 | while (!test_bit(ADAPTER_STATE_UP, &hba->adapter_state) && i--) | |
1650 | msleep(BNX2FC_INIT_POLL_TIME); | |
1651 | ||
1652 | if (!test_bit(ADAPTER_STATE_UP, &hba->adapter_state)) { | |
1653 | printk(KERN_ERR PFX "bnx2fc_start: %s failed to initialize. " | |
1654 | "Ignoring...\n", | |
1655 | hba->cnic->netdev->name); | |
1656 | rc = -1; | |
1657 | goto err_unbind; | |
1658 | } | |
1659 | ||
1660 | ||
1661 | /* Mark HBA to indicate that the FW INIT is done */ | |
1662 | set_bit(BNX2FC_FW_INIT_DONE, &hba->init_done); | |
1663 | return 0; | |
1664 | ||
1665 | err_unbind: | |
1666 | bnx2fc_unbind_adapter_devices(hba); | |
1667 | err_out: | |
1668 | return rc; | |
1669 | } | |
1670 | ||
1671 | static void bnx2fc_fw_destroy(struct bnx2fc_hba *hba) | |
1672 | { | |
1673 | if (test_and_clear_bit(BNX2FC_FW_INIT_DONE, &hba->init_done)) { | |
1674 | if (bnx2fc_send_fw_fcoe_destroy_msg(hba) == 0) { | |
1675 | init_timer(&hba->destroy_timer); | |
1676 | hba->destroy_timer.expires = BNX2FC_FW_TIMEOUT + | |
1677 | jiffies; | |
1678 | hba->destroy_timer.function = bnx2fc_destroy_timer; | |
1679 | hba->destroy_timer.data = (unsigned long)hba; | |
1680 | add_timer(&hba->destroy_timer); | |
1681 | wait_event_interruptible(hba->destroy_wait, | |
1682 | (hba->flags & | |
1683 | BNX2FC_FLAG_DESTROY_CMPL)); | |
1684 | /* This should never happen */ | |
1685 | if (signal_pending(current)) | |
1686 | flush_signals(current); | |
1687 | ||
1688 | del_timer_sync(&hba->destroy_timer); | |
1689 | } | |
1690 | bnx2fc_unbind_adapter_devices(hba); | |
1691 | } | |
1692 | } | |
1693 | ||
1694 | /** | |
1695 | * bnx2fc_ulp_stop - cnic callback to shutdown adapter instance | |
1696 | * | |
1697 | * @handle: transport handle pointing to adapter structure | |
1698 | * | |
1699 | * Driver checks if adapter is already in shutdown mode, if not start | |
1700 | * the shutdown process. | |
1701 | */ | |
1702 | static void bnx2fc_ulp_stop(void *handle) | |
1703 | { | |
1704 | struct bnx2fc_hba *hba = (struct bnx2fc_hba *)handle; | |
1705 | ||
1706 | printk(KERN_ERR "ULP_STOP\n"); | |
1707 | ||
1708 | mutex_lock(&bnx2fc_dev_lock); | |
1709 | bnx2fc_stop(hba); | |
1710 | bnx2fc_fw_destroy(hba); | |
1711 | mutex_unlock(&bnx2fc_dev_lock); | |
1712 | } | |
1713 | ||
1714 | static void bnx2fc_start_disc(struct bnx2fc_hba *hba) | |
1715 | { | |
1716 | struct fc_lport *lport; | |
1717 | int wait_cnt = 0; | |
1718 | ||
1719 | BNX2FC_MISC_DBG("Entered %s\n", __func__); | |
1720 | /* Kick off FIP/FLOGI */ | |
1721 | if (!test_bit(BNX2FC_FW_INIT_DONE, &hba->init_done)) { | |
1722 | printk(KERN_ERR PFX "Init not done yet\n"); | |
1723 | return; | |
1724 | } | |
1725 | ||
1726 | lport = hba->ctlr.lp; | |
1727 | BNX2FC_HBA_DBG(lport, "calling fc_fabric_login\n"); | |
1728 | ||
1729 | if (!bnx2fc_link_ok(lport)) { | |
1730 | BNX2FC_HBA_DBG(lport, "ctlr_link_up\n"); | |
1731 | fcoe_ctlr_link_up(&hba->ctlr); | |
1732 | fc_host_port_type(lport->host) = FC_PORTTYPE_NPORT; | |
1733 | set_bit(ADAPTER_STATE_READY, &hba->adapter_state); | |
1734 | } | |
1735 | ||
1736 | /* wait for the FCF to be selected before issuing FLOGI */ | |
1737 | while (!hba->ctlr.sel_fcf) { | |
1738 | msleep(250); | |
1739 | /* give up after 3 secs */ | |
1740 | if (++wait_cnt > 12) | |
1741 | break; | |
1742 | } | |
1743 | fc_lport_init(lport); | |
1744 | fc_fabric_login(lport); | |
1745 | } | |
1746 | ||
1747 | ||
1748 | /** | |
1749 | * bnx2fc_ulp_init - Initialize an adapter instance | |
1750 | * | |
1751 | * @dev : cnic device handle | |
1752 | * Called from cnic_register_driver() context to initialize all | |
1753 | * enumerated cnic devices. This routine allocates adapter structure | |
1754 | * and other device specific resources. | |
1755 | */ | |
1756 | static void bnx2fc_ulp_init(struct cnic_dev *dev) | |
1757 | { | |
1758 | struct bnx2fc_hba *hba; | |
1759 | int rc = 0; | |
1760 | ||
1761 | BNX2FC_MISC_DBG("Entered %s\n", __func__); | |
1762 | /* bnx2fc works only when bnx2x is loaded */ | |
1763 | if (!test_bit(CNIC_F_BNX2X_CLASS, &dev->flags)) { | |
1764 | printk(KERN_ERR PFX "bnx2fc FCoE not supported on %s," | |
1765 | " flags: %lx\n", | |
1766 | dev->netdev->name, dev->flags); | |
1767 | return; | |
1768 | } | |
1769 | ||
1770 | /* Configure FCoE interface */ | |
1771 | hba = bnx2fc_interface_create(dev); | |
1772 | if (!hba) { | |
1773 | printk(KERN_ERR PFX "hba initialization failed\n"); | |
1774 | return; | |
1775 | } | |
1776 | ||
1777 | /* Add HBA to the adapter list */ | |
1778 | mutex_lock(&bnx2fc_dev_lock); | |
1779 | list_add_tail(&hba->link, &adapter_list); | |
1780 | adapter_count++; | |
1781 | mutex_unlock(&bnx2fc_dev_lock); | |
1782 | ||
1783 | clear_bit(BNX2FC_CNIC_REGISTERED, &hba->reg_with_cnic); | |
1784 | rc = dev->register_device(dev, CNIC_ULP_FCOE, | |
1785 | (void *) hba); | |
1786 | if (rc) | |
1787 | printk(KERN_ALERT PFX "register_device failed, rc = %d\n", rc); | |
1788 | else | |
1789 | set_bit(BNX2FC_CNIC_REGISTERED, &hba->reg_with_cnic); | |
1790 | } | |
1791 | ||
1792 | ||
1793 | static int bnx2fc_disable(struct net_device *netdev) | |
1794 | { | |
1795 | struct bnx2fc_hba *hba; | |
1796 | struct net_device *phys_dev; | |
1797 | struct ethtool_drvinfo drvinfo; | |
1798 | int rc = 0; | |
1799 | ||
6702ca1d | 1800 | rtnl_lock(); |
853e2bd2 BG |
1801 | |
1802 | mutex_lock(&bnx2fc_dev_lock); | |
1803 | ||
1804 | if (THIS_MODULE->state != MODULE_STATE_LIVE) { | |
1805 | rc = -ENODEV; | |
1806 | goto nodev; | |
1807 | } | |
1808 | ||
1809 | /* obtain physical netdev */ | |
1810 | if (netdev->priv_flags & IFF_802_1Q_VLAN) | |
1811 | phys_dev = vlan_dev_real_dev(netdev); | |
1812 | else { | |
1813 | printk(KERN_ERR PFX "Not a vlan device\n"); | |
1814 | rc = -ENODEV; | |
1815 | goto nodev; | |
1816 | } | |
1817 | ||
1818 | /* verify if the physical device is a netxtreme2 device */ | |
1819 | if (phys_dev->ethtool_ops && phys_dev->ethtool_ops->get_drvinfo) { | |
1820 | memset(&drvinfo, 0, sizeof(drvinfo)); | |
1821 | phys_dev->ethtool_ops->get_drvinfo(phys_dev, &drvinfo); | |
1822 | if (strcmp(drvinfo.driver, "bnx2x")) { | |
1823 | printk(KERN_ERR PFX "Not a netxtreme2 device\n"); | |
1824 | rc = -ENODEV; | |
1825 | goto nodev; | |
1826 | } | |
1827 | } else { | |
1828 | printk(KERN_ERR PFX "unable to obtain drv_info\n"); | |
1829 | rc = -ENODEV; | |
1830 | goto nodev; | |
1831 | } | |
1832 | ||
1833 | printk(KERN_ERR PFX "phys_dev is netxtreme2 device\n"); | |
1834 | ||
1835 | /* obtain hba and initialize rest of the structure */ | |
1836 | hba = bnx2fc_hba_lookup(phys_dev); | |
1837 | if (!hba || !hba->ctlr.lp) { | |
1838 | rc = -ENODEV; | |
1839 | printk(KERN_ERR PFX "bnx2fc_disable: hba or lport not found\n"); | |
1840 | } else { | |
1841 | fcoe_ctlr_link_down(&hba->ctlr); | |
1842 | fcoe_clean_pending_queue(hba->ctlr.lp); | |
1843 | } | |
1844 | ||
1845 | nodev: | |
1846 | mutex_unlock(&bnx2fc_dev_lock); | |
1847 | rtnl_unlock(); | |
1848 | return rc; | |
1849 | } | |
1850 | ||
1851 | ||
1852 | static int bnx2fc_enable(struct net_device *netdev) | |
1853 | { | |
1854 | struct bnx2fc_hba *hba; | |
1855 | struct net_device *phys_dev; | |
1856 | struct ethtool_drvinfo drvinfo; | |
1857 | int rc = 0; | |
1858 | ||
6702ca1d | 1859 | rtnl_lock(); |
853e2bd2 BG |
1860 | |
1861 | BNX2FC_MISC_DBG("Entered %s\n", __func__); | |
1862 | mutex_lock(&bnx2fc_dev_lock); | |
1863 | ||
1864 | if (THIS_MODULE->state != MODULE_STATE_LIVE) { | |
1865 | rc = -ENODEV; | |
1866 | goto nodev; | |
1867 | } | |
1868 | ||
1869 | /* obtain physical netdev */ | |
1870 | if (netdev->priv_flags & IFF_802_1Q_VLAN) | |
1871 | phys_dev = vlan_dev_real_dev(netdev); | |
1872 | else { | |
1873 | printk(KERN_ERR PFX "Not a vlan device\n"); | |
1874 | rc = -ENODEV; | |
1875 | goto nodev; | |
1876 | } | |
1877 | /* verify if the physical device is a netxtreme2 device */ | |
1878 | if (phys_dev->ethtool_ops && phys_dev->ethtool_ops->get_drvinfo) { | |
1879 | memset(&drvinfo, 0, sizeof(drvinfo)); | |
1880 | phys_dev->ethtool_ops->get_drvinfo(phys_dev, &drvinfo); | |
1881 | if (strcmp(drvinfo.driver, "bnx2x")) { | |
1882 | printk(KERN_ERR PFX "Not a netxtreme2 device\n"); | |
1883 | rc = -ENODEV; | |
1884 | goto nodev; | |
1885 | } | |
1886 | } else { | |
1887 | printk(KERN_ERR PFX "unable to obtain drv_info\n"); | |
1888 | rc = -ENODEV; | |
1889 | goto nodev; | |
1890 | } | |
1891 | ||
1892 | /* obtain hba and initialize rest of the structure */ | |
1893 | hba = bnx2fc_hba_lookup(phys_dev); | |
1894 | if (!hba || !hba->ctlr.lp) { | |
1895 | rc = -ENODEV; | |
1896 | printk(KERN_ERR PFX "bnx2fc_enable: hba or lport not found\n"); | |
1897 | } else if (!bnx2fc_link_ok(hba->ctlr.lp)) | |
1898 | fcoe_ctlr_link_up(&hba->ctlr); | |
1899 | ||
1900 | nodev: | |
1901 | mutex_unlock(&bnx2fc_dev_lock); | |
1902 | rtnl_unlock(); | |
1903 | return rc; | |
1904 | } | |
1905 | ||
1906 | /** | |
1907 | * bnx2fc_create - Create bnx2fc FCoE interface | |
1908 | * | |
1909 | * @buffer: The name of Ethernet interface to create on | |
1910 | * @kp: The associated kernel param | |
1911 | * | |
1912 | * Called from sysfs. | |
1913 | * | |
1914 | * Returns: 0 for success | |
1915 | */ | |
1916 | static int bnx2fc_create(struct net_device *netdev, enum fip_state fip_mode) | |
1917 | { | |
1918 | struct bnx2fc_hba *hba; | |
1919 | struct net_device *phys_dev; | |
1920 | struct fc_lport *lport; | |
1921 | struct ethtool_drvinfo drvinfo; | |
1922 | int rc = 0; | |
1923 | int vlan_id; | |
1924 | ||
1925 | BNX2FC_MISC_DBG("Entered bnx2fc_create\n"); | |
1926 | if (fip_mode != FIP_MODE_FABRIC) { | |
1927 | printk(KERN_ERR "fip mode not FABRIC\n"); | |
1928 | return -EIO; | |
1929 | } | |
1930 | ||
6702ca1d NS |
1931 | rtnl_lock(); |
1932 | ||
853e2bd2 BG |
1933 | mutex_lock(&bnx2fc_dev_lock); |
1934 | ||
1935 | #ifdef CONFIG_SCSI_BNX2X_FCOE_MODULE | |
1936 | if (THIS_MODULE->state != MODULE_STATE_LIVE) { | |
1937 | rc = -ENODEV; | |
1938 | goto mod_err; | |
1939 | } | |
1940 | #endif | |
1941 | ||
1942 | if (!try_module_get(THIS_MODULE)) { | |
1943 | rc = -EINVAL; | |
1944 | goto mod_err; | |
1945 | } | |
1946 | ||
1947 | /* obtain physical netdev */ | |
1948 | if (netdev->priv_flags & IFF_802_1Q_VLAN) { | |
1949 | phys_dev = vlan_dev_real_dev(netdev); | |
1950 | vlan_id = vlan_dev_vlan_id(netdev); | |
1951 | } else { | |
1952 | printk(KERN_ERR PFX "Not a vlan device\n"); | |
1953 | rc = -EINVAL; | |
1954 | goto netdev_err; | |
1955 | } | |
1956 | /* verify if the physical device is a netxtreme2 device */ | |
1957 | if (phys_dev->ethtool_ops && phys_dev->ethtool_ops->get_drvinfo) { | |
1958 | memset(&drvinfo, 0, sizeof(drvinfo)); | |
1959 | phys_dev->ethtool_ops->get_drvinfo(phys_dev, &drvinfo); | |
1960 | if (strcmp(drvinfo.driver, "bnx2x")) { | |
1961 | printk(KERN_ERR PFX "Not a netxtreme2 device\n"); | |
1962 | rc = -EINVAL; | |
1963 | goto netdev_err; | |
1964 | } | |
1965 | } else { | |
1966 | printk(KERN_ERR PFX "unable to obtain drv_info\n"); | |
1967 | rc = -EINVAL; | |
1968 | goto netdev_err; | |
1969 | } | |
1970 | ||
1971 | /* obtain hba and initialize rest of the structure */ | |
1972 | hba = bnx2fc_hba_lookup(phys_dev); | |
1973 | if (!hba) { | |
1974 | rc = -ENODEV; | |
1975 | printk(KERN_ERR PFX "bnx2fc_create: hba not found\n"); | |
1976 | goto netdev_err; | |
1977 | } | |
1978 | ||
1979 | if (!test_bit(BNX2FC_FW_INIT_DONE, &hba->init_done)) { | |
1980 | rc = bnx2fc_fw_init(hba); | |
1981 | if (rc) | |
1982 | goto netdev_err; | |
1983 | } | |
1984 | ||
1985 | if (test_bit(BNX2FC_CREATE_DONE, &hba->init_done)) { | |
1986 | rc = -EEXIST; | |
1987 | goto netdev_err; | |
1988 | } | |
1989 | ||
1990 | /* update netdev with vlan netdev */ | |
1991 | hba->netdev = netdev; | |
1992 | hba->vlan_id = vlan_id; | |
1993 | hba->vlan_enabled = 1; | |
1994 | ||
1995 | rc = bnx2fc_interface_setup(hba, fip_mode); | |
1996 | if (rc) { | |
1997 | printk(KERN_ERR PFX "bnx2fc_interface_setup failed\n"); | |
1998 | goto ifput_err; | |
1999 | } | |
2000 | ||
2001 | hba->timer_work_queue = | |
2002 | create_singlethread_workqueue("bnx2fc_timer_wq"); | |
2003 | if (!hba->timer_work_queue) { | |
2004 | printk(KERN_ERR PFX "ulp_init could not create timer_wq\n"); | |
2005 | rc = -EINVAL; | |
2006 | goto ifput_err; | |
2007 | } | |
2008 | ||
2009 | lport = bnx2fc_if_create(hba, &hba->pcidev->dev, 0); | |
2010 | if (!lport) { | |
2011 | printk(KERN_ERR PFX "Failed to create interface (%s)\n", | |
2012 | netdev->name); | |
2013 | bnx2fc_netdev_cleanup(hba); | |
2014 | rc = -EINVAL; | |
2015 | goto if_create_err; | |
2016 | } | |
2017 | ||
2018 | lport->boot_time = jiffies; | |
2019 | ||
2020 | /* Make this master N_port */ | |
2021 | hba->ctlr.lp = lport; | |
2022 | ||
2023 | set_bit(BNX2FC_CREATE_DONE, &hba->init_done); | |
2024 | printk(KERN_ERR PFX "create: START DISC\n"); | |
2025 | bnx2fc_start_disc(hba); | |
2026 | /* | |
2027 | * Release from kref_init in bnx2fc_interface_setup, on success | |
2028 | * lport should be holding a reference taken in bnx2fc_if_create | |
2029 | */ | |
2030 | bnx2fc_interface_put(hba); | |
2031 | /* put netdev that was held while calling dev_get_by_name */ | |
2032 | mutex_unlock(&bnx2fc_dev_lock); | |
2033 | rtnl_unlock(); | |
2034 | return 0; | |
2035 | ||
2036 | if_create_err: | |
2037 | destroy_workqueue(hba->timer_work_queue); | |
2038 | ifput_err: | |
2039 | bnx2fc_interface_put(hba); | |
2040 | netdev_err: | |
2041 | module_put(THIS_MODULE); | |
2042 | mod_err: | |
2043 | mutex_unlock(&bnx2fc_dev_lock); | |
2044 | rtnl_unlock(); | |
2045 | return rc; | |
2046 | } | |
2047 | ||
2048 | /** | |
2049 | * bnx2fc_find_hba_for_cnic - maps cnic instance to bnx2fc adapter instance | |
2050 | * | |
2051 | * @cnic: Pointer to cnic device instance | |
2052 | * | |
2053 | **/ | |
2054 | static struct bnx2fc_hba *bnx2fc_find_hba_for_cnic(struct cnic_dev *cnic) | |
2055 | { | |
2056 | struct list_head *list; | |
2057 | struct list_head *temp; | |
2058 | struct bnx2fc_hba *hba; | |
2059 | ||
2060 | /* Called with bnx2fc_dev_lock held */ | |
2061 | list_for_each_safe(list, temp, &adapter_list) { | |
2062 | hba = (struct bnx2fc_hba *)list; | |
2063 | if (hba->cnic == cnic) | |
2064 | return hba; | |
2065 | } | |
2066 | return NULL; | |
2067 | } | |
2068 | ||
2069 | static struct bnx2fc_hba *bnx2fc_hba_lookup(struct net_device *phys_dev) | |
2070 | { | |
2071 | struct list_head *list; | |
2072 | struct list_head *temp; | |
2073 | struct bnx2fc_hba *hba; | |
2074 | ||
2075 | /* Called with bnx2fc_dev_lock held */ | |
2076 | list_for_each_safe(list, temp, &adapter_list) { | |
2077 | hba = (struct bnx2fc_hba *)list; | |
2078 | if (hba->phys_dev == phys_dev) | |
2079 | return hba; | |
2080 | } | |
2081 | printk(KERN_ERR PFX "hba_lookup: hba NULL\n"); | |
2082 | return NULL; | |
2083 | } | |
2084 | ||
2085 | /** | |
2086 | * bnx2fc_ulp_exit - shuts down adapter instance and frees all resources | |
2087 | * | |
2088 | * @dev cnic device handle | |
2089 | */ | |
2090 | static void bnx2fc_ulp_exit(struct cnic_dev *dev) | |
2091 | { | |
2092 | struct bnx2fc_hba *hba; | |
2093 | ||
2094 | BNX2FC_MISC_DBG("Entered bnx2fc_ulp_exit\n"); | |
2095 | ||
2096 | if (!test_bit(CNIC_F_BNX2X_CLASS, &dev->flags)) { | |
2097 | printk(KERN_ERR PFX "bnx2fc port check: %s, flags: %lx\n", | |
2098 | dev->netdev->name, dev->flags); | |
2099 | return; | |
2100 | } | |
2101 | ||
2102 | mutex_lock(&bnx2fc_dev_lock); | |
2103 | hba = bnx2fc_find_hba_for_cnic(dev); | |
2104 | if (!hba) { | |
2105 | printk(KERN_ERR PFX "bnx2fc_ulp_exit: hba not found, dev 0%p\n", | |
2106 | dev); | |
2107 | mutex_unlock(&bnx2fc_dev_lock); | |
2108 | return; | |
2109 | } | |
2110 | ||
2111 | list_del_init(&hba->link); | |
2112 | adapter_count--; | |
2113 | ||
2114 | if (test_bit(BNX2FC_CREATE_DONE, &hba->init_done)) { | |
2115 | /* destroy not called yet, move to quiesced list */ | |
2116 | bnx2fc_netdev_cleanup(hba); | |
2117 | bnx2fc_if_destroy(hba->ctlr.lp); | |
2118 | } | |
2119 | mutex_unlock(&bnx2fc_dev_lock); | |
2120 | ||
2121 | bnx2fc_ulp_stop(hba); | |
2122 | /* unregister cnic device */ | |
2123 | if (test_and_clear_bit(BNX2FC_CNIC_REGISTERED, &hba->reg_with_cnic)) | |
2124 | hba->cnic->unregister_device(hba->cnic, CNIC_ULP_FCOE); | |
2125 | bnx2fc_interface_destroy(hba); | |
2126 | } | |
2127 | ||
2128 | /** | |
2129 | * bnx2fc_fcoe_reset - Resets the fcoe | |
2130 | * | |
2131 | * @shost: shost the reset is from | |
2132 | * | |
2133 | * Returns: always 0 | |
2134 | */ | |
2135 | static int bnx2fc_fcoe_reset(struct Scsi_Host *shost) | |
2136 | { | |
2137 | struct fc_lport *lport = shost_priv(shost); | |
2138 | fc_lport_reset(lport); | |
2139 | return 0; | |
2140 | } | |
2141 | ||
2142 | ||
2143 | static bool bnx2fc_match(struct net_device *netdev) | |
2144 | { | |
2145 | mutex_lock(&bnx2fc_dev_lock); | |
2146 | if (netdev->priv_flags & IFF_802_1Q_VLAN) { | |
2147 | struct net_device *phys_dev = vlan_dev_real_dev(netdev); | |
2148 | ||
2149 | if (bnx2fc_hba_lookup(phys_dev)) { | |
2150 | mutex_unlock(&bnx2fc_dev_lock); | |
2151 | return true; | |
2152 | } | |
2153 | } | |
2154 | mutex_unlock(&bnx2fc_dev_lock); | |
2155 | return false; | |
2156 | } | |
2157 | ||
2158 | ||
2159 | static struct fcoe_transport bnx2fc_transport = { | |
2160 | .name = {"bnx2fc"}, | |
2161 | .attached = false, | |
2162 | .list = LIST_HEAD_INIT(bnx2fc_transport.list), | |
2163 | .match = bnx2fc_match, | |
2164 | .create = bnx2fc_create, | |
2165 | .destroy = bnx2fc_destroy, | |
2166 | .enable = bnx2fc_enable, | |
2167 | .disable = bnx2fc_disable, | |
2168 | }; | |
2169 | ||
2170 | /** | |
2171 | * bnx2fc_percpu_thread_create - Create a receive thread for an | |
2172 | * online CPU | |
2173 | * | |
2174 | * @cpu: cpu index for the online cpu | |
2175 | */ | |
2176 | static void bnx2fc_percpu_thread_create(unsigned int cpu) | |
2177 | { | |
2178 | struct bnx2fc_percpu_s *p; | |
2179 | struct task_struct *thread; | |
2180 | ||
2181 | p = &per_cpu(bnx2fc_percpu, cpu); | |
2182 | ||
2183 | thread = kthread_create(bnx2fc_percpu_io_thread, | |
2184 | (void *)p, | |
2185 | "bnx2fc_thread/%d", cpu); | |
2186 | /* bind thread to the cpu */ | |
2187 | if (likely(!IS_ERR(p->iothread))) { | |
2188 | kthread_bind(thread, cpu); | |
2189 | p->iothread = thread; | |
2190 | wake_up_process(thread); | |
2191 | } | |
2192 | } | |
2193 | ||
2194 | static void bnx2fc_percpu_thread_destroy(unsigned int cpu) | |
2195 | { | |
2196 | struct bnx2fc_percpu_s *p; | |
2197 | struct task_struct *thread; | |
2198 | struct bnx2fc_work *work, *tmp; | |
2199 | LIST_HEAD(work_list); | |
2200 | ||
2201 | BNX2FC_MISC_DBG("destroying io thread for CPU %d\n", cpu); | |
2202 | ||
2203 | /* Prevent any new work from being queued for this CPU */ | |
2204 | p = &per_cpu(bnx2fc_percpu, cpu); | |
2205 | spin_lock_bh(&p->fp_work_lock); | |
2206 | thread = p->iothread; | |
2207 | p->iothread = NULL; | |
2208 | ||
2209 | ||
2210 | /* Free all work in the list */ | |
2211 | list_for_each_entry_safe(work, tmp, &work_list, list) { | |
2212 | list_del_init(&work->list); | |
2213 | bnx2fc_process_cq_compl(work->tgt, work->wqe); | |
2214 | kfree(work); | |
2215 | } | |
2216 | ||
2217 | spin_unlock_bh(&p->fp_work_lock); | |
2218 | ||
2219 | if (thread) | |
2220 | kthread_stop(thread); | |
2221 | } | |
2222 | ||
2223 | /** | |
2224 | * bnx2fc_cpu_callback - Handler for CPU hotplug events | |
2225 | * | |
2226 | * @nfb: The callback data block | |
2227 | * @action: The event triggering the callback | |
2228 | * @hcpu: The index of the CPU that the event is for | |
2229 | * | |
2230 | * This creates or destroys per-CPU data for fcoe | |
2231 | * | |
2232 | * Returns NOTIFY_OK always. | |
2233 | */ | |
2234 | static int bnx2fc_cpu_callback(struct notifier_block *nfb, | |
2235 | unsigned long action, void *hcpu) | |
2236 | { | |
2237 | unsigned cpu = (unsigned long)hcpu; | |
2238 | ||
2239 | switch (action) { | |
2240 | case CPU_ONLINE: | |
2241 | case CPU_ONLINE_FROZEN: | |
2242 | printk(PFX "CPU %x online: Create Rx thread\n", cpu); | |
2243 | bnx2fc_percpu_thread_create(cpu); | |
2244 | break; | |
2245 | case CPU_DEAD: | |
2246 | case CPU_DEAD_FROZEN: | |
2247 | printk(PFX "CPU %x offline: Remove Rx thread\n", cpu); | |
2248 | bnx2fc_percpu_thread_destroy(cpu); | |
2249 | break; | |
2250 | default: | |
2251 | break; | |
2252 | } | |
2253 | return NOTIFY_OK; | |
2254 | } | |
2255 | ||
2256 | /** | |
2257 | * bnx2fc_mod_init - module init entry point | |
2258 | * | |
2259 | * Initialize driver wide global data structures, and register | |
2260 | * with cnic module | |
2261 | **/ | |
2262 | static int __init bnx2fc_mod_init(void) | |
2263 | { | |
2264 | struct fcoe_percpu_s *bg; | |
2265 | struct task_struct *l2_thread; | |
2266 | int rc = 0; | |
2267 | unsigned int cpu = 0; | |
2268 | struct bnx2fc_percpu_s *p; | |
2269 | ||
2270 | printk(KERN_INFO PFX "%s", version); | |
2271 | ||
2272 | /* register as a fcoe transport */ | |
2273 | rc = fcoe_transport_attach(&bnx2fc_transport); | |
2274 | if (rc) { | |
2275 | printk(KERN_ERR "failed to register an fcoe transport, check " | |
2276 | "if libfcoe is loaded\n"); | |
2277 | goto out; | |
2278 | } | |
2279 | ||
2280 | INIT_LIST_HEAD(&adapter_list); | |
2281 | mutex_init(&bnx2fc_dev_lock); | |
2282 | adapter_count = 0; | |
2283 | ||
2284 | /* Attach FC transport template */ | |
2285 | rc = bnx2fc_attach_transport(); | |
2286 | if (rc) | |
2287 | goto detach_ft; | |
2288 | ||
2289 | bnx2fc_wq = alloc_workqueue("bnx2fc", 0, 0); | |
2290 | if (!bnx2fc_wq) { | |
2291 | rc = -ENOMEM; | |
2292 | goto release_bt; | |
2293 | } | |
2294 | ||
2295 | bg = &bnx2fc_global; | |
2296 | skb_queue_head_init(&bg->fcoe_rx_list); | |
2297 | l2_thread = kthread_create(bnx2fc_l2_rcv_thread, | |
2298 | (void *)bg, | |
2299 | "bnx2fc_l2_thread"); | |
2300 | if (IS_ERR(l2_thread)) { | |
2301 | rc = PTR_ERR(l2_thread); | |
2302 | goto free_wq; | |
2303 | } | |
2304 | wake_up_process(l2_thread); | |
2305 | spin_lock_bh(&bg->fcoe_rx_list.lock); | |
2306 | bg->thread = l2_thread; | |
2307 | spin_unlock_bh(&bg->fcoe_rx_list.lock); | |
2308 | ||
2309 | for_each_possible_cpu(cpu) { | |
2310 | p = &per_cpu(bnx2fc_percpu, cpu); | |
2311 | INIT_LIST_HEAD(&p->work_list); | |
2312 | spin_lock_init(&p->fp_work_lock); | |
2313 | } | |
2314 | ||
2315 | for_each_online_cpu(cpu) { | |
2316 | bnx2fc_percpu_thread_create(cpu); | |
2317 | } | |
2318 | ||
2319 | /* Initialize per CPU interrupt thread */ | |
2320 | register_hotcpu_notifier(&bnx2fc_cpu_notifier); | |
2321 | ||
2322 | cnic_register_driver(CNIC_ULP_FCOE, &bnx2fc_cnic_cb); | |
2323 | ||
2324 | return 0; | |
2325 | ||
2326 | free_wq: | |
2327 | destroy_workqueue(bnx2fc_wq); | |
2328 | release_bt: | |
2329 | bnx2fc_release_transport(); | |
2330 | detach_ft: | |
2331 | fcoe_transport_detach(&bnx2fc_transport); | |
2332 | out: | |
2333 | return rc; | |
2334 | } | |
2335 | ||
2336 | static void __exit bnx2fc_mod_exit(void) | |
2337 | { | |
2338 | LIST_HEAD(to_be_deleted); | |
2339 | struct bnx2fc_hba *hba, *next; | |
2340 | struct fcoe_percpu_s *bg; | |
2341 | struct task_struct *l2_thread; | |
2342 | struct sk_buff *skb; | |
2343 | unsigned int cpu = 0; | |
2344 | ||
2345 | /* | |
2346 | * NOTE: Since cnic calls register_driver routine rtnl_lock, | |
2347 | * it will have higher precedence than bnx2fc_dev_lock. | |
2348 | * unregister_device() cannot be called with bnx2fc_dev_lock | |
2349 | * held. | |
2350 | */ | |
2351 | mutex_lock(&bnx2fc_dev_lock); | |
2352 | list_splice(&adapter_list, &to_be_deleted); | |
2353 | INIT_LIST_HEAD(&adapter_list); | |
2354 | adapter_count = 0; | |
2355 | mutex_unlock(&bnx2fc_dev_lock); | |
2356 | ||
2357 | /* Unregister with cnic */ | |
2358 | list_for_each_entry_safe(hba, next, &to_be_deleted, link) { | |
2359 | list_del_init(&hba->link); | |
2360 | printk(KERN_ERR PFX "MOD_EXIT:destroy hba = 0x%p, kref = %d\n", | |
2361 | hba, atomic_read(&hba->kref.refcount)); | |
2362 | bnx2fc_ulp_stop(hba); | |
2363 | /* unregister cnic device */ | |
2364 | if (test_and_clear_bit(BNX2FC_CNIC_REGISTERED, | |
2365 | &hba->reg_with_cnic)) | |
2366 | hba->cnic->unregister_device(hba->cnic, CNIC_ULP_FCOE); | |
2367 | bnx2fc_interface_destroy(hba); | |
2368 | } | |
2369 | cnic_unregister_driver(CNIC_ULP_FCOE); | |
2370 | ||
2371 | /* Destroy global thread */ | |
2372 | bg = &bnx2fc_global; | |
2373 | spin_lock_bh(&bg->fcoe_rx_list.lock); | |
2374 | l2_thread = bg->thread; | |
2375 | bg->thread = NULL; | |
2376 | while ((skb = __skb_dequeue(&bg->fcoe_rx_list)) != NULL) | |
2377 | kfree_skb(skb); | |
2378 | ||
2379 | spin_unlock_bh(&bg->fcoe_rx_list.lock); | |
2380 | ||
2381 | if (l2_thread) | |
2382 | kthread_stop(l2_thread); | |
2383 | ||
2384 | unregister_hotcpu_notifier(&bnx2fc_cpu_notifier); | |
2385 | ||
2386 | /* Destroy per cpu threads */ | |
2387 | for_each_online_cpu(cpu) { | |
2388 | bnx2fc_percpu_thread_destroy(cpu); | |
2389 | } | |
2390 | ||
2391 | destroy_workqueue(bnx2fc_wq); | |
2392 | /* | |
2393 | * detach from scsi transport | |
2394 | * must happen after all destroys are done | |
2395 | */ | |
2396 | bnx2fc_release_transport(); | |
2397 | ||
2398 | /* detach from fcoe transport */ | |
2399 | fcoe_transport_detach(&bnx2fc_transport); | |
2400 | } | |
2401 | ||
2402 | module_init(bnx2fc_mod_init); | |
2403 | module_exit(bnx2fc_mod_exit); | |
2404 | ||
2405 | static struct fc_function_template bnx2fc_transport_function = { | |
2406 | .show_host_node_name = 1, | |
2407 | .show_host_port_name = 1, | |
2408 | .show_host_supported_classes = 1, | |
2409 | .show_host_supported_fc4s = 1, | |
2410 | .show_host_active_fc4s = 1, | |
2411 | .show_host_maxframe_size = 1, | |
2412 | ||
2413 | .show_host_port_id = 1, | |
2414 | .show_host_supported_speeds = 1, | |
2415 | .get_host_speed = fc_get_host_speed, | |
2416 | .show_host_speed = 1, | |
2417 | .show_host_port_type = 1, | |
2418 | .get_host_port_state = fc_get_host_port_state, | |
2419 | .show_host_port_state = 1, | |
2420 | .show_host_symbolic_name = 1, | |
2421 | ||
2422 | .dd_fcrport_size = (sizeof(struct fc_rport_libfc_priv) + | |
2423 | sizeof(struct bnx2fc_rport)), | |
2424 | .show_rport_maxframe_size = 1, | |
2425 | .show_rport_supported_classes = 1, | |
2426 | ||
2427 | .show_host_fabric_name = 1, | |
2428 | .show_starget_node_name = 1, | |
2429 | .show_starget_port_name = 1, | |
2430 | .show_starget_port_id = 1, | |
2431 | .set_rport_dev_loss_tmo = fc_set_rport_loss_tmo, | |
2432 | .show_rport_dev_loss_tmo = 1, | |
2433 | .get_fc_host_stats = bnx2fc_get_host_stats, | |
2434 | ||
2435 | .issue_fc_host_lip = bnx2fc_fcoe_reset, | |
2436 | ||
2437 | .terminate_rport_io = fc_rport_terminate_io, | |
2438 | ||
2439 | .vport_create = bnx2fc_vport_create, | |
2440 | .vport_delete = bnx2fc_vport_destroy, | |
2441 | .vport_disable = bnx2fc_vport_disable, | |
2442 | }; | |
2443 | ||
2444 | static struct fc_function_template bnx2fc_vport_xport_function = { | |
2445 | .show_host_node_name = 1, | |
2446 | .show_host_port_name = 1, | |
2447 | .show_host_supported_classes = 1, | |
2448 | .show_host_supported_fc4s = 1, | |
2449 | .show_host_active_fc4s = 1, | |
2450 | .show_host_maxframe_size = 1, | |
2451 | ||
2452 | .show_host_port_id = 1, | |
2453 | .show_host_supported_speeds = 1, | |
2454 | .get_host_speed = fc_get_host_speed, | |
2455 | .show_host_speed = 1, | |
2456 | .show_host_port_type = 1, | |
2457 | .get_host_port_state = fc_get_host_port_state, | |
2458 | .show_host_port_state = 1, | |
2459 | .show_host_symbolic_name = 1, | |
2460 | ||
2461 | .dd_fcrport_size = (sizeof(struct fc_rport_libfc_priv) + | |
2462 | sizeof(struct bnx2fc_rport)), | |
2463 | .show_rport_maxframe_size = 1, | |
2464 | .show_rport_supported_classes = 1, | |
2465 | ||
2466 | .show_host_fabric_name = 1, | |
2467 | .show_starget_node_name = 1, | |
2468 | .show_starget_port_name = 1, | |
2469 | .show_starget_port_id = 1, | |
2470 | .set_rport_dev_loss_tmo = fc_set_rport_loss_tmo, | |
2471 | .show_rport_dev_loss_tmo = 1, | |
2472 | .get_fc_host_stats = fc_get_host_stats, | |
2473 | .issue_fc_host_lip = bnx2fc_fcoe_reset, | |
2474 | .terminate_rport_io = fc_rport_terminate_io, | |
2475 | }; | |
2476 | ||
2477 | /** | |
2478 | * scsi_host_template structure used while registering with SCSI-ml | |
2479 | */ | |
2480 | static struct scsi_host_template bnx2fc_shost_template = { | |
2481 | .module = THIS_MODULE, | |
2482 | .name = "Broadcom Offload FCoE Initiator", | |
2483 | .queuecommand = bnx2fc_queuecommand, | |
2484 | .eh_abort_handler = bnx2fc_eh_abort, /* abts */ | |
2485 | .eh_device_reset_handler = bnx2fc_eh_device_reset, /* lun reset */ | |
2486 | .eh_target_reset_handler = bnx2fc_eh_target_reset, /* tgt reset */ | |
2487 | .eh_host_reset_handler = fc_eh_host_reset, | |
2488 | .slave_alloc = fc_slave_alloc, | |
2489 | .change_queue_depth = fc_change_queue_depth, | |
2490 | .change_queue_type = fc_change_queue_type, | |
2491 | .this_id = -1, | |
2492 | .cmd_per_lun = 3, | |
0ea5c275 | 2493 | .can_queue = BNX2FC_CAN_QUEUE, |
853e2bd2 BG |
2494 | .use_clustering = ENABLE_CLUSTERING, |
2495 | .sg_tablesize = BNX2FC_MAX_BDS_PER_CMD, | |
2496 | .max_sectors = 512, | |
2497 | }; | |
2498 | ||
2499 | static struct libfc_function_template bnx2fc_libfc_fcn_templ = { | |
2500 | .frame_send = bnx2fc_xmit, | |
2501 | .elsct_send = bnx2fc_elsct_send, | |
2502 | .fcp_abort_io = bnx2fc_abort_io, | |
2503 | .fcp_cleanup = bnx2fc_cleanup, | |
2504 | .rport_event_callback = bnx2fc_rport_event_handler, | |
2505 | }; | |
2506 | ||
2507 | /** | |
2508 | * bnx2fc_cnic_cb - global template of bnx2fc - cnic driver interface | |
2509 | * structure carrying callback function pointers | |
2510 | */ | |
2511 | static struct cnic_ulp_ops bnx2fc_cnic_cb = { | |
2512 | .owner = THIS_MODULE, | |
2513 | .cnic_init = bnx2fc_ulp_init, | |
2514 | .cnic_exit = bnx2fc_ulp_exit, | |
2515 | .cnic_start = bnx2fc_ulp_start, | |
2516 | .cnic_stop = bnx2fc_ulp_stop, | |
2517 | .indicate_kcqes = bnx2fc_indicate_kcqe, | |
2518 | .indicate_netevent = bnx2fc_indicate_netevent, | |
2519 | }; |