xref: /freebsd/sys/dev/rtwn/rtl8192c/pci/r92ce_tx.c (revision 6be3386466ab79a84b48429ae66244f21526d3df)
1 /*	$OpenBSD: if_rtwn.c,v 1.6 2015/08/28 00:03:53 deraadt Exp $	*/
2 
3 /*-
4  * Copyright (c) 2010 Damien Bergamini <damien.bergamini@free.fr>
5  * Copyright (c) 2015 Stefan Sperling <stsp@openbsd.org>
6  * Copyright (c) 2016 Andriy Voskoboinyk <avos@FreeBSD.org>
7  *
8  * Permission to use, copy, modify, and distribute this software for any
9  * purpose with or without fee is hereby granted, provided that the above
10  * copyright notice and this permission notice appear in all copies.
11  *
12  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
13  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
14  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
15  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
16  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
17  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
18  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19  */
20 
21 #include <sys/cdefs.h>
22 __FBSDID("$FreeBSD$");
23 
24 #include "opt_wlan.h"
25 
26 #include <sys/param.h>
27 #include <sys/lock.h>
28 #include <sys/mutex.h>
29 #include <sys/mbuf.h>
30 #include <sys/kernel.h>
31 #include <sys/socket.h>
32 #include <sys/systm.h>
33 #include <sys/malloc.h>
34 #include <sys/queue.h>
35 #include <sys/taskqueue.h>
36 #include <sys/bus.h>
37 #include <sys/endian.h>
38 #include <sys/linker.h>
39 
40 #include <machine/bus.h>
41 #include <machine/resource.h>
42 #include <sys/rman.h>
43 
44 #include <net/if.h>
45 #include <net/ethernet.h>
46 #include <net/if_media.h>
47 
48 #include <net80211/ieee80211_var.h>
49 #include <net80211/ieee80211_radiotap.h>
50 
51 #include <dev/rtwn/if_rtwnvar.h>
52 #include <dev/rtwn/if_rtwn_debug.h>
53 
54 #include <dev/rtwn/pci/rtwn_pci_var.h>
55 
56 #include <dev/rtwn/rtl8192c/pci/r92ce.h>
57 #include <dev/rtwn/rtl8192c/pci/r92ce_tx_desc.h>
58 
59 void
60 r92ce_setup_tx_desc(struct rtwn_pci_softc *pc, void *desc,
61     uint32_t next_desc_addr)
62 {
63 	struct r92ce_tx_desc *txd = desc;
64 
65 	/* setup tx desc */
66 	txd->nextdescaddr = htole32(next_desc_addr);
67 }
68 
69 void
70 r92ce_tx_postsetup(struct rtwn_pci_softc *pc, void *desc,
71     bus_dma_segment_t segs[])
72 {
73 	struct r92ce_tx_desc *txd = desc;
74 
75 	txd->txbufaddr = htole32(segs[0].ds_addr);
76 	txd->txbufsize = txd->pktlen;
77 	bus_space_barrier(pc->pc_st, pc->pc_sh, 0, pc->pc_mapsize,
78 	    BUS_SPACE_BARRIER_WRITE);
79 }
80 
81 void
82 r92ce_copy_tx_desc(void *dest, const void *src)
83 {
84 	struct r92ce_tx_desc *txd = dest;
85 	size_t len = sizeof(struct r92c_tx_desc) +
86 	    sizeof(txd->txbufsize) + sizeof(txd->pad);
87 
88 	if (src != NULL)
89 		memcpy(dest, src, len);
90 	else
91 		memset(dest, 0, len);
92 }
93 
94 void
95 r92ce_dump_tx_desc(struct rtwn_softc *sc, const void *desc)
96 {
97 #ifdef RTWN_DEBUG
98 	const struct r92ce_tx_desc *txd = desc;
99 
100 	RTWN_DPRINTF(sc, RTWN_DEBUG_XMIT_DESC,
101 	    "%s: len %d, off %d, flags0 %02X, dw: 1 %08X, 2 %08X, 3 %04X "
102 	    "(seq %04X), 4 %08X, 5 %08X, 6 %08X, size %04X, pad %04X, "
103 	    "addr: %08X (64: %08X), next: %08X (64: %08X), "
104 	    "rsvd: %08X %08X %08X %08X\n",
105 	    __func__, le16toh(txd->pktlen), txd->offset, txd->flags0,
106 	    le32toh(txd->txdw1), le32toh(txd->txdw2), le16toh(txd->txdw3),
107 	    le16toh(txd->txdseq), le32toh(txd->txdw4), le32toh(txd->txdw5),
108 	    le32toh(txd->txdw6), le16toh(txd->txbufsize), le16toh(txd->pad),
109 	    le32toh(txd->txbufaddr), le32toh(txd->txbufaddr64),
110 	    le32toh(txd->nextdescaddr), le32toh(txd->nextdescaddr64),
111 	    le32toh(txd->reserved[0]), le32toh(txd->reserved[1]),
112 	    le32toh(txd->reserved[2]), le32toh(txd->reserved[3]));
113 #endif
114 }
115