Skip to contentSkip to conversation

wilc1000: add chip wakeup support and few fixes

PATCH In review [email protected] 2 participants 13 messages Sep 16, 2021 – Sep 21, 2021 Microchip WILC1000 wifi driver

lore
Share & tools
lore

[email protected]

author maintainer
#0 lore raw

v2 cover wilc1000: add chip wakeup support and few fixes

From: Ajay Singh <[email protected]>

The series contains following patches:
- add chip wakeup sequence support required for PS mode
- new WID to handle passing of WOWLan info to FW
- add reset command support for WILC SPI bus
- few trivial fixes for WILC SPI

Changes in v2:
- updated commit details to address the review comments
- used pr_debug instead of pr_info in patch#8
- removed patch#9 as those changes already merged to mainline

Ajay Singh (11):
wilc1000: move 'deinit_lock' lock init/destroy inside module probe
wilc1000: fix possible memory leak in cfg_scan_result()
wilc1000: add new WID to pass wake_enable information to firmware
wilc1000: configure registers to handle chip wakeup sequence
wilc1000: add reset/terminate/repeat command support for SPI bus
wilc1000: handle read failure issue for clockless registers
wilc1000: ignore clockless registers status response for SPI
wilc1000: invoke chip reset register before firmware download
wilc1000: add 'initialized' flag check before adding an element to TX
queue
wilc1000: use correct write command sequence in wilc_spi_sync_ext()
wilc1000: increase config packets response wait timeout limit

 .../wireless/microchip/wilc1000/cfg80211.c    |  11 +-
 drivers/net/wireless/microchip/wilc1000/hif.c |  31 +++-
 drivers/net/wireless/microchip/wilc1000/hif.h |   1 +
 .../net/wireless/microchip/wilc1000/netdev.h  |   2 -
 .../net/wireless/microchip/wilc1000/sdio.c    |   1 +
 drivers/net/wireless/microchip/wilc1000/spi.c |  91 +++++++++++-
 .../net/wireless/microchip/wilc1000/wlan.c    | 134 +++++++++++-------
 .../net/wireless/microchip/wilc1000/wlan.h    |   5 +-
 .../wireless/microchip/wilc1000/wlan_cfg.c    |   1 +
 .../net/wireless/microchip/wilc1000/wlan_if.h |   7 +-
 10 files changed, 210 insertions(+), 74 deletions(-)
Signature · 1 line
2.25.1
author maintainer
#1 lore raw

PATCH v2 1/11 wilc1000: move 'deinit_lock' lock init/destroy inside module probe

From: Ajay Singh <[email protected]>

Move initialization & deinitialization of 'deinit_lock' mutex lock inside wlan_init_locks() & wlan_deinit_locks() API's respectively alongside other locks. After the movement, the client count variable(client_count) which is used for lock init/deinit is removed.

---
 drivers/net/wireless/microchip/wilc1000/cfg80211.c | 2 ++
 drivers/net/wireless/microchip/wilc1000/hif.c      | 7 -------
 drivers/net/wireless/microchip/wilc1000/netdev.h   | 1 -
 3 files changed, 2 insertions(+), 8 deletions(-)
drivers/net/wireless/microchip/wilc1000/cfg80211.c +2 -0
index 96973ec7bd9a..530a768547cc 100644
@@ -1683,6 +1683,7 @@ static void wlan_init_locks(struct wilc *wl)
 	mutex_init(&wl->rxq_cs);
 	mutex_init(&wl->cfg_cmd_lock);
 	mutex_init(&wl->vif_mutex);
+	mutex_init(&wl->deinit_lock);
 
 	spin_lock_init(&wl->txq_spinlock);
 	mutex_init(&wl->txq_add_to_head_cs);
@@ -1701,6 +1702,7 @@ void wlan_deinit_locks(struct wilc *wilc)
 	mutex_destroy(&wilc->cfg_cmd_lock);
 	mutex_destroy(&wilc->txq_add_to_head_cs);
 	mutex_destroy(&wilc->vif_mutex);
+	mutex_destroy(&wilc->deinit_lock);
 	cleanup_srcu_struct(&wilc->srcu);
 }
 
