Add files via upload

This commit is contained in:
ivanovborislav 2021-11-21 14:15:16 +02:00 committed by GitHub
parent d75aa750f6
commit 75c26685e1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
42 changed files with 56355 additions and 0 deletions

View File

@ -0,0 +1,340 @@
/******************************************************************************
*
* Copyright(c) 2007 - 2017 Realtek Corporation.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of version 2 of the GNU General Public License as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
*****************************************************************************/
#include "drv_types.h"
#ifdef CONFIG_PLATFORM_SPRD
/* gspi func & GPIO define */
#include <mach/gpio.h>/* 0915 */
#include <mach/board.h>
#if !(defined ANDROID_2X)
#ifdef CONFIG_RTL8188E
#include <mach/regulator.h>
#include <linux/regulator/consumer.h>
#endif /* CONFIG_RTL8188E */
#ifndef GPIO_WIFI_POWER
#define GPIO_WIFI_POWER -1
#endif /* !GPIO_WIFI_POWER */
#ifndef GPIO_WIFI_RESET
#define GPIO_WIFI_RESET -1
#endif /* !GPIO_WIFI_RESET */
#ifndef GPIO_WIFI_PWDN
#define GPIO_WIFI_PWDN -1
#endif /* !GPIO_WIFI_RESET */
#ifdef CONFIG_GSPI_HCI
extern unsigned int oob_irq;
#endif /* CONFIG_GSPI_HCI */
#ifdef CONFIG_SDIO_HCI
extern int rtw_mp_mode;
#else /* !CONFIG_SDIO_HCI */
#endif /* !CONFIG_SDIO_HCI */
int rtw_wifi_gpio_init(void)
{
#ifdef CONFIG_GSPI_HCI
if (GPIO_WIFI_IRQ > 0) {
gpio_request(GPIO_WIFI_IRQ, "oob_irq");
gpio_direction_input(GPIO_WIFI_IRQ);
oob_irq = gpio_to_irq(GPIO_WIFI_IRQ);
RTW_INFO("%s oob_irq:%d\n", __func__, oob_irq);
}
#endif
if (GPIO_WIFI_RESET > 0)
gpio_request(GPIO_WIFI_RESET , "wifi_rst");
if (GPIO_WIFI_POWER > 0)
gpio_request(GPIO_WIFI_POWER, "wifi_power");
#ifdef CONFIG_SDIO_HCI
#if (defined(CONFIG_RTL8723B)) && (MP_DRIVER == 1)
if (rtw_mp_mode == 1) {
RTW_INFO("%s GPIO_BT_RESET pin special for mp_test\n", __func__);
if (GPIO_BT_RESET > 0)
gpio_request(GPIO_BT_RESET , "bt_rst");
}
#endif
#endif
return 0;
}
int rtw_wifi_gpio_deinit(void)
{
#ifdef CONFIG_GSPI_HCI
if (GPIO_WIFI_IRQ > 0)
gpio_free(GPIO_WIFI_IRQ);
#endif
if (GPIO_WIFI_RESET > 0)
gpio_free(GPIO_WIFI_RESET);
if (GPIO_WIFI_POWER > 0)
gpio_free(GPIO_WIFI_POWER);
#ifdef CONFIG_SDIO_HCI
#if (defined(CONFIG_RTL8723B)) && (MP_DRIVER == 1)
if (rtw_mp_mode == 1) {
RTW_INFO("%s GPIO_BT_RESET pin special for mp_test\n", __func__);
if (GPIO_BT_RESET > 0)
gpio_free(GPIO_BT_RESET);
}
#endif
#endif
return 0;
}
/* Customer function to control hw specific wlan gpios */
void rtw_wifi_gpio_wlan_ctrl(int onoff)
{
switch (onoff) {
case WLAN_PWDN_OFF:
RTW_INFO("%s: call customer specific GPIO(%d) to set wifi power down pin to 0\n",
__FUNCTION__, GPIO_WIFI_RESET);
#ifndef CONFIG_DONT_BUS_SCAN
if (GPIO_WIFI_RESET > 0)
gpio_direction_output(GPIO_WIFI_RESET , 0);
#endif
break;
case WLAN_PWDN_ON:
RTW_INFO("%s: callc customer specific GPIO(%d) to set wifi power down pin to 1\n",
__FUNCTION__, GPIO_WIFI_RESET);
if (GPIO_WIFI_RESET > 0)
gpio_direction_output(GPIO_WIFI_RESET , 1);
break;
case WLAN_POWER_OFF:
break;
case WLAN_POWER_ON:
break;
#ifdef CONFIG_SDIO_HCI
#if (defined(CONFIG_RTL8723B)) && (MP_DRIVER == 1)
case WLAN_BT_PWDN_OFF:
if (rtw_mp_mode == 1) {
RTW_INFO("%s: call customer specific GPIO to set wifi power down pin to 0\n",
__FUNCTION__);
if (GPIO_BT_RESET > 0)
gpio_direction_output(GPIO_BT_RESET , 0);
}
break;
case WLAN_BT_PWDN_ON:
if (rtw_mp_mode == 1) {
RTW_INFO("%s: callc customer specific GPIO to set wifi power down pin to 1 %x\n",
__FUNCTION__, GPIO_BT_RESET);
if (GPIO_BT_RESET > 0)
gpio_direction_output(GPIO_BT_RESET , 1);
}
break;
#endif
#endif
}
}
#else /* ANDROID_2X */
#include <mach/ldo.h>
#ifdef CONFIG_RTL8188E
extern int sprd_3rdparty_gpio_wifi_power;
#endif
extern int sprd_3rdparty_gpio_wifi_pwd;
#if defined(CONFIG_RTL8723B)
extern int sprd_3rdparty_gpio_bt_reset;
#endif
int rtw_wifi_gpio_init(void)
{
#if defined(CONFIG_RTL8723B)
if (sprd_3rdparty_gpio_bt_reset > 0)
gpio_direction_output(sprd_3rdparty_gpio_bt_reset, 1);
#endif
return 0;
}
int rtw_wifi_gpio_deinit(void)
{
return 0;
}
/* Customer function to control hw specific wlan gpios */
void rtw_wifi_gpio_wlan_ctrl(int onoff)
{
switch (onoff) {
case WLAN_PWDN_OFF:
RTW_INFO("%s: call customer specific GPIO to set wifi power down pin to 0\n",
__FUNCTION__);
if (sprd_3rdparty_gpio_wifi_pwd > 0)
gpio_set_value(sprd_3rdparty_gpio_wifi_pwd, 0);
if (sprd_3rdparty_gpio_wifi_pwd == 60) {
RTW_INFO("%s: turn off VSIM2 2.8V\n", __func__);
LDO_TurnOffLDO(LDO_LDO_SIM2);
}
break;
case WLAN_PWDN_ON:
RTW_INFO("%s: callc customer specific GPIO to set wifi power down pin to 1\n",
__FUNCTION__);
if (sprd_3rdparty_gpio_wifi_pwd == 60) {
RTW_INFO("%s: turn on VSIM2 2.8V\n", __func__);
LDO_SetVoltLevel(LDO_LDO_SIM2, LDO_VOLT_LEVEL0);
LDO_TurnOnLDO(LDO_LDO_SIM2);
}
if (sprd_3rdparty_gpio_wifi_pwd > 0)
gpio_set_value(sprd_3rdparty_gpio_wifi_pwd, 1);
break;
case WLAN_POWER_OFF:
#ifdef CONFIG_RTL8188E
#ifdef CONFIG_WIF1_LDO
RTW_INFO("%s: turn off VDD-WIFI0 1.2V\n", __FUNCTION__);
LDO_TurnOffLDO(LDO_LDO_WIF1);
#endif /* CONFIG_WIF1_LDO */
RTW_INFO("%s: turn off VDD-WIFI0 3.3V\n", __FUNCTION__);
LDO_TurnOffLDO(LDO_LDO_WIF0);
RTW_INFO("%s: call customer specific GPIO(%d) to turn off wifi power\n",
__FUNCTION__, sprd_3rdparty_gpio_wifi_power);
if (sprd_3rdparty_gpio_wifi_power != 65535)
gpio_set_value(sprd_3rdparty_gpio_wifi_power, 0);
#endif
break;
case WLAN_POWER_ON:
#ifdef CONFIG_RTL8188E
RTW_INFO("%s: call customer specific GPIO(%d) to turn on wifi power\n",
__FUNCTION__, sprd_3rdparty_gpio_wifi_power);
if (sprd_3rdparty_gpio_wifi_power != 65535)
gpio_set_value(sprd_3rdparty_gpio_wifi_power, 1);
RTW_INFO("%s: turn on VDD-WIFI0 3.3V\n", __FUNCTION__);
LDO_TurnOnLDO(LDO_LDO_WIF0);
LDO_SetVoltLevel(LDO_LDO_WIF0, LDO_VOLT_LEVEL1);
#ifdef CONFIG_WIF1_LDO
RTW_INFO("%s: turn on VDD-WIFI1 1.2V\n", __func__);
LDO_TurnOnLDO(LDO_LDO_WIF1);
LDO_SetVoltLevel(LDO_LDO_WIF1, LDO_VOLT_LEVEL3);
#endif /* CONFIG_WIF1_LDO */
#endif
break;
case WLAN_BT_PWDN_OFF:
RTW_INFO("%s: call customer specific GPIO to set bt power down pin to 0\n",
__FUNCTION__);
#if defined(CONFIG_RTL8723B)
if (sprd_3rdparty_gpio_bt_reset > 0)
gpio_set_value(sprd_3rdparty_gpio_bt_reset, 0);
#endif
break;
case WLAN_BT_PWDN_ON:
RTW_INFO("%s: callc customer specific GPIO to set bt power down pin to 1\n",
__FUNCTION__);
#if defined(CONFIG_RTL8723B)
if (sprd_3rdparty_gpio_bt_reset > 0)
gpio_set_value(sprd_3rdparty_gpio_bt_reset, 1);
#endif
break;
}
}
#endif /* ANDROID_2X */
#elif defined(CONFIG_PLATFORM_ARM_RK3066)
#include <mach/iomux.h>
#define GPIO_WIFI_IRQ RK30_PIN2_PC2
extern unsigned int oob_irq;
int rtw_wifi_gpio_init(void)
{
#ifdef CONFIG_GSPI_HCI
if (GPIO_WIFI_IRQ > 0) {
rk30_mux_api_set(GPIO2C2_LCDC1DATA18_SMCBLSN1_HSADCDATA5_NAME, GPIO2C_GPIO2C2);/* jacky_test */
gpio_request(GPIO_WIFI_IRQ, "oob_irq");
gpio_direction_input(GPIO_WIFI_IRQ);
oob_irq = gpio_to_irq(GPIO_WIFI_IRQ);
RTW_INFO("%s oob_irq:%d\n", __func__, oob_irq);
}
#endif
return 0;
}
int rtw_wifi_gpio_deinit(void)
{
#ifdef CONFIG_GSPI_HCI
if (GPIO_WIFI_IRQ > 0)
gpio_free(GPIO_WIFI_IRQ);
#endif
return 0;
}
void rtw_wifi_gpio_wlan_ctrl(int onoff)
{
}
#ifdef CONFIG_GPIO_API
/* this is a demo for extending GPIO pin[7] as interrupt mode */
struct net_device *rtl_net;
extern int rtw_register_gpio_interrupt(struct net_device *netdev, int gpio_num, void(*callback)(u8 level));
extern int rtw_disable_gpio_interrupt(struct net_device *netdev, int gpio_num);
void gpio_int(u8 is_high)
{
RTW_INFO("%s level=%d\n", __func__, is_high);
}
int register_net_gpio_init(void)
{
rtl_net = dev_get_by_name(&init_net, "wlan0");
if (!rtl_net) {
RTW_PRINT("rtl_net init fail!\n");
return -1;
}
return rtw_register_gpio_interrupt(rtl_net, 7, gpio_int);
}
int unregister_net_gpio_init(void)
{
rtl_net = dev_get_by_name(&init_net, "wlan0");
if (!rtl_net) {
RTW_PRINT("rtl_net init fail!\n");
return -1;
}
return rtw_disable_gpio_interrupt(rtl_net, 7);
}
#endif
#else
int rtw_wifi_gpio_init(void)
{
return 0;
}
void rtw_wifi_gpio_wlan_ctrl(int onoff)
{
}
#endif /* CONFIG_PLATFORM_SPRD */

10896
os_dep/linux/ioctl_cfg80211.c Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,454 @@
/******************************************************************************
*
* Copyright(c) 2007 - 2017 Realtek Corporation.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of version 2 of the GNU General Public License as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
*****************************************************************************/
#ifndef __IOCTL_CFG80211_H__
#define __IOCTL_CFG80211_H__
#define RTW_CFG80211_BLOCK_DISCON_WHEN_CONNECT BIT0
#define RTW_CFG80211_BLOCK_DISCON_WHEN_DISCONNECT BIT1
#ifndef RTW_CFG80211_BLOCK_STA_DISCON_EVENT
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 2, 0))
#define RTW_CFG80211_BLOCK_STA_DISCON_EVENT (RTW_CFG80211_BLOCK_DISCON_WHEN_CONNECT)
#else
#define RTW_CFG80211_BLOCK_STA_DISCON_EVENT (RTW_CFG80211_BLOCK_DISCON_WHEN_CONNECT | RTW_CFG80211_BLOCK_DISCON_WHEN_DISCONNECT)
#endif
#endif
#if defined(RTW_USE_CFG80211_STA_EVENT)
#undef CONFIG_CFG80211_FORCE_COMPATIBLE_2_6_37_UNDER
#endif
#ifndef RTW_P2P_GROUP_INTERFACE
#define RTW_P2P_GROUP_INTERFACE 0
#endif
/*
* (RTW_P2P_GROUP_INTERFACE, RTW_DEDICATED_P2P_DEVICE)
* (0, 0): wlan0 + p2p0(PD+PG)
* (1, 0): wlan0(with PD) + dynamic PGs
* (1, 1): wlan0 (with dynamic PD wdev) + dynamic PGs
*/
#if RTW_P2P_GROUP_INTERFACE
#ifndef CONFIG_RTW_DYNAMIC_NDEV
#define CONFIG_RTW_DYNAMIC_NDEV
#endif
#ifndef RTW_SINGLE_WIPHY
#define RTW_SINGLE_WIPHY
#endif
#ifndef CONFIG_RADIO_WORK
#define CONFIG_RADIO_WORK
#endif
#ifndef RTW_DEDICATED_P2P_DEVICE
#define RTW_DEDICATED_P2P_DEVICE
#endif
#endif
#ifndef CONFIG_RADIO_WORK
#define RTW_ROCH_DURATION_ENLARGE
#define RTW_ROCH_BACK_OP
#endif
#if !defined(CONFIG_P2P) && RTW_P2P_GROUP_INTERFACE
#error "RTW_P2P_GROUP_INTERFACE can't be enabled when CONFIG_P2P is disabled\n"
#endif
#if !RTW_P2P_GROUP_INTERFACE && defined(RTW_DEDICATED_P2P_DEVICE)
#error "RTW_DEDICATED_P2P_DEVICE can't be enabled when RTW_P2P_GROUP_INTERFACE is disabled\n"
#endif
#if defined(RTW_DEDICATED_P2P_DEVICE) && (LINUX_VERSION_CODE < KERNEL_VERSION(3, 7, 0))
#error "RTW_DEDICATED_P2P_DEVICE can't be enabled when kernel < 3.7.0\n"
#endif
#ifdef CONFIG_RTW_MESH
#if (LINUX_VERSION_CODE < KERNEL_VERSION(3, 10, 0))
#error "CONFIG_RTW_MESH can't be enabled when kernel < 3.10.0\n"
#endif
#endif
struct rtw_wdev_invit_info {
u8 state; /* 0: req, 1:rep */
u8 peer_mac[ETH_ALEN];
u8 group_bssid[ETH_ALEN];
u8 active;
u8 token;
u8 flags;
u8 status;
u8 req_op_ch;
u8 rsp_op_ch;
};
#define rtw_wdev_invit_info_init(invit_info) \
do { \
(invit_info)->state = 0xff; \
_rtw_memset((invit_info)->peer_mac, 0, ETH_ALEN); \
_rtw_memset((invit_info)->group_bssid, 0, ETH_ALEN); \
(invit_info)->active = 0xff; \
(invit_info)->token = 0; \
(invit_info)->flags = 0x00; \
(invit_info)->status = 0xff; \
(invit_info)->req_op_ch = 0; \
(invit_info)->rsp_op_ch = 0; \
} while (0)
struct rtw_wdev_nego_info {
u8 state; /* 0: req, 1:rep, 2:conf */
u8 iface_addr[ETH_ALEN];
u8 peer_mac[ETH_ALEN];
u8 peer_iface_addr[ETH_ALEN];
u8 active;
u8 token;
u8 status;
u8 req_intent;
u8 req_op_ch;
u8 req_listen_ch;
u8 rsp_intent;
u8 rsp_op_ch;
u8 conf_op_ch;
};
#define rtw_wdev_nego_info_init(nego_info) \
do { \
(nego_info)->state = 0xff; \
_rtw_memset((nego_info)->iface_addr, 0, ETH_ALEN); \
_rtw_memset((nego_info)->peer_mac, 0, ETH_ALEN); \
_rtw_memset((nego_info)->peer_iface_addr, 0, ETH_ALEN); \
(nego_info)->active = 0xff; \
(nego_info)->token = 0; \
(nego_info)->status = 0xff; \
(nego_info)->req_intent = 0xff; \
(nego_info)->req_op_ch = 0; \
(nego_info)->req_listen_ch = 0; \
(nego_info)->rsp_intent = 0xff; \
(nego_info)->rsp_op_ch = 0; \
(nego_info)->conf_op_ch = 0; \
} while (0)
struct rtw_wdev_priv {
struct wireless_dev *rtw_wdev;
_adapter *padapter;
#if RTW_CFG80211_BLOCK_STA_DISCON_EVENT
u8 not_indic_disco;
#endif
struct cfg80211_scan_request *scan_request;
_lock scan_req_lock;
struct cfg80211_connect_params *connect_req;
_lock connect_req_lock;
struct net_device *pmon_ndev;/* for monitor interface */
char ifname_mon[IFNAMSIZ + 1]; /* interface name for monitor interface */
u8 p2p_enabled;
systime probe_resp_ie_update_time;
u8 provdisc_req_issued;
struct rtw_wdev_invit_info invit_info;
struct rtw_wdev_nego_info nego_info;
u8 bandroid_scan;
bool block;
bool block_scan;
/**
* mgmt_regs: bitmap of management frame subtypes registered for the
* given interface
* mcast_mgmt_regs: mcast RX is needed on this interface for these
* subtypes
*/
u32 mgmt_regs;
/* u32 mcast_mgmt_regs; */
u8 is_mgmt_tx;
u16 mgmt_tx_cookie;
_mutex roch_mutex;
#ifdef CONFIG_CONCURRENT_MODE
ATOMIC_T switch_ch_to;
#endif
#if defined(CONFIG_RTW_CFGVENDOR_RANDOM_MAC_OUI) || defined(CONFIG_RTW_SCAN_RAND)
u8 pno_mac_addr[ETH_ALEN];
u16 pno_scan_seq_num;
#endif
#ifdef CONFIG_RTW_CFGVENDOR_RSSIMONITOR
s8 rssi_monitor_max;
s8 rssi_monitor_min;
u8 rssi_monitor_enable;
#endif
};
enum external_auth_action {
EXTERNAL_AUTH_START,
EXTERNAL_AUTH_ABORT,
};
struct rtw_external_auth_params {
enum external_auth_action action;
u8 bssid[ETH_ALEN]__aligned(2);
struct cfg80211_ssid ssid;
unsigned int key_mgmt_suite;
u16 status;
u8 pmkid[PMKID_LEN];
};
bool rtw_cfg80211_is_connect_requested(_adapter *adapter);
#if RTW_CFG80211_BLOCK_STA_DISCON_EVENT
#define rtw_wdev_not_indic_disco(rtw_wdev_data) ((rtw_wdev_data)->not_indic_disco)
#define rtw_wdev_set_not_indic_disco(rtw_wdev_data, val) do { (rtw_wdev_data)->not_indic_disco = (val); } while (0)
#else
#define rtw_wdev_not_indic_disco(rtw_wdev_data) 0
#define rtw_wdev_set_not_indic_disco(rtw_wdev_data, val) do {} while (0)
#endif
#define rtw_wdev_free_connect_req(rtw_wdev_data) \
do { \
if ((rtw_wdev_data)->connect_req) { \
rtw_mfree((u8 *)(rtw_wdev_data)->connect_req, sizeof(*(rtw_wdev_data)->connect_req)); \
(rtw_wdev_data)->connect_req = NULL; \
} \
} while (0)
#define wdev_to_ndev(w) ((w)->netdev)
#define wdev_to_wiphy(w) ((w)->wiphy)
#define ndev_to_wdev(n) ((n)->ieee80211_ptr)
struct rtw_wiphy_data {
struct dvobj_priv *dvobj;
#ifndef RTW_SINGLE_WIPHY
_adapter *adapter;
#endif
#if defined(RTW_DEDICATED_P2P_DEVICE)
struct wireless_dev *pd_wdev; /* P2P device wdev */
#endif
s16 txpwr_total_lmt_mbm; /* EIRP */
s16 txpwr_total_target_mbm; /* EIRP */
};
#define rtw_wiphy_priv(wiphy) ((struct rtw_wiphy_data *)wiphy_priv(wiphy))
#define wiphy_to_dvobj(wiphy) (((struct rtw_wiphy_data *)wiphy_priv(wiphy))->dvobj)
#ifdef RTW_SINGLE_WIPHY
#define wiphy_to_adapter(wiphy) (dvobj_get_primary_adapter(wiphy_to_dvobj(wiphy)))
#else
#define wiphy_to_adapter(wiphy) (((struct rtw_wiphy_data *)wiphy_priv(wiphy))->adapter)
#endif
#if defined(RTW_DEDICATED_P2P_DEVICE)
#define wiphy_to_pd_wdev(wiphy) (rtw_wiphy_priv(wiphy)->pd_wdev)
#else
#define wiphy_to_pd_wdev(wiphy) NULL
#endif
#define WIPHY_FMT "%s"
#define WIPHY_ARG(wiphy) wiphy_name(wiphy)
#define FUNC_WIPHY_FMT "%s("WIPHY_FMT")"
#define FUNC_WIPHY_ARG(wiphy) __func__, WIPHY_ARG(wiphy)
#define SET_CFG80211_MGMT_REGS(w, t) (w |= BIT(t >> 4))
#define CLR_CFG80211_MGMT_REGS(w, t) (w &= (~BIT(t >> 4)))
#define GET_CFG80211_MGMT_REGS(w, t) ((w & BIT(t >> 4)) > 0)
#define SET_CFG80211_REPORT_MGMT(w, t) (SET_CFG80211_MGMT_REGS(w->mgmt_regs, t))
#define CLR_CFG80211_REPORT_MGMT(w, t) (CLR_CFG80211_MGMT_REGS(w->mgmt_regs, t))
#define GET_CFG80211_REPORT_MGMT(w, t) (GET_CFG80211_MGMT_REGS(w->mgmt_regs, t))
struct wiphy *rtw_wiphy_alloc(_adapter *padapter, struct device *dev);
void rtw_wiphy_free(struct wiphy *wiphy);
int rtw_wiphy_register(struct wiphy *wiphy);
void rtw_wiphy_unregister(struct wiphy *wiphy);
int rtw_wdev_alloc(_adapter *padapter, struct wiphy *wiphy);
void rtw_wdev_free(struct wireless_dev *wdev);
void rtw_wdev_unregister(struct wireless_dev *wdev);
int rtw_cfg80211_ndev_res_alloc(_adapter *adapter);
void rtw_cfg80211_ndev_res_free(_adapter *adapter);
int rtw_cfg80211_ndev_res_register(_adapter *adapter);
void rtw_cfg80211_ndev_res_unregister(_adapter *adapter);
int rtw_cfg80211_dev_res_alloc(struct dvobj_priv *dvobj);
void rtw_cfg80211_dev_res_free(struct dvobj_priv *dvobj);
int rtw_cfg80211_dev_res_register(struct dvobj_priv *dvobj);
void rtw_cfg80211_dev_res_unregister(struct dvobj_priv *dvobj);
s16 rtw_cfg80211_dev_get_total_txpwr_lmt_mbm(struct dvobj_priv *dvobj);
s16 rtw_cfg80211_dev_get_total_txpwr_target_mbm(struct dvobj_priv *dvobj);
void rtw_cfg80211_init_wdev_data(_adapter *padapter);
void rtw_cfg80211_unlink_bss(_adapter *padapter, struct wlan_network *pnetwork);
void rtw_cfg80211_surveydone_event_callback(_adapter *padapter);
struct cfg80211_bss *rtw_cfg80211_inform_bss(_adapter *padapter, struct wlan_network *pnetwork);
int rtw_cfg80211_check_bss(_adapter *padapter);
void rtw_cfg80211_ibss_indicate_connect(_adapter *padapter);
void rtw_cfg80211_indicate_connect(_adapter *padapter);
void rtw_cfg80211_indicate_disconnect(_adapter *padapter, u16 reason, u8 locally_generated);
void rtw_cfg80211_indicate_scan_done(_adapter *adapter, bool aborted);
u32 rtw_cfg80211_wait_scan_req_empty(_adapter *adapter, u32 timeout_ms);
#ifdef CONFIG_CONCURRENT_MODE
u8 rtw_cfg80211_scan_via_buddy(_adapter *padapter, struct cfg80211_scan_request *request);
void rtw_cfg80211_indicate_scan_done_for_buddy(_adapter *padapter, bool bscan_aborted);
#endif
#ifdef CONFIG_AP_MODE
void rtw_cfg80211_indicate_sta_assoc(_adapter *padapter, u8 *pmgmt_frame, uint frame_len);
void rtw_cfg80211_indicate_sta_disassoc(_adapter *padapter, const u8 *da, unsigned short reason);
int rtw_cfg80211_set_mgnt_wpsp2pie(struct net_device *net, char *buf, int len, int type);
#endif /* CONFIG_AP_MODE */
void rtw_cfg80211_set_is_roch(_adapter *adapter, bool val);
bool rtw_cfg80211_get_is_roch(_adapter *adapter);
bool rtw_cfg80211_is_ro_ch_once(_adapter *adapter);
void rtw_cfg80211_set_last_ro_ch_time(_adapter *adapter);
s32 rtw_cfg80211_get_last_ro_ch_passing_ms(_adapter *adapter);
#ifdef CONFIG_P2P
int rtw_cfg80211_iface_has_p2p_group_cap(_adapter *adapter);
int rtw_cfg80211_is_p2p_scan(_adapter *adapter);
#if defined(RTW_DEDICATED_P2P_DEVICE)
int rtw_cfg80211_redirect_pd_wdev(struct wiphy *wiphy, u8 *ra, struct wireless_dev **wdev);
int rtw_cfg80211_is_scan_by_pd_wdev(_adapter *adapter);
int rtw_pd_iface_alloc(struct wiphy *wiphy, const char *name, struct wireless_dev **pd_wdev);
void rtw_pd_iface_free(struct wiphy *wiphy);
#endif
#endif /* CONFIG_P2P */
void rtw_cfg80211_set_is_mgmt_tx(_adapter *adapter, u8 val);
u8 rtw_cfg80211_get_is_mgmt_tx(_adapter *adapter);
u8 rtw_mgnt_tx_handler(_adapter *adapter, u8 *buf);
void rtw_cfg80211_issue_p2p_provision_request(_adapter *padapter, const u8 *buf, size_t len);
void rtw_cfg80211_rx_p2p_action_public(_adapter *padapter, union recv_frame *rframe);
void rtw_cfg80211_rx_action_p2p(_adapter *padapter, union recv_frame *rframe);
void rtw_cfg80211_rx_action(_adapter *adapter, union recv_frame *rframe, const char *msg);
void rtw_cfg80211_rx_mframe(_adapter *adapter, union recv_frame *rframe, const char *msg);
void rtw_cfg80211_rx_probe_request(_adapter *padapter, union recv_frame *rframe);
void rtw_cfg80211_external_auth_request(_adapter *padapter, union recv_frame *rframe);
void rtw_cfg80211_external_auth_status(struct wiphy *wiphy, struct net_device *dev,
struct rtw_external_auth_params *params);
bool rtw_cfg80211_pwr_mgmt(_adapter *adapter);
#ifdef CONFIG_RTW_80211K
void rtw_cfg80211_rx_rrm_action(_adapter *adapter, union recv_frame *rframe);
#endif
#ifdef CONFIG_RFKILL_POLL
void rtw_cfg80211_init_rfkill(struct wiphy *wiphy);
void rtw_cfg80211_deinit_rfkill(struct wiphy *wiphy);
#endif
#if (LINUX_VERSION_CODE < KERNEL_VERSION(3, 4, 0)) && !defined(COMPAT_KERNEL_RELEASE)
#define rtw_cfg80211_rx_mgmt(wdev, freq, sig_dbm, buf, len, gfp) cfg80211_rx_mgmt(wdev_to_ndev(wdev), freq, buf, len, gfp)
#elif (LINUX_VERSION_CODE < KERNEL_VERSION(3, 6, 0))
#define rtw_cfg80211_rx_mgmt(wdev, freq, sig_dbm, buf, len, gfp) cfg80211_rx_mgmt(wdev_to_ndev(wdev), freq, sig_dbm, buf, len, gfp)
#elif (LINUX_VERSION_CODE < KERNEL_VERSION(3, 12, 0))
#define rtw_cfg80211_rx_mgmt(wdev, freq, sig_dbm, buf, len, gfp) cfg80211_rx_mgmt(wdev, freq, sig_dbm, buf, len, gfp)
#elif (LINUX_VERSION_CODE < KERNEL_VERSION(3 , 18 , 0))
#define rtw_cfg80211_rx_mgmt(wdev , freq , sig_dbm , buf , len , gfp) cfg80211_rx_mgmt(wdev , freq , sig_dbm , buf , len , 0 , gfp)
#else
#define rtw_cfg80211_rx_mgmt(wdev , freq , sig_dbm , buf , len , gfp) cfg80211_rx_mgmt(wdev , freq , sig_dbm , buf , len , 0)
#endif
#if (LINUX_VERSION_CODE < KERNEL_VERSION(3, 4, 0)) && !defined(COMPAT_KERNEL_RELEASE)
#define rtw_cfg80211_send_rx_assoc(adapter, bss, buf, len) cfg80211_send_rx_assoc((adapter)->pnetdev, buf, len)
#else
#define rtw_cfg80211_send_rx_assoc(adapter, bss, buf, len) cfg80211_send_rx_assoc((adapter)->pnetdev, bss, buf, len)
#endif
#if (LINUX_VERSION_CODE < KERNEL_VERSION(3, 6, 0))
#define rtw_cfg80211_mgmt_tx_status(wdev, cookie, buf, len, ack, gfp) cfg80211_mgmt_tx_status(wdev_to_ndev(wdev), cookie, buf, len, ack, gfp)
#else
#define rtw_cfg80211_mgmt_tx_status(wdev, cookie, buf, len, ack, gfp) cfg80211_mgmt_tx_status(wdev, cookie, buf, len, ack, gfp)
#endif
#if (LINUX_VERSION_CODE < KERNEL_VERSION(3, 6, 0))
#define rtw_cfg80211_ready_on_channel(wdev, cookie, chan, channel_type, duration, gfp) cfg80211_ready_on_channel(wdev_to_ndev(wdev), cookie, chan, channel_type, duration, gfp)
#define rtw_cfg80211_remain_on_channel_expired(wdev, cookie, chan, chan_type, gfp) cfg80211_remain_on_channel_expired(wdev_to_ndev(wdev), cookie, chan, chan_type, gfp)
#elif (LINUX_VERSION_CODE < KERNEL_VERSION(3, 8, 0))
#define rtw_cfg80211_ready_on_channel(wdev, cookie, chan, channel_type, duration, gfp) cfg80211_ready_on_channel(wdev, cookie, chan, channel_type, duration, gfp)
#define rtw_cfg80211_remain_on_channel_expired(wdev, cookie, chan, chan_type, gfp) cfg80211_remain_on_channel_expired(wdev, cookie, chan, chan_type, gfp)
#else
#define rtw_cfg80211_ready_on_channel(wdev, cookie, chan, channel_type, duration, gfp) cfg80211_ready_on_channel(wdev, cookie, chan, duration, gfp)
#define rtw_cfg80211_remain_on_channel_expired(wdev, cookie, chan, chan_type, gfp) cfg80211_remain_on_channel_expired(wdev, cookie, chan, gfp)
#endif
#define rtw_cfg80211_connect_result(wdev, bssid, req_ie, req_ie_len, resp_ie, resp_ie_len, status, gfp) cfg80211_connect_result(wdev_to_ndev(wdev), bssid, req_ie, req_ie_len, resp_ie, resp_ie_len, status, gfp)
#if (LINUX_VERSION_CODE < KERNEL_VERSION(4, 2, 0))
#define rtw_cfg80211_disconnected(wdev, reason, ie, ie_len, locally_generated, gfp) cfg80211_disconnected(wdev_to_ndev(wdev), reason, ie, ie_len, gfp)
#else
#define rtw_cfg80211_disconnected(wdev, reason, ie, ie_len, locally_generated, gfp) cfg80211_disconnected(wdev_to_ndev(wdev), reason, ie, ie_len, locally_generated, gfp)
#endif
#ifdef CONFIG_RTW_80211R
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 10, 0))
#define rtw_cfg80211_ft_event(adapter, parm) cfg80211_ft_event((adapter)->pnetdev, parm)
#else
#error "Cannot support FT for KERNEL_VERSION < 3.10\n"
#endif
#endif
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 0, 0))
#define rtw_cfg80211_notify_new_peer_candidate(wdev, addr, ie, ie_len, sig_dbm, gfp) cfg80211_notify_new_peer_candidate(wdev_to_ndev(wdev), addr, ie, ie_len, sig_dbm, gfp)
#elif (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 0, 0))
#define rtw_cfg80211_notify_new_peer_candidate(wdev, addr, ie, ie_len, sig_dbm, gfp) cfg80211_notify_new_peer_candidate(wdev_to_ndev(wdev), addr, ie, ie_len, gfp)
#endif
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 5, 0))
u8 rtw_cfg80211_ch_switch_notify(_adapter *adapter, u8 ch, u8 bw, u8 offset, u8 ht, bool started);
#endif
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27)) && (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 31))
#define IEEE80211_CHAN_NO_HT40PLUS IEEE80211_CHAN_NO_FAT_ABOVE
#define IEEE80211_CHAN_NO_HT40MINUS IEEE80211_CHAN_NO_FAT_BELOW
#endif
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 26)) && (LINUX_VERSION_CODE < KERNEL_VERSION(4, 7, 0))
#define NL80211_BAND_2GHZ IEEE80211_BAND_2GHZ
#define NL80211_BAND_5GHZ IEEE80211_BAND_5GHZ
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 6, 0))
#define NL80211_BAND_60GHZ IEEE80211_BAND_60GHZ
#endif
#define NUM_NL80211_BANDS IEEE80211_NUM_BANDS
#endif
#define rtw_band_to_nl80211_band(band) \
(band == BAND_ON_2_4G) ? NL80211_BAND_2GHZ : \
(band == BAND_ON_5G) ? NL80211_BAND_5GHZ : NUM_NL80211_BANDS
#if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 36))
#define NL80211_TX_POWER_AUTOMATIC TX_POWER_AUTOMATIC
#define NL80211_TX_POWER_LIMITED TX_POWER_LIMITED
#define NL80211_TX_POWER_FIXED TX_POWER_FIXED
#endif
#include "wifi_regd.h"
#include "rtw_cfgvendor.h"
#endif /* __IOCTL_CFG80211_H__ */

