1e6550b3eSThomas Gleixner // SPDX-License-Identifier: GPL-2.0-only
25df6d737SAbhijeet Joglekar /*
35df6d737SAbhijeet Joglekar * Copyright 2008 Cisco Systems, Inc. All rights reserved.
45df6d737SAbhijeet Joglekar * Copyright 2007 Nuova Systems, Inc. All rights reserved.
55df6d737SAbhijeet Joglekar */
65df6d737SAbhijeet Joglekar #include <linux/errno.h>
75df6d737SAbhijeet Joglekar #include <linux/pci.h>
85a0e3ad6STejun Heo #include <linux/slab.h>
95df6d737SAbhijeet Joglekar #include <linux/skbuff.h>
105df6d737SAbhijeet Joglekar #include <linux/interrupt.h>
115df6d737SAbhijeet Joglekar #include <linux/spinlock.h>
125df6d737SAbhijeet Joglekar #include <linux/if_ether.h>
135df6d737SAbhijeet Joglekar #include <linux/if_vlan.h>
145df6d737SAbhijeet Joglekar #include <linux/workqueue.h>
1578112e55SJoe Eykholt #include <scsi/fc/fc_fip.h>
165df6d737SAbhijeet Joglekar #include <scsi/fc/fc_els.h>
175df6d737SAbhijeet Joglekar #include <scsi/fc/fc_fcoe.h>
185df6d737SAbhijeet Joglekar #include <scsi/fc_frame.h>
195df6d737SAbhijeet Joglekar #include <scsi/libfc.h>
205df6d737SAbhijeet Joglekar #include "fnic_io.h"
215df6d737SAbhijeet Joglekar #include "fnic.h"
22d3c995f1SHiral Patel #include "fnic_fip.h"
235df6d737SAbhijeet Joglekar #include "cq_enet_desc.h"
245df6d737SAbhijeet Joglekar #include "cq_exch_desc.h"
255df6d737SAbhijeet Joglekar
2686001f24SHiral Shah static u8 fcoe_all_fcfs[ETH_ALEN] = FIP_ALL_FCF_MACS;
27d3c995f1SHiral Patel struct workqueue_struct *fnic_fip_queue;
285df6d737SAbhijeet Joglekar struct workqueue_struct *fnic_event_queue;
295df6d737SAbhijeet Joglekar
3078112e55SJoe Eykholt static void fnic_set_eth_mode(struct fnic *);
31d3c995f1SHiral Patel static void fnic_fcoe_send_vlan_req(struct fnic *fnic);
32d3c995f1SHiral Patel static void fnic_fcoe_start_fcf_disc(struct fnic *fnic);
33d3c995f1SHiral Patel static void fnic_fcoe_process_vlan_resp(struct fnic *fnic, struct sk_buff *);
34d3c995f1SHiral Patel static int fnic_fcoe_vlan_check(struct fnic *fnic, u16 flag);
35d3c995f1SHiral Patel static int fnic_fcoe_handle_fip_frame(struct fnic *fnic, struct sk_buff *skb);
3678112e55SJoe Eykholt
fnic_handle_link(struct work_struct * work)375df6d737SAbhijeet Joglekar void fnic_handle_link(struct work_struct *work)
385df6d737SAbhijeet Joglekar {
395df6d737SAbhijeet Joglekar struct fnic *fnic = container_of(work, struct fnic, link_work);
405df6d737SAbhijeet Joglekar unsigned long flags;
415df6d737SAbhijeet Joglekar int old_link_status;
425df6d737SAbhijeet Joglekar u32 old_link_down_cnt;
4390302e95SJohn Pittman u64 old_port_speed, new_port_speed;
445df6d737SAbhijeet Joglekar
455df6d737SAbhijeet Joglekar spin_lock_irqsave(&fnic->fnic_lock, flags);
465df6d737SAbhijeet Joglekar
47f9e2beb9SKaran Tilak Kumar fnic->link_events = 1; /* less work to just set everytime*/
48f9e2beb9SKaran Tilak Kumar
495df6d737SAbhijeet Joglekar if (fnic->stop_rx_link_events) {
505df6d737SAbhijeet Joglekar spin_unlock_irqrestore(&fnic->fnic_lock, flags);
515df6d737SAbhijeet Joglekar return;
525df6d737SAbhijeet Joglekar }
535df6d737SAbhijeet Joglekar
545df6d737SAbhijeet Joglekar old_link_down_cnt = fnic->link_down_cnt;
555df6d737SAbhijeet Joglekar old_link_status = fnic->link_status;
5690302e95SJohn Pittman old_port_speed = atomic64_read(
5790302e95SJohn Pittman &fnic->fnic_stats.misc_stats.current_port_speed);
5890302e95SJohn Pittman
595df6d737SAbhijeet Joglekar fnic->link_status = vnic_dev_link_status(fnic->vdev);
605df6d737SAbhijeet Joglekar fnic->link_down_cnt = vnic_dev_link_down_cnt(fnic->vdev);
615df6d737SAbhijeet Joglekar
6290302e95SJohn Pittman new_port_speed = vnic_dev_port_speed(fnic->vdev);
63d948e638SSatish Kharat atomic64_set(&fnic->fnic_stats.misc_stats.current_port_speed,
6490302e95SJohn Pittman new_port_speed);
6590302e95SJohn Pittman if (old_port_speed != new_port_speed)
663df9dd0dSKaran Tilak Kumar FNIC_FCS_DBG(KERN_INFO, fnic->lport->host, fnic->fnic_num,
6790302e95SJohn Pittman "Current vnic speed set to: %llu\n",
6890302e95SJohn Pittman new_port_speed);
69d948e638SSatish Kharat
70c22fa50bSSatish Kharat switch (vnic_dev_port_speed(fnic->vdev)) {
71c22fa50bSSatish Kharat case DCEM_PORTSPEED_10G:
72c22fa50bSSatish Kharat fc_host_speed(fnic->lport->host) = FC_PORTSPEED_10GBIT;
73c22fa50bSSatish Kharat fnic->lport->link_supported_speeds = FC_PORTSPEED_10GBIT;
74c22fa50bSSatish Kharat break;
75c01461a6SSatish Kharat case DCEM_PORTSPEED_20G:
76c01461a6SSatish Kharat fc_host_speed(fnic->lport->host) = FC_PORTSPEED_20GBIT;
77c01461a6SSatish Kharat fnic->lport->link_supported_speeds = FC_PORTSPEED_20GBIT;
78c01461a6SSatish Kharat break;
79c22fa50bSSatish Kharat case DCEM_PORTSPEED_25G:
80c22fa50bSSatish Kharat fc_host_speed(fnic->lport->host) = FC_PORTSPEED_25GBIT;
81c22fa50bSSatish Kharat fnic->lport->link_supported_speeds = FC_PORTSPEED_25GBIT;
82c22fa50bSSatish Kharat break;
83c22fa50bSSatish Kharat case DCEM_PORTSPEED_40G:
84c22fa50bSSatish Kharat case DCEM_PORTSPEED_4x10G:
85c22fa50bSSatish Kharat fc_host_speed(fnic->lport->host) = FC_PORTSPEED_40GBIT;
86c22fa50bSSatish Kharat fnic->lport->link_supported_speeds = FC_PORTSPEED_40GBIT;
87c22fa50bSSatish Kharat break;
88c22fa50bSSatish Kharat case DCEM_PORTSPEED_100G:
89c22fa50bSSatish Kharat fc_host_speed(fnic->lport->host) = FC_PORTSPEED_100GBIT;
90c22fa50bSSatish Kharat fnic->lport->link_supported_speeds = FC_PORTSPEED_100GBIT;
91c22fa50bSSatish Kharat break;
92c22fa50bSSatish Kharat default:
93c22fa50bSSatish Kharat fc_host_speed(fnic->lport->host) = FC_PORTSPEED_UNKNOWN;
94c22fa50bSSatish Kharat fnic->lport->link_supported_speeds = FC_PORTSPEED_UNKNOWN;
95c22fa50bSSatish Kharat break;
96c22fa50bSSatish Kharat }
97c22fa50bSSatish Kharat
985df6d737SAbhijeet Joglekar if (old_link_status == fnic->link_status) {
99abb14148SHiral Shah if (!fnic->link_status) {
1005df6d737SAbhijeet Joglekar /* DOWN -> DOWN */
1015df6d737SAbhijeet Joglekar spin_unlock_irqrestore(&fnic->fnic_lock, flags);
102abb14148SHiral Shah fnic_fc_trace_set_data(fnic->lport->host->host_no,
103abb14148SHiral Shah FNIC_FC_LE, "Link Status: DOWN->DOWN",
104abb14148SHiral Shah strlen("Link Status: DOWN->DOWN"));
1053df9dd0dSKaran Tilak Kumar FNIC_FCS_DBG(KERN_INFO, fnic->lport->host, fnic->fnic_num,
1063df9dd0dSKaran Tilak Kumar "down->down\n");
107abb14148SHiral Shah } else {
1085df6d737SAbhijeet Joglekar if (old_link_down_cnt != fnic->link_down_cnt) {
1095df6d737SAbhijeet Joglekar /* UP -> DOWN -> UP */
1105df6d737SAbhijeet Joglekar fnic->lport->host_stats.link_failure_count++;
1115df6d737SAbhijeet Joglekar spin_unlock_irqrestore(&fnic->fnic_lock, flags);
112abb14148SHiral Shah fnic_fc_trace_set_data(
113abb14148SHiral Shah fnic->lport->host->host_no,
114abb14148SHiral Shah FNIC_FC_LE,
115abb14148SHiral Shah "Link Status:UP_DOWN_UP",
116abb14148SHiral Shah strlen("Link_Status:UP_DOWN_UP")
117abb14148SHiral Shah );
1183df9dd0dSKaran Tilak Kumar FNIC_FCS_DBG(KERN_DEBUG, fnic->lport->host, fnic->fnic_num,
1195df6d737SAbhijeet Joglekar "link down\n");
12078112e55SJoe Eykholt fcoe_ctlr_link_down(&fnic->ctlr);
121d3c995f1SHiral Patel if (fnic->config.flags & VFCF_FIP_CAPABLE) {
122d3c995f1SHiral Patel /* start FCoE VLAN discovery */
123abb14148SHiral Shah fnic_fc_trace_set_data(
124abb14148SHiral Shah fnic->lport->host->host_no,
125abb14148SHiral Shah FNIC_FC_LE,
126abb14148SHiral Shah "Link Status: UP_DOWN_UP_VLAN",
127abb14148SHiral Shah strlen(
128abb14148SHiral Shah "Link Status: UP_DOWN_UP_VLAN")
129abb14148SHiral Shah );
130d3c995f1SHiral Patel fnic_fcoe_send_vlan_req(fnic);
131d3c995f1SHiral Patel return;
132d3c995f1SHiral Patel }
1333df9dd0dSKaran Tilak Kumar FNIC_FCS_DBG(KERN_INFO, fnic->lport->host, fnic->fnic_num,
1343df9dd0dSKaran Tilak Kumar "up->down->up: Link up\n");
13578112e55SJoe Eykholt fcoe_ctlr_link_up(&fnic->ctlr);
13686001f24SHiral Shah } else {
1375df6d737SAbhijeet Joglekar /* UP -> UP */
1385df6d737SAbhijeet Joglekar spin_unlock_irqrestore(&fnic->fnic_lock, flags);
139abb14148SHiral Shah fnic_fc_trace_set_data(
140abb14148SHiral Shah fnic->lport->host->host_no, FNIC_FC_LE,
141abb14148SHiral Shah "Link Status: UP_UP",
142abb14148SHiral Shah strlen("Link Status: UP_UP"));
1433df9dd0dSKaran Tilak Kumar FNIC_FCS_DBG(KERN_INFO, fnic->lport->host, fnic->fnic_num,
1443df9dd0dSKaran Tilak Kumar "up->up\n");
1455df6d737SAbhijeet Joglekar }
14686001f24SHiral Shah }
1475df6d737SAbhijeet Joglekar } else if (fnic->link_status) {
1485df6d737SAbhijeet Joglekar /* DOWN -> UP */
1495df6d737SAbhijeet Joglekar spin_unlock_irqrestore(&fnic->fnic_lock, flags);
150d3c995f1SHiral Patel if (fnic->config.flags & VFCF_FIP_CAPABLE) {
151d3c995f1SHiral Patel /* start FCoE VLAN discovery */
1525ef104b7SJiapeng Chong fnic_fc_trace_set_data(fnic->lport->host->host_no,
153abb14148SHiral Shah FNIC_FC_LE, "Link Status: DOWN_UP_VLAN",
154abb14148SHiral Shah strlen("Link Status: DOWN_UP_VLAN"));
155d3c995f1SHiral Patel fnic_fcoe_send_vlan_req(fnic);
1565ef104b7SJiapeng Chong
157d3c995f1SHiral Patel return;
158d3c995f1SHiral Patel }
1595ef104b7SJiapeng Chong
1603df9dd0dSKaran Tilak Kumar FNIC_FCS_DBG(KERN_INFO, fnic->lport->host, fnic->fnic_num,
1613df9dd0dSKaran Tilak Kumar "down->up: Link up\n");
162abb14148SHiral Shah fnic_fc_trace_set_data(fnic->lport->host->host_no, FNIC_FC_LE,
163abb14148SHiral Shah "Link Status: DOWN_UP", strlen("Link Status: DOWN_UP"));
16478112e55SJoe Eykholt fcoe_ctlr_link_up(&fnic->ctlr);
1655df6d737SAbhijeet Joglekar } else {
1665df6d737SAbhijeet Joglekar /* UP -> DOWN */
1675df6d737SAbhijeet Joglekar fnic->lport->host_stats.link_failure_count++;
1685df6d737SAbhijeet Joglekar spin_unlock_irqrestore(&fnic->fnic_lock, flags);
1693df9dd0dSKaran Tilak Kumar FNIC_FCS_DBG(KERN_INFO, fnic->lport->host, fnic->fnic_num,
1703df9dd0dSKaran Tilak Kumar "up->down: Link down\n");
171abb14148SHiral Shah fnic_fc_trace_set_data(
172abb14148SHiral Shah fnic->lport->host->host_no, FNIC_FC_LE,
173abb14148SHiral Shah "Link Status: UP_DOWN",
174abb14148SHiral Shah strlen("Link Status: UP_DOWN"));
1750ee7b871SHiral Shah if (fnic->config.flags & VFCF_FIP_CAPABLE) {
1763df9dd0dSKaran Tilak Kumar FNIC_FCS_DBG(KERN_DEBUG, fnic->lport->host, fnic->fnic_num,
1770ee7b871SHiral Shah "deleting fip-timer during link-down\n");
1780ee7b871SHiral Shah del_timer_sync(&fnic->fip_timer);
1790ee7b871SHiral Shah }
18078112e55SJoe Eykholt fcoe_ctlr_link_down(&fnic->ctlr);
1815df6d737SAbhijeet Joglekar }
1825df6d737SAbhijeet Joglekar
1835df6d737SAbhijeet Joglekar }
1845df6d737SAbhijeet Joglekar
1855df6d737SAbhijeet Joglekar /*
1865df6d737SAbhijeet Joglekar * This function passes incoming fabric frames to libFC
1875df6d737SAbhijeet Joglekar */
fnic_handle_frame(struct work_struct * work)1885df6d737SAbhijeet Joglekar void fnic_handle_frame(struct work_struct *work)
1895df6d737SAbhijeet Joglekar {
1905df6d737SAbhijeet Joglekar struct fnic *fnic = container_of(work, struct fnic, frame_work);
1915df6d737SAbhijeet Joglekar struct fc_lport *lp = fnic->lport;
1925df6d737SAbhijeet Joglekar unsigned long flags;
1935df6d737SAbhijeet Joglekar struct sk_buff *skb;
1945df6d737SAbhijeet Joglekar struct fc_frame *fp;
1955df6d737SAbhijeet Joglekar
1965df6d737SAbhijeet Joglekar while ((skb = skb_dequeue(&fnic->frame_queue))) {
1975df6d737SAbhijeet Joglekar
1985df6d737SAbhijeet Joglekar spin_lock_irqsave(&fnic->fnic_lock, flags);
1995df6d737SAbhijeet Joglekar if (fnic->stop_rx_link_events) {
2005df6d737SAbhijeet Joglekar spin_unlock_irqrestore(&fnic->fnic_lock, flags);
2015df6d737SAbhijeet Joglekar dev_kfree_skb(skb);
2025df6d737SAbhijeet Joglekar return;
2035df6d737SAbhijeet Joglekar }
2045df6d737SAbhijeet Joglekar fp = (struct fc_frame *)skb;
20578112e55SJoe Eykholt
20678112e55SJoe Eykholt /*
20778112e55SJoe Eykholt * If we're in a transitional state, just re-queue and return.
20878112e55SJoe Eykholt * The queue will be serviced when we get to a stable state.
20978112e55SJoe Eykholt */
21078112e55SJoe Eykholt if (fnic->state != FNIC_IN_FC_MODE &&
21178112e55SJoe Eykholt fnic->state != FNIC_IN_ETH_MODE) {
21278112e55SJoe Eykholt skb_queue_head(&fnic->frame_queue, skb);
21378112e55SJoe Eykholt spin_unlock_irqrestore(&fnic->fnic_lock, flags);
21478112e55SJoe Eykholt return;
2155df6d737SAbhijeet Joglekar }
2165df6d737SAbhijeet Joglekar spin_unlock_irqrestore(&fnic->fnic_lock, flags);
2175df6d737SAbhijeet Joglekar
21852ff878cSVasu Dev fc_exch_recv(lp, fp);
2195df6d737SAbhijeet Joglekar }
2205df6d737SAbhijeet Joglekar }
2215df6d737SAbhijeet Joglekar
fnic_fcoe_evlist_free(struct fnic * fnic)222d3c995f1SHiral Patel void fnic_fcoe_evlist_free(struct fnic *fnic)
223d3c995f1SHiral Patel {
224d3c995f1SHiral Patel struct fnic_event *fevt = NULL;
225d3c995f1SHiral Patel struct fnic_event *next = NULL;
226d3c995f1SHiral Patel unsigned long flags;
227d3c995f1SHiral Patel
228d3c995f1SHiral Patel spin_lock_irqsave(&fnic->fnic_lock, flags);
229d3c995f1SHiral Patel if (list_empty(&fnic->evlist)) {
230d3c995f1SHiral Patel spin_unlock_irqrestore(&fnic->fnic_lock, flags);
231d3c995f1SHiral Patel return;
232d3c995f1SHiral Patel }
233d3c995f1SHiral Patel
234d3c995f1SHiral Patel list_for_each_entry_safe(fevt, next, &fnic->evlist, list) {
235d3c995f1SHiral Patel list_del(&fevt->list);
236d3c995f1SHiral Patel kfree(fevt);
237d3c995f1SHiral Patel }
238d3c995f1SHiral Patel spin_unlock_irqrestore(&fnic->fnic_lock, flags);
239d3c995f1SHiral Patel }
240d3c995f1SHiral Patel
fnic_handle_event(struct work_struct * work)241d3c995f1SHiral Patel void fnic_handle_event(struct work_struct *work)
242d3c995f1SHiral Patel {
243d3c995f1SHiral Patel struct fnic *fnic = container_of(work, struct fnic, event_work);
244d3c995f1SHiral Patel struct fnic_event *fevt = NULL;
245d3c995f1SHiral Patel struct fnic_event *next = NULL;
246d3c995f1SHiral Patel unsigned long flags;
247d3c995f1SHiral Patel
248d3c995f1SHiral Patel spin_lock_irqsave(&fnic->fnic_lock, flags);
249d3c995f1SHiral Patel if (list_empty(&fnic->evlist)) {
250d3c995f1SHiral Patel spin_unlock_irqrestore(&fnic->fnic_lock, flags);
251d3c995f1SHiral Patel return;
252d3c995f1SHiral Patel }
253d3c995f1SHiral Patel
254d3c995f1SHiral Patel list_for_each_entry_safe(fevt, next, &fnic->evlist, list) {
255d3c995f1SHiral Patel if (fnic->stop_rx_link_events) {
256d3c995f1SHiral Patel list_del(&fevt->list);
257d3c995f1SHiral Patel kfree(fevt);
258d3c995f1SHiral Patel spin_unlock_irqrestore(&fnic->fnic_lock, flags);
259d3c995f1SHiral Patel return;
260d3c995f1SHiral Patel }
261d3c995f1SHiral Patel /*
262d3c995f1SHiral Patel * If we're in a transitional state, just re-queue and return.
263d3c995f1SHiral Patel * The queue will be serviced when we get to a stable state.
264d3c995f1SHiral Patel */
265d3c995f1SHiral Patel if (fnic->state != FNIC_IN_FC_MODE &&
266d3c995f1SHiral Patel fnic->state != FNIC_IN_ETH_MODE) {
267d3c995f1SHiral Patel spin_unlock_irqrestore(&fnic->fnic_lock, flags);
268d3c995f1SHiral Patel return;
269d3c995f1SHiral Patel }
270d3c995f1SHiral Patel
271d3c995f1SHiral Patel list_del(&fevt->list);
272d3c995f1SHiral Patel switch (fevt->event) {
273d3c995f1SHiral Patel case FNIC_EVT_START_VLAN_DISC:
274d3c995f1SHiral Patel spin_unlock_irqrestore(&fnic->fnic_lock, flags);
275d3c995f1SHiral Patel fnic_fcoe_send_vlan_req(fnic);
276d3c995f1SHiral Patel spin_lock_irqsave(&fnic->fnic_lock, flags);
277d3c995f1SHiral Patel break;
278d3c995f1SHiral Patel case FNIC_EVT_START_FCF_DISC:
2793df9dd0dSKaran Tilak Kumar FNIC_FCS_DBG(KERN_DEBUG, fnic->lport->host, fnic->fnic_num,
280d3c995f1SHiral Patel "Start FCF Discovery\n");
281d3c995f1SHiral Patel fnic_fcoe_start_fcf_disc(fnic);
282d3c995f1SHiral Patel break;
283d3c995f1SHiral Patel default:
2843df9dd0dSKaran Tilak Kumar FNIC_FCS_DBG(KERN_DEBUG, fnic->lport->host, fnic->fnic_num,
285d3c995f1SHiral Patel "Unknown event 0x%x\n", fevt->event);
286d3c995f1SHiral Patel break;
287d3c995f1SHiral Patel }
288d3c995f1SHiral Patel kfree(fevt);
289d3c995f1SHiral Patel }
290d3c995f1SHiral Patel spin_unlock_irqrestore(&fnic->fnic_lock, flags);
291d3c995f1SHiral Patel }
292d3c995f1SHiral Patel
293d3c995f1SHiral Patel /**
2942efd8631SLee Jones * is_fnic_fip_flogi_reject() - Check if the Received FIP FLOGI frame is rejected
295d3c995f1SHiral Patel * @fip: The FCoE controller that received the frame
296d3c995f1SHiral Patel * @skb: The received FIP frame
297d3c995f1SHiral Patel *
298d3c995f1SHiral Patel * Returns non-zero if the frame is rejected with unsupported cmd with
299d3c995f1SHiral Patel * insufficient resource els explanation.
300d3c995f1SHiral Patel */
is_fnic_fip_flogi_reject(struct fcoe_ctlr * fip,struct sk_buff * skb)301d3c995f1SHiral Patel static inline int is_fnic_fip_flogi_reject(struct fcoe_ctlr *fip,
302d3c995f1SHiral Patel struct sk_buff *skb)
303d3c995f1SHiral Patel {
304d3c995f1SHiral Patel struct fc_lport *lport = fip->lp;
305d3c995f1SHiral Patel struct fip_header *fiph;
306d3c995f1SHiral Patel struct fc_frame_header *fh = NULL;
307d3c995f1SHiral Patel struct fip_desc *desc;
308d3c995f1SHiral Patel struct fip_encaps *els;
309d3c995f1SHiral Patel u16 op;
310d3c995f1SHiral Patel u8 els_op;
311d3c995f1SHiral Patel u8 sub;
312d3c995f1SHiral Patel
313d3c995f1SHiral Patel size_t rlen;
314d3c995f1SHiral Patel size_t dlen = 0;
315d3c995f1SHiral Patel
316d3c995f1SHiral Patel if (skb_linearize(skb))
317d3c995f1SHiral Patel return 0;
318d3c995f1SHiral Patel
319d3c995f1SHiral Patel if (skb->len < sizeof(*fiph))
320d3c995f1SHiral Patel return 0;
321d3c995f1SHiral Patel
322d3c995f1SHiral Patel fiph = (struct fip_header *)skb->data;
323d3c995f1SHiral Patel op = ntohs(fiph->fip_op);
324d3c995f1SHiral Patel sub = fiph->fip_subcode;
325d3c995f1SHiral Patel
326d3c995f1SHiral Patel if (op != FIP_OP_LS)
327d3c995f1SHiral Patel return 0;
328d3c995f1SHiral Patel
329d3c995f1SHiral Patel if (sub != FIP_SC_REP)
330d3c995f1SHiral Patel return 0;
331d3c995f1SHiral Patel
332d3c995f1SHiral Patel rlen = ntohs(fiph->fip_dl_len) * 4;
333d3c995f1SHiral Patel if (rlen + sizeof(*fiph) > skb->len)
334d3c995f1SHiral Patel return 0;
335d3c995f1SHiral Patel
336d3c995f1SHiral Patel desc = (struct fip_desc *)(fiph + 1);
337d3c995f1SHiral Patel dlen = desc->fip_dlen * FIP_BPW;
338d3c995f1SHiral Patel
339d3c995f1SHiral Patel if (desc->fip_dtype == FIP_DT_FLOGI) {
340d3c995f1SHiral Patel
341d3c995f1SHiral Patel if (dlen < sizeof(*els) + sizeof(*fh) + 1)
342d3c995f1SHiral Patel return 0;
343d3c995f1SHiral Patel
344d3c995f1SHiral Patel els = (struct fip_encaps *)desc;
345d3c995f1SHiral Patel fh = (struct fc_frame_header *)(els + 1);
346d3c995f1SHiral Patel
347d3c995f1SHiral Patel if (!fh)
348d3c995f1SHiral Patel return 0;
349d3c995f1SHiral Patel
350d3c995f1SHiral Patel /*
351d3c995f1SHiral Patel * ELS command code, reason and explanation should be = Reject,
352d3c995f1SHiral Patel * unsupported command and insufficient resource
353d3c995f1SHiral Patel */
354d3c995f1SHiral Patel els_op = *(u8 *)(fh + 1);
355d3c995f1SHiral Patel if (els_op == ELS_LS_RJT) {
356d3c995f1SHiral Patel shost_printk(KERN_INFO, lport->host,
357d3c995f1SHiral Patel "Flogi Request Rejected by Switch\n");
358d3c995f1SHiral Patel return 1;
359d3c995f1SHiral Patel }
360d3c995f1SHiral Patel shost_printk(KERN_INFO, lport->host,
361d3c995f1SHiral Patel "Flogi Request Accepted by Switch\n");
362d3c995f1SHiral Patel }
363d3c995f1SHiral Patel return 0;
364d3c995f1SHiral Patel }
365d3c995f1SHiral Patel
fnic_fcoe_send_vlan_req(struct fnic * fnic)366d3c995f1SHiral Patel static void fnic_fcoe_send_vlan_req(struct fnic *fnic)
367d3c995f1SHiral Patel {
368d3c995f1SHiral Patel struct fcoe_ctlr *fip = &fnic->ctlr;
36967125b02SHiral Patel struct fnic_stats *fnic_stats = &fnic->fnic_stats;
370d3c995f1SHiral Patel struct sk_buff *skb;
371d3c995f1SHiral Patel char *eth_fr;
372d3c995f1SHiral Patel struct fip_vlan *vlan;
373d3c995f1SHiral Patel u64 vlan_tov;
374d3c995f1SHiral Patel
375d3c995f1SHiral Patel fnic_fcoe_reset_vlans(fnic);
376d3c995f1SHiral Patel fnic->set_vlan(fnic, 0);
377b43abcbbSSatish Kharat
378b43abcbbSSatish Kharat if (printk_ratelimit())
3793df9dd0dSKaran Tilak Kumar FNIC_FCS_DBG(KERN_INFO, fnic->lport->host, fnic->fnic_num,
380d3c995f1SHiral Patel "Sending VLAN request...\n");
381b43abcbbSSatish Kharat
382d3c995f1SHiral Patel skb = dev_alloc_skb(sizeof(struct fip_vlan));
383d3c995f1SHiral Patel if (!skb)
384d3c995f1SHiral Patel return;
385d3c995f1SHiral Patel
386d3c995f1SHiral Patel eth_fr = (char *)skb->data;
387d3c995f1SHiral Patel vlan = (struct fip_vlan *)eth_fr;
388d3c995f1SHiral Patel
389d3c995f1SHiral Patel memset(vlan, 0, sizeof(*vlan));
390d3c995f1SHiral Patel memcpy(vlan->eth.h_source, fip->ctl_src_addr, ETH_ALEN);
391d3c995f1SHiral Patel memcpy(vlan->eth.h_dest, fcoe_all_fcfs, ETH_ALEN);
392d3c995f1SHiral Patel vlan->eth.h_proto = htons(ETH_P_FIP);
393d3c995f1SHiral Patel
394d3c995f1SHiral Patel vlan->fip.fip_ver = FIP_VER_ENCAPS(FIP_VER);
395d3c995f1SHiral Patel vlan->fip.fip_op = htons(FIP_OP_VLAN);
396b8e1aa3cSSatish Kharat vlan->fip.fip_subcode = FIP_SC_VL_REQ;
397d3c995f1SHiral Patel vlan->fip.fip_dl_len = htons(sizeof(vlan->desc) / FIP_BPW);
398d3c995f1SHiral Patel
399d3c995f1SHiral Patel vlan->desc.mac.fd_desc.fip_dtype = FIP_DT_MAC;
400d3c995f1SHiral Patel vlan->desc.mac.fd_desc.fip_dlen = sizeof(vlan->desc.mac) / FIP_BPW;
401d3c995f1SHiral Patel memcpy(&vlan->desc.mac.fd_mac, fip->ctl_src_addr, ETH_ALEN);
402d3c995f1SHiral Patel
403d3c995f1SHiral Patel vlan->desc.wwnn.fd_desc.fip_dtype = FIP_DT_NAME;
404d3c995f1SHiral Patel vlan->desc.wwnn.fd_desc.fip_dlen = sizeof(vlan->desc.wwnn) / FIP_BPW;
405d3c995f1SHiral Patel put_unaligned_be64(fip->lp->wwnn, &vlan->desc.wwnn.fd_wwn);
40667125b02SHiral Patel atomic64_inc(&fnic_stats->vlan_stats.vlan_disc_reqs);
407d3c995f1SHiral Patel
408d3c995f1SHiral Patel skb_put(skb, sizeof(*vlan));
409d3c995f1SHiral Patel skb->protocol = htons(ETH_P_FIP);
410d3c995f1SHiral Patel skb_reset_mac_header(skb);
411d3c995f1SHiral Patel skb_reset_network_header(skb);
412d3c995f1SHiral Patel fip->send(fip, skb);
413d3c995f1SHiral Patel
414d3c995f1SHiral Patel /* set a timer so that we can retry if there no response */
415d3c995f1SHiral Patel vlan_tov = jiffies + msecs_to_jiffies(FCOE_CTLR_FIPVLAN_TOV);
416d3c995f1SHiral Patel mod_timer(&fnic->fip_timer, round_jiffies(vlan_tov));
417d3c995f1SHiral Patel }
418d3c995f1SHiral Patel
fnic_fcoe_process_vlan_resp(struct fnic * fnic,struct sk_buff * skb)419d3c995f1SHiral Patel static void fnic_fcoe_process_vlan_resp(struct fnic *fnic, struct sk_buff *skb)
420d3c995f1SHiral Patel {
421d3c995f1SHiral Patel struct fcoe_ctlr *fip = &fnic->ctlr;
422d3c995f1SHiral Patel struct fip_header *fiph;
423d3c995f1SHiral Patel struct fip_desc *desc;
42467125b02SHiral Patel struct fnic_stats *fnic_stats = &fnic->fnic_stats;
425d3c995f1SHiral Patel u16 vid;
426d3c995f1SHiral Patel size_t rlen;
427d3c995f1SHiral Patel size_t dlen;
428d3c995f1SHiral Patel struct fcoe_vlan *vlan;
429d3c995f1SHiral Patel u64 sol_time;
430d3c995f1SHiral Patel unsigned long flags;
431d3c995f1SHiral Patel
4323df9dd0dSKaran Tilak Kumar FNIC_FCS_DBG(KERN_INFO, fnic->lport->host, fnic->fnic_num,
433d3c995f1SHiral Patel "Received VLAN response...\n");
434d3c995f1SHiral Patel
435d3c995f1SHiral Patel fiph = (struct fip_header *) skb->data;
436d3c995f1SHiral Patel
4373df9dd0dSKaran Tilak Kumar FNIC_FCS_DBG(KERN_INFO, fnic->lport->host, fnic->fnic_num,
438d3c995f1SHiral Patel "Received VLAN response... OP 0x%x SUB_OP 0x%x\n",
439d3c995f1SHiral Patel ntohs(fiph->fip_op), fiph->fip_subcode);
440d3c995f1SHiral Patel
441d3c995f1SHiral Patel rlen = ntohs(fiph->fip_dl_len) * 4;
442d3c995f1SHiral Patel fnic_fcoe_reset_vlans(fnic);
443d3c995f1SHiral Patel spin_lock_irqsave(&fnic->vlans_lock, flags);
444d3c995f1SHiral Patel desc = (struct fip_desc *)(fiph + 1);
445d3c995f1SHiral Patel while (rlen > 0) {
446d3c995f1SHiral Patel dlen = desc->fip_dlen * FIP_BPW;
447d3c995f1SHiral Patel switch (desc->fip_dtype) {
448d3c995f1SHiral Patel case FIP_DT_VLAN:
449d3c995f1SHiral Patel vid = ntohs(((struct fip_vlan_desc *)desc)->fd_vlan);
450d3c995f1SHiral Patel shost_printk(KERN_INFO, fnic->lport->host,
451d3c995f1SHiral Patel "process_vlan_resp: FIP VLAN %d\n", vid);
452dbc1ebe7SRasmus Villemoes vlan = kzalloc(sizeof(*vlan), GFP_ATOMIC);
453d3c995f1SHiral Patel if (!vlan) {
454d3c995f1SHiral Patel /* retry from timer */
455d3c995f1SHiral Patel spin_unlock_irqrestore(&fnic->vlans_lock,
456d3c995f1SHiral Patel flags);
457d3c995f1SHiral Patel goto out;
458d3c995f1SHiral Patel }
459d3c995f1SHiral Patel vlan->vid = vid & 0x0fff;
460d3c995f1SHiral Patel vlan->state = FIP_VLAN_AVAIL;
461d3c995f1SHiral Patel list_add_tail(&vlan->list, &fnic->vlans);
462d3c995f1SHiral Patel break;
463d3c995f1SHiral Patel }
464d3c995f1SHiral Patel desc = (struct fip_desc *)((char *)desc + dlen);
465d3c995f1SHiral Patel rlen -= dlen;
466d3c995f1SHiral Patel }
467d3c995f1SHiral Patel
468d3c995f1SHiral Patel /* any VLAN descriptors present ? */
469d3c995f1SHiral Patel if (list_empty(&fnic->vlans)) {
470d3c995f1SHiral Patel /* retry from timer */
47167125b02SHiral Patel atomic64_inc(&fnic_stats->vlan_stats.resp_withno_vlanID);
4723df9dd0dSKaran Tilak Kumar FNIC_FCS_DBG(KERN_INFO, fnic->lport->host, fnic->fnic_num,
473d3c995f1SHiral Patel "No VLAN descriptors in FIP VLAN response\n");
474d3c995f1SHiral Patel spin_unlock_irqrestore(&fnic->vlans_lock, flags);
475d3c995f1SHiral Patel goto out;
476d3c995f1SHiral Patel }
477d3c995f1SHiral Patel
478d3c995f1SHiral Patel vlan = list_first_entry(&fnic->vlans, struct fcoe_vlan, list);
479d3c995f1SHiral Patel fnic->set_vlan(fnic, vlan->vid);
480d3c995f1SHiral Patel vlan->state = FIP_VLAN_SENT; /* sent now */
481d3c995f1SHiral Patel vlan->sol_count++;
482d3c995f1SHiral Patel spin_unlock_irqrestore(&fnic->vlans_lock, flags);
483d3c995f1SHiral Patel
484d3c995f1SHiral Patel /* start the solicitation */
485d3c995f1SHiral Patel fcoe_ctlr_link_up(fip);
486d3c995f1SHiral Patel
487d3c995f1SHiral Patel sol_time = jiffies + msecs_to_jiffies(FCOE_CTLR_START_DELAY);
488d3c995f1SHiral Patel mod_timer(&fnic->fip_timer, round_jiffies(sol_time));
489d3c995f1SHiral Patel out:
490d3c995f1SHiral Patel return;
491d3c995f1SHiral Patel }
492d3c995f1SHiral Patel
fnic_fcoe_start_fcf_disc(struct fnic * fnic)493d3c995f1SHiral Patel static void fnic_fcoe_start_fcf_disc(struct fnic *fnic)
494d3c995f1SHiral Patel {
495d3c995f1SHiral Patel unsigned long flags;
496d3c995f1SHiral Patel struct fcoe_vlan *vlan;
497d3c995f1SHiral Patel u64 sol_time;
498d3c995f1SHiral Patel
499d3c995f1SHiral Patel spin_lock_irqsave(&fnic->vlans_lock, flags);
500d3c995f1SHiral Patel vlan = list_first_entry(&fnic->vlans, struct fcoe_vlan, list);
501d3c995f1SHiral Patel fnic->set_vlan(fnic, vlan->vid);
502d3c995f1SHiral Patel vlan->state = FIP_VLAN_SENT; /* sent now */
503d3c995f1SHiral Patel vlan->sol_count = 1;
504d3c995f1SHiral Patel spin_unlock_irqrestore(&fnic->vlans_lock, flags);
505d3c995f1SHiral Patel
506d3c995f1SHiral Patel /* start the solicitation */
507d3c995f1SHiral Patel fcoe_ctlr_link_up(&fnic->ctlr);
508d3c995f1SHiral Patel
509d3c995f1SHiral Patel sol_time = jiffies + msecs_to_jiffies(FCOE_CTLR_START_DELAY);
510d3c995f1SHiral Patel mod_timer(&fnic->fip_timer, round_jiffies(sol_time));
511d3c995f1SHiral Patel }
512d3c995f1SHiral Patel
fnic_fcoe_vlan_check(struct fnic * fnic,u16 flag)513d3c995f1SHiral Patel static int fnic_fcoe_vlan_check(struct fnic *fnic, u16 flag)
514d3c995f1SHiral Patel {
515d3c995f1SHiral Patel unsigned long flags;
516d3c995f1SHiral Patel struct fcoe_vlan *fvlan;
517d3c995f1SHiral Patel
518d3c995f1SHiral Patel spin_lock_irqsave(&fnic->vlans_lock, flags);
519d3c995f1SHiral Patel if (list_empty(&fnic->vlans)) {
520d3c995f1SHiral Patel spin_unlock_irqrestore(&fnic->vlans_lock, flags);
521d3c995f1SHiral Patel return -EINVAL;
522d3c995f1SHiral Patel }
523d3c995f1SHiral Patel
524d3c995f1SHiral Patel fvlan = list_first_entry(&fnic->vlans, struct fcoe_vlan, list);
525d3c995f1SHiral Patel if (fvlan->state == FIP_VLAN_USED) {
526d3c995f1SHiral Patel spin_unlock_irqrestore(&fnic->vlans_lock, flags);
527d3c995f1SHiral Patel return 0;
528d3c995f1SHiral Patel }
529d3c995f1SHiral Patel
530d3c995f1SHiral Patel if (fvlan->state == FIP_VLAN_SENT) {
531d3c995f1SHiral Patel fvlan->state = FIP_VLAN_USED;
532d3c995f1SHiral Patel spin_unlock_irqrestore(&fnic->vlans_lock, flags);
533d3c995f1SHiral Patel return 0;
534d3c995f1SHiral Patel }
535d3c995f1SHiral Patel spin_unlock_irqrestore(&fnic->vlans_lock, flags);
536d3c995f1SHiral Patel return -EINVAL;
537d3c995f1SHiral Patel }
538d3c995f1SHiral Patel
fnic_event_enq(struct fnic * fnic,enum fnic_evt ev)539d3c995f1SHiral Patel static void fnic_event_enq(struct fnic *fnic, enum fnic_evt ev)
540d3c995f1SHiral Patel {
541d3c995f1SHiral Patel struct fnic_event *fevt;
542d3c995f1SHiral Patel unsigned long flags;
543d3c995f1SHiral Patel
544d3c995f1SHiral Patel fevt = kmalloc(sizeof(*fevt), GFP_ATOMIC);
545d3c995f1SHiral Patel if (!fevt)
546d3c995f1SHiral Patel return;
547d3c995f1SHiral Patel
548d3c995f1SHiral Patel fevt->fnic = fnic;
549d3c995f1SHiral Patel fevt->event = ev;
550d3c995f1SHiral Patel
551d3c995f1SHiral Patel spin_lock_irqsave(&fnic->fnic_lock, flags);
552d3c995f1SHiral Patel list_add_tail(&fevt->list, &fnic->evlist);
553d3c995f1SHiral Patel spin_unlock_irqrestore(&fnic->fnic_lock, flags);
554d3c995f1SHiral Patel
555d3c995f1SHiral Patel schedule_work(&fnic->event_work);
556d3c995f1SHiral Patel }
557d3c995f1SHiral Patel
fnic_fcoe_handle_fip_frame(struct fnic * fnic,struct sk_buff * skb)558d3c995f1SHiral Patel static int fnic_fcoe_handle_fip_frame(struct fnic *fnic, struct sk_buff *skb)
559d3c995f1SHiral Patel {
560d3c995f1SHiral Patel struct fip_header *fiph;
561d3c995f1SHiral Patel int ret = 1;
562d3c995f1SHiral Patel u16 op;
563d3c995f1SHiral Patel u8 sub;
564d3c995f1SHiral Patel
565d3c995f1SHiral Patel if (!skb || !(skb->data))
566d3c995f1SHiral Patel return -1;
567d3c995f1SHiral Patel
568d3c995f1SHiral Patel if (skb_linearize(skb))
569d3c995f1SHiral Patel goto drop;
570d3c995f1SHiral Patel
571d3c995f1SHiral Patel fiph = (struct fip_header *)skb->data;
572d3c995f1SHiral Patel op = ntohs(fiph->fip_op);
573d3c995f1SHiral Patel sub = fiph->fip_subcode;
574d3c995f1SHiral Patel
575d3c995f1SHiral Patel if (FIP_VER_DECAPS(fiph->fip_ver) != FIP_VER)
576d3c995f1SHiral Patel goto drop;
577d3c995f1SHiral Patel
578d3c995f1SHiral Patel if (ntohs(fiph->fip_dl_len) * FIP_BPW + sizeof(*fiph) > skb->len)
579d3c995f1SHiral Patel goto drop;
580d3c995f1SHiral Patel
581d3c995f1SHiral Patel if (op == FIP_OP_DISC && sub == FIP_SC_ADV) {
582d3c995f1SHiral Patel if (fnic_fcoe_vlan_check(fnic, ntohs(fiph->fip_flags)))
583d3c995f1SHiral Patel goto drop;
584d3c995f1SHiral Patel /* pass it on to fcoe */
585d3c995f1SHiral Patel ret = 1;
5866a551c11SHannes Reinecke } else if (op == FIP_OP_VLAN && sub == FIP_SC_VL_NOTE) {
587d3c995f1SHiral Patel /* set the vlan as used */
588d3c995f1SHiral Patel fnic_fcoe_process_vlan_resp(fnic, skb);
589d3c995f1SHiral Patel ret = 0;
590d3c995f1SHiral Patel } else if (op == FIP_OP_CTRL && sub == FIP_SC_CLR_VLINK) {
591d3c995f1SHiral Patel /* received CVL request, restart vlan disc */
592d3c995f1SHiral Patel fnic_event_enq(fnic, FNIC_EVT_START_VLAN_DISC);
593d3c995f1SHiral Patel /* pass it on to fcoe */
594d3c995f1SHiral Patel ret = 1;
595d3c995f1SHiral Patel }
596d3c995f1SHiral Patel drop:
597d3c995f1SHiral Patel return ret;
598d3c995f1SHiral Patel }
599d3c995f1SHiral Patel
fnic_handle_fip_frame(struct work_struct * work)600d3c995f1SHiral Patel void fnic_handle_fip_frame(struct work_struct *work)
601d3c995f1SHiral Patel {
602d3c995f1SHiral Patel struct fnic *fnic = container_of(work, struct fnic, fip_frame_work);
60367125b02SHiral Patel struct fnic_stats *fnic_stats = &fnic->fnic_stats;
604d3c995f1SHiral Patel unsigned long flags;
605d3c995f1SHiral Patel struct sk_buff *skb;
606d3c995f1SHiral Patel struct ethhdr *eh;
607d3c995f1SHiral Patel
608d3c995f1SHiral Patel while ((skb = skb_dequeue(&fnic->fip_frame_queue))) {
609d3c995f1SHiral Patel spin_lock_irqsave(&fnic->fnic_lock, flags);
610d3c995f1SHiral Patel if (fnic->stop_rx_link_events) {
611d3c995f1SHiral Patel spin_unlock_irqrestore(&fnic->fnic_lock, flags);
612d3c995f1SHiral Patel dev_kfree_skb(skb);
613d3c995f1SHiral Patel return;
614d3c995f1SHiral Patel }
615d3c995f1SHiral Patel /*
616d3c995f1SHiral Patel * If we're in a transitional state, just re-queue and return.
617d3c995f1SHiral Patel * The queue will be serviced when we get to a stable state.
618d3c995f1SHiral Patel */
619d3c995f1SHiral Patel if (fnic->state != FNIC_IN_FC_MODE &&
620d3c995f1SHiral Patel fnic->state != FNIC_IN_ETH_MODE) {
621d3c995f1SHiral Patel skb_queue_head(&fnic->fip_frame_queue, skb);
622d3c995f1SHiral Patel spin_unlock_irqrestore(&fnic->fnic_lock, flags);
623d3c995f1SHiral Patel return;
624d3c995f1SHiral Patel }
625d3c995f1SHiral Patel spin_unlock_irqrestore(&fnic->fnic_lock, flags);
626d3c995f1SHiral Patel eh = (struct ethhdr *)skb->data;
627d3c995f1SHiral Patel if (eh->h_proto == htons(ETH_P_FIP)) {
628d3c995f1SHiral Patel skb_pull(skb, sizeof(*eh));
629d3c995f1SHiral Patel if (fnic_fcoe_handle_fip_frame(fnic, skb) <= 0) {
630d3c995f1SHiral Patel dev_kfree_skb(skb);
631d3c995f1SHiral Patel continue;
632d3c995f1SHiral Patel }
633d3c995f1SHiral Patel /*
634d3c995f1SHiral Patel * If there's FLOGI rejects - clear all
635d3c995f1SHiral Patel * fcf's & restart from scratch
636d3c995f1SHiral Patel */
637d3c995f1SHiral Patel if (is_fnic_fip_flogi_reject(&fnic->ctlr, skb)) {
63867125b02SHiral Patel atomic64_inc(
63967125b02SHiral Patel &fnic_stats->vlan_stats.flogi_rejects);
640d3c995f1SHiral Patel shost_printk(KERN_INFO, fnic->lport->host,
641d3c995f1SHiral Patel "Trigger a Link down - VLAN Disc\n");
642d3c995f1SHiral Patel fcoe_ctlr_link_down(&fnic->ctlr);
643d3c995f1SHiral Patel /* start FCoE VLAN discovery */
644d3c995f1SHiral Patel fnic_fcoe_send_vlan_req(fnic);
645d3c995f1SHiral Patel dev_kfree_skb(skb);
646d3c995f1SHiral Patel continue;
647d3c995f1SHiral Patel }
648d3c995f1SHiral Patel fcoe_ctlr_recv(&fnic->ctlr, skb);
649d3c995f1SHiral Patel continue;
650d3c995f1SHiral Patel }
651d3c995f1SHiral Patel }
652d3c995f1SHiral Patel }
653d3c995f1SHiral Patel
65478112e55SJoe Eykholt /**
65578112e55SJoe Eykholt * fnic_import_rq_eth_pkt() - handle received FCoE or FIP frame.
65678112e55SJoe Eykholt * @fnic: fnic instance.
65778112e55SJoe Eykholt * @skb: Ethernet Frame.
65878112e55SJoe Eykholt */
fnic_import_rq_eth_pkt(struct fnic * fnic,struct sk_buff * skb)65978112e55SJoe Eykholt static inline int fnic_import_rq_eth_pkt(struct fnic *fnic, struct sk_buff *skb)
6605df6d737SAbhijeet Joglekar {
6615df6d737SAbhijeet Joglekar struct fc_frame *fp;
6625df6d737SAbhijeet Joglekar struct ethhdr *eh;
6635df6d737SAbhijeet Joglekar struct fcoe_hdr *fcoe_hdr;
6645df6d737SAbhijeet Joglekar struct fcoe_crc_eof *ft;
6655df6d737SAbhijeet Joglekar
66678112e55SJoe Eykholt /*
66778112e55SJoe Eykholt * Undo VLAN encapsulation if present.
66878112e55SJoe Eykholt */
6695df6d737SAbhijeet Joglekar eh = (struct ethhdr *)skb->data;
67078112e55SJoe Eykholt if (eh->h_proto == htons(ETH_P_8021Q)) {
67178112e55SJoe Eykholt memmove((u8 *)eh + VLAN_HLEN, eh, ETH_ALEN * 2);
672af72868bSJohannes Berg eh = skb_pull(skb, VLAN_HLEN);
67378112e55SJoe Eykholt skb_reset_mac_header(skb);
67478112e55SJoe Eykholt }
67578112e55SJoe Eykholt if (eh->h_proto == htons(ETH_P_FIP)) {
676d7fadce3SHiral Patel if (!(fnic->config.flags & VFCF_FIP_CAPABLE)) {
677d7fadce3SHiral Patel printk(KERN_ERR "Dropped FIP frame, as firmware "
678d7fadce3SHiral Patel "uses non-FIP mode, Enable FIP "
679d7fadce3SHiral Patel "using UCSM\n");
680d7fadce3SHiral Patel goto drop;
681d7fadce3SHiral Patel }
682abb14148SHiral Shah if ((fnic_fc_trace_set_data(fnic->lport->host->host_no,
683abb14148SHiral Shah FNIC_FC_RECV|0x80, (char *)skb->data, skb->len)) != 0) {
684abb14148SHiral Shah printk(KERN_ERR "fnic ctlr frame trace error!!!");
685abb14148SHiral Shah }
686d3c995f1SHiral Patel skb_queue_tail(&fnic->fip_frame_queue, skb);
687d3c995f1SHiral Patel queue_work(fnic_fip_queue, &fnic->fip_frame_work);
68878112e55SJoe Eykholt return 1; /* let caller know packet was used */
68978112e55SJoe Eykholt }
69078112e55SJoe Eykholt if (eh->h_proto != htons(ETH_P_FCOE))
69178112e55SJoe Eykholt goto drop;
69278112e55SJoe Eykholt skb_set_network_header(skb, sizeof(*eh));
69378112e55SJoe Eykholt skb_pull(skb, sizeof(*eh));
6945df6d737SAbhijeet Joglekar
6955df6d737SAbhijeet Joglekar fcoe_hdr = (struct fcoe_hdr *)skb->data;
6965df6d737SAbhijeet Joglekar if (FC_FCOE_DECAPS_VER(fcoe_hdr) != FC_FCOE_VER)
69778112e55SJoe Eykholt goto drop;
6985df6d737SAbhijeet Joglekar
6995df6d737SAbhijeet Joglekar fp = (struct fc_frame *)skb;
7005df6d737SAbhijeet Joglekar fc_frame_init(fp);
7015df6d737SAbhijeet Joglekar fr_sof(fp) = fcoe_hdr->fcoe_sof;
7025df6d737SAbhijeet Joglekar skb_pull(skb, sizeof(struct fcoe_hdr));
70378112e55SJoe Eykholt skb_reset_transport_header(skb);
7045df6d737SAbhijeet Joglekar
70578112e55SJoe Eykholt ft = (struct fcoe_crc_eof *)(skb->data + skb->len - sizeof(*ft));
7065df6d737SAbhijeet Joglekar fr_eof(fp) = ft->fcoe_eof;
70778112e55SJoe Eykholt skb_trim(skb, skb->len - sizeof(*ft));
7085df6d737SAbhijeet Joglekar return 0;
70978112e55SJoe Eykholt drop:
71078112e55SJoe Eykholt dev_kfree_skb_irq(skb);
71178112e55SJoe Eykholt return -1;
7125df6d737SAbhijeet Joglekar }
7135df6d737SAbhijeet Joglekar
71478112e55SJoe Eykholt /**
71578112e55SJoe Eykholt * fnic_update_mac_locked() - set data MAC address and filters.
71678112e55SJoe Eykholt * @fnic: fnic instance.
71778112e55SJoe Eykholt * @new: newly-assigned FCoE MAC address.
71878112e55SJoe Eykholt *
71978112e55SJoe Eykholt * Called with the fnic lock held.
72078112e55SJoe Eykholt */
fnic_update_mac_locked(struct fnic * fnic,u8 * new)72178112e55SJoe Eykholt void fnic_update_mac_locked(struct fnic *fnic, u8 *new)
7225df6d737SAbhijeet Joglekar {
72378112e55SJoe Eykholt u8 *ctl = fnic->ctlr.ctl_src_addr;
72478112e55SJoe Eykholt u8 *data = fnic->data_src_addr;
7255df6d737SAbhijeet Joglekar
72678112e55SJoe Eykholt if (is_zero_ether_addr(new))
72778112e55SJoe Eykholt new = ctl;
7286942df7fSJoe Perches if (ether_addr_equal(data, new))
72978112e55SJoe Eykholt return;
7303df9dd0dSKaran Tilak Kumar FNIC_FCS_DBG(KERN_DEBUG, fnic->lport->host, fnic->fnic_num,
7313df9dd0dSKaran Tilak Kumar "update_mac %pM\n", new);
7326942df7fSJoe Perches if (!is_zero_ether_addr(data) && !ether_addr_equal(data, ctl))
73378112e55SJoe Eykholt vnic_dev_del_addr(fnic->vdev, data);
73478112e55SJoe Eykholt memcpy(data, new, ETH_ALEN);
7356942df7fSJoe Perches if (!ether_addr_equal(new, ctl))
73678112e55SJoe Eykholt vnic_dev_add_addr(fnic->vdev, new);
7375df6d737SAbhijeet Joglekar }
7385df6d737SAbhijeet Joglekar
73978112e55SJoe Eykholt /**
74078112e55SJoe Eykholt * fnic_update_mac() - set data MAC address and filters.
74178112e55SJoe Eykholt * @lport: local port.
74278112e55SJoe Eykholt * @new: newly-assigned FCoE MAC address.
7435df6d737SAbhijeet Joglekar */
fnic_update_mac(struct fc_lport * lport,u8 * new)74478112e55SJoe Eykholt void fnic_update_mac(struct fc_lport *lport, u8 *new)
74578112e55SJoe Eykholt {
74678112e55SJoe Eykholt struct fnic *fnic = lport_priv(lport);
7475df6d737SAbhijeet Joglekar
74878112e55SJoe Eykholt spin_lock_irq(&fnic->fnic_lock);
74978112e55SJoe Eykholt fnic_update_mac_locked(fnic, new);
75078112e55SJoe Eykholt spin_unlock_irq(&fnic->fnic_lock);
7515df6d737SAbhijeet Joglekar }
7525df6d737SAbhijeet Joglekar
75378112e55SJoe Eykholt /**
75478112e55SJoe Eykholt * fnic_set_port_id() - set the port_ID after successful FLOGI.
75578112e55SJoe Eykholt * @lport: local port.
75678112e55SJoe Eykholt * @port_id: assigned FC_ID.
75778112e55SJoe Eykholt * @fp: received frame containing the FLOGI accept or NULL.
75878112e55SJoe Eykholt *
75978112e55SJoe Eykholt * This is called from libfc when a new FC_ID has been assigned.
76078112e55SJoe Eykholt * This causes us to reset the firmware to FC_MODE and setup the new MAC
76178112e55SJoe Eykholt * address and FC_ID.
76278112e55SJoe Eykholt *
76378112e55SJoe Eykholt * It is also called with FC_ID 0 when we're logged off.
76478112e55SJoe Eykholt *
76578112e55SJoe Eykholt * If the FC_ID is due to point-to-point, fp may be NULL.
7665df6d737SAbhijeet Joglekar */
fnic_set_port_id(struct fc_lport * lport,u32 port_id,struct fc_frame * fp)76778112e55SJoe Eykholt void fnic_set_port_id(struct fc_lport *lport, u32 port_id, struct fc_frame *fp)
76878112e55SJoe Eykholt {
76978112e55SJoe Eykholt struct fnic *fnic = lport_priv(lport);
77078112e55SJoe Eykholt u8 *mac;
77178112e55SJoe Eykholt int ret;
7725df6d737SAbhijeet Joglekar
7733df9dd0dSKaran Tilak Kumar FNIC_FCS_DBG(KERN_DEBUG, lport->host, fnic->fnic_num,
7743df9dd0dSKaran Tilak Kumar "set port_id 0x%x fp 0x%p\n",
77578112e55SJoe Eykholt port_id, fp);
7765df6d737SAbhijeet Joglekar
77778112e55SJoe Eykholt /*
77878112e55SJoe Eykholt * If we're clearing the FC_ID, change to use the ctl_src_addr.
77978112e55SJoe Eykholt * Set ethernet mode to send FLOGI.
78078112e55SJoe Eykholt */
78178112e55SJoe Eykholt if (!port_id) {
78278112e55SJoe Eykholt fnic_update_mac(lport, fnic->ctlr.ctl_src_addr);
78378112e55SJoe Eykholt fnic_set_eth_mode(fnic);
78478112e55SJoe Eykholt return;
78578112e55SJoe Eykholt }
78678112e55SJoe Eykholt
78778112e55SJoe Eykholt if (fp) {
78878112e55SJoe Eykholt mac = fr_cb(fp)->granted_mac;
78978112e55SJoe Eykholt if (is_zero_ether_addr(mac)) {
79078112e55SJoe Eykholt /* non-FIP - FLOGI already accepted - ignore return */
79178112e55SJoe Eykholt fcoe_ctlr_recv_flogi(&fnic->ctlr, lport, fp);
79278112e55SJoe Eykholt }
79378112e55SJoe Eykholt fnic_update_mac(lport, mac);
79478112e55SJoe Eykholt }
79578112e55SJoe Eykholt
79678112e55SJoe Eykholt /* Change state to reflect transition to FC mode */
79778112e55SJoe Eykholt spin_lock_irq(&fnic->fnic_lock);
79878112e55SJoe Eykholt if (fnic->state == FNIC_IN_ETH_MODE || fnic->state == FNIC_IN_FC_MODE)
7995df6d737SAbhijeet Joglekar fnic->state = FNIC_IN_ETH_TRANS_FC_MODE;
80078112e55SJoe Eykholt else {
8013df9dd0dSKaran Tilak Kumar FNIC_FCS_DBG(KERN_ERR, fnic->lport->host, fnic->fnic_num,
8023df9dd0dSKaran Tilak Kumar "Unexpected fnic state: %s processing FLOGI response",
8035df6d737SAbhijeet Joglekar fnic_state_to_str(fnic->state));
80478112e55SJoe Eykholt spin_unlock_irq(&fnic->fnic_lock);
80578112e55SJoe Eykholt return;
8065df6d737SAbhijeet Joglekar }
80778112e55SJoe Eykholt spin_unlock_irq(&fnic->fnic_lock);
8085df6d737SAbhijeet Joglekar
8095df6d737SAbhijeet Joglekar /*
81078112e55SJoe Eykholt * Send FLOGI registration to firmware to set up FC mode.
81178112e55SJoe Eykholt * The new address will be set up when registration completes.
8125df6d737SAbhijeet Joglekar */
81378112e55SJoe Eykholt ret = fnic_flogi_reg_handler(fnic, port_id);
8145df6d737SAbhijeet Joglekar
8155df6d737SAbhijeet Joglekar if (ret < 0) {
81678112e55SJoe Eykholt spin_lock_irq(&fnic->fnic_lock);
8175df6d737SAbhijeet Joglekar if (fnic->state == FNIC_IN_ETH_TRANS_FC_MODE)
8185df6d737SAbhijeet Joglekar fnic->state = FNIC_IN_ETH_MODE;
81978112e55SJoe Eykholt spin_unlock_irq(&fnic->fnic_lock);
8205df6d737SAbhijeet Joglekar }
8215df6d737SAbhijeet Joglekar }
8225df6d737SAbhijeet Joglekar
fnic_rq_cmpl_frame_recv(struct vnic_rq * rq,struct cq_desc * cq_desc,struct vnic_rq_buf * buf,int skipped,void * opaque)8235df6d737SAbhijeet Joglekar static void fnic_rq_cmpl_frame_recv(struct vnic_rq *rq, struct cq_desc
8245df6d737SAbhijeet Joglekar *cq_desc, struct vnic_rq_buf *buf,
8255df6d737SAbhijeet Joglekar int skipped __attribute__((unused)),
8265df6d737SAbhijeet Joglekar void *opaque)
8275df6d737SAbhijeet Joglekar {
8285df6d737SAbhijeet Joglekar struct fnic *fnic = vnic_dev_priv(rq->vdev);
8295df6d737SAbhijeet Joglekar struct sk_buff *skb;
8305df6d737SAbhijeet Joglekar struct fc_frame *fp;
83167125b02SHiral Patel struct fnic_stats *fnic_stats = &fnic->fnic_stats;
8325df6d737SAbhijeet Joglekar u8 type, color, eop, sop, ingress_port, vlan_stripped;
8335df6d737SAbhijeet Joglekar u8 fcoe = 0, fcoe_sof, fcoe_eof;
8345df6d737SAbhijeet Joglekar u8 fcoe_fc_crc_ok = 1, fcoe_enc_error = 0;
8355df6d737SAbhijeet Joglekar u8 tcp_udp_csum_ok, udp, tcp, ipv4_csum_ok;
8365df6d737SAbhijeet Joglekar u8 ipv6, ipv4, ipv4_fragment, rss_type, csum_not_calc;
8375df6d737SAbhijeet Joglekar u8 fcs_ok = 1, packet_error = 0;
8385df6d737SAbhijeet Joglekar u16 q_number, completed_index, bytes_written = 0, vlan, checksum;
8395df6d737SAbhijeet Joglekar u32 rss_hash;
8405df6d737SAbhijeet Joglekar u16 exchange_id, tmpl;
8415df6d737SAbhijeet Joglekar u8 sof = 0;
8425df6d737SAbhijeet Joglekar u8 eof = 0;
8435df6d737SAbhijeet Joglekar u32 fcp_bytes_written = 0;
8445df6d737SAbhijeet Joglekar unsigned long flags;
8455df6d737SAbhijeet Joglekar
8467f9b0f77SChristoph Hellwig dma_unmap_single(&fnic->pdev->dev, buf->dma_addr, buf->len,
8477f9b0f77SChristoph Hellwig DMA_FROM_DEVICE);
8485df6d737SAbhijeet Joglekar skb = buf->os_buf;
84978112e55SJoe Eykholt fp = (struct fc_frame *)skb;
8505df6d737SAbhijeet Joglekar buf->os_buf = NULL;
8515df6d737SAbhijeet Joglekar
8525df6d737SAbhijeet Joglekar cq_desc_dec(cq_desc, &type, &color, &q_number, &completed_index);
8535df6d737SAbhijeet Joglekar if (type == CQ_DESC_TYPE_RQ_FCP) {
8545df6d737SAbhijeet Joglekar cq_fcp_rq_desc_dec((struct cq_fcp_rq_desc *)cq_desc,
8555df6d737SAbhijeet Joglekar &type, &color, &q_number, &completed_index,
8565df6d737SAbhijeet Joglekar &eop, &sop, &fcoe_fc_crc_ok, &exchange_id,
8575df6d737SAbhijeet Joglekar &tmpl, &fcp_bytes_written, &sof, &eof,
8585df6d737SAbhijeet Joglekar &ingress_port, &packet_error,
8595df6d737SAbhijeet Joglekar &fcoe_enc_error, &fcs_ok, &vlan_stripped,
8605df6d737SAbhijeet Joglekar &vlan);
86178112e55SJoe Eykholt skb_trim(skb, fcp_bytes_written);
86278112e55SJoe Eykholt fr_sof(fp) = sof;
86378112e55SJoe Eykholt fr_eof(fp) = eof;
8645df6d737SAbhijeet Joglekar
8655df6d737SAbhijeet Joglekar } else if (type == CQ_DESC_TYPE_RQ_ENET) {
8665df6d737SAbhijeet Joglekar cq_enet_rq_desc_dec((struct cq_enet_rq_desc *)cq_desc,
8675df6d737SAbhijeet Joglekar &type, &color, &q_number, &completed_index,
8685df6d737SAbhijeet Joglekar &ingress_port, &fcoe, &eop, &sop,
8695df6d737SAbhijeet Joglekar &rss_type, &csum_not_calc, &rss_hash,
8705df6d737SAbhijeet Joglekar &bytes_written, &packet_error,
8715df6d737SAbhijeet Joglekar &vlan_stripped, &vlan, &checksum,
8725df6d737SAbhijeet Joglekar &fcoe_sof, &fcoe_fc_crc_ok,
8735df6d737SAbhijeet Joglekar &fcoe_enc_error, &fcoe_eof,
8745df6d737SAbhijeet Joglekar &tcp_udp_csum_ok, &udp, &tcp,
8755df6d737SAbhijeet Joglekar &ipv4_csum_ok, &ipv6, &ipv4,
8765df6d737SAbhijeet Joglekar &ipv4_fragment, &fcs_ok);
87778112e55SJoe Eykholt skb_trim(skb, bytes_written);
87878112e55SJoe Eykholt if (!fcs_ok) {
87967125b02SHiral Patel atomic64_inc(&fnic_stats->misc_stats.frame_errors);
8803df9dd0dSKaran Tilak Kumar FNIC_FCS_DBG(KERN_DEBUG, fnic->lport->host, fnic->fnic_num,
88178112e55SJoe Eykholt "fcs error. dropping packet.\n");
88278112e55SJoe Eykholt goto drop;
88378112e55SJoe Eykholt }
88478112e55SJoe Eykholt if (fnic_import_rq_eth_pkt(fnic, skb))
88578112e55SJoe Eykholt return;
8865df6d737SAbhijeet Joglekar
8875df6d737SAbhijeet Joglekar } else {
8885df6d737SAbhijeet Joglekar /* wrong CQ type*/
8895df6d737SAbhijeet Joglekar shost_printk(KERN_ERR, fnic->lport->host,
8905df6d737SAbhijeet Joglekar "fnic rq_cmpl wrong cq type x%x\n", type);
8915df6d737SAbhijeet Joglekar goto drop;
8925df6d737SAbhijeet Joglekar }
8935df6d737SAbhijeet Joglekar
8945df6d737SAbhijeet Joglekar if (!fcs_ok || packet_error || !fcoe_fc_crc_ok || fcoe_enc_error) {
89567125b02SHiral Patel atomic64_inc(&fnic_stats->misc_stats.frame_errors);
8963df9dd0dSKaran Tilak Kumar FNIC_FCS_DBG(KERN_DEBUG, fnic->lport->host, fnic->fnic_num,
8975df6d737SAbhijeet Joglekar "fnic rq_cmpl fcoe x%x fcsok x%x"
8985df6d737SAbhijeet Joglekar " pkterr x%x fcoe_fc_crc_ok x%x, fcoe_enc_err"
8995df6d737SAbhijeet Joglekar " x%x\n",
9005df6d737SAbhijeet Joglekar fcoe, fcs_ok, packet_error,
9015df6d737SAbhijeet Joglekar fcoe_fc_crc_ok, fcoe_enc_error);
9025df6d737SAbhijeet Joglekar goto drop;
9035df6d737SAbhijeet Joglekar }
9045df6d737SAbhijeet Joglekar
9055df6d737SAbhijeet Joglekar spin_lock_irqsave(&fnic->fnic_lock, flags);
9065df6d737SAbhijeet Joglekar if (fnic->stop_rx_link_events) {
9075df6d737SAbhijeet Joglekar spin_unlock_irqrestore(&fnic->fnic_lock, flags);
9085df6d737SAbhijeet Joglekar goto drop;
9095df6d737SAbhijeet Joglekar }
9105df6d737SAbhijeet Joglekar fr_dev(fp) = fnic->lport;
9115df6d737SAbhijeet Joglekar spin_unlock_irqrestore(&fnic->fnic_lock, flags);
912abb14148SHiral Shah if ((fnic_fc_trace_set_data(fnic->lport->host->host_no, FNIC_FC_RECV,
913abb14148SHiral Shah (char *)skb->data, skb->len)) != 0) {
914abb14148SHiral Shah printk(KERN_ERR "fnic ctlr frame trace error!!!");
915abb14148SHiral Shah }
9165df6d737SAbhijeet Joglekar
9175df6d737SAbhijeet Joglekar skb_queue_tail(&fnic->frame_queue, skb);
9185df6d737SAbhijeet Joglekar queue_work(fnic_event_queue, &fnic->frame_work);
9195df6d737SAbhijeet Joglekar
9205df6d737SAbhijeet Joglekar return;
9215df6d737SAbhijeet Joglekar drop:
9225df6d737SAbhijeet Joglekar dev_kfree_skb_irq(skb);
9235df6d737SAbhijeet Joglekar }
9245df6d737SAbhijeet Joglekar
fnic_rq_cmpl_handler_cont(struct vnic_dev * vdev,struct cq_desc * cq_desc,u8 type,u16 q_number,u16 completed_index,void * opaque)9255df6d737SAbhijeet Joglekar static int fnic_rq_cmpl_handler_cont(struct vnic_dev *vdev,
9265df6d737SAbhijeet Joglekar struct cq_desc *cq_desc, u8 type,
9275df6d737SAbhijeet Joglekar u16 q_number, u16 completed_index,
9285df6d737SAbhijeet Joglekar void *opaque)
9295df6d737SAbhijeet Joglekar {
9305df6d737SAbhijeet Joglekar struct fnic *fnic = vnic_dev_priv(vdev);
9315df6d737SAbhijeet Joglekar
9325df6d737SAbhijeet Joglekar vnic_rq_service(&fnic->rq[q_number], cq_desc, completed_index,
9335df6d737SAbhijeet Joglekar VNIC_RQ_RETURN_DESC, fnic_rq_cmpl_frame_recv,
9345df6d737SAbhijeet Joglekar NULL);
9355df6d737SAbhijeet Joglekar return 0;
9365df6d737SAbhijeet Joglekar }
9375df6d737SAbhijeet Joglekar
fnic_rq_cmpl_handler(struct fnic * fnic,int rq_work_to_do)9385df6d737SAbhijeet Joglekar int fnic_rq_cmpl_handler(struct fnic *fnic, int rq_work_to_do)
9395df6d737SAbhijeet Joglekar {
9405df6d737SAbhijeet Joglekar unsigned int tot_rq_work_done = 0, cur_work_done;
9415df6d737SAbhijeet Joglekar unsigned int i;
9425df6d737SAbhijeet Joglekar int err;
9435df6d737SAbhijeet Joglekar
9445df6d737SAbhijeet Joglekar for (i = 0; i < fnic->rq_count; i++) {
9455df6d737SAbhijeet Joglekar cur_work_done = vnic_cq_service(&fnic->cq[i], rq_work_to_do,
9465df6d737SAbhijeet Joglekar fnic_rq_cmpl_handler_cont,
9475df6d737SAbhijeet Joglekar NULL);
9485df6d737SAbhijeet Joglekar if (cur_work_done) {
9495df6d737SAbhijeet Joglekar err = vnic_rq_fill(&fnic->rq[i], fnic_alloc_rq_frame);
9505df6d737SAbhijeet Joglekar if (err)
9515df6d737SAbhijeet Joglekar shost_printk(KERN_ERR, fnic->lport->host,
95225985edcSLucas De Marchi "fnic_alloc_rq_frame can't alloc"
9535df6d737SAbhijeet Joglekar " frame\n");
9545df6d737SAbhijeet Joglekar }
9555df6d737SAbhijeet Joglekar tot_rq_work_done += cur_work_done;
9565df6d737SAbhijeet Joglekar }
9575df6d737SAbhijeet Joglekar
9585df6d737SAbhijeet Joglekar return tot_rq_work_done;
9595df6d737SAbhijeet Joglekar }
9605df6d737SAbhijeet Joglekar
9615df6d737SAbhijeet Joglekar /*
9625df6d737SAbhijeet Joglekar * This function is called once at init time to allocate and fill RQ
9635df6d737SAbhijeet Joglekar * buffers. Subsequently, it is called in the interrupt context after RQ
9645df6d737SAbhijeet Joglekar * buffer processing to replenish the buffers in the RQ
9655df6d737SAbhijeet Joglekar */
fnic_alloc_rq_frame(struct vnic_rq * rq)9665df6d737SAbhijeet Joglekar int fnic_alloc_rq_frame(struct vnic_rq *rq)
9675df6d737SAbhijeet Joglekar {
9685df6d737SAbhijeet Joglekar struct fnic *fnic = vnic_dev_priv(rq->vdev);
9695df6d737SAbhijeet Joglekar struct sk_buff *skb;
9705df6d737SAbhijeet Joglekar u16 len;
9715df6d737SAbhijeet Joglekar dma_addr_t pa;
972fd6ddfa4SMaurizio Lombardi int r;
9735df6d737SAbhijeet Joglekar
9745df6d737SAbhijeet Joglekar len = FC_FRAME_HEADROOM + FC_MAX_FRAME + FC_FRAME_TAILROOM;
9755df6d737SAbhijeet Joglekar skb = dev_alloc_skb(len);
9765df6d737SAbhijeet Joglekar if (!skb) {
9773df9dd0dSKaran Tilak Kumar FNIC_FCS_DBG(KERN_DEBUG, fnic->lport->host, fnic->fnic_num,
9785df6d737SAbhijeet Joglekar "Unable to allocate RQ sk_buff\n");
9795df6d737SAbhijeet Joglekar return -ENOMEM;
9805df6d737SAbhijeet Joglekar }
9815df6d737SAbhijeet Joglekar skb_reset_mac_header(skb);
9825df6d737SAbhijeet Joglekar skb_reset_transport_header(skb);
9835df6d737SAbhijeet Joglekar skb_reset_network_header(skb);
9845df6d737SAbhijeet Joglekar skb_put(skb, len);
9857f9b0f77SChristoph Hellwig pa = dma_map_single(&fnic->pdev->dev, skb->data, len, DMA_FROM_DEVICE);
9867f9b0f77SChristoph Hellwig if (dma_mapping_error(&fnic->pdev->dev, pa)) {
987dd7328e4SDan Carpenter r = -ENOMEM;
988fd6ddfa4SMaurizio Lombardi printk(KERN_ERR "PCI mapping failed with error %d\n", r);
989fd6ddfa4SMaurizio Lombardi goto free_skb;
990fd6ddfa4SMaurizio Lombardi }
991fd6ddfa4SMaurizio Lombardi
9925df6d737SAbhijeet Joglekar fnic_queue_rq_desc(rq, skb, pa, len);
9935df6d737SAbhijeet Joglekar return 0;
994fd6ddfa4SMaurizio Lombardi
995fd6ddfa4SMaurizio Lombardi free_skb:
996fd6ddfa4SMaurizio Lombardi kfree_skb(skb);
997fd6ddfa4SMaurizio Lombardi return r;
9985df6d737SAbhijeet Joglekar }
9995df6d737SAbhijeet Joglekar
fnic_free_rq_buf(struct vnic_rq * rq,struct vnic_rq_buf * buf)10005df6d737SAbhijeet Joglekar void fnic_free_rq_buf(struct vnic_rq *rq, struct vnic_rq_buf *buf)
10015df6d737SAbhijeet Joglekar {
10025df6d737SAbhijeet Joglekar struct fc_frame *fp = buf->os_buf;
10035df6d737SAbhijeet Joglekar struct fnic *fnic = vnic_dev_priv(rq->vdev);
10045df6d737SAbhijeet Joglekar
10057f9b0f77SChristoph Hellwig dma_unmap_single(&fnic->pdev->dev, buf->dma_addr, buf->len,
10067f9b0f77SChristoph Hellwig DMA_FROM_DEVICE);
10075df6d737SAbhijeet Joglekar
10085df6d737SAbhijeet Joglekar dev_kfree_skb(fp_skb(fp));
10095df6d737SAbhijeet Joglekar buf->os_buf = NULL;
10105df6d737SAbhijeet Joglekar }
10115df6d737SAbhijeet Joglekar
101278112e55SJoe Eykholt /**
101378112e55SJoe Eykholt * fnic_eth_send() - Send Ethernet frame.
101478112e55SJoe Eykholt * @fip: fcoe_ctlr instance.
101578112e55SJoe Eykholt * @skb: Ethernet Frame, FIP, without VLAN encapsulation.
101678112e55SJoe Eykholt */
fnic_eth_send(struct fcoe_ctlr * fip,struct sk_buff * skb)101778112e55SJoe Eykholt void fnic_eth_send(struct fcoe_ctlr *fip, struct sk_buff *skb)
10185df6d737SAbhijeet Joglekar {
101978112e55SJoe Eykholt struct fnic *fnic = fnic_from_ctlr(fip);
102078112e55SJoe Eykholt struct vnic_wq *wq = &fnic->wq[0];
102178112e55SJoe Eykholt dma_addr_t pa;
102278112e55SJoe Eykholt struct ethhdr *eth_hdr;
102378112e55SJoe Eykholt struct vlan_ethhdr *vlan_hdr;
102478112e55SJoe Eykholt unsigned long flags;
102578112e55SJoe Eykholt
102678112e55SJoe Eykholt if (!fnic->vlan_hw_insert) {
102778112e55SJoe Eykholt eth_hdr = (struct ethhdr *)skb_mac_header(skb);
1028d58ff351SJohannes Berg vlan_hdr = skb_push(skb, sizeof(*vlan_hdr) - sizeof(*eth_hdr));
102978112e55SJoe Eykholt memcpy(vlan_hdr, eth_hdr, 2 * ETH_ALEN);
103078112e55SJoe Eykholt vlan_hdr->h_vlan_proto = htons(ETH_P_8021Q);
103178112e55SJoe Eykholt vlan_hdr->h_vlan_encapsulated_proto = eth_hdr->h_proto;
103278112e55SJoe Eykholt vlan_hdr->h_vlan_TCI = htons(fnic->vlan_id);
1033abb14148SHiral Shah if ((fnic_fc_trace_set_data(fnic->lport->host->host_no,
1034abb14148SHiral Shah FNIC_FC_SEND|0x80, (char *)eth_hdr, skb->len)) != 0) {
1035abb14148SHiral Shah printk(KERN_ERR "fnic ctlr frame trace error!!!");
1036abb14148SHiral Shah }
1037abb14148SHiral Shah } else {
1038abb14148SHiral Shah if ((fnic_fc_trace_set_data(fnic->lport->host->host_no,
1039abb14148SHiral Shah FNIC_FC_SEND|0x80, (char *)skb->data, skb->len)) != 0) {
1040abb14148SHiral Shah printk(KERN_ERR "fnic ctlr frame trace error!!!");
1041abb14148SHiral Shah }
10425df6d737SAbhijeet Joglekar }
10435df6d737SAbhijeet Joglekar
10447f9b0f77SChristoph Hellwig pa = dma_map_single(&fnic->pdev->dev, skb->data, skb->len,
10457f9b0f77SChristoph Hellwig DMA_TO_DEVICE);
10467f9b0f77SChristoph Hellwig if (dma_mapping_error(&fnic->pdev->dev, pa)) {
10477f9b0f77SChristoph Hellwig printk(KERN_ERR "DMA mapping failed\n");
1048fd6ddfa4SMaurizio Lombardi goto free_skb;
104978112e55SJoe Eykholt }
105078112e55SJoe Eykholt
1051fd6ddfa4SMaurizio Lombardi spin_lock_irqsave(&fnic->wq_lock[0], flags);
1052fd6ddfa4SMaurizio Lombardi if (!vnic_wq_desc_avail(wq))
1053fd6ddfa4SMaurizio Lombardi goto irq_restore;
1054fd6ddfa4SMaurizio Lombardi
105578112e55SJoe Eykholt fnic_queue_wq_eth_desc(wq, skb, pa, skb->len,
1056c0773b7cSHiral Patel 0 /* hw inserts cos value */,
1057c0773b7cSHiral Patel fnic->vlan_id, 1);
105878112e55SJoe Eykholt spin_unlock_irqrestore(&fnic->wq_lock[0], flags);
1059fd6ddfa4SMaurizio Lombardi return;
1060fd6ddfa4SMaurizio Lombardi
1061fd6ddfa4SMaurizio Lombardi irq_restore:
1062fd6ddfa4SMaurizio Lombardi spin_unlock_irqrestore(&fnic->wq_lock[0], flags);
10637f9b0f77SChristoph Hellwig dma_unmap_single(&fnic->pdev->dev, pa, skb->len, DMA_TO_DEVICE);
1064fd6ddfa4SMaurizio Lombardi free_skb:
1065fd6ddfa4SMaurizio Lombardi kfree_skb(skb);
106678112e55SJoe Eykholt }
106778112e55SJoe Eykholt
106878112e55SJoe Eykholt /*
106978112e55SJoe Eykholt * Send FC frame.
107078112e55SJoe Eykholt */
fnic_send_frame(struct fnic * fnic,struct fc_frame * fp)107178112e55SJoe Eykholt static int fnic_send_frame(struct fnic *fnic, struct fc_frame *fp)
10725df6d737SAbhijeet Joglekar {
10735df6d737SAbhijeet Joglekar struct vnic_wq *wq = &fnic->wq[0];
10745df6d737SAbhijeet Joglekar struct sk_buff *skb;
10755df6d737SAbhijeet Joglekar dma_addr_t pa;
10765df6d737SAbhijeet Joglekar struct ethhdr *eth_hdr;
10775df6d737SAbhijeet Joglekar struct vlan_ethhdr *vlan_hdr;
10785df6d737SAbhijeet Joglekar struct fcoe_hdr *fcoe_hdr;
10795df6d737SAbhijeet Joglekar struct fc_frame_header *fh;
10805df6d737SAbhijeet Joglekar u32 tot_len, eth_hdr_len;
10815df6d737SAbhijeet Joglekar int ret = 0;
10825df6d737SAbhijeet Joglekar unsigned long flags;
10835df6d737SAbhijeet Joglekar
10845df6d737SAbhijeet Joglekar fh = fc_frame_header_get(fp);
10855df6d737SAbhijeet Joglekar skb = fp_skb(fp);
10865df6d737SAbhijeet Joglekar
108778112e55SJoe Eykholt if (unlikely(fh->fh_r_ctl == FC_RCTL_ELS_REQ) &&
108878112e55SJoe Eykholt fcoe_ctlr_els_send(&fnic->ctlr, fnic->lport, skb))
108978112e55SJoe Eykholt return 0;
109078112e55SJoe Eykholt
10915df6d737SAbhijeet Joglekar if (!fnic->vlan_hw_insert) {
10925df6d737SAbhijeet Joglekar eth_hdr_len = sizeof(*vlan_hdr) + sizeof(*fcoe_hdr);
1093d58ff351SJohannes Berg vlan_hdr = skb_push(skb, eth_hdr_len);
10945df6d737SAbhijeet Joglekar eth_hdr = (struct ethhdr *)vlan_hdr;
10955df6d737SAbhijeet Joglekar vlan_hdr->h_vlan_proto = htons(ETH_P_8021Q);
10965df6d737SAbhijeet Joglekar vlan_hdr->h_vlan_encapsulated_proto = htons(ETH_P_FCOE);
10975df6d737SAbhijeet Joglekar vlan_hdr->h_vlan_TCI = htons(fnic->vlan_id);
10985df6d737SAbhijeet Joglekar fcoe_hdr = (struct fcoe_hdr *)(vlan_hdr + 1);
10995df6d737SAbhijeet Joglekar } else {
11005df6d737SAbhijeet Joglekar eth_hdr_len = sizeof(*eth_hdr) + sizeof(*fcoe_hdr);
1101d58ff351SJohannes Berg eth_hdr = skb_push(skb, eth_hdr_len);
11025df6d737SAbhijeet Joglekar eth_hdr->h_proto = htons(ETH_P_FCOE);
11035df6d737SAbhijeet Joglekar fcoe_hdr = (struct fcoe_hdr *)(eth_hdr + 1);
11045df6d737SAbhijeet Joglekar }
11055df6d737SAbhijeet Joglekar
110678112e55SJoe Eykholt if (fnic->ctlr.map_dest)
11075df6d737SAbhijeet Joglekar fc_fcoe_set_mac(eth_hdr->h_dest, fh->fh_d_id);
11085df6d737SAbhijeet Joglekar else
110978112e55SJoe Eykholt memcpy(eth_hdr->h_dest, fnic->ctlr.dest_addr, ETH_ALEN);
11105df6d737SAbhijeet Joglekar memcpy(eth_hdr->h_source, fnic->data_src_addr, ETH_ALEN);
11115df6d737SAbhijeet Joglekar
11125df6d737SAbhijeet Joglekar tot_len = skb->len;
11135df6d737SAbhijeet Joglekar BUG_ON(tot_len % 4);
11145df6d737SAbhijeet Joglekar
11155df6d737SAbhijeet Joglekar memset(fcoe_hdr, 0, sizeof(*fcoe_hdr));
11165df6d737SAbhijeet Joglekar fcoe_hdr->fcoe_sof = fr_sof(fp);
11175df6d737SAbhijeet Joglekar if (FC_FCOE_VER)
11185df6d737SAbhijeet Joglekar FC_FCOE_ENCAPS_VER(fcoe_hdr, FC_FCOE_VER);
11195df6d737SAbhijeet Joglekar
11207f9b0f77SChristoph Hellwig pa = dma_map_single(&fnic->pdev->dev, eth_hdr, tot_len, DMA_TO_DEVICE);
11217f9b0f77SChristoph Hellwig if (dma_mapping_error(&fnic->pdev->dev, pa)) {
1122dd7328e4SDan Carpenter ret = -ENOMEM;
1123fd6ddfa4SMaurizio Lombardi printk(KERN_ERR "DMA map failed with error %d\n", ret);
1124fd6ddfa4SMaurizio Lombardi goto free_skb_on_err;
1125fd6ddfa4SMaurizio Lombardi }
1126fd6ddfa4SMaurizio Lombardi
1127abb14148SHiral Shah if ((fnic_fc_trace_set_data(fnic->lport->host->host_no, FNIC_FC_SEND,
1128abb14148SHiral Shah (char *)eth_hdr, tot_len)) != 0) {
1129abb14148SHiral Shah printk(KERN_ERR "fnic ctlr frame trace error!!!");
1130abb14148SHiral Shah }
1131abb14148SHiral Shah
11325df6d737SAbhijeet Joglekar spin_lock_irqsave(&fnic->wq_lock[0], flags);
11335df6d737SAbhijeet Joglekar
11345df6d737SAbhijeet Joglekar if (!vnic_wq_desc_avail(wq)) {
11357f9b0f77SChristoph Hellwig dma_unmap_single(&fnic->pdev->dev, pa, tot_len, DMA_TO_DEVICE);
11365df6d737SAbhijeet Joglekar ret = -1;
1137fd6ddfa4SMaurizio Lombardi goto irq_restore;
11385df6d737SAbhijeet Joglekar }
11395df6d737SAbhijeet Joglekar
11405df6d737SAbhijeet Joglekar fnic_queue_wq_desc(wq, skb, pa, tot_len, fr_eof(fp),
1141c0773b7cSHiral Patel 0 /* hw inserts cos value */,
1142c0773b7cSHiral Patel fnic->vlan_id, 1, 1, 1);
1143fd6ddfa4SMaurizio Lombardi
1144fd6ddfa4SMaurizio Lombardi irq_restore:
11455df6d737SAbhijeet Joglekar spin_unlock_irqrestore(&fnic->wq_lock[0], flags);
11465df6d737SAbhijeet Joglekar
1147fd6ddfa4SMaurizio Lombardi free_skb_on_err:
11485df6d737SAbhijeet Joglekar if (ret)
11495df6d737SAbhijeet Joglekar dev_kfree_skb_any(fp_skb(fp));
11505df6d737SAbhijeet Joglekar
11515df6d737SAbhijeet Joglekar return ret;
11525df6d737SAbhijeet Joglekar }
11535df6d737SAbhijeet Joglekar
11545df6d737SAbhijeet Joglekar /*
11555df6d737SAbhijeet Joglekar * fnic_send
11565df6d737SAbhijeet Joglekar * Routine to send a raw frame
11575df6d737SAbhijeet Joglekar */
fnic_send(struct fc_lport * lp,struct fc_frame * fp)11585df6d737SAbhijeet Joglekar int fnic_send(struct fc_lport *lp, struct fc_frame *fp)
11595df6d737SAbhijeet Joglekar {
11605df6d737SAbhijeet Joglekar struct fnic *fnic = lport_priv(lp);
11615df6d737SAbhijeet Joglekar unsigned long flags;
11625df6d737SAbhijeet Joglekar
11635df6d737SAbhijeet Joglekar if (fnic->in_remove) {
11645df6d737SAbhijeet Joglekar dev_kfree_skb(fp_skb(fp));
116578112e55SJoe Eykholt return -1;
11665df6d737SAbhijeet Joglekar }
11675df6d737SAbhijeet Joglekar
116878112e55SJoe Eykholt /*
116978112e55SJoe Eykholt * Queue frame if in a transitional state.
117078112e55SJoe Eykholt * This occurs while registering the Port_ID / MAC address after FLOGI.
117178112e55SJoe Eykholt */
117278112e55SJoe Eykholt spin_lock_irqsave(&fnic->fnic_lock, flags);
117378112e55SJoe Eykholt if (fnic->state != FNIC_IN_FC_MODE && fnic->state != FNIC_IN_ETH_MODE) {
117478112e55SJoe Eykholt skb_queue_tail(&fnic->tx_queue, fp_skb(fp));
117578112e55SJoe Eykholt spin_unlock_irqrestore(&fnic->fnic_lock, flags);
117678112e55SJoe Eykholt return 0;
117778112e55SJoe Eykholt }
117878112e55SJoe Eykholt spin_unlock_irqrestore(&fnic->fnic_lock, flags);
11795df6d737SAbhijeet Joglekar
118078112e55SJoe Eykholt return fnic_send_frame(fnic, fp);
118178112e55SJoe Eykholt }
118278112e55SJoe Eykholt
118378112e55SJoe Eykholt /**
118478112e55SJoe Eykholt * fnic_flush_tx() - send queued frames.
1185*379a58caSLee Duncan * @work: pointer to work element
118678112e55SJoe Eykholt *
118778112e55SJoe Eykholt * Send frames that were waiting to go out in FC or Ethernet mode.
118878112e55SJoe Eykholt * Whenever changing modes we purge queued frames, so these frames should
118978112e55SJoe Eykholt * be queued for the stable mode that we're in, either FC or Ethernet.
119078112e55SJoe Eykholt *
119178112e55SJoe Eykholt * Called without fnic_lock held.
119278112e55SJoe Eykholt */
fnic_flush_tx(struct work_struct * work)1193*379a58caSLee Duncan void fnic_flush_tx(struct work_struct *work)
119478112e55SJoe Eykholt {
1195*379a58caSLee Duncan struct fnic *fnic = container_of(work, struct fnic, flush_work);
119678112e55SJoe Eykholt struct sk_buff *skb;
119778112e55SJoe Eykholt struct fc_frame *fp;
119878112e55SJoe Eykholt
1199d9e9ab56SBrian Uchino while ((skb = skb_dequeue(&fnic->tx_queue))) {
120078112e55SJoe Eykholt fp = (struct fc_frame *)skb;
120178112e55SJoe Eykholt fnic_send_frame(fnic, fp);
120278112e55SJoe Eykholt }
120378112e55SJoe Eykholt }
120478112e55SJoe Eykholt
120578112e55SJoe Eykholt /**
120678112e55SJoe Eykholt * fnic_set_eth_mode() - put fnic into ethernet mode.
120778112e55SJoe Eykholt * @fnic: fnic device
120878112e55SJoe Eykholt *
120978112e55SJoe Eykholt * Called without fnic lock held.
121078112e55SJoe Eykholt */
fnic_set_eth_mode(struct fnic * fnic)121178112e55SJoe Eykholt static void fnic_set_eth_mode(struct fnic *fnic)
121278112e55SJoe Eykholt {
121378112e55SJoe Eykholt unsigned long flags;
121478112e55SJoe Eykholt enum fnic_state old_state;
121578112e55SJoe Eykholt int ret;
12165df6d737SAbhijeet Joglekar
12175df6d737SAbhijeet Joglekar spin_lock_irqsave(&fnic->fnic_lock, flags);
12185df6d737SAbhijeet Joglekar again:
12195df6d737SAbhijeet Joglekar old_state = fnic->state;
12205df6d737SAbhijeet Joglekar switch (old_state) {
12215df6d737SAbhijeet Joglekar case FNIC_IN_FC_MODE:
12225df6d737SAbhijeet Joglekar case FNIC_IN_ETH_TRANS_FC_MODE:
12235df6d737SAbhijeet Joglekar default:
12245df6d737SAbhijeet Joglekar fnic->state = FNIC_IN_FC_TRANS_ETH_MODE;
12255df6d737SAbhijeet Joglekar spin_unlock_irqrestore(&fnic->fnic_lock, flags);
12265df6d737SAbhijeet Joglekar
12275df6d737SAbhijeet Joglekar ret = fnic_fw_reset_handler(fnic);
12285df6d737SAbhijeet Joglekar
12295df6d737SAbhijeet Joglekar spin_lock_irqsave(&fnic->fnic_lock, flags);
12305df6d737SAbhijeet Joglekar if (fnic->state != FNIC_IN_FC_TRANS_ETH_MODE)
12315df6d737SAbhijeet Joglekar goto again;
123278112e55SJoe Eykholt if (ret)
12335df6d737SAbhijeet Joglekar fnic->state = old_state;
12345df6d737SAbhijeet Joglekar break;
12355df6d737SAbhijeet Joglekar
12365df6d737SAbhijeet Joglekar case FNIC_IN_FC_TRANS_ETH_MODE:
12375df6d737SAbhijeet Joglekar case FNIC_IN_ETH_MODE:
12385df6d737SAbhijeet Joglekar break;
12395df6d737SAbhijeet Joglekar }
124078112e55SJoe Eykholt spin_unlock_irqrestore(&fnic->fnic_lock, flags);
12415df6d737SAbhijeet Joglekar }
12425df6d737SAbhijeet Joglekar
fnic_wq_complete_frame_send(struct vnic_wq * wq,struct cq_desc * cq_desc,struct vnic_wq_buf * buf,void * opaque)12435df6d737SAbhijeet Joglekar static void fnic_wq_complete_frame_send(struct vnic_wq *wq,
12445df6d737SAbhijeet Joglekar struct cq_desc *cq_desc,
12455df6d737SAbhijeet Joglekar struct vnic_wq_buf *buf, void *opaque)
12465df6d737SAbhijeet Joglekar {
12475df6d737SAbhijeet Joglekar struct sk_buff *skb = buf->os_buf;
12485df6d737SAbhijeet Joglekar struct fc_frame *fp = (struct fc_frame *)skb;
12495df6d737SAbhijeet Joglekar struct fnic *fnic = vnic_dev_priv(wq->vdev);
12505df6d737SAbhijeet Joglekar
12517f9b0f77SChristoph Hellwig dma_unmap_single(&fnic->pdev->dev, buf->dma_addr, buf->len,
12527f9b0f77SChristoph Hellwig DMA_TO_DEVICE);
12535df6d737SAbhijeet Joglekar dev_kfree_skb_irq(fp_skb(fp));
12545df6d737SAbhijeet Joglekar buf->os_buf = NULL;
12555df6d737SAbhijeet Joglekar }
12565df6d737SAbhijeet Joglekar
fnic_wq_cmpl_handler_cont(struct vnic_dev * vdev,struct cq_desc * cq_desc,u8 type,u16 q_number,u16 completed_index,void * opaque)12575df6d737SAbhijeet Joglekar static int fnic_wq_cmpl_handler_cont(struct vnic_dev *vdev,
12585df6d737SAbhijeet Joglekar struct cq_desc *cq_desc, u8 type,
12595df6d737SAbhijeet Joglekar u16 q_number, u16 completed_index,
12605df6d737SAbhijeet Joglekar void *opaque)
12615df6d737SAbhijeet Joglekar {
12625df6d737SAbhijeet Joglekar struct fnic *fnic = vnic_dev_priv(vdev);
12635df6d737SAbhijeet Joglekar unsigned long flags;
12645df6d737SAbhijeet Joglekar
12655df6d737SAbhijeet Joglekar spin_lock_irqsave(&fnic->wq_lock[q_number], flags);
12665df6d737SAbhijeet Joglekar vnic_wq_service(&fnic->wq[q_number], cq_desc, completed_index,
12675df6d737SAbhijeet Joglekar fnic_wq_complete_frame_send, NULL);
12685df6d737SAbhijeet Joglekar spin_unlock_irqrestore(&fnic->wq_lock[q_number], flags);
12695df6d737SAbhijeet Joglekar
12705df6d737SAbhijeet Joglekar return 0;
12715df6d737SAbhijeet Joglekar }
12725df6d737SAbhijeet Joglekar
fnic_wq_cmpl_handler(struct fnic * fnic,int work_to_do)12735df6d737SAbhijeet Joglekar int fnic_wq_cmpl_handler(struct fnic *fnic, int work_to_do)
12745df6d737SAbhijeet Joglekar {
12755df6d737SAbhijeet Joglekar unsigned int wq_work_done = 0;
12765df6d737SAbhijeet Joglekar unsigned int i;
12775df6d737SAbhijeet Joglekar
12785df6d737SAbhijeet Joglekar for (i = 0; i < fnic->raw_wq_count; i++) {
12795df6d737SAbhijeet Joglekar wq_work_done += vnic_cq_service(&fnic->cq[fnic->rq_count+i],
12805df6d737SAbhijeet Joglekar work_to_do,
12815df6d737SAbhijeet Joglekar fnic_wq_cmpl_handler_cont,
12825df6d737SAbhijeet Joglekar NULL);
12835df6d737SAbhijeet Joglekar }
12845df6d737SAbhijeet Joglekar
12855df6d737SAbhijeet Joglekar return wq_work_done;
12865df6d737SAbhijeet Joglekar }
12875df6d737SAbhijeet Joglekar
12885df6d737SAbhijeet Joglekar
fnic_free_wq_buf(struct vnic_wq * wq,struct vnic_wq_buf * buf)12895df6d737SAbhijeet Joglekar void fnic_free_wq_buf(struct vnic_wq *wq, struct vnic_wq_buf *buf)
12905df6d737SAbhijeet Joglekar {
12915df6d737SAbhijeet Joglekar struct fc_frame *fp = buf->os_buf;
12925df6d737SAbhijeet Joglekar struct fnic *fnic = vnic_dev_priv(wq->vdev);
12935df6d737SAbhijeet Joglekar
12947f9b0f77SChristoph Hellwig dma_unmap_single(&fnic->pdev->dev, buf->dma_addr, buf->len,
12957f9b0f77SChristoph Hellwig DMA_TO_DEVICE);
12965df6d737SAbhijeet Joglekar
12975df6d737SAbhijeet Joglekar dev_kfree_skb(fp_skb(fp));
12985df6d737SAbhijeet Joglekar buf->os_buf = NULL;
12995df6d737SAbhijeet Joglekar }
1300d3c995f1SHiral Patel
fnic_fcoe_reset_vlans(struct fnic * fnic)1301d3c995f1SHiral Patel void fnic_fcoe_reset_vlans(struct fnic *fnic)
1302d3c995f1SHiral Patel {
1303d3c995f1SHiral Patel unsigned long flags;
1304d3c995f1SHiral Patel struct fcoe_vlan *vlan;
1305d3c995f1SHiral Patel struct fcoe_vlan *next;
1306d3c995f1SHiral Patel
1307d3c995f1SHiral Patel /*
1308d3c995f1SHiral Patel * indicate a link down to fcoe so that all fcf's are free'd
1309d3c995f1SHiral Patel * might not be required since we did this before sending vlan
1310d3c995f1SHiral Patel * discovery request
1311d3c995f1SHiral Patel */
1312d3c995f1SHiral Patel spin_lock_irqsave(&fnic->vlans_lock, flags);
1313d3c995f1SHiral Patel if (!list_empty(&fnic->vlans)) {
1314d3c995f1SHiral Patel list_for_each_entry_safe(vlan, next, &fnic->vlans, list) {
1315d3c995f1SHiral Patel list_del(&vlan->list);
1316d3c995f1SHiral Patel kfree(vlan);
1317d3c995f1SHiral Patel }
1318d3c995f1SHiral Patel }
1319d3c995f1SHiral Patel spin_unlock_irqrestore(&fnic->vlans_lock, flags);
1320d3c995f1SHiral Patel }
1321d3c995f1SHiral Patel
fnic_handle_fip_timer(struct fnic * fnic)1322d3c995f1SHiral Patel void fnic_handle_fip_timer(struct fnic *fnic)
1323d3c995f1SHiral Patel {
1324d3c995f1SHiral Patel unsigned long flags;
1325d3c995f1SHiral Patel struct fcoe_vlan *vlan;
132667125b02SHiral Patel struct fnic_stats *fnic_stats = &fnic->fnic_stats;
1327d3c995f1SHiral Patel u64 sol_time;
1328d3c995f1SHiral Patel
1329d3c995f1SHiral Patel spin_lock_irqsave(&fnic->fnic_lock, flags);
1330d3c995f1SHiral Patel if (fnic->stop_rx_link_events) {
1331d3c995f1SHiral Patel spin_unlock_irqrestore(&fnic->fnic_lock, flags);
1332d3c995f1SHiral Patel return;
1333d3c995f1SHiral Patel }
1334d3c995f1SHiral Patel spin_unlock_irqrestore(&fnic->fnic_lock, flags);
1335d3c995f1SHiral Patel
13361917d42dSHannes Reinecke if (fnic->ctlr.mode == FIP_MODE_NON_FIP)
1337d3c995f1SHiral Patel return;
1338d3c995f1SHiral Patel
1339d3c995f1SHiral Patel spin_lock_irqsave(&fnic->vlans_lock, flags);
1340d3c995f1SHiral Patel if (list_empty(&fnic->vlans)) {
1341b43abcbbSSatish Kharat spin_unlock_irqrestore(&fnic->vlans_lock, flags);
1342d3c995f1SHiral Patel /* no vlans available, try again */
1343d2478dd2SLee Duncan if (unlikely(fnic_log_level & FNIC_FCS_LOGGING))
1344b43abcbbSSatish Kharat if (printk_ratelimit())
1345d2478dd2SLee Duncan shost_printk(KERN_DEBUG, fnic->lport->host,
1346d3c995f1SHiral Patel "Start VLAN Discovery\n");
1347d3c995f1SHiral Patel fnic_event_enq(fnic, FNIC_EVT_START_VLAN_DISC);
1348d3c995f1SHiral Patel return;
1349d3c995f1SHiral Patel }
1350d3c995f1SHiral Patel
1351d3c995f1SHiral Patel vlan = list_first_entry(&fnic->vlans, struct fcoe_vlan, list);
13523df9dd0dSKaran Tilak Kumar FNIC_FCS_DBG(KERN_DEBUG, fnic->lport->host, fnic->fnic_num,
1353d3c995f1SHiral Patel "fip_timer: vlan %d state %d sol_count %d\n",
1354d3c995f1SHiral Patel vlan->vid, vlan->state, vlan->sol_count);
1355d3c995f1SHiral Patel switch (vlan->state) {
1356d3c995f1SHiral Patel case FIP_VLAN_USED:
13573df9dd0dSKaran Tilak Kumar FNIC_FCS_DBG(KERN_DEBUG, fnic->lport->host, fnic->fnic_num,
1358d3c995f1SHiral Patel "FIP VLAN is selected for FC transaction\n");
1359d3c995f1SHiral Patel spin_unlock_irqrestore(&fnic->vlans_lock, flags);
1360d3c995f1SHiral Patel break;
1361d3c995f1SHiral Patel case FIP_VLAN_FAILED:
1362b43abcbbSSatish Kharat spin_unlock_irqrestore(&fnic->vlans_lock, flags);
1363d3c995f1SHiral Patel /* if all vlans are in failed state, restart vlan disc */
1364d2478dd2SLee Duncan if (unlikely(fnic_log_level & FNIC_FCS_LOGGING))
1365b43abcbbSSatish Kharat if (printk_ratelimit())
1366d2478dd2SLee Duncan shost_printk(KERN_DEBUG, fnic->lport->host,
1367d3c995f1SHiral Patel "Start VLAN Discovery\n");
1368d3c995f1SHiral Patel fnic_event_enq(fnic, FNIC_EVT_START_VLAN_DISC);
1369d3c995f1SHiral Patel break;
1370d3c995f1SHiral Patel case FIP_VLAN_SENT:
1371d3c995f1SHiral Patel if (vlan->sol_count >= FCOE_CTLR_MAX_SOL) {
1372d3c995f1SHiral Patel /*
1373d3c995f1SHiral Patel * no response on this vlan, remove from the list.
1374d3c995f1SHiral Patel * Try the next vlan
1375d3c995f1SHiral Patel */
13763df9dd0dSKaran Tilak Kumar FNIC_FCS_DBG(KERN_INFO, fnic->lport->host, fnic->fnic_num,
1377d3c995f1SHiral Patel "Dequeue this VLAN ID %d from list\n",
1378d3c995f1SHiral Patel vlan->vid);
1379d3c995f1SHiral Patel list_del(&vlan->list);
1380d3c995f1SHiral Patel kfree(vlan);
1381d3c995f1SHiral Patel vlan = NULL;
1382d3c995f1SHiral Patel if (list_empty(&fnic->vlans)) {
1383d3c995f1SHiral Patel /* we exhausted all vlans, restart vlan disc */
1384d3c995f1SHiral Patel spin_unlock_irqrestore(&fnic->vlans_lock,
1385d3c995f1SHiral Patel flags);
13863df9dd0dSKaran Tilak Kumar FNIC_FCS_DBG(KERN_INFO, fnic->lport->host, fnic->fnic_num,
1387d3c995f1SHiral Patel "fip_timer: vlan list empty, "
1388d3c995f1SHiral Patel "trigger vlan disc\n");
1389d3c995f1SHiral Patel fnic_event_enq(fnic, FNIC_EVT_START_VLAN_DISC);
1390d3c995f1SHiral Patel return;
1391d3c995f1SHiral Patel }
1392d3c995f1SHiral Patel /* check the next vlan */
1393d3c995f1SHiral Patel vlan = list_first_entry(&fnic->vlans, struct fcoe_vlan,
1394d3c995f1SHiral Patel list);
1395d3c995f1SHiral Patel fnic->set_vlan(fnic, vlan->vid);
1396d3c995f1SHiral Patel vlan->state = FIP_VLAN_SENT; /* sent now */
1397d3c995f1SHiral Patel }
1398d3c995f1SHiral Patel spin_unlock_irqrestore(&fnic->vlans_lock, flags);
139967125b02SHiral Patel atomic64_inc(&fnic_stats->vlan_stats.sol_expiry_count);
1400d3c995f1SHiral Patel vlan->sol_count++;
1401d3c995f1SHiral Patel sol_time = jiffies + msecs_to_jiffies
1402d3c995f1SHiral Patel (FCOE_CTLR_START_DELAY);
1403d3c995f1SHiral Patel mod_timer(&fnic->fip_timer, round_jiffies(sol_time));
1404d3c995f1SHiral Patel break;
1405d3c995f1SHiral Patel }
1406d3c995f1SHiral Patel }
1407