Skip to contentSkip to conversation

ath6kl: cut power when interface is down

PATCH In review Kalle Valo 1 participant 7 messages Oct 30, 2011 – Nov 1, 2011 Atheros ATH6KL wireless driver

lore
Share & tools
lore

Kalle Valo

author
#0 lore raw

cover ath6kl: cut power when interface is down

The following series changes interface handling so that power is cut from the chip whenever interface is down compared to the current situation when the harware is powered all the time since module is loaded.

I'm not really sure if this is going be the final implementation but I'll send this for review anyway. I structured the code so that it's easy to go back to the old functionality if we so desire.

Also I need to solve support for multivif. Currently these patches work as there's only one vif.

---

Kalle Valo (5):
ath6kl: create ath6kl_hif_stop()
ath6kl: power down hardware when interface is down
ath6kl: fix WLAN_ENABLE usage in ath6kl_close()
ath6kl: print firmware crashes always
ath6kl: print seqno in htc debug logs

 drivers/net/wireless/ath/ath6kl/bmi.c     |    5 ++
 drivers/net/wireless/ath/ath6kl/bmi.h     |    2 +
 drivers/net/wireless/ath/ath6kl/core.h    |    5 +-
 drivers/net/wireless/ath/ath6kl/hif-ops.h |    7 ++
 drivers/net/wireless/ath/ath6kl/hif.c     |   69 ++++++++++++++++++++--
 drivers/net/wireless/ath/ath6kl/hif.h     |    1 
 drivers/net/wireless/ath/ath6kl/htc.c     |   14 +++--
 drivers/net/wireless/ath/ath6kl/init.c    |   90 ++++++++++-------------------
 drivers/net/wireless/ath/ath6kl/main.c    |   25 ++++++--
 drivers/net/wireless/ath/ath6kl/sdio.c    |   45 +++++++++++++++
 10 files changed, 187 insertions(+), 76 deletions(-)
author
#1 lore raw

PATCH 1/5 ath6kl: create ath6kl_hif_stop()

This is to reset hif layer for powering down hw.

---
 drivers/net/wireless/ath/ath6kl/hif-ops.h |    7 +++++
 drivers/net/wireless/ath/ath6kl/hif.h     |    1 +
 drivers/net/wireless/ath/ath6kl/sdio.c    |   45 +++++++++++++++++++++++++++++
 3 files changed, 53 insertions(+), 0 deletions(-)
drivers/net/wireless/ath/ath6kl/hif-ops.h +7 -0
index 34adc77..50fd3e9 100644
@@ -111,4 +111,11 @@ static inline int ath6kl_hif_power_off(struct ath6kl *ar)
 	return ar->hif_ops->power_off(ar);
 }
 
+static inline void ath6kl_hif_stop(struct ath6kl *ar)
+{
+	ath6kl_dbg(ATH6KL_DBG_HIF, "hif stop\n");
+
+	ar->hif_ops->stop(ar);
+}
+
 #endif
drivers/net/wireless/ath/ath6kl/hif.h +1 -0
index 78a6c79..814386d 100644
@@ -246,6 +246,7 @@ struct ath6kl_hif_ops {
 	int (*resume)(struct ath6kl *ar);
 	int (*power_on)(struct ath6kl *ar);
 	int (*power_off)(struct ath6kl *ar);
+	void (*stop)(struct ath6kl *ar);
 };
 
 int ath6kl_hif_setup(struct ath6kl_device *dev);
drivers/net/wireless/ath/ath6kl/sdio.c +45 -0

75 lines not on this page · raw message

author
#2 lore raw

PATCH 2/5 ath6kl: power down hardware when interface is down

In reply to Kalle Valo

The benefit from this is that user space can control hardware's power state by putting interface up and down. This is handy if firmware gets to some weird state.

The downside will be that putting interface up takes a bit longer, I was measuring ~500 ms during interface up.

---
 drivers/net/wireless/ath/ath6kl/bmi.c  |    5 +++++
 drivers/net/wireless/ath/ath6kl/bmi.h  |    2 ++
 drivers/net/wireless/ath/ath6kl/core.h |    4 ++++
 drivers/net/wireless/ath/ath6kl/htc.c  |    3 +++
 drivers/net/wireless/ath/ath6kl/init.c |   35 +++++++++++++++++++++++++++++---
 drivers/net/wireless/ath/ath6kl/main.c |   22 ++++++++++++++++----
 6 files changed, 64 insertions(+), 7 deletions(-)
