2 * Copyright 2008 Cisco Systems, Inc. All rights reserved.
3 * Copyright 2007 Nuova Systems, Inc. All rights reserved.
5 * This program is free software; you may redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; version 2 of the License.
9 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
10 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
11 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
12 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
13 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
14 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
15 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
18 #include <linux/errno.h>
19 #include <linux/pci.h>
20 #include <linux/slab.h>
21 #include <linux/skbuff.h>
22 #include <linux/interrupt.h>
23 #include <linux/spinlock.h>
24 #include <linux/if_ether.h>
25 #include <linux/if_vlan.h>
26 #include <linux/workqueue.h>
27 #include <scsi/fc/fc_fip.h>
28 #include <scsi/fc/fc_els.h>
29 #include <scsi/fc/fc_fcoe.h>
30 #include <scsi/fc_frame.h>
31 #include <scsi/libfc.h>
35 #include "cq_enet_desc.h"
36 #include "cq_exch_desc.h"
38 static u8 fcoe_all_fcfs
[ETH_ALEN
] = FIP_ALL_FCF_MACS
;
39 struct workqueue_struct
*fnic_fip_queue
;
40 struct workqueue_struct
*fnic_event_queue
;
42 static void fnic_set_eth_mode(struct fnic
*);
43 static void fnic_fcoe_send_vlan_req(struct fnic
*fnic
);
44 static void fnic_fcoe_start_fcf_disc(struct fnic
*fnic
);
45 static void fnic_fcoe_process_vlan_resp(struct fnic
*fnic
, struct sk_buff
*);
46 static int fnic_fcoe_vlan_check(struct fnic
*fnic
, u16 flag
);
47 static int fnic_fcoe_handle_fip_frame(struct fnic
*fnic
, struct sk_buff
*skb
);
49 void fnic_handle_link(struct work_struct
*work
)
51 struct fnic
*fnic
= container_of(work
, struct fnic
, link_work
);
54 u32 old_link_down_cnt
;
55 u64 old_port_speed
, new_port_speed
;
57 spin_lock_irqsave(&fnic
->fnic_lock
, flags
);
59 if (fnic
->stop_rx_link_events
) {
60 spin_unlock_irqrestore(&fnic
->fnic_lock
, flags
);
64 old_link_down_cnt
= fnic
->link_down_cnt
;
65 old_link_status
= fnic
->link_status
;
66 old_port_speed
= atomic64_read(
67 &fnic
->fnic_stats
.misc_stats
.current_port_speed
);
69 fnic
->link_status
= vnic_dev_link_status(fnic
->vdev
);
70 fnic
->link_down_cnt
= vnic_dev_link_down_cnt(fnic
->vdev
);
72 new_port_speed
= vnic_dev_port_speed(fnic
->vdev
);
73 atomic64_set(&fnic
->fnic_stats
.misc_stats
.current_port_speed
,
75 if (old_port_speed
!= new_port_speed
)
76 shost_printk(KERN_INFO
, fnic
->lport
->host
,
77 "Current vnic speed set to : %llu\n",
80 switch (vnic_dev_port_speed(fnic
->vdev
)) {
81 case DCEM_PORTSPEED_10G
:
82 fc_host_speed(fnic
->lport
->host
) = FC_PORTSPEED_10GBIT
;
83 fnic
->lport
->link_supported_speeds
= FC_PORTSPEED_10GBIT
;
85 case DCEM_PORTSPEED_20G
:
86 fc_host_speed(fnic
->lport
->host
) = FC_PORTSPEED_20GBIT
;
87 fnic
->lport
->link_supported_speeds
= FC_PORTSPEED_20GBIT
;
89 case DCEM_PORTSPEED_25G
:
90 fc_host_speed(fnic
->lport
->host
) = FC_PORTSPEED_25GBIT
;
91 fnic
->lport
->link_supported_speeds
= FC_PORTSPEED_25GBIT
;
93 case DCEM_PORTSPEED_40G
:
94 case DCEM_PORTSPEED_4x10G
:
95 fc_host_speed(fnic
->lport
->host
) = FC_PORTSPEED_40GBIT
;
96 fnic
->lport
->link_supported_speeds
= FC_PORTSPEED_40GBIT
;
98 case DCEM_PORTSPEED_100G
:
99 fc_host_speed(fnic
->lport
->host
) = FC_PORTSPEED_100GBIT
;
100 fnic
->lport
->link_supported_speeds
= FC_PORTSPEED_100GBIT
;
103 fc_host_speed(fnic
->lport
->host
) = FC_PORTSPEED_UNKNOWN
;
104 fnic
->lport
->link_supported_speeds
= FC_PORTSPEED_UNKNOWN
;
108 if (old_link_status
== fnic
->link_status
) {
109 if (!fnic
->link_status
) {
111 spin_unlock_irqrestore(&fnic
->fnic_lock
, flags
);
112 fnic_fc_trace_set_data(fnic
->lport
->host
->host_no
,
113 FNIC_FC_LE
, "Link Status: DOWN->DOWN",
114 strlen("Link Status: DOWN->DOWN"));
116 if (old_link_down_cnt
!= fnic
->link_down_cnt
) {
117 /* UP -> DOWN -> UP */
118 fnic
->lport
->host_stats
.link_failure_count
++;
119 spin_unlock_irqrestore(&fnic
->fnic_lock
, flags
);
120 fnic_fc_trace_set_data(
121 fnic
->lport
->host
->host_no
,
123 "Link Status:UP_DOWN_UP",
124 strlen("Link_Status:UP_DOWN_UP")
126 FNIC_FCS_DBG(KERN_DEBUG
, fnic
->lport
->host
,
128 fcoe_ctlr_link_down(&fnic
->ctlr
);
129 if (fnic
->config
.flags
& VFCF_FIP_CAPABLE
) {
130 /* start FCoE VLAN discovery */
131 fnic_fc_trace_set_data(
132 fnic
->lport
->host
->host_no
,
134 "Link Status: UP_DOWN_UP_VLAN",
136 "Link Status: UP_DOWN_UP_VLAN")
138 fnic_fcoe_send_vlan_req(fnic
);
141 FNIC_FCS_DBG(KERN_DEBUG
, fnic
->lport
->host
,
143 fcoe_ctlr_link_up(&fnic
->ctlr
);
146 spin_unlock_irqrestore(&fnic
->fnic_lock
, flags
);
147 fnic_fc_trace_set_data(
148 fnic
->lport
->host
->host_no
, FNIC_FC_LE
,
149 "Link Status: UP_UP",
150 strlen("Link Status: UP_UP"));
153 } else if (fnic
->link_status
) {
155 spin_unlock_irqrestore(&fnic
->fnic_lock
, flags
);
156 if (fnic
->config
.flags
& VFCF_FIP_CAPABLE
) {
157 /* start FCoE VLAN discovery */
158 fnic_fc_trace_set_data(
159 fnic
->lport
->host
->host_no
,
160 FNIC_FC_LE
, "Link Status: DOWN_UP_VLAN",
161 strlen("Link Status: DOWN_UP_VLAN"));
162 fnic_fcoe_send_vlan_req(fnic
);
165 FNIC_FCS_DBG(KERN_DEBUG
, fnic
->lport
->host
, "link up\n");
166 fnic_fc_trace_set_data(fnic
->lport
->host
->host_no
, FNIC_FC_LE
,
167 "Link Status: DOWN_UP", strlen("Link Status: DOWN_UP"));
168 fcoe_ctlr_link_up(&fnic
->ctlr
);
171 fnic
->lport
->host_stats
.link_failure_count
++;
172 spin_unlock_irqrestore(&fnic
->fnic_lock
, flags
);
173 FNIC_FCS_DBG(KERN_DEBUG
, fnic
->lport
->host
, "link down\n");
174 fnic_fc_trace_set_data(
175 fnic
->lport
->host
->host_no
, FNIC_FC_LE
,
176 "Link Status: UP_DOWN",
177 strlen("Link Status: UP_DOWN"));
178 if (fnic
->config
.flags
& VFCF_FIP_CAPABLE
) {
179 FNIC_FCS_DBG(KERN_DEBUG
, fnic
->lport
->host
,
180 "deleting fip-timer during link-down\n");
181 del_timer_sync(&fnic
->fip_timer
);
183 fcoe_ctlr_link_down(&fnic
->ctlr
);
189 * This function passes incoming fabric frames to libFC
191 void fnic_handle_frame(struct work_struct
*work
)
193 struct fnic
*fnic
= container_of(work
, struct fnic
, frame_work
);
194 struct fc_lport
*lp
= fnic
->lport
;
199 while ((skb
= skb_dequeue(&fnic
->frame_queue
))) {
201 spin_lock_irqsave(&fnic
->fnic_lock
, flags
);
202 if (fnic
->stop_rx_link_events
) {
203 spin_unlock_irqrestore(&fnic
->fnic_lock
, flags
);
207 fp
= (struct fc_frame
*)skb
;
210 * If we're in a transitional state, just re-queue and return.
211 * The queue will be serviced when we get to a stable state.
213 if (fnic
->state
!= FNIC_IN_FC_MODE
&&
214 fnic
->state
!= FNIC_IN_ETH_MODE
) {
215 skb_queue_head(&fnic
->frame_queue
, skb
);
216 spin_unlock_irqrestore(&fnic
->fnic_lock
, flags
);
219 spin_unlock_irqrestore(&fnic
->fnic_lock
, flags
);
221 fc_exch_recv(lp
, fp
);
225 void fnic_fcoe_evlist_free(struct fnic
*fnic
)
227 struct fnic_event
*fevt
= NULL
;
228 struct fnic_event
*next
= NULL
;
231 spin_lock_irqsave(&fnic
->fnic_lock
, flags
);
232 if (list_empty(&fnic
->evlist
)) {
233 spin_unlock_irqrestore(&fnic
->fnic_lock
, flags
);
237 list_for_each_entry_safe(fevt
, next
, &fnic
->evlist
, list
) {
238 list_del(&fevt
->list
);
241 spin_unlock_irqrestore(&fnic
->fnic_lock
, flags
);
244 void fnic_handle_event(struct work_struct
*work
)
246 struct fnic
*fnic
= container_of(work
, struct fnic
, event_work
);
247 struct fnic_event
*fevt
= NULL
;
248 struct fnic_event
*next
= NULL
;
251 spin_lock_irqsave(&fnic
->fnic_lock
, flags
);
252 if (list_empty(&fnic
->evlist
)) {
253 spin_unlock_irqrestore(&fnic
->fnic_lock
, flags
);
257 list_for_each_entry_safe(fevt
, next
, &fnic
->evlist
, list
) {
258 if (fnic
->stop_rx_link_events
) {
259 list_del(&fevt
->list
);
261 spin_unlock_irqrestore(&fnic
->fnic_lock
, flags
);
265 * If we're in a transitional state, just re-queue and return.
266 * The queue will be serviced when we get to a stable state.
268 if (fnic
->state
!= FNIC_IN_FC_MODE
&&
269 fnic
->state
!= FNIC_IN_ETH_MODE
) {
270 spin_unlock_irqrestore(&fnic
->fnic_lock
, flags
);
274 list_del(&fevt
->list
);
275 switch (fevt
->event
) {
276 case FNIC_EVT_START_VLAN_DISC
:
277 spin_unlock_irqrestore(&fnic
->fnic_lock
, flags
);
278 fnic_fcoe_send_vlan_req(fnic
);
279 spin_lock_irqsave(&fnic
->fnic_lock
, flags
);
281 case FNIC_EVT_START_FCF_DISC
:
282 FNIC_FCS_DBG(KERN_DEBUG
, fnic
->lport
->host
,
283 "Start FCF Discovery\n");
284 fnic_fcoe_start_fcf_disc(fnic
);
287 FNIC_FCS_DBG(KERN_DEBUG
, fnic
->lport
->host
,
288 "Unknown event 0x%x\n", fevt
->event
);
293 spin_unlock_irqrestore(&fnic
->fnic_lock
, flags
);
297 * Check if the Received FIP FLOGI frame is rejected
298 * @fip: The FCoE controller that received the frame
299 * @skb: The received FIP frame
301 * Returns non-zero if the frame is rejected with unsupported cmd with
302 * insufficient resource els explanation.
304 static inline int is_fnic_fip_flogi_reject(struct fcoe_ctlr
*fip
,
307 struct fc_lport
*lport
= fip
->lp
;
308 struct fip_header
*fiph
;
309 struct fc_frame_header
*fh
= NULL
;
310 struct fip_desc
*desc
;
311 struct fip_encaps
*els
;
312 enum fip_desc_type els_dtype
= 0;
321 if (skb_linearize(skb
))
324 if (skb
->len
< sizeof(*fiph
))
327 fiph
= (struct fip_header
*)skb
->data
;
328 op
= ntohs(fiph
->fip_op
);
329 sub
= fiph
->fip_subcode
;
334 if (sub
!= FIP_SC_REP
)
337 rlen
= ntohs(fiph
->fip_dl_len
) * 4;
338 if (rlen
+ sizeof(*fiph
) > skb
->len
)
341 desc
= (struct fip_desc
*)(fiph
+ 1);
342 dlen
= desc
->fip_dlen
* FIP_BPW
;
344 if (desc
->fip_dtype
== FIP_DT_FLOGI
) {
346 if (dlen
< sizeof(*els
) + sizeof(*fh
) + 1)
349 els_len
= dlen
- sizeof(*els
);
350 els
= (struct fip_encaps
*)desc
;
351 fh
= (struct fc_frame_header
*)(els
+ 1);
352 els_dtype
= desc
->fip_dtype
;
358 * ELS command code, reason and explanation should be = Reject,
359 * unsupported command and insufficient resource
361 els_op
= *(u8
*)(fh
+ 1);
362 if (els_op
== ELS_LS_RJT
) {
363 shost_printk(KERN_INFO
, lport
->host
,
364 "Flogi Request Rejected by Switch\n");
367 shost_printk(KERN_INFO
, lport
->host
,
368 "Flogi Request Accepted by Switch\n");
373 static void fnic_fcoe_send_vlan_req(struct fnic
*fnic
)
375 struct fcoe_ctlr
*fip
= &fnic
->ctlr
;
376 struct fnic_stats
*fnic_stats
= &fnic
->fnic_stats
;
380 struct fip_vlan
*vlan
;
383 fnic_fcoe_reset_vlans(fnic
);
384 fnic
->set_vlan(fnic
, 0);
386 if (printk_ratelimit())
387 FNIC_FCS_DBG(KERN_INFO
, fnic
->lport
->host
,
388 "Sending VLAN request...\n");
390 skb
= dev_alloc_skb(sizeof(struct fip_vlan
));
394 fr_len
= sizeof(*vlan
);
395 eth_fr
= (char *)skb
->data
;
396 vlan
= (struct fip_vlan
*)eth_fr
;
398 memset(vlan
, 0, sizeof(*vlan
));
399 memcpy(vlan
->eth
.h_source
, fip
->ctl_src_addr
, ETH_ALEN
);
400 memcpy(vlan
->eth
.h_dest
, fcoe_all_fcfs
, ETH_ALEN
);
401 vlan
->eth
.h_proto
= htons(ETH_P_FIP
);
403 vlan
->fip
.fip_ver
= FIP_VER_ENCAPS(FIP_VER
);
404 vlan
->fip
.fip_op
= htons(FIP_OP_VLAN
);
405 vlan
->fip
.fip_subcode
= FIP_SC_VL_REQ
;
406 vlan
->fip
.fip_dl_len
= htons(sizeof(vlan
->desc
) / FIP_BPW
);
408 vlan
->desc
.mac
.fd_desc
.fip_dtype
= FIP_DT_MAC
;
409 vlan
->desc
.mac
.fd_desc
.fip_dlen
= sizeof(vlan
->desc
.mac
) / FIP_BPW
;
410 memcpy(&vlan
->desc
.mac
.fd_mac
, fip
->ctl_src_addr
, ETH_ALEN
);
412 vlan
->desc
.wwnn
.fd_desc
.fip_dtype
= FIP_DT_NAME
;
413 vlan
->desc
.wwnn
.fd_desc
.fip_dlen
= sizeof(vlan
->desc
.wwnn
) / FIP_BPW
;
414 put_unaligned_be64(fip
->lp
->wwnn
, &vlan
->desc
.wwnn
.fd_wwn
);
415 atomic64_inc(&fnic_stats
->vlan_stats
.vlan_disc_reqs
);
417 skb_put(skb
, sizeof(*vlan
));
418 skb
->protocol
= htons(ETH_P_FIP
);
419 skb_reset_mac_header(skb
);
420 skb_reset_network_header(skb
);
423 /* set a timer so that we can retry if there no response */
424 vlan_tov
= jiffies
+ msecs_to_jiffies(FCOE_CTLR_FIPVLAN_TOV
);
425 mod_timer(&fnic
->fip_timer
, round_jiffies(vlan_tov
));
428 static void fnic_fcoe_process_vlan_resp(struct fnic
*fnic
, struct sk_buff
*skb
)
430 struct fcoe_ctlr
*fip
= &fnic
->ctlr
;
431 struct fip_header
*fiph
;
432 struct fip_desc
*desc
;
433 struct fnic_stats
*fnic_stats
= &fnic
->fnic_stats
;
437 struct fcoe_vlan
*vlan
;
441 FNIC_FCS_DBG(KERN_INFO
, fnic
->lport
->host
,
442 "Received VLAN response...\n");
444 fiph
= (struct fip_header
*) skb
->data
;
446 FNIC_FCS_DBG(KERN_INFO
, fnic
->lport
->host
,
447 "Received VLAN response... OP 0x%x SUB_OP 0x%x\n",
448 ntohs(fiph
->fip_op
), fiph
->fip_subcode
);
450 rlen
= ntohs(fiph
->fip_dl_len
) * 4;
451 fnic_fcoe_reset_vlans(fnic
);
452 spin_lock_irqsave(&fnic
->vlans_lock
, flags
);
453 desc
= (struct fip_desc
*)(fiph
+ 1);
455 dlen
= desc
->fip_dlen
* FIP_BPW
;
456 switch (desc
->fip_dtype
) {
458 vid
= ntohs(((struct fip_vlan_desc
*)desc
)->fd_vlan
);
459 shost_printk(KERN_INFO
, fnic
->lport
->host
,
460 "process_vlan_resp: FIP VLAN %d\n", vid
);
461 vlan
= kzalloc(sizeof(*vlan
), GFP_ATOMIC
);
463 /* retry from timer */
464 spin_unlock_irqrestore(&fnic
->vlans_lock
,
468 vlan
->vid
= vid
& 0x0fff;
469 vlan
->state
= FIP_VLAN_AVAIL
;
470 list_add_tail(&vlan
->list
, &fnic
->vlans
);
473 desc
= (struct fip_desc
*)((char *)desc
+ dlen
);
477 /* any VLAN descriptors present ? */
478 if (list_empty(&fnic
->vlans
)) {
479 /* retry from timer */
480 atomic64_inc(&fnic_stats
->vlan_stats
.resp_withno_vlanID
);
481 FNIC_FCS_DBG(KERN_INFO
, fnic
->lport
->host
,
482 "No VLAN descriptors in FIP VLAN response\n");
483 spin_unlock_irqrestore(&fnic
->vlans_lock
, flags
);
487 vlan
= list_first_entry(&fnic
->vlans
, struct fcoe_vlan
, list
);
488 fnic
->set_vlan(fnic
, vlan
->vid
);
489 vlan
->state
= FIP_VLAN_SENT
; /* sent now */
491 spin_unlock_irqrestore(&fnic
->vlans_lock
, flags
);
493 /* start the solicitation */
494 fcoe_ctlr_link_up(fip
);
496 sol_time
= jiffies
+ msecs_to_jiffies(FCOE_CTLR_START_DELAY
);
497 mod_timer(&fnic
->fip_timer
, round_jiffies(sol_time
));
502 static void fnic_fcoe_start_fcf_disc(struct fnic
*fnic
)
505 struct fcoe_vlan
*vlan
;
508 spin_lock_irqsave(&fnic
->vlans_lock
, flags
);
509 vlan
= list_first_entry(&fnic
->vlans
, struct fcoe_vlan
, list
);
510 fnic
->set_vlan(fnic
, vlan
->vid
);
511 vlan
->state
= FIP_VLAN_SENT
; /* sent now */
513 spin_unlock_irqrestore(&fnic
->vlans_lock
, flags
);
515 /* start the solicitation */
516 fcoe_ctlr_link_up(&fnic
->ctlr
);
518 sol_time
= jiffies
+ msecs_to_jiffies(FCOE_CTLR_START_DELAY
);
519 mod_timer(&fnic
->fip_timer
, round_jiffies(sol_time
));
522 static int fnic_fcoe_vlan_check(struct fnic
*fnic
, u16 flag
)
525 struct fcoe_vlan
*fvlan
;
527 spin_lock_irqsave(&fnic
->vlans_lock
, flags
);
528 if (list_empty(&fnic
->vlans
)) {
529 spin_unlock_irqrestore(&fnic
->vlans_lock
, flags
);
533 fvlan
= list_first_entry(&fnic
->vlans
, struct fcoe_vlan
, list
);
534 if (fvlan
->state
== FIP_VLAN_USED
) {
535 spin_unlock_irqrestore(&fnic
->vlans_lock
, flags
);
539 if (fvlan
->state
== FIP_VLAN_SENT
) {
540 fvlan
->state
= FIP_VLAN_USED
;
541 spin_unlock_irqrestore(&fnic
->vlans_lock
, flags
);
544 spin_unlock_irqrestore(&fnic
->vlans_lock
, flags
);
548 static void fnic_event_enq(struct fnic
*fnic
, enum fnic_evt ev
)
550 struct fnic_event
*fevt
;
553 fevt
= kmalloc(sizeof(*fevt
), GFP_ATOMIC
);
560 spin_lock_irqsave(&fnic
->fnic_lock
, flags
);
561 list_add_tail(&fevt
->list
, &fnic
->evlist
);
562 spin_unlock_irqrestore(&fnic
->fnic_lock
, flags
);
564 schedule_work(&fnic
->event_work
);
567 static int fnic_fcoe_handle_fip_frame(struct fnic
*fnic
, struct sk_buff
*skb
)
569 struct fip_header
*fiph
;
574 if (!skb
|| !(skb
->data
))
577 if (skb_linearize(skb
))
580 fiph
= (struct fip_header
*)skb
->data
;
581 op
= ntohs(fiph
->fip_op
);
582 sub
= fiph
->fip_subcode
;
584 if (FIP_VER_DECAPS(fiph
->fip_ver
) != FIP_VER
)
587 if (ntohs(fiph
->fip_dl_len
) * FIP_BPW
+ sizeof(*fiph
) > skb
->len
)
590 if (op
== FIP_OP_DISC
&& sub
== FIP_SC_ADV
) {
591 if (fnic_fcoe_vlan_check(fnic
, ntohs(fiph
->fip_flags
)))
593 /* pass it on to fcoe */
595 } else if (op
== FIP_OP_VLAN
&& sub
== FIP_SC_VL_NOTE
) {
596 /* set the vlan as used */
597 fnic_fcoe_process_vlan_resp(fnic
, skb
);
599 } else if (op
== FIP_OP_CTRL
&& sub
== FIP_SC_CLR_VLINK
) {
600 /* received CVL request, restart vlan disc */
601 fnic_event_enq(fnic
, FNIC_EVT_START_VLAN_DISC
);
602 /* pass it on to fcoe */
609 void fnic_handle_fip_frame(struct work_struct
*work
)
611 struct fnic
*fnic
= container_of(work
, struct fnic
, fip_frame_work
);
612 struct fnic_stats
*fnic_stats
= &fnic
->fnic_stats
;
617 while ((skb
= skb_dequeue(&fnic
->fip_frame_queue
))) {
618 spin_lock_irqsave(&fnic
->fnic_lock
, flags
);
619 if (fnic
->stop_rx_link_events
) {
620 spin_unlock_irqrestore(&fnic
->fnic_lock
, flags
);
625 * If we're in a transitional state, just re-queue and return.
626 * The queue will be serviced when we get to a stable state.
628 if (fnic
->state
!= FNIC_IN_FC_MODE
&&
629 fnic
->state
!= FNIC_IN_ETH_MODE
) {
630 skb_queue_head(&fnic
->fip_frame_queue
, skb
);
631 spin_unlock_irqrestore(&fnic
->fnic_lock
, flags
);
634 spin_unlock_irqrestore(&fnic
->fnic_lock
, flags
);
635 eh
= (struct ethhdr
*)skb
->data
;
636 if (eh
->h_proto
== htons(ETH_P_FIP
)) {
637 skb_pull(skb
, sizeof(*eh
));
638 if (fnic_fcoe_handle_fip_frame(fnic
, skb
) <= 0) {
643 * If there's FLOGI rejects - clear all
644 * fcf's & restart from scratch
646 if (is_fnic_fip_flogi_reject(&fnic
->ctlr
, skb
)) {
648 &fnic_stats
->vlan_stats
.flogi_rejects
);
649 shost_printk(KERN_INFO
, fnic
->lport
->host
,
650 "Trigger a Link down - VLAN Disc\n");
651 fcoe_ctlr_link_down(&fnic
->ctlr
);
652 /* start FCoE VLAN discovery */
653 fnic_fcoe_send_vlan_req(fnic
);
657 fcoe_ctlr_recv(&fnic
->ctlr
, skb
);
664 * fnic_import_rq_eth_pkt() - handle received FCoE or FIP frame.
665 * @fnic: fnic instance.
666 * @skb: Ethernet Frame.
668 static inline int fnic_import_rq_eth_pkt(struct fnic
*fnic
, struct sk_buff
*skb
)
672 struct fcoe_hdr
*fcoe_hdr
;
673 struct fcoe_crc_eof
*ft
;
676 * Undo VLAN encapsulation if present.
678 eh
= (struct ethhdr
*)skb
->data
;
679 if (eh
->h_proto
== htons(ETH_P_8021Q
)) {
680 memmove((u8
*)eh
+ VLAN_HLEN
, eh
, ETH_ALEN
* 2);
681 eh
= skb_pull(skb
, VLAN_HLEN
);
682 skb_reset_mac_header(skb
);
684 if (eh
->h_proto
== htons(ETH_P_FIP
)) {
685 if (!(fnic
->config
.flags
& VFCF_FIP_CAPABLE
)) {
686 printk(KERN_ERR
"Dropped FIP frame, as firmware "
687 "uses non-FIP mode, Enable FIP "
691 if ((fnic_fc_trace_set_data(fnic
->lport
->host
->host_no
,
692 FNIC_FC_RECV
|0x80, (char *)skb
->data
, skb
->len
)) != 0) {
693 printk(KERN_ERR
"fnic ctlr frame trace error!!!");
695 skb_queue_tail(&fnic
->fip_frame_queue
, skb
);
696 queue_work(fnic_fip_queue
, &fnic
->fip_frame_work
);
697 return 1; /* let caller know packet was used */
699 if (eh
->h_proto
!= htons(ETH_P_FCOE
))
701 skb_set_network_header(skb
, sizeof(*eh
));
702 skb_pull(skb
, sizeof(*eh
));
704 fcoe_hdr
= (struct fcoe_hdr
*)skb
->data
;
705 if (FC_FCOE_DECAPS_VER(fcoe_hdr
) != FC_FCOE_VER
)
708 fp
= (struct fc_frame
*)skb
;
710 fr_sof(fp
) = fcoe_hdr
->fcoe_sof
;
711 skb_pull(skb
, sizeof(struct fcoe_hdr
));
712 skb_reset_transport_header(skb
);
714 ft
= (struct fcoe_crc_eof
*)(skb
->data
+ skb
->len
- sizeof(*ft
));
715 fr_eof(fp
) = ft
->fcoe_eof
;
716 skb_trim(skb
, skb
->len
- sizeof(*ft
));
719 dev_kfree_skb_irq(skb
);
724 * fnic_update_mac_locked() - set data MAC address and filters.
725 * @fnic: fnic instance.
726 * @new: newly-assigned FCoE MAC address.
728 * Called with the fnic lock held.
730 void fnic_update_mac_locked(struct fnic
*fnic
, u8
*new)
732 u8
*ctl
= fnic
->ctlr
.ctl_src_addr
;
733 u8
*data
= fnic
->data_src_addr
;
735 if (is_zero_ether_addr(new))
737 if (ether_addr_equal(data
, new))
739 FNIC_FCS_DBG(KERN_DEBUG
, fnic
->lport
->host
, "update_mac %pM\n", new);
740 if (!is_zero_ether_addr(data
) && !ether_addr_equal(data
, ctl
))
741 vnic_dev_del_addr(fnic
->vdev
, data
);
742 memcpy(data
, new, ETH_ALEN
);
743 if (!ether_addr_equal(new, ctl
))
744 vnic_dev_add_addr(fnic
->vdev
, new);
748 * fnic_update_mac() - set data MAC address and filters.
749 * @lport: local port.
750 * @new: newly-assigned FCoE MAC address.
752 void fnic_update_mac(struct fc_lport
*lport
, u8
*new)
754 struct fnic
*fnic
= lport_priv(lport
);
756 spin_lock_irq(&fnic
->fnic_lock
);
757 fnic_update_mac_locked(fnic
, new);
758 spin_unlock_irq(&fnic
->fnic_lock
);
762 * fnic_set_port_id() - set the port_ID after successful FLOGI.
763 * @lport: local port.
764 * @port_id: assigned FC_ID.
765 * @fp: received frame containing the FLOGI accept or NULL.
767 * This is called from libfc when a new FC_ID has been assigned.
768 * This causes us to reset the firmware to FC_MODE and setup the new MAC
771 * It is also called with FC_ID 0 when we're logged off.
773 * If the FC_ID is due to point-to-point, fp may be NULL.
775 void fnic_set_port_id(struct fc_lport
*lport
, u32 port_id
, struct fc_frame
*fp
)
777 struct fnic
*fnic
= lport_priv(lport
);
781 FNIC_FCS_DBG(KERN_DEBUG
, lport
->host
, "set port_id %x fp %p\n",
785 * If we're clearing the FC_ID, change to use the ctl_src_addr.
786 * Set ethernet mode to send FLOGI.
789 fnic_update_mac(lport
, fnic
->ctlr
.ctl_src_addr
);
790 fnic_set_eth_mode(fnic
);
795 mac
= fr_cb(fp
)->granted_mac
;
796 if (is_zero_ether_addr(mac
)) {
797 /* non-FIP - FLOGI already accepted - ignore return */
798 fcoe_ctlr_recv_flogi(&fnic
->ctlr
, lport
, fp
);
800 fnic_update_mac(lport
, mac
);
803 /* Change state to reflect transition to FC mode */
804 spin_lock_irq(&fnic
->fnic_lock
);
805 if (fnic
->state
== FNIC_IN_ETH_MODE
|| fnic
->state
== FNIC_IN_FC_MODE
)
806 fnic
->state
= FNIC_IN_ETH_TRANS_FC_MODE
;
808 FNIC_FCS_DBG(KERN_DEBUG
, fnic
->lport
->host
,
809 "Unexpected fnic state %s while"
810 " processing flogi resp\n",
811 fnic_state_to_str(fnic
->state
));
812 spin_unlock_irq(&fnic
->fnic_lock
);
815 spin_unlock_irq(&fnic
->fnic_lock
);
818 * Send FLOGI registration to firmware to set up FC mode.
819 * The new address will be set up when registration completes.
821 ret
= fnic_flogi_reg_handler(fnic
, port_id
);
824 spin_lock_irq(&fnic
->fnic_lock
);
825 if (fnic
->state
== FNIC_IN_ETH_TRANS_FC_MODE
)
826 fnic
->state
= FNIC_IN_ETH_MODE
;
827 spin_unlock_irq(&fnic
->fnic_lock
);
831 static void fnic_rq_cmpl_frame_recv(struct vnic_rq
*rq
, struct cq_desc
832 *cq_desc
, struct vnic_rq_buf
*buf
,
833 int skipped
__attribute__((unused
)),
836 struct fnic
*fnic
= vnic_dev_priv(rq
->vdev
);
839 struct fnic_stats
*fnic_stats
= &fnic
->fnic_stats
;
840 unsigned int eth_hdrs_stripped
;
841 u8 type
, color
, eop
, sop
, ingress_port
, vlan_stripped
;
842 u8 fcoe
= 0, fcoe_sof
, fcoe_eof
;
843 u8 fcoe_fc_crc_ok
= 1, fcoe_enc_error
= 0;
844 u8 tcp_udp_csum_ok
, udp
, tcp
, ipv4_csum_ok
;
845 u8 ipv6
, ipv4
, ipv4_fragment
, rss_type
, csum_not_calc
;
846 u8 fcs_ok
= 1, packet_error
= 0;
847 u16 q_number
, completed_index
, bytes_written
= 0, vlan
, checksum
;
849 u16 exchange_id
, tmpl
;
852 u32 fcp_bytes_written
= 0;
855 dma_unmap_single(&fnic
->pdev
->dev
, buf
->dma_addr
, buf
->len
,
858 fp
= (struct fc_frame
*)skb
;
861 cq_desc_dec(cq_desc
, &type
, &color
, &q_number
, &completed_index
);
862 if (type
== CQ_DESC_TYPE_RQ_FCP
) {
863 cq_fcp_rq_desc_dec((struct cq_fcp_rq_desc
*)cq_desc
,
864 &type
, &color
, &q_number
, &completed_index
,
865 &eop
, &sop
, &fcoe_fc_crc_ok
, &exchange_id
,
866 &tmpl
, &fcp_bytes_written
, &sof
, &eof
,
867 &ingress_port
, &packet_error
,
868 &fcoe_enc_error
, &fcs_ok
, &vlan_stripped
,
870 eth_hdrs_stripped
= 1;
871 skb_trim(skb
, fcp_bytes_written
);
875 } else if (type
== CQ_DESC_TYPE_RQ_ENET
) {
876 cq_enet_rq_desc_dec((struct cq_enet_rq_desc
*)cq_desc
,
877 &type
, &color
, &q_number
, &completed_index
,
878 &ingress_port
, &fcoe
, &eop
, &sop
,
879 &rss_type
, &csum_not_calc
, &rss_hash
,
880 &bytes_written
, &packet_error
,
881 &vlan_stripped
, &vlan
, &checksum
,
882 &fcoe_sof
, &fcoe_fc_crc_ok
,
883 &fcoe_enc_error
, &fcoe_eof
,
884 &tcp_udp_csum_ok
, &udp
, &tcp
,
885 &ipv4_csum_ok
, &ipv6
, &ipv4
,
886 &ipv4_fragment
, &fcs_ok
);
887 eth_hdrs_stripped
= 0;
888 skb_trim(skb
, bytes_written
);
890 atomic64_inc(&fnic_stats
->misc_stats
.frame_errors
);
891 FNIC_FCS_DBG(KERN_DEBUG
, fnic
->lport
->host
,
892 "fcs error. dropping packet.\n");
895 if (fnic_import_rq_eth_pkt(fnic
, skb
))
900 shost_printk(KERN_ERR
, fnic
->lport
->host
,
901 "fnic rq_cmpl wrong cq type x%x\n", type
);
905 if (!fcs_ok
|| packet_error
|| !fcoe_fc_crc_ok
|| fcoe_enc_error
) {
906 atomic64_inc(&fnic_stats
->misc_stats
.frame_errors
);
907 FNIC_FCS_DBG(KERN_DEBUG
, fnic
->lport
->host
,
908 "fnic rq_cmpl fcoe x%x fcsok x%x"
909 " pkterr x%x fcoe_fc_crc_ok x%x, fcoe_enc_err"
911 fcoe
, fcs_ok
, packet_error
,
912 fcoe_fc_crc_ok
, fcoe_enc_error
);
916 spin_lock_irqsave(&fnic
->fnic_lock
, flags
);
917 if (fnic
->stop_rx_link_events
) {
918 spin_unlock_irqrestore(&fnic
->fnic_lock
, flags
);
921 fr_dev(fp
) = fnic
->lport
;
922 spin_unlock_irqrestore(&fnic
->fnic_lock
, flags
);
923 if ((fnic_fc_trace_set_data(fnic
->lport
->host
->host_no
, FNIC_FC_RECV
,
924 (char *)skb
->data
, skb
->len
)) != 0) {
925 printk(KERN_ERR
"fnic ctlr frame trace error!!!");
928 skb_queue_tail(&fnic
->frame_queue
, skb
);
929 queue_work(fnic_event_queue
, &fnic
->frame_work
);
933 dev_kfree_skb_irq(skb
);
936 static int fnic_rq_cmpl_handler_cont(struct vnic_dev
*vdev
,
937 struct cq_desc
*cq_desc
, u8 type
,
938 u16 q_number
, u16 completed_index
,
941 struct fnic
*fnic
= vnic_dev_priv(vdev
);
943 vnic_rq_service(&fnic
->rq
[q_number
], cq_desc
, completed_index
,
944 VNIC_RQ_RETURN_DESC
, fnic_rq_cmpl_frame_recv
,
949 int fnic_rq_cmpl_handler(struct fnic
*fnic
, int rq_work_to_do
)
951 unsigned int tot_rq_work_done
= 0, cur_work_done
;
955 for (i
= 0; i
< fnic
->rq_count
; i
++) {
956 cur_work_done
= vnic_cq_service(&fnic
->cq
[i
], rq_work_to_do
,
957 fnic_rq_cmpl_handler_cont
,
960 err
= vnic_rq_fill(&fnic
->rq
[i
], fnic_alloc_rq_frame
);
962 shost_printk(KERN_ERR
, fnic
->lport
->host
,
963 "fnic_alloc_rq_frame can't alloc"
966 tot_rq_work_done
+= cur_work_done
;
969 return tot_rq_work_done
;
973 * This function is called once at init time to allocate and fill RQ
974 * buffers. Subsequently, it is called in the interrupt context after RQ
975 * buffer processing to replenish the buffers in the RQ
977 int fnic_alloc_rq_frame(struct vnic_rq
*rq
)
979 struct fnic
*fnic
= vnic_dev_priv(rq
->vdev
);
985 len
= FC_FRAME_HEADROOM
+ FC_MAX_FRAME
+ FC_FRAME_TAILROOM
;
986 skb
= dev_alloc_skb(len
);
988 FNIC_FCS_DBG(KERN_DEBUG
, fnic
->lport
->host
,
989 "Unable to allocate RQ sk_buff\n");
992 skb_reset_mac_header(skb
);
993 skb_reset_transport_header(skb
);
994 skb_reset_network_header(skb
);
996 pa
= dma_map_single(&fnic
->pdev
->dev
, skb
->data
, len
, DMA_FROM_DEVICE
);
997 if (dma_mapping_error(&fnic
->pdev
->dev
, pa
)) {
999 printk(KERN_ERR
"PCI mapping failed with error %d\n", r
);
1003 fnic_queue_rq_desc(rq
, skb
, pa
, len
);
1011 void fnic_free_rq_buf(struct vnic_rq
*rq
, struct vnic_rq_buf
*buf
)
1013 struct fc_frame
*fp
= buf
->os_buf
;
1014 struct fnic
*fnic
= vnic_dev_priv(rq
->vdev
);
1016 dma_unmap_single(&fnic
->pdev
->dev
, buf
->dma_addr
, buf
->len
,
1019 dev_kfree_skb(fp_skb(fp
));
1024 * fnic_eth_send() - Send Ethernet frame.
1025 * @fip: fcoe_ctlr instance.
1026 * @skb: Ethernet Frame, FIP, without VLAN encapsulation.
1028 void fnic_eth_send(struct fcoe_ctlr
*fip
, struct sk_buff
*skb
)
1030 struct fnic
*fnic
= fnic_from_ctlr(fip
);
1031 struct vnic_wq
*wq
= &fnic
->wq
[0];
1033 struct ethhdr
*eth_hdr
;
1034 struct vlan_ethhdr
*vlan_hdr
;
1035 unsigned long flags
;
1037 if (!fnic
->vlan_hw_insert
) {
1038 eth_hdr
= (struct ethhdr
*)skb_mac_header(skb
);
1039 vlan_hdr
= skb_push(skb
, sizeof(*vlan_hdr
) - sizeof(*eth_hdr
));
1040 memcpy(vlan_hdr
, eth_hdr
, 2 * ETH_ALEN
);
1041 vlan_hdr
->h_vlan_proto
= htons(ETH_P_8021Q
);
1042 vlan_hdr
->h_vlan_encapsulated_proto
= eth_hdr
->h_proto
;
1043 vlan_hdr
->h_vlan_TCI
= htons(fnic
->vlan_id
);
1044 if ((fnic_fc_trace_set_data(fnic
->lport
->host
->host_no
,
1045 FNIC_FC_SEND
|0x80, (char *)eth_hdr
, skb
->len
)) != 0) {
1046 printk(KERN_ERR
"fnic ctlr frame trace error!!!");
1049 if ((fnic_fc_trace_set_data(fnic
->lport
->host
->host_no
,
1050 FNIC_FC_SEND
|0x80, (char *)skb
->data
, skb
->len
)) != 0) {
1051 printk(KERN_ERR
"fnic ctlr frame trace error!!!");
1055 pa
= dma_map_single(&fnic
->pdev
->dev
, skb
->data
, skb
->len
,
1057 if (dma_mapping_error(&fnic
->pdev
->dev
, pa
)) {
1058 printk(KERN_ERR
"DMA mapping failed\n");
1062 spin_lock_irqsave(&fnic
->wq_lock
[0], flags
);
1063 if (!vnic_wq_desc_avail(wq
))
1066 fnic_queue_wq_eth_desc(wq
, skb
, pa
, skb
->len
,
1067 0 /* hw inserts cos value */,
1069 spin_unlock_irqrestore(&fnic
->wq_lock
[0], flags
);
1073 spin_unlock_irqrestore(&fnic
->wq_lock
[0], flags
);
1074 dma_unmap_single(&fnic
->pdev
->dev
, pa
, skb
->len
, DMA_TO_DEVICE
);
1082 static int fnic_send_frame(struct fnic
*fnic
, struct fc_frame
*fp
)
1084 struct vnic_wq
*wq
= &fnic
->wq
[0];
1085 struct sk_buff
*skb
;
1087 struct ethhdr
*eth_hdr
;
1088 struct vlan_ethhdr
*vlan_hdr
;
1089 struct fcoe_hdr
*fcoe_hdr
;
1090 struct fc_frame_header
*fh
;
1091 u32 tot_len
, eth_hdr_len
;
1093 unsigned long flags
;
1095 fh
= fc_frame_header_get(fp
);
1098 if (unlikely(fh
->fh_r_ctl
== FC_RCTL_ELS_REQ
) &&
1099 fcoe_ctlr_els_send(&fnic
->ctlr
, fnic
->lport
, skb
))
1102 if (!fnic
->vlan_hw_insert
) {
1103 eth_hdr_len
= sizeof(*vlan_hdr
) + sizeof(*fcoe_hdr
);
1104 vlan_hdr
= skb_push(skb
, eth_hdr_len
);
1105 eth_hdr
= (struct ethhdr
*)vlan_hdr
;
1106 vlan_hdr
->h_vlan_proto
= htons(ETH_P_8021Q
);
1107 vlan_hdr
->h_vlan_encapsulated_proto
= htons(ETH_P_FCOE
);
1108 vlan_hdr
->h_vlan_TCI
= htons(fnic
->vlan_id
);
1109 fcoe_hdr
= (struct fcoe_hdr
*)(vlan_hdr
+ 1);
1111 eth_hdr_len
= sizeof(*eth_hdr
) + sizeof(*fcoe_hdr
);
1112 eth_hdr
= skb_push(skb
, eth_hdr_len
);
1113 eth_hdr
->h_proto
= htons(ETH_P_FCOE
);
1114 fcoe_hdr
= (struct fcoe_hdr
*)(eth_hdr
+ 1);
1117 if (fnic
->ctlr
.map_dest
)
1118 fc_fcoe_set_mac(eth_hdr
->h_dest
, fh
->fh_d_id
);
1120 memcpy(eth_hdr
->h_dest
, fnic
->ctlr
.dest_addr
, ETH_ALEN
);
1121 memcpy(eth_hdr
->h_source
, fnic
->data_src_addr
, ETH_ALEN
);
1124 BUG_ON(tot_len
% 4);
1126 memset(fcoe_hdr
, 0, sizeof(*fcoe_hdr
));
1127 fcoe_hdr
->fcoe_sof
= fr_sof(fp
);
1129 FC_FCOE_ENCAPS_VER(fcoe_hdr
, FC_FCOE_VER
);
1131 pa
= dma_map_single(&fnic
->pdev
->dev
, eth_hdr
, tot_len
, DMA_TO_DEVICE
);
1132 if (dma_mapping_error(&fnic
->pdev
->dev
, pa
)) {
1134 printk(KERN_ERR
"DMA map failed with error %d\n", ret
);
1135 goto free_skb_on_err
;
1138 if ((fnic_fc_trace_set_data(fnic
->lport
->host
->host_no
, FNIC_FC_SEND
,
1139 (char *)eth_hdr
, tot_len
)) != 0) {
1140 printk(KERN_ERR
"fnic ctlr frame trace error!!!");
1143 spin_lock_irqsave(&fnic
->wq_lock
[0], flags
);
1145 if (!vnic_wq_desc_avail(wq
)) {
1146 dma_unmap_single(&fnic
->pdev
->dev
, pa
, tot_len
, DMA_TO_DEVICE
);
1151 fnic_queue_wq_desc(wq
, skb
, pa
, tot_len
, fr_eof(fp
),
1152 0 /* hw inserts cos value */,
1153 fnic
->vlan_id
, 1, 1, 1);
1156 spin_unlock_irqrestore(&fnic
->wq_lock
[0], flags
);
1160 dev_kfree_skb_any(fp_skb(fp
));
1167 * Routine to send a raw frame
1169 int fnic_send(struct fc_lport
*lp
, struct fc_frame
*fp
)
1171 struct fnic
*fnic
= lport_priv(lp
);
1172 unsigned long flags
;
1174 if (fnic
->in_remove
) {
1175 dev_kfree_skb(fp_skb(fp
));
1180 * Queue frame if in a transitional state.
1181 * This occurs while registering the Port_ID / MAC address after FLOGI.
1183 spin_lock_irqsave(&fnic
->fnic_lock
, flags
);
1184 if (fnic
->state
!= FNIC_IN_FC_MODE
&& fnic
->state
!= FNIC_IN_ETH_MODE
) {
1185 skb_queue_tail(&fnic
->tx_queue
, fp_skb(fp
));
1186 spin_unlock_irqrestore(&fnic
->fnic_lock
, flags
);
1189 spin_unlock_irqrestore(&fnic
->fnic_lock
, flags
);
1191 return fnic_send_frame(fnic
, fp
);
1195 * fnic_flush_tx() - send queued frames.
1196 * @fnic: fnic device
1198 * Send frames that were waiting to go out in FC or Ethernet mode.
1199 * Whenever changing modes we purge queued frames, so these frames should
1200 * be queued for the stable mode that we're in, either FC or Ethernet.
1202 * Called without fnic_lock held.
1204 void fnic_flush_tx(struct fnic
*fnic
)
1206 struct sk_buff
*skb
;
1207 struct fc_frame
*fp
;
1209 while ((skb
= skb_dequeue(&fnic
->tx_queue
))) {
1210 fp
= (struct fc_frame
*)skb
;
1211 fnic_send_frame(fnic
, fp
);
1216 * fnic_set_eth_mode() - put fnic into ethernet mode.
1217 * @fnic: fnic device
1219 * Called without fnic lock held.
1221 static void fnic_set_eth_mode(struct fnic
*fnic
)
1223 unsigned long flags
;
1224 enum fnic_state old_state
;
1227 spin_lock_irqsave(&fnic
->fnic_lock
, flags
);
1229 old_state
= fnic
->state
;
1230 switch (old_state
) {
1231 case FNIC_IN_FC_MODE
:
1232 case FNIC_IN_ETH_TRANS_FC_MODE
:
1234 fnic
->state
= FNIC_IN_FC_TRANS_ETH_MODE
;
1235 spin_unlock_irqrestore(&fnic
->fnic_lock
, flags
);
1237 ret
= fnic_fw_reset_handler(fnic
);
1239 spin_lock_irqsave(&fnic
->fnic_lock
, flags
);
1240 if (fnic
->state
!= FNIC_IN_FC_TRANS_ETH_MODE
)
1243 fnic
->state
= old_state
;
1246 case FNIC_IN_FC_TRANS_ETH_MODE
:
1247 case FNIC_IN_ETH_MODE
:
1250 spin_unlock_irqrestore(&fnic
->fnic_lock
, flags
);
1253 static void fnic_wq_complete_frame_send(struct vnic_wq
*wq
,
1254 struct cq_desc
*cq_desc
,
1255 struct vnic_wq_buf
*buf
, void *opaque
)
1257 struct sk_buff
*skb
= buf
->os_buf
;
1258 struct fc_frame
*fp
= (struct fc_frame
*)skb
;
1259 struct fnic
*fnic
= vnic_dev_priv(wq
->vdev
);
1261 dma_unmap_single(&fnic
->pdev
->dev
, buf
->dma_addr
, buf
->len
,
1263 dev_kfree_skb_irq(fp_skb(fp
));
1267 static int fnic_wq_cmpl_handler_cont(struct vnic_dev
*vdev
,
1268 struct cq_desc
*cq_desc
, u8 type
,
1269 u16 q_number
, u16 completed_index
,
1272 struct fnic
*fnic
= vnic_dev_priv(vdev
);
1273 unsigned long flags
;
1275 spin_lock_irqsave(&fnic
->wq_lock
[q_number
], flags
);
1276 vnic_wq_service(&fnic
->wq
[q_number
], cq_desc
, completed_index
,
1277 fnic_wq_complete_frame_send
, NULL
);
1278 spin_unlock_irqrestore(&fnic
->wq_lock
[q_number
], flags
);
1283 int fnic_wq_cmpl_handler(struct fnic
*fnic
, int work_to_do
)
1285 unsigned int wq_work_done
= 0;
1288 for (i
= 0; i
< fnic
->raw_wq_count
; i
++) {
1289 wq_work_done
+= vnic_cq_service(&fnic
->cq
[fnic
->rq_count
+i
],
1291 fnic_wq_cmpl_handler_cont
,
1295 return wq_work_done
;
1299 void fnic_free_wq_buf(struct vnic_wq
*wq
, struct vnic_wq_buf
*buf
)
1301 struct fc_frame
*fp
= buf
->os_buf
;
1302 struct fnic
*fnic
= vnic_dev_priv(wq
->vdev
);
1304 dma_unmap_single(&fnic
->pdev
->dev
, buf
->dma_addr
, buf
->len
,
1307 dev_kfree_skb(fp_skb(fp
));
1311 void fnic_fcoe_reset_vlans(struct fnic
*fnic
)
1313 unsigned long flags
;
1314 struct fcoe_vlan
*vlan
;
1315 struct fcoe_vlan
*next
;
1318 * indicate a link down to fcoe so that all fcf's are free'd
1319 * might not be required since we did this before sending vlan
1322 spin_lock_irqsave(&fnic
->vlans_lock
, flags
);
1323 if (!list_empty(&fnic
->vlans
)) {
1324 list_for_each_entry_safe(vlan
, next
, &fnic
->vlans
, list
) {
1325 list_del(&vlan
->list
);
1329 spin_unlock_irqrestore(&fnic
->vlans_lock
, flags
);
1332 void fnic_handle_fip_timer(struct fnic
*fnic
)
1334 unsigned long flags
;
1335 struct fcoe_vlan
*vlan
;
1336 struct fnic_stats
*fnic_stats
= &fnic
->fnic_stats
;
1339 spin_lock_irqsave(&fnic
->fnic_lock
, flags
);
1340 if (fnic
->stop_rx_link_events
) {
1341 spin_unlock_irqrestore(&fnic
->fnic_lock
, flags
);
1344 spin_unlock_irqrestore(&fnic
->fnic_lock
, flags
);
1346 if (fnic
->ctlr
.mode
== FIP_MODE_NON_FIP
)
1349 spin_lock_irqsave(&fnic
->vlans_lock
, flags
);
1350 if (list_empty(&fnic
->vlans
)) {
1351 spin_unlock_irqrestore(&fnic
->vlans_lock
, flags
);
1352 /* no vlans available, try again */
1353 if (printk_ratelimit())
1354 FNIC_FCS_DBG(KERN_DEBUG
, fnic
->lport
->host
,
1355 "Start VLAN Discovery\n");
1356 fnic_event_enq(fnic
, FNIC_EVT_START_VLAN_DISC
);
1360 vlan
= list_first_entry(&fnic
->vlans
, struct fcoe_vlan
, list
);
1361 shost_printk(KERN_DEBUG
, fnic
->lport
->host
,
1362 "fip_timer: vlan %d state %d sol_count %d\n",
1363 vlan
->vid
, vlan
->state
, vlan
->sol_count
);
1364 switch (vlan
->state
) {
1366 FNIC_FCS_DBG(KERN_DEBUG
, fnic
->lport
->host
,
1367 "FIP VLAN is selected for FC transaction\n");
1368 spin_unlock_irqrestore(&fnic
->vlans_lock
, flags
);
1370 case FIP_VLAN_FAILED
:
1371 spin_unlock_irqrestore(&fnic
->vlans_lock
, flags
);
1372 /* if all vlans are in failed state, restart vlan disc */
1373 if (printk_ratelimit())
1374 FNIC_FCS_DBG(KERN_DEBUG
, fnic
->lport
->host
,
1375 "Start VLAN Discovery\n");
1376 fnic_event_enq(fnic
, FNIC_EVT_START_VLAN_DISC
);
1379 if (vlan
->sol_count
>= FCOE_CTLR_MAX_SOL
) {
1381 * no response on this vlan, remove from the list.
1384 shost_printk(KERN_INFO
, fnic
->lport
->host
,
1385 "Dequeue this VLAN ID %d from list\n",
1387 list_del(&vlan
->list
);
1390 if (list_empty(&fnic
->vlans
)) {
1391 /* we exhausted all vlans, restart vlan disc */
1392 spin_unlock_irqrestore(&fnic
->vlans_lock
,
1394 shost_printk(KERN_INFO
, fnic
->lport
->host
,
1395 "fip_timer: vlan list empty, "
1396 "trigger vlan disc\n");
1397 fnic_event_enq(fnic
, FNIC_EVT_START_VLAN_DISC
);
1400 /* check the next vlan */
1401 vlan
= list_first_entry(&fnic
->vlans
, struct fcoe_vlan
,
1403 fnic
->set_vlan(fnic
, vlan
->vid
);
1404 vlan
->state
= FIP_VLAN_SENT
; /* sent now */
1406 spin_unlock_irqrestore(&fnic
->vlans_lock
, flags
);
1407 atomic64_inc(&fnic_stats
->vlan_stats
.sol_expiry_count
);
1409 sol_time
= jiffies
+ msecs_to_jiffies
1410 (FCOE_CTLR_START_DELAY
);
1411 mod_timer(&fnic
->fip_timer
, round_jiffies(sol_time
));