xref: /freebsd/sys/contrib/dev/ath/ath_hal/ar9300/ar9300_freebsd.c (revision 0b3105a37d7adcadcb720112fed4dc4e8040be99)
1 /*
2  * Copyright (c) 2012, 2013 Adrian Chadd <adrian@FreeBSD.org>.
3  *
4  * Permission to use, copy, modify, and/or 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 "opt_ah.h"
18 
19 #include "ah.h"
20 #include "ah_internal.h"
21 #include "ah_devid.h"
22 #include "ah_desc.h"
23 
24 #include "ar9300.h"
25 #include "ar9300reg.h"
26 #include "ar9300phy.h"
27 #include "ar9300desc.h"
28 
29 #include "ar9300_freebsd.h"
30 
31 #include "ar9300_stub.h"
32 #include "ar9300_stub_funcs.h"
33 
34 #define FIX_NOISE_FLOOR     1
35 #define NEXT_TBTT_NOW      5
36 static HAL_BOOL ar9300ClrMulticastFilterIndex(struct ath_hal *ah, uint32_t ix);
37 static HAL_BOOL ar9300SetMulticastFilterIndex(struct ath_hal *ah, uint32_t ix);
38 
39 static void ar9300_beacon_set_beacon_timers(struct ath_hal *ah,
40     const HAL_BEACON_TIMERS *bt);
41 
42 static void
43 ar9300SetChainMasks(struct ath_hal *ah, uint32_t tx_chainmask,
44     uint32_t rx_chainmask)
45 {
46 
47 	AH9300(ah)->ah_tx_chainmask =
48 	    tx_chainmask & AH_PRIVATE(ah)->ah_caps.halTxChainMask;
49 	AH9300(ah)->ah_rx_chainmask =
50 	    rx_chainmask & AH_PRIVATE(ah)->ah_caps.halRxChainMask;
51 }
52 
53 static u_int
54 ar9300GetSlotTime(struct ath_hal *ah)
55 {
56 	u_int clks = OS_REG_READ(ah, AR_D_GBL_IFS_SLOT) & 0xffff;
57 	return (ath_hal_mac_usec(ah, clks));	/* convert from system clocks */
58 }
59 
60 static HAL_BOOL
61 ar9300_freebsd_set_tx_power_limit(struct ath_hal *ah, uint32_t limit)
62 {
63 	return (ar9300_set_tx_power_limit(ah, limit, 0, 0));
64 }
65 
66 static uint64_t
67 ar9300_get_next_tbtt(struct ath_hal *ah)
68 {
69 	return (OS_REG_READ(ah, AR_NEXT_TBTT_TIMER));
70 }
71 
72 
73 /*
74  * TODO: implement the antenna diversity control for AR9485 and
75  * other LNA mixing based NICs.
76  *
77  * For now we'll just go with the HAL default and make these no-ops.
78  */
79 static HAL_ANT_SETTING
80 ar9300_freebsd_get_antenna_switch(struct ath_hal *ah)
81 {
82 
83 	return (HAL_ANT_VARIABLE);
84 }
85 
86 static HAL_BOOL
87 ar9300_freebsd_set_antenna_switch(struct ath_hal *ah, HAL_ANT_SETTING setting)
88 {
89 
90 	return (AH_TRUE);
91 }
92 
93 static u_int
94 ar9300_freebsd_get_cts_timeout(struct ath_hal *ah)
95 {
96     u_int clks = MS(OS_REG_READ(ah, AR_TIME_OUT), AR_TIME_OUT_CTS);
97     return ath_hal_mac_usec(ah, clks);      /* convert from system clocks */
98 }
99 
100 static void
101 ar9300_freebsd_set_tsf64(struct ath_hal *ah, uint64_t tsf64)
102 {
103 
104 	/*
105 	 * XXX TODO: read ar5416SetTsf64() - we should wait before we do
106 	 * this.
107 	 */
108 	OS_REG_WRITE(ah, AR_TSF_L32, tsf64 & 0xffffffff);
109 	OS_REG_WRITE(ah, AR_TSF_U32, (tsf64 >> 32) & 0xffffffff);
110 }
111 
112 void
113 ar9300_attach_freebsd_ops(struct ath_hal *ah)
114 {
115 
116 	/* Global functions */
117 	ah->ah_detach		= ar9300_detach;
118 	ah->ah_getRateTable		= ar9300_get_rate_table;
119 
120 	/* Reset functions */
121 	ah->ah_reset		= ar9300_reset_freebsd;
122 	ah->ah_phyDisable		= ar9300_phy_disable;
123 	ah->ah_disable		= ar9300_disable;
124 	ah->ah_configPCIE		= ar9300_config_pcie_freebsd;
125 //	ah->ah_disablePCIE		= ar9300_disable_pcie_phy;
126 	ah->ah_setPCUConfig		= ar9300_set_pcu_config;
127 	// perCalibration
128 	ah->ah_perCalibrationN	= ar9300_per_calibration_freebsd;
129 	ah->ah_resetCalValid	= ar9300_reset_cal_valid_freebsd;
130 	ah->ah_setTxPowerLimit	= ar9300_freebsd_set_tx_power_limit;
131 	ah->ah_getChanNoise		= ath_hal_getChanNoise;
132 
133 	/* Transmit functions */
134 	ah->ah_setupTxQueue		= ar9300_setup_tx_queue;
135 	ah->ah_setTxQueueProps	= ar9300_set_tx_queue_props;
136 	ah->ah_getTxQueueProps	= ar9300_get_tx_queue_props;
137 	ah->ah_releaseTxQueue	= ar9300_release_tx_queue;
138 	ah->ah_resetTxQueue		= ar9300_reset_tx_queue;
139 	ah->ah_getTxDP		= ar9300_get_tx_dp;
140 	ah->ah_setTxDP		= ar9300_set_tx_dp;
141 	ah->ah_numTxPending		= ar9300_num_tx_pending;
142 	ah->ah_startTxDma		= ar9300_start_tx_dma;
143 	ah->ah_stopTxDma		= ar9300_stop_tx_dma_freebsd;
144 	ah->ah_setupTxDesc		= ar9300_freebsd_setup_tx_desc;
145 	ah->ah_setupXTxDesc		= ar9300_freebsd_setup_x_tx_desc;
146 	ah->ah_fillTxDesc		= ar9300_freebsd_fill_tx_desc;
147 	ah->ah_procTxDesc		= ar9300_freebsd_proc_tx_desc;
148 	ah->ah_getTxIntrQueue	= ar9300_get_tx_intr_queue;
149 	// reqTxIntrDesc
150 	ah->ah_getTxCompletionRates	= ar9300_freebsd_get_tx_completion_rates;
151 	ah->ah_setTxDescLink	= ar9300_set_desc_link;
152 	ah->ah_getTxDescLink	= ar9300_freebsd_get_desc_link;
153 	ah->ah_getTxDescLinkPtr	= ar9300_get_desc_link_ptr;
154 	ah->ah_setupTxStatusRing	= ar9300_setup_tx_status_ring;
155 	ah->ah_getTxRawTxDesc	 = ar9300_get_raw_tx_desc;
156 	ah->ah_updateTxTrigLevel	= ar9300_update_tx_trig_level;
157 
158 	/* RX functions */
159 	ah->ah_getRxDP		= ar9300_get_rx_dp;
160 	ah->ah_setRxDP		= ar9300_set_rx_dp;
161 	ah->ah_enableReceive	= ar9300_enable_receive;
162 	ah->ah_stopDmaReceive	= ar9300_stop_dma_receive_freebsd;
163 	ah->ah_startPcuReceive	= ar9300_start_pcu_receive_freebsd;
164 	ah->ah_stopPcuReceive	= ar9300_stop_pcu_receive;
165 	ah->ah_setMulticastFilter	= ar9300_set_multicast_filter;
166 	ah->ah_setMulticastFilterIndex = ar9300SetMulticastFilterIndex;
167 	ah->ah_clrMulticastFilterIndex = ar9300ClrMulticastFilterIndex;
168 	ah->ah_getRxFilter		= ar9300_get_rx_filter;
169 	ah->ah_setRxFilter		= ar9300_set_rx_filter;
170 	/* setupRxDesc */
171 	ah->ah_procRxDesc		= ar9300_proc_rx_desc_freebsd;
172 	ah->ah_rxMonitor		= ar9300_ani_rxmonitor_freebsd;
173 	ah->ah_aniPoll		= ar9300_ani_poll_freebsd;
174 	ah->ah_procMibEvent		= ar9300_process_mib_intr;
175 
176 	/* Misc functions */
177 	ah->ah_getCapability	= ar9300_get_capability;
178 	ah->ah_setCapability	= ar9300_set_capability;
179 	ah->ah_getDiagState		= ar9300_get_diag_state;
180 	ah->ah_getMacAddress	= ar9300_get_mac_address;
181 	ah->ah_setMacAddress	= ar9300_set_mac_address;
182 	ah->ah_getBssIdMask		= ar9300_get_bss_id_mask;
183 	ah->ah_setBssIdMask		= ar9300_set_bss_id_mask;
184 	ah->ah_setRegulatoryDomain	= ar9300_set_regulatory_domain;
185 	ah->ah_setLedState		= ar9300_set_led_state;
186 	ah->ah_writeAssocid		= ar9300_write_associd;
187 	ah->ah_gpioCfgInput		= ar9300_gpio_cfg_input;
188 	ah->ah_gpioCfgOutput	= ar9300_gpio_cfg_output;
189 	ah->ah_gpioGet		= ar9300_gpio_get;
190 	ah->ah_gpioSet		= ar9300_gpio_set;
191 	ah->ah_gpioSetIntr		= ar9300_gpio_set_intr;
192 	/* polarity */
193 	/* mask */
194 	ah->ah_getTsf32		= ar9300_get_tsf32;
195 	ah->ah_getTsf64		= ar9300_get_tsf64;
196 	ah->ah_resetTsf		= ar9300_reset_tsf;
197 	ah->ah_setTsf64		= ar9300_freebsd_set_tsf64;
198 	ah->ah_detectCardPresent	= ar9300_detect_card_present;
199 	// ah->ah_updateMibCounters	= ar9300_update_mib_counters;
200 	ah->ah_getRfGain		= ar9300_get_rfgain;
201 	ah->ah_getDefAntenna	= ar9300_get_def_antenna;
202 	ah->ah_setDefAntenna	= ar9300_set_def_antenna;
203 	ah->ah_getAntennaSwitch	= ar9300_freebsd_get_antenna_switch;
204 	ah->ah_setAntennaSwitch	= ar9300_freebsd_set_antenna_switch;
205 	// ah->ah_setSifsTime		= ar9300_set_sifs_time;
206 	// ah->ah_getSifsTime		= ar9300_get_sifs_time;
207 	ah->ah_setSlotTime		= ar9300_set_slot_time;
208 	ah->ah_getSlotTime		= ar9300GetSlotTime;
209 	ah->ah_getAckTimeout	= ar9300_get_ack_timeout;
210 	ah->ah_setAckTimeout	= ar9300_set_ack_timeout;
211 	// XXX ack/ctsrate
212 	// XXX CTS timeout
213 	ah->ah_getCTSTimeout = ar9300_freebsd_get_cts_timeout;
214 	// XXX decompmask
215 	// coverageclass
216 	ah->ah_setQuiet		= ar9300_set_quiet;
217 	ah->ah_getMibCycleCounts	= ar9300_freebsd_get_mib_cycle_counts;
218 
219 	/* DFS functions */
220 	ah->ah_enableDfs		= ar9300_enable_dfs;
221 	ah->ah_getDfsThresh		= ar9300_get_dfs_thresh;
222 	ah->ah_getDfsDefaultThresh	= ar9300_freebsd_get_dfs_default_thresh;
223 	// procradarevent
224 	ah->ah_isFastClockEnabled	= ar9300_is_fast_clock_enabled;
225 	ah->ah_get11nExtBusy	= ar9300_get_11n_ext_busy;
226 
227 	/* Spectral Scan Functions */
228 	ah->ah_spectralConfigure	= ar9300_configure_spectral_scan;
229 	ah->ah_spectralGetConfig	= ar9300_get_spectral_params;
230 	ah->ah_spectralStart		= ar9300_start_spectral_scan;
231 	ah->ah_spectralStop		= ar9300_stop_spectral_scan;
232 	ah->ah_spectralIsEnabled	= ar9300_is_spectral_enabled;
233 	ah->ah_spectralIsActive		= ar9300_is_spectral_active;
234 
235 	/* Key cache functions */
236 	ah->ah_getKeyCacheSize	= ar9300_get_key_cache_size;
237 	ah->ah_resetKeyCacheEntry	= ar9300_reset_key_cache_entry;
238 	ah->ah_isKeyCacheEntryValid	= ar9300_is_key_cache_entry_valid;
239 	ah->ah_setKeyCacheEntry	= ar9300_set_key_cache_entry;
240 	ah->ah_setKeyCacheEntryMac	= ar9300_set_key_cache_entry_mac;
241 
242 	/* Power management functions */
243 	ah->ah_setPowerMode		= ar9300_set_power_mode;
244 	ah->ah_getPowerMode		= ar9300_get_power_mode;
245 
246 	/* Beacon functions */
247 	/* ah_setBeaconTimers */
248 	ah->ah_beaconInit		= ar9300_freebsd_beacon_init;
249 	ah->ah_setBeaconTimers		= ar9300_beacon_set_beacon_timers;
250 	ah->ah_setStationBeaconTimers = ar9300_set_sta_beacon_timers;
251 	/* ah_resetStationBeaconTimers */
252 	ah->ah_getNextTBTT = ar9300_get_next_tbtt;
253 
254 	/* Interrupt functions */
255 	ah->ah_isInterruptPending	= ar9300_is_interrupt_pending;
256 	ah->ah_getPendingInterrupts	= ar9300_get_pending_interrupts_freebsd;
257 	ah->ah_getInterrupts =	ar9300_get_interrupts;
258 	ah->ah_setInterrupts =	ar9300_set_interrupts_freebsd;
259 
260 	/* Regulatory/internal functions */
261 	//    AH_PRIVATE(ah)->ah_getNfAdjust = ar9300_get_nf_adjust;
262 	AH_PRIVATE(ah)->ah_eepromRead = ar9300_eeprom_read_word;
263 	//    AH_PRIVATE(ah)->ah_getChipPowerLimits = ar9300_get_chip_power_limits;
264 	AH_PRIVATE(ah)->ah_getWirelessModes = ar9300_get_wireless_modes;
265 	AH_PRIVATE(ah)->ah_getChannelEdges = ar9300_get_channel_edges;
266 
267 	AH_PRIVATE(ah)->ah_eepromRead = ar9300_eeprom_read_word;
268 	/* XXX ah_eeprom */
269 	/* XXX ah_eeversion */
270 	/* XXX ah_eepromDetach */
271 	/* XXX ah_eepromGet */
272 	AH_PRIVATE(ah)->ah_eepromGet = ar9300_eeprom_get_freebsd;
273 	/* XXX ah_eepromSet */
274 	/* XXX ah_getSpurChan */
275 	/* XXX ah_eepromDiag */
276 
277 	/* 802.11n functions */
278 	ah->ah_chainTxDesc = ar9300_freebsd_chain_tx_desc;
279 	ah->ah_setupFirstTxDesc= ar9300_freebsd_setup_first_tx_desc;
280 	ah->ah_setupLastTxDesc = ar9300_freebsd_setup_last_tx_desc;
281 	ah->ah_set11nRateScenario = ar9300_freebsd_set_11n_rate_scenario;
282 	ah->ah_set11nTxDesc = ar9300_freebsd_setup_11n_desc;
283 	ah->ah_set11nAggrFirst = ar9300_set_11n_aggr_first;
284 	ah->ah_set11nAggrMiddle = ar9300_set_11n_aggr_middle;
285 	ah->ah_set11nAggrLast = ar9300_set_11n_aggr_last;
286 	ah->ah_clr11nAggr = ar9300_clr_11n_aggr;
287 	ah->ah_set11nBurstDuration = ar9300_set_11n_burst_duration;
288 	/* ah_get11nExtBusy */
289 	ah->ah_set11nMac2040 = ar9300_set_11n_mac2040;
290 	ah->ah_setChainMasks = ar9300SetChainMasks;
291 	/* ah_get11nRxClear */
292 	/* ah_set11nRxClear */
293 
294 	/* bluetooth coexistence functions */
295 	ah->ah_btCoexSetInfo		= ar9300_set_bt_coex_info;
296 	ah->ah_btCoexSetConfig		= ar9300_bt_coex_config;
297 	ah->ah_btCoexSetQcuThresh	= ar9300_bt_coex_set_qcu_thresh;
298 	ah->ah_btCoexSetWeights		= ar9300_bt_coex_set_weights;
299 	ah->ah_btCoexSetBmissThresh	= ar9300_bt_coex_setup_bmiss_thresh;
300 	ah->ah_btCoexSetParameter	= ar9300_bt_coex_set_parameter;
301 	ah->ah_btCoexDisable		= ar9300_bt_coex_disable;
302 	ah->ah_btCoexEnable		= ar9300_bt_coex_enable;
303 
304 	/* MCI bluetooth functions */
305 	if (AR_SREV_JUPITER(ah) || AR_SREV_APHRODITE(ah)) {
306 		ah->ah_btCoexSetWeights = ar9300_mci_bt_coex_set_weights;
307 		ah->ah_btCoexDisable = ar9300_mci_bt_coex_disable;
308 		ah->ah_btCoexEnable = ar9300_mci_bt_coex_enable;
309 	}
310 	ah->ah_btMciSetup		= ar9300_mci_setup;
311 	ah->ah_btMciSendMessage		= ar9300_mci_send_message;
312 	ah->ah_btMciGetInterrupt	= ar9300_mci_get_interrupt;
313 	ah->ah_btMciGetState		= ar9300_mci_state;
314 	ah->ah_btMciDetach		= ar9300_mci_detach;
315 
316 	/* LNA diversity functions */
317 	ah->ah_divLnaConfGet = ar9300_ant_div_comb_get_config;
318 	ah->ah_divLnaConfSet = ar9300_ant_div_comb_set_config;
319 }
320 
321 HAL_BOOL
322 ar9300_reset_freebsd(struct ath_hal *ah, HAL_OPMODE opmode,
323     struct ieee80211_channel *chan, HAL_BOOL bChannelChange,
324     HAL_RESET_TYPE resetType,
325     HAL_STATUS *status)
326 {
327 	HAL_BOOL r;
328 	HAL_HT_MACMODE macmode;
329 	struct ath_hal_private  *ap  = AH_PRIVATE(ah);
330 
331 	macmode =
332 	    IEEE80211_IS_CHAN_HT40(chan) ?
333 	        HAL_HT_MACMODE_2040 : HAL_HT_MACMODE_20;
334 
335 	r = ar9300_reset(ah, opmode, chan, macmode,
336 	    ap->ah_caps.halTxChainMask,
337 	    ap->ah_caps.halRxChainMask,
338 	    HAL_HT_EXTPROTSPACING_20, /* always 20Mhz channel spacing */
339 	    bChannelChange,
340 	    status,
341 	    AH_FALSE);       /* XXX should really extend ath_hal_reset() */
342 
343 	return (r);
344 }
345 
346 void
347 ar9300_config_pcie_freebsd(struct ath_hal *ah, HAL_BOOL restore,
348     HAL_BOOL powerOff)
349 {
350 
351 	ar9300_config_pci_power_save(ah, restore ? 1 : 0, powerOff ? 1 : 0);
352 }
353 
354 /*
355  * This is a copy from ar9300_eeprom_get(), purely because the FreeBSD
356  * API is very silly and inconsistent.
357  *
358  * The AR93xx HAL doesn't call the eepromGetFlag() function, so this
359  * only occurs for FreeBSD code.
360  *
361  * When I fix this particular API, I'll undo this.
362  */
363 HAL_STATUS
364 ar9300_eeprom_get_freebsd(struct ath_hal *ah, int param, void *val)
365 {
366 
367 	switch (param) {
368 	case AR_EEP_FSTCLK_5G:
369 		return HAL_OK;
370 	default:
371 		ath_hal_printf(ah, "%s: called, param=%d\n",
372 		    __func__, param);
373 		return HAL_EIO;
374 	}
375 }
376 
377 HAL_BOOL
378 ar9300_stop_tx_dma_freebsd(struct ath_hal *ah, u_int q)
379 {
380 
381 	return ar9300_stop_tx_dma(ah, q, 1000);
382 }
383 
384 void
385 ar9300_ani_poll_freebsd(struct ath_hal *ah,
386     const struct ieee80211_channel *chan)
387 {
388 
389 	HAL_NODE_STATS stats;
390 	HAL_ANISTATS anistats;
391 	HAL_SURVEY_SAMPLE survey;
392 
393 	OS_MEMZERO(&stats, sizeof(stats));
394 	OS_MEMZERO(&anistats, sizeof(anistats));
395 	OS_MEMZERO(&survey, sizeof(survey));
396 
397 	ar9300_ani_ar_poll(ah, &stats, chan, &anistats);
398 
399 	/*
400 	 * If ANI stats are valid, use them to update the
401 	 * channel survey.
402 	 */
403 	if (anistats.valid) {
404 		survey.cycle_count = anistats.cyclecnt_diff;
405 		survey.chan_busy = anistats.rxclr_cnt;
406 		survey.ext_chan_busy = anistats.extrxclr_cnt;
407 		survey.tx_busy = anistats.txframecnt_diff;
408 		survey.rx_busy = anistats.rxframecnt_diff;
409 		ath_hal_survey_add_sample(ah, &survey);
410 	}
411 }
412 
413 /*
414  * Setup the configuration parameters in the style the AR9300 HAL
415  * wants.
416  */
417 void
418 ar9300_config_defaults_freebsd(struct ath_hal *ah, HAL_OPS_CONFIG *ah_config)
419 {
420 
421 	/* Until FreeBSD's HAL does this by default - just copy */
422 	OS_MEMCPY(&ah->ah_config, ah_config, sizeof(HAL_OPS_CONFIG));
423 	ah->ah_config.ath_hal_enable_ani = AH_TRUE;
424 }
425 
426 HAL_BOOL
427 ar9300_stop_dma_receive_freebsd(struct ath_hal *ah)
428 {
429 
430 	return ar9300_stop_dma_receive(ah, 1000);
431 }
432 
433 HAL_BOOL
434 ar9300_get_pending_interrupts_freebsd(struct ath_hal *ah, HAL_INT *masked)
435 {
436 
437 	/* Non-MSI, so no MSI vector; and 'nortc' = 0 */
438 	return ar9300_get_pending_interrupts(ah, masked, HAL_INT_LINE, 0, 0);
439 }
440 
441 HAL_INT
442 ar9300_set_interrupts_freebsd(struct ath_hal *ah, HAL_INT ints)
443 {
444 
445 	/* nortc = 0 */
446 	return ar9300_set_interrupts(ah, ints, 0);
447 }
448 
449 HAL_BOOL
450 ar9300_per_calibration_freebsd(struct ath_hal *ah,
451     struct ieee80211_channel *chan, u_int rxchainmask, HAL_BOOL long_cal,
452     HAL_BOOL *isCalDone)
453 {
454 	/* XXX fake scheduled calibrations for now */
455 	u_int32_t sched_cals = 0xfffffff;
456 
457 	return ar9300_calibration(ah, chan,
458 	    AH_PRIVATE(ah)->ah_caps.halRxChainMask,
459 	    long_cal,
460 	    isCalDone,
461 	    0,			/* is_scan */
462 	    &sched_cals);
463 }
464 
465 HAL_BOOL
466 ar9300_reset_cal_valid_freebsd(struct ath_hal *ah,
467     const struct ieee80211_channel *chan)
468 {
469 
470 	HAL_BOOL is_cal_done = AH_TRUE;
471 
472 	ar9300_reset_cal_valid(ah, chan, &is_cal_done, 0xffffffff);
473 	return (is_cal_done);
474 }
475 
476 
477 void
478 ar9300_start_pcu_receive_freebsd(struct ath_hal *ah)
479 {
480 
481 	/* is_scanning flag == NULL */
482 	ar9300_start_pcu_receive(ah, AH_FALSE);
483 }
484 
485 /*
486  * FreeBSD will just pass in the descriptor value as 'pa'.
487  * The Atheros HAL treats 'pa' as the physical address of the RX
488  * descriptor and 'bufaddr' as the physical address of the RX buffer.
489  * I'm not sure why they didn't collapse them - the AR9300 RX descriptor
490  * routine doesn't check 'pa'.
491  */
492 HAL_STATUS
493 ar9300_proc_rx_desc_freebsd(struct ath_hal *ah, struct ath_desc *ds,
494     uint32_t pa, struct ath_desc *ds_next, uint64_t tsf,
495     struct ath_rx_status *rxs)
496 {
497 
498 	return (ar9300_proc_rx_desc_fast(ah, ds, 0, ds_next, rxs,
499 	    (void *) ds));
500 }
501 
502 void
503 ar9300_ani_rxmonitor_freebsd(struct ath_hal *ah, const HAL_NODE_STATS *stats,
504     const struct ieee80211_channel *chan)
505 {
506 
507 }
508 
509 void
510 ar9300_freebsd_get_desc_link(struct ath_hal *ah, void *ds, uint32_t *link)
511 {
512 	struct ar9300_txc *ads = AR9300TXC(ds);
513 
514 	(*link) = ads->ds_link;
515 }
516 
517 /*
518  * TX descriptor field setting wrappers - eek.
519  */
520 
521 
522 HAL_BOOL
523 ar9300_freebsd_setup_tx_desc(struct ath_hal *ah, struct ath_desc *ds,
524     u_int pktLen, u_int hdrLen, HAL_PKT_TYPE type, u_int txPower,
525     u_int txRate0, u_int txTries0, u_int keyIx, u_int antMode, u_int flags,
526     u_int rtsctsRate, u_int rtsCtsDuration, u_int compicvLen,
527     u_int compivLen, u_int comp)
528 {
529 	struct ath_hal_9300 *ahp = AH9300(ah);
530 
531 	HAL_KEY_TYPE keyType = 0;	/* XXX No padding */
532 
533 	if (keyIx != HAL_TXKEYIX_INVALID)
534 		keyType = ahp->ah_keytype[keyIx];
535 
536 	/* XXX bounds check keyix */
537 	ar9300_set_11n_tx_desc(ah, ds, pktLen, type, txPower, keyIx,
538 	    keyType, flags);
539 
540 	return AH_TRUE;
541 }
542 
543 HAL_BOOL
544 ar9300_freebsd_setup_x_tx_desc(struct ath_hal *ah, struct ath_desc *ds,
545     u_int txRate1, u_int txTries1,
546     u_int txRate2, u_int txTries2,
547     u_int txRate3, u_int txTries3)
548 {
549 
550 #if 0
551 	ath_hal_printf(ah, "%s: called, 0x%x/%d, 0x%x/%d, 0x%x/%d\n",
552 	    __func__,
553 	    txRate1, txTries1,
554 	    txRate2, txTries2,
555 	    txRate3, txTries3);
556 #endif
557 
558 	/* XXX should only be called during probe */
559 	return (AH_TRUE);
560 }
561 
562 HAL_BOOL
563 ar9300_freebsd_fill_tx_desc(struct ath_hal *ah, struct ath_desc *ds,
564     HAL_DMA_ADDR *bufListPtr, uint32_t *segLenPtr, u_int descId, u_int qid,
565     HAL_BOOL firstSeg, HAL_BOOL lastSeg,
566     const struct ath_desc *ds0)
567 {
568 	HAL_KEY_TYPE keyType = 0;
569 	const struct ar9300_txc *ads = AR9300TXC_CONST(ds0);
570 
571 	/*
572 	 * FreeBSD's HAL doesn't pass the keytype to fill_tx_desc();
573 	 * it's copied as part of the descriptor chaining.
574 	 *
575 	 * So, extract it from ds0.
576 	 */
577 	keyType = MS(ads->ds_ctl17, AR_encr_type);
578 
579 	return ar9300_fill_tx_desc(ah, ds, bufListPtr, segLenPtr, descId,
580 	    qid, keyType, firstSeg, lastSeg, ds0);
581 }
582 
583 HAL_BOOL
584 ar9300_freebsd_get_tx_completion_rates(struct ath_hal *ah,
585     const struct ath_desc *ds0, int *rates, int *tries)
586 {
587 
588 	ath_hal_printf(ah, "%s: called\n", __func__);
589 	return AH_FALSE;	/* XXX for now */
590 }
591 
592 
593 /*
594  * 802.11n TX descriptor wrappers
595  */
596 void
597 ar9300_freebsd_set_11n_rate_scenario(struct ath_hal *ah, struct ath_desc *ds,
598     u_int durUpdateEn, u_int rtsctsRate, HAL_11N_RATE_SERIES series[],
599     u_int nseries, u_int flags)
600 {
601 
602 	/* lastds=NULL, rtscts_duration is 0, smart antenna is 0 */
603 	ar9300_set_11n_rate_scenario(ah, (void *) ds, (void *)ds, durUpdateEn,
604 	    rtsctsRate, 0, series, nseries, flags, 0);
605 }
606 
607 /* chaintxdesc */
608 HAL_BOOL
609 ar9300_freebsd_chain_tx_desc(struct ath_hal *ah, struct ath_desc *ds,
610     HAL_DMA_ADDR *bufLenList, uint32_t *segLenList,
611     u_int pktLen, u_int hdrLen, HAL_PKT_TYPE type, u_int keyIx,
612     HAL_CIPHER cipher, uint8_t numDelims,
613     HAL_BOOL firstSeg, HAL_BOOL lastSeg, HAL_BOOL lastAggr)
614 {
615 
616 	ath_hal_printf(ah, "%s: called\n", __func__);
617 	return AH_FALSE;
618 }
619 
620 /* setupfirsttxdesc */
621 HAL_BOOL
622 ar9300_freebsd_setup_first_tx_desc(struct ath_hal *ah, struct ath_desc *ds,
623     u_int aggrLen, u_int flags, u_int txPower, u_int txRate0,
624     u_int txTries0, u_int antMode, u_int rtsctsRate, u_int rtsctsDuration)
625 {
626 
627 	ath_hal_printf(ah, "%s: called\n", __func__);
628 	return AH_FALSE;
629 }
630 
631 /* setuplasttxdesc */
632 /*
633  * This gets called but for now let's not log anything;
634  * it's only used to update the rate control information.
635  */
636 HAL_BOOL
637 ar9300_freebsd_setup_last_tx_desc(struct ath_hal *ah, struct ath_desc *ds,
638     const struct ath_desc *ds0)
639 {
640 
641 //	ath_hal_printf(ah, "%s: called\n", __func__);
642 	return AH_FALSE;
643 }
644 
645 void
646 ar9300_freebsd_setup_11n_desc(struct ath_hal *ah, void *ds, u_int pktLen,
647     HAL_PKT_TYPE type, u_int txPower, u_int keyIx, u_int flags)
648 {
649 	ath_hal_printf(ah, "%s: called\n", __func__);
650 #if 0
651 	struct ath_hal_9300 *ahp = AH9300(ah);
652 
653 	HAL_KEY_TYPE keyType = 0;	/* XXX No padding */
654 
655 	if (keyIx != HAL_TXKEYIX_INVALID)
656 		keyType = ahp->ah_keytype[keyIx];
657 
658 	/* XXX bounds check keyix */
659 	ar9300_set_11n_tx_desc(ah, ds, pktLen, type, txPower, keyIx,
660 	    keyType, flags);
661 #endif
662 }
663 
664 HAL_STATUS
665 ar9300_freebsd_proc_tx_desc(struct ath_hal *ah, struct ath_desc *ds,
666     struct ath_tx_status *ts)
667 {
668 
669 	return ar9300_proc_tx_desc(ah, ts);
670 }
671 
672 void
673 ar9300_freebsd_beacon_init(struct ath_hal *ah, uint32_t next_beacon,
674     uint32_t beacon_period)
675 {
676 
677 	ar9300_beacon_init(ah, next_beacon, beacon_period, 0,
678 	    AH_PRIVATE(ah)->ah_opmode);
679 }
680 
681 HAL_BOOL
682 ar9300_freebsd_get_mib_cycle_counts(struct ath_hal *ah,
683     HAL_SURVEY_SAMPLE *hs)
684 
685 {
686 
687 	return (AH_FALSE);
688 }
689 
690 HAL_BOOL
691 ar9300_freebsd_get_dfs_default_thresh(struct ath_hal *ah,
692     HAL_PHYERR_PARAM *pe)
693 {
694 
695 	/* XXX not yet */
696 
697 	return (AH_FALSE);
698 }
699 
700 /*
701  * Clear multicast filter by index - from FreeBSD ar5212_recv.c
702  */
703 static HAL_BOOL
704 ar9300ClrMulticastFilterIndex(struct ath_hal *ah, uint32_t ix)
705 {
706 	uint32_t val;
707 
708 	if (ix >= 64)
709 		return (AH_FALSE);
710 	if (ix >= 32) {
711 		val = OS_REG_READ(ah, AR_MCAST_FIL1);
712 		OS_REG_WRITE(ah, AR_MCAST_FIL1, (val &~ (1<<(ix-32))));
713 	} else {
714 		val = OS_REG_READ(ah, AR_MCAST_FIL0);
715 		OS_REG_WRITE(ah, AR_MCAST_FIL0, (val &~ (1<<ix)));
716 	}
717 	return AH_TRUE;
718 }
719 
720 /*
721  * Set multicast filter by index - from FreeBSD ar5212_recv.c
722  */
723 static HAL_BOOL
724 ar9300SetMulticastFilterIndex(struct ath_hal *ah, uint32_t ix)
725 {
726 	uint32_t val;
727 
728 	if (ix >= 64)
729 		return (AH_FALSE);
730 	if (ix >= 32) {
731 		val = OS_REG_READ(ah, AR_MCAST_FIL1);
732 		OS_REG_WRITE(ah, AR_MCAST_FIL1, (val | (1<<(ix-32))));
733 	} else {
734 		val = OS_REG_READ(ah, AR_MCAST_FIL0);
735 		OS_REG_WRITE(ah, AR_MCAST_FIL0, (val | (1<<ix)));
736 	}
737 	return (AH_TRUE);
738 }
739 
740 #define	TU_TO_USEC(_tu) ((_tu) << 10)
741 #define	ONE_EIGHTH_TU_TO_USEC(_tu8) ((_tu8) << 7)
742 
743 /*
744  * Initializes all of the hardware registers used to
745  * send beacons.  Note that for station operation the
746  * driver calls ar9300_set_sta_beacon_timers instead.
747  */
748 static void
749 ar9300_beacon_set_beacon_timers(struct ath_hal *ah,
750     const HAL_BEACON_TIMERS *bt)
751 {
752 	uint32_t bperiod;
753 
754 #if 0
755     HALASSERT(opmode == HAL_M_IBSS || opmode == HAL_M_HOSTAP);
756     if (opmode == HAL_M_IBSS) {
757         OS_REG_SET_BIT(ah, AR_TXCFG, AR_TXCFG_ADHOC_BEACON_ATIM_TX_POLICY);
758     }
759 #endif
760 
761 	/* XXX TODO: should migrate the HAL code to always use ONE_EIGHTH_TU */
762 	OS_REG_WRITE(ah, AR_NEXT_TBTT_TIMER, TU_TO_USEC(bt->bt_nexttbtt));
763 	OS_REG_WRITE(ah, AR_NEXT_DMA_BEACON_ALERT, ONE_EIGHTH_TU_TO_USEC(bt->bt_nextdba));
764 	OS_REG_WRITE(ah, AR_NEXT_SWBA, ONE_EIGHTH_TU_TO_USEC(bt->bt_nextswba));
765 	OS_REG_WRITE(ah, AR_NEXT_NDP_TIMER, TU_TO_USEC(bt->bt_nextatim));
766 
767 	bperiod = TU_TO_USEC(bt->bt_intval & HAL_BEACON_PERIOD);
768 	/* XXX TODO! */
769 //        ahp->ah_beaconInterval = bt->bt_intval & HAL_BEACON_PERIOD;
770 	OS_REG_WRITE(ah, AR_BEACON_PERIOD, bperiod);
771 	OS_REG_WRITE(ah, AR_DMA_BEACON_PERIOD, bperiod);
772 	OS_REG_WRITE(ah, AR_SWBA_PERIOD, bperiod);
773 	OS_REG_WRITE(ah, AR_NDP_PERIOD, bperiod);
774 
775 	/*
776 	 * Reset TSF if required.
777 	 */
778 	if (bt->bt_intval & HAL_BEACON_RESET_TSF)
779 		ar9300_reset_tsf(ah);
780 
781 	/* enable timers */
782 	/* NB: flags == 0 handled specially for backwards compatibility */
783 	OS_REG_SET_BIT(ah, AR_TIMER_MODE,
784 	    bt->bt_flags != 0 ? bt->bt_flags :
785 	    AR_TBTT_TIMER_EN | AR_DBA_TIMER_EN | AR_SWBA_TIMER_EN);
786 }
787 
788 
789 /*
790  * RF attach stubs
791  */
792 
793 static HAL_BOOL
794 rf9330_attach(struct ath_hal *ah, HAL_STATUS *status)
795 {
796 
797 	(*status) = HAL_EINVAL;
798 	return (AH_FALSE);
799 }
800 
801 static HAL_BOOL
802 rf9330_probe(struct ath_hal *ah)
803 {
804 	return (AH_FALSE);
805 }
806 
807 AH_RF(RF9330, rf9330_probe, rf9330_attach);
808 
809