drivers/net/wireless/ath/ath6kl/bmi.c +5 -0
index 5a4c24d..a962fe4 100644
@@ -670,6 +670,11 @@ int ath6kl_bmi_fast_download(struct ath6kl *ar, u32 addr, u8 *buf, u32 len)
 	return ret;
 }
 
+void ath6kl_bmi_reset(struct ath6kl *ar)
+{
+	ar->bmi.done_sent = false;
+}
+
 int ath6kl_bmi_init(struct ath6kl *ar)
 {
 	ar->bmi.cmd_buf = kzalloc(MAX_BMI_CMDBUF_SZ, GFP_ATOMIC);
drivers/net/wireless/ath/ath6kl/bmi.h +2 -0
index 96851d5..009e8f6 100644
@@ -230,6 +230,8 @@ struct ath6kl_bmi_target_info {
 
 int ath6kl_bmi_init(struct ath6kl *ar);
 void ath6kl_bmi_cleanup(struct ath6kl *ar);
+void ath6kl_bmi_reset(struct ath6kl *ar);
+
 int ath6kl_bmi_done(struct ath6kl *ar);
 int ath6kl_bmi_get_target_info(struct ath6kl *ar,
 			       struct ath6kl_bmi_target_info *targ_info);
drivers/net/wireless/ath/ath6kl/core.h +4 -0
index 5ac415e..1ac0dd1 100644
@@ -447,6 +447,7 @@ enum ath6kl_dev_state {
 	DESTROY_IN_PROGRESS,
 	SKIP_SCAN,
 	ROAM_TBL_PEND,
+	FIRST_BOOT,
 };
 
 struct ath6kl {
@@ -662,4 +663,7 @@ void ath6kl_deinit_if_data(struct ath6kl_vif *vif);
 void ath6kl_core_free(struct ath6kl *ar);
 struct ath6kl_vif *ath6kl_vif_first(struct ath6kl *ar);
 void ath6kl_cleanup_vif(struct ath6kl_vif *vif, bool wmi_ready);
+int ath6kl_init_hw_start(struct ath6kl *ar);
+int ath6kl_init_hw_stop(struct ath6kl *ar);
+
 #endif /* CORE_H */
drivers/net/wireless/ath/ath6kl/htc.c +3 -0
index 04b4070..99220d4 100644
@@ -2622,6 +2622,9 @@ int ath6kl_htc_start(struct htc_target *target)
 	struct htc_packet *packet;
 	int status;
 
+	memset(&target->dev->irq_proc_reg, 0,
+	       sizeof(target->dev->irq_proc_reg));
+
 	/* Disable interrupts at the chip level */
 	ath6kl_hif_disable_intrs(target->dev);
 
drivers/net/wireless/ath/ath6kl/init.c +32 -3
index a0b81c3..c197e4c 100644
@@ -1421,11 +1421,13 @@ static int ath6kl_init_hw_params(struct ath6kl *ar)
 	return 0;
 }
 
-static int ath6kl_hw_start(struct ath6kl *ar)
+int ath6kl_init_hw_start(struct ath6kl *ar)
 {
 	long timeleft;
 	int ret, i;
 
+	ath6kl_dbg(ATH6KL_DBG_BOOT, "hw start\n");
+
 	ret = ath6kl_hif_power_on(ar);
 	if (ret)
 		return ret;
@@ -1517,6 +1519,25 @@ err_power_off:
 	return ret;
 }
 
+int ath6kl_init_hw_stop(struct ath6kl *ar)
+{
+	int ret;
+
+	ath6kl_dbg(ATH6KL_DBG_BOOT, "hw stop\n");
+
+	ath6kl_htc_stop(ar->htc_target);
+
+	ath6kl_hif_stop(ar);
+
+	ath6kl_bmi_reset(ar);
+
+	ret = ath6kl_hif_power_off(ar);
+	if (ret)
+		ath6kl_warn("failed to power off hif: %d\n", ret);
+
+	return 0;
+}
+
 int ath6kl_core_init(struct ath6kl *ar)
 {
 	struct ath6kl_bmi_target_info targ_info;
@@ -1628,9 +1649,11 @@ int ath6kl_core_init(struct ath6kl *ar)
 
 	ar->wiphy->flags |= WIPHY_FLAG_SUPPORTS_FW_ROAM;
 
-	ret = ath6kl_hw_start(ar);
+	set_bit(FIRST_BOOT, &ar->flag);
+
+	ret = ath6kl_init_hw_start(ar);
 	if (ret) {
-		ath6kl_err("Failed to boot hardware: %d\n", ret);
+		ath6kl_err("Failed to start hardware: %d\n", ret);
 		goto err_rxbuf_cleanup;
 	}
 
@@ -1640,6 +1663,12 @@ int ath6kl_core_init(struct ath6kl *ar)
 	 */
 	memcpy(ndev->dev_addr, ar->mac_addr, ETH_ALEN);
 
+	ret = ath6kl_init_hw_stop(ar);
+	if (ret) {
+		ath6kl_err("Failed to stop hardware: %d\n", ret);
+		goto err_htc_cleanup;
+	}
+
 	return ret;
 
 err_rxbuf_cleanup:
drivers/net/wireless/ath/ath6kl/main.c +18 -4
index 3b2a7e8..717ed22 100644
@@ -673,10 +673,12 @@ void ath6kl_ready_event(void *devt, u8 *datap, u32 sw_ver, u32 abi_ver)
 	set_bit(WMI_READY, &ar->flag);
 	wake_up(&ar->event_wq);
 
-	ath6kl_info("hw %s fw %s%s\n",
-		    get_hw_id_string(ar->wiphy->hw_version),
-		    ar->wiphy->fw_version,
-		    test_bit(TESTMODE, &ar->flag) ? " testmode" : "");
+	if (test_and_clear_bit(FIRST_BOOT, &ar->flag)) {
+		ath6kl_info("hw %s fw %s%s\n",
+			    get_hw_id_string(ar->wiphy->hw_version),
+			    ar->wiphy->fw_version,
+			    test_bit(TESTMODE, &ar->flag) ? " testmode" : "");
+	}
 }
 
 void ath6kl_scan_complete_evt(struct ath6kl_vif *vif, int status)
@@ -1112,6 +1114,12 @@ struct ath6kl_vif *ath6kl_vif_first(struct ath6kl *ar)
 static int ath6kl_open(struct net_device *dev)
 {
 	struct ath6kl_vif *vif = netdev_priv(dev);
+	int ret;
+
+	/* FIXME: how to handle multi vif support? */
+	ret = ath6kl_init_hw_start(vif->ar);
+	if (ret)
+		return ret;
 
 	set_bit(WLAN_ENABLED, &vif->flags);
 
@@ -1128,6 +1136,7 @@ static int ath6kl_close(struct net_device *dev)
 {
 	struct ath6kl *ar = ath6kl_priv(dev);
 	struct ath6kl_vif *vif = netdev_priv(dev);
+	int ret;
 
 	netif_stop_queue(dev);
 
@@ -1143,6 +1152,11 @@ static int ath6kl_close(struct net_device *dev)
 
 	ath6kl_cfg80211_scan_complete_event(vif, -ECANCELED);
 
+	/* FIXME: how to handle multi vif support? */
+	ret = ath6kl_init_hw_stop(ar);
+	if (ret)
+		return ret;
+
 	return 0;
 }
 
author
#3 lore raw

PATCH 3/5 ath6kl: fix WLAN_ENABLE usage in ath6kl_close()

In reply to Kalle Valo

If ath6kl_init_hw_stop() failed with an error WLAN_ENABLED would not be cleared. Found during code review and just a theoretical issue.

---
 drivers/net/wireless/ath/ath6kl/main.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)
drivers/net/wireless/ath/ath6kl/main.c +2 -1
index 717ed22..def0b7f 100644
@@ -1147,7 +1147,6 @@ static int ath6kl_close(struct net_device *dev)
 					      0, 0, 0, 0, 0, 0, 0, 0, 0))
 			return -EIO;
 