drivers/net/wireless/microchip/wilc1000/hif.c +0 -7
index a133736a7821..497a49a182ef 100644
@@ -1494,7 +1494,6 @@ int wilc_init(struct net_device *dev, struct host_if_drv **hif_drv_handler)
 {
 	struct host_if_drv *hif_drv;
 	struct wilc_vif *vif = netdev_priv(dev);
-	struct wilc *wilc = vif->wilc;
 
 	hif_drv  = kzalloc(sizeof(*hif_drv), GFP_KERNEL);
 	if (!hif_drv)
@@ -1504,9 +1503,6 @@ int wilc_init(struct net_device *dev, struct host_if_drv **hif_drv_handler)
 
 	vif->hif_drv = hif_drv;
 
-	if (wilc->clients_count == 0)
-		mutex_init(&wilc->deinit_lock);
-
 	timer_setup(&vif->periodic_rssi, get_periodic_rssi, 0);
 	mod_timer(&vif->periodic_rssi, jiffies + msecs_to_jiffies(5000));
 
@@ -1518,8 +1514,6 @@ int wilc_init(struct net_device *dev, struct host_if_drv **hif_drv_handler)
 
 	hif_drv->p2p_timeout = 0;
 
-	wilc->clients_count++;
-
 	return 0;
 }
 
@@ -1550,7 +1544,6 @@ int wilc_deinit(struct wilc_vif *vif)
 
 	kfree(hif_drv);
 	vif->hif_drv = NULL;
-	vif->wilc->clients_count--;
 	mutex_unlock(&vif->wilc->deinit_lock);
 	return result;
 }
drivers/net/wireless/microchip/wilc1000/netdev.h +0 -1
index 86209b391a3d..a39c62a20f04 100644
@@ -264,7 +264,6 @@ struct wilc {
 	struct device *dev;
 	bool suspend_event;
 
-	int clients_count;
 	struct workqueue_struct *hif_workqueue;
 	enum chip_ps_states chip_ps_state;
 	struct wilc_cfg cfg;
Signature · 1 line
2.25.1
#2 lore raw

Re: [PATCH v2 01/11] wilc1000: move 'deinit_lock' lock init/destroy inside module probe

Quoted 8 lines · <[email protected]> wrote:

From: Ajay Singh <[email protected]>

Move initialization & deinitialization of 'deinit_lock' mutex lock inside wlan_init_locks() & wlan_deinit_locks() API's respectively alongside other locks. After the movement, the client count variable(client_count) which is used for lock init/deinit is removed.

11 patches applied to wireless-drivers-next.git, thanks.

c8e2036ee90b wilc1000: move 'deinit_lock' lock init/destroy inside module probe 3c719fed0f3a wilc1000: fix possible memory leak in cfg_scan_result() 0ec5408cd448 wilc1000: add new WID to pass wake_enable information to firmware 5bb9de8bcb18 wilc1000: configure registers to handle chip wakeup sequence 1bcc0879c963 wilc1000: add reset/terminate/repeat command support for SPI bus c2dcb4766bcb wilc1000: handle read failure issue for clockless registers aa3fda4fcf63 wilc1000: ignore clockless registers status response for SPI 29f7393e02ac wilc1000: invoke chip reset register before firmware download cd50248de35b wilc1000: add 'initialized' flag check before adding an element to TX queue 301cfbab09fd wilc1000: use correct write command sequence in wilc_spi_sync_ext() bb6a0d5404aa wilc1000: increase config packets response wait timeout limit

Signature · 3 lines
https://patchwork.kernel.org/project/linux-wireless/patch/[email protected]/

https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches
author maintainer
#3 lore raw

PATCH v2 2/11 wilc1000: fix possible memory leak in cfg_scan_result()

In reply to [email protected]

From: Ajay Singh <[email protected]>

When the BSS reference holds a valid reference, it is not freed. The 'if' condition is wrong. Instead of the 'if (bss)' check, the 'if (!bss)' check is used.
The issue is solved by removing the unnecessary 'if' check because cfg80211_put_bss() already performs the NULL validation.

Fixes 6cd4fa5ab691 ("staging: wilc1000: make use of cfg80211_inform_bss_frame()")
---
 drivers/net/wireless/microchip/wilc1000/cfg80211.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/net/wireless/microchip/wilc1000/cfg80211.c +1 -2
index 530a768547cc..36b87ed38092 100644
@@ -129,8 +129,7 @@ static void cfg_scan_result(enum scan_event scan_event,
 						info->frame_len,
 						(s32)info->rssi * 100,
 						GFP_KERNEL);
-		if (!bss)
-			cfg80211_put_bss(wiphy, bss);
+		cfg80211_put_bss(wiphy, bss);
 	} else if (scan_event == SCAN_EVENT_DONE) {
 		mutex_lock(&priv->scan_req_lock);
 
Signature · 1 line
2.25.1
author maintainer
#4 lore raw

PATCH v2 3/11 wilc1000: add new WID to pass wake_enable information to firmware

In reply to [email protected]

From: Ajay Singh <[email protected]>

Add new WID(WID_WOWLAN_TRIGGER) to send wake_enable information to firmware. In 'set_wakeup' cfg80211_ops callback, the enable information was not passed to firmware which is required to handle WOWLan trigger notification from firmware.

---
 .../wireless/microchip/wilc1000/cfg80211.c    |  1 +
 drivers/net/wireless/microchip/wilc1000/hif.c | 24 +++++++++++++++++++
 drivers/net/wireless/microchip/wilc1000/hif.h |  1 +
 .../wireless/microchip/wilc1000/wlan_cfg.c    |  1 +
 .../net/wireless/microchip/wilc1000/wlan_if.h |  1 +
 5 files changed, 28 insertions(+)
drivers/net/wireless/microchip/wilc1000/cfg80211.c +1 -0
index 36b87ed38092..75160ab3914a 100644
@@ -1580,6 +1580,7 @@ static void wilc_set_wakeup(struct wiphy *wiphy, bool enabled)
 	}
 
 	netdev_info(vif->ndev, "cfg set wake up = %d\n", enabled);
