2024-01-30 19:23:28

by Alex Elder

[permalink] [raw]
Subject: [PATCH net-next 0/7] net: ipa: simplify TX power handling

In order to deliver a packet to the IPA hardware, we must ensure
it is powered. We request power by calling pm_runtime_get(), and
its return value tells us the power state. We can't block in
ipa_start_xmit(), so if power isn't enabled we prevent further
transmit attempts by calling netif_stop_queue(). Power will
eventually become enabled, at which point we call netif_wake_queue()
to allow the transmit to be retried. When it does, the power should
be enabled, so the packet delivery can proceed.

The logic that handles this is convoluted, and was put in place
to address a race condition pointed out by Jakub Kicinski during
review. The fix addressed that race, as well as another one that
was found while investigating it:
b8e36e13ea5e ("net: ipa: fix TX queue race")
I have wanted to simplify this code ever since, and I'm pleased to
report that this series implements a much better solution that
avoids both race conditions.

The first race occurs between the ->ndo_start_xmit thread and the
runtime resume thread. If we find power is not enabled when
requested in ipa_start_xmit(), we stop queueing. But there's a
chance the runtime resume will enable queuing just before that,
leaving queueing stopped forever. A flag is used to ensure that
does not occur.

A second flag is used to prevent NETDEV_TX_BUSY from being returned
repeatedly during the small window between enabling queueing and
finishing power resume. This can happen if resume was underway when
pm_runtime_get() was called and completes immediately afterward.
This condition only exists because of the use of the first flag.

The fix is to disable transmit for *every* call to ipa_start_xmit(),
disabling it *before* calling pm_runtime_get(). This leaves three
cases:
- If the return value indicates power is not active (or is in
transition), queueing remains disabled--thereby avoiding
the race between disabling it and a concurrent power thread
enabling it.
- If pm_runtime_get() returns an error, we drop the packet and
re-enable queueing.
- Finally, if the hardware is powered, we re-enable queueing
before delivering the packet to the hardware.

So the first race is avoided. And as a result, the second condition
will not occur.


The first patch adds pointers to the TX and RX IPA endpoints in the
netdev private data. The second patch has netif_stop_queue() be
called for all packets; if pm_runtime_get() indicates power is
enabled (or an error), netif_wake_queue() is called to enable it
again. The third and fourth patches get rid of the STARTED and
STOPPED IPA power flags, as well as the power spinlock, because they
are no longer needed. The last three patches just eliminate some
trivial functions, open-coding them instead.

-Alex

Alex Elder (7):
net: ipa: stash modem TX and RX endpoints
net: ipa: begin simplifying TX queue stop
net: ipa: kill the STARTED IPA power flag
net: ipa: kill the IPA power STOPPED flag
net: ipa: kill ipa_power_modem_queue_stop()
net: ipa: kill ipa_power_modem_queue_active()
net: ipa: kill ipa_power_modem_queue_wake()

drivers/net/ipa/ipa_modem.c | 96 +++++++++++++++++++++++--------------
drivers/net/ipa/ipa_power.c | 71 ---------------------------
drivers/net/ipa/ipa_power.h | 18 -------
3 files changed, 61 insertions(+), 124 deletions(-)

--
2.40.1



2024-01-30 19:23:47

by Alex Elder

[permalink] [raw]
Subject: [PATCH net-next 1/7] net: ipa: stash modem TX and RX endpoints

Rather than repeatedly looking up the endpoints in the name map,
save the modem TX and RX endpoint pointers in the netdev private
area.

Signed-off-by: Alex Elder <[email protected]>
---
drivers/net/ipa/ipa_modem.c | 49 +++++++++++++++++++++++--------------
1 file changed, 30 insertions(+), 19 deletions(-)

