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