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 60 void 61 r92ce_setup_tx_desc(struct rtwn_pci_softc *pc, void *desc, 62 uint32_t next_desc_addr) 63 { 64 struct r92ce_tx_desc *txd = desc; 65 66 /* setup tx desc */ 67 txd->nextdescaddr = htole32(next_desc_addr); 68 } 69 70 void 71 r92ce_tx_postsetup(struct rtwn_pci_softc *pc, void *desc, 72 bus_dma_segment_t segs[]) 73 { 74 struct r92ce_tx_desc *txd = desc; 75 76 txd->txbufaddr = htole32(segs[0].ds_addr); 77 txd->txbufsize = txd->pktlen; 78 bus_space_barrier(pc->pc_st, pc->pc_sh, 0, pc->pc_mapsize, 79 BUS_SPACE_BARRIER_WRITE); 80 } 81 82 void 83 r92ce_copy_tx_desc(void *dest, const void *src) 84 { 85 struct r92ce_tx_desc *txd = dest; 86 size_t len = sizeof(struct r92c_tx_desc) + 87 sizeof(txd->txbufsize) + sizeof(txd->pad); 88 89 if (src != NULL) 90 memcpy(dest, src, len); 91 else 92 memset(dest, 0, len); 93 } 94 95 void 96 r92ce_dump_tx_desc(struct rtwn_softc *sc, const void *desc) 97 { 98 #ifdef RTWN_DEBUG 99 const struct r92ce_tx_desc *txd = desc; 100 101 RTWN_DPRINTF(sc, RTWN_DEBUG_XMIT_DESC, 102 "%s: len %d, off %d, flags0 %02X, dw: 1 %08X, 2 %08X, 3 %04X " 103 "(seq %04X), 4 %08X, 5 %08X, 6 %08X, size %04X, pad %04X, " 104 "addr: %08X (64: %08X), next: %08X (64: %08X), " 105 "rsvd: %08X %08X %08X %08X\n", 106 __func__, le16toh(txd->pktlen), txd->offset, txd->flags0, 107 le32toh(txd->txdw1), le32toh(txd->txdw2), le16toh(txd->txdw3), 108 le16toh(txd->txdseq), le32toh(txd->txdw4), le32toh(txd->txdw5), 109 le32toh(txd->txdw6), le16toh(txd->txbufsize), le16toh(txd->pad), 110 le32toh(txd->txbufaddr), le32toh(txd->txbufaddr64), 111 le32toh(txd->nextdescaddr), le32toh(txd->nextdescaddr64), 112 le32toh(txd->reserved[0]), le32toh(txd->reserved[1]), 113 le32toh(txd->reserved[2]), le32toh(txd->reserved[3])); 114 #endif 115 } 116