13058
os_dep/linux/ioctl_linux.c Normal file

File diff suppressed because it is too large Load Diff

3530
os_dep/linux/ioctl_mp.c Normal file

File diff suppressed because it is too large Load Diff

444
os_dep/linux/mlme_linux.c Normal file
View File

@ -0,0 +1,444 @@
/******************************************************************************
*
* Copyright(c) 2007 - 2017 Realtek Corporation.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of version 2 of the GNU General Public License as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
*****************************************************************************/
#define _MLME_OSDEP_C_
#include <drv_types.h>
#ifdef RTK_DMP_PLATFORM
void Linkup_workitem_callback(struct work_struct *work)
{
struct mlme_priv *pmlmepriv = container_of(work, struct mlme_priv, Linkup_workitem);
_adapter *padapter = container_of(pmlmepriv, _adapter, mlmepriv);
#if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 12))
kobject_uevent(&padapter->pnetdev->dev.kobj, KOBJ_LINKUP);
#else
kobject_hotplug(&padapter->pnetdev->class_dev.kobj, KOBJ_LINKUP);
#endif
}
void Linkdown_workitem_callback(struct work_struct *work)
{
struct mlme_priv *pmlmepriv = container_of(work, struct mlme_priv, Linkdown_workitem);
_adapter *padapter = container_of(pmlmepriv, _adapter, mlmepriv);
#if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 12))
kobject_uevent(&padapter->pnetdev->dev.kobj, KOBJ_LINKDOWN);
#else
kobject_hotplug(&padapter->pnetdev->class_dev.kobj, KOBJ_LINKDOWN);
#endif
}
#endif
extern void rtw_indicate_wx_assoc_event(_adapter *padapter);
extern void rtw_indicate_wx_disassoc_event(_adapter *padapter);
void rtw_os_indicate_connect(_adapter *adapter)
{
struct mlme_priv *pmlmepriv = &(adapter->mlmepriv);
#ifdef CONFIG_IOCTL_CFG80211
if ((check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE) == _TRUE) ||
(check_fwstate(pmlmepriv, WIFI_ADHOC_STATE) == _TRUE))
rtw_cfg80211_ibss_indicate_connect(adapter);
else
rtw_cfg80211_indicate_connect(adapter);
#endif /* CONFIG_IOCTL_CFG80211 */
rtw_indicate_wx_assoc_event(adapter);
#ifdef CONFIG_RTW_MESH
#if CONFIG_RTW_MESH_CTO_MGATE_CARRIER
if (!rtw_mesh_cto_mgate_required(adapter))
#endif
#endif
rtw_netif_carrier_on(adapter->pnetdev);
if (adapter->pid[2] != 0)
rtw_signal_process(adapter->pid[2], SIGALRM);
#ifdef RTK_DMP_PLATFORM
_set_workitem(&adapter->mlmepriv.Linkup_workitem);
#endif
}
extern void indicate_wx_scan_complete_event(_adapter *padapter);
void rtw_os_indicate_scan_done(_adapter *padapter, bool aborted)
{
#ifdef CONFIG_IOCTL_CFG80211
rtw_cfg80211_indicate_scan_done(padapter, aborted);
#endif
indicate_wx_scan_complete_event(padapter);
}
static RT_PMKID_LIST backupPMKIDList[NUM_PMKID_CACHE];
void rtw_reset_securitypriv(_adapter *adapter)
{
u8 backupPMKIDIndex = 0;
u8 backupTKIPCountermeasure = 0x00;
u32 backupTKIPcountermeasure_time = 0;
/* add for CONFIG_IEEE80211W, none 11w also can use */
_irqL irqL;
_enter_critical_bh(&adapter->security_key_mutex, &irqL);
if (adapter->securitypriv.dot11AuthAlgrthm == dot11AuthAlgrthm_8021X) { /* 802.1x */
u8 backup_sw_encrypt, backup_sw_decrypt;
backup_sw_encrypt = adapter->securitypriv.sw_encrypt;
backup_sw_decrypt = adapter->securitypriv.sw_decrypt;
/* Added by Albert 2009/02/18 */
/* We have to backup the PMK information for WiFi PMK Caching test item. */
/* */
/* Backup the btkip_countermeasure information. */
/* When the countermeasure is trigger, the driver have to disconnect with AP for 60 seconds. */
_rtw_memset(&backupPMKIDList[0], 0x00, sizeof(RT_PMKID_LIST) * NUM_PMKID_CACHE);
_rtw_memcpy(&backupPMKIDList[0], &adapter->securitypriv.PMKIDList[0], sizeof(RT_PMKID_LIST) * NUM_PMKID_CACHE);
backupPMKIDIndex = adapter->securitypriv.PMKIDIndex;
backupTKIPCountermeasure = adapter->securitypriv.btkip_countermeasure;
backupTKIPcountermeasure_time = adapter->securitypriv.btkip_countermeasure_time;
_rtw_memset((unsigned char *)&adapter->securitypriv, 0, sizeof(struct security_priv));
/* Added by Albert 2009/02/18 */
/* Restore the PMK information to securitypriv structure for the following connection. */
_rtw_memcpy(&adapter->securitypriv.PMKIDList[0], &backupPMKIDList[0], sizeof(RT_PMKID_LIST) * NUM_PMKID_CACHE);
adapter->securitypriv.PMKIDIndex = backupPMKIDIndex;
adapter->securitypriv.btkip_countermeasure = backupTKIPCountermeasure;
adapter->securitypriv.btkip_countermeasure_time = backupTKIPcountermeasure_time;
adapter->securitypriv.ndisauthtype = Ndis802_11AuthModeOpen;
adapter->securitypriv.ndisencryptstatus = Ndis802_11WEPDisabled;
adapter->securitypriv.extauth_status = WLAN_STATUS_UNSPECIFIED_FAILURE;
adapter->securitypriv.sw_encrypt = backup_sw_encrypt;
adapter->securitypriv.sw_decrypt = backup_sw_decrypt;
} else { /* reset values in securitypriv */
/* if(adapter->mlmepriv.fw_state & WIFI_STATION_STATE) */
/* { */
struct security_priv *psec_priv = &adapter->securitypriv;
psec_priv->dot11AuthAlgrthm = dot11AuthAlgrthm_Open; /* open system */
psec_priv->dot11PrivacyAlgrthm = _NO_PRIVACY_;
psec_priv->dot11PrivacyKeyIndex = 0;
psec_priv->dot118021XGrpPrivacy = _NO_PRIVACY_;
psec_priv->dot118021XGrpKeyid = 1;
psec_priv->ndisauthtype = Ndis802_11AuthModeOpen;
psec_priv->ndisencryptstatus = Ndis802_11WEPDisabled;
/* } */
psec_priv->extauth_status = WLAN_STATUS_UNSPECIFIED_FAILURE;
}
/* add for CONFIG_IEEE80211W, none 11w also can use */
_exit_critical_bh(&adapter->security_key_mutex, &irqL);
RTW_INFO(FUNC_ADPT_FMT" - End to Disconnect\n", FUNC_ADPT_ARG(adapter));
}
void rtw_os_indicate_disconnect(_adapter *adapter, u16 reason, u8 locally_generated)
{
/* RT_PMKID_LIST backupPMKIDList[NUM_PMKID_CACHE]; */
rtw_netif_carrier_off(adapter->pnetdev); /* Do it first for tx broadcast pkt after disconnection issue! */
#ifdef CONFIG_IOCTL_CFG80211
rtw_cfg80211_indicate_disconnect(adapter, reason, locally_generated);
#endif /* CONFIG_IOCTL_CFG80211 */
rtw_indicate_wx_disassoc_event(adapter);
#ifdef RTK_DMP_PLATFORM
_set_workitem(&adapter->mlmepriv.Linkdown_workitem);
#endif
/* modify for CONFIG_IEEE80211W, none 11w also can use the same command */
rtw_reset_securitypriv_cmd(adapter);
}
void rtw_report_sec_ie(_adapter *adapter, u8 authmode, u8 *sec_ie)
{
uint len;
u8 *buff, *p, i;
union iwreq_data wrqu;
buff = NULL;
if (authmode == _WPA_IE_ID_) {
buff = rtw_zmalloc(IW_CUSTOM_MAX);
if (NULL == buff) {
RTW_INFO(FUNC_ADPT_FMT ": alloc memory FAIL!!\n",
FUNC_ADPT_ARG(adapter));
return;
}
p = buff;
p += sprintf(p, "ASSOCINFO(ReqIEs=");
len = sec_ie[1] + 2;
len = (len < IW_CUSTOM_MAX) ? len : IW_CUSTOM_MAX;
for (i = 0; i < len; i++)
p += sprintf(p, "%02x", sec_ie[i]);
p += sprintf(p, ")");
_rtw_memset(&wrqu, 0, sizeof(wrqu));
wrqu.data.length = p - buff;
wrqu.data.length = (wrqu.data.length < IW_CUSTOM_MAX) ? wrqu.data.length : IW_CUSTOM_MAX;
#ifndef CONFIG_IOCTL_CFG80211
wireless_send_event(adapter->pnetdev, IWEVCUSTOM, &wrqu, buff);
#endif
rtw_mfree(buff, IW_CUSTOM_MAX);
}
}
#ifdef CONFIG_AP_MODE
void rtw_indicate_sta_assoc_event(_adapter *padapter, struct sta_info *psta)
{
union iwreq_data wrqu;
struct sta_priv *pstapriv = &padapter->stapriv;
if (psta == NULL)
return;
if (psta->cmn.aid > pstapriv->max_aid)
return;
if (pstapriv->sta_aid[psta->cmn.aid - 1] != psta)
return;
wrqu.addr.sa_family = ARPHRD_ETHER;
_rtw_memcpy(wrqu.addr.sa_data, psta->cmn.mac_addr, ETH_ALEN);
RTW_INFO("+rtw_indicate_sta_assoc_event\n");
#ifndef CONFIG_IOCTL_CFG80211
wireless_send_event(padapter->pnetdev, IWEVREGISTERED, &wrqu, NULL);
#endif
}
void rtw_indicate_sta_disassoc_event(_adapter *padapter, struct sta_info *psta)
{
union iwreq_data wrqu;
struct sta_priv *pstapriv = &padapter->stapriv;
if (psta == NULL)
return;
if (psta->cmn.aid > pstapriv->max_aid)
return;
if (pstapriv->sta_aid[psta->cmn.aid - 1] != psta)
return;
wrqu.addr.sa_family = ARPHRD_ETHER;
_rtw_memcpy(wrqu.addr.sa_data, psta->cmn.mac_addr, ETH_ALEN);
RTW_INFO("+rtw_indicate_sta_disassoc_event\n");
#ifndef CONFIG_IOCTL_CFG80211
wireless_send_event(padapter->pnetdev, IWEVEXPIRED, &wrqu, NULL);
#endif
}
#ifdef CONFIG_HOSTAPD_MLME
static int mgnt_xmit_entry(struct sk_buff *skb, struct net_device *pnetdev)
{
struct hostapd_priv *phostapdpriv = rtw_netdev_priv(pnetdev);
_adapter *padapter = (_adapter *)phostapdpriv->padapter;
/* RTW_INFO("%s\n", __FUNCTION__); */
return rtw_hal_hostap_mgnt_xmit_entry(padapter, skb);
}
static int mgnt_netdev_open(struct net_device *pnetdev)
{
struct hostapd_priv *phostapdpriv = rtw_netdev_priv(pnetdev);
RTW_INFO("mgnt_netdev_open: MAC Address:" MAC_FMT "\n", MAC_ARG(pnetdev->dev_addr));
init_usb_anchor(&phostapdpriv->anchored);
rtw_netif_wake_queue(pnetdev);
rtw_netif_carrier_on(pnetdev);
/* rtw_write16(phostapdpriv->padapter, 0x0116, 0x0100); */ /* only excluding beacon */
return 0;
}
static int mgnt_netdev_close(struct net_device *pnetdev)
{
struct hostapd_priv *phostapdpriv = rtw_netdev_priv(pnetdev);
RTW_INFO("%s\n", __FUNCTION__);
usb_kill_anchored_urbs(&phostapdpriv->anchored);
rtw_netif_carrier_off(pnetdev);
rtw_netif_stop_queue(pnetdev);
/* rtw_write16(phostapdpriv->padapter, 0x0116, 0x3f3f); */
return 0;
}
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 29))
static const struct net_device_ops rtl871x_mgnt_netdev_ops = {
.ndo_open = mgnt_netdev_open,
.ndo_stop = mgnt_netdev_close,
.ndo_start_xmit = mgnt_xmit_entry,
#if 0
.ndo_set_mac_address = r871x_net_set_mac_address,
.ndo_get_stats = r871x_net_get_stats,
.ndo_do_ioctl = r871x_mp_ioctl,
#endif
};
#endif
int hostapd_mode_init(_adapter *padapter)
{
unsigned char mac[ETH_ALEN];
struct hostapd_priv *phostapdpriv;
struct net_device *pnetdev;
pnetdev = rtw_alloc_etherdev(sizeof(struct hostapd_priv));
if (!pnetdev)
return -ENOMEM;
/* SET_MODULE_OWNER(pnetdev); */
ether_setup(pnetdev);
/* pnetdev->type = ARPHRD_IEEE80211; */
phostapdpriv = rtw_netdev_priv(pnetdev);
phostapdpriv->pmgnt_netdev = pnetdev;
phostapdpriv->padapter = padapter;
padapter->phostapdpriv = phostapdpriv;
/* pnetdev->init = NULL; */
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 29))
RTW_INFO("register rtl871x_mgnt_netdev_ops to netdev_ops\n");
pnetdev->netdev_ops = &rtl871x_mgnt_netdev_ops;
#else
pnetdev->open = mgnt_netdev_open;
pnetdev->stop = mgnt_netdev_close;
pnetdev->hard_start_xmit = mgnt_xmit_entry;
/* pnetdev->set_mac_address = r871x_net_set_mac_address; */
/* pnetdev->get_stats = r871x_net_get_stats; */
/* pnetdev->do_ioctl = r871x_mp_ioctl; */
#endif
pnetdev->watchdog_timeo = HZ; /* 1 second timeout */
/* pnetdev->wireless_handlers = NULL; */
if (dev_alloc_name(pnetdev, "mgnt.wlan%d") < 0)
RTW_INFO("hostapd_mode_init(): dev_alloc_name, fail!\n");
/* SET_NETDEV_DEV(pnetdev, pintfpriv->udev); */
mac[0] = 0x00;
mac[1] = 0xe0;
mac[2] = 0x4c;
mac[3] = 0x87;
mac[4] = 0x11;
mac[5] = 0x12;
_rtw_memcpy(pnetdev->dev_addr, mac, ETH_ALEN);
rtw_netif_carrier_off(pnetdev);
/* Tell the network stack we exist */
if (register_netdev(pnetdev) != 0) {
RTW_INFO("hostapd_mode_init(): register_netdev fail!\n");
if (pnetdev)
rtw_free_netdev(pnetdev);
}
return 0;
}
void hostapd_mode_unload(_adapter *padapter)
{
struct hostapd_priv *phostapdpriv = padapter->phostapdpriv;
struct net_device *pnetdev = phostapdpriv->pmgnt_netdev;
unregister_netdev(pnetdev);
rtw_free_netdev(pnetdev);
}
#endif
#endif

583
os_dep/linux/nlrtw.c Normal file
View File

@ -0,0 +1,583 @@
/******************************************************************************
*
* Copyright(c) 2007 - 2020 Realtek Corporation.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of version 2 of the GNU General Public License as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
*****************************************************************************/
#define _RTW_NLRTW_C_
#include <drv_types.h>
#include "nlrtw.h"
#ifdef CONFIG_RTW_NLRTW
#include <net/netlink.h>
#include <net/genetlink.h>
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 7, 0))
#include <uapi/linux/netlink.h>
#endif
enum nlrtw_cmds {
NLRTW_CMD_UNSPEC,
NLRTW_CMD_CHANNEL_UTILIZATION,
NLRTW_CMD_REG_CHANGE,
NLRTW_CMD_REG_BEACON_HINT,
NLRTW_CMD_RADAR_EVENT,
NLRTW_CMD_RADIO_OPMODE,
__NLRTW_CMD_AFTER_LAST,
NLRTW_CMD_MAX = __NLRTW_CMD_AFTER_LAST - 1
};
enum nlrtw_attrs {
NLRTW_ATTR_UNSPEC,
NLRTW_ATTR_WIPHY_NAME,
NLRTW_ATTR_CHANNEL_UTILIZATIONS,
NLRTW_ATTR_CHANNEL_UTILIZATION_THRESHOLD,
NLRTW_ATTR_CHANNEL_CENTER,
NLRTW_ATTR_CHANNEL_WIDTH,
NLRTW_ATTR_RADAR_EVENT,
NLRTW_ATTR_OP_CLASS,
NLRTW_ATTR_OP_CHANNEL,
NLRTW_ATTR_OP_TXPWR_MAX,
NLRTW_ATTR_IF_OPMODES,
__NLRTW_ATTR_AFTER_LAST,
NUM_NLRTW_ATTR = __NLRTW_ATTR_AFTER_LAST,
NLRTW_ATTR_MAX = __NLRTW_ATTR_AFTER_LAST - 1
};
enum nlrtw_ch_util_attrs {
__NLRTW_ATTR_CHANNEL_UTILIZATION_INVALID,
NLRTW_ATTR_CHANNEL_UTILIZATION_VALUE,
NLRTW_ATTR_CHANNEL_UTILIZATION_BSSID,
__NLRTW_ATTR_CHANNEL_UTILIZATION_AFTER_LAST,
NUM_NLRTW_ATTR_CHANNEL_UTILIZATION = __NLRTW_ATTR_CHANNEL_UTILIZATION_AFTER_LAST,
NLRTW_ATTR_CHANNEL_UTILIZATION_MAX = __NLRTW_ATTR_CHANNEL_UTILIZATION_AFTER_LAST - 1
};
enum nlrtw_radar_event {
NLRTW_RADAR_DETECTED,
NLRTW_RADAR_CAC_FINISHED,
NLRTW_RADAR_CAC_ABORTED,
NLRTW_RADAR_NOP_FINISHED,
NLRTW_RADAR_NOP_STARTED, /* NON_OCP started not by local radar detection */
};
enum nlrtw_if_opmode_attrs {
NLRTW_IF_OPMODE_UNSPEC,
NLRTW_IF_OPMODE_MACADDR,
NLRTW_IF_OPMODE_OP_CLASS,
NLRTW_IF_OPMODE_OP_CHANNEL,
__NLRTW_IF_OPMODE_ATTR_AFTER_LAST,
NUM_NLRTW_IF_OPMODE_ATTR = __NLRTW_IF_OPMODE_ATTR_AFTER_LAST,
NLRTW_IF_OPMODE_ATTR_MAX = __NLRTW_IF_OPMODE_ATTR_AFTER_LAST - 1
};
static int nlrtw_ch_util_set(struct sk_buff *skb, struct genl_info *info)
{
unsigned int msg;
if (!info->attrs[NLRTW_ATTR_CHANNEL_UTILIZATION_THRESHOLD])
return -EINVAL;
msg = nla_get_u8(info->attrs[NLRTW_ATTR_CHANNEL_UTILIZATION_THRESHOLD]);
return 0;
}
static struct nla_policy nlrtw_genl_policy[NUM_NLRTW_ATTR] = {
[NLRTW_ATTR_CHANNEL_UTILIZATION_THRESHOLD] = { .type = NLA_U8 },
};
static struct genl_ops nlrtw_genl_ops[] = {
{
.cmd = NLRTW_CMD_CHANNEL_UTILIZATION,
.flags = 0,
#if LINUX_VERSION_CODE < KERNEL_VERSION(5, 2, 0)
.policy = nlrtw_genl_policy,
#endif
.doit = nlrtw_ch_util_set,
.dumpit = NULL,
},
};
enum nlrtw_multicast_groups {
NLRTW_MCGRP_DEFAULT,
};
static struct genl_multicast_group nlrtw_genl_mcgrp[] = {
[NLRTW_MCGRP_DEFAULT] = { .name = "nlrtw_default" },
};
/* family definition */
static struct genl_family nlrtw_genl_family = {
.hdrsize = 0,
.name = "nlrtw_"DRV_NAME,
.version = 1,
.maxattr = NLRTW_ATTR_MAX,
#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 2, 0)
.policy = nlrtw_genl_policy,
#endif
.netnsok = true,
#if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 10, 12)
.module = THIS_MODULE,
#endif
#if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 13, 0)
.ops = nlrtw_genl_ops,
.n_ops = ARRAY_SIZE(nlrtw_genl_ops),
.mcgrps = nlrtw_genl_mcgrp,
.n_mcgrps = ARRAY_SIZE(nlrtw_genl_mcgrp),
#endif
};
static inline int nlrtw_multicast(const struct genl_family *family,
struct sk_buff *skb, u32 portid,
unsigned int group, gfp_t flags)
{
int ret;
#if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 13, 0)
ret = genlmsg_multicast(&nlrtw_genl_family, skb, portid, group, flags);
#else
ret = genlmsg_multicast(skb, portid, nlrtw_genl_mcgrp[group].id, flags);
#endif
return ret;
}
int rtw_nlrtw_ch_util_rpt(_adapter *adapter, u8 n_rpts, u8 *val, u8 **mac_addr)
{
struct sk_buff *skb = NULL;
void *msg_header = NULL;
struct nlattr *nl_ch_util, *nl_ch_utils;
struct wiphy *wiphy;
u8 i;
int ret;
wiphy = adapter_to_wiphy(adapter);
if (!wiphy)
return -EINVAL;
/* allocate memory */
skb = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
if (!skb) {
nlmsg_free(skb);
return -ENOMEM;
}
/* create the message headers */
msg_header = genlmsg_put(skb, 0, 0, &nlrtw_genl_family, 0,
NLRTW_CMD_CHANNEL_UTILIZATION);
if (!msg_header) {
ret = -ENOMEM;
goto err_out;
}
/* add attributes */
ret = nla_put_string(skb, NLRTW_ATTR_WIPHY_NAME, wiphy_name(wiphy));
nl_ch_utils = nla_nest_start(skb, NLRTW_ATTR_CHANNEL_UTILIZATIONS);
if (!nl_ch_utils) {
ret = -EMSGSIZE;
goto err_out;
}
for (i = 0; i < n_rpts; i++) {
nl_ch_util = nla_nest_start(skb, i);
if (!nl_ch_util) {
ret = -EMSGSIZE;
goto err_out;
}
ret = nla_put(skb, NLRTW_ATTR_CHANNEL_UTILIZATION_BSSID, ETH_ALEN, *(mac_addr + i));
if (ret != 0)
goto err_out;
ret = nla_put_u8(skb, NLRTW_ATTR_CHANNEL_UTILIZATION_VALUE, *(val + i));
if (ret != 0)
goto err_out;
nla_nest_end(skb, nl_ch_util);
}
nla_nest_end(skb, nl_ch_utils);
/* finalize the message */
genlmsg_end(skb, msg_header);
ret = nlrtw_multicast(&nlrtw_genl_family, skb, 0, NLRTW_MCGRP_DEFAULT, GFP_KERNEL);
if (ret == -ESRCH) {
RTW_INFO("[%s] return ESRCH(No such process)."
" Maybe no process waits for this msg\n", __func__);
return ret;
} else if (ret != 0) {
RTW_INFO("[%s] ret = %d\n", __func__, ret);
return ret;
}
return 0;
err_out:
nlmsg_free(skb);
return ret;
}
int rtw_nlrtw_reg_change_event(_adapter *adapter)
{
struct sk_buff *skb = NULL;
void *msg_header = NULL;
struct wiphy *wiphy;
u8 i;
int ret;
wiphy = adapter_to_wiphy(adapter);
if (!wiphy) {
ret = -EINVAL;
goto err_out;
}
/* allocate memory */
skb = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
if (!skb) {
ret = -ENOMEM;
goto err_out;
}
/* create the message headers */
msg_header = genlmsg_put(skb, 0, 0, &nlrtw_genl_family, 0, NLRTW_CMD_REG_CHANGE);
if (!msg_header) {
ret = -ENOMEM;
goto err_out;
}
/* add attributes */
ret = nla_put_string(skb, NLRTW_ATTR_WIPHY_NAME, wiphy_name(wiphy));
if (ret)
goto err_out;
/* finalize the message */
genlmsg_end(skb, msg_header);
ret = nlrtw_multicast(&nlrtw_genl_family, skb, 0, NLRTW_MCGRP_DEFAULT, GFP_KERNEL);
if (ret == -ESRCH) {
RTW_DBG(FUNC_WIPHY_FMT" return -ESRCH(No such process)."
" Maybe no process waits for this msg\n", FUNC_WIPHY_ARG(wiphy));
return ret;
} else if (ret != 0) {
RTW_WARN(FUNC_WIPHY_FMT" return %d\n", FUNC_WIPHY_ARG(wiphy), ret);
return ret;
}
return 0;
err_out:
if (skb)
nlmsg_free(skb);
return ret;
}
int rtw_nlrtw_reg_beacon_hint_event(_adapter *adapter)
{
struct sk_buff *skb = NULL;
void *msg_header = NULL;
struct wiphy *wiphy;
u8 i;
int ret;
wiphy = adapter_to_wiphy(adapter);
if (!wiphy) {
ret = -EINVAL;
goto err_out;
}
/* allocate memory */
skb = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
if (!skb) {
ret = -ENOMEM;
goto err_out;
}
/* create the message headers */
msg_header = genlmsg_put(skb, 0, 0, &nlrtw_genl_family, 0, NLRTW_CMD_REG_BEACON_HINT);
if (!msg_header) {
ret = -ENOMEM;
goto err_out;
}
/* add attributes */
ret = nla_put_string(skb, NLRTW_ATTR_WIPHY_NAME, wiphy_name(wiphy));
if (ret)
goto err_out;
/* finalize the message */
genlmsg_end(skb, msg_header);
ret = nlrtw_multicast(&nlrtw_genl_family, skb, 0, NLRTW_MCGRP_DEFAULT, GFP_KERNEL);
if (ret == -ESRCH) {
RTW_DBG(FUNC_WIPHY_FMT" return -ESRCH(No such process)."
" Maybe no process waits for this msg\n", FUNC_WIPHY_ARG(wiphy));
return ret;
} else if (ret != 0) {
RTW_WARN(FUNC_WIPHY_FMT" return %d\n", FUNC_WIPHY_ARG(wiphy), ret);
return ret;
}
return 0;
err_out:
if (skb)
nlmsg_free(skb);
return ret;
}
#ifdef CONFIG_DFS_MASTER
static int _rtw_nlrtw_radar_event(_adapter *adapter, enum nlrtw_radar_event evt_type, u8 cch, u8 bw)
{
struct sk_buff *skb = NULL;
void *msg_header = NULL;
struct wiphy *wiphy;
u8 i;
int ret;
wiphy = adapter_to_wiphy(adapter);
if (!wiphy) {
ret = -EINVAL;
goto err_out;
}
/* allocate memory */
skb = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
if (!skb) {
ret = -ENOMEM;
goto err_out;
}
/* create the message headers */
msg_header = genlmsg_put(skb, 0, 0, &nlrtw_genl_family, 0, NLRTW_CMD_RADAR_EVENT);
if (!msg_header) {
ret = -ENOMEM;
goto err_out;
}
/* add attributes */
ret = nla_put_string(skb, NLRTW_ATTR_WIPHY_NAME, wiphy_name(wiphy));
if (ret)
goto err_out;
ret = nla_put_u8(skb, NLRTW_ATTR_RADAR_EVENT, (uint8_t)evt_type);
if (ret != 0)
goto err_out;
ret = nla_put_u8(skb, NLRTW_ATTR_CHANNEL_CENTER, cch);
if (ret != 0)
goto err_out;
ret = nla_put_u8(skb, NLRTW_ATTR_CHANNEL_WIDTH, bw);
if (ret != 0)
goto err_out;
/* finalize the message */
genlmsg_end(skb, msg_header);
ret = nlrtw_multicast(&nlrtw_genl_family, skb, 0, NLRTW_MCGRP_DEFAULT, GFP_KERNEL);
if (ret == -ESRCH) {
RTW_DBG(FUNC_WIPHY_FMT" return -ESRCH(No such process)."
" Maybe no process waits for this msg\n", FUNC_WIPHY_ARG(wiphy));
return ret;
} else if (ret != 0) {
RTW_WARN(FUNC_WIPHY_FMT" return %d\n", FUNC_WIPHY_ARG(wiphy), ret);
return ret;
}
return 0;
err_out:
if (skb)
nlmsg_free(skb);
return ret;
}
int rtw_nlrtw_radar_detect_event(_adapter *adapter, u8 cch, u8 bw)
{
return _rtw_nlrtw_radar_event(adapter, NLRTW_RADAR_DETECTED, cch, bw);
}
int rtw_nlrtw_cac_finish_event(_adapter *adapter, u8 cch, u8 bw)
{
return _rtw_nlrtw_radar_event(adapter, NLRTW_RADAR_CAC_FINISHED, cch, bw);
}
int rtw_nlrtw_cac_abort_event(_adapter *adapter, u8 cch, u8 bw)
{
return _rtw_nlrtw_radar_event(adapter, NLRTW_RADAR_CAC_ABORTED, cch, bw);
}
int rtw_nlrtw_nop_finish_event(_adapter *adapter, u8 cch, u8 bw)
{
return _rtw_nlrtw_radar_event(adapter, NLRTW_RADAR_NOP_FINISHED, cch, bw);
}
int rtw_nlrtw_nop_start_event(_adapter *adapter, u8 cch, u8 bw)
{
return _rtw_nlrtw_radar_event(adapter, NLRTW_RADAR_NOP_STARTED, cch, bw);
}
#endif /* CONFIG_DFS_MASTER */
int rtw_nlrtw_radio_opmode_notify(struct rf_ctl_t *rfctl)
{
struct dvobj_priv *dvobj = rfctl_to_dvobj(rfctl);
_adapter *iface;
struct sk_buff *skb = NULL;
void *msg_header = NULL;
struct nlattr *nl_if_opmodes, *nl_if_opmode;
struct wiphy *wiphy;
u16 op_txpwr_max_u16;
u8 i;
int ret;
wiphy = dvobj_to_wiphy(dvobj);
if (!wiphy) {
ret = -EINVAL;
goto err_out;
}
/* allocate memory */
skb = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
if (!skb) {
ret = -ENOMEM;
goto err_out;
}
/* create the message headers */
msg_header = genlmsg_put(skb, 0, 0, &nlrtw_genl_family, 0, NLRTW_CMD_RADIO_OPMODE);
if (!msg_header) {
ret = -ENOBUFS;
goto err_out;
}
/* add attributes */
ret = nla_put_string(skb, NLRTW_ATTR_WIPHY_NAME, wiphy_name(wiphy));
if (ret)
goto err_out;
ret = nla_put_u8(skb, NLRTW_ATTR_OP_CLASS, rfctl->op_class);
if (ret != 0)
goto err_out;
ret = nla_put_u8(skb, NLRTW_ATTR_OP_CHANNEL, rfctl->op_ch);
if (ret != 0)
goto err_out;
*((s16 *)&op_txpwr_max_u16) = rfctl->op_txpwr_max;
ret = nla_put_u16(skb, NLRTW_ATTR_OP_TXPWR_MAX, op_txpwr_max_u16);
if (ret != 0)
goto err_out;
if (0)
RTW_INFO("radio: %u,%u %d\n", rfctl->op_class, rfctl->op_ch, rfctl->op_txpwr_max);
nl_if_opmodes = nla_nest_start(skb, NLRTW_ATTR_IF_OPMODES);
if (!nl_if_opmodes) {
ret = -ENOBUFS;
goto err_out;
}
for (i = 0; i < dvobj->iface_nums; i++) {
if (!dvobj->padapters[i])
continue;
iface = dvobj->padapters[i];
if (!rfctl->if_op_class[i] || !rfctl->if_op_ch[i])
continue;
if (0)
RTW_INFO(ADPT_FMT": %u,%u\n", ADPT_ARG(iface), rfctl->if_op_class[i], rfctl->if_op_ch[i]);
nl_if_opmode = nla_nest_start(skb, i + 1);
if (!nl_if_opmode) {
ret = -ENOBUFS;
goto err_out;
}
ret = nla_put(skb, NLRTW_IF_OPMODE_MACADDR, ETH_ALEN, adapter_mac_addr(iface));
if (ret != 0)
goto err_out;
ret = nla_put_u8(skb, NLRTW_IF_OPMODE_OP_CLASS, rfctl->if_op_class[i]);
if (ret != 0)
goto err_out;
ret = nla_put_u8(skb, NLRTW_IF_OPMODE_OP_CHANNEL, rfctl->if_op_ch[i]);
if (ret != 0)
goto err_out;
nla_nest_end(skb, nl_if_opmode);
}
nla_nest_end(skb, nl_if_opmodes);
/* finalize the message */
genlmsg_end(skb, msg_header);
ret = nlrtw_multicast(&nlrtw_genl_family, skb, 0, NLRTW_MCGRP_DEFAULT, GFP_KERNEL);
if (ret == -ESRCH) {
RTW_DBG(FUNC_WIPHY_FMT" return -ESRCH(No such process)."
" Maybe no process waits for this msg\n", FUNC_WIPHY_ARG(wiphy));
return ret;
} else if (ret != 0) {
RTW_WARN(FUNC_WIPHY_FMT" return %d\n", FUNC_WIPHY_ARG(wiphy), ret);
return ret;
}
return 0;
err_out:
if (skb)
nlmsg_free(skb);
return ret;
}
int rtw_nlrtw_init(void)
{
int err;
#if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 13, 0)
err = genl_register_family(&nlrtw_genl_family);
if (err)
return err;
#else
err = genl_register_family_with_ops(&nlrtw_genl_family, nlrtw_genl_ops, ARRAY_SIZE(nlrtw_genl_ops));
if (err)
return err;
err = genl_register_mc_group(&nlrtw_genl_family, &nlrtw_genl_mcgrp[0]);
if (err) {
genl_unregister_family(&nlrtw_genl_family);
return err;
}
#endif
RTW_INFO("[%s] %s\n", __func__, nlrtw_genl_family.name);
return 0;
}
int rtw_nlrtw_deinit(void)
{
int err;
err = genl_unregister_family(&nlrtw_genl_family);
RTW_INFO("[%s] err = %d\n", __func__, err);
return err;
}
#endif /* CONFIG_RTW_NLRTW */

