ar9300_attach.c revision 252238
1/*
2 * Copyright (c) 2013 Qualcomm Atheros, Inc.
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 WITH
9 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
10 * AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
11 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
12 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
13 * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
14 * 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
23#include "ar9300/ar9300desc.h"
24#include "ar9300/ar9300.h"
25#include "ar9300/ar9300reg.h"
26#include "ar9300/ar9300phy.h"
27#include "ar9300/ar9300paprd.h"
28
29#include "ar9300/ar9300_stub.h"
30#include "ar9300/ar9300_stub_funcs.h"
31
32
33/* Add static register initialization vectors */
34#include "ar9300/ar9300_osprey22.ini"
35#include "ar9300/ar9330_11.ini"
36#include "ar9300/ar9330_12.ini"
37#include "ar9300/ar9340.ini"
38#include "ar9300/ar9485.ini"
39#include "ar9300/ar9485_1_1.ini"
40#include "ar9300/ar9300_jupiter10.ini"
41#include "ar9300/ar9300_jupiter20.ini"
42#include "ar9300/ar9580.ini"
43#include "ar9300/ar955x.ini"
44#include "ar9300/ar9300_aphrodite10.ini"
45
46
47/* Include various freebsd specific HAL methods */
48#include "ar9300/ar9300_freebsd.h"
49
50/* XXX duplicate in ar9300_radio.c ? */
51static HAL_BOOL ar9300_get_chip_power_limits(struct ath_hal *ah,
52    struct ieee80211_channel *chan);
53
54static inline HAL_STATUS ar9300_init_mac_addr(struct ath_hal *ah);
55static inline HAL_STATUS ar9300_hw_attach(struct ath_hal *ah);
56static inline void ar9300_hw_detach(struct ath_hal *ah);
57static int16_t ar9300_get_nf_adjust(struct ath_hal *ah,
58    const HAL_CHANNEL_INTERNAL *c);
59#if 0
60int ar9300_get_cal_intervals(struct ath_hal *ah, HAL_CALIBRATION_TIMER **timerp,
61    HAL_CAL_QUERY query);
62#endif
63
64#if ATH_TRAFFIC_FAST_RECOVER
65unsigned long ar9300_get_pll3_sqsum_dvc(struct ath_hal *ah);
66#endif
67static int ar9300_init_offsets(struct ath_hal *ah, u_int16_t devid);
68
69
70static void
71ar9300_disable_pcie_phy(struct ath_hal *ah);
72
73static const HAL_PERCAL_DATA iq_cal_single_sample =
74                          {IQ_MISMATCH_CAL,
75                          MIN_CAL_SAMPLES,
76                          PER_MAX_LOG_COUNT,
77                          ar9300_iq_cal_collect,
78                          ar9300_iq_calibration};
79
80#if 0
81static HAL_CALIBRATION_TIMER ar9300_cals[] =
82                          { {IQ_MISMATCH_CAL,               /* Cal type */
83                             1200000,                       /* Cal interval */
84                             0                              /* Cal timestamp */
85                            },
86                          {TEMP_COMP_CAL,
87                             5000,
88                             0
89                            },
90                          };
91#endif
92
93#if ATH_PCIE_ERROR_MONITOR
94
95int ar9300_start_pcie_error_monitor(struct ath_hal *ah, int b_auto_stop)
96{
97    u_int32_t val;
98
99    /* Clear the counters */
100    OS_REG_WRITE(ah, PCIE_CO_ERR_CTR_CTR0, 0);
101    OS_REG_WRITE(ah, PCIE_CO_ERR_CTR_CTR1, 0);
102
103    /* Read the previous value */
104    val = OS_REG_READ(ah, PCIE_CO_ERR_CTR_CTRL);
105
106    /* Set auto_stop */
107    if (b_auto_stop) {
108        val |=
109            RCVD_ERR_CTR_AUTO_STOP | BAD_TLP_ERR_CTR_AUTO_STOP |
110            BAD_DLLP_ERR_CTR_AUTO_STOP | RPLY_TO_ERR_CTR_AUTO_STOP |
111            RPLY_NUM_RO_ERR_CTR_AUTO_STOP;
112    } else {
113        val &= ~(
114            RCVD_ERR_CTR_AUTO_STOP | BAD_TLP_ERR_CTR_AUTO_STOP |
115            BAD_DLLP_ERR_CTR_AUTO_STOP | RPLY_TO_ERR_CTR_AUTO_STOP |
116            RPLY_NUM_RO_ERR_CTR_AUTO_STOP);
117    }
118    OS_REG_WRITE(ah, PCIE_CO_ERR_CTR_CTRL, val );
119
120    /*
121     * Start to run.
122     * This has to be done separately from the above auto_stop flag setting,
123     * to avoid a HW race condition.
124     */
125    val |=
126        RCVD_ERR_CTR_RUN | BAD_TLP_ERR_CTR_RUN | BAD_DLLP_ERR_CTR_RUN |
127        RPLY_TO_ERR_CTR_RUN | RPLY_NUM_RO_ERR_CTR_RUN;
128    OS_REG_WRITE(ah, PCIE_CO_ERR_CTR_CTRL, val);
129
130    return 0;
131}
132
133int ar9300_read_pcie_error_monitor(struct ath_hal *ah, void* p_read_counters)
134{
135    u_int32_t val;
136    ar_pcie_error_moniter_counters *p_counters =
137        (ar_pcie_error_moniter_counters*) p_read_counters;
138
139    val = OS_REG_READ(ah, PCIE_CO_ERR_CTR_CTR0);
140
141    p_counters->uc_receiver_errors = MS(val, RCVD_ERR_MASK);
142    p_counters->uc_bad_tlp_errors  = MS(val, BAD_TLP_ERR_MASK);
143    p_counters->uc_bad_dllp_errors = MS(val, BAD_DLLP_ERR_MASK);
144
145    val = OS_REG_READ(ah, PCIE_CO_ERR_CTR_CTR1);
146
147    p_counters->uc_replay_timeout_errors        = MS(val, RPLY_TO_ERR_MASK);
148    p_counters->uc_replay_number_rollover_errors= MS(val, RPLY_NUM_RO_ERR_MASK);
149
150    return 0;
151}
152
153int ar9300_stop_pcie_error_monitor(struct ath_hal *ah)
154{
155    u_int32_t val;
156
157    /* Read the previous value */
158    val = OS_REG_READ(ah, PCIE_CO_ERR_CTR_CTRL);
159
160    val &= ~(
161        RCVD_ERR_CTR_RUN |
162        BAD_TLP_ERR_CTR_RUN |
163        BAD_DLLP_ERR_CTR_RUN |
164        RPLY_TO_ERR_CTR_RUN |
165        RPLY_NUM_RO_ERR_CTR_RUN);
166
167    /* Start to stop */
168    OS_REG_WRITE(ah, PCIE_CO_ERR_CTR_CTRL, val );
169
170    return 0;
171}
172
173#endif /* ATH_PCIE_ERROR_MONITOR */
174
175#if 0
176/* WIN32 does not support C99 */
177static const struct ath_hal_private ar9300hal = {
178    {
179        ar9300_get_rate_table,             /* ah_get_rate_table */
180        ar9300_detach,                     /* ah_detach */
181
182        /* Reset Functions */
183        ar9300_reset,                      /* ah_reset */
184        ar9300_phy_disable,                /* ah_phy_disable */
185        ar9300_disable,                    /* ah_disable */
186        ar9300_config_pci_power_save,      /* ah_config_pci_power_save */
187        ar9300_set_pcu_config,             /* ah_set_pcu_config */
188        ar9300_calibration,                /* ah_per_calibration */
189        ar9300_reset_cal_valid,            /* ah_reset_cal_valid */
190        ar9300_set_tx_power_limit,         /* ah_set_tx_power_limit */
191
192#if ATH_ANT_DIV_COMB
193        ar9300_ant_ctrl_set_lna_div_use_bt_ant,     /* ah_ant_ctrl_set_lna_div_use_bt_ant */
194#endif /* ATH_ANT_DIV_COMB */
195#ifdef ATH_SUPPORT_DFS
196        ar9300_radar_wait,                 /* ah_radar_wait */
197
198        /* New DFS functions */
199        ar9300_check_dfs,                  /* ah_ar_check_dfs */
200        ar9300_dfs_found,                  /* ah_ar_dfs_found */
201        ar9300_enable_dfs,                 /* ah_ar_enable_dfs */
202        ar9300_get_dfs_thresh,             /* ah_ar_get_dfs_thresh */
203        ar9300_get_dfs_radars,             /* ah_ar_get_dfs_radars */
204        ar9300_adjust_difs,                /* ah_adjust_difs */
205        ar9300_dfs_config_fft,             /* ah_dfs_config_fft */
206        ar9300_dfs_cac_war,                /* ah_dfs_cac_war */
207        ar9300_cac_tx_quiet,               /* ah_cac_tx_quiet */
208#endif
209        ar9300_get_extension_channel,      /* ah_get_extension_channel */
210        ar9300_is_fast_clock_enabled,      /* ah_is_fast_clock_enabled */
211
212        /* Transmit functions */
213        ar9300_update_tx_trig_level,       /* ah_update_tx_trig_level */
214        ar9300_get_tx_trig_level,          /* ah_get_tx_trig_level */
215        ar9300_setup_tx_queue,             /* ah_setup_tx_queue */
216        ar9300_set_tx_queue_props,         /* ah_set_tx_queue_props */
217        ar9300_get_tx_queue_props,         /* ah_get_tx_queue_props */
218        ar9300_release_tx_queue,           /* ah_release_tx_queue */
219        ar9300_reset_tx_queue,             /* ah_reset_tx_queue */
220        ar9300_get_tx_dp,                  /* ah_get_tx_dp */
221        ar9300_set_tx_dp,                  /* ah_set_tx_dp */
222        ar9300_num_tx_pending,             /* ah_num_tx_pending */
223        ar9300_start_tx_dma,               /* ah_start_tx_dma */
224        ar9300_stop_tx_dma,                /* ah_stop_tx_dma */
225        ar9300_stop_tx_dma_indv_que,       /* ah_stop_tx_dma_indv_que */
226        ar9300_abort_tx_dma,               /* ah_abort_tx_dma */
227        ar9300_fill_tx_desc,               /* ah_fill_tx_desc */
228        ar9300_set_desc_link,              /* ah_set_desc_link */
229        ar9300_get_desc_link_ptr,          /* ah_get_desc_link_ptr */
230        ar9300_clear_tx_desc_status,       /* ah_clear_tx_desc_status */
231#ifdef ATH_SWRETRY
232        ar9300_clear_dest_mask,            /* ah_clear_dest_mask */
233#endif
234        ar9300_proc_tx_desc,               /* ah_proc_tx_desc */
235        ar9300_get_raw_tx_desc,            /* ah_get_raw_tx_desc */
236        ar9300_get_tx_rate_code,           /* ah_get_tx_rate_code */
237        AH_NULL,                           /* ah_get_tx_intr_queue */
238        ar9300_tx_req_intr_desc,           /* ah_req_tx_intr_desc */
239        ar9300_calc_tx_airtime,            /* ah_calc_tx_airtime */
240        ar9300_setup_tx_status_ring,       /* ah_setup_tx_status_ring */
241
242        /* RX Functions */
243        ar9300_get_rx_dp,                  /* ah_get_rx_dp */
244        ar9300_set_rx_dp,                  /* ah_set_rx_dp */
245        ar9300_enable_receive,             /* ah_enable_receive */
246        ar9300_stop_dma_receive,           /* ah_stop_dma_receive */
247        ar9300_start_pcu_receive,          /* ah_start_pcu_receive */
248        ar9300_stop_pcu_receive,           /* ah_stop_pcu_receive */
249        ar9300_set_multicast_filter,       /* ah_set_multicast_filter */
250        ar9300_get_rx_filter,              /* ah_get_rx_filter */
251        ar9300_set_rx_filter,              /* ah_set_rx_filter */
252        ar9300_set_rx_sel_evm,             /* ah_set_rx_sel_evm */
253        ar9300_set_rx_abort,               /* ah_set_rx_abort */
254        AH_NULL,                           /* ah_setup_rx_desc */
255        ar9300_proc_rx_desc,               /* ah_proc_rx_desc */
256        ar9300_get_rx_key_idx,             /* ah_get_rx_key_idx */
257        ar9300_proc_rx_desc_fast,          /* ah_proc_rx_desc_fast */
258        ar9300_ani_ar_poll,                /* ah_rx_monitor */
259        ar9300_process_mib_intr,           /* ah_proc_mib_event */
260
261        /* Misc Functions */
262        ar9300_get_capability,             /* ah_get_capability */
263        ar9300_set_capability,             /* ah_set_capability */
264        ar9300_get_diag_state,             /* ah_get_diag_state */
265        ar9300_get_mac_address,            /* ah_get_mac_address */
266        ar9300_set_mac_address,            /* ah_set_mac_address */
267        ar9300_get_bss_id_mask,            /* ah_get_bss_id_mask */
268        ar9300_set_bss_id_mask,            /* ah_set_bss_id_mask */
269        ar9300_set_regulatory_domain,      /* ah_set_regulatory_domain */
270        ar9300_set_led_state,              /* ah_set_led_state */
271        ar9300_set_power_led_state,        /* ah_setpowerledstate */
272        ar9300_set_network_led_state,      /* ah_setnetworkledstate */
273        ar9300_write_associd,              /* ah_write_associd */
274        ar9300_force_tsf_sync,             /* ah_force_tsf_sync */
275        ar9300_gpio_cfg_input,             /* ah_gpio_cfg_input */
276        ar9300_gpio_cfg_output,            /* ah_gpio_cfg_output */
277        ar9300_gpio_cfg_output_led_off,    /* ah_gpio_cfg_output_led_off */
278        ar9300_gpio_get,                   /* ah_gpio_get */
279        ar9300_gpio_set,                   /* ah_gpio_set */
280        ar9300_gpio_get_intr,              /* ah_gpio_get_intr */
281        ar9300_gpio_set_intr,              /* ah_gpio_set_intr */
282        ar9300_gpio_get_polarity,          /* ah_gpio_get_polarity */
283        ar9300_gpio_set_polarity,          /* ah_gpio_set_polarity */
284        ar9300_gpio_get_mask,              /* ah_gpio_get_mask */
285        ar9300_gpio_set_mask,              /* ah_gpio_set_mask */
286        ar9300_get_tsf32,                  /* ah_get_tsf32 */
287        ar9300_get_tsf64,                  /* ah_get_tsf64 */
288        ar9300_get_tsf2_32,                /* ah_get_tsf2_32 */
289        ar9300_reset_tsf,                  /* ah_reset_tsf */
290        ar9300_detect_card_present,        /* ah_detect_card_present */
291        ar9300_update_mib_mac_stats,       /* ah_update_mib_mac_stats */
292        ar9300_get_mib_mac_stats,          /* ah_get_mib_mac_stats */
293        ar9300_get_rfgain,                 /* ah_get_rf_gain */
294        ar9300_get_def_antenna,            /* ah_get_def_antenna */
295        ar9300_set_def_antenna,            /* ah_set_def_antenna */
296        ar9300_set_slot_time,              /* ah_set_slot_time */
297        ar9300_set_ack_timeout,            /* ah_set_ack_timeout */
298        ar9300_get_ack_timeout,            /* ah_get_ack_timeout */
299        ar9300_set_coverage_class,         /* ah_set_coverage_class */
300        ar9300_set_quiet,                  /* ah_set_quiet */
301        ar9300_set_antenna_switch,         /* ah_set_antenna_switch */
302        ar9300_get_desc_info,              /* ah_get_desc_info */
303        ar9300_select_ant_config,          /* ah_select_ant_config */
304        ar9300_ant_ctrl_common_get,        /* ah_ant_ctrl_common_get */
305        ar9300_enable_tpc,                 /* ah_enable_tpc */
306        AH_NULL,                           /* ah_olpc_temp_compensation */
307#if ATH_SUPPORT_CRDC
308        ar9300_chain_rssi_diff_compensation,/*ah_chain_rssi_diff_compensation*/
309#endif
310        ar9300_disable_phy_restart,        /* ah_disable_phy_restart */
311        ar9300_enable_keysearch_always,
312        ar9300_interference_is_present,    /* ah_interference_is_present */
313        ar9300_disp_tpc_tables,             /* ah_disp_tpc_tables */
314        ar9300_get_tpc_tables,              /* ah_get_tpc_tables */
315        /* Key Cache Functions */
316        ar9300_get_key_cache_size,         /* ah_get_key_cache_size */
317        ar9300_reset_key_cache_entry,      /* ah_reset_key_cache_entry */
318        ar9300_is_key_cache_entry_valid,   /* ah_is_key_cache_entry_valid */
319        ar9300_set_key_cache_entry,        /* ah_set_key_cache_entry */
320        ar9300_set_key_cache_entry_mac,    /* ah_set_key_cache_entry_mac */
321        ar9300_print_keycache,             /* ah_print_key_cache */
322
323        /* Power Management Functions */
324        ar9300_set_power_mode,             /* ah_set_power_mode */
325        ar9300_set_sm_power_mode,          /* ah_set_sm_ps_mode */
326#if ATH_WOW
327        ar9300_wow_apply_pattern,          /* ah_wow_apply_pattern */
328        ar9300_wow_enable,                 /* ah_wow_enable */
329        ar9300_wow_wake_up,                /* ah_wow_wake_up */
330#if ATH_WOW_OFFLOAD
331        ar9300_wowoffload_prep,                 /* ah_wow_offload_prep */
332        ar9300_wowoffload_post,                 /* ah_wow_offload_post */
333        ar9300_wowoffload_download_rekey_data,  /* ah_wow_offload_download_rekey_data */
334        ar9300_wowoffload_retrieve_data,        /* ah_wow_offload_retrieve_data */
335        ar9300_wowoffload_download_acer_magic,  /* ah_wow_offload_download_acer_magic */
336        ar9300_wowoffload_download_acer_swka,   /* ah_wow_offload_download_acer_swka */
337        ar9300_wowoffload_download_arp_info,    /* ah_wow_offload_download_arp_info */
338        ar9300_wowoffload_download_ns_info,     /* ah_wow_offload_download_ns_info */
339#endif /* ATH_WOW_OFFLOAD */
340#endif
341
342        /* Get Channel Noise */
343        ath_hal_get_chan_noise,            /* ah_get_chan_noise */
344        ar9300_chain_noise_floor,          /* ah_get_chain_noise_floor */
345
346        /* Beacon Functions */
347        ar9300_beacon_init,                /* ah_beacon_init */
348        ar9300_set_sta_beacon_timers,      /* ah_set_station_beacon_timers */
349
350        /* Interrupt Functions */
351        ar9300_is_interrupt_pending,       /* ah_is_interrupt_pending */
352        ar9300_get_pending_interrupts,     /* ah_get_pending_interrupts */
353        ar9300_get_interrupts,             /* ah_get_interrupts */
354        ar9300_set_interrupts,             /* ah_set_interrupts */
355        ar9300_set_intr_mitigation_timer,  /* ah_set_intr_mitigation_timer */
356        ar9300_get_intr_mitigation_timer,  /* ah_get_intr_mitigation_timer */
357	ar9300ForceVCS,
358        ar9300SetDfs3StreamFix,
359        ar9300Get3StreamSignature,
360
361        /* 11n specific functions (NOT applicable to ar9300) */
362        ar9300_set_11n_tx_desc,            /* ah_set_11n_tx_desc */
363        /* Update rxchain */
364        ar9300_set_rx_chainmask,           /*ah_set_rx_chainmask*/
365        /*Updating locationing register */
366        ar9300_update_loc_ctl_reg,         /*ah_update_loc_ctl_reg*/
367        /* Start PAPRD functions  */
368        ar9300_set_paprd_tx_desc,          /* ah_set_paprd_tx_desc */
369        ar9300_paprd_init_table,           /* ah_paprd_init_table */
370        ar9300_paprd_setup_gain_table,     /* ah_paprd_setup_gain_table */
371        ar9300_paprd_create_curve,         /* ah_paprd_create_curve */
372        ar9300_paprd_is_done,              /* ah_paprd_is_done */
373        ar9300_enable_paprd,               /* ah_PAPRDEnable */
374        ar9300_populate_paprd_single_table,/* ah_paprd_populate_table */
375        ar9300_is_tx_done,                 /* ah_is_tx_done */
376        ar9300_paprd_dec_tx_pwr,            /* ah_paprd_dec_tx_pwr*/
377        ar9300_paprd_thermal_send,         /* ah_paprd_thermal_send */
378        /* End PAPRD functions */
379        ar9300_set_11n_rate_scenario,      /* ah_set_11n_rate_scenario */
380        ar9300_set_11n_aggr_first,         /* ah_set_11n_aggr_first */
381        ar9300_set_11n_aggr_middle,        /* ah_set_11n_aggr_middle */
382        ar9300_set_11n_aggr_last,          /* ah_set_11n_aggr_last */
383        ar9300_clr_11n_aggr,               /* ah_clr_11n_aggr */
384        ar9300_set_11n_rifs_burst_middle,  /* ah_set_11n_rifs_burst_middle */
385        ar9300_set_11n_rifs_burst_last,    /* ah_set_11n_rifs_burst_last */
386        ar9300_clr_11n_rifs_burst,         /* ah_clr_11n_rifs_burst */
387        ar9300_set_11n_aggr_rifs_burst,    /* ah_set_11n_aggr_rifs_burst */
388        ar9300_set_11n_rx_rifs,            /* ah_set_11n_rx_rifs */
389        ar9300_set_smart_antenna,             /* ah_setSmartAntenna */
390        ar9300_detect_bb_hang,             /* ah_detect_bb_hang */
391        ar9300_detect_mac_hang,            /* ah_detect_mac_hang */
392        ar9300_set_immunity,               /* ah_immunity */
393        ar9300_get_hw_hangs,               /* ah_get_hang_types */
394        ar9300_set_11n_burst_duration,     /* ah_set_11n_burst_duration */
395        ar9300_set_11n_virtual_more_frag,  /* ah_set_11n_virtual_more_frag */
396        ar9300_get_11n_ext_busy,           /* ah_get_11n_ext_busy */
397        ar9300_set_11n_mac2040,            /* ah_set_11n_mac2040 */
398        ar9300_get_11n_rx_clear,           /* ah_get_11n_rx_clear */
399        ar9300_set_11n_rx_clear,           /* ah_set_11n_rx_clear */
400        ar9300_get_mib_cycle_counts_pct,   /* ah_get_mib_cycle_counts_pct */
401        ar9300_dma_reg_dump,               /* ah_dma_reg_dump */
402
403        /* force_ppm specific functions */
404        ar9300_ppm_get_rssi_dump,          /* ah_ppm_get_rssi_dump */
405        ar9300_ppm_arm_trigger,            /* ah_ppm_arm_trigger */
406        ar9300_ppm_get_trigger,            /* ah_ppm_get_trigger */
407        ar9300_ppm_force,                  /* ah_ppm_force */
408        ar9300_ppm_un_force,               /* ah_ppm_un_force */
409        ar9300_ppm_get_force_state,        /* ah_ppm_get_force_state */
410
411        ar9300_get_spur_info,              /* ah_get_spur_info */
412        ar9300_set_spur_info,              /* ah_get_spur_info */
413
414        ar9300_get_min_cca_pwr,            /* ah_ar_get_noise_floor_val */
415
416        ar9300_green_ap_ps_on_off,         /* ah_set_rx_green_ap_ps_on_off */
417        ar9300_is_single_ant_power_save_possible, /* ah_is_single_ant_power_save_possible */
418
419        /* radio measurement specific functions */
420        ar9300_get_mib_cycle_counts,       /* ah_get_mib_cycle_counts */
421        ar9300_get_vow_stats,              /* ah_get_vow_stats */
422        ar9300_clear_mib_counters,         /* ah_clear_mib_counters */
423#if ATH_GEN_RANDOMNESS
424        ar9300_get_rssi_chain0,            /* ah_get_rssi_chain0 */
425#endif
426#ifdef ATH_BT_COEX
427        /* Bluetooth Coexistence functions */
428        ar9300_set_bt_coex_info,           /* ah_set_bt_coex_info */
429        ar9300_bt_coex_config,             /* ah_bt_coex_config */
430        ar9300_bt_coex_set_qcu_thresh,     /* ah_bt_coex_set_qcu_thresh */
431        ar9300_bt_coex_set_weights,        /* ah_bt_coex_set_weights */
432        ar9300_bt_coex_setup_bmiss_thresh, /* ah_bt_coex_set_bmiss_thresh */
433        ar9300_bt_coex_set_parameter,      /* ah_bt_coex_set_parameter */
434        ar9300_bt_coex_disable,            /* ah_bt_coex_disable */
435        ar9300_bt_coex_enable,             /* ah_bt_coex_enable */
436        ar9300_get_bt_active_gpio,         /* ah_bt_coex_info*/
437        ar9300_get_wlan_active_gpio,       /* ah__coex_wlan_info*/
438#endif
439        /* Generic Timer functions */
440        ar9300_alloc_generic_timer,        /* ah_gentimer_alloc */
441        ar9300_free_generic_timer,         /* ah_gentimer_free */
442        ar9300_start_generic_timer,        /* ah_gentimer_start */
443        ar9300_stop_generic_timer,         /* ah_gentimer_stop */
444        ar9300_get_gen_timer_interrupts,   /* ah_gentimer_get_intr */
445
446        ar9300_set_dcs_mode,               /* ah_set_dcs_mode */
447        ar9300_get_dcs_mode,               /* ah_get_dcs_mode */
448
449#if ATH_ANT_DIV_COMB
450        ar9300_ant_div_comb_get_config,    /* ah_get_ant_dvi_comb_conf */
451        ar9300_ant_div_comb_set_config,    /* ah_set_ant_dvi_comb_conf */
452#endif
453
454        ar9300_get_bb_panic_info,          /* ah_get_bb_panic_info */
455        ar9300_handle_radar_bb_panic,      /* ah_handle_radar_bb_panic */
456        ar9300_set_hal_reset_reason,       /* ah_set_hal_reset_reason */
457
458#if ATH_PCIE_ERROR_MONITOR
459        ar9300_start_pcie_error_monitor,   /* ah_start_pcie_error_monitor */
460        ar9300_read_pcie_error_monitor,    /* ah_read_pcie_error_monitor*/
461        ar9300_stop_pcie_error_monitor,    /* ah_stop_pcie_error_monitor*/
462#endif /* ATH_PCIE_ERROR_MONITOR */
463
464#if ATH_SUPPORT_SPECTRAL
465        /* Spectral scan */
466        ar9300_configure_spectral_scan,    /* ah_ar_configure_spectral */
467        ar9300_get_spectral_params,        /* ah_ar_get_spectral_config */
468        ar9300_start_spectral_scan,        /* ah_ar_start_spectral_scan */
469        ar9300_stop_spectral_scan,         /* ah_ar_stop_spectral_scan */
470        ar9300_is_spectral_enabled,        /* ah_ar_is_spectral_enabled */
471        ar9300_is_spectral_active,         /* ah_ar_is_spectral_active */
472        ar9300_get_ctl_chan_nf,            /* ah_ar_get_ctl_nf */
473        ar9300_get_ext_chan_nf,            /* ah_ar_get_ext_nf */
474#endif  /*  ATH_SUPPORT_SPECTRAL */
475
476
477        ar9300_promisc_mode,               /* ah_promisc_mode */
478        ar9300_read_pktlog_reg,            /* ah_read_pktlog_reg */
479        ar9300_write_pktlog_reg,           /* ah_write_pktlog_reg */
480        ar9300_set_proxy_sta,              /* ah_set_proxy_sta */
481        ar9300_get_cal_intervals,          /* ah_get_cal_intervals */
482#if ATH_TRAFFIC_FAST_RECOVER
483        ar9300_get_pll3_sqsum_dvc,         /* ah_get_pll3_sqsum_dvc */
484#endif
485#ifdef ATH_SUPPORT_HTC
486        AH_NULL,
487#endif
488
489#ifdef ATH_TX99_DIAG
490        /* Tx99 functions */
491#ifdef ATH_SUPPORT_HTC
492        AH_NULL,
493        AH_NULL,
494        AH_NULL,
495        AH_NULL,
496        AH_NULL,
497        AH_NULL,
498        AH_NULL,
499#else
500        AH_NULL,
501        AH_NULL,
502        ar9300TX99TgtChannelPwrUpdate,		/* ah_tx99channelpwrupdate */
503        ar9300TX99TgtStart,					/* ah_tx99start */
504        ar9300TX99TgtStop,					/* ah_tx99stop */
505        ar9300TX99TgtChainmskSetup,			/* ah_tx99_chainmsk_setup */
506        ar9300TX99SetSingleCarrier,			/* ah_tx99_set_single_carrier */
507#endif
508#endif
509        ar9300_chk_rssi_update_tx_pwr,
510        ar9300_is_skip_paprd_by_greentx,   /* ah_is_skip_paprd_by_greentx */
511        ar9300_hwgreentx_set_pal_spare,    /* ah_hwgreentx_set_pal_spare */
512#if ATH_SUPPORT_MCI
513        /* MCI Coexistence Functions */
514        ar9300_mci_setup,                   /* ah_mci_setup */
515        ar9300_mci_send_message,            /* ah_mci_send_message */
516        ar9300_mci_get_interrupt,           /* ah_mci_get_interrupt */
517        ar9300_mci_state,                   /* ah_mci_state */
518        ar9300_mci_detach,                  /* ah_mci_detach */
519#endif
520        ar9300_reset_hw_beacon_proc_crc,   /* ah_reset_hw_beacon_proc_crc */
521        ar9300_get_hw_beacon_rssi,         /* ah_get_hw_beacon_rssi */
522        ar9300_set_hw_beacon_rssi_threshold,/*ah_set_hw_beacon_rssi_threshold*/
523        ar9300_reset_hw_beacon_rssi,       /* ah_reset_hw_beacon_rssi */
524        ar9300_mat_enable,                 /* ah_mat_enable */
525        ar9300_dump_keycache,              /* ah_dump_keycache */
526        ar9300_is_ani_noise_spur,         /* ah_is_ani_noise_spur */
527        ar9300_set_hw_beacon_proc,         /* ah_set_hw_beacon_proc */
528    },
529
530    ar9300_get_channel_edges,              /* ah_get_channel_edges */
531    ar9300_get_wireless_modes,             /* ah_get_wireless_modes */
532    ar9300_eeprom_read_word,               /* ah_eeprom_read */
533    AH_NULL,
534    ar9300_eeprom_dump_support,            /* ah_eeprom_dump */
535    ar9300_get_chip_power_limits,          /* ah_get_chip_power_limits */
536
537    ar9300_get_nf_adjust,                  /* ah_get_nf_adjust */
538    /* rest is zero'd by compiler */
539};
540#endif
541
542/*
543 * Read MAC version/revision information from Chip registers and initialize
544 * local data structures.
545 */
546void
547ar9300_read_revisions(struct ath_hal *ah)
548{
549    u_int32_t val;
550
551    /* XXX verify if this is the correct way to read revision on Osprey */
552    /* new SREV format for Sowl and later */
553    val = OS_REG_READ(ah, AR_HOSTIF_REG(ah, AR_SREV));
554
555    if (AH_PRIVATE(ah)->ah_devid == AR9300_DEVID_AR9340) {
556        /* XXX: AR_SREV register in Wasp reads 0 */
557        AH_PRIVATE(ah)->ah_macVersion = AR_SREV_VERSION_WASP;
558    } else if(AH_PRIVATE(ah)->ah_devid == AR9300_DEVID_QCA955X) {
559        /* XXX: AR_SREV register in Scorpion reads 0 */
560       AH_PRIVATE(ah)->ah_macVersion = AR_SREV_VERSION_SCORPION;
561    } else {
562        /*
563         * Include 6-bit Chip Type (masked to 0)
564         * to differentiate from pre-Sowl versions
565         */
566        AH_PRIVATE(ah)->ah_macVersion =
567            (val & AR_SREV_VERSION2) >> AR_SREV_TYPE2_S;
568    }
569
570
571
572
573
574#ifdef AH_SUPPORT_HORNET
575    /*
576     *  EV74984, due to Hornet 1.1 didn't update WMAC revision,
577     *  so that have to read SoC's revision ID instead
578     */
579    if (AH_PRIVATE(ah)->ah_macVersion == AR_SREV_VERSION_HORNET) {
580#define AR_SOC_RST_REVISION_ID         0xB8060090
581#define REG_READ(_reg)                 *((volatile u_int32_t *)(_reg))
582        if ((REG_READ(AR_SOC_RST_REVISION_ID) & AR_SREV_REVISION_HORNET_11_MASK)
583            == AR_SREV_REVISION_HORNET_11)
584        {
585            AH_PRIVATE(ah)->ah_macRev = AR_SREV_REVISION_HORNET_11;
586        } else {
587            AH_PRIVATE(ah)->ah_macRev = MS(val, AR_SREV_REVISION2);
588        }
589#undef REG_READ
590#undef AR_SOC_RST_REVISION_ID
591    } else
592#endif
593    if (AH_PRIVATE(ah)->ah_macVersion == AR_SREV_VERSION_WASP)
594    {
595#define AR_SOC_RST_REVISION_ID         0xB8060090
596#define REG_READ(_reg)                 *((volatile u_int32_t *)(_reg))
597
598        AH_PRIVATE(ah)->ah_macRev =
599            REG_READ(AR_SOC_RST_REVISION_ID) & AR_SREV_REVISION_WASP_MASK;
600#undef REG_READ
601#undef AR_SOC_RST_REVISION_ID
602    }
603    else
604        AH_PRIVATE(ah)->ah_macRev = MS(val, AR_SREV_REVISION2);
605
606    if (AR_SREV_JUPITER(ah) || AR_SREV_APHRODITE(ah)) {
607        AH_PRIVATE(ah)->ah_ispcie = AH_TRUE;
608    }
609    else {
610        AH_PRIVATE(ah)->ah_ispcie =
611            (val & AR_SREV_TYPE2_HOST_MODE) ? 0 : 1;
612    }
613
614}
615
616/*
617 * Attach for an AR9300 part.
618 */
619struct ath_hal *
620ar9300_attach(u_int16_t devid, HAL_SOFTC sc, HAL_BUS_TAG st,
621  HAL_BUS_HANDLE sh, uint16_t *eepromdata, HAL_STATUS *status)
622{
623    struct ath_hal_9300     *ahp;
624    struct ath_hal          *ah;
625    struct ath_hal_private  *ahpriv;
626    HAL_STATUS              ecode;
627
628    HAL_NO_INTERSPERSED_READS;
629
630    /* NB: memory is returned zero'd */
631    ahp = ar9300_new_state(devid, sc, st, sh, eepromdata, status);
632    if (ahp == AH_NULL) {
633        return AH_NULL;
634    }
635    ah = &ahp->ah_priv.h;
636    ar9300_init_offsets(ah, devid);
637    ahpriv = AH_PRIVATE(ah);
638//    AH_PRIVATE(ah)->ah_bustype = bustype;
639
640    /* FreeBSD: to make OTP work for now, provide this.. */
641    AH9300(ah)->ah_cal_mem = ath_hal_malloc(HOST_CALDATA_SIZE);
642
643    /*
644     * If eepromdata is not NULL, copy it it into ah_cal_mem.
645     */
646    if (eepromdata != NULL)
647        OS_MEMCPY(AH9300(ah)->ah_cal_mem, eepromdata, HOST_CALDATA_SIZE);
648
649    /* XXX FreeBSD: enable RX mitigation */
650    ah->ah_config.ath_hal_intr_mitigation_rx = 1;
651
652    /*
653     * XXX what's this do? Check in the qcamain driver code
654     * as to what it does.
655     */
656    ah->ah_config.ath_hal_ext_atten_margin_cfg = 0;
657
658    /* interrupt mitigation */
659#ifdef AR5416_INT_MITIGATION
660    if (ah->ah_config.ath_hal_intr_mitigation_rx != 0) {
661        ahp->ah_intr_mitigation_rx = AH_TRUE;
662    }
663#else
664    /* Enable Rx mitigation (default) */
665    ahp->ah_intr_mitigation_rx = AH_TRUE;
666    ah->ah_config.ath_hal_intr_mitigation_rx = 1;
667
668#endif
669#ifdef HOST_OFFLOAD
670    /* Reset default Rx mitigation values for Hornet */
671    if (AR_SREV_HORNET(ah)) {
672        ahp->ah_intr_mitigation_rx = AH_FALSE;
673#ifdef AR5416_INT_MITIGATION
674        ah->ah_config.ath_hal_intr_mitigation_rx = 0;
675#endif
676    }
677#endif
678
679    if (ah->ah_config.ath_hal_intr_mitigation_tx != 0) {
680        ahp->ah_intr_mitigation_tx = AH_TRUE;
681    }
682
683    /*
684     * Read back AR_WA into a permanent copy and set bits 14 and 17.
685     * We need to do this to avoid RMW of this register.
686     * Do this before calling ar9300_set_reset_reg.
687     * If not, the AR_WA register which was inited via EEPROM
688     * will get wiped out.
689     */
690    ahp->ah_wa_reg_val = OS_REG_READ(ah,  AR_HOSTIF_REG(ah, AR_WA));
691    /* Set Bits 14 and 17 in the AR_WA register. */
692    ahp->ah_wa_reg_val |=
693        AR_WA_D3_TO_L1_DISABLE | AR_WA_ASPM_TIMER_BASED_DISABLE;
694
695    if (!ar9300_set_reset_reg(ah, HAL_RESET_POWER_ON)) {    /* reset chip */
696        HALDEBUG(ah, HAL_DEBUG_RESET, "%s: couldn't reset chip\n", __func__);
697        ecode = HAL_EIO;
698        goto bad;
699    }
700
701    if (AR_SREV_JUPITER(ah)
702#if ATH_WOW_OFFLOAD
703        && !HAL_WOW_CTRL(ah, HAL_WOW_OFFLOAD_SET_4004_BIT14)
704#endif
705        )
706    {
707        /* Jupiter doesn't need bit 14 to be set. */
708        ahp->ah_wa_reg_val &= ~AR_WA_D3_TO_L1_DISABLE;
709        OS_REG_WRITE(ah, AR_HOSTIF_REG(ah, AR_WA), ahp->ah_wa_reg_val);
710    }
711
712#if ATH_SUPPORT_MCI
713    if (AR_SREV_JUPITER(ah) || AR_SREV_APHRODITE(ah)) {
714#if 0
715        ah->ah_bt_coex_set_weights = ar9300_mci_bt_coex_set_weights;
716        ah->ah_bt_coex_disable = ar9300_mci_bt_coex_disable;
717        ah->ah_bt_coex_enable = ar9300_mci_bt_coex_enable;
718#endif
719        ahp->ah_mci_ready = AH_FALSE;
720        ahp->ah_mci_bt_state = MCI_BT_SLEEP;
721        ahp->ah_mci_coex_major_version_wlan = MCI_GPM_COEX_MAJOR_VERSION_WLAN;
722        ahp->ah_mci_coex_minor_version_wlan = MCI_GPM_COEX_MINOR_VERSION_WLAN;
723        ahp->ah_mci_coex_major_version_bt = MCI_GPM_COEX_MAJOR_VERSION_DEFAULT;
724        ahp->ah_mci_coex_minor_version_bt = MCI_GPM_COEX_MINOR_VERSION_DEFAULT;
725        ahp->ah_mci_coex_bt_version_known = AH_FALSE;
726        ahp->ah_mci_coex_2g5g_update = AH_TRUE; /* track if 2g5g status sent */
727        /* will be updated before boot up sequence */
728        ahp->ah_mci_coex_is_2g = AH_TRUE;
729        ahp->ah_mci_coex_wlan_channels_update = AH_FALSE;
730        ahp->ah_mci_coex_wlan_channels[0] = 0x00000000;
731        ahp->ah_mci_coex_wlan_channels[1] = 0xffffffff;
732        ahp->ah_mci_coex_wlan_channels[2] = 0xffffffff;
733        ahp->ah_mci_coex_wlan_channels[3] = 0x7fffffff;
734        ahp->ah_mci_query_bt = AH_TRUE; /* In case WLAN start after BT */
735        ahp->ah_mci_unhalt_bt_gpm = AH_TRUE; /* Send UNHALT at beginning */
736        ahp->ah_mci_halted_bt_gpm = AH_FALSE; /* Allow first HALT */
737        ahp->ah_mci_need_flush_btinfo = AH_FALSE;
738        ahp->ah_mci_wlan_cal_seq = 0;
739        ahp->ah_mci_wlan_cal_done = 0;
740    }
741#endif /* ATH_SUPPORT_MCI */
742
743#if ATH_WOW_OFFLOAD
744    ahp->ah_mcast_filter_l32_set = 0;
745    ahp->ah_mcast_filter_u32_set = 0;
746#endif
747
748    if (AR_SREV_HORNET(ah)) {
749#ifdef AH_SUPPORT_HORNET
750        if (!AR_SREV_HORNET_11(ah)) {
751            /*
752             * Do not check bootstrap register, which cannot be trusted
753             * due to s26 switch issue on CUS164/AP121.
754             */
755            ahp->clk_25mhz = 1;
756            HALDEBUG(AH_NULL, HAL_DEBUG_UNMASKABLE, "Bootstrap clock 25MHz\n");
757        } else {
758            /* check bootstrap clock setting */
759#define AR_SOC_SEL_25M_40M         0xB80600AC
760#define REG_WRITE(_reg, _val)    *((volatile u_int32_t *)(_reg)) = (_val);
761#define REG_READ(_reg)          (*((volatile u_int32_t *)(_reg)))
762            if (REG_READ(AR_SOC_SEL_25M_40M) & 0x1) {
763                ahp->clk_25mhz = 0;
764                HALDEBUG(AH_NULL, HAL_DEBUG_UNMASKABLE,
765                    "Bootstrap clock 40MHz\n");
766            } else {
767                ahp->clk_25mhz = 1;
768                HALDEBUG(AH_NULL, HAL_DEBUG_UNMASKABLE,
769                    "Bootstrap clock 25MHz\n");
770            }
771#undef REG_READ
772#undef REG_WRITE
773#undef AR_SOC_SEL_25M_40M
774        }
775#endif /* AH_SUPPORT_HORNET */
776    }
777
778    if (AR_SREV_WASP(ah) || AR_SREV_SCORPION(ah)) {
779        /* check bootstrap clock setting */
780#define AR9340_SOC_SEL_25M_40M         0xB80600B0
781#define AR9340_REF_CLK_40              (1 << 4) /* 0 - 25MHz   1 - 40 MHz */
782#define REG_READ(_reg)          (*((volatile u_int32_t *)(_reg)))
783        if (REG_READ(AR9340_SOC_SEL_25M_40M) & AR9340_REF_CLK_40) {
784            ahp->clk_25mhz = 0;
785            HALDEBUG(AH_NULL, HAL_DEBUG_UNMASKABLE, "Bootstrap clock 40MHz\n");
786        } else {
787            ahp->clk_25mhz = 1;
788            HALDEBUG(AH_NULL, HAL_DEBUG_UNMASKABLE, "Bootstrap clock 25MHz\n");
789        }
790#undef REG_READ
791#undef AR9340_SOC_SEL_25M_40M
792#undef AR9340_REF_CLK_40
793    }
794    ar9300_init_pll(ah, AH_NULL);
795
796    if (!ar9300_set_power_mode(ah, HAL_PM_AWAKE, AH_TRUE)) {
797        HALDEBUG(ah, HAL_DEBUG_RESET, "%s: couldn't wakeup chip\n", __func__);
798        ecode = HAL_EIO;
799        goto bad;
800    }
801
802    /* No serialization of Register Accesses needed. */
803    ah->ah_config.ah_serialise_reg_war = SER_REG_MODE_OFF;
804    HALDEBUG(ah, HAL_DEBUG_RESET, "%s: ah_serialise_reg_war is %d\n",
805             __func__, ah->ah_config.ah_serialise_reg_war);
806
807    /*
808     * Add mac revision check when needed.
809     * - Osprey 1.0 and 2.0 no longer supported.
810     */
811    if (((ahpriv->ah_macVersion == AR_SREV_VERSION_OSPREY) &&
812          (ahpriv->ah_macRev <= AR_SREV_REVISION_OSPREY_20)) ||
813        (ahpriv->ah_macVersion != AR_SREV_VERSION_OSPREY &&
814        ahpriv->ah_macVersion != AR_SREV_VERSION_WASP &&
815        ahpriv->ah_macVersion != AR_SREV_VERSION_HORNET &&
816        ahpriv->ah_macVersion != AR_SREV_VERSION_POSEIDON &&
817        ahpriv->ah_macVersion != AR_SREV_VERSION_SCORPION &&
818        ahpriv->ah_macVersion != AR_SREV_VERSION_JUPITER &&
819        ahpriv->ah_macVersion != AR_SREV_VERSION_APHRODITE) ) {
820        HALDEBUG(ah, HAL_DEBUG_RESET,
821            "%s: Mac Chip Rev 0x%02x.%x is not supported by this driver\n",
822            __func__,
823            ahpriv->ah_macVersion,
824            ahpriv->ah_macRev);
825        ecode = HAL_ENOTSUPP;
826        goto bad;
827    }
828
829    AH_PRIVATE(ah)->ah_phyRev = OS_REG_READ(ah, AR_PHY_CHIP_ID);
830
831    /* Setup supported calibrations */
832    ahp->ah_iq_cal_data.cal_data = &iq_cal_single_sample;
833    ahp->ah_supp_cals = IQ_MISMATCH_CAL;
834
835    /* Enable ANI */
836    ahp->ah_ani_function = HAL_ANI_ALL;
837
838    /* Enable RIFS */
839    ahp->ah_rifs_enabled = AH_TRUE;
840
841    HALDEBUG(ah, HAL_DEBUG_RESET,
842        "%s: This Mac Chip Rev 0x%02x.%x is \n", __func__,
843        ahpriv->ah_macVersion,
844        ahpriv->ah_macRev);
845
846    if (AR_SREV_HORNET_12(ah)) {
847        /* mac */
848        INIT_INI_ARRAY(&ahp->ah_ini_mac[ATH_INI_PRE], NULL, 0, 0);
849        INIT_INI_ARRAY(&ahp->ah_ini_mac[ATH_INI_CORE],
850            ar9331_hornet1_2_mac_core,
851            ARRAY_LENGTH(ar9331_hornet1_2_mac_core), 2);
852        INIT_INI_ARRAY(&ahp->ah_ini_mac[ATH_INI_POST],
853            ar9331_hornet1_2_mac_postamble,
854            ARRAY_LENGTH(ar9331_hornet1_2_mac_postamble), 5);
855
856        /* bb */
857        INIT_INI_ARRAY(&ahp->ah_ini_bb[ATH_INI_PRE], NULL, 0, 0);
858        INIT_INI_ARRAY(&ahp->ah_ini_bb[ATH_INI_CORE],
859            ar9331_hornet1_2_baseband_core,
860            ARRAY_LENGTH(ar9331_hornet1_2_baseband_core), 2);
861        INIT_INI_ARRAY(&ahp->ah_ini_bb[ATH_INI_POST],
862            ar9331_hornet1_2_baseband_postamble,
863            ARRAY_LENGTH(ar9331_hornet1_2_baseband_postamble), 5);
864
865        /* radio */
866        INIT_INI_ARRAY(&ahp->ah_ini_radio[ATH_INI_PRE], NULL, 0, 0);
867        INIT_INI_ARRAY(&ahp->ah_ini_radio[ATH_INI_CORE],
868            ar9331_hornet1_2_radio_core,
869            ARRAY_LENGTH(ar9331_hornet1_2_radio_core), 2);
870        INIT_INI_ARRAY(&ahp->ah_ini_radio[ATH_INI_POST], NULL, 0, 0);
871
872        /* soc */
873        INIT_INI_ARRAY(&ahp->ah_ini_soc[ATH_INI_PRE],
874            ar9331_hornet1_2_soc_preamble,
875            ARRAY_LENGTH(ar9331_hornet1_2_soc_preamble), 2);
876        INIT_INI_ARRAY(&ahp->ah_ini_soc[ATH_INI_CORE], NULL, 0, 0);
877        INIT_INI_ARRAY(&ahp->ah_ini_soc[ATH_INI_POST],
878            ar9331_hornet1_2_soc_postamble,
879            ARRAY_LENGTH(ar9331_hornet1_2_soc_postamble), 2);
880
881        /* rx/tx gain */
882        INIT_INI_ARRAY(&ahp->ah_ini_modes_rxgain,
883            ar9331_common_rx_gain_hornet1_2,
884            ARRAY_LENGTH(ar9331_common_rx_gain_hornet1_2), 2);
885        INIT_INI_ARRAY(&ahp->ah_ini_modes_txgain,
886            ar9331_modes_lowest_ob_db_tx_gain_hornet1_2,
887            ARRAY_LENGTH(ar9331_modes_lowest_ob_db_tx_gain_hornet1_2), 5);
888
889        ah->ah_config.ath_hal_pcie_power_save_enable = 0;
890
891        /* Japan 2484Mhz CCK settings */
892        INIT_INI_ARRAY(&ahp->ah_ini_japan2484,
893            ar9331_hornet1_2_baseband_core_txfir_coeff_japan_2484,
894            ARRAY_LENGTH(
895                ar9331_hornet1_2_baseband_core_txfir_coeff_japan_2484), 2);
896
897#if 0 /* ATH_WOW */
898        /* SerDes values during WOW sleep */
899        INIT_INI_ARRAY(&ahp->ah_ini_pcie_serdes_wow, ar9300_pcie_phy_awow,
900                ARRAY_LENGTH(ar9300_pcie_phy_awow), 2);
901#endif
902
903        /* additional clock settings */
904        if (AH9300(ah)->clk_25mhz) {
905            INIT_INI_ARRAY(&ahp->ah_ini_modes_additional,
906                ar9331_hornet1_2_xtal_25M,
907                ARRAY_LENGTH(ar9331_hornet1_2_xtal_25M), 2);
908        } else {
909            INIT_INI_ARRAY(&ahp->ah_ini_modes_additional,
910                ar9331_hornet1_2_xtal_40M,
911                ARRAY_LENGTH(ar9331_hornet1_2_xtal_40M), 2);
912        }
913
914    } else if (AR_SREV_HORNET_11(ah)) {
915        /* mac */
916        INIT_INI_ARRAY(&ahp->ah_ini_mac[ATH_INI_PRE], NULL, 0, 0);
917        INIT_INI_ARRAY(&ahp->ah_ini_mac[ATH_INI_CORE],
918            ar9331_hornet1_1_mac_core,
919            ARRAY_LENGTH(ar9331_hornet1_1_mac_core), 2);
920        INIT_INI_ARRAY(&ahp->ah_ini_mac[ATH_INI_POST],
921            ar9331_hornet1_1_mac_postamble,
922            ARRAY_LENGTH(ar9331_hornet1_1_mac_postamble), 5);
923
924        /* bb */
925        INIT_INI_ARRAY(&ahp->ah_ini_bb[ATH_INI_PRE], NULL, 0, 0);
926        INIT_INI_ARRAY(&ahp->ah_ini_bb[ATH_INI_CORE],
927            ar9331_hornet1_1_baseband_core,
928            ARRAY_LENGTH(ar9331_hornet1_1_baseband_core), 2);
929        INIT_INI_ARRAY(&ahp->ah_ini_bb[ATH_INI_POST],
930            ar9331_hornet1_1_baseband_postamble,
931            ARRAY_LENGTH(ar9331_hornet1_1_baseband_postamble), 5);
932
933        /* radio */
934        INIT_INI_ARRAY(&ahp->ah_ini_radio[ATH_INI_PRE], NULL, 0, 0);
935        INIT_INI_ARRAY(&ahp->ah_ini_radio[ATH_INI_CORE],
936            ar9331_hornet1_1_radio_core,
937            ARRAY_LENGTH(ar9331_hornet1_1_radio_core), 2);
938        INIT_INI_ARRAY(&ahp->ah_ini_radio[ATH_INI_POST], NULL, 0, 0);
939
940        /* soc */
941        INIT_INI_ARRAY(&ahp->ah_ini_soc[ATH_INI_PRE],
942            ar9331_hornet1_1_soc_preamble,
943            ARRAY_LENGTH(ar9331_hornet1_1_soc_preamble), 2);
944        INIT_INI_ARRAY(&ahp->ah_ini_soc[ATH_INI_CORE], NULL, 0, 0);
945        INIT_INI_ARRAY(&ahp->ah_ini_soc[ATH_INI_POST],
946            ar9331_hornet1_1_soc_postamble,
947            ARRAY_LENGTH(ar9331_hornet1_1_soc_postamble), 2);
948
949        /* rx/tx gain */
950        INIT_INI_ARRAY(&ahp->ah_ini_modes_rxgain,
951            ar9331_common_rx_gain_hornet1_1,
952            ARRAY_LENGTH(ar9331_common_rx_gain_hornet1_1), 2);
953        INIT_INI_ARRAY(&ahp->ah_ini_modes_txgain,
954            ar9331_modes_lowest_ob_db_tx_gain_hornet1_1,
955            ARRAY_LENGTH(ar9331_modes_lowest_ob_db_tx_gain_hornet1_1), 5);
956
957        ah->ah_config.ath_hal_pcie_power_save_enable = 0;
958
959        /* Japan 2484Mhz CCK settings */
960        INIT_INI_ARRAY(&ahp->ah_ini_japan2484,
961            ar9331_hornet1_1_baseband_core_txfir_coeff_japan_2484,
962            ARRAY_LENGTH(
963                ar9331_hornet1_1_baseband_core_txfir_coeff_japan_2484), 2);
964
965#if 0 /* ATH_WOW */
966        /* SerDes values during WOW sleep */
967        INIT_INI_ARRAY(&ahp->ah_ini_pcie_serdes_wow, ar9300_pcie_phy_awow,
968                       N(ar9300_pcie_phy_awow), 2);
969#endif
970
971        /* additional clock settings */
972        if (AH9300(ah)->clk_25mhz) {
973            INIT_INI_ARRAY(&ahp->ah_ini_modes_additional,
974                ar9331_hornet1_1_xtal_25M,
975                ARRAY_LENGTH(ar9331_hornet1_1_xtal_25M), 2);
976        } else {
977            INIT_INI_ARRAY(&ahp->ah_ini_modes_additional,
978                ar9331_hornet1_1_xtal_40M,
979                ARRAY_LENGTH(ar9331_hornet1_1_xtal_40M), 2);
980        }
981
982       } else if (AR_SREV_POSEIDON_11_OR_LATER(ah)) {
983        /* mac */
984        INIT_INI_ARRAY(&ahp->ah_ini_mac[ATH_INI_PRE], NULL, 0, 0);
985        INIT_INI_ARRAY(&ahp->ah_ini_mac[ATH_INI_CORE],
986            ar9485_poseidon1_1_mac_core,
987            ARRAY_LENGTH( ar9485_poseidon1_1_mac_core), 2);
988        INIT_INI_ARRAY(&ahp->ah_ini_mac[ATH_INI_POST],
989            ar9485_poseidon1_1_mac_postamble,
990            ARRAY_LENGTH(ar9485_poseidon1_1_mac_postamble), 5);
991
992        /* bb */
993        INIT_INI_ARRAY(&ahp->ah_ini_bb[ATH_INI_PRE],
994            ar9485_poseidon1_1, ARRAY_LENGTH(ar9485_poseidon1_1), 2);
995        INIT_INI_ARRAY(&ahp->ah_ini_bb[ATH_INI_CORE],
996            ar9485_poseidon1_1_baseband_core,
997            ARRAY_LENGTH(ar9485_poseidon1_1_baseband_core), 2);
998        INIT_INI_ARRAY(&ahp->ah_ini_bb[ATH_INI_POST],
999            ar9485_poseidon1_1_baseband_postamble,
1000            ARRAY_LENGTH(ar9485_poseidon1_1_baseband_postamble), 5);
1001
1002        /* radio */
1003        INIT_INI_ARRAY(&ahp->ah_ini_radio[ATH_INI_PRE], NULL, 0, 0);
1004        INIT_INI_ARRAY(&ahp->ah_ini_radio[ATH_INI_CORE],
1005            ar9485_poseidon1_1_radio_core,
1006            ARRAY_LENGTH(ar9485_poseidon1_1_radio_core), 2);
1007        INIT_INI_ARRAY(&ahp->ah_ini_radio[ATH_INI_POST],
1008            ar9485_poseidon1_1_radio_postamble,
1009            ARRAY_LENGTH(ar9485_poseidon1_1_radio_postamble), 2);
1010
1011        /* soc */
1012        INIT_INI_ARRAY(&ahp->ah_ini_soc[ATH_INI_PRE],
1013            ar9485_poseidon1_1_soc_preamble,
1014            ARRAY_LENGTH(ar9485_poseidon1_1_soc_preamble), 2);
1015
1016        INIT_INI_ARRAY(&ahp->ah_ini_soc[ATH_INI_CORE], NULL, 0, 0);
1017        INIT_INI_ARRAY(&ahp->ah_ini_soc[ATH_INI_POST], NULL, 0, 0);
1018
1019        /* rx/tx gain */
1020        INIT_INI_ARRAY(&ahp->ah_ini_modes_rxgain,
1021            ar9485_common_wo_xlna_rx_gain_poseidon1_1,
1022            ARRAY_LENGTH(ar9485_common_wo_xlna_rx_gain_poseidon1_1), 2);
1023        INIT_INI_ARRAY(&ahp->ah_ini_modes_txgain,
1024            ar9485_modes_lowest_ob_db_tx_gain_poseidon1_1,
1025            ARRAY_LENGTH(ar9485_modes_lowest_ob_db_tx_gain_poseidon1_1), 5);
1026
1027        /* Japan 2484Mhz CCK settings */
1028        INIT_INI_ARRAY(&ahp->ah_ini_japan2484,
1029            ar9485_poseidon1_1_baseband_core_txfir_coeff_japan_2484,
1030            ARRAY_LENGTH(
1031                ar9485_poseidon1_1_baseband_core_txfir_coeff_japan_2484), 2);
1032
1033        /* Load PCIE SERDES settings from INI */
1034        if (ah->ah_config.ath_hal_pcie_clock_req) {
1035            /* Pci-e Clock Request = 1 */
1036            if (ah->ah_config.ath_hal_pll_pwr_save
1037                & AR_PCIE_PLL_PWRSAVE_CONTROL)
1038            {
1039                /* Sleep Setting */
1040                if (ah->ah_config.ath_hal_pll_pwr_save &
1041                    AR_PCIE_PLL_PWRSAVE_ON_D3)
1042                {
1043                    INIT_INI_ARRAY(&ahp->ah_ini_pcie_serdes,
1044                        ar9485_poseidon1_1_pcie_phy_clkreq_enable_L1,
1045                        ARRAY_LENGTH(
1046                           ar9485_poseidon1_1_pcie_phy_clkreq_enable_L1),
1047                        2);
1048                } else {
1049                    INIT_INI_ARRAY(&ahp->ah_ini_pcie_serdes,
1050                        ar9485_poseidon1_1_pcie_phy_pll_on_clkreq_enable_L1,
1051                        ARRAY_LENGTH(
1052                           ar9485_poseidon1_1_pcie_phy_pll_on_clkreq_enable_L1),
1053                        2);
1054                }
1055                /* Awake Setting */
1056                if (ah->ah_config.ath_hal_pll_pwr_save &
1057                    AR_PCIE_PLL_PWRSAVE_ON_D0)
1058                {
1059                    INIT_INI_ARRAY(&ahp->ah_ini_pcie_serdes_low_power,
1060                        ar9485_poseidon1_1_pcie_phy_clkreq_enable_L1,
1061                        ARRAY_LENGTH(
1062                           ar9485_poseidon1_1_pcie_phy_clkreq_enable_L1),
1063                        2);
1064                } else {
1065                    INIT_INI_ARRAY(&ahp->ah_ini_pcie_serdes_low_power,
1066                        ar9485_poseidon1_1_pcie_phy_pll_on_clkreq_enable_L1,
1067                        ARRAY_LENGTH(
1068                           ar9485_poseidon1_1_pcie_phy_pll_on_clkreq_enable_L1),
1069                        2);
1070                }
1071
1072            } else {
1073                /*Use driver default setting*/
1074                /* Sleep Setting */
1075                INIT_INI_ARRAY(&ahp->ah_ini_pcie_serdes,
1076                    ar9485_poseidon1_1_pcie_phy_clkreq_enable_L1,
1077                    ARRAY_LENGTH(ar9485_poseidon1_1_pcie_phy_clkreq_enable_L1),
1078                    2);
1079                /* Awake Setting */
1080                INIT_INI_ARRAY(&ahp->ah_ini_pcie_serdes_low_power,
1081                    ar9485_poseidon1_1_pcie_phy_clkreq_enable_L1,
1082                    ARRAY_LENGTH(ar9485_poseidon1_1_pcie_phy_clkreq_enable_L1),
1083                    2);
1084            }
1085        } else {
1086            /* Pci-e Clock Request = 0 */
1087            if (ah->ah_config.ath_hal_pll_pwr_save
1088                & AR_PCIE_PLL_PWRSAVE_CONTROL)
1089            {
1090                /* Sleep Setting */
1091                if (ah->ah_config.ath_hal_pll_pwr_save &
1092                    AR_PCIE_PLL_PWRSAVE_ON_D3)
1093                {
1094                    INIT_INI_ARRAY(&ahp->ah_ini_pcie_serdes,
1095                        ar9485_poseidon1_1_pcie_phy_clkreq_disable_L1,
1096                        ARRAY_LENGTH(
1097                          ar9485_poseidon1_1_pcie_phy_clkreq_disable_L1),
1098                        2);
1099                } else {
1100                    INIT_INI_ARRAY(&ahp->ah_ini_pcie_serdes,
1101                        ar9485_poseidon1_1_pcie_phy_pll_on_clkreq_disable_L1,
1102                        ARRAY_LENGTH(
1103                          ar9485_poseidon1_1_pcie_phy_pll_on_clkreq_disable_L1),
1104                        2);
1105                }
1106                /* Awake Setting */
1107                if (ah->ah_config.ath_hal_pll_pwr_save &
1108                    AR_PCIE_PLL_PWRSAVE_ON_D0)
1109                {
1110                    INIT_INI_ARRAY(&ahp->ah_ini_pcie_serdes_low_power,
1111                        ar9485_poseidon1_1_pcie_phy_clkreq_disable_L1,
1112                        ARRAY_LENGTH(
1113                          ar9485_poseidon1_1_pcie_phy_clkreq_disable_L1),
1114                        2);
1115                } else {
1116                    INIT_INI_ARRAY(&ahp->ah_ini_pcie_serdes_low_power,
1117                        ar9485_poseidon1_1_pcie_phy_pll_on_clkreq_disable_L1,
1118                        ARRAY_LENGTH(
1119                          ar9485_poseidon1_1_pcie_phy_pll_on_clkreq_disable_L1),
1120                        2);
1121                }
1122
1123            } else {
1124                /*Use driver default setting*/
1125                /* Sleep Setting */
1126                INIT_INI_ARRAY(&ahp->ah_ini_pcie_serdes,
1127                    ar9485_poseidon1_1_pcie_phy_clkreq_disable_L1,
1128                    ARRAY_LENGTH(ar9485_poseidon1_1_pcie_phy_clkreq_disable_L1),
1129                    2);
1130                /* Awake Setting */
1131                INIT_INI_ARRAY(&ahp->ah_ini_pcie_serdes_low_power,
1132                    ar9485_poseidon1_1_pcie_phy_clkreq_disable_L1,
1133                    ARRAY_LENGTH(ar9485_poseidon1_1_pcie_phy_clkreq_disable_L1),
1134                    2);
1135            }
1136        }
1137        /* pcie ps setting will honor registry setting, default is 0 */
1138        //ah->ah_config.ath_hal_pciePowerSaveEnable = 0;
1139   } else if (AR_SREV_POSEIDON(ah)) {
1140        /* mac */
1141        INIT_INI_ARRAY(&ahp->ah_ini_mac[ATH_INI_PRE], NULL, 0, 0);
1142        INIT_INI_ARRAY(&ahp->ah_ini_mac[ATH_INI_CORE],
1143            ar9485_poseidon1_0_mac_core,
1144            ARRAY_LENGTH(ar9485_poseidon1_0_mac_core), 2);
1145        INIT_INI_ARRAY(&ahp->ah_ini_mac[ATH_INI_POST],
1146            ar9485_poseidon1_0_mac_postamble,
1147            ARRAY_LENGTH(ar9485_poseidon1_0_mac_postamble), 5);
1148
1149        /* bb */
1150        INIT_INI_ARRAY(&ahp->ah_ini_bb[ATH_INI_PRE],
1151            ar9485_poseidon1_0,
1152            ARRAY_LENGTH(ar9485_poseidon1_0), 2);
1153        INIT_INI_ARRAY(&ahp->ah_ini_bb[ATH_INI_CORE],
1154            ar9485_poseidon1_0_baseband_core,
1155            ARRAY_LENGTH(ar9485_poseidon1_0_baseband_core), 2);
1156        INIT_INI_ARRAY(&ahp->ah_ini_bb[ATH_INI_POST],
1157            ar9485_poseidon1_0_baseband_postamble,
1158            ARRAY_LENGTH(ar9485_poseidon1_0_baseband_postamble), 5);
1159
1160        /* radio */
1161        INIT_INI_ARRAY(&ahp->ah_ini_radio[ATH_INI_PRE], NULL, 0, 0);
1162        INIT_INI_ARRAY(&ahp->ah_ini_radio[ATH_INI_CORE],
1163            ar9485_poseidon1_0_radio_core,
1164            ARRAY_LENGTH(ar9485_poseidon1_0_radio_core), 2);
1165        INIT_INI_ARRAY(&ahp->ah_ini_radio[ATH_INI_POST],
1166            ar9485_poseidon1_0_radio_postamble,
1167            ARRAY_LENGTH(ar9485_poseidon1_0_radio_postamble), 2);
1168
1169        /* soc */
1170        INIT_INI_ARRAY(&ahp->ah_ini_soc[ATH_INI_PRE],
1171            ar9485_poseidon1_0_soc_preamble,
1172            ARRAY_LENGTH(ar9485_poseidon1_0_soc_preamble), 2);
1173        INIT_INI_ARRAY(&ahp->ah_ini_soc[ATH_INI_CORE], NULL, 0, 0);
1174        INIT_INI_ARRAY(&ahp->ah_ini_soc[ATH_INI_POST], NULL, 0, 0);
1175
1176        /* rx/tx gain */
1177        INIT_INI_ARRAY(&ahp->ah_ini_modes_rxgain,
1178            ar9485Common_wo_xlna_rx_gain_poseidon1_0,
1179            ARRAY_LENGTH(ar9485Common_wo_xlna_rx_gain_poseidon1_0), 2);
1180        INIT_INI_ARRAY(&ahp->ah_ini_modes_txgain,
1181            ar9485Modes_lowest_ob_db_tx_gain_poseidon1_0,
1182            ARRAY_LENGTH(ar9485Modes_lowest_ob_db_tx_gain_poseidon1_0), 5);
1183
1184        /* Japan 2484Mhz CCK settings */
1185        INIT_INI_ARRAY(&ahp->ah_ini_japan2484,
1186            ar9485_poseidon1_0_baseband_core_txfir_coeff_japan_2484,
1187            ARRAY_LENGTH(
1188                ar9485_poseidon1_0_baseband_core_txfir_coeff_japan_2484), 2);
1189
1190        /* Load PCIE SERDES settings from INI */
1191        if (ah->ah_config.ath_hal_pcie_clock_req) {
1192            /* Pci-e Clock Request = 1 */
1193            if (ah->ah_config.ath_hal_pll_pwr_save
1194                & AR_PCIE_PLL_PWRSAVE_CONTROL)
1195            {
1196                /* Sleep Setting */
1197                if (ah->ah_config.ath_hal_pll_pwr_save &
1198                    AR_PCIE_PLL_PWRSAVE_ON_D3)
1199                {
1200                    INIT_INI_ARRAY(&ahp->ah_ini_pcie_serdes,
1201                        ar9485_poseidon1_0_pcie_phy_clkreq_enable_L1,
1202                        ARRAY_LENGTH(
1203                           ar9485_poseidon1_0_pcie_phy_clkreq_enable_L1),
1204                        2);
1205                } else {
1206                    INIT_INI_ARRAY(&ahp->ah_ini_pcie_serdes,
1207                        ar9485_poseidon1_0_pcie_phy_pll_on_clkreq_enable_L1,
1208                        ARRAY_LENGTH(
1209                           ar9485_poseidon1_0_pcie_phy_pll_on_clkreq_enable_L1),
1210                        2);
1211                }
1212                /* Awake Setting */
1213                if (ah->ah_config.ath_hal_pll_pwr_save &
1214                    AR_PCIE_PLL_PWRSAVE_ON_D0)
1215                {
1216                    INIT_INI_ARRAY(&ahp->ah_ini_pcie_serdes_low_power,
1217                        ar9485_poseidon1_0_pcie_phy_clkreq_enable_L1,
1218                        ARRAY_LENGTH(
1219                           ar9485_poseidon1_0_pcie_phy_clkreq_enable_L1),
1220                        2);
1221                } else {
1222                    INIT_INI_ARRAY(&ahp->ah_ini_pcie_serdes_low_power,
1223                        ar9485_poseidon1_0_pcie_phy_pll_on_clkreq_enable_L1,
1224                        ARRAY_LENGTH(
1225                           ar9485_poseidon1_0_pcie_phy_pll_on_clkreq_enable_L1),
1226                        2);
1227                }
1228
1229            } else {
1230                /*Use driver default setting*/
1231                /* Sleep Setting */
1232                INIT_INI_ARRAY(&ahp->ah_ini_pcie_serdes,
1233                    ar9485_poseidon1_0_pcie_phy_pll_on_clkreq_enable_L1,
1234                    ARRAY_LENGTH(
1235                        ar9485_poseidon1_0_pcie_phy_pll_on_clkreq_enable_L1),
1236                    2);
1237                /* Awake Setting */
1238                INIT_INI_ARRAY(&ahp->ah_ini_pcie_serdes_low_power,
1239                    ar9485_poseidon1_0_pcie_phy_pll_on_clkreq_enable_L1,
1240                    ARRAY_LENGTH(
1241                        ar9485_poseidon1_0_pcie_phy_pll_on_clkreq_enable_L1),
1242                    2);
1243            }
1244        } else {
1245            /* Pci-e Clock Request = 0 */
1246            if (ah->ah_config.ath_hal_pll_pwr_save
1247                & AR_PCIE_PLL_PWRSAVE_CONTROL)
1248            {
1249                /* Sleep Setting */
1250                if (ah->ah_config.ath_hal_pll_pwr_save &
1251                    AR_PCIE_PLL_PWRSAVE_ON_D3)
1252                {
1253                    INIT_INI_ARRAY(&ahp->ah_ini_pcie_serdes,
1254                        ar9485_poseidon1_0_pcie_phy_clkreq_disable_L1,
1255                        ARRAY_LENGTH(
1256                          ar9485_poseidon1_0_pcie_phy_clkreq_disable_L1),
1257                        2);
1258                } else {
1259                    INIT_INI_ARRAY(&ahp->ah_ini_pcie_serdes,
1260                        ar9485_poseidon1_0_pcie_phy_pll_on_clkreq_disable_L1,
1261                        ARRAY_LENGTH(
1262                          ar9485_poseidon1_0_pcie_phy_pll_on_clkreq_disable_L1),
1263                        2);
1264                }
1265                /* Awake Setting */
1266                if (ah->ah_config.ath_hal_pll_pwr_save &
1267                    AR_PCIE_PLL_PWRSAVE_ON_D0)
1268                {
1269                    INIT_INI_ARRAY(&ahp->ah_ini_pcie_serdes_low_power,
1270                        ar9485_poseidon1_0_pcie_phy_clkreq_disable_L1,
1271                        ARRAY_LENGTH(
1272                          ar9485_poseidon1_0_pcie_phy_clkreq_disable_L1),
1273                        2);
1274                } else {
1275                    INIT_INI_ARRAY(&ahp->ah_ini_pcie_serdes_low_power,
1276                        ar9485_poseidon1_0_pcie_phy_pll_on_clkreq_disable_L1,
1277                        ARRAY_LENGTH(
1278                          ar9485_poseidon1_0_pcie_phy_pll_on_clkreq_disable_L1),
1279                        2);
1280                }
1281
1282            } else {
1283                /*Use driver default setting*/
1284                /* Sleep Setting */
1285                INIT_INI_ARRAY(&ahp->ah_ini_pcie_serdes,
1286                    ar9485_poseidon1_0_pcie_phy_pll_on_clkreq_disable_L1,
1287                    ARRAY_LENGTH(
1288                        ar9485_poseidon1_0_pcie_phy_pll_on_clkreq_disable_L1),
1289                    2);
1290                /* Awake Setting */
1291                INIT_INI_ARRAY(&ahp->ah_ini_pcie_serdes_low_power,
1292                    ar9485_poseidon1_0_pcie_phy_pll_on_clkreq_disable_L1,
1293                    ARRAY_LENGTH(
1294                        ar9485_poseidon1_0_pcie_phy_pll_on_clkreq_disable_L1),
1295                    2);
1296            }
1297        }
1298        /* pcie ps setting will honor registry setting, default is 0 */
1299        /*ah->ah_config.ath_hal_pcie_power_save_enable = 0;*/
1300
1301#if 0 /* ATH_WOW */
1302        /* SerDes values during WOW sleep */
1303        INIT_INI_ARRAY(&ahp->ah_ini_pcie_serdes_wow, ar9300_pcie_phy_awow,
1304                       ARRAY_LENGTH(ar9300_pcie_phy_awow), 2);
1305#endif
1306
1307    } else if (AR_SREV_WASP(ah)) {
1308        /* mac */
1309        INIT_INI_ARRAY(&ahp->ah_ini_mac[ATH_INI_PRE], NULL, 0, 0);
1310        INIT_INI_ARRAY(&ahp->ah_ini_mac[ATH_INI_CORE],
1311            ar9340_wasp_1p0_mac_core,
1312            ARRAY_LENGTH(ar9340_wasp_1p0_mac_core), 2);
1313        INIT_INI_ARRAY(&ahp->ah_ini_mac[ATH_INI_POST],
1314            ar9340_wasp_1p0_mac_postamble,
1315            ARRAY_LENGTH(ar9340_wasp_1p0_mac_postamble), 5);
1316
1317        /* bb */
1318        INIT_INI_ARRAY(&ahp->ah_ini_bb[ATH_INI_PRE], NULL, 0, 0);
1319        INIT_INI_ARRAY(&ahp->ah_ini_bb[ATH_INI_CORE],
1320            ar9340_wasp_1p0_baseband_core,
1321            ARRAY_LENGTH(ar9340_wasp_1p0_baseband_core), 2);
1322        INIT_INI_ARRAY(&ahp->ah_ini_bb[ATH_INI_POST],
1323            ar9340_wasp_1p0_baseband_postamble,
1324            ARRAY_LENGTH(ar9340_wasp_1p0_baseband_postamble), 5);
1325
1326        /* radio */
1327        INIT_INI_ARRAY(&ahp->ah_ini_radio[ATH_INI_PRE], NULL, 0, 0);
1328        INIT_INI_ARRAY(&ahp->ah_ini_radio[ATH_INI_CORE],
1329            ar9340_wasp_1p0_radio_core,
1330            ARRAY_LENGTH(ar9340_wasp_1p0_radio_core), 2);
1331        INIT_INI_ARRAY(&ahp->ah_ini_radio[ATH_INI_POST],
1332            ar9340_wasp_1p0_radio_postamble,
1333            ARRAY_LENGTH(ar9340_wasp_1p0_radio_postamble), 5);
1334
1335        /* soc */
1336        INIT_INI_ARRAY(&ahp->ah_ini_soc[ATH_INI_PRE],
1337            ar9340_wasp_1p0_soc_preamble,
1338            ARRAY_LENGTH(ar9340_wasp_1p0_soc_preamble), 2);
1339        INIT_INI_ARRAY(&ahp->ah_ini_soc[ATH_INI_CORE], NULL, 0, 0);
1340        INIT_INI_ARRAY(&ahp->ah_ini_soc[ATH_INI_POST],
1341            ar9340_wasp_1p0_soc_postamble,
1342            ARRAY_LENGTH(ar9340_wasp_1p0_soc_postamble), 5);
1343
1344        /* rx/tx gain */
1345        INIT_INI_ARRAY(&ahp->ah_ini_modes_rxgain,
1346            ar9340Common_wo_xlna_rx_gain_table_wasp_1p0,
1347            ARRAY_LENGTH(ar9340Common_wo_xlna_rx_gain_table_wasp_1p0), 2);
1348        INIT_INI_ARRAY(&ahp->ah_ini_modes_txgain,
1349            ar9340Modes_high_ob_db_tx_gain_table_wasp_1p0,
1350            ARRAY_LENGTH(ar9340Modes_high_ob_db_tx_gain_table_wasp_1p0), 5);
1351
1352        ah->ah_config.ath_hal_pcie_power_save_enable = 0;
1353
1354        /* Fast clock modal settings */
1355        INIT_INI_ARRAY(&ahp->ah_ini_modes_additional,
1356            ar9340Modes_fast_clock_wasp_1p0,
1357            ARRAY_LENGTH(ar9340Modes_fast_clock_wasp_1p0), 3);
1358
1359        /* Additional setttings for 40Mhz */
1360        INIT_INI_ARRAY(&ahp->ah_ini_modes_additional_40mhz,
1361            ar9340_wasp_1p0_radio_core_40M,
1362            ARRAY_LENGTH(ar9340_wasp_1p0_radio_core_40M), 2);
1363
1364        /* DFS */
1365        INIT_INI_ARRAY(&ahp->ah_ini_dfs,
1366            ar9340_wasp_1p0_baseband_postamble_dfs_channel,
1367            ARRAY_LENGTH(ar9340_wasp_1p0_baseband_postamble_dfs_channel), 3);
1368    } else if (AR_SREV_SCORPION(ah)) {
1369        /* mac */
1370        INIT_INI_ARRAY(&ahp->ah_ini_mac[ATH_INI_PRE], NULL, 0, 0);
1371        INIT_INI_ARRAY(&ahp->ah_ini_mac[ATH_INI_CORE],
1372                        ar955x_scorpion_1p0_mac_core,
1373                        ARRAY_LENGTH(ar955x_scorpion_1p0_mac_core), 2);
1374        INIT_INI_ARRAY(&ahp->ah_ini_mac[ATH_INI_POST],
1375                        ar955x_scorpion_1p0_mac_postamble,
1376                        ARRAY_LENGTH(ar955x_scorpion_1p0_mac_postamble), 5);
1377
1378        /* bb */
1379        INIT_INI_ARRAY(&ahp->ah_ini_bb[ATH_INI_PRE], NULL, 0, 0);
1380        INIT_INI_ARRAY(&ahp->ah_ini_bb[ATH_INI_CORE],
1381                        ar955x_scorpion_1p0_baseband_core,
1382                        ARRAY_LENGTH(ar955x_scorpion_1p0_baseband_core), 2);
1383        INIT_INI_ARRAY(&ahp->ah_ini_bb[ATH_INI_POST],
1384                        ar955x_scorpion_1p0_baseband_postamble,
1385                        ARRAY_LENGTH(ar955x_scorpion_1p0_baseband_postamble), 5);
1386
1387        /* radio */
1388        INIT_INI_ARRAY(&ahp->ah_ini_radio[ATH_INI_PRE], NULL, 0, 0);
1389        INIT_INI_ARRAY(&ahp->ah_ini_radio[ATH_INI_CORE],
1390                        ar955x_scorpion_1p0_radio_core,
1391                        ARRAY_LENGTH(ar955x_scorpion_1p0_radio_core), 2);
1392        INIT_INI_ARRAY(&ahp->ah_ini_radio[ATH_INI_POST],
1393                        ar955x_scorpion_1p0_radio_postamble,
1394                        ARRAY_LENGTH(ar955x_scorpion_1p0_radio_postamble), 5);
1395
1396        /* soc */
1397        INIT_INI_ARRAY(&ahp->ah_ini_soc[ATH_INI_PRE],
1398                        ar955x_scorpion_1p0_soc_preamble,
1399                        ARRAY_LENGTH(ar955x_scorpion_1p0_soc_preamble), 2);
1400        INIT_INI_ARRAY(&ahp->ah_ini_soc[ATH_INI_CORE], NULL, 0, 0);
1401        INIT_INI_ARRAY(&ahp->ah_ini_soc[ATH_INI_POST],
1402                        ar955x_scorpion_1p0_soc_postamble,
1403                        ARRAY_LENGTH(ar955x_scorpion_1p0_soc_postamble), 5);
1404
1405        /* rx/tx gain */
1406        INIT_INI_ARRAY(&ahp->ah_ini_modes_rxgain,
1407                        ar955xCommon_wo_xlna_rx_gain_table_scorpion_1p0,
1408                        ARRAY_LENGTH(ar955xCommon_wo_xlna_rx_gain_table_scorpion_1p0), 2);
1409        INIT_INI_ARRAY(&ahp->ah_ini_modes_rxgain_bounds,
1410                        ar955xCommon_wo_xlna_rx_gain_bounds_scorpion_1p0,
1411                        ARRAY_LENGTH(ar955xCommon_wo_xlna_rx_gain_bounds_scorpion_1p0), 5);
1412        INIT_INI_ARRAY(&ahp->ah_ini_modes_txgain,
1413                        ar955xModes_no_xpa_tx_gain_table_scorpion_1p0,
1414                        ARRAY_LENGTH(ar955xModes_no_xpa_tx_gain_table_scorpion_1p0), 5);
1415
1416        /*ath_hal_pciePowerSaveEnable should be 2 for OWL/Condor and 0 for merlin */
1417        ah->ah_config.ath_hal_pcie_power_save_enable = 0;
1418
1419        /* Fast clock modal settings */
1420        INIT_INI_ARRAY(&ahp->ah_ini_modes_additional,
1421                        ar955xModes_fast_clock_scorpion_1p0,
1422                        ARRAY_LENGTH(ar955xModes_fast_clock_scorpion_1p0), 3);
1423
1424        /* Additional setttings for 40Mhz */
1425        //INIT_INI_ARRAY(&ahp->ah_ini_modes_additional_40M,
1426        //                ar955x_scorpion_1p0_radio_core_40M,
1427        //                ARRAY_LENGTH(ar955x_scorpion_1p0_radio_core_40M), 2);
1428    } else if (AR_SREV_JUPITER_10(ah)) {
1429        /* Jupiter: new INI format (pre, core, post arrays per subsystem) */
1430
1431        /* mac */
1432        INIT_INI_ARRAY(&ahp->ah_ini_mac[ATH_INI_PRE], NULL, 0, 0);
1433        INIT_INI_ARRAY(&ahp->ah_ini_mac[ATH_INI_CORE],
1434            ar9300_jupiter_1p0_mac_core,
1435            ARRAY_LENGTH(ar9300_jupiter_1p0_mac_core), 2);
1436        INIT_INI_ARRAY(&ahp->ah_ini_mac[ATH_INI_POST],
1437            ar9300_jupiter_1p0_mac_postamble,
1438            ARRAY_LENGTH(ar9300_jupiter_1p0_mac_postamble), 5);
1439
1440        /* bb */
1441        INIT_INI_ARRAY(&ahp->ah_ini_bb[ATH_INI_PRE], NULL, 0, 0);
1442        INIT_INI_ARRAY(&ahp->ah_ini_bb[ATH_INI_CORE],
1443            ar9300_jupiter_1p0_baseband_core,
1444            ARRAY_LENGTH(ar9300_jupiter_1p0_baseband_core), 2);
1445        INIT_INI_ARRAY(&ahp->ah_ini_bb[ATH_INI_POST],
1446            ar9300_jupiter_1p0_baseband_postamble,
1447            ARRAY_LENGTH(ar9300_jupiter_1p0_baseband_postamble), 5);
1448
1449        /* radio */
1450        INIT_INI_ARRAY(&ahp->ah_ini_radio[ATH_INI_PRE], NULL, 0, 0);
1451        INIT_INI_ARRAY(&ahp->ah_ini_radio[ATH_INI_CORE],
1452            ar9300_jupiter_1p0_radio_core,
1453            ARRAY_LENGTH(ar9300_jupiter_1p0_radio_core), 2);
1454        INIT_INI_ARRAY(&ahp->ah_ini_radio[ATH_INI_POST],
1455            ar9300_jupiter_1p0_radio_postamble,
1456            ARRAY_LENGTH(ar9300_jupiter_1p0_radio_postamble), 5);
1457
1458        /* soc */
1459        INIT_INI_ARRAY(&ahp->ah_ini_soc[ATH_INI_PRE],
1460            ar9300_jupiter_1p0_soc_preamble,
1461            ARRAY_LENGTH(ar9300_jupiter_1p0_soc_preamble), 2);
1462        INIT_INI_ARRAY(&ahp->ah_ini_soc[ATH_INI_CORE], NULL, 0, 0);
1463        INIT_INI_ARRAY(&ahp->ah_ini_soc[ATH_INI_POST],
1464            ar9300_jupiter_1p0_soc_postamble,
1465            ARRAY_LENGTH(ar9300_jupiter_1p0_soc_postamble), 5);
1466
1467        /* rx/tx gain */
1468        INIT_INI_ARRAY(&ahp->ah_ini_modes_rxgain,
1469            ar9300_common_rx_gain_table_jupiter_1p0,
1470            ARRAY_LENGTH(ar9300_common_rx_gain_table_jupiter_1p0), 2);
1471
1472        /* Load PCIE SERDES settings from INI */
1473        if (ah->ah_config.ath_hal_pcie_clock_req) {
1474            /* Pci-e Clock Request = 1 */
1475            /*
1476             * PLL ON + clkreq enable is not a valid combination,
1477             * thus to ignore ath_hal_pll_pwr_save, use PLL OFF.
1478             */
1479            {
1480                /*Use driver default setting*/
1481                /* Awake -> Sleep Setting */
1482                INIT_INI_ARRAY(&ahp->ah_ini_pcie_serdes,
1483                    ar9300_pcie_phy_clkreq_enable_L1_jupiter_1p0,
1484                    ARRAY_LENGTH(ar9300_pcie_phy_clkreq_enable_L1_jupiter_1p0),
1485                    2);
1486                /* Sleep -> Awake Setting */
1487                INIT_INI_ARRAY(&ahp->ah_ini_pcie_serdes_low_power,
1488                    ar9300_pcie_phy_clkreq_enable_L1_jupiter_1p0,
1489                    ARRAY_LENGTH(ar9300_pcie_phy_clkreq_enable_L1_jupiter_1p0),
1490                    2);
1491            }
1492        }
1493        else {
1494            /*
1495             * Since Jupiter 1.0 and 2.0 share the same device id and will be
1496             * installed with same INF, but Jupiter 1.0 has issue with PLL OFF.
1497             *
1498             * Force Jupiter 1.0 to use ON/ON setting.
1499             */
1500            ah->ah_config.ath_hal_pll_pwr_save = 0;
1501            /* Pci-e Clock Request = 0 */
1502            if (ah->ah_config.ath_hal_pll_pwr_save &
1503                AR_PCIE_PLL_PWRSAVE_CONTROL)
1504            {
1505                /* Awake -> Sleep Setting */
1506                if (ah->ah_config.ath_hal_pll_pwr_save &
1507                     AR_PCIE_PLL_PWRSAVE_ON_D3)
1508                {
1509                    INIT_INI_ARRAY(&ahp->ah_ini_pcie_serdes,
1510                        ar9300_pcie_phy_clkreq_disable_L1_jupiter_1p0,
1511                        ARRAY_LENGTH(
1512                            ar9300_pcie_phy_clkreq_disable_L1_jupiter_1p0),
1513                        2);
1514                }
1515                else {
1516                    INIT_INI_ARRAY(&ahp->ah_ini_pcie_serdes,
1517                        ar9300_pcie_phy_pll_on_clkreq_disable_L1_jupiter_1p0,
1518                        ARRAY_LENGTH(
1519                          ar9300_pcie_phy_pll_on_clkreq_disable_L1_jupiter_1p0),
1520                        2);
1521                }
1522                /* Sleep -> Awake Setting */
1523                if (ah->ah_config.ath_hal_pll_pwr_save &
1524                    AR_PCIE_PLL_PWRSAVE_ON_D0)
1525                {
1526                    INIT_INI_ARRAY(&ahp->ah_ini_pcie_serdes_low_power,
1527                        ar9300_pcie_phy_clkreq_disable_L1_jupiter_1p0,
1528                        ARRAY_LENGTH(
1529                            ar9300_pcie_phy_clkreq_disable_L1_jupiter_1p0),
1530                        2);
1531                }
1532                else {
1533                    INIT_INI_ARRAY(&ahp->ah_ini_pcie_serdes_low_power,
1534                        ar9300_pcie_phy_pll_on_clkreq_disable_L1_jupiter_1p0,
1535                        ARRAY_LENGTH(
1536                          ar9300_pcie_phy_pll_on_clkreq_disable_L1_jupiter_1p0),
1537                        2);
1538                }
1539
1540            }
1541            else {
1542                /*Use driver default setting*/
1543                /* Awake -> Sleep Setting */
1544                INIT_INI_ARRAY(&ahp->ah_ini_pcie_serdes,
1545                    ar9300_pcie_phy_pll_on_clkreq_disable_L1_jupiter_1p0,
1546                    ARRAY_LENGTH(
1547                        ar9300_pcie_phy_pll_on_clkreq_disable_L1_jupiter_1p0),
1548                    2);
1549                /* Sleep -> Awake Setting */
1550                INIT_INI_ARRAY(&ahp->ah_ini_pcie_serdes_low_power,
1551                    ar9300_pcie_phy_pll_on_clkreq_disable_L1_jupiter_1p0,
1552                    ARRAY_LENGTH(
1553                        ar9300_pcie_phy_pll_on_clkreq_disable_L1_jupiter_1p0),
1554                    2);
1555            }
1556        }
1557        /*
1558         * ath_hal_pcie_power_save_enable should be 2 for OWL/Condor and
1559         * 0 for merlin
1560         */
1561        ah->ah_config.ath_hal_pcie_power_save_enable = 0;
1562
1563#if 0 // ATH_WOW
1564        /* SerDes values during WOW sleep */
1565        INIT_INI_ARRAY(&ahp->ah_ini_pcie_serdes_wow, ar9300_pcie_phy_AWOW,
1566            ARRAY_LENGTH(ar9300_pcie_phy_AWOW), 2);
1567#endif
1568
1569        /* Fast clock modal settings */
1570        INIT_INI_ARRAY(&ahp->ah_ini_modes_additional,
1571            ar9300_modes_fast_clock_jupiter_1p0,
1572            ARRAY_LENGTH(ar9300_modes_fast_clock_jupiter_1p0), 3);
1573        INIT_INI_ARRAY(&ahp->ah_ini_japan2484,
1574            ar9300_jupiter_1p0_baseband_core_txfir_coeff_japan_2484,
1575            ARRAY_LENGTH(
1576            ar9300_jupiter_1p0_baseband_core_txfir_coeff_japan_2484), 2);
1577
1578    }
1579    else if (AR_SREV_JUPITER_20(ah)) {
1580        /* Jupiter: new INI format (pre, core, post arrays per subsystem) */
1581
1582        /* mac */
1583        INIT_INI_ARRAY(&ahp->ah_ini_mac[ATH_INI_PRE], NULL, 0, 0);
1584        INIT_INI_ARRAY(&ahp->ah_ini_mac[ATH_INI_CORE],
1585            ar9300_jupiter_2p0_mac_core,
1586            ARRAY_LENGTH(ar9300_jupiter_2p0_mac_core), 2);
1587        INIT_INI_ARRAY(&ahp->ah_ini_mac[ATH_INI_POST],
1588            ar9300_jupiter_2p0_mac_postamble,
1589            ARRAY_LENGTH(ar9300_jupiter_2p0_mac_postamble), 5);
1590
1591        /* bb */
1592        INIT_INI_ARRAY(&ahp->ah_ini_bb[ATH_INI_PRE], NULL, 0, 0);
1593        INIT_INI_ARRAY(&ahp->ah_ini_bb[ATH_INI_CORE],
1594            ar9300_jupiter_2p0_baseband_core,
1595            ARRAY_LENGTH(ar9300_jupiter_2p0_baseband_core), 2);
1596        INIT_INI_ARRAY(&ahp->ah_ini_bb[ATH_INI_POST],
1597            ar9300_jupiter_2p0_baseband_postamble,
1598            ARRAY_LENGTH(ar9300_jupiter_2p0_baseband_postamble), 5);
1599
1600        /* radio */
1601        INIT_INI_ARRAY(&ahp->ah_ini_radio[ATH_INI_PRE], NULL, 0, 0);
1602        INIT_INI_ARRAY(&ahp->ah_ini_radio[ATH_INI_CORE],
1603            ar9300_jupiter_2p0_radio_core,
1604            ARRAY_LENGTH(ar9300_jupiter_2p0_radio_core), 2);
1605        INIT_INI_ARRAY(&ahp->ah_ini_radio[ATH_INI_POST],
1606            ar9300_jupiter_2p0_radio_postamble,
1607            ARRAY_LENGTH(ar9300_jupiter_2p0_radio_postamble), 5);
1608        INIT_INI_ARRAY(&ahp->ah_ini_radio_post_sys2ant,
1609            ar9300_jupiter_2p0_radio_postamble_sys2ant,
1610            ARRAY_LENGTH(ar9300_jupiter_2p0_radio_postamble_sys2ant), 5);
1611
1612        /* soc */
1613        INIT_INI_ARRAY(&ahp->ah_ini_soc[ATH_INI_PRE],
1614            ar9300_jupiter_2p0_soc_preamble,
1615            ARRAY_LENGTH(ar9300_jupiter_2p0_soc_preamble), 2);
1616        INIT_INI_ARRAY(&ahp->ah_ini_soc[ATH_INI_CORE], NULL, 0, 0);
1617        INIT_INI_ARRAY(&ahp->ah_ini_soc[ATH_INI_POST],
1618            ar9300_jupiter_2p0_soc_postamble,
1619            ARRAY_LENGTH(ar9300_jupiter_2p0_soc_postamble), 5);
1620
1621        /* rx/tx gain */
1622        INIT_INI_ARRAY(&ahp->ah_ini_modes_rxgain,
1623            ar9300Common_rx_gain_table_jupiter_2p0,
1624            ARRAY_LENGTH(ar9300Common_rx_gain_table_jupiter_2p0), 2);
1625
1626        /* BTCOEX */
1627        INIT_INI_ARRAY(&ahp->ah_ini_BTCOEX_MAX_TXPWR,
1628            ar9300_jupiter_2p0_BTCOEX_MAX_TXPWR_table,
1629            ARRAY_LENGTH(ar9300_jupiter_2p0_BTCOEX_MAX_TXPWR_table), 2);
1630
1631        /* Load PCIE SERDES settings from INI */
1632        if (ah->ah_config.ath_hal_pcie_clock_req) {
1633            /* Pci-e Clock Request = 1 */
1634            /*
1635             * PLL ON + clkreq enable is not a valid combination,
1636             * thus to ignore ath_hal_pll_pwr_save, use PLL OFF.
1637             */
1638            {
1639                /*Use driver default setting*/
1640                /* Awake -> Sleep Setting */
1641                INIT_INI_ARRAY(&ahp->ah_ini_pcie_serdes,
1642                    ar9300_PciePhy_clkreq_enable_L1_jupiter_2p0,
1643                    ARRAY_LENGTH(ar9300_PciePhy_clkreq_enable_L1_jupiter_2p0),
1644                    2);
1645                /* Sleep -> Awake Setting */
1646                INIT_INI_ARRAY(&ahp->ah_ini_pcie_serdes_low_power,
1647                    ar9300_PciePhy_clkreq_enable_L1_jupiter_2p0,
1648                    ARRAY_LENGTH(ar9300_PciePhy_clkreq_enable_L1_jupiter_2p0),
1649                    2);
1650            }
1651        }
1652        else {
1653            /* Pci-e Clock Request = 0 */
1654            if (ah->ah_config.ath_hal_pll_pwr_save &
1655                AR_PCIE_PLL_PWRSAVE_CONTROL)
1656            {
1657                /* Awake -> Sleep Setting */
1658                if (ah->ah_config.ath_hal_pll_pwr_save &
1659                     AR_PCIE_PLL_PWRSAVE_ON_D3)
1660                {
1661                    INIT_INI_ARRAY(&ahp->ah_ini_pcie_serdes,
1662                        ar9300_PciePhy_clkreq_disable_L1_jupiter_2p0,
1663                        ARRAY_LENGTH(
1664                            ar9300_PciePhy_clkreq_disable_L1_jupiter_2p0),
1665                        2);
1666                }
1667                else {
1668                    INIT_INI_ARRAY(&ahp->ah_ini_pcie_serdes,
1669                        ar9300_PciePhy_pll_on_clkreq_disable_L1_jupiter_2p0,
1670                        ARRAY_LENGTH(
1671                          ar9300_PciePhy_pll_on_clkreq_disable_L1_jupiter_2p0),
1672                        2);
1673                }
1674                /* Sleep -> Awake Setting */
1675                if (ah->ah_config.ath_hal_pll_pwr_save &
1676                    AR_PCIE_PLL_PWRSAVE_ON_D0)
1677                {
1678                    INIT_INI_ARRAY(&ahp->ah_ini_pcie_serdes_low_power,
1679                        ar9300_PciePhy_clkreq_disable_L1_jupiter_2p0,
1680                        ARRAY_LENGTH(
1681                            ar9300_PciePhy_clkreq_disable_L1_jupiter_2p0),
1682                        2);
1683                }
1684                else {
1685                    INIT_INI_ARRAY(&ahp->ah_ini_pcie_serdes_low_power,
1686                        ar9300_PciePhy_pll_on_clkreq_disable_L1_jupiter_2p0,
1687                        ARRAY_LENGTH(
1688                          ar9300_PciePhy_pll_on_clkreq_disable_L1_jupiter_2p0),
1689                        2);
1690                }
1691
1692            }
1693            else {
1694                /*Use driver default setting*/
1695                /* Awake -> Sleep Setting */
1696                INIT_INI_ARRAY(&ahp->ah_ini_pcie_serdes,
1697                    ar9300_PciePhy_pll_on_clkreq_disable_L1_jupiter_2p0,
1698                    ARRAY_LENGTH(
1699                        ar9300_PciePhy_pll_on_clkreq_disable_L1_jupiter_2p0),
1700                    2);
1701                /* Sleep -> Awake Setting */
1702                INIT_INI_ARRAY(&ahp->ah_ini_pcie_serdes_low_power,
1703                    ar9300_PciePhy_pll_on_clkreq_disable_L1_jupiter_2p0,
1704                    ARRAY_LENGTH(
1705                        ar9300_PciePhy_pll_on_clkreq_disable_L1_jupiter_2p0),
1706                    2);
1707            }
1708        }
1709
1710        /*
1711         * ath_hal_pcie_power_save_enable should be 2 for OWL/Condor and
1712         * 0 for merlin
1713         */
1714        ah->ah_config.ath_hal_pcie_power_save_enable = 0;
1715
1716#if 0 // ATH_WOW
1717        /* SerDes values during WOW sleep */
1718        INIT_INI_ARRAY(&ahp->ah_ini_pcie_serdes_wow, ar9300_pcie_phy_AWOW,
1719            ARRAY_LENGTH(ar9300_pcie_phy_AWOW), 2);
1720#endif
1721
1722        /* Fast clock modal settings */
1723        INIT_INI_ARRAY(&ahp->ah_ini_modes_additional,
1724            ar9300Modes_fast_clock_jupiter_2p0,
1725            ARRAY_LENGTH(ar9300Modes_fast_clock_jupiter_2p0), 3);
1726        INIT_INI_ARRAY(&ahp->ah_ini_japan2484,
1727            ar9300_jupiter_2p0_baseband_core_txfir_coeff_japan_2484,
1728            ARRAY_LENGTH(
1729            ar9300_jupiter_2p0_baseband_core_txfir_coeff_japan_2484), 2);
1730
1731    } else if (AR_SREV_APHRODITE(ah)) {
1732        /* Aphrodite: new INI format (pre, core, post arrays per subsystem) */
1733
1734        /* mac */
1735        INIT_INI_ARRAY(&ahp->ah_ini_mac[ATH_INI_PRE], NULL, 0, 0);
1736        INIT_INI_ARRAY(&ahp->ah_ini_mac[ATH_INI_CORE],
1737            ar956X_aphrodite_1p0_mac_core,
1738            ARRAY_LENGTH(ar956X_aphrodite_1p0_mac_core), 2);
1739        INIT_INI_ARRAY(&ahp->ah_ini_mac[ATH_INI_POST],
1740            ar956X_aphrodite_1p0_mac_postamble,
1741            ARRAY_LENGTH(ar956X_aphrodite_1p0_mac_postamble), 5);
1742
1743        /* bb */
1744        INIT_INI_ARRAY(&ahp->ah_ini_bb[ATH_INI_PRE], NULL, 0, 0);
1745        INIT_INI_ARRAY(&ahp->ah_ini_bb[ATH_INI_CORE],
1746            ar956X_aphrodite_1p0_baseband_core,
1747            ARRAY_LENGTH(ar956X_aphrodite_1p0_baseband_core), 2);
1748        INIT_INI_ARRAY(&ahp->ah_ini_bb[ATH_INI_POST],
1749            ar956X_aphrodite_1p0_baseband_postamble,
1750            ARRAY_LENGTH(ar956X_aphrodite_1p0_baseband_postamble), 5);
1751
1752//mark jupiter have but aphrodite don't have
1753//        /* radio */
1754//        INIT_INI_ARRAY(&ahp->ah_ini_radio[ATH_INI_PRE], NULL, 0, 0);
1755//        INIT_INI_ARRAY(&ahp->ah_ini_radio[ATH_INI_CORE],
1756//            ar9300_aphrodite_1p0_radio_core,
1757//            ARRAY_LENGTH(ar9300_aphrodite_1p0_radio_core), 2);
1758//        INIT_INI_ARRAY(&ahp->ah_ini_radio[ATH_INI_POST],
1759//            ar9300_aphrodite_1p0_radio_postamble,
1760//            ARRAY_LENGTH(ar9300_aphrodite_1p0_radio_postamble), 5);
1761
1762        /* soc */
1763        INIT_INI_ARRAY(&ahp->ah_ini_soc[ATH_INI_PRE],
1764            ar956X_aphrodite_1p0_soc_preamble,
1765            ARRAY_LENGTH(ar956X_aphrodite_1p0_soc_preamble), 2);
1766        INIT_INI_ARRAY(&ahp->ah_ini_soc[ATH_INI_CORE], NULL, 0, 0);
1767        INIT_INI_ARRAY(&ahp->ah_ini_soc[ATH_INI_POST],
1768            ar956X_aphrodite_1p0_soc_postamble,
1769            ARRAY_LENGTH(ar956X_aphrodite_1p0_soc_postamble), 5);
1770
1771        /* rx/tx gain */
1772        INIT_INI_ARRAY(&ahp->ah_ini_modes_rxgain,
1773            ar956XCommon_rx_gain_table_aphrodite_1p0,
1774            ARRAY_LENGTH(ar956XCommon_rx_gain_table_aphrodite_1p0), 2);
1775        //INIT_INI_ARRAY(&ahp->ah_ini_modes_txgain,
1776        //    ar956XModes_lowest_ob_db_tx_gain_table_aphrodite_1p0,
1777        //    ARRAY_LENGTH(ar956XModes_lowest_ob_db_tx_gain_table_aphrodite_1p0),
1778        //    5);
1779
1780
1781        /*
1782         * ath_hal_pcie_power_save_enable should be 2 for OWL/Condor and
1783         * 0 for merlin
1784         */
1785        ah->ah_config.ath_hal_pcie_power_save_enable = 0;
1786
1787#if 0 // ATH_WOW
1788        /* SerDes values during WOW sleep */
1789        INIT_INI_ARRAY(&ahp->ah_ini_pcie_serdes_wow, ar9300_pcie_phy_AWOW,
1790            ARRAY_LENGTH(ar9300_pcie_phy_AWOW), 2);
1791#endif
1792       /* Fast clock modal settings */
1793       INIT_INI_ARRAY(&ahp->ah_ini_modes_additional,
1794            ar956XModes_fast_clock_aphrodite_1p0,
1795            ARRAY_LENGTH(ar956XModes_fast_clock_aphrodite_1p0), 3);
1796
1797    } else if (AR_SREV_AR9580(ah)) {
1798        /*
1799         * AR9580/Peacock -
1800         * new INI format (pre, core, post arrays per subsystem)
1801         */
1802
1803        /* mac */
1804        INIT_INI_ARRAY(&ahp->ah_ini_mac[ATH_INI_PRE], NULL, 0, 0);
1805        INIT_INI_ARRAY(&ahp->ah_ini_mac[ATH_INI_CORE],
1806            ar9300_ar9580_1p0_mac_core,
1807            ARRAY_LENGTH(ar9300_ar9580_1p0_mac_core), 2);
1808        INIT_INI_ARRAY(&ahp->ah_ini_mac[ATH_INI_POST],
1809            ar9300_ar9580_1p0_mac_postamble,
1810            ARRAY_LENGTH(ar9300_ar9580_1p0_mac_postamble), 5);
1811
1812        /* bb */
1813        INIT_INI_ARRAY(&ahp->ah_ini_bb[ATH_INI_PRE], NULL, 0, 0);
1814        INIT_INI_ARRAY(&ahp->ah_ini_bb[ATH_INI_CORE],
1815            ar9300_ar9580_1p0_baseband_core,
1816            ARRAY_LENGTH(ar9300_ar9580_1p0_baseband_core), 2);
1817        INIT_INI_ARRAY(&ahp->ah_ini_bb[ATH_INI_POST],
1818            ar9300_ar9580_1p0_baseband_postamble,
1819            ARRAY_LENGTH(ar9300_ar9580_1p0_baseband_postamble), 5);
1820
1821        /* radio */
1822        INIT_INI_ARRAY(&ahp->ah_ini_radio[ATH_INI_PRE], NULL, 0, 0);
1823        INIT_INI_ARRAY(&ahp->ah_ini_radio[ATH_INI_CORE],
1824            ar9300_ar9580_1p0_radio_core,
1825            ARRAY_LENGTH(ar9300_ar9580_1p0_radio_core), 2);
1826        INIT_INI_ARRAY(&ahp->ah_ini_radio[ATH_INI_POST],
1827            ar9300_ar9580_1p0_radio_postamble,
1828            ARRAY_LENGTH(ar9300_ar9580_1p0_radio_postamble), 5);
1829
1830        /* soc */
1831        INIT_INI_ARRAY(&ahp->ah_ini_soc[ATH_INI_PRE],
1832            ar9300_ar9580_1p0_soc_preamble,
1833            ARRAY_LENGTH(ar9300_ar9580_1p0_soc_preamble), 2);
1834        INIT_INI_ARRAY(&ahp->ah_ini_soc[ATH_INI_CORE], NULL, 0, 0);
1835        INIT_INI_ARRAY(&ahp->ah_ini_soc[ATH_INI_POST],
1836            ar9300_ar9580_1p0_soc_postamble,
1837            ARRAY_LENGTH(ar9300_ar9580_1p0_soc_postamble), 5);
1838
1839        /* rx/tx gain */
1840        INIT_INI_ARRAY(&ahp->ah_ini_modes_rxgain,
1841            ar9300_common_rx_gain_table_ar9580_1p0,
1842            ARRAY_LENGTH(ar9300_common_rx_gain_table_ar9580_1p0), 2);
1843        INIT_INI_ARRAY(&ahp->ah_ini_modes_txgain,
1844            ar9300Modes_lowest_ob_db_tx_gain_table_ar9580_1p0,
1845            ARRAY_LENGTH(ar9300Modes_lowest_ob_db_tx_gain_table_ar9580_1p0), 5);
1846
1847        /* DFS */
1848        INIT_INI_ARRAY(&ahp->ah_ini_dfs,
1849            ar9300_ar9580_1p0_baseband_postamble_dfs_channel,
1850            ARRAY_LENGTH(ar9300_ar9580_1p0_baseband_postamble_dfs_channel), 3);
1851
1852
1853        /* Load PCIE SERDES settings from INI */
1854
1855        /*D3 Setting */
1856        if  (ah->ah_config.ath_hal_pcie_clock_req) {
1857            if (ah->ah_config.ath_hal_pll_pwr_save &
1858                AR_PCIE_PLL_PWRSAVE_CONTROL)
1859            { //registry control
1860                if (ah->ah_config.ath_hal_pll_pwr_save &
1861                    AR_PCIE_PLL_PWRSAVE_ON_D3)
1862                { //bit1, in to D3
1863                    INIT_INI_ARRAY(&ahp->ah_ini_pcie_serdes,
1864                        ar9300PciePhy_clkreq_enable_L1_ar9580_1p0,
1865                        ARRAY_LENGTH(ar9300PciePhy_clkreq_enable_L1_ar9580_1p0),
1866                    2);
1867                } else {
1868                    INIT_INI_ARRAY(&ahp->ah_ini_pcie_serdes,
1869                        ar9300PciePhy_pll_on_clkreq_disable_L1_ar9580_1p0,
1870                        ARRAY_LENGTH(
1871                            ar9300PciePhy_pll_on_clkreq_disable_L1_ar9580_1p0),
1872                    2);
1873                }
1874            } else {//no registry control, default is pll on
1875                INIT_INI_ARRAY(
1876                    &ahp->ah_ini_pcie_serdes,
1877                    ar9300PciePhy_pll_on_clkreq_disable_L1_ar9580_1p0,
1878                    ARRAY_LENGTH(
1879                        ar9300PciePhy_pll_on_clkreq_disable_L1_ar9580_1p0),
1880                    2);
1881            }
1882        } else {
1883            if (ah->ah_config.ath_hal_pll_pwr_save &
1884                AR_PCIE_PLL_PWRSAVE_CONTROL)
1885            { //registry control
1886                if (ah->ah_config.ath_hal_pll_pwr_save &
1887                    AR_PCIE_PLL_PWRSAVE_ON_D3)
1888                { //bit1, in to D3
1889                    INIT_INI_ARRAY(&ahp->ah_ini_pcie_serdes,
1890                        ar9300PciePhy_clkreq_disable_L1_ar9580_1p0,
1891                        ARRAY_LENGTH(
1892                            ar9300PciePhy_clkreq_disable_L1_ar9580_1p0),
1893                        2);
1894                } else {
1895                    INIT_INI_ARRAY(&ahp->ah_ini_pcie_serdes,
1896                        ar9300PciePhy_pll_on_clkreq_disable_L1_ar9580_1p0,
1897                        ARRAY_LENGTH(
1898                            ar9300PciePhy_pll_on_clkreq_disable_L1_ar9580_1p0),
1899                        2);
1900                }
1901            } else {//no registry control, default is pll on
1902                INIT_INI_ARRAY(
1903                    &ahp->ah_ini_pcie_serdes,
1904                    ar9300PciePhy_pll_on_clkreq_disable_L1_ar9580_1p0,
1905                    ARRAY_LENGTH(
1906                        ar9300PciePhy_pll_on_clkreq_disable_L1_ar9580_1p0),
1907                    2);
1908            }
1909        }
1910
1911        /*D0 Setting */
1912        if  (ah->ah_config.ath_hal_pcie_clock_req) {
1913             if (ah->ah_config.ath_hal_pll_pwr_save &
1914                AR_PCIE_PLL_PWRSAVE_CONTROL)
1915             { //registry control
1916                if (ah->ah_config.ath_hal_pll_pwr_save &
1917                    AR_PCIE_PLL_PWRSAVE_ON_D0)
1918                { //bit2, out of D3
1919                    INIT_INI_ARRAY(&ahp->ah_ini_pcie_serdes_low_power,
1920                        ar9300PciePhy_clkreq_enable_L1_ar9580_1p0,
1921                        ARRAY_LENGTH(ar9300PciePhy_clkreq_enable_L1_ar9580_1p0),
1922                    2);
1923
1924                } else {
1925                    INIT_INI_ARRAY(&ahp->ah_ini_pcie_serdes_low_power,
1926                        ar9300PciePhy_pll_on_clkreq_disable_L1_ar9580_1p0,
1927                        ARRAY_LENGTH(
1928                            ar9300PciePhy_pll_on_clkreq_disable_L1_ar9580_1p0),
1929                    2);
1930                }
1931            } else { //no registry control, default is pll on
1932                INIT_INI_ARRAY(
1933                    &ahp->ah_ini_pcie_serdes_low_power,
1934                    ar9300PciePhy_pll_on_clkreq_disable_L1_ar9580_1p0,
1935                    ARRAY_LENGTH(
1936                        ar9300PciePhy_pll_on_clkreq_disable_L1_ar9580_1p0),
1937                    2);
1938            }
1939        } else {
1940            if (ah->ah_config.ath_hal_pll_pwr_save &
1941                AR_PCIE_PLL_PWRSAVE_CONTROL)
1942            {//registry control
1943                if (ah->ah_config.ath_hal_pll_pwr_save &
1944                    AR_PCIE_PLL_PWRSAVE_ON_D0)
1945                {//bit2, out of D3
1946                    INIT_INI_ARRAY(&ahp->ah_ini_pcie_serdes_low_power,
1947                        ar9300PciePhy_clkreq_disable_L1_ar9580_1p0,
1948                       ARRAY_LENGTH(ar9300PciePhy_clkreq_disable_L1_ar9580_1p0),
1949                    2);
1950                } else {
1951                    INIT_INI_ARRAY(&ahp->ah_ini_pcie_serdes_low_power,
1952                        ar9300PciePhy_pll_on_clkreq_disable_L1_ar9580_1p0,
1953                        ARRAY_LENGTH(
1954                            ar9300PciePhy_pll_on_clkreq_disable_L1_ar9580_1p0),
1955                    2);
1956                }
1957            } else { //no registry control, default is pll on
1958                INIT_INI_ARRAY(
1959                    &ahp->ah_ini_pcie_serdes_low_power,
1960                    ar9300PciePhy_pll_on_clkreq_disable_L1_ar9580_1p0,
1961                    ARRAY_LENGTH(
1962                        ar9300PciePhy_pll_on_clkreq_disable_L1_ar9580_1p0),
1963                    2);
1964            }
1965        }
1966
1967        ah->ah_config.ath_hal_pcie_power_save_enable = 0;
1968
1969#if 0 /* ATH_WOW */
1970        /* SerDes values during WOW sleep */
1971        INIT_INI_ARRAY(&ahp->ah_ini_pcie_serdes_wow, ar9300_pcie_phy_awow,
1972                       ARRAY_LENGTH(ar9300_pcie_phy_awow), 2);
1973#endif
1974
1975        /* Fast clock modal settings */
1976        INIT_INI_ARRAY(&ahp->ah_ini_modes_additional,
1977            ar9300Modes_fast_clock_ar9580_1p0,
1978            ARRAY_LENGTH(ar9300Modes_fast_clock_ar9580_1p0), 3);
1979        INIT_INI_ARRAY(&ahp->ah_ini_japan2484,
1980            ar9300_ar9580_1p0_baseband_core_txfir_coeff_japan_2484,
1981            ARRAY_LENGTH(
1982                ar9300_ar9580_1p0_baseband_core_txfir_coeff_japan_2484), 2);
1983
1984    } else {
1985        /*
1986         * Osprey 2.2 -  new INI format (pre, core, post arrays per subsystem)
1987         */
1988
1989        /* mac */
1990        INIT_INI_ARRAY(&ahp->ah_ini_mac[ATH_INI_PRE], NULL, 0, 0);
1991        INIT_INI_ARRAY(&ahp->ah_ini_mac[ATH_INI_CORE],
1992            ar9300_osprey_2p2_mac_core,
1993            ARRAY_LENGTH(ar9300_osprey_2p2_mac_core), 2);
1994        INIT_INI_ARRAY(&ahp->ah_ini_mac[ATH_INI_POST],
1995            ar9300_osprey_2p2_mac_postamble,
1996            ARRAY_LENGTH(ar9300_osprey_2p2_mac_postamble), 5);
1997
1998        /* bb */
1999        INIT_INI_ARRAY(&ahp->ah_ini_bb[ATH_INI_PRE], NULL, 0, 0);
2000        INIT_INI_ARRAY(&ahp->ah_ini_bb[ATH_INI_CORE],
2001            ar9300_osprey_2p2_baseband_core,
2002            ARRAY_LENGTH(ar9300_osprey_2p2_baseband_core), 2);
2003        INIT_INI_ARRAY(&ahp->ah_ini_bb[ATH_INI_POST],
2004            ar9300_osprey_2p2_baseband_postamble,
2005            ARRAY_LENGTH(ar9300_osprey_2p2_baseband_postamble), 5);
2006
2007        /* radio */
2008        INIT_INI_ARRAY(&ahp->ah_ini_radio[ATH_INI_PRE], NULL, 0, 0);
2009        INIT_INI_ARRAY(&ahp->ah_ini_radio[ATH_INI_CORE],
2010            ar9300_osprey_2p2_radio_core,
2011            ARRAY_LENGTH(ar9300_osprey_2p2_radio_core), 2);
2012        INIT_INI_ARRAY(&ahp->ah_ini_radio[ATH_INI_POST],
2013            ar9300_osprey_2p2_radio_postamble,
2014            ARRAY_LENGTH(ar9300_osprey_2p2_radio_postamble), 5);
2015
2016        /* soc */
2017        INIT_INI_ARRAY(&ahp->ah_ini_soc[ATH_INI_PRE],
2018            ar9300_osprey_2p2_soc_preamble,
2019            ARRAY_LENGTH(ar9300_osprey_2p2_soc_preamble), 2);
2020        INIT_INI_ARRAY(&ahp->ah_ini_soc[ATH_INI_CORE], NULL, 0, 0);
2021        INIT_INI_ARRAY(&ahp->ah_ini_soc[ATH_INI_POST],
2022            ar9300_osprey_2p2_soc_postamble,
2023            ARRAY_LENGTH(ar9300_osprey_2p2_soc_postamble), 5);
2024
2025        /* rx/tx gain */
2026        INIT_INI_ARRAY(&ahp->ah_ini_modes_rxgain,
2027            ar9300_common_rx_gain_table_osprey_2p2,
2028            ARRAY_LENGTH(ar9300_common_rx_gain_table_osprey_2p2), 2);
2029        INIT_INI_ARRAY(&ahp->ah_ini_modes_txgain,
2030            ar9300_modes_lowest_ob_db_tx_gain_table_osprey_2p2,
2031            ARRAY_LENGTH(ar9300_modes_lowest_ob_db_tx_gain_table_osprey_2p2), 5);
2032
2033        /* DFS */
2034        INIT_INI_ARRAY(&ahp->ah_ini_dfs,
2035            ar9300_osprey_2p2_baseband_postamble_dfs_channel,
2036            ARRAY_LENGTH(ar9300_osprey_2p2_baseband_postamble_dfs_channel), 3);
2037
2038        /* Load PCIE SERDES settings from INI */
2039
2040        /*D3 Setting */
2041        if  (ah->ah_config.ath_hal_pcie_clock_req) {
2042            if (ah->ah_config.ath_hal_pll_pwr_save &
2043                AR_PCIE_PLL_PWRSAVE_CONTROL)
2044            { //registry control
2045                if (ah->ah_config.ath_hal_pll_pwr_save &
2046                    AR_PCIE_PLL_PWRSAVE_ON_D3)
2047                { //bit1, in to D3
2048                    INIT_INI_ARRAY(&ahp->ah_ini_pcie_serdes,
2049                        ar9300PciePhy_clkreq_enable_L1_osprey_2p2,
2050                        ARRAY_LENGTH(ar9300PciePhy_clkreq_enable_L1_osprey_2p2),
2051                    2);
2052                } else {
2053                    INIT_INI_ARRAY(&ahp->ah_ini_pcie_serdes,
2054                        ar9300PciePhy_pll_on_clkreq_disable_L1_osprey_2p2,
2055                        ARRAY_LENGTH(
2056                            ar9300PciePhy_pll_on_clkreq_disable_L1_osprey_2p2),
2057                    2);
2058                }
2059             } else {//no registry control, default is pll on
2060#ifndef ATH_BUS_PM
2061                    INIT_INI_ARRAY(
2062                        &ahp->ah_ini_pcie_serdes,
2063                        ar9300PciePhy_pll_on_clkreq_disable_L1_osprey_2p2,
2064                        ARRAY_LENGTH(
2065                            ar9300PciePhy_pll_on_clkreq_disable_L1_osprey_2p2),
2066                    2);
2067#else
2068        //no registry control, default is pll off
2069        INIT_INI_ARRAY(
2070                &ahp->ah_ini_pcie_serdes,
2071                ar9300PciePhy_clkreq_disable_L1_osprey_2p2,
2072                ARRAY_LENGTH(
2073                    ar9300PciePhy_clkreq_disable_L1_osprey_2p2),
2074                  2);
2075#endif
2076
2077            }
2078        } else {
2079            if (ah->ah_config.ath_hal_pll_pwr_save &
2080                AR_PCIE_PLL_PWRSAVE_CONTROL)
2081            { //registry control
2082                if (ah->ah_config.ath_hal_pll_pwr_save &
2083                    AR_PCIE_PLL_PWRSAVE_ON_D3)
2084                { //bit1, in to D3
2085                    INIT_INI_ARRAY(&ahp->ah_ini_pcie_serdes,
2086                        ar9300PciePhy_clkreq_disable_L1_osprey_2p2,
2087                        ARRAY_LENGTH(
2088                            ar9300PciePhy_clkreq_disable_L1_osprey_2p2),
2089                        2);
2090                } else {
2091                    INIT_INI_ARRAY(&ahp->ah_ini_pcie_serdes,
2092                       ar9300PciePhy_pll_on_clkreq_disable_L1_osprey_2p2,
2093                       ARRAY_LENGTH(
2094                           ar9300PciePhy_pll_on_clkreq_disable_L1_osprey_2p2),
2095                       2);
2096                }
2097             } else {
2098#ifndef ATH_BUS_PM
2099        //no registry control, default is pll on
2100                INIT_INI_ARRAY(
2101                    &ahp->ah_ini_pcie_serdes,
2102                    ar9300PciePhy_pll_on_clkreq_disable_L1_osprey_2p2,
2103                    ARRAY_LENGTH(
2104                        ar9300PciePhy_pll_on_clkreq_disable_L1_osprey_2p2),
2105                    2);
2106#else
2107        //no registry control, default is pll off
2108        INIT_INI_ARRAY(&ahp->ah_ini_pcie_serdes, ar9300PciePhy_clkreq_disable_L1_osprey_2p2,
2109                           ARRAY_LENGTH(ar9300PciePhy_clkreq_disable_L1_osprey_2p2), 2);
2110#endif
2111            }
2112        }
2113
2114        /*D0 Setting */
2115        if  (ah->ah_config.ath_hal_pcie_clock_req) {
2116             if (ah->ah_config.ath_hal_pll_pwr_save &
2117                AR_PCIE_PLL_PWRSAVE_CONTROL)
2118             { //registry control
2119                if (ah->ah_config.ath_hal_pll_pwr_save &
2120                    AR_PCIE_PLL_PWRSAVE_ON_D0)
2121                { //bit2, out of D3
2122                    INIT_INI_ARRAY(&ahp->ah_ini_pcie_serdes_low_power,
2123                        ar9300PciePhy_clkreq_enable_L1_osprey_2p2,
2124                        ARRAY_LENGTH(ar9300PciePhy_clkreq_enable_L1_osprey_2p2),
2125                    2);
2126
2127                } else {
2128                    INIT_INI_ARRAY(&ahp->ah_ini_pcie_serdes_low_power,
2129                        ar9300PciePhy_pll_on_clkreq_disable_L1_osprey_2p2,
2130                        ARRAY_LENGTH(
2131                            ar9300PciePhy_pll_on_clkreq_disable_L1_osprey_2p2),
2132                    2);
2133                }
2134            } else { //no registry control, default is pll on
2135                INIT_INI_ARRAY(
2136                    &ahp->ah_ini_pcie_serdes_low_power,
2137                    ar9300PciePhy_pll_on_clkreq_disable_L1_osprey_2p2,
2138                    ARRAY_LENGTH(
2139                        ar9300PciePhy_pll_on_clkreq_disable_L1_osprey_2p2),
2140                    2);
2141            }
2142        } else {
2143            if (ah->ah_config.ath_hal_pll_pwr_save &
2144                AR_PCIE_PLL_PWRSAVE_CONTROL)
2145            {//registry control
2146                if (ah->ah_config.ath_hal_pll_pwr_save &
2147                    AR_PCIE_PLL_PWRSAVE_ON_D0)
2148                {//bit2, out of D3
2149                    INIT_INI_ARRAY(&ahp->ah_ini_pcie_serdes_low_power,
2150                        ar9300PciePhy_clkreq_disable_L1_osprey_2p2,
2151                       ARRAY_LENGTH(ar9300PciePhy_clkreq_disable_L1_osprey_2p2),
2152                    2);
2153                } else {
2154                    INIT_INI_ARRAY(&ahp->ah_ini_pcie_serdes_low_power,
2155                        ar9300PciePhy_pll_on_clkreq_disable_L1_osprey_2p2,
2156                        ARRAY_LENGTH(
2157                            ar9300PciePhy_pll_on_clkreq_disable_L1_osprey_2p2),
2158                    2);
2159                }
2160            } else { //no registry control, default is pll on
2161                INIT_INI_ARRAY(
2162                    &ahp->ah_ini_pcie_serdes_low_power,
2163                    ar9300PciePhy_pll_on_clkreq_disable_L1_osprey_2p2,
2164                    ARRAY_LENGTH(
2165                        ar9300PciePhy_pll_on_clkreq_disable_L1_osprey_2p2),
2166                    2);
2167            }
2168        }
2169
2170        ah->ah_config.ath_hal_pcie_power_save_enable = 0;
2171
2172#ifdef ATH_BUS_PM
2173        /*Use HAL to config PCI powersave by writing into the SerDes Registers */
2174        ah->ah_config.ath_hal_pcie_ser_des_write = 1;
2175#endif
2176
2177#if 0 /* ATH_WOW */
2178        /* SerDes values during WOW sleep */
2179        INIT_INI_ARRAY(&ahp->ah_ini_pcie_serdes_wow, ar9300_pcie_phy_awow,
2180                       ARRAY_LENGTH(ar9300_pcie_phy_awow), 2);
2181#endif
2182
2183        /* Fast clock modal settings */
2184        INIT_INI_ARRAY(&ahp->ah_ini_modes_additional,
2185            ar9300Modes_fast_clock_osprey_2p2,
2186            ARRAY_LENGTH(ar9300Modes_fast_clock_osprey_2p2), 3);
2187        INIT_INI_ARRAY(&ahp->ah_ini_japan2484,
2188            ar9300_osprey_2p2_baseband_core_txfir_coeff_japan_2484,
2189            ARRAY_LENGTH(
2190                ar9300_osprey_2p2_baseband_core_txfir_coeff_japan_2484), 2);
2191
2192    }
2193
2194    if(AR_SREV_WASP(ah) || AR_SREV_SCORPION(ah))
2195    {
2196#define AR_SOC_RST_OTP_INTF  0xB80600B4
2197#define REG_READ(_reg)       *((volatile u_int32_t *)(_reg))
2198
2199        ahp->ah_enterprise_mode = REG_READ(AR_SOC_RST_OTP_INTF);
2200        if (AR_SREV_SCORPION(ah)) {
2201            ahp->ah_enterprise_mode = ahp->ah_enterprise_mode << 12;
2202        }
2203        ath_hal_printf (ah, "Enterprise mode: 0x%08x\n", ahp->ah_enterprise_mode);
2204#undef REG_READ
2205#undef AR_SOC_RST_OTP_INTF
2206    } else {
2207        ahp->ah_enterprise_mode = OS_REG_READ(ah, AR_ENT_OTP);
2208    }
2209
2210
2211    if (ahpriv->ah_ispcie) {
2212        ar9300_config_pci_power_save(ah, 0, 0);
2213    } else {
2214        ar9300_disable_pcie_phy(ah);
2215    }
2216    ath_hal_printf(ah, "%s: calling ar9300_hw_attach\n", __func__);
2217    ecode = ar9300_hw_attach(ah);
2218    if (ecode != HAL_OK) {
2219        goto bad;
2220    }
2221
2222    /* set gain table pointers according to values read from the eeprom */
2223    ar9300_tx_gain_table_apply(ah);
2224    ar9300_rx_gain_table_apply(ah);
2225
2226    /*
2227    **
2228    ** Got everything we need now to setup the capabilities.
2229    */
2230
2231    if (!ar9300_fill_capability_info(ah)) {
2232        HALDEBUG(ah, HAL_DEBUG_RESET,
2233            "%s:failed ar9300_fill_capability_info\n", __func__);
2234        ecode = HAL_EEREAD;
2235        goto bad;
2236    }
2237    ecode = ar9300_init_mac_addr(ah);
2238    if (ecode != HAL_OK) {
2239        HALDEBUG(ah, HAL_DEBUG_RESET,
2240            "%s: failed initializing mac address\n", __func__);
2241        goto bad;
2242    }
2243
2244    /*
2245     * Initialize receive buffer size to MAC default
2246     */
2247    ahp->rx_buf_size = HAL_RXBUFSIZE_DEFAULT;
2248
2249#if ATH_WOW
2250#if 0
2251    /*
2252     * Needs to be removed once we stop using XB92 XXX
2253     * FIXME: Check with latest boards too - SriniK
2254     */
2255    ar9300_wow_set_gpio_reset_low(ah);
2256#endif
2257
2258    /*
2259     * Clear the Wow Status.
2260     */
2261    OS_REG_WRITE(ah, AR_HOSTIF_REG(ah, AR_PCIE_PM_CTRL),
2262        OS_REG_READ(ah, AR_HOSTIF_REG(ah, AR_PCIE_PM_CTRL)) |
2263        AR_PMCTRL_WOW_PME_CLR);
2264    OS_REG_WRITE(ah, AR_WOW_PATTERN_REG,
2265        AR_WOW_CLEAR_EVENTS(OS_REG_READ(ah, AR_WOW_PATTERN_REG)));
2266#endif
2267
2268    /*
2269     * Set the cur_trig_level to a value that works all modes - 11a/b/g or 11n
2270     * with aggregation enabled or disabled.
2271     */
2272    ahp->ah_tx_trig_level = (AR_FTRIG_512B >> AR_FTRIG_S);
2273
2274    if (AR_SREV_HORNET(ah)) {
2275        ahp->nf_2GHz.nominal = AR_PHY_CCA_NOM_VAL_HORNET_2GHZ;
2276        ahp->nf_2GHz.max     = AR_PHY_CCA_MAX_GOOD_VAL_OSPREY_2GHZ;
2277        ahp->nf_2GHz.min     = AR_PHY_CCA_MIN_GOOD_VAL_OSPREY_2GHZ;
2278        ahp->nf_5GHz.nominal = AR_PHY_CCA_NOM_VAL_OSPREY_5GHZ;
2279        ahp->nf_5GHz.max     = AR_PHY_CCA_MAX_GOOD_VAL_OSPREY_5GHZ;
2280        ahp->nf_5GHz.min     = AR_PHY_CCA_MIN_GOOD_VAL_OSPREY_5GHZ;
2281        ahp->nf_cw_int_delta = AR_PHY_CCA_CW_INT_DELTA;
2282    } else if(AR_SREV_JUPITER(ah) || AR_SREV_APHRODITE(ah)){
2283        ahp->nf_2GHz.nominal = AR_PHY_CCA_NOM_VAL_JUPITER_2GHZ;
2284        ahp->nf_2GHz.max     = AR_PHY_CCA_MAX_GOOD_VAL_OSPREY_2GHZ;
2285        ahp->nf_2GHz.min     = AR_PHY_CCA_MIN_GOOD_VAL_JUPITER_2GHZ;
2286        ahp->nf_5GHz.nominal = AR_PHY_CCA_NOM_VAL_JUPITER_5GHZ;
2287        ahp->nf_5GHz.max     = AR_PHY_CCA_MAX_GOOD_VAL_OSPREY_5GHZ;
2288        ahp->nf_5GHz.min     = AR_PHY_CCA_MIN_GOOD_VAL_JUPITER_5GHZ;
2289        ahp->nf_cw_int_delta = AR_PHY_CCA_CW_INT_DELTA;
2290    }	else {
2291        ahp->nf_2GHz.nominal = AR_PHY_CCA_NOM_VAL_OSPREY_2GHZ;
2292        ahp->nf_2GHz.max     = AR_PHY_CCA_MAX_GOOD_VAL_OSPREY_2GHZ;
2293        ahp->nf_2GHz.min     = AR_PHY_CCA_MIN_GOOD_VAL_OSPREY_2GHZ;
2294        if (AR_SREV_AR9580(ah) || AR_SREV_WASP(ah) || AR_SREV_SCORPION(ah)) {
2295            ahp->nf_5GHz.nominal = AR_PHY_CCA_NOM_VAL_PEACOCK_5GHZ;
2296        } else {
2297            ahp->nf_5GHz.nominal = AR_PHY_CCA_NOM_VAL_OSPREY_5GHZ;
2298        }
2299        ahp->nf_5GHz.max     = AR_PHY_CCA_MAX_GOOD_VAL_OSPREY_5GHZ;
2300        ahp->nf_5GHz.min     = AR_PHY_CCA_MIN_GOOD_VAL_OSPREY_5GHZ;
2301        ahp->nf_cw_int_delta = AR_PHY_CCA_CW_INT_DELTA;
2302     }
2303
2304
2305
2306
2307    /* init BB Panic Watchdog timeout */
2308    if (AR_SREV_HORNET(ah)) {
2309        ahp->ah_bb_panic_timeout_ms = HAL_BB_PANIC_WD_TMO_HORNET;
2310    } else {
2311        ahp->ah_bb_panic_timeout_ms = HAL_BB_PANIC_WD_TMO;
2312    }
2313
2314
2315    /*
2316     * Determine whether tx IQ calibration HW should be enabled,
2317     * and whether tx IQ calibration should be performed during
2318     * AGC calibration, or separately.
2319     */
2320    if (AR_SREV_JUPITER(ah) || AR_SREV_APHRODITE(ah)) {
2321        /*
2322         * Register not initialized yet. This flag will be re-initialized
2323         * after INI loading following each reset.
2324         */
2325        ahp->tx_iq_cal_enable = 1;
2326        /* if tx IQ cal is enabled, do it together with AGC cal */
2327        ahp->tx_iq_cal_during_agc_cal = 1;
2328    } else if (AR_SREV_POSEIDON_OR_LATER(ah) && !AR_SREV_WASP(ah)) {
2329        ahp->tx_iq_cal_enable = 1;
2330        ahp->tx_iq_cal_during_agc_cal = 1;
2331    } else {
2332        /* osprey, hornet, wasp */
2333        ahp->tx_iq_cal_enable = 1;
2334        ahp->tx_iq_cal_during_agc_cal = 0;
2335    }
2336    return ah;
2337
2338bad:
2339    if (ahp) {
2340        ar9300_detach((struct ath_hal *) ahp);
2341    }
2342    if (status) {
2343        *status = ecode;
2344    }
2345    return AH_NULL;
2346}
2347
2348void
2349ar9300_detach(struct ath_hal *ah)
2350{
2351    HALASSERT(ah != AH_NULL);
2352    HALASSERT(ah->ah_magic == AR9300_MAGIC);
2353
2354    /* Make sure that chip is awake before writing to it */
2355    if (!ar9300_set_power_mode(ah, HAL_PM_AWAKE, AH_TRUE)) {
2356        HALDEBUG(ah, HAL_DEBUG_UNMASKABLE,
2357                 "%s: failed to wake up chip\n",
2358                 __func__);
2359    }
2360
2361    ar9300_hw_detach(ah);
2362    ar9300_set_power_mode(ah, HAL_PM_FULL_SLEEP, AH_TRUE);
2363
2364//    ath_hal_hdprintf_deregister(ah);
2365
2366    if (AH9300(ah)->ah_cal_mem)
2367        ath_hal_free(AH9300(ah)->ah_cal_mem);
2368    AH9300(ah)->ah_cal_mem = AH_NULL;
2369
2370    ath_hal_free(ah);
2371}
2372
2373struct ath_hal_9300 *
2374ar9300_new_state(u_int16_t devid, HAL_SOFTC sc,
2375    HAL_BUS_TAG st, HAL_BUS_HANDLE sh,
2376    uint16_t *eepromdata, HAL_STATUS *status)
2377{
2378    static const u_int8_t defbssidmask[IEEE80211_ADDR_LEN] =
2379        { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
2380    struct ath_hal_9300 *ahp;
2381    struct ath_hal *ah;
2382
2383    /* NB: memory is returned zero'd */
2384    ahp = ath_hal_malloc(sizeof(struct ath_hal_9300));
2385    if (ahp == AH_NULL) {
2386        HALDEBUG(AH_NULL, HAL_DEBUG_UNMASKABLE,
2387                 "%s: cannot allocate memory for state block\n",
2388                 __func__);
2389        *status = HAL_ENOMEM;
2390        return AH_NULL;
2391    }
2392
2393    ah = &ahp->ah_priv.h;
2394    /* set initial values */
2395
2396    /* stub everything first */
2397    ar9300_set_stub_functions(ah);
2398
2399    /* setup the FreeBSD HAL methods */
2400    ar9300_attach_freebsd_ops(ah);
2401
2402    /* These are private to this particular file, so .. */
2403    ah->ah_disablePCIE = ar9300_disable_pcie_phy;
2404    AH_PRIVATE(ah)->ah_getNfAdjust = ar9300_get_nf_adjust;
2405    AH_PRIVATE(ah)->ah_getChipPowerLimits = ar9300_get_chip_power_limits;
2406
2407#if 0
2408    /* Attach Osprey structure as default hal structure */
2409    OS_MEMCPY(&ahp->ah_priv.priv, &ar9300hal, sizeof(ahp->ah_priv.priv));
2410#endif
2411
2412#if 0
2413    AH_PRIVATE(ah)->amem_handle = amem_handle;
2414    AH_PRIVATE(ah)->ah_osdev = osdev;
2415#endif
2416    ah->ah_sc = sc;
2417    ah->ah_st = st;
2418    ah->ah_sh = sh;
2419    ah->ah_magic = AR9300_MAGIC;
2420    AH_PRIVATE(ah)->ah_devid = devid;
2421
2422    AH_PRIVATE(ah)->ah_flags = 0;
2423
2424    /*
2425    ** Initialize factory defaults in the private space
2426    */
2427//    ath_hal_factory_defaults(AH_PRIVATE(ah), hal_conf_parm);
2428    ar9300_config_defaults_freebsd(ah);
2429
2430    /* XXX FreeBSD: cal is always in EEPROM */
2431#if 0
2432    if (!hal_conf_parm->calInFlash) {
2433        AH_PRIVATE(ah)->ah_flags |= AH_USE_EEPROM;
2434    }
2435#endif
2436    AH_PRIVATE(ah)->ah_flags |= AH_USE_EEPROM;
2437
2438#if 0
2439    if (ar9300_eep_data_in_flash(ah)) {
2440        ahp->ah_priv.priv.ah_eeprom_read  = ar9300_flash_read;
2441        ahp->ah_priv.priv.ah_eeprom_dump  = AH_NULL;
2442    } else {
2443        ahp->ah_priv.priv.ah_eeprom_read  = ar9300_eeprom_read_word;
2444    }
2445#endif
2446
2447    /* XXX FreeBSD - for now, just supports EEPROM reading */
2448    ahp->ah_priv.ah_eepromRead = ar9300_eeprom_read_word;
2449
2450    AH_PRIVATE(ah)->ah_powerLimit = MAX_RATE_POWER;
2451    AH_PRIVATE(ah)->ah_tpScale = HAL_TP_SCALE_MAX;  /* no scaling */
2452
2453    ahp->ah_atim_window = 0;         /* [0..1000] */
2454    ahp->ah_diversity_control =
2455        ah->ah_config.ath_hal_diversity_control;
2456    ahp->ah_antenna_switch_swap =
2457        ah->ah_config.ath_hal_antenna_switch_swap;
2458
2459    /*
2460     * Enable MIC handling.
2461     */
2462    ahp->ah_sta_id1_defaults = AR_STA_ID1_CRPT_MIC_ENABLE;
2463    ahp->ah_enable32k_hz_clock = DONT_USE_32KHZ;/* XXX */
2464    ahp->ah_slot_time = (u_int) -1;
2465    ahp->ah_ack_timeout = (u_int) -1;
2466    OS_MEMCPY(&ahp->ah_bssid_mask, defbssidmask, IEEE80211_ADDR_LEN);
2467
2468    /*
2469     * 11g-specific stuff
2470     */
2471    ahp->ah_g_beacon_rate = 0;        /* adhoc beacon fixed rate */
2472
2473    /* SM power mode: Attach time, disable any setting */
2474    ahp->ah_sm_power_mode = HAL_SMPS_DEFAULT;
2475
2476    return ahp;
2477}
2478
2479HAL_BOOL
2480ar9300_chip_test(struct ath_hal *ah)
2481{
2482    /*u_int32_t reg_addr[2] = { AR_STA_ID0, AR_PHY_BASE+(8 << 2) };*/
2483    u_int32_t reg_addr[2] = { AR_STA_ID0 };
2484    u_int32_t reg_hold[2];
2485    u_int32_t pattern_data[4] =
2486        { 0x55555555, 0xaaaaaaaa, 0x66666666, 0x99999999 };
2487    int i, j;
2488
2489    /* Test PHY & MAC registers */
2490    for (i = 0; i < 1; i++) {
2491        u_int32_t addr = reg_addr[i];
2492        u_int32_t wr_data, rd_data;
2493
2494        reg_hold[i] = OS_REG_READ(ah, addr);
2495        for (j = 0; j < 0x100; j++) {
2496            wr_data = (j << 16) | j;
2497            OS_REG_WRITE(ah, addr, wr_data);
2498            rd_data = OS_REG_READ(ah, addr);
2499            if (rd_data != wr_data) {
2500                HALDEBUG(ah, HAL_DEBUG_REGIO,
2501                    "%s: address test failed addr: "
2502                    "0x%08x - wr:0x%08x != rd:0x%08x\n",
2503                    __func__, addr, wr_data, rd_data);
2504                return AH_FALSE;
2505            }
2506        }
2507        for (j = 0; j < 4; j++) {
2508            wr_data = pattern_data[j];
2509            OS_REG_WRITE(ah, addr, wr_data);
2510            rd_data = OS_REG_READ(ah, addr);
2511            if (wr_data != rd_data) {
2512                HALDEBUG(ah, HAL_DEBUG_REGIO,
2513                    "%s: address test failed addr: "
2514                    "0x%08x - wr:0x%08x != rd:0x%08x\n",
2515                    __func__, addr, wr_data, rd_data);
2516                return AH_FALSE;
2517            }
2518        }
2519        OS_REG_WRITE(ah, reg_addr[i], reg_hold[i]);
2520    }
2521    OS_DELAY(100);
2522    return AH_TRUE;
2523}
2524
2525/*
2526 * Store the channel edges for the requested operational mode
2527 */
2528HAL_BOOL
2529ar9300_get_channel_edges(struct ath_hal *ah,
2530    u_int16_t flags, u_int16_t *low, u_int16_t *high)
2531{
2532    struct ath_hal_private *ahpriv = AH_PRIVATE(ah);
2533    HAL_CAPABILITIES *p_cap = &ahpriv->ah_caps;
2534
2535    if (flags & IEEE80211_CHAN_5GHZ) {
2536        *low = p_cap->halLow5GhzChan;
2537        *high = p_cap->halHigh5GhzChan;
2538        return AH_TRUE;
2539    }
2540    if ((flags & IEEE80211_CHAN_2GHZ)) {
2541        *low = p_cap->halLow2GhzChan;
2542        *high = p_cap->halHigh2GhzChan;
2543
2544        return AH_TRUE;
2545    }
2546    return AH_FALSE;
2547}
2548
2549HAL_BOOL
2550ar9300_regulatory_domain_override(struct ath_hal *ah, u_int16_t regdmn)
2551{
2552    AH_PRIVATE(ah)->ah_currentRD = regdmn;
2553    return AH_TRUE;
2554}
2555
2556/*
2557 * Fill all software cached or static hardware state information.
2558 * Return failure if capabilities are to come from EEPROM and
2559 * cannot be read.
2560 */
2561HAL_BOOL
2562ar9300_fill_capability_info(struct ath_hal *ah)
2563{
2564#define AR_KEYTABLE_SIZE    128
2565    struct ath_hal_9300 *ahp = AH9300(ah);
2566    struct ath_hal_private *ahpriv = AH_PRIVATE(ah);
2567    HAL_CAPABILITIES *p_cap = &ahpriv->ah_caps;
2568    u_int16_t cap_field = 0, eeval;
2569
2570    ahpriv->ah_devType = (u_int16_t)ar9300_eeprom_get(ahp, EEP_DEV_TYPE);
2571    eeval = ar9300_eeprom_get(ahp, EEP_REG_0);
2572
2573    /* XXX record serial number */
2574    AH_PRIVATE(ah)->ah_currentRD = eeval;
2575
2576    /* Always enable fast clock; leave it up to EEPROM and channel */
2577    p_cap->halSupportsFastClock5GHz = AH_TRUE;
2578
2579    p_cap->halIntrMitigation = AH_TRUE;
2580    eeval = ar9300_eeprom_get(ahp, EEP_REG_1);
2581    AH_PRIVATE(ah)->ah_currentRDext = eeval | AR9300_RDEXT_DEFAULT;
2582
2583    /* Read the capability EEPROM location */
2584    cap_field = ar9300_eeprom_get(ahp, EEP_OP_CAP);
2585
2586    /* Construct wireless mode from EEPROM */
2587    p_cap->halWirelessModes = 0;
2588    eeval = ar9300_eeprom_get(ahp, EEP_OP_MODE);
2589
2590    /*
2591     * XXX FreeBSD specific: for now, set ath_hal_ht_enable to 1,
2592     * or we won't have 11n support.
2593     */
2594    ah->ah_config.ath_hal_ht_enable = 1;
2595
2596    if (eeval & AR9300_OPFLAGS_11A) {
2597        p_cap->halWirelessModes |= HAL_MODE_11A |
2598            ((!ah->ah_config.ath_hal_ht_enable ||
2599              (eeval & AR9300_OPFLAGS_N_5G_HT20)) ?  0 :
2600             (HAL_MODE_11NA_HT20 | ((eeval & AR9300_OPFLAGS_N_5G_HT40) ? 0 :
2601                                    (HAL_MODE_11NA_HT40PLUS | HAL_MODE_11NA_HT40MINUS))));
2602    }
2603    if (eeval & AR9300_OPFLAGS_11G) {
2604        p_cap->halWirelessModes |= HAL_MODE_11B | HAL_MODE_11G |
2605            ((!ah->ah_config.ath_hal_ht_enable ||
2606              (eeval & AR9300_OPFLAGS_N_2G_HT20)) ?  0 :
2607             (HAL_MODE_11NG_HT20 | ((eeval & AR9300_OPFLAGS_N_2G_HT40) ? 0 :
2608                                    (HAL_MODE_11NG_HT40PLUS | HAL_MODE_11NG_HT40MINUS))));
2609    }
2610
2611    /* Get chainamsks from eeprom */
2612    p_cap->halTxChainMask = ar9300_eeprom_get(ahp, EEP_TX_MASK);
2613    p_cap->halRxChainMask = ar9300_eeprom_get(ahp, EEP_RX_MASK);
2614
2615
2616
2617#define owl_get_ntxchains(_txchainmask) \
2618    (((_txchainmask >> 2) & 1) + ((_txchainmask >> 1) & 1) + (_txchainmask & 1))
2619
2620    /* FreeBSD: Update number of TX/RX streams */
2621    p_cap->halTxStreams = owl_get_ntxchains(p_cap->halTxChainMask);
2622    p_cap->halRxStreams = owl_get_ntxchains(p_cap->halRxChainMask);
2623
2624
2625    /*
2626     * This being a newer chip supports TKIP non-splitmic mode.
2627     *
2628     */
2629    ahp->ah_misc_mode |= AR_PCU_MIC_NEW_LOC_ENA;
2630    p_cap->halTkipMicTxRxKeySupport = AH_TRUE;
2631
2632    p_cap->halLow2GhzChan = 2312;
2633    p_cap->halHigh2GhzChan = 2732;
2634
2635    p_cap->halLow5GhzChan = 4920;
2636    p_cap->halHigh5GhzChan = 6100;
2637
2638    p_cap->halCipherCkipSupport = AH_FALSE;
2639    p_cap->halCipherTkipSupport = AH_TRUE;
2640    p_cap->halCipherAesCcmSupport = AH_TRUE;
2641
2642    p_cap->halMicCkipSupport = AH_FALSE;
2643    p_cap->halMicTkipSupport = AH_TRUE;
2644    p_cap->halMicAesCcmSupport = AH_TRUE;
2645
2646    p_cap->halChanSpreadSupport = AH_TRUE;
2647    p_cap->halSleepAfterBeaconBroken = AH_TRUE;
2648
2649    p_cap->halBurstSupport = AH_TRUE;
2650    p_cap->halChapTuningSupport = AH_TRUE;
2651    p_cap->halTurboPrimeSupport = AH_TRUE;
2652    p_cap->halFastFramesSupport = AH_FALSE;
2653
2654    p_cap->halTurboGSupport = p_cap->halWirelessModes & HAL_MODE_108G;
2655
2656//    p_cap->hal_xr_support = AH_FALSE;
2657
2658    p_cap->halHTSupport =
2659        ah->ah_config.ath_hal_ht_enable ?  AH_TRUE : AH_FALSE;
2660
2661    p_cap->halGTTSupport = AH_TRUE;
2662    p_cap->halPSPollBroken = AH_TRUE;    /* XXX fixed in later revs? */
2663    p_cap->halNumMRRetries = 4;		/* Hardware supports 4 MRR */
2664    p_cap->halHTSGI20Support = AH_TRUE;
2665    p_cap->halVEOLSupport = AH_TRUE;
2666    p_cap->halBssIdMaskSupport = AH_TRUE;
2667    /* Bug 26802, fixed in later revs? */
2668    p_cap->halMcastKeySrchSupport = AH_TRUE;
2669    p_cap->halTsfAddSupport = AH_TRUE;
2670
2671    if (cap_field & AR_EEPROM_EEPCAP_MAXQCU) {
2672        p_cap->halTotalQueues = MS(cap_field, AR_EEPROM_EEPCAP_MAXQCU);
2673    } else {
2674        p_cap->halTotalQueues = HAL_NUM_TX_QUEUES;
2675    }
2676
2677    if (cap_field & AR_EEPROM_EEPCAP_KC_ENTRIES) {
2678        p_cap->halKeyCacheSize =
2679            1 << MS(cap_field, AR_EEPROM_EEPCAP_KC_ENTRIES);
2680    } else {
2681        p_cap->halKeyCacheSize = AR_KEYTABLE_SIZE;
2682    }
2683    p_cap->halFastCCSupport = AH_TRUE;
2684//    p_cap->hal_num_mr_retries = 4;
2685//    ahp->hal_tx_trig_level_max = MAX_TX_FIFO_THRESHOLD;
2686
2687    p_cap->halNumGpioPins = AR9382_MAX_GPIO_PIN_NUM;
2688
2689#if 0
2690    /* XXX Verify support in Osprey */
2691    if (AR_SREV_MERLIN_10_OR_LATER(ah)) {
2692        p_cap->halWowSupport = AH_TRUE;
2693        p_cap->hal_wow_match_pattern_exact = AH_TRUE;
2694        if (AR_SREV_MERLIN(ah)) {
2695            p_cap->hal_wow_pattern_match_dword = AH_TRUE;
2696        }
2697    } else {
2698        p_cap->halWowSupport = AH_FALSE;
2699        p_cap->hal_wow_match_pattern_exact = AH_FALSE;
2700    }
2701#endif
2702    p_cap->halWowSupport = AH_TRUE;
2703    p_cap->halWowMatchPatternExact = AH_TRUE;
2704    if (AR_SREV_POSEIDON(ah)) {
2705        p_cap->halWowMatchPatternExact = AH_TRUE;
2706    }
2707
2708    p_cap->halCSTSupport = AH_TRUE;
2709
2710    p_cap->halRifsRxSupport = AH_TRUE;
2711    p_cap->halRifsTxSupport = AH_TRUE;
2712
2713#define	IEEE80211_AMPDU_LIMIT_MAX (65536)
2714    p_cap->halRtsAggrLimit = IEEE80211_AMPDU_LIMIT_MAX;
2715#undef IEEE80211_AMPDU_LIMIT_MAX
2716
2717    p_cap->halMfpSupport = ah->ah_config.ath_hal_mfp_support;
2718
2719    p_cap->halForcePpmSupport = AH_TRUE;
2720    p_cap->halHwBeaconProcSupport = AH_TRUE;
2721
2722    /* ar9300 - has the HW UAPSD trigger support,
2723     * but it has the following limitations
2724     * The power state change from the following
2725     * frames are not put in High priority queue.
2726     *     i) Mgmt frames
2727     *     ii) NoN QoS frames
2728     *     iii) QoS frames form the access categories for which
2729     *          UAPSD is not enabled.
2730     * so we can not enable this feature currently.
2731     * could be enabled, if these limitations are fixed
2732     * in later versions of ar9300 chips
2733     */
2734    p_cap->halHasUapsdSupport = AH_FALSE;
2735
2736    /* Number of buffers that can be help in a single TxD */
2737    p_cap->halNumTxMaps = 4;
2738
2739    p_cap->halTxDescLen = sizeof(struct ar9300_txc);
2740    p_cap->halTxStatusLen = sizeof(struct ar9300_txs);
2741    p_cap->halRxStatusLen = sizeof(struct ar9300_rxs);
2742
2743    p_cap->halRxHpFifoDepth = HAL_HP_RXFIFO_DEPTH;
2744    p_cap->halRxLpFifoDepth = HAL_LP_RXFIFO_DEPTH;
2745
2746    /* Enable extension channel DFS support */
2747    p_cap->halUseCombinedRadarRssi = AH_TRUE;
2748    p_cap->halExtChanDfsSupport = AH_TRUE;
2749#if ATH_SUPPORT_SPECTRAL
2750    p_cap->halSpectralScanSupport = AH_TRUE;
2751#endif
2752
2753    ahpriv->ah_rfsilent = ar9300_eeprom_get(ahp, EEP_RF_SILENT);
2754    if (ahpriv->ah_rfsilent & EEP_RFSILENT_ENABLED) {
2755        ahp->ah_gpio_select = MS(ahpriv->ah_rfsilent, EEP_RFSILENT_GPIO_SEL);
2756        ahp->ah_polarity   = MS(ahpriv->ah_rfsilent, EEP_RFSILENT_POLARITY);
2757
2758        ath_hal_enable_rfkill(ah, AH_TRUE);
2759        p_cap->halRfSilentSupport = AH_TRUE;
2760    }
2761
2762    /* XXX */
2763    p_cap->halWpsPushButtonSupport = AH_FALSE;
2764
2765#ifdef ATH_BT_COEX
2766    p_cap->halBtCoexSupport = AH_TRUE;
2767    p_cap->halBtCoexApsmWar = AH_FALSE;
2768#endif
2769
2770    p_cap->halGenTimerSupport = AH_TRUE;
2771    ahp->ah_avail_gen_timers = ~((1 << AR_FIRST_NDP_TIMER) - 1);
2772    ahp->ah_avail_gen_timers &= (1 << AR_NUM_GEN_TIMERS) - 1;
2773    /*
2774     * According to Kyungwan, generic timer 0 and 8 are special
2775     * timers. Remove timer 8 from the available gen timer list.
2776     * Jupiter testing shows timer won't trigger with timer 8.
2777     */
2778    ahp->ah_avail_gen_timers &= ~(1 << AR_GEN_TIMER_RESERVED);
2779
2780    if (AR_SREV_JUPITER(ah) || AR_SREV_APHRODITE(ah)) {
2781#if ATH_SUPPORT_MCI
2782        if (ah->ah_config.ath_hal_mci_config & ATH_MCI_CONFIG_DISABLE_MCI)
2783        {
2784            p_cap->halMciSupport = AH_FALSE;
2785        }
2786        else
2787#endif
2788        {
2789            p_cap->halMciSupport = (ahp->ah_enterprise_mode &
2790                            AR_ENT_OTP_49GHZ_DISABLE) ? AH_FALSE: AH_TRUE;
2791        }
2792        HALDEBUG(AH_NULL, HAL_DEBUG_UNMASKABLE,
2793                 "%s: (MCI) MCI support = %d\n",
2794                 __func__, p_cap->halMciSupport);
2795    }
2796    else {
2797        p_cap->halMciSupport = AH_FALSE;
2798    }
2799
2800    if (AR_SREV_JUPITER_20(ah)) {
2801        p_cap->halRadioRetentionSupport = AH_TRUE;
2802    } else {
2803        p_cap->halRadioRetentionSupport = AH_FALSE;
2804    }
2805
2806    p_cap->halAutoSleepSupport = AH_TRUE;
2807
2808    p_cap->halMbssidAggrSupport = AH_TRUE;
2809//    p_cap->hal_proxy_sta_support = AH_TRUE;
2810
2811    /* XXX Mark it true after it is verfied as fixed */
2812    p_cap->hal4kbSplitTransSupport = AH_FALSE;
2813
2814    /* Read regulatory domain flag */
2815    if (AH_PRIVATE(ah)->ah_currentRDext & (1 << REG_EXT_JAPAN_MIDBAND)) {
2816        /*
2817         * If REG_EXT_JAPAN_MIDBAND is set, turn on U1 EVEN, U2, and MIDBAND.
2818         */
2819        p_cap->halRegCap =
2820            AR_EEPROM_EEREGCAP_EN_KK_NEW_11A |
2821            AR_EEPROM_EEREGCAP_EN_KK_U1_EVEN |
2822            AR_EEPROM_EEREGCAP_EN_KK_U2      |
2823            AR_EEPROM_EEREGCAP_EN_KK_MIDBAND;
2824    } else {
2825        p_cap->halRegCap =
2826            AR_EEPROM_EEREGCAP_EN_KK_NEW_11A | AR_EEPROM_EEREGCAP_EN_KK_U1_EVEN;
2827    }
2828
2829    /* For AR9300 and above, midband channels are always supported */
2830    p_cap->halRegCap |= AR_EEPROM_EEREGCAP_EN_FCC_MIDBAND;
2831
2832    p_cap->halNumAntCfg5GHz =
2833        ar9300_eeprom_get_num_ant_config(ahp, HAL_FREQ_BAND_5GHZ);
2834    p_cap->halNumAntCfg2GHz =
2835        ar9300_eeprom_get_num_ant_config(ahp, HAL_FREQ_BAND_2GHZ);
2836
2837    /* STBC supported */
2838    p_cap->halRxStbcSupport = 1; /* number of streams for STBC recieve. */
2839    if (AR_SREV_HORNET(ah) || AR_SREV_POSEIDON(ah) || AR_SREV_APHRODITE(ah)) {
2840        p_cap->halTxStbcSupport = 0;
2841    } else {
2842        p_cap->halTxStbcSupport = 1;
2843    }
2844
2845    p_cap->halEnhancedDmaSupport = AH_TRUE;
2846    p_cap->halEnhancedDfsSupport = AH_TRUE;
2847
2848    /*
2849     *  EV61133 (missing interrupts due to AR_ISR_RAC).
2850     *  Fixed in Osprey 2.0.
2851     */
2852    p_cap->halIsrRacSupport = AH_TRUE;
2853
2854    /* XXX FreeBSD won't support TKIP and WEP aggregation */
2855#if 0
2856    p_cap->hal_wep_tkip_aggr_support = AH_TRUE;
2857    p_cap->hal_wep_tkip_aggr_num_tx_delim = 10;    /* TBD */
2858    p_cap->hal_wep_tkip_aggr_num_rx_delim = 10;    /* TBD */
2859    p_cap->hal_wep_tkip_max_ht_rate = 15;         /* TBD */
2860#endif
2861
2862    /*
2863     * XXX FreeBSD won't need these; but eventually add them
2864     * and add the WARs - AGGR extra delim WAR is useful to know
2865     * about.
2866     */
2867#if 0
2868    p_cap->hal_cfend_fix_support = AH_FALSE;
2869    p_cap->hal_aggr_extra_delim_war = AH_FALSE;
2870#endif
2871    p_cap->halHasLongRxDescTsf = AH_TRUE;
2872//    p_cap->hal_rx_desc_timestamp_bits = 32;
2873    p_cap->halRxTxAbortSupport = AH_TRUE;
2874    p_cap->hal_ani_poll_interval = AR9300_ANI_POLLINTERVAL;
2875    p_cap->hal_channel_switch_time_usec = AR9300_CHANNEL_SWITCH_TIME_USEC;
2876
2877    /* Transmit Beamforming supported, fill capabilities */
2878    p_cap->halPaprdEnabled = ar9300_eeprom_get(ahp, EEP_PAPRD_ENABLED);
2879    p_cap->halChanHalfRate =
2880        !(ahp->ah_enterprise_mode & AR_ENT_OTP_10MHZ_DISABLE);
2881    p_cap->halChanQuarterRate =
2882        !(ahp->ah_enterprise_mode & AR_ENT_OTP_5MHZ_DISABLE);
2883
2884    if(AR_SREV_JUPITER(ah) || AR_SREV_APHRODITE(ah)){
2885        /* There is no AR_ENT_OTP_49GHZ_DISABLE feature in Jupiter, now the bit is used to disable BT. */
2886        p_cap->hal49GhzSupport = 1;
2887    } else {
2888        p_cap->hal49GhzSupport = !(ahp->ah_enterprise_mode & AR_ENT_OTP_49GHZ_DISABLE);
2889    }
2890
2891    if (AR_SREV_POSEIDON(ah) || AR_SREV_HORNET(ah) || AR_SREV_APHRODITE(ah)) {
2892        /* LDPC supported */
2893        /* Poseidon doesn't support LDPC, or it will cause receiver CRC Error */
2894        p_cap->halLDPCSupport = AH_FALSE;
2895        /* PCI_E LCR offset */
2896        if (AR_SREV_POSEIDON(ah)) {
2897            p_cap->hal_pcie_lcr_offset = 0x80; /*for Poseidon*/
2898        }
2899        /*WAR method for APSM L0s with Poseidon 1.0*/
2900        if (AR_SREV_POSEIDON_10(ah)) {
2901            p_cap->hal_pcie_lcr_extsync_en = AH_TRUE;
2902        }
2903    } else {
2904        p_cap->halLDPCSupport = AH_TRUE;
2905    }
2906
2907    /* XXX is this a flag, or a chainmask number? */
2908    p_cap->halApmEnable = !! ar9300_eeprom_get(ahp, EEP_CHAIN_MASK_REDUCE);
2909#if ATH_ANT_DIV_COMB
2910    if (AR_SREV_HORNET(ah) || AR_SREV_POSEIDON_11_OR_LATER(ah)) {
2911        if (ahp->ah_diversity_control == HAL_ANT_VARIABLE) {
2912            u_int8_t ant_div_control1 =
2913                ar9300_eeprom_get(ahp, EEP_ANTDIV_control);
2914            /* if enable_lnadiv is 0x1 and enable_fast_div is 0x1,
2915             * we enable the diversity-combining algorithm.
2916             */
2917            if ((ant_div_control1 >> 0x6) == 0x3) {
2918                p_cap->halAntDivCombSupport = AH_TRUE;
2919            }
2920            p_cap->halAntDivCombSupportOrg = p_cap->halAntDivCombSupport;
2921        }
2922    }
2923#endif /* ATH_ANT_DIV_COMB */
2924
2925    /*
2926     * FreeBSD: enable LNA mixing if the chip is Hornet or Poseidon.
2927     */
2928    if (AR_SREV_HORNET(ah) || AR_SREV_POSEIDON_11_OR_LATER(ah)) {
2929        p_cap->halRxUsingLnaMixing = AH_TRUE;
2930    }
2931
2932
2933#if ATH_WOW_OFFLOAD
2934    if (AR_SREV_JUPITER_20_OR_LATER(ah) || AR_SREV_APHRODITE(ah)) {
2935        p_cap->hal_wow_gtk_offload_support    = AH_TRUE;
2936        p_cap->hal_wow_arp_offload_support    = AH_TRUE;
2937        p_cap->hal_wow_ns_offload_support     = AH_TRUE;
2938        p_cap->hal_wow_4way_hs_wakeup_support = AH_TRUE;
2939        p_cap->hal_wow_acer_magic_support     = AH_TRUE;
2940        p_cap->hal_wow_acer_swka_support      = AH_TRUE;
2941    } else {
2942        p_cap->hal_wow_gtk_offload_support    = AH_FALSE;
2943        p_cap->hal_wow_arp_offload_support    = AH_FALSE;
2944        p_cap->hal_wow_ns_offload_support     = AH_FALSE;
2945        p_cap->hal_wow_4way_hs_wakeup_support = AH_FALSE;
2946        p_cap->hal_wow_acer_magic_support     = AH_FALSE;
2947        p_cap->hal_wow_acer_swka_support      = AH_FALSE;
2948    }
2949#endif /* ATH_WOW_OFFLOAD */
2950
2951
2952    return AH_TRUE;
2953#undef AR_KEYTABLE_SIZE
2954}
2955
2956#if 0
2957static HAL_BOOL
2958ar9300_get_chip_power_limits(struct ath_hal *ah, HAL_CHANNEL *chans,
2959    u_int32_t nchans)
2960{
2961    struct ath_hal_9300 *ahp = AH9300(ah);
2962
2963    return ahp->ah_rf_hal.get_chip_power_lim(ah, chans, nchans);
2964}
2965#endif
2966/* XXX FreeBSD */
2967
2968static HAL_BOOL
2969ar9300_get_chip_power_limits(struct ath_hal *ah,
2970    struct ieee80211_channel *chan)
2971{
2972
2973	chan->ic_maxpower = AR9300_MAX_RATE_POWER;
2974	chan->ic_minpower = 0;
2975
2976	return AH_TRUE;
2977}
2978
2979/*
2980 * Disable PLL when in L0s as well as receiver clock when in L1.
2981 * This power saving option must be enabled through the Serdes.
2982 *
2983 * Programming the Serdes must go through the same 288 bit serial shift
2984 * register as the other analog registers.  Hence the 9 writes.
2985 *
2986 * XXX Clean up the magic numbers.
2987 */
2988void
2989ar9300_config_pci_power_save(struct ath_hal *ah, int restore, int power_off)
2990{
2991    struct ath_hal_9300 *ahp = AH9300(ah);
2992    int i;
2993
2994    if (AH_PRIVATE(ah)->ah_ispcie != AH_TRUE) {
2995        return;
2996    }
2997
2998    /*
2999     * Increase L1 Entry Latency. Some WB222 boards don't have
3000     * this change in eeprom/OTP.
3001     */
3002    if (AR_SREV_JUPITER(ah)) {
3003        u_int32_t val = ah->ah_config.ath_hal_war70c;
3004        if ((val & 0xff000000) == 0x17000000) {
3005            val &= 0x00ffffff;
3006            val |= 0x27000000;
3007            OS_REG_WRITE(ah, 0x570c, val);
3008        }
3009    }
3010
3011    /* Do not touch SERDES registers */
3012    if (ah->ah_config.ath_hal_pcie_power_save_enable == 2) {
3013        return;
3014    }
3015
3016    /* Nothing to do on restore for 11N */
3017    if (!restore) {
3018        /* set bit 19 to allow forcing of pcie core into L1 state */
3019        OS_REG_SET_BIT(ah,
3020            AR_HOSTIF_REG(ah, AR_PCIE_PM_CTRL), AR_PCIE_PM_CTRL_ENA);
3021
3022        /*
3023         * Set PCIE workaround config only if requested, else use the reset
3024         * value of this register.
3025         */
3026        if (ah->ah_config.ath_hal_pcie_waen) {
3027            OS_REG_WRITE(ah,
3028                AR_HOSTIF_REG(ah, AR_WA),
3029                ah->ah_config.ath_hal_pcie_waen);
3030        } else {
3031            /* Set Bits 17 and 14 in the AR_WA register. */
3032            OS_REG_WRITE(ah, AR_HOSTIF_REG(ah, AR_WA), ahp->ah_wa_reg_val);
3033        }
3034    }
3035
3036    /* Configure PCIE after Ini init. SERDES values now come from ini file */
3037    if (ah->ah_config.ath_hal_pcie_ser_des_write) {
3038        if (power_off) {
3039            for (i = 0; i < ahp->ah_ini_pcie_serdes.ia_rows; i++) {
3040                OS_REG_WRITE(ah,
3041                    INI_RA(&ahp->ah_ini_pcie_serdes, i, 0),
3042                    INI_RA(&ahp->ah_ini_pcie_serdes, i, 1));
3043            }
3044        } else {
3045            for (i = 0; i < ahp->ah_ini_pcie_serdes_low_power.ia_rows; i++) {
3046                OS_REG_WRITE(ah,
3047                    INI_RA(&ahp->ah_ini_pcie_serdes_low_power, i, 0),
3048                    INI_RA(&ahp->ah_ini_pcie_serdes_low_power, i, 1));
3049            }
3050        }
3051    }
3052
3053}
3054
3055/*
3056 * Recipe from charles to turn off PCIe PHY in PCI mode for power savings
3057 */
3058void
3059ar9300_disable_pcie_phy(struct ath_hal *ah)
3060{
3061    /* Osprey does not support PCI mode */
3062}
3063
3064static inline HAL_STATUS
3065ar9300_init_mac_addr(struct ath_hal *ah)
3066{
3067    u_int32_t sum;
3068    int i;
3069    u_int16_t eeval;
3070    struct ath_hal_9300 *ahp = AH9300(ah);
3071    u_int32_t EEP_MAC [] = { EEP_MAC_LSW, EEP_MAC_MID, EEP_MAC_MSW };
3072
3073    sum = 0;
3074    for (i = 0; i < 3; i++) {
3075        eeval = ar9300_eeprom_get(ahp, EEP_MAC[i]);
3076        sum += eeval;
3077        ahp->ah_macaddr[2*i] = eeval >> 8;
3078        ahp->ah_macaddr[2*i + 1] = eeval & 0xff;
3079    }
3080    if (sum == 0 || sum == 0xffff*3) {
3081        HALDEBUG(ah, HAL_DEBUG_EEPROM, "%s: mac address read failed: %s\n",
3082            __func__, ath_hal_ether_sprintf(ahp->ah_macaddr));
3083        return HAL_EEBADMAC;
3084    }
3085
3086    return HAL_OK;
3087}
3088
3089/*
3090 * Code for the "real" chip i.e. non-emulation. Review and revisit
3091 * when actual hardware is at hand.
3092 */
3093static inline HAL_STATUS
3094ar9300_hw_attach(struct ath_hal *ah)
3095{
3096    HAL_STATUS ecode;
3097
3098    if (!ar9300_chip_test(ah)) {
3099        HALDEBUG(ah, HAL_DEBUG_REGIO,
3100            "%s: hardware self-test failed\n", __func__);
3101        return HAL_ESELFTEST;
3102    }
3103
3104    ath_hal_printf(ah, "%s: calling ar9300_eeprom_attach\n", __func__);
3105    ecode = ar9300_eeprom_attach(ah);
3106    ath_hal_printf(ah, "%s: ar9300_eeprom_attach returned %d\n", __func__, ecode);
3107    if (ecode != HAL_OK) {
3108        return ecode;
3109    }
3110    if (!ar9300_rf_attach(ah, &ecode)) {
3111        HALDEBUG(ah, HAL_DEBUG_RESET, "%s: RF setup failed, status %u\n",
3112            __func__, ecode);
3113    }
3114
3115    if (ecode != HAL_OK) {
3116        return ecode;
3117    }
3118    ar9300_ani_attach(ah);
3119
3120    return HAL_OK;
3121}
3122
3123static inline void
3124ar9300_hw_detach(struct ath_hal *ah)
3125{
3126    /* XXX EEPROM allocated state */
3127    ar9300_ani_detach(ah);
3128}
3129
3130static int16_t
3131ar9300_get_nf_adjust(struct ath_hal *ah, const HAL_CHANNEL_INTERNAL *c)
3132{
3133    return 0;
3134}
3135
3136void
3137ar9300_set_immunity(struct ath_hal *ah, HAL_BOOL enable)
3138{
3139    struct ath_hal_9300 *ahp = AH9300(ah);
3140    u_int32_t m1_thresh_low = enable ? 127 : ahp->ah_immunity_vals[0],
3141              m2_thresh_low = enable ? 127 : ahp->ah_immunity_vals[1],
3142              m1_thresh = enable ? 127 : ahp->ah_immunity_vals[2],
3143              m2_thresh = enable ? 127 : ahp->ah_immunity_vals[3],
3144              m2_count_thr = enable ? 31 : ahp->ah_immunity_vals[4],
3145              m2_count_thr_low = enable ? 63 : ahp->ah_immunity_vals[5];
3146
3147    if (ahp->ah_immunity_on == enable) {
3148        return;
3149    }
3150
3151    ahp->ah_immunity_on = enable;
3152
3153    OS_REG_RMW_FIELD(ah, AR_PHY_SFCORR_LOW,
3154                     AR_PHY_SFCORR_LOW_M1_THRESH_LOW, m1_thresh_low);
3155    OS_REG_RMW_FIELD(ah, AR_PHY_SFCORR_LOW,
3156                     AR_PHY_SFCORR_LOW_M2_THRESH_LOW, m2_thresh_low);
3157    OS_REG_RMW_FIELD(ah, AR_PHY_SFCORR,
3158                     AR_PHY_SFCORR_M1_THRESH, m1_thresh);
3159    OS_REG_RMW_FIELD(ah, AR_PHY_SFCORR,
3160                     AR_PHY_SFCORR_M2_THRESH, m2_thresh);
3161    OS_REG_RMW_FIELD(ah, AR_PHY_SFCORR,
3162                     AR_PHY_SFCORR_M2COUNT_THR, m2_count_thr);
3163    OS_REG_RMW_FIELD(ah, AR_PHY_SFCORR_LOW,
3164                     AR_PHY_SFCORR_LOW_M2COUNT_THR_LOW, m2_count_thr_low);
3165
3166    OS_REG_RMW_FIELD(ah, AR_PHY_SFCORR_EXT,
3167                     AR_PHY_SFCORR_EXT_M1_THRESH_LOW, m1_thresh_low);
3168    OS_REG_RMW_FIELD(ah, AR_PHY_SFCORR_EXT,
3169                     AR_PHY_SFCORR_EXT_M2_THRESH_LOW, m2_thresh_low);
3170    OS_REG_RMW_FIELD(ah, AR_PHY_SFCORR_EXT,
3171                     AR_PHY_SFCORR_EXT_M1_THRESH, m1_thresh);
3172    OS_REG_RMW_FIELD(ah, AR_PHY_SFCORR_EXT,
3173                     AR_PHY_SFCORR_EXT_M2_THRESH, m2_thresh);
3174
3175    if (!enable) {
3176        OS_REG_SET_BIT(ah, AR_PHY_SFCORR_LOW,
3177                       AR_PHY_SFCORR_LOW_USE_SELF_CORR_LOW);
3178    } else {
3179        OS_REG_CLR_BIT(ah, AR_PHY_SFCORR_LOW,
3180                       AR_PHY_SFCORR_LOW_USE_SELF_CORR_LOW);
3181    }
3182}
3183
3184/* XXX FreeBSD: I'm not sure how to implement this.. */
3185#if 0
3186int
3187ar9300_get_cal_intervals(struct ath_hal *ah, HAL_CALIBRATION_TIMER **timerp,
3188    HAL_CAL_QUERY query)
3189{
3190#define AR9300_IS_CHAIN_RX_IQCAL_INVALID(_ah, _reg) \
3191    ((OS_REG_READ((_ah), _reg) & 0x3fff) == 0)
3192#define AR9300_IS_RX_IQCAL_DISABLED(_ah) \
3193    (!(OS_REG_READ((_ah), AR_PHY_RX_IQCAL_CORR_B0) & \
3194    AR_PHY_RX_IQCAL_CORR_IQCORR_ENABLE))
3195/* Avoid comilation warnings. Variables are not used when EMULATION. */
3196    struct ath_hal_9300 *ahp = AH9300(ah);
3197    u_int8_t rxchainmask = ahp->ah_rx_chainmask, i;
3198    int rx_iqcal_invalid = 0, num_chains = 0;
3199    static const u_int32_t offset_array[3] = {
3200        AR_PHY_RX_IQCAL_CORR_B0,
3201        AR_PHY_RX_IQCAL_CORR_B1,
3202        AR_PHY_RX_IQCAL_CORR_B2};
3203
3204    *timerp = ar9300_cals;
3205
3206    switch (query) {
3207    case HAL_QUERY_CALS:
3208        return AR9300_NUM_CAL_TYPES;
3209    case HAL_QUERY_RERUN_CALS:
3210        for (i = 0; i < AR9300_MAX_CHAINS; i++) {
3211            if (rxchainmask & (1 << i)) {
3212                num_chains++;
3213            }
3214        }
3215        for (i = 0; i < num_chains; i++) {
3216            if (AR_SREV_POSEIDON(ah) || AR_SREV_APHRODITE(ah)) {
3217                HALASSERT(num_chains == 0x1);
3218            }
3219            if (AR9300_IS_CHAIN_RX_IQCAL_INVALID(ah, offset_array[i])) {
3220                rx_iqcal_invalid = 1;
3221            }
3222        }
3223        if (AR9300_IS_RX_IQCAL_DISABLED(ah)) {
3224            rx_iqcal_invalid = 1;
3225        }
3226
3227        return rx_iqcal_invalid;
3228    default:
3229        HALASSERT(0);
3230    }
3231    return 0;
3232}
3233#endif
3234
3235#if ATH_TRAFFIC_FAST_RECOVER
3236#define PLL3              0x16188
3237#define PLL3_DO_MEAS_MASK 0x40000000
3238#define PLL4              0x1618c
3239#define PLL4_MEAS_DONE    0x8
3240#define SQSUM_DVC_MASK    0x007ffff8
3241unsigned long
3242ar9300_get_pll3_sqsum_dvc(struct ath_hal *ah)
3243{
3244    if (AR_SREV_HORNET(ah) || AR_SREV_POSEIDON(ah) || AR_SREV_WASP(ah) || AR_SREV_SCORPION(ah)) {
3245        OS_REG_WRITE(ah, PLL3, (OS_REG_READ(ah, PLL3) & ~(PLL3_DO_MEAS_MASK)));
3246        OS_DELAY(100);
3247        OS_REG_WRITE(ah, PLL3, (OS_REG_READ(ah, PLL3) | PLL3_DO_MEAS_MASK));
3248
3249        while ( (OS_REG_READ(ah, PLL4) & PLL4_MEAS_DONE) == 0) {
3250            OS_DELAY(100);
3251        }
3252
3253        return (( OS_REG_READ(ah, PLL3) & SQSUM_DVC_MASK ) >> 3);
3254    } else {
3255        HALDEBUG(ah, HAL_DEBUG_UNMASKABLE,
3256                 "%s: unable to get pll3_sqsum_dvc\n",
3257                 __func__);
3258        return 0;
3259    }
3260}
3261#endif
3262
3263
3264#define RX_GAIN_TABLE_LENGTH	128
3265// this will be called if rfGainCAP is enabled and rfGainCAP setting is changed,
3266// or rxGainTable setting is changed
3267HAL_BOOL ar9300_rf_gain_cap_apply(struct ath_hal *ah, int is_2GHz)
3268{
3269	int i, done = 0, i_rx_gain = 32;
3270    u_int32_t rf_gain_cap;
3271    u_int32_t rx_gain_value, a_Byte, rx_gain_value_caped;
3272	static u_int32_t  rx_gain_table[RX_GAIN_TABLE_LENGTH * 2][2];
3273    ar9300_eeprom_t *eep = &AH9300(ah)->ah_eeprom;
3274    struct ath_hal_9300 *ahp = AH9300(ah);
3275
3276    if ( !((eep->base_eep_header.misc_configuration & 0x80) >> 7) )
3277        return AH_FALSE;
3278
3279    if (is_2GHz)
3280    {
3281        rf_gain_cap = (u_int32_t) eep->modal_header_2g.rf_gain_cap;
3282    }
3283    else
3284    {
3285        rf_gain_cap = (u_int32_t) eep->modal_header_5g.rf_gain_cap;
3286	}
3287
3288	if (rf_gain_cap == 0)
3289        return AH_FALSE;
3290
3291	for (i = 0; i< RX_GAIN_TABLE_LENGTH * 2; i++)
3292	{
3293        if (AR_SREV_AR9580(ah))
3294        {
3295            // BB_rx_ocgain2
3296            i_rx_gain = 128 + 32;
3297            switch (ar9300_rx_gain_index_get(ah))
3298            {
3299            case 0:
3300                rx_gain_table[i][0] =
3301					ar9300_common_rx_gain_table_ar9580_1p0[i][0];
3302                rx_gain_table[i][1] =
3303					ar9300_common_rx_gain_table_ar9580_1p0[i][1];
3304                break;
3305            case 1:
3306                rx_gain_table[i][0] =
3307					ar9300_common_wo_xlna_rx_gain_table_ar9580_1p0[i][0];
3308                rx_gain_table[i][1] =
3309					ar9300_common_wo_xlna_rx_gain_table_ar9580_1p0[i][1];
3310                break;
3311			}
3312        }
3313        else if (AR_SREV_OSPREY_22(ah))
3314        {
3315            i_rx_gain = 128 + 32;
3316            switch (ar9300_rx_gain_index_get(ah))
3317            {
3318            case 0:
3319                rx_gain_table[i][0] = ar9300_common_rx_gain_table_osprey_2p2[i][0];
3320                rx_gain_table[i][1] = ar9300_common_rx_gain_table_osprey_2p2[i][1];
3321                break;
3322            case 1:
3323                rx_gain_table[i][0] =
3324					ar9300Common_wo_xlna_rx_gain_table_osprey_2p2[i][0];
3325                rx_gain_table[i][1] =
3326					ar9300Common_wo_xlna_rx_gain_table_osprey_2p2[i][1];
3327                break;
3328			}
3329        }
3330        else
3331        {
3332            return AH_FALSE;
3333        }
3334    }
3335
3336    while (1)
3337	{
3338        rx_gain_value = rx_gain_table[i_rx_gain][1];
3339        rx_gain_value_caped = rx_gain_value;
3340        a_Byte = rx_gain_value & (0x000000FF);
3341        if (a_Byte>rf_gain_cap)
3342        {
3343        	rx_gain_value_caped = (rx_gain_value_caped &
3344				(0xFFFFFF00)) + rf_gain_cap;
3345        }
3346        a_Byte = rx_gain_value & (0x0000FF00);
3347        if ( a_Byte > ( rf_gain_cap << 8 ) )
3348        {
3349        	rx_gain_value_caped = (rx_gain_value_caped &
3350				(0xFFFF00FF)) + (rf_gain_cap<<8);
3351        }
3352        a_Byte = rx_gain_value & (0x00FF0000);
3353        if ( a_Byte > ( rf_gain_cap << 16 ) )
3354        {
3355        	rx_gain_value_caped = (rx_gain_value_caped &
3356				(0xFF00FFFF)) + (rf_gain_cap<<16);
3357        }
3358        a_Byte = rx_gain_value & (0xFF000000);
3359        if ( a_Byte > ( rf_gain_cap << 24 ) )
3360        {
3361        	rx_gain_value_caped = (rx_gain_value_caped &
3362				(0x00FFFFFF)) + (rf_gain_cap<<24);
3363        }
3364        else
3365        {
3366            done = 1;
3367        }
3368		HALDEBUG(ah, HAL_DEBUG_RESET,
3369			"%s: rx_gain_address: %x, rx_gain_value: %x	rx_gain_value_caped: %x\n",
3370			__func__, rx_gain_table[i_rx_gain][0], rx_gain_value, rx_gain_value_caped);
3371        if (rx_gain_value_caped != rx_gain_value)
3372		{
3373            rx_gain_table[i_rx_gain][1] = rx_gain_value_caped;
3374		}
3375        if (done == 1)
3376            break;
3377        i_rx_gain ++;
3378	}
3379    INIT_INI_ARRAY(&ahp->ah_ini_modes_rxgain, rx_gain_table, ARRAY_LENGTH(rx_gain_table), 2);
3380    return AH_TRUE;
3381}
3382
3383
3384void ar9300_rx_gain_table_apply(struct ath_hal *ah)
3385{
3386    struct ath_hal_9300 *ahp = AH9300(ah);
3387//struct ath_hal_private *ahpriv = AH_PRIVATE(ah);
3388    u_int32_t xlan_gpio_cfg;
3389    u_int8_t  i;
3390
3391    if (AR_SREV_OSPREY(ah) || AR_SREV_AR9580(ah))
3392    {
3393		// this will be called if rxGainTable setting is changed
3394        if (ar9300_rf_gain_cap_apply(ah, 1))
3395            return;
3396	}
3397
3398    switch (ar9300_rx_gain_index_get(ah))
3399    {
3400    case 2:
3401        if (AR_SREV_JUPITER_10(ah)) {
3402            INIT_INI_ARRAY(&ahp->ah_ini_modes_rxgain,
3403                ar9300_common_mixed_rx_gain_table_jupiter_1p0,
3404                ARRAY_LENGTH(ar9300_common_mixed_rx_gain_table_jupiter_1p0), 2);
3405            break;
3406        }
3407        else if (AR_SREV_JUPITER_20(ah)) {
3408            INIT_INI_ARRAY(&ahp->ah_ini_modes_rxgain,
3409                ar9300Common_mixed_rx_gain_table_jupiter_2p0,
3410                ARRAY_LENGTH(ar9300Common_mixed_rx_gain_table_jupiter_2p0), 2);
3411            break;
3412        }
3413    case 0:
3414    default:
3415        if (AR_SREV_HORNET_12(ah)) {
3416            INIT_INI_ARRAY(&ahp->ah_ini_modes_rxgain,
3417                ar9331_common_rx_gain_hornet1_2,
3418                ARRAY_LENGTH(ar9331_common_rx_gain_hornet1_2), 2);
3419        } else if (AR_SREV_HORNET_11(ah)) {
3420            INIT_INI_ARRAY(&ahp->ah_ini_modes_rxgain,
3421                ar9331_common_rx_gain_hornet1_1,
3422                ARRAY_LENGTH(ar9331_common_rx_gain_hornet1_1), 2);
3423        } else if (AR_SREV_POSEIDON_11_OR_LATER(ah)) {
3424            INIT_INI_ARRAY(&ahp->ah_ini_modes_rxgain,
3425                ar9485_common_wo_xlna_rx_gain_poseidon1_1,
3426                ARRAY_LENGTH(ar9485_common_wo_xlna_rx_gain_poseidon1_1), 2);
3427            /* XXX FreeBSD: this needs to be revisited!! */
3428            xlan_gpio_cfg = ah->ah_config.ath_hal_ext_lna_ctl_gpio;
3429            if (xlan_gpio_cfg) {
3430                for (i = 0; i < 32; i++) {
3431                    if (xlan_gpio_cfg & (1 << i)) {
3432                        /*
3433                         * XXX FreeBSD: definitely make sure this
3434                         * results in the correct value being written
3435                         * to the hardware, or weird crap is very likely
3436                         * to occur!
3437                         */
3438                        ath_hal_gpioCfgOutput(ah, i,
3439                            HAL_GPIO_OUTPUT_MUX_PCIE_ATTENTION_LED);
3440                    }
3441                }
3442            }
3443
3444        } else if (AR_SREV_POSEIDON(ah)) {
3445            INIT_INI_ARRAY(&ahp->ah_ini_modes_rxgain,
3446                ar9485Common_wo_xlna_rx_gain_poseidon1_0,
3447                ARRAY_LENGTH(ar9485Common_wo_xlna_rx_gain_poseidon1_0), 2);
3448        } else if (AR_SREV_JUPITER_10(ah)) {
3449            INIT_INI_ARRAY(&ahp->ah_ini_modes_rxgain,
3450                ar9300_common_rx_gain_table_jupiter_1p0,
3451                ARRAY_LENGTH(ar9300_common_rx_gain_table_jupiter_1p0), 2);
3452        } else if (AR_SREV_JUPITER_20(ah)) {
3453            INIT_INI_ARRAY(&ahp->ah_ini_modes_rxgain,
3454                ar9300Common_rx_gain_table_jupiter_2p0,
3455                ARRAY_LENGTH(ar9300Common_rx_gain_table_jupiter_2p0), 2);
3456        } else if (AR_SREV_AR9580(ah)) {
3457            INIT_INI_ARRAY(&ahp->ah_ini_modes_rxgain,
3458                ar9300_common_rx_gain_table_ar9580_1p0,
3459                ARRAY_LENGTH(ar9300_common_rx_gain_table_ar9580_1p0), 2);
3460        } else if (AR_SREV_WASP(ah)) {
3461            INIT_INI_ARRAY(&ahp->ah_ini_modes_rxgain,
3462                ar9340Common_rx_gain_table_wasp_1p0,
3463                ARRAY_LENGTH(ar9340Common_rx_gain_table_wasp_1p0), 2);
3464        } else if (AR_SREV_SCORPION(ah)) {
3465            INIT_INI_ARRAY(&ahp->ah_ini_modes_rxgain,
3466                ar955xCommon_rx_gain_table_scorpion_1p0,
3467                ARRAY_LENGTH(ar955xCommon_rx_gain_table_scorpion_1p0), 2);
3468            INIT_INI_ARRAY(&ahp->ah_ini_modes_rxgain_bounds,
3469                ar955xCommon_rx_gain_bounds_scorpion_1p0,
3470                ARRAY_LENGTH(ar955xCommon_rx_gain_bounds_scorpion_1p0), 5);
3471        } else {
3472            INIT_INI_ARRAY(&ahp->ah_ini_modes_rxgain,
3473                ar9300_common_rx_gain_table_osprey_2p2,
3474                ARRAY_LENGTH(ar9300_common_rx_gain_table_osprey_2p2), 2);
3475        }
3476        break;
3477    case 1:
3478        if (AR_SREV_HORNET_12(ah)) {
3479            INIT_INI_ARRAY(&ahp->ah_ini_modes_rxgain,
3480                ar9331_common_wo_xlna_rx_gain_hornet1_2,
3481                ARRAY_LENGTH(ar9331_common_wo_xlna_rx_gain_hornet1_2), 2);
3482        } else if (AR_SREV_HORNET_11(ah)) {
3483            INIT_INI_ARRAY(&ahp->ah_ini_modes_rxgain,
3484                ar9331_common_wo_xlna_rx_gain_hornet1_1,
3485                ARRAY_LENGTH(ar9331_common_wo_xlna_rx_gain_hornet1_1), 2);
3486        } else if (AR_SREV_POSEIDON_11_OR_LATER(ah)) {
3487            INIT_INI_ARRAY(&ahp->ah_ini_modes_rxgain,
3488                ar9485_common_wo_xlna_rx_gain_poseidon1_1,
3489                ARRAY_LENGTH(ar9485_common_wo_xlna_rx_gain_poseidon1_1), 2);
3490        } else if (AR_SREV_POSEIDON(ah)) {
3491            INIT_INI_ARRAY(&ahp->ah_ini_modes_rxgain,
3492                ar9485Common_wo_xlna_rx_gain_poseidon1_0,
3493                ARRAY_LENGTH(ar9485Common_wo_xlna_rx_gain_poseidon1_0), 2);
3494        } else if (AR_SREV_JUPITER_10(ah)) {
3495            INIT_INI_ARRAY(&ahp->ah_ini_modes_rxgain,
3496                ar9300_common_wo_xlna_rx_gain_table_jupiter_1p0,
3497                ARRAY_LENGTH(ar9300_common_wo_xlna_rx_gain_table_jupiter_1p0),
3498                2);
3499        } else if (AR_SREV_JUPITER_20(ah)) {
3500            INIT_INI_ARRAY(&ahp->ah_ini_modes_rxgain,
3501                ar9300Common_wo_xlna_rx_gain_table_jupiter_2p0,
3502                ARRAY_LENGTH(ar9300Common_wo_xlna_rx_gain_table_jupiter_2p0),
3503                2);
3504        } else if (AR_SREV_APHRODITE(ah)) {
3505            INIT_INI_ARRAY(&ahp->ah_ini_modes_rxgain,
3506                ar956XCommon_wo_xlna_rx_gain_table_aphrodite_1p0,
3507                ARRAY_LENGTH(ar956XCommon_wo_xlna_rx_gain_table_aphrodite_1p0),
3508                2);
3509        } else if (AR_SREV_AR9580(ah)) {
3510            INIT_INI_ARRAY(&ahp->ah_ini_modes_rxgain,
3511                ar9300_common_wo_xlna_rx_gain_table_ar9580_1p0,
3512                ARRAY_LENGTH(ar9300_common_wo_xlna_rx_gain_table_ar9580_1p0), 2);
3513        } else if (AR_SREV_WASP(ah)) {
3514            INIT_INI_ARRAY(&ahp->ah_ini_modes_rxgain,
3515                ar9340Common_wo_xlna_rx_gain_table_wasp_1p0,
3516                ARRAY_LENGTH(ar9340Common_wo_xlna_rx_gain_table_wasp_1p0), 2);
3517        } else if (AR_SREV_SCORPION(ah)) {
3518            INIT_INI_ARRAY(&ahp->ah_ini_modes_rxgain,
3519                ar955xCommon_wo_xlna_rx_gain_table_scorpion_1p0,
3520                ARRAY_LENGTH(ar955xCommon_wo_xlna_rx_gain_table_scorpion_1p0), 2);
3521            INIT_INI_ARRAY(&ahp->ah_ini_modes_rxgain_bounds,
3522                ar955xCommon_wo_xlna_rx_gain_bounds_scorpion_1p0,
3523                ARRAY_LENGTH(ar955xCommon_wo_xlna_rx_gain_bounds_scorpion_1p0), 5);
3524        } else {
3525            INIT_INI_ARRAY(&ahp->ah_ini_modes_rxgain,
3526                ar9300Common_wo_xlna_rx_gain_table_osprey_2p2,
3527                ARRAY_LENGTH(ar9300Common_wo_xlna_rx_gain_table_osprey_2p2), 2);
3528        }
3529        break;
3530    }
3531}
3532
3533void ar9300_tx_gain_table_apply(struct ath_hal *ah)
3534{
3535    struct ath_hal_9300 *ahp = AH9300(ah);
3536
3537    switch (ar9300_tx_gain_index_get(ah))
3538    {
3539    case 0:
3540    default:
3541        if (AR_SREV_HORNET_12(ah)) {
3542            INIT_INI_ARRAY(&ahp->ah_ini_modes_txgain,
3543                ar9331_modes_lowest_ob_db_tx_gain_hornet1_2,
3544                ARRAY_LENGTH(ar9331_modes_lowest_ob_db_tx_gain_hornet1_2), 5);
3545        } else if (AR_SREV_HORNET_11(ah)) {
3546            INIT_INI_ARRAY(&ahp->ah_ini_modes_txgain,
3547                ar9331_modes_lowest_ob_db_tx_gain_hornet1_1,
3548                ARRAY_LENGTH(ar9331_modes_lowest_ob_db_tx_gain_hornet1_1), 5);
3549        } else if (AR_SREV_POSEIDON_11_OR_LATER(ah)) {
3550            INIT_INI_ARRAY(&ahp->ah_ini_modes_txgain,
3551                ar9485_modes_lowest_ob_db_tx_gain_poseidon1_1,
3552                ARRAY_LENGTH(ar9485_modes_lowest_ob_db_tx_gain_poseidon1_1), 5);
3553        } else if (AR_SREV_POSEIDON(ah)) {
3554            INIT_INI_ARRAY(&ahp->ah_ini_modes_txgain,
3555                ar9485Modes_lowest_ob_db_tx_gain_poseidon1_0,
3556                ARRAY_LENGTH(ar9485Modes_lowest_ob_db_tx_gain_poseidon1_0), 5);
3557        } else if (AR_SREV_AR9580(ah)) {
3558            INIT_INI_ARRAY(&ahp->ah_ini_modes_txgain,
3559                ar9300Modes_lowest_ob_db_tx_gain_table_ar9580_1p0,
3560                ARRAY_LENGTH(ar9300Modes_lowest_ob_db_tx_gain_table_ar9580_1p0),
3561                5);
3562        } else if (AR_SREV_WASP(ah)) {
3563            INIT_INI_ARRAY(&ahp->ah_ini_modes_txgain,
3564                ar9340Modes_lowest_ob_db_tx_gain_table_wasp_1p0,
3565                ARRAY_LENGTH(ar9340Modes_lowest_ob_db_tx_gain_table_wasp_1p0),
3566                5);
3567        } else if (AR_SREV_SCORPION(ah)) {
3568            INIT_INI_ARRAY(&ahp->ah_ini_modes_txgain,
3569                ar955xModes_xpa_tx_gain_table_scorpion_1p0,
3570                ARRAY_LENGTH(ar955xModes_xpa_tx_gain_table_scorpion_1p0),
3571                9);
3572        } else if (AR_SREV_JUPITER_10(ah)) {
3573            INIT_INI_ARRAY(&ahp->ah_ini_modes_txgain,
3574                ar9300_modes_low_ob_db_tx_gain_table_jupiter_1p0,
3575                ARRAY_LENGTH(ar9300_modes_low_ob_db_tx_gain_table_jupiter_1p0),
3576                5);
3577        } else if (AR_SREV_JUPITER_20(ah)) {
3578            INIT_INI_ARRAY(&ahp->ah_ini_modes_txgain,
3579                ar9300Modes_low_ob_db_tx_gain_table_jupiter_2p0,
3580                ARRAY_LENGTH(ar9300Modes_low_ob_db_tx_gain_table_jupiter_2p0),
3581                5);
3582        } else if (AR_SREV_APHRODITE(ah)) {
3583            INIT_INI_ARRAY(&ahp->ah_ini_modes_txgain,
3584                ar956XModes_low_ob_db_tx_gain_table_aphrodite_1p0,
3585                ARRAY_LENGTH(ar956XModes_low_ob_db_tx_gain_table_aphrodite_1p0),
3586                5);
3587        } else {
3588            INIT_INI_ARRAY(&ahp->ah_ini_modes_txgain,
3589                ar9300_modes_lowest_ob_db_tx_gain_table_osprey_2p2,
3590                ARRAY_LENGTH(ar9300_modes_lowest_ob_db_tx_gain_table_osprey_2p2),
3591                5);
3592        }
3593        break;
3594    case 1:
3595        if (AR_SREV_HORNET_12(ah)) {
3596            INIT_INI_ARRAY(&ahp->ah_ini_modes_txgain,
3597                ar9331_modes_high_ob_db_tx_gain_hornet1_2,
3598                ARRAY_LENGTH(ar9331_modes_high_ob_db_tx_gain_hornet1_2), 5);
3599        } else if (AR_SREV_HORNET_11(ah)) {
3600            INIT_INI_ARRAY(&ahp->ah_ini_modes_txgain,
3601                ar9331_modes_high_ob_db_tx_gain_hornet1_1,
3602                ARRAY_LENGTH(ar9331_modes_high_ob_db_tx_gain_hornet1_1), 5);
3603        } else if (AR_SREV_POSEIDON_11_OR_LATER(ah)) {
3604            INIT_INI_ARRAY(&ahp->ah_ini_modes_txgain,
3605                ar9485_modes_high_ob_db_tx_gain_poseidon1_1,
3606                ARRAY_LENGTH(ar9485_modes_high_ob_db_tx_gain_poseidon1_1), 5);
3607        } else if (AR_SREV_POSEIDON(ah)) {
3608            INIT_INI_ARRAY(&ahp->ah_ini_modes_txgain,
3609                ar9485Modes_high_ob_db_tx_gain_poseidon1_0,
3610                ARRAY_LENGTH(ar9485Modes_high_ob_db_tx_gain_poseidon1_0), 5);
3611        } else if (AR_SREV_AR9580(ah)) {
3612            INIT_INI_ARRAY(&ahp->ah_ini_modes_txgain,
3613                ar9300Modes_high_ob_db_tx_gain_table_ar9580_1p0,
3614                ARRAY_LENGTH(ar9300Modes_high_ob_db_tx_gain_table_ar9580_1p0),
3615                5);
3616        } else if (AR_SREV_WASP(ah)) {
3617            INIT_INI_ARRAY(&ahp->ah_ini_modes_txgain,
3618                ar9340Modes_high_ob_db_tx_gain_table_wasp_1p0,
3619                ARRAY_LENGTH(ar9340Modes_high_ob_db_tx_gain_table_wasp_1p0), 5);
3620        } else if (AR_SREV_SCORPION(ah)) {
3621            INIT_INI_ARRAY(&ahp->ah_ini_modes_txgain,
3622                ar955xModes_no_xpa_tx_gain_table_scorpion_1p0,
3623                ARRAY_LENGTH(ar955xModes_no_xpa_tx_gain_table_scorpion_1p0), 9);
3624        } else if (AR_SREV_JUPITER_10(ah)) {
3625            INIT_INI_ARRAY(&ahp->ah_ini_modes_txgain,
3626                ar9300_modes_high_ob_db_tx_gain_table_jupiter_1p0,
3627                ARRAY_LENGTH(
3628                ar9300_modes_high_ob_db_tx_gain_table_jupiter_1p0), 5);
3629        } else if (AR_SREV_JUPITER_20(ah)) {
3630            INIT_INI_ARRAY(&ahp->ah_ini_modes_txgain,
3631                ar9300Modes_high_ob_db_tx_gain_table_jupiter_2p0,
3632                ARRAY_LENGTH(
3633                ar9300Modes_high_ob_db_tx_gain_table_jupiter_2p0), 5);
3634        } else if (AR_SREV_APHRODITE(ah)) {
3635            INIT_INI_ARRAY(&ahp->ah_ini_modes_txgain,
3636                ar956XModes_high_ob_db_tx_gain_table_aphrodite_1p0,
3637                ARRAY_LENGTH(
3638                ar956XModes_high_ob_db_tx_gain_table_aphrodite_1p0), 5);
3639        } else {
3640            INIT_INI_ARRAY(&ahp->ah_ini_modes_txgain,
3641                ar9300Modes_high_ob_db_tx_gain_table_osprey_2p2,
3642                ARRAY_LENGTH(ar9300Modes_high_ob_db_tx_gain_table_osprey_2p2),
3643                5);
3644        }
3645        break;
3646    case 2:
3647        if (AR_SREV_HORNET_12(ah)) {
3648            INIT_INI_ARRAY(&ahp->ah_ini_modes_txgain,
3649                ar9331_modes_low_ob_db_tx_gain_hornet1_2,
3650                ARRAY_LENGTH(ar9331_modes_low_ob_db_tx_gain_hornet1_2), 5);
3651        } else if (AR_SREV_HORNET_11(ah)) {
3652            INIT_INI_ARRAY(&ahp->ah_ini_modes_txgain,
3653                ar9331_modes_low_ob_db_tx_gain_hornet1_1,
3654                ARRAY_LENGTH(ar9331_modes_low_ob_db_tx_gain_hornet1_1), 5);
3655        } else if (AR_SREV_POSEIDON_11_OR_LATER(ah)) {
3656            INIT_INI_ARRAY(&ahp->ah_ini_modes_txgain,
3657                ar9485_modes_low_ob_db_tx_gain_poseidon1_1,
3658                ARRAY_LENGTH(ar9485_modes_low_ob_db_tx_gain_poseidon1_1), 5);
3659        } else if (AR_SREV_POSEIDON(ah)) {
3660            INIT_INI_ARRAY(&ahp->ah_ini_modes_txgain,
3661                ar9485Modes_low_ob_db_tx_gain_poseidon1_0,
3662                ARRAY_LENGTH(ar9485Modes_low_ob_db_tx_gain_poseidon1_0), 5);
3663        } else if (AR_SREV_AR9580(ah)) {
3664            INIT_INI_ARRAY(&ahp->ah_ini_modes_txgain,
3665                ar9300Modes_low_ob_db_tx_gain_table_ar9580_1p0,
3666                ARRAY_LENGTH(ar9300Modes_low_ob_db_tx_gain_table_ar9580_1p0),
3667                5);
3668        } else if (AR_SREV_WASP(ah)) {
3669            INIT_INI_ARRAY(&ahp->ah_ini_modes_txgain,
3670                ar9340Modes_low_ob_db_tx_gain_table_wasp_1p0,
3671                ARRAY_LENGTH(ar9340Modes_low_ob_db_tx_gain_table_wasp_1p0), 5);
3672        } else if (AR_SREV_APHRODITE(ah)) {
3673            INIT_INI_ARRAY(&ahp->ah_ini_modes_txgain,
3674                ar956XModes_low_ob_db_tx_gain_table_aphrodite_1p0,
3675                ARRAY_LENGTH(ar956XModes_low_ob_db_tx_gain_table_aphrodite_1p0), 5);
3676        } else {
3677            INIT_INI_ARRAY(&ahp->ah_ini_modes_txgain,
3678                ar9300Modes_low_ob_db_tx_gain_table_osprey_2p2,
3679                ARRAY_LENGTH(ar9300Modes_low_ob_db_tx_gain_table_osprey_2p2),
3680                5);
3681        }
3682        break;
3683    case 3:
3684        if (AR_SREV_HORNET_12(ah)) {
3685            INIT_INI_ARRAY(&ahp->ah_ini_modes_txgain,
3686                ar9331_modes_high_power_tx_gain_hornet1_2,
3687                ARRAY_LENGTH(ar9331_modes_high_power_tx_gain_hornet1_2), 5);
3688        } else if (AR_SREV_HORNET_11(ah)) {
3689            INIT_INI_ARRAY(&ahp->ah_ini_modes_txgain,
3690                ar9331_modes_high_power_tx_gain_hornet1_1,
3691                ARRAY_LENGTH(ar9331_modes_high_power_tx_gain_hornet1_1), 5);
3692        } else if (AR_SREV_POSEIDON_11_OR_LATER(ah)) {
3693            INIT_INI_ARRAY(&ahp->ah_ini_modes_txgain,
3694                ar9485_modes_high_power_tx_gain_poseidon1_1,
3695                ARRAY_LENGTH(ar9485_modes_high_power_tx_gain_poseidon1_1), 5);
3696        } else if (AR_SREV_POSEIDON(ah)) {
3697            INIT_INI_ARRAY(&ahp->ah_ini_modes_txgain,
3698                ar9485Modes_high_power_tx_gain_poseidon1_0,
3699                ARRAY_LENGTH(ar9485Modes_high_power_tx_gain_poseidon1_0), 5);
3700        } else if (AR_SREV_AR9580(ah)) {
3701            INIT_INI_ARRAY(&ahp->ah_ini_modes_txgain,
3702                ar9300Modes_high_power_tx_gain_table_ar9580_1p0,
3703                ARRAY_LENGTH(ar9300Modes_high_power_tx_gain_table_ar9580_1p0),
3704                5);
3705        } else if (AR_SREV_WASP(ah)) {
3706            INIT_INI_ARRAY(&ahp->ah_ini_modes_txgain,
3707                ar9340Modes_high_power_tx_gain_table_wasp_1p0,
3708                ARRAY_LENGTH(ar9340Modes_high_power_tx_gain_table_wasp_1p0),
3709                5);
3710        } else if (AR_SREV_APHRODITE(ah)) {
3711            INIT_INI_ARRAY(&ahp->ah_ini_modes_txgain,
3712                ar956XModes_high_power_tx_gain_table_aphrodite_1p0,
3713                ARRAY_LENGTH(ar956XModes_high_power_tx_gain_table_aphrodite_1p0), 5);
3714        } else {
3715            INIT_INI_ARRAY(&ahp->ah_ini_modes_txgain,
3716                ar9300Modes_high_power_tx_gain_table_osprey_2p2,
3717                ARRAY_LENGTH(ar9300Modes_high_power_tx_gain_table_osprey_2p2),
3718                5);
3719        }
3720        break;
3721    case 4:
3722        if (AR_SREV_WASP(ah)) {
3723            INIT_INI_ARRAY(&ahp->ah_ini_modes_txgain,
3724                ar9340Modes_mixed_ob_db_tx_gain_table_wasp_1p0,
3725                ARRAY_LENGTH(ar9340Modes_mixed_ob_db_tx_gain_table_wasp_1p0),
3726                5);
3727        } else if (AR_SREV_AR9580(ah)) {
3728            INIT_INI_ARRAY(&ahp->ah_ini_modes_txgain,
3729                ar9300_modes_mixed_ob_db_tx_gain_table_ar9580_1p0,
3730                ARRAY_LENGTH(ar9300_modes_mixed_ob_db_tx_gain_table_ar9580_1p0),
3731                5);
3732        } else {
3733            INIT_INI_ARRAY(&ahp->ah_ini_modes_txgain,
3734		ar9300Modes_mixed_ob_db_tx_gain_table_osprey_2p2,
3735                ARRAY_LENGTH(ar9300Modes_mixed_ob_db_tx_gain_table_osprey_2p2),
3736		 5);
3737        }
3738        break;
3739    case 5:
3740        /* HW Green TX */
3741        if (AR_SREV_POSEIDON(ah)) {
3742            if (AR_SREV_POSEIDON_11_OR_LATER(ah)) {
3743                INIT_INI_ARRAY(&ahp->ah_ini_modes_txgain,
3744                    ar9485_modes_green_ob_db_tx_gain_poseidon1_1,
3745                    sizeof(ar9485_modes_green_ob_db_tx_gain_poseidon1_1) /
3746                    sizeof(ar9485_modes_green_ob_db_tx_gain_poseidon1_1[0]), 5);
3747            } else {
3748                INIT_INI_ARRAY(&ahp->ah_ini_modes_txgain,
3749                    ar9485_modes_green_ob_db_tx_gain_poseidon1_0,
3750                    sizeof(ar9485_modes_green_ob_db_tx_gain_poseidon1_0) /
3751                    sizeof(ar9485_modes_green_ob_db_tx_gain_poseidon1_0[0]), 5);
3752            }
3753            ahp->ah_hw_green_tx_enable = 1;
3754        }
3755        else if (AR_SREV_WASP(ah)) {
3756            INIT_INI_ARRAY(&ahp->ah_ini_modes_txgain,
3757            ar9340_modes_ub124_tx_gain_table_wasp_1p0,
3758            sizeof(ar9340_modes_ub124_tx_gain_table_wasp_1p0) /
3759            sizeof(ar9340_modes_ub124_tx_gain_table_wasp_1p0[0]), 5);
3760        }
3761        else if (AR_SREV_AR9580(ah)) {
3762            INIT_INI_ARRAY(&ahp->ah_ini_modes_txgain,
3763                ar9300_modes_type5_tx_gain_table_ar9580_1p0,
3764                ARRAY_LENGTH( ar9300_modes_type5_tx_gain_table_ar9580_1p0),
3765                5);
3766        }
3767        else if (AR_SREV_OSPREY_22(ah)) {
3768            INIT_INI_ARRAY(&ahp->ah_ini_modes_txgain,
3769                ar9300_modes_number_5_tx_gain_table_osprey_2p2,
3770                ARRAY_LENGTH( ar9300_modes_number_5_tx_gain_table_osprey_2p2),
3771                5);
3772        }
3773        break;
3774	case 6:
3775        if (AR_SREV_WASP(ah)) {
3776            INIT_INI_ARRAY(&ahp->ah_ini_modes_txgain,
3777            ar9340_modes_low_ob_db_and_spur_tx_gain_table_wasp_1p0,
3778            sizeof(ar9340_modes_low_ob_db_and_spur_tx_gain_table_wasp_1p0) /
3779            sizeof(ar9340_modes_low_ob_db_and_spur_tx_gain_table_wasp_1p0[0]), 5);
3780        }
3781        /* HW Green TX */
3782        else if (AR_SREV_POSEIDON(ah)) {
3783            if (AR_SREV_POSEIDON_11_OR_LATER(ah)) {
3784                INIT_INI_ARRAY(&ahp->ah_ini_modes_txgain,
3785                ar9485_modes_green_spur_ob_db_tx_gain_poseidon1_1,
3786                sizeof(ar9485_modes_green_spur_ob_db_tx_gain_poseidon1_1) /
3787                sizeof(ar9485_modes_green_spur_ob_db_tx_gain_poseidon1_1[0]),
3788                5);
3789            }
3790            ahp->ah_hw_green_tx_enable = 1;
3791	}
3792        else if (AR_SREV_AR9580(ah)) {
3793            INIT_INI_ARRAY(&ahp->ah_ini_modes_txgain,
3794                ar9300_modes_type6_tx_gain_table_ar9580_1p0,
3795                ARRAY_LENGTH( ar9300_modes_type6_tx_gain_table_ar9580_1p0),
3796                5);
3797        }
3798        break;
3799	case 7:
3800		if (AR_SREV_WASP(ah)) {
3801            INIT_INI_ARRAY(&ahp->ah_ini_modes_txgain,
3802            ar9340Modes_cus227_tx_gain_table_wasp_1p0,
3803            sizeof(ar9340Modes_cus227_tx_gain_table_wasp_1p0) /
3804            sizeof(ar9340Modes_cus227_tx_gain_table_wasp_1p0[0]), 5);
3805		}
3806		break;
3807    }
3808}
3809
3810#if ATH_ANT_DIV_COMB
3811void
3812ar9300_ant_div_comb_get_config(struct ath_hal *ah,
3813    HAL_ANT_COMB_CONFIG *div_comb_conf)
3814{
3815    u_int32_t reg_val = OS_REG_READ(ah, AR_PHY_MC_GAIN_CTRL);
3816    div_comb_conf->main_lna_conf =
3817        MULTICHAIN_GAIN_CTRL__ANT_DIV_MAIN_LNACONF__READ(reg_val);
3818    div_comb_conf->alt_lna_conf =
3819        MULTICHAIN_GAIN_CTRL__ANT_DIV_ALT_LNACONF__READ(reg_val);
3820    div_comb_conf->fast_div_bias =
3821        MULTICHAIN_GAIN_CTRL__ANT_FAST_DIV_BIAS__READ(reg_val);
3822    if (AR_SREV_HORNET_11(ah)) {
3823        div_comb_conf->antdiv_configgroup = HAL_ANTDIV_CONFIG_GROUP_1;
3824    } else if (AR_SREV_POSEIDON_11_OR_LATER(ah)) {
3825        div_comb_conf->antdiv_configgroup = HAL_ANTDIV_CONFIG_GROUP_2;
3826    } else {
3827        div_comb_conf->antdiv_configgroup = DEFAULT_ANTDIV_CONFIG_GROUP;
3828    }
3829}
3830
3831void
3832ar9300_ant_div_comb_set_config(struct ath_hal *ah,
3833    HAL_ANT_COMB_CONFIG *div_comb_conf)
3834{
3835    u_int32_t reg_val;
3836    struct ath_hal_9300 *ahp = AH9300(ah);
3837
3838    /* DO NOTHING when set to fixed antenna for manufacturing purpose */
3839    if (AR_SREV_POSEIDON(ah) && ( ahp->ah_diversity_control == HAL_ANT_FIXED_A
3840         || ahp->ah_diversity_control == HAL_ANT_FIXED_B)) {
3841        return;
3842    }
3843    reg_val = OS_REG_READ(ah, AR_PHY_MC_GAIN_CTRL);
3844    reg_val &= ~(MULTICHAIN_GAIN_CTRL__ANT_DIV_MAIN_LNACONF__MASK    |
3845                MULTICHAIN_GAIN_CTRL__ANT_DIV_ALT_LNACONF__MASK     |
3846                MULTICHAIN_GAIN_CTRL__ANT_FAST_DIV_BIAS__MASK       |
3847                MULTICHAIN_GAIN_CTRL__ANT_DIV_MAIN_GAINTB__MASK     |
3848                MULTICHAIN_GAIN_CTRL__ANT_DIV_ALT_GAINTB__MASK );
3849    reg_val |=
3850        MULTICHAIN_GAIN_CTRL__ANT_DIV_MAIN_GAINTB__WRITE(
3851        div_comb_conf->main_gaintb);
3852    reg_val |=
3853        MULTICHAIN_GAIN_CTRL__ANT_DIV_ALT_GAINTB__WRITE(
3854        div_comb_conf->alt_gaintb);
3855    reg_val |=
3856        MULTICHAIN_GAIN_CTRL__ANT_DIV_MAIN_LNACONF__WRITE(
3857        div_comb_conf->main_lna_conf);
3858    reg_val |=
3859        MULTICHAIN_GAIN_CTRL__ANT_DIV_ALT_LNACONF__WRITE(
3860        div_comb_conf->alt_lna_conf);
3861    reg_val |=
3862        MULTICHAIN_GAIN_CTRL__ANT_FAST_DIV_BIAS__WRITE(
3863        div_comb_conf->fast_div_bias);
3864    OS_REG_WRITE(ah, AR_PHY_MC_GAIN_CTRL, reg_val);
3865
3866}
3867#endif /* ATH_ANT_DIV_COMB */
3868
3869static void
3870ar9300_init_hostif_offsets(struct ath_hal *ah)
3871{
3872    AR_HOSTIF_REG(ah, AR_RC) =
3873        AR9300_HOSTIF_OFFSET(HOST_INTF_RESET_CONTROL);
3874    AR_HOSTIF_REG(ah, AR_WA) =
3875        AR9300_HOSTIF_OFFSET(HOST_INTF_WORK_AROUND);
3876    AR_HOSTIF_REG(ah, AR_PM_STATE) =
3877        AR9300_HOSTIF_OFFSET(HOST_INTF_PM_STATE);
3878    AR_HOSTIF_REG(ah, AR_H_INFOL) =
3879        AR9300_HOSTIF_OFFSET(HOST_INTF_CXPL_DEBUG_INFOL);
3880    AR_HOSTIF_REG(ah, AR_H_INFOH) =
3881        AR9300_HOSTIF_OFFSET(HOST_INTF_CXPL_DEBUG_INFOH);
3882    AR_HOSTIF_REG(ah, AR_PCIE_PM_CTRL) =
3883        AR9300_HOSTIF_OFFSET(HOST_INTF_PM_CTRL);
3884    AR_HOSTIF_REG(ah, AR_HOST_TIMEOUT) =
3885        AR9300_HOSTIF_OFFSET(HOST_INTF_TIMEOUT);
3886    AR_HOSTIF_REG(ah, AR_EEPROM) =
3887        AR9300_HOSTIF_OFFSET(HOST_INTF_EEPROM_CTRL);
3888    AR_HOSTIF_REG(ah, AR_SREV) =
3889        AR9300_HOSTIF_OFFSET(HOST_INTF_SREV);
3890    AR_HOSTIF_REG(ah, AR_INTR_SYNC_CAUSE) =
3891        AR9300_HOSTIF_OFFSET(HOST_INTF_INTR_SYNC_CAUSE);
3892    AR_HOSTIF_REG(ah, AR_INTR_SYNC_CAUSE_CLR) =
3893        AR9300_HOSTIF_OFFSET(HOST_INTF_INTR_SYNC_CAUSE);
3894    AR_HOSTIF_REG(ah, AR_INTR_SYNC_ENABLE) =
3895        AR9300_HOSTIF_OFFSET(HOST_INTF_INTR_SYNC_ENABLE);
3896    AR_HOSTIF_REG(ah, AR_INTR_ASYNC_MASK) =
3897        AR9300_HOSTIF_OFFSET(HOST_INTF_INTR_ASYNC_MASK);
3898    AR_HOSTIF_REG(ah, AR_INTR_SYNC_MASK) =
3899        AR9300_HOSTIF_OFFSET(HOST_INTF_INTR_SYNC_MASK);
3900    AR_HOSTIF_REG(ah, AR_INTR_ASYNC_CAUSE_CLR) =
3901        AR9300_HOSTIF_OFFSET(HOST_INTF_INTR_ASYNC_CAUSE);
3902    AR_HOSTIF_REG(ah, AR_INTR_ASYNC_CAUSE) =
3903        AR9300_HOSTIF_OFFSET(HOST_INTF_INTR_ASYNC_CAUSE);
3904    AR_HOSTIF_REG(ah, AR_INTR_ASYNC_ENABLE) =
3905        AR9300_HOSTIF_OFFSET(HOST_INTF_INTR_ASYNC_ENABLE);
3906    AR_HOSTIF_REG(ah, AR_PCIE_SERDES) =
3907        AR9300_HOSTIF_OFFSET(HOST_INTF_PCIE_PHY_RW);
3908    AR_HOSTIF_REG(ah, AR_PCIE_SERDES2) =
3909        AR9300_HOSTIF_OFFSET(HOST_INTF_PCIE_PHY_LOAD);
3910    AR_HOSTIF_REG(ah, AR_GPIO_OUT) =
3911        AR9300_HOSTIF_OFFSET(HOST_INTF_GPIO_OUT);
3912    AR_HOSTIF_REG(ah, AR_GPIO_IN) =
3913        AR9300_HOSTIF_OFFSET(HOST_INTF_GPIO_IN);
3914    AR_HOSTIF_REG(ah, AR_GPIO_OE_OUT) =
3915        AR9300_HOSTIF_OFFSET(HOST_INTF_GPIO_OE);
3916    AR_HOSTIF_REG(ah, AR_GPIO_OE1_OUT) =
3917        AR9300_HOSTIF_OFFSET(HOST_INTF_GPIO_OE1);
3918    AR_HOSTIF_REG(ah, AR_GPIO_INTR_POL) =
3919        AR9300_HOSTIF_OFFSET(HOST_INTF_GPIO_INTR_POLAR);
3920    AR_HOSTIF_REG(ah, AR_GPIO_INPUT_EN_VAL) =
3921        AR9300_HOSTIF_OFFSET(HOST_INTF_GPIO_INPUT_VALUE);
3922    AR_HOSTIF_REG(ah, AR_GPIO_INPUT_MUX1) =
3923        AR9300_HOSTIF_OFFSET(HOST_INTF_GPIO_INPUT_MUX1);
3924    AR_HOSTIF_REG(ah, AR_GPIO_INPUT_MUX2) =
3925        AR9300_HOSTIF_OFFSET(HOST_INTF_GPIO_INPUT_MUX2);
3926    AR_HOSTIF_REG(ah, AR_GPIO_OUTPUT_MUX1) =
3927        AR9300_HOSTIF_OFFSET(HOST_INTF_GPIO_OUTPUT_MUX1);
3928    AR_HOSTIF_REG(ah, AR_GPIO_OUTPUT_MUX2) =
3929        AR9300_HOSTIF_OFFSET(HOST_INTF_GPIO_OUTPUT_MUX2);
3930    AR_HOSTIF_REG(ah, AR_GPIO_OUTPUT_MUX3) =
3931        AR9300_HOSTIF_OFFSET(HOST_INTF_GPIO_OUTPUT_MUX3);
3932    AR_HOSTIF_REG(ah, AR_INPUT_STATE) =
3933        AR9300_HOSTIF_OFFSET(HOST_INTF_GPIO_INPUT_STATE);
3934    AR_HOSTIF_REG(ah, AR_SPARE) =
3935        AR9300_HOSTIF_OFFSET(HOST_INTF_SPARE);
3936    AR_HOSTIF_REG(ah, AR_PCIE_CORE_RESET_EN) =
3937        AR9300_HOSTIF_OFFSET(HOST_INTF_PCIE_CORE_RST_EN);
3938    AR_HOSTIF_REG(ah, AR_CLKRUN) =
3939        AR9300_HOSTIF_OFFSET(HOST_INTF_CLKRUN);
3940    AR_HOSTIF_REG(ah, AR_EEPROM_STATUS_DATA) =
3941        AR9300_HOSTIF_OFFSET(HOST_INTF_EEPROM_STS);
3942    AR_HOSTIF_REG(ah, AR_OBS) =
3943        AR9300_HOSTIF_OFFSET(HOST_INTF_OBS_CTRL);
3944    AR_HOSTIF_REG(ah, AR_RFSILENT) =
3945        AR9300_HOSTIF_OFFSET(HOST_INTF_RFSILENT);
3946    AR_HOSTIF_REG(ah, AR_GPIO_PDPU) =
3947        AR9300_HOSTIF_OFFSET(HOST_INTF_GPIO_PDPU);
3948    AR_HOSTIF_REG(ah, AR_GPIO_DS) =
3949        AR9300_HOSTIF_OFFSET(HOST_INTF_GPIO_DS);
3950    AR_HOSTIF_REG(ah, AR_MISC) =
3951        AR9300_HOSTIF_OFFSET(HOST_INTF_MISC);
3952    AR_HOSTIF_REG(ah, AR_PCIE_MSI) =
3953        AR9300_HOSTIF_OFFSET(HOST_INTF_PCIE_MSI);
3954#if 0   /* Offsets are not defined in reg_map structure */
3955    AR_HOSTIF_REG(ah, AR_TSF_SNAPSHOT_BT_ACTIVE) =
3956        AR9300_HOSTIF_OFFSET(HOST_INTF_TSF_SNAPSHOT_BT_ACTIVE);
3957    AR_HOSTIF_REG(ah, AR_TSF_SNAPSHOT_BT_PRIORITY) =
3958        AR9300_HOSTIF_OFFSET(HOST_INTF_TSF_SNAPSHOT_BT_PRIORITY);
3959    AR_HOSTIF_REG(ah, AR_TSF_SNAPSHOT_BT_CNTL) =
3960        AR9300_HOSTIF_OFFSET(HOST_INTF_MAC_TSF_SNAPSHOT_BT_CNTL);
3961#endif
3962    AR_HOSTIF_REG(ah, AR_PCIE_PHY_LATENCY_NFTS_ADJ) =
3963        AR9300_HOSTIF_OFFSET(HOST_INTF_PCIE_PHY_LATENCY_NFTS_ADJ);
3964    AR_HOSTIF_REG(ah, AR_TDMA_CCA_CNTL) =
3965        AR9300_HOSTIF_OFFSET(HOST_INTF_MAC_TDMA_CCA_CNTL);
3966    AR_HOSTIF_REG(ah, AR_TXAPSYNC) =
3967        AR9300_HOSTIF_OFFSET(HOST_INTF_MAC_TXAPSYNC);
3968    AR_HOSTIF_REG(ah, AR_TXSYNC_INIT_SYNC_TMR) =
3969        AR9300_HOSTIF_OFFSET(HOST_INTF_MAC_TXSYNC_INITIAL_SYNC_TMR);
3970    AR_HOSTIF_REG(ah, AR_INTR_PRIO_SYNC_CAUSE) =
3971        AR9300_HOSTIF_OFFSET(HOST_INTF_INTR_PRIORITY_SYNC_CAUSE);
3972    AR_HOSTIF_REG(ah, AR_INTR_PRIO_SYNC_ENABLE) =
3973        AR9300_HOSTIF_OFFSET(HOST_INTF_INTR_PRIORITY_SYNC_ENABLE);
3974    AR_HOSTIF_REG(ah, AR_INTR_PRIO_ASYNC_MASK) =
3975        AR9300_HOSTIF_OFFSET(HOST_INTF_INTR_PRIORITY_ASYNC_MASK);
3976    AR_HOSTIF_REG(ah, AR_INTR_PRIO_SYNC_MASK) =
3977        AR9300_HOSTIF_OFFSET(HOST_INTF_INTR_PRIORITY_SYNC_MASK);
3978    AR_HOSTIF_REG(ah, AR_INTR_PRIO_ASYNC_CAUSE) =
3979        AR9300_HOSTIF_OFFSET(HOST_INTF_INTR_PRIORITY_ASYNC_CAUSE);
3980    AR_HOSTIF_REG(ah, AR_INTR_PRIO_ASYNC_ENABLE) =
3981        AR9300_HOSTIF_OFFSET(HOST_INTF_INTR_PRIORITY_ASYNC_ENABLE);
3982}
3983
3984static void
3985ar9340_init_hostif_offsets(struct ath_hal *ah)
3986{
3987    AR_HOSTIF_REG(ah, AR_RC) =
3988        AR9340_HOSTIF_OFFSET(HOST_INTF_RESET_CONTROL);
3989    AR_HOSTIF_REG(ah, AR_WA) =
3990        AR9340_HOSTIF_OFFSET(HOST_INTF_WORK_AROUND);
3991    AR_HOSTIF_REG(ah, AR_PCIE_PM_CTRL) =
3992        AR9340_HOSTIF_OFFSET(HOST_INTF_PM_CTRL);
3993    AR_HOSTIF_REG(ah, AR_HOST_TIMEOUT) =
3994        AR9340_HOSTIF_OFFSET(HOST_INTF_TIMEOUT);
3995    AR_HOSTIF_REG(ah, AR_SREV) =
3996        AR9340_HOSTIF_OFFSET(HOST_INTF_SREV);
3997    AR_HOSTIF_REG(ah, AR_INTR_SYNC_CAUSE) =
3998        AR9340_HOSTIF_OFFSET(HOST_INTF_INTR_SYNC_CAUSE);
3999    AR_HOSTIF_REG(ah, AR_INTR_SYNC_CAUSE_CLR) =
4000        AR9340_HOSTIF_OFFSET(HOST_INTF_INTR_SYNC_CAUSE);
4001    AR_HOSTIF_REG(ah, AR_INTR_SYNC_ENABLE) =
4002        AR9340_HOSTIF_OFFSET(HOST_INTF_INTR_SYNC_ENABLE);
4003    AR_HOSTIF_REG(ah, AR_INTR_ASYNC_MASK) =
4004        AR9340_HOSTIF_OFFSET(HOST_INTF_INTR_ASYNC_MASK);
4005    AR_HOSTIF_REG(ah, AR_INTR_SYNC_MASK) =
4006        AR9340_HOSTIF_OFFSET(HOST_INTF_INTR_SYNC_MASK);
4007    AR_HOSTIF_REG(ah, AR_INTR_ASYNC_CAUSE_CLR) =
4008        AR9340_HOSTIF_OFFSET(HOST_INTF_INTR_ASYNC_CAUSE);
4009    AR_HOSTIF_REG(ah, AR_INTR_ASYNC_CAUSE) =
4010        AR9340_HOSTIF_OFFSET(HOST_INTF_INTR_ASYNC_CAUSE);
4011    AR_HOSTIF_REG(ah, AR_INTR_ASYNC_ENABLE) =
4012        AR9340_HOSTIF_OFFSET(HOST_INTF_INTR_ASYNC_ENABLE);
4013    AR_HOSTIF_REG(ah, AR_GPIO_OUT) =
4014        AR9340_HOSTIF_OFFSET(HOST_INTF_GPIO_OUT);
4015    AR_HOSTIF_REG(ah, AR_GPIO_IN) =
4016        AR9340_HOSTIF_OFFSET(HOST_INTF_GPIO_IN);
4017    AR_HOSTIF_REG(ah, AR_GPIO_OE_OUT) =
4018        AR9340_HOSTIF_OFFSET(HOST_INTF_GPIO_OE);
4019    AR_HOSTIF_REG(ah, AR_GPIO_OE1_OUT) =
4020        AR9340_HOSTIF_OFFSET(HOST_INTF_GPIO_OE1);
4021    AR_HOSTIF_REG(ah, AR_GPIO_INTR_POL) =
4022        AR9340_HOSTIF_OFFSET(HOST_INTF_GPIO_INTR_POLAR);
4023    AR_HOSTIF_REG(ah, AR_GPIO_INPUT_EN_VAL) =
4024        AR9340_HOSTIF_OFFSET(HOST_INTF_GPIO_INPUT_VALUE);
4025    AR_HOSTIF_REG(ah, AR_GPIO_INPUT_MUX1) =
4026        AR9340_HOSTIF_OFFSET(HOST_INTF_GPIO_INPUT_MUX1);
4027    AR_HOSTIF_REG(ah, AR_GPIO_INPUT_MUX2) =
4028        AR9340_HOSTIF_OFFSET(HOST_INTF_GPIO_INPUT_MUX2);
4029    AR_HOSTIF_REG(ah, AR_GPIO_OUTPUT_MUX1) =
4030        AR9340_HOSTIF_OFFSET(HOST_INTF_GPIO_OUTPUT_MUX1);
4031    AR_HOSTIF_REG(ah, AR_GPIO_OUTPUT_MUX2) =
4032        AR9340_HOSTIF_OFFSET(HOST_INTF_GPIO_OUTPUT_MUX2);
4033    AR_HOSTIF_REG(ah, AR_GPIO_OUTPUT_MUX3) =
4034        AR9340_HOSTIF_OFFSET(HOST_INTF_GPIO_OUTPUT_MUX3);
4035    AR_HOSTIF_REG(ah, AR_INPUT_STATE) =
4036        AR9340_HOSTIF_OFFSET(HOST_INTF_GPIO_INPUT_STATE);
4037    AR_HOSTIF_REG(ah, AR_CLKRUN) =
4038        AR9340_HOSTIF_OFFSET(HOST_INTF_CLKRUN);
4039    AR_HOSTIF_REG(ah, AR_EEPROM_STATUS_DATA) =
4040        AR9340_HOSTIF_OFFSET(HOST_INTF_EEPROM_STS);
4041    AR_HOSTIF_REG(ah, AR_OBS) =
4042        AR9340_HOSTIF_OFFSET(HOST_INTF_OBS_CTRL);
4043    AR_HOSTIF_REG(ah, AR_RFSILENT) =
4044        AR9340_HOSTIF_OFFSET(HOST_INTF_RFSILENT);
4045    AR_HOSTIF_REG(ah, AR_MISC) =
4046        AR9340_HOSTIF_OFFSET(HOST_INTF_MISC);
4047    AR_HOSTIF_REG(ah, AR_PCIE_MSI) =
4048        AR9340_HOSTIF_OFFSET(HOST_INTF_PCIE_MSI);
4049    AR_HOSTIF_REG(ah, AR_TDMA_CCA_CNTL) =
4050        AR9340_HOSTIF_OFFSET(HOST_INTF_MAC_TDMA_CCA_CNTL);
4051    AR_HOSTIF_REG(ah, AR_TXAPSYNC) =
4052        AR9340_HOSTIF_OFFSET(HOST_INTF_MAC_TXAPSYNC);
4053    AR_HOSTIF_REG(ah, AR_TXSYNC_INIT_SYNC_TMR) =
4054        AR9340_HOSTIF_OFFSET(HOST_INTF_MAC_TXSYNC_INITIAL_SYNC_TMR);
4055    AR_HOSTIF_REG(ah, AR_INTR_PRIO_SYNC_CAUSE) =
4056        AR9340_HOSTIF_OFFSET(HOST_INTF_INTR_PRIORITY_SYNC_CAUSE);
4057    AR_HOSTIF_REG(ah, AR_INTR_PRIO_SYNC_ENABLE) =
4058        AR9340_HOSTIF_OFFSET(HOST_INTF_INTR_PRIORITY_SYNC_ENABLE);
4059    AR_HOSTIF_REG(ah, AR_INTR_PRIO_ASYNC_MASK) =
4060        AR9340_HOSTIF_OFFSET(HOST_INTF_INTR_PRIORITY_ASYNC_MASK);
4061    AR_HOSTIF_REG(ah, AR_INTR_PRIO_SYNC_MASK) =
4062        AR9340_HOSTIF_OFFSET(HOST_INTF_INTR_PRIORITY_SYNC_MASK);
4063    AR_HOSTIF_REG(ah, AR_INTR_PRIO_ASYNC_CAUSE) =
4064        AR9340_HOSTIF_OFFSET(HOST_INTF_INTR_PRIORITY_ASYNC_CAUSE);
4065    AR_HOSTIF_REG(ah, AR_INTR_PRIO_ASYNC_ENABLE) =
4066        AR9340_HOSTIF_OFFSET(HOST_INTF_INTR_PRIORITY_ASYNC_ENABLE);
4067}
4068
4069/*
4070 * Host interface register offsets are different for Osprey and Wasp
4071 * and hence store the offsets in hal structure
4072 */
4073static int ar9300_init_offsets(struct ath_hal *ah, u_int16_t devid)
4074{
4075    if (devid == AR9300_DEVID_AR9340) {
4076        ar9340_init_hostif_offsets(ah);
4077    } else {
4078        ar9300_init_hostif_offsets(ah);
4079    }
4080    return 0;
4081}
4082
4083
4084static const char*
4085ar9300_probe(uint16_t vendorid, uint16_t devid)
4086{
4087    if (vendorid != ATHEROS_VENDOR_ID)
4088        return AH_NULL;
4089
4090    switch (devid) {
4091    case AR9300_DEVID_AR9380_PCIE: /* PCIE (Osprey) */
4092        return "Atheros AR938x";
4093    case AR9300_DEVID_AR9340: /* Wasp */
4094        return "Atheros AR934x";
4095    case AR9300_DEVID_AR9485_PCIE: /* Poseidon */
4096        return "Atheros AR9485";
4097    case AR9300_DEVID_AR9580_PCIE: /* Peacock */
4098        return "Atheros AR9580";
4099    case AR9300_DEVID_AR946X_PCIE: /* AR9462, AR9463, AR9482 */
4100        return "Atheros AR946x/AR948x";
4101    case AR9300_DEVID_AR9330: /* Hornet */
4102        return "Atheros AR933x";
4103    case AR9300_DEVID_QCA955X: /* Scorpion */
4104        return "Qualcomm Atheros QCA955x";
4105    case AR9300_DEVID_QCA9565: /* Aphrodite */
4106         return "Qualcomm Atheros AR9565";
4107    default:
4108        return AH_NULL;
4109    }
4110
4111    return AH_NULL;
4112}
4113
4114AH_CHIP(AR9300, ar9300_probe, ar9300_attach);
4115
4116