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