48
os_dep/linux/nlrtw.h Normal file
View File

@ -0,0 +1,48 @@
/******************************************************************************
*
* Copyright(c) 2007 - 2020 Realtek Corporation.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of version 2 of the GNU General Public License as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
*****************************************************************************/
#ifndef __RTW_NLRTW_H_
#define __RTW_NLRTW_H_
#ifdef CONFIG_RTW_NLRTW
int rtw_nlrtw_init(void);
int rtw_nlrtw_deinit(void);
int rtw_nlrtw_ch_util_rpt(_adapter *adapter, u8 n_rpts, u8 *val, u8 **mac_addr);
int rtw_nlrtw_reg_change_event(_adapter *adapter);
int rtw_nlrtw_reg_beacon_hint_event(_adapter *adapter);
int rtw_nlrtw_radio_opmode_notify(struct rf_ctl_t *rfctl);
#else
static inline int rtw_nlrtw_init(void) {return _FAIL;}
static inline int rtw_nlrtw_deinit(void) {return _FAIL;}
static inline int rtw_nlrtw_ch_util_rpt(_adapter *adapter, u8 n_rpts, u8 *val, u8 **mac_addr) {return _FAIL;}
static inline int rtw_nlrtw_reg_change_event(_adapter *adapter) {return _FAIL;}
static inline int rtw_nlrtw_reg_beacon_hint_event(_adapter *adapter) {return _FAIL;}
static inline int rtw_nlrtw_radio_opmode_notify(struct rf_ctl_t *rfctl) {return _FAIL;}
#endif /* CONFIG_RTW_NLRTW */
#if defined(CONFIG_RTW_NLRTW) && defined(CONFIG_DFS_MASTER)
int rtw_nlrtw_radar_detect_event(_adapter *adapter, u8 cch, u8 bw);
int rtw_nlrtw_cac_finish_event(_adapter *adapter, u8 cch, u8 bw);
int rtw_nlrtw_cac_abort_event(_adapter *adapter, u8 cch, u8 bw);
int rtw_nlrtw_nop_finish_event(_adapter *adapter, u8 cch, u8 bw);
int rtw_nlrtw_nop_start_event(_adapter *adapter, u8 cch, u8 bw);
#else
static inline int rtw_nlrtw_radar_detect_event(_adapter *adapter, u8 cch, u8 bw) {return _FAIL;}
static inline int rtw_nlrtw_cac_finish_event(_adapter *adapter, u8 cch, u8 bw) {return _FAIL;}
static inline int rtw_nlrtw_cac_abort_event(_adapter *adapter, u8 cch, u8 bw) {return _FAIL;}
static inline int rtw_nlrtw_nop_finish_event(_adapter *adapter, u8 cch, u8 bw) {return _FAIL;}
static inline int rtw_nlrtw_nop_start_event(_adapter *adapter, u8 cch, u8 bw) {return _FAIL;}
#endif /* defined(CONFIG_RTW_NLRTW) && defined(CONFIG_DFS_MASTER) */
#endif /* __RTW_NLRTW_H_ */

5768
os_dep/linux/os_intfs.c Normal file

File diff suppressed because it is too large Load Diff

738
os_dep/linux/recv_linux.c Normal file
View File

@ -0,0 +1,738 @@
/******************************************************************************
*
* Copyright(c) 2007 - 2017 Realtek Corporation.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of version 2 of the GNU General Public License as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
*****************************************************************************/
#define _RECV_OSDEP_C_
#include <drv_types.h>
int rtw_os_recvframe_duplicate_skb(_adapter *padapter, union recv_frame *pcloneframe, _pkt *pskb)
{
int res = _SUCCESS;
_pkt *pkt_copy = NULL;
if (pskb == NULL) {
RTW_INFO("%s [WARN] skb == NULL, drop frag frame\n", __func__);
return _FAIL;
}
#if 1
pkt_copy = rtw_skb_copy(pskb);
if (pkt_copy == NULL) {
RTW_INFO("%s [WARN] rtw_skb_copy fail , drop frag frame\n", __func__);
return _FAIL;
}
#else
pkt_copy = rtw_skb_clone(pskb);
if (pkt_copy == NULL) {
RTW_INFO("%s [WARN] rtw_skb_clone fail , drop frag frame\n", __func__);
return _FAIL;
}
#endif
pkt_copy->dev = padapter->pnetdev;
pcloneframe->u.hdr.pkt = pkt_copy;
pcloneframe->u.hdr.rx_head = pkt_copy->head;
pcloneframe->u.hdr.rx_data = pkt_copy->data;
pcloneframe->u.hdr.rx_end = skb_end_pointer(pkt_copy);
pcloneframe->u.hdr.rx_tail = skb_tail_pointer(pkt_copy);
pcloneframe->u.hdr.len = pkt_copy->len;
return res;
}
int rtw_os_alloc_recvframe(_adapter *padapter, union recv_frame *precvframe, u8 *pdata, _pkt *pskb)
{
int res = _SUCCESS;
u8 shift_sz = 0;
u32 skb_len, alloc_sz;
_pkt *pkt_copy = NULL;
struct rx_pkt_attrib *pattrib = &precvframe->u.hdr.attrib;
if (pdata == NULL) {
precvframe->u.hdr.pkt = NULL;
res = _FAIL;
return res;
}
/* Modified by Albert 20101213 */
/* For 8 bytes IP header alignment. */
shift_sz = pattrib->qos ? 6 : 0; /* Qos data, wireless lan header length is 26 */
skb_len = pattrib->pkt_len;
/* for first fragment packet, driver need allocate 1536+drvinfo_sz+RXDESC_SIZE to defrag packet. */
/* modify alloc_sz for recvive crc error packet by thomas 2011-06-02 */
if ((pattrib->mfrag == 1) && (pattrib->frag_num == 0)) {
/* alloc_sz = 1664; */ /* 1664 is 128 alignment. */
alloc_sz = (skb_len <= 1650) ? 1664 : (skb_len + 14);
} else {
alloc_sz = skb_len;
/* 6 is for IP header 8 bytes alignment in QoS packet case. */
/* 8 is for skb->data 4 bytes alignment. */
alloc_sz += 14;
}
pkt_copy = rtw_skb_alloc(alloc_sz);
if (pkt_copy) {
pkt_copy->dev = padapter->pnetdev;
pkt_copy->len = skb_len;
precvframe->u.hdr.pkt = pkt_copy;
precvframe->u.hdr.rx_head = pkt_copy->head;
precvframe->u.hdr.rx_end = pkt_copy->data + alloc_sz;
skb_reserve(pkt_copy, 8 - ((SIZE_PTR)(pkt_copy->data) & 7)); /* force pkt_copy->data at 8-byte alignment address */
skb_reserve(pkt_copy, shift_sz);/* force ip_hdr at 8-byte alignment address according to shift_sz. */
_rtw_memcpy(pkt_copy->data, pdata, skb_len);
precvframe->u.hdr.rx_data = precvframe->u.hdr.rx_tail = pkt_copy->data;
} else {
#if 0
{
rtw_free_recvframe(precvframe_if2, &precvpriv->free_recv_queue);
rtw_enqueue_recvbuf_to_head(precvbuf, &precvpriv->recv_buf_pending_queue);
/* The case of can't allocate skb is serious and may never be recovered,
once bDriverStopped is enable, this task should be stopped.*/
if (!rtw_is_drv_stopped(secondary_padapter))
#ifdef PLATFORM_LINUX
tasklet_schedule(&precvpriv->recv_tasklet);
#endif
return ret;
}
#endif
#ifdef CONFIG_USE_USB_BUFFER_ALLOC_RX
RTW_INFO("%s:can not allocate memory for skb copy\n", __func__);
precvframe->u.hdr.pkt = NULL;
/* rtw_free_recvframe(precvframe, pfree_recv_queue); */
/*exit_rtw_os_recv_resource_alloc;*/
res = _FAIL;
#else
if ((pattrib->mfrag == 1) && (pattrib->frag_num == 0)) {
RTW_INFO("%s: alloc_skb fail , drop frag frame\n", __FUNCTION__);
/* rtw_free_recvframe(precvframe, pfree_recv_queue); */
res = _FAIL;
goto exit_rtw_os_recv_resource_alloc;
}
if (pskb == NULL) {
res = _FAIL;
goto exit_rtw_os_recv_resource_alloc;
}
precvframe->u.hdr.pkt = rtw_skb_clone(pskb);
if (precvframe->u.hdr.pkt) {
precvframe->u.hdr.pkt->dev = padapter->pnetdev;
precvframe->u.hdr.rx_head = precvframe->u.hdr.rx_data = precvframe->u.hdr.rx_tail = pdata;
precvframe->u.hdr.rx_end = pdata + alloc_sz;
} else {
RTW_INFO("%s: rtw_skb_clone fail\n", __FUNCTION__);
/* rtw_free_recvframe(precvframe, pfree_recv_queue); */
/*exit_rtw_os_recv_resource_alloc;*/
res = _FAIL;
}
#endif
}
exit_rtw_os_recv_resource_alloc:
return res;
}
void rtw_os_free_recvframe(union recv_frame *precvframe)
{
if (precvframe->u.hdr.pkt) {
rtw_os_pkt_free(precvframe->u.hdr.pkt);
precvframe->u.hdr.pkt = NULL;
}
}
/* init os related resource in struct recv_priv */
int rtw_os_recv_resource_init(struct recv_priv *precvpriv, _adapter *padapter)
{
int res = _SUCCESS;
#ifdef CONFIG_RTW_NAPI
skb_queue_head_init(&precvpriv->rx_napi_skb_queue);
#endif /* CONFIG_RTW_NAPI */
return res;
}
/* alloc os related resource in union recv_frame */
int rtw_os_recv_resource_alloc(_adapter *padapter, union recv_frame *precvframe)
{
int res = _SUCCESS;
precvframe->u.hdr.pkt = NULL;
return res;
}
/* free os related resource in union recv_frame */
void rtw_os_recv_resource_free(struct recv_priv *precvpriv)
{
sint i;
union recv_frame *precvframe;
precvframe = (union recv_frame *) precvpriv->precv_frame_buf;
#ifdef CONFIG_RTW_NAPI
if (skb_queue_len(&precvpriv->rx_napi_skb_queue))
RTW_WARN("rx_napi_skb_queue not empty\n");
rtw_skb_queue_purge(&precvpriv->rx_napi_skb_queue);
#endif /* CONFIG_RTW_NAPI */
for (i = 0; i < NR_RECVFRAME; i++) {
rtw_os_free_recvframe(precvframe);
precvframe++;
}
}
#if defined(CONFIG_SDIO_HCI) || defined(CONFIG_GSPI_HCI)
#if !defined(CONFIG_RTL8822B) && !defined(CONFIG_RTL8822C)
#ifdef CONFIG_SDIO_RX_COPY
static int sdio_init_recvbuf_with_skb(struct recv_priv *recvpriv, struct recv_buf *rbuf, u32 size)
{
#ifdef CONFIG_PREALLOC_RX_SKB_BUFFER
if (RBUF_IS_PREALLOC(rbuf)) {
rbuf->pskb = rtw_alloc_skb_premem(size);
if (!rbuf->pskb) {
RTW_WARN("%s: Fail to get pre-alloc skb! size=%d\n", __func__, size);
return _FAIL;
}
skb_set_tail_pointer(rbuf->pskb, 0); /* TODO: do this in RTKM */
} else
#else
{
SIZE_PTR tmpaddr = 0;
SIZE_PTR alignment = 0;
rbuf->pskb = rtw_skb_alloc(size + RECVBUFF_ALIGN_SZ);
if (!rbuf->pskb)
return _FAIL;
tmpaddr = (SIZE_PTR)rbuf->pskb->data;
alignment = tmpaddr & (RECVBUFF_ALIGN_SZ - 1);
skb_reserve(rbuf->pskb, (RECVBUFF_ALIGN_SZ - alignment));
}
#endif
rbuf->pskb->dev = recvpriv->adapter->pnetdev;
/* init recvbuf */
rbuf->phead = rbuf->pskb->head;
rbuf->pdata = rbuf->pskb->data;
rbuf->ptail = skb_tail_pointer(rbuf->pskb);
rbuf->pend = skb_end_pointer(rbuf->pskb);
rbuf->len = 0;
return _SUCCESS;
}
#endif /* CONFIG_SDIO_RX_COPY */
#endif /* !defined(CONFIG_RTL8822B) && !defined(CONFIG_RTL8822C) */
#endif /* defined(CONFIG_SDIO_HCI) || defined(CONFIG_GSPI_HCI) */
/* alloc os related resource in struct recv_buf */
int rtw_os_recvbuf_resource_alloc(_adapter *padapter, struct recv_buf *precvbuf, u32 size)
{
int res = _SUCCESS;
#ifdef CONFIG_USB_HCI
#ifdef CONFIG_USE_USB_BUFFER_ALLOC_RX
struct dvobj_priv *pdvobjpriv = adapter_to_dvobj(padapter);
struct usb_device *pusbd = pdvobjpriv->pusbdev;
#endif
precvbuf->irp_pending = _FALSE;
precvbuf->purb = usb_alloc_urb(0, GFP_KERNEL);
if (precvbuf->purb == NULL)
res = _FAIL;
precvbuf->pskb = NULL;
precvbuf->pallocated_buf = precvbuf->pbuf = NULL;
precvbuf->pdata = precvbuf->phead = precvbuf->ptail = precvbuf->pend = NULL;
precvbuf->transfer_len = 0;
precvbuf->len = 0;
#ifdef CONFIG_USE_USB_BUFFER_ALLOC_RX
precvbuf->pallocated_buf = rtw_usb_buffer_alloc(pusbd, (size_t)size, &precvbuf->dma_transfer_addr);
precvbuf->pbuf = precvbuf->pallocated_buf;
if (precvbuf->pallocated_buf == NULL)
return _FAIL;
#endif /* CONFIG_USE_USB_BUFFER_ALLOC_RX */
#elif defined(CONFIG_SDIO_HCI) || defined(CONFIG_GSPI_HCI)
#if !defined(CONFIG_RTL8822B) && !defined(CONFIG_RTL8822C)
#ifdef CONFIG_SDIO_RX_COPY
res = sdio_init_recvbuf_with_skb(&padapter->recvpriv, precvbuf, size);
#endif
#endif
#endif /* CONFIG_XXX_HCI */
return res;
}
/* free os related resource in struct recv_buf */
int rtw_os_recvbuf_resource_free(_adapter *padapter, struct recv_buf *precvbuf)
{
int ret = _SUCCESS;
#ifdef CONFIG_USB_HCI
#ifdef CONFIG_USE_USB_BUFFER_ALLOC_RX
struct dvobj_priv *pdvobjpriv = adapter_to_dvobj(padapter);
struct usb_device *pusbd = pdvobjpriv->pusbdev;
rtw_usb_buffer_free(pusbd, (size_t)precvbuf->alloc_sz, precvbuf->pallocated_buf, precvbuf->dma_transfer_addr);
precvbuf->pallocated_buf = NULL;
precvbuf->dma_transfer_addr = 0;
#endif /* CONFIG_USE_USB_BUFFER_ALLOC_RX */
if (precvbuf->purb) {
/* usb_kill_urb(precvbuf->purb); */
usb_free_urb(precvbuf->purb);
}
#endif /* CONFIG_USB_HCI */
if (precvbuf->pskb) {
#ifdef CONFIG_PREALLOC_RX_SKB_BUFFER
if (rtw_free_skb_premem(precvbuf->pskb) != 0)
#endif
rtw_skb_free(precvbuf->pskb);
}
return ret;
}
_pkt *rtw_os_alloc_msdu_pkt(union recv_frame *prframe, const u8 *da, const u8 *sa
, u8 *msdu ,u16 msdu_len, enum rtw_rx_llc_hdl llc_hdl)
{
u8 *data_ptr;
_pkt *sub_skb;
struct rx_pkt_attrib *pattrib;
pattrib = &prframe->u.hdr.attrib;
#ifdef CONFIG_SKB_COPY
sub_skb = rtw_skb_alloc(msdu_len + 14);
if (sub_skb) {
skb_reserve(sub_skb, 14);
data_ptr = (u8 *)skb_put(sub_skb, msdu_len);
_rtw_memcpy(data_ptr, msdu, msdu_len);
} else
#endif /* CONFIG_SKB_COPY */
{
sub_skb = rtw_skb_clone(prframe->u.hdr.pkt);
if (sub_skb) {
sub_skb->data = msdu;
sub_skb->len = msdu_len;
skb_set_tail_pointer(sub_skb, msdu_len);
} else {
RTW_INFO("%s(): rtw_skb_clone() Fail!!!\n", __FUNCTION__);
return NULL;
}
}
if (llc_hdl) {
/* remove RFC1042 or Bridge-Tunnel encapsulation and replace EtherType */
skb_pull(sub_skb, SNAP_SIZE);
_rtw_memcpy(skb_push(sub_skb, ETH_ALEN), sa, ETH_ALEN);
_rtw_memcpy(skb_push(sub_skb, ETH_ALEN), da, ETH_ALEN);
} else {
/* Leave Ethernet header part of hdr and full payload */
u16 len;
len = htons(sub_skb->len);
_rtw_memcpy(skb_push(sub_skb, 2), &len, 2);
_rtw_memcpy(skb_push(sub_skb, ETH_ALEN), sa, ETH_ALEN);
_rtw_memcpy(skb_push(sub_skb, ETH_ALEN), da, ETH_ALEN);
}
return sub_skb;
}
#ifdef CONFIG_RTW_NAPI
static int napi_recv(_adapter *padapter, int budget)
{
_pkt *pskb;
struct recv_priv *precvpriv = &padapter->recvpriv;
int work_done = 0;
struct registry_priv *pregistrypriv = &padapter->registrypriv;
u8 rx_ok;
while ((work_done < budget) &&
(!skb_queue_empty(&precvpriv->rx_napi_skb_queue))) {
pskb = skb_dequeue(&precvpriv->rx_napi_skb_queue);
if (!pskb)
break;
rx_ok = _FALSE;
#ifdef CONFIG_RTW_GRO
/*
cloned SKB use dataref to avoid kernel release it.
But dataref changed in napi_gro_receive.
So, we should prevent cloned SKB go into napi_gro_receive.
*/
if (pregistrypriv->en_gro && !skb_cloned(pskb)) {
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 12, 0))
if (rtw_napi_gro_receive(&padapter->napi, pskb) != GRO_MERGED_FREE)
#else
if (rtw_napi_gro_receive(&padapter->napi, pskb) != GRO_DROP)
#endif
rx_ok = _TRUE;
goto next;
}
#endif /* CONFIG_RTW_GRO */
if (rtw_netif_receive_skb(padapter->pnetdev, pskb) == NET_RX_SUCCESS)
rx_ok = _TRUE;
next:
if (rx_ok == _TRUE) {
work_done++;
DBG_COUNTER(padapter->rx_logs.os_netif_ok);
} else {
DBG_COUNTER(padapter->rx_logs.os_netif_err);
}
}
return work_done;
}
int rtw_recv_napi_poll(struct napi_struct *napi, int budget)
{
_adapter *padapter = container_of(napi, _adapter, napi);
int work_done = 0;
struct recv_priv *precvpriv = &padapter->recvpriv;
work_done = napi_recv(padapter, budget);
if (work_done < budget) {
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 19, 0)) && defined(CONFIG_PCI_HCI)
napi_complete_done(napi, work_done);
#else
napi_complete(napi);
#endif
if (!skb_queue_empty(&precvpriv->rx_napi_skb_queue))
napi_schedule(napi);
}
return work_done;
}
#ifdef CONFIG_RTW_NAPI_DYNAMIC
void dynamic_napi_th_chk (_adapter *adapter)
{
if (adapter->registrypriv.en_napi) {
struct dvobj_priv *dvobj;
struct registry_priv *registry;
dvobj = adapter_to_dvobj(adapter);
registry = &adapter->registrypriv;
if (dvobj->traffic_stat.cur_rx_tp > registry->napi_threshold)
dvobj->en_napi_dynamic = 1;
else
dvobj->en_napi_dynamic = 0;
}
}
#endif /* CONFIG_RTW_NAPI_DYNAMIC */
#endif /* CONFIG_RTW_NAPI */
void rtw_os_recv_indicate_pkt(_adapter *padapter, _pkt *pkt, union recv_frame *rframe)
{
struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
struct recv_priv *precvpriv = &(padapter->recvpriv);
struct registry_priv *pregistrypriv = &padapter->registrypriv;
#ifdef CONFIG_BR_EXT
void *br_port = NULL;
#endif
int ret;
/* Indicat the packets to upper layer */
if (pkt) {
struct ethhdr *ehdr = (struct ethhdr *)pkt->data;
DBG_COUNTER(padapter->rx_logs.os_indicate);
#ifdef CONFIG_BR_EXT
if (!adapter_use_wds(padapter) && check_fwstate(pmlmepriv, WIFI_STATION_STATE | WIFI_ADHOC_STATE) == _TRUE) {
/* Insert NAT2.5 RX here! */
#if (LINUX_VERSION_CODE <= KERNEL_VERSION(2, 6, 35))
br_port = padapter->pnetdev->br_port;
#else
rcu_read_lock();
br_port = rcu_dereference(padapter->pnetdev->rx_handler_data);
rcu_read_unlock();
#endif
if (br_port) {
int nat25_handle_frame(_adapter *priv, struct sk_buff *skb);
if (nat25_handle_frame(padapter, pkt) == -1) {
/* priv->ext_stats.rx_data_drops++; */
/* DEBUG_ERR("RX DROP: nat25_handle_frame fail!\n"); */
/* return FAIL; */
#if 1
/* bypass this frame to upper layer!! */
#else
rtw_skb_free(sub_skb);
continue;
#endif
}
}
}
#endif /* CONFIG_BR_EXT */
/* After eth_type_trans process , pkt->data pointer will move from ethrnet header to ip header */
pkt->protocol = eth_type_trans(pkt, padapter->pnetdev);
pkt->dev = padapter->pnetdev;
pkt->ip_summed = CHECKSUM_NONE; /* CONFIG_TCP_CSUM_OFFLOAD_RX */
#ifdef CONFIG_TCP_CSUM_OFFLOAD_RX
if ((rframe->u.hdr.attrib.csum_valid == 1)
&& (rframe->u.hdr.attrib.csum_err == 0))
pkt->ip_summed = CHECKSUM_UNNECESSARY;
#endif /* CONFIG_TCP_CSUM_OFFLOAD_RX */
#ifdef CONFIG_RTW_NAPI
#ifdef CONFIG_RTW_NAPI_DYNAMIC
if (!skb_queue_empty(&precvpriv->rx_napi_skb_queue)
&& !adapter_to_dvobj(padapter)->en_napi_dynamic
)
napi_recv(padapter, RTL_NAPI_WEIGHT);
#endif
if (pregistrypriv->en_napi
#ifdef CONFIG_RTW_NAPI_DYNAMIC
&& adapter_to_dvobj(padapter)->en_napi_dynamic
#endif
) {
skb_queue_tail(&precvpriv->rx_napi_skb_queue, pkt);
#ifndef CONFIG_RTW_NAPI_V2
napi_schedule(&padapter->napi);
#endif
return;
}
#endif /* CONFIG_RTW_NAPI */
ret = rtw_netif_rx(padapter->pnetdev, pkt);
if (ret == NET_RX_SUCCESS)
DBG_COUNTER(padapter->rx_logs.os_netif_ok);
else
DBG_COUNTER(padapter->rx_logs.os_netif_err);
}
}
void rtw_handle_tkip_mic_err(_adapter *padapter, struct sta_info *sta, u8 bgroup)
{
#ifdef CONFIG_IOCTL_CFG80211
enum nl80211_key_type key_type = 0;
#endif
union iwreq_data wrqu;
struct iw_michaelmicfailure ev;
struct security_priv *psecuritypriv = &padapter->securitypriv;
systime cur_time = 0;
if (psecuritypriv->last_mic_err_time == 0)
psecuritypriv->last_mic_err_time = rtw_get_current_time();
else {
cur_time = rtw_get_current_time();
if (cur_time - psecuritypriv->last_mic_err_time < 60 * HZ) {
psecuritypriv->btkip_countermeasure = _TRUE;
psecuritypriv->last_mic_err_time = 0;
psecuritypriv->btkip_countermeasure_time = cur_time;
} else
psecuritypriv->last_mic_err_time = rtw_get_current_time();
}
#ifdef CONFIG_IOCTL_CFG80211
if (bgroup)
key_type |= NL80211_KEYTYPE_GROUP;
else
key_type |= NL80211_KEYTYPE_PAIRWISE;
cfg80211_michael_mic_failure(padapter->pnetdev, sta->cmn.mac_addr, key_type, -1, NULL, GFP_ATOMIC);
#endif
_rtw_memset(&ev, 0x00, sizeof(ev));
if (bgroup)
ev.flags |= IW_MICFAILURE_GROUP;
else
ev.flags |= IW_MICFAILURE_PAIRWISE;
ev.src_addr.sa_family = ARPHRD_ETHER;
_rtw_memcpy(ev.src_addr.sa_data, sta->cmn.mac_addr, ETH_ALEN);
_rtw_memset(&wrqu, 0x00, sizeof(wrqu));
wrqu.data.length = sizeof(ev);
#ifndef CONFIG_IOCTL_CFG80211
wireless_send_event(padapter->pnetdev, IWEVMICHAELMICFAILURE, &wrqu, (char *) &ev);
#endif
}
#ifdef CONFIG_HOSTAPD_MLME
void rtw_hostapd_mlme_rx(_adapter *padapter, union recv_frame *precv_frame)
{
_pkt *skb;
struct hostapd_priv *phostapdpriv = padapter->phostapdpriv;
struct net_device *pmgnt_netdev = phostapdpriv->pmgnt_netdev;
skb = precv_frame->u.hdr.pkt;
if (skb == NULL)
return;
skb->data = precv_frame->u.hdr.rx_data;
skb->tail = precv_frame->u.hdr.rx_tail;
skb->len = precv_frame->u.hdr.len;
/* pskb_copy = rtw_skb_copy(skb);
* if(skb == NULL) goto _exit; */
skb->dev = pmgnt_netdev;
skb->ip_summed = CHECKSUM_NONE;
skb->pkt_type = PACKET_OTHERHOST;
/* skb->protocol = __constant_htons(0x0019); ETH_P_80211_RAW */
skb->protocol = __constant_htons(0x0003); /*ETH_P_80211_RAW*/
/* RTW_INFO("(1)data=0x%x, head=0x%x, tail=0x%x, mac_header=0x%x, len=%d\n", skb->data, skb->head, skb->tail, skb->mac_header, skb->len); */
/* skb->mac.raw = skb->data; */
skb_reset_mac_header(skb);
/* skb_pull(skb, 24); */
_rtw_memset(skb->cb, 0, sizeof(skb->cb));
rtw_netif_rx(pmgnt_netdev, skb);
precv_frame->u.hdr.pkt = NULL; /* set pointer to NULL before rtw_free_recvframe() if call rtw_netif_rx() */
}
#endif /* CONFIG_HOSTAPD_MLME */
#ifdef CONFIG_WIFI_MONITOR
/*
precv_frame: impossible to be NULL
precv_frame: free by caller
*/
int rtw_recv_monitor(_adapter *padapter, union recv_frame *precv_frame)
{
int ret = _FAIL;
_pkt *skb;
skb = precv_frame->u.hdr.pkt;
if (skb == NULL) {
RTW_INFO("%s :skb==NULL something wrong!!!!\n", __func__);
goto _recv_drop;
}
skb->data = precv_frame->u.hdr.rx_data;
skb_set_tail_pointer(skb, precv_frame->u.hdr.len);
skb->len = precv_frame->u.hdr.len;
skb->ip_summed = CHECKSUM_NONE;
skb->pkt_type = PACKET_OTHERHOST;
skb->protocol = htons(0x0019); /* ETH_P_80211_RAW */
/* send to kernel */
rtw_netif_rx(padapter->pnetdev, skb);
/* pointers to NULL before rtw_free_recvframe() */
precv_frame->u.hdr.pkt = NULL;
ret = _SUCCESS;
_recv_drop:
return ret;
}
#endif /* CONFIG_WIFI_MONITOR */
inline void rtw_rframe_set_os_pkt(union recv_frame *rframe)
{
_pkt *skb = rframe->u.hdr.pkt;
skb->data = rframe->u.hdr.rx_data;
skb_set_tail_pointer(skb, rframe->u.hdr.len);
skb->len = rframe->u.hdr.len;
}
int rtw_recv_indicatepkt(_adapter *padapter, union recv_frame *precv_frame)
{
struct recv_priv *precvpriv;
_queue *pfree_recv_queue;
precvpriv = &(padapter->recvpriv);
pfree_recv_queue = &(precvpriv->free_recv_queue);
if (precv_frame->u.hdr.pkt == NULL)
goto _recv_indicatepkt_drop;
rtw_os_recv_indicate_pkt(padapter, precv_frame->u.hdr.pkt, precv_frame);
precv_frame->u.hdr.pkt = NULL;
rtw_free_recvframe(precv_frame, pfree_recv_queue);
return _SUCCESS;
_recv_indicatepkt_drop:
rtw_free_recvframe(precv_frame, pfree_recv_queue);
DBG_COUNTER(padapter->rx_logs.os_indicate_err);
return _FAIL;
}
void rtw_os_read_port(_adapter *padapter, struct recv_buf *precvbuf)
{
#ifdef CONFIG_USB_HCI
struct recv_priv *precvpriv = &padapter->recvpriv;
precvbuf->ref_cnt--;
/* free skb in recv_buf */
rtw_skb_free(precvbuf->pskb);
precvbuf->pskb = NULL;
if (precvbuf->irp_pending == _FALSE)
rtw_read_port(padapter, precvpriv->ff_hwaddr, 0, (unsigned char *)precvbuf);
#endif
#if defined(CONFIG_SDIO_HCI) || defined(CONFIG_GSPI_HCI)
precvbuf->pskb = NULL;
#endif
}

