2018-09-19 11:41:50

by Ajay Singh

[permalink] [raw]
Subject: [PATCH 00/29] staging: wilc1000: avoid static variables and cleanup changes

This patch series contains changes to avoid the use of static variables.
Cleanup changes to fix some checkpatch issues and return void for function
if their return value is not used.
Also deleted 'wilc_debugfs.c' file as it's not used.

Ajay Singh (29):
staging: wilc1000: change return type to 'void' for
wilc_frame_register()
staging: wilc1000: change return type to 'void' for
wilc_wlan_set_bssid()
staging: wilc1000: change return type to 'void' for lock init & deinit
functions
staging: wilc1000: change return type to 'void' for
wilc_deinit_host_int()
staging: wilc1000: change return type to 'void' for
wilc_wfi_deinit_mon_interface()
staging: wilc1000: use 'void' return type for
host_int_get_assoc_res_info()
staging: wilc1000: use 'void' return for wilc_wlan_txq_add_to_head()
staging: wilc1000: change return type to 'void' tcp ack filter
functions
staging: wilc1000: use 'void' return for
wilc_wlan_txq_filter_dup_tcp_ack()
staging: wilc1000: change return type to 'void' for
wilc_wlan_cfg_indicate_rx()
staging: wilc1000: refactor wilc_wlan_parse_info_frame() function
staging: wilc1000: set default value of cfg response type in
wilc_wlan_cfg_indicate_rx()
staging: wilc1000: changes 'val' type to u8 in wilc_cfg_byte struct
staging: wilc1000: remove unused wid type values
staging: wilc1000: remove unused wid from cfg struct
staging: wilc1000: refactor code to remove 'mac_status' from
'wilc_mac_cfg' struct
staging: wilc1000: refactor code to avoid static variables for config
parameters
staging: wilc1000: rename 'wilc_mac_cfg' struct to 'wilc_cfg_str_vals'
staging: wilc1000: avoid the use of 'hif_driver_comp' completion
variable
staging: wilc1000: remove use of unnecessary 'wilc_connected_ssid'
variable
staging: wilc1000: avoid use of 'g_sdio' static variable
staging: wilc1000: avoid use of 'g_spi' static variable
staging: wilc1000: remove unnecessary memset in sdio_init() &
wilc_spi_init()
staging: wilc1000: remove p2p related static variables to wilc_vif
struct
staging: wilc1000: remove wilc_debugfs.c file as its not used
staging: wilc1000: remove unnecessary option used with ccflags-y in
Makefile
staging: wilc1000: use usleep_range() in place of udelay()
staging: wilc1000: avoid spaces preferred around checkpatch issue
staging: wilc1000: return exact error of register_netdev() from
wilc_netdev_init()

drivers/staging/wilc1000/Makefile | 5 +-
drivers/staging/wilc1000/host_interface.c | 64 ++---
drivers/staging/wilc1000/host_interface.h | 6 +-
drivers/staging/wilc1000/linux_mon.c | 3 +-
drivers/staging/wilc1000/linux_wlan.c | 40 +--
drivers/staging/wilc1000/wilc_debugfs.c | 115 ---------
drivers/staging/wilc1000/wilc_sdio.c | 56 +++--
drivers/staging/wilc1000/wilc_spi.c | 57 +++--
drivers/staging/wilc1000/wilc_wfi_cfgoperations.c | 90 +++----
drivers/staging/wilc1000/wilc_wfi_cfgoperations.h | 4 +-
drivers/staging/wilc1000/wilc_wfi_netdevice.h | 14 +-
drivers/staging/wilc1000/wilc_wlan.c | 44 ++--
drivers/staging/wilc1000/wilc_wlan.h | 3 +-
drivers/staging/wilc1000/wilc_wlan_cfg.c | 294 +++++++++-------------
drivers/staging/wilc1000/wilc_wlan_cfg.h | 26 +-
drivers/staging/wilc1000/wilc_wlan_if.h | 4 -
16 files changed, 325 insertions(+), 500 deletions(-)
delete mode 100644 drivers/staging/wilc1000/wilc_debugfs.c

--
2.7.4


2018-09-19 11:42:42

by Ajay Singh

[permalink] [raw]
Subject: [PATCH 15/29] staging: wilc1000: remove unused wid from cfg struct

Cleanup patch to remove the unused element stored in cfg struct.
Removed those wid from the cfg variables whose value is not
fetched(GET_CFG) from the code. In case the wid is only set to the
firmware then there is need to store them as part of cfg variables, so
removed the unused code.

Signed-off-by: Ajay Singh <[email protected]>
---
drivers/staging/wilc1000/wilc_wlan_cfg.c | 107 -------------------------------
1 file changed, 107 deletions(-)