diff --git a/drivers/net/ipa/ipa_modem.c b/drivers/net/ipa/ipa_modem.c
index 423422a2a445f..a6f6cd149c1b6 100644
--- a/drivers/net/ipa/ipa_modem.c
+++ b/drivers/net/ipa/ipa_modem.c
@@ -39,10 +39,14 @@ enum ipa_modem_state {
/**
* struct ipa_priv - IPA network device private data
* @ipa: IPA pointer
+ * @tx: Transmit endpoint pointer
+ * @rx: Receive endpoint pointer
* @work: Work structure used to wake the modem netdev TX queue
*/
struct ipa_priv {
struct ipa *ipa;
+ struct ipa_endpoint *tx;
+ struct ipa_endpoint *rx;
struct work_struct work;
};

@@ -59,11 +63,11 @@ static int ipa_open(struct net_device *netdev)
if (ret < 0)
goto err_power_put;

- ret = ipa_endpoint_enable_one(ipa->name_map[IPA_ENDPOINT_AP_MODEM_TX]);
+ ret = ipa_endpoint_enable_one(priv->tx);
if (ret)
goto err_power_put;

- ret = ipa_endpoint_enable_one(ipa->name_map[IPA_ENDPOINT_AP_MODEM_RX]);
+ ret = ipa_endpoint_enable_one(priv->rx);
if (ret)
goto err_disable_tx;

@@ -75,7 +79,7 @@ static int ipa_open(struct net_device *netdev)
return 0;

err_disable_tx:
- ipa_endpoint_disable_one(ipa->name_map[IPA_ENDPOINT_AP_MODEM_TX]);
+ ipa_endpoint_disable_one(priv->tx);
err_power_put:
pm_runtime_put_noidle(dev);

@@ -97,8 +101,8 @@ static int ipa_stop(struct net_device *netdev)

netif_stop_queue(netdev);

- ipa_endpoint_disable_one(ipa->name_map[IPA_ENDPOINT_AP_MODEM_RX]);
- ipa_endpoint_disable_one(ipa->name_map[IPA_ENDPOINT_AP_MODEM_TX]);
+ ipa_endpoint_disable_one(priv->rx);
+ ipa_endpoint_disable_one(priv->tx);
out_power_put:
pm_runtime_mark_last_busy(dev);
(void)pm_runtime_put_autosuspend(dev);
@@ -233,14 +237,14 @@ static void ipa_modem_netdev_setup(struct net_device *netdev)
*/
void ipa_modem_suspend(struct net_device *netdev)
{
- struct ipa_priv *priv = netdev_priv(netdev);
- struct ipa *ipa = priv->ipa;
+ struct ipa_priv *priv;

if (!(netdev->flags & IFF_UP))
return;

- ipa_endpoint_suspend_one(ipa->name_map[IPA_ENDPOINT_AP_MODEM_RX]);
- ipa_endpoint_suspend_one(ipa->name_map[IPA_ENDPOINT_AP_MODEM_TX]);
+ priv = netdev_priv(netdev);
+ ipa_endpoint_suspend_one(priv->rx);
+ ipa_endpoint_suspend_one(priv->tx);
}

/**
@@ -268,14 +272,14 @@ static void ipa_modem_wake_queue_work(struct work_struct *work)
*/
void ipa_modem_resume(struct net_device *netdev)
{
- struct ipa_priv *priv = netdev_priv(netdev);
- struct ipa *ipa = priv->ipa;
+ struct ipa_priv *priv;

if (!(netdev->flags & IFF_UP))
return;

- ipa_endpoint_resume_one(ipa->name_map[IPA_ENDPOINT_AP_MODEM_TX]);
- ipa_endpoint_resume_one(ipa->name_map[IPA_ENDPOINT_AP_MODEM_RX]);
+ priv = netdev_priv(netdev);
+ ipa_endpoint_resume_one(priv->tx);
+ ipa_endpoint_resume_one(priv->rx);

/* Arrange for the TX queue to be restarted */
(void)queue_pm_work(&priv->work);
@@ -306,16 +310,21 @@ int ipa_modem_start(struct ipa *ipa)
SET_NETDEV_DEV(netdev, &ipa->pdev->dev);
priv = netdev_priv(netdev);
priv->ipa = ipa;
+ priv->tx = ipa->name_map[IPA_ENDPOINT_AP_MODEM_TX];
+ priv->rx = ipa->name_map[IPA_ENDPOINT_AP_MODEM_RX];
INIT_WORK(&priv->work, ipa_modem_wake_queue_work);
- ipa->name_map[IPA_ENDPOINT_AP_MODEM_TX]->netdev = netdev;
- ipa->name_map[IPA_ENDPOINT_AP_MODEM_RX]->netdev = netdev;
+
+ priv->tx->netdev = netdev;
+ priv->rx->netdev = netdev;
+
ipa->modem_netdev = netdev;

ret = register_netdev(netdev);
if (ret) {
ipa->modem_netdev = NULL;
- ipa->name_map[IPA_ENDPOINT_AP_MODEM_RX]->netdev = NULL;
- ipa->name_map[IPA_ENDPOINT_AP_MODEM_TX]->netdev = NULL;
+ priv->rx->netdev = NULL;
+ priv->tx->netdev = NULL;
+
free_netdev(netdev);
}

@@ -355,9 +364,11 @@ int ipa_modem_stop(struct ipa *ipa)
if (netdev->flags & IFF_UP)
(void)ipa_stop(netdev);
unregister_netdev(netdev);
+
ipa->modem_netdev = NULL;
- ipa->name_map[IPA_ENDPOINT_AP_MODEM_RX]->netdev = NULL;
- ipa->name_map[IPA_ENDPOINT_AP_MODEM_TX]->netdev = NULL;
+ priv->rx->netdev = NULL;
+ priv->tx->netdev = NULL;
+
free_netdev(netdev);
}

--
2.40.1


2024-01-30 19:24:15

by Alex Elder

[permalink] [raw]
Subject: [PATCH net-next 2/7] net: ipa: begin simplifying TX queue stop

There are a number of flags used in the IPA driver to attempt to
manage race conditions that can occur between runtime resume and
netdev transmit. If we disable TX before requesting power, we can
avoid these races entirely, simplifying things considerably.

This patch implements the main change, disabling transmit always in
the net_device->ndo_start_xmit() callback, then re-enabling it again
whenever we find power is active (or when we drop the skb).

The patches that follow will refactor the "old" code to the point
that most of it can be eliminated.

Signed-off-by: Alex Elder <[email protected]>
---
drivers/net/ipa/ipa_modem.c | 41 +++++++++++++++++++++++-----------
drivers/net/ipa/ipa_power.c | 44 ++++++++++++++++++++++---------------
2 files changed, 54 insertions(+), 31 deletions(-)

diff --git a/drivers/net/ipa/ipa_modem.c b/drivers/net/ipa/ipa_modem.c
index a6f6cd149c1b6..c7a0b167c4326 100644
--- a/drivers/net/ipa/ipa_modem.c
+++ b/drivers/net/ipa/ipa_modem.c
@@ -110,13 +110,16 @@ static int ipa_stop(struct net_device *netdev)
return 0;
}

