1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3  * QLogic qlcnic NIC Driver
4  * Copyright (c) 2009-2013 QLogic Corporation
5  */
6 
7 #include <linux/netdevice.h>
8 #include <linux/if_vlan.h>
9 #include <net/ip.h>
10 #include <linux/ipv6.h>
11 #include <net/checksum.h>
12 #include <linux/printk.h>
13 
14 #include "qlcnic.h"
15 
16 #define QLCNIC_TX_ETHER_PKT		0x01
17 #define QLCNIC_TX_TCP_PKT		0x02
18 #define QLCNIC_TX_UDP_PKT		0x03
19 #define QLCNIC_TX_IP_PKT		0x04
20 #define QLCNIC_TX_TCP_LSO		0x05
21 #define QLCNIC_TX_TCP_LSO6		0x06
22 #define QLCNIC_TX_ENCAP_PKT		0x07
23 #define QLCNIC_TX_ENCAP_LSO		0x08
24 #define QLCNIC_TX_TCPV6_PKT		0x0b
25 #define QLCNIC_TX_UDPV6_PKT		0x0c
26 
27 #define QLCNIC_FLAGS_VLAN_TAGGED	0x10
28 #define QLCNIC_FLAGS_VLAN_OOB		0x40
29 
30 #define qlcnic_set_tx_vlan_tci(cmd_desc, v)	\
31 	(cmd_desc)->vlan_TCI = cpu_to_le16(v);
32 #define qlcnic_set_cmd_desc_port(cmd_desc, var)	\
33 	((cmd_desc)->port_ctxid |= ((var) & 0x0F))
34 #define qlcnic_set_cmd_desc_ctxid(cmd_desc, var)	\
35 	((cmd_desc)->port_ctxid |= ((var) << 4 & 0xF0))
36 
37 #define qlcnic_set_tx_port(_desc, _port) \
38 	((_desc)->port_ctxid = ((_port) & 0xf) | (((_port) << 4) & 0xf0))
39 
40 #define qlcnic_set_tx_flags_opcode(_desc, _flags, _opcode) \
41 	((_desc)->flags_opcode |= \
42 	cpu_to_le16(((_flags) & 0x7f) | (((_opcode) & 0x3f) << 7)))
43 
44 #define qlcnic_set_tx_frags_len(_desc, _frags, _len) \
45 	((_desc)->nfrags__length = \
46 	cpu_to_le32(((_frags) & 0xff) | (((_len) & 0xffffff) << 8)))
47 
48 /* owner bits of status_desc */
49 #define STATUS_OWNER_HOST	(0x1ULL << 56)
50 #define STATUS_OWNER_PHANTOM	(0x2ULL << 56)
51 
52 /* Status descriptor:
53    0-3 port, 4-7 status, 8-11 type, 12-27 total_length
54    28-43 reference_handle, 44-47 protocol, 48-52 pkt_offset
55    53-55 desc_cnt, 56-57 owner, 58-63 opcode
56  */
57 #define qlcnic_get_sts_port(sts_data)	\
58 	((sts_data) & 0x0F)
59 #define qlcnic_get_sts_status(sts_data)	\
60 	(((sts_data) >> 4) & 0x0F)
61 #define qlcnic_get_sts_type(sts_data)	\
62 	(((sts_data) >> 8) & 0x0F)
63 #define qlcnic_get_sts_totallength(sts_data)	\
64 	(((sts_data) >> 12) & 0xFFFF)
65 #define qlcnic_get_sts_refhandle(sts_data)	\
66 	(((sts_data) >> 28) & 0xFFFF)
67 #define qlcnic_get_sts_prot(sts_data)	\
68 	(((sts_data) >> 44) & 0x0F)
69 #define qlcnic_get_sts_pkt_offset(sts_data)	\
70 	(((sts_data) >> 48) & 0x1F)
71 #define qlcnic_get_sts_desc_cnt(sts_data)	\
72 	(((sts_data) >> 53) & 0x7)
73 #define qlcnic_get_sts_opcode(sts_data)	\
74 	(((sts_data) >> 58) & 0x03F)
75 
76 #define qlcnic_get_lro_sts_refhandle(sts_data) 	\
77 	((sts_data) & 0x07FFF)
78 #define qlcnic_get_lro_sts_length(sts_data)	\
79 	(((sts_data) >> 16) & 0x0FFFF)
80 #define qlcnic_get_lro_sts_l2_hdr_offset(sts_data)	\
81 	(((sts_data) >> 32) & 0x0FF)
82 #define qlcnic_get_lro_sts_l4_hdr_offset(sts_data)	\
83 	(((sts_data) >> 40) & 0x0FF)
84 #define qlcnic_get_lro_sts_timestamp(sts_data)	\
85 	(((sts_data) >> 48) & 0x1)
86 #define qlcnic_get_lro_sts_type(sts_data)	\
87 	(((sts_data) >> 49) & 0x7)
88 #define qlcnic_get_lro_sts_push_flag(sts_data)		\
89 	(((sts_data) >> 52) & 0x1)
90 #define qlcnic_get_lro_sts_seq_number(sts_data)		\
91 	((sts_data) & 0x0FFFFFFFF)
92 #define qlcnic_get_lro_sts_mss(sts_data1)		\
93 	((sts_data1 >> 32) & 0x0FFFF)
94 
95 #define qlcnic_83xx_get_lro_sts_mss(sts) ((sts) & 0xffff)
96 
97 /* opcode field in status_desc */
98 #define QLCNIC_SYN_OFFLOAD	0x03
99 #define QLCNIC_RXPKT_DESC  	0x04
100 #define QLCNIC_OLD_RXPKT_DESC	0x3f
101 #define QLCNIC_RESPONSE_DESC	0x05
102 #define QLCNIC_LRO_DESC  	0x12
103 
104 #define QLCNIC_TCP_HDR_SIZE		20
105 #define QLCNIC_TCP_TS_OPTION_SIZE	12
106 #define QLCNIC_FETCH_RING_ID(handle)	((handle) >> 63)
107 #define QLCNIC_DESC_OWNER_FW		cpu_to_le64(STATUS_OWNER_PHANTOM)
108 
109 #define QLCNIC_TCP_TS_HDR_SIZE (QLCNIC_TCP_HDR_SIZE + QLCNIC_TCP_TS_OPTION_SIZE)
110 
111 /* for status field in status_desc */
112 #define STATUS_CKSUM_LOOP	0
113 #define STATUS_CKSUM_OK		2
114 
115 #define qlcnic_83xx_pktln(sts)		((sts >> 32) & 0x3FFF)
116 #define qlcnic_83xx_hndl(sts)		((sts >> 48) & 0x7FFF)
117 #define qlcnic_83xx_csum_status(sts)	((sts >> 39) & 7)
118 #define qlcnic_83xx_opcode(sts)	((sts >> 42) & 0xF)
119 #define qlcnic_83xx_vlan_tag(sts)	(((sts) >> 48) & 0xFFFF)
120 #define qlcnic_83xx_lro_pktln(sts)	(((sts) >> 32) & 0x3FFF)
121 #define qlcnic_83xx_l2_hdr_off(sts)	(((sts) >> 16) & 0xFF)
122 #define qlcnic_83xx_l4_hdr_off(sts)	(((sts) >> 24) & 0xFF)
123 #define qlcnic_83xx_pkt_cnt(sts)	(((sts) >> 16) & 0x7)
124 #define qlcnic_83xx_is_tstamp(sts)	(((sts) >> 40) & 1)
125 #define qlcnic_83xx_is_psh_bit(sts)	(((sts) >> 41) & 1)
126 #define qlcnic_83xx_is_ip_align(sts)	(((sts) >> 46) & 1)
127 #define qlcnic_83xx_has_vlan_tag(sts)	(((sts) >> 47) & 1)
128 
129 static int qlcnic_process_rcv_ring(struct qlcnic_host_sds_ring *sds_ring,
130 				   int max);
131 
132 static struct sk_buff *qlcnic_process_rxbuf(struct qlcnic_adapter *,
133 					    struct qlcnic_host_rds_ring *,
134 					    u16, u16);
135 
136 static inline u8 qlcnic_mac_hash(u64 mac, u16 vlan)
137 {
138 	return (u8)((mac & 0xff) ^ ((mac >> 40) & 0xff) ^ (vlan & 0xff));
139 }
140 
141 static inline u32 qlcnic_get_ref_handle(struct qlcnic_adapter *adapter,
142 					u16 handle, u8 ring_id)
143 {
144 	if (qlcnic_83xx_check(adapter))
145 		return handle | (ring_id << 15);
146 	else
147 		return handle;
148 }
149 
150 static inline int qlcnic_82xx_is_lb_pkt(u64 sts_data)
151 {
152 	return (qlcnic_get_sts_status(sts_data) == STATUS_CKSUM_LOOP) ? 1 : 0;
153 }
154 
155 static void qlcnic_delete_rx_list_mac(struct qlcnic_adapter *adapter,
156 				      struct qlcnic_filter *fil,
157 				      void *addr, u16 vlan_id)
158 {
159 	int ret;
160 	u8 op;
161 
162 	op = vlan_id ? QLCNIC_MAC_VLAN_ADD : QLCNIC_MAC_ADD;
163 	ret = qlcnic_sre_macaddr_change(adapter, addr, vlan_id, op);
164 	if (ret)
165 		return;
166 
167 	op = vlan_id ? QLCNIC_MAC_VLAN_DEL : QLCNIC_MAC_DEL;
168 	ret = qlcnic_sre_macaddr_change(adapter, addr, vlan_id, op);
169 	if (!ret) {
170 		hlist_del(&fil->fnode);
171 		adapter->rx_fhash.fnum--;
172 	}
173 }
174 
175 static struct qlcnic_filter *qlcnic_find_mac_filter(struct hlist_head *head,
176 						    void *addr, u16 vlan_id)
177 {
178 	struct qlcnic_filter *tmp_fil = NULL;
179 	struct hlist_node *n;
180 
181 	hlist_for_each_entry_safe(tmp_fil, n, head, fnode) {
182 		if (ether_addr_equal(tmp_fil->faddr, addr) &&
183 		    tmp_fil->vlan_id == vlan_id)
184 			return tmp_fil;
185 	}
186 
187 	return NULL;
188 }
189 
190 static void qlcnic_add_lb_filter(struct qlcnic_adapter *adapter,
191 				 struct sk_buff *skb, int loopback_pkt, u16 vlan_id)
192 {
193 	struct ethhdr *phdr = (struct ethhdr *)(skb->data);
194 	struct qlcnic_filter *fil, *tmp_fil;
195 	struct hlist_head *head;
196 	unsigned long time;
197 	u64 src_addr = 0;
198 	u8 hindex, op;
199 	int ret;
200 
201 	if (!qlcnic_sriov_pf_check(adapter) || (vlan_id == 0xffff))
202 		vlan_id = 0;
203 
204 	memcpy(&src_addr, phdr->h_source, ETH_ALEN);
205 	hindex = qlcnic_mac_hash(src_addr, vlan_id) &
206 		 (adapter->fhash.fbucket_size - 1);
207 
208 	if (loopback_pkt) {
209 		if (adapter->rx_fhash.fnum >= adapter->rx_fhash.fmax)
210 			return;
211 
212 		head = &(adapter->rx_fhash.fhead[hindex]);
213 
214 		tmp_fil = qlcnic_find_mac_filter(head, &src_addr, vlan_id);
215 		if (tmp_fil) {
216 			time = tmp_fil->ftime;
217 			if (time_after(jiffies, QLCNIC_READD_AGE * HZ + time))
218 				tmp_fil->ftime = jiffies;
219 			return;
220 		}
221 
222 		fil = kzalloc(sizeof(struct qlcnic_filter), GFP_ATOMIC);
223 		if (!fil)
224 			return;
225 
226 		fil->ftime = jiffies;
227 		memcpy(fil->faddr, &src_addr, ETH_ALEN);
228 		fil->vlan_id = vlan_id;
229 		spin_lock(&adapter->rx_mac_learn_lock);
230 		hlist_add_head(&(fil->fnode), head);
231 		adapter->rx_fhash.fnum++;
232 		spin_unlock(&adapter->rx_mac_learn_lock);
233 	} else {
234 		head = &adapter->fhash.fhead[hindex];
235 
236 		spin_lock(&adapter->mac_learn_lock);
237 
238 		tmp_fil = qlcnic_find_mac_filter(head, &src_addr, vlan_id);
239 		if (tmp_fil) {
240 			op = vlan_id ? QLCNIC_MAC_VLAN_DEL : QLCNIC_MAC_DEL;
241 			ret = qlcnic_sre_macaddr_change(adapter,
242 							(u8 *)&src_addr,
243 							vlan_id, op);
244 			if (!ret) {
245 				hlist_del(&tmp_fil->fnode);
246 				adapter->fhash.fnum--;
247 			}
248 
249 			spin_unlock(&adapter->mac_learn_lock);
250 
251 			return;
252 		}
253 
254 		spin_unlock(&adapter->mac_learn_lock);
255 
256 		head = &adapter->rx_fhash.fhead[hindex];
257 
258 		spin_lock(&adapter->rx_mac_learn_lock);
259 
260 		tmp_fil = qlcnic_find_mac_filter(head, &src_addr, vlan_id);
261 		if (tmp_fil)
262 			qlcnic_delete_rx_list_mac(adapter, tmp_fil, &src_addr,
263 						  vlan_id);
264 
265 		spin_unlock(&adapter->rx_mac_learn_lock);
266 	}
267 }
268 
269 void qlcnic_82xx_change_filter(struct qlcnic_adapter *adapter, u64 *uaddr,
270 			       u16 vlan_id, struct qlcnic_host_tx_ring *tx_ring)
271 {
272 	struct cmd_desc_type0 *hwdesc;
273 	struct qlcnic_nic_req *req;
274 	struct qlcnic_mac_req *mac_req;
275 	struct qlcnic_vlan_req *vlan_req;
276 	u32 producer;
277 	u64 word;
278 
279 	producer = tx_ring->producer;
280 	hwdesc = &tx_ring->desc_head[tx_ring->producer];
281 
282 	req = (struct qlcnic_nic_req *)hwdesc;
283 	memset(req, 0, sizeof(struct qlcnic_nic_req));
284 	req->qhdr = cpu_to_le64(QLCNIC_REQUEST << 23);
285 
286 	word = QLCNIC_MAC_EVENT | ((u64)(adapter->portnum) << 16);
287 	req->req_hdr = cpu_to_le64(word);
288 
289 	mac_req = (struct qlcnic_mac_req *)&(req->words[0]);
290 	mac_req->op = vlan_id ? QLCNIC_MAC_VLAN_ADD : QLCNIC_MAC_ADD;
291 	memcpy(mac_req->mac_addr, uaddr, ETH_ALEN);
292 
293 	vlan_req = (struct qlcnic_vlan_req *)&req->words[1];
294 	vlan_req->vlan_id = cpu_to_le16(vlan_id);
295 
296 	tx_ring->producer = get_next_index(producer, tx_ring->num_desc);
297 	smp_mb();
298 }
299 
300 static void qlcnic_send_filter(struct qlcnic_adapter *adapter,
301 			       struct cmd_desc_type0 *first_desc,
302 			       struct sk_buff *skb,
303 			       struct qlcnic_host_tx_ring *tx_ring)
304 {
305 	struct vlan_ethhdr *vh = (struct vlan_ethhdr *)(skb->data);
306 	struct ethhdr *phdr = (struct ethhdr *)(skb->data);
307 	u16 protocol = ntohs(skb->protocol);
308 	struct qlcnic_filter *fil, *tmp_fil;
309 	struct hlist_head *head;
310 	struct hlist_node *n;
311 	u64 src_addr = 0;
312 	u16 vlan_id = 0;
313 	u8 hindex, hval;
314 
315 	if (ether_addr_equal(phdr->h_source, adapter->mac_addr))
316 		return;
317 
318 	if (adapter->flags & QLCNIC_VLAN_FILTERING) {
319 		if (protocol == ETH_P_8021Q) {
320 			vh = (struct vlan_ethhdr *)skb->data;
321 			vlan_id = ntohs(vh->h_vlan_TCI);
322 		} else if (skb_vlan_tag_present(skb)) {
323 			vlan_id = skb_vlan_tag_get(skb);
324 		}
325 	}
326 
327 	memcpy(&src_addr, phdr->h_source, ETH_ALEN);
328 	hval = qlcnic_mac_hash(src_addr, vlan_id);
329 	hindex = hval & (adapter->fhash.fbucket_size - 1);
330 	head = &(adapter->fhash.fhead[hindex]);
331 
332 	hlist_for_each_entry_safe(tmp_fil, n, head, fnode) {
333 		if (ether_addr_equal(tmp_fil->faddr, (u8 *)&src_addr) &&
334 		    tmp_fil->vlan_id == vlan_id) {
335 			if (jiffies > (QLCNIC_READD_AGE * HZ + tmp_fil->ftime))
336 				qlcnic_change_filter(adapter, &src_addr,
337 						     vlan_id, tx_ring);
338 			tmp_fil->ftime = jiffies;
339 			return;
340 		}
341 	}
342 
343 	if (unlikely(adapter->fhash.fnum >= adapter->fhash.fmax)) {
344 		adapter->stats.mac_filter_limit_overrun++;
345 		return;
346 	}
347 
348 	fil = kzalloc(sizeof(struct qlcnic_filter), GFP_ATOMIC);
349 	if (!fil)
350 		return;
351 
352 	qlcnic_change_filter(adapter, &src_addr, vlan_id, tx_ring);
353 	fil->ftime = jiffies;
354 	fil->vlan_id = vlan_id;
355 	memcpy(fil->faddr, &src_addr, ETH_ALEN);
356 	spin_lock(&adapter->mac_learn_lock);
357 	hlist_add_head(&(fil->fnode), head);
358 	adapter->fhash.fnum++;
359 	spin_unlock(&adapter->mac_learn_lock);
360 }
361 
362 #define QLCNIC_ENCAP_VXLAN_PKT		BIT_0
363 #define QLCNIC_ENCAP_OUTER_L3_IP6	BIT_1
364 #define QLCNIC_ENCAP_INNER_L3_IP6	BIT_2
365 #define QLCNIC_ENCAP_INNER_L4_UDP	BIT_3
366 #define QLCNIC_ENCAP_DO_L3_CSUM		BIT_4
367 #define QLCNIC_ENCAP_DO_L4_CSUM		BIT_5
368 
369 static int qlcnic_tx_encap_pkt(struct qlcnic_adapter *adapter,
370 			       struct cmd_desc_type0 *first_desc,
371 			       struct sk_buff *skb,
372 			       struct qlcnic_host_tx_ring *tx_ring)
373 {
374 	u8 opcode = 0, inner_hdr_len = 0, outer_hdr_len = 0, total_hdr_len = 0;
375 	int copied, copy_len, descr_size;
376 	u32 producer = tx_ring->producer;
377 	struct cmd_desc_type0 *hwdesc;
378 	u16 flags = 0, encap_descr = 0;
379 
380 	opcode = QLCNIC_TX_ETHER_PKT;
381 	encap_descr = QLCNIC_ENCAP_VXLAN_PKT;
382 
383 	if (skb_is_gso(skb)) {
384 		inner_hdr_len = skb_inner_transport_header(skb) +
385 				inner_tcp_hdrlen(skb) -
386 				skb_inner_mac_header(skb);
387 
388 		/* VXLAN header size = 8 */
389 		outer_hdr_len = skb_transport_offset(skb) + 8 +
390 				sizeof(struct udphdr);
391 		first_desc->outer_hdr_length = outer_hdr_len;
392 		total_hdr_len = inner_hdr_len + outer_hdr_len;
393 		encap_descr |= QLCNIC_ENCAP_DO_L3_CSUM |
394 			       QLCNIC_ENCAP_DO_L4_CSUM;
395 		first_desc->mss = cpu_to_le16(skb_shinfo(skb)->gso_size);
396 		first_desc->hdr_length = inner_hdr_len;
397 
398 		/* Copy inner and outer headers in Tx descriptor(s)
399 		 * If total_hdr_len > cmd_desc_type0, use multiple
400 		 * descriptors
401 		 */
402 		copied = 0;
403 		descr_size = (int)sizeof(struct cmd_desc_type0);
404 		while (copied < total_hdr_len) {
405 			copy_len = min(descr_size, (total_hdr_len - copied));
406 			hwdesc = &tx_ring->desc_head[producer];
407 			tx_ring->cmd_buf_arr[producer].skb = NULL;
408 			skb_copy_from_linear_data_offset(skb, copied,
409 							 (char *)hwdesc,
410 							 copy_len);
411 			copied += copy_len;
412 			producer = get_next_index(producer, tx_ring->num_desc);
413 		}
414 
415 		tx_ring->producer = producer;
416 
417 		/* Make sure updated tx_ring->producer is visible
418 		 * for qlcnic_tx_avail()
419 		 */
420 		smp_mb();
421 		adapter->stats.encap_lso_frames++;
422 
423 		opcode = QLCNIC_TX_ENCAP_LSO;
424 	} else if (skb->ip_summed == CHECKSUM_PARTIAL) {
425 		if (inner_ip_hdr(skb)->version == 6) {
426 			if (inner_ipv6_hdr(skb)->nexthdr == IPPROTO_UDP)
427 				encap_descr |= QLCNIC_ENCAP_INNER_L4_UDP;
428 		} else {
429 			if (inner_ip_hdr(skb)->protocol == IPPROTO_UDP)
430 				encap_descr |= QLCNIC_ENCAP_INNER_L4_UDP;
431 		}
432 
433 		adapter->stats.encap_tx_csummed++;
434 		opcode = QLCNIC_TX_ENCAP_PKT;
435 	}
436 
437 	/* Prepare first 16 bits of byte offset 16 of Tx descriptor */
438 	if (ip_hdr(skb)->version == 6)
439 		encap_descr |= QLCNIC_ENCAP_OUTER_L3_IP6;
440 
441 	/* outer IP header's size in 32bit words size*/
442 	encap_descr |= (skb_network_header_len(skb) >> 2) << 6;
443 
444 	/* outer IP header offset */
445 	encap_descr |= skb_network_offset(skb) << 10;
446 	first_desc->encap_descr = cpu_to_le16(encap_descr);
447 
448 	first_desc->tcp_hdr_offset = skb_inner_transport_header(skb) -
449 				     skb->data;
450 	first_desc->ip_hdr_offset = skb_inner_network_offset(skb);
451 
452 	qlcnic_set_tx_flags_opcode(first_desc, flags, opcode);
453 
454 	return 0;
455 }
456 
457 static int qlcnic_tx_pkt(struct qlcnic_adapter *adapter,
458 			 struct cmd_desc_type0 *first_desc, struct sk_buff *skb,
459 			 struct qlcnic_host_tx_ring *tx_ring)
460 {
461 	u8 l4proto, opcode = 0, hdr_len = 0, tag_vlan = 0;
462 	u16 flags = 0, vlan_tci = 0;
463 	int copied, offset, copy_len, size;
464 	struct cmd_desc_type0 *hwdesc;
465 	struct vlan_ethhdr *vh;
466 	u16 protocol = ntohs(skb->protocol);
467 	u32 producer = tx_ring->producer;
468 
469 	if (protocol == ETH_P_8021Q) {
470 		vh = (struct vlan_ethhdr *)skb->data;
471 		flags = QLCNIC_FLAGS_VLAN_TAGGED;
472 		vlan_tci = ntohs(vh->h_vlan_TCI);
473 		protocol = ntohs(vh->h_vlan_encapsulated_proto);
474 		tag_vlan = 1;
475 	} else if (skb_vlan_tag_present(skb)) {
476 		flags = QLCNIC_FLAGS_VLAN_OOB;
477 		vlan_tci = skb_vlan_tag_get(skb);
478 		tag_vlan = 1;
479 	}
480 	if (unlikely(adapter->tx_pvid)) {
481 		if (tag_vlan && !(adapter->flags & QLCNIC_TAGGING_ENABLED))
482 			return -EIO;
483 		if (tag_vlan && (adapter->flags & QLCNIC_TAGGING_ENABLED))
484 			goto set_flags;
485 
486 		flags = QLCNIC_FLAGS_VLAN_OOB;
487 		vlan_tci = adapter->tx_pvid;
488 	}
489 set_flags:
490 	qlcnic_set_tx_vlan_tci(first_desc, vlan_tci);
491 	qlcnic_set_tx_flags_opcode(first_desc, flags, opcode);
492 
493 	if (*(skb->data) & BIT_0) {
494 		flags |= BIT_0;
495 		memcpy(&first_desc->eth_addr, skb->data, ETH_ALEN);
496 	}
497 	opcode = QLCNIC_TX_ETHER_PKT;
498 	if (skb_is_gso(skb)) {
499 		hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
500 		first_desc->mss = cpu_to_le16(skb_shinfo(skb)->gso_size);
501 		first_desc->hdr_length = hdr_len;
502 		opcode = (protocol == ETH_P_IPV6) ? QLCNIC_TX_TCP_LSO6 :
503 						    QLCNIC_TX_TCP_LSO;
504 
505 		/* For LSO, we need to copy the MAC/IP/TCP headers into
506 		* the descriptor ring */
507 		copied = 0;
508 		offset = 2;
509 
510 		if (flags & QLCNIC_FLAGS_VLAN_OOB) {
511 			first_desc->hdr_length += VLAN_HLEN;
512 			first_desc->tcp_hdr_offset = VLAN_HLEN;
513 			first_desc->ip_hdr_offset = VLAN_HLEN;
514 
515 			/* Only in case of TSO on vlan device */
516 			flags |= QLCNIC_FLAGS_VLAN_TAGGED;
517 
518 			/* Create a TSO vlan header template for firmware */
519 			hwdesc = &tx_ring->desc_head[producer];
520 			tx_ring->cmd_buf_arr[producer].skb = NULL;
521 
522 			copy_len = min((int)sizeof(struct cmd_desc_type0) -
523 				       offset, hdr_len + VLAN_HLEN);
524 
525 			vh = (struct vlan_ethhdr *)((char *) hwdesc + 2);
526 			skb_copy_from_linear_data(skb, vh, 12);
527 			vh->h_vlan_proto = htons(ETH_P_8021Q);
528 			vh->h_vlan_TCI = htons(vlan_tci);
529 
530 			skb_copy_from_linear_data_offset(skb, 12,
531 							 (char *)vh + 16,
532 							 copy_len - 16);
533 			copied = copy_len - VLAN_HLEN;
534 			offset = 0;
535 			producer = get_next_index(producer, tx_ring->num_desc);
536 		}
537 
538 		while (copied < hdr_len) {
539 			size = (int)sizeof(struct cmd_desc_type0) - offset;
540 			copy_len = min(size, (hdr_len - copied));
541 			hwdesc = &tx_ring->desc_head[producer];
542 			tx_ring->cmd_buf_arr[producer].skb = NULL;
543 			skb_copy_from_linear_data_offset(skb, copied,
544 							 (char *)hwdesc +
545 							 offset, copy_len);
546 			copied += copy_len;
547 			offset = 0;
548 			producer = get_next_index(producer, tx_ring->num_desc);
549 		}
550 
551 		tx_ring->producer = producer;
552 		smp_mb();
553 		adapter->stats.lso_frames++;
554 
555 	} else if (skb->ip_summed == CHECKSUM_PARTIAL) {
556 		if (protocol == ETH_P_IP) {
557 			l4proto = ip_hdr(skb)->protocol;
558 
559 			if (l4proto == IPPROTO_TCP)
560 				opcode = QLCNIC_TX_TCP_PKT;
561 			else if (l4proto == IPPROTO_UDP)
562 				opcode = QLCNIC_TX_UDP_PKT;
563 		} else if (protocol == ETH_P_IPV6) {
564 			l4proto = ipv6_hdr(skb)->nexthdr;
565 
566 			if (l4proto == IPPROTO_TCP)
567 				opcode = QLCNIC_TX_TCPV6_PKT;
568 			else if (l4proto == IPPROTO_UDP)
569 				opcode = QLCNIC_TX_UDPV6_PKT;
570 		}
571 	}
572 	first_desc->tcp_hdr_offset += skb_transport_offset(skb);
573 	first_desc->ip_hdr_offset += skb_network_offset(skb);
574 	qlcnic_set_tx_flags_opcode(first_desc, flags, opcode);
575 
576 	return 0;
577 }
578 
579 static int qlcnic_map_tx_skb(struct pci_dev *pdev, struct sk_buff *skb,
580 			     struct qlcnic_cmd_buffer *pbuf)
581 {
582 	struct qlcnic_skb_frag *nf;
583 	skb_frag_t *frag;
584 	int i, nr_frags;
585 	dma_addr_t map;
586 
587 	nr_frags = skb_shinfo(skb)->nr_frags;
588 	nf = &pbuf->frag_array[0];
589 
590 	map = dma_map_single(&pdev->dev, skb->data, skb_headlen(skb),
591 			     DMA_TO_DEVICE);
592 	if (dma_mapping_error(&pdev->dev, map))
593 		goto out_err;
594 
595 	nf->dma = map;
596 	nf->length = skb_headlen(skb);
597 
598 	for (i = 0; i < nr_frags; i++) {
599 		frag = &skb_shinfo(skb)->frags[i];
600 		nf = &pbuf->frag_array[i+1];
601 		map = skb_frag_dma_map(&pdev->dev, frag, 0, skb_frag_size(frag),
602 				       DMA_TO_DEVICE);
603 		if (dma_mapping_error(&pdev->dev, map))
604 			goto unwind;
605 
606 		nf->dma = map;
607 		nf->length = skb_frag_size(frag);
608 	}
609 
610 	return 0;
611 
612 unwind:
613 	while (--i >= 0) {
614 		nf = &pbuf->frag_array[i+1];
615 		dma_unmap_page(&pdev->dev, nf->dma, nf->length, DMA_TO_DEVICE);
616 	}
617 
618 	nf = &pbuf->frag_array[0];
619 	dma_unmap_single(&pdev->dev, nf->dma, skb_headlen(skb), DMA_TO_DEVICE);
620 
621 out_err:
622 	return -ENOMEM;
623 }
624 
625 static void qlcnic_unmap_buffers(struct pci_dev *pdev, struct sk_buff *skb,
626 				 struct qlcnic_cmd_buffer *pbuf)
627 {
628 	struct qlcnic_skb_frag *nf = &pbuf->frag_array[0];
629 	int i, nr_frags = skb_shinfo(skb)->nr_frags;
630 
631 	for (i = 0; i < nr_frags; i++) {
632 		nf = &pbuf->frag_array[i+1];
633 		dma_unmap_page(&pdev->dev, nf->dma, nf->length, DMA_TO_DEVICE);
634 	}
635 
636 	nf = &pbuf->frag_array[0];
637 	dma_unmap_single(&pdev->dev, nf->dma, skb_headlen(skb), DMA_TO_DEVICE);
638 	pbuf->skb = NULL;
639 }
640 
641 static inline void qlcnic_clear_cmddesc(u64 *desc)
642 {
643 	desc[0] = 0ULL;
644 	desc[2] = 0ULL;
645 	desc[7] = 0ULL;
646 }
647 
648 netdev_tx_t qlcnic_xmit_frame(struct sk_buff *skb, struct net_device *netdev)
649 {
650 	struct qlcnic_adapter *adapter = netdev_priv(netdev);
651 	struct qlcnic_host_tx_ring *tx_ring;
652 	struct qlcnic_cmd_buffer *pbuf;
653 	struct qlcnic_skb_frag *buffrag;
654 	struct cmd_desc_type0 *hwdesc, *first_desc;
655 	struct pci_dev *pdev;
656 	struct ethhdr *phdr;
657 	int i, k, frag_count, delta = 0;
658 	u32 producer, num_txd;
659 	u16 protocol;
660 	bool l4_is_udp = false;
661 
662 	if (!test_bit(__QLCNIC_DEV_UP, &adapter->state)) {
663 		netif_tx_stop_all_queues(netdev);
664 		return NETDEV_TX_BUSY;
665 	}
666 
667 	if (adapter->flags & QLCNIC_MACSPOOF) {
668 		phdr = (struct ethhdr *)skb->data;
669 		if (!ether_addr_equal(phdr->h_source, adapter->mac_addr))
670 			goto drop_packet;
671 	}
672 
673 	tx_ring = &adapter->tx_ring[skb_get_queue_mapping(skb)];
674 	num_txd = tx_ring->num_desc;
675 
676 	frag_count = skb_shinfo(skb)->nr_frags + 1;
677 
678 	/* 14 frags supported for normal packet and
679 	 * 32 frags supported for TSO packet
680 	 */
681 	if (!skb_is_gso(skb) && frag_count > QLCNIC_MAX_FRAGS_PER_TX) {
682 		for (i = 0; i < (frag_count - QLCNIC_MAX_FRAGS_PER_TX); i++)
683 			delta += skb_frag_size(&skb_shinfo(skb)->frags[i]);
684 
685 		if (!__pskb_pull_tail(skb, delta))
686 			goto drop_packet;
687 
688 		frag_count = 1 + skb_shinfo(skb)->nr_frags;
689 	}
690 
691 	if (unlikely(qlcnic_tx_avail(tx_ring) <= TX_STOP_THRESH)) {
692 		netif_tx_stop_queue(tx_ring->txq);
693 		if (qlcnic_tx_avail(tx_ring) > TX_STOP_THRESH) {
694 			netif_tx_start_queue(tx_ring->txq);
695 		} else {
696 			tx_ring->tx_stats.xmit_off++;
697 			return NETDEV_TX_BUSY;
698 		}
699 	}
700 
701 	producer = tx_ring->producer;
702 	pbuf = &tx_ring->cmd_buf_arr[producer];
703 	pdev = adapter->pdev;
704 	first_desc = &tx_ring->desc_head[producer];
705 	hwdesc = &tx_ring->desc_head[producer];
706 	qlcnic_clear_cmddesc((u64 *)hwdesc);
707 
708 	if (qlcnic_map_tx_skb(pdev, skb, pbuf)) {
709 		adapter->stats.tx_dma_map_error++;
710 		goto drop_packet;
711 	}
712 
713 	pbuf->skb = skb;
714 	pbuf->frag_count = frag_count;
715 
716 	qlcnic_set_tx_frags_len(first_desc, frag_count, skb->len);
717 	qlcnic_set_tx_port(first_desc, adapter->portnum);
718 
719 	for (i = 0; i < frag_count; i++) {
720 		k = i % 4;
721 
722 		if ((k == 0) && (i > 0)) {
723 			/* move to next desc.*/
724 			producer = get_next_index(producer, num_txd);
725 			hwdesc = &tx_ring->desc_head[producer];
726 			qlcnic_clear_cmddesc((u64 *)hwdesc);
727 			tx_ring->cmd_buf_arr[producer].skb = NULL;
728 		}
729 
730 		buffrag = &pbuf->frag_array[i];
731 		hwdesc->buffer_length[k] = cpu_to_le16(buffrag->length);
732 		switch (k) {
733 		case 0:
734 			hwdesc->addr_buffer1 = cpu_to_le64(buffrag->dma);
735 			break;
736 		case 1:
737 			hwdesc->addr_buffer2 = cpu_to_le64(buffrag->dma);
738 			break;
739 		case 2:
740 			hwdesc->addr_buffer3 = cpu_to_le64(buffrag->dma);
741 			break;
742 		case 3:
743 			hwdesc->addr_buffer4 = cpu_to_le64(buffrag->dma);
744 			break;
745 		}
746 	}
747 
748 	tx_ring->producer = get_next_index(producer, num_txd);
749 	smp_mb();
750 
751 	protocol = ntohs(skb->protocol);
752 	if (protocol == ETH_P_IP)
753 		l4_is_udp = ip_hdr(skb)->protocol == IPPROTO_UDP;
754 	else if (protocol == ETH_P_IPV6)
755 		l4_is_udp = ipv6_hdr(skb)->nexthdr == IPPROTO_UDP;
756 
757 	/* Check if it is a VXLAN packet */
758 	if (!skb->encapsulation || !l4_is_udp ||
759 	    !qlcnic_encap_tx_offload(adapter)) {
760 		if (unlikely(qlcnic_tx_pkt(adapter, first_desc, skb,
761 					   tx_ring)))
762 			goto unwind_buff;
763 	} else {
764 		if (unlikely(qlcnic_tx_encap_pkt(adapter, first_desc,
765 						 skb, tx_ring)))
766 			goto unwind_buff;
767 	}
768 
769 	if (adapter->drv_mac_learn)
770 		qlcnic_send_filter(adapter, first_desc, skb, tx_ring);
771 
772 	tx_ring->tx_stats.tx_bytes += skb->len;
773 	tx_ring->tx_stats.xmit_called++;
774 
775 	/* Ensure writes are complete before HW fetches Tx descriptors */
776 	wmb();
777 	qlcnic_update_cmd_producer(tx_ring);
778 
779 	return NETDEV_TX_OK;
780 
781 unwind_buff:
782 	qlcnic_unmap_buffers(pdev, skb, pbuf);
783 drop_packet:
784 	adapter->stats.txdropped++;
785 	dev_kfree_skb_any(skb);
786 	return NETDEV_TX_OK;
787 }
788 
789 void qlcnic_advert_link_change(struct qlcnic_adapter *adapter, int linkup)
790 {
791 	struct net_device *netdev = adapter->netdev;
792 
793 	if (adapter->ahw->linkup && !linkup) {
794 		netdev_info(netdev, "NIC Link is down\n");
795 		adapter->ahw->linkup = 0;
796 		netif_carrier_off(netdev);
797 	} else if (!adapter->ahw->linkup && linkup) {
798 		adapter->ahw->linkup = 1;
799 
800 		/* Do not advertise Link up to the stack if device
801 		 * is in loopback mode
802 		 */
803 		if (qlcnic_83xx_check(adapter) && adapter->ahw->lb_mode) {
804 			netdev_info(netdev, "NIC Link is up for loopback test\n");
805 			return;
806 		}
807 
808 		netdev_info(netdev, "NIC Link is up\n");
809 		netif_carrier_on(netdev);
810 	}
811 }
812 
813 static int qlcnic_alloc_rx_skb(struct qlcnic_adapter *adapter,
814 			       struct qlcnic_host_rds_ring *rds_ring,
815 			       struct qlcnic_rx_buffer *buffer)
816 {
817 	struct sk_buff *skb;
818 	dma_addr_t dma;
819 	struct pci_dev *pdev = adapter->pdev;
820 
821 	skb = netdev_alloc_skb(adapter->netdev, rds_ring->skb_size);
822 	if (!skb) {
823 		adapter->stats.skb_alloc_failure++;
824 		return -ENOMEM;
825 	}
826 
827 	skb_reserve(skb, NET_IP_ALIGN);
828 	dma = dma_map_single(&pdev->dev, skb->data, rds_ring->dma_size,
829 			     DMA_FROM_DEVICE);
830 
831 	if (dma_mapping_error(&pdev->dev, dma)) {
832 		adapter->stats.rx_dma_map_error++;
833 		dev_kfree_skb_any(skb);
834 		return -ENOMEM;
835 	}
836 
837 	buffer->skb = skb;
838 	buffer->dma = dma;
839 
840 	return 0;
841 }
842 
843 static void qlcnic_post_rx_buffers_nodb(struct qlcnic_adapter *adapter,
844 					struct qlcnic_host_rds_ring *rds_ring,
845 					u8 ring_id)
846 {
847 	struct rcv_desc *pdesc;
848 	struct qlcnic_rx_buffer *buffer;
849 	int  count = 0;
850 	uint32_t producer, handle;
851 	struct list_head *head;
852 
853 	if (!spin_trylock(&rds_ring->lock))
854 		return;
855 
856 	producer = rds_ring->producer;
857 	head = &rds_ring->free_list;
858 	while (!list_empty(head)) {
859 		buffer = list_entry(head->next, struct qlcnic_rx_buffer, list);
860 
861 		if (!buffer->skb) {
862 			if (qlcnic_alloc_rx_skb(adapter, rds_ring, buffer))
863 				break;
864 		}
865 		count++;
866 		list_del(&buffer->list);
867 
868 		/* make a rcv descriptor  */
869 		pdesc = &rds_ring->desc_head[producer];
870 		handle = qlcnic_get_ref_handle(adapter,
871 					       buffer->ref_handle, ring_id);
872 		pdesc->reference_handle = cpu_to_le16(handle);
873 		pdesc->buffer_length = cpu_to_le32(rds_ring->dma_size);
874 		pdesc->addr_buffer = cpu_to_le64(buffer->dma);
875 		producer = get_next_index(producer, rds_ring->num_desc);
876 	}
877 	if (count) {
878 		rds_ring->producer = producer;
879 		writel((producer - 1) & (rds_ring->num_desc - 1),
880 		       rds_ring->crb_rcv_producer);
881 	}
882 	spin_unlock(&rds_ring->lock);
883 }
884 
885 static int qlcnic_process_cmd_ring(struct qlcnic_adapter *adapter,
886 				   struct qlcnic_host_tx_ring *tx_ring,
887 				   int budget)
888 {
889 	u32 sw_consumer, hw_consumer;
890 	int i, done, count = 0;
891 	struct qlcnic_cmd_buffer *buffer;
892 	struct pci_dev *pdev = adapter->pdev;
893 	struct net_device *netdev = adapter->netdev;
894 	struct qlcnic_skb_frag *frag;
895 
896 	if (!spin_trylock(&tx_ring->tx_clean_lock))
897 		return 1;
898 
899 	sw_consumer = tx_ring->sw_consumer;
900 	hw_consumer = le32_to_cpu(*(tx_ring->hw_consumer));
901 
902 	while (sw_consumer != hw_consumer) {
903 		buffer = &tx_ring->cmd_buf_arr[sw_consumer];
904 		if (buffer->skb) {
905 			frag = &buffer->frag_array[0];
906 			dma_unmap_single(&pdev->dev, frag->dma, frag->length,
907 					 DMA_TO_DEVICE);
908 			frag->dma = 0ULL;
909 			for (i = 1; i < buffer->frag_count; i++) {
910 				frag++;
911 				dma_unmap_page(&pdev->dev, frag->dma,
912 					       frag->length, DMA_TO_DEVICE);
913 				frag->dma = 0ULL;
914 			}
915 			tx_ring->tx_stats.xmit_finished++;
916 			dev_kfree_skb_any(buffer->skb);
917 			buffer->skb = NULL;
918 		}
919 
920 		sw_consumer = get_next_index(sw_consumer, tx_ring->num_desc);
921 		if (++count >= budget)
922 			break;
923 	}
924 
925 	tx_ring->sw_consumer = sw_consumer;
926 
927 	if (count && netif_running(netdev)) {
928 		smp_mb();
929 		if (netif_tx_queue_stopped(tx_ring->txq) &&
930 		    netif_carrier_ok(netdev)) {
931 			if (qlcnic_tx_avail(tx_ring) > TX_STOP_THRESH) {
932 				netif_tx_wake_queue(tx_ring->txq);
933 				tx_ring->tx_stats.xmit_on++;
934 			}
935 		}
936 		adapter->tx_timeo_cnt = 0;
937 	}
938 	/*
939 	 * If everything is freed up to consumer then check if the ring is full
940 	 * If the ring is full then check if more needs to be freed and
941 	 * schedule the call back again.
942 	 *
943 	 * This happens when there are 2 CPUs. One could be freeing and the
944 	 * other filling it. If the ring is full when we get out of here and
945 	 * the card has already interrupted the host then the host can miss the
946 	 * interrupt.
947 	 *
948 	 * There is still a possible race condition and the host could miss an
949 	 * interrupt. The card has to take care of this.
950 	 */
951 	hw_consumer = le32_to_cpu(*(tx_ring->hw_consumer));
952 	done = (sw_consumer == hw_consumer);
953 
954 	spin_unlock(&tx_ring->tx_clean_lock);
955 
956 	return done;
957 }
958 
959 static int qlcnic_poll(struct napi_struct *napi, int budget)
960 {
961 	int tx_complete, work_done;
962 	struct qlcnic_host_sds_ring *sds_ring;
963 	struct qlcnic_adapter *adapter;
964 	struct qlcnic_host_tx_ring *tx_ring;
965 
966 	sds_ring = container_of(napi, struct qlcnic_host_sds_ring, napi);
967 	adapter = sds_ring->adapter;
968 	tx_ring = sds_ring->tx_ring;
969 
970 	tx_complete = qlcnic_process_cmd_ring(adapter, tx_ring,
971 					      budget);
972 	work_done = qlcnic_process_rcv_ring(sds_ring, budget);
973 
974 	/* Check if we need a repoll */
975 	if (!tx_complete)
976 		work_done = budget;
977 
978 	if (work_done < budget) {
979 		napi_complete_done(&sds_ring->napi, work_done);
980 		if (test_bit(__QLCNIC_DEV_UP, &adapter->state)) {
981 			qlcnic_enable_sds_intr(adapter, sds_ring);
982 			qlcnic_enable_tx_intr(adapter, tx_ring);
983 		}
984 	}
985 
986 	return work_done;
987 }
988 
989 static int qlcnic_tx_poll(struct napi_struct *napi, int budget)
990 {
991 	struct qlcnic_host_tx_ring *tx_ring;
992 	struct qlcnic_adapter *adapter;
993 	int work_done;
994 
995 	tx_ring = container_of(napi, struct qlcnic_host_tx_ring, napi);
996 	adapter = tx_ring->adapter;
997 
998 	work_done = qlcnic_process_cmd_ring(adapter, tx_ring, budget);
999 	if (work_done) {
1000 		napi_complete(&tx_ring->napi);
1001 		if (test_bit(__QLCNIC_DEV_UP, &adapter->state))
1002 			qlcnic_enable_tx_intr(adapter, tx_ring);
1003 	} else {
1004 		/* As qlcnic_process_cmd_ring() returned 0, we need a repoll*/
1005 		work_done = budget;
1006 	}
1007 
1008 	return work_done;
1009 }
1010 
1011 static int qlcnic_rx_poll(struct napi_struct *napi, int budget)
1012 {
1013 	struct qlcnic_host_sds_ring *sds_ring;
1014 	struct qlcnic_adapter *adapter;
1015 	int work_done;
1016 
1017 	sds_ring = container_of(napi, struct qlcnic_host_sds_ring, napi);
1018 	adapter = sds_ring->adapter;
1019 
1020 	work_done = qlcnic_process_rcv_ring(sds_ring, budget);
1021 
1022 	if (work_done < budget) {
1023 		napi_complete_done(&sds_ring->napi, work_done);
1024 		if (test_bit(__QLCNIC_DEV_UP, &adapter->state))
1025 			qlcnic_enable_sds_intr(adapter, sds_ring);
1026 	}
1027 
1028 	return work_done;
1029 }
1030 
1031 static void qlcnic_handle_linkevent(struct qlcnic_adapter *adapter,
1032 				    struct qlcnic_fw_msg *msg)
1033 {
1034 	u32 cable_OUI;
1035 	u16 cable_len, link_speed;
1036 	u8  link_status, module, duplex, autoneg, lb_status = 0;
1037 	struct net_device *netdev = adapter->netdev;
1038 
1039 	adapter->ahw->has_link_events = 1;
1040 
1041 	cable_OUI = msg->body[1] & 0xffffffff;
1042 	cable_len = (msg->body[1] >> 32) & 0xffff;
1043 	link_speed = (msg->body[1] >> 48) & 0xffff;
1044 
1045 	link_status = msg->body[2] & 0xff;
1046 	duplex = (msg->body[2] >> 16) & 0xff;
1047 	autoneg = (msg->body[2] >> 24) & 0xff;
1048 	lb_status = (msg->body[2] >> 32) & 0x3;
1049 
1050 	module = (msg->body[2] >> 8) & 0xff;
1051 	if (module == LINKEVENT_MODULE_TWINAX_UNSUPPORTED_CABLE)
1052 		dev_info(&netdev->dev,
1053 			 "unsupported cable: OUI 0x%x, length %d\n",
1054 			 cable_OUI, cable_len);
1055 	else if (module == LINKEVENT_MODULE_TWINAX_UNSUPPORTED_CABLELEN)
1056 		dev_info(&netdev->dev, "unsupported cable length %d\n",
1057 			 cable_len);
1058 
1059 	if (!link_status && (lb_status == QLCNIC_ILB_MODE ||
1060 	    lb_status == QLCNIC_ELB_MODE))
1061 		adapter->ahw->loopback_state |= QLCNIC_LINKEVENT;
1062 
1063 	qlcnic_advert_link_change(adapter, link_status);
1064 
1065 	if (duplex == LINKEVENT_FULL_DUPLEX)
1066 		adapter->ahw->link_duplex = DUPLEX_FULL;
1067 	else
1068 		adapter->ahw->link_duplex = DUPLEX_HALF;
1069 
1070 	adapter->ahw->module_type = module;
1071 	adapter->ahw->link_autoneg = autoneg;
1072 
1073 	if (link_status) {
1074 		adapter->ahw->link_speed = link_speed;
1075 	} else {
1076 		adapter->ahw->link_speed = SPEED_UNKNOWN;
1077 		adapter->ahw->link_duplex = DUPLEX_UNKNOWN;
1078 	}
1079 }
1080 
1081 static void qlcnic_handle_fw_message(int desc_cnt, int index,
1082 				     struct qlcnic_host_sds_ring *sds_ring)
1083 {
1084 	struct qlcnic_fw_msg msg;
1085 	struct status_desc *desc;
1086 	struct qlcnic_adapter *adapter;
1087 	struct device *dev;
1088 	int i = 0, opcode, ret;
1089 
1090 	while (desc_cnt > 0 && i < 8) {
1091 		desc = &sds_ring->desc_head[index];
1092 		msg.words[i++] = le64_to_cpu(desc->status_desc_data[0]);
1093 		msg.words[i++] = le64_to_cpu(desc->status_desc_data[1]);
1094 
1095 		index = get_next_index(index, sds_ring->num_desc);
1096 		desc_cnt--;
1097 	}
1098 
1099 	adapter = sds_ring->adapter;
1100 	dev = &adapter->pdev->dev;
1101 	opcode = qlcnic_get_nic_msg_opcode(msg.body[0]);
1102 
1103 	switch (opcode) {
1104 	case QLCNIC_C2H_OPCODE_GET_LINKEVENT_RESPONSE:
1105 		qlcnic_handle_linkevent(adapter, &msg);
1106 		break;
1107 	case QLCNIC_C2H_OPCODE_CONFIG_LOOPBACK:
1108 		ret = (u32)(msg.body[1]);
1109 		switch (ret) {
1110 		case 0:
1111 			adapter->ahw->loopback_state |= QLCNIC_LB_RESPONSE;
1112 			break;
1113 		case 1:
1114 			dev_info(dev, "loopback already in progress\n");
1115 			adapter->ahw->diag_cnt = -EINPROGRESS;
1116 			break;
1117 		case 2:
1118 			dev_info(dev, "loopback cable is not connected\n");
1119 			adapter->ahw->diag_cnt = -ENODEV;
1120 			break;
1121 		default:
1122 			dev_info(dev,
1123 				 "loopback configure request failed, err %x\n",
1124 				 ret);
1125 			adapter->ahw->diag_cnt = -EIO;
1126 			break;
1127 		}
1128 		break;
1129 	case QLCNIC_C2H_OPCODE_GET_DCB_AEN:
1130 		qlcnic_dcb_aen_handler(adapter->dcb, (void *)&msg);
1131 		break;
1132 	default:
1133 		break;
1134 	}
1135 }
1136 
1137 static struct sk_buff *qlcnic_process_rxbuf(struct qlcnic_adapter *adapter,
1138 					    struct qlcnic_host_rds_ring *ring,
1139 					    u16 index, u16 cksum)
1140 {
1141 	struct qlcnic_rx_buffer *buffer;
1142 	struct sk_buff *skb;
1143 
1144 	buffer = &ring->rx_buf_arr[index];
1145 	if (unlikely(buffer->skb == NULL)) {
1146 		WARN_ON(1);
1147 		return NULL;
1148 	}
1149 
1150 	dma_unmap_single(&adapter->pdev->dev, buffer->dma, ring->dma_size,
1151 			 DMA_FROM_DEVICE);
1152 
1153 	skb = buffer->skb;
1154 	if (likely((adapter->netdev->features & NETIF_F_RXCSUM) &&
1155 		   (cksum == STATUS_CKSUM_OK || cksum == STATUS_CKSUM_LOOP))) {
1156 		adapter->stats.csummed++;
1157 		skb->ip_summed = CHECKSUM_UNNECESSARY;
1158 	} else {
1159 		skb_checksum_none_assert(skb);
1160 	}
1161 
1162 
1163 	buffer->skb = NULL;
1164 
1165 	return skb;
1166 }
1167 
1168 static inline int qlcnic_check_rx_tagging(struct qlcnic_adapter *adapter,
1169 					  struct sk_buff *skb, u16 *vlan_tag)
1170 {
1171 	struct ethhdr *eth_hdr;
1172 
1173 	if (!__vlan_get_tag(skb, vlan_tag)) {
1174 		eth_hdr = (struct ethhdr *)skb->data;
1175 		memmove(skb->data + VLAN_HLEN, eth_hdr, ETH_ALEN * 2);
1176 		skb_pull(skb, VLAN_HLEN);
1177 	}
1178 	if (!adapter->rx_pvid)
1179 		return 0;
1180 
1181 	if (*vlan_tag == adapter->rx_pvid) {
1182 		/* Outer vlan tag. Packet should follow non-vlan path */
1183 		*vlan_tag = 0xffff;
1184 		return 0;
1185 	}
1186 	if (adapter->flags & QLCNIC_TAGGING_ENABLED)
1187 		return 0;
1188 
1189 	return -EINVAL;
1190 }
1191 
1192 static struct qlcnic_rx_buffer *
1193 qlcnic_process_rcv(struct qlcnic_adapter *adapter,
1194 		   struct qlcnic_host_sds_ring *sds_ring, int ring,
1195 		   u64 sts_data0)
1196 {
1197 	struct net_device *netdev = adapter->netdev;
1198 	struct qlcnic_recv_context *recv_ctx = adapter->recv_ctx;
1199 	struct qlcnic_rx_buffer *buffer;
1200 	struct sk_buff *skb;
1201 	struct qlcnic_host_rds_ring *rds_ring;
1202 	int index, length, cksum, pkt_offset, is_lb_pkt;
1203 	u16 vid = 0xffff, t_vid;
1204 
1205 	if (unlikely(ring >= adapter->max_rds_rings))
1206 		return NULL;
1207 
1208 	rds_ring = &recv_ctx->rds_rings[ring];
1209 
1210 	index = qlcnic_get_sts_refhandle(sts_data0);
1211 	if (unlikely(index >= rds_ring->num_desc))
1212 		return NULL;
1213 
1214 	buffer = &rds_ring->rx_buf_arr[index];
1215 	length = qlcnic_get_sts_totallength(sts_data0);
1216 	cksum  = qlcnic_get_sts_status(sts_data0);
1217 	pkt_offset = qlcnic_get_sts_pkt_offset(sts_data0);
1218 
1219 	skb = qlcnic_process_rxbuf(adapter, rds_ring, index, cksum);
1220 	if (!skb)
1221 		return buffer;
1222 
1223 	if (adapter->rx_mac_learn) {
1224 		t_vid = 0;
1225 		is_lb_pkt = qlcnic_82xx_is_lb_pkt(sts_data0);
1226 		qlcnic_add_lb_filter(adapter, skb, is_lb_pkt, t_vid);
1227 	}
1228 
1229 	if (length > rds_ring->skb_size)
1230 		skb_put(skb, rds_ring->skb_size);
1231 	else
1232 		skb_put(skb, length);
1233 
1234 	if (pkt_offset)
1235 		skb_pull(skb, pkt_offset);
1236 
1237 	if (unlikely(qlcnic_check_rx_tagging(adapter, skb, &vid))) {
1238 		adapter->stats.rxdropped++;
1239 		dev_kfree_skb(skb);
1240 		return buffer;
1241 	}
1242 
1243 	skb->protocol = eth_type_trans(skb, netdev);
1244 
1245 	if (vid != 0xffff)
1246 		__vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q), vid);
1247 
1248 	napi_gro_receive(&sds_ring->napi, skb);
1249 
1250 	adapter->stats.rx_pkts++;
1251 	adapter->stats.rxbytes += length;
1252 
1253 	return buffer;
1254 }
1255 
1256 #define QLC_TCP_HDR_SIZE            20
1257 #define QLC_TCP_TS_OPTION_SIZE      12
1258 #define QLC_TCP_TS_HDR_SIZE         (QLC_TCP_HDR_SIZE + QLC_TCP_TS_OPTION_SIZE)
1259 
1260 static struct qlcnic_rx_buffer *
1261 qlcnic_process_lro(struct qlcnic_adapter *adapter,
1262 		   int ring, u64 sts_data0, u64 sts_data1)
1263 {
1264 	struct net_device *netdev = adapter->netdev;
1265 	struct qlcnic_recv_context *recv_ctx = adapter->recv_ctx;
1266 	struct qlcnic_rx_buffer *buffer;
1267 	struct sk_buff *skb;
1268 	struct qlcnic_host_rds_ring *rds_ring;
1269 	struct iphdr *iph;
1270 	struct ipv6hdr *ipv6h;
1271 	struct tcphdr *th;
1272 	bool push, timestamp;
1273 	int index, l2_hdr_offset, l4_hdr_offset, is_lb_pkt;
1274 	u16 lro_length, length, data_offset, t_vid, vid = 0xffff;
1275 	u32 seq_number;
1276 
1277 	if (unlikely(ring >= adapter->max_rds_rings))
1278 		return NULL;
1279 
1280 	rds_ring = &recv_ctx->rds_rings[ring];
1281 
1282 	index = qlcnic_get_lro_sts_refhandle(sts_data0);
1283 	if (unlikely(index >= rds_ring->num_desc))
1284 		return NULL;
1285 
1286 	buffer = &rds_ring->rx_buf_arr[index];
1287 
1288 	timestamp = qlcnic_get_lro_sts_timestamp(sts_data0);
1289 	lro_length = qlcnic_get_lro_sts_length(sts_data0);
1290 	l2_hdr_offset = qlcnic_get_lro_sts_l2_hdr_offset(sts_data0);
1291 	l4_hdr_offset = qlcnic_get_lro_sts_l4_hdr_offset(sts_data0);
1292 	push = qlcnic_get_lro_sts_push_flag(sts_data0);
1293 	seq_number = qlcnic_get_lro_sts_seq_number(sts_data1);
1294 
1295 	skb = qlcnic_process_rxbuf(adapter, rds_ring, index, STATUS_CKSUM_OK);
1296 	if (!skb)
1297 		return buffer;
1298 
1299 	if (adapter->rx_mac_learn) {
1300 		t_vid = 0;
1301 		is_lb_pkt = qlcnic_82xx_is_lb_pkt(sts_data0);
1302 		qlcnic_add_lb_filter(adapter, skb, is_lb_pkt, t_vid);
1303 	}
1304 
1305 	if (timestamp)
1306 		data_offset = l4_hdr_offset + QLC_TCP_TS_HDR_SIZE;
1307 	else
1308 		data_offset = l4_hdr_offset + QLC_TCP_HDR_SIZE;
1309 
1310 	skb_put(skb, lro_length + data_offset);
1311 	skb_pull(skb, l2_hdr_offset);
1312 
1313 	if (unlikely(qlcnic_check_rx_tagging(adapter, skb, &vid))) {
1314 		adapter->stats.rxdropped++;
1315 		dev_kfree_skb(skb);
1316 		return buffer;
1317 	}
1318 
1319 	skb->protocol = eth_type_trans(skb, netdev);
1320 
1321 	if (ntohs(skb->protocol) == ETH_P_IPV6) {
1322 		ipv6h = (struct ipv6hdr *)skb->data;
1323 		th = (struct tcphdr *)(skb->data + sizeof(struct ipv6hdr));
1324 		length = (th->doff << 2) + lro_length;
1325 		ipv6h->payload_len = htons(length);
1326 	} else {
1327 		iph = (struct iphdr *)skb->data;
1328 		th = (struct tcphdr *)(skb->data + (iph->ihl << 2));
1329 		length = (iph->ihl << 2) + (th->doff << 2) + lro_length;
1330 		csum_replace2(&iph->check, iph->tot_len, htons(length));
1331 		iph->tot_len = htons(length);
1332 	}
1333 
1334 	th->psh = push;
1335 	th->seq = htonl(seq_number);
1336 	length = skb->len;
1337 
1338 	if (adapter->flags & QLCNIC_FW_LRO_MSS_CAP) {
1339 		skb_shinfo(skb)->gso_size = qlcnic_get_lro_sts_mss(sts_data1);
1340 		if (skb->protocol == htons(ETH_P_IPV6))
1341 			skb_shinfo(skb)->gso_type = SKB_GSO_TCPV6;
1342 		else
1343 			skb_shinfo(skb)->gso_type = SKB_GSO_TCPV4;
1344 	}
1345 
1346 	if (vid != 0xffff)
1347 		__vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q), vid);
1348 	netif_receive_skb(skb);
1349 
1350 	adapter->stats.lro_pkts++;
1351 	adapter->stats.lrobytes += length;
1352 
1353 	return buffer;
1354 }
1355 
1356 static int qlcnic_process_rcv_ring(struct qlcnic_host_sds_ring *sds_ring, int max)
1357 {
1358 	struct qlcnic_host_rds_ring *rds_ring;
1359 	struct qlcnic_adapter *adapter = sds_ring->adapter;
1360 	struct list_head *cur;
1361 	struct status_desc *desc;
1362 	struct qlcnic_rx_buffer *rxbuf;
1363 	int opcode, desc_cnt, count = 0;
1364 	u64 sts_data0, sts_data1;
1365 	u8 ring;
1366 	u32 consumer = sds_ring->consumer;
1367 
1368 	while (count < max) {
1369 		desc = &sds_ring->desc_head[consumer];
1370 		sts_data0 = le64_to_cpu(desc->status_desc_data[0]);
1371 
1372 		if (!(sts_data0 & STATUS_OWNER_HOST))
1373 			break;
1374 
1375 		desc_cnt = qlcnic_get_sts_desc_cnt(sts_data0);
1376 		opcode = qlcnic_get_sts_opcode(sts_data0);
1377 		switch (opcode) {
1378 		case QLCNIC_RXPKT_DESC:
1379 		case QLCNIC_OLD_RXPKT_DESC:
1380 		case QLCNIC_SYN_OFFLOAD:
1381 			ring = qlcnic_get_sts_type(sts_data0);
1382 			rxbuf = qlcnic_process_rcv(adapter, sds_ring, ring,
1383 						   sts_data0);
1384 			break;
1385 		case QLCNIC_LRO_DESC:
1386 			ring = qlcnic_get_lro_sts_type(sts_data0);
1387 			sts_data1 = le64_to_cpu(desc->status_desc_data[1]);
1388 			rxbuf = qlcnic_process_lro(adapter, ring, sts_data0,
1389 						   sts_data1);
1390 			break;
1391 		case QLCNIC_RESPONSE_DESC:
1392 			qlcnic_handle_fw_message(desc_cnt, consumer, sds_ring);
1393 			goto skip;
1394 		default:
1395 			goto skip;
1396 		}
1397 		WARN_ON(desc_cnt > 1);
1398 
1399 		if (likely(rxbuf))
1400 			list_add_tail(&rxbuf->list, &sds_ring->free_list[ring]);
1401 		else
1402 			adapter->stats.null_rxbuf++;
1403 skip:
1404 		for (; desc_cnt > 0; desc_cnt--) {
1405 			desc = &sds_ring->desc_head[consumer];
1406 			desc->status_desc_data[0] = QLCNIC_DESC_OWNER_FW;
1407 			consumer = get_next_index(consumer, sds_ring->num_desc);
1408 		}
1409 		count++;
1410 	}
1411 
1412 	for (ring = 0; ring < adapter->max_rds_rings; ring++) {
1413 		rds_ring = &adapter->recv_ctx->rds_rings[ring];
1414 		if (!list_empty(&sds_ring->free_list[ring])) {
1415 			list_for_each(cur, &sds_ring->free_list[ring]) {
1416 				rxbuf = list_entry(cur, struct qlcnic_rx_buffer,
1417 						   list);
1418 				qlcnic_alloc_rx_skb(adapter, rds_ring, rxbuf);
1419 			}
1420 			spin_lock(&rds_ring->lock);
1421 			list_splice_tail_init(&sds_ring->free_list[ring],
1422 					      &rds_ring->free_list);
1423 			spin_unlock(&rds_ring->lock);
1424 		}
1425 
1426 		qlcnic_post_rx_buffers_nodb(adapter, rds_ring, ring);
1427 	}
1428 
1429 	if (count) {
1430 		sds_ring->consumer = consumer;
1431 		writel(consumer, sds_ring->crb_sts_consumer);
1432 	}
1433 
1434 	return count;
1435 }
1436 
1437 void qlcnic_post_rx_buffers(struct qlcnic_adapter *adapter,
1438 			    struct qlcnic_host_rds_ring *rds_ring, u8 ring_id)
1439 {
1440 	struct rcv_desc *pdesc;
1441 	struct qlcnic_rx_buffer *buffer;
1442 	int count = 0;
1443 	u32 producer, handle;
1444 	struct list_head *head;
1445 
1446 	producer = rds_ring->producer;
1447 	head = &rds_ring->free_list;
1448 
1449 	while (!list_empty(head)) {
1450 
1451 		buffer = list_entry(head->next, struct qlcnic_rx_buffer, list);
1452 
1453 		if (!buffer->skb) {
1454 			if (qlcnic_alloc_rx_skb(adapter, rds_ring, buffer))
1455 				break;
1456 		}
1457 
1458 		count++;
1459 		list_del(&buffer->list);
1460 
1461 		/* make a rcv descriptor  */
1462 		pdesc = &rds_ring->desc_head[producer];
1463 		pdesc->addr_buffer = cpu_to_le64(buffer->dma);
1464 		handle = qlcnic_get_ref_handle(adapter, buffer->ref_handle,
1465 					       ring_id);
1466 		pdesc->reference_handle = cpu_to_le16(handle);
1467 		pdesc->buffer_length = cpu_to_le32(rds_ring->dma_size);
1468 		producer = get_next_index(producer, rds_ring->num_desc);
1469 	}
1470 
1471 	if (count) {
1472 		rds_ring->producer = producer;
1473 		writel((producer-1) & (rds_ring->num_desc-1),
1474 		       rds_ring->crb_rcv_producer);
1475 	}
1476 }
1477 
1478 static void dump_skb(struct sk_buff *skb, struct qlcnic_adapter *adapter)
1479 {
1480 	if (adapter->ahw->msg_enable & NETIF_MSG_DRV) {
1481 		char prefix[30];
1482 
1483 		scnprintf(prefix, sizeof(prefix), "%s: %s: ",
1484 			  dev_name(&adapter->pdev->dev), __func__);
1485 
1486 		print_hex_dump_debug(prefix, DUMP_PREFIX_NONE, 16, 1,
1487 				     skb->data, skb->len, true);
1488 	}
1489 }
1490 
1491 static void qlcnic_process_rcv_diag(struct qlcnic_adapter *adapter, int ring,
1492 				    u64 sts_data0)
1493 {
1494 	struct qlcnic_recv_context *recv_ctx = adapter->recv_ctx;
1495 	struct sk_buff *skb;
1496 	struct qlcnic_host_rds_ring *rds_ring;
1497 	int index, length, cksum, pkt_offset;
1498 
1499 	if (unlikely(ring >= adapter->max_rds_rings))
1500 		return;
1501 
1502 	rds_ring = &recv_ctx->rds_rings[ring];
1503 
1504 	index = qlcnic_get_sts_refhandle(sts_data0);
1505 	length = qlcnic_get_sts_totallength(sts_data0);
1506 	if (unlikely(index >= rds_ring->num_desc))
1507 		return;
1508 
1509 	cksum  = qlcnic_get_sts_status(sts_data0);
1510 	pkt_offset = qlcnic_get_sts_pkt_offset(sts_data0);
1511 
1512 	skb = qlcnic_process_rxbuf(adapter, rds_ring, index, cksum);
1513 	if (!skb)
1514 		return;
1515 
1516 	if (length > rds_ring->skb_size)
1517 		skb_put(skb, rds_ring->skb_size);
1518 	else
1519 		skb_put(skb, length);
1520 
1521 	if (pkt_offset)
1522 		skb_pull(skb, pkt_offset);
1523 
1524 	if (!qlcnic_check_loopback_buff(skb->data, adapter->mac_addr))
1525 		adapter->ahw->diag_cnt++;
1526 	else
1527 		dump_skb(skb, adapter);
1528 
1529 	dev_kfree_skb_any(skb);
1530 	adapter->stats.rx_pkts++;
1531 	adapter->stats.rxbytes += length;
1532 
1533 	return;
1534 }
1535 
1536 void qlcnic_82xx_process_rcv_ring_diag(struct qlcnic_host_sds_ring *sds_ring)
1537 {
1538 	struct qlcnic_adapter *adapter = sds_ring->adapter;
1539 	struct status_desc *desc;
1540 	u64 sts_data0;
1541 	int ring, opcode, desc_cnt;
1542 
1543 	u32 consumer = sds_ring->consumer;
1544 
1545 	desc = &sds_ring->desc_head[consumer];
1546 	sts_data0 = le64_to_cpu(desc->status_desc_data[0]);
1547 
1548 	if (!(sts_data0 & STATUS_OWNER_HOST))
1549 		return;
1550 
1551 	desc_cnt = qlcnic_get_sts_desc_cnt(sts_data0);
1552 	opcode = qlcnic_get_sts_opcode(sts_data0);
1553 	switch (opcode) {
1554 	case QLCNIC_RESPONSE_DESC:
1555 		qlcnic_handle_fw_message(desc_cnt, consumer, sds_ring);
1556 		break;
1557 	default:
1558 		ring = qlcnic_get_sts_type(sts_data0);
1559 		qlcnic_process_rcv_diag(adapter, ring, sts_data0);
1560 		break;
1561 	}
1562 
1563 	for (; desc_cnt > 0; desc_cnt--) {
1564 		desc = &sds_ring->desc_head[consumer];
1565 		desc->status_desc_data[0] = cpu_to_le64(STATUS_OWNER_PHANTOM);
1566 		consumer = get_next_index(consumer, sds_ring->num_desc);
1567 	}
1568 
1569 	sds_ring->consumer = consumer;
1570 	writel(consumer, sds_ring->crb_sts_consumer);
1571 }
1572 
1573 int qlcnic_82xx_napi_add(struct qlcnic_adapter *adapter,
1574 			 struct net_device *netdev)
1575 {
1576 	int ring;
1577 	struct qlcnic_host_sds_ring *sds_ring;
1578 	struct qlcnic_recv_context *recv_ctx = adapter->recv_ctx;
1579 	struct qlcnic_host_tx_ring *tx_ring;
1580 
1581 	if (qlcnic_alloc_sds_rings(recv_ctx, adapter->drv_sds_rings))
1582 		return -ENOMEM;
1583 
1584 	for (ring = 0; ring < adapter->drv_sds_rings; ring++) {
1585 		sds_ring = &recv_ctx->sds_rings[ring];
1586 		if (qlcnic_check_multi_tx(adapter) &&
1587 		    !adapter->ahw->diag_test) {
1588 			netif_napi_add(netdev, &sds_ring->napi, qlcnic_rx_poll,
1589 				       NAPI_POLL_WEIGHT);
1590 		} else {
1591 			if (ring == (adapter->drv_sds_rings - 1))
1592 				netif_napi_add(netdev, &sds_ring->napi,
1593 					       qlcnic_poll,
1594 					       NAPI_POLL_WEIGHT);
1595 			else
1596 				netif_napi_add(netdev, &sds_ring->napi,
1597 					       qlcnic_rx_poll,
1598 					       NAPI_POLL_WEIGHT);
1599 		}
1600 	}
1601 
1602 	if (qlcnic_alloc_tx_rings(adapter, netdev)) {
1603 		qlcnic_free_sds_rings(recv_ctx);
1604 		return -ENOMEM;
1605 	}
1606 
1607 	if (qlcnic_check_multi_tx(adapter) && !adapter->ahw->diag_test) {
1608 		for (ring = 0; ring < adapter->drv_tx_rings; ring++) {
1609 			tx_ring = &adapter->tx_ring[ring];
1610 			netif_tx_napi_add(netdev, &tx_ring->napi, qlcnic_tx_poll,
1611 				       NAPI_POLL_WEIGHT);
1612 		}
1613 	}
1614 
1615 	return 0;
1616 }
1617 
1618 void qlcnic_82xx_napi_del(struct qlcnic_adapter *adapter)
1619 {
1620 	int ring;
1621 	struct qlcnic_host_sds_ring *sds_ring;
1622 	struct qlcnic_recv_context *recv_ctx = adapter->recv_ctx;
1623 	struct qlcnic_host_tx_ring *tx_ring;
1624 
1625 	for (ring = 0; ring < adapter->drv_sds_rings; ring++) {
1626 		sds_ring = &recv_ctx->sds_rings[ring];
1627 		netif_napi_del(&sds_ring->napi);
1628 	}
1629 
1630 	qlcnic_free_sds_rings(adapter->recv_ctx);
1631 
1632 	if (qlcnic_check_multi_tx(adapter) && !adapter->ahw->diag_test) {
1633 		for (ring = 0; ring < adapter->drv_tx_rings; ring++) {
1634 			tx_ring = &adapter->tx_ring[ring];
1635 			netif_napi_del(&tx_ring->napi);
1636 		}
1637 	}
1638 
1639 	qlcnic_free_tx_rings(adapter);
1640 }
1641 
1642 void qlcnic_82xx_napi_enable(struct qlcnic_adapter *adapter)
1643 {
1644 	int ring;
1645 	struct qlcnic_host_sds_ring *sds_ring;
1646 	struct qlcnic_host_tx_ring *tx_ring;
1647 	struct qlcnic_recv_context *recv_ctx = adapter->recv_ctx;
1648 
1649 	if (adapter->is_up != QLCNIC_ADAPTER_UP_MAGIC)
1650 		return;
1651 
1652 	for (ring = 0; ring < adapter->drv_sds_rings; ring++) {
1653 		sds_ring = &recv_ctx->sds_rings[ring];
1654 		napi_enable(&sds_ring->napi);
1655 		qlcnic_enable_sds_intr(adapter, sds_ring);
1656 	}
1657 
1658 	if (qlcnic_check_multi_tx(adapter) &&
1659 	    (adapter->flags & QLCNIC_MSIX_ENABLED) &&
1660 	    !adapter->ahw->diag_test) {
1661 		for (ring = 0; ring < adapter->drv_tx_rings; ring++) {
1662 			tx_ring = &adapter->tx_ring[ring];
1663 			napi_enable(&tx_ring->napi);
1664 			qlcnic_enable_tx_intr(adapter, tx_ring);
1665 		}
1666 	}
1667 }
1668 
1669 void qlcnic_82xx_napi_disable(struct qlcnic_adapter *adapter)
1670 {
1671 	int ring;
1672 	struct qlcnic_host_sds_ring *sds_ring;
1673 	struct qlcnic_host_tx_ring *tx_ring;
1674 	struct qlcnic_recv_context *recv_ctx = adapter->recv_ctx;
1675 
1676 	if (adapter->is_up != QLCNIC_ADAPTER_UP_MAGIC)
1677 		return;
1678 
1679 	for (ring = 0; ring < adapter->drv_sds_rings; ring++) {
1680 		sds_ring = &recv_ctx->sds_rings[ring];
1681 		qlcnic_disable_sds_intr(adapter, sds_ring);
1682 		napi_synchronize(&sds_ring->napi);
1683 		napi_disable(&sds_ring->napi);
1684 	}
1685 
1686 	if ((adapter->flags & QLCNIC_MSIX_ENABLED) &&
1687 	    !adapter->ahw->diag_test &&
1688 	    qlcnic_check_multi_tx(adapter)) {
1689 		for (ring = 0; ring < adapter->drv_tx_rings; ring++) {
1690 			tx_ring = &adapter->tx_ring[ring];
1691 			qlcnic_disable_tx_intr(adapter, tx_ring);
1692 			napi_synchronize(&tx_ring->napi);
1693 			napi_disable(&tx_ring->napi);
1694 		}
1695 	}
1696 }
1697 
1698 #define QLC_83XX_NORMAL_LB_PKT	(1ULL << 36)
1699 #define QLC_83XX_LRO_LB_PKT	(1ULL << 46)
1700 
1701 static inline int qlcnic_83xx_is_lb_pkt(u64 sts_data, int lro_pkt)
1702 {
1703 	if (lro_pkt)
1704 		return (sts_data & QLC_83XX_LRO_LB_PKT) ? 1 : 0;
1705 	else
1706 		return (sts_data & QLC_83XX_NORMAL_LB_PKT) ? 1 : 0;
1707 }
1708 
1709 #define QLCNIC_ENCAP_LENGTH_MASK	0x7f
1710 
1711 static inline u8 qlcnic_encap_length(u64 sts_data)
1712 {
1713 	return sts_data & QLCNIC_ENCAP_LENGTH_MASK;
1714 }
1715 
1716 static struct qlcnic_rx_buffer *
1717 qlcnic_83xx_process_rcv(struct qlcnic_adapter *adapter,
1718 			struct qlcnic_host_sds_ring *sds_ring,
1719 			u8 ring, u64 sts_data[])
1720 {
1721 	struct net_device *netdev = adapter->netdev;
1722 	struct qlcnic_recv_context *recv_ctx = adapter->recv_ctx;
1723 	struct qlcnic_rx_buffer *buffer;
1724 	struct sk_buff *skb;
1725 	struct qlcnic_host_rds_ring *rds_ring;
1726 	int index, length, cksum, is_lb_pkt;
1727 	u16 vid = 0xffff;
1728 	int err;
1729 
1730 	if (unlikely(ring >= adapter->max_rds_rings))
1731 		return NULL;
1732 
1733 	rds_ring = &recv_ctx->rds_rings[ring];
1734 
1735 	index = qlcnic_83xx_hndl(sts_data[0]);
1736 	if (unlikely(index >= rds_ring->num_desc))
1737 		return NULL;
1738 
1739 	buffer = &rds_ring->rx_buf_arr[index];
1740 	length = qlcnic_83xx_pktln(sts_data[0]);
1741 	cksum  = qlcnic_83xx_csum_status(sts_data[1]);
1742 	skb = qlcnic_process_rxbuf(adapter, rds_ring, index, cksum);
1743 	if (!skb)
1744 		return buffer;
1745 
1746 	if (length > rds_ring->skb_size)
1747 		skb_put(skb, rds_ring->skb_size);
1748 	else
1749 		skb_put(skb, length);
1750 
1751 	err = qlcnic_check_rx_tagging(adapter, skb, &vid);
1752 
1753 	if (adapter->rx_mac_learn) {
1754 		is_lb_pkt = qlcnic_83xx_is_lb_pkt(sts_data[1], 0);
1755 		qlcnic_add_lb_filter(adapter, skb, is_lb_pkt, vid);
1756 	}
1757 
1758 	if (unlikely(err)) {
1759 		adapter->stats.rxdropped++;
1760 		dev_kfree_skb(skb);
1761 		return buffer;
1762 	}
1763 
1764 	skb->protocol = eth_type_trans(skb, netdev);
1765 
1766 	if (qlcnic_encap_length(sts_data[1]) &&
1767 	    skb->ip_summed == CHECKSUM_UNNECESSARY) {
1768 		skb->csum_level = 1;
1769 		adapter->stats.encap_rx_csummed++;
1770 	}
1771 
1772 	if (vid != 0xffff)
1773 		__vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q), vid);
1774 
1775 	napi_gro_receive(&sds_ring->napi, skb);
1776 
1777 	adapter->stats.rx_pkts++;
1778 	adapter->stats.rxbytes += length;
1779 
1780 	return buffer;
1781 }
1782 
1783 static struct qlcnic_rx_buffer *
1784 qlcnic_83xx_process_lro(struct qlcnic_adapter *adapter,
1785 			u8 ring, u64 sts_data[])
1786 {
1787 	struct net_device *netdev = adapter->netdev;
1788 	struct qlcnic_recv_context *recv_ctx = adapter->recv_ctx;
1789 	struct qlcnic_rx_buffer *buffer;
1790 	struct sk_buff *skb;
1791 	struct qlcnic_host_rds_ring *rds_ring;
1792 	struct iphdr *iph;
1793 	struct ipv6hdr *ipv6h;
1794 	struct tcphdr *th;
1795 	bool push;
1796 	int l2_hdr_offset, l4_hdr_offset;
1797 	int index, is_lb_pkt;
1798 	u16 lro_length, length, data_offset, gso_size;
1799 	u16 vid = 0xffff;
1800 	int err;
1801 
1802 	if (unlikely(ring >= adapter->max_rds_rings))
1803 		return NULL;
1804 
1805 	rds_ring = &recv_ctx->rds_rings[ring];
1806 
1807 	index = qlcnic_83xx_hndl(sts_data[0]);
1808 	if (unlikely(index >= rds_ring->num_desc))
1809 		return NULL;
1810 
1811 	buffer = &rds_ring->rx_buf_arr[index];
1812 
1813 	lro_length = qlcnic_83xx_lro_pktln(sts_data[0]);
1814 	l2_hdr_offset = qlcnic_83xx_l2_hdr_off(sts_data[1]);
1815 	l4_hdr_offset = qlcnic_83xx_l4_hdr_off(sts_data[1]);
1816 	push = qlcnic_83xx_is_psh_bit(sts_data[1]);
1817 
1818 	skb = qlcnic_process_rxbuf(adapter, rds_ring, index, STATUS_CKSUM_OK);
1819 	if (!skb)
1820 		return buffer;
1821 
1822 	if (qlcnic_83xx_is_tstamp(sts_data[1]))
1823 		data_offset = l4_hdr_offset + QLCNIC_TCP_TS_HDR_SIZE;
1824 	else
1825 		data_offset = l4_hdr_offset + QLCNIC_TCP_HDR_SIZE;
1826 
1827 	skb_put(skb, lro_length + data_offset);
1828 	skb_pull(skb, l2_hdr_offset);
1829 
1830 	err = qlcnic_check_rx_tagging(adapter, skb, &vid);
1831 
1832 	if (adapter->rx_mac_learn) {
1833 		is_lb_pkt = qlcnic_83xx_is_lb_pkt(sts_data[1], 1);
1834 		qlcnic_add_lb_filter(adapter, skb, is_lb_pkt, vid);
1835 	}
1836 
1837 	if (unlikely(err)) {
1838 		adapter->stats.rxdropped++;
1839 		dev_kfree_skb(skb);
1840 		return buffer;
1841 	}
1842 
1843 	skb->protocol = eth_type_trans(skb, netdev);
1844 	if (ntohs(skb->protocol) == ETH_P_IPV6) {
1845 		ipv6h = (struct ipv6hdr *)skb->data;
1846 		th = (struct tcphdr *)(skb->data + sizeof(struct ipv6hdr));
1847 
1848 		length = (th->doff << 2) + lro_length;
1849 		ipv6h->payload_len = htons(length);
1850 	} else {
1851 		iph = (struct iphdr *)skb->data;
1852 		th = (struct tcphdr *)(skb->data + (iph->ihl << 2));
1853 		length = (iph->ihl << 2) + (th->doff << 2) + lro_length;
1854 		csum_replace2(&iph->check, iph->tot_len, htons(length));
1855 		iph->tot_len = htons(length);
1856 	}
1857 
1858 	th->psh = push;
1859 	length = skb->len;
1860 
1861 	if (adapter->flags & QLCNIC_FW_LRO_MSS_CAP) {
1862 		gso_size = qlcnic_83xx_get_lro_sts_mss(sts_data[0]);
1863 		skb_shinfo(skb)->gso_size = gso_size;
1864 		if (skb->protocol == htons(ETH_P_IPV6))
1865 			skb_shinfo(skb)->gso_type = SKB_GSO_TCPV6;
1866 		else
1867 			skb_shinfo(skb)->gso_type = SKB_GSO_TCPV4;
1868 	}
1869 
1870 	if (vid != 0xffff)
1871 		__vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q), vid);
1872 
1873 	netif_receive_skb(skb);
1874 
1875 	adapter->stats.lro_pkts++;
1876 	adapter->stats.lrobytes += length;
1877 	return buffer;
1878 }
1879 
1880 static int qlcnic_83xx_process_rcv_ring(struct qlcnic_host_sds_ring *sds_ring,
1881 					int max)
1882 {
1883 	struct qlcnic_host_rds_ring *rds_ring;
1884 	struct qlcnic_adapter *adapter = sds_ring->adapter;
1885 	struct list_head *cur;
1886 	struct status_desc *desc;
1887 	struct qlcnic_rx_buffer *rxbuf = NULL;
1888 	u8 ring;
1889 	u64 sts_data[2];
1890 	int count = 0, opcode;
1891 	u32 consumer = sds_ring->consumer;
1892 
1893 	while (count < max) {
1894 		desc = &sds_ring->desc_head[consumer];
1895 		sts_data[1] = le64_to_cpu(desc->status_desc_data[1]);
1896 		opcode = qlcnic_83xx_opcode(sts_data[1]);
1897 		if (!opcode)
1898 			break;
1899 		sts_data[0] = le64_to_cpu(desc->status_desc_data[0]);
1900 		ring = QLCNIC_FETCH_RING_ID(sts_data[0]);
1901 
1902 		switch (opcode) {
1903 		case QLC_83XX_REG_DESC:
1904 			rxbuf = qlcnic_83xx_process_rcv(adapter, sds_ring,
1905 							ring, sts_data);
1906 			break;
1907 		case QLC_83XX_LRO_DESC:
1908 			rxbuf = qlcnic_83xx_process_lro(adapter, ring,
1909 							sts_data);
1910 			break;
1911 		default:
1912 			dev_info(&adapter->pdev->dev,
1913 				 "Unknown opcode: 0x%x\n", opcode);
1914 			goto skip;
1915 		}
1916 
1917 		if (likely(rxbuf))
1918 			list_add_tail(&rxbuf->list, &sds_ring->free_list[ring]);
1919 		else
1920 			adapter->stats.null_rxbuf++;
1921 skip:
1922 		desc = &sds_ring->desc_head[consumer];
1923 		/* Reset the descriptor */
1924 		desc->status_desc_data[1] = 0;
1925 		consumer = get_next_index(consumer, sds_ring->num_desc);
1926 		count++;
1927 	}
1928 	for (ring = 0; ring < adapter->max_rds_rings; ring++) {
1929 		rds_ring = &adapter->recv_ctx->rds_rings[ring];
1930 		if (!list_empty(&sds_ring->free_list[ring])) {
1931 			list_for_each(cur, &sds_ring->free_list[ring]) {
1932 				rxbuf = list_entry(cur, struct qlcnic_rx_buffer,
1933 						   list);
1934 				qlcnic_alloc_rx_skb(adapter, rds_ring, rxbuf);
1935 			}
1936 			spin_lock(&rds_ring->lock);
1937 			list_splice_tail_init(&sds_ring->free_list[ring],
1938 					      &rds_ring->free_list);
1939 			spin_unlock(&rds_ring->lock);
1940 		}
1941 		qlcnic_post_rx_buffers_nodb(adapter, rds_ring, ring);
1942 	}
1943 	if (count) {
1944 		sds_ring->consumer = consumer;
1945 		writel(consumer, sds_ring->crb_sts_consumer);
1946 	}
1947 	return count;
1948 }
1949 
1950 static int qlcnic_83xx_msix_sriov_vf_poll(struct napi_struct *napi, int budget)
1951 {
1952 	int tx_complete;
1953 	int work_done;
1954 	struct qlcnic_host_sds_ring *sds_ring;
1955 	struct qlcnic_adapter *adapter;
1956 	struct qlcnic_host_tx_ring *tx_ring;
1957 
1958 	sds_ring = container_of(napi, struct qlcnic_host_sds_ring, napi);
1959 	adapter = sds_ring->adapter;
1960 	/* tx ring count = 1 */
1961 	tx_ring = adapter->tx_ring;
1962 
1963 	tx_complete = qlcnic_process_cmd_ring(adapter, tx_ring, budget);
1964 	work_done = qlcnic_83xx_process_rcv_ring(sds_ring, budget);
1965 
1966 	/* Check if we need a repoll */
1967 	if (!tx_complete)
1968 		work_done = budget;
1969 
1970 	if (work_done < budget) {
1971 		napi_complete_done(&sds_ring->napi, work_done);
1972 		qlcnic_enable_sds_intr(adapter, sds_ring);
1973 	}
1974 
1975 	return work_done;
1976 }
1977 
1978 static int qlcnic_83xx_poll(struct napi_struct *napi, int budget)
1979 {
1980 	int tx_complete;
1981 	int work_done;
1982 	struct qlcnic_host_sds_ring *sds_ring;
1983 	struct qlcnic_adapter *adapter;
1984 	struct qlcnic_host_tx_ring *tx_ring;
1985 
1986 	sds_ring = container_of(napi, struct qlcnic_host_sds_ring, napi);
1987 	adapter = sds_ring->adapter;
1988 	/* tx ring count = 1 */
1989 	tx_ring = adapter->tx_ring;
1990 
1991 	tx_complete = qlcnic_process_cmd_ring(adapter, tx_ring, budget);
1992 	work_done = qlcnic_83xx_process_rcv_ring(sds_ring, budget);
1993 
1994 	/* Check if we need a repoll */
1995 	if (!tx_complete)
1996 		work_done = budget;
1997 
1998 	if (work_done < budget) {
1999 		napi_complete_done(&sds_ring->napi, work_done);
2000 		qlcnic_enable_sds_intr(adapter, sds_ring);
2001 	}
2002 
2003 	return work_done;
2004 }
2005 
2006 static int qlcnic_83xx_msix_tx_poll(struct napi_struct *napi, int budget)
2007 {
2008 	int work_done;
2009 	struct qlcnic_host_tx_ring *tx_ring;
2010 	struct qlcnic_adapter *adapter;
2011 
2012 	tx_ring = container_of(napi, struct qlcnic_host_tx_ring, napi);
2013 	adapter = tx_ring->adapter;
2014 	work_done = qlcnic_process_cmd_ring(adapter, tx_ring, budget);
2015 	if (work_done) {
2016 		napi_complete(&tx_ring->napi);
2017 		if (test_bit(__QLCNIC_DEV_UP , &adapter->state))
2018 			qlcnic_enable_tx_intr(adapter, tx_ring);
2019 	} else {
2020 		/* need a repoll */
2021 		work_done = budget;
2022 	}
2023 
2024 	return work_done;
2025 }
2026 
2027 static int qlcnic_83xx_rx_poll(struct napi_struct *napi, int budget)
2028 {
2029 	int work_done;
2030 	struct qlcnic_host_sds_ring *sds_ring;
2031 	struct qlcnic_adapter *adapter;
2032 
2033 	sds_ring = container_of(napi, struct qlcnic_host_sds_ring, napi);
2034 	adapter = sds_ring->adapter;
2035 	work_done = qlcnic_83xx_process_rcv_ring(sds_ring, budget);
2036 	if (work_done < budget) {
2037 		napi_complete_done(&sds_ring->napi, work_done);
2038 		if (test_bit(__QLCNIC_DEV_UP, &adapter->state))
2039 			qlcnic_enable_sds_intr(adapter, sds_ring);
2040 	}
2041 
2042 	return work_done;
2043 }
2044 
2045 void qlcnic_83xx_napi_enable(struct qlcnic_adapter *adapter)
2046 {
2047 	int ring;
2048 	struct qlcnic_host_sds_ring *sds_ring;
2049 	struct qlcnic_host_tx_ring *tx_ring;
2050 	struct qlcnic_recv_context *recv_ctx = adapter->recv_ctx;
2051 
2052 	if (adapter->is_up != QLCNIC_ADAPTER_UP_MAGIC)
2053 		return;
2054 
2055 	for (ring = 0; ring < adapter->drv_sds_rings; ring++) {
2056 		sds_ring = &recv_ctx->sds_rings[ring];
2057 		napi_enable(&sds_ring->napi);
2058 		if (adapter->flags & QLCNIC_MSIX_ENABLED)
2059 			qlcnic_enable_sds_intr(adapter, sds_ring);
2060 	}
2061 
2062 	if ((adapter->flags & QLCNIC_MSIX_ENABLED) &&
2063 	    !(adapter->flags & QLCNIC_TX_INTR_SHARED)) {
2064 		for (ring = 0; ring < adapter->drv_tx_rings; ring++) {
2065 			tx_ring = &adapter->tx_ring[ring];
2066 			napi_enable(&tx_ring->napi);
2067 			qlcnic_enable_tx_intr(adapter, tx_ring);
2068 		}
2069 	}
2070 }
2071 
2072 void qlcnic_83xx_napi_disable(struct qlcnic_adapter *adapter)
2073 {
2074 	int ring;
2075 	struct qlcnic_host_sds_ring *sds_ring;
2076 	struct qlcnic_recv_context *recv_ctx = adapter->recv_ctx;
2077 	struct qlcnic_host_tx_ring *tx_ring;
2078 
2079 	if (adapter->is_up != QLCNIC_ADAPTER_UP_MAGIC)
2080 		return;
2081 
2082 	for (ring = 0; ring < adapter->drv_sds_rings; ring++) {
2083 		sds_ring = &recv_ctx->sds_rings[ring];
2084 		if (adapter->flags & QLCNIC_MSIX_ENABLED)
2085 			qlcnic_disable_sds_intr(adapter, sds_ring);
2086 		napi_synchronize(&sds_ring->napi);
2087 		napi_disable(&sds_ring->napi);
2088 	}
2089 
2090 	if ((adapter->flags & QLCNIC_MSIX_ENABLED) &&
2091 	    !(adapter->flags & QLCNIC_TX_INTR_SHARED)) {
2092 		for (ring = 0; ring < adapter->drv_tx_rings; ring++) {
2093 			tx_ring = &adapter->tx_ring[ring];
2094 			qlcnic_disable_tx_intr(adapter, tx_ring);
2095 			napi_synchronize(&tx_ring->napi);
2096 			napi_disable(&tx_ring->napi);
2097 		}
2098 	}
2099 }
2100 
2101 int qlcnic_83xx_napi_add(struct qlcnic_adapter *adapter,
2102 			 struct net_device *netdev)
2103 {
2104 	int ring;
2105 	struct qlcnic_host_sds_ring *sds_ring;
2106 	struct qlcnic_host_tx_ring *tx_ring;
2107 	struct qlcnic_recv_context *recv_ctx = adapter->recv_ctx;
2108 
2109 	if (qlcnic_alloc_sds_rings(recv_ctx, adapter->drv_sds_rings))
2110 		return -ENOMEM;
2111 
2112 	for (ring = 0; ring < adapter->drv_sds_rings; ring++) {
2113 		sds_ring = &recv_ctx->sds_rings[ring];
2114 		if (adapter->flags & QLCNIC_MSIX_ENABLED) {
2115 			if (!(adapter->flags & QLCNIC_TX_INTR_SHARED))
2116 				netif_napi_add(netdev, &sds_ring->napi,
2117 					       qlcnic_83xx_rx_poll,
2118 					       NAPI_POLL_WEIGHT);
2119 			else
2120 				netif_napi_add(netdev, &sds_ring->napi,
2121 					       qlcnic_83xx_msix_sriov_vf_poll,
2122 					       NAPI_POLL_WEIGHT);
2123 
2124 		} else {
2125 			netif_napi_add(netdev, &sds_ring->napi,
2126 				       qlcnic_83xx_poll,
2127 				       NAPI_POLL_WEIGHT);
2128 		}
2129 	}
2130 
2131 	if (qlcnic_alloc_tx_rings(adapter, netdev)) {
2132 		qlcnic_free_sds_rings(recv_ctx);
2133 		return -ENOMEM;
2134 	}
2135 
2136 	if ((adapter->flags & QLCNIC_MSIX_ENABLED) &&
2137 	    !(adapter->flags & QLCNIC_TX_INTR_SHARED)) {
2138 		for (ring = 0; ring < adapter->drv_tx_rings; ring++) {
2139 			tx_ring = &adapter->tx_ring[ring];
2140 			netif_tx_napi_add(netdev, &tx_ring->napi,
2141 				       qlcnic_83xx_msix_tx_poll,
2142 				       NAPI_POLL_WEIGHT);
2143 		}
2144 	}
2145 
2146 	return 0;
2147 }
2148 
2149 void qlcnic_83xx_napi_del(struct qlcnic_adapter *adapter)
2150 {
2151 	int ring;
2152 	struct qlcnic_host_sds_ring *sds_ring;
2153 	struct qlcnic_recv_context *recv_ctx = adapter->recv_ctx;
2154 	struct qlcnic_host_tx_ring *tx_ring;
2155 
2156 	for (ring = 0; ring < adapter->drv_sds_rings; ring++) {
2157 		sds_ring = &recv_ctx->sds_rings[ring];
2158 		netif_napi_del(&sds_ring->napi);
2159 	}
2160 
2161 	qlcnic_free_sds_rings(adapter->recv_ctx);
2162 
2163 	if ((adapter->flags & QLCNIC_MSIX_ENABLED) &&
2164 	    !(adapter->flags & QLCNIC_TX_INTR_SHARED)) {
2165 		for (ring = 0; ring < adapter->drv_tx_rings; ring++) {
2166 			tx_ring = &adapter->tx_ring[ring];
2167 			netif_napi_del(&tx_ring->napi);
2168 		}
2169 	}
2170 
2171 	qlcnic_free_tx_rings(adapter);
2172 }
2173 
2174 static void qlcnic_83xx_process_rcv_diag(struct qlcnic_adapter *adapter,
2175 					 int ring, u64 sts_data[])
2176 {
2177 	struct qlcnic_recv_context *recv_ctx = adapter->recv_ctx;
2178 	struct sk_buff *skb;
2179 	struct qlcnic_host_rds_ring *rds_ring;
2180 	int index, length;
2181 
2182 	if (unlikely(ring >= adapter->max_rds_rings))
2183 		return;
2184 
2185 	rds_ring = &recv_ctx->rds_rings[ring];
2186 	index = qlcnic_83xx_hndl(sts_data[0]);
2187 	if (unlikely(index >= rds_ring->num_desc))
2188 		return;
2189 
2190 	length = qlcnic_83xx_pktln(sts_data[0]);
2191 
2192 	skb = qlcnic_process_rxbuf(adapter, rds_ring, index, STATUS_CKSUM_OK);
2193 	if (!skb)
2194 		return;
2195 
2196 	if (length > rds_ring->skb_size)
2197 		skb_put(skb, rds_ring->skb_size);
2198 	else
2199 		skb_put(skb, length);
2200 
2201 	if (!qlcnic_check_loopback_buff(skb->data, adapter->mac_addr))
2202 		adapter->ahw->diag_cnt++;
2203 	else
2204 		dump_skb(skb, adapter);
2205 
2206 	dev_kfree_skb_any(skb);
2207 	return;
2208 }
2209 
2210 void qlcnic_83xx_process_rcv_ring_diag(struct qlcnic_host_sds_ring *sds_ring)
2211 {
2212 	struct qlcnic_adapter *adapter = sds_ring->adapter;
2213 	struct status_desc *desc;
2214 	u64 sts_data[2];
2215 	int ring, opcode;
2216 	u32 consumer = sds_ring->consumer;
2217 
2218 	desc = &sds_ring->desc_head[consumer];
2219 	sts_data[0] = le64_to_cpu(desc->status_desc_data[0]);
2220 	sts_data[1] = le64_to_cpu(desc->status_desc_data[1]);
2221 	opcode = qlcnic_83xx_opcode(sts_data[1]);
2222 	if (!opcode)
2223 		return;
2224 
2225 	ring = QLCNIC_FETCH_RING_ID(sts_data[0]);
2226 	qlcnic_83xx_process_rcv_diag(adapter, ring, sts_data);
2227 	desc = &sds_ring->desc_head[consumer];
2228 	desc->status_desc_data[0] = cpu_to_le64(STATUS_OWNER_PHANTOM);
2229 	consumer = get_next_index(consumer, sds_ring->num_desc);
2230 	sds_ring->consumer = consumer;
2231 	writel(consumer, sds_ring->crb_sts_consumer);
2232 }
2233