844
os_dep/linux/rhashtable.c Normal file
View File

@ -0,0 +1,844 @@
/*
* Resizable, Scalable, Concurrent Hash Table
*
* Copyright (c) 2015 Herbert Xu <herbert@gondor.apana.org.au>
* Copyright (c) 2014-2015 Thomas Graf <tgraf@suug.ch>
* Copyright (c) 2008-2014 Patrick McHardy <kaber@trash.net>
*
* Code partially derived from nft_hash
* Rewritten with rehash code from br_multicast plus single list
* pointer as suggested by Josh Triplett
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*/
#include <linux/atomic.h>
#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/log2.h>
#include <linux/sched.h>
#include <linux/slab.h>
#include <linux/vmalloc.h>
#include <linux/mm.h>
#include <linux/jhash.h>
#include <linux/random.h>
#include <linux/err.h>
#include <linux/export.h>
#define HASH_DEFAULT_SIZE 64UL
#define HASH_MIN_SIZE 4U
#define BUCKET_LOCKS_PER_CPU 128UL
static u32 head_hashfn(struct rhashtable *ht,
const struct bucket_table *tbl,
const struct rhash_head *he)
{
return rht_head_hashfn(ht, tbl, he, ht->p);
}
#ifdef CONFIG_PROVE_LOCKING
#define ASSERT_RHT_MUTEX(HT) BUG_ON(!lockdep_rht_mutex_is_held(HT))
int lockdep_rht_mutex_is_held(struct rhashtable *ht)
{
return (debug_locks) ? lockdep_is_held(&ht->mutex) : 1;
}
int lockdep_rht_bucket_is_held(const struct bucket_table *tbl, u32 hash)
{
spinlock_t *lock = rht_bucket_lock(tbl, hash);
return (debug_locks) ? lockdep_is_held(lock) : 1;
}
#else
#define ASSERT_RHT_MUTEX(HT)
#endif
static int alloc_bucket_locks(struct rhashtable *ht, struct bucket_table *tbl,
gfp_t gfp)
{
unsigned int i, size;
#if defined(CONFIG_PROVE_LOCKING)
unsigned int nr_pcpus = 2;
#else
unsigned int nr_pcpus = num_possible_cpus();
#endif
nr_pcpus = min_t(unsigned int, nr_pcpus, 32UL);
size = roundup_pow_of_two(nr_pcpus * ht->p.locks_mul);
/* Never allocate more than 0.5 locks per bucket */
size = min_t(unsigned int, size, tbl->size >> 1);
if (sizeof(spinlock_t) != 0) {
#ifdef CONFIG_NUMA
if (size * sizeof(spinlock_t) > PAGE_SIZE &&
gfp == GFP_KERNEL)
tbl->locks = vmalloc(size * sizeof(spinlock_t));
else
#endif
tbl->locks = kmalloc_array(size, sizeof(spinlock_t),
gfp);
if (!tbl->locks)
return -ENOMEM;
for (i = 0; i < size; i++)
spin_lock_init(&tbl->locks[i]);
}
tbl->locks_mask = size - 1;
return 0;
}
static void bucket_table_free(const struct bucket_table *tbl)
{
if (tbl)
kvfree(tbl->locks);
kvfree(tbl);
}
static void bucket_table_free_rcu(struct rcu_head *head)
{
bucket_table_free(container_of(head, struct bucket_table, rcu));
}
static struct bucket_table *bucket_table_alloc(struct rhashtable *ht,
size_t nbuckets,
gfp_t gfp)
{
struct bucket_table *tbl = NULL;
size_t size;
int i;
size = sizeof(*tbl) + nbuckets * sizeof(tbl->buckets[0]);
if (size <= (PAGE_SIZE << PAGE_ALLOC_COSTLY_ORDER) ||
gfp != GFP_KERNEL)
tbl = kzalloc(size, gfp | __GFP_NOWARN | __GFP_NORETRY);
if (tbl == NULL && gfp == GFP_KERNEL)
tbl = vzalloc(size);
if (tbl == NULL)
return NULL;
tbl->size = nbuckets;
if (alloc_bucket_locks(ht, tbl, gfp) < 0) {
bucket_table_free(tbl);
return NULL;
}
INIT_LIST_HEAD(&tbl->walkers);
get_random_bytes(&tbl->hash_rnd, sizeof(tbl->hash_rnd));
for (i = 0; i < nbuckets; i++)
INIT_RHT_NULLS_HEAD(tbl->buckets[i], ht, i);
return tbl;
}
static struct bucket_table *rhashtable_last_table(struct rhashtable *ht,
struct bucket_table *tbl)
{
struct bucket_table *new_tbl;
do {
new_tbl = tbl;
tbl = rht_dereference_rcu(tbl->future_tbl, ht);
} while (tbl);
return new_tbl;
}
static int rhashtable_rehash_one(struct rhashtable *ht, unsigned int old_hash)
{
struct bucket_table *old_tbl = rht_dereference(ht->tbl, ht);
struct bucket_table *new_tbl = rhashtable_last_table(ht,
rht_dereference_rcu(old_tbl->future_tbl, ht));
struct rhash_head __rcu **pprev = &old_tbl->buckets[old_hash];
int err = -ENOENT;
struct rhash_head *head, *next, *entry;
spinlock_t *new_bucket_lock;
unsigned int new_hash;
rht_for_each(entry, old_tbl, old_hash) {
err = 0;
next = rht_dereference_bucket(entry->next, old_tbl, old_hash);
if (rht_is_a_nulls(next))
break;
pprev = &entry->next;
}
if (err)
goto out;
new_hash = head_hashfn(ht, new_tbl, entry);
new_bucket_lock = rht_bucket_lock(new_tbl, new_hash);
spin_lock_nested(new_bucket_lock, SINGLE_DEPTH_NESTING);
head = rht_dereference_bucket(new_tbl->buckets[new_hash],
new_tbl, new_hash);
RCU_INIT_POINTER(entry->next, head);
rcu_assign_pointer(new_tbl->buckets[new_hash], entry);
spin_unlock(new_bucket_lock);
rcu_assign_pointer(*pprev, next);
out:
return err;
}
static void rhashtable_rehash_chain(struct rhashtable *ht,
unsigned int old_hash)
{
struct bucket_table *old_tbl = rht_dereference(ht->tbl, ht);
spinlock_t *old_bucket_lock;
old_bucket_lock = rht_bucket_lock(old_tbl, old_hash);
spin_lock_bh(old_bucket_lock);
while (!rhashtable_rehash_one(ht, old_hash))
;
old_tbl->rehash++;
spin_unlock_bh(old_bucket_lock);
}
static int rhashtable_rehash_attach(struct rhashtable *ht,
struct bucket_table *old_tbl,
struct bucket_table *new_tbl)
{
/* Protect future_tbl using the first bucket lock. */
spin_lock_bh(old_tbl->locks);
/* Did somebody beat us to it? */
if (rcu_access_pointer(old_tbl->future_tbl)) {
spin_unlock_bh(old_tbl->locks);
return -EEXIST;
}
/* Make insertions go into the new, empty table right away. Deletions
* and lookups will be attempted in both tables until we synchronize.
*/
rcu_assign_pointer(old_tbl->future_tbl, new_tbl);
/* Ensure the new table is visible to readers. */
smp_wmb();
spin_unlock_bh(old_tbl->locks);
return 0;
}
static int rhashtable_rehash_table(struct rhashtable *ht)
{
struct bucket_table *old_tbl = rht_dereference(ht->tbl, ht);
struct bucket_table *new_tbl;
struct rhashtable_walker *walker;
unsigned int old_hash;
new_tbl = rht_dereference(old_tbl->future_tbl, ht);
if (!new_tbl)
return 0;
for (old_hash = 0; old_hash < old_tbl->size; old_hash++)
rhashtable_rehash_chain(ht, old_hash);
/* Publish the new table pointer. */
rcu_assign_pointer(ht->tbl, new_tbl);
spin_lock(&ht->lock);
list_for_each_entry(walker, &old_tbl->walkers, list)
walker->tbl = NULL;
spin_unlock(&ht->lock);
/* Wait for readers. All new readers will see the new
* table, and thus no references to the old table will
* remain.
*/
call_rcu(&old_tbl->rcu, bucket_table_free_rcu);
return rht_dereference(new_tbl->future_tbl, ht) ? -EAGAIN : 0;
}
/**
* rhashtable_expand - Expand hash table while allowing concurrent lookups
* @ht: the hash table to expand
*
* A secondary bucket array is allocated and the hash entries are migrated.
*
* This function may only be called in a context where it is safe to call
* synchronize_rcu(), e.g. not within a rcu_read_lock() section.
*
* The caller must ensure that no concurrent resizing occurs by holding
* ht->mutex.
*
* It is valid to have concurrent insertions and deletions protected by per
* bucket locks or concurrent RCU protected lookups and traversals.
*/
static int rhashtable_expand(struct rhashtable *ht)
{
struct bucket_table *new_tbl, *old_tbl = rht_dereference(ht->tbl, ht);
int err;
ASSERT_RHT_MUTEX(ht);
old_tbl = rhashtable_last_table(ht, old_tbl);
new_tbl = bucket_table_alloc(ht, old_tbl->size * 2, GFP_KERNEL);
if (new_tbl == NULL)
return -ENOMEM;
err = rhashtable_rehash_attach(ht, old_tbl, new_tbl);
if (err)
bucket_table_free(new_tbl);
return err;
}
/**
* rhashtable_shrink - Shrink hash table while allowing concurrent lookups
* @ht: the hash table to shrink
*
* This function shrinks the hash table to fit, i.e., the smallest
* size would not cause it to expand right away automatically.
*
* The caller must ensure that no concurrent resizing occurs by holding
* ht->mutex.
*
* The caller must ensure that no concurrent table mutations take place.
* It is however valid to have concurrent lookups if they are RCU protected.
*
* It is valid to have concurrent insertions and deletions protected by per
* bucket locks or concurrent RCU protected lookups and traversals.
*/
static int rhashtable_shrink(struct rhashtable *ht)
{
struct bucket_table *new_tbl, *old_tbl = rht_dereference(ht->tbl, ht);
unsigned int size;
int err;
ASSERT_RHT_MUTEX(ht);
size = roundup_pow_of_two(atomic_read(&ht->nelems) * 3 / 2);
if (size < ht->p.min_size)
size = ht->p.min_size;
if (old_tbl->size <= size)
return 0;
if (rht_dereference(old_tbl->future_tbl, ht))
return -EEXIST;
new_tbl = bucket_table_alloc(ht, size, GFP_KERNEL);
if (new_tbl == NULL)
return -ENOMEM;
err = rhashtable_rehash_attach(ht, old_tbl, new_tbl);
if (err)
bucket_table_free(new_tbl);
return err;
}
static void rht_deferred_worker(struct work_struct *work)
{
struct rhashtable *ht;
struct bucket_table *tbl;
int err = 0;
ht = container_of(work, struct rhashtable, run_work);
mutex_lock(&ht->mutex);
tbl = rht_dereference(ht->tbl, ht);
tbl = rhashtable_last_table(ht, tbl);
if (rht_grow_above_75(ht, tbl))
rhashtable_expand(ht);
else if (ht->p.automatic_shrinking && rht_shrink_below_30(ht, tbl))
rhashtable_shrink(ht);
err = rhashtable_rehash_table(ht);
mutex_unlock(&ht->mutex);
if (err)
schedule_work(&ht->run_work);
}
static bool rhashtable_check_elasticity(struct rhashtable *ht,
struct bucket_table *tbl,
unsigned int hash)
{
unsigned int elasticity = ht->elasticity;
struct rhash_head *head;
rht_for_each(head, tbl, hash)
if (!--elasticity)
return true;
return false;
}
int rhashtable_insert_rehash(struct rhashtable *ht,
struct bucket_table *tbl)
{
struct bucket_table *old_tbl;
struct bucket_table *new_tbl;
unsigned int size;
int err;
old_tbl = rht_dereference_rcu(ht->tbl, ht);
size = tbl->size;
err = -EBUSY;
if (rht_grow_above_75(ht, tbl))
size *= 2;
/* Do not schedule more than one rehash */
else if (old_tbl != tbl)
goto fail;
err = -ENOMEM;
new_tbl = bucket_table_alloc(ht, size, GFP_ATOMIC);
if (new_tbl == NULL)
goto fail;
err = rhashtable_rehash_attach(ht, tbl, new_tbl);
if (err) {
bucket_table_free(new_tbl);
if (err == -EEXIST)
err = 0;
} else
schedule_work(&ht->run_work);
return err;
fail:
/* Do not fail the insert if someone else did a rehash. */
if (likely(rcu_dereference_raw(tbl->future_tbl)))
return 0;
/* Schedule async rehash to retry allocation in process context. */
if (err == -ENOMEM)
schedule_work(&ht->run_work);
return err;
}
struct bucket_table *rhashtable_insert_slow(struct rhashtable *ht,
const void *key,
struct rhash_head *obj,
struct bucket_table *tbl)
{
struct rhash_head *head;
unsigned int hash;
int err;
tbl = rhashtable_last_table(ht, tbl);
hash = head_hashfn(ht, tbl, obj);
spin_lock_nested(rht_bucket_lock(tbl, hash), SINGLE_DEPTH_NESTING);
err = -EEXIST;
if (key && rhashtable_lookup_fast(ht, key, ht->p))
goto exit;
err = -E2BIG;
if (unlikely(rht_grow_above_max(ht, tbl)))
goto exit;
err = -EAGAIN;
if (rhashtable_check_elasticity(ht, tbl, hash) ||
rht_grow_above_100(ht, tbl))
goto exit;
err = 0;
head = rht_dereference_bucket(tbl->buckets[hash], tbl, hash);
RCU_INIT_POINTER(obj->next, head);
rcu_assign_pointer(tbl->buckets[hash], obj);
atomic_inc(&ht->nelems);
exit:
spin_unlock(rht_bucket_lock(tbl, hash));
if (err == 0)
return NULL;
else if (err == -EAGAIN)
return tbl;
else
return ERR_PTR(err);
}
/**
* rhashtable_walk_init - Initialise an iterator
* @ht: Table to walk over
* @iter: Hash table Iterator
*
* This function prepares a hash table walk.
*
* Note that if you restart a walk after rhashtable_walk_stop you
* may see the same object twice. Also, you may miss objects if
* there are removals in between rhashtable_walk_stop and the next
* call to rhashtable_walk_start.
*
* For a completely stable walk you should construct your own data
* structure outside the hash table.
*
* This function may sleep so you must not call it from interrupt
* context or with spin locks held.
*
* You must call rhashtable_walk_exit if this function returns
* successfully.
*/
int rhashtable_walk_init(struct rhashtable *ht, struct rhashtable_iter *iter)
{
iter->ht = ht;
iter->p = NULL;
iter->slot = 0;
iter->skip = 0;
iter->walker = kmalloc(sizeof(*iter->walker), GFP_KERNEL);
if (!iter->walker)
return -ENOMEM;
spin_lock(&ht->lock);
iter->walker->tbl =
rcu_dereference_protected(ht->tbl, lockdep_is_held(&ht->lock));
list_add(&iter->walker->list, &iter->walker->tbl->walkers);
spin_unlock(&ht->lock);
return 0;
}
/**
* rhashtable_walk_exit - Free an iterator
* @iter: Hash table Iterator
*
* This function frees resources allocated by rhashtable_walk_init.
*/
void rhashtable_walk_exit(struct rhashtable_iter *iter)
{
spin_lock(&iter->ht->lock);
if (iter->walker->tbl)
list_del(&iter->walker->list);
spin_unlock(&iter->ht->lock);
kfree(iter->walker);
}
/**
* rhashtable_walk_start - Start a hash table walk
* @iter: Hash table iterator
*
* Start a hash table walk. Note that we take the RCU lock in all
* cases including when we return an error. So you must always call
* rhashtable_walk_stop to clean up.
*
* Returns zero if successful.
*
* Returns -EAGAIN if resize event occured. Note that the iterator
* will rewind back to the beginning and you may use it immediately
* by calling rhashtable_walk_next.
*/
int rhashtable_walk_start(struct rhashtable_iter *iter)
__acquires(RCU)
{
struct rhashtable *ht = iter->ht;
rcu_read_lock();
spin_lock(&ht->lock);
if (iter->walker->tbl)
list_del(&iter->walker->list);
spin_unlock(&ht->lock);
if (!iter->walker->tbl) {
iter->walker->tbl = rht_dereference_rcu(ht->tbl, ht);
return -EAGAIN;
}
return 0;
}
/**
* rhashtable_walk_next - Return the next object and advance the iterator
* @iter: Hash table iterator
*
* Note that you must call rhashtable_walk_stop when you are finished
* with the walk.
*
* Returns the next object or NULL when the end of the table is reached.
*
* Returns -EAGAIN if resize event occured. Note that the iterator
* will rewind back to the beginning and you may continue to use it.
*/
void *rhashtable_walk_next(struct rhashtable_iter *iter)
{
struct bucket_table *tbl = iter->walker->tbl;
struct rhashtable *ht = iter->ht;
struct rhash_head *p = iter->p;
if (p) {
p = rht_dereference_bucket_rcu(p->next, tbl, iter->slot);
goto next;
}
for (; iter->slot < tbl->size; iter->slot++) {
int skip = iter->skip;
rht_for_each_rcu(p, tbl, iter->slot) {
if (!skip)
break;
skip--;
}
next:
if (!rht_is_a_nulls(p)) {
iter->skip++;
iter->p = p;
return rht_obj(ht, p);
}
iter->skip = 0;
}
iter->p = NULL;
/* Ensure we see any new tables. */
smp_rmb();
iter->walker->tbl = rht_dereference_rcu(tbl->future_tbl, ht);
if (iter->walker->tbl) {
iter->slot = 0;
iter->skip = 0;
return ERR_PTR(-EAGAIN);
}
return NULL;
}
/**
* rhashtable_walk_stop - Finish a hash table walk
* @iter: Hash table iterator
*
* Finish a hash table walk.
*/
void rhashtable_walk_stop(struct rhashtable_iter *iter)
__releases(RCU)
{
struct rhashtable *ht;
struct bucket_table *tbl = iter->walker->tbl;
if (!tbl)
goto out;
ht = iter->ht;
spin_lock(&ht->lock);
if (tbl->rehash < tbl->size)
list_add(&iter->walker->list, &tbl->walkers);
else
iter->walker->tbl = NULL;
spin_unlock(&ht->lock);
iter->p = NULL;
out:
rcu_read_unlock();
}
static size_t rounded_hashtable_size(const struct rhashtable_params *params)
{
return max(roundup_pow_of_two(params->nelem_hint * 4 / 3),
(unsigned long)params->min_size);
}
static u32 rhashtable_jhash2(const void *key, u32 length, u32 seed)
{
return jhash2(key, length, seed);
}
/**
* rhashtable_init - initialize a new hash table
* @ht: hash table to be initialized
* @params: configuration parameters
*
* Initializes a new hash table based on the provided configuration
* parameters. A table can be configured either with a variable or
* fixed length key:
*
* Configuration Example 1: Fixed length keys
* struct test_obj {
* int key;
* void * my_member;
* struct rhash_head node;
* };
*
* struct rhashtable_params params = {
* .head_offset = offsetof(struct test_obj, node),
* .key_offset = offsetof(struct test_obj, key),
* .key_len = sizeof(int),
* .hashfn = jhash,
* .nulls_base = (1U << RHT_BASE_SHIFT),
* };
*
* Configuration Example 2: Variable length keys
* struct test_obj {
* [...]
* struct rhash_head node;
* };
*
* u32 my_hash_fn(const void *data, u32 len, u32 seed)
* {
* struct test_obj *obj = data;
*
* return [... hash ...];
* }
*
* struct rhashtable_params params = {
* .head_offset = offsetof(struct test_obj, node),
* .hashfn = jhash,
* .obj_hashfn = my_hash_fn,
* };
*/
int rhashtable_init(struct rhashtable *ht,
const struct rhashtable_params *params)
{
struct bucket_table *tbl;
size_t size;
size = HASH_DEFAULT_SIZE;
if ((!params->key_len && !params->obj_hashfn) ||
(params->obj_hashfn && !params->obj_cmpfn))
return -EINVAL;
if (params->nulls_base && params->nulls_base < (1U << RHT_BASE_SHIFT))
return -EINVAL;
memset(ht, 0, sizeof(*ht));
mutex_init(&ht->mutex);
spin_lock_init(&ht->lock);
memcpy(&ht->p, params, sizeof(*params));
if (params->min_size)
ht->p.min_size = roundup_pow_of_two(params->min_size);
if (params->max_size)
ht->p.max_size = rounddown_pow_of_two(params->max_size);
if (params->insecure_max_entries)
ht->p.insecure_max_entries =
rounddown_pow_of_two(params->insecure_max_entries);
else
ht->p.insecure_max_entries = ht->p.max_size * 2;
ht->p.min_size = max(ht->p.min_size, HASH_MIN_SIZE);
if (params->nelem_hint)
size = rounded_hashtable_size(&ht->p);
/* The maximum (not average) chain length grows with the
* size of the hash table, at a rate of (log N)/(log log N).
* The value of 16 is selected so that even if the hash
* table grew to 2^32 you would not expect the maximum
* chain length to exceed it unless we are under attack
* (or extremely unlucky).
*
* As this limit is only to detect attacks, we don't need
* to set it to a lower value as you'd need the chain
* length to vastly exceed 16 to have any real effect
* on the system.
*/
if (!params->insecure_elasticity)
ht->elasticity = 16;
if (params->locks_mul)
ht->p.locks_mul = roundup_pow_of_two(params->locks_mul);
else
ht->p.locks_mul = BUCKET_LOCKS_PER_CPU;
ht->key_len = ht->p.key_len;
if (!params->hashfn) {
ht->p.hashfn = jhash;
if (!(ht->key_len & (sizeof(u32) - 1))) {
ht->key_len /= sizeof(u32);
ht->p.hashfn = rhashtable_jhash2;
}
}
tbl = bucket_table_alloc(ht, size, GFP_KERNEL);
if (tbl == NULL)
return -ENOMEM;
atomic_set(&ht->nelems, 0);
RCU_INIT_POINTER(ht->tbl, tbl);
INIT_WORK(&ht->run_work, rht_deferred_worker);
return 0;
}
/**
* rhashtable_free_and_destroy - free elements and destroy hash table
* @ht: the hash table to destroy
* @free_fn: callback to release resources of element
* @arg: pointer passed to free_fn
*
* Stops an eventual async resize. If defined, invokes free_fn for each
* element to releasal resources. Please note that RCU protected
* readers may still be accessing the elements. Releasing of resources
* must occur in a compatible manner. Then frees the bucket array.
*
* This function will eventually sleep to wait for an async resize
* to complete. The caller is responsible that no further write operations
* occurs in parallel.
*/
void rhashtable_free_and_destroy(struct rhashtable *ht,
void (*free_fn)(void *ptr, void *arg),
void *arg)
{
const struct bucket_table *tbl;
unsigned int i;
cancel_work_sync(&ht->run_work);
mutex_lock(&ht->mutex);
tbl = rht_dereference(ht->tbl, ht);
if (free_fn) {
for (i = 0; i < tbl->size; i++) {
struct rhash_head *pos, *next;
for (pos = rht_dereference(tbl->buckets[i], ht),
next = !rht_is_a_nulls(pos) ?
rht_dereference(pos->next, ht) : NULL;
!rht_is_a_nulls(pos);
pos = next,
next = !rht_is_a_nulls(pos) ?
rht_dereference(pos->next, ht) : NULL)
free_fn(rht_obj(ht, pos), arg);
}
}
bucket_table_free(tbl);
mutex_unlock(&ht->mutex);
}
void rhashtable_destroy(struct rhashtable *ht)
{
return rhashtable_free_and_destroy(ht, NULL, NULL);
}

827
os_dep/linux/rhashtable.h Normal file
View File

