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 __FBSDID("$FreeBSD$"); 29 30 #include "opt_wlan.h" 31 32 #include <sys/param.h> 33 #include <sys/lock.h> 34 #include <sys/mutex.h> 35 #include <sys/mbuf.h> 36 #include <sys/kernel.h> 37 #include <sys/socket.h> 38 #include <sys/systm.h> 39 #include <sys/malloc.h> 40 #include <sys/queue.h> 41 #include <sys/taskqueue.h> 42 #include <sys/bus.h> 43 #include <sys/endian.h> 44 #include <sys/linker.h> 45 46 #include <net/if.h> 47 #include <net/ethernet.h> 48 #include <net/if_media.h> 49 50 #include <net80211/ieee80211_var.h> 51 #include <net80211/ieee80211_radiotap.h> 52 53 #include <dev/rtwn/if_rtwnreg.h> 54 #include <dev/rtwn/if_rtwnvar.h> 55 #include <dev/rtwn/if_rtwn_nop.h> 56 57 #include <dev/rtwn/usb/rtwn_usb_var.h> 58 59 #include <dev/rtwn/rtl8192c/r92c.h> 60 61 #include <dev/rtwn/rtl8188e/r88e.h> 62 63 #include <dev/rtwn/rtl8812a/r12a_var.h> 64 #include <dev/rtwn/rtl8812a/r12a_rom_defs.h> 65 66 #include <dev/rtwn/rtl8812a/usb/r12au.h> 67 #include <dev/rtwn/rtl8812a/usb/r12au_tx_desc.h> 68 69 #include <dev/rtwn/rtl8821a/r21a_reg.h> 70 #include <dev/rtwn/rtl8821a/r21a_priv.h> 71 72 #include <dev/rtwn/rtl8821a/usb/r21au.h> 73 74 75 void r21au_attach(struct rtwn_usb_softc *); 76 77 static void 78 r21a_postattach(struct rtwn_softc *sc) 79 { 80 struct r12a_softc *rs = sc->sc_priv; 81 82 if (rs->board_type == R92C_BOARD_TYPE_MINICARD || 83 rs->board_type == R92C_BOARD_TYPE_SOLO || 84 rs->board_type == R92C_BOARD_TYPE_COMBO) 85 sc->sc_set_led = r88e_set_led; 86 else 87 sc->sc_set_led = r21a_set_led; 88 89 sc->sc_ic.ic_ioctl = r12a_ioctl_net; 90 } 91 92 static void 93 r21a_attach_private(struct rtwn_softc *sc) 94 { 95 struct r12a_softc *rs; 96 97 rs = malloc(sizeof(struct r12a_softc), M_RTWN_PRIV, M_WAITOK | M_ZERO); 98 99 rs->rs_flags = R12A_RXCKSUM_EN | R12A_RXCKSUM6_EN; 100 101 rs->rs_fix_spur = rtwn_nop_softc_chan; 102 rs->rs_set_band_2ghz = r21a_set_band_2ghz; 103 rs->rs_set_band_5ghz = r21a_set_band_5ghz; 104 rs->rs_init_burstlen = r21au_init_burstlen; 105 rs->rs_init_ampdu_fwhw = r21a_init_ampdu_fwhw; 106 rs->rs_crystalcap_write = r21a_crystalcap_write; 107 #ifndef RTWN_WITHOUT_UCODE 108 rs->rs_iq_calib_fw_supported = r21a_iq_calib_fw_supported; 109 #endif 110 rs->rs_iq_calib_sw = r21a_iq_calib_sw; 111 112 rs->ampdu_max_time = 0x5e; 113 114 rs->ac_usb_dma_size = 0x01; 115 rs->ac_usb_dma_time = 0x10; 116 117 sc->sc_priv = rs; 118 } 119 120 static void 121 r21au_adj_devcaps(struct rtwn_softc *sc) 122 { 123 /* TODO: DFS, LDPC etc */ 124 } 125 126 void 127 r21au_attach(struct rtwn_usb_softc *uc) 128 { 129 struct rtwn_softc *sc = &uc->uc_sc; 130 131 /* USB part. */ 132 uc->uc_align_rx = r12au_align_rx; 133 uc->tx_agg_desc_num = 6; 134 135 /* Common part. */ 136 sc->sc_flags = RTWN_FLAG_EXT_HDR; 137 138 sc->sc_set_chan = r12a_set_chan; 139 sc->sc_fill_tx_desc = r12a_fill_tx_desc; 140 sc->sc_fill_tx_desc_raw = r12a_fill_tx_desc_raw; 141 sc->sc_fill_tx_desc_null = r12a_fill_tx_desc_null; 142 sc->sc_dump_tx_desc = r12au_dump_tx_desc; 143 sc->sc_tx_radiotap_flags = r12a_tx_radiotap_flags; 144 sc->sc_rx_radiotap_flags = r12a_rx_radiotap_flags; 145 sc->sc_get_rssi_cck = r21a_get_rssi_cck; 146 sc->sc_get_rssi_ofdm = r88e_get_rssi_ofdm; 147 sc->sc_classify_intr = r12au_classify_intr; 148 sc->sc_handle_tx_report = r12a_ratectl_tx_complete; 149 sc->sc_handle_c2h_report = r12a_handle_c2h_report; 150 sc->sc_check_frame = r12a_check_frame_checksum; 151 sc->sc_rf_read = r12a_c_cut_rf_read; 152 sc->sc_rf_write = r12a_rf_write; 153 sc->sc_check_condition = r21a_check_condition; 154 sc->sc_efuse_postread = rtwn_nop_softc; 155 sc->sc_parse_rom = r21a_parse_rom; 156 sc->sc_power_on = r21a_power_on; 157 sc->sc_power_off = r21a_power_off; 158 #ifndef RTWN_WITHOUT_UCODE 159 sc->sc_fw_reset = r21a_fw_reset; 160 sc->sc_fw_download_enable = r12a_fw_download_enable; 161 #endif 162 sc->sc_set_page_size = rtwn_nop_int_softc; 163 sc->sc_lc_calib = rtwn_nop_softc; /* XXX not used */ 164 sc->sc_iq_calib = r12a_iq_calib; 165 sc->sc_read_chipid_vendor = rtwn_nop_softc_uint32; 166 sc->sc_adj_devcaps = r21au_adj_devcaps; 167 sc->sc_vap_preattach = r12a_vap_preattach; 168 sc->sc_postattach = r21a_postattach; 169 sc->sc_detach_private = r12a_detach_private; 170 #ifndef RTWN_WITHOUT_UCODE 171 sc->sc_set_media_status = r12a_set_media_status; 172 sc->sc_set_rsvd_page = r88e_set_rsvd_page; 173 sc->sc_set_pwrmode = r12a_set_pwrmode; 174 sc->sc_set_rssi = rtwn_nop_softc; /* XXX TODO */ 175 #else 176 sc->sc_set_media_status = rtwn_nop_softc_int; 177 #endif 178 sc->sc_beacon_init = r21a_beacon_init; 179 sc->sc_beacon_enable = r92c_beacon_enable; 180 sc->sc_beacon_set_rate = r12a_beacon_set_rate; 181 sc->sc_beacon_select = r21a_beacon_select; 182 sc->sc_temp_measure = r88e_temp_measure; 183 sc->sc_temp_read = r88e_temp_read; 184 sc->sc_init_tx_agg = r21au_init_tx_agg; 185 sc->sc_init_rx_agg = r12au_init_rx_agg; 186 sc->sc_init_ampdu = r12au_init_ampdu; 187 sc->sc_init_intr = r12a_init_intr; 188 sc->sc_init_edca = r12a_init_edca; 189 sc->sc_init_bb = r12a_init_bb; 190 sc->sc_init_rf = r12a_init_rf; 191 sc->sc_init_antsel = r12a_init_antsel; 192 sc->sc_post_init = r12au_post_init; 193 sc->sc_init_bcnq1_boundary = r21a_init_bcnq1_boundary; 194 195 sc->chan_list_5ghz[0] = r12a_chan_5ghz_0; 196 sc->chan_list_5ghz[1] = r12a_chan_5ghz_1; 197 sc->chan_list_5ghz[2] = r12a_chan_5ghz_2; 198 sc->chan_num_5ghz[0] = nitems(r12a_chan_5ghz_0); 199 sc->chan_num_5ghz[1] = nitems(r12a_chan_5ghz_1); 200 sc->chan_num_5ghz[2] = nitems(r12a_chan_5ghz_2); 201 202 sc->mac_prog = &rtl8821au_mac[0]; 203 sc->mac_size = nitems(rtl8821au_mac); 204 sc->bb_prog = &rtl8821au_bb[0]; 205 sc->bb_size = nitems(rtl8821au_bb); 206 sc->agc_prog = &rtl8821au_agc[0]; 207 sc->agc_size = nitems(rtl8821au_agc); 208 sc->rf_prog = &rtl8821au_rf[0]; 209 210 sc->name = "RTL8821AU"; 211 sc->fwname = "rtwn-rtl8821aufw"; 212 sc->fwsig = 0x210; 213 214 sc->page_count = R21A_TX_PAGE_COUNT; 215 sc->pktbuf_count = R12A_TXPKTBUF_COUNT; 216 217 sc->ackto = 0x80; 218 sc->npubqpages = R12A_PUBQ_NPAGES; 219 sc->page_size = R21A_TX_PAGE_SIZE; 220 221 sc->txdesc_len = sizeof(struct r12au_tx_desc); 222 sc->efuse_maxlen = R12A_EFUSE_MAX_LEN; 223 sc->efuse_maplen = R12A_EFUSE_MAP_LEN; 224 sc->rx_dma_size = R12A_RX_DMA_BUFFER_SIZE; 225 226 sc->macid_limit = R12A_MACID_MAX + 1; 227 sc->cam_entry_limit = R12A_CAM_ENTRY_COUNT; 228 sc->fwsize_limit = R12A_MAX_FW_SIZE; 229 sc->temp_delta = R88E_CALIB_THRESHOLD; 230 231 sc->bcn_status_reg[0] = R92C_TDECTRL; 232 sc->bcn_status_reg[1] = R21A_DWBCN1_CTRL; 233 sc->rcr = R12A_RCR_DIS_CHK_14 | 234 R12A_RCR_VHT_ACK | 235 R12A_RCR_TCP_OFFLD_EN; 236 237 sc->ntxchains = 1; 238 sc->nrxchains = 1; 239 240 r21a_attach_private(sc); 241 } 242