]>
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 ([email protected]) | |
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 | |
fd254189 | 25 | #define DRV_MODULE_RELDATE "Oct 21, 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 <[email protected]>"); | |
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 | { | |
853e2bd2 BG |
943 | if (!fc_exch_mgr_alloc(lport, FC_CLASS_3, FCOE_MIN_XID, |
944 | FCOE_MAX_XID, NULL)) { | |
945 | printk(KERN_ERR PFX "em_config:fc_exch_mgr_alloc failed\n"); | |
946 | return -ENOMEM; | |
947 | } | |
948 | ||
853e2bd2 BG |
949 | return 0; |
950 | } | |
951 | ||
952 | static int bnx2fc_lport_config(struct fc_lport *lport) | |
953 | { | |
954 | lport->link_up = 0; | |
955 | lport->qfull = 0; | |
956 | lport->max_retry_count = 3; | |
957 | lport->max_rport_retry_count = 3; | |
958 | lport->e_d_tov = 2 * 1000; | |
959 | lport->r_a_tov = 10 * 1000; | |
960 | ||
853e2bd2 BG |
961 | lport->service_params = (FCP_SPPF_INIT_FCN | FCP_SPPF_RD_XRDY_DIS | |
962 | FCP_SPPF_RETRY | FCP_SPPF_CONF_COMPL); | |
853e2bd2 BG |
963 | lport->does_npiv = 1; |
964 | ||
965 | memset(&lport->rnid_gen, 0, sizeof(struct fc_els_rnid_gen)); | |
966 | lport->rnid_gen.rnid_atype = BNX2FC_RNID_HBA; | |
967 | ||
968 | /* alloc stats structure */ | |
969 | if (fc_lport_init_stats(lport)) | |
970 | return -ENOMEM; | |
971 | ||
972 | /* Finish fc_lport configuration */ | |
973 | fc_lport_config(lport); | |
974 | ||
975 | return 0; | |
976 | } | |
977 | ||
978 | /** | |
979 | * bnx2fc_fip_recv - handle a received FIP frame. | |
980 | * | |
981 | * @skb: the received skb | |
982 | * @dev: associated &net_device | |
983 | * @ptype: the &packet_type structure which was used to register this handler. | |
984 | * @orig_dev: original receive &net_device, in case @ dev is a bond. | |
985 | * | |
986 | * Returns: 0 for success | |
987 | */ | |
988 | static int bnx2fc_fip_recv(struct sk_buff *skb, struct net_device *dev, | |
989 | struct packet_type *ptype, | |
990 | struct net_device *orig_dev) | |
991 | { | |
aea71a02 BPG |
992 | struct bnx2fc_interface *interface; |
993 | interface = container_of(ptype, struct bnx2fc_interface, | |
994 | fip_packet_type); | |
995 | fcoe_ctlr_recv(&interface->ctlr, skb); | |
853e2bd2 BG |
996 | return 0; |
997 | } | |
998 | ||
999 | /** | |
1000 | * bnx2fc_update_src_mac - Update Ethernet MAC filters. | |
1001 | * | |
1002 | * @fip: FCoE controller. | |
1003 | * @old: Unicast MAC address to delete if the MAC is non-zero. | |
1004 | * @new: Unicast MAC address to add. | |
1005 | * | |
1006 | * Remove any previously-set unicast MAC filter. | |
1007 | * Add secondary FCoE MAC address filter for our OUI. | |
1008 | */ | |
1009 | static void bnx2fc_update_src_mac(struct fc_lport *lport, u8 *addr) | |
1010 | { | |
1011 | struct fcoe_port *port = lport_priv(lport); | |
1012 | ||
1013 | memcpy(port->data_src_addr, addr, ETH_ALEN); | |
1014 | } | |
1015 | ||
1016 | /** | |
1017 | * bnx2fc_get_src_mac - return the ethernet source address for an lport | |
1018 | * | |
1019 | * @lport: libfc port | |
1020 | */ | |
1021 | static u8 *bnx2fc_get_src_mac(struct fc_lport *lport) | |
1022 | { | |
1023 | struct fcoe_port *port; | |
1024 | ||
1025 | port = (struct fcoe_port *)lport_priv(lport); | |
1026 | return port->data_src_addr; | |
1027 | } | |
1028 | ||
1029 | /** | |
1030 | * bnx2fc_fip_send - send an Ethernet-encapsulated FIP frame. | |
1031 | * | |
1032 | * @fip: FCoE controller. | |
1033 | * @skb: FIP Packet. | |
1034 | */ | |
1035 | static void bnx2fc_fip_send(struct fcoe_ctlr *fip, struct sk_buff *skb) | |
1036 | { | |
1037 | skb->dev = bnx2fc_from_ctlr(fip)->netdev; | |
1038 | dev_queue_xmit(skb); | |
1039 | } | |
1040 | ||
1041 | static int bnx2fc_vport_create(struct fc_vport *vport, bool disabled) | |
1042 | { | |
1043 | struct Scsi_Host *shost = vport_to_shost(vport); | |
1044 | struct fc_lport *n_port = shost_priv(shost); | |
1045 | struct fcoe_port *port = lport_priv(n_port); | |
aea71a02 BPG |
1046 | struct bnx2fc_interface *interface = port->priv; |
1047 | struct net_device *netdev = interface->netdev; | |
853e2bd2 | 1048 | struct fc_lport *vn_port; |
861efc54 BPG |
1049 | int rc; |
1050 | char buf[32]; | |
1051 | ||
1052 | rc = fcoe_validate_vport_create(vport); | |
1053 | if (rc) { | |
1054 | fcoe_wwn_to_str(vport->port_name, buf, sizeof(buf)); | |
1055 | printk(KERN_ERR PFX "Failed to create vport, " | |
1056 | "WWPN (0x%s) already exists\n", | |
1057 | buf); | |
1058 | return rc; | |
1059 | } | |
853e2bd2 | 1060 | |
aea71a02 | 1061 | if (!test_bit(BNX2FC_FLAG_FW_INIT_DONE, &interface->hba->flags)) { |
853e2bd2 | 1062 | printk(KERN_ERR PFX "vn ports cannot be created on" |
aea71a02 | 1063 | "this interface\n"); |
853e2bd2 BG |
1064 | return -EIO; |
1065 | } | |
4bc71cb9 | 1066 | rtnl_lock(); |
853e2bd2 | 1067 | mutex_lock(&bnx2fc_dev_lock); |
aea71a02 | 1068 | vn_port = bnx2fc_if_create(interface, &vport->dev, 1); |
853e2bd2 | 1069 | mutex_unlock(&bnx2fc_dev_lock); |
4bc71cb9 | 1070 | rtnl_unlock(); |
853e2bd2 BG |
1071 | |
1072 | if (IS_ERR(vn_port)) { | |
1073 | printk(KERN_ERR PFX "bnx2fc_vport_create (%s) failed\n", | |
1074 | netdev->name); | |
1075 | return -EIO; | |
1076 | } | |
1077 | ||
1078 | if (disabled) { | |
1079 | fc_vport_set_state(vport, FC_VPORT_DISABLED); | |
1080 | } else { | |
1081 | vn_port->boot_time = jiffies; | |
1082 | fc_lport_init(vn_port); | |
1083 | fc_fabric_login(vn_port); | |
1084 | fc_vport_setlink(vn_port); | |
1085 | } | |
1086 | return 0; | |
1087 | } | |
1088 | ||
abc49a93 BPG |
1089 | static void bnx2fc_free_vport(struct bnx2fc_hba *hba, struct fc_lport *lport) |
1090 | { | |
1091 | struct bnx2fc_lport *blport, *tmp; | |
1092 | ||
1093 | spin_lock_bh(&hba->hba_lock); | |
1094 | list_for_each_entry_safe(blport, tmp, &hba->vports, list) { | |
1095 | if (blport->lport == lport) { | |
1096 | list_del(&blport->list); | |
1097 | kfree(blport); | |
1098 | } | |
1099 | } | |
1100 | spin_unlock_bh(&hba->hba_lock); | |
1101 | } | |
1102 | ||
853e2bd2 BG |
1103 | static int bnx2fc_vport_destroy(struct fc_vport *vport) |
1104 | { | |
1105 | struct Scsi_Host *shost = vport_to_shost(vport); | |
1106 | struct fc_lport *n_port = shost_priv(shost); | |
1107 | struct fc_lport *vn_port = vport->dd_data; | |
1108 | struct fcoe_port *port = lport_priv(vn_port); | |
abc49a93 | 1109 | struct bnx2fc_interface *interface = port->priv; |
cdf54668 BPG |
1110 | struct fc_lport *v_port; |
1111 | bool found = false; | |
853e2bd2 BG |
1112 | |
1113 | mutex_lock(&n_port->lp_mutex); | |
cdf54668 BPG |
1114 | list_for_each_entry(v_port, &n_port->vports, list) |
1115 | if (v_port->vport == vport) { | |
1116 | found = true; | |
1117 | break; | |
1118 | } | |
1119 | ||
1120 | if (!found) { | |
1121 | mutex_unlock(&n_port->lp_mutex); | |
1122 | return -ENOENT; | |
1123 | } | |
853e2bd2 BG |
1124 | list_del(&vn_port->list); |
1125 | mutex_unlock(&n_port->lp_mutex); | |
abc49a93 BPG |
1126 | bnx2fc_free_vport(interface->hba, port->lport); |
1127 | bnx2fc_port_shutdown(port->lport); | |
1128 | bnx2fc_interface_put(interface); | |
853e2bd2 BG |
1129 | queue_work(bnx2fc_wq, &port->destroy_work); |
1130 | return 0; | |
1131 | } | |
1132 | ||
1133 | static int bnx2fc_vport_disable(struct fc_vport *vport, bool disable) | |
1134 | { | |
1135 | struct fc_lport *lport = vport->dd_data; | |
1136 | ||
1137 | if (disable) { | |
1138 | fc_vport_set_state(vport, FC_VPORT_DISABLED); | |
1139 | fc_fabric_logoff(lport); | |
1140 | } else { | |
1141 | lport->boot_time = jiffies; | |
1142 | fc_fabric_login(lport); | |
1143 | fc_vport_setlink(lport); | |
1144 | } | |
1145 | return 0; | |
1146 | } | |
1147 | ||
1148 | ||
776cebca | 1149 | static int bnx2fc_interface_setup(struct bnx2fc_interface *interface) |
853e2bd2 | 1150 | { |
aea71a02 BPG |
1151 | struct net_device *netdev = interface->netdev; |
1152 | struct net_device *physdev = interface->hba->phys_dev; | |
853e2bd2 BG |
1153 | struct netdev_hw_addr *ha; |
1154 | int sel_san_mac = 0; | |
1155 | ||
853e2bd2 BG |
1156 | /* setup Source MAC Address */ |
1157 | rcu_read_lock(); | |
1158 | for_each_dev_addr(physdev, ha) { | |
1159 | BNX2FC_MISC_DBG("net_config: ha->type = %d, fip_mac = ", | |
1160 | ha->type); | |
1161 | printk(KERN_INFO "%2x:%2x:%2x:%2x:%2x:%2x\n", ha->addr[0], | |
1162 | ha->addr[1], ha->addr[2], ha->addr[3], | |
1163 | ha->addr[4], ha->addr[5]); | |
1164 | ||
1165 | if ((ha->type == NETDEV_HW_ADDR_T_SAN) && | |
1166 | (is_valid_ether_addr(ha->addr))) { | |
aea71a02 BPG |
1167 | memcpy(interface->ctlr.ctl_src_addr, ha->addr, |
1168 | ETH_ALEN); | |
853e2bd2 BG |
1169 | sel_san_mac = 1; |
1170 | BNX2FC_MISC_DBG("Found SAN MAC\n"); | |
1171 | } | |
1172 | } | |
1173 | rcu_read_unlock(); | |
1174 | ||
1175 | if (!sel_san_mac) | |
1176 | return -ENODEV; | |
1177 | ||
aea71a02 BPG |
1178 | interface->fip_packet_type.func = bnx2fc_fip_recv; |
1179 | interface->fip_packet_type.type = htons(ETH_P_FIP); | |
1180 | interface->fip_packet_type.dev = netdev; | |
1181 | dev_add_pack(&interface->fip_packet_type); | |
853e2bd2 | 1182 | |
aea71a02 BPG |
1183 | interface->fcoe_packet_type.func = bnx2fc_rcv; |
1184 | interface->fcoe_packet_type.type = __constant_htons(ETH_P_FCOE); | |
1185 | interface->fcoe_packet_type.dev = netdev; | |
1186 | dev_add_pack(&interface->fcoe_packet_type); | |
853e2bd2 BG |
1187 | |
1188 | return 0; | |
1189 | } | |
1190 | ||
1191 | static int bnx2fc_attach_transport(void) | |
1192 | { | |
1193 | bnx2fc_transport_template = | |
1194 | fc_attach_transport(&bnx2fc_transport_function); | |
1195 | ||
1196 | if (bnx2fc_transport_template == NULL) { | |
1197 | printk(KERN_ERR PFX "Failed to attach FC transport\n"); | |
1198 | return -ENODEV; | |
1199 | } | |
1200 | ||
1201 | bnx2fc_vport_xport_template = | |
1202 | fc_attach_transport(&bnx2fc_vport_xport_function); | |
1203 | if (bnx2fc_vport_xport_template == NULL) { | |
1204 | printk(KERN_ERR PFX | |
1205 | "Failed to attach FC transport for vport\n"); | |
1206 | fc_release_transport(bnx2fc_transport_template); | |
1207 | bnx2fc_transport_template = NULL; | |
1208 | return -ENODEV; | |
1209 | } | |
1210 | return 0; | |
1211 | } | |
1212 | static void bnx2fc_release_transport(void) | |
1213 | { | |
1214 | fc_release_transport(bnx2fc_transport_template); | |
1215 | fc_release_transport(bnx2fc_vport_xport_template); | |
1216 | bnx2fc_transport_template = NULL; | |
1217 | bnx2fc_vport_xport_template = NULL; | |
1218 | } | |
1219 | ||
1220 | static void bnx2fc_interface_release(struct kref *kref) | |
1221 | { | |
aea71a02 | 1222 | struct bnx2fc_interface *interface; |
853e2bd2 | 1223 | struct net_device *netdev; |
853e2bd2 | 1224 | |
aea71a02 | 1225 | interface = container_of(kref, struct bnx2fc_interface, kref); |
068bdce4 | 1226 | BNX2FC_MISC_DBG("Interface is being released\n"); |
853e2bd2 | 1227 | |
aea71a02 | 1228 | netdev = interface->netdev; |
853e2bd2 BG |
1229 | |
1230 | /* tear-down FIP controller */ | |
aea71a02 BPG |
1231 | if (test_and_clear_bit(BNX2FC_CTLR_INIT_DONE, &interface->if_flags)) |
1232 | fcoe_ctlr_destroy(&interface->ctlr); | |
1233 | ||
1234 | kfree(interface); | |
853e2bd2 | 1235 | |
853e2bd2 BG |
1236 | dev_put(netdev); |
1237 | module_put(THIS_MODULE); | |
1238 | } | |
1239 | ||
aea71a02 | 1240 | static inline void bnx2fc_interface_get(struct bnx2fc_interface *interface) |
853e2bd2 | 1241 | { |
aea71a02 | 1242 | kref_get(&interface->kref); |
853e2bd2 BG |
1243 | } |
1244 | ||
aea71a02 | 1245 | static inline void bnx2fc_interface_put(struct bnx2fc_interface *interface) |
853e2bd2 | 1246 | { |
aea71a02 | 1247 | kref_put(&interface->kref, bnx2fc_interface_release); |
853e2bd2 | 1248 | } |
aea71a02 | 1249 | static void bnx2fc_hba_destroy(struct bnx2fc_hba *hba) |
853e2bd2 | 1250 | { |
aea71a02 BPG |
1251 | /* Free the command manager */ |
1252 | if (hba->cmd_mgr) { | |
1253 | bnx2fc_cmd_mgr_free(hba->cmd_mgr); | |
1254 | hba->cmd_mgr = NULL; | |
1255 | } | |
1256 | kfree(hba->tgt_ofld_list); | |
853e2bd2 BG |
1257 | bnx2fc_unbind_pcidev(hba); |
1258 | kfree(hba); | |
1259 | } | |
1260 | ||
1261 | /** | |
aea71a02 | 1262 | * bnx2fc_hba_create - create a new bnx2fc hba |
853e2bd2 BG |
1263 | * |
1264 | * @cnic: pointer to cnic device | |
1265 | * | |
aea71a02 BPG |
1266 | * Creates a new FCoE hba on the given device. |
1267 | * | |
853e2bd2 | 1268 | */ |
aea71a02 | 1269 | static struct bnx2fc_hba *bnx2fc_hba_create(struct cnic_dev *cnic) |
853e2bd2 BG |
1270 | { |
1271 | struct bnx2fc_hba *hba; | |
1272 | int rc; | |
1273 | ||
1274 | hba = kzalloc(sizeof(*hba), GFP_KERNEL); | |
1275 | if (!hba) { | |
1276 | printk(KERN_ERR PFX "Unable to allocate hba structure\n"); | |
1277 | return NULL; | |
1278 | } | |
1279 | spin_lock_init(&hba->hba_lock); | |
1280 | mutex_init(&hba->hba_mutex); | |
1281 | ||
1282 | hba->cnic = cnic; | |
1283 | rc = bnx2fc_bind_pcidev(hba); | |
aea71a02 BPG |
1284 | if (rc) { |
1285 | printk(KERN_ERR PFX "create_adapter: bind error\n"); | |
853e2bd2 | 1286 | goto bind_err; |
aea71a02 | 1287 | } |
853e2bd2 | 1288 | hba->phys_dev = cnic->netdev; |
aea71a02 BPG |
1289 | hba->next_conn_id = 0; |
1290 | ||
1291 | hba->tgt_ofld_list = | |
1292 | kzalloc(sizeof(struct bnx2fc_rport *) * BNX2FC_NUM_MAX_SESS, | |
1293 | GFP_KERNEL); | |
1294 | if (!hba->tgt_ofld_list) { | |
1295 | printk(KERN_ERR PFX "Unable to allocate tgt offload list\n"); | |
1296 | goto tgtofld_err; | |
1297 | } | |
1298 | ||
1299 | hba->num_ofld_sess = 0; | |
1300 | ||
1301 | hba->cmd_mgr = bnx2fc_cmd_mgr_alloc(hba, BNX2FC_MIN_XID, | |
1302 | BNX2FC_MAX_XID); | |
1303 | if (!hba->cmd_mgr) { | |
1304 | printk(KERN_ERR PFX "em_config:bnx2fc_cmd_mgr_alloc failed\n"); | |
1305 | goto cmgr_err; | |
1306 | } | |
853e2bd2 BG |
1307 | |
1308 | init_waitqueue_head(&hba->shutdown_wait); | |
1309 | init_waitqueue_head(&hba->destroy_wait); | |
aea71a02 | 1310 | INIT_LIST_HEAD(&hba->vports); |
853e2bd2 BG |
1311 | |
1312 | return hba; | |
aea71a02 BPG |
1313 | |
1314 | cmgr_err: | |
1315 | kfree(hba->tgt_ofld_list); | |
1316 | tgtofld_err: | |
1317 | bnx2fc_unbind_pcidev(hba); | |
853e2bd2 | 1318 | bind_err: |
853e2bd2 BG |
1319 | kfree(hba); |
1320 | return NULL; | |
1321 | } | |
1322 | ||
aea71a02 BPG |
1323 | struct bnx2fc_interface *bnx2fc_interface_create(struct bnx2fc_hba *hba, |
1324 | struct net_device *netdev, | |
1325 | enum fip_state fip_mode) | |
853e2bd2 | 1326 | { |
aea71a02 | 1327 | struct bnx2fc_interface *interface; |
853e2bd2 | 1328 | int rc = 0; |
853e2bd2 | 1329 | |
aea71a02 BPG |
1330 | interface = kzalloc(sizeof(*interface), GFP_KERNEL); |
1331 | if (!interface) { | |
1332 | printk(KERN_ERR PFX "Unable to allocate interface structure\n"); | |
1333 | return NULL; | |
1334 | } | |
853e2bd2 | 1335 | dev_hold(netdev); |
aea71a02 BPG |
1336 | kref_init(&interface->kref); |
1337 | interface->hba = hba; | |
1338 | interface->netdev = netdev; | |
853e2bd2 BG |
1339 | |
1340 | /* Initialize FIP */ | |
aea71a02 BPG |
1341 | fcoe_ctlr_init(&interface->ctlr, fip_mode); |
1342 | interface->ctlr.send = bnx2fc_fip_send; | |
1343 | interface->ctlr.update_mac = bnx2fc_update_src_mac; | |
1344 | interface->ctlr.get_src_addr = bnx2fc_get_src_mac; | |
1345 | set_bit(BNX2FC_CTLR_INIT_DONE, &interface->if_flags); | |
853e2bd2 | 1346 | |
776cebca | 1347 | rc = bnx2fc_interface_setup(interface); |
aea71a02 BPG |
1348 | if (!rc) |
1349 | return interface; | |
853e2bd2 | 1350 | |
aea71a02 | 1351 | fcoe_ctlr_destroy(&interface->ctlr); |
853e2bd2 | 1352 | dev_put(netdev); |
aea71a02 BPG |
1353 | kfree(interface); |
1354 | return NULL; | |
853e2bd2 BG |
1355 | } |
1356 | ||
1357 | /** | |
1358 | * bnx2fc_if_create - Create FCoE instance on a given interface | |
1359 | * | |
aea71a02 | 1360 | * @interface: FCoE interface to create a local port on |
853e2bd2 BG |
1361 | * @parent: Device pointer to be the parent in sysfs for the SCSI host |
1362 | * @npiv: Indicates if the port is vport or not | |
1363 | * | |
1364 | * Creates a fc_lport instance and a Scsi_Host instance and configure them. | |
1365 | * | |
1366 | * Returns: Allocated fc_lport or an error pointer | |
1367 | */ | |
aea71a02 | 1368 | static struct fc_lport *bnx2fc_if_create(struct bnx2fc_interface *interface, |
853e2bd2 BG |
1369 | struct device *parent, int npiv) |
1370 | { | |
134a4e27 | 1371 | struct fc_lport *lport, *n_port; |
853e2bd2 BG |
1372 | struct fcoe_port *port; |
1373 | struct Scsi_Host *shost; | |
1374 | struct fc_vport *vport = dev_to_vport(parent); | |
d36b3279 | 1375 | struct bnx2fc_lport *blport; |
aea71a02 | 1376 | struct bnx2fc_hba *hba; |
853e2bd2 BG |
1377 | int rc = 0; |
1378 | ||
d36b3279 BPG |
1379 | blport = kzalloc(sizeof(struct bnx2fc_lport), GFP_KERNEL); |
1380 | if (!blport) { | |
aea71a02 | 1381 | BNX2FC_HBA_DBG(interface->ctlr.lp, "Unable to alloc blport\n"); |
d36b3279 BPG |
1382 | return NULL; |
1383 | } | |
1384 | ||
853e2bd2 | 1385 | /* Allocate Scsi_Host structure */ |
134a4e27 VD |
1386 | if (!npiv) |
1387 | lport = libfc_host_alloc(&bnx2fc_shost_template, sizeof(*port)); | |
1388 | else | |
1389 | lport = libfc_vport_create(vport, sizeof(*port)); | |
853e2bd2 BG |
1390 | |
1391 | if (!lport) { | |
1392 | printk(KERN_ERR PFX "could not allocate scsi host structure\n"); | |
d36b3279 | 1393 | goto free_blport; |
853e2bd2 BG |
1394 | } |
1395 | shost = lport->host; | |
1396 | port = lport_priv(lport); | |
1397 | port->lport = lport; | |
aea71a02 | 1398 | port->priv = interface; |
853e2bd2 BG |
1399 | INIT_WORK(&port->destroy_work, bnx2fc_destroy_work); |
1400 | ||
1401 | /* Configure fcoe_port */ | |
1402 | rc = bnx2fc_lport_config(lport); | |
1403 | if (rc) | |
1404 | goto lp_config_err; | |
1405 | ||
1406 | if (npiv) { | |
853e2bd2 BG |
1407 | printk(KERN_ERR PFX "Setting vport names, 0x%llX 0x%llX\n", |
1408 | vport->node_name, vport->port_name); | |
1409 | fc_set_wwnn(lport, vport->node_name); | |
1410 | fc_set_wwpn(lport, vport->port_name); | |
1411 | } | |
1412 | /* Configure netdev and networking properties of the lport */ | |
52439607 | 1413 | rc = bnx2fc_net_config(lport, interface->netdev); |
853e2bd2 BG |
1414 | if (rc) { |
1415 | printk(KERN_ERR PFX "Error on bnx2fc_net_config\n"); | |
1416 | goto lp_config_err; | |
1417 | } | |
1418 | ||
1419 | rc = bnx2fc_shost_config(lport, parent); | |
1420 | if (rc) { | |
1421 | printk(KERN_ERR PFX "Couldnt configure shost for %s\n", | |
aea71a02 | 1422 | interface->netdev->name); |
853e2bd2 BG |
1423 | goto lp_config_err; |
1424 | } | |
1425 | ||
1426 | /* Initialize the libfc library */ | |
1427 | rc = bnx2fc_libfc_config(lport); | |
1428 | if (rc) { | |
1429 | printk(KERN_ERR PFX "Couldnt configure libfc\n"); | |
1430 | goto shost_err; | |
1431 | } | |
1432 | fc_host_port_type(lport->host) = FC_PORTTYPE_UNKNOWN; | |
1433 | ||
1434 | /* Allocate exchange manager */ | |
134a4e27 | 1435 | if (!npiv) |
853e2bd2 | 1436 | rc = bnx2fc_em_config(lport); |
134a4e27 VD |
1437 | else { |
1438 | shost = vport_to_shost(vport); | |
1439 | n_port = shost_priv(shost); | |
1440 | rc = fc_exch_mgr_list_clone(n_port, lport); | |
1441 | } | |
1442 | ||
1443 | if (rc) { | |
1444 | printk(KERN_ERR PFX "Error on bnx2fc_em_config\n"); | |
1445 | goto shost_err; | |
853e2bd2 BG |
1446 | } |
1447 | ||
aea71a02 | 1448 | bnx2fc_interface_get(interface); |
d36b3279 | 1449 | |
aea71a02 | 1450 | hba = interface->hba; |
d36b3279 BPG |
1451 | spin_lock_bh(&hba->hba_lock); |
1452 | blport->lport = lport; | |
1453 | list_add_tail(&blport->list, &hba->vports); | |
1454 | spin_unlock_bh(&hba->hba_lock); | |
1455 | ||
853e2bd2 BG |
1456 | return lport; |
1457 | ||
1458 | shost_err: | |
1459 | scsi_remove_host(shost); | |
1460 | lp_config_err: | |
1461 | scsi_host_put(lport->host); | |
d36b3279 BPG |
1462 | free_blport: |
1463 | kfree(blport); | |
853e2bd2 BG |
1464 | return NULL; |
1465 | } | |
1466 | ||
013068fa | 1467 | static void bnx2fc_net_cleanup(struct bnx2fc_interface *interface) |
853e2bd2 BG |
1468 | { |
1469 | /* Dont listen for Ethernet packets anymore */ | |
aea71a02 BPG |
1470 | __dev_remove_pack(&interface->fcoe_packet_type); |
1471 | __dev_remove_pack(&interface->fip_packet_type); | |
853e2bd2 BG |
1472 | synchronize_net(); |
1473 | } | |
1474 | ||
776cebca | 1475 | static void bnx2fc_interface_cleanup(struct bnx2fc_interface *interface) |
853e2bd2 | 1476 | { |
9be17fc4 | 1477 | struct fc_lport *lport = interface->ctlr.lp; |
853e2bd2 | 1478 | struct fcoe_port *port = lport_priv(lport); |
9be17fc4 | 1479 | struct bnx2fc_hba *hba = interface->hba; |
853e2bd2 | 1480 | |
853e2bd2 BG |
1481 | /* Stop the transmit retry timer */ |
1482 | del_timer_sync(&port->timer); | |
1483 | ||
1484 | /* Free existing transmit skbs */ | |
1485 | fcoe_clean_pending_queue(lport); | |
1486 | ||
013068fa | 1487 | bnx2fc_net_cleanup(interface); |
9be17fc4 | 1488 | |
abc49a93 | 1489 | bnx2fc_free_vport(hba, lport); |
9be17fc4 BPG |
1490 | } |
1491 | ||
1492 | static void bnx2fc_if_destroy(struct fc_lport *lport) | |
1493 | { | |
1494 | ||
853e2bd2 BG |
1495 | /* Free queued packets for the receive thread */ |
1496 | bnx2fc_clean_rx_queue(lport); | |
1497 | ||
1498 | /* Detach from scsi-ml */ | |
1499 | fc_remove_host(lport->host); | |
1500 | scsi_remove_host(lport->host); | |
1501 | ||
1502 | /* | |
1503 | * Note that only the physical lport will have the exchange manager. | |
1504 | * for vports, this function is NOP | |
1505 | */ | |
1506 | fc_exch_mgr_free(lport); | |
1507 | ||
1508 | /* Free memory used by statistical counters */ | |
1509 | fc_lport_free_stats(lport); | |
1510 | ||
1511 | /* Release Scsi_Host */ | |
1512 | scsi_host_put(lport->host); | |
1513 | } | |
1514 | ||
eccdcd02 | 1515 | static void __bnx2fc_destroy(struct bnx2fc_interface *interface) |
abc49a93 BPG |
1516 | { |
1517 | struct fc_lport *lport = interface->ctlr.lp; | |
0cbf32e1 | 1518 | struct fcoe_port *port = lport_priv(lport); |
abc49a93 BPG |
1519 | |
1520 | bnx2fc_interface_cleanup(interface); | |
1521 | bnx2fc_stop(interface); | |
abc49a93 | 1522 | list_del(&interface->list); |
abc49a93 | 1523 | bnx2fc_interface_put(interface); |
0cbf32e1 | 1524 | queue_work(bnx2fc_wq, &port->destroy_work); |
abc49a93 BPG |
1525 | } |
1526 | ||
853e2bd2 BG |
1527 | /** |
1528 | * bnx2fc_destroy - Destroy a bnx2fc FCoE interface | |
1529 | * | |
1530 | * @buffer: The name of the Ethernet interface to be destroyed | |
1531 | * @kp: The associated kernel parameter | |
1532 | * | |
1533 | * Called from sysfs. | |
1534 | * | |
1535 | * Returns: 0 for success | |
1536 | */ | |
1537 | static int bnx2fc_destroy(struct net_device *netdev) | |
1538 | { | |
aea71a02 | 1539 | struct bnx2fc_interface *interface = NULL; |
853e2bd2 BG |
1540 | int rc = 0; |
1541 | ||
6702ca1d | 1542 | rtnl_lock(); |
853e2bd2 | 1543 | mutex_lock(&bnx2fc_dev_lock); |
853e2bd2 | 1544 | |
aea71a02 BPG |
1545 | interface = bnx2fc_interface_lookup(netdev); |
1546 | if (!interface || !interface->ctlr.lp) { | |
853e2bd2 | 1547 | rc = -ENODEV; |
aea71a02 | 1548 | printk(KERN_ERR PFX "bnx2fc_destroy: interface or lport not found\n"); |
853e2bd2 BG |
1549 | goto netdev_err; |
1550 | } | |
1551 | ||
853e2bd2 | 1552 | |
aea71a02 | 1553 | destroy_workqueue(interface->timer_work_queue); |
eccdcd02 | 1554 | __bnx2fc_destroy(interface); |
853e2bd2 | 1555 | |
853e2bd2 BG |
1556 | netdev_err: |
1557 | mutex_unlock(&bnx2fc_dev_lock); | |
1558 | rtnl_unlock(); | |
1559 | return rc; | |
1560 | } | |
1561 | ||
1562 | static void bnx2fc_destroy_work(struct work_struct *work) | |
1563 | { | |
1564 | struct fcoe_port *port; | |
1565 | struct fc_lport *lport; | |
1566 | ||
1567 | port = container_of(work, struct fcoe_port, destroy_work); | |
1568 | lport = port->lport; | |
1569 | ||
1570 | BNX2FC_HBA_DBG(lport, "Entered bnx2fc_destroy_work\n"); | |
1571 | ||
9be17fc4 | 1572 | bnx2fc_if_destroy(lport); |
853e2bd2 BG |
1573 | } |
1574 | ||
1575 | static void bnx2fc_unbind_adapter_devices(struct bnx2fc_hba *hba) | |
1576 | { | |
1577 | bnx2fc_free_fw_resc(hba); | |
1578 | bnx2fc_free_task_ctx(hba); | |
1579 | } | |
1580 | ||
1581 | /** | |
1582 | * bnx2fc_bind_adapter_devices - binds bnx2fc adapter with the associated | |
1583 | * pci structure | |
1584 | * | |
1585 | * @hba: Adapter instance | |
1586 | */ | |
1587 | static int bnx2fc_bind_adapter_devices(struct bnx2fc_hba *hba) | |
1588 | { | |
1589 | if (bnx2fc_setup_task_ctx(hba)) | |
1590 | goto mem_err; | |
1591 | ||
1592 | if (bnx2fc_setup_fw_resc(hba)) | |
1593 | goto mem_err; | |
1594 | ||
1595 | return 0; | |
1596 | mem_err: | |
1597 | bnx2fc_unbind_adapter_devices(hba); | |
1598 | return -ENOMEM; | |
1599 | } | |
1600 | ||
1601 | static int bnx2fc_bind_pcidev(struct bnx2fc_hba *hba) | |
1602 | { | |
1603 | struct cnic_dev *cnic; | |
1604 | ||
1605 | if (!hba->cnic) { | |
1606 | printk(KERN_ERR PFX "cnic is NULL\n"); | |
1607 | return -ENODEV; | |
1608 | } | |
1609 | cnic = hba->cnic; | |
1610 | hba->pcidev = cnic->pcidev; | |
1611 | if (hba->pcidev) | |
1612 | pci_dev_get(hba->pcidev); | |
1613 | ||
1614 | return 0; | |
1615 | } | |
1616 | ||
1617 | static void bnx2fc_unbind_pcidev(struct bnx2fc_hba *hba) | |
1618 | { | |
1619 | if (hba->pcidev) | |
1620 | pci_dev_put(hba->pcidev); | |
1621 | hba->pcidev = NULL; | |
1622 | } | |
1623 | ||
1624 | ||
1625 | ||
1626 | /** | |
1627 | * bnx2fc_ulp_start - cnic callback to initialize & start adapter instance | |
1628 | * | |
1629 | * @handle: transport handle pointing to adapter struture | |
1630 | * | |
1631 | * This function maps adapter structure to pcidev structure and initiates | |
1632 | * firmware handshake to enable/initialize on-chip FCoE components. | |
1633 | * This bnx2fc - cnic interface api callback is used after following | |
1634 | * conditions are met - | |
1635 | * a) underlying network interface is up (marked by event NETDEV_UP | |
1636 | * from netdev | |
1637 | * b) bnx2fc adatper structure is registered. | |
1638 | */ | |
1639 | static void bnx2fc_ulp_start(void *handle) | |
1640 | { | |
1641 | struct bnx2fc_hba *hba = handle; | |
aea71a02 BPG |
1642 | struct bnx2fc_interface *interface; |
1643 | struct fc_lport *lport; | |
853e2bd2 | 1644 | |
853e2bd2 BG |
1645 | mutex_lock(&bnx2fc_dev_lock); |
1646 | ||
aea71a02 | 1647 | if (!test_bit(BNX2FC_FLAG_FW_INIT_DONE, &hba->flags)) |
853e2bd2 BG |
1648 | bnx2fc_fw_init(hba); |
1649 | ||
853e2bd2 BG |
1650 | BNX2FC_MISC_DBG("bnx2fc started.\n"); |
1651 | ||
aea71a02 BPG |
1652 | list_for_each_entry(interface, &if_list, list) { |
1653 | if (interface->hba == hba) { | |
1654 | lport = interface->ctlr.lp; | |
1655 | /* Kick off Fabric discovery*/ | |
1656 | printk(KERN_ERR PFX "ulp_init: start discovery\n"); | |
1657 | lport->tt.frame_send = bnx2fc_xmit; | |
1658 | bnx2fc_start_disc(interface); | |
1659 | } | |
853e2bd2 | 1660 | } |
aea71a02 BPG |
1661 | |
1662 | mutex_unlock(&bnx2fc_dev_lock); | |
853e2bd2 BG |
1663 | } |
1664 | ||
1665 | static void bnx2fc_port_shutdown(struct fc_lport *lport) | |
1666 | { | |
1667 | BNX2FC_MISC_DBG("Entered %s\n", __func__); | |
1668 | fc_fabric_logoff(lport); | |
1669 | fc_lport_destroy(lport); | |
1670 | } | |
1671 | ||
aea71a02 | 1672 | static void bnx2fc_stop(struct bnx2fc_interface *interface) |
853e2bd2 BG |
1673 | { |
1674 | struct fc_lport *lport; | |
1675 | struct fc_lport *vport; | |
1676 | ||
aea71a02 BPG |
1677 | if (!test_bit(BNX2FC_FLAG_FW_INIT_DONE, &interface->hba->flags)) |
1678 | return; | |
853e2bd2 | 1679 | |
aea71a02 BPG |
1680 | lport = interface->ctlr.lp; |
1681 | bnx2fc_port_shutdown(lport); | |
1682 | ||
1683 | mutex_lock(&lport->lp_mutex); | |
1684 | list_for_each_entry(vport, &lport->vports, list) | |
1685 | fc_host_port_type(vport->host) = | |
1686 | FC_PORTTYPE_UNKNOWN; | |
1687 | mutex_unlock(&lport->lp_mutex); | |
1688 | fc_host_port_type(lport->host) = FC_PORTTYPE_UNKNOWN; | |
1689 | fcoe_ctlr_link_down(&interface->ctlr); | |
1690 | fcoe_clean_pending_queue(lport); | |
853e2bd2 BG |
1691 | } |
1692 | ||
1693 | static int bnx2fc_fw_init(struct bnx2fc_hba *hba) | |
1694 | { | |
1695 | #define BNX2FC_INIT_POLL_TIME (1000 / HZ) | |
1696 | int rc = -1; | |
1697 | int i = HZ; | |
1698 | ||
1699 | rc = bnx2fc_bind_adapter_devices(hba); | |
1700 | if (rc) { | |
1701 | printk(KERN_ALERT PFX | |
1702 | "bnx2fc_bind_adapter_devices failed - rc = %d\n", rc); | |
1703 | goto err_out; | |
1704 | } | |
1705 | ||
1706 | rc = bnx2fc_send_fw_fcoe_init_msg(hba); | |
1707 | if (rc) { | |
1708 | printk(KERN_ALERT PFX | |
1709 | "bnx2fc_send_fw_fcoe_init_msg failed - rc = %d\n", rc); | |
1710 | goto err_unbind; | |
1711 | } | |
1712 | ||
1713 | /* | |
1714 | * Wait until the adapter init message is complete, and adapter | |
1715 | * state is UP. | |
1716 | */ | |
1717 | while (!test_bit(ADAPTER_STATE_UP, &hba->adapter_state) && i--) | |
1718 | msleep(BNX2FC_INIT_POLL_TIME); | |
1719 | ||
1720 | if (!test_bit(ADAPTER_STATE_UP, &hba->adapter_state)) { | |
1721 | printk(KERN_ERR PFX "bnx2fc_start: %s failed to initialize. " | |
1722 | "Ignoring...\n", | |
1723 | hba->cnic->netdev->name); | |
1724 | rc = -1; | |
1725 | goto err_unbind; | |
1726 | } | |
1727 | ||
1728 | ||
aea71a02 | 1729 | set_bit(BNX2FC_FLAG_FW_INIT_DONE, &hba->flags); |
853e2bd2 BG |
1730 | return 0; |
1731 | ||
1732 | err_unbind: | |
1733 | bnx2fc_unbind_adapter_devices(hba); | |
1734 | err_out: | |
1735 | return rc; | |
1736 | } | |
1737 | ||
1738 | static void bnx2fc_fw_destroy(struct bnx2fc_hba *hba) | |
1739 | { | |
aea71a02 | 1740 | if (test_and_clear_bit(BNX2FC_FLAG_FW_INIT_DONE, &hba->flags)) { |
853e2bd2 BG |
1741 | if (bnx2fc_send_fw_fcoe_destroy_msg(hba) == 0) { |
1742 | init_timer(&hba->destroy_timer); | |
1743 | hba->destroy_timer.expires = BNX2FC_FW_TIMEOUT + | |
1744 | jiffies; | |
1745 | hba->destroy_timer.function = bnx2fc_destroy_timer; | |
1746 | hba->destroy_timer.data = (unsigned long)hba; | |
1747 | add_timer(&hba->destroy_timer); | |
1748 | wait_event_interruptible(hba->destroy_wait, | |
aea71a02 BPG |
1749 | test_bit(BNX2FC_FLAG_DESTROY_CMPL, |
1750 | &hba->flags)); | |
cd703ae7 | 1751 | clear_bit(BNX2FC_FLAG_DESTROY_CMPL, &hba->flags); |
853e2bd2 BG |
1752 | /* This should never happen */ |
1753 | if (signal_pending(current)) | |
1754 | flush_signals(current); | |
1755 | ||
1756 | del_timer_sync(&hba->destroy_timer); | |
1757 | } | |
1758 | bnx2fc_unbind_adapter_devices(hba); | |
1759 | } | |
1760 | } | |
1761 | ||
1762 | /** | |
1763 | * bnx2fc_ulp_stop - cnic callback to shutdown adapter instance | |
1764 | * | |
1765 | * @handle: transport handle pointing to adapter structure | |
1766 | * | |
1767 | * Driver checks if adapter is already in shutdown mode, if not start | |
1768 | * the shutdown process. | |
1769 | */ | |
1770 | static void bnx2fc_ulp_stop(void *handle) | |
1771 | { | |
aea71a02 BPG |
1772 | struct bnx2fc_hba *hba = handle; |
1773 | struct bnx2fc_interface *interface; | |
853e2bd2 BG |
1774 | |
1775 | printk(KERN_ERR "ULP_STOP\n"); | |
1776 | ||
1777 | mutex_lock(&bnx2fc_dev_lock); | |
aea71a02 BPG |
1778 | if (!test_bit(BNX2FC_FLAG_FW_INIT_DONE, &hba->flags)) |
1779 | goto exit; | |
1780 | list_for_each_entry(interface, &if_list, list) { | |
1781 | if (interface->hba == hba) | |
1782 | bnx2fc_stop(interface); | |
1783 | } | |
1784 | BUG_ON(hba->num_ofld_sess != 0); | |
1785 | ||
1786 | mutex_lock(&hba->hba_mutex); | |
1787 | clear_bit(ADAPTER_STATE_UP, &hba->adapter_state); | |
1788 | clear_bit(ADAPTER_STATE_GOING_DOWN, | |
1789 | &hba->adapter_state); | |
1790 | ||
1791 | clear_bit(ADAPTER_STATE_READY, &hba->adapter_state); | |
1792 | mutex_unlock(&hba->hba_mutex); | |
1793 | ||
853e2bd2 | 1794 | bnx2fc_fw_destroy(hba); |
aea71a02 | 1795 | exit: |
853e2bd2 BG |
1796 | mutex_unlock(&bnx2fc_dev_lock); |
1797 | } | |
1798 | ||
aea71a02 | 1799 | static void bnx2fc_start_disc(struct bnx2fc_interface *interface) |
853e2bd2 BG |
1800 | { |
1801 | struct fc_lport *lport; | |
1802 | int wait_cnt = 0; | |
1803 | ||
1804 | BNX2FC_MISC_DBG("Entered %s\n", __func__); | |
1805 | /* Kick off FIP/FLOGI */ | |
aea71a02 | 1806 | if (!test_bit(BNX2FC_FLAG_FW_INIT_DONE, &interface->hba->flags)) { |
853e2bd2 BG |
1807 | printk(KERN_ERR PFX "Init not done yet\n"); |
1808 | return; | |
1809 | } | |
1810 | ||
aea71a02 | 1811 | lport = interface->ctlr.lp; |
853e2bd2 BG |
1812 | BNX2FC_HBA_DBG(lport, "calling fc_fabric_login\n"); |
1813 | ||
8a5badf1 | 1814 | if (!bnx2fc_link_ok(lport) && interface->enabled) { |
853e2bd2 | 1815 | BNX2FC_HBA_DBG(lport, "ctlr_link_up\n"); |
aea71a02 | 1816 | fcoe_ctlr_link_up(&interface->ctlr); |
853e2bd2 | 1817 | fc_host_port_type(lport->host) = FC_PORTTYPE_NPORT; |
aea71a02 | 1818 | set_bit(ADAPTER_STATE_READY, &interface->hba->adapter_state); |
853e2bd2 BG |
1819 | } |
1820 | ||
1821 | /* wait for the FCF to be selected before issuing FLOGI */ | |
aea71a02 | 1822 | while (!interface->ctlr.sel_fcf) { |
853e2bd2 BG |
1823 | msleep(250); |
1824 | /* give up after 3 secs */ | |
1825 | if (++wait_cnt > 12) | |
1826 | break; | |
1827 | } | |
627e628f BPG |
1828 | |
1829 | /* Reset max receive frame size to default */ | |
1830 | if (fc_set_mfs(lport, BNX2FC_MFS)) | |
1831 | return; | |
1832 | ||
853e2bd2 BG |
1833 | fc_lport_init(lport); |
1834 | fc_fabric_login(lport); | |
1835 | } | |
1836 | ||
1837 | ||
1838 | /** | |
1839 | * bnx2fc_ulp_init - Initialize an adapter instance | |
1840 | * | |
1841 | * @dev : cnic device handle | |
1842 | * Called from cnic_register_driver() context to initialize all | |
1843 | * enumerated cnic devices. This routine allocates adapter structure | |
1844 | * and other device specific resources. | |
1845 | */ | |
1846 | static void bnx2fc_ulp_init(struct cnic_dev *dev) | |
1847 | { | |
1848 | struct bnx2fc_hba *hba; | |
1849 | int rc = 0; | |
1850 | ||
1851 | BNX2FC_MISC_DBG("Entered %s\n", __func__); | |
1852 | /* bnx2fc works only when bnx2x is loaded */ | |
aea71a02 BPG |
1853 | if (!test_bit(CNIC_F_BNX2X_CLASS, &dev->flags) || |
1854 | (dev->max_fcoe_conn == 0)) { | |
853e2bd2 | 1855 | printk(KERN_ERR PFX "bnx2fc FCoE not supported on %s," |
aea71a02 BPG |
1856 | " flags: %lx fcoe_conn: %d\n", |
1857 | dev->netdev->name, dev->flags, dev->max_fcoe_conn); | |
853e2bd2 BG |
1858 | return; |
1859 | } | |
1860 | ||
aea71a02 | 1861 | hba = bnx2fc_hba_create(dev); |
853e2bd2 BG |
1862 | if (!hba) { |
1863 | printk(KERN_ERR PFX "hba initialization failed\n"); | |
1864 | return; | |
1865 | } | |
1866 | ||
1867 | /* Add HBA to the adapter list */ | |
1868 | mutex_lock(&bnx2fc_dev_lock); | |
aea71a02 | 1869 | list_add_tail(&hba->list, &adapter_list); |
853e2bd2 BG |
1870 | adapter_count++; |
1871 | mutex_unlock(&bnx2fc_dev_lock); | |
1872 | ||
1873 | clear_bit(BNX2FC_CNIC_REGISTERED, &hba->reg_with_cnic); | |
1874 | rc = dev->register_device(dev, CNIC_ULP_FCOE, | |
1875 | (void *) hba); | |
1876 | if (rc) | |
b2a554ff | 1877 | printk(KERN_ERR PFX "register_device failed, rc = %d\n", rc); |
853e2bd2 BG |
1878 | else |
1879 | set_bit(BNX2FC_CNIC_REGISTERED, &hba->reg_with_cnic); | |
1880 | } | |
1881 | ||
1882 | ||
1883 | static int bnx2fc_disable(struct net_device *netdev) | |
1884 | { | |
aea71a02 | 1885 | struct bnx2fc_interface *interface; |
853e2bd2 BG |
1886 | int rc = 0; |
1887 | ||
6702ca1d | 1888 | rtnl_lock(); |
853e2bd2 BG |
1889 | mutex_lock(&bnx2fc_dev_lock); |
1890 | ||
aea71a02 BPG |
1891 | interface = bnx2fc_interface_lookup(netdev); |
1892 | if (!interface || !interface->ctlr.lp) { | |
853e2bd2 | 1893 | rc = -ENODEV; |
aea71a02 | 1894 | printk(KERN_ERR PFX "bnx2fc_disable: interface or lport not found\n"); |
853e2bd2 | 1895 | } else { |
8a5badf1 | 1896 | interface->enabled = false; |
aea71a02 BPG |
1897 | fcoe_ctlr_link_down(&interface->ctlr); |
1898 | fcoe_clean_pending_queue(interface->ctlr.lp); | |
853e2bd2 BG |
1899 | } |
1900 | ||
853e2bd2 BG |
1901 | mutex_unlock(&bnx2fc_dev_lock); |
1902 | rtnl_unlock(); | |
1903 | return rc; | |
1904 | } | |
1905 | ||
1906 | ||
1907 | static int bnx2fc_enable(struct net_device *netdev) | |
1908 | { | |
aea71a02 | 1909 | struct bnx2fc_interface *interface; |
853e2bd2 BG |
1910 | int rc = 0; |
1911 | ||
6702ca1d | 1912 | rtnl_lock(); |
853e2bd2 BG |
1913 | mutex_lock(&bnx2fc_dev_lock); |
1914 | ||
aea71a02 BPG |
1915 | interface = bnx2fc_interface_lookup(netdev); |
1916 | if (!interface || !interface->ctlr.lp) { | |
853e2bd2 | 1917 | rc = -ENODEV; |
aea71a02 | 1918 | printk(KERN_ERR PFX "bnx2fc_enable: interface or lport not found\n"); |
8a5badf1 | 1919 | } else if (!bnx2fc_link_ok(interface->ctlr.lp)) { |
aea71a02 | 1920 | fcoe_ctlr_link_up(&interface->ctlr); |
8a5badf1 BPG |
1921 | interface->enabled = true; |
1922 | } | |
853e2bd2 | 1923 | |
853e2bd2 BG |
1924 | mutex_unlock(&bnx2fc_dev_lock); |
1925 | rtnl_unlock(); | |
1926 | return rc; | |
1927 | } | |
1928 | ||
1929 | /** | |
1930 | * bnx2fc_create - Create bnx2fc FCoE interface | |
1931 | * | |
1932 | * @buffer: The name of Ethernet interface to create on | |
1933 | * @kp: The associated kernel param | |
1934 | * | |
1935 | * Called from sysfs. | |
1936 | * | |
1937 | * Returns: 0 for success | |
1938 | */ | |
1939 | static int bnx2fc_create(struct net_device *netdev, enum fip_state fip_mode) | |
1940 | { | |
aea71a02 | 1941 | struct bnx2fc_interface *interface; |
853e2bd2 BG |
1942 | struct bnx2fc_hba *hba; |
1943 | struct net_device *phys_dev; | |
1944 | struct fc_lport *lport; | |
1945 | struct ethtool_drvinfo drvinfo; | |
1946 | int rc = 0; | |
1947 | int vlan_id; | |
1948 | ||
1949 | BNX2FC_MISC_DBG("Entered bnx2fc_create\n"); | |
1950 | if (fip_mode != FIP_MODE_FABRIC) { | |
1951 | printk(KERN_ERR "fip mode not FABRIC\n"); | |
1952 | return -EIO; | |
1953 | } | |
1954 | ||
6702ca1d NS |
1955 | rtnl_lock(); |
1956 | ||
853e2bd2 BG |
1957 | mutex_lock(&bnx2fc_dev_lock); |
1958 | ||
853e2bd2 BG |
1959 | if (!try_module_get(THIS_MODULE)) { |
1960 | rc = -EINVAL; | |
1961 | goto mod_err; | |
1962 | } | |
1963 | ||
1964 | /* obtain physical netdev */ | |
1965 | if (netdev->priv_flags & IFF_802_1Q_VLAN) { | |
1966 | phys_dev = vlan_dev_real_dev(netdev); | |
1967 | vlan_id = vlan_dev_vlan_id(netdev); | |
1968 | } else { | |
1969 | printk(KERN_ERR PFX "Not a vlan device\n"); | |
1970 | rc = -EINVAL; | |
1971 | goto netdev_err; | |
1972 | } | |
1973 | /* verify if the physical device is a netxtreme2 device */ | |
1974 | if (phys_dev->ethtool_ops && phys_dev->ethtool_ops->get_drvinfo) { | |
1975 | memset(&drvinfo, 0, sizeof(drvinfo)); | |
1976 | phys_dev->ethtool_ops->get_drvinfo(phys_dev, &drvinfo); | |
aea71a02 | 1977 | if (strncmp(drvinfo.driver, "bnx2x", strlen("bnx2x"))) { |
853e2bd2 BG |
1978 | printk(KERN_ERR PFX "Not a netxtreme2 device\n"); |
1979 | rc = -EINVAL; | |
1980 | goto netdev_err; | |
1981 | } | |
1982 | } else { | |
1983 | printk(KERN_ERR PFX "unable to obtain drv_info\n"); | |
1984 | rc = -EINVAL; | |
1985 | goto netdev_err; | |
1986 | } | |
1987 | ||
aea71a02 | 1988 | /* obtain interface and initialize rest of the structure */ |
853e2bd2 BG |
1989 | hba = bnx2fc_hba_lookup(phys_dev); |
1990 | if (!hba) { | |
1991 | rc = -ENODEV; | |
1992 | printk(KERN_ERR PFX "bnx2fc_create: hba not found\n"); | |
1993 | goto netdev_err; | |
1994 | } | |
1995 | ||
aea71a02 | 1996 | if (bnx2fc_interface_lookup(netdev)) { |
853e2bd2 BG |
1997 | rc = -EEXIST; |
1998 | goto netdev_err; | |
1999 | } | |
2000 | ||
aea71a02 BPG |
2001 | interface = bnx2fc_interface_create(hba, netdev, fip_mode); |
2002 | if (!interface) { | |
2003 | printk(KERN_ERR PFX "bnx2fc_interface_create failed\n"); | |
853e2bd2 BG |
2004 | goto ifput_err; |
2005 | } | |
2006 | ||
aea71a02 BPG |
2007 | interface->vlan_id = vlan_id; |
2008 | interface->vlan_enabled = 1; | |
2009 | ||
2010 | interface->timer_work_queue = | |
853e2bd2 | 2011 | create_singlethread_workqueue("bnx2fc_timer_wq"); |
aea71a02 | 2012 | if (!interface->timer_work_queue) { |
853e2bd2 BG |
2013 | printk(KERN_ERR PFX "ulp_init could not create timer_wq\n"); |
2014 | rc = -EINVAL; | |
2015 | goto ifput_err; | |
2016 | } | |
2017 | ||
aea71a02 | 2018 | lport = bnx2fc_if_create(interface, &interface->hba->pcidev->dev, 0); |
853e2bd2 BG |
2019 | if (!lport) { |
2020 | printk(KERN_ERR PFX "Failed to create interface (%s)\n", | |
2021 | netdev->name); | |
853e2bd2 BG |
2022 | rc = -EINVAL; |
2023 | goto if_create_err; | |
2024 | } | |
2025 | ||
aea71a02 BPG |
2026 | /* Add interface to if_list */ |
2027 | list_add_tail(&interface->list, &if_list); | |
2028 | ||
853e2bd2 BG |
2029 | lport->boot_time = jiffies; |
2030 | ||
2031 | /* Make this master N_port */ | |
aea71a02 | 2032 | interface->ctlr.lp = lport; |
853e2bd2 | 2033 | |
8a5badf1 BPG |
2034 | if (!bnx2fc_link_ok(lport)) { |
2035 | fcoe_ctlr_link_up(&interface->ctlr); | |
2036 | fc_host_port_type(lport->host) = FC_PORTTYPE_NPORT; | |
2037 | set_bit(ADAPTER_STATE_READY, &interface->hba->adapter_state); | |
2038 | } | |
2039 | ||
aea71a02 BPG |
2040 | BNX2FC_HBA_DBG(lport, "create: START DISC\n"); |
2041 | bnx2fc_start_disc(interface); | |
8a5badf1 | 2042 | interface->enabled = true; |
853e2bd2 BG |
2043 | /* |
2044 | * Release from kref_init in bnx2fc_interface_setup, on success | |
2045 | * lport should be holding a reference taken in bnx2fc_if_create | |
2046 | */ | |
aea71a02 | 2047 | bnx2fc_interface_put(interface); |
853e2bd2 BG |
2048 | /* put netdev that was held while calling dev_get_by_name */ |
2049 | mutex_unlock(&bnx2fc_dev_lock); | |
2050 | rtnl_unlock(); | |
2051 | return 0; | |
2052 | ||
2053 | if_create_err: | |
aea71a02 | 2054 | destroy_workqueue(interface->timer_work_queue); |
853e2bd2 | 2055 | ifput_err: |
013068fa | 2056 | bnx2fc_net_cleanup(interface); |
aea71a02 | 2057 | bnx2fc_interface_put(interface); |
853e2bd2 BG |
2058 | netdev_err: |
2059 | module_put(THIS_MODULE); | |
2060 | mod_err: | |
2061 | mutex_unlock(&bnx2fc_dev_lock); | |
2062 | rtnl_unlock(); | |
2063 | return rc; | |
2064 | } | |
2065 | ||
2066 | /** | |
aea71a02 | 2067 | * bnx2fc_find_hba_for_cnic - maps cnic instance to bnx2fc hba instance |
853e2bd2 BG |
2068 | * |
2069 | * @cnic: Pointer to cnic device instance | |
2070 | * | |
2071 | **/ | |
2072 | static struct bnx2fc_hba *bnx2fc_find_hba_for_cnic(struct cnic_dev *cnic) | |
2073 | { | |
2074 | struct list_head *list; | |
2075 | struct list_head *temp; | |
2076 | struct bnx2fc_hba *hba; | |
2077 | ||
2078 | /* Called with bnx2fc_dev_lock held */ | |
2079 | list_for_each_safe(list, temp, &adapter_list) { | |
2080 | hba = (struct bnx2fc_hba *)list; | |
2081 | if (hba->cnic == cnic) | |
2082 | return hba; | |
2083 | } | |
2084 | return NULL; | |
2085 | } | |
2086 | ||
aea71a02 BPG |
2087 | static struct bnx2fc_interface *bnx2fc_interface_lookup(struct net_device |
2088 | *netdev) | |
2089 | { | |
2090 | struct bnx2fc_interface *interface; | |
2091 | ||
2092 | /* Called with bnx2fc_dev_lock held */ | |
2093 | list_for_each_entry(interface, &if_list, list) { | |
2094 | if (interface->netdev == netdev) | |
2095 | return interface; | |
2096 | } | |
2097 | return NULL; | |
2098 | } | |
2099 | ||
2100 | static struct bnx2fc_hba *bnx2fc_hba_lookup(struct net_device | |
2101 | *phys_dev) | |
853e2bd2 | 2102 | { |
853e2bd2 BG |
2103 | struct bnx2fc_hba *hba; |
2104 | ||
2105 | /* Called with bnx2fc_dev_lock held */ | |
aea71a02 | 2106 | list_for_each_entry(hba, &adapter_list, list) { |
853e2bd2 BG |
2107 | if (hba->phys_dev == phys_dev) |
2108 | return hba; | |
2109 | } | |
aea71a02 | 2110 | printk(KERN_ERR PFX "adapter_lookup: hba NULL\n"); |
853e2bd2 BG |
2111 | return NULL; |
2112 | } | |
2113 | ||
2114 | /** | |
2115 | * bnx2fc_ulp_exit - shuts down adapter instance and frees all resources | |
2116 | * | |
2117 | * @dev cnic device handle | |
2118 | */ | |
2119 | static void bnx2fc_ulp_exit(struct cnic_dev *dev) | |
2120 | { | |
2121 | struct bnx2fc_hba *hba; | |
aea71a02 | 2122 | struct bnx2fc_interface *interface, *tmp; |
853e2bd2 BG |
2123 | |
2124 | BNX2FC_MISC_DBG("Entered bnx2fc_ulp_exit\n"); | |
2125 | ||
2126 | if (!test_bit(CNIC_F_BNX2X_CLASS, &dev->flags)) { | |
2127 | printk(KERN_ERR PFX "bnx2fc port check: %s, flags: %lx\n", | |
2128 | dev->netdev->name, dev->flags); | |
2129 | return; | |
2130 | } | |
2131 | ||
2132 | mutex_lock(&bnx2fc_dev_lock); | |
2133 | hba = bnx2fc_find_hba_for_cnic(dev); | |
2134 | if (!hba) { | |
2135 | printk(KERN_ERR PFX "bnx2fc_ulp_exit: hba not found, dev 0%p\n", | |
2136 | dev); | |
2137 | mutex_unlock(&bnx2fc_dev_lock); | |
2138 | return; | |
2139 | } | |
2140 | ||
aea71a02 | 2141 | list_del_init(&hba->list); |
853e2bd2 BG |
2142 | adapter_count--; |
2143 | ||
abc49a93 | 2144 | list_for_each_entry_safe(interface, tmp, &if_list, list) |
853e2bd2 | 2145 | /* destroy not called yet, move to quiesced list */ |
abc49a93 | 2146 | if (interface->hba == hba) |
eccdcd02 | 2147 | __bnx2fc_destroy(interface); |
853e2bd2 BG |
2148 | mutex_unlock(&bnx2fc_dev_lock); |
2149 | ||
2150 | bnx2fc_ulp_stop(hba); | |
2151 | /* unregister cnic device */ | |
2152 | if (test_and_clear_bit(BNX2FC_CNIC_REGISTERED, &hba->reg_with_cnic)) | |
2153 | hba->cnic->unregister_device(hba->cnic, CNIC_ULP_FCOE); | |
aea71a02 | 2154 | bnx2fc_hba_destroy(hba); |
853e2bd2 BG |
2155 | } |
2156 | ||
2157 | /** | |
2158 | * bnx2fc_fcoe_reset - Resets the fcoe | |
2159 | * | |
2160 | * @shost: shost the reset is from | |
2161 | * | |
2162 | * Returns: always 0 | |
2163 | */ | |
2164 | static int bnx2fc_fcoe_reset(struct Scsi_Host *shost) | |
2165 | { | |
2166 | struct fc_lport *lport = shost_priv(shost); | |
2167 | fc_lport_reset(lport); | |
2168 | return 0; | |
2169 | } | |
2170 | ||
2171 | ||
2172 | static bool bnx2fc_match(struct net_device *netdev) | |
2173 | { | |
2174 | mutex_lock(&bnx2fc_dev_lock); | |
2175 | if (netdev->priv_flags & IFF_802_1Q_VLAN) { | |
2176 | struct net_device *phys_dev = vlan_dev_real_dev(netdev); | |
2177 | ||
2178 | if (bnx2fc_hba_lookup(phys_dev)) { | |
2179 | mutex_unlock(&bnx2fc_dev_lock); | |
2180 | return true; | |
2181 | } | |
2182 | } | |
2183 | mutex_unlock(&bnx2fc_dev_lock); | |
2184 | return false; | |
2185 | } | |
2186 | ||
2187 | ||
2188 | static struct fcoe_transport bnx2fc_transport = { | |
2189 | .name = {"bnx2fc"}, | |
2190 | .attached = false, | |
2191 | .list = LIST_HEAD_INIT(bnx2fc_transport.list), | |
2192 | .match = bnx2fc_match, | |
2193 | .create = bnx2fc_create, | |
2194 | .destroy = bnx2fc_destroy, | |
2195 | .enable = bnx2fc_enable, | |
2196 | .disable = bnx2fc_disable, | |
2197 | }; | |
2198 | ||
2199 | /** | |
2200 | * bnx2fc_percpu_thread_create - Create a receive thread for an | |
2201 | * online CPU | |
2202 | * | |
2203 | * @cpu: cpu index for the online cpu | |
2204 | */ | |
2205 | static void bnx2fc_percpu_thread_create(unsigned int cpu) | |
2206 | { | |
2207 | struct bnx2fc_percpu_s *p; | |
2208 | struct task_struct *thread; | |
2209 | ||
2210 | p = &per_cpu(bnx2fc_percpu, cpu); | |
2211 | ||
2212 | thread = kthread_create(bnx2fc_percpu_io_thread, | |
2213 | (void *)p, | |
2214 | "bnx2fc_thread/%d", cpu); | |
2215 | /* bind thread to the cpu */ | |
32248763 | 2216 | if (likely(!IS_ERR(thread))) { |
853e2bd2 BG |
2217 | kthread_bind(thread, cpu); |
2218 | p->iothread = thread; | |
2219 | wake_up_process(thread); | |
2220 | } | |
2221 | } | |
2222 | ||
2223 | static void bnx2fc_percpu_thread_destroy(unsigned int cpu) | |
2224 | { | |
2225 | struct bnx2fc_percpu_s *p; | |
2226 | struct task_struct *thread; | |
2227 | struct bnx2fc_work *work, *tmp; | |
853e2bd2 BG |
2228 | |
2229 | BNX2FC_MISC_DBG("destroying io thread for CPU %d\n", cpu); | |
2230 | ||
2231 | /* Prevent any new work from being queued for this CPU */ | |
2232 | p = &per_cpu(bnx2fc_percpu, cpu); | |
2233 | spin_lock_bh(&p->fp_work_lock); | |
2234 | thread = p->iothread; | |
2235 | p->iothread = NULL; | |
2236 | ||
2237 | ||
2238 | /* Free all work in the list */ | |
32248763 | 2239 | list_for_each_entry_safe(work, tmp, &p->work_list, list) { |
853e2bd2 BG |
2240 | list_del_init(&work->list); |
2241 | bnx2fc_process_cq_compl(work->tgt, work->wqe); | |
2242 | kfree(work); | |
2243 | } | |
2244 | ||
2245 | spin_unlock_bh(&p->fp_work_lock); | |
2246 | ||
2247 | if (thread) | |
2248 | kthread_stop(thread); | |
2249 | } | |
2250 | ||
2251 | /** | |
2252 | * bnx2fc_cpu_callback - Handler for CPU hotplug events | |
2253 | * | |
2254 | * @nfb: The callback data block | |
2255 | * @action: The event triggering the callback | |
2256 | * @hcpu: The index of the CPU that the event is for | |
2257 | * | |
2258 | * This creates or destroys per-CPU data for fcoe | |
2259 | * | |
2260 | * Returns NOTIFY_OK always. | |
2261 | */ | |
2262 | static int bnx2fc_cpu_callback(struct notifier_block *nfb, | |
2263 | unsigned long action, void *hcpu) | |
2264 | { | |
2265 | unsigned cpu = (unsigned long)hcpu; | |
2266 | ||
2267 | switch (action) { | |
2268 | case CPU_ONLINE: | |
2269 | case CPU_ONLINE_FROZEN: | |
2270 | printk(PFX "CPU %x online: Create Rx thread\n", cpu); | |
2271 | bnx2fc_percpu_thread_create(cpu); | |
2272 | break; | |
2273 | case CPU_DEAD: | |
2274 | case CPU_DEAD_FROZEN: | |
2275 | printk(PFX "CPU %x offline: Remove Rx thread\n", cpu); | |
2276 | bnx2fc_percpu_thread_destroy(cpu); | |
2277 | break; | |
2278 | default: | |
2279 | break; | |
2280 | } | |
2281 | return NOTIFY_OK; | |
2282 | } | |
2283 | ||
2284 | /** | |
2285 | * bnx2fc_mod_init - module init entry point | |
2286 | * | |
2287 | * Initialize driver wide global data structures, and register | |
2288 | * with cnic module | |
2289 | **/ | |
2290 | static int __init bnx2fc_mod_init(void) | |
2291 | { | |
2292 | struct fcoe_percpu_s *bg; | |
2293 | struct task_struct *l2_thread; | |
2294 | int rc = 0; | |
2295 | unsigned int cpu = 0; | |
2296 | struct bnx2fc_percpu_s *p; | |
2297 | ||
2298 | printk(KERN_INFO PFX "%s", version); | |
2299 | ||
2300 | /* register as a fcoe transport */ | |
2301 | rc = fcoe_transport_attach(&bnx2fc_transport); | |
2302 | if (rc) { | |
2303 | printk(KERN_ERR "failed to register an fcoe transport, check " | |
2304 | "if libfcoe is loaded\n"); | |
2305 | goto out; | |
2306 | } | |
2307 | ||
2308 | INIT_LIST_HEAD(&adapter_list); | |
aea71a02 | 2309 | INIT_LIST_HEAD(&if_list); |
853e2bd2 BG |
2310 | mutex_init(&bnx2fc_dev_lock); |
2311 | adapter_count = 0; | |
2312 | ||
2313 | /* Attach FC transport template */ | |
2314 | rc = bnx2fc_attach_transport(); | |
2315 | if (rc) | |
2316 | goto detach_ft; | |
2317 | ||
2318 | bnx2fc_wq = alloc_workqueue("bnx2fc", 0, 0); | |
2319 | if (!bnx2fc_wq) { | |
2320 | rc = -ENOMEM; | |
2321 | goto release_bt; | |
2322 | } | |
2323 | ||
2324 | bg = &bnx2fc_global; | |
2325 | skb_queue_head_init(&bg->fcoe_rx_list); | |
2326 | l2_thread = kthread_create(bnx2fc_l2_rcv_thread, | |
2327 | (void *)bg, | |
2328 | "bnx2fc_l2_thread"); | |
2329 | if (IS_ERR(l2_thread)) { | |
2330 | rc = PTR_ERR(l2_thread); | |
2331 | goto free_wq; | |
2332 | } | |
2333 | wake_up_process(l2_thread); | |
2334 | spin_lock_bh(&bg->fcoe_rx_list.lock); | |
2335 | bg->thread = l2_thread; | |
2336 | spin_unlock_bh(&bg->fcoe_rx_list.lock); | |
2337 | ||
2338 | for_each_possible_cpu(cpu) { | |
2339 | p = &per_cpu(bnx2fc_percpu, cpu); | |
2340 | INIT_LIST_HEAD(&p->work_list); | |
2341 | spin_lock_init(&p->fp_work_lock); | |
2342 | } | |
2343 | ||
2344 | for_each_online_cpu(cpu) { | |
2345 | bnx2fc_percpu_thread_create(cpu); | |
2346 | } | |
2347 | ||
2348 | /* Initialize per CPU interrupt thread */ | |
2349 | register_hotcpu_notifier(&bnx2fc_cpu_notifier); | |
2350 | ||
2351 | cnic_register_driver(CNIC_ULP_FCOE, &bnx2fc_cnic_cb); | |
2352 | ||
2353 | return 0; | |
2354 | ||
2355 | free_wq: | |
2356 | destroy_workqueue(bnx2fc_wq); | |
2357 | release_bt: | |
2358 | bnx2fc_release_transport(); | |
2359 | detach_ft: | |
2360 | fcoe_transport_detach(&bnx2fc_transport); | |
2361 | out: | |
2362 | return rc; | |
2363 | } | |
2364 | ||
2365 | static void __exit bnx2fc_mod_exit(void) | |
2366 | { | |
2367 | LIST_HEAD(to_be_deleted); | |
2368 | struct bnx2fc_hba *hba, *next; | |
2369 | struct fcoe_percpu_s *bg; | |
2370 | struct task_struct *l2_thread; | |
2371 | struct sk_buff *skb; | |
2372 | unsigned int cpu = 0; | |
2373 | ||
2374 | /* | |
2375 | * NOTE: Since cnic calls register_driver routine rtnl_lock, | |
2376 | * it will have higher precedence than bnx2fc_dev_lock. | |
2377 | * unregister_device() cannot be called with bnx2fc_dev_lock | |
2378 | * held. | |
2379 | */ | |
2380 | mutex_lock(&bnx2fc_dev_lock); | |
2381 | list_splice(&adapter_list, &to_be_deleted); | |
2382 | INIT_LIST_HEAD(&adapter_list); | |
2383 | adapter_count = 0; | |
2384 | mutex_unlock(&bnx2fc_dev_lock); | |
2385 | ||
2386 | /* Unregister with cnic */ | |
aea71a02 BPG |
2387 | list_for_each_entry_safe(hba, next, &to_be_deleted, list) { |
2388 | list_del_init(&hba->list); | |
2389 | printk(KERN_ERR PFX "MOD_EXIT:destroy hba = 0x%p\n", | |
2390 | hba); | |
853e2bd2 BG |
2391 | bnx2fc_ulp_stop(hba); |
2392 | /* unregister cnic device */ | |
2393 | if (test_and_clear_bit(BNX2FC_CNIC_REGISTERED, | |
2394 | &hba->reg_with_cnic)) | |
aea71a02 BPG |
2395 | hba->cnic->unregister_device(hba->cnic, |
2396 | CNIC_ULP_FCOE); | |
2397 | bnx2fc_hba_destroy(hba); | |
853e2bd2 BG |
2398 | } |
2399 | cnic_unregister_driver(CNIC_ULP_FCOE); | |
2400 | ||
2401 | /* Destroy global thread */ | |
2402 | bg = &bnx2fc_global; | |
2403 | spin_lock_bh(&bg->fcoe_rx_list.lock); | |
2404 | l2_thread = bg->thread; | |
2405 | bg->thread = NULL; | |
2406 | while ((skb = __skb_dequeue(&bg->fcoe_rx_list)) != NULL) | |
2407 | kfree_skb(skb); | |
2408 | ||
2409 | spin_unlock_bh(&bg->fcoe_rx_list.lock); | |
2410 | ||
2411 | if (l2_thread) | |
2412 | kthread_stop(l2_thread); | |
2413 | ||
2414 | unregister_hotcpu_notifier(&bnx2fc_cpu_notifier); | |
2415 | ||
2416 | /* Destroy per cpu threads */ | |
2417 | for_each_online_cpu(cpu) { | |
2418 | bnx2fc_percpu_thread_destroy(cpu); | |
2419 | } | |
2420 | ||
2421 | destroy_workqueue(bnx2fc_wq); | |
2422 | /* | |
2423 | * detach from scsi transport | |
2424 | * must happen after all destroys are done | |
2425 | */ | |
2426 | bnx2fc_release_transport(); | |
2427 | ||
2428 | /* detach from fcoe transport */ | |
2429 | fcoe_transport_detach(&bnx2fc_transport); | |
2430 | } | |
2431 | ||
2432 | module_init(bnx2fc_mod_init); | |
2433 | module_exit(bnx2fc_mod_exit); | |
2434 | ||
2435 | static struct fc_function_template bnx2fc_transport_function = { | |
2436 | .show_host_node_name = 1, | |
2437 | .show_host_port_name = 1, | |
2438 | .show_host_supported_classes = 1, | |
2439 | .show_host_supported_fc4s = 1, | |
2440 | .show_host_active_fc4s = 1, | |
2441 | .show_host_maxframe_size = 1, | |
2442 | ||
2443 | .show_host_port_id = 1, | |
2444 | .show_host_supported_speeds = 1, | |
2445 | .get_host_speed = fc_get_host_speed, | |
2446 | .show_host_speed = 1, | |
2447 | .show_host_port_type = 1, | |
2448 | .get_host_port_state = fc_get_host_port_state, | |
2449 | .show_host_port_state = 1, | |
2450 | .show_host_symbolic_name = 1, | |
2451 | ||
2452 | .dd_fcrport_size = (sizeof(struct fc_rport_libfc_priv) + | |
2453 | sizeof(struct bnx2fc_rport)), | |
2454 | .show_rport_maxframe_size = 1, | |
2455 | .show_rport_supported_classes = 1, | |
2456 | ||
2457 | .show_host_fabric_name = 1, | |
2458 | .show_starget_node_name = 1, | |
2459 | .show_starget_port_name = 1, | |
2460 | .show_starget_port_id = 1, | |
2461 | .set_rport_dev_loss_tmo = fc_set_rport_loss_tmo, | |
2462 | .show_rport_dev_loss_tmo = 1, | |
2463 | .get_fc_host_stats = bnx2fc_get_host_stats, | |
2464 | ||
2465 | .issue_fc_host_lip = bnx2fc_fcoe_reset, | |
2466 | ||
2467 | .terminate_rport_io = fc_rport_terminate_io, | |
2468 | ||
2469 | .vport_create = bnx2fc_vport_create, | |
2470 | .vport_delete = bnx2fc_vport_destroy, | |
2471 | .vport_disable = bnx2fc_vport_disable, | |
e9a5289c | 2472 | .bsg_request = fc_lport_bsg_request, |
853e2bd2 BG |
2473 | }; |
2474 | ||
2475 | static struct fc_function_template bnx2fc_vport_xport_function = { | |
2476 | .show_host_node_name = 1, | |
2477 | .show_host_port_name = 1, | |
2478 | .show_host_supported_classes = 1, | |
2479 | .show_host_supported_fc4s = 1, | |
2480 | .show_host_active_fc4s = 1, | |
2481 | .show_host_maxframe_size = 1, | |
2482 | ||
2483 | .show_host_port_id = 1, | |
2484 | .show_host_supported_speeds = 1, | |
2485 | .get_host_speed = fc_get_host_speed, | |
2486 | .show_host_speed = 1, | |
2487 | .show_host_port_type = 1, | |
2488 | .get_host_port_state = fc_get_host_port_state, | |
2489 | .show_host_port_state = 1, | |
2490 | .show_host_symbolic_name = 1, | |
2491 | ||
2492 | .dd_fcrport_size = (sizeof(struct fc_rport_libfc_priv) + | |
2493 | sizeof(struct bnx2fc_rport)), | |
2494 | .show_rport_maxframe_size = 1, | |
2495 | .show_rport_supported_classes = 1, | |
2496 | ||
2497 | .show_host_fabric_name = 1, | |
2498 | .show_starget_node_name = 1, | |
2499 | .show_starget_port_name = 1, | |
2500 | .show_starget_port_id = 1, | |
2501 | .set_rport_dev_loss_tmo = fc_set_rport_loss_tmo, | |
2502 | .show_rport_dev_loss_tmo = 1, | |
2503 | .get_fc_host_stats = fc_get_host_stats, | |
2504 | .issue_fc_host_lip = bnx2fc_fcoe_reset, | |
2505 | .terminate_rport_io = fc_rport_terminate_io, | |
e9a5289c | 2506 | .bsg_request = fc_lport_bsg_request, |
853e2bd2 BG |
2507 | }; |
2508 | ||
2509 | /** | |
2510 | * scsi_host_template structure used while registering with SCSI-ml | |
2511 | */ | |
2512 | static struct scsi_host_template bnx2fc_shost_template = { | |
2513 | .module = THIS_MODULE, | |
2514 | .name = "Broadcom Offload FCoE Initiator", | |
2515 | .queuecommand = bnx2fc_queuecommand, | |
2516 | .eh_abort_handler = bnx2fc_eh_abort, /* abts */ | |
2517 | .eh_device_reset_handler = bnx2fc_eh_device_reset, /* lun reset */ | |
2518 | .eh_target_reset_handler = bnx2fc_eh_target_reset, /* tgt reset */ | |
2519 | .eh_host_reset_handler = fc_eh_host_reset, | |
2520 | .slave_alloc = fc_slave_alloc, | |
2521 | .change_queue_depth = fc_change_queue_depth, | |
2522 | .change_queue_type = fc_change_queue_type, | |
2523 | .this_id = -1, | |
2524 | .cmd_per_lun = 3, | |
0ea5c275 | 2525 | .can_queue = BNX2FC_CAN_QUEUE, |
853e2bd2 BG |
2526 | .use_clustering = ENABLE_CLUSTERING, |
2527 | .sg_tablesize = BNX2FC_MAX_BDS_PER_CMD, | |
2528 | .max_sectors = 512, | |
2529 | }; | |
2530 | ||
2531 | static struct libfc_function_template bnx2fc_libfc_fcn_templ = { | |
2532 | .frame_send = bnx2fc_xmit, | |
2533 | .elsct_send = bnx2fc_elsct_send, | |
2534 | .fcp_abort_io = bnx2fc_abort_io, | |
2535 | .fcp_cleanup = bnx2fc_cleanup, | |
f72f6979 | 2536 | .get_lesb = bnx2fc_get_lesb, |
853e2bd2 BG |
2537 | .rport_event_callback = bnx2fc_rport_event_handler, |
2538 | }; | |
2539 | ||
2540 | /** | |
2541 | * bnx2fc_cnic_cb - global template of bnx2fc - cnic driver interface | |
2542 | * structure carrying callback function pointers | |
2543 | */ | |
2544 | static struct cnic_ulp_ops bnx2fc_cnic_cb = { | |
2545 | .owner = THIS_MODULE, | |
2546 | .cnic_init = bnx2fc_ulp_init, | |
2547 | .cnic_exit = bnx2fc_ulp_exit, | |
2548 | .cnic_start = bnx2fc_ulp_start, | |
2549 | .cnic_stop = bnx2fc_ulp_stop, | |
2550 | .indicate_kcqes = bnx2fc_indicate_kcqe, | |
2551 | .indicate_netevent = bnx2fc_indicate_netevent, | |
2552 | }; |