1Some usual/frequent control trick over the openwifi FPGA. You need to do these controls on board in the openwifi directory. 2 3[[CCA LBT threshold and disable](#CCA-LBT-threshold-and-disable)] 4[[Retransmission and ACK tx control](#Retransmission-and-ACK-tx-control)] 5[[NAV DIFS EIFS CW disable and enable](#NAV-DIFS-EIFS-CW-disable-and-enable)] 6[[CW max and min config](#CW-max-and-min-config)] 7 8[[Rx gain config](#Rx-gain-config)] 9[[Tx power config](#Tx-power-config)] 10[[Tx Lo and port config](#Tx-Lo-and-port-config)] 11[[Antenna selection](#Antenna-selection)] 12[[Restrict the frequency](#Restrict-the-frequency)] 13 14[[Tx rate config](#Tx-rate-config)] 15[[Arbiturary Tx IQ sample](#Arbiturary-Tx-IQ-sample)] 16 17## CCA LBT threshold and disable 18 19In normal operation, different threshold is set to FPGA according to the different calibration of different frequency/channel by driver automatically. Show the current LBT threshold in FPGA: 20``` 21./set_lbt_th.sh 22``` 23"reg val: 00000086" means the current threshold is 134 (86 in Hex). 24 25Override a new threshold to FPGA, for example 4dB higher than 134, the new value should be 134 + 4*2 = 142 (1 means 0.5dB, so 4dB higher needs adding 8) 26``` 27./set_lbt_th.sh 142 28``` 29Above will disable the automatic CCA threshold setting from the openwifi driver. 30 31Recover the driver automatic control on the threshold: 32``` 33./set_lbt_th.sh 0 34``` 35Disable the CCA by setting a maximum threshold 2047: 36``` 37./set_lbt_th.sh 2047 38``` 39After above command, the CCA engine will always believe the channel is idle. 40 41## Retransmission and ACK tx control 42 43The best way of override the maximum number of re-transmission for a Tx packet is doing it in the driver openwifi_tx() function. 44``` 45retry_limit_hw_value = ( retry_limit_raw==0?0:((retry_limit_raw - 1)&0xF) ); 46``` 47Override retry_limit_hw_value to 0 to disable re-transmission. Override it to 1 means that let FPGA do maximum 1 time re-transmission. 48 49The FPGA also has a register to override the re-transmission and ACK behavior. Check the current register value. 50``` 51./sdrctl dev sdr0 get reg xpu 11 52``` 53When operate this register, make sure you only change the relevant bits and leave other bits untouched, because other bits have other purposes. 54 55To override the maximum number of re-transmission, set bit3 to 1, and set the value (0 ~ 7) to bit2 ~ 0. Example, override the maximum number of re-transmission to 1 56``` 57./sdrctl dev sdr0 set reg xpu 11 9 58``` 59 609 in binary form is 01001. 61 62To disable the ACK TX after receive a packet, set bit4 to 1. (Assume we want to preserve the above re-transmission overriding setting) 63``` 64./sdrctl dev sdr0 set reg xpu 11 25 65``` 66 6725 in binary form is 11001. the 1001 of bit3 to 1 is untouched. 68 69Disabling ACK TX might be useful for monitor mode and packet injection. 70 71## NAV DIFS EIFS CW disable and enable 72 73To check the current NAV/DIFS/EIFS/CW disable status, just run 74``` 75./nav_disable.sh 76./difs_disable.sh 77./eifs_disable.sh 78./cw_disable.sh 79``` 80If NAV is disabled, the openwifi will always assume the NAV (Network Allocation Vector) is already counting down to 0. If DIFS/EIFS is disabled, when the CSMA engine needs to wait for DIFS/EIFS, it won't wait anymore. If CW is disabled, the contention window is fixed to 0, and there won't be any number of slots for random backoff procedure. To disable them, just input 1 as the script argument. 81``` 82./nav_disable.sh 1 83./difs_disable.sh 1 84./eifs_disable.sh 1 85./cw_disable.sh 1 86``` 87To enable them, just input 0 as the script argument. 88``` 89./nav_disable.sh 0 90./difs_disable.sh 0 91./eifs_disable.sh 0 92./cw_disable.sh 0 93``` 94 95## CW max and min config 96 97When the openwifi NIC bring up (as AP/Client/ad-hoc/etc), Linux will configure the CW (Contention Window) max and min value for FPGA queue 3 ~ 0 via openwifi_conf_tx() in the openwifi driver. You can check the current CW configuration in FPGA (set by Linux). 98``` 99./cw_max_min_cfg.sh 100``` 101It will show sth like 102``` 103FPGA cw max min for q3 to q0: 1023 15; 63 15; 15 7; 7 3 104FPGA cw max min for q3 to q0: a4644332 105``` 106The CW max and min for q3 ~ 0 are a4, 64, 43, 32 (in hex). Example explanation for q3: in hex the configuration is a4, which means 10 and 4 in the logarithmic domain, (2^10)-1=1023 and (2^4)-1=15 in the linear domain. 107 108To override the CW max and min for queue 3 ~ 0, for example 2047 31; 63 31; 15 7; 7 3, just map it to a hex string b5654332 for queue 3 ~ 0 and give it as the script argument: 109``` 110./cw_max_min_cfg.sh b5654332 111``` 112It will show sth like 113``` 114FPGA cw max min for q3 to q0: 2047 31; 63 31; 15 7; 7 3 115FPGA cw max min for q3 to q0: b5654332 116SYSFS cw max min for q3 to q0: 2047 31; 63 31; 15 7; 7 3 117SYSFS cw max min for q3 to q0: b5654332 118``` 119To give the control back to Linux 120``` 121./cw_max_min_cfg.sh 0 122``` 123Be careful that above command won't bring the Linux CW max min setting back to FPGA automatically, because Linux normally only call the setting function openwifi_conf_tx() for 1 time when the NIC is started. So either you write down the Linux setting by checking it at the beginning, and set it back via cw_max_min_cfg.sh before giving it argument 0, or re-load the NIC/driver to trigger the Linux setting action for the NIC. 124 125## Rx gain config 126 127In normal operation, you don't need to do Rx gain control manually, because it is controled by the AD9361 AGC function. For optimization/experiment purpose, you might want to use the manual rx gain control, you can run 128``` 129./set_rx_gain_manual.sh 30 130``` 131Above command will turn the automatic gain control mode to manual gain control mode, and set 30dB to the Rx gain module. 132 133Bring it back to the automatic gain control mode 134``` 135./set_rx_gain_auto.sh 136``` 137To find out a good reference about a manual Rx gain setting for the current link/peer, you can set it to automatic mode and then run 138``` 139rx_gain_show.sh 140``` 141for multiple times to check the actual AGC gain vlaue for received packet as explained in this [Access counter/statistics in driver](driver_stat.md). Then you can set the AGC gain value as argument to the **set_rx_gain_manual.sh** with the corret **offset**! For example, if **rx_gain_show.sh** reports a AGC gain value 34 for many successfully received data packets, and you want to use it as a manual gain setting, you need to set 142``` 143./set_rx_gain_manual.sh 20 144``` 145if the current working channel is 5220MHz (34 - 14dB offset = 20). You need to set 146``` 147./set_rx_gain_manual.sh 29 148``` 149if the current working channel is in 2.4GHz (34 - 5dB offset = 29). 150 151## Tx power config 152``` 153./sdrctl dev sdr0 set reg rf 0 20000 154``` 155Above command will set Tx power attenuation to 20dB (20*1000). By default it is 0dB. 156 157If you want an initial attenuation 20dB while loading and bringing up the openwifi NIC, please use the **init_tx_att** argument for the sdr.ko. 158``` 159insmod sdr.ko init_tx_att=20000 160``` 161You can change above driver loading action at the end of **wgd.sh**. 162 163The initial Tx attenuation might be useful when you connect two SDR boards directly by cable. Even though, you shouldn't not connect them during the setup phase (bring up the AP or client), because the initialization/tuning of AD9361 might generate big Tx power and kill the other AD9361's Rx. Only connect two SDR boards by cable after both sides have been setup and the attenuation setting takes effect. 164 165## Tx Lo and port config 166 167In normal operation, the Tx Lo and RF port are controled by FPGA automatically during signal Tx. To check the current Tx Lo and RF port switch status 168``` 169./set_tx_port.sh 170./set_tx_lo.sh 171``` 172Give argument **1** to above scripts to turn them **ON**, **0** for **OFF**. 173 174## Antenna selection 175 176By default, the 1st Tx and Rx antennas are used (tx0 and rx0). You can change the tx antenna to tx1 by 177``` 178./sdrctl dev sdr0 set reg drv_tx 4 1 179``` 180Change the tx antenna back to tx0 by 181``` 182./sdrctl dev sdr0 set reg drv_tx 4 0 183``` 184Change the rx antenna to rx1 and rx0 by 185``` 186./sdrctl dev sdr0 set reg drv_rx 4 1 187./sdrctl dev sdr0 set reg drv_rx 4 0 188``` 189 190## Restrict the frequency 191 192Since the AD9361 frequency tuning could generate big unwanted Tx noise, and it could damage the other AD9361 Rx during the test via cable, a restricted frequency can be set to avoid the possible frequency tuning (such as the background scan of Wifi). For example, you want the AD9361 works only in 5220Mhz: 193``` 194./set_restrict_freq.sh 5220 195``` 196Above command will fix the AD9361 in 5220MHz and let driver ignore frequency tuning request other than 5220MHz. The restriction can be removed by: 197``` 198./set_restrict_freq.sh 0 199``` 200## Tx rate config 201 202By default, the Linux rate adaptation algorithm **minstrel_ht** set the packet rate/MCS automatically via openwifi_tx() function. 203``` 204rate_hw_value = ieee80211_get_tx_rate(dev, info)->hw_value; 205``` 206To override the Linux automatic control for non-ht packet 207``` 208./sdrctl dev sdr0 set reg drv_tx 0 N 209``` 210Value N: 0 for Linux auto control; 4 ~ 11 for 6M, 9M, 12M, 18M, 24M, 36M, 48M, 54M. 211 212To override the Linux automatic control for ht packet 213``` 214./sdrctl dev sdr0 set reg drv_tx 1 N 215``` 216Value N: 0 for Linux auto control; 4 ~ 11 for 6.5M, 13M, 19.5M, 26M, 39M, 52M, 58.5M, 65M. By default, the normal GI is used. To use the short GI, you need to add 16 to the target value N. 217 218## Arbiturary Tx IQ sample 219 220 To be written. 221