xref: /freebsd/sys/dev/rtwn/rtl8192e/usb/r92eu_attach.c (revision e32fecd0c2c3ee37c47ee100f169e7eb0282a873)
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 __FBSDID("$FreeBSD$");
19 
20 #include "opt_wlan.h"
21 
22 #include <sys/param.h>
23 #include <sys/lock.h>
24 #include <sys/mutex.h>
25 #include <sys/mbuf.h>
26 #include <sys/kernel.h>
27 #include <sys/socket.h>
28 #include <sys/systm.h>
29 #include <sys/malloc.h>
30 #include <sys/queue.h>
31 #include <sys/taskqueue.h>
32 #include <sys/bus.h>
33 #include <sys/endian.h>
34 #include <sys/linker.h>
35 
36 #include <net/if.h>
37 #include <net/ethernet.h>
38 #include <net/if_media.h>
39 
40 #include <net80211/ieee80211_var.h>
41 #include <net80211/ieee80211_radiotap.h>
42 
43 #include <dev/usb/usb.h>
44 #include <dev/usb/usbdi.h>
45 
46 #include <dev/rtwn/if_rtwnreg.h>
47 #include <dev/rtwn/if_rtwnvar.h>
48 
49 #include <dev/rtwn/if_rtwn_nop.h>
50 
51 #include <dev/rtwn/usb/rtwn_usb_var.h>
52 
53 #include <dev/rtwn/rtl8192c/usb/r92cu.h>
54 
55 #include <dev/rtwn/rtl8188e/r88e.h>
56 
57 #include <dev/rtwn/rtl8192e/r92e_priv.h>
58 #include <dev/rtwn/rtl8192e/r92e_reg.h>
59 #include <dev/rtwn/rtl8192e/r92e_var.h>
60 #include <dev/rtwn/rtl8192e/usb/r92eu.h>
61 
62 #include <dev/rtwn/rtl8812a/usb/r12au.h>
63 #include <dev/rtwn/rtl8812a/usb/r12au_tx_desc.h>
64 #include <dev/rtwn/rtl8821a/usb/r21au.h>
65 
66 #include <dev/rtwn/rtl8821a/r21a_reg.h>
67 
68 void	r92eu_attach(struct rtwn_usb_softc *);
69 
70 static void
71 r92eu_attach_private(struct rtwn_softc *sc)
72 {
73 	struct r92e_softc *rs;
74 
75 	rs = malloc(sizeof(struct r92e_softc), M_RTWN_PRIV, M_WAITOK | M_ZERO);
76 
77 	rs->ac_usb_dma_size		= 0x06;
78 	rs->ac_usb_dma_time             = 0x20;
79 
80 	sc->sc_priv = rs;
81 }
82 
83 void
84 r92e_detach_private(struct rtwn_softc *sc)
85 {
86 	struct r92e_softc *rs = sc->sc_priv;
87 
88 	free(rs, M_RTWN_PRIV);
89 }
90 
91 static void
92 r92eu_adj_devcaps(struct rtwn_softc *sc)
93 {
94 	/* XXX TODO? */
95 }
96 
97 void
98 r92eu_attach(struct rtwn_usb_softc *uc)
99 {
100 	struct rtwn_softc *sc		= &uc->uc_sc;
101 
102 	/* USB part. */
103 	uc->uc_align_rx			= r12au_align_rx;
104 	uc->tx_agg_desc_num		= 3;
105 
106 	/* Common part. */
107 	sc->sc_flags			= RTWN_FLAG_EXT_HDR;
108 
109 	sc->sc_set_chan			= r92e_set_chan;
110 	sc->sc_fill_tx_desc		= r12a_fill_tx_desc;
111 	sc->sc_fill_tx_desc_raw 	= r12a_fill_tx_desc_raw;
112 	sc->sc_fill_tx_desc_null	= r12a_fill_tx_desc_null;
113 	sc->sc_dump_tx_desc		= r12au_dump_tx_desc;
114 	sc->sc_tx_radiotap_flags	= r12a_tx_radiotap_flags;
115 	sc->sc_rx_radiotap_flags	= r12a_rx_radiotap_flags;
116 	sc->sc_get_rx_stats		= r12a_get_rx_stats;
117 	sc->sc_get_rssi_cck		= r92e_get_rssi_cck;
118 	sc->sc_get_rssi_ofdm		= r88e_get_rssi_ofdm;
119 	sc->sc_classify_intr		= r12au_classify_intr;
120 	sc->sc_handle_tx_report		= r12a_ratectl_tx_complete;
121 	sc->sc_handle_c2h_report	= r92e_handle_c2h_report;
122 	sc->sc_check_frame		= rtwn_nop_int_softc_mbuf;
123 	sc->sc_rf_read			= r92e_rf_read;
124 	sc->sc_rf_write			= r92e_rf_write;
125 	sc->sc_check_condition		= r92c_check_condition;
126 	sc->sc_efuse_postread		= rtwn_nop_softc;
127 	sc->sc_parse_rom		= r92e_parse_rom;
128 	sc->sc_set_led			= r92e_set_led;
129 	sc->sc_power_on			= r92e_power_on;
130 	sc->sc_power_off		= r92e_power_off;
131 #ifndef RTWN_WITHOUT_UCODE
132 	sc->sc_fw_reset			= r92e_fw_reset;
133 	sc->sc_fw_download_enable	= r12a_fw_download_enable;
134 #endif
135 	sc->sc_llt_init			= r92e_llt_init;
136 	sc->sc_set_page_size		= rtwn_nop_int_softc;
137 	sc->sc_lc_calib			= r92c_lc_calib;
138 	sc->sc_iq_calib			= rtwn_nop_softc;	/* XXX TODO */
139 	sc->sc_read_chipid_vendor	= rtwn_nop_softc_uint32;
140 	sc->sc_adj_devcaps		= r92eu_adj_devcaps;
141 	sc->sc_vap_preattach		= rtwn_nop_softc_vap;
142 	sc->sc_postattach		= rtwn_nop_softc;
143 	sc->sc_detach_private		= r92e_detach_private;
144 #ifndef RTWN_WITHOUT_UCODE
145 	sc->sc_set_media_status		= r92e_set_media_status;
146 	sc->sc_set_rsvd_page		= r88e_set_rsvd_page;
147 	sc->sc_set_pwrmode		= r92e_set_pwrmode;
148 	sc->sc_set_rssi			= rtwn_nop_softc;	/* XXX TODO? */
149 #else
150 	sc->sc_set_media_status		= rtwn_nop_softc_int;
151 #endif
152 	sc->sc_beacon_init		= r12a_beacon_init;
153 	sc->sc_beacon_enable		= r92c_beacon_enable;
154 	sc->sc_beacon_set_rate		= rtwn_nop_void_int;
155 	sc->sc_beacon_select		= r21a_beacon_select;
156 	sc->sc_temp_measure		= r88e_temp_measure;
157 	sc->sc_temp_read		= r88e_temp_read;
158 	sc->sc_init_tx_agg		= r21au_init_tx_agg;
159 	sc->sc_init_rx_agg		= r92eu_init_rx_agg;
160 	sc->sc_init_ampdu		= rtwn_nop_softc;
161 	sc->sc_init_intr		= r12a_init_intr;
162 	sc->sc_init_edca		= r92c_init_edca;
163 	sc->sc_init_bb			= r92e_init_bb;
164 	sc->sc_init_rf			= r92e_init_rf;
165 	sc->sc_init_antsel		= rtwn_nop_softc;
166 	sc->sc_post_init		= r92eu_post_init;
167 	sc->sc_init_bcnq1_boundary	= rtwn_nop_int_softc;
168 
169 	sc->mac_prog			= &rtl8192eu_mac[0];
170 	sc->mac_size			= nitems(rtl8192eu_mac);
171 	sc->bb_prog			= &rtl8192eu_bb[0];
172 	sc->bb_size			= nitems(rtl8192eu_bb);
173 	sc->agc_prog			= &rtl8192eu_agc[0];
174 	sc->agc_size			= nitems(rtl8192eu_agc);
175 	sc->rf_prog			= &rtl8192eu_rf[0];
176 
177 	sc->name			= "RTL8192EU";
178 	sc->fwname			= "rtwn-rtl8192eufw";
179 	sc->fwsig			= 0x92e;
180 
181 	sc->page_count			= R92E_TX_PAGE_COUNT;
182 	sc->pktbuf_count		= 0;			/* Unused */
183 	sc->ackto			= 0x40;
184 	sc->npubqpages			= R92E_PUBQ_NPAGES;
185 	sc->page_size			= R92E_TX_PAGE_SIZE;
186 	sc->txdesc_len			= sizeof(struct r12au_tx_desc);
187 	sc->efuse_maxlen		= R92E_EFUSE_MAX_LEN;
188 	sc->efuse_maplen		= R92E_EFUSE_MAP_LEN;
189 	sc->rx_dma_size			= R92E_RX_DMA_BUFFER_SIZE;
190 
191 	sc->macid_limit			= R12A_MACID_MAX + 1;
192 	sc->cam_entry_limit		= R12A_CAM_ENTRY_COUNT;
193 	sc->fwsize_limit		= R92E_MAX_FW_SIZE;
194 	sc->temp_delta			= R88E_CALIB_THRESHOLD;
195 
196 	sc->bcn_status_reg[0]		= R92C_TDECTRL;
197 	sc->bcn_status_reg[1]		= R21A_DWBCN1_CTRL;
198 	sc->rcr				= 0;
199 
200 	sc->ntxchains			= 2;
201 	sc->nrxchains			= 2;
202 
203 	r92eu_attach_private(sc);
204 }
205