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