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 fnic
->link_events
= 1; /* less work to just set everytime*/
61 if (fnic
->stop_rx_link_events
) {
62 spin_unlock_irqrestore(&fnic
->fnic_lock
, flags
);
66 old_link_down_cnt
= fnic
->link_down_cnt
;
67 old_link_status
= fnic
->link_status
;
68 old_port_speed
= atomic64_read(
69 &fnic
->fnic_stats
.misc_stats
.current_port_speed
);
71 fnic
->link_status
= vnic_dev_link_status(fnic
->vdev
);
72 fnic
->link_down_cnt
= vnic_dev_link_down_cnt(fnic
->vdev
);
74 new_port_speed
= vnic_dev_port_speed(fnic
->vdev
);
75 atomic64_set(&fnic
->fnic_stats
.misc_stats
.current_port_speed
,
77 if (old_port_speed
!= new_port_speed
)
78 FNIC_MAIN_DBG(KERN_INFO
, fnic
->lport
->host
,
79 "Current vnic speed set to : %llu\n",
82 switch (vnic_dev_port_speed(fnic
->vdev
)) {
83 case DCEM_PORTSPEED_10G
:
84 fc_host_speed(fnic
->lport
->host
) = FC_PORTSPEED_10GBIT
;
85 fnic
->lport
->link_supported_speeds
= FC_PORTSPEED_10GBIT
;
87 case DCEM_PORTSPEED_20G
:
88 fc_host_speed(fnic
->lport
->host
) = FC_PORTSPEED_20GBIT
;
89 fnic
->lport
->link_supported_speeds
= FC_PORTSPEED_20GBIT
;
91 case DCEM_PORTSPEED_25G
:
92 fc_host_speed(fnic
->lport
->host
) = FC_PORTSPEED_25GBIT
;
93 fnic
->lport
->link_supported_speeds
= FC_PORTSPEED_25GBIT
;
95 case DCEM_PORTSPEED_40G
:
96 case DCEM_PORTSPEED_4x10G
:
97 fc_host_speed(fnic
->lport
->host
) = FC_PORTSPEED_40GBIT
;
98 fnic
->lport
->link_supported_speeds
= FC_PORTSPEED_40GBIT
;
100 case DCEM_PORTSPEED_100G
:
101 fc_host_speed(fnic
->lport
->host
) = FC_PORTSPEED_100GBIT
;
102 fnic
->lport
->link_supported_speeds
= FC_PORTSPEED_100GBIT
;
105 fc_host_speed(fnic
->lport
->host
) = FC_PORTSPEED_UNKNOWN
;
106 fnic
->lport
->link_supported_speeds
= FC_PORTSPEED_UNKNOWN
;
110 if (old_link_status
== fnic
->link_status
) {
111 if (!fnic
->link_status
) {
113 spin_unlock_irqrestore(&fnic
->fnic_lock
, flags
);
114 fnic_fc_trace_set_data(fnic
->lport
->host
->host_no
,
115 FNIC_FC_LE
, "Link Status: DOWN->DOWN",
116 strlen("Link Status: DOWN->DOWN"));
118 if (old_link_down_cnt
!= fnic
->link_down_cnt
) {
119 /* UP -> DOWN -> UP */
120 fnic
->lport
->host_stats
.link_failure_count
++;
121 spin_unlock_irqrestore(&fnic
->fnic_lock
, flags
);
122 fnic_fc_trace_set_data(
123 fnic
->lport
->host
->host_no
,
125 "Link Status:UP_DOWN_UP",
126 strlen("Link_Status:UP_DOWN_UP")
128 FNIC_FCS_DBG(KERN_DEBUG
, fnic
->lport
->host
,
130 fcoe_ctlr_link_down(&fnic
->ctlr
);
131 if (fnic
->config
.flags
& VFCF_FIP_CAPABLE
) {
132 /* start FCoE VLAN discovery */
133 fnic_fc_trace_set_data(
134 fnic
->lport
->host
->host_no
,
136 "Link Status: UP_DOWN_UP_VLAN",
138 "Link Status: UP_DOWN_UP_VLAN")
140 fnic_fcoe_send_vlan_req(fnic
);
143 FNIC_FCS_DBG(KERN_DEBUG
, fnic
->lport
->host
,
145 fcoe_ctlr_link_up(&fnic
->ctlr
);
148 spin_unlock_irqrestore(&fnic
->fnic_lock
, flags
);
149 fnic_fc_trace_set_data(
150 fnic
->lport
->host
->host_no
, FNIC_FC_LE
,
151 "Link Status: UP_UP",
152 strlen("Link Status: UP_UP"));
155 } else if (fnic
->link_status
) {
157 spin_unlock_irqrestore(&fnic
->fnic_lock
, flags
);
158 if (fnic
->config
.flags
& VFCF_FIP_CAPABLE
) {
159 /* start FCoE VLAN discovery */
160 fnic_fc_trace_set_data(
161 fnic
->lport
->host
->host_no
,
162 FNIC_FC_LE
, "Link Status: DOWN_UP_VLAN",
163 strlen("Link Status: DOWN_UP_VLAN"));
164 fnic_fcoe_send_vlan_req(fnic
);
167 FNIC_FCS_DBG(KERN_DEBUG
, fnic
->lport
->host
, "link up\n");
168 fnic_fc_trace_set_data(fnic
->lport
->host
->host_no
, FNIC_FC_LE
,
169 "Link Status: DOWN_UP", strlen("Link Status: DOWN_UP"));
170 fcoe_ctlr_link_up(&fnic
->ctlr
);
173 fnic
->lport
->host_stats
.link_failure_count
++;
174 spin_unlock_irqrestore(&fnic
->fnic_lock
, flags
);
175 FNIC_FCS_DBG(KERN_DEBUG
, fnic
->lport
->host
, "link down\n");
176 fnic_fc_trace_set_data(
177 fnic
->lport
->host
->host_no
, FNIC_FC_LE
,
178 "Link Status: UP_DOWN",
179 strlen("Link Status: UP_DOWN"));
180 if (fnic
->config
.flags
& VFCF_FIP_CAPABLE
) {
181 FNIC_FCS_DBG(KERN_DEBUG
, fnic
->lport
->host
,
182 "deleting fip-timer during link-down\n");
183 del_timer_sync(&fnic
->fip_timer
);
185 fcoe_ctlr_link_down(&fnic
->ctlr
);
191 * This function passes incoming fabric frames to libFC
193 void fnic_handle_frame(struct work_struct
*work
)
195 struct fnic
*fnic
= container_of(work
, struct fnic
, frame_work
);
196 struct fc_lport
*lp
= fnic
->lport
;
201 while ((skb
= skb_dequeue(&fnic
->frame_queue
))) {
203 spin_lock_irqsave(&fnic
->fnic_lock
, flags
);
204 if (fnic
->stop_rx_link_events
) {
205 spin_unlock_irqrestore(&fnic
->fnic_lock
, flags
);
209 fp
= (struct fc_frame
*)skb
;
212 * If we're in a transitional state, just re-queue and return.
213 * The queue will be serviced when we get to a stable state.
215 if (fnic
->state
!= FNIC_IN_FC_MODE
&&
216 fnic
->state
!= FNIC_IN_ETH_MODE
) {
217 skb_queue_head(&fnic
->frame_queue
, skb
);
218 spin_unlock_irqrestore(&fnic
->fnic_lock
, flags
);
221 spin_unlock_irqrestore(&fnic
->fnic_lock
, flags
);
223 fc_exch_recv(lp
, fp
);
227 void fnic_fcoe_evlist_free(struct fnic
*fnic
)
229 struct fnic_event
*fevt
= NULL
;
230 struct fnic_event
*next
= NULL
;
233 spin_lock_irqsave(&fnic
->fnic_lock
, flags
);
234 if (list_empty(&fnic
->evlist
)) {
235 spin_unlock_irqrestore(&fnic
->fnic_lock
, flags
);
239 list_for_each_entry_safe(fevt
, next
, &fnic
->evlist
, list
) {
240 list_del(&fevt
->list
);
243 spin_unlock_irqrestore(&fnic
->fnic_lock
, flags
);
246 void fnic_handle_event(struct work_struct
*work
)
248 struct fnic
*fnic
= container_of(work
, struct fnic
, event_work
);
249 struct fnic_event
*fevt
= NULL
;
250 struct fnic_event
*next
= NULL
;
253 spin_lock_irqsave(&fnic
->fnic_lock
, flags
);
254 if (list_empty(&fnic
->evlist
)) {
255 spin_unlock_irqrestore(&fnic
->fnic_lock
, flags
);
259 list_for_each_entry_safe(fevt
, next
, &fnic
->evlist
, list
) {
260 if (fnic
->stop_rx_link_events
) {
261 list_del(&fevt
->list
);
263 spin_unlock_irqrestore(&fnic
->fnic_lock
, flags
);
267 * If we're in a transitional state, just re-queue and return.
268 * The queue will be serviced when we get to a stable state.
270 if (fnic
->state
!= FNIC_IN_FC_MODE
&&
271 fnic
->state
!= FNIC_IN_ETH_MODE
) {
272 spin_unlock_irqrestore(&fnic
->fnic_lock
, flags
);
276 list_del(&fevt
->list
);
277 switch (fevt
->event
) {
278 case FNIC_EVT_START_VLAN_DISC
:
279 spin_unlock_irqrestore(&fnic
->fnic_lock
, flags
);
280 fnic_fcoe_send_vlan_req(fnic
);
281 spin_lock_irqsave(&fnic
->fnic_lock
, flags
);
283 case FNIC_EVT_START_FCF_DISC
:
284 FNIC_FCS_DBG(KERN_DEBUG
, fnic
->lport
->host
,
285 "Start FCF Discovery\n");
286 fnic_fcoe_start_fcf_disc(fnic
);
289 FNIC_FCS_DBG(KERN_DEBUG
, fnic
->lport
->host
,
290 "Unknown event 0x%x\n", fevt
->event
);
295 spin_unlock_irqrestore(&fnic
->fnic_lock
, flags
);
299 * Check if the Received FIP FLOGI frame is rejected
300 * @fip: The FCoE controller that received the frame
301 * @skb: The received FIP frame
303 * Returns non-zero if the frame is rejected with unsupported cmd with
304 * insufficient resource els explanation.
306 static inline int is_fnic_fip_flogi_reject(struct fcoe_ctlr
*fip
,
309 struct fc_lport
*lport
= fip
->lp
;
310 struct fip_header
*fiph
;
311 struct fc_frame_header
*fh
= NULL
;
312 struct fip_desc
*desc
;
313 struct fip_encaps
*els
;
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
= (struct fip_encaps
*)desc
;
350 fh
= (struct fc_frame_header
*)(els
+ 1);
356 * ELS command code, reason and explanation should be = Reject,
357 * unsupported command and insufficient resource
359 els_op
= *(u8
*)(fh
+ 1);
360 if (els_op
== ELS_LS_RJT
) {
361 shost_printk(KERN_INFO
, lport
->host
,
362 "Flogi Request Rejected by Switch\n");
365 shost_printk(KERN_INFO
, lport
->host
,
366 "Flogi Request Accepted by Switch\n");
371 static void fnic_fcoe_send_vlan_req(struct fnic
*fnic
)
373 struct fcoe_ctlr
*fip
= &fnic
->ctlr
;
374 struct fnic_stats
*fnic_stats
= &fnic
->fnic_stats
;
377 struct fip_vlan
*vlan
;
380 fnic_fcoe_reset_vlans(fnic
);
381 fnic
->set_vlan(fnic
, 0);
383 if (printk_ratelimit())
384 FNIC_FCS_DBG(KERN_INFO
, fnic
->lport
->host
,
385 "Sending VLAN request...\n");
387 skb
= dev_alloc_skb(sizeof(struct fip_vlan
));
391 eth_fr
= (char *)skb
->data
;
392 vlan
= (struct fip_vlan
*)eth_fr
;
394 memset(vlan
, 0, sizeof(*vlan
));
395 memcpy(vlan
->eth
.h_source
, fip
->ctl_src_addr
, ETH_ALEN
);
396 memcpy(vlan
->eth
.h_dest
, fcoe_all_fcfs
, ETH_ALEN
);
397 vlan
->eth
.h_proto
= htons(ETH_P_FIP
);
399 vlan
->fip
.fip_ver
= FIP_VER_ENCAPS(FIP_VER
);
400 vlan
->fip
.fip_op
= htons(FIP_OP_VLAN
);
401 vlan
->fip
.fip_subcode
= FIP_SC_VL_REQ
;
402 vlan
->fip
.fip_dl_len
= htons(sizeof(vlan
->desc
) / FIP_BPW
);
404 vlan
->desc
.mac
.fd_desc
.fip_dtype
= FIP_DT_MAC
;
405 vlan
->desc
.mac
.fd_desc
.fip_dlen
= sizeof(vlan
->desc
.mac
) / FIP_BPW
;
406 memcpy(&vlan
->desc
.mac
.fd_mac
, fip
->ctl_src_addr
, ETH_ALEN
);
408 vlan
->desc
.wwnn
.fd_desc
.fip_dtype
= FIP_DT_NAME
;
409 vlan
->desc
.wwnn
.fd_desc
.fip_dlen
= sizeof(vlan
->desc
.wwnn
) / FIP_BPW
;
410 put_unaligned_be64(fip
->lp
->wwnn
, &vlan
->desc
.wwnn
.fd_wwn
);
411 atomic64_inc(&fnic_stats
->vlan_stats
.vlan_disc_reqs
);
413 skb_put(skb
, sizeof(*vlan
));
414 skb
->protocol
= htons(ETH_P_FIP
);
415 skb_reset_mac_header(skb
);
416 skb_reset_network_header(skb
);
419 /* set a timer so that we can retry if there no response */
420 vlan_tov
= jiffies
+ msecs_to_jiffies(FCOE_CTLR_FIPVLAN_TOV
);
421 mod_timer(&fnic
->fip_timer
, round_jiffies(vlan_tov
));
424 static void fnic_fcoe_process_vlan_resp(struct fnic
*fnic
, struct sk_buff
*skb
)
426 struct fcoe_ctlr
*fip
= &fnic
->ctlr
;
427 struct fip_header
*fiph
;
428 struct fip_desc
*desc
;
429 struct fnic_stats
*fnic_stats
= &fnic
->fnic_stats
;
433 struct fcoe_vlan
*vlan
;
437 FNIC_FCS_DBG(KERN_INFO
, fnic
->lport
->host
,
438 "Received VLAN response...\n");
440 fiph
= (struct fip_header
*) skb
->data
;
442 FNIC_FCS_DBG(KERN_INFO
, fnic
->lport
->host
,
443 "Received VLAN response... OP 0x%x SUB_OP 0x%x\n",
444 ntohs(fiph
->fip_op
), fiph
->fip_subcode
);
446 rlen
= ntohs(fiph
->fip_dl_len
) * 4;
447 fnic_fcoe_reset_vlans(fnic
);
448 spin_lock_irqsave(&fnic
->vlans_lock
, flags
);
449 desc
= (struct fip_desc
*)(fiph
+ 1);
451 dlen
= desc
->fip_dlen
* FIP_BPW
;
452 switch (desc
->fip_dtype
) {
454 vid
= ntohs(((struct fip_vlan_desc
*)desc
)->fd_vlan
);
455 shost_printk(KERN_INFO
, fnic
->lport
->host
,
456 "process_vlan_resp: FIP VLAN %d\n", vid
);
457 vlan
= kzalloc(sizeof(*vlan
), GFP_ATOMIC
);
459 /* retry from timer */
460 spin_unlock_irqrestore(&fnic
->vlans_lock
,
464 vlan
->vid
= vid
& 0x0fff;
465 vlan
->state
= FIP_VLAN_AVAIL
;
466 list_add_tail(&vlan
->list
, &fnic
->vlans
);
469 desc
= (struct fip_desc
*)((char *)desc
+ dlen
);
473 /* any VLAN descriptors present ? */
474 if (list_empty(&fnic
->vlans
)) {
475 /* retry from timer */
476 atomic64_inc(&fnic_stats
->vlan_stats
.resp_withno_vlanID
);
477 FNIC_FCS_DBG(KERN_INFO
, fnic
->lport
->host
,
478 "No VLAN descriptors in FIP VLAN response\n");
479 spin_unlock_irqrestore(&fnic
->vlans_lock
, flags
);
483 vlan
= list_first_entry(&fnic
->vlans
, struct fcoe_vlan
, list
);
484 fnic
->set_vlan(fnic
, vlan
->vid
);
485 vlan
->state
= FIP_VLAN_SENT
; /* sent now */
487 spin_unlock_irqrestore(&fnic
->vlans_lock
, flags
);
489 /* start the solicitation */
490 fcoe_ctlr_link_up(fip
);
492 sol_time
= jiffies
+ msecs_to_jiffies(FCOE_CTLR_START_DELAY
);
493 mod_timer(&fnic
->fip_timer
, round_jiffies(sol_time
));
498 static void fnic_fcoe_start_fcf_disc(struct fnic
*fnic
)
501 struct fcoe_vlan
*vlan
;
504 spin_lock_irqsave(&fnic
->vlans_lock
, flags
);
505 vlan
= list_first_entry(&fnic
->vlans
, struct fcoe_vlan
, list
);
506 fnic
->set_vlan(fnic
, vlan
->vid
);
507 vlan
->state
= FIP_VLAN_SENT
; /* sent now */
509 spin_unlock_irqrestore(&fnic
->vlans_lock
, flags
);
511 /* start the solicitation */
512 fcoe_ctlr_link_up(&fnic
->ctlr
);
514 sol_time
= jiffies
+ msecs_to_jiffies(FCOE_CTLR_START_DELAY
);
515 mod_timer(&fnic
->fip_timer
, round_jiffies(sol_time
));
518 static int fnic_fcoe_vlan_check(struct fnic
*fnic
, u16 flag
)
521 struct fcoe_vlan
*fvlan
;
523 spin_lock_irqsave(&fnic
->vlans_lock
, flags
);
524 if (list_empty(&fnic
->vlans
)) {
525 spin_unlock_irqrestore(&fnic
->vlans_lock
, flags
);
529 fvlan
= list_first_entry(&fnic
->vlans
, struct fcoe_vlan
, list
);
530 if (fvlan
->state
== FIP_VLAN_USED
) {
531 spin_unlock_irqrestore(&fnic
->vlans_lock
, flags
);
535 if (fvlan
->state
== FIP_VLAN_SENT
) {
536 fvlan
->state
= FIP_VLAN_USED
;
537 spin_unlock_irqrestore(&fnic
->vlans_lock
, flags
);
540 spin_unlock_irqrestore(&fnic
->vlans_lock
, flags
);
544 static void fnic_event_enq(struct fnic
*fnic
, enum fnic_evt ev
)
546 struct fnic_event
*fevt
;
549 fevt
= kmalloc(sizeof(*fevt
), GFP_ATOMIC
);
556 spin_lock_irqsave(&fnic
->fnic_lock
, flags
);
557 list_add_tail(&fevt
->list
, &fnic
->evlist
);
558 spin_unlock_irqrestore(&fnic
->fnic_lock
, flags
);
560 schedule_work(&fnic
->event_work
);
563 static int fnic_fcoe_handle_fip_frame(struct fnic
*fnic
, struct sk_buff
*skb
)
565 struct fip_header
*fiph
;
570 if (!skb
|| !(skb
->data
))
573 if (skb_linearize(skb
))
576 fiph
= (struct fip_header
*)skb
->data
;
577 op
= ntohs(fiph
->fip_op
);
578 sub
= fiph
->fip_subcode
;
580 if (FIP_VER_DECAPS(fiph
->fip_ver
) != FIP_VER
)
583 if (ntohs(fiph
->fip_dl_len
) * FIP_BPW
+ sizeof(*fiph
) > skb
->len
)
586 if (op
== FIP_OP_DISC
&& sub
== FIP_SC_ADV
) {
587 if (fnic_fcoe_vlan_check(fnic
, ntohs(fiph
->fip_flags
)))
589 /* pass it on to fcoe */
591 } else if (op
== FIP_OP_VLAN
&& sub
== FIP_SC_VL_NOTE
) {
592 /* set the vlan as used */
593 fnic_fcoe_process_vlan_resp(fnic
, skb
);
595 } else if (op
== FIP_OP_CTRL
&& sub
== FIP_SC_CLR_VLINK
) {
596 /* received CVL request, restart vlan disc */
597 fnic_event_enq(fnic
, FNIC_EVT_START_VLAN_DISC
);
598 /* pass it on to fcoe */
605 void fnic_handle_fip_frame(struct work_struct
*work
)
607 struct fnic
*fnic
= container_of(work
, struct fnic
, fip_frame_work
);
608 struct fnic_stats
*fnic_stats
= &fnic
->fnic_stats
;
613 while ((skb
= skb_dequeue(&fnic
->fip_frame_queue
))) {
614 spin_lock_irqsave(&fnic
->fnic_lock
, flags
);
615 if (fnic
->stop_rx_link_events
) {
616 spin_unlock_irqrestore(&fnic
->fnic_lock
, flags
);
621 * If we're in a transitional state, just re-queue and return.
622 * The queue will be serviced when we get to a stable state.
624 if (fnic
->state
!= FNIC_IN_FC_MODE
&&
625 fnic
->state
!= FNIC_IN_ETH_MODE
) {
626 skb_queue_head(&fnic
->fip_frame_queue
, skb
);
627 spin_unlock_irqrestore(&fnic
->fnic_lock
, flags
);
630 spin_unlock_irqrestore(&fnic
->fnic_lock
, flags
);
631 eh
= (struct ethhdr
*)skb
->data
;
632 if (eh
->h_proto
== htons(ETH_P_FIP
)) {
633 skb_pull(skb
, sizeof(*eh
));
634 if (fnic_fcoe_handle_fip_frame(fnic
, skb
) <= 0) {
639 * If there's FLOGI rejects - clear all
640 * fcf's & restart from scratch
642 if (is_fnic_fip_flogi_reject(&fnic
->ctlr
, skb
)) {
644 &fnic_stats
->vlan_stats
.flogi_rejects
);
645 shost_printk(KERN_INFO
, fnic
->lport
->host
,
646 "Trigger a Link down - VLAN Disc\n");
647 fcoe_ctlr_link_down(&fnic
->ctlr
);
648 /* start FCoE VLAN discovery */
649 fnic_fcoe_send_vlan_req(fnic
);
653 fcoe_ctlr_recv(&fnic
->ctlr
, skb
);
660 * fnic_import_rq_eth_pkt() - handle received FCoE or FIP frame.
661 * @fnic: fnic instance.
662 * @skb: Ethernet Frame.
664 static inline int fnic_import_rq_eth_pkt(struct fnic
*fnic
, struct sk_buff
*skb
)
668 struct fcoe_hdr
*fcoe_hdr
;
669 struct fcoe_crc_eof
*ft
;
672 * Undo VLAN encapsulation if present.
674 eh
= (struct ethhdr
*)skb
->data
;
675 if (eh
->h_proto
== htons(ETH_P_8021Q
)) {
676 memmove((u8
*)eh
+ VLAN_HLEN
, eh
, ETH_ALEN
* 2);
677 eh
= skb_pull(skb
, VLAN_HLEN
);
678 skb_reset_mac_header(skb
);
680 if (eh
->h_proto
== htons(ETH_P_FIP
)) {
681 if (!(fnic
->config
.flags
& VFCF_FIP_CAPABLE
)) {
682 printk(KERN_ERR
"Dropped FIP frame, as firmware "
683 "uses non-FIP mode, Enable FIP "
687 if ((fnic_fc_trace_set_data(fnic
->lport
->host
->host_no
,
688 FNIC_FC_RECV
|0x80, (char *)skb
->data
, skb
->len
)) != 0) {
689 printk(KERN_ERR
"fnic ctlr frame trace error!!!");
691 skb_queue_tail(&fnic
->fip_frame_queue
, skb
);
692 queue_work(fnic_fip_queue
, &fnic
->fip_frame_work
);
693 return 1; /* let caller know packet was used */
695 if (eh
->h_proto
!= htons(ETH_P_FCOE
))
697 skb_set_network_header(skb
, sizeof(*eh
));
698 skb_pull(skb
, sizeof(*eh
));
700 fcoe_hdr
= (struct fcoe_hdr
*)skb
->data
;
701 if (FC_FCOE_DECAPS_VER(fcoe_hdr
) != FC_FCOE_VER
)
704 fp
= (struct fc_frame
*)skb
;
706 fr_sof(fp
) = fcoe_hdr
->fcoe_sof
;
707 skb_pull(skb
, sizeof(struct fcoe_hdr
));
708 skb_reset_transport_header(skb
);
710 ft
= (struct fcoe_crc_eof
*)(skb
->data
+ skb
->len
- sizeof(*ft
));
711 fr_eof(fp
) = ft
->fcoe_eof
;
712 skb_trim(skb
, skb
->len
- sizeof(*ft
));
715 dev_kfree_skb_irq(skb
);
720 * fnic_update_mac_locked() - set data MAC address and filters.
721 * @fnic: fnic instance.
722 * @new: newly-assigned FCoE MAC address.
724 * Called with the fnic lock held.
726 void fnic_update_mac_locked(struct fnic
*fnic
, u8
*new)
728 u8
*ctl
= fnic
->ctlr
.ctl_src_addr
;
729 u8
*data
= fnic
->data_src_addr
;
731 if (is_zero_ether_addr(new))
733 if (ether_addr_equal(data
, new))
735 FNIC_FCS_DBG(KERN_DEBUG
, fnic
->lport
->host
, "update_mac %pM\n", new);
736 if (!is_zero_ether_addr(data
) && !ether_addr_equal(data
, ctl
))
737 vnic_dev_del_addr(fnic
->vdev
, data
);
738 memcpy(data
, new, ETH_ALEN
);
739 if (!ether_addr_equal(new, ctl
))
740 vnic_dev_add_addr(fnic
->vdev
, new);
744 * fnic_update_mac() - set data MAC address and filters.
745 * @lport: local port.
746 * @new: newly-assigned FCoE MAC address.
748 void fnic_update_mac(struct fc_lport
*lport
, u8
*new)
750 struct fnic
*fnic
= lport_priv(lport
);
752 spin_lock_irq(&fnic
->fnic_lock
);
753 fnic_update_mac_locked(fnic
, new);
754 spin_unlock_irq(&fnic
->fnic_lock
);
758 * fnic_set_port_id() - set the port_ID after successful FLOGI.
759 * @lport: local port.
760 * @port_id: assigned FC_ID.
761 * @fp: received frame containing the FLOGI accept or NULL.
763 * This is called from libfc when a new FC_ID has been assigned.
764 * This causes us to reset the firmware to FC_MODE and setup the new MAC
767 * It is also called with FC_ID 0 when we're logged off.
769 * If the FC_ID is due to point-to-point, fp may be NULL.
771 void fnic_set_port_id(struct fc_lport
*lport
, u32 port_id
, struct fc_frame
*fp
)
773 struct fnic
*fnic
= lport_priv(lport
);
777 FNIC_FCS_DBG(KERN_DEBUG
, lport
->host
, "set port_id %x fp %p\n",
781 * If we're clearing the FC_ID, change to use the ctl_src_addr.
782 * Set ethernet mode to send FLOGI.
785 fnic_update_mac(lport
, fnic
->ctlr
.ctl_src_addr
);
786 fnic_set_eth_mode(fnic
);
791 mac
= fr_cb(fp
)->granted_mac
;
792 if (is_zero_ether_addr(mac
)) {
793 /* non-FIP - FLOGI already accepted - ignore return */
794 fcoe_ctlr_recv_flogi(&fnic
->ctlr
, lport
, fp
);
796 fnic_update_mac(lport
, mac
);
799 /* Change state to reflect transition to FC mode */
800 spin_lock_irq(&fnic
->fnic_lock
);
801 if (fnic
->state
== FNIC_IN_ETH_MODE
|| fnic
->state
== FNIC_IN_FC_MODE
)
802 fnic
->state
= FNIC_IN_ETH_TRANS_FC_MODE
;
804 FNIC_FCS_DBG(KERN_DEBUG
, fnic
->lport
->host
,
805 "Unexpected fnic state %s while"
806 " processing flogi resp\n",
807 fnic_state_to_str(fnic
->state
));
808 spin_unlock_irq(&fnic
->fnic_lock
);
811 spin_unlock_irq(&fnic
->fnic_lock
);
814 * Send FLOGI registration to firmware to set up FC mode.
815 * The new address will be set up when registration completes.
817 ret
= fnic_flogi_reg_handler(fnic
, port_id
);
820 spin_lock_irq(&fnic
->fnic_lock
);
821 if (fnic
->state
== FNIC_IN_ETH_TRANS_FC_MODE
)
822 fnic
->state
= FNIC_IN_ETH_MODE
;
823 spin_unlock_irq(&fnic
->fnic_lock
);
827 static void fnic_rq_cmpl_frame_recv(struct vnic_rq
*rq
, struct cq_desc
828 *cq_desc
, struct vnic_rq_buf
*buf
,
829 int skipped
__attribute__((unused
)),
832 struct fnic
*fnic
= vnic_dev_priv(rq
->vdev
);
835 struct fnic_stats
*fnic_stats
= &fnic
->fnic_stats
;
836 u8 type
, color
, eop
, sop
, ingress_port
, vlan_stripped
;
837 u8 fcoe
= 0, fcoe_sof
, fcoe_eof
;
838 u8 fcoe_fc_crc_ok
= 1, fcoe_enc_error
= 0;
839 u8 tcp_udp_csum_ok
, udp
, tcp
, ipv4_csum_ok
;
840 u8 ipv6
, ipv4
, ipv4_fragment
, rss_type
, csum_not_calc
;
841 u8 fcs_ok
= 1, packet_error
= 0;
842 u16 q_number
, completed_index
, bytes_written
= 0, vlan
, checksum
;
844 u16 exchange_id
, tmpl
;
847 u32 fcp_bytes_written
= 0;
850 dma_unmap_single(&fnic
->pdev
->dev
, buf
->dma_addr
, buf
->len
,
853 fp
= (struct fc_frame
*)skb
;
856 cq_desc_dec(cq_desc
, &type
, &color
, &q_number
, &completed_index
);
857 if (type
== CQ_DESC_TYPE_RQ_FCP
) {
858 cq_fcp_rq_desc_dec((struct cq_fcp_rq_desc
*)cq_desc
,
859 &type
, &color
, &q_number
, &completed_index
,
860 &eop
, &sop
, &fcoe_fc_crc_ok
, &exchange_id
,
861 &tmpl
, &fcp_bytes_written
, &sof
, &eof
,
862 &ingress_port
, &packet_error
,
863 &fcoe_enc_error
, &fcs_ok
, &vlan_stripped
,
865 skb_trim(skb
, fcp_bytes_written
);
869 } else if (type
== CQ_DESC_TYPE_RQ_ENET
) {
870 cq_enet_rq_desc_dec((struct cq_enet_rq_desc
*)cq_desc
,
871 &type
, &color
, &q_number
, &completed_index
,
872 &ingress_port
, &fcoe
, &eop
, &sop
,
873 &rss_type
, &csum_not_calc
, &rss_hash
,
874 &bytes_written
, &packet_error
,
875 &vlan_stripped
, &vlan
, &checksum
,
876 &fcoe_sof
, &fcoe_fc_crc_ok
,
877 &fcoe_enc_error
, &fcoe_eof
,
878 &tcp_udp_csum_ok
, &udp
, &tcp
,
879 &ipv4_csum_ok
, &ipv6
, &ipv4
,
880 &ipv4_fragment
, &fcs_ok
);
881 skb_trim(skb
, bytes_written
);
883 atomic64_inc(&fnic_stats
->misc_stats
.frame_errors
);
884 FNIC_FCS_DBG(KERN_DEBUG
, fnic
->lport
->host
,
885 "fcs error. dropping packet.\n");
888 if (fnic_import_rq_eth_pkt(fnic
, skb
))
893 shost_printk(KERN_ERR
, fnic
->lport
->host
,
894 "fnic rq_cmpl wrong cq type x%x\n", type
);
898 if (!fcs_ok
|| packet_error
|| !fcoe_fc_crc_ok
|| fcoe_enc_error
) {
899 atomic64_inc(&fnic_stats
->misc_stats
.frame_errors
);
900 FNIC_FCS_DBG(KERN_DEBUG
, fnic
->lport
->host
,
901 "fnic rq_cmpl fcoe x%x fcsok x%x"
902 " pkterr x%x fcoe_fc_crc_ok x%x, fcoe_enc_err"
904 fcoe
, fcs_ok
, packet_error
,
905 fcoe_fc_crc_ok
, fcoe_enc_error
);
909 spin_lock_irqsave(&fnic
->fnic_lock
, flags
);
910 if (fnic
->stop_rx_link_events
) {
911 spin_unlock_irqrestore(&fnic
->fnic_lock
, flags
);
914 fr_dev(fp
) = fnic
->lport
;
915 spin_unlock_irqrestore(&fnic
->fnic_lock
, flags
);
916 if ((fnic_fc_trace_set_data(fnic
->lport
->host
->host_no
, FNIC_FC_RECV
,
917 (char *)skb
->data
, skb
->len
)) != 0) {
918 printk(KERN_ERR
"fnic ctlr frame trace error!!!");
921 skb_queue_tail(&fnic
->frame_queue
, skb
);
922 queue_work(fnic_event_queue
, &fnic
->frame_work
);
926 dev_kfree_skb_irq(skb
);
929 static int fnic_rq_cmpl_handler_cont(struct vnic_dev
*vdev
,
930 struct cq_desc
*cq_desc
, u8 type
,
931 u16 q_number
, u16 completed_index
,
934 struct fnic
*fnic
= vnic_dev_priv(vdev
);
936 vnic_rq_service(&fnic
->rq
[q_number
], cq_desc
, completed_index
,
937 VNIC_RQ_RETURN_DESC
, fnic_rq_cmpl_frame_recv
,
942 int fnic_rq_cmpl_handler(struct fnic
*fnic
, int rq_work_to_do
)
944 unsigned int tot_rq_work_done
= 0, cur_work_done
;
948 for (i
= 0; i
< fnic
->rq_count
; i
++) {
949 cur_work_done
= vnic_cq_service(&fnic
->cq
[i
], rq_work_to_do
,
950 fnic_rq_cmpl_handler_cont
,
953 err
= vnic_rq_fill(&fnic
->rq
[i
], fnic_alloc_rq_frame
);
955 shost_printk(KERN_ERR
, fnic
->lport
->host
,
956 "fnic_alloc_rq_frame can't alloc"
959 tot_rq_work_done
+= cur_work_done
;
962 return tot_rq_work_done
;
966 * This function is called once at init time to allocate and fill RQ
967 * buffers. Subsequently, it is called in the interrupt context after RQ
968 * buffer processing to replenish the buffers in the RQ
970 int fnic_alloc_rq_frame(struct vnic_rq
*rq
)
972 struct fnic
*fnic
= vnic_dev_priv(rq
->vdev
);
978 len
= FC_FRAME_HEADROOM
+ FC_MAX_FRAME
+ FC_FRAME_TAILROOM
;
979 skb
= dev_alloc_skb(len
);
981 FNIC_FCS_DBG(KERN_DEBUG
, fnic
->lport
->host
,
982 "Unable to allocate RQ sk_buff\n");
985 skb_reset_mac_header(skb
);
986 skb_reset_transport_header(skb
);
987 skb_reset_network_header(skb
);
989 pa
= dma_map_single(&fnic
->pdev
->dev
, skb
->data
, len
, DMA_FROM_DEVICE
);
990 if (dma_mapping_error(&fnic
->pdev
->dev
, pa
)) {
992 printk(KERN_ERR
"PCI mapping failed with error %d\n", r
);
996 fnic_queue_rq_desc(rq
, skb
, pa
, len
);
1004 void fnic_free_rq_buf(struct vnic_rq
*rq
, struct vnic_rq_buf
*buf
)
1006 struct fc_frame
*fp
= buf
->os_buf
;
1007 struct fnic
*fnic
= vnic_dev_priv(rq
->vdev
);
1009 dma_unmap_single(&fnic
->pdev
->dev
, buf
->dma_addr
, buf
->len
,
1012 dev_kfree_skb(fp_skb(fp
));
1017 * fnic_eth_send() - Send Ethernet frame.
1018 * @fip: fcoe_ctlr instance.
1019 * @skb: Ethernet Frame, FIP, without VLAN encapsulation.
1021 void fnic_eth_send(struct fcoe_ctlr
*fip
, struct sk_buff
*skb
)
1023 struct fnic
*fnic
= fnic_from_ctlr(fip
);
1024 struct vnic_wq
*wq
= &fnic
->wq
[0];
1026 struct ethhdr
*eth_hdr
;
1027 struct vlan_ethhdr
*vlan_hdr
;
1028 unsigned long flags
;
1030 if (!fnic
->vlan_hw_insert
) {
1031 eth_hdr
= (struct ethhdr
*)skb_mac_header(skb
);
1032 vlan_hdr
= skb_push(skb
, sizeof(*vlan_hdr
) - sizeof(*eth_hdr
));
1033 memcpy(vlan_hdr
, eth_hdr
, 2 * ETH_ALEN
);
1034 vlan_hdr
->h_vlan_proto
= htons(ETH_P_8021Q
);
1035 vlan_hdr
->h_vlan_encapsulated_proto
= eth_hdr
->h_proto
;
1036 vlan_hdr
->h_vlan_TCI
= htons(fnic
->vlan_id
);
1037 if ((fnic_fc_trace_set_data(fnic
->lport
->host
->host_no
,
1038 FNIC_FC_SEND
|0x80, (char *)eth_hdr
, skb
->len
)) != 0) {
1039 printk(KERN_ERR
"fnic ctlr frame trace error!!!");
1042 if ((fnic_fc_trace_set_data(fnic
->lport
->host
->host_no
,
1043 FNIC_FC_SEND
|0x80, (char *)skb
->data
, skb
->len
)) != 0) {
1044 printk(KERN_ERR
"fnic ctlr frame trace error!!!");
1048 pa
= dma_map_single(&fnic
->pdev
->dev
, skb
->data
, skb
->len
,
1050 if (dma_mapping_error(&fnic
->pdev
->dev
, pa
)) {
1051 printk(KERN_ERR
"DMA mapping failed\n");
1055 spin_lock_irqsave(&fnic
->wq_lock
[0], flags
);
1056 if (!vnic_wq_desc_avail(wq
))
1059 fnic_queue_wq_eth_desc(wq
, skb
, pa
, skb
->len
,
1060 0 /* hw inserts cos value */,
1062 spin_unlock_irqrestore(&fnic
->wq_lock
[0], flags
);
1066 spin_unlock_irqrestore(&fnic
->wq_lock
[0], flags
);
1067 dma_unmap_single(&fnic
->pdev
->dev
, pa
, skb
->len
, DMA_TO_DEVICE
);
1075 static int fnic_send_frame(struct fnic
*fnic
, struct fc_frame
*fp
)
1077 struct vnic_wq
*wq
= &fnic
->wq
[0];
1078 struct sk_buff
*skb
;
1080 struct ethhdr
*eth_hdr
;
1081 struct vlan_ethhdr
*vlan_hdr
;
1082 struct fcoe_hdr
*fcoe_hdr
;
1083 struct fc_frame_header
*fh
;
1084 u32 tot_len
, eth_hdr_len
;
1086 unsigned long flags
;
1088 fh
= fc_frame_header_get(fp
);
1091 if (unlikely(fh
->fh_r_ctl
== FC_RCTL_ELS_REQ
) &&
1092 fcoe_ctlr_els_send(&fnic
->ctlr
, fnic
->lport
, skb
))
1095 if (!fnic
->vlan_hw_insert
) {
1096 eth_hdr_len
= sizeof(*vlan_hdr
) + sizeof(*fcoe_hdr
);
1097 vlan_hdr
= skb_push(skb
, eth_hdr_len
);
1098 eth_hdr
= (struct ethhdr
*)vlan_hdr
;
1099 vlan_hdr
->h_vlan_proto
= htons(ETH_P_8021Q
);
1100 vlan_hdr
->h_vlan_encapsulated_proto
= htons(ETH_P_FCOE
);
1101 vlan_hdr
->h_vlan_TCI
= htons(fnic
->vlan_id
);
1102 fcoe_hdr
= (struct fcoe_hdr
*)(vlan_hdr
+ 1);
1104 eth_hdr_len
= sizeof(*eth_hdr
) + sizeof(*fcoe_hdr
);
1105 eth_hdr
= skb_push(skb
, eth_hdr_len
);
1106 eth_hdr
->h_proto
= htons(ETH_P_FCOE
);
1107 fcoe_hdr
= (struct fcoe_hdr
*)(eth_hdr
+ 1);
1110 if (fnic
->ctlr
.map_dest
)
1111 fc_fcoe_set_mac(eth_hdr
->h_dest
, fh
->fh_d_id
);
1113 memcpy(eth_hdr
->h_dest
, fnic
->ctlr
.dest_addr
, ETH_ALEN
);
1114 memcpy(eth_hdr
->h_source
, fnic
->data_src_addr
, ETH_ALEN
);
1117 BUG_ON(tot_len
% 4);
1119 memset(fcoe_hdr
, 0, sizeof(*fcoe_hdr
));
1120 fcoe_hdr
->fcoe_sof
= fr_sof(fp
);
1122 FC_FCOE_ENCAPS_VER(fcoe_hdr
, FC_FCOE_VER
);
1124 pa
= dma_map_single(&fnic
->pdev
->dev
, eth_hdr
, tot_len
, DMA_TO_DEVICE
);
1125 if (dma_mapping_error(&fnic
->pdev
->dev
, pa
)) {
1127 printk(KERN_ERR
"DMA map failed with error %d\n", ret
);
1128 goto free_skb_on_err
;
1131 if ((fnic_fc_trace_set_data(fnic
->lport
->host
->host_no
, FNIC_FC_SEND
,
1132 (char *)eth_hdr
, tot_len
)) != 0) {
1133 printk(KERN_ERR
"fnic ctlr frame trace error!!!");
1136 spin_lock_irqsave(&fnic
->wq_lock
[0], flags
);
1138 if (!vnic_wq_desc_avail(wq
)) {
1139 dma_unmap_single(&fnic
->pdev
->dev
, pa
, tot_len
, DMA_TO_DEVICE
);
1144 fnic_queue_wq_desc(wq
, skb
, pa
, tot_len
, fr_eof(fp
),
1145 0 /* hw inserts cos value */,
1146 fnic
->vlan_id
, 1, 1, 1);
1149 spin_unlock_irqrestore(&fnic
->wq_lock
[0], flags
);
1153 dev_kfree_skb_any(fp_skb(fp
));
1160 * Routine to send a raw frame
1162 int fnic_send(struct fc_lport
*lp
, struct fc_frame
*fp
)
1164 struct fnic
*fnic
= lport_priv(lp
);
1165 unsigned long flags
;
1167 if (fnic
->in_remove
) {
1168 dev_kfree_skb(fp_skb(fp
));
1173 * Queue frame if in a transitional state.
1174 * This occurs while registering the Port_ID / MAC address after FLOGI.
1176 spin_lock_irqsave(&fnic
->fnic_lock
, flags
);
1177 if (fnic
->state
!= FNIC_IN_FC_MODE
&& fnic
->state
!= FNIC_IN_ETH_MODE
) {
1178 skb_queue_tail(&fnic
->tx_queue
, fp_skb(fp
));
1179 spin_unlock_irqrestore(&fnic
->fnic_lock
, flags
);
1182 spin_unlock_irqrestore(&fnic
->fnic_lock
, flags
);
1184 return fnic_send_frame(fnic
, fp
);
1188 * fnic_flush_tx() - send queued frames.
1189 * @fnic: fnic device
1191 * Send frames that were waiting to go out in FC or Ethernet mode.
1192 * Whenever changing modes we purge queued frames, so these frames should
1193 * be queued for the stable mode that we're in, either FC or Ethernet.
1195 * Called without fnic_lock held.
1197 void fnic_flush_tx(struct fnic
*fnic
)
1199 struct sk_buff
*skb
;
1200 struct fc_frame
*fp
;
1202 while ((skb
= skb_dequeue(&fnic
->tx_queue
))) {
1203 fp
= (struct fc_frame
*)skb
;
1204 fnic_send_frame(fnic
, fp
);
1209 * fnic_set_eth_mode() - put fnic into ethernet mode.
1210 * @fnic: fnic device
1212 * Called without fnic lock held.
1214 static void fnic_set_eth_mode(struct fnic
*fnic
)
1216 unsigned long flags
;
1217 enum fnic_state old_state
;
1220 spin_lock_irqsave(&fnic
->fnic_lock
, flags
);
1222 old_state
= fnic
->state
;
1223 switch (old_state
) {
1224 case FNIC_IN_FC_MODE
:
1225 case FNIC_IN_ETH_TRANS_FC_MODE
:
1227 fnic
->state
= FNIC_IN_FC_TRANS_ETH_MODE
;
1228 spin_unlock_irqrestore(&fnic
->fnic_lock
, flags
);
1230 ret
= fnic_fw_reset_handler(fnic
);
1232 spin_lock_irqsave(&fnic
->fnic_lock
, flags
);
1233 if (fnic
->state
!= FNIC_IN_FC_TRANS_ETH_MODE
)
1236 fnic
->state
= old_state
;
1239 case FNIC_IN_FC_TRANS_ETH_MODE
:
1240 case FNIC_IN_ETH_MODE
:
1243 spin_unlock_irqrestore(&fnic
->fnic_lock
, flags
);
1246 static void fnic_wq_complete_frame_send(struct vnic_wq
*wq
,
1247 struct cq_desc
*cq_desc
,
1248 struct vnic_wq_buf
*buf
, void *opaque
)
1250 struct sk_buff
*skb
= buf
->os_buf
;
1251 struct fc_frame
*fp
= (struct fc_frame
*)skb
;
1252 struct fnic
*fnic
= vnic_dev_priv(wq
->vdev
);
1254 dma_unmap_single(&fnic
->pdev
->dev
, buf
->dma_addr
, buf
->len
,
1256 dev_kfree_skb_irq(fp_skb(fp
));
1260 static int fnic_wq_cmpl_handler_cont(struct vnic_dev
*vdev
,
1261 struct cq_desc
*cq_desc
, u8 type
,
1262 u16 q_number
, u16 completed_index
,
1265 struct fnic
*fnic
= vnic_dev_priv(vdev
);
1266 unsigned long flags
;
1268 spin_lock_irqsave(&fnic
->wq_lock
[q_number
], flags
);
1269 vnic_wq_service(&fnic
->wq
[q_number
], cq_desc
, completed_index
,
1270 fnic_wq_complete_frame_send
, NULL
);
1271 spin_unlock_irqrestore(&fnic
->wq_lock
[q_number
], flags
);
1276 int fnic_wq_cmpl_handler(struct fnic
*fnic
, int work_to_do
)
1278 unsigned int wq_work_done
= 0;
1281 for (i
= 0; i
< fnic
->raw_wq_count
; i
++) {
1282 wq_work_done
+= vnic_cq_service(&fnic
->cq
[fnic
->rq_count
+i
],
1284 fnic_wq_cmpl_handler_cont
,
1288 return wq_work_done
;
1292 void fnic_free_wq_buf(struct vnic_wq
*wq
, struct vnic_wq_buf
*buf
)
1294 struct fc_frame
*fp
= buf
->os_buf
;
1295 struct fnic
*fnic
= vnic_dev_priv(wq
->vdev
);
1297 dma_unmap_single(&fnic
->pdev
->dev
, buf
->dma_addr
, buf
->len
,
1300 dev_kfree_skb(fp_skb(fp
));
1304 void fnic_fcoe_reset_vlans(struct fnic
*fnic
)
1306 unsigned long flags
;
1307 struct fcoe_vlan
*vlan
;
1308 struct fcoe_vlan
*next
;
1311 * indicate a link down to fcoe so that all fcf's are free'd
1312 * might not be required since we did this before sending vlan
1315 spin_lock_irqsave(&fnic
->vlans_lock
, flags
);
1316 if (!list_empty(&fnic
->vlans
)) {
1317 list_for_each_entry_safe(vlan
, next
, &fnic
->vlans
, list
) {
1318 list_del(&vlan
->list
);
1322 spin_unlock_irqrestore(&fnic
->vlans_lock
, flags
);
1325 void fnic_handle_fip_timer(struct fnic
*fnic
)
1327 unsigned long flags
;
1328 struct fcoe_vlan
*vlan
;
1329 struct fnic_stats
*fnic_stats
= &fnic
->fnic_stats
;
1332 spin_lock_irqsave(&fnic
->fnic_lock
, flags
);
1333 if (fnic
->stop_rx_link_events
) {
1334 spin_unlock_irqrestore(&fnic
->fnic_lock
, flags
);
1337 spin_unlock_irqrestore(&fnic
->fnic_lock
, flags
);
1339 if (fnic
->ctlr
.mode
== FIP_MODE_NON_FIP
)
1342 spin_lock_irqsave(&fnic
->vlans_lock
, flags
);
1343 if (list_empty(&fnic
->vlans
)) {
1344 spin_unlock_irqrestore(&fnic
->vlans_lock
, flags
);
1345 /* no vlans available, try again */
1346 if (printk_ratelimit())
1347 FNIC_FCS_DBG(KERN_DEBUG
, fnic
->lport
->host
,
1348 "Start VLAN Discovery\n");
1349 fnic_event_enq(fnic
, FNIC_EVT_START_VLAN_DISC
);
1353 vlan
= list_first_entry(&fnic
->vlans
, struct fcoe_vlan
, list
);
1354 FNIC_FCS_DBG(KERN_DEBUG
, fnic
->lport
->host
,
1355 "fip_timer: vlan %d state %d sol_count %d\n",
1356 vlan
->vid
, vlan
->state
, vlan
->sol_count
);
1357 switch (vlan
->state
) {
1359 FNIC_FCS_DBG(KERN_DEBUG
, fnic
->lport
->host
,
1360 "FIP VLAN is selected for FC transaction\n");
1361 spin_unlock_irqrestore(&fnic
->vlans_lock
, flags
);
1363 case FIP_VLAN_FAILED
:
1364 spin_unlock_irqrestore(&fnic
->vlans_lock
, flags
);
1365 /* if all vlans are in failed state, restart vlan disc */
1366 if (printk_ratelimit())
1367 FNIC_FCS_DBG(KERN_DEBUG
, fnic
->lport
->host
,
1368 "Start VLAN Discovery\n");
1369 fnic_event_enq(fnic
, FNIC_EVT_START_VLAN_DISC
);
1372 if (vlan
->sol_count
>= FCOE_CTLR_MAX_SOL
) {
1374 * no response on this vlan, remove from the list.
1377 FNIC_FCS_DBG(KERN_INFO
, fnic
->lport
->host
,
1378 "Dequeue this VLAN ID %d from list\n",
1380 list_del(&vlan
->list
);
1383 if (list_empty(&fnic
->vlans
)) {
1384 /* we exhausted all vlans, restart vlan disc */
1385 spin_unlock_irqrestore(&fnic
->vlans_lock
,
1387 FNIC_FCS_DBG(KERN_INFO
, fnic
->lport
->host
,
1388 "fip_timer: vlan list empty, "
1389 "trigger vlan disc\n");
1390 fnic_event_enq(fnic
, FNIC_EVT_START_VLAN_DISC
);
1393 /* check the next vlan */
1394 vlan
= list_first_entry(&fnic
->vlans
, struct fcoe_vlan
,
1396 fnic
->set_vlan(fnic
, vlan
->vid
);
1397 vlan
->state
= FIP_VLAN_SENT
; /* sent now */
1399 spin_unlock_irqrestore(&fnic
->vlans_lock
, flags
);
1400 atomic64_inc(&fnic_stats
->vlan_stats
.sol_expiry_count
);
1402 sol_time
= jiffies
+ msecs_to_jiffies
1403 (FCOE_CTLR_START_DELAY
);
1404 mod_timer(&fnic
->fip_timer
, round_jiffies(sol_time
));