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