1 /*-
2 * Copyright (c) 2017 Kevin Lo <kevlo@FreeBSD.org>
3 *
4 * Permission to use, copy, modify, and distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 */
16
17 #include <sys/cdefs.h>
18 #include "opt_wlan.h"
19
20 #include <sys/param.h>
21 #include <sys/lock.h>
22 #include <sys/mutex.h>
23 #include <sys/mbuf.h>
24 #include <sys/kernel.h>
25 #include <sys/socket.h>
26 #include <sys/systm.h>
27 #include <sys/malloc.h>
28 #include <sys/queue.h>
29 #include <sys/taskqueue.h>
30 #include <sys/bus.h>
31 #include <sys/endian.h>
32 #include <sys/linker.h>
33
34 #include <net/if.h>
35 #include <net/ethernet.h>
36 #include <net/if_media.h>
37
38 #include <net80211/ieee80211_var.h>
39 #include <net80211/ieee80211_radiotap.h>
40
41 #include <dev/usb/usb.h>
42 #include <dev/usb/usbdi.h>
43
44 #include <dev/rtwn/if_rtwnreg.h>
45 #include <dev/rtwn/if_rtwnvar.h>
46
47 #include <dev/rtwn/if_rtwn_nop.h>
48
49 #include <dev/rtwn/usb/rtwn_usb_var.h>
50
51 #include <dev/rtwn/rtl8192c/usb/r92cu.h>
52
53 #include <dev/rtwn/rtl8188e/r88e.h>
54
55 #include <dev/rtwn/rtl8192e/r92e_priv.h>
56 #include <dev/rtwn/rtl8192e/r92e_reg.h>
57 #include <dev/rtwn/rtl8192e/r92e_var.h>
58 #include <dev/rtwn/rtl8192e/usb/r92eu.h>
59
60 #include <dev/rtwn/rtl8812a/usb/r12au.h>
61 #include <dev/rtwn/rtl8812a/usb/r12au_tx_desc.h>
62 #include <dev/rtwn/rtl8821a/usb/r21au.h>
63
64 #include <dev/rtwn/rtl8821a/r21a_reg.h>
65
66 void r92eu_attach(struct rtwn_usb_softc *);
67
68 static void
r92eu_attach_private(struct rtwn_softc * sc)69 r92eu_attach_private(struct rtwn_softc *sc)
70 {
71 struct r92e_softc *rs;
72
73 rs = malloc(sizeof(struct r92e_softc), M_RTWN_PRIV, M_WAITOK | M_ZERO);
74
75 rs->ac_usb_dma_size = 0x06;
76 rs->ac_usb_dma_time = 0x20;
77
78 sc->sc_priv = rs;
79 }
80
81 void
r92e_detach_private(struct rtwn_softc * sc)82 r92e_detach_private(struct rtwn_softc *sc)
83 {
84 struct r92e_softc *rs = sc->sc_priv;
85
86 free(rs, M_RTWN_PRIV);
87 }
88
89 static void
r92eu_adj_devcaps(struct rtwn_softc * sc)90 r92eu_adj_devcaps(struct rtwn_softc *sc)
91 {
92 /* XXX TODO? */
93 }
94
95 void
r92eu_attach(struct rtwn_usb_softc * uc)96 r92eu_attach(struct rtwn_usb_softc *uc)
97 {
98 struct rtwn_softc *sc = &uc->uc_sc;
99
100 /* USB part. */
101 uc->uc_align_rx = r12au_align_rx;
102 uc->tx_agg_desc_num = 3;
103
104 /* Common part. */
105 sc->sc_flags = RTWN_FLAG_EXT_HDR;
106
107 sc->sc_set_chan = r92e_set_chan;
108 sc->sc_fill_tx_desc = r12a_fill_tx_desc;
109 sc->sc_fill_tx_desc_raw = r12a_fill_tx_desc_raw;
110 sc->sc_fill_tx_desc_null = r12a_fill_tx_desc_null;
111 sc->sc_dump_tx_desc = r12au_dump_tx_desc;
112 sc->sc_tx_radiotap_flags = r12a_tx_radiotap_flags;
113 sc->sc_rx_radiotap_flags = r12a_rx_radiotap_flags;
114 sc->sc_get_rx_stats = r12a_get_rx_stats;
115 sc->sc_get_rssi_cck = r92e_get_rssi_cck;
116 sc->sc_get_rssi_ofdm = r88e_get_rssi_ofdm;
117 sc->sc_classify_intr = r12au_classify_intr;
118 sc->sc_handle_tx_report = r12a_ratectl_tx_complete;
119 sc->sc_handle_c2h_report = r92e_handle_c2h_report;
120 sc->sc_check_frame = rtwn_nop_int_softc_mbuf;
121 sc->sc_rf_read = r92e_rf_read;
122 sc->sc_rf_write = r92e_rf_write;
123 sc->sc_check_condition = r92c_check_condition;
124 sc->sc_efuse_postread = rtwn_nop_softc;
125 sc->sc_parse_rom = r92e_parse_rom;
126 sc->sc_set_led = r92e_set_led;
127 sc->sc_power_on = r92e_power_on;
128 sc->sc_power_off = r92e_power_off;
129 #ifndef RTWN_WITHOUT_UCODE
130 sc->sc_fw_reset = r92e_fw_reset;
131 sc->sc_fw_download_enable = r12a_fw_download_enable;
132 #endif
133 sc->sc_llt_init = r92e_llt_init;
134 sc->sc_set_page_size = rtwn_nop_int_softc;
135 sc->sc_lc_calib = r92c_lc_calib;
136 sc->sc_iq_calib = rtwn_nop_softc; /* XXX TODO */
137 sc->sc_read_chipid_vendor = rtwn_nop_softc_uint32;
138 sc->sc_adj_devcaps = r92eu_adj_devcaps;
139 sc->sc_vap_preattach = rtwn_nop_softc_vap;
140 sc->sc_postattach = rtwn_nop_softc;
141 sc->sc_detach_private = r92e_detach_private;
142 #ifndef RTWN_WITHOUT_UCODE
143 sc->sc_set_media_status = r92e_set_media_status;
144 sc->sc_set_rsvd_page = r88e_set_rsvd_page;
145 sc->sc_set_pwrmode = r92e_set_pwrmode;
146 sc->sc_set_rssi = rtwn_nop_softc; /* XXX TODO? */
147 #else
148 sc->sc_set_media_status = rtwn_nop_softc_int;
149 #endif
150 sc->sc_beacon_init = r12a_beacon_init;
151 sc->sc_beacon_enable = r92c_beacon_enable;
152 sc->sc_beacon_set_rate = rtwn_nop_void_int;
153 sc->sc_beacon_select = r21a_beacon_select;
154 sc->sc_temp_measure = r88e_temp_measure;
155 sc->sc_temp_read = r88e_temp_read;
156 sc->sc_init_tx_agg = r21au_init_tx_agg;
157 sc->sc_init_rx_agg = r92eu_init_rx_agg;
158 sc->sc_init_ampdu = rtwn_nop_softc;
159 sc->sc_init_intr = r12a_init_intr;
160 sc->sc_init_edca = r92c_init_edca;
161 sc->sc_init_bb = r92e_init_bb;
162 sc->sc_init_rf = r92e_init_rf;
163 sc->sc_init_antsel = rtwn_nop_softc;
164 sc->sc_post_init = r92eu_post_init;
165 sc->sc_init_bcnq1_boundary = rtwn_nop_int_softc;
166
167 sc->mac_prog = &rtl8192eu_mac[0];
168 sc->mac_size = nitems(rtl8192eu_mac);
169 sc->bb_prog = &rtl8192eu_bb[0];
170 sc->bb_size = nitems(rtl8192eu_bb);
171 sc->agc_prog = &rtl8192eu_agc[0];
172 sc->agc_size = nitems(rtl8192eu_agc);
173 sc->rf_prog = &rtl8192eu_rf[0];
174
175 sc->name = "RTL8192EU";
176 sc->fwname = "rtwn-rtl8192eufw";
177 sc->fwsig = 0x92e;
178
179 sc->page_count = R92E_TX_PAGE_COUNT;
180 sc->pktbuf_count = 0; /* Unused */
181 sc->ackto = 0x40;
182 sc->npubqpages = R92E_PUBQ_NPAGES;
183 sc->page_size = R92E_TX_PAGE_SIZE;
184 sc->txdesc_len = sizeof(struct r12au_tx_desc);
185 sc->efuse_maxlen = R92E_EFUSE_MAX_LEN;
186 sc->efuse_maplen = R92E_EFUSE_MAP_LEN;
187 sc->rx_dma_size = R92E_RX_DMA_BUFFER_SIZE;
188
189 sc->macid_limit = R12A_MACID_MAX + 1;
190 sc->cam_entry_limit = R12A_CAM_ENTRY_COUNT;
191 sc->fwsize_limit = R92E_MAX_FW_SIZE;
192 sc->temp_delta = R88E_CALIB_THRESHOLD;
193
194 sc->bcn_status_reg[0] = R92C_TDECTRL;
195 sc->bcn_status_reg[1] = R21A_DWBCN1_CTRL;
196 sc->rcr = 0;
197
198 sc->ntxchains = 2;
199 sc->nrxchains = 2;
200
201 r92eu_attach_private(sc);
202 }
203