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 #define R92C_MIN_TX_PWR 0x00 22 #define R92C_MAX_TX_PWR 0x3f 23 24 #define R92C_H2C_NBOX 4 25 26 27 /* Common part of Tx descriptor (named only!). */ 28 struct rtwn_tx_desc_common { 29 uint16_t pktlen; 30 uint8_t offset; 31 uint8_t flags0; 32 #define RTWN_FLAGS0_OWN 0x80 33 34 uint32_t txdw1; 35 /* NB: qsel is shared too; however, it looks better at the lower level */ 36 #define RTWN_TXDW1_CIPHER_M 0x00c00000 37 #define RTWN_TXDW1_CIPHER_S 22 38 #define RTWN_TXDW1_CIPHER_NONE 0 39 #define RTWN_TXDW1_CIPHER_RC4 1 40 #define RTWN_TXDW1_CIPHER_SM4 2 41 #define RTWN_TXDW1_CIPHER_AES 3 42 43 uint32_t reserved[5]; 44 45 union txdw7_shared { 46 uint16_t usb_checksum; 47 uint16_t pci_txbufsize; 48 } txdw7; 49 } __packed __attribute__((aligned(4))); 50 51 /* 52 * Macros to access subfields in registers. 53 */ 54 /* Mask and Shift (getter). */ 55 #define MS(val, field) \ 56 (((val) & field##_M) >> field##_S) 57 58 /* Shift and Mask (setter). */ 59 #define SM(field, val) \ 60 (((val) << field##_S) & field##_M) 61 62 /* Rewrite. */ 63 #define RW(var, field, val) \ 64 (((var) & ~field##_M) | SM(field, val)) 65 66 67 #define RTWN_MAX_CONDITIONS 3 68 69 /* 70 * Structure for MAC initialization values. 71 */ 72 struct rtwn_mac_prog { 73 uint16_t reg; 74 uint8_t val; 75 }; 76 77 /* 78 * Structure for baseband initialization values. 79 */ 80 struct rtwn_bb_prog { 81 int count; 82 const uint16_t *reg; 83 const uint32_t *val; 84 const uint8_t cond[RTWN_MAX_CONDITIONS]; 85 const struct rtwn_bb_prog *next; 86 }; 87 88 struct rtwn_agc_prog { 89 int count; 90 const uint32_t *val; 91 const uint8_t cond[RTWN_MAX_CONDITIONS]; 92 const struct rtwn_agc_prog *next; 93 }; 94 95 /* 96 * Structure for RF initialization values. 97 */ 98 struct rtwn_rf_prog { 99 int count; 100 const uint8_t *reg; 101 const uint32_t *val; 102 const uint8_t cond[RTWN_MAX_CONDITIONS]; 103 const struct rtwn_rf_prog *next; 104 }; 105 106 107 /* XXX move to net80211. */ 108 static __inline int 109 rtwn_chan2centieee(const struct ieee80211_channel *c) 110 { 111 int chan; 112 113 chan = c->ic_ieee; 114 if (c->ic_extieee != 0) 115 chan = (chan + c->ic_extieee) / 2; 116 117 return (chan); 118 } 119