net: mhi: Add protocol support
MHI can transport different protocols, some are handled at upper level, like IP and QMAP(rmnet/netlink), but others will need to be inside MHI net driver, like mbim. This change adds support for protocol rx and tx_fixup callbacks registration, that can be used to encode/decode the targeted protocol. Signed-off-by: Loic Poulain <loic.poulain@linaro.org> Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
parent
24a1720a08
commit
ddeb9bfa59
@ -34,11 +34,24 @@ struct mhi_net_dev {
|
|||||||
struct net_device *ndev;
|
struct net_device *ndev;
|
||||||
struct sk_buff *skbagg_head;
|
struct sk_buff *skbagg_head;
|
||||||
struct sk_buff *skbagg_tail;
|
struct sk_buff *skbagg_tail;
|
||||||
|
const struct mhi_net_proto *proto;
|
||||||
|
void *proto_data;
|
||||||
struct delayed_work rx_refill;
|
struct delayed_work rx_refill;
|
||||||
struct mhi_net_stats stats;
|
struct mhi_net_stats stats;
|
||||||
u32 rx_queue_sz;
|
u32 rx_queue_sz;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct mhi_net_proto {
|
||||||
|
int (*init)(struct mhi_net_dev *mhi_netdev);
|
||||||
|
struct sk_buff * (*tx_fixup)(struct mhi_net_dev *mhi_netdev, struct sk_buff *skb);
|
||||||
|
void (*rx)(struct mhi_net_dev *mhi_netdev, struct sk_buff *skb);
|
||||||
|
};
|
||||||
|
|
||||||
|
struct mhi_device_info {
|
||||||
|
const char *netname;
|
||||||
|
const struct mhi_net_proto *proto;
|
||||||
|
};
|
||||||
|
|
||||||
static int mhi_ndo_open(struct net_device *ndev)
|
static int mhi_ndo_open(struct net_device *ndev)
|
||||||
{
|
{
|
||||||
struct mhi_net_dev *mhi_netdev = netdev_priv(ndev);
|
struct mhi_net_dev *mhi_netdev = netdev_priv(ndev);
|
||||||
@ -68,26 +81,35 @@ static int mhi_ndo_stop(struct net_device *ndev)
|
|||||||
static int mhi_ndo_xmit(struct sk_buff *skb, struct net_device *ndev)
|
static int mhi_ndo_xmit(struct sk_buff *skb, struct net_device *ndev)
|
||||||
{
|
{
|
||||||
struct mhi_net_dev *mhi_netdev = netdev_priv(ndev);
|
struct mhi_net_dev *mhi_netdev = netdev_priv(ndev);
|
||||||
|
const struct mhi_net_proto *proto = mhi_netdev->proto;
|
||||||
struct mhi_device *mdev = mhi_netdev->mdev;
|
struct mhi_device *mdev = mhi_netdev->mdev;
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
|
if (proto && proto->tx_fixup) {
|
||||||
|
skb = proto->tx_fixup(mhi_netdev, skb);
|
||||||
|
if (unlikely(!skb))
|
||||||
|
goto exit_drop;
|
||||||
|
}
|
||||||
|
|
||||||
err = mhi_queue_skb(mdev, DMA_TO_DEVICE, skb, skb->len, MHI_EOT);
|
err = mhi_queue_skb(mdev, DMA_TO_DEVICE, skb, skb->len, MHI_EOT);
|
||||||
if (unlikely(err)) {
|
if (unlikely(err)) {
|
||||||
net_err_ratelimited("%s: Failed to queue TX buf (%d)\n",
|
net_err_ratelimited("%s: Failed to queue TX buf (%d)\n",
|
||||||
ndev->name, err);
|
ndev->name, err);
|
||||||
|
|
||||||
u64_stats_update_begin(&mhi_netdev->stats.tx_syncp);
|
|
||||||
u64_stats_inc(&mhi_netdev->stats.tx_dropped);
|
|
||||||
u64_stats_update_end(&mhi_netdev->stats.tx_syncp);
|
|
||||||
|
|
||||||
/* drop the packet */
|
|
||||||
dev_kfree_skb_any(skb);
|
dev_kfree_skb_any(skb);
|
||||||
|
goto exit_drop;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mhi_queue_is_full(mdev, DMA_TO_DEVICE))
|
if (mhi_queue_is_full(mdev, DMA_TO_DEVICE))
|
||||||
netif_stop_queue(ndev);
|
netif_stop_queue(ndev);
|
||||||
|
|
||||||
return NETDEV_TX_OK;
|
return NETDEV_TX_OK;
|
||||||
|
|
||||||
|
exit_drop:
|
||||||
|
u64_stats_update_begin(&mhi_netdev->stats.tx_syncp);
|
||||||
|
u64_stats_inc(&mhi_netdev->stats.tx_dropped);
|
||||||
|
u64_stats_update_end(&mhi_netdev->stats.tx_syncp);
|
||||||
|
|
||||||
|
return NETDEV_TX_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void mhi_ndo_get_stats64(struct net_device *ndev,
|
static void mhi_ndo_get_stats64(struct net_device *ndev,
|
||||||
@ -164,6 +186,7 @@ static void mhi_net_dl_callback(struct mhi_device *mhi_dev,
|
|||||||
struct mhi_result *mhi_res)
|
struct mhi_result *mhi_res)
|
||||||
{
|
{
|
||||||
struct mhi_net_dev *mhi_netdev = dev_get_drvdata(&mhi_dev->dev);
|
struct mhi_net_dev *mhi_netdev = dev_get_drvdata(&mhi_dev->dev);
|
||||||
|
const struct mhi_net_proto *proto = mhi_netdev->proto;
|
||||||
struct sk_buff *skb = mhi_res->buf_addr;
|
struct sk_buff *skb = mhi_res->buf_addr;
|
||||||
int free_desc_count;
|
int free_desc_count;
|
||||||
|
|
||||||
@ -220,7 +243,10 @@ static void mhi_net_dl_callback(struct mhi_device *mhi_dev,
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
netif_rx(skb);
|
if (proto && proto->rx)
|
||||||
|
proto->rx(mhi_netdev, skb);
|
||||||
|
else
|
||||||
|
netif_rx(skb);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Refill if RX buffers queue becomes low */
|
/* Refill if RX buffers queue becomes low */
|
||||||
@ -302,14 +328,14 @@ static struct device_type wwan_type = {
|
|||||||
static int mhi_net_probe(struct mhi_device *mhi_dev,
|
static int mhi_net_probe(struct mhi_device *mhi_dev,
|
||||||
const struct mhi_device_id *id)
|
const struct mhi_device_id *id)
|
||||||
{
|
{
|
||||||
const char *netname = (char *)id->driver_data;
|
const struct mhi_device_info *info = (struct mhi_device_info *)id->driver_data;
|
||||||
struct device *dev = &mhi_dev->dev;
|
struct device *dev = &mhi_dev->dev;
|
||||||
struct mhi_net_dev *mhi_netdev;
|
struct mhi_net_dev *mhi_netdev;
|
||||||
struct net_device *ndev;
|
struct net_device *ndev;
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
ndev = alloc_netdev(sizeof(*mhi_netdev), netname, NET_NAME_PREDICTABLE,
|
ndev = alloc_netdev(sizeof(*mhi_netdev), info->netname,
|
||||||
mhi_net_setup);
|
NET_NAME_PREDICTABLE, mhi_net_setup);
|
||||||
if (!ndev)
|
if (!ndev)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
|
||||||
@ -318,6 +344,7 @@ static int mhi_net_probe(struct mhi_device *mhi_dev,
|
|||||||
mhi_netdev->ndev = ndev;
|
mhi_netdev->ndev = ndev;
|
||||||
mhi_netdev->mdev = mhi_dev;
|
mhi_netdev->mdev = mhi_dev;
|
||||||
mhi_netdev->skbagg_head = NULL;
|
mhi_netdev->skbagg_head = NULL;
|
||||||
|
mhi_netdev->proto = info->proto;
|
||||||
SET_NETDEV_DEV(ndev, &mhi_dev->dev);
|
SET_NETDEV_DEV(ndev, &mhi_dev->dev);
|
||||||
SET_NETDEV_DEVTYPE(ndev, &wwan_type);
|
SET_NETDEV_DEVTYPE(ndev, &wwan_type);
|
||||||
|
|
||||||
@ -337,8 +364,16 @@ static int mhi_net_probe(struct mhi_device *mhi_dev,
|
|||||||
if (err)
|
if (err)
|
||||||
goto out_err;
|
goto out_err;
|
||||||
|
|
||||||
|
if (mhi_netdev->proto) {
|
||||||
|
err = mhi_netdev->proto->init(mhi_netdev);
|
||||||
|
if (err)
|
||||||
|
goto out_err_proto;
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
out_err_proto:
|
||||||
|
unregister_netdev(ndev);
|
||||||
out_err:
|
out_err:
|
||||||
free_netdev(ndev);
|
free_netdev(ndev);
|
||||||
return err;
|
return err;
|
||||||
@ -358,9 +393,19 @@ static void mhi_net_remove(struct mhi_device *mhi_dev)
|
|||||||
free_netdev(mhi_netdev->ndev);
|
free_netdev(mhi_netdev->ndev);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static const struct mhi_device_info mhi_hwip0 = {
|
||||||
|
.netname = "mhi_hwip%d",
|
||||||
|
};
|
||||||
|
|
||||||
|
static const struct mhi_device_info mhi_swip0 = {
|
||||||
|
.netname = "mhi_swip%d",
|
||||||
|
};
|
||||||
|
|
||||||
static const struct mhi_device_id mhi_net_id_table[] = {
|
static const struct mhi_device_id mhi_net_id_table[] = {
|
||||||
{ .chan = "IP_HW0", .driver_data = (kernel_ulong_t)"mhi_hwip%d" },
|
/* Hardware accelerated data PATH (to modem IPA), protocol agnostic */
|
||||||
{ .chan = "IP_SW0", .driver_data = (kernel_ulong_t)"mhi_swip%d" },
|
{ .chan = "IP_HW0", .driver_data = (kernel_ulong_t)&mhi_hwip0 },
|
||||||
|
/* Software data PATH (to modem CPU) */
|
||||||
|
{ .chan = "IP_SW0", .driver_data = (kernel_ulong_t)&mhi_swip0 },
|
||||||
{}
|
{}
|
||||||
};
|
};
|
||||||
MODULE_DEVICE_TABLE(mhi, mhi_net_id_table);
|
MODULE_DEVICE_TABLE(mhi, mhi_net_id_table);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user