160b9567dSKevin Lo /*- 260b9567dSKevin Lo * Copyright (c) 2017 Kevin Lo <kevlo@FreeBSD.org> 360b9567dSKevin Lo * 460b9567dSKevin Lo * Permission to use, copy, modify, and distribute this software for any 560b9567dSKevin Lo * purpose with or without fee is hereby granted, provided that the above 660b9567dSKevin Lo * copyright notice and this permission notice appear in all copies. 760b9567dSKevin Lo * 860b9567dSKevin Lo * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 960b9567dSKevin Lo * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 1060b9567dSKevin Lo * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 1160b9567dSKevin Lo * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 1260b9567dSKevin Lo * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 1360b9567dSKevin Lo * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 1460b9567dSKevin Lo * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 1560b9567dSKevin Lo */ 1660b9567dSKevin Lo 1760b9567dSKevin Lo #include <sys/cdefs.h> 1860b9567dSKevin Lo __FBSDID("$FreeBSD$"); 1960b9567dSKevin Lo 2060b9567dSKevin Lo #include "opt_wlan.h" 2160b9567dSKevin Lo 2260b9567dSKevin Lo #include <sys/param.h> 2360b9567dSKevin Lo #include <sys/lock.h> 2460b9567dSKevin Lo #include <sys/mutex.h> 2560b9567dSKevin Lo #include <sys/mbuf.h> 2660b9567dSKevin Lo #include <sys/kernel.h> 2760b9567dSKevin Lo #include <sys/socket.h> 2860b9567dSKevin Lo #include <sys/systm.h> 2960b9567dSKevin Lo #include <sys/malloc.h> 3060b9567dSKevin Lo #include <sys/queue.h> 3160b9567dSKevin Lo #include <sys/taskqueue.h> 3260b9567dSKevin Lo #include <sys/bus.h> 3360b9567dSKevin Lo #include <sys/endian.h> 3460b9567dSKevin Lo #include <sys/linker.h> 3560b9567dSKevin Lo 3660b9567dSKevin Lo #include <net/if.h> 3760b9567dSKevin Lo #include <net/ethernet.h> 3860b9567dSKevin Lo #include <net/if_media.h> 3960b9567dSKevin Lo 4060b9567dSKevin Lo #include <net80211/ieee80211_var.h> 4160b9567dSKevin Lo #include <net80211/ieee80211_radiotap.h> 4260b9567dSKevin Lo 4360b9567dSKevin Lo #include <dev/usb/usb.h> 4460b9567dSKevin Lo #include <dev/usb/usbdi.h> 4560b9567dSKevin Lo 4660b9567dSKevin Lo #include <dev/rtwn/if_rtwnreg.h> 4760b9567dSKevin Lo #include <dev/rtwn/if_rtwnvar.h> 4860b9567dSKevin Lo 4960b9567dSKevin Lo #include <dev/rtwn/if_rtwn_nop.h> 5060b9567dSKevin Lo 5160b9567dSKevin Lo #include <dev/rtwn/usb/rtwn_usb_var.h> 5260b9567dSKevin Lo 5360b9567dSKevin Lo #include <dev/rtwn/rtl8192c/usb/r92cu.h> 5460b9567dSKevin Lo 5560b9567dSKevin Lo #include <dev/rtwn/rtl8188e/r88e.h> 5660b9567dSKevin Lo 5760b9567dSKevin Lo #include <dev/rtwn/rtl8192e/r92e_priv.h> 5860b9567dSKevin Lo #include <dev/rtwn/rtl8192e/r92e_reg.h> 5960b9567dSKevin Lo #include <dev/rtwn/rtl8192e/r92e_var.h> 6060b9567dSKevin Lo #include <dev/rtwn/rtl8192e/usb/r92eu.h> 6160b9567dSKevin Lo 6260b9567dSKevin Lo #include <dev/rtwn/rtl8812a/usb/r12au.h> 6360b9567dSKevin Lo #include <dev/rtwn/rtl8812a/usb/r12au_tx_desc.h> 6460b9567dSKevin Lo #include <dev/rtwn/rtl8821a/usb/r21au.h> 6560b9567dSKevin Lo 6660b9567dSKevin Lo #include <dev/rtwn/rtl8821a/r21a_reg.h> 6760b9567dSKevin Lo 6860b9567dSKevin Lo void r92eu_attach(struct rtwn_usb_softc *); 6960b9567dSKevin Lo 7060b9567dSKevin Lo static void 7160b9567dSKevin Lo r92eu_attach_private(struct rtwn_softc *sc) 7260b9567dSKevin Lo { 7360b9567dSKevin Lo struct r92e_softc *rs; 7460b9567dSKevin Lo 7560b9567dSKevin Lo rs = malloc(sizeof(struct r92e_softc), M_RTWN_PRIV, M_WAITOK | M_ZERO); 7660b9567dSKevin Lo 7760b9567dSKevin Lo rs->ac_usb_dma_size = 0x06; 7860b9567dSKevin Lo rs->ac_usb_dma_time = 0x20; 7960b9567dSKevin Lo 8060b9567dSKevin Lo sc->sc_priv = rs; 8160b9567dSKevin Lo } 8260b9567dSKevin Lo 8360b9567dSKevin Lo void 8460b9567dSKevin Lo r92e_detach_private(struct rtwn_softc *sc) 8560b9567dSKevin Lo { 8660b9567dSKevin Lo struct r92e_softc *rs = sc->sc_priv; 8760b9567dSKevin Lo 8860b9567dSKevin Lo free(rs, M_RTWN_PRIV); 8960b9567dSKevin Lo } 9060b9567dSKevin Lo 9160b9567dSKevin Lo static void 9260b9567dSKevin Lo r92eu_adj_devcaps(struct rtwn_softc *sc) 9360b9567dSKevin Lo { 9460b9567dSKevin Lo /* XXX TODO? */ 9560b9567dSKevin Lo } 9660b9567dSKevin Lo 9760b9567dSKevin Lo void 9860b9567dSKevin Lo r92eu_attach(struct rtwn_usb_softc *uc) 9960b9567dSKevin Lo { 10060b9567dSKevin Lo struct rtwn_softc *sc = &uc->uc_sc; 10160b9567dSKevin Lo 10260b9567dSKevin Lo /* USB part. */ 10360b9567dSKevin Lo uc->uc_align_rx = r12au_align_rx; 10460b9567dSKevin Lo uc->tx_agg_desc_num = 3; 10560b9567dSKevin Lo 10660b9567dSKevin Lo /* Common part. */ 10760b9567dSKevin Lo sc->sc_flags = RTWN_FLAG_EXT_HDR; 10860b9567dSKevin Lo 10960b9567dSKevin Lo sc->sc_set_chan = r92e_set_chan; 11060b9567dSKevin Lo sc->sc_fill_tx_desc = r12a_fill_tx_desc; 11160b9567dSKevin Lo sc->sc_fill_tx_desc_raw = r12a_fill_tx_desc_raw; 11260b9567dSKevin Lo sc->sc_fill_tx_desc_null = r12a_fill_tx_desc_null; 11360b9567dSKevin Lo sc->sc_dump_tx_desc = r12au_dump_tx_desc; 11460b9567dSKevin Lo sc->sc_tx_radiotap_flags = r12a_tx_radiotap_flags; 11560b9567dSKevin Lo sc->sc_rx_radiotap_flags = r12a_rx_radiotap_flags; 11660b9567dSKevin Lo sc->sc_get_rx_stats = r12a_get_rx_stats; 11760b9567dSKevin Lo sc->sc_get_rssi_cck = r92e_get_rssi_cck; 11860b9567dSKevin Lo sc->sc_get_rssi_ofdm = r88e_get_rssi_ofdm; 11960b9567dSKevin Lo sc->sc_classify_intr = r12au_classify_intr; 12060b9567dSKevin Lo sc->sc_handle_tx_report = r12a_ratectl_tx_complete; 12160b9567dSKevin Lo sc->sc_handle_c2h_report = r92e_handle_c2h_report; 12260b9567dSKevin Lo sc->sc_check_frame = rtwn_nop_int_softc_mbuf; 12360b9567dSKevin Lo sc->sc_rf_read = r92e_rf_read; 12460b9567dSKevin Lo sc->sc_rf_write = r92e_rf_write; 12560b9567dSKevin Lo sc->sc_check_condition = r92c_check_condition; 12660b9567dSKevin Lo sc->sc_efuse_postread = rtwn_nop_softc; 12760b9567dSKevin Lo sc->sc_parse_rom = r92e_parse_rom; 12860b9567dSKevin Lo sc->sc_set_led = r92e_set_led; 12960b9567dSKevin Lo sc->sc_power_on = r92e_power_on; 13060b9567dSKevin Lo sc->sc_power_off = r92e_power_off; 13160b9567dSKevin Lo #ifndef RTWN_WITHOUT_UCODE 13260b9567dSKevin Lo sc->sc_fw_reset = r92e_fw_reset; 13360b9567dSKevin Lo sc->sc_fw_download_enable = r12a_fw_download_enable; 13460b9567dSKevin Lo #endif 13560b9567dSKevin Lo sc->sc_llt_init = r92e_llt_init; 13660b9567dSKevin Lo sc->sc_set_page_size = rtwn_nop_int_softc; 13760b9567dSKevin Lo sc->sc_lc_calib = r92c_lc_calib; 13860b9567dSKevin Lo sc->sc_iq_calib = r88e_iq_calib; /* XXX TODO */ 13960b9567dSKevin Lo sc->sc_read_chipid_vendor = rtwn_nop_softc_uint32; 14060b9567dSKevin Lo sc->sc_adj_devcaps = r92eu_adj_devcaps; 14160b9567dSKevin Lo sc->sc_vap_preattach = rtwn_nop_softc_vap; 14260b9567dSKevin Lo sc->sc_postattach = rtwn_nop_softc; 14360b9567dSKevin Lo sc->sc_detach_private = r92e_detach_private; 14460b9567dSKevin Lo #ifndef RTWN_WITHOUT_UCODE 145*8d4d46ffSAndriy Voskoboinyk sc->sc_set_media_status = r92e_set_media_status; 14660b9567dSKevin Lo sc->sc_set_rsvd_page = r88e_set_rsvd_page; 14760b9567dSKevin Lo sc->sc_set_pwrmode = r92e_set_pwrmode; 14860b9567dSKevin Lo sc->sc_set_rssi = rtwn_nop_softc; /* XXX TODO? */ 149*8d4d46ffSAndriy Voskoboinyk #else 150*8d4d46ffSAndriy Voskoboinyk sc->sc_set_media_status = rtwn_nop_softc_int; 15160b9567dSKevin Lo #endif 15260b9567dSKevin Lo sc->sc_beacon_init = r12a_beacon_init; 15360b9567dSKevin Lo sc->sc_beacon_enable = r92c_beacon_enable; 15460b9567dSKevin Lo sc->sc_beacon_set_rate = rtwn_nop_void_int; 15560b9567dSKevin Lo sc->sc_beacon_select = r21a_beacon_select; 15660b9567dSKevin Lo sc->sc_temp_measure = r88e_temp_measure; 15760b9567dSKevin Lo sc->sc_temp_read = r88e_temp_read; 15860b9567dSKevin Lo sc->sc_init_tx_agg = r21au_init_tx_agg; 15960b9567dSKevin Lo sc->sc_init_rx_agg = r92eu_init_rx_agg; 16060b9567dSKevin Lo sc->sc_init_ampdu = rtwn_nop_softc; 16160b9567dSKevin Lo sc->sc_init_intr = r12a_init_intr; 16260b9567dSKevin Lo sc->sc_init_edca = r92c_init_edca; 16360b9567dSKevin Lo sc->sc_init_bb = r92e_init_bb; 16460b9567dSKevin Lo sc->sc_init_rf = r92e_init_rf; 16560b9567dSKevin Lo sc->sc_init_antsel = rtwn_nop_softc; 16660b9567dSKevin Lo sc->sc_post_init = r92eu_post_init; 16760b9567dSKevin Lo sc->sc_init_bcnq1_boundary = rtwn_nop_int_softc; 16860b9567dSKevin Lo 16960b9567dSKevin Lo sc->mac_prog = &rtl8192eu_mac[0]; 17060b9567dSKevin Lo sc->mac_size = nitems(rtl8192eu_mac); 17160b9567dSKevin Lo sc->bb_prog = &rtl8192eu_bb[0]; 17260b9567dSKevin Lo sc->bb_size = nitems(rtl8192eu_bb); 17360b9567dSKevin Lo sc->agc_prog = &rtl8192eu_agc[0]; 17460b9567dSKevin Lo sc->agc_size = nitems(rtl8192eu_agc); 17560b9567dSKevin Lo sc->rf_prog = &rtl8192eu_rf[0]; 17660b9567dSKevin Lo 17760b9567dSKevin Lo sc->name = "RTL8192EU"; 17860b9567dSKevin Lo sc->fwname = "rtwn-rtl8192eufw"; 17960b9567dSKevin Lo sc->fwsig = 0x92e; 18060b9567dSKevin Lo 18160b9567dSKevin Lo sc->page_count = R92E_TX_PAGE_COUNT; 18260b9567dSKevin Lo sc->pktbuf_count = 0; /* Unused */ 18360b9567dSKevin Lo sc->ackto = 0x40; 18460b9567dSKevin Lo sc->npubqpages = R92E_PUBQ_NPAGES; 18560b9567dSKevin Lo sc->page_size = R92E_TX_PAGE_SIZE; 18660b9567dSKevin Lo sc->txdesc_len = sizeof(struct r12au_tx_desc); 18760b9567dSKevin Lo sc->efuse_maxlen = R92E_EFUSE_MAX_LEN; 18860b9567dSKevin Lo sc->efuse_maplen = R92E_EFUSE_MAP_LEN; 18960b9567dSKevin Lo sc->rx_dma_size = R92E_RX_DMA_BUFFER_SIZE; 19060b9567dSKevin Lo 19160b9567dSKevin Lo sc->macid_limit = R12A_MACID_MAX + 1; 19260b9567dSKevin Lo sc->cam_entry_limit = R12A_CAM_ENTRY_COUNT; 19360b9567dSKevin Lo sc->fwsize_limit = R92E_MAX_FW_SIZE; 19460b9567dSKevin Lo sc->temp_delta = R88E_CALIB_THRESHOLD; 19560b9567dSKevin Lo 19660b9567dSKevin Lo sc->bcn_status_reg[0] = R92C_TDECTRL; 19760b9567dSKevin Lo sc->bcn_status_reg[1] = R21A_DWBCN1_CTRL; 19860b9567dSKevin Lo sc->rcr = 0; 19960b9567dSKevin Lo 20060b9567dSKevin Lo sc->ntxchains = 2; 20160b9567dSKevin Lo sc->nrxchains = 2; 20260b9567dSKevin Lo 20360b9567dSKevin Lo r92eu_attach_private(sc); 20460b9567dSKevin Lo } 205