blob: 54ebf300332a353246066e5cf62f1d097355e1e5 [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>
Sony Chackoc70001a2012-11-28 04:34:26 +000013
14#include "qlcnic.h"
15
Sony Chackoc70001a2012-11-28 04:34:26 +000016#define TX_ETHER_PKT 0x01
17#define TX_TCP_PKT 0x02
18#define TX_UDP_PKT 0x03
19#define TX_IP_PKT 0x04
20#define TX_TCP_LSO 0x05
21#define TX_TCP_LSO6 0x06
22#define TX_TCPV6_PKT 0x0b
23#define TX_UDPV6_PKT 0x0c
24#define FLAGS_VLAN_TAGGED 0x10
25#define FLAGS_VLAN_OOB 0x40
26
27#define qlcnic_set_tx_vlan_tci(cmd_desc, v) \
28 (cmd_desc)->vlan_TCI = cpu_to_le16(v);
29#define qlcnic_set_cmd_desc_port(cmd_desc, var) \
30 ((cmd_desc)->port_ctxid |= ((var) & 0x0F))
31#define qlcnic_set_cmd_desc_ctxid(cmd_desc, var) \
32 ((cmd_desc)->port_ctxid |= ((var) << 4 & 0xF0))
33
34#define qlcnic_set_tx_port(_desc, _port) \
35 ((_desc)->port_ctxid = ((_port) & 0xf) | (((_port) << 4) & 0xf0))
36
37#define qlcnic_set_tx_flags_opcode(_desc, _flags, _opcode) \
38 ((_desc)->flags_opcode |= \
39 cpu_to_le16(((_flags) & 0x7f) | (((_opcode) & 0x3f) << 7)))
40
41#define qlcnic_set_tx_frags_len(_desc, _frags, _len) \
42 ((_desc)->nfrags__length = \
43 cpu_to_le32(((_frags) & 0xff) | (((_len) & 0xffffff) << 8)))
44
45/* owner bits of status_desc */
46#define STATUS_OWNER_HOST (0x1ULL << 56)
47#define STATUS_OWNER_PHANTOM (0x2ULL << 56)
48
49/* Status descriptor:
50 0-3 port, 4-7 status, 8-11 type, 12-27 total_length
51 28-43 reference_handle, 44-47 protocol, 48-52 pkt_offset
52 53-55 desc_cnt, 56-57 owner, 58-63 opcode
53 */
54#define qlcnic_get_sts_port(sts_data) \
55 ((sts_data) & 0x0F)
56#define qlcnic_get_sts_status(sts_data) \
57 (((sts_data) >> 4) & 0x0F)
58#define qlcnic_get_sts_type(sts_data) \
59 (((sts_data) >> 8) & 0x0F)
60#define qlcnic_get_sts_totallength(sts_data) \
61 (((sts_data) >> 12) & 0xFFFF)
62#define qlcnic_get_sts_refhandle(sts_data) \
63 (((sts_data) >> 28) & 0xFFFF)
64#define qlcnic_get_sts_prot(sts_data) \
65 (((sts_data) >> 44) & 0x0F)
66#define qlcnic_get_sts_pkt_offset(sts_data) \
67 (((sts_data) >> 48) & 0x1F)
68#define qlcnic_get_sts_desc_cnt(sts_data) \
69 (((sts_data) >> 53) & 0x7)
70#define qlcnic_get_sts_opcode(sts_data) \
71 (((sts_data) >> 58) & 0x03F)
72
73#define qlcnic_get_lro_sts_refhandle(sts_data) \
Sony Chacko5796bd02012-12-04 03:33:57 +000074 ((sts_data) & 0x07FFF)
Sony Chackoc70001a2012-11-28 04:34:26 +000075#define qlcnic_get_lro_sts_length(sts_data) \
76 (((sts_data) >> 16) & 0x0FFFF)
77#define qlcnic_get_lro_sts_l2_hdr_offset(sts_data) \
78 (((sts_data) >> 32) & 0x0FF)
79#define qlcnic_get_lro_sts_l4_hdr_offset(sts_data) \
80 (((sts_data) >> 40) & 0x0FF)
81#define qlcnic_get_lro_sts_timestamp(sts_data) \
82 (((sts_data) >> 48) & 0x1)
83#define qlcnic_get_lro_sts_type(sts_data) \
84 (((sts_data) >> 49) & 0x7)
85#define qlcnic_get_lro_sts_push_flag(sts_data) \
86 (((sts_data) >> 52) & 0x1)
87#define qlcnic_get_lro_sts_seq_number(sts_data) \
88 ((sts_data) & 0x0FFFFFFFF)
89#define qlcnic_get_lro_sts_mss(sts_data1) \
90 ((sts_data1 >> 32) & 0x0FFFF)
91
Shahed Shaikh99e85872013-02-18 12:06:16 +000092#define qlcnic_83xx_get_lro_sts_mss(sts) ((sts) & 0xffff)
93
Sony Chackoc70001a2012-11-28 04:34:26 +000094/* opcode field in status_desc */
95#define QLCNIC_SYN_OFFLOAD 0x03
96#define QLCNIC_RXPKT_DESC 0x04
97#define QLCNIC_OLD_RXPKT_DESC 0x3f
98#define QLCNIC_RESPONSE_DESC 0x05
99#define QLCNIC_LRO_DESC 0x12
100
Sony Chacko4be41e92013-01-01 03:20:20 +0000101#define QLCNIC_TX_POLL_BUDGET 128
102#define QLCNIC_TCP_HDR_SIZE 20
103#define QLCNIC_TCP_TS_OPTION_SIZE 12
104#define QLCNIC_FETCH_RING_ID(handle) ((handle) >> 63)
105#define QLCNIC_DESC_OWNER_FW cpu_to_le64(STATUS_OWNER_PHANTOM)
106
107#define QLCNIC_TCP_TS_HDR_SIZE (QLCNIC_TCP_HDR_SIZE + QLCNIC_TCP_TS_OPTION_SIZE)
108
Sony Chackoc70001a2012-11-28 04:34:26 +0000109/* for status field in status_desc */
110#define STATUS_CKSUM_LOOP 0
111#define STATUS_CKSUM_OK 2
Sony Chackod17dd0d2012-11-28 04:34:27 +0000112
Sony Chacko4be41e92013-01-01 03:20:20 +0000113#define qlcnic_83xx_pktln(sts) ((sts >> 32) & 0x3FFF)
114#define qlcnic_83xx_hndl(sts) ((sts >> 48) & 0x7FFF)
115#define qlcnic_83xx_csum_status(sts) ((sts >> 39) & 7)
116#define qlcnic_83xx_opcode(sts) ((sts >> 42) & 0xF)
117#define qlcnic_83xx_vlan_tag(sts) (((sts) >> 48) & 0xFFFF)
118#define qlcnic_83xx_lro_pktln(sts) (((sts) >> 32) & 0x3FFF)
119#define qlcnic_83xx_l2_hdr_off(sts) (((sts) >> 16) & 0xFF)
120#define qlcnic_83xx_l4_hdr_off(sts) (((sts) >> 24) & 0xFF)
121#define qlcnic_83xx_pkt_cnt(sts) (((sts) >> 16) & 0x7)
122#define qlcnic_83xx_is_tstamp(sts) (((sts) >> 40) & 1)
123#define qlcnic_83xx_is_psh_bit(sts) (((sts) >> 41) & 1)
124#define qlcnic_83xx_is_ip_align(sts) (((sts) >> 46) & 1)
125#define qlcnic_83xx_has_vlan_tag(sts) (((sts) >> 47) & 1)
126
stephen hemminger21041402014-01-16 10:31:27 -0800127static int qlcnic_process_rcv_ring(struct qlcnic_host_sds_ring *sds_ring,
128 int max);
129
130static struct sk_buff *qlcnic_process_rxbuf(struct qlcnic_adapter *,
131 struct qlcnic_host_rds_ring *,
132 u16, u16);
Sony Chacko4be41e92013-01-01 03:20:20 +0000133
Sucheta Chakrabortyb3f7de82014-01-10 11:48:55 -0500134static inline u8 qlcnic_mac_hash(u64 mac, u16 vlan)
Sony Chacko4be41e92013-01-01 03:20:20 +0000135{
Sucheta Chakrabortyb3f7de82014-01-10 11:48:55 -0500136 return (u8)((mac & 0xff) ^ ((mac >> 40) & 0xff) ^ (vlan & 0xff));
Sony Chacko4be41e92013-01-01 03:20:20 +0000137}
138
139static inline u32 qlcnic_get_ref_handle(struct qlcnic_adapter *adapter,
140 u16 handle, u8 ring_id)
141{
Manish Chopra15ca1402013-08-16 19:07:13 -0400142 if (qlcnic_83xx_check(adapter))
Sony Chacko4be41e92013-01-01 03:20:20 +0000143 return handle | (ring_id << 15);
144 else
145 return handle;
146}
147
Shahed Shaikh53643a72013-02-18 13:22:37 +0000148static inline int qlcnic_82xx_is_lb_pkt(u64 sts_data)
149{
150 return (qlcnic_get_sts_status(sts_data) == STATUS_CKSUM_LOOP) ? 1 : 0;
151}
152
Shahed Shaikhe0d138d2013-08-02 23:15:55 -0400153static void qlcnic_delete_rx_list_mac(struct qlcnic_adapter *adapter,
154 struct qlcnic_filter *fil,
155 void *addr, u16 vlan_id)
156{
157 int ret;
158 u8 op;
159
160 op = vlan_id ? QLCNIC_MAC_VLAN_ADD : QLCNIC_MAC_ADD;
161 ret = qlcnic_sre_macaddr_change(adapter, addr, vlan_id, op);
162 if (ret)
163 return;
164
165 op = vlan_id ? QLCNIC_MAC_VLAN_DEL : QLCNIC_MAC_DEL;
166 ret = qlcnic_sre_macaddr_change(adapter, addr, vlan_id, op);
167 if (!ret) {
168 hlist_del(&fil->fnode);
169 adapter->rx_fhash.fnum--;
170 }
171}
172
173static struct qlcnic_filter *qlcnic_find_mac_filter(struct hlist_head *head,
174 void *addr, u16 vlan_id)
175{
176 struct qlcnic_filter *tmp_fil = NULL;
177 struct hlist_node *n;
178
179 hlist_for_each_entry_safe(tmp_fil, n, head, fnode) {
dingtianhong6878f792013-12-30 15:41:14 +0800180 if (ether_addr_equal(tmp_fil->faddr, addr) &&
Shahed Shaikhe0d138d2013-08-02 23:15:55 -0400181 tmp_fil->vlan_id == vlan_id)
182 return tmp_fil;
183 }
184
185 return NULL;
186}
187
stephen hemminger21041402014-01-16 10:31:27 -0800188static void qlcnic_add_lb_filter(struct qlcnic_adapter *adapter,
189 struct sk_buff *skb, int loopback_pkt, u16 vlan_id)
Shahed Shaikh53643a72013-02-18 13:22:37 +0000190{
191 struct ethhdr *phdr = (struct ethhdr *)(skb->data);
192 struct qlcnic_filter *fil, *tmp_fil;
Shahed Shaikh53643a72013-02-18 13:22:37 +0000193 struct hlist_head *head;
194 unsigned long time;
195 u64 src_addr = 0;
Shahed Shaikhe0d138d2013-08-02 23:15:55 -0400196 u8 hindex, op;
Shahed Shaikh53643a72013-02-18 13:22:37 +0000197 int ret;
198
Sucheta Chakrabortyb3f7de82014-01-10 11:48:55 -0500199 if (!qlcnic_sriov_pf_check(adapter) || (vlan_id == 0xffff))
200 vlan_id = 0;
201
Shahed Shaikh53643a72013-02-18 13:22:37 +0000202 memcpy(&src_addr, phdr->h_source, ETH_ALEN);
Sucheta Chakrabortyb3f7de82014-01-10 11:48:55 -0500203 hindex = qlcnic_mac_hash(src_addr, vlan_id) &
Shahed Shaikhe0d138d2013-08-02 23:15:55 -0400204 (adapter->fhash.fbucket_size - 1);
Shahed Shaikh53643a72013-02-18 13:22:37 +0000205
206 if (loopback_pkt) {
207 if (adapter->rx_fhash.fnum >= adapter->rx_fhash.fmax)
208 return;
209
Shahed Shaikh53643a72013-02-18 13:22:37 +0000210 head = &(adapter->rx_fhash.fhead[hindex]);
211
Shahed Shaikhe0d138d2013-08-02 23:15:55 -0400212 tmp_fil = qlcnic_find_mac_filter(head, &src_addr, vlan_id);
213 if (tmp_fil) {
214 time = tmp_fil->ftime;
215 if (time_after(jiffies, QLCNIC_READD_AGE * HZ + time))
216 tmp_fil->ftime = jiffies;
217 return;
Shahed Shaikh53643a72013-02-18 13:22:37 +0000218 }
219
220 fil = kzalloc(sizeof(struct qlcnic_filter), GFP_ATOMIC);
221 if (!fil)
222 return;
223
224 fil->ftime = jiffies;
225 memcpy(fil->faddr, &src_addr, ETH_ALEN);
226 fil->vlan_id = vlan_id;
227 spin_lock(&adapter->rx_mac_learn_lock);
228 hlist_add_head(&(fil->fnode), head);
229 adapter->rx_fhash.fnum++;
230 spin_unlock(&adapter->rx_mac_learn_lock);
231 } else {
Shahed Shaikhe0d138d2013-08-02 23:15:55 -0400232 head = &adapter->fhash.fhead[hindex];
Shahed Shaikh53643a72013-02-18 13:22:37 +0000233
Shahed Shaikhe0d138d2013-08-02 23:15:55 -0400234 spin_lock(&adapter->mac_learn_lock);
Shahed Shaikh53643a72013-02-18 13:22:37 +0000235
Shahed Shaikhe0d138d2013-08-02 23:15:55 -0400236 tmp_fil = qlcnic_find_mac_filter(head, &src_addr, vlan_id);
237 if (tmp_fil) {
Shahed Shaikh53643a72013-02-18 13:22:37 +0000238 op = vlan_id ? QLCNIC_MAC_VLAN_DEL : QLCNIC_MAC_DEL;
239 ret = qlcnic_sre_macaddr_change(adapter,
240 (u8 *)&src_addr,
241 vlan_id, op);
242 if (!ret) {
Shahed Shaikhe0d138d2013-08-02 23:15:55 -0400243 hlist_del(&tmp_fil->fnode);
244 adapter->fhash.fnum--;
Shahed Shaikh53643a72013-02-18 13:22:37 +0000245 }
Shahed Shaikhe0d138d2013-08-02 23:15:55 -0400246
247 spin_unlock(&adapter->mac_learn_lock);
248
249 return;
Shahed Shaikh53643a72013-02-18 13:22:37 +0000250 }
Shahed Shaikhe0d138d2013-08-02 23:15:55 -0400251
252 spin_unlock(&adapter->mac_learn_lock);
253
254 head = &adapter->rx_fhash.fhead[hindex];
255
256 spin_lock(&adapter->rx_mac_learn_lock);
257
258 tmp_fil = qlcnic_find_mac_filter(head, &src_addr, vlan_id);
259 if (tmp_fil)
260 qlcnic_delete_rx_list_mac(adapter, tmp_fil, &src_addr,
261 vlan_id);
262
Shahed Shaikh53643a72013-02-18 13:22:37 +0000263 spin_unlock(&adapter->rx_mac_learn_lock);
264 }
265}
266
Sony Chacko7e2cf4f2013-01-01 03:20:17 +0000267void qlcnic_82xx_change_filter(struct qlcnic_adapter *adapter, u64 *uaddr,
Rajesh Borundiaf80bc8f2013-04-19 07:01:08 +0000268 u16 vlan_id)
Sony Chackoc70001a2012-11-28 04:34:26 +0000269{
270 struct cmd_desc_type0 *hwdesc;
271 struct qlcnic_nic_req *req;
272 struct qlcnic_mac_req *mac_req;
273 struct qlcnic_vlan_req *vlan_req;
Sony Chacko7e2cf4f2013-01-01 03:20:17 +0000274 struct qlcnic_host_tx_ring *tx_ring = adapter->tx_ring;
Sony Chackoc70001a2012-11-28 04:34:26 +0000275 u32 producer;
276 u64 word;
277
278 producer = tx_ring->producer;
279 hwdesc = &tx_ring->desc_head[tx_ring->producer];
280
281 req = (struct qlcnic_nic_req *)hwdesc;
282 memset(req, 0, sizeof(struct qlcnic_nic_req));
283 req->qhdr = cpu_to_le64(QLCNIC_REQUEST << 23);
284
285 word = QLCNIC_MAC_EVENT | ((u64)(adapter->portnum) << 16);
286 req->req_hdr = cpu_to_le64(word);
287
288 mac_req = (struct qlcnic_mac_req *)&(req->words[0]);
289 mac_req->op = vlan_id ? QLCNIC_MAC_VLAN_ADD : QLCNIC_MAC_ADD;
Shahed Shaikh4a99ab52013-08-02 23:15:54 -0400290 memcpy(mac_req->mac_addr, uaddr, ETH_ALEN);
Sony Chackoc70001a2012-11-28 04:34:26 +0000291
292 vlan_req = (struct qlcnic_vlan_req *)&req->words[1];
Rajesh Borundiaf80bc8f2013-04-19 07:01:08 +0000293 vlan_req->vlan_id = cpu_to_le16(vlan_id);
Sony Chackoc70001a2012-11-28 04:34:26 +0000294
295 tx_ring->producer = get_next_index(producer, tx_ring->num_desc);
296 smp_mb();
297}
298
Sony Chackod17dd0d2012-11-28 04:34:27 +0000299static void qlcnic_send_filter(struct qlcnic_adapter *adapter,
Sony Chackod17dd0d2012-11-28 04:34:27 +0000300 struct cmd_desc_type0 *first_desc,
301 struct sk_buff *skb)
Sony Chackoc70001a2012-11-28 04:34:26 +0000302{
Sucheta Chakrabortyb3f7de82014-01-10 11:48:55 -0500303 struct vlan_ethhdr *vh = (struct vlan_ethhdr *)(skb->data);
Sony Chacko7e2cf4f2013-01-01 03:20:17 +0000304 struct ethhdr *phdr = (struct ethhdr *)(skb->data);
Sucheta Chakrabortyb3f7de82014-01-10 11:48:55 -0500305 struct net_device *netdev = adapter->netdev;
306 u16 protocol = ntohs(skb->protocol);
307 struct qlcnic_filter *fil, *tmp_fil;
308 struct hlist_head *head;
309 struct hlist_node *n;
Sony Chackoc70001a2012-11-28 04:34:26 +0000310 u64 src_addr = 0;
Rajesh Borundiaf80bc8f2013-04-19 07:01:08 +0000311 u16 vlan_id = 0;
Sucheta Chakrabortyb3f7de82014-01-10 11:48:55 -0500312 u8 hindex, hval;
Sony Chackoc70001a2012-11-28 04:34:26 +0000313
Sucheta Chakrabortyb3f7de82014-01-10 11:48:55 -0500314 if (!qlcnic_sriov_pf_check(adapter)) {
315 if (ether_addr_equal(phdr->h_source, adapter->mac_addr))
316 return;
317 } else {
318 if (protocol == ETH_P_8021Q) {
319 vh = (struct vlan_ethhdr *)skb->data;
320 vlan_id = ntohs(vh->h_vlan_TCI);
321 } else if (vlan_tx_tag_present(skb)) {
322 vlan_id = vlan_tx_tag_get(skb);
323 }
324
325 if (ether_addr_equal(phdr->h_source, adapter->mac_addr) &&
326 !vlan_id)
327 return;
328 }
Sony Chackoc70001a2012-11-28 04:34:26 +0000329
Sony Chacko4be41e92013-01-01 03:20:20 +0000330 if (adapter->fhash.fnum >= adapter->fhash.fmax) {
331 adapter->stats.mac_filter_limit_overrun++;
Sucheta Chakrabortyb3f7de82014-01-10 11:48:55 -0500332 netdev_info(netdev, "Can not add more than %d mac-vlan filters, configured %d\n",
333 adapter->fhash.fmax, adapter->fhash.fnum);
Sony Chackoc70001a2012-11-28 04:34:26 +0000334 return;
Sony Chacko4be41e92013-01-01 03:20:20 +0000335 }
Sony Chackoc70001a2012-11-28 04:34:26 +0000336
Sony Chackoc70001a2012-11-28 04:34:26 +0000337 memcpy(&src_addr, phdr->h_source, ETH_ALEN);
Sucheta Chakrabortyb3f7de82014-01-10 11:48:55 -0500338 hval = qlcnic_mac_hash(src_addr, vlan_id);
339 hindex = hval & (adapter->fhash.fbucket_size - 1);
Sony Chackoc70001a2012-11-28 04:34:26 +0000340 head = &(adapter->fhash.fhead[hindex]);
341
Sasha Levinb67bfe02013-02-27 17:06:00 -0800342 hlist_for_each_entry_safe(tmp_fil, n, head, fnode) {
dingtianhonge2072cd2014-01-11 16:23:35 +0800343 if (ether_addr_equal(tmp_fil->faddr, (u8 *)&src_addr) &&
Sony Chacko7e2cf4f2013-01-01 03:20:17 +0000344 tmp_fil->vlan_id == vlan_id) {
Sony Chackod17dd0d2012-11-28 04:34:27 +0000345 if (jiffies > (QLCNIC_READD_AGE * HZ + tmp_fil->ftime))
Sony Chacko7e2cf4f2013-01-01 03:20:17 +0000346 qlcnic_change_filter(adapter, &src_addr,
347 vlan_id);
Sony Chackoc70001a2012-11-28 04:34:26 +0000348 tmp_fil->ftime = jiffies;
349 return;
350 }
351 }
352
353 fil = kzalloc(sizeof(struct qlcnic_filter), GFP_ATOMIC);
354 if (!fil)
355 return;
356
Sony Chacko7e2cf4f2013-01-01 03:20:17 +0000357 qlcnic_change_filter(adapter, &src_addr, vlan_id);
Sony Chackoc70001a2012-11-28 04:34:26 +0000358 fil->ftime = jiffies;
359 fil->vlan_id = vlan_id;
360 memcpy(fil->faddr, &src_addr, ETH_ALEN);
361 spin_lock(&adapter->mac_learn_lock);
362 hlist_add_head(&(fil->fnode), head);
363 adapter->fhash.fnum++;
364 spin_unlock(&adapter->mac_learn_lock);
365}
366
Sony Chackod17dd0d2012-11-28 04:34:27 +0000367static int qlcnic_tx_pkt(struct qlcnic_adapter *adapter,
Himanshu Madhani012ec812013-08-21 11:24:10 -0400368 struct cmd_desc_type0 *first_desc, struct sk_buff *skb,
369 struct qlcnic_host_tx_ring *tx_ring)
Sony Chackoc70001a2012-11-28 04:34:26 +0000370{
Sony Chackod17dd0d2012-11-28 04:34:27 +0000371 u8 l4proto, opcode = 0, hdr_len = 0;
Sony Chackoc70001a2012-11-28 04:34:26 +0000372 u16 flags = 0, vlan_tci = 0;
Sony Chackod17dd0d2012-11-28 04:34:27 +0000373 int copied, offset, copy_len, size;
Sony Chackoc70001a2012-11-28 04:34:26 +0000374 struct cmd_desc_type0 *hwdesc;
375 struct vlan_ethhdr *vh;
Sony Chackoc70001a2012-11-28 04:34:26 +0000376 u16 protocol = ntohs(skb->protocol);
377 u32 producer = tx_ring->producer;
378
379 if (protocol == ETH_P_8021Q) {
380 vh = (struct vlan_ethhdr *)skb->data;
381 flags = FLAGS_VLAN_TAGGED;
382 vlan_tci = ntohs(vh->h_vlan_TCI);
383 protocol = ntohs(vh->h_vlan_encapsulated_proto);
384 } else if (vlan_tx_tag_present(skb)) {
385 flags = FLAGS_VLAN_OOB;
386 vlan_tci = vlan_tx_tag_get(skb);
387 }
Rajesh Borundia91b72822013-04-19 07:01:12 +0000388 if (unlikely(adapter->tx_pvid)) {
Sony Chackoc70001a2012-11-28 04:34:26 +0000389 if (vlan_tci && !(adapter->flags & QLCNIC_TAGGING_ENABLED))
390 return -EIO;
391 if (vlan_tci && (adapter->flags & QLCNIC_TAGGING_ENABLED))
392 goto set_flags;
393
394 flags = FLAGS_VLAN_OOB;
Rajesh Borundia91b72822013-04-19 07:01:12 +0000395 vlan_tci = adapter->tx_pvid;
Sony Chackoc70001a2012-11-28 04:34:26 +0000396 }
397set_flags:
398 qlcnic_set_tx_vlan_tci(first_desc, vlan_tci);
399 qlcnic_set_tx_flags_opcode(first_desc, flags, opcode);
400
401 if (*(skb->data) & BIT_0) {
402 flags |= BIT_0;
403 memcpy(&first_desc->eth_addr, skb->data, ETH_ALEN);
404 }
405 opcode = TX_ETHER_PKT;
Sritej Velaga3eead212013-04-18 08:10:05 +0000406 if (skb_is_gso(skb)) {
Sony Chackoc70001a2012-11-28 04:34:26 +0000407 hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
Sony Chackoc70001a2012-11-28 04:34:26 +0000408 first_desc->mss = cpu_to_le16(skb_shinfo(skb)->gso_size);
409 first_desc->total_hdr_length = hdr_len;
Sony Chackoc70001a2012-11-28 04:34:26 +0000410 opcode = (protocol == ETH_P_IPV6) ? TX_TCP_LSO6 : TX_TCP_LSO;
411
412 /* For LSO, we need to copy the MAC/IP/TCP headers into
413 * the descriptor ring */
414 copied = 0;
415 offset = 2;
416
417 if (flags & FLAGS_VLAN_OOB) {
418 first_desc->total_hdr_length += VLAN_HLEN;
419 first_desc->tcp_hdr_offset = VLAN_HLEN;
420 first_desc->ip_hdr_offset = VLAN_HLEN;
Sony Chackod17dd0d2012-11-28 04:34:27 +0000421
Sony Chackoc70001a2012-11-28 04:34:26 +0000422 /* Only in case of TSO on vlan device */
423 flags |= FLAGS_VLAN_TAGGED;
424
425 /* Create a TSO vlan header template for firmware */
Sony Chackoc70001a2012-11-28 04:34:26 +0000426 hwdesc = &tx_ring->desc_head[producer];
427 tx_ring->cmd_buf_arr[producer].skb = NULL;
428
429 copy_len = min((int)sizeof(struct cmd_desc_type0) -
Sony Chackod17dd0d2012-11-28 04:34:27 +0000430 offset, hdr_len + VLAN_HLEN);
Sony Chackoc70001a2012-11-28 04:34:26 +0000431
432 vh = (struct vlan_ethhdr *)((char *) hwdesc + 2);
433 skb_copy_from_linear_data(skb, vh, 12);
434 vh->h_vlan_proto = htons(ETH_P_8021Q);
435 vh->h_vlan_TCI = htons(vlan_tci);
436
437 skb_copy_from_linear_data_offset(skb, 12,
Sony Chackod17dd0d2012-11-28 04:34:27 +0000438 (char *)vh + 16,
439 copy_len - 16);
Sony Chackoc70001a2012-11-28 04:34:26 +0000440 copied = copy_len - VLAN_HLEN;
441 offset = 0;
Sony Chackoc70001a2012-11-28 04:34:26 +0000442 producer = get_next_index(producer, tx_ring->num_desc);
443 }
444
445 while (copied < hdr_len) {
Sony Chackod17dd0d2012-11-28 04:34:27 +0000446 size = (int)sizeof(struct cmd_desc_type0) - offset;
447 copy_len = min(size, (hdr_len - copied));
Sony Chackoc70001a2012-11-28 04:34:26 +0000448 hwdesc = &tx_ring->desc_head[producer];
449 tx_ring->cmd_buf_arr[producer].skb = NULL;
Sony Chackoc70001a2012-11-28 04:34:26 +0000450 skb_copy_from_linear_data_offset(skb, copied,
Sony Chackod17dd0d2012-11-28 04:34:27 +0000451 (char *)hwdesc +
452 offset, copy_len);
Sony Chackoc70001a2012-11-28 04:34:26 +0000453 copied += copy_len;
454 offset = 0;
Sony Chackoc70001a2012-11-28 04:34:26 +0000455 producer = get_next_index(producer, tx_ring->num_desc);
456 }
457
458 tx_ring->producer = producer;
459 smp_mb();
460 adapter->stats.lso_frames++;
461
462 } else if (skb->ip_summed == CHECKSUM_PARTIAL) {
Sony Chackoc70001a2012-11-28 04:34:26 +0000463 if (protocol == ETH_P_IP) {
464 l4proto = ip_hdr(skb)->protocol;
465
466 if (l4proto == IPPROTO_TCP)
467 opcode = TX_TCP_PKT;
468 else if (l4proto == IPPROTO_UDP)
469 opcode = TX_UDP_PKT;
470 } else if (protocol == ETH_P_IPV6) {
471 l4proto = ipv6_hdr(skb)->nexthdr;
472
473 if (l4proto == IPPROTO_TCP)
474 opcode = TX_TCPV6_PKT;
475 else if (l4proto == IPPROTO_UDP)
476 opcode = TX_UDPV6_PKT;
477 }
478 }
479 first_desc->tcp_hdr_offset += skb_transport_offset(skb);
480 first_desc->ip_hdr_offset += skb_network_offset(skb);
481 qlcnic_set_tx_flags_opcode(first_desc, flags, opcode);
482
483 return 0;
484}
485
Sony Chackod17dd0d2012-11-28 04:34:27 +0000486static int qlcnic_map_tx_skb(struct pci_dev *pdev, struct sk_buff *skb,
487 struct qlcnic_cmd_buffer *pbuf)
Sony Chackoc70001a2012-11-28 04:34:26 +0000488{
489 struct qlcnic_skb_frag *nf;
490 struct skb_frag_struct *frag;
491 int i, nr_frags;
492 dma_addr_t map;
493
494 nr_frags = skb_shinfo(skb)->nr_frags;
495 nf = &pbuf->frag_array[0];
496
Sony Chackod17dd0d2012-11-28 04:34:27 +0000497 map = pci_map_single(pdev, skb->data, skb_headlen(skb),
498 PCI_DMA_TODEVICE);
Sony Chackoc70001a2012-11-28 04:34:26 +0000499 if (pci_dma_mapping_error(pdev, map))
500 goto out_err;
501
502 nf->dma = map;
503 nf->length = skb_headlen(skb);
504
505 for (i = 0; i < nr_frags; i++) {
506 frag = &skb_shinfo(skb)->frags[i];
507 nf = &pbuf->frag_array[i+1];
Sony Chackoc70001a2012-11-28 04:34:26 +0000508 map = skb_frag_dma_map(&pdev->dev, frag, 0, skb_frag_size(frag),
509 DMA_TO_DEVICE);
510 if (dma_mapping_error(&pdev->dev, map))
511 goto unwind;
512
513 nf->dma = map;
514 nf->length = skb_frag_size(frag);
515 }
516
517 return 0;
518
519unwind:
520 while (--i >= 0) {
521 nf = &pbuf->frag_array[i+1];
522 pci_unmap_page(pdev, nf->dma, nf->length, PCI_DMA_TODEVICE);
523 }
524
525 nf = &pbuf->frag_array[0];
526 pci_unmap_single(pdev, nf->dma, skb_headlen(skb), PCI_DMA_TODEVICE);
527
528out_err:
529 return -ENOMEM;
530}
531
Sony Chackod17dd0d2012-11-28 04:34:27 +0000532static void qlcnic_unmap_buffers(struct pci_dev *pdev, struct sk_buff *skb,
533 struct qlcnic_cmd_buffer *pbuf)
Sony Chackoc70001a2012-11-28 04:34:26 +0000534{
535 struct qlcnic_skb_frag *nf = &pbuf->frag_array[0];
Sony Chackod17dd0d2012-11-28 04:34:27 +0000536 int i, nr_frags = skb_shinfo(skb)->nr_frags;
Sony Chackoc70001a2012-11-28 04:34:26 +0000537
538 for (i = 0; i < nr_frags; i++) {
539 nf = &pbuf->frag_array[i+1];
540 pci_unmap_page(pdev, nf->dma, nf->length, PCI_DMA_TODEVICE);
541 }
542
543 nf = &pbuf->frag_array[0];
544 pci_unmap_single(pdev, nf->dma, skb_headlen(skb), PCI_DMA_TODEVICE);
545 pbuf->skb = NULL;
546}
547
Sony Chackod17dd0d2012-11-28 04:34:27 +0000548static inline void qlcnic_clear_cmddesc(u64 *desc)
Sony Chackoc70001a2012-11-28 04:34:26 +0000549{
550 desc[0] = 0ULL;
551 desc[2] = 0ULL;
552 desc[7] = 0ULL;
553}
554
Sony Chackod17dd0d2012-11-28 04:34:27 +0000555netdev_tx_t qlcnic_xmit_frame(struct sk_buff *skb, struct net_device *netdev)
Sony Chackoc70001a2012-11-28 04:34:26 +0000556{
557 struct qlcnic_adapter *adapter = netdev_priv(netdev);
Himanshu Madhani012ec812013-08-21 11:24:10 -0400558 struct qlcnic_host_tx_ring *tx_ring;
Sony Chackoc70001a2012-11-28 04:34:26 +0000559 struct qlcnic_cmd_buffer *pbuf;
560 struct qlcnic_skb_frag *buffrag;
561 struct cmd_desc_type0 *hwdesc, *first_desc;
562 struct pci_dev *pdev;
563 struct ethhdr *phdr;
Sony Chackod17dd0d2012-11-28 04:34:27 +0000564 int i, k, frag_count, delta = 0;
565 u32 producer, num_txd;
Sony Chackoc70001a2012-11-28 04:34:26 +0000566
Sony Chackoc70001a2012-11-28 04:34:26 +0000567 if (!test_bit(__QLCNIC_DEV_UP, &adapter->state)) {
Himanshu Madhani012ec812013-08-21 11:24:10 -0400568 netif_tx_stop_all_queues(netdev);
Sony Chackoc70001a2012-11-28 04:34:26 +0000569 return NETDEV_TX_BUSY;
570 }
571
572 if (adapter->flags & QLCNIC_MACSPOOF) {
573 phdr = (struct ethhdr *)skb->data;
574 if (!ether_addr_equal(phdr->h_source, adapter->mac_addr))
575 goto drop_packet;
576 }
577
Himanshu Madhani18afc102013-11-04 13:31:32 -0500578 tx_ring = &adapter->tx_ring[skb_get_queue_mapping(skb)];
Himanshu Madhani012ec812013-08-21 11:24:10 -0400579 num_txd = tx_ring->num_desc;
580
Sony Chackoc70001a2012-11-28 04:34:26 +0000581 frag_count = skb_shinfo(skb)->nr_frags + 1;
Himanshu Madhani012ec812013-08-21 11:24:10 -0400582
Sony Chackoc70001a2012-11-28 04:34:26 +0000583 /* 14 frags supported for normal packet and
584 * 32 frags supported for TSO packet
585 */
586 if (!skb_is_gso(skb) && frag_count > QLCNIC_MAX_FRAGS_PER_TX) {
Sony Chackoc70001a2012-11-28 04:34:26 +0000587 for (i = 0; i < (frag_count - QLCNIC_MAX_FRAGS_PER_TX); i++)
588 delta += skb_frag_size(&skb_shinfo(skb)->frags[i]);
589
590 if (!__pskb_pull_tail(skb, delta))
591 goto drop_packet;
592
593 frag_count = 1 + skb_shinfo(skb)->nr_frags;
594 }
595
596 if (unlikely(qlcnic_tx_avail(tx_ring) <= TX_STOP_THRESH)) {
Himanshu Madhani012ec812013-08-21 11:24:10 -0400597 netif_tx_stop_queue(tx_ring->txq);
Sony Chackod17dd0d2012-11-28 04:34:27 +0000598 if (qlcnic_tx_avail(tx_ring) > TX_STOP_THRESH) {
Himanshu Madhani012ec812013-08-21 11:24:10 -0400599 netif_tx_start_queue(tx_ring->txq);
Sony Chackod17dd0d2012-11-28 04:34:27 +0000600 } else {
Himanshu Madhanif27c75b2013-11-04 13:31:30 -0500601 tx_ring->tx_stats.xmit_off++;
Sony Chackoc70001a2012-11-28 04:34:26 +0000602 return NETDEV_TX_BUSY;
603 }
604 }
605
606 producer = tx_ring->producer;
607 pbuf = &tx_ring->cmd_buf_arr[producer];
Sony Chackoc70001a2012-11-28 04:34:26 +0000608 pdev = adapter->pdev;
Sony Chackod17dd0d2012-11-28 04:34:27 +0000609 first_desc = &tx_ring->desc_head[producer];
610 hwdesc = &tx_ring->desc_head[producer];
Sony Chackoc70001a2012-11-28 04:34:26 +0000611 qlcnic_clear_cmddesc((u64 *)hwdesc);
612
613 if (qlcnic_map_tx_skb(pdev, skb, pbuf)) {
614 adapter->stats.tx_dma_map_error++;
615 goto drop_packet;
616 }
617
618 pbuf->skb = skb;
619 pbuf->frag_count = frag_count;
620
621 qlcnic_set_tx_frags_len(first_desc, frag_count, skb->len);
622 qlcnic_set_tx_port(first_desc, adapter->portnum);
623
624 for (i = 0; i < frag_count; i++) {
Sony Chackoc70001a2012-11-28 04:34:26 +0000625 k = i % 4;
626
627 if ((k == 0) && (i > 0)) {
628 /* move to next desc.*/
629 producer = get_next_index(producer, num_txd);
630 hwdesc = &tx_ring->desc_head[producer];
631 qlcnic_clear_cmddesc((u64 *)hwdesc);
632 tx_ring->cmd_buf_arr[producer].skb = NULL;
633 }
634
635 buffrag = &pbuf->frag_array[i];
Sony Chackoc70001a2012-11-28 04:34:26 +0000636 hwdesc->buffer_length[k] = cpu_to_le16(buffrag->length);
637 switch (k) {
638 case 0:
639 hwdesc->addr_buffer1 = cpu_to_le64(buffrag->dma);
640 break;
641 case 1:
642 hwdesc->addr_buffer2 = cpu_to_le64(buffrag->dma);
643 break;
644 case 2:
645 hwdesc->addr_buffer3 = cpu_to_le64(buffrag->dma);
646 break;
647 case 3:
648 hwdesc->addr_buffer4 = cpu_to_le64(buffrag->dma);
649 break;
650 }
651 }
652
653 tx_ring->producer = get_next_index(producer, num_txd);
654 smp_mb();
655
Himanshu Madhani012ec812013-08-21 11:24:10 -0400656 if (unlikely(qlcnic_tx_pkt(adapter, first_desc, skb, tx_ring)))
Sony Chackoc70001a2012-11-28 04:34:26 +0000657 goto unwind_buff;
658
Jitendra Kalsariafe1adc62013-01-25 10:20:40 +0000659 if (adapter->drv_mac_learn)
Sony Chacko4be41e92013-01-01 03:20:20 +0000660 qlcnic_send_filter(adapter, first_desc, skb);
Sony Chackoc70001a2012-11-28 04:34:26 +0000661
Himanshu Madhanif27c75b2013-11-04 13:31:30 -0500662 tx_ring->tx_stats.tx_bytes += skb->len;
663 tx_ring->tx_stats.xmit_called++;
Sony Chackoc70001a2012-11-28 04:34:26 +0000664
665 qlcnic_update_cmd_producer(tx_ring);
666
667 return NETDEV_TX_OK;
668
669unwind_buff:
670 qlcnic_unmap_buffers(pdev, skb, pbuf);
671drop_packet:
672 adapter->stats.txdropped++;
673 dev_kfree_skb_any(skb);
674 return NETDEV_TX_OK;
675}
676
Sony Chacko7f9664522013-01-01 03:20:19 +0000677void qlcnic_advert_link_change(struct qlcnic_adapter *adapter, int linkup)
Sony Chackoc70001a2012-11-28 04:34:26 +0000678{
679 struct net_device *netdev = adapter->netdev;
680
681 if (adapter->ahw->linkup && !linkup) {
682 netdev_info(netdev, "NIC Link is down\n");
683 adapter->ahw->linkup = 0;
Himanshu Madhanib84caae2013-12-16 15:36:56 -0500684 netif_carrier_off(netdev);
Sony Chackoc70001a2012-11-28 04:34:26 +0000685 } else if (!adapter->ahw->linkup && linkup) {
Shahed Shaikh092dfcf2014-01-28 11:55:30 -0500686 adapter->ahw->linkup = 1;
687
688 /* Do not advertise Link up to the stack if device
689 * is in loopback mode
690 */
691 if (qlcnic_83xx_check(adapter) && adapter->ahw->lb_mode) {
692 netdev_info(netdev, "NIC Link is up for loopback test\n");
Manish Choprad9c602f2014-01-02 13:38:43 -0500693 return;
Shahed Shaikh092dfcf2014-01-28 11:55:30 -0500694 }
Manish Choprad9c602f2014-01-02 13:38:43 -0500695
Sony Chackoc70001a2012-11-28 04:34:26 +0000696 netdev_info(netdev, "NIC Link is up\n");
Himanshu Madhanib84caae2013-12-16 15:36:56 -0500697 netif_carrier_on(netdev);
Sony Chackoc70001a2012-11-28 04:34:26 +0000698 }
699}
700
Sony Chackod17dd0d2012-11-28 04:34:27 +0000701static int qlcnic_alloc_rx_skb(struct qlcnic_adapter *adapter,
702 struct qlcnic_host_rds_ring *rds_ring,
703 struct qlcnic_rx_buffer *buffer)
Sony Chackoc70001a2012-11-28 04:34:26 +0000704{
705 struct sk_buff *skb;
706 dma_addr_t dma;
707 struct pci_dev *pdev = adapter->pdev;
708
709 skb = netdev_alloc_skb(adapter->netdev, rds_ring->skb_size);
710 if (!skb) {
711 adapter->stats.skb_alloc_failure++;
712 return -ENOMEM;
713 }
714
715 skb_reserve(skb, NET_IP_ALIGN);
Sony Chacko4be41e92013-01-01 03:20:20 +0000716 dma = pci_map_single(pdev, skb->data,
717 rds_ring->dma_size, PCI_DMA_FROMDEVICE);
Sony Chackoc70001a2012-11-28 04:34:26 +0000718
719 if (pci_dma_mapping_error(pdev, dma)) {
720 adapter->stats.rx_dma_map_error++;
721 dev_kfree_skb_any(skb);
722 return -ENOMEM;
723 }
724
725 buffer->skb = skb;
726 buffer->dma = dma;
727
728 return 0;
729}
730
731static void qlcnic_post_rx_buffers_nodb(struct qlcnic_adapter *adapter,
Sony Chacko4be41e92013-01-01 03:20:20 +0000732 struct qlcnic_host_rds_ring *rds_ring,
733 u8 ring_id)
Sony Chackoc70001a2012-11-28 04:34:26 +0000734{
735 struct rcv_desc *pdesc;
736 struct qlcnic_rx_buffer *buffer;
737 int count = 0;
Sony Chacko4be41e92013-01-01 03:20:20 +0000738 uint32_t producer, handle;
Sony Chackoc70001a2012-11-28 04:34:26 +0000739 struct list_head *head;
740
741 if (!spin_trylock(&rds_ring->lock))
742 return;
743
744 producer = rds_ring->producer;
Sony Chackoc70001a2012-11-28 04:34:26 +0000745 head = &rds_ring->free_list;
Sony Chackod17dd0d2012-11-28 04:34:27 +0000746 while (!list_empty(head)) {
Sony Chackoc70001a2012-11-28 04:34:26 +0000747 buffer = list_entry(head->next, struct qlcnic_rx_buffer, list);
748
749 if (!buffer->skb) {
750 if (qlcnic_alloc_rx_skb(adapter, rds_ring, buffer))
751 break;
752 }
Sony Chackoc70001a2012-11-28 04:34:26 +0000753 count++;
754 list_del(&buffer->list);
755
756 /* make a rcv descriptor */
757 pdesc = &rds_ring->desc_head[producer];
Sony Chacko4be41e92013-01-01 03:20:20 +0000758 handle = qlcnic_get_ref_handle(adapter,
759 buffer->ref_handle, ring_id);
760 pdesc->reference_handle = cpu_to_le16(handle);
Sony Chackoc70001a2012-11-28 04:34:26 +0000761 pdesc->buffer_length = cpu_to_le32(rds_ring->dma_size);
762 pdesc->addr_buffer = cpu_to_le64(buffer->dma);
Sony Chackoc70001a2012-11-28 04:34:26 +0000763 producer = get_next_index(producer, rds_ring->num_desc);
764 }
Sony Chackoc70001a2012-11-28 04:34:26 +0000765 if (count) {
766 rds_ring->producer = producer;
767 writel((producer - 1) & (rds_ring->num_desc - 1),
Sony Chackod17dd0d2012-11-28 04:34:27 +0000768 rds_ring->crb_rcv_producer);
Sony Chackoc70001a2012-11-28 04:34:26 +0000769 }
770 spin_unlock(&rds_ring->lock);
771}
772
Sony Chacko4be41e92013-01-01 03:20:20 +0000773static int qlcnic_process_cmd_ring(struct qlcnic_adapter *adapter,
774 struct qlcnic_host_tx_ring *tx_ring,
775 int budget)
Sony Chackoc70001a2012-11-28 04:34:26 +0000776{
777 u32 sw_consumer, hw_consumer;
Sony Chackod17dd0d2012-11-28 04:34:27 +0000778 int i, done, count = 0;
Sony Chackoc70001a2012-11-28 04:34:26 +0000779 struct qlcnic_cmd_buffer *buffer;
780 struct pci_dev *pdev = adapter->pdev;
781 struct net_device *netdev = adapter->netdev;
782 struct qlcnic_skb_frag *frag;
Sony Chackoc70001a2012-11-28 04:34:26 +0000783
Shahed Shaikha02bdd42014-01-03 01:34:28 -0500784 if (!spin_trylock(&tx_ring->tx_clean_lock))
Himanshu Madhani34e8c402013-11-04 13:31:31 -0500785 return 1;
786
Sony Chackoc70001a2012-11-28 04:34:26 +0000787 sw_consumer = tx_ring->sw_consumer;
788 hw_consumer = le32_to_cpu(*(tx_ring->hw_consumer));
789
790 while (sw_consumer != hw_consumer) {
791 buffer = &tx_ring->cmd_buf_arr[sw_consumer];
792 if (buffer->skb) {
793 frag = &buffer->frag_array[0];
794 pci_unmap_single(pdev, frag->dma, frag->length,
795 PCI_DMA_TODEVICE);
796 frag->dma = 0ULL;
797 for (i = 1; i < buffer->frag_count; i++) {
798 frag++;
799 pci_unmap_page(pdev, frag->dma, frag->length,
800 PCI_DMA_TODEVICE);
801 frag->dma = 0ULL;
802 }
Himanshu Madhanif27c75b2013-11-04 13:31:30 -0500803 tx_ring->tx_stats.xmit_finished++;
Sony Chackoc70001a2012-11-28 04:34:26 +0000804 dev_kfree_skb_any(buffer->skb);
805 buffer->skb = NULL;
806 }
807
808 sw_consumer = get_next_index(sw_consumer, tx_ring->num_desc);
Sony Chacko4be41e92013-01-01 03:20:20 +0000809 if (++count >= budget)
Sony Chackoc70001a2012-11-28 04:34:26 +0000810 break;
811 }
812
Shahed Shaikha02bdd42014-01-03 01:34:28 -0500813 tx_ring->sw_consumer = sw_consumer;
814
Sony Chackoc70001a2012-11-28 04:34:26 +0000815 if (count && netif_running(netdev)) {
Sony Chackoc70001a2012-11-28 04:34:26 +0000816 smp_mb();
Himanshu Madhani012ec812013-08-21 11:24:10 -0400817 if (netif_tx_queue_stopped(tx_ring->txq) &&
818 netif_carrier_ok(netdev)) {
Sony Chackoc70001a2012-11-28 04:34:26 +0000819 if (qlcnic_tx_avail(tx_ring) > TX_STOP_THRESH) {
Himanshu Madhani012ec812013-08-21 11:24:10 -0400820 netif_tx_wake_queue(tx_ring->txq);
Himanshu Madhanif27c75b2013-11-04 13:31:30 -0500821 tx_ring->tx_stats.xmit_on++;
Sony Chackoc70001a2012-11-28 04:34:26 +0000822 }
823 }
824 adapter->tx_timeo_cnt = 0;
825 }
826 /*
827 * If everything is freed up to consumer then check if the ring is full
828 * If the ring is full then check if more needs to be freed and
829 * schedule the call back again.
830 *
831 * This happens when there are 2 CPUs. One could be freeing and the
832 * other filling it. If the ring is full when we get out of here and
833 * the card has already interrupted the host then the host can miss the
834 * interrupt.
835 *
836 * There is still a possible race condition and the host could miss an
837 * interrupt. The card has to take care of this.
838 */
839 hw_consumer = le32_to_cpu(*(tx_ring->hw_consumer));
840 done = (sw_consumer == hw_consumer);
Shahed Shaikha02bdd42014-01-03 01:34:28 -0500841
842 spin_unlock(&tx_ring->tx_clean_lock);
Sony Chackoc70001a2012-11-28 04:34:26 +0000843
844 return done;
845}
846
847static int qlcnic_poll(struct napi_struct *napi, int budget)
848{
Sony Chacko4be41e92013-01-01 03:20:20 +0000849 int tx_complete, work_done;
Sony Chackod17dd0d2012-11-28 04:34:27 +0000850 struct qlcnic_host_sds_ring *sds_ring;
851 struct qlcnic_adapter *adapter;
Himanshu Madhani012ec812013-08-21 11:24:10 -0400852 struct qlcnic_host_tx_ring *tx_ring;
Sony Chackoc70001a2012-11-28 04:34:26 +0000853
Sony Chackod17dd0d2012-11-28 04:34:27 +0000854 sds_ring = container_of(napi, struct qlcnic_host_sds_ring, napi);
855 adapter = sds_ring->adapter;
Himanshu Madhani012ec812013-08-21 11:24:10 -0400856 tx_ring = sds_ring->tx_ring;
857
858 tx_complete = qlcnic_process_cmd_ring(adapter, tx_ring,
Sony Chacko4be41e92013-01-01 03:20:20 +0000859 budget);
Sony Chackoc70001a2012-11-28 04:34:26 +0000860 work_done = qlcnic_process_rcv_ring(sds_ring, budget);
Sony Chackoc70001a2012-11-28 04:34:26 +0000861 if ((work_done < budget) && tx_complete) {
862 napi_complete(&sds_ring->napi);
Himanshu Madhani012ec812013-08-21 11:24:10 -0400863 if (test_bit(__QLCNIC_DEV_UP, &adapter->state)) {
Manish chopra2cc57522014-01-23 17:18:30 -0500864 qlcnic_enable_sds_intr(adapter, sds_ring);
Himanshu Madhani012ec812013-08-21 11:24:10 -0400865 qlcnic_enable_tx_intr(adapter, tx_ring);
866 }
867 }
868
869 return work_done;
870}
871
872static int qlcnic_tx_poll(struct napi_struct *napi, int budget)
873{
874 struct qlcnic_host_tx_ring *tx_ring;
875 struct qlcnic_adapter *adapter;
876 int work_done;
877
878 tx_ring = container_of(napi, struct qlcnic_host_tx_ring, napi);
879 adapter = tx_ring->adapter;
880
881 work_done = qlcnic_process_cmd_ring(adapter, tx_ring, budget);
882 if (work_done) {
883 napi_complete(&tx_ring->napi);
884 if (test_bit(__QLCNIC_DEV_UP, &adapter->state))
885 qlcnic_enable_tx_intr(adapter, tx_ring);
Sony Chackoc70001a2012-11-28 04:34:26 +0000886 }
887
888 return work_done;
889}
890
891static int qlcnic_rx_poll(struct napi_struct *napi, int budget)
892{
Sony Chackod17dd0d2012-11-28 04:34:27 +0000893 struct qlcnic_host_sds_ring *sds_ring;
894 struct qlcnic_adapter *adapter;
Sony Chackoc70001a2012-11-28 04:34:26 +0000895 int work_done;
896
Sony Chackod17dd0d2012-11-28 04:34:27 +0000897 sds_ring = container_of(napi, struct qlcnic_host_sds_ring, napi);
898 adapter = sds_ring->adapter;
899
Sony Chackoc70001a2012-11-28 04:34:26 +0000900 work_done = qlcnic_process_rcv_ring(sds_ring, budget);
901
902 if (work_done < budget) {
903 napi_complete(&sds_ring->napi);
904 if (test_bit(__QLCNIC_DEV_UP, &adapter->state))
Manish chopra2cc57522014-01-23 17:18:30 -0500905 qlcnic_enable_sds_intr(adapter, sds_ring);
Sony Chackoc70001a2012-11-28 04:34:26 +0000906 }
907
908 return work_done;
909}
910
Sony Chackod17dd0d2012-11-28 04:34:27 +0000911static void qlcnic_handle_linkevent(struct qlcnic_adapter *adapter,
912 struct qlcnic_fw_msg *msg)
Sony Chackoc70001a2012-11-28 04:34:26 +0000913{
914 u32 cable_OUI;
Sony Chackod17dd0d2012-11-28 04:34:27 +0000915 u16 cable_len, link_speed;
916 u8 link_status, module, duplex, autoneg, lb_status = 0;
Sony Chackoc70001a2012-11-28 04:34:26 +0000917 struct net_device *netdev = adapter->netdev;
918
Sony Chacko79788452012-12-04 03:33:53 +0000919 adapter->ahw->has_link_events = 1;
Sony Chackoc70001a2012-11-28 04:34:26 +0000920
921 cable_OUI = msg->body[1] & 0xffffffff;
922 cable_len = (msg->body[1] >> 32) & 0xffff;
923 link_speed = (msg->body[1] >> 48) & 0xffff;
924
925 link_status = msg->body[2] & 0xff;
926 duplex = (msg->body[2] >> 16) & 0xff;
927 autoneg = (msg->body[2] >> 24) & 0xff;
928 lb_status = (msg->body[2] >> 32) & 0x3;
929
930 module = (msg->body[2] >> 8) & 0xff;
931 if (module == LINKEVENT_MODULE_TWINAX_UNSUPPORTED_CABLE)
Sony Chackod17dd0d2012-11-28 04:34:27 +0000932 dev_info(&netdev->dev,
933 "unsupported cable: OUI 0x%x, length %d\n",
934 cable_OUI, cable_len);
Sony Chackoc70001a2012-11-28 04:34:26 +0000935 else if (module == LINKEVENT_MODULE_TWINAX_UNSUPPORTED_CABLELEN)
936 dev_info(&netdev->dev, "unsupported cable length %d\n",
Sony Chackod17dd0d2012-11-28 04:34:27 +0000937 cable_len);
Sony Chackoc70001a2012-11-28 04:34:26 +0000938
939 if (!link_status && (lb_status == QLCNIC_ILB_MODE ||
940 lb_status == QLCNIC_ELB_MODE))
941 adapter->ahw->loopback_state |= QLCNIC_LINKEVENT;
942
943 qlcnic_advert_link_change(adapter, link_status);
944
945 if (duplex == LINKEVENT_FULL_DUPLEX)
Sony Chacko79788452012-12-04 03:33:53 +0000946 adapter->ahw->link_duplex = DUPLEX_FULL;
Sony Chackoc70001a2012-11-28 04:34:26 +0000947 else
Sony Chacko79788452012-12-04 03:33:53 +0000948 adapter->ahw->link_duplex = DUPLEX_HALF;
Sony Chackoc70001a2012-11-28 04:34:26 +0000949
Sony Chacko79788452012-12-04 03:33:53 +0000950 adapter->ahw->module_type = module;
951 adapter->ahw->link_autoneg = autoneg;
Sony Chackoc70001a2012-11-28 04:34:26 +0000952
953 if (link_status) {
Sony Chacko79788452012-12-04 03:33:53 +0000954 adapter->ahw->link_speed = link_speed;
Sony Chackoc70001a2012-11-28 04:34:26 +0000955 } else {
Sony Chacko79788452012-12-04 03:33:53 +0000956 adapter->ahw->link_speed = SPEED_UNKNOWN;
957 adapter->ahw->link_duplex = DUPLEX_UNKNOWN;
Sony Chackoc70001a2012-11-28 04:34:26 +0000958 }
959}
960
Sony Chackod17dd0d2012-11-28 04:34:27 +0000961static void qlcnic_handle_fw_message(int desc_cnt, int index,
962 struct qlcnic_host_sds_ring *sds_ring)
Sony Chackoc70001a2012-11-28 04:34:26 +0000963{
964 struct qlcnic_fw_msg msg;
965 struct status_desc *desc;
966 struct qlcnic_adapter *adapter;
967 struct device *dev;
968 int i = 0, opcode, ret;
969
970 while (desc_cnt > 0 && i < 8) {
971 desc = &sds_ring->desc_head[index];
972 msg.words[i++] = le64_to_cpu(desc->status_desc_data[0]);
973 msg.words[i++] = le64_to_cpu(desc->status_desc_data[1]);
974
975 index = get_next_index(index, sds_ring->num_desc);
976 desc_cnt--;
977 }
978
979 adapter = sds_ring->adapter;
980 dev = &adapter->pdev->dev;
981 opcode = qlcnic_get_nic_msg_opcode(msg.body[0]);
982
983 switch (opcode) {
984 case QLCNIC_C2H_OPCODE_GET_LINKEVENT_RESPONSE:
985 qlcnic_handle_linkevent(adapter, &msg);
986 break;
987 case QLCNIC_C2H_OPCODE_CONFIG_LOOPBACK:
988 ret = (u32)(msg.body[1]);
989 switch (ret) {
990 case 0:
991 adapter->ahw->loopback_state |= QLCNIC_LB_RESPONSE;
992 break;
993 case 1:
994 dev_info(dev, "loopback already in progress\n");
Jitendra Kalsariab9c11982013-08-02 00:57:39 -0400995 adapter->ahw->diag_cnt = -EINPROGRESS;
Sony Chackoc70001a2012-11-28 04:34:26 +0000996 break;
997 case 2:
998 dev_info(dev, "loopback cable is not connected\n");
Jitendra Kalsariab9c11982013-08-02 00:57:39 -0400999 adapter->ahw->diag_cnt = -ENODEV;
Sony Chackoc70001a2012-11-28 04:34:26 +00001000 break;
1001 default:
Sony Chackod17dd0d2012-11-28 04:34:27 +00001002 dev_info(dev,
1003 "loopback configure request failed, err %x\n",
1004 ret);
Jitendra Kalsariab9c11982013-08-02 00:57:39 -04001005 adapter->ahw->diag_cnt = -EIO;
Sony Chackoc70001a2012-11-28 04:34:26 +00001006 break;
1007 }
1008 break;
Sucheta Chakraborty2d8ebca2013-08-23 13:38:27 -04001009 case QLCNIC_C2H_OPCODE_GET_DCB_AEN:
Sucheta Chakraborty1de899d2013-10-18 12:22:33 -04001010 qlcnic_dcb_aen_handler(adapter->dcb, (void *)&msg);
Sucheta Chakraborty2d8ebca2013-08-23 13:38:27 -04001011 break;
Sony Chackoc70001a2012-11-28 04:34:26 +00001012 default:
1013 break;
1014 }
1015}
1016
stephen hemminger21041402014-01-16 10:31:27 -08001017static struct sk_buff *qlcnic_process_rxbuf(struct qlcnic_adapter *adapter,
1018 struct qlcnic_host_rds_ring *ring,
1019 u16 index, u16 cksum)
Sony Chackoc70001a2012-11-28 04:34:26 +00001020{
1021 struct qlcnic_rx_buffer *buffer;
1022 struct sk_buff *skb;
1023
Sony Chacko4be41e92013-01-01 03:20:20 +00001024 buffer = &ring->rx_buf_arr[index];
Sony Chackoc70001a2012-11-28 04:34:26 +00001025 if (unlikely(buffer->skb == NULL)) {
1026 WARN_ON(1);
1027 return NULL;
1028 }
1029
Sony Chacko4be41e92013-01-01 03:20:20 +00001030 pci_unmap_single(adapter->pdev, buffer->dma, ring->dma_size,
Sony Chackod17dd0d2012-11-28 04:34:27 +00001031 PCI_DMA_FROMDEVICE);
Sony Chackoc70001a2012-11-28 04:34:26 +00001032
1033 skb = buffer->skb;
Sony Chackoc70001a2012-11-28 04:34:26 +00001034 if (likely((adapter->netdev->features & NETIF_F_RXCSUM) &&
Sony Chackod17dd0d2012-11-28 04:34:27 +00001035 (cksum == STATUS_CKSUM_OK || cksum == STATUS_CKSUM_LOOP))) {
Sony Chackoc70001a2012-11-28 04:34:26 +00001036 adapter->stats.csummed++;
1037 skb->ip_summed = CHECKSUM_UNNECESSARY;
1038 } else {
1039 skb_checksum_none_assert(skb);
1040 }
1041
Sony Chacko4be41e92013-01-01 03:20:20 +00001042
Sony Chackoc70001a2012-11-28 04:34:26 +00001043 buffer->skb = NULL;
1044
1045 return skb;
1046}
1047
Sony Chackod17dd0d2012-11-28 04:34:27 +00001048static inline int qlcnic_check_rx_tagging(struct qlcnic_adapter *adapter,
1049 struct sk_buff *skb, u16 *vlan_tag)
Sony Chackoc70001a2012-11-28 04:34:26 +00001050{
1051 struct ethhdr *eth_hdr;
1052
1053 if (!__vlan_get_tag(skb, vlan_tag)) {
Sony Chackod17dd0d2012-11-28 04:34:27 +00001054 eth_hdr = (struct ethhdr *)skb->data;
Sony Chackoc70001a2012-11-28 04:34:26 +00001055 memmove(skb->data + VLAN_HLEN, eth_hdr, ETH_ALEN * 2);
1056 skb_pull(skb, VLAN_HLEN);
1057 }
Rajesh Borundia91b72822013-04-19 07:01:12 +00001058 if (!adapter->rx_pvid)
Sony Chackoc70001a2012-11-28 04:34:26 +00001059 return 0;
1060
Rajesh Borundia91b72822013-04-19 07:01:12 +00001061 if (*vlan_tag == adapter->rx_pvid) {
Sony Chackoc70001a2012-11-28 04:34:26 +00001062 /* Outer vlan tag. Packet should follow non-vlan path */
1063 *vlan_tag = 0xffff;
1064 return 0;
1065 }
1066 if (adapter->flags & QLCNIC_TAGGING_ENABLED)
1067 return 0;
1068
1069 return -EINVAL;
1070}
1071
1072static struct qlcnic_rx_buffer *
1073qlcnic_process_rcv(struct qlcnic_adapter *adapter,
Sony Chackod17dd0d2012-11-28 04:34:27 +00001074 struct qlcnic_host_sds_ring *sds_ring, int ring,
1075 u64 sts_data0)
Sony Chackoc70001a2012-11-28 04:34:26 +00001076{
1077 struct net_device *netdev = adapter->netdev;
1078 struct qlcnic_recv_context *recv_ctx = adapter->recv_ctx;
1079 struct qlcnic_rx_buffer *buffer;
1080 struct sk_buff *skb;
1081 struct qlcnic_host_rds_ring *rds_ring;
Shahed Shaikh53643a72013-02-18 13:22:37 +00001082 int index, length, cksum, pkt_offset, is_lb_pkt;
1083 u16 vid = 0xffff, t_vid;
Sony Chackoc70001a2012-11-28 04:34:26 +00001084
1085 if (unlikely(ring >= adapter->max_rds_rings))
1086 return NULL;
1087
1088 rds_ring = &recv_ctx->rds_rings[ring];
1089
1090 index = qlcnic_get_sts_refhandle(sts_data0);
1091 if (unlikely(index >= rds_ring->num_desc))
1092 return NULL;
1093
1094 buffer = &rds_ring->rx_buf_arr[index];
Sony Chackoc70001a2012-11-28 04:34:26 +00001095 length = qlcnic_get_sts_totallength(sts_data0);
1096 cksum = qlcnic_get_sts_status(sts_data0);
1097 pkt_offset = qlcnic_get_sts_pkt_offset(sts_data0);
1098
1099 skb = qlcnic_process_rxbuf(adapter, rds_ring, index, cksum);
1100 if (!skb)
1101 return buffer;
1102
Shahed Shaikh53643a72013-02-18 13:22:37 +00001103 if (adapter->drv_mac_learn &&
1104 (adapter->flags & QLCNIC_ESWITCH_ENABLED)) {
1105 t_vid = 0;
1106 is_lb_pkt = qlcnic_82xx_is_lb_pkt(sts_data0);
Rajesh Borundiaf80bc8f2013-04-19 07:01:08 +00001107 qlcnic_add_lb_filter(adapter, skb, is_lb_pkt, t_vid);
Shahed Shaikh53643a72013-02-18 13:22:37 +00001108 }
1109
Sony Chackoc70001a2012-11-28 04:34:26 +00001110 if (length > rds_ring->skb_size)
1111 skb_put(skb, rds_ring->skb_size);
1112 else
1113 skb_put(skb, length);
1114
1115 if (pkt_offset)
1116 skb_pull(skb, pkt_offset);
1117
1118 if (unlikely(qlcnic_check_rx_tagging(adapter, skb, &vid))) {
1119 adapter->stats.rxdropped++;
1120 dev_kfree_skb(skb);
1121 return buffer;
1122 }
1123
1124 skb->protocol = eth_type_trans(skb, netdev);
1125
1126 if (vid != 0xffff)
Patrick McHardy86a9bad2013-04-19 02:04:30 +00001127 __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q), vid);
Sony Chackoc70001a2012-11-28 04:34:26 +00001128
1129 napi_gro_receive(&sds_ring->napi, skb);
1130
1131 adapter->stats.rx_pkts++;
1132 adapter->stats.rxbytes += length;
1133
1134 return buffer;
1135}
1136
1137#define QLC_TCP_HDR_SIZE 20
1138#define QLC_TCP_TS_OPTION_SIZE 12
1139#define QLC_TCP_TS_HDR_SIZE (QLC_TCP_HDR_SIZE + QLC_TCP_TS_OPTION_SIZE)
1140
1141static struct qlcnic_rx_buffer *
1142qlcnic_process_lro(struct qlcnic_adapter *adapter,
Sony Chackod17dd0d2012-11-28 04:34:27 +00001143 int ring, u64 sts_data0, u64 sts_data1)
Sony Chackoc70001a2012-11-28 04:34:26 +00001144{
1145 struct net_device *netdev = adapter->netdev;
1146 struct qlcnic_recv_context *recv_ctx = adapter->recv_ctx;
1147 struct qlcnic_rx_buffer *buffer;
1148 struct sk_buff *skb;
1149 struct qlcnic_host_rds_ring *rds_ring;
1150 struct iphdr *iph;
Shahed Shaikh776e7bd2013-01-25 10:20:35 +00001151 struct ipv6hdr *ipv6h;
Sony Chackoc70001a2012-11-28 04:34:26 +00001152 struct tcphdr *th;
1153 bool push, timestamp;
Shahed Shaikh53643a72013-02-18 13:22:37 +00001154 int index, l2_hdr_offset, l4_hdr_offset, is_lb_pkt;
1155 u16 lro_length, length, data_offset, t_vid, vid = 0xffff;
Sony Chackoc70001a2012-11-28 04:34:26 +00001156 u32 seq_number;
Sony Chackoc70001a2012-11-28 04:34:26 +00001157
Manish Chopra462bed42014-01-28 11:55:27 -05001158 if (unlikely(ring >= adapter->max_rds_rings))
Sony Chackoc70001a2012-11-28 04:34:26 +00001159 return NULL;
1160
1161 rds_ring = &recv_ctx->rds_rings[ring];
1162
1163 index = qlcnic_get_lro_sts_refhandle(sts_data0);
Manish Chopra462bed42014-01-28 11:55:27 -05001164 if (unlikely(index >= rds_ring->num_desc))
Sony Chackoc70001a2012-11-28 04:34:26 +00001165 return NULL;
1166
1167 buffer = &rds_ring->rx_buf_arr[index];
1168
1169 timestamp = qlcnic_get_lro_sts_timestamp(sts_data0);
1170 lro_length = qlcnic_get_lro_sts_length(sts_data0);
1171 l2_hdr_offset = qlcnic_get_lro_sts_l2_hdr_offset(sts_data0);
1172 l4_hdr_offset = qlcnic_get_lro_sts_l4_hdr_offset(sts_data0);
1173 push = qlcnic_get_lro_sts_push_flag(sts_data0);
1174 seq_number = qlcnic_get_lro_sts_seq_number(sts_data1);
1175
1176 skb = qlcnic_process_rxbuf(adapter, rds_ring, index, STATUS_CKSUM_OK);
1177 if (!skb)
1178 return buffer;
1179
Shahed Shaikh53643a72013-02-18 13:22:37 +00001180 if (adapter->drv_mac_learn &&
1181 (adapter->flags & QLCNIC_ESWITCH_ENABLED)) {
1182 t_vid = 0;
1183 is_lb_pkt = qlcnic_82xx_is_lb_pkt(sts_data0);
Rajesh Borundiaf80bc8f2013-04-19 07:01:08 +00001184 qlcnic_add_lb_filter(adapter, skb, is_lb_pkt, t_vid);
Shahed Shaikh53643a72013-02-18 13:22:37 +00001185 }
1186
Sony Chackoc70001a2012-11-28 04:34:26 +00001187 if (timestamp)
1188 data_offset = l4_hdr_offset + QLC_TCP_TS_HDR_SIZE;
1189 else
1190 data_offset = l4_hdr_offset + QLC_TCP_HDR_SIZE;
1191
1192 skb_put(skb, lro_length + data_offset);
Sony Chackoc70001a2012-11-28 04:34:26 +00001193 skb_pull(skb, l2_hdr_offset);
1194
1195 if (unlikely(qlcnic_check_rx_tagging(adapter, skb, &vid))) {
1196 adapter->stats.rxdropped++;
1197 dev_kfree_skb(skb);
1198 return buffer;
1199 }
1200
1201 skb->protocol = eth_type_trans(skb, netdev);
Shahed Shaikh776e7bd2013-01-25 10:20:35 +00001202
Shahed Shaikh069048f2013-01-30 12:47:12 +00001203 if (ntohs(skb->protocol) == ETH_P_IPV6) {
Shahed Shaikh776e7bd2013-01-25 10:20:35 +00001204 ipv6h = (struct ipv6hdr *)skb->data;
1205 th = (struct tcphdr *)(skb->data + sizeof(struct ipv6hdr));
1206 length = (th->doff << 2) + lro_length;
1207 ipv6h->payload_len = htons(length);
1208 } else {
1209 iph = (struct iphdr *)skb->data;
1210 th = (struct tcphdr *)(skb->data + (iph->ihl << 2));
1211 length = (iph->ihl << 2) + (th->doff << 2) + lro_length;
Li RongQing1bcac3b2013-03-14 22:50:07 +00001212 csum_replace2(&iph->check, iph->tot_len, htons(length));
Shahed Shaikh776e7bd2013-01-25 10:20:35 +00001213 iph->tot_len = htons(length);
Shahed Shaikh776e7bd2013-01-25 10:20:35 +00001214 }
1215
Sony Chackoc70001a2012-11-28 04:34:26 +00001216 th->psh = push;
1217 th->seq = htonl(seq_number);
Sony Chackoc70001a2012-11-28 04:34:26 +00001218 length = skb->len;
1219
Michael S. Tsirkinbd69ba72013-02-07 03:13:13 +00001220 if (adapter->flags & QLCNIC_FW_LRO_MSS_CAP) {
Sony Chackoc70001a2012-11-28 04:34:26 +00001221 skb_shinfo(skb)->gso_size = qlcnic_get_lro_sts_mss(sts_data1);
Michael S. Tsirkinbd69ba72013-02-07 03:13:13 +00001222 if (skb->protocol == htons(ETH_P_IPV6))
1223 skb_shinfo(skb)->gso_type = SKB_GSO_TCPV6;
1224 else
1225 skb_shinfo(skb)->gso_type = SKB_GSO_TCPV4;
1226 }
Sony Chackoc70001a2012-11-28 04:34:26 +00001227
1228 if (vid != 0xffff)
Patrick McHardy86a9bad2013-04-19 02:04:30 +00001229 __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q), vid);
Sony Chackoc70001a2012-11-28 04:34:26 +00001230 netif_receive_skb(skb);
1231
1232 adapter->stats.lro_pkts++;
1233 adapter->stats.lrobytes += length;
1234
1235 return buffer;
1236}
1237
stephen hemminger21041402014-01-16 10:31:27 -08001238static int qlcnic_process_rcv_ring(struct qlcnic_host_sds_ring *sds_ring, int max)
Sony Chackoc70001a2012-11-28 04:34:26 +00001239{
Sony Chackod17dd0d2012-11-28 04:34:27 +00001240 struct qlcnic_host_rds_ring *rds_ring;
Sony Chackoc70001a2012-11-28 04:34:26 +00001241 struct qlcnic_adapter *adapter = sds_ring->adapter;
1242 struct list_head *cur;
1243 struct status_desc *desc;
1244 struct qlcnic_rx_buffer *rxbuf;
Sony Chacko4be41e92013-01-01 03:20:20 +00001245 int opcode, desc_cnt, count = 0;
Sony Chackoc70001a2012-11-28 04:34:26 +00001246 u64 sts_data0, sts_data1;
Sony Chacko4be41e92013-01-01 03:20:20 +00001247 u8 ring;
Sony Chackoc70001a2012-11-28 04:34:26 +00001248 u32 consumer = sds_ring->consumer;
1249
1250 while (count < max) {
1251 desc = &sds_ring->desc_head[consumer];
1252 sts_data0 = le64_to_cpu(desc->status_desc_data[0]);
1253
1254 if (!(sts_data0 & STATUS_OWNER_HOST))
1255 break;
1256
1257 desc_cnt = qlcnic_get_sts_desc_cnt(sts_data0);
1258 opcode = qlcnic_get_sts_opcode(sts_data0);
Sony Chackoc70001a2012-11-28 04:34:26 +00001259 switch (opcode) {
1260 case QLCNIC_RXPKT_DESC:
1261 case QLCNIC_OLD_RXPKT_DESC:
1262 case QLCNIC_SYN_OFFLOAD:
1263 ring = qlcnic_get_sts_type(sts_data0);
Sony Chackod17dd0d2012-11-28 04:34:27 +00001264 rxbuf = qlcnic_process_rcv(adapter, sds_ring, ring,
1265 sts_data0);
Sony Chackoc70001a2012-11-28 04:34:26 +00001266 break;
1267 case QLCNIC_LRO_DESC:
1268 ring = qlcnic_get_lro_sts_type(sts_data0);
1269 sts_data1 = le64_to_cpu(desc->status_desc_data[1]);
1270 rxbuf = qlcnic_process_lro(adapter, ring, sts_data0,
1271 sts_data1);
1272 break;
1273 case QLCNIC_RESPONSE_DESC:
1274 qlcnic_handle_fw_message(desc_cnt, consumer, sds_ring);
1275 default:
1276 goto skip;
1277 }
Sony Chackoc70001a2012-11-28 04:34:26 +00001278 WARN_ON(desc_cnt > 1);
1279
1280 if (likely(rxbuf))
1281 list_add_tail(&rxbuf->list, &sds_ring->free_list[ring]);
1282 else
1283 adapter->stats.null_rxbuf++;
Sony Chackoc70001a2012-11-28 04:34:26 +00001284skip:
1285 for (; desc_cnt > 0; desc_cnt--) {
1286 desc = &sds_ring->desc_head[consumer];
Sony Chacko4be41e92013-01-01 03:20:20 +00001287 desc->status_desc_data[0] = QLCNIC_DESC_OWNER_FW;
Sony Chackoc70001a2012-11-28 04:34:26 +00001288 consumer = get_next_index(consumer, sds_ring->num_desc);
1289 }
1290 count++;
1291 }
1292
1293 for (ring = 0; ring < adapter->max_rds_rings; ring++) {
Sony Chackod17dd0d2012-11-28 04:34:27 +00001294 rds_ring = &adapter->recv_ctx->rds_rings[ring];
Sony Chackoc70001a2012-11-28 04:34:26 +00001295 if (!list_empty(&sds_ring->free_list[ring])) {
1296 list_for_each(cur, &sds_ring->free_list[ring]) {
Sony Chackod17dd0d2012-11-28 04:34:27 +00001297 rxbuf = list_entry(cur, struct qlcnic_rx_buffer,
1298 list);
Sony Chackoc70001a2012-11-28 04:34:26 +00001299 qlcnic_alloc_rx_skb(adapter, rds_ring, rxbuf);
1300 }
1301 spin_lock(&rds_ring->lock);
1302 list_splice_tail_init(&sds_ring->free_list[ring],
Sony Chackod17dd0d2012-11-28 04:34:27 +00001303 &rds_ring->free_list);
Sony Chackoc70001a2012-11-28 04:34:26 +00001304 spin_unlock(&rds_ring->lock);
1305 }
1306
Sony Chacko4be41e92013-01-01 03:20:20 +00001307 qlcnic_post_rx_buffers_nodb(adapter, rds_ring, ring);
Sony Chackoc70001a2012-11-28 04:34:26 +00001308 }
1309
1310 if (count) {
1311 sds_ring->consumer = consumer;
1312 writel(consumer, sds_ring->crb_sts_consumer);
1313 }
1314
1315 return count;
1316}
1317
Sony Chackod17dd0d2012-11-28 04:34:27 +00001318void qlcnic_post_rx_buffers(struct qlcnic_adapter *adapter,
Sony Chacko4be41e92013-01-01 03:20:20 +00001319 struct qlcnic_host_rds_ring *rds_ring, u8 ring_id)
Sony Chackoc70001a2012-11-28 04:34:26 +00001320{
1321 struct rcv_desc *pdesc;
1322 struct qlcnic_rx_buffer *buffer;
1323 int count = 0;
Sony Chacko4be41e92013-01-01 03:20:20 +00001324 u32 producer, handle;
Sony Chackoc70001a2012-11-28 04:34:26 +00001325 struct list_head *head;
1326
1327 producer = rds_ring->producer;
Sony Chackoc70001a2012-11-28 04:34:26 +00001328 head = &rds_ring->free_list;
Sony Chackod17dd0d2012-11-28 04:34:27 +00001329
Sony Chackoc70001a2012-11-28 04:34:26 +00001330 while (!list_empty(head)) {
1331
1332 buffer = list_entry(head->next, struct qlcnic_rx_buffer, list);
1333
1334 if (!buffer->skb) {
1335 if (qlcnic_alloc_rx_skb(adapter, rds_ring, buffer))
1336 break;
1337 }
1338
1339 count++;
1340 list_del(&buffer->list);
1341
1342 /* make a rcv descriptor */
1343 pdesc = &rds_ring->desc_head[producer];
1344 pdesc->addr_buffer = cpu_to_le64(buffer->dma);
Sony Chacko4be41e92013-01-01 03:20:20 +00001345 handle = qlcnic_get_ref_handle(adapter, buffer->ref_handle,
1346 ring_id);
1347 pdesc->reference_handle = cpu_to_le16(handle);
Sony Chackoc70001a2012-11-28 04:34:26 +00001348 pdesc->buffer_length = cpu_to_le32(rds_ring->dma_size);
Sony Chackoc70001a2012-11-28 04:34:26 +00001349 producer = get_next_index(producer, rds_ring->num_desc);
1350 }
1351
1352 if (count) {
1353 rds_ring->producer = producer;
1354 writel((producer-1) & (rds_ring->num_desc-1),
Sony Chackod17dd0d2012-11-28 04:34:27 +00001355 rds_ring->crb_rcv_producer);
Sony Chackoc70001a2012-11-28 04:34:26 +00001356 }
1357}
1358
1359static void dump_skb(struct sk_buff *skb, struct qlcnic_adapter *adapter)
1360{
1361 int i;
1362 unsigned char *data = skb->data;
1363
Sony Chackod17dd0d2012-11-28 04:34:27 +00001364 pr_info(KERN_INFO "\n");
Sony Chackoc70001a2012-11-28 04:34:26 +00001365 for (i = 0; i < skb->len; i++) {
1366 QLCDB(adapter, DRV, "%02x ", data[i]);
1367 if ((i & 0x0f) == 8)
Sony Chackod17dd0d2012-11-28 04:34:27 +00001368 pr_info(KERN_INFO "\n");
Sony Chackoc70001a2012-11-28 04:34:26 +00001369 }
1370}
1371
1372static void qlcnic_process_rcv_diag(struct qlcnic_adapter *adapter, int ring,
1373 u64 sts_data0)
1374{
1375 struct qlcnic_recv_context *recv_ctx = adapter->recv_ctx;
1376 struct sk_buff *skb;
1377 struct qlcnic_host_rds_ring *rds_ring;
1378 int index, length, cksum, pkt_offset;
1379
1380 if (unlikely(ring >= adapter->max_rds_rings))
1381 return;
1382
1383 rds_ring = &recv_ctx->rds_rings[ring];
1384
1385 index = qlcnic_get_sts_refhandle(sts_data0);
1386 length = qlcnic_get_sts_totallength(sts_data0);
1387 if (unlikely(index >= rds_ring->num_desc))
1388 return;
1389
1390 cksum = qlcnic_get_sts_status(sts_data0);
1391 pkt_offset = qlcnic_get_sts_pkt_offset(sts_data0);
1392
1393 skb = qlcnic_process_rxbuf(adapter, rds_ring, index, cksum);
1394 if (!skb)
1395 return;
1396
1397 if (length > rds_ring->skb_size)
1398 skb_put(skb, rds_ring->skb_size);
1399 else
1400 skb_put(skb, length);
1401
1402 if (pkt_offset)
1403 skb_pull(skb, pkt_offset);
1404
1405 if (!qlcnic_check_loopback_buff(skb->data, adapter->mac_addr))
Sony Chacko79788452012-12-04 03:33:53 +00001406 adapter->ahw->diag_cnt++;
Sony Chackoc70001a2012-11-28 04:34:26 +00001407 else
1408 dump_skb(skb, adapter);
1409
1410 dev_kfree_skb_any(skb);
1411 adapter->stats.rx_pkts++;
1412 adapter->stats.rxbytes += length;
1413
1414 return;
1415}
1416
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00001417void qlcnic_82xx_process_rcv_ring_diag(struct qlcnic_host_sds_ring *sds_ring)
Sony Chackoc70001a2012-11-28 04:34:26 +00001418{
1419 struct qlcnic_adapter *adapter = sds_ring->adapter;
1420 struct status_desc *desc;
1421 u64 sts_data0;
1422 int ring, opcode, desc_cnt;
1423
1424 u32 consumer = sds_ring->consumer;
1425
1426 desc = &sds_ring->desc_head[consumer];
1427 sts_data0 = le64_to_cpu(desc->status_desc_data[0]);
1428
1429 if (!(sts_data0 & STATUS_OWNER_HOST))
1430 return;
1431
1432 desc_cnt = qlcnic_get_sts_desc_cnt(sts_data0);
1433 opcode = qlcnic_get_sts_opcode(sts_data0);
1434 switch (opcode) {
1435 case QLCNIC_RESPONSE_DESC:
1436 qlcnic_handle_fw_message(desc_cnt, consumer, sds_ring);
1437 break;
1438 default:
1439 ring = qlcnic_get_sts_type(sts_data0);
1440 qlcnic_process_rcv_diag(adapter, ring, sts_data0);
1441 break;
1442 }
1443
1444 for (; desc_cnt > 0; desc_cnt--) {
1445 desc = &sds_ring->desc_head[consumer];
1446 desc->status_desc_data[0] = cpu_to_le64(STATUS_OWNER_PHANTOM);
1447 consumer = get_next_index(consumer, sds_ring->num_desc);
1448 }
1449
1450 sds_ring->consumer = consumer;
1451 writel(consumer, sds_ring->crb_sts_consumer);
1452}
1453
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00001454int qlcnic_82xx_napi_add(struct qlcnic_adapter *adapter,
1455 struct net_device *netdev)
Sony Chackoc70001a2012-11-28 04:34:26 +00001456{
Michal Schmidtdf95fc42013-09-04 15:03:05 +02001457 int ring;
Sony Chackoc70001a2012-11-28 04:34:26 +00001458 struct qlcnic_host_sds_ring *sds_ring;
1459 struct qlcnic_recv_context *recv_ctx = adapter->recv_ctx;
Himanshu Madhani012ec812013-08-21 11:24:10 -04001460 struct qlcnic_host_tx_ring *tx_ring;
Sony Chackoc70001a2012-11-28 04:34:26 +00001461
Himanshu Madhani34e8c402013-11-04 13:31:31 -05001462 if (qlcnic_alloc_sds_rings(recv_ctx, adapter->drv_sds_rings))
Sony Chackoc70001a2012-11-28 04:34:26 +00001463 return -ENOMEM;
1464
Himanshu Madhani34e8c402013-11-04 13:31:31 -05001465 for (ring = 0; ring < adapter->drv_sds_rings; ring++) {
Sony Chackoc70001a2012-11-28 04:34:26 +00001466 sds_ring = &recv_ctx->sds_rings[ring];
Himanshu Madhani012ec812013-08-21 11:24:10 -04001467 if (qlcnic_check_multi_tx(adapter) &&
Himanshu Madhani80c0e4f2013-12-17 09:01:52 -05001468 !adapter->ahw->diag_test) {
Sony Chackod17dd0d2012-11-28 04:34:27 +00001469 netif_napi_add(netdev, &sds_ring->napi, qlcnic_rx_poll,
Michal Schmidtdf95fc42013-09-04 15:03:05 +02001470 NAPI_POLL_WEIGHT);
Himanshu Madhani012ec812013-08-21 11:24:10 -04001471 } else {
Himanshu Madhani34e8c402013-11-04 13:31:31 -05001472 if (ring == (adapter->drv_sds_rings - 1))
Himanshu Madhani012ec812013-08-21 11:24:10 -04001473 netif_napi_add(netdev, &sds_ring->napi,
1474 qlcnic_poll,
Michal Schmidtdf95fc42013-09-04 15:03:05 +02001475 NAPI_POLL_WEIGHT);
Himanshu Madhani012ec812013-08-21 11:24:10 -04001476 else
1477 netif_napi_add(netdev, &sds_ring->napi,
1478 qlcnic_rx_poll,
Michal Schmidtdf95fc42013-09-04 15:03:05 +02001479 NAPI_POLL_WEIGHT);
Himanshu Madhani012ec812013-08-21 11:24:10 -04001480 }
Sony Chackoc70001a2012-11-28 04:34:26 +00001481 }
1482
Sony Chacko4be41e92013-01-01 03:20:20 +00001483 if (qlcnic_alloc_tx_rings(adapter, netdev)) {
1484 qlcnic_free_sds_rings(recv_ctx);
1485 return -ENOMEM;
1486 }
1487
Himanshu Madhanic2c5e3a2013-08-21 11:24:12 -04001488 if (qlcnic_check_multi_tx(adapter) && !adapter->ahw->diag_test) {
Himanshu Madhani34e8c402013-11-04 13:31:31 -05001489 for (ring = 0; ring < adapter->drv_tx_rings; ring++) {
Himanshu Madhani012ec812013-08-21 11:24:10 -04001490 tx_ring = &adapter->tx_ring[ring];
1491 netif_napi_add(netdev, &tx_ring->napi, qlcnic_tx_poll,
Michal Schmidtdf95fc42013-09-04 15:03:05 +02001492 NAPI_POLL_WEIGHT);
Himanshu Madhani012ec812013-08-21 11:24:10 -04001493 }
1494 }
1495
Sony Chackoc70001a2012-11-28 04:34:26 +00001496 return 0;
1497}
1498
Sony Chacko4be41e92013-01-01 03:20:20 +00001499void qlcnic_82xx_napi_del(struct qlcnic_adapter *adapter)
Sony Chackoc70001a2012-11-28 04:34:26 +00001500{
1501 int ring;
1502 struct qlcnic_host_sds_ring *sds_ring;
1503 struct qlcnic_recv_context *recv_ctx = adapter->recv_ctx;
Himanshu Madhani012ec812013-08-21 11:24:10 -04001504 struct qlcnic_host_tx_ring *tx_ring;
Sony Chackoc70001a2012-11-28 04:34:26 +00001505
Himanshu Madhani34e8c402013-11-04 13:31:31 -05001506 for (ring = 0; ring < adapter->drv_sds_rings; ring++) {
Sony Chackoc70001a2012-11-28 04:34:26 +00001507 sds_ring = &recv_ctx->sds_rings[ring];
1508 netif_napi_del(&sds_ring->napi);
1509 }
1510
1511 qlcnic_free_sds_rings(adapter->recv_ctx);
Himanshu Madhani012ec812013-08-21 11:24:10 -04001512
Himanshu Madhanic2c5e3a2013-08-21 11:24:12 -04001513 if (qlcnic_check_multi_tx(adapter) && !adapter->ahw->diag_test) {
Himanshu Madhani34e8c402013-11-04 13:31:31 -05001514 for (ring = 0; ring < adapter->drv_tx_rings; ring++) {
Himanshu Madhani012ec812013-08-21 11:24:10 -04001515 tx_ring = &adapter->tx_ring[ring];
1516 netif_napi_del(&tx_ring->napi);
1517 }
1518 }
1519
Sony Chacko4be41e92013-01-01 03:20:20 +00001520 qlcnic_free_tx_rings(adapter);
Sony Chackoc70001a2012-11-28 04:34:26 +00001521}
1522
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00001523void qlcnic_82xx_napi_enable(struct qlcnic_adapter *adapter)
Sony Chackoc70001a2012-11-28 04:34:26 +00001524{
1525 int ring;
1526 struct qlcnic_host_sds_ring *sds_ring;
Himanshu Madhani012ec812013-08-21 11:24:10 -04001527 struct qlcnic_host_tx_ring *tx_ring;
Sony Chackoc70001a2012-11-28 04:34:26 +00001528 struct qlcnic_recv_context *recv_ctx = adapter->recv_ctx;
1529
1530 if (adapter->is_up != QLCNIC_ADAPTER_UP_MAGIC)
1531 return;
1532
Himanshu Madhani34e8c402013-11-04 13:31:31 -05001533 for (ring = 0; ring < adapter->drv_sds_rings; ring++) {
Sony Chackoc70001a2012-11-28 04:34:26 +00001534 sds_ring = &recv_ctx->sds_rings[ring];
1535 napi_enable(&sds_ring->napi);
Manish chopra2cc57522014-01-23 17:18:30 -05001536 qlcnic_enable_sds_intr(adapter, sds_ring);
Sony Chackoc70001a2012-11-28 04:34:26 +00001537 }
Himanshu Madhani012ec812013-08-21 11:24:10 -04001538
1539 if (qlcnic_check_multi_tx(adapter) &&
1540 (adapter->flags & QLCNIC_MSIX_ENABLED) &&
Himanshu Madhani80c0e4f2013-12-17 09:01:52 -05001541 !adapter->ahw->diag_test) {
Himanshu Madhani34e8c402013-11-04 13:31:31 -05001542 for (ring = 0; ring < adapter->drv_tx_rings; ring++) {
Himanshu Madhani012ec812013-08-21 11:24:10 -04001543 tx_ring = &adapter->tx_ring[ring];
1544 napi_enable(&tx_ring->napi);
1545 qlcnic_enable_tx_intr(adapter, tx_ring);
1546 }
1547 }
Sony Chackoc70001a2012-11-28 04:34:26 +00001548}
1549
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00001550void qlcnic_82xx_napi_disable(struct qlcnic_adapter *adapter)
Sony Chackoc70001a2012-11-28 04:34:26 +00001551{
1552 int ring;
1553 struct qlcnic_host_sds_ring *sds_ring;
Himanshu Madhani012ec812013-08-21 11:24:10 -04001554 struct qlcnic_host_tx_ring *tx_ring;
Sony Chackoc70001a2012-11-28 04:34:26 +00001555 struct qlcnic_recv_context *recv_ctx = adapter->recv_ctx;
1556
1557 if (adapter->is_up != QLCNIC_ADAPTER_UP_MAGIC)
1558 return;
1559
Himanshu Madhani34e8c402013-11-04 13:31:31 -05001560 for (ring = 0; ring < adapter->drv_sds_rings; ring++) {
Sony Chackoc70001a2012-11-28 04:34:26 +00001561 sds_ring = &recv_ctx->sds_rings[ring];
Manish chopra2cc57522014-01-23 17:18:30 -05001562 qlcnic_disable_sds_intr(adapter, sds_ring);
Sony Chackoc70001a2012-11-28 04:34:26 +00001563 napi_synchronize(&sds_ring->napi);
1564 napi_disable(&sds_ring->napi);
1565 }
Himanshu Madhani012ec812013-08-21 11:24:10 -04001566
1567 if ((adapter->flags & QLCNIC_MSIX_ENABLED) &&
Himanshu Madhanic2c5e3a2013-08-21 11:24:12 -04001568 !adapter->ahw->diag_test &&
Himanshu Madhani012ec812013-08-21 11:24:10 -04001569 qlcnic_check_multi_tx(adapter)) {
Himanshu Madhani34e8c402013-11-04 13:31:31 -05001570 for (ring = 0; ring < adapter->drv_tx_rings; ring++) {
Himanshu Madhani012ec812013-08-21 11:24:10 -04001571 tx_ring = &adapter->tx_ring[ring];
Manish chopra2cc57522014-01-23 17:18:30 -05001572 qlcnic_disable_tx_intr(adapter, tx_ring);
Himanshu Madhani012ec812013-08-21 11:24:10 -04001573 napi_synchronize(&tx_ring->napi);
1574 napi_disable(&tx_ring->napi);
1575 }
1576 }
Sony Chackoc70001a2012-11-28 04:34:26 +00001577}
Sony Chacko4be41e92013-01-01 03:20:20 +00001578
Shahed Shaikh53643a72013-02-18 13:22:37 +00001579#define QLC_83XX_NORMAL_LB_PKT (1ULL << 36)
1580#define QLC_83XX_LRO_LB_PKT (1ULL << 46)
1581
1582static inline int qlcnic_83xx_is_lb_pkt(u64 sts_data, int lro_pkt)
1583{
1584 if (lro_pkt)
1585 return (sts_data & QLC_83XX_LRO_LB_PKT) ? 1 : 0;
1586 else
1587 return (sts_data & QLC_83XX_NORMAL_LB_PKT) ? 1 : 0;
1588}
1589
Sony Chacko4be41e92013-01-01 03:20:20 +00001590static struct qlcnic_rx_buffer *
1591qlcnic_83xx_process_rcv(struct qlcnic_adapter *adapter,
1592 struct qlcnic_host_sds_ring *sds_ring,
1593 u8 ring, u64 sts_data[])
1594{
1595 struct net_device *netdev = adapter->netdev;
1596 struct qlcnic_recv_context *recv_ctx = adapter->recv_ctx;
1597 struct qlcnic_rx_buffer *buffer;
1598 struct sk_buff *skb;
1599 struct qlcnic_host_rds_ring *rds_ring;
Shahed Shaikh53643a72013-02-18 13:22:37 +00001600 int index, length, cksum, is_lb_pkt;
Sucheta Chakrabortyb3f7de82014-01-10 11:48:55 -05001601 u16 vid = 0xffff;
1602 int err;
Sony Chacko4be41e92013-01-01 03:20:20 +00001603
1604 if (unlikely(ring >= adapter->max_rds_rings))
1605 return NULL;
1606
1607 rds_ring = &recv_ctx->rds_rings[ring];
1608
1609 index = qlcnic_83xx_hndl(sts_data[0]);
1610 if (unlikely(index >= rds_ring->num_desc))
1611 return NULL;
1612
1613 buffer = &rds_ring->rx_buf_arr[index];
1614 length = qlcnic_83xx_pktln(sts_data[0]);
1615 cksum = qlcnic_83xx_csum_status(sts_data[1]);
1616 skb = qlcnic_process_rxbuf(adapter, rds_ring, index, cksum);
1617 if (!skb)
1618 return buffer;
1619
1620 if (length > rds_ring->skb_size)
1621 skb_put(skb, rds_ring->skb_size);
1622 else
1623 skb_put(skb, length);
1624
Sucheta Chakrabortyb3f7de82014-01-10 11:48:55 -05001625 err = qlcnic_check_rx_tagging(adapter, skb, &vid);
1626
1627 if (adapter->rx_mac_learn) {
1628 is_lb_pkt = qlcnic_83xx_is_lb_pkt(sts_data[1], 0);
1629 qlcnic_add_lb_filter(adapter, skb, is_lb_pkt, vid);
1630 }
1631
1632 if (unlikely(err)) {
Sony Chacko4be41e92013-01-01 03:20:20 +00001633 adapter->stats.rxdropped++;
1634 dev_kfree_skb(skb);
1635 return buffer;
1636 }
1637
1638 skb->protocol = eth_type_trans(skb, netdev);
1639
1640 if (vid != 0xffff)
Patrick McHardy86a9bad2013-04-19 02:04:30 +00001641 __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q), vid);
Sony Chacko4be41e92013-01-01 03:20:20 +00001642
1643 napi_gro_receive(&sds_ring->napi, skb);
1644
1645 adapter->stats.rx_pkts++;
1646 adapter->stats.rxbytes += length;
1647
1648 return buffer;
1649}
1650
1651static struct qlcnic_rx_buffer *
1652qlcnic_83xx_process_lro(struct qlcnic_adapter *adapter,
1653 u8 ring, u64 sts_data[])
1654{
1655 struct net_device *netdev = adapter->netdev;
1656 struct qlcnic_recv_context *recv_ctx = adapter->recv_ctx;
1657 struct qlcnic_rx_buffer *buffer;
1658 struct sk_buff *skb;
1659 struct qlcnic_host_rds_ring *rds_ring;
1660 struct iphdr *iph;
1661 struct ipv6hdr *ipv6h;
1662 struct tcphdr *th;
1663 bool push;
1664 int l2_hdr_offset, l4_hdr_offset;
Shahed Shaikh53643a72013-02-18 13:22:37 +00001665 int index, is_lb_pkt;
Shahed Shaikh99e85872013-02-18 12:06:16 +00001666 u16 lro_length, length, data_offset, gso_size;
Sucheta Chakrabortyb3f7de82014-01-10 11:48:55 -05001667 u16 vid = 0xffff;
1668 int err;
Sony Chacko4be41e92013-01-01 03:20:20 +00001669
Manish Chopra462bed42014-01-28 11:55:27 -05001670 if (unlikely(ring >= adapter->max_rds_rings))
Sony Chacko4be41e92013-01-01 03:20:20 +00001671 return NULL;
1672
1673 rds_ring = &recv_ctx->rds_rings[ring];
1674
1675 index = qlcnic_83xx_hndl(sts_data[0]);
Manish Chopra462bed42014-01-28 11:55:27 -05001676 if (unlikely(index >= rds_ring->num_desc))
Sony Chacko4be41e92013-01-01 03:20:20 +00001677 return NULL;
1678
1679 buffer = &rds_ring->rx_buf_arr[index];
1680
1681 lro_length = qlcnic_83xx_lro_pktln(sts_data[0]);
1682 l2_hdr_offset = qlcnic_83xx_l2_hdr_off(sts_data[1]);
1683 l4_hdr_offset = qlcnic_83xx_l4_hdr_off(sts_data[1]);
1684 push = qlcnic_83xx_is_psh_bit(sts_data[1]);
1685
1686 skb = qlcnic_process_rxbuf(adapter, rds_ring, index, STATUS_CKSUM_OK);
1687 if (!skb)
1688 return buffer;
Shahed Shaikh53643a72013-02-18 13:22:37 +00001689
Sony Chacko4be41e92013-01-01 03:20:20 +00001690 if (qlcnic_83xx_is_tstamp(sts_data[1]))
1691 data_offset = l4_hdr_offset + QLCNIC_TCP_TS_HDR_SIZE;
1692 else
1693 data_offset = l4_hdr_offset + QLCNIC_TCP_HDR_SIZE;
1694
1695 skb_put(skb, lro_length + data_offset);
1696 skb_pull(skb, l2_hdr_offset);
1697
Sucheta Chakrabortyb3f7de82014-01-10 11:48:55 -05001698 err = qlcnic_check_rx_tagging(adapter, skb, &vid);
1699
1700 if (adapter->rx_mac_learn) {
1701 is_lb_pkt = qlcnic_83xx_is_lb_pkt(sts_data[1], 1);
1702 qlcnic_add_lb_filter(adapter, skb, is_lb_pkt, vid);
1703 }
1704
1705 if (unlikely(err)) {
Sony Chacko4be41e92013-01-01 03:20:20 +00001706 adapter->stats.rxdropped++;
1707 dev_kfree_skb(skb);
1708 return buffer;
1709 }
1710
1711 skb->protocol = eth_type_trans(skb, netdev);
1712 if (ntohs(skb->protocol) == ETH_P_IPV6) {
1713 ipv6h = (struct ipv6hdr *)skb->data;
1714 th = (struct tcphdr *)(skb->data + sizeof(struct ipv6hdr));
1715
1716 length = (th->doff << 2) + lro_length;
1717 ipv6h->payload_len = htons(length);
1718 } else {
1719 iph = (struct iphdr *)skb->data;
1720 th = (struct tcphdr *)(skb->data + (iph->ihl << 2));
1721 length = (iph->ihl << 2) + (th->doff << 2) + lro_length;
Li RongQing1bcac3b2013-03-14 22:50:07 +00001722 csum_replace2(&iph->check, iph->tot_len, htons(length));
Sony Chacko4be41e92013-01-01 03:20:20 +00001723 iph->tot_len = htons(length);
Sony Chacko4be41e92013-01-01 03:20:20 +00001724 }
1725
1726 th->psh = push;
1727 length = skb->len;
1728
Shahed Shaikh99e85872013-02-18 12:06:16 +00001729 if (adapter->flags & QLCNIC_FW_LRO_MSS_CAP) {
1730 gso_size = qlcnic_83xx_get_lro_sts_mss(sts_data[0]);
1731 skb_shinfo(skb)->gso_size = gso_size;
1732 if (skb->protocol == htons(ETH_P_IPV6))
1733 skb_shinfo(skb)->gso_type = SKB_GSO_TCPV6;
1734 else
1735 skb_shinfo(skb)->gso_type = SKB_GSO_TCPV4;
1736 }
1737
Sony Chacko4be41e92013-01-01 03:20:20 +00001738 if (vid != 0xffff)
Patrick McHardy86a9bad2013-04-19 02:04:30 +00001739 __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q), vid);
Sony Chacko4be41e92013-01-01 03:20:20 +00001740
1741 netif_receive_skb(skb);
1742
1743 adapter->stats.lro_pkts++;
1744 adapter->stats.lrobytes += length;
1745 return buffer;
1746}
1747
1748static int qlcnic_83xx_process_rcv_ring(struct qlcnic_host_sds_ring *sds_ring,
1749 int max)
1750{
1751 struct qlcnic_host_rds_ring *rds_ring;
1752 struct qlcnic_adapter *adapter = sds_ring->adapter;
1753 struct list_head *cur;
1754 struct status_desc *desc;
1755 struct qlcnic_rx_buffer *rxbuf = NULL;
1756 u8 ring;
1757 u64 sts_data[2];
1758 int count = 0, opcode;
1759 u32 consumer = sds_ring->consumer;
1760
1761 while (count < max) {
1762 desc = &sds_ring->desc_head[consumer];
1763 sts_data[1] = le64_to_cpu(desc->status_desc_data[1]);
1764 opcode = qlcnic_83xx_opcode(sts_data[1]);
1765 if (!opcode)
1766 break;
1767 sts_data[0] = le64_to_cpu(desc->status_desc_data[0]);
1768 ring = QLCNIC_FETCH_RING_ID(sts_data[0]);
1769
1770 switch (opcode) {
1771 case QLC_83XX_REG_DESC:
1772 rxbuf = qlcnic_83xx_process_rcv(adapter, sds_ring,
1773 ring, sts_data);
1774 break;
1775 case QLC_83XX_LRO_DESC:
1776 rxbuf = qlcnic_83xx_process_lro(adapter, ring,
1777 sts_data);
1778 break;
1779 default:
1780 dev_info(&adapter->pdev->dev,
Masanari Iida0b1587b2013-07-17 04:37:44 +09001781 "Unknown opcode: 0x%x\n", opcode);
Sony Chacko4be41e92013-01-01 03:20:20 +00001782 goto skip;
1783 }
1784
1785 if (likely(rxbuf))
1786 list_add_tail(&rxbuf->list, &sds_ring->free_list[ring]);
1787 else
1788 adapter->stats.null_rxbuf++;
1789skip:
1790 desc = &sds_ring->desc_head[consumer];
1791 /* Reset the descriptor */
1792 desc->status_desc_data[1] = 0;
1793 consumer = get_next_index(consumer, sds_ring->num_desc);
1794 count++;
1795 }
1796 for (ring = 0; ring < adapter->max_rds_rings; ring++) {
1797 rds_ring = &adapter->recv_ctx->rds_rings[ring];
1798 if (!list_empty(&sds_ring->free_list[ring])) {
1799 list_for_each(cur, &sds_ring->free_list[ring]) {
1800 rxbuf = list_entry(cur, struct qlcnic_rx_buffer,
1801 list);
1802 qlcnic_alloc_rx_skb(adapter, rds_ring, rxbuf);
1803 }
1804 spin_lock(&rds_ring->lock);
1805 list_splice_tail_init(&sds_ring->free_list[ring],
1806 &rds_ring->free_list);
1807 spin_unlock(&rds_ring->lock);
1808 }
1809 qlcnic_post_rx_buffers_nodb(adapter, rds_ring, ring);
1810 }
1811 if (count) {
1812 sds_ring->consumer = consumer;
1813 writel(consumer, sds_ring->crb_sts_consumer);
1814 }
1815 return count;
1816}
1817
Rajesh Borundiada6c8062013-03-29 05:46:35 +00001818static int qlcnic_83xx_msix_sriov_vf_poll(struct napi_struct *napi, int budget)
1819{
1820 int tx_complete;
1821 int work_done;
1822 struct qlcnic_host_sds_ring *sds_ring;
1823 struct qlcnic_adapter *adapter;
1824 struct qlcnic_host_tx_ring *tx_ring;
1825
1826 sds_ring = container_of(napi, struct qlcnic_host_sds_ring, napi);
1827 adapter = sds_ring->adapter;
1828 /* tx ring count = 1 */
1829 tx_ring = adapter->tx_ring;
1830
1831 tx_complete = qlcnic_process_cmd_ring(adapter, tx_ring, budget);
1832 work_done = qlcnic_83xx_process_rcv_ring(sds_ring, budget);
1833 if ((work_done < budget) && tx_complete) {
1834 napi_complete(&sds_ring->napi);
Manish chopra2cc57522014-01-23 17:18:30 -05001835 qlcnic_enable_sds_intr(adapter, sds_ring);
Rajesh Borundiada6c8062013-03-29 05:46:35 +00001836 }
1837
1838 return work_done;
1839}
1840
Sony Chacko4be41e92013-01-01 03:20:20 +00001841static int qlcnic_83xx_poll(struct napi_struct *napi, int budget)
1842{
1843 int tx_complete;
1844 int work_done;
1845 struct qlcnic_host_sds_ring *sds_ring;
1846 struct qlcnic_adapter *adapter;
1847 struct qlcnic_host_tx_ring *tx_ring;
1848
1849 sds_ring = container_of(napi, struct qlcnic_host_sds_ring, napi);
1850 adapter = sds_ring->adapter;
1851 /* tx ring count = 1 */
1852 tx_ring = adapter->tx_ring;
1853
Sony Chacko4be41e92013-01-01 03:20:20 +00001854 tx_complete = qlcnic_process_cmd_ring(adapter, tx_ring, budget);
1855 work_done = qlcnic_83xx_process_rcv_ring(sds_ring, budget);
1856 if ((work_done < budget) && tx_complete) {
1857 napi_complete(&sds_ring->napi);
Manish chopra2cc57522014-01-23 17:18:30 -05001858 qlcnic_enable_sds_intr(adapter, sds_ring);
Sony Chacko4be41e92013-01-01 03:20:20 +00001859 }
1860
1861 return work_done;
1862}
1863
1864static int qlcnic_83xx_msix_tx_poll(struct napi_struct *napi, int budget)
1865{
1866 int work_done;
1867 struct qlcnic_host_tx_ring *tx_ring;
1868 struct qlcnic_adapter *adapter;
1869
1870 budget = QLCNIC_TX_POLL_BUDGET;
1871 tx_ring = container_of(napi, struct qlcnic_host_tx_ring, napi);
1872 adapter = tx_ring->adapter;
1873 work_done = qlcnic_process_cmd_ring(adapter, tx_ring, budget);
1874 if (work_done) {
1875 napi_complete(&tx_ring->napi);
1876 if (test_bit(__QLCNIC_DEV_UP , &adapter->state))
Manish chopra2cc57522014-01-23 17:18:30 -05001877 qlcnic_enable_tx_intr(adapter, tx_ring);
Sony Chacko4be41e92013-01-01 03:20:20 +00001878 }
1879
1880 return work_done;
1881}
1882
1883static int qlcnic_83xx_rx_poll(struct napi_struct *napi, int budget)
1884{
1885 int work_done;
1886 struct qlcnic_host_sds_ring *sds_ring;
1887 struct qlcnic_adapter *adapter;
1888
1889 sds_ring = container_of(napi, struct qlcnic_host_sds_ring, napi);
1890 adapter = sds_ring->adapter;
1891 work_done = qlcnic_83xx_process_rcv_ring(sds_ring, budget);
1892 if (work_done < budget) {
1893 napi_complete(&sds_ring->napi);
1894 if (test_bit(__QLCNIC_DEV_UP, &adapter->state))
Manish chopra2cc57522014-01-23 17:18:30 -05001895 qlcnic_enable_sds_intr(adapter, sds_ring);
Sony Chacko4be41e92013-01-01 03:20:20 +00001896 }
1897
1898 return work_done;
1899}
1900
1901void qlcnic_83xx_napi_enable(struct qlcnic_adapter *adapter)
1902{
1903 int ring;
1904 struct qlcnic_host_sds_ring *sds_ring;
1905 struct qlcnic_host_tx_ring *tx_ring;
1906 struct qlcnic_recv_context *recv_ctx = adapter->recv_ctx;
1907
1908 if (adapter->is_up != QLCNIC_ADAPTER_UP_MAGIC)
1909 return;
1910
Himanshu Madhani34e8c402013-11-04 13:31:31 -05001911 for (ring = 0; ring < adapter->drv_sds_rings; ring++) {
Sony Chacko4be41e92013-01-01 03:20:20 +00001912 sds_ring = &recv_ctx->sds_rings[ring];
1913 napi_enable(&sds_ring->napi);
Himanshu Madhaniac166702013-02-18 12:06:15 +00001914 if (adapter->flags & QLCNIC_MSIX_ENABLED)
Manish chopra2cc57522014-01-23 17:18:30 -05001915 qlcnic_enable_sds_intr(adapter, sds_ring);
Sony Chacko4be41e92013-01-01 03:20:20 +00001916 }
1917
Rajesh Borundiada6c8062013-03-29 05:46:35 +00001918 if ((adapter->flags & QLCNIC_MSIX_ENABLED) &&
1919 !(adapter->flags & QLCNIC_TX_INTR_SHARED)) {
Himanshu Madhani34e8c402013-11-04 13:31:31 -05001920 for (ring = 0; ring < adapter->drv_tx_rings; ring++) {
Sony Chacko4be41e92013-01-01 03:20:20 +00001921 tx_ring = &adapter->tx_ring[ring];
1922 napi_enable(&tx_ring->napi);
Manish chopra2cc57522014-01-23 17:18:30 -05001923 qlcnic_enable_tx_intr(adapter, tx_ring);
Sony Chacko4be41e92013-01-01 03:20:20 +00001924 }
1925 }
1926}
1927
1928void qlcnic_83xx_napi_disable(struct qlcnic_adapter *adapter)
1929{
1930 int ring;
1931 struct qlcnic_host_sds_ring *sds_ring;
1932 struct qlcnic_recv_context *recv_ctx = adapter->recv_ctx;
1933 struct qlcnic_host_tx_ring *tx_ring;
1934
1935 if (adapter->is_up != QLCNIC_ADAPTER_UP_MAGIC)
1936 return;
1937
Himanshu Madhani34e8c402013-11-04 13:31:31 -05001938 for (ring = 0; ring < adapter->drv_sds_rings; ring++) {
Sony Chacko4be41e92013-01-01 03:20:20 +00001939 sds_ring = &recv_ctx->sds_rings[ring];
Himanshu Madhaniac166702013-02-18 12:06:15 +00001940 if (adapter->flags & QLCNIC_MSIX_ENABLED)
Manish chopra2cc57522014-01-23 17:18:30 -05001941 qlcnic_disable_sds_intr(adapter, sds_ring);
Sony Chacko4be41e92013-01-01 03:20:20 +00001942 napi_synchronize(&sds_ring->napi);
1943 napi_disable(&sds_ring->napi);
1944 }
1945
Rajesh Borundiada6c8062013-03-29 05:46:35 +00001946 if ((adapter->flags & QLCNIC_MSIX_ENABLED) &&
1947 !(adapter->flags & QLCNIC_TX_INTR_SHARED)) {
Himanshu Madhani34e8c402013-11-04 13:31:31 -05001948 for (ring = 0; ring < adapter->drv_tx_rings; ring++) {
Sony Chacko4be41e92013-01-01 03:20:20 +00001949 tx_ring = &adapter->tx_ring[ring];
Manish chopra2cc57522014-01-23 17:18:30 -05001950 qlcnic_disable_tx_intr(adapter, tx_ring);
Sony Chacko4be41e92013-01-01 03:20:20 +00001951 napi_synchronize(&tx_ring->napi);
1952 napi_disable(&tx_ring->napi);
1953 }
1954 }
1955}
1956
1957int qlcnic_83xx_napi_add(struct qlcnic_adapter *adapter,
1958 struct net_device *netdev)
1959{
Michal Schmidtdf95fc42013-09-04 15:03:05 +02001960 int ring;
Sony Chacko4be41e92013-01-01 03:20:20 +00001961 struct qlcnic_host_sds_ring *sds_ring;
1962 struct qlcnic_host_tx_ring *tx_ring;
1963 struct qlcnic_recv_context *recv_ctx = adapter->recv_ctx;
1964
Himanshu Madhani34e8c402013-11-04 13:31:31 -05001965 if (qlcnic_alloc_sds_rings(recv_ctx, adapter->drv_sds_rings))
Sony Chacko4be41e92013-01-01 03:20:20 +00001966 return -ENOMEM;
1967
Himanshu Madhani34e8c402013-11-04 13:31:31 -05001968 for (ring = 0; ring < adapter->drv_sds_rings; ring++) {
Sony Chacko4be41e92013-01-01 03:20:20 +00001969 sds_ring = &recv_ctx->sds_rings[ring];
Rajesh Borundiada6c8062013-03-29 05:46:35 +00001970 if (adapter->flags & QLCNIC_MSIX_ENABLED) {
Michal Schmidtdf95fc42013-09-04 15:03:05 +02001971 if (!(adapter->flags & QLCNIC_TX_INTR_SHARED))
Rajesh Borundiada6c8062013-03-29 05:46:35 +00001972 netif_napi_add(netdev, &sds_ring->napi,
1973 qlcnic_83xx_rx_poll,
Michal Schmidtdf95fc42013-09-04 15:03:05 +02001974 NAPI_POLL_WEIGHT);
1975 else
Rajesh Borundiada6c8062013-03-29 05:46:35 +00001976 netif_napi_add(netdev, &sds_ring->napi,
1977 qlcnic_83xx_msix_sriov_vf_poll,
Michal Schmidtdf95fc42013-09-04 15:03:05 +02001978 NAPI_POLL_WEIGHT);
Rajesh Borundiada6c8062013-03-29 05:46:35 +00001979
1980 } else {
Sony Chacko4be41e92013-01-01 03:20:20 +00001981 netif_napi_add(netdev, &sds_ring->napi,
1982 qlcnic_83xx_poll,
Michal Schmidtdf95fc42013-09-04 15:03:05 +02001983 NAPI_POLL_WEIGHT);
Rajesh Borundiada6c8062013-03-29 05:46:35 +00001984 }
Sony Chacko4be41e92013-01-01 03:20:20 +00001985 }
1986
1987 if (qlcnic_alloc_tx_rings(adapter, netdev)) {
1988 qlcnic_free_sds_rings(recv_ctx);
1989 return -ENOMEM;
1990 }
1991
Rajesh Borundiada6c8062013-03-29 05:46:35 +00001992 if ((adapter->flags & QLCNIC_MSIX_ENABLED) &&
1993 !(adapter->flags & QLCNIC_TX_INTR_SHARED)) {
Himanshu Madhani34e8c402013-11-04 13:31:31 -05001994 for (ring = 0; ring < adapter->drv_tx_rings; ring++) {
Sony Chacko4be41e92013-01-01 03:20:20 +00001995 tx_ring = &adapter->tx_ring[ring];
1996 netif_napi_add(netdev, &tx_ring->napi,
1997 qlcnic_83xx_msix_tx_poll,
Michal Schmidtdf95fc42013-09-04 15:03:05 +02001998 NAPI_POLL_WEIGHT);
Sony Chacko4be41e92013-01-01 03:20:20 +00001999 }
2000 }
2001
2002 return 0;
2003}
2004
2005void qlcnic_83xx_napi_del(struct qlcnic_adapter *adapter)
2006{
2007 int ring;
2008 struct qlcnic_host_sds_ring *sds_ring;
2009 struct qlcnic_recv_context *recv_ctx = adapter->recv_ctx;
2010 struct qlcnic_host_tx_ring *tx_ring;
2011
Himanshu Madhani34e8c402013-11-04 13:31:31 -05002012 for (ring = 0; ring < adapter->drv_sds_rings; ring++) {
Sony Chacko4be41e92013-01-01 03:20:20 +00002013 sds_ring = &recv_ctx->sds_rings[ring];
2014 netif_napi_del(&sds_ring->napi);
2015 }
2016
2017 qlcnic_free_sds_rings(adapter->recv_ctx);
2018
Rajesh Borundiada6c8062013-03-29 05:46:35 +00002019 if ((adapter->flags & QLCNIC_MSIX_ENABLED) &&
2020 !(adapter->flags & QLCNIC_TX_INTR_SHARED)) {
Himanshu Madhani34e8c402013-11-04 13:31:31 -05002021 for (ring = 0; ring < adapter->drv_tx_rings; ring++) {
Sony Chacko4be41e92013-01-01 03:20:20 +00002022 tx_ring = &adapter->tx_ring[ring];
2023 netif_napi_del(&tx_ring->napi);
2024 }
2025 }
2026
2027 qlcnic_free_tx_rings(adapter);
2028}
2029
stephen hemminger21041402014-01-16 10:31:27 -08002030static void qlcnic_83xx_process_rcv_diag(struct qlcnic_adapter *adapter,
2031 int ring, u64 sts_data[])
Sony Chacko4be41e92013-01-01 03:20:20 +00002032{
2033 struct qlcnic_recv_context *recv_ctx = adapter->recv_ctx;
2034 struct sk_buff *skb;
2035 struct qlcnic_host_rds_ring *rds_ring;
2036 int index, length;
2037
2038 if (unlikely(ring >= adapter->max_rds_rings))
2039 return;
2040
2041 rds_ring = &recv_ctx->rds_rings[ring];
2042 index = qlcnic_83xx_hndl(sts_data[0]);
2043 if (unlikely(index >= rds_ring->num_desc))
2044 return;
2045
2046 length = qlcnic_83xx_pktln(sts_data[0]);
2047
2048 skb = qlcnic_process_rxbuf(adapter, rds_ring, index, STATUS_CKSUM_OK);
2049 if (!skb)
2050 return;
2051
2052 if (length > rds_ring->skb_size)
2053 skb_put(skb, rds_ring->skb_size);
2054 else
2055 skb_put(skb, length);
2056
2057 if (!qlcnic_check_loopback_buff(skb->data, adapter->mac_addr))
2058 adapter->ahw->diag_cnt++;
2059 else
2060 dump_skb(skb, adapter);
2061
2062 dev_kfree_skb_any(skb);
2063 return;
2064}
2065
2066void qlcnic_83xx_process_rcv_ring_diag(struct qlcnic_host_sds_ring *sds_ring)
2067{
2068 struct qlcnic_adapter *adapter = sds_ring->adapter;
2069 struct status_desc *desc;
2070 u64 sts_data[2];
2071 int ring, opcode;
2072 u32 consumer = sds_ring->consumer;
2073
2074 desc = &sds_ring->desc_head[consumer];
2075 sts_data[0] = le64_to_cpu(desc->status_desc_data[0]);
2076 sts_data[1] = le64_to_cpu(desc->status_desc_data[1]);
2077 opcode = qlcnic_83xx_opcode(sts_data[1]);
2078 if (!opcode)
2079 return;
2080
2081 ring = QLCNIC_FETCH_RING_ID(qlcnic_83xx_hndl(sts_data[0]));
2082 qlcnic_83xx_process_rcv_diag(adapter, ring, sts_data);
2083 desc = &sds_ring->desc_head[consumer];
2084 desc->status_desc_data[0] = cpu_to_le64(STATUS_OWNER_PHANTOM);
2085 consumer = get_next_index(consumer, sds_ring->num_desc);
2086 sds_ring->consumer = consumer;
2087 writel(consumer, sds_ring->crb_sts_consumer);
2088}