Skip to contentSkip to conversation

mwl8k: add firmware files for 8366

PATCH NAK Brian Cavagnolo 3 participants 30 messages Nov 2, 2010 – Nov 13, 2010

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/7 mwl8k: add firmware files for 8366

From: Nishant Sarmukadam <[email protected]>

Add Helper image, client image (4.1.0.3) and ap image (5.2.6.6)

---
 firmware/Makefile                      |    2 +
 firmware/mwl8k/fmimage_8366.fw.ihex    | 6044 ++++++++++++++++++++++++++++++
 firmware/mwl8k/fmimage_8366_ap.fw.ihex | 6365 ++++++++++++++++++++++++++++++++
 firmware/mwl8k/helper_8366.fw.ihex     |  156 +
 4 files changed, 12567 insertions(+), 0 deletions(-)
 create mode 100644 firmware/mwl8k/fmimage_8366.fw.ihex
 create mode 100644 firmware/mwl8k/fmimage_8366_ap.fw.ihex
 create mode 100644 firmware/mwl8k/helper_8366.fw.ihex
firmware/Makefile +2 -0
index 74d47cd..0c8a771 100644
@@ -68,6 +68,8 @@ fw-shipped-$(CONFIG_DVB_AV7110) += av7110/bootcode.bin
 fw-shipped-$(CONFIG_DVB_TTUSB_BUDGET) += ttusb-budget/dspbootcode.bin
 fw-shipped-$(CONFIG_E100) += e100/d101m_ucode.bin e100/d101s_ucode.bin \
 			     e100/d102e_ucode.bin
+fw-shipped-$(CONFIG_MWL8K) += mwl8k/helper_8366.fw mwl8k/fmimage_8366_ap.fw \
+			      mwl8k/fmimage_8366.fw
 fw-shipped-$(CONFIG_MYRI_SBUS) += myricom/lanai.bin
 fw-shipped-$(CONFIG_PCMCIA_PCNET) += cis/LA-PCM.cis cis/PCMLM28.cis \
 				     cis/DP83903.cis cis/NE2K.cis \
firmware/mwl8k/fmimage_8366.fw.ihex new file +6044 -0

2,992 lines not on this page · raw message

firmware/mwl8k/fmimage_8366_ap.fw.ihex new file +6365 -0

6,365 lines not on this page · raw message

firmware/mwl8k/helper_8366.fw.ihex new file +156 -0

156 lines not on this page · raw message

The rest of this diff is not shown. View the raw message.

Signature · 1 line
1.7.1.1

Part of the diff is not shown here. View the raw message.

#1 lore raw

PATCH 2/7 mwl8k: rf_tx_power cmd deprecated for AP firmware

From: Nishant Sarmukadam <[email protected]>

For AP firmware, rf_tx_power command has been deprecated and replaced by tx_power command.

---
 drivers/net/wireless/mwl8k.c |   78 ++++++++++++++++++++++++++++++++++++++---
 1 files changed, 72 insertions(+), 6 deletions(-)
drivers/net/wireless/mwl8k.c +72 -6
index f152a25..cfda87a 100644
@@ -285,8 +285,9 @@ static const struct ieee80211_rate mwl8k_rates_50[] = {
 };
 
 /* Set or get info from Firmware */
-#define MWL8K_CMD_SET			0x0001
 #define MWL8K_CMD_GET			0x0000
+#define MWL8K_CMD_SET			0x0001
+#define MWL8K_CMD_SET_LIST		0x0002
 
 /* Firmware command codes */
 #define MWL8K_CMD_CODE_DNLD		0x0001
