xref: /freebsd/sys/dev/rtwn/rtl8192c/pci/r92ce_tx.c (revision 685dc743)
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 #include "opt_wlan.h"
23 
24 #include <sys/param.h>
25 #include <sys/lock.h>
26 #include <sys/mutex.h>
27 #include <sys/mbuf.h>
28 #include <sys/kernel.h>
29 #include <sys/socket.h>
30 #include <sys/systm.h>
31 #include <sys/malloc.h>
32 #include <sys/queue.h>
33 #include <sys/taskqueue.h>
34 #include <sys/bus.h>
35 #include <sys/endian.h>
36 #include <sys/linker.h>
37 
38 #include <machine/bus.h>
39 #include <machine/resource.h>
40 #include <sys/rman.h>
41 
42 #include <net/if.h>
43 #include <net/ethernet.h>
44 #include <net/if_media.h>
45 
46 #include <net80211/ieee80211_var.h>
47 #include <net80211/ieee80211_radiotap.h>
48 
49 #include <dev/rtwn/if_rtwnvar.h>
50 #include <dev/rtwn/if_rtwn_debug.h>
51 
52 #include <dev/rtwn/pci/rtwn_pci_var.h>
53 
54 #include <dev/rtwn/rtl8192c/pci/r92ce.h>
55 #include <dev/rtwn/rtl8192c/pci/r92ce_tx_desc.h>
56 
57 void
r92ce_setup_tx_desc(struct rtwn_pci_softc * pc,void * desc,uint32_t next_desc_addr)58 r92ce_setup_tx_desc(struct rtwn_pci_softc *pc, void *desc,
59     uint32_t next_desc_addr)
60 {
61 	struct r92ce_tx_desc *txd = desc;
62 
63 	/* setup tx desc */
64 	txd->nextdescaddr = htole32(next_desc_addr);
65 }
66 
67 void
r92ce_tx_postsetup(struct rtwn_pci_softc * pc,void * desc,bus_dma_segment_t segs[])68 r92ce_tx_postsetup(struct rtwn_pci_softc *pc, void *desc,
69     bus_dma_segment_t segs[])
70 {
71 	struct r92ce_tx_desc *txd = desc;
72 
73 	txd->txbufaddr = htole32(segs[0].ds_addr);
74 	txd->txbufsize = txd->pktlen;
75 	bus_space_barrier(pc->pc_st, pc->pc_sh, 0, pc->pc_mapsize,
76 	    BUS_SPACE_BARRIER_WRITE);
77 }
78 
79 void
r92ce_copy_tx_desc(void * dest,const void * src)80 r92ce_copy_tx_desc(void *dest, const void *src)
81 {
82 	struct r92ce_tx_desc *txd = dest;
83 	size_t len = sizeof(struct r92c_tx_desc) +
84 	    sizeof(txd->txbufsize) + sizeof(txd->pad);
85 
86 	if (src != NULL)
87 		memcpy(dest, src, len);
88 	else
89 		memset(dest, 0, len);
90 }
91 
92 void
r92ce_dump_tx_desc(struct rtwn_softc * sc,const void * desc)93 r92ce_dump_tx_desc(struct rtwn_softc *sc, const void *desc)
94 {
95 #ifdef RTWN_DEBUG
96 	const struct r92ce_tx_desc *txd = desc;
97 
98 	RTWN_DPRINTF(sc, RTWN_DEBUG_XMIT_DESC,
99 	    "%s: len %d, off %d, flags0 %02X, dw: 1 %08X, 2 %08X, 3 %04X "
100 	    "(seq %04X), 4 %08X, 5 %08X, 6 %08X, size %04X, pad %04X, "
101 	    "addr: %08X (64: %08X), next: %08X (64: %08X), "
102 	    "rsvd: %08X %08X %08X %08X\n",
103 	    __func__, le16toh(txd->pktlen), txd->offset, txd->flags0,
104 	    le32toh(txd->txdw1), le32toh(txd->txdw2), le16toh(txd->txdw3),
105 	    le16toh(txd->txdseq), le32toh(txd->txdw4), le32toh(txd->txdw5),
106 	    le32toh(txd->txdw6), le16toh(txd->txbufsize), le16toh(txd->pad),
107 	    le32toh(txd->txbufaddr), le32toh(txd->txbufaddr64),
108 	    le32toh(txd->nextdescaddr), le32toh(txd->nextdescaddr64),
109 	    le32toh(txd->reserved[0]), le32toh(txd->reserved[1]),
110 	    le32toh(txd->reserved[2]), le32toh(txd->reserved[3]));
111 #endif
112 }
113