-/** ipa_start_xmit() - Transmits an skb.
- * @skb: skb to be transmitted
- * @dev: network device
+/** ipa_start_xmit() - Transmit an skb
+ * @skb: Socket buffer to be transmitted
+ * @netdev: Network device
*
- * Return codes:
- * NETDEV_TX_OK: Success
- * NETDEV_TX_BUSY: Error while transmitting the skb. Try again later
+ * Return: NETDEV_TX_OK if successful (or dropped), NETDEV_TX_BUSY otherwise
+
+ * Normally NETDEV_TX_OK indicates the buffer was successfully transmitted.
+ * If the buffer has an unexpected protocol or its size is out of range it
+ * is quietly dropped, returning NETDEV_TX_OK. NETDEV_TX_BUSY indicates
+ * the buffer cannot be sent at this time and should retried later.
*/
static netdev_tx_t
ipa_start_xmit(struct sk_buff *skb, struct net_device *netdev)
@@ -136,7 +139,25 @@ ipa_start_xmit(struct sk_buff *skb, struct net_device *netdev)
if (endpoint->config.qmap && skb->protocol != htons(ETH_P_MAP))
goto err_drop_skb;

- /* The hardware must be powered for us to transmit */
+ /* The hardware must be powered for us to transmit, so if we're not
+ * ready we want the network stack to stop queueing until power is
+ * ACTIVE. Once runtime resume has completed, we inform the network
+ * stack it's OK to try transmitting again.
+ *
+ * We learn from pm_runtime_get() whether the hardware is powered.
+ * If it was not, powering up is either started or already underway.
+ * And in that case we want to disable queueing, expecting it to be
+ * re-enabled once power is ACTIVE. But runtime PM and network
+ * transmit run concurrently, and if we're not careful the requests
+ * to stop and start queueing could occur in the wrong order.
+ *
+ * For that reason we *always* stop queueing here, *before* the call
+ * to pm_runtime_get(). If we determine here that power is ACTIVE,
+ * we restart queueing before transmitting the SKB. Otherwise
+ * queueing will eventually be enabled after resume completes.
+ */
+ ipa_power_modem_queue_stop(ipa);
+
dev = &ipa->pdev->dev;
ret = pm_runtime_get(dev);
if (ret < 1) {
@@ -147,12 +168,6 @@ ipa_start_xmit(struct sk_buff *skb, struct net_device *netdev)
goto err_drop_skb;
}

- /* No power (yet). Stop the network stack from transmitting
- * until we're resumed; ipa_modem_resume() arranges for the
- * TX queue to be started again.
- */
- ipa_power_modem_queue_stop(ipa);
-
pm_runtime_put_noidle(dev);

return NETDEV_TX_BUSY;
diff --git a/drivers/net/ipa/ipa_power.c b/drivers/net/ipa/ipa_power.c
index e223886123cea..f1802448ff447 100644
--- a/drivers/net/ipa/ipa_power.c
+++ b/drivers/net/ipa/ipa_power.c
@@ -233,28 +233,32 @@ void ipa_power_suspend_handler(struct ipa *ipa, enum ipa_irq_id irq_id)
ipa_interrupt_suspend_clear_all(ipa->interrupt);
}

-/* The next few functions coordinate stopping and starting the modem
+/* The next few functions are used when stopping and starting the modem
* network device transmit queue.
*
- * Transmit can be running concurrent with power resume, and there's a
- * chance the resume completes before the transmit path stops the queue,
- * leaving the queue in a stopped state. The next two functions are used
- * to avoid this: ipa_power_modem_queue_stop() is used by ipa_start_xmit()
- * to conditionally stop the TX queue; and ipa_power_modem_queue_start()
- * is used by ipa_runtime_resume() to conditionally restart it.
+ * Transmit can run concurrent with power resume. When transmitting,
+ * we disable further transmits until we can determine whether power
+ * is ACTIVE. If it is, future transmits are re-enabled and the buffer
+ * gets sent (or dropped). If power is not ACTIVE, it will eventually
+ * be, and transmits stay disabled until after it is.
*
- * Two flags and a spinlock are used. If the queue is stopped, the STOPPED
- * power flag is set. And if the queue is started, the STARTED flag is set.
- * The queue is only started on resume if the STOPPED flag is set. And the
- * queue is only started in ipa_start_xmit() if the STARTED flag is *not*
- * set. As a result, the queue remains operational if the two activites
- * happen concurrently regardless of the order they complete. The spinlock
- * ensures the flag and TX queue operations are done atomically.
+ * Two flags and a spinlock are used when managing this. If the queue
+ * is stopped, the STOPPED power flag is set. And if the queue is
+ * started, the STARTED flag is set.
*
* The first function stops the modem netdev transmit queue, but only if
- * the STARTED flag is *not* set. That flag is cleared if it was set.
- * If the queue is stopped, the STOPPED flag is set. This is called only
- * from the power ->runtime_resume operation.
+ * the STARTED flag is *not* set. This previously avoided a race where
+ * the TX path stops further transmits after power has become ACTIVE.
+ * The STARTED flag is cleared by this function.
+ *
+ * The second function starts the transmit queue, but only if the
+ * STOPPED flag is set. This avoids enabling transmits repeatedly
+ * immediately after power has become ACTIVE (not really a big deal).
+ * If the STOPPED flag was set, it is cleared and the STARTED flag
+ * is set by this function.
+ *
+ * The third function enables transmits again and clears the STARTED
+ * flag in case it was set, to return it to initial state.
*/
void ipa_power_modem_queue_stop(struct ipa *ipa)
{
@@ -291,9 +295,13 @@ void ipa_power_modem_queue_wake(struct ipa *ipa)
spin_unlock_irqrestore(&power->spinlock, flags);
}

