xref: /linux/drivers/net/wwan/iosm/iosm_ipc_wwan.c (revision 0c9441c430104dcf2cd066aae74dbeefb9f9e1bf)
12a54f2c7SM Chetan Kumar // SPDX-License-Identifier: GPL-2.0-only
22a54f2c7SM Chetan Kumar /*
32a54f2c7SM Chetan Kumar  * Copyright (C) 2020-21 Intel Corporation.
42a54f2c7SM Chetan Kumar  */
52a54f2c7SM Chetan Kumar 
62a54f2c7SM Chetan Kumar #include <linux/etherdevice.h>
72a54f2c7SM Chetan Kumar #include <linux/if_arp.h>
82a54f2c7SM Chetan Kumar #include <linux/if_link.h>
92a54f2c7SM Chetan Kumar #include <linux/rtnetlink.h>
102a54f2c7SM Chetan Kumar #include <linux/wwan.h>
115d710dc3SM Chetan Kumar #include <net/pkt_sched.h>
122a54f2c7SM Chetan Kumar 
132a54f2c7SM Chetan Kumar #include "iosm_ipc_chnl_cfg.h"
142a54f2c7SM Chetan Kumar #include "iosm_ipc_imem_ops.h"
152a54f2c7SM Chetan Kumar #include "iosm_ipc_wwan.h"
162a54f2c7SM Chetan Kumar 
172a54f2c7SM Chetan Kumar #define IOSM_IP_TYPE_MASK 0xF0
182a54f2c7SM Chetan Kumar #define IOSM_IP_TYPE_IPV4 0x40
192a54f2c7SM Chetan Kumar #define IOSM_IP_TYPE_IPV6 0x60
202a54f2c7SM Chetan Kumar 
212a54f2c7SM Chetan Kumar #define IOSM_IF_ID_PAYLOAD 2
222a54f2c7SM Chetan Kumar 
232a54f2c7SM Chetan Kumar /**
2469940924SSergey Ryazanov  * struct iosm_netdev_priv - netdev WWAN driver specific private data
252a54f2c7SM Chetan Kumar  * @ipc_wwan:	Pointer to iosm_wwan struct
262a54f2c7SM Chetan Kumar  * @netdev:	Pointer to network interface device structure
272a54f2c7SM Chetan Kumar  * @if_id:	Interface id for device.
282a54f2c7SM Chetan Kumar  * @ch_id:	IPC channel number for which interface device is created.
292a54f2c7SM Chetan Kumar  */
302a54f2c7SM Chetan Kumar struct iosm_netdev_priv {
312a54f2c7SM Chetan Kumar 	struct iosm_wwan *ipc_wwan;
322a54f2c7SM Chetan Kumar 	struct net_device *netdev;
332a54f2c7SM Chetan Kumar 	int if_id;
342a54f2c7SM Chetan Kumar 	int ch_id;
352a54f2c7SM Chetan Kumar };
362a54f2c7SM Chetan Kumar 
372a54f2c7SM Chetan Kumar /**
382a54f2c7SM Chetan Kumar  * struct iosm_wwan - This structure contains information about WWAN root device
392a54f2c7SM Chetan Kumar  *		      and interface to the IPC layer.
402a54f2c7SM Chetan Kumar  * @ipc_imem:		Pointer to imem data-struct
412a54f2c7SM Chetan Kumar  * @sub_netlist:	List of active netdevs
422a54f2c7SM Chetan Kumar  * @dev:		Pointer device structure
432a54f2c7SM Chetan Kumar  * @if_mutex:		Mutex used for add and remove interface id
442a54f2c7SM Chetan Kumar  */
452a54f2c7SM Chetan Kumar struct iosm_wwan {
462a54f2c7SM Chetan Kumar 	struct iosm_imem *ipc_imem;
472a54f2c7SM Chetan Kumar 	struct iosm_netdev_priv __rcu *sub_netlist[IP_MUX_SESSION_END + 1];
482a54f2c7SM Chetan Kumar 	struct device *dev;
492a54f2c7SM Chetan Kumar 	struct mutex if_mutex; /* Mutex used for add and remove interface id */
502a54f2c7SM Chetan Kumar };
512a54f2c7SM Chetan Kumar 
522a54f2c7SM Chetan Kumar /* Bring-up the wwan net link */
532a54f2c7SM Chetan Kumar static int ipc_wwan_link_open(struct net_device *netdev)
542a54f2c7SM Chetan Kumar {
5569940924SSergey Ryazanov 	struct iosm_netdev_priv *priv = wwan_netdev_drvpriv(netdev);
562a54f2c7SM Chetan Kumar 	struct iosm_wwan *ipc_wwan = priv->ipc_wwan;
572a54f2c7SM Chetan Kumar 	int if_id = priv->if_id;
582a54f2c7SM Chetan Kumar 	int ret;
592a54f2c7SM Chetan Kumar 
602a54f2c7SM Chetan Kumar 	if (if_id < IP_MUX_SESSION_START ||
612a54f2c7SM Chetan Kumar 	    if_id >= ARRAY_SIZE(ipc_wwan->sub_netlist))
622a54f2c7SM Chetan Kumar 		return -EINVAL;
632a54f2c7SM Chetan Kumar 
642a54f2c7SM Chetan Kumar 	mutex_lock(&ipc_wwan->if_mutex);
652a54f2c7SM Chetan Kumar 
662a54f2c7SM Chetan Kumar 	/* get channel id */
672a54f2c7SM Chetan Kumar 	priv->ch_id = ipc_imem_sys_wwan_open(ipc_wwan->ipc_imem, if_id);
682a54f2c7SM Chetan Kumar 
692a54f2c7SM Chetan Kumar 	if (priv->ch_id < 0) {
702a54f2c7SM Chetan Kumar 		dev_err(ipc_wwan->dev,
712a54f2c7SM Chetan Kumar 			"cannot connect wwan0 & id %d to the IPC mem layer",
722a54f2c7SM Chetan Kumar 			if_id);
732a54f2c7SM Chetan Kumar 		ret = -ENODEV;
742a54f2c7SM Chetan Kumar 		goto out;
752a54f2c7SM Chetan Kumar 	}
762a54f2c7SM Chetan Kumar 
772a54f2c7SM Chetan Kumar 	/* enable tx path, DL data may follow */
782a54f2c7SM Chetan Kumar 	netif_start_queue(netdev);
792a54f2c7SM Chetan Kumar 
802a54f2c7SM Chetan Kumar 	dev_dbg(ipc_wwan->dev, "Channel id %d allocated to if_id %d",
812a54f2c7SM Chetan Kumar 		priv->ch_id, priv->if_id);
822a54f2c7SM Chetan Kumar 
832a54f2c7SM Chetan Kumar 	ret = 0;
842a54f2c7SM Chetan Kumar out:
852a54f2c7SM Chetan Kumar 	mutex_unlock(&ipc_wwan->if_mutex);
862a54f2c7SM Chetan Kumar 	return ret;
872a54f2c7SM Chetan Kumar }
882a54f2c7SM Chetan Kumar 
892a54f2c7SM Chetan Kumar /* Bring-down the wwan net link */
902a54f2c7SM Chetan Kumar static int ipc_wwan_link_stop(struct net_device *netdev)
912a54f2c7SM Chetan Kumar {
9269940924SSergey Ryazanov 	struct iosm_netdev_priv *priv = wwan_netdev_drvpriv(netdev);
932a54f2c7SM Chetan Kumar 
942a54f2c7SM Chetan Kumar 	netif_stop_queue(netdev);
952a54f2c7SM Chetan Kumar 
962a54f2c7SM Chetan Kumar 	mutex_lock(&priv->ipc_wwan->if_mutex);
972a54f2c7SM Chetan Kumar 	ipc_imem_sys_wwan_close(priv->ipc_wwan->ipc_imem, priv->if_id,
982a54f2c7SM Chetan Kumar 				priv->ch_id);
992a54f2c7SM Chetan Kumar 	priv->ch_id = -1;
1002a54f2c7SM Chetan Kumar 	mutex_unlock(&priv->ipc_wwan->if_mutex);
1012a54f2c7SM Chetan Kumar 
1022a54f2c7SM Chetan Kumar 	return 0;
1032a54f2c7SM Chetan Kumar }
1042a54f2c7SM Chetan Kumar 
1052a54f2c7SM Chetan Kumar /* Transmit a packet */
106*0c9441c4SNathan Huckleberry static netdev_tx_t ipc_wwan_link_transmit(struct sk_buff *skb,
1072a54f2c7SM Chetan Kumar 					  struct net_device *netdev)
1082a54f2c7SM Chetan Kumar {
10969940924SSergey Ryazanov 	struct iosm_netdev_priv *priv = wwan_netdev_drvpriv(netdev);
1102a54f2c7SM Chetan Kumar 	struct iosm_wwan *ipc_wwan = priv->ipc_wwan;
111c302e3a1SM Chetan Kumar 	unsigned int len = skb->len;
1122a54f2c7SM Chetan Kumar 	int if_id = priv->if_id;
1132a54f2c7SM Chetan Kumar 	int ret;
1142a54f2c7SM Chetan Kumar 
1152a54f2c7SM Chetan Kumar 	/* Interface IDs from 1 to 8 are for IP data
1162a54f2c7SM Chetan Kumar 	 * & from 257 to 261 are for non-IP data
1172a54f2c7SM Chetan Kumar 	 */
1182a54f2c7SM Chetan Kumar 	if (if_id < IP_MUX_SESSION_START ||
1192a54f2c7SM Chetan Kumar 	    if_id >= ARRAY_SIZE(ipc_wwan->sub_netlist))
1202a54f2c7SM Chetan Kumar 		return -EINVAL;
1212a54f2c7SM Chetan Kumar 
1222a54f2c7SM Chetan Kumar 	/* Send the SKB to device for transmission */
1232a54f2c7SM Chetan Kumar 	ret = ipc_imem_sys_wwan_transmit(ipc_wwan->ipc_imem,
1242a54f2c7SM Chetan Kumar 					 if_id, priv->ch_id, skb);
1252a54f2c7SM Chetan Kumar 
1262a54f2c7SM Chetan Kumar 	/* Return code of zero is success */
1272a54f2c7SM Chetan Kumar 	if (ret == 0) {
128c302e3a1SM Chetan Kumar 		netdev->stats.tx_packets++;
129c302e3a1SM Chetan Kumar 		netdev->stats.tx_bytes += len;
1302a54f2c7SM Chetan Kumar 		ret = NETDEV_TX_OK;
1312a54f2c7SM Chetan Kumar 	} else if (ret == -EBUSY) {
1322a54f2c7SM Chetan Kumar 		ret = NETDEV_TX_BUSY;
1332a54f2c7SM Chetan Kumar 		dev_err(ipc_wwan->dev, "unable to push packets");
1342a54f2c7SM Chetan Kumar 	} else {
1352a54f2c7SM Chetan Kumar 		goto exit;
1362a54f2c7SM Chetan Kumar 	}
1372a54f2c7SM Chetan Kumar 
1382a54f2c7SM Chetan Kumar 	return ret;
1392a54f2c7SM Chetan Kumar 
1402a54f2c7SM Chetan Kumar exit:
1412a54f2c7SM Chetan Kumar 	/* Log any skb drop */
1422a54f2c7SM Chetan Kumar 	if (if_id)
1432a54f2c7SM Chetan Kumar 		dev_dbg(ipc_wwan->dev, "skb dropped. IF_ID: %d, ret: %d", if_id,
1442a54f2c7SM Chetan Kumar 			ret);
1452a54f2c7SM Chetan Kumar 
1462a54f2c7SM Chetan Kumar 	dev_kfree_skb_any(skb);
147c302e3a1SM Chetan Kumar 	netdev->stats.tx_dropped++;
148c302e3a1SM Chetan Kumar 	return NETDEV_TX_OK;
1492a54f2c7SM Chetan Kumar }
1502a54f2c7SM Chetan Kumar 
1512a54f2c7SM Chetan Kumar /* Ops structure for wwan net link */
1522a54f2c7SM Chetan Kumar static const struct net_device_ops ipc_inm_ops = {
1532a54f2c7SM Chetan Kumar 	.ndo_open = ipc_wwan_link_open,
1542a54f2c7SM Chetan Kumar 	.ndo_stop = ipc_wwan_link_stop,
1552a54f2c7SM Chetan Kumar 	.ndo_start_xmit = ipc_wwan_link_transmit,
1562a54f2c7SM Chetan Kumar };
1572a54f2c7SM Chetan Kumar 
1582a54f2c7SM Chetan Kumar /* Setup function for creating new net link */
1592a54f2c7SM Chetan Kumar static void ipc_wwan_setup(struct net_device *iosm_dev)
1602a54f2c7SM Chetan Kumar {
1612a54f2c7SM Chetan Kumar 	iosm_dev->header_ops = NULL;
1622a54f2c7SM Chetan Kumar 	iosm_dev->hard_header_len = 0;
1635d710dc3SM Chetan Kumar 	iosm_dev->tx_queue_len = DEFAULT_TX_QUEUE_LEN;
1642a54f2c7SM Chetan Kumar 
1652a54f2c7SM Chetan Kumar 	iosm_dev->type = ARPHRD_NONE;
166d7340f46SM Chetan Kumar 	iosm_dev->mtu = ETH_DATA_LEN;
1672a54f2c7SM Chetan Kumar 	iosm_dev->min_mtu = ETH_MIN_MTU;
1682a54f2c7SM Chetan Kumar 	iosm_dev->max_mtu = ETH_MAX_MTU;
1692a54f2c7SM Chetan Kumar 
1702a54f2c7SM Chetan Kumar 	iosm_dev->flags = IFF_POINTOPOINT | IFF_NOARP;
1712a54f2c7SM Chetan Kumar 
1722a54f2c7SM Chetan Kumar 	iosm_dev->netdev_ops = &ipc_inm_ops;
1732a54f2c7SM Chetan Kumar }
1742a54f2c7SM Chetan Kumar 
1752a54f2c7SM Chetan Kumar /* Create new wwan net link */
1762a54f2c7SM Chetan Kumar static int ipc_wwan_newlink(void *ctxt, struct net_device *dev,
1772a54f2c7SM Chetan Kumar 			    u32 if_id, struct netlink_ext_ack *extack)
1782a54f2c7SM Chetan Kumar {
1792a54f2c7SM Chetan Kumar 	struct iosm_wwan *ipc_wwan = ctxt;
1802a54f2c7SM Chetan Kumar 	struct iosm_netdev_priv *priv;
1812a54f2c7SM Chetan Kumar 	int err;
1822a54f2c7SM Chetan Kumar 
1832a54f2c7SM Chetan Kumar 	if (if_id < IP_MUX_SESSION_START ||
1842a54f2c7SM Chetan Kumar 	    if_id >= ARRAY_SIZE(ipc_wwan->sub_netlist))
1852a54f2c7SM Chetan Kumar 		return -EINVAL;
1862a54f2c7SM Chetan Kumar 
18769940924SSergey Ryazanov 	priv = wwan_netdev_drvpriv(dev);
1882a54f2c7SM Chetan Kumar 	priv->if_id = if_id;
1892a54f2c7SM Chetan Kumar 	priv->netdev = dev;
1902a54f2c7SM Chetan Kumar 	priv->ipc_wwan = ipc_wwan;
1912a54f2c7SM Chetan Kumar 
1922a54f2c7SM Chetan Kumar 	mutex_lock(&ipc_wwan->if_mutex);
1932a54f2c7SM Chetan Kumar 	if (rcu_access_pointer(ipc_wwan->sub_netlist[if_id])) {
1942a54f2c7SM Chetan Kumar 		err = -EBUSY;
1952a54f2c7SM Chetan Kumar 		goto out_unlock;
1962a54f2c7SM Chetan Kumar 	}
1972a54f2c7SM Chetan Kumar 
1982a54f2c7SM Chetan Kumar 	err = register_netdevice(dev);
1992a54f2c7SM Chetan Kumar 	if (err)
2002a54f2c7SM Chetan Kumar 		goto out_unlock;
2012a54f2c7SM Chetan Kumar 
2022a54f2c7SM Chetan Kumar 	rcu_assign_pointer(ipc_wwan->sub_netlist[if_id], priv);
2032a54f2c7SM Chetan Kumar 	mutex_unlock(&ipc_wwan->if_mutex);
2042a54f2c7SM Chetan Kumar 
2052a54f2c7SM Chetan Kumar 	netif_device_attach(dev);
2062a54f2c7SM Chetan Kumar 
2072a54f2c7SM Chetan Kumar 	return 0;
2082a54f2c7SM Chetan Kumar 
2092a54f2c7SM Chetan Kumar out_unlock:
2102a54f2c7SM Chetan Kumar 	mutex_unlock(&ipc_wwan->if_mutex);
2112a54f2c7SM Chetan Kumar 	return err;
2122a54f2c7SM Chetan Kumar }
2132a54f2c7SM Chetan Kumar 
2142a54f2c7SM Chetan Kumar static void ipc_wwan_dellink(void *ctxt, struct net_device *dev,
2152a54f2c7SM Chetan Kumar 			     struct list_head *head)
2162a54f2c7SM Chetan Kumar {
21769940924SSergey Ryazanov 	struct iosm_netdev_priv *priv = wwan_netdev_drvpriv(dev);
2182a54f2c7SM Chetan Kumar 	struct iosm_wwan *ipc_wwan = ctxt;
2192a54f2c7SM Chetan Kumar 	int if_id = priv->if_id;
2202a54f2c7SM Chetan Kumar 
2212a54f2c7SM Chetan Kumar 	if (WARN_ON(if_id < IP_MUX_SESSION_START ||
2222a54f2c7SM Chetan Kumar 		    if_id >= ARRAY_SIZE(ipc_wwan->sub_netlist)))
2232a54f2c7SM Chetan Kumar 		return;
2242a54f2c7SM Chetan Kumar 
2252a54f2c7SM Chetan Kumar 	mutex_lock(&ipc_wwan->if_mutex);
2262a54f2c7SM Chetan Kumar 
2272a54f2c7SM Chetan Kumar 	if (WARN_ON(rcu_access_pointer(ipc_wwan->sub_netlist[if_id]) != priv))
2282a54f2c7SM Chetan Kumar 		goto unlock;
2292a54f2c7SM Chetan Kumar 
2302a54f2c7SM Chetan Kumar 	RCU_INIT_POINTER(ipc_wwan->sub_netlist[if_id], NULL);
2312a54f2c7SM Chetan Kumar 	/* unregistering includes synchronize_net() */
232679505baSM Chetan Kumar 	unregister_netdevice_queue(dev, head);
2332a54f2c7SM Chetan Kumar 
2342a54f2c7SM Chetan Kumar unlock:
2352a54f2c7SM Chetan Kumar 	mutex_unlock(&ipc_wwan->if_mutex);
2362a54f2c7SM Chetan Kumar }
2372a54f2c7SM Chetan Kumar 
2382a54f2c7SM Chetan Kumar static const struct wwan_ops iosm_wwan_ops = {
2392a54f2c7SM Chetan Kumar 	.priv_size = sizeof(struct iosm_netdev_priv),
2402a54f2c7SM Chetan Kumar 	.setup = ipc_wwan_setup,
2412a54f2c7SM Chetan Kumar 	.newlink = ipc_wwan_newlink,
2422a54f2c7SM Chetan Kumar 	.dellink = ipc_wwan_dellink,
2432a54f2c7SM Chetan Kumar };
2442a54f2c7SM Chetan Kumar 
2452a54f2c7SM Chetan Kumar int ipc_wwan_receive(struct iosm_wwan *ipc_wwan, struct sk_buff *skb_arg,
2462a54f2c7SM Chetan Kumar 		     bool dss, int if_id)
2472a54f2c7SM Chetan Kumar {
2482a54f2c7SM Chetan Kumar 	struct sk_buff *skb = skb_arg;
2492a54f2c7SM Chetan Kumar 	struct net_device_stats *stats;
2502a54f2c7SM Chetan Kumar 	struct iosm_netdev_priv *priv;
2512a54f2c7SM Chetan Kumar 	int ret;
2522a54f2c7SM Chetan Kumar 
2532a54f2c7SM Chetan Kumar 	if ((skb->data[0] & IOSM_IP_TYPE_MASK) == IOSM_IP_TYPE_IPV4)
2542a54f2c7SM Chetan Kumar 		skb->protocol = htons(ETH_P_IP);
2552a54f2c7SM Chetan Kumar 	else if ((skb->data[0] & IOSM_IP_TYPE_MASK) ==
2562a54f2c7SM Chetan Kumar 		 IOSM_IP_TYPE_IPV6)
2572a54f2c7SM Chetan Kumar 		skb->protocol = htons(ETH_P_IPV6);
2582a54f2c7SM Chetan Kumar 
2592a54f2c7SM Chetan Kumar 	skb->pkt_type = PACKET_HOST;
2602a54f2c7SM Chetan Kumar 
2615bb4eea0SM Chetan Kumar 	if (if_id < IP_MUX_SESSION_START ||
2625bb4eea0SM Chetan Kumar 	    if_id > IP_MUX_SESSION_END) {
2632a54f2c7SM Chetan Kumar 		ret = -EINVAL;
2642a54f2c7SM Chetan Kumar 		goto free;
2652a54f2c7SM Chetan Kumar 	}
2662a54f2c7SM Chetan Kumar 
2672a54f2c7SM Chetan Kumar 	rcu_read_lock();
2682a54f2c7SM Chetan Kumar 	priv = rcu_dereference(ipc_wwan->sub_netlist[if_id]);
2692a54f2c7SM Chetan Kumar 	if (!priv) {
2702a54f2c7SM Chetan Kumar 		ret = -EINVAL;
2712a54f2c7SM Chetan Kumar 		goto unlock;
2722a54f2c7SM Chetan Kumar 	}
2732a54f2c7SM Chetan Kumar 	skb->dev = priv->netdev;
2742a54f2c7SM Chetan Kumar 	stats = &priv->netdev->stats;
2752a54f2c7SM Chetan Kumar 	stats->rx_packets++;
2762a54f2c7SM Chetan Kumar 	stats->rx_bytes += skb->len;
2772a54f2c7SM Chetan Kumar 
2782a54f2c7SM Chetan Kumar 	ret = netif_rx(skb);
2792a54f2c7SM Chetan Kumar 	skb = NULL;
2802a54f2c7SM Chetan Kumar unlock:
2812a54f2c7SM Chetan Kumar 	rcu_read_unlock();
2822a54f2c7SM Chetan Kumar free:
2832a54f2c7SM Chetan Kumar 	dev_kfree_skb(skb);
2842a54f2c7SM Chetan Kumar 	return ret;
2852a54f2c7SM Chetan Kumar }
2862a54f2c7SM Chetan Kumar 
2872a54f2c7SM Chetan Kumar void ipc_wwan_tx_flowctrl(struct iosm_wwan *ipc_wwan, int if_id, bool on)
2882a54f2c7SM Chetan Kumar {
2892a54f2c7SM Chetan Kumar 	struct net_device *netdev;
2902a54f2c7SM Chetan Kumar 	struct iosm_netdev_priv *priv;
2912a54f2c7SM Chetan Kumar 	bool is_tx_blk;
2922a54f2c7SM Chetan Kumar 
2932a54f2c7SM Chetan Kumar 	rcu_read_lock();
2942a54f2c7SM Chetan Kumar 	priv = rcu_dereference(ipc_wwan->sub_netlist[if_id]);
2952a54f2c7SM Chetan Kumar 	if (!priv) {
2962a54f2c7SM Chetan Kumar 		rcu_read_unlock();
2972a54f2c7SM Chetan Kumar 		return;
2982a54f2c7SM Chetan Kumar 	}
2992a54f2c7SM Chetan Kumar 
3002a54f2c7SM Chetan Kumar 	netdev = priv->netdev;
3012a54f2c7SM Chetan Kumar 
3022a54f2c7SM Chetan Kumar 	is_tx_blk = netif_queue_stopped(netdev);
3032a54f2c7SM Chetan Kumar 
3042a54f2c7SM Chetan Kumar 	if (on)
3052a54f2c7SM Chetan Kumar 		dev_dbg(ipc_wwan->dev, "session id[%d]: flowctrl enable",
3062a54f2c7SM Chetan Kumar 			if_id);
3072a54f2c7SM Chetan Kumar 
3082a54f2c7SM Chetan Kumar 	if (on && !is_tx_blk)
3092a54f2c7SM Chetan Kumar 		netif_stop_queue(netdev);
3102a54f2c7SM Chetan Kumar 	else if (!on && is_tx_blk)
3112a54f2c7SM Chetan Kumar 		netif_wake_queue(netdev);
3122a54f2c7SM Chetan Kumar 	rcu_read_unlock();
3132a54f2c7SM Chetan Kumar }
3142a54f2c7SM Chetan Kumar 
3152a54f2c7SM Chetan Kumar struct iosm_wwan *ipc_wwan_init(struct iosm_imem *ipc_imem, struct device *dev)
3162a54f2c7SM Chetan Kumar {
3172a54f2c7SM Chetan Kumar 	struct iosm_wwan *ipc_wwan;
3182a54f2c7SM Chetan Kumar 
3192a54f2c7SM Chetan Kumar 	ipc_wwan = kzalloc(sizeof(*ipc_wwan), GFP_KERNEL);
3202a54f2c7SM Chetan Kumar 	if (!ipc_wwan)
3212a54f2c7SM Chetan Kumar 		return NULL;
3222a54f2c7SM Chetan Kumar 
3232a54f2c7SM Chetan Kumar 	ipc_wwan->dev = dev;
3242a54f2c7SM Chetan Kumar 	ipc_wwan->ipc_imem = ipc_imem;
3252a54f2c7SM Chetan Kumar 
32683068395SSergey Ryazanov 	/* WWAN core will create a netdev for the default IP MUX channel */
327ca374290SSergey Ryazanov 	if (wwan_register_ops(ipc_wwan->dev, &iosm_wwan_ops, ipc_wwan,
32883068395SSergey Ryazanov 			      IP_MUX_SESSION_DEFAULT)) {
3292a54f2c7SM Chetan Kumar 		kfree(ipc_wwan);
3302a54f2c7SM Chetan Kumar 		return NULL;
3312a54f2c7SM Chetan Kumar 	}
3322a54f2c7SM Chetan Kumar 
3332a54f2c7SM Chetan Kumar 	mutex_init(&ipc_wwan->if_mutex);
3342a54f2c7SM Chetan Kumar 
3352a54f2c7SM Chetan Kumar 	return ipc_wwan;
3362a54f2c7SM Chetan Kumar }
3372a54f2c7SM Chetan Kumar 
3382a54f2c7SM Chetan Kumar void ipc_wwan_deinit(struct iosm_wwan *ipc_wwan)
3392a54f2c7SM Chetan Kumar {
340322a0ba9SSergey Ryazanov 	/* This call will remove all child netdev(s) */
3412a54f2c7SM Chetan Kumar 	wwan_unregister_ops(ipc_wwan->dev);
3422a54f2c7SM Chetan Kumar 
3432a54f2c7SM Chetan Kumar 	mutex_destroy(&ipc_wwan->if_mutex);
3442a54f2c7SM Chetan Kumar 
3452a54f2c7SM Chetan Kumar 	kfree(ipc_wwan);
3462a54f2c7SM Chetan Kumar }
347