xref: /freebsd/sys/dev/rtwn/rtl8188e/pci/r88ee_attach.c (revision d0b2dbfa0ecf2bbc9709efc5e20baf8e4b44bbbf)
1 /*-
2  * Copyright (c) 2018 Farhan Khan <khanzf@gmail.com>
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 <machine/bus.h>
35 #include <machine/resource.h>
36 #include <sys/rman.h>
37 
38 #include <net/if.h>
39 #include <net/ethernet.h>
40 #include <net/if_media.h>
41 
42 #include <net80211/ieee80211_var.h>
43 #include <net80211/ieee80211_radiotap.h>
44 
45 #include <dev/rtwn/if_rtwnreg.h>
46 #include <dev/rtwn/if_rtwnvar.h>
47 #include <dev/rtwn/if_rtwn_nop.h>
48 
49 #include <dev/rtwn/pci/rtwn_pci_var.h>
50 
51 #include <dev/rtwn/rtl8192c/r92c_var.h>
52 
53 #include <dev/rtwn/rtl8188e/r88e_priv.h>
54 #include <dev/rtwn/rtl8188e/r88e_rom_image.h>	/* for 'macaddr' field */
55 
56 #include <dev/rtwn/rtl8192c/pci/r92ce.h>
57 #include <dev/rtwn/rtl8192c/pci/r92ce_tx_desc.h>
58 
59 #include <dev/rtwn/rtl8188e/pci/r88ee.h>
60 #include <dev/rtwn/rtl8188e/pci/r88ee_reg.h>
61 
62 static struct rtwn_r88e_txpwr r88ee_txpwr;
63 
64 void	r88ee_attach(struct rtwn_pci_softc *);
65 
66 static void
67 r88ee_set_macaddr(struct rtwn_softc *sc, uint8_t *buf)
68 {
69 	struct r88e_rom *rom = (struct r88e_rom *)buf;
70 
71 	IEEE80211_ADDR_COPY(sc->sc_ic.ic_macaddr, rom->diff_d0.pci.macaddr);
72 }
73 
74 static void
75 r88ee_postattach(struct rtwn_softc *sc)
76 {
77 	struct r92c_softc *rs = sc->sc_priv;
78 	struct ieee80211com *ic = &sc->sc_ic;
79 
80 	rs->rs_scan_start = ic->ic_scan_start;
81 	ic->ic_scan_start = r92c_scan_start;
82 	rs->rs_scan_end = ic->ic_scan_end;
83 	ic->ic_scan_end = r92c_scan_end;
84 }
85 
86 static void
87 r88ee_attach_private(struct rtwn_softc *sc)
88 {
89 	struct r92c_softc *rs;
90 
91 	rs = malloc(sizeof(struct r92c_softc), M_RTWN_PRIV, M_WAITOK | M_ZERO);
92 
93 	rs->rs_txpwr			= &r88ee_txpwr;
94 
95 	rs->rs_set_bw20			= r88e_set_bw20;
96 	rs->rs_get_txpower		= r88e_get_txpower;
97 	rs->rs_set_gain			= r88e_set_gain;
98 	rs->rs_tx_enable_ampdu		= r88e_tx_enable_ampdu;
99 	rs->rs_tx_setup_hwseq		= r88e_tx_setup_hwseq;
100 	rs->rs_tx_setup_macid		= r88e_tx_setup_macid;
101 	rs->rs_set_rom_opts		= r88ee_set_macaddr;
102 
103 	rs->rf_read_delay[0]		= 1000;
104 	rs->rf_read_delay[1]		= 1000;
105 	rs->rf_read_delay[2]		= 1000;
106 
107 	sc->sc_priv = rs;
108 
109 }
110 
111 static void
112 r88ee_adj_devcaps(struct rtwn_softc *sc)
113 {
114 	/* XXX TODO */
115 }
116 
117 void
118 r88ee_attach(struct rtwn_pci_softc *pc)
119 {
120 	struct rtwn_softc *sc		= &pc->pc_sc;
121 
122 	/* PCIe part. */
123 	pc->pc_setup_tx_desc		= r92ce_setup_tx_desc;
124 	pc->pc_tx_postsetup		= r92ce_tx_postsetup;
125 	pc->pc_copy_tx_desc		= r92ce_copy_tx_desc;
126 	pc->pc_enable_intr		= r88ee_enable_intr;
127 	pc->pc_get_intr_status		= r88ee_get_intr_status;
128 
129 	pc->pc_qmap			= 0xe771;
130 	pc->tcr				= 0x8200;
131 
132 	/* Common part. */
133 	sc->sc_flags			= RTWN_FLAG_EXT_HDR;
134 
135 	sc->sc_start_xfers		= r88ee_start_xfers;
136 	sc->sc_set_chan			= r92c_set_chan;
137 	sc->sc_fill_tx_desc		= r92c_fill_tx_desc;
138 	sc->sc_fill_tx_desc_raw		= r92c_fill_tx_desc_raw;
139 	sc->sc_fill_tx_desc_null	= r92c_fill_tx_desc_null; /* XXX recheck */
140 	sc->sc_dump_tx_desc		= r92ce_dump_tx_desc;
141 	sc->sc_tx_radiotap_flags	= r92c_tx_radiotap_flags;
142 	sc->sc_rx_radiotap_flags	= r92c_rx_radiotap_flags;
143 	sc->sc_get_rx_stats		= r88e_get_rx_stats;
144 	sc->sc_get_rssi_cck		= r88e_get_rssi_cck;
145 	sc->sc_get_rssi_ofdm		= r88e_get_rssi_ofdm;
146 	sc->sc_classify_intr		= r88e_classify_intr;
147 	sc->sc_handle_tx_report		= r88e_ratectl_tx_complete;
148 	sc->sc_handle_c2h_report	= r88e_handle_c2h_report;
149 	sc->sc_check_frame		= rtwn_nop_int_softc_mbuf;
150 	sc->sc_rf_read			= r92c_rf_read;
151 	sc->sc_rf_write			= r88e_rf_write;
152 	sc->sc_check_condition		= r92c_check_condition;
153 	sc->sc_efuse_postread		= rtwn_nop_softc;
154 	sc->sc_parse_rom		= r88e_parse_rom;
155 	sc->sc_set_led			= r88e_set_led;
156 	sc->sc_power_on			= r88ee_power_on;
157 	sc->sc_power_off		= r88ee_power_off;
158 #ifndef RTWN_WITHOUT_UCODE
159 	sc->sc_fw_reset			= r88e_fw_reset;
160 	sc->sc_fw_download_enable	= r88e_fw_download_enable;
161 #endif
162 	sc->sc_llt_init			= r92c_llt_init;
163 	sc->sc_set_page_size		= r92c_set_page_size;
164 	sc->sc_lc_calib			= r92c_lc_calib;
165 	sc->sc_iq_calib			= r88e_iq_calib;
166 	sc->sc_read_chipid_vendor	= rtwn_nop_softc_uint32;
167 	sc->sc_adj_devcaps		= r88ee_adj_devcaps;
168 	sc->sc_vap_preattach		= rtwn_nop_softc_vap;
169 	sc->sc_postattach		= r88ee_postattach;
170 	sc->sc_detach_private		= r92c_detach_private;
171 	sc->sc_set_media_status		= r88e_set_media_status;
172 #ifndef RTWN_WITHOUT_UCODE
173 	sc->sc_set_rsvd_page		= r88e_set_rsvd_page;
174 	sc->sc_set_pwrmode		= r88e_set_pwrmode;
175 	sc->sc_set_rssi			= r92c_set_rssi;
176 #endif
177 	sc->sc_beacon_init		= r92c_beacon_init;
178 	sc->sc_beacon_enable		= r88e_beacon_enable;
179 	sc->sc_beacon_set_rate		= rtwn_nop_void_int;
180 	sc->sc_beacon_select		= rtwn_nop_softc_int;
181 	sc->sc_temp_measure		= r88e_temp_measure;
182 	sc->sc_temp_read		= r88e_temp_read;
183 	sc->sc_init_tx_agg		= rtwn_nop_softc;
184 	sc->sc_init_rx_agg		= rtwn_nop_softc;
185 	sc->sc_init_ampdu		= r92ce_init_ampdu;
186 	sc->sc_init_intr		= r88ee_init_intr;
187 	sc->sc_init_edca		= r92ce_init_edca;
188 	sc->sc_init_bb			= r88ee_init_bb;
189 	sc->sc_init_rf			= r92c_init_rf;
190 	sc->sc_init_antsel		= rtwn_nop_softc;
191 	sc->sc_post_init		= r88ee_post_init;
192 	sc->sc_init_bcnq1_boundary	= rtwn_nop_int_softc;
193 
194 	sc->mac_prog			= &rtl8188e_mac[0];
195 	sc->mac_size			= nitems(rtl8188e_mac);
196 	sc->bb_prog			= &rtl8188e_bb[0];
197 	sc->bb_size			= nitems(rtl8188e_bb);
198 	sc->agc_prog			= &rtl8188e_agc[0];
199 	sc->agc_size			= nitems(rtl8188e_agc);
200 	sc->rf_prog			= &rtl8188e_rf[0];
201 
202 	sc->name			= "RTL8188EE";
203 	sc->fwname			= "rtwn-rtl8188eefw";
204 	sc->fwsig			= 0x88e;
205 
206 	sc->page_count			= R88EE_TX_PAGE_COUNT;
207 	sc->pktbuf_count		= R88E_TXPKTBUF_COUNT;
208 
209 	sc->ackto			= 0x40;
210 	sc->npubqpages			= R88EE_PUBQ_NPAGES;
211 	sc->nhqpages			= R88EE_HPQ_NPAGES;
212 	sc->nnqpages			= R88EE_NPQ_NPAGES;
213 	sc->nlqpages			= R88EE_LPQ_NPAGES;
214 	sc->page_size			= R92C_TX_PAGE_SIZE;
215 
216 	sc->txdesc_len			= sizeof(struct r92ce_tx_desc);
217 	sc->efuse_maxlen		= R88E_EFUSE_MAX_LEN;
218 	sc->efuse_maplen		= R88E_EFUSE_MAP_LEN;
219 	sc->rx_dma_size			= R88E_RX_DMA_BUFFER_SIZE;
220 
221 	sc->macid_limit			= R88E_MACID_MAX + 1;
222 	sc->cam_entry_limit		= R92C_CAM_ENTRY_COUNT;
223 	sc->fwsize_limit		= R92C_MAX_FW_SIZE;
224 	sc->temp_delta			= R88E_CALIB_THRESHOLD;
225 
226 	sc->bcn_status_reg[0]		= R92C_TDECTRL;
227 	/*
228 	 * TODO: some additional setup is required
229 	 * to maintain few beacons at the same time.
230 	 *
231 	 * XXX BCNQ1 mechanism is not needed here; move it to the USB module.
232 	 */
233 	sc->bcn_status_reg[1]		= R92C_TDECTRL;
234 	sc->rcr				= 0;
235 
236 	sc->ntxchains			= 1;
237 	sc->nrxchains			= 1;
238 
239 	r88ee_attach_private(sc);
240 }
241