1 // Author: Xianjun Jiao, Michael Mehari, Wei Liu 2 // SPDX-FileCopyrightText: 2019 UGent 3 // SPDX-License-Identifier: AGPL-3.0-or-later 4 5 #ifndef OPENWIFI_SDR 6 #define OPENWIFI_SDR 7 8 // -------------------for leds-------------------------------- 9 struct gpio_led_data { //pleas always align with the leds-gpio.c in linux kernel 10 struct led_classdev cdev; 11 struct gpio_desc *gpiod; 12 u8 can_sleep; 13 u8 blinking; 14 gpio_blink_set_t platform_gpio_blink_set; 15 }; 16 17 struct gpio_leds_priv { //pleas always align with the leds-gpio.c in linux kernel 18 int num_leds; 19 struct gpio_led_data leds[]; 20 }; 21 22 struct openwifi_rf_ops { 23 char *name; 24 // void (*init)(struct ieee80211_hw *); 25 // void (*stop)(struct ieee80211_hw *); 26 void (*set_chan)(struct ieee80211_hw *, struct ieee80211_conf *); 27 // u8 (*calc_rssi)(u8 agc, u8 sq); 28 }; 29 30 struct openwifi_buffer_descriptor { 31 // u32 num_dma_byte; 32 // u32 sn; 33 // u32 hw_queue_idx; 34 // u32 retry_limit; 35 // u32 need_ack; 36 struct sk_buff *skb_linked; 37 dma_addr_t dma_mapping_addr; 38 // u32 reserved; 39 } __packed; 40 41 struct openwifi_ring { 42 struct openwifi_buffer_descriptor *bds; 43 u32 bd_wr_idx; 44 u32 bd_rd_idx; 45 u32 stop_flag; // track the stop/wake status between tx interrupt and openwifi_tx 46 // u32 num_dma_symbol_request; 47 // u32 reserved; 48 } __packed; 49 50 struct openwifi_vif { 51 struct ieee80211_hw *dev; 52 53 int idx; // this vif's idx on the dev 54 55 /* beaconing */ 56 struct delayed_work beacon_work; 57 bool enable_beacon; 58 }; 59 60 union u32_byte4 { 61 u32 a; 62 u8 c[4]; 63 }; 64 union u16_byte2 { 65 u16 a; 66 u8 c[2]; 67 }; 68 69 #define MAX_NUM_LED 4 70 #define OPENWIFI_LED_MAX_NAME_LEN 32 71 72 // ------------ software reg definition ------------ 73 #define MAX_NUM_DRV_REG 8 74 #define DRV_TX_REG_IDX_RATE 0 75 #define DRV_TX_REG_IDX_FREQ_BW_CFG 1 76 #define DRV_TX_REG_IDX_PRINT_CFG (MAX_NUM_DRV_REG-1) 77 78 #define DRV_RX_REG_IDX_FREQ_BW_CFG 1 79 #define DRV_RX_REG_IDX_EXTRA_FO 2 80 #define DRV_RX_REG_IDX_PRINT_CFG (MAX_NUM_DRV_REG-1) 81 82 #define DRV_XPU_REG_IDX_GIT_REV (MAX_NUM_DRV_REG-1) 83 84 // ------end of software reg definition ------------ 85 86 #define MAX_NUM_VIF 4 87 88 #define LEN_PHY_HEADER 16 89 #define LEN_PHY_CRC 4 90 91 #define RING_ROOM_THRESHOLD 4 92 #define NUM_TX_BD 64 // !!! should align to the fifo size in tx_bit_intf.v 93 #define NUM_RX_BD 16 94 #define TX_BD_BUF_SIZE (8192) 95 #define RX_BD_BUF_SIZE (8192) 96 97 #define NUM_BIT_MAX_NUM_HW_QUEUE 2 98 #define MAX_NUM_HW_QUEUE 4 // number of queue in FPGA 99 #define MAX_NUM_SW_QUEUE 4 // number of queue in Linux, depends on the number we report by dev->queues in openwifi_dev_probe 100 #define NUM_BIT_MAX_PHY_TX_SN 10 // decrease 12 to 10 to reserve 2 bits storing related linux prio idx 101 #define MAX_PHY_TX_SN ((1<<NUM_BIT_MAX_PHY_TX_SN)-1) 102 103 #define AD9361_RADIO_OFF_TX_ATT 89750 //please align with ad9361.c 104 #define AD9361_RADIO_ON_TX_ATT 000 //please align with rf_init.sh 105 106 #define SDR_SUPPORTED_FILTERS \ 107 (FIF_ALLMULTI | \ 108 FIF_BCN_PRBRESP_PROMISC | \ 109 FIF_CONTROL | \ 110 FIF_OTHER_BSS | \ 111 FIF_PSPOLL | \ 112 FIF_PROBE_REQ) 113 114 #define HIGH_PRIORITY_DISCARD_FLAG ((~0x040)<<16) // don't force drop OTHER_BSS by high priority discard 115 //#define HIGH_PRIORITY_DISCARD_FLAG ((~0x140)<<16) // don't force drop OTHER_BSS and PROB_REQ by high priority discard 116 117 /* 5G chan 36 - chan 64*/ 118 #define SDR_5GHZ_CH36_64 \ 119 REG_RULE(5150-10, 5350+10, 80, 0, 20, 0) 120 /* 5G chan 36 - chan 48*/ 121 #define SDR_5GHZ_CH36_48 \ 122 REG_RULE(5150-10, 5270+10, 80, 0, 20, 0) 123 124 /* 125 *Only these channels all allow active 126 *scan on all world regulatory domains 127 */ 128 #define SDR_2GHZ_CH01_13 REG_RULE(2412-10, 2472+10, 40, 0, 20, NL80211_RRF_NO_CCK) // disable 11b 129 #define SDR_2GHZ_CH01_14 REG_RULE(2412-10, 2484+10, 40, 0, 20, NL80211_RRF_NO_CCK) // disable 11b 130 131 // regulatory.h alpha2 132 // * 00 - World regulatory domain 133 // * 99 - built by driver but a specific alpha2 cannot be determined 134 // * 98 - result of an intersection between two regulatory domains 135 // * 97 - regulatory domain has not yet been configured 136 static const struct ieee80211_regdomain sdr_regd = { // for wiphy_apply_custom_regulatory 137 .n_reg_rules = 2, 138 .alpha2 = "99", 139 .dfs_region = NL80211_DFS_ETSI, 140 .reg_rules = { 141 //SDR_2GHZ_CH01_13, 142 //SDR_5GHZ_CH36_48, //Avoid radar! 143 SDR_2GHZ_CH01_14, 144 SDR_5GHZ_CH36_64, 145 } 146 }; 147 148 #define CHAN2G(_channel, _freq, _flags) { \ 149 .band = NL80211_BAND_2GHZ, \ 150 .hw_value = (_channel), \ 151 .center_freq = (_freq), \ 152 .flags = (_flags), \ 153 .max_antenna_gain = 0, \ 154 .max_power = 0, \ 155 } 156 157 #define CHAN5G(_channel, _freq, _flags) { \ 158 .band = NL80211_BAND_5GHZ, \ 159 .hw_value = (_channel), \ 160 .center_freq = (_freq), \ 161 .flags = (_flags), \ 162 .max_antenna_gain = 0, \ 163 .max_power = 0, \ 164 } 165 166 static const struct ieee80211_rate openwifi_5GHz_rates[] = { 167 { .bitrate = 10, .hw_value = 0, .flags = 0}, 168 { .bitrate = 20, .hw_value = 1, .flags = 0}, 169 { .bitrate = 55, .hw_value = 2, .flags = 0}, 170 { .bitrate = 110, .hw_value = 3, .flags = 0}, 171 { .bitrate = 60, .hw_value = 4, .flags = IEEE80211_RATE_MANDATORY_A}, 172 { .bitrate = 90, .hw_value = 5, .flags = IEEE80211_RATE_MANDATORY_A}, 173 { .bitrate = 120, .hw_value = 6, .flags = IEEE80211_RATE_MANDATORY_A}, 174 { .bitrate = 180, .hw_value = 7, .flags = IEEE80211_RATE_MANDATORY_A}, 175 { .bitrate = 240, .hw_value = 8, .flags = IEEE80211_RATE_MANDATORY_A}, 176 { .bitrate = 360, .hw_value = 9, .flags = IEEE80211_RATE_MANDATORY_A}, 177 { .bitrate = 480, .hw_value = 10, .flags = IEEE80211_RATE_MANDATORY_A}, 178 { .bitrate = 540, .hw_value = 11, .flags = IEEE80211_RATE_MANDATORY_A}, 179 }; 180 181 static const struct ieee80211_rate openwifi_2GHz_rates[] = { 182 { .bitrate = 10, .hw_value = 0, .flags = 0}, 183 { .bitrate = 20, .hw_value = 1, .flags = 0}, 184 { .bitrate = 55, .hw_value = 2, .flags = 0}, 185 { .bitrate = 110, .hw_value = 3, .flags = 0}, 186 { .bitrate = 60, .hw_value = 4, .flags = IEEE80211_RATE_MANDATORY_G|IEEE80211_RATE_ERP_G}, 187 { .bitrate = 90, .hw_value = 5, .flags = IEEE80211_RATE_MANDATORY_G|IEEE80211_RATE_ERP_G}, 188 { .bitrate = 120, .hw_value = 6, .flags = IEEE80211_RATE_MANDATORY_G|IEEE80211_RATE_ERP_G}, 189 { .bitrate = 180, .hw_value = 7, .flags = IEEE80211_RATE_MANDATORY_G|IEEE80211_RATE_ERP_G}, 190 { .bitrate = 240, .hw_value = 8, .flags = IEEE80211_RATE_MANDATORY_G|IEEE80211_RATE_ERP_G}, 191 { .bitrate = 360, .hw_value = 9, .flags = IEEE80211_RATE_MANDATORY_G|IEEE80211_RATE_ERP_G}, 192 { .bitrate = 480, .hw_value = 10, .flags = IEEE80211_RATE_MANDATORY_G|IEEE80211_RATE_ERP_G}, 193 { .bitrate = 540, .hw_value = 11, .flags = IEEE80211_RATE_MANDATORY_G|IEEE80211_RATE_ERP_G}, 194 }; 195 196 static const struct ieee80211_channel openwifi_2GHz_channels[] = { 197 CHAN2G(1, 2412, 0), 198 CHAN2G(2, 2417, 0), 199 CHAN2G(3, 2422, 0), 200 CHAN2G(4, 2427, 0), 201 CHAN2G(5, 2432, 0), 202 CHAN2G(6, 2437, 0), 203 CHAN2G(7, 2442, 0), 204 CHAN2G(8, 2447, 0), 205 CHAN2G(9, 2452, 0), 206 CHAN2G(10, 2457, 0), 207 CHAN2G(11, 2462, 0), 208 CHAN2G(12, 2467, 0), 209 CHAN2G(13, 2472, 0), 210 CHAN2G(14, 2484, 0), 211 }; 212 213 static const struct ieee80211_channel openwifi_5GHz_channels[] = { 214 CHAN5G(36, 5180, 0), 215 CHAN5G(38, 5190, 0), 216 CHAN5G(40, 5200, 0), 217 CHAN5G(42, 5210, 0), 218 CHAN5G(44, 5220, 0), 219 CHAN5G(46, 5230, 0), 220 CHAN5G(48, 5240, 0), 221 CHAN5G(52, 5260, IEEE80211_CHAN_RADAR), 222 CHAN5G(56, 5280, IEEE80211_CHAN_RADAR), 223 CHAN5G(60, 5300, IEEE80211_CHAN_RADAR), 224 CHAN5G(64, 5320, IEEE80211_CHAN_RADAR), 225 // CHAN5G(100, 5500, 0), 226 // CHAN5G(104, 5520, 0), 227 // CHAN5G(108, 5540, 0), 228 // CHAN5G(112, 5560, 0), 229 // CHAN5G(116, 5580, 0), 230 // CHAN5G(120, 5600, 0), 231 // CHAN5G(124, 5620, 0), 232 // CHAN5G(128, 5640, 0), 233 // CHAN5G(132, 5660, 0), 234 // CHAN5G(136, 5680, 0), 235 // CHAN5G(140, 5700, 0), 236 // CHAN5G(144, 5720, 0), 237 // CHAN5G(149, 5745, 0), 238 // CHAN5G(153, 5765, 0), 239 // CHAN5G(157, 5785, 0), 240 // CHAN5G(161, 5805, 0), 241 // CHAN5G(165, 5825, 0), 242 // CHAN5G(169, 5845, 0), 243 }; 244 245 static const struct ieee80211_iface_limit openwifi_if_limits[] = { 246 { .max = 2048, .types = BIT(NL80211_IFTYPE_STATION) }, 247 { .max = 4, .types = 248 #ifdef CONFIG_MAC80211_MESH 249 BIT(NL80211_IFTYPE_MESH_POINT) | 250 #endif 251 BIT(NL80211_IFTYPE_AP) }, 252 }; 253 254 static const struct ieee80211_iface_combination openwifi_if_comb = { 255 .limits = openwifi_if_limits, 256 .n_limits = ARRAY_SIZE(openwifi_if_limits), 257 .max_interfaces = 2048, 258 .num_different_channels = 1, 259 .radar_detect_widths = BIT(NL80211_CHAN_WIDTH_20_NOHT) | 260 BIT(NL80211_CHAN_WIDTH_20) | 261 BIT(NL80211_CHAN_WIDTH_40) | 262 BIT(NL80211_CHAN_WIDTH_80), 263 }; 264 265 static const u8 wifi_rate_table_mapping[24] = { 0, 0, 0, 0, 0, 0, 0, 0, 10, 8, 6, 4, 11, 9, 7, 5, 0, 1, 2, 3, 4, 5, 6, 7}; 266 static const u16 wifi_rate_table[24] = { 0, 0, 0, 0, 0, 0, 0, 0, 480, 240, 120, 60, 540, 360, 180, 90, 65, 130, 195, 260, 390, 520, 585, 650}; 267 static const u16 wifi_rate_all[20] = {10, 20, 55, 110, 60, 90, 120, 180, 240, 360, 480, 540, 65, 130, 195, 260, 390, 520, 585, 650}; 268 static const u8 wifi_mcs_table_11b_force_up[16] = {11, 11, 11, 11, 11, 15, 10, 14, 9, 13, 8, 12, 0, 0, 0, 0}; 269 static const u16 wifi_n_dbps_table[16] = {24, 24, 24, 24, 24, 36, 48, 72, 96, 144, 192, 216, 0, 0, 0, 0}; 270 static const u16 wifi_n_dbps_ht_table[16] = {26, 26, 26, 26, 26, 52, 78, 104, 156, 208, 234, 260, 0, 0, 0, 0}; 271 // static const u8 wifi_mcs_table[8] = {6,9,12,18,24,36,48,54}; 272 // static const u8 wifi_mcs_table_phy_tx[8] = {11,15,10,14,9,13,8,12}; 273 274 // ===== copy from adi-linux/drivers/iio/frequency/cf_axi_dds.c ===== 275 struct cf_axi_dds_state { 276 struct device *dev_spi; 277 struct clk *clk; 278 struct cf_axi_dds_chip_info *chip_info; 279 struct gpio_desc *plddrbypass_gpio; 280 struct gpio_desc *interpolation_gpio; 281 282 bool standalone; 283 bool dp_disable; 284 bool enable; 285 bool pl_dma_fifo_en; 286 enum fifo_ctrl gpio_dma_fifo_ctrl; 287 288 struct iio_info iio_info; 289 size_t regs_size; 290 void __iomem *regs; 291 void __iomem *slave_regs; 292 void __iomem *master_regs; 293 u64 dac_clk; 294 unsigned int ddr_dds_interp_en; 295 unsigned int cached_freq[16]; 296 unsigned int version; 297 unsigned int have_slave_channels; 298 unsigned int interpolation_factor; 299 struct notifier_block clk_nb; 300 }; 301 // ===== end of copy from adi-linux/drivers/iio/frequency/cf_axi_dds.c ===== 302 303 #define RX_DMA_CYCLIC_MODE 304 struct openwifi_priv { 305 struct platform_device *pdev; 306 struct ieee80211_vif *vif[MAX_NUM_VIF]; 307 308 const struct openwifi_rf_ops *rf; 309 310 struct cf_axi_dds_state *dds_st; //axi_ad9361 hdl ref design module, dac channel 311 struct axiadc_state *adc_st; //axi_ad9361 hdl ref design module, adc channel 312 struct ad9361_rf_phy *ad9361_phy; //ad9361 chip 313 struct ctrl_outs_control ctrl_out; 314 315 int rx_freq_offset_to_lo_MHz; 316 int tx_freq_offset_to_lo_MHz; 317 u32 rf_bw; 318 u32 actual_rx_lo; 319 320 struct ieee80211_rate rates_2GHz[12]; 321 struct ieee80211_rate rates_5GHz[12]; 322 struct ieee80211_channel channels_2GHz[14]; 323 struct ieee80211_channel channels_5GHz[11]; 324 struct ieee80211_supported_band band_2GHz; 325 struct ieee80211_supported_band band_5GHz; 326 bool rfkill_off; 327 328 int rssi_correction; // dynamic RSSI correction according to current channel in _rf_set_channel() 329 330 enum rx_intf_mode rx_intf_cfg; 331 enum tx_intf_mode tx_intf_cfg; 332 enum openofdm_rx_mode openofdm_rx_cfg; 333 enum openofdm_tx_mode openofdm_tx_cfg; 334 enum xpu_mode xpu_cfg; 335 336 int irq_rx; 337 int irq_tx; 338 339 // u32 call_counter; 340 u8 *rx_cyclic_buf; 341 dma_addr_t rx_cyclic_buf_dma_mapping_addr; 342 struct dma_chan *rx_chan; 343 struct dma_async_tx_descriptor *rxd; 344 dma_cookie_t rx_cookie; 345 346 struct openwifi_ring tx_ring[MAX_NUM_SW_QUEUE]; 347 struct scatterlist tx_sg; 348 struct dma_chan *tx_chan; 349 struct dma_async_tx_descriptor *txd; 350 dma_cookie_t tx_cookie; 351 // struct completion tx_dma_complete; 352 // bool openwifi_tx_first_time_run; 353 354 // int phy_tx_sn; 355 u32 slice_idx; 356 u32 dest_mac_addr_queue_map[MAX_NUM_HW_QUEUE]; 357 u8 mac_addr[ETH_ALEN]; 358 u16 seqno; 359 360 bool use_short_slot; 361 u8 band; 362 u16 channel; 363 364 u32 drv_rx_reg_val[MAX_NUM_DRV_REG]; 365 u32 drv_tx_reg_val[MAX_NUM_DRV_REG]; 366 u32 drv_xpu_reg_val[MAX_NUM_DRV_REG]; 367 // u8 num_led; 368 // struct led_classdev *led[MAX_NUM_LED];//zc706 has 4 user leds. please find openwifi_dev_probe to see how we get them. 369 // char led_name[MAX_NUM_LED][OPENWIFI_LED_MAX_NAME_LEN]; 370 371 spinlock_t lock; 372 }; 373 374 #endif /* OPENWIFI_SDR */ 375