-		clear_bit(WLAN_ENABLED, &vif->flags);
 	}
 
 	ath6kl_cfg80211_scan_complete_event(vif, -ECANCELED);
@@ -1157,6 +1156,8 @@ static int ath6kl_close(struct net_device *dev)
 	if (ret)
 		return ret;
 
+	clear_bit(WLAN_ENABLED, &vif->flags);
+
 	return 0;
 }
 
author
#4 lore raw

PATCH 4/5 ath6kl: print firmware crashes always

In reply to Kalle Valo

Currently firmware crash dump is printed only if debug is enabled. Change it so that the crash dump is always printed.

Also move the code from init.c to hif.c.

---
 drivers/net/wireless/ath/ath6kl/core.h |    1 
 drivers/net/wireless/ath/ath6kl/hif.c  |   69 ++++++++++++++++++++++++++++----
 drivers/net/wireless/ath/ath6kl/init.c |   55 --------------------------
 3 files changed, 61 insertions(+), 64 deletions(-)
drivers/net/wireless/ath/ath6kl/core.h +0 -1
index 1ac0dd1..95aed7d 100644
@@ -654,7 +654,6 @@ void aggr_recv_delba_req_evt(struct ath6kl_vif *vif, u8 tid);
 void aggr_recv_addba_req_evt(struct ath6kl_vif *vif, u8 tid, u16 seq_no,
 			     u8 win_sz);
 void ath6kl_wakeup_event(void *dev);