-/* This function clears the STARTED flag once the TX queue is operating */
+/* This function is run after power has become ACTIVE. It enables transmits
+ * again clears the STARTED flag to indicate the TX queue is operating and
+ * can be stopped again if necessary.
+ */
void ipa_power_modem_queue_active(struct ipa *ipa)
{
+ netif_wake_queue(ipa->modem_netdev);
clear_bit(IPA_POWER_FLAG_STARTED, ipa->power->flags);
}

--
2.40.1


2024-01-30 19:24:48

by Alex Elder

[permalink] [raw]
Subject: [PATCH net-next 4/7] net: ipa: kill the IPA power STOPPED flag

Currently the STOPPED IPA power flag is used to indicate that the
transmit queue has been stopped. Previously this was used to avoid
setting the STARTED flag unless the queue had already been stopped.
It meant transmit queuing would be enabled on resume if it was
stopped by the transmit path--and if so, it ensured it only got
enabled once.

We only stop the transmit queue in the transmit path. The STARTED
flag has been removed, and it causes no real harm to enable
transmits when they're already enabled. So we can get rid of
the STOPPED flag and call netif_wake_queue() unconditionally.

This makes the IPA power spinlock unnecessary, so it can be removed
as well.

Signed-off-by: Alex Elder <[email protected]>
---
drivers/net/ipa/ipa_power.c | 40 +++++--------------------------------
1 file changed, 5 insertions(+), 35 deletions(-)

diff --git a/drivers/net/ipa/ipa_power.c b/drivers/net/ipa/ipa_power.c
index 509c9bfa648e7..e615473d23805 100644
--- a/drivers/net/ipa/ipa_power.c
+++ b/drivers/net/ipa/ipa_power.c
@@ -38,13 +38,11 @@
* enum ipa_power_flag - IPA power flags
* @IPA_POWER_FLAG_RESUMED: Whether resume from suspend has been signaled
* @IPA_POWER_FLAG_SYSTEM: Hardware is system (not runtime) suspended
- * @IPA_POWER_FLAG_STOPPED: Modem TX is disabled by ipa_start_xmit()
* @IPA_POWER_FLAG_COUNT: Number of defined power flags
*/
enum ipa_power_flag {
IPA_POWER_FLAG_RESUMED,
IPA_POWER_FLAG_SYSTEM,
- IPA_POWER_FLAG_STOPPED,
IPA_POWER_FLAG_COUNT, /* Last; not a flag */
};

