Skip to content

Commit 6b51f80

Browse files
Alex Elderdavem330
authored andcommitted
net: ipa: ensure hardware has power in ipa_start_xmit()
We need to ensure the hardware is powered when we transmit a packet. But if it's not, we can't block to wait for it. So asynchronously request power in ipa_start_xmit(), and only proceed if the return value indicates the power state is active. If the hardware is not active, a runtime resume request will have been initiated. In that case, stop the network stack from further transmit attempts until the resume completes. Return NETDEV_TX_BUSY, to retry sending the packet once the queue is restarted. If the power request returns an error (other than -EINPROGRESS, which just means a resume requested elsewhere isn't complete), just drop the packet. Signed-off-by: Alex Elder <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent a96e73f commit 6b51f80

File tree

1 file changed

+29
-1
lines changed

1 file changed

+29
-1
lines changed

drivers/net/ipa/ipa_modem.c

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ static int ipa_start_xmit(struct sk_buff *skb, struct net_device *netdev)
106106
struct ipa_endpoint *endpoint;
107107
struct ipa *ipa = priv->ipa;
108108
u32 skb_len = skb->len;
109+
struct device *dev;
109110
int ret;
110111

111112
if (!skb_len)
@@ -115,7 +116,31 @@ static int ipa_start_xmit(struct sk_buff *skb, struct net_device *netdev)
115116
if (endpoint->data->qmap && skb->protocol != htons(ETH_P_MAP))
116117
goto err_drop_skb;
117118

119+
/* The hardware must be powered for us to transmit */
120+
dev = &ipa->pdev->dev;
121+
ret = pm_runtime_get(dev);
122+
if (ret < 1) {
123+
/* If a resume won't happen, just drop the packet */
124+
if (ret < 0 && ret != -EINPROGRESS) {
125+
pm_runtime_put_noidle(dev);
126+
goto err_drop_skb;
127+
}
128+
129+
/* No power (yet). Stop the network stack from transmitting
130+
* until we're resumed; ipa_modem_resume() arranges for the
131+
* TX queue to be started again.
132+
*/
133+
netif_stop_queue(netdev);
134+
135+
(void)pm_runtime_put(dev);
136+
137+
return NETDEV_TX_BUSY;
138+
}
139+
118140
ret = ipa_endpoint_skb_tx(endpoint, skb);
141+
142+
(void)pm_runtime_put(dev);
143+
119144
if (ret) {
120145
if (ret != -E2BIG)
121146
return NETDEV_TX_BUSY;
@@ -201,7 +226,10 @@ void ipa_modem_suspend(struct net_device *netdev)
201226
*
202227
* Re-enable transmit on the modem network device. This is called
203228
* in (power management) work queue context, scheduled when resuming
204-
* the modem.
229+
* the modem. We can't enable the queue directly in ipa_modem_resume()
230+
* because transmits restart the instant the queue is awakened; but the
231+
* device power state won't be ACTIVE until *after* ipa_modem_resume()
232+
* returns.
205233
*/
206234
static void ipa_modem_wake_queue_work(struct work_struct *work)
207235
{

0 commit comments

Comments
 (0)