@ -0,0 +1,827 @@
/*
* Resizable, Scalable, Concurrent Hash Table
*
* Copyright (c) 2015 Herbert Xu <herbert@gondor.apana.org.au>
* Copyright (c) 2014-2015 Thomas Graf <tgraf@suug.ch>
* Copyright (c) 2008-2014 Patrick McHardy <kaber@trash.net>
*
* Code partially derived from nft_hash
* Rewritten with rehash code from br_multicast plus single list
* pointer as suggested by Josh Triplett
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*/
#ifndef _LINUX_RHASHTABLE_H
#define _LINUX_RHASHTABLE_H
#include <linux/atomic.h>
#include <linux/compiler.h>
#include <linux/err.h>
#include <linux/errno.h>
#include <linux/jhash.h>
#include <linux/list_nulls.h>
#include <linux/workqueue.h>
#include <linux/mutex.h>
#include <linux/rcupdate.h>
/*
* The end of the chain is marked with a special nulls marks which has
* the following format:
*
* +-------+-----------------------------------------------------+-+
* | Base | Hash |1|
* +-------+-----------------------------------------------------+-+
*
* Base (4 bits) : Reserved to distinguish between multiple tables.
* Specified via &struct rhashtable_params.nulls_base.
* Hash (27 bits): Full hash (unmasked) of first element added to bucket
* 1 (1 bit) : Nulls marker (always set)
*
* The remaining bits of the next pointer remain unused for now.
*/
#define RHT_BASE_BITS 4
#define RHT_HASH_BITS 27
#define RHT_BASE_SHIFT RHT_HASH_BITS
/* Base bits plus 1 bit for nulls marker */
#define RHT_HASH_RESERVED_SPACE (RHT_BASE_BITS + 1)
struct rhash_head {
struct rhash_head __rcu *next;
};
/**
* struct bucket_table - Table of hash buckets
* @size: Number of hash buckets
* @rehash: Current bucket being rehashed
* @hash_rnd: Random seed to fold into hash
* @locks_mask: Mask to apply before accessing locks[]
* @locks: Array of spinlocks protecting individual buckets
* @walkers: List of active walkers
* @rcu: RCU structure for freeing the table
* @future_tbl: Table under construction during rehashing
* @buckets: size * hash buckets
*/
struct bucket_table {
unsigned int size;
unsigned int rehash;
u32 hash_rnd;
unsigned int locks_mask;
spinlock_t *locks;
struct list_head walkers;
struct rcu_head rcu;
struct bucket_table __rcu *future_tbl;
struct rhash_head __rcu *buckets[] ____cacheline_aligned_in_smp;
};
/**
* struct rhashtable_compare_arg - Key for the function rhashtable_compare
* @ht: Hash table
* @key: Key to compare against
*/
struct rhashtable_compare_arg {
struct rhashtable *ht;
const void *key;
};
typedef u32 (*rht_hashfn_t)(const void *data, u32 len, u32 seed);
typedef u32 (*rht_obj_hashfn_t)(const void *data, u32 len, u32 seed);
typedef int (*rht_obj_cmpfn_t)(struct rhashtable_compare_arg *arg,
const void *obj);
struct rhashtable;
/**
* struct rhashtable_params - Hash table construction parameters
* @nelem_hint: Hint on number of elements, should be 75% of desired size
* @key_len: Length of key
* @key_offset: Offset of key in struct to be hashed
* @head_offset: Offset of rhash_head in struct to be hashed
* @insecure_max_entries: Maximum number of entries (may be exceeded)
* @max_size: Maximum size while expanding
* @min_size: Minimum size while shrinking
* @nulls_base: Base value to generate nulls marker
* @insecure_elasticity: Set to true to disable chain length checks
* @automatic_shrinking: Enable automatic shrinking of tables
* @locks_mul: Number of bucket locks to allocate per cpu (default: 128)
* @hashfn: Hash function (default: jhash2 if !(key_len % 4), or jhash)
* @obj_hashfn: Function to hash object
* @obj_cmpfn: Function to compare key with object
*/
struct rhashtable_params {
size_t nelem_hint;
size_t key_len;
size_t key_offset;
size_t head_offset;
unsigned int insecure_max_entries;
unsigned int max_size;
unsigned int min_size;
u32 nulls_base;
bool insecure_elasticity;
bool automatic_shrinking;
size_t locks_mul;
rht_hashfn_t hashfn;
rht_obj_hashfn_t obj_hashfn;
rht_obj_cmpfn_t obj_cmpfn;
};
/**
* struct rhashtable - Hash table handle
* @tbl: Bucket table
* @nelems: Number of elements in table
* @key_len: Key length for hashfn
* @elasticity: Maximum chain length before rehash
* @p: Configuration parameters
* @run_work: Deferred worker to expand/shrink asynchronously
* @mutex: Mutex to protect current/future table swapping
* @lock: Spin lock to protect walker list
*/
struct rhashtable {
struct bucket_table __rcu *tbl;
atomic_t nelems;
unsigned int key_len;
unsigned int elasticity;
struct rhashtable_params p;
struct work_struct run_work;
struct mutex mutex;
spinlock_t lock;
};
/**
* struct rhashtable_walker - Hash table walker
* @list: List entry on list of walkers
* @tbl: The table that we were walking over
*/
struct rhashtable_walker {
struct list_head list;
struct bucket_table *tbl;
};
/**
* struct rhashtable_iter - Hash table iterator, fits into netlink cb
* @ht: Table to iterate through
* @p: Current pointer
* @walker: Associated rhashtable walker
* @slot: Current slot
* @skip: Number of entries to skip in slot
*/
struct rhashtable_iter {
struct rhashtable *ht;
struct rhash_head *p;
struct rhashtable_walker *walker;
unsigned int slot;
unsigned int skip;
};
static inline unsigned long rht_marker(const struct rhashtable *ht, u32 hash)
{
return NULLS_MARKER(ht->p.nulls_base + hash);
}
#define INIT_RHT_NULLS_HEAD(ptr, ht, hash) \
((ptr) = (typeof(ptr)) rht_marker(ht, hash))
static inline bool rht_is_a_nulls(const struct rhash_head *ptr)
{
return ((unsigned long) ptr & 1);
}
static inline unsigned long rht_get_nulls_value(const struct rhash_head *ptr)
{
return ((unsigned long) ptr) >> 1;
}
static inline void *rht_obj(const struct rhashtable *ht,
const struct rhash_head *he)
{
return (char *)he - ht->p.head_offset;
}
static inline unsigned int rht_bucket_index(const struct bucket_table *tbl,
unsigned int hash)
{
return (hash >> RHT_HASH_RESERVED_SPACE) & (tbl->size - 1);
}
static inline unsigned int rht_key_hashfn(
struct rhashtable *ht, const struct bucket_table *tbl,
const void *key, const struct rhashtable_params params)
{
unsigned int hash;
/* params must be equal to ht->p if it isn't constant. */
if (!__builtin_constant_p(params.key_len))
hash = ht->p.hashfn(key, ht->key_len, tbl->hash_rnd);
else if (params.key_len) {
unsigned int key_len = params.key_len;
if (params.hashfn)
hash = params.hashfn(key, key_len, tbl->hash_rnd);
else if (key_len & (sizeof(u32) - 1))
hash = jhash(key, key_len, tbl->hash_rnd);
else
hash = jhash2(key, key_len / sizeof(u32),
tbl->hash_rnd);
} else {
unsigned int key_len = ht->p.key_len;
if (params.hashfn)
hash = params.hashfn(key, key_len, tbl->hash_rnd);
else
hash = jhash(key, key_len, tbl->hash_rnd);
}
return rht_bucket_index(tbl, hash);
}
static inline unsigned int rht_head_hashfn(
struct rhashtable *ht, const struct bucket_table *tbl,
const struct rhash_head *he, const struct rhashtable_params params)
{
const char *ptr = rht_obj(ht, he);
return likely(params.obj_hashfn) ?
rht_bucket_index(tbl, params.obj_hashfn(ptr, params.key_len ?:
ht->p.key_len,
tbl->hash_rnd)) :
rht_key_hashfn(ht, tbl, ptr + params.key_offset, params);
}
/**
* rht_grow_above_75 - returns true if nelems > 0.75 * table-size
* @ht: hash table
* @tbl: current table
*/
static inline bool rht_grow_above_75(const struct rhashtable *ht,
const struct bucket_table *tbl)
{
/* Expand table when exceeding 75% load */
return atomic_read(&ht->nelems) > (tbl->size / 4 * 3) &&
(!ht->p.max_size || tbl->size < ht->p.max_size);
}
/**
* rht_shrink_below_30 - returns true if nelems < 0.3 * table-size
* @ht: hash table
* @tbl: current table
*/
static inline bool rht_shrink_below_30(const struct rhashtable *ht,
const struct bucket_table *tbl)
{
/* Shrink table beneath 30% load */
return atomic_read(&ht->nelems) < (tbl->size * 3 / 10) &&
tbl->size > ht->p.min_size;
}
/**
* rht_grow_above_100 - returns true if nelems > table-size
* @ht: hash table
* @tbl: current table
*/
static inline bool rht_grow_above_100(const struct rhashtable *ht,
const struct bucket_table *tbl)
{
return atomic_read(&ht->nelems) > tbl->size &&
(!ht->p.max_size || tbl->size < ht->p.max_size);
}
/**
* rht_grow_above_max - returns true if table is above maximum
* @ht: hash table
* @tbl: current table
*/
static inline bool rht_grow_above_max(const struct rhashtable *ht,
const struct bucket_table *tbl)
{
return ht->p.insecure_max_entries &&
atomic_read(&ht->nelems) >= ht->p.insecure_max_entries;
}
/* The bucket lock is selected based on the hash and protects mutations
* on a group of hash buckets.
*
* A maximum of tbl->size/2 bucket locks is allocated. This ensures that
* a single lock always covers both buckets which may both contains
* entries which link to the same bucket of the old table during resizing.
* This allows to simplify the locking as locking the bucket in both
* tables during resize always guarantee protection.
*
* IMPORTANT: When holding the bucket lock of both the old and new table
* during expansions and shrinking, the old bucket lock must always be
* acquired first.
*/
static inline spinlock_t *rht_bucket_lock(const struct bucket_table *tbl,
unsigned int hash)
{
return &tbl->locks[hash & tbl->locks_mask];
}
#ifdef CONFIG_PROVE_LOCKING
int lockdep_rht_mutex_is_held(struct rhashtable *ht);
int lockdep_rht_bucket_is_held(const struct bucket_table *tbl, u32 hash);
#else
static inline int lockdep_rht_mutex_is_held(struct rhashtable *ht)
{
return 1;
}
static inline int lockdep_rht_bucket_is_held(const struct bucket_table *tbl,
u32 hash)
{
return 1;
}
#endif /* CONFIG_PROVE_LOCKING */
int rhashtable_init(struct rhashtable *ht,
const struct rhashtable_params *params);
struct bucket_table *rhashtable_insert_slow(struct rhashtable *ht,
const void *key,
struct rhash_head *obj,
struct bucket_table *old_tbl);
int rhashtable_insert_rehash(struct rhashtable *ht, struct bucket_table *tbl);
int rhashtable_walk_init(struct rhashtable *ht, struct rhashtable_iter *iter);
void rhashtable_walk_exit(struct rhashtable_iter *iter);
int rhashtable_walk_start(struct rhashtable_iter *iter) __acquires(RCU);
void *rhashtable_walk_next(struct rhashtable_iter *iter);
void rhashtable_walk_stop(struct rhashtable_iter *iter) __releases(RCU);
void rhashtable_free_and_destroy(struct rhashtable *ht,
void (*free_fn)(void *ptr, void *arg),
void *arg);
void rhashtable_destroy(struct rhashtable *ht);
#define rht_dereference(p, ht) \
rcu_dereference_protected(p, lockdep_rht_mutex_is_held(ht))
#define rht_dereference_rcu(p, ht) \
rcu_dereference_check(p, lockdep_rht_mutex_is_held(ht))
#define rht_dereference_bucket(p, tbl, hash) \
rcu_dereference_protected(p, lockdep_rht_bucket_is_held(tbl, hash))
#define rht_dereference_bucket_rcu(p, tbl, hash) \
rcu_dereference_check(p, lockdep_rht_bucket_is_held(tbl, hash))
#define rht_entry(tpos, pos, member) \
({ tpos = container_of(pos, typeof(*tpos), member); 1; })
/**
* rht_for_each_continue - continue iterating over hash chain
* @pos: the &struct rhash_head to use as a loop cursor.
* @head: the previous &struct rhash_head to continue from
* @tbl: the &struct bucket_table
* @hash: the hash value / bucket index
*/
#define rht_for_each_continue(pos, head, tbl, hash) \
for (pos = rht_dereference_bucket(head, tbl, hash); \
!rht_is_a_nulls(pos); \
pos = rht_dereference_bucket((pos)->next, tbl, hash))
/**
* rht_for_each - iterate over hash chain
* @pos: the &struct rhash_head to use as a loop cursor.
* @tbl: the &struct bucket_table
* @hash: the hash value / bucket index
*/
#define rht_for_each(pos, tbl, hash) \
rht_for_each_continue(pos, (tbl)->buckets[hash], tbl, hash)
/**
* rht_for_each_entry_continue - continue iterating over hash chain
* @tpos: the type * to use as a loop cursor.
* @pos: the &struct rhash_head to use as a loop cursor.
* @head: the previous &struct rhash_head to continue from
* @tbl: the &struct bucket_table
* @hash: the hash value / bucket index
* @member: name of the &struct rhash_head within the hashable struct.
*/
#define rht_for_each_entry_continue(tpos, pos, head, tbl, hash, member) \
for (pos = rht_dereference_bucket(head, tbl, hash); \
(!rht_is_a_nulls(pos)) && rht_entry(tpos, pos, member); \
pos = rht_dereference_bucket((pos)->next, tbl, hash))
/**
* rht_for_each_entry - iterate over hash chain of given type
* @tpos: the type * to use as a loop cursor.
* @pos: the &struct rhash_head to use as a loop cursor.
* @tbl: the &struct bucket_table
* @hash: the hash value / bucket index
* @member: name of the &struct rhash_head within the hashable struct.
*/
#define rht_for_each_entry(tpos, pos, tbl, hash, member) \
rht_for_each_entry_continue(tpos, pos, (tbl)->buckets[hash], \
tbl, hash, member)
/**
* rht_for_each_entry_safe - safely iterate over hash chain of given type
* @tpos: the type * to use as a loop cursor.
* @pos: the &struct rhash_head to use as a loop cursor.
* @next: the &struct rhash_head to use as next in loop cursor.
* @tbl: the &struct bucket_table
* @hash: the hash value / bucket index
* @member: name of the &struct rhash_head within the hashable struct.
*
* This hash chain list-traversal primitive allows for the looped code to
* remove the loop cursor from the list.
*/
#define rht_for_each_entry_safe(tpos, pos, next, tbl, hash, member) \
for (pos = rht_dereference_bucket((tbl)->buckets[hash], tbl, hash), \
next = !rht_is_a_nulls(pos) ? \
rht_dereference_bucket(pos->next, tbl, hash) : NULL; \
(!rht_is_a_nulls(pos)) && rht_entry(tpos, pos, member); \
pos = next, \
next = !rht_is_a_nulls(pos) ? \
rht_dereference_bucket(pos->next, tbl, hash) : NULL)
/**
* rht_for_each_rcu_continue - continue iterating over rcu hash chain
* @pos: the &struct rhash_head to use as a loop cursor.
* @head: the previous &struct rhash_head to continue from
* @tbl: the &struct bucket_table
* @hash: the hash value / bucket index
*
* This hash chain list-traversal primitive may safely run concurrently with
* the _rcu mutation primitives such as rhashtable_insert() as long as the
* traversal is guarded by rcu_read_lock().
*/
#define rht_for_each_rcu_continue(pos, head, tbl, hash) \
for (({barrier(); }), \
pos = rht_dereference_bucket_rcu(head, tbl, hash); \
!rht_is_a_nulls(pos); \
pos = rcu_dereference_raw(pos->next))
/**
* rht_for_each_rcu - iterate over rcu hash chain
* @pos: the &struct rhash_head to use as a loop cursor.
* @tbl: the &struct bucket_table
* @hash: the hash value / bucket index
*
* This hash chain list-traversal primitive may safely run concurrently with
* the _rcu mutation primitives such as rhashtable_insert() as long as the
* traversal is guarded by rcu_read_lock().
*/
#define rht_for_each_rcu(pos, tbl, hash) \
rht_for_each_rcu_continue(pos, (tbl)->buckets[hash], tbl, hash)
/**
* rht_for_each_entry_rcu_continue - continue iterating over rcu hash chain
* @tpos: the type * to use as a loop cursor.
* @pos: the &struct rhash_head to use as a loop cursor.
* @head: the previous &struct rhash_head to continue from
* @tbl: the &struct bucket_table
* @hash: the hash value / bucket index
* @member: name of the &struct rhash_head within the hashable struct.
*
* This hash chain list-traversal primitive may safely run concurrently with
* the _rcu mutation primitives such as rhashtable_insert() as long as the
* traversal is guarded by rcu_read_lock().
*/
#define rht_for_each_entry_rcu_continue(tpos, pos, head, tbl, hash, member) \
for (({barrier(); }), \
pos = rht_dereference_bucket_rcu(head, tbl, hash); \
(!rht_is_a_nulls(pos)) && rht_entry(tpos, pos, member); \
pos = rht_dereference_bucket_rcu(pos->next, tbl, hash))
/**
* rht_for_each_entry_rcu - iterate over rcu hash chain of given type
* @tpos: the type * to use as a loop cursor.
* @pos: the &struct rhash_head to use as a loop cursor.
* @tbl: the &struct bucket_table
* @hash: the hash value / bucket index
* @member: name of the &struct rhash_head within the hashable struct.
*
* This hash chain list-traversal primitive may safely run concurrently with
* the _rcu mutation primitives such as rhashtable_insert() as long as the
* traversal is guarded by rcu_read_lock().
*/
#define rht_for_each_entry_rcu(tpos, pos, tbl, hash, member) \
rht_for_each_entry_rcu_continue(tpos, pos, (tbl)->buckets[hash],\
tbl, hash, member)
static inline int rhashtable_compare(struct rhashtable_compare_arg *arg,
const void *obj)
{
struct rhashtable *ht = arg->ht;
const char *ptr = obj;
return memcmp(ptr + ht->p.key_offset, arg->key, ht->p.key_len);
}
/**
* rhashtable_lookup_fast - search hash table, inlined version
* @ht: hash table
* @key: the pointer to the key
* @params: hash table parameters
*
* Computes the hash value for the key and traverses the bucket chain looking
* for a entry with an identical key. The first matching entry is returned.
*
* Returns the first entry on which the compare function returned true.
*/
static inline void *rhashtable_lookup_fast(
struct rhashtable *ht, const void *key,
const struct rhashtable_params params)
{
struct rhashtable_compare_arg arg = {
.ht = ht,
.key = key,
};
const struct bucket_table *tbl;
struct rhash_head *he;
unsigned int hash;
rcu_read_lock();
tbl = rht_dereference_rcu(ht->tbl, ht);
restart:
hash = rht_key_hashfn(ht, tbl, key, params);
rht_for_each_rcu(he, tbl, hash) {
if (params.obj_cmpfn ?
params.obj_cmpfn(&arg, rht_obj(ht, he)) :
rhashtable_compare(&arg, rht_obj(ht, he)))
continue;
rcu_read_unlock();
return rht_obj(ht, he);
}
/* Ensure we see any new tables. */
smp_rmb();
tbl = rht_dereference_rcu(tbl->future_tbl, ht);
if (unlikely(tbl))
goto restart;
rcu_read_unlock();
return NULL;
}
/* Internal function, please use rhashtable_insert_fast() instead */
static inline int __rhashtable_insert_fast(
struct rhashtable *ht, const void *key, struct rhash_head *obj,
const struct rhashtable_params params)
{
struct rhashtable_compare_arg arg = {
.ht = ht,
.key = key,
};
struct bucket_table *tbl, *new_tbl;
struct rhash_head *head;
spinlock_t *lock;
unsigned int elasticity;
unsigned int hash;
int err;
restart:
rcu_read_lock();
tbl = rht_dereference_rcu(ht->tbl, ht);
/* All insertions must grab the oldest table containing
* the hashed bucket that is yet to be rehashed.
*/
for (;;) {
hash = rht_head_hashfn(ht, tbl, obj, params);
lock = rht_bucket_lock(tbl, hash);
spin_lock_bh(lock);
if (tbl->rehash <= hash)
break;
spin_unlock_bh(lock);
tbl = rht_dereference_rcu(tbl->future_tbl, ht);
}
new_tbl = rht_dereference_rcu(tbl->future_tbl, ht);
if (unlikely(new_tbl)) {
tbl = rhashtable_insert_slow(ht, key, obj, new_tbl);
if (!IS_ERR_OR_NULL(tbl))
goto slow_path;
err = PTR_ERR(tbl);
goto out;
}
err = -E2BIG;
if (unlikely(rht_grow_above_max(ht, tbl)))
goto out;
if (unlikely(rht_grow_above_100(ht, tbl))) {
slow_path:
spin_unlock_bh(lock);
err = rhashtable_insert_rehash(ht, tbl);
rcu_read_unlock();
if (err)
return err;
goto restart;
}
err = -EEXIST;
elasticity = ht->elasticity;
rht_for_each(head, tbl, hash) {
if (key &&
unlikely(!(params.obj_cmpfn ?
params.obj_cmpfn(&arg, rht_obj(ht, head)) :
rhashtable_compare(&arg, rht_obj(ht, head)))))
goto out;
if (!--elasticity)
goto slow_path;
}
err = 0;
head = rht_dereference_bucket(tbl->buckets[hash], tbl, hash);
RCU_INIT_POINTER(obj->next, head);
rcu_assign_pointer(tbl->buckets[hash], obj);
atomic_inc(&ht->nelems);
if (rht_grow_above_75(ht, tbl))
schedule_work(&ht->run_work);
out:
spin_unlock_bh(lock);
rcu_read_unlock();
return err;
}
/**
* rhashtable_insert_fast - insert object into hash table
* @ht: hash table
* @obj: pointer to hash head inside object
* @params: hash table parameters
*
* Will take a per bucket spinlock to protect against mutual mutations
* on the same bucket. Multiple insertions may occur in parallel unless
* they map to the same bucket lock.
*
* It is safe to call this function from atomic context.
*
* Will trigger an automatic deferred table resizing if the size grows
* beyond the watermark indicated by grow_decision() which can be passed
* to rhashtable_init().
*/
static inline int rhashtable_insert_fast(
struct rhashtable *ht, struct rhash_head *obj,
const struct rhashtable_params params)
{
return __rhashtable_insert_fast(ht, NULL, obj, params);
}
/**
* rhashtable_lookup_insert_fast - lookup and insert object into hash table
* @ht: hash table
* @obj: pointer to hash head inside object
* @params: hash table parameters
*
* Locks down the bucket chain in both the old and new table if a resize
* is in progress to ensure that writers can't remove from the old table
* and can't insert to the new table during the atomic operation of search
* and insertion. Searches for duplicates in both the old and new table if
* a resize is in progress.
*
* This lookup function may only be used for fixed key hash table (key_len
* parameter set). It will BUG() if used inappropriately.
*
* It is safe to call this function from atomic context.
*
* Will trigger an automatic deferred table resizing if the size grows
* beyond the watermark indicated by grow_decision() which can be passed
* to rhashtable_init().
*/
static inline int rhashtable_lookup_insert_fast(
struct rhashtable *ht, struct rhash_head *obj,
const struct rhashtable_params params)
{
const char *key = rht_obj(ht, obj);
BUG_ON(ht->p.obj_hashfn);
return __rhashtable_insert_fast(ht, key + ht->p.key_offset, obj,
params);
}
/**
* rhashtable_lookup_insert_key - search and insert object to hash table
* with explicit key
* @ht: hash table
* @key: key
* @obj: pointer to hash head inside object
* @params: hash table parameters
*
* Locks down the bucket chain in both the old and new table if a resize
* is in progress to ensure that writers can't remove from the old table
* and can't insert to the new table during the atomic operation of search
* and insertion. Searches for duplicates in both the old and new table if
* a resize is in progress.
*
* Lookups may occur in parallel with hashtable mutations and resizing.
*
* Will trigger an automatic deferred table resizing if the size grows
* beyond the watermark indicated by grow_decision() which can be passed
* to rhashtable_init().
*
* Returns zero on success.
*/
static inline int rhashtable_lookup_insert_key(
struct rhashtable *ht, const void *key, struct rhash_head *obj,
const struct rhashtable_params params)
{
BUG_ON(!ht->p.obj_hashfn || !key);
return __rhashtable_insert_fast(ht, key, obj, params);
}
/* Internal function, please use rhashtable_remove_fast() instead */
static inline int __rhashtable_remove_fast(
struct rhashtable *ht, struct bucket_table *tbl,
struct rhash_head *obj, const struct rhashtable_params params)
{
struct rhash_head __rcu **pprev;
struct rhash_head *he;
spinlock_t * lock;
unsigned int hash;
int err = -ENOENT;
hash = rht_head_hashfn(ht, tbl, obj, params);
lock = rht_bucket_lock(tbl, hash);
spin_lock_bh(lock);
pprev = &tbl->buckets[hash];
rht_for_each(he, tbl, hash) {
if (he != obj) {
pprev = &he->next;
continue;
}
rcu_assign_pointer(*pprev, obj->next);
err = 0;
break;
}
spin_unlock_bh(lock);
return err;
}
/**
* rhashtable_remove_fast - remove object from hash table
* @ht: hash table
* @obj: pointer to hash head inside object
* @params: hash table parameters
*
* Since the hash chain is single linked, the removal operation needs to
* walk the bucket chain upon removal. The removal operation is thus
* considerable slow if the hash table is not correctly sized.
*
* Will automatically shrink the table via rhashtable_expand() if the
* shrink_decision function specified at rhashtable_init() returns true.
*
* Returns zero on success, -ENOENT if the entry could not be found.
*/
static inline int rhashtable_remove_fast(
struct rhashtable *ht, struct rhash_head *obj,
const struct rhashtable_params params)
{
struct bucket_table *tbl;
int err;
rcu_read_lock();
tbl = rht_dereference_rcu(ht->tbl, ht);
/* Because we have already taken (and released) the bucket
* lock in old_tbl, if we find that future_tbl is not yet
* visible then that guarantees the entry to still be in
* the old tbl if it exists.
*/
while ((err = __rhashtable_remove_fast(ht, tbl, obj, params)) &&
(tbl = rht_dereference_rcu(tbl->future_tbl, ht)))
;
if (err)
goto out;
atomic_dec(&ht->nelems);
if (unlikely(ht->p.automatic_shrinking &&
rht_shrink_below_30(ht, tbl)))
schedule_work(&ht->run_work);
out:
rcu_read_unlock();
return err;
}
#endif /* _LINUX_RHASHTABLE_H */

1346
os_dep/linux/rtw_android.c Normal file

File diff suppressed because it is too large Load Diff