@@ -53,7 +51,6 @@ enum ipa_power_flag {
* @dev: IPA device pointer
* @core: IPA core clock
* @qmp: QMP handle for AOSS communication
- * @spinlock: Protects modem TX queue enable/disable
* @flags: Boolean state flags
* @interconnect_count: Number of elements in interconnect[]
* @interconnect: Interconnect array
@@ -62,7 +59,6 @@ struct ipa_power {
struct device *dev;
struct clk *core;
struct qmp *qmp;
- spinlock_t spinlock; /* used with STOPPED power flag */
DECLARE_BITMAP(flags, IPA_POWER_FLAG_COUNT);
u32 interconnect_count;
struct icc_bulk_data interconnect[] __counted_by(interconnect_count);
@@ -240,47 +236,22 @@ void ipa_power_suspend_handler(struct ipa *ipa, enum ipa_irq_id irq_id)
* gets sent (or dropped). If power is not ACTIVE, it will eventually
* be, and transmits stay disabled until after it is.
*
- * A flag and a spinlock are used when managing this. If the queue gets
- * stopped, the STOPPED power flag is set.
- *
* The first function stops the modem netdev transmit queue. The second
- * function starts the transmit queue, but only if the STOPPED flag is
- * set. This avoids enabling transmits repeatedly immediately after
- * power has become ACTIVE (not really a big deal). If the STOPPED flag
- * was set, it is cleared by this function.
- *
- * The third function just enables transmits again.
+ * function starts the transmit queue and is used in the power resume
+ * path after power has become ACTIVE. The third function also enables
+ * transmits again, and is used by ipa_start_xmit() once it knows power
+ * is active.
*/
void ipa_power_modem_queue_stop(struct ipa *ipa)
{
- struct ipa_power *power = ipa->power;
- unsigned long flags;
-
- spin_lock_irqsave(&power->spinlock, flags);
-
netif_stop_queue(ipa->modem_netdev);
- __set_bit(IPA_POWER_FLAG_STOPPED, power->flags);
-
- spin_unlock_irqrestore(&power->spinlock, flags);
}

-/* This function starts the modem netdev transmit queue, but only if the
- * STOPPED flag is set. That flag is cleared if it was set.
- */
void ipa_power_modem_queue_wake(struct ipa *ipa)
{
- struct ipa_power *power = ipa->power;
- unsigned long flags;
-
- spin_lock_irqsave(&power->spinlock, flags);
-
- if (__test_and_clear_bit(IPA_POWER_FLAG_STOPPED, power->flags))
- netif_wake_queue(ipa->modem_netdev);
-
- spin_unlock_irqrestore(&power->spinlock, flags);
+ netif_wake_queue(ipa->modem_netdev);
}

-/* This function enables transmits again after power has become ACTIVE. */
void ipa_power_modem_queue_active(struct ipa *ipa)
{
netif_wake_queue(ipa->modem_netdev);
@@ -374,7 +345,6 @@ ipa_power_init(struct device *dev, const struct ipa_power_data *data)
}
power->dev = dev;
power->core = clk;
- spin_lock_init(&power->spinlock);
power->interconnect_count = data->interconnect_count;

ret = ipa_interconnect_init(power, data->interconnect_data);
--
2.40.1


2024-01-30 19:25:37

by Alex Elder

[permalink] [raw]
Subject: [PATCH net-next 6/7] net: ipa: kill ipa_power_modem_queue_active()

All ipa_power_modem_queue_active() does now is call netif_wake_queue().
Just call netif_wake_queue() in the two places it's needed, and get
rid of ipa_power_modem_queue_active().

Signed-off-by: Alex Elder <[email protected]>
---
drivers/net/ipa/ipa_modem.c | 4 ++--
drivers/net/ipa/ipa_power.c | 19 ++++---------------
drivers/net/ipa/ipa_power.h | 6 ------
3 files changed, 6 insertions(+), 23 deletions(-)

diff --git a/drivers/net/ipa/ipa_modem.c b/drivers/net/ipa/ipa_modem.c
index 08e1202f12863..0c298060468eb 100644
--- a/drivers/net/ipa/ipa_modem.c
+++ b/drivers/net/ipa/ipa_modem.c
@@ -163,7 +163,7 @@ ipa_start_xmit(struct sk_buff *skb, struct net_device *netdev)
if (ret < 1) {
/* If a resume won't happen, just drop the packet */
if (ret < 0 && ret != -EINPROGRESS) {
- ipa_power_modem_queue_active(ipa);
+ netif_wake_queue(netdev);
pm_runtime_put_noidle(dev);
goto err_drop_skb;
}
@@ -173,7 +173,7 @@ ipa_start_xmit(struct sk_buff *skb, struct net_device *netdev)
return NETDEV_TX_BUSY;
}

- ipa_power_modem_queue_active(ipa);
+ netif_wake_queue(netdev);

ret = ipa_endpoint_skb_tx(endpoint, skb);

diff --git a/drivers/net/ipa/ipa_power.c b/drivers/net/ipa/ipa_power.c
index 812359c7977da..fd2abce043fa5 100644
--- a/drivers/net/ipa/ipa_power.c
+++ b/drivers/net/ipa/ipa_power.c
@@ -227,30 +227,19 @@ void ipa_power_suspend_handler(struct ipa *ipa, enum ipa_irq_id irq_id)
ipa_interrupt_suspend_clear_all(ipa->interrupt);
}

-/* The next two functions are used when stopping and starting the modem
- * network device transmit queue.
- *
- * Transmit can run concurrent with power resume. When transmitting,
+/* Transmit can run concurrent with power resume. When transmitting,
* we disable further transmits until we can determine whether power
* is ACTIVE. If it is, future transmits are re-enabled and the buffer
* gets sent (or dropped). If power is not ACTIVE, it will eventually
- * be, and transmits stay disabled until after it is.
- *
- * The first function starts the transmit queue and is used in the power
- * resume path after power has become ACTIVE. The second function also
- * enables transmits again, and is used by ipa_start_xmit() once it
- * knows power is active.
+ * be, and transmits stay disabled until after it is. This function
+ * starts the transmit queue and is used in the power resume path after
+ * power has become ACTIVE.
*/
void ipa_power_modem_queue_wake(struct ipa *ipa)
{
netif_wake_queue(ipa->modem_netdev);
}

-void ipa_power_modem_queue_active(struct ipa *ipa)
-{
- netif_wake_queue(ipa->modem_netdev);
-}
-
static int ipa_power_retention_init(struct ipa_power *power)
{
struct qmp *qmp = qmp_get(power->dev);
diff --git a/drivers/net/ipa/ipa_power.h b/drivers/net/ipa/ipa_power.h
index f51653399a07d..dcd36a6a718f2 100644
--- a/drivers/net/ipa/ipa_power.h
+++ b/drivers/net/ipa/ipa_power.h
@@ -29,12 +29,6 @@ u32 ipa_core_clock_rate(struct ipa *ipa);
*/
void ipa_power_modem_queue_wake(struct ipa *ipa);

-/**
- * ipa_power_modem_queue_active() - Report modem netdev TX queue active
- * @ipa: IPA pointer
- */
-void ipa_power_modem_queue_active(struct ipa *ipa);
-
/**
* ipa_power_retention() - Control register retention on power collapse
* @ipa: IPA pointer
--
2.40.1


2024-01-30 19:26:01

by Alex Elder

[permalink] [raw]
Subject: [PATCH net-next 7/7] net: ipa: kill ipa_power_modem_queue_wake()

All ipa_power_modem_queue_wake() does is call netif_wake_queue()
on the modem netdev. There is no need to wrap that call in a
trivial function (and certainly not one defined in "ipa_power.c").

So get rid of ipa_power_modem_queue_wake(), and replace its one
caller with a direct call to netif_wake_queue(). Determine the
netdev pointer to use from the private TX endpoint's netdev pointer.

Signed-off-by: Alex Elder <[email protected]>
---
drivers/net/ipa/ipa_modem.c | 2 +-
drivers/net/ipa/ipa_power.c | 13 -------------
drivers/net/ipa/ipa_power.h | 6 ------
3 files changed, 1 insertion(+), 20 deletions(-)

diff --git a/drivers/net/ipa/ipa_modem.c b/drivers/net/ipa/ipa_modem.c
index 0c298060468eb..1d1be92fbebcb 100644
--- a/drivers/net/ipa/ipa_modem.c
+++ b/drivers/net/ipa/ipa_modem.c
@@ -277,7 +277,7 @@ static void ipa_modem_wake_queue_work(struct work_struct *work)
{
struct ipa_priv *priv = container_of(work, struct ipa_priv, work);

- ipa_power_modem_queue_wake(priv->ipa);
+ netif_wake_queue(priv->tx->netdev);
}

/** ipa_modem_resume() - resume callback for runtime_pm
diff --git a/drivers/net/ipa/ipa_power.c b/drivers/net/ipa/ipa_power.c
index fd2abce043fa5..128a816f65237 100644
--- a/drivers/net/ipa/ipa_power.c
+++ b/drivers/net/ipa/ipa_power.c
@@ -227,19 +227,6 @@ void ipa_power_suspend_handler(struct ipa *ipa, enum ipa_irq_id irq_id)
ipa_interrupt_suspend_clear_all(ipa->interrupt);
}

-/* Transmit can run concurrent with power resume. When transmitting,
- * we disable further transmits until we can determine whether power
- * is ACTIVE. If it is, future transmits are re-enabled and the buffer
- * gets sent (or dropped). If power is not ACTIVE, it will eventually
- * be, and transmits stay disabled until after it is. This function
- * starts the transmit queue and is used in the power resume path after
- * power has become ACTIVE.
- */
-void ipa_power_modem_queue_wake(struct ipa *ipa)
-{
- netif_wake_queue(ipa->modem_netdev);
-}
-
static int ipa_power_retention_init(struct ipa_power *power)
{
struct qmp *qmp = qmp_get(power->dev);
diff --git a/drivers/net/ipa/ipa_power.h b/drivers/net/ipa/ipa_power.h
index dcd36a6a718f2..718aacf5e2b23 100644
--- a/drivers/net/ipa/ipa_power.h
+++ b/drivers/net/ipa/ipa_power.h
@@ -23,12 +23,6 @@ extern const struct dev_pm_ops ipa_pm_ops;
*/
u32 ipa_core_clock_rate(struct ipa *ipa);

-/**
- * ipa_power_modem_queue_wake() - Possibly wake the modem netdev TX queue
- * @ipa: IPA pointer
- */
-void ipa_power_modem_queue_wake(struct ipa *ipa);
-
/**
* ipa_power_retention() - Control register retention on power collapse
* @ipa: IPA pointer
--
2.40.1


2024-01-30 19:27:34

by Alex Elder

[permalink] [raw]
Subject: [PATCH net-next 5/7] net: ipa: kill ipa_power_modem_queue_stop()

All ipa_power_modem_queue_stop() does now is call netif_stop_queue().
Just call netif_stop_queue() in the one place it's needed, and get
rid of ipa_power_modem_queue_stop().

Signed-off-by: Alex Elder <[email protected]>
---
drivers/net/ipa/ipa_modem.c | 2 +-
drivers/net/ipa/ipa_power.c | 16 +++++-----------
drivers/net/ipa/ipa_power.h | 6 ------
3 files changed, 6 insertions(+), 18 deletions(-)

diff --git a/drivers/net/ipa/ipa_modem.c b/drivers/net/ipa/ipa_modem.c
index c7a0b167c4326..08e1202f12863 100644
--- a/drivers/net/ipa/ipa_modem.c
+++ b/drivers/net/ipa/ipa_modem.c
@@ -156,7 +156,7 @@ ipa_start_xmit(struct sk_buff *skb, struct net_device *netdev)
* we restart queueing before transmitting the SKB. Otherwise
* queueing will eventually be enabled after resume completes.
*/
- ipa_power_modem_queue_stop(ipa);
+ netif_stop_queue(netdev);

dev = &ipa->pdev->dev;
ret = pm_runtime_get(dev);
diff --git a/drivers/net/ipa/ipa_power.c b/drivers/net/ipa/ipa_power.c
index e615473d23805..812359c7977da 100644
--- a/drivers/net/ipa/ipa_power.c
+++ b/drivers/net/ipa/ipa_power.c
@@ -227,7 +227,7 @@ void ipa_power_suspend_handler(struct ipa *ipa, enum ipa_irq_id irq_id)
ipa_interrupt_suspend_clear_all(ipa->interrupt);
}

-/* The next few functions are used when stopping and starting the modem
+/* The next two functions are used when stopping and starting the modem
* network device transmit queue.
*
* Transmit can run concurrent with power resume. When transmitting,
@@ -236,17 +236,11 @@ void ipa_power_suspend_handler(struct ipa *ipa, enum ipa_irq_id irq_id)
* gets sent (or dropped). If power is not ACTIVE, it will eventually
* be, and transmits stay disabled until after it is.
*
- * The first function stops the modem netdev transmit queue. The second
- * function starts the transmit queue and is used in the power resume
- * path after power has become ACTIVE. The third function also enables
- * transmits again, and is used by ipa_start_xmit() once it knows power
- * is active.
+ * The first function starts the transmit queue and is used in the power
+ * resume path after power has become ACTIVE. The second function also
+ * enables transmits again, and is used by ipa_start_xmit() once it
+ * knows power is active.
*/
-void ipa_power_modem_queue_stop(struct ipa *ipa)
-{
- netif_stop_queue(ipa->modem_netdev);
-}
-
void ipa_power_modem_queue_wake(struct ipa *ipa)
{
netif_wake_queue(ipa->modem_netdev);
diff --git a/drivers/net/ipa/ipa_power.h b/drivers/net/ipa/ipa_power.h
index 3a4c59ea1222b..f51653399a07d 100644
--- a/drivers/net/ipa/ipa_power.h
+++ b/drivers/net/ipa/ipa_power.h
@@ -23,12 +23,6 @@ extern const struct dev_pm_ops ipa_pm_ops;
*/
u32 ipa_core_clock_rate(struct ipa *ipa);

-/**
- * ipa_power_modem_queue_stop() - Possibly stop the modem netdev TX queue
- * @ipa: IPA pointer
- */
-void ipa_power_modem_queue_stop(struct ipa *ipa);
-
/**
* ipa_power_modem_queue_wake() - Possibly wake the modem netdev TX queue
* @ipa: IPA pointer
--
2.40.1


2024-01-30 19:32:26

by Alex Elder

[permalink] [raw]
Subject: [PATCH net-next 3/7] net: ipa: kill the STARTED IPA power flag

A transmit on the modem netdev can only complete if the IPA hardware
is powered. Currently, if a transmit request arrives when the
hardware was not powered, further transmits are be stopped to allow
power-up to complete. Once power-up completes, transmits are once
again enabled.

Runtime resume can complete at the same time a transmit request is
being handled, and previously there was a race between stopping and
restarting transmits. The STARTED flag was used to ensure the
stop request in the transmit path was skipped if the start request
in the runtime resume path had already occurred.

Now, the queue is *always* stopped in the transmit path, *before*
determining whether power is ACTIVE. If power is found to already
be active (or if the socket buffer is gets dropped), transmit is
re-enabled. Otherwise it will (always) be enabled after runtime
resume completes.

The race between transmit and runtime resume no longer exists, so
there is no longer any need to maintain the STARTED flag.

Signed-off-by: Alex Elder <[email protected]>
---
drivers/net/ipa/ipa_power.c | 47 +++++++++++--------------------------
1 file changed, 14 insertions(+), 33 deletions(-)

diff --git a/drivers/net/ipa/ipa_power.c b/drivers/net/ipa/ipa_power.c
index f1802448ff447..509c9bfa648e7 100644
--- a/drivers/net/ipa/ipa_power.c
+++ b/drivers/net/ipa/ipa_power.c
@@ -39,14 +39,12 @@
* @IPA_POWER_FLAG_RESUMED: Whether resume from suspend has been signaled
* @IPA_POWER_FLAG_SYSTEM: Hardware is system (not runtime) suspended
* @IPA_POWER_FLAG_STOPPED: Modem TX is disabled by ipa_start_xmit()
- * @IPA_POWER_FLAG_STARTED: Modem TX was enabled by ipa_runtime_resume()
* @IPA_POWER_FLAG_COUNT: Number of defined power flags
*/
enum ipa_power_flag {
IPA_POWER_FLAG_RESUMED,
IPA_POWER_FLAG_SYSTEM,
IPA_POWER_FLAG_STOPPED,
- IPA_POWER_FLAG_STARTED,
IPA_POWER_FLAG_COUNT, /* Last; not a flag */
};

@@ -64,7 +62,7 @@ struct ipa_power {
struct device *dev;
struct clk *core;
struct qmp *qmp;
- spinlock_t spinlock; /* used with STOPPED/STARTED power flags */
+ spinlock_t spinlock; /* used with STOPPED power flag */
DECLARE_BITMAP(flags, IPA_POWER_FLAG_COUNT);
u32 interconnect_count;
struct icc_bulk_data interconnect[] __counted_by(interconnect_count);
@@ -242,23 +240,16 @@ void ipa_power_suspend_handler(struct ipa *ipa, enum ipa_irq_id irq_id)
* gets sent (or dropped). If power is not ACTIVE, it will eventually
* be, and transmits stay disabled until after it is.
*
- * Two flags and a spinlock are used when managing this. If the queue
- * is stopped, the STOPPED power flag is set. And if the queue is
- * started, the STARTED flag is set.
+ * A flag and a spinlock are used when managing this. If the queue gets
+ * stopped, the STOPPED power flag is set.
*
- * The first function stops the modem netdev transmit queue, but only if
- * the STARTED flag is *not* set. This previously avoided a race where
- * the TX path stops further transmits after power has become ACTIVE.
- * The STARTED flag is cleared by this function.
+ * The first function stops the modem netdev transmit queue. The second
+ * function starts the transmit queue, but only if the STOPPED flag is
+ * set. This avoids enabling transmits repeatedly immediately after
+ * power has become ACTIVE (not really a big deal). If the STOPPED flag
+ * was set, it is cleared by this function.
*
- * The second function starts the transmit queue, but only if the
- * STOPPED flag is set. This avoids enabling transmits repeatedly
- * immediately after power has become ACTIVE (not really a big deal).
- * If the STOPPED flag was set, it is cleared and the STARTED flag
- * is set by this function.
- *
- * The third function enables transmits again and clears the STARTED
- * flag in case it was set, to return it to initial state.
+ * The third function just enables transmits again.
*/
void ipa_power_modem_queue_stop(struct ipa *ipa)
{
@@ -267,18 +258,14 @@ void ipa_power_modem_queue_stop(struct ipa *ipa)

spin_lock_irqsave(&power->spinlock, flags);

- if (!__test_and_clear_bit(IPA_POWER_FLAG_STARTED, power->flags)) {
- netif_stop_queue(ipa->modem_netdev);
- __set_bit(IPA_POWER_FLAG_STOPPED, power->flags);
- }
+ netif_stop_queue(ipa->modem_netdev);
+ __set_bit(IPA_POWER_FLAG_STOPPED, power->flags);

spin_unlock_irqrestore(&power->spinlock, flags);
}

/* This function starts the modem netdev transmit queue, but only if the
- * STOPPED flag is set. That flag is cleared if it was set. If the queue
- * was restarted, the STARTED flag is set; this allows ipa_start_xmit()
- * to skip stopping the queue in the event of a race.
+ * STOPPED flag is set. That flag is cleared if it was set.
*/
void ipa_power_modem_queue_wake(struct ipa *ipa)
{
@@ -287,22 +274,16 @@ void ipa_power_modem_queue_wake(struct ipa *ipa)

spin_lock_irqsave(&power->spinlock, flags);

- if (__test_and_clear_bit(IPA_POWER_FLAG_STOPPED, power->flags)) {
- __set_bit(IPA_POWER_FLAG_STARTED, power->flags);
+ if (__test_and_clear_bit(IPA_POWER_FLAG_STOPPED, power->flags))
netif_wake_queue(ipa->modem_netdev);
- }

spin_unlock_irqrestore(&power->spinlock, flags);
}

-/* This function is run after power has become ACTIVE. It enables transmits
- * again clears the STARTED flag to indicate the TX queue is operating and
- * can be stopped again if necessary.
- */
+/* This function enables transmits again after power has become ACTIVE. */
void ipa_power_modem_queue_active(struct ipa *ipa)
{
netif_wake_queue(ipa->modem_netdev);
- clear_bit(IPA_POWER_FLAG_STARTED, ipa->power->flags);
}

static int ipa_power_retention_init(struct ipa_power *power)
--
2.40.1


2024-02-02 05:03:41

by patchwork-bot+netdevbpf

[permalink] [raw]
Subject: Re: [PATCH net-next 0/7] net: ipa: simplify TX power handling

Hello:

This series was applied to netdev/net-next.git (main)
by Jakub Kicinski <[email protected]>:

On Tue, 30 Jan 2024 13:22:57 -0600 you wrote:
> In order to deliver a packet to the IPA hardware, we must ensure
> it is powered. We request power by calling pm_runtime_get(), and
> its return value tells us the power state. We can't block in
> ipa_start_xmit(), so if power isn't enabled we prevent further
> transmit attempts by calling netif_stop_queue(). Power will
> eventually become enabled, at which point we call netif_wake_queue()
> to allow the transmit to be retried. When it does, the power should
> be enabled, so the packet delivery can proceed.
>
> [...]

Here is the summary with links:
- [net-next,1/7] net: ipa: stash modem TX and RX endpoints
https://git.kernel.org/netdev/net-next/c/102c28b83ddf
- [net-next,2/7] net: ipa: begin simplifying TX queue stop
https://git.kernel.org/netdev/net-next/c/844ecc4aa78e
- [net-next,3/7] net: ipa: kill the STARTED IPA power flag
https://git.kernel.org/netdev/net-next/c/688de12f080f
- [net-next,4/7] net: ipa: kill the IPA power STOPPED flag
https://git.kernel.org/netdev/net-next/c/86c9a4929258
- [net-next,5/7] net: ipa: kill ipa_power_modem_queue_stop()
https://git.kernel.org/netdev/net-next/c/30cdaea23600
- [net-next,6/7] net: ipa: kill ipa_power_modem_queue_active()
https://git.kernel.org/netdev/net-next/c/2acf5fc8daba
- [net-next,7/7] net: ipa: kill ipa_power_modem_queue_wake()
https://git.kernel.org/netdev/net-next/c/e01bbdc9f851

You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html