-void ath6kl_target_failure(struct ath6kl *ar);
 
 void ath6kl_reset_device(struct ath6kl *ar, u32 target_type,
 			 bool wait_fot_compltn, bool cold_reset);
drivers/net/wireless/ath/ath6kl/hif.c +61 -8

87 lines not on this page · raw message

drivers/net/wireless/ath/ath6kl/init.c +0 -55

61 lines not on this page · raw message

author
#5 lore raw

PATCH 5/5 ath6kl: print seqno in htc debug logs

In reply to Kalle Valo

Makes it easier to debug where frames are going.

---
 drivers/net/wireless/ath/ath6kl/htc.c |   11 +++++++----
 1 files changed, 7 insertions(+), 4 deletions(-)
drivers/net/wireless/ath/ath6kl/htc.c +7 -4
index 99220d4..f3b63ca 100644
@@ -439,6 +439,9 @@ static void htc_tx_comp_handler(struct htc_target *target,
 	struct htc_endpoint *endpoint = &target->endpoint[packet->endpoint];
 	struct list_head container;
 
+	ath6kl_dbg(ATH6KL_DBG_HTC, "htc tx complete seqno %d\n",
+		   packet->info.tx.seqno);
+
 	htc_tx_comp_update(target, endpoint, packet);
 	INIT_LIST_HEAD(&container);
 	list_add_tail(&packet->list, &container);
@@ -501,8 +504,8 @@ static int ath6kl_htc_tx_issue(struct htc_target *target,
 	padded_len = CALC_TXRX_PADDED_LEN(target, send_len);
 
 	ath6kl_dbg(ATH6KL_DBG_HTC,
-		   "htc tx issue len %d padded_len %d mbox 0x%X %s\n",
-		   send_len, padded_len,
+		   "htc tx issue len %d seqno %d padded_len %d mbox 0x%X %s\n",
+		   send_len, packet->info.tx.seqno, padded_len,
 		   target->dev->ar->mbox_info.htc_addr,
 		   sync ? "sync" : "async");
 
@@ -705,8 +708,8 @@ static int ath6kl_htc_tx_setup_scat_list(struct htc_target *target,
 		scat_req->len += len;
 		scat_req->scat_entries++;
 		ath6kl_dbg(ATH6KL_DBG_HTC,
-			   "htc tx adding (%d) pkt 0x%p len %d remaining %d\n",
-			   i, packet, len, rem_scat);
+			   "htc tx adding (%d) pkt 0x%p seqno %d len %d remaining %d\n",
+			   i, packet, packet->info.tx.seqno, len, rem_scat);
 	}
 
 	/* Roll back scatter setup in case of any failure */
author
#6 lore raw
In reply to Kalle Valo
Quoted 11 lines · Kalle Valo

The following series changes interface handling so that power is cut from the chip whenever interface is down compared to the current situation when the harware is powered all the time since module is loaded.

I'm not really sure if this is going be the final implementation but I'll send this for review anyway. I structured the code so that it's easy to go back to the old functionality if we so desire.

Also I need to solve support for multivif. Currently these patches work as there's only one vif.

Applied all five.

Kalle