@@ -296,6 +297,7 @@ static const struct ieee80211_rate mwl8k_rates_50[] = {
 #define MWL8K_CMD_GET_STAT		0x0014
 #define MWL8K_CMD_RADIO_CONTROL		0x001c
 #define MWL8K_CMD_RF_TX_POWER		0x001e
+#define MWL8K_CMD_TX_POWER		0x001f
 #define MWL8K_CMD_RF_ANTENNA		0x0020
 #define MWL8K_CMD_SET_BEACON		0x0100		/* per-vif */
 #define MWL8K_CMD_SET_PRE_SCAN		0x0107
@@ -333,6 +335,7 @@ static const char *mwl8k_cmd_name(__le16 cmd, char *buf, int bufsize)
 		MWL8K_CMDNAME(GET_STAT);
 		MWL8K_CMDNAME(RADIO_CONTROL);
 		MWL8K_CMDNAME(RF_TX_POWER);
+		MWL8K_CMDNAME(TX_POWER);
 		MWL8K_CMDNAME(RF_ANTENNA);
 		MWL8K_CMDNAME(SET_BEACON);
 		MWL8K_CMDNAME(SET_PRE_SCAN);
@@ -2084,7 +2087,7 @@ mwl8k_set_radio_preamble(struct ieee80211_hw *hw, bool short_preamble)
 /*
  * CMD_RF_TX_POWER.
  */
-#define MWL8K_TX_POWER_LEVEL_TOTAL	8
+#define MWL8K_RF_TX_POWER_LEVEL_TOTAL	8
 
 struct mwl8k_cmd_rf_tx_power {
 	struct mwl8k_cmd_pkt header;
@@ -2092,7 +2095,7 @@ struct mwl8k_cmd_rf_tx_power {
 	__le16 support_level;
 	__le16 current_level;
 	__le16 reserved;
-	__le16 power_level_list[MWL8K_TX_POWER_LEVEL_TOTAL];
+	__le16 power_level_list[MWL8K_RF_TX_POWER_LEVEL_TOTAL];
 } __packed;
 
 static int mwl8k_cmd_rf_tx_power(struct ieee80211_hw *hw, int dBm)
@@ -2116,6 +2119,65 @@ static int mwl8k_cmd_rf_tx_power(struct ieee80211_hw *hw, int dBm)
 }
 
 /*
+ * CMD_TX_POWER.
+ */
+#define MWL8K_TX_POWER_LEVEL_TOTAL      12
+
+struct mwl8k_cmd_tx_power {
+	struct mwl8k_cmd_pkt header;
+	__le16 action;
+	__le16 band;
+	__le16 channel;
+	__le16 bw;
+	__le16 sub_ch;
+	__le16 power_level_list[MWL8K_TX_POWER_LEVEL_TOTAL];
+} __attribute__((packed));
+
+static int mwl8k_cmd_tx_power(struct ieee80211_hw *hw,
+				     struct ieee80211_conf *conf,
+				     unsigned short pwr)
+{
+	struct ieee80211_channel *channel = conf->channel;
+	struct mwl8k_cmd_tx_power *cmd;
+	int rc;
+	int i;
+
+	cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
+	if (cmd == NULL)
+		return -ENOMEM;
+
+	cmd->header.code = cpu_to_le16(MWL8K_CMD_TX_POWER);
+	cmd->header.length = cpu_to_le16(sizeof(*cmd));
+	cmd->action = cpu_to_le16(MWL8K_CMD_SET_LIST);
+
+	if (channel->band == IEEE80211_BAND_2GHZ)
+		cmd->band = cpu_to_le16(0x1);
+	else if (channel->band == IEEE80211_BAND_5GHZ)
+		cmd->band = cpu_to_le16(0x4);
+
+	cmd->channel = channel->hw_value;
+
+	if (conf->channel_type == NL80211_CHAN_NO_HT ||
+	    conf->channel_type == NL80211_CHAN_HT20) {
+		cmd->bw = cpu_to_le16(0x2);
+	} else {
+		cmd->bw = cpu_to_le16(0x4);
+		if (conf->channel_type == NL80211_CHAN_HT40MINUS)
+			cmd->sub_ch = cpu_to_le16(0x3);
+		else if (conf->channel_type == NL80211_CHAN_HT40PLUS)
+			cmd->sub_ch = cpu_to_le16(0x1);
+	}
+
+	for (i = 0; i < MWL8K_TX_POWER_LEVEL_TOTAL; i++)
+		cmd->power_level_list[i] = cpu_to_le16(pwr);
+
+	rc = mwl8k_post_cmd(hw, &cmd->header);
+	kfree(cmd);
+
+	return rc;
+}
+
+/*
  * CMD_RF_ANTENNA.
  */
 struct mwl8k_cmd_rf_antenna {
@@ -3377,15 +3439,19 @@ static int mwl8k_config(struct ieee80211_hw *hw, u32 changed)
 
 	if (conf->power_level > 18)
 		conf->power_level = 18;
-	rc = mwl8k_cmd_rf_tx_power(hw, conf->power_level);
-	if (rc)
-		goto out;
 
 	if (priv->ap_fw) {
+		rc = mwl8k_cmd_tx_power(hw, conf, conf->power_level);
+		if (rc)
+			goto out;
+
 		rc = mwl8k_cmd_rf_antenna(hw, MWL8K_RF_ANTENNA_RX, 0x7);
 		if (!rc)
 			rc = mwl8k_cmd_rf_antenna(hw, MWL8K_RF_ANTENNA_TX, 0x7);
 	} else {
+		rc = mwl8k_cmd_rf_tx_power(hw, conf->power_level);
+		if (rc)
+			goto out;
 		rc = mwl8k_cmd_mimo_config(hw, 0x7, 0x7);
 	}
 
Signature · 1 line
1.7.1.1
#2 lore raw

Re: [PATCH 2/7] mwl8k: rf_tx_power cmd deprecated for AP firmware

Quoted 4 lines · Brian Cavagnolo

From: Nishant Sarmukadam <[email protected]>

For AP firmware, rf_tx_power command has been deprecated and replaced by tx_power command.

The commit message is misleading: s/deprecated/removed/.

Also, command names go in capitals.

#3 lore raw

PATCH 3/7 mwl8k: allow for padding in AP transmit descriptor

In reply to Brian Cavagnolo

From: Pradeep Nemavat <[email protected]>

The AP transmit descriptor has padding of 20 bytes at the end of the descriptor. This padding is not used by mwl8k driver but it still has to be accounted for while calculating the size of the descriptor in order to calculate start of next descriptor. Allow for different transmit descriptor size due to padding for AP transmit descriptor.

---
 drivers/net/wireless/mwl8k.c |   32 ++++++++++++++++++++++++--------
 1 files changed, 24 insertions(+), 8 deletions(-)
drivers/net/wireless/mwl8k.c +24 -8
index cfda87a..9d614b8 100644
@@ -121,7 +121,8 @@ struct mwl8k_tx_queue {
 	int tail;
 
 	unsigned int len;
-	struct mwl8k_tx_desc *txd;
+	void *txd;
+
 	dma_addr_t txd_dma;
 	struct sk_buff **skb;
 };
@@ -210,6 +211,9 @@ struct mwl8k_priv {
 
 	/* Most recently reported noise in dBm */
 	s8 noise;
+
+	/* Size of the tx descriptor for the currently loaded firmware */
+	unsigned short txd_size;
 };
 
 /* Per interface specific private data */
@@ -1116,6 +1120,15 @@ static int rxq_process(struct ieee80211_hw *hw, int index, int limit)
 #define MWL8K_QOS_ACK_POLICY_BLOCKACK		0x0060
 #define MWL8K_QOS_EOSP				0x0010
 
+/*
+ * The size of the tx descriptors used by the firmware varies depending on
+ * whether we use AP firmware or STA firmware.  However, the fields used by
+ * this driver are identical, so the difference in size is treated as padding
+ * at the end of the structure.
+ */
+#define MWL8K_TX_DESC_SIZE_STA			32
+#define MWL8K_TX_DESC_SIZE_AP			52
+
 struct mwl8k_tx_desc {
 	__le32 status;
 	__u8 data_rate;
@@ -1144,7 +1157,7 @@ static int mwl8k_txq_init(struct ieee80211_hw *hw, int index)
 	txq->head = 0;
 	txq->tail = 0;
 
-	size = MWL8K_TX_DESCS * sizeof(struct mwl8k_tx_desc);
+	size = MWL8K_TX_DESCS * priv->txd_size;
 
 	txq->txd = pci_alloc_consistent(priv->pdev, size, &txq->txd_dma);
 	if (txq->txd == NULL) {
@@ -1165,12 +1178,12 @@ static int mwl8k_txq_init(struct ieee80211_hw *hw, int index)
 		struct mwl8k_tx_desc *tx_desc;
 		int nexti;
 
-		tx_desc = txq->txd + i;
+		tx_desc = txq->txd + i * priv->txd_size;
 		nexti = (i + 1) % MWL8K_TX_DESCS;
 
 		tx_desc->status = 0;
 		tx_desc->next_txd_phys_addr =
-			cpu_to_le32(txq->txd_dma + nexti * sizeof(*tx_desc));
+			cpu_to_le32(txq->txd_dma + nexti * priv->txd_size);
 	}
 
 	return 0;
@@ -1198,9 +1211,10 @@ static void mwl8k_dump_tx_rings(struct ieee80211_hw *hw)
 		int desc;
 
 		for (desc = 0; desc < MWL8K_TX_DESCS; desc++) {
-			struct mwl8k_tx_desc *tx_desc = txq->txd + desc;
+			struct mwl8k_tx_desc *tx_desc;
 			u32 status;
 
+			tx_desc = txq->txd + desc * priv->txd_size;
 			status = le32_to_cpu(tx_desc->status);
 			if (status & MWL8K_TXD_STATUS_FW_OWNED)
 				fw_owned++;
@@ -1309,7 +1323,7 @@ mwl8k_txq_reclaim(struct ieee80211_hw *hw, int index, int limit, int force)
 		u32 status;
 
 		tx = txq->head;
-		tx_desc = txq->txd + tx;
+		tx_desc = txq->txd + tx * priv->txd_size;
 
 		status = le32_to_cpu(tx_desc->status);
 
@@ -1367,7 +1381,7 @@ static void mwl8k_txq_deinit(struct ieee80211_hw *hw, int index)
 	txq->skb = NULL;
 
 	pci_free_consistent(priv->pdev,
-			    MWL8K_TX_DESCS * sizeof(struct mwl8k_tx_desc),
+			    MWL8K_TX_DESCS * priv->txd_size,
 			    txq->txd, txq->txd_dma);
 	txq->txd = NULL;
 }
@@ -1440,7 +1454,7 @@ mwl8k_txq_xmit(struct ieee80211_hw *hw, int index, struct sk_buff *skb)
 	BUG_ON(txq->skb[txq->tail] != NULL);
 	txq->skb[txq->tail] = skb;
 
-	tx = txq->txd + txq->tail;
+	tx = txq->txd + txq->tail * priv->txd_size;
 	tx->data_rate = txdatarate;
 	tx->tx_priority = index;
 	tx->qos_control = cpu_to_le16(qos);
@@ -4038,8 +4052,10 @@ static int __devinit mwl8k_probe(struct pci_dev *pdev,
 				  "Driver does not have AP firmware image support for this hardware\n");
 			goto err_stop_firmware;
 		}
+		priv->txd_size = MWL8K_TX_DESC_SIZE_AP;
 	} else {
 		priv->rxd_ops = &rxd_sta_ops;
+		priv->txd_size = MWL8K_TX_DESC_SIZE_STA;
 	}
 
 	priv->sniffer_enabled = false;
Signature · 1 line
1.7.1.1
#4 lore raw

Re: [PATCH 3/7] mwl8k: allow for padding in AP transmit descriptor

drivers/net/wireless/mwl8k.c static int rxq_process(struct ieee80211_hw *hw, int index, int limit) · line 1130

Quoted 8 lines · Brian Cavagnolo
drivers/net/wireless/mwl8k.c +8 -0
+/*
+ * The size of the tx descriptors used by the firmware varies depending on
+ * whether we use AP firmware or STA firmware.  However, the fields used by
+ * this driver are identical, so the difference in size is treated as padding
+ * at the end of the structure.
+ */
+#define MWL8K_TX_DESC_SIZE_STA			32
+#define MWL8K_TX_DESC_SIZE_AP			52

This is misleading, if not downright a lie.

Only the STA firmware branch bothers to mostly keep a degree of ABI compatibility -- the TX descriptor for STA firmware images is 32 bytes, no matter whether you're on 8687, 8363, or 8366.

(I like this very much about STA firmware -- it meant I could take the 8687 STA driver and run it on 8363 and 8366 STA with hardly any changes. And there's reports that mwl8k runs on 8361P STA with almost no patching needed either.)

But the AP firmware branch changes stuff around all the time, as the AP people generally supply their driver along with the firmware, and can make concurrent changes to those while not having to give a damn about the other users of their firmware.

E.g., the format of the SET_MAC_ADDR command packet changing if you're compiling the AP firmware for multi-BSS (a 16 bit field is added in the _middle_ of the command packet if you do that, see mwl8k_cmd_set_mac_addr) -- and changing the TX descriptor format is another one of those things.

The reason that the AP TX descriptor for 8366 is 52 bytes is not because it has been defined to be such, but because the "official" AP driver for 8366 just so happens, at this moment, to have 20 bytes of driver-private info for every TX packet, which it stashes into the TX descriptor (that doesn't even make any sense either, but hey). If next week they decide they need 4 more bytes for driver-private info, they'll just bump it to 56, and we'll be left to pick up the pieces.

So this

Quoted 1 line

+#define MWL8K_TX_DESC_SIZE_AP 52

is very misleading, as:

- It suggests that something is set in stone which isn't set in stone at all.
- It only applies to this particular 8366 AP image, and might not apply to other 8366 AP images or even AP images in general.

In other words, it's just a quick hack to get things to work for one more HW/firmware/version combo, but it doesn't solve the problem in a clean way or in general. (Then again, you probably don't care about that anyway.)

Since you're being paid by Marvell to do this, please tell them that this nonsense needs to stop, and that they need to add something to the firmware so that the driver can figure out what options the firmware has been built with, or include some way that we can reliably figure out which ABI variation to use to talk to the firmware.

#5 lore raw

PATCH 4/7 mwl8k: force AP mode to use non-AMPDU frames

In reply to Brian Cavagnolo

From: Nishant Sarmukadam <[email protected]>

AP firmware uses xmitcontrol to differentiate between AMPDU and non-AMPDU frames. As the support for AMPDU is not yet added, set xmitcontrol to non-AMPDU for all tx frames for AP firmware. This field will be set to indicate ampdu/non-ampdu frames when tx AMPDU support is added.

---
 drivers/net/wireless/mwl8k.c |    7 ++++++-
 1 files changed, 6 insertions(+), 1 deletions(-)
drivers/net/wireless/mwl8k.c +6 -1
index 9d614b8..99cc48d 100644
@@ -1141,10 +1141,12 @@ struct mwl8k_tx_desc {
 	__le32 reserved;
 	__le16 rate_info;
 	__u8 peer_id;
-	__u8 tx_frag_cnt;
+	__u8 xmitcontrol;
 } __packed;
 
 #define MWL8K_TX_DESCS		128
+#define MWL8K_XMITCONTROL_NON_AMPDU	0x04
+
 
 static int mwl8k_txq_init(struct ieee80211_hw *hw, int index)
 {
@@ -1465,6 +1467,9 @@ mwl8k_txq_xmit(struct ieee80211_hw *hw, int index, struct sk_buff *skb)
 		tx->peer_id = MWL8K_STA(tx_info->control.sta)->peer_id;
 	else
 		tx->peer_id = 0;
+
+	if (priv->ap_fw)
+		tx->xmitcontrol = MWL8K_XMITCONTROL_NON_AMPDU;
 	wmb();
 	tx->status = cpu_to_le32(MWL8K_TXD_STATUS_FW_OWNED | txstatus);
 
Signature · 1 line
1.7.1.1
Acked-by on v1 4/7
#6 lore raw

Re: [PATCH 4/7] mwl8k: force AP mode to use non-AMPDU frames

Quoted 10 lines · Brian Cavagnolo

From: Nishant Sarmukadam <[email protected]>

AP firmware uses xmitcontrol to differentiate between AMPDU and non-AMPDU frames. As the support for AMPDU is not yet added, set xmitcontrol to non-AMPDU for all tx frames for AP firmware. This field will be set to indicate ampdu/non-ampdu frames when tx AMPDU support is added.

It's still pretty dumb of the firmware to require that the driver tell the firmware _again_ (it already has that info) whether a TX packet is part of an AMPDU session or not, but I guess this requirement is set in stone now.

I'm still not happy that it just does this blindly based on whether the image is an AP firmware image or not (earlier AP images did not require this).

Ideally they'd just replace the firmware people by ones that have some taste, but that probably won't happen.

#7 lore raw

PATCH 5/7 mwl8k: factor out firmware loading and hw init code

In reply to Brian Cavagnolo

This is in preparation for supporting different fw images for different interface types.

Based on a patch from Pradeep Nemavat <[email protected]>

---
 drivers/net/wireless/mwl8k.c |  265 +++++++++++++++++++++++-------------------
 1 files changed, 148 insertions(+), 117 deletions(-)
drivers/net/wireless/mwl8k.c +148 -117
index 99cc48d..bbf8222 100644
@@ -3961,6 +3961,142 @@ static DEFINE_PCI_DEVICE_TABLE(mwl8k_pci_id_table) = {
 };
 MODULE_DEVICE_TABLE(pci, mwl8k_pci_id_table);
 
+static int mwl8k_init_firmware(struct ieee80211_hw *hw)
+{
+	struct mwl8k_priv *priv = hw->priv;
+	int rc;
+
+	/* Reset firmware and hardware */
+	mwl8k_hw_reset(priv);
+
+	/* Ask userland hotplug daemon for the device firmware */
+	rc = mwl8k_request_firmware(priv);
+	if (rc) {
+		wiphy_err(hw->wiphy, "Firmware files not found\n");
+		return rc;
+	}
+
+	/* Load firmware into hardware */
+	rc = mwl8k_load_firmware(hw);
+	if (rc)
+		wiphy_err(hw->wiphy, "Cannot start firmware\n");
+
+	/* Reclaim memory once firmware is successfully loaded */
+	mwl8k_release_firmware(priv);
+
+	return rc;
+}
+
+/* initialize hw after successfully loading a firmware image */
+static int mwl8k_probe_hw(struct ieee80211_hw *hw)
+{
+	struct mwl8k_priv *priv = hw->priv;
+	int rc = 0;
+	int i;
+
+	if (priv->ap_fw) {
+		priv->rxd_ops = priv->device_info->ap_rxd_ops;
+		if (priv->rxd_ops == NULL) {
+			wiphy_err(hw->wiphy,
+				  "Driver does not have AP firmware image support for this hardware\n");
+			goto err_stop_firmware;
+		}
+		priv->txd_size = MWL8K_TX_DESC_SIZE_AP;
+	} else {
+		priv->rxd_ops = &rxd_sta_ops;
+		priv->txd_size = MWL8K_TX_DESC_SIZE_STA;
+	}
+
+	priv->sniffer_enabled = false;
+	priv->wmm_enabled = false;
+	priv->pending_tx_pkts = 0;
+
+	rc = mwl8k_rxq_init(hw, 0);
+	if (rc)
+		goto err_stop_firmware;
+	rxq_refill(hw, 0, INT_MAX);
+
+	for (i = 0; i < MWL8K_TX_QUEUES; i++) {
+		rc = mwl8k_txq_init(hw, i);
+		if (rc)
+			goto err_free_queues;
+	}
+
+	iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS);
+	iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
+	iowrite32(MWL8K_A2H_INT_TX_DONE | MWL8K_A2H_INT_RX_READY,
+		  priv->regs + MWL8K_HIU_A2H_INTERRUPT_CLEAR_SEL);
+	iowrite32(0xffffffff, priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS_MASK);
+
+	rc = request_irq(priv->pdev->irq, mwl8k_interrupt,
+			 IRQF_SHARED, MWL8K_NAME, hw);
+	if (rc) {
+		wiphy_err(hw->wiphy, "failed to register IRQ handler\n");
+		goto err_free_queues;
+	}
+
+	/*
+	 * Temporarily enable interrupts.  Initial firmware host
+	 * commands use interrupts and avoid polling.  Disable
+	 * interrupts when done.
+	 */
+	iowrite32(MWL8K_A2H_EVENTS, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
+
+	/* Get config data, mac addrs etc */
+	if (priv->ap_fw) {
+		rc = mwl8k_cmd_get_hw_spec_ap(hw);
+		if (!rc)
+			rc = mwl8k_cmd_set_hw_spec(hw);
+	} else {
+		rc = mwl8k_cmd_get_hw_spec_sta(hw);
+	}
+	if (rc) {
+		wiphy_err(hw->wiphy, "Cannot initialise firmware\n");
+		goto err_free_irq;
+	}
+
+	/* Turn radio off */
+	rc = mwl8k_cmd_radio_disable(hw);
+	if (rc) {
+		wiphy_err(hw->wiphy, "Cannot disable\n");
+		goto err_free_irq;
+	}
+
+	/* Clear MAC address */
+	rc = mwl8k_cmd_set_mac_addr(hw, NULL, "\x00\x00\x00\x00\x00\x00");
+	if (rc) {
+		wiphy_err(hw->wiphy, "Cannot clear MAC address\n");
+		goto err_free_irq;
+	}
+
+	/* Disable interrupts */
+	iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
+	free_irq(priv->pdev->irq, hw);
+
+	wiphy_info(hw->wiphy, "%s v%d, %pm, %s firmware %u.%u.%u.%u\n",
+		   priv->device_info->part_name,
+		   priv->hw_rev, hw->wiphy->perm_addr,
+		   priv->ap_fw ? "AP" : "STA",
+		   (priv->fw_rev >> 24) & 0xff, (priv->fw_rev >> 16) & 0xff,
+		   (priv->fw_rev >> 8) & 0xff, priv->fw_rev & 0xff);
+
+	return 0;
+
+err_free_irq:
+	iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
+	free_irq(priv->pdev->irq, hw);
+
+err_free_queues:
+	for (i = 0; i < MWL8K_TX_QUEUES; i++)
+		mwl8k_txq_deinit(hw, i);
+	mwl8k_rxq_deinit(hw, 0);
+
+err_stop_firmware:
+	mwl8k_hw_reset(priv);
+
+	return rc;
+}
+
 static int __devinit mwl8k_probe(struct pci_dev *pdev,
 				 const struct pci_device_id *id)
 {
@@ -4028,45 +4164,9 @@ static int __devinit mwl8k_probe(struct pci_dev *pdev,
 		}
 	}
 
-
-	/* Reset firmware and hardware */
-	mwl8k_hw_reset(priv);
-
-	/* Ask userland hotplug daemon for the device firmware */
-	rc = mwl8k_request_firmware(priv);
-	if (rc) {
-		wiphy_err(hw->wiphy, "Firmware files not found\n");
-		goto err_stop_firmware;
-	}
-
-	/* Load firmware into hardware */
-	rc = mwl8k_load_firmware(hw);
-	if (rc) {
-		wiphy_err(hw->wiphy, "Cannot start firmware\n");
+	rc = mwl8k_init_firmware(hw);
+	if (rc)
 		goto err_stop_firmware;
-	}
-
-	/* Reclaim memory once firmware is successfully loaded */
-	mwl8k_release_firmware(priv);
-
-
-	if (priv->ap_fw) {
-		priv->rxd_ops = priv->device_info->ap_rxd_ops;
-		if (priv->rxd_ops == NULL) {
-			wiphy_err(hw->wiphy,
-				  "Driver does not have AP firmware image support for this hardware\n");
-			goto err_stop_firmware;
-		}
-		priv->txd_size = MWL8K_TX_DESC_SIZE_AP;
-	} else {
-		priv->rxd_ops = &rxd_sta_ops;
-		priv->txd_size = MWL8K_TX_DESC_SIZE_STA;
-	}
-
-	priv->sniffer_enabled = false;
-	priv->wmm_enabled = false;
-	priv->pending_tx_pkts = 0;
-
 
 	/*
 	 * Extra headroom is the size of the required DMA header
@@ -4102,13 +4202,10 @@ static int __devinit mwl8k_probe(struct pci_dev *pdev,
 
 	/* Power management cookie */
 	priv->cookie = pci_alloc_consistent(priv->pdev, 4, &priv->cookie_dma);
-	if (priv->cookie == NULL)
+	if (priv->cookie == NULL) {
+		rc = -ENOMEM;
 		goto err_stop_firmware;
-
-	rc = mwl8k_rxq_init(hw, 0);
-	if (rc)
-		goto err_free_cookie;
-	rxq_refill(hw, 0, INT_MAX);
+	}
 
 	mutex_init(&priv->fw_mutex);
 	priv->fw_mutex_owner = NULL;
@@ -4119,90 +4216,25 @@ static int __devinit mwl8k_probe(struct pci_dev *pdev,
 
 	priv->tx_wait = NULL;
 
-	for (i = 0; i < MWL8K_TX_QUEUES; i++) {
-		rc = mwl8k_txq_init(hw, i);
-		if (rc)
-			goto err_free_queues;
-	}
-
-	iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS);
-	iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
-	iowrite32(MWL8K_A2H_INT_TX_DONE | MWL8K_A2H_INT_RX_READY,
-		  priv->regs + MWL8K_HIU_A2H_INTERRUPT_CLEAR_SEL);
-	iowrite32(0xffffffff, priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS_MASK);
-
-	rc = request_irq(priv->pdev->irq, mwl8k_interrupt,
-			 IRQF_SHARED, MWL8K_NAME, hw);
-	if (rc) {
-		wiphy_err(hw->wiphy, "failed to register IRQ handler\n");
-		goto err_free_queues;
-	}
-
-	/*
-	 * Temporarily enable interrupts.  Initial firmware host
-	 * commands use interrupts and avoid polling.  Disable
-	 * interrupts when done.
-	 */
-	iowrite32(MWL8K_A2H_EVENTS, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
-
-	/* Get config data, mac addrs etc */
-	if (priv->ap_fw) {
-		rc = mwl8k_cmd_get_hw_spec_ap(hw);
-		if (!rc)
-			rc = mwl8k_cmd_set_hw_spec(hw);
-	} else {
-		rc = mwl8k_cmd_get_hw_spec_sta(hw);
-	}
-	if (rc) {
-		wiphy_err(hw->wiphy, "Cannot initialise firmware\n");
-		goto err_free_irq;
-	}
+	rc = mwl8k_probe_hw(hw);
+	if (rc)
+		goto err_free_cookie;
 
 	hw->wiphy->interface_modes = 0;
-	if (priv->ap_macids_supported)
+	if (priv->ap_macids_supported || priv->device_info->fw_image_ap)
 		hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_AP);
-	if (priv->sta_macids_supported)
+	if (priv->sta_macids_supported || priv->device_info->fw_image_sta)
 		hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_STATION);
 
-
-	/* Turn radio off */
-	rc = mwl8k_cmd_radio_disable(hw);
-	if (rc) {
-		wiphy_err(hw->wiphy, "Cannot disable\n");
-		goto err_free_irq;
-	}
-
-	/* Clear MAC address */
-	rc = mwl8k_cmd_set_mac_addr(hw, NULL, "\x00\x00\x00\x00\x00\x00");
-	if (rc) {
-		wiphy_err(hw->wiphy, "Cannot clear MAC address\n");
-		goto err_free_irq;
-	}
-
-	/* Disable interrupts */
-	iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
-	free_irq(priv->pdev->irq, hw);
-
 	rc = ieee80211_register_hw(hw);
 	if (rc) {
 		wiphy_err(hw->wiphy, "Cannot register device\n");
-		goto err_free_queues;
+		goto err_unprobe_hw;
 	}
 
-	wiphy_info(hw->wiphy, "%s v%d, %pm, %s firmware %u.%u.%u.%u\n",
-		   priv->device_info->part_name,
-		   priv->hw_rev, hw->wiphy->perm_addr,
-		   priv->ap_fw ? "AP" : "STA",
-		   (priv->fw_rev >> 24) & 0xff, (priv->fw_rev >> 16) & 0xff,
-		   (priv->fw_rev >> 8) & 0xff, priv->fw_rev & 0xff);
-
 	return 0;
 
-err_free_irq:
-	iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
-	free_irq(priv->pdev->irq, hw);
-
-err_free_queues:
+err_unprobe_hw:
 	for (i = 0; i < MWL8K_TX_QUEUES; i++)
 		mwl8k_txq_deinit(hw, i);
 	mwl8k_rxq_deinit(hw, 0);
@@ -4214,7 +4246,6 @@ err_free_cookie:
 
 err_stop_firmware:
 	mwl8k_hw_reset(priv);
-	mwl8k_release_firmware(priv);
 
 err_iounmap:
 	if (priv->regs != NULL)
Signature · 1 line
1.7.1.1
#9 lore raw

PATCH 6/7 mwl8k: choose proper firmware image as directed by user

In reply to Brian Cavagnolo

The mwl8k can operate in AP or STA mode, depending on the firmware image that is loaded. Allow the user to specify the desired firmware image at module load time.

Also, the firmware image can be swapped to meet the user's add_interface request. For example, suppose the STA firmware is loaded, no STA interface has been added, and the user adds an AP interface. In this case, the AP firmware will be loaded to meet the request.

Based on a patch from Pradeep Nemavat <[email protected]>

---
 drivers/net/wireless/mwl8k.c |  127 ++++++++++++++++++++++++++++++++++++++----
 1 files changed, 115 insertions(+), 12 deletions(-)
drivers/net/wireless/mwl8k.c +115 -12
index bbf8222..1368e5c 100644
@@ -29,6 +29,11 @@
 #define MWL8K_NAME	KBUILD_MODNAME
 #define MWL8K_VERSION	"0.12"
 
+/* Module parameters */
+static unsigned want_ap_fw;
+module_param(want_ap_fw, bool, 0);
+MODULE_PARM_DESC(want_ap_fw, "Set to 1 to default to ap fw instead of sta fw");
+
 /* Register definitions */
 #define MWL8K_HIU_GEN_PTR			0x00000c10
 #define  MWL8K_MODE_STA				 0x0000005a
@@ -92,7 +97,8 @@ struct rxd_ops {
 struct mwl8k_device_info {
 	char *part_name;
 	char *helper_image;
-	char *fw_image;
+	char *fw_image_sta;
+	char *fw_image_ap;
 	struct rxd_ops *ap_rxd_ops;
 };
 
@@ -214,6 +220,12 @@ struct mwl8k_priv {
 
 	/* Size of the tx descriptor for the currently loaded firmware */
 	unsigned short txd_size;
+
+	/*
+	 * preserve the queue configurations so they can be restored if/when
+	 * the firmware image is swapped.
+	 */
+	struct ieee80211_tx_queue_params wmm_params[MWL8K_TX_QUEUES];
 };
 
 /* Per interface specific private data */
@@ -405,7 +417,7 @@ static int mwl8k_request_fw(struct mwl8k_priv *priv,
 				fname, &priv->pdev->dev);
 }
 
-static int mwl8k_request_firmware(struct mwl8k_priv *priv)
+static int mwl8k_request_firmware(struct mwl8k_priv *priv, char *fw_image)
 {
 	struct mwl8k_device_info *di = priv->device_info;
 	int rc;
@@ -420,10 +432,10 @@ static int mwl8k_request_firmware(struct mwl8k_priv *priv)
 		}
 	}
 
-	rc = mwl8k_request_fw(priv, di->fw_image, &priv->fw_ucode);
+	rc = mwl8k_request_fw(priv, fw_image, &priv->fw_ucode);
 	if (rc) {
 		printk(KERN_ERR "%s: Error requesting firmware file %s\n",
-		       pci_name(priv->pdev), di->fw_image);
+		       pci_name(priv->pdev), fw_image);
 		mwl8k_release_fw(&priv->fw_helper);
 		return rc;
 	}
@@ -3364,13 +3376,16 @@ static void mwl8k_stop(struct ieee80211_hw *hw)
 		mwl8k_txq_reclaim(hw, i, INT_MAX, 1);
 }
 
+static int mwl8k_reload_firmware(struct ieee80211_hw *hw, char *fw_image);
+
 static int mwl8k_add_interface(struct ieee80211_hw *hw,
 			       struct ieee80211_vif *vif)
 {
 	struct mwl8k_priv *priv = hw->priv;
 	struct mwl8k_vif *mwl8k_vif;
 	u32 macids_supported;
-	int macid;
+	int macid, rc;
+	struct mwl8k_device_info *di;
 
 	/*
 	 * Reject interface creation if sniffer mode is active, as
@@ -3383,12 +3398,28 @@ static int mwl8k_add_interface(struct ieee80211_hw *hw,
 		return -EINVAL;
 	}
 
-
+	di = priv->device_info;
 	switch (vif->type) {
 	case NL80211_IFTYPE_AP:
+		if (!priv->ap_fw && di->fw_image_ap) {
+			/* we must load the ap fw to meet this request */
+			if (!list_empty(&priv->vif_list))
+				return -EBUSY;
+			rc = mwl8k_reload_firmware(hw, di->fw_image_ap);
+			if (rc)
+				return rc;
+		}
 		macids_supported = priv->ap_macids_supported;
 		break;
 	case NL80211_IFTYPE_STATION:
+		if (priv->ap_fw && di->fw_image_sta) {
+			/* we must load the sta fw to meet this request */
+			if (!list_empty(&priv->vif_list))
+				return -EBUSY;
+			rc = mwl8k_reload_firmware(hw, di->fw_image_sta);
+			if (rc)
+				return rc;
+		}
 		macids_supported = priv->sta_macids_supported;
 		break;
 	default:
@@ -3824,6 +3855,9 @@ static int mwl8k_conf_tx(struct ieee80211_hw *hw, u16 queue,
 
 	rc = mwl8k_fw_lock(hw);
 	if (!rc) {
+		BUG_ON(queue > MWL8K_TX_QUEUES - 1);
+		memcpy(&priv->wmm_params[queue], params, sizeof(*params));
+
 		if (!priv->wmm_enabled)
 			rc = mwl8k_cmd_set_wmm_mode(hw, 1);
 
@@ -3927,17 +3961,18 @@ static struct mwl8k_device_info mwl8k_info_tbl[] __devinitdata = {
 	[MWL8363] = {
 		.part_name	= "88w8363",
 		.helper_image	= "mwl8k/helper_8363.fw",
-		.fw_image	= "mwl8k/fmimage_8363.fw",
+		.fw_image_sta	= "mwl8k/fmimage_8363.fw",
 	},
 	[MWL8687] = {
 		.part_name	= "88w8687",
 		.helper_image	= "mwl8k/helper_8687.fw",
-		.fw_image	= "mwl8k/fmimage_8687.fw",
+		.fw_image_sta	= "mwl8k/fmimage_8687.fw",
 	},
 	[MWL8366] = {
 		.part_name	= "88w8366",
 		.helper_image	= "mwl8k/helper_8366.fw",
-		.fw_image	= "mwl8k/fmimage_8366.fw",
+		.fw_image_sta	= "mwl8k/fmimage_8366.fw",
+		.fw_image_ap	= "mwl8k/fmimage_8366_ap.fw",
 		.ap_rxd_ops	= &rxd_8366_ap_ops,
 	},
 };
@@ -3961,7 +3996,7 @@ static DEFINE_PCI_DEVICE_TABLE(mwl8k_pci_id_table) = {
 };
 MODULE_DEVICE_TABLE(pci, mwl8k_pci_id_table);
 
-static int mwl8k_init_firmware(struct ieee80211_hw *hw)
+static int mwl8k_init_firmware(struct ieee80211_hw *hw, char *fw_image)
 {
 	struct mwl8k_priv *priv = hw->priv;
 	int rc;
@@ -3970,7 +4005,7 @@ static int mwl8k_init_firmware(struct ieee80211_hw *hw)
 	mwl8k_hw_reset(priv);
 
 	/* Ask userland hotplug daemon for the device firmware */
-	rc = mwl8k_request_firmware(priv);
+	rc = mwl8k_request_firmware(priv, fw_image);
 	if (rc) {
 		wiphy_err(hw->wiphy, "Firmware files not found\n");
 		return rc;
@@ -4097,12 +4132,64 @@ err_stop_firmware:
 	return rc;
 }
 
+/*
+ * invoke mwl8k_reload_firmware to change the firmware image after the device
+ * has already been registered
+ */
+static int mwl8k_reload_firmware(struct ieee80211_hw *hw, char *fw_image)
+{
+	int i, rc = 0;
+	struct mwl8k_priv *priv = hw->priv;
+
+	mwl8k_stop(hw);
+	mwl8k_rxq_deinit(hw, 0);
+
+	for (i = 0; i < MWL8K_TX_QUEUES; i++)
+		mwl8k_txq_deinit(hw, i);
+
+	rc = mwl8k_init_firmware(hw, fw_image);
+	if (rc)
+		goto fail;
+
+	rc = mwl8k_probe_hw(hw);
+	if (rc)
+		goto fail;
+
+	rc = mwl8k_start(hw);
+	if (rc)
+		goto fail;
+
+	rc = mwl8k_config(hw, ~0);
+	if (rc)
+		goto fail;
+
+	for (i = 0; i < MWL8K_TX_QUEUES; i++) {
+		rc = mwl8k_conf_tx(hw, i, &priv->wmm_params[i]);
+		if (rc)
+			goto fail;
+	}
+
+	printk(KERN_INFO "%s: %s v%d, %pM, %s firmware %u.%u.%u.%u\n",
+	       wiphy_name(hw->wiphy), priv->device_info->part_name,
+	       priv->hw_rev, hw->wiphy->perm_addr,
+	       priv->ap_fw ? "AP" : "STA",
+	       (priv->fw_rev >> 24) & 0xff, (priv->fw_rev >> 16) & 0xff,
+	       (priv->fw_rev >> 8) & 0xff, priv->fw_rev & 0xff);
+
+	return rc;
+
+fail:
+	printk(KERN_WARNING "mwl8k: Failed to reload firmware image.\n");
+	return rc;
+}
+
 static int __devinit mwl8k_probe(struct pci_dev *pdev,
 				 const struct pci_device_id *id)
 {
 	static int printed_version = 0;
 	struct ieee80211_hw *hw;
 	struct mwl8k_priv *priv;
+	struct mwl8k_device_info *di;
 	int rc;
 	int i;
 
@@ -4164,7 +4251,23 @@ static int __devinit mwl8k_probe(struct pci_dev *pdev,
 		}
 	}
 
-	rc = mwl8k_init_firmware(hw);
+	/*
+	 * Choose the initial fw image depending on user input and availability
+	 * of images.
+	 */
+	di = priv->device_info;
+	if (want_ap_fw && di->fw_image_ap)
+		rc = mwl8k_init_firmware(hw, di->fw_image_ap);
+	else if (!want_ap_fw && di->fw_image_sta)
+		rc = mwl8k_init_firmware(hw, di->fw_image_sta);
+	else if (want_ap_fw && !di->fw_image_ap && di->fw_image_sta) {
+		printk(KERN_WARNING "AP fw is unavailable.  Using STA fw.");
+		rc = mwl8k_init_firmware(hw, di->fw_image_sta);
+	} else if (!want_ap_fw && !di->fw_image_sta && di->fw_image_ap) {
+		printk(KERN_WARNING "STA fw is unavailable.  Using AP fw.");
+		rc = mwl8k_init_firmware(hw, di->fw_image_ap);
+	} else
+		rc = mwl8k_init_firmware(hw, di->fw_image_sta);
 	if (rc)
 		goto err_stop_firmware;
 
Signature · 1 line
1.7.1.1
#10 lore raw

Re: [PATCH 6/7] mwl8k: choose proper firmware image as directed by user

Quoted 3 lines · Brian Cavagnolo

The mwl8k can operate in AP or STA mode, depending on the firmware image that is loaded. Allow the user to specify the desired firmware image at module load time.

Strong NAK on selecting firmware image type with a module parameter, that's so wrong it's not even funny.

Just use the STA image before ->add_interface() has been called if it is available.

And please switch to async firmware loading while you're at it.

Quoted 7 lines

Also, the firmware image can be swapped to meet the user's add_interface request. For example, suppose the STA firmware is loaded, no STA interface has been added, and the user adds an AP interface. In this case, the AP firmware will be loaded to meet the request.

Based on a patch from Pradeep Nemavat <[email protected]>

Which was suggested by Lennert Buytenhek -- please give credit where it is due.

#11 lore raw

Re: [PATCH 6/7] mwl8k: choose proper firmware image as directed by user

Quoted 11 lines · Lennert Buytenhek
Quoted 3 lines · Brian Cavagnolo

The mwl8k can operate in AP or STA mode, depending on the firmware image that is loaded.  Allow the user to specify the desired firmware image at module load time.

Strong NAK on selecting firmware image type with a module parameter, that's so wrong it's not even funny.

Just use the STA image before ->add_interface() has been called if it is available.

The intention here is to save users who wish to only operate in AP mode from sustaining an unnecessary firmware re-load. Can you elaborate on why it is unacceptable to achieve this with a module parameter? Perhaps just calling it ap_mode instead of want_ap_fw makes more sense?

Quoted 1 line

And please switch to async firmware loading while you're at it.

Okay.

Quoted 11 lines
Quoted 7 lines

Also, the firmware image can be swapped to meet the user's add_interface request.  For example, suppose the STA firmware is loaded, no STA interface has been added, and the user adds an AP interface.  In this case, the AP firmware will be loaded to meet the request.

Based on a patch from Pradeep Nemavat <[email protected]>

Which was suggested by Lennert Buytenhek -- please give credit where it is due.

My apologies. Understood.

#12 lore raw

PATCH 7/7 mac80211: unset SDATA_STATE_OFFCHANNEL when cancelling a scan

In reply to Brian Cavagnolo

For client STA interfaces, ieee80211_do_stop unsets the relevant interface's SDATA_STATE_RUNNING state bit prior to cancelling an interrupted scan. When ieee80211_offchannel_return is invoked as part of cancelling the scan, it doesn't bother unsetting the SDATA_STATE_OFFCHANNEL bit because it sees that the interface is down. Normally this doesn't matter because when the client STA interface is brought back up, it will probably issue a scan. But in some cases (e.g., the user changes the interface type while it is down), the SDATA_STATE_OFFCHANNEL bit will remain set. This prevents the interface queues from being started. So we unconditionally unset this bit when we cancel a scan.

---
 net/mac80211/offchannel.c |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)
net/mac80211/offchannel.c +3 -1
index 4b56409..6252a76 100644
@@ -156,8 +156,10 @@ void ieee80211_offchannel_return(struct ieee80211_local *local,
 
 	mutex_lock(&local->iflist_mtx);
 	list_for_each_entry(sdata, &local->interfaces, list) {
-		if (!ieee80211_sdata_running(sdata))
+		if (!ieee80211_sdata_running(sdata)) {
+			clear_bit(SDATA_STATE_OFFCHANNEL, &sdata->state);
 			continue;
+		}
 
 		/* Tell AP we're back */
 		if (sdata->vif.type == NL80211_IFTYPE_STATION) {
Signature · 1 line
1.7.1.1
#13 lore raw

Re: [PATCH 7/7] mac80211: unset SDATA_STATE_OFFCHANNEL when cancelling a scan

Quoted 11 lines · Brian Cavagnolo

For client STA interfaces, ieee80211_do_stop unsets the relevant interface's SDATA_STATE_RUNNING state bit prior to cancelling an interrupted scan. When ieee80211_offchannel_return is invoked as part of cancelling the scan, it doesn't bother unsetting the SDATA_STATE_OFFCHANNEL bit because it sees that the interface is down. Normally this doesn't matter because when the client STA interface is brought back up, it will probably issue a scan. But in some cases (e.g., the user changes the interface type while it is down), the SDATA_STATE_OFFCHANNEL bit will remain set. This prevents the interface queues from being started. So we unconditionally unset this bit when we cancel a scan.

How does this patch fit into the series?

#14 lore raw

Re: [PATCH 7/7] mac80211: unset SDATA_STATE_OFFCHANNEL when cancelling a scan

Quoted 14 lines · Lennert Buytenhek
Quoted 11 lines · Brian Cavagnolo

For client STA interfaces, ieee80211_do_stop unsets the relevant interface's SDATA_STATE_RUNNING state bit prior to cancelling an interrupted scan.  When ieee80211_offchannel_return is invoked as part of cancelling the scan, it doesn't bother unsetting the SDATA_STATE_OFFCHANNEL bit because it sees that the interface is down.  Normally this doesn't matter because when the client STA interface is brought back up, it will probably issue a scan.  But in some cases (e.g., the user changes the interface type while it is down), the SDATA_STATE_OFFCHANNEL bit will remain set.  This prevents the interface queues from being started.  So we unconditionally unset this bit when we cancel a scan.

Quoted 2 lines

How does this patch fit into the series?

Sorry. That should have gone to Johannes. I'll resubmit.

#16 lore raw
Quoted 6 lines · Lennert Buytenhek
Quoted 4 lines · Brian Cavagnolo

From: Nishant Sarmukadam <[email protected]>

Add Helper image, client image (4.1.0.3) and ap image (5.2.6.6)

Quoted 8 lines
Quoted 2 lines

NAK, for obvious reasons.

Also, spamming thousands of people's inboxes with 500kb firmware patches is generally not a nice thing to do.

Well, patches containing hundreds of kB of binary firmware do pass through this mailing list. However, a closer inspection reveals that these were destined for the linux-firmware with linux-wireless CC'd. My bad. When I resubmit I'll do it that way.

maintainer
#17 lore raw
Quoted 4 lines · Brian Cavagnolo

Well, patches containing hundreds of kB of binary firmware do pass through this mailing list. However, a closer inspection reveals that these were destined for the linux-firmware with linux-wireless CC'd. My bad. When I resubmit I'll do it that way.

Before you do that though, you really really need to fix this patch to not add the firmware to the _kernel_ tree, but to the _firmware_ tree. Including a proper license for them, of course, and not as ihex crap, etc.

johannes

#18 lore raw
Quoted 11 lines · Johannes Berg
Quoted 4 lines · Brian Cavagnolo

Well, patches containing hundreds of kB of binary firmware do pass through this mailing list.  However, a closer inspection reveals that these were destined for the linux-firmware with linux-wireless CC'd. My bad.  When I resubmit I'll do it that way.

Before you do that though, you really really need to fix this patch to not add the firmware to the _kernel_ tree, but to the _firmware_ tree. Including a proper license for them, of course, and not as ihex crap, etc.

Understood. This is underway.

Ciao,
Brian

#19 lore raw
In reply to Brian Cavagnolo
Quoted 7 lines · Brian Cavagnolo
Quoted 7 lines
Quoted 6 lines

From: Nishant Sarmukadam <[email protected]>

Add Helper image, client image (4.1.0.3) and ap image (5.2.6.6)

Quoted 7 lines
Quoted 4 lines

NAK, for obvious reasons.

Also, spamming thousands of people's inboxes with 500kb firmware patches is generally not a nice thing to do.

Well, patches containing hundreds of kB of binary firmware do pass through this mailing list.

Not through linux-wireless@.

Quoted 2 lines

However, a closer inspection reveals that these were destined for the linux-firmware with linux-wireless CC'd.

Since they are patching different things, they shouldn't even be in the same patch series anyway.

#20 lore raw

v2 cover mwl8k: add initial support for AP firmware on 8366

In reply to Brian Cavagnolo

Hello Lennert,

The other contributors to this upstream effort and I understand and share the concern you expressed about the future interoperability of this driver with other firmware/hardware combos. So this V2 patchset is accompanied by an updated firmware image that will be submitted to linux-firmware shortly*. The changes include:

-- the unused padding in the TX descriptor has been eliminated.

-- the firmware no longer repurposes the tx_frag_cnt member of
the common tx descriptor.

-- The GET_HW_CAPS command for the AP firmware now reports the
API version of the firmware.

It is reasonable to expect that all future mwl8k AP firmwares released to the linux-firmware tree will have this API version field. It is also reasonable to expect that future firmwares for future mwl8k chips supported by Marvell will either a) require no changes to the mwl8k driver that would break existing released firmware/hw combos, or b) will have a different API version number. The API version number can then be used to select different hw capabilities, different internal and external ops as needed, etc.

* The reason for not submitting the firmware immediately is that other forces are at work consolidating all Marvell firmware images in linux-firmware under a single license. We figured it would be best to submit under the new unified license. In the meantime, if anybody needs the fw, just email me.

#21 lore raw

PATCH v2 1/7 mwl8k: revert unnecessary modification of tx descriptor

In reply to Brian Cavagnolo

This reverts change 783391c443728febc669e40597193308460e7b4f. The stabilized AP v1 firmware uses the same tx descriptor as the STA firmware.

---
 drivers/net/wireless/mwl8k.c |    7 +------
 1 files changed, 1 insertions(+), 6 deletions(-)
drivers/net/wireless/mwl8k.c +1 -6
index 1bbcd7c..f152a25 100644
@@ -1125,12 +1125,10 @@ struct mwl8k_tx_desc {
 	__le32 reserved;
 	__le16 rate_info;
 	__u8 peer_id;
-	__u8 xmitcontrol;
+	__u8 tx_frag_cnt;
 } __packed;
 
 #define MWL8K_TX_DESCS		128
-#define MWL8K_XMITCONTROL_NON_AMPDU	0x04
-
 
 static int mwl8k_txq_init(struct ieee80211_hw *hw, int index)
 {
@@ -1450,9 +1448,6 @@ mwl8k_txq_xmit(struct ieee80211_hw *hw, int index, struct sk_buff *skb)
 		tx->peer_id = MWL8K_STA(tx_info->control.sta)->peer_id;
 	else
 		tx->peer_id = 0;
-
-	if (priv->ap_fw)
-		tx->xmitcontrol = MWL8K_XMITCONTROL_NON_AMPDU;
 	wmb();
 	tx->status = cpu_to_le32(MWL8K_TXD_STATUS_FW_OWNED | txstatus);
 
Signature · 1 line
1.7.1.1
#22 lore raw

PATCH v2 2/7 mwl8k: rf_tx_power cmd not supported by AP firmware APIv1

In reply to Brian Cavagnolo

From: Nishant Sarmukadam <[email protected]>

APIv1 AP firmware does not support the RF_TX_POWER command. It supports the similar TX_POWER command.

---
 drivers/net/wireless/mwl8k.c |   78 ++++++++++++++++++++++++++++++++++++++---
 1 files changed, 72 insertions(+), 6 deletions(-)
drivers/net/wireless/mwl8k.c +72 -6
index f152a25..cfda87a 100644
@@ -285,8 +285,9 @@ static const struct ieee80211_rate mwl8k_rates_50[] = {
 };
 
 /* Set or get info from Firmware */
-#define MWL8K_CMD_SET			0x0001
 #define MWL8K_CMD_GET			0x0000
+#define MWL8K_CMD_SET			0x0001
+#define MWL8K_CMD_SET_LIST		0x0002
 
 /* Firmware command codes */
 #define MWL8K_CMD_CODE_DNLD		0x0001
@@ -296,6 +297,7 @@ static const struct ieee80211_rate mwl8k_rates_50[] = {
 #define MWL8K_CMD_GET_STAT		0x0014
 #define MWL8K_CMD_RADIO_CONTROL		0x001c
 #define MWL8K_CMD_RF_TX_POWER		0x001e
+#define MWL8K_CMD_TX_POWER		0x001f
 #define MWL8K_CMD_RF_ANTENNA		0x0020
 #define MWL8K_CMD_SET_BEACON		0x0100		/* per-vif */
 #define MWL8K_CMD_SET_PRE_SCAN		0x0107
@@ -333,6 +335,7 @@ static const char *mwl8k_cmd_name(__le16 cmd, char *buf, int bufsize)
 		MWL8K_CMDNAME(GET_STAT);
 		MWL8K_CMDNAME(RADIO_CONTROL);
 		MWL8K_CMDNAME(RF_TX_POWER);
+		MWL8K_CMDNAME(TX_POWER);
 		MWL8K_CMDNAME(RF_ANTENNA);
 		MWL8K_CMDNAME(SET_BEACON);
 		MWL8K_CMDNAME(SET_PRE_SCAN);
@@ -2084,7 +2087,7 @@ mwl8k_set_radio_preamble(struct ieee80211_hw *hw, bool short_preamble)
 /*
  * CMD_RF_TX_POWER.
  */
-#define MWL8K_TX_POWER_LEVEL_TOTAL	8
+#define MWL8K_RF_TX_POWER_LEVEL_TOTAL	8
 
 struct mwl8k_cmd_rf_tx_power {
 	struct mwl8k_cmd_pkt header;
@@ -2092,7 +2095,7 @@ struct mwl8k_cmd_rf_tx_power {
 	__le16 support_level;
 	__le16 current_level;
 	__le16 reserved;
-	__le16 power_level_list[MWL8K_TX_POWER_LEVEL_TOTAL];
+	__le16 power_level_list[MWL8K_RF_TX_POWER_LEVEL_TOTAL];
 } __packed;
 
 static int mwl8k_cmd_rf_tx_power(struct ieee80211_hw *hw, int dBm)
@@ -2116,6 +2119,65 @@ static int mwl8k_cmd_rf_tx_power(struct ieee80211_hw *hw, int dBm)
 }
 
 /*
+ * CMD_TX_POWER.
+ */
+#define MWL8K_TX_POWER_LEVEL_TOTAL      12
+
+struct mwl8k_cmd_tx_power {
+	struct mwl8k_cmd_pkt header;
+	__le16 action;
+	__le16 band;
+	__le16 channel;
+	__le16 bw;
+	__le16 sub_ch;
+	__le16 power_level_list[MWL8K_TX_POWER_LEVEL_TOTAL];
+} __attribute__((packed));
+
+static int mwl8k_cmd_tx_power(struct ieee80211_hw *hw,
+				     struct ieee80211_conf *conf,
+				     unsigned short pwr)
+{
+	struct ieee80211_channel *channel = conf->channel;
+	struct mwl8k_cmd_tx_power *cmd;
+	int rc;
+	int i;
+
+	cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
+	if (cmd == NULL)
+		return -ENOMEM;
+
+	cmd->header.code = cpu_to_le16(MWL8K_CMD_TX_POWER);
+	cmd->header.length = cpu_to_le16(sizeof(*cmd));
+	cmd->action = cpu_to_le16(MWL8K_CMD_SET_LIST);
+
+	if (channel->band == IEEE80211_BAND_2GHZ)
+		cmd->band = cpu_to_le16(0x1);
+	else if (channel->band == IEEE80211_BAND_5GHZ)
+		cmd->band = cpu_to_le16(0x4);
+
+	cmd->channel = channel->hw_value;
+
+	if (conf->channel_type == NL80211_CHAN_NO_HT ||
+	    conf->channel_type == NL80211_CHAN_HT20) {
+		cmd->bw = cpu_to_le16(0x2);
+	} else {
+		cmd->bw = cpu_to_le16(0x4);
+		if (conf->channel_type == NL80211_CHAN_HT40MINUS)
+			cmd->sub_ch = cpu_to_le16(0x3);
+		else if (conf->channel_type == NL80211_CHAN_HT40PLUS)
+			cmd->sub_ch = cpu_to_le16(0x1);
+	}
+
+	for (i = 0; i < MWL8K_TX_POWER_LEVEL_TOTAL; i++)
+		cmd->power_level_list[i] = cpu_to_le16(pwr);
+
+	rc = mwl8k_post_cmd(hw, &cmd->header);
+	kfree(cmd);
+
+	return rc;
+}
+
+/*
  * CMD_RF_ANTENNA.
  */
 struct mwl8k_cmd_rf_antenna {
@@ -3377,15 +3439,19 @@ static int mwl8k_config(struct ieee80211_hw *hw, u32 changed)
 
 	if (conf->power_level > 18)
 		conf->power_level = 18;
-	rc = mwl8k_cmd_rf_tx_power(hw, conf->power_level);
-	if (rc)
-		goto out;
 
 	if (priv->ap_fw) {
+		rc = mwl8k_cmd_tx_power(hw, conf, conf->power_level);
+		if (rc)
+			goto out;
+
 		rc = mwl8k_cmd_rf_antenna(hw, MWL8K_RF_ANTENNA_RX, 0x7);
 		if (!rc)
 			rc = mwl8k_cmd_rf_antenna(hw, MWL8K_RF_ANTENNA_TX, 0x7);
 	} else {
+		rc = mwl8k_cmd_rf_tx_power(hw, conf->power_level);
+		if (rc)
+			goto out;
 		rc = mwl8k_cmd_mimo_config(hw, 0x7, 0x7);
 	}
 
Signature · 1 line
1.7.1.1
#23 lore raw

PATCH v2 3/7 mwl8k: factor out firmware loading and hw init code

In reply to Brian Cavagnolo

This is in preparation for supporting different fw images for different interface types, and for supporting asynchronous firmware loading.

Based on a patch from Pradeep Nemavat <[email protected]> and Yogesh Powar <[email protected]>

---
 drivers/net/wireless/mwl8k.c |  345 ++++++++++++++++++++++++++----------------
 1 files changed, 214 insertions(+), 131 deletions(-)
drivers/net/wireless/mwl8k.c +214 -131
index cfda87a..7bd8615 100644
@@ -3942,73 +3942,10 @@ static DEFINE_PCI_DEVICE_TABLE(mwl8k_pci_id_table) = {
 };
 MODULE_DEVICE_TABLE(pci, mwl8k_pci_id_table);
 
-static int __devinit mwl8k_probe(struct pci_dev *pdev,
-				 const struct pci_device_id *id)
+static int mwl8k_init_firmware(struct ieee80211_hw *hw)
 {
-	static int printed_version = 0;
-	struct ieee80211_hw *hw;
-	struct mwl8k_priv *priv;
+	struct mwl8k_priv *priv = hw->priv;
 	int rc;
-	int i;
-
-	if (!printed_version) {
-		printk(KERN_INFO "%s version %s\n", MWL8K_DESC, MWL8K_VERSION);
-		printed_version = 1;
-	}
-
-
-	rc = pci_enable_device(pdev);
-	if (rc) {
-		printk(KERN_ERR "%s: Cannot enable new PCI device\n",
-		       MWL8K_NAME);
-		return rc;
-	}
-
-	rc = pci_request_regions(pdev, MWL8K_NAME);
-	if (rc) {
-		printk(KERN_ERR "%s: Cannot obtain PCI resources\n",
-		       MWL8K_NAME);
-		goto err_disable_device;
-	}
-
-	pci_set_master(pdev);
-
-
-	hw = ieee80211_alloc_hw(sizeof(*priv), &mwl8k_ops);
-	if (hw == NULL) {
-		printk(KERN_ERR "%s: ieee80211 alloc failed\n", MWL8K_NAME);
-		rc = -ENOMEM;
-		goto err_free_reg;
-	}
-
-	SET_IEEE80211_DEV(hw, &pdev->dev);
-	pci_set_drvdata(pdev, hw);
-
-	priv = hw->priv;
-	priv->hw = hw;
-	priv->pdev = pdev;
-	priv->device_info = &mwl8k_info_tbl[id->driver_data];
-
-
-	priv->sram = pci_iomap(pdev, 0, 0x10000);
-	if (priv->sram == NULL) {
-		wiphy_err(hw->wiphy, "Cannot map device SRAM\n");
-		goto err_iounmap;
-	}
-
-	/*
-	 * If BAR0 is a 32 bit BAR, the register BAR will be BAR1.
-	 * If BAR0 is a 64 bit BAR, the register BAR will be BAR2.
-	 */
-	priv->regs = pci_iomap(pdev, 1, 0x10000);
-	if (priv->regs == NULL) {
-		priv->regs = pci_iomap(pdev, 2, 0x10000);
-		if (priv->regs == NULL) {
-			wiphy_err(hw->wiphy, "Cannot map device registers\n");
-			goto err_iounmap;
-		}
-	}
-
 
 	/* Reset firmware and hardware */
 	mwl8k_hw_reset(priv);
@@ -4017,19 +3954,26 @@ static int __devinit mwl8k_probe(struct pci_dev *pdev,
 	rc = mwl8k_request_firmware(priv);
 	if (rc) {
 		wiphy_err(hw->wiphy, "Firmware files not found\n");
-		goto err_stop_firmware;
+		return rc;
 	}
 
 	/* Load firmware into hardware */
 	rc = mwl8k_load_firmware(hw);
-	if (rc) {
+	if (rc)
 		wiphy_err(hw->wiphy, "Cannot start firmware\n");
-		goto err_stop_firmware;
-	}
 
 	/* Reclaim memory once firmware is successfully loaded */
 	mwl8k_release_firmware(priv);
 
+	return rc;
+}
+
+/* initialize hw after successfully loading a firmware image */
+static int mwl8k_probe_hw(struct ieee80211_hw *hw)
+{
+	struct mwl8k_priv *priv = hw->priv;
+	int rc = 0;
+	int i;
 
 	if (priv->ap_fw) {
 		priv->rxd_ops = priv->device_info->ap_rxd_ops;
@@ -4046,58 +3990,11 @@ static int __devinit mwl8k_probe(struct pci_dev *pdev,
 	priv->wmm_enabled = false;
 	priv->pending_tx_pkts = 0;
 
-
-	/*
-	 * Extra headroom is the size of the required DMA header
-	 * minus the size of the smallest 802.11 frame (CTS frame).
-	 */
-	hw->extra_tx_headroom =
-		sizeof(struct mwl8k_dma_data) - sizeof(struct ieee80211_cts);
-
-	hw->channel_change_time = 10;
-
-	hw->queues = MWL8K_TX_QUEUES;
-
-	/* Set rssi values to dBm */
-	hw->flags |= IEEE80211_HW_SIGNAL_DBM;
-	hw->vif_data_size = sizeof(struct mwl8k_vif);
-	hw->sta_data_size = sizeof(struct mwl8k_sta);
-
-	priv->macids_used = 0;
-	INIT_LIST_HEAD(&priv->vif_list);
-
-	/* Set default radio state and preamble */
-	priv->radio_on = 0;
-	priv->radio_short_preamble = 0;
-
-	/* Finalize join worker */
-	INIT_WORK(&priv->finalize_join_worker, mwl8k_finalize_join_worker);
-
-	/* TX reclaim and RX tasklets.  */
-	tasklet_init(&priv->poll_tx_task, mwl8k_tx_poll, (unsigned long)hw);
-	tasklet_disable(&priv->poll_tx_task);
-	tasklet_init(&priv->poll_rx_task, mwl8k_rx_poll, (unsigned long)hw);
-	tasklet_disable(&priv->poll_rx_task);
-
-	/* Power management cookie */
-	priv->cookie = pci_alloc_consistent(priv->pdev, 4, &priv->cookie_dma);
-	if (priv->cookie == NULL)
-		goto err_stop_firmware;
-
 	rc = mwl8k_rxq_init(hw, 0);
 	if (rc)
-		goto err_free_cookie;
+		goto err_stop_firmware;
 	rxq_refill(hw, 0, INT_MAX);
 
-	mutex_init(&priv->fw_mutex);
-	priv->fw_mutex_owner = NULL;
-	priv->fw_mutex_depth = 0;
-	priv->hostcmd_wait = NULL;
-
-	spin_lock_init(&priv->tx_lock);
-
-	priv->tx_wait = NULL;
-
 	for (i = 0; i < MWL8K_TX_QUEUES; i++) {
 		rc = mwl8k_txq_init(hw, i);
 		if (rc)
@@ -4137,13 +4034,6 @@ static int __devinit mwl8k_probe(struct pci_dev *pdev,
 		goto err_free_irq;
 	}
 
-	hw->wiphy->interface_modes = 0;
-	if (priv->ap_macids_supported)
-		hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_AP);
-	if (priv->sta_macids_supported)
-		hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_STATION);
-
-
 	/* Turn radio off */
 	rc = mwl8k_cmd_radio_disable(hw);
 	if (rc) {
@@ -4162,12 +4052,6 @@ static int __devinit mwl8k_probe(struct pci_dev *pdev,
 	iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
 	free_irq(priv->pdev->irq, hw);
 
-	rc = ieee80211_register_hw(hw);
-	if (rc) {
-		wiphy_err(hw->wiphy, "Cannot register device\n");
-		goto err_free_queues;
-	}
-
 	wiphy_info(hw->wiphy, "%s v%d, %pm, %s firmware %u.%u.%u.%u\n",
 		   priv->device_info->part_name,
 		   priv->hw_rev, hw->wiphy->perm_addr,
@@ -4186,14 +4070,213 @@ err_free_queues:
 		mwl8k_txq_deinit(hw, i);
 	mwl8k_rxq_deinit(hw, 0);
 
+err_stop_firmware:
+	mwl8k_hw_reset(priv);
+
+	return rc;
+}
+
+/*
+ * invoke mwl8k_reload_firmware to change the firmware image after the device
+ * has already been registered
+ */
+static int mwl8k_reload_firmware(struct ieee80211_hw *hw, char *fw_image)
+{
+	int i, rc = 0;
+	struct mwl8k_priv *priv = hw->priv;
+
+	mwl8k_stop(hw);
+	mwl8k_rxq_deinit(hw, 0);
+
+	for (i = 0; i < MWL8K_TX_QUEUES; i++)
+		mwl8k_txq_deinit(hw, i);
+
+	rc = mwl8k_init_firmware(hw, fw_image);
+	if (rc)
+		goto fail;
+
+	rc = mwl8k_probe_hw(hw);
+	if (rc)
+		goto fail;
+
+	rc = mwl8k_start(hw);
+	if (rc)
+		goto fail;
+
+	rc = mwl8k_config(hw, ~0);
+	if (rc)
+		goto fail;
+
+	for (i = 0; i < MWL8K_TX_QUEUES; i++) {
+		rc = mwl8k_conf_tx(hw, i, &priv->wmm_params[i]);
+		if (rc)
+			goto fail;
+	}
+
+	return rc;
+
+fail:
+	printk(KERN_WARNING "mwl8k: Failed to reload firmware image.\n");
+	return rc;
+}
+
+static int mwl8k_firmware_load_success(struct mwl8k_priv *priv)
+{
+	struct ieee80211_hw *hw = priv->hw;
+	int i, rc;
+
+	/*
+	 * Extra headroom is the size of the required DMA header
+	 * minus the size of the smallest 802.11 frame (CTS frame).
+	 */
+	hw->extra_tx_headroom =
+		sizeof(struct mwl8k_dma_data) - sizeof(struct ieee80211_cts);
+
+	hw->channel_change_time = 10;
+
+	hw->queues = MWL8K_TX_QUEUES;
+
+	/* Set rssi values to dBm */
+	hw->flags |= IEEE80211_HW_SIGNAL_DBM;
+	hw->vif_data_size = sizeof(struct mwl8k_vif);
+	hw->sta_data_size = sizeof(struct mwl8k_sta);
+
+	priv->macids_used = 0;
+	INIT_LIST_HEAD(&priv->vif_list);
+
+	/* Set default radio state and preamble */
+	priv->radio_on = 0;
+	priv->radio_short_preamble = 0;
+
+	/* Finalize join worker */
+	INIT_WORK(&priv->finalize_join_worker, mwl8k_finalize_join_worker);
+
+	/* TX reclaim and RX tasklets.  */
+	tasklet_init(&priv->poll_tx_task, mwl8k_tx_poll, (unsigned long)hw);
+	tasklet_disable(&priv->poll_tx_task);
+	tasklet_init(&priv->poll_rx_task, mwl8k_rx_poll, (unsigned long)hw);
+	tasklet_disable(&priv->poll_rx_task);
+
+	/* Power management cookie */
+	priv->cookie = pci_alloc_consistent(priv->pdev, 4, &priv->cookie_dma);
+	if (priv->cookie == NULL)
+		return -ENOMEM;
+
+	mutex_init(&priv->fw_mutex);
+	priv->fw_mutex_owner = NULL;
+	priv->fw_mutex_depth = 0;
+	priv->hostcmd_wait = NULL;
+
+	spin_lock_init(&priv->tx_lock);
+
+	priv->tx_wait = NULL;
+
+	rc = mwl8k_probe_hw(hw);
+	if (rc)
+		goto err_free_cookie;
+
+	hw->wiphy->interface_modes = 0;
+	if (priv->ap_macids_supported || priv->device_info->fw_image_ap)
+		hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_AP);
+	if (priv->sta_macids_supported || priv->device_info->fw_image_sta)
+		hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_STATION);
+
+	rc = ieee80211_register_hw(hw);
+	if (rc) {
+		wiphy_err(hw->wiphy, "Cannot register device\n");
+		goto err_unprobe_hw;
+	}
+
+	return 0;
+
+err_unprobe_hw:
+	for (i = 0; i < MWL8K_TX_QUEUES; i++)
+		mwl8k_txq_deinit(hw, i);
+	mwl8k_rxq_deinit(hw, 0);
+
 err_free_cookie:
 	if (priv->cookie != NULL)
 		pci_free_consistent(priv->pdev, 4,
 				priv->cookie, priv->cookie_dma);
 
+	return rc;
+}
+static int __devinit mwl8k_probe(struct pci_dev *pdev,
+				 const struct pci_device_id *id)
+{
+	static int printed_version;
+	struct ieee80211_hw *hw;
+	struct mwl8k_priv *priv;
+	int rc;
+
+	if (!printed_version) {
+		printk(KERN_INFO "%s version %s\n", MWL8K_DESC, MWL8K_VERSION);
+		printed_version = 1;
+	}
+
+
+	rc = pci_enable_device(pdev);
+	if (rc) {
+		printk(KERN_ERR "%s: Cannot enable new PCI device\n",
+		       MWL8K_NAME);
+		return rc;
+	}
+
+	rc = pci_request_regions(pdev, MWL8K_NAME);
+	if (rc) {
+		printk(KERN_ERR "%s: Cannot obtain PCI resources\n",
+		       MWL8K_NAME);
+		goto err_disable_device;
+	}
+
+	pci_set_master(pdev);
+
+
+	hw = ieee80211_alloc_hw(sizeof(*priv), &mwl8k_ops);
+	if (hw == NULL) {
+		printk(KERN_ERR "%s: ieee80211 alloc failed\n", MWL8K_NAME);
+		rc = -ENOMEM;
+		goto err_free_reg;
+	}
+
+	SET_IEEE80211_DEV(hw, &pdev->dev);
+	pci_set_drvdata(pdev, hw);
+
+	priv = hw->priv;
+	priv->hw = hw;
+	priv->pdev = pdev;
+	priv->device_info = &mwl8k_info_tbl[id->driver_data];
+
+
+	priv->sram = pci_iomap(pdev, 0, 0x10000);
+	if (priv->sram == NULL) {
+		wiphy_err(hw->wiphy, "Cannot map device SRAM\n");
+		goto err_iounmap;
+	}
+
+	/*
+	 * If BAR0 is a 32 bit BAR, the register BAR will be BAR1.
+	 * If BAR0 is a 64 bit BAR, the register BAR will be BAR2.
+	 */
+	priv->regs = pci_iomap(pdev, 1, 0x10000);
+	if (priv->regs == NULL) {
+		priv->regs = pci_iomap(pdev, 2, 0x10000);
+		if (priv->regs == NULL) {
+			wiphy_err(hw->wiphy, "Cannot map device registers\n");
+			goto err_iounmap;
+		}
+	}
+
+	rc = mwl8k_init_firmware(hw);
+	if (rc)
+		goto err_stop_firmware;
+
+	rc = mwl8k_firmware_load_success(priv);
+	if (!rc)
+		return rc;
+
 err_stop_firmware:
 	mwl8k_hw_reset(priv);
-	mwl8k_release_firmware(priv);
 
 err_iounmap:
 	if (priv->regs != NULL)
Signature · 1 line
1.7.1.1
#24 lore raw

Re: [PATCH V2 3/7] mwl8k: factor out firmware loading and hw init code

My apologies. This is also a V2 patch despite the subject.

Quoted 429 lines · Brian Cavagnolo

This is in preparation for supporting different fw images for different interface types, and for supporting asynchronous firmware loading.

Based on a patch from Pradeep Nemavat <[email protected]> and Yogesh Powar <[email protected]>

---
 drivers/net/wireless/mwl8k.c |  345 ++++++++++++++++++++++++++----------------

 1 files changed, 214 insertions(+), 131 deletions(-)
drivers/net/wireless/mwl8k.c +138 -130
index cfda87a..7bd8615 100644
@@ -3942,73 +3942,10 @@ static DEFINE_PCI_DEVICE_TABLE(mwl8k_pci_id_table) = {
  };
  MODULE_DEVICE_TABLE(pci, mwl8k_pci_id_table);
 
-static int __devinit mwl8k_probe(struct pci_dev *pdev,
-                                const struct pci_device_id *id)
+static int mwl8k_init_firmware(struct ieee80211_hw *hw)
  {
-       static int printed_version = 0;
-       struct ieee80211_hw *hw;
-       struct mwl8k_priv *priv;
+       struct mwl8k_priv *priv = hw->priv;
        int rc;
-       int i;
-
-       if (!printed_version) {
-               printk(KERN_INFO "%s version %s\n", MWL8K_DESC, MWL8K_VERSION);
-               printed_version = 1;
-       }
-
-
-       rc = pci_enable_device(pdev);
-       if (rc) {
-               printk(KERN_ERR "%s: Cannot enable new PCI device\n",
-                      MWL8K_NAME);
-               return rc;
-       }
-
-       rc = pci_request_regions(pdev, MWL8K_NAME);
-       if (rc) {
-               printk(KERN_ERR "%s: Cannot obtain PCI resources\n",
-                      MWL8K_NAME);
-               goto err_disable_device;
-       }
-
-       pci_set_master(pdev);
-
-
-       hw = ieee80211_alloc_hw(sizeof(*priv), &mwl8k_ops);
-       if (hw == NULL) {
-               printk(KERN_ERR "%s: ieee80211 alloc failed\n", MWL8K_NAME);
-               rc = -ENOMEM;
-               goto err_free_reg;
-       }
-
-       SET_IEEE80211_DEV(hw, &pdev->dev);
-       pci_set_drvdata(pdev, hw);
-
-       priv = hw->priv;
-       priv->hw = hw;
-       priv->pdev = pdev;
-       priv->device_info = &mwl8k_info_tbl[id->driver_data];
-
-
-       priv->sram = pci_iomap(pdev, 0, 0x10000);
-       if (priv->sram == NULL) {
-               wiphy_err(hw->wiphy, "Cannot map device SRAM\n");
-               goto err_iounmap;
-       }
-
-       /*
-        * If BAR0 is a 32 bit BAR, the register BAR will be BAR1.
-        * If BAR0 is a 64 bit BAR, the register BAR will be BAR2.
-        */
-       priv->regs = pci_iomap(pdev, 1, 0x10000);
-       if (priv->regs == NULL) {
-               priv->regs = pci_iomap(pdev, 2, 0x10000);
-               if (priv->regs == NULL) {
-                       wiphy_err(hw->wiphy, "Cannot map device registers\n");
-                       goto err_iounmap;
-               }
-       }
-
 
        /* Reset firmware and hardware */
        mwl8k_hw_reset(priv);
@@ -4017,19 +3954,26 @@ static int __devinit mwl8k_probe(struct pci_dev *pdev,
        rc = mwl8k_request_firmware(priv);
        if (rc) {
                wiphy_err(hw->wiphy, "Firmware files not found\n");
-               goto err_stop_firmware;
+               return rc;
        }
 
        /* Load firmware into hardware */
        rc = mwl8k_load_firmware(hw);
-       if (rc) {
+       if (rc)
                wiphy_err(hw->wiphy, "Cannot start firmware\n");
-               goto err_stop_firmware;
-       }
 
        /* Reclaim memory once firmware is successfully loaded */
        mwl8k_release_firmware(priv);
 
+       return rc;
+}
+
+/* initialize hw after successfully loading a firmware image */
+static int mwl8k_probe_hw(struct ieee80211_hw *hw)
+{
+       struct mwl8k_priv *priv = hw->priv;
+       int rc = 0;
+       int i;
 
        if (priv->ap_fw) {
                priv->rxd_ops = priv->device_info->ap_rxd_ops;
@@ -4046,58 +3990,11 @@ static int __devinit mwl8k_probe(struct pci_dev *pdev,
        priv->wmm_enabled = false;
        priv->pending_tx_pkts = 0;
 
-
-       /*
-        * Extra headroom is the size of the required DMA header
-        * minus the size of the smallest 802.11 frame (CTS frame).
-        */
-       hw->extra_tx_headroom =
-               sizeof(struct mwl8k_dma_data) - sizeof(struct ieee80211_cts);
-
-       hw->channel_change_time = 10;
-
-       hw->queues = MWL8K_TX_QUEUES;
-
-       /* Set rssi values to dBm */
-       hw->flags |= IEEE80211_HW_SIGNAL_DBM;
-       hw->vif_data_size = sizeof(struct mwl8k_vif);
-       hw->sta_data_size = sizeof(struct mwl8k_sta);
-
-       priv->macids_used = 0;
-       INIT_LIST_HEAD(&priv->vif_list);
-
-       /* Set default radio state and preamble */
-       priv->radio_on = 0;
-       priv->radio_short_preamble = 0;
-
-       /* Finalize join worker */
-       INIT_WORK(&priv->finalize_join_worker, mwl8k_finalize_join_worker);
-
-       /* TX reclaim and RX tasklets.  */
-       tasklet_init(&priv->poll_tx_task, mwl8k_tx_poll, (unsigned long)hw);
-       tasklet_disable(&priv->poll_tx_task);
-       tasklet_init(&priv->poll_rx_task, mwl8k_rx_poll, (unsigned long)hw);
-       tasklet_disable(&priv->poll_rx_task);
-
-       /* Power management cookie */
-       priv->cookie = pci_alloc_consistent(priv->pdev, 4, &priv->cookie_dma);
-       if (priv->cookie == NULL)
-               goto err_stop_firmware;
-
        rc = mwl8k_rxq_init(hw, 0);
        if (rc)
-               goto err_free_cookie;
+               goto err_stop_firmware;
        rxq_refill(hw, 0, INT_MAX);
 
-       mutex_init(&priv->fw_mutex);
-       priv->fw_mutex_owner = NULL;
-       priv->fw_mutex_depth = 0;
-       priv->hostcmd_wait = NULL;
-
-       spin_lock_init(&priv->tx_lock);
-
-       priv->tx_wait = NULL;
-
        for (i = 0; i < MWL8K_TX_QUEUES; i++) {
                rc = mwl8k_txq_init(hw, i);
                if (rc)
@@ -4137,13 +4034,6 @@ static int __devinit mwl8k_probe(struct pci_dev *pdev,
                goto err_free_irq;
        }
 
-       hw->wiphy->interface_modes = 0;
-       if (priv->ap_macids_supported)
-               hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_AP);
-       if (priv->sta_macids_supported)
-               hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_STATION);
-
-
        /* Turn radio off */
        rc = mwl8k_cmd_radio_disable(hw);
        if (rc) {
@@ -4162,12 +4052,6 @@ static int __devinit mwl8k_probe(struct pci_dev *pdev,
        iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
        free_irq(priv->pdev->irq, hw);
 
-       rc = ieee80211_register_hw(hw);
-       if (rc) {
-               wiphy_err(hw->wiphy, "Cannot register device\n");
-               goto err_free_queues;
-       }
-
        wiphy_info(hw->wiphy, "%s v%d, %pm, %s firmware %u.%u.%u.%u\n",
                   priv->device_info->part_name,
                   priv->hw_rev, hw->wiphy->perm_addr,
@@ -4186,14 +4070,213 @@ err_free_queues:
                mwl8k_txq_deinit(hw, i);
        mwl8k_rxq_deinit(hw, 0);
 
+err_stop_firmware:
+       mwl8k_hw_reset(priv);
+
+       return rc;
+}
+
+/*
+ * invoke mwl8k_reload_firmware to change the firmware image after the device
+ * has already been registered
+ */
+static int mwl8k_reload_firmware(struct ieee80211_hw *hw, char *fw_image)
+{
+       int i, rc = 0;
+       struct mwl8k_priv *priv = hw->priv;
+
+       mwl8k_stop(hw);
+       mwl8k_rxq_deinit(hw, 0);
+
+       for (i = 0; i < MWL8K_TX_QUEUES; i++)
+               mwl8k_txq_deinit(hw, i);
+
+       rc = mwl8k_init_firmware(hw, fw_image);
+       if (rc)
+               goto fail;
+
+       rc = mwl8k_probe_hw(hw);
+       if (rc)
+               goto fail;
+
+       rc = mwl8k_start(hw);
+       if (rc)
+               goto fail;
+
+       rc = mwl8k_config(hw, ~0);
+       if (rc)
+               goto fail;
+
+       for (i = 0; i < MWL8K_TX_QUEUES; i++) {
+               rc = mwl8k_conf_tx(hw, i, &priv->wmm_params[i]);
+               if (rc)
+                       goto fail;
+       }
+
+       return rc;
+
+fail:
+       printk(KERN_WARNING "mwl8k: Failed to reload firmware image.\n");
+       return rc;
+}
+
+static int mwl8k_firmware_load_success(struct mwl8k_priv *priv)
+{
+       struct ieee80211_hw *hw = priv->hw;
+       int i, rc;
+
+       /*
+        * Extra headroom is the size of the required DMA header
+        * minus the size of the smallest 802.11 frame (CTS frame).
+        */
+       hw->extra_tx_headroom =
+               sizeof(struct mwl8k_dma_data) - sizeof(struct ieee80211_cts);
+
+       hw->channel_change_time = 10;
+
+       hw->queues = MWL8K_TX_QUEUES;
+
+       /* Set rssi values to dBm */
+       hw->flags |= IEEE80211_HW_SIGNAL_DBM;
+       hw->vif_data_size = sizeof(struct mwl8k_vif);
+       hw->sta_data_size = sizeof(struct mwl8k_sta);
+
+       priv->macids_used = 0;
+       INIT_LIST_HEAD(&priv->vif_list);
+
+       /* Set default radio state and preamble */
+       priv->radio_on = 0;
+       priv->radio_short_preamble = 0;
+
+       /* Finalize join worker */
+       INIT_WORK(&priv->finalize_join_worker, mwl8k_finalize_join_worker);
+
+       /* TX reclaim and RX tasklets.  */
+       tasklet_init(&priv->poll_tx_task, mwl8k_tx_poll, (unsigned long)hw);
+       tasklet_disable(&priv->poll_tx_task);
+       tasklet_init(&priv->poll_rx_task, mwl8k_rx_poll, (unsigned long)hw);
+       tasklet_disable(&priv->poll_rx_task);
+
+       /* Power management cookie */
+       priv->cookie = pci_alloc_consistent(priv->pdev, 4, &priv->cookie_dma);
+       if (priv->cookie == NULL)
+               return -ENOMEM;
+
+       mutex_init(&priv->fw_mutex);
+       priv->fw_mutex_owner = NULL;
+       priv->fw_mutex_depth = 0;
+       priv->hostcmd_wait = NULL;
+
+       spin_lock_init(&priv->tx_lock);
+
+       priv->tx_wait = NULL;
+
+       rc = mwl8k_probe_hw(hw);
+       if (rc)
+               goto err_free_cookie;
+
+       hw->wiphy->interface_modes = 0;
+       if (priv->ap_macids_supported || priv->device_info->fw_image_ap)
+               hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_AP);
+       if (priv->sta_macids_supported || priv->device_info->fw_image_sta)
+               hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_STATION);
+
+       rc = ieee80211_register_hw(hw);
+       if (rc) {
+               wiphy_err(hw->wiphy, "Cannot register device\n");
+               goto err_unprobe_hw;
+       }
+
+       return 0;
+
+err_unprobe_hw:
+       for (i = 0; i < MWL8K_TX_QUEUES; i++)
+               mwl8k_txq_deinit(hw, i);
+       mwl8k_rxq_deinit(hw, 0);
+

 err_free_cookie:
       if (priv->cookie != NULL) pci_free_consistent(priv->pdev, 4, priv->cookie, priv->cookie_dma);

+       return rc;

drivers/net/wireless/mwl8k.c +75 -0
+}
+static int __devinit mwl8k_probe(struct pci_dev *pdev,
+                                const struct pci_device_id *id)
+{
+       static int printed_version;
+       struct ieee80211_hw *hw;
+       struct mwl8k_priv *priv;
+       int rc;
+
+       if (!printed_version) {
+               printk(KERN_INFO "%s version %s\n", MWL8K_DESC, MWL8K_VERSION);
+               printed_version = 1;
+       }
+
+
+       rc = pci_enable_device(pdev);
+       if (rc) {
+               printk(KERN_ERR "%s: Cannot enable new PCI device\n",
+                      MWL8K_NAME);
+               return rc;
+       }
+
+       rc = pci_request_regions(pdev, MWL8K_NAME);
+       if (rc) {
+               printk(KERN_ERR "%s: Cannot obtain PCI resources\n",
+                      MWL8K_NAME);
+               goto err_disable_device;
+       }
+
+       pci_set_master(pdev);
+
+
+       hw = ieee80211_alloc_hw(sizeof(*priv), &mwl8k_ops);
+       if (hw == NULL) {
+               printk(KERN_ERR "%s: ieee80211 alloc failed\n", MWL8K_NAME);
+               rc = -ENOMEM;
+               goto err_free_reg;
+       }
+
+       SET_IEEE80211_DEV(hw, &pdev->dev);
+       pci_set_drvdata(pdev, hw);
+
+       priv = hw->priv;
+       priv->hw = hw;
+       priv->pdev = pdev;
+       priv->device_info = &mwl8k_info_tbl[id->driver_data];
+
+
+       priv->sram = pci_iomap(pdev, 0, 0x10000);
+       if (priv->sram == NULL) {
+               wiphy_err(hw->wiphy, "Cannot map device SRAM\n");
+               goto err_iounmap;
+       }
+
+       /*
+        * If BAR0 is a 32 bit BAR, the register BAR will be BAR1.
+        * If BAR0 is a 64 bit BAR, the register BAR will be BAR2.
+        */
+       priv->regs = pci_iomap(pdev, 1, 0x10000);
+       if (priv->regs == NULL) {
+               priv->regs = pci_iomap(pdev, 2, 0x10000);
+               if (priv->regs == NULL) {
+                       wiphy_err(hw->wiphy, "Cannot map device registers\n");
+                       goto err_iounmap;
+               }
+       }
+
+       rc = mwl8k_init_firmware(hw);
+       if (rc)
+               goto err_stop_firmware;
+
+       rc = mwl8k_firmware_load_success(priv);
+       if (!rc)
+               return rc;
+

 err_stop_firmware:
       mwl8k_hw_reset(priv);
-       mwl8k_release_firmware(priv);

 err_iounmap:
       if (priv->regs != NULL)
--
1.7.1.1

#25 lore raw

PATCH v2 4/7 mwl8k: choose proper firmware image as directed by user

In reply to Brian Cavagnolo

The mwl8k can operate in AP or STA mode, depending on the firmware image that is loaded. By default, STA firmware is loaded. Allow the user to override this default mode at module load time. This saves an unnecessary firmware reload for users only interested in AP mode.

Also, the firmware image can be swapped to meet the user's add_interface request. For example, suppose the STA firmware is loaded, no STA interface has been added, and the user adds an AP interface. In this case, the AP firmware will be loaded to meet the request.

Based on contributions from Pradeep Nemavat <[email protected]>, Yogesh Powar <[email protected]>, and
Lennert Buytenhek <[email protected]>.

---
 drivers/net/wireless/mwl8k.c |   78 +++++++++++++++++++++++++++++++++++------
 1 files changed, 66 insertions(+), 12 deletions(-)
drivers/net/wireless/mwl8k.c +66 -12
index 7bd8615..cbf7271 100644
@@ -29,6 +29,12 @@
 #define MWL8K_NAME	KBUILD_MODNAME
 #define MWL8K_VERSION	"0.12"
 
+/* Module parameters */
+static unsigned ap_mode_default;
+module_param(ap_mode_default, bool, 0);
+MODULE_PARM_DESC(ap_mode_default,
+		 "Set to 1 to make ap mode the default instead of sta mode");
+
 /* Register definitions */
 #define MWL8K_HIU_GEN_PTR			0x00000c10
 #define  MWL8K_MODE_STA				 0x0000005a
@@ -92,7 +98,8 @@ struct rxd_ops {
 struct mwl8k_device_info {
 	char *part_name;
 	char *helper_image;
-	char *fw_image;
+	char *fw_image_sta;
+	char *fw_image_ap;
 	struct rxd_ops *ap_rxd_ops;
 };
 
@@ -210,6 +217,12 @@ struct mwl8k_priv {
 
 	/* Most recently reported noise in dBm */
 	s8 noise;
+
+	/*
+	 * preserve the queue configurations so they can be restored if/when
+	 * the firmware image is swapped.
+	 */
+	struct ieee80211_tx_queue_params wmm_params[MWL8K_TX_QUEUES];
 };
 
 /* Per interface specific private data */
@@ -401,7 +414,7 @@ static int mwl8k_request_fw(struct mwl8k_priv *priv,
 				fname, &priv->pdev->dev);
 }
 
-static int mwl8k_request_firmware(struct mwl8k_priv *priv)
+static int mwl8k_request_firmware(struct mwl8k_priv *priv, char *fw_image)
 {
 	struct mwl8k_device_info *di = priv->device_info;
 	int rc;
@@ -416,10 +429,10 @@ static int mwl8k_request_firmware(struct mwl8k_priv *priv)
 		}
 	}
 
-	rc = mwl8k_request_fw(priv, di->fw_image, &priv->fw_ucode);
+	rc = mwl8k_request_fw(priv, fw_image, &priv->fw_ucode);
 	if (rc) {
 		printk(KERN_ERR "%s: Error requesting firmware file %s\n",
-		       pci_name(priv->pdev), di->fw_image);
+		       pci_name(priv->pdev), fw_image);
 		mwl8k_release_fw(&priv->fw_helper);
 		return rc;
 	}
@@ -3345,13 +3358,16 @@ static void mwl8k_stop(struct ieee80211_hw *hw)
 		mwl8k_txq_reclaim(hw, i, INT_MAX, 1);
 }
 
+static int mwl8k_reload_firmware(struct ieee80211_hw *hw, char *fw_image);
+
 static int mwl8k_add_interface(struct ieee80211_hw *hw,
 			       struct ieee80211_vif *vif)
 {
 	struct mwl8k_priv *priv = hw->priv;
 	struct mwl8k_vif *mwl8k_vif;
 	u32 macids_supported;
-	int macid;
+	int macid, rc;
+	struct mwl8k_device_info *di;
 
 	/*
 	 * Reject interface creation if sniffer mode is active, as
@@ -3364,12 +3380,28 @@ static int mwl8k_add_interface(struct ieee80211_hw *hw,
 		return -EINVAL;
 	}
 
-
+	di = priv->device_info;
 	switch (vif->type) {
 	case NL80211_IFTYPE_AP:
+		if (!priv->ap_fw && di->fw_image_ap) {
+			/* we must load the ap fw to meet this request */
+			if (!list_empty(&priv->vif_list))
+				return -EBUSY;
+			rc = mwl8k_reload_firmware(hw, di->fw_image_ap);
+			if (rc)
+				return rc;
+		}
 		macids_supported = priv->ap_macids_supported;
 		break;
 	case NL80211_IFTYPE_STATION:
+		if (priv->ap_fw && di->fw_image_sta) {
+			/* we must load the sta fw to meet this request */
+			if (!list_empty(&priv->vif_list))
+				return -EBUSY;
+			rc = mwl8k_reload_firmware(hw, di->fw_image_sta);
+			if (rc)
+				return rc;
+		}
 		macids_supported = priv->sta_macids_supported;
 		break;
 	default:
@@ -3805,6 +3837,9 @@ static int mwl8k_conf_tx(struct ieee80211_hw *hw, u16 queue,
 
 	rc = mwl8k_fw_lock(hw);
 	if (!rc) {
+		BUG_ON(queue > MWL8K_TX_QUEUES - 1);
+		memcpy(&priv->wmm_params[queue], params, sizeof(*params));
+
 		if (!priv->wmm_enabled)
 			rc = mwl8k_cmd_set_wmm_mode(hw, 1);
 
@@ -3908,17 +3943,18 @@ static struct mwl8k_device_info mwl8k_info_tbl[] __devinitdata = {
 	[MWL8363] = {
 		.part_name	= "88w8363",
 		.helper_image	= "mwl8k/helper_8363.fw",
-		.fw_image	= "mwl8k/fmimage_8363.fw",
+		.fw_image_sta	= "mwl8k/fmimage_8363.fw",
 	},
 	[MWL8687] = {
 		.part_name	= "88w8687",
 		.helper_image	= "mwl8k/helper_8687.fw",
-		.fw_image	= "mwl8k/fmimage_8687.fw",
+		.fw_image_sta	= "mwl8k/fmimage_8687.fw",
 	},
 	[MWL8366] = {
 		.part_name	= "88w8366",
 		.helper_image	= "mwl8k/helper_8366.fw",
-		.fw_image	= "mwl8k/fmimage_8366.fw",
+		.fw_image_sta	= "mwl8k/fmimage_8366.fw",
+		.fw_image_ap	= "mwl8k/fmimage_8366_ap-1.fw",
 		.ap_rxd_ops	= &rxd_8366_ap_ops,
 	},
 };
@@ -3929,6 +3965,7 @@ MODULE_FIRMWARE("mwl8k/helper_8687.fw");
 MODULE_FIRMWARE("mwl8k/fmimage_8687.fw");
 MODULE_FIRMWARE("mwl8k/helper_8366.fw");
 MODULE_FIRMWARE("mwl8k/fmimage_8366.fw");
+MODULE_FIRMWARE("mwl8k/fmimage_8366_ap-1.fw");
 
 static DEFINE_PCI_DEVICE_TABLE(mwl8k_pci_id_table) = {
 	{ PCI_VDEVICE(MARVELL, 0x2a0a), .driver_data = MWL8363, },
@@ -3942,7 +3979,7 @@ static DEFINE_PCI_DEVICE_TABLE(mwl8k_pci_id_table) = {
 };
 MODULE_DEVICE_TABLE(pci, mwl8k_pci_id_table);
 
-static int mwl8k_init_firmware(struct ieee80211_hw *hw)
+static int mwl8k_init_firmware(struct ieee80211_hw *hw, char *fw_image)
 {
 	struct mwl8k_priv *priv = hw->priv;
 	int rc;
@@ -3951,7 +3988,7 @@ static int mwl8k_init_firmware(struct ieee80211_hw *hw)
 	mwl8k_hw_reset(priv);
 
 	/* Ask userland hotplug daemon for the device firmware */
-	rc = mwl8k_request_firmware(priv);
+	rc = mwl8k_request_firmware(priv, fw_image);
 	if (rc) {
 		wiphy_err(hw->wiphy, "Firmware files not found\n");
 		return rc;
@@ -4207,6 +4244,7 @@ static int __devinit mwl8k_probe(struct pci_dev *pdev,
 	static int printed_version;
 	struct ieee80211_hw *hw;
 	struct mwl8k_priv *priv;
+	struct mwl8k_device_info *di;
 	int rc;
 
 	if (!printed_version) {
@@ -4267,7 +4305,23 @@ static int __devinit mwl8k_probe(struct pci_dev *pdev,
 		}
 	}
 
-	rc = mwl8k_init_firmware(hw);
+	/*
+	 * Choose the initial fw image depending on user input and availability
+	 * of images.
+	 */
+	di = priv->device_info;
+	if (ap_mode_default && di->fw_image_ap)
+		rc = mwl8k_init_firmware(hw, di->fw_image_ap);
+	else if (!ap_mode_default && di->fw_image_sta)
+		rc = mwl8k_init_firmware(hw, di->fw_image_sta);
+	else if (ap_mode_default && !di->fw_image_ap && di->fw_image_sta) {
+		printk(KERN_WARNING "AP fw is unavailable.  Using STA fw.");
+		rc = mwl8k_init_firmware(hw, di->fw_image_sta);
+	} else if (!ap_mode_default && !di->fw_image_sta && di->fw_image_ap) {
+		printk(KERN_WARNING "STA fw is unavailable.  Using AP fw.");
+		rc = mwl8k_init_firmware(hw, di->fw_image_ap);
+	} else
+		rc = mwl8k_init_firmware(hw, di->fw_image_sta);
 	if (rc)
 		goto err_stop_firmware;
 
Signature · 1 line
1.7.1.1
#26 lore raw

Re: [PATCH V2 4/7] mwl8k: choose proper firmware image as directed by user

My apologies. This is the V2 patch despite the subject.

Quoted 226 lines · Brian Cavagnolo

The mwl8k can operate in AP or STA mode, depending on the firmware image that is loaded.  By default, STA firmware is loaded.  Allow the user to override this default mode at module load time.  This saves an unnecessary firmware reload for users only interested in AP mode.

Also, the firmware image can be swapped to meet the user's add_interface request.  For example, suppose the STA firmware is loaded, no STA interface has been added, and the user adds an AP interface.  In this case, the AP firmware will be loaded to meet the request.

Based on contributions from Pradeep Nemavat <[email protected]>, Yogesh Powar <[email protected]>, and
Lennert Buytenhek <[email protected]>.

---
 drivers/net/wireless/mwl8k.c |   78 +++++++++++++++++++++++++++++++++++------

 1 files changed, 66 insertions(+), 12 deletions(-)
drivers/net/wireless/mwl8k.c +22 -6
index 7bd8615..cbf7271 100644
@@ -29,6 +29,12 @@
  #define MWL8K_NAME     KBUILD_MODNAME
  #define MWL8K_VERSION  "0.12"
 
+/* Module parameters */
+static unsigned ap_mode_default;
+module_param(ap_mode_default, bool, 0);
+MODULE_PARM_DESC(ap_mode_default,
+                "Set to 1 to make ap mode the default instead of sta mode");
+
  /* Register definitions */
  #define MWL8K_HIU_GEN_PTR                      0x00000c10
  #define  MWL8K_MODE_STA                                 0x0000005a
@@ -92,7 +98,8 @@ struct rxd_ops {
  struct mwl8k_device_info {
        char *part_name;
        char *helper_image;
-       char *fw_image;
+       char *fw_image_sta;
+       char *fw_image_ap;
        struct rxd_ops *ap_rxd_ops;
  };
 
@@ -210,6 +217,12 @@ struct mwl8k_priv {
 
        /* Most recently reported noise in dBm */
        s8 noise;
+
+       /*
+        * preserve the queue configurations so they can be restored if/when
+        * the firmware image is swapped.
+        */
+       struct ieee80211_tx_queue_params wmm_params[MWL8K_TX_QUEUES];
  };
 
  /* Per interface specific private data */
@@ -401,7 +414,7 @@ static int mwl8k_request_fw(struct mwl8k_priv *priv,
                                fname, &priv->pdev->dev);
  }
 
-static int mwl8k_request_firmware(struct mwl8k_priv *priv)
+static int mwl8k_request_firmware(struct mwl8k_priv *priv, char *fw_image)
  {
        struct mwl8k_device_info *di = priv->device_info;
        int rc;
@@ -416,10 +429,10 @@ static int mwl8k_request_firmware(struct mwl8k_priv *priv)
                }
        }
 
-       rc = mwl8k_request_fw(priv, di->fw_image, &priv->fw_ucode);
+       rc = mwl8k_request_fw(priv, fw_image, &priv->fw_ucode);
        if (rc) {
                printk(KERN_ERR "%s: Error requesting firmware file %s\n",
-                      pci_name(priv->pdev), di->fw_image);
+                      pci_name(priv->pdev), fw_image);
                mwl8k_release_fw(&priv->fw_helper);
                return rc;
        }
@@ -3345,13 +3358,16 @@ static void mwl8k_stop(struct ieee80211_hw *hw)
                mwl8k_txq_reclaim(hw, i, INT_MAX, 1);
  }
 
+static int mwl8k_reload_firmware(struct ieee80211_hw *hw, char *fw_image);
+
  static int mwl8k_add_interface(struct ieee80211_hw *hw,
                               struct ieee80211_vif *vif)
  {
        struct mwl8k_priv *priv = hw->priv;
        struct mwl8k_vif *mwl8k_vif;
        u32 macids_supported;
-       int macid;
+       int macid, rc;
+       struct mwl8k_device_info *di;
 
        /*
         * Reject interface creation if sniffer mode is active, as
@@ -3364,12 +3380,28 @@ static int mwl8k_add_interface(struct ieee80211_hw *hw,
                return -EINVAL;
        }
 
-
+       di = priv->device_info;
        switch (vif->type) {

       case NL80211_IFTYPE_AP:
+               if (!priv->ap_fw && di->fw_image_ap) {
+                       /* we must load the ap fw to meet this request */
+                       if (!list_empty(&priv->vif_list))
+                               return -EBUSY;
+                       rc = mwl8k_reload_firmware(hw, di->fw_image_ap);
+                       if (rc)
+                               return rc;
+               }
               macids_supported = priv->ap_macids_supported; break;
       case NL80211_IFTYPE_STATION:
+               if (priv->ap_fw && di->fw_image_sta) {
+                       /* we must load the sta fw to meet this request */
+                       if (!list_empty(&priv->vif_list))
+                               return -EBUSY;
+                       rc = mwl8k_reload_firmware(hw, di->fw_image_sta);
+                       if (rc)
+                               return rc;
+               }
               macids_supported = priv->sta_macids_supported; break;
       default:

drivers/net/wireless/mwl8k.c +28 -7
@@ -3805,6 +3837,9 @@ static int mwl8k_conf_tx(struct ieee80211_hw *hw, u16 queue,
 
        rc = mwl8k_fw_lock(hw);
        if (!rc) {
+               BUG_ON(queue > MWL8K_TX_QUEUES - 1);
+               memcpy(&priv->wmm_params[queue], params, sizeof(*params));
+
                if (!priv->wmm_enabled)
                        rc = mwl8k_cmd_set_wmm_mode(hw, 1);
 
@@ -3908,17 +3943,18 @@ static struct mwl8k_device_info mwl8k_info_tbl[] __devinitdata = {
        [MWL8363] = {
                .part_name      = "88w8363",
                .helper_image   = "mwl8k/helper_8363.fw",
-               .fw_image       = "mwl8k/fmimage_8363.fw",
+               .fw_image_sta   = "mwl8k/fmimage_8363.fw",
        },
        [MWL8687] = {
                .part_name      = "88w8687",
                .helper_image   = "mwl8k/helper_8687.fw",
-               .fw_image       = "mwl8k/fmimage_8687.fw",
+               .fw_image_sta   = "mwl8k/fmimage_8687.fw",
        },
        [MWL8366] = {
                .part_name      = "88w8366",
                .helper_image   = "mwl8k/helper_8366.fw",
-               .fw_image       = "mwl8k/fmimage_8366.fw",
+               .fw_image_sta   = "mwl8k/fmimage_8366.fw",
+               .fw_image_ap    = "mwl8k/fmimage_8366_ap-1.fw",
                .ap_rxd_ops     = &rxd_8366_ap_ops,
        },
  };
@@ -3929,6 +3965,7 @@ MODULE_FIRMWARE("mwl8k/helper_8687.fw");
  MODULE_FIRMWARE("mwl8k/fmimage_8687.fw");
  MODULE_FIRMWARE("mwl8k/helper_8366.fw");
  MODULE_FIRMWARE("mwl8k/fmimage_8366.fw");
+MODULE_FIRMWARE("mwl8k/fmimage_8366_ap-1.fw");
 
  static DEFINE_PCI_DEVICE_TABLE(mwl8k_pci_id_table) = {
        { PCI_VDEVICE(MARVELL, 0x2a0a), .driver_data = MWL8363, },
@@ -3942,7 +3979,7 @@ static DEFINE_PCI_DEVICE_TABLE(mwl8k_pci_id_table) = {
  };
  MODULE_DEVICE_TABLE(pci, mwl8k_pci_id_table);
 
-static int mwl8k_init_firmware(struct ieee80211_hw *hw)
+static int mwl8k_init_firmware(struct ieee80211_hw *hw, char *fw_image)
  {
        struct mwl8k_priv *priv = hw->priv;
        int rc;
@@ -3951,7 +3988,7 @@ static int mwl8k_init_firmware(struct ieee80211_hw *hw)
        mwl8k_hw_reset(priv);
 
        /* Ask userland hotplug daemon for the device firmware */
-       rc = mwl8k_request_firmware(priv);
+       rc = mwl8k_request_firmware(priv, fw_image);
        if (rc) {
                wiphy_err(hw->wiphy, "Firmware files not found\n");
                return rc;
@@ -4207,6 +4244,7 @@ static int __devinit mwl8k_probe(struct pci_dev *pdev,
        static int printed_version;
        struct ieee80211_hw *hw;
        struct mwl8k_priv *priv;
+       struct mwl8k_device_info *di;
        int rc;
 
        if (!printed_version) {
@@ -4267,7 +4305,23 @@ static int __devinit mwl8k_probe(struct pci_dev *pdev,
                }
        }
 
-       rc = mwl8k_init_firmware(hw);
+       /*
+        * Choose the initial fw image depending on user input and availability
+        * of images.
+        */
+       di = priv->device_info;
+       if (ap_mode_default && di->fw_image_ap)
+               rc = mwl8k_init_firmware(hw, di->fw_image_ap);
+       else if (!ap_mode_default && di->fw_image_sta)
+               rc = mwl8k_init_firmware(hw, di->fw_image_sta);
+       else if (ap_mode_default && !di->fw_image_ap && di->fw_image_sta) {
+               printk(KERN_WARNING "AP fw is unavailable.  Using STA fw.");
+               rc = mwl8k_init_firmware(hw, di->fw_image_sta);
+       } else if (!ap_mode_default && !di->fw_image_sta && di->fw_image_ap) {
+               printk(KERN_WARNING "STA fw is unavailable.  Using AP fw.");
+               rc = mwl8k_init_firmware(hw, di->fw_image_ap);
+       } else
+               rc = mwl8k_init_firmware(hw, di->fw_image_sta);
        if (rc)
                goto err_stop_firmware;
 
--

1.7.1.1

#27 lore raw

PATCH v2 5/7 mwl8k: add API version checking for AP firmware

In reply to Brian Cavagnolo

The AP firmware specifies an API version in the GET_HW_SPEC command response. Currently, the driver only supports AP firmware for the 8366, and only supports API v1. In the future, if higher API version firmwares emerge (possibly for different chips), different ops can be selected based on the reported API version.

---
 drivers/net/wireless/mwl8k.c |   23 +++++++++++++++++++++--
 1 files changed, 21 insertions(+), 2 deletions(-)
drivers/net/wireless/mwl8k.c +21 -2
index cbf7271..e5b062c 100644
@@ -101,6 +101,7 @@ struct mwl8k_device_info {
 	char *fw_image_sta;
 	char *fw_image_ap;
 	struct rxd_ops *ap_rxd_ops;
+	u32 fw_api_ap;
 };
 
 struct mwl8k_rx_queue {
@@ -1827,6 +1828,7 @@ struct mwl8k_cmd_get_hw_spec_ap {
 	__le32 wcbbase1;
 	__le32 wcbbase2;
 	__le32 wcbbase3;
+	__le32 fw_api_version;
 } __packed;
 
 static int mwl8k_cmd_get_hw_spec_ap(struct ieee80211_hw *hw)
@@ -1834,6 +1836,7 @@ static int mwl8k_cmd_get_hw_spec_ap(struct ieee80211_hw *hw)
 	struct mwl8k_priv *priv = hw->priv;
 	struct mwl8k_cmd_get_hw_spec_ap *cmd;
 	int rc;
+	u32 api_version;
 
 	cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
 	if (cmd == NULL)
@@ -1850,6 +1853,16 @@ static int mwl8k_cmd_get_hw_spec_ap(struct ieee80211_hw *hw)
 	if (!rc) {
 		int off;
 
+		api_version = le32_to_cpu(cmd->fw_api_version);
+		if (priv->device_info->fw_api_ap != api_version) {
+			printk(KERN_ERR "%s: Unsupported fw API version for %s."
+			       "  Expected %d got %d.\n", MWL8K_NAME,
+			       priv->device_info->part_name,
+			       priv->device_info->fw_api_ap,
+			       api_version);
+			rc = -EINVAL;
+			goto done;
+		}
 		SET_IEEE80211_PERM_ADDR(hw, cmd->perm_addr);
 		priv->num_mcaddrs = le16_to_cpu(cmd->num_mcaddrs);
 		priv->fw_rev = le32_to_cpu(cmd->fw_rev);
@@ -1877,6 +1890,7 @@ static int mwl8k_cmd_get_hw_spec_ap(struct ieee80211_hw *hw)
 		iowrite32(priv->txq[3].txd_dma, priv->sram + off);
 	}
 
+done:
 	kfree(cmd);
 	return rc;
 }
@@ -3939,6 +3953,10 @@ enum {
 	MWL8366,
 };
 
+#define MWL8K_8366_AP_FW_API 1
+#define _MWL8K_8366_AP_FW(api) "mwl8k/fmimage_8366_ap-" #api ".fw"
+#define MWL8K_8366_AP_FW(api) _MWL8K_8366_AP_FW(api)
+
 static struct mwl8k_device_info mwl8k_info_tbl[] __devinitdata = {
 	[MWL8363] = {
 		.part_name	= "88w8363",
@@ -3954,7 +3972,8 @@ static struct mwl8k_device_info mwl8k_info_tbl[] __devinitdata = {
 		.part_name	= "88w8366",
 		.helper_image	= "mwl8k/helper_8366.fw",
 		.fw_image_sta	= "mwl8k/fmimage_8366.fw",
-		.fw_image_ap	= "mwl8k/fmimage_8366_ap-1.fw",
+		.fw_image_ap	= MWL8K_8366_AP_FW(MWL8K_8366_AP_FW_API),
+		.fw_api_ap	= MWL8K_8366_AP_FW_API,
 		.ap_rxd_ops	= &rxd_8366_ap_ops,
 	},
 };
@@ -3965,7 +3984,7 @@ MODULE_FIRMWARE("mwl8k/helper_8687.fw");
 MODULE_FIRMWARE("mwl8k/fmimage_8687.fw");
 MODULE_FIRMWARE("mwl8k/helper_8366.fw");
 MODULE_FIRMWARE("mwl8k/fmimage_8366.fw");
-MODULE_FIRMWARE("mwl8k/fmimage_8366_ap-1.fw");
+MODULE_FIRMWARE(MWL8K_8366_AP_FW(MWL8K_8366_AP_FW_API));
 
 static DEFINE_PCI_DEVICE_TABLE(mwl8k_pci_id_table) = {
 	{ PCI_VDEVICE(MARVELL, 0x2a0a), .driver_data = MWL8363, },
Signature · 1 line
1.7.1.1
#28 lore raw

PATCH v2 6/7 mwl8k: make initial firmware load asynchronous

In reply to Brian Cavagnolo

Introduce a firmware loading state machine to manage the process of loading firmware asynchronously and completing initialization upon success. The state machine attempts to load the preferred firmware image. If that fails, and if an alternative firmware image is available, it will attempt to load that one.

---
 drivers/net/wireless/mwl8k.c |  207 ++++++++++++++++++++++++++++++++++++------
 1 files changed, 178 insertions(+), 29 deletions(-)
drivers/net/wireless/mwl8k.c +178 -29
index e5b062c..081bb6c 100644
@@ -224,6 +224,12 @@ struct mwl8k_priv {
 	 * the firmware image is swapped.
 	 */
 	struct ieee80211_tx_queue_params wmm_params[MWL8K_TX_QUEUES];
+
+	/* async firmware loading state */
+	unsigned fw_state;
+	char *fw_pref;
+	char *fw_alt;
+	struct completion firmware_loading_complete;
 };
 
 /* Per interface specific private data */
@@ -403,34 +409,66 @@ static void mwl8k_release_firmware(struct mwl8k_priv *priv)
 	mwl8k_release_fw(&priv->fw_helper);
 }
 
+/* states for asynchronous f/w loading */
+static void mwl8k_fw_state_machine(const struct firmware *fw, void *context);
+enum {
+	FW_STATE_INIT = 0,
+	FW_STATE_LOADING_PREF,
+	FW_STATE_LOADING_ALT,
+	FW_STATE_ERROR,
+};
+
 /* Request fw image */
 static int mwl8k_request_fw(struct mwl8k_priv *priv,
-			    const char *fname, struct firmware **fw)
+			    const char *fname, struct firmware **fw,
+			    bool nowait)
 {
 	/* release current image */
 	if (*fw != NULL)
 		mwl8k_release_fw(fw);
 
-	return request_firmware((const struct firmware **)fw,
-				fname, &priv->pdev->dev);
+	if (nowait)
+		return request_firmware_nowait(THIS_MODULE, 1, fname,
+					       &priv->pdev->dev, GFP_KERNEL,
+					       priv, mwl8k_fw_state_machine);
+	else
+		return request_firmware((const struct firmware **)fw,
+					fname, &priv->pdev->dev);
 }
 
-static int mwl8k_request_firmware(struct mwl8k_priv *priv, char *fw_image)
+static int mwl8k_request_firmware(struct mwl8k_priv *priv, char *fw_image,
+				  bool nowait)
 {
 	struct mwl8k_device_info *di = priv->device_info;
 	int rc;
 
 	if (di->helper_image != NULL) {
-		rc = mwl8k_request_fw(priv, di->helper_image, &priv->fw_helper);
-		if (rc) {
-			printk(KERN_ERR "%s: Error requesting helper "
-			       "firmware file %s\n", pci_name(priv->pdev),
-			       di->helper_image);
+		if (nowait)
+			rc = mwl8k_request_fw(priv, di->helper_image,
+					      &priv->fw_helper, true);
+		else
+			rc = mwl8k_request_fw(priv, di->helper_image,
+					      &priv->fw_helper, false);
+		if (rc)
+			printk(KERN_ERR "%s: Error requesting helper fw %s\n",
+			       pci_name(priv->pdev), di->helper_image);
+
+		if (rc || nowait)
 			return rc;
-		}
 	}
 
-	rc = mwl8k_request_fw(priv, fw_image, &priv->fw_ucode);
+	if (nowait) {
+		/*
+		 * if we get here, no helper image is needed.  Skip the
+		 * FW_STATE_INIT state.
+		 */
+		priv->fw_state = FW_STATE_LOADING_PREF;
+		rc = mwl8k_request_fw(priv, fw_image,
+				      &priv->fw_ucode,
+				      true);
+	} else
+		rc = mwl8k_request_fw(priv, fw_image,
+				      &priv->fw_ucode, false);
 	if (rc) {
 		printk(KERN_ERR "%s: Error requesting firmware file %s\n",
 		       pci_name(priv->pdev), fw_image);
@@ -3998,7 +4036,99 @@ static DEFINE_PCI_DEVICE_TABLE(mwl8k_pci_id_table) = {
 };
 MODULE_DEVICE_TABLE(pci, mwl8k_pci_id_table);
 
-static int mwl8k_init_firmware(struct ieee80211_hw *hw, char *fw_image)
+static int mwl8k_request_alt_fw(struct mwl8k_priv *priv)
+{
+	int rc;
+	printk(KERN_ERR "%s: Error requesting preferred fw %s.\n"
+	       "Trying alternative firmware %s\n", pci_name(priv->pdev),
+	       priv->fw_pref, priv->fw_alt);
+	rc = mwl8k_request_fw(priv, priv->fw_alt, &priv->fw_ucode, true);
+	if (rc) {
+		printk(KERN_ERR "%s: Error requesting alt fw %s\n",
+		       pci_name(priv->pdev), priv->fw_alt);
+		return rc;
+	}
+	return 0;
+}
+
+static int mwl8k_firmware_load_success(struct mwl8k_priv *priv);
+static void mwl8k_fw_state_machine(const struct firmware *fw, void *context)
+{
+	struct mwl8k_priv *priv = context;
+	struct mwl8k_device_info *di = priv->device_info;
+	int rc;
+
+	switch (priv->fw_state) {
+	case FW_STATE_INIT:
+		if (!fw) {
+			printk(KERN_ERR "%s: Error requesting helper fw %s\n",
+			       pci_name(priv->pdev), di->helper_image);
+			goto fail;
+		}
+		priv->fw_helper = fw;
+		rc = mwl8k_request_fw(priv, priv->fw_pref, &priv->fw_ucode,
+				      true);
+		if (rc && priv->fw_alt) {
+			rc = mwl8k_request_alt_fw(priv);
+			if (rc)
+				goto fail;
+			priv->fw_state = FW_STATE_LOADING_ALT;
+		} else if (rc)
+			goto fail;
+		else
+			priv->fw_state = FW_STATE_LOADING_PREF;
+		break;
+
+	case FW_STATE_LOADING_PREF:
+		if (!fw) {
+			if (priv->fw_alt) {
+				rc = mwl8k_request_alt_fw(priv);
+				if (rc)
+					goto fail;
+				priv->fw_state = FW_STATE_LOADING_ALT;
+			} else
+				goto fail;
+		} else {
+			priv->fw_ucode = fw;
+			rc = mwl8k_firmware_load_success(priv);
+			if (rc)
+				goto fail;
+			else
+				complete(&priv->firmware_loading_complete);
+		}
+		break;
+
+	case FW_STATE_LOADING_ALT:
+		if (!fw) {
+			printk(KERN_ERR "%s: Error requesting alt fw %s\n",
+			       pci_name(priv->pdev), di->helper_image);
+			goto fail;
+		}
+		priv->fw_ucode = fw;
+		rc = mwl8k_firmware_load_success(priv);
+		if (rc)
+			goto fail;
+		else
+			complete(&priv->firmware_loading_complete);
+		break;
+
+	default:
+		printk(KERN_ERR "%s: Unexpected firmware loading state: %d\n",
+		       MWL8K_NAME, priv->fw_state);
+		BUG_ON(1);
+	}
+
+	return;
+
+fail:
+	priv->fw_state = FW_STATE_ERROR;
+	complete(&priv->firmware_loading_complete);
+	device_release_driver(&priv->pdev->dev);
+	mwl8k_release_firmware(priv);
+}
+
+static int mwl8k_init_firmware(struct ieee80211_hw *hw, char *fw_image,
+			       bool nowait)
 {
 	struct mwl8k_priv *priv = hw->priv;
 	int rc;
@@ -4007,12 +4137,15 @@ static int mwl8k_init_firmware(struct ieee80211_hw *hw, char *fw_image)
 	mwl8k_hw_reset(priv);
 
 	/* Ask userland hotplug daemon for the device firmware */
-	rc = mwl8k_request_firmware(priv, fw_image);
+	rc = mwl8k_request_firmware(priv, fw_image, nowait);
 	if (rc) {
 		wiphy_err(hw->wiphy, "Firmware files not found\n");
 		return rc;
 	}
 
+	if (nowait)
+		return rc;
+
 	/* Load firmware into hardware */
 	rc = mwl8k_load_firmware(hw);
 	if (rc)
@@ -4147,7 +4280,7 @@ static int mwl8k_reload_firmware(struct ieee80211_hw *hw, char *fw_image)
 	for (i = 0; i < MWL8K_TX_QUEUES; i++)
 		mwl8k_txq_deinit(hw, i);
 
-	rc = mwl8k_init_firmware(hw, fw_image);
+	rc = mwl8k_init_firmware(hw, fw_image, false);
 	if (rc)
 		goto fail;
 
@@ -4181,6 +4314,13 @@ static int mwl8k_firmware_load_success(struct mwl8k_priv *priv)
 	struct ieee80211_hw *hw = priv->hw;
 	int i, rc;
 
+	rc = mwl8k_load_firmware(hw);
+	mwl8k_release_firmware(priv);
+	if (rc) {
+		wiphy_err(hw->wiphy, "Cannot start firmware\n");
+		return rc;
+	}
+
 	/*
 	 * Extra headroom is the size of the required DMA header
 	 * minus the size of the smallest 802.11 frame (CTS frame).
@@ -4325,28 +4465,29 @@ static int __devinit mwl8k_probe(struct pci_dev *pdev,
 	}
 
 	/*
-	 * Choose the initial fw image depending on user input and availability
-	 * of images.
+	 * Choose the initial fw image depending on user input.  If a second
+	 * image is available, make it the alternative image that will be
+	 * loaded if the first one fails.
 	 */
+	init_completion(&priv->firmware_loading_complete);
 	di = priv->device_info;
-	if (ap_mode_default && di->fw_image_ap)
-		rc = mwl8k_init_firmware(hw, di->fw_image_ap);
-	else if (!ap_mode_default && di->fw_image_sta)
-		rc = mwl8k_init_firmware(hw, di->fw_image_sta);
-	else if (ap_mode_default && !di->fw_image_ap && di->fw_image_sta) {
+	if (ap_mode_default && di->fw_image_ap) {
+		priv->fw_pref = di->fw_image_ap;
+		priv->fw_alt = di->fw_image_sta;
+	} else if (!ap_mode_default && di->fw_image_sta) {
+		priv->fw_pref = di->fw_image_sta;
+		priv->fw_alt = di->fw_image_ap;
+	} else if (ap_mode_default && !di->fw_image_ap && di->fw_image_sta) {
 		printk(KERN_WARNING "AP fw is unavailable.  Using STA fw.");
-		rc = mwl8k_init_firmware(hw, di->fw_image_sta);
+		priv->fw_pref = di->fw_image_sta;
 	} else if (!ap_mode_default && !di->fw_image_sta && di->fw_image_ap) {
 		printk(KERN_WARNING "STA fw is unavailable.  Using AP fw.");
-		rc = mwl8k_init_firmware(hw, di->fw_image_ap);
-	} else
-		rc = mwl8k_init_firmware(hw, di->fw_image_sta);
+		priv->fw_pref = di->fw_image_ap;
+	}
+	rc = mwl8k_init_firmware(hw, priv->fw_pref, true);
 	if (rc)
 		goto err_stop_firmware;
-
-	rc = mwl8k_firmware_load_success(priv);
-	if (!rc)
-		return rc;
+	return rc;
 
 err_stop_firmware:
 	mwl8k_hw_reset(priv);
@@ -4385,6 +4526,13 @@ static void __devexit mwl8k_remove(struct pci_dev *pdev)
 		return;
 	priv = hw->priv;
 
+	wait_for_completion(&priv->firmware_loading_complete);
+
+	if (priv->fw_state == FW_STATE_ERROR) {
+		mwl8k_hw_reset(priv);
+		goto unmap;
+	}
+
 	ieee80211_stop_queues(hw);
 
 	ieee80211_unregister_hw(hw);
@@ -4407,6 +4555,7 @@ static void __devexit mwl8k_remove(struct pci_dev *pdev)
 
 	pci_free_consistent(priv->pdev, 4, priv->cookie, priv->cookie_dma);
 
+unmap:
 	pci_iounmap(pdev, priv->regs);
 	pci_iounmap(pdev, priv->sram);
 	pci_set_drvdata(pdev, NULL);
Signature · 1 line
1.7.1.1
#29 lore raw

PATCH v2 7/7 mwl8k: use const struct fw pointers throughout

In reply to Brian Cavagnolo

This eliminates compiler warnings by doing things how the firmware class expects.

---
 drivers/net/wireless/mwl8k.c |   15 +++++++--------
 1 files changed, 7 insertions(+), 8 deletions(-)
drivers/net/wireless/mwl8k.c +7 -8
index 081bb6c..9ecf840 100644
@@ -144,8 +144,8 @@ struct mwl8k_priv {
 	void __iomem *regs;
 
 	/* firmware */
-	struct firmware *fw_helper;
-	struct firmware *fw_ucode;
+	const struct firmware *fw_helper;
+	const struct firmware *fw_ucode;
 
 	/* hardware/firmware parameters */
 	bool ap_fw;
@@ -395,7 +395,7 @@ static void mwl8k_hw_reset(struct mwl8k_priv *priv)
 }
 
 /* Release fw image */
-static void mwl8k_release_fw(struct firmware **fw)
+static void mwl8k_release_fw(const struct firmware **fw)
 {
 	if (*fw == NULL)
 		return;
@@ -420,7 +420,7 @@ enum {
 
 /* Request fw image */
 static int mwl8k_request_fw(struct mwl8k_priv *priv,
-			    const char *fname, struct firmware **fw,
+			    const char *fname, const struct firmware **fw,
 			    bool nowait)
 {
 	/* release current image */
@@ -432,8 +432,7 @@ static int mwl8k_request_fw(struct mwl8k_priv *priv,
 					       &priv->pdev->dev, GFP_KERNEL,
 					       priv, mwl8k_fw_state_machine);
 	else
-		return request_firmware((const struct firmware **)fw,
-					fname, &priv->pdev->dev);
+		return request_firmware(fw, fname, &priv->pdev->dev);
 }
 
 static int mwl8k_request_firmware(struct mwl8k_priv *priv, char *fw_image,
@@ -632,12 +631,12 @@ static int mwl8k_feed_fw_image(struct mwl8k_priv *priv,
 static int mwl8k_load_firmware(struct ieee80211_hw *hw)
 {
 	struct mwl8k_priv *priv = hw->priv;
-	struct firmware *fw = priv->fw_ucode;
+	const struct firmware *fw = priv->fw_ucode;
 	int rc;
 	int loops;
 
 	if (!memcmp(fw->data, "\x01\x00\x00\x00", 4)) {
-		struct firmware *helper = priv->fw_helper;
+		const struct firmware *helper = priv->fw_helper;
 
 		if (helper == NULL) {
 			printk(KERN_ERR "%s: helper image needed but none "
Signature · 1 line
1.7.1.1