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/if_var.h> 46 #include <net/ethernet.h> 47 #include <net/if_media.h> 48 49 #include <net80211/ieee80211_var.h> 50 #include <net80211/ieee80211_radiotap.h> 51 52 #include <dev/usb/usb.h> 53 #include <dev/usb/usbdi.h> 54 55 #include <dev/rtwn/if_rtwnreg.h> 56 #include <dev/rtwn/if_rtwnvar.h> 57 58 #include <dev/rtwn/if_rtwn_nop.h> 59 60 #include <dev/rtwn/usb/rtwn_usb_var.h> 61 62 #include <dev/rtwn/rtl8192c/usb/r92cu.h> 63 64 #include <dev/rtwn/rtl8188e/r88e.h> 65 66 #include <dev/rtwn/rtl8812a/r12a_priv.h> 67 #include <dev/rtwn/rtl8812a/r12a_reg.h> 68 #include <dev/rtwn/rtl8812a/r12a_var.h> 69 70 #include <dev/rtwn/rtl8812a/usb/r12au.h> 71 #include <dev/rtwn/rtl8812a/usb/r12au_tx_desc.h> 72 73 void r12au_attach(struct rtwn_usb_softc *); 74 75 static void 76 r12au_postattach(struct rtwn_softc *sc) 77 { 78 struct rtwn_usb_softc *uc = RTWN_USB_SOFTC(sc); 79 struct r12a_softc *rs = sc->sc_priv; 80 81 if (usbd_get_speed(uc->uc_udev) == USB_SPEED_SUPER) { 82 rs->ac_usb_dma_size = 0x07; 83 rs->ac_usb_dma_time = 0x1a; 84 } else { 85 rs->ac_usb_dma_size = 0x01; 86 rs->ac_usb_dma_time = 0x10; 87 } 88 89 if (rs->chip & R12A_CHIP_C_CUT) 90 sc->sc_rf_read = r12a_c_cut_rf_read; 91 else 92 sc->sc_rf_read = r12a_rf_read; 93 94 if (rs->board_type == R92C_BOARD_TYPE_MINICARD || 95 rs->board_type == R92C_BOARD_TYPE_SOLO || 96 rs->board_type == R92C_BOARD_TYPE_COMBO) 97 sc->sc_set_led = r88e_set_led; 98 else 99 sc->sc_set_led = r12a_set_led; 100 101 if (!(rs->ext_pa_2g || rs->ext_lna_2g || 102 rs->ext_pa_5g || rs->ext_lna_5g)) 103 sc->mac_prog = &rtl8812au_mac_no_ext_pa_lna[0]; 104 105 sc->sc_ic.ic_ioctl = r12a_ioctl_net; 106 } 107 108 void 109 r12a_vap_preattach(struct rtwn_softc *sc, struct ieee80211vap *vap) 110 { 111 struct r12a_softc *rs = sc->sc_priv; 112 if_t ifp = vap->iv_ifp; 113 114 if_setcapabilities(ifp, IFCAP_RXCSUM | IFCAP_RXCSUM_IPV6); 115 RTWN_LOCK(sc); 116 if (rs->rs_flags & R12A_RXCKSUM_EN) 117 if_setcapenablebit(ifp, IFCAP_RXCSUM, 0); 118 if (rs->rs_flags & R12A_RXCKSUM6_EN) 119 if_setcapenablebit(ifp, IFCAP_RXCSUM_IPV6, 0); 120 RTWN_UNLOCK(sc); 121 } 122 123 static void 124 r12a_attach_private(struct rtwn_softc *sc) 125 { 126 struct r12a_softc *rs; 127 128 rs = malloc(sizeof(struct r12a_softc), M_RTWN_PRIV, M_WAITOK | M_ZERO); 129 130 rs->rs_flags = R12A_RXCKSUM_EN | R12A_RXCKSUM6_EN; 131 132 rs->rs_fix_spur = r12a_fix_spur; 133 rs->rs_set_band_2ghz = r12a_set_band_2ghz; 134 rs->rs_set_band_5ghz = r12a_set_band_5ghz; 135 rs->rs_init_burstlen = r12au_init_burstlen; 136 rs->rs_init_ampdu_fwhw = r12au_init_ampdu_fwhw; 137 rs->rs_crystalcap_write = r12a_crystalcap_write; 138 #ifndef RTWN_WITHOUT_UCODE 139 rs->rs_iq_calib_fw_supported = r12a_iq_calib_fw_supported; 140 #endif 141 rs->rs_iq_calib_sw = r12a_iq_calib_sw; 142 143 rs->ampdu_max_time = 0x70; 144 rs->ampdu_max_size = 0x1ffff; /* 128k */ 145 146 sc->sc_priv = rs; 147 } 148 149 void 150 r12a_detach_private(struct rtwn_softc *sc) 151 { 152 struct r12a_softc *rs = sc->sc_priv; 153 154 free(rs, M_RTWN_PRIV); 155 } 156 157 static void 158 r12a_read_chipid_vendor(struct rtwn_softc *sc, uint32_t reg_sys_cfg) 159 { 160 struct r12a_softc *rs = sc->sc_priv; 161 162 if (MS(reg_sys_cfg, R92C_SYS_CFG_CHIP_VER_RTL) == 1) 163 rs->chip |= R12A_CHIP_C_CUT; 164 } 165 166 static void 167 r12au_adj_devcaps(struct rtwn_softc *sc) 168 { 169 struct r12a_softc *rs = sc->sc_priv; 170 struct ieee80211com *ic = &sc->sc_ic; 171 172 if (rs->chip & R12A_CHIP_C_CUT) { 173 ic->ic_htcaps |= IEEE80211_HTCAP_LDPC | 174 IEEE80211_HTC_TXLDPC; 175 } 176 177 ic->ic_htcaps |= 178 IEEE80211_HTCAP_CHWIDTH40 | /* 40 MHz channel width */ 179 IEEE80211_HTCAP_SHORTGI40 /* short GI in 40MHz */ 180 ; 181 182 /* TODO: STBC */ 183 184 /* VHT config */ 185 ic->ic_flags_ext |= IEEE80211_FEXT_VHT; 186 ic->ic_vht_cap.vht_cap_info = 187 IEEE80211_VHTCAP_MAX_MPDU_LENGTH_11454 | 188 IEEE80211_VHTCAP_SHORT_GI_80 | 189 IEEE80211_VHTCAP_TXSTBC | 190 IEEE80211_VHTCAP_RXSTBC_1 | 191 IEEE80211_VHTCAP_HTC_VHT | 192 _IEEE80211_SHIFTMASK(7, 193 IEEE80211_VHTCAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK); 194 195 rtwn_attach_vht_cap_info_mcs(sc); 196 } 197 198 void 199 r12au_attach(struct rtwn_usb_softc *uc) 200 { 201 struct rtwn_softc *sc = &uc->uc_sc; 202 203 /* USB part. */ 204 uc->uc_align_rx = r12au_align_rx; 205 uc->tx_agg_desc_num = 1; 206 207 /* Common part. */ 208 sc->sc_flags = RTWN_FLAG_EXT_HDR; 209 210 sc->sc_set_chan = r12a_set_chan; 211 sc->sc_fill_tx_desc = r12a_fill_tx_desc; 212 sc->sc_fill_tx_desc_raw = r12a_fill_tx_desc_raw; 213 sc->sc_fill_tx_desc_null = r12a_fill_tx_desc_null; 214 sc->sc_dump_tx_desc = r12au_dump_tx_desc; 215 sc->sc_tx_radiotap_flags = r12a_tx_radiotap_flags; 216 sc->sc_rx_radiotap_flags = r12a_rx_radiotap_flags; 217 sc->sc_get_rx_stats = r12a_get_rx_stats; 218 sc->sc_get_rssi_cck = r88e_get_rssi_cck; 219 sc->sc_get_rssi_ofdm = r88e_get_rssi_ofdm; 220 sc->sc_classify_intr = r12au_classify_intr; 221 sc->sc_handle_tx_report = r12a_ratectl_tx_complete; 222 sc->sc_handle_tx_report2 = rtwn_nop_softc_uint8_int; 223 sc->sc_handle_c2h_report = r12a_handle_c2h_report; 224 sc->sc_check_frame = r12a_check_frame_checksum; 225 sc->sc_rf_write = r12a_rf_write; 226 sc->sc_check_condition = r12a_check_condition; 227 sc->sc_efuse_postread = rtwn_nop_softc; 228 sc->sc_parse_rom = r12a_parse_rom; 229 sc->sc_power_on = r12a_power_on; 230 sc->sc_power_off = r12a_power_off; 231 #ifndef RTWN_WITHOUT_UCODE 232 sc->sc_fw_reset = r12a_fw_reset; 233 sc->sc_fw_download_enable = r12a_fw_download_enable; 234 #endif 235 sc->sc_llt_init = r92c_llt_init; 236 sc->sc_set_page_size = r12a_set_page_size; 237 sc->sc_lc_calib = r12a_lc_calib; 238 sc->sc_iq_calib = r12a_iq_calib; 239 sc->sc_read_chipid_vendor = r12a_read_chipid_vendor; 240 sc->sc_adj_devcaps = r12au_adj_devcaps; 241 sc->sc_vap_preattach = r12a_vap_preattach; 242 sc->sc_postattach = r12au_postattach; 243 sc->sc_detach_private = r12a_detach_private; 244 #ifndef RTWN_WITHOUT_UCODE 245 sc->sc_set_media_status = r12a_set_media_status; 246 sc->sc_set_rsvd_page = r88e_set_rsvd_page; 247 sc->sc_set_pwrmode = r12a_set_pwrmode; 248 sc->sc_set_rssi = rtwn_nop_softc; /* XXX TODO */ 249 #else 250 sc->sc_set_media_status = rtwn_nop_softc_int; 251 #endif 252 sc->sc_beacon_init = r12a_beacon_init; 253 sc->sc_beacon_enable = r92c_beacon_enable; 254 sc->sc_sta_beacon_enable = r12a_sta_beacon_enable; 255 sc->sc_beacon_set_rate = r12a_beacon_set_rate; 256 sc->sc_beacon_select = rtwn_nop_softc_int; 257 sc->sc_temp_measure = r88e_temp_measure; 258 sc->sc_temp_read = r88e_temp_read; 259 sc->sc_init_tx_agg = r92cu_init_tx_agg; 260 sc->sc_init_rx_agg = r12au_init_rx_agg; 261 sc->sc_init_ampdu = r12au_init_ampdu; 262 sc->sc_init_intr = r12a_init_intr; 263 sc->sc_init_edca = r12a_init_edca; 264 sc->sc_init_bb = r12a_init_bb; 265 sc->sc_init_rf = r12a_init_rf; 266 sc->sc_init_antsel = r12a_init_antsel; 267 sc->sc_post_init = r12au_post_init; 268 sc->sc_init_bcnq1_boundary = rtwn_nop_int_softc; 269 sc->sc_set_tx_power = rtwn_nop_int_softc_vap; 270 271 sc->chan_list_5ghz[0] = r12a_chan_5ghz_0; 272 sc->chan_list_5ghz[1] = r12a_chan_5ghz_1; 273 sc->chan_list_5ghz[2] = r12a_chan_5ghz_2; 274 sc->chan_num_5ghz[0] = nitems(r12a_chan_5ghz_0); 275 sc->chan_num_5ghz[1] = nitems(r12a_chan_5ghz_1); 276 sc->chan_num_5ghz[2] = nitems(r12a_chan_5ghz_2); 277 278 sc->mac_prog = &rtl8812au_mac[0]; 279 sc->mac_size = nitems(rtl8812au_mac); 280 sc->bb_prog = &rtl8812au_bb[0]; 281 sc->bb_size = nitems(rtl8812au_bb); 282 sc->agc_prog = &rtl8812au_agc[0]; 283 sc->agc_size = nitems(rtl8812au_agc); 284 sc->rf_prog = &rtl8812au_rf[0]; 285 286 sc->name = "RTL8812AU"; 287 sc->fwname = "rtwn-rtl8812aufw"; 288 sc->fwsig = 0x950; 289 290 sc->page_count = R12A_TX_PAGE_COUNT; 291 sc->pktbuf_count = R12A_TXPKTBUF_COUNT; 292 293 sc->ackto = 0x80; 294 sc->npubqpages = R12A_PUBQ_NPAGES; 295 sc->page_size = R12A_TX_PAGE_SIZE; 296 297 sc->txdesc_len = sizeof(struct r12au_tx_desc); 298 sc->efuse_maxlen = R12A_EFUSE_MAX_LEN; 299 sc->efuse_maplen = R12A_EFUSE_MAP_LEN; 300 sc->rx_dma_size = R12A_RX_DMA_BUFFER_SIZE; 301 302 sc->macid_limit = R12A_MACID_MAX + 1; 303 sc->cam_entry_limit = R12A_CAM_ENTRY_COUNT; 304 sc->fwsize_limit = R12A_MAX_FW_SIZE; 305 sc->temp_delta = R88E_CALIB_THRESHOLD; 306 307 sc->bcn_status_reg[0] = R92C_TDECTRL; 308 sc->bcn_status_reg[1] = R92C_TDECTRL; 309 sc->rcr = R12A_RCR_DIS_CHK_14 | 310 R12A_RCR_VHT_ACK | 311 R12A_RCR_TCP_OFFLD_EN; 312 313 sc->ntxchains = 2; 314 sc->nrxchains = 2; 315 316 sc->sc_ht40 = 1; 317 318 r12a_attach_private(sc); 319 } 320