+	wilc_set_wowlan_trigger(vif, enabled);
 	srcu_read_unlock(&wl->srcu, srcu_idx);
 }
 
drivers/net/wireless/microchip/wilc1000/hif.c +24 -0
index 497a49a182ef..e69b9c7f3d31 100644
@@ -23,6 +23,10 @@ struct wilc_set_multicast {
 	u8 *mc_list;
 };
 
+struct host_if_wowlan_trigger {
+	u8 wowlan_trigger;
+};
+
 struct wilc_del_all_sta {
 	u8 assoc_sta;
 	u8 mac[WILC_MAX_NUM_STA][ETH_ALEN];
@@ -34,6 +38,7 @@ union wilc_message_body {
 	struct wilc_set_multicast mc_info;
 	struct wilc_remain_ch remain_on_ch;
 	char *data;
+	struct host_if_wowlan_trigger wow_trigger;
 };
 
 struct host_if_msg {
@@ -962,6 +967,25 @@ static void handle_set_mcast_filter(struct work_struct *work)
 	kfree(msg);
 }
 
+void wilc_set_wowlan_trigger(struct wilc_vif *vif, bool enabled)
+{
+	int ret;
+	struct wid wid;
+	u8 wowlan_trigger = 0;
+
+	if (enabled)
+		wowlan_trigger = 1;
+
+	wid.id = WID_WOWLAN_TRIGGER;
+	wid.type = WID_CHAR;
+	wid.val = &wowlan_trigger;
+	wid.size = sizeof(char);
+
+	ret = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1);
+	if (ret)
+		pr_err("Failed to send wowlan trigger config packet\n");
+}
+
 static void handle_scan_timer(struct work_struct *work)
 {
 	struct host_if_msg *msg = container_of(work, struct host_if_msg, work);
drivers/net/wireless/microchip/wilc1000/hif.h +1 -0
index 58811911213b..cccd54ed0518 100644
@@ -207,6 +207,7 @@ int wilc_get_statistics(struct wilc_vif *vif, struct rf_info *stats);
 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);
+void wilc_set_wowlan_trigger(struct wilc_vif *vif, bool enabled);
 void wilc_scan_complete_received(struct wilc *wilc, u8 *buffer, u32 length);
 void wilc_network_info_received(struct wilc *wilc, u8 *buffer, u32 length);
 void wilc_gnrl_async_info_received(struct wilc *wilc, u8 *buffer, u32 length);
drivers/net/wireless/microchip/wilc1000/wlan_cfg.c +1 -0
index fe2a7ed8e5cd..dba301378b7f 100644
@@ -22,6 +22,7 @@ static const struct wilc_cfg_byte g_cfg_byte[] = {
 	{WID_STATUS, 0},
 	{WID_RSSI, 0},
 	{WID_LINKSPEED, 0},
+	{WID_WOWLAN_TRIGGER, 0},
 	{WID_NIL, 0}
 };
 