2172
os_dep/linux/rtw_cfgvendor.c Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,638 @@
/******************************************************************************
*
* Copyright(c) 2007 - 2017 Realtek Corporation.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of version 2 of the GNU General Public License as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
*****************************************************************************/
#ifndef _RTW_CFGVENDOR_H_
#define _RTW_CFGVENDOR_H_
#define OUI_GOOGLE 0x001A11
#define ATTRIBUTE_U32_LEN (NLA_HDRLEN + 4)
#define VENDOR_ID_OVERHEAD ATTRIBUTE_U32_LEN
#define VENDOR_SUBCMD_OVERHEAD ATTRIBUTE_U32_LEN
#define VENDOR_DATA_OVERHEAD (NLA_HDRLEN)
#define SCAN_RESULTS_COMPLETE_FLAG_LEN ATTRIBUTE_U32_LEN
#define SCAN_INDEX_HDR_LEN (NLA_HDRLEN)
#define SCAN_ID_HDR_LEN ATTRIBUTE_U32_LEN
#define SCAN_FLAGS_HDR_LEN ATTRIBUTE_U32_LEN
#define GSCAN_NUM_RESULTS_HDR_LEN ATTRIBUTE_U32_LEN
#define GSCAN_RESULTS_HDR_LEN (NLA_HDRLEN)
#define GSCAN_BATCH_RESULT_HDR_LEN (SCAN_INDEX_HDR_LEN + SCAN_ID_HDR_LEN + \
SCAN_FLAGS_HDR_LEN + \
GSCAN_NUM_RESULTS_HDR_LEN + \
GSCAN_RESULTS_HDR_LEN)
#define VENDOR_REPLY_OVERHEAD (VENDOR_ID_OVERHEAD + \
VENDOR_SUBCMD_OVERHEAD + \
VENDOR_DATA_OVERHEAD)
typedef enum {
/* don't use 0 as a valid subcommand */
VENDOR_NL80211_SUBCMD_UNSPECIFIED,
/* define all vendor startup commands between 0x0 and 0x0FFF */
VENDOR_NL80211_SUBCMD_RANGE_START = 0x0001,
VENDOR_NL80211_SUBCMD_RANGE_END = 0x0FFF,
/* define all GScan related commands between 0x1000 and 0x10FF */
ANDROID_NL80211_SUBCMD_GSCAN_RANGE_START = 0x1000,
ANDROID_NL80211_SUBCMD_GSCAN_RANGE_END = 0x10FF,
/* define all NearbyDiscovery related commands between 0x1100 and 0x11FF */
ANDROID_NL80211_SUBCMD_NBD_RANGE_START = 0x1100,
ANDROID_NL80211_SUBCMD_NBD_RANGE_END = 0x11FF,
/* define all RTT related commands between 0x1100 and 0x11FF */
ANDROID_NL80211_SUBCMD_RTT_RANGE_START = 0x1100,
ANDROID_NL80211_SUBCMD_RTT_RANGE_END = 0x11FF,
ANDROID_NL80211_SUBCMD_LSTATS_RANGE_START = 0x1200,
ANDROID_NL80211_SUBCMD_LSTATS_RANGE_END = 0x12FF,
/* define all Logger related commands between 0x1400 and 0x14FF */
ANDROID_NL80211_SUBCMD_DEBUG_RANGE_START = 0x1400,
ANDROID_NL80211_SUBCMD_DEBUG_RANGE_END = 0x14FF,
/* define all wifi offload related commands between 0x1600 and 0x16FF */
ANDROID_NL80211_SUBCMD_WIFI_OFFLOAD_RANGE_START = 0x1600,
ANDROID_NL80211_SUBCMD_WIFI_OFFLOAD_RANGE_END = 0x16FF,
/* define all NAN related commands between 0x1700 and 0x17FF */
ANDROID_NL80211_SUBCMD_NAN_RANGE_START = 0x1700,
ANDROID_NL80211_SUBCMD_NAN_RANGE_END = 0x17FF,
/* define all Android Packet Filter related commands between 0x1800 and 0x18FF */
ANDROID_NL80211_SUBCMD_PKT_FILTER_RANGE_START = 0x1800,
ANDROID_NL80211_SUBCMD_PKT_FILTER_RANGE_END = 0x18FF,
/* This is reserved for future usage */
} ANDROID_VENDOR_SUB_COMMAND;
enum rtw_vendor_subcmd {
GSCAN_SUBCMD_GET_CAPABILITIES = ANDROID_NL80211_SUBCMD_GSCAN_RANGE_START,
GSCAN_SUBCMD_SET_CONFIG, /* 0x1001 */
GSCAN_SUBCMD_SET_SCAN_CONFIG, /* 0x1002 */
GSCAN_SUBCMD_ENABLE_GSCAN, /* 0x1003 */
GSCAN_SUBCMD_GET_SCAN_RESULTS, /* 0x1004 */
GSCAN_SUBCMD_SCAN_RESULTS, /* 0x1005 */
GSCAN_SUBCMD_SET_HOTLIST, /* 0x1006 */
GSCAN_SUBCMD_SET_SIGNIFICANT_CHANGE_CONFIG, /* 0x1007 */
GSCAN_SUBCMD_ENABLE_FULL_SCAN_RESULTS, /* 0x1008 */
GSCAN_SUBCMD_GET_CHANNEL_LIST, /* 0x1009 */
WIFI_SUBCMD_GET_FEATURE_SET, /* 0x100A */
WIFI_SUBCMD_GET_FEATURE_SET_MATRIX, /* 0x100B */
WIFI_SUBCMD_SET_PNO_RANDOM_MAC_OUI, /* 0x100C */
WIFI_SUBCMD_NODFS_SET, /* 0x100D */
WIFI_SUBCMD_SET_COUNTRY_CODE, /* 0x100E */
/* Add more sub commands here */
GSCAN_SUBCMD_SET_EPNO_SSID, /* 0x100F */
WIFI_SUBCMD_SET_SSID_WHITE_LIST, /* 0x1010 */
WIFI_SUBCMD_SET_ROAM_PARAMS, /* 0x1011 */
WIFI_SUBCMD_ENABLE_LAZY_ROAM, /* 0x1012 */
WIFI_SUBCMD_SET_BSSID_PREF, /* 0x1013 */
WIFI_SUBCMD_SET_BSSID_BLACKLIST, /* 0x1014 */
GSCAN_SUBCMD_ANQPO_CONFIG, /* 0x1015 */
WIFI_SUBCMD_SET_RSSI_MONITOR, /* 0x1016 */
WIFI_SUBCMD_CONFIG_ND_OFFLOAD, /* 0x1017 */
/* Add more sub commands here */
GSCAN_SUBCMD_MAX,
RTT_SUBCMD_SET_CONFIG = ANDROID_NL80211_SUBCMD_RTT_RANGE_START,
RTT_SUBCMD_CANCEL_CONFIG,
RTT_SUBCMD_GETCAPABILITY,
APF_SUBCMD_GET_CAPABILITIES = ANDROID_NL80211_SUBCMD_PKT_FILTER_RANGE_START,
APF_SUBCMD_SET_FILTER,
LOGGER_START_LOGGING = ANDROID_NL80211_SUBCMD_DEBUG_RANGE_START,
LOGGER_TRIGGER_MEM_DUMP,
LOGGER_GET_MEM_DUMP,
LOGGER_GET_VER,
LOGGER_GET_RING_STATUS,
LOGGER_GET_RING_DATA,
LOGGER_GET_FEATURE,
LOGGER_RESET_LOGGING,
LOGGER_TRIGGER_DRIVER_MEM_DUMP,
LOGGER_GET_DRIVER_MEM_DUMP,
LOGGER_START_PKT_FATE_MONITORING,
LOGGER_GET_TX_PKT_FATES,
LOGGER_GET_RX_PKT_FATES,
WIFI_OFFLOAD_SUBCMD_START_MKEEP_ALIVE = ANDROID_NL80211_SUBCMD_WIFI_OFFLOAD_RANGE_START,
WIFI_OFFLOAD_SUBCMD_STOP_MKEEP_ALIVE,
VENDOR_SUBCMD_MAX
};
enum gscan_attributes {
GSCAN_ATTRIBUTE_NUM_BUCKETS = 10,
GSCAN_ATTRIBUTE_BASE_PERIOD,
GSCAN_ATTRIBUTE_BUCKETS_BAND,
GSCAN_ATTRIBUTE_BUCKET_ID,
GSCAN_ATTRIBUTE_BUCKET_PERIOD,
GSCAN_ATTRIBUTE_BUCKET_NUM_CHANNELS,
GSCAN_ATTRIBUTE_BUCKET_CHANNELS,
GSCAN_ATTRIBUTE_NUM_AP_PER_SCAN,
GSCAN_ATTRIBUTE_REPORT_THRESHOLD,
GSCAN_ATTRIBUTE_NUM_SCANS_TO_CACHE,
GSCAN_ATTRIBUTE_BAND = GSCAN_ATTRIBUTE_BUCKETS_BAND,
GSCAN_ATTRIBUTE_ENABLE_FEATURE = 20,
GSCAN_ATTRIBUTE_SCAN_RESULTS_COMPLETE,
GSCAN_ATTRIBUTE_FLUSH_FEATURE,
GSCAN_ATTRIBUTE_ENABLE_FULL_SCAN_RESULTS,
GSCAN_ATTRIBUTE_REPORT_EVENTS,
/* remaining reserved for additional attributes */
GSCAN_ATTRIBUTE_NUM_OF_RESULTS = 30,
GSCAN_ATTRIBUTE_FLUSH_RESULTS,
GSCAN_ATTRIBUTE_SCAN_RESULTS, /* flat array of wifi_scan_result */
GSCAN_ATTRIBUTE_SCAN_ID, /* indicates scan number */
GSCAN_ATTRIBUTE_SCAN_FLAGS, /* indicates if scan was aborted */
GSCAN_ATTRIBUTE_AP_FLAGS, /* flags on significant change event */
GSCAN_ATTRIBUTE_NUM_CHANNELS,
GSCAN_ATTRIBUTE_CHANNEL_LIST,
/* remaining reserved for additional attributes */
GSCAN_ATTRIBUTE_SSID = 40,
GSCAN_ATTRIBUTE_BSSID,
GSCAN_ATTRIBUTE_CHANNEL,
GSCAN_ATTRIBUTE_RSSI,
GSCAN_ATTRIBUTE_TIMESTAMP,
GSCAN_ATTRIBUTE_RTT,
GSCAN_ATTRIBUTE_RTTSD,
/* remaining reserved for additional attributes */
GSCAN_ATTRIBUTE_HOTLIST_BSSIDS = 50,
GSCAN_ATTRIBUTE_RSSI_LOW,
GSCAN_ATTRIBUTE_RSSI_HIGH,
GSCAN_ATTRIBUTE_HOSTLIST_BSSID_ELEM,
GSCAN_ATTRIBUTE_HOTLIST_FLUSH,
/* remaining reserved for additional attributes */
GSCAN_ATTRIBUTE_RSSI_SAMPLE_SIZE = 60,
GSCAN_ATTRIBUTE_LOST_AP_SAMPLE_SIZE,
GSCAN_ATTRIBUTE_MIN_BREACHING,
GSCAN_ATTRIBUTE_SIGNIFICANT_CHANGE_BSSIDS,
GSCAN_ATTRIBUTE_SIGNIFICANT_CHANGE_FLUSH,
GSCAN_ATTRIBUTE_MAX
};
enum gscan_bucket_attributes {
GSCAN_ATTRIBUTE_CH_BUCKET_1,
GSCAN_ATTRIBUTE_CH_BUCKET_2,
GSCAN_ATTRIBUTE_CH_BUCKET_3,
GSCAN_ATTRIBUTE_CH_BUCKET_4,
GSCAN_ATTRIBUTE_CH_BUCKET_5,
GSCAN_ATTRIBUTE_CH_BUCKET_6,
GSCAN_ATTRIBUTE_CH_BUCKET_7
};
enum gscan_ch_attributes {
GSCAN_ATTRIBUTE_CH_ID_1,
GSCAN_ATTRIBUTE_CH_ID_2,
GSCAN_ATTRIBUTE_CH_ID_3,
GSCAN_ATTRIBUTE_CH_ID_4,
GSCAN_ATTRIBUTE_CH_ID_5,
GSCAN_ATTRIBUTE_CH_ID_6,
GSCAN_ATTRIBUTE_CH_ID_7
};
enum wifi_rssi_monitor_attr {
RSSI_MONITOR_ATTRIBUTE_MAX_RSSI,
RSSI_MONITOR_ATTRIBUTE_MIN_RSSI,
RSSI_MONITOR_ATTRIBUTE_START,
};
enum rtt_attributes {
RTT_ATTRIBUTE_TARGET_CNT,
RTT_ATTRIBUTE_TARGET_INFO,
RTT_ATTRIBUTE_TARGET_MAC,
RTT_ATTRIBUTE_TARGET_TYPE,
RTT_ATTRIBUTE_TARGET_PEER,
RTT_ATTRIBUTE_TARGET_CHAN,
RTT_ATTRIBUTE_TARGET_MODE,
RTT_ATTRIBUTE_TARGET_INTERVAL,
RTT_ATTRIBUTE_TARGET_NUM_MEASUREMENT,
RTT_ATTRIBUTE_TARGET_NUM_PKT,
RTT_ATTRIBUTE_TARGET_NUM_RETRY
};
enum logger_attributes {
LOGGER_ATTRIBUTE_GET_DRIVER,
LOGGER_ATTRIBUTE_GET_FW,
LOGGER_ATTRIBUTE_RING_ID,
LOGGER_ATTRIBUTE_RING_NAME,
LOGGER_ATTRIBUTE_RING_FLAGS,
LOGGER_ATTRIBUTE_LOG_LEVEL,
LOGGER_ATTRIBUTE_LOG_TIME_INTVAL,
LOGGER_ATTRIBUTE_LOG_MIN_DATA_SIZE,
LOGGER_ATTRIBUTE_FW_DUMP_LEN,
LOGGER_ATTRIBUTE_FW_DUMP_DATA,
LOGGERG_ATTRIBUTE_RING_DATA,
LOGGER_ATTRIBUTE_RING_STATUS,
LOGGER_ATTRIBUTE_RING_NUM
};
typedef enum rtw_vendor_event {
RTK_RESERVED1,
RTK_RESERVED2,
GSCAN_EVENT_SIGNIFICANT_CHANGE_RESULTS ,
GSCAN_EVENT_HOTLIST_RESULTS_FOUND,
GSCAN_EVENT_SCAN_RESULTS_AVAILABLE,
GSCAN_EVENT_FULL_SCAN_RESULTS,
RTT_EVENT_COMPLETE,
GSCAN_EVENT_COMPLETE_SCAN,
GSCAN_EVENT_HOTLIST_RESULTS_LOST,
GSCAN_EVENT_EPNO_EVENT,
GOOGLE_DEBUG_RING_EVENT,
GOOGLE_DEBUG_MEM_DUMP_EVENT,
GSCAN_EVENT_ANQPO_HOTSPOT_MATCH,
GOOGLE_RSSI_MONITOR_EVENT
} rtw_vendor_event_t;
enum andr_wifi_feature_set_attr {
ANDR_WIFI_ATTRIBUTE_NUM_FEATURE_SET,
ANDR_WIFI_ATTRIBUTE_FEATURE_SET,
ANDR_WIFI_ATTRIBUTE_RANDOM_MAC_OUI,
ANDR_WIFI_ATTRIBUTE_NODFS_SET,
ANDR_WIFI_ATTRIBUTE_COUNTRY,
ANDR_WIFI_ATTRIBUTE_ND_OFFLOAD_VALUE
// Add more attribute here
};
typedef enum rtw_vendor_gscan_attribute {
ATTR_START_GSCAN,
ATTR_STOP_GSCAN,
ATTR_SET_SCAN_BATCH_CFG_ID, /* set batch scan params */
ATTR_SET_SCAN_GEOFENCE_CFG_ID, /* set list of bssids to track */
ATTR_SET_SCAN_SIGNIFICANT_CFG_ID, /* set list of bssids, rssi threshold etc.. */
ATTR_SET_SCAN_CFG_ID, /* set common scan config params here */
ATTR_GET_GSCAN_CAPABILITIES_ID,
/* Add more sub commands here */
ATTR_GSCAN_MAX
} rtw_vendor_gscan_attribute_t;
typedef enum gscan_batch_attribute {
ATTR_GSCAN_BATCH_BESTN,
ATTR_GSCAN_BATCH_MSCAN,
ATTR_GSCAN_BATCH_BUFFER_THRESHOLD
} gscan_batch_attribute_t;
typedef enum gscan_geofence_attribute {
ATTR_GSCAN_NUM_HOTLIST_BSSID,
ATTR_GSCAN_HOTLIST_BSSID
} gscan_geofence_attribute_t;
typedef enum gscan_complete_event {
WIFI_SCAN_BUFFER_FULL,
WIFI_SCAN_COMPLETE
} gscan_complete_event_t;
/* wifi_hal.h */
/* WiFi Common definitions */
typedef unsigned char byte;
typedef int wifi_request_id;
typedef int wifi_channel; // indicates channel frequency in MHz
typedef int wifi_rssi;
typedef byte mac_addr[6];
typedef byte oui[3];
typedef int64_t wifi_timestamp; // In microseconds (us)
typedef int64_t wifi_timespan; // In picoseconds (ps)
struct wifi_info;
struct wifi_interface_info;
typedef struct wifi_info *wifi_handle;
typedef struct wifi_interface_info *wifi_interface_handle;
/* channel operating width */
typedef enum {
WIFI_CHAN_WIDTH_20 = 0,
WIFI_CHAN_WIDTH_40 = 1,
WIFI_CHAN_WIDTH_80 = 2,
WIFI_CHAN_WIDTH_160 = 3,
WIFI_CHAN_WIDTH_80P80 = 4,
WIFI_CHAN_WIDTH_5 = 5,
WIFI_CHAN_WIDTH_10 = 6,
WIFI_CHAN_WIDTH_INVALID = -1
} wifi_channel_width;
typedef int wifi_radio;
typedef struct {
wifi_channel_width width;
int center_frequency0;
int center_frequency1;
int primary_frequency;
} wifi_channel_spec;
typedef enum {
WIFI_SUCCESS = 0,
WIFI_ERROR_NONE = 0,
WIFI_ERROR_UNKNOWN = -1,
WIFI_ERROR_UNINITIALIZED = -2,
WIFI_ERROR_NOT_SUPPORTED = -3,
WIFI_ERROR_NOT_AVAILABLE = -4, // Not available right now, but try later
WIFI_ERROR_INVALID_ARGS = -5,
WIFI_ERROR_INVALID_REQUEST_ID = -6,
WIFI_ERROR_TIMED_OUT = -7,
WIFI_ERROR_TOO_MANY_REQUESTS = -8, // Too many instances of this request
WIFI_ERROR_OUT_OF_MEMORY = -9,
WIFI_ERROR_BUSY = -10,
} wifi_error;
typedef int wifi_ring_buffer_id;
/* ring buffer params */
/**
* written_bytes and read_bytes implement a producer consumer API
* hence written_bytes >= read_bytes
* a modulo arithmetic of the buffer size has to be applied to those counters:
* actual offset into ring buffer = written_bytes % ring_buffer_byte_size
*
*/
typedef struct {
u8 name[32];
u32 flags;
wifi_ring_buffer_id ring_id; // unique integer representing the ring
u32 ring_buffer_byte_size; // total memory size allocated for the buffer
u32 verbose_level; // verbose level for ring buffer
u32 written_bytes; // number of bytes that was written to the buffer by driver,
// monotonously increasing integer
u32 read_bytes; // number of bytes that was read from the buffer by user land,
// monotonously increasing integer
u32 written_records; // number of records that was written to the buffer by driver,
// monotonously increasing integer
} wifi_ring_buffer_status;
#ifdef CONFIG_RTW_CFGVENDOR_LLSTATS
#define STATS_MAJOR_VERSION 1
#define STATS_MINOR_VERSION 0
#define STATS_MICRO_VERSION 0
typedef enum {
WIFI_DISCONNECTED = 0,
WIFI_AUTHENTICATING = 1,
WIFI_ASSOCIATING = 2,
WIFI_ASSOCIATED = 3,
WIFI_EAPOL_STARTED = 4, // if done by firmware/driver
WIFI_EAPOL_COMPLETED = 5, // if done by firmware/driver
} wifi_connection_state;
typedef enum {
WIFI_ROAMING_IDLE = 0,
WIFI_ROAMING_ACTIVE = 1,
} wifi_roam_state;
typedef enum {
WIFI_INTERFACE_STA = 0,
WIFI_INTERFACE_SOFTAP = 1,
WIFI_INTERFACE_IBSS = 2,
WIFI_INTERFACE_P2P_CLIENT = 3,
WIFI_INTERFACE_P2P_GO = 4,
WIFI_INTERFACE_NAN = 5,
WIFI_INTERFACE_MESH = 6,
WIFI_INTERFACE_UNKNOWN = -1
} wifi_interface_mode;
#define WIFI_CAPABILITY_QOS 0x00000001 // set for QOS association
#define WIFI_CAPABILITY_PROTECTED 0x00000002 // set for protected association (802.11 beacon frame control protected bit set)
#define WIFI_CAPABILITY_INTERWORKING 0x00000004 // set if 802.11 Extended Capabilities element interworking bit is set
#define WIFI_CAPABILITY_HS20 0x00000008 // set for HS20 association
#define WIFI_CAPABILITY_SSID_UTF8 0x00000010 // set is 802.11 Extended Capabilities element UTF-8 SSID bit is set
#define WIFI_CAPABILITY_COUNTRY 0x00000020 // set is 802.11 Country Element is present
typedef struct {
wifi_interface_mode mode; // interface mode
u8 mac_addr[6]; // interface mac address (self)
wifi_connection_state state; // connection state (valid for STA, CLI only)
wifi_roam_state roaming; // roaming state
u32 capabilities; // WIFI_CAPABILITY_XXX (self)
u8 ssid[33]; // null terminated SSID
u8 bssid[6]; // bssid
u8 ap_country_str[3]; // country string advertised by AP
u8 country_str[3]; // country string for this association
} wifi_interface_link_layer_info;
/* channel information */
typedef struct {
wifi_channel_width width; // channel width (20, 40, 80, 80+80, 160)
wifi_channel center_freq; // primary 20 MHz channel
wifi_channel center_freq0; // center frequency (MHz) first segment
wifi_channel center_freq1; // center frequency (MHz) second segment
} wifi_channel_info;
/* wifi rate */
typedef struct {
u32 preamble :3; // 0: OFDM, 1:CCK, 2:HT 3:VHT 4..7 reserved
u32 nss :2; // 0:1x1, 1:2x2, 3:3x3, 4:4x4
u32 bw :3; // 0:20MHz, 1:40Mhz, 2:80Mhz, 3:160Mhz
u32 rateMcsIdx :8; // OFDM/CCK rate code would be as per ieee std in the units of 0.5mbps
// HT/VHT it would be mcs index
u32 reserved :16; // reserved
u32 bitrate; // units of 100 Kbps
} wifi_rate;
/* channel statistics */
typedef struct {
wifi_channel_info channel; // channel
u32 on_time; // msecs the radio is awake (32 bits number accruing over time)
u32 cca_busy_time; // msecs the CCA register is busy (32 bits number accruing over time)
} wifi_channel_stat;
// Max number of tx power levels. The actual number vary per device and is specified by |num_tx_levels|
#define RADIO_STAT_MAX_TX_LEVELS 256
/* Internal radio statistics structure in the driver */
typedef struct {
wifi_radio radio; // wifi radio (if multiple radio supported)
u32 on_time; // msecs the radio is awake (32 bits number accruing over time)
u32 tx_time; // msecs the radio is transmitting (32 bits number accruing over time)
u32 rx_time; // msecs the radio is in active receive (32 bits number accruing over time)
u32 on_time_scan; // msecs the radio is awake due to all scan (32 bits number accruing over time)
u32 on_time_nbd; // msecs the radio is awake due to NAN (32 bits number accruing over time)
u32 on_time_gscan; // msecs the radio is awake due to G?scan (32 bits number accruing over time)
u32 on_time_roam_scan; // msecs the radio is awake due to roam?scan (32 bits number accruing over time)
u32 on_time_pno_scan; // msecs the radio is awake due to PNO scan (32 bits number accruing over time)
u32 on_time_hs20; // msecs the radio is awake due to HS2.0 scans and GAS exchange (32 bits number accruing over time)
u32 num_channels; // number of channels
wifi_channel_stat channels[]; // channel statistics
} wifi_radio_stat_internal;
/**
* Packet statistics reporting by firmware is performed on MPDU basi (i.e. counters increase by 1 for each MPDU)
* As well, "data packet" in associated comments, shall be interpreted as 802.11 data packet,
* that is, 802.11 frame control subtype == 2 and excluding management and control frames.
*
* As an example, in the case of transmission of an MSDU fragmented in 16 MPDUs which are transmitted
* OTA in a 16 units long a-mpdu, for which a block ack is received with 5 bits set:
* tx_mpdu : shall increase by 5
* retries : shall increase by 16
* tx_ampdu : shall increase by 1
* data packet counters shall not increase regardless of the number of BAR potentially sent by device for this a-mpdu
* data packet counters shall not increase regardless of the number of BA received by device for this a-mpdu
*
* For each subsequent retransmission of the 11 remaining non ACK'ed mpdus
* (regardless of the fact that they are transmitted in a-mpdu or not)
* retries : shall increase by 1
*
* If no subsequent BA or ACK are received from AP, until packet lifetime expires for those 11 packet that were not ACK'ed
* mpdu_lost : shall increase by 11
*/
/* per rate statistics */
typedef struct {
wifi_rate rate; // rate information
u32 tx_mpdu; // number of successfully transmitted data pkts (ACK rcvd)
u32 rx_mpdu; // number of received data pkts
u32 mpdu_lost; // number of data packet losses (no ACK)
u32 retries; // total number of data pkt retries
u32 retries_short; // number of short data pkt retries
u32 retries_long; // number of long data pkt retries
} wifi_rate_stat;
/* access categories */
typedef enum {
WIFI_AC_VO = 0,
WIFI_AC_VI = 1,
WIFI_AC_BE = 2,
WIFI_AC_BK = 3,
WIFI_AC_MAX = 4,
} wifi_traffic_ac;
/* wifi peer type */
typedef enum
{
WIFI_PEER_STA,
WIFI_PEER_AP,
WIFI_PEER_P2P_GO,
WIFI_PEER_P2P_CLIENT,
WIFI_PEER_NAN,
WIFI_PEER_TDLS,
WIFI_PEER_INVALID,
} wifi_peer_type;
/* per peer statistics */
typedef struct {
wifi_peer_type type; // peer type (AP, TDLS, GO etc.)
u8 peer_mac_address[6]; // mac address
u32 capabilities; // peer WIFI_CAPABILITY_XXX
u32 num_rate; // number of rates
wifi_rate_stat rate_stats[]; // per rate statistics, number of entries = num_rate
} wifi_peer_info;
/* Per access category statistics */
typedef struct {
wifi_traffic_ac ac; // access category (VI, VO, BE, BK)
u32 tx_mpdu; // number of successfully transmitted unicast data pkts (ACK rcvd)
u32 rx_mpdu; // number of received unicast data packets
u32 tx_mcast; // number of succesfully transmitted multicast data packets
// STA case: implies ACK received from AP for the unicast packet in which mcast pkt was sent
u32 rx_mcast; // number of received multicast data packets
u32 rx_ampdu; // number of received unicast a-mpdus; support of this counter is optional
u32 tx_ampdu; // number of transmitted unicast a-mpdus; support of this counter is optional
u32 mpdu_lost; // number of data pkt losses (no ACK)
u32 retries; // total number of data pkt retries
u32 retries_short; // number of short data pkt retries
u32 retries_long; // number of long data pkt retries
u32 contention_time_min; // data pkt min contention time (usecs)
u32 contention_time_max; // data pkt max contention time (usecs)
u32 contention_time_avg; // data pkt avg contention time (usecs)
u32 contention_num_samples; // num of data pkts used for contention statistics
} wifi_wmm_ac_stat;
/* interface statistics */
typedef struct {
wifi_interface_handle iface; // wifi interface
wifi_interface_link_layer_info info; // current state of the interface
u32 beacon_rx; // access point beacon received count from connected AP
u64 average_tsf_offset; // average beacon offset encountered (beacon_TSF - TBTT)
// The average_tsf_offset field is used so as to calculate the
// typical beacon contention time on the channel as well may be
// used to debug beacon synchronization and related power consumption issue
u32 leaky_ap_detected; // indicate that this AP typically leaks packets beyond the driver guard time.
u32 leaky_ap_avg_num_frames_leaked; // average number of frame leaked by AP after frame with PM bit set was ACK'ed by AP
u32 leaky_ap_guard_time; // guard time currently in force (when implementing IEEE power management based on
// frame control PM bit), How long driver waits before shutting down the radio and
// after receiving an ACK for a data frame with PM bit set)
u32 mgmt_rx; // access point mgmt frames received count from connected AP (including Beacon)
u32 mgmt_action_rx; // action frames received count
u32 mgmt_action_tx; // action frames transmit count
wifi_rssi rssi_mgmt; // access Point Beacon and Management frames RSSI (averaged)
wifi_rssi rssi_data; // access Point Data Frames RSSI (averaged) from connected AP
wifi_rssi rssi_ack; // access Point ACK RSSI (averaged) from connected AP
wifi_wmm_ac_stat ac[WIFI_AC_MAX]; // per ac data packet statistics
u32 num_peers; // number of peers
wifi_peer_info peer_info[]; // per peer statistics
} wifi_iface_stat;
/* configuration params */
typedef struct {
u32 mpdu_size_threshold; // threshold to classify the pkts as short or long
// packet size < mpdu_size_threshold => short
u32 aggressive_statistics_gathering; // set for field debug mode. Driver should collect all statistics regardless of performance impact.
} wifi_link_layer_params;
#define RSSI_MONITOR_EVT_VERSION 1
typedef struct {
u8 version;
s8 cur_rssi;
mac_addr BSSID;
} rssi_monitor_evt;
/* wifi statistics bitmap */
#define WIFI_STATS_RADIO 0x00000001 // all radio statistics
#define WIFI_STATS_RADIO_CCA 0x00000002 // cca_busy_time (within radio statistics)
#define WIFI_STATS_RADIO_CHANNELS 0x00000004 // all channel statistics (within radio statistics)
#define WIFI_STATS_RADIO_SCAN 0x00000008 // all scan statistics (within radio statistics)
#define WIFI_STATS_IFACE 0x00000010 // all interface statistics
#define WIFI_STATS_IFACE_TXRATE 0x00000020 // all tx rate statistics (within interface statistics)
#define WIFI_STATS_IFACE_AC 0x00000040 // all ac statistics (within interface statistics)
#define WIFI_STATS_IFACE_CONTENTION 0x00000080 // all contention (min, max, avg) statistics (within ac statisctics)
#endif /* CONFIG_RTW_CFGVENDOR_LLSTATS */
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 14, 0)) || defined(RTW_VENDOR_EXT_SUPPORT)
extern int rtw_cfgvendor_attach(struct wiphy *wiphy);
extern int rtw_cfgvendor_detach(struct wiphy *wiphy);
extern int rtw_cfgvendor_send_async_event(struct wiphy *wiphy,
struct net_device *dev, int event_id, const void *data, int len);
#if defined(GSCAN_SUPPORT) && 0
extern int rtw_cfgvendor_send_hotlist_event(struct wiphy *wiphy,
struct net_device *dev, void *data, int len, rtw_vendor_event_t event);
#endif
#endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 14, 0)) || defined(RTW_VENDOR_EXT_SUPPORT) */
#ifdef CONFIG_RTW_CFGVENDOR_RSSIMONITOR
void rtw_cfgvendor_rssi_monitor_evt(_adapter *padapter);
#endif
#ifdef CONFIG_RTW_CFGVENDOR_RANDOM_MAC_OUI
void rtw_hal_pno_random_gen_mac_addr(PADAPTER adapter);
#endif
#if defined(CONFIG_RTW_CFGVENDOR_RANDOM_MAC_OUI) || defined(CONFIG_RTW_SCAN_RAND)
void rtw_hal_set_hw_mac_addr(PADAPTER adapter, u8 *mac_addr);
#endif
#endif /* _RTW_CFGVENDOR_H_ */

6290
os_dep/linux/rtw_proc.c Normal file

File diff suppressed because it is too large Load Diff

72
os_dep/linux/rtw_proc.h Normal file
View File

@ -0,0 +1,72 @@
/******************************************************************************
*
* Copyright(c) 2007 - 2017 Realtek Corporation.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of version 2 of the GNU General Public License as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
*****************************************************************************/
#ifndef __RTW_PROC_H__
#define __RTW_PROC_H__
#include <linux/proc_fs.h>
#include <linux/seq_file.h>
#define RTW_PROC_HDL_TYPE_SEQ 0
#define RTW_PROC_HDL_TYPE_SSEQ 1
#define RTW_PROC_HDL_TYPE_SZSEQ 2
struct rtw_proc_hdl {
char *name;
u8 type;
union {
int (*show)(struct seq_file *, void *);
struct seq_operations *seq_op;
struct {
int (*show)(struct seq_file *, void *);
size_t size;
} sz;
} u;
ssize_t (*write)(struct file *file, const char __user *buffer, size_t count, loff_t *pos, void *data);
};
#define RTW_PROC_HDL_SEQ(_name, _seq_op, _write) \
{ .name = _name, .type = RTW_PROC_HDL_TYPE_SEQ, .u.seq_op = _seq_op, .write = _write}
#define RTW_PROC_HDL_SSEQ(_name, _show, _write) \
{ .name = _name, .type = RTW_PROC_HDL_TYPE_SSEQ, .u.show = _show, .write = _write}
#define RTW_PROC_HDL_SZSEQ(_name, _show, _write, _size) \
{ .name = _name, .type = RTW_PROC_HDL_TYPE_SZSEQ, .u.sz.show = _show, .write = _write, .u.sz.size = _size}
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 6, 0))
#define rtw_proc_ops proc_ops
#else
#define rtw_proc_ops file_operations
#endif
#ifdef CONFIG_PROC_DEBUG
int rtw_drv_proc_init(void);
void rtw_drv_proc_deinit(void);
struct proc_dir_entry *rtw_adapter_proc_init(struct net_device *dev);
void rtw_adapter_proc_deinit(struct net_device *dev);
void rtw_adapter_proc_replace(struct net_device *dev);
#else /* !CONFIG_PROC_DEBUG */
static inline int rtw_drv_proc_init(void) {return _FAIL;}
#define rtw_drv_proc_deinit() do {} while (0)
static inline struct proc_dir_entry *rtw_adapter_proc_init(struct net_device *dev) {return NULL;}
#define rtw_adapter_proc_deinit(dev) do {} while (0)
#define rtw_adapter_proc_replace(dev) do {} while (0)
#endif /* !CONFIG_PROC_DEBUG */
#endif /* __RTW_PROC_H__ */

View File

@ -0,0 +1,77 @@
/******************************************************************************
*
* Copyright(c) 2007 - 2017 Realtek Corporation.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of version 2 of the GNU General Public License as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
*****************************************************************************/
#include <drv_types.h>
#if defined(CONFIG_RTW_WDS) || defined(CONFIG_RTW_MESH) /* for now, only promised for kernel versions we support mesh */
int rtw_rhashtable_walk_enter(rtw_rhashtable *ht, rtw_rhashtable_iter *iter)
{
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 9, 0))
rhashtable_walk_enter((ht), (iter));
return 0;
#elif (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 7, 0))
return rhashtable_walk_init((ht), (iter), GFP_ATOMIC);
#else
/* kernel >= 4.4.0 rhashtable_walk_init use GFP_KERNEL to alloc, spin_lock for assignment */
iter->ht = ht;
iter->p = NULL;
iter->slot = 0;
iter->skip = 0;
iter->walker = kmalloc(sizeof(*iter->walker), GFP_ATOMIC);
if (!iter->walker)
return -ENOMEM;
spin_lock(&ht->lock);
iter->walker->tbl =
rcu_dereference_protected(ht->tbl, lockdep_is_held(&ht->lock));
list_add(&iter->walker->list, &iter->walker->tbl->walkers);
spin_unlock(&ht->lock);
return 0;
#endif
}
#if (LINUX_VERSION_CODE < KERNEL_VERSION(4, 4, 0))
#if (LINUX_VERSION_CODE < KERNEL_VERSION(3, 15, 0))
#if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 25))
static inline int is_vmalloc_addr(const void *x)
{
#ifdef CONFIG_MMU
unsigned long addr = (unsigned long)x;
return addr >= VMALLOC_START && addr < VMALLOC_END;
#else
return 0;
#endif
}
#endif /* (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 25)) */
void kvfree(const void *addr)
{
if (is_vmalloc_addr(addr))
vfree(addr);
else
kfree(addr);
}
#endif /* (LINUX_VERSION_CODE < KERNEL_VERSION(3, 15, 0)) */
#include "rhashtable.c"
#endif /* (LINUX_VERSION_CODE < KERNEL_VERSION(4, 4, 0)) */
#endif /* defined(CONFIG_RTW_WDS) || defined(CONFIG_RTW_MESH) */

View File

@ -0,0 +1,67 @@
/******************************************************************************
*
* Copyright(c) 2007 - 2017 Realtek Corporation.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of version 2 of the GNU General Public License as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
*****************************************************************************/
#ifndef __RTW_RHASHTABLE_H__
#define __RTW_RHASHTABLE_H__
#if defined(CONFIG_RTW_WDS) || defined(CONFIG_RTW_MESH) /* for now, only promised for kernel versions we support mesh */
/* directly reference rhashtable in kernel */
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 4, 0))
#include <linux/rhashtable.h>
#endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 4, 0)) */
/* Use rhashtable from kernel 4.4 */
#if (LINUX_VERSION_CODE < KERNEL_VERSION(4, 4, 0))
#if (LINUX_VERSION_CODE < KERNEL_VERSION(4, 0, 0))
#define NULLS_MARKER(value) (1UL | (((long)value) << 1))
#endif
#if (LINUX_VERSION_CODE < KERNEL_VERSION(3, 4, 0))
static inline void *kmalloc_array(size_t n, size_t size, gfp_t flags)
{
if (size != 0 && n > ULONG_MAX / size)
return NULL;
return __kmalloc(n * size, flags);
}
#endif
#include "rhashtable.h"
#endif /* (LINUX_VERSION_CODE < KERNEL_VERSION(4, 4, 0)) */
typedef struct rhashtable rtw_rhashtable;
typedef struct rhash_head rtw_rhash_head;
typedef struct rhashtable_params rtw_rhashtable_params;
#define rtw_rhashtable_init(ht, params) rhashtable_init(ht, params)
typedef struct rhashtable_iter rtw_rhashtable_iter;
int rtw_rhashtable_walk_enter(rtw_rhashtable *ht, rtw_rhashtable_iter *iter);
#define rtw_rhashtable_walk_exit(iter) rhashtable_walk_exit(iter)
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 16, 0))
#define rtw_rhashtable_walk_start(iter) rhashtable_walk_start_check(iter)
#else
#define rtw_rhashtable_walk_start(iter) rhashtable_walk_start(iter)
#endif
#define rtw_rhashtable_walk_next(iter) rhashtable_walk_next(iter)
#define rtw_rhashtable_walk_stop(iter) rhashtable_walk_stop(iter)
#define rtw_rhashtable_free_and_destroy(ht, free_fn, arg) rhashtable_free_and_destroy((ht), (free_fn), (arg))
#define rtw_rhashtable_lookup_fast(ht, key, params) rhashtable_lookup_fast((ht), (key), (params))
#define rtw_rhashtable_lookup_insert_fast(ht, obj, params) rhashtable_lookup_insert_fast((ht), (obj), (params))
#define rtw_rhashtable_remove_fast(ht, obj, params) rhashtable_remove_fast((ht), (obj), (params))
#endif /* defined(CONFIG_RTW_WDS) || defined(CONFIG_RTW_MESH) */
#endif /* __RTW_RHASHTABLE_H__ */

1505
os_dep/linux/usb_intf.c Normal file

File diff suppressed because it is too large Load Diff

1157
os_dep/linux/usb_ops_linux.c Normal file

File diff suppressed because it is too large Load Diff

414
os_dep/linux/wifi_regd.c Normal file
View File

