2020-03-05 21:28:27 -07:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
|
|
|
|
|
|
|
/* Copyright (c) 2014-2018, The Linux Foundation. All rights reserved.
|
2024-04-16 16:10:18 -07:00
|
|
|
* Copyright (C) 2018-2024 Linaro Ltd.
|
2020-03-05 21:28:27 -07:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/errno.h>
|
2024-04-16 16:10:18 -07:00
|
|
|
#include <linux/etherdevice.h>
|
2020-03-05 21:28:27 -07:00
|
|
|
#include <linux/if_arp.h>
|
2024-04-16 16:10:18 -07:00
|
|
|
#include <linux/if_rmnet.h>
|
2020-03-05 21:28:27 -07:00
|
|
|
#include <linux/netdevice.h>
|
2024-04-16 16:10:18 -07:00
|
|
|
#include <linux/pm_runtime.h>
|
2020-03-05 21:28:27 -07:00
|
|
|
#include <linux/skbuff.h>
|
2022-05-19 08:12:14 -07:00
|
|
|
#include <net/pkt_sched.h>
|
2024-04-16 16:10:18 -07:00
|
|
|
|
2020-07-24 11:11:41 -07:00
|
|
|
#include <linux/remoteproc/qcom_rproc.h>
|
2020-03-05 21:28:27 -07:00
|
|
|
|
|
|
|
#include "ipa.h"
|
|
|
|
#include "ipa_endpoint.h"
|
|
|
|
#include "ipa_mem.h"
|
|
|
|
#include "ipa_modem.h"
|
|
|
|
#include "ipa_smp2p.h"
|
2024-04-16 16:10:18 -07:00
|
|
|
#include "ipa_table.h"
|
2021-07-26 13:11:36 -07:00
|
|
|
#include "ipa_uc.h"
|
2020-03-05 21:28:27 -07:00
|
|
|
|
|
|
|
#define IPA_NETDEV_NAME "rmnet_ipa%d"
|
|
|
|
#define IPA_NETDEV_TAILROOM 0 /* for padding by mux layer */
|
|
|
|
#define IPA_NETDEV_TIMEOUT 10 /* seconds */
|
|
|
|
|
|
|
|
enum ipa_modem_state {
|
|
|
|
IPA_MODEM_STATE_STOPPED = 0,
|
|
|
|
IPA_MODEM_STATE_STARTING,
|
|
|
|
IPA_MODEM_STATE_RUNNING,
|
|
|
|
IPA_MODEM_STATE_STOPPING,
|
|
|
|
};
|
|
|
|
|
2021-08-12 12:50:32 -07:00
|
|
|
/**
|
|
|
|
* struct ipa_priv - IPA network device private data
|
|
|
|
* @ipa: IPA pointer
|
2024-01-30 12:22:58 -07:00
|
|
|
* @tx: Transmit endpoint pointer
|
|
|
|
* @rx: Receive endpoint pointer
|
2021-08-12 12:50:32 -07:00
|
|
|
* @work: Work structure used to wake the modem netdev TX queue
|
|
|
|
*/
|
2020-03-05 21:28:27 -07:00
|
|
|
struct ipa_priv {
|
|
|
|
struct ipa *ipa;
|
2024-01-30 12:22:58 -07:00
|
|
|
struct ipa_endpoint *tx;
|
|
|
|
struct ipa_endpoint *rx;
|
2021-08-12 12:50:32 -07:00
|
|
|
struct work_struct work;
|
2020-03-05 21:28:27 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
/** ipa_open() - Opens the modem network interface */
|
|
|
|
static int ipa_open(struct net_device *netdev)
|
|
|
|
{
|
|
|
|
struct ipa_priv *priv = netdev_priv(netdev);
|
|
|
|
struct ipa *ipa = priv->ipa;
|
2021-08-19 15:19:26 -07:00
|
|
|
struct device *dev;
|
2020-03-05 21:28:27 -07:00
|
|
|
int ret;
|
|
|
|
|
2024-03-01 10:02:42 -07:00
|
|
|
dev = ipa->dev;
|
2021-08-19 15:19:26 -07:00
|
|
|
ret = pm_runtime_get_sync(dev);
|
|
|
|
if (ret < 0)
|
|
|
|
goto err_power_put;
|
2021-07-27 14:19:32 -07:00
|
|
|
|
2024-01-30 12:22:58 -07:00
|
|
|
ret = ipa_endpoint_enable_one(priv->tx);
|
2020-03-05 21:28:27 -07:00
|
|
|
if (ret)
|
2021-08-19 15:19:26 -07:00
|
|
|
goto err_power_put;
|
2021-07-27 14:19:32 -07:00
|
|
|
|
2024-01-30 12:22:58 -07:00
|
|
|
ret = ipa_endpoint_enable_one(priv->rx);
|
2020-03-05 21:28:27 -07:00
|
|
|
if (ret)
|
|
|
|
goto err_disable_tx;
|
|
|
|
|
|
|
|
netif_start_queue(netdev);
|
|
|
|
|
2021-08-20 09:01:27 -07:00
|
|
|
pm_runtime_mark_last_busy(dev);
|
|
|
|
(void)pm_runtime_put_autosuspend(dev);
|
2021-08-12 12:50:35 -07:00
|
|
|
|
2020-03-05 21:28:27 -07:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
err_disable_tx:
|
2024-01-30 12:22:58 -07:00
|
|
|
ipa_endpoint_disable_one(priv->tx);
|
2021-08-19 15:19:26 -07:00
|
|
|
err_power_put:
|
2021-08-20 09:01:27 -07:00
|
|
|
pm_runtime_put_noidle(dev);
|
2020-03-05 21:28:27 -07:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** ipa_stop() - Stops the modem network interface. */
|
|
|
|
static int ipa_stop(struct net_device *netdev)
|
|
|
|
{
|
|
|
|
struct ipa_priv *priv = netdev_priv(netdev);
|
|
|
|
struct ipa *ipa = priv->ipa;
|
2021-08-19 15:19:26 -07:00
|
|
|
struct device *dev;
|
2021-08-12 12:50:35 -07:00
|
|
|
int ret;
|
|
|
|
|
2024-03-01 10:02:42 -07:00
|
|
|
dev = ipa->dev;
|
2021-08-19 15:19:26 -07:00
|
|
|
ret = pm_runtime_get_sync(dev);
|
|
|
|
if (ret < 0)
|
|
|
|
goto out_power_put;
|
2020-03-05 21:28:27 -07:00
|
|
|
|
|
|
|
netif_stop_queue(netdev);
|
|
|
|
|
2024-01-30 12:22:58 -07:00
|
|
|
ipa_endpoint_disable_one(priv->rx);
|
|
|
|
ipa_endpoint_disable_one(priv->tx);
|
2021-08-19 15:19:26 -07:00
|
|
|
out_power_put:
|
2021-08-20 09:01:27 -07:00
|
|
|
pm_runtime_mark_last_busy(dev);
|
|
|
|
(void)pm_runtime_put_autosuspend(dev);
|
2021-07-27 14:19:32 -07:00
|
|
|
|
2020-03-05 21:28:27 -07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2024-01-30 12:22:59 -07:00
|
|
|
/** ipa_start_xmit() - Transmit an skb
|
|
|
|
* @skb: Socket buffer to be transmitted
|
|
|
|
* @netdev: Network device
|
2020-03-05 21:28:27 -07:00
|
|
|
*
|
2024-01-30 12:22:59 -07:00
|
|
|
* 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.
|
2020-03-05 21:28:27 -07:00
|
|
|
*/
|
2021-08-12 12:50:35 -07:00
|
|
|
static netdev_tx_t
|
|
|
|
ipa_start_xmit(struct sk_buff *skb, struct net_device *netdev)
|
2020-03-05 21:28:27 -07:00
|
|
|
{
|
|
|
|
struct net_device_stats *stats = &netdev->stats;
|
|
|
|
struct ipa_priv *priv = netdev_priv(netdev);
|
|
|
|
struct ipa_endpoint *endpoint;
|
|
|
|
struct ipa *ipa = priv->ipa;
|
|
|
|
u32 skb_len = skb->len;
|
2021-08-12 12:50:33 -07:00
|
|
|
struct device *dev;
|
2020-03-05 21:28:27 -07:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (!skb_len)
|
|
|
|
goto err_drop_skb;
|
|
|
|
|
|
|
|
endpoint = ipa->name_map[IPA_ENDPOINT_AP_MODEM_TX];
|
2022-05-19 08:12:17 -07:00
|
|
|
if (endpoint->config.qmap && skb->protocol != htons(ETH_P_MAP))
|
2020-03-05 21:28:27 -07:00
|
|
|
goto err_drop_skb;
|
|
|
|
|
2024-01-30 12:22:59 -07:00
|
|
|
/* 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.
|
|
|
|
*/
|
2024-01-30 12:23:02 -07:00
|
|
|
netif_stop_queue(netdev);
|
2024-01-30 12:22:59 -07:00
|
|
|
|
2024-03-01 10:02:42 -07:00
|
|
|
dev = ipa->dev;
|
2021-08-12 12:50:33 -07:00
|
|
|
ret = pm_runtime_get(dev);
|
|
|
|
if (ret < 1) {
|
|
|
|
/* If a resume won't happen, just drop the packet */
|
|
|
|
if (ret < 0 && ret != -EINPROGRESS) {
|
2024-01-30 12:23:03 -07:00
|
|
|
netif_wake_queue(netdev);
|
2021-08-12 12:50:33 -07:00
|
|
|
pm_runtime_put_noidle(dev);
|
|
|
|
goto err_drop_skb;
|
|
|
|
}
|
|
|
|
|
2021-08-20 09:01:27 -07:00
|
|
|
pm_runtime_put_noidle(dev);
|
2021-08-12 12:50:33 -07:00
|
|
|
|
|
|
|
return NETDEV_TX_BUSY;
|
|
|
|
}
|
|
|
|
|
2024-01-30 12:23:03 -07:00
|
|
|
netif_wake_queue(netdev);
|
2021-08-19 14:12:28 -07:00
|
|
|
|
2020-03-05 21:28:27 -07:00
|
|
|
ret = ipa_endpoint_skb_tx(endpoint, skb);
|
2021-08-12 12:50:33 -07:00
|
|
|
|
2021-08-20 09:01:27 -07:00
|
|
|
pm_runtime_mark_last_busy(dev);
|
|
|
|
(void)pm_runtime_put_autosuspend(dev);
|
2021-08-12 12:50:33 -07:00
|
|
|
|
2020-03-05 21:28:27 -07:00
|
|
|
if (ret) {
|
|
|
|
if (ret != -E2BIG)
|
|
|
|
return NETDEV_TX_BUSY;
|
|
|
|
goto err_drop_skb;
|
|
|
|
}
|
|
|
|
|
|
|
|
stats->tx_packets++;
|
|
|
|
stats->tx_bytes += skb_len;
|
|
|
|
|
|
|
|
return NETDEV_TX_OK;
|
|
|
|
|
|
|
|
err_drop_skb:
|
|
|
|
dev_kfree_skb_any(skb);
|
|
|
|
stats->tx_dropped++;
|
|
|
|
|
|
|
|
return NETDEV_TX_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ipa_modem_skb_rx(struct net_device *netdev, struct sk_buff *skb)
|
|
|
|
{
|
|
|
|
struct net_device_stats *stats = &netdev->stats;
|
|
|
|
|
|
|
|
if (skb) {
|
|
|
|
skb->dev = netdev;
|
|
|
|
skb->protocol = htons(ETH_P_MAP);
|
|
|
|
stats->rx_packets++;
|
|
|
|
stats->rx_bytes += skb->len;
|
|
|
|
|
|
|
|
(void)netif_receive_skb(skb);
|
|
|
|
} else {
|
|
|
|
stats->rx_dropped++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct net_device_ops ipa_modem_ops = {
|
|
|
|
.ndo_open = ipa_open,
|
|
|
|
.ndo_stop = ipa_stop,
|
|
|
|
.ndo_start_xmit = ipa_start_xmit,
|
|
|
|
};
|
|
|
|
|
|
|
|
/** ipa_modem_netdev_setup() - netdev setup function for the modem */
|
|
|
|
static void ipa_modem_netdev_setup(struct net_device *netdev)
|
|
|
|
{
|
|
|
|
netdev->netdev_ops = &ipa_modem_ops;
|
2022-05-19 08:12:14 -07:00
|
|
|
|
2020-03-05 21:28:27 -07:00
|
|
|
netdev->header_ops = NULL;
|
|
|
|
netdev->type = ARPHRD_RAWIP;
|
|
|
|
netdev->hard_header_len = 0;
|
2022-05-19 08:12:14 -07:00
|
|
|
netdev->min_header_len = ETH_HLEN;
|
|
|
|
netdev->min_mtu = ETH_MIN_MTU;
|
2020-03-05 21:28:27 -07:00
|
|
|
netdev->max_mtu = IPA_MTU;
|
|
|
|
netdev->mtu = netdev->max_mtu;
|
|
|
|
netdev->addr_len = 0;
|
2022-05-19 08:12:14 -07:00
|
|
|
netdev->tx_queue_len = DEFAULT_TX_QUEUE_LEN;
|
2020-03-05 21:28:27 -07:00
|
|
|
netdev->flags &= ~(IFF_BROADCAST | IFF_MULTICAST);
|
2022-05-19 08:12:14 -07:00
|
|
|
netdev->priv_flags |= IFF_TX_SKB_SHARING;
|
|
|
|
eth_broadcast_addr(netdev->broadcast);
|
|
|
|
|
2020-03-05 21:28:27 -07:00
|
|
|
/* The endpoint is configured for QMAP */
|
|
|
|
netdev->needed_headroom = sizeof(struct rmnet_map_header);
|
|
|
|
netdev->needed_tailroom = IPA_NETDEV_TAILROOM;
|
|
|
|
netdev->watchdog_timeo = IPA_NETDEV_TIMEOUT * HZ;
|
|
|
|
netdev->hw_features = NETIF_F_SG;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** ipa_modem_suspend() - suspend callback
|
|
|
|
* @netdev: Network device
|
|
|
|
*
|
|
|
|
* Suspend the modem's endpoints.
|
|
|
|
*/
|
|
|
|
void ipa_modem_suspend(struct net_device *netdev)
|
|
|
|
{
|
2024-01-30 12:22:58 -07:00
|
|
|
struct ipa_priv *priv;
|
2020-03-05 21:28:27 -07:00
|
|
|
|
2021-08-04 08:36:21 -07:00
|
|
|
if (!(netdev->flags & IFF_UP))
|
|
|
|
return;
|
|
|
|
|
2024-01-30 12:22:58 -07:00
|
|
|
priv = netdev_priv(netdev);
|
|
|
|
ipa_endpoint_suspend_one(priv->rx);
|
|
|
|
ipa_endpoint_suspend_one(priv->tx);
|
2020-03-05 21:28:27 -07:00
|
|
|
}
|
|
|
|
|
2021-08-12 12:50:32 -07:00
|
|
|
/**
|
|
|
|
* ipa_modem_wake_queue_work() - enable modem netdev queue
|
|
|
|
* @work: Work structure
|
|
|
|
*
|
|
|
|
* Re-enable transmit on the modem network device. This is called
|
|
|
|
* in (power management) work queue context, scheduled when resuming
|
2021-08-12 12:50:33 -07:00
|
|
|
* the modem. We can't enable the queue directly in ipa_modem_resume()
|
|
|
|
* because transmits restart the instant the queue is awakened; but the
|
|
|
|
* device power state won't be ACTIVE until *after* ipa_modem_resume()
|
|
|
|
* returns.
|
2021-08-12 12:50:32 -07:00
|
|
|
*/
|
|
|
|
static void ipa_modem_wake_queue_work(struct work_struct *work)
|
|
|
|
{
|
|
|
|
struct ipa_priv *priv = container_of(work, struct ipa_priv, work);
|
|
|
|
|
2024-01-30 12:23:04 -07:00
|
|
|
netif_wake_queue(priv->tx->netdev);
|
2021-08-12 12:50:32 -07:00
|
|
|
}
|
|
|
|
|
2020-03-05 21:28:27 -07:00
|
|
|
/** ipa_modem_resume() - resume callback for runtime_pm
|
|
|
|
* @dev: pointer to device
|
|
|
|
*
|
|
|
|
* Resume the modem's endpoints.
|
|
|
|
*/
|
|
|
|
void ipa_modem_resume(struct net_device *netdev)
|
|
|
|
{
|
2024-01-30 12:22:58 -07:00
|
|
|
struct ipa_priv *priv;
|
2020-03-05 21:28:27 -07:00
|
|
|
|
2021-08-04 08:36:21 -07:00
|
|
|
if (!(netdev->flags & IFF_UP))
|
|
|
|
return;
|
|
|
|
|
2024-01-30 12:22:58 -07:00
|
|
|
priv = netdev_priv(netdev);
|
|
|
|
ipa_endpoint_resume_one(priv->tx);
|
|
|
|
ipa_endpoint_resume_one(priv->rx);
|
2020-03-05 21:28:27 -07:00
|
|
|
|
2021-08-12 12:50:32 -07:00
|
|
|
/* Arrange for the TX queue to be restarted */
|
|
|
|
(void)queue_pm_work(&priv->work);
|
2020-03-05 21:28:27 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
int ipa_modem_start(struct ipa *ipa)
|
|
|
|
{
|
|
|
|
enum ipa_modem_state state;
|
|
|
|
struct net_device *netdev;
|
|
|
|
struct ipa_priv *priv;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
/* Only attempt to start the modem if it's stopped */
|
|
|
|
state = atomic_cmpxchg(&ipa->modem_state, IPA_MODEM_STATE_STOPPED,
|
|
|
|
IPA_MODEM_STATE_STARTING);
|
|
|
|
|
|
|
|
/* Silently ignore attempts when running, or when changing state */
|
|
|
|
if (state != IPA_MODEM_STATE_STOPPED)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
netdev = alloc_netdev(sizeof(struct ipa_priv), IPA_NETDEV_NAME,
|
|
|
|
NET_NAME_UNKNOWN, ipa_modem_netdev_setup);
|
|
|
|
if (!netdev) {
|
|
|
|
ret = -ENOMEM;
|
|
|
|
goto out_set_state;
|
|
|
|
}
|
|
|
|
|
2024-03-01 10:02:42 -07:00
|
|
|
SET_NETDEV_DEV(netdev, ipa->dev);
|
2020-03-05 21:28:27 -07:00
|
|
|
priv = netdev_priv(netdev);
|
|
|
|
priv->ipa = ipa;
|
2024-01-30 12:22:58 -07:00
|
|
|
priv->tx = ipa->name_map[IPA_ENDPOINT_AP_MODEM_TX];
|
|
|
|
priv->rx = ipa->name_map[IPA_ENDPOINT_AP_MODEM_RX];
|
2021-08-12 12:50:32 -07:00
|
|
|
INIT_WORK(&priv->work, ipa_modem_wake_queue_work);
|
2024-01-30 12:22:58 -07:00
|
|
|
|
|
|
|
priv->tx->netdev = netdev;
|
|
|
|
priv->rx->netdev = netdev;
|
|
|
|
|
2021-08-04 08:36:22 -07:00
|
|
|
ipa->modem_netdev = netdev;
|
2020-03-05 21:28:27 -07:00
|
|
|
|
|
|
|
ret = register_netdev(netdev);
|
2021-08-04 08:36:22 -07:00
|
|
|
if (ret) {
|
|
|
|
ipa->modem_netdev = NULL;
|
2024-01-30 12:22:58 -07:00
|
|
|
priv->rx->netdev = NULL;
|
|
|
|
priv->tx->netdev = NULL;
|
|
|
|
|
2021-04-09 11:07:18 -07:00
|
|
|
free_netdev(netdev);
|
|
|
|
}
|
2020-03-05 21:28:27 -07:00
|
|
|
|
|
|
|
out_set_state:
|
|
|
|
if (ret)
|
|
|
|
atomic_set(&ipa->modem_state, IPA_MODEM_STATE_STOPPED);
|
|
|
|
else
|
|
|
|
atomic_set(&ipa->modem_state, IPA_MODEM_STATE_RUNNING);
|
|
|
|
smp_mb__after_atomic();
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
int ipa_modem_stop(struct ipa *ipa)
|
|
|
|
{
|
|
|
|
struct net_device *netdev = ipa->modem_netdev;
|
|
|
|
enum ipa_modem_state state;
|
|
|
|
|
|
|
|
/* Only attempt to stop the modem if it's running */
|
|
|
|
state = atomic_cmpxchg(&ipa->modem_state, IPA_MODEM_STATE_RUNNING,
|
|
|
|
IPA_MODEM_STATE_STOPPING);
|
|
|
|
|
|
|
|
/* Silently ignore attempts when already stopped */
|
|
|
|
if (state == IPA_MODEM_STATE_STOPPED)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* If we're somewhere between stopped and starting, we're busy */
|
|
|
|
if (state != IPA_MODEM_STATE_RUNNING)
|
|
|
|
return -EBUSY;
|
|
|
|
|
2021-08-04 08:36:21 -07:00
|
|
|
/* Clean up the netdev and endpoints if it was started */
|
2020-03-05 21:28:27 -07:00
|
|
|
if (netdev) {
|
2021-08-12 12:50:32 -07:00
|
|
|
struct ipa_priv *priv = netdev_priv(netdev);
|
|
|
|
|
|
|
|
cancel_work_sync(&priv->work);
|
2021-08-04 08:36:21 -07:00
|
|
|
/* If it was opened, stop it first */
|
|
|
|
if (netdev->flags & IFF_UP)
|
|
|
|
(void)ipa_stop(netdev);
|
2021-08-04 08:36:22 -07:00
|
|
|
unregister_netdev(netdev);
|
2024-01-30 12:22:58 -07:00
|
|
|
|
2021-08-04 08:36:22 -07:00
|
|
|
ipa->modem_netdev = NULL;
|
2024-01-30 12:22:58 -07:00
|
|
|
priv->rx->netdev = NULL;
|
|
|
|
priv->tx->netdev = NULL;
|
|
|
|
|
2020-03-05 21:28:27 -07:00
|
|
|
free_netdev(netdev);
|
|
|
|
}
|
|
|
|
|
2021-04-09 11:07:19 -07:00
|
|
|
atomic_set(&ipa->modem_state, IPA_MODEM_STATE_STOPPED);
|
2020-03-05 21:28:27 -07:00
|
|
|
smp_mb__after_atomic();
|
|
|
|
|
2021-04-09 11:07:19 -07:00
|
|
|
return 0;
|
2020-03-05 21:28:27 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Treat a "clean" modem stop the same as a crash */
|
|
|
|
static void ipa_modem_crashed(struct ipa *ipa)
|
|
|
|
{
|
2024-03-01 10:02:42 -07:00
|
|
|
struct device *dev = ipa->dev;
|
2020-03-05 21:28:27 -07:00
|
|
|
int ret;
|
|
|
|
|
net: ipa: separate disabling setup from modem stop
The IPA setup_complete flag is set at the end of ipa_setup(), when
the setup phase of initialization has completed successfully. This
occurs as part of driver probe processing, or (if "modem-init" is
specified in the DTS file) it is triggered by the "ipa-setup-ready"
SMP2P interrupt generated by the modem.
In the latter case, it's possible for driver shutdown (or remove) to
begin while setup processing is underway, and this can't be allowed.
The problem is that the setup_complete flag is not adequate to signal
that setup is underway.
If setup_complete is set, it will never be un-set, so that case is
not a problem. But if setup_complete is false, there's a chance
setup is underway.
Because setup is triggered by an interrupt on a "modem-init" system,
there is a simple way to ensure the value of setup_complete is safe
to read. The threaded handler--if it is executing--will complete as
part of a request to disable the "ipa-modem-ready" interrupt. This
means that ipa_setup() (which is called from the handler) will run
to completion if it was underway, or will never be called otherwise.
The request to disable the "ipa-setup-ready" interrupt is currently
made within ipa_modem_stop(). Instead, disable the interrupt
outside that function in the two places it's called. In the case of
ipa_remove(), this ensures the setup_complete flag is safe to read
before we read it.
Rename ipa_smp2p_disable() to be ipa_smp2p_irq_disable_setup(), to be
more specific about its effect.
Fixes: 530f9216a953 ("soc: qcom: ipa: AP/modem communications")
Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
2021-11-22 17:15:55 -07:00
|
|
|
/* Prevent the modem from triggering a call to ipa_setup() */
|
|
|
|
ipa_smp2p_irq_disable_setup(ipa);
|
|
|
|
|
2021-08-19 15:19:26 -07:00
|
|
|
ret = pm_runtime_get_sync(dev);
|
|
|
|
if (ret < 0) {
|
|
|
|
dev_err(dev, "error %d getting power to handle crash\n", ret);
|
|
|
|
goto out_power_put;
|
|
|
|
}
|
2021-07-27 14:19:31 -07:00
|
|
|
|
2020-03-05 21:28:27 -07:00
|
|
|
ipa_endpoint_modem_pause_all(ipa, true);
|
|
|
|
|
|
|
|
ipa_endpoint_modem_hol_block_clear_all(ipa);
|
|
|
|
|
|
|
|
ipa_table_reset(ipa, true);
|
|
|
|
|
|
|
|
ret = ipa_table_hash_flush(ipa);
|
|
|
|
if (ret)
|
2020-03-11 02:16:13 -07:00
|
|
|
dev_err(dev, "error %d flushing hash caches\n", ret);
|
2020-03-05 21:28:27 -07:00
|
|
|
|
|
|
|
ret = ipa_endpoint_modem_exception_reset_all(ipa);
|
|
|
|
if (ret)
|
2020-04-11 00:30:04 -07:00
|
|
|
dev_err(dev, "error %d resetting exception endpoint\n", ret);
|
2020-03-05 21:28:27 -07:00
|
|
|
|
|
|
|
ipa_endpoint_modem_pause_all(ipa, false);
|
|
|
|
|
|
|
|
ret = ipa_modem_stop(ipa);
|
|
|
|
if (ret)
|
2020-04-11 00:30:04 -07:00
|
|
|
dev_err(dev, "error %d stopping modem\n", ret);
|
2020-03-05 21:28:27 -07:00
|
|
|
|
|
|
|
/* Now prepare for the next modem boot */
|
|
|
|
ret = ipa_mem_zero_modem(ipa);
|
|
|
|
if (ret)
|
|
|
|
dev_err(dev, "error %d zeroing modem memory regions\n", ret);
|
2021-07-27 14:19:31 -07:00
|
|
|
|
2021-08-19 15:19:26 -07:00
|
|
|
out_power_put:
|
2021-08-20 09:01:27 -07:00
|
|
|
pm_runtime_mark_last_busy(dev);
|
|
|
|
(void)pm_runtime_put_autosuspend(dev);
|
2020-03-05 21:28:27 -07:00
|
|
|
}
|
|
|
|
|
2020-07-24 11:11:41 -07:00
|
|
|
static int ipa_modem_notify(struct notifier_block *nb, unsigned long action,
|
|
|
|
void *data)
|
2020-03-05 21:28:27 -07:00
|
|
|
{
|
2020-07-24 11:11:41 -07:00
|
|
|
struct ipa *ipa = container_of(nb, struct ipa, nb);
|
|
|
|
struct qcom_ssr_notify_data *notify_data = data;
|
2024-03-01 10:02:42 -07:00
|
|
|
struct device *dev = ipa->dev;
|
2020-03-05 21:28:27 -07:00
|
|
|
|
2020-07-24 11:11:41 -07:00
|
|
|
switch (action) {
|
|
|
|
case QCOM_SSR_BEFORE_POWERUP:
|
2020-03-05 21:28:27 -07:00
|
|
|
dev_info(dev, "received modem starting event\n");
|
2021-08-20 09:01:28 -07:00
|
|
|
ipa_uc_power(ipa);
|
2020-03-05 21:28:27 -07:00
|
|
|
ipa_smp2p_notify_reset(ipa);
|
|
|
|
break;
|
|
|
|
|
2020-07-24 11:11:41 -07:00
|
|
|
case QCOM_SSR_AFTER_POWERUP:
|
2020-03-05 21:28:27 -07:00
|
|
|
dev_info(dev, "received modem running event\n");
|
|
|
|
break;
|
|
|
|
|
2020-07-24 11:11:41 -07:00
|
|
|
case QCOM_SSR_BEFORE_SHUTDOWN:
|
2020-03-05 21:28:27 -07:00
|
|
|
dev_info(dev, "received modem %s event\n",
|
2020-07-24 11:11:41 -07:00
|
|
|
notify_data->crashed ? "crashed" : "stopping");
|
2020-03-05 21:28:27 -07:00
|
|
|
if (ipa->setup_complete)
|
|
|
|
ipa_modem_crashed(ipa);
|
|
|
|
break;
|
|
|
|
|
2020-07-24 11:11:41 -07:00
|
|
|
case QCOM_SSR_AFTER_SHUTDOWN:
|
2020-03-05 21:28:27 -07:00
|
|
|
dev_info(dev, "received modem offline event\n");
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2020-07-24 11:11:41 -07:00
|
|
|
dev_err(dev, "received unrecognized event %lu\n", action);
|
2020-03-05 21:28:27 -07:00
|
|
|
break;
|
|
|
|
}
|
2020-07-24 11:11:41 -07:00
|
|
|
|
|
|
|
return NOTIFY_OK;
|
2020-03-05 21:28:27 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
int ipa_modem_config(struct ipa *ipa)
|
|
|
|
{
|
2020-07-24 11:11:41 -07:00
|
|
|
void *notifier;
|
|
|
|
|
|
|
|
ipa->nb.notifier_call = ipa_modem_notify;
|
|
|
|
|
|
|
|
notifier = qcom_register_ssr_notifier("mpss", &ipa->nb);
|
|
|
|
if (IS_ERR(notifier))
|
|
|
|
return PTR_ERR(notifier);
|
|
|
|
|
|
|
|
ipa->notifier = notifier;
|
|
|
|
|
|
|
|
return 0;
|
2020-03-05 21:28:27 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void ipa_modem_deconfig(struct ipa *ipa)
|
|
|
|
{
|
2024-03-01 10:02:42 -07:00
|
|
|
struct device *dev = ipa->dev;
|
2020-07-24 11:11:41 -07:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = qcom_unregister_ssr_notifier(ipa->notifier, &ipa->nb);
|
|
|
|
if (ret)
|
|
|
|
dev_err(dev, "error %d unregistering notifier", ret);
|
|
|
|
|
|
|
|
ipa->notifier = NULL;
|
|
|
|
memset(&ipa->nb, 0, sizeof(ipa->nb));
|
2020-03-05 21:28:27 -07:00
|
|
|
}
|