From patchwork Tue Jul 18 06:15:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vivek Pernamitta X-Patchwork-Id: 13316761 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 35538EB64DC for ; Tue, 18 Jul 2023 06:17:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231366AbjGRGRF (ORCPT ); Tue, 18 Jul 2023 02:17:05 -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 Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@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[] = {