xref: /freebsd/sys/dev/rtwn/rtl8188e/usb/r88eu_attach.c (revision 5e386598a6d77973b93c073080f0cc574edda9e2)
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) 2015-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_reg.h>
54 #include <dev/rtwn/rtl8192c/r92c_var.h>
55 
56 #include <dev/rtwn/rtl8192c/usb/r92cu.h>
57 #include <dev/rtwn/rtl8192c/usb/r92cu_tx_desc.h>
58 
59 #include <dev/rtwn/rtl8188e/r88e_priv.h>
60 
61 #include <dev/rtwn/rtl8188e/usb/r88eu.h>
62 
63 
64 static struct rtwn_r88e_txpwr r88e_txpwr;
65 
66 void	r88eu_attach(struct rtwn_usb_softc *);
67 
68 static void
69 r88e_postattach(struct rtwn_softc *sc)
70 {
71 	struct r92c_softc *rs = sc->sc_priv;
72 	struct ieee80211com *ic = &sc->sc_ic;
73 
74 	rs->rs_scan_start = ic->ic_scan_start;
75 	ic->ic_scan_start = r92c_scan_start;
76 	rs->rs_scan_end = ic->ic_scan_end;
77 	ic->ic_scan_end = r92c_scan_end;
78 }
79 
80 static void
81 r88eu_attach_private(struct rtwn_softc *sc)
82 {
83 	struct r92c_softc *rs;
84 
85 	rs = malloc(sizeof(struct r92c_softc), M_RTWN_PRIV, M_WAITOK | M_ZERO);
86 
87 	rs->rs_txpwr			= &r88e_txpwr;
88 	rs->rs_txagc			= &r88e_txagc;
89 
90 	rs->rs_set_bw20			= r88e_set_bw20;
91 	rs->rs_get_txpower		= r88e_get_txpower;
92 	rs->rs_set_gain			= r88e_set_gain;
93 	rs->rs_tx_enable_ampdu		= r88e_tx_enable_ampdu;
94 	rs->rs_tx_setup_hwseq		= r88e_tx_setup_hwseq;
95 	rs->rs_tx_setup_macid		= r88e_tx_setup_macid;
96 	rs->rs_set_name			= rtwn_nop_softc;	/* not used */
97 
98 	rs->rf_read_delay[0]		= 10;
99 	rs->rf_read_delay[1]		= 100;
100 	rs->rf_read_delay[2]		= 10;
101 
102 	sc->sc_priv = rs;
103 }
104 
105 static void
106 r88eu_adj_devcaps(struct rtwn_softc *sc)
107 {
108 	/* XXX TODO? */
109 }
110 
111 void
112 r88eu_attach(struct rtwn_usb_softc *uc)
113 {
114 	struct rtwn_softc *sc		= &uc->uc_sc;
115 
116 	/* USB part. */
117 	uc->uc_align_rx			= r92cu_align_rx;
118 	uc->tx_agg_desc_num		= 6;
119 
120 	/* Common part. */
121 	sc->sc_flags			= RTWN_FLAG_EXT_HDR;
122 
123 	sc->sc_set_chan			= r92c_set_chan;
124 	sc->sc_fill_tx_desc		= r92c_fill_tx_desc;
125 	sc->sc_fill_tx_desc_raw 	= r92c_fill_tx_desc_raw;
126 	sc->sc_fill_tx_desc_null	= r92c_fill_tx_desc_null;
127 	sc->sc_dump_tx_desc		= r92cu_dump_tx_desc;
128 	sc->sc_tx_radiotap_flags	= r92c_tx_radiotap_flags;
129 	sc->sc_rx_radiotap_flags	= r92c_rx_radiotap_flags;
130 	sc->sc_get_rx_stats		= r88e_get_rx_stats;
131 	sc->sc_get_rssi_cck		= r88e_get_rssi_cck;
132 	sc->sc_get_rssi_ofdm		= r88e_get_rssi_ofdm;
133 	sc->sc_classify_intr		= r88eu_classify_intr;
134 	sc->sc_handle_tx_report		= r88e_ratectl_tx_complete;
135 	sc->sc_handle_c2h_report	= r88e_handle_c2h_report;
136 	sc->sc_check_frame		= rtwn_nop_int_softc_mbuf;
137 	sc->sc_rf_read			= r92c_rf_read;
138 	sc->sc_rf_write			= r88e_rf_write;
139 	sc->sc_check_condition		= r92c_check_condition;
140 	sc->sc_efuse_postread		= rtwn_nop_softc;
141 	sc->sc_parse_rom		= r88e_parse_rom;
142 	sc->sc_set_led			= r88e_set_led;
143 	sc->sc_power_on			= r88e_power_on;
144 	sc->sc_power_off		= r88eu_power_off;
145 #ifndef RTWN_WITHOUT_UCODE
146 	sc->sc_fw_reset			= r88e_fw_reset;
147 	sc->sc_fw_download_enable	= r88e_fw_download_enable;
148 #endif
149 	sc->sc_llt_init			= r92c_llt_init;
150 	sc->sc_set_page_size		= r92c_set_page_size;
151 	sc->sc_lc_calib			= r92c_lc_calib;
152 	sc->sc_iq_calib			= r88e_iq_calib;	/* XXX TODO */
153 	sc->sc_read_chipid_vendor	= rtwn_nop_softc_uint32;
154 	sc->sc_adj_devcaps		= r88eu_adj_devcaps;
155 	sc->sc_vap_preattach		= rtwn_nop_softc_vap;
156 	sc->sc_postattach		= r88e_postattach;
157 	sc->sc_detach_private		= r92c_detach_private;
158 	sc->sc_set_media_status		= r88e_set_media_status;
159 #ifndef RTWN_WITHOUT_UCODE
160 	sc->sc_set_rsvd_page		= r88e_set_rsvd_page;
161 	sc->sc_set_pwrmode		= r88e_set_pwrmode;
162 	sc->sc_set_rssi			= rtwn_nop_softc;	/* XXX TODO? */
163 #endif
164 	sc->sc_beacon_init		= r92c_beacon_init;
165 	sc->sc_beacon_enable		= r88e_beacon_enable;
166 	sc->sc_beacon_set_rate		= rtwn_nop_void_int;
167 	sc->sc_beacon_select		= rtwn_nop_softc_int;
168 	sc->sc_temp_measure		= r88e_temp_measure;
169 	sc->sc_temp_read		= r88e_temp_read;
170 	sc->sc_init_tx_agg		= r92cu_init_tx_agg;
171 	sc->sc_init_rx_agg		= r88eu_init_rx_agg;
172 	sc->sc_init_ampdu		= rtwn_nop_softc;
173 	sc->sc_init_intr		= r88eu_init_intr;
174 	sc->sc_init_edca		= r92c_init_edca;
175 	sc->sc_init_bb			= r88e_init_bb;
176 	sc->sc_init_rf			= r92c_init_rf;
177 	sc->sc_init_antsel		= rtwn_nop_softc;
178 	sc->sc_post_init		= r88eu_post_init;
179 	sc->sc_init_bcnq1_boundary	= rtwn_nop_int_softc;
180 
181 	sc->mac_prog			= &rtl8188eu_mac[0];
182 	sc->mac_size			= nitems(rtl8188eu_mac);
183 	sc->bb_prog			= &rtl8188eu_bb[0];
184 	sc->bb_size			= nitems(rtl8188eu_bb);
185 	sc->agc_prog			= &rtl8188eu_agc[0];
186 	sc->agc_size			= nitems(rtl8188eu_agc);
187 	sc->rf_prog			= &rtl8188eu_rf[0];
188 
189 	sc->name			= "RTL8188EU";
190 	sc->fwname			= "rtwn-rtl8188eufw";
191 	sc->fwsig			= 0x88e;
192 
193 	sc->page_count			= R88E_TX_PAGE_COUNT;
194 	sc->pktbuf_count		= R88E_TXPKTBUF_COUNT;
195 
196 	sc->ackto			= 0x40;
197 	sc->npubqpages			= R88E_PUBQ_NPAGES;
198 	sc->page_size			= R92C_TX_PAGE_SIZE;
199 
200 	sc->txdesc_len			= sizeof(struct r92cu_tx_desc);
201 	sc->efuse_maxlen		= R88E_EFUSE_MAX_LEN;
202 	sc->efuse_maplen		= R88E_EFUSE_MAP_LEN;
203 	sc->rx_dma_size			= R88E_RX_DMA_BUFFER_SIZE;
204 
205 	sc->macid_limit			= R88E_MACID_MAX + 1;
206 	sc->cam_entry_limit		= R92C_CAM_ENTRY_COUNT;
207 	sc->fwsize_limit		= R92C_MAX_FW_SIZE;
208 	sc->temp_delta			= R88E_CALIB_THRESHOLD;
209 
210 	sc->bcn_status_reg[0]		= R92C_TDECTRL;
211 	sc->bcn_status_reg[1]		= R92C_TDECTRL;
212 	sc->rcr				= 0;
213 
214 	sc->ntxchains			= 1;
215 	sc->nrxchains			= 1;
216 
217 	r88eu_attach_private(sc);
218 }
219