1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright 2008 Cisco Systems, Inc. All rights reserved.
4 * Copyright 2007 Nuova Systems, Inc. All rights reserved.
6 #include <linux/errno.h>
8 #include <linux/slab.h>
9 #include <linux/skbuff.h>
10 #include <linux/interrupt.h>
11 #include <linux/spinlock.h>
12 #include <linux/if_ether.h>
13 #include <linux/if_vlan.h>
14 #include <linux/workqueue.h>
15 #include <scsi/fc/fc_fip.h>
16 #include <scsi/fc/fc_els.h>
17 #include <scsi/fc/fc_fcoe.h>
18 #include <scsi/fc_frame.h>
19 #include <scsi/libfc.h>
23 #include "cq_enet_desc.h"
24 #include "cq_exch_desc.h"
26 static u8 fcoe_all_fcfs
[ETH_ALEN
] = FIP_ALL_FCF_MACS
;
27 struct workqueue_struct
*fnic_fip_queue
;
28 struct workqueue_struct
*fnic_event_queue
;
30 static void fnic_set_eth_mode(struct fnic
*);
31 static void fnic_fcoe_send_vlan_req(struct fnic
*fnic
);
32 static void fnic_fcoe_start_fcf_disc(struct fnic
*fnic
);
33 static void fnic_fcoe_process_vlan_resp(struct fnic
*fnic
, struct sk_buff
*);
34 static int fnic_fcoe_vlan_check(struct fnic
*fnic
, u16 flag
);
35 static int fnic_fcoe_handle_fip_frame(struct fnic
*fnic
, struct sk_buff
*skb
);
37 void fnic_handle_link(struct work_struct
*work
)
39 struct fnic
*fnic
= container_of(work
, struct fnic
, link_work
);
42 u32 old_link_down_cnt
;
43 u64 old_port_speed
, new_port_speed
;
45 spin_lock_irqsave(&fnic
->fnic_lock
, flags
);
47 fnic
->link_events
= 1; /* less work to just set everytime*/
49 if (fnic
->stop_rx_link_events
) {
50 spin_unlock_irqrestore(&fnic
->fnic_lock
, flags
);
54 old_link_down_cnt
= fnic
->link_down_cnt
;
55 old_link_status
= fnic
->link_status
;
56 old_port_speed
= atomic64_read(
57 &fnic
->fnic_stats
.misc_stats
.current_port_speed
);
59 fnic
->link_status
= vnic_dev_link_status(fnic
->vdev
);
60 fnic
->link_down_cnt
= vnic_dev_link_down_cnt(fnic
->vdev
);
62 new_port_speed
= vnic_dev_port_speed(fnic
->vdev
);
63 atomic64_set(&fnic
->fnic_stats
.misc_stats
.current_port_speed
,
65 if (old_port_speed
!= new_port_speed
)
66 FNIC_FCS_DBG(KERN_INFO
, fnic
->lport
->host
, fnic
->fnic_num
,
67 "Current vnic speed set to: %llu\n",
70 switch (vnic_dev_port_speed(fnic
->vdev
)) {
71 case DCEM_PORTSPEED_10G
:
72 fc_host_speed(fnic
->lport
->host
) = FC_PORTSPEED_10GBIT
;
73 fnic
->lport
->link_supported_speeds
= FC_PORTSPEED_10GBIT
;
75 case DCEM_PORTSPEED_20G
:
76 fc_host_speed(fnic
->lport
->host
) = FC_PORTSPEED_20GBIT
;
77 fnic
->lport
->link_supported_speeds
= FC_PORTSPEED_20GBIT
;
79 case DCEM_PORTSPEED_25G
:
80 fc_host_speed(fnic
->lport
->host
) = FC_PORTSPEED_25GBIT
;
81 fnic
->lport
->link_supported_speeds
= FC_PORTSPEED_25GBIT
;
83 case DCEM_PORTSPEED_40G
:
84 case DCEM_PORTSPEED_4x10G
:
85 fc_host_speed(fnic
->lport
->host
) = FC_PORTSPEED_40GBIT
;
86 fnic
->lport
->link_supported_speeds
= FC_PORTSPEED_40GBIT
;
88 case DCEM_PORTSPEED_100G
:
89 fc_host_speed(fnic
->lport
->host
) = FC_PORTSPEED_100GBIT
;
90 fnic
->lport
->link_supported_speeds
= FC_PORTSPEED_100GBIT
;
93 fc_host_speed(fnic
->lport
->host
) = FC_PORTSPEED_UNKNOWN
;
94 fnic
->lport
->link_supported_speeds
= FC_PORTSPEED_UNKNOWN
;
98 if (old_link_status
== fnic
->link_status
) {
99 if (!fnic
->link_status
) {
101 spin_unlock_irqrestore(&fnic
->fnic_lock
, flags
);
102 fnic_fc_trace_set_data(fnic
->lport
->host
->host_no
,
103 FNIC_FC_LE
, "Link Status: DOWN->DOWN",
104 strlen("Link Status: DOWN->DOWN"));
105 FNIC_FCS_DBG(KERN_INFO
, fnic
->lport
->host
, fnic
->fnic_num
,
108 if (old_link_down_cnt
!= fnic
->link_down_cnt
) {
109 /* UP -> DOWN -> UP */
110 fnic
->lport
->host_stats
.link_failure_count
++;
111 spin_unlock_irqrestore(&fnic
->fnic_lock
, flags
);
112 fnic_fc_trace_set_data(
113 fnic
->lport
->host
->host_no
,
115 "Link Status:UP_DOWN_UP",
116 strlen("Link_Status:UP_DOWN_UP")
118 FNIC_FCS_DBG(KERN_DEBUG
, fnic
->lport
->host
, fnic
->fnic_num
,
120 fcoe_ctlr_link_down(&fnic
->ctlr
);
121 if (fnic
->config
.flags
& VFCF_FIP_CAPABLE
) {
122 /* start FCoE VLAN discovery */
123 fnic_fc_trace_set_data(
124 fnic
->lport
->host
->host_no
,
126 "Link Status: UP_DOWN_UP_VLAN",
128 "Link Status: UP_DOWN_UP_VLAN")
130 fnic_fcoe_send_vlan_req(fnic
);
133 FNIC_FCS_DBG(KERN_INFO
, fnic
->lport
->host
, fnic
->fnic_num
,
134 "up->down->up: Link up\n");
135 fcoe_ctlr_link_up(&fnic
->ctlr
);
138 spin_unlock_irqrestore(&fnic
->fnic_lock
, flags
);
139 fnic_fc_trace_set_data(
140 fnic
->lport
->host
->host_no
, FNIC_FC_LE
,
141 "Link Status: UP_UP",
142 strlen("Link Status: UP_UP"));
143 FNIC_FCS_DBG(KERN_INFO
, fnic
->lport
->host
, fnic
->fnic_num
,
147 } else if (fnic
->link_status
) {
149 spin_unlock_irqrestore(&fnic
->fnic_lock
, flags
);
150 if (fnic
->config
.flags
& VFCF_FIP_CAPABLE
) {
151 /* start FCoE VLAN discovery */
152 fnic_fc_trace_set_data(fnic
->lport
->host
->host_no
,
153 FNIC_FC_LE
, "Link Status: DOWN_UP_VLAN",
154 strlen("Link Status: DOWN_UP_VLAN"));
155 fnic_fcoe_send_vlan_req(fnic
);
160 FNIC_FCS_DBG(KERN_INFO
, fnic
->lport
->host
, fnic
->fnic_num
,
161 "down->up: Link up\n");
162 fnic_fc_trace_set_data(fnic
->lport
->host
->host_no
, FNIC_FC_LE
,
163 "Link Status: DOWN_UP", strlen("Link Status: DOWN_UP"));
164 fcoe_ctlr_link_up(&fnic
->ctlr
);
167 fnic
->lport
->host_stats
.link_failure_count
++;
168 spin_unlock_irqrestore(&fnic
->fnic_lock
, flags
);
169 FNIC_FCS_DBG(KERN_INFO
, fnic
->lport
->host
, fnic
->fnic_num
,
170 "up->down: Link down\n");
171 fnic_fc_trace_set_data(
172 fnic
->lport
->host
->host_no
, FNIC_FC_LE
,
173 "Link Status: UP_DOWN",
174 strlen("Link Status: UP_DOWN"));
175 if (fnic
->config
.flags
& VFCF_FIP_CAPABLE
) {
176 FNIC_FCS_DBG(KERN_DEBUG
, fnic
->lport
->host
, fnic
->fnic_num
,
177 "deleting fip-timer during link-down\n");
178 del_timer_sync(&fnic
->fip_timer
);
180 fcoe_ctlr_link_down(&fnic
->ctlr
);
186 * This function passes incoming fabric frames to libFC
188 void fnic_handle_frame(struct work_struct
*work
)
190 struct fnic
*fnic
= container_of(work
, struct fnic
, frame_work
);
191 struct fc_lport
*lp
= fnic
->lport
;
196 while ((skb
= skb_dequeue(&fnic
->frame_queue
))) {
198 spin_lock_irqsave(&fnic
->fnic_lock
, flags
);
199 if (fnic
->stop_rx_link_events
) {
200 spin_unlock_irqrestore(&fnic
->fnic_lock
, flags
);
204 fp
= (struct fc_frame
*)skb
;
207 * If we're in a transitional state, just re-queue and return.
208 * The queue will be serviced when we get to a stable state.
210 if (fnic
->state
!= FNIC_IN_FC_MODE
&&
211 fnic
->state
!= FNIC_IN_ETH_MODE
) {
212 skb_queue_head(&fnic
->frame_queue
, skb
);
213 spin_unlock_irqrestore(&fnic
->fnic_lock
, flags
);
216 spin_unlock_irqrestore(&fnic
->fnic_lock
, flags
);
218 fc_exch_recv(lp
, fp
);
222 void fnic_fcoe_evlist_free(struct fnic
*fnic
)
224 struct fnic_event
*fevt
= NULL
;
225 struct fnic_event
*next
= NULL
;
228 spin_lock_irqsave(&fnic
->fnic_lock
, flags
);
229 if (list_empty(&fnic
->evlist
)) {
230 spin_unlock_irqrestore(&fnic
->fnic_lock
, flags
);
234 list_for_each_entry_safe(fevt
, next
, &fnic
->evlist
, list
) {
235 list_del(&fevt
->list
);
238 spin_unlock_irqrestore(&fnic
->fnic_lock
, flags
);
241 void fnic_handle_event(struct work_struct
*work
)
243 struct fnic
*fnic
= container_of(work
, struct fnic
, event_work
);
244 struct fnic_event
*fevt
= NULL
;
245 struct fnic_event
*next
= NULL
;
248 spin_lock_irqsave(&fnic
->fnic_lock
, flags
);
249 if (list_empty(&fnic
->evlist
)) {
250 spin_unlock_irqrestore(&fnic
->fnic_lock
, flags
);
254 list_for_each_entry_safe(fevt
, next
, &fnic
->evlist
, list
) {
255 if (fnic
->stop_rx_link_events
) {
256 list_del(&fevt
->list
);
258 spin_unlock_irqrestore(&fnic
->fnic_lock
, flags
);
262 * If we're in a transitional state, just re-queue and return.
263 * The queue will be serviced when we get to a stable state.
265 if (fnic
->state
!= FNIC_IN_FC_MODE
&&
266 fnic
->state
!= FNIC_IN_ETH_MODE
) {
267 spin_unlock_irqrestore(&fnic
->fnic_lock
, flags
);
271 list_del(&fevt
->list
);
272 switch (fevt
->event
) {
273 case FNIC_EVT_START_VLAN_DISC
:
274 spin_unlock_irqrestore(&fnic
->fnic_lock
, flags
);
275 fnic_fcoe_send_vlan_req(fnic
);
276 spin_lock_irqsave(&fnic
->fnic_lock
, flags
);
278 case FNIC_EVT_START_FCF_DISC
:
279 FNIC_FCS_DBG(KERN_DEBUG
, fnic
->lport
->host
, fnic
->fnic_num
,
280 "Start FCF Discovery\n");
281 fnic_fcoe_start_fcf_disc(fnic
);
284 FNIC_FCS_DBG(KERN_DEBUG
, fnic
->lport
->host
, fnic
->fnic_num
,
285 "Unknown event 0x%x\n", fevt
->event
);
290 spin_unlock_irqrestore(&fnic
->fnic_lock
, flags
);
294 * is_fnic_fip_flogi_reject() - Check if the Received FIP FLOGI frame is rejected
295 * @fip: The FCoE controller that received the frame
296 * @skb: The received FIP frame
298 * Returns non-zero if the frame is rejected with unsupported cmd with
299 * insufficient resource els explanation.
301 static inline int is_fnic_fip_flogi_reject(struct fcoe_ctlr
*fip
,
304 struct fc_lport
*lport
= fip
->lp
;
305 struct fip_header
*fiph
;
306 struct fc_frame_header
*fh
= NULL
;
307 struct fip_desc
*desc
;
308 struct fip_encaps
*els
;
316 if (skb_linearize(skb
))
319 if (skb
->len
< sizeof(*fiph
))
322 fiph
= (struct fip_header
*)skb
->data
;
323 op
= ntohs(fiph
->fip_op
);
324 sub
= fiph
->fip_subcode
;
329 if (sub
!= FIP_SC_REP
)
332 rlen
= ntohs(fiph
->fip_dl_len
) * 4;
333 if (rlen
+ sizeof(*fiph
) > skb
->len
)
336 desc
= (struct fip_desc
*)(fiph
+ 1);
337 dlen
= desc
->fip_dlen
* FIP_BPW
;
339 if (desc
->fip_dtype
== FIP_DT_FLOGI
) {
341 if (dlen
< sizeof(*els
) + sizeof(*fh
) + 1)
344 els
= (struct fip_encaps
*)desc
;
345 fh
= (struct fc_frame_header
*)(els
+ 1);
351 * ELS command code, reason and explanation should be = Reject,
352 * unsupported command and insufficient resource
354 els_op
= *(u8
*)(fh
+ 1);
355 if (els_op
== ELS_LS_RJT
) {
356 shost_printk(KERN_INFO
, lport
->host
,
357 "Flogi Request Rejected by Switch\n");
360 shost_printk(KERN_INFO
, lport
->host
,
361 "Flogi Request Accepted by Switch\n");
366 static void fnic_fcoe_send_vlan_req(struct fnic
*fnic
)
368 struct fcoe_ctlr
*fip
= &fnic
->ctlr
;
369 struct fnic_stats
*fnic_stats
= &fnic
->fnic_stats
;
372 struct fip_vlan
*vlan
;
375 fnic_fcoe_reset_vlans(fnic
);
376 fnic
->set_vlan(fnic
, 0);
378 if (printk_ratelimit())
379 FNIC_FCS_DBG(KERN_INFO
, fnic
->lport
->host
, fnic
->fnic_num
,
380 "Sending VLAN request...\n");
382 skb
= dev_alloc_skb(sizeof(struct fip_vlan
));
386 eth_fr
= (char *)skb
->data
;
387 vlan
= (struct fip_vlan
*)eth_fr
;
389 memset(vlan
, 0, sizeof(*vlan
));
390 memcpy(vlan
->eth
.h_source
, fip
->ctl_src_addr
, ETH_ALEN
);
391 memcpy(vlan
->eth
.h_dest
, fcoe_all_fcfs
, ETH_ALEN
);
392 vlan
->eth
.h_proto
= htons(ETH_P_FIP
);
394 vlan
->fip
.fip_ver
= FIP_VER_ENCAPS(FIP_VER
);
395 vlan
->fip
.fip_op
= htons(FIP_OP_VLAN
);
396 vlan
->fip
.fip_subcode
= FIP_SC_VL_REQ
;
397 vlan
->fip
.fip_dl_len
= htons(sizeof(vlan
->desc
) / FIP_BPW
);
399 vlan
->desc
.mac
.fd_desc
.fip_dtype
= FIP_DT_MAC
;
400 vlan
->desc
.mac
.fd_desc
.fip_dlen
= sizeof(vlan
->desc
.mac
) / FIP_BPW
;
401 memcpy(&vlan
->desc
.mac
.fd_mac
, fip
->ctl_src_addr
, ETH_ALEN
);
403 vlan
->desc
.wwnn
.fd_desc
.fip_dtype
= FIP_DT_NAME
;
404 vlan
->desc
.wwnn
.fd_desc
.fip_dlen
= sizeof(vlan
->desc
.wwnn
) / FIP_BPW
;
405 put_unaligned_be64(fip
->lp
->wwnn
, &vlan
->desc
.wwnn
.fd_wwn
);
406 atomic64_inc(&fnic_stats
->vlan_stats
.vlan_disc_reqs
);
408 skb_put(skb
, sizeof(*vlan
));
409 skb
->protocol
= htons(ETH_P_FIP
);
410 skb_reset_mac_header(skb
);
411 skb_reset_network_header(skb
);
414 /* set a timer so that we can retry if there no response */
415 vlan_tov
= jiffies
+ msecs_to_jiffies(FCOE_CTLR_FIPVLAN_TOV
);
416 mod_timer(&fnic
->fip_timer
, round_jiffies(vlan_tov
));
419 static void fnic_fcoe_process_vlan_resp(struct fnic
*fnic
, struct sk_buff
*skb
)
421 struct fcoe_ctlr
*fip
= &fnic
->ctlr
;
422 struct fip_header
*fiph
;
423 struct fip_desc
*desc
;
424 struct fnic_stats
*fnic_stats
= &fnic
->fnic_stats
;
428 struct fcoe_vlan
*vlan
;
432 FNIC_FCS_DBG(KERN_INFO
, fnic
->lport
->host
, fnic
->fnic_num
,
433 "Received VLAN response...\n");
435 fiph
= (struct fip_header
*) skb
->data
;
437 FNIC_FCS_DBG(KERN_INFO
, fnic
->lport
->host
, fnic
->fnic_num
,
438 "Received VLAN response... OP 0x%x SUB_OP 0x%x\n",
439 ntohs(fiph
->fip_op
), fiph
->fip_subcode
);
441 rlen
= ntohs(fiph
->fip_dl_len
) * 4;
442 fnic_fcoe_reset_vlans(fnic
);
443 spin_lock_irqsave(&fnic
->vlans_lock
, flags
);
444 desc
= (struct fip_desc
*)(fiph
+ 1);
446 dlen
= desc
->fip_dlen
* FIP_BPW
;
447 switch (desc
->fip_dtype
) {
449 vid
= ntohs(((struct fip_vlan_desc
*)desc
)->fd_vlan
);
450 shost_printk(KERN_INFO
, fnic
->lport
->host
,
451 "process_vlan_resp: FIP VLAN %d\n", vid
);
452 vlan
= kzalloc(sizeof(*vlan
), GFP_ATOMIC
);
454 /* retry from timer */
455 spin_unlock_irqrestore(&fnic
->vlans_lock
,
459 vlan
->vid
= vid
& 0x0fff;
460 vlan
->state
= FIP_VLAN_AVAIL
;
461 list_add_tail(&vlan
->list
, &fnic
->vlans
);
464 desc
= (struct fip_desc
*)((char *)desc
+ dlen
);
468 /* any VLAN descriptors present ? */
469 if (list_empty(&fnic
->vlans
)) {
470 /* retry from timer */
471 atomic64_inc(&fnic_stats
->vlan_stats
.resp_withno_vlanID
);
472 FNIC_FCS_DBG(KERN_INFO
, fnic
->lport
->host
, fnic
->fnic_num
,
473 "No VLAN descriptors in FIP VLAN response\n");
474 spin_unlock_irqrestore(&fnic
->vlans_lock
, flags
);
478 vlan
= list_first_entry(&fnic
->vlans
, struct fcoe_vlan
, list
);
479 fnic
->set_vlan(fnic
, vlan
->vid
);
480 vlan
->state
= FIP_VLAN_SENT
; /* sent now */
482 spin_unlock_irqrestore(&fnic
->vlans_lock
, flags
);
484 /* start the solicitation */
485 fcoe_ctlr_link_up(fip
);
487 sol_time
= jiffies
+ msecs_to_jiffies(FCOE_CTLR_START_DELAY
);
488 mod_timer(&fnic
->fip_timer
, round_jiffies(sol_time
));
493 static void fnic_fcoe_start_fcf_disc(struct fnic
*fnic
)
496 struct fcoe_vlan
*vlan
;
499 spin_lock_irqsave(&fnic
->vlans_lock
, flags
);
500 vlan
= list_first_entry(&fnic
->vlans
, struct fcoe_vlan
, list
);
501 fnic
->set_vlan(fnic
, vlan
->vid
);
502 vlan
->state
= FIP_VLAN_SENT
; /* sent now */
504 spin_unlock_irqrestore(&fnic
->vlans_lock
, flags
);
506 /* start the solicitation */
507 fcoe_ctlr_link_up(&fnic
->ctlr
);
509 sol_time
= jiffies
+ msecs_to_jiffies(FCOE_CTLR_START_DELAY
);
510 mod_timer(&fnic
->fip_timer
, round_jiffies(sol_time
));
513 static int fnic_fcoe_vlan_check(struct fnic
*fnic
, u16 flag
)
516 struct fcoe_vlan
*fvlan
;
518 spin_lock_irqsave(&fnic
->vlans_lock
, flags
);
519 if (list_empty(&fnic
->vlans
)) {
520 spin_unlock_irqrestore(&fnic
->vlans_lock
, flags
);
524 fvlan
= list_first_entry(&fnic
->vlans
, struct fcoe_vlan
, list
);
525 if (fvlan
->state
== FIP_VLAN_USED
) {
526 spin_unlock_irqrestore(&fnic
->vlans_lock
, flags
);
530 if (fvlan
->state
== FIP_VLAN_SENT
) {
531 fvlan
->state
= FIP_VLAN_USED
;
532 spin_unlock_irqrestore(&fnic
->vlans_lock
, flags
);
535 spin_unlock_irqrestore(&fnic
->vlans_lock
, flags
);
539 static void fnic_event_enq(struct fnic
*fnic
, enum fnic_evt ev
)
541 struct fnic_event
*fevt
;
544 fevt
= kmalloc(sizeof(*fevt
), GFP_ATOMIC
);
551 spin_lock_irqsave(&fnic
->fnic_lock
, flags
);
552 list_add_tail(&fevt
->list
, &fnic
->evlist
);
553 spin_unlock_irqrestore(&fnic
->fnic_lock
, flags
);
555 schedule_work(&fnic
->event_work
);
558 static int fnic_fcoe_handle_fip_frame(struct fnic
*fnic
, struct sk_buff
*skb
)
560 struct fip_header
*fiph
;
565 if (!skb
|| !(skb
->data
))
568 if (skb_linearize(skb
))
571 fiph
= (struct fip_header
*)skb
->data
;
572 op
= ntohs(fiph
->fip_op
);
573 sub
= fiph
->fip_subcode
;
575 if (FIP_VER_DECAPS(fiph
->fip_ver
) != FIP_VER
)
578 if (ntohs(fiph
->fip_dl_len
) * FIP_BPW
+ sizeof(*fiph
) > skb
->len
)
581 if (op
== FIP_OP_DISC
&& sub
== FIP_SC_ADV
) {
582 if (fnic_fcoe_vlan_check(fnic
, ntohs(fiph
->fip_flags
)))
584 /* pass it on to fcoe */
586 } else if (op
== FIP_OP_VLAN
&& sub
== FIP_SC_VL_NOTE
) {
587 /* set the vlan as used */
588 fnic_fcoe_process_vlan_resp(fnic
, skb
);
590 } else if (op
== FIP_OP_CTRL
&& sub
== FIP_SC_CLR_VLINK
) {
591 /* received CVL request, restart vlan disc */
592 fnic_event_enq(fnic
, FNIC_EVT_START_VLAN_DISC
);
593 /* pass it on to fcoe */
600 void fnic_handle_fip_frame(struct work_struct
*work
)
602 struct fnic
*fnic
= container_of(work
, struct fnic
, fip_frame_work
);
603 struct fnic_stats
*fnic_stats
= &fnic
->fnic_stats
;
608 while ((skb
= skb_dequeue(&fnic
->fip_frame_queue
))) {
609 spin_lock_irqsave(&fnic
->fnic_lock
, flags
);
610 if (fnic
->stop_rx_link_events
) {
611 spin_unlock_irqrestore(&fnic
->fnic_lock
, flags
);
616 * If we're in a transitional state, just re-queue and return.
617 * The queue will be serviced when we get to a stable state.
619 if (fnic
->state
!= FNIC_IN_FC_MODE
&&
620 fnic
->state
!= FNIC_IN_ETH_MODE
) {
621 skb_queue_head(&fnic
->fip_frame_queue
, skb
);
622 spin_unlock_irqrestore(&fnic
->fnic_lock
, flags
);
625 spin_unlock_irqrestore(&fnic
->fnic_lock
, flags
);
626 eh
= (struct ethhdr
*)skb
->data
;
627 if (eh
->h_proto
== htons(ETH_P_FIP
)) {
628 skb_pull(skb
, sizeof(*eh
));
629 if (fnic_fcoe_handle_fip_frame(fnic
, skb
) <= 0) {
634 * If there's FLOGI rejects - clear all
635 * fcf's & restart from scratch
637 if (is_fnic_fip_flogi_reject(&fnic
->ctlr
, skb
)) {
639 &fnic_stats
->vlan_stats
.flogi_rejects
);
640 shost_printk(KERN_INFO
, fnic
->lport
->host
,
641 "Trigger a Link down - VLAN Disc\n");
642 fcoe_ctlr_link_down(&fnic
->ctlr
);
643 /* start FCoE VLAN discovery */
644 fnic_fcoe_send_vlan_req(fnic
);
648 fcoe_ctlr_recv(&fnic
->ctlr
, skb
);
655 * fnic_import_rq_eth_pkt() - handle received FCoE or FIP frame.
656 * @fnic: fnic instance.
657 * @skb: Ethernet Frame.
659 static inline int fnic_import_rq_eth_pkt(struct fnic
*fnic
, struct sk_buff
*skb
)
663 struct fcoe_hdr
*fcoe_hdr
;
664 struct fcoe_crc_eof
*ft
;
667 * Undo VLAN encapsulation if present.
669 eh
= (struct ethhdr
*)skb
->data
;
670 if (eh
->h_proto
== htons(ETH_P_8021Q
)) {
671 memmove((u8
*)eh
+ VLAN_HLEN
, eh
, ETH_ALEN
* 2);
672 eh
= skb_pull(skb
, VLAN_HLEN
);
673 skb_reset_mac_header(skb
);
675 if (eh
->h_proto
== htons(ETH_P_FIP
)) {
676 if (!(fnic
->config
.flags
& VFCF_FIP_CAPABLE
)) {
677 printk(KERN_ERR
"Dropped FIP frame, as firmware "
678 "uses non-FIP mode, Enable FIP "
682 if ((fnic_fc_trace_set_data(fnic
->lport
->host
->host_no
,
683 FNIC_FC_RECV
|0x80, (char *)skb
->data
, skb
->len
)) != 0) {
684 printk(KERN_ERR
"fnic ctlr frame trace error!!!");
686 skb_queue_tail(&fnic
->fip_frame_queue
, skb
);
687 queue_work(fnic_fip_queue
, &fnic
->fip_frame_work
);
688 return 1; /* let caller know packet was used */
690 if (eh
->h_proto
!= htons(ETH_P_FCOE
))
692 skb_set_network_header(skb
, sizeof(*eh
));
693 skb_pull(skb
, sizeof(*eh
));
695 fcoe_hdr
= (struct fcoe_hdr
*)skb
->data
;
696 if (FC_FCOE_DECAPS_VER(fcoe_hdr
) != FC_FCOE_VER
)
699 fp
= (struct fc_frame
*)skb
;
701 fr_sof(fp
) = fcoe_hdr
->fcoe_sof
;
702 skb_pull(skb
, sizeof(struct fcoe_hdr
));
703 skb_reset_transport_header(skb
);
705 ft
= (struct fcoe_crc_eof
*)(skb
->data
+ skb
->len
- sizeof(*ft
));
706 fr_eof(fp
) = ft
->fcoe_eof
;
707 skb_trim(skb
, skb
->len
- sizeof(*ft
));
710 dev_kfree_skb_irq(skb
);
715 * fnic_update_mac_locked() - set data MAC address and filters.
716 * @fnic: fnic instance.
717 * @new: newly-assigned FCoE MAC address.
719 * Called with the fnic lock held.
721 void fnic_update_mac_locked(struct fnic
*fnic
, u8
*new)
723 u8
*ctl
= fnic
->ctlr
.ctl_src_addr
;
724 u8
*data
= fnic
->data_src_addr
;
726 if (is_zero_ether_addr(new))
728 if (ether_addr_equal(data
, new))
730 FNIC_FCS_DBG(KERN_DEBUG
, fnic
->lport
->host
, fnic
->fnic_num
,
731 "update_mac %pM\n", new);
732 if (!is_zero_ether_addr(data
) && !ether_addr_equal(data
, ctl
))
733 vnic_dev_del_addr(fnic
->vdev
, data
);
734 memcpy(data
, new, ETH_ALEN
);
735 if (!ether_addr_equal(new, ctl
))
736 vnic_dev_add_addr(fnic
->vdev
, new);
740 * fnic_update_mac() - set data MAC address and filters.
741 * @lport: local port.
742 * @new: newly-assigned FCoE MAC address.
744 void fnic_update_mac(struct fc_lport
*lport
, u8
*new)
746 struct fnic
*fnic
= lport_priv(lport
);
748 spin_lock_irq(&fnic
->fnic_lock
);
749 fnic_update_mac_locked(fnic
, new);
750 spin_unlock_irq(&fnic
->fnic_lock
);
754 * fnic_set_port_id() - set the port_ID after successful FLOGI.
755 * @lport: local port.
756 * @port_id: assigned FC_ID.
757 * @fp: received frame containing the FLOGI accept or NULL.
759 * This is called from libfc when a new FC_ID has been assigned.
760 * This causes us to reset the firmware to FC_MODE and setup the new MAC
763 * It is also called with FC_ID 0 when we're logged off.
765 * If the FC_ID is due to point-to-point, fp may be NULL.
767 void fnic_set_port_id(struct fc_lport
*lport
, u32 port_id
, struct fc_frame
*fp
)
769 struct fnic
*fnic
= lport_priv(lport
);
773 FNIC_FCS_DBG(KERN_DEBUG
, lport
->host
, fnic
->fnic_num
,
774 "set port_id 0x%x fp 0x%p\n",
778 * If we're clearing the FC_ID, change to use the ctl_src_addr.
779 * Set ethernet mode to send FLOGI.
782 fnic_update_mac(lport
, fnic
->ctlr
.ctl_src_addr
);
783 fnic_set_eth_mode(fnic
);
788 mac
= fr_cb(fp
)->granted_mac
;
789 if (is_zero_ether_addr(mac
)) {
790 /* non-FIP - FLOGI already accepted - ignore return */
791 fcoe_ctlr_recv_flogi(&fnic
->ctlr
, lport
, fp
);
793 fnic_update_mac(lport
, mac
);
796 /* Change state to reflect transition to FC mode */
797 spin_lock_irq(&fnic
->fnic_lock
);
798 if (fnic
->state
== FNIC_IN_ETH_MODE
|| fnic
->state
== FNIC_IN_FC_MODE
)
799 fnic
->state
= FNIC_IN_ETH_TRANS_FC_MODE
;
801 FNIC_FCS_DBG(KERN_ERR
, fnic
->lport
->host
, fnic
->fnic_num
,
802 "Unexpected fnic state: %s processing FLOGI response",
803 fnic_state_to_str(fnic
->state
));
804 spin_unlock_irq(&fnic
->fnic_lock
);
807 spin_unlock_irq(&fnic
->fnic_lock
);
810 * Send FLOGI registration to firmware to set up FC mode.
811 * The new address will be set up when registration completes.
813 ret
= fnic_flogi_reg_handler(fnic
, port_id
);
816 spin_lock_irq(&fnic
->fnic_lock
);
817 if (fnic
->state
== FNIC_IN_ETH_TRANS_FC_MODE
)
818 fnic
->state
= FNIC_IN_ETH_MODE
;
819 spin_unlock_irq(&fnic
->fnic_lock
);
823 static void fnic_rq_cmpl_frame_recv(struct vnic_rq
*rq
, struct cq_desc
824 *cq_desc
, struct vnic_rq_buf
*buf
,
825 int skipped
__attribute__((unused
)),
828 struct fnic
*fnic
= vnic_dev_priv(rq
->vdev
);
831 struct fnic_stats
*fnic_stats
= &fnic
->fnic_stats
;
832 u8 type
, color
, eop
, sop
, ingress_port
, vlan_stripped
;
833 u8 fcoe
= 0, fcoe_sof
, fcoe_eof
;
834 u8 fcoe_fc_crc_ok
= 1, fcoe_enc_error
= 0;
835 u8 tcp_udp_csum_ok
, udp
, tcp
, ipv4_csum_ok
;
836 u8 ipv6
, ipv4
, ipv4_fragment
, rss_type
, csum_not_calc
;
837 u8 fcs_ok
= 1, packet_error
= 0;
838 u16 q_number
, completed_index
, bytes_written
= 0, vlan
, checksum
;
840 u16 exchange_id
, tmpl
;
843 u32 fcp_bytes_written
= 0;
846 dma_unmap_single(&fnic
->pdev
->dev
, buf
->dma_addr
, buf
->len
,
849 fp
= (struct fc_frame
*)skb
;
852 cq_desc_dec(cq_desc
, &type
, &color
, &q_number
, &completed_index
);
853 if (type
== CQ_DESC_TYPE_RQ_FCP
) {
854 cq_fcp_rq_desc_dec((struct cq_fcp_rq_desc
*)cq_desc
,
855 &type
, &color
, &q_number
, &completed_index
,
856 &eop
, &sop
, &fcoe_fc_crc_ok
, &exchange_id
,
857 &tmpl
, &fcp_bytes_written
, &sof
, &eof
,
858 &ingress_port
, &packet_error
,
859 &fcoe_enc_error
, &fcs_ok
, &vlan_stripped
,
861 skb_trim(skb
, fcp_bytes_written
);
865 } else if (type
== CQ_DESC_TYPE_RQ_ENET
) {
866 cq_enet_rq_desc_dec((struct cq_enet_rq_desc
*)cq_desc
,
867 &type
, &color
, &q_number
, &completed_index
,
868 &ingress_port
, &fcoe
, &eop
, &sop
,
869 &rss_type
, &csum_not_calc
, &rss_hash
,
870 &bytes_written
, &packet_error
,
871 &vlan_stripped
, &vlan
, &checksum
,
872 &fcoe_sof
, &fcoe_fc_crc_ok
,
873 &fcoe_enc_error
, &fcoe_eof
,
874 &tcp_udp_csum_ok
, &udp
, &tcp
,
875 &ipv4_csum_ok
, &ipv6
, &ipv4
,
876 &ipv4_fragment
, &fcs_ok
);
877 skb_trim(skb
, bytes_written
);
879 atomic64_inc(&fnic_stats
->misc_stats
.frame_errors
);
880 FNIC_FCS_DBG(KERN_DEBUG
, fnic
->lport
->host
, fnic
->fnic_num
,
881 "fcs error. dropping packet.\n");
884 if (fnic_import_rq_eth_pkt(fnic
, skb
))
889 shost_printk(KERN_ERR
, fnic
->lport
->host
,
890 "fnic rq_cmpl wrong cq type x%x\n", type
);
894 if (!fcs_ok
|| packet_error
|| !fcoe_fc_crc_ok
|| fcoe_enc_error
) {
895 atomic64_inc(&fnic_stats
->misc_stats
.frame_errors
);
896 FNIC_FCS_DBG(KERN_DEBUG
, fnic
->lport
->host
, fnic
->fnic_num
,
897 "fnic rq_cmpl fcoe x%x fcsok x%x"
898 " pkterr x%x fcoe_fc_crc_ok x%x, fcoe_enc_err"
900 fcoe
, fcs_ok
, packet_error
,
901 fcoe_fc_crc_ok
, fcoe_enc_error
);
905 spin_lock_irqsave(&fnic
->fnic_lock
, flags
);
906 if (fnic
->stop_rx_link_events
) {
907 spin_unlock_irqrestore(&fnic
->fnic_lock
, flags
);
910 fr_dev(fp
) = fnic
->lport
;
911 spin_unlock_irqrestore(&fnic
->fnic_lock
, flags
);
912 if ((fnic_fc_trace_set_data(fnic
->lport
->host
->host_no
, FNIC_FC_RECV
,
913 (char *)skb
->data
, skb
->len
)) != 0) {
914 printk(KERN_ERR
"fnic ctlr frame trace error!!!");
917 skb_queue_tail(&fnic
->frame_queue
, skb
);
918 queue_work(fnic_event_queue
, &fnic
->frame_work
);
922 dev_kfree_skb_irq(skb
);
925 static int fnic_rq_cmpl_handler_cont(struct vnic_dev
*vdev
,
926 struct cq_desc
*cq_desc
, u8 type
,
927 u16 q_number
, u16 completed_index
,
930 struct fnic
*fnic
= vnic_dev_priv(vdev
);
932 vnic_rq_service(&fnic
->rq
[q_number
], cq_desc
, completed_index
,
933 VNIC_RQ_RETURN_DESC
, fnic_rq_cmpl_frame_recv
,
938 int fnic_rq_cmpl_handler(struct fnic
*fnic
, int rq_work_to_do
)
940 unsigned int tot_rq_work_done
= 0, cur_work_done
;
944 for (i
= 0; i
< fnic
->rq_count
; i
++) {
945 cur_work_done
= vnic_cq_service(&fnic
->cq
[i
], rq_work_to_do
,
946 fnic_rq_cmpl_handler_cont
,
949 err
= vnic_rq_fill(&fnic
->rq
[i
], fnic_alloc_rq_frame
);
951 shost_printk(KERN_ERR
, fnic
->lport
->host
,
952 "fnic_alloc_rq_frame can't alloc"
955 tot_rq_work_done
+= cur_work_done
;
958 return tot_rq_work_done
;
962 * This function is called once at init time to allocate and fill RQ
963 * buffers. Subsequently, it is called in the interrupt context after RQ
964 * buffer processing to replenish the buffers in the RQ
966 int fnic_alloc_rq_frame(struct vnic_rq
*rq
)
968 struct fnic
*fnic
= vnic_dev_priv(rq
->vdev
);
974 len
= FC_FRAME_HEADROOM
+ FC_MAX_FRAME
+ FC_FRAME_TAILROOM
;
975 skb
= dev_alloc_skb(len
);
977 FNIC_FCS_DBG(KERN_DEBUG
, fnic
->lport
->host
, fnic
->fnic_num
,
978 "Unable to allocate RQ sk_buff\n");
981 skb_reset_mac_header(skb
);
982 skb_reset_transport_header(skb
);
983 skb_reset_network_header(skb
);
985 pa
= dma_map_single(&fnic
->pdev
->dev
, skb
->data
, len
, DMA_FROM_DEVICE
);
986 if (dma_mapping_error(&fnic
->pdev
->dev
, pa
)) {
988 printk(KERN_ERR
"PCI mapping failed with error %d\n", r
);
992 fnic_queue_rq_desc(rq
, skb
, pa
, len
);
1000 void fnic_free_rq_buf(struct vnic_rq
*rq
, struct vnic_rq_buf
*buf
)
1002 struct fc_frame
*fp
= buf
->os_buf
;
1003 struct fnic
*fnic
= vnic_dev_priv(rq
->vdev
);
1005 dma_unmap_single(&fnic
->pdev
->dev
, buf
->dma_addr
, buf
->len
,
1008 dev_kfree_skb(fp_skb(fp
));
1013 * fnic_eth_send() - Send Ethernet frame.
1014 * @fip: fcoe_ctlr instance.
1015 * @skb: Ethernet Frame, FIP, without VLAN encapsulation.
1017 void fnic_eth_send(struct fcoe_ctlr
*fip
, struct sk_buff
*skb
)
1019 struct fnic
*fnic
= fnic_from_ctlr(fip
);
1020 struct vnic_wq
*wq
= &fnic
->wq
[0];
1022 struct ethhdr
*eth_hdr
;
1023 struct vlan_ethhdr
*vlan_hdr
;
1024 unsigned long flags
;
1026 if (!fnic
->vlan_hw_insert
) {
1027 eth_hdr
= (struct ethhdr
*)skb_mac_header(skb
);
1028 vlan_hdr
= skb_push(skb
, sizeof(*vlan_hdr
) - sizeof(*eth_hdr
));
1029 memcpy(vlan_hdr
, eth_hdr
, 2 * ETH_ALEN
);
1030 vlan_hdr
->h_vlan_proto
= htons(ETH_P_8021Q
);
1031 vlan_hdr
->h_vlan_encapsulated_proto
= eth_hdr
->h_proto
;
1032 vlan_hdr
->h_vlan_TCI
= htons(fnic
->vlan_id
);
1033 if ((fnic_fc_trace_set_data(fnic
->lport
->host
->host_no
,
1034 FNIC_FC_SEND
|0x80, (char *)eth_hdr
, skb
->len
)) != 0) {
1035 printk(KERN_ERR
"fnic ctlr frame trace error!!!");
1038 if ((fnic_fc_trace_set_data(fnic
->lport
->host
->host_no
,
1039 FNIC_FC_SEND
|0x80, (char *)skb
->data
, skb
->len
)) != 0) {
1040 printk(KERN_ERR
"fnic ctlr frame trace error!!!");
1044 pa
= dma_map_single(&fnic
->pdev
->dev
, skb
->data
, skb
->len
,
1046 if (dma_mapping_error(&fnic
->pdev
->dev
, pa
)) {
1047 printk(KERN_ERR
"DMA mapping failed\n");
1051 spin_lock_irqsave(&fnic
->wq_lock
[0], flags
);
1052 if (!vnic_wq_desc_avail(wq
))
1055 fnic_queue_wq_eth_desc(wq
, skb
, pa
, skb
->len
,
1056 0 /* hw inserts cos value */,
1058 spin_unlock_irqrestore(&fnic
->wq_lock
[0], flags
);
1062 spin_unlock_irqrestore(&fnic
->wq_lock
[0], flags
);
1063 dma_unmap_single(&fnic
->pdev
->dev
, pa
, skb
->len
, DMA_TO_DEVICE
);
1071 static int fnic_send_frame(struct fnic
*fnic
, struct fc_frame
*fp
)
1073 struct vnic_wq
*wq
= &fnic
->wq
[0];
1074 struct sk_buff
*skb
;
1076 struct ethhdr
*eth_hdr
;
1077 struct vlan_ethhdr
*vlan_hdr
;
1078 struct fcoe_hdr
*fcoe_hdr
;
1079 struct fc_frame_header
*fh
;
1080 u32 tot_len
, eth_hdr_len
;
1082 unsigned long flags
;
1084 fh
= fc_frame_header_get(fp
);
1087 if (unlikely(fh
->fh_r_ctl
== FC_RCTL_ELS_REQ
) &&
1088 fcoe_ctlr_els_send(&fnic
->ctlr
, fnic
->lport
, skb
))
1091 if (!fnic
->vlan_hw_insert
) {
1092 eth_hdr_len
= sizeof(*vlan_hdr
) + sizeof(*fcoe_hdr
);
1093 vlan_hdr
= skb_push(skb
, eth_hdr_len
);
1094 eth_hdr
= (struct ethhdr
*)vlan_hdr
;
1095 vlan_hdr
->h_vlan_proto
= htons(ETH_P_8021Q
);
1096 vlan_hdr
->h_vlan_encapsulated_proto
= htons(ETH_P_FCOE
);
1097 vlan_hdr
->h_vlan_TCI
= htons(fnic
->vlan_id
);
1098 fcoe_hdr
= (struct fcoe_hdr
*)(vlan_hdr
+ 1);
1100 eth_hdr_len
= sizeof(*eth_hdr
) + sizeof(*fcoe_hdr
);
1101 eth_hdr
= skb_push(skb
, eth_hdr_len
);
1102 eth_hdr
->h_proto
= htons(ETH_P_FCOE
);
1103 fcoe_hdr
= (struct fcoe_hdr
*)(eth_hdr
+ 1);
1106 if (fnic
->ctlr
.map_dest
)
1107 fc_fcoe_set_mac(eth_hdr
->h_dest
, fh
->fh_d_id
);
1109 memcpy(eth_hdr
->h_dest
, fnic
->ctlr
.dest_addr
, ETH_ALEN
);
1110 memcpy(eth_hdr
->h_source
, fnic
->data_src_addr
, ETH_ALEN
);
1113 BUG_ON(tot_len
% 4);
1115 memset(fcoe_hdr
, 0, sizeof(*fcoe_hdr
));
1116 fcoe_hdr
->fcoe_sof
= fr_sof(fp
);
1118 FC_FCOE_ENCAPS_VER(fcoe_hdr
, FC_FCOE_VER
);
1120 pa
= dma_map_single(&fnic
->pdev
->dev
, eth_hdr
, tot_len
, DMA_TO_DEVICE
);
1121 if (dma_mapping_error(&fnic
->pdev
->dev
, pa
)) {
1123 printk(KERN_ERR
"DMA map failed with error %d\n", ret
);
1124 goto free_skb_on_err
;
1127 if ((fnic_fc_trace_set_data(fnic
->lport
->host
->host_no
, FNIC_FC_SEND
,
1128 (char *)eth_hdr
, tot_len
)) != 0) {
1129 printk(KERN_ERR
"fnic ctlr frame trace error!!!");
1132 spin_lock_irqsave(&fnic
->wq_lock
[0], flags
);
1134 if (!vnic_wq_desc_avail(wq
)) {
1135 dma_unmap_single(&fnic
->pdev
->dev
, pa
, tot_len
, DMA_TO_DEVICE
);
1140 fnic_queue_wq_desc(wq
, skb
, pa
, tot_len
, fr_eof(fp
),
1141 0 /* hw inserts cos value */,
1142 fnic
->vlan_id
, 1, 1, 1);
1145 spin_unlock_irqrestore(&fnic
->wq_lock
[0], flags
);
1149 dev_kfree_skb_any(fp_skb(fp
));
1156 * Routine to send a raw frame
1158 int fnic_send(struct fc_lport
*lp
, struct fc_frame
*fp
)
1160 struct fnic
*fnic
= lport_priv(lp
);
1161 unsigned long flags
;
1163 if (fnic
->in_remove
) {
1164 dev_kfree_skb(fp_skb(fp
));
1169 * Queue frame if in a transitional state.
1170 * This occurs while registering the Port_ID / MAC address after FLOGI.
1172 spin_lock_irqsave(&fnic
->fnic_lock
, flags
);
1173 if (fnic
->state
!= FNIC_IN_FC_MODE
&& fnic
->state
!= FNIC_IN_ETH_MODE
) {
1174 skb_queue_tail(&fnic
->tx_queue
, fp_skb(fp
));
1175 spin_unlock_irqrestore(&fnic
->fnic_lock
, flags
);
1178 spin_unlock_irqrestore(&fnic
->fnic_lock
, flags
);
1180 return fnic_send_frame(fnic
, fp
);
1184 * fnic_flush_tx() - send queued frames.
1185 * @work: pointer to work element
1187 * Send frames that were waiting to go out in FC or Ethernet mode.
1188 * Whenever changing modes we purge queued frames, so these frames should
1189 * be queued for the stable mode that we're in, either FC or Ethernet.
1191 * Called without fnic_lock held.
1193 void fnic_flush_tx(struct work_struct
*work
)
1195 struct fnic
*fnic
= container_of(work
, struct fnic
, flush_work
);
1196 struct sk_buff
*skb
;
1197 struct fc_frame
*fp
;
1199 while ((skb
= skb_dequeue(&fnic
->tx_queue
))) {
1200 fp
= (struct fc_frame
*)skb
;
1201 fnic_send_frame(fnic
, fp
);
1206 * fnic_set_eth_mode() - put fnic into ethernet mode.
1207 * @fnic: fnic device
1209 * Called without fnic lock held.
1211 static void fnic_set_eth_mode(struct fnic
*fnic
)
1213 unsigned long flags
;
1214 enum fnic_state old_state
;
1217 spin_lock_irqsave(&fnic
->fnic_lock
, flags
);
1219 old_state
= fnic
->state
;
1220 switch (old_state
) {
1221 case FNIC_IN_FC_MODE
:
1222 case FNIC_IN_ETH_TRANS_FC_MODE
:
1224 fnic
->state
= FNIC_IN_FC_TRANS_ETH_MODE
;
1225 spin_unlock_irqrestore(&fnic
->fnic_lock
, flags
);
1227 ret
= fnic_fw_reset_handler(fnic
);
1229 spin_lock_irqsave(&fnic
->fnic_lock
, flags
);
1230 if (fnic
->state
!= FNIC_IN_FC_TRANS_ETH_MODE
)
1233 fnic
->state
= old_state
;
1236 case FNIC_IN_FC_TRANS_ETH_MODE
:
1237 case FNIC_IN_ETH_MODE
:
1240 spin_unlock_irqrestore(&fnic
->fnic_lock
, flags
);
1243 static void fnic_wq_complete_frame_send(struct vnic_wq
*wq
,
1244 struct cq_desc
*cq_desc
,
1245 struct vnic_wq_buf
*buf
, void *opaque
)
1247 struct sk_buff
*skb
= buf
->os_buf
;
1248 struct fc_frame
*fp
= (struct fc_frame
*)skb
;
1249 struct fnic
*fnic
= vnic_dev_priv(wq
->vdev
);
1251 dma_unmap_single(&fnic
->pdev
->dev
, buf
->dma_addr
, buf
->len
,
1253 dev_kfree_skb_irq(fp_skb(fp
));
1257 static int fnic_wq_cmpl_handler_cont(struct vnic_dev
*vdev
,
1258 struct cq_desc
*cq_desc
, u8 type
,
1259 u16 q_number
, u16 completed_index
,
1262 struct fnic
*fnic
= vnic_dev_priv(vdev
);
1263 unsigned long flags
;
1265 spin_lock_irqsave(&fnic
->wq_lock
[q_number
], flags
);
1266 vnic_wq_service(&fnic
->wq
[q_number
], cq_desc
, completed_index
,
1267 fnic_wq_complete_frame_send
, NULL
);
1268 spin_unlock_irqrestore(&fnic
->wq_lock
[q_number
], flags
);
1273 int fnic_wq_cmpl_handler(struct fnic
*fnic
, int work_to_do
)
1275 unsigned int wq_work_done
= 0;
1278 for (i
= 0; i
< fnic
->raw_wq_count
; i
++) {
1279 wq_work_done
+= vnic_cq_service(&fnic
->cq
[fnic
->rq_count
+i
],
1281 fnic_wq_cmpl_handler_cont
,
1285 return wq_work_done
;
1289 void fnic_free_wq_buf(struct vnic_wq
*wq
, struct vnic_wq_buf
*buf
)
1291 struct fc_frame
*fp
= buf
->os_buf
;
1292 struct fnic
*fnic
= vnic_dev_priv(wq
->vdev
);
1294 dma_unmap_single(&fnic
->pdev
->dev
, buf
->dma_addr
, buf
->len
,
1297 dev_kfree_skb(fp_skb(fp
));
1301 void fnic_fcoe_reset_vlans(struct fnic
*fnic
)
1303 unsigned long flags
;
1304 struct fcoe_vlan
*vlan
;
1305 struct fcoe_vlan
*next
;
1308 * indicate a link down to fcoe so that all fcf's are free'd
1309 * might not be required since we did this before sending vlan
1312 spin_lock_irqsave(&fnic
->vlans_lock
, flags
);
1313 if (!list_empty(&fnic
->vlans
)) {
1314 list_for_each_entry_safe(vlan
, next
, &fnic
->vlans
, list
) {
1315 list_del(&vlan
->list
);
1319 spin_unlock_irqrestore(&fnic
->vlans_lock
, flags
);
1322 void fnic_handle_fip_timer(struct fnic
*fnic
)
1324 unsigned long flags
;
1325 struct fcoe_vlan
*vlan
;
1326 struct fnic_stats
*fnic_stats
= &fnic
->fnic_stats
;
1329 spin_lock_irqsave(&fnic
->fnic_lock
, flags
);
1330 if (fnic
->stop_rx_link_events
) {
1331 spin_unlock_irqrestore(&fnic
->fnic_lock
, flags
);
1334 spin_unlock_irqrestore(&fnic
->fnic_lock
, flags
);
1336 if (fnic
->ctlr
.mode
== FIP_MODE_NON_FIP
)
1339 spin_lock_irqsave(&fnic
->vlans_lock
, flags
);
1340 if (list_empty(&fnic
->vlans
)) {
1341 spin_unlock_irqrestore(&fnic
->vlans_lock
, flags
);
1342 /* no vlans available, try again */
1343 if (unlikely(fnic_log_level
& FNIC_FCS_LOGGING
))
1344 if (printk_ratelimit())
1345 shost_printk(KERN_DEBUG
, fnic
->lport
->host
,
1346 "Start VLAN Discovery\n");
1347 fnic_event_enq(fnic
, FNIC_EVT_START_VLAN_DISC
);
1351 vlan
= list_first_entry(&fnic
->vlans
, struct fcoe_vlan
, list
);
1352 FNIC_FCS_DBG(KERN_DEBUG
, fnic
->lport
->host
, fnic
->fnic_num
,
1353 "fip_timer: vlan %d state %d sol_count %d\n",
1354 vlan
->vid
, vlan
->state
, vlan
->sol_count
);
1355 switch (vlan
->state
) {
1357 FNIC_FCS_DBG(KERN_DEBUG
, fnic
->lport
->host
, fnic
->fnic_num
,
1358 "FIP VLAN is selected for FC transaction\n");
1359 spin_unlock_irqrestore(&fnic
->vlans_lock
, flags
);
1361 case FIP_VLAN_FAILED
:
1362 spin_unlock_irqrestore(&fnic
->vlans_lock
, flags
);
1363 /* if all vlans are in failed state, restart vlan disc */
1364 if (unlikely(fnic_log_level
& FNIC_FCS_LOGGING
))
1365 if (printk_ratelimit())
1366 shost_printk(KERN_DEBUG
, fnic
->lport
->host
,
1367 "Start VLAN Discovery\n");
1368 fnic_event_enq(fnic
, FNIC_EVT_START_VLAN_DISC
);
1371 if (vlan
->sol_count
>= FCOE_CTLR_MAX_SOL
) {
1373 * no response on this vlan, remove from the list.
1376 FNIC_FCS_DBG(KERN_INFO
, fnic
->lport
->host
, fnic
->fnic_num
,
1377 "Dequeue this VLAN ID %d from list\n",
1379 list_del(&vlan
->list
);
1382 if (list_empty(&fnic
->vlans
)) {
1383 /* we exhausted all vlans, restart vlan disc */
1384 spin_unlock_irqrestore(&fnic
->vlans_lock
,
1386 FNIC_FCS_DBG(KERN_INFO
, fnic
->lport
->host
, fnic
->fnic_num
,
1387 "fip_timer: vlan list empty, "
1388 "trigger vlan disc\n");
1389 fnic_event_enq(fnic
, FNIC_EVT_START_VLAN_DISC
);
1392 /* check the next vlan */
1393 vlan
= list_first_entry(&fnic
->vlans
, struct fcoe_vlan
,
1395 fnic
->set_vlan(fnic
, vlan
->vid
);
1396 vlan
->state
= FIP_VLAN_SENT
; /* sent now */
1398 spin_unlock_irqrestore(&fnic
->vlans_lock
, flags
);
1399 atomic64_inc(&fnic_stats
->vlan_stats
.sol_expiry_count
);
1401 sol_time
= jiffies
+ msecs_to_jiffies
1402 (FCOE_CTLR_START_DELAY
);
1403 mod_timer(&fnic
->fip_timer
, round_jiffies(sol_time
));