From: Vivek Pernamitta <quic_vpernami@quicinc.com>
To: <mhi@lists.linux.dev>
Cc: <mrana@quicinc.com>, <quic_qianyu@quicinc.com>,
<manivannan.sadhasivam@linaro.org>,
"David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>,
"Paolo Abeni" <pabeni@redhat.com>,
"open list:NETWORKING DRIVERS" <netdev@vger.kernel.org>,
open list <linux-kernel@vger.kernel.org>,
<quic_krichai@quicinc.com>, <quic_vbadigan@quicinc.com>,
<linux-arm-msm@vger.kernel.org>
Subject: Re: [PATCH V1] net: mhi : Add support to enable ethernet interface
Date: Fri, 30 Jun 2023 15:25:57 +0530 [thread overview]
Message-ID: <32832352-e832-3ce1-caed-51e909b9ba62@quicinc.com> (raw)
In-Reply-To: <1688118281-13032-1-git-send-email-quic_vpernami@quicinc.com>
On 6/30/2023 3:14 PM, Vivek Pernamitta wrote:
> Add support to enable ethernet interface for MHI SWIP channels.
>
> Signed-off-by: Vivek Pernamitta <quic_vpernami@quicinc.com>
> ---
> drivers/net/mhi_net.c | 53 ++++++++++++++++++++++++++++++++++++++-------------
> 1 file changed, 40 insertions(+), 13 deletions(-)
>
> diff --git a/drivers/net/mhi_net.c b/drivers/net/mhi_net.c
> index 3d322ac..0a47e15 100644
> --- a/drivers/net/mhi_net.c
> +++ b/drivers/net/mhi_net.c
> @@ -11,6 +11,7 @@
> #include <linux/netdevice.h>
> #include <linux/skbuff.h>
> #include <linux/u64_stats_sync.h>
> +#include <linux/etherdevice.h>
>
> #define MHI_NET_MIN_MTU ETH_MIN_MTU
> #define MHI_NET_MAX_MTU 0xffff
> @@ -38,10 +39,12 @@ struct mhi_net_dev {
> u32 rx_queue_sz;
> int msg_enable;
> unsigned int mru;
> + bool ethernet_if;
> };
>
> struct mhi_device_info {
> const char *netname;
> + bool ethernet_if;
> };
>
> static int mhi_ndo_open(struct net_device *ndev)
> @@ -140,6 +143,14 @@ static void mhi_net_setup(struct net_device *ndev)
> ndev->tx_queue_len = 1000;
> }
>
> +static void mhi_ethernet_setup(struct net_device *ndev)
> +{
> + ndev->netdev_ops = &mhi_netdev_ops;
> + ether_setup(ndev);
> + ndev->min_mtu = ETH_MIN_MTU;
> + ndev->max_mtu = ETH_MAX_MTU;
> +}
> +
> static struct sk_buff *mhi_net_skb_agg(struct mhi_net_dev *mhi_netdev,
> struct sk_buff *skb)
> {
> @@ -209,16 +220,22 @@ static void mhi_net_dl_callback(struct mhi_device *mhi_dev,
> mhi_netdev->skbagg_head = NULL;
> }
>
> - switch (skb->data[0] & 0xf0) {
> - case 0x40:
> - skb->protocol = htons(ETH_P_IP);
> - break;
> - case 0x60:
> - skb->protocol = htons(ETH_P_IPV6);
> - break;
> - default:
> - skb->protocol = htons(ETH_P_MAP);
> - break;
> + if (mhi_netdev->ethernet_if) {
> + skb_copy_to_linear_data(skb, skb->data,
> + mhi_res->bytes_xferd);
> + skb->protocol = eth_type_trans(skb, mhi_netdev->ndev);
> + } else {
> + switch (skb->data[0] & 0xf0) {
> + case 0x40:
> + skb->protocol = htons(ETH_P_IP);
> + break;
> + case 0x60:
> + skb->protocol = htons(ETH_P_IPV6);
> + break;
> + default:
> + skb->protocol = htons(ETH_P_MAP);
> + break;
> + }
> }
>
> u64_stats_update_begin(&mhi_netdev->stats.rx_syncp);
> @@ -301,11 +318,17 @@ static void mhi_net_rx_refill_work(struct work_struct *work)
> schedule_delayed_work(&mhi_netdev->rx_refill, HZ / 2);
> }
>
> -static int mhi_net_newlink(struct mhi_device *mhi_dev, struct net_device *ndev)
> +static int mhi_net_newlink(struct mhi_device *mhi_dev, struct net_device *ndev, bool eth_dev)
> {
> struct mhi_net_dev *mhi_netdev;
> int err;
>
> + if (eth_dev) {
> + eth_random_addr(ndev->dev_addr);
> + if (!is_valid_ether_addr(ndev->dev_addr))
> + return -EADDRNOTAVAIL;
> + }
> +
> mhi_netdev = netdev_priv(ndev);
>
> dev_set_drvdata(&mhi_dev->dev, mhi_netdev);
> @@ -313,6 +336,7 @@ static int mhi_net_newlink(struct mhi_device *mhi_dev, struct net_device *ndev)
> mhi_netdev->mdev = mhi_dev;
> mhi_netdev->skbagg_head = NULL;
> mhi_netdev->mru = mhi_dev->mhi_cntrl->mru;
> + mhi_netdev->ethernet_if = eth_dev;
>
> INIT_DELAYED_WORK(&mhi_netdev->rx_refill, mhi_net_rx_refill_work);
> u64_stats_init(&mhi_netdev->stats.rx_syncp);
> @@ -356,13 +380,14 @@ static int mhi_net_probe(struct mhi_device *mhi_dev,
> int err;
>
> ndev = alloc_netdev(sizeof(struct mhi_net_dev), info->netname,
> - NET_NAME_PREDICTABLE, mhi_net_setup);
> + NET_NAME_PREDICTABLE, info->ethernet_if ?
> + mhi_ethernet_setup : mhi_net_setup);
> if (!ndev)
> return -ENOMEM;
>
> SET_NETDEV_DEV(ndev, &mhi_dev->dev);
>
> - err = mhi_net_newlink(mhi_dev, ndev);
> + err = mhi_net_newlink(mhi_dev, ndev, info->ethernet_if);
> if (err) {
> free_netdev(ndev);
> return err;
> @@ -380,10 +405,12 @@ static void mhi_net_remove(struct mhi_device *mhi_dev)
>
> static const struct mhi_device_info mhi_hwip0 = {
> .netname = "mhi_hwip%d",
> + .ethernet_if = false,
> };
>
> static const struct mhi_device_info mhi_swip0 = {
> .netname = "mhi_swip%d",
> + .ethernet_if = false,
> };
>
> static const struct mhi_device_id mhi_net_id_table[] = {
next prev parent reply other threads:[~2023-06-30 9:56 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-06-30 9:44 Vivek Pernamitta
2023-06-30 9:55 ` Vivek Pernamitta [this message]
2023-06-30 11:55 ` Daniele Palmas
2023-06-30 13:13 ` Simon Horman
2023-06-30 13:46 ` kernel test robot
2023-07-02 13:37 ` kernel test robot
2023-07-11 7:50 ` kernel test robot
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=32832352-e832-3ce1-caed-51e909b9ba62@quicinc.com \
--to=quic_vpernami@quicinc.com \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=kuba@kernel.org \
--cc=linux-arm-msm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=manivannan.sadhasivam@linaro.org \
--cc=mhi@lists.linux.dev \
--cc=mrana@quicinc.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=quic_krichai@quicinc.com \
--cc=quic_qianyu@quicinc.com \
--cc=quic_vbadigan@quicinc.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®