Commit 83b00f6e authored by Sergey Matyukevich's avatar Sergey Matyukevich Committed by Kalle Valo

qtnfmac: simplify firmware state tracking

This patch streamlines firmware state tracking. In particular, state
QTNF_FW_STATE_FW_DNLD_DONE is removed, states QTNF_FW_STATE_RESET and
QTNF_FW_STATE_DETACHED are merged into a single state. Besides, new
state QTNF_FW_STATE_RUNNING is introduced to distinguish between
the following two cases:
- firmware load succeeded, firmware init process is ongoing
- firmware init succeeded, firmware is fully functional
Signed-off-by: default avatarSergey Matyukevich <sergey.matyukevich.os@quantenna.com>
Signed-off-by: default avatarKalle Valo <kvalo@codeaurora.org>
parent ae1946be
...@@ -13,12 +13,11 @@ ...@@ -13,12 +13,11 @@
#define QTNF_MAX_MAC 3 #define QTNF_MAX_MAC 3
enum qtnf_fw_state { enum qtnf_fw_state {
QTNF_FW_STATE_RESET, QTNF_FW_STATE_DETACHED,
QTNF_FW_STATE_FW_DNLD_DONE,
QTNF_FW_STATE_BOOT_DONE, QTNF_FW_STATE_BOOT_DONE,
QTNF_FW_STATE_ACTIVE, QTNF_FW_STATE_ACTIVE,
QTNF_FW_STATE_DETACHED, QTNF_FW_STATE_RUNNING,
QTNF_FW_STATE_EP_DEAD, QTNF_FW_STATE_DEAD,
}; };
struct qtnf_bus; struct qtnf_bus;
...@@ -58,6 +57,23 @@ struct qtnf_bus { ...@@ -58,6 +57,23 @@ struct qtnf_bus {
char bus_priv[0] __aligned(sizeof(void *)); char bus_priv[0] __aligned(sizeof(void *));
}; };
static inline bool qtnf_fw_is_up(struct qtnf_bus *bus)
{
enum qtnf_fw_state state = bus->fw_state;
return ((state == QTNF_FW_STATE_ACTIVE) ||
(state == QTNF_FW_STATE_RUNNING));
}
static inline bool qtnf_fw_is_attached(struct qtnf_bus *bus)
{
enum qtnf_fw_state state = bus->fw_state;
return ((state == QTNF_FW_STATE_ACTIVE) ||
(state == QTNF_FW_STATE_RUNNING) ||
(state == QTNF_FW_STATE_DEAD));
}
static inline void *get_bus_priv(struct qtnf_bus *bus) static inline void *get_bus_priv(struct qtnf_bus *bus)
{ {
if (WARN(!bus, "qtnfmac: invalid bus pointer")) if (WARN(!bus, "qtnfmac: invalid bus pointer"))
......
...@@ -89,8 +89,7 @@ static int qtnf_cmd_send_with_reply(struct qtnf_bus *bus, ...@@ -89,8 +89,7 @@ static int qtnf_cmd_send_with_reply(struct qtnf_bus *bus,
pr_debug("VIF%u.%u cmd=0x%.4X\n", mac_id, vif_id, cmd_id); pr_debug("VIF%u.%u cmd=0x%.4X\n", mac_id, vif_id, cmd_id);
if (bus->fw_state != QTNF_FW_STATE_ACTIVE && if (!qtnf_fw_is_up(bus) && cmd_id != QLINK_CMD_FW_INIT) {
cmd_id != QLINK_CMD_FW_INIT) {
pr_warn("VIF%u.%u: drop cmd 0x%.4X in fw state %d\n", pr_warn("VIF%u.%u: drop cmd 0x%.4X in fw state %d\n",
mac_id, vif_id, cmd_id, bus->fw_state); mac_id, vif_id, cmd_id, bus->fw_state);
dev_kfree_skb(cmd_skb); dev_kfree_skb(cmd_skb);
......
...@@ -589,8 +589,6 @@ int qtnf_core_attach(struct qtnf_bus *bus) ...@@ -589,8 +589,6 @@ int qtnf_core_attach(struct qtnf_bus *bus)
int ret; int ret;
qtnf_trans_init(bus); qtnf_trans_init(bus);
bus->fw_state = QTNF_FW_STATE_BOOT_DONE;
qtnf_bus_data_rx_start(bus); qtnf_bus_data_rx_start(bus);
bus->workqueue = alloc_ordered_workqueue("QTNF_BUS", 0); bus->workqueue = alloc_ordered_workqueue("QTNF_BUS", 0);
...@@ -639,6 +637,7 @@ int qtnf_core_attach(struct qtnf_bus *bus) ...@@ -639,6 +637,7 @@ int qtnf_core_attach(struct qtnf_bus *bus)
} }
} }
bus->fw_state = QTNF_FW_STATE_RUNNING;
return 0; return 0;
error: error:
...@@ -657,7 +656,7 @@ void qtnf_core_detach(struct qtnf_bus *bus) ...@@ -657,7 +656,7 @@ void qtnf_core_detach(struct qtnf_bus *bus)
for (macid = 0; macid < QTNF_MAX_MAC; macid++) for (macid = 0; macid < QTNF_MAX_MAC; macid++)
qtnf_core_mac_detach(bus, macid); qtnf_core_mac_detach(bus, macid);
if (bus->fw_state == QTNF_FW_STATE_ACTIVE) if (qtnf_fw_is_up(bus))
qtnf_cmd_send_deinit_fw(bus); qtnf_cmd_send_deinit_fw(bus);
bus->fw_state = QTNF_FW_STATE_DETACHED; bus->fw_state = QTNF_FW_STATE_DETACHED;
...@@ -683,6 +682,9 @@ struct net_device *qtnf_classify_skb(struct qtnf_bus *bus, struct sk_buff *skb) ...@@ -683,6 +682,9 @@ struct net_device *qtnf_classify_skb(struct qtnf_bus *bus, struct sk_buff *skb)
struct qtnf_wmac *mac; struct qtnf_wmac *mac;
struct qtnf_vif *vif; struct qtnf_vif *vif;
if (unlikely(bus->fw_state != QTNF_FW_STATE_RUNNING))
return NULL;
meta = (struct qtnf_frame_meta_info *) meta = (struct qtnf_frame_meta_info *)
(skb_tail_pointer(skb) - sizeof(*meta)); (skb_tail_pointer(skb) - sizeof(*meta));
......
...@@ -56,7 +56,7 @@ int qtnf_pcie_control_tx(struct qtnf_bus *bus, struct sk_buff *skb) ...@@ -56,7 +56,7 @@ int qtnf_pcie_control_tx(struct qtnf_bus *bus, struct sk_buff *skb)
if (ret == -ETIMEDOUT) { if (ret == -ETIMEDOUT) {
pr_err("EP firmware is dead\n"); pr_err("EP firmware is dead\n");
bus->fw_state = QTNF_FW_STATE_EP_DEAD; bus->fw_state = QTNF_FW_STATE_DEAD;
} }
return ret; return ret;
...@@ -132,11 +132,10 @@ int qtnf_pcie_fw_boot_done(struct qtnf_bus *bus) ...@@ -132,11 +132,10 @@ int qtnf_pcie_fw_boot_done(struct qtnf_bus *bus)
{ {
int ret; int ret;
bus->fw_state = QTNF_FW_STATE_FW_DNLD_DONE; bus->fw_state = QTNF_FW_STATE_BOOT_DONE;
ret = qtnf_core_attach(bus); ret = qtnf_core_attach(bus);
if (ret) { if (ret) {
pr_err("failed to attach core\n"); pr_err("failed to attach core\n");
bus->fw_state = QTNF_FW_STATE_DETACHED;
} else { } else {
qtnf_debugfs_init(bus, DRV_NAME); qtnf_debugfs_init(bus, DRV_NAME);
qtnf_debugfs_add_entry(bus, "mps", qtnf_dbg_mps_show); qtnf_debugfs_add_entry(bus, "mps", qtnf_dbg_mps_show);
...@@ -335,7 +334,7 @@ static int qtnf_pcie_probe(struct pci_dev *pdev, const struct pci_device_id *id) ...@@ -335,7 +334,7 @@ static int qtnf_pcie_probe(struct pci_dev *pdev, const struct pci_device_id *id)
pcie_priv = get_bus_priv(bus); pcie_priv = get_bus_priv(bus);
pci_set_drvdata(pdev, bus); pci_set_drvdata(pdev, bus);
bus->dev = &pdev->dev; bus->dev = &pdev->dev;
bus->fw_state = QTNF_FW_STATE_RESET; bus->fw_state = QTNF_FW_STATE_DETACHED;
pcie_priv->pdev = pdev; pcie_priv->pdev = pdev;
pcie_priv->tx_stopped = 0; pcie_priv->tx_stopped = 0;
pcie_priv->rx_bd_num = rx_bd_size_param; pcie_priv->rx_bd_num = rx_bd_size_param;
...@@ -410,8 +409,7 @@ static void qtnf_pcie_remove(struct pci_dev *dev) ...@@ -410,8 +409,7 @@ static void qtnf_pcie_remove(struct pci_dev *dev)
cancel_work_sync(&bus->fw_work); cancel_work_sync(&bus->fw_work);
if (bus->fw_state == QTNF_FW_STATE_ACTIVE || if (qtnf_fw_is_attached(bus))
bus->fw_state == QTNF_FW_STATE_EP_DEAD)
qtnf_core_detach(bus); qtnf_core_detach(bus);
netif_napi_del(&bus->mux_napi); netif_napi_del(&bus->mux_napi);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment