1 /*- 2 * Copyright (c) 2016 Andriy Voskoboinyk <avos@FreeBSD.org> 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 */ 26 27 #include <sys/cdefs.h> 28 #include "opt_wlan.h" 29 30 #include <sys/param.h> 31 #include <sys/lock.h> 32 #include <sys/mutex.h> 33 #include <sys/mbuf.h> 34 #include <sys/kernel.h> 35 #include <sys/socket.h> 36 #include <sys/systm.h> 37 #include <sys/malloc.h> 38 #include <sys/queue.h> 39 #include <sys/taskqueue.h> 40 #include <sys/bus.h> 41 #include <sys/endian.h> 42 #include <sys/linker.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_rtwnreg.h> 52 #include <dev/rtwn/if_rtwnvar.h> 53 #include <dev/rtwn/if_rtwn_nop.h> 54 55 #include <dev/rtwn/usb/rtwn_usb_var.h> 56 57 #include <dev/rtwn/rtl8192c/r92c.h> 58 59 #include <dev/rtwn/rtl8188e/r88e.h> 60 61 #include <dev/rtwn/rtl8812a/r12a_var.h> 62 63 #include <dev/rtwn/rtl8812a/usb/r12au.h> 64 #include <dev/rtwn/rtl8812a/usb/r12au_tx_desc.h> 65 66 #include <dev/rtwn/rtl8821a/r21a_reg.h> 67 #include <dev/rtwn/rtl8821a/r21a_priv.h> 68 69 #include <dev/rtwn/rtl8821a/usb/r21au.h> 70 71 void r21au_attach(struct rtwn_usb_softc *); 72 73 static void 74 r21a_postattach(struct rtwn_softc *sc) 75 { 76 struct ieee80211com *ic = &sc->sc_ic; 77 struct r12a_softc *rs = sc->sc_priv; 78 79 if (rs->board_type == R92C_BOARD_TYPE_MINICARD || 80 rs->board_type == R92C_BOARD_TYPE_SOLO || 81 rs->board_type == R92C_BOARD_TYPE_COMBO) 82 sc->sc_set_led = r88e_set_led; 83 else 84 sc->sc_set_led = r21a_set_led; 85 86 TIMEOUT_TASK_INIT(taskqueue_thread, &rs->rs_chan_check, 0, 87 r21au_chan_check, sc); 88 89 /* RXCKSUM */ 90 ic->ic_ioctl = r12a_ioctl_net; 91 /* DFS */ 92 rs->rs_scan_start = ic->ic_scan_start; 93 ic->ic_scan_start = r21au_scan_start; 94 rs->rs_scan_end = ic->ic_scan_end; 95 ic->ic_scan_end = r21au_scan_end; 96 } 97 98 static void 99 r21au_vap_preattach(struct rtwn_softc *sc, struct ieee80211vap *vap) 100 { 101 struct rtwn_vap *rvp = RTWN_VAP(vap); 102 struct r12a_softc *rs = sc->sc_priv; 103 104 r12a_vap_preattach(sc, vap); 105 106 /* Install DFS newstate handler (non-monitor vaps only). */ 107 if (rvp->id != RTWN_VAP_ID_INVALID) { 108 KASSERT(rvp->id >= 0 && rvp->id <= nitems(rs->rs_newstate), 109 ("%s: wrong vap id %d\n", __func__, rvp->id)); 110 111 rs->rs_newstate[rvp->id] = vap->iv_newstate; 112 vap->iv_newstate = r21au_newstate; 113 } 114 } 115 116 static void 117 r21a_attach_private(struct rtwn_softc *sc) 118 { 119 struct sysctl_ctx_list *ctx = device_get_sysctl_ctx(sc->sc_dev); 120 struct sysctl_oid *tree = device_get_sysctl_tree(sc->sc_dev); 121 struct r12a_softc *rs; 122 123 rs = malloc(sizeof(struct r12a_softc), M_RTWN_PRIV, M_WAITOK | M_ZERO); 124 125 rs->rs_flags = R12A_RXCKSUM_EN | R12A_RXCKSUM6_EN; 126 127 rs->rs_radar = 0; 128 SYSCTL_ADD_INT(ctx, SYSCTL_CHILDREN(tree), OID_AUTO, 129 "radar_detection", CTLFLAG_RDTUN, &rs->rs_radar, 130 rs->rs_radar, "Enable radar detection (untested)"); 131 132 rs->rs_fix_spur = rtwn_nop_softc_chan; 133 rs->rs_set_band_2ghz = r21a_set_band_2ghz; 134 rs->rs_set_band_5ghz = r21a_set_band_5ghz; 135 rs->rs_init_burstlen = r12au_init_burstlen_usb2; 136 rs->rs_init_ampdu_fwhw = r21a_init_ampdu_fwhw; 137 rs->rs_crystalcap_write = r21a_crystalcap_write; 138 #ifndef RTWN_WITHOUT_UCODE 139 rs->rs_iq_calib_fw_supported = r21a_iq_calib_fw_supported; 140 #endif 141 rs->rs_iq_calib_sw = r21a_iq_calib_sw; 142 143 rs->ampdu_max_time = 0x5e; 144 145 rs->ac_usb_dma_size = 0x01; 146 rs->ac_usb_dma_time = 0x10; 147 148 sc->sc_priv = rs; 149 } 150 151 static void 152 r21au_adj_devcaps(struct rtwn_softc *sc) 153 { 154 struct ieee80211com *ic = &sc->sc_ic; 155 struct r12a_softc *rs = sc->sc_priv; 156 157 ic->ic_htcaps |= IEEE80211_HTC_TXLDPC; 158 if (rs->rs_radar != 0) 159 ic->ic_caps |= IEEE80211_C_DFS; 160 161 ic->ic_htcaps |= 162 IEEE80211_HTCAP_CHWIDTH40 /* 40 MHz channel width */ 163 | IEEE80211_HTCAP_SHORTGI40 /* short GI in 40MHz */ 164 ; 165 166 /* TODO: VHT */ 167 } 168 169 void 170 r21au_attach(struct rtwn_usb_softc *uc) 171 { 172 struct rtwn_softc *sc = &uc->uc_sc; 173 174 /* USB part. */ 175 uc->uc_align_rx = r12au_align_rx; 176 uc->tx_agg_desc_num = 6; 177 178 /* Common part. */ 179 sc->sc_flags = RTWN_FLAG_EXT_HDR; 180 181 sc->sc_set_chan = r12a_set_chan; 182 sc->sc_fill_tx_desc = r12a_fill_tx_desc; 183 sc->sc_fill_tx_desc_raw = r12a_fill_tx_desc_raw; 184 sc->sc_fill_tx_desc_null = r12a_fill_tx_desc_null; 185 sc->sc_dump_tx_desc = r12au_dump_tx_desc; 186 sc->sc_tx_radiotap_flags = r12a_tx_radiotap_flags; 187 sc->sc_rx_radiotap_flags = r12a_rx_radiotap_flags; 188 sc->sc_get_rx_stats = r12a_get_rx_stats; 189 sc->sc_get_rssi_cck = r21a_get_rssi_cck; 190 sc->sc_get_rssi_ofdm = r88e_get_rssi_ofdm; 191 sc->sc_classify_intr = r12au_classify_intr; 192 sc->sc_handle_tx_report = r12a_ratectl_tx_complete; 193 sc->sc_handle_tx_report2 = rtwn_nop_softc_uint8_int; 194 sc->sc_handle_c2h_report = r12a_handle_c2h_report; 195 sc->sc_check_frame = r12a_check_frame_checksum; 196 sc->sc_rf_read = r12a_c_cut_rf_read; 197 sc->sc_rf_write = r12a_rf_write; 198 sc->sc_check_condition = r21a_check_condition; 199 sc->sc_efuse_postread = rtwn_nop_softc; 200 sc->sc_parse_rom = r21a_parse_rom; 201 sc->sc_power_on = r21a_power_on; 202 sc->sc_power_off = r21a_power_off; 203 #ifndef RTWN_WITHOUT_UCODE 204 sc->sc_fw_reset = r21a_fw_reset; 205 sc->sc_fw_download_enable = r12a_fw_download_enable; 206 #endif 207 sc->sc_llt_init = r92c_llt_init; 208 sc->sc_set_page_size = rtwn_nop_int_softc; 209 sc->sc_lc_calib = rtwn_nop_softc; /* XXX not used */ 210 sc->sc_iq_calib = r12a_iq_calib; 211 sc->sc_read_chipid_vendor = rtwn_nop_softc_uint32; 212 sc->sc_adj_devcaps = r21au_adj_devcaps; 213 sc->sc_vap_preattach = r21au_vap_preattach; 214 sc->sc_postattach = r21a_postattach; 215 sc->sc_detach_private = r12a_detach_private; 216 #ifndef RTWN_WITHOUT_UCODE 217 sc->sc_set_media_status = r12a_set_media_status; 218 sc->sc_set_rsvd_page = r88e_set_rsvd_page; 219 sc->sc_set_pwrmode = r12a_set_pwrmode; 220 sc->sc_set_rssi = rtwn_nop_softc; /* XXX TODO */ 221 #else 222 sc->sc_set_media_status = rtwn_nop_softc_int; 223 #endif 224 sc->sc_beacon_init = r21a_beacon_init; 225 sc->sc_beacon_enable = r92c_beacon_enable; 226 sc->sc_beacon_set_rate = r12a_beacon_set_rate; 227 sc->sc_beacon_select = r21a_beacon_select; 228 sc->sc_temp_measure = r88e_temp_measure; 229 sc->sc_temp_read = r88e_temp_read; 230 sc->sc_init_tx_agg = r21au_init_tx_agg; 231 sc->sc_init_rx_agg = r12au_init_rx_agg; 232 sc->sc_init_ampdu = r12au_init_ampdu; 233 sc->sc_init_intr = r12a_init_intr; 234 sc->sc_init_edca = r12a_init_edca; 235 sc->sc_init_bb = r12a_init_bb; 236 sc->sc_init_rf = r12a_init_rf; 237 sc->sc_init_antsel = r12a_init_antsel; 238 sc->sc_post_init = r12au_post_init; 239 sc->sc_init_bcnq1_boundary = r21a_init_bcnq1_boundary; 240 sc->sc_set_tx_power = rtwn_nop_int_softc_vap; 241 242 sc->chan_list_5ghz[0] = r12a_chan_5ghz_0; 243 sc->chan_list_5ghz[1] = r12a_chan_5ghz_1; 244 sc->chan_list_5ghz[2] = r12a_chan_5ghz_2; 245 sc->chan_num_5ghz[0] = nitems(r12a_chan_5ghz_0); 246 sc->chan_num_5ghz[1] = nitems(r12a_chan_5ghz_1); 247 sc->chan_num_5ghz[2] = nitems(r12a_chan_5ghz_2); 248 249 sc->mac_prog = &rtl8821au_mac[0]; 250 sc->mac_size = nitems(rtl8821au_mac); 251 sc->bb_prog = &rtl8821au_bb[0]; 252 sc->bb_size = nitems(rtl8821au_bb); 253 sc->agc_prog = &rtl8821au_agc[0]; 254 sc->agc_size = nitems(rtl8821au_agc); 255 sc->rf_prog = &rtl8821au_rf[0]; 256 257 sc->name = "RTL8821AU"; 258 sc->fwname = "rtwn-rtl8821aufw"; 259 sc->fwsig = 0x210; 260 261 sc->page_count = R21A_TX_PAGE_COUNT; 262 sc->pktbuf_count = R12A_TXPKTBUF_COUNT; 263 264 sc->ackto = 0x80; 265 sc->npubqpages = R12A_PUBQ_NPAGES; 266 sc->page_size = R21A_TX_PAGE_SIZE; 267 268 sc->txdesc_len = sizeof(struct r12au_tx_desc); 269 sc->efuse_maxlen = R12A_EFUSE_MAX_LEN; 270 sc->efuse_maplen = R12A_EFUSE_MAP_LEN; 271 sc->rx_dma_size = R12A_RX_DMA_BUFFER_SIZE; 272 273 sc->macid_limit = R12A_MACID_MAX + 1; 274 sc->cam_entry_limit = R12A_CAM_ENTRY_COUNT; 275 sc->fwsize_limit = R12A_MAX_FW_SIZE; 276 sc->temp_delta = R88E_CALIB_THRESHOLD; 277 278 sc->bcn_status_reg[0] = R92C_TDECTRL; 279 sc->bcn_status_reg[1] = R21A_DWBCN1_CTRL; 280 sc->rcr = R12A_RCR_DIS_CHK_14 | 281 R12A_RCR_VHT_ACK | 282 R12A_RCR_TCP_OFFLD_EN; 283 284 sc->ntxchains = 1; 285 sc->nrxchains = 1; 286 287 sc->sc_ht40 = 1; 288 289 r21a_attach_private(sc); 290 } 291