xref: /linux/drivers/scsi/fnic/fnic_fcs.c (revision 6942df7f775107b504f10de42c81971f514d718d)
15df6d737SAbhijeet Joglekar /*
25df6d737SAbhijeet Joglekar  * Copyright 2008 Cisco Systems, Inc.  All rights reserved.
35df6d737SAbhijeet Joglekar  * Copyright 2007 Nuova Systems, Inc.  All rights reserved.
45df6d737SAbhijeet Joglekar  *
55df6d737SAbhijeet Joglekar  * This program is free software; you may redistribute it and/or modify
65df6d737SAbhijeet Joglekar  * it under the terms of the GNU General Public License as published by
75df6d737SAbhijeet Joglekar  * the Free Software Foundation; version 2 of the License.
85df6d737SAbhijeet Joglekar  *
95df6d737SAbhijeet Joglekar  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
105df6d737SAbhijeet Joglekar  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
115df6d737SAbhijeet Joglekar  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
125df6d737SAbhijeet Joglekar  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
135df6d737SAbhijeet Joglekar  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
145df6d737SAbhijeet Joglekar  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
155df6d737SAbhijeet Joglekar  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
165df6d737SAbhijeet Joglekar  * SOFTWARE.
175df6d737SAbhijeet Joglekar  */
185df6d737SAbhijeet Joglekar #include <linux/errno.h>
195df6d737SAbhijeet Joglekar #include <linux/pci.h>
205a0e3ad6STejun Heo #include <linux/slab.h>
215df6d737SAbhijeet Joglekar #include <linux/skbuff.h>
225df6d737SAbhijeet Joglekar #include <linux/interrupt.h>
235df6d737SAbhijeet Joglekar #include <linux/spinlock.h>
245df6d737SAbhijeet Joglekar #include <linux/if_ether.h>
255df6d737SAbhijeet Joglekar #include <linux/if_vlan.h>
265df6d737SAbhijeet Joglekar #include <linux/workqueue.h>
2778112e55SJoe Eykholt #include <scsi/fc/fc_fip.h>
285df6d737SAbhijeet Joglekar #include <scsi/fc/fc_els.h>
295df6d737SAbhijeet Joglekar #include <scsi/fc/fc_fcoe.h>
305df6d737SAbhijeet Joglekar #include <scsi/fc_frame.h>
315df6d737SAbhijeet Joglekar #include <scsi/libfc.h>
325df6d737SAbhijeet Joglekar #include "fnic_io.h"
335df6d737SAbhijeet Joglekar #include "fnic.h"
34d3c995f1SHiral Patel #include "fnic_fip.h"
355df6d737SAbhijeet Joglekar #include "cq_enet_desc.h"
365df6d737SAbhijeet Joglekar #include "cq_exch_desc.h"
375df6d737SAbhijeet Joglekar 
38d3c995f1SHiral Patel static u8 fcoe_all_fcfs[ETH_ALEN];
39d3c995f1SHiral Patel struct workqueue_struct *fnic_fip_queue;
405df6d737SAbhijeet Joglekar struct workqueue_struct *fnic_event_queue;
415df6d737SAbhijeet Joglekar 
4278112e55SJoe Eykholt static void fnic_set_eth_mode(struct fnic *);
43d3c995f1SHiral Patel static void fnic_fcoe_send_vlan_req(struct fnic *fnic);
44d3c995f1SHiral Patel static void fnic_fcoe_start_fcf_disc(struct fnic *fnic);
45d3c995f1SHiral Patel static void fnic_fcoe_process_vlan_resp(struct fnic *fnic, struct sk_buff *);
46d3c995f1SHiral Patel static int fnic_fcoe_vlan_check(struct fnic *fnic, u16 flag);
47d3c995f1SHiral Patel static int fnic_fcoe_handle_fip_frame(struct fnic *fnic, struct sk_buff *skb);
4878112e55SJoe Eykholt 
495df6d737SAbhijeet Joglekar void fnic_handle_link(struct work_struct *work)
505df6d737SAbhijeet Joglekar {
515df6d737SAbhijeet Joglekar 	struct fnic *fnic = container_of(work, struct fnic, link_work);
525df6d737SAbhijeet Joglekar 	unsigned long flags;
535df6d737SAbhijeet Joglekar 	int old_link_status;
545df6d737SAbhijeet Joglekar 	u32 old_link_down_cnt;
555df6d737SAbhijeet Joglekar 
565df6d737SAbhijeet Joglekar 	spin_lock_irqsave(&fnic->fnic_lock, flags);
575df6d737SAbhijeet Joglekar 
585df6d737SAbhijeet Joglekar 	if (fnic->stop_rx_link_events) {
595df6d737SAbhijeet Joglekar 		spin_unlock_irqrestore(&fnic->fnic_lock, flags);
605df6d737SAbhijeet Joglekar 		return;
615df6d737SAbhijeet Joglekar 	}
625df6d737SAbhijeet Joglekar 
635df6d737SAbhijeet Joglekar 	old_link_down_cnt = fnic->link_down_cnt;
645df6d737SAbhijeet Joglekar 	old_link_status = fnic->link_status;
655df6d737SAbhijeet Joglekar 	fnic->link_status = vnic_dev_link_status(fnic->vdev);
665df6d737SAbhijeet Joglekar 	fnic->link_down_cnt = vnic_dev_link_down_cnt(fnic->vdev);
675df6d737SAbhijeet Joglekar 
685df6d737SAbhijeet Joglekar 	if (old_link_status == fnic->link_status) {
695df6d737SAbhijeet Joglekar 		if (!fnic->link_status)
705df6d737SAbhijeet Joglekar 			/* DOWN -> DOWN */
715df6d737SAbhijeet Joglekar 			spin_unlock_irqrestore(&fnic->fnic_lock, flags);
725df6d737SAbhijeet Joglekar 		else {
735df6d737SAbhijeet Joglekar 			if (old_link_down_cnt != fnic->link_down_cnt) {
745df6d737SAbhijeet Joglekar 				/* UP -> DOWN -> UP */
755df6d737SAbhijeet Joglekar 				fnic->lport->host_stats.link_failure_count++;
765df6d737SAbhijeet Joglekar 				spin_unlock_irqrestore(&fnic->fnic_lock, flags);
775df6d737SAbhijeet Joglekar 				FNIC_FCS_DBG(KERN_DEBUG, fnic->lport->host,
785df6d737SAbhijeet Joglekar 					     "link down\n");
7978112e55SJoe Eykholt 				fcoe_ctlr_link_down(&fnic->ctlr);
80d3c995f1SHiral Patel 				if (fnic->config.flags & VFCF_FIP_CAPABLE) {
81d3c995f1SHiral Patel 					/* start FCoE VLAN discovery */
82d3c995f1SHiral Patel 					fnic_fcoe_send_vlan_req(fnic);
83d3c995f1SHiral Patel 					return;
84d3c995f1SHiral Patel 				}
855df6d737SAbhijeet Joglekar 				FNIC_FCS_DBG(KERN_DEBUG, fnic->lport->host,
865df6d737SAbhijeet Joglekar 					     "link up\n");
8778112e55SJoe Eykholt 				fcoe_ctlr_link_up(&fnic->ctlr);
885df6d737SAbhijeet Joglekar 			} else
895df6d737SAbhijeet Joglekar 				/* UP -> UP */
905df6d737SAbhijeet Joglekar 				spin_unlock_irqrestore(&fnic->fnic_lock, flags);
915df6d737SAbhijeet Joglekar 		}
925df6d737SAbhijeet Joglekar 	} else if (fnic->link_status) {
935df6d737SAbhijeet Joglekar 		/* DOWN -> UP */
945df6d737SAbhijeet Joglekar 		spin_unlock_irqrestore(&fnic->fnic_lock, flags);
95d3c995f1SHiral Patel 		if (fnic->config.flags & VFCF_FIP_CAPABLE) {
96d3c995f1SHiral Patel 			/* start FCoE VLAN discovery */
97d3c995f1SHiral Patel 			fnic_fcoe_send_vlan_req(fnic);
98d3c995f1SHiral Patel 			return;
99d3c995f1SHiral Patel 		}
1005df6d737SAbhijeet Joglekar 		FNIC_FCS_DBG(KERN_DEBUG, fnic->lport->host, "link up\n");
10178112e55SJoe Eykholt 		fcoe_ctlr_link_up(&fnic->ctlr);
1025df6d737SAbhijeet Joglekar 	} else {
1035df6d737SAbhijeet Joglekar 		/* UP -> DOWN */
1045df6d737SAbhijeet Joglekar 		fnic->lport->host_stats.link_failure_count++;
1055df6d737SAbhijeet Joglekar 		spin_unlock_irqrestore(&fnic->fnic_lock, flags);
1065df6d737SAbhijeet Joglekar 		FNIC_FCS_DBG(KERN_DEBUG, fnic->lport->host, "link down\n");
10778112e55SJoe Eykholt 		fcoe_ctlr_link_down(&fnic->ctlr);
1085df6d737SAbhijeet Joglekar 	}
1095df6d737SAbhijeet Joglekar 
1105df6d737SAbhijeet Joglekar }
1115df6d737SAbhijeet Joglekar 
1125df6d737SAbhijeet Joglekar /*
1135df6d737SAbhijeet Joglekar  * This function passes incoming fabric frames to libFC
1145df6d737SAbhijeet Joglekar  */
1155df6d737SAbhijeet Joglekar void fnic_handle_frame(struct work_struct *work)
1165df6d737SAbhijeet Joglekar {
1175df6d737SAbhijeet Joglekar 	struct fnic *fnic = container_of(work, struct fnic, frame_work);
1185df6d737SAbhijeet Joglekar 	struct fc_lport *lp = fnic->lport;
1195df6d737SAbhijeet Joglekar 	unsigned long flags;
1205df6d737SAbhijeet Joglekar 	struct sk_buff *skb;
1215df6d737SAbhijeet Joglekar 	struct fc_frame *fp;
1225df6d737SAbhijeet Joglekar 
1235df6d737SAbhijeet Joglekar 	while ((skb = skb_dequeue(&fnic->frame_queue))) {
1245df6d737SAbhijeet Joglekar 
1255df6d737SAbhijeet Joglekar 		spin_lock_irqsave(&fnic->fnic_lock, flags);
1265df6d737SAbhijeet Joglekar 		if (fnic->stop_rx_link_events) {
1275df6d737SAbhijeet Joglekar 			spin_unlock_irqrestore(&fnic->fnic_lock, flags);
1285df6d737SAbhijeet Joglekar 			dev_kfree_skb(skb);
1295df6d737SAbhijeet Joglekar 			return;
1305df6d737SAbhijeet Joglekar 		}
1315df6d737SAbhijeet Joglekar 		fp = (struct fc_frame *)skb;
13278112e55SJoe Eykholt 
13378112e55SJoe Eykholt 		/*
13478112e55SJoe Eykholt 		 * If we're in a transitional state, just re-queue and return.
13578112e55SJoe Eykholt 		 * The queue will be serviced when we get to a stable state.
13678112e55SJoe Eykholt 		 */
13778112e55SJoe Eykholt 		if (fnic->state != FNIC_IN_FC_MODE &&
13878112e55SJoe Eykholt 		    fnic->state != FNIC_IN_ETH_MODE) {
13978112e55SJoe Eykholt 			skb_queue_head(&fnic->frame_queue, skb);
14078112e55SJoe Eykholt 			spin_unlock_irqrestore(&fnic->fnic_lock, flags);
14178112e55SJoe Eykholt 			return;
1425df6d737SAbhijeet Joglekar 		}
1435df6d737SAbhijeet Joglekar 		spin_unlock_irqrestore(&fnic->fnic_lock, flags);
1445df6d737SAbhijeet Joglekar 
14552ff878cSVasu Dev 		fc_exch_recv(lp, fp);
1465df6d737SAbhijeet Joglekar 	}
1475df6d737SAbhijeet Joglekar }
1485df6d737SAbhijeet Joglekar 
149d3c995f1SHiral Patel void fnic_fcoe_evlist_free(struct fnic *fnic)
150d3c995f1SHiral Patel {
151d3c995f1SHiral Patel 	struct fnic_event *fevt = NULL;
152d3c995f1SHiral Patel 	struct fnic_event *next = NULL;
153d3c995f1SHiral Patel 	unsigned long flags;
154d3c995f1SHiral Patel 
155d3c995f1SHiral Patel 	spin_lock_irqsave(&fnic->fnic_lock, flags);
156d3c995f1SHiral Patel 	if (list_empty(&fnic->evlist)) {
157d3c995f1SHiral Patel 		spin_unlock_irqrestore(&fnic->fnic_lock, flags);
158d3c995f1SHiral Patel 		return;
159d3c995f1SHiral Patel 	}
160d3c995f1SHiral Patel 
161d3c995f1SHiral Patel 	list_for_each_entry_safe(fevt, next, &fnic->evlist, list) {
162d3c995f1SHiral Patel 		list_del(&fevt->list);
163d3c995f1SHiral Patel 		kfree(fevt);
164d3c995f1SHiral Patel 	}
165d3c995f1SHiral Patel 	spin_unlock_irqrestore(&fnic->fnic_lock, flags);
166d3c995f1SHiral Patel }
167d3c995f1SHiral Patel 
168d3c995f1SHiral Patel void fnic_handle_event(struct work_struct *work)
169d3c995f1SHiral Patel {
170d3c995f1SHiral Patel 	struct fnic *fnic = container_of(work, struct fnic, event_work);
171d3c995f1SHiral Patel 	struct fnic_event *fevt = NULL;
172d3c995f1SHiral Patel 	struct fnic_event *next = NULL;
173d3c995f1SHiral Patel 	unsigned long flags;
174d3c995f1SHiral Patel 
175d3c995f1SHiral Patel 	spin_lock_irqsave(&fnic->fnic_lock, flags);
176d3c995f1SHiral Patel 	if (list_empty(&fnic->evlist)) {
177d3c995f1SHiral Patel 		spin_unlock_irqrestore(&fnic->fnic_lock, flags);
178d3c995f1SHiral Patel 		return;
179d3c995f1SHiral Patel 	}
180d3c995f1SHiral Patel 
181d3c995f1SHiral Patel 	list_for_each_entry_safe(fevt, next, &fnic->evlist, list) {
182d3c995f1SHiral Patel 		if (fnic->stop_rx_link_events) {
183d3c995f1SHiral Patel 			list_del(&fevt->list);
184d3c995f1SHiral Patel 			kfree(fevt);
185d3c995f1SHiral Patel 			spin_unlock_irqrestore(&fnic->fnic_lock, flags);
186d3c995f1SHiral Patel 			return;
187d3c995f1SHiral Patel 		}
188d3c995f1SHiral Patel 		/*
189d3c995f1SHiral Patel 		 * If we're in a transitional state, just re-queue and return.
190d3c995f1SHiral Patel 		 * The queue will be serviced when we get to a stable state.
191d3c995f1SHiral Patel 		 */
192d3c995f1SHiral Patel 		if (fnic->state != FNIC_IN_FC_MODE &&
193d3c995f1SHiral Patel 		    fnic->state != FNIC_IN_ETH_MODE) {
194d3c995f1SHiral Patel 			spin_unlock_irqrestore(&fnic->fnic_lock, flags);
195d3c995f1SHiral Patel 			return;
196d3c995f1SHiral Patel 		}
197d3c995f1SHiral Patel 
198d3c995f1SHiral Patel 		list_del(&fevt->list);
199d3c995f1SHiral Patel 		switch (fevt->event) {
200d3c995f1SHiral Patel 		case FNIC_EVT_START_VLAN_DISC:
201d3c995f1SHiral Patel 			spin_unlock_irqrestore(&fnic->fnic_lock, flags);
202d3c995f1SHiral Patel 			fnic_fcoe_send_vlan_req(fnic);
203d3c995f1SHiral Patel 			spin_lock_irqsave(&fnic->fnic_lock, flags);
204d3c995f1SHiral Patel 			break;
205d3c995f1SHiral Patel 		case FNIC_EVT_START_FCF_DISC:
206d3c995f1SHiral Patel 			FNIC_FCS_DBG(KERN_DEBUG, fnic->lport->host,
207d3c995f1SHiral Patel 				  "Start FCF Discovery\n");
208d3c995f1SHiral Patel 			fnic_fcoe_start_fcf_disc(fnic);
209d3c995f1SHiral Patel 			break;
210d3c995f1SHiral Patel 		default:
211d3c995f1SHiral Patel 			FNIC_FCS_DBG(KERN_DEBUG, fnic->lport->host,
212d3c995f1SHiral Patel 				  "Unknown event 0x%x\n", fevt->event);
213d3c995f1SHiral Patel 			break;
214d3c995f1SHiral Patel 		}
215d3c995f1SHiral Patel 		kfree(fevt);
216d3c995f1SHiral Patel 	}
217d3c995f1SHiral Patel 	spin_unlock_irqrestore(&fnic->fnic_lock, flags);
218d3c995f1SHiral Patel }
219d3c995f1SHiral Patel 
220d3c995f1SHiral Patel /**
221d3c995f1SHiral Patel  * Check if the Received FIP FLOGI frame is rejected
222d3c995f1SHiral Patel  * @fip: The FCoE controller that received the frame
223d3c995f1SHiral Patel  * @skb: The received FIP frame
224d3c995f1SHiral Patel  *
225d3c995f1SHiral Patel  * Returns non-zero if the frame is rejected with unsupported cmd with
226d3c995f1SHiral Patel  * insufficient resource els explanation.
227d3c995f1SHiral Patel  */
228d3c995f1SHiral Patel static inline int is_fnic_fip_flogi_reject(struct fcoe_ctlr *fip,
229d3c995f1SHiral Patel 					 struct sk_buff *skb)
230d3c995f1SHiral Patel {
231d3c995f1SHiral Patel 	struct fc_lport *lport = fip->lp;
232d3c995f1SHiral Patel 	struct fip_header *fiph;
233d3c995f1SHiral Patel 	struct fc_frame_header *fh = NULL;
234d3c995f1SHiral Patel 	struct fip_desc *desc;
235d3c995f1SHiral Patel 	struct fip_encaps *els;
236d3c995f1SHiral Patel 	enum fip_desc_type els_dtype = 0;
237d3c995f1SHiral Patel 	u16 op;
238d3c995f1SHiral Patel 	u8 els_op;
239d3c995f1SHiral Patel 	u8 sub;
240d3c995f1SHiral Patel 
241d3c995f1SHiral Patel 	size_t els_len = 0;
242d3c995f1SHiral Patel 	size_t rlen;
243d3c995f1SHiral Patel 	size_t dlen = 0;
244d3c995f1SHiral Patel 
245d3c995f1SHiral Patel 	if (skb_linearize(skb))
246d3c995f1SHiral Patel 		return 0;
247d3c995f1SHiral Patel 
248d3c995f1SHiral Patel 	if (skb->len < sizeof(*fiph))
249d3c995f1SHiral Patel 		return 0;
250d3c995f1SHiral Patel 
251d3c995f1SHiral Patel 	fiph = (struct fip_header *)skb->data;
252d3c995f1SHiral Patel 	op = ntohs(fiph->fip_op);
253d3c995f1SHiral Patel 	sub = fiph->fip_subcode;
254d3c995f1SHiral Patel 
255d3c995f1SHiral Patel 	if (op != FIP_OP_LS)
256d3c995f1SHiral Patel 		return 0;
257d3c995f1SHiral Patel 
258d3c995f1SHiral Patel 	if (sub != FIP_SC_REP)
259d3c995f1SHiral Patel 		return 0;
260d3c995f1SHiral Patel 
261d3c995f1SHiral Patel 	rlen = ntohs(fiph->fip_dl_len) * 4;
262d3c995f1SHiral Patel 	if (rlen + sizeof(*fiph) > skb->len)
263d3c995f1SHiral Patel 		return 0;
264d3c995f1SHiral Patel 
265d3c995f1SHiral Patel 	desc = (struct fip_desc *)(fiph + 1);
266d3c995f1SHiral Patel 	dlen = desc->fip_dlen * FIP_BPW;
267d3c995f1SHiral Patel 
268d3c995f1SHiral Patel 	if (desc->fip_dtype == FIP_DT_FLOGI) {
269d3c995f1SHiral Patel 
270d3c995f1SHiral Patel 		shost_printk(KERN_DEBUG, lport->host,
271d3c995f1SHiral Patel 			  " FIP TYPE FLOGI: fab name:%llx "
272d3c995f1SHiral Patel 			  "vfid:%d map:%x\n",
273d3c995f1SHiral Patel 			  fip->sel_fcf->fabric_name, fip->sel_fcf->vfid,
274d3c995f1SHiral Patel 			  fip->sel_fcf->fc_map);
275d3c995f1SHiral Patel 		if (dlen < sizeof(*els) + sizeof(*fh) + 1)
276d3c995f1SHiral Patel 			return 0;
277d3c995f1SHiral Patel 
278d3c995f1SHiral Patel 		els_len = dlen - sizeof(*els);
279d3c995f1SHiral Patel 		els = (struct fip_encaps *)desc;
280d3c995f1SHiral Patel 		fh = (struct fc_frame_header *)(els + 1);
281d3c995f1SHiral Patel 		els_dtype = desc->fip_dtype;
282d3c995f1SHiral Patel 
283d3c995f1SHiral Patel 		if (!fh)
284d3c995f1SHiral Patel 			return 0;
285d3c995f1SHiral Patel 
286d3c995f1SHiral Patel 		/*
287d3c995f1SHiral Patel 		 * ELS command code, reason and explanation should be = Reject,
288d3c995f1SHiral Patel 		 * unsupported command and insufficient resource
289d3c995f1SHiral Patel 		 */
290d3c995f1SHiral Patel 		els_op = *(u8 *)(fh + 1);
291d3c995f1SHiral Patel 		if (els_op == ELS_LS_RJT) {
292d3c995f1SHiral Patel 			shost_printk(KERN_INFO, lport->host,
293d3c995f1SHiral Patel 				  "Flogi Request Rejected by Switch\n");
294d3c995f1SHiral Patel 			return 1;
295d3c995f1SHiral Patel 		}
296d3c995f1SHiral Patel 		shost_printk(KERN_INFO, lport->host,
297d3c995f1SHiral Patel 				"Flogi Request Accepted by Switch\n");
298d3c995f1SHiral Patel 	}
299d3c995f1SHiral Patel 	return 0;
300d3c995f1SHiral Patel }
301d3c995f1SHiral Patel 
302d3c995f1SHiral Patel static void fnic_fcoe_send_vlan_req(struct fnic *fnic)
303d3c995f1SHiral Patel {
304d3c995f1SHiral Patel 	struct fcoe_ctlr *fip = &fnic->ctlr;
305d3c995f1SHiral Patel 	struct sk_buff *skb;
306d3c995f1SHiral Patel 	char *eth_fr;
307d3c995f1SHiral Patel 	int fr_len;
308d3c995f1SHiral Patel 	struct fip_vlan *vlan;
309d3c995f1SHiral Patel 	u64 vlan_tov;
310d3c995f1SHiral Patel 
311d3c995f1SHiral Patel 	fnic_fcoe_reset_vlans(fnic);
312d3c995f1SHiral Patel 	fnic->set_vlan(fnic, 0);
313d3c995f1SHiral Patel 	FNIC_FCS_DBG(KERN_INFO, fnic->lport->host,
314d3c995f1SHiral Patel 		  "Sending VLAN request...\n");
315d3c995f1SHiral Patel 	skb = dev_alloc_skb(sizeof(struct fip_vlan));
316d3c995f1SHiral Patel 	if (!skb)
317d3c995f1SHiral Patel 		return;
318d3c995f1SHiral Patel 
319d3c995f1SHiral Patel 	fr_len = sizeof(*vlan);
320d3c995f1SHiral Patel 	eth_fr = (char *)skb->data;
321d3c995f1SHiral Patel 	vlan = (struct fip_vlan *)eth_fr;
322d3c995f1SHiral Patel 
323d3c995f1SHiral Patel 	memset(vlan, 0, sizeof(*vlan));
324d3c995f1SHiral Patel 	memcpy(vlan->eth.h_source, fip->ctl_src_addr, ETH_ALEN);
325d3c995f1SHiral Patel 	memcpy(vlan->eth.h_dest, fcoe_all_fcfs, ETH_ALEN);
326d3c995f1SHiral Patel 	vlan->eth.h_proto = htons(ETH_P_FIP);
327d3c995f1SHiral Patel 
328d3c995f1SHiral Patel 	vlan->fip.fip_ver = FIP_VER_ENCAPS(FIP_VER);
329d3c995f1SHiral Patel 	vlan->fip.fip_op = htons(FIP_OP_VLAN);
330d3c995f1SHiral Patel 	vlan->fip.fip_subcode = FIP_SC_VL_REQ;
331d3c995f1SHiral Patel 	vlan->fip.fip_dl_len = htons(sizeof(vlan->desc) / FIP_BPW);
332d3c995f1SHiral Patel 
333d3c995f1SHiral Patel 	vlan->desc.mac.fd_desc.fip_dtype = FIP_DT_MAC;
334d3c995f1SHiral Patel 	vlan->desc.mac.fd_desc.fip_dlen = sizeof(vlan->desc.mac) / FIP_BPW;
335d3c995f1SHiral Patel 	memcpy(&vlan->desc.mac.fd_mac, fip->ctl_src_addr, ETH_ALEN);
336d3c995f1SHiral Patel 
337d3c995f1SHiral Patel 	vlan->desc.wwnn.fd_desc.fip_dtype = FIP_DT_NAME;
338d3c995f1SHiral Patel 	vlan->desc.wwnn.fd_desc.fip_dlen = sizeof(vlan->desc.wwnn) / FIP_BPW;
339d3c995f1SHiral Patel 	put_unaligned_be64(fip->lp->wwnn, &vlan->desc.wwnn.fd_wwn);
340d3c995f1SHiral Patel 
341d3c995f1SHiral Patel 	skb_put(skb, sizeof(*vlan));
342d3c995f1SHiral Patel 	skb->protocol = htons(ETH_P_FIP);
343d3c995f1SHiral Patel 	skb_reset_mac_header(skb);
344d3c995f1SHiral Patel 	skb_reset_network_header(skb);
345d3c995f1SHiral Patel 	fip->send(fip, skb);
346d3c995f1SHiral Patel 
347d3c995f1SHiral Patel 	/* set a timer so that we can retry if there no response */
348d3c995f1SHiral Patel 	vlan_tov = jiffies + msecs_to_jiffies(FCOE_CTLR_FIPVLAN_TOV);
349d3c995f1SHiral Patel 	mod_timer(&fnic->fip_timer, round_jiffies(vlan_tov));
350d3c995f1SHiral Patel }
351d3c995f1SHiral Patel 
352d3c995f1SHiral Patel static void fnic_fcoe_process_vlan_resp(struct fnic *fnic, struct sk_buff *skb)
353d3c995f1SHiral Patel {
354d3c995f1SHiral Patel 	struct fcoe_ctlr *fip = &fnic->ctlr;
355d3c995f1SHiral Patel 	struct fip_header *fiph;
356d3c995f1SHiral Patel 	struct fip_desc *desc;
357d3c995f1SHiral Patel 	u16 vid;
358d3c995f1SHiral Patel 	size_t rlen;
359d3c995f1SHiral Patel 	size_t dlen;
360d3c995f1SHiral Patel 	struct fcoe_vlan *vlan;
361d3c995f1SHiral Patel 	u64 sol_time;
362d3c995f1SHiral Patel 	unsigned long flags;
363d3c995f1SHiral Patel 
364d3c995f1SHiral Patel 	FNIC_FCS_DBG(KERN_INFO, fnic->lport->host,
365d3c995f1SHiral Patel 		  "Received VLAN response...\n");
366d3c995f1SHiral Patel 
367d3c995f1SHiral Patel 	fiph = (struct fip_header *) skb->data;
368d3c995f1SHiral Patel 
369d3c995f1SHiral Patel 	FNIC_FCS_DBG(KERN_INFO, fnic->lport->host,
370d3c995f1SHiral Patel 		  "Received VLAN response... OP 0x%x SUB_OP 0x%x\n",
371d3c995f1SHiral Patel 		  ntohs(fiph->fip_op), fiph->fip_subcode);
372d3c995f1SHiral Patel 
373d3c995f1SHiral Patel 	rlen = ntohs(fiph->fip_dl_len) * 4;
374d3c995f1SHiral Patel 	fnic_fcoe_reset_vlans(fnic);
375d3c995f1SHiral Patel 	spin_lock_irqsave(&fnic->vlans_lock, flags);
376d3c995f1SHiral Patel 	desc = (struct fip_desc *)(fiph + 1);
377d3c995f1SHiral Patel 	while (rlen > 0) {
378d3c995f1SHiral Patel 		dlen = desc->fip_dlen * FIP_BPW;
379d3c995f1SHiral Patel 		switch (desc->fip_dtype) {
380d3c995f1SHiral Patel 		case FIP_DT_VLAN:
381d3c995f1SHiral Patel 			vid = ntohs(((struct fip_vlan_desc *)desc)->fd_vlan);
382d3c995f1SHiral Patel 			shost_printk(KERN_INFO, fnic->lport->host,
383d3c995f1SHiral Patel 				  "process_vlan_resp: FIP VLAN %d\n", vid);
384d3c995f1SHiral Patel 			vlan = kmalloc(sizeof(*vlan),
385d3c995f1SHiral Patel 							GFP_ATOMIC);
386d3c995f1SHiral Patel 			if (!vlan) {
387d3c995f1SHiral Patel 				/* retry from timer */
388d3c995f1SHiral Patel 				spin_unlock_irqrestore(&fnic->vlans_lock,
389d3c995f1SHiral Patel 							flags);
390d3c995f1SHiral Patel 				goto out;
391d3c995f1SHiral Patel 			}
392d3c995f1SHiral Patel 			memset(vlan, 0, sizeof(struct fcoe_vlan));
393d3c995f1SHiral Patel 			vlan->vid = vid & 0x0fff;
394d3c995f1SHiral Patel 			vlan->state = FIP_VLAN_AVAIL;
395d3c995f1SHiral Patel 			list_add_tail(&vlan->list, &fnic->vlans);
396d3c995f1SHiral Patel 			break;
397d3c995f1SHiral Patel 		}
398d3c995f1SHiral Patel 		desc = (struct fip_desc *)((char *)desc + dlen);
399d3c995f1SHiral Patel 		rlen -= dlen;
400d3c995f1SHiral Patel 	}
401d3c995f1SHiral Patel 
402d3c995f1SHiral Patel 	/* any VLAN descriptors present ? */
403d3c995f1SHiral Patel 	if (list_empty(&fnic->vlans)) {
404d3c995f1SHiral Patel 		/* retry from timer */
405d3c995f1SHiral Patel 		FNIC_FCS_DBG(KERN_INFO, fnic->lport->host,
406d3c995f1SHiral Patel 			  "No VLAN descriptors in FIP VLAN response\n");
407d3c995f1SHiral Patel 		spin_unlock_irqrestore(&fnic->vlans_lock, flags);
408d3c995f1SHiral Patel 		goto out;
409d3c995f1SHiral Patel 	}
410d3c995f1SHiral Patel 
411d3c995f1SHiral Patel 	vlan = list_first_entry(&fnic->vlans, struct fcoe_vlan, list);
412d3c995f1SHiral Patel 	fnic->set_vlan(fnic, vlan->vid);
413d3c995f1SHiral Patel 	vlan->state = FIP_VLAN_SENT; /* sent now */
414d3c995f1SHiral Patel 	vlan->sol_count++;
415d3c995f1SHiral Patel 	spin_unlock_irqrestore(&fnic->vlans_lock, flags);
416d3c995f1SHiral Patel 
417d3c995f1SHiral Patel 	/* start the solicitation */
418d3c995f1SHiral Patel 	fcoe_ctlr_link_up(fip);
419d3c995f1SHiral Patel 
420d3c995f1SHiral Patel 	sol_time = jiffies + msecs_to_jiffies(FCOE_CTLR_START_DELAY);
421d3c995f1SHiral Patel 	mod_timer(&fnic->fip_timer, round_jiffies(sol_time));
422d3c995f1SHiral Patel out:
423d3c995f1SHiral Patel 	return;
424d3c995f1SHiral Patel }
425d3c995f1SHiral Patel 
426d3c995f1SHiral Patel static void fnic_fcoe_start_fcf_disc(struct fnic *fnic)
427d3c995f1SHiral Patel {
428d3c995f1SHiral Patel 	unsigned long flags;
429d3c995f1SHiral Patel 	struct fcoe_vlan *vlan;
430d3c995f1SHiral Patel 	u64 sol_time;
431d3c995f1SHiral Patel 
432d3c995f1SHiral Patel 	spin_lock_irqsave(&fnic->vlans_lock, flags);
433d3c995f1SHiral Patel 	vlan = list_first_entry(&fnic->vlans, struct fcoe_vlan, list);
434d3c995f1SHiral Patel 	fnic->set_vlan(fnic, vlan->vid);
435d3c995f1SHiral Patel 	vlan->state = FIP_VLAN_SENT; /* sent now */
436d3c995f1SHiral Patel 	vlan->sol_count = 1;
437d3c995f1SHiral Patel 	spin_unlock_irqrestore(&fnic->vlans_lock, flags);
438d3c995f1SHiral Patel 
439d3c995f1SHiral Patel 	/* start the solicitation */
440d3c995f1SHiral Patel 	fcoe_ctlr_link_up(&fnic->ctlr);
441d3c995f1SHiral Patel 
442d3c995f1SHiral Patel 	sol_time = jiffies + msecs_to_jiffies(FCOE_CTLR_START_DELAY);
443d3c995f1SHiral Patel 	mod_timer(&fnic->fip_timer, round_jiffies(sol_time));
444d3c995f1SHiral Patel }
445d3c995f1SHiral Patel 
446d3c995f1SHiral Patel static int fnic_fcoe_vlan_check(struct fnic *fnic, u16 flag)
447d3c995f1SHiral Patel {
448d3c995f1SHiral Patel 	unsigned long flags;
449d3c995f1SHiral Patel 	struct fcoe_vlan *fvlan;
450d3c995f1SHiral Patel 
451d3c995f1SHiral Patel 	spin_lock_irqsave(&fnic->vlans_lock, flags);
452d3c995f1SHiral Patel 	if (list_empty(&fnic->vlans)) {
453d3c995f1SHiral Patel 		spin_unlock_irqrestore(&fnic->vlans_lock, flags);
454d3c995f1SHiral Patel 		return -EINVAL;
455d3c995f1SHiral Patel 	}
456d3c995f1SHiral Patel 
457d3c995f1SHiral Patel 	fvlan = list_first_entry(&fnic->vlans, struct fcoe_vlan, list);
458d3c995f1SHiral Patel 	if (fvlan->state == FIP_VLAN_USED) {
459d3c995f1SHiral Patel 		spin_unlock_irqrestore(&fnic->vlans_lock, flags);
460d3c995f1SHiral Patel 		return 0;
461d3c995f1SHiral Patel 	}
462d3c995f1SHiral Patel 
463d3c995f1SHiral Patel 	if (fvlan->state == FIP_VLAN_SENT) {
464d3c995f1SHiral Patel 		fvlan->state = FIP_VLAN_USED;
465d3c995f1SHiral Patel 		spin_unlock_irqrestore(&fnic->vlans_lock, flags);
466d3c995f1SHiral Patel 		return 0;
467d3c995f1SHiral Patel 	}
468d3c995f1SHiral Patel 	spin_unlock_irqrestore(&fnic->vlans_lock, flags);
469d3c995f1SHiral Patel 	return -EINVAL;
470d3c995f1SHiral Patel }
471d3c995f1SHiral Patel 
472d3c995f1SHiral Patel static void fnic_event_enq(struct fnic *fnic, enum fnic_evt ev)
473d3c995f1SHiral Patel {
474d3c995f1SHiral Patel 	struct fnic_event *fevt;
475d3c995f1SHiral Patel 	unsigned long flags;
476d3c995f1SHiral Patel 
477d3c995f1SHiral Patel 	fevt = kmalloc(sizeof(*fevt), GFP_ATOMIC);
478d3c995f1SHiral Patel 	if (!fevt)
479d3c995f1SHiral Patel 		return;
480d3c995f1SHiral Patel 
481d3c995f1SHiral Patel 	fevt->fnic = fnic;
482d3c995f1SHiral Patel 	fevt->event = ev;
483d3c995f1SHiral Patel 
484d3c995f1SHiral Patel 	spin_lock_irqsave(&fnic->fnic_lock, flags);
485d3c995f1SHiral Patel 	list_add_tail(&fevt->list, &fnic->evlist);
486d3c995f1SHiral Patel 	spin_unlock_irqrestore(&fnic->fnic_lock, flags);
487d3c995f1SHiral Patel 
488d3c995f1SHiral Patel 	schedule_work(&fnic->event_work);
489d3c995f1SHiral Patel }
490d3c995f1SHiral Patel 
491d3c995f1SHiral Patel static int fnic_fcoe_handle_fip_frame(struct fnic *fnic, struct sk_buff *skb)
492d3c995f1SHiral Patel {
493d3c995f1SHiral Patel 	struct fip_header *fiph;
494d3c995f1SHiral Patel 	int ret = 1;
495d3c995f1SHiral Patel 	u16 op;
496d3c995f1SHiral Patel 	u8 sub;
497d3c995f1SHiral Patel 
498d3c995f1SHiral Patel 	if (!skb || !(skb->data))
499d3c995f1SHiral Patel 		return -1;
500d3c995f1SHiral Patel 
501d3c995f1SHiral Patel 	if (skb_linearize(skb))
502d3c995f1SHiral Patel 		goto drop;
503d3c995f1SHiral Patel 
504d3c995f1SHiral Patel 	fiph = (struct fip_header *)skb->data;
505d3c995f1SHiral Patel 	op = ntohs(fiph->fip_op);
506d3c995f1SHiral Patel 	sub = fiph->fip_subcode;
507d3c995f1SHiral Patel 
508d3c995f1SHiral Patel 	if (FIP_VER_DECAPS(fiph->fip_ver) != FIP_VER)
509d3c995f1SHiral Patel 		goto drop;
510d3c995f1SHiral Patel 
511d3c995f1SHiral Patel 	if (ntohs(fiph->fip_dl_len) * FIP_BPW + sizeof(*fiph) > skb->len)
512d3c995f1SHiral Patel 		goto drop;
513d3c995f1SHiral Patel 
514d3c995f1SHiral Patel 	if (op == FIP_OP_DISC && sub == FIP_SC_ADV) {
515d3c995f1SHiral Patel 		if (fnic_fcoe_vlan_check(fnic, ntohs(fiph->fip_flags)))
516d3c995f1SHiral Patel 			goto drop;
517d3c995f1SHiral Patel 		/* pass it on to fcoe */
518d3c995f1SHiral Patel 		ret = 1;
519d3c995f1SHiral Patel 	} else if (op == FIP_OP_VLAN && sub == FIP_SC_VL_REP) {
520d3c995f1SHiral Patel 		/* set the vlan as used */
521d3c995f1SHiral Patel 		fnic_fcoe_process_vlan_resp(fnic, skb);
522d3c995f1SHiral Patel 		ret = 0;
523d3c995f1SHiral Patel 	} else if (op == FIP_OP_CTRL && sub == FIP_SC_CLR_VLINK) {
524d3c995f1SHiral Patel 		/* received CVL request, restart vlan disc */
525d3c995f1SHiral Patel 		fnic_event_enq(fnic, FNIC_EVT_START_VLAN_DISC);
526d3c995f1SHiral Patel 		/* pass it on to fcoe */
527d3c995f1SHiral Patel 		ret = 1;
528d3c995f1SHiral Patel 	}
529d3c995f1SHiral Patel drop:
530d3c995f1SHiral Patel 	return ret;
531d3c995f1SHiral Patel }
532d3c995f1SHiral Patel 
533d3c995f1SHiral Patel void fnic_handle_fip_frame(struct work_struct *work)
534d3c995f1SHiral Patel {
535d3c995f1SHiral Patel 	struct fnic *fnic = container_of(work, struct fnic, fip_frame_work);
536d3c995f1SHiral Patel 	unsigned long flags;
537d3c995f1SHiral Patel 	struct sk_buff *skb;
538d3c995f1SHiral Patel 	struct ethhdr *eh;
539d3c995f1SHiral Patel 
540d3c995f1SHiral Patel 	while ((skb = skb_dequeue(&fnic->fip_frame_queue))) {
541d3c995f1SHiral Patel 		spin_lock_irqsave(&fnic->fnic_lock, flags);
542d3c995f1SHiral Patel 		if (fnic->stop_rx_link_events) {
543d3c995f1SHiral Patel 			spin_unlock_irqrestore(&fnic->fnic_lock, flags);
544d3c995f1SHiral Patel 			dev_kfree_skb(skb);
545d3c995f1SHiral Patel 			return;
546d3c995f1SHiral Patel 		}
547d3c995f1SHiral Patel 		/*
548d3c995f1SHiral Patel 		 * If we're in a transitional state, just re-queue and return.
549d3c995f1SHiral Patel 		 * The queue will be serviced when we get to a stable state.
550d3c995f1SHiral Patel 		 */
551d3c995f1SHiral Patel 		if (fnic->state != FNIC_IN_FC_MODE &&
552d3c995f1SHiral Patel 		    fnic->state != FNIC_IN_ETH_MODE) {
553d3c995f1SHiral Patel 			skb_queue_head(&fnic->fip_frame_queue, skb);
554d3c995f1SHiral Patel 			spin_unlock_irqrestore(&fnic->fnic_lock, flags);
555d3c995f1SHiral Patel 			return;
556d3c995f1SHiral Patel 		}
557d3c995f1SHiral Patel 		spin_unlock_irqrestore(&fnic->fnic_lock, flags);
558d3c995f1SHiral Patel 		eh = (struct ethhdr *)skb->data;
559d3c995f1SHiral Patel 		if (eh->h_proto == htons(ETH_P_FIP)) {
560d3c995f1SHiral Patel 			skb_pull(skb, sizeof(*eh));
561d3c995f1SHiral Patel 			if (fnic_fcoe_handle_fip_frame(fnic, skb) <= 0) {
562d3c995f1SHiral Patel 				dev_kfree_skb(skb);
563d3c995f1SHiral Patel 				continue;
564d3c995f1SHiral Patel 			}
565d3c995f1SHiral Patel 			/*
566d3c995f1SHiral Patel 			 * If there's FLOGI rejects - clear all
567d3c995f1SHiral Patel 			 * fcf's & restart from scratch
568d3c995f1SHiral Patel 			 */
569d3c995f1SHiral Patel 			if (is_fnic_fip_flogi_reject(&fnic->ctlr, skb)) {
570d3c995f1SHiral Patel 				shost_printk(KERN_INFO, fnic->lport->host,
571d3c995f1SHiral Patel 					  "Trigger a Link down - VLAN Disc\n");
572d3c995f1SHiral Patel 				fcoe_ctlr_link_down(&fnic->ctlr);
573d3c995f1SHiral Patel 				/* start FCoE VLAN discovery */
574d3c995f1SHiral Patel 				fnic_fcoe_send_vlan_req(fnic);
575d3c995f1SHiral Patel 				dev_kfree_skb(skb);
576d3c995f1SHiral Patel 				continue;
577d3c995f1SHiral Patel 			}
578d3c995f1SHiral Patel 			fcoe_ctlr_recv(&fnic->ctlr, skb);
579d3c995f1SHiral Patel 			continue;
580d3c995f1SHiral Patel 		}
581d3c995f1SHiral Patel 	}
582d3c995f1SHiral Patel }
583d3c995f1SHiral Patel 
58478112e55SJoe Eykholt /**
58578112e55SJoe Eykholt  * fnic_import_rq_eth_pkt() - handle received FCoE or FIP frame.
58678112e55SJoe Eykholt  * @fnic:	fnic instance.
58778112e55SJoe Eykholt  * @skb:	Ethernet Frame.
58878112e55SJoe Eykholt  */
58978112e55SJoe Eykholt static inline int fnic_import_rq_eth_pkt(struct fnic *fnic, struct sk_buff *skb)
5905df6d737SAbhijeet Joglekar {
5915df6d737SAbhijeet Joglekar 	struct fc_frame *fp;
5925df6d737SAbhijeet Joglekar 	struct ethhdr *eh;
5935df6d737SAbhijeet Joglekar 	struct fcoe_hdr *fcoe_hdr;
5945df6d737SAbhijeet Joglekar 	struct fcoe_crc_eof *ft;
5955df6d737SAbhijeet Joglekar 
59678112e55SJoe Eykholt 	/*
59778112e55SJoe Eykholt 	 * Undo VLAN encapsulation if present.
59878112e55SJoe Eykholt 	 */
5995df6d737SAbhijeet Joglekar 	eh = (struct ethhdr *)skb->data;
60078112e55SJoe Eykholt 	if (eh->h_proto == htons(ETH_P_8021Q)) {
60178112e55SJoe Eykholt 		memmove((u8 *)eh + VLAN_HLEN, eh, ETH_ALEN * 2);
60278112e55SJoe Eykholt 		eh = (struct ethhdr *)skb_pull(skb, VLAN_HLEN);
60378112e55SJoe Eykholt 		skb_reset_mac_header(skb);
60478112e55SJoe Eykholt 	}
60578112e55SJoe Eykholt 	if (eh->h_proto == htons(ETH_P_FIP)) {
606d7fadce3SHiral Patel 		if (!(fnic->config.flags & VFCF_FIP_CAPABLE)) {
607d7fadce3SHiral Patel 			printk(KERN_ERR "Dropped FIP frame, as firmware "
608d7fadce3SHiral Patel 					"uses non-FIP mode, Enable FIP "
609d7fadce3SHiral Patel 					"using UCSM\n");
610d7fadce3SHiral Patel 			goto drop;
611d7fadce3SHiral Patel 		}
612d3c995f1SHiral Patel 		skb_queue_tail(&fnic->fip_frame_queue, skb);
613d3c995f1SHiral Patel 		queue_work(fnic_fip_queue, &fnic->fip_frame_work);
61478112e55SJoe Eykholt 		return 1;		/* let caller know packet was used */
61578112e55SJoe Eykholt 	}
61678112e55SJoe Eykholt 	if (eh->h_proto != htons(ETH_P_FCOE))
61778112e55SJoe Eykholt 		goto drop;
61878112e55SJoe Eykholt 	skb_set_network_header(skb, sizeof(*eh));
61978112e55SJoe Eykholt 	skb_pull(skb, sizeof(*eh));
6205df6d737SAbhijeet Joglekar 
6215df6d737SAbhijeet Joglekar 	fcoe_hdr = (struct fcoe_hdr *)skb->data;
6225df6d737SAbhijeet Joglekar 	if (FC_FCOE_DECAPS_VER(fcoe_hdr) != FC_FCOE_VER)
62378112e55SJoe Eykholt 		goto drop;
6245df6d737SAbhijeet Joglekar 
6255df6d737SAbhijeet Joglekar 	fp = (struct fc_frame *)skb;
6265df6d737SAbhijeet Joglekar 	fc_frame_init(fp);
6275df6d737SAbhijeet Joglekar 	fr_sof(fp) = fcoe_hdr->fcoe_sof;
6285df6d737SAbhijeet Joglekar 	skb_pull(skb, sizeof(struct fcoe_hdr));
62978112e55SJoe Eykholt 	skb_reset_transport_header(skb);
6305df6d737SAbhijeet Joglekar 
63178112e55SJoe Eykholt 	ft = (struct fcoe_crc_eof *)(skb->data + skb->len - sizeof(*ft));
6325df6d737SAbhijeet Joglekar 	fr_eof(fp) = ft->fcoe_eof;
63378112e55SJoe Eykholt 	skb_trim(skb, skb->len - sizeof(*ft));
6345df6d737SAbhijeet Joglekar 	return 0;
63578112e55SJoe Eykholt drop:
63678112e55SJoe Eykholt 	dev_kfree_skb_irq(skb);
63778112e55SJoe Eykholt 	return -1;
6385df6d737SAbhijeet Joglekar }
6395df6d737SAbhijeet Joglekar 
64078112e55SJoe Eykholt /**
64178112e55SJoe Eykholt  * fnic_update_mac_locked() - set data MAC address and filters.
64278112e55SJoe Eykholt  * @fnic:	fnic instance.
64378112e55SJoe Eykholt  * @new:	newly-assigned FCoE MAC address.
64478112e55SJoe Eykholt  *
64578112e55SJoe Eykholt  * Called with the fnic lock held.
64678112e55SJoe Eykholt  */
64778112e55SJoe Eykholt void fnic_update_mac_locked(struct fnic *fnic, u8 *new)
6485df6d737SAbhijeet Joglekar {
64978112e55SJoe Eykholt 	u8 *ctl = fnic->ctlr.ctl_src_addr;
65078112e55SJoe Eykholt 	u8 *data = fnic->data_src_addr;
6515df6d737SAbhijeet Joglekar 
65278112e55SJoe Eykholt 	if (is_zero_ether_addr(new))
65378112e55SJoe Eykholt 		new = ctl;
654*6942df7fSJoe Perches 	if (ether_addr_equal(data, new))
65578112e55SJoe Eykholt 		return;
65678112e55SJoe Eykholt 	FNIC_FCS_DBG(KERN_DEBUG, fnic->lport->host, "update_mac %pM\n", new);
657*6942df7fSJoe Perches 	if (!is_zero_ether_addr(data) && !ether_addr_equal(data, ctl))
65878112e55SJoe Eykholt 		vnic_dev_del_addr(fnic->vdev, data);
65978112e55SJoe Eykholt 	memcpy(data, new, ETH_ALEN);
660*6942df7fSJoe Perches 	if (!ether_addr_equal(new, ctl))
66178112e55SJoe Eykholt 		vnic_dev_add_addr(fnic->vdev, new);
6625df6d737SAbhijeet Joglekar }
6635df6d737SAbhijeet Joglekar 
66478112e55SJoe Eykholt /**
66578112e55SJoe Eykholt  * fnic_update_mac() - set data MAC address and filters.
66678112e55SJoe Eykholt  * @lport:	local port.
66778112e55SJoe Eykholt  * @new:	newly-assigned FCoE MAC address.
6685df6d737SAbhijeet Joglekar  */
66978112e55SJoe Eykholt void fnic_update_mac(struct fc_lport *lport, u8 *new)
67078112e55SJoe Eykholt {
67178112e55SJoe Eykholt 	struct fnic *fnic = lport_priv(lport);
6725df6d737SAbhijeet Joglekar 
67378112e55SJoe Eykholt 	spin_lock_irq(&fnic->fnic_lock);
67478112e55SJoe Eykholt 	fnic_update_mac_locked(fnic, new);
67578112e55SJoe Eykholt 	spin_unlock_irq(&fnic->fnic_lock);
6765df6d737SAbhijeet Joglekar }
6775df6d737SAbhijeet Joglekar 
67878112e55SJoe Eykholt /**
67978112e55SJoe Eykholt  * fnic_set_port_id() - set the port_ID after successful FLOGI.
68078112e55SJoe Eykholt  * @lport:	local port.
68178112e55SJoe Eykholt  * @port_id:	assigned FC_ID.
68278112e55SJoe Eykholt  * @fp:		received frame containing the FLOGI accept or NULL.
68378112e55SJoe Eykholt  *
68478112e55SJoe Eykholt  * This is called from libfc when a new FC_ID has been assigned.
68578112e55SJoe Eykholt  * This causes us to reset the firmware to FC_MODE and setup the new MAC
68678112e55SJoe Eykholt  * address and FC_ID.
68778112e55SJoe Eykholt  *
68878112e55SJoe Eykholt  * It is also called with FC_ID 0 when we're logged off.
68978112e55SJoe Eykholt  *
69078112e55SJoe Eykholt  * If the FC_ID is due to point-to-point, fp may be NULL.
6915df6d737SAbhijeet Joglekar  */
69278112e55SJoe Eykholt void fnic_set_port_id(struct fc_lport *lport, u32 port_id, struct fc_frame *fp)
69378112e55SJoe Eykholt {
69478112e55SJoe Eykholt 	struct fnic *fnic = lport_priv(lport);
69578112e55SJoe Eykholt 	u8 *mac;
69678112e55SJoe Eykholt 	int ret;
6975df6d737SAbhijeet Joglekar 
69878112e55SJoe Eykholt 	FNIC_FCS_DBG(KERN_DEBUG, lport->host, "set port_id %x fp %p\n",
69978112e55SJoe Eykholt 		     port_id, fp);
7005df6d737SAbhijeet Joglekar 
70178112e55SJoe Eykholt 	/*
70278112e55SJoe Eykholt 	 * If we're clearing the FC_ID, change to use the ctl_src_addr.
70378112e55SJoe Eykholt 	 * Set ethernet mode to send FLOGI.
70478112e55SJoe Eykholt 	 */
70578112e55SJoe Eykholt 	if (!port_id) {
70678112e55SJoe Eykholt 		fnic_update_mac(lport, fnic->ctlr.ctl_src_addr);
70778112e55SJoe Eykholt 		fnic_set_eth_mode(fnic);
70878112e55SJoe Eykholt 		return;
70978112e55SJoe Eykholt 	}
71078112e55SJoe Eykholt 
71178112e55SJoe Eykholt 	if (fp) {
71278112e55SJoe Eykholt 		mac = fr_cb(fp)->granted_mac;
71378112e55SJoe Eykholt 		if (is_zero_ether_addr(mac)) {
71478112e55SJoe Eykholt 			/* non-FIP - FLOGI already accepted - ignore return */
71578112e55SJoe Eykholt 			fcoe_ctlr_recv_flogi(&fnic->ctlr, lport, fp);
71678112e55SJoe Eykholt 		}
71778112e55SJoe Eykholt 		fnic_update_mac(lport, mac);
71878112e55SJoe Eykholt 	}
71978112e55SJoe Eykholt 
72078112e55SJoe Eykholt 	/* Change state to reflect transition to FC mode */
72178112e55SJoe Eykholt 	spin_lock_irq(&fnic->fnic_lock);
72278112e55SJoe Eykholt 	if (fnic->state == FNIC_IN_ETH_MODE || fnic->state == FNIC_IN_FC_MODE)
7235df6d737SAbhijeet Joglekar 		fnic->state = FNIC_IN_ETH_TRANS_FC_MODE;
72478112e55SJoe Eykholt 	else {
7255df6d737SAbhijeet Joglekar 		FNIC_FCS_DBG(KERN_DEBUG, fnic->lport->host,
7265df6d737SAbhijeet Joglekar 			     "Unexpected fnic state %s while"
7275df6d737SAbhijeet Joglekar 			     " processing flogi resp\n",
7285df6d737SAbhijeet Joglekar 			     fnic_state_to_str(fnic->state));
72978112e55SJoe Eykholt 		spin_unlock_irq(&fnic->fnic_lock);
73078112e55SJoe Eykholt 		return;
7315df6d737SAbhijeet Joglekar 	}
73278112e55SJoe Eykholt 	spin_unlock_irq(&fnic->fnic_lock);
7335df6d737SAbhijeet Joglekar 
7345df6d737SAbhijeet Joglekar 	/*
73578112e55SJoe Eykholt 	 * Send FLOGI registration to firmware to set up FC mode.
73678112e55SJoe Eykholt 	 * The new address will be set up when registration completes.
7375df6d737SAbhijeet Joglekar 	 */
73878112e55SJoe Eykholt 	ret = fnic_flogi_reg_handler(fnic, port_id);
7395df6d737SAbhijeet Joglekar 
7405df6d737SAbhijeet Joglekar 	if (ret < 0) {
74178112e55SJoe Eykholt 		spin_lock_irq(&fnic->fnic_lock);
7425df6d737SAbhijeet Joglekar 		if (fnic->state == FNIC_IN_ETH_TRANS_FC_MODE)
7435df6d737SAbhijeet Joglekar 			fnic->state = FNIC_IN_ETH_MODE;
74478112e55SJoe Eykholt 		spin_unlock_irq(&fnic->fnic_lock);
7455df6d737SAbhijeet Joglekar 	}
7465df6d737SAbhijeet Joglekar }
7475df6d737SAbhijeet Joglekar 
7485df6d737SAbhijeet Joglekar static void fnic_rq_cmpl_frame_recv(struct vnic_rq *rq, struct cq_desc
7495df6d737SAbhijeet Joglekar 				    *cq_desc, struct vnic_rq_buf *buf,
7505df6d737SAbhijeet Joglekar 				    int skipped __attribute__((unused)),
7515df6d737SAbhijeet Joglekar 				    void *opaque)
7525df6d737SAbhijeet Joglekar {
7535df6d737SAbhijeet Joglekar 	struct fnic *fnic = vnic_dev_priv(rq->vdev);
7545df6d737SAbhijeet Joglekar 	struct sk_buff *skb;
7555df6d737SAbhijeet Joglekar 	struct fc_frame *fp;
7565df6d737SAbhijeet Joglekar 	unsigned int eth_hdrs_stripped;
7575df6d737SAbhijeet Joglekar 	u8 type, color, eop, sop, ingress_port, vlan_stripped;
7585df6d737SAbhijeet Joglekar 	u8 fcoe = 0, fcoe_sof, fcoe_eof;
7595df6d737SAbhijeet Joglekar 	u8 fcoe_fc_crc_ok = 1, fcoe_enc_error = 0;
7605df6d737SAbhijeet Joglekar 	u8 tcp_udp_csum_ok, udp, tcp, ipv4_csum_ok;
7615df6d737SAbhijeet Joglekar 	u8 ipv6, ipv4, ipv4_fragment, rss_type, csum_not_calc;
7625df6d737SAbhijeet Joglekar 	u8 fcs_ok = 1, packet_error = 0;
7635df6d737SAbhijeet Joglekar 	u16 q_number, completed_index, bytes_written = 0, vlan, checksum;
7645df6d737SAbhijeet Joglekar 	u32 rss_hash;
7655df6d737SAbhijeet Joglekar 	u16 exchange_id, tmpl;
7665df6d737SAbhijeet Joglekar 	u8 sof = 0;
7675df6d737SAbhijeet Joglekar 	u8 eof = 0;
7685df6d737SAbhijeet Joglekar 	u32 fcp_bytes_written = 0;
7695df6d737SAbhijeet Joglekar 	unsigned long flags;
7705df6d737SAbhijeet Joglekar 
7715df6d737SAbhijeet Joglekar 	pci_unmap_single(fnic->pdev, buf->dma_addr, buf->len,
7725df6d737SAbhijeet Joglekar 			 PCI_DMA_FROMDEVICE);
7735df6d737SAbhijeet Joglekar 	skb = buf->os_buf;
77478112e55SJoe Eykholt 	fp = (struct fc_frame *)skb;
7755df6d737SAbhijeet Joglekar 	buf->os_buf = NULL;
7765df6d737SAbhijeet Joglekar 
7775df6d737SAbhijeet Joglekar 	cq_desc_dec(cq_desc, &type, &color, &q_number, &completed_index);
7785df6d737SAbhijeet Joglekar 	if (type == CQ_DESC_TYPE_RQ_FCP) {
7795df6d737SAbhijeet Joglekar 		cq_fcp_rq_desc_dec((struct cq_fcp_rq_desc *)cq_desc,
7805df6d737SAbhijeet Joglekar 				   &type, &color, &q_number, &completed_index,
7815df6d737SAbhijeet Joglekar 				   &eop, &sop, &fcoe_fc_crc_ok, &exchange_id,
7825df6d737SAbhijeet Joglekar 				   &tmpl, &fcp_bytes_written, &sof, &eof,
7835df6d737SAbhijeet Joglekar 				   &ingress_port, &packet_error,
7845df6d737SAbhijeet Joglekar 				   &fcoe_enc_error, &fcs_ok, &vlan_stripped,
7855df6d737SAbhijeet Joglekar 				   &vlan);
7865df6d737SAbhijeet Joglekar 		eth_hdrs_stripped = 1;
78778112e55SJoe Eykholt 		skb_trim(skb, fcp_bytes_written);
78878112e55SJoe Eykholt 		fr_sof(fp) = sof;
78978112e55SJoe Eykholt 		fr_eof(fp) = eof;
7905df6d737SAbhijeet Joglekar 
7915df6d737SAbhijeet Joglekar 	} else if (type == CQ_DESC_TYPE_RQ_ENET) {
7925df6d737SAbhijeet Joglekar 		cq_enet_rq_desc_dec((struct cq_enet_rq_desc *)cq_desc,
7935df6d737SAbhijeet Joglekar 				    &type, &color, &q_number, &completed_index,
7945df6d737SAbhijeet Joglekar 				    &ingress_port, &fcoe, &eop, &sop,
7955df6d737SAbhijeet Joglekar 				    &rss_type, &csum_not_calc, &rss_hash,
7965df6d737SAbhijeet Joglekar 				    &bytes_written, &packet_error,
7975df6d737SAbhijeet Joglekar 				    &vlan_stripped, &vlan, &checksum,
7985df6d737SAbhijeet Joglekar 				    &fcoe_sof, &fcoe_fc_crc_ok,
7995df6d737SAbhijeet Joglekar 				    &fcoe_enc_error, &fcoe_eof,
8005df6d737SAbhijeet Joglekar 				    &tcp_udp_csum_ok, &udp, &tcp,
8015df6d737SAbhijeet Joglekar 				    &ipv4_csum_ok, &ipv6, &ipv4,
8025df6d737SAbhijeet Joglekar 				    &ipv4_fragment, &fcs_ok);
8035df6d737SAbhijeet Joglekar 		eth_hdrs_stripped = 0;
80478112e55SJoe Eykholt 		skb_trim(skb, bytes_written);
80578112e55SJoe Eykholt 		if (!fcs_ok) {
80678112e55SJoe Eykholt 			FNIC_FCS_DBG(KERN_DEBUG, fnic->lport->host,
80778112e55SJoe Eykholt 				     "fcs error.  dropping packet.\n");
80878112e55SJoe Eykholt 			goto drop;
80978112e55SJoe Eykholt 		}
81078112e55SJoe Eykholt 		if (fnic_import_rq_eth_pkt(fnic, skb))
81178112e55SJoe Eykholt 			return;
8125df6d737SAbhijeet Joglekar 
8135df6d737SAbhijeet Joglekar 	} else {
8145df6d737SAbhijeet Joglekar 		/* wrong CQ type*/
8155df6d737SAbhijeet Joglekar 		shost_printk(KERN_ERR, fnic->lport->host,
8165df6d737SAbhijeet Joglekar 			     "fnic rq_cmpl wrong cq type x%x\n", type);
8175df6d737SAbhijeet Joglekar 		goto drop;
8185df6d737SAbhijeet Joglekar 	}
8195df6d737SAbhijeet Joglekar 
8205df6d737SAbhijeet Joglekar 	if (!fcs_ok || packet_error || !fcoe_fc_crc_ok || fcoe_enc_error) {
8215df6d737SAbhijeet Joglekar 		FNIC_FCS_DBG(KERN_DEBUG, fnic->lport->host,
8225df6d737SAbhijeet Joglekar 			     "fnic rq_cmpl fcoe x%x fcsok x%x"
8235df6d737SAbhijeet Joglekar 			     " pkterr x%x fcoe_fc_crc_ok x%x, fcoe_enc_err"
8245df6d737SAbhijeet Joglekar 			     " x%x\n",
8255df6d737SAbhijeet Joglekar 			     fcoe, fcs_ok, packet_error,
8265df6d737SAbhijeet Joglekar 			     fcoe_fc_crc_ok, fcoe_enc_error);
8275df6d737SAbhijeet Joglekar 		goto drop;
8285df6d737SAbhijeet Joglekar 	}
8295df6d737SAbhijeet Joglekar 
8305df6d737SAbhijeet Joglekar 	spin_lock_irqsave(&fnic->fnic_lock, flags);
8315df6d737SAbhijeet Joglekar 	if (fnic->stop_rx_link_events) {
8325df6d737SAbhijeet Joglekar 		spin_unlock_irqrestore(&fnic->fnic_lock, flags);
8335df6d737SAbhijeet Joglekar 		goto drop;
8345df6d737SAbhijeet Joglekar 	}
8355df6d737SAbhijeet Joglekar 	fr_dev(fp) = fnic->lport;
8365df6d737SAbhijeet Joglekar 	spin_unlock_irqrestore(&fnic->fnic_lock, flags);
8375df6d737SAbhijeet Joglekar 
8385df6d737SAbhijeet Joglekar 	skb_queue_tail(&fnic->frame_queue, skb);
8395df6d737SAbhijeet Joglekar 	queue_work(fnic_event_queue, &fnic->frame_work);
8405df6d737SAbhijeet Joglekar 
8415df6d737SAbhijeet Joglekar 	return;
8425df6d737SAbhijeet Joglekar drop:
8435df6d737SAbhijeet Joglekar 	dev_kfree_skb_irq(skb);
8445df6d737SAbhijeet Joglekar }
8455df6d737SAbhijeet Joglekar 
8465df6d737SAbhijeet Joglekar static int fnic_rq_cmpl_handler_cont(struct vnic_dev *vdev,
8475df6d737SAbhijeet Joglekar 				     struct cq_desc *cq_desc, u8 type,
8485df6d737SAbhijeet Joglekar 				     u16 q_number, u16 completed_index,
8495df6d737SAbhijeet Joglekar 				     void *opaque)
8505df6d737SAbhijeet Joglekar {
8515df6d737SAbhijeet Joglekar 	struct fnic *fnic = vnic_dev_priv(vdev);
8525df6d737SAbhijeet Joglekar 
8535df6d737SAbhijeet Joglekar 	vnic_rq_service(&fnic->rq[q_number], cq_desc, completed_index,
8545df6d737SAbhijeet Joglekar 			VNIC_RQ_RETURN_DESC, fnic_rq_cmpl_frame_recv,
8555df6d737SAbhijeet Joglekar 			NULL);
8565df6d737SAbhijeet Joglekar 	return 0;
8575df6d737SAbhijeet Joglekar }
8585df6d737SAbhijeet Joglekar 
8595df6d737SAbhijeet Joglekar int fnic_rq_cmpl_handler(struct fnic *fnic, int rq_work_to_do)
8605df6d737SAbhijeet Joglekar {
8615df6d737SAbhijeet Joglekar 	unsigned int tot_rq_work_done = 0, cur_work_done;
8625df6d737SAbhijeet Joglekar 	unsigned int i;
8635df6d737SAbhijeet Joglekar 	int err;
8645df6d737SAbhijeet Joglekar 
8655df6d737SAbhijeet Joglekar 	for (i = 0; i < fnic->rq_count; i++) {
8665df6d737SAbhijeet Joglekar 		cur_work_done = vnic_cq_service(&fnic->cq[i], rq_work_to_do,
8675df6d737SAbhijeet Joglekar 						fnic_rq_cmpl_handler_cont,
8685df6d737SAbhijeet Joglekar 						NULL);
8695df6d737SAbhijeet Joglekar 		if (cur_work_done) {
8705df6d737SAbhijeet Joglekar 			err = vnic_rq_fill(&fnic->rq[i], fnic_alloc_rq_frame);
8715df6d737SAbhijeet Joglekar 			if (err)
8725df6d737SAbhijeet Joglekar 				shost_printk(KERN_ERR, fnic->lport->host,
87325985edcSLucas De Marchi 					     "fnic_alloc_rq_frame can't alloc"
8745df6d737SAbhijeet Joglekar 					     " frame\n");
8755df6d737SAbhijeet Joglekar 		}
8765df6d737SAbhijeet Joglekar 		tot_rq_work_done += cur_work_done;
8775df6d737SAbhijeet Joglekar 	}
8785df6d737SAbhijeet Joglekar 
8795df6d737SAbhijeet Joglekar 	return tot_rq_work_done;
8805df6d737SAbhijeet Joglekar }
8815df6d737SAbhijeet Joglekar 
8825df6d737SAbhijeet Joglekar /*
8835df6d737SAbhijeet Joglekar  * This function is called once at init time to allocate and fill RQ
8845df6d737SAbhijeet Joglekar  * buffers. Subsequently, it is called in the interrupt context after RQ
8855df6d737SAbhijeet Joglekar  * buffer processing to replenish the buffers in the RQ
8865df6d737SAbhijeet Joglekar  */
8875df6d737SAbhijeet Joglekar int fnic_alloc_rq_frame(struct vnic_rq *rq)
8885df6d737SAbhijeet Joglekar {
8895df6d737SAbhijeet Joglekar 	struct fnic *fnic = vnic_dev_priv(rq->vdev);
8905df6d737SAbhijeet Joglekar 	struct sk_buff *skb;
8915df6d737SAbhijeet Joglekar 	u16 len;
8925df6d737SAbhijeet Joglekar 	dma_addr_t pa;
8935df6d737SAbhijeet Joglekar 
8945df6d737SAbhijeet Joglekar 	len = FC_FRAME_HEADROOM + FC_MAX_FRAME + FC_FRAME_TAILROOM;
8955df6d737SAbhijeet Joglekar 	skb = dev_alloc_skb(len);
8965df6d737SAbhijeet Joglekar 	if (!skb) {
8975df6d737SAbhijeet Joglekar 		FNIC_FCS_DBG(KERN_DEBUG, fnic->lport->host,
8985df6d737SAbhijeet Joglekar 			     "Unable to allocate RQ sk_buff\n");
8995df6d737SAbhijeet Joglekar 		return -ENOMEM;
9005df6d737SAbhijeet Joglekar 	}
9015df6d737SAbhijeet Joglekar 	skb_reset_mac_header(skb);
9025df6d737SAbhijeet Joglekar 	skb_reset_transport_header(skb);
9035df6d737SAbhijeet Joglekar 	skb_reset_network_header(skb);
9045df6d737SAbhijeet Joglekar 	skb_put(skb, len);
9055df6d737SAbhijeet Joglekar 	pa = pci_map_single(fnic->pdev, skb->data, len, PCI_DMA_FROMDEVICE);
9065df6d737SAbhijeet Joglekar 	fnic_queue_rq_desc(rq, skb, pa, len);
9075df6d737SAbhijeet Joglekar 	return 0;
9085df6d737SAbhijeet Joglekar }
9095df6d737SAbhijeet Joglekar 
9105df6d737SAbhijeet Joglekar void fnic_free_rq_buf(struct vnic_rq *rq, struct vnic_rq_buf *buf)
9115df6d737SAbhijeet Joglekar {
9125df6d737SAbhijeet Joglekar 	struct fc_frame *fp = buf->os_buf;
9135df6d737SAbhijeet Joglekar 	struct fnic *fnic = vnic_dev_priv(rq->vdev);
9145df6d737SAbhijeet Joglekar 
9155df6d737SAbhijeet Joglekar 	pci_unmap_single(fnic->pdev, buf->dma_addr, buf->len,
9165df6d737SAbhijeet Joglekar 			 PCI_DMA_FROMDEVICE);
9175df6d737SAbhijeet Joglekar 
9185df6d737SAbhijeet Joglekar 	dev_kfree_skb(fp_skb(fp));
9195df6d737SAbhijeet Joglekar 	buf->os_buf = NULL;
9205df6d737SAbhijeet Joglekar }
9215df6d737SAbhijeet Joglekar 
92278112e55SJoe Eykholt /**
92378112e55SJoe Eykholt  * fnic_eth_send() - Send Ethernet frame.
92478112e55SJoe Eykholt  * @fip:	fcoe_ctlr instance.
92578112e55SJoe Eykholt  * @skb:	Ethernet Frame, FIP, without VLAN encapsulation.
92678112e55SJoe Eykholt  */
92778112e55SJoe Eykholt void fnic_eth_send(struct fcoe_ctlr *fip, struct sk_buff *skb)
9285df6d737SAbhijeet Joglekar {
92978112e55SJoe Eykholt 	struct fnic *fnic = fnic_from_ctlr(fip);
93078112e55SJoe Eykholt 	struct vnic_wq *wq = &fnic->wq[0];
93178112e55SJoe Eykholt 	dma_addr_t pa;
93278112e55SJoe Eykholt 	struct ethhdr *eth_hdr;
93378112e55SJoe Eykholt 	struct vlan_ethhdr *vlan_hdr;
93478112e55SJoe Eykholt 	unsigned long flags;
93578112e55SJoe Eykholt 
93678112e55SJoe Eykholt 	if (!fnic->vlan_hw_insert) {
93778112e55SJoe Eykholt 		eth_hdr = (struct ethhdr *)skb_mac_header(skb);
93878112e55SJoe Eykholt 		vlan_hdr = (struct vlan_ethhdr *)skb_push(skb,
93978112e55SJoe Eykholt 				sizeof(*vlan_hdr) - sizeof(*eth_hdr));
94078112e55SJoe Eykholt 		memcpy(vlan_hdr, eth_hdr, 2 * ETH_ALEN);
94178112e55SJoe Eykholt 		vlan_hdr->h_vlan_proto = htons(ETH_P_8021Q);
94278112e55SJoe Eykholt 		vlan_hdr->h_vlan_encapsulated_proto = eth_hdr->h_proto;
94378112e55SJoe Eykholt 		vlan_hdr->h_vlan_TCI = htons(fnic->vlan_id);
9445df6d737SAbhijeet Joglekar 	}
9455df6d737SAbhijeet Joglekar 
94678112e55SJoe Eykholt 	pa = pci_map_single(fnic->pdev, skb->data, skb->len, PCI_DMA_TODEVICE);
94778112e55SJoe Eykholt 
94878112e55SJoe Eykholt 	spin_lock_irqsave(&fnic->wq_lock[0], flags);
94978112e55SJoe Eykholt 	if (!vnic_wq_desc_avail(wq)) {
95078112e55SJoe Eykholt 		pci_unmap_single(fnic->pdev, pa, skb->len, PCI_DMA_TODEVICE);
95178112e55SJoe Eykholt 		spin_unlock_irqrestore(&fnic->wq_lock[0], flags);
95278112e55SJoe Eykholt 		kfree_skb(skb);
95378112e55SJoe Eykholt 		return;
95478112e55SJoe Eykholt 	}
95578112e55SJoe Eykholt 
95678112e55SJoe Eykholt 	fnic_queue_wq_eth_desc(wq, skb, pa, skb->len,
957c0773b7cSHiral Patel 			       0 /* hw inserts cos value */,
958c0773b7cSHiral Patel 			       fnic->vlan_id, 1);
95978112e55SJoe Eykholt 	spin_unlock_irqrestore(&fnic->wq_lock[0], flags);
96078112e55SJoe Eykholt }
96178112e55SJoe Eykholt 
96278112e55SJoe Eykholt /*
96378112e55SJoe Eykholt  * Send FC frame.
96478112e55SJoe Eykholt  */
96578112e55SJoe Eykholt static int fnic_send_frame(struct fnic *fnic, struct fc_frame *fp)
9665df6d737SAbhijeet Joglekar {
9675df6d737SAbhijeet Joglekar 	struct vnic_wq *wq = &fnic->wq[0];
9685df6d737SAbhijeet Joglekar 	struct sk_buff *skb;
9695df6d737SAbhijeet Joglekar 	dma_addr_t pa;
9705df6d737SAbhijeet Joglekar 	struct ethhdr *eth_hdr;
9715df6d737SAbhijeet Joglekar 	struct vlan_ethhdr *vlan_hdr;
9725df6d737SAbhijeet Joglekar 	struct fcoe_hdr *fcoe_hdr;
9735df6d737SAbhijeet Joglekar 	struct fc_frame_header *fh;
9745df6d737SAbhijeet Joglekar 	u32 tot_len, eth_hdr_len;
9755df6d737SAbhijeet Joglekar 	int ret = 0;
9765df6d737SAbhijeet Joglekar 	unsigned long flags;
9775df6d737SAbhijeet Joglekar 
9785df6d737SAbhijeet Joglekar 	fh = fc_frame_header_get(fp);
9795df6d737SAbhijeet Joglekar 	skb = fp_skb(fp);
9805df6d737SAbhijeet Joglekar 
98178112e55SJoe Eykholt 	if (unlikely(fh->fh_r_ctl == FC_RCTL_ELS_REQ) &&
98278112e55SJoe Eykholt 	    fcoe_ctlr_els_send(&fnic->ctlr, fnic->lport, skb))
98378112e55SJoe Eykholt 		return 0;
98478112e55SJoe Eykholt 
9855df6d737SAbhijeet Joglekar 	if (!fnic->vlan_hw_insert) {
9865df6d737SAbhijeet Joglekar 		eth_hdr_len = sizeof(*vlan_hdr) + sizeof(*fcoe_hdr);
9875df6d737SAbhijeet Joglekar 		vlan_hdr = (struct vlan_ethhdr *)skb_push(skb, eth_hdr_len);
9885df6d737SAbhijeet Joglekar 		eth_hdr = (struct ethhdr *)vlan_hdr;
9895df6d737SAbhijeet Joglekar 		vlan_hdr->h_vlan_proto = htons(ETH_P_8021Q);
9905df6d737SAbhijeet Joglekar 		vlan_hdr->h_vlan_encapsulated_proto = htons(ETH_P_FCOE);
9915df6d737SAbhijeet Joglekar 		vlan_hdr->h_vlan_TCI = htons(fnic->vlan_id);
9925df6d737SAbhijeet Joglekar 		fcoe_hdr = (struct fcoe_hdr *)(vlan_hdr + 1);
9935df6d737SAbhijeet Joglekar 	} else {
9945df6d737SAbhijeet Joglekar 		eth_hdr_len = sizeof(*eth_hdr) + sizeof(*fcoe_hdr);
9955df6d737SAbhijeet Joglekar 		eth_hdr = (struct ethhdr *)skb_push(skb, eth_hdr_len);
9965df6d737SAbhijeet Joglekar 		eth_hdr->h_proto = htons(ETH_P_FCOE);
9975df6d737SAbhijeet Joglekar 		fcoe_hdr = (struct fcoe_hdr *)(eth_hdr + 1);
9985df6d737SAbhijeet Joglekar 	}
9995df6d737SAbhijeet Joglekar 
100078112e55SJoe Eykholt 	if (fnic->ctlr.map_dest)
10015df6d737SAbhijeet Joglekar 		fc_fcoe_set_mac(eth_hdr->h_dest, fh->fh_d_id);
10025df6d737SAbhijeet Joglekar 	else
100378112e55SJoe Eykholt 		memcpy(eth_hdr->h_dest, fnic->ctlr.dest_addr, ETH_ALEN);
10045df6d737SAbhijeet Joglekar 	memcpy(eth_hdr->h_source, fnic->data_src_addr, ETH_ALEN);
10055df6d737SAbhijeet Joglekar 
10065df6d737SAbhijeet Joglekar 	tot_len = skb->len;
10075df6d737SAbhijeet Joglekar 	BUG_ON(tot_len % 4);
10085df6d737SAbhijeet Joglekar 
10095df6d737SAbhijeet Joglekar 	memset(fcoe_hdr, 0, sizeof(*fcoe_hdr));
10105df6d737SAbhijeet Joglekar 	fcoe_hdr->fcoe_sof = fr_sof(fp);
10115df6d737SAbhijeet Joglekar 	if (FC_FCOE_VER)
10125df6d737SAbhijeet Joglekar 		FC_FCOE_ENCAPS_VER(fcoe_hdr, FC_FCOE_VER);
10135df6d737SAbhijeet Joglekar 
10145df6d737SAbhijeet Joglekar 	pa = pci_map_single(fnic->pdev, eth_hdr, tot_len, PCI_DMA_TODEVICE);
10155df6d737SAbhijeet Joglekar 
10165df6d737SAbhijeet Joglekar 	spin_lock_irqsave(&fnic->wq_lock[0], flags);
10175df6d737SAbhijeet Joglekar 
10185df6d737SAbhijeet Joglekar 	if (!vnic_wq_desc_avail(wq)) {
10195df6d737SAbhijeet Joglekar 		pci_unmap_single(fnic->pdev, pa,
10205df6d737SAbhijeet Joglekar 				 tot_len, PCI_DMA_TODEVICE);
10215df6d737SAbhijeet Joglekar 		ret = -1;
10225df6d737SAbhijeet Joglekar 		goto fnic_send_frame_end;
10235df6d737SAbhijeet Joglekar 	}
10245df6d737SAbhijeet Joglekar 
10255df6d737SAbhijeet Joglekar 	fnic_queue_wq_desc(wq, skb, pa, tot_len, fr_eof(fp),
1026c0773b7cSHiral Patel 			   0 /* hw inserts cos value */,
1027c0773b7cSHiral Patel 			   fnic->vlan_id, 1, 1, 1);
10285df6d737SAbhijeet Joglekar fnic_send_frame_end:
10295df6d737SAbhijeet Joglekar 	spin_unlock_irqrestore(&fnic->wq_lock[0], flags);
10305df6d737SAbhijeet Joglekar 
10315df6d737SAbhijeet Joglekar 	if (ret)
10325df6d737SAbhijeet Joglekar 		dev_kfree_skb_any(fp_skb(fp));
10335df6d737SAbhijeet Joglekar 
10345df6d737SAbhijeet Joglekar 	return ret;
10355df6d737SAbhijeet Joglekar }
10365df6d737SAbhijeet Joglekar 
10375df6d737SAbhijeet Joglekar /*
10385df6d737SAbhijeet Joglekar  * fnic_send
10395df6d737SAbhijeet Joglekar  * Routine to send a raw frame
10405df6d737SAbhijeet Joglekar  */
10415df6d737SAbhijeet Joglekar int fnic_send(struct fc_lport *lp, struct fc_frame *fp)
10425df6d737SAbhijeet Joglekar {
10435df6d737SAbhijeet Joglekar 	struct fnic *fnic = lport_priv(lp);
10445df6d737SAbhijeet Joglekar 	unsigned long flags;
10455df6d737SAbhijeet Joglekar 
10465df6d737SAbhijeet Joglekar 	if (fnic->in_remove) {
10475df6d737SAbhijeet Joglekar 		dev_kfree_skb(fp_skb(fp));
104878112e55SJoe Eykholt 		return -1;
10495df6d737SAbhijeet Joglekar 	}
10505df6d737SAbhijeet Joglekar 
105178112e55SJoe Eykholt 	/*
105278112e55SJoe Eykholt 	 * Queue frame if in a transitional state.
105378112e55SJoe Eykholt 	 * This occurs while registering the Port_ID / MAC address after FLOGI.
105478112e55SJoe Eykholt 	 */
105578112e55SJoe Eykholt 	spin_lock_irqsave(&fnic->fnic_lock, flags);
105678112e55SJoe Eykholt 	if (fnic->state != FNIC_IN_FC_MODE && fnic->state != FNIC_IN_ETH_MODE) {
105778112e55SJoe Eykholt 		skb_queue_tail(&fnic->tx_queue, fp_skb(fp));
105878112e55SJoe Eykholt 		spin_unlock_irqrestore(&fnic->fnic_lock, flags);
105978112e55SJoe Eykholt 		return 0;
106078112e55SJoe Eykholt 	}
106178112e55SJoe Eykholt 	spin_unlock_irqrestore(&fnic->fnic_lock, flags);
10625df6d737SAbhijeet Joglekar 
106378112e55SJoe Eykholt 	return fnic_send_frame(fnic, fp);
106478112e55SJoe Eykholt }
106578112e55SJoe Eykholt 
106678112e55SJoe Eykholt /**
106778112e55SJoe Eykholt  * fnic_flush_tx() - send queued frames.
106878112e55SJoe Eykholt  * @fnic: fnic device
106978112e55SJoe Eykholt  *
107078112e55SJoe Eykholt  * Send frames that were waiting to go out in FC or Ethernet mode.
107178112e55SJoe Eykholt  * Whenever changing modes we purge queued frames, so these frames should
107278112e55SJoe Eykholt  * be queued for the stable mode that we're in, either FC or Ethernet.
107378112e55SJoe Eykholt  *
107478112e55SJoe Eykholt  * Called without fnic_lock held.
107578112e55SJoe Eykholt  */
107678112e55SJoe Eykholt void fnic_flush_tx(struct fnic *fnic)
107778112e55SJoe Eykholt {
107878112e55SJoe Eykholt 	struct sk_buff *skb;
107978112e55SJoe Eykholt 	struct fc_frame *fp;
108078112e55SJoe Eykholt 
1081d9e9ab56SBrian Uchino 	while ((skb = skb_dequeue(&fnic->tx_queue))) {
108278112e55SJoe Eykholt 		fp = (struct fc_frame *)skb;
108378112e55SJoe Eykholt 		fnic_send_frame(fnic, fp);
108478112e55SJoe Eykholt 	}
108578112e55SJoe Eykholt }
108678112e55SJoe Eykholt 
108778112e55SJoe Eykholt /**
108878112e55SJoe Eykholt  * fnic_set_eth_mode() - put fnic into ethernet mode.
108978112e55SJoe Eykholt  * @fnic: fnic device
109078112e55SJoe Eykholt  *
109178112e55SJoe Eykholt  * Called without fnic lock held.
109278112e55SJoe Eykholt  */
109378112e55SJoe Eykholt static void fnic_set_eth_mode(struct fnic *fnic)
109478112e55SJoe Eykholt {
109578112e55SJoe Eykholt 	unsigned long flags;
109678112e55SJoe Eykholt 	enum fnic_state old_state;
109778112e55SJoe Eykholt 	int ret;
10985df6d737SAbhijeet Joglekar 
10995df6d737SAbhijeet Joglekar 	spin_lock_irqsave(&fnic->fnic_lock, flags);
11005df6d737SAbhijeet Joglekar again:
11015df6d737SAbhijeet Joglekar 	old_state = fnic->state;
11025df6d737SAbhijeet Joglekar 	switch (old_state) {
11035df6d737SAbhijeet Joglekar 	case FNIC_IN_FC_MODE:
11045df6d737SAbhijeet Joglekar 	case FNIC_IN_ETH_TRANS_FC_MODE:
11055df6d737SAbhijeet Joglekar 	default:
11065df6d737SAbhijeet Joglekar 		fnic->state = FNIC_IN_FC_TRANS_ETH_MODE;
11075df6d737SAbhijeet Joglekar 		spin_unlock_irqrestore(&fnic->fnic_lock, flags);
11085df6d737SAbhijeet Joglekar 
11095df6d737SAbhijeet Joglekar 		ret = fnic_fw_reset_handler(fnic);
11105df6d737SAbhijeet Joglekar 
11115df6d737SAbhijeet Joglekar 		spin_lock_irqsave(&fnic->fnic_lock, flags);
11125df6d737SAbhijeet Joglekar 		if (fnic->state != FNIC_IN_FC_TRANS_ETH_MODE)
11135df6d737SAbhijeet Joglekar 			goto again;
111478112e55SJoe Eykholt 		if (ret)
11155df6d737SAbhijeet Joglekar 			fnic->state = old_state;
11165df6d737SAbhijeet Joglekar 		break;
11175df6d737SAbhijeet Joglekar 
11185df6d737SAbhijeet Joglekar 	case FNIC_IN_FC_TRANS_ETH_MODE:
11195df6d737SAbhijeet Joglekar 	case FNIC_IN_ETH_MODE:
11205df6d737SAbhijeet Joglekar 		break;
11215df6d737SAbhijeet Joglekar 	}
112278112e55SJoe Eykholt 	spin_unlock_irqrestore(&fnic->fnic_lock, flags);
11235df6d737SAbhijeet Joglekar }
11245df6d737SAbhijeet Joglekar 
11255df6d737SAbhijeet Joglekar static void fnic_wq_complete_frame_send(struct vnic_wq *wq,
11265df6d737SAbhijeet Joglekar 					struct cq_desc *cq_desc,
11275df6d737SAbhijeet Joglekar 					struct vnic_wq_buf *buf, void *opaque)
11285df6d737SAbhijeet Joglekar {
11295df6d737SAbhijeet Joglekar 	struct sk_buff *skb = buf->os_buf;
11305df6d737SAbhijeet Joglekar 	struct fc_frame *fp = (struct fc_frame *)skb;
11315df6d737SAbhijeet Joglekar 	struct fnic *fnic = vnic_dev_priv(wq->vdev);
11325df6d737SAbhijeet Joglekar 
11335df6d737SAbhijeet Joglekar 	pci_unmap_single(fnic->pdev, buf->dma_addr,
11345df6d737SAbhijeet Joglekar 			 buf->len, PCI_DMA_TODEVICE);
11355df6d737SAbhijeet Joglekar 	dev_kfree_skb_irq(fp_skb(fp));
11365df6d737SAbhijeet Joglekar 	buf->os_buf = NULL;
11375df6d737SAbhijeet Joglekar }
11385df6d737SAbhijeet Joglekar 
11395df6d737SAbhijeet Joglekar static int fnic_wq_cmpl_handler_cont(struct vnic_dev *vdev,
11405df6d737SAbhijeet Joglekar 				     struct cq_desc *cq_desc, u8 type,
11415df6d737SAbhijeet Joglekar 				     u16 q_number, u16 completed_index,
11425df6d737SAbhijeet Joglekar 				     void *opaque)
11435df6d737SAbhijeet Joglekar {
11445df6d737SAbhijeet Joglekar 	struct fnic *fnic = vnic_dev_priv(vdev);
11455df6d737SAbhijeet Joglekar 	unsigned long flags;
11465df6d737SAbhijeet Joglekar 
11475df6d737SAbhijeet Joglekar 	spin_lock_irqsave(&fnic->wq_lock[q_number], flags);
11485df6d737SAbhijeet Joglekar 	vnic_wq_service(&fnic->wq[q_number], cq_desc, completed_index,
11495df6d737SAbhijeet Joglekar 			fnic_wq_complete_frame_send, NULL);
11505df6d737SAbhijeet Joglekar 	spin_unlock_irqrestore(&fnic->wq_lock[q_number], flags);
11515df6d737SAbhijeet Joglekar 
11525df6d737SAbhijeet Joglekar 	return 0;
11535df6d737SAbhijeet Joglekar }
11545df6d737SAbhijeet Joglekar 
11555df6d737SAbhijeet Joglekar int fnic_wq_cmpl_handler(struct fnic *fnic, int work_to_do)
11565df6d737SAbhijeet Joglekar {
11575df6d737SAbhijeet Joglekar 	unsigned int wq_work_done = 0;
11585df6d737SAbhijeet Joglekar 	unsigned int i;
11595df6d737SAbhijeet Joglekar 
11605df6d737SAbhijeet Joglekar 	for (i = 0; i < fnic->raw_wq_count; i++) {
11615df6d737SAbhijeet Joglekar 		wq_work_done  += vnic_cq_service(&fnic->cq[fnic->rq_count+i],
11625df6d737SAbhijeet Joglekar 						 work_to_do,
11635df6d737SAbhijeet Joglekar 						 fnic_wq_cmpl_handler_cont,
11645df6d737SAbhijeet Joglekar 						 NULL);
11655df6d737SAbhijeet Joglekar 	}
11665df6d737SAbhijeet Joglekar 
11675df6d737SAbhijeet Joglekar 	return wq_work_done;
11685df6d737SAbhijeet Joglekar }
11695df6d737SAbhijeet Joglekar 
11705df6d737SAbhijeet Joglekar 
11715df6d737SAbhijeet Joglekar void fnic_free_wq_buf(struct vnic_wq *wq, struct vnic_wq_buf *buf)
11725df6d737SAbhijeet Joglekar {
11735df6d737SAbhijeet Joglekar 	struct fc_frame *fp = buf->os_buf;
11745df6d737SAbhijeet Joglekar 	struct fnic *fnic = vnic_dev_priv(wq->vdev);
11755df6d737SAbhijeet Joglekar 
11765df6d737SAbhijeet Joglekar 	pci_unmap_single(fnic->pdev, buf->dma_addr,
11775df6d737SAbhijeet Joglekar 			 buf->len, PCI_DMA_TODEVICE);
11785df6d737SAbhijeet Joglekar 
11795df6d737SAbhijeet Joglekar 	dev_kfree_skb(fp_skb(fp));
11805df6d737SAbhijeet Joglekar 	buf->os_buf = NULL;
11815df6d737SAbhijeet Joglekar }
1182d3c995f1SHiral Patel 
1183d3c995f1SHiral Patel void fnic_fcoe_reset_vlans(struct fnic *fnic)
1184d3c995f1SHiral Patel {
1185d3c995f1SHiral Patel 	unsigned long flags;
1186d3c995f1SHiral Patel 	struct fcoe_vlan *vlan;
1187d3c995f1SHiral Patel 	struct fcoe_vlan *next;
1188d3c995f1SHiral Patel 
1189d3c995f1SHiral Patel 	/*
1190d3c995f1SHiral Patel 	 * indicate a link down to fcoe so that all fcf's are free'd
1191d3c995f1SHiral Patel 	 * might not be required since we did this before sending vlan
1192d3c995f1SHiral Patel 	 * discovery request
1193d3c995f1SHiral Patel 	 */
1194d3c995f1SHiral Patel 	spin_lock_irqsave(&fnic->vlans_lock, flags);
1195d3c995f1SHiral Patel 	if (!list_empty(&fnic->vlans)) {
1196d3c995f1SHiral Patel 		list_for_each_entry_safe(vlan, next, &fnic->vlans, list) {
1197d3c995f1SHiral Patel 			list_del(&vlan->list);
1198d3c995f1SHiral Patel 			kfree(vlan);
1199d3c995f1SHiral Patel 		}
1200d3c995f1SHiral Patel 	}
1201d3c995f1SHiral Patel 	spin_unlock_irqrestore(&fnic->vlans_lock, flags);
1202d3c995f1SHiral Patel }
1203d3c995f1SHiral Patel 
1204d3c995f1SHiral Patel void fnic_handle_fip_timer(struct fnic *fnic)
1205d3c995f1SHiral Patel {
1206d3c995f1SHiral Patel 	unsigned long flags;
1207d3c995f1SHiral Patel 	struct fcoe_vlan *vlan;
1208d3c995f1SHiral Patel 	u64 sol_time;
1209d3c995f1SHiral Patel 
1210d3c995f1SHiral Patel 	spin_lock_irqsave(&fnic->fnic_lock, flags);
1211d3c995f1SHiral Patel 	if (fnic->stop_rx_link_events) {
1212d3c995f1SHiral Patel 		spin_unlock_irqrestore(&fnic->fnic_lock, flags);
1213d3c995f1SHiral Patel 		return;
1214d3c995f1SHiral Patel 	}
1215d3c995f1SHiral Patel 	spin_unlock_irqrestore(&fnic->fnic_lock, flags);
1216d3c995f1SHiral Patel 
1217d3c995f1SHiral Patel 	if (fnic->ctlr.mode == FIP_ST_NON_FIP)
1218d3c995f1SHiral Patel 		return;
1219d3c995f1SHiral Patel 
1220d3c995f1SHiral Patel 	spin_lock_irqsave(&fnic->vlans_lock, flags);
1221d3c995f1SHiral Patel 	if (list_empty(&fnic->vlans)) {
1222d3c995f1SHiral Patel 		/* no vlans available, try again */
1223d3c995f1SHiral Patel 		FNIC_FCS_DBG(KERN_DEBUG, fnic->lport->host,
1224d3c995f1SHiral Patel 			  "Start VLAN Discovery\n");
1225d3c995f1SHiral Patel 		spin_unlock_irqrestore(&fnic->vlans_lock, flags);
1226d3c995f1SHiral Patel 		fnic_event_enq(fnic, FNIC_EVT_START_VLAN_DISC);
1227d3c995f1SHiral Patel 		return;
1228d3c995f1SHiral Patel 	}
1229d3c995f1SHiral Patel 
1230d3c995f1SHiral Patel 	vlan = list_first_entry(&fnic->vlans, struct fcoe_vlan, list);
1231d3c995f1SHiral Patel 	shost_printk(KERN_DEBUG, fnic->lport->host,
1232d3c995f1SHiral Patel 		  "fip_timer: vlan %d state %d sol_count %d\n",
1233d3c995f1SHiral Patel 		  vlan->vid, vlan->state, vlan->sol_count);
1234d3c995f1SHiral Patel 	switch (vlan->state) {
1235d3c995f1SHiral Patel 	case FIP_VLAN_USED:
1236d3c995f1SHiral Patel 		FNIC_FCS_DBG(KERN_DEBUG, fnic->lport->host,
1237d3c995f1SHiral Patel 			  "FIP VLAN is selected for FC transaction\n");
1238d3c995f1SHiral Patel 		spin_unlock_irqrestore(&fnic->vlans_lock, flags);
1239d3c995f1SHiral Patel 		break;
1240d3c995f1SHiral Patel 	case FIP_VLAN_FAILED:
1241d3c995f1SHiral Patel 		/* if all vlans are in failed state, restart vlan disc */
1242d3c995f1SHiral Patel 		FNIC_FCS_DBG(KERN_DEBUG, fnic->lport->host,
1243d3c995f1SHiral Patel 			  "Start VLAN Discovery\n");
1244d3c995f1SHiral Patel 		spin_unlock_irqrestore(&fnic->vlans_lock, flags);
1245d3c995f1SHiral Patel 		fnic_event_enq(fnic, FNIC_EVT_START_VLAN_DISC);
1246d3c995f1SHiral Patel 		break;
1247d3c995f1SHiral Patel 	case FIP_VLAN_SENT:
1248d3c995f1SHiral Patel 		if (vlan->sol_count >= FCOE_CTLR_MAX_SOL) {
1249d3c995f1SHiral Patel 			/*
1250d3c995f1SHiral Patel 			 * no response on this vlan, remove  from the list.
1251d3c995f1SHiral Patel 			 * Try the next vlan
1252d3c995f1SHiral Patel 			 */
1253d3c995f1SHiral Patel 			shost_printk(KERN_INFO, fnic->lport->host,
1254d3c995f1SHiral Patel 				  "Dequeue this VLAN ID %d from list\n",
1255d3c995f1SHiral Patel 				  vlan->vid);
1256d3c995f1SHiral Patel 			list_del(&vlan->list);
1257d3c995f1SHiral Patel 			kfree(vlan);
1258d3c995f1SHiral Patel 			vlan = NULL;
1259d3c995f1SHiral Patel 			if (list_empty(&fnic->vlans)) {
1260d3c995f1SHiral Patel 				/* we exhausted all vlans, restart vlan disc */
1261d3c995f1SHiral Patel 				spin_unlock_irqrestore(&fnic->vlans_lock,
1262d3c995f1SHiral Patel 							flags);
1263d3c995f1SHiral Patel 				shost_printk(KERN_INFO, fnic->lport->host,
1264d3c995f1SHiral Patel 					  "fip_timer: vlan list empty, "
1265d3c995f1SHiral Patel 					  "trigger vlan disc\n");
1266d3c995f1SHiral Patel 				fnic_event_enq(fnic, FNIC_EVT_START_VLAN_DISC);
1267d3c995f1SHiral Patel 				return;
1268d3c995f1SHiral Patel 			}
1269d3c995f1SHiral Patel 			/* check the next vlan */
1270d3c995f1SHiral Patel 			vlan = list_first_entry(&fnic->vlans, struct fcoe_vlan,
1271d3c995f1SHiral Patel 							list);
1272d3c995f1SHiral Patel 			fnic->set_vlan(fnic, vlan->vid);
1273d3c995f1SHiral Patel 			vlan->state = FIP_VLAN_SENT; /* sent now */
1274d3c995f1SHiral Patel 		}
1275d3c995f1SHiral Patel 		spin_unlock_irqrestore(&fnic->vlans_lock, flags);
1276d3c995f1SHiral Patel 		vlan->sol_count++;
1277d3c995f1SHiral Patel 		sol_time = jiffies + msecs_to_jiffies
1278d3c995f1SHiral Patel 					(FCOE_CTLR_START_DELAY);
1279d3c995f1SHiral Patel 		mod_timer(&fnic->fip_timer, round_jiffies(sol_time));
1280d3c995f1SHiral Patel 		break;
1281d3c995f1SHiral Patel 	}
1282d3c995f1SHiral Patel }
1283