@ -0,0 +1,414 @@
/******************************************************************************
*
* Copyright(c) 2009-2010 - 2017 Realtek Corporation.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of version 2 of the GNU General Public License as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
*****************************************************************************/
#include <drv_types.h>
#ifdef CONFIG_IOCTL_CFG80211
static void rtw_regd_overide_flags(struct wiphy *wiphy, struct rf_ctl_t *rfctl)
{
RT_CHANNEL_INFO *channel_set = rfctl->channel_set;
u8 max_chan_nums = rfctl->max_chan_nums;
struct ieee80211_supported_band *sband;
struct ieee80211_channel *ch;
unsigned int i, j;
u16 channel;
u32 freq;
/* all channels disable */
for (i = 0; i < NUM_NL80211_BANDS; i++) {
sband = wiphy->bands[i];
if (!sband)
continue;
for (j = 0; j < sband->n_channels; j++) {
ch = &sband->channels[j];
if (!ch)
continue;
ch->flags = IEEE80211_CHAN_DISABLED;
}
}
/* channels apply by channel plans. */
for (i = 0; i < max_chan_nums; i++) {
channel = channel_set[i].ChannelNum;
freq = rtw_ch2freq(channel);
ch = ieee80211_get_channel(wiphy, freq);
if (!ch) {
rtw_warn_on(1);
continue;
}
/* enable */
ch->flags = 0;
if (channel_set[i].flags & RTW_CHF_DFS) {
/*
* before integrating with nl80211 flow
* bypass IEEE80211_CHAN_RADAR when configured with radar detection
* to prevent from hostapd blocking DFS channels
*/
if (rtw_rfctl_dfs_domain_unknown(rfctl))
ch->flags |= IEEE80211_CHAN_RADAR;
}
if (channel_set[i].flags & RTW_CHF_NO_IR) {
#if (LINUX_VERSION_CODE < KERNEL_VERSION(3, 14, 0))
ch->flags |= IEEE80211_CHAN_NO_IBSS | IEEE80211_CHAN_PASSIVE_SCAN;
#else
ch->flags |= IEEE80211_CHAN_NO_IR;
#endif
}
}
}
#ifdef CONFIG_REGD_SRC_FROM_OS
static void rtw_regd_apply_dfs_flags(struct rf_ctl_t *rfctl)
{
RT_CHANNEL_INFO *channel_set = rfctl->channel_set;
u8 max_chan_nums = rfctl->max_chan_nums;
unsigned int i;
struct ieee80211_channel *chan;
/* channels apply by channel plans. */
for (i = 0; i < max_chan_nums; i++) {
chan = channel_set[i].os_chan;
if (channel_set[i].flags & RTW_CHF_DFS) {
/*
* before integrating with nl80211 flow
* clear IEEE80211_CHAN_RADAR when configured with radar detection
* to prevent from hostapd blocking DFS channels
*/
if (!rtw_rfctl_dfs_domain_unknown(rfctl))
chan->flags &= ~IEEE80211_CHAN_RADAR;
}
}
}
#endif
void rtw_regd_apply_flags(struct wiphy *wiphy)
{
struct dvobj_priv *dvobj = wiphy_to_dvobj(wiphy);
struct rf_ctl_t *rfctl = dvobj_to_rfctl(dvobj);
if (rfctl->regd_src == REGD_SRC_RTK_PRIV)
rtw_regd_overide_flags(wiphy, rfctl);
#ifdef CONFIG_REGD_SRC_FROM_OS
else if (rfctl->regd_src == REGD_SRC_OS)
rtw_regd_apply_dfs_flags(rfctl);
#endif
else
rtw_warn_on(1);
}
#ifdef CONFIG_REGD_SRC_FROM_OS
/* init_channel_set_from_wiphy */
u8 rtw_os_init_channel_set(_adapter *padapter, RT_CHANNEL_INFO *channel_set)
{
struct wiphy *wiphy = adapter_to_wiphy(padapter);
struct rf_ctl_t *rfctl = adapter_to_rfctl(padapter);
struct registry_priv *regsty = adapter_to_regsty(padapter);
struct ieee80211_channel *chan;
u8 chanset_size = 0;
int i, j;
_rtw_memset(channel_set, 0, sizeof(RT_CHANNEL_INFO) * MAX_CHANNEL_NUM);
for (i = NL80211_BAND_2GHZ; i <= NL80211_BAND_5GHZ; i++) {
if (!wiphy->bands[i])
continue;
for (j = 0; j < wiphy->bands[i]->n_channels; j++) {
chan = &wiphy->bands[i]->channels[j];
if (chan->flags & IEEE80211_CHAN_DISABLED)
continue;
if (rtw_regsty_is_excl_chs(regsty, chan->hw_value))
continue;
if (chanset_size >= MAX_CHANNEL_NUM) {
RTW_WARN("chset size can't exceed MAX_CHANNEL_NUM(%u)\n", MAX_CHANNEL_NUM);
i = NL80211_BAND_5GHZ + 1;
break;
}
channel_set[chanset_size].ChannelNum = chan->hw_value;
#if (LINUX_VERSION_CODE < KERNEL_VERSION(3, 14, 0))
if (chan->flags & (IEEE80211_CHAN_NO_IBSS | IEEE80211_CHAN_PASSIVE_SCAN))
#else
if (chan->flags & IEEE80211_CHAN_NO_IR)
#endif
channel_set[chanset_size].flags |= RTW_CHF_NO_IR;
if (chan->flags & IEEE80211_CHAN_RADAR)
channel_set[chanset_size].flags |= RTW_CHF_DFS;
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27))
if (chan->flags & IEEE80211_CHAN_NO_HT40PLUS)
channel_set[chanset_size].flags |= RTW_CHF_NO_HT40U;
if (chan->flags & IEEE80211_CHAN_NO_HT40MINUS)
channel_set[chanset_size].flags |= RTW_CHF_NO_HT40L;
#endif
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 9, 0))
if (chan->flags & IEEE80211_CHAN_NO_80MHZ)
channel_set[chanset_size].flags |= RTW_CHF_NO_80MHZ;
if (chan->flags & IEEE80211_CHAN_NO_160MHZ)
channel_set[chanset_size].flags |= RTW_CHF_NO_160MHZ;
#endif
channel_set[chanset_size].os_chan = chan;
chanset_size++;
}
}
#if CONFIG_IEEE80211_BAND_5GHZ
#ifdef CONFIG_DFS_MASTER
for (i = 0; i < chanset_size; i++)
channel_set[i].non_ocp_end_time = rtw_get_current_time();
#endif
#endif /* CONFIG_IEEE80211_BAND_5GHZ */
if (chanset_size)
RTW_INFO(FUNC_ADPT_FMT" ch num:%d\n"
, FUNC_ADPT_ARG(padapter), chanset_size);
else
RTW_WARN(FUNC_ADPT_FMT" final chset has no channel\n"
, FUNC_ADPT_ARG(padapter));
return chanset_size;
}
s16 rtw_os_get_total_txpwr_regd_lmt_mbm(_adapter *adapter, u8 cch, enum channel_width bw)
{
struct wiphy *wiphy = adapter_to_wiphy(adapter);
s16 mbm = UNSPECIFIED_MBM;
u8 *op_chs;
u8 op_ch_num;
u8 i;
u32 freq;
struct ieee80211_channel *ch;
if (!rtw_get_op_chs_by_cch_bw(cch, bw, &op_chs, &op_ch_num))
goto exit;
for (i = 0; i < op_ch_num; i++) {
freq = rtw_ch2freq(op_chs[i]);
ch = ieee80211_get_channel(wiphy, freq);
if (!ch) {
rtw_warn_on(1);
continue;
}
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 4, 0))
mbm = rtw_min(mbm, ch->max_reg_power * MBM_PDBM);
#else
/* require max_power == 0 (therefore orig_mpwr set to 0) when wiphy registration */
mbm = rtw_min(mbm, ch->max_power * MBM_PDBM);
#endif
}
exit:
return mbm;
}
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 3, 0))
static enum rtw_dfs_regd nl80211_dfs_regions_to_rtw_dfs_region(enum nl80211_dfs_regions region)
{
switch (region) {
case NL80211_DFS_FCC:
return RTW_DFS_REGD_FCC;
case NL80211_DFS_ETSI:
return RTW_DFS_REGD_ETSI;
case NL80211_DFS_JP:
return RTW_DFS_REGD_MKK;
case NL80211_DFS_UNSET:
default:
return RTW_DFS_REGD_NONE;
}
};
#endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 3, 0)) */
#endif /* CONFIG_REGD_SRC_FROM_OS */
#ifdef CONFIG_RTW_DEBUG
static const char *nl80211_reg_initiator_str(enum nl80211_reg_initiator initiator)
{
switch (initiator) {
case NL80211_REGDOM_SET_BY_DRIVER:
return "DRIVER";
case NL80211_REGDOM_SET_BY_CORE:
return "CORE";
case NL80211_REGDOM_SET_BY_USER:
return "USER";
case NL80211_REGDOM_SET_BY_COUNTRY_IE:
return "COUNTRY_IE";
}
rtw_warn_on(1);
return "UNKNOWN";
}
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 6, 0))
static const char *nl80211_user_reg_hint_type_str(enum nl80211_user_reg_hint_type type)
{
switch (type) {
case NL80211_USER_REG_HINT_USER:
return "USER";
case NL80211_USER_REG_HINT_CELL_BASE:
return "CELL_BASE";
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 16, 0))
case NL80211_USER_REG_HINT_INDOOR:
return "INDOOR";
#endif
}
rtw_warn_on(1);
return "UNKNOWN";
}
#endif
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 3, 0))
static const char *nl80211_dfs_regions_str(enum nl80211_dfs_regions region)
{
switch (region) {
case NL80211_DFS_UNSET:
return "UNSET";
case NL80211_DFS_FCC:
return "FCC";
case NL80211_DFS_ETSI:
return "ETSI";
case NL80211_DFS_JP:
return "JP";
}
rtw_warn_on(1);
return "UNKNOWN";
};
#endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 3, 0)) */
static const char *environment_cap_str(enum environment_cap cap)
{
switch (cap) {
case ENVIRON_ANY:
return "ANY";
case ENVIRON_INDOOR:
return "INDOOR";
case ENVIRON_OUTDOOR:
return "OUTDOOR";
}
rtw_warn_on(1);
return "UNKNOWN";
}
static void dump_requlatory_request(void *sel, struct regulatory_request *request)
{
u8 alpha2_len;
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 16, 0))
alpha2_len = 3;
#else
alpha2_len = 2;
#endif
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 6, 0))
RTW_PRINT_SEL(sel, "initiator:%s, wiphy_idx:%d, type:%s\n"
, nl80211_reg_initiator_str(request->initiator)
, request->wiphy_idx
, nl80211_user_reg_hint_type_str(request->user_reg_hint_type));
#else
RTW_PRINT_SEL(sel, "initiator:%s, wiphy_idx:%d\n"
, nl80211_reg_initiator_str(request->initiator)
, request->wiphy_idx);
#endif
RTW_PRINT_SEL(sel, "alpha2:%.*s\n", alpha2_len, request->alpha2);
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 3, 0))
RTW_PRINT_SEL(sel, "dfs_region:%s\n", nl80211_dfs_regions_str(request->dfs_region));
#endif
RTW_PRINT_SEL(sel, "intersect:%d\n", request->intersect);
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 38))
RTW_PRINT_SEL(sel, "processed:%d\n", request->processed);
#endif
#if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 36))
RTW_PRINT_SEL(sel, "country_ie_checksum:0x%08x\n", request->country_ie_checksum);
#endif
RTW_PRINT_SEL(sel, "country_ie_env:%s\n", environment_cap_str(request->country_ie_env));
}
#endif /* CONFIG_RTW_DEBUG */
static void rtw_reg_notifier(struct wiphy *wiphy, struct regulatory_request *request)
{
struct dvobj_priv *dvobj = wiphy_to_dvobj(wiphy);
struct rf_ctl_t *rfctl = dvobj_to_rfctl(dvobj);
struct registry_priv *regsty = dvobj_to_regsty(dvobj);
#ifdef CONFIG_RTW_DEBUG
if (rtw_drv_log_level >= _DRV_INFO_) {
RTW_INFO(FUNC_WIPHY_FMT"\n", FUNC_WIPHY_ARG(wiphy));
dump_requlatory_request(RTW_DBGDUMP, request);
}
#endif
#ifdef CONFIG_REGD_SRC_FROM_OS
if (REGSTY_REGD_SRC_FROM_OS(regsty)) {
enum rtw_dfs_regd dfs_region = RTW_DFS_REGD_NONE;
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 3, 0))
dfs_region = nl80211_dfs_regions_to_rtw_dfs_region(request->dfs_region);
#endif
/* trigger command to sync regulatory form OS */
rtw_sync_os_regd_cmd(wiphy_to_adapter(wiphy), RTW_CMDF_WAIT_ACK, request->alpha2, dfs_region);
} else
#endif
{
/* use alpha2 as input to select the corresponding channel plan settings defined by Realtek */
switch (request->initiator) {
case NL80211_REGDOM_SET_BY_DRIVER:
break;
case NL80211_REGDOM_SET_BY_CORE:
break;
case NL80211_REGDOM_SET_BY_USER:
rtw_set_country(wiphy_to_adapter(wiphy), request->alpha2);
break;
case NL80211_REGDOM_SET_BY_COUNTRY_IE:
break;
}
rtw_regd_apply_flags(wiphy);
}
}
#if (LINUX_VERSION_CODE < KERNEL_VERSION(3, 9, 0))
static int rtw_reg_notifier_return(struct wiphy *wiphy, struct regulatory_request *request)
{
rtw_reg_notifier(wiphy, request);
return 0;
}
#endif
int rtw_regd_init(struct wiphy *wiphy)
{
#if (LINUX_VERSION_CODE < KERNEL_VERSION(3, 9, 0))
wiphy->reg_notifier = rtw_reg_notifier_return;
#else
wiphy->reg_notifier = rtw_reg_notifier;
#endif
#if (LINUX_VERSION_CODE < KERNEL_VERSION(3, 14, 0))
wiphy->flags &= ~WIPHY_FLAG_STRICT_REGULATORY;
wiphy->flags &= ~WIPHY_FLAG_DISABLE_BEACON_HINTS;
#else
wiphy->regulatory_flags &= ~REGULATORY_STRICT_REG;
wiphy->regulatory_flags &= ~REGULATORY_DISABLE_BEACON_HINTS;
#endif
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 19, 0))
wiphy->regulatory_flags |= REGULATORY_IGNORE_STALE_KICKOFF;
#endif
return 0;
}
#endif /* CONFIG_IOCTL_CFG80211 */

27
os_dep/linux/wifi_regd.h Normal file
View File

@ -0,0 +1,27 @@
/******************************************************************************
*
* Copyright(c) 2009-2010 - 2017 Realtek Corporation.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of version 2 of the GNU General Public License as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
*****************************************************************************/
#ifndef __WIFI_REGD_H__
#define __WIFI_REGD_H__
void rtw_regd_apply_flags(struct wiphy *wiphy);
#ifdef CONFIG_REGD_SRC_FROM_OS
struct _RT_CHANNEL_INFO;
u8 rtw_os_init_channel_set(_adapter *padapter, struct _RT_CHANNEL_INFO *channel_set);
s16 rtw_os_get_total_txpwr_regd_lmt_mbm(_adapter *adapter, u8 cch, enum channel_width bw);
#endif
int rtw_regd_init(struct wiphy *wiphy);
#endif /* __WIFI_REGD_H__ */

554
os_dep/linux/xmit_linux.c Normal file
View File

@ -0,0 +1,554 @@
/******************************************************************************
*
* Copyright(c) 2007 - 2017 Realtek Corporation.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of version 2 of the GNU General Public License as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
*****************************************************************************/
#define _XMIT_OSDEP_C_
#include <drv_types.h>
#define DBG_DUMP_OS_QUEUE_CTL 0
uint rtw_remainder_len(struct pkt_file *pfile)
{
return pfile->buf_len - ((SIZE_PTR)(pfile->cur_addr) - (SIZE_PTR)(pfile->buf_start));
}
void _rtw_open_pktfile(_pkt *pktptr, struct pkt_file *pfile)
{
pfile->pkt = pktptr;
pfile->cur_addr = pfile->buf_start = pktptr->data;
pfile->pkt_len = pfile->buf_len = pktptr->len;
pfile->cur_buffer = pfile->buf_start ;
}
uint _rtw_pktfile_read(struct pkt_file *pfile, u8 *rmem, uint rlen)
{
uint len = 0;
len = rtw_remainder_len(pfile);
len = (rlen > len) ? len : rlen;
if (rmem)
skb_copy_bits(pfile->pkt, pfile->buf_len - pfile->pkt_len, rmem, len);
pfile->cur_addr += len;
pfile->pkt_len -= len;
return len;
}
sint rtw_endofpktfile(struct pkt_file *pfile)
{
if (pfile->pkt_len == 0) {
return _TRUE;
}
return _FALSE;
}
void rtw_set_tx_chksum_offload(_pkt *pkt, struct pkt_attrib *pattrib)
{
#ifdef CONFIG_TCP_CSUM_OFFLOAD_TX
struct sk_buff *skb = (struct sk_buff *)pkt;
struct iphdr *iph = NULL;
struct ipv6hdr *i6ph = NULL;
struct udphdr *uh = NULL;
struct tcphdr *th = NULL;
u8 protocol = 0xFF;
if (skb->protocol == htons(ETH_P_IP)) {
iph = (struct iphdr *)skb_network_header(skb);
protocol = iph->protocol;
} else if (skb->protocol == htons(ETH_P_IPV6)) {
i6ph = (struct ipv6hdr *)skb_network_header(skb);
protocol = i6ph->nexthdr;
} else
{}
/* HW unable to compute CSUM if header & payload was be encrypted by SW(cause TXDMA error) */
if (pattrib->bswenc == _TRUE) {
if (skb->ip_summed == CHECKSUM_PARTIAL)
skb_checksum_help(skb);
return;
}
/* For HW rule, clear ipv4_csum & UDP/TCP_csum if it is UDP/TCP packet */
switch (protocol) {
case IPPROTO_UDP:
uh = (struct udphdr *)skb_transport_header(skb);
uh->check = 0;
if (iph)
iph->check = 0;
pattrib->hw_csum = _TRUE;
break;
case IPPROTO_TCP:
th = (struct tcphdr *)skb_transport_header(skb);
th->check = 0;
if (iph)
iph->check = 0;
pattrib->hw_csum = _TRUE;
break;
default:
break;
}
#endif
}
int rtw_os_xmit_resource_alloc(_adapter *padapter, struct xmit_buf *pxmitbuf, u32 alloc_sz, u8 flag)
{
if (alloc_sz > 0) {
#ifdef CONFIG_USE_USB_BUFFER_ALLOC_TX
struct dvobj_priv *pdvobjpriv = adapter_to_dvobj(padapter);
struct usb_device *pusbd = pdvobjpriv->pusbdev;
pxmitbuf->pallocated_buf = rtw_usb_buffer_alloc(pusbd, (size_t)alloc_sz, &pxmitbuf->dma_transfer_addr);
pxmitbuf->pbuf = pxmitbuf->pallocated_buf;
if (pxmitbuf->pallocated_buf == NULL)
return _FAIL;
#else /* CONFIG_USE_USB_BUFFER_ALLOC_TX */
pxmitbuf->pallocated_buf = rtw_zmalloc(alloc_sz);
if (pxmitbuf->pallocated_buf == NULL)
return _FAIL;
pxmitbuf->pbuf = (u8 *)N_BYTE_ALIGMENT((SIZE_PTR)(pxmitbuf->pallocated_buf), XMITBUF_ALIGN_SZ);
#endif /* CONFIG_USE_USB_BUFFER_ALLOC_TX */
}
if (flag) {
#ifdef CONFIG_USB_HCI
int i;
for (i = 0; i < 8; i++) {
pxmitbuf->pxmit_urb[i] = usb_alloc_urb(0, GFP_KERNEL);
if (pxmitbuf->pxmit_urb[i] == NULL) {
RTW_INFO("pxmitbuf->pxmit_urb[i]==NULL");
return _FAIL;
}
}
#endif
}
return _SUCCESS;
}
void rtw_os_xmit_resource_free(_adapter *padapter, struct xmit_buf *pxmitbuf, u32 free_sz, u8 flag)
{
if (flag) {
#ifdef CONFIG_USB_HCI
int i;
for (i = 0; i < 8; i++) {
if (pxmitbuf->pxmit_urb[i]) {
/* usb_kill_urb(pxmitbuf->pxmit_urb[i]); */
usb_free_urb(pxmitbuf->pxmit_urb[i]);
}
}
#endif
}
if (free_sz > 0) {
#ifdef CONFIG_USE_USB_BUFFER_ALLOC_TX
struct dvobj_priv *pdvobjpriv = adapter_to_dvobj(padapter);
struct usb_device *pusbd = pdvobjpriv->pusbdev;
rtw_usb_buffer_free(pusbd, (size_t)free_sz, pxmitbuf->pallocated_buf, pxmitbuf->dma_transfer_addr);
pxmitbuf->pallocated_buf = NULL;
pxmitbuf->dma_transfer_addr = 0;
#else /* CONFIG_USE_USB_BUFFER_ALLOC_TX */
if (pxmitbuf->pallocated_buf)
rtw_mfree(pxmitbuf->pallocated_buf, free_sz);
#endif /* CONFIG_USE_USB_BUFFER_ALLOC_TX */
}
}
void dump_os_queue(void *sel, _adapter *padapter)
{
struct net_device *ndev = padapter->pnetdev;
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 35))
int i;
for (i = 0; i < 4; i++) {
RTW_PRINT_SEL(sel, "os_queue[%d]:%s\n"
, i, __netif_subqueue_stopped(ndev, i) ? "stopped" : "waked");
}
#else
RTW_PRINT_SEL(sel, "os_queue:%s\n"
, netif_queue_stopped(ndev) ? "stopped" : "waked");
#endif
}
#define WMM_XMIT_THRESHOLD (NR_XMITFRAME*2/5)
static inline bool rtw_os_need_wake_queue(_adapter *padapter, u16 os_qid)
{
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 35))
struct xmit_priv *pxmitpriv = &padapter->xmitpriv;
if (padapter->registrypriv.wifi_spec) {
if (pxmitpriv->hwxmits[os_qid].accnt < WMM_XMIT_THRESHOLD)
return _TRUE;
#ifdef DBG_CONFIG_ERROR_DETECT
#ifdef DBG_CONFIG_ERROR_RESET
} else if (rtw_hal_sreset_inprogress(padapter) == _TRUE) {
return _FALSE;
#endif/* #ifdef DBG_CONFIG_ERROR_RESET */
#endif/* #ifdef DBG_CONFIG_ERROR_DETECT */
} else {
#ifdef CONFIG_MCC_MODE
if (MCC_EN(padapter)) {
if (rtw_hal_check_mcc_status(padapter, MCC_STATUS_DOING_MCC)
&& MCC_STOP(padapter))
return _FALSE;
}
#endif /* CONFIG_MCC_MODE */
return _TRUE;
}
return _FALSE;
#else
#ifdef CONFIG_MCC_MODE
if (MCC_EN(padapter)) {
if (rtw_hal_check_mcc_status(padapter, MCC_STATUS_DOING_MCC)
&& MCC_STOP(padapter))
return _FALSE;
}
#endif /* CONFIG_MCC_MODE */
return _TRUE;
#endif
}
static inline bool rtw_os_need_stop_queue(_adapter *padapter, u16 os_qid)
{
struct xmit_priv *pxmitpriv = &padapter->xmitpriv;
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 35))
if (padapter->registrypriv.wifi_spec) {
/* No free space for Tx, tx_worker is too slow */
if (pxmitpriv->hwxmits[os_qid].accnt > WMM_XMIT_THRESHOLD)
return _TRUE;
} else {
if (pxmitpriv->free_xmitframe_cnt <= 4)
return _TRUE;
}
#else
if (pxmitpriv->free_xmitframe_cnt <= 4)
return _TRUE;
#endif
return _FALSE;
}
void rtw_os_pkt_complete(_adapter *padapter, _pkt *pkt)
{
rtw_skb_free(pkt);
}
void rtw_os_xmit_complete(_adapter *padapter, struct xmit_frame *pxframe)
{
if (pxframe->pkt)
rtw_os_pkt_complete(padapter, pxframe->pkt);
pxframe->pkt = NULL;
}
void rtw_os_xmit_schedule(_adapter *padapter)
{
#if defined(CONFIG_SDIO_HCI) || defined(CONFIG_GSPI_HCI)
_adapter *pri_adapter;
if (!padapter)
return;
pri_adapter = GET_PRIMARY_ADAPTER(padapter);
if (_rtw_queue_empty(&padapter->xmitpriv.pending_xmitbuf_queue) == _FALSE)
_rtw_up_sema(&pri_adapter->xmitpriv.xmit_sema);
#else
_irqL irqL;
struct xmit_priv *pxmitpriv;
if (!padapter)
return;
pxmitpriv = &padapter->xmitpriv;
_enter_critical_bh(&pxmitpriv->lock, &irqL);
if (rtw_txframes_pending(padapter))
tasklet_hi_schedule(&pxmitpriv->xmit_tasklet);
_exit_critical_bh(&pxmitpriv->lock, &irqL);
#if defined(CONFIG_PCI_HCI) && defined(CONFIG_XMIT_THREAD_MODE)
if (_rtw_queue_empty(&padapter->xmitpriv.pending_xmitbuf_queue) == _FALSE)
_rtw_up_sema(&padapter->xmitpriv.xmit_sema);
#endif
#endif
}
void rtw_os_check_wakup_queue(_adapter *adapter, u16 os_qid)
{
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 35))
if (rtw_os_need_wake_queue(adapter, os_qid)) {
if (DBG_DUMP_OS_QUEUE_CTL)
RTW_INFO(FUNC_ADPT_FMT": netif_wake_subqueue[%d]\n", FUNC_ADPT_ARG(adapter), os_qid);
netif_wake_subqueue(adapter->pnetdev, os_qid);
}
#else
if (rtw_os_need_wake_queue(adapter, 0)) {
if (DBG_DUMP_OS_QUEUE_CTL)
RTW_INFO(FUNC_ADPT_FMT": netif_wake_queue\n", FUNC_ADPT_ARG(adapter));
netif_wake_queue(adapter->pnetdev);
}
#endif
}
bool rtw_os_check_stop_queue(_adapter *adapter, u16 os_qid)
{
bool busy = _FALSE;
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 35))
if (rtw_os_need_stop_queue(adapter, os_qid)) {
if (DBG_DUMP_OS_QUEUE_CTL)
RTW_INFO(FUNC_ADPT_FMT": netif_stop_subqueue[%d]\n", FUNC_ADPT_ARG(adapter), os_qid);
netif_stop_subqueue(adapter->pnetdev, os_qid);
busy = _TRUE;
}
#else
if (rtw_os_need_stop_queue(adapter, 0)) {
if (DBG_DUMP_OS_QUEUE_CTL)
RTW_INFO(FUNC_ADPT_FMT": netif_stop_queue\n", FUNC_ADPT_ARG(adapter));
rtw_netif_stop_queue(adapter->pnetdev);
busy = _TRUE;
}
#endif
return busy;
}
void rtw_os_wake_queue_at_free_stainfo(_adapter *padapter, int *qcnt_freed)
{
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 35))
int i;
for (i = 0; i < 4; i++) {
if (qcnt_freed[i] == 0)
continue;
if (rtw_os_need_wake_queue(padapter, i)) {
if (DBG_DUMP_OS_QUEUE_CTL)
RTW_INFO(FUNC_ADPT_FMT": netif_wake_subqueue[%d]\n", FUNC_ADPT_ARG(padapter), i);
netif_wake_subqueue(padapter->pnetdev, i);
}
}
#else
if (qcnt_freed[0] || qcnt_freed[1] || qcnt_freed[2] || qcnt_freed[3]) {
if (rtw_os_need_wake_queue(padapter, 0)) {
if (DBG_DUMP_OS_QUEUE_CTL)
RTW_INFO(FUNC_ADPT_FMT": netif_wake_queue\n", FUNC_ADPT_ARG(padapter));
netif_wake_queue(padapter->pnetdev);
}
}
#endif
}
int _rtw_xmit_entry(_pkt *pkt, _nic_hdl pnetdev)
{
_adapter *padapter = (_adapter *)rtw_netdev_priv(pnetdev);
struct xmit_priv *pxmitpriv = &padapter->xmitpriv;
#ifdef CONFIG_TCP_CSUM_OFFLOAD_TX
struct sk_buff *skb = pkt;
struct sk_buff *segs, *nskb;
netdev_features_t features = padapter->pnetdev->features;
#endif
u16 os_qid = 0;
s32 res = 0;
if (padapter->registrypriv.mp_mode) {
RTW_INFO("MP_TX_DROP_OS_FRAME\n");
goto drop_packet;
}
DBG_COUNTER(padapter->tx_logs.os_tx);
if ((rtw_if_up(padapter) == _FALSE)
#ifdef CONFIG_LAYER2_ROAMING
&&(!padapter->mlmepriv.roam_network)
#endif
){
DBG_COUNTER(padapter->tx_logs.os_tx_err_up);
#ifdef DBG_TX_DROP_FRAME
RTW_INFO("DBG_TX_DROP_FRAME %s if_up fail\n", __FUNCTION__);
#endif
goto drop_packet;
}
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 35))
os_qid = skb_get_queue_mapping(pkt);
#endif
#ifdef CONFIG_TCP_CSUM_OFFLOAD_TX
if (skb_shinfo(skb)->gso_size) {
/* split a big(65k) skb into several small(1.5k) skbs */
features &= ~(NETIF_F_TSO | NETIF_F_TSO6);
segs = skb_gso_segment(skb, features);
if (IS_ERR(segs) || !segs)
goto drop_packet;
do {
nskb = segs;
segs = segs->next;
nskb->next = NULL;
rtw_mstat_update( MSTAT_TYPE_SKB, MSTAT_ALLOC_SUCCESS, nskb->truesize);
res = rtw_xmit(padapter, &nskb, os_qid);
if (res < 0) {
#ifdef DBG_TX_DROP_FRAME
RTW_INFO("DBG_TX_DROP_FRAME %s rtw_xmit fail\n", __FUNCTION__);
#endif
pxmitpriv->tx_drop++;
rtw_os_pkt_complete(padapter, nskb);
}
} while (segs);
rtw_os_pkt_complete(padapter, skb);
goto exit;
}
#endif
res = rtw_xmit(padapter, &pkt, os_qid);
if (res < 0) {
#ifdef DBG_TX_DROP_FRAME
RTW_INFO("DBG_TX_DROP_FRAME %s rtw_xmit fail\n", __FUNCTION__);
#endif
goto drop_packet;
}
goto exit;
drop_packet:
pxmitpriv->tx_drop++;
rtw_os_pkt_complete(padapter, pkt);
exit:
return 0;
}
#ifdef CONFIG_CUSTOMER_ALIBABA_GENERAL
int check_alibaba_meshpkt(struct sk_buff *skb)
{
u16 protocol;
if (skb)
return (htons(skb->protocol) == ETH_P_ALL);
return _FALSE;
}
s32 rtw_alibaba_mesh_xmit_entry(_pkt *pkt, struct net_device *ndev)
{
u16 frame_ctl;
_adapter *padapter = (_adapter *)rtw_netdev_priv(ndev);
struct pkt_file pktfile;
struct rtw_ieee80211_hdr *pwlanhdr;
struct pkt_attrib *pattrib;
struct xmit_frame *pmgntframe;
struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
struct xmit_priv *pxmitpriv = &(padapter->xmitpriv);
unsigned char *pframe;
struct sk_buff *skb = (struct sk_buff *)pkt;
int len = skb->len;
rtw_mstat_update(MSTAT_TYPE_SKB, MSTAT_ALLOC_SUCCESS, skb->truesize);
pmgntframe = alloc_mgtxmitframe(pxmitpriv);
if (pmgntframe == NULL) {
goto fail;
return -1;
}
pattrib = &pmgntframe->attrib;
update_mgntframe_attrib(padapter, pattrib);
_rtw_memset(pmgntframe->buf_addr, 0, WLANHDR_OFFSET + TXDESC_OFFSET);
pframe = (u8 *)(pmgntframe->buf_addr) + TXDESC_OFFSET;
pwlanhdr = (struct rtw_ieee80211_hdr *)pframe;
_rtw_open_pktfile(pkt, &pktfile);
_rtw_pktfile_read(&pktfile, pframe, len);
pattrib->type = pframe[0] & 0x0C;
pattrib->subtype = pframe[0] & 0xF0;
pattrib->raid = rtw_get_mgntframe_raid(padapter, WIRELESS_11G);
pattrib->rate = MGN_24M;
pattrib->pktlen = len;
SetSeqNum(pwlanhdr, pmlmeext->mgnt_seq);
pmlmeext->mgnt_seq++;
RTW_DBG_DUMP("rtw_alibaba_mesh_xmit_entry payload:", skb->data, len);
pattrib->last_txcmdsz = pattrib->pktlen;
dump_mgntframe(padapter, pmgntframe);
fail:
rtw_skb_free(skb);
return 0;
}
#endif
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 32))
netdev_tx_t rtw_xmit_entry(_pkt *pkt, _nic_hdl pnetdev)
#else
int rtw_xmit_entry(_pkt *pkt, _nic_hdl pnetdev)
#endif
{
_adapter *padapter = (_adapter *)rtw_netdev_priv(pnetdev);
struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
int ret = 0;
if (pkt) {
#ifdef CONFIG_CUSTOMER_ALIBABA_GENERAL
if (check_alibaba_meshpkt(pkt)) {
ret = rtw_alibaba_mesh_xmit_entry(pkt, pnetdev);
goto out;
}
#endif
if (check_fwstate(pmlmepriv, WIFI_MONITOR_STATE) == _TRUE) {
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 24))
rtw_monitor_xmit_entry((struct sk_buff *)pkt, pnetdev);
#endif
}
else {
rtw_mstat_update(MSTAT_TYPE_SKB, MSTAT_ALLOC_SUCCESS, pkt->truesize);
ret = _rtw_xmit_entry(pkt, pnetdev);
}
}
#ifdef CONFIG_CUSTOMER_ALIBABA_GENERAL
out:
#endif
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 32))
return (ret == 0) ? NETDEV_TX_OK : NETDEV_TX_BUSY;
#else
return ret;
#endif
}

