xref: /freebsd/sys/dev/rtwn/rtl8192c/usb/r92cu_attach.c (revision d93a896ef95946b0bf1219866fcb324b78543444)
1 /*	$OpenBSD: if_urtwn.c,v 1.16 2011/02/10 17:26:40 jakemsr Exp $	*/
2 
3 /*-
4  * Copyright (c) 2010 Damien Bergamini <damien.bergamini@free.fr>
5  * Copyright (c) 2014 Kevin Lo <kevlo@FreeBSD.org>
6  * Copyright (c) 2016 Andriy Voskoboinyk <avos@FreeBSD.org>
7  *
8  * Permission to use, copy, modify, and distribute this software for any
9  * purpose with or without fee is hereby granted, provided that the above
10  * copyright notice and this permission notice appear in all copies.
11  *
12  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
13  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
14  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
15  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
16  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
17  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
18  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19  */
20 
21 #include <sys/cdefs.h>
22 __FBSDID("$FreeBSD$");
23 
24 #include "opt_wlan.h"
25 
26 #include <sys/param.h>
27 #include <sys/lock.h>
28 #include <sys/mutex.h>
29 #include <sys/mbuf.h>
30 #include <sys/kernel.h>
31 #include <sys/socket.h>
32 #include <sys/systm.h>
33 #include <sys/malloc.h>
34 #include <sys/queue.h>
35 #include <sys/taskqueue.h>
36 #include <sys/bus.h>
37 #include <sys/endian.h>
38 #include <sys/linker.h>
39 
40 #include <net/if.h>
41 #include <net/ethernet.h>
42 #include <net/if_media.h>
43 
44 #include <net80211/ieee80211_var.h>
45 #include <net80211/ieee80211_radiotap.h>
46 
47 #include <dev/rtwn/if_rtwnreg.h>
48 #include <dev/rtwn/if_rtwnvar.h>
49 #include <dev/rtwn/if_rtwn_nop.h>
50 
51 #include <dev/rtwn/usb/rtwn_usb_var.h>
52 
53 #include <dev/rtwn/rtl8192c/r92c_var.h>
54 
55 #include <dev/rtwn/rtl8192c/usb/r92cu.h>
56 #include <dev/rtwn/rtl8192c/usb/r92cu_priv.h>
57 #include <dev/rtwn/rtl8192c/usb/r92cu_reg.h>
58 #include <dev/rtwn/rtl8192c/usb/r92cu_tx_desc.h>
59 
60 
61 static struct rtwn_r92c_txpwr r92c_txpwr;
62 
63 void	r92cu_attach(struct rtwn_usb_softc *);
64 
65 static void
66 r92cu_postattach(struct rtwn_softc *sc)
67 {
68 	struct r92c_softc *rs = sc->sc_priv;
69 	struct ieee80211com *ic = &sc->sc_ic;
70 
71 	if (!(rs->chip & R92C_CHIP_92C) &&
72 	    rs->board_type == R92C_BOARD_TYPE_HIGHPA) {
73 		sc->agc_prog = &rtl8188ru_agc[0];
74 		sc->agc_size = nitems(rtl8188ru_agc);
75 		rs->rs_txagc = &rtl8188ru_txagc[0];
76 	} else {
77 		sc->agc_prog = &rtl8192ce_agc[0];
78 		sc->agc_size = nitems(rtl8192ce_agc);
79 		rs->rs_txagc = &rtl8192cu_txagc[0];
80 	}
81 
82 	if ((rs->chip & (R92C_CHIP_UMC_A_CUT | R92C_CHIP_92C)) ==
83 		    R92C_CHIP_UMC_A_CUT) {
84 		sc->fwname = "rtwn-rtl8192cfwU";
85 	} else {
86 		sc->fwname = "rtwn-rtl8192cfwT";
87 	}
88 	sc->fwsig = 0x88c;
89 
90 	rs->rs_scan_start = ic->ic_scan_start;
91 	ic->ic_scan_start = r92c_scan_start;
92 	rs->rs_scan_end = ic->ic_scan_end;
93 	ic->ic_scan_end = r92c_scan_end;
94 }
95 
96 static void
97 r92cu_set_name(struct rtwn_softc *sc)
98 {
99 	struct r92c_softc *rs = sc->sc_priv;
100 
101 	if (!(rs->chip & R92C_CHIP_92C)) {
102 		if (rs->board_type == R92C_BOARD_TYPE_HIGHPA)
103 			sc->name = "RTL8188RU";
104 		else if (rs->board_type == R92C_BOARD_TYPE_MINICARD)
105 			sc->name = "RTL8188CU-VAU";
106 		else
107 			sc->name = "RTL8188CUS";
108 	} else
109 		sc->name = "RTL8192CU";
110 }
111 
112 static void
113 r92cu_attach_private(struct rtwn_softc *sc)
114 {
115 	struct r92c_softc *rs;
116 
117 	rs = malloc(sizeof(struct r92c_softc), M_RTWN_PRIV, M_WAITOK | M_ZERO);
118 
119 	rs->rs_txpwr			= &r92c_txpwr;
120 
121 	rs->rs_set_bw20			= r92c_set_bw20;
122 	rs->rs_get_txpower		= r92c_get_txpower;
123 	rs->rs_set_gain			= r92c_set_gain;
124 	rs->rs_tx_enable_ampdu		= r92c_tx_enable_ampdu;
125 	rs->rs_tx_setup_hwseq		= r92c_tx_setup_hwseq;
126 	rs->rs_tx_setup_macid		= r92c_tx_setup_macid;
127 	rs->rs_set_name			= r92cu_set_name;
128 
129 #ifndef RTWN_WITHOUT_UCODE
130 	rs->rs_c2h_timeout		= hz;
131 
132 	callout_init_mtx(&rs->rs_c2h_report, &sc->sc_mtx, 0);
133 #endif
134 
135 	rs->rf_read_delay[0]		= 10;
136 	rs->rf_read_delay[1]		= 100;
137 	rs->rf_read_delay[2]		= 10;
138 
139 	sc->sc_priv = rs;
140 }
141 
142 static void
143 r92cu_adj_devcaps(struct rtwn_softc *sc)
144 {
145 	/* XXX Currently broken / incomplete. */
146 	sc->sc_ic.ic_caps &= ~IEEE80211_C_PMGT;
147 }
148 
149 void
150 r92cu_attach(struct rtwn_usb_softc *uc)
151 {
152 	struct rtwn_softc *sc		= &uc->uc_sc;
153 
154 	/* USB part. */
155 	uc->uc_align_rx			= r92cu_align_rx;
156 	uc->tx_agg_desc_num		= 6;
157 
158 	/* Common part. */
159 	sc->sc_flags			= RTWN_FLAG_CAM_FIXED;
160 
161 	sc->sc_set_chan			= r92c_set_chan;
162 	sc->sc_fill_tx_desc		= r92c_fill_tx_desc;
163 	sc->sc_fill_tx_desc_raw 	= r92c_fill_tx_desc_raw;
164 	sc->sc_fill_tx_desc_null	= r92c_fill_tx_desc_null;
165 	sc->sc_dump_tx_desc		= r92cu_dump_tx_desc;
166 	sc->sc_tx_radiotap_flags	= r92c_tx_radiotap_flags;
167 	sc->sc_rx_radiotap_flags	= r92c_rx_radiotap_flags;
168 	sc->sc_get_rx_stats		= r92c_get_rx_stats;
169 	sc->sc_get_rssi_cck		= r92c_get_rssi_cck;
170 	sc->sc_get_rssi_ofdm		= r92c_get_rssi_ofdm;
171 	sc->sc_classify_intr		= r92cu_classify_intr;
172 	sc->sc_handle_tx_report		= rtwn_nop_softc_uint8_int;
173 	sc->sc_handle_c2h_report	= rtwn_nop_softc_uint8_int;
174 	sc->sc_check_frame		= rtwn_nop_int_softc_mbuf;
175 	sc->sc_rf_read			= r92c_rf_read;
176 	sc->sc_rf_write			= r92c_rf_write;
177 	sc->sc_check_condition		= r92c_check_condition;
178 	sc->sc_efuse_postread		= r92c_efuse_postread;
179 	sc->sc_parse_rom		= r92c_parse_rom;
180 	sc->sc_set_led			= r92cu_set_led;
181 	sc->sc_power_on			= r92cu_power_on;
182 	sc->sc_power_off		= r92cu_power_off;
183 #ifndef RTWN_WITHOUT_UCODE
184 	sc->sc_fw_reset			= r92c_fw_reset;
185 	sc->sc_fw_download_enable	= r92c_fw_download_enable;
186 #endif
187 	sc->sc_llt_init			= r92c_llt_init;
188 	sc->sc_set_page_size		= r92c_set_page_size;
189 	sc->sc_lc_calib			= r92c_lc_calib;
190 	sc->sc_iq_calib			= r92c_iq_calib;	/* XXX TODO */
191 	sc->sc_read_chipid_vendor	= r92c_read_chipid_vendor;
192 	sc->sc_adj_devcaps		= r92cu_adj_devcaps;
193 	sc->sc_vap_preattach		= rtwn_nop_softc_vap;
194 	sc->sc_postattach		= r92cu_postattach;
195 	sc->sc_detach_private		= r92c_detach_private;
196 	sc->sc_set_media_status		= r92c_joinbss_rpt;
197 #ifndef RTWN_WITHOUT_UCODE
198 	sc->sc_set_rsvd_page		= r92c_set_rsvd_page;
199 	sc->sc_set_pwrmode		= r92c_set_pwrmode;
200 	sc->sc_set_rssi			= r92c_set_rssi;
201 #endif
202 	sc->sc_beacon_init		= r92c_beacon_init;
203 	sc->sc_beacon_enable		= r92c_beacon_enable;
204 	sc->sc_beacon_set_rate		= rtwn_nop_void_int;
205 	sc->sc_beacon_select		= rtwn_nop_softc_int;
206 	sc->sc_temp_measure		= r92c_temp_measure;
207 	sc->sc_temp_read		= r92c_temp_read;
208 	sc->sc_init_tx_agg		= r92cu_init_tx_agg;
209 	sc->sc_init_rx_agg		= r92cu_init_rx_agg;
210 	sc->sc_init_ampdu		= r92c_init_ampdu;
211 	sc->sc_init_intr		= r92cu_init_intr;
212 	sc->sc_init_edca		= r92c_init_edca;
213 	sc->sc_init_bb			= r92cu_init_bb;
214 	sc->sc_init_rf			= r92c_init_rf;
215 	sc->sc_init_antsel		= r92c_init_antsel;
216 	sc->sc_post_init		= r92cu_post_init;
217 	sc->sc_init_bcnq1_boundary	= rtwn_nop_int_softc;
218 
219 	sc->mac_prog			= &rtl8192cu_mac[0];
220 	sc->mac_size			= nitems(rtl8192cu_mac);
221 	sc->bb_prog			= &rtl8192cu_bb[0];
222 	sc->bb_size			= nitems(rtl8192cu_bb);
223 	sc->rf_prog			= &rtl8192c_rf[0];
224 
225 	sc->page_count			= R92CU_TX_PAGE_COUNT;
226 	sc->pktbuf_count		= R92C_TXPKTBUF_COUNT;
227 
228 	sc->ackto			= 0x40;
229 	sc->npubqpages			= R92CU_PUBQ_NPAGES;
230 	sc->page_size			= R92C_TX_PAGE_SIZE;
231 
232 	sc->txdesc_len			= sizeof(struct r92cu_tx_desc);
233 	sc->efuse_maxlen		= R92C_EFUSE_MAX_LEN;
234 	sc->efuse_maplen		= R92C_EFUSE_MAP_LEN;
235 	sc->rx_dma_size			= R92C_RX_DMA_BUFFER_SIZE;
236 
237 	sc->macid_limit			= R92C_MACID_MAX + 1;
238 	sc->cam_entry_limit		= R92C_CAM_ENTRY_COUNT;
239 	sc->fwsize_limit		= R92C_MAX_FW_SIZE;
240 	sc->temp_delta			= R92C_CALIB_THRESHOLD;
241 
242 	sc->bcn_status_reg[0]		= R92C_TDECTRL;
243 	sc->bcn_status_reg[1]		= R92C_TDECTRL;
244 	sc->rcr				= 0;
245 
246 	r92cu_attach_private(sc);
247 }
248