blob: f3fe31e8f6bdf78a0c6c295e76dcee072d6fee65 [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
130inline void qlcnic_83xx_enable_tx_intr(struct qlcnic_adapter *adapter,
131 struct qlcnic_host_tx_ring *tx_ring)
132{
133 writel(0, tx_ring->crb_intr_mask);
134}
135
136inline void qlcnic_83xx_disable_tx_intr(struct qlcnic_adapter *adapter,
137 struct qlcnic_host_tx_ring *tx_ring)
138{
139 writel(1, tx_ring->crb_intr_mask);
140}
141
142static inline u8 qlcnic_mac_hash(u64 mac)
143{
144 return (u8)((mac & 0xff) ^ ((mac >> 40) & 0xff));
145}
146
147static inline u32 qlcnic_get_ref_handle(struct qlcnic_adapter *adapter,
148 u16 handle, u8 ring_id)
149{
Rajesh Borundia7cb03b22013-03-29 05:46:37 +0000150 unsigned short device = adapter->pdev->device;
151
152 if ((device == PCI_DEVICE_ID_QLOGIC_QLE834X) ||
153 (device == PCI_DEVICE_ID_QLOGIC_VF_QLE834X))
Sony Chacko4be41e92013-01-01 03:20:20 +0000154 return handle | (ring_id << 15);
155 else
156 return handle;
157}
158
Shahed Shaikh53643a72013-02-18 13:22:37 +0000159static inline int qlcnic_82xx_is_lb_pkt(u64 sts_data)
160{
161 return (qlcnic_get_sts_status(sts_data) == STATUS_CKSUM_LOOP) ? 1 : 0;
162}
163
164void qlcnic_add_lb_filter(struct qlcnic_adapter *adapter, struct sk_buff *skb,
Rajesh Borundiaf80bc8f2013-04-19 07:01:08 +0000165 int loopback_pkt, u16 vlan_id)
Shahed Shaikh53643a72013-02-18 13:22:37 +0000166{
167 struct ethhdr *phdr = (struct ethhdr *)(skb->data);
168 struct qlcnic_filter *fil, *tmp_fil;
Sasha Levinb67bfe02013-02-27 17:06:00 -0800169 struct hlist_node *n;
Shahed Shaikh53643a72013-02-18 13:22:37 +0000170 struct hlist_head *head;
171 unsigned long time;
172 u64 src_addr = 0;
173 u8 hindex, found = 0, op;
174 int ret;
175
176 memcpy(&src_addr, phdr->h_source, ETH_ALEN);
177
178 if (loopback_pkt) {
179 if (adapter->rx_fhash.fnum >= adapter->rx_fhash.fmax)
180 return;
181
182 hindex = qlcnic_mac_hash(src_addr) &
183 (adapter->fhash.fbucket_size - 1);
184 head = &(adapter->rx_fhash.fhead[hindex]);
185
Sasha Levinb67bfe02013-02-27 17:06:00 -0800186 hlist_for_each_entry_safe(tmp_fil, n, head, fnode) {
Shahed Shaikh53643a72013-02-18 13:22:37 +0000187 if (!memcmp(tmp_fil->faddr, &src_addr, ETH_ALEN) &&
188 tmp_fil->vlan_id == vlan_id) {
189 time = tmp_fil->ftime;
190 if (jiffies > (QLCNIC_READD_AGE * HZ + time))
191 tmp_fil->ftime = jiffies;
192 return;
193 }
194 }
195
196 fil = kzalloc(sizeof(struct qlcnic_filter), GFP_ATOMIC);
197 if (!fil)
198 return;
199
200 fil->ftime = jiffies;
201 memcpy(fil->faddr, &src_addr, ETH_ALEN);
202 fil->vlan_id = vlan_id;
203 spin_lock(&adapter->rx_mac_learn_lock);
204 hlist_add_head(&(fil->fnode), head);
205 adapter->rx_fhash.fnum++;
206 spin_unlock(&adapter->rx_mac_learn_lock);
207 } else {
208 hindex = qlcnic_mac_hash(src_addr) &
209 (adapter->fhash.fbucket_size - 1);
210 head = &(adapter->rx_fhash.fhead[hindex]);
211 spin_lock(&adapter->rx_mac_learn_lock);
Sasha Levinb67bfe02013-02-27 17:06:00 -0800212 hlist_for_each_entry_safe(tmp_fil, n, head, fnode) {
Shahed Shaikh53643a72013-02-18 13:22:37 +0000213 if (!memcmp(tmp_fil->faddr, &src_addr, ETH_ALEN) &&
214 tmp_fil->vlan_id == vlan_id) {
215 found = 1;
216 break;
217 }
218 }
219
220 if (!found) {
221 spin_unlock(&adapter->rx_mac_learn_lock);
222 return;
223 }
224
225 op = vlan_id ? QLCNIC_MAC_VLAN_ADD : QLCNIC_MAC_ADD;
226 ret = qlcnic_sre_macaddr_change(adapter, (u8 *)&src_addr,
227 vlan_id, op);
228 if (!ret) {
229 op = vlan_id ? QLCNIC_MAC_VLAN_DEL : QLCNIC_MAC_DEL;
230 ret = qlcnic_sre_macaddr_change(adapter,
231 (u8 *)&src_addr,
232 vlan_id, op);
233 if (!ret) {
234 hlist_del(&(tmp_fil->fnode));
235 adapter->rx_fhash.fnum--;
236 }
237 }
238 spin_unlock(&adapter->rx_mac_learn_lock);
239 }
240}
241
Sony Chacko7e2cf4f2013-01-01 03:20:17 +0000242void qlcnic_82xx_change_filter(struct qlcnic_adapter *adapter, u64 *uaddr,
Rajesh Borundiaf80bc8f2013-04-19 07:01:08 +0000243 u16 vlan_id)
Sony Chackoc70001a2012-11-28 04:34:26 +0000244{
245 struct cmd_desc_type0 *hwdesc;
246 struct qlcnic_nic_req *req;
247 struct qlcnic_mac_req *mac_req;
248 struct qlcnic_vlan_req *vlan_req;
Sony Chacko7e2cf4f2013-01-01 03:20:17 +0000249 struct qlcnic_host_tx_ring *tx_ring = adapter->tx_ring;
Sony Chackoc70001a2012-11-28 04:34:26 +0000250 u32 producer;
251 u64 word;
252
253 producer = tx_ring->producer;
254 hwdesc = &tx_ring->desc_head[tx_ring->producer];
255
256 req = (struct qlcnic_nic_req *)hwdesc;
257 memset(req, 0, sizeof(struct qlcnic_nic_req));
258 req->qhdr = cpu_to_le64(QLCNIC_REQUEST << 23);
259
260 word = QLCNIC_MAC_EVENT | ((u64)(adapter->portnum) << 16);
261 req->req_hdr = cpu_to_le64(word);
262
263 mac_req = (struct qlcnic_mac_req *)&(req->words[0]);
264 mac_req->op = vlan_id ? QLCNIC_MAC_VLAN_ADD : QLCNIC_MAC_ADD;
265 memcpy(mac_req->mac_addr, &uaddr, ETH_ALEN);
266
267 vlan_req = (struct qlcnic_vlan_req *)&req->words[1];
Rajesh Borundiaf80bc8f2013-04-19 07:01:08 +0000268 vlan_req->vlan_id = cpu_to_le16(vlan_id);
Sony Chackoc70001a2012-11-28 04:34:26 +0000269
270 tx_ring->producer = get_next_index(producer, tx_ring->num_desc);
271 smp_mb();
272}
273
Sony Chackod17dd0d2012-11-28 04:34:27 +0000274static void qlcnic_send_filter(struct qlcnic_adapter *adapter,
Sony Chackod17dd0d2012-11-28 04:34:27 +0000275 struct cmd_desc_type0 *first_desc,
276 struct sk_buff *skb)
Sony Chackoc70001a2012-11-28 04:34:26 +0000277{
Sony Chackoc70001a2012-11-28 04:34:26 +0000278 struct qlcnic_filter *fil, *tmp_fil;
Sasha Levinb67bfe02013-02-27 17:06:00 -0800279 struct hlist_node *n;
Sony Chackoc70001a2012-11-28 04:34:26 +0000280 struct hlist_head *head;
Sony Chacko4be41e92013-01-01 03:20:20 +0000281 struct net_device *netdev = adapter->netdev;
Sony Chacko7e2cf4f2013-01-01 03:20:17 +0000282 struct ethhdr *phdr = (struct ethhdr *)(skb->data);
Sony Chackoc70001a2012-11-28 04:34:26 +0000283 u64 src_addr = 0;
Rajesh Borundiaf80bc8f2013-04-19 07:01:08 +0000284 u16 vlan_id = 0;
Sony Chackoc70001a2012-11-28 04:34:26 +0000285 u8 hindex;
286
Sony Chacko4be41e92013-01-01 03:20:20 +0000287 if (ether_addr_equal(phdr->h_source, adapter->mac_addr))
Sony Chackoc70001a2012-11-28 04:34:26 +0000288 return;
289
Sony Chacko4be41e92013-01-01 03:20:20 +0000290 if (adapter->fhash.fnum >= adapter->fhash.fmax) {
291 adapter->stats.mac_filter_limit_overrun++;
292 netdev_info(netdev, "Can not add more than %d mac addresses\n",
293 adapter->fhash.fmax);
Sony Chackoc70001a2012-11-28 04:34:26 +0000294 return;
Sony Chacko4be41e92013-01-01 03:20:20 +0000295 }
Sony Chackoc70001a2012-11-28 04:34:26 +0000296
Sony Chackoc70001a2012-11-28 04:34:26 +0000297 memcpy(&src_addr, phdr->h_source, ETH_ALEN);
Sony Chacko4be41e92013-01-01 03:20:20 +0000298 hindex = qlcnic_mac_hash(src_addr) & (adapter->fhash.fbucket_size - 1);
Sony Chackoc70001a2012-11-28 04:34:26 +0000299 head = &(adapter->fhash.fhead[hindex]);
300
Sasha Levinb67bfe02013-02-27 17:06:00 -0800301 hlist_for_each_entry_safe(tmp_fil, n, head, fnode) {
Sony Chackoc70001a2012-11-28 04:34:26 +0000302 if (!memcmp(tmp_fil->faddr, &src_addr, ETH_ALEN) &&
Sony Chacko7e2cf4f2013-01-01 03:20:17 +0000303 tmp_fil->vlan_id == vlan_id) {
Sony Chackod17dd0d2012-11-28 04:34:27 +0000304 if (jiffies > (QLCNIC_READD_AGE * HZ + tmp_fil->ftime))
Sony Chacko7e2cf4f2013-01-01 03:20:17 +0000305 qlcnic_change_filter(adapter, &src_addr,
306 vlan_id);
Sony Chackoc70001a2012-11-28 04:34:26 +0000307 tmp_fil->ftime = jiffies;
308 return;
309 }
310 }
311
312 fil = kzalloc(sizeof(struct qlcnic_filter), GFP_ATOMIC);
313 if (!fil)
314 return;
315
Sony Chacko7e2cf4f2013-01-01 03:20:17 +0000316 qlcnic_change_filter(adapter, &src_addr, vlan_id);
Sony Chackoc70001a2012-11-28 04:34:26 +0000317 fil->ftime = jiffies;
318 fil->vlan_id = vlan_id;
319 memcpy(fil->faddr, &src_addr, ETH_ALEN);
320 spin_lock(&adapter->mac_learn_lock);
321 hlist_add_head(&(fil->fnode), head);
322 adapter->fhash.fnum++;
323 spin_unlock(&adapter->mac_learn_lock);
324}
325
Sony Chackod17dd0d2012-11-28 04:34:27 +0000326static int qlcnic_tx_pkt(struct qlcnic_adapter *adapter,
327 struct cmd_desc_type0 *first_desc, struct sk_buff *skb)
Sony Chackoc70001a2012-11-28 04:34:26 +0000328{
Sony Chackod17dd0d2012-11-28 04:34:27 +0000329 u8 l4proto, opcode = 0, hdr_len = 0;
Sony Chackoc70001a2012-11-28 04:34:26 +0000330 u16 flags = 0, vlan_tci = 0;
Sony Chackod17dd0d2012-11-28 04:34:27 +0000331 int copied, offset, copy_len, size;
Sony Chackoc70001a2012-11-28 04:34:26 +0000332 struct cmd_desc_type0 *hwdesc;
333 struct vlan_ethhdr *vh;
334 struct qlcnic_host_tx_ring *tx_ring = adapter->tx_ring;
335 u16 protocol = ntohs(skb->protocol);
336 u32 producer = tx_ring->producer;
337
338 if (protocol == ETH_P_8021Q) {
339 vh = (struct vlan_ethhdr *)skb->data;
340 flags = FLAGS_VLAN_TAGGED;
341 vlan_tci = ntohs(vh->h_vlan_TCI);
342 protocol = ntohs(vh->h_vlan_encapsulated_proto);
343 } else if (vlan_tx_tag_present(skb)) {
344 flags = FLAGS_VLAN_OOB;
345 vlan_tci = vlan_tx_tag_get(skb);
346 }
347 if (unlikely(adapter->pvid)) {
348 if (vlan_tci && !(adapter->flags & QLCNIC_TAGGING_ENABLED))
349 return -EIO;
350 if (vlan_tci && (adapter->flags & QLCNIC_TAGGING_ENABLED))
351 goto set_flags;
352
353 flags = FLAGS_VLAN_OOB;
354 vlan_tci = adapter->pvid;
355 }
356set_flags:
357 qlcnic_set_tx_vlan_tci(first_desc, vlan_tci);
358 qlcnic_set_tx_flags_opcode(first_desc, flags, opcode);
359
360 if (*(skb->data) & BIT_0) {
361 flags |= BIT_0;
362 memcpy(&first_desc->eth_addr, skb->data, ETH_ALEN);
363 }
364 opcode = TX_ETHER_PKT;
365 if ((adapter->netdev->features & (NETIF_F_TSO | NETIF_F_TSO6)) &&
Sony Chackod17dd0d2012-11-28 04:34:27 +0000366 skb_shinfo(skb)->gso_size > 0) {
Sony Chackoc70001a2012-11-28 04:34:26 +0000367 hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
Sony Chackoc70001a2012-11-28 04:34:26 +0000368 first_desc->mss = cpu_to_le16(skb_shinfo(skb)->gso_size);
369 first_desc->total_hdr_length = hdr_len;
Sony Chackoc70001a2012-11-28 04:34:26 +0000370 opcode = (protocol == ETH_P_IPV6) ? TX_TCP_LSO6 : TX_TCP_LSO;
371
372 /* For LSO, we need to copy the MAC/IP/TCP headers into
373 * the descriptor ring */
374 copied = 0;
375 offset = 2;
376
377 if (flags & FLAGS_VLAN_OOB) {
378 first_desc->total_hdr_length += VLAN_HLEN;
379 first_desc->tcp_hdr_offset = VLAN_HLEN;
380 first_desc->ip_hdr_offset = VLAN_HLEN;
Sony Chackod17dd0d2012-11-28 04:34:27 +0000381
Sony Chackoc70001a2012-11-28 04:34:26 +0000382 /* Only in case of TSO on vlan device */
383 flags |= FLAGS_VLAN_TAGGED;
384
385 /* Create a TSO vlan header template for firmware */
Sony Chackoc70001a2012-11-28 04:34:26 +0000386 hwdesc = &tx_ring->desc_head[producer];
387 tx_ring->cmd_buf_arr[producer].skb = NULL;
388
389 copy_len = min((int)sizeof(struct cmd_desc_type0) -
Sony Chackod17dd0d2012-11-28 04:34:27 +0000390 offset, hdr_len + VLAN_HLEN);
Sony Chackoc70001a2012-11-28 04:34:26 +0000391
392 vh = (struct vlan_ethhdr *)((char *) hwdesc + 2);
393 skb_copy_from_linear_data(skb, vh, 12);
394 vh->h_vlan_proto = htons(ETH_P_8021Q);
395 vh->h_vlan_TCI = htons(vlan_tci);
396
397 skb_copy_from_linear_data_offset(skb, 12,
Sony Chackod17dd0d2012-11-28 04:34:27 +0000398 (char *)vh + 16,
399 copy_len - 16);
Sony Chackoc70001a2012-11-28 04:34:26 +0000400 copied = copy_len - VLAN_HLEN;
401 offset = 0;
Sony Chackoc70001a2012-11-28 04:34:26 +0000402 producer = get_next_index(producer, tx_ring->num_desc);
403 }
404
405 while (copied < hdr_len) {
Sony Chackod17dd0d2012-11-28 04:34:27 +0000406 size = (int)sizeof(struct cmd_desc_type0) - offset;
407 copy_len = min(size, (hdr_len - copied));
Sony Chackoc70001a2012-11-28 04:34:26 +0000408 hwdesc = &tx_ring->desc_head[producer];
409 tx_ring->cmd_buf_arr[producer].skb = NULL;
Sony Chackoc70001a2012-11-28 04:34:26 +0000410 skb_copy_from_linear_data_offset(skb, copied,
Sony Chackod17dd0d2012-11-28 04:34:27 +0000411 (char *)hwdesc +
412 offset, copy_len);
Sony Chackoc70001a2012-11-28 04:34:26 +0000413 copied += copy_len;
414 offset = 0;
Sony Chackoc70001a2012-11-28 04:34:26 +0000415 producer = get_next_index(producer, tx_ring->num_desc);
416 }
417
418 tx_ring->producer = producer;
419 smp_mb();
420 adapter->stats.lso_frames++;
421
422 } else if (skb->ip_summed == CHECKSUM_PARTIAL) {
Sony Chackoc70001a2012-11-28 04:34:26 +0000423 if (protocol == ETH_P_IP) {
424 l4proto = ip_hdr(skb)->protocol;
425
426 if (l4proto == IPPROTO_TCP)
427 opcode = TX_TCP_PKT;
428 else if (l4proto == IPPROTO_UDP)
429 opcode = TX_UDP_PKT;
430 } else if (protocol == ETH_P_IPV6) {
431 l4proto = ipv6_hdr(skb)->nexthdr;
432
433 if (l4proto == IPPROTO_TCP)
434 opcode = TX_TCPV6_PKT;
435 else if (l4proto == IPPROTO_UDP)
436 opcode = TX_UDPV6_PKT;
437 }
438 }
439 first_desc->tcp_hdr_offset += skb_transport_offset(skb);
440 first_desc->ip_hdr_offset += skb_network_offset(skb);
441 qlcnic_set_tx_flags_opcode(first_desc, flags, opcode);
442
443 return 0;
444}
445
Sony Chackod17dd0d2012-11-28 04:34:27 +0000446static int qlcnic_map_tx_skb(struct pci_dev *pdev, struct sk_buff *skb,
447 struct qlcnic_cmd_buffer *pbuf)
Sony Chackoc70001a2012-11-28 04:34:26 +0000448{
449 struct qlcnic_skb_frag *nf;
450 struct skb_frag_struct *frag;
451 int i, nr_frags;
452 dma_addr_t map;
453
454 nr_frags = skb_shinfo(skb)->nr_frags;
455 nf = &pbuf->frag_array[0];
456
Sony Chackod17dd0d2012-11-28 04:34:27 +0000457 map = pci_map_single(pdev, skb->data, skb_headlen(skb),
458 PCI_DMA_TODEVICE);
Sony Chackoc70001a2012-11-28 04:34:26 +0000459 if (pci_dma_mapping_error(pdev, map))
460 goto out_err;
461
462 nf->dma = map;
463 nf->length = skb_headlen(skb);
464
465 for (i = 0; i < nr_frags; i++) {
466 frag = &skb_shinfo(skb)->frags[i];
467 nf = &pbuf->frag_array[i+1];
Sony Chackoc70001a2012-11-28 04:34:26 +0000468 map = skb_frag_dma_map(&pdev->dev, frag, 0, skb_frag_size(frag),
469 DMA_TO_DEVICE);
470 if (dma_mapping_error(&pdev->dev, map))
471 goto unwind;
472
473 nf->dma = map;
474 nf->length = skb_frag_size(frag);
475 }
476
477 return 0;
478
479unwind:
480 while (--i >= 0) {
481 nf = &pbuf->frag_array[i+1];
482 pci_unmap_page(pdev, nf->dma, nf->length, PCI_DMA_TODEVICE);
483 }
484
485 nf = &pbuf->frag_array[0];
486 pci_unmap_single(pdev, nf->dma, skb_headlen(skb), PCI_DMA_TODEVICE);
487
488out_err:
489 return -ENOMEM;
490}
491
Sony Chackod17dd0d2012-11-28 04:34:27 +0000492static void qlcnic_unmap_buffers(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 = &pbuf->frag_array[0];
Sony Chackod17dd0d2012-11-28 04:34:27 +0000496 int i, nr_frags = skb_shinfo(skb)->nr_frags;
Sony Chackoc70001a2012-11-28 04:34:26 +0000497
498 for (i = 0; i < nr_frags; i++) {
499 nf = &pbuf->frag_array[i+1];
500 pci_unmap_page(pdev, nf->dma, nf->length, PCI_DMA_TODEVICE);
501 }
502
503 nf = &pbuf->frag_array[0];
504 pci_unmap_single(pdev, nf->dma, skb_headlen(skb), PCI_DMA_TODEVICE);
505 pbuf->skb = NULL;
506}
507
Sony Chackod17dd0d2012-11-28 04:34:27 +0000508static inline void qlcnic_clear_cmddesc(u64 *desc)
Sony Chackoc70001a2012-11-28 04:34:26 +0000509{
510 desc[0] = 0ULL;
511 desc[2] = 0ULL;
512 desc[7] = 0ULL;
513}
514
Sony Chackod17dd0d2012-11-28 04:34:27 +0000515netdev_tx_t qlcnic_xmit_frame(struct sk_buff *skb, struct net_device *netdev)
Sony Chackoc70001a2012-11-28 04:34:26 +0000516{
517 struct qlcnic_adapter *adapter = netdev_priv(netdev);
518 struct qlcnic_host_tx_ring *tx_ring = adapter->tx_ring;
519 struct qlcnic_cmd_buffer *pbuf;
520 struct qlcnic_skb_frag *buffrag;
521 struct cmd_desc_type0 *hwdesc, *first_desc;
522 struct pci_dev *pdev;
523 struct ethhdr *phdr;
Sony Chackod17dd0d2012-11-28 04:34:27 +0000524 int i, k, frag_count, delta = 0;
525 u32 producer, num_txd;
Sony Chackoc70001a2012-11-28 04:34:26 +0000526
Sony Chackod17dd0d2012-11-28 04:34:27 +0000527 num_txd = tx_ring->num_desc;
Sony Chackoc70001a2012-11-28 04:34:26 +0000528
529 if (!test_bit(__QLCNIC_DEV_UP, &adapter->state)) {
530 netif_stop_queue(netdev);
531 return NETDEV_TX_BUSY;
532 }
533
534 if (adapter->flags & QLCNIC_MACSPOOF) {
535 phdr = (struct ethhdr *)skb->data;
536 if (!ether_addr_equal(phdr->h_source, adapter->mac_addr))
537 goto drop_packet;
538 }
539
540 frag_count = skb_shinfo(skb)->nr_frags + 1;
541 /* 14 frags supported for normal packet and
542 * 32 frags supported for TSO packet
543 */
544 if (!skb_is_gso(skb) && frag_count > QLCNIC_MAX_FRAGS_PER_TX) {
Sony Chackoc70001a2012-11-28 04:34:26 +0000545 for (i = 0; i < (frag_count - QLCNIC_MAX_FRAGS_PER_TX); i++)
546 delta += skb_frag_size(&skb_shinfo(skb)->frags[i]);
547
548 if (!__pskb_pull_tail(skb, delta))
549 goto drop_packet;
550
551 frag_count = 1 + skb_shinfo(skb)->nr_frags;
552 }
553
554 if (unlikely(qlcnic_tx_avail(tx_ring) <= TX_STOP_THRESH)) {
555 netif_stop_queue(netdev);
Sony Chackod17dd0d2012-11-28 04:34:27 +0000556 if (qlcnic_tx_avail(tx_ring) > TX_STOP_THRESH) {
Sony Chackoc70001a2012-11-28 04:34:26 +0000557 netif_start_queue(netdev);
Sony Chackod17dd0d2012-11-28 04:34:27 +0000558 } else {
Sony Chackoc70001a2012-11-28 04:34:26 +0000559 adapter->stats.xmit_off++;
560 return NETDEV_TX_BUSY;
561 }
562 }
563
564 producer = tx_ring->producer;
565 pbuf = &tx_ring->cmd_buf_arr[producer];
Sony Chackoc70001a2012-11-28 04:34:26 +0000566 pdev = adapter->pdev;
Sony Chackod17dd0d2012-11-28 04:34:27 +0000567 first_desc = &tx_ring->desc_head[producer];
568 hwdesc = &tx_ring->desc_head[producer];
Sony Chackoc70001a2012-11-28 04:34:26 +0000569 qlcnic_clear_cmddesc((u64 *)hwdesc);
570
571 if (qlcnic_map_tx_skb(pdev, skb, pbuf)) {
572 adapter->stats.tx_dma_map_error++;
573 goto drop_packet;
574 }
575
576 pbuf->skb = skb;
577 pbuf->frag_count = frag_count;
578
579 qlcnic_set_tx_frags_len(first_desc, frag_count, skb->len);
580 qlcnic_set_tx_port(first_desc, adapter->portnum);
581
582 for (i = 0; i < frag_count; i++) {
Sony Chackoc70001a2012-11-28 04:34:26 +0000583 k = i % 4;
584
585 if ((k == 0) && (i > 0)) {
586 /* move to next desc.*/
587 producer = get_next_index(producer, num_txd);
588 hwdesc = &tx_ring->desc_head[producer];
589 qlcnic_clear_cmddesc((u64 *)hwdesc);
590 tx_ring->cmd_buf_arr[producer].skb = NULL;
591 }
592
593 buffrag = &pbuf->frag_array[i];
Sony Chackoc70001a2012-11-28 04:34:26 +0000594 hwdesc->buffer_length[k] = cpu_to_le16(buffrag->length);
595 switch (k) {
596 case 0:
597 hwdesc->addr_buffer1 = cpu_to_le64(buffrag->dma);
598 break;
599 case 1:
600 hwdesc->addr_buffer2 = cpu_to_le64(buffrag->dma);
601 break;
602 case 2:
603 hwdesc->addr_buffer3 = cpu_to_le64(buffrag->dma);
604 break;
605 case 3:
606 hwdesc->addr_buffer4 = cpu_to_le64(buffrag->dma);
607 break;
608 }
609 }
610
611 tx_ring->producer = get_next_index(producer, num_txd);
612 smp_mb();
613
614 if (unlikely(qlcnic_tx_pkt(adapter, first_desc, skb)))
615 goto unwind_buff;
616
Jitendra Kalsariafe1adc62013-01-25 10:20:40 +0000617 if (adapter->drv_mac_learn)
Sony Chacko4be41e92013-01-01 03:20:20 +0000618 qlcnic_send_filter(adapter, first_desc, skb);
Sony Chackoc70001a2012-11-28 04:34:26 +0000619
620 adapter->stats.txbytes += skb->len;
621 adapter->stats.xmitcalled++;
622
623 qlcnic_update_cmd_producer(tx_ring);
624
625 return NETDEV_TX_OK;
626
627unwind_buff:
628 qlcnic_unmap_buffers(pdev, skb, pbuf);
629drop_packet:
630 adapter->stats.txdropped++;
631 dev_kfree_skb_any(skb);
632 return NETDEV_TX_OK;
633}
634
Sony Chacko7f9664522013-01-01 03:20:19 +0000635void qlcnic_advert_link_change(struct qlcnic_adapter *adapter, int linkup)
Sony Chackoc70001a2012-11-28 04:34:26 +0000636{
637 struct net_device *netdev = adapter->netdev;
638
639 if (adapter->ahw->linkup && !linkup) {
640 netdev_info(netdev, "NIC Link is down\n");
641 adapter->ahw->linkup = 0;
642 if (netif_running(netdev)) {
643 netif_carrier_off(netdev);
644 netif_stop_queue(netdev);
645 }
646 } else if (!adapter->ahw->linkup && linkup) {
647 netdev_info(netdev, "NIC Link is up\n");
648 adapter->ahw->linkup = 1;
649 if (netif_running(netdev)) {
650 netif_carrier_on(netdev);
651 netif_wake_queue(netdev);
652 }
653 }
654}
655
Sony Chackod17dd0d2012-11-28 04:34:27 +0000656static int qlcnic_alloc_rx_skb(struct qlcnic_adapter *adapter,
657 struct qlcnic_host_rds_ring *rds_ring,
658 struct qlcnic_rx_buffer *buffer)
Sony Chackoc70001a2012-11-28 04:34:26 +0000659{
660 struct sk_buff *skb;
661 dma_addr_t dma;
662 struct pci_dev *pdev = adapter->pdev;
663
664 skb = netdev_alloc_skb(adapter->netdev, rds_ring->skb_size);
665 if (!skb) {
666 adapter->stats.skb_alloc_failure++;
667 return -ENOMEM;
668 }
669
670 skb_reserve(skb, NET_IP_ALIGN);
Sony Chacko4be41e92013-01-01 03:20:20 +0000671 dma = pci_map_single(pdev, skb->data,
672 rds_ring->dma_size, PCI_DMA_FROMDEVICE);
Sony Chackoc70001a2012-11-28 04:34:26 +0000673
674 if (pci_dma_mapping_error(pdev, dma)) {
675 adapter->stats.rx_dma_map_error++;
676 dev_kfree_skb_any(skb);
677 return -ENOMEM;
678 }
679
680 buffer->skb = skb;
681 buffer->dma = dma;
682
683 return 0;
684}
685
686static void qlcnic_post_rx_buffers_nodb(struct qlcnic_adapter *adapter,
Sony Chacko4be41e92013-01-01 03:20:20 +0000687 struct qlcnic_host_rds_ring *rds_ring,
688 u8 ring_id)
Sony Chackoc70001a2012-11-28 04:34:26 +0000689{
690 struct rcv_desc *pdesc;
691 struct qlcnic_rx_buffer *buffer;
692 int count = 0;
Sony Chacko4be41e92013-01-01 03:20:20 +0000693 uint32_t producer, handle;
Sony Chackoc70001a2012-11-28 04:34:26 +0000694 struct list_head *head;
695
696 if (!spin_trylock(&rds_ring->lock))
697 return;
698
699 producer = rds_ring->producer;
Sony Chackoc70001a2012-11-28 04:34:26 +0000700 head = &rds_ring->free_list;
Sony Chackod17dd0d2012-11-28 04:34:27 +0000701 while (!list_empty(head)) {
Sony Chackoc70001a2012-11-28 04:34:26 +0000702 buffer = list_entry(head->next, struct qlcnic_rx_buffer, list);
703
704 if (!buffer->skb) {
705 if (qlcnic_alloc_rx_skb(adapter, rds_ring, buffer))
706 break;
707 }
Sony Chackoc70001a2012-11-28 04:34:26 +0000708 count++;
709 list_del(&buffer->list);
710
711 /* make a rcv descriptor */
712 pdesc = &rds_ring->desc_head[producer];
Sony Chacko4be41e92013-01-01 03:20:20 +0000713 handle = qlcnic_get_ref_handle(adapter,
714 buffer->ref_handle, ring_id);
715 pdesc->reference_handle = cpu_to_le16(handle);
Sony Chackoc70001a2012-11-28 04:34:26 +0000716 pdesc->buffer_length = cpu_to_le32(rds_ring->dma_size);
717 pdesc->addr_buffer = cpu_to_le64(buffer->dma);
Sony Chackoc70001a2012-11-28 04:34:26 +0000718 producer = get_next_index(producer, rds_ring->num_desc);
719 }
Sony Chackoc70001a2012-11-28 04:34:26 +0000720 if (count) {
721 rds_ring->producer = producer;
722 writel((producer - 1) & (rds_ring->num_desc - 1),
Sony Chackod17dd0d2012-11-28 04:34:27 +0000723 rds_ring->crb_rcv_producer);
Sony Chackoc70001a2012-11-28 04:34:26 +0000724 }
725 spin_unlock(&rds_ring->lock);
726}
727
Sony Chacko4be41e92013-01-01 03:20:20 +0000728static int qlcnic_process_cmd_ring(struct qlcnic_adapter *adapter,
729 struct qlcnic_host_tx_ring *tx_ring,
730 int budget)
Sony Chackoc70001a2012-11-28 04:34:26 +0000731{
732 u32 sw_consumer, hw_consumer;
Sony Chackod17dd0d2012-11-28 04:34:27 +0000733 int i, done, count = 0;
Sony Chackoc70001a2012-11-28 04:34:26 +0000734 struct qlcnic_cmd_buffer *buffer;
735 struct pci_dev *pdev = adapter->pdev;
736 struct net_device *netdev = adapter->netdev;
737 struct qlcnic_skb_frag *frag;
Sony Chackoc70001a2012-11-28 04:34:26 +0000738
739 if (!spin_trylock(&adapter->tx_clean_lock))
740 return 1;
741
742 sw_consumer = tx_ring->sw_consumer;
743 hw_consumer = le32_to_cpu(*(tx_ring->hw_consumer));
744
745 while (sw_consumer != hw_consumer) {
746 buffer = &tx_ring->cmd_buf_arr[sw_consumer];
747 if (buffer->skb) {
748 frag = &buffer->frag_array[0];
749 pci_unmap_single(pdev, frag->dma, frag->length,
750 PCI_DMA_TODEVICE);
751 frag->dma = 0ULL;
752 for (i = 1; i < buffer->frag_count; i++) {
753 frag++;
754 pci_unmap_page(pdev, frag->dma, frag->length,
755 PCI_DMA_TODEVICE);
756 frag->dma = 0ULL;
757 }
Sony Chackoc70001a2012-11-28 04:34:26 +0000758 adapter->stats.xmitfinished++;
759 dev_kfree_skb_any(buffer->skb);
760 buffer->skb = NULL;
761 }
762
763 sw_consumer = get_next_index(sw_consumer, tx_ring->num_desc);
Sony Chacko4be41e92013-01-01 03:20:20 +0000764 if (++count >= budget)
Sony Chackoc70001a2012-11-28 04:34:26 +0000765 break;
766 }
767
768 if (count && netif_running(netdev)) {
769 tx_ring->sw_consumer = sw_consumer;
Sony Chackoc70001a2012-11-28 04:34:26 +0000770 smp_mb();
Sony Chackoc70001a2012-11-28 04:34:26 +0000771 if (netif_queue_stopped(netdev) && netif_carrier_ok(netdev)) {
772 if (qlcnic_tx_avail(tx_ring) > TX_STOP_THRESH) {
773 netif_wake_queue(netdev);
774 adapter->stats.xmit_on++;
775 }
776 }
777 adapter->tx_timeo_cnt = 0;
778 }
779 /*
780 * If everything is freed up to consumer then check if the ring is full
781 * If the ring is full then check if more needs to be freed and
782 * schedule the call back again.
783 *
784 * This happens when there are 2 CPUs. One could be freeing and the
785 * other filling it. If the ring is full when we get out of here and
786 * the card has already interrupted the host then the host can miss the
787 * interrupt.
788 *
789 * There is still a possible race condition and the host could miss an
790 * interrupt. The card has to take care of this.
791 */
792 hw_consumer = le32_to_cpu(*(tx_ring->hw_consumer));
793 done = (sw_consumer == hw_consumer);
794 spin_unlock(&adapter->tx_clean_lock);
795
796 return done;
797}
798
799static int qlcnic_poll(struct napi_struct *napi, int budget)
800{
Sony Chacko4be41e92013-01-01 03:20:20 +0000801 int tx_complete, work_done;
Sony Chackod17dd0d2012-11-28 04:34:27 +0000802 struct qlcnic_host_sds_ring *sds_ring;
803 struct qlcnic_adapter *adapter;
Sony Chackoc70001a2012-11-28 04:34:26 +0000804
Sony Chackod17dd0d2012-11-28 04:34:27 +0000805 sds_ring = container_of(napi, struct qlcnic_host_sds_ring, napi);
806 adapter = sds_ring->adapter;
Sony Chacko4be41e92013-01-01 03:20:20 +0000807 tx_complete = qlcnic_process_cmd_ring(adapter, adapter->tx_ring,
808 budget);
Sony Chackoc70001a2012-11-28 04:34:26 +0000809 work_done = qlcnic_process_rcv_ring(sds_ring, budget);
Sony Chackoc70001a2012-11-28 04:34:26 +0000810 if ((work_done < budget) && tx_complete) {
811 napi_complete(&sds_ring->napi);
812 if (test_bit(__QLCNIC_DEV_UP, &adapter->state))
813 qlcnic_enable_int(sds_ring);
814 }
815
816 return work_done;
817}
818
819static int qlcnic_rx_poll(struct napi_struct *napi, int budget)
820{
Sony Chackod17dd0d2012-11-28 04:34:27 +0000821 struct qlcnic_host_sds_ring *sds_ring;
822 struct qlcnic_adapter *adapter;
Sony Chackoc70001a2012-11-28 04:34:26 +0000823 int work_done;
824
Sony Chackod17dd0d2012-11-28 04:34:27 +0000825 sds_ring = container_of(napi, struct qlcnic_host_sds_ring, napi);
826 adapter = sds_ring->adapter;
827
Sony Chackoc70001a2012-11-28 04:34:26 +0000828 work_done = qlcnic_process_rcv_ring(sds_ring, budget);
829
830 if (work_done < budget) {
831 napi_complete(&sds_ring->napi);
832 if (test_bit(__QLCNIC_DEV_UP, &adapter->state))
833 qlcnic_enable_int(sds_ring);
834 }
835
836 return work_done;
837}
838
Sony Chackod17dd0d2012-11-28 04:34:27 +0000839static void qlcnic_handle_linkevent(struct qlcnic_adapter *adapter,
840 struct qlcnic_fw_msg *msg)
Sony Chackoc70001a2012-11-28 04:34:26 +0000841{
842 u32 cable_OUI;
Sony Chackod17dd0d2012-11-28 04:34:27 +0000843 u16 cable_len, link_speed;
844 u8 link_status, module, duplex, autoneg, lb_status = 0;
Sony Chackoc70001a2012-11-28 04:34:26 +0000845 struct net_device *netdev = adapter->netdev;
846
Sony Chacko79788452012-12-04 03:33:53 +0000847 adapter->ahw->has_link_events = 1;
Sony Chackoc70001a2012-11-28 04:34:26 +0000848
849 cable_OUI = msg->body[1] & 0xffffffff;
850 cable_len = (msg->body[1] >> 32) & 0xffff;
851 link_speed = (msg->body[1] >> 48) & 0xffff;
852
853 link_status = msg->body[2] & 0xff;
854 duplex = (msg->body[2] >> 16) & 0xff;
855 autoneg = (msg->body[2] >> 24) & 0xff;
856 lb_status = (msg->body[2] >> 32) & 0x3;
857
858 module = (msg->body[2] >> 8) & 0xff;
859 if (module == LINKEVENT_MODULE_TWINAX_UNSUPPORTED_CABLE)
Sony Chackod17dd0d2012-11-28 04:34:27 +0000860 dev_info(&netdev->dev,
861 "unsupported cable: OUI 0x%x, length %d\n",
862 cable_OUI, cable_len);
Sony Chackoc70001a2012-11-28 04:34:26 +0000863 else if (module == LINKEVENT_MODULE_TWINAX_UNSUPPORTED_CABLELEN)
864 dev_info(&netdev->dev, "unsupported cable length %d\n",
Sony Chackod17dd0d2012-11-28 04:34:27 +0000865 cable_len);
Sony Chackoc70001a2012-11-28 04:34:26 +0000866
867 if (!link_status && (lb_status == QLCNIC_ILB_MODE ||
868 lb_status == QLCNIC_ELB_MODE))
869 adapter->ahw->loopback_state |= QLCNIC_LINKEVENT;
870
871 qlcnic_advert_link_change(adapter, link_status);
872
873 if (duplex == LINKEVENT_FULL_DUPLEX)
Sony Chacko79788452012-12-04 03:33:53 +0000874 adapter->ahw->link_duplex = DUPLEX_FULL;
Sony Chackoc70001a2012-11-28 04:34:26 +0000875 else
Sony Chacko79788452012-12-04 03:33:53 +0000876 adapter->ahw->link_duplex = DUPLEX_HALF;
Sony Chackoc70001a2012-11-28 04:34:26 +0000877
Sony Chacko79788452012-12-04 03:33:53 +0000878 adapter->ahw->module_type = module;
879 adapter->ahw->link_autoneg = autoneg;
Sony Chackoc70001a2012-11-28 04:34:26 +0000880
881 if (link_status) {
Sony Chacko79788452012-12-04 03:33:53 +0000882 adapter->ahw->link_speed = link_speed;
Sony Chackoc70001a2012-11-28 04:34:26 +0000883 } else {
Sony Chacko79788452012-12-04 03:33:53 +0000884 adapter->ahw->link_speed = SPEED_UNKNOWN;
885 adapter->ahw->link_duplex = DUPLEX_UNKNOWN;
Sony Chackoc70001a2012-11-28 04:34:26 +0000886 }
887}
888
Sony Chackod17dd0d2012-11-28 04:34:27 +0000889static void qlcnic_handle_fw_message(int desc_cnt, int index,
890 struct qlcnic_host_sds_ring *sds_ring)
Sony Chackoc70001a2012-11-28 04:34:26 +0000891{
892 struct qlcnic_fw_msg msg;
893 struct status_desc *desc;
894 struct qlcnic_adapter *adapter;
895 struct device *dev;
896 int i = 0, opcode, ret;
897
898 while (desc_cnt > 0 && i < 8) {
899 desc = &sds_ring->desc_head[index];
900 msg.words[i++] = le64_to_cpu(desc->status_desc_data[0]);
901 msg.words[i++] = le64_to_cpu(desc->status_desc_data[1]);
902
903 index = get_next_index(index, sds_ring->num_desc);
904 desc_cnt--;
905 }
906
907 adapter = sds_ring->adapter;
908 dev = &adapter->pdev->dev;
909 opcode = qlcnic_get_nic_msg_opcode(msg.body[0]);
910
911 switch (opcode) {
912 case QLCNIC_C2H_OPCODE_GET_LINKEVENT_RESPONSE:
913 qlcnic_handle_linkevent(adapter, &msg);
914 break;
915 case QLCNIC_C2H_OPCODE_CONFIG_LOOPBACK:
916 ret = (u32)(msg.body[1]);
917 switch (ret) {
918 case 0:
919 adapter->ahw->loopback_state |= QLCNIC_LB_RESPONSE;
920 break;
921 case 1:
922 dev_info(dev, "loopback already in progress\n");
Sony Chacko79788452012-12-04 03:33:53 +0000923 adapter->ahw->diag_cnt = -QLCNIC_TEST_IN_PROGRESS;
Sony Chackoc70001a2012-11-28 04:34:26 +0000924 break;
925 case 2:
926 dev_info(dev, "loopback cable is not connected\n");
Sony Chacko79788452012-12-04 03:33:53 +0000927 adapter->ahw->diag_cnt = -QLCNIC_LB_CABLE_NOT_CONN;
Sony Chackoc70001a2012-11-28 04:34:26 +0000928 break;
929 default:
Sony Chackod17dd0d2012-11-28 04:34:27 +0000930 dev_info(dev,
931 "loopback configure request failed, err %x\n",
932 ret);
Sony Chacko79788452012-12-04 03:33:53 +0000933 adapter->ahw->diag_cnt = -QLCNIC_UNDEFINED_ERROR;
Sony Chackoc70001a2012-11-28 04:34:26 +0000934 break;
935 }
936 break;
937 default:
938 break;
939 }
940}
941
Sony Chacko4be41e92013-01-01 03:20:20 +0000942struct sk_buff *qlcnic_process_rxbuf(struct qlcnic_adapter *adapter,
943 struct qlcnic_host_rds_ring *ring,
944 u16 index, u16 cksum)
Sony Chackoc70001a2012-11-28 04:34:26 +0000945{
946 struct qlcnic_rx_buffer *buffer;
947 struct sk_buff *skb;
948
Sony Chacko4be41e92013-01-01 03:20:20 +0000949 buffer = &ring->rx_buf_arr[index];
Sony Chackoc70001a2012-11-28 04:34:26 +0000950 if (unlikely(buffer->skb == NULL)) {
951 WARN_ON(1);
952 return NULL;
953 }
954
Sony Chacko4be41e92013-01-01 03:20:20 +0000955 pci_unmap_single(adapter->pdev, buffer->dma, ring->dma_size,
Sony Chackod17dd0d2012-11-28 04:34:27 +0000956 PCI_DMA_FROMDEVICE);
Sony Chackoc70001a2012-11-28 04:34:26 +0000957
958 skb = buffer->skb;
Sony Chackoc70001a2012-11-28 04:34:26 +0000959 if (likely((adapter->netdev->features & NETIF_F_RXCSUM) &&
Sony Chackod17dd0d2012-11-28 04:34:27 +0000960 (cksum == STATUS_CKSUM_OK || cksum == STATUS_CKSUM_LOOP))) {
Sony Chackoc70001a2012-11-28 04:34:26 +0000961 adapter->stats.csummed++;
962 skb->ip_summed = CHECKSUM_UNNECESSARY;
963 } else {
964 skb_checksum_none_assert(skb);
965 }
966
Sony Chacko4be41e92013-01-01 03:20:20 +0000967
Sony Chackoc70001a2012-11-28 04:34:26 +0000968 buffer->skb = NULL;
969
970 return skb;
971}
972
Sony Chackod17dd0d2012-11-28 04:34:27 +0000973static inline int qlcnic_check_rx_tagging(struct qlcnic_adapter *adapter,
974 struct sk_buff *skb, u16 *vlan_tag)
Sony Chackoc70001a2012-11-28 04:34:26 +0000975{
976 struct ethhdr *eth_hdr;
977
978 if (!__vlan_get_tag(skb, vlan_tag)) {
Sony Chackod17dd0d2012-11-28 04:34:27 +0000979 eth_hdr = (struct ethhdr *)skb->data;
Sony Chackoc70001a2012-11-28 04:34:26 +0000980 memmove(skb->data + VLAN_HLEN, eth_hdr, ETH_ALEN * 2);
981 skb_pull(skb, VLAN_HLEN);
982 }
983 if (!adapter->pvid)
984 return 0;
985
986 if (*vlan_tag == adapter->pvid) {
987 /* Outer vlan tag. Packet should follow non-vlan path */
988 *vlan_tag = 0xffff;
989 return 0;
990 }
991 if (adapter->flags & QLCNIC_TAGGING_ENABLED)
992 return 0;
993
994 return -EINVAL;
995}
996
997static struct qlcnic_rx_buffer *
998qlcnic_process_rcv(struct qlcnic_adapter *adapter,
Sony Chackod17dd0d2012-11-28 04:34:27 +0000999 struct qlcnic_host_sds_ring *sds_ring, int ring,
1000 u64 sts_data0)
Sony Chackoc70001a2012-11-28 04:34:26 +00001001{
1002 struct net_device *netdev = adapter->netdev;
1003 struct qlcnic_recv_context *recv_ctx = adapter->recv_ctx;
1004 struct qlcnic_rx_buffer *buffer;
1005 struct sk_buff *skb;
1006 struct qlcnic_host_rds_ring *rds_ring;
Shahed Shaikh53643a72013-02-18 13:22:37 +00001007 int index, length, cksum, pkt_offset, is_lb_pkt;
1008 u16 vid = 0xffff, t_vid;
Sony Chackoc70001a2012-11-28 04:34:26 +00001009
1010 if (unlikely(ring >= adapter->max_rds_rings))
1011 return NULL;
1012
1013 rds_ring = &recv_ctx->rds_rings[ring];
1014
1015 index = qlcnic_get_sts_refhandle(sts_data0);
1016 if (unlikely(index >= rds_ring->num_desc))
1017 return NULL;
1018
1019 buffer = &rds_ring->rx_buf_arr[index];
Sony Chackoc70001a2012-11-28 04:34:26 +00001020 length = qlcnic_get_sts_totallength(sts_data0);
1021 cksum = qlcnic_get_sts_status(sts_data0);
1022 pkt_offset = qlcnic_get_sts_pkt_offset(sts_data0);
1023
1024 skb = qlcnic_process_rxbuf(adapter, rds_ring, index, cksum);
1025 if (!skb)
1026 return buffer;
1027
Shahed Shaikh53643a72013-02-18 13:22:37 +00001028 if (adapter->drv_mac_learn &&
1029 (adapter->flags & QLCNIC_ESWITCH_ENABLED)) {
1030 t_vid = 0;
1031 is_lb_pkt = qlcnic_82xx_is_lb_pkt(sts_data0);
Rajesh Borundiaf80bc8f2013-04-19 07:01:08 +00001032 qlcnic_add_lb_filter(adapter, skb, is_lb_pkt, t_vid);
Shahed Shaikh53643a72013-02-18 13:22:37 +00001033 }
1034
Sony Chackoc70001a2012-11-28 04:34:26 +00001035 if (length > rds_ring->skb_size)
1036 skb_put(skb, rds_ring->skb_size);
1037 else
1038 skb_put(skb, length);
1039
1040 if (pkt_offset)
1041 skb_pull(skb, pkt_offset);
1042
1043 if (unlikely(qlcnic_check_rx_tagging(adapter, skb, &vid))) {
1044 adapter->stats.rxdropped++;
1045 dev_kfree_skb(skb);
1046 return buffer;
1047 }
1048
1049 skb->protocol = eth_type_trans(skb, netdev);
1050
1051 if (vid != 0xffff)
Patrick McHardy86a9bad2013-04-19 02:04:30 +00001052 __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q), vid);
Sony Chackoc70001a2012-11-28 04:34:26 +00001053
1054 napi_gro_receive(&sds_ring->napi, skb);
1055
1056 adapter->stats.rx_pkts++;
1057 adapter->stats.rxbytes += length;
1058
1059 return buffer;
1060}
1061
1062#define QLC_TCP_HDR_SIZE 20
1063#define QLC_TCP_TS_OPTION_SIZE 12
1064#define QLC_TCP_TS_HDR_SIZE (QLC_TCP_HDR_SIZE + QLC_TCP_TS_OPTION_SIZE)
1065
1066static struct qlcnic_rx_buffer *
1067qlcnic_process_lro(struct qlcnic_adapter *adapter,
Sony Chackod17dd0d2012-11-28 04:34:27 +00001068 int ring, u64 sts_data0, u64 sts_data1)
Sony Chackoc70001a2012-11-28 04:34:26 +00001069{
1070 struct net_device *netdev = adapter->netdev;
1071 struct qlcnic_recv_context *recv_ctx = adapter->recv_ctx;
1072 struct qlcnic_rx_buffer *buffer;
1073 struct sk_buff *skb;
1074 struct qlcnic_host_rds_ring *rds_ring;
1075 struct iphdr *iph;
Shahed Shaikh776e7bd2013-01-25 10:20:35 +00001076 struct ipv6hdr *ipv6h;
Sony Chackoc70001a2012-11-28 04:34:26 +00001077 struct tcphdr *th;
1078 bool push, timestamp;
Shahed Shaikh53643a72013-02-18 13:22:37 +00001079 int index, l2_hdr_offset, l4_hdr_offset, is_lb_pkt;
1080 u16 lro_length, length, data_offset, t_vid, vid = 0xffff;
Sony Chackoc70001a2012-11-28 04:34:26 +00001081 u32 seq_number;
Sony Chackoc70001a2012-11-28 04:34:26 +00001082
1083 if (unlikely(ring > adapter->max_rds_rings))
1084 return NULL;
1085
1086 rds_ring = &recv_ctx->rds_rings[ring];
1087
1088 index = qlcnic_get_lro_sts_refhandle(sts_data0);
1089 if (unlikely(index > rds_ring->num_desc))
1090 return NULL;
1091
1092 buffer = &rds_ring->rx_buf_arr[index];
1093
1094 timestamp = qlcnic_get_lro_sts_timestamp(sts_data0);
1095 lro_length = qlcnic_get_lro_sts_length(sts_data0);
1096 l2_hdr_offset = qlcnic_get_lro_sts_l2_hdr_offset(sts_data0);
1097 l4_hdr_offset = qlcnic_get_lro_sts_l4_hdr_offset(sts_data0);
1098 push = qlcnic_get_lro_sts_push_flag(sts_data0);
1099 seq_number = qlcnic_get_lro_sts_seq_number(sts_data1);
1100
1101 skb = qlcnic_process_rxbuf(adapter, rds_ring, index, STATUS_CKSUM_OK);
1102 if (!skb)
1103 return buffer;
1104
Shahed Shaikh53643a72013-02-18 13:22:37 +00001105 if (adapter->drv_mac_learn &&
1106 (adapter->flags & QLCNIC_ESWITCH_ENABLED)) {
1107 t_vid = 0;
1108 is_lb_pkt = qlcnic_82xx_is_lb_pkt(sts_data0);
Rajesh Borundiaf80bc8f2013-04-19 07:01:08 +00001109 qlcnic_add_lb_filter(adapter, skb, is_lb_pkt, t_vid);
Shahed Shaikh53643a72013-02-18 13:22:37 +00001110 }
1111
Sony Chackoc70001a2012-11-28 04:34:26 +00001112 if (timestamp)
1113 data_offset = l4_hdr_offset + QLC_TCP_TS_HDR_SIZE;
1114 else
1115 data_offset = l4_hdr_offset + QLC_TCP_HDR_SIZE;
1116
1117 skb_put(skb, lro_length + data_offset);
Sony Chackoc70001a2012-11-28 04:34:26 +00001118 skb_pull(skb, l2_hdr_offset);
1119
1120 if (unlikely(qlcnic_check_rx_tagging(adapter, skb, &vid))) {
1121 adapter->stats.rxdropped++;
1122 dev_kfree_skb(skb);
1123 return buffer;
1124 }
1125
1126 skb->protocol = eth_type_trans(skb, netdev);
Shahed Shaikh776e7bd2013-01-25 10:20:35 +00001127
Shahed Shaikh069048f2013-01-30 12:47:12 +00001128 if (ntohs(skb->protocol) == ETH_P_IPV6) {
Shahed Shaikh776e7bd2013-01-25 10:20:35 +00001129 ipv6h = (struct ipv6hdr *)skb->data;
1130 th = (struct tcphdr *)(skb->data + sizeof(struct ipv6hdr));
1131 length = (th->doff << 2) + lro_length;
1132 ipv6h->payload_len = htons(length);
1133 } else {
1134 iph = (struct iphdr *)skb->data;
1135 th = (struct tcphdr *)(skb->data + (iph->ihl << 2));
1136 length = (iph->ihl << 2) + (th->doff << 2) + lro_length;
Li RongQing1bcac3b2013-03-14 22:50:07 +00001137 csum_replace2(&iph->check, iph->tot_len, htons(length));
Shahed Shaikh776e7bd2013-01-25 10:20:35 +00001138 iph->tot_len = htons(length);
Shahed Shaikh776e7bd2013-01-25 10:20:35 +00001139 }
1140
Sony Chackoc70001a2012-11-28 04:34:26 +00001141 th->psh = push;
1142 th->seq = htonl(seq_number);
Sony Chackoc70001a2012-11-28 04:34:26 +00001143 length = skb->len;
1144
Michael S. Tsirkinbd69ba72013-02-07 03:13:13 +00001145 if (adapter->flags & QLCNIC_FW_LRO_MSS_CAP) {
Sony Chackoc70001a2012-11-28 04:34:26 +00001146 skb_shinfo(skb)->gso_size = qlcnic_get_lro_sts_mss(sts_data1);
Michael S. Tsirkinbd69ba72013-02-07 03:13:13 +00001147 if (skb->protocol == htons(ETH_P_IPV6))
1148 skb_shinfo(skb)->gso_type = SKB_GSO_TCPV6;
1149 else
1150 skb_shinfo(skb)->gso_type = SKB_GSO_TCPV4;
1151 }
Sony Chackoc70001a2012-11-28 04:34:26 +00001152
1153 if (vid != 0xffff)
Patrick McHardy86a9bad2013-04-19 02:04:30 +00001154 __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q), vid);
Sony Chackoc70001a2012-11-28 04:34:26 +00001155 netif_receive_skb(skb);
1156
1157 adapter->stats.lro_pkts++;
1158 adapter->stats.lrobytes += length;
1159
1160 return buffer;
1161}
1162
Sony Chackod17dd0d2012-11-28 04:34:27 +00001163int qlcnic_process_rcv_ring(struct qlcnic_host_sds_ring *sds_ring, int max)
Sony Chackoc70001a2012-11-28 04:34:26 +00001164{
Sony Chackod17dd0d2012-11-28 04:34:27 +00001165 struct qlcnic_host_rds_ring *rds_ring;
Sony Chackoc70001a2012-11-28 04:34:26 +00001166 struct qlcnic_adapter *adapter = sds_ring->adapter;
1167 struct list_head *cur;
1168 struct status_desc *desc;
1169 struct qlcnic_rx_buffer *rxbuf;
Sony Chacko4be41e92013-01-01 03:20:20 +00001170 int opcode, desc_cnt, count = 0;
Sony Chackoc70001a2012-11-28 04:34:26 +00001171 u64 sts_data0, sts_data1;
Sony Chacko4be41e92013-01-01 03:20:20 +00001172 u8 ring;
Sony Chackoc70001a2012-11-28 04:34:26 +00001173 u32 consumer = sds_ring->consumer;
1174
1175 while (count < max) {
1176 desc = &sds_ring->desc_head[consumer];
1177 sts_data0 = le64_to_cpu(desc->status_desc_data[0]);
1178
1179 if (!(sts_data0 & STATUS_OWNER_HOST))
1180 break;
1181
1182 desc_cnt = qlcnic_get_sts_desc_cnt(sts_data0);
1183 opcode = qlcnic_get_sts_opcode(sts_data0);
Sony Chackoc70001a2012-11-28 04:34:26 +00001184 switch (opcode) {
1185 case QLCNIC_RXPKT_DESC:
1186 case QLCNIC_OLD_RXPKT_DESC:
1187 case QLCNIC_SYN_OFFLOAD:
1188 ring = qlcnic_get_sts_type(sts_data0);
Sony Chackod17dd0d2012-11-28 04:34:27 +00001189 rxbuf = qlcnic_process_rcv(adapter, sds_ring, ring,
1190 sts_data0);
Sony Chackoc70001a2012-11-28 04:34:26 +00001191 break;
1192 case QLCNIC_LRO_DESC:
1193 ring = qlcnic_get_lro_sts_type(sts_data0);
1194 sts_data1 = le64_to_cpu(desc->status_desc_data[1]);
1195 rxbuf = qlcnic_process_lro(adapter, ring, sts_data0,
1196 sts_data1);
1197 break;
1198 case QLCNIC_RESPONSE_DESC:
1199 qlcnic_handle_fw_message(desc_cnt, consumer, sds_ring);
1200 default:
1201 goto skip;
1202 }
Sony Chackoc70001a2012-11-28 04:34:26 +00001203 WARN_ON(desc_cnt > 1);
1204
1205 if (likely(rxbuf))
1206 list_add_tail(&rxbuf->list, &sds_ring->free_list[ring]);
1207 else
1208 adapter->stats.null_rxbuf++;
Sony Chackoc70001a2012-11-28 04:34:26 +00001209skip:
1210 for (; desc_cnt > 0; desc_cnt--) {
1211 desc = &sds_ring->desc_head[consumer];
Sony Chacko4be41e92013-01-01 03:20:20 +00001212 desc->status_desc_data[0] = QLCNIC_DESC_OWNER_FW;
Sony Chackoc70001a2012-11-28 04:34:26 +00001213 consumer = get_next_index(consumer, sds_ring->num_desc);
1214 }
1215 count++;
1216 }
1217
1218 for (ring = 0; ring < adapter->max_rds_rings; ring++) {
Sony Chackod17dd0d2012-11-28 04:34:27 +00001219 rds_ring = &adapter->recv_ctx->rds_rings[ring];
Sony Chackoc70001a2012-11-28 04:34:26 +00001220 if (!list_empty(&sds_ring->free_list[ring])) {
1221 list_for_each(cur, &sds_ring->free_list[ring]) {
Sony Chackod17dd0d2012-11-28 04:34:27 +00001222 rxbuf = list_entry(cur, struct qlcnic_rx_buffer,
1223 list);
Sony Chackoc70001a2012-11-28 04:34:26 +00001224 qlcnic_alloc_rx_skb(adapter, rds_ring, rxbuf);
1225 }
1226 spin_lock(&rds_ring->lock);
1227 list_splice_tail_init(&sds_ring->free_list[ring],
Sony Chackod17dd0d2012-11-28 04:34:27 +00001228 &rds_ring->free_list);
Sony Chackoc70001a2012-11-28 04:34:26 +00001229 spin_unlock(&rds_ring->lock);
1230 }
1231
Sony Chacko4be41e92013-01-01 03:20:20 +00001232 qlcnic_post_rx_buffers_nodb(adapter, rds_ring, ring);
Sony Chackoc70001a2012-11-28 04:34:26 +00001233 }
1234
1235 if (count) {
1236 sds_ring->consumer = consumer;
1237 writel(consumer, sds_ring->crb_sts_consumer);
1238 }
1239
1240 return count;
1241}
1242
Sony Chackod17dd0d2012-11-28 04:34:27 +00001243void qlcnic_post_rx_buffers(struct qlcnic_adapter *adapter,
Sony Chacko4be41e92013-01-01 03:20:20 +00001244 struct qlcnic_host_rds_ring *rds_ring, u8 ring_id)
Sony Chackoc70001a2012-11-28 04:34:26 +00001245{
1246 struct rcv_desc *pdesc;
1247 struct qlcnic_rx_buffer *buffer;
1248 int count = 0;
Sony Chacko4be41e92013-01-01 03:20:20 +00001249 u32 producer, handle;
Sony Chackoc70001a2012-11-28 04:34:26 +00001250 struct list_head *head;
1251
1252 producer = rds_ring->producer;
Sony Chackoc70001a2012-11-28 04:34:26 +00001253 head = &rds_ring->free_list;
Sony Chackod17dd0d2012-11-28 04:34:27 +00001254
Sony Chackoc70001a2012-11-28 04:34:26 +00001255 while (!list_empty(head)) {
1256
1257 buffer = list_entry(head->next, struct qlcnic_rx_buffer, list);
1258
1259 if (!buffer->skb) {
1260 if (qlcnic_alloc_rx_skb(adapter, rds_ring, buffer))
1261 break;
1262 }
1263
1264 count++;
1265 list_del(&buffer->list);
1266
1267 /* make a rcv descriptor */
1268 pdesc = &rds_ring->desc_head[producer];
1269 pdesc->addr_buffer = cpu_to_le64(buffer->dma);
Sony Chacko4be41e92013-01-01 03:20:20 +00001270 handle = qlcnic_get_ref_handle(adapter, buffer->ref_handle,
1271 ring_id);
1272 pdesc->reference_handle = cpu_to_le16(handle);
Sony Chackoc70001a2012-11-28 04:34:26 +00001273 pdesc->buffer_length = cpu_to_le32(rds_ring->dma_size);
Sony Chackoc70001a2012-11-28 04:34:26 +00001274 producer = get_next_index(producer, rds_ring->num_desc);
1275 }
1276
1277 if (count) {
1278 rds_ring->producer = producer;
1279 writel((producer-1) & (rds_ring->num_desc-1),
Sony Chackod17dd0d2012-11-28 04:34:27 +00001280 rds_ring->crb_rcv_producer);
Sony Chackoc70001a2012-11-28 04:34:26 +00001281 }
1282}
1283
1284static void dump_skb(struct sk_buff *skb, struct qlcnic_adapter *adapter)
1285{
1286 int i;
1287 unsigned char *data = skb->data;
1288
Sony Chackod17dd0d2012-11-28 04:34:27 +00001289 pr_info(KERN_INFO "\n");
Sony Chackoc70001a2012-11-28 04:34:26 +00001290 for (i = 0; i < skb->len; i++) {
1291 QLCDB(adapter, DRV, "%02x ", data[i]);
1292 if ((i & 0x0f) == 8)
Sony Chackod17dd0d2012-11-28 04:34:27 +00001293 pr_info(KERN_INFO "\n");
Sony Chackoc70001a2012-11-28 04:34:26 +00001294 }
1295}
1296
1297static void qlcnic_process_rcv_diag(struct qlcnic_adapter *adapter, int ring,
1298 u64 sts_data0)
1299{
1300 struct qlcnic_recv_context *recv_ctx = adapter->recv_ctx;
1301 struct sk_buff *skb;
1302 struct qlcnic_host_rds_ring *rds_ring;
1303 int index, length, cksum, pkt_offset;
1304
1305 if (unlikely(ring >= adapter->max_rds_rings))
1306 return;
1307
1308 rds_ring = &recv_ctx->rds_rings[ring];
1309
1310 index = qlcnic_get_sts_refhandle(sts_data0);
1311 length = qlcnic_get_sts_totallength(sts_data0);
1312 if (unlikely(index >= rds_ring->num_desc))
1313 return;
1314
1315 cksum = qlcnic_get_sts_status(sts_data0);
1316 pkt_offset = qlcnic_get_sts_pkt_offset(sts_data0);
1317
1318 skb = qlcnic_process_rxbuf(adapter, rds_ring, index, cksum);
1319 if (!skb)
1320 return;
1321
1322 if (length > rds_ring->skb_size)
1323 skb_put(skb, rds_ring->skb_size);
1324 else
1325 skb_put(skb, length);
1326
1327 if (pkt_offset)
1328 skb_pull(skb, pkt_offset);
1329
1330 if (!qlcnic_check_loopback_buff(skb->data, adapter->mac_addr))
Sony Chacko79788452012-12-04 03:33:53 +00001331 adapter->ahw->diag_cnt++;
Sony Chackoc70001a2012-11-28 04:34:26 +00001332 else
1333 dump_skb(skb, adapter);
1334
1335 dev_kfree_skb_any(skb);
1336 adapter->stats.rx_pkts++;
1337 adapter->stats.rxbytes += length;
1338
1339 return;
1340}
1341
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00001342void qlcnic_82xx_process_rcv_ring_diag(struct qlcnic_host_sds_ring *sds_ring)
Sony Chackoc70001a2012-11-28 04:34:26 +00001343{
1344 struct qlcnic_adapter *adapter = sds_ring->adapter;
1345 struct status_desc *desc;
1346 u64 sts_data0;
1347 int ring, opcode, desc_cnt;
1348
1349 u32 consumer = sds_ring->consumer;
1350
1351 desc = &sds_ring->desc_head[consumer];
1352 sts_data0 = le64_to_cpu(desc->status_desc_data[0]);
1353
1354 if (!(sts_data0 & STATUS_OWNER_HOST))
1355 return;
1356
1357 desc_cnt = qlcnic_get_sts_desc_cnt(sts_data0);
1358 opcode = qlcnic_get_sts_opcode(sts_data0);
1359 switch (opcode) {
1360 case QLCNIC_RESPONSE_DESC:
1361 qlcnic_handle_fw_message(desc_cnt, consumer, sds_ring);
1362 break;
1363 default:
1364 ring = qlcnic_get_sts_type(sts_data0);
1365 qlcnic_process_rcv_diag(adapter, ring, sts_data0);
1366 break;
1367 }
1368
1369 for (; desc_cnt > 0; desc_cnt--) {
1370 desc = &sds_ring->desc_head[consumer];
1371 desc->status_desc_data[0] = cpu_to_le64(STATUS_OWNER_PHANTOM);
1372 consumer = get_next_index(consumer, sds_ring->num_desc);
1373 }
1374
1375 sds_ring->consumer = consumer;
1376 writel(consumer, sds_ring->crb_sts_consumer);
1377}
1378
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00001379int qlcnic_82xx_napi_add(struct qlcnic_adapter *adapter,
1380 struct net_device *netdev)
Sony Chackoc70001a2012-11-28 04:34:26 +00001381{
Sony Chackod17dd0d2012-11-28 04:34:27 +00001382 int ring, max_sds_rings;
Sony Chackoc70001a2012-11-28 04:34:26 +00001383 struct qlcnic_host_sds_ring *sds_ring;
1384 struct qlcnic_recv_context *recv_ctx = adapter->recv_ctx;
1385
1386 if (qlcnic_alloc_sds_rings(recv_ctx, adapter->max_sds_rings))
1387 return -ENOMEM;
1388
Sony Chackod17dd0d2012-11-28 04:34:27 +00001389 max_sds_rings = adapter->max_sds_rings;
1390
Sony Chackoc70001a2012-11-28 04:34:26 +00001391 for (ring = 0; ring < adapter->max_sds_rings; ring++) {
1392 sds_ring = &recv_ctx->sds_rings[ring];
Sony Chacko4be41e92013-01-01 03:20:20 +00001393 if (ring == adapter->max_sds_rings - 1)
Sony Chackoc70001a2012-11-28 04:34:26 +00001394 netif_napi_add(netdev, &sds_ring->napi, qlcnic_poll,
Sony Chackod17dd0d2012-11-28 04:34:27 +00001395 QLCNIC_NETDEV_WEIGHT / max_sds_rings);
Sony Chackoc70001a2012-11-28 04:34:26 +00001396 else
Sony Chackod17dd0d2012-11-28 04:34:27 +00001397 netif_napi_add(netdev, &sds_ring->napi, qlcnic_rx_poll,
1398 QLCNIC_NETDEV_WEIGHT*2);
Sony Chackoc70001a2012-11-28 04:34:26 +00001399 }
1400
Sony Chacko4be41e92013-01-01 03:20:20 +00001401 if (qlcnic_alloc_tx_rings(adapter, netdev)) {
1402 qlcnic_free_sds_rings(recv_ctx);
1403 return -ENOMEM;
1404 }
1405
Sony Chackoc70001a2012-11-28 04:34:26 +00001406 return 0;
1407}
1408
Sony Chacko4be41e92013-01-01 03:20:20 +00001409void qlcnic_82xx_napi_del(struct qlcnic_adapter *adapter)
Sony Chackoc70001a2012-11-28 04:34:26 +00001410{
1411 int ring;
1412 struct qlcnic_host_sds_ring *sds_ring;
1413 struct qlcnic_recv_context *recv_ctx = adapter->recv_ctx;
1414
1415 for (ring = 0; ring < adapter->max_sds_rings; ring++) {
1416 sds_ring = &recv_ctx->sds_rings[ring];
1417 netif_napi_del(&sds_ring->napi);
1418 }
1419
1420 qlcnic_free_sds_rings(adapter->recv_ctx);
Sony Chacko4be41e92013-01-01 03:20:20 +00001421 qlcnic_free_tx_rings(adapter);
Sony Chackoc70001a2012-11-28 04:34:26 +00001422}
1423
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00001424void qlcnic_82xx_napi_enable(struct qlcnic_adapter *adapter)
Sony Chackoc70001a2012-11-28 04:34:26 +00001425{
1426 int ring;
1427 struct qlcnic_host_sds_ring *sds_ring;
1428 struct qlcnic_recv_context *recv_ctx = adapter->recv_ctx;
1429
1430 if (adapter->is_up != QLCNIC_ADAPTER_UP_MAGIC)
1431 return;
1432
1433 for (ring = 0; ring < adapter->max_sds_rings; ring++) {
1434 sds_ring = &recv_ctx->sds_rings[ring];
1435 napi_enable(&sds_ring->napi);
1436 qlcnic_enable_int(sds_ring);
1437 }
1438}
1439
Sony Chacko7e2cf4f2013-01-01 03:20:17 +00001440void qlcnic_82xx_napi_disable(struct qlcnic_adapter *adapter)
Sony Chackoc70001a2012-11-28 04:34:26 +00001441{
1442 int ring;
1443 struct qlcnic_host_sds_ring *sds_ring;
1444 struct qlcnic_recv_context *recv_ctx = adapter->recv_ctx;
1445
1446 if (adapter->is_up != QLCNIC_ADAPTER_UP_MAGIC)
1447 return;
1448
1449 for (ring = 0; ring < adapter->max_sds_rings; ring++) {
1450 sds_ring = &recv_ctx->sds_rings[ring];
1451 qlcnic_disable_int(sds_ring);
1452 napi_synchronize(&sds_ring->napi);
1453 napi_disable(&sds_ring->napi);
1454 }
1455}
Sony Chacko4be41e92013-01-01 03:20:20 +00001456
Shahed Shaikh53643a72013-02-18 13:22:37 +00001457#define QLC_83XX_NORMAL_LB_PKT (1ULL << 36)
1458#define QLC_83XX_LRO_LB_PKT (1ULL << 46)
1459
1460static inline int qlcnic_83xx_is_lb_pkt(u64 sts_data, int lro_pkt)
1461{
1462 if (lro_pkt)
1463 return (sts_data & QLC_83XX_LRO_LB_PKT) ? 1 : 0;
1464 else
1465 return (sts_data & QLC_83XX_NORMAL_LB_PKT) ? 1 : 0;
1466}
1467
Sony Chacko4be41e92013-01-01 03:20:20 +00001468static struct qlcnic_rx_buffer *
1469qlcnic_83xx_process_rcv(struct qlcnic_adapter *adapter,
1470 struct qlcnic_host_sds_ring *sds_ring,
1471 u8 ring, u64 sts_data[])
1472{
1473 struct net_device *netdev = adapter->netdev;
1474 struct qlcnic_recv_context *recv_ctx = adapter->recv_ctx;
1475 struct qlcnic_rx_buffer *buffer;
1476 struct sk_buff *skb;
1477 struct qlcnic_host_rds_ring *rds_ring;
Shahed Shaikh53643a72013-02-18 13:22:37 +00001478 int index, length, cksum, is_lb_pkt;
1479 u16 vid = 0xffff, t_vid;
Sony Chacko4be41e92013-01-01 03:20:20 +00001480
1481 if (unlikely(ring >= adapter->max_rds_rings))
1482 return NULL;
1483
1484 rds_ring = &recv_ctx->rds_rings[ring];
1485
1486 index = qlcnic_83xx_hndl(sts_data[0]);
1487 if (unlikely(index >= rds_ring->num_desc))
1488 return NULL;
1489
1490 buffer = &rds_ring->rx_buf_arr[index];
1491 length = qlcnic_83xx_pktln(sts_data[0]);
1492 cksum = qlcnic_83xx_csum_status(sts_data[1]);
1493 skb = qlcnic_process_rxbuf(adapter, rds_ring, index, cksum);
1494 if (!skb)
1495 return buffer;
1496
Shahed Shaikh53643a72013-02-18 13:22:37 +00001497 if (adapter->drv_mac_learn &&
1498 (adapter->flags & QLCNIC_ESWITCH_ENABLED)) {
1499 t_vid = 0;
1500 is_lb_pkt = qlcnic_83xx_is_lb_pkt(sts_data[1], 0);
Rajesh Borundiaf80bc8f2013-04-19 07:01:08 +00001501 qlcnic_add_lb_filter(adapter, skb, is_lb_pkt, t_vid);
Shahed Shaikh53643a72013-02-18 13:22:37 +00001502 }
1503
Sony Chacko4be41e92013-01-01 03:20:20 +00001504 if (length > rds_ring->skb_size)
1505 skb_put(skb, rds_ring->skb_size);
1506 else
1507 skb_put(skb, length);
1508
1509 if (unlikely(qlcnic_check_rx_tagging(adapter, skb, &vid))) {
1510 adapter->stats.rxdropped++;
1511 dev_kfree_skb(skb);
1512 return buffer;
1513 }
1514
1515 skb->protocol = eth_type_trans(skb, netdev);
1516
1517 if (vid != 0xffff)
Patrick McHardy86a9bad2013-04-19 02:04:30 +00001518 __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q), vid);
Sony Chacko4be41e92013-01-01 03:20:20 +00001519
1520 napi_gro_receive(&sds_ring->napi, skb);
1521
1522 adapter->stats.rx_pkts++;
1523 adapter->stats.rxbytes += length;
1524
1525 return buffer;
1526}
1527
1528static struct qlcnic_rx_buffer *
1529qlcnic_83xx_process_lro(struct qlcnic_adapter *adapter,
1530 u8 ring, u64 sts_data[])
1531{
1532 struct net_device *netdev = adapter->netdev;
1533 struct qlcnic_recv_context *recv_ctx = adapter->recv_ctx;
1534 struct qlcnic_rx_buffer *buffer;
1535 struct sk_buff *skb;
1536 struct qlcnic_host_rds_ring *rds_ring;
1537 struct iphdr *iph;
1538 struct ipv6hdr *ipv6h;
1539 struct tcphdr *th;
1540 bool push;
1541 int l2_hdr_offset, l4_hdr_offset;
Shahed Shaikh53643a72013-02-18 13:22:37 +00001542 int index, is_lb_pkt;
Shahed Shaikh99e85872013-02-18 12:06:16 +00001543 u16 lro_length, length, data_offset, gso_size;
Shahed Shaikh53643a72013-02-18 13:22:37 +00001544 u16 vid = 0xffff, t_vid;
Sony Chacko4be41e92013-01-01 03:20:20 +00001545
1546 if (unlikely(ring > adapter->max_rds_rings))
1547 return NULL;
1548
1549 rds_ring = &recv_ctx->rds_rings[ring];
1550
1551 index = qlcnic_83xx_hndl(sts_data[0]);
1552 if (unlikely(index > rds_ring->num_desc))
1553 return NULL;
1554
1555 buffer = &rds_ring->rx_buf_arr[index];
1556
1557 lro_length = qlcnic_83xx_lro_pktln(sts_data[0]);
1558 l2_hdr_offset = qlcnic_83xx_l2_hdr_off(sts_data[1]);
1559 l4_hdr_offset = qlcnic_83xx_l4_hdr_off(sts_data[1]);
1560 push = qlcnic_83xx_is_psh_bit(sts_data[1]);
1561
1562 skb = qlcnic_process_rxbuf(adapter, rds_ring, index, STATUS_CKSUM_OK);
1563 if (!skb)
1564 return buffer;
Shahed Shaikh53643a72013-02-18 13:22:37 +00001565
1566 if (adapter->drv_mac_learn &&
1567 (adapter->flags & QLCNIC_ESWITCH_ENABLED)) {
1568 t_vid = 0;
1569 is_lb_pkt = qlcnic_83xx_is_lb_pkt(sts_data[1], 1);
Rajesh Borundiaf80bc8f2013-04-19 07:01:08 +00001570 qlcnic_add_lb_filter(adapter, skb, is_lb_pkt, t_vid);
Shahed Shaikh53643a72013-02-18 13:22:37 +00001571 }
Sony Chacko4be41e92013-01-01 03:20:20 +00001572 if (qlcnic_83xx_is_tstamp(sts_data[1]))
1573 data_offset = l4_hdr_offset + QLCNIC_TCP_TS_HDR_SIZE;
1574 else
1575 data_offset = l4_hdr_offset + QLCNIC_TCP_HDR_SIZE;
1576
1577 skb_put(skb, lro_length + data_offset);
1578 skb_pull(skb, l2_hdr_offset);
1579
1580 if (unlikely(qlcnic_check_rx_tagging(adapter, skb, &vid))) {
1581 adapter->stats.rxdropped++;
1582 dev_kfree_skb(skb);
1583 return buffer;
1584 }
1585
1586 skb->protocol = eth_type_trans(skb, netdev);
1587 if (ntohs(skb->protocol) == ETH_P_IPV6) {
1588 ipv6h = (struct ipv6hdr *)skb->data;
1589 th = (struct tcphdr *)(skb->data + sizeof(struct ipv6hdr));
1590
1591 length = (th->doff << 2) + lro_length;
1592 ipv6h->payload_len = htons(length);
1593 } else {
1594 iph = (struct iphdr *)skb->data;
1595 th = (struct tcphdr *)(skb->data + (iph->ihl << 2));
1596 length = (iph->ihl << 2) + (th->doff << 2) + lro_length;
Li RongQing1bcac3b2013-03-14 22:50:07 +00001597 csum_replace2(&iph->check, iph->tot_len, htons(length));
Sony Chacko4be41e92013-01-01 03:20:20 +00001598 iph->tot_len = htons(length);
Sony Chacko4be41e92013-01-01 03:20:20 +00001599 }
1600
1601 th->psh = push;
1602 length = skb->len;
1603
Shahed Shaikh99e85872013-02-18 12:06:16 +00001604 if (adapter->flags & QLCNIC_FW_LRO_MSS_CAP) {
1605 gso_size = qlcnic_83xx_get_lro_sts_mss(sts_data[0]);
1606 skb_shinfo(skb)->gso_size = gso_size;
1607 if (skb->protocol == htons(ETH_P_IPV6))
1608 skb_shinfo(skb)->gso_type = SKB_GSO_TCPV6;
1609 else
1610 skb_shinfo(skb)->gso_type = SKB_GSO_TCPV4;
1611 }
1612
Sony Chacko4be41e92013-01-01 03:20:20 +00001613 if (vid != 0xffff)
Patrick McHardy86a9bad2013-04-19 02:04:30 +00001614 __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q), vid);
Sony Chacko4be41e92013-01-01 03:20:20 +00001615
1616 netif_receive_skb(skb);
1617
1618 adapter->stats.lro_pkts++;
1619 adapter->stats.lrobytes += length;
1620 return buffer;
1621}
1622
1623static int qlcnic_83xx_process_rcv_ring(struct qlcnic_host_sds_ring *sds_ring,
1624 int max)
1625{
1626 struct qlcnic_host_rds_ring *rds_ring;
1627 struct qlcnic_adapter *adapter = sds_ring->adapter;
1628 struct list_head *cur;
1629 struct status_desc *desc;
1630 struct qlcnic_rx_buffer *rxbuf = NULL;
1631 u8 ring;
1632 u64 sts_data[2];
1633 int count = 0, opcode;
1634 u32 consumer = sds_ring->consumer;
1635
1636 while (count < max) {
1637 desc = &sds_ring->desc_head[consumer];
1638 sts_data[1] = le64_to_cpu(desc->status_desc_data[1]);
1639 opcode = qlcnic_83xx_opcode(sts_data[1]);
1640 if (!opcode)
1641 break;
1642 sts_data[0] = le64_to_cpu(desc->status_desc_data[0]);
1643 ring = QLCNIC_FETCH_RING_ID(sts_data[0]);
1644
1645 switch (opcode) {
1646 case QLC_83XX_REG_DESC:
1647 rxbuf = qlcnic_83xx_process_rcv(adapter, sds_ring,
1648 ring, sts_data);
1649 break;
1650 case QLC_83XX_LRO_DESC:
1651 rxbuf = qlcnic_83xx_process_lro(adapter, ring,
1652 sts_data);
1653 break;
1654 default:
1655 dev_info(&adapter->pdev->dev,
1656 "Unkonwn opcode: 0x%x\n", opcode);
1657 goto skip;
1658 }
1659
1660 if (likely(rxbuf))
1661 list_add_tail(&rxbuf->list, &sds_ring->free_list[ring]);
1662 else
1663 adapter->stats.null_rxbuf++;
1664skip:
1665 desc = &sds_ring->desc_head[consumer];
1666 /* Reset the descriptor */
1667 desc->status_desc_data[1] = 0;
1668 consumer = get_next_index(consumer, sds_ring->num_desc);
1669 count++;
1670 }
1671 for (ring = 0; ring < adapter->max_rds_rings; ring++) {
1672 rds_ring = &adapter->recv_ctx->rds_rings[ring];
1673 if (!list_empty(&sds_ring->free_list[ring])) {
1674 list_for_each(cur, &sds_ring->free_list[ring]) {
1675 rxbuf = list_entry(cur, struct qlcnic_rx_buffer,
1676 list);
1677 qlcnic_alloc_rx_skb(adapter, rds_ring, rxbuf);
1678 }
1679 spin_lock(&rds_ring->lock);
1680 list_splice_tail_init(&sds_ring->free_list[ring],
1681 &rds_ring->free_list);
1682 spin_unlock(&rds_ring->lock);
1683 }
1684 qlcnic_post_rx_buffers_nodb(adapter, rds_ring, ring);
1685 }
1686 if (count) {
1687 sds_ring->consumer = consumer;
1688 writel(consumer, sds_ring->crb_sts_consumer);
1689 }
1690 return count;
1691}
1692
Rajesh Borundiada6c8062013-03-29 05:46:35 +00001693static int qlcnic_83xx_msix_sriov_vf_poll(struct napi_struct *napi, int budget)
1694{
1695 int tx_complete;
1696 int work_done;
1697 struct qlcnic_host_sds_ring *sds_ring;
1698 struct qlcnic_adapter *adapter;
1699 struct qlcnic_host_tx_ring *tx_ring;
1700
1701 sds_ring = container_of(napi, struct qlcnic_host_sds_ring, napi);
1702 adapter = sds_ring->adapter;
1703 /* tx ring count = 1 */
1704 tx_ring = adapter->tx_ring;
1705
1706 tx_complete = qlcnic_process_cmd_ring(adapter, tx_ring, budget);
1707 work_done = qlcnic_83xx_process_rcv_ring(sds_ring, budget);
1708 if ((work_done < budget) && tx_complete) {
1709 napi_complete(&sds_ring->napi);
1710 qlcnic_83xx_enable_intr(adapter, sds_ring);
1711 }
1712
1713 return work_done;
1714}
1715
Sony Chacko4be41e92013-01-01 03:20:20 +00001716static int qlcnic_83xx_poll(struct napi_struct *napi, int budget)
1717{
1718 int tx_complete;
1719 int work_done;
1720 struct qlcnic_host_sds_ring *sds_ring;
1721 struct qlcnic_adapter *adapter;
1722 struct qlcnic_host_tx_ring *tx_ring;
1723
1724 sds_ring = container_of(napi, struct qlcnic_host_sds_ring, napi);
1725 adapter = sds_ring->adapter;
1726 /* tx ring count = 1 */
1727 tx_ring = adapter->tx_ring;
1728
Sony Chacko4be41e92013-01-01 03:20:20 +00001729 tx_complete = qlcnic_process_cmd_ring(adapter, tx_ring, budget);
1730 work_done = qlcnic_83xx_process_rcv_ring(sds_ring, budget);
1731 if ((work_done < budget) && tx_complete) {
1732 napi_complete(&sds_ring->napi);
Himanshu Madhaniac166702013-02-18 12:06:15 +00001733 qlcnic_83xx_enable_intr(adapter, sds_ring);
Sony Chacko4be41e92013-01-01 03:20:20 +00001734 }
1735
1736 return work_done;
1737}
1738
1739static int qlcnic_83xx_msix_tx_poll(struct napi_struct *napi, int budget)
1740{
1741 int work_done;
1742 struct qlcnic_host_tx_ring *tx_ring;
1743 struct qlcnic_adapter *adapter;
1744
1745 budget = QLCNIC_TX_POLL_BUDGET;
1746 tx_ring = container_of(napi, struct qlcnic_host_tx_ring, napi);
1747 adapter = tx_ring->adapter;
1748 work_done = qlcnic_process_cmd_ring(adapter, tx_ring, budget);
1749 if (work_done) {
1750 napi_complete(&tx_ring->napi);
1751 if (test_bit(__QLCNIC_DEV_UP , &adapter->state))
1752 qlcnic_83xx_enable_tx_intr(adapter, tx_ring);
1753 }
1754
1755 return work_done;
1756}
1757
1758static int qlcnic_83xx_rx_poll(struct napi_struct *napi, int budget)
1759{
1760 int work_done;
1761 struct qlcnic_host_sds_ring *sds_ring;
1762 struct qlcnic_adapter *adapter;
1763
1764 sds_ring = container_of(napi, struct qlcnic_host_sds_ring, napi);
1765 adapter = sds_ring->adapter;
1766 work_done = qlcnic_83xx_process_rcv_ring(sds_ring, budget);
1767 if (work_done < budget) {
1768 napi_complete(&sds_ring->napi);
1769 if (test_bit(__QLCNIC_DEV_UP, &adapter->state))
1770 qlcnic_83xx_enable_intr(adapter, sds_ring);
1771 }
1772
1773 return work_done;
1774}
1775
1776void qlcnic_83xx_napi_enable(struct qlcnic_adapter *adapter)
1777{
1778 int ring;
1779 struct qlcnic_host_sds_ring *sds_ring;
1780 struct qlcnic_host_tx_ring *tx_ring;
1781 struct qlcnic_recv_context *recv_ctx = adapter->recv_ctx;
1782
1783 if (adapter->is_up != QLCNIC_ADAPTER_UP_MAGIC)
1784 return;
1785
1786 for (ring = 0; ring < adapter->max_sds_rings; ring++) {
1787 sds_ring = &recv_ctx->sds_rings[ring];
1788 napi_enable(&sds_ring->napi);
Himanshu Madhaniac166702013-02-18 12:06:15 +00001789 if (adapter->flags & QLCNIC_MSIX_ENABLED)
1790 qlcnic_83xx_enable_intr(adapter, sds_ring);
Sony Chacko4be41e92013-01-01 03:20:20 +00001791 }
1792
Rajesh Borundiada6c8062013-03-29 05:46:35 +00001793 if ((adapter->flags & QLCNIC_MSIX_ENABLED) &&
1794 !(adapter->flags & QLCNIC_TX_INTR_SHARED)) {
Sony Chacko4be41e92013-01-01 03:20:20 +00001795 for (ring = 0; ring < adapter->max_drv_tx_rings; ring++) {
1796 tx_ring = &adapter->tx_ring[ring];
1797 napi_enable(&tx_ring->napi);
1798 qlcnic_83xx_enable_tx_intr(adapter, tx_ring);
1799 }
1800 }
1801}
1802
1803void qlcnic_83xx_napi_disable(struct qlcnic_adapter *adapter)
1804{
1805 int ring;
1806 struct qlcnic_host_sds_ring *sds_ring;
1807 struct qlcnic_recv_context *recv_ctx = adapter->recv_ctx;
1808 struct qlcnic_host_tx_ring *tx_ring;
1809
1810 if (adapter->is_up != QLCNIC_ADAPTER_UP_MAGIC)
1811 return;
1812
1813 for (ring = 0; ring < adapter->max_sds_rings; ring++) {
1814 sds_ring = &recv_ctx->sds_rings[ring];
Himanshu Madhaniac166702013-02-18 12:06:15 +00001815 if (adapter->flags & QLCNIC_MSIX_ENABLED)
1816 qlcnic_83xx_disable_intr(adapter, sds_ring);
Sony Chacko4be41e92013-01-01 03:20:20 +00001817 napi_synchronize(&sds_ring->napi);
1818 napi_disable(&sds_ring->napi);
1819 }
1820
Rajesh Borundiada6c8062013-03-29 05:46:35 +00001821 if ((adapter->flags & QLCNIC_MSIX_ENABLED) &&
1822 !(adapter->flags & QLCNIC_TX_INTR_SHARED)) {
Sony Chacko4be41e92013-01-01 03:20:20 +00001823 for (ring = 0; ring < adapter->max_drv_tx_rings; ring++) {
1824 tx_ring = &adapter->tx_ring[ring];
1825 qlcnic_83xx_disable_tx_intr(adapter, tx_ring);
1826 napi_synchronize(&tx_ring->napi);
1827 napi_disable(&tx_ring->napi);
1828 }
1829 }
1830}
1831
1832int qlcnic_83xx_napi_add(struct qlcnic_adapter *adapter,
1833 struct net_device *netdev)
1834{
Rajesh Borundiada6c8062013-03-29 05:46:35 +00001835 int ring, max_sds_rings, temp;
Sony Chacko4be41e92013-01-01 03:20:20 +00001836 struct qlcnic_host_sds_ring *sds_ring;
1837 struct qlcnic_host_tx_ring *tx_ring;
1838 struct qlcnic_recv_context *recv_ctx = adapter->recv_ctx;
1839
1840 if (qlcnic_alloc_sds_rings(recv_ctx, adapter->max_sds_rings))
1841 return -ENOMEM;
1842
1843 max_sds_rings = adapter->max_sds_rings;
1844 for (ring = 0; ring < adapter->max_sds_rings; ring++) {
1845 sds_ring = &recv_ctx->sds_rings[ring];
Rajesh Borundiada6c8062013-03-29 05:46:35 +00001846 if (adapter->flags & QLCNIC_MSIX_ENABLED) {
1847 if (!(adapter->flags & QLCNIC_TX_INTR_SHARED)) {
1848 netif_napi_add(netdev, &sds_ring->napi,
1849 qlcnic_83xx_rx_poll,
1850 QLCNIC_NETDEV_WEIGHT * 2);
1851 } else {
1852 temp = QLCNIC_NETDEV_WEIGHT / max_sds_rings;
1853 netif_napi_add(netdev, &sds_ring->napi,
1854 qlcnic_83xx_msix_sriov_vf_poll,
1855 temp);
1856 }
1857
1858 } else {
Sony Chacko4be41e92013-01-01 03:20:20 +00001859 netif_napi_add(netdev, &sds_ring->napi,
1860 qlcnic_83xx_poll,
1861 QLCNIC_NETDEV_WEIGHT / max_sds_rings);
Rajesh Borundiada6c8062013-03-29 05:46:35 +00001862 }
Sony Chacko4be41e92013-01-01 03:20:20 +00001863 }
1864
1865 if (qlcnic_alloc_tx_rings(adapter, netdev)) {
1866 qlcnic_free_sds_rings(recv_ctx);
1867 return -ENOMEM;
1868 }
1869
Rajesh Borundiada6c8062013-03-29 05:46:35 +00001870 if ((adapter->flags & QLCNIC_MSIX_ENABLED) &&
1871 !(adapter->flags & QLCNIC_TX_INTR_SHARED)) {
Sony Chacko4be41e92013-01-01 03:20:20 +00001872 for (ring = 0; ring < adapter->max_drv_tx_rings; ring++) {
1873 tx_ring = &adapter->tx_ring[ring];
1874 netif_napi_add(netdev, &tx_ring->napi,
1875 qlcnic_83xx_msix_tx_poll,
1876 QLCNIC_NETDEV_WEIGHT);
1877 }
1878 }
1879
1880 return 0;
1881}
1882
1883void qlcnic_83xx_napi_del(struct qlcnic_adapter *adapter)
1884{
1885 int ring;
1886 struct qlcnic_host_sds_ring *sds_ring;
1887 struct qlcnic_recv_context *recv_ctx = adapter->recv_ctx;
1888 struct qlcnic_host_tx_ring *tx_ring;
1889
1890 for (ring = 0; ring < adapter->max_sds_rings; ring++) {
1891 sds_ring = &recv_ctx->sds_rings[ring];
1892 netif_napi_del(&sds_ring->napi);
1893 }
1894
1895 qlcnic_free_sds_rings(adapter->recv_ctx);
1896
Rajesh Borundiada6c8062013-03-29 05:46:35 +00001897 if ((adapter->flags & QLCNIC_MSIX_ENABLED) &&
1898 !(adapter->flags & QLCNIC_TX_INTR_SHARED)) {
Sony Chacko4be41e92013-01-01 03:20:20 +00001899 for (ring = 0; ring < adapter->max_drv_tx_rings; ring++) {
1900 tx_ring = &adapter->tx_ring[ring];
1901 netif_napi_del(&tx_ring->napi);
1902 }
1903 }
1904
1905 qlcnic_free_tx_rings(adapter);
1906}
1907
1908void qlcnic_83xx_process_rcv_diag(struct qlcnic_adapter *adapter,
1909 int ring, u64 sts_data[])
1910{
1911 struct qlcnic_recv_context *recv_ctx = adapter->recv_ctx;
1912 struct sk_buff *skb;
1913 struct qlcnic_host_rds_ring *rds_ring;
1914 int index, length;
1915
1916 if (unlikely(ring >= adapter->max_rds_rings))
1917 return;
1918
1919 rds_ring = &recv_ctx->rds_rings[ring];
1920 index = qlcnic_83xx_hndl(sts_data[0]);
1921 if (unlikely(index >= rds_ring->num_desc))
1922 return;
1923
1924 length = qlcnic_83xx_pktln(sts_data[0]);
1925
1926 skb = qlcnic_process_rxbuf(adapter, rds_ring, index, STATUS_CKSUM_OK);
1927 if (!skb)
1928 return;
1929
1930 if (length > rds_ring->skb_size)
1931 skb_put(skb, rds_ring->skb_size);
1932 else
1933 skb_put(skb, length);
1934
1935 if (!qlcnic_check_loopback_buff(skb->data, adapter->mac_addr))
1936 adapter->ahw->diag_cnt++;
1937 else
1938 dump_skb(skb, adapter);
1939
1940 dev_kfree_skb_any(skb);
1941 return;
1942}
1943
1944void qlcnic_83xx_process_rcv_ring_diag(struct qlcnic_host_sds_ring *sds_ring)
1945{
1946 struct qlcnic_adapter *adapter = sds_ring->adapter;
1947 struct status_desc *desc;
1948 u64 sts_data[2];
1949 int ring, opcode;
1950 u32 consumer = sds_ring->consumer;
1951
1952 desc = &sds_ring->desc_head[consumer];
1953 sts_data[0] = le64_to_cpu(desc->status_desc_data[0]);
1954 sts_data[1] = le64_to_cpu(desc->status_desc_data[1]);
1955 opcode = qlcnic_83xx_opcode(sts_data[1]);
1956 if (!opcode)
1957 return;
1958
1959 ring = QLCNIC_FETCH_RING_ID(qlcnic_83xx_hndl(sts_data[0]));
1960 qlcnic_83xx_process_rcv_diag(adapter, ring, sts_data);
1961 desc = &sds_ring->desc_head[consumer];
1962 desc->status_desc_data[0] = cpu_to_le64(STATUS_OWNER_PHANTOM);
1963 consumer = get_next_index(consumer, sds_ring->num_desc);
1964 sds_ring->consumer = consumer;
1965 writel(consumer, sds_ring->crb_sts_consumer);
1966}