Main Page | Data Structures | Directories | File List | Data Fields | Globals

ar5211.c

Go to the documentation of this file.
00001 /*      $OpenBSD: ar5211.c,v 1.19 2005/07/30 17:13:17 reyk Exp $        */
00002 
00003 /*
00004  * Copyright (c) 2004, 2005 Reyk Floeter <reyk@vantronix.net>
00005  *
00006  * Permission to use, copy, modify, and distribute this software for any
00007  * purpose with or without fee is hereby granted, provided that the above
00008  * copyright notice and this permission notice appear in all copies.
00009  *
00010  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
00011  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
00012  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
00013  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
00014  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
00015  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
00016  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
00017  */
00018 
00019 /*
00020  * HAL interface for the Atheros AR5001 Wireless LAN chipset
00021  * (AR5211 + AR5111).
00022  */
00023 
00024 #include <dev/ic/ar5xxx.h>
00025 #include <dev/ic/ar5211reg.h>
00026 #include <dev/ic/ar5211var.h>
00027 
00028 HAL_BOOL         ar5k_ar5211_nic_reset(struct ath_hal *, u_int32_t);
00029 HAL_BOOL         ar5k_ar5211_nic_wakeup(struct ath_hal *, u_int16_t);
00030 u_int16_t        ar5k_ar5211_radio_revision(struct ath_hal *, HAL_CHIP);
00031 const void       ar5k_ar5211_fill(struct ath_hal *);
00032 void             ar5k_ar5211_rfregs(struct ath_hal *, HAL_CHANNEL *, u_int,
00033     u_int);
00034 
00035 /*
00036  * Initial register setting for the AR5211
00037  */
00038 static const struct ar5k_ini ar5211_ini[] =
00039     AR5K_AR5211_INI;
00040 static const struct ar5k_ar5211_ini_mode ar5211_mode[] =
00041     AR5K_AR5211_INI_MODE;
00042 static const struct ar5k_ar5211_ini_rf ar5211_rf[] =
00043     AR5K_AR5211_INI_RF;
00044 
00045 AR5K_HAL_FUNCTIONS(extern, ar5k_ar5211,);
00046 
00047 const void
00048 ar5k_ar5211_fill(hal)
00049         struct ath_hal *hal;
00050 {
00051         hal->ah_magic = AR5K_AR5211_MAGIC;
00052 
00053         /*
00054          * Init/Exit functions
00055          */
00056         AR5K_HAL_FUNCTION(hal, ar5211, get_rate_table);
00057         AR5K_HAL_FUNCTION(hal, ar5211, detach);
00058 
00059         /*
00060          * Reset functions
00061          */
00062         AR5K_HAL_FUNCTION(hal, ar5211, reset);
00063         AR5K_HAL_FUNCTION(hal, ar5211, set_opmode);
00064         AR5K_HAL_FUNCTION(hal, ar5211, calibrate);
00065 
00066         /*
00067          * TX functions
00068          */
00069         AR5K_HAL_FUNCTION(hal, ar5211, update_tx_triglevel);
00070         AR5K_HAL_FUNCTION(hal, ar5211, setup_tx_queue);
00071         AR5K_HAL_FUNCTION(hal, ar5211, setup_tx_queueprops);
00072         AR5K_HAL_FUNCTION(hal, ar5211, release_tx_queue);
00073         AR5K_HAL_FUNCTION(hal, ar5211, reset_tx_queue);
00074         AR5K_HAL_FUNCTION(hal, ar5211, get_tx_buf);
00075         AR5K_HAL_FUNCTION(hal, ar5211, put_tx_buf);
00076         AR5K_HAL_FUNCTION(hal, ar5211, tx_start);
00077         AR5K_HAL_FUNCTION(hal, ar5211, stop_tx_dma);
00078         AR5K_HAL_FUNCTION(hal, ar5211, setup_tx_desc);
00079         AR5K_HAL_FUNCTION(hal, ar5211, setup_xtx_desc);
00080         AR5K_HAL_FUNCTION(hal, ar5211, fill_tx_desc);
00081         AR5K_HAL_FUNCTION(hal, ar5211, proc_tx_desc);
00082         AR5K_HAL_FUNCTION(hal, ar5211, has_veol);
00083 
00084         /*
00085          * RX functions
00086          */
00087         AR5K_HAL_FUNCTION(hal, ar5211, get_rx_buf);
00088         AR5K_HAL_FUNCTION(hal, ar5211, put_rx_buf);
00089         AR5K_HAL_FUNCTION(hal, ar5211, start_rx);
00090         AR5K_HAL_FUNCTION(hal, ar5211, stop_rx_dma);
00091         AR5K_HAL_FUNCTION(hal, ar5211, start_rx_pcu);
00092         AR5K_HAL_FUNCTION(hal, ar5211, stop_pcu_recv);
00093         AR5K_HAL_FUNCTION(hal, ar5211, set_mcast_filter);
00094         AR5K_HAL_FUNCTION(hal, ar5211, set_mcast_filterindex);
00095         AR5K_HAL_FUNCTION(hal, ar5211, clear_mcast_filter_idx);
00096         AR5K_HAL_FUNCTION(hal, ar5211, get_rx_filter);
00097         AR5K_HAL_FUNCTION(hal, ar5211, set_rx_filter);
00098         AR5K_HAL_FUNCTION(hal, ar5211, setup_rx_desc);
00099         AR5K_HAL_FUNCTION(hal, ar5211, proc_rx_desc);
00100         AR5K_HAL_FUNCTION(hal, ar5211, set_rx_signal);
00101 
00102         /*
00103          * Misc functions
00104          */
00105         AR5K_HAL_FUNCTION(hal, ar5211, dump_state);
00106         AR5K_HAL_FUNCTION(hal, ar5211, get_diag_state);
00107         AR5K_HAL_FUNCTION(hal, ar5211, get_lladdr);
00108         AR5K_HAL_FUNCTION(hal, ar5211, set_lladdr);
00109         AR5K_HAL_FUNCTION(hal, ar5211, set_regdomain);
00110         AR5K_HAL_FUNCTION(hal, ar5211, set_ledstate);
00111         AR5K_HAL_FUNCTION(hal, ar5211, set_associd);
00112         AR5K_HAL_FUNCTION(hal, ar5211, set_gpio_input);
00113         AR5K_HAL_FUNCTION(hal, ar5211, set_gpio_output);
00114         AR5K_HAL_FUNCTION(hal, ar5211, get_gpio);
00115         AR5K_HAL_FUNCTION(hal, ar5211, set_gpio);
00116         AR5K_HAL_FUNCTION(hal, ar5211, set_gpio_intr);
00117         AR5K_HAL_FUNCTION(hal, ar5211, get_tsf32);
00118         AR5K_HAL_FUNCTION(hal, ar5211, get_tsf64);
00119         AR5K_HAL_FUNCTION(hal, ar5211, reset_tsf);
00120         AR5K_HAL_FUNCTION(hal, ar5211, get_regdomain);
00121         AR5K_HAL_FUNCTION(hal, ar5211, detect_card_present);
00122         AR5K_HAL_FUNCTION(hal, ar5211, update_mib_counters);
00123         AR5K_HAL_FUNCTION(hal, ar5211, get_rf_gain);
00124         AR5K_HAL_FUNCTION(hal, ar5211, set_slot_time);
00125         AR5K_HAL_FUNCTION(hal, ar5211, get_slot_time);
00126         AR5K_HAL_FUNCTION(hal, ar5211, set_ack_timeout);
00127         AR5K_HAL_FUNCTION(hal, ar5211, get_ack_timeout);
00128         AR5K_HAL_FUNCTION(hal, ar5211, set_cts_timeout);
00129         AR5K_HAL_FUNCTION(hal, ar5211, get_cts_timeout);
00130 
00131         /*
00132          * Key table (WEP) functions
00133          */
00134         AR5K_HAL_FUNCTION(hal, ar5211, is_cipher_supported);
00135         AR5K_HAL_FUNCTION(hal, ar5211, get_keycache_size);
00136         AR5K_HAL_FUNCTION(hal, ar5211, reset_key);
00137         AR5K_HAL_FUNCTION(hal, ar5211, is_key_valid);
00138         AR5K_HAL_FUNCTION(hal, ar5211, set_key);
00139         AR5K_HAL_FUNCTION(hal, ar5211, set_key_lladdr);
00140 
00141         /*
00142          * Power management functions
00143          */
00144         AR5K_HAL_FUNCTION(hal, ar5211, set_power);
00145         AR5K_HAL_FUNCTION(hal, ar5211, get_power_mode);
00146         AR5K_HAL_FUNCTION(hal, ar5211, query_pspoll_support);
00147         AR5K_HAL_FUNCTION(hal, ar5211, init_pspoll);
00148         AR5K_HAL_FUNCTION(hal, ar5211, enable_pspoll);
00149         AR5K_HAL_FUNCTION(hal, ar5211, disable_pspoll);
00150 
00151         /*
00152          * Beacon functions
00153          */
00154         AR5K_HAL_FUNCTION(hal, ar5211, init_beacon);
00155         AR5K_HAL_FUNCTION(hal, ar5211, set_beacon_timers);
00156         AR5K_HAL_FUNCTION(hal, ar5211, reset_beacon);
00157         AR5K_HAL_FUNCTION(hal, ar5211, wait_for_beacon);
00158 
00159         /*
00160          * Interrupt functions
00161          */
00162         AR5K_HAL_FUNCTION(hal, ar5211, is_intr_pending);
00163         AR5K_HAL_FUNCTION(hal, ar5211, get_isr);
00164         AR5K_HAL_FUNCTION(hal, ar5211, get_intr);
00165         AR5K_HAL_FUNCTION(hal, ar5211, set_intr);
00166 
00167         /*
00168          * Chipset functions (ar5k-specific, non-HAL)
00169          */
00170         AR5K_HAL_FUNCTION(hal, ar5211, get_capabilities);
00171         AR5K_HAL_FUNCTION(hal, ar5211, radar_alert);
00172 
00173         /*
00174          * EEPROM access
00175          */
00176         AR5K_HAL_FUNCTION(hal, ar5211, eeprom_is_busy);
00177         AR5K_HAL_FUNCTION(hal, ar5211, eeprom_read);
00178         AR5K_HAL_FUNCTION(hal, ar5211, eeprom_write);
00179 }
00180 
00181 struct ath_hal *
00182 ar5k_ar5211_attach(device, sc, st, sh, status)
00183         u_int16_t device;
00184         void *sc;
00185         bus_space_tag_t st;
00186         bus_space_handle_t sh;
00187         int *status;
00188 {
00189         struct ath_hal *hal = (struct ath_hal*) sc;
00190         u_int8_t mac[IEEE80211_ADDR_LEN];
00191         u_int32_t srev;
00192 
00193         ar5k_ar5211_fill(hal);
00194 
00195         /* Bring device out of sleep and reset it's units */
00196         if (ar5k_ar5211_nic_wakeup(hal, AR5K_INIT_MODE) != AH_TRUE)
00197                 return (NULL);
00198 
00199         /* Get MAC, PHY and RADIO revisions */
00200         srev = AR5K_REG_READ(AR5K_AR5211_SREV);
00201         hal->ah_mac_version = AR5K_REG_MS(srev, AR5K_AR5211_SREV_VER);
00202         hal->ah_mac_revision = AR5K_REG_MS(srev, AR5K_AR5211_SREV_REV);
00203         hal->ah_phy_revision = AR5K_REG_READ(AR5K_AR5211_PHY_CHIP_ID) &
00204             0x00ffffffff;
00205 
00206         hal->ah_radio_5ghz_revision =
00207             ar5k_ar5211_radio_revision(hal, HAL_CHIP_5GHZ);
00208 
00209         /* Get the 2GHz radio revision if it's supported */
00210         if (hal->ah_mac_version >= AR5K_SREV_VER_AR5211)
00211                 hal->ah_radio_2ghz_revision =
00212                     ar5k_ar5211_radio_revision(hal, HAL_CHIP_2GHZ);
00213 
00214         /* Identify the chipset (this has to be done in an early step) */
00215         hal->ah_version = AR5K_AR5211;
00216         hal->ah_radio = AR5K_AR5111;
00217         hal->ah_phy = AR5K_AR5211_PHY(0);
00218 
00219         bcopy(etherbroadcastaddr, mac, IEEE80211_ADDR_LEN);
00220         ar5k_ar5211_set_associd(hal, mac, 0, 0);
00221         ar5k_ar5211_get_lladdr(hal, mac);
00222         ar5k_ar5211_set_opmode(hal);
00223 
00224         return (hal);
00225 }
00226 
00227 HAL_BOOL
00228 ar5k_ar5211_nic_reset(hal, val)
00229         struct ath_hal *hal;
00230         u_int32_t val;
00231 {
00232         HAL_BOOL ret = AH_FALSE;
00233         u_int32_t mask = val ? val : ~0;
00234 
00235         /* Read-and-clear */
00236         AR5K_REG_READ(AR5K_AR5211_RXDP);
00237 
00238         /*
00239          * Reset the device and wait until success
00240          */
00241         AR5K_REG_WRITE(AR5K_AR5211_RC, val);
00242 
00243         /* Wait at least 128 PCI clocks */
00244         AR5K_DELAY(15);
00245 
00246         val &=
00247             AR5K_AR5211_RC_PCU | AR5K_AR5211_RC_BB;
00248 
00249         mask &=
00250             AR5K_AR5211_RC_PCU | AR5K_AR5211_RC_BB;
00251 
00252         ret = ar5k_register_timeout(hal, AR5K_AR5211_RC, mask, val, AH_FALSE);
00253 
00254         /*
00255          * Reset configuration register
00256          */
00257         if ((val & AR5K_AR5211_RC_PCU) == 0)
00258                 AR5K_REG_WRITE(AR5K_AR5211_CFG, AR5K_AR5211_INIT_CFG);
00259 
00260         return (ret);
00261 }
00262 
00263 HAL_BOOL
00264 ar5k_ar5211_nic_wakeup(hal, flags)
00265         struct ath_hal *hal;
00266         u_int16_t flags;
00267 {
00268         u_int32_t turbo, mode, clock;
00269 
00270         turbo = 0;
00271         mode = 0;
00272         clock = 0;
00273 
00274         /*
00275          * Get channel mode flags
00276          */
00277 
00278         if (flags & IEEE80211_CHAN_2GHZ) {
00279                 mode |= AR5K_AR5211_PHY_MODE_FREQ_2GHZ;
00280                 clock |= AR5K_AR5211_PHY_PLL_44MHZ;
00281         } else if (flags & IEEE80211_CHAN_5GHZ) {
00282                 mode |= AR5K_AR5211_PHY_MODE_FREQ_5GHZ;
00283                 clock |= AR5K_AR5211_PHY_PLL_40MHZ;
00284         } else {
00285                 AR5K_PRINT("invalid radio frequency mode\n");
00286                 return (AH_FALSE);
00287         }
00288 
00289         if ((flags & IEEE80211_CHAN_CCK) ||
00290             (flags & IEEE80211_CHAN_DYN)) {
00291                 /* Dynamic OFDM/CCK is not supported by the AR5211 */
00292                 mode |= AR5K_AR5211_PHY_MODE_MOD_CCK;
00293         } else if (flags & IEEE80211_CHAN_OFDM) {
00294                 mode |= AR5K_AR5211_PHY_MODE_MOD_OFDM;
00295         } else {
00296                 AR5K_PRINT("invalid radio frequency mode\n");
00297                 return (AH_FALSE);
00298         }
00299 
00300         if (flags & IEEE80211_CHAN_TURBO) {
00301                 turbo = AR5K_AR5211_PHY_TURBO_MODE |
00302                     AR5K_AR5211_PHY_TURBO_SHORT;
00303         }
00304 
00305         /*
00306          * Reset and wakeup the device
00307          */
00308 
00309         /* ...reset chipset and PCI device */
00310         if (ar5k_ar5211_nic_reset(hal,
00311                 AR5K_AR5211_RC_CHIP | AR5K_AR5211_RC_PCI) == AH_FALSE) {
00312                 AR5K_PRINT("failed to reset the AR5211 + PCI chipset\n");
00313                 return (AH_FALSE);
00314         }
00315 
00316         /* ...wakeup */
00317         if (ar5k_ar5211_set_power(hal,
00318                 HAL_PM_AWAKE, AH_TRUE, 0) == AH_FALSE) {
00319                 AR5K_PRINT("failed to resume the AR5211 (again)\n");
00320                 return (AH_FALSE);
00321         }
00322 
00323         /* ...final warm reset */
00324         if (ar5k_ar5211_nic_reset(hal, 0) == AH_FALSE) {
00325                 AR5K_PRINT("failed to warm reset the AR5211\n");
00326                 return (AH_FALSE);
00327         }
00328 
00329         /* ...set the PHY operating mode */
00330         AR5K_REG_WRITE(AR5K_AR5211_PHY_PLL, clock);
00331         AR5K_DELAY(300);
00332 
00333         AR5K_REG_WRITE(AR5K_AR5211_PHY_MODE, mode);
00334         AR5K_REG_WRITE(AR5K_AR5211_PHY_TURBO, turbo);
00335 
00336         return (AH_TRUE);
00337 }
00338 
00339 u_int16_t
00340 ar5k_ar5211_radio_revision(hal, chip)
00341         struct ath_hal *hal;
00342         HAL_CHIP chip;
00343 {
00344         int i;
00345         u_int32_t srev;
00346         u_int16_t ret;
00347 
00348         /*
00349          * Set the radio chip access register
00350          */
00351         switch (chip) {
00352         case HAL_CHIP_2GHZ:
00353                 AR5K_REG_WRITE(AR5K_AR5211_PHY(0), AR5K_AR5211_PHY_SHIFT_2GHZ);
00354                 break;
00355         case HAL_CHIP_5GHZ:
00356                 AR5K_REG_WRITE(AR5K_AR5211_PHY(0), AR5K_AR5211_PHY_SHIFT_5GHZ);
00357                 break;
00358         default:
00359                 return (0);
00360         }
00361 
00362         AR5K_DELAY(2000);
00363 
00364         /* ...wait until PHY is ready and read the selected radio revision */
00365         AR5K_REG_WRITE(AR5K_AR5211_PHY(0x34), 0x00001c16);
00366 
00367         for (i = 0; i < 8; i++)
00368                 AR5K_REG_WRITE(AR5K_AR5211_PHY(0x20), 0x00010000);
00369         srev = (AR5K_REG_READ(AR5K_AR5211_PHY(0x100)) >> 24) & 0xff;
00370 
00371         ret = ar5k_bitswap(((srev & 0xf0) >> 4) | ((srev & 0x0f) << 4), 8);
00372 
00373         /* Reset to the 5GHz mode */
00374         AR5K_REG_WRITE(AR5K_AR5211_PHY(0), AR5K_AR5211_PHY_SHIFT_5GHZ);
00375 
00376         return (ret);
00377 }
00378 
00379 const HAL_RATE_TABLE *
00380 ar5k_ar5211_get_rate_table(hal, mode)
00381         struct ath_hal *hal;
00382         u_int mode;
00383 {
00384         switch (mode) {
00385         case HAL_MODE_11A:
00386                 return (&hal->ah_rt_11a);
00387         case HAL_MODE_TURBO:
00388                 return (&hal->ah_rt_turbo);
00389         case HAL_MODE_11B:
00390                 return (&hal->ah_rt_11b);
00391         case HAL_MODE_11G:
00392         case HAL_MODE_PUREG:
00393                 return (&hal->ah_rt_11g);
00394         default:
00395                 return (NULL);
00396         }
00397 
00398         return (NULL);
00399 }
00400 
00401 void
00402 ar5k_ar5211_detach(hal)
00403         struct ath_hal *hal;
00404 {
00405         /*
00406          * Free HAL structure, assume interrupts are down
00407          */
00408         free(hal, M_DEVBUF);
00409 }
00410 
00411 HAL_BOOL
00412 ar5k_ar5211_reset(hal, op_mode, channel, change_channel, status)
00413         struct ath_hal *hal;
00414         HAL_OPMODE op_mode;
00415         HAL_CHANNEL *channel;
00416         HAL_BOOL change_channel;
00417         HAL_STATUS *status;
00418 {
00419         struct ar5k_eeprom_info *ee = &hal->ah_capabilities.cap_eeprom;
00420         u_int8_t mac[IEEE80211_ADDR_LEN];
00421         u_int32_t data, s_seq, s_ant, s_led[3];
00422         u_int i, mode, freq, ee_mode, ant[2];
00423 
00424         /*
00425          * Save some registers before a reset
00426          */
00427         if (change_channel == AH_TRUE) {
00428                 s_seq = AR5K_REG_READ(AR5K_AR5211_DCU_SEQNUM(0));
00429                 s_ant = AR5K_REG_READ(AR5K_AR5211_DEFAULT_ANTENNA);
00430         } else {
00431                 s_seq = 0;
00432                 s_ant = 1;
00433         }
00434 
00435         s_led[0] = AR5K_REG_READ(AR5K_AR5211_PCICFG) &
00436             AR5K_AR5211_PCICFG_LEDSTATE;
00437         s_led[1] = AR5K_REG_READ(AR5K_AR5211_GPIOCR);
00438         s_led[2] = AR5K_REG_READ(AR5K_AR5211_GPIODO);
00439 
00440         if (ar5k_ar5211_nic_wakeup(hal, channel->c_channel_flags) == AH_FALSE)
00441                 return (AH_FALSE);
00442 
00443         /*
00444          * Initialize operating mode
00445          */
00446         hal->ah_op_mode = op_mode;
00447 
00448         if (channel->c_channel_flags & IEEE80211_CHAN_A) {
00449                 mode = AR5K_INI_VAL_11A;
00450                 freq = AR5K_INI_RFGAIN_5GHZ;
00451                 ee_mode = AR5K_EEPROM_MODE_11A;
00452         } else if (channel->c_channel_flags & IEEE80211_CHAN_T) {
00453                 mode = AR5K_INI_VAL_11A_TURBO;
00454                 freq = AR5K_INI_RFGAIN_5GHZ;
00455                 ee_mode = AR5K_EEPROM_MODE_11A;
00456         } else if (channel->c_channel_flags & IEEE80211_CHAN_B) {
00457                 mode = AR5K_INI_VAL_11B;
00458                 freq = AR5K_INI_RFGAIN_2GHZ;
00459                 ee_mode = AR5K_EEPROM_MODE_11B;
00460         } else if (channel->c_channel_flags & IEEE80211_CHAN_G) {
00461                 mode = AR5K_INI_VAL_11G;
00462                 freq = AR5K_INI_RFGAIN_2GHZ;
00463                 ee_mode = AR5K_EEPROM_MODE_11G;
00464         } else {
00465                 AR5K_PRINTF("invalid channel: %d\n", channel->c_channel);
00466                 return (AH_FALSE);
00467         }
00468 
00469         /* PHY access enable */
00470         AR5K_REG_WRITE(AR5K_AR5211_PHY(0), AR5K_AR5211_PHY_SHIFT_5GHZ);
00471 
00472         /*
00473          * Write initial RF registers
00474          */
00475         ar5k_ar5211_rfregs(hal, channel, freq, ee_mode);
00476 
00477         /*
00478          * Write initial mode settings
00479          */
00480         for (i = 0; i < AR5K_ELEMENTS(ar5211_mode); i++) {
00481                 AR5K_REG_WAIT(i);
00482                 AR5K_REG_WRITE((u_int32_t)ar5211_mode[i].mode_register,
00483                     ar5211_mode[i].mode_value[mode]);
00484         }
00485 
00486         /*
00487          * Write initial register settings
00488          */
00489         for (i = 0; i < AR5K_ELEMENTS(ar5211_ini); i++) {
00490                 if (change_channel == AH_TRUE &&
00491                     ar5211_ini[i].ini_register >= AR5K_AR5211_PCU_MIN &&
00492                     ar5211_ini[i].ini_register <= AR5K_AR5211_PCU_MAX)
00493                         continue;
00494 
00495                 AR5K_REG_WAIT(i);
00496                 AR5K_REG_WRITE((u_int32_t)ar5211_ini[i].ini_register,
00497                     ar5211_ini[i].ini_value);
00498         }
00499 
00500         /*
00501          * Write initial RF gain settings
00502          */
00503         if (ar5k_rfgain(hal, AR5K_INI_PHY_5111, freq) == AH_FALSE)
00504                 return (AH_FALSE);
00505 
00506         AR5K_DELAY(1000);
00507 
00508         /*
00509          * Configure additional registers
00510          */
00511 
00512         if (hal->ah_radio == AR5K_AR5111) {
00513                 if (channel->c_channel_flags & IEEE80211_CHAN_B)
00514                         AR5K_REG_ENABLE_BITS(AR5K_AR5211_TXCFG,
00515                             AR5K_AR5211_TXCFG_B_MODE);
00516                 else
00517                         AR5K_REG_DISABLE_BITS(AR5K_AR5211_TXCFG,
00518                             AR5K_AR5211_TXCFG_B_MODE);
00519         }
00520 
00521         /* Set antenna mode */
00522         AR5K_REG_MASKED_BITS(AR5K_AR5211_PHY(0x44),
00523             hal->ah_antenna[ee_mode][0], 0xfffffc06);
00524 
00525         ant[0] = HAL_ANT_FIXED_A;
00526         ant[1] = HAL_ANT_FIXED_B;
00527 
00528         if (hal->ah_ant_diversity == AH_FALSE) {
00529                 if (freq == AR5K_INI_RFGAIN_2GHZ)
00530                         ant[0] = HAL_ANT_FIXED_B;
00531                 else if (freq == AR5K_INI_RFGAIN_5GHZ)
00532                         ant[1] = HAL_ANT_FIXED_A;
00533         }
00534 
00535         AR5K_REG_WRITE(AR5K_AR5211_PHY_ANT_SWITCH_TABLE_0,
00536             hal->ah_antenna[ee_mode][ant[0]]);
00537         AR5K_REG_WRITE(AR5K_AR5211_PHY_ANT_SWITCH_TABLE_1,
00538             hal->ah_antenna[ee_mode][ant[1]]);
00539 
00540         /* Commit values from EEPROM */
00541         AR5K_REG_WRITE_BITS(AR5K_AR5211_PHY_FC,
00542             AR5K_AR5211_PHY_FC_TX_CLIP, ee->ee_tx_clip);
00543 
00544         AR5K_REG_WRITE(AR5K_AR5211_PHY(0x5a),
00545             AR5K_AR5211_PHY_NF_SVAL(ee->ee_noise_floor_thr[ee_mode]));
00546 
00547         AR5K_REG_MASKED_BITS(AR5K_AR5211_PHY(0x11),
00548             (ee->ee_switch_settling[ee_mode] << 7) & 0x3f80, 0xffffc07f);
00549         AR5K_REG_MASKED_BITS(AR5K_AR5211_PHY(0x12),
00550             (ee->ee_ant_tx_rx[ee_mode] << 12) & 0x3f000, 0xfffc0fff);
00551         AR5K_REG_MASKED_BITS(AR5K_AR5211_PHY(0x14),
00552             (ee->ee_adc_desired_size[ee_mode] & 0x00ff) |
00553             ((ee->ee_pga_desired_size[ee_mode] << 8) & 0xff00), 0xffff0000);
00554 
00555         AR5K_REG_WRITE(AR5K_AR5211_PHY(0x0d),
00556             (ee->ee_tx_end2xpa_disable[ee_mode] << 24) |
00557             (ee->ee_tx_end2xpa_disable[ee_mode] << 16) |
00558             (ee->ee_tx_frm2xpa_enable[ee_mode] << 8) |
00559             (ee->ee_tx_frm2xpa_enable[ee_mode]));
00560 
00561         AR5K_REG_MASKED_BITS(AR5K_AR5211_PHY(0x0a),
00562             ee->ee_tx_end2xlna_enable[ee_mode] << 8, 0xffff00ff);
00563         AR5K_REG_MASKED_BITS(AR5K_AR5211_PHY(0x19),
00564             (ee->ee_thr_62[ee_mode] << 12) & 0x7f000, 0xfff80fff);
00565         AR5K_REG_MASKED_BITS(AR5K_AR5211_PHY(0x49), 4, 0xffffff01);
00566 
00567         AR5K_REG_ENABLE_BITS(AR5K_AR5211_PHY_IQ,
00568             AR5K_AR5211_PHY_IQ_CORR_ENABLE |
00569             (ee->ee_i_cal[ee_mode] << AR5K_AR5211_PHY_IQ_CORR_Q_I_COFF_S) |
00570             ee->ee_q_cal[ee_mode]);
00571 
00572         /*
00573          * Restore saved values
00574          */
00575         AR5K_REG_WRITE(AR5K_AR5211_DCU_SEQNUM(0), s_seq);
00576         AR5K_REG_WRITE(AR5K_AR5211_DEFAULT_ANTENNA, s_ant);
00577         AR5K_REG_ENABLE_BITS(AR5K_AR5211_PCICFG, s_led[0]);
00578         AR5K_REG_WRITE(AR5K_AR5211_GPIOCR, s_led[1]);
00579         AR5K_REG_WRITE(AR5K_AR5211_GPIODO, s_led[2]);
00580 
00581         /*
00582          * Misc
00583          */
00584         bcopy(etherbroadcastaddr, mac, IEEE80211_ADDR_LEN);
00585         ar5k_ar5211_set_associd(hal, mac, 0, 0);
00586         ar5k_ar5211_set_opmode(hal);
00587         AR5K_REG_WRITE(AR5K_AR5211_PISR, 0xffffffff);
00588         AR5K_REG_WRITE(AR5K_AR5211_RSSI_THR, AR5K_TUNE_RSSI_THRES);
00589 
00590         /*
00591          * Set Rx/Tx DMA Configuration
00592          */
00593         AR5K_REG_WRITE_BITS(AR5K_AR5211_TXCFG, AR5K_AR5211_TXCFG_SDMAMR,
00594             AR5K_AR5211_DMASIZE_512B | AR5K_AR5211_TXCFG_DMASIZE);
00595         AR5K_REG_WRITE_BITS(AR5K_AR5211_RXCFG, AR5K_AR5211_RXCFG_SDMAMW,
00596             AR5K_AR5211_DMASIZE_512B);
00597 
00598         /*
00599          * Set channel and calibrate the PHY
00600          */
00601         if (ar5k_channel(hal, channel) == AH_FALSE)
00602                 return (AH_FALSE);
00603 
00604         /*
00605          * Enable the PHY and wait until completion
00606          */
00607         AR5K_REG_WRITE(AR5K_AR5211_PHY_ACTIVE, AR5K_AR5211_PHY_ENABLE);
00608 
00609         data = AR5K_REG_READ(AR5K_AR5211_PHY_RX_DELAY) &
00610             AR5K_AR5211_PHY_RX_DELAY_M;
00611         data = (channel->c_channel_flags & IEEE80211_CHAN_CCK) ?
00612             ((data << 2) / 22) : (data / 10);
00613 
00614         AR5K_DELAY(100 + data);
00615 
00616         /*
00617          * Start calibration
00618          */
00619         AR5K_REG_ENABLE_BITS(AR5K_AR5211_PHY_AGCCTL,
00620             AR5K_AR5211_PHY_AGCCTL_NF |
00621             AR5K_AR5211_PHY_AGCCTL_CAL);
00622 
00623         if (channel->c_channel_flags & IEEE80211_CHAN_B) {
00624                 hal->ah_calibration = AH_FALSE;
00625         } else {
00626                 hal->ah_calibration = AH_TRUE;
00627                 AR5K_REG_WRITE_BITS(AR5K_AR5211_PHY_IQ,
00628                     AR5K_AR5211_PHY_IQ_CAL_NUM_LOG_MAX, 15);
00629                 AR5K_REG_ENABLE_BITS(AR5K_AR5211_PHY_IQ,
00630                     AR5K_AR5211_PHY_IQ_RUN);
00631         }
00632 
00633         /*
00634          * Reset queues and start beacon timers at the end of the reset routine
00635          */
00636         for (i = 0; i < hal->ah_capabilities.cap_queues.q_tx_num; i++) {
00637                 AR5K_REG_WRITE_Q(AR5K_AR5211_DCU_QCUMASK(i), i);
00638                 if (ar5k_ar5211_reset_tx_queue(hal, i) == AH_FALSE) {
00639                         AR5K_PRINTF("failed to reset TX queue #%d\n", i);
00640                         return (AH_FALSE);
00641                 }
00642         }
00643 
00644         /* Pre-enable interrupts */
00645         ar5k_ar5211_set_intr(hal, HAL_INT_RX | HAL_INT_TX | HAL_INT_FATAL);
00646 
00647         /*
00648          * Set RF kill flags if supported by the device (read from the EEPROM)
00649          */
00650         if (AR5K_EEPROM_HDR_RFKILL(hal->ah_capabilities.cap_eeprom.ee_header)) {
00651                 ar5k_ar5211_set_gpio_input(hal, 0);
00652                 if ((hal->ah_gpio[0] = ar5k_ar5211_get_gpio(hal, 0)) == 0)
00653                         ar5k_ar5211_set_gpio_intr(hal, 0, 1);
00654                 else
00655                         ar5k_ar5211_set_gpio_intr(hal, 0, 0);
00656         }
00657 
00658         /* 
00659          * Disable beacons and reset the register
00660          */
00661         AR5K_REG_DISABLE_BITS(AR5K_AR5211_BEACON,
00662             AR5K_AR5211_BEACON_ENABLE | AR5K_AR5211_BEACON_RESET_TSF);
00663 
00664         return (AH_TRUE);
00665 }
00666 
00667 void
00668 ar5k_ar5211_set_opmode(hal)
00669         struct ath_hal *hal;
00670 {
00671         u_int32_t pcu_reg, low_id, high_id;
00672 
00673         pcu_reg = 0;
00674 
00675         switch (hal->ah_op_mode) {
00676         case IEEE80211_M_IBSS:
00677                 pcu_reg |= AR5K_AR5211_STA_ID1_ADHOC |
00678                     AR5K_AR5211_STA_ID1_DESC_ANTENNA;
00679                 break;
00680 
00681         case IEEE80211_M_HOSTAP:
00682                 pcu_reg |= AR5K_AR5211_STA_ID1_AP |
00683                     AR5K_AR5211_STA_ID1_RTS_DEFAULT_ANTENNA;
00684                 break;
00685 
00686         case IEEE80211_M_STA:
00687         case IEEE80211_M_MONITOR:
00688                 pcu_reg |= AR5K_AR5211_STA_ID1_DEFAULT_ANTENNA;
00689                 break;
00690 
00691         default:
00692                 return;
00693         }
00694 
00695         /*
00696          * Set PCU registers
00697          */
00698         bcopy(&(hal->ah_sta_id[0]), &low_id, 4);
00699         bcopy(&(hal->ah_sta_id[4]), &high_id, 2);
00700         AR5K_REG_WRITE(AR5K_AR5211_STA_ID0, low_id);
00701         AR5K_REG_WRITE(AR5K_AR5211_STA_ID1, pcu_reg | high_id);
00702 
00703         return;
00704 }
00705 
00706 HAL_BOOL
00707 ar5k_ar5211_calibrate(hal, channel)
00708         struct ath_hal *hal;
00709         HAL_CHANNEL *channel;
00710 {
00711         u_int32_t i_pwr, q_pwr;
00712         int32_t iq_corr, i_coff, i_coffd, q_coff, q_coffd;
00713 
00714         if (hal->ah_calibration == AH_FALSE ||
00715             AR5K_REG_READ(AR5K_AR5211_PHY_IQ) & AR5K_AR5211_PHY_IQ_RUN)
00716                 goto done;
00717 
00718         hal->ah_calibration = AH_FALSE;
00719 
00720         iq_corr = AR5K_REG_READ(AR5K_AR5211_PHY_IQRES_CAL_CORR);
00721         i_pwr = AR5K_REG_READ(AR5K_AR5211_PHY_IQRES_CAL_PWR_I);
00722         q_pwr = AR5K_REG_READ(AR5K_AR5211_PHY_IQRES_CAL_PWR_Q);
00723         i_coffd = ((i_pwr >> 1) + (q_pwr >> 1)) >> 7;
00724         q_coffd = q_pwr >> 6;
00725 
00726         if (i_coffd == 0 || q_coffd == 0)
00727                 goto done;
00728 
00729         i_coff = ((-iq_corr) / i_coffd) & 0x3f;
00730         q_coff = (((int32_t)i_pwr / q_coffd) - 64) & 0x1f;
00731 
00732         /* Commit new IQ value */
00733         AR5K_REG_ENABLE_BITS(AR5K_AR5211_PHY_IQ,
00734             AR5K_AR5211_PHY_IQ_CORR_ENABLE |
00735             ((u_int32_t)q_coff) |
00736             ((u_int32_t)i_coff << AR5K_AR5211_PHY_IQ_CORR_Q_I_COFF_S));
00737 
00738  done:
00739         /* Start noise floor calibration */
00740         AR5K_REG_ENABLE_BITS(AR5K_AR5211_PHY_AGCCTL,
00741             AR5K_AR5211_PHY_AGCCTL_NF);
00742 
00743         return (AH_TRUE);
00744 }
00745 
00746 /*
00747  * Transmit functions
00748  */
00749 
00750 HAL_BOOL
00751 ar5k_ar5211_update_tx_triglevel(hal, increase)
00752         struct ath_hal *hal;
00753         HAL_BOOL increase;
00754 {
00755         u_int32_t trigger_level, imr;
00756         HAL_BOOL status = AH_FALSE;
00757 
00758         /*
00759          * Disable interrupts by setting the mask
00760          */
00761         imr = ar5k_ar5211_set_intr(hal, hal->ah_imr & ~HAL_INT_GLOBAL);
00762 
00763         trigger_level = AR5K_REG_MS(AR5K_REG_READ(AR5K_AR5211_TXCFG),
00764             AR5K_AR5211_TXCFG_TXFULL);
00765 
00766         if (increase == AH_FALSE) {
00767                 if (--trigger_level < AR5K_TUNE_MIN_TX_FIFO_THRES)
00768                         goto done;
00769         } else
00770                 trigger_level +=
00771                     ((AR5K_TUNE_MAX_TX_FIFO_THRES - trigger_level) / 2);
00772 
00773         /*
00774          * Update trigger level on success
00775          */
00776         AR5K_REG_WRITE_BITS(AR5K_AR5211_TXCFG,
00777             AR5K_AR5211_TXCFG_TXFULL, trigger_level);
00778         status = AH_TRUE;
00779 
00780  done:
00781         /*
00782          * Restore interrupt mask
00783          */
00784         ar5k_ar5211_set_intr(hal, imr);
00785 
00786         return (status);
00787 }
00788 
00789 int
00790 ar5k_ar5211_setup_tx_queue(hal, queue_type, queue_info)
00791         struct ath_hal *hal;
00792         HAL_TX_QUEUE queue_type;
00793         const HAL_TXQ_INFO *queue_info;
00794 {
00795         u_int queue;
00796 
00797         /*
00798          * Get queue by type
00799          */
00800         if (queue_type == HAL_TX_QUEUE_DATA) {
00801                 for (queue = HAL_TX_QUEUE_ID_DATA_MIN;
00802                      hal->ah_txq[queue].tqi_type != HAL_TX_QUEUE_INACTIVE;
00803                      queue++)
00804                         if (queue > HAL_TX_QUEUE_ID_DATA_MAX)
00805                                 return (-1);
00806         } else if (queue_type == HAL_TX_QUEUE_PSPOLL) {
00807                 queue = HAL_TX_QUEUE_ID_PSPOLL;
00808         } else if (queue_type == HAL_TX_QUEUE_BEACON) {
00809                 queue = HAL_TX_QUEUE_ID_BEACON;
00810         } else if (queue_type == HAL_TX_QUEUE_CAB) {
00811                 queue = HAL_TX_QUEUE_ID_CAB;
00812         } else
00813                 return (-1);
00814 
00815         /*
00816          * Setup internal queue structure
00817          */
00818         bzero(&hal->ah_txq[queue], sizeof(HAL_TXQ_INFO));
00819         hal->ah_txq[queue].tqi_type = queue_type;
00820 
00821         if (queue_info != NULL) {
00822                 if (ar5k_ar5211_setup_tx_queueprops(hal, queue, queue_info)
00823                     != AH_TRUE)
00824                         return (-1);
00825         }
00826 
00827         AR5K_Q_ENABLE_BITS(hal->ah_txq_interrupts, queue);
00828 
00829         return (queue);
00830 }
00831 
00832 HAL_BOOL
00833 ar5k_ar5211_setup_tx_queueprops(hal, queue, queue_info)
00834         struct ath_hal *hal;
00835         int queue;
00836         const HAL_TXQ_INFO *queue_info;
00837 {
00838         AR5K_ASSERT_ENTRY(queue, hal->ah_capabilities.cap_queues.q_tx_num);
00839 
00840         if (hal->ah_txq[queue].tqi_type == HAL_TX_QUEUE_INACTIVE)
00841                 return (AH_FALSE);
00842 
00843         bcopy(queue_info, &hal->ah_txq[queue], sizeof(HAL_TXQ_INFO));
00844 
00845         if (queue_info->tqi_type == HAL_TX_QUEUE_DATA &&
00846             (queue_info->tqi_subtype >= HAL_WME_AC_VI) &&
00847             (queue_info->tqi_subtype <= HAL_WME_UPSD))
00848                 hal->ah_txq[queue].tqi_flags |=
00849                     AR5K_TXQ_FLAG_POST_FR_BKOFF_DIS;
00850 
00851         return (AH_TRUE);
00852 }
00853 
00854 HAL_BOOL
00855 ar5k_ar5211_release_tx_queue(hal, queue)
00856         struct ath_hal *hal;
00857         u_int queue;
00858 {
00859         AR5K_ASSERT_ENTRY(queue, hal->ah_capabilities.cap_queues.q_tx_num);
00860 
00861         /* This queue will be skipped in further operations */
00862         hal->ah_txq[queue].tqi_type = HAL_TX_QUEUE_INACTIVE;
00863         AR5K_Q_DISABLE_BITS(hal->ah_txq_interrupts, queue);
00864 
00865         return (AH_FALSE);
00866 }
00867 
00868 HAL_BOOL
00869 ar5k_ar5211_reset_tx_queue(hal, queue)
00870         struct ath_hal *hal;
00871         u_int queue;
00872 {
00873         u_int32_t cw_min, cw_max, retry_lg, retry_sh;
00874         struct ieee80211_channel *channel = (struct ieee80211_channel*)
00875             &hal->ah_current_channel;
00876         HAL_TXQ_INFO *tq;
00877 
00878         AR5K_ASSERT_ENTRY(queue, hal->ah_capabilities.cap_queues.q_tx_num);
00879 
00880         tq = &hal->ah_txq[queue];
00881 
00882         if (tq->tqi_type == HAL_TX_QUEUE_INACTIVE)
00883                 return (AH_TRUE);
00884 
00885         /*
00886          * Set registers by channel mode
00887          */
00888         if (IEEE80211_IS_CHAN_B(channel)) {
00889                 hal->ah_cw_min = AR5K_TUNE_CWMIN_11B;
00890                 cw_max = hal->ah_cw_max = AR5K_TUNE_CWMAX_11B;
00891                 hal->ah_aifs = AR5K_TUNE_AIFS_11B;
00892         } else {
00893                 hal->ah_cw_min = AR5K_TUNE_CWMIN;
00894                 cw_max = hal->ah_cw_max = AR5K_TUNE_CWMAX;
00895                 hal->ah_aifs = AR5K_TUNE_AIFS;
00896         }
00897 
00898         /*
00899          * Set retry limits
00900          */
00901         if (hal->ah_software_retry == AH_TRUE) {
00902                 /* XXX Need to test this */
00903                 retry_lg = hal->ah_limit_tx_retries;
00904                 retry_sh = retry_lg =
00905                     retry_lg > AR5K_AR5211_DCU_RETRY_LMT_SH_RETRY ?
00906                     AR5K_AR5211_DCU_RETRY_LMT_SH_RETRY : retry_lg;
00907         } else {
00908                 retry_lg = AR5K_INIT_LG_RETRY;
00909                 retry_sh = AR5K_INIT_SH_RETRY;
00910         }
00911 
00912         AR5K_REG_WRITE(AR5K_AR5211_DCU_RETRY_LMT(queue),
00913             AR5K_REG_SM(AR5K_INIT_SLG_RETRY,
00914             AR5K_AR5211_DCU_RETRY_LMT_SLG_RETRY) |
00915             AR5K_REG_SM(AR5K_INIT_SSH_RETRY,
00916             AR5K_AR5211_DCU_RETRY_LMT_SSH_RETRY) |
00917             AR5K_REG_SM(retry_lg, AR5K_AR5211_DCU_RETRY_LMT_LG_RETRY) |
00918             AR5K_REG_SM(retry_sh, AR5K_AR5211_DCU_RETRY_LMT_SH_RETRY));
00919 
00920         /*
00921          * Set initial content window (cw_min/cw_max)
00922          */
00923         cw_min = 1;
00924         while (cw_min < hal->ah_cw_min)
00925                 cw_min = (cw_min << 1) | 1;
00926 
00927         cw_min = tq->tqi_cw_min < 0 ?
00928             (cw_min >> (-tq->tqi_cw_min)) :
00929             ((cw_min << tq->tqi_cw_min) + (1 << tq->tqi_cw_min) - 1);
00930         cw_max = tq->tqi_cw_max < 0 ?
00931             (cw_max >> (-tq->tqi_cw_max)) :
00932             ((cw_max << tq->tqi_cw_max) + (1 << tq->tqi_cw_max) - 1);
00933 
00934         AR5K_REG_WRITE(AR5K_AR5211_DCU_LCL_IFS(queue),
00935             AR5K_REG_SM(cw_min, AR5K_AR5211_DCU_LCL_IFS_CW_MIN) |
00936             AR5K_REG_SM(cw_max, AR5K_AR5211_DCU_LCL_IFS_CW_MAX) |
00937             AR5K_REG_SM(hal->ah_aifs + tq->tqi_aifs,
00938             AR5K_AR5211_DCU_LCL_IFS_AIFS));
00939 
00940         /*
00941          * Set misc registers
00942          */
00943         AR5K_REG_WRITE(AR5K_AR5211_QCU_MISC(queue),
00944             AR5K_AR5211_QCU_MISC_DCU_EARLY);
00945 
00946         if (tq->tqi_cbr_period) {
00947                 AR5K_REG_WRITE(AR5K_AR5211_QCU_CBRCFG(queue),
00948                     AR5K_REG_SM(tq->tqi_cbr_period,
00949                     AR5K_AR5211_QCU_CBRCFG_INTVAL) |
00950                     AR5K_REG_SM(tq->tqi_cbr_overflow_limit,
00951                     AR5K_AR5211_QCU_CBRCFG_ORN_THRES));
00952                 AR5K_REG_ENABLE_BITS(AR5K_AR5211_QCU_MISC(queue),
00953                     AR5K_AR5211_QCU_MISC_FRSHED_CBR);
00954                 if (tq->tqi_cbr_overflow_limit)
00955                         AR5K_REG_ENABLE_BITS(AR5K_AR5211_QCU_MISC(queue),
00956                             AR5K_AR5211_QCU_MISC_CBR_THRES_ENABLE);
00957         }
00958 
00959         if (tq->tqi_ready_time) {
00960                 AR5K_REG_WRITE(AR5K_AR5211_QCU_RDYTIMECFG(queue),
00961                     AR5K_REG_SM(tq->tqi_ready_time,
00962                     AR5K_AR5211_QCU_RDYTIMECFG_INTVAL) |
00963                     AR5K_AR5211_QCU_RDYTIMECFG_ENABLE);
00964         }
00965 
00966         if (tq->tqi_burst_time) {
00967                 AR5K_REG_WRITE(AR5K_AR5211_DCU_CHAN_TIME(queue),
00968                     AR5K_REG_SM(tq->tqi_burst_time,
00969                     AR5K_AR5211_DCU_CHAN_TIME_DUR) |
00970                     AR5K_AR5211_DCU_CHAN_TIME_ENABLE);
00971 
00972                 if (tq->tqi_flags & AR5K_TXQ_FLAG_RDYTIME_EXP_POLICY_ENABLE) {
00973                         AR5K_REG_ENABLE_BITS(AR5K_AR5211_QCU_MISC(queue),
00974                             AR5K_AR5211_QCU_MISC_TXE);
00975                 }
00976         }
00977 
00978         if (tq->tqi_flags & AR5K_TXQ_FLAG_BACKOFF_DISABLE) {
00979                 AR5K_REG_WRITE(AR5K_AR5211_DCU_MISC(queue),
00980                     AR5K_AR5211_DCU_MISC_POST_FR_BKOFF_DIS);
00981         }
00982 
00983         if (tq->tqi_flags & AR5K_TXQ_FLAG_FRAG_BURST_BACKOFF_ENABLE) {
00984                 AR5K_REG_WRITE(AR5K_AR5211_DCU_MISC(queue),
00985                     AR5K_AR5211_DCU_MISC_BACKOFF_FRAG);
00986         }
00987 
00988         /*
00989          * Set registers by queue type
00990          */
00991         switch (tq->tqi_type) {
00992         case HAL_TX_QUEUE_BEACON:
00993                 AR5K_REG_ENABLE_BITS(AR5K_AR5211_QCU_MISC(queue),
00994                     AR5K_AR5211_QCU_MISC_FRSHED_DBA_GT |
00995                     AR5K_AR5211_QCU_MISC_CBREXP_BCN |
00996                     AR5K_AR5211_QCU_MISC_BCN_ENABLE);
00997 
00998                 AR5K_REG_ENABLE_BITS(AR5K_AR5211_DCU_MISC(queue),
00999                     (AR5K_AR5211_DCU_MISC_ARBLOCK_CTL_GLOBAL <<
01000                     AR5K_AR5211_DCU_MISC_ARBLOCK_CTL_GLOBAL) |
01001                     AR5K_AR5211_DCU_MISC_POST_FR_BKOFF_DIS |
01002                     AR5K_AR5211_DCU_MISC_BCN_ENABLE);
01003 
01004                 AR5K_REG_WRITE(AR5K_AR5211_QCU_RDYTIMECFG(queue),
01005                     ((AR5K_TUNE_BEACON_INTERVAL -
01006                     (AR5K_TUNE_SW_BEACON_RESP - AR5K_TUNE_DMA_BEACON_RESP) -
01007                     AR5K_TUNE_ADDITIONAL_SWBA_BACKOFF) * 1024) |
01008                     AR5K_AR5211_QCU_RDYTIMECFG_ENABLE);
01009                 break;
01010 
01011         case HAL_TX_QUEUE_CAB:
01012                 AR5K_REG_ENABLE_BITS(AR5K_AR5211_QCU_MISC(queue),
01013                     AR5K_AR5211_QCU_MISC_FRSHED_DBA_GT |
01014                     AR5K_AR5211_QCU_MISC_CBREXP |
01015                     AR5K_AR5211_QCU_MISC_CBREXP_BCN);
01016 
01017                 AR5K_REG_ENABLE_BITS(AR5K_AR5211_DCU_MISC(queue),
01018                     (AR5K_AR5211_DCU_MISC_ARBLOCK_CTL_GLOBAL <<
01019                     AR5K_AR5211_DCU_MISC_ARBLOCK_CTL_GLOBAL));
01020                 break;
01021 
01022         case HAL_TX_QUEUE_PSPOLL:
01023                 AR5K_REG_ENABLE_BITS(AR5K_AR5211_QCU_MISC(queue),
01024                     AR5K_AR5211_QCU_MISC_CBREXP);
01025                 break;
01026 
01027         case HAL_TX_QUEUE_DATA:
01028         default:
01029                 break;
01030         }
01031 
01032         /*
01033          * Enable tx queue in the secondary interrupt mask registers
01034          */
01035         AR5K_REG_WRITE(AR5K_AR5211_SIMR0,
01036             AR5K_REG_SM(hal->ah_txq_interrupts, AR5K_AR5211_SIMR0_QCU_TXOK) |
01037             AR5K_REG_SM(hal->ah_txq_interrupts, AR5K_AR5211_SIMR0_QCU_TXDESC));
01038         AR5K_REG_WRITE(AR5K_AR5211_SIMR1,
01039             AR5K_REG_SM(hal->ah_txq_interrupts, AR5K_AR5211_SIMR1_QCU_TXERR));
01040         AR5K_REG_WRITE(AR5K_AR5211_SIMR2,
01041             AR5K_REG_SM(hal->ah_txq_interrupts, AR5K_AR5211_SIMR2_QCU_TXURN));
01042 
01043         return (AH_TRUE);
01044 }
01045 
01046 u_int32_t
01047 ar5k_ar5211_get_tx_buf(hal, queue)
01048         struct ath_hal *hal;
01049         u_int queue;
01050 {
01051         AR5K_ASSERT_ENTRY(queue, hal->ah_capabilities.cap_queues.q_tx_num);
01052 
01053         /*
01054          * Get the transmit queue descriptor pointer from the selected queue
01055          */
01056         return (AR5K_REG_READ(AR5K_AR5211_QCU_TXDP(queue)));
01057 }
01058 
01059 HAL_BOOL
01060 ar5k_ar5211_put_tx_buf(hal, queue, phys_addr)
01061         struct ath_hal *hal;
01062         u_int queue;
01063         u_int32_t phys_addr;
01064 {
01065         AR5K_ASSERT_ENTRY(queue, hal->ah_capabilities.cap_queues.q_tx_num);
01066 
01067         /*
01068          * Set the transmit queue descriptor pointer for the selected queue
01069          * (this won't work if the queue is still active)
01070          */
01071         if (AR5K_REG_READ_Q(AR5K_AR5211_QCU_TXE, queue))
01072                 return (AH_FALSE);
01073 
01074         AR5K_REG_WRITE(AR5K_AR5211_QCU_TXDP(queue), phys_addr);
01075 
01076         return (AH_TRUE);
01077 }
01078 
01079 HAL_BOOL
01080 ar5k_ar5211_tx_start(hal, queue)
01081         struct ath_hal *hal;
01082         u_int queue;
01083 {
01084         AR5K_ASSERT_ENTRY(queue, hal->ah_capabilities.cap_queues.q_tx_num);
01085 
01086         /* Return if queue is disabled */
01087         if (AR5K_REG_READ_Q(AR5K_AR5211_QCU_TXD, queue))
01088                 return (AH_FALSE);
01089 
01090         /* Start queue */
01091         AR5K_REG_WRITE_Q(AR5K_AR5211_QCU_TXE, queue);
01092 
01093         return (AH_TRUE);
01094 }
01095 
01096 HAL_BOOL
01097 ar5k_ar5211_stop_tx_dma(hal, queue)
01098         struct ath_hal *hal;
01099         u_int queue;
01100 {
01101         int i = 100, pending;
01102 
01103         AR5K_ASSERT_ENTRY(queue, hal->ah_capabilities.cap_queues.q_tx_num);
01104 
01105         /*
01106          * Schedule TX disable and wait until queue is empty
01107          */
01108         AR5K_REG_WRITE_Q(AR5K_AR5211_QCU_TXD, queue);
01109 
01110         do {
01111                 pending = AR5K_REG_READ(AR5K_AR5211_QCU_STS(queue)) &
01112                      AR5K_AR5211_QCU_STS_FRMPENDCNT;
01113                 delay(100);
01114         } while (--i && pending);
01115 
01116         /* Clear register */
01117         AR5K_REG_WRITE(AR5K_AR5211_QCU_TXD, 0);
01118 
01119         return (AH_TRUE);
01120 }
01121 
01122 HAL_BOOL
01123 ar5k_ar5211_setup_tx_desc(hal, desc, packet_length, header_length, type,
01124     tx_power, tx_rate0, tx_tries0, key_index, antenna_mode, flags, rtscts_rate,
01125     rtscts_duration)
01126         struct ath_hal *hal;
01127         struct ath_desc *desc;
01128         u_int packet_length;
01129         u_int header_length;
01130         HAL_PKT_TYPE type;
01131         u_int tx_power;
01132         u_int tx_rate0;
01133         u_int tx_tries0;
01134         u_int key_index;
01135         u_int antenna_mode;
01136         u_int flags;
01137         u_int rtscts_rate;
01138         u_int rtscts_duration;
01139 {
01140         struct ar5k_ar5211_tx_desc *tx_desc;
01141 
01142         tx_desc = (struct ar5k_ar5211_tx_desc*)&desc->ds_ctl0;
01143 
01144         /*
01145          * Validate input
01146          */
01147         if (tx_tries0 == 0)
01148                 return (AH_FALSE);
01149 
01150         if ((tx_desc->tx_control_0 = (packet_length &
01151             AR5K_AR5211_DESC_TX_CTL0_FRAME_LEN)) != packet_length)
01152                 return (AH_FALSE);
01153 
01154         tx_desc->tx_control_0 |=
01155             AR5K_REG_SM(tx_rate0, AR5K_AR5211_DESC_TX_CTL0_XMIT_RATE) |
01156             AR5K_REG_SM(antenna_mode, AR5K_AR5211_DESC_TX_CTL0_ANT_MODE_XMIT);
01157         tx_desc->tx_control_1 =
01158             AR5K_REG_SM(type, AR5K_AR5211_DESC_TX_CTL1_FRAME_TYPE);
01159 
01160 #define _TX_FLAGS(_c, _flag)                                            \
01161         if (flags & HAL_TXDESC_##_flag)                                 \
01162                 tx_desc->tx_control_##_c |=                             \
01163                         AR5K_AR5211_DESC_TX_CTL##_c##_##_flag
01164 
01165         _TX_FLAGS(0, CLRDMASK);
01166         _TX_FLAGS(0, VEOL);
01167         _TX_FLAGS(0, INTREQ);
01168         _TX_FLAGS(0, RTSENA);
01169         _TX_FLAGS(1, NOACK);
01170 
01171 #undef _TX_FLAGS
01172 
01173         /*
01174          * WEP crap
01175          */
01176         if (key_index != HAL_TXKEYIX_INVALID) {
01177                 tx_desc->tx_control_0 |=
01178                     AR5K_AR5211_DESC_TX_CTL0_ENCRYPT_KEY_VALID;
01179                 tx_desc->tx_control_1 |=
01180                     AR5K_REG_SM(key_index,
01181                     AR5K_AR5211_DESC_TX_CTL1_ENCRYPT_KEY_INDEX);
01182         }
01183 
01184         return (AH_TRUE);
01185 }
01186 
01187 HAL_BOOL
01188 ar5k_ar5211_fill_tx_desc(hal, desc, segment_length, first_segment, last_segment)
01189         struct ath_hal *hal;
01190         struct ath_desc *desc;
01191         u_int segment_length;
01192         HAL_BOOL first_segment;
01193         HAL_BOOL last_segment;
01194 {
01195         struct ar5k_ar5211_tx_desc *tx_desc;
01196 
01197         tx_desc = (struct ar5k_ar5211_tx_desc*)&desc->ds_ctl0;
01198 
01199         /* Clear status descriptor */
01200         bzero(desc->ds_hw, sizeof(desc->ds_hw));
01201 
01202         /* Validate segment length and initialize the descriptor */
01203         if ((tx_desc->tx_control_1 = (segment_length &
01204             AR5K_AR5211_DESC_TX_CTL1_BUF_LEN)) != segment_length)
01205                 return (AH_FALSE);
01206 
01207         if (first_segment != AH_TRUE)
01208                 tx_desc->tx_control_0 &= ~AR5K_AR5211_DESC_TX_CTL0_FRAME_LEN;
01209 
01210         if (last_segment != AH_TRUE)
01211                 tx_desc->tx_control_1 |= AR5K_AR5211_DESC_TX_CTL1_MORE;
01212 
01213         return (AH_TRUE);
01214 }
01215 
01216 HAL_BOOL
01217 ar5k_ar5211_setup_xtx_desc(hal, desc, tx_rate1, tx_tries1, tx_rate2, tx_tries2,
01218     tx_rate3, tx_tries3)
01219         struct ath_hal *hal;
01220         struct ath_desc *desc;
01221         u_int tx_rate1;
01222         u_int tx_tries1;
01223         u_int tx_rate2;
01224         u_int tx_tries2;
01225         u_int tx_rate3;
01226         u_int tx_tries3;
01227 {
01228         return (AH_FALSE);
01229 }
01230 
01231 HAL_STATUS
01232 ar5k_ar5211_proc_tx_desc(hal, desc)
01233         struct ath_hal *hal;
01234         struct ath_desc *desc;
01235 {
01236         struct ar5k_ar5211_tx_status *tx_status;
01237         struct ar5k_ar5211_tx_desc *tx_desc;
01238 
01239         tx_desc = (struct ar5k_ar5211_tx_desc*)&desc->ds_ctl0;
01240         tx_status = (struct ar5k_ar5211_tx_status*)&desc->ds_hw[0];
01241 
01242         /* No frame has been send or error */
01243         if ((tx_status->tx_status_1 & AR5K_AR5211_DESC_TX_STATUS1_DONE) == 0)
01244                 return (HAL_EINPROGRESS);
01245 
01246         /*
01247          * Get descriptor status
01248          */
01249         desc->ds_us.tx.ts_tstamp =
01250             AR5K_REG_MS(tx_status->tx_status_0,
01251             AR5K_AR5211_DESC_TX_STATUS0_SEND_TIMESTAMP);
01252         desc->ds_us.tx.ts_shortretry =
01253             AR5K_REG_MS(tx_status->tx_status_0,
01254             AR5K_AR5211_DESC_TX_STATUS0_RTS_FAIL_COUNT);
01255         desc->ds_us.tx.ts_longretry =
01256             AR5K_REG_MS(tx_status->tx_status_0,
01257             AR5K_AR5211_DESC_TX_STATUS0_DATA_FAIL_COUNT);
01258         desc->ds_us.tx.ts_seqnum =
01259             AR5K_REG_MS(tx_status->tx_status_1,
01260             AR5K_AR5211_DESC_TX_STATUS1_SEQ_NUM);
01261         desc->ds_us.tx.ts_rssi =
01262             AR5K_REG_MS(tx_status->tx_status_1,
01263             AR5K_AR5211_DESC_TX_STATUS1_ACK_SIG_STRENGTH);
01264         desc->ds_us.tx.ts_antenna = 1;
01265         desc->ds_us.tx.ts_status = 0;
01266         desc->ds_us.tx.ts_tstamp =
01267             AR5K_REG_MS(tx_desc->tx_control_0,
01268             AR5K_AR5211_DESC_TX_CTL0_XMIT_RATE);
01269 
01270         if ((tx_status->tx_status_0 &
01271             AR5K_AR5211_DESC_TX_STATUS0_FRAME_XMIT_OK) == 0) {
01272                 if (tx_status->tx_status_0 &
01273                     AR5K_AR5211_DESC_TX_STATUS0_EXCESSIVE_RETRIES)
01274                         desc->ds_us.tx.ts_status |= HAL_TXERR_XRETRY;
01275 
01276                 if (tx_status->tx_status_0 &
01277                     AR5K_AR5211_DESC_TX_STATUS0_FIFO_UNDERRUN)
01278                         desc->ds_us.tx.ts_status |= HAL_TXERR_FIFO;
01279 
01280                 if (tx_status->tx_status_0 &
01281                     AR5K_AR5211_DESC_TX_STATUS0_FILTERED)
01282                         desc->ds_us.tx.ts_status |= HAL_TXERR_FILT;
01283         }
01284 
01285         return (HAL_OK);
01286 }
01287 
01288 HAL_BOOL
01289 ar5k_ar5211_has_veol(hal)
01290         struct ath_hal *hal;
01291 {
01292         return (AH_TRUE);
01293 }
01294 
01295 /*
01296  * Receive functions
01297  */
01298 
01299 u_int32_t
01300 ar5k_ar5211_get_rx_buf(hal)
01301         struct ath_hal *hal;
01302 {
01303         return (AR5K_REG_READ(AR5K_AR5211_RXDP));
01304 }
01305 
01306 void
01307 ar5k_ar5211_put_rx_buf(hal, phys_addr)
01308         struct ath_hal *hal;
01309         u_int32_t phys_addr;
01310 {
01311         AR5K_REG_WRITE(AR5K_AR5211_RXDP, phys_addr);
01312 }
01313 
01314 void
01315 ar5k_ar5211_start_rx(hal)
01316         struct ath_hal *hal;
01317 {
01318         AR5K_REG_WRITE(AR5K_AR5211_CR, AR5K_AR5211_CR_RXE);
01319 }
01320 
01321 HAL_BOOL
01322 ar5k_ar5211_stop_rx_dma(hal)
01323         struct ath_hal *hal;
01324 {
01325         int i;
01326 
01327         AR5K_REG_WRITE(AR5K_AR5211_CR, AR5K_AR5211_CR_RXD);
01328 
01329         /*
01330          * It may take some time to disable the DMA receive unit
01331          */
01332         for (i = 2000;
01333              i > 0 && (AR5K_REG_READ(AR5K_AR5211_CR) & AR5K_AR5211_CR_RXE) != 0;
01334              i--)
01335                 AR5K_DELAY(10);
01336 
01337         return (i > 0 ? AH_TRUE : AH_FALSE);
01338 }
01339 
01340 void
01341 ar5k_ar5211_start_rx_pcu(hal)
01342         struct ath_hal *hal;
01343 {
01344         AR5K_REG_DISABLE_BITS(AR5K_AR5211_DIAG_SW, AR5K_AR5211_DIAG_SW_DIS_RX);
01345 }
01346 
01347 void
01348 ar5k_ar5211_stop_pcu_recv(hal)
01349         struct ath_hal *hal;
01350 {
01351         AR5K_REG_ENABLE_BITS(AR5K_AR5211_DIAG_SW, AR5K_AR5211_DIAG_SW_DIS_RX);
01352 }
01353 
01354 void
01355 ar5k_ar5211_set_mcast_filter(hal, filter0, filter1)
01356         struct ath_hal *hal;
01357         u_int32_t filter0;
01358         u_int32_t filter1;
01359 {
01360         /* Set the multicat filter */
01361         AR5K_REG_WRITE(AR5K_AR5211_MCAST_FIL0, filter0);
01362         AR5K_REG_WRITE(AR5K_AR5211_MCAST_FIL1, filter1);
01363 }
01364 
01365 HAL_BOOL
01366 ar5k_ar5211_set_mcast_filterindex(hal, index)
01367         struct ath_hal *hal;
01368         u_int32_t index;
01369 {
01370         if (index >= 64) {
01371             return (AH_FALSE);
01372         } else if (index >= 32) {
01373             AR5K_REG_ENABLE_BITS(AR5K_AR5211_MCAST_FIL1,
01374                 (1 << (index - 32)));
01375         } else {
01376             AR5K_REG_ENABLE_BITS(AR5K_AR5211_MCAST_FIL0,
01377                 (1 << index));
01378         }
01379 
01380         return (AH_TRUE);
01381 }
01382 
01383 HAL_BOOL
01384 ar5k_ar5211_clear_mcast_filter_idx(hal, index)
01385         struct ath_hal *hal;
01386         u_int32_t index;
01387 {
01388 
01389         if (index >= 64) {
01390             return (AH_FALSE);
01391         } else if (index >= 32) {
01392             AR5K_REG_DISABLE_BITS(AR5K_AR5211_MCAST_FIL1,
01393                 (1 << (index - 32)));
01394         } else {
01395             AR5K_REG_DISABLE_BITS(AR5K_AR5211_MCAST_FIL0,
01396                 (1 << index));
01397         }
01398 
01399         return (AH_TRUE);
01400 }
01401 
01402 u_int32_t
01403 ar5k_ar5211_get_rx_filter(hal)
01404         struct ath_hal *hal;
01405 {
01406         return (AR5K_REG_READ(AR5K_AR5211_RX_FILTER));
01407 }
01408 
01409 void
01410 ar5k_ar5211_set_rx_filter(hal, filter)
01411         struct ath_hal *hal;
01412         u_int32_t filter;
01413 {
01414         AR5K_REG_WRITE(AR5K_AR5211_RX_FILTER, filter);
01415 }
01416 
01417 HAL_BOOL
01418 ar5k_ar5211_setup_rx_desc(hal, desc, size, flags)
01419         struct ath_hal *hal;
01420         struct ath_desc *desc;
01421         u_int32_t size;
01422         u_int flags;
01423 {
01424         struct ar5k_ar5211_rx_desc *rx_desc;
01425 
01426         rx_desc = (struct ar5k_ar5211_rx_desc*)&desc->ds_ctl0;
01427 
01428         if ((rx_desc->rx_control_1 = (size &
01429             AR5K_AR5211_DESC_RX_CTL1_BUF_LEN)) != size)
01430                 return (AH_FALSE);
01431 
01432         if (flags & HAL_RXDESC_INTREQ)
01433                 rx_desc->rx_control_1 |= AR5K_AR5211_DESC_RX_CTL1_INTREQ;
01434 
01435         return (AH_TRUE);
01436 }
01437 
01438 HAL_STATUS
01439 ar5k_ar5211_proc_rx_desc(hal, desc, phys_addr, next)
01440         struct ath_hal *hal;
01441         struct ath_desc *desc;
01442         u_int32_t phys_addr;
01443         struct ath_desc *next;
01444 {
01445         struct ar5k_ar5211_rx_status *rx_status;
01446 
01447         rx_status = (struct ar5k_ar5211_rx_status*)&desc->ds_hw[0];
01448 
01449         /* No frame received / not ready */
01450         if ((rx_status->rx_status_1 & AR5K_AR5211_DESC_RX_STATUS1_DONE) == 0)
01451                 return (HAL_EINPROGRESS);
01452 
01453         /*
01454          * Frame receive status
01455          */
01456         desc->ds_us.rx.rs_datalen = rx_status->rx_status_0 &
01457             AR5K_AR5211_DESC_RX_STATUS0_DATA_LEN;
01458         desc->ds_us.rx.rs_rssi =
01459             AR5K_REG_MS(rx_status->rx_status_0,
01460             AR5K_AR5211_DESC_RX_STATUS0_RECEIVE_SIGNAL);
01461         desc->ds_us.rx.rs_rate =
01462             AR5K_REG_MS(rx_status->rx_status_0,
01463             AR5K_AR5211_DESC_RX_STATUS0_RECEIVE_RATE);
01464         desc->ds_us.rx.rs_antenna = rx_status->rx_status_0 &
01465             AR5K_AR5211_DESC_RX_STATUS0_RECEIVE_ANTENNA;
01466         desc->ds_us.rx.rs_more = rx_status->rx_status_0 &
01467             AR5K_AR5211_DESC_RX_STATUS0_MORE;
01468         desc->ds_us.rx.rs_tstamp =
01469             AR5K_REG_MS(rx_status->rx_status_1,
01470             AR5K_AR5211_DESC_RX_STATUS1_RECEIVE_TIMESTAMP);
01471         desc->ds_us.rx.rs_status = 0;
01472 
01473         /*
01474          * Key table status
01475          */
01476         if (rx_status->rx_status_1 &
01477             AR5K_AR5211_DESC_RX_STATUS1_KEY_INDEX_VALID) {
01478                 desc->ds_us.rx.rs_keyix =
01479                     AR5K_REG_MS(rx_status->rx_status_1,
01480                     AR5K_AR5211_DESC_RX_STATUS1_KEY_INDEX);
01481         } else {
01482                 desc->ds_us.rx.rs_keyix = HAL_RXKEYIX_INVALID;
01483         }
01484 
01485         /*
01486          * Receive/descriptor errors
01487          */
01488         if ((rx_status->rx_status_1 &
01489             AR5K_AR5211_DESC_RX_STATUS1_FRAME_RECEIVE_OK) == 0) {
01490                 if (rx_status->rx_status_1 &
01491                     AR5K_AR5211_DESC_RX_STATUS1_CRC_ERROR)
01492                         desc->ds_us.rx.rs_status |= HAL_RXERR_CRC;
01493 
01494                 if (rx_status->rx_status_1 &
01495                     AR5K_AR5211_DESC_RX_STATUS1_PHY_ERROR) {
01496                         desc->ds_us.rx.rs_status |= HAL_RXERR_PHY;
01497                         desc->ds_us.rx.rs_phyerr =
01498                             AR5K_REG_MS(rx_status->rx_status_1,
01499                             AR5K_AR5211_DESC_RX_STATUS1_PHY_ERROR);
01500                 }
01501 
01502                 if (rx_status->rx_status_1 &
01503                     AR5K_AR5211_DESC_RX_STATUS1_DECRYPT_CRC_ERROR)
01504                         desc->ds_us.rx.rs_status |= HAL_RXERR_DECRYPT;
01505         }
01506 
01507         return (HAL_OK);
01508 }
01509 
01510 void
01511 ar5k_ar5211_set_rx_signal(hal)
01512         struct ath_hal *hal;
01513 {
01514         /* Signal state monitoring is not yet supported */
01515 }
01516 
01517 /*
01518  * Misc functions
01519  */
01520 
01521 void
01522 ar5k_ar5211_dump_state(hal)
01523         struct ath_hal *hal;
01524 {
01525 #ifdef AR5K_DEBUG
01526 #define AR5K_PRINT_REGISTER(_x)                                         \
01527         printf("(%s: %08x) ", #_x, AR5K_REG_READ(AR5K_AR5211_##_x));
01528 
01529         printf("MAC registers:\n");
01530         AR5K_PRINT_REGISTER(CR);
01531         AR5K_PRINT_REGISTER(CFG);
01532         AR5K_PRINT_REGISTER(IER);
01533         AR5K_PRINT_REGISTER(RTSD0);
01534         AR5K_PRINT_REGISTER(TXCFG);
01535         AR5K_PRINT_REGISTER(RXCFG);
01536         AR5K_PRINT_REGISTER(RXJLA);
01537         AR5K_PRINT_REGISTER(MIBC);
01538         AR5K_PRINT_REGISTER(TOPS);
01539         AR5K_PRINT_REGISTER(RXNOFRM);
01540         AR5K_PRINT_REGISTER(RPGTO);
01541         AR5K_PRINT_REGISTER(RFCNT);
01542         AR5K_PRINT_REGISTER(MISC);
01543         AR5K_PRINT_REGISTER(PISR);
01544         AR5K_PRINT_REGISTER(SISR0);
01545         AR5K_PRINT_REGISTER(SISR1);
01546         AR5K_PRINT_REGISTER(SISR3);
01547         AR5K_PRINT_REGISTER(SISR4);
01548         AR5K_PRINT_REGISTER(QCU_TXE);
01549         AR5K_PRINT_REGISTER(QCU_TXD);
01550         AR5K_PRINT_REGISTER(DCU_GBL_IFS_SIFS);
01551         AR5K_PRINT_REGISTER(DCU_GBL_IFS_SLOT);
01552         AR5K_PRINT_REGISTER(DCU_FP);
01553         AR5K_PRINT_REGISTER(DCU_TXP);
01554         AR5K_PRINT_REGISTER(DCU_TX_FILTER);
01555         AR5K_PRINT_REGISTER(RC);
01556         AR5K_PRINT_REGISTER(SCR);
01557         AR5K_PRINT_REGISTER(INTPEND);
01558         AR5K_PRINT_REGISTER(PCICFG);
01559         AR5K_PRINT_REGISTER(GPIOCR);
01560         AR5K_PRINT_REGISTER(GPIODO);
01561         AR5K_PRINT_REGISTER(SREV);
01562         AR5K_PRINT_REGISTER(EEPROM_BASE);
01563         AR5K_PRINT_REGISTER(EEPROM_DATA);
01564         AR5K_PRINT_REGISTER(EEPROM_CMD);
01565         AR5K_PRINT_REGISTER(EEPROM_CFG);
01566         AR5K_PRINT_REGISTER(PCU_MIN);
01567         AR5K_PRINT_REGISTER(STA_ID0);
01568         AR5K_PRINT_REGISTER(STA_ID1);
01569         AR5K_PRINT_REGISTER(BSS_ID0);
01570         AR5K_PRINT_REGISTER(SLOT_TIME);
01571         AR5K_PRINT_REGISTER(TIME_OUT);
01572         AR5K_PRINT_REGISTER(RSSI_THR);
01573         AR5K_PRINT_REGISTER(BEACON);
01574         AR5K_PRINT_REGISTER(CFP_PERIOD);
01575         AR5K_PRINT_REGISTER(TIMER0);
01576         AR5K_PRINT_REGISTER(TIMER2);
01577         AR5K_PRINT_REGISTER(TIMER3);
01578         AR5K_PRINT_REGISTER(CFP_DUR);
01579         AR5K_PRINT_REGISTER(MCAST_FIL0);
01580         AR5K_PRINT_REGISTER(MCAST_FIL1);
01581         AR5K_PRINT_REGISTER(DIAG_SW);
01582         AR5K_PRINT_REGISTER(TSF_U32);
01583         AR5K_PRINT_REGISTER(ADDAC_TEST);
01584         AR5K_PRINT_REGISTER(DEFAULT_ANTENNA);
01585         AR5K_PRINT_REGISTER(LAST_TSTP);
01586         AR5K_PRINT_REGISTER(NAV);
01587         AR5K_PRINT_REGISTER(RTS_OK);
01588         AR5K_PRINT_REGISTER(ACK_FAIL);
01589         AR5K_PRINT_REGISTER(FCS_FAIL);
01590         AR5K_PRINT_REGISTER(BEACON_CNT);
01591         AR5K_PRINT_REGISTER(KEYTABLE_0);
01592         printf("\n");
01593 
01594         printf("PHY registers:\n");
01595         AR5K_PRINT_REGISTER(PHY_TURBO);
01596         AR5K_PRINT_REGISTER(PHY_AGC);
01597         AR5K_PRINT_REGISTER(PHY_CHIP_ID);
01598         AR5K_PRINT_REGISTER(PHY_AGCCTL);
01599         AR5K_PRINT_REGISTER(PHY_NF);
01600         AR5K_PRINT_REGISTER(PHY_RX_DELAY);
01601         AR5K_PRINT_REGISTER(PHY_IQ);
01602         AR5K_PRINT_REGISTER(PHY_PAPD_PROBE);
01603         AR5K_PRINT_REGISTER(PHY_FC);
01604         AR5K_PRINT_REGISTER(PHY_RADAR);
01605         AR5K_PRINT_REGISTER(PHY_ANT_SWITCH_TABLE_0);
01606         AR5K_PRINT_REGISTER(PHY_ANT_SWITCH_TABLE_1);
01607         printf("\n");
01608 #endif
01609 }
01610 
01611 HAL_BOOL
01612 ar5k_ar5211_get_diag_state(hal, id, device, size)
01613         struct ath_hal *hal;
01614         int id;
01615         void **device;
01616         u_int *size;
01617 
01618 {
01619         /*
01620          * We'll ignore this right now. This seems to be some kind of an obscure
01621          * debugging interface for the binary-only HAL.
01622          */
01623         return (AH_FALSE);
01624 }
01625 
01626 void
01627 ar5k_ar5211_get_lladdr(hal, mac)
01628         struct ath_hal *hal;
01629         u_int8_t *mac;
01630 {
01631         bcopy(hal->ah_sta_id, mac, IEEE80211_ADDR_LEN);
01632 }
01633 
01634 HAL_BOOL
01635 ar5k_ar5211_set_lladdr(hal, mac)
01636         struct ath_hal *hal;
01637         const u_int8_t *mac;
01638 {
01639         u_int32_t low_id, high_id;
01640 
01641         /* Set new station ID */
01642         bcopy(mac, hal->ah_sta_id, IEEE80211_ADDR_LEN);
01643 
01644         bcopy(mac, &low_id, 4);
01645         bcopy(mac + 4, &high_id, 2);
01646         high_id = 0x0000ffff & high_id;
01647 
01648         AR5K_REG_WRITE(AR5K_AR5211_STA_ID0, low_id);
01649         AR5K_REG_WRITE(AR5K_AR5211_STA_ID1, high_id);
01650 
01651         return (AH_TRUE);
01652 }
01653 
01654 HAL_BOOL
01655 ar5k_ar5211_set_regdomain(hal, regdomain, status)
01656         struct ath_hal *hal;
01657         u_int16_t regdomain;
01658         HAL_STATUS *status;
01659 
01660 {
01661         ieee80211_regdomain_t ieee_regdomain;
01662 
01663         ieee_regdomain = ar5k_regdomain_to_ieee(regdomain);
01664 
01665         if (ar5k_eeprom_regulation_domain(hal, AH_TRUE,
01666                 &ieee_regdomain) == AH_TRUE) {
01667                 *status = HAL_OK;
01668                 return (AH_TRUE);
01669         }
01670 
01671         *status = EIO;
01672 
01673         return (AH_FALSE);
01674 }
01675 
01676 void
01677 ar5k_ar5211_set_ledstate(hal, state)
01678         struct ath_hal *hal;
01679         HAL_LED_STATE state;
01680 {
01681         u_int32_t led;
01682 
01683         AR5K_REG_DISABLE_BITS(AR5K_AR5211_PCICFG,
01684             AR5K_AR5211_PCICFG_LEDMODE |  AR5K_AR5211_PCICFG_LED);
01685 
01686         /*
01687          * Some blinking values, define at your wish
01688          */
01689         switch (state) {
01690         case IEEE80211_S_SCAN:
01691         case IEEE80211_S_AUTH:
01692                 led = AR5K_AR5211_PCICFG_LEDMODE_PROP |
01693                     AR5K_AR5211_PCICFG_LED_PEND;
01694                 break;
01695 
01696         case IEEE80211_S_INIT:
01697                 led = AR5K_AR5211_PCICFG_LEDMODE_PROP |
01698                     AR5K_AR5211_PCICFG_LED_NONE;
01699                 break;
01700 
01701         case IEEE80211_S_ASSOC:
01702         case IEEE80211_S_RUN:
01703                 led = AR5K_AR5211_PCICFG_LEDMODE_PROP |
01704                     AR5K_AR5211_PCICFG_LED_ASSOC;
01705                 break;
01706 
01707         default:
01708                 led = AR5K_AR5211_PCICFG_LEDMODE_PROM |
01709                     AR5K_AR5211_PCICFG_LED_NONE;
01710                 break;
01711         }
01712 
01713         AR5K_REG_ENABLE_BITS(AR5K_AR5211_PCICFG, led);
01714 }
01715 
01716 void
01717 ar5k_ar5211_set_associd(hal, bssid, assoc_id, tim_offset)
01718         struct ath_hal *hal;
01719         const u_int8_t *bssid;
01720         u_int16_t assoc_id;
01721         u_int16_t tim_offset;
01722 {
01723         u_int32_t low_id, high_id;
01724 
01725         /*
01726          * Set BSSID which triggers the "SME Join" operation
01727          */
01728         bcopy(bssid, &low_id, 4);
01729         bcopy(bssid + 4, &high_id, 2);
01730         AR5K_REG_WRITE(AR5K_AR5211_BSS_ID0, low_id);
01731         AR5K_REG_WRITE(AR5K_AR5211_BSS_ID1, high_id |
01732             ((assoc_id & 0x3fff) << AR5K_AR5211_BSS_ID1_AID_S));
01733         bcopy(bssid, hal->ah_bssid, IEEE80211_ADDR_LEN);
01734 
01735         if (assoc_id == 0) {
01736                 ar5k_ar5211_disable_pspoll(hal);
01737                 return;
01738         }
01739 
01740         AR5K_REG_WRITE(AR5K_AR5211_BEACON,
01741             (AR5K_REG_READ(AR5K_AR5211_BEACON) &
01742             ~AR5K_AR5211_BEACON_TIM) |
01743             (((tim_offset ? tim_offset + 4 : 0) <<
01744             AR5K_AR5211_BEACON_TIM_S) &
01745             AR5K_AR5211_BEACON_TIM));
01746 
01747         ar5k_ar5211_enable_pspoll(hal, NULL, 0);
01748 }
01749 
01750 HAL_BOOL
01751 ar5k_ar5211_set_gpio_output(hal, gpio)
01752         struct ath_hal *hal;
01753         u_int32_t gpio;
01754 {
01755         if (gpio > AR5K_AR5211_NUM_GPIO)
01756                 return (AH_FALSE);
01757 
01758         AR5K_REG_WRITE(AR5K_AR5211_GPIOCR,
01759             (AR5K_REG_READ(AR5K_AR5211_GPIOCR) &~ AR5K_AR5211_GPIOCR_ALL(gpio))
01760             | AR5K_AR5211_GPIOCR_ALL(gpio));
01761 
01762         return (AH_TRUE);
01763 }
01764 
01765 HAL_BOOL
01766 ar5k_ar5211_set_gpio_input(hal, gpio)
01767         struct ath_hal *hal;
01768         u_int32_t gpio;
01769 {
01770         if (gpio > AR5K_AR5211_NUM_GPIO)
01771                 return (AH_FALSE);
01772 
01773         AR5K_REG_WRITE(AR5K_AR5211_GPIOCR,
01774             (AR5K_REG_READ(AR5K_AR5211_GPIOCR) &~ AR5K_AR5211_GPIOCR_ALL(gpio))
01775             | AR5K_AR5211_GPIOCR_NONE(gpio));
01776 
01777         return (AH_TRUE);
01778 }
01779 
01780 u_int32_t
01781 ar5k_ar5211_get_gpio(hal, gpio)
01782         struct ath_hal *hal;
01783         u_int32_t gpio;
01784 {
01785         if (gpio > AR5K_AR5211_NUM_GPIO)
01786                 return (0xffffffff);
01787 
01788         /* GPIO input magic */
01789         return (((AR5K_REG_READ(AR5K_AR5211_GPIODI) &
01790             AR5K_AR5211_GPIODI_M) >> gpio) & 0x1);
01791 }
01792 
01793 HAL_BOOL
01794 ar5k_ar5211_set_gpio(hal, gpio, val)
01795         struct ath_hal *hal;
01796         u_int32_t gpio;
01797         u_int32_t val;
01798 {
01799         u_int32_t data;
01800 
01801         if (gpio > AR5K_AR5211_NUM_GPIO)
01802                 return (0xffffffff);
01803 
01804         /* GPIO output magic */
01805         data =  AR5K_REG_READ(AR5K_AR5211_GPIODO);
01806 
01807         data &= ~(1 << gpio);
01808         data |= (val&1) << gpio;
01809 
01810         AR5K_REG_WRITE(AR5K_AR5211_GPIODO, data);
01811 
01812         return (AH_TRUE);
01813 }
01814 
01815 void
01816 ar5k_ar5211_set_gpio_intr(hal, gpio, interrupt_level)
01817         struct ath_hal *hal;
01818         u_int gpio;
01819         u_int32_t interrupt_level;
01820 {
01821         u_int32_t data;
01822 
01823         if (gpio > AR5K_AR5211_NUM_GPIO)
01824                 return;
01825 
01826         /*
01827          * Set the GPIO interrupt
01828          */
01829         data = (AR5K_REG_READ(AR5K_AR5211_GPIOCR) &
01830             ~(AR5K_AR5211_GPIOCR_INT_SEL(gpio) | AR5K_AR5211_GPIOCR_INT_SELH |
01831             AR5K_AR5211_GPIOCR_INT_ENA | AR5K_AR5211_GPIOCR_ALL(gpio))) |
01832             (AR5K_AR5211_GPIOCR_INT_SEL(gpio) | AR5K_AR5211_GPIOCR_INT_ENA);
01833 
01834         AR5K_REG_WRITE(AR5K_AR5211_GPIOCR,
01835             interrupt_level ? data : (data | AR5K_AR5211_GPIOCR_INT_SELH));
01836 
01837         hal->ah_imr |= AR5K_AR5211_PIMR_GPIO;
01838 
01839         /* Enable GPIO interrupts */
01840         AR5K_REG_ENABLE_BITS(AR5K_AR5211_PIMR, AR5K_AR5211_PIMR_GPIO);
01841 }
01842 
01843 u_int32_t
01844 ar5k_ar5211_get_tsf32(hal)
01845         struct ath_hal *hal;
01846 {
01847         return (AR5K_REG_READ(AR5K_AR5211_TSF_L32));
01848 }
01849 
01850 u_int64_t
01851 ar5k_ar5211_get_tsf64(hal)
01852         struct ath_hal *hal;
01853 {
01854         u_int64_t tsf = AR5K_REG_READ(AR5K_AR5211_TSF_U32);
01855 
01856         return (AR5K_REG_READ(AR5K_AR5211_TSF_L32) | (tsf << 32));
01857 }
01858 
01859 void
01860 ar5k_ar5211_reset_tsf(hal)
01861         struct ath_hal *hal;
01862 {
01863         AR5K_REG_ENABLE_BITS(AR5K_AR5211_BEACON,
01864             AR5K_AR5211_BEACON_RESET_TSF);
01865 }
01866 
01867 u_int16_t
01868 ar5k_ar5211_get_regdomain(hal)
01869         struct ath_hal *hal;
01870 {
01871         return (ar5k_get_regdomain(hal));
01872 }
01873 
01874 HAL_BOOL
01875 ar5k_ar5211_detect_card_present(hal)
01876         struct ath_hal *hal;
01877 {
01878         u_int16_t magic;
01879 
01880         /*
01881          * Checking the EEPROM's magic value could be an indication
01882          * if the card is still present. I didn't find another suitable
01883          * way to do this.
01884          */
01885         if (ar5k_ar5211_eeprom_read(hal, AR5K_EEPROM_MAGIC, &magic) != 0)
01886                 return (AH_FALSE);
01887 
01888         return (magic == AR5K_EEPROM_MAGIC_VALUE ? AH_TRUE : AH_FALSE);
01889 }
01890 
01891 void
01892 ar5k_ar5211_update_mib_counters(hal, statistics)
01893         struct ath_hal *hal;
01894         HAL_MIB_STATS *statistics;
01895 {
01896         statistics->ackrcv_bad += AR5K_REG_READ(AR5K_AR5211_ACK_FAIL);
01897         statistics->rts_bad += AR5K_REG_READ(AR5K_AR5211_RTS_FAIL);
01898         statistics->rts_good += AR5K_REG_READ(AR5K_AR5211_RTS_OK);
01899         statistics->fcs_bad += AR5K_REG_READ(AR5K_AR5211_FCS_FAIL);
01900         statistics->beacons += AR5K_REG_READ(AR5K_AR5211_BEACON_CNT);
01901 }
01902 
01903 HAL_RFGAIN
01904 ar5k_ar5211_get_rf_gain(hal)
01905         struct ath_hal *hal;
01906 {
01907         return (HAL_RFGAIN_INACTIVE);
01908 }
01909 
01910 HAL_BOOL
01911 ar5k_ar5211_set_slot_time(hal, slot_time)
01912         struct ath_hal *hal;
01913         u_int slot_time;
01914 {
01915         if (slot_time < HAL_SLOT_TIME_9 || slot_time > HAL_SLOT_TIME_MAX)
01916                 return (AH_FALSE);
01917 
01918         AR5K_REG_WRITE(AR5K_AR5211_DCU_GBL_IFS_SLOT, slot_time);
01919 
01920         return (AH_TRUE);
01921 }
01922 
01923 u_int
01924 ar5k_ar5211_get_slot_time(hal)
01925         struct ath_hal *hal;
01926 {
01927         return (AR5K_REG_READ(AR5K_AR5211_DCU_GBL_IFS_SLOT) & 0xffff);
01928 }
01929 
01930 HAL_BOOL
01931 ar5k_ar5211_set_ack_timeout(hal, timeout)
01932         struct ath_hal *hal;
01933         u_int timeout;
01934 {
01935         if (ar5k_clocktoh(AR5K_REG_MS(0xffffffff, AR5K_AR5211_TIME_OUT_ACK),
01936             hal->ah_turbo) <= timeout)
01937                 return (AH_FALSE);
01938 
01939         AR5K_REG_WRITE_BITS(AR5K_AR5211_TIME_OUT, AR5K_AR5211_TIME_OUT_ACK,
01940             ar5k_htoclock(timeout, hal->ah_turbo));
01941 
01942         return (AH_TRUE);
01943 }
01944 
01945 u_int
01946 ar5k_ar5211_get_ack_timeout(hal)
01947         struct ath_hal *hal;
01948 {
01949         return (ar5k_clocktoh(AR5K_REG_MS(AR5K_REG_READ(AR5K_AR5211_TIME_OUT),
01950             AR5K_AR5211_TIME_OUT_ACK), hal->ah_turbo));
01951 }
01952 
01953 HAL_BOOL
01954 ar5k_ar5211_set_cts_timeout(hal, timeout)
01955         struct ath_hal *hal;
01956         u_int timeout;
01957 {
01958         if (ar5k_clocktoh(AR5K_REG_MS(0xffffffff, AR5K_AR5211_TIME_OUT_CTS),
01959             hal->ah_turbo) <= timeout)
01960                 return (AH_FALSE);
01961 
01962         AR5K_REG_WRITE_BITS(AR5K_AR5211_TIME_OUT, AR5K_AR5211_TIME_OUT_CTS,
01963             ar5k_htoclock(timeout, hal->ah_turbo));
01964 
01965         return (AH_TRUE);
01966 }
01967 
01968 u_int
01969 ar5k_ar5211_get_cts_timeout(hal)
01970         struct ath_hal *hal;
01971 {
01972         return (ar5k_clocktoh(AR5K_REG_MS(AR5K_REG_READ(AR5K_AR5211_TIME_OUT),
01973             AR5K_AR5211_TIME_OUT_CTS), hal->ah_turbo));
01974 }
01975 
01976 /*
01977  * Key table (WEP) functions
01978  */
01979 
01980 HAL_BOOL
01981 ar5k_ar5211_is_cipher_supported(hal, cipher)
01982         struct ath_hal *hal;
01983         HAL_CIPHER cipher;
01984 {
01985         /*
01986          * The AR5211 only supports WEP
01987          */
01988         if (cipher == HAL_CIPHER_WEP)
01989                 return (AH_TRUE);
01990 
01991         return (AH_FALSE);
01992 }
01993 
01994 u_int32_t
01995 ar5k_ar5211_get_keycache_size(hal)
01996         struct ath_hal *hal;
01997 {
01998         return (AR5K_AR5211_KEYCACHE_SIZE);
01999 }
02000 
02001 HAL_BOOL
02002 ar5k_ar5211_reset_key(hal, entry)
02003         struct ath_hal *hal;
02004         u_int16_t entry;
02005 {
02006         int i;
02007 
02008         AR5K_ASSERT_ENTRY(entry, AR5K_AR5211_KEYTABLE_SIZE);
02009 
02010         for (i = 0; i < AR5K_AR5211_KEYCACHE_SIZE; i++)
02011                 AR5K_REG_WRITE(AR5K_AR5211_KEYTABLE_OFF(entry, i), 0);
02012 
02013         return (AH_FALSE);
02014 }
02015 
02016 HAL_BOOL
02017 ar5k_ar5211_is_key_valid(hal, entry)
02018         struct ath_hal *hal;
02019         u_int16_t entry;
02020 {
02021         AR5K_ASSERT_ENTRY(entry, AR5K_AR5211_KEYTABLE_SIZE);
02022 
02023         /*
02024          * Check the validation flag at the end of the entry
02025          */
02026         if (AR5K_REG_READ(AR5K_AR5211_KEYTABLE_MAC1(entry)) &
02027             AR5K_AR5211_KEYTABLE_VALID)
02028                 return (AH_TRUE);
02029 
02030         return (AH_FALSE);
02031 }
02032 
02033 HAL_BOOL
02034 ar5k_ar5211_set_key(hal, entry, keyval, mac, xor_notused)
02035         struct ath_hal *hal;
02036         u_int16_t entry;
02037         const HAL_KEYVAL *keyval;
02038         const u_int8_t *mac;
02039         int xor_notused;
02040 {
02041         int i;
02042         u_int32_t key_v[AR5K_AR5211_KEYCACHE_SIZE - 2];
02043 
02044         AR5K_ASSERT_ENTRY(entry, AR5K_AR5211_KEYTABLE_SIZE);
02045 
02046         bzero(&key_v, sizeof(key_v));
02047 
02048         switch (keyval->wk_len) {
02049         case AR5K_KEYVAL_LENGTH_40:
02050                 bcopy(keyval->wk_key, &key_v[0], 4);
02051                 bcopy(keyval->wk_key + 4, &key_v[1], 1);
02052                 key_v[5] = AR5K_AR5211_KEYTABLE_TYPE_40;
02053                 break;
02054 
02055         case AR5K_KEYVAL_LENGTH_104:
02056                 bcopy(keyval->wk_key, &key_v[0], 4);
02057                 bcopy(keyval->wk_key + 4, &key_v[1], 2);
02058                 bcopy(keyval->wk_key + 6, &key_v[2], 4);
02059                 bcopy(keyval->wk_key + 10, &key_v[3], 2);
02060                 bcopy(keyval->wk_key + 12, &key_v[4], 1);
02061                 key_v[5] = AR5K_AR5211_KEYTABLE_TYPE_104;
02062                 break;
02063 
02064         case AR5K_KEYVAL_LENGTH_128:
02065                 bcopy(keyval->wk_key, &key_v[0], 4);
02066                 bcopy(keyval->wk_key + 4, &key_v[1], 2);
02067                 bcopy(keyval->wk_key + 6, &key_v[2], 4);
02068                 bcopy(keyval->wk_key + 10, &key_v[3], 2);
02069                 bcopy(keyval->wk_key + 12, &key_v[4], 4);
02070                 key_v[5] = AR5K_AR5211_KEYTABLE_TYPE_128;
02071                 break;
02072 
02073         default:
02074                 /* Unsupported key length (not WEP40/104/128) */
02075                 return (AH_FALSE);
02076         }
02077 
02078         for (i = 0; i < AR5K_ELEMENTS(key_v); i++)
02079                 AR5K_REG_WRITE(AR5K_AR5211_KEYTABLE_OFF(entry, i), key_v[i]);
02080 
02081         return (ar5k_ar5211_set_key_lladdr(hal, entry, mac));
02082 }
02083 
02084 HAL_BOOL
02085 ar5k_ar5211_set_key_lladdr(hal, entry, mac)
02086         struct ath_hal *hal;
02087         u_int16_t entry;
02088         const u_int8_t *mac;
02089 {
02090         u_int32_t low_id, high_id;
02091         const u_int8_t *mac_v;
02092 
02093         /*
02094          * Invalid entry (key table overflow)
02095          */
02096         AR5K_ASSERT_ENTRY(entry, AR5K_AR5211_KEYTABLE_SIZE);
02097 
02098         /* MAC may be NULL if it's a broadcast key */
02099         mac_v = mac == NULL ? etherbroadcastaddr : mac;
02100 
02101         bcopy(mac_v, &low_id, 4);
02102         bcopy(mac_v + 4, &high_id, 2);
02103         high_id |= AR5K_AR5211_KEYTABLE_VALID;
02104 
02105         AR5K_REG_WRITE(AR5K_AR5211_KEYTABLE_MAC0(entry), low_id);
02106         AR5K_REG_WRITE(AR5K_AR5211_KEYTABLE_MAC1(entry), high_id);
02107 
02108         return (AH_TRUE);
02109 }
02110 
02111 /*
02112  * Power management functions
02113  */
02114 
02115 HAL_BOOL
02116 ar5k_ar5211_set_power(hal, mode, set_chip, sleep_duration)
02117         struct ath_hal *hal;
02118         HAL_POWER_MODE mode;
02119         HAL_BOOL set_chip;
02120         u_int16_t sleep_duration;
02121 {
02122         u_int32_t staid;
02123         int i;
02124 
02125         staid = AR5K_REG_READ(AR5K_AR5211_STA_ID1);
02126 
02127         switch (mode) {
02128         case HAL_PM_AUTO:
02129                 staid &= ~AR5K_AR5211_STA_ID1_DEFAULT_ANTENNA;
02130                 /* fallthrough */
02131         case HAL_PM_NETWORK_SLEEP:
02132                 if (set_chip == AH_TRUE) {
02133                         AR5K_REG_WRITE(AR5K_AR5211_SCR,
02134                             AR5K_AR5211_SCR_SLE | sleep_duration);
02135                 }
02136                 staid |= AR5K_AR5211_STA_ID1_PWR_SV;
02137                 break;
02138 
02139         case HAL_PM_FULL_SLEEP:
02140                 if (set_chip == AH_TRUE) {
02141                         AR5K_REG_WRITE(AR5K_AR5211_SCR,
02142                             AR5K_AR5211_SCR_SLE_SLP);
02143                 }
02144                 staid |= AR5K_AR5211_STA_ID1_PWR_SV;
02145                 break;
02146 
02147         case HAL_PM_AWAKE:
02148                 if (set_chip == AH_FALSE)
02149                         goto commit;
02150 
02151                 AR5K_REG_WRITE(AR5K_AR5211_SCR, AR5K_AR5211_SCR_SLE_WAKE);
02152 
02153                 for (i = 5000; i > 0; i--) {
02154                         /* Check if the AR5211 did wake up */
02155                         if ((AR5K_REG_READ(AR5K_AR5211_PCICFG) &
02156                             AR5K_AR5211_PCICFG_SPWR_DN) == 0)
02157                                 break;
02158 
02159                         /* Wait a bit and retry */
02160                         AR5K_DELAY(200);
02161                         AR5K_REG_WRITE(AR5K_AR5211_SCR,
02162                             AR5K_AR5211_SCR_SLE_WAKE);
02163                 }
02164 
02165                 /* Fail if the AR5211 didn't wake up */
02166                 if (i <= 0)
02167                         return (AH_FALSE);
02168                 
02169                 staid &= ~AR5K_AR5211_STA_ID1_PWR_SV;
02170                 break;
02171 
02172         default:
02173                 return (AH_FALSE);
02174         }
02175 
02176  commit:
02177         hal->ah_power_mode = mode;
02178 
02179         AR5K_REG_WRITE(AR5K_AR5211_STA_ID1, staid);
02180 
02181         return (AH_TRUE);
02182 }
02183 
02184 HAL_POWER_MODE
02185 ar5k_ar5211_get_power_mode(hal)
02186         struct ath_hal *hal;
02187 {
02188         return (hal->ah_power_mode);
02189 }
02190 
02191 HAL_BOOL
02192 ar5k_ar5211_query_pspoll_support(hal)
02193         struct ath_hal *hal;
02194 {
02195         /* nope */
02196         return (AH_FALSE);
02197 }
02198 
02199 HAL_BOOL
02200 ar5k_ar5211_init_pspoll(hal)
02201         struct ath_hal *hal;
02202 {
02203         /*
02204          * Not used on the AR5211
02205          */
02206         return (AH_FALSE);
02207 }
02208 
02209 HAL_BOOL
02210 ar5k_ar5211_enable_pspoll(hal, bssid, assoc_id)
02211         struct ath_hal *hal;
02212         u_int8_t *bssid;
02213         u_int16_t assoc_id;
02214 {
02215         return (AH_FALSE);
02216 }
02217 
02218 HAL_BOOL
02219 ar5k_ar5211_disable_pspoll(hal)
02220         struct ath_hal *hal;
02221 {
02222         return (AH_FALSE);
02223 }
02224 
02225 /*
02226  * Beacon functions
02227  */
02228 
02229 void
02230 ar5k_ar5211_init_beacon(hal, next_beacon, interval)
02231         struct ath_hal *hal;
02232         u_int32_t next_beacon;
02233         u_int32_t interval;
02234 {
02235         u_int32_t timer1, timer2, timer3;
02236 
02237         /*
02238          * Set the additional timers by mode
02239          */
02240         switch (hal->ah_op_mode) {
02241         case HAL_M_STA:
02242                 timer1 = 0x0000ffff;
02243                 timer2 = 0x0007ffff;
02244                 break;
02245 
02246         default:
02247                 timer1 = (next_beacon - AR5K_TUNE_DMA_BEACON_RESP) <<
02248                     0x00000003;
02249                 timer2 = (next_beacon - AR5K_TUNE_SW_BEACON_RESP) <<
02250                     0x00000003;
02251         }
02252 
02253         timer3 = next_beacon +
02254             (hal->ah_atim_window ? hal->ah_atim_window : 1);
02255 
02256         /*
02257          * Enable all timers and set the beacon register
02258          * (next beacon, DMA beacon, software beacon, ATIM window time)
02259          */
02260         AR5K_REG_WRITE(AR5K_AR5211_TIMER0, next_beacon);
02261         AR5K_REG_WRITE(AR5K_AR5211_TIMER1, timer1);
02262         AR5K_REG_WRITE(AR5K_AR5211_TIMER2, timer2);
02263         AR5K_REG_WRITE(AR5K_AR5211_TIMER3, timer3);
02264 
02265         AR5K_REG_WRITE(AR5K_AR5211_BEACON, interval &
02266             (AR5K_AR5211_BEACON_PERIOD | AR5K_AR5211_BEACON_RESET_TSF |
02267             AR5K_AR5211_BEACON_ENABLE));
02268 }
02269 
02270 void
02271 ar5k_ar5211_set_beacon_timers(hal, state, tsf, dtim_count, cfp_count)
02272         struct ath_hal *hal;
02273         const HAL_BEACON_STATE *state;
02274         u_int32_t tsf;
02275         u_int32_t dtim_count;
02276         u_int32_t cfp_count;
02277 
02278 {
02279         u_int32_t cfp_period, next_cfp;
02280 
02281         /* Return on an invalid beacon state */
02282         if (state->bs_interval < 1)
02283                 return;
02284 
02285         /*
02286          * PCF support?
02287          */
02288         if (state->bs_cfp_period > 0) {
02289                 /* Enable CFP mode and set the CFP and timer registers */
02290                 cfp_period = state->bs_cfp_period * state->bs_dtim_period *
02291                     state->bs_interval;
02292                 next_cfp = (cfp_count * state->bs_dtim_period + dtim_count) *
02293                     state->bs_interval;
02294 
02295                 AR5K_REG_DISABLE_BITS(AR5K_AR5211_STA_ID1,
02296                     AR5K_AR5211_STA_ID1_DEFAULT_ANTENNA |
02297                     AR5K_AR5211_STA_ID1_PCF);
02298                 AR5K_REG_WRITE(AR5K_AR5211_CFP_PERIOD, cfp_period);
02299                 AR5K_REG_WRITE(AR5K_AR5211_CFP_DUR, state->bs_cfp_max_duration);
02300                 AR5K_REG_WRITE(AR5K_AR5211_TIMER2,
02301                     (tsf + (next_cfp == 0 ? cfp_period : next_cfp)) << 3);
02302         } else {
02303                 /* Disable PCF mode */
02304                 AR5K_REG_DISABLE_BITS(AR5K_AR5211_STA_ID1,
02305                     AR5K_AR5211_STA_ID1_DEFAULT_ANTENNA |
02306                     AR5K_AR5211_STA_ID1_PCF);
02307         }
02308 
02309         /*
02310          * Enable the beacon timer register
02311          */
02312         AR5K_REG_WRITE(AR5K_AR5211_TIMER0, state->bs_next_beacon);
02313 
02314         /*
02315          * Start the beacon timers
02316          */
02317         AR5K_REG_WRITE(AR5K_AR5211_BEACON,
02318             (AR5K_REG_READ(AR5K_AR5211_BEACON) &~
02319             (AR5K_AR5211_BEACON_PERIOD | AR5K_AR5211_BEACON_TIM)) |
02320             AR5K_REG_SM(state->bs_tim_offset ? state->bs_tim_offset + 4 : 0,
02321             AR5K_AR5211_BEACON_TIM) | AR5K_REG_SM(state->bs_interval,
02322             AR5K_AR5211_BEACON_PERIOD));
02323 
02324         /*
02325          * Write new beacon miss threshold, if it appears to be valid
02326          */
02327         if ((AR5K_AR5211_RSSI_THR_BMISS >> AR5K_AR5211_RSSI_THR_BMISS_S) <
02328             state->bs_bmiss_threshold)
02329                 return;
02330 
02331         AR5K_REG_WRITE_BITS(AR5K_AR5211_RSSI_THR_M,
02332             AR5K_AR5211_RSSI_THR_BMISS, state->bs_bmiss_threshold);
02333         AR5K_REG_WRITE_BITS(AR5K_AR5211_SCR, AR5K_AR5211_SCR_SLDUR,
02334             (state->bs_sleepduration - 3) << 3);
02335 }
02336 
02337 void
02338 ar5k_ar5211_reset_beacon(hal)
02339         struct ath_hal *hal;
02340 {
02341         /*
02342          * Disable beacon timer
02343          */
02344         AR5K_REG_WRITE(AR5K_AR5211_TIMER0, 0);
02345 
02346         /*
02347          * Disable some beacon register values
02348          */
02349         AR5K_REG_DISABLE_BITS(AR5K_AR5211_STA_ID1,
02350             AR5K_AR5211_STA_ID1_DEFAULT_ANTENNA | AR5K_AR5211_STA_ID1_PCF);
02351         AR5K_REG_WRITE(AR5K_AR5211_BEACON, AR5K_AR5211_BEACON_PERIOD);
02352 }
02353 
02354 HAL_BOOL
02355 ar5k_ar5211_wait_for_beacon(hal, phys_addr)
02356         struct ath_hal *hal;
02357         bus_addr_t phys_addr;
02358 {
02359         HAL_BOOL ret;
02360 
02361         /*
02362          * Wait for beaconn queue to be done
02363          */
02364         ret = ar5k_register_timeout(hal,
02365             AR5K_AR5211_QCU_STS(HAL_TX_QUEUE_ID_BEACON),
02366             AR5K_AR5211_QCU_STS_FRMPENDCNT, 0, AH_FALSE);
02367 
02368         if (AR5K_REG_READ_Q(AR5K_AR5211_QCU_TXE, HAL_TX_QUEUE_ID_BEACON))
02369                 return (AH_FALSE);
02370 
02371         return (ret);
02372 }
02373 
02374 /*
02375  * Interrupt handling
02376  */
02377 
02378 HAL_BOOL
02379 ar5k_ar5211_is_intr_pending(hal)
02380         struct ath_hal *hal;
02381 {
02382         return (AR5K_REG_READ(AR5K_AR5211_INTPEND) == 0 ? AH_FALSE : AH_TRUE);
02383 }
02384 
02385 HAL_BOOL
02386 ar5k_ar5211_get_isr(hal, interrupt_mask)
02387         struct ath_hal *hal;
02388         u_int32_t *interrupt_mask;
02389 {
02390         u_int32_t data;
02391 
02392         /*
02393          * Read interrupt status from the Read-And-Clear shadow register
02394          */
02395         data = AR5K_REG_READ(AR5K_AR5211_RAC_PISR);
02396 
02397         /*
02398          * Get abstract interrupt mask (HAL-compatible)
02399          */
02400         *interrupt_mask = (data & HAL_INT_COMMON) & hal->ah_imr;
02401 
02402         if (data == HAL_INT_NOCARD)
02403                 return (AH_FALSE);
02404 
02405         if (data & (AR5K_AR5211_PISR_RXOK | AR5K_AR5211_PISR_RXERR))
02406                 *interrupt_mask |= HAL_INT_RX;
02407 
02408         if (data & (AR5K_AR5211_PISR_TXOK | AR5K_AR5211_PISR_TXERR))
02409                 *interrupt_mask |= HAL_INT_TX;
02410 
02411         if (data & (AR5K_AR5211_PISR_HIUERR))
02412                 *interrupt_mask |= HAL_INT_FATAL;
02413 
02414         /*
02415          * Special interrupt handling (not catched by the driver)
02416          */
02417         if (((*interrupt_mask) & AR5K_AR5211_PISR_RXPHY) &&
02418             hal->ah_radar.r_enabled == AH_TRUE)
02419                 ar5k_radar_alert(hal);
02420 
02421         return (AH_TRUE);
02422 }
02423 
02424 u_int32_t
02425 ar5k_ar5211_get_intr(hal)
02426         struct ath_hal *hal;
02427 {
02428         /* Return the interrupt mask stored previously */
02429         return (hal->ah_imr);
02430 }
02431 
02432 HAL_INT
02433 ar5k_ar5211_set_intr(hal, new_mask)
02434         struct ath_hal *hal;
02435         HAL_INT new_mask;
02436 {
02437         HAL_INT old_mask, int_mask;
02438 
02439         /*
02440          * Disable card interrupts to prevent any race conditions
02441          * (they will be re-enabled afterwards).
02442          */
02443         AR5K_REG_WRITE(AR5K_AR5211_IER, AR5K_AR5211_IER_DISABLE);
02444 
02445         old_mask = hal->ah_imr;
02446 
02447         /*
02448          * Add additional, chipset-dependent interrupt mask flags
02449          * and write them to the IMR (interrupt mask register).
02450          */
02451         int_mask = new_mask & HAL_INT_COMMON;
02452 
02453         if (new_mask & HAL_INT_RX)
02454                 int_mask |=
02455                     AR5K_AR5211_PIMR_RXOK |
02456                     AR5K_AR5211_PIMR_RXERR |
02457                     AR5K_AR5211_PIMR_RXORN |
02458                     AR5K_AR5211_PIMR_RXDESC;
02459 
02460         if (new_mask & HAL_INT_TX)
02461                 int_mask |=
02462                     AR5K_AR5211_PIMR_TXOK |
02463                     AR5K_AR5211_PIMR_TXERR |
02464                     AR5K_AR5211_PIMR_TXDESC |
02465                     AR5K_AR5211_PIMR_TXURN;
02466 
02467         if (new_mask & HAL_INT_FATAL) {
02468                 int_mask |= AR5K_AR5211_PIMR_HIUERR;
02469                 AR5K_REG_ENABLE_BITS(AR5K_AR5211_SIMR2,
02470                     AR5K_AR5211_SIMR2_MCABT |
02471                     AR5K_AR5211_SIMR2_SSERR |
02472                     AR5K_AR5211_SIMR2_DPERR);
02473         }
02474 
02475         AR5K_REG_WRITE(AR5K_AR5211_PIMR, int_mask);
02476 
02477         /* Store new interrupt mask */
02478         hal->ah_imr = new_mask;
02479 
02480         /* ..re-enable interrupts */
02481         AR5K_REG_WRITE(AR5K_AR5211_IER, AR5K_AR5211_IER_ENABLE);
02482 
02483         return (old_mask);
02484 }
02485 
02486 /*
02487  * Misc internal functions
02488  */
02489 
02490 HAL_BOOL
02491 ar5k_ar5211_get_capabilities(hal)
02492         struct ath_hal *hal;
02493 {
02494         u_int16_t ee_header;
02495 
02496         /* Capabilities stored in the EEPROM */
02497         ee_header = hal->ah_capabilities.cap_eeprom.ee_header;
02498 
02499         /*
02500          * XXX The AR5211 tranceiver supports frequencies from 4920 to 6100GHz
02501          * XXX and from 2312 to 2732GHz. There are problems with the current
02502          * XXX ieee80211 implementation because the IEEE channel mapping
02503          * XXX does not support negative channel numbers (2312MHz is channel
02504          * XXX -19). Of course, this doesn't matter because these channels
02505          * XXX are out of range but some regulation domains like MKK (Japan)
02506          * XXX will support frequencies somewhere around 4.8GHz.
02507          */
02508 
02509         /*
02510          * Set radio capabilities
02511          */
02512 
02513         if (AR5K_EEPROM_HDR_11A(ee_header)) {
02514                 hal->ah_capabilities.cap_range.range_5ghz_min = 5005; /* 4920 */
02515                 hal->ah_capabilities.cap_range.range_5ghz_max = 6100;
02516 
02517                 /* Set supported modes */
02518                 hal->ah_capabilities.cap_mode = HAL_MODE_11A | HAL_MODE_TURBO;
02519         }
02520 
02521         /* This chip will support 802.11b if the 2GHz radio is connected */
02522         if (AR5K_EEPROM_HDR_11B(ee_header) || AR5K_EEPROM_HDR_11G(ee_header)) {
02523                 hal->ah_capabilities.cap_range.range_2ghz_min = 2412; /* 2312 */
02524                 hal->ah_capabilities.cap_range.range_2ghz_max = 2732;
02525                 hal->ah_capabilities.cap_mode |= HAL_MODE_11B;
02526 
02527                 if (AR5K_EEPROM_HDR_11B(ee_header))
02528                         hal->ah_capabilities.cap_mode |= HAL_MODE_11B;
02529                 if (AR5K_EEPROM_HDR_11G(ee_header))
02530                         hal->ah_capabilities.cap_mode |= HAL_MODE_11G;
02531         }
02532 
02533         /* GPIO */
02534         hal->ah_gpio_npins = AR5K_AR5211_NUM_GPIO;
02535 
02536         /* Set number of supported TX queues */
02537         hal->ah_capabilities.cap_queues.q_tx_num = AR5K_AR5211_TX_NUM_QUEUES;
02538 
02539         return (AH_TRUE);
02540 }
02541 
02542 void
02543 ar5k_ar5211_radar_alert(hal, enable)
02544         struct ath_hal *hal;
02545         HAL_BOOL enable;
02546 {
02547         /*
02548          * Enable radar detection
02549          */
02550         AR5K_REG_WRITE(AR5K_AR5211_IER, AR5K_AR5211_IER_DISABLE);
02551 
02552         if (enable == AH_TRUE) {
02553                 AR5K_REG_WRITE(AR5K_AR5211_PHY_RADAR,
02554                     AR5K_AR5211_PHY_RADAR_ENABLE);
02555                 AR5K_REG_ENABLE_BITS(AR5K_AR5211_PIMR,
02556                     AR5K_AR5211_PIMR_RXPHY);
02557         } else {
02558                 AR5K_REG_WRITE(AR5K_AR5211_PHY_RADAR,
02559                     AR5K_AR5211_PHY_RADAR_DISABLE);
02560                 AR5K_REG_DISABLE_BITS(AR5K_AR5211_PIMR,
02561                     AR5K_AR5211_PIMR_RXPHY);
02562         }
02563 
02564         AR5K_REG_WRITE(AR5K_AR5211_IER, AR5K_AR5211_IER_ENABLE);
02565 }
02566 
02567 /*
02568  * EEPROM access functions
02569  */
02570 
02571 HAL_BOOL
02572 ar5k_ar5211_eeprom_is_busy(hal)
02573         struct ath_hal *hal;
02574 {
02575         return (AR5K_REG_READ(AR5K_AR5211_CFG) & AR5K_AR5211_CFG_EEBS ?
02576             AH_TRUE : AH_FALSE);
02577 }
02578 
02579 int
02580 ar5k_ar5211_eeprom_read(hal, offset, data)
02581         struct ath_hal *hal;
02582         u_int32_t offset;
02583         u_int16_t *data;
02584 {
02585         u_int32_t status, i;
02586 
02587         /*
02588          * Initialize EEPROM access
02589          */
02590         AR5K_REG_WRITE(AR5K_AR5211_EEPROM_BASE, (u_int8_t)offset);
02591         AR5K_REG_ENABLE_BITS(AR5K_AR5211_EEPROM_CMD,
02592             AR5K_AR5211_EEPROM_CMD_READ);
02593 
02594         for (i = AR5K_TUNE_REGISTER_TIMEOUT; i > 0; i--) {
02595                 status = AR5K_REG_READ(AR5K_AR5211_EEPROM_STATUS);
02596                 if (status & AR5K_AR5211_EEPROM_STAT_RDDONE) {
02597                         if (status & AR5K_AR5211_EEPROM_STAT_RDERR)
02598                                 return (EIO);
02599                         *data = (u_int16_t)
02600                             (AR5K_REG_READ(AR5K_AR5211_EEPROM_DATA) & 0xffff);
02601                         return (0);
02602                 }
02603                 AR5K_DELAY(15);
02604         }
02605 
02606         return (ETIMEDOUT);
02607 }
02608 
02609 int
02610 ar5k_ar5211_eeprom_write(hal, offset, data)
02611         struct ath_hal *hal;
02612         u_int32_t offset;
02613         u_int16_t data;
02614 {
02615         u_int32_t status, timeout;
02616 
02617         /* Enable eeprom access */
02618         AR5K_REG_ENABLE_BITS(AR5K_AR5211_EEPROM_CMD,
02619             AR5K_AR5211_EEPROM_CMD_RESET);
02620         AR5K_REG_ENABLE_BITS(AR5K_AR5211_EEPROM_CMD,
02621             AR5K_AR5211_EEPROM_CMD_WRITE);
02622 
02623         /*
02624          * Prime write pump
02625          */
02626         AR5K_REG_WRITE(AR5K_AR5211_EEPROM_BASE, (u_int8_t)offset - 1);
02627 
02628         for (timeout = 10000; timeout > 0; timeout--) {
02629                 AR5K_DELAY(1);
02630                 status = AR5K_REG_READ(AR5K_AR5211_EEPROM_STATUS);
02631                 if (status & AR5K_AR5211_EEPROM_STAT_WRDONE) {
02632                         if (status & AR5K_AR5211_EEPROM_STAT_WRERR)
02633                                 return (EIO);
02634                         return (0);
02635                 }
02636         }
02637 
02638         return (ETIMEDOUT);
02639 }
02640 
02641 /*
02642  * RF register settings
02643  */
02644 
02645 void
02646 ar5k_ar5211_rfregs(hal, channel, freq, ee_mode)
02647         struct ath_hal *hal;
02648         HAL_CHANNEL *channel;
02649         u_int freq, ee_mode;
02650 {
02651         struct ar5k_eeprom_info *ee = &hal->ah_capabilities.cap_eeprom;
02652         struct ar5k_ar5211_ini_rf rf[AR5K_ELEMENTS(ar5211_rf)];
02653         u_int32_t ob, db, obdb, xpds, xpdp, x_gain;
02654         u_int i;
02655 
02656         bcopy(ar5211_rf, rf, sizeof(rf));
02657         obdb = 0;
02658 
02659         if (freq == AR5K_INI_RFGAIN_2GHZ &&
02660             hal->ah_ee_version >= AR5K_EEPROM_VERSION_3_1) {
02661                 ob = ar5k_bitswap(ee->ee_ob[ee_mode][0], 3);
02662                 db = ar5k_bitswap(ee->ee_db[ee_mode][0], 3);
02663                 rf[25].rf_value[freq] =
02664                     ((ob << 6) & 0xc0) | (rf[25].rf_value[freq] & ~0xc0);
02665                 rf[26].rf_value[freq] =
02666                     (((ob >> 2) & 0x1) | ((db << 1) & 0xe)) |
02667                     (rf[26].rf_value[freq] & ~0xf);
02668         }
02669 
02670         if (freq == AR5K_INI_RFGAIN_5GHZ) {
02671                 /* For 11a and Turbo */
02672                 obdb = channel->c_channel >= 5725 ? 3 :
02673                     (channel->c_channel >= 5500 ? 2 :
02674                         (channel->c_channel >= 5260 ? 1 :
02675                             (channel->c_channel > 4000 ? 0 : -1)));
02676         }
02677 
02678         ob = ee->ee_ob[ee_mode][obdb];
02679         db = ee->ee_db[ee_mode][obdb];
02680         x_gain = ee->ee_x_gain[ee_mode];
02681         xpds = ee->ee_xpd[ee_mode];
02682         xpdp = !xpds;
02683 
02684         rf[11].rf_value[freq] = (rf[11].rf_value[freq] & ~0xc0) |
02685                 (((ar5k_bitswap(x_gain, 4) << 7) | (xpdp << 6)) & 0xc0);
02686         rf[12].rf_value[freq] = (rf[12].rf_value[freq] & ~0x7) |
02687                 ((ar5k_bitswap(x_gain, 4) >> 1) & 0x7);
02688         rf[12].rf_value[freq] = (rf[12].rf_value[freq] & ~0x80) |
02689                 ((ar5k_bitswap(ob, 3) << 7) & 0x80);
02690         rf[13].rf_value[freq] = (rf[13].rf_value[freq] & ~0x3) |
02691                 ((ar5k_bitswap(ob, 3) >> 1) & 0x3);
02692         rf[13].rf_value[freq] = (rf[13].rf_value[freq] & ~0x1c) |
02693                 ((ar5k_bitswap(db, 3) << 2) & 0x1c);
02694         rf[17].rf_value[freq] = (rf[17].rf_value[freq] & ~0x8) |
02695                 ((xpds << 3) & 0x8);
02696 
02697         for (i = 0; i < AR5K_ELEMENTS(rf); i++) {
02698                 AR5K_REG_WAIT(i);
02699                 AR5K_REG_WRITE((u_int32_t)rf[i].rf_register,
02700                     rf[i].rf_value[freq]);
02701         }       
02702 
02703         hal->ah_rf_gain = HAL_RFGAIN_INACTIVE;
02704 }

Generated on Mon Nov 21 15:58:10 2005 for openwifi by  doxygen 1.4.1