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
;
56 spin_lock_irqsave(&fnic
->fnic_lock
, flags
);
58 if (fnic
->stop_rx_link_events
) {
59 spin_unlock_irqrestore(&fnic
->fnic_lock
, flags
);
63 old_link_down_cnt
= fnic
->link_down_cnt
;
64 old_link_status
= fnic
->link_status
;
65 fnic
->link_status
= vnic_dev_link_status(fnic
->vdev
);
66 fnic
->link_down_cnt
= vnic_dev_link_down_cnt(fnic
->vdev
);
68 atomic64_set(&fnic
->fnic_stats
.misc_stats
.current_port_speed
,
69 vnic_dev_port_speed(fnic
->vdev
));
70 shost_printk(KERN_INFO
, fnic
->lport
->host
, "Current vnic speed set to : %llu\n",
72 &fnic
->fnic_stats
.misc_stats
.current_port_speed
));
74 switch (vnic_dev_port_speed(fnic
->vdev
)) {
75 case DCEM_PORTSPEED_10G
:
76 fc_host_speed(fnic
->lport
->host
) = FC_PORTSPEED_10GBIT
;
77 fnic
->lport
->link_supported_speeds
= FC_PORTSPEED_10GBIT
;
79 case DCEM_PORTSPEED_20G
:
80 fc_host_speed(fnic
->lport
->host
) = FC_PORTSPEED_20GBIT
;
81 fnic
->lport
->link_supported_speeds
= FC_PORTSPEED_20GBIT
;
83 case DCEM_PORTSPEED_25G
:
84 fc_host_speed(fnic
->lport
->host
) = FC_PORTSPEED_25GBIT
;
85 fnic
->lport
->link_supported_speeds
= FC_PORTSPEED_25GBIT
;
87 case DCEM_PORTSPEED_40G
:
88 case DCEM_PORTSPEED_4x10G
:
89 fc_host_speed(fnic
->lport
->host
) = FC_PORTSPEED_40GBIT
;
90 fnic
->lport
->link_supported_speeds
= FC_PORTSPEED_40GBIT
;
92 case DCEM_PORTSPEED_100G
:
93 fc_host_speed(fnic
->lport
->host
) = FC_PORTSPEED_100GBIT
;
94 fnic
->lport
->link_supported_speeds
= FC_PORTSPEED_100GBIT
;
97 fc_host_speed(fnic
->lport
->host
) = FC_PORTSPEED_UNKNOWN
;
98 fnic
->lport
->link_supported_speeds
= FC_PORTSPEED_UNKNOWN
;
102 if (old_link_status
== fnic
->link_status
) {
103 if (!fnic
->link_status
) {
105 spin_unlock_irqrestore(&fnic
->fnic_lock
, flags
);
106 fnic_fc_trace_set_data(fnic
->lport
->host
->host_no
,
107 FNIC_FC_LE
, "Link Status: DOWN->DOWN",
108 strlen("Link Status: DOWN->DOWN"));
110 if (old_link_down_cnt
!= fnic
->link_down_cnt
) {
111 /* UP -> DOWN -> UP */
112 fnic
->lport
->host_stats
.link_failure_count
++;
113 spin_unlock_irqrestore(&fnic
->fnic_lock
, flags
);
114 fnic_fc_trace_set_data(
115 fnic
->lport
->host
->host_no
,
117 "Link Status:UP_DOWN_UP",
118 strlen("Link_Status:UP_DOWN_UP")
120 FNIC_FCS_DBG(KERN_DEBUG
, fnic
->lport
->host
,
122 fcoe_ctlr_link_down(&fnic
->ctlr
);
123 if (fnic
->config
.flags
& VFCF_FIP_CAPABLE
) {
124 /* start FCoE VLAN discovery */
125 fnic_fc_trace_set_data(
126 fnic
->lport
->host
->host_no
,
128 "Link Status: UP_DOWN_UP_VLAN",
130 "Link Status: UP_DOWN_UP_VLAN")
132 fnic_fcoe_send_vlan_req(fnic
);
135 FNIC_FCS_DBG(KERN_DEBUG
, fnic
->lport
->host
,
137 fcoe_ctlr_link_up(&fnic
->ctlr
);
140 spin_unlock_irqrestore(&fnic
->fnic_lock
, flags
);
141 fnic_fc_trace_set_data(
142 fnic
->lport
->host
->host_no
, FNIC_FC_LE
,
143 "Link Status: UP_UP",
144 strlen("Link Status: UP_UP"));
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(
153 fnic
->lport
->host
->host_no
,
154 FNIC_FC_LE
, "Link Status: DOWN_UP_VLAN",
155 strlen("Link Status: DOWN_UP_VLAN"));
156 fnic_fcoe_send_vlan_req(fnic
);
159 FNIC_FCS_DBG(KERN_DEBUG
, fnic
->lport
->host
, "link up\n");
160 fnic_fc_trace_set_data(fnic
->lport
->host
->host_no
, FNIC_FC_LE
,
161 "Link Status: DOWN_UP", strlen("Link Status: DOWN_UP"));
162 fcoe_ctlr_link_up(&fnic
->ctlr
);
165 fnic
->lport
->host_stats
.link_failure_count
++;
166 spin_unlock_irqrestore(&fnic
->fnic_lock
, flags
);
167 FNIC_FCS_DBG(KERN_DEBUG
, fnic
->lport
->host
, "link down\n");
168 fnic_fc_trace_set_data(
169 fnic
->lport
->host
->host_no
, FNIC_FC_LE
,
170 "Link Status: UP_DOWN",
171 strlen("Link Status: UP_DOWN"));
172 if (fnic
->config
.flags
& VFCF_FIP_CAPABLE
) {
173 FNIC_FCS_DBG(KERN_DEBUG
, fnic
->lport
->host
,
174 "deleting fip-timer during link-down\n");
175 del_timer_sync(&fnic
->fip_timer
);
177 fcoe_ctlr_link_down(&fnic
->ctlr
);
183 * This function passes incoming fabric frames to libFC
185 void fnic_handle_frame(struct work_struct
*work
)
187 struct fnic
*fnic
= container_of(work
, struct fnic
, frame_work
);
188 struct fc_lport
*lp
= fnic
->lport
;
193 while ((skb
= skb_dequeue(&fnic
->frame_queue
))) {
195 spin_lock_irqsave(&fnic
->fnic_lock
, flags
);
196 if (fnic
->stop_rx_link_events
) {
197 spin_unlock_irqrestore(&fnic
->fnic_lock
, flags
);
201 fp
= (struct fc_frame
*)skb
;
204 * If we're in a transitional state, just re-queue and return.
205 * The queue will be serviced when we get to a stable state.
207 if (fnic
->state
!= FNIC_IN_FC_MODE
&&
208 fnic
->state
!= FNIC_IN_ETH_MODE
) {
209 skb_queue_head(&fnic
->frame_queue
, skb
);
210 spin_unlock_irqrestore(&fnic
->fnic_lock
, flags
);
213 spin_unlock_irqrestore(&fnic
->fnic_lock
, flags
);
215 fc_exch_recv(lp
, fp
);
219 void fnic_fcoe_evlist_free(struct fnic
*fnic
)
221 struct fnic_event
*fevt
= NULL
;
222 struct fnic_event
*next
= NULL
;
225 spin_lock_irqsave(&fnic
->fnic_lock
, flags
);
226 if (list_empty(&fnic
->evlist
)) {
227 spin_unlock_irqrestore(&fnic
->fnic_lock
, flags
);
231 list_for_each_entry_safe(fevt
, next
, &fnic
->evlist
, list
) {
232 list_del(&fevt
->list
);
235 spin_unlock_irqrestore(&fnic
->fnic_lock
, flags
);
238 void fnic_handle_event(struct work_struct
*work
)
240 struct fnic
*fnic
= container_of(work
, struct fnic
, event_work
);
241 struct fnic_event
*fevt
= NULL
;
242 struct fnic_event
*next
= NULL
;
245 spin_lock_irqsave(&fnic
->fnic_lock
, flags
);
246 if (list_empty(&fnic
->evlist
)) {
247 spin_unlock_irqrestore(&fnic
->fnic_lock
, flags
);
251 list_for_each_entry_safe(fevt
, next
, &fnic
->evlist
, list
) {
252 if (fnic
->stop_rx_link_events
) {
253 list_del(&fevt
->list
);
255 spin_unlock_irqrestore(&fnic
->fnic_lock
, flags
);
259 * If we're in a transitional state, just re-queue and return.
260 * The queue will be serviced when we get to a stable state.
262 if (fnic
->state
!= FNIC_IN_FC_MODE
&&
263 fnic
->state
!= FNIC_IN_ETH_MODE
) {
264 spin_unlock_irqrestore(&fnic
->fnic_lock
, flags
);
268 list_del(&fevt
->list
);
269 switch (fevt
->event
) {
270 case FNIC_EVT_START_VLAN_DISC
:
271 spin_unlock_irqrestore(&fnic
->fnic_lock
, flags
);
272 fnic_fcoe_send_vlan_req(fnic
);
273 spin_lock_irqsave(&fnic
->fnic_lock
, flags
);
275 case FNIC_EVT_START_FCF_DISC
:
276 FNIC_FCS_DBG(KERN_DEBUG
, fnic
->lport
->host
,
277 "Start FCF Discovery\n");
278 fnic_fcoe_start_fcf_disc(fnic
);
281 FNIC_FCS_DBG(KERN_DEBUG
, fnic
->lport
->host
,
282 "Unknown event 0x%x\n", fevt
->event
);
287 spin_unlock_irqrestore(&fnic
->fnic_lock
, flags
);
291 * Check if the Received FIP FLOGI frame is rejected
292 * @fip: The FCoE controller that received the frame
293 * @skb: The received FIP frame
295 * Returns non-zero if the frame is rejected with unsupported cmd with
296 * insufficient resource els explanation.
298 static inline int is_fnic_fip_flogi_reject(struct fcoe_ctlr
*fip
,
301 struct fc_lport
*lport
= fip
->lp
;
302 struct fip_header
*fiph
;
303 struct fc_frame_header
*fh
= NULL
;
304 struct fip_desc
*desc
;
305 struct fip_encaps
*els
;
306 enum fip_desc_type els_dtype
= 0;
315 if (skb_linearize(skb
))
318 if (skb
->len
< sizeof(*fiph
))
321 fiph
= (struct fip_header
*)skb
->data
;
322 op
= ntohs(fiph
->fip_op
);
323 sub
= fiph
->fip_subcode
;
328 if (sub
!= FIP_SC_REP
)
331 rlen
= ntohs(fiph
->fip_dl_len
) * 4;
332 if (rlen
+ sizeof(*fiph
) > skb
->len
)
335 desc
= (struct fip_desc
*)(fiph
+ 1);
336 dlen
= desc
->fip_dlen
* FIP_BPW
;
338 if (desc
->fip_dtype
== FIP_DT_FLOGI
) {
340 if (dlen
< sizeof(*els
) + sizeof(*fh
) + 1)
343 els_len
= dlen
- sizeof(*els
);
344 els
= (struct fip_encaps
*)desc
;
345 fh
= (struct fc_frame_header
*)(els
+ 1);
346 els_dtype
= desc
->fip_dtype
;
352 * ELS command code, reason and explanation should be = Reject,
353 * unsupported command and insufficient resource
355 els_op
= *(u8
*)(fh
+ 1);
356 if (els_op
== ELS_LS_RJT
) {
357 shost_printk(KERN_INFO
, lport
->host
,
358 "Flogi Request Rejected by Switch\n");
361 shost_printk(KERN_INFO
, lport
->host
,
362 "Flogi Request Accepted by Switch\n");
367 static void fnic_fcoe_send_vlan_req(struct fnic
*fnic
)
369 struct fcoe_ctlr
*fip
= &fnic
->ctlr
;
370 struct fnic_stats
*fnic_stats
= &fnic
->fnic_stats
;
374 struct fip_vlan
*vlan
;
377 fnic_fcoe_reset_vlans(fnic
);
378 fnic
->set_vlan(fnic
, 0);
380 if (printk_ratelimit())
381 FNIC_FCS_DBG(KERN_INFO
, fnic
->lport
->host
,
382 "Sending VLAN request...\n");
384 skb
= dev_alloc_skb(sizeof(struct fip_vlan
));
388 fr_len
= sizeof(*vlan
);
389 eth_fr
= (char *)skb
->data
;
390 vlan
= (struct fip_vlan
*)eth_fr
;
392 memset(vlan
, 0, sizeof(*vlan
));
393 memcpy(vlan
->eth
.h_source
, fip
->ctl_src_addr
, ETH_ALEN
);
394 memcpy(vlan
->eth
.h_dest
, fcoe_all_fcfs
, ETH_ALEN
);
395 vlan
->eth
.h_proto
= htons(ETH_P_FIP
);
397 vlan
->fip
.fip_ver
= FIP_VER_ENCAPS(FIP_VER
);
398 vlan
->fip
.fip_op
= htons(FIP_OP_VLAN
);
399 vlan
->fip
.fip_subcode
= FIP_SC_VL_REQ
;
400 vlan
->fip
.fip_dl_len
= htons(sizeof(vlan
->desc
) / FIP_BPW
);
402 vlan
->desc
.mac
.fd_desc
.fip_dtype
= FIP_DT_MAC
;
403 vlan
->desc
.mac
.fd_desc
.fip_dlen
= sizeof(vlan
->desc
.mac
) / FIP_BPW
;
404 memcpy(&vlan
->desc
.mac
.fd_mac
, fip
->ctl_src_addr
, ETH_ALEN
);
406 vlan
->desc
.wwnn
.fd_desc
.fip_dtype
= FIP_DT_NAME
;
407 vlan
->desc
.wwnn
.fd_desc
.fip_dlen
= sizeof(vlan
->desc
.wwnn
) / FIP_BPW
;
408 put_unaligned_be64(fip
->lp
->wwnn
, &vlan
->desc
.wwnn
.fd_wwn
);
409 atomic64_inc(&fnic_stats
->vlan_stats
.vlan_disc_reqs
);
411 skb_put(skb
, sizeof(*vlan
));
412 skb
->protocol
= htons(ETH_P_FIP
);
413 skb_reset_mac_header(skb
);
414 skb_reset_network_header(skb
);
417 /* set a timer so that we can retry if there no response */
418 vlan_tov
= jiffies
+ msecs_to_jiffies(FCOE_CTLR_FIPVLAN_TOV
);
419 mod_timer(&fnic
->fip_timer
, round_jiffies(vlan_tov
));
422 static void fnic_fcoe_process_vlan_resp(struct fnic
*fnic
, struct sk_buff
*skb
)
424 struct fcoe_ctlr
*fip
= &fnic
->ctlr
;
425 struct fip_header
*fiph
;
426 struct fip_desc
*desc
;
427 struct fnic_stats
*fnic_stats
= &fnic
->fnic_stats
;
431 struct fcoe_vlan
*vlan
;
435 FNIC_FCS_DBG(KERN_INFO
, fnic
->lport
->host
,
436 "Received VLAN response...\n");
438 fiph
= (struct fip_header
*) skb
->data
;
440 FNIC_FCS_DBG(KERN_INFO
, fnic
->lport
->host
,
441 "Received VLAN response... OP 0x%x SUB_OP 0x%x\n",
442 ntohs(fiph
->fip_op
), fiph
->fip_subcode
);
444 rlen
= ntohs(fiph
->fip_dl_len
) * 4;
445 fnic_fcoe_reset_vlans(fnic
);
446 spin_lock_irqsave(&fnic
->vlans_lock
, flags
);
447 desc
= (struct fip_desc
*)(fiph
+ 1);
449 dlen
= desc
->fip_dlen
* FIP_BPW
;
450 switch (desc
->fip_dtype
) {
452 vid
= ntohs(((struct fip_vlan_desc
*)desc
)->fd_vlan
);
453 shost_printk(KERN_INFO
, fnic
->lport
->host
,
454 "process_vlan_resp: FIP VLAN %d\n", vid
);
455 vlan
= kzalloc(sizeof(*vlan
), GFP_ATOMIC
);
457 /* retry from timer */
458 spin_unlock_irqrestore(&fnic
->vlans_lock
,
462 vlan
->vid
= vid
& 0x0fff;
463 vlan
->state
= FIP_VLAN_AVAIL
;
464 list_add_tail(&vlan
->list
, &fnic
->vlans
);
467 desc
= (struct fip_desc
*)((char *)desc
+ dlen
);
471 /* any VLAN descriptors present ? */
472 if (list_empty(&fnic
->vlans
)) {
473 /* retry from timer */
474 atomic64_inc(&fnic_stats
->vlan_stats
.resp_withno_vlanID
);
475 FNIC_FCS_DBG(KERN_INFO
, fnic
->lport
->host
,
476 "No VLAN descriptors in FIP VLAN response\n");
477 spin_unlock_irqrestore(&fnic
->vlans_lock
, flags
);
481 vlan
= list_first_entry(&fnic
->vlans
, struct fcoe_vlan
, list
);
482 fnic
->set_vlan(fnic
, vlan
->vid
);
483 vlan
->state
= FIP_VLAN_SENT
; /* sent now */
485 spin_unlock_irqrestore(&fnic
->vlans_lock
, flags
);
487 /* start the solicitation */
488 fcoe_ctlr_link_up(fip
);
490 sol_time
= jiffies
+ msecs_to_jiffies(FCOE_CTLR_START_DELAY
);
491 mod_timer(&fnic
->fip_timer
, round_jiffies(sol_time
));
496 static void fnic_fcoe_start_fcf_disc(struct fnic
*fnic
)
499 struct fcoe_vlan
*vlan
;
502 spin_lock_irqsave(&fnic
->vlans_lock
, flags
);
503 vlan
= list_first_entry(&fnic
->vlans
, struct fcoe_vlan
, list
);
504 fnic
->set_vlan(fnic
, vlan
->vid
);
505 vlan
->state
= FIP_VLAN_SENT
; /* sent now */
507 spin_unlock_irqrestore(&fnic
->vlans_lock
, flags
);
509 /* start the solicitation */
510 fcoe_ctlr_link_up(&fnic
->ctlr
);
512 sol_time
= jiffies
+ msecs_to_jiffies(FCOE_CTLR_START_DELAY
);
513 mod_timer(&fnic
->fip_timer
, round_jiffies(sol_time
));
516 static int fnic_fcoe_vlan_check(struct fnic
*fnic
, u16 flag
)
519 struct fcoe_vlan
*fvlan
;
521 spin_lock_irqsave(&fnic
->vlans_lock
, flags
);
522 if (list_empty(&fnic
->vlans
)) {
523 spin_unlock_irqrestore(&fnic
->vlans_lock
, flags
);
527 fvlan
= list_first_entry(&fnic
->vlans
, struct fcoe_vlan
, list
);
528 if (fvlan
->state
== FIP_VLAN_USED
) {
529 spin_unlock_irqrestore(&fnic
->vlans_lock
, flags
);
533 if (fvlan
->state
== FIP_VLAN_SENT
) {
534 fvlan
->state
= FIP_VLAN_USED
;
535 spin_unlock_irqrestore(&fnic
->vlans_lock
, flags
);
538 spin_unlock_irqrestore(&fnic
->vlans_lock
, flags
);
542 static void fnic_event_enq(struct fnic
*fnic
, enum fnic_evt ev
)
544 struct fnic_event
*fevt
;
547 fevt
= kmalloc(sizeof(*fevt
), GFP_ATOMIC
);
554 spin_lock_irqsave(&fnic
->fnic_lock
, flags
);
555 list_add_tail(&fevt
->list
, &fnic
->evlist
);
556 spin_unlock_irqrestore(&fnic
->fnic_lock
, flags
);
558 schedule_work(&fnic
->event_work
);
561 static int fnic_fcoe_handle_fip_frame(struct fnic
*fnic
, struct sk_buff
*skb
)
563 struct fip_header
*fiph
;
568 if (!skb
|| !(skb
->data
))
571 if (skb_linearize(skb
))
574 fiph
= (struct fip_header
*)skb
->data
;
575 op
= ntohs(fiph
->fip_op
);
576 sub
= fiph
->fip_subcode
;
578 if (FIP_VER_DECAPS(fiph
->fip_ver
) != FIP_VER
)
581 if (ntohs(fiph
->fip_dl_len
) * FIP_BPW
+ sizeof(*fiph
) > skb
->len
)
584 if (op
== FIP_OP_DISC
&& sub
== FIP_SC_ADV
) {
585 if (fnic_fcoe_vlan_check(fnic
, ntohs(fiph
->fip_flags
)))
587 /* pass it on to fcoe */
589 } else if (op
== FIP_OP_VLAN
&& sub
== FIP_SC_VL_NOTE
) {
590 /* set the vlan as used */
591 fnic_fcoe_process_vlan_resp(fnic
, skb
);
593 } else if (op
== FIP_OP_CTRL
&& sub
== FIP_SC_CLR_VLINK
) {
594 /* received CVL request, restart vlan disc */
595 fnic_event_enq(fnic
, FNIC_EVT_START_VLAN_DISC
);
596 /* pass it on to fcoe */
603 void fnic_handle_fip_frame(struct work_struct
*work
)
605 struct fnic
*fnic
= container_of(work
, struct fnic
, fip_frame_work
);
606 struct fnic_stats
*fnic_stats
= &fnic
->fnic_stats
;
611 while ((skb
= skb_dequeue(&fnic
->fip_frame_queue
))) {
612 spin_lock_irqsave(&fnic
->fnic_lock
, flags
);
613 if (fnic
->stop_rx_link_events
) {
614 spin_unlock_irqrestore(&fnic
->fnic_lock
, flags
);
619 * If we're in a transitional state, just re-queue and return.
620 * The queue will be serviced when we get to a stable state.
622 if (fnic
->state
!= FNIC_IN_FC_MODE
&&
623 fnic
->state
!= FNIC_IN_ETH_MODE
) {
624 skb_queue_head(&fnic
->fip_frame_queue
, skb
);
625 spin_unlock_irqrestore(&fnic
->fnic_lock
, flags
);
628 spin_unlock_irqrestore(&fnic
->fnic_lock
, flags
);
629 eh
= (struct ethhdr
*)skb
->data
;
630 if (eh
->h_proto
== htons(ETH_P_FIP
)) {
631 skb_pull(skb
, sizeof(*eh
));
632 if (fnic_fcoe_handle_fip_frame(fnic
, skb
) <= 0) {
637 * If there's FLOGI rejects - clear all
638 * fcf's & restart from scratch
640 if (is_fnic_fip_flogi_reject(&fnic
->ctlr
, skb
)) {
642 &fnic_stats
->vlan_stats
.flogi_rejects
);
643 shost_printk(KERN_INFO
, fnic
->lport
->host
,
644 "Trigger a Link down - VLAN Disc\n");
645 fcoe_ctlr_link_down(&fnic
->ctlr
);
646 /* start FCoE VLAN discovery */
647 fnic_fcoe_send_vlan_req(fnic
);
651 fcoe_ctlr_recv(&fnic
->ctlr
, skb
);
658 * fnic_import_rq_eth_pkt() - handle received FCoE or FIP frame.
659 * @fnic: fnic instance.
660 * @skb: Ethernet Frame.
662 static inline int fnic_import_rq_eth_pkt(struct fnic
*fnic
, struct sk_buff
*skb
)
666 struct fcoe_hdr
*fcoe_hdr
;
667 struct fcoe_crc_eof
*ft
;
670 * Undo VLAN encapsulation if present.
672 eh
= (struct ethhdr
*)skb
->data
;
673 if (eh
->h_proto
== htons(ETH_P_8021Q
)) {
674 memmove((u8
*)eh
+ VLAN_HLEN
, eh
, ETH_ALEN
* 2);
675 eh
= skb_pull(skb
, VLAN_HLEN
);
676 skb_reset_mac_header(skb
);
678 if (eh
->h_proto
== htons(ETH_P_FIP
)) {
679 if (!(fnic
->config
.flags
& VFCF_FIP_CAPABLE
)) {
680 printk(KERN_ERR
"Dropped FIP frame, as firmware "
681 "uses non-FIP mode, Enable FIP "
685 if ((fnic_fc_trace_set_data(fnic
->lport
->host
->host_no
,
686 FNIC_FC_RECV
|0x80, (char *)skb
->data
, skb
->len
)) != 0) {
687 printk(KERN_ERR
"fnic ctlr frame trace error!!!");
689 skb_queue_tail(&fnic
->fip_frame_queue
, skb
);
690 queue_work(fnic_fip_queue
, &fnic
->fip_frame_work
);
691 return 1; /* let caller know packet was used */
693 if (eh
->h_proto
!= htons(ETH_P_FCOE
))
695 skb_set_network_header(skb
, sizeof(*eh
));
696 skb_pull(skb
, sizeof(*eh
));
698 fcoe_hdr
= (struct fcoe_hdr
*)skb
->data
;
699 if (FC_FCOE_DECAPS_VER(fcoe_hdr
) != FC_FCOE_VER
)
702 fp
= (struct fc_frame
*)skb
;
704 fr_sof(fp
) = fcoe_hdr
->fcoe_sof
;
705 skb_pull(skb
, sizeof(struct fcoe_hdr
));
706 skb_reset_transport_header(skb
);
708 ft
= (struct fcoe_crc_eof
*)(skb
->data
+ skb
->len
- sizeof(*ft
));
709 fr_eof(fp
) = ft
->fcoe_eof
;
710 skb_trim(skb
, skb
->len
- sizeof(*ft
));
713 dev_kfree_skb_irq(skb
);
718 * fnic_update_mac_locked() - set data MAC address and filters.
719 * @fnic: fnic instance.
720 * @new: newly-assigned FCoE MAC address.
722 * Called with the fnic lock held.
724 void fnic_update_mac_locked(struct fnic
*fnic
, u8
*new)
726 u8
*ctl
= fnic
->ctlr
.ctl_src_addr
;
727 u8
*data
= fnic
->data_src_addr
;
729 if (is_zero_ether_addr(new))
731 if (ether_addr_equal(data
, new))
733 FNIC_FCS_DBG(KERN_DEBUG
, fnic
->lport
->host
, "update_mac %pM\n", new);
734 if (!is_zero_ether_addr(data
) && !ether_addr_equal(data
, ctl
))
735 vnic_dev_del_addr(fnic
->vdev
, data
);
736 memcpy(data
, new, ETH_ALEN
);
737 if (!ether_addr_equal(new, ctl
))
738 vnic_dev_add_addr(fnic
->vdev
, new);
742 * fnic_update_mac() - set data MAC address and filters.
743 * @lport: local port.
744 * @new: newly-assigned FCoE MAC address.
746 void fnic_update_mac(struct fc_lport
*lport
, u8
*new)
748 struct fnic
*fnic
= lport_priv(lport
);
750 spin_lock_irq(&fnic
->fnic_lock
);
751 fnic_update_mac_locked(fnic
, new);
752 spin_unlock_irq(&fnic
->fnic_lock
);
756 * fnic_set_port_id() - set the port_ID after successful FLOGI.
757 * @lport: local port.
758 * @port_id: assigned FC_ID.
759 * @fp: received frame containing the FLOGI accept or NULL.
761 * This is called from libfc when a new FC_ID has been assigned.
762 * This causes us to reset the firmware to FC_MODE and setup the new MAC
765 * It is also called with FC_ID 0 when we're logged off.
767 * If the FC_ID is due to point-to-point, fp may be NULL.
769 void fnic_set_port_id(struct fc_lport
*lport
, u32 port_id
, struct fc_frame
*fp
)
771 struct fnic
*fnic
= lport_priv(lport
);
775 FNIC_FCS_DBG(KERN_DEBUG
, lport
->host
, "set port_id %x fp %p\n",
779 * If we're clearing the FC_ID, change to use the ctl_src_addr.
780 * Set ethernet mode to send FLOGI.
783 fnic_update_mac(lport
, fnic
->ctlr
.ctl_src_addr
);
784 fnic_set_eth_mode(fnic
);
789 mac
= fr_cb(fp
)->granted_mac
;
790 if (is_zero_ether_addr(mac
)) {
791 /* non-FIP - FLOGI already accepted - ignore return */
792 fcoe_ctlr_recv_flogi(&fnic
->ctlr
, lport
, fp
);
794 fnic_update_mac(lport
, mac
);
797 /* Change state to reflect transition to FC mode */
798 spin_lock_irq(&fnic
->fnic_lock
);
799 if (fnic
->state
== FNIC_IN_ETH_MODE
|| fnic
->state
== FNIC_IN_FC_MODE
)
800 fnic
->state
= FNIC_IN_ETH_TRANS_FC_MODE
;
802 FNIC_FCS_DBG(KERN_DEBUG
, fnic
->lport
->host
,
803 "Unexpected fnic state %s while"
804 " processing flogi resp\n",
805 fnic_state_to_str(fnic
->state
));
806 spin_unlock_irq(&fnic
->fnic_lock
);
809 spin_unlock_irq(&fnic
->fnic_lock
);
812 * Send FLOGI registration to firmware to set up FC mode.
813 * The new address will be set up when registration completes.
815 ret
= fnic_flogi_reg_handler(fnic
, port_id
);
818 spin_lock_irq(&fnic
->fnic_lock
);
819 if (fnic
->state
== FNIC_IN_ETH_TRANS_FC_MODE
)
820 fnic
->state
= FNIC_IN_ETH_MODE
;
821 spin_unlock_irq(&fnic
->fnic_lock
);
825 static void fnic_rq_cmpl_frame_recv(struct vnic_rq
*rq
, struct cq_desc
826 *cq_desc
, struct vnic_rq_buf
*buf
,
827 int skipped
__attribute__((unused
)),
830 struct fnic
*fnic
= vnic_dev_priv(rq
->vdev
);
833 struct fnic_stats
*fnic_stats
= &fnic
->fnic_stats
;
834 unsigned int eth_hdrs_stripped
;
835 u8 type
, color
, eop
, sop
, ingress_port
, vlan_stripped
;
836 u8 fcoe
= 0, fcoe_sof
, fcoe_eof
;
837 u8 fcoe_fc_crc_ok
= 1, fcoe_enc_error
= 0;
838 u8 tcp_udp_csum_ok
, udp
, tcp
, ipv4_csum_ok
;
839 u8 ipv6
, ipv4
, ipv4_fragment
, rss_type
, csum_not_calc
;
840 u8 fcs_ok
= 1, packet_error
= 0;
841 u16 q_number
, completed_index
, bytes_written
= 0, vlan
, checksum
;
843 u16 exchange_id
, tmpl
;
846 u32 fcp_bytes_written
= 0;
849 dma_unmap_single(&fnic
->pdev
->dev
, buf
->dma_addr
, buf
->len
,
852 fp
= (struct fc_frame
*)skb
;
855 cq_desc_dec(cq_desc
, &type
, &color
, &q_number
, &completed_index
);
856 if (type
== CQ_DESC_TYPE_RQ_FCP
) {
857 cq_fcp_rq_desc_dec((struct cq_fcp_rq_desc
*)cq_desc
,
858 &type
, &color
, &q_number
, &completed_index
,
859 &eop
, &sop
, &fcoe_fc_crc_ok
, &exchange_id
,
860 &tmpl
, &fcp_bytes_written
, &sof
, &eof
,
861 &ingress_port
, &packet_error
,
862 &fcoe_enc_error
, &fcs_ok
, &vlan_stripped
,
864 eth_hdrs_stripped
= 1;
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 eth_hdrs_stripped
= 0;
882 skb_trim(skb
, bytes_written
);
884 atomic64_inc(&fnic_stats
->misc_stats
.frame_errors
);
885 FNIC_FCS_DBG(KERN_DEBUG
, fnic
->lport
->host
,
886 "fcs error. dropping packet.\n");
889 if (fnic_import_rq_eth_pkt(fnic
, skb
))
894 shost_printk(KERN_ERR
, fnic
->lport
->host
,
895 "fnic rq_cmpl wrong cq type x%x\n", type
);
899 if (!fcs_ok
|| packet_error
|| !fcoe_fc_crc_ok
|| fcoe_enc_error
) {
900 atomic64_inc(&fnic_stats
->misc_stats
.frame_errors
);
901 FNIC_FCS_DBG(KERN_DEBUG
, fnic
->lport
->host
,
902 "fnic rq_cmpl fcoe x%x fcsok x%x"
903 " pkterr x%x fcoe_fc_crc_ok x%x, fcoe_enc_err"
905 fcoe
, fcs_ok
, packet_error
,
906 fcoe_fc_crc_ok
, fcoe_enc_error
);
910 spin_lock_irqsave(&fnic
->fnic_lock
, flags
);
911 if (fnic
->stop_rx_link_events
) {
912 spin_unlock_irqrestore(&fnic
->fnic_lock
, flags
);
915 fr_dev(fp
) = fnic
->lport
;
916 spin_unlock_irqrestore(&fnic
->fnic_lock
, flags
);
917 if ((fnic_fc_trace_set_data(fnic
->lport
->host
->host_no
, FNIC_FC_RECV
,
918 (char *)skb
->data
, skb
->len
)) != 0) {
919 printk(KERN_ERR
"fnic ctlr frame trace error!!!");
922 skb_queue_tail(&fnic
->frame_queue
, skb
);
923 queue_work(fnic_event_queue
, &fnic
->frame_work
);
927 dev_kfree_skb_irq(skb
);
930 static int fnic_rq_cmpl_handler_cont(struct vnic_dev
*vdev
,
931 struct cq_desc
*cq_desc
, u8 type
,
932 u16 q_number
, u16 completed_index
,
935 struct fnic
*fnic
= vnic_dev_priv(vdev
);
937 vnic_rq_service(&fnic
->rq
[q_number
], cq_desc
, completed_index
,
938 VNIC_RQ_RETURN_DESC
, fnic_rq_cmpl_frame_recv
,
943 int fnic_rq_cmpl_handler(struct fnic
*fnic
, int rq_work_to_do
)
945 unsigned int tot_rq_work_done
= 0, cur_work_done
;
949 for (i
= 0; i
< fnic
->rq_count
; i
++) {
950 cur_work_done
= vnic_cq_service(&fnic
->cq
[i
], rq_work_to_do
,
951 fnic_rq_cmpl_handler_cont
,
954 err
= vnic_rq_fill(&fnic
->rq
[i
], fnic_alloc_rq_frame
);
956 shost_printk(KERN_ERR
, fnic
->lport
->host
,
957 "fnic_alloc_rq_frame can't alloc"
960 tot_rq_work_done
+= cur_work_done
;
963 return tot_rq_work_done
;
967 * This function is called once at init time to allocate and fill RQ
968 * buffers. Subsequently, it is called in the interrupt context after RQ
969 * buffer processing to replenish the buffers in the RQ
971 int fnic_alloc_rq_frame(struct vnic_rq
*rq
)
973 struct fnic
*fnic
= vnic_dev_priv(rq
->vdev
);
979 len
= FC_FRAME_HEADROOM
+ FC_MAX_FRAME
+ FC_FRAME_TAILROOM
;
980 skb
= dev_alloc_skb(len
);
982 FNIC_FCS_DBG(KERN_DEBUG
, fnic
->lport
->host
,
983 "Unable to allocate RQ sk_buff\n");
986 skb_reset_mac_header(skb
);
987 skb_reset_transport_header(skb
);
988 skb_reset_network_header(skb
);
990 pa
= dma_map_single(&fnic
->pdev
->dev
, skb
->data
, len
, DMA_FROM_DEVICE
);
991 if (dma_mapping_error(&fnic
->pdev
->dev
, pa
)) {
993 printk(KERN_ERR
"PCI mapping failed with error %d\n", r
);
997 fnic_queue_rq_desc(rq
, skb
, pa
, len
);
1005 void fnic_free_rq_buf(struct vnic_rq
*rq
, struct vnic_rq_buf
*buf
)
1007 struct fc_frame
*fp
= buf
->os_buf
;
1008 struct fnic
*fnic
= vnic_dev_priv(rq
->vdev
);
1010 dma_unmap_single(&fnic
->pdev
->dev
, buf
->dma_addr
, buf
->len
,
1013 dev_kfree_skb(fp_skb(fp
));
1018 * fnic_eth_send() - Send Ethernet frame.
1019 * @fip: fcoe_ctlr instance.
1020 * @skb: Ethernet Frame, FIP, without VLAN encapsulation.
1022 void fnic_eth_send(struct fcoe_ctlr
*fip
, struct sk_buff
*skb
)
1024 struct fnic
*fnic
= fnic_from_ctlr(fip
);
1025 struct vnic_wq
*wq
= &fnic
->wq
[0];
1027 struct ethhdr
*eth_hdr
;
1028 struct vlan_ethhdr
*vlan_hdr
;
1029 unsigned long flags
;
1031 if (!fnic
->vlan_hw_insert
) {
1032 eth_hdr
= (struct ethhdr
*)skb_mac_header(skb
);
1033 vlan_hdr
= skb_push(skb
, sizeof(*vlan_hdr
) - sizeof(*eth_hdr
));
1034 memcpy(vlan_hdr
, eth_hdr
, 2 * ETH_ALEN
);
1035 vlan_hdr
->h_vlan_proto
= htons(ETH_P_8021Q
);
1036 vlan_hdr
->h_vlan_encapsulated_proto
= eth_hdr
->h_proto
;
1037 vlan_hdr
->h_vlan_TCI
= htons(fnic
->vlan_id
);
1038 if ((fnic_fc_trace_set_data(fnic
->lport
->host
->host_no
,
1039 FNIC_FC_SEND
|0x80, (char *)eth_hdr
, skb
->len
)) != 0) {
1040 printk(KERN_ERR
"fnic ctlr frame trace error!!!");
1043 if ((fnic_fc_trace_set_data(fnic
->lport
->host
->host_no
,
1044 FNIC_FC_SEND
|0x80, (char *)skb
->data
, skb
->len
)) != 0) {
1045 printk(KERN_ERR
"fnic ctlr frame trace error!!!");
1049 pa
= dma_map_single(&fnic
->pdev
->dev
, skb
->data
, skb
->len
,
1051 if (dma_mapping_error(&fnic
->pdev
->dev
, pa
)) {
1052 printk(KERN_ERR
"DMA mapping failed\n");
1056 spin_lock_irqsave(&fnic
->wq_lock
[0], flags
);
1057 if (!vnic_wq_desc_avail(wq
))
1060 fnic_queue_wq_eth_desc(wq
, skb
, pa
, skb
->len
,
1061 0 /* hw inserts cos value */,
1063 spin_unlock_irqrestore(&fnic
->wq_lock
[0], flags
);
1067 spin_unlock_irqrestore(&fnic
->wq_lock
[0], flags
);
1068 dma_unmap_single(&fnic
->pdev
->dev
, pa
, skb
->len
, DMA_TO_DEVICE
);
1076 static int fnic_send_frame(struct fnic
*fnic
, struct fc_frame
*fp
)
1078 struct vnic_wq
*wq
= &fnic
->wq
[0];
1079 struct sk_buff
*skb
;
1081 struct ethhdr
*eth_hdr
;
1082 struct vlan_ethhdr
*vlan_hdr
;
1083 struct fcoe_hdr
*fcoe_hdr
;
1084 struct fc_frame_header
*fh
;
1085 u32 tot_len
, eth_hdr_len
;
1087 unsigned long flags
;
1089 fh
= fc_frame_header_get(fp
);
1092 if (unlikely(fh
->fh_r_ctl
== FC_RCTL_ELS_REQ
) &&
1093 fcoe_ctlr_els_send(&fnic
->ctlr
, fnic
->lport
, skb
))
1096 if (!fnic
->vlan_hw_insert
) {
1097 eth_hdr_len
= sizeof(*vlan_hdr
) + sizeof(*fcoe_hdr
);
1098 vlan_hdr
= skb_push(skb
, eth_hdr_len
);
1099 eth_hdr
= (struct ethhdr
*)vlan_hdr
;
1100 vlan_hdr
->h_vlan_proto
= htons(ETH_P_8021Q
);
1101 vlan_hdr
->h_vlan_encapsulated_proto
= htons(ETH_P_FCOE
);
1102 vlan_hdr
->h_vlan_TCI
= htons(fnic
->vlan_id
);
1103 fcoe_hdr
= (struct fcoe_hdr
*)(vlan_hdr
+ 1);
1105 eth_hdr_len
= sizeof(*eth_hdr
) + sizeof(*fcoe_hdr
);
1106 eth_hdr
= skb_push(skb
, eth_hdr_len
);
1107 eth_hdr
->h_proto
= htons(ETH_P_FCOE
);
1108 fcoe_hdr
= (struct fcoe_hdr
*)(eth_hdr
+ 1);
1111 if (fnic
->ctlr
.map_dest
)
1112 fc_fcoe_set_mac(eth_hdr
->h_dest
, fh
->fh_d_id
);
1114 memcpy(eth_hdr
->h_dest
, fnic
->ctlr
.dest_addr
, ETH_ALEN
);
1115 memcpy(eth_hdr
->h_source
, fnic
->data_src_addr
, ETH_ALEN
);
1118 BUG_ON(tot_len
% 4);
1120 memset(fcoe_hdr
, 0, sizeof(*fcoe_hdr
));
1121 fcoe_hdr
->fcoe_sof
= fr_sof(fp
);
1123 FC_FCOE_ENCAPS_VER(fcoe_hdr
, FC_FCOE_VER
);
1125 pa
= dma_map_single(&fnic
->pdev
->dev
, eth_hdr
, tot_len
, DMA_TO_DEVICE
);
1126 if (dma_mapping_error(&fnic
->pdev
->dev
, pa
)) {
1128 printk(KERN_ERR
"DMA map failed with error %d\n", ret
);
1129 goto free_skb_on_err
;
1132 if ((fnic_fc_trace_set_data(fnic
->lport
->host
->host_no
, FNIC_FC_SEND
,
1133 (char *)eth_hdr
, tot_len
)) != 0) {
1134 printk(KERN_ERR
"fnic ctlr frame trace error!!!");
1137 spin_lock_irqsave(&fnic
->wq_lock
[0], flags
);
1139 if (!vnic_wq_desc_avail(wq
)) {
1140 dma_unmap_single(&fnic
->pdev
->dev
, pa
, tot_len
, DMA_TO_DEVICE
);
1145 fnic_queue_wq_desc(wq
, skb
, pa
, tot_len
, fr_eof(fp
),
1146 0 /* hw inserts cos value */,
1147 fnic
->vlan_id
, 1, 1, 1);
1150 spin_unlock_irqrestore(&fnic
->wq_lock
[0], flags
);
1154 dev_kfree_skb_any(fp_skb(fp
));
1161 * Routine to send a raw frame
1163 int fnic_send(struct fc_lport
*lp
, struct fc_frame
*fp
)
1165 struct fnic
*fnic
= lport_priv(lp
);
1166 unsigned long flags
;
1168 if (fnic
->in_remove
) {
1169 dev_kfree_skb(fp_skb(fp
));
1174 * Queue frame if in a transitional state.
1175 * This occurs while registering the Port_ID / MAC address after FLOGI.
1177 spin_lock_irqsave(&fnic
->fnic_lock
, flags
);
1178 if (fnic
->state
!= FNIC_IN_FC_MODE
&& fnic
->state
!= FNIC_IN_ETH_MODE
) {
1179 skb_queue_tail(&fnic
->tx_queue
, fp_skb(fp
));
1180 spin_unlock_irqrestore(&fnic
->fnic_lock
, flags
);
1183 spin_unlock_irqrestore(&fnic
->fnic_lock
, flags
);
1185 return fnic_send_frame(fnic
, fp
);
1189 * fnic_flush_tx() - send queued frames.
1190 * @fnic: fnic device
1192 * Send frames that were waiting to go out in FC or Ethernet mode.
1193 * Whenever changing modes we purge queued frames, so these frames should
1194 * be queued for the stable mode that we're in, either FC or Ethernet.
1196 * Called without fnic_lock held.
1198 void fnic_flush_tx(struct fnic
*fnic
)
1200 struct sk_buff
*skb
;
1201 struct fc_frame
*fp
;
1203 while ((skb
= skb_dequeue(&fnic
->tx_queue
))) {
1204 fp
= (struct fc_frame
*)skb
;
1205 fnic_send_frame(fnic
, fp
);
1210 * fnic_set_eth_mode() - put fnic into ethernet mode.
1211 * @fnic: fnic device
1213 * Called without fnic lock held.
1215 static void fnic_set_eth_mode(struct fnic
*fnic
)
1217 unsigned long flags
;
1218 enum fnic_state old_state
;
1221 spin_lock_irqsave(&fnic
->fnic_lock
, flags
);
1223 old_state
= fnic
->state
;
1224 switch (old_state
) {
1225 case FNIC_IN_FC_MODE
:
1226 case FNIC_IN_ETH_TRANS_FC_MODE
:
1228 fnic
->state
= FNIC_IN_FC_TRANS_ETH_MODE
;
1229 spin_unlock_irqrestore(&fnic
->fnic_lock
, flags
);
1231 ret
= fnic_fw_reset_handler(fnic
);
1233 spin_lock_irqsave(&fnic
->fnic_lock
, flags
);
1234 if (fnic
->state
!= FNIC_IN_FC_TRANS_ETH_MODE
)
1237 fnic
->state
= old_state
;
1240 case FNIC_IN_FC_TRANS_ETH_MODE
:
1241 case FNIC_IN_ETH_MODE
:
1244 spin_unlock_irqrestore(&fnic
->fnic_lock
, flags
);
1247 static void fnic_wq_complete_frame_send(struct vnic_wq
*wq
,
1248 struct cq_desc
*cq_desc
,
1249 struct vnic_wq_buf
*buf
, void *opaque
)
1251 struct sk_buff
*skb
= buf
->os_buf
;
1252 struct fc_frame
*fp
= (struct fc_frame
*)skb
;
1253 struct fnic
*fnic
= vnic_dev_priv(wq
->vdev
);
1255 dma_unmap_single(&fnic
->pdev
->dev
, buf
->dma_addr
, buf
->len
,
1257 dev_kfree_skb_irq(fp_skb(fp
));
1261 static int fnic_wq_cmpl_handler_cont(struct vnic_dev
*vdev
,
1262 struct cq_desc
*cq_desc
, u8 type
,
1263 u16 q_number
, u16 completed_index
,
1266 struct fnic
*fnic
= vnic_dev_priv(vdev
);
1267 unsigned long flags
;
1269 spin_lock_irqsave(&fnic
->wq_lock
[q_number
], flags
);
1270 vnic_wq_service(&fnic
->wq
[q_number
], cq_desc
, completed_index
,
1271 fnic_wq_complete_frame_send
, NULL
);
1272 spin_unlock_irqrestore(&fnic
->wq_lock
[q_number
], flags
);
1277 int fnic_wq_cmpl_handler(struct fnic
*fnic
, int work_to_do
)
1279 unsigned int wq_work_done
= 0;
1282 for (i
= 0; i
< fnic
->raw_wq_count
; i
++) {
1283 wq_work_done
+= vnic_cq_service(&fnic
->cq
[fnic
->rq_count
+i
],
1285 fnic_wq_cmpl_handler_cont
,
1289 return wq_work_done
;
1293 void fnic_free_wq_buf(struct vnic_wq
*wq
, struct vnic_wq_buf
*buf
)
1295 struct fc_frame
*fp
= buf
->os_buf
;
1296 struct fnic
*fnic
= vnic_dev_priv(wq
->vdev
);
1298 dma_unmap_single(&fnic
->pdev
->dev
, buf
->dma_addr
, buf
->len
,
1301 dev_kfree_skb(fp_skb(fp
));
1305 void fnic_fcoe_reset_vlans(struct fnic
*fnic
)
1307 unsigned long flags
;
1308 struct fcoe_vlan
*vlan
;
1309 struct fcoe_vlan
*next
;
1312 * indicate a link down to fcoe so that all fcf's are free'd
1313 * might not be required since we did this before sending vlan
1316 spin_lock_irqsave(&fnic
->vlans_lock
, flags
);
1317 if (!list_empty(&fnic
->vlans
)) {
1318 list_for_each_entry_safe(vlan
, next
, &fnic
->vlans
, list
) {
1319 list_del(&vlan
->list
);
1323 spin_unlock_irqrestore(&fnic
->vlans_lock
, flags
);
1326 void fnic_handle_fip_timer(struct fnic
*fnic
)
1328 unsigned long flags
;
1329 struct fcoe_vlan
*vlan
;
1330 struct fnic_stats
*fnic_stats
= &fnic
->fnic_stats
;
1333 spin_lock_irqsave(&fnic
->fnic_lock
, flags
);
1334 if (fnic
->stop_rx_link_events
) {
1335 spin_unlock_irqrestore(&fnic
->fnic_lock
, flags
);
1338 spin_unlock_irqrestore(&fnic
->fnic_lock
, flags
);
1340 if (fnic
->ctlr
.mode
== FIP_MODE_NON_FIP
)
1343 spin_lock_irqsave(&fnic
->vlans_lock
, flags
);
1344 if (list_empty(&fnic
->vlans
)) {
1345 spin_unlock_irqrestore(&fnic
->vlans_lock
, flags
);
1346 /* no vlans available, try again */
1347 if (printk_ratelimit())
1348 FNIC_FCS_DBG(KERN_DEBUG
, fnic
->lport
->host
,
1349 "Start VLAN Discovery\n");
1350 fnic_event_enq(fnic
, FNIC_EVT_START_VLAN_DISC
);
1354 vlan
= list_first_entry(&fnic
->vlans
, struct fcoe_vlan
, list
);
1355 shost_printk(KERN_DEBUG
, fnic
->lport
->host
,
1356 "fip_timer: vlan %d state %d sol_count %d\n",
1357 vlan
->vid
, vlan
->state
, vlan
->sol_count
);
1358 switch (vlan
->state
) {
1360 FNIC_FCS_DBG(KERN_DEBUG
, fnic
->lport
->host
,
1361 "FIP VLAN is selected for FC transaction\n");
1362 spin_unlock_irqrestore(&fnic
->vlans_lock
, flags
);
1364 case FIP_VLAN_FAILED
:
1365 spin_unlock_irqrestore(&fnic
->vlans_lock
, flags
);
1366 /* if all vlans are in failed state, restart vlan disc */
1367 if (printk_ratelimit())
1368 FNIC_FCS_DBG(KERN_DEBUG
, fnic
->lport
->host
,
1369 "Start VLAN Discovery\n");
1370 fnic_event_enq(fnic
, FNIC_EVT_START_VLAN_DISC
);
1373 if (vlan
->sol_count
>= FCOE_CTLR_MAX_SOL
) {
1375 * no response on this vlan, remove from the list.
1378 shost_printk(KERN_INFO
, fnic
->lport
->host
,
1379 "Dequeue this VLAN ID %d from list\n",
1381 list_del(&vlan
->list
);
1384 if (list_empty(&fnic
->vlans
)) {
1385 /* we exhausted all vlans, restart vlan disc */
1386 spin_unlock_irqrestore(&fnic
->vlans_lock
,
1388 shost_printk(KERN_INFO
, fnic
->lport
->host
,
1389 "fip_timer: vlan list empty, "
1390 "trigger vlan disc\n");
1391 fnic_event_enq(fnic
, FNIC_EVT_START_VLAN_DISC
);
1394 /* check the next vlan */
1395 vlan
= list_first_entry(&fnic
->vlans
, struct fcoe_vlan
,
1397 fnic
->set_vlan(fnic
, vlan
->vid
);
1398 vlan
->state
= FIP_VLAN_SENT
; /* sent now */
1400 spin_unlock_irqrestore(&fnic
->vlans_lock
, flags
);
1401 atomic64_inc(&fnic_stats
->vlan_stats
.sol_expiry_count
);
1403 sol_time
= jiffies
+ msecs_to_jiffies
1404 (FCOE_CTLR_START_DELAY
);
1405 mod_timer(&fnic
->fip_timer
, round_jiffies(sol_time
));