Received: by 2002:a05:6358:7058:b0:131:369:b2a3 with SMTP id 24csp6436610rwp; Mon, 17 Jul 2023 23:36:59 -0700 (PDT) X-Google-Smtp-Source: APBJJlFdr6UvUAuaWe1PYGUPwUlOr74Spz72yWhv1IL8rVY3gftEIxYlsbgvavEm3KEZJLTqEgVX X-Received: by 2002:aa7:dcca:0:b0:51d:9462:16b3 with SMTP id w10-20020aa7dcca000000b0051d946216b3mr15073837edu.11.1689662219577; Mon, 17 Jul 2023 23:36:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689662219; cv=none; d=google.com; s=arc-20160816; b=UL53sktVwC78KeGBVI8rFFkIX4zcsz3RDFzWaVucghf/F1Km9jDS5+w7iA1z2REdqQ fcI4PWaaEW0O1+R05g7/h7jNeNQn0lTeLTe1LMyjmWSVa3GdMRpdMwT4vb3d2E8Sog2U O9nTvD0y2818zz/04S8Bsh29S1cU7XDI0nRv7nAkMdhzyYLnyKNDckputQ/oBJNlE9T4 gPCqD54b7is3vDuLq/PBEFomavduxeMyxfmKLO1SLXpRyMvD1c0GeqwvRRszIP3V+tGo /6ThTeWql1U8iCS5JBjLyNDuoiJ/4eQQNuMAThoTJxfV0SkWf9ukVJXhRfoSS3XuJE1V isIA== 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=FnMF/hPnhkGhQNVCRlvihoFhBZmvCK2+QcLEk0jb/Bs=; fh=sc5LcRaCAx11lTznMdPYMgiY9TjEGJ9XY+0GBxNb7zA=; b=tHA5cUEIM930FQrLPKuVIbDrt5YfeS48y255ZDPqr4+YloHZS75X1W/NB0dslO5chY FENZBbJLZGPZ86n5ZkokdRiSIjEJGZYG988HSG0OgOCwvg6qLlQNqLyZrAMgoa2R1zsy 6LGLwj/PWSA8Z1RpCLJhtFBbltdksWGQPv+FxnFd4m8YBN/UgxNy6tHL8cgH7erf5Fvc 724yVl95Osktf0GAglSf/1rdJRh2beM4dj3Cwm0zH5WPr3RuNtcrHe23IG9+b2sgAEdy 9Pzzmng2Co15Jy501vwQvFYzsRbFerCLiXE8b6UnhMlwGThCmCY/81rpWK60uyGnxF3B wOuA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=PV0vPj80; 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 h13-20020aa7c94d000000b0051dd511f0c1si709701edt.177.2023.07.17.23.36.33; Mon, 17 Jul 2023 23:36:59 -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=PV0vPj80; 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 S231384AbjGRGRG (ORCPT + 99 others); Tue, 18 Jul 2023 02:17:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58316 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231324AbjGRGQh (ORCPT ); Tue, 18 Jul 2023 02:16:37 -0400 Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 06D8F1988; Mon, 17 Jul 2023 23:15:53 -0700 (PDT) Received: from pps.filterd (m0279866.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 36I5W4OU017342; Tue, 18 Jul 2023 06:15:37 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=FnMF/hPnhkGhQNVCRlvihoFhBZmvCK2+QcLEk0jb/Bs=; b=PV0vPj80LkunkeppXTpH+hmpB1eAKDotTOc69n3zXPA7uDYzhfh7DAdq2Sdrm5fqzNSj FUlG/Cw0utQFQMNvPcWUes3QkYUsrF8+XxJE79XOPoeZOSNDGa2eyAFD9dNpesDXNRZd bcjcqcNH+LfdjkhxybCvSeGkHebA3Bagsd6nGvMmXOzRJFeChcsnuAAeMRdp9kP/QdNK D7KAgTDz+54oCB7KVhC4ErPgSb+vzQZ5V/fjGsZ7EczALs+hywvohKNSmGq9HCeMvHA1 9r/7yn0Mq4TsrubqPeH2N8HJrLhmaYrllAwpkN/7aiQHck0lFO1SID97i1Jjs0/Ll9fd Wg== Received: from apblrppmta02.qualcomm.com (blr-bdr-fw-01_GlobalNAT_AllZones-Outside.qualcomm.com [103.229.18.19]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3rw289thn2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 18 Jul 2023 06:15:37 +0000 Received: from pps.filterd (APBLRPPMTA02.qualcomm.com [127.0.0.1]) by APBLRPPMTA02.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTP id 36I6FXKc006794; Tue, 18 Jul 2023 06:15:33 GMT Received: from pps.reinject (localhost [127.0.0.1]) by APBLRPPMTA02.qualcomm.com (PPS) with ESMTPS id 3rumhk9kv1-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Tue, 18 Jul 2023 06:15:33 +0000 Received: from APBLRPPMTA02.qualcomm.com (APBLRPPMTA02.qualcomm.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 36I6FW2E006789; Tue, 18 Jul 2023 06:15:32 GMT Received: from hu-sgudaval-hyd.qualcomm.com (hu-vpernami-hyd.qualcomm.com [10.213.107.240]) by APBLRPPMTA02.qualcomm.com (PPS) with ESMTP id 36I6FW2G006788; Tue, 18 Jul 2023 06:15:32 +0000 Received: by hu-sgudaval-hyd.qualcomm.com (Postfix, from userid 2370923) id 640644BF5; Tue, 18 Jul 2023 11:45:31 +0530 (+0530) From: Vivek Pernamitta To: mhi@lists.linux.dev Cc: mrana@quicinc.com, quic_qianyu@quicinc.com, manivannan.sadhasivam@linaro.org, quic_vbadigan@quicinc.com, quic_krichai@quicinc.com, quic_skananth@quicinc.com, linux-arm-msm@vger.kernel.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 V2] net: mhi : Add support to enable ethernet interface Date: Tue, 18 Jul 2023 11:45:28 +0530 Message-Id: <1689660928-12092-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-ORIG-GUID: EVSTbR9y7PXaKywYjZxux8sKff_IZUml X-Proofpoint-GUID: EVSTbR9y7PXaKywYjZxux8sKff_IZUml 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-07-17_15,2023-07-13_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 clxscore=1011 suspectscore=0 bulkscore=0 mlxscore=0 adultscore=0 spamscore=0 impostorscore=0 phishscore=0 priorityscore=1501 mlxlogscore=871 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2306200000 definitions=main-2307180056 X-Spam-Status: No, score=-1.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_BLOCKED,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 Reviewed-by: Daniele Palmas Reviewed-by: Simon Horman --- changes since v1: - Moved to net-next from linux-next - moved to eth_hw_addr_random() to assign Ethernet MAC address from eth_random_addr() --- 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..5bb8d99 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_hw_addr_random(ndev); + 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