blob: eda6c691d8970418ae14eb67db450a87314aa882 [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 Madhani18afc102013-11-04 13:31:32 -0500584 tx_ring = &adapter->tx_ring[skb_get_queue_mapping(skb)];
Himanshu Madhani012ec812013-08-21 11:24:10 -0400585 num_txd = tx_ring->num_desc;
586
Sony Chackoc70001a2012-11-28 04:34:26 +0000587 frag_count = skb_shinfo(skb)->nr_frags + 1;
Himanshu Madhani012ec812013-08-21 11:24:10 -0400588
Sony Chackoc70001a2012-11-28 04:34:26 +0000589 /* 14 frags supported for normal packet and
590 * 32 frags supported for TSO packet
591 */
592 if (!skb_is_gso(skb) && frag_count > QLCNIC_MAX_FRAGS_PER_TX) {
Sony Chackoc70001a2012-11-28 04:34:26 +0000593 for (i = 0; i < (frag_count - QLCNIC_MAX_FRAGS_PER_TX); i++)
594 delta += skb_frag_size(&skb_shinfo(skb)->frags[i]);
595
596 if (!__pskb_pull_tail(skb, delta))
597 goto drop_packet;
598
599 frag_count = 1 + skb_shinfo(skb)->nr_frags;
600 }
601
602 if (unlikely(qlcnic_tx_avail(tx_ring) <= TX_STOP_THRESH)) {
Himanshu Madhani012ec812013-08-21 11:24:10 -0400603 netif_tx_stop_queue(tx_ring->txq);
Sony Chackod17dd0d2012-11-28 04:34:27 +0000604 if (qlcnic_tx_avail(tx_ring) > TX_STOP_THRESH) {
Himanshu Madhani012ec812013-08-21 11:24:10 -0400605 netif_tx_start_queue(tx_ring->txq);
Sony Chackod17dd0d2012-11-28 04:34:27 +0000606 } else {
Himanshu Madhanif27c75b2013-11-04 13:31:30 -0500607 tx_ring->tx_stats.xmit_off++;
Sony Chackoc70001a2012-11-28 04:34:26 +0000608 return NETDEV_TX_BUSY;
609 }
610 }
611
612 producer = tx_ring->producer;
613 pbuf = &tx_ring->cmd_buf_arr[producer];
Sony Chackoc70001a2012-11-28 04:34:26 +0000614 pdev = adapter->pdev;
Sony Chackod17dd0d2012-11-28 04:34:27 +0000615 first_desc = &tx_ring->desc_head[producer];
616 hwdesc = &tx_ring->desc_head[producer];
Sony Chackoc70001a2012-11-28 04:34:26 +0000617 qlcnic_clear_cmddesc((u64 *)hwdesc);
618
619 if (qlcnic_map_tx_skb(pdev, skb, pbuf)) {
620 adapter->stats.tx_dma_map_error++;
621 goto drop_packet;
622 }
623
624 pbuf->skb = skb;
625 pbuf->frag_count = frag_count;
626
627 qlcnic_set_tx_frags_len(first_desc, frag_count, skb->len);
628 qlcnic_set_tx_port(first_desc, adapter->portnum);
629
630 for (i = 0; i < frag_count; i++) {
Sony Chackoc70001a2012-11-28 04:34:26 +0000631 k = i % 4;
632
633 if ((k == 0) && (i > 0)) {
634 /* move to next desc.*/
635 producer = get_next_index(producer, num_txd);
636 hwdesc = &tx_ring->desc_head[producer];
637 qlcnic_clear_cmddesc((u64 *)hwdesc);
638 tx_ring->cmd_buf_arr[producer].skb = NULL;
639 }
640
641 buffrag = &pbuf->frag_array[i];
Sony Chackoc70001a2012-11-28 04:34:26 +0000642 hwdesc->buffer_length[k] = cpu_to_le16(buffrag->length);
643 switch (k) {
644 case 0:
645 hwdesc->addr_buffer1 = cpu_to_le64(buffrag->dma);
646 break;
647 case 1:
648 hwdesc->addr_buffer2 = cpu_to_le64(buffrag->dma);
649 break;
650 case 2:
651 hwdesc->addr_buffer3 = cpu_to_le64(buffrag->dma);
652 break;
653 case 3:
654 hwdesc->addr_buffer4 = cpu_to_le64(buffrag->dma);
655 break;
656 }
657 }
658
659 tx_ring->producer = get_next_index(producer, num_txd);
660 smp_mb();
661
Himanshu Madhani012ec812013-08-21 11:24:10 -0400662 if (unlikely(qlcnic_tx_pkt(adapter, first_desc, skb, tx_ring)))
Sony Chackoc70001a2012-11-28 04:34:26 +0000663 goto unwind_buff;
664
Jitendra Kalsariafe1adc62013-01-25 10:20:40 +0000665 if (adapter->drv_mac_learn)
Sony Chacko4be41e92013-01-01 03:20:20 +0000666 qlcnic_send_filter(adapter, first_desc, skb);
Sony Chackoc70001a2012-11-28 04:34:26 +0000667
Himanshu Madhanif27c75b2013-11-04 13:31:30 -0500668 tx_ring->tx_stats.tx_bytes += skb->len;
669 tx_ring->tx_stats.xmit_called++;
Sony Chackoc70001a2012-11-28 04:34:26 +0000670
671 qlcnic_update_cmd_producer(tx_ring);
672
673 return NETDEV_TX_OK;
674
675unwind_buff:
676 qlcnic_unmap_buffers(pdev, skb, pbuf);
677drop_packet:
678 adapter->stats.txdropped++;
679 dev_kfree_skb_any(skb);
680 return NETDEV_TX_OK;
681}
682
Sony Chacko7f9664522013-01-01 03:20:19 +0000683void qlcnic_advert_link_change(struct qlcnic_adapter *adapter, int linkup)
Sony Chackoc70001a2012-11-28 04:34:26 +0000684{
685 struct net_device *netdev = adapter->netdev;
686
687 if (adapter->ahw->linkup && !linkup) {
688 netdev_info(netdev, "NIC Link is down\n");
689 adapter->ahw->linkup = 0;
Himanshu Madhanib84caae2013-12-16 15:36:56 -0500690 netif_carrier_off(netdev);
Sony Chackoc70001a2012-11-28 04:34:26 +0000691 } else if (!adapter->ahw->linkup && linkup) {
692 netdev_info(netdev, "NIC Link is up\n");
693 adapter->ahw->linkup = 1;
Himanshu Madhanib84caae2013-12-16 15:36:56 -0500694 netif_carrier_on(netdev);
Sony Chackoc70001a2012-11-28 04:34:26 +0000695 }
696}
697
Sony Chackod17dd0d2012-11-28 04:34:27 +0000698static int qlcnic_alloc_rx_skb(struct qlcnic_adapter *adapter,
699 struct qlcnic_host_rds_ring *rds_ring,
700 struct qlcnic_rx_buffer *buffer)
Sony Chackoc70001a2012-11-28 04:34:26 +0000701{
702 struct sk_buff *skb;
703 dma_addr_t dma;
704 struct pci_dev *pdev = adapter->pdev;
705
706 skb = netdev_alloc_skb(adapter->netdev, rds_ring->skb_size);
707 if (!skb) {
708 adapter->stats.skb_alloc_failure++;
709 return -ENOMEM;
710 }
711
712 skb_reserve(skb, NET_IP_ALIGN);
Sony Chacko4be41e92013-01-01 03:20:20 +0000713 dma = pci_map_single(pdev, skb->data,
714 rds_ring->dma_size, PCI_DMA_FROMDEVICE);
Sony Chackoc70001a2012-11-28 04:34:26 +0000715
716 if (pci_dma_mapping_error(pdev, dma)) {
717 adapter->stats.rx_dma_map_error++;
718 dev_kfree_skb_any(skb);
719 return -ENOMEM;
720 }
721
722 buffer->skb = skb;
723 buffer->dma = dma;
724
725 return 0;
726}
727
728static void qlcnic_post_rx_buffers_nodb(struct qlcnic_adapter *adapter,
Sony Chacko4be41e92013-01-01 03:20:20 +0000729 struct qlcnic_host_rds_ring *rds_ring,
730 u8 ring_id)
Sony Chackoc70001a2012-11-28 04:34:26 +0000731{
732 struct rcv_desc *pdesc;
733 struct qlcnic_rx_buffer *buffer;
734 int count = 0;
Sony Chacko4be41e92013-01-01 03:20:20 +0000735 uint32_t producer, handle;
Sony Chackoc70001a2012-11-28 04:34:26 +0000736 struct list_head *head;
737
738 if (!spin_trylock(&rds_ring->lock))
739 return;
740
741 producer = rds_ring->producer;
Sony Chackoc70001a2012-11-28 04:34:26 +0000742 head = &rds_ring->free_list;
Sony Chackod17dd0d2012-11-28 04:34:27 +0000743 while (!list_empty(head)) {
Sony Chackoc70001a2012-11-28 04:34:26 +0000744 buffer = list_entry(head->next, struct qlcnic_rx_buffer, list);
745
746 if (!buffer->skb) {
747 if (qlcnic_alloc_rx_skb(adapter, rds_ring, buffer))
748 break;
749 }
Sony Chackoc70001a2012-11-28 04:34:26 +0000750 count++;
751 list_del(&buffer->list);
752
753 /* make a rcv descriptor */
754 pdesc = &rds_ring->desc_head[producer];
Sony Chacko4be41e92013-01-01 03:20:20 +0000755 handle = qlcnic_get_ref_handle(adapter,
756 buffer->ref_handle, ring_id);
757 pdesc->reference_handle = cpu_to_le16(handle);
Sony Chackoc70001a2012-11-28 04:34:26 +0000758 pdesc->buffer_length = cpu_to_le32(rds_ring->dma_size);
759 pdesc->addr_buffer = cpu_to_le64(buffer->dma);
Sony Chackoc70001a2012-11-28 04:34:26 +0000760 producer = get_next_index(producer, rds_ring->num_desc);
761 }
Sony Chackoc70001a2012-11-28 04:34:26 +0000762 if (count) {
763 rds_ring->producer = producer;
764 writel((producer - 1) & (rds_ring->num_desc - 1),
Sony Chackod17dd0d2012-11-28 04:34:27 +0000765 rds_ring->crb_rcv_producer);
Sony Chackoc70001a2012-11-28 04:34:26 +0000766 }
767 spin_unlock(&rds_ring->lock);
768}
769
Sony Chacko4be41e92013-01-01 03:20:20 +0000770static int qlcnic_process_cmd_ring(struct qlcnic_adapter *adapter,
771 struct qlcnic_host_tx_ring *tx_ring,
772 int budget)
Sony Chackoc70001a2012-11-28 04:34:26 +0000773{
774 u32 sw_consumer, hw_consumer;
Sony Chackod17dd0d2012-11-28 04:34:27 +0000775 int i, done, count = 0;
Sony Chackoc70001a2012-11-28 04:34:26 +0000776 struct qlcnic_cmd_buffer *buffer;
777 struct pci_dev *pdev = adapter->pdev;
778 struct net_device *netdev = adapter->netdev;
779 struct qlcnic_skb_frag *frag;
Sony Chackoc70001a2012-11-28 04:34:26 +0000780
Himanshu Madhani34e8c402013-11-04 13:31:31 -0500781 if (!spin_trylock(&adapter->tx_clean_lock))
782 return 1;
783
Sony Chackoc70001a2012-11-28 04:34:26 +0000784 sw_consumer = tx_ring->sw_consumer;
785 hw_consumer = le32_to_cpu(*(tx_ring->hw_consumer));
786
787 while (sw_consumer != hw_consumer) {
788 buffer = &tx_ring->cmd_buf_arr[sw_consumer];
789 if (buffer->skb) {
790 frag = &buffer->frag_array[0];
791 pci_unmap_single(pdev, frag->dma, frag->length,
792 PCI_DMA_TODEVICE);
793 frag->dma = 0ULL;
794 for (i = 1; i < buffer->frag_count; i++) {
795 frag++;
796 pci_unmap_page(pdev, frag->dma, frag->length,
797 PCI_DMA_TODEVICE);
798 frag->dma = 0ULL;
799 }
Himanshu Madhanif27c75b2013-11-04 13:31:30 -0500800 tx_ring->tx_stats.xmit_finished++;
Sony Chackoc70001a2012-11-28 04:34:26 +0000801 dev_kfree_skb_any(buffer->skb);
802 buffer->skb = NULL;
803 }
804
805 sw_consumer = get_next_index(sw_consumer, tx_ring->num_desc);
Sony Chacko4be41e92013-01-01 03:20:20 +0000806 if (++count >= budget)
Sony Chackoc70001a2012-11-28 04:34:26 +0000807 break;
808 }
809
810 if (count && netif_running(netdev)) {
811 tx_ring->sw_consumer = sw_consumer;
Sony Chackoc70001a2012-11-28 04:34:26 +0000812 smp_mb();
Himanshu Madhani012ec812013-08-21 11:24:10 -0400813 if (netif_tx_queue_stopped(tx_ring->txq) &&
814 netif_carrier_ok(netdev)) {
Sony Chackoc70001a2012-11-28 04:34:26 +0000815 if (qlcnic_tx_avail(tx_ring) > TX_STOP_THRESH) {
Himanshu Madhani012ec812013-08-21 11:24:10 -0400816 netif_tx_wake_queue(tx_ring->txq);
Himanshu Madhanif27c75b2013-11-04 13:31:30 -0500817 tx_ring->tx_stats.xmit_on++;
Sony Chackoc70001a2012-11-28 04:34:26 +0000818 }
819 }
820 adapter->tx_timeo_cnt = 0;
821 }
822 /*
823 * If everything is freed up to consumer then check if the ring is full
824 * If the ring is full then check if more needs to be freed and
825 * schedule the call back again.
826 *
827 * This happens when there are 2 CPUs. One could be freeing and the
828 * other filling it. If the ring is full when we get out of here and
829 * the card has already interrupted the host then the host can miss the
830 * interrupt.
831 *
832 * There is still a possible race condition and the host could miss an
833 * interrupt. The card has to take care of this.
834 */
835 hw_consumer = le32_to_cpu(*(tx_ring->hw_consumer));
836 done = (sw_consumer == hw_consumer);
Himanshu Madhani34e8c402013-11-04 13:31:31 -0500837 spin_unlock(&adapter->tx_clean_lock);
Sony Chackoc70001a2012-11-28 04:34:26 +0000838
839 return done;
840}
841
842static int qlcnic_poll(struct napi_struct *napi, int budget)
843{
Sony Chacko4be41e92013-01-01 03:20:20 +0000844 int tx_complete, work_done;
Sony Chackod17dd0d2012-11-28 04:34:27 +0000845 struct qlcnic_host_sds_ring *sds_ring;
846 struct qlcnic_adapter *adapter;
Himanshu Madhani012ec812013-08-21 11:24:10 -0400847 struct qlcnic_host_tx_ring *tx_ring;
Sony Chackoc70001a2012-11-28 04:34:26 +0000848
Sony Chackod17dd0d2012-11-28 04:34:27 +0000849 sds_ring = container_of(napi, struct qlcnic_host_sds_ring, napi);
850 adapter = sds_ring->adapter;
Himanshu Madhani012ec812013-08-21 11:24:10 -0400851 tx_ring = sds_ring->tx_ring;
852
853 tx_complete = qlcnic_process_cmd_ring(adapter, tx_ring,
Sony Chacko4be41e92013-01-01 03:20:20 +0000854 budget);
Sony Chackoc70001a2012-11-28 04:34:26 +0000855 work_done = qlcnic_process_rcv_ring(sds_ring, budget);
Sony Chackoc70001a2012-11-28 04:34:26 +0000856 if ((work_done < budget) && tx_complete) {
857 napi_complete(&sds_ring->napi);
Himanshu Madhani012ec812013-08-21 11:24:10 -0400858 if (test_bit(__QLCNIC_DEV_UP, &adapter->state)) {
Sony Chackoc70001a2012-11-28 04:34:26 +0000859 qlcnic_enable_int(sds_ring);
Himanshu Madhani012ec812013-08-21 11:24:10 -0400860 qlcnic_enable_tx_intr(adapter, tx_ring);
861 }
862 }
863
864 return work_done;
865}
866
867static int qlcnic_tx_poll(struct napi_struct *napi, int budget)
868{
869 struct qlcnic_host_tx_ring *tx_ring;
870 struct qlcnic_adapter *adapter;
871 int work_done;
872
873 tx_ring = container_of(napi, struct qlcnic_host_tx_ring, napi);
874 adapter = tx_ring->adapter;
875
876 work_done = qlcnic_process_cmd_ring(adapter, tx_ring, budget);
877 if (work_done) {
878 napi_complete(&tx_ring->napi);
879 if (test_bit(__QLCNIC_DEV_UP, &adapter->state))
880 qlcnic_enable_tx_intr(adapter, tx_ring);
Sony Chackoc70001a2012-11-28 04:34:26 +0000881 }
882
883 return work_done;
884}
885
886static int qlcnic_rx_poll(struct napi_struct *napi, int budget)
887{
Sony Chackod17dd0d2012-11-28 04:34:27 +0000888 struct qlcnic_host_sds_ring *sds_ring;
889 struct qlcnic_adapter *adapter;
Sony Chackoc70001a2012-11-28 04:34:26 +0000890 int work_done;
891
Sony Chackod17dd0d2012-11-28 04:34:27 +0000892 sds_ring = container_of(napi, struct qlcnic_host_sds_ring, napi);
893 adapter = sds_ring->adapter;
894
Sony Chackoc70001a2012-11-28 04:34:26 +0000895 work_done = qlcnic_process_rcv_ring(sds_ring, budget);
896
897 if (work_done < budget) {
898 napi_complete(&sds_ring->napi);
899 if (test_bit(__QLCNIC_DEV_UP, &adapter->state))
900 qlcnic_enable_int(sds_ring);
901 }
902
903 return work_done;
904}
905
Sony Chackod17dd0d2012-11-28 04:34:27 +0000906static void qlcnic_handle_linkevent(struct qlcnic_adapter *adapter,
907 struct qlcnic_fw_msg *msg)
Sony Chackoc70001a2012-11-28 04:34:26 +0000908{
909 u32 cable_OUI;
Sony Chackod17dd0d2012-11-28 04:34:27 +0000910 u16 cable_len, link_speed;
911 u8 link_status, module, duplex, autoneg, lb_status = 0;
Sony Chackoc70001a2012-11-28 04:34:26 +0000912 struct net_device *netdev = adapter->netdev;
913
Sony Chacko79788452012-12-04 03:33:53 +0000914 adapter->ahw->has_link_events = 1;
Sony Chackoc70001a2012-11-28 04:34:26 +0000915
916 cable_OUI = msg->body[1] & 0xffffffff;
917 cable_len = (msg->body[1] >> 32) & 0xffff;
918 link_speed = (msg->body[1] >> 48) & 0xffff;
919
920 link_status = msg->body[2] & 0xff;
921 duplex = (msg->body[2] >> 16) & 0xff;
922 autoneg = (msg->body[2] >> 24) & 0xff;
923 lb_status = (msg->body[2] >> 32) & 0x3;
924
925 module = (msg->body[2] >> 8) & 0xff;
926 if (module == LINKEVENT_MODULE_TWINAX_UNSUPPORTED_CABLE)
Sony Chackod17dd0d2012-11-28 04:34:27 +0000927 dev_info(&netdev->dev,
928 "unsupported cable: OUI 0x%x, length %d\n",
929 cable_OUI, cable_len);
Sony Chackoc70001a2012-11-28 04:34:26 +0000930 else if (module == LINKEVENT_MODULE_TWINAX_UNSUPPORTED_CABLELEN)
931 dev_info(&netdev->dev, "unsupported cable length %d\n",
Sony Chackod17dd0d2012-11-28 04:34:27 +0000932 cable_len);
Sony Chackoc70001a2012-11-28 04:34:26 +0000933
934 if (!link_status && (lb_status == QLCNIC_ILB_MODE ||
935 lb_status == QLCNIC_ELB_MODE))
936 adapter->ahw->loopback_state |= QLCNIC_LINKEVENT;
937
938 qlcnic_advert_link_change(adapter, link_status);
939
940 if (duplex == LINKEVENT_FULL_DUPLEX)
Sony Chacko79788452012-12-04 03:33:53 +0000941 adapter->ahw->link_duplex = DUPLEX_FULL;
Sony Chackoc70001a2012-11-28 04:34:26 +0000942 else
Sony Chacko79788452012-12-04 03:33:53 +0000943 adapter->ahw->link_duplex = DUPLEX_HALF;
Sony Chackoc70001a2012-11-28 04:34:26 +0000944
Sony Chacko79788452012-12-04 03:33:53 +0000945 adapter->ahw->module_type = module;
946 adapter->ahw->link_autoneg = autoneg;
Sony Chackoc70001a2012-11-28 04:34:26 +0000947
948 if (link_status) {
Sony Chacko79788452012-12-04 03:33:53 +0000949 adapter->ahw->link_speed = link_speed;
Sony Chackoc70001a2012-11-28 04:34:26 +0000950 } else {
Sony Chacko79788452012-12-04 03:33:53 +0000951 adapter->ahw->link_speed = SPEED_UNKNOWN;
952 adapter->ahw->link_duplex = DUPLEX_UNKNOWN;
Sony Chackoc70001a2012-11-28 04:34:26 +0000953 }
954}
955
Sony Chackod17dd0d2012-11-28 04:34:27 +0000956static void qlcnic_handle_fw_message(int desc_cnt, int index,
957 struct qlcnic_host_sds_ring *sds_ring)
Sony Chackoc70001a2012-11-28 04:34:26 +0000958{
959 struct qlcnic_fw_msg msg;
960 struct status_desc *desc;
961 struct qlcnic_adapter *adapter;
962 struct device *dev;
963 int i = 0, opcode, ret;
964
965 while (desc_cnt > 0 && i < 8) {
966 desc = &sds_ring->desc_head[index];
967 msg.words[i++] = le64_to_cpu(desc->status_desc_data[0]);
968 msg.words[i++] = le64_to_cpu(desc->status_desc_data[1]);
969
970 index = get_next_index(index, sds_ring->num_desc);
971 desc_cnt--;
972 }
973
974 adapter = sds_ring->adapter;
975 dev = &adapter->pdev->dev;
976 opcode = qlcnic_get_nic_msg_opcode(msg.body[0]);
977
978 switch (opcode) {
979 case QLCNIC_C2H_OPCODE_GET_LINKEVENT_RESPONSE:
980 qlcnic_handle_linkevent(adapter, &msg);
981 break;
982 case QLCNIC_C2H_OPCODE_CONFIG_LOOPBACK:
983 ret = (u32)(msg.body[1]);
984 switch (ret) {
985 case 0:
986 adapter->ahw->loopback_state |= QLCNIC_LB_RESPONSE;
987 break;
988 case 1:
989 dev_info(dev, "loopback already in progress\n");
Jitendra Kalsariab9c11982013-08-02 00:57:39 -0400990 adapter->ahw->diag_cnt = -EINPROGRESS;
Sony Chackoc70001a2012-11-28 04:34:26 +0000991 break;
992 case 2:
993 dev_info(dev, "loopback cable is not connected\n");
Jitendra Kalsariab9c11982013-08-02 00:57:39 -0400994 adapter->ahw->diag_cnt = -ENODEV;
Sony Chackoc70001a2012-11-28 04:34:26 +0000995 break;
996 default:
Sony Chackod17dd0d2012-11-28 04:34:27 +0000997 dev_info(dev,
998 "loopback configure request failed, err %x\n",
999 ret);
Jitendra Kalsariab9c11982013-08-02 00:57:39 -04001000 adapter->ahw->diag_cnt = -EIO;
Sony Chackoc70001a2012-11-28 04:34:26 +00001001 break;
1002 }
1003 break;
Sucheta Chakraborty2d8ebca2013-08-23 13:38:27 -04001004 case QLCNIC_C2H_OPCODE_GET_DCB_AEN:
Sucheta Chakraborty1de899d2013-10-18 12:22:33 -04001005 qlcnic_dcb_aen_handler(adapter->dcb, (void *)&msg);
Sucheta Chakraborty2d8ebca2013-08-23 13:38:27 -04001006 break;
Sony Chackoc70001a2012-11-28 04:34:26 +00001007 default:
1008 break;
1009 }
1010}
1011
Sony Chacko4be41e92013-01-01 03:20:20 +00001012struct sk_buff *qlcnic_process_rxbuf(struct qlcnic_adapter *adapter,
1013 struct qlcnic_host_rds_ring *ring,
1014 u16 index, u16 cksum)
Sony Chackoc70001a2012-11-28 04:34:26 +00001015{
1016 struct qlcnic_rx_buffer *buffer;
1017 struct sk_buff *skb;
1018
Sony Chacko4be41e92013-01-01 03:20:20 +00001019 buffer = &ring->rx_buf_arr[index];
Sony Chackoc70001a2012-11-28 04:34:26 +00001020 if (unlikely(buffer->skb == NULL)) {
1021 WARN_ON(1);
1022 return NULL;
1023 }
1024
Sony Chacko4be41e92013-01-01 03:20:20 +00001025 pci_unmap_single(adapter->pdev, buffer->dma, ring->dma_size,
Sony Chackod17dd0d2012-11-28 04:34:27 +00001026 PCI_DMA_FROMDEVICE);
Sony Chackoc70001a2012-11-28 04:34:26 +00001027
1028 skb = buffer->skb;
Sony Chackoc70001a2012-11-28 04:34:26 +00001029 if (likely((adapter->netdev->features & NETIF_F_RXCSUM) &&
Sony Chackod17dd0d2012-11-28 04:34:27 +00001030 (cksum == STATUS_CKSUM_OK || cksum == STATUS_CKSUM_LOOP))) {
Sony Chackoc70001a2012-11-28 04:34:26 +00001031 adapter->stats.csummed++;
1032 skb->ip_summed = CHECKSUM_UNNECESSARY;
1033 } else {
1034 skb_checksum_none_assert(skb);
1035 }
1036
Sony Chacko4be41e92013-01-01 03:20:20 +00001037
Sony Chackoc70001a2012-11-28 04:34:26 +00001038 buffer->skb = NULL;
1039
1040 return skb;
1041}
1042
Sony Chackod17dd0d2012-11-28 04:34:27 +00001043static inline int qlcnic_check_rx_tagging(struct qlcnic_adapter *adapter,
1044 struct sk_buff *skb, u16 *vlan_tag)
Sony Chackoc70001a2012-11-28 04:34:26 +00001045{
1046 struct ethhdr *eth_hdr;
1047
1048 if (!__vlan_get_tag(skb, vlan_tag)) {
Sony Chackod17dd0d2012-11-28 04:34:27 +00001049 eth_hdr = (struct ethhdr *)skb->data;
Sony Chackoc70001a2012-11-28 04:34:26 +00001050 memmove(skb->data + VLAN_HLEN, eth_hdr, ETH_ALEN * 2);
1051 skb_pull(skb, VLAN_HLEN);
1052 }
Rajesh Borundia91b72822013-04-19 07:01:12 +00001053 if (!adapter->rx_pvid)
Sony Chackoc70001a2012-11-28 04:34:26 +00001054 return 0;
1055
Rajesh Borundia91b72822013-04-19 07:01:12 +00001056 if (*vlan_tag == adapter->rx_pvid) {
Sony Chackoc70001a2012-11-28 04:34:26 +00001057 /* Outer vlan tag. Packet should follow non-vlan path */
1058 *vlan_tag = 0xffff;
1059 return 0;
1060 }
1061 if (adapter->flags & QLCNIC_TAGGING_ENABLED)
1062 return 0;
1063
1064 return -EINVAL;
1065}
1066
1067static struct qlcnic_rx_buffer *
1068qlcnic_process_rcv(struct qlcnic_adapter *adapter,
Sony Chackod17dd0d2012-11-28 04:34:27 +00001069 struct qlcnic_host_sds_ring *sds_ring, int ring,
1070 u64 sts_data0)
Sony Chackoc70001a2012-11-28 04:34:26 +00001071{
1072 struct net_device *netdev = adapter->netdev;
1073 struct qlcnic_recv_context *recv_ctx = adapter->recv_ctx;
1074 struct qlcnic_rx_buffer *buffer;
1075 struct sk_buff *skb;
1076 struct qlcnic_host_rds_ring *rds_ring;
Shahed Shaikh53643a72013-02-18 13:22:37 +00001077 int index, length, cksum, pkt_offset, is_lb_pkt;
1078 u16 vid = 0xffff, t_vid;
Sony Chackoc70001a2012-11-28 04:34:26 +00001079
1080 if (unlikely(ring >= adapter->max_rds_rings))
1081 return NULL;
1082
1083 rds_ring = &recv_ctx->rds_rings[ring];
1084
1085 index = qlcnic_get_sts_refhandle(sts_data0);
1086 if (unlikely(index >= rds_ring->num_desc))
1087 return NULL;
1088
1089 buffer = &rds_ring->rx_buf_arr[index];
Sony Chackoc70001a2012-11-28 04:34:26 +00001090 length = qlcnic_get_sts_totallength(sts_data0);
1091 cksum = qlcnic_get_sts_status(sts_data0);
1092 pkt_offset = qlcnic_get_sts_pkt_offset(sts_data0);
1093
1094 skb = qlcnic_process_rxbuf(adapter, rds_ring, index, cksum);
1095 if (!skb)
1096 return buffer;
1097
Shahed Shaikh53643a72013-02-18 13:22:37 +00001098 if (adapter->drv_mac_learn &&
1099 (adapter->flags & QLCNIC_ESWITCH_ENABLED)) {
1100 t_vid = 0;
1101 is_lb_pkt = qlcnic_82xx_is_lb_pkt(sts_data0);
Rajesh Borundiaf80bc8f2013-04-19 07:01:08 +00001102 qlcnic_add_lb_filter(adapter, skb, is_lb_pkt, t_vid);
Shahed Shaikh53643a72013-02-18 13:22:37 +00001103 }
1104
Sony Chackoc70001a2012-11-28 04:34:26 +00001105 if (length > rds_ring->skb_size)
1106 skb_put(skb, rds_ring->skb_size);
1107 else
1108 skb_put(skb, length);
1109
1110 if (pkt_offset)
1111 skb_pull(skb, pkt_offset);
1112
1113 if (unlikely(qlcnic_check_rx_tagging(adapter, skb, &vid))) {
1114 adapter->stats.rxdropped++;
1115 dev_kfree_skb(skb);
1116 return buffer;
1117 }
1118
1119 skb->protocol = eth_type_trans(skb, netdev);
1120
1121 if (vid != 0xffff)
Patrick McHardy86a9bad2013-04-19 02:04:30 +00001122 __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q), vid);
Sony Chackoc70001a2012-11-28 04:34:26 +00001123
1124 napi_gro_receive(&sds_ring->napi, skb);
1125
1126 adapter->stats.rx_pkts++;
1127 adapter->stats.rxbytes += length;
1128
1129 return buffer;
1130}
1131
1132#define QLC_TCP_HDR_SIZE 20
1133#define QLC_TCP_TS_OPTION_SIZE 12
1134#define QLC_TCP_TS_HDR_SIZE (QLC_TCP_HDR_SIZE + QLC_TCP_TS_OPTION_SIZE)
1135
1136static struct qlcnic_rx_buffer *
1137qlcnic_process_lro(struct qlcnic_adapter *adapter,
Sony Chackod17dd0d2012-11-28 04:34:27 +00001138 int ring, u64 sts_data0, u64 sts_data1)
Sony Chackoc70001a2012-11-28 04:34:26 +00001139{
1140 struct net_device *netdev = adapter->netdev;
1141 struct qlcnic_recv_context *recv_ctx = adapter->recv_ctx;
1142 struct qlcnic_rx_buffer *buffer;
1143 struct sk_buff *skb;
1144 struct qlcnic_host_rds_ring *rds_ring;
1145 struct iphdr *iph;
Shahed Shaikh776e7bd2013-01-25 10:20:35 +00001146 struct ipv6hdr *ipv6h;
Sony Chackoc70001a2012-11-28 04:34:26 +00001147 struct tcphdr *th;
1148 bool push, timestamp;
Shahed Shaikh53643a72013-02-18 13:22:37 +00001149 int index, l2_hdr_offset, l4_hdr_offset, is_lb_pkt;
1150 u16 lro_length, length, data_offset, t_vid, vid = 0xffff;
Sony Chackoc70001a2012-11-28 04:34:26 +00001151 u32 seq_number;
Sony Chackoc70001a2012-11-28 04:34:26 +00001152
1153 if (unlikely(ring > adapter->max_rds_rings))
1154 return NULL;
1155
1156 rds_ring = &recv_ctx->rds_rings[ring];
1157
1158 index = qlcnic_get_lro_sts_refhandle(sts_data0);
1159 if (unlikely(index > rds_ring->num_desc))
1160 return NULL;
1161
1162 buffer = &rds_ring->rx_buf_arr[index];
1163
1164 timestamp = qlcnic_get_lro_sts_timestamp(sts_data0);
1165 lro_length = qlcnic_get_lro_sts_length(sts_data0);
1166 l2_hdr_offset = qlcnic_get_lro_sts_l2_hdr_offset(sts_data0);
1167 l4_hdr_offset = qlcnic_get_lro_sts_l4_hdr_offset(sts_data0);
1168 push = qlcnic_get_lro_sts_push_flag(sts_data0);
1169 seq_number = qlcnic_get_lro_sts_seq_number(sts_data1);
1170
1171 skb = qlcnic_process_rxbuf(adapter, rds_ring, index, STATUS_CKSUM_OK);
1172 if (!skb)
1173 return buffer;
1174
Shahed Shaikh53643a72013-02-18 13:22:37 +00001175 if (adapter->drv_mac_learn &&
1176 (adapter->flags & QLCNIC_ESWITCH_ENABLED)) {
1177 t_vid = 0;
1178 is_lb_pkt = qlcnic_82xx_is_lb_pkt(sts_data0);
Rajesh Borundiaf80bc8f2013-04-19 07:01:08 +00001179 qlcnic_add_lb_filter(adapter, skb, is_lb_pkt, t_vid);
Shahed Shaikh53643a72013-02-18 13:22:37 +00001180 }
1181
Sony Chackoc70001a2012-11-28 04:34:26 +00001182 if (timestamp)
1183 data_offset = l4_hdr_offset + QLC_TCP_TS_HDR_SIZE;
1184 else
1185 data_offset = l4_hdr_offset + QLC_TCP_HDR_SIZE;
1186
1187 skb_put(skb, lro_length + data_offset);
Sony Chackoc70001a2012-11-28 04:34:26 +00001188 skb_pull(skb, l2_hdr_offset);
1189
1190 if (unlikely(qlcnic_check_rx_tagging(adapter, skb, &vid))) {
1191 adapter->stats.rxdropped++;
1192 dev_kfree_skb(skb);
1193 return buffer;
1194 }
1195
1196 skb->protocol = eth_type_trans(skb, netdev);
Shahed Shaikh776e7bd2013-01-25 10:20:35 +00001197
Shahed Shaikh069048f2013-01-30 12:47:12 +00001198 if (ntohs(skb->protocol) == ETH_P_IPV6) {
Shahed Shaikh776e7bd2013-01-25 10:20:35 +00001199 ipv6h = (struct ipv6hdr *)skb->data;
1200 th = (struct tcphdr *)(skb->data + sizeof(struct ipv6hdr));
1201 length = (th->doff << 2) + lro_length;
1202 ipv6h->payload_len = htons(length);
1203 } else {
1204 iph = (struct iphdr *)skb->data;
1205 th = (struct tcphdr *)(skb->data + (iph->ihl << 2));
1206 length = (iph->ihl << 2) + (th->doff << 2) + lro_length;
Li RongQing1bcac3b2013-03-14 22:50:07 +00001207 csum_replace2(&iph->check, iph->tot_len, htons(length));
Shahed Shaikh776e7bd2013-01-25 10:20:35 +00001208 iph->tot_len = htons(length);
Shahed Shaikh776e7bd2013-01-25 10:20:35 +00001209 }
1210
Sony Chackoc70001a2012-11-28 04:34:26 +00001211 th->psh = push;
1212 th->seq = htonl(seq_number);
Sony Chackoc70001a2012-11-28 04:34:26 +00001213 length = skb->len;
1214
Michael S. Tsirkinbd69ba72013-02-07 03:13:13 +00001215 if (adapter->flags & QLCNIC_FW_LRO_MSS_CAP) {
Sony Chackoc70001a2012-11-28 04:34:26 +00001216 skb_shinfo(skb)->gso_size = qlcnic_get_lro_sts_mss(sts_data1);
Michael S. Tsirkinbd69ba72013-02-07 03:13:13 +00001217 if (skb->protocol == htons(ETH_P_IPV6))
1218 skb_shinfo(skb)->gso_type = SKB_GSO_TCPV6;
1219 else
1220 skb_shinfo(skb)->gso_type = SKB_GSO_TCPV4;
1221 }
Sony Chackoc70001a2012-11-28 04:34:26 +00001222
1223 if (vid != 0xffff)
Patrick McHardy86a9bad2013-04-19 02:04:30 +00001224 __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q), vid);
Sony Chackoc70001a2012-11-28 04:34:26 +00001225 netif_receive_skb(skb);
1226
1227 adapter->stats.lro_pkts++;
1228 adapter->stats.lrobytes += length;
1229
1230 return buffer;
1231}
1232
Sony Chackod17dd0d2012-11-28 04:34:27 +00001233int qlcnic_process_rcv_ring(struct qlcnic_host_sds_ring *sds_ring, int max)
Sony Chackoc70001a2012-11-28 04:34:26 +00001234{
Sony Chackod17dd0d2012-11-28 04:34:27 +00001235 struct qlcnic_host_rds_ring *rds_ring;
Sony Chackoc70001a2012-11-28 04:34:26 +00001236 struct qlcnic_adapter *adapter = sds_ring->adapter;
1237 struct list_head *cur;
1238 struct status_desc *desc;
1239 struct qlcnic_rx_buffer *rxbuf;
Sony Chacko4be41e92013-01-01 03:20:20 +00001240 int opcode, desc_cnt, count = 0;
Sony Chackoc70001a2012-11-28 04:34:26 +00001241 u64 sts_data0, sts_data1;
Sony Chacko4be41e92013-01-01 03:20:20 +00001242 u8 ring;
Sony Chackoc70001a2012-11-28 04:34:26 +00001243 u32 consumer = sds_ring->consumer;
1244
1245 while (count < max) {
1246 desc = &sds_ring->desc_head[consumer];
1247 sts_data0 = le64_to_cpu(desc->status_desc_data[0]);
1248
1249 if (!(sts_data0 & STATUS_OWNER_HOST))
1250 break;
1251
1252 desc_cnt = qlcnic_get_sts_desc_cnt(sts_data0);
1253 opcode = qlcnic_get_sts_opcode(sts_data0);
Sony Chackoc70001a2012-11-28 04:34:26 +00001254 switch (opcode) {
1255 case QLCNIC_RXPKT_DESC:
1256 case QLCNIC_OLD_RXPKT_DESC:
1257 case QLCNIC_SYN_OFFLOAD:
1258 ring = qlcnic_get_sts_type(sts_data0);
Sony Chackod17dd0d2012-11-28 04:34:27 +00001259 rxbuf = qlcnic_process_rcv(adapter, sds_ring, ring,
1260 sts_data0);
Sony Chackoc70001a2012-11-28 04:34:26 +00001261 break;
1262 case QLCNIC_LRO_DESC:
1263 ring = qlcnic_get_lro_sts_type(sts_data0);
1264 sts_data1 = le64_to_cpu(desc->status_desc_data[1]);
1265 rxbuf = qlcnic_process_lro(adapter, ring, sts_data0,
1266 sts_data1);
1267 break;
1268 case QLCNIC_RESPONSE_DESC:
1269 qlcnic_handle_fw_message(desc_cnt, consumer, sds_ring);
1270 default:
1271 goto skip;
1272 }
Sony Chackoc70001a2012-11-28 04:34:26 +00001273 WARN_ON(desc_cnt > 1);
1274
1275 if (likely(rxbuf))
1276 list_add_tail(&rxbuf->list, &sds_ring->free_list[ring]);
1277 else
1278 adapter->stats.null_rxbuf++;
Sony Chackoc70001a2012-11-28 04:34:26 +00001279skip:
1280 for (; desc_cnt > 0; desc_cnt--) {
1281 desc = &sds_ring->desc_head[consumer];
Sony Chacko4be41e92013-01-01 03:20:20 +00001282 desc->status_desc_data[0] = QLCNIC_DESC_OWNER_FW;
Sony Chackoc70001a2012-11-28 04:34:26 +00001283 consumer = get_next_index(consumer, sds_ring->num_desc);
1284 }
1285 count++;
1286 }
1287
1288 for (ring = 0; ring < adapter->max_rds_rings; ring++) {
Sony Chackod17dd0d2012-11-28 04:34:27 +00001289 rds_ring = &adapter->recv_ctx->rds_rings[ring];
Sony Chackoc70001a2012-11-28 04:34:26 +00001290 if (!list_empty(&sds_ring->free_list[ring])) {
1291 list_for_each(cur, &sds_ring->free_list[ring]) {
Sony Chackod17dd0d2012-11-28 04:34:27 +00001292 rxbuf = list_entry(cur, struct qlcnic_rx_buffer,
1293 list);
Sony Chackoc70001a2012-11-28 04:34:26 +00001294 qlcnic_alloc_rx_skb(adapter, rds_ring, rxbuf);
1295 }
1296 spin_lock(&rds_ring->lock);
1297 list_splice_tail_init(&sds_ring->free_list[ring],
Sony Chackod17dd0d2012-11-28 04:34:27 +00001298 &rds_ring->free_list);
Sony Chackoc70001a2012-11-28 04:34:26 +00001299 spin_unlock(&rds_ring->lock);
1300 }
1301
Sony Chacko4be41e92013-01-01 03:20:20 +00001302 qlcnic_post_rx_buffers_nodb(adapter, rds_ring, ring);
Sony Chackoc70001a2012-11-28 04:34:26 +00001303 }
1304
1305 if (count) {
1306 sds_ring->consumer = consumer;
1307 writel(consumer, sds_ring->crb_sts_consumer);
1308 }
1309
1310 return count;
1311}
1312
Sony Chackod17dd0d2012-11-28 04:34:27 +00001313void qlcnic_post_rx_buffers(struct qlcnic_adapter *adapter,
Sony Chacko4be41e92013-01-01 03:20:20 +00001314 struct qlcnic_host_rds_ring *rds_ring, u8 ring_id)
Sony Chackoc70001a2012-11-28 04:34:26 +00001315{
1316 struct rcv_desc *pdesc;
1317 struct qlcnic_rx_buffer *buffer;
1318 int count = 0;
Sony Chacko4be41e92013-01-01 03:20:20 +00001319 u32 producer, handle;
Sony Chackoc70001a2012-11-28 04:34:26 +00001320 struct list_head *head;
1321
1322 producer = rds_ring->producer;
Sony Chackoc70001a2012-11-28 04:34:26 +00001323 head = &rds_ring->free_list;
Sony Chackod17dd0d2012-11-28 04:34:27 +00001324
Sony Chackoc70001a2012-11-28 04:34:26 +00001325 while (!list_empty(head)) {
1326
1327 buffer = list_entry(head->next, struct qlcnic_rx_buffer, list);
1328
1329 if (!buffer->skb) {
1330 if (qlcnic_alloc_rx_skb(adapter, rds_ring, buffer))
1331 break;
1332 }
1333
1334 count++;
1335 list_del(&buffer->list);
1336
1337 /* make a rcv descriptor */
1338 pdesc = &rds_ring->desc_head[producer];
1339 pdesc->addr_buffer = cpu_to_le64(buffer->dma);
Sony Chacko4be41e92013-01-01 03:20:20 +00001340 handle = qlcnic_get_ref_handle(adapter, buffer->ref_handle,
1341 ring_id);
1342 pdesc->reference_handle = cpu_to_le16(handle);
Sony Chackoc70001a2012-11-28 04:34:26 +00001343 pdesc->buffer_length = cpu_to_le32(rds_ring->dma_size);
Sony Chackoc70001a2012-11-28 04:34:26 +00001344 producer = get_next_index(producer, rds_ring->num_desc);
1345 }
1346
1347 if (count) {
1348 rds_ring->producer = producer;
1349 writel((producer-1) & (rds_ring->num_desc-1),
Sony Chackod17dd0d2012-11-28 04:34:27 +00001350 rds_ring->crb_rcv_producer);
Sony Chackoc70001a2012-11-28 04:34:26 +00001351 }
1352}
1353
1354static void dump_skb(struct sk_buff *skb, struct qlcnic_adapter *adapter)
1355{
1356 int i;
1357 unsigned char *data = skb->data;
1358
Sony Chackod17dd0d2012-11-28 04:34:27 +00001359 pr_info(KERN_INFO "\n");
Sony Chackoc70001a2012-11-28 04:34:26 +00001360 for (i = 0; i < skb->len; i++) {
1361 QLCDB(adapter, DRV, "%02x ", data[i]);
1362 if ((i & 0x0f) == 8)
Sony Chackod17dd0d2012-11-28 04:34:27 +00001363 pr_info(KERN_INFO "\n");
Sony Chackoc70001a2012-11-28 04:34:26 +00001364 }
1365}
1366
1367static void qlcnic_process_rcv_diag(struct qlcnic_adapter *adapter, int ring,
1368 u64 sts_data0)
1369{
1370 struct qlcnic_recv_context *recv_ctx = adapter->recv_ctx;
1371 struct sk_buff *skb;
1372 struct qlcnic_host_rds_ring *rds_ring;
1373 int index, length, cksum, pkt_offset;
1374
1375 if (unlikely(ring >= adapter->max_rds_rings))
1376 return;
1377
1378 rds_ring = &recv_ctx->rds_rings[ring];
1379
1380 index = qlcnic_get_sts_refhandle(sts_data0);
1381 length = qlcnic_get_sts_totallength(sts_data0);
1382 if (unlikely(index >= rds_ring->num_desc))
1383 return;
1384
1385 cksum = qlcnic_get_sts_status(sts_data0);
1386 pkt_offset = qlcnic_get_sts_pkt_offset(sts_data0);
1387
1388 skb = qlcnic_process_rxbuf(adapter, rds_ring, index, cksum);
1389 if (!skb)
1390 return;
1391
1392 if (length > rds_ring->skb_size)
1393 skb_put(skb, rds_ring->skb_size);
1394 else
1395 skb_put(skb, length);
1396
1397 if (pkt_offset)
1398 skb_pull(skb, pkt_offset);
1399
1400 if (!qlcnic_check_loopback_buff(skb->data, adapter->mac_addr))
Sony Chacko79788452012-12-04 03:33:53 +00001401 adapter->ahw->diag_cnt++;
Sony Chackoc70001a2012-11-28 04:34:26 +00001402 else
1403 dump_skb(skb, adapter);
1404
1405 dev_kfree_skb_any(skb);
1406 adapter->stats.rx_pkts++;
1407 adapter->stats.rxbytes += length;
1408
1409 return;
1410}
1411
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00001412void qlcnic_82xx_process_rcv_ring_diag(struct qlcnic_host_sds_ring *sds_ring)
Sony Chackoc70001a2012-11-28 04:34:26 +00001413{
1414 struct qlcnic_adapter *adapter = sds_ring->adapter;
1415 struct status_desc *desc;
1416 u64 sts_data0;
1417 int ring, opcode, desc_cnt;
1418
1419 u32 consumer = sds_ring->consumer;
1420
1421 desc = &sds_ring->desc_head[consumer];
1422 sts_data0 = le64_to_cpu(desc->status_desc_data[0]);
1423
1424 if (!(sts_data0 & STATUS_OWNER_HOST))
1425 return;
1426
1427 desc_cnt = qlcnic_get_sts_desc_cnt(sts_data0);
1428 opcode = qlcnic_get_sts_opcode(sts_data0);
1429 switch (opcode) {
1430 case QLCNIC_RESPONSE_DESC:
1431 qlcnic_handle_fw_message(desc_cnt, consumer, sds_ring);
1432 break;
1433 default:
1434 ring = qlcnic_get_sts_type(sts_data0);
1435 qlcnic_process_rcv_diag(adapter, ring, sts_data0);
1436 break;
1437 }
1438
1439 for (; desc_cnt > 0; desc_cnt--) {
1440 desc = &sds_ring->desc_head[consumer];
1441 desc->status_desc_data[0] = cpu_to_le64(STATUS_OWNER_PHANTOM);
1442 consumer = get_next_index(consumer, sds_ring->num_desc);
1443 }
1444
1445 sds_ring->consumer = consumer;
1446 writel(consumer, sds_ring->crb_sts_consumer);
1447}
1448
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00001449int qlcnic_82xx_napi_add(struct qlcnic_adapter *adapter,
1450 struct net_device *netdev)
Sony Chackoc70001a2012-11-28 04:34:26 +00001451{
Michal Schmidtdf95fc42013-09-04 15:03:05 +02001452 int ring;
Sony Chackoc70001a2012-11-28 04:34:26 +00001453 struct qlcnic_host_sds_ring *sds_ring;
1454 struct qlcnic_recv_context *recv_ctx = adapter->recv_ctx;
Himanshu Madhani012ec812013-08-21 11:24:10 -04001455 struct qlcnic_host_tx_ring *tx_ring;
Sony Chackoc70001a2012-11-28 04:34:26 +00001456
Himanshu Madhani34e8c402013-11-04 13:31:31 -05001457 if (qlcnic_alloc_sds_rings(recv_ctx, adapter->drv_sds_rings))
Sony Chackoc70001a2012-11-28 04:34:26 +00001458 return -ENOMEM;
1459
Himanshu Madhani34e8c402013-11-04 13:31:31 -05001460 for (ring = 0; ring < adapter->drv_sds_rings; ring++) {
Sony Chackoc70001a2012-11-28 04:34:26 +00001461 sds_ring = &recv_ctx->sds_rings[ring];
Himanshu Madhani012ec812013-08-21 11:24:10 -04001462 if (qlcnic_check_multi_tx(adapter) &&
Himanshu Madhanic2c5e3a2013-08-21 11:24:12 -04001463 !adapter->ahw->diag_test &&
Himanshu Madhani34e8c402013-11-04 13:31:31 -05001464 (adapter->drv_tx_rings > QLCNIC_SINGLE_RING)) {
Sony Chackod17dd0d2012-11-28 04:34:27 +00001465 netif_napi_add(netdev, &sds_ring->napi, qlcnic_rx_poll,
Michal Schmidtdf95fc42013-09-04 15:03:05 +02001466 NAPI_POLL_WEIGHT);
Himanshu Madhani012ec812013-08-21 11:24:10 -04001467 } else {
Himanshu Madhani34e8c402013-11-04 13:31:31 -05001468 if (ring == (adapter->drv_sds_rings - 1))
Himanshu Madhani012ec812013-08-21 11:24:10 -04001469 netif_napi_add(netdev, &sds_ring->napi,
1470 qlcnic_poll,
Michal Schmidtdf95fc42013-09-04 15:03:05 +02001471 NAPI_POLL_WEIGHT);
Himanshu Madhani012ec812013-08-21 11:24:10 -04001472 else
1473 netif_napi_add(netdev, &sds_ring->napi,
1474 qlcnic_rx_poll,
Michal Schmidtdf95fc42013-09-04 15:03:05 +02001475 NAPI_POLL_WEIGHT);
Himanshu Madhani012ec812013-08-21 11:24:10 -04001476 }
Sony Chackoc70001a2012-11-28 04:34:26 +00001477 }
1478
Sony Chacko4be41e92013-01-01 03:20:20 +00001479 if (qlcnic_alloc_tx_rings(adapter, netdev)) {
1480 qlcnic_free_sds_rings(recv_ctx);
1481 return -ENOMEM;
1482 }
1483
Himanshu Madhanic2c5e3a2013-08-21 11:24:12 -04001484 if (qlcnic_check_multi_tx(adapter) && !adapter->ahw->diag_test) {
Himanshu Madhani34e8c402013-11-04 13:31:31 -05001485 for (ring = 0; ring < adapter->drv_tx_rings; ring++) {
Himanshu Madhani012ec812013-08-21 11:24:10 -04001486 tx_ring = &adapter->tx_ring[ring];
1487 netif_napi_add(netdev, &tx_ring->napi, qlcnic_tx_poll,
Michal Schmidtdf95fc42013-09-04 15:03:05 +02001488 NAPI_POLL_WEIGHT);
Himanshu Madhani012ec812013-08-21 11:24:10 -04001489 }
1490 }
1491
Sony Chackoc70001a2012-11-28 04:34:26 +00001492 return 0;
1493}
1494
Sony Chacko4be41e92013-01-01 03:20:20 +00001495void qlcnic_82xx_napi_del(struct qlcnic_adapter *adapter)
Sony Chackoc70001a2012-11-28 04:34:26 +00001496{
1497 int ring;
1498 struct qlcnic_host_sds_ring *sds_ring;
1499 struct qlcnic_recv_context *recv_ctx = adapter->recv_ctx;
Himanshu Madhani012ec812013-08-21 11:24:10 -04001500 struct qlcnic_host_tx_ring *tx_ring;
Sony Chackoc70001a2012-11-28 04:34:26 +00001501
Himanshu Madhani34e8c402013-11-04 13:31:31 -05001502 for (ring = 0; ring < adapter->drv_sds_rings; ring++) {
Sony Chackoc70001a2012-11-28 04:34:26 +00001503 sds_ring = &recv_ctx->sds_rings[ring];
1504 netif_napi_del(&sds_ring->napi);
1505 }
1506
1507 qlcnic_free_sds_rings(adapter->recv_ctx);
Himanshu Madhani012ec812013-08-21 11:24:10 -04001508
Himanshu Madhanic2c5e3a2013-08-21 11:24:12 -04001509 if (qlcnic_check_multi_tx(adapter) && !adapter->ahw->diag_test) {
Himanshu Madhani34e8c402013-11-04 13:31:31 -05001510 for (ring = 0; ring < adapter->drv_tx_rings; ring++) {
Himanshu Madhani012ec812013-08-21 11:24:10 -04001511 tx_ring = &adapter->tx_ring[ring];
1512 netif_napi_del(&tx_ring->napi);
1513 }
1514 }
1515
Sony Chacko4be41e92013-01-01 03:20:20 +00001516 qlcnic_free_tx_rings(adapter);
Sony Chackoc70001a2012-11-28 04:34:26 +00001517}
1518
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00001519void qlcnic_82xx_napi_enable(struct qlcnic_adapter *adapter)
Sony Chackoc70001a2012-11-28 04:34:26 +00001520{
1521 int ring;
1522 struct qlcnic_host_sds_ring *sds_ring;
Himanshu Madhani012ec812013-08-21 11:24:10 -04001523 struct qlcnic_host_tx_ring *tx_ring;
Sony Chackoc70001a2012-11-28 04:34:26 +00001524 struct qlcnic_recv_context *recv_ctx = adapter->recv_ctx;
1525
1526 if (adapter->is_up != QLCNIC_ADAPTER_UP_MAGIC)
1527 return;
1528
Himanshu Madhani34e8c402013-11-04 13:31:31 -05001529 for (ring = 0; ring < adapter->drv_sds_rings; ring++) {
Sony Chackoc70001a2012-11-28 04:34:26 +00001530 sds_ring = &recv_ctx->sds_rings[ring];
1531 napi_enable(&sds_ring->napi);
1532 qlcnic_enable_int(sds_ring);
1533 }
Himanshu Madhani012ec812013-08-21 11:24:10 -04001534
1535 if (qlcnic_check_multi_tx(adapter) &&
1536 (adapter->flags & QLCNIC_MSIX_ENABLED) &&
Himanshu Madhanic2c5e3a2013-08-21 11:24:12 -04001537 !adapter->ahw->diag_test &&
Himanshu Madhani34e8c402013-11-04 13:31:31 -05001538 (adapter->drv_tx_rings > QLCNIC_SINGLE_RING)) {
1539 for (ring = 0; ring < adapter->drv_tx_rings; ring++) {
Himanshu Madhani012ec812013-08-21 11:24:10 -04001540 tx_ring = &adapter->tx_ring[ring];
1541 napi_enable(&tx_ring->napi);
1542 qlcnic_enable_tx_intr(adapter, tx_ring);
1543 }
1544 }
Sony Chackoc70001a2012-11-28 04:34:26 +00001545}
1546
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00001547void qlcnic_82xx_napi_disable(struct qlcnic_adapter *adapter)
Sony Chackoc70001a2012-11-28 04:34:26 +00001548{
1549 int ring;
1550 struct qlcnic_host_sds_ring *sds_ring;
Himanshu Madhani012ec812013-08-21 11:24:10 -04001551 struct qlcnic_host_tx_ring *tx_ring;
Sony Chackoc70001a2012-11-28 04:34:26 +00001552 struct qlcnic_recv_context *recv_ctx = adapter->recv_ctx;
1553
1554 if (adapter->is_up != QLCNIC_ADAPTER_UP_MAGIC)
1555 return;
1556
Himanshu Madhani34e8c402013-11-04 13:31:31 -05001557 for (ring = 0; ring < adapter->drv_sds_rings; ring++) {
Sony Chackoc70001a2012-11-28 04:34:26 +00001558 sds_ring = &recv_ctx->sds_rings[ring];
1559 qlcnic_disable_int(sds_ring);
1560 napi_synchronize(&sds_ring->napi);
1561 napi_disable(&sds_ring->napi);
1562 }
Himanshu Madhani012ec812013-08-21 11:24:10 -04001563
1564 if ((adapter->flags & QLCNIC_MSIX_ENABLED) &&
Himanshu Madhanic2c5e3a2013-08-21 11:24:12 -04001565 !adapter->ahw->diag_test &&
Himanshu Madhani012ec812013-08-21 11:24:10 -04001566 qlcnic_check_multi_tx(adapter)) {
Himanshu Madhani34e8c402013-11-04 13:31:31 -05001567 for (ring = 0; ring < adapter->drv_tx_rings; ring++) {
Himanshu Madhani012ec812013-08-21 11:24:10 -04001568 tx_ring = &adapter->tx_ring[ring];
1569 qlcnic_disable_tx_int(adapter, tx_ring);
1570 napi_synchronize(&tx_ring->napi);
1571 napi_disable(&tx_ring->napi);
1572 }
1573 }
Sony Chackoc70001a2012-11-28 04:34:26 +00001574}
Sony Chacko4be41e92013-01-01 03:20:20 +00001575
Shahed Shaikh53643a72013-02-18 13:22:37 +00001576#define QLC_83XX_NORMAL_LB_PKT (1ULL << 36)
1577#define QLC_83XX_LRO_LB_PKT (1ULL << 46)
1578
1579static inline int qlcnic_83xx_is_lb_pkt(u64 sts_data, int lro_pkt)
1580{
1581 if (lro_pkt)
1582 return (sts_data & QLC_83XX_LRO_LB_PKT) ? 1 : 0;
1583 else
1584 return (sts_data & QLC_83XX_NORMAL_LB_PKT) ? 1 : 0;
1585}
1586
Sony Chacko4be41e92013-01-01 03:20:20 +00001587static struct qlcnic_rx_buffer *
1588qlcnic_83xx_process_rcv(struct qlcnic_adapter *adapter,
1589 struct qlcnic_host_sds_ring *sds_ring,
1590 u8 ring, u64 sts_data[])
1591{
1592 struct net_device *netdev = adapter->netdev;
1593 struct qlcnic_recv_context *recv_ctx = adapter->recv_ctx;
1594 struct qlcnic_rx_buffer *buffer;
1595 struct sk_buff *skb;
1596 struct qlcnic_host_rds_ring *rds_ring;
Shahed Shaikh53643a72013-02-18 13:22:37 +00001597 int index, length, cksum, is_lb_pkt;
1598 u16 vid = 0xffff, t_vid;
Sony Chacko4be41e92013-01-01 03:20:20 +00001599
1600 if (unlikely(ring >= adapter->max_rds_rings))
1601 return NULL;
1602
1603 rds_ring = &recv_ctx->rds_rings[ring];
1604
1605 index = qlcnic_83xx_hndl(sts_data[0]);
1606 if (unlikely(index >= rds_ring->num_desc))
1607 return NULL;
1608
1609 buffer = &rds_ring->rx_buf_arr[index];
1610 length = qlcnic_83xx_pktln(sts_data[0]);
1611 cksum = qlcnic_83xx_csum_status(sts_data[1]);
1612 skb = qlcnic_process_rxbuf(adapter, rds_ring, index, cksum);
1613 if (!skb)
1614 return buffer;
1615
Shahed Shaikh53643a72013-02-18 13:22:37 +00001616 if (adapter->drv_mac_learn &&
1617 (adapter->flags & QLCNIC_ESWITCH_ENABLED)) {
1618 t_vid = 0;
1619 is_lb_pkt = qlcnic_83xx_is_lb_pkt(sts_data[1], 0);
Rajesh Borundiaf80bc8f2013-04-19 07:01:08 +00001620 qlcnic_add_lb_filter(adapter, skb, is_lb_pkt, t_vid);
Shahed Shaikh53643a72013-02-18 13:22:37 +00001621 }
1622
Sony Chacko4be41e92013-01-01 03:20:20 +00001623 if (length > rds_ring->skb_size)
1624 skb_put(skb, rds_ring->skb_size);
1625 else
1626 skb_put(skb, length);
1627
1628 if (unlikely(qlcnic_check_rx_tagging(adapter, skb, &vid))) {
1629 adapter->stats.rxdropped++;
1630 dev_kfree_skb(skb);
1631 return buffer;
1632 }
1633
1634 skb->protocol = eth_type_trans(skb, netdev);
1635
1636 if (vid != 0xffff)
Patrick McHardy86a9bad2013-04-19 02:04:30 +00001637 __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q), vid);
Sony Chacko4be41e92013-01-01 03:20:20 +00001638
1639 napi_gro_receive(&sds_ring->napi, skb);
1640
1641 adapter->stats.rx_pkts++;
1642 adapter->stats.rxbytes += length;
1643
1644 return buffer;
1645}
1646
1647static struct qlcnic_rx_buffer *
1648qlcnic_83xx_process_lro(struct qlcnic_adapter *adapter,
1649 u8 ring, u64 sts_data[])
1650{
1651 struct net_device *netdev = adapter->netdev;
1652 struct qlcnic_recv_context *recv_ctx = adapter->recv_ctx;
1653 struct qlcnic_rx_buffer *buffer;
1654 struct sk_buff *skb;
1655 struct qlcnic_host_rds_ring *rds_ring;
1656 struct iphdr *iph;
1657 struct ipv6hdr *ipv6h;
1658 struct tcphdr *th;
1659 bool push;
1660 int l2_hdr_offset, l4_hdr_offset;
Shahed Shaikh53643a72013-02-18 13:22:37 +00001661 int index, is_lb_pkt;
Shahed Shaikh99e85872013-02-18 12:06:16 +00001662 u16 lro_length, length, data_offset, gso_size;
Shahed Shaikh53643a72013-02-18 13:22:37 +00001663 u16 vid = 0xffff, t_vid;
Sony Chacko4be41e92013-01-01 03:20:20 +00001664
1665 if (unlikely(ring > adapter->max_rds_rings))
1666 return NULL;
1667
1668 rds_ring = &recv_ctx->rds_rings[ring];
1669
1670 index = qlcnic_83xx_hndl(sts_data[0]);
1671 if (unlikely(index > rds_ring->num_desc))
1672 return NULL;
1673
1674 buffer = &rds_ring->rx_buf_arr[index];
1675
1676 lro_length = qlcnic_83xx_lro_pktln(sts_data[0]);
1677 l2_hdr_offset = qlcnic_83xx_l2_hdr_off(sts_data[1]);
1678 l4_hdr_offset = qlcnic_83xx_l4_hdr_off(sts_data[1]);
1679 push = qlcnic_83xx_is_psh_bit(sts_data[1]);
1680
1681 skb = qlcnic_process_rxbuf(adapter, rds_ring, index, STATUS_CKSUM_OK);
1682 if (!skb)
1683 return buffer;
Shahed Shaikh53643a72013-02-18 13:22:37 +00001684
1685 if (adapter->drv_mac_learn &&
1686 (adapter->flags & QLCNIC_ESWITCH_ENABLED)) {
1687 t_vid = 0;
1688 is_lb_pkt = qlcnic_83xx_is_lb_pkt(sts_data[1], 1);
Rajesh Borundiaf80bc8f2013-04-19 07:01:08 +00001689 qlcnic_add_lb_filter(adapter, skb, is_lb_pkt, t_vid);
Shahed Shaikh53643a72013-02-18 13:22:37 +00001690 }
Sony Chacko4be41e92013-01-01 03:20:20 +00001691 if (qlcnic_83xx_is_tstamp(sts_data[1]))
1692 data_offset = l4_hdr_offset + QLCNIC_TCP_TS_HDR_SIZE;
1693 else
1694 data_offset = l4_hdr_offset + QLCNIC_TCP_HDR_SIZE;
1695
1696 skb_put(skb, lro_length + data_offset);
1697 skb_pull(skb, l2_hdr_offset);
1698
1699 if (unlikely(qlcnic_check_rx_tagging(adapter, skb, &vid))) {
1700 adapter->stats.rxdropped++;
1701 dev_kfree_skb(skb);
1702 return buffer;
1703 }
1704
1705 skb->protocol = eth_type_trans(skb, netdev);
1706 if (ntohs(skb->protocol) == ETH_P_IPV6) {
1707 ipv6h = (struct ipv6hdr *)skb->data;
1708 th = (struct tcphdr *)(skb->data + sizeof(struct ipv6hdr));
1709
1710 length = (th->doff << 2) + lro_length;
1711 ipv6h->payload_len = htons(length);
1712 } else {
1713 iph = (struct iphdr *)skb->data;
1714 th = (struct tcphdr *)(skb->data + (iph->ihl << 2));
1715 length = (iph->ihl << 2) + (th->doff << 2) + lro_length;
Li RongQing1bcac3b2013-03-14 22:50:07 +00001716 csum_replace2(&iph->check, iph->tot_len, htons(length));
Sony Chacko4be41e92013-01-01 03:20:20 +00001717 iph->tot_len = htons(length);
Sony Chacko4be41e92013-01-01 03:20:20 +00001718 }
1719
1720 th->psh = push;
1721 length = skb->len;
1722
Shahed Shaikh99e85872013-02-18 12:06:16 +00001723 if (adapter->flags & QLCNIC_FW_LRO_MSS_CAP) {
1724 gso_size = qlcnic_83xx_get_lro_sts_mss(sts_data[0]);
1725 skb_shinfo(skb)->gso_size = gso_size;
1726 if (skb->protocol == htons(ETH_P_IPV6))
1727 skb_shinfo(skb)->gso_type = SKB_GSO_TCPV6;
1728 else
1729 skb_shinfo(skb)->gso_type = SKB_GSO_TCPV4;
1730 }
1731
Sony Chacko4be41e92013-01-01 03:20:20 +00001732 if (vid != 0xffff)
Patrick McHardy86a9bad2013-04-19 02:04:30 +00001733 __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q), vid);
Sony Chacko4be41e92013-01-01 03:20:20 +00001734
1735 netif_receive_skb(skb);
1736
1737 adapter->stats.lro_pkts++;
1738 adapter->stats.lrobytes += length;
1739 return buffer;
1740}
1741
1742static int qlcnic_83xx_process_rcv_ring(struct qlcnic_host_sds_ring *sds_ring,
1743 int max)
1744{
1745 struct qlcnic_host_rds_ring *rds_ring;
1746 struct qlcnic_adapter *adapter = sds_ring->adapter;
1747 struct list_head *cur;
1748 struct status_desc *desc;
1749 struct qlcnic_rx_buffer *rxbuf = NULL;
1750 u8 ring;
1751 u64 sts_data[2];
1752 int count = 0, opcode;
1753 u32 consumer = sds_ring->consumer;
1754
1755 while (count < max) {
1756 desc = &sds_ring->desc_head[consumer];
1757 sts_data[1] = le64_to_cpu(desc->status_desc_data[1]);
1758 opcode = qlcnic_83xx_opcode(sts_data[1]);
1759 if (!opcode)
1760 break;
1761 sts_data[0] = le64_to_cpu(desc->status_desc_data[0]);
1762 ring = QLCNIC_FETCH_RING_ID(sts_data[0]);
1763
1764 switch (opcode) {
1765 case QLC_83XX_REG_DESC:
1766 rxbuf = qlcnic_83xx_process_rcv(adapter, sds_ring,
1767 ring, sts_data);
1768 break;
1769 case QLC_83XX_LRO_DESC:
1770 rxbuf = qlcnic_83xx_process_lro(adapter, ring,
1771 sts_data);
1772 break;
1773 default:
1774 dev_info(&adapter->pdev->dev,
Masanari Iida0b1587b2013-07-17 04:37:44 +09001775 "Unknown opcode: 0x%x\n", opcode);
Sony Chacko4be41e92013-01-01 03:20:20 +00001776 goto skip;
1777 }
1778
1779 if (likely(rxbuf))
1780 list_add_tail(&rxbuf->list, &sds_ring->free_list[ring]);
1781 else
1782 adapter->stats.null_rxbuf++;
1783skip:
1784 desc = &sds_ring->desc_head[consumer];
1785 /* Reset the descriptor */
1786 desc->status_desc_data[1] = 0;
1787 consumer = get_next_index(consumer, sds_ring->num_desc);
1788 count++;
1789 }
1790 for (ring = 0; ring < adapter->max_rds_rings; ring++) {
1791 rds_ring = &adapter->recv_ctx->rds_rings[ring];
1792 if (!list_empty(&sds_ring->free_list[ring])) {
1793 list_for_each(cur, &sds_ring->free_list[ring]) {
1794 rxbuf = list_entry(cur, struct qlcnic_rx_buffer,
1795 list);
1796 qlcnic_alloc_rx_skb(adapter, rds_ring, rxbuf);
1797 }
1798 spin_lock(&rds_ring->lock);
1799 list_splice_tail_init(&sds_ring->free_list[ring],
1800 &rds_ring->free_list);
1801 spin_unlock(&rds_ring->lock);
1802 }
1803 qlcnic_post_rx_buffers_nodb(adapter, rds_ring, ring);
1804 }
1805 if (count) {
1806 sds_ring->consumer = consumer;
1807 writel(consumer, sds_ring->crb_sts_consumer);
1808 }
1809 return count;
1810}
1811
Rajesh Borundiada6c8062013-03-29 05:46:35 +00001812static int qlcnic_83xx_msix_sriov_vf_poll(struct napi_struct *napi, int budget)
1813{
1814 int tx_complete;
1815 int work_done;
1816 struct qlcnic_host_sds_ring *sds_ring;
1817 struct qlcnic_adapter *adapter;
1818 struct qlcnic_host_tx_ring *tx_ring;
1819
1820 sds_ring = container_of(napi, struct qlcnic_host_sds_ring, napi);
1821 adapter = sds_ring->adapter;
1822 /* tx ring count = 1 */
1823 tx_ring = adapter->tx_ring;
1824
1825 tx_complete = qlcnic_process_cmd_ring(adapter, tx_ring, budget);
1826 work_done = qlcnic_83xx_process_rcv_ring(sds_ring, budget);
1827 if ((work_done < budget) && tx_complete) {
1828 napi_complete(&sds_ring->napi);
1829 qlcnic_83xx_enable_intr(adapter, sds_ring);
1830 }
1831
1832 return work_done;
1833}
1834
Sony Chacko4be41e92013-01-01 03:20:20 +00001835static int qlcnic_83xx_poll(struct napi_struct *napi, int budget)
1836{
1837 int tx_complete;
1838 int work_done;
1839 struct qlcnic_host_sds_ring *sds_ring;
1840 struct qlcnic_adapter *adapter;
1841 struct qlcnic_host_tx_ring *tx_ring;
1842
1843 sds_ring = container_of(napi, struct qlcnic_host_sds_ring, napi);
1844 adapter = sds_ring->adapter;
1845 /* tx ring count = 1 */
1846 tx_ring = adapter->tx_ring;
1847
Sony Chacko4be41e92013-01-01 03:20:20 +00001848 tx_complete = qlcnic_process_cmd_ring(adapter, tx_ring, budget);
1849 work_done = qlcnic_83xx_process_rcv_ring(sds_ring, budget);
1850 if ((work_done < budget) && tx_complete) {
1851 napi_complete(&sds_ring->napi);
Himanshu Madhaniac166702013-02-18 12:06:15 +00001852 qlcnic_83xx_enable_intr(adapter, sds_ring);
Sony Chacko4be41e92013-01-01 03:20:20 +00001853 }
1854
1855 return work_done;
1856}
1857
1858static int qlcnic_83xx_msix_tx_poll(struct napi_struct *napi, int budget)
1859{
1860 int work_done;
1861 struct qlcnic_host_tx_ring *tx_ring;
1862 struct qlcnic_adapter *adapter;
1863
1864 budget = QLCNIC_TX_POLL_BUDGET;
1865 tx_ring = container_of(napi, struct qlcnic_host_tx_ring, napi);
1866 adapter = tx_ring->adapter;
1867 work_done = qlcnic_process_cmd_ring(adapter, tx_ring, budget);
1868 if (work_done) {
1869 napi_complete(&tx_ring->napi);
1870 if (test_bit(__QLCNIC_DEV_UP , &adapter->state))
1871 qlcnic_83xx_enable_tx_intr(adapter, tx_ring);
1872 }
1873
1874 return work_done;
1875}
1876
1877static int qlcnic_83xx_rx_poll(struct napi_struct *napi, int budget)
1878{
1879 int work_done;
1880 struct qlcnic_host_sds_ring *sds_ring;
1881 struct qlcnic_adapter *adapter;
1882
1883 sds_ring = container_of(napi, struct qlcnic_host_sds_ring, napi);
1884 adapter = sds_ring->adapter;
1885 work_done = qlcnic_83xx_process_rcv_ring(sds_ring, budget);
1886 if (work_done < budget) {
1887 napi_complete(&sds_ring->napi);
1888 if (test_bit(__QLCNIC_DEV_UP, &adapter->state))
1889 qlcnic_83xx_enable_intr(adapter, sds_ring);
1890 }
1891
1892 return work_done;
1893}
1894
1895void qlcnic_83xx_napi_enable(struct qlcnic_adapter *adapter)
1896{
1897 int ring;
1898 struct qlcnic_host_sds_ring *sds_ring;
1899 struct qlcnic_host_tx_ring *tx_ring;
1900 struct qlcnic_recv_context *recv_ctx = adapter->recv_ctx;
1901
1902 if (adapter->is_up != QLCNIC_ADAPTER_UP_MAGIC)
1903 return;
1904
Himanshu Madhani34e8c402013-11-04 13:31:31 -05001905 for (ring = 0; ring < adapter->drv_sds_rings; ring++) {
Sony Chacko4be41e92013-01-01 03:20:20 +00001906 sds_ring = &recv_ctx->sds_rings[ring];
1907 napi_enable(&sds_ring->napi);
Himanshu Madhaniac166702013-02-18 12:06:15 +00001908 if (adapter->flags & QLCNIC_MSIX_ENABLED)
1909 qlcnic_83xx_enable_intr(adapter, sds_ring);
Sony Chacko4be41e92013-01-01 03:20:20 +00001910 }
1911
Rajesh Borundiada6c8062013-03-29 05:46:35 +00001912 if ((adapter->flags & QLCNIC_MSIX_ENABLED) &&
1913 !(adapter->flags & QLCNIC_TX_INTR_SHARED)) {
Himanshu Madhani34e8c402013-11-04 13:31:31 -05001914 for (ring = 0; ring < adapter->drv_tx_rings; ring++) {
Sony Chacko4be41e92013-01-01 03:20:20 +00001915 tx_ring = &adapter->tx_ring[ring];
1916 napi_enable(&tx_ring->napi);
1917 qlcnic_83xx_enable_tx_intr(adapter, tx_ring);
1918 }
1919 }
1920}
1921
1922void qlcnic_83xx_napi_disable(struct qlcnic_adapter *adapter)
1923{
1924 int ring;
1925 struct qlcnic_host_sds_ring *sds_ring;
1926 struct qlcnic_recv_context *recv_ctx = adapter->recv_ctx;
1927 struct qlcnic_host_tx_ring *tx_ring;
1928
1929 if (adapter->is_up != QLCNIC_ADAPTER_UP_MAGIC)
1930 return;
1931
Himanshu Madhani34e8c402013-11-04 13:31:31 -05001932 for (ring = 0; ring < adapter->drv_sds_rings; ring++) {
Sony Chacko4be41e92013-01-01 03:20:20 +00001933 sds_ring = &recv_ctx->sds_rings[ring];
Himanshu Madhaniac166702013-02-18 12:06:15 +00001934 if (adapter->flags & QLCNIC_MSIX_ENABLED)
1935 qlcnic_83xx_disable_intr(adapter, sds_ring);
Sony Chacko4be41e92013-01-01 03:20:20 +00001936 napi_synchronize(&sds_ring->napi);
1937 napi_disable(&sds_ring->napi);
1938 }
1939
Rajesh Borundiada6c8062013-03-29 05:46:35 +00001940 if ((adapter->flags & QLCNIC_MSIX_ENABLED) &&
1941 !(adapter->flags & QLCNIC_TX_INTR_SHARED)) {
Himanshu Madhani34e8c402013-11-04 13:31:31 -05001942 for (ring = 0; ring < adapter->drv_tx_rings; ring++) {
Sony Chacko4be41e92013-01-01 03:20:20 +00001943 tx_ring = &adapter->tx_ring[ring];
1944 qlcnic_83xx_disable_tx_intr(adapter, tx_ring);
1945 napi_synchronize(&tx_ring->napi);
1946 napi_disable(&tx_ring->napi);
1947 }
1948 }
1949}
1950
1951int qlcnic_83xx_napi_add(struct qlcnic_adapter *adapter,
1952 struct net_device *netdev)
1953{
Michal Schmidtdf95fc42013-09-04 15:03:05 +02001954 int ring;
Sony Chacko4be41e92013-01-01 03:20:20 +00001955 struct qlcnic_host_sds_ring *sds_ring;
1956 struct qlcnic_host_tx_ring *tx_ring;
1957 struct qlcnic_recv_context *recv_ctx = adapter->recv_ctx;
1958
Himanshu Madhani34e8c402013-11-04 13:31:31 -05001959 if (qlcnic_alloc_sds_rings(recv_ctx, adapter->drv_sds_rings))
Sony Chacko4be41e92013-01-01 03:20:20 +00001960 return -ENOMEM;
1961
Himanshu Madhani34e8c402013-11-04 13:31:31 -05001962 for (ring = 0; ring < adapter->drv_sds_rings; ring++) {
Sony Chacko4be41e92013-01-01 03:20:20 +00001963 sds_ring = &recv_ctx->sds_rings[ring];
Rajesh Borundiada6c8062013-03-29 05:46:35 +00001964 if (adapter->flags & QLCNIC_MSIX_ENABLED) {
Michal Schmidtdf95fc42013-09-04 15:03:05 +02001965 if (!(adapter->flags & QLCNIC_TX_INTR_SHARED))
Rajesh Borundiada6c8062013-03-29 05:46:35 +00001966 netif_napi_add(netdev, &sds_ring->napi,
1967 qlcnic_83xx_rx_poll,
Michal Schmidtdf95fc42013-09-04 15:03:05 +02001968 NAPI_POLL_WEIGHT);
1969 else
Rajesh Borundiada6c8062013-03-29 05:46:35 +00001970 netif_napi_add(netdev, &sds_ring->napi,
1971 qlcnic_83xx_msix_sriov_vf_poll,
Michal Schmidtdf95fc42013-09-04 15:03:05 +02001972 NAPI_POLL_WEIGHT);
Rajesh Borundiada6c8062013-03-29 05:46:35 +00001973
1974 } else {
Sony Chacko4be41e92013-01-01 03:20:20 +00001975 netif_napi_add(netdev, &sds_ring->napi,
1976 qlcnic_83xx_poll,
Michal Schmidtdf95fc42013-09-04 15:03:05 +02001977 NAPI_POLL_WEIGHT);
Rajesh Borundiada6c8062013-03-29 05:46:35 +00001978 }
Sony Chacko4be41e92013-01-01 03:20:20 +00001979 }
1980
1981 if (qlcnic_alloc_tx_rings(adapter, netdev)) {
1982 qlcnic_free_sds_rings(recv_ctx);
1983 return -ENOMEM;
1984 }
1985
Rajesh Borundiada6c8062013-03-29 05:46:35 +00001986 if ((adapter->flags & QLCNIC_MSIX_ENABLED) &&
1987 !(adapter->flags & QLCNIC_TX_INTR_SHARED)) {
Himanshu Madhani34e8c402013-11-04 13:31:31 -05001988 for (ring = 0; ring < adapter->drv_tx_rings; ring++) {
Sony Chacko4be41e92013-01-01 03:20:20 +00001989 tx_ring = &adapter->tx_ring[ring];
1990 netif_napi_add(netdev, &tx_ring->napi,
1991 qlcnic_83xx_msix_tx_poll,
Michal Schmidtdf95fc42013-09-04 15:03:05 +02001992 NAPI_POLL_WEIGHT);
Sony Chacko4be41e92013-01-01 03:20:20 +00001993 }
1994 }
1995
1996 return 0;
1997}
1998
1999void qlcnic_83xx_napi_del(struct qlcnic_adapter *adapter)
2000{
2001 int ring;
2002 struct qlcnic_host_sds_ring *sds_ring;
2003 struct qlcnic_recv_context *recv_ctx = adapter->recv_ctx;
2004 struct qlcnic_host_tx_ring *tx_ring;
2005
Himanshu Madhani34e8c402013-11-04 13:31:31 -05002006 for (ring = 0; ring < adapter->drv_sds_rings; ring++) {
Sony Chacko4be41e92013-01-01 03:20:20 +00002007 sds_ring = &recv_ctx->sds_rings[ring];
2008 netif_napi_del(&sds_ring->napi);
2009 }
2010
2011 qlcnic_free_sds_rings(adapter->recv_ctx);
2012
Rajesh Borundiada6c8062013-03-29 05:46:35 +00002013 if ((adapter->flags & QLCNIC_MSIX_ENABLED) &&
2014 !(adapter->flags & QLCNIC_TX_INTR_SHARED)) {
Himanshu Madhani34e8c402013-11-04 13:31:31 -05002015 for (ring = 0; ring < adapter->drv_tx_rings; ring++) {
Sony Chacko4be41e92013-01-01 03:20:20 +00002016 tx_ring = &adapter->tx_ring[ring];
2017 netif_napi_del(&tx_ring->napi);
2018 }
2019 }
2020
2021 qlcnic_free_tx_rings(adapter);
2022}
2023
2024void qlcnic_83xx_process_rcv_diag(struct qlcnic_adapter *adapter,
2025 int ring, u64 sts_data[])
2026{
2027 struct qlcnic_recv_context *recv_ctx = adapter->recv_ctx;
2028 struct sk_buff *skb;
2029 struct qlcnic_host_rds_ring *rds_ring;
2030 int index, length;
2031
2032 if (unlikely(ring >= adapter->max_rds_rings))
2033 return;
2034
2035 rds_ring = &recv_ctx->rds_rings[ring];
2036 index = qlcnic_83xx_hndl(sts_data[0]);
2037 if (unlikely(index >= rds_ring->num_desc))
2038 return;
2039
2040 length = qlcnic_83xx_pktln(sts_data[0]);
2041
2042 skb = qlcnic_process_rxbuf(adapter, rds_ring, index, STATUS_CKSUM_OK);
2043 if (!skb)
2044 return;
2045
2046 if (length > rds_ring->skb_size)
2047 skb_put(skb, rds_ring->skb_size);
2048 else
2049 skb_put(skb, length);
2050
2051 if (!qlcnic_check_loopback_buff(skb->data, adapter->mac_addr))
2052 adapter->ahw->diag_cnt++;
2053 else
2054 dump_skb(skb, adapter);
2055
2056 dev_kfree_skb_any(skb);
2057 return;
2058}
2059
2060void qlcnic_83xx_process_rcv_ring_diag(struct qlcnic_host_sds_ring *sds_ring)
2061{
2062 struct qlcnic_adapter *adapter = sds_ring->adapter;
2063 struct status_desc *desc;
2064 u64 sts_data[2];
2065 int ring, opcode;
2066 u32 consumer = sds_ring->consumer;
2067
2068 desc = &sds_ring->desc_head[consumer];
2069 sts_data[0] = le64_to_cpu(desc->status_desc_data[0]);
2070 sts_data[1] = le64_to_cpu(desc->status_desc_data[1]);
2071 opcode = qlcnic_83xx_opcode(sts_data[1]);
2072 if (!opcode)
2073 return;
2074
2075 ring = QLCNIC_FETCH_RING_ID(qlcnic_83xx_hndl(sts_data[0]));
2076 qlcnic_83xx_process_rcv_diag(adapter, ring, sts_data);
2077 desc = &sds_ring->desc_head[consumer];
2078 desc->status_desc_data[0] = cpu_to_le64(STATUS_OWNER_PHANTOM);
2079 consumer = get_next_index(consumer, sds_ring->num_desc);
2080 sds_ring->consumer = consumer;
2081 writel(consumer, sds_ring->crb_sts_consumer);
2082}