1 /*- 2 * Copyright (c) 2010 Damien Bergamini <damien.bergamini@free.fr> 3 * Copyright (c) 2016 Andriy Voskoboinyk <avos@FreeBSD.org> 4 * 5 * Permission to use, copy, modify, and distribute this software for any 6 * purpose with or without fee is hereby granted, provided that the above 7 * copyright notice and this permission notice appear in all copies. 8 * 9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 16 * 17 * $OpenBSD: if_urtwnreg.h,v 1.3 2010/11/16 18:02:59 damien Exp $ 18 * $FreeBSD$ 19 */ 20 21 #ifndef IF_RTWNREG_H 22 #define IF_RTWNREG_H 23 24 #define R92C_MIN_TX_PWR 0x00 25 #define R92C_MAX_TX_PWR 0x3f 26 27 #define R92C_H2C_NBOX 4 28 29 /* Common part of Tx descriptor (named only!). */ 30 struct rtwn_tx_desc_common { 31 uint16_t pktlen; 32 uint8_t offset; 33 uint8_t flags0; 34 #define RTWN_FLAGS0_OWN 0x80 35 36 uint32_t txdw1; 37 /* NB: qsel is shared too; however, it looks better at the lower level */ 38 #define RTWN_TXDW1_CIPHER_M 0x00c00000 39 #define RTWN_TXDW1_CIPHER_S 22 40 #define RTWN_TXDW1_CIPHER_NONE 0 41 #define RTWN_TXDW1_CIPHER_RC4 1 42 #define RTWN_TXDW1_CIPHER_SM4 2 43 #define RTWN_TXDW1_CIPHER_AES 3 44 45 uint32_t reserved[5]; 46 47 union txdw7_shared { 48 uint16_t usb_checksum; 49 uint16_t pci_txbufsize; 50 } txdw7; 51 } __packed __attribute__((aligned(4))); 52 53 /* Common part of Rx descriptor. */ 54 struct rtwn_rx_stat_common { 55 uint32_t rxdw0; 56 #define RTWN_RXDW0_PKTLEN_M 0x00003fff 57 #define RTWN_RXDW0_PKTLEN_S 0 58 #define RTWN_RXDW0_CRCERR 0x00004000 59 #define RTWN_RXDW0_ICVERR 0x00008000 60 #define RTWN_RXDW0_INFOSZ_M 0x000f0000 61 #define RTWN_RXDW0_INFOSZ_S 16 62 #define RTWN_RXDW0_CIPHER_M 0x00700000 63 #define RTWN_RXDW0_CIPHER_S 20 64 #define RTWN_RXDW0_QOS 0x00800000 65 #define RTWN_RXDW0_SHIFT_M 0x03000000 66 #define RTWN_RXDW0_SHIFT_S 24 67 #define RTWN_RXDW0_PHYST 0x04000000 68 #define RTWN_RXDW0_SWDEC 0x08000000 69 #define RTWN_RXDW0_LS 0x10000000 70 #define RTWN_RXDW0_FS 0x20000000 71 #define RTWN_RXDW0_EOR 0x40000000 72 #define RTWN_RXDW0_OWN 0x80000000 73 74 uint32_t rxdw1; 75 #define RTWN_RXDW1_AMSDU 0x00002000 76 #define RTWN_RXDW1_MC 0x40000000 77 #define RTWN_RXDW1_BC 0x80000000 78 79 uint32_t rxdw2; 80 uint32_t rxdw3; 81 #define RTWN_RXDW3_HTC 0x00000400 82 #define RTWN_RXDW3_BSSID01_FIT_M 0x00003000 83 #define RTWN_RXDW3_BSSID01_FIT_S 12 84 85 uint32_t rxdw4; 86 uint32_t tsf_low; 87 } __packed __attribute__((aligned(4))); 88 89 /* Rx descriptor for PCIe devices. */ 90 struct rtwn_rx_stat_pci { 91 uint32_t rxdw0; 92 uint32_t rxdw1; 93 uint32_t rxdw2; 94 uint32_t rxdw3; 95 uint32_t rxdw4; 96 uint32_t tsf_low; 97 98 uint32_t rxbufaddr; 99 uint32_t rxbufaddr64; 100 } __packed __attribute__((aligned(4))); 101 102 /* 103 * Macros to access subfields in registers. 104 */ 105 /* Mask and Shift (getter). */ 106 #define MS(val, field) \ 107 (((val) & field##_M) >> field##_S) 108 109 /* Shift and Mask (setter). */ 110 #define SM(field, val) \ 111 (((val) << field##_S) & field##_M) 112 113 /* Rewrite. */ 114 #define RW(var, field, val) \ 115 (((var) & ~field##_M) | SM(field, val)) 116 117 #define RTWN_MAX_CONDITIONS 3 118 119 /* 120 * Structure for MAC initialization values. 121 */ 122 struct rtwn_mac_prog { 123 uint16_t reg; 124 uint8_t val; 125 }; 126 127 /* 128 * Structure for baseband initialization values. 129 */ 130 struct rtwn_bb_prog { 131 int count; 132 const uint16_t *reg; 133 const uint32_t *val; 134 const uint8_t cond[RTWN_MAX_CONDITIONS]; 135 const struct rtwn_bb_prog *next; 136 }; 137 138 struct rtwn_agc_prog { 139 int count; 140 const uint32_t *val; 141 const uint8_t cond[RTWN_MAX_CONDITIONS]; 142 const struct rtwn_agc_prog *next; 143 }; 144 145 /* 146 * Structure for RF initialization values. 147 */ 148 struct rtwn_rf_prog { 149 int count; 150 const uint8_t *reg; 151 const uint32_t *val; 152 const uint8_t cond[RTWN_MAX_CONDITIONS]; 153 const struct rtwn_rf_prog *next; 154 }; 155 156 /* XXX move to net80211. */ 157 static __inline int 158 rtwn_chan2centieee(const struct ieee80211_channel *c) 159 { 160 int chan; 161 162 chan = c->ic_ieee; 163 if (c->ic_extieee != 0) 164 chan = (chan + c->ic_extieee) / 2; 165 166 return (chan); 167 } 168 169 #endif /* IF_RTWNREG_H */ 170