Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp22041573rwd; Fri, 30 Jun 2023 03:08:47 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ65UvD9i8jSgyT5TKvbE9ouEfFjpnOaA2dxxi6AspZ2o6eyPVXlkstVt4wSiHl0S/veI+54 X-Received: by 2002:a05:6a20:3ca:b0:122:5441:b415 with SMTP id 10-20020a056a2003ca00b001225441b415mr1358017pzu.58.1688119727645; Fri, 30 Jun 2023 03:08:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688119727; cv=none; d=google.com; s=arc-20160816; b=ssUmCq4eIsry+rDBpW10UrkvqKuQxQ9/Z1NjglMMDEQJQoLHzTAE8KfoGc0kRB94tI 1MoEymlUvvPBYNO4GwFgY/w4I8nEk9fglUUv1zwxRxVXjULGiFILrldPhJ7GDIAegKHn Yr58epDWe6o+E/fUgl7qqD/z3Np11jIb3z54fJxhSFnaXVyadbAgOi1SNXG1U6xWyLW6 1X1A2DKpxXZTaaqw59Q0v+VcwH+Qv3pm+bcjQUtapg/2sL90dn3R2I52X08iMdpoLdVS tyb1MsjLYjHEW7c32b7r7iOngs0IZW9/e2FRo9gaheEuNdnrtkKOjYPryJIJP0Sgavfy EE9g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:date:subject:cc:to:from :dkim-signature; bh=m8GkzGGB8Y/Nd6gD6JDaZOx78tepjwbsym4/wVw+4dM=; fh=Z2BHX9hG7CD19yXzyBSv5Z3pqyMziJmvIVRwjRBW/Kw=; b=VXy5OPX9Hrp0mT3mYGZ5MPUQ9KSW+BMu8+lSfLA5ACBUjwxNytPOMKSiztfbdiEFMA qtibsyFALsLNflXDRJbnUYJRuMCx3PhPDgzY9mFWITihkttnbI4tgxkqsVYv5x0IvDKX ojVSk76l8p7P6q0tAOf170j7r/+WEQxeXgp6/gGOu7Akcy5Onh8ypXQGh8sgjjlE+NEV VdPXMwbK0oLH3zW65pfyDbD+JJX7xBTTG4nTZ9tRUeU5yfkCHfepkwoa+seJkF98YFg3 578OLDPC+q3DUui1Km+ZjRk3dtsKaoZmzZpOhmvkggAcR0O9ahQ3B+/R+pbC9VToCAe0 saOg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=CDp3B69o; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id m12-20020a170902f64c00b001b3eeaad177si12128642plg.99.2023.06.30.03.08.32; Fri, 30 Jun 2023 03:08:47 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=CDp3B69o; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232908AbjF3JpY (ORCPT + 99 others); Fri, 30 Jun 2023 05:45:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44194 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232925AbjF3JpO (ORCPT ); Fri, 30 Jun 2023 05:45:14 -0400 Received: from mx0b-0031df01.pphosted.com (mx0b-0031df01.pphosted.com [205.220.180.131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8F4ED10B; Fri, 30 Jun 2023 02:45:13 -0700 (PDT) Received: from pps.filterd (m0279872.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 35U8TtwQ024825; Fri, 30 Jun 2023 09:44:57 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h=from : to : cc : subject : date : message-id; s=qcppdkim1; bh=m8GkzGGB8Y/Nd6gD6JDaZOx78tepjwbsym4/wVw+4dM=; b=CDp3B69oegF+HOCX19SYzVDBNBSEOq++516NVcTqeiYaXPxhOS+bcTr9cTPT3PkiDJsy 3+HlQmv0dBrgJIjzibf+2SJJVs1OzdKg+Qb4S+T6OXbFxCZZuu6f12XN5p1w8ZufU3tl sjr591RVOMh8FTuxxVhhApTyq4MKWyE4igOm2R+1UjJKZPNtrUAwaPjyWir48RV2x9YM F4dTOTh0RPWh4DMW+hUTp9IIOBoH7sl+Yj+uCTQInHeTlV76vrZoGBtLcFhbnvjfHX8o y8C8yMAdiMIIMfCXQwoRKw7O985MI9uZkOsEl77X2fnWDBPZqfCZavcOHEr/sVHRBAME nw== Received: from apblrppmta01.qualcomm.com (blr-bdr-fw-01_GlobalNAT_AllZones-Outside.qualcomm.com [103.229.18.19]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3rh7aetqac-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 30 Jun 2023 09:44:57 +0000 Received: from pps.filterd (APBLRPPMTA01.qualcomm.com [127.0.0.1]) by APBLRPPMTA01.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTP id 35U9eeUB004943; Fri, 30 Jun 2023 09:44:53 GMT Received: from pps.reinject (localhost [127.0.0.1]) by APBLRPPMTA01.qualcomm.com (PPS) with ESMTPS id 3rdsjm5ucb-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Fri, 30 Jun 2023 09:44:53 +0000 Received: from APBLRPPMTA01.qualcomm.com (APBLRPPMTA01.qualcomm.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 35U9iqx5009498; Fri, 30 Jun 2023 09:44:52 GMT Received: from hu-sgudaval-hyd.qualcomm.com (hu-vpernami-hyd.qualcomm.com [10.213.107.240]) by APBLRPPMTA01.qualcomm.com (PPS) with ESMTP id 35U9ipi2009491; Fri, 30 Jun 2023 09:44:52 +0000 Received: by hu-sgudaval-hyd.qualcomm.com (Postfix, from userid 2370923) id 08A2F4BD9; Fri, 30 Jun 2023 15:14:51 +0530 (+0530) From: Vivek Pernamitta To: mhi@lists.linux.dev Cc: mrana@quicinc.com, quic_qianyu@quicinc.com, manivannan.sadhasivam@linaro.org, Vivek Pernamitta , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , netdev@vger.kernel.org (open list:NETWORKING DRIVERS), linux-kernel@vger.kernel.org (open list) Subject: [PATCH V1] net: mhi : Add support to enable ethernet interface Date: Fri, 30 Jun 2023 15:14:41 +0530 Message-Id: <1688118281-13032-1-git-send-email-quic_vpernami@quicinc.com> X-Mailer: git-send-email 2.7.4 X-QCInternal: smtphost X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-GUID: pgMviZbwroaeKlBLZdiEeWL_tbDTCS54 X-Proofpoint-ORIG-GUID: pgMviZbwroaeKlBLZdiEeWL_tbDTCS54 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.957,Hydra:6.0.591,FMLib:17.11.176.26 definitions=2023-06-30_05,2023-06-30_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 adultscore=0 mlxlogscore=742 malwarescore=0 phishscore=0 bulkscore=0 lowpriorityscore=0 spamscore=0 clxscore=1011 suspectscore=0 priorityscore=1501 impostorscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2305260000 definitions=main-2306300081 X-Spam-Status: No, score=-1.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,SPF_HELO_NONE, SPF_NONE,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add support to enable ethernet interface for MHI SWIP channels. Signed-off-by: Vivek Pernamitta --- 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 #include #include +#include #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[] = { -- 2.7.4