diff --git a/drivers/staging/wilc1000/wilc_wlan_cfg.c b/drivers/staging/wilc1000/wilc_wlan_cfg.c
index 2c463a3..541251b 100644
--- a/drivers/staging/wilc1000/wilc_wlan_cfg.c
+++ b/drivers/staging/wilc1000/wilc_wlan_cfg.c
@@ -20,131 +20,36 @@ enum cfg_cmd_type {
struct wilc_mac_cfg {
int mac_status;
u8 mac_address[7];
- u8 ip_address[5];
- u8 bssid[7];
- u8 ssid[34];
u8 firmware_version[129];
- u8 supp_rate[24];
- u8 wep_key[28];
- u8 i_psk[66];
- u8 hw_product_version[33];
- u8 phyversion[17];
- u8 supp_username[21];
- u8 supp_password[64];
- u8 assoc_req[256];
u8 assoc_rsp[256];
- u8 firmware_info[8];
- u8 scan_result[256];
- u8 scan_result1[256];
};

static struct wilc_mac_cfg g_mac;

static struct wilc_cfg_byte g_cfg_byte[] = {
- {WID_BSS_TYPE, 0},
- {WID_CURRENT_TX_RATE, 0},
- {WID_CURRENT_CHANNEL, 0},
- {WID_PREAMBLE, 0},
- {WID_11G_OPERATING_MODE, 0},
{WID_STATUS, 0},
- {WID_SCAN_TYPE, 0},
- {WID_KEY_ID, 0},
- {WID_QOS_ENABLE, 0},
- {WID_POWER_MANAGEMENT, 0},
- {WID_11I_MODE, 0},
- {WID_AUTH_TYPE, 0},
- {WID_SITE_SURVEY, 0},
- {WID_LISTEN_INTERVAL, 0},
- {WID_DTIM_PERIOD, 0},
- {WID_ACK_POLICY, 0},
- {WID_BCAST_SSID, 0},
- {WID_REKEY_POLICY, 0},
- {WID_SHORT_SLOT_ALLOWED, 0},
- {WID_START_SCAN_REQ, 0},
{WID_RSSI, 0},
{WID_LINKSPEED, 0},
- {WID_AUTO_RX_SENSITIVITY, 0},
- {WID_DATAFLOW_CONTROL, 0},
- {WID_SCAN_FILTER, 0},
- {WID_11N_PROT_MECH, 0},
- {WID_11N_ERP_PROT_TYPE, 0},
- {WID_11N_ENABLE, 0},
- {WID_11N_OPERATING_MODE, 0},
- {WID_11N_OBSS_NONHT_DETECTION, 0},
- {WID_11N_HT_PROT_TYPE, 0},
- {WID_11N_RIFS_PROT_ENABLE, 0},
- {WID_11N_SMPS_MODE, 0},
- {WID_11N_CURRENT_TX_MCS, 0},
- {WID_11N_SHORT_GI_ENABLE, 0},
- {WID_RIFS_MODE, 0},
- {WID_TX_ABORT_CONFIG, 0},
- {WID_11N_IMMEDIATE_BA_ENABLED, 0},
- {WID_11N_TXOP_PROT_DISABLE, 0},
{WID_NIL, 0}
};

static struct wilc_cfg_hword g_cfg_hword[] = {
- {WID_LINK_LOSS_THRESHOLD, 0},
- {WID_RTS_THRESHOLD, 0},
- {WID_FRAG_THRESHOLD, 0},
- {WID_SHORT_RETRY_LIMIT, 0},
- {WID_LONG_RETRY_LIMIT, 0},
- {WID_BEACON_INTERVAL, 0},
- {WID_RX_SENSE, 0},
- {WID_ACTIVE_SCAN_TIME, 0},
- {WID_PASSIVE_SCAN_TIME, 0},
- {WID_SITE_SURVEY_SCAN_TIME, 0},
- {WID_JOIN_START_TIMEOUT, 0},
- {WID_AUTH_TIMEOUT, 0},
- {WID_ASOC_TIMEOUT, 0},
- {WID_11I_PROTOCOL_TIMEOUT, 0},
- {WID_EAPOL_RESPONSE_TIMEOUT, 0},
- {WID_11N_SIG_QUAL_VAL, 0},
- {WID_CCA_THRESHOLD, 0},
{WID_NIL, 0}
};

static struct wilc_cfg_word g_cfg_word[] = {
{WID_FAILED_COUNT, 0},
- {WID_RETRY_COUNT, 0},
- {WID_MULTIPLE_RETRY_COUNT, 0},
- {WID_FRAME_DUPLICATE_COUNT, 0},
- {WID_ACK_FAILURE_COUNT, 0},
{WID_RECEIVED_FRAGMENT_COUNT, 0},
- {WID_MCAST_RECEIVED_FRAME_COUNT, 0},
- {WID_FCS_ERROR_COUNT, 0},
{WID_SUCCESS_FRAME_COUNT, 0},
- {WID_TX_FRAGMENT_COUNT, 0},
- {WID_TX_MULTICAST_FRAME_COUNT, 0},
- {WID_RTS_SUCCESS_COUNT, 0},
- {WID_RTS_FAILURE_COUNT, 0},
- {WID_WEP_UNDECRYPTABLE_COUNT, 0},
- {WID_REKEY_PERIOD, 0},
- {WID_REKEY_PACKET_COUNT, 0},
- {WID_HW_RX_COUNT, 0},
{WID_GET_INACTIVE_TIME, 0},
{WID_NIL, 0}

};

static struct wilc_cfg_str g_cfg_str[] = {
- {WID_SSID, g_mac.ssid}, /* 33 + 1 bytes */
{WID_FIRMWARE_VERSION, g_mac.firmware_version},
- {WID_OPERATIONAL_RATE_SET, g_mac.supp_rate},
- {WID_BSSID, g_mac.bssid}, /* 6 bytes */
- {WID_WEP_KEY_VALUE, g_mac.wep_key}, /* 27 bytes */
- {WID_11I_PSK, g_mac.i_psk}, /* 65 bytes */
- {WID_HARDWARE_VERSION, g_mac.hw_product_version},
{WID_MAC_ADDR, g_mac.mac_address},
- {WID_PHY_VERSION, g_mac.phyversion},
- {WID_SUPP_USERNAME, g_mac.supp_username},
- {WID_SUPP_PASSWORD, g_mac.supp_password},
- {WID_SITE_SURVEY_RESULTS, g_mac.scan_result},
- {WID_SITE_SURVEY_RESULTS, g_mac.scan_result1},
- {WID_ASSOC_REQ_INFO, g_mac.assoc_req},
{WID_ASSOC_RES_INFO, g_mac.assoc_rsp},
- {WID_FIRMWARE_INFO, g_mac.firmware_version},
- {WID_IP_ADDRESS, g_mac.ip_address},
{WID_NIL, NULL}
};

@@ -327,12 +232,6 @@ static void wilc_wlan_parse_response_frame(u8 *info, int size)
break;

if (g_cfg_str[i].id == wid) {
- if (wid == WID_SITE_SURVEY_RESULTS) {
- static int toggle;
-
- i += toggle;
- toggle ^= 1;
- }
memcpy(g_cfg_str[i].str, &info[2],
(info[2] + 2));
break;
@@ -478,12 +377,6 @@ int wilc_wlan_cfg_get_wid_value(u16 wid, u8 *buffer, u32 buffer_size)
(g_cfg_str[i].str[1] << 8);

if (buffer_size >= size) {
- if (id == WID_SITE_SURVEY_RESULTS) {
- static int toggle;
-
- i += toggle;
- toggle ^= 1;
- }
memcpy(buffer, &g_cfg_str[i].str[2],
size);
ret = size;
--
2.7.4

2018-09-19 11:42:16

by Ajay Singh

[permalink] [raw]
Subject: [PATCH 08/29] staging: wilc1000: change return type to 'void' tcp ack filter functions

Use 'void' return type for below functions as they always return '0' and
their return value is not used by caller.
add_tcp_pending_ack()
update_tcp_session()
add_tcp_pending_ack()

Signed-off-by: Ajay Singh <[email protected]>
---
drivers/staging/wilc1000/wilc_wlan.c | 15 ++++++---------
1 file changed, 6 insertions(+), 9 deletions(-)

diff --git a/drivers/staging/wilc1000/wilc_wlan.c b/drivers/staging/wilc1000/wilc_wlan.c
index 8057db9..66ce29d 100644
--- a/drivers/staging/wilc1000/wilc_wlan.c
+++ b/drivers/staging/wilc1000/wilc_wlan.c
@@ -91,8 +91,8 @@ static void wilc_wlan_txq_add_to_head(struct wilc_vif *vif,

#define NOT_TCP_ACK (-1)

-static inline int add_tcp_session(struct wilc_vif *vif, u32 src_prt,
- u32 dst_prt, u32 seq)
+static inline void add_tcp_session(struct wilc_vif *vif, u32 src_prt,
+ u32 dst_prt, u32 seq)
{
struct tcp_ack_filter *f = &vif->ack_filter;

@@ -103,22 +103,20 @@ static inline int add_tcp_session(struct wilc_vif *vif, u32 src_prt,
f->ack_session_info[f->tcp_session].dst_port = dst_prt;
f->tcp_session++;
}
- return 0;
}

-static inline int update_tcp_session(struct wilc_vif *vif, u32 index, u32 ack)
+static inline void update_tcp_session(struct wilc_vif *vif, u32 index, u32 ack)
{
struct tcp_ack_filter *f = &vif->ack_filter;

if (index < 2 * MAX_TCP_SESSION &&
ack > f->ack_session_info[index].bigger_ack_num)
f->ack_session_info[index].bigger_ack_num = ack;
- return 0;
}

-static inline int add_tcp_pending_ack(struct wilc_vif *vif, u32 ack,
- u32 session_index,
- struct txq_entry_t *txqe)
+static inline void add_tcp_pending_ack(struct wilc_vif *vif, u32 ack,
+ u32 session_index,
+ struct txq_entry_t *txqe)
{
struct tcp_ack_filter *f = &vif->ack_filter;
u32 i = f->pending_base + f->pending_acks_idx;
@@ -130,7 +128,6 @@ static inline int add_tcp_pending_ack(struct wilc_vif *vif, u32 ack,
txqe->ack_idx = i;
f->pending_acks_idx++;
}
- return 0;
}

static inline void tcp_process(struct net_device *dev, struct txq_entry_t *tqe)
--
2.7.4

2018-09-19 11:43:07

by Ajay Singh

[permalink] [raw]
Subject: [PATCH 22/29] staging: wilc1000: avoid use of 'g_spi' static variable

Instead of using static variable 'g_spi' move it as part of 'wilc'
struct. Also allocating the memory in the probe function and
free is taken care in wilc_netdev_cleanup().

Signed-off-by: Ajay Singh <[email protected]>
---
drivers/staging/wilc1000/wilc_spi.c | 58 +++++++++++++++++++++++--------------
1 file changed, 36 insertions(+), 22 deletions(-)

diff --git a/drivers/staging/wilc1000/wilc_spi.c b/drivers/staging/wilc1000/wilc_spi.c
index 5517477..2559cf0 100644
--- a/drivers/staging/wilc1000/wilc_spi.c
+++ b/drivers/staging/wilc1000/wilc_spi.c
@@ -14,7 +14,6 @@ struct wilc_spi {
int has_thrpt_enh;
};

-static struct wilc_spi g_spi;
static const struct wilc_hif_func wilc_hif_spi;

/********************************************
@@ -107,6 +106,11 @@ static int wilc_bus_probe(struct spi_device *spi)
int ret;
struct wilc *wilc;
struct gpio_desc *gpio;
+ struct wilc_spi *spi_priv;
+
+ spi_priv = kzalloc(sizeof(*spi_priv), GFP_KERNEL);
+ if (!spi_priv)
+ return -ENOMEM;

gpio = gpiod_get(&spi->dev, "irq", GPIOD_IN);
if (IS_ERR(gpio)) {
@@ -117,11 +121,14 @@ static int wilc_bus_probe(struct spi_device *spi)
}

ret = wilc_netdev_init(&wilc, NULL, HIF_SPI, &wilc_hif_spi);
- if (ret)
+ if (ret) {
+ kfree(spi_priv);
return ret;
+ }

spi_set_drvdata(spi, wilc);
wilc->dev = &spi->dev;
+ wilc->bus_data = spi_priv;
wilc->gpio_irq = gpio;

return 0;
@@ -275,6 +282,7 @@ static int spi_cmd_complete(struct wilc *wilc, u8 cmd, u32 adr, u8 *b, u32 sz,
u8 clockless)
{
struct spi_device *spi = to_spi_device(wilc->dev);
+ struct wilc_spi *spi_priv = wilc->bus_data;
u8 wb[32], rb[32];
u8 wix, rix;
u32 len2;
@@ -375,7 +383,7 @@ static int spi_cmd_complete(struct wilc *wilc, u8 cmd, u32 adr, u8 *b, u32 sz,
if (result != N_OK)
return result;

- if (!g_spi.crc_off)
+ if (!spi_priv->crc_off)
wb[len - 1] = (crc7(0x7f, (const u8 *)&wb[0], len - 1)) << 1;
else
len -= 1;
@@ -393,7 +401,7 @@ static int spi_cmd_complete(struct wilc *wilc, u8 cmd, u32 adr, u8 *b, u32 sz,
} else if (cmd == CMD_INTERNAL_READ || cmd == CMD_SINGLE_READ) {
int tmp = NUM_RSP_BYTES + NUM_DATA_HDR_BYTES + NUM_DATA_BYTES
+ NUM_DUMMY_BYTES;
- if (!g_spi.crc_off)
+ if (!spi_priv->crc_off)
len2 = len + tmp + NUM_CRC_BYTES;
else
len2 = len + tmp;
@@ -485,7 +493,7 @@ static int spi_cmd_complete(struct wilc *wilc, u8 cmd, u32 adr, u8 *b, u32 sz,
return N_FAIL;
}

- if (!g_spi.crc_off) {
+ if (!spi_priv->crc_off) {
/*
* Read Crc
*/
@@ -527,7 +535,7 @@ static int spi_cmd_complete(struct wilc *wilc, u8 cmd, u32 adr, u8 *b, u32 sz,
/*
* Read Crc
*/
- if (!g_spi.crc_off && wilc_spi_rx(wilc, crc, 2)) {
+ if (!spi_priv->crc_off && wilc_spi_rx(wilc, crc, 2)) {
dev_err(&spi->dev,
"Failed block crc read, bus err\n");
return N_FAIL;
@@ -585,7 +593,7 @@ static int spi_cmd_complete(struct wilc *wilc, u8 cmd, u32 adr, u8 *b, u32 sz,
/*
* Read Crc
*/
- if (!g_spi.crc_off && wilc_spi_rx(wilc, crc, 2)) {
+ if (!spi_priv->crc_off && wilc_spi_rx(wilc, crc, 2)) {
dev_err(&spi->dev,
"Failed block crc read, bus err\n");
result = N_FAIL;
@@ -602,6 +610,7 @@ static int spi_cmd_complete(struct wilc *wilc, u8 cmd, u32 adr, u8 *b, u32 sz,
static int spi_data_write(struct wilc *wilc, u8 *b, u32 sz)
{
struct spi_device *spi = to_spi_device(wilc->dev);
+ struct wilc_spi *spi_priv = wilc->bus_data;
int ix, nbytes;
int result = 1;
u8 cmd, order, crc[2] = {0};
@@ -648,7 +657,7 @@ static int spi_data_write(struct wilc *wilc, u8 *b, u32 sz)
/*
* Write Crc
*/
- if (!g_spi.crc_off) {
+ if (!spi_priv->crc_off) {
if (wilc_spi_tx(wilc, crc, 2)) {
dev_err(&spi->dev, "Failed data block crc write, bus error...\n");
result = N_FAIL;
@@ -816,6 +825,7 @@ static int _wilc_spi_deinit(struct wilc *wilc)
static int wilc_spi_init(struct wilc *wilc, bool resume)
{
struct spi_device *spi = to_spi_device(wilc->dev);
+ struct wilc_spi *spi_priv = wilc->bus_data;
u32 reg;
u32 chipid;
static int isinit;
@@ -828,12 +838,12 @@ static int wilc_spi_init(struct wilc *wilc, bool resume)
return 1;
}

- memset(&g_spi, 0, sizeof(struct wilc_spi));
+ memset(spi_priv, 0, sizeof(struct wilc_spi));

/*
* configure protocol
*/
- g_spi.crc_off = 0;
+ spi_priv->crc_off = 0;

/*
* TODO: We can remove the CRC trials if there is a definite
@@ -845,7 +855,7 @@ static int wilc_spi_init(struct wilc *wilc, bool resume)
* Read failed. Try with CRC off. This might happen when module
* is removed but chip isn't reset
*/
- g_spi.crc_off = 1;
+ spi_priv->crc_off = 1;
dev_err(&spi->dev,
"Failed read with CRC on, retrying with CRC off\n");
if (!spi_internal_read(wilc, WILC_SPI_PROTOCOL_OFFSET, &reg)) {
@@ -857,7 +867,7 @@ static int wilc_spi_init(struct wilc *wilc, bool resume)
return 0;
}
}
- if (g_spi.crc_off == 0) {
+ if (spi_priv->crc_off == 0) {
reg &= ~0xc; /* disable crc checking */
reg &= ~0x70;
reg |= (0x5 << 4);
@@ -867,7 +877,7 @@ static int wilc_spi_init(struct wilc *wilc, bool resume)
__LINE__);
return 0;
}
- g_spi.crc_off = 1;
+ spi_priv->crc_off = 1;
}

/*
@@ -878,7 +888,7 @@ static int wilc_spi_init(struct wilc *wilc, bool resume)
return 0;
}

- g_spi.has_thrpt_enh = 1;
+ spi_priv->has_thrpt_enh = 1;

isinit = 1;

@@ -888,9 +898,10 @@ static int wilc_spi_init(struct wilc *wilc, bool resume)
static int wilc_spi_read_size(struct wilc *wilc, u32 *size)
{
struct spi_device *spi = to_spi_device(wilc->dev);
+ struct wilc_spi *spi_priv = wilc->bus_data;
int ret;

- if (g_spi.has_thrpt_enh) {
+ if (spi_priv->has_thrpt_enh) {
ret = spi_internal_read(wilc, 0xe840 - WILC_SPI_REG_BASE,
size);
*size = *size & IRQ_DMA_WD_CNT_MASK;
@@ -915,6 +926,7 @@ static int wilc_spi_read_size(struct wilc *wilc, u32 *size)
static int wilc_spi_read_int(struct wilc *wilc, u32 *int_status)
{
struct spi_device *spi = to_spi_device(wilc->dev);
+ struct wilc_spi *spi_priv = wilc->bus_data;
int ret;
u32 tmp;
u32 byte_cnt;
@@ -923,7 +935,7 @@ static int wilc_spi_read_int(struct wilc *wilc, u32 *int_status)
u32 irq_flags;
int k = IRG_FLAGS_OFFSET + 5;

- if (g_spi.has_thrpt_enh) {
+ if (spi_priv->has_thrpt_enh) {
ret = spi_internal_read(wilc, 0xe840 - WILC_SPI_REG_BASE,
int_status);
return ret;
@@ -943,12 +955,12 @@ static int wilc_spi_read_int(struct wilc *wilc, u32 *int_status)
wilc_spi_read_reg(wilc, 0x1a90, &irq_flags);
tmp |= ((irq_flags >> 27) << IRG_FLAGS_OFFSET);

- if (g_spi.nint > 5) {
+ if (spi_priv->nint > 5) {
wilc_spi_read_reg(wilc, 0x1a94, &irq_flags);
tmp |= (((irq_flags >> 0) & 0x7) << k);
}

- unknown_mask = ~((1ul << g_spi.nint) - 1);
+ unknown_mask = ~((1ul << spi_priv->nint) - 1);

if ((tmp >> IRG_FLAGS_OFFSET) & unknown_mask) {
dev_err(&spi->dev,
@@ -968,11 +980,12 @@ static int wilc_spi_read_int(struct wilc *wilc, u32 *int_status)
static int wilc_spi_clear_int_ext(struct wilc *wilc, u32 val)
{
struct spi_device *spi = to_spi_device(wilc->dev);
+ struct wilc_spi *spi_priv = wilc->bus_data;
int ret;
u32 flags;
u32 tbl_ctl;

- if (g_spi.has_thrpt_enh) {
+ if (spi_priv->has_thrpt_enh) {
ret = spi_internal_write(wilc, 0xe844 - WILC_SPI_REG_BASE,
val);
return ret;
@@ -983,7 +996,7 @@ static int wilc_spi_clear_int_ext(struct wilc *wilc, u32 val)
int i;

ret = 1;
- for (i = 0; i < g_spi.nint; i++) {
+ for (i = 0; i < spi_priv->nint; i++) {
/*
* No matter what you write 1 or 0,
* it will clear interrupt.
@@ -1001,7 +1014,7 @@ static int wilc_spi_clear_int_ext(struct wilc *wilc, u32 val)
0x10c8 + i * 4);
return ret;
}
- for (i = g_spi.nint; i < MAX_NUM_INT; i++) {
+ for (i = spi_priv->nint; i < MAX_NUM_INT; i++) {
if (flags & 1)
dev_err(&spi->dev,
"Unexpected interrupt cleared %d...\n",
@@ -1041,6 +1054,7 @@ static int wilc_spi_clear_int_ext(struct wilc *wilc, u32 val)
static int wilc_spi_sync_ext(struct wilc *wilc, int nint)
{
struct spi_device *spi = to_spi_device(wilc->dev);
+ struct wilc_spi *spi_priv = wilc->bus_data;
u32 reg;
int ret, i;

@@ -1049,7 +1063,7 @@ static int wilc_spi_sync_ext(struct wilc *wilc, int nint)
return 0;
}

- g_spi.nint = nint;
+ spi_priv->nint = nint;

/*
* interrupt pin mux select
--
2.7.4

2018-09-19 11:42:19

by Ajay Singh

[permalink] [raw]
Subject: [PATCH 09/29] staging: wilc1000: use 'void' return for wilc_wlan_txq_filter_dup_tcp_ack()

Use 'void' return for wilc_wlan_txq_filter_dup_tcp_ack() as it always
return value '1' and its not used by the caller.

Signed-off-by: Ajay Singh <[email protected]>
---
drivers/staging/wilc1000/wilc_wlan.c | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/drivers/staging/wilc1000/wilc_wlan.c b/drivers/staging/wilc1000/wilc_wlan.c
index 66ce29d..88808d9 100644
--- a/drivers/staging/wilc1000/wilc_wlan.c
+++ b/drivers/staging/wilc1000/wilc_wlan.c
@@ -182,7 +182,7 @@ static inline void tcp_process(struct net_device *dev, struct txq_entry_t *tqe)
spin_unlock_irqrestore(&wilc->txq_spinlock, flags);
}

-static int wilc_wlan_txq_filter_dup_tcp_ack(struct net_device *dev)
+static void wilc_wlan_txq_filter_dup_tcp_ack(struct net_device *dev)
{
struct wilc_vif *vif = netdev_priv(dev);
struct wilc *wilc = vif->wilc;
@@ -237,8 +237,6 @@ static int wilc_wlan_txq_filter_dup_tcp_ack(struct net_device *dev)
msecs_to_jiffies(1));
dropped--;
}
-
- return 1;
}

void wilc_enable_tcp_ack_filter(struct wilc_vif *vif, bool value)
--
2.7.4

2018-09-19 11:41:54

by Ajay Singh

[permalink] [raw]
Subject: [PATCH 02/29] staging: wilc1000: change return type to 'void' for wilc_wlan_set_bssid()

Cleanup patch to use 'void' return type for wilc_wlan_set_bssid(),
as its always returns the same value.

Signed-off-by: Ajay Singh <[email protected]>
---
drivers/staging/wilc1000/linux_wlan.c | 4 +---
drivers/staging/wilc1000/wilc_wfi_netdevice.h | 2 +-
2 files changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/staging/wilc1000/linux_wlan.c b/drivers/staging/wilc1000/linux_wlan.c
index 49afda6..d1d2c64 100644
--- a/drivers/staging/wilc1000/linux_wlan.c
+++ b/drivers/staging/wilc1000/linux_wlan.c
@@ -192,14 +192,12 @@ static struct net_device *get_if_handler(struct wilc *wilc, u8 *mac_header)
return NULL;
}

-int wilc_wlan_set_bssid(struct net_device *wilc_netdev, u8 *bssid, u8 mode)
+void wilc_wlan_set_bssid(struct net_device *wilc_netdev, u8 *bssid, u8 mode)
{
struct wilc_vif *vif = netdev_priv(wilc_netdev);

memcpy(vif->bssid, bssid, 6);
vif->mode = mode;
-
- return 0;
}

int wilc_wlan_get_num_conn_ifcs(struct wilc *wilc)
diff --git a/drivers/staging/wilc1000/wilc_wfi_netdevice.h b/drivers/staging/wilc1000/wilc_wfi_netdevice.h
index 1837808..30151b2 100644
--- a/drivers/staging/wilc1000/wilc_wfi_netdevice.h
+++ b/drivers/staging/wilc1000/wilc_wfi_netdevice.h
@@ -215,6 +215,6 @@ void wilc_netdev_cleanup(struct wilc *wilc);
int wilc_netdev_init(struct wilc **wilc, struct device *dev, int io_type,
const struct wilc_hif_func *ops);
void wilc_wfi_mgmt_rx(struct wilc *wilc, u8 *buff, u32 size);
-int wilc_wlan_set_bssid(struct net_device *wilc_netdev, u8 *bssid, u8 mode);
+void wilc_wlan_set_bssid(struct net_device *wilc_netdev, u8 *bssid, u8 mode);

#endif
--
2.7.4

2018-09-19 11:42:53

by Ajay Singh

[permalink] [raw]
Subject: [PATCH 18/29] staging: wilc1000: rename 'wilc_mac_cfg' struct to 'wilc_cfg_str_vals'

Rename 'wilc_mac_cfg' struct to 'wilc_cfg_str_vals' as its more
appropriate for structure to store the values of string configuration.

Signed-off-by: Ajay Singh <[email protected]>
---
drivers/staging/wilc1000/wilc_wlan_cfg.c | 14 +++++++-------
drivers/staging/wilc1000/wilc_wlan_cfg.h | 4 ++--
2 files changed, 9 insertions(+), 9 deletions(-)

diff --git a/drivers/staging/wilc1000/wilc_wlan_cfg.c b/drivers/staging/wilc1000/wilc_wlan_cfg.c
index 8f1e962..930a389 100644
--- a/drivers/staging/wilc1000/wilc_wlan_cfg.c
+++ b/drivers/staging/wilc1000/wilc_wlan_cfg.c
@@ -438,7 +438,7 @@ void wilc_wlan_cfg_indicate_rx(struct wilc *wilc, u8 *frame, int size,

int wilc_wlan_cfg_init(struct wilc *wl)
{
- struct wilc_mac_cfg *mac_cfg;
+ struct wilc_cfg_str_vals *str_vals;
int i = 0;

wl->cfg.b = kmemdup(g_cfg_byte, sizeof(g_cfg_byte), GFP_KERNEL);
@@ -457,20 +457,20 @@ int wilc_wlan_cfg_init(struct wilc *wl)
if (!wl->cfg.s)
goto out_w;

- mac_cfg = kzalloc(sizeof(mac_cfg), GFP_KERNEL);
- if (!mac_cfg)
+ str_vals = kzalloc(sizeof(str_vals), GFP_KERNEL);
+ if (!str_vals)
goto out_s;

- wl->cfg.str_vals = mac_cfg;
+ wl->cfg.str_vals = str_vals;
/* store the string cfg parameters */
wl->cfg.s[i].id = WID_FIRMWARE_VERSION;
- wl->cfg.s[i].str = mac_cfg->firmware_version;
+ wl->cfg.s[i].str = str_vals->firmware_version;
i++;
wl->cfg.s[i].id = WID_MAC_ADDR;
- wl->cfg.s[i].str = mac_cfg->mac_address;
+ wl->cfg.s[i].str = str_vals->mac_address;
i++;
wl->cfg.s[i].id = WID_ASSOC_RES_INFO;
- wl->cfg.s[i].str = mac_cfg->assoc_rsp;
+ wl->cfg.s[i].str = str_vals->assoc_rsp;
i++;
wl->cfg.s[i].id = WID_NIL;
wl->cfg.s[i].str = NULL;
diff --git a/drivers/staging/wilc1000/wilc_wlan_cfg.h b/drivers/staging/wilc1000/wilc_wlan_cfg.h
index 176eef1..e5ca6ce 100644
--- a/drivers/staging/wilc1000/wilc_wlan_cfg.h
+++ b/drivers/staging/wilc1000/wilc_wlan_cfg.h
@@ -27,7 +27,7 @@ struct wilc_cfg_str {
u8 *str;
};

-struct wilc_mac_cfg {
+struct wilc_cfg_str_vals {
u8 mac_address[7];
u8 firmware_version[129];
u8 assoc_rsp[256];
@@ -38,7 +38,7 @@ struct wilc_cfg {
struct wilc_cfg_hword *hw;
struct wilc_cfg_word *w;
struct wilc_cfg_str *s;
- struct wilc_mac_cfg *str_vals;
+ struct wilc_cfg_str_vals *str_vals;
};

struct wilc;
--
2.7.4

2018-09-19 11:42:38

by Ajay Singh

[permalink] [raw]
Subject: [PATCH 14/29] staging: wilc1000: remove unused wid type values

Cleanup patch to remove the wid type not used in the code.

Signed-off-by: Ajay Singh <[email protected]>
---
drivers/staging/wilc1000/wilc_wlan_if.h | 4 ----
1 file changed, 4 deletions(-)

diff --git a/drivers/staging/wilc1000/wilc_wlan_if.h b/drivers/staging/wilc1000/wilc_wlan_if.h
index b81a73b..ce2066b 100644
--- a/drivers/staging/wilc1000/wilc_wlan_if.h
+++ b/drivers/staging/wilc1000/wilc_wlan_if.h
@@ -204,10 +204,6 @@ enum wid_type {
WID_STR = 3,
WID_BIN_DATA = 4,
WID_BIN = 5,
- WID_IP = 6,
- WID_ADR = 7,
- WID_UNDEF = 8,
- WID_TYPE_FORCE_32BIT = 0xFFFFFFFF
};

struct wid {
--
2.7.4

2018-09-19 11:42:23

by Ajay Singh

[permalink] [raw]
Subject: [PATCH 10/29] staging: wilc1000: change return type to 'void' for wilc_wlan_cfg_indicate_rx()

Cleanup patch to use 'void' return type for wilc_wlan_cfg_indicate_rx(),
as its return value is not used in caller. The value set in
'rsp' argument is used to get the success status.

Signed-off-by: Ajay Singh <[email protected]>
---
drivers/staging/wilc1000/wilc_wlan_cfg.c | 8 ++------
drivers/staging/wilc1000/wilc_wlan_cfg.h | 4 ++--
2 files changed, 4 insertions(+), 8 deletions(-)

diff --git a/drivers/staging/wilc1000/wilc_wlan_cfg.c b/drivers/staging/wilc1000/wilc_wlan_cfg.c
index 4215763..42c64ed 100644
--- a/drivers/staging/wilc1000/wilc_wlan_cfg.c
+++ b/drivers/staging/wilc1000/wilc_wlan_cfg.c
@@ -502,10 +502,9 @@ int wilc_wlan_cfg_get_wid_value(u16 wid, u8 *buffer, u32 buffer_size)
return ret;
}

-int wilc_wlan_cfg_indicate_rx(struct wilc *wilc, u8 *frame, int size,
- struct wilc_cfg_rsp *rsp)
+void wilc_wlan_cfg_indicate_rx(struct wilc *wilc, u8 *frame, int size,
+ struct wilc_cfg_rsp *rsp)
{
- int ret = 1;
u8 msg_type;
u8 msg_id;

@@ -547,11 +546,8 @@ int wilc_wlan_cfg_indicate_rx(struct wilc *wilc, u8 *frame, int size,
default:
rsp->type = 0;
rsp->seq_no = msg_id;
- ret = 0;
break;
}
-
- return ret;
}

int wilc_wlan_cfg_init(void)
diff --git a/drivers/staging/wilc1000/wilc_wlan_cfg.h b/drivers/staging/wilc1000/wilc_wlan_cfg.h
index 0c649d1..189e617 100644
--- a/drivers/staging/wilc1000/wilc_wlan_cfg.h
+++ b/drivers/staging/wilc1000/wilc_wlan_cfg.h
@@ -31,8 +31,8 @@ struct wilc;
int wilc_wlan_cfg_set_wid(u8 *frame, u32 offset, u16 id, u8 *buf, int size);
int wilc_wlan_cfg_get_wid(u8 *frame, u32 offset, u16 id);
int wilc_wlan_cfg_get_wid_value(u16 wid, u8 *buffer, u32 buffer_size);
-int wilc_wlan_cfg_indicate_rx(struct wilc *wilc, u8 *frame, int size,
- struct wilc_cfg_rsp *rsp);
+void wilc_wlan_cfg_indicate_rx(struct wilc *wilc, u8 *frame, int size,
+ struct wilc_cfg_rsp *rsp);
int wilc_wlan_cfg_init(void);

#endif
--
2.7.4

2018-09-19 11:42:46

by Ajay Singh

[permalink] [raw]
Subject: [PATCH 16/29] staging: wilc1000: refactor code to remove 'mac_status' from 'wilc_mac_cfg' struct

Refactor the code by removing use of 'mac_status' from 'wilc_mac_cfg'
and only have the string type configuration values in 'wilc_mac_cfg'
struct. Now fetch the value 'WID_STATUS' configuration from 'g_cfg_byte'
array.

Signed-off-by: Ajay Singh <[email protected]>
---
drivers/staging/wilc1000/linux_wlan.c | 4 ++--
drivers/staging/wilc1000/wilc_wfi_netdevice.h | 2 +-
drivers/staging/wilc1000/wilc_wlan_cfg.c | 23 ++++++++++++++---------
3 files changed, 17 insertions(+), 12 deletions(-)

diff --git a/drivers/staging/wilc1000/linux_wlan.c b/drivers/staging/wilc1000/linux_wlan.c
index e2669b9..d9f927e 100644
--- a/drivers/staging/wilc1000/linux_wlan.c
+++ b/drivers/staging/wilc1000/linux_wlan.c
@@ -159,9 +159,9 @@ static void deinit_irq(struct net_device *dev)

void wilc_mac_indicate(struct wilc *wilc)
{
- int status;
+ s8 status;

- wilc_wlan_cfg_get_val(WID_STATUS, (unsigned char *)&status, 4);
+ wilc_wlan_cfg_get_val(WID_STATUS, &status, 1);
if (wilc->mac_status == MAC_STATUS_INIT) {
wilc->mac_status = status;
complete(&wilc->sync_event);
diff --git a/drivers/staging/wilc1000/wilc_wfi_netdevice.h b/drivers/staging/wilc1000/wilc_wfi_netdevice.h
index 30151b2..70bae3a 100644
--- a/drivers/staging/wilc1000/wilc_wfi_netdevice.h
+++ b/drivers/staging/wilc1000/wilc_wfi_netdevice.h
@@ -155,7 +155,7 @@ struct wilc_vif {
struct wilc {
const struct wilc_hif_func *hif_func;
int io_type;
- int mac_status;
+ s8 mac_status;
struct gpio_desc *gpio_irq;
bool initialized;
int dev_irq_num;
diff --git a/drivers/staging/wilc1000/wilc_wlan_cfg.c b/drivers/staging/wilc1000/wilc_wlan_cfg.c
index 541251b..4434976 100644
--- a/drivers/staging/wilc1000/wilc_wlan_cfg.c
+++ b/drivers/staging/wilc1000/wilc_wlan_cfg.c
@@ -18,7 +18,6 @@ enum cfg_cmd_type {
};

struct wilc_mac_cfg {
- int mac_status;
u8 mac_address[7];
u8 firmware_version[129];
u8 assoc_rsp[256];
@@ -251,15 +250,26 @@ static void wilc_wlan_parse_response_frame(u8 *info, int size)

static void wilc_wlan_parse_info_frame(u8 *info)
{
- struct wilc_mac_cfg *pd = &g_mac;
u32 wid, len;

wid = info[0] | (info[1] << 8);

len = info[2];

- if (len == 1 && wid == WID_STATUS)
- pd->mac_status = info[3];
+ if (len == 1 && wid == WID_STATUS) {
+ int i = 0;
+
+ do {
+ if (g_cfg_byte[i].id == WID_NIL)
+ break;
+
+ if (g_cfg_byte[i].id == wid) {
+ g_cfg_byte[i].val = info[3];
+ break;
+ }
+ i++;
+ } while (1);
+ }
}

/********************************************
@@ -323,11 +333,6 @@ int wilc_wlan_cfg_get_wid_value(u16 wid, u8 *buffer, u32 buffer_size)
u32 type = (wid >> 12) & 0xf;
int i, ret = 0;

- if (wid == WID_STATUS) {
- *((u32 *)buffer) = g_mac.mac_status;
- return 4;
- }
-
i = 0;
if (type == CFG_BYTE_CMD) {
do {
--
2.7.4

2018-09-19 15:18:51

by Dan Carpenter

[permalink] [raw]
Subject: Re: [PATCH 29/29] staging: wilc1000: return exact error of register_netdev() from wilc_netdev_init()

I was waiting for you to send this like a spider waits for flies. You
fell directly into my trap. Mwuahahahahaha.

drivers/staging/wilc1000/linux_wlan.c
1056 int wilc_netdev_init(struct wilc **wilc, struct device *dev, int io_type,
1057 const struct wilc_hif_func *ops)
1058 {
1059 int i, ret = -ENOMEM;
1060 struct wilc_vif *vif;
1061 struct net_device *ndev;
1062 struct wilc *wl;
1063
1064 wl = kzalloc(sizeof(*wl), GFP_KERNEL);
1065 if (!wl)
1066 return ret;
^^^
It's cleaner to return -ENOMEM so that we don't have to glance up to the
declaration block. This is especially true when "ret" is zero, btw,
because that can indicate a reversed test.

if (!ret)
return ret;

In this theoretically example it was supposed to be:

if (ret)
return ret;

Normally, reversed conditions are caught in testing, but for the kernel,
no one has the hardware to test everything so we do get reversed
conditions from time to time.

1067
1068 if (wilc_wlan_cfg_init(wl))
1069 goto free_wl;
1070
1071 *wilc = wl;
1072 wl->io_type = io_type;
1073 wl->hif_func = ops;
1074 wl->enable_ps = true;
1075 wl->chip_ps_state = CHIP_WAKEDUP;
1076 INIT_LIST_HEAD(&wl->txq_head.list);
1077 INIT_LIST_HEAD(&wl->rxq_head.list);
1078
1079 wl->hif_workqueue = create_singlethread_workqueue("WILC_wq");
1080 if (!wl->hif_workqueue)
1081 goto free_cfg;
1082
1083 register_inetaddr_notifier(&g_dev_notifier);
1084
1085 for (i = 0; i < NUM_CONCURRENT_IFC; i++) {
1086 struct wireless_dev *wdev;
1087
1088 ndev = alloc_etherdev(sizeof(struct wilc_vif));
1089 if (!ndev)
1090 goto free_ndev;
^^^^^^^^^^^^^^^
ret is zero on the second iteration through the loop.

1091
1092 vif = netdev_priv(ndev);
1093 memset(vif, 0, sizeof(struct wilc_vif));
1094
1095 if (i == 0) {
1096 strcpy(ndev->name, "wlan%d");
1097 vif->ifc_id = 1;
1098 } else {
1099 strcpy(ndev->name, "p2p%d");
1100 vif->ifc_id = 0;
1101 }
1102 vif->wilc = *wilc;
1103 vif->ndev = ndev;
1104 wl->vif[i] = vif;
1105 wl->vif_num = i;
1106 vif->idx = wl->vif_num;
1107
1108 ndev->netdev_ops = &wilc_netdev_ops;
1109
1110 wdev = wilc_create_wiphy(ndev, dev);
1111 if (!wdev) {
1112 netdev_err(ndev, "Can't register WILC Wiphy\n");
1113 goto free_ndev;
^^^^^^^^^^^^^^^
Here too.

1114 }
1115
1116 SET_NETDEV_DEV(ndev, dev);
1117
1118 vif->ndev->ieee80211_ptr = wdev;
1119 vif->ndev->ml_priv = vif;
1120 wdev->netdev = vif->ndev;
1121 vif->netstats.rx_packets = 0;
1122 vif->netstats.tx_packets = 0;
1123 vif->netstats.rx_bytes = 0;
1124 vif->netstats.tx_bytes = 0;
1125
1126 ret = register_netdev(ndev);
1127 if (ret)
1128 goto free_ndev;
^^^^^^^^
ret is cleared on the first iteration through the loop.

1129
1130 vif->iftype = STATION_MODE;
1131 vif->mac_opened = 0;
1132 }
1133
1134 return 0;

regards,
dan carpenter

2018-09-19 11:43:11

by Ajay Singh

[permalink] [raw]
Subject: [PATCH 23/29] staging: wilc1000: remove unnecessary memset in sdio_init() & wilc_spi_init()

Cleanup changes to avoid unnecessary setting 'wilc->bus_data' value to
zero as the buffer was allocated using kzalloc().

Signed-off-by: Ajay Singh <[email protected]>
---
drivers/staging/wilc1000/wilc_sdio.c | 4 +---
drivers/staging/wilc1000/wilc_spi.c | 3 ---
2 files changed, 1 insertion(+), 6 deletions(-)

diff --git a/drivers/staging/wilc1000/wilc_sdio.c b/drivers/staging/wilc1000/wilc_sdio.c
index 7ef047c..ca351c9 100644
--- a/drivers/staging/wilc1000/wilc_sdio.c
+++ b/drivers/staging/wilc1000/wilc_sdio.c
@@ -689,10 +689,8 @@ static int sdio_init(struct wilc *wilc, bool resume)
int loop, ret;
u32 chipid;

- if (!resume) {
- memset(sdio_priv, 0, sizeof(struct wilc_sdio));
+ if (!resume)
sdio_priv->irq_gpio = wilc->dev_irq_num;
- }

/**
* function 0 csa enable
diff --git a/drivers/staging/wilc1000/wilc_spi.c b/drivers/staging/wilc1000/wilc_spi.c
index 2559cf0..cef127b 100644
--- a/drivers/staging/wilc1000/wilc_spi.c
+++ b/drivers/staging/wilc1000/wilc_spi.c
@@ -838,12 +838,9 @@ static int wilc_spi_init(struct wilc *wilc, bool resume)
return 1;
}

- memset(spi_priv, 0, sizeof(struct wilc_spi));
-
/*
* configure protocol
*/
- spi_priv->crc_off = 0;

/*
* TODO: We can remove the CRC trials if there is a definite
--
2.7.4

2018-09-19 11:43:33

by Ajay Singh

[permalink] [raw]
Subject: [PATCH 29/29] staging: wilc1000: return exact error of register_netdev() from wilc_netdev_init()

Modified wilc_netdev_init() to return the error code received from
register_netdev() during the failure condition.

Earlier discussion link
[1]. https://www.spinics.net/lists/linux-wireless/msg177304.html

Suggested-by: Claudiu Beznea <[email protected]>
Signed-off-by: Ajay Singh <[email protected]>
---
drivers/staging/wilc1000/linux_wlan.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/staging/wilc1000/linux_wlan.c b/drivers/staging/wilc1000/linux_wlan.c
index 29c1317..75abaf9 100644
--- a/drivers/staging/wilc1000/linux_wlan.c
+++ b/drivers/staging/wilc1000/linux_wlan.c
@@ -1056,14 +1056,14 @@ static const struct net_device_ops wilc_netdev_ops = {
int wilc_netdev_init(struct wilc **wilc, struct device *dev, int io_type,
const struct wilc_hif_func *ops)
{
- int i, ret;
+ int i, ret = -ENOMEM;
struct wilc_vif *vif;
struct net_device *ndev;
struct wilc *wl;

wl = kzalloc(sizeof(*wl), GFP_KERNEL);
if (!wl)
- return -ENOMEM;
+ return ret;

if (wilc_wlan_cfg_init(wl))
goto free_wl;
@@ -1151,7 +1151,7 @@ int wilc_netdev_init(struct wilc **wilc, struct device *dev, int io_type,
wilc_wlan_cfg_deinit(wl);
free_wl:
kfree(wl);
- return -ENOMEM;
+ return ret;
}
EXPORT_SYMBOL_GPL(wilc_netdev_init);

--
2.7.4

2018-09-19 11:43:00

by Ajay Singh

[permalink] [raw]
Subject: [PATCH 20/29] staging: wilc1000: remove use of unnecessary 'wilc_connected_ssid' variable

'wilc_connected_ssid' actually used to store the BSSID information for
connected BSSID. 'wilc_vif' already has 'bssid' variable to store the
same information. So refactor code to remove 'wilc_connected_ssid' and
instead used 'wilc_vif' struct 'bssid' element.

Signed-off-by: Ajay Singh <[email protected]>
---
drivers/staging/wilc1000/host_interface.c | 24 -----------------------
drivers/staging/wilc1000/host_interface.h | 2 --
drivers/staging/wilc1000/wilc_wfi_cfgoperations.c | 24 ++++++++++++++---------
3 files changed, 15 insertions(+), 35 deletions(-)

diff --git a/drivers/staging/wilc1000/host_interface.c b/drivers/staging/wilc1000/host_interface.c
index 529390d..01db899 100644
--- a/drivers/staging/wilc1000/host_interface.c
+++ b/drivers/staging/wilc1000/host_interface.c
@@ -813,7 +813,6 @@ static void handle_scan(struct work_struct *work)
kfree(msg);
}

-u8 wilc_connected_ssid[6] = {0};
static void handle_connect(struct work_struct *work)
{
struct host_if_msg *msg = container_of(work, struct host_if_msg, work);
@@ -835,11 +834,6 @@ static void handle_connect(struct work_struct *work)
return;
}

- if (memcmp(conn_attr->bssid, wilc_connected_ssid, ETH_ALEN) == 0) {
- netdev_err(vif->ndev, "Discard connect request\n");
- goto error;
- }
-
bss_param = conn_attr->params;
if (!bss_param) {
netdev_err(vif->ndev, "Required BSSID not found\n");
@@ -1019,10 +1013,6 @@ static void handle_connect(struct work_struct *work)
cur_byte = wid_list[wid_cnt].val;
wid_cnt++;

- if (conn_attr->bssid)
- memcpy(wilc_connected_ssid,
- conn_attr->bssid, ETH_ALEN);
-
result = wilc_send_config_pkt(vif, SET_CFG, wid_list,
wid_cnt,
wilc_get_vif_idx(vif));
@@ -1145,8 +1135,6 @@ static void handle_connect_timeout(struct work_struct *work)
kfree(hif_drv->usr_conn_req.ies);
hif_drv->usr_conn_req.ies = NULL;

- eth_zero_addr(wilc_connected_ssid);
-
out:
kfree(msg);
}
@@ -1452,16 +1440,6 @@ static inline void host_int_parse_assoc_resp_info(struct wilc_vif *vif,
}
}

- if (mac_status == MAC_STATUS_CONNECTED &&
- conn_info.status != WLAN_STATUS_SUCCESS) {
- netdev_err(vif->ndev,
- "Received MAC status is MAC_STATUS_CONNECTED, Assoc Resp is not SUCCESS\n");
- eth_zero_addr(wilc_connected_ssid);
- } else if (mac_status == MAC_STATUS_DISCONNECTED) {
- netdev_err(vif->ndev, "Received MAC status is MAC_STATUS_DISCONNECTED\n");
- eth_zero_addr(wilc_connected_ssid);
- }
-
if (hif_drv->usr_conn_req.bssid) {
memcpy(conn_info.bssid, hif_drv->usr_conn_req.bssid, 6);

@@ -1874,8 +1852,6 @@ static void handle_disconnect(struct work_struct *work)
vif->obtaining_ip = false;
wilc_set_power_mgmt(vif, 0, 0);

- eth_zero_addr(wilc_connected_ssid);
-
result = wilc_send_config_pkt(vif, SET_CFG, &wid, 1,
wilc_get_vif_idx(vif));

diff --git a/drivers/staging/wilc1000/host_interface.h b/drivers/staging/wilc1000/host_interface.h
index 4416f8f..33fb731 100644
--- a/drivers/staging/wilc1000/host_interface.h
+++ b/drivers/staging/wilc1000/host_interface.h
@@ -359,6 +359,4 @@ int wilc_get_vif_idx(struct wilc_vif *vif);
int wilc_set_tx_power(struct wilc_vif *vif, u8 tx_power);
int wilc_get_tx_power(struct wilc_vif *vif, u8 *tx_power);

-extern u8 wilc_connected_ssid[6];
-
#endif
diff --git a/drivers/staging/wilc1000/wilc_wfi_cfgoperations.c b/drivers/staging/wilc1000/wilc_wfi_cfgoperations.c
index 76d017d..1a4d262 100644
--- a/drivers/staging/wilc1000/wilc_wfi_cfgoperations.c
+++ b/drivers/staging/wilc1000/wilc_wfi_cfgoperations.c
@@ -478,7 +478,6 @@ static void cfg_connect_result(enum conn_event conn_disconn_evt,
connect_status = WLAN_STATUS_UNSPECIFIED_FAILURE;
wilc_wlan_set_bssid(priv->dev, null_bssid,
STATION_MODE);
- eth_zero_addr(wilc_connected_ssid);

if (!wfi_drv->p2p_connect)
wlan_channel = INVALID_CHANNEL;
@@ -521,7 +520,6 @@ static void cfg_connect_result(enum conn_event conn_disconn_evt,
wilc_ie = false;
eth_zero_addr(priv->associated_bss);
wilc_wlan_set_bssid(priv->dev, null_bssid, STATION_MODE);
- eth_zero_addr(wilc_connected_ssid);

if (!wfi_drv->p2p_connect)
wlan_channel = INVALID_CHANNEL;
@@ -696,8 +694,12 @@ static int connect(struct wiphy *wiphy, struct net_device *dev,
nw_info = &priv->scanned_shadow[sel_bssi_idx];
} else {
ret = -ENOENT;
- vif->connecting = false;
- return ret;
+ goto out_error;
+ }
+
+ if (ether_addr_equal_unaligned(vif->bssid, nw_info->bssid)) {
+ ret = -EALREADY;
+ goto out_error;
}

memset(priv->wep_key, 0, sizeof(priv->wep_key));
@@ -739,8 +741,7 @@ static int connect(struct wiphy *wiphy, struct net_device *dev,
ret = -ENOTSUPP;
netdev_err(dev, "%s: Unsupported cipher\n",
__func__);
- vif->connecting = false;
- return ret;
+ goto out_error;
}
}

@@ -787,13 +788,18 @@ static int connect(struct wiphy *wiphy, struct net_device *dev,
security, auth_type,
nw_info->ch,
nw_info->join_params);
- if (ret != 0) {
+ if (ret) {
+ u8 null_bssid[ETH_ALEN] = {0};
+
netdev_err(dev, "wilc_set_join_req(): Error\n");
ret = -ENOENT;
- vif->connecting = false;
- return ret;
+ wilc_wlan_set_bssid(dev, null_bssid, STATION_MODE);
+ goto out_error;
}
+ return 0;

+out_error:
+ vif->connecting = false;
return ret;
}

--
2.7.4

2018-09-19 11:42:02

by Ajay Singh

[permalink] [raw]
Subject: [PATCH 03/29] staging: wilc1000: change return type to 'void' for lock init & deinit functions

Cleanup patch to use 'void' return type for wlan_deinit_locks() &
wlan_init_locks(), as same value is return.

Signed-off-by: Ajay Singh <[email protected]>
---
drivers/staging/wilc1000/linux_wlan.c | 8 ++------
1 file changed, 2 insertions(+), 6 deletions(-)

diff --git a/drivers/staging/wilc1000/linux_wlan.c b/drivers/staging/wilc1000/linux_wlan.c
index d1d2c64..e2669b9 100644
--- a/drivers/staging/wilc1000/linux_wlan.c
+++ b/drivers/staging/wilc1000/linux_wlan.c
@@ -525,7 +525,7 @@ static int linux_wlan_init_test_config(struct net_device *dev,
return -1;
}

-static int wlan_deinit_locks(struct net_device *dev)
+static void wlan_deinit_locks(struct net_device *dev)
{
struct wilc_vif *vif = netdev_priv(dev);
struct wilc *wilc = vif->wilc;
@@ -533,8 +533,6 @@ static int wlan_deinit_locks(struct net_device *dev)
mutex_destroy(&wilc->hif_cs);
mutex_destroy(&wilc->rxq_cs);
mutex_destroy(&wilc->txq_add_to_head_cs);
-
- return 0;
}

static void wlan_deinitialize_threads(struct net_device *dev)
@@ -588,7 +586,7 @@ static void wilc_wlan_deinitialize(struct net_device *dev)
}
}

-static int wlan_init_locks(struct net_device *dev)
+static void wlan_init_locks(struct net_device *dev)
{
struct wilc_vif *vif = netdev_priv(dev);
struct wilc *wl = vif->wilc;
@@ -604,8 +602,6 @@ static int wlan_init_locks(struct net_device *dev)
init_completion(&wl->cfg_event);
init_completion(&wl->sync_event);
init_completion(&wl->txq_thread_started);
-
- return 0;
}

static int wlan_initialize_threads(struct net_device *dev)
--
2.7.4

2018-09-19 11:43:21

by Ajay Singh

[permalink] [raw]
Subject: [PATCH 26/29] staging: wilc1000: remove unnecessary option used with ccflags-y in Makefile

Cleanup patch to remove -I(src) and -DWILC_ASIC_A0 option used in
ccflag-y in Makefile.

Signed-off-by: Ajay Singh <[email protected]>
---
drivers/staging/wilc1000/Makefile | 2 --
1 file changed, 2 deletions(-)

diff --git a/drivers/staging/wilc1000/Makefile b/drivers/staging/wilc1000/Makefile
index 5718bc4..37e8560 100644
--- a/drivers/staging/wilc1000/Makefile
+++ b/drivers/staging/wilc1000/Makefile
@@ -4,8 +4,6 @@ obj-$(CONFIG_WILC1000) += wilc1000.o
ccflags-y += -DFIRMWARE_1002=\"atmel/wilc1002_firmware.bin\" \
-DFIRMWARE_1003=\"atmel/wilc1003_firmware.bin\"

-ccflags-y += -I$(src)/ -DWILC_ASIC_A0
-
wilc1000-objs := wilc_wfi_cfgoperations.o linux_wlan.o linux_mon.o \
coreconfigurator.o host_interface.o \
wilc_wlan_cfg.o wilc_wlan.o
--
2.7.4

2018-09-19 11:42:09

by Ajay Singh

[permalink] [raw]
Subject: [PATCH 06/29] staging: wilc1000: use 'void' return type for host_int_get_assoc_res_info()

Change return type to 'void' for host_int_get_assoc_res_info() as its
return value is not used. 'rcvd_assoc_resp_info_len' parameter value is
used to know the status.

Signed-off-by: Ajay Singh <[email protected]>
---
drivers/staging/wilc1000/host_interface.c | 11 +++++------
1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/drivers/staging/wilc1000/host_interface.c b/drivers/staging/wilc1000/host_interface.c
index 7729f83..237a098d 100644
--- a/drivers/staging/wilc1000/host_interface.c
+++ b/drivers/staging/wilc1000/host_interface.c
@@ -1388,10 +1388,10 @@ static void handle_rcvd_ntwrk_info(struct work_struct *work)
kfree(msg);
}

-static s32 host_int_get_assoc_res_info(struct wilc_vif *vif,
- u8 *assoc_resp_info,
- u32 max_assoc_resp_info_len,
- u32 *rcvd_assoc_resp_info_len)
+static void host_int_get_assoc_res_info(struct wilc_vif *vif,
+ u8 *assoc_resp_info,
+ u32 max_assoc_resp_info_len,
+ u32 *rcvd_assoc_resp_info_len)
{
int result;
struct wid wid;
@@ -1406,11 +1406,10 @@ static s32 host_int_get_assoc_res_info(struct wilc_vif *vif,
if (result) {
*rcvd_assoc_resp_info_len = 0;
netdev_err(vif->ndev, "Failed to send association response\n");
- return -EINVAL;
+ return;
}

*rcvd_assoc_resp_info_len = wid.size;
- return result;
}

static inline void host_int_free_user_conn_req(struct host_if_drv *hif_drv)
--
2.7.4

2018-09-19 11:43:25

by Ajay Singh

[permalink] [raw]
Subject: [PATCH 27/29] staging: wilc1000: use usleep_range() in place of udelay()

Changes to avoid the below checkpatch warning:

'usleep_range is preferred over udelay; see
Documentation/timers/timers-howto.txt;'

Signed-off-by: Ajay Singh <[email protected]>
---
drivers/staging/wilc1000/wilc_wlan.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/staging/wilc1000/wilc_wlan.c b/drivers/staging/wilc1000/wilc_wlan.c
index 0ec0d9b..a48c906 100644
--- a/drivers/staging/wilc1000/wilc_wlan.c
+++ b/drivers/staging/wilc1000/wilc_wlan.c
@@ -412,7 +412,7 @@ void chip_wakeup(struct wilc *wilc)
} while (wilc_get_chipid(wilc, true) == 0);
} else if ((wilc->io_type & 0x1) == HIF_SDIO) {
wilc->hif_func->hif_write_reg(wilc, 0xfa, 1);
- udelay(200);
+ usleep_range(200, 400);
wilc->hif_func->hif_read_reg(wilc, 0xf0, &reg);
do {
wilc->hif_func->hif_write_reg(wilc, 0xf0,
--
2.7.4

2018-09-19 11:43:29

by Ajay Singh

[permalink] [raw]
Subject: [PATCH 28/29] staging: wilc1000: avoid spaces preferred around checkpatch issue

Cleanup patch to add extra spaces around the '/' to avoid the below
checkpatch warning.

'spaces preferred around that '/' (ctx:VxV)'

Signed-off-by: Ajay Singh <[email protected]>
---
drivers/staging/wilc1000/linux_wlan.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/staging/wilc1000/linux_wlan.c b/drivers/staging/wilc1000/linux_wlan.c
index 695d5b2..29c1317 100644
--- a/drivers/staging/wilc1000/linux_wlan.c
+++ b/drivers/staging/wilc1000/linux_wlan.c
@@ -823,7 +823,7 @@ static void wilc_set_multicast_list(struct net_device *dev)

netdev_for_each_mc_addr(ha, dev) {
memcpy(mc_list + i, ha->addr, ETH_ALEN);
- netdev_dbg(dev, "Entry[%d]: %x:%x:%x:%x:%x:%x\n", i/ETH_ALEN,
+ netdev_dbg(dev, "Entry[%d]: %x:%x:%x:%x:%x:%x\n", i / ETH_ALEN,
mc_list[i], mc_list[i + 1], mc_list[i + 2],
mc_list[i + 3], mc_list[i + 4], mc_list[i + 5]);
i += ETH_ALEN;
--
2.7.4

2018-09-19 11:42:31

by Ajay Singh

[permalink] [raw]
Subject: [PATCH 12/29] staging: wilc1000: set default value of cfg response type in wilc_wlan_cfg_indicate_rx()

Handle the setting of default value for 'wilc_cfg_rsp' type for all
cases in wilc_wlan_cfg_indicate_rx() as the caller make use of this
value to know the type of the received message.

Signed-off-by: Ajay Singh <[email protected]>
---
drivers/staging/wilc1000/wilc_wlan_cfg.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/staging/wilc1000/wilc_wlan_cfg.c b/drivers/staging/wilc1000/wilc_wlan_cfg.c
index 2b5471b..2c463a3 100644
--- a/drivers/staging/wilc1000/wilc_wlan_cfg.c
+++ b/drivers/staging/wilc1000/wilc_wlan_cfg.c
@@ -507,6 +507,7 @@ void wilc_wlan_cfg_indicate_rx(struct wilc *wilc, u8 *frame, int size,
msg_id = frame[1]; /* seq no */
frame += 4;
size -= 4;
+ rsp->type = 0;

/*
* The valid types of response messages are
@@ -532,7 +533,6 @@ void wilc_wlan_cfg_indicate_rx(struct wilc *wilc, u8 *frame, int size,

case 'N':
wilc_network_info_received(wilc, frame - 4, size + 4);
- rsp->type = 0;
break;

case 'S':
@@ -540,7 +540,6 @@ void wilc_wlan_cfg_indicate_rx(struct wilc *wilc, u8 *frame, int size,
break;

default:
- rsp->type = 0;
rsp->seq_no = msg_id;
break;
}
--
2.7.4

2018-09-19 11:42:02

by Ajay Singh

[permalink] [raw]
Subject: [PATCH 04/29] staging: wilc1000: change return type to 'void' for wilc_deinit_host_int()

Cleanup patch to use 'void' return type for wilc_deinit_host_int(),
as its return value is not used in caller.

Signed-off-by: Ajay Singh <[email protected]>
---
drivers/staging/wilc1000/wilc_wfi_cfgoperations.c | 4 +---
drivers/staging/wilc1000/wilc_wfi_cfgoperations.h | 2 +-
2 files changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/staging/wilc1000/wilc_wfi_cfgoperations.c b/drivers/staging/wilc1000/wilc_wfi_cfgoperations.c
index 37c26d4..02a8846 100644
--- a/drivers/staging/wilc1000/wilc_wfi_cfgoperations.c
+++ b/drivers/staging/wilc1000/wilc_wfi_cfgoperations.c
@@ -2175,7 +2175,7 @@ int wilc_init_host_int(struct net_device *net)
return ret;
}

-int wilc_deinit_host_int(struct net_device *net)
+void wilc_deinit_host_int(struct net_device *net)
{
int ret;
struct wilc_priv *priv = wdev_priv(net->ieee80211_ptr);
@@ -2192,8 +2192,6 @@ int wilc_deinit_host_int(struct net_device *net)

if (ret)
netdev_err(net, "Error while deinitializing host interface\n");
-
- return ret;
}

void wilc_free_wiphy(struct net_device *net)
diff --git a/drivers/staging/wilc1000/wilc_wfi_cfgoperations.h b/drivers/staging/wilc1000/wilc_wfi_cfgoperations.h
index be412b6..1858f56 100644
--- a/drivers/staging/wilc1000/wilc_wfi_cfgoperations.h
+++ b/drivers/staging/wilc1000/wilc_wfi_cfgoperations.h
@@ -11,7 +11,7 @@
struct wireless_dev *wilc_create_wiphy(struct net_device *net,
struct device *dev);
void wilc_free_wiphy(struct net_device *net);
-int wilc_deinit_host_int(struct net_device *net);
+void wilc_deinit_host_int(struct net_device *net);
int wilc_init_host_int(struct net_device *net);
void wilc_wfi_monitor_rx(u8 *buff, u32 size);
int wilc_wfi_deinit_mon_interface(void);
--
2.7.4

2018-09-19 11:42:34

by Ajay Singh

[permalink] [raw]
Subject: [PATCH 13/29] staging: wilc1000: changes 'val' type to u8 in wilc_cfg_byte struct

Use the correct datatype for storing the byte value in 'wilc_cfg_byte'
struct.

Signed-off-by: Ajay Singh <[email protected]>
---
drivers/staging/wilc1000/wilc_wlan_cfg.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/staging/wilc1000/wilc_wlan_cfg.h b/drivers/staging/wilc1000/wilc_wlan_cfg.h
index 189e617..082093f 100644
--- a/drivers/staging/wilc1000/wilc_wlan_cfg.h
+++ b/drivers/staging/wilc1000/wilc_wlan_cfg.h
@@ -9,7 +9,7 @@

struct wilc_cfg_byte {
u16 id;
- u16 val;
+ u8 val;
};

struct wilc_cfg_hword {
--
2.7.4

2018-09-19 11:42:12

by Ajay Singh

[permalink] [raw]
Subject: [PATCH 07/29] staging: wilc1000: use 'void' return for wilc_wlan_txq_add_to_head()

Use 'void' return for wilc_wlan_txq_add_to_head() as its always
return '0' value.

Signed-off-by: Ajay Singh <[email protected]>
---
drivers/staging/wilc1000/wilc_wlan.c | 11 +++--------
1 file changed, 3 insertions(+), 8 deletions(-)

diff --git a/drivers/staging/wilc1000/wilc_wlan.c b/drivers/staging/wilc1000/wilc_wlan.c
index 590a51c..8057db9 100644
--- a/drivers/staging/wilc1000/wilc_wlan.c
+++ b/drivers/staging/wilc1000/wilc_wlan.c
@@ -71,8 +71,8 @@ static void wilc_wlan_txq_add_to_tail(struct net_device *dev,
complete(&wilc->txq_event);
}

-static int wilc_wlan_txq_add_to_head(struct wilc_vif *vif,
- struct txq_entry_t *tqe)
+static void wilc_wlan_txq_add_to_head(struct wilc_vif *vif,
+ struct txq_entry_t *tqe)
{
unsigned long flags;
struct wilc *wilc = vif->wilc;
@@ -87,8 +87,6 @@ static int wilc_wlan_txq_add_to_head(struct wilc_vif *vif,
spin_unlock_irqrestore(&wilc->txq_spinlock, flags);
mutex_unlock(&wilc->txq_add_to_head_cs);
complete(&wilc->txq_event);
-
- return 0;
}

#define NOT_TCP_ACK (-1)
@@ -275,10 +273,7 @@ static int wilc_wlan_txq_add_cfg_pkt(struct wilc_vif *vif, u8 *buffer,
tqe->priv = NULL;
tqe->ack_idx = NOT_TCP_ACK;

- if (wilc_wlan_txq_add_to_head(vif, tqe)) {
- kfree(tqe);
- return 0;
- }
+ wilc_wlan_txq_add_to_head(vif, tqe);

return 1;
}
--
2.7.4

2018-09-19 11:42:05

by Ajay Singh

[permalink] [raw]
Subject: [PATCH 05/29] staging: wilc1000: change return type to 'void' for wilc_wfi_deinit_mon_interface()

Use 'void' return type for wilc_wfi_deinit_mon_interface(), as same
value always return.

Signed-off-by: Ajay Singh <[email protected]>
---
drivers/staging/wilc1000/linux_mon.c | 3 +--
drivers/staging/wilc1000/wilc_wfi_cfgoperations.h | 2 +-
2 files changed, 2 insertions(+), 3 deletions(-)

diff --git a/drivers/staging/wilc1000/linux_mon.c b/drivers/staging/wilc1000/linux_mon.c
index 1afdb9e..a634468 100644
--- a/drivers/staging/wilc1000/linux_mon.c
+++ b/drivers/staging/wilc1000/linux_mon.c
@@ -253,7 +253,7 @@ struct net_device *wilc_wfi_init_mon_interface(const char *name,
return wilc_wfi_mon;
}

-int wilc_wfi_deinit_mon_interface(void)
+void wilc_wfi_deinit_mon_interface(void)
{
bool rollback_lock = false;

@@ -270,5 +270,4 @@ int wilc_wfi_deinit_mon_interface(void)
}
wilc_wfi_mon = NULL;
}
- return 0;
}
diff --git a/drivers/staging/wilc1000/wilc_wfi_cfgoperations.h b/drivers/staging/wilc1000/wilc_wfi_cfgoperations.h
index 1858f56..4812c8e 100644
--- a/drivers/staging/wilc1000/wilc_wfi_cfgoperations.h
+++ b/drivers/staging/wilc1000/wilc_wfi_cfgoperations.h
@@ -14,7 +14,7 @@ void wilc_free_wiphy(struct net_device *net);
void wilc_deinit_host_int(struct net_device *net);
int wilc_init_host_int(struct net_device *net);
void wilc_wfi_monitor_rx(u8 *buff, u32 size);
-int wilc_wfi_deinit_mon_interface(void);
+void wilc_wfi_deinit_mon_interface(void);
struct net_device *wilc_wfi_init_mon_interface(const char *name,
struct net_device *real_dev);
void wilc_mgmt_frame_register(struct wiphy *wiphy, struct wireless_dev *wdev,
--
2.7.4

2018-09-19 11:42:49

by Ajay Singh

[permalink] [raw]
Subject: [PATCH 17/29] staging: wilc1000: refactor code to avoid static variables for config parameters

Refactor the code in wilc_wlan_cfg.c file to avoid the use of static
variables. Move the static variables as part of wilc struct and also
dynamically allocating memory for keeping those variables.

Signed-off-by: Ajay Singh <[email protected]>
---
drivers/staging/wilc1000/linux_wlan.c | 12 +-
drivers/staging/wilc1000/wilc_wfi_netdevice.h | 2 +
drivers/staging/wilc1000/wilc_wlan.c | 12 +-
drivers/staging/wilc1000/wilc_wlan.h | 3 +-
drivers/staging/wilc1000/wilc_wlan_cfg.c | 159 +++++++++++++++++---------
drivers/staging/wilc1000/wilc_wlan_cfg.h | 20 +++-
6 files changed, 138 insertions(+), 70 deletions(-)

diff --git a/drivers/staging/wilc1000/linux_wlan.c b/drivers/staging/wilc1000/linux_wlan.c
index d9f927e..8ecd664 100644
--- a/drivers/staging/wilc1000/linux_wlan.c
+++ b/drivers/staging/wilc1000/linux_wlan.c
@@ -161,7 +161,7 @@ void wilc_mac_indicate(struct wilc *wilc)
{
s8 status;

- wilc_wlan_cfg_get_val(WID_STATUS, &status, 1);
+ wilc_wlan_cfg_get_val(wilc, WID_STATUS, &status, 1);
if (wilc->mac_status == MAC_STATUS_INIT) {
wilc->mac_status = status;
complete(&wilc->sync_event);
@@ -677,7 +677,7 @@ static int wilc_wlan_initialize(struct net_device *dev, struct wilc_vif *vif)
int size;
char firmware_ver[20];

- size = wilc_wlan_cfg_get_val(WID_FIRMWARE_VERSION,
+ size = wilc_wlan_cfg_get_val(wl, WID_FIRMWARE_VERSION,
firmware_ver,
sizeof(firmware_ver));
firmware_ver[size] = '\0';
@@ -1035,6 +1035,7 @@ void wilc_netdev_cleanup(struct wilc *wilc)

flush_workqueue(wilc->hif_workqueue);
destroy_workqueue(wilc->hif_workqueue);
+ wilc_wlan_cfg_deinit(wilc);
kfree(wilc);
}
EXPORT_SYMBOL_GPL(wilc_netdev_cleanup);
@@ -1060,6 +1061,9 @@ int wilc_netdev_init(struct wilc **wilc, struct device *dev, int io_type,
if (!wl)
return -ENOMEM;

+ if (wilc_wlan_cfg_init(wl))
+ goto free_wl;
+
*wilc = wl;
wl->io_type = io_type;
wl->hif_func = ops;
@@ -1070,7 +1074,7 @@ int wilc_netdev_init(struct wilc **wilc, struct device *dev, int io_type,

wl->hif_workqueue = create_singlethread_workqueue("WILC_wq");
if (!wl->hif_workqueue)
- goto free_wl;
+ goto free_cfg;

register_inetaddr_notifier(&g_dev_notifier);

@@ -1139,6 +1143,8 @@ int wilc_netdev_init(struct wilc **wilc, struct device *dev, int io_type,
}
unregister_inetaddr_notifier(&g_dev_notifier);
destroy_workqueue(wl->hif_workqueue);
+free_cfg:
+ wilc_wlan_cfg_deinit(wl);
free_wl:
kfree(wl);
return -ENOMEM;
diff --git a/drivers/staging/wilc1000/wilc_wfi_netdevice.h b/drivers/staging/wilc1000/wilc_wfi_netdevice.h
index 70bae3a..484c265 100644
--- a/drivers/staging/wilc1000/wilc_wfi_netdevice.h
+++ b/drivers/staging/wilc1000/wilc_wfi_netdevice.h
@@ -16,6 +16,7 @@

#include "host_interface.h"
#include "wilc_wlan.h"
+#include "wilc_wlan_cfg.h"

#define FLOW_CONTROL_LOWER_THRESHOLD 128
#define FLOW_CONTROL_UPPER_THRESHOLD 256
@@ -203,6 +204,7 @@ struct wilc {
int clients_count;
struct workqueue_struct *hif_workqueue;
enum chip_ps_states chip_ps_state;
+ struct wilc_cfg cfg;
};

struct wilc_wfi_mon_priv {
diff --git a/drivers/staging/wilc1000/wilc_wlan.c b/drivers/staging/wilc1000/wilc_wlan.c
index 88808d9..0ec0d9b 100644
--- a/drivers/staging/wilc1000/wilc_wlan.c
+++ b/drivers/staging/wilc1000/wilc_wlan.c
@@ -1194,9 +1194,9 @@ int wilc_wlan_cfg_get(struct wilc_vif *vif, int start, u16 wid, int commit,
return ret_size;
}

-int wilc_wlan_cfg_get_val(u16 wid, u8 *buffer, u32 buffer_size)
+int wilc_wlan_cfg_get_val(struct wilc *wl, u16 wid, u8 *buffer, u32 buffer_size)
{
- return wilc_wlan_cfg_get_wid_value(wid, buffer, buffer_size);
+ return wilc_wlan_cfg_get_wid_value(wl, wid, buffer, buffer_size);
}

int wilc_send_config_pkt(struct wilc_vif *vif, u8 mode, struct wid *wids,
@@ -1216,7 +1216,8 @@ int wilc_send_config_pkt(struct wilc_vif *vif, u8 mode, struct wid *wids,
}
}
for (i = 0; i < count; i++) {
- wids[i].size = wilc_wlan_cfg_get_val(wids[i].id,
+ wids[i].size = wilc_wlan_cfg_get_val(vif->wilc,
+ wids[i].id,
wids[i].val,
wids[i].size);
}
@@ -1315,11 +1316,6 @@ int wilc_wlan_init(struct net_device *dev)
goto fail;
}

- if (!wilc_wlan_cfg_init()) {
- ret = -ENOBUFS;
- goto fail;
- }
-
if (!wilc->tx_buffer)
wilc->tx_buffer = kmalloc(LINUX_TX_SIZE, GFP_KERNEL);

diff --git a/drivers/staging/wilc1000/wilc_wlan.h b/drivers/staging/wilc1000/wilc_wlan.h
index 8c49c0c..2766713 100644
--- a/drivers/staging/wilc1000/wilc_wlan.h
+++ b/drivers/staging/wilc1000/wilc_wlan.h
@@ -277,7 +277,8 @@ int wilc_wlan_cfg_set(struct wilc_vif *vif, int start, u16 wid, u8 *buffer,
u32 buffer_size, int commit, u32 drv_handler);
int wilc_wlan_cfg_get(struct wilc_vif *vif, int start, u16 wid, int commit,
u32 drv_handler);
-int wilc_wlan_cfg_get_val(u16 wid, u8 *buffer, u32 buffer_size);
+int wilc_wlan_cfg_get_val(struct wilc *wl, u16 wid, u8 *buffer,
+ u32 buffer_size);
int wilc_wlan_txq_add_mgmt_pkt(struct net_device *dev, void *priv, u8 *buffer,
u32 buffer_size, wilc_tx_complete_func_t func);
void wilc_chip_sleep_manually(struct wilc *wilc);
diff --git a/drivers/staging/wilc1000/wilc_wlan_cfg.c b/drivers/staging/wilc1000/wilc_wlan_cfg.c
index 4434976..8f1e962 100644
--- a/drivers/staging/wilc1000/wilc_wlan_cfg.c
+++ b/drivers/staging/wilc1000/wilc_wlan_cfg.c
@@ -8,6 +8,7 @@
#include "wilc_wlan.h"
#include "wilc_wlan_cfg.h"
#include "coreconfigurator.h"
+#include "wilc_wfi_netdevice.h"

enum cfg_cmd_type {
CFG_BYTE_CMD = 0,
@@ -17,26 +18,18 @@ enum cfg_cmd_type {
CFG_BIN_CMD = 4
};

-struct wilc_mac_cfg {
- u8 mac_address[7];
- u8 firmware_version[129];
- u8 assoc_rsp[256];
-};
-
-static struct wilc_mac_cfg g_mac;
-
-static struct wilc_cfg_byte g_cfg_byte[] = {
+static const struct wilc_cfg_byte g_cfg_byte[] = {
{WID_STATUS, 0},
{WID_RSSI, 0},
{WID_LINKSPEED, 0},
{WID_NIL, 0}
};

-static struct wilc_cfg_hword g_cfg_hword[] = {
+static const struct wilc_cfg_hword g_cfg_hword[] = {
{WID_NIL, 0}
};

-static struct wilc_cfg_word g_cfg_word[] = {
+static const struct wilc_cfg_word g_cfg_word[] = {
{WID_FAILED_COUNT, 0},
{WID_RECEIVED_FRAGMENT_COUNT, 0},
{WID_SUCCESS_FRAME_COUNT, 0},
@@ -45,10 +38,10 @@ static struct wilc_cfg_word g_cfg_word[] = {

};

-static struct wilc_cfg_str g_cfg_str[] = {
- {WID_FIRMWARE_VERSION, g_mac.firmware_version},
- {WID_MAC_ADDR, g_mac.mac_address},
- {WID_ASSOC_RES_INFO, g_mac.assoc_rsp},
+static const struct wilc_cfg_str g_cfg_str[] = {
+ {WID_FIRMWARE_VERSION, NULL},
+ {WID_MAC_ADDR, NULL},
+ {WID_ASSOC_RES_INFO, NULL},
{WID_NIL, NULL}
};

@@ -169,7 +162,7 @@ static int wilc_wlan_cfg_set_bin(u8 *frame, u32 offset, u16 id, u8 *b, u32 size)
********************************************/

#define GET_WID_TYPE(wid) (((wid) >> 12) & 0x7)
-static void wilc_wlan_parse_response_frame(u8 *info, int size)
+static void wilc_wlan_parse_response_frame(struct wilc *wl, u8 *info, int size)
{
u16 wid;
u32 len = 0, i = 0;
@@ -181,11 +174,11 @@ static void wilc_wlan_parse_response_frame(u8 *info, int size)
switch (GET_WID_TYPE(wid)) {
case WID_CHAR:
do {
- if (g_cfg_byte[i].id == WID_NIL)
+ if (wl->cfg.b[i].id == WID_NIL)
break;

- if (g_cfg_byte[i].id == wid) {
- g_cfg_byte[i].val = info[4];
+ if (wl->cfg.b[i].id == wid) {
+ wl->cfg.b[i].val = info[4];
break;
}
i++;
@@ -195,12 +188,12 @@ static void wilc_wlan_parse_response_frame(u8 *info, int size)

case WID_SHORT:
do {
- if (g_cfg_hword[i].id == WID_NIL)
+ if (wl->cfg.hw[i].id == WID_NIL)
break;

- if (g_cfg_hword[i].id == wid) {
- g_cfg_hword[i].val = (info[4] |
- (info[5] << 8));
+ if (wl->cfg.hw[i].id == wid) {
+ wl->cfg.hw[i].val = (info[4] |
+ (info[5] << 8));
break;
}
i++;
@@ -210,14 +203,14 @@ static void wilc_wlan_parse_response_frame(u8 *info, int size)

case WID_INT:
do {
- if (g_cfg_word[i].id == WID_NIL)
+ if (wl->cfg.w[i].id == WID_NIL)
break;

- if (g_cfg_word[i].id == wid) {
- g_cfg_word[i].val = (info[4] |
- (info[5] << 8) |
- (info[6] << 16) |
- (info[7] << 24));
+ if (wl->cfg.w[i].id == wid) {
+ wl->cfg.w[i].val = (info[4] |
+ (info[5] << 8) |
+ (info[6] << 16) |
+ (info[7] << 24));
break;
}
i++;
@@ -227,11 +220,11 @@ static void wilc_wlan_parse_response_frame(u8 *info, int size)

case WID_STR:
do {
- if (g_cfg_str[i].id == WID_NIL)
+ if (wl->cfg.s[i].id == WID_NIL)
break;

- if (g_cfg_str[i].id == wid) {
- memcpy(g_cfg_str[i].str, &info[2],
+ if (wl->cfg.s[i].id == wid) {
+ memcpy(wl->cfg.s[i].str, &info[2],
(info[2] + 2));
break;
}
@@ -248,7 +241,7 @@ static void wilc_wlan_parse_response_frame(u8 *info, int size)
}
}

-static void wilc_wlan_parse_info_frame(u8 *info)
+static void wilc_wlan_parse_info_frame(struct wilc *wl, u8 *info)
{
u32 wid, len;

@@ -260,11 +253,11 @@ static void wilc_wlan_parse_info_frame(u8 *info)
int i = 0;

do {
- if (g_cfg_byte[i].id == WID_NIL)
+ if (wl->cfg.b[i].id == WID_NIL)
break;

- if (g_cfg_byte[i].id == wid) {
- g_cfg_byte[i].val = info[3];
+ if (wl->cfg.b[i].id == wid) {
+ wl->cfg.b[i].val = info[3];
break;
}
i++;
@@ -328,7 +321,8 @@ int wilc_wlan_cfg_get_wid(u8 *frame, u32 offset, u16 id)
return 2;
}

-int wilc_wlan_cfg_get_wid_value(u16 wid, u8 *buffer, u32 buffer_size)
+int wilc_wlan_cfg_get_wid_value(struct wilc *wl, u16 wid, u8 *buffer,
+ u32 buffer_size)
{
u32 type = (wid >> 12) & 0xf;
int i, ret = 0;
@@ -336,11 +330,11 @@ int wilc_wlan_cfg_get_wid_value(u16 wid, u8 *buffer, u32 buffer_size)
i = 0;
if (type == CFG_BYTE_CMD) {
do {
- if (g_cfg_byte[i].id == WID_NIL)
+ if (wl->cfg.b[i].id == WID_NIL)
break;

- if (g_cfg_byte[i].id == wid) {
- memcpy(buffer, &g_cfg_byte[i].val, 1);
+ if (wl->cfg.b[i].id == wid) {
+ memcpy(buffer, &wl->cfg.b[i].val, 1);
ret = 1;
break;
}
@@ -348,11 +342,11 @@ int wilc_wlan_cfg_get_wid_value(u16 wid, u8 *buffer, u32 buffer_size)
} while (1);
} else if (type == CFG_HWORD_CMD) {
do {
- if (g_cfg_hword[i].id == WID_NIL)
+ if (wl->cfg.hw[i].id == WID_NIL)
break;

- if (g_cfg_hword[i].id == wid) {
- memcpy(buffer, &g_cfg_hword[i].val, 2);
+ if (wl->cfg.hw[i].id == wid) {
+ memcpy(buffer, &wl->cfg.hw[i].val, 2);
ret = 2;
break;
}
@@ -360,11 +354,11 @@ int wilc_wlan_cfg_get_wid_value(u16 wid, u8 *buffer, u32 buffer_size)
} while (1);
} else if (type == CFG_WORD_CMD) {
do {
- if (g_cfg_word[i].id == WID_NIL)
+ if (wl->cfg.w[i].id == WID_NIL)
break;

- if (g_cfg_word[i].id == wid) {
- memcpy(buffer, &g_cfg_word[i].val, 4);
+ if (wl->cfg.w[i].id == wid) {
+ memcpy(buffer, &wl->cfg.w[i].val, 4);
ret = 4;
break;
}
@@ -372,17 +366,17 @@ int wilc_wlan_cfg_get_wid_value(u16 wid, u8 *buffer, u32 buffer_size)
} while (1);
} else if (type == CFG_STR_CMD) {
do {
- u32 id = g_cfg_str[i].id;
+ u32 id = wl->cfg.s[i].id;

if (id == WID_NIL)
break;

if (id == wid) {
- u32 size = g_cfg_str[i].str[0] |
- (g_cfg_str[i].str[1] << 8);
+ u32 size = (wl->cfg.s[i].str[0] |
+ (wl->cfg.s[i].str[1] << 8));

if (buffer_size >= size) {
- memcpy(buffer, &g_cfg_str[i].str[2],
+ memcpy(buffer, &wl->cfg.s[i].str[2],
size);
ret = size;
}
@@ -391,7 +385,6 @@ int wilc_wlan_cfg_get_wid_value(u16 wid, u8 *buffer, u32 buffer_size)
i++;
} while (1);
}
-
return ret;
}

@@ -416,13 +409,13 @@ void wilc_wlan_cfg_indicate_rx(struct wilc *wilc, u8 *frame, int size,

switch (msg_type) {
case 'R':
- wilc_wlan_parse_response_frame(frame, size);
+ wilc_wlan_parse_response_frame(wilc, frame, size);
rsp->type = WILC_CFG_RSP;
rsp->seq_no = msg_id;
break;

case 'I':
- wilc_wlan_parse_info_frame(frame);
+ wilc_wlan_parse_info_frame(wilc, frame);
rsp->type = WILC_CFG_RSP_STATUS;
rsp->seq_no = msg_id;
/*call host interface info parse as well*/
@@ -443,8 +436,62 @@ void wilc_wlan_cfg_indicate_rx(struct wilc *wilc, u8 *frame, int size,
}
}

-int wilc_wlan_cfg_init(void)
+int wilc_wlan_cfg_init(struct wilc *wl)
+{
+ struct wilc_mac_cfg *mac_cfg;
+ int i = 0;
+
+ wl->cfg.b = kmemdup(g_cfg_byte, sizeof(g_cfg_byte), GFP_KERNEL);
+ if (!wl->cfg.b)
+ return -ENOMEM;
+
+ wl->cfg.hw = kmemdup(g_cfg_hword, sizeof(g_cfg_hword), GFP_KERNEL);
+ if (!wl->cfg.hw)
+ goto out_b;
+
+ wl->cfg.w = kmemdup(g_cfg_word, sizeof(g_cfg_word), GFP_KERNEL);
+ if (!wl->cfg.w)
+ goto out_hw;
+
+ wl->cfg.s = kmemdup(g_cfg_str, sizeof(g_cfg_str), GFP_KERNEL);
+ if (!wl->cfg.s)
+ goto out_w;
+
+ mac_cfg = kzalloc(sizeof(mac_cfg), GFP_KERNEL);
+ if (!mac_cfg)
+ goto out_s;
+
+ wl->cfg.str_vals = mac_cfg;
+ /* store the string cfg parameters */
+ wl->cfg.s[i].id = WID_FIRMWARE_VERSION;
+ wl->cfg.s[i].str = mac_cfg->firmware_version;
+ i++;
+ wl->cfg.s[i].id = WID_MAC_ADDR;
+ wl->cfg.s[i].str = mac_cfg->mac_address;
+ i++;
+ wl->cfg.s[i].id = WID_ASSOC_RES_INFO;
+ wl->cfg.s[i].str = mac_cfg->assoc_rsp;
+ i++;
+ wl->cfg.s[i].id = WID_NIL;
+ wl->cfg.s[i].str = NULL;
+ return 0;
+
+out_s:
+ kfree(wl->cfg.s);
+out_w:
+ kfree(wl->cfg.w);
+out_hw:
+ kfree(wl->cfg.hw);
+out_b:
+ kfree(wl->cfg.b);
+ return -ENOMEM;
+}
+
+void wilc_wlan_cfg_deinit(struct wilc *wl)
{
- memset((void *)&g_mac, 0, sizeof(struct wilc_mac_cfg));
- return 1;
+ kfree(wl->cfg.b);
+ kfree(wl->cfg.hw);
+ kfree(wl->cfg.w);
+ kfree(wl->cfg.s);
+ kfree(wl->cfg.str_vals);
}
diff --git a/drivers/staging/wilc1000/wilc_wlan_cfg.h b/drivers/staging/wilc1000/wilc_wlan_cfg.h
index 082093f..176eef1 100644
--- a/drivers/staging/wilc1000/wilc_wlan_cfg.h
+++ b/drivers/staging/wilc1000/wilc_wlan_cfg.h
@@ -27,12 +27,28 @@ struct wilc_cfg_str {
u8 *str;
};

+struct wilc_mac_cfg {
+ u8 mac_address[7];
+ u8 firmware_version[129];
+ u8 assoc_rsp[256];
+};
+
+struct wilc_cfg {
+ struct wilc_cfg_byte *b;
+ struct wilc_cfg_hword *hw;
+ struct wilc_cfg_word *w;
+ struct wilc_cfg_str *s;
+ struct wilc_mac_cfg *str_vals;
+};
+
struct wilc;
int wilc_wlan_cfg_set_wid(u8 *frame, u32 offset, u16 id, u8 *buf, int size);
int wilc_wlan_cfg_get_wid(u8 *frame, u32 offset, u16 id);
-int wilc_wlan_cfg_get_wid_value(u16 wid, u8 *buffer, u32 buffer_size);
+int wilc_wlan_cfg_get_wid_value(struct wilc *wl, u16 wid, u8 *buffer,
+ u32 buffer_size);
void wilc_wlan_cfg_indicate_rx(struct wilc *wilc, u8 *frame, int size,
struct wilc_cfg_rsp *rsp);
-int wilc_wlan_cfg_init(void);
+int wilc_wlan_cfg_init(struct wilc *wl);
+void wilc_wlan_cfg_deinit(struct wilc *wl);

#endif
--
2.7.4

2018-09-19 11:42:56

by Ajay Singh

[permalink] [raw]
Subject: [PATCH 19/29] staging: wilc1000: avoid the use of 'hif_driver_comp' completion variable

Instead of using extra completion variable to handle the sync call now
using msg->is_sync flag to handle the sync call.

Signed-off-by: Ajay Singh <[email protected]>
---
drivers/staging/wilc1000/host_interface.c | 23 +++++++++++------------
drivers/staging/wilc1000/host_interface.h | 2 +-
drivers/staging/wilc1000/linux_wlan.c | 3 ++-
drivers/staging/wilc1000/wilc_wfi_cfgoperations.c | 2 +-
4 files changed, 15 insertions(+), 15 deletions(-)

diff --git a/drivers/staging/wilc1000/host_interface.c b/drivers/staging/wilc1000/host_interface.c
index 237a098d..529390d 100644
--- a/drivers/staging/wilc1000/host_interface.c
+++ b/drivers/staging/wilc1000/host_interface.c
@@ -187,7 +187,6 @@ struct join_bss_param {
};

static struct host_if_drv *terminated_handle;
-static struct completion hif_driver_comp;
static struct mutex hif_deinit_lock;

/* 'msg' should be free by the caller for syc */
@@ -310,10 +309,12 @@ static void handle_set_wfi_drv_handler(struct work_struct *work)
if (ret)
netdev_err(vif->ndev, "Failed to set driver handler\n");

- complete(&hif_driver_comp);
kfree(buffer);

free_msg:
+ if (msg->is_sync)
+ complete(&msg->work_comp);
+
kfree(msg);
}

@@ -333,9 +334,6 @@ static void handle_set_operation_mode(struct work_struct *work)
ret = wilc_send_config_pkt(vif, SET_CFG, &wid, 1,
wilc_get_vif_idx(vif));

- if (hif_op_mode->mode == IDLE_MODE)
- complete(&hif_driver_comp);
-
if (ret)
netdev_err(vif->ndev, "Failed to set operation mode\n");

@@ -3118,12 +3116,12 @@ int wilc_set_mac_chnl_num(struct wilc_vif *vif, u8 channel)
}

int wilc_set_wfi_drv_handler(struct wilc_vif *vif, int index, u8 mode,
- u8 ifc_id)
+ u8 ifc_id, bool is_sync)
{
int result;
struct host_if_msg *msg;

- msg = wilc_alloc_work(vif, handle_set_wfi_drv_handler, false);
+ msg = wilc_alloc_work(vif, handle_set_wfi_drv_handler, is_sync);
if (IS_ERR(msg))
return PTR_ERR(msg);

@@ -3135,8 +3133,12 @@ int wilc_set_wfi_drv_handler(struct wilc_vif *vif, int index, u8 mode,
if (result) {
netdev_err(vif->ndev, "%s: enqueue work failed\n", __func__);
kfree(msg);
+ return result;
}

+ if (is_sync)
+ wait_for_completion(&msg->work_comp);
+
return result;
}

@@ -3380,10 +3382,8 @@ int wilc_init(struct net_device *dev, struct host_if_drv **hif_drv_handler)

vif->obtaining_ip = false;

- if (wilc->clients_count == 0) {
- init_completion(&hif_driver_comp);
+ if (wilc->clients_count == 0)
mutex_init(&hif_deinit_lock);
- }

timer_setup(&vif->periodic_rssi, get_periodic_rssi, 0);
mod_timer(&vif->periodic_rssi, jiffies + msecs_to_jiffies(5000));
@@ -3430,8 +3430,7 @@ int wilc_deinit(struct wilc_vif *vif)
del_timer_sync(&vif->periodic_rssi);
del_timer_sync(&hif_drv->remain_on_ch_timer);

- wilc_set_wfi_drv_handler(vif, 0, 0, 0);
- wait_for_completion(&hif_driver_comp);
+ wilc_set_wfi_drv_handler(vif, 0, 0, 0, true);

if (hif_drv->usr_scan_req.scan_result) {
hif_drv->usr_scan_req.scan_result(SCAN_EVENT_ABORTED, NULL,
diff --git a/drivers/staging/wilc1000/host_interface.h b/drivers/staging/wilc1000/host_interface.h
index 15ffaeb..4416f8f 100644
--- a/drivers/staging/wilc1000/host_interface.h
+++ b/drivers/staging/wilc1000/host_interface.h
@@ -350,7 +350,7 @@ int wilc_remain_on_channel(struct wilc_vif *vif, u32 session_id,
int wilc_listen_state_expired(struct wilc_vif *vif, u32 session_id);
void wilc_frame_register(struct wilc_vif *vif, u16 frame_type, bool reg);
int wilc_set_wfi_drv_handler(struct wilc_vif *vif, int index, u8 mode,
- u8 ifc_id);
+ u8 ifc_id, bool is_sync);
int wilc_set_operation_mode(struct wilc_vif *vif, u32 mode);
int wilc_get_statistics(struct wilc_vif *vif, struct rf_info *stats,
bool is_sync);
diff --git a/drivers/staging/wilc1000/linux_wlan.c b/drivers/staging/wilc1000/linux_wlan.c
index 8ecd664..b666e1e 100644
--- a/drivers/staging/wilc1000/linux_wlan.c
+++ b/drivers/staging/wilc1000/linux_wlan.c
@@ -753,7 +753,8 @@ static int wilc_mac_open(struct net_device *ndev)
for (i = 0; i < wl->vif_num; i++) {
if (ndev == wl->vif[i]->ndev) {
wilc_set_wfi_drv_handler(vif, wilc_get_vif_idx(vif),
- vif->iftype, vif->ifc_id);
+ vif->iftype, vif->ifc_id,
+ false);
wilc_set_operation_mode(vif, vif->iftype);
break;
}
diff --git a/drivers/staging/wilc1000/wilc_wfi_cfgoperations.c b/drivers/staging/wilc1000/wilc_wfi_cfgoperations.c
index 02a8846..76d017d 100644
--- a/drivers/staging/wilc1000/wilc_wfi_cfgoperations.c
+++ b/drivers/staging/wilc1000/wilc_wfi_cfgoperations.c
@@ -1779,7 +1779,7 @@ static int change_virtual_intf(struct wiphy *wiphy, struct net_device *dev,

if (wl->initialized) {
wilc_set_wfi_drv_handler(vif, wilc_get_vif_idx(vif),
- 0, vif->ifc_id);
+ 0, vif->ifc_id, false);
wilc_set_operation_mode(vif, AP_MODE);
wilc_set_power_mgmt(vif, 0, 0);
}
--
2.7.4

2018-09-19 16:42:10

by Ajay Singh

[permalink] [raw]
Subject: Re: [PATCH 29/29] staging: wilc1000: return exact error of register_netdev() from wilc_netdev_init()

Hi Dan,

Thanks your reviewing the patch.

On Wed, 19 Sep 2018 12:41:32 +0300
Dan Carpenter <[email protected]> wrote:

> I was waiting for you to send this like a spider waits for flies. You
> fell directly into my trap. Mwuahahahahaha.

Oops!!! I missed seeing it coming :)

>
> drivers/staging/wilc1000/linux_wlan.c
> 1056 int wilc_netdev_init(struct wilc **wilc, struct device *dev,
> int io_type, 1057 const struct wilc_hif_func
> *ops) 1058 {
> 1059 int i, ret = -ENOMEM;
> 1060 struct wilc_vif *vif;
> 1061 struct net_device *ndev;
> 1062 struct wilc *wl;
> 1063
> 1064 wl = kzalloc(sizeof(*wl), GFP_KERNEL);
> 1065 if (!wl)
> 1066 return ret;
> ^^^
> It's cleaner to return -ENOMEM so that we don't have to glance up to
> the declaration block. This is especially true when "ret" is zero,
> btw, because that can indicate a reversed test.

I will change it to directly return -ENOMEM value.

>
> if (!ret)
> return ret;
>
> In this theoretically example it was supposed to be:
>
> if (ret)
> return ret;
>
> Normally, reversed conditions are caught in testing, but for the
> kernel, no one has the hardware to test everything so we do get
> reversed conditions from time to time.
>
> 1067
> 1068 if (wilc_wlan_cfg_init(wl))

I will set 'ret' value to -ENOMEM here also.

> 1069 goto free_wl;
> 1070
> 1071 *wilc = wl;
> 1072 wl->io_type = io_type;
> 1073 wl->hif_func = ops;
> 1074 wl->enable_ps = true;
> 1075 wl->chip_ps_state = CHIP_WAKEDUP;
> 1076 INIT_LIST_HEAD(&wl->txq_head.list);
> 1077 INIT_LIST_HEAD(&wl->rxq_head.list);
> 1078
> 1079 wl->hif_workqueue =
> create_singlethread_workqueue("WILC_wq"); 1080 if
> (!wl->hif_workqueue) 1081 goto free_cfg;
> 1082
> 1083 register_inetaddr_notifier(&g_dev_notifier);
> 1084
> 1085 for (i = 0; i < NUM_CONCURRENT_IFC; i++) {
> 1086 struct wireless_dev *wdev;
> 1087
> 1088 ndev = alloc_etherdev(sizeof(struct
> wilc_vif)); 1089 if (!ndev)
> 1090 goto free_ndev;
> ^^^^^^^^^^^^^^^
> ret is zero on the second iteration through the loop.

I will set 'ret' to -ENOMEM before 'goto', which should handle this
scenario.

>
> 1091
> 1092 vif = netdev_priv(ndev);
> 1093 memset(vif, 0, sizeof(struct wilc_vif));
> 1094
> 1095 if (i == 0) {
> 1096 strcpy(ndev->name, "wlan%d");
> 1097 vif->ifc_id = 1;
> 1098 } else {
> 1099 strcpy(ndev->name, "p2p%d");
> 1100 vif->ifc_id = 0;
> 1101 }
> 1102 vif->wilc = *wilc;
> 1103 vif->ndev = ndev;
> 1104 wl->vif[i] = vif;
> 1105 wl->vif_num = i;
> 1106 vif->idx = wl->vif_num;
> 1107
> 1108 ndev->netdev_ops = &wilc_netdev_ops;
> 1109
> 1110 wdev = wilc_create_wiphy(ndev, dev);
> 1111 if (!wdev) {
> 1112 netdev_err(ndev, "Can't register WILC
> Wiphy\n"); 1113 goto free_ndev;
> ^^^^^^^^^^^^^^^
> Here too.

Same here, i.e setting ret = -ENOMEM should handle the condition.

Also I will remove the default setting of 'ret' value to -ENOMEM because
after modification the error scenarios will set 'ret' explicitly.

Regards,
Ajay

2018-09-19 11:43:18

by Ajay Singh

[permalink] [raw]
Subject: [PATCH 25/29] staging: wilc1000: remove wilc_debugfs.c file as its not used

Deleted wilc_debugfs.c file as it's not used.

Earlier discussion link:
[1]. https://www.spinics.net/lists/linux-wireless/msg176076.html

Suggested-by: Greg KH <[email protected]>
Signed-off-by: Ajay Singh <[email protected]>
---
drivers/staging/wilc1000/Makefile | 5 +-
drivers/staging/wilc1000/wilc_debugfs.c | 115 --------------------------------
2 files changed, 2 insertions(+), 118 deletions(-)
delete mode 100644 drivers/staging/wilc1000/wilc_debugfs.c

diff --git a/drivers/staging/wilc1000/Makefile b/drivers/staging/wilc1000/Makefile
index ee7e26b..5718bc4 100644
--- a/drivers/staging/wilc1000/Makefile
+++ b/drivers/staging/wilc1000/Makefile
@@ -4,12 +4,11 @@ obj-$(CONFIG_WILC1000) += wilc1000.o
ccflags-y += -DFIRMWARE_1002=\"atmel/wilc1002_firmware.bin\" \
-DFIRMWARE_1003=\"atmel/wilc1003_firmware.bin\"

-ccflags-y += -I$(src)/ -DWILC_ASIC_A0 -DWILC_DEBUGFS
+ccflags-y += -I$(src)/ -DWILC_ASIC_A0

wilc1000-objs := wilc_wfi_cfgoperations.o linux_wlan.o linux_mon.o \
coreconfigurator.o host_interface.o \
- wilc_wlan_cfg.o wilc_debugfs.o \
- wilc_wlan.o
+ wilc_wlan_cfg.o wilc_wlan.o

obj-$(CONFIG_WILC1000_SDIO) += wilc1000-sdio.o
wilc1000-sdio-objs += wilc_sdio.o
diff --git a/drivers/staging/wilc1000/wilc_debugfs.c b/drivers/staging/wilc1000/wilc_debugfs.c
deleted file mode 100644
index 8001df6..0000000
--- a/drivers/staging/wilc1000/wilc_debugfs.c
+++ /dev/null
@@ -1,115 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0
-/*
- * Copyright (c) 2012 - 2018 Microchip Technology Inc., and its subsidiaries.
- * All rights reserved.
- */
-
-#if defined(WILC_DEBUGFS)
-#include <linux/module.h>
-#include <linux/debugfs.h>
-
-#include "wilc_wlan_if.h"
-
-static struct dentry *wilc_dir;
-
-#define DEBUG BIT(0)
-#define INFO BIT(1)
-#define WRN BIT(2)
-#define ERR BIT(3)
-
-#define DBG_LEVEL_ALL (DEBUG | INFO | WRN | ERR)
-static atomic_t WILC_DEBUG_LEVEL = ATOMIC_INIT(ERR);
-EXPORT_SYMBOL_GPL(WILC_DEBUG_LEVEL);
-
-static ssize_t wilc_debug_level_read(struct file *file, char __user *userbuf,
- size_t count, loff_t *ppos)
-{
- char buf[128];
- int res = 0;
-
- /* only allow read from start */
- if (*ppos > 0)
- return 0;
-
- res = scnprintf(buf, sizeof(buf), "Debug Level: %x\n",
- atomic_read(&WILC_DEBUG_LEVEL));
-
- return simple_read_from_buffer(userbuf, count, ppos, buf, res);
-}
-
-static ssize_t wilc_debug_level_write(struct file *filp,
- const char __user *buf, size_t count,
- loff_t *ppos)
-{
- int flag = 0;
- int ret;
-
- ret = kstrtouint_from_user(buf, count, 16, &flag);
- if (ret)
- return ret;
-
- if (flag > DBG_LEVEL_ALL) {
- pr_info("%s, value (0x%08x) is out of range, stay previous flag (0x%08x)\n",
- __func__, flag, atomic_read(&WILC_DEBUG_LEVEL));
- return -EINVAL;
- }
-
- atomic_set(&WILC_DEBUG_LEVEL, (int)flag);
-
- if (flag == 0)
- pr_info("Debug-level disabled\n");
- else
- pr_info("Debug-level enabled\n");
-
- return count;
-}
-
-#define FOPS(_open, _read, _write, _poll) { \
- .owner = THIS_MODULE, \
- .open = (_open), \
- .read = (_read), \
- .write = (_write), \
- .poll = (_poll), \
-}
-
-struct wilc_debugfs_info_t {
- const char *name;
- int perm;
- unsigned int data;
- const struct file_operations fops;
-};
-
-static struct wilc_debugfs_info_t debugfs_info[] = {
- {
- "wilc_debug_level",
- 0666,
- (DEBUG | ERR),
- FOPS(NULL, wilc_debug_level_read, wilc_debug_level_write, NULL),
- },
-};
-
-static int __init wilc_debugfs_init(void)
-{
- int i;
- struct wilc_debugfs_info_t *info;
-
- wilc_dir = debugfs_create_dir("wilc_wifi", NULL);
- for (i = 0; i < ARRAY_SIZE(debugfs_info); i++) {
- info = &debugfs_info[i];
- debugfs_create_file(info->name,
- info->perm,
- wilc_dir,
- &info->data,
- &info->fops);
- }
- return 0;
-}
-module_init(wilc_debugfs_init);
-
-static void __exit wilc_debugfs_remove(void)
-{
- debugfs_remove_recursive(wilc_dir);
-}
-module_exit(wilc_debugfs_remove);
-
-#endif
--
2.7.4

2018-09-19 11:42:29

by Ajay Singh

[permalink] [raw]
Subject: [PATCH 11/29] staging: wilc1000: refactor wilc_wlan_parse_info_frame() function

Return 'void' from wilc_wlan_parse_info_frame() as same constant value
is returned always. Also removed the 'size' from input parameter as its
not used in the function.

Signed-off-by: Ajay Singh <[email protected]>
---
drivers/staging/wilc1000/wilc_wlan_cfg.c | 12 ++++--------
1 file changed, 4 insertions(+), 8 deletions(-)

diff --git a/drivers/staging/wilc1000/wilc_wlan_cfg.c b/drivers/staging/wilc1000/wilc_wlan_cfg.c
index 42c64ed..2b5471b 100644
--- a/drivers/staging/wilc1000/wilc_wlan_cfg.c
+++ b/drivers/staging/wilc1000/wilc_wlan_cfg.c
@@ -350,22 +350,17 @@ static void wilc_wlan_parse_response_frame(u8 *info, int size)
}
}

-static int wilc_wlan_parse_info_frame(u8 *info, int size)
+static void wilc_wlan_parse_info_frame(u8 *info)
{
struct wilc_mac_cfg *pd = &g_mac;
u32 wid, len;
- int type = WILC_CFG_RSP_STATUS;

wid = info[0] | (info[1] << 8);

len = info[2];

- if (len == 1 && wid == WID_STATUS) {
+ if (len == 1 && wid == WID_STATUS)
pd->mac_status = info[3];
- type = WILC_CFG_RSP_STATUS;
- }
-
- return type;
}

/********************************************
@@ -528,7 +523,8 @@ void wilc_wlan_cfg_indicate_rx(struct wilc *wilc, u8 *frame, int size,
break;

case 'I':
- rsp->type = wilc_wlan_parse_info_frame(frame, size);
+ wilc_wlan_parse_info_frame(frame);
+ rsp->type = WILC_CFG_RSP_STATUS;
rsp->seq_no = msg_id;
/*call host interface info parse as well*/
wilc_gnrl_async_info_received(wilc, frame - 4, size + 4);
--
2.7.4

2018-09-19 11:41:53

by Ajay Singh

[permalink] [raw]
Subject: [PATCH 01/29] staging: wilc1000: change return type to 'void' for wilc_frame_register()

Cleanup patch to use 'void' return type for wilc_frame_register(), as
its return value is not used.

Signed-off-by: Ajay Singh <[email protected]>
---
drivers/staging/wilc1000/host_interface.c | 6 ++----
drivers/staging/wilc1000/host_interface.h | 2 +-
2 files changed, 3 insertions(+), 5 deletions(-)

diff --git a/drivers/staging/wilc1000/host_interface.c b/drivers/staging/wilc1000/host_interface.c
index 5388be9..7729f83 100644
--- a/drivers/staging/wilc1000/host_interface.c
+++ b/drivers/staging/wilc1000/host_interface.c
@@ -3641,14 +3641,14 @@ int wilc_listen_state_expired(struct wilc_vif *vif, u32 session_id)
return result;
}

-int wilc_frame_register(struct wilc_vif *vif, u16 frame_type, bool reg)
+void wilc_frame_register(struct wilc_vif *vif, u16 frame_type, bool reg)
{
int result;
struct host_if_msg *msg;

msg = wilc_alloc_work(vif, handle_register_frame, false);
if (IS_ERR(msg))
- return PTR_ERR(msg);
+ return;

switch (frame_type) {
case ACTION:
@@ -3670,8 +3670,6 @@ int wilc_frame_register(struct wilc_vif *vif, u16 frame_type, bool reg)
netdev_err(vif->ndev, "%s: enqueue work failed\n", __func__);
kfree(msg);
}
-
- return result;
}

int wilc_add_beacon(struct wilc_vif *vif, u32 interval, u32 dtim_period,
diff --git a/drivers/staging/wilc1000/host_interface.h b/drivers/staging/wilc1000/host_interface.h
index a48818f..15ffaeb 100644
--- a/drivers/staging/wilc1000/host_interface.h
+++ b/drivers/staging/wilc1000/host_interface.h
@@ -348,7 +348,7 @@ int wilc_remain_on_channel(struct wilc_vif *vif, u32 session_id,
wilc_remain_on_chan_ready ready,
void *user_arg);
int wilc_listen_state_expired(struct wilc_vif *vif, u32 session_id);
-int wilc_frame_register(struct wilc_vif *vif, u16 frame_type, bool reg);
+void wilc_frame_register(struct wilc_vif *vif, u16 frame_type, bool reg);
int wilc_set_wfi_drv_handler(struct wilc_vif *vif, int index, u8 mode,
u8 ifc_id);
int wilc_set_operation_mode(struct wilc_vif *vif, u32 mode);
--
2.7.4

2018-09-19 11:43:04

by Ajay Singh

[permalink] [raw]
Subject: [PATCH 21/29] staging: wilc1000: avoid use of 'g_sdio' static variable

Instead of using static variable 'g_sdio' move it as part of 'wilc'
struct. Also allocating the memory in the probe function and free during
deinitialization.

Signed-off-by: Ajay Singh <[email protected]>
---
drivers/staging/wilc1000/linux_wlan.c | 1 +
drivers/staging/wilc1000/wilc_sdio.c | 54 +++++++++++++++++----------
drivers/staging/wilc1000/wilc_wfi_netdevice.h | 1 +
3 files changed, 36 insertions(+), 20 deletions(-)

diff --git a/drivers/staging/wilc1000/linux_wlan.c b/drivers/staging/wilc1000/linux_wlan.c
index b666e1e..560c168 100644
--- a/drivers/staging/wilc1000/linux_wlan.c
+++ b/drivers/staging/wilc1000/linux_wlan.c
@@ -1037,6 +1037,7 @@ void wilc_netdev_cleanup(struct wilc *wilc)
flush_workqueue(wilc->hif_workqueue);
destroy_workqueue(wilc->hif_workqueue);
wilc_wlan_cfg_deinit(wilc);
+ kfree(wilc->bus_data);
kfree(wilc);
}
EXPORT_SYMBOL_GPL(wilc_netdev_cleanup);
diff --git a/drivers/staging/wilc1000/wilc_sdio.c b/drivers/staging/wilc1000/wilc_sdio.c
index b2080d8..7ef047c 100644
--- a/drivers/staging/wilc1000/wilc_sdio.c
+++ b/drivers/staging/wilc1000/wilc_sdio.c
@@ -30,7 +30,6 @@ struct wilc_sdio {
int has_thrpt_enh3;
};

-static struct wilc_sdio g_sdio;
static const struct wilc_hif_func wilc_hif_sdio;

static int sdio_write_reg(struct wilc *wilc, u32 addr, u32 data);
@@ -109,6 +108,11 @@ static int linux_sdio_probe(struct sdio_func *func,
struct wilc *wilc;
int ret;
struct gpio_desc *gpio = NULL;
+ struct wilc_sdio *sdio_priv;
+
+ sdio_priv = kzalloc(sizeof(*sdio_priv), GFP_KERNEL);
+ if (!sdio_priv)
+ return -ENOMEM;

if (IS_ENABLED(CONFIG_WILC1000_HW_OOB_INTR)) {
gpio = gpiod_get(&func->dev, "irq", GPIOD_IN);
@@ -124,9 +128,11 @@ static int linux_sdio_probe(struct sdio_func *func,
ret = wilc_netdev_init(&wilc, &func->dev, HIF_SDIO, &wilc_hif_sdio);
if (ret) {
dev_err(&func->dev, "Couldn't initialize netdev\n");
+ kfree(sdio_priv);
return ret;
}
sdio_set_drvdata(func, wilc);
+ wilc->bus_data = sdio_priv;
wilc->dev = &func->dev;
wilc->gpio_irq = gpio;

@@ -381,6 +387,7 @@ static int sdio_set_func1_block_size(struct wilc *wilc, u32 block_size)
static int sdio_write_reg(struct wilc *wilc, u32 addr, u32 data)
{
struct sdio_func *func = dev_to_sdio_func(wilc->dev);
+ struct wilc_sdio *sdio_priv = wilc->bus_data;
int ret;

cpu_to_le32s(&data);
@@ -415,7 +422,7 @@ static int sdio_write_reg(struct wilc *wilc, u32 addr, u32 data)
cmd.increment = 1;
cmd.count = 4;
cmd.buffer = (u8 *)&data;
- cmd.block_size = g_sdio.block_size;
+ cmd.block_size = sdio_priv->block_size;
ret = wilc_sdio_cmd53(wilc, &cmd);
if (ret) {
dev_err(&func->dev,
@@ -434,7 +441,8 @@ static int sdio_write_reg(struct wilc *wilc, u32 addr, u32 data)
static int sdio_write(struct wilc *wilc, u32 addr, u8 *buf, u32 size)
{
struct sdio_func *func = dev_to_sdio_func(wilc->dev);
- u32 block_size = g_sdio.block_size;
+ struct wilc_sdio *sdio_priv = wilc->bus_data;
+ u32 block_size = sdio_priv->block_size;
struct sdio_cmd53 cmd;
int nblk, nleft, ret;

@@ -523,6 +531,7 @@ static int sdio_write(struct wilc *wilc, u32 addr, u8 *buf, u32 size)
static int sdio_read_reg(struct wilc *wilc, u32 addr, u32 *data)
{
struct sdio_func *func = dev_to_sdio_func(wilc->dev);
+ struct wilc_sdio *sdio_priv = wilc->bus_data;
int ret;

if (addr >= 0xf0 && addr <= 0xff) {
@@ -553,7 +562,7 @@ static int sdio_read_reg(struct wilc *wilc, u32 addr, u32 *data)
cmd.count = 4;
cmd.buffer = (u8 *)data;

- cmd.block_size = g_sdio.block_size;
+ cmd.block_size = sdio_priv->block_size;
ret = wilc_sdio_cmd53(wilc, &cmd);
if (ret) {
dev_err(&func->dev,
@@ -574,7 +583,8 @@ static int sdio_read_reg(struct wilc *wilc, u32 addr, u32 *data)
static int sdio_read(struct wilc *wilc, u32 addr, u8 *buf, u32 size)
{
struct sdio_func *func = dev_to_sdio_func(wilc->dev);
- u32 block_size = g_sdio.block_size;
+ struct wilc_sdio *sdio_priv = wilc->bus_data;
+ u32 block_size = sdio_priv->block_size;
struct sdio_cmd53 cmd;
int nblk, nleft, ret;

@@ -674,13 +684,14 @@ static int sdio_deinit(struct wilc *wilc)
static int sdio_init(struct wilc *wilc, bool resume)
{
struct sdio_func *func = dev_to_sdio_func(wilc->dev);
+ struct wilc_sdio *sdio_priv = wilc->bus_data;
struct sdio_cmd52 cmd;
int loop, ret;
u32 chipid;

if (!resume) {
- memset(&g_sdio, 0, sizeof(struct wilc_sdio));
- g_sdio.irq_gpio = wilc->dev_irq_num;
+ memset(sdio_priv, 0, sizeof(struct wilc_sdio));
+ sdio_priv->irq_gpio = wilc->dev_irq_num;
}

/**
@@ -704,7 +715,7 @@ static int sdio_init(struct wilc *wilc, bool resume)
dev_err(&func->dev, "Fail cmd 52, set func 0 block size...\n");
goto fail;
}
- g_sdio.block_size = WILC_SDIO_BLOCK_SIZE;
+ sdio_priv->block_size = WILC_SDIO_BLOCK_SIZE;

/**
* enable func1 IO
@@ -778,11 +789,11 @@ static int sdio_init(struct wilc *wilc, bool resume)
}
dev_err(&func->dev, "chipid (%08x)\n", chipid);
if ((chipid & 0xfff) > 0x2a0)
- g_sdio.has_thrpt_enh3 = 1;
+ sdio_priv->has_thrpt_enh3 = 1;
else
- g_sdio.has_thrpt_enh3 = 0;
+ sdio_priv->has_thrpt_enh3 = 0;
dev_info(&func->dev, "has_thrpt_enh3 = %d...\n",
- g_sdio.has_thrpt_enh3);
+ sdio_priv->has_thrpt_enh3);
}

return 1;
@@ -820,6 +831,7 @@ static int sdio_read_size(struct wilc *wilc, u32 *size)
static int sdio_read_int(struct wilc *wilc, u32 *int_status)
{
struct sdio_func *func = dev_to_sdio_func(wilc->dev);
+ struct wilc_sdio *sdio_priv = wilc->bus_data;
u32 tmp;
struct sdio_cmd52 cmd;

@@ -828,7 +840,7 @@ static int sdio_read_int(struct wilc *wilc, u32 *int_status)
/**
* Read IRQ flags
**/
- if (!g_sdio.irq_gpio) {
+ if (!sdio_priv->irq_gpio) {
int i;

cmd.function = 1;
@@ -848,7 +860,7 @@ static int sdio_read_int(struct wilc *wilc, u32 *int_status)
tmp |= INT_4;
if (cmd.data & BIT(6))
tmp |= INT_5;
- for (i = g_sdio.nint; i < MAX_NUM_INT; i++) {
+ for (i = sdio_priv->nint; i < MAX_NUM_INT; i++) {
if ((tmp >> (IRG_FLAGS_OFFSET + i)) & 0x1) {
dev_err(&func->dev,
"Unexpected interrupt (1) : tmp=%x, data=%x\n",
@@ -877,13 +889,14 @@ static int sdio_read_int(struct wilc *wilc, u32 *int_status)
static int sdio_clear_int_ext(struct wilc *wilc, u32 val)
{
struct sdio_func *func = dev_to_sdio_func(wilc->dev);
+ struct wilc_sdio *sdio_priv = wilc->bus_data;
int ret;
int vmm_ctl;

- if (g_sdio.has_thrpt_enh3) {
+ if (sdio_priv->has_thrpt_enh3) {
u32 reg;

- if (g_sdio.irq_gpio) {
+ if (sdio_priv->irq_gpio) {
u32 flags;

flags = val & (BIT(MAX_NUN_INT_THRPT_ENH2) - 1);
@@ -919,7 +932,7 @@ static int sdio_clear_int_ext(struct wilc *wilc, u32 val)
}
return 1;
}
- if (g_sdio.irq_gpio) {
+ if (sdio_priv->irq_gpio) {
/* has_thrpt_enh2 uses register 0xf8 to clear interrupts. */
/*
* Cannot clear multiple interrupts.
@@ -932,7 +945,7 @@ static int sdio_clear_int_ext(struct wilc *wilc, u32 val)
int i;

ret = 1;
- for (i = 0; i < g_sdio.nint; i++) {
+ for (i = 0; i < sdio_priv->nint; i++) {
if (flags & 1) {
struct sdio_cmd52 cmd;

@@ -956,7 +969,7 @@ static int sdio_clear_int_ext(struct wilc *wilc, u32 val)
}
if (!ret)
goto fail;
- for (i = g_sdio.nint; i < MAX_NUM_INT; i++) {
+ for (i = sdio_priv->nint; i < MAX_NUM_INT; i++) {
if (flags & 1)
dev_err(&func->dev,
"Unexpected interrupt cleared %d...\n",
@@ -1001,6 +1014,7 @@ static int sdio_clear_int_ext(struct wilc *wilc, u32 val)
static int sdio_sync_ext(struct wilc *wilc, int nint)
{
struct sdio_func *func = dev_to_sdio_func(wilc->dev);
+ struct wilc_sdio *sdio_priv = wilc->bus_data;
u32 reg;

if (nint > MAX_NUM_INT) {
@@ -1013,7 +1027,7 @@ static int sdio_sync_ext(struct wilc *wilc, int nint)
return 0;
}

- g_sdio.nint = nint;
+ sdio_priv->nint = nint;

/**
* Disable power sequencer
@@ -1029,7 +1043,7 @@ static int sdio_sync_ext(struct wilc *wilc, int nint)
return 0;
}

- if (g_sdio.irq_gpio) {
+ if (sdio_priv->irq_gpio) {
u32 reg;
int ret, i;

diff --git a/drivers/staging/wilc1000/wilc_wfi_netdevice.h b/drivers/staging/wilc1000/wilc_wfi_netdevice.h
index 484c265..4ba5887 100644
--- a/drivers/staging/wilc1000/wilc_wfi_netdevice.h
+++ b/drivers/staging/wilc1000/wilc_wfi_netdevice.h
@@ -205,6 +205,7 @@ struct wilc {
struct workqueue_struct *hif_workqueue;
enum chip_ps_states chip_ps_state;
struct wilc_cfg cfg;
+ void *bus_data;
};

struct wilc_wfi_mon_priv {
--
2.7.4

2018-09-19 11:43:14

by Ajay Singh

[permalink] [raw]
Subject: [PATCH 24/29] staging: wilc1000: remove p2p related static variables to wilc_vif struct

Avoid use of static variable and move them as part of private
data(wilc_priv) struct.

Signed-off-by: Ajay Singh <[email protected]>
---
drivers/staging/wilc1000/linux_wlan.c | 2 +
drivers/staging/wilc1000/wilc_wfi_cfgoperations.c | 60 +++++++++++------------
drivers/staging/wilc1000/wilc_wfi_netdevice.h | 7 +++
3 files changed, 38 insertions(+), 31 deletions(-)

diff --git a/drivers/staging/wilc1000/linux_wlan.c b/drivers/staging/wilc1000/linux_wlan.c
index 560c168..695d5b2 100644
--- a/drivers/staging/wilc1000/linux_wlan.c
+++ b/drivers/staging/wilc1000/linux_wlan.c
@@ -729,6 +729,7 @@ static int wilc_mac_open(struct net_device *ndev)
{
struct wilc_vif *vif = netdev_priv(ndev);
struct wilc *wl = vif->wilc;
+ struct wilc_priv *priv = wdev_priv(vif->ndev->ieee80211_ptr);
unsigned char mac_add[ETH_ALEN] = {0};
int ret = 0;
int i = 0;
@@ -782,6 +783,7 @@ static int wilc_mac_open(struct net_device *ndev)
vif->frame_reg[1].reg);
netif_wake_queue(ndev);
wl->open_ifcs++;
+ priv->p2p.local_random = 0x01;
vif->mac_opened = 1;
return 0;
}
diff --git a/drivers/staging/wilc1000/wilc_wfi_cfgoperations.c b/drivers/staging/wilc1000/wilc_wfi_cfgoperations.c
index 1a4d262..4fbbbbd 100644
--- a/drivers/staging/wilc1000/wilc_wfi_cfgoperations.c
+++ b/drivers/staging/wilc1000/wilc_wfi_cfgoperations.c
@@ -137,10 +137,7 @@ struct p2p_mgmt_data {
static u8 wlan_channel = INVALID_CHANNEL;
static u8 curr_channel;
static u8 p2p_oui[] = {0x50, 0x6f, 0x9A, 0x09};
-static u8 p2p_local_random = 0x01;
-static u8 p2p_recv_random;
static u8 p2p_vendor_spec[] = {0xdd, 0x05, 0x00, 0x08, 0x40, 0x03};
-static bool wilc_ie;

static struct ieee80211_supported_band wilc_band_2ghz = {
.channels = ieee80211_2ghz_channels,
@@ -515,9 +512,9 @@ static void cfg_connect_result(enum conn_event conn_disconn_evt,
GFP_KERNEL);
} else if (conn_disconn_evt == CONN_DISCONN_EVENT_DISCONN_NOTIF) {
vif->obtaining_ip = false;
- p2p_local_random = 0x01;
- p2p_recv_random = 0x00;
- wilc_ie = false;
+ priv->p2p.local_random = 0x01;
+ priv->p2p.recv_random = 0x00;
+ priv->p2p.is_wilc_ie = false;
eth_zero_addr(priv->associated_bss);
wilc_wlan_set_bssid(priv->dev, null_bssid, STATION_MODE);

@@ -829,9 +826,9 @@ static int disconnect(struct wiphy *wiphy, struct net_device *dev,
wlan_channel = INVALID_CHANNEL;
wilc_wlan_set_bssid(priv->dev, null_bssid, STATION_MODE);

- p2p_local_random = 0x01;
- p2p_recv_random = 0x00;
- wilc_ie = false;
+ priv->p2p.local_random = 0x01;
+ priv->p2p.recv_random = 0x00;
+ priv->p2p.is_wilc_ie = false;
wfi_drv->p2p_timeout = 0;

ret = wilc_disconnect(vif, reason_code);
@@ -1330,20 +1327,21 @@ static void wilc_wfi_cfg_parse_rx_vendor_spec(struct wilc_priv *priv, u8 *buff,
struct wilc_vif *vif = netdev_priv(priv->dev);

subtype = buff[P2P_PUB_ACTION_SUBTYPE];
- if ((subtype == GO_NEG_REQ || subtype == GO_NEG_RSP) && !wilc_ie) {
+ if ((subtype == GO_NEG_REQ || subtype == GO_NEG_RSP) &&
+ !priv->p2p.is_wilc_ie) {
for (i = P2P_PUB_ACTION_SUBTYPE; i < size; i++) {
if (!memcmp(p2p_vendor_spec, &buff[i], 6)) {
- p2p_recv_random = buff[i + 6];
- wilc_ie = true;
+ priv->p2p.recv_random = buff[i + 6];
+ priv->p2p.is_wilc_ie = true;
break;
}
}
}

- if (p2p_local_random <= p2p_recv_random) {
+ if (priv->p2p.local_random <= priv->p2p.recv_random) {
netdev_dbg(vif->ndev,
"PEER WILL BE GO LocaRand=%02x RecvRand %02x\n",
- p2p_local_random, p2p_recv_random);
+ priv->p2p.local_random, priv->p2p.recv_random);
return;
}

@@ -1411,7 +1409,7 @@ void wilc_wfi_p2p_rx(struct net_device *dev, u8 *buff, u32 size)
size);

if ((subtype == GO_NEG_REQ || subtype == GO_NEG_RSP) &&
- wilc_ie)
+ priv->p2p.is_wilc_ie)
size -= 7;

break;
@@ -1503,7 +1501,8 @@ static int cancel_remain_on_channel(struct wiphy *wiphy,
priv->remain_on_ch_params.listen_session_id);
}

-static void wilc_wfi_cfg_tx_vendor_spec(struct p2p_mgmt_data *mgmt_tx,
+static void wilc_wfi_cfg_tx_vendor_spec(struct wilc_priv *priv,
+ struct p2p_mgmt_data *mgmt_tx,
struct cfg80211_mgmt_tx_params *params,
u8 iftype, u32 buf_len)
{
@@ -1513,17 +1512,16 @@ static void wilc_wfi_cfg_tx_vendor_spec(struct p2p_mgmt_data *mgmt_tx,
u8 subtype = buf[P2P_PUB_ACTION_SUBTYPE];

if (subtype == GO_NEG_REQ || subtype == GO_NEG_RSP) {
- if (p2p_local_random == 1 &&
- p2p_recv_random < p2p_local_random) {
- get_random_bytes(&p2p_local_random, 1);
- p2p_local_random++;
+ if (priv->p2p.local_random == 1 &&
+ priv->p2p.recv_random < priv->p2p.local_random) {
+ get_random_bytes(&priv->p2p.local_random, 1);
+ priv->p2p.local_random++;
}
}

- if (p2p_local_random <= p2p_recv_random || !(subtype == GO_NEG_REQ ||
- subtype == GO_NEG_RSP ||
- subtype == P2P_INV_REQ ||
- subtype == P2P_INV_RSP))
+ if (priv->p2p.local_random <= priv->p2p.recv_random ||
+ !(subtype == GO_NEG_REQ || subtype == GO_NEG_RSP ||
+ subtype == P2P_INV_REQ || subtype == P2P_INV_RSP))
return;

for (i = P2P_PUB_ACTION_SUBTYPE + 2; i < len; i++) {
@@ -1547,7 +1545,7 @@ static void wilc_wfi_cfg_tx_vendor_spec(struct p2p_mgmt_data *mgmt_tx,

memcpy(&mgmt_tx->buff[len], p2p_vendor_spec,
vendor_spec_len);
- mgmt_tx->buff[len + vendor_spec_len] = p2p_local_random;
+ mgmt_tx->buff[len + vendor_spec_len] = priv->p2p.local_random;
mgmt_tx->size = buf_len;
}
}
@@ -1566,7 +1564,7 @@ static int mgmt_tx(struct wiphy *wiphy,
struct wilc_priv *priv = wiphy_priv(wiphy);
struct host_if_drv *wfi_drv = priv->hif_drv;
struct wilc_vif *vif = netdev_priv(wdev->netdev);
- u32 buf_len = len + sizeof(p2p_vendor_spec) + sizeof(p2p_local_random);
+ u32 buf_len = len + sizeof(p2p_vendor_spec) + sizeof(priv->p2p.local_random);
int ret = 0;

*cookie = (unsigned long)buf;
@@ -1614,8 +1612,8 @@ static int mgmt_tx(struct wiphy *wiphy,

case PUBLIC_ACT_VENDORSPEC:
if (!memcmp(p2p_oui, &buf[ACTION_SUBTYPE_ID + 1], 4))
- wilc_wfi_cfg_tx_vendor_spec(mgmt_tx, params,
- vif->iftype,
+ wilc_wfi_cfg_tx_vendor_spec(priv, mgmt_tx,
+ params, vif->iftype,
buf_len);
else
netdev_dbg(vif->ndev,
@@ -1743,9 +1741,9 @@ static int change_virtual_intf(struct wiphy *wiphy, struct net_device *dev,
struct wilc_vif *vif = netdev_priv(dev);
struct wilc *wl = vif->wilc;

- p2p_local_random = 0x01;
- p2p_recv_random = 0x00;
- wilc_ie = false;
+ priv->p2p.local_random = 0x01;
+ priv->p2p.recv_random = 0x00;
+ priv->p2p.is_wilc_ie = false;
vif->obtaining_ip = false;
del_timer(&vif->during_ip_timer);

diff --git a/drivers/staging/wilc1000/wilc_wfi_netdevice.h b/drivers/staging/wilc1000/wilc_wfi_netdevice.h
index 4ba5887..4f05a16 100644
--- a/drivers/staging/wilc1000/wilc_wfi_netdevice.h
+++ b/drivers/staging/wilc1000/wilc_wfi_netdevice.h
@@ -69,6 +69,12 @@ struct wilc_wfi_p2p_listen_params {
u32 listen_session_id;
};

+struct wilc_p2p_var {
+ u8 local_random;
+ u8 recv_random;
+ bool is_wilc_ie;
+};
+
struct wilc_priv {
struct wireless_dev *wdev;
struct cfg80211_scan_request *scan_req;
@@ -98,6 +104,7 @@ struct wilc_priv {
struct timer_list aging_timer;
struct network_info scanned_shadow[MAX_NUM_SCANNED_NETWORKS_SHADOW];
int scanned_cnt;
+ struct wilc_p2p_var p2p;
};

struct frame_reg {
--
2.7.4