diff -uNr old/bb_soc.c new/bb_soc.c --- old/bb_soc.c 1970-01-01 08:00:00.000000000 +0800 +++ new/bb_soc.c 2022-01-27 10:56:20.543975000 +0800 @@ -0,0 +1,126 @@ +/* + Module Name: + bb_soc.c + + Abstract: + Broad Band SoC platform added. + + revision History: + Who When What + --------- ---------- ---------------------------------------------- + GeoYang 2021.Apr.13 file created + */ +#include +#include +#include +#include +#include +#include +#include + +#include "mt76.h" + +//set the file path to be the same as Linux driver +//maybe one day mt76+mac80211.ko is porting to tclinux +#define BIN_FILE_PATH "/etc/Wireless/RT2860AP_AC/RT30xxEEPROM.bin" +#define BIN_FILE_PATH_2G "/etc/RT30xxEEPROM.bin" +#define FILE_OPEN_ERR(_fd) ((_fd == NULL) || IS_ERR((_fd))) + +static bool glb_eeprom_has_read_once = false; + + + +static int bbsoc_file_read(struct file *fp, char *eeprom_data, int len) +{ +// > 3.19.0 +#if (LINUX_VERSION_CODE < KERNEL_VERSION(3, 19, 0)) + if (fp->f_op && fp->f_op->read) { + return fp->f_op->read(fp, eeprom_data, len, &fp->f_pos); + } +// 3.19.1 ~ 4.19.0 +#elif (LINUX_VERSION_CODE < KERNEL_VERSION(4, 19, 0)) + if (fp->f_mode & FMODE_CAN_READ) { + return __vfs_read(fp, eeprom_data, len, &fp->f_pos); + } +// > 4.19.1 +#else + if (fp->f_mode & FMODE_CAN_READ) { + return kernel_read(fp, eeprom_data, len, &fp->f_pos); + } +#endif + else{ + printk("mt76: this should be an error !!!\n"); + } + + return -EPERM; +} + +/* + * Implementation for reading eeprom from bin file instead of using mtd_read + */ +int bbsoc_load_eeprom_from_bin(struct mt76_dev *dev, int len, bool is_dbdc) +{ + char file_path[100] = {'\0'}; + mm_segment_t oldfs; + struct file *fp = NULL; + int ret = 0; + + + dev->eeprom.size = len; + dev->eeprom.data = devm_kzalloc(dev->dev, len, GFP_KERNEL); + if (!dev->eeprom.data){ + dev_info(dev->dev,"mt76 mem alloc fail!!!\n"); + return -ENOMEM; + } + + memset(dev->eeprom.data, 0, len); + //dev_info(dev->dev,"%s() len:%d is_dbdc:%d\n", __func__, len, is_dbdc); + + if(is_dbdc){ + snprintf(file_path, 100, "%s", BIN_FILE_PATH); + } + else{ + if(glb_eeprom_has_read_once){ + snprintf(file_path, 100, "%s", BIN_FILE_PATH); + } + else{ + glb_eeprom_has_read_once = true; + snprintf(file_path, 100, "%s", BIN_FILE_PATH_2G); + } + } + dev_info(dev->dev,"%s() file_path:%s\n", __func__, file_path); + + // init + oldfs = get_fs(); + set_fs(KERNEL_DS); + + // file open + fp = filp_open(file_path, O_RDONLY, 0); + if(FILE_OPEN_ERR(fp)){ + dev_info(dev->dev,"open file fail: %s\n", file_path); + goto error_condition; + } + + // file read + ret = bbsoc_file_read(fp, dev->eeprom.data, len); + if(ret > 0) { + dev_info(dev->dev,"load eeprom succesfully from %s\n", file_path); + } + else { + dev_info(dev->dev,"read file fail: %s\n", file_path); + filp_close(fp, NULL); + goto error_condition; + } + + + // file close + filp_close(fp, NULL); + set_fs(oldfs); + + return 0; + +error_condition: + set_fs(oldfs); + return -ENOENT; +} +EXPORT_SYMBOL_GPL(bbsoc_load_eeprom_from_bin); diff -uNr old/mac80211.c new/mac80211.c --- old/mac80211.c 2023-04-21 22:01:15.976372000 +0800 +++ new/mac80211.c 2023-04-24 17:56:45.907508000 +0800 @@ -5,7 +5,9 @@ #include #include #include "mt76.h" - +#if defined(TCSUPPORT_RA_HWNAT) && defined(TCSUPPORT_HWNAT_V3) +#include +#endif #define CHAN2G(_idx, _freq) { \ .band = NL80211_BAND_2GHZ, \ .center_freq = (_freq), \ @@ -1280,7 +1282,9 @@ struct ieee80211_hw *hw; struct sk_buff *skb, *tmp; LIST_HEAD(list); - +#if defined(TCSUPPORT_RA_HWNAT) && defined(TCSUPPORT_HWNAT_V3) + int qid = napi - dev->napi; +#endif spin_lock(&dev->rx_lock); while ((skb = __skb_dequeue(frames)) != NULL) { struct sk_buff *nskb = skb_shinfo(skb)->frag_list; @@ -1309,6 +1313,21 @@ list_for_each_entry_safe(skb, tmp, &list, list) { skb_list_del_init(skb); +#if defined(TCSUPPORT_RA_HWNAT) && defined(TCSUPPORT_HWNAT_V3) + if((qid == MT_RXQ_MAIN) || (qid == MT_RXQ_BAND1)) + { + if(ra_sw_nat_hook_set_magic) + ra_sw_nat_hook_set_magic(skb, FOE_MAGIC_WLAN); + if(ra_sw_nat_hook_rx != NULL) + { + if(ra_sw_nat_hook_rx(skb) != 0) + { + napi_gro_receive(napi, skb); + } + } + } + else +#endif napi_gro_receive(napi, skb); } } diff -uNr old/Makefile new/Makefile --- old/Makefile 2022-12-10 20:11:05.000000000 +0800 +++ new/Makefile 2023-04-24 17:57:14.224546000 +0800 @@ -10,7 +10,7 @@ mt76-y := \ mmio.o util.o trace.o dma.o mac80211.o debugfs.o eeprom.o \ tx.o agg-rx.o mcu.o - +mt76-$(CONFIG_BB_SOC) += bb_soc.o mt76-$(CONFIG_PCI) += pci.o mt76-$(CONFIG_NL80211_TESTMODE) += testmode.o diff -uNr old/mt7915/mac.c new/mt7915/mac.c --- old/mt7915/mac.c 2023-04-21 22:01:16.050370000 +0800 +++ new/mt7915/mac.c 2023-04-24 17:43:27.748564000 +0800 @@ -690,8 +690,8 @@ rate_idx += 4; r = &phy->mt76->hw->wiphy->bands[band]->bitrates[rate_idx]; - val = cck ? r->hw_value_short : r->hw_value; - + //val = cck ? r->hw_value_short : r->hw_value; + val = r->hw_value; mode = val >> 8; rate_idx = val & 0xff; break; diff -uNr old/testmode.c new/testmode.c --- old/testmode.c 2023-04-21 22:01:14.422364000 +0800 +++ new/testmode.c 2023-04-24 18:03:02.293536000 +0800 @@ -52,8 +52,12 @@ if (ret < 0) break; + td->tx_pending--; count--; - td->tx_pending--; + + /* tx_count == UINT_MAX for continuous tx */ + if (td->tx_count != UINT_MAX) + td->tx_pending--; td->tx_queued++; if (td->tx_rate_mode != MT76_TM_TX_MODE_HE_MU) --- old/mt7915/eeprom.c 2022-11-14 14:27:56.264380000 +0800 +++ new/mt7915/eeprom.c 2022-11-14 15:38:54.929101000 +0800 @@ -4,7 +4,52 @@ #include #include "mt7915.h" #include "eeprom.h" +#ifdef CONFIG_BB_SOC +static u32 mt7915_eeprom_read(struct mt7915_dev *dev, u32 offset) +{ + u8 *data = dev->mt76.eeprom.data; + + if (data[offset] == 0xff){ + dev_info(dev->mt76.dev, "%s get offset 0x%x value\n", __func__, offset); + mt7915_mcu_get_eeprom(dev, offset, NULL); + } + + return data[offset]; +} +//MT7915D eeprom 0x190 is 0x92 +//MT7915A eeprom 0x190 is 0x24 +static int bb_soc_mt7915_check_e2p_matched_hw(struct mt7915_dev *dev) +{ + u8 *eeprom = dev->mt76.eeprom.data; + u8 val; + + val = mt7915_eeprom_read(dev, MT_EE_WIFI_CONF); + dev_info(dev->mt76.dev, "val:0x%x\n", val); + + if(dev->dbdc_support && val == 0x92){ + dev_info(dev->mt76.dev, "e2p matched with mt7915d hw\n"); + return 0; + } + else if(val == 0x24){ + dev_info(dev->mt76.dev, "e2p matched with mt7915a hw\n"); + return 0; + } + else if(val == 0x12){ + dev_info(dev->mt76.dev, "e2p matched with mt7916d hw\n"); + return 0; + } + else{ + dev_info(dev->mt76.dev, + "e2p table isn't matched with hw !!! 0x%04x=0x%x\n",MT_EE_WIFI_CONF, val); + // try to use efuse mode if e2p table from flash isn't matched with hw + dev->flash_mode = false; + memset(dev->mt76.eeprom.data, -1, MT7915_EEPROM_SIZE); + return -EINVAL; + } +} +#endif + static int mt7915_eeprom_load_precal(struct mt7915_dev *dev) { struct mt76_dev *mdev = &dev->mt76; @@ -109,11 +154,19 @@ int ret; u16 eeprom_size = mt7915_eeprom_size(dev); - ret = mt76_eeprom_init(&dev->mt76, eeprom_size); +#ifndef CONFIG_BB_SOC + ret = mt76_eeprom_init(&dev->mt76, MT7915_EEPROM_SIZE); if (ret < 0) return ret; - if (ret) { + if (ret) +#else + ret = bbsoc_load_eeprom_from_bin(&dev->mt76, MT7915_EEPROM_SIZE, dev->dbdc_support); + + if (ret == 0) +#endif + { + dev_info(dev->mt76.dev, "%s flash_mode\n", __func__); dev->flash_mode = true; dev->eeprom_mode = FLASH_MODE; } else { @@ -140,7 +193,11 @@ dev->eeprom_mode = EFUSE_MODE; } - return mt7915_check_eeprom(dev); +#ifdef CONFIG_BB_SOC + return 0; +#else + return mt7915_check_eeprom(dev); +#endif } static void mt7915_eeprom_parse_band_config(struct mt7915_phy *phy) @@ -297,7 +354,9 @@ if (ret) return ret; } - +#ifdef CONFIG_BB_SOC + bb_soc_mt7915_check_e2p_matched_hw(dev); +#endif mt7915_eeprom_rebonding(dev); ret = mt7915_eeprom_load_precal(dev); --- old/mt76.h 2022-11-14 14:27:56.997373000 +0800 +++ new/mt76.h 2022-11-14 15:26:17.035168000 +0800 @@ -1549,7 +1549,9 @@ struct ieee80211_channel *chan, struct mt76_power_limits *dest, s8 target_power); - +#ifdef CONFIG_BB_SOC +int bbsoc_load_eeprom_from_bin(struct mt76_dev *dev, int len, bool is_dbdc); +#endif struct mt76_txwi_cache * mt76_token_release(struct mt76_dev *dev, int token, bool *wake); int mt76_token_consume(struct mt76_dev *dev, struct mt76_txwi_cache **ptxwi);