From patchwork Tue Jan 2 10:29:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bhavya Kapoor X-Patchwork-Id: 184309 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:6f82:b0:100:9c79:88ff with SMTP id tb2csp4366520dyb; Tue, 2 Jan 2024 02:30:50 -0800 (PST) X-Google-Smtp-Source: AGHT+IEMhTSXSsXYZB2xgqCxYAlD6dmXF6wt42/DhKPimukoo7nhTsIBmke834z4Ogs+pWRWsjJ9 X-Received: by 2002:a05:6830:e0c:b0:6dc:4fcf:4859 with SMTP id do12-20020a0568300e0c00b006dc4fcf4859mr1973238otb.75.1704191450413; Tue, 02 Jan 2024 02:30:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704191450; cv=none; d=google.com; s=arc-20160816; b=m+zd1lLyxJkrBUyYlv8+GzMc8wcE2FWc8PaDM26QUtUWFG6aKp4OaUL2ZpfIrEs6ia lqzL9u73jJclTTazFkcckFoyr7EHV7o/ToZsoHaZ0B4JJ1G3xIFUBKnR6U3Mw8cjTgvd a0cyFUrZMR1JAp6H8EBYKMdKhFfMNFz54KoFMQxnKn9jFgx3OJdoDE0eI9DhfXiFC6Xl Mtpiry/EuU69BINHpoLgNmHREzv9dO1TUDKdFCfQq1amyaMdEsNLEinUtzdx0FKDRRKB 6wiYf+5krsI3dxDfbaZN63W/AJV1P5NIsVfKxAwlwjUeg2NTVqnbkX2R/ePkaUFof/jT 2VZw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from:dkim-signature; bh=py4JJm+wTIiadC5aI9EnyBmLyFhvonKYqsl52ZyUjE8=; fh=EFlypyC09g/t9UHJA+06Z9c0PzQ3OyV77K92Aanqj10=; b=JuCsNFHA28fU4LFFwMRsf9Pxbfx3IFcKWvHj/bOjcxb1ttac2Crdv4oCDyBQAwR7Eg Ud8E5QaAYKKT9ArIdUN+51pdG0uT6zAu6apR8bwTEouwA/ql1MNN98zYVAsPCZKNEmOH xhB0SoHwI/Y81ZhaOikoxJRKu05PvsrgrKYk9qVP9y4pCKh95tvrwMVNEgagRWp0z08s /TXTBT/1pLZxgVjHI5q5lqBYvfEOMHsdfGWGG41RRTOkzwguX18WHjOi+u1rtW74XTPu jX7rQVhw0j11xsHGvJfSavYZ+XvX4yU8IxDhloVc0oW72iqKHPcbxFz5LcRRxBAJW27n eKkA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=GHZw89Z2; spf=pass (google.com: domain of linux-kernel+bounces-14243-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-14243-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id s62-20020a635e41000000b005ce018f4293si16644871pgb.701.2024.01.02.02.30.50 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Jan 2024 02:30:50 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-14243-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=GHZw89Z2; spf=pass (google.com: domain of linux-kernel+bounces-14243-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-14243-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 2765AB21BE8 for ; Tue, 2 Jan 2024 10:30:47 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 77337D534; Tue, 2 Jan 2024 10:30:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ti.com header.i=@ti.com header.b="GHZw89Z2" X-Original-To: linux-kernel@vger.kernel.org Received: from fllv0015.ext.ti.com (fllv0015.ext.ti.com [198.47.19.141]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 568FEDF51; Tue, 2 Jan 2024 10:30:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=ti.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ti.com Received: from lelv0265.itg.ti.com ([10.180.67.224]) by fllv0015.ext.ti.com (8.15.2/8.15.2) with ESMTP id 402ATpYu012619; Tue, 2 Jan 2024 04:29:51 -0600 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1704191391; bh=py4JJm+wTIiadC5aI9EnyBmLyFhvonKYqsl52ZyUjE8=; h=From:To:CC:Subject:Date; b=GHZw89Z26f/IbpjxHF70MbGJrqMHhvQI1nKCRMpx2yMfaNlgCvR9ZpF2xYnr85Lj1 M/tjHyCgsMpBGISjVzOKK/nZKd2J7sKulzt3uq/4TBD3xNLcFsvQax2UyLQhHLs7gI PGJ++7P9xXYSs6eHcK1Q2wl6ISbZkff7ojxiFczQ= Received: from DFLE100.ent.ti.com (dfle100.ent.ti.com [10.64.6.21]) by lelv0265.itg.ti.com (8.15.2/8.15.2) with ESMTPS id 402ATpfN025970 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Tue, 2 Jan 2024 04:29:51 -0600 Received: from DFLE104.ent.ti.com (10.64.6.25) by DFLE100.ent.ti.com (10.64.6.21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2507.23; Tue, 2 Jan 2024 04:29:51 -0600 Received: from lelvsmtp5.itg.ti.com (10.180.75.250) by DFLE104.ent.ti.com (10.64.6.25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2507.23 via Frontend Transport; Tue, 2 Jan 2024 04:29:50 -0600 Received: from localhost ([10.249.131.155]) by lelvsmtp5.itg.ti.com (8.15.2/8.15.2) with ESMTP id 402AToSq071024; Tue, 2 Jan 2024 04:29:50 -0600 From: Bhavya Kapoor To: , CC: , , , , , , , , , , , Subject: [PATCH] net: can: Add support for aliases in CAN Date: Tue, 2 Jan 2024 15:59:49 +0530 Message-ID: <20240102102949.138607-1-b-kapoor@ti.com> X-Mailer: git-send-email 2.40.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1786974254363030345 X-GMAIL-MSGID: 1786974254363030345 When multiple CAN's are present, then names that are getting assigned changes after every boot even after providing alias in the device tree. Thus, Add support for implementing CAN aliasing so that names or alias for CAN will now be provided from device tree. Signed-off-by: Bhavya Kapoor --- drivers/net/can/dev/dev.c | 15 ++++++++++++--- drivers/net/can/m_can/m_can.c | 2 +- include/linux/can/dev.h | 8 +++++--- 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/drivers/net/can/dev/dev.c b/drivers/net/can/dev/dev.c index 3a3be5cdfc1f..ed483c23ec79 100644 --- a/drivers/net/can/dev/dev.c +++ b/drivers/net/can/dev/dev.c @@ -247,12 +247,14 @@ void can_setup(struct net_device *dev) /* Allocate and setup space for the CAN network device */ struct net_device *alloc_candev_mqs(int sizeof_priv, unsigned int echo_skb_max, - unsigned int txqs, unsigned int rxqs) + unsigned int txqs, unsigned int rxqs, + struct device *candev) { struct can_ml_priv *can_ml; struct net_device *dev; struct can_priv *priv; - int size; + int size, aliasid; + char devname[6] = "can%d"; /* We put the driver's priv, the CAN mid layer priv and the * echo skb into the netdevice's priv. The memory layout for @@ -273,7 +275,14 @@ struct net_device *alloc_candev_mqs(int sizeof_priv, unsigned int echo_skb_max, size = ALIGN(size, sizeof(struct sk_buff *)) + echo_skb_max * sizeof(struct sk_buff *); - dev = alloc_netdev_mqs(size, "can%d", NET_NAME_UNKNOWN, can_setup, + if (candev) { + aliasid = of_alias_get_id(candev->of_node, "can"); + if (aliasid >= 0) + snprintf(devname, sizeof(devname), "%s%d", "can", aliasid); + } + dev_dbg(candev, "Name of CAN assigned is : %s\n", devname); + + dev = alloc_netdev_mqs(size, devname, NET_NAME_UNKNOWN, can_setup, txqs, rxqs); if (!dev) return NULL; diff --git a/drivers/net/can/m_can/m_can.c b/drivers/net/can/m_can/m_can.c index 16ecc11c7f62..c91a5c7b3ae5 100644 --- a/drivers/net/can/m_can/m_can.c +++ b/drivers/net/can/m_can/m_can.c @@ -2029,7 +2029,7 @@ struct m_can_classdev *m_can_class_allocate_dev(struct device *dev, tx_fifo_size = mram_config_vals[7]; /* allocate the m_can device */ - net_dev = alloc_candev(sizeof_priv, tx_fifo_size); + net_dev = alloc_candev_with_dev(sizeof_priv, tx_fifo_size, dev); if (!net_dev) { dev_err(dev, "Failed to allocate CAN device"); goto out; diff --git a/include/linux/can/dev.h b/include/linux/can/dev.h index 1b92aed49363..b59142c16e59 100644 --- a/include/linux/can/dev.h +++ b/include/linux/can/dev.h @@ -171,11 +171,13 @@ static inline bool can_dev_dropped_skb(struct net_device *dev, struct sk_buff *s void can_setup(struct net_device *dev); struct net_device *alloc_candev_mqs(int sizeof_priv, unsigned int echo_skb_max, - unsigned int txqs, unsigned int rxqs); + unsigned int txqs, unsigned int rxqs, struct device *dev); #define alloc_candev(sizeof_priv, echo_skb_max) \ - alloc_candev_mqs(sizeof_priv, echo_skb_max, 1, 1) + alloc_candev_mqs(sizeof_priv, echo_skb_max, 1, 1, NULL) +#define alloc_candev_with_dev(sizeof_priv, echo_skb_max, dev) \ + alloc_candev_mqs(sizeof_priv, echo_skb_max, 1, 1, dev) #define alloc_candev_mq(sizeof_priv, echo_skb_max, count) \ - alloc_candev_mqs(sizeof_priv, echo_skb_max, count, count) + alloc_candev_mqs(sizeof_priv, echo_skb_max, count, count, NULL) void free_candev(struct net_device *dev); /* a candev safe wrapper around netdev_priv */