2 * Copyright (c) 2012 Qualcomm Atheros, Inc.
4 * Permission to use, copy, modify, and/or distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 #include <linux/etherdevice.h>
18 #include <net/ieee80211_radiotap.h>
19 #include <linux/if_arp.h>
20 #include <linux/moduleparam.h>
22 #include <linux/ipv6.h>
30 static bool rtap_include_phy_info;
31 module_param(rtap_include_phy_info, bool, S_IRUGO);
32 MODULE_PARM_DESC(rtap_include_phy_info,
33 " Include PHY info in the radiotap header, default - no");
35 static inline int wil_vring_is_empty(struct vring *vring)
37 return vring->swhead == vring->swtail;
40 static inline u32 wil_vring_next_tail(struct vring *vring)
42 return (vring->swtail + 1) % vring->size;
45 static inline void wil_vring_advance_head(struct vring *vring, int n)
47 vring->swhead = (vring->swhead + n) % vring->size;
50 static inline int wil_vring_is_full(struct vring *vring)
52 return wil_vring_next_tail(vring) == vring->swhead;
55 * Available space in Tx Vring
57 static inline int wil_vring_avail_tx(struct vring *vring)
59 u32 swhead = vring->swhead;
60 u32 swtail = vring->swtail;
61 int used = (vring->size + swhead - swtail) % vring->size;
63 return vring->size - used - 1;
66 static int wil_vring_alloc(struct wil6210_priv *wil, struct vring *vring)
68 struct device *dev = wil_to_dev(wil);
69 size_t sz = vring->size * sizeof(vring->va[0]);
72 BUILD_BUG_ON(sizeof(vring->va[0]) != 32);
76 vring->ctx = kcalloc(vring->size, sizeof(vring->ctx[0]), GFP_KERNEL);
82 * vring->va should be aligned on its size rounded up to power of 2
83 * This is granted by the dma_alloc_coherent
85 vring->va = dma_alloc_coherent(dev, sz, &vring->pa, GFP_KERNEL);
91 /* initially, all descriptors are SW owned
92 * For Tx and Rx, ownership bit is at the same location, thus
95 for (i = 0; i < vring->size; i++) {
96 volatile struct vring_tx_desc *_d = &(vring->va[i].tx);
97 _d->dma.status = TX_DMA_STATUS_DU;
100 wil_dbg_misc(wil, "vring[%d] 0x%p:0x%016llx 0x%p\n", vring->size,
101 vring->va, (unsigned long long)vring->pa, vring->ctx);
106 static void wil_vring_free(struct wil6210_priv *wil, struct vring *vring,
109 struct device *dev = wil_to_dev(wil);
110 size_t sz = vring->size * sizeof(vring->va[0]);
112 while (!wil_vring_is_empty(vring)) {
118 struct vring_tx_desc dd, *d = ⅆ
119 volatile struct vring_tx_desc *_d =
120 &vring->va[vring->swtail].tx;
122 ctx = &vring->ctx[vring->swtail];
124 pa = wil_desc_addr(&d->dma.addr);
125 dmalen = le16_to_cpu(d->dma.length);
126 if (vring->ctx[vring->swtail].mapped_as_page) {
127 dma_unmap_page(dev, pa, dmalen,
130 dma_unmap_single(dev, pa, dmalen,
134 dev_kfree_skb_any(ctx->skb);
135 vring->swtail = wil_vring_next_tail(vring);
137 struct vring_rx_desc dd, *d = ⅆ
138 volatile struct vring_rx_desc *_d =
139 &vring->va[vring->swhead].rx;
141 ctx = &vring->ctx[vring->swhead];
143 pa = wil_desc_addr(&d->dma.addr);
144 dmalen = le16_to_cpu(d->dma.length);
145 dma_unmap_single(dev, pa, dmalen, DMA_FROM_DEVICE);
147 wil_vring_advance_head(vring, 1);
150 dma_free_coherent(dev, sz, (void *)vring->va, vring->pa);
158 * Allocate one skb for Rx VRING
160 * Safe to call from IRQ
162 static int wil_vring_alloc_skb(struct wil6210_priv *wil, struct vring *vring,
165 struct device *dev = wil_to_dev(wil);
166 unsigned int sz = RX_BUF_LEN;
167 struct vring_rx_desc dd, *d = ⅆ
168 volatile struct vring_rx_desc *_d = &(vring->va[i].rx);
172 struct sk_buff *skb = dev_alloc_skb(sz + headroom);
176 skb_reserve(skb, headroom);
179 pa = dma_map_single(dev, skb->data, skb->len, DMA_FROM_DEVICE);
180 if (unlikely(dma_mapping_error(dev, pa))) {
185 d->dma.d0 = BIT(9) | RX_DMA_D0_CMD_DMA_IT;
186 wil_desc_addr_set(&d->dma.addr, pa);
187 /* ip_length don't care */
189 /* error don't care */
190 d->dma.status = 0; /* BIT(0) should be 0 for HW_OWNED */
191 d->dma.length = cpu_to_le16(sz);
193 vring->ctx[i].skb = skb;
199 * Adds radiotap header
201 * Any error indicated as "Bad FCS"
203 * Vendor data for 04:ce:14-1 (Wilocity-1) consists of:
204 * - Rx descriptor: 32 bytes
207 static void wil_rx_add_radiotap_header(struct wil6210_priv *wil,
210 struct wireless_dev *wdev = wil->wdev;
211 struct wil6210_rtap {
212 struct ieee80211_radiotap_header rthdr;
213 /* fields should be in the order of bits in rthdr.it_present */
217 __le16 chnl_freq __aligned(2);
224 struct wil6210_rtap_vendor {
225 struct wil6210_rtap rtap;
227 u8 vendor_oui[3] __aligned(2);
232 struct vring_rx_desc *d = wil_skb_rxdesc(skb);
233 struct wil6210_rtap_vendor *rtap_vendor;
234 int rtap_len = sizeof(struct wil6210_rtap);
235 int phy_length = 0; /* phy info header size, bytes */
236 static char phy_data[128];
237 struct ieee80211_channel *ch = wdev->preset_chandef.chan;
239 if (rtap_include_phy_info) {
240 rtap_len = sizeof(*rtap_vendor) + sizeof(*d);
241 /* calculate additional length */
242 if (d->dma.status & RX_DMA_STATUS_PHY_INFO) {
244 * PHY info starts from 8-byte boundary
245 * there are 8-byte lines, last line may be partially
246 * written (HW bug), thus FW configures for last line
247 * to be excessive. Driver skips this last line.
249 int len = min_t(int, 8 + sizeof(phy_data),
250 wil_rxdesc_phy_length(d));
252 void *p = skb_tail_pointer(skb);
253 void *pa = PTR_ALIGN(p, 8);
254 if (skb_tailroom(skb) >= len + (pa - p)) {
255 phy_length = len - 8;
256 memcpy(phy_data, pa, phy_length);
260 rtap_len += phy_length;
263 if (skb_headroom(skb) < rtap_len &&
264 pskb_expand_head(skb, rtap_len, 0, GFP_ATOMIC)) {
265 wil_err(wil, "Unable to expand headrom to %d\n", rtap_len);
269 rtap_vendor = (void *)skb_push(skb, rtap_len);
270 memset(rtap_vendor, 0, rtap_len);
272 rtap_vendor->rtap.rthdr.it_version = PKTHDR_RADIOTAP_VERSION;
273 rtap_vendor->rtap.rthdr.it_len = cpu_to_le16(rtap_len);
274 rtap_vendor->rtap.rthdr.it_present = cpu_to_le32(
275 (1 << IEEE80211_RADIOTAP_FLAGS) |
276 (1 << IEEE80211_RADIOTAP_CHANNEL) |
277 (1 << IEEE80211_RADIOTAP_MCS));
278 if (d->dma.status & RX_DMA_STATUS_ERROR)
279 rtap_vendor->rtap.flags |= IEEE80211_RADIOTAP_F_BADFCS;
281 rtap_vendor->rtap.chnl_freq = cpu_to_le16(ch ? ch->center_freq : 58320);
282 rtap_vendor->rtap.chnl_flags = cpu_to_le16(0);
284 rtap_vendor->rtap.mcs_present = IEEE80211_RADIOTAP_MCS_HAVE_MCS;
285 rtap_vendor->rtap.mcs_flags = 0;
286 rtap_vendor->rtap.mcs_index = wil_rxdesc_mcs(d);
288 if (rtap_include_phy_info) {
289 rtap_vendor->rtap.rthdr.it_present |= cpu_to_le32(1 <<
290 IEEE80211_RADIOTAP_VENDOR_NAMESPACE);
291 /* OUI for Wilocity 04:ce:14 */
292 rtap_vendor->vendor_oui[0] = 0x04;
293 rtap_vendor->vendor_oui[1] = 0xce;
294 rtap_vendor->vendor_oui[2] = 0x14;
295 rtap_vendor->vendor_ns = 1;
296 /* Rx descriptor + PHY data */
297 rtap_vendor->vendor_skip = cpu_to_le16(sizeof(*d) +
299 memcpy(rtap_vendor->vendor_data, (void *)d, sizeof(*d));
300 memcpy(rtap_vendor->vendor_data + sizeof(*d), phy_data,
306 * Fast swap in place between 2 registers
308 static void wil_swap_u16(u16 *a, u16 *b)
315 static void wil_swap_ethaddr(void *data)
317 struct ethhdr *eth = data;
318 u16 *s = (u16 *)eth->h_source;
319 u16 *d = (u16 *)eth->h_dest;
321 wil_swap_u16(s++, d++);
322 wil_swap_u16(s++, d++);
327 * reap 1 frame from @swhead
329 * Rx descriptor copied to skb->cb
331 * Safe to call from IRQ
333 static struct sk_buff *wil_vring_reap_rx(struct wil6210_priv *wil,
336 struct device *dev = wil_to_dev(wil);
337 struct net_device *ndev = wil_to_ndev(wil);
338 volatile struct vring_rx_desc *_d;
339 struct vring_rx_desc *d;
342 unsigned int sz = RX_BUF_LEN;
347 BUILD_BUG_ON(sizeof(struct vring_rx_desc) > sizeof(skb->cb));
349 if (wil_vring_is_empty(vring))
352 _d = &(vring->va[vring->swhead].rx);
353 if (!(_d->dma.status & RX_DMA_STATUS_DU)) {
354 /* it is not error, we just reached end of Rx done area */
358 skb = vring->ctx[vring->swhead].skb;
359 d = wil_skb_rxdesc(skb);
361 pa = wil_desc_addr(&d->dma.addr);
362 vring->ctx[vring->swhead].skb = NULL;
363 wil_vring_advance_head(vring, 1);
365 dma_unmap_single(dev, pa, sz, DMA_FROM_DEVICE);
366 dmalen = le16_to_cpu(d->dma.length);
368 trace_wil6210_rx(vring->swhead, d);
369 wil_dbg_txrx(wil, "Rx[%3d] : %d bytes\n", vring->swhead, dmalen);
370 wil_hex_dump_txrx("Rx ", DUMP_PREFIX_NONE, 32, 4,
371 (const void *)d, sizeof(*d), false);
374 wil_err(wil, "Rx size too large: %d bytes!\n", dmalen);
378 skb_trim(skb, dmalen);
380 wil_hex_dump_txrx("Rx ", DUMP_PREFIX_OFFSET, 16, 1,
381 skb->data, skb_headlen(skb), false);
384 wil->stats.last_mcs_rx = wil_rxdesc_mcs(d);
386 /* use radiotap header only if required */
387 if (ndev->type == ARPHRD_IEEE80211_RADIOTAP)
388 wil_rx_add_radiotap_header(wil, skb);
390 /* no extra checks if in sniffer mode */
391 if (ndev->type != ARPHRD_ETHER)
394 * Non-data frames may be delivered through Rx DMA channel (ex: BAR)
395 * Driver should recognize it by frame type, that is found
396 * in Rx descriptor. If type is not data, it is 802.11 frame as is
398 ftype = wil_rxdesc_ftype(d) << 2;
399 if (ftype != IEEE80211_FTYPE_DATA) {
400 wil_dbg_txrx(wil, "Non-data frame ftype 0x%08x\n", ftype);
401 /* TODO: process it */
406 if (skb->len < ETH_HLEN) {
407 wil_err(wil, "Short frame, len = %d\n", skb->len);
408 /* TODO: process it (i.e. BAR) */
413 /* L4 IDENT is on when HW calculated checksum, check status
414 * and in case of error drop the packet
415 * higher stack layers will handle retransmission (if required)
417 if (d->dma.status & RX_DMA_STATUS_L4_IDENT) {
418 /* L4 protocol identified, csum calculated */
419 if ((d->dma.error & RX_DMA_ERROR_L4_ERR) == 0)
420 skb->ip_summed = CHECKSUM_UNNECESSARY;
421 /* If HW reports bad checksum, let IP stack re-check it
422 * For example, HW don't understand Microsoft IP stack that
423 * mis-calculates TCP checksum - if it should be 0x0,
424 * it writes 0xffff in violation of RFC 1624
428 ds_bits = wil_rxdesc_ds_bits(d);
431 * HW bug - in ToDS mode, i.e. Rx on AP side,
432 * addresses get swapped
434 wil_swap_ethaddr(skb->data);
441 * allocate and fill up to @count buffers in rx ring
442 * buffers posted at @swtail
444 static int wil_rx_refill(struct wil6210_priv *wil, int count)
446 struct net_device *ndev = wil_to_ndev(wil);
447 struct vring *v = &wil->vring_rx;
450 int headroom = ndev->type == ARPHRD_IEEE80211_RADIOTAP ?
451 WIL6210_RTAP_SIZE : 0;
453 for (; next_tail = wil_vring_next_tail(v),
454 (next_tail != v->swhead) && (count-- > 0);
455 v->swtail = next_tail) {
456 rc = wil_vring_alloc_skb(wil, v, v->swtail, headroom);
458 wil_err(wil, "Error %d in wil_rx_refill[%d]\n",
463 iowrite32(v->swtail, wil->csr + HOSTADDR(v->hwtail));
469 * Pass Rx packet to the netif. Update statistics.
470 * Called in softirq context (NAPI poll).
472 static void wil_netif_rx_any(struct sk_buff *skb, struct net_device *ndev)
475 unsigned int len = skb->len;
479 rc = netif_receive_skb(skb);
481 if (likely(rc == NET_RX_SUCCESS)) {
482 ndev->stats.rx_packets++;
483 ndev->stats.rx_bytes += len;
486 ndev->stats.rx_dropped++;
491 * Proceed all completed skb's from Rx VRING
493 * Safe to call from NAPI poll, i.e. softirq with interrupts enabled
495 void wil_rx_handle(struct wil6210_priv *wil, int *quota)
497 struct net_device *ndev = wil_to_ndev(wil);
498 struct vring *v = &wil->vring_rx;
502 wil_err(wil, "Rx IRQ while Rx not yet initialized\n");
505 wil_dbg_txrx(wil, "%s()\n", __func__);
506 while ((*quota > 0) && (NULL != (skb = wil_vring_reap_rx(wil, v)))) {
509 if (wil->wdev->iftype == NL80211_IFTYPE_MONITOR) {
511 skb_reset_mac_header(skb);
512 skb->ip_summed = CHECKSUM_UNNECESSARY;
513 skb->pkt_type = PACKET_OTHERHOST;
514 skb->protocol = htons(ETH_P_802_2);
517 skb->protocol = eth_type_trans(skb, ndev);
520 wil_netif_rx_any(skb, ndev);
522 wil_rx_refill(wil, v->size);
525 int wil_rx_init(struct wil6210_priv *wil)
527 struct vring *vring = &wil->vring_rx;
530 vring->size = WIL6210_RX_RING_SIZE;
531 rc = wil_vring_alloc(wil, vring);
535 rc = wmi_rx_chain_add(wil, vring);
539 rc = wil_rx_refill(wil, vring->size);
545 wil_vring_free(wil, vring, 0);
550 void wil_rx_fini(struct wil6210_priv *wil)
552 struct vring *vring = &wil->vring_rx;
555 wil_vring_free(wil, vring, 0);
558 int wil_vring_init_tx(struct wil6210_priv *wil, int id, int size,
562 struct wmi_vring_cfg_cmd cmd = {
563 .action = cpu_to_le32(WMI_VRING_CMD_ADD),
566 .max_mpdu_size = cpu_to_le16(TX_BUF_LEN),
567 .ring_size = cpu_to_le16(size),
570 .cidxtid = (cid & 0xf) | ((tid & 0xf) << 4),
571 .encap_trans_type = WMI_VRING_ENC_TYPE_802_3,
576 .priority = cpu_to_le16(0),
577 .timeslot_us = cpu_to_le16(0xfff),
582 struct wil6210_mbox_hdr_wmi wmi;
583 struct wmi_vring_cfg_done_event cmd;
585 struct vring *vring = &wil->vring_tx[id];
588 wil_err(wil, "Tx ring [%d] already allocated\n", id);
594 rc = wil_vring_alloc(wil, vring);
598 cmd.vring_cfg.tx_sw_ring.ring_mem_base = cpu_to_le64(vring->pa);
600 rc = wmi_call(wil, WMI_VRING_CFG_CMDID, &cmd, sizeof(cmd),
601 WMI_VRING_CFG_DONE_EVENTID, &reply, sizeof(reply), 100);
605 if (reply.cmd.status != WMI_FW_STATUS_SUCCESS) {
606 wil_err(wil, "Tx config failed, status 0x%02x\n",
611 vring->hwtail = le32_to_cpu(reply.cmd.tx_vring_tail_ptr);
615 wil_vring_free(wil, vring, 1);
621 void wil_vring_fini_tx(struct wil6210_priv *wil, int id)
623 struct vring *vring = &wil->vring_tx[id];
628 wil_vring_free(wil, vring, 1);
631 static struct vring *wil_find_tx_vring(struct wil6210_priv *wil,
634 struct vring *v = &wil->vring_tx[0];
642 static int wil_tx_desc_map(struct vring_tx_desc *d, dma_addr_t pa, u32 len,
645 wil_desc_addr_set(&d->dma.addr, pa);
646 d->dma.ip_length = 0;
647 /* 0..6: mac_length; 7:ip_version 0-IP6 1-IP4*/
648 d->dma.b11 = 0/*14 | BIT(7)*/;
650 d->dma.status = 0; /* BIT(0) should be 0 for HW_OWNED */
651 d->dma.length = cpu_to_le16((u16)len);
652 d->dma.d0 = (vring_index << DMA_CFG_DESC_TX_0_QID_POS);
656 d->mac.ucode_cmd = 0;
657 /* use dst index 0 */
658 d->mac.d[1] |= BIT(MAC_CFG_DESC_TX_1_DST_INDEX_EN_POS) |
659 (0 << MAC_CFG_DESC_TX_1_DST_INDEX_POS);
660 /* translation type: 0 - bypass; 1 - 802.3; 2 - native wifi */
661 d->mac.d[2] = BIT(MAC_CFG_DESC_TX_2_SNAP_HDR_INSERTION_EN_POS) |
662 (1 << MAC_CFG_DESC_TX_2_L2_TRANSLATION_TYPE_POS);
667 static int wil_tx_desc_offload_cksum_set(struct wil6210_priv *wil,
668 struct vring_tx_desc *d,
673 if (skb->ip_summed != CHECKSUM_PARTIAL)
676 switch (skb->protocol) {
677 case cpu_to_be16(ETH_P_IP):
678 protocol = ip_hdr(skb)->protocol;
680 case cpu_to_be16(ETH_P_IPV6):
681 protocol = ipv6_hdr(skb)->nexthdr;
689 d->dma.d0 |= (2 << DMA_CFG_DESC_TX_0_L4_TYPE_POS);
690 /* L4 header len: TCP header length */
692 (tcp_hdrlen(skb) & DMA_CFG_DESC_TX_0_L4_LENGTH_MSK);
695 /* L4 header len: UDP header length */
697 (sizeof(struct udphdr) & DMA_CFG_DESC_TX_0_L4_LENGTH_MSK);
703 d->dma.ip_length = skb_network_header_len(skb);
704 d->dma.b11 = ETH_HLEN; /* MAC header length */
705 d->dma.b11 |= BIT(DMA_CFG_DESC_TX_OFFLOAD_CFG_L3T_IPV4_POS);
706 /* Enable TCP/UDP checksum */
707 d->dma.d0 |= BIT(DMA_CFG_DESC_TX_0_TCP_UDP_CHECKSUM_EN_POS);
708 /* Calculate pseudo-header */
709 d->dma.d0 |= BIT(DMA_CFG_DESC_TX_0_PSEUDO_HEADER_CALC_EN_POS);
714 static int wil_tx_vring(struct wil6210_priv *wil, struct vring *vring,
717 struct device *dev = wil_to_dev(wil);
718 struct vring_tx_desc dd, *d = ⅆ
719 volatile struct vring_tx_desc *_d;
720 u32 swhead = vring->swhead;
721 int avail = wil_vring_avail_tx(vring);
722 int nr_frags = skb_shinfo(skb)->nr_frags;
724 int vring_index = vring - wil->vring_tx;
728 wil_dbg_txrx(wil, "%s()\n", __func__);
730 if (avail < vring->size/8)
731 netif_tx_stop_all_queues(wil_to_ndev(wil));
732 if (avail < 1 + nr_frags) {
733 wil_err(wil, "Tx ring full. No space for %d fragments\n",
737 _d = &(vring->va[i].tx);
739 /* FIXME FW can accept only unicast frames for the peer */
740 memcpy(skb->data, wil->dst_addr[vring_index], ETH_ALEN);
742 pa = dma_map_single(dev, skb->data,
743 skb_headlen(skb), DMA_TO_DEVICE);
745 wil_dbg_txrx(wil, "Tx skb %d bytes %p -> %#08llx\n", skb_headlen(skb),
746 skb->data, (unsigned long long)pa);
747 wil_hex_dump_txrx("Tx ", DUMP_PREFIX_OFFSET, 16, 1,
748 skb->data, skb_headlen(skb), false);
750 if (unlikely(dma_mapping_error(dev, pa)))
753 wil_tx_desc_map(d, pa, skb_headlen(skb), vring_index);
754 /* Process TCP/UDP checksum offloading */
755 if (wil_tx_desc_offload_cksum_set(wil, d, skb)) {
756 wil_err(wil, "VRING #%d Failed to set cksum, drop packet\n",
761 d->mac.d[2] |= ((nr_frags + 1) <<
762 MAC_CFG_DESC_TX_2_NUM_OF_DESCRIPTORS_POS);
766 /* middle segments */
767 for (; f < nr_frags; f++) {
768 const struct skb_frag_struct *frag =
769 &skb_shinfo(skb)->frags[f];
770 int len = skb_frag_size(frag);
771 i = (swhead + f + 1) % vring->size;
772 _d = &(vring->va[i].tx);
773 pa = skb_frag_dma_map(dev, frag, 0, skb_frag_size(frag),
775 if (unlikely(dma_mapping_error(dev, pa)))
777 wil_tx_desc_map(d, pa, len, vring_index);
778 vring->ctx[i].mapped_as_page = 1;
781 /* for the last seg only */
782 d->dma.d0 |= BIT(DMA_CFG_DESC_TX_0_CMD_EOP_POS);
783 d->dma.d0 |= BIT(DMA_CFG_DESC_TX_0_CMD_MARK_WB_POS);
784 d->dma.d0 |= BIT(DMA_CFG_DESC_TX_0_CMD_DMA_IT_POS);
787 /* hold reference to skb
788 * to prevent skb release before accounting
789 * in case of immediate "tx done"
791 vring->ctx[i].skb = skb_get(skb);
793 wil_hex_dump_txrx("Tx ", DUMP_PREFIX_NONE, 32, 4,
794 (const void *)d, sizeof(*d), false);
797 wil_vring_advance_head(vring, nr_frags + 1);
798 wil_dbg_txrx(wil, "Tx swhead %d -> %d\n", swhead, vring->swhead);
799 trace_wil6210_tx(vring_index, swhead, skb->len, nr_frags);
800 iowrite32(vring->swhead, wil->csr + HOSTADDR(vring->hwtail));
804 /* unmap what we have mapped */
805 nr_frags = f + 1; /* frags mapped + one for skb head */
806 for (f = 0; f < nr_frags; f++) {
810 i = (swhead + f) % vring->size;
811 ctx = &vring->ctx[i];
812 _d = &(vring->va[i].tx);
814 _d->dma.status = TX_DMA_STATUS_DU;
815 pa = wil_desc_addr(&d->dma.addr);
816 dmalen = le16_to_cpu(d->dma.length);
817 if (ctx->mapped_as_page)
818 dma_unmap_page(dev, pa, dmalen, DMA_TO_DEVICE);
820 dma_unmap_single(dev, pa, dmalen, DMA_TO_DEVICE);
823 dev_kfree_skb_any(ctx->skb);
825 memset(ctx, 0, sizeof(*ctx));
832 netdev_tx_t wil_start_xmit(struct sk_buff *skb, struct net_device *ndev)
834 struct wil6210_priv *wil = ndev_to_wil(ndev);
838 wil_dbg_txrx(wil, "%s()\n", __func__);
839 if (!test_bit(wil_status_fwready, &wil->status)) {
840 wil_err(wil, "FW not ready\n");
843 if (!test_bit(wil_status_fwconnected, &wil->status)) {
844 wil_err(wil, "FW not connected\n");
847 if (wil->wdev->iftype == NL80211_IFTYPE_MONITOR) {
848 wil_err(wil, "Xmit in monitor mode not supported\n");
853 vring = wil_find_tx_vring(wil, skb);
855 wil_err(wil, "No Tx VRING available\n");
858 /* set up vring entry */
859 rc = wil_tx_vring(wil, vring, skb);
863 /* statistics will be updated on the tx_complete */
864 dev_kfree_skb_any(skb);
867 return NETDEV_TX_BUSY;
869 break; /* goto drop; */
872 ndev->stats.tx_dropped++;
873 dev_kfree_skb_any(skb);
875 return NET_XMIT_DROP;
879 * Clean up transmitted skb's from the Tx VRING
881 * Return number of descriptors cleared
883 * Safe to call from IRQ
885 int wil_tx_complete(struct wil6210_priv *wil, int ringid)
887 struct net_device *ndev = wil_to_ndev(wil);
888 struct device *dev = wil_to_dev(wil);
889 struct vring *vring = &wil->vring_tx[ringid];
893 wil_err(wil, "Tx irq[%d]: vring not initialized\n", ringid);
897 wil_dbg_txrx(wil, "%s(%d)\n", __func__, ringid);
899 while (!wil_vring_is_empty(vring)) {
900 volatile struct vring_tx_desc *_d =
901 &vring->va[vring->swtail].tx;
902 struct vring_tx_desc dd, *d = ⅆ
905 struct wil_ctx *ctx = &vring->ctx[vring->swtail];
906 struct sk_buff *skb = ctx->skb;
910 if (!(d->dma.status & TX_DMA_STATUS_DU))
913 dmalen = le16_to_cpu(d->dma.length);
914 trace_wil6210_tx_done(ringid, vring->swtail, dmalen,
917 "Tx[%3d] : %d bytes, status 0x%02x err 0x%02x\n",
918 vring->swtail, dmalen, d->dma.status,
920 wil_hex_dump_txrx("TxC ", DUMP_PREFIX_NONE, 32, 4,
921 (const void *)d, sizeof(*d), false);
923 pa = wil_desc_addr(&d->dma.addr);
924 if (ctx->mapped_as_page)
925 dma_unmap_page(dev, pa, dmalen, DMA_TO_DEVICE);
927 dma_unmap_single(dev, pa, dmalen, DMA_TO_DEVICE);
930 if (d->dma.error == 0) {
931 ndev->stats.tx_packets++;
932 ndev->stats.tx_bytes += skb->len;
934 ndev->stats.tx_errors++;
937 dev_kfree_skb_any(skb);
939 memset(ctx, 0, sizeof(*ctx));
941 * There is no need to touch HW descriptor:
942 * - ststus bit TX_DMA_STATUS_DU is set by design,
943 * so hardware will not try to process this desc.,
944 * - rest of descriptor will be initialized on Tx.
946 vring->swtail = wil_vring_next_tail(vring);
949 if (wil_vring_avail_tx(vring) > vring->size/4)
950 netif_tx_wake_all_queues(wil_to_ndev(wil));