blob: 897627dd1d04e7f6c3cd60ad25ede51fad376327 [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
127struct sk_buff *qlcnic_process_rxbuf(struct qlcnic_adapter *,
128 struct qlcnic_host_rds_ring *, u16, u16);
129
Himanshu Madhani012ec812013-08-21 11:24:10 -0400130inline void qlcnic_enable_tx_intr(struct qlcnic_adapter *adapter,
131 struct qlcnic_host_tx_ring *tx_ring)
132{
Himanshu Madhanic2c5e3a2013-08-21 11:24:12 -0400133 if (qlcnic_check_multi_tx(adapter) &&
134 !adapter->ahw->diag_test)
Himanshu Madhani012ec812013-08-21 11:24:10 -0400135 writel(0x0, tx_ring->crb_intr_mask);
136}
137
138
139static inline void qlcnic_disable_tx_int(struct qlcnic_adapter *adapter,
140 struct qlcnic_host_tx_ring *tx_ring)
141{
Himanshu Madhanic2c5e3a2013-08-21 11:24:12 -0400142 if (qlcnic_check_multi_tx(adapter) &&
143 !adapter->ahw->diag_test)
Himanshu Madhani012ec812013-08-21 11:24:10 -0400144 writel(1, tx_ring->crb_intr_mask);
145}
146
Sony Chacko4be41e92013-01-01 03:20:20 +0000147inline void qlcnic_83xx_enable_tx_intr(struct qlcnic_adapter *adapter,
148 struct qlcnic_host_tx_ring *tx_ring)
149{
150 writel(0, tx_ring->crb_intr_mask);
151}
152
153inline void qlcnic_83xx_disable_tx_intr(struct qlcnic_adapter *adapter,
154 struct qlcnic_host_tx_ring *tx_ring)
155{
156 writel(1, tx_ring->crb_intr_mask);
157}
158
159static inline u8 qlcnic_mac_hash(u64 mac)
160{
161 return (u8)((mac & 0xff) ^ ((mac >> 40) & 0xff));
162}
163
164static inline u32 qlcnic_get_ref_handle(struct qlcnic_adapter *adapter,
165 u16 handle, u8 ring_id)
166{
Manish Chopra15ca1402013-08-16 19:07:13 -0400167 if (qlcnic_83xx_check(adapter))
Sony Chacko4be41e92013-01-01 03:20:20 +0000168 return handle | (ring_id << 15);
169 else
170 return handle;
171}
172
Shahed Shaikh53643a72013-02-18 13:22:37 +0000173static inline int qlcnic_82xx_is_lb_pkt(u64 sts_data)
174{
175 return (qlcnic_get_sts_status(sts_data) == STATUS_CKSUM_LOOP) ? 1 : 0;
176}
177
Shahed Shaikhe0d138d2013-08-02 23:15:55 -0400178static void qlcnic_delete_rx_list_mac(struct qlcnic_adapter *adapter,
179 struct qlcnic_filter *fil,
180 void *addr, u16 vlan_id)
181{
182 int ret;
183 u8 op;
184
185 op = vlan_id ? QLCNIC_MAC_VLAN_ADD : QLCNIC_MAC_ADD;
186 ret = qlcnic_sre_macaddr_change(adapter, addr, vlan_id, op);
187 if (ret)
188 return;
189
190 op = vlan_id ? QLCNIC_MAC_VLAN_DEL : QLCNIC_MAC_DEL;
191 ret = qlcnic_sre_macaddr_change(adapter, addr, vlan_id, op);
192 if (!ret) {
193 hlist_del(&fil->fnode);
194 adapter->rx_fhash.fnum--;
195 }
196}
197
198static struct qlcnic_filter *qlcnic_find_mac_filter(struct hlist_head *head,
199 void *addr, u16 vlan_id)
200{
201 struct qlcnic_filter *tmp_fil = NULL;
202 struct hlist_node *n;
203
204 hlist_for_each_entry_safe(tmp_fil, n, head, fnode) {
205 if (!memcmp(tmp_fil->faddr, addr, ETH_ALEN) &&
206 tmp_fil->vlan_id == vlan_id)
207 return tmp_fil;
208 }
209
210 return NULL;
211}
212
Shahed Shaikh53643a72013-02-18 13:22:37 +0000213void qlcnic_add_lb_filter(struct qlcnic_adapter *adapter, struct sk_buff *skb,
Rajesh Borundiaf80bc8f2013-04-19 07:01:08 +0000214 int loopback_pkt, u16 vlan_id)
Shahed Shaikh53643a72013-02-18 13:22:37 +0000215{
216 struct ethhdr *phdr = (struct ethhdr *)(skb->data);
217 struct qlcnic_filter *fil, *tmp_fil;
Shahed Shaikh53643a72013-02-18 13:22:37 +0000218 struct hlist_head *head;
219 unsigned long time;
220 u64 src_addr = 0;
Shahed Shaikhe0d138d2013-08-02 23:15:55 -0400221 u8 hindex, op;
Shahed Shaikh53643a72013-02-18 13:22:37 +0000222 int ret;
223
224 memcpy(&src_addr, phdr->h_source, ETH_ALEN);
Shahed Shaikhe0d138d2013-08-02 23:15:55 -0400225 hindex = qlcnic_mac_hash(src_addr) &
226 (adapter->fhash.fbucket_size - 1);
Shahed Shaikh53643a72013-02-18 13:22:37 +0000227
228 if (loopback_pkt) {
229 if (adapter->rx_fhash.fnum >= adapter->rx_fhash.fmax)
230 return;
231
Shahed Shaikh53643a72013-02-18 13:22:37 +0000232 head = &(adapter->rx_fhash.fhead[hindex]);
233
Shahed Shaikhe0d138d2013-08-02 23:15:55 -0400234 tmp_fil = qlcnic_find_mac_filter(head, &src_addr, vlan_id);
235 if (tmp_fil) {
236 time = tmp_fil->ftime;
237 if (time_after(jiffies, QLCNIC_READD_AGE * HZ + time))
238 tmp_fil->ftime = jiffies;
239 return;
Shahed Shaikh53643a72013-02-18 13:22:37 +0000240 }
241
242 fil = kzalloc(sizeof(struct qlcnic_filter), GFP_ATOMIC);
243 if (!fil)
244 return;
245
246 fil->ftime = jiffies;
247 memcpy(fil->faddr, &src_addr, ETH_ALEN);
248 fil->vlan_id = vlan_id;
249 spin_lock(&adapter->rx_mac_learn_lock);
250 hlist_add_head(&(fil->fnode), head);
251 adapter->rx_fhash.fnum++;
252 spin_unlock(&adapter->rx_mac_learn_lock);
253 } else {
Shahed Shaikhe0d138d2013-08-02 23:15:55 -0400254 head = &adapter->fhash.fhead[hindex];
Shahed Shaikh53643a72013-02-18 13:22:37 +0000255
Shahed Shaikhe0d138d2013-08-02 23:15:55 -0400256 spin_lock(&adapter->mac_learn_lock);
Shahed Shaikh53643a72013-02-18 13:22:37 +0000257
Shahed Shaikhe0d138d2013-08-02 23:15:55 -0400258 tmp_fil = qlcnic_find_mac_filter(head, &src_addr, vlan_id);
259 if (tmp_fil) {
Shahed Shaikh53643a72013-02-18 13:22:37 +0000260 op = vlan_id ? QLCNIC_MAC_VLAN_DEL : QLCNIC_MAC_DEL;
261 ret = qlcnic_sre_macaddr_change(adapter,
262 (u8 *)&src_addr,
263 vlan_id, op);
264 if (!ret) {
Shahed Shaikhe0d138d2013-08-02 23:15:55 -0400265 hlist_del(&tmp_fil->fnode);
266 adapter->fhash.fnum--;
Shahed Shaikh53643a72013-02-18 13:22:37 +0000267 }
Shahed Shaikhe0d138d2013-08-02 23:15:55 -0400268
269 spin_unlock(&adapter->mac_learn_lock);
270
271 return;
Shahed Shaikh53643a72013-02-18 13:22:37 +0000272 }
Shahed Shaikhe0d138d2013-08-02 23:15:55 -0400273
274 spin_unlock(&adapter->mac_learn_lock);
275
276 head = &adapter->rx_fhash.fhead[hindex];
277
278 spin_lock(&adapter->rx_mac_learn_lock);
279
280 tmp_fil = qlcnic_find_mac_filter(head, &src_addr, vlan_id);
281 if (tmp_fil)
282 qlcnic_delete_rx_list_mac(adapter, tmp_fil, &src_addr,
283 vlan_id);
284
Shahed Shaikh53643a72013-02-18 13:22:37 +0000285 spin_unlock(&adapter->rx_mac_learn_lock);
286 }
287}
288
Sony Chacko7e2cf4f2013-01-01 03:20:17 +0000289void qlcnic_82xx_change_filter(struct qlcnic_adapter *adapter, u64 *uaddr,
Rajesh Borundiaf80bc8f2013-04-19 07:01:08 +0000290 u16 vlan_id)
Sony Chackoc70001a2012-11-28 04:34:26 +0000291{
292 struct cmd_desc_type0 *hwdesc;
293 struct qlcnic_nic_req *req;
294 struct qlcnic_mac_req *mac_req;
295 struct qlcnic_vlan_req *vlan_req;
Sony Chacko7e2cf4f2013-01-01 03:20:17 +0000296 struct qlcnic_host_tx_ring *tx_ring = adapter->tx_ring;
Sony Chackoc70001a2012-11-28 04:34:26 +0000297 u32 producer;
298 u64 word;
299
300 producer = tx_ring->producer;
301 hwdesc = &tx_ring->desc_head[tx_ring->producer];
302
303 req = (struct qlcnic_nic_req *)hwdesc;
304 memset(req, 0, sizeof(struct qlcnic_nic_req));
305 req->qhdr = cpu_to_le64(QLCNIC_REQUEST << 23);
306
307 word = QLCNIC_MAC_EVENT | ((u64)(adapter->portnum) << 16);
308 req->req_hdr = cpu_to_le64(word);
309
310 mac_req = (struct qlcnic_mac_req *)&(req->words[0]);
311 mac_req->op = vlan_id ? QLCNIC_MAC_VLAN_ADD : QLCNIC_MAC_ADD;
Shahed Shaikh4a99ab52013-08-02 23:15:54 -0400312 memcpy(mac_req->mac_addr, uaddr, ETH_ALEN);
Sony Chackoc70001a2012-11-28 04:34:26 +0000313
314 vlan_req = (struct qlcnic_vlan_req *)&req->words[1];
Rajesh Borundiaf80bc8f2013-04-19 07:01:08 +0000315 vlan_req->vlan_id = cpu_to_le16(vlan_id);
Sony Chackoc70001a2012-11-28 04:34:26 +0000316
317 tx_ring->producer = get_next_index(producer, tx_ring->num_desc);
318 smp_mb();
319}
320
Sony Chackod17dd0d2012-11-28 04:34:27 +0000321static void qlcnic_send_filter(struct qlcnic_adapter *adapter,
Sony Chackod17dd0d2012-11-28 04:34:27 +0000322 struct cmd_desc_type0 *first_desc,
323 struct sk_buff *skb)
Sony Chackoc70001a2012-11-28 04:34:26 +0000324{
Sony Chackoc70001a2012-11-28 04:34:26 +0000325 struct qlcnic_filter *fil, *tmp_fil;
Sasha Levinb67bfe02013-02-27 17:06:00 -0800326 struct hlist_node *n;
Sony Chackoc70001a2012-11-28 04:34:26 +0000327 struct hlist_head *head;
Sony Chacko4be41e92013-01-01 03:20:20 +0000328 struct net_device *netdev = adapter->netdev;
Sony Chacko7e2cf4f2013-01-01 03:20:17 +0000329 struct ethhdr *phdr = (struct ethhdr *)(skb->data);
Sony Chackoc70001a2012-11-28 04:34:26 +0000330 u64 src_addr = 0;
Rajesh Borundiaf80bc8f2013-04-19 07:01:08 +0000331 u16 vlan_id = 0;
Sony Chackoc70001a2012-11-28 04:34:26 +0000332 u8 hindex;
333
Sony Chacko4be41e92013-01-01 03:20:20 +0000334 if (ether_addr_equal(phdr->h_source, adapter->mac_addr))
Sony Chackoc70001a2012-11-28 04:34:26 +0000335 return;
336
Sony Chacko4be41e92013-01-01 03:20:20 +0000337 if (adapter->fhash.fnum >= adapter->fhash.fmax) {
338 adapter->stats.mac_filter_limit_overrun++;
339 netdev_info(netdev, "Can not add more than %d mac addresses\n",
340 adapter->fhash.fmax);
Sony Chackoc70001a2012-11-28 04:34:26 +0000341 return;
Sony Chacko4be41e92013-01-01 03:20:20 +0000342 }
Sony Chackoc70001a2012-11-28 04:34:26 +0000343
Sony Chackoc70001a2012-11-28 04:34:26 +0000344 memcpy(&src_addr, phdr->h_source, ETH_ALEN);
Sony Chacko4be41e92013-01-01 03:20:20 +0000345 hindex = qlcnic_mac_hash(src_addr) & (adapter->fhash.fbucket_size - 1);
Sony Chackoc70001a2012-11-28 04:34:26 +0000346 head = &(adapter->fhash.fhead[hindex]);
347
Sasha Levinb67bfe02013-02-27 17:06:00 -0800348 hlist_for_each_entry_safe(tmp_fil, n, head, fnode) {
Sony Chackoc70001a2012-11-28 04:34:26 +0000349 if (!memcmp(tmp_fil->faddr, &src_addr, ETH_ALEN) &&
Sony Chacko7e2cf4f2013-01-01 03:20:17 +0000350 tmp_fil->vlan_id == vlan_id) {
Sony Chackod17dd0d2012-11-28 04:34:27 +0000351 if (jiffies > (QLCNIC_READD_AGE * HZ + tmp_fil->ftime))
Sony Chacko7e2cf4f2013-01-01 03:20:17 +0000352 qlcnic_change_filter(adapter, &src_addr,
353 vlan_id);
Sony Chackoc70001a2012-11-28 04:34:26 +0000354 tmp_fil->ftime = jiffies;
355 return;
356 }
357 }
358
359 fil = kzalloc(sizeof(struct qlcnic_filter), GFP_ATOMIC);
360 if (!fil)
361 return;
362
Sony Chacko7e2cf4f2013-01-01 03:20:17 +0000363 qlcnic_change_filter(adapter, &src_addr, vlan_id);
Sony Chackoc70001a2012-11-28 04:34:26 +0000364 fil->ftime = jiffies;
365 fil->vlan_id = vlan_id;
366 memcpy(fil->faddr, &src_addr, ETH_ALEN);
367 spin_lock(&adapter->mac_learn_lock);
368 hlist_add_head(&(fil->fnode), head);
369 adapter->fhash.fnum++;
370 spin_unlock(&adapter->mac_learn_lock);
371}
372
Sony Chackod17dd0d2012-11-28 04:34:27 +0000373static int qlcnic_tx_pkt(struct qlcnic_adapter *adapter,
Himanshu Madhani012ec812013-08-21 11:24:10 -0400374 struct cmd_desc_type0 *first_desc, struct sk_buff *skb,
375 struct qlcnic_host_tx_ring *tx_ring)
Sony Chackoc70001a2012-11-28 04:34:26 +0000376{
Sony Chackod17dd0d2012-11-28 04:34:27 +0000377 u8 l4proto, opcode = 0, hdr_len = 0;
Sony Chackoc70001a2012-11-28 04:34:26 +0000378 u16 flags = 0, vlan_tci = 0;
Sony Chackod17dd0d2012-11-28 04:34:27 +0000379 int copied, offset, copy_len, size;
Sony Chackoc70001a2012-11-28 04:34:26 +0000380 struct cmd_desc_type0 *hwdesc;
381 struct vlan_ethhdr *vh;
Sony Chackoc70001a2012-11-28 04:34:26 +0000382 u16 protocol = ntohs(skb->protocol);
383 u32 producer = tx_ring->producer;
384
385 if (protocol == ETH_P_8021Q) {
386 vh = (struct vlan_ethhdr *)skb->data;
387 flags = FLAGS_VLAN_TAGGED;
388 vlan_tci = ntohs(vh->h_vlan_TCI);
389 protocol = ntohs(vh->h_vlan_encapsulated_proto);
390 } else if (vlan_tx_tag_present(skb)) {
391 flags = FLAGS_VLAN_OOB;
392 vlan_tci = vlan_tx_tag_get(skb);
393 }
Rajesh Borundia91b72822013-04-19 07:01:12 +0000394 if (unlikely(adapter->tx_pvid)) {
Sony Chackoc70001a2012-11-28 04:34:26 +0000395 if (vlan_tci && !(adapter->flags & QLCNIC_TAGGING_ENABLED))
396 return -EIO;
397 if (vlan_tci && (adapter->flags & QLCNIC_TAGGING_ENABLED))
398 goto set_flags;
399
400 flags = FLAGS_VLAN_OOB;
Rajesh Borundia91b72822013-04-19 07:01:12 +0000401 vlan_tci = adapter->tx_pvid;
Sony Chackoc70001a2012-11-28 04:34:26 +0000402 }
403set_flags:
404 qlcnic_set_tx_vlan_tci(first_desc, vlan_tci);
405 qlcnic_set_tx_flags_opcode(first_desc, flags, opcode);
406
407 if (*(skb->data) & BIT_0) {
408 flags |= BIT_0;
409 memcpy(&first_desc->eth_addr, skb->data, ETH_ALEN);
410 }
411 opcode = TX_ETHER_PKT;
Sritej Velaga3eead212013-04-18 08:10:05 +0000412 if (skb_is_gso(skb)) {
Sony Chackoc70001a2012-11-28 04:34:26 +0000413 hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
Sony Chackoc70001a2012-11-28 04:34:26 +0000414 first_desc->mss = cpu_to_le16(skb_shinfo(skb)->gso_size);
415 first_desc->total_hdr_length = hdr_len;
Sony Chackoc70001a2012-11-28 04:34:26 +0000416 opcode = (protocol == ETH_P_IPV6) ? TX_TCP_LSO6 : TX_TCP_LSO;
417
418 /* For LSO, we need to copy the MAC/IP/TCP headers into
419 * the descriptor ring */
420 copied = 0;
421 offset = 2;
422
423 if (flags & FLAGS_VLAN_OOB) {
424 first_desc->total_hdr_length += VLAN_HLEN;
425 first_desc->tcp_hdr_offset = VLAN_HLEN;
426 first_desc->ip_hdr_offset = VLAN_HLEN;
Sony Chackod17dd0d2012-11-28 04:34:27 +0000427
Sony Chackoc70001a2012-11-28 04:34:26 +0000428 /* Only in case of TSO on vlan device */
429 flags |= FLAGS_VLAN_TAGGED;
430
431 /* Create a TSO vlan header template for firmware */
Sony Chackoc70001a2012-11-28 04:34:26 +0000432 hwdesc = &tx_ring->desc_head[producer];
433 tx_ring->cmd_buf_arr[producer].skb = NULL;
434
435 copy_len = min((int)sizeof(struct cmd_desc_type0) -
Sony Chackod17dd0d2012-11-28 04:34:27 +0000436 offset, hdr_len + VLAN_HLEN);
Sony Chackoc70001a2012-11-28 04:34:26 +0000437
438 vh = (struct vlan_ethhdr *)((char *) hwdesc + 2);
439 skb_copy_from_linear_data(skb, vh, 12);
440 vh->h_vlan_proto = htons(ETH_P_8021Q);
441 vh->h_vlan_TCI = htons(vlan_tci);
442
443 skb_copy_from_linear_data_offset(skb, 12,
Sony Chackod17dd0d2012-11-28 04:34:27 +0000444 (char *)vh + 16,
445 copy_len - 16);
Sony Chackoc70001a2012-11-28 04:34:26 +0000446 copied = copy_len - VLAN_HLEN;
447 offset = 0;
Sony Chackoc70001a2012-11-28 04:34:26 +0000448 producer = get_next_index(producer, tx_ring->num_desc);
449 }
450
451 while (copied < hdr_len) {
Sony Chackod17dd0d2012-11-28 04:34:27 +0000452 size = (int)sizeof(struct cmd_desc_type0) - offset;
453 copy_len = min(size, (hdr_len - copied));
Sony Chackoc70001a2012-11-28 04:34:26 +0000454 hwdesc = &tx_ring->desc_head[producer];
455 tx_ring->cmd_buf_arr[producer].skb = NULL;
Sony Chackoc70001a2012-11-28 04:34:26 +0000456 skb_copy_from_linear_data_offset(skb, copied,
Sony Chackod17dd0d2012-11-28 04:34:27 +0000457 (char *)hwdesc +
458 offset, copy_len);
Sony Chackoc70001a2012-11-28 04:34:26 +0000459 copied += copy_len;
460 offset = 0;
Sony Chackoc70001a2012-11-28 04:34:26 +0000461 producer = get_next_index(producer, tx_ring->num_desc);
462 }
463
464 tx_ring->producer = producer;
465 smp_mb();
466 adapter->stats.lso_frames++;
467
468 } else if (skb->ip_summed == CHECKSUM_PARTIAL) {
Sony Chackoc70001a2012-11-28 04:34:26 +0000469 if (protocol == ETH_P_IP) {
470 l4proto = ip_hdr(skb)->protocol;
471
472 if (l4proto == IPPROTO_TCP)
473 opcode = TX_TCP_PKT;
474 else if (l4proto == IPPROTO_UDP)
475 opcode = TX_UDP_PKT;
476 } else if (protocol == ETH_P_IPV6) {
477 l4proto = ipv6_hdr(skb)->nexthdr;
478
479 if (l4proto == IPPROTO_TCP)
480 opcode = TX_TCPV6_PKT;
481 else if (l4proto == IPPROTO_UDP)
482 opcode = TX_UDPV6_PKT;
483 }
484 }
485 first_desc->tcp_hdr_offset += skb_transport_offset(skb);
486 first_desc->ip_hdr_offset += skb_network_offset(skb);
487 qlcnic_set_tx_flags_opcode(first_desc, flags, opcode);
488
489 return 0;
490}
491
Sony Chackod17dd0d2012-11-28 04:34:27 +0000492static int qlcnic_map_tx_skb(struct pci_dev *pdev, struct sk_buff *skb,
493 struct qlcnic_cmd_buffer *pbuf)
Sony Chackoc70001a2012-11-28 04:34:26 +0000494{
495 struct qlcnic_skb_frag *nf;
496 struct skb_frag_struct *frag;
497 int i, nr_frags;
498 dma_addr_t map;
499
500 nr_frags = skb_shinfo(skb)->nr_frags;
501 nf = &pbuf->frag_array[0];
502
Sony Chackod17dd0d2012-11-28 04:34:27 +0000503 map = pci_map_single(pdev, skb->data, skb_headlen(skb),
504 PCI_DMA_TODEVICE);
Sony Chackoc70001a2012-11-28 04:34:26 +0000505 if (pci_dma_mapping_error(pdev, map))
506 goto out_err;
507
508 nf->dma = map;
509 nf->length = skb_headlen(skb);
510
511 for (i = 0; i < nr_frags; i++) {
512 frag = &skb_shinfo(skb)->frags[i];
513 nf = &pbuf->frag_array[i+1];
Sony Chackoc70001a2012-11-28 04:34:26 +0000514 map = skb_frag_dma_map(&pdev->dev, frag, 0, skb_frag_size(frag),
515 DMA_TO_DEVICE);
516 if (dma_mapping_error(&pdev->dev, map))
517 goto unwind;
518
519 nf->dma = map;
520 nf->length = skb_frag_size(frag);
521 }
522
523 return 0;
524
525unwind:
526 while (--i >= 0) {
527 nf = &pbuf->frag_array[i+1];
528 pci_unmap_page(pdev, nf->dma, nf->length, PCI_DMA_TODEVICE);
529 }
530
531 nf = &pbuf->frag_array[0];
532 pci_unmap_single(pdev, nf->dma, skb_headlen(skb), PCI_DMA_TODEVICE);
533
534out_err:
535 return -ENOMEM;
536}
537
Sony Chackod17dd0d2012-11-28 04:34:27 +0000538static void qlcnic_unmap_buffers(struct pci_dev *pdev, struct sk_buff *skb,
539 struct qlcnic_cmd_buffer *pbuf)
Sony Chackoc70001a2012-11-28 04:34:26 +0000540{
541 struct qlcnic_skb_frag *nf = &pbuf->frag_array[0];
Sony Chackod17dd0d2012-11-28 04:34:27 +0000542 int i, nr_frags = skb_shinfo(skb)->nr_frags;
Sony Chackoc70001a2012-11-28 04:34:26 +0000543
544 for (i = 0; i < nr_frags; i++) {
545 nf = &pbuf->frag_array[i+1];
546 pci_unmap_page(pdev, nf->dma, nf->length, PCI_DMA_TODEVICE);
547 }
548
549 nf = &pbuf->frag_array[0];
550 pci_unmap_single(pdev, nf->dma, skb_headlen(skb), PCI_DMA_TODEVICE);
551 pbuf->skb = NULL;
552}
553
Sony Chackod17dd0d2012-11-28 04:34:27 +0000554static inline void qlcnic_clear_cmddesc(u64 *desc)
Sony Chackoc70001a2012-11-28 04:34:26 +0000555{
556 desc[0] = 0ULL;
557 desc[2] = 0ULL;
558 desc[7] = 0ULL;
559}
560
Sony Chackod17dd0d2012-11-28 04:34:27 +0000561netdev_tx_t qlcnic_xmit_frame(struct sk_buff *skb, struct net_device *netdev)
Sony Chackoc70001a2012-11-28 04:34:26 +0000562{
563 struct qlcnic_adapter *adapter = netdev_priv(netdev);
Himanshu Madhani012ec812013-08-21 11:24:10 -0400564 struct qlcnic_host_tx_ring *tx_ring;
Sony Chackoc70001a2012-11-28 04:34:26 +0000565 struct qlcnic_cmd_buffer *pbuf;
566 struct qlcnic_skb_frag *buffrag;
567 struct cmd_desc_type0 *hwdesc, *first_desc;
568 struct pci_dev *pdev;
569 struct ethhdr *phdr;
Sony Chackod17dd0d2012-11-28 04:34:27 +0000570 int i, k, frag_count, delta = 0;
571 u32 producer, num_txd;
Sony Chackoc70001a2012-11-28 04:34:26 +0000572
Sony Chackoc70001a2012-11-28 04:34:26 +0000573 if (!test_bit(__QLCNIC_DEV_UP, &adapter->state)) {
Himanshu Madhani012ec812013-08-21 11:24:10 -0400574 netif_tx_stop_all_queues(netdev);
Sony Chackoc70001a2012-11-28 04:34:26 +0000575 return NETDEV_TX_BUSY;
576 }
577
578 if (adapter->flags & QLCNIC_MACSPOOF) {
579 phdr = (struct ethhdr *)skb->data;
580 if (!ether_addr_equal(phdr->h_source, adapter->mac_addr))
581 goto drop_packet;
582 }
583
Himanshu Madhani012ec812013-08-21 11:24:10 -0400584 if (qlcnic_check_multi_tx(adapter))
585 tx_ring = &adapter->tx_ring[skb_get_queue_mapping(skb)];
586 else
587 tx_ring = &adapter->tx_ring[0];
588 num_txd = tx_ring->num_desc;
589
Sony Chackoc70001a2012-11-28 04:34:26 +0000590 frag_count = skb_shinfo(skb)->nr_frags + 1;
Himanshu Madhani012ec812013-08-21 11:24:10 -0400591
Sony Chackoc70001a2012-11-28 04:34:26 +0000592 /* 14 frags supported for normal packet and
593 * 32 frags supported for TSO packet
594 */
595 if (!skb_is_gso(skb) && frag_count > QLCNIC_MAX_FRAGS_PER_TX) {
Sony Chackoc70001a2012-11-28 04:34:26 +0000596 for (i = 0; i < (frag_count - QLCNIC_MAX_FRAGS_PER_TX); i++)
597 delta += skb_frag_size(&skb_shinfo(skb)->frags[i]);
598
599 if (!__pskb_pull_tail(skb, delta))
600 goto drop_packet;
601
602 frag_count = 1 + skb_shinfo(skb)->nr_frags;
603 }
604
605 if (unlikely(qlcnic_tx_avail(tx_ring) <= TX_STOP_THRESH)) {
Himanshu Madhani012ec812013-08-21 11:24:10 -0400606 netif_tx_stop_queue(tx_ring->txq);
Sony Chackod17dd0d2012-11-28 04:34:27 +0000607 if (qlcnic_tx_avail(tx_ring) > TX_STOP_THRESH) {
Himanshu Madhani012ec812013-08-21 11:24:10 -0400608 netif_tx_start_queue(tx_ring->txq);
Sony Chackod17dd0d2012-11-28 04:34:27 +0000609 } else {
Sony Chackoc70001a2012-11-28 04:34:26 +0000610 adapter->stats.xmit_off++;
Himanshu Madhani012ec812013-08-21 11:24:10 -0400611 tx_ring->xmit_off++;
Sony Chackoc70001a2012-11-28 04:34:26 +0000612 return NETDEV_TX_BUSY;
613 }
614 }
615
616 producer = tx_ring->producer;
617 pbuf = &tx_ring->cmd_buf_arr[producer];
Sony Chackoc70001a2012-11-28 04:34:26 +0000618 pdev = adapter->pdev;
Sony Chackod17dd0d2012-11-28 04:34:27 +0000619 first_desc = &tx_ring->desc_head[producer];
620 hwdesc = &tx_ring->desc_head[producer];
Sony Chackoc70001a2012-11-28 04:34:26 +0000621 qlcnic_clear_cmddesc((u64 *)hwdesc);
622
623 if (qlcnic_map_tx_skb(pdev, skb, pbuf)) {
624 adapter->stats.tx_dma_map_error++;
625 goto drop_packet;
626 }
627
628 pbuf->skb = skb;
629 pbuf->frag_count = frag_count;
630
631 qlcnic_set_tx_frags_len(first_desc, frag_count, skb->len);
632 qlcnic_set_tx_port(first_desc, adapter->portnum);
633
634 for (i = 0; i < frag_count; i++) {
Sony Chackoc70001a2012-11-28 04:34:26 +0000635 k = i % 4;
636
637 if ((k == 0) && (i > 0)) {
638 /* move to next desc.*/
639 producer = get_next_index(producer, num_txd);
640 hwdesc = &tx_ring->desc_head[producer];
641 qlcnic_clear_cmddesc((u64 *)hwdesc);
642 tx_ring->cmd_buf_arr[producer].skb = NULL;
643 }
644
645 buffrag = &pbuf->frag_array[i];
Sony Chackoc70001a2012-11-28 04:34:26 +0000646 hwdesc->buffer_length[k] = cpu_to_le16(buffrag->length);
647 switch (k) {
648 case 0:
649 hwdesc->addr_buffer1 = cpu_to_le64(buffrag->dma);
650 break;
651 case 1:
652 hwdesc->addr_buffer2 = cpu_to_le64(buffrag->dma);
653 break;
654 case 2:
655 hwdesc->addr_buffer3 = cpu_to_le64(buffrag->dma);
656 break;
657 case 3:
658 hwdesc->addr_buffer4 = cpu_to_le64(buffrag->dma);
659 break;
660 }
661 }
662
663 tx_ring->producer = get_next_index(producer, num_txd);
664 smp_mb();
665
Himanshu Madhani012ec812013-08-21 11:24:10 -0400666 if (unlikely(qlcnic_tx_pkt(adapter, first_desc, skb, tx_ring)))
Sony Chackoc70001a2012-11-28 04:34:26 +0000667 goto unwind_buff;
668
Jitendra Kalsariafe1adc62013-01-25 10:20:40 +0000669 if (adapter->drv_mac_learn)
Sony Chacko4be41e92013-01-01 03:20:20 +0000670 qlcnic_send_filter(adapter, first_desc, skb);
Sony Chackoc70001a2012-11-28 04:34:26 +0000671
672 adapter->stats.txbytes += skb->len;
673 adapter->stats.xmitcalled++;
Himanshu Madhani012ec812013-08-21 11:24:10 -0400674 tx_ring->xmit_called++;
Sony Chackoc70001a2012-11-28 04:34:26 +0000675
676 qlcnic_update_cmd_producer(tx_ring);
677
678 return NETDEV_TX_OK;
679
680unwind_buff:
681 qlcnic_unmap_buffers(pdev, skb, pbuf);
682drop_packet:
683 adapter->stats.txdropped++;
684 dev_kfree_skb_any(skb);
685 return NETDEV_TX_OK;
686}
687
Sony Chacko7f9664522013-01-01 03:20:19 +0000688void qlcnic_advert_link_change(struct qlcnic_adapter *adapter, int linkup)
Sony Chackoc70001a2012-11-28 04:34:26 +0000689{
690 struct net_device *netdev = adapter->netdev;
691
692 if (adapter->ahw->linkup && !linkup) {
693 netdev_info(netdev, "NIC Link is down\n");
694 adapter->ahw->linkup = 0;
695 if (netif_running(netdev)) {
696 netif_carrier_off(netdev);
Himanshu Madhani012ec812013-08-21 11:24:10 -0400697 netif_tx_stop_all_queues(netdev);
Sony Chackoc70001a2012-11-28 04:34:26 +0000698 }
699 } else if (!adapter->ahw->linkup && linkup) {
700 netdev_info(netdev, "NIC Link is up\n");
701 adapter->ahw->linkup = 1;
702 if (netif_running(netdev)) {
703 netif_carrier_on(netdev);
704 netif_wake_queue(netdev);
705 }
706 }
707}
708
Sony Chackod17dd0d2012-11-28 04:34:27 +0000709static int qlcnic_alloc_rx_skb(struct qlcnic_adapter *adapter,
710 struct qlcnic_host_rds_ring *rds_ring,
711 struct qlcnic_rx_buffer *buffer)
Sony Chackoc70001a2012-11-28 04:34:26 +0000712{
713 struct sk_buff *skb;
714 dma_addr_t dma;
715 struct pci_dev *pdev = adapter->pdev;
716
717 skb = netdev_alloc_skb(adapter->netdev, rds_ring->skb_size);
718 if (!skb) {
719 adapter->stats.skb_alloc_failure++;
720 return -ENOMEM;
721 }
722
723 skb_reserve(skb, NET_IP_ALIGN);
Sony Chacko4be41e92013-01-01 03:20:20 +0000724 dma = pci_map_single(pdev, skb->data,
725 rds_ring->dma_size, PCI_DMA_FROMDEVICE);
Sony Chackoc70001a2012-11-28 04:34:26 +0000726
727 if (pci_dma_mapping_error(pdev, dma)) {
728 adapter->stats.rx_dma_map_error++;
729 dev_kfree_skb_any(skb);
730 return -ENOMEM;
731 }
732
733 buffer->skb = skb;
734 buffer->dma = dma;
735
736 return 0;
737}
738
739static void qlcnic_post_rx_buffers_nodb(struct qlcnic_adapter *adapter,
Sony Chacko4be41e92013-01-01 03:20:20 +0000740 struct qlcnic_host_rds_ring *rds_ring,
741 u8 ring_id)
Sony Chackoc70001a2012-11-28 04:34:26 +0000742{
743 struct rcv_desc *pdesc;
744 struct qlcnic_rx_buffer *buffer;
745 int count = 0;
Sony Chacko4be41e92013-01-01 03:20:20 +0000746 uint32_t producer, handle;
Sony Chackoc70001a2012-11-28 04:34:26 +0000747 struct list_head *head;
748
749 if (!spin_trylock(&rds_ring->lock))
750 return;
751
752 producer = rds_ring->producer;
Sony Chackoc70001a2012-11-28 04:34:26 +0000753 head = &rds_ring->free_list;
Sony Chackod17dd0d2012-11-28 04:34:27 +0000754 while (!list_empty(head)) {
Sony Chackoc70001a2012-11-28 04:34:26 +0000755 buffer = list_entry(head->next, struct qlcnic_rx_buffer, list);
756
757 if (!buffer->skb) {
758 if (qlcnic_alloc_rx_skb(adapter, rds_ring, buffer))
759 break;
760 }
Sony Chackoc70001a2012-11-28 04:34:26 +0000761 count++;
762 list_del(&buffer->list);
763
764 /* make a rcv descriptor */
765 pdesc = &rds_ring->desc_head[producer];
Sony Chacko4be41e92013-01-01 03:20:20 +0000766 handle = qlcnic_get_ref_handle(adapter,
767 buffer->ref_handle, ring_id);
768 pdesc->reference_handle = cpu_to_le16(handle);
Sony Chackoc70001a2012-11-28 04:34:26 +0000769 pdesc->buffer_length = cpu_to_le32(rds_ring->dma_size);
770 pdesc->addr_buffer = cpu_to_le64(buffer->dma);
Sony Chackoc70001a2012-11-28 04:34:26 +0000771 producer = get_next_index(producer, rds_ring->num_desc);
772 }
Sony Chackoc70001a2012-11-28 04:34:26 +0000773 if (count) {
774 rds_ring->producer = producer;
775 writel((producer - 1) & (rds_ring->num_desc - 1),
Sony Chackod17dd0d2012-11-28 04:34:27 +0000776 rds_ring->crb_rcv_producer);
Sony Chackoc70001a2012-11-28 04:34:26 +0000777 }
778 spin_unlock(&rds_ring->lock);
779}
780
Sony Chacko4be41e92013-01-01 03:20:20 +0000781static int qlcnic_process_cmd_ring(struct qlcnic_adapter *adapter,
782 struct qlcnic_host_tx_ring *tx_ring,
783 int budget)
Sony Chackoc70001a2012-11-28 04:34:26 +0000784{
785 u32 sw_consumer, hw_consumer;
Sony Chackod17dd0d2012-11-28 04:34:27 +0000786 int i, done, count = 0;
Sony Chackoc70001a2012-11-28 04:34:26 +0000787 struct qlcnic_cmd_buffer *buffer;
788 struct pci_dev *pdev = adapter->pdev;
789 struct net_device *netdev = adapter->netdev;
790 struct qlcnic_skb_frag *frag;
Sony Chackoc70001a2012-11-28 04:34:26 +0000791
Sony Chackoc70001a2012-11-28 04:34:26 +0000792 sw_consumer = tx_ring->sw_consumer;
793 hw_consumer = le32_to_cpu(*(tx_ring->hw_consumer));
794
795 while (sw_consumer != hw_consumer) {
796 buffer = &tx_ring->cmd_buf_arr[sw_consumer];
797 if (buffer->skb) {
798 frag = &buffer->frag_array[0];
799 pci_unmap_single(pdev, frag->dma, frag->length,
800 PCI_DMA_TODEVICE);
801 frag->dma = 0ULL;
802 for (i = 1; i < buffer->frag_count; i++) {
803 frag++;
804 pci_unmap_page(pdev, frag->dma, frag->length,
805 PCI_DMA_TODEVICE);
806 frag->dma = 0ULL;
807 }
Sony Chackoc70001a2012-11-28 04:34:26 +0000808 adapter->stats.xmitfinished++;
Himanshu Madhani012ec812013-08-21 11:24:10 -0400809 tx_ring->xmit_finished++;
Sony Chackoc70001a2012-11-28 04:34:26 +0000810 dev_kfree_skb_any(buffer->skb);
811 buffer->skb = NULL;
812 }
813
814 sw_consumer = get_next_index(sw_consumer, tx_ring->num_desc);
Sony Chacko4be41e92013-01-01 03:20:20 +0000815 if (++count >= budget)
Sony Chackoc70001a2012-11-28 04:34:26 +0000816 break;
817 }
818
819 if (count && netif_running(netdev)) {
820 tx_ring->sw_consumer = sw_consumer;
Sony Chackoc70001a2012-11-28 04:34:26 +0000821 smp_mb();
Himanshu Madhani012ec812013-08-21 11:24:10 -0400822 if (netif_tx_queue_stopped(tx_ring->txq) &&
823 netif_carrier_ok(netdev)) {
Sony Chackoc70001a2012-11-28 04:34:26 +0000824 if (qlcnic_tx_avail(tx_ring) > TX_STOP_THRESH) {
Himanshu Madhani012ec812013-08-21 11:24:10 -0400825 netif_tx_wake_queue(tx_ring->txq);
Sony Chackoc70001a2012-11-28 04:34:26 +0000826 adapter->stats.xmit_on++;
Himanshu Madhani012ec812013-08-21 11:24:10 -0400827 tx_ring->xmit_on++;
Sony Chackoc70001a2012-11-28 04:34:26 +0000828 }
829 }
830 adapter->tx_timeo_cnt = 0;
831 }
832 /*
833 * If everything is freed up to consumer then check if the ring is full
834 * If the ring is full then check if more needs to be freed and
835 * schedule the call back again.
836 *
837 * This happens when there are 2 CPUs. One could be freeing and the
838 * other filling it. If the ring is full when we get out of here and
839 * the card has already interrupted the host then the host can miss the
840 * interrupt.
841 *
842 * There is still a possible race condition and the host could miss an
843 * interrupt. The card has to take care of this.
844 */
845 hw_consumer = le32_to_cpu(*(tx_ring->hw_consumer));
846 done = (sw_consumer == hw_consumer);
Sony Chackoc70001a2012-11-28 04:34:26 +0000847
848 return done;
849}
850
851static int qlcnic_poll(struct napi_struct *napi, int budget)
852{
Sony Chacko4be41e92013-01-01 03:20:20 +0000853 int tx_complete, work_done;
Sony Chackod17dd0d2012-11-28 04:34:27 +0000854 struct qlcnic_host_sds_ring *sds_ring;
855 struct qlcnic_adapter *adapter;
Himanshu Madhani012ec812013-08-21 11:24:10 -0400856 struct qlcnic_host_tx_ring *tx_ring;
Sony Chackoc70001a2012-11-28 04:34:26 +0000857
Sony Chackod17dd0d2012-11-28 04:34:27 +0000858 sds_ring = container_of(napi, struct qlcnic_host_sds_ring, napi);
859 adapter = sds_ring->adapter;
Himanshu Madhani012ec812013-08-21 11:24:10 -0400860 tx_ring = sds_ring->tx_ring;
861
862 tx_complete = qlcnic_process_cmd_ring(adapter, tx_ring,
Sony Chacko4be41e92013-01-01 03:20:20 +0000863 budget);
Sony Chackoc70001a2012-11-28 04:34:26 +0000864 work_done = qlcnic_process_rcv_ring(sds_ring, budget);
Sony Chackoc70001a2012-11-28 04:34:26 +0000865 if ((work_done < budget) && tx_complete) {
866 napi_complete(&sds_ring->napi);
Himanshu Madhani012ec812013-08-21 11:24:10 -0400867 if (test_bit(__QLCNIC_DEV_UP, &adapter->state)) {
Sony Chackoc70001a2012-11-28 04:34:26 +0000868 qlcnic_enable_int(sds_ring);
Himanshu Madhani012ec812013-08-21 11:24:10 -0400869 qlcnic_enable_tx_intr(adapter, tx_ring);
870 }
871 }
872
873 return work_done;
874}
875
876static int qlcnic_tx_poll(struct napi_struct *napi, int budget)
877{
878 struct qlcnic_host_tx_ring *tx_ring;
879 struct qlcnic_adapter *adapter;
880 int work_done;
881
882 tx_ring = container_of(napi, struct qlcnic_host_tx_ring, napi);
883 adapter = tx_ring->adapter;
884
885 work_done = qlcnic_process_cmd_ring(adapter, tx_ring, budget);
886 if (work_done) {
887 napi_complete(&tx_ring->napi);
888 if (test_bit(__QLCNIC_DEV_UP, &adapter->state))
889 qlcnic_enable_tx_intr(adapter, tx_ring);
Sony Chackoc70001a2012-11-28 04:34:26 +0000890 }
891
892 return work_done;
893}
894
895static int qlcnic_rx_poll(struct napi_struct *napi, int budget)
896{
Sony Chackod17dd0d2012-11-28 04:34:27 +0000897 struct qlcnic_host_sds_ring *sds_ring;
898 struct qlcnic_adapter *adapter;
Sony Chackoc70001a2012-11-28 04:34:26 +0000899 int work_done;
900
Sony Chackod17dd0d2012-11-28 04:34:27 +0000901 sds_ring = container_of(napi, struct qlcnic_host_sds_ring, napi);
902 adapter = sds_ring->adapter;
903
Sony Chackoc70001a2012-11-28 04:34:26 +0000904 work_done = qlcnic_process_rcv_ring(sds_ring, budget);
905
906 if (work_done < budget) {
907 napi_complete(&sds_ring->napi);
908 if (test_bit(__QLCNIC_DEV_UP, &adapter->state))
909 qlcnic_enable_int(sds_ring);
910 }
911
912 return work_done;
913}
914
Sony Chackod17dd0d2012-11-28 04:34:27 +0000915static void qlcnic_handle_linkevent(struct qlcnic_adapter *adapter,
916 struct qlcnic_fw_msg *msg)
Sony Chackoc70001a2012-11-28 04:34:26 +0000917{
918 u32 cable_OUI;
Sony Chackod17dd0d2012-11-28 04:34:27 +0000919 u16 cable_len, link_speed;
920 u8 link_status, module, duplex, autoneg, lb_status = 0;
Sony Chackoc70001a2012-11-28 04:34:26 +0000921 struct net_device *netdev = adapter->netdev;
922
Sony Chacko79788452012-12-04 03:33:53 +0000923 adapter->ahw->has_link_events = 1;
Sony Chackoc70001a2012-11-28 04:34:26 +0000924
925 cable_OUI = msg->body[1] & 0xffffffff;
926 cable_len = (msg->body[1] >> 32) & 0xffff;
927 link_speed = (msg->body[1] >> 48) & 0xffff;
928
929 link_status = msg->body[2] & 0xff;
930 duplex = (msg->body[2] >> 16) & 0xff;
931 autoneg = (msg->body[2] >> 24) & 0xff;
932 lb_status = (msg->body[2] >> 32) & 0x3;
933
934 module = (msg->body[2] >> 8) & 0xff;
935 if (module == LINKEVENT_MODULE_TWINAX_UNSUPPORTED_CABLE)
Sony Chackod17dd0d2012-11-28 04:34:27 +0000936 dev_info(&netdev->dev,
937 "unsupported cable: OUI 0x%x, length %d\n",
938 cable_OUI, cable_len);
Sony Chackoc70001a2012-11-28 04:34:26 +0000939 else if (module == LINKEVENT_MODULE_TWINAX_UNSUPPORTED_CABLELEN)
940 dev_info(&netdev->dev, "unsupported cable length %d\n",
Sony Chackod17dd0d2012-11-28 04:34:27 +0000941 cable_len);
Sony Chackoc70001a2012-11-28 04:34:26 +0000942
943 if (!link_status && (lb_status == QLCNIC_ILB_MODE ||
944 lb_status == QLCNIC_ELB_MODE))
945 adapter->ahw->loopback_state |= QLCNIC_LINKEVENT;
946
947 qlcnic_advert_link_change(adapter, link_status);
948
949 if (duplex == LINKEVENT_FULL_DUPLEX)
Sony Chacko79788452012-12-04 03:33:53 +0000950 adapter->ahw->link_duplex = DUPLEX_FULL;
Sony Chackoc70001a2012-11-28 04:34:26 +0000951 else
Sony Chacko79788452012-12-04 03:33:53 +0000952 adapter->ahw->link_duplex = DUPLEX_HALF;
Sony Chackoc70001a2012-11-28 04:34:26 +0000953
Sony Chacko79788452012-12-04 03:33:53 +0000954 adapter->ahw->module_type = module;
955 adapter->ahw->link_autoneg = autoneg;
Sony Chackoc70001a2012-11-28 04:34:26 +0000956
957 if (link_status) {
Sony Chacko79788452012-12-04 03:33:53 +0000958 adapter->ahw->link_speed = link_speed;
Sony Chackoc70001a2012-11-28 04:34:26 +0000959 } else {
Sony Chacko79788452012-12-04 03:33:53 +0000960 adapter->ahw->link_speed = SPEED_UNKNOWN;
961 adapter->ahw->link_duplex = DUPLEX_UNKNOWN;
Sony Chackoc70001a2012-11-28 04:34:26 +0000962 }
963}
964
Sony Chackod17dd0d2012-11-28 04:34:27 +0000965static void qlcnic_handle_fw_message(int desc_cnt, int index,
966 struct qlcnic_host_sds_ring *sds_ring)
Sony Chackoc70001a2012-11-28 04:34:26 +0000967{
968 struct qlcnic_fw_msg msg;
969 struct status_desc *desc;
970 struct qlcnic_adapter *adapter;
971 struct device *dev;
972 int i = 0, opcode, ret;
973
974 while (desc_cnt > 0 && i < 8) {
975 desc = &sds_ring->desc_head[index];
976 msg.words[i++] = le64_to_cpu(desc->status_desc_data[0]);
977 msg.words[i++] = le64_to_cpu(desc->status_desc_data[1]);
978
979 index = get_next_index(index, sds_ring->num_desc);
980 desc_cnt--;
981 }
982
983 adapter = sds_ring->adapter;
984 dev = &adapter->pdev->dev;
985 opcode = qlcnic_get_nic_msg_opcode(msg.body[0]);
986
987 switch (opcode) {
988 case QLCNIC_C2H_OPCODE_GET_LINKEVENT_RESPONSE:
989 qlcnic_handle_linkevent(adapter, &msg);
990 break;
991 case QLCNIC_C2H_OPCODE_CONFIG_LOOPBACK:
992 ret = (u32)(msg.body[1]);
993 switch (ret) {
994 case 0:
995 adapter->ahw->loopback_state |= QLCNIC_LB_RESPONSE;
996 break;
997 case 1:
998 dev_info(dev, "loopback already in progress\n");
Jitendra Kalsariab9c11982013-08-02 00:57:39 -0400999 adapter->ahw->diag_cnt = -EINPROGRESS;
Sony Chackoc70001a2012-11-28 04:34:26 +00001000 break;
1001 case 2:
1002 dev_info(dev, "loopback cable is not connected\n");
Jitendra Kalsariab9c11982013-08-02 00:57:39 -04001003 adapter->ahw->diag_cnt = -ENODEV;
Sony Chackoc70001a2012-11-28 04:34:26 +00001004 break;
1005 default:
Sony Chackod17dd0d2012-11-28 04:34:27 +00001006 dev_info(dev,
1007 "loopback configure request failed, err %x\n",
1008 ret);
Jitendra Kalsariab9c11982013-08-02 00:57:39 -04001009 adapter->ahw->diag_cnt = -EIO;
Sony Chackoc70001a2012-11-28 04:34:26 +00001010 break;
1011 }
1012 break;
Sucheta Chakraborty2d8ebca2013-08-23 13:38:27 -04001013 case QLCNIC_C2H_OPCODE_GET_DCB_AEN:
Sucheta Chakraborty1de899d2013-10-18 12:22:33 -04001014 qlcnic_dcb_aen_handler(adapter->dcb, (void *)&msg);
Sucheta Chakraborty2d8ebca2013-08-23 13:38:27 -04001015 break;
Sony Chackoc70001a2012-11-28 04:34:26 +00001016 default:
1017 break;
1018 }
1019}
1020
Sony Chacko4be41e92013-01-01 03:20:20 +00001021struct sk_buff *qlcnic_process_rxbuf(struct qlcnic_adapter *adapter,
1022 struct qlcnic_host_rds_ring *ring,
1023 u16 index, u16 cksum)
Sony Chackoc70001a2012-11-28 04:34:26 +00001024{
1025 struct qlcnic_rx_buffer *buffer;
1026 struct sk_buff *skb;
1027
Sony Chacko4be41e92013-01-01 03:20:20 +00001028 buffer = &ring->rx_buf_arr[index];
Sony Chackoc70001a2012-11-28 04:34:26 +00001029 if (unlikely(buffer->skb == NULL)) {
1030 WARN_ON(1);
1031 return NULL;
1032 }
1033
Sony Chacko4be41e92013-01-01 03:20:20 +00001034 pci_unmap_single(adapter->pdev, buffer->dma, ring->dma_size,
Sony Chackod17dd0d2012-11-28 04:34:27 +00001035 PCI_DMA_FROMDEVICE);
Sony Chackoc70001a2012-11-28 04:34:26 +00001036
1037 skb = buffer->skb;
Sony Chackoc70001a2012-11-28 04:34:26 +00001038 if (likely((adapter->netdev->features & NETIF_F_RXCSUM) &&
Sony Chackod17dd0d2012-11-28 04:34:27 +00001039 (cksum == STATUS_CKSUM_OK || cksum == STATUS_CKSUM_LOOP))) {
Sony Chackoc70001a2012-11-28 04:34:26 +00001040 adapter->stats.csummed++;
1041 skb->ip_summed = CHECKSUM_UNNECESSARY;
1042 } else {
1043 skb_checksum_none_assert(skb);
1044 }
1045
Sony Chacko4be41e92013-01-01 03:20:20 +00001046
Sony Chackoc70001a2012-11-28 04:34:26 +00001047 buffer->skb = NULL;
1048
1049 return skb;
1050}
1051
Sony Chackod17dd0d2012-11-28 04:34:27 +00001052static inline int qlcnic_check_rx_tagging(struct qlcnic_adapter *adapter,
1053 struct sk_buff *skb, u16 *vlan_tag)
Sony Chackoc70001a2012-11-28 04:34:26 +00001054{
1055 struct ethhdr *eth_hdr;
1056
1057 if (!__vlan_get_tag(skb, vlan_tag)) {
Sony Chackod17dd0d2012-11-28 04:34:27 +00001058 eth_hdr = (struct ethhdr *)skb->data;
Sony Chackoc70001a2012-11-28 04:34:26 +00001059 memmove(skb->data + VLAN_HLEN, eth_hdr, ETH_ALEN * 2);
1060 skb_pull(skb, VLAN_HLEN);
1061 }
Rajesh Borundia91b72822013-04-19 07:01:12 +00001062 if (!adapter->rx_pvid)
Sony Chackoc70001a2012-11-28 04:34:26 +00001063 return 0;
1064
Rajesh Borundia91b72822013-04-19 07:01:12 +00001065 if (*vlan_tag == adapter->rx_pvid) {
Sony Chackoc70001a2012-11-28 04:34:26 +00001066 /* Outer vlan tag. Packet should follow non-vlan path */
1067 *vlan_tag = 0xffff;
1068 return 0;
1069 }
1070 if (adapter->flags & QLCNIC_TAGGING_ENABLED)
1071 return 0;
1072
1073 return -EINVAL;
1074}
1075
1076static struct qlcnic_rx_buffer *
1077qlcnic_process_rcv(struct qlcnic_adapter *adapter,
Sony Chackod17dd0d2012-11-28 04:34:27 +00001078 struct qlcnic_host_sds_ring *sds_ring, int ring,
1079 u64 sts_data0)
Sony Chackoc70001a2012-11-28 04:34:26 +00001080{
1081 struct net_device *netdev = adapter->netdev;
1082 struct qlcnic_recv_context *recv_ctx = adapter->recv_ctx;
1083 struct qlcnic_rx_buffer *buffer;
1084 struct sk_buff *skb;
1085 struct qlcnic_host_rds_ring *rds_ring;
Shahed Shaikh53643a72013-02-18 13:22:37 +00001086 int index, length, cksum, pkt_offset, is_lb_pkt;
1087 u16 vid = 0xffff, t_vid;
Sony Chackoc70001a2012-11-28 04:34:26 +00001088
1089 if (unlikely(ring >= adapter->max_rds_rings))
1090 return NULL;
1091
1092 rds_ring = &recv_ctx->rds_rings[ring];
1093
1094 index = qlcnic_get_sts_refhandle(sts_data0);
1095 if (unlikely(index >= rds_ring->num_desc))
1096 return NULL;
1097
1098 buffer = &rds_ring->rx_buf_arr[index];
Sony Chackoc70001a2012-11-28 04:34:26 +00001099 length = qlcnic_get_sts_totallength(sts_data0);
1100 cksum = qlcnic_get_sts_status(sts_data0);
1101 pkt_offset = qlcnic_get_sts_pkt_offset(sts_data0);
1102
1103 skb = qlcnic_process_rxbuf(adapter, rds_ring, index, cksum);
1104 if (!skb)
1105 return buffer;
1106
Shahed Shaikh53643a72013-02-18 13:22:37 +00001107 if (adapter->drv_mac_learn &&
1108 (adapter->flags & QLCNIC_ESWITCH_ENABLED)) {
1109 t_vid = 0;
1110 is_lb_pkt = qlcnic_82xx_is_lb_pkt(sts_data0);
Rajesh Borundiaf80bc8f2013-04-19 07:01:08 +00001111 qlcnic_add_lb_filter(adapter, skb, is_lb_pkt, t_vid);
Shahed Shaikh53643a72013-02-18 13:22:37 +00001112 }
1113
Sony Chackoc70001a2012-11-28 04:34:26 +00001114 if (length > rds_ring->skb_size)
1115 skb_put(skb, rds_ring->skb_size);
1116 else
1117 skb_put(skb, length);
1118
1119 if (pkt_offset)
1120 skb_pull(skb, pkt_offset);
1121
1122 if (unlikely(qlcnic_check_rx_tagging(adapter, skb, &vid))) {
1123 adapter->stats.rxdropped++;
1124 dev_kfree_skb(skb);
1125 return buffer;
1126 }
1127
1128 skb->protocol = eth_type_trans(skb, netdev);
1129
1130 if (vid != 0xffff)
Patrick McHardy86a9bad2013-04-19 02:04:30 +00001131 __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q), vid);
Sony Chackoc70001a2012-11-28 04:34:26 +00001132
1133 napi_gro_receive(&sds_ring->napi, skb);
1134
1135 adapter->stats.rx_pkts++;
1136 adapter->stats.rxbytes += length;
1137
1138 return buffer;
1139}
1140
1141#define QLC_TCP_HDR_SIZE 20
1142#define QLC_TCP_TS_OPTION_SIZE 12
1143#define QLC_TCP_TS_HDR_SIZE (QLC_TCP_HDR_SIZE + QLC_TCP_TS_OPTION_SIZE)
1144
1145static struct qlcnic_rx_buffer *
1146qlcnic_process_lro(struct qlcnic_adapter *adapter,
Sony Chackod17dd0d2012-11-28 04:34:27 +00001147 int ring, u64 sts_data0, u64 sts_data1)
Sony Chackoc70001a2012-11-28 04:34:26 +00001148{
1149 struct net_device *netdev = adapter->netdev;
1150 struct qlcnic_recv_context *recv_ctx = adapter->recv_ctx;
1151 struct qlcnic_rx_buffer *buffer;
1152 struct sk_buff *skb;
1153 struct qlcnic_host_rds_ring *rds_ring;
1154 struct iphdr *iph;
Shahed Shaikh776e7bd2013-01-25 10:20:35 +00001155 struct ipv6hdr *ipv6h;
Sony Chackoc70001a2012-11-28 04:34:26 +00001156 struct tcphdr *th;
1157 bool push, timestamp;
Shahed Shaikh53643a72013-02-18 13:22:37 +00001158 int index, l2_hdr_offset, l4_hdr_offset, is_lb_pkt;
1159 u16 lro_length, length, data_offset, t_vid, vid = 0xffff;
Sony Chackoc70001a2012-11-28 04:34:26 +00001160 u32 seq_number;
Sony Chackoc70001a2012-11-28 04:34:26 +00001161
1162 if (unlikely(ring > adapter->max_rds_rings))
1163 return NULL;
1164
1165 rds_ring = &recv_ctx->rds_rings[ring];
1166
1167 index = qlcnic_get_lro_sts_refhandle(sts_data0);
1168 if (unlikely(index > rds_ring->num_desc))
1169 return NULL;
1170
1171 buffer = &rds_ring->rx_buf_arr[index];
1172
1173 timestamp = qlcnic_get_lro_sts_timestamp(sts_data0);
1174 lro_length = qlcnic_get_lro_sts_length(sts_data0);
1175 l2_hdr_offset = qlcnic_get_lro_sts_l2_hdr_offset(sts_data0);
1176 l4_hdr_offset = qlcnic_get_lro_sts_l4_hdr_offset(sts_data0);
1177 push = qlcnic_get_lro_sts_push_flag(sts_data0);
1178 seq_number = qlcnic_get_lro_sts_seq_number(sts_data1);
1179
1180 skb = qlcnic_process_rxbuf(adapter, rds_ring, index, STATUS_CKSUM_OK);
1181 if (!skb)
1182 return buffer;
1183
Shahed Shaikh53643a72013-02-18 13:22:37 +00001184 if (adapter->drv_mac_learn &&
1185 (adapter->flags & QLCNIC_ESWITCH_ENABLED)) {
1186 t_vid = 0;
1187 is_lb_pkt = qlcnic_82xx_is_lb_pkt(sts_data0);
Rajesh Borundiaf80bc8f2013-04-19 07:01:08 +00001188 qlcnic_add_lb_filter(adapter, skb, is_lb_pkt, t_vid);
Shahed Shaikh53643a72013-02-18 13:22:37 +00001189 }
1190
Sony Chackoc70001a2012-11-28 04:34:26 +00001191 if (timestamp)
1192 data_offset = l4_hdr_offset + QLC_TCP_TS_HDR_SIZE;
1193 else
1194 data_offset = l4_hdr_offset + QLC_TCP_HDR_SIZE;
1195
1196 skb_put(skb, lro_length + data_offset);
Sony Chackoc70001a2012-11-28 04:34:26 +00001197 skb_pull(skb, l2_hdr_offset);
1198
1199 if (unlikely(qlcnic_check_rx_tagging(adapter, skb, &vid))) {
1200 adapter->stats.rxdropped++;
1201 dev_kfree_skb(skb);
1202 return buffer;
1203 }
1204
1205 skb->protocol = eth_type_trans(skb, netdev);
Shahed Shaikh776e7bd2013-01-25 10:20:35 +00001206
Shahed Shaikh069048f2013-01-30 12:47:12 +00001207 if (ntohs(skb->protocol) == ETH_P_IPV6) {
Shahed Shaikh776e7bd2013-01-25 10:20:35 +00001208 ipv6h = (struct ipv6hdr *)skb->data;
1209 th = (struct tcphdr *)(skb->data + sizeof(struct ipv6hdr));
1210 length = (th->doff << 2) + lro_length;
1211 ipv6h->payload_len = htons(length);
1212 } else {
1213 iph = (struct iphdr *)skb->data;
1214 th = (struct tcphdr *)(skb->data + (iph->ihl << 2));
1215 length = (iph->ihl << 2) + (th->doff << 2) + lro_length;
Li RongQing1bcac3b2013-03-14 22:50:07 +00001216 csum_replace2(&iph->check, iph->tot_len, htons(length));
Shahed Shaikh776e7bd2013-01-25 10:20:35 +00001217 iph->tot_len = htons(length);
Shahed Shaikh776e7bd2013-01-25 10:20:35 +00001218 }
1219
Sony Chackoc70001a2012-11-28 04:34:26 +00001220 th->psh = push;
1221 th->seq = htonl(seq_number);
Sony Chackoc70001a2012-11-28 04:34:26 +00001222 length = skb->len;
1223
Michael S. Tsirkinbd69ba72013-02-07 03:13:13 +00001224 if (adapter->flags & QLCNIC_FW_LRO_MSS_CAP) {
Sony Chackoc70001a2012-11-28 04:34:26 +00001225 skb_shinfo(skb)->gso_size = qlcnic_get_lro_sts_mss(sts_data1);
Michael S. Tsirkinbd69ba72013-02-07 03:13:13 +00001226 if (skb->protocol == htons(ETH_P_IPV6))
1227 skb_shinfo(skb)->gso_type = SKB_GSO_TCPV6;
1228 else
1229 skb_shinfo(skb)->gso_type = SKB_GSO_TCPV4;
1230 }
Sony Chackoc70001a2012-11-28 04:34:26 +00001231
1232 if (vid != 0xffff)
Patrick McHardy86a9bad2013-04-19 02:04:30 +00001233 __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q), vid);
Sony Chackoc70001a2012-11-28 04:34:26 +00001234 netif_receive_skb(skb);
1235
1236 adapter->stats.lro_pkts++;
1237 adapter->stats.lrobytes += length;
1238
1239 return buffer;
1240}
1241
Sony Chackod17dd0d2012-11-28 04:34:27 +00001242int qlcnic_process_rcv_ring(struct qlcnic_host_sds_ring *sds_ring, int max)
Sony Chackoc70001a2012-11-28 04:34:26 +00001243{
Sony Chackod17dd0d2012-11-28 04:34:27 +00001244 struct qlcnic_host_rds_ring *rds_ring;
Sony Chackoc70001a2012-11-28 04:34:26 +00001245 struct qlcnic_adapter *adapter = sds_ring->adapter;
1246 struct list_head *cur;
1247 struct status_desc *desc;
1248 struct qlcnic_rx_buffer *rxbuf;
Sony Chacko4be41e92013-01-01 03:20:20 +00001249 int opcode, desc_cnt, count = 0;
Sony Chackoc70001a2012-11-28 04:34:26 +00001250 u64 sts_data0, sts_data1;
Sony Chacko4be41e92013-01-01 03:20:20 +00001251 u8 ring;
Sony Chackoc70001a2012-11-28 04:34:26 +00001252 u32 consumer = sds_ring->consumer;
1253
1254 while (count < max) {
1255 desc = &sds_ring->desc_head[consumer];
1256 sts_data0 = le64_to_cpu(desc->status_desc_data[0]);
1257
1258 if (!(sts_data0 & STATUS_OWNER_HOST))
1259 break;
1260
1261 desc_cnt = qlcnic_get_sts_desc_cnt(sts_data0);
1262 opcode = qlcnic_get_sts_opcode(sts_data0);
Sony Chackoc70001a2012-11-28 04:34:26 +00001263 switch (opcode) {
1264 case QLCNIC_RXPKT_DESC:
1265 case QLCNIC_OLD_RXPKT_DESC:
1266 case QLCNIC_SYN_OFFLOAD:
1267 ring = qlcnic_get_sts_type(sts_data0);
Sony Chackod17dd0d2012-11-28 04:34:27 +00001268 rxbuf = qlcnic_process_rcv(adapter, sds_ring, ring,
1269 sts_data0);
Sony Chackoc70001a2012-11-28 04:34:26 +00001270 break;
1271 case QLCNIC_LRO_DESC:
1272 ring = qlcnic_get_lro_sts_type(sts_data0);
1273 sts_data1 = le64_to_cpu(desc->status_desc_data[1]);
1274 rxbuf = qlcnic_process_lro(adapter, ring, sts_data0,
1275 sts_data1);
1276 break;
1277 case QLCNIC_RESPONSE_DESC:
1278 qlcnic_handle_fw_message(desc_cnt, consumer, sds_ring);
1279 default:
1280 goto skip;
1281 }
Sony Chackoc70001a2012-11-28 04:34:26 +00001282 WARN_ON(desc_cnt > 1);
1283
1284 if (likely(rxbuf))
1285 list_add_tail(&rxbuf->list, &sds_ring->free_list[ring]);
1286 else
1287 adapter->stats.null_rxbuf++;
Sony Chackoc70001a2012-11-28 04:34:26 +00001288skip:
1289 for (; desc_cnt > 0; desc_cnt--) {
1290 desc = &sds_ring->desc_head[consumer];
Sony Chacko4be41e92013-01-01 03:20:20 +00001291 desc->status_desc_data[0] = QLCNIC_DESC_OWNER_FW;
Sony Chackoc70001a2012-11-28 04:34:26 +00001292 consumer = get_next_index(consumer, sds_ring->num_desc);
1293 }
1294 count++;
1295 }
1296
1297 for (ring = 0; ring < adapter->max_rds_rings; ring++) {
Sony Chackod17dd0d2012-11-28 04:34:27 +00001298 rds_ring = &adapter->recv_ctx->rds_rings[ring];
Sony Chackoc70001a2012-11-28 04:34:26 +00001299 if (!list_empty(&sds_ring->free_list[ring])) {
1300 list_for_each(cur, &sds_ring->free_list[ring]) {
Sony Chackod17dd0d2012-11-28 04:34:27 +00001301 rxbuf = list_entry(cur, struct qlcnic_rx_buffer,
1302 list);
Sony Chackoc70001a2012-11-28 04:34:26 +00001303 qlcnic_alloc_rx_skb(adapter, rds_ring, rxbuf);
1304 }
1305 spin_lock(&rds_ring->lock);
1306 list_splice_tail_init(&sds_ring->free_list[ring],
Sony Chackod17dd0d2012-11-28 04:34:27 +00001307 &rds_ring->free_list);
Sony Chackoc70001a2012-11-28 04:34:26 +00001308 spin_unlock(&rds_ring->lock);
1309 }
1310
Sony Chacko4be41e92013-01-01 03:20:20 +00001311 qlcnic_post_rx_buffers_nodb(adapter, rds_ring, ring);
Sony Chackoc70001a2012-11-28 04:34:26 +00001312 }
1313
1314 if (count) {
1315 sds_ring->consumer = consumer;
1316 writel(consumer, sds_ring->crb_sts_consumer);
1317 }
1318
1319 return count;
1320}
1321
Sony Chackod17dd0d2012-11-28 04:34:27 +00001322void qlcnic_post_rx_buffers(struct qlcnic_adapter *adapter,
Sony Chacko4be41e92013-01-01 03:20:20 +00001323 struct qlcnic_host_rds_ring *rds_ring, u8 ring_id)
Sony Chackoc70001a2012-11-28 04:34:26 +00001324{
1325 struct rcv_desc *pdesc;
1326 struct qlcnic_rx_buffer *buffer;
1327 int count = 0;
Sony Chacko4be41e92013-01-01 03:20:20 +00001328 u32 producer, handle;
Sony Chackoc70001a2012-11-28 04:34:26 +00001329 struct list_head *head;
1330
1331 producer = rds_ring->producer;
Sony Chackoc70001a2012-11-28 04:34:26 +00001332 head = &rds_ring->free_list;
Sony Chackod17dd0d2012-11-28 04:34:27 +00001333
Sony Chackoc70001a2012-11-28 04:34:26 +00001334 while (!list_empty(head)) {
1335
1336 buffer = list_entry(head->next, struct qlcnic_rx_buffer, list);
1337
1338 if (!buffer->skb) {
1339 if (qlcnic_alloc_rx_skb(adapter, rds_ring, buffer))
1340 break;
1341 }
1342
1343 count++;
1344 list_del(&buffer->list);
1345
1346 /* make a rcv descriptor */
1347 pdesc = &rds_ring->desc_head[producer];
1348 pdesc->addr_buffer = cpu_to_le64(buffer->dma);
Sony Chacko4be41e92013-01-01 03:20:20 +00001349 handle = qlcnic_get_ref_handle(adapter, buffer->ref_handle,
1350 ring_id);
1351 pdesc->reference_handle = cpu_to_le16(handle);
Sony Chackoc70001a2012-11-28 04:34:26 +00001352 pdesc->buffer_length = cpu_to_le32(rds_ring->dma_size);
Sony Chackoc70001a2012-11-28 04:34:26 +00001353 producer = get_next_index(producer, rds_ring->num_desc);
1354 }
1355
1356 if (count) {
1357 rds_ring->producer = producer;
1358 writel((producer-1) & (rds_ring->num_desc-1),
Sony Chackod17dd0d2012-11-28 04:34:27 +00001359 rds_ring->crb_rcv_producer);
Sony Chackoc70001a2012-11-28 04:34:26 +00001360 }
1361}
1362
1363static void dump_skb(struct sk_buff *skb, struct qlcnic_adapter *adapter)
1364{
1365 int i;
1366 unsigned char *data = skb->data;
1367
Sony Chackod17dd0d2012-11-28 04:34:27 +00001368 pr_info(KERN_INFO "\n");
Sony Chackoc70001a2012-11-28 04:34:26 +00001369 for (i = 0; i < skb->len; i++) {
1370 QLCDB(adapter, DRV, "%02x ", data[i]);
1371 if ((i & 0x0f) == 8)
Sony Chackod17dd0d2012-11-28 04:34:27 +00001372 pr_info(KERN_INFO "\n");
Sony Chackoc70001a2012-11-28 04:34:26 +00001373 }
1374}
1375
1376static void qlcnic_process_rcv_diag(struct qlcnic_adapter *adapter, int ring,
1377 u64 sts_data0)
1378{
1379 struct qlcnic_recv_context *recv_ctx = adapter->recv_ctx;
1380 struct sk_buff *skb;
1381 struct qlcnic_host_rds_ring *rds_ring;
1382 int index, length, cksum, pkt_offset;
1383
1384 if (unlikely(ring >= adapter->max_rds_rings))
1385 return;
1386
1387 rds_ring = &recv_ctx->rds_rings[ring];
1388
1389 index = qlcnic_get_sts_refhandle(sts_data0);
1390 length = qlcnic_get_sts_totallength(sts_data0);
1391 if (unlikely(index >= rds_ring->num_desc))
1392 return;
1393
1394 cksum = qlcnic_get_sts_status(sts_data0);
1395 pkt_offset = qlcnic_get_sts_pkt_offset(sts_data0);
1396
1397 skb = qlcnic_process_rxbuf(adapter, rds_ring, index, cksum);
1398 if (!skb)
1399 return;
1400
1401 if (length > rds_ring->skb_size)
1402 skb_put(skb, rds_ring->skb_size);
1403 else
1404 skb_put(skb, length);
1405
1406 if (pkt_offset)
1407 skb_pull(skb, pkt_offset);
1408
1409 if (!qlcnic_check_loopback_buff(skb->data, adapter->mac_addr))
Sony Chacko79788452012-12-04 03:33:53 +00001410 adapter->ahw->diag_cnt++;
Sony Chackoc70001a2012-11-28 04:34:26 +00001411 else
1412 dump_skb(skb, adapter);
1413
1414 dev_kfree_skb_any(skb);
1415 adapter->stats.rx_pkts++;
1416 adapter->stats.rxbytes += length;
1417
1418 return;
1419}
1420
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00001421void qlcnic_82xx_process_rcv_ring_diag(struct qlcnic_host_sds_ring *sds_ring)
Sony Chackoc70001a2012-11-28 04:34:26 +00001422{
1423 struct qlcnic_adapter *adapter = sds_ring->adapter;
1424 struct status_desc *desc;
1425 u64 sts_data0;
1426 int ring, opcode, desc_cnt;
1427
1428 u32 consumer = sds_ring->consumer;
1429
1430 desc = &sds_ring->desc_head[consumer];
1431 sts_data0 = le64_to_cpu(desc->status_desc_data[0]);
1432
1433 if (!(sts_data0 & STATUS_OWNER_HOST))
1434 return;
1435
1436 desc_cnt = qlcnic_get_sts_desc_cnt(sts_data0);
1437 opcode = qlcnic_get_sts_opcode(sts_data0);
1438 switch (opcode) {
1439 case QLCNIC_RESPONSE_DESC:
1440 qlcnic_handle_fw_message(desc_cnt, consumer, sds_ring);
1441 break;
1442 default:
1443 ring = qlcnic_get_sts_type(sts_data0);
1444 qlcnic_process_rcv_diag(adapter, ring, sts_data0);
1445 break;
1446 }
1447
1448 for (; desc_cnt > 0; desc_cnt--) {
1449 desc = &sds_ring->desc_head[consumer];
1450 desc->status_desc_data[0] = cpu_to_le64(STATUS_OWNER_PHANTOM);
1451 consumer = get_next_index(consumer, sds_ring->num_desc);
1452 }
1453
1454 sds_ring->consumer = consumer;
1455 writel(consumer, sds_ring->crb_sts_consumer);
1456}
1457
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00001458int qlcnic_82xx_napi_add(struct qlcnic_adapter *adapter,
1459 struct net_device *netdev)
Sony Chackoc70001a2012-11-28 04:34:26 +00001460{
Michal Schmidtdf95fc42013-09-04 15:03:05 +02001461 int ring;
Sony Chackoc70001a2012-11-28 04:34:26 +00001462 struct qlcnic_host_sds_ring *sds_ring;
1463 struct qlcnic_recv_context *recv_ctx = adapter->recv_ctx;
Himanshu Madhani012ec812013-08-21 11:24:10 -04001464 struct qlcnic_host_tx_ring *tx_ring;
Sony Chackoc70001a2012-11-28 04:34:26 +00001465
1466 if (qlcnic_alloc_sds_rings(recv_ctx, adapter->max_sds_rings))
1467 return -ENOMEM;
1468
1469 for (ring = 0; ring < adapter->max_sds_rings; ring++) {
1470 sds_ring = &recv_ctx->sds_rings[ring];
Himanshu Madhani012ec812013-08-21 11:24:10 -04001471 if (qlcnic_check_multi_tx(adapter) &&
Himanshu Madhanic2c5e3a2013-08-21 11:24:12 -04001472 !adapter->ahw->diag_test &&
Himanshu Madhani012ec812013-08-21 11:24:10 -04001473 (adapter->max_drv_tx_rings > 1)) {
Sony Chackod17dd0d2012-11-28 04:34:27 +00001474 netif_napi_add(netdev, &sds_ring->napi, qlcnic_rx_poll,
Michal Schmidtdf95fc42013-09-04 15:03:05 +02001475 NAPI_POLL_WEIGHT);
Himanshu Madhani012ec812013-08-21 11:24:10 -04001476 } else {
1477 if (ring == (adapter->max_sds_rings - 1))
1478 netif_napi_add(netdev, &sds_ring->napi,
1479 qlcnic_poll,
Michal Schmidtdf95fc42013-09-04 15:03:05 +02001480 NAPI_POLL_WEIGHT);
Himanshu Madhani012ec812013-08-21 11:24:10 -04001481 else
1482 netif_napi_add(netdev, &sds_ring->napi,
1483 qlcnic_rx_poll,
Michal Schmidtdf95fc42013-09-04 15:03:05 +02001484 NAPI_POLL_WEIGHT);
Himanshu Madhani012ec812013-08-21 11:24:10 -04001485 }
Sony Chackoc70001a2012-11-28 04:34:26 +00001486 }
1487
Sony Chacko4be41e92013-01-01 03:20:20 +00001488 if (qlcnic_alloc_tx_rings(adapter, netdev)) {
1489 qlcnic_free_sds_rings(recv_ctx);
1490 return -ENOMEM;
1491 }
1492
Himanshu Madhanic2c5e3a2013-08-21 11:24:12 -04001493 if (qlcnic_check_multi_tx(adapter) && !adapter->ahw->diag_test) {
Himanshu Madhani012ec812013-08-21 11:24:10 -04001494 for (ring = 0; ring < adapter->max_drv_tx_rings; ring++) {
1495 tx_ring = &adapter->tx_ring[ring];
1496 netif_napi_add(netdev, &tx_ring->napi, qlcnic_tx_poll,
Michal Schmidtdf95fc42013-09-04 15:03:05 +02001497 NAPI_POLL_WEIGHT);
Himanshu Madhani012ec812013-08-21 11:24:10 -04001498 }
1499 }
1500
Sony Chackoc70001a2012-11-28 04:34:26 +00001501 return 0;
1502}
1503
Sony Chacko4be41e92013-01-01 03:20:20 +00001504void qlcnic_82xx_napi_del(struct qlcnic_adapter *adapter)
Sony Chackoc70001a2012-11-28 04:34:26 +00001505{
1506 int ring;
1507 struct qlcnic_host_sds_ring *sds_ring;
1508 struct qlcnic_recv_context *recv_ctx = adapter->recv_ctx;
Himanshu Madhani012ec812013-08-21 11:24:10 -04001509 struct qlcnic_host_tx_ring *tx_ring;
Sony Chackoc70001a2012-11-28 04:34:26 +00001510
1511 for (ring = 0; ring < adapter->max_sds_rings; ring++) {
1512 sds_ring = &recv_ctx->sds_rings[ring];
1513 netif_napi_del(&sds_ring->napi);
1514 }
1515
1516 qlcnic_free_sds_rings(adapter->recv_ctx);
Himanshu Madhani012ec812013-08-21 11:24:10 -04001517
Himanshu Madhanic2c5e3a2013-08-21 11:24:12 -04001518 if (qlcnic_check_multi_tx(adapter) && !adapter->ahw->diag_test) {
Himanshu Madhani012ec812013-08-21 11:24:10 -04001519 for (ring = 0; ring < adapter->max_drv_tx_rings; ring++) {
1520 tx_ring = &adapter->tx_ring[ring];
1521 netif_napi_del(&tx_ring->napi);
1522 }
1523 }
1524
Sony Chacko4be41e92013-01-01 03:20:20 +00001525 qlcnic_free_tx_rings(adapter);
Sony Chackoc70001a2012-11-28 04:34:26 +00001526}
1527
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00001528void qlcnic_82xx_napi_enable(struct qlcnic_adapter *adapter)
Sony Chackoc70001a2012-11-28 04:34:26 +00001529{
1530 int ring;
1531 struct qlcnic_host_sds_ring *sds_ring;
Himanshu Madhani012ec812013-08-21 11:24:10 -04001532 struct qlcnic_host_tx_ring *tx_ring;
Sony Chackoc70001a2012-11-28 04:34:26 +00001533 struct qlcnic_recv_context *recv_ctx = adapter->recv_ctx;
1534
1535 if (adapter->is_up != QLCNIC_ADAPTER_UP_MAGIC)
1536 return;
1537
1538 for (ring = 0; ring < adapter->max_sds_rings; ring++) {
1539 sds_ring = &recv_ctx->sds_rings[ring];
1540 napi_enable(&sds_ring->napi);
1541 qlcnic_enable_int(sds_ring);
1542 }
Himanshu Madhani012ec812013-08-21 11:24:10 -04001543
1544 if (qlcnic_check_multi_tx(adapter) &&
1545 (adapter->flags & QLCNIC_MSIX_ENABLED) &&
Himanshu Madhanic2c5e3a2013-08-21 11:24:12 -04001546 !adapter->ahw->diag_test &&
Himanshu Madhani012ec812013-08-21 11:24:10 -04001547 (adapter->max_drv_tx_rings > 1)) {
1548 for (ring = 0; ring < adapter->max_drv_tx_rings; ring++) {
1549 tx_ring = &adapter->tx_ring[ring];
1550 napi_enable(&tx_ring->napi);
1551 qlcnic_enable_tx_intr(adapter, tx_ring);
1552 }
1553 }
Sony Chackoc70001a2012-11-28 04:34:26 +00001554}
1555
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00001556void qlcnic_82xx_napi_disable(struct qlcnic_adapter *adapter)
Sony Chackoc70001a2012-11-28 04:34:26 +00001557{
1558 int ring;
1559 struct qlcnic_host_sds_ring *sds_ring;
Himanshu Madhani012ec812013-08-21 11:24:10 -04001560 struct qlcnic_host_tx_ring *tx_ring;
Sony Chackoc70001a2012-11-28 04:34:26 +00001561 struct qlcnic_recv_context *recv_ctx = adapter->recv_ctx;
1562
1563 if (adapter->is_up != QLCNIC_ADAPTER_UP_MAGIC)
1564 return;
1565
1566 for (ring = 0; ring < adapter->max_sds_rings; ring++) {
1567 sds_ring = &recv_ctx->sds_rings[ring];
1568 qlcnic_disable_int(sds_ring);
1569 napi_synchronize(&sds_ring->napi);
1570 napi_disable(&sds_ring->napi);
1571 }
Himanshu Madhani012ec812013-08-21 11:24:10 -04001572
1573 if ((adapter->flags & QLCNIC_MSIX_ENABLED) &&
Himanshu Madhanic2c5e3a2013-08-21 11:24:12 -04001574 !adapter->ahw->diag_test &&
Himanshu Madhani012ec812013-08-21 11:24:10 -04001575 qlcnic_check_multi_tx(adapter)) {
1576 for (ring = 0; ring < adapter->max_drv_tx_rings; ring++) {
1577 tx_ring = &adapter->tx_ring[ring];
1578 qlcnic_disable_tx_int(adapter, tx_ring);
1579 napi_synchronize(&tx_ring->napi);
1580 napi_disable(&tx_ring->napi);
1581 }
1582 }
Sony Chackoc70001a2012-11-28 04:34:26 +00001583}
Sony Chacko4be41e92013-01-01 03:20:20 +00001584
Shahed Shaikh53643a72013-02-18 13:22:37 +00001585#define QLC_83XX_NORMAL_LB_PKT (1ULL << 36)
1586#define QLC_83XX_LRO_LB_PKT (1ULL << 46)
1587
1588static inline int qlcnic_83xx_is_lb_pkt(u64 sts_data, int lro_pkt)
1589{
1590 if (lro_pkt)
1591 return (sts_data & QLC_83XX_LRO_LB_PKT) ? 1 : 0;
1592 else
1593 return (sts_data & QLC_83XX_NORMAL_LB_PKT) ? 1 : 0;
1594}
1595
Sony Chacko4be41e92013-01-01 03:20:20 +00001596static struct qlcnic_rx_buffer *
1597qlcnic_83xx_process_rcv(struct qlcnic_adapter *adapter,
1598 struct qlcnic_host_sds_ring *sds_ring,
1599 u8 ring, u64 sts_data[])
1600{
1601 struct net_device *netdev = adapter->netdev;
1602 struct qlcnic_recv_context *recv_ctx = adapter->recv_ctx;
1603 struct qlcnic_rx_buffer *buffer;
1604 struct sk_buff *skb;
1605 struct qlcnic_host_rds_ring *rds_ring;
Shahed Shaikh53643a72013-02-18 13:22:37 +00001606 int index, length, cksum, is_lb_pkt;
1607 u16 vid = 0xffff, t_vid;
Sony Chacko4be41e92013-01-01 03:20:20 +00001608
1609 if (unlikely(ring >= adapter->max_rds_rings))
1610 return NULL;
1611
1612 rds_ring = &recv_ctx->rds_rings[ring];
1613
1614 index = qlcnic_83xx_hndl(sts_data[0]);
1615 if (unlikely(index >= rds_ring->num_desc))
1616 return NULL;
1617
1618 buffer = &rds_ring->rx_buf_arr[index];
1619 length = qlcnic_83xx_pktln(sts_data[0]);
1620 cksum = qlcnic_83xx_csum_status(sts_data[1]);
1621 skb = qlcnic_process_rxbuf(adapter, rds_ring, index, cksum);
1622 if (!skb)
1623 return buffer;
1624
Shahed Shaikh53643a72013-02-18 13:22:37 +00001625 if (adapter->drv_mac_learn &&
1626 (adapter->flags & QLCNIC_ESWITCH_ENABLED)) {
1627 t_vid = 0;
1628 is_lb_pkt = qlcnic_83xx_is_lb_pkt(sts_data[1], 0);
Rajesh Borundiaf80bc8f2013-04-19 07:01:08 +00001629 qlcnic_add_lb_filter(adapter, skb, is_lb_pkt, t_vid);
Shahed Shaikh53643a72013-02-18 13:22:37 +00001630 }
1631
Sony Chacko4be41e92013-01-01 03:20:20 +00001632 if (length > rds_ring->skb_size)
1633 skb_put(skb, rds_ring->skb_size);
1634 else
1635 skb_put(skb, length);
1636
1637 if (unlikely(qlcnic_check_rx_tagging(adapter, skb, &vid))) {
1638 adapter->stats.rxdropped++;
1639 dev_kfree_skb(skb);
1640 return buffer;
1641 }
1642
1643 skb->protocol = eth_type_trans(skb, netdev);
1644
1645 if (vid != 0xffff)
Patrick McHardy86a9bad2013-04-19 02:04:30 +00001646 __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q), vid);
Sony Chacko4be41e92013-01-01 03:20:20 +00001647
1648 napi_gro_receive(&sds_ring->napi, skb);
1649
1650 adapter->stats.rx_pkts++;
1651 adapter->stats.rxbytes += length;
1652
1653 return buffer;
1654}
1655
1656static struct qlcnic_rx_buffer *
1657qlcnic_83xx_process_lro(struct qlcnic_adapter *adapter,
1658 u8 ring, u64 sts_data[])
1659{
1660 struct net_device *netdev = adapter->netdev;
1661 struct qlcnic_recv_context *recv_ctx = adapter->recv_ctx;
1662 struct qlcnic_rx_buffer *buffer;
1663 struct sk_buff *skb;
1664 struct qlcnic_host_rds_ring *rds_ring;
1665 struct iphdr *iph;
1666 struct ipv6hdr *ipv6h;
1667 struct tcphdr *th;
1668 bool push;
1669 int l2_hdr_offset, l4_hdr_offset;
Shahed Shaikh53643a72013-02-18 13:22:37 +00001670 int index, is_lb_pkt;
Shahed Shaikh99e85872013-02-18 12:06:16 +00001671 u16 lro_length, length, data_offset, gso_size;
Shahed Shaikh53643a72013-02-18 13:22:37 +00001672 u16 vid = 0xffff, t_vid;
Sony Chacko4be41e92013-01-01 03:20:20 +00001673
1674 if (unlikely(ring > adapter->max_rds_rings))
1675 return NULL;
1676
1677 rds_ring = &recv_ctx->rds_rings[ring];
1678
1679 index = qlcnic_83xx_hndl(sts_data[0]);
1680 if (unlikely(index > rds_ring->num_desc))
1681 return NULL;
1682
1683 buffer = &rds_ring->rx_buf_arr[index];
1684
1685 lro_length = qlcnic_83xx_lro_pktln(sts_data[0]);
1686 l2_hdr_offset = qlcnic_83xx_l2_hdr_off(sts_data[1]);
1687 l4_hdr_offset = qlcnic_83xx_l4_hdr_off(sts_data[1]);
1688 push = qlcnic_83xx_is_psh_bit(sts_data[1]);
1689
1690 skb = qlcnic_process_rxbuf(adapter, rds_ring, index, STATUS_CKSUM_OK);
1691 if (!skb)
1692 return buffer;
Shahed Shaikh53643a72013-02-18 13:22:37 +00001693
1694 if (adapter->drv_mac_learn &&
1695 (adapter->flags & QLCNIC_ESWITCH_ENABLED)) {
1696 t_vid = 0;
1697 is_lb_pkt = qlcnic_83xx_is_lb_pkt(sts_data[1], 1);
Rajesh Borundiaf80bc8f2013-04-19 07:01:08 +00001698 qlcnic_add_lb_filter(adapter, skb, is_lb_pkt, t_vid);
Shahed Shaikh53643a72013-02-18 13:22:37 +00001699 }
Sony Chacko4be41e92013-01-01 03:20:20 +00001700 if (qlcnic_83xx_is_tstamp(sts_data[1]))
1701 data_offset = l4_hdr_offset + QLCNIC_TCP_TS_HDR_SIZE;
1702 else
1703 data_offset = l4_hdr_offset + QLCNIC_TCP_HDR_SIZE;
1704
1705 skb_put(skb, lro_length + data_offset);
1706 skb_pull(skb, l2_hdr_offset);
1707
1708 if (unlikely(qlcnic_check_rx_tagging(adapter, skb, &vid))) {
1709 adapter->stats.rxdropped++;
1710 dev_kfree_skb(skb);
1711 return buffer;
1712 }
1713
1714 skb->protocol = eth_type_trans(skb, netdev);
1715 if (ntohs(skb->protocol) == ETH_P_IPV6) {
1716 ipv6h = (struct ipv6hdr *)skb->data;
1717 th = (struct tcphdr *)(skb->data + sizeof(struct ipv6hdr));
1718
1719 length = (th->doff << 2) + lro_length;
1720 ipv6h->payload_len = htons(length);
1721 } else {
1722 iph = (struct iphdr *)skb->data;
1723 th = (struct tcphdr *)(skb->data + (iph->ihl << 2));
1724 length = (iph->ihl << 2) + (th->doff << 2) + lro_length;
Li RongQing1bcac3b2013-03-14 22:50:07 +00001725 csum_replace2(&iph->check, iph->tot_len, htons(length));
Sony Chacko4be41e92013-01-01 03:20:20 +00001726 iph->tot_len = htons(length);
Sony Chacko4be41e92013-01-01 03:20:20 +00001727 }
1728
1729 th->psh = push;
1730 length = skb->len;
1731
Shahed Shaikh99e85872013-02-18 12:06:16 +00001732 if (adapter->flags & QLCNIC_FW_LRO_MSS_CAP) {
1733 gso_size = qlcnic_83xx_get_lro_sts_mss(sts_data[0]);
1734 skb_shinfo(skb)->gso_size = gso_size;
1735 if (skb->protocol == htons(ETH_P_IPV6))
1736 skb_shinfo(skb)->gso_type = SKB_GSO_TCPV6;
1737 else
1738 skb_shinfo(skb)->gso_type = SKB_GSO_TCPV4;
1739 }
1740
Sony Chacko4be41e92013-01-01 03:20:20 +00001741 if (vid != 0xffff)
Patrick McHardy86a9bad2013-04-19 02:04:30 +00001742 __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q), vid);
Sony Chacko4be41e92013-01-01 03:20:20 +00001743
1744 netif_receive_skb(skb);
1745
1746 adapter->stats.lro_pkts++;
1747 adapter->stats.lrobytes += length;
1748 return buffer;
1749}
1750
1751static int qlcnic_83xx_process_rcv_ring(struct qlcnic_host_sds_ring *sds_ring,
1752 int max)
1753{
1754 struct qlcnic_host_rds_ring *rds_ring;
1755 struct qlcnic_adapter *adapter = sds_ring->adapter;
1756 struct list_head *cur;
1757 struct status_desc *desc;
1758 struct qlcnic_rx_buffer *rxbuf = NULL;
1759 u8 ring;
1760 u64 sts_data[2];
1761 int count = 0, opcode;
1762 u32 consumer = sds_ring->consumer;
1763
1764 while (count < max) {
1765 desc = &sds_ring->desc_head[consumer];
1766 sts_data[1] = le64_to_cpu(desc->status_desc_data[1]);
1767 opcode = qlcnic_83xx_opcode(sts_data[1]);
1768 if (!opcode)
1769 break;
1770 sts_data[0] = le64_to_cpu(desc->status_desc_data[0]);
1771 ring = QLCNIC_FETCH_RING_ID(sts_data[0]);
1772
1773 switch (opcode) {
1774 case QLC_83XX_REG_DESC:
1775 rxbuf = qlcnic_83xx_process_rcv(adapter, sds_ring,
1776 ring, sts_data);
1777 break;
1778 case QLC_83XX_LRO_DESC:
1779 rxbuf = qlcnic_83xx_process_lro(adapter, ring,
1780 sts_data);
1781 break;
1782 default:
1783 dev_info(&adapter->pdev->dev,
Masanari Iida0b1587b2013-07-17 04:37:44 +09001784 "Unknown opcode: 0x%x\n", opcode);
Sony Chacko4be41e92013-01-01 03:20:20 +00001785 goto skip;
1786 }
1787
1788 if (likely(rxbuf))
1789 list_add_tail(&rxbuf->list, &sds_ring->free_list[ring]);
1790 else
1791 adapter->stats.null_rxbuf++;
1792skip:
1793 desc = &sds_ring->desc_head[consumer];
1794 /* Reset the descriptor */
1795 desc->status_desc_data[1] = 0;
1796 consumer = get_next_index(consumer, sds_ring->num_desc);
1797 count++;
1798 }
1799 for (ring = 0; ring < adapter->max_rds_rings; ring++) {
1800 rds_ring = &adapter->recv_ctx->rds_rings[ring];
1801 if (!list_empty(&sds_ring->free_list[ring])) {
1802 list_for_each(cur, &sds_ring->free_list[ring]) {
1803 rxbuf = list_entry(cur, struct qlcnic_rx_buffer,
1804 list);
1805 qlcnic_alloc_rx_skb(adapter, rds_ring, rxbuf);
1806 }
1807 spin_lock(&rds_ring->lock);
1808 list_splice_tail_init(&sds_ring->free_list[ring],
1809 &rds_ring->free_list);
1810 spin_unlock(&rds_ring->lock);
1811 }
1812 qlcnic_post_rx_buffers_nodb(adapter, rds_ring, ring);
1813 }
1814 if (count) {
1815 sds_ring->consumer = consumer;
1816 writel(consumer, sds_ring->crb_sts_consumer);
1817 }
1818 return count;
1819}
1820
Rajesh Borundiada6c8062013-03-29 05:46:35 +00001821static int qlcnic_83xx_msix_sriov_vf_poll(struct napi_struct *napi, int budget)
1822{
1823 int tx_complete;
1824 int work_done;
1825 struct qlcnic_host_sds_ring *sds_ring;
1826 struct qlcnic_adapter *adapter;
1827 struct qlcnic_host_tx_ring *tx_ring;
1828
1829 sds_ring = container_of(napi, struct qlcnic_host_sds_ring, napi);
1830 adapter = sds_ring->adapter;
1831 /* tx ring count = 1 */
1832 tx_ring = adapter->tx_ring;
1833
1834 tx_complete = qlcnic_process_cmd_ring(adapter, tx_ring, budget);
1835 work_done = qlcnic_83xx_process_rcv_ring(sds_ring, budget);
1836 if ((work_done < budget) && tx_complete) {
1837 napi_complete(&sds_ring->napi);
1838 qlcnic_83xx_enable_intr(adapter, sds_ring);
1839 }
1840
1841 return work_done;
1842}
1843
Sony Chacko4be41e92013-01-01 03:20:20 +00001844static int qlcnic_83xx_poll(struct napi_struct *napi, int budget)
1845{
1846 int tx_complete;
1847 int work_done;
1848 struct qlcnic_host_sds_ring *sds_ring;
1849 struct qlcnic_adapter *adapter;
1850 struct qlcnic_host_tx_ring *tx_ring;
1851
1852 sds_ring = container_of(napi, struct qlcnic_host_sds_ring, napi);
1853 adapter = sds_ring->adapter;
1854 /* tx ring count = 1 */
1855 tx_ring = adapter->tx_ring;
1856
Sony Chacko4be41e92013-01-01 03:20:20 +00001857 tx_complete = qlcnic_process_cmd_ring(adapter, tx_ring, budget);
1858 work_done = qlcnic_83xx_process_rcv_ring(sds_ring, budget);
1859 if ((work_done < budget) && tx_complete) {
1860 napi_complete(&sds_ring->napi);
Himanshu Madhaniac166702013-02-18 12:06:15 +00001861 qlcnic_83xx_enable_intr(adapter, sds_ring);
Sony Chacko4be41e92013-01-01 03:20:20 +00001862 }
1863
1864 return work_done;
1865}
1866
1867static int qlcnic_83xx_msix_tx_poll(struct napi_struct *napi, int budget)
1868{
1869 int work_done;
1870 struct qlcnic_host_tx_ring *tx_ring;
1871 struct qlcnic_adapter *adapter;
1872
1873 budget = QLCNIC_TX_POLL_BUDGET;
1874 tx_ring = container_of(napi, struct qlcnic_host_tx_ring, napi);
1875 adapter = tx_ring->adapter;
1876 work_done = qlcnic_process_cmd_ring(adapter, tx_ring, budget);
1877 if (work_done) {
1878 napi_complete(&tx_ring->napi);
1879 if (test_bit(__QLCNIC_DEV_UP , &adapter->state))
1880 qlcnic_83xx_enable_tx_intr(adapter, tx_ring);
1881 }
1882
1883 return work_done;
1884}
1885
1886static int qlcnic_83xx_rx_poll(struct napi_struct *napi, int budget)
1887{
1888 int work_done;
1889 struct qlcnic_host_sds_ring *sds_ring;
1890 struct qlcnic_adapter *adapter;
1891
1892 sds_ring = container_of(napi, struct qlcnic_host_sds_ring, napi);
1893 adapter = sds_ring->adapter;
1894 work_done = qlcnic_83xx_process_rcv_ring(sds_ring, budget);
1895 if (work_done < budget) {
1896 napi_complete(&sds_ring->napi);
1897 if (test_bit(__QLCNIC_DEV_UP, &adapter->state))
1898 qlcnic_83xx_enable_intr(adapter, sds_ring);
1899 }
1900
1901 return work_done;
1902}
1903
1904void qlcnic_83xx_napi_enable(struct qlcnic_adapter *adapter)
1905{
1906 int ring;
1907 struct qlcnic_host_sds_ring *sds_ring;
1908 struct qlcnic_host_tx_ring *tx_ring;
1909 struct qlcnic_recv_context *recv_ctx = adapter->recv_ctx;
1910
1911 if (adapter->is_up != QLCNIC_ADAPTER_UP_MAGIC)
1912 return;
1913
1914 for (ring = 0; ring < adapter->max_sds_rings; ring++) {
1915 sds_ring = &recv_ctx->sds_rings[ring];
1916 napi_enable(&sds_ring->napi);
Himanshu Madhaniac166702013-02-18 12:06:15 +00001917 if (adapter->flags & QLCNIC_MSIX_ENABLED)
1918 qlcnic_83xx_enable_intr(adapter, sds_ring);
Sony Chacko4be41e92013-01-01 03:20:20 +00001919 }
1920
Rajesh Borundiada6c8062013-03-29 05:46:35 +00001921 if ((adapter->flags & QLCNIC_MSIX_ENABLED) &&
1922 !(adapter->flags & QLCNIC_TX_INTR_SHARED)) {
Sony Chacko4be41e92013-01-01 03:20:20 +00001923 for (ring = 0; ring < adapter->max_drv_tx_rings; ring++) {
1924 tx_ring = &adapter->tx_ring[ring];
1925 napi_enable(&tx_ring->napi);
1926 qlcnic_83xx_enable_tx_intr(adapter, tx_ring);
1927 }
1928 }
1929}
1930
1931void qlcnic_83xx_napi_disable(struct qlcnic_adapter *adapter)
1932{
1933 int ring;
1934 struct qlcnic_host_sds_ring *sds_ring;
1935 struct qlcnic_recv_context *recv_ctx = adapter->recv_ctx;
1936 struct qlcnic_host_tx_ring *tx_ring;
1937
1938 if (adapter->is_up != QLCNIC_ADAPTER_UP_MAGIC)
1939 return;
1940
1941 for (ring = 0; ring < adapter->max_sds_rings; ring++) {
1942 sds_ring = &recv_ctx->sds_rings[ring];
Himanshu Madhaniac166702013-02-18 12:06:15 +00001943 if (adapter->flags & QLCNIC_MSIX_ENABLED)
1944 qlcnic_83xx_disable_intr(adapter, sds_ring);
Sony Chacko4be41e92013-01-01 03:20:20 +00001945 napi_synchronize(&sds_ring->napi);
1946 napi_disable(&sds_ring->napi);
1947 }
1948
Rajesh Borundiada6c8062013-03-29 05:46:35 +00001949 if ((adapter->flags & QLCNIC_MSIX_ENABLED) &&
1950 !(adapter->flags & QLCNIC_TX_INTR_SHARED)) {
Sony Chacko4be41e92013-01-01 03:20:20 +00001951 for (ring = 0; ring < adapter->max_drv_tx_rings; ring++) {
1952 tx_ring = &adapter->tx_ring[ring];
1953 qlcnic_83xx_disable_tx_intr(adapter, tx_ring);
1954 napi_synchronize(&tx_ring->napi);
1955 napi_disable(&tx_ring->napi);
1956 }
1957 }
1958}
1959
1960int qlcnic_83xx_napi_add(struct qlcnic_adapter *adapter,
1961 struct net_device *netdev)
1962{
Michal Schmidtdf95fc42013-09-04 15:03:05 +02001963 int ring;
Sony Chacko4be41e92013-01-01 03:20:20 +00001964 struct qlcnic_host_sds_ring *sds_ring;
1965 struct qlcnic_host_tx_ring *tx_ring;
1966 struct qlcnic_recv_context *recv_ctx = adapter->recv_ctx;
1967
1968 if (qlcnic_alloc_sds_rings(recv_ctx, adapter->max_sds_rings))
1969 return -ENOMEM;
1970
Sony Chacko4be41e92013-01-01 03:20:20 +00001971 for (ring = 0; ring < adapter->max_sds_rings; ring++) {
1972 sds_ring = &recv_ctx->sds_rings[ring];
Rajesh Borundiada6c8062013-03-29 05:46:35 +00001973 if (adapter->flags & QLCNIC_MSIX_ENABLED) {
Michal Schmidtdf95fc42013-09-04 15:03:05 +02001974 if (!(adapter->flags & QLCNIC_TX_INTR_SHARED))
Rajesh Borundiada6c8062013-03-29 05:46:35 +00001975 netif_napi_add(netdev, &sds_ring->napi,
1976 qlcnic_83xx_rx_poll,
Michal Schmidtdf95fc42013-09-04 15:03:05 +02001977 NAPI_POLL_WEIGHT);
1978 else
Rajesh Borundiada6c8062013-03-29 05:46:35 +00001979 netif_napi_add(netdev, &sds_ring->napi,
1980 qlcnic_83xx_msix_sriov_vf_poll,
Michal Schmidtdf95fc42013-09-04 15:03:05 +02001981 NAPI_POLL_WEIGHT);
Rajesh Borundiada6c8062013-03-29 05:46:35 +00001982
1983 } else {
Sony Chacko4be41e92013-01-01 03:20:20 +00001984 netif_napi_add(netdev, &sds_ring->napi,
1985 qlcnic_83xx_poll,
Michal Schmidtdf95fc42013-09-04 15:03:05 +02001986 NAPI_POLL_WEIGHT);
Rajesh Borundiada6c8062013-03-29 05:46:35 +00001987 }
Sony Chacko4be41e92013-01-01 03:20:20 +00001988 }
1989
1990 if (qlcnic_alloc_tx_rings(adapter, netdev)) {
1991 qlcnic_free_sds_rings(recv_ctx);
1992 return -ENOMEM;
1993 }
1994
Rajesh Borundiada6c8062013-03-29 05:46:35 +00001995 if ((adapter->flags & QLCNIC_MSIX_ENABLED) &&
1996 !(adapter->flags & QLCNIC_TX_INTR_SHARED)) {
Sony Chacko4be41e92013-01-01 03:20:20 +00001997 for (ring = 0; ring < adapter->max_drv_tx_rings; ring++) {
1998 tx_ring = &adapter->tx_ring[ring];
1999 netif_napi_add(netdev, &tx_ring->napi,
2000 qlcnic_83xx_msix_tx_poll,
Michal Schmidtdf95fc42013-09-04 15:03:05 +02002001 NAPI_POLL_WEIGHT);
Sony Chacko4be41e92013-01-01 03:20:20 +00002002 }
2003 }
2004
2005 return 0;
2006}
2007
2008void qlcnic_83xx_napi_del(struct qlcnic_adapter *adapter)
2009{
2010 int ring;
2011 struct qlcnic_host_sds_ring *sds_ring;
2012 struct qlcnic_recv_context *recv_ctx = adapter->recv_ctx;
2013 struct qlcnic_host_tx_ring *tx_ring;
2014
2015 for (ring = 0; ring < adapter->max_sds_rings; ring++) {
2016 sds_ring = &recv_ctx->sds_rings[ring];
2017 netif_napi_del(&sds_ring->napi);
2018 }
2019
2020 qlcnic_free_sds_rings(adapter->recv_ctx);
2021
Rajesh Borundiada6c8062013-03-29 05:46:35 +00002022 if ((adapter->flags & QLCNIC_MSIX_ENABLED) &&
2023 !(adapter->flags & QLCNIC_TX_INTR_SHARED)) {
Sony Chacko4be41e92013-01-01 03:20:20 +00002024 for (ring = 0; ring < adapter->max_drv_tx_rings; ring++) {
2025 tx_ring = &adapter->tx_ring[ring];
2026 netif_napi_del(&tx_ring->napi);
2027 }
2028 }
2029
2030 qlcnic_free_tx_rings(adapter);
2031}
2032
2033void qlcnic_83xx_process_rcv_diag(struct qlcnic_adapter *adapter,
2034 int ring, u64 sts_data[])
2035{
2036 struct qlcnic_recv_context *recv_ctx = adapter->recv_ctx;
2037 struct sk_buff *skb;
2038 struct qlcnic_host_rds_ring *rds_ring;
2039 int index, length;
2040
2041 if (unlikely(ring >= adapter->max_rds_rings))
2042 return;
2043
2044 rds_ring = &recv_ctx->rds_rings[ring];
2045 index = qlcnic_83xx_hndl(sts_data[0]);
2046 if (unlikely(index >= rds_ring->num_desc))
2047 return;
2048
2049 length = qlcnic_83xx_pktln(sts_data[0]);
2050
2051 skb = qlcnic_process_rxbuf(adapter, rds_ring, index, STATUS_CKSUM_OK);
2052 if (!skb)
2053 return;
2054
2055 if (length > rds_ring->skb_size)
2056 skb_put(skb, rds_ring->skb_size);
2057 else
2058 skb_put(skb, length);
2059
2060 if (!qlcnic_check_loopback_buff(skb->data, adapter->mac_addr))
2061 adapter->ahw->diag_cnt++;
2062 else
2063 dump_skb(skb, adapter);
2064
2065 dev_kfree_skb_any(skb);
2066 return;
2067}
2068
2069void qlcnic_83xx_process_rcv_ring_diag(struct qlcnic_host_sds_ring *sds_ring)
2070{
2071 struct qlcnic_adapter *adapter = sds_ring->adapter;
2072 struct status_desc *desc;
2073 u64 sts_data[2];
2074 int ring, opcode;
2075 u32 consumer = sds_ring->consumer;
2076
2077 desc = &sds_ring->desc_head[consumer];
2078 sts_data[0] = le64_to_cpu(desc->status_desc_data[0]);
2079 sts_data[1] = le64_to_cpu(desc->status_desc_data[1]);
2080 opcode = qlcnic_83xx_opcode(sts_data[1]);
2081 if (!opcode)
2082 return;
2083
2084 ring = QLCNIC_FETCH_RING_ID(qlcnic_83xx_hndl(sts_data[0]));
2085 qlcnic_83xx_process_rcv_diag(adapter, ring, sts_data);
2086 desc = &sds_ring->desc_head[consumer];
2087 desc->status_desc_data[0] = cpu_to_le64(STATUS_OWNER_PHANTOM);
2088 consumer = get_next_index(consumer, sds_ring->num_desc);
2089 sds_ring->consumer = consumer;
2090 writel(consumer, sds_ring->crb_sts_consumer);
2091}