blob: 84dd83031a1bfcc31c0f8a908fef0c1bb3e7d155 [file] [log] [blame]
Jitendra Kalsaria577ae392013-02-04 12:33:07 +00001/*
2 * QLogic qlcnic NIC Driver
3 * Copyright (c) 2009-2013 QLogic Corporation
4 *
5 * See LICENSE.qlcnic for copyright and licensing details.
6 */
7
Sony Chackoc70001a2012-11-28 04:34:26 +00008#include <linux/netdevice.h>
9#include <linux/if_vlan.h>
10#include <net/ip.h>
11#include <linux/ipv6.h>
Li RongQing1bcac3b2013-03-14 22:50:07 +000012#include <net/checksum.h>
Joe Perches3620af02015-01-03 17:50:16 -080013#include <linux/printk.h>
Sony Chackoc70001a2012-11-28 04:34:26 +000014
15#include "qlcnic.h"
16
Shahed Shaikh381709d2014-03-21 04:41:16 -040017#define QLCNIC_TX_ETHER_PKT 0x01
18#define QLCNIC_TX_TCP_PKT 0x02
19#define QLCNIC_TX_UDP_PKT 0x03
20#define QLCNIC_TX_IP_PKT 0x04
21#define QLCNIC_TX_TCP_LSO 0x05
22#define QLCNIC_TX_TCP_LSO6 0x06
23#define QLCNIC_TX_ENCAP_PKT 0x07
24#define QLCNIC_TX_ENCAP_LSO 0x08
25#define QLCNIC_TX_TCPV6_PKT 0x0b
26#define QLCNIC_TX_UDPV6_PKT 0x0c
27
28#define QLCNIC_FLAGS_VLAN_TAGGED 0x10
29#define QLCNIC_FLAGS_VLAN_OOB 0x40
Sony Chackoc70001a2012-11-28 04:34:26 +000030
31#define qlcnic_set_tx_vlan_tci(cmd_desc, v) \
32 (cmd_desc)->vlan_TCI = cpu_to_le16(v);
33#define qlcnic_set_cmd_desc_port(cmd_desc, var) \
34 ((cmd_desc)->port_ctxid |= ((var) & 0x0F))
35#define qlcnic_set_cmd_desc_ctxid(cmd_desc, var) \
36 ((cmd_desc)->port_ctxid |= ((var) << 4 & 0xF0))
37
38#define qlcnic_set_tx_port(_desc, _port) \
39 ((_desc)->port_ctxid = ((_port) & 0xf) | (((_port) << 4) & 0xf0))
40
41#define qlcnic_set_tx_flags_opcode(_desc, _flags, _opcode) \
42 ((_desc)->flags_opcode |= \
43 cpu_to_le16(((_flags) & 0x7f) | (((_opcode) & 0x3f) << 7)))
44
45#define qlcnic_set_tx_frags_len(_desc, _frags, _len) \
46 ((_desc)->nfrags__length = \
47 cpu_to_le32(((_frags) & 0xff) | (((_len) & 0xffffff) << 8)))
48
49/* owner bits of status_desc */
50#define STATUS_OWNER_HOST (0x1ULL << 56)
51#define STATUS_OWNER_PHANTOM (0x2ULL << 56)
52
53/* Status descriptor:
54 0-3 port, 4-7 status, 8-11 type, 12-27 total_length
55 28-43 reference_handle, 44-47 protocol, 48-52 pkt_offset
56 53-55 desc_cnt, 56-57 owner, 58-63 opcode
57 */
58#define qlcnic_get_sts_port(sts_data) \
59 ((sts_data) & 0x0F)
60#define qlcnic_get_sts_status(sts_data) \
61 (((sts_data) >> 4) & 0x0F)
62#define qlcnic_get_sts_type(sts_data) \
63 (((sts_data) >> 8) & 0x0F)
64#define qlcnic_get_sts_totallength(sts_data) \
65 (((sts_data) >> 12) & 0xFFFF)
66#define qlcnic_get_sts_refhandle(sts_data) \
67 (((sts_data) >> 28) & 0xFFFF)
68#define qlcnic_get_sts_prot(sts_data) \
69 (((sts_data) >> 44) & 0x0F)
70#define qlcnic_get_sts_pkt_offset(sts_data) \
71 (((sts_data) >> 48) & 0x1F)
72#define qlcnic_get_sts_desc_cnt(sts_data) \
73 (((sts_data) >> 53) & 0x7)
74#define qlcnic_get_sts_opcode(sts_data) \
75 (((sts_data) >> 58) & 0x03F)
76
77#define qlcnic_get_lro_sts_refhandle(sts_data) \
Sony Chacko5796bd02012-12-04 03:33:57 +000078 ((sts_data) & 0x07FFF)
Sony Chackoc70001a2012-11-28 04:34:26 +000079#define qlcnic_get_lro_sts_length(sts_data) \
80 (((sts_data) >> 16) & 0x0FFFF)
81#define qlcnic_get_lro_sts_l2_hdr_offset(sts_data) \
82 (((sts_data) >> 32) & 0x0FF)
83#define qlcnic_get_lro_sts_l4_hdr_offset(sts_data) \
84 (((sts_data) >> 40) & 0x0FF)
85#define qlcnic_get_lro_sts_timestamp(sts_data) \
86 (((sts_data) >> 48) & 0x1)
87#define qlcnic_get_lro_sts_type(sts_data) \
88 (((sts_data) >> 49) & 0x7)
89#define qlcnic_get_lro_sts_push_flag(sts_data) \
90 (((sts_data) >> 52) & 0x1)
91#define qlcnic_get_lro_sts_seq_number(sts_data) \
92 ((sts_data) & 0x0FFFFFFFF)
93#define qlcnic_get_lro_sts_mss(sts_data1) \
94 ((sts_data1 >> 32) & 0x0FFFF)
95
Shahed Shaikh99e85872013-02-18 12:06:16 +000096#define qlcnic_83xx_get_lro_sts_mss(sts) ((sts) & 0xffff)
97
Sony Chackoc70001a2012-11-28 04:34:26 +000098/* opcode field in status_desc */
99#define QLCNIC_SYN_OFFLOAD 0x03
100#define QLCNIC_RXPKT_DESC 0x04
101#define QLCNIC_OLD_RXPKT_DESC 0x3f
102#define QLCNIC_RESPONSE_DESC 0x05
103#define QLCNIC_LRO_DESC 0x12
104
Sony Chacko4be41e92013-01-01 03:20:20 +0000105#define QLCNIC_TCP_HDR_SIZE 20
106#define QLCNIC_TCP_TS_OPTION_SIZE 12
107#define QLCNIC_FETCH_RING_ID(handle) ((handle) >> 63)
108#define QLCNIC_DESC_OWNER_FW cpu_to_le64(STATUS_OWNER_PHANTOM)
109
110#define QLCNIC_TCP_TS_HDR_SIZE (QLCNIC_TCP_HDR_SIZE + QLCNIC_TCP_TS_OPTION_SIZE)
111
Sony Chackoc70001a2012-11-28 04:34:26 +0000112/* for status field in status_desc */
113#define STATUS_CKSUM_LOOP 0
114#define STATUS_CKSUM_OK 2
Sony Chackod17dd0d2012-11-28 04:34:27 +0000115
Sony Chacko4be41e92013-01-01 03:20:20 +0000116#define qlcnic_83xx_pktln(sts) ((sts >> 32) & 0x3FFF)
117#define qlcnic_83xx_hndl(sts) ((sts >> 48) & 0x7FFF)
118#define qlcnic_83xx_csum_status(sts) ((sts >> 39) & 7)
119#define qlcnic_83xx_opcode(sts) ((sts >> 42) & 0xF)
120#define qlcnic_83xx_vlan_tag(sts) (((sts) >> 48) & 0xFFFF)
121#define qlcnic_83xx_lro_pktln(sts) (((sts) >> 32) & 0x3FFF)
122#define qlcnic_83xx_l2_hdr_off(sts) (((sts) >> 16) & 0xFF)
123#define qlcnic_83xx_l4_hdr_off(sts) (((sts) >> 24) & 0xFF)
124#define qlcnic_83xx_pkt_cnt(sts) (((sts) >> 16) & 0x7)
125#define qlcnic_83xx_is_tstamp(sts) (((sts) >> 40) & 1)
126#define qlcnic_83xx_is_psh_bit(sts) (((sts) >> 41) & 1)
127#define qlcnic_83xx_is_ip_align(sts) (((sts) >> 46) & 1)
128#define qlcnic_83xx_has_vlan_tag(sts) (((sts) >> 47) & 1)
129
stephen hemminger21041402014-01-16 10:31:27 -0800130static int qlcnic_process_rcv_ring(struct qlcnic_host_sds_ring *sds_ring,
131 int max);
132
133static struct sk_buff *qlcnic_process_rxbuf(struct qlcnic_adapter *,
134 struct qlcnic_host_rds_ring *,
135 u16, u16);
Sony Chacko4be41e92013-01-01 03:20:20 +0000136
Sucheta Chakrabortyb3f7de82014-01-10 11:48:55 -0500137static inline u8 qlcnic_mac_hash(u64 mac, u16 vlan)
Sony Chacko4be41e92013-01-01 03:20:20 +0000138{
Sucheta Chakrabortyb3f7de82014-01-10 11:48:55 -0500139 return (u8)((mac & 0xff) ^ ((mac >> 40) & 0xff) ^ (vlan & 0xff));
Sony Chacko4be41e92013-01-01 03:20:20 +0000140}
141
142static inline u32 qlcnic_get_ref_handle(struct qlcnic_adapter *adapter,
143 u16 handle, u8 ring_id)
144{
Manish Chopra15ca1402013-08-16 19:07:13 -0400145 if (qlcnic_83xx_check(adapter))
Sony Chacko4be41e92013-01-01 03:20:20 +0000146 return handle | (ring_id << 15);
147 else
148 return handle;
149}
150
Shahed Shaikh53643a72013-02-18 13:22:37 +0000151static inline int qlcnic_82xx_is_lb_pkt(u64 sts_data)
152{
153 return (qlcnic_get_sts_status(sts_data) == STATUS_CKSUM_LOOP) ? 1 : 0;
154}
155
Shahed Shaikhe0d138d2013-08-02 23:15:55 -0400156static void qlcnic_delete_rx_list_mac(struct qlcnic_adapter *adapter,
157 struct qlcnic_filter *fil,
158 void *addr, u16 vlan_id)
159{
160 int ret;
161 u8 op;
162
163 op = vlan_id ? QLCNIC_MAC_VLAN_ADD : QLCNIC_MAC_ADD;
164 ret = qlcnic_sre_macaddr_change(adapter, addr, vlan_id, op);
165 if (ret)
166 return;
167
168 op = vlan_id ? QLCNIC_MAC_VLAN_DEL : QLCNIC_MAC_DEL;
169 ret = qlcnic_sre_macaddr_change(adapter, addr, vlan_id, op);
170 if (!ret) {
171 hlist_del(&fil->fnode);
172 adapter->rx_fhash.fnum--;
173 }
174}
175
176static struct qlcnic_filter *qlcnic_find_mac_filter(struct hlist_head *head,
177 void *addr, u16 vlan_id)
178{
179 struct qlcnic_filter *tmp_fil = NULL;
180 struct hlist_node *n;
181
182 hlist_for_each_entry_safe(tmp_fil, n, head, fnode) {
dingtianhong6878f792013-12-30 15:41:14 +0800183 if (ether_addr_equal(tmp_fil->faddr, addr) &&
Shahed Shaikhe0d138d2013-08-02 23:15:55 -0400184 tmp_fil->vlan_id == vlan_id)
185 return tmp_fil;
186 }
187
188 return NULL;
189}
190
stephen hemminger21041402014-01-16 10:31:27 -0800191static void qlcnic_add_lb_filter(struct qlcnic_adapter *adapter,
192 struct sk_buff *skb, int loopback_pkt, u16 vlan_id)
Shahed Shaikh53643a72013-02-18 13:22:37 +0000193{
194 struct ethhdr *phdr = (struct ethhdr *)(skb->data);
195 struct qlcnic_filter *fil, *tmp_fil;
Shahed Shaikh53643a72013-02-18 13:22:37 +0000196 struct hlist_head *head;
197 unsigned long time;
198 u64 src_addr = 0;
Shahed Shaikhe0d138d2013-08-02 23:15:55 -0400199 u8 hindex, op;
Shahed Shaikh53643a72013-02-18 13:22:37 +0000200 int ret;
201
Sucheta Chakrabortyb3f7de82014-01-10 11:48:55 -0500202 if (!qlcnic_sriov_pf_check(adapter) || (vlan_id == 0xffff))
203 vlan_id = 0;
204
Shahed Shaikh53643a72013-02-18 13:22:37 +0000205 memcpy(&src_addr, phdr->h_source, ETH_ALEN);
Sucheta Chakrabortyb3f7de82014-01-10 11:48:55 -0500206 hindex = qlcnic_mac_hash(src_addr, vlan_id) &
Shahed Shaikhe0d138d2013-08-02 23:15:55 -0400207 (adapter->fhash.fbucket_size - 1);
Shahed Shaikh53643a72013-02-18 13:22:37 +0000208
209 if (loopback_pkt) {
210 if (adapter->rx_fhash.fnum >= adapter->rx_fhash.fmax)
211 return;
212
Shahed Shaikh53643a72013-02-18 13:22:37 +0000213 head = &(adapter->rx_fhash.fhead[hindex]);
214
Shahed Shaikhe0d138d2013-08-02 23:15:55 -0400215 tmp_fil = qlcnic_find_mac_filter(head, &src_addr, vlan_id);
216 if (tmp_fil) {
217 time = tmp_fil->ftime;
218 if (time_after(jiffies, QLCNIC_READD_AGE * HZ + time))
219 tmp_fil->ftime = jiffies;
220 return;
Shahed Shaikh53643a72013-02-18 13:22:37 +0000221 }
222
223 fil = kzalloc(sizeof(struct qlcnic_filter), GFP_ATOMIC);
224 if (!fil)
225 return;
226
227 fil->ftime = jiffies;
228 memcpy(fil->faddr, &src_addr, ETH_ALEN);
229 fil->vlan_id = vlan_id;
230 spin_lock(&adapter->rx_mac_learn_lock);
231 hlist_add_head(&(fil->fnode), head);
232 adapter->rx_fhash.fnum++;
233 spin_unlock(&adapter->rx_mac_learn_lock);
234 } else {
Shahed Shaikhe0d138d2013-08-02 23:15:55 -0400235 head = &adapter->fhash.fhead[hindex];
Shahed Shaikh53643a72013-02-18 13:22:37 +0000236
Shahed Shaikhe0d138d2013-08-02 23:15:55 -0400237 spin_lock(&adapter->mac_learn_lock);
Shahed Shaikh53643a72013-02-18 13:22:37 +0000238
Shahed Shaikhe0d138d2013-08-02 23:15:55 -0400239 tmp_fil = qlcnic_find_mac_filter(head, &src_addr, vlan_id);
240 if (tmp_fil) {
Shahed Shaikh53643a72013-02-18 13:22:37 +0000241 op = vlan_id ? QLCNIC_MAC_VLAN_DEL : QLCNIC_MAC_DEL;
242 ret = qlcnic_sre_macaddr_change(adapter,
243 (u8 *)&src_addr,
244 vlan_id, op);
245 if (!ret) {
Shahed Shaikhe0d138d2013-08-02 23:15:55 -0400246 hlist_del(&tmp_fil->fnode);
247 adapter->fhash.fnum--;
Shahed Shaikh53643a72013-02-18 13:22:37 +0000248 }
Shahed Shaikhe0d138d2013-08-02 23:15:55 -0400249
250 spin_unlock(&adapter->mac_learn_lock);
251
252 return;
Shahed Shaikh53643a72013-02-18 13:22:37 +0000253 }
Shahed Shaikhe0d138d2013-08-02 23:15:55 -0400254
255 spin_unlock(&adapter->mac_learn_lock);
256
257 head = &adapter->rx_fhash.fhead[hindex];
258
259 spin_lock(&adapter->rx_mac_learn_lock);
260
261 tmp_fil = qlcnic_find_mac_filter(head, &src_addr, vlan_id);
262 if (tmp_fil)
263 qlcnic_delete_rx_list_mac(adapter, tmp_fil, &src_addr,
264 vlan_id);
265
Shahed Shaikh53643a72013-02-18 13:22:37 +0000266 spin_unlock(&adapter->rx_mac_learn_lock);
267 }
268}
269
Sony Chacko7e2cf4f2013-01-01 03:20:17 +0000270void qlcnic_82xx_change_filter(struct qlcnic_adapter *adapter, u64 *uaddr,
Rajesh Borundiaf80bc8f2013-04-19 07:01:08 +0000271 u16 vlan_id)
Sony Chackoc70001a2012-11-28 04:34:26 +0000272{
273 struct cmd_desc_type0 *hwdesc;
274 struct qlcnic_nic_req *req;
275 struct qlcnic_mac_req *mac_req;
276 struct qlcnic_vlan_req *vlan_req;
Sony Chacko7e2cf4f2013-01-01 03:20:17 +0000277 struct qlcnic_host_tx_ring *tx_ring = adapter->tx_ring;
Sony Chackoc70001a2012-11-28 04:34:26 +0000278 u32 producer;
279 u64 word;
280
281 producer = tx_ring->producer;
282 hwdesc = &tx_ring->desc_head[tx_ring->producer];
283
284 req = (struct qlcnic_nic_req *)hwdesc;
285 memset(req, 0, sizeof(struct qlcnic_nic_req));
286 req->qhdr = cpu_to_le64(QLCNIC_REQUEST << 23);
287
288 word = QLCNIC_MAC_EVENT | ((u64)(adapter->portnum) << 16);
289 req->req_hdr = cpu_to_le64(word);
290
291 mac_req = (struct qlcnic_mac_req *)&(req->words[0]);
292 mac_req->op = vlan_id ? QLCNIC_MAC_VLAN_ADD : QLCNIC_MAC_ADD;
Shahed Shaikh4a99ab52013-08-02 23:15:54 -0400293 memcpy(mac_req->mac_addr, uaddr, ETH_ALEN);
Sony Chackoc70001a2012-11-28 04:34:26 +0000294
295 vlan_req = (struct qlcnic_vlan_req *)&req->words[1];
Rajesh Borundiaf80bc8f2013-04-19 07:01:08 +0000296 vlan_req->vlan_id = cpu_to_le16(vlan_id);
Sony Chackoc70001a2012-11-28 04:34:26 +0000297
298 tx_ring->producer = get_next_index(producer, tx_ring->num_desc);
299 smp_mb();
300}
301
Sony Chackod17dd0d2012-11-28 04:34:27 +0000302static void qlcnic_send_filter(struct qlcnic_adapter *adapter,
Sony Chackod17dd0d2012-11-28 04:34:27 +0000303 struct cmd_desc_type0 *first_desc,
304 struct sk_buff *skb)
Sony Chackoc70001a2012-11-28 04:34:26 +0000305{
Sucheta Chakrabortyb3f7de82014-01-10 11:48:55 -0500306 struct vlan_ethhdr *vh = (struct vlan_ethhdr *)(skb->data);
Sony Chacko7e2cf4f2013-01-01 03:20:17 +0000307 struct ethhdr *phdr = (struct ethhdr *)(skb->data);
Sucheta Chakrabortyb3f7de82014-01-10 11:48:55 -0500308 u16 protocol = ntohs(skb->protocol);
309 struct qlcnic_filter *fil, *tmp_fil;
310 struct hlist_head *head;
311 struct hlist_node *n;
Sony Chackoc70001a2012-11-28 04:34:26 +0000312 u64 src_addr = 0;
Rajesh Borundiaf80bc8f2013-04-19 07:01:08 +0000313 u16 vlan_id = 0;
Sucheta Chakrabortyb3f7de82014-01-10 11:48:55 -0500314 u8 hindex, hval;
Sony Chackoc70001a2012-11-28 04:34:26 +0000315
Rajesh Borundiad747c332014-05-09 02:51:31 -0400316 if (ether_addr_equal(phdr->h_source, adapter->mac_addr))
317 return;
318
319 if (adapter->flags & QLCNIC_VLAN_FILTERING) {
Sucheta Chakrabortyb3f7de82014-01-10 11:48:55 -0500320 if (protocol == ETH_P_8021Q) {
321 vh = (struct vlan_ethhdr *)skb->data;
322 vlan_id = ntohs(vh->h_vlan_TCI);
Jiri Pirkodf8a39d2015-01-13 17:13:44 +0100323 } else if (skb_vlan_tag_present(skb)) {
324 vlan_id = skb_vlan_tag_get(skb);
Sucheta Chakrabortyb3f7de82014-01-10 11:48:55 -0500325 }
Sucheta Chakrabortyb3f7de82014-01-10 11:48:55 -0500326 }
Sony Chackoc70001a2012-11-28 04:34:26 +0000327
Sony Chackoc70001a2012-11-28 04:34:26 +0000328 memcpy(&src_addr, phdr->h_source, ETH_ALEN);
Sucheta Chakrabortyb3f7de82014-01-10 11:48:55 -0500329 hval = qlcnic_mac_hash(src_addr, vlan_id);
330 hindex = hval & (adapter->fhash.fbucket_size - 1);
Sony Chackoc70001a2012-11-28 04:34:26 +0000331 head = &(adapter->fhash.fhead[hindex]);
332
Sasha Levinb67bfe02013-02-27 17:06:00 -0800333 hlist_for_each_entry_safe(tmp_fil, n, head, fnode) {
dingtianhonge2072cd2014-01-11 16:23:35 +0800334 if (ether_addr_equal(tmp_fil->faddr, (u8 *)&src_addr) &&
Sony Chacko7e2cf4f2013-01-01 03:20:17 +0000335 tmp_fil->vlan_id == vlan_id) {
Sony Chackod17dd0d2012-11-28 04:34:27 +0000336 if (jiffies > (QLCNIC_READD_AGE * HZ + tmp_fil->ftime))
Sony Chacko7e2cf4f2013-01-01 03:20:17 +0000337 qlcnic_change_filter(adapter, &src_addr,
338 vlan_id);
Sony Chackoc70001a2012-11-28 04:34:26 +0000339 tmp_fil->ftime = jiffies;
340 return;
341 }
342 }
343
Shahed Shaikhddfbac02014-04-25 17:43:56 -0400344 if (unlikely(adapter->fhash.fnum >= adapter->fhash.fmax)) {
345 adapter->stats.mac_filter_limit_overrun++;
346 return;
347 }
348
Sony Chackoc70001a2012-11-28 04:34:26 +0000349 fil = kzalloc(sizeof(struct qlcnic_filter), GFP_ATOMIC);
350 if (!fil)
351 return;
352
Sony Chacko7e2cf4f2013-01-01 03:20:17 +0000353 qlcnic_change_filter(adapter, &src_addr, vlan_id);
Sony Chackoc70001a2012-11-28 04:34:26 +0000354 fil->ftime = jiffies;
355 fil->vlan_id = vlan_id;
356 memcpy(fil->faddr, &src_addr, ETH_ALEN);
357 spin_lock(&adapter->mac_learn_lock);
358 hlist_add_head(&(fil->fnode), head);
359 adapter->fhash.fnum++;
360 spin_unlock(&adapter->mac_learn_lock);
361}
362
Shahed Shaikh381709d2014-03-21 04:41:16 -0400363#define QLCNIC_ENCAP_VXLAN_PKT BIT_0
364#define QLCNIC_ENCAP_OUTER_L3_IP6 BIT_1
365#define QLCNIC_ENCAP_INNER_L3_IP6 BIT_2
366#define QLCNIC_ENCAP_INNER_L4_UDP BIT_3
367#define QLCNIC_ENCAP_DO_L3_CSUM BIT_4
368#define QLCNIC_ENCAP_DO_L4_CSUM BIT_5
369
370static int qlcnic_tx_encap_pkt(struct qlcnic_adapter *adapter,
371 struct cmd_desc_type0 *first_desc,
372 struct sk_buff *skb,
373 struct qlcnic_host_tx_ring *tx_ring)
374{
375 u8 opcode = 0, inner_hdr_len = 0, outer_hdr_len = 0, total_hdr_len = 0;
376 int copied, copy_len, descr_size;
377 u32 producer = tx_ring->producer;
378 struct cmd_desc_type0 *hwdesc;
379 u16 flags = 0, encap_descr = 0;
380
381 opcode = QLCNIC_TX_ETHER_PKT;
382 encap_descr = QLCNIC_ENCAP_VXLAN_PKT;
383
384 if (skb_is_gso(skb)) {
385 inner_hdr_len = skb_inner_transport_header(skb) +
386 inner_tcp_hdrlen(skb) -
387 skb_inner_mac_header(skb);
388
389 /* VXLAN header size = 8 */
390 outer_hdr_len = skb_transport_offset(skb) + 8 +
391 sizeof(struct udphdr);
392 first_desc->outer_hdr_length = outer_hdr_len;
393 total_hdr_len = inner_hdr_len + outer_hdr_len;
394 encap_descr |= QLCNIC_ENCAP_DO_L3_CSUM |
395 QLCNIC_ENCAP_DO_L4_CSUM;
396 first_desc->mss = cpu_to_le16(skb_shinfo(skb)->gso_size);
397 first_desc->hdr_length = inner_hdr_len;
398
399 /* Copy inner and outer headers in Tx descriptor(s)
400 * If total_hdr_len > cmd_desc_type0, use multiple
401 * descriptors
402 */
403 copied = 0;
404 descr_size = (int)sizeof(struct cmd_desc_type0);
405 while (copied < total_hdr_len) {
406 copy_len = min(descr_size, (total_hdr_len - copied));
407 hwdesc = &tx_ring->desc_head[producer];
408 tx_ring->cmd_buf_arr[producer].skb = NULL;
409 skb_copy_from_linear_data_offset(skb, copied,
410 (char *)hwdesc,
411 copy_len);
412 copied += copy_len;
413 producer = get_next_index(producer, tx_ring->num_desc);
414 }
415
416 tx_ring->producer = producer;
417
418 /* Make sure updated tx_ring->producer is visible
419 * for qlcnic_tx_avail()
420 */
421 smp_mb();
422 adapter->stats.encap_lso_frames++;
423
424 opcode = QLCNIC_TX_ENCAP_LSO;
425 } else if (skb->ip_summed == CHECKSUM_PARTIAL) {
426 if (inner_ip_hdr(skb)->version == 6) {
427 if (inner_ipv6_hdr(skb)->nexthdr == IPPROTO_UDP)
428 encap_descr |= QLCNIC_ENCAP_INNER_L4_UDP;
429 } else {
430 if (inner_ip_hdr(skb)->protocol == IPPROTO_UDP)
431 encap_descr |= QLCNIC_ENCAP_INNER_L4_UDP;
432 }
433
434 adapter->stats.encap_tx_csummed++;
435 opcode = QLCNIC_TX_ENCAP_PKT;
436 }
437
438 /* Prepare first 16 bits of byte offset 16 of Tx descriptor */
439 if (ip_hdr(skb)->version == 6)
440 encap_descr |= QLCNIC_ENCAP_OUTER_L3_IP6;
441
442 /* outer IP header's size in 32bit words size*/
443 encap_descr |= (skb_network_header_len(skb) >> 2) << 6;
444
445 /* outer IP header offset */
446 encap_descr |= skb_network_offset(skb) << 10;
447 first_desc->encap_descr = cpu_to_le16(encap_descr);
448
449 first_desc->tcp_hdr_offset = skb_inner_transport_header(skb) -
450 skb->data;
451 first_desc->ip_hdr_offset = skb_inner_network_offset(skb);
452
453 qlcnic_set_tx_flags_opcode(first_desc, flags, opcode);
454
455 return 0;
456}
457
Sony Chackod17dd0d2012-11-28 04:34:27 +0000458static int qlcnic_tx_pkt(struct qlcnic_adapter *adapter,
Himanshu Madhani012ec812013-08-21 11:24:10 -0400459 struct cmd_desc_type0 *first_desc, struct sk_buff *skb,
460 struct qlcnic_host_tx_ring *tx_ring)
Sony Chackoc70001a2012-11-28 04:34:26 +0000461{
Sony Chackod17dd0d2012-11-28 04:34:27 +0000462 u8 l4proto, opcode = 0, hdr_len = 0;
Sony Chackoc70001a2012-11-28 04:34:26 +0000463 u16 flags = 0, vlan_tci = 0;
Sony Chackod17dd0d2012-11-28 04:34:27 +0000464 int copied, offset, copy_len, size;
Sony Chackoc70001a2012-11-28 04:34:26 +0000465 struct cmd_desc_type0 *hwdesc;
466 struct vlan_ethhdr *vh;
Sony Chackoc70001a2012-11-28 04:34:26 +0000467 u16 protocol = ntohs(skb->protocol);
468 u32 producer = tx_ring->producer;
469
470 if (protocol == ETH_P_8021Q) {
471 vh = (struct vlan_ethhdr *)skb->data;
Shahed Shaikh381709d2014-03-21 04:41:16 -0400472 flags = QLCNIC_FLAGS_VLAN_TAGGED;
Sony Chackoc70001a2012-11-28 04:34:26 +0000473 vlan_tci = ntohs(vh->h_vlan_TCI);
474 protocol = ntohs(vh->h_vlan_encapsulated_proto);
Jiri Pirkodf8a39d2015-01-13 17:13:44 +0100475 } else if (skb_vlan_tag_present(skb)) {
Shahed Shaikh381709d2014-03-21 04:41:16 -0400476 flags = QLCNIC_FLAGS_VLAN_OOB;
Jiri Pirkodf8a39d2015-01-13 17:13:44 +0100477 vlan_tci = skb_vlan_tag_get(skb);
Sony Chackoc70001a2012-11-28 04:34:26 +0000478 }
Rajesh Borundia91b72822013-04-19 07:01:12 +0000479 if (unlikely(adapter->tx_pvid)) {
Sony Chackoc70001a2012-11-28 04:34:26 +0000480 if (vlan_tci && !(adapter->flags & QLCNIC_TAGGING_ENABLED))
481 return -EIO;
482 if (vlan_tci && (adapter->flags & QLCNIC_TAGGING_ENABLED))
483 goto set_flags;
484
Shahed Shaikh381709d2014-03-21 04:41:16 -0400485 flags = QLCNIC_FLAGS_VLAN_OOB;
Rajesh Borundia91b72822013-04-19 07:01:12 +0000486 vlan_tci = adapter->tx_pvid;
Sony Chackoc70001a2012-11-28 04:34:26 +0000487 }
488set_flags:
489 qlcnic_set_tx_vlan_tci(first_desc, vlan_tci);
490 qlcnic_set_tx_flags_opcode(first_desc, flags, opcode);
491
492 if (*(skb->data) & BIT_0) {
493 flags |= BIT_0;
494 memcpy(&first_desc->eth_addr, skb->data, ETH_ALEN);
495 }
Shahed Shaikh381709d2014-03-21 04:41:16 -0400496 opcode = QLCNIC_TX_ETHER_PKT;
Sritej Velaga3eead212013-04-18 08:10:05 +0000497 if (skb_is_gso(skb)) {
Sony Chackoc70001a2012-11-28 04:34:26 +0000498 hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
Sony Chackoc70001a2012-11-28 04:34:26 +0000499 first_desc->mss = cpu_to_le16(skb_shinfo(skb)->gso_size);
Shahed Shaikh381709d2014-03-21 04:41:16 -0400500 first_desc->hdr_length = hdr_len;
501 opcode = (protocol == ETH_P_IPV6) ? QLCNIC_TX_TCP_LSO6 :
502 QLCNIC_TX_TCP_LSO;
Sony Chackoc70001a2012-11-28 04:34:26 +0000503
504 /* For LSO, we need to copy the MAC/IP/TCP headers into
505 * the descriptor ring */
506 copied = 0;
507 offset = 2;
508
Shahed Shaikh381709d2014-03-21 04:41:16 -0400509 if (flags & QLCNIC_FLAGS_VLAN_OOB) {
510 first_desc->hdr_length += VLAN_HLEN;
Sony Chackoc70001a2012-11-28 04:34:26 +0000511 first_desc->tcp_hdr_offset = VLAN_HLEN;
512 first_desc->ip_hdr_offset = VLAN_HLEN;
Sony Chackod17dd0d2012-11-28 04:34:27 +0000513
Sony Chackoc70001a2012-11-28 04:34:26 +0000514 /* Only in case of TSO on vlan device */
Shahed Shaikh381709d2014-03-21 04:41:16 -0400515 flags |= QLCNIC_FLAGS_VLAN_TAGGED;
Sony Chackoc70001a2012-11-28 04:34:26 +0000516
517 /* Create a TSO vlan header template for firmware */
Sony Chackoc70001a2012-11-28 04:34:26 +0000518 hwdesc = &tx_ring->desc_head[producer];
519 tx_ring->cmd_buf_arr[producer].skb = NULL;
520
521 copy_len = min((int)sizeof(struct cmd_desc_type0) -
Sony Chackod17dd0d2012-11-28 04:34:27 +0000522 offset, hdr_len + VLAN_HLEN);
Sony Chackoc70001a2012-11-28 04:34:26 +0000523
524 vh = (struct vlan_ethhdr *)((char *) hwdesc + 2);
525 skb_copy_from_linear_data(skb, vh, 12);
526 vh->h_vlan_proto = htons(ETH_P_8021Q);
527 vh->h_vlan_TCI = htons(vlan_tci);
528
529 skb_copy_from_linear_data_offset(skb, 12,
Sony Chackod17dd0d2012-11-28 04:34:27 +0000530 (char *)vh + 16,
531 copy_len - 16);
Sony Chackoc70001a2012-11-28 04:34:26 +0000532 copied = copy_len - VLAN_HLEN;
533 offset = 0;
Sony Chackoc70001a2012-11-28 04:34:26 +0000534 producer = get_next_index(producer, tx_ring->num_desc);
535 }
536
537 while (copied < hdr_len) {
Sony Chackod17dd0d2012-11-28 04:34:27 +0000538 size = (int)sizeof(struct cmd_desc_type0) - offset;
539 copy_len = min(size, (hdr_len - copied));
Sony Chackoc70001a2012-11-28 04:34:26 +0000540 hwdesc = &tx_ring->desc_head[producer];
541 tx_ring->cmd_buf_arr[producer].skb = NULL;
Sony Chackoc70001a2012-11-28 04:34:26 +0000542 skb_copy_from_linear_data_offset(skb, copied,
Sony Chackod17dd0d2012-11-28 04:34:27 +0000543 (char *)hwdesc +
544 offset, copy_len);
Sony Chackoc70001a2012-11-28 04:34:26 +0000545 copied += copy_len;
546 offset = 0;
Sony Chackoc70001a2012-11-28 04:34:26 +0000547 producer = get_next_index(producer, tx_ring->num_desc);
548 }
549
550 tx_ring->producer = producer;
551 smp_mb();
552 adapter->stats.lso_frames++;
553
554 } else if (skb->ip_summed == CHECKSUM_PARTIAL) {
Sony Chackoc70001a2012-11-28 04:34:26 +0000555 if (protocol == ETH_P_IP) {
556 l4proto = ip_hdr(skb)->protocol;
557
558 if (l4proto == IPPROTO_TCP)
Shahed Shaikh381709d2014-03-21 04:41:16 -0400559 opcode = QLCNIC_TX_TCP_PKT;
Sony Chackoc70001a2012-11-28 04:34:26 +0000560 else if (l4proto == IPPROTO_UDP)
Shahed Shaikh381709d2014-03-21 04:41:16 -0400561 opcode = QLCNIC_TX_UDP_PKT;
Sony Chackoc70001a2012-11-28 04:34:26 +0000562 } else if (protocol == ETH_P_IPV6) {
563 l4proto = ipv6_hdr(skb)->nexthdr;
564
565 if (l4proto == IPPROTO_TCP)
Shahed Shaikh381709d2014-03-21 04:41:16 -0400566 opcode = QLCNIC_TX_TCPV6_PKT;
Sony Chackoc70001a2012-11-28 04:34:26 +0000567 else if (l4proto == IPPROTO_UDP)
Shahed Shaikh381709d2014-03-21 04:41:16 -0400568 opcode = QLCNIC_TX_UDPV6_PKT;
Sony Chackoc70001a2012-11-28 04:34:26 +0000569 }
570 }
571 first_desc->tcp_hdr_offset += skb_transport_offset(skb);
572 first_desc->ip_hdr_offset += skb_network_offset(skb);
573 qlcnic_set_tx_flags_opcode(first_desc, flags, opcode);
574
575 return 0;
576}
577
Sony Chackod17dd0d2012-11-28 04:34:27 +0000578static int qlcnic_map_tx_skb(struct pci_dev *pdev, struct sk_buff *skb,
579 struct qlcnic_cmd_buffer *pbuf)
Sony Chackoc70001a2012-11-28 04:34:26 +0000580{
581 struct qlcnic_skb_frag *nf;
582 struct skb_frag_struct *frag;
583 int i, nr_frags;
584 dma_addr_t map;
585
586 nr_frags = skb_shinfo(skb)->nr_frags;
587 nf = &pbuf->frag_array[0];
588
Sony Chackod17dd0d2012-11-28 04:34:27 +0000589 map = pci_map_single(pdev, skb->data, skb_headlen(skb),
590 PCI_DMA_TODEVICE);
Sony Chackoc70001a2012-11-28 04:34:26 +0000591 if (pci_dma_mapping_error(pdev, map))
592 goto out_err;
593
594 nf->dma = map;
595 nf->length = skb_headlen(skb);
596
597 for (i = 0; i < nr_frags; i++) {
598 frag = &skb_shinfo(skb)->frags[i];
599 nf = &pbuf->frag_array[i+1];
Sony Chackoc70001a2012-11-28 04:34:26 +0000600 map = skb_frag_dma_map(&pdev->dev, frag, 0, skb_frag_size(frag),
601 DMA_TO_DEVICE);
602 if (dma_mapping_error(&pdev->dev, map))
603 goto unwind;
604
605 nf->dma = map;
606 nf->length = skb_frag_size(frag);
607 }
608
609 return 0;
610
611unwind:
612 while (--i >= 0) {
613 nf = &pbuf->frag_array[i+1];
614 pci_unmap_page(pdev, nf->dma, nf->length, PCI_DMA_TODEVICE);
615 }
616
617 nf = &pbuf->frag_array[0];
618 pci_unmap_single(pdev, nf->dma, skb_headlen(skb), PCI_DMA_TODEVICE);
619
620out_err:
621 return -ENOMEM;
622}
623
Sony Chackod17dd0d2012-11-28 04:34:27 +0000624static void qlcnic_unmap_buffers(struct pci_dev *pdev, struct sk_buff *skb,
625 struct qlcnic_cmd_buffer *pbuf)
Sony Chackoc70001a2012-11-28 04:34:26 +0000626{
627 struct qlcnic_skb_frag *nf = &pbuf->frag_array[0];
Sony Chackod17dd0d2012-11-28 04:34:27 +0000628 int i, nr_frags = skb_shinfo(skb)->nr_frags;
Sony Chackoc70001a2012-11-28 04:34:26 +0000629
630 for (i = 0; i < nr_frags; i++) {
631 nf = &pbuf->frag_array[i+1];
632 pci_unmap_page(pdev, nf->dma, nf->length, PCI_DMA_TODEVICE);
633 }
634
635 nf = &pbuf->frag_array[0];
636 pci_unmap_single(pdev, nf->dma, skb_headlen(skb), PCI_DMA_TODEVICE);
637 pbuf->skb = NULL;
638}
639
Sony Chackod17dd0d2012-11-28 04:34:27 +0000640static inline void qlcnic_clear_cmddesc(u64 *desc)
Sony Chackoc70001a2012-11-28 04:34:26 +0000641{
642 desc[0] = 0ULL;
643 desc[2] = 0ULL;
644 desc[7] = 0ULL;
645}
646
Sony Chackod17dd0d2012-11-28 04:34:27 +0000647netdev_tx_t qlcnic_xmit_frame(struct sk_buff *skb, struct net_device *netdev)
Sony Chackoc70001a2012-11-28 04:34:26 +0000648{
649 struct qlcnic_adapter *adapter = netdev_priv(netdev);
Himanshu Madhani012ec812013-08-21 11:24:10 -0400650 struct qlcnic_host_tx_ring *tx_ring;
Sony Chackoc70001a2012-11-28 04:34:26 +0000651 struct qlcnic_cmd_buffer *pbuf;
652 struct qlcnic_skb_frag *buffrag;
653 struct cmd_desc_type0 *hwdesc, *first_desc;
654 struct pci_dev *pdev;
655 struct ethhdr *phdr;
Sony Chackod17dd0d2012-11-28 04:34:27 +0000656 int i, k, frag_count, delta = 0;
657 u32 producer, num_txd;
Shahed Shaikh381709d2014-03-21 04:41:16 -0400658 u16 protocol;
659 bool l4_is_udp = false;
Sony Chackoc70001a2012-11-28 04:34:26 +0000660
Sony Chackoc70001a2012-11-28 04:34:26 +0000661 if (!test_bit(__QLCNIC_DEV_UP, &adapter->state)) {
Himanshu Madhani012ec812013-08-21 11:24:10 -0400662 netif_tx_stop_all_queues(netdev);
Sony Chackoc70001a2012-11-28 04:34:26 +0000663 return NETDEV_TX_BUSY;
664 }
665
666 if (adapter->flags & QLCNIC_MACSPOOF) {
667 phdr = (struct ethhdr *)skb->data;
668 if (!ether_addr_equal(phdr->h_source, adapter->mac_addr))
669 goto drop_packet;
670 }
671
Himanshu Madhani18afc102013-11-04 13:31:32 -0500672 tx_ring = &adapter->tx_ring[skb_get_queue_mapping(skb)];
Himanshu Madhani012ec812013-08-21 11:24:10 -0400673 num_txd = tx_ring->num_desc;
674
Sony Chackoc70001a2012-11-28 04:34:26 +0000675 frag_count = skb_shinfo(skb)->nr_frags + 1;
Himanshu Madhani012ec812013-08-21 11:24:10 -0400676
Sony Chackoc70001a2012-11-28 04:34:26 +0000677 /* 14 frags supported for normal packet and
678 * 32 frags supported for TSO packet
679 */
680 if (!skb_is_gso(skb) && frag_count > QLCNIC_MAX_FRAGS_PER_TX) {
Sony Chackoc70001a2012-11-28 04:34:26 +0000681 for (i = 0; i < (frag_count - QLCNIC_MAX_FRAGS_PER_TX); i++)
682 delta += skb_frag_size(&skb_shinfo(skb)->frags[i]);
683
684 if (!__pskb_pull_tail(skb, delta))
685 goto drop_packet;
686
687 frag_count = 1 + skb_shinfo(skb)->nr_frags;
688 }
689
690 if (unlikely(qlcnic_tx_avail(tx_ring) <= TX_STOP_THRESH)) {
Himanshu Madhani012ec812013-08-21 11:24:10 -0400691 netif_tx_stop_queue(tx_ring->txq);
Sony Chackod17dd0d2012-11-28 04:34:27 +0000692 if (qlcnic_tx_avail(tx_ring) > TX_STOP_THRESH) {
Himanshu Madhani012ec812013-08-21 11:24:10 -0400693 netif_tx_start_queue(tx_ring->txq);
Sony Chackod17dd0d2012-11-28 04:34:27 +0000694 } else {
Himanshu Madhanif27c75b2013-11-04 13:31:30 -0500695 tx_ring->tx_stats.xmit_off++;
Sony Chackoc70001a2012-11-28 04:34:26 +0000696 return NETDEV_TX_BUSY;
697 }
698 }
699
700 producer = tx_ring->producer;
701 pbuf = &tx_ring->cmd_buf_arr[producer];
Sony Chackoc70001a2012-11-28 04:34:26 +0000702 pdev = adapter->pdev;
Sony Chackod17dd0d2012-11-28 04:34:27 +0000703 first_desc = &tx_ring->desc_head[producer];
704 hwdesc = &tx_ring->desc_head[producer];
Sony Chackoc70001a2012-11-28 04:34:26 +0000705 qlcnic_clear_cmddesc((u64 *)hwdesc);
706
707 if (qlcnic_map_tx_skb(pdev, skb, pbuf)) {
708 adapter->stats.tx_dma_map_error++;
709 goto drop_packet;
710 }
711
712 pbuf->skb = skb;
713 pbuf->frag_count = frag_count;
714
715 qlcnic_set_tx_frags_len(first_desc, frag_count, skb->len);
716 qlcnic_set_tx_port(first_desc, adapter->portnum);
717
718 for (i = 0; i < frag_count; i++) {
Sony Chackoc70001a2012-11-28 04:34:26 +0000719 k = i % 4;
720
721 if ((k == 0) && (i > 0)) {
722 /* move to next desc.*/
723 producer = get_next_index(producer, num_txd);
724 hwdesc = &tx_ring->desc_head[producer];
725 qlcnic_clear_cmddesc((u64 *)hwdesc);
726 tx_ring->cmd_buf_arr[producer].skb = NULL;
727 }
728
729 buffrag = &pbuf->frag_array[i];
Sony Chackoc70001a2012-11-28 04:34:26 +0000730 hwdesc->buffer_length[k] = cpu_to_le16(buffrag->length);
731 switch (k) {
732 case 0:
733 hwdesc->addr_buffer1 = cpu_to_le64(buffrag->dma);
734 break;
735 case 1:
736 hwdesc->addr_buffer2 = cpu_to_le64(buffrag->dma);
737 break;
738 case 2:
739 hwdesc->addr_buffer3 = cpu_to_le64(buffrag->dma);
740 break;
741 case 3:
742 hwdesc->addr_buffer4 = cpu_to_le64(buffrag->dma);
743 break;
744 }
745 }
746
747 tx_ring->producer = get_next_index(producer, num_txd);
748 smp_mb();
749
Shahed Shaikh381709d2014-03-21 04:41:16 -0400750 protocol = ntohs(skb->protocol);
751 if (protocol == ETH_P_IP)
752 l4_is_udp = ip_hdr(skb)->protocol == IPPROTO_UDP;
753 else if (protocol == ETH_P_IPV6)
754 l4_is_udp = ipv6_hdr(skb)->nexthdr == IPPROTO_UDP;
755
756 /* Check if it is a VXLAN packet */
757 if (!skb->encapsulation || !l4_is_udp ||
758 !qlcnic_encap_tx_offload(adapter)) {
759 if (unlikely(qlcnic_tx_pkt(adapter, first_desc, skb,
760 tx_ring)))
761 goto unwind_buff;
762 } else {
763 if (unlikely(qlcnic_tx_encap_pkt(adapter, first_desc,
764 skb, tx_ring)))
765 goto unwind_buff;
766 }
Sony Chackoc70001a2012-11-28 04:34:26 +0000767
Jitendra Kalsariafe1adc62013-01-25 10:20:40 +0000768 if (adapter->drv_mac_learn)
Sony Chacko4be41e92013-01-01 03:20:20 +0000769 qlcnic_send_filter(adapter, first_desc, skb);
Sony Chackoc70001a2012-11-28 04:34:26 +0000770
Himanshu Madhanif27c75b2013-11-04 13:31:30 -0500771 tx_ring->tx_stats.tx_bytes += skb->len;
772 tx_ring->tx_stats.xmit_called++;
Sony Chackoc70001a2012-11-28 04:34:26 +0000773
Sony Chacko9216a972016-06-29 17:51:34 -0400774 /* Ensure writes are complete before HW fetches Tx descriptors */
775 wmb();
Sony Chackoc70001a2012-11-28 04:34:26 +0000776 qlcnic_update_cmd_producer(tx_ring);
777
778 return NETDEV_TX_OK;
779
780unwind_buff:
781 qlcnic_unmap_buffers(pdev, skb, pbuf);
782drop_packet:
783 adapter->stats.txdropped++;
784 dev_kfree_skb_any(skb);
785 return NETDEV_TX_OK;
786}
787
Sony Chacko7f9664522013-01-01 03:20:19 +0000788void qlcnic_advert_link_change(struct qlcnic_adapter *adapter, int linkup)
Sony Chackoc70001a2012-11-28 04:34:26 +0000789{
790 struct net_device *netdev = adapter->netdev;
791
792 if (adapter->ahw->linkup && !linkup) {
793 netdev_info(netdev, "NIC Link is down\n");
794 adapter->ahw->linkup = 0;
Himanshu Madhanib84caae2013-12-16 15:36:56 -0500795 netif_carrier_off(netdev);
Sony Chackoc70001a2012-11-28 04:34:26 +0000796 } else if (!adapter->ahw->linkup && linkup) {
Shahed Shaikh092dfcf2014-01-28 11:55:30 -0500797 adapter->ahw->linkup = 1;
798
799 /* Do not advertise Link up to the stack if device
800 * is in loopback mode
801 */
802 if (qlcnic_83xx_check(adapter) && adapter->ahw->lb_mode) {
803 netdev_info(netdev, "NIC Link is up for loopback test\n");
Manish Choprad9c602f2014-01-02 13:38:43 -0500804 return;
Shahed Shaikh092dfcf2014-01-28 11:55:30 -0500805 }
Manish Choprad9c602f2014-01-02 13:38:43 -0500806
Sony Chackoc70001a2012-11-28 04:34:26 +0000807 netdev_info(netdev, "NIC Link is up\n");
Himanshu Madhanib84caae2013-12-16 15:36:56 -0500808 netif_carrier_on(netdev);
Sony Chackoc70001a2012-11-28 04:34:26 +0000809 }
810}
811
Sony Chackod17dd0d2012-11-28 04:34:27 +0000812static int qlcnic_alloc_rx_skb(struct qlcnic_adapter *adapter,
813 struct qlcnic_host_rds_ring *rds_ring,
814 struct qlcnic_rx_buffer *buffer)
Sony Chackoc70001a2012-11-28 04:34:26 +0000815{
816 struct sk_buff *skb;
817 dma_addr_t dma;
818 struct pci_dev *pdev = adapter->pdev;
819
820 skb = netdev_alloc_skb(adapter->netdev, rds_ring->skb_size);
821 if (!skb) {
822 adapter->stats.skb_alloc_failure++;
823 return -ENOMEM;
824 }
825
826 skb_reserve(skb, NET_IP_ALIGN);
Sony Chacko4be41e92013-01-01 03:20:20 +0000827 dma = pci_map_single(pdev, skb->data,
828 rds_ring->dma_size, PCI_DMA_FROMDEVICE);
Sony Chackoc70001a2012-11-28 04:34:26 +0000829
830 if (pci_dma_mapping_error(pdev, dma)) {
831 adapter->stats.rx_dma_map_error++;
832 dev_kfree_skb_any(skb);
833 return -ENOMEM;
834 }
835
836 buffer->skb = skb;
837 buffer->dma = dma;
838
839 return 0;
840}
841
842static void qlcnic_post_rx_buffers_nodb(struct qlcnic_adapter *adapter,
Sony Chacko4be41e92013-01-01 03:20:20 +0000843 struct qlcnic_host_rds_ring *rds_ring,
844 u8 ring_id)
Sony Chackoc70001a2012-11-28 04:34:26 +0000845{
846 struct rcv_desc *pdesc;
847 struct qlcnic_rx_buffer *buffer;
848 int count = 0;
Sony Chacko4be41e92013-01-01 03:20:20 +0000849 uint32_t producer, handle;
Sony Chackoc70001a2012-11-28 04:34:26 +0000850 struct list_head *head;
851
852 if (!spin_trylock(&rds_ring->lock))
853 return;
854
855 producer = rds_ring->producer;
Sony Chackoc70001a2012-11-28 04:34:26 +0000856 head = &rds_ring->free_list;
Sony Chackod17dd0d2012-11-28 04:34:27 +0000857 while (!list_empty(head)) {
Sony Chackoc70001a2012-11-28 04:34:26 +0000858 buffer = list_entry(head->next, struct qlcnic_rx_buffer, list);
859
860 if (!buffer->skb) {
861 if (qlcnic_alloc_rx_skb(adapter, rds_ring, buffer))
862 break;
863 }
Sony Chackoc70001a2012-11-28 04:34:26 +0000864 count++;
865 list_del(&buffer->list);
866
867 /* make a rcv descriptor */
868 pdesc = &rds_ring->desc_head[producer];
Sony Chacko4be41e92013-01-01 03:20:20 +0000869 handle = qlcnic_get_ref_handle(adapter,
870 buffer->ref_handle, ring_id);
871 pdesc->reference_handle = cpu_to_le16(handle);
Sony Chackoc70001a2012-11-28 04:34:26 +0000872 pdesc->buffer_length = cpu_to_le32(rds_ring->dma_size);
873 pdesc->addr_buffer = cpu_to_le64(buffer->dma);
Sony Chackoc70001a2012-11-28 04:34:26 +0000874 producer = get_next_index(producer, rds_ring->num_desc);
875 }
Sony Chackoc70001a2012-11-28 04:34:26 +0000876 if (count) {
877 rds_ring->producer = producer;
878 writel((producer - 1) & (rds_ring->num_desc - 1),
Sony Chackod17dd0d2012-11-28 04:34:27 +0000879 rds_ring->crb_rcv_producer);
Sony Chackoc70001a2012-11-28 04:34:26 +0000880 }
881 spin_unlock(&rds_ring->lock);
882}
883
Sony Chacko4be41e92013-01-01 03:20:20 +0000884static int qlcnic_process_cmd_ring(struct qlcnic_adapter *adapter,
885 struct qlcnic_host_tx_ring *tx_ring,
886 int budget)
Sony Chackoc70001a2012-11-28 04:34:26 +0000887{
888 u32 sw_consumer, hw_consumer;
Sony Chackod17dd0d2012-11-28 04:34:27 +0000889 int i, done, count = 0;
Sony Chackoc70001a2012-11-28 04:34:26 +0000890 struct qlcnic_cmd_buffer *buffer;
891 struct pci_dev *pdev = adapter->pdev;
892 struct net_device *netdev = adapter->netdev;
893 struct qlcnic_skb_frag *frag;
Sony Chackoc70001a2012-11-28 04:34:26 +0000894
Shahed Shaikha02bdd42014-01-03 01:34:28 -0500895 if (!spin_trylock(&tx_ring->tx_clean_lock))
Himanshu Madhani34e8c402013-11-04 13:31:31 -0500896 return 1;
897
Sony Chackoc70001a2012-11-28 04:34:26 +0000898 sw_consumer = tx_ring->sw_consumer;
899 hw_consumer = le32_to_cpu(*(tx_ring->hw_consumer));
900
901 while (sw_consumer != hw_consumer) {
902 buffer = &tx_ring->cmd_buf_arr[sw_consumer];
903 if (buffer->skb) {
904 frag = &buffer->frag_array[0];
905 pci_unmap_single(pdev, frag->dma, frag->length,
906 PCI_DMA_TODEVICE);
907 frag->dma = 0ULL;
908 for (i = 1; i < buffer->frag_count; i++) {
909 frag++;
910 pci_unmap_page(pdev, frag->dma, frag->length,
911 PCI_DMA_TODEVICE);
912 frag->dma = 0ULL;
913 }
Himanshu Madhanif27c75b2013-11-04 13:31:30 -0500914 tx_ring->tx_stats.xmit_finished++;
Sony Chackoc70001a2012-11-28 04:34:26 +0000915 dev_kfree_skb_any(buffer->skb);
916 buffer->skb = NULL;
917 }
918
919 sw_consumer = get_next_index(sw_consumer, tx_ring->num_desc);
Sony Chacko4be41e92013-01-01 03:20:20 +0000920 if (++count >= budget)
Sony Chackoc70001a2012-11-28 04:34:26 +0000921 break;
922 }
923
Shahed Shaikha02bdd42014-01-03 01:34:28 -0500924 tx_ring->sw_consumer = sw_consumer;
925
Sony Chackoc70001a2012-11-28 04:34:26 +0000926 if (count && netif_running(netdev)) {
Sony Chackoc70001a2012-11-28 04:34:26 +0000927 smp_mb();
Himanshu Madhani012ec812013-08-21 11:24:10 -0400928 if (netif_tx_queue_stopped(tx_ring->txq) &&
929 netif_carrier_ok(netdev)) {
Sony Chackoc70001a2012-11-28 04:34:26 +0000930 if (qlcnic_tx_avail(tx_ring) > TX_STOP_THRESH) {
Himanshu Madhani012ec812013-08-21 11:24:10 -0400931 netif_tx_wake_queue(tx_ring->txq);
Himanshu Madhanif27c75b2013-11-04 13:31:30 -0500932 tx_ring->tx_stats.xmit_on++;
Sony Chackoc70001a2012-11-28 04:34:26 +0000933 }
934 }
935 adapter->tx_timeo_cnt = 0;
936 }
937 /*
938 * If everything is freed up to consumer then check if the ring is full
939 * If the ring is full then check if more needs to be freed and
940 * schedule the call back again.
941 *
942 * This happens when there are 2 CPUs. One could be freeing and the
943 * other filling it. If the ring is full when we get out of here and
944 * the card has already interrupted the host then the host can miss the
945 * interrupt.
946 *
947 * There is still a possible race condition and the host could miss an
948 * interrupt. The card has to take care of this.
949 */
950 hw_consumer = le32_to_cpu(*(tx_ring->hw_consumer));
951 done = (sw_consumer == hw_consumer);
Shahed Shaikha02bdd42014-01-03 01:34:28 -0500952
953 spin_unlock(&tx_ring->tx_clean_lock);
Sony Chackoc70001a2012-11-28 04:34:26 +0000954
955 return done;
956}
957
958static int qlcnic_poll(struct napi_struct *napi, int budget)
959{
Sony Chacko4be41e92013-01-01 03:20:20 +0000960 int tx_complete, work_done;
Sony Chackod17dd0d2012-11-28 04:34:27 +0000961 struct qlcnic_host_sds_ring *sds_ring;
962 struct qlcnic_adapter *adapter;
Himanshu Madhani012ec812013-08-21 11:24:10 -0400963 struct qlcnic_host_tx_ring *tx_ring;
Sony Chackoc70001a2012-11-28 04:34:26 +0000964
Sony Chackod17dd0d2012-11-28 04:34:27 +0000965 sds_ring = container_of(napi, struct qlcnic_host_sds_ring, napi);
966 adapter = sds_ring->adapter;
Himanshu Madhani012ec812013-08-21 11:24:10 -0400967 tx_ring = sds_ring->tx_ring;
968
969 tx_complete = qlcnic_process_cmd_ring(adapter, tx_ring,
Sony Chacko4be41e92013-01-01 03:20:20 +0000970 budget);
Sony Chackoc70001a2012-11-28 04:34:26 +0000971 work_done = qlcnic_process_rcv_ring(sds_ring, budget);
Shahed Shaikhf31ec952015-02-04 05:41:25 -0500972
973 /* Check if we need a repoll */
974 if (!tx_complete)
975 work_done = budget;
976
977 if (work_done < budget) {
Eric Dumazet6ad20162017-01-30 08:22:01 -0800978 napi_complete_done(&sds_ring->napi, work_done);
Himanshu Madhani012ec812013-08-21 11:24:10 -0400979 if (test_bit(__QLCNIC_DEV_UP, &adapter->state)) {
Manish chopra2cc57522014-01-23 17:18:30 -0500980 qlcnic_enable_sds_intr(adapter, sds_ring);
Himanshu Madhani012ec812013-08-21 11:24:10 -0400981 qlcnic_enable_tx_intr(adapter, tx_ring);
982 }
983 }
984
985 return work_done;
986}
987
988static int qlcnic_tx_poll(struct napi_struct *napi, int budget)
989{
990 struct qlcnic_host_tx_ring *tx_ring;
991 struct qlcnic_adapter *adapter;
992 int work_done;
993
994 tx_ring = container_of(napi, struct qlcnic_host_tx_ring, napi);
995 adapter = tx_ring->adapter;
996
997 work_done = qlcnic_process_cmd_ring(adapter, tx_ring, budget);
998 if (work_done) {
999 napi_complete(&tx_ring->napi);
1000 if (test_bit(__QLCNIC_DEV_UP, &adapter->state))
1001 qlcnic_enable_tx_intr(adapter, tx_ring);
Shahed Shaikhf31ec952015-02-04 05:41:25 -05001002 } else {
1003 /* As qlcnic_process_cmd_ring() returned 0, we need a repoll*/
1004 work_done = budget;
Sony Chackoc70001a2012-11-28 04:34:26 +00001005 }
1006
1007 return work_done;
1008}
1009
1010static int qlcnic_rx_poll(struct napi_struct *napi, int budget)
1011{
Sony Chackod17dd0d2012-11-28 04:34:27 +00001012 struct qlcnic_host_sds_ring *sds_ring;
1013 struct qlcnic_adapter *adapter;
Sony Chackoc70001a2012-11-28 04:34:26 +00001014 int work_done;
1015
Sony Chackod17dd0d2012-11-28 04:34:27 +00001016 sds_ring = container_of(napi, struct qlcnic_host_sds_ring, napi);
1017 adapter = sds_ring->adapter;
1018
Sony Chackoc70001a2012-11-28 04:34:26 +00001019 work_done = qlcnic_process_rcv_ring(sds_ring, budget);
1020
1021 if (work_done < budget) {
Eric Dumazet6ad20162017-01-30 08:22:01 -08001022 napi_complete_done(&sds_ring->napi, work_done);
Sony Chackoc70001a2012-11-28 04:34:26 +00001023 if (test_bit(__QLCNIC_DEV_UP, &adapter->state))
Manish chopra2cc57522014-01-23 17:18:30 -05001024 qlcnic_enable_sds_intr(adapter, sds_ring);
Sony Chackoc70001a2012-11-28 04:34:26 +00001025 }
1026
1027 return work_done;
1028}
1029
Sony Chackod17dd0d2012-11-28 04:34:27 +00001030static void qlcnic_handle_linkevent(struct qlcnic_adapter *adapter,
1031 struct qlcnic_fw_msg *msg)
Sony Chackoc70001a2012-11-28 04:34:26 +00001032{
1033 u32 cable_OUI;
Sony Chackod17dd0d2012-11-28 04:34:27 +00001034 u16 cable_len, link_speed;
1035 u8 link_status, module, duplex, autoneg, lb_status = 0;
Sony Chackoc70001a2012-11-28 04:34:26 +00001036 struct net_device *netdev = adapter->netdev;
1037
Sony Chacko79788452012-12-04 03:33:53 +00001038 adapter->ahw->has_link_events = 1;
Sony Chackoc70001a2012-11-28 04:34:26 +00001039
1040 cable_OUI = msg->body[1] & 0xffffffff;
1041 cable_len = (msg->body[1] >> 32) & 0xffff;
1042 link_speed = (msg->body[1] >> 48) & 0xffff;
1043
1044 link_status = msg->body[2] & 0xff;
1045 duplex = (msg->body[2] >> 16) & 0xff;
1046 autoneg = (msg->body[2] >> 24) & 0xff;
1047 lb_status = (msg->body[2] >> 32) & 0x3;
1048
1049 module = (msg->body[2] >> 8) & 0xff;
1050 if (module == LINKEVENT_MODULE_TWINAX_UNSUPPORTED_CABLE)
Sony Chackod17dd0d2012-11-28 04:34:27 +00001051 dev_info(&netdev->dev,
1052 "unsupported cable: OUI 0x%x, length %d\n",
1053 cable_OUI, cable_len);
Sony Chackoc70001a2012-11-28 04:34:26 +00001054 else if (module == LINKEVENT_MODULE_TWINAX_UNSUPPORTED_CABLELEN)
1055 dev_info(&netdev->dev, "unsupported cable length %d\n",
Sony Chackod17dd0d2012-11-28 04:34:27 +00001056 cable_len);
Sony Chackoc70001a2012-11-28 04:34:26 +00001057
1058 if (!link_status && (lb_status == QLCNIC_ILB_MODE ||
1059 lb_status == QLCNIC_ELB_MODE))
1060 adapter->ahw->loopback_state |= QLCNIC_LINKEVENT;
1061
1062 qlcnic_advert_link_change(adapter, link_status);
1063
1064 if (duplex == LINKEVENT_FULL_DUPLEX)
Sony Chacko79788452012-12-04 03:33:53 +00001065 adapter->ahw->link_duplex = DUPLEX_FULL;
Sony Chackoc70001a2012-11-28 04:34:26 +00001066 else
Sony Chacko79788452012-12-04 03:33:53 +00001067 adapter->ahw->link_duplex = DUPLEX_HALF;
Sony Chackoc70001a2012-11-28 04:34:26 +00001068
Sony Chacko79788452012-12-04 03:33:53 +00001069 adapter->ahw->module_type = module;
1070 adapter->ahw->link_autoneg = autoneg;
Sony Chackoc70001a2012-11-28 04:34:26 +00001071
1072 if (link_status) {
Sony Chacko79788452012-12-04 03:33:53 +00001073 adapter->ahw->link_speed = link_speed;
Sony Chackoc70001a2012-11-28 04:34:26 +00001074 } else {
Sony Chacko79788452012-12-04 03:33:53 +00001075 adapter->ahw->link_speed = SPEED_UNKNOWN;
1076 adapter->ahw->link_duplex = DUPLEX_UNKNOWN;
Sony Chackoc70001a2012-11-28 04:34:26 +00001077 }
1078}
1079
Sony Chackod17dd0d2012-11-28 04:34:27 +00001080static void qlcnic_handle_fw_message(int desc_cnt, int index,
1081 struct qlcnic_host_sds_ring *sds_ring)
Sony Chackoc70001a2012-11-28 04:34:26 +00001082{
1083 struct qlcnic_fw_msg msg;
1084 struct status_desc *desc;
1085 struct qlcnic_adapter *adapter;
1086 struct device *dev;
1087 int i = 0, opcode, ret;
1088
1089 while (desc_cnt > 0 && i < 8) {
1090 desc = &sds_ring->desc_head[index];
1091 msg.words[i++] = le64_to_cpu(desc->status_desc_data[0]);
1092 msg.words[i++] = le64_to_cpu(desc->status_desc_data[1]);
1093
1094 index = get_next_index(index, sds_ring->num_desc);
1095 desc_cnt--;
1096 }
1097
1098 adapter = sds_ring->adapter;
1099 dev = &adapter->pdev->dev;
1100 opcode = qlcnic_get_nic_msg_opcode(msg.body[0]);
1101
1102 switch (opcode) {
1103 case QLCNIC_C2H_OPCODE_GET_LINKEVENT_RESPONSE:
1104 qlcnic_handle_linkevent(adapter, &msg);
1105 break;
1106 case QLCNIC_C2H_OPCODE_CONFIG_LOOPBACK:
1107 ret = (u32)(msg.body[1]);
1108 switch (ret) {
1109 case 0:
1110 adapter->ahw->loopback_state |= QLCNIC_LB_RESPONSE;
1111 break;
1112 case 1:
1113 dev_info(dev, "loopback already in progress\n");
Jitendra Kalsariab9c11982013-08-02 00:57:39 -04001114 adapter->ahw->diag_cnt = -EINPROGRESS;
Sony Chackoc70001a2012-11-28 04:34:26 +00001115 break;
1116 case 2:
1117 dev_info(dev, "loopback cable is not connected\n");
Jitendra Kalsariab9c11982013-08-02 00:57:39 -04001118 adapter->ahw->diag_cnt = -ENODEV;
Sony Chackoc70001a2012-11-28 04:34:26 +00001119 break;
1120 default:
Sony Chackod17dd0d2012-11-28 04:34:27 +00001121 dev_info(dev,
1122 "loopback configure request failed, err %x\n",
1123 ret);
Jitendra Kalsariab9c11982013-08-02 00:57:39 -04001124 adapter->ahw->diag_cnt = -EIO;
Sony Chackoc70001a2012-11-28 04:34:26 +00001125 break;
1126 }
1127 break;
Sucheta Chakraborty2d8ebca2013-08-23 13:38:27 -04001128 case QLCNIC_C2H_OPCODE_GET_DCB_AEN:
Sucheta Chakraborty1de899d2013-10-18 12:22:33 -04001129 qlcnic_dcb_aen_handler(adapter->dcb, (void *)&msg);
Sucheta Chakraborty2d8ebca2013-08-23 13:38:27 -04001130 break;
Sony Chackoc70001a2012-11-28 04:34:26 +00001131 default:
1132 break;
1133 }
1134}
1135
stephen hemminger21041402014-01-16 10:31:27 -08001136static struct sk_buff *qlcnic_process_rxbuf(struct qlcnic_adapter *adapter,
1137 struct qlcnic_host_rds_ring *ring,
1138 u16 index, u16 cksum)
Sony Chackoc70001a2012-11-28 04:34:26 +00001139{
1140 struct qlcnic_rx_buffer *buffer;
1141 struct sk_buff *skb;
1142
Sony Chacko4be41e92013-01-01 03:20:20 +00001143 buffer = &ring->rx_buf_arr[index];
Sony Chackoc70001a2012-11-28 04:34:26 +00001144 if (unlikely(buffer->skb == NULL)) {
1145 WARN_ON(1);
1146 return NULL;
1147 }
1148
Sony Chacko4be41e92013-01-01 03:20:20 +00001149 pci_unmap_single(adapter->pdev, buffer->dma, ring->dma_size,
Sony Chackod17dd0d2012-11-28 04:34:27 +00001150 PCI_DMA_FROMDEVICE);
Sony Chackoc70001a2012-11-28 04:34:26 +00001151
1152 skb = buffer->skb;
Sony Chackoc70001a2012-11-28 04:34:26 +00001153 if (likely((adapter->netdev->features & NETIF_F_RXCSUM) &&
Sony Chackod17dd0d2012-11-28 04:34:27 +00001154 (cksum == STATUS_CKSUM_OK || cksum == STATUS_CKSUM_LOOP))) {
Sony Chackoc70001a2012-11-28 04:34:26 +00001155 adapter->stats.csummed++;
1156 skb->ip_summed = CHECKSUM_UNNECESSARY;
1157 } else {
1158 skb_checksum_none_assert(skb);
1159 }
1160
Sony Chacko4be41e92013-01-01 03:20:20 +00001161
Sony Chackoc70001a2012-11-28 04:34:26 +00001162 buffer->skb = NULL;
1163
1164 return skb;
1165}
1166
Sony Chackod17dd0d2012-11-28 04:34:27 +00001167static inline int qlcnic_check_rx_tagging(struct qlcnic_adapter *adapter,
1168 struct sk_buff *skb, u16 *vlan_tag)
Sony Chackoc70001a2012-11-28 04:34:26 +00001169{
1170 struct ethhdr *eth_hdr;
1171
1172 if (!__vlan_get_tag(skb, vlan_tag)) {
Sony Chackod17dd0d2012-11-28 04:34:27 +00001173 eth_hdr = (struct ethhdr *)skb->data;
Sony Chackoc70001a2012-11-28 04:34:26 +00001174 memmove(skb->data + VLAN_HLEN, eth_hdr, ETH_ALEN * 2);
1175 skb_pull(skb, VLAN_HLEN);
1176 }
Rajesh Borundia91b72822013-04-19 07:01:12 +00001177 if (!adapter->rx_pvid)
Sony Chackoc70001a2012-11-28 04:34:26 +00001178 return 0;
1179
Rajesh Borundia91b72822013-04-19 07:01:12 +00001180 if (*vlan_tag == adapter->rx_pvid) {
Sony Chackoc70001a2012-11-28 04:34:26 +00001181 /* Outer vlan tag. Packet should follow non-vlan path */
1182 *vlan_tag = 0xffff;
1183 return 0;
1184 }
1185 if (adapter->flags & QLCNIC_TAGGING_ENABLED)
1186 return 0;
1187
1188 return -EINVAL;
1189}
1190
1191static struct qlcnic_rx_buffer *
1192qlcnic_process_rcv(struct qlcnic_adapter *adapter,
Sony Chackod17dd0d2012-11-28 04:34:27 +00001193 struct qlcnic_host_sds_ring *sds_ring, int ring,
1194 u64 sts_data0)
Sony Chackoc70001a2012-11-28 04:34:26 +00001195{
1196 struct net_device *netdev = adapter->netdev;
1197 struct qlcnic_recv_context *recv_ctx = adapter->recv_ctx;
1198 struct qlcnic_rx_buffer *buffer;
1199 struct sk_buff *skb;
1200 struct qlcnic_host_rds_ring *rds_ring;
Shahed Shaikh53643a72013-02-18 13:22:37 +00001201 int index, length, cksum, pkt_offset, is_lb_pkt;
1202 u16 vid = 0xffff, t_vid;
Sony Chackoc70001a2012-11-28 04:34:26 +00001203
1204 if (unlikely(ring >= adapter->max_rds_rings))
1205 return NULL;
1206
1207 rds_ring = &recv_ctx->rds_rings[ring];
1208
1209 index = qlcnic_get_sts_refhandle(sts_data0);
1210 if (unlikely(index >= rds_ring->num_desc))
1211 return NULL;
1212
1213 buffer = &rds_ring->rx_buf_arr[index];
Sony Chackoc70001a2012-11-28 04:34:26 +00001214 length = qlcnic_get_sts_totallength(sts_data0);
1215 cksum = qlcnic_get_sts_status(sts_data0);
1216 pkt_offset = qlcnic_get_sts_pkt_offset(sts_data0);
1217
1218 skb = qlcnic_process_rxbuf(adapter, rds_ring, index, cksum);
1219 if (!skb)
1220 return buffer;
1221
Shahed Shaikhddfbac02014-04-25 17:43:56 -04001222 if (adapter->rx_mac_learn) {
Shahed Shaikh53643a72013-02-18 13:22:37 +00001223 t_vid = 0;
1224 is_lb_pkt = qlcnic_82xx_is_lb_pkt(sts_data0);
Rajesh Borundiaf80bc8f2013-04-19 07:01:08 +00001225 qlcnic_add_lb_filter(adapter, skb, is_lb_pkt, t_vid);
Shahed Shaikh53643a72013-02-18 13:22:37 +00001226 }
1227
Sony Chackoc70001a2012-11-28 04:34:26 +00001228 if (length > rds_ring->skb_size)
1229 skb_put(skb, rds_ring->skb_size);
1230 else
1231 skb_put(skb, length);
1232
1233 if (pkt_offset)
1234 skb_pull(skb, pkt_offset);
1235
1236 if (unlikely(qlcnic_check_rx_tagging(adapter, skb, &vid))) {
1237 adapter->stats.rxdropped++;
1238 dev_kfree_skb(skb);
1239 return buffer;
1240 }
1241
1242 skb->protocol = eth_type_trans(skb, netdev);
1243
1244 if (vid != 0xffff)
Patrick McHardy86a9bad2013-04-19 02:04:30 +00001245 __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q), vid);
Sony Chackoc70001a2012-11-28 04:34:26 +00001246
1247 napi_gro_receive(&sds_ring->napi, skb);
1248
1249 adapter->stats.rx_pkts++;
1250 adapter->stats.rxbytes += length;
1251
1252 return buffer;
1253}
1254
1255#define QLC_TCP_HDR_SIZE 20
1256#define QLC_TCP_TS_OPTION_SIZE 12
1257#define QLC_TCP_TS_HDR_SIZE (QLC_TCP_HDR_SIZE + QLC_TCP_TS_OPTION_SIZE)
1258
1259static struct qlcnic_rx_buffer *
1260qlcnic_process_lro(struct qlcnic_adapter *adapter,
Sony Chackod17dd0d2012-11-28 04:34:27 +00001261 int ring, u64 sts_data0, u64 sts_data1)
Sony Chackoc70001a2012-11-28 04:34:26 +00001262{
1263 struct net_device *netdev = adapter->netdev;
1264 struct qlcnic_recv_context *recv_ctx = adapter->recv_ctx;
1265 struct qlcnic_rx_buffer *buffer;
1266 struct sk_buff *skb;
1267 struct qlcnic_host_rds_ring *rds_ring;
1268 struct iphdr *iph;
Shahed Shaikh776e7bd2013-01-25 10:20:35 +00001269 struct ipv6hdr *ipv6h;
Sony Chackoc70001a2012-11-28 04:34:26 +00001270 struct tcphdr *th;
1271 bool push, timestamp;
Shahed Shaikh53643a72013-02-18 13:22:37 +00001272 int index, l2_hdr_offset, l4_hdr_offset, is_lb_pkt;
1273 u16 lro_length, length, data_offset, t_vid, vid = 0xffff;
Sony Chackoc70001a2012-11-28 04:34:26 +00001274 u32 seq_number;
Sony Chackoc70001a2012-11-28 04:34:26 +00001275
Manish Chopra462bed42014-01-28 11:55:27 -05001276 if (unlikely(ring >= adapter->max_rds_rings))
Sony Chackoc70001a2012-11-28 04:34:26 +00001277 return NULL;
1278
1279 rds_ring = &recv_ctx->rds_rings[ring];
1280
1281 index = qlcnic_get_lro_sts_refhandle(sts_data0);
Manish Chopra462bed42014-01-28 11:55:27 -05001282 if (unlikely(index >= rds_ring->num_desc))
Sony Chackoc70001a2012-11-28 04:34:26 +00001283 return NULL;
1284
1285 buffer = &rds_ring->rx_buf_arr[index];
1286
1287 timestamp = qlcnic_get_lro_sts_timestamp(sts_data0);
1288 lro_length = qlcnic_get_lro_sts_length(sts_data0);
1289 l2_hdr_offset = qlcnic_get_lro_sts_l2_hdr_offset(sts_data0);
1290 l4_hdr_offset = qlcnic_get_lro_sts_l4_hdr_offset(sts_data0);
1291 push = qlcnic_get_lro_sts_push_flag(sts_data0);
1292 seq_number = qlcnic_get_lro_sts_seq_number(sts_data1);
1293
1294 skb = qlcnic_process_rxbuf(adapter, rds_ring, index, STATUS_CKSUM_OK);
1295 if (!skb)
1296 return buffer;
1297
Shahed Shaikhddfbac02014-04-25 17:43:56 -04001298 if (adapter->rx_mac_learn) {
Shahed Shaikh53643a72013-02-18 13:22:37 +00001299 t_vid = 0;
1300 is_lb_pkt = qlcnic_82xx_is_lb_pkt(sts_data0);
Rajesh Borundiaf80bc8f2013-04-19 07:01:08 +00001301 qlcnic_add_lb_filter(adapter, skb, is_lb_pkt, t_vid);
Shahed Shaikh53643a72013-02-18 13:22:37 +00001302 }
1303
Sony Chackoc70001a2012-11-28 04:34:26 +00001304 if (timestamp)
1305 data_offset = l4_hdr_offset + QLC_TCP_TS_HDR_SIZE;
1306 else
1307 data_offset = l4_hdr_offset + QLC_TCP_HDR_SIZE;
1308
1309 skb_put(skb, lro_length + data_offset);
Sony Chackoc70001a2012-11-28 04:34:26 +00001310 skb_pull(skb, l2_hdr_offset);
1311
1312 if (unlikely(qlcnic_check_rx_tagging(adapter, skb, &vid))) {
1313 adapter->stats.rxdropped++;
1314 dev_kfree_skb(skb);
1315 return buffer;
1316 }
1317
1318 skb->protocol = eth_type_trans(skb, netdev);
Shahed Shaikh776e7bd2013-01-25 10:20:35 +00001319
Shahed Shaikh069048f2013-01-30 12:47:12 +00001320 if (ntohs(skb->protocol) == ETH_P_IPV6) {
Shahed Shaikh776e7bd2013-01-25 10:20:35 +00001321 ipv6h = (struct ipv6hdr *)skb->data;
1322 th = (struct tcphdr *)(skb->data + sizeof(struct ipv6hdr));
1323 length = (th->doff << 2) + lro_length;
1324 ipv6h->payload_len = htons(length);
1325 } else {
1326 iph = (struct iphdr *)skb->data;
1327 th = (struct tcphdr *)(skb->data + (iph->ihl << 2));
1328 length = (iph->ihl << 2) + (th->doff << 2) + lro_length;
Li RongQing1bcac3b2013-03-14 22:50:07 +00001329 csum_replace2(&iph->check, iph->tot_len, htons(length));
Shahed Shaikh776e7bd2013-01-25 10:20:35 +00001330 iph->tot_len = htons(length);
Shahed Shaikh776e7bd2013-01-25 10:20:35 +00001331 }
1332
Sony Chackoc70001a2012-11-28 04:34:26 +00001333 th->psh = push;
1334 th->seq = htonl(seq_number);
Sony Chackoc70001a2012-11-28 04:34:26 +00001335 length = skb->len;
1336
Michael S. Tsirkinbd69ba72013-02-07 03:13:13 +00001337 if (adapter->flags & QLCNIC_FW_LRO_MSS_CAP) {
Sony Chackoc70001a2012-11-28 04:34:26 +00001338 skb_shinfo(skb)->gso_size = qlcnic_get_lro_sts_mss(sts_data1);
Michael S. Tsirkinbd69ba72013-02-07 03:13:13 +00001339 if (skb->protocol == htons(ETH_P_IPV6))
1340 skb_shinfo(skb)->gso_type = SKB_GSO_TCPV6;
1341 else
1342 skb_shinfo(skb)->gso_type = SKB_GSO_TCPV4;
1343 }
Sony Chackoc70001a2012-11-28 04:34:26 +00001344
1345 if (vid != 0xffff)
Patrick McHardy86a9bad2013-04-19 02:04:30 +00001346 __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q), vid);
Sony Chackoc70001a2012-11-28 04:34:26 +00001347 netif_receive_skb(skb);
1348
1349 adapter->stats.lro_pkts++;
1350 adapter->stats.lrobytes += length;
1351
1352 return buffer;
1353}
1354
stephen hemminger21041402014-01-16 10:31:27 -08001355static int qlcnic_process_rcv_ring(struct qlcnic_host_sds_ring *sds_ring, int max)
Sony Chackoc70001a2012-11-28 04:34:26 +00001356{
Sony Chackod17dd0d2012-11-28 04:34:27 +00001357 struct qlcnic_host_rds_ring *rds_ring;
Sony Chackoc70001a2012-11-28 04:34:26 +00001358 struct qlcnic_adapter *adapter = sds_ring->adapter;
1359 struct list_head *cur;
1360 struct status_desc *desc;
1361 struct qlcnic_rx_buffer *rxbuf;
Sony Chacko4be41e92013-01-01 03:20:20 +00001362 int opcode, desc_cnt, count = 0;
Sony Chackoc70001a2012-11-28 04:34:26 +00001363 u64 sts_data0, sts_data1;
Sony Chacko4be41e92013-01-01 03:20:20 +00001364 u8 ring;
Sony Chackoc70001a2012-11-28 04:34:26 +00001365 u32 consumer = sds_ring->consumer;
1366
1367 while (count < max) {
1368 desc = &sds_ring->desc_head[consumer];
1369 sts_data0 = le64_to_cpu(desc->status_desc_data[0]);
1370
1371 if (!(sts_data0 & STATUS_OWNER_HOST))
1372 break;
1373
1374 desc_cnt = qlcnic_get_sts_desc_cnt(sts_data0);
1375 opcode = qlcnic_get_sts_opcode(sts_data0);
Sony Chackoc70001a2012-11-28 04:34:26 +00001376 switch (opcode) {
1377 case QLCNIC_RXPKT_DESC:
1378 case QLCNIC_OLD_RXPKT_DESC:
1379 case QLCNIC_SYN_OFFLOAD:
1380 ring = qlcnic_get_sts_type(sts_data0);
Sony Chackod17dd0d2012-11-28 04:34:27 +00001381 rxbuf = qlcnic_process_rcv(adapter, sds_ring, ring,
1382 sts_data0);
Sony Chackoc70001a2012-11-28 04:34:26 +00001383 break;
1384 case QLCNIC_LRO_DESC:
1385 ring = qlcnic_get_lro_sts_type(sts_data0);
1386 sts_data1 = le64_to_cpu(desc->status_desc_data[1]);
1387 rxbuf = qlcnic_process_lro(adapter, ring, sts_data0,
1388 sts_data1);
1389 break;
1390 case QLCNIC_RESPONSE_DESC:
1391 qlcnic_handle_fw_message(desc_cnt, consumer, sds_ring);
1392 default:
1393 goto skip;
1394 }
Sony Chackoc70001a2012-11-28 04:34:26 +00001395 WARN_ON(desc_cnt > 1);
1396
1397 if (likely(rxbuf))
1398 list_add_tail(&rxbuf->list, &sds_ring->free_list[ring]);
1399 else
1400 adapter->stats.null_rxbuf++;
Sony Chackoc70001a2012-11-28 04:34:26 +00001401skip:
1402 for (; desc_cnt > 0; desc_cnt--) {
1403 desc = &sds_ring->desc_head[consumer];
Sony Chacko4be41e92013-01-01 03:20:20 +00001404 desc->status_desc_data[0] = QLCNIC_DESC_OWNER_FW;
Sony Chackoc70001a2012-11-28 04:34:26 +00001405 consumer = get_next_index(consumer, sds_ring->num_desc);
1406 }
1407 count++;
1408 }
1409
1410 for (ring = 0; ring < adapter->max_rds_rings; ring++) {
Sony Chackod17dd0d2012-11-28 04:34:27 +00001411 rds_ring = &adapter->recv_ctx->rds_rings[ring];
Sony Chackoc70001a2012-11-28 04:34:26 +00001412 if (!list_empty(&sds_ring->free_list[ring])) {
1413 list_for_each(cur, &sds_ring->free_list[ring]) {
Sony Chackod17dd0d2012-11-28 04:34:27 +00001414 rxbuf = list_entry(cur, struct qlcnic_rx_buffer,
1415 list);
Sony Chackoc70001a2012-11-28 04:34:26 +00001416 qlcnic_alloc_rx_skb(adapter, rds_ring, rxbuf);
1417 }
1418 spin_lock(&rds_ring->lock);
1419 list_splice_tail_init(&sds_ring->free_list[ring],
Sony Chackod17dd0d2012-11-28 04:34:27 +00001420 &rds_ring->free_list);
Sony Chackoc70001a2012-11-28 04:34:26 +00001421 spin_unlock(&rds_ring->lock);
1422 }
1423
Sony Chacko4be41e92013-01-01 03:20:20 +00001424 qlcnic_post_rx_buffers_nodb(adapter, rds_ring, ring);
Sony Chackoc70001a2012-11-28 04:34:26 +00001425 }
1426
1427 if (count) {
1428 sds_ring->consumer = consumer;
1429 writel(consumer, sds_ring->crb_sts_consumer);
1430 }
1431
1432 return count;
1433}
1434
Sony Chackod17dd0d2012-11-28 04:34:27 +00001435void qlcnic_post_rx_buffers(struct qlcnic_adapter *adapter,
Sony Chacko4be41e92013-01-01 03:20:20 +00001436 struct qlcnic_host_rds_ring *rds_ring, u8 ring_id)
Sony Chackoc70001a2012-11-28 04:34:26 +00001437{
1438 struct rcv_desc *pdesc;
1439 struct qlcnic_rx_buffer *buffer;
1440 int count = 0;
Sony Chacko4be41e92013-01-01 03:20:20 +00001441 u32 producer, handle;
Sony Chackoc70001a2012-11-28 04:34:26 +00001442 struct list_head *head;
1443
1444 producer = rds_ring->producer;
Sony Chackoc70001a2012-11-28 04:34:26 +00001445 head = &rds_ring->free_list;
Sony Chackod17dd0d2012-11-28 04:34:27 +00001446
Sony Chackoc70001a2012-11-28 04:34:26 +00001447 while (!list_empty(head)) {
1448
1449 buffer = list_entry(head->next, struct qlcnic_rx_buffer, list);
1450
1451 if (!buffer->skb) {
1452 if (qlcnic_alloc_rx_skb(adapter, rds_ring, buffer))
1453 break;
1454 }
1455
1456 count++;
1457 list_del(&buffer->list);
1458
1459 /* make a rcv descriptor */
1460 pdesc = &rds_ring->desc_head[producer];
1461 pdesc->addr_buffer = cpu_to_le64(buffer->dma);
Sony Chacko4be41e92013-01-01 03:20:20 +00001462 handle = qlcnic_get_ref_handle(adapter, buffer->ref_handle,
1463 ring_id);
1464 pdesc->reference_handle = cpu_to_le16(handle);
Sony Chackoc70001a2012-11-28 04:34:26 +00001465 pdesc->buffer_length = cpu_to_le32(rds_ring->dma_size);
Sony Chackoc70001a2012-11-28 04:34:26 +00001466 producer = get_next_index(producer, rds_ring->num_desc);
1467 }
1468
1469 if (count) {
1470 rds_ring->producer = producer;
1471 writel((producer-1) & (rds_ring->num_desc-1),
Sony Chackod17dd0d2012-11-28 04:34:27 +00001472 rds_ring->crb_rcv_producer);
Sony Chackoc70001a2012-11-28 04:34:26 +00001473 }
1474}
1475
1476static void dump_skb(struct sk_buff *skb, struct qlcnic_adapter *adapter)
1477{
Joe Perches3620af02015-01-03 17:50:16 -08001478 if (adapter->ahw->msg_enable & NETIF_MSG_DRV) {
1479 char prefix[30];
Sony Chackoc70001a2012-11-28 04:34:26 +00001480
Joe Perches3620af02015-01-03 17:50:16 -08001481 scnprintf(prefix, sizeof(prefix), "%s: %s: ",
1482 dev_name(&adapter->pdev->dev), __func__);
1483
1484 print_hex_dump_debug(prefix, DUMP_PREFIX_NONE, 16, 1,
1485 skb->data, skb->len, true);
Sony Chackoc70001a2012-11-28 04:34:26 +00001486 }
1487}
1488
1489static void qlcnic_process_rcv_diag(struct qlcnic_adapter *adapter, int ring,
1490 u64 sts_data0)
1491{
1492 struct qlcnic_recv_context *recv_ctx = adapter->recv_ctx;
1493 struct sk_buff *skb;
1494 struct qlcnic_host_rds_ring *rds_ring;
1495 int index, length, cksum, pkt_offset;
1496
1497 if (unlikely(ring >= adapter->max_rds_rings))
1498 return;
1499
1500 rds_ring = &recv_ctx->rds_rings[ring];
1501
1502 index = qlcnic_get_sts_refhandle(sts_data0);
1503 length = qlcnic_get_sts_totallength(sts_data0);
1504 if (unlikely(index >= rds_ring->num_desc))
1505 return;
1506
1507 cksum = qlcnic_get_sts_status(sts_data0);
1508 pkt_offset = qlcnic_get_sts_pkt_offset(sts_data0);
1509
1510 skb = qlcnic_process_rxbuf(adapter, rds_ring, index, cksum);
1511 if (!skb)
1512 return;
1513
1514 if (length > rds_ring->skb_size)
1515 skb_put(skb, rds_ring->skb_size);
1516 else
1517 skb_put(skb, length);
1518
1519 if (pkt_offset)
1520 skb_pull(skb, pkt_offset);
1521
1522 if (!qlcnic_check_loopback_buff(skb->data, adapter->mac_addr))
Sony Chacko79788452012-12-04 03:33:53 +00001523 adapter->ahw->diag_cnt++;
Sony Chackoc70001a2012-11-28 04:34:26 +00001524 else
1525 dump_skb(skb, adapter);
1526
1527 dev_kfree_skb_any(skb);
1528 adapter->stats.rx_pkts++;
1529 adapter->stats.rxbytes += length;
1530
1531 return;
1532}
1533
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00001534void qlcnic_82xx_process_rcv_ring_diag(struct qlcnic_host_sds_ring *sds_ring)
Sony Chackoc70001a2012-11-28 04:34:26 +00001535{
1536 struct qlcnic_adapter *adapter = sds_ring->adapter;
1537 struct status_desc *desc;
1538 u64 sts_data0;
1539 int ring, opcode, desc_cnt;
1540
1541 u32 consumer = sds_ring->consumer;
1542
1543 desc = &sds_ring->desc_head[consumer];
1544 sts_data0 = le64_to_cpu(desc->status_desc_data[0]);
1545
1546 if (!(sts_data0 & STATUS_OWNER_HOST))
1547 return;
1548
1549 desc_cnt = qlcnic_get_sts_desc_cnt(sts_data0);
1550 opcode = qlcnic_get_sts_opcode(sts_data0);
1551 switch (opcode) {
1552 case QLCNIC_RESPONSE_DESC:
1553 qlcnic_handle_fw_message(desc_cnt, consumer, sds_ring);
1554 break;
1555 default:
1556 ring = qlcnic_get_sts_type(sts_data0);
1557 qlcnic_process_rcv_diag(adapter, ring, sts_data0);
1558 break;
1559 }
1560
1561 for (; desc_cnt > 0; desc_cnt--) {
1562 desc = &sds_ring->desc_head[consumer];
1563 desc->status_desc_data[0] = cpu_to_le64(STATUS_OWNER_PHANTOM);
1564 consumer = get_next_index(consumer, sds_ring->num_desc);
1565 }
1566
1567 sds_ring->consumer = consumer;
1568 writel(consumer, sds_ring->crb_sts_consumer);
1569}
1570
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00001571int qlcnic_82xx_napi_add(struct qlcnic_adapter *adapter,
1572 struct net_device *netdev)
Sony Chackoc70001a2012-11-28 04:34:26 +00001573{
Michal Schmidtdf95fc42013-09-04 15:03:05 +02001574 int ring;
Sony Chackoc70001a2012-11-28 04:34:26 +00001575 struct qlcnic_host_sds_ring *sds_ring;
1576 struct qlcnic_recv_context *recv_ctx = adapter->recv_ctx;
Himanshu Madhani012ec812013-08-21 11:24:10 -04001577 struct qlcnic_host_tx_ring *tx_ring;
Sony Chackoc70001a2012-11-28 04:34:26 +00001578
Himanshu Madhani34e8c402013-11-04 13:31:31 -05001579 if (qlcnic_alloc_sds_rings(recv_ctx, adapter->drv_sds_rings))
Sony Chackoc70001a2012-11-28 04:34:26 +00001580 return -ENOMEM;
1581
Himanshu Madhani34e8c402013-11-04 13:31:31 -05001582 for (ring = 0; ring < adapter->drv_sds_rings; ring++) {
Sony Chackoc70001a2012-11-28 04:34:26 +00001583 sds_ring = &recv_ctx->sds_rings[ring];
Himanshu Madhani012ec812013-08-21 11:24:10 -04001584 if (qlcnic_check_multi_tx(adapter) &&
Himanshu Madhani80c0e4f2013-12-17 09:01:52 -05001585 !adapter->ahw->diag_test) {
Sony Chackod17dd0d2012-11-28 04:34:27 +00001586 netif_napi_add(netdev, &sds_ring->napi, qlcnic_rx_poll,
Michal Schmidtdf95fc42013-09-04 15:03:05 +02001587 NAPI_POLL_WEIGHT);
Himanshu Madhani012ec812013-08-21 11:24:10 -04001588 } else {
Himanshu Madhani34e8c402013-11-04 13:31:31 -05001589 if (ring == (adapter->drv_sds_rings - 1))
Himanshu Madhani012ec812013-08-21 11:24:10 -04001590 netif_napi_add(netdev, &sds_ring->napi,
1591 qlcnic_poll,
Michal Schmidtdf95fc42013-09-04 15:03:05 +02001592 NAPI_POLL_WEIGHT);
Himanshu Madhani012ec812013-08-21 11:24:10 -04001593 else
1594 netif_napi_add(netdev, &sds_ring->napi,
1595 qlcnic_rx_poll,
Michal Schmidtdf95fc42013-09-04 15:03:05 +02001596 NAPI_POLL_WEIGHT);
Himanshu Madhani012ec812013-08-21 11:24:10 -04001597 }
Sony Chackoc70001a2012-11-28 04:34:26 +00001598 }
1599
Sony Chacko4be41e92013-01-01 03:20:20 +00001600 if (qlcnic_alloc_tx_rings(adapter, netdev)) {
1601 qlcnic_free_sds_rings(recv_ctx);
1602 return -ENOMEM;
1603 }
1604
Himanshu Madhanic2c5e3a2013-08-21 11:24:12 -04001605 if (qlcnic_check_multi_tx(adapter) && !adapter->ahw->diag_test) {
Himanshu Madhani34e8c402013-11-04 13:31:31 -05001606 for (ring = 0; ring < adapter->drv_tx_rings; ring++) {
Himanshu Madhani012ec812013-08-21 11:24:10 -04001607 tx_ring = &adapter->tx_ring[ring];
Eric Dumazetd64b5e82015-11-18 06:31:00 -08001608 netif_tx_napi_add(netdev, &tx_ring->napi, qlcnic_tx_poll,
Michal Schmidtdf95fc42013-09-04 15:03:05 +02001609 NAPI_POLL_WEIGHT);
Himanshu Madhani012ec812013-08-21 11:24:10 -04001610 }
1611 }
1612
Sony Chackoc70001a2012-11-28 04:34:26 +00001613 return 0;
1614}
1615
Sony Chacko4be41e92013-01-01 03:20:20 +00001616void qlcnic_82xx_napi_del(struct qlcnic_adapter *adapter)
Sony Chackoc70001a2012-11-28 04:34:26 +00001617{
1618 int ring;
1619 struct qlcnic_host_sds_ring *sds_ring;
1620 struct qlcnic_recv_context *recv_ctx = adapter->recv_ctx;
Himanshu Madhani012ec812013-08-21 11:24:10 -04001621 struct qlcnic_host_tx_ring *tx_ring;
Sony Chackoc70001a2012-11-28 04:34:26 +00001622
Himanshu Madhani34e8c402013-11-04 13:31:31 -05001623 for (ring = 0; ring < adapter->drv_sds_rings; ring++) {
Sony Chackoc70001a2012-11-28 04:34:26 +00001624 sds_ring = &recv_ctx->sds_rings[ring];
1625 netif_napi_del(&sds_ring->napi);
1626 }
1627
1628 qlcnic_free_sds_rings(adapter->recv_ctx);
Himanshu Madhani012ec812013-08-21 11:24:10 -04001629
Himanshu Madhanic2c5e3a2013-08-21 11:24:12 -04001630 if (qlcnic_check_multi_tx(adapter) && !adapter->ahw->diag_test) {
Himanshu Madhani34e8c402013-11-04 13:31:31 -05001631 for (ring = 0; ring < adapter->drv_tx_rings; ring++) {
Himanshu Madhani012ec812013-08-21 11:24:10 -04001632 tx_ring = &adapter->tx_ring[ring];
1633 netif_napi_del(&tx_ring->napi);
1634 }
1635 }
1636
Sony Chacko4be41e92013-01-01 03:20:20 +00001637 qlcnic_free_tx_rings(adapter);
Sony Chackoc70001a2012-11-28 04:34:26 +00001638}
1639
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00001640void qlcnic_82xx_napi_enable(struct qlcnic_adapter *adapter)
Sony Chackoc70001a2012-11-28 04:34:26 +00001641{
1642 int ring;
1643 struct qlcnic_host_sds_ring *sds_ring;
Himanshu Madhani012ec812013-08-21 11:24:10 -04001644 struct qlcnic_host_tx_ring *tx_ring;
Sony Chackoc70001a2012-11-28 04:34:26 +00001645 struct qlcnic_recv_context *recv_ctx = adapter->recv_ctx;
1646
1647 if (adapter->is_up != QLCNIC_ADAPTER_UP_MAGIC)
1648 return;
1649
Himanshu Madhani34e8c402013-11-04 13:31:31 -05001650 for (ring = 0; ring < adapter->drv_sds_rings; ring++) {
Sony Chackoc70001a2012-11-28 04:34:26 +00001651 sds_ring = &recv_ctx->sds_rings[ring];
1652 napi_enable(&sds_ring->napi);
Manish chopra2cc57522014-01-23 17:18:30 -05001653 qlcnic_enable_sds_intr(adapter, sds_ring);
Sony Chackoc70001a2012-11-28 04:34:26 +00001654 }
Himanshu Madhani012ec812013-08-21 11:24:10 -04001655
1656 if (qlcnic_check_multi_tx(adapter) &&
1657 (adapter->flags & QLCNIC_MSIX_ENABLED) &&
Himanshu Madhani80c0e4f2013-12-17 09:01:52 -05001658 !adapter->ahw->diag_test) {
Himanshu Madhani34e8c402013-11-04 13:31:31 -05001659 for (ring = 0; ring < adapter->drv_tx_rings; ring++) {
Himanshu Madhani012ec812013-08-21 11:24:10 -04001660 tx_ring = &adapter->tx_ring[ring];
1661 napi_enable(&tx_ring->napi);
1662 qlcnic_enable_tx_intr(adapter, tx_ring);
1663 }
1664 }
Sony Chackoc70001a2012-11-28 04:34:26 +00001665}
1666
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00001667void qlcnic_82xx_napi_disable(struct qlcnic_adapter *adapter)
Sony Chackoc70001a2012-11-28 04:34:26 +00001668{
1669 int ring;
1670 struct qlcnic_host_sds_ring *sds_ring;
Himanshu Madhani012ec812013-08-21 11:24:10 -04001671 struct qlcnic_host_tx_ring *tx_ring;
Sony Chackoc70001a2012-11-28 04:34:26 +00001672 struct qlcnic_recv_context *recv_ctx = adapter->recv_ctx;
1673
1674 if (adapter->is_up != QLCNIC_ADAPTER_UP_MAGIC)
1675 return;
1676
Himanshu Madhani34e8c402013-11-04 13:31:31 -05001677 for (ring = 0; ring < adapter->drv_sds_rings; ring++) {
Sony Chackoc70001a2012-11-28 04:34:26 +00001678 sds_ring = &recv_ctx->sds_rings[ring];
Manish chopra2cc57522014-01-23 17:18:30 -05001679 qlcnic_disable_sds_intr(adapter, sds_ring);
Sony Chackoc70001a2012-11-28 04:34:26 +00001680 napi_synchronize(&sds_ring->napi);
1681 napi_disable(&sds_ring->napi);
1682 }
Himanshu Madhani012ec812013-08-21 11:24:10 -04001683
1684 if ((adapter->flags & QLCNIC_MSIX_ENABLED) &&
Himanshu Madhanic2c5e3a2013-08-21 11:24:12 -04001685 !adapter->ahw->diag_test &&
Himanshu Madhani012ec812013-08-21 11:24:10 -04001686 qlcnic_check_multi_tx(adapter)) {
Himanshu Madhani34e8c402013-11-04 13:31:31 -05001687 for (ring = 0; ring < adapter->drv_tx_rings; ring++) {
Himanshu Madhani012ec812013-08-21 11:24:10 -04001688 tx_ring = &adapter->tx_ring[ring];
Manish chopra2cc57522014-01-23 17:18:30 -05001689 qlcnic_disable_tx_intr(adapter, tx_ring);
Himanshu Madhani012ec812013-08-21 11:24:10 -04001690 napi_synchronize(&tx_ring->napi);
1691 napi_disable(&tx_ring->napi);
1692 }
1693 }
Sony Chackoc70001a2012-11-28 04:34:26 +00001694}
Sony Chacko4be41e92013-01-01 03:20:20 +00001695
Shahed Shaikh53643a72013-02-18 13:22:37 +00001696#define QLC_83XX_NORMAL_LB_PKT (1ULL << 36)
1697#define QLC_83XX_LRO_LB_PKT (1ULL << 46)
1698
1699static inline int qlcnic_83xx_is_lb_pkt(u64 sts_data, int lro_pkt)
1700{
1701 if (lro_pkt)
1702 return (sts_data & QLC_83XX_LRO_LB_PKT) ? 1 : 0;
1703 else
1704 return (sts_data & QLC_83XX_NORMAL_LB_PKT) ? 1 : 0;
1705}
1706
Shahed Shaikh2b3d7b72014-03-21 04:41:17 -04001707#define QLCNIC_ENCAP_LENGTH_MASK 0x7f
1708
1709static inline u8 qlcnic_encap_length(u64 sts_data)
1710{
1711 return sts_data & QLCNIC_ENCAP_LENGTH_MASK;
1712}
1713
Sony Chacko4be41e92013-01-01 03:20:20 +00001714static struct qlcnic_rx_buffer *
1715qlcnic_83xx_process_rcv(struct qlcnic_adapter *adapter,
1716 struct qlcnic_host_sds_ring *sds_ring,
1717 u8 ring, u64 sts_data[])
1718{
1719 struct net_device *netdev = adapter->netdev;
1720 struct qlcnic_recv_context *recv_ctx = adapter->recv_ctx;
1721 struct qlcnic_rx_buffer *buffer;
1722 struct sk_buff *skb;
1723 struct qlcnic_host_rds_ring *rds_ring;
Shahed Shaikh53643a72013-02-18 13:22:37 +00001724 int index, length, cksum, is_lb_pkt;
Sucheta Chakrabortyb3f7de82014-01-10 11:48:55 -05001725 u16 vid = 0xffff;
1726 int err;
Sony Chacko4be41e92013-01-01 03:20:20 +00001727
1728 if (unlikely(ring >= adapter->max_rds_rings))
1729 return NULL;
1730
1731 rds_ring = &recv_ctx->rds_rings[ring];
1732
1733 index = qlcnic_83xx_hndl(sts_data[0]);
1734 if (unlikely(index >= rds_ring->num_desc))
1735 return NULL;
1736
1737 buffer = &rds_ring->rx_buf_arr[index];
1738 length = qlcnic_83xx_pktln(sts_data[0]);
1739 cksum = qlcnic_83xx_csum_status(sts_data[1]);
1740 skb = qlcnic_process_rxbuf(adapter, rds_ring, index, cksum);
1741 if (!skb)
1742 return buffer;
1743
1744 if (length > rds_ring->skb_size)
1745 skb_put(skb, rds_ring->skb_size);
1746 else
1747 skb_put(skb, length);
1748
Sucheta Chakrabortyb3f7de82014-01-10 11:48:55 -05001749 err = qlcnic_check_rx_tagging(adapter, skb, &vid);
1750
1751 if (adapter->rx_mac_learn) {
1752 is_lb_pkt = qlcnic_83xx_is_lb_pkt(sts_data[1], 0);
1753 qlcnic_add_lb_filter(adapter, skb, is_lb_pkt, vid);
1754 }
1755
1756 if (unlikely(err)) {
Sony Chacko4be41e92013-01-01 03:20:20 +00001757 adapter->stats.rxdropped++;
1758 dev_kfree_skb(skb);
1759 return buffer;
1760 }
1761
1762 skb->protocol = eth_type_trans(skb, netdev);
1763
Shahed Shaikh2b3d7b72014-03-21 04:41:17 -04001764 if (qlcnic_encap_length(sts_data[1]) &&
1765 skb->ip_summed == CHECKSUM_UNNECESSARY) {
Tom Herbert71d7a272014-08-27 21:28:01 -07001766 skb->csum_level = 1;
Shahed Shaikh2b3d7b72014-03-21 04:41:17 -04001767 adapter->stats.encap_rx_csummed++;
1768 }
1769
Sony Chacko4be41e92013-01-01 03:20:20 +00001770 if (vid != 0xffff)
Patrick McHardy86a9bad2013-04-19 02:04:30 +00001771 __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q), vid);
Sony Chacko4be41e92013-01-01 03:20:20 +00001772
1773 napi_gro_receive(&sds_ring->napi, skb);
1774
1775 adapter->stats.rx_pkts++;
1776 adapter->stats.rxbytes += length;
1777
1778 return buffer;
1779}
1780
1781static struct qlcnic_rx_buffer *
1782qlcnic_83xx_process_lro(struct qlcnic_adapter *adapter,
1783 u8 ring, u64 sts_data[])
1784{
1785 struct net_device *netdev = adapter->netdev;
1786 struct qlcnic_recv_context *recv_ctx = adapter->recv_ctx;
1787 struct qlcnic_rx_buffer *buffer;
1788 struct sk_buff *skb;
1789 struct qlcnic_host_rds_ring *rds_ring;
1790 struct iphdr *iph;
1791 struct ipv6hdr *ipv6h;
1792 struct tcphdr *th;
1793 bool push;
1794 int l2_hdr_offset, l4_hdr_offset;
Shahed Shaikh53643a72013-02-18 13:22:37 +00001795 int index, is_lb_pkt;
Shahed Shaikh99e85872013-02-18 12:06:16 +00001796 u16 lro_length, length, data_offset, gso_size;
Sucheta Chakrabortyb3f7de82014-01-10 11:48:55 -05001797 u16 vid = 0xffff;
1798 int err;
Sony Chacko4be41e92013-01-01 03:20:20 +00001799
Manish Chopra462bed42014-01-28 11:55:27 -05001800 if (unlikely(ring >= adapter->max_rds_rings))
Sony Chacko4be41e92013-01-01 03:20:20 +00001801 return NULL;
1802
1803 rds_ring = &recv_ctx->rds_rings[ring];
1804
1805 index = qlcnic_83xx_hndl(sts_data[0]);
Manish Chopra462bed42014-01-28 11:55:27 -05001806 if (unlikely(index >= rds_ring->num_desc))
Sony Chacko4be41e92013-01-01 03:20:20 +00001807 return NULL;
1808
1809 buffer = &rds_ring->rx_buf_arr[index];
1810
1811 lro_length = qlcnic_83xx_lro_pktln(sts_data[0]);
1812 l2_hdr_offset = qlcnic_83xx_l2_hdr_off(sts_data[1]);
1813 l4_hdr_offset = qlcnic_83xx_l4_hdr_off(sts_data[1]);
1814 push = qlcnic_83xx_is_psh_bit(sts_data[1]);
1815
1816 skb = qlcnic_process_rxbuf(adapter, rds_ring, index, STATUS_CKSUM_OK);
1817 if (!skb)
1818 return buffer;
Shahed Shaikh53643a72013-02-18 13:22:37 +00001819
Sony Chacko4be41e92013-01-01 03:20:20 +00001820 if (qlcnic_83xx_is_tstamp(sts_data[1]))
1821 data_offset = l4_hdr_offset + QLCNIC_TCP_TS_HDR_SIZE;
1822 else
1823 data_offset = l4_hdr_offset + QLCNIC_TCP_HDR_SIZE;
1824
1825 skb_put(skb, lro_length + data_offset);
1826 skb_pull(skb, l2_hdr_offset);
1827
Sucheta Chakrabortyb3f7de82014-01-10 11:48:55 -05001828 err = qlcnic_check_rx_tagging(adapter, skb, &vid);
1829
1830 if (adapter->rx_mac_learn) {
1831 is_lb_pkt = qlcnic_83xx_is_lb_pkt(sts_data[1], 1);
1832 qlcnic_add_lb_filter(adapter, skb, is_lb_pkt, vid);
1833 }
1834
1835 if (unlikely(err)) {
Sony Chacko4be41e92013-01-01 03:20:20 +00001836 adapter->stats.rxdropped++;
1837 dev_kfree_skb(skb);
1838 return buffer;
1839 }
1840
1841 skb->protocol = eth_type_trans(skb, netdev);
1842 if (ntohs(skb->protocol) == ETH_P_IPV6) {
1843 ipv6h = (struct ipv6hdr *)skb->data;
1844 th = (struct tcphdr *)(skb->data + sizeof(struct ipv6hdr));
1845
1846 length = (th->doff << 2) + lro_length;
1847 ipv6h->payload_len = htons(length);
1848 } else {
1849 iph = (struct iphdr *)skb->data;
1850 th = (struct tcphdr *)(skb->data + (iph->ihl << 2));
1851 length = (iph->ihl << 2) + (th->doff << 2) + lro_length;
Li RongQing1bcac3b2013-03-14 22:50:07 +00001852 csum_replace2(&iph->check, iph->tot_len, htons(length));
Sony Chacko4be41e92013-01-01 03:20:20 +00001853 iph->tot_len = htons(length);
Sony Chacko4be41e92013-01-01 03:20:20 +00001854 }
1855
1856 th->psh = push;
1857 length = skb->len;
1858
Shahed Shaikh99e85872013-02-18 12:06:16 +00001859 if (adapter->flags & QLCNIC_FW_LRO_MSS_CAP) {
1860 gso_size = qlcnic_83xx_get_lro_sts_mss(sts_data[0]);
1861 skb_shinfo(skb)->gso_size = gso_size;
1862 if (skb->protocol == htons(ETH_P_IPV6))
1863 skb_shinfo(skb)->gso_type = SKB_GSO_TCPV6;
1864 else
1865 skb_shinfo(skb)->gso_type = SKB_GSO_TCPV4;
1866 }
1867
Sony Chacko4be41e92013-01-01 03:20:20 +00001868 if (vid != 0xffff)
Patrick McHardy86a9bad2013-04-19 02:04:30 +00001869 __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q), vid);
Sony Chacko4be41e92013-01-01 03:20:20 +00001870
1871 netif_receive_skb(skb);
1872
1873 adapter->stats.lro_pkts++;
1874 adapter->stats.lrobytes += length;
1875 return buffer;
1876}
1877
1878static int qlcnic_83xx_process_rcv_ring(struct qlcnic_host_sds_ring *sds_ring,
1879 int max)
1880{
1881 struct qlcnic_host_rds_ring *rds_ring;
1882 struct qlcnic_adapter *adapter = sds_ring->adapter;
1883 struct list_head *cur;
1884 struct status_desc *desc;
1885 struct qlcnic_rx_buffer *rxbuf = NULL;
1886 u8 ring;
1887 u64 sts_data[2];
1888 int count = 0, opcode;
1889 u32 consumer = sds_ring->consumer;
1890
1891 while (count < max) {
1892 desc = &sds_ring->desc_head[consumer];
1893 sts_data[1] = le64_to_cpu(desc->status_desc_data[1]);
1894 opcode = qlcnic_83xx_opcode(sts_data[1]);
1895 if (!opcode)
1896 break;
1897 sts_data[0] = le64_to_cpu(desc->status_desc_data[0]);
1898 ring = QLCNIC_FETCH_RING_ID(sts_data[0]);
1899
1900 switch (opcode) {
1901 case QLC_83XX_REG_DESC:
1902 rxbuf = qlcnic_83xx_process_rcv(adapter, sds_ring,
1903 ring, sts_data);
1904 break;
1905 case QLC_83XX_LRO_DESC:
1906 rxbuf = qlcnic_83xx_process_lro(adapter, ring,
1907 sts_data);
1908 break;
1909 default:
1910 dev_info(&adapter->pdev->dev,
Masanari Iida0b1587b2013-07-17 04:37:44 +09001911 "Unknown opcode: 0x%x\n", opcode);
Sony Chacko4be41e92013-01-01 03:20:20 +00001912 goto skip;
1913 }
1914
1915 if (likely(rxbuf))
1916 list_add_tail(&rxbuf->list, &sds_ring->free_list[ring]);
1917 else
1918 adapter->stats.null_rxbuf++;
1919skip:
1920 desc = &sds_ring->desc_head[consumer];
1921 /* Reset the descriptor */
1922 desc->status_desc_data[1] = 0;
1923 consumer = get_next_index(consumer, sds_ring->num_desc);
1924 count++;
1925 }
1926 for (ring = 0; ring < adapter->max_rds_rings; ring++) {
1927 rds_ring = &adapter->recv_ctx->rds_rings[ring];
1928 if (!list_empty(&sds_ring->free_list[ring])) {
1929 list_for_each(cur, &sds_ring->free_list[ring]) {
1930 rxbuf = list_entry(cur, struct qlcnic_rx_buffer,
1931 list);
1932 qlcnic_alloc_rx_skb(adapter, rds_ring, rxbuf);
1933 }
1934 spin_lock(&rds_ring->lock);
1935 list_splice_tail_init(&sds_ring->free_list[ring],
1936 &rds_ring->free_list);
1937 spin_unlock(&rds_ring->lock);
1938 }
1939 qlcnic_post_rx_buffers_nodb(adapter, rds_ring, ring);
1940 }
1941 if (count) {
1942 sds_ring->consumer = consumer;
1943 writel(consumer, sds_ring->crb_sts_consumer);
1944 }
1945 return count;
1946}
1947
Rajesh Borundiada6c8062013-03-29 05:46:35 +00001948static int qlcnic_83xx_msix_sriov_vf_poll(struct napi_struct *napi, int budget)
1949{
1950 int tx_complete;
1951 int work_done;
1952 struct qlcnic_host_sds_ring *sds_ring;
1953 struct qlcnic_adapter *adapter;
1954 struct qlcnic_host_tx_ring *tx_ring;
1955
1956 sds_ring = container_of(napi, struct qlcnic_host_sds_ring, napi);
1957 adapter = sds_ring->adapter;
1958 /* tx ring count = 1 */
1959 tx_ring = adapter->tx_ring;
1960
1961 tx_complete = qlcnic_process_cmd_ring(adapter, tx_ring, budget);
1962 work_done = qlcnic_83xx_process_rcv_ring(sds_ring, budget);
Shahed Shaikhf31ec952015-02-04 05:41:25 -05001963
1964 /* Check if we need a repoll */
1965 if (!tx_complete)
1966 work_done = budget;
1967
1968 if (work_done < budget) {
Eric Dumazet6ad20162017-01-30 08:22:01 -08001969 napi_complete_done(&sds_ring->napi, work_done);
Manish chopra2cc57522014-01-23 17:18:30 -05001970 qlcnic_enable_sds_intr(adapter, sds_ring);
Rajesh Borundiada6c8062013-03-29 05:46:35 +00001971 }
1972
1973 return work_done;
1974}
1975
Sony Chacko4be41e92013-01-01 03:20:20 +00001976static int qlcnic_83xx_poll(struct napi_struct *napi, int budget)
1977{
1978 int tx_complete;
1979 int work_done;
1980 struct qlcnic_host_sds_ring *sds_ring;
1981 struct qlcnic_adapter *adapter;
1982 struct qlcnic_host_tx_ring *tx_ring;
1983
1984 sds_ring = container_of(napi, struct qlcnic_host_sds_ring, napi);
1985 adapter = sds_ring->adapter;
1986 /* tx ring count = 1 */
1987 tx_ring = adapter->tx_ring;
1988
Sony Chacko4be41e92013-01-01 03:20:20 +00001989 tx_complete = qlcnic_process_cmd_ring(adapter, tx_ring, budget);
1990 work_done = qlcnic_83xx_process_rcv_ring(sds_ring, budget);
Shahed Shaikhf31ec952015-02-04 05:41:25 -05001991
1992 /* Check if we need a repoll */
1993 if (!tx_complete)
1994 work_done = budget;
1995
1996 if (work_done < budget) {
Eric Dumazet6ad20162017-01-30 08:22:01 -08001997 napi_complete_done(&sds_ring->napi, work_done);
Manish chopra2cc57522014-01-23 17:18:30 -05001998 qlcnic_enable_sds_intr(adapter, sds_ring);
Sony Chacko4be41e92013-01-01 03:20:20 +00001999 }
2000
2001 return work_done;
2002}
2003
2004static int qlcnic_83xx_msix_tx_poll(struct napi_struct *napi, int budget)
2005{
2006 int work_done;
2007 struct qlcnic_host_tx_ring *tx_ring;
2008 struct qlcnic_adapter *adapter;
2009
Sony Chacko4be41e92013-01-01 03:20:20 +00002010 tx_ring = container_of(napi, struct qlcnic_host_tx_ring, napi);
2011 adapter = tx_ring->adapter;
2012 work_done = qlcnic_process_cmd_ring(adapter, tx_ring, budget);
2013 if (work_done) {
2014 napi_complete(&tx_ring->napi);
2015 if (test_bit(__QLCNIC_DEV_UP , &adapter->state))
Manish chopra2cc57522014-01-23 17:18:30 -05002016 qlcnic_enable_tx_intr(adapter, tx_ring);
Shahed Shaikhf31ec952015-02-04 05:41:25 -05002017 } else {
2018 /* need a repoll */
2019 work_done = budget;
Sony Chacko4be41e92013-01-01 03:20:20 +00002020 }
2021
2022 return work_done;
2023}
2024
2025static int qlcnic_83xx_rx_poll(struct napi_struct *napi, int budget)
2026{
2027 int work_done;
2028 struct qlcnic_host_sds_ring *sds_ring;
2029 struct qlcnic_adapter *adapter;
2030
2031 sds_ring = container_of(napi, struct qlcnic_host_sds_ring, napi);
2032 adapter = sds_ring->adapter;
2033 work_done = qlcnic_83xx_process_rcv_ring(sds_ring, budget);
2034 if (work_done < budget) {
Eric Dumazet6ad20162017-01-30 08:22:01 -08002035 napi_complete_done(&sds_ring->napi, work_done);
Sony Chacko4be41e92013-01-01 03:20:20 +00002036 if (test_bit(__QLCNIC_DEV_UP, &adapter->state))
Manish chopra2cc57522014-01-23 17:18:30 -05002037 qlcnic_enable_sds_intr(adapter, sds_ring);
Sony Chacko4be41e92013-01-01 03:20:20 +00002038 }
2039
2040 return work_done;
2041}
2042
2043void qlcnic_83xx_napi_enable(struct qlcnic_adapter *adapter)
2044{
2045 int ring;
2046 struct qlcnic_host_sds_ring *sds_ring;
2047 struct qlcnic_host_tx_ring *tx_ring;
2048 struct qlcnic_recv_context *recv_ctx = adapter->recv_ctx;
2049
2050 if (adapter->is_up != QLCNIC_ADAPTER_UP_MAGIC)
2051 return;
2052
Himanshu Madhani34e8c402013-11-04 13:31:31 -05002053 for (ring = 0; ring < adapter->drv_sds_rings; ring++) {
Sony Chacko4be41e92013-01-01 03:20:20 +00002054 sds_ring = &recv_ctx->sds_rings[ring];
2055 napi_enable(&sds_ring->napi);
Himanshu Madhaniac166702013-02-18 12:06:15 +00002056 if (adapter->flags & QLCNIC_MSIX_ENABLED)
Manish chopra2cc57522014-01-23 17:18:30 -05002057 qlcnic_enable_sds_intr(adapter, sds_ring);
Sony Chacko4be41e92013-01-01 03:20:20 +00002058 }
2059
Rajesh Borundiada6c8062013-03-29 05:46:35 +00002060 if ((adapter->flags & QLCNIC_MSIX_ENABLED) &&
2061 !(adapter->flags & QLCNIC_TX_INTR_SHARED)) {
Himanshu Madhani34e8c402013-11-04 13:31:31 -05002062 for (ring = 0; ring < adapter->drv_tx_rings; ring++) {
Sony Chacko4be41e92013-01-01 03:20:20 +00002063 tx_ring = &adapter->tx_ring[ring];
2064 napi_enable(&tx_ring->napi);
Manish chopra2cc57522014-01-23 17:18:30 -05002065 qlcnic_enable_tx_intr(adapter, tx_ring);
Sony Chacko4be41e92013-01-01 03:20:20 +00002066 }
2067 }
2068}
2069
2070void qlcnic_83xx_napi_disable(struct qlcnic_adapter *adapter)
2071{
2072 int ring;
2073 struct qlcnic_host_sds_ring *sds_ring;
2074 struct qlcnic_recv_context *recv_ctx = adapter->recv_ctx;
2075 struct qlcnic_host_tx_ring *tx_ring;
2076
2077 if (adapter->is_up != QLCNIC_ADAPTER_UP_MAGIC)
2078 return;
2079
Himanshu Madhani34e8c402013-11-04 13:31:31 -05002080 for (ring = 0; ring < adapter->drv_sds_rings; ring++) {
Sony Chacko4be41e92013-01-01 03:20:20 +00002081 sds_ring = &recv_ctx->sds_rings[ring];
Himanshu Madhaniac166702013-02-18 12:06:15 +00002082 if (adapter->flags & QLCNIC_MSIX_ENABLED)
Manish chopra2cc57522014-01-23 17:18:30 -05002083 qlcnic_disable_sds_intr(adapter, sds_ring);
Sony Chacko4be41e92013-01-01 03:20:20 +00002084 napi_synchronize(&sds_ring->napi);
2085 napi_disable(&sds_ring->napi);
2086 }
2087
Rajesh Borundiada6c8062013-03-29 05:46:35 +00002088 if ((adapter->flags & QLCNIC_MSIX_ENABLED) &&
2089 !(adapter->flags & QLCNIC_TX_INTR_SHARED)) {
Himanshu Madhani34e8c402013-11-04 13:31:31 -05002090 for (ring = 0; ring < adapter->drv_tx_rings; ring++) {
Sony Chacko4be41e92013-01-01 03:20:20 +00002091 tx_ring = &adapter->tx_ring[ring];
Manish chopra2cc57522014-01-23 17:18:30 -05002092 qlcnic_disable_tx_intr(adapter, tx_ring);
Sony Chacko4be41e92013-01-01 03:20:20 +00002093 napi_synchronize(&tx_ring->napi);
2094 napi_disable(&tx_ring->napi);
2095 }
2096 }
2097}
2098
2099int qlcnic_83xx_napi_add(struct qlcnic_adapter *adapter,
2100 struct net_device *netdev)
2101{
Michal Schmidtdf95fc42013-09-04 15:03:05 +02002102 int ring;
Sony Chacko4be41e92013-01-01 03:20:20 +00002103 struct qlcnic_host_sds_ring *sds_ring;
2104 struct qlcnic_host_tx_ring *tx_ring;
2105 struct qlcnic_recv_context *recv_ctx = adapter->recv_ctx;
2106
Himanshu Madhani34e8c402013-11-04 13:31:31 -05002107 if (qlcnic_alloc_sds_rings(recv_ctx, adapter->drv_sds_rings))
Sony Chacko4be41e92013-01-01 03:20:20 +00002108 return -ENOMEM;
2109
Himanshu Madhani34e8c402013-11-04 13:31:31 -05002110 for (ring = 0; ring < adapter->drv_sds_rings; ring++) {
Sony Chacko4be41e92013-01-01 03:20:20 +00002111 sds_ring = &recv_ctx->sds_rings[ring];
Rajesh Borundiada6c8062013-03-29 05:46:35 +00002112 if (adapter->flags & QLCNIC_MSIX_ENABLED) {
Michal Schmidtdf95fc42013-09-04 15:03:05 +02002113 if (!(adapter->flags & QLCNIC_TX_INTR_SHARED))
Rajesh Borundiada6c8062013-03-29 05:46:35 +00002114 netif_napi_add(netdev, &sds_ring->napi,
2115 qlcnic_83xx_rx_poll,
Michal Schmidtdf95fc42013-09-04 15:03:05 +02002116 NAPI_POLL_WEIGHT);
2117 else
Rajesh Borundiada6c8062013-03-29 05:46:35 +00002118 netif_napi_add(netdev, &sds_ring->napi,
2119 qlcnic_83xx_msix_sriov_vf_poll,
Michal Schmidtdf95fc42013-09-04 15:03:05 +02002120 NAPI_POLL_WEIGHT);
Rajesh Borundiada6c8062013-03-29 05:46:35 +00002121
2122 } else {
Sony Chacko4be41e92013-01-01 03:20:20 +00002123 netif_napi_add(netdev, &sds_ring->napi,
2124 qlcnic_83xx_poll,
Michal Schmidtdf95fc42013-09-04 15:03:05 +02002125 NAPI_POLL_WEIGHT);
Rajesh Borundiada6c8062013-03-29 05:46:35 +00002126 }
Sony Chacko4be41e92013-01-01 03:20:20 +00002127 }
2128
2129 if (qlcnic_alloc_tx_rings(adapter, netdev)) {
2130 qlcnic_free_sds_rings(recv_ctx);
2131 return -ENOMEM;
2132 }
2133
Rajesh Borundiada6c8062013-03-29 05:46:35 +00002134 if ((adapter->flags & QLCNIC_MSIX_ENABLED) &&
2135 !(adapter->flags & QLCNIC_TX_INTR_SHARED)) {
Himanshu Madhani34e8c402013-11-04 13:31:31 -05002136 for (ring = 0; ring < adapter->drv_tx_rings; ring++) {
Sony Chacko4be41e92013-01-01 03:20:20 +00002137 tx_ring = &adapter->tx_ring[ring];
Eric Dumazetd64b5e82015-11-18 06:31:00 -08002138 netif_tx_napi_add(netdev, &tx_ring->napi,
Sony Chacko4be41e92013-01-01 03:20:20 +00002139 qlcnic_83xx_msix_tx_poll,
Michal Schmidtdf95fc42013-09-04 15:03:05 +02002140 NAPI_POLL_WEIGHT);
Sony Chacko4be41e92013-01-01 03:20:20 +00002141 }
2142 }
2143
2144 return 0;
2145}
2146
2147void qlcnic_83xx_napi_del(struct qlcnic_adapter *adapter)
2148{
2149 int ring;
2150 struct qlcnic_host_sds_ring *sds_ring;
2151 struct qlcnic_recv_context *recv_ctx = adapter->recv_ctx;
2152 struct qlcnic_host_tx_ring *tx_ring;
2153
Himanshu Madhani34e8c402013-11-04 13:31:31 -05002154 for (ring = 0; ring < adapter->drv_sds_rings; ring++) {
Sony Chacko4be41e92013-01-01 03:20:20 +00002155 sds_ring = &recv_ctx->sds_rings[ring];
2156 netif_napi_del(&sds_ring->napi);
2157 }
2158
2159 qlcnic_free_sds_rings(adapter->recv_ctx);
2160
Rajesh Borundiada6c8062013-03-29 05:46:35 +00002161 if ((adapter->flags & QLCNIC_MSIX_ENABLED) &&
2162 !(adapter->flags & QLCNIC_TX_INTR_SHARED)) {
Himanshu Madhani34e8c402013-11-04 13:31:31 -05002163 for (ring = 0; ring < adapter->drv_tx_rings; ring++) {
Sony Chacko4be41e92013-01-01 03:20:20 +00002164 tx_ring = &adapter->tx_ring[ring];
2165 netif_napi_del(&tx_ring->napi);
2166 }
2167 }
2168
2169 qlcnic_free_tx_rings(adapter);
2170}
2171
stephen hemminger21041402014-01-16 10:31:27 -08002172static void qlcnic_83xx_process_rcv_diag(struct qlcnic_adapter *adapter,
2173 int ring, u64 sts_data[])
Sony Chacko4be41e92013-01-01 03:20:20 +00002174{
2175 struct qlcnic_recv_context *recv_ctx = adapter->recv_ctx;
2176 struct sk_buff *skb;
2177 struct qlcnic_host_rds_ring *rds_ring;
2178 int index, length;
2179
2180 if (unlikely(ring >= adapter->max_rds_rings))
2181 return;
2182
2183 rds_ring = &recv_ctx->rds_rings[ring];
2184 index = qlcnic_83xx_hndl(sts_data[0]);
2185 if (unlikely(index >= rds_ring->num_desc))
2186 return;
2187
2188 length = qlcnic_83xx_pktln(sts_data[0]);
2189
2190 skb = qlcnic_process_rxbuf(adapter, rds_ring, index, STATUS_CKSUM_OK);
2191 if (!skb)
2192 return;
2193
2194 if (length > rds_ring->skb_size)
2195 skb_put(skb, rds_ring->skb_size);
2196 else
2197 skb_put(skb, length);
2198
2199 if (!qlcnic_check_loopback_buff(skb->data, adapter->mac_addr))
2200 adapter->ahw->diag_cnt++;
2201 else
2202 dump_skb(skb, adapter);
2203
2204 dev_kfree_skb_any(skb);
2205 return;
2206}
2207
2208void qlcnic_83xx_process_rcv_ring_diag(struct qlcnic_host_sds_ring *sds_ring)
2209{
2210 struct qlcnic_adapter *adapter = sds_ring->adapter;
2211 struct status_desc *desc;
2212 u64 sts_data[2];
2213 int ring, opcode;
2214 u32 consumer = sds_ring->consumer;
2215
2216 desc = &sds_ring->desc_head[consumer];
2217 sts_data[0] = le64_to_cpu(desc->status_desc_data[0]);
2218 sts_data[1] = le64_to_cpu(desc->status_desc_data[1]);
2219 opcode = qlcnic_83xx_opcode(sts_data[1]);
2220 if (!opcode)
2221 return;
2222
Dan Carpenter5b4d10f2016-06-27 23:50:29 +03002223 ring = QLCNIC_FETCH_RING_ID(sts_data[0]);
Sony Chacko4be41e92013-01-01 03:20:20 +00002224 qlcnic_83xx_process_rcv_diag(adapter, ring, sts_data);
2225 desc = &sds_ring->desc_head[consumer];
2226 desc->status_desc_data[0] = cpu_to_le64(STATUS_OWNER_PHANTOM);
2227 consumer = get_next_index(consumer, sds_ring->num_desc);
2228 sds_ring->consumer = consumer;
2229 writel(consumer, sds_ring->crb_sts_consumer);
2230}