3473
os_dep/osdep_service.c Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,22 @@
/******************************************************************************
*
* Copyright(c) 2013 - 2017 Realtek Corporation.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of version 2 of the GNU General Public License as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
*****************************************************************************/
#error "You have defined CONFIG_CUSTOMIZED_COUNTRY_CHPLAN_MAP to use a customized map of your own instead of the default one"
#error "Before removing these error notifications, please make sure regulatory certification requirements of your target markets"
static const struct country_chplan CUSTOMIZED_country_chplan_map[] = {
COUNTRY_CHPLAN_ENT("TW", 0x76, 1), /* Taiwan */
};

View File

@ -0,0 +1,86 @@
/******************************************************************************
*
* Copyright(c) 2013 - 2017 Realtek Corporation.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of version 2 of the GNU General Public License as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
*****************************************************************************/
/*
* Description:
* This file can be applied to following platforms:
* CONFIG_PLATFORM_ARM_SUN50IW1P1
*/
#include <drv_types.h>
#ifdef CONFIG_GPIO_WAKEUP
#include <linux/gpio.h>
#endif
#ifdef CONFIG_MMC
#if defined(CONFIG_PLATFORM_ARM_SUN50IW1P1)
extern void sunxi_mmc_rescan_card(unsigned ids);
extern void sunxi_wlan_set_power(int on);
extern int sunxi_wlan_get_bus_index(void);
extern int sunxi_wlan_get_oob_irq(void);
extern int sunxi_wlan_get_oob_irq_flags(void);
#endif
#ifdef CONFIG_GPIO_WAKEUP
extern unsigned int oob_irq;
#endif
#endif /* CONFIG_MMC */
/*
* Return:
* 0: power on successfully
* others: power on failed
*/
int platform_wifi_power_on(void)
{
int ret = 0;
#ifdef CONFIG_MMC
{
#if defined(CONFIG_PLATFORM_ARM_SUN50IW1P1)
int wlan_bus_index = sunxi_wlan_get_bus_index();
if (wlan_bus_index < 0)
return wlan_bus_index;
sunxi_wlan_set_power(1);
mdelay(100);
sunxi_mmc_rescan_card(wlan_bus_index);
#endif
RTW_INFO("%s: power up, rescan card.\n", __FUNCTION__);
#ifdef CONFIG_GPIO_WAKEUP
#if defined(CONFIG_PLATFORM_ARM_SUN50IW1P1)
oob_irq = sunxi_wlan_get_oob_irq();
#endif
#endif /* CONFIG_GPIO_WAKEUP */
}
#endif /* CONFIG_MMC */
return ret;
}
void platform_wifi_power_off(void)
{
#ifdef CONFIG_MMC
#if defined(CONFIG_PLATFORM_ARM_SUN50IW1P1)
int wlan_bus_index = sunxi_wlan_get_bus_index();
if (wlan_bus_index < 0)
return;
sunxi_mmc_rescan_card(wlan_bus_index);
mdelay(100);
sunxi_wlan_set_power(0);
#endif
RTW_INFO("%s: remove card, power off.\n", __FUNCTION__);
#endif /* CONFIG_MMC */
}

View File

@ -0,0 +1,130 @@
/******************************************************************************
*
* Copyright(c) 2013 - 2017 Realtek Corporation.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of version 2 of the GNU General Public License as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
*****************************************************************************/
/*
* Description:
* This file can be applied to following platforms:
* CONFIG_PLATFORM_ARM_SUN6I
* CONFIG_PLATFORM_ARM_SUN7I
* CONFIG_PLATFORM_ARM_SUN8I
*/
#include <drv_types.h>
#include <mach/sys_config.h>
#ifdef CONFIG_GPIO_WAKEUP
#include <linux/gpio.h>
#endif
#ifdef CONFIG_MMC
static int sdc_id = -1;
static signed int gpio_eint_wlan = -1;
static u32 eint_wlan_handle = 0;
#if defined(CONFIG_PLATFORM_ARM_SUN6I) || defined(CONFIG_PLATFORM_ARM_SUN7I)
extern void sw_mci_rescan_card(unsigned id, unsigned insert);
#elif defined(CONFIG_PLATFORM_ARM_SUN8I)
extern void sunxi_mci_rescan_card(unsigned id, unsigned insert);
#endif
#ifdef CONFIG_PLATFORM_ARM_SUN8I_W5P1
extern int get_rf_mod_type(void);
#else
extern int wifi_pm_get_mod_type(void);
#endif
extern void wifi_pm_power(int on);
#ifdef CONFIG_GPIO_WAKEUP
extern unsigned int oob_irq;
#endif
#endif /* CONFIG_MMC */
/*
* Return:
* 0: power on successfully
* others: power on failed
*/
int platform_wifi_power_on(void)
{
int ret = 0;
#ifdef CONFIG_MMC
{
script_item_u val;
script_item_value_type_e type;
#ifdef CONFIG_PLATFORM_ARM_SUN8I_W5P1
unsigned int mod_sel = get_rf_mod_type();
#else
unsigned int mod_sel = wifi_pm_get_mod_type();
#endif
type = script_get_item("wifi_para", "wifi_sdc_id", &val);
if (SCIRPT_ITEM_VALUE_TYPE_INT != type) {
RTW_INFO("get wifi_sdc_id failed\n");
ret = -1;
} else {
sdc_id = val.val;
RTW_INFO("----- %s sdc_id: %d, mod_sel: %d\n", __FUNCTION__, sdc_id, mod_sel);
#if defined(CONFIG_PLATFORM_ARM_SUN6I) || defined(CONFIG_PLATFORM_ARM_SUN7I)
sw_mci_rescan_card(sdc_id, 1);
#elif defined(CONFIG_PLATFORM_ARM_SUN8I)
sunxi_mci_rescan_card(sdc_id, 1);
#endif
mdelay(100);
wifi_pm_power(1);
RTW_INFO("%s: power up, rescan card.\n", __FUNCTION__);
}
#ifdef CONFIG_GPIO_WAKEUP
#ifdef CONFIG_PLATFORM_ARM_SUN8I_W5P1
type = script_get_item("wifi_para", "wl_host_wake", &val);
#else
#ifdef CONFIG_RTL8723B
type = script_get_item("wifi_para", "rtl8723bs_wl_host_wake", &val);
#endif
#ifdef CONFIG_RTL8188E
type = script_get_item("wifi_para", "rtl8189es_host_wake", &val);
#endif
#endif /* CONFIG_PLATFORM_ARM_SUN8I_W5P1 */
if (SCIRPT_ITEM_VALUE_TYPE_PIO != type) {
RTW_INFO("No definition of wake up host PIN\n");
ret = -1;
} else {
gpio_eint_wlan = val.gpio.gpio;
#ifdef CONFIG_PLATFORM_ARM_SUN8I
oob_irq = gpio_to_irq(gpio_eint_wlan);
#endif
}
#endif /* CONFIG_GPIO_WAKEUP */
}
#endif /* CONFIG_MMC */
return ret;
}
void platform_wifi_power_off(void)
{
#ifdef CONFIG_MMC
#if defined(CONFIG_PLATFORM_ARM_SUN6I) || defined(CONFIG_PLATFORM_ARM_SUN7I)
sw_mci_rescan_card(sdc_id, 0);
#elif defined(CONFIG_PLATFORM_ARM_SUN8I)
sunxi_mci_rescan_card(sdc_id, 0);
#endif
mdelay(100);
wifi_pm_power(0);
RTW_INFO("%s: remove card, power off.\n", __FUNCTION__);
#endif /* CONFIG_MMC */
}

View File

@ -0,0 +1,90 @@
/******************************************************************************
*
* Copyright(c) 2013 - 2017 Realtek Corporation.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of version 2 of the GNU General Public License as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
*****************************************************************************/
#include <drv_types.h>
#ifdef CONFIG_MMC_SUNXI_POWER_CONTROL
#ifdef CONFIG_WITS_EVB_V13
#define SDIOID 0
#else /* !CONFIG_WITS_EVB_V13 */
#define SDIOID (CONFIG_CHIP_ID == 1123 ? 3 : 1)
#endif /* !CONFIG_WITS_EVB_V13 */
#define SUNXI_SDIO_WIFI_NUM_RTL8189ES 10
extern void sunximmc_rescan_card(unsigned id, unsigned insert);
extern int mmc_pm_get_mod_type(void);
extern int mmc_pm_gpio_ctrl(char *name, int level);
/*
* rtl8189es_shdn = port:PH09<1><default><default><0>
* rtl8189es_wakeup = port:PH10<1><default><default><1>
* rtl8189es_vdd_en = port:PH11<1><default><default><0>
* rtl8189es_vcc_en = port:PH12<1><default><default><0>
*/
int rtl8189es_sdio_powerup(void)
{
mmc_pm_gpio_ctrl("rtl8189es_vdd_en", 1);
udelay(100);
mmc_pm_gpio_ctrl("rtl8189es_vcc_en", 1);
udelay(50);
mmc_pm_gpio_ctrl("rtl8189es_shdn", 1);
return 0;
}
int rtl8189es_sdio_poweroff(void)
{
mmc_pm_gpio_ctrl("rtl8189es_shdn", 0);
mmc_pm_gpio_ctrl("rtl8189es_vcc_en", 0);
mmc_pm_gpio_ctrl("rtl8189es_vdd_en", 0);
return 0;
}
#endif /* CONFIG_MMC_SUNXI_POWER_CONTROL */
/*
* Return:
* 0: power on successfully
* others: power on failed
*/
int platform_wifi_power_on(void)
{
int ret = 0;
#ifdef CONFIG_MMC_SUNXI_POWER_CONTROL
unsigned int mod_sel = mmc_pm_get_mod_type();
#endif /* CONFIG_MMC_SUNXI_POWER_CONTROL */
#ifdef CONFIG_MMC_SUNXI_POWER_CONTROL
if (mod_sel == SUNXI_SDIO_WIFI_NUM_RTL8189ES) {
rtl8189es_sdio_powerup();
sunximmc_rescan_card(SDIOID, 1);
printk("[rtl8189es] %s: power up, rescan card.\n", __FUNCTION__);
} else {
ret = -1;
printk("[rtl8189es] %s: mod_sel = %d is incorrect.\n", __FUNCTION__, mod_sel);
}
#endif /* CONFIG_MMC_SUNXI_POWER_CONTROL */
return ret;
}
void platform_wifi_power_off(void)
{
#ifdef CONFIG_MMC_SUNXI_POWER_CONTROL
sunximmc_rescan_card(SDIOID, 0);
#ifdef CONFIG_RTL8188E
rtl8189es_sdio_poweroff();
printk("[rtl8189es] %s: remove card, power off.\n", __FUNCTION__);
#endif /* CONFIG_RTL8188E */
#endif /* CONFIG_MMC_SUNXI_POWER_CONTROL */
}

View File

@ -0,0 +1,136 @@
/******************************************************************************
*
* Copyright(c) 2013 - 2017 Realtek Corporation.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of version 2 of the GNU General Public License as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
*****************************************************************************/
/*
* Description:
* This file can be applied to following platforms:
* CONFIG_PLATFORM_ARM_SUNXI Series platform
*
*/
#include <drv_types.h>
#include <mach/sys_config.h>
#ifdef CONFIG_PLATFORM_ARM_SUNxI
extern int sw_usb_disable_hcd(__u32 usbc_no);
extern int sw_usb_enable_hcd(__u32 usbc_no);
static int usb_wifi_host = 2;
#endif
#if defined(CONFIG_PLATFORM_ARM_SUN6I) || defined(CONFIG_PLATFORM_ARM_SUN7I)
extern int sw_usb_disable_hcd(__u32 usbc_no);
extern int sw_usb_enable_hcd(__u32 usbc_no);
extern void wifi_pm_power(int on);
static script_item_u item;
#endif
#ifdef CONFIG_PLATFORM_ARM_SUN8I
extern int sunxi_usb_disable_hcd(__u32 usbc_no);
extern int sunxi_usb_enable_hcd(__u32 usbc_no);
extern void wifi_pm_power(int on);
static script_item_u item;
#endif
int platform_wifi_power_on(void)
{
int ret = 0;
#ifdef CONFIG_PLATFORM_ARM_SUNxI
#ifndef CONFIG_RTL8723A
{
/* ----------get usb_wifi_usbc_num------------- */
ret = script_parser_fetch("usb_wifi_para", "usb_wifi_usbc_num", (int *)&usb_wifi_host, 64);
if (ret != 0) {
RTW_INFO("ERR: script_parser_fetch usb_wifi_usbc_num failed\n");
ret = -ENOMEM;
goto exit;
}
RTW_INFO("sw_usb_enable_hcd: usbc_num = %d\n", usb_wifi_host);
sw_usb_enable_hcd(usb_wifi_host);
}
#endif /* CONFIG_RTL8723A */
#endif /* CONFIG_PLATFORM_ARM_SUNxI */
#if defined(CONFIG_PLATFORM_ARM_SUN6I) || defined(CONFIG_PLATFORM_ARM_SUN7I)
{
script_item_value_type_e type;
type = script_get_item("wifi_para", "wifi_usbc_id", &item);
if (SCIRPT_ITEM_VALUE_TYPE_INT != type) {
printk("ERR: script_get_item wifi_usbc_id failed\n");
ret = -ENOMEM;
goto exit;
}
printk("sw_usb_enable_hcd: usbc_num = %d\n", item.val);
wifi_pm_power(1);
mdelay(10);
#if !(defined(CONFIG_RTL8723A)) && !(defined(CONFIG_RTL8723B))
sw_usb_enable_hcd(item.val);
#endif
}
#endif /* defined(CONFIG_PLATFORM_ARM_SUN6I) || defined(CONFIG_PLATFORM_ARM_SUN7I) */
#if defined(CONFIG_PLATFORM_ARM_SUN8I)
{
script_item_value_type_e type;
type = script_get_item("wifi_para", "wifi_usbc_id", &item);
if (SCIRPT_ITEM_VALUE_TYPE_INT != type) {
printk("ERR: script_get_item wifi_usbc_id failed\n");
ret = -ENOMEM;
goto exit;
}
printk("sw_usb_enable_hcd: usbc_num = %d\n", item.val);
wifi_pm_power(1);
mdelay(10);
#if !(defined(CONFIG_RTL8723A)) && !(defined(CONFIG_RTL8723B))
sunxi_usb_enable_hcd(item.val);
#endif
}
#endif /* CONFIG_PLATFORM_ARM_SUN8I */
exit:
return ret;
}
void platform_wifi_power_off(void)
{
#ifdef CONFIG_PLATFORM_ARM_SUNxI
#ifndef CONFIG_RTL8723A
RTW_INFO("sw_usb_disable_hcd: usbc_num = %d\n", usb_wifi_host);
sw_usb_disable_hcd(usb_wifi_host);
#endif /* ifndef CONFIG_RTL8723A */
#endif /* CONFIG_PLATFORM_ARM_SUNxI */
#if defined(CONFIG_PLATFORM_ARM_SUN6I) || defined(CONFIG_PLATFORM_ARM_SUN7I)
#if !(defined(CONFIG_RTL8723A)) && !(defined(CONFIG_RTL8723B))
sw_usb_disable_hcd(item.val);
#endif
wifi_pm_power(0);
#endif /* defined(CONFIG_PLATFORM_ARM_SUN6I) || defined(CONFIG_PLATFORM_ARM_SUN7I) */
#if defined(CONFIG_PLATFORM_ARM_SUN8I)
#if !(defined(CONFIG_RTL8723A)) && !(defined(CONFIG_RTL8723B))
sunxi_usb_disable_hcd(item.val);
#endif
wifi_pm_power(0);
#endif /* defined(CONFIG_PLATFORM_ARM_SUN8I) */
}

View File

@ -0,0 +1,46 @@
/******************************************************************************
*
* Copyright(c) 2013 - 2017 Realtek Corporation.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of version 2 of the GNU General Public License as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
*****************************************************************************/
#include <drv_types.h>
#include <mach/wmt_iomux.h>
#include <linux/gpio.h>
extern void wmt_detect_sdio2(void);
extern void force_remove_sdio2(void);
int platform_wifi_power_on(void)
{
int err = 0;
err = gpio_request(WMT_PIN_GP62_SUSGPIO1, "wifi_chip_en");
if (err < 0) {
printk("request gpio for rtl8188eu failed!\n");
return err;
}
gpio_direction_output(WMT_PIN_GP62_SUSGPIO1, 0);/* pull sus_gpio1 to 0 to open vcc_wifi. */
printk("power on rtl8189.\n");
msleep(500);
wmt_detect_sdio2();
printk("[rtl8189es] %s: new card, power on.\n", __FUNCTION__);
return err;
}
void platform_wifi_power_off(void)
{
force_remove_sdio2();
gpio_direction_output(WMT_PIN_GP62_SUSGPIO1, 1);/* pull sus_gpio1 to 1 to close vcc_wifi. */
printk("power off rtl8189.\n");
gpio_free(WMT_PIN_GP62_SUSGPIO1);
printk("[rtl8189es] %s: remove card, power off.\n", __FUNCTION__);
}

View File

@ -0,0 +1,30 @@
/******************************************************************************
*
* Copyright(c) 2013 - 2017 Realtek Corporation.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of version 2 of the GNU General Public License as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
*****************************************************************************/
#include <drv_types.h>
int platform_wifi_power_on(void)
{
int ret = 0;
u32 tmp;
tmp = readl((volatile unsigned int *)0xb801a608);
tmp &= 0xffffff00;
tmp |= 0x55;
writel(tmp, (volatile unsigned int *)0xb801a608); /* write dummy register for 1055 */
return ret;
}
void platform_wifi_power_off(void)
{
}

View File

@ -0,0 +1,54 @@
/******************************************************************************
*
* Copyright(c) 2016 - 2018 Realtek Corporation.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of version 2 of the GNU General Public License as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
*****************************************************************************/
#include <linux/printk.h> /* pr_info(() */
#include <linux/delay.h> /* msleep() */
#include "platform_aml_s905_sdio.h" /* sdio_reinit() and etc */
/*
* Return:
* 0: power on successfully
* others: power on failed
*/
int platform_wifi_power_on(void)
{
int ret = 0;
#if (LINUX_VERSION_CODE < KERNEL_VERSION(3, 14, 0))
ret = wifi_setup_dt();
if (ret) {
pr_err("%s: setup dt failed!!(%d)\n", __func__, ret);
return -1;
}
#endif /* kernel < 3.14.0 */
#if 0 /* Seems redundancy? Already done before insert driver */
pr_info("######%s:\n", __func__);
extern_wifi_set_enable(0);
msleep(500);
extern_wifi_set_enable(1);
msleep(500);
sdio_reinit();
#endif
return ret;
}
void platform_wifi_power_off(void)
{
#if (LINUX_VERSION_CODE < KERNEL_VERSION(3, 14, 0))
wifi_teardown_dt();
#endif /* kernel < 3.14.0 */
}

View File

@ -0,0 +1,28 @@
/******************************************************************************
*
* Copyright(c) 2016 - 2018 Realtek Corporation.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of version 2 of the GNU General Public License as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
*****************************************************************************/
#ifndef __PLATFORM_AML_S905_SDIO_H__
#define __PLATFORM_AML_S905_SDIO_H__
#include <linux/version.h> /* Linux vresion */
extern void sdio_reinit(void);
extern void extern_wifi_set_enable(int is_on);
#if (LINUX_VERSION_CODE < KERNEL_VERSION(3, 14, 0))
extern void wifi_teardown_dt(void);
extern int wifi_setup_dt(void);
#endif /* kernel < 3.14.0 */
#endif /* __PLATFORM_AML_S905_SDIO_H__ */

View File

@ -0,0 +1,53 @@
/******************************************************************************
*
* Copyright(c) 2013 - 2017 Realtek Corporation.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of version 2 of the GNU General Public License as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
*****************************************************************************/
/*
* Description:
* This file can be applied to following platforms:
* CONFIG_PLATFORM_ACTIONS_ATM703X
*/
#include <drv_types.h>
#ifdef CONFIG_PLATFORM_ACTIONS_ATM705X
extern int acts_wifi_init(void);
extern void acts_wifi_cleanup(void);
#endif
/*
* Return:
* 0: power on successfully
* others: power on failed
*/
int platform_wifi_power_on(void)
{
int ret = 0;
#ifdef CONFIG_PLATFORM_ACTIONS_ATM705X
ret = acts_wifi_init();
if (unlikely(ret < 0)) {
pr_err("%s Failed to register the power control driver.\n", __FUNCTION__);
goto exit;
}
#endif
exit:
return ret;
}
void platform_wifi_power_off(void)
{
#ifdef CONFIG_PLATFORM_ACTIONS_ATM705X
acts_wifi_cleanup();
#endif
}

View File

@ -0,0 +1,110 @@
/******************************************************************************
*
* Copyright(c) 2017 - 2018 Realtek Corporation.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of version 2 of the GNU General Public License as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
*****************************************************************************/
#include <linux/delay.h> /* mdelay() */
#include <mach/hardware.h> /* __io_address(), readl(), writel() */
#include "platform_hisilicon_hi3798_sdio.h" /* HI_S32() and etc. */
typedef enum hi_GPIO_DIR_E {
HI_DIR_OUT = 0,
HI_DIR_IN = 1,
} HI_GPIO_DIR_E;
#define RTL_REG_ON_GPIO (4*8 + 3)
#define REG_BASE_CTRL __io_address(0xf8a20008)
int gpio_wlan_reg_on = RTL_REG_ON_GPIO;
#if 0
module_param(gpio_wlan_reg_on, uint, 0644);
MODULE_PARM_DESC(gpio_wlan_reg_on, "wlan reg_on gpio num (default:gpio4_3)");
#endif
static int hi_gpio_set_value(u32 gpio, u32 value)
{
HI_S32 s32Status;
s32Status = HI_DRV_GPIO_SetDirBit(gpio, HI_DIR_OUT);
if (s32Status != HI_SUCCESS) {
pr_err("gpio(%d) HI_DRV_GPIO_SetDirBit HI_DIR_OUT failed\n",
gpio);
return -1;
}
s32Status = HI_DRV_GPIO_WriteBit(gpio, value);
if (s32Status != HI_SUCCESS) {
pr_err("gpio(%d) HI_DRV_GPIO_WriteBit value(%d) failed\n",
gpio, value);
return -1;
}
return 0;
}
static int hisi_wlan_set_carddetect(bool present)
{
u32 regval;
u32 mask;
#ifndef CONFIG_HISI_SDIO_ID
return;
#endif
pr_info("SDIO ID=%d\n", CONFIG_HISI_SDIO_ID);
#if (CONFIG_HISI_SDIO_ID == 1)
mask = 1;
#elif (CONFIG_HISI_SDIO_ID == 0)
mask = 2;
#endif
regval = readl(REG_BASE_CTRL);
if (present) {
pr_info("====== Card detection to detect SDIO card! ======\n");
/* set card_detect low to detect card */
regval |= mask;
} else {
pr_info("====== Card detection to remove SDIO card! ======\n");
/* set card_detect high to remove card */
regval &= ~(mask);
}
writel(regval, REG_BASE_CTRL);
return 0;
}
/*
* Return:
* 0: power on successfully
* others: power on failed
*/
int platform_wifi_power_on(void)
{
int ret = 0;
hi_gpio_set_value(gpio_wlan_reg_on, 1);
mdelay(100);
hisi_wlan_set_carddetect(1);
mdelay(2000);
pr_info("======== set_carddetect delay 2s! ========\n");
return ret;
}
void platform_wifi_power_off(void)
{
hisi_wlan_set_carddetect(0);
mdelay(100);
hi_gpio_set_value(gpio_wlan_reg_on, 0);
}

View File

@ -0,0 +1,28 @@
/******************************************************************************
*
* Copyright(c) 2017 - 2018 Realtek Corporation.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of version 2 of the GNU General Public License as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
*****************************************************************************/
#ifndef __PLATFORM_HISILICON_HI3798_SDIO_H__
#define __PLATFORM_HISILICON_HI3798_SDIO_H__
typedef unsigned int HI_U32;
typedef int HI_S32;
#define HI_SUCCESS 0
#define HI_FAILURE (-1)
extern HI_S32 HI_DRV_GPIO_SetDirBit(HI_U32 u32GpioNo, HI_U32 u32DirBit);
extern HI_S32 HI_DRV_GPIO_WriteBit(HI_U32 u32GpioNo, HI_U32 u32BitValue);
#endif /* __PLATFORM_HISILICON_HI3798_SDIO_H__ */

32
platform/platform_ops.c Normal file
View File

@ -0,0 +1,32 @@
/******************************************************************************
*
* Copyright(c) 2013 - 2017 Realtek Corporation.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of version 2 of the GNU General Public License as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
*****************************************************************************/
#ifndef CONFIG_PLATFORM_OPS
/*
* Return:
* 0: power on successfully
* others: power on failed
*/
int platform_wifi_power_on(void)
{
int ret = 0;
return ret;
}
void platform_wifi_power_off(void)
{
}
#endif /* !CONFIG_PLATFORM_OPS */

26
platform/platform_ops.h Normal file
View File

@ -0,0 +1,26 @@
/******************************************************************************
*
* Copyright(c) 2013 - 2017 Realtek Corporation.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of version 2 of the GNU General Public License as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
*****************************************************************************/
#ifndef __PLATFORM_OPS_H__
#define __PLATFORM_OPS_H__
/*
* Return:
* 0: power on successfully
* others: power on failed
*/
int platform_wifi_power_on(void);
void platform_wifi_power_off(void);
#endif /* __PLATFORM_OPS_H__ */

View File

@ -0,0 +1,84 @@
/******************************************************************************
*
* Copyright(c) 2013 - 2017 Realtek Corporation.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of version 2 of the GNU General Public License as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
*****************************************************************************/
#include <drv_types.h>
extern void sdhci_bus_scan(void);
#ifndef ANDROID_2X
extern int sdhci_device_attached(void);
#endif
/*
* Return:
* 0: power on successfully
* others: power on failed
*/
int platform_wifi_power_on(void)
{
int ret = 0;
#ifdef CONFIG_RTL8188E
rtw_wifi_gpio_wlan_ctrl(WLAN_POWER_ON);
#endif /* CONFIG_RTL8188E */
/* Pull up pwd pin, make wifi leave power down mode. */
rtw_wifi_gpio_init();
rtw_wifi_gpio_wlan_ctrl(WLAN_PWDN_ON);
#if (MP_DRIVER == 1) && (defined(CONFIG_RTL8723A) || defined(CONFIG_RTL8723B))
/* Pull up BT reset pin. */
rtw_wifi_gpio_wlan_ctrl(WLAN_BT_PWDN_ON);
#endif
rtw_mdelay_os(5);
sdhci_bus_scan();
#ifdef CONFIG_RTL8723B
/* YJ,test,130305 */
rtw_mdelay_os(1000);
#endif
#ifdef ANDROID_2X
rtw_mdelay_os(200);
#else /* !ANDROID_2X */
if (1) {
int i = 0;
for (i = 0; i <= 50; i++) {
msleep(10);
if (sdhci_device_attached())
break;
printk("%s delay times:%d\n", __func__, i);
}
}
#endif /* !ANDROID_2X */
return ret;
}
void platform_wifi_power_off(void)
{
/* Pull down pwd pin, make wifi enter power down mode. */
rtw_wifi_gpio_wlan_ctrl(WLAN_PWDN_OFF);
rtw_mdelay_os(5);
rtw_wifi_gpio_deinit();
#ifdef CONFIG_RTL8188E
rtw_wifi_gpio_wlan_ctrl(WLAN_POWER_OFF);
#endif /* CONFIG_RTL8188E */
#ifdef CONFIG_WOWLAN
if (mmc_host)
mmc_host->pm_flags &= ~MMC_PM_KEEP_POWER;
#endif /* CONFIG_WOWLAN */
}

View File

@ -0,0 +1,53 @@
/******************************************************************************
*
* Copyright(c) 2016 - 2018 Realtek Corporation.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of version 2 of the GNU General Public License as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
*****************************************************************************/
#include <linux/printk.h> /* pr_info(() */
#include <linux/delay.h> /* msleep() */
#include "platform_zte_zx296716_sdio.h" /* sdio_reinit() and etc */
/*
* Return:
* 0: power on successfully
* others: power on failed
*/
int platform_wifi_power_on(void)
{
int ret = 0;
pr_info("######%s: disable--1--\n", __func__);
extern_wifi_set_enable(0);
/*msleep(500);*/ /* add in function:extern_wifi_set_enable */
pr_info("######%s: enable--2---\n", __func__);
extern_wifi_set_enable(1);
/*msleep(500);*/
sdio_reinit();
return ret;
}
void platform_wifi_power_off(void)
{
int card_val;
pr_info("######%s:\n", __func__);
#ifdef CONFIG_A16T03_BOARD
card_val = sdio_host_is_null();
if (card_val)
remove_card();
#endif /* CONFIG_A16T03_BOARD */
extern_wifi_set_enable(0);
/*msleep(500);*/
}

View File

@ -0,0 +1,25 @@
/******************************************************************************
*
* Copyright(c) 2016 - 2018 Realtek Corporation.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of version 2 of the GNU General Public License as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
*****************************************************************************/
#ifndef __PLATFORM_ZTE_ZX296716_SDIO_H__
#define __PLATFORM_ZTE_ZX296716_SDIO_H__
extern void sdio_reinit(void);
extern void extern_wifi_set_enable(int val);
#ifdef CONFIG_A16T03_BOARD
extern int sdio_host_is_null(void);
extern void remove_card(void);
#endif /* CONFIG_A16T03_BOARD */
#endif /* __PLATFORM_ZTE_ZX296716_SDIO_H__ */