drivers/net/wireless/microchip/wilc1000/wlan_if.h +1 -0
index f85fd575136d..31c68643731d 100644
@@ -662,6 +662,7 @@ enum {
 
 	WID_LOG_TERMINAL_SWITCH		= 0x00CD,
 	WID_TX_POWER			= 0x00CE,
+	WID_WOWLAN_TRIGGER		= 0X00CF,
 	/*  EMAC Short WID list */
 	/*  RTS Threshold */
 	/*
Signature · 1 line
2.25.1
author maintainer
#5 lore raw

PATCH v2 4/11 wilc1000: configure registers to handle chip wakeup sequence

In reply to [email protected]

From: Ajay Singh <[email protected]>

Use the correct sequence to configure clockless registers for chip wake-up. The following sequence is expected from WILC chip for wakeup:
- set wakeup bit in wakeup_reg register
- after setting the wakeup bit, read back the clock status bit for wakeup complete.

For SDIO/SPI modules, the wakeup sequence is the same except uses different register values so refactored the code to use common function for both SDIO/SPI bus.

---
 .../wireless/microchip/wilc1000/cfg80211.c    |  1 -
 .../net/wireless/microchip/wilc1000/netdev.h  |  1 -
 .../net/wireless/microchip/wilc1000/wlan.c    | 98 ++++++++++---------
 .../net/wireless/microchip/wilc1000/wlan.h    |  2 +
 .../net/wireless/microchip/wilc1000/wlan_if.h |  6 --
 5 files changed, 53 insertions(+), 55 deletions(-)
drivers/net/wireless/microchip/wilc1000/cfg80211.c +0 -1
index 75160ab3914a..91a471f3b1c8 100644
@@ -1726,7 +1726,6 @@ int wilc_cfg80211_init(struct wilc **wilc, struct device *dev, int io_type,
 	*wilc = wl;
 	wl->io_type = io_type;
 	wl->hif_func = ops;
-	wl->chip_ps_state = WILC_CHIP_WAKEDUP;
 
 	for (i = 0; i < NQUEUES; i++)
 		INIT_LIST_HEAD(&wl->txq[i].txq_head.list);
drivers/net/wireless/microchip/wilc1000/netdev.h +0 -1
index a39c62a20f04..79f73a72da57 100644
@@ -265,7 +265,6 @@ struct wilc {
 	bool suspend_event;
 
 	struct workqueue_struct *hif_workqueue;
-	enum chip_ps_states chip_ps_state;
 	struct wilc_cfg cfg;
 	void *bus_data;
 	struct net_device *monitor_dev;
drivers/net/wireless/microchip/wilc1000/wlan.c +51 -47

117 lines not on this page · raw message

drivers/net/wireless/microchip/wilc1000/wlan.h +2 -0
index 771c25fa849b..285e5d9a2b48 100644
@@ -97,6 +97,8 @@
 #define WILC_SPI_WAKEUP_REG		0x1
 #define WILC_SPI_WAKEUP_BIT		BIT(1)
 
+#define WILC_SPI_CLK_STATUS_REG        0x0f
+#define WILC_SPI_CLK_STATUS_BIT        BIT(2)
 #define WILC_SPI_HOST_TO_FW_REG		0x0b
 #define WILC_SPI_HOST_TO_FW_BIT		BIT(0)
 
drivers/net/wireless/microchip/wilc1000/wlan_if.h +0 -6
index 31c68643731d..6eb7eb4ac294 100644
@@ -48,12 +48,6 @@ enum {
 	WILC_FW_MAX_PSPOLL_PS = 4
 };
 
-enum chip_ps_states {
-	WILC_CHIP_WAKEDUP = 0,
-	WILC_CHIP_SLEEPING_AUTO = 1,
-	WILC_CHIP_SLEEPING_MANUAL = 2
-};
-
 enum bus_acquire {
 	WILC_BUS_ACQUIRE_ONLY = 0,
 	WILC_BUS_ACQUIRE_AND_WAKEUP = 1,
Signature · 1 line
2.25.1
author maintainer
#6 lore raw

PATCH v2 5/11 wilc1000: add reset/terminate/repeat command support for SPI bus

In reply to [email protected]

From: Ajay Singh <[email protected]>

Add reset/terminate/repeat command for SPI module. In case of SPI commands failure, the host should issue a RESET command to WILC chip to recover from any temporary bus error.
For now, the new command support is added and later the SPI read/write API's would be modified to make use of these commands for retry mechanism

---
 drivers/net/wireless/microchip/wilc1000/spi.c | 61 +++++++++++++++++++
 1 file changed, 61 insertions(+)
drivers/net/wireless/microchip/wilc1000/spi.c +61 -0
index dd481dc0b5ce..602316f4367c 100644
@@ -144,6 +144,12 @@ struct wilc_spi_rsp_data {
 	u8 data[];
 } __packed;
 
+struct wilc_spi_special_cmd_rsp {
+	u8 skip_byte;
+	u8 rsp_cmd_type;
+	u8 status;
+} __packed;
+
 static int wilc_bus_probe(struct spi_device *spi)
 {
 	int ret;
@@ -709,6 +715,61 @@ static int wilc_spi_dma_rw(struct wilc *wilc, u8 cmd, u32 adr, u8 *b, u32 sz)
 	return 0;
 }
 
+static int wilc_spi_special_cmd(struct wilc *wilc, u8 cmd)
+{
+	struct spi_device *spi = to_spi_device(wilc->dev);
+	struct wilc_spi *spi_priv = wilc->bus_data;
+	u8 wb[32], rb[32];
+	int cmd_len, resp_len = 0;
+	struct wilc_spi_cmd *c;
+	struct wilc_spi_special_cmd_rsp *r;
+
+	if (cmd != CMD_TERMINATE && cmd != CMD_REPEAT && cmd != CMD_RESET)
+		return -EINVAL;
+
+	memset(wb, 0x0, sizeof(wb));
+	memset(rb, 0x0, sizeof(rb));
+	c = (struct wilc_spi_cmd *)wb;
+	c->cmd_type = cmd;
+
+	if (cmd == CMD_RESET)
+		memset(c->u.simple_cmd.addr, 0xFF, 3);
+
+	cmd_len = offsetof(struct wilc_spi_cmd, u.simple_cmd.crc);
+	resp_len = sizeof(*r);
+
+	if (spi_priv->crc7_enabled) {
+		c->u.simple_cmd.crc[0] = wilc_get_crc7(wb, cmd_len);
+		cmd_len += 1;
+	}
+	if (cmd_len + resp_len > ARRAY_SIZE(wb)) {
+		dev_err(&spi->dev, "spi buffer size too small (%d) (%d) (%zu)\n",
+			cmd_len, resp_len, ARRAY_SIZE(wb));
+		return -EINVAL;
+	}
+
+	if (wilc_spi_tx_rx(wilc, wb, rb, cmd_len + resp_len)) {
+		dev_err(&spi->dev, "Failed cmd write, bus error...\n");
+		return -EINVAL;
+	}
+
+	r = (struct wilc_spi_special_cmd_rsp *)&rb[cmd_len];
+	if (r->rsp_cmd_type != cmd) {
+		if (!spi_priv->probing_crc)
+			dev_err(&spi->dev,
+				"Failed cmd response, cmd (%02x), resp (%02x)\n",
+				cmd, r->rsp_cmd_type);
+		return -EINVAL;
+	}
+
+	if (r->status != WILC_SPI_COMMAND_STAT_SUCCESS) {
+		dev_err(&spi->dev, "Failed cmd state response state (%02x)\n",
+			r->status);
+		return -EINVAL;
+	}
+	return 0;
+}
+
 static int wilc_spi_read_reg(struct wilc *wilc, u32 addr, u32 *data)
 {
 	struct spi_device *spi = to_spi_device(wilc->dev);
Signature · 1 line
2.25.1
author maintainer
#7 lore raw

PATCH v2 6/11 wilc1000: handle read failure issue for clockless registers

In reply to [email protected]

From: Ajay Singh <[email protected]>

For SPI bus, the register read fails after read/write to the clockless register during chip wakeup sequence. Add workaround to send CMD_RESET command during chip wake-up sequence to overcome the issue.

---
 drivers/net/wireless/microchip/wilc1000/sdio.c |  1 +
 drivers/net/wireless/microchip/wilc1000/spi.c  | 16 ++++++++++++++++
 drivers/net/wireless/microchip/wilc1000/wlan.c |  5 +++++
 drivers/net/wireless/microchip/wilc1000/wlan.h |  1 +
 4 files changed, 23 insertions(+)
drivers/net/wireless/microchip/wilc1000/sdio.c +1 -0
index 42e03a701ae1..26ebf6664342 100644
@@ -978,6 +978,7 @@ static const struct wilc_hif_func wilc_hif_sdio = {
 	.hif_sync_ext = wilc_sdio_sync_ext,
 	.enable_interrupt = wilc_sdio_enable_interrupt,
 	.disable_interrupt = wilc_sdio_disable_interrupt,
+	.hif_reset = wilc_sdio_reset,
 };
 
 static int wilc_sdio_resume(struct device *dev)
drivers/net/wireless/microchip/wilc1000/spi.c +16 -0
index 602316f4367c..511b9264185f 100644
@@ -47,6 +47,8 @@ struct wilc_spi {
 
 static const struct wilc_hif_func wilc_hif_spi;
 
+static int wilc_spi_reset(struct wilc *wilc);
+
 /********************************************
  *
  *      Spi protocol Function
@@ -956,6 +958,19 @@ static int wilc_spi_write(struct wilc *wilc, u32 addr, u8 *buf, u32 size)
  *
  ********************************************/
 
+static int wilc_spi_reset(struct wilc *wilc)
+{
+	struct spi_device *spi = to_spi_device(wilc->dev);
+	struct wilc_spi *spi_priv = wilc->bus_data;
+	int result;
+
+	result = wilc_spi_special_cmd(wilc, CMD_RESET);
+	if (result && !spi_priv->probing_crc)
+		dev_err(&spi->dev, "Failed cmd reset\n");
+
+	return result;
+}
+
 static int wilc_spi_deinit(struct wilc *wilc)
 {
 	/*
@@ -1173,4 +1188,5 @@ static const struct wilc_hif_func wilc_hif_spi = {
 	.hif_block_tx_ext = wilc_spi_write,
 	.hif_block_rx_ext = wilc_spi_read,
 	.hif_sync_ext = wilc_spi_sync_ext,
+	.hif_reset = wilc_spi_reset,
 };
drivers/net/wireless/microchip/wilc1000/wlan.c +5 -0
index 1aad537c468f..f9256c1bad45 100644
@@ -669,6 +669,11 @@ void chip_wakeup(struct wilc *wilc)
 		pr_err("Failed to wake-up the chip\n");
 		return;
 	}
+	/* Sometimes spi fail to read clock regs after reading
+	 * writing clockless registers
+	 */
+	if (wilc->io_type == WILC_HIF_SPI)
+		wilc->hif_func->hif_reset(wilc);
 }
 EXPORT_SYMBOL_GPL(chip_wakeup);
 
drivers/net/wireless/microchip/wilc1000/wlan.h +1 -0
index 285e5d9a2b48..150648b2c872 100644
@@ -373,6 +373,7 @@ struct wilc_hif_func {
 	int (*hif_sync_ext)(struct wilc *wilc, int nint);
 	int (*enable_interrupt)(struct wilc *nic);
 	void (*disable_interrupt)(struct wilc *nic);
+	int (*hif_reset)(struct wilc *wilc);
 };
 
 #define WILC_MAX_CFG_FRAME_SIZE		1468
Signature · 1 line
2.25.1
author maintainer
#8 lore raw

PATCH v2 7/11 wilc1000: ignore clockless registers status response for SPI

In reply to [email protected]

From: Ajay Singh <[email protected]>

During WILC chip wake-up sequence, the clockless status register sometimes reports failure even when the actual status is successful. So, for the clockless register, remove the incorrect error status reporting during the read and write command API's.

---
 drivers/net/wireless/microchip/wilc1000/spi.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)
drivers/net/wireless/microchip/wilc1000/spi.c +8 -4
index 511b9264185f..4f0bc24d2a78 100644
@@ -474,7 +474,7 @@ static int wilc_spi_single_read(struct wilc *wilc, u8 cmd, u32 adr, void *b,
 	}
 
 	r = (struct wilc_spi_rsp_data *)&rb[cmd_len];
-	if (r->rsp_cmd_type != cmd) {
+	if (r->rsp_cmd_type != cmd && !clockless) {
 		if (!spi_priv->probing_crc)
 			dev_err(&spi->dev,
 				"Failed cmd, cmd (%02x), resp (%02x)\n",
@@ -482,7 +482,7 @@ static int wilc_spi_single_read(struct wilc *wilc, u8 cmd, u32 adr, void *b,
 		return -EINVAL;
 	}
 
-	if (r->status != WILC_SPI_COMMAND_STAT_SUCCESS) {
+	if (r->status != WILC_SPI_COMMAND_STAT_SUCCESS && !clockless) {
 		dev_err(&spi->dev, "Failed cmd state response state (%02x)\n",
 			r->status);
 		return -EINVAL;
@@ -571,14 +571,18 @@ static int wilc_spi_write_cmd(struct wilc *wilc, u8 cmd, u32 adr, u32 data,
 	}
 
 	r = (struct wilc_spi_rsp_data *)&rb[cmd_len];
-	if (r->rsp_cmd_type != cmd) {
+	/*
+	 * Clockless registers operations might return unexptected responses,
+	 * even if successful.
+	 */
+	if (r->rsp_cmd_type != cmd && !clockless) {
 		dev_err(&spi->dev,
 			"Failed cmd response, cmd (%02x), resp (%02x)\n",
 			cmd, r->rsp_cmd_type);
 		return -EINVAL;
 	}
 
-	if (r->status != WILC_SPI_COMMAND_STAT_SUCCESS) {
+	if (r->status != WILC_SPI_COMMAND_STAT_SUCCESS && !clockless) {
 		dev_err(&spi->dev, "Failed cmd state response state (%02x)\n",
 			r->status);
 		return -EINVAL;
Signature · 1 line
2.25.1
author maintainer
#9 lore raw

PATCH v2 8/11 wilc1000: invoke chip reset register before firmware download

In reply to [email protected]

From: Ajay Singh <[email protected]>

Add the chip reset command to initialize the WILC chip before downloading the firmware. Also, put the chip in wake-up mode so it is ready to receive the firmware binary from the host.

---
 .../net/wireless/microchip/wilc1000/wlan.c    | 22 ++++++++++++++++---
 1 file changed, 19 insertions(+), 3 deletions(-)
drivers/net/wireless/microchip/wilc1000/wlan.c +19 -3
index f9256c1bad45..de5287cd8652 100644
@@ -1080,6 +1080,7 @@ int wilc_wlan_firmware_download(struct wilc *wilc, const u8 *buffer,
 	u32 addr, size, size2, blksz;
 	u8 *dma_buffer;
 	int ret = 0;
+	u32 reg = 0;
 
 	blksz = BIT(12);
 
@@ -1088,10 +1089,22 @@ int wilc_wlan_firmware_download(struct wilc *wilc, const u8 *buffer,
 		return -EIO;
 
 	offset = 0;
+	pr_debug("%s: Downloading firmware size = %d\n", __func__, buffer_size);
+
+	acquire_bus(wilc, WILC_BUS_ACQUIRE_AND_WAKEUP);
+
+	wilc->hif_func->hif_read_reg(wilc, WILC_GLB_RESET_0, &reg);
+	reg &= ~BIT(10);
+	ret = wilc->hif_func->hif_write_reg(wilc, WILC_GLB_RESET_0, reg);
+	wilc->hif_func->hif_read_reg(wilc, WILC_GLB_RESET_0, &reg);
+	if (reg & BIT(10))
+		pr_err("%s: Failed to reset\n", __func__);
+
+	release_bus(wilc, WILC_BUS_RELEASE_ONLY);
 	do {
 		addr = get_unaligned_le32(&buffer[offset]);
 		size = get_unaligned_le32(&buffer[offset + 4]);
-		acquire_bus(wilc, WILC_BUS_ACQUIRE_ONLY);
+		acquire_bus(wilc, WILC_BUS_ACQUIRE_AND_WAKEUP);
 		offset += 8;
 		while (((int)size) && (offset < buffer_size)) {
 			if (size <= blksz)
@@ -1109,10 +1122,13 @@ int wilc_wlan_firmware_download(struct wilc *wilc, const u8 *buffer,
 			offset += size2;
 			size -= size2;
 		}
-		release_bus(wilc, WILC_BUS_RELEASE_ONLY);
+		release_bus(wilc, WILC_BUS_RELEASE_ALLOW_SLEEP);
 
-		if (ret)
+		if (ret) {
+			pr_err("%s Bus error\n", __func__);
 			goto fail;
+		}
+		pr_debug("%s Offset = %d\n", __func__, offset);
 	} while (offset < buffer_size);
 
 fail:
Signature · 1 line
2.25.1
author maintainer
#10 lore raw

PATCH v2 9/11 wilc1000: add 'initialized' flag check before adding an element to TX queue

In reply to [email protected]

From: Ajay Singh <[email protected]>

Add 'initialized' variable check before adding net/mgmt packet to TX queue as safety check before passing the commands to the firmware.

---
 drivers/net/wireless/microchip/wilc1000/cfg80211.c | 4 ++++
 drivers/net/wireless/microchip/wilc1000/wlan.c     | 9 +++++++++
 2 files changed, 13 insertions(+)
drivers/net/wireless/microchip/wilc1000/cfg80211.c +4 -0
index 91a471f3b1c8..dc4bfe7be378 100644
@@ -728,6 +728,7 @@ static int get_station(struct wiphy *wiphy, struct net_device *dev,
 {
 	struct wilc_vif *vif = netdev_priv(dev);
 	struct wilc_priv *priv = &vif->priv;
+	struct wilc *wilc = vif->wilc;
 	u32 i = 0;
 	u32 associatedsta = ~0;
 	u32 inactive_time = 0;
@@ -754,6 +755,9 @@ static int get_station(struct wiphy *wiphy, struct net_device *dev,
 	} else if (vif->iftype == WILC_STATION_MODE) {
 		struct rf_info stats;
 
+		if (!wilc->initialized)
+			return -EBUSY;
+
 		wilc_get_statistics(vif, &stats);
 
 		sinfo->filled |= BIT_ULL(NL80211_STA_INFO_SIGNAL) |
drivers/net/wireless/microchip/wilc1000/wlan.c +9 -0
index de5287cd8652..ea81ef120fd1 100644
@@ -427,6 +427,11 @@ int wilc_wlan_txq_add_net_pkt(struct net_device *dev,
 		return 0;
 	}
 
+	if (!wilc->initialized) {
+		tx_complete_fn(tx_data, 0);
+		return 0;
+	}
+
 	tqe = kmalloc(sizeof(*tqe), GFP_ATOMIC);
 
 	if (!tqe) {
@@ -476,6 +481,10 @@ int wilc_wlan_txq_add_mgmt_pkt(struct net_device *dev, void *priv, u8 *buffer,
 		return 0;
 	}
 
+	if (!wilc->initialized) {
+		tx_complete_fn(priv, 0);
+		return 0;
+	}
 	tqe = kmalloc(sizeof(*tqe), GFP_ATOMIC);
 
 	if (!tqe) {
Signature · 1 line
2.25.1
author maintainer
#11 lore raw

PATCH v2 10/11 wilc1000: use correct write command sequence in wilc_spi_sync_ext()

In reply to [email protected]

From: Ajay Singh <[email protected]>

Instead of using double read for the same register, use the write register command after the read command.
The correct sequence is to use the read value in write command instead of reading the same register again.

---
 drivers/net/wireless/microchip/wilc1000/spi.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/wireless/microchip/wilc1000/spi.c +1 -1
index 4f0bc24d2a78..640850f989dd 100644
@@ -1167,7 +1167,7 @@ static int wilc_spi_sync_ext(struct wilc *wilc, int nint)
 		for (i = 0; (i < 3) && (nint > 0); i++, nint--)
 			reg |= BIT(i);
 
-		ret = wilc_spi_read_reg(wilc, WILC_INTR2_ENABLE, &reg);
+		ret = wilc_spi_write_reg(wilc, WILC_INTR2_ENABLE, reg);
 		if (ret) {
 			dev_err(&spi->dev, "Failed write reg (%08x)...\n",
 				WILC_INTR2_ENABLE);
Signature · 1 line
2.25.1
author maintainer
#12 lore raw

PATCH v2 11/11 wilc1000: increase config packets response wait timeout limit

In reply to [email protected]

From: Ajay Singh <[email protected]>

Increase the WID config packet response timeout to have extra wait time for host to receive the response message from firmware. Sometimes the WID config response was timed out because of host interrupt latency.

---
 drivers/net/wireless/microchip/wilc1000/wlan.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/wireless/microchip/wilc1000/wlan.h +1 -1
index 150648b2c872..13fde636aa0e 100644
@@ -302,7 +302,7 @@
 #define ENABLE_RX_VMM		(SEL_VMM_TBL1 | EN_VMM)
 #define ENABLE_TX_VMM		(SEL_VMM_TBL0 | EN_VMM)
 /* time for expiring the completion of cfg packets */
-#define WILC_CFG_PKTS_TIMEOUT	msecs_to_jiffies(2000)
+#define WILC_CFG_PKTS_TIMEOUT	msecs_to_jiffies(3000)
 
 #define IS_MANAGMEMENT		0x100
 #define IS_MANAGMEMENT_CALLBACK	0x080
Signature · 1 line
2.25.1