From nobody Fri Apr 3 01:41:56 2026 Received: from smtp-out3.simply.com (smtp-out3.simply.com [94.231.106.210]) (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 656E333D512; Fri, 6 Mar 2026 16:29:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=94.231.106.210 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772814599; cv=none; b=L+f1V8YKIjem7VK8qCPSAzWVyhTpcRz2DXGpsQIKdxMxfgnlDgzwcA9uG73YoGqpliifUUBb6Fwkp3mA2Z/T/mJx1sW6aMULwKoxtrAyDJsK4Tya/D96Y/zZicbC0WsChyIshSpKgycN1B5whPuxlctaD4qDYrnweP4SroXoQzM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772814599; c=relaxed/simple; bh=hn2JXeogaIuqlSuRpXcL50R/H5l6JhWQSQ9knZLQLwM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Vp3Zy6Bl607lDt2tdYXswhKZRQoozufxShz+PvxrHjMzfE0y1mLJn+pSgh1jt32uqVQuXrlhNa+ozWKAXEWzJz3tX0mSWUJHHnCfto96/p+0zqwKhcl9JlilE0XcF0GTZ9bE9Ct346V0w2kVV/Qm7jGaqJ2WhuW07fLU9vnBcmI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gaisler.com; spf=pass smtp.mailfrom=gaisler.com; dkim=fail (0-bit key) header.d=gaisler.com header.i=@gaisler.com header.b=W89/n5xL reason="key not found in DNS"; arc=none smtp.client-ip=94.231.106.210 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gaisler.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gaisler.com Authentication-Results: smtp.subspace.kernel.org; dkim=fail reason="key not found in DNS" (0-bit key) header.d=gaisler.com header.i=@gaisler.com header.b="W89/n5xL" Received: from localhost (localhost [127.0.0.1]) by smtp.simply.com (Simply.com) with ESMTP id 4fSBh90X6hz1Fg9K; Fri, 6 Mar 2026 17:29:45 +0100 (CET) Received: from d-5xj5g74.got.gaisler.com.com (h-98-128-223-123.NA.cust.bahnhof.se [98.128.223.123]) by smtp.simply.com (Simply.com) with ESMTPA id 4fSBh85Mwbz1Fg8H; Fri, 6 Mar 2026 17:29:44 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gaisler.com; s=simplycom2; t=1772814584; bh=PG6Ar2Kiv+3KQmNKtPVULbEJgKNRrIjdmfNlwHZcMEo=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=W89/n5xLNQosv3MMet61JewRZCa8plMisGQHMsSqDNM8iNSuM3wsotLiBG0uhqIXR FM4sOvHA/MmFXGDJe1qvjircHI5Lh6XGmnlwfQ1eY6K1Fnlw9n2ls5JIA5H93vRiXy iNiGl6V0jKAt5LCR1dCr9NgzxxW4T6ActeM7RMaBo8yEXb6CdkKHweJwdU8Bl5FOQX XU7FLOgt6MJA7sOkk4IdtUbAkp0PhbH0b7830mEHhUZJhxe5ugCkqAjwglPrZe2Nrh 8OX5vXxZy+rehF6N0EnRkqVOM7mFev8PVqPRNCxXSx3POZAmY/Lq3Z4PIiPFRhicEh P7vqmIEwA4T1A== From: Arun Muthusamy To: robh@kernel.org, krzk+dt@kernel.org, conor+dt@kernel.org, mkl@pengutronix.de, mailhol@kernel.org Cc: devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-can@vger.kernel.org, Ludwig Rydberg , Krzysztof Kozlowski , Arun Muthusamy Subject: [PATCH v6 01/15] dt-bindings: Add vendor prefix for Frontgrade Gaisler AB Date: Fri, 6 Mar 2026 17:29:20 +0100 Message-ID: <20260306162934.22955-2-arun.muthusamy@gaisler.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20260306162934.22955-1-arun.muthusamy@gaisler.com> References: <20260306162934.22955-1-arun.muthusamy@gaisler.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Ludwig Rydberg Frontgrade Gaisler AB provides IP cores and supporting development tools for embedded processors based on the SPARC and RISC-V architectures. Some essential products are the LEON and NOEL synthesizable processor models together with a complete development environment and a library of IP cores (GRLIB). The company specializes in digital hardware design (ASIC/FPGA) for both commercial and aerospace applications. Web site: https://www.gaisler.com/ Signed-off-by: Ludwig Rydberg Acked-by: Krzysztof Kozlowski Signed-off-by: Arun Muthusamy --- Documentation/devicetree/bindings/vendor-prefixes.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Documentation/devicetree/bindings/vendor-prefixes.yaml b/Docum= entation/devicetree/bindings/vendor-prefixes.yaml index 424aa7b911a7..4e1b4eeff9ff 100644 --- a/Documentation/devicetree/bindings/vendor-prefixes.yaml +++ b/Documentation/devicetree/bindings/vendor-prefixes.yaml @@ -594,6 +594,8 @@ patternProperties: description: Fujitsu Ltd. "^fxtec,.*": description: FX Technology Ltd. + "^gaisler,.*": + description: Frontgrade Gaisler AB "^galaxycore,.*": description: GalaxyCore Inc. "^gameforce,.*": --=20 2.51.0 From nobody Fri Apr 3 01:41:56 2026 Received: from smtp-out3.simply.com (smtp-out3.simply.com [94.231.106.210]) (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 67ADC3E95B5; Fri, 6 Mar 2026 16:29:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=94.231.106.210 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772814600; cv=none; b=VYTyRpd8f1A0AZtqtwDj5wfRTyr/fjaXn0SiJPGkmJglbyzNxrorSx6vTJghX+8ln7zgelTzCXUegu7+YFXxckd8ZphNd07sScyzUbqp+pSd2gYg3hFc1KSIR+kl1jqii/9WNymA/nKRJwkfOyyJ0uY9iDyeiRbLHkwkY4AzU1c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772814600; c=relaxed/simple; bh=bgxiL2CenjSgTX8ZyWNi0qXCIeEd1o7ChPjVwhCLiCc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=makn+YagzMQ7DZ5sTI8RsDSi231/C+2GyVMAJZmZ0sz58Zrugvtu0My2fQom936Kkjf8+bzznMXUp2H/48AXyFvAX2fCi2RFyfiSh6NAtbnCfyIfWmyjdLQJYBC/pCvy2o4F9m7MMXuAQO4vOFXiyskSk1Ttr4Hz96rLC4vObLE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gaisler.com; spf=pass smtp.mailfrom=gaisler.com; dkim=fail (0-bit key) header.d=gaisler.com header.i=@gaisler.com header.b=XEL0VFob reason="key not found in DNS"; arc=none smtp.client-ip=94.231.106.210 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gaisler.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gaisler.com Authentication-Results: smtp.subspace.kernel.org; dkim=fail reason="key not found in DNS" (0-bit key) header.d=gaisler.com header.i=@gaisler.com header.b="XEL0VFob" Received: from localhost (localhost [127.0.0.1]) by smtp.simply.com (Simply.com) with ESMTP id 4fSBh922pDz1FlZ2; Fri, 6 Mar 2026 17:29:45 +0100 (CET) Received: from d-5xj5g74.got.gaisler.com.com (h-98-128-223-123.NA.cust.bahnhof.se [98.128.223.123]) by smtp.simply.com (Simply.com) with ESMTPA id 4fSBh90Hk1z1DDgW; Fri, 6 Mar 2026 17:29:45 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gaisler.com; s=simplycom2; t=1772814585; bh=sKdKbsysS8VkeCXJuVcT399Xxcd+y14MQjnvsfRAtQA=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=XEL0VFobqiWfVEYUoDUAKi3ssn1+8xxpeo8sRdFi7dcwlmyGC9ynpEX2nHrHtqqjY LdKVhYg58qQ1zKS234V9kez2UVyw7GFnuf9zLNXIDJTx/CdUKYmTPhBRo7JsOafIFY vV4A686CBlWDsBWgGkfw0V/bIGkZxXMQu0Y4zz7tqzvIV/szHrfLYtnAzw0CNrJYPe CVKyo8Z9QnCcnVpp4m4L/DnuEiHquXHV60tC2dXfTlRnluzPkoNptk9BD5beDXI6UF /jFLZfdHm9H8+yyz6OjhON8zu1j8A71JuZBrJE4d8eFSfYsKU358wTPkdo8gx2/J/H yATPxRfmsXW9w== From: Arun Muthusamy To: robh@kernel.org, krzk+dt@kernel.org, conor+dt@kernel.org, mkl@pengutronix.de, mailhol@kernel.org Cc: devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-can@vger.kernel.org, Arun Muthusamy Subject: [PATCH v6 02/15] dt-bindings: net: can: gaisler,grcan: Convert to DT schema Date: Fri, 6 Mar 2026 17:29:21 +0100 Message-ID: <20260306162934.22955-3-arun.muthusamy@gaisler.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20260306162934.22955-1-arun.muthusamy@gaisler.com> References: <20260306162934.22955-1-arun.muthusamy@gaisler.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Migrate device tree bindings for Gaisler GRCAN, GRHCAN and GRCANFD CAN controllers from a text format to YAML format. Additional changes: - Remove stale systemid property removed in commit 1e93ed26acf0 ("can: grcan: grcan_probe(): fix broken system id check for errata workaround needs") - Make freq optional - Add clocks - Add compatible - Add example Reviewed-by: Rob Herring Signed-off-by: Arun Muthusamy --- .../bindings/net/can/gaisler,grcan.yaml | 62 +++++++++++++++++++ .../devicetree/bindings/net/can/grcan.txt | 28 --------- 2 files changed, 62 insertions(+), 28 deletions(-) create mode 100644 Documentation/devicetree/bindings/net/can/gaisler,grcan= .yaml delete mode 100644 Documentation/devicetree/bindings/net/can/grcan.txt diff --git a/Documentation/devicetree/bindings/net/can/gaisler,grcan.yaml b= /Documentation/devicetree/bindings/net/can/gaisler,grcan.yaml new file mode 100644 index 000000000000..8fea97c7319a --- /dev/null +++ b/Documentation/devicetree/bindings/net/can/gaisler,grcan.yaml @@ -0,0 +1,62 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/net/can/gaisler,grcan.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Aeroflex Gaisler GRCAN, GRHCAN and GRCANFD CAN controllers. + +description: | + GRCAN, GRCANFD, GRHCAN controllers are available in the GRLIB VHDL + IP core library. + For further information look in the documentation for the GRLIB IP libra= ry: + https://download.gaisler.com/products/GRLIB/doc/grip.pdf + +maintainers: + - Arun Muthusamy + - Andreas Larsson + +allOf: + - $ref: can-controller.yaml# + +properties: + compatible: + enum: + - gaisler,grcan + - gaisler,grcanfd + + reg: + maxItems: 1 + + interrupts: + maxItems: 1 + + clocks: + maxItems: 1 + + freq: + $ref: /schemas/types.yaml#/definitions/uint32 + description: | + Frequency of the external oscillator clock in Hz (the frequency of t= he + AMBA bus in the ordinary case). + This property should be used by systems where the common clock + framework is not supported. + +required: + - compatible + - reg + - interrupts + +unevaluatedProperties: false + +examples: + - | + #include + + can@ff400000 { + compatible =3D "gaisler,grcanfd"; + clocks =3D <&sysclock>; + reg =3D <0xff400000 0x400>; + interrupt-parent =3D <&plic0>; + interrupts =3D <6>; + }; diff --git a/Documentation/devicetree/bindings/net/can/grcan.txt b/Document= ation/devicetree/bindings/net/can/grcan.txt deleted file mode 100644 index 34ef3498f887..000000000000 --- a/Documentation/devicetree/bindings/net/can/grcan.txt +++ /dev/null @@ -1,28 +0,0 @@ -Aeroflex Gaisler GRCAN and GRHCAN CAN controllers. - -The GRCAN and CRHCAN CAN controllers are available in the GRLIB VHDL IP co= re -library. - -Note: These properties are built from the AMBA plug&play in a Leon SPARC s= ystem -(the ordinary environment for GRCAN and GRHCAN). There are no dts files for -sparc. - -Required properties: - -- name : Should be "GAISLER_GRCAN", "01_03d", "GAISLER_GRHCAN" or "01_034" - -- reg : Address and length of the register set for the device - -- freq : Frequency of the external oscillator clock in Hz (the frequency of - the amba bus in the ordinary case) - -- interrupts : Interrupt number for this device - -Optional properties: - -- systemid : If not present or if the value of the least significant 16 bi= ts - of this 32-bit property is smaller than GRCAN_TXBUG_SAFE_GRLIB_VERSION - a bug workaround is activated. - -For further information look in the documentation for the GLIB IP core lib= rary: -http://www.gaisler.com/products/grlib/grip.pdf --=20 2.51.0 From nobody Fri Apr 3 01:41:56 2026 Received: from smtp-out3.simply.com (smtp-out3.simply.com [94.231.106.210]) (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 67A4536A034; Fri, 6 Mar 2026 16:29:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=94.231.106.210 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772814598; cv=none; b=l6aMr5NHUjPeZHvvd67u36G3IOQSvVFBCtemtZuQGJv6gT+6TqdlfFmR/iEYZe1I5EFliclkjpQx7YGlhToCHbGGxMXDl63fvJlgA/e6Y7TnTUV4iAdLewwfi3iybbppIjc25wUd3wgnanhvQdRpoid20yq/QKtJ0IabPcolWVc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772814598; c=relaxed/simple; bh=hG5KSuPtLiBtHjq424HSyAbeOdsq1PzCy6qL7NHd2UY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=anDyxUi3fX5OOEtOTZWBj7JuX3U3WvfHOq9LLfiUgmf/WW93sk8o7sFSikhh53MNJYJVdb+/BRMunJnzSBin43sSeT3yxOR5Rmj8o+Kfg26ppIxIaOrfaPMlsHMIeeqpECGuDEtk187SpcT1lYV5+1AK0CJKcev7FM7pGpkrwI8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gaisler.com; spf=pass smtp.mailfrom=gaisler.com; dkim=fail (0-bit key) header.d=gaisler.com header.i=@gaisler.com header.b=BOf8nTg7 reason="key not found in DNS"; arc=none smtp.client-ip=94.231.106.210 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gaisler.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gaisler.com Authentication-Results: smtp.subspace.kernel.org; dkim=fail reason="key not found in DNS" (0-bit key) header.d=gaisler.com header.i=@gaisler.com header.b="BOf8nTg7" Received: from localhost (localhost [127.0.0.1]) by smtp.simply.com (Simply.com) with ESMTP id 4fSBh93zQBz1FlZ3; Fri, 6 Mar 2026 17:29:45 +0100 (CET) Received: from d-5xj5g74.got.gaisler.com.com (h-98-128-223-123.NA.cust.bahnhof.se [98.128.223.123]) by smtp.simply.com (Simply.com) with ESMTPA id 4fSBh91r33z1DDRx; Fri, 6 Mar 2026 17:29:45 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gaisler.com; s=simplycom2; t=1772814585; bh=lDfZgx61aSWUJ1n5uo3C1KLCGawncX5ACzgdlX+fljk=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=BOf8nTg7uWD0YSfa+LliFDUqJVkDZJieNh5oPIorkT+Jj6noMUWuUpkcENfsn6/vd uVveHwble9oEwCCfzAtUA3o7YkT6dljo1B+MVlLuQT8C+i8dj+Ydc1kxaiadnRPGku RVBxAYf8dhFLw3+48VStKaSbLMZqXjsCRM7lK56WPUITLI0xXuo2L3NImJj4xcEe+p WFHNYdVbOGcu9u4arF4u6tz2CeF5UA/WHHauUaRwhplHZZcss07uGyqJYBCE9ULSw3 D4Rum+iskE95gG7j0Yto8nYLKEoX1vt8dxBJ6aiFaau+oCHlts4qBjAdEP/J27EnaG cU6wPWsChYvdQ== From: Arun Muthusamy To: robh@kernel.org, krzk+dt@kernel.org, conor+dt@kernel.org, mkl@pengutronix.de, mailhol@kernel.org Cc: devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-can@vger.kernel.org, Arun Muthusamy Subject: [PATCH v6 03/15] MAINTAINERS: Add maintainers for GRCAN CAN network driver Date: Fri, 6 Mar 2026 17:29:22 +0100 Message-ID: <20260306162934.22955-4-arun.muthusamy@gaisler.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20260306162934.22955-1-arun.muthusamy@gaisler.com> References: <20260306162934.22955-1-arun.muthusamy@gaisler.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add Arun Muthusamy and Andreas Larsson as maintainers for the GRCAN CAN network driver, This entry ensures clear communication channels for maintaining the Documentation and driver code associated with GRCAN. Signed-off-by: Arun Muthusamy --- MAINTAINERS | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/MAINTAINERS b/MAINTAINERS index 0dc4aa37d903..14ddd48e063f 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -10706,6 +10706,14 @@ F: drivers/gpio/gpiolib-cdev.c F: include/uapi/linux/gpio.h F: tools/gpio/ =20 +GRCAN CAN NETWORK DRIVER +M: Andreas Larsson +M: Arun Muthusamy +L: linux-can@vger.kernel.org +S: Maintained +F: Documentation/devicetree/bindings/net/can/gaisler,grcan.yaml +F: drivers/net/can/grcan.c + GRETH 10/100/1G Ethernet MAC device driver M: Andreas Larsson L: netdev@vger.kernel.org --=20 2.51.0 From nobody Fri Apr 3 01:41:56 2026 Received: from smtp-out3.simply.com (smtp-out3.simply.com [94.231.106.210]) (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 E136F3ED10B; Fri, 6 Mar 2026 16:29:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=94.231.106.210 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772814597; cv=none; b=d5Rd0OQxD8m6ZHxVhZK22jaglF2aPKg/zQGjtnn2yP6EdnIYDQy0DH571MmuE8v06a3I+Hc+R3y/EntnmofT/rzb5u5tBjcmLYW2bEzmi6qurBGEaX5d/i7gC2BYKSlOEukERy0DfzY0VmV7e4nIMhVDcNjifKRLEEnNuTsRNw0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772814597; c=relaxed/simple; bh=pAbE7oUiYBzPGw0DKpSKNoz6vw1tL4Fy7hQ2s129X2w=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=jwVfmis60j49o7+K7Qjg6gSmDC+oXg/MfJfOkWfPt52pmZ76732xGsrxOe2+NavSizH/mTxccH/CtaE8aSTILYz9bOPySJR56yUljKzSmmqluIAIOLs9NNv2MhflzjxFffqf709NhJliPhJ0IBBo3F/T5LmXSyIxWJ5dp2PwAVE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gaisler.com; spf=pass smtp.mailfrom=gaisler.com; dkim=fail (0-bit key) header.d=gaisler.com header.i=@gaisler.com header.b=KRVt+oSw reason="key not found in DNS"; arc=none smtp.client-ip=94.231.106.210 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gaisler.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gaisler.com Authentication-Results: smtp.subspace.kernel.org; dkim=fail reason="key not found in DNS" (0-bit key) header.d=gaisler.com header.i=@gaisler.com header.b="KRVt+oSw" Received: from localhost (localhost [127.0.0.1]) by smtp.simply.com (Simply.com) with ESMTP id 4fSBh95rdjz1Fljh; Fri, 6 Mar 2026 17:29:45 +0100 (CET) Received: from d-5xj5g74.got.gaisler.com.com (h-98-128-223-123.NA.cust.bahnhof.se [98.128.223.123]) by smtp.simply.com (Simply.com) with ESMTPA id 4fSBh93p7Rz1Fg8v; Fri, 6 Mar 2026 17:29:45 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gaisler.com; s=simplycom2; t=1772814585; bh=IMU/wLjbU6RVE7LY0W7niv61k/USFwtxnDj46IVSkeM=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=KRVt+oSw9PnRdqNE569zq+1jM1e//TMrO54VyqnVfcakUnmSoZ+LUZuSuD7wWOJxh h5j+35jl5M4knvrKJCdHIxQ90Nkadqcx4V1NRfo6y6Hcg/R8wNquIrYia2AS8+VUw8 24thYXBt5Yhc0yeQm8pLt2GZm37PMMVwEiI32B8f1XVtVLJIU0CVbcP5kJ3V+tTZsY MN+MvWV3fv38HHT/HUHTGn1onNXV/ur9XQl1jrZBKQpJSu+BvSKXpraT5LASbQSysR FLAKijQdW7Epn3+RhPAfd2SYmDIujfBKCanMVIpeNEVhE99eYJDD8q0Q75qciNoEOU 3uhyeaWIZtlQw== From: Arun Muthusamy To: robh@kernel.org, krzk+dt@kernel.org, conor+dt@kernel.org, mkl@pengutronix.de, mailhol@kernel.org Cc: devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-can@vger.kernel.org, Daniel Hellstrom , Arun Muthusamy Subject: [PATCH v6 04/15] can: grcan: Add clock handling Date: Fri, 6 Mar 2026 17:29:23 +0100 Message-ID: <20260306162934.22955-5-arun.muthusamy@gaisler.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20260306162934.22955-1-arun.muthusamy@gaisler.com> References: <20260306162934.22955-1-arun.muthusamy@gaisler.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Daniel Hellstrom Add clock handling and add error messages for missing 'freq' DT property. Signed-off-by: Daniel Hellstrom Signed-off-by: Arun Muthusamy --- drivers/net/can/grcan.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/drivers/net/can/grcan.c b/drivers/net/can/grcan.c index 3b1b09943436..f3821e224f4f 100644 --- a/drivers/net/can/grcan.c +++ b/drivers/net/can/grcan.c @@ -34,7 +34,7 @@ #include #include #include - +#include #include =20 #define DRV_NAME "grcan" @@ -1644,6 +1644,7 @@ static int grcan_probe(struct platform_device *ofdev) { struct device_node *np =3D ofdev->dev.of_node; struct device_node *sysid_parent; + struct clk *clk; u32 sysid, ambafreq; int irq, err; void __iomem *base; @@ -1663,8 +1664,19 @@ static int grcan_probe(struct platform_device *ofdev) =20 err =3D of_property_read_u32(np, "freq", &ambafreq); if (err) { - dev_err(&ofdev->dev, "unable to fetch \"freq\" property\n"); - goto exit_error; + clk =3D devm_clk_get(&ofdev->dev, NULL); + if (IS_ERR(clk)) { + dev_err_probe(&ofdev->dev, PTR_ERR(clk), + "Failed both to get \"freq\" property and clock for fallback\n"); + err =3D PTR_ERR(clk); + goto exit_error; + } + + ambafreq =3D clk_get_rate(clk); + if (!ambafreq) { + dev_err(&ofdev->dev, "Invalid or Uninitialized clock\n"); + return -EINVAL; + } } =20 base =3D devm_platform_ioremap_resource(ofdev, 0); --=20 2.51.0 From nobody Fri Apr 3 01:41:56 2026 Received: from smtp-out3.simply.com (smtp-out3.simply.com [94.231.106.210]) (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 BEDCC3F23C3; Fri, 6 Mar 2026 16:29:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=94.231.106.210 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772814604; cv=none; b=EG+sHLrEPi63GB65e+KNLO9seMmBeEvqV6T61oZIRuzU15mkrbcCjJUoHTlvHBDmUezq/BoebCSXMuLFX+LcbXf7SIMX/1fHqgn/neSpBGNV93qtGy7iS2IQUMD1FHXFj70uaItcaHIvsuxwCIQyx3kLcFvxreZXPmhVj5mpqVQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772814604; c=relaxed/simple; bh=TWkjM+UW5DAN4D6Oye0M3JdjP5FNkom4GCXrYZNNyIo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Y9Z34Z34sydfoCDaiSkgeDbH0VgNdr+3jMnjGZDyYsxzR1jHLHdfk0sizTNZ2OM5YV+4oL9XN+DyRuM4EK8cERZPfC84YANqcTCJT9FCxtLMOcrEmXEYg5BZz4q8PaoSnGAiv6oXAMU2PN9gEjEsFYh78U27z8RyfCeLmB/NUAg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gaisler.com; spf=pass smtp.mailfrom=gaisler.com; dkim=fail (0-bit key) header.d=gaisler.com header.i=@gaisler.com header.b=c5b96DyU reason="key not found in DNS"; arc=none smtp.client-ip=94.231.106.210 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gaisler.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gaisler.com Authentication-Results: smtp.subspace.kernel.org; dkim=fail reason="key not found in DNS" (0-bit key) header.d=gaisler.com header.i=@gaisler.com header.b="c5b96DyU" Received: from localhost (localhost [127.0.0.1]) by smtp.simply.com (Simply.com) with ESMTP id 4fSBhB0NFcz1FlZ4; Fri, 6 Mar 2026 17:29:46 +0100 (CET) Received: from d-5xj5g74.got.gaisler.com.com (h-98-128-223-123.NA.cust.bahnhof.se [98.128.223.123]) by smtp.simply.com (Simply.com) with ESMTPA id 4fSBh95XCCz1DDgW; Fri, 6 Mar 2026 17:29:45 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gaisler.com; s=simplycom2; t=1772814585; bh=2u/dURyvkjbBiJ8Nb2RyMQrghcOhEN6vRgEdgLNCLOM=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=c5b96DyUUUccK8NotSzVnPpr2f/1enkVOHjzKeyvXnuhn/ReKVq4r/5OjgTKEOWre Qm7Iyd3XuJfc1FqtUEdIDRh94cCsTYPoUfuKAcV5TlW9FI6MpcYg/UAazvmEMcn7rc fpfZm166qlFii/zH8QJvUotXDmGdPu/qEpqywOJncy2MxXfjqcKzqmRPaCPJihn62a 8K2nCrUE4kGh6QDhwZ4QJ+fCKvjONHfjaMIqL25K3H4bUUclwjcHEOLcaRNh+4w6+i VvDonhYD0ERqQMA70L+wmQfl/RUVrQF3q4xsDKKtMcY4kR22x5SjsSgekigmSgffCT iFIlReeTiCXEQ== From: Arun Muthusamy To: robh@kernel.org, krzk+dt@kernel.org, conor+dt@kernel.org, mkl@pengutronix.de, mailhol@kernel.org Cc: devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-can@vger.kernel.org, Arun Muthusamy , Daniel Hellstrom Subject: [PATCH v6 05/15] can: grcan: Replace bit timing macros with literal values Date: Fri, 6 Mar 2026 17:29:24 +0100 Message-ID: <20260306162934.22955-6-arun.muthusamy@gaisler.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20260306162934.22955-1-arun.muthusamy@gaisler.com> References: <20260306162934.22955-1-arun.muthusamy@gaisler.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Refactor the bit timing constants in grcan_bittiming_const by replacing macros with literal values. Signed-off-by: Daniel Hellstrom Signed-off-by: Arun Muthusamy --- drivers/net/can/grcan.c | 27 +++++++++------------------ 1 file changed, 9 insertions(+), 18 deletions(-) diff --git a/drivers/net/can/grcan.c b/drivers/net/can/grcan.c index f3821e224f4f..12fd4911add2 100644 --- a/drivers/net/can/grcan.c +++ b/drivers/net/can/grcan.c @@ -36,6 +36,7 @@ #include #include #include +#include =20 #define DRV_NAME "grcan" =20 @@ -93,16 +94,6 @@ struct grcan_registers { (GRCAN_CONF_BPR | GRCAN_CONF_RSJ | GRCAN_CONF_PS1 \ | GRCAN_CONF_PS2 | GRCAN_CONF_SCALER) =20 -#define GRCAN_CONF_RSJ_MIN 1 -#define GRCAN_CONF_RSJ_MAX 4 -#define GRCAN_CONF_PS1_MIN 1 -#define GRCAN_CONF_PS1_MAX 15 -#define GRCAN_CONF_PS2_MIN 2 -#define GRCAN_CONF_PS2_MAX 8 -#define GRCAN_CONF_SCALER_MIN 0 -#define GRCAN_CONF_SCALER_MAX 255 -#define GRCAN_CONF_SCALER_INC 1 - #define GRCAN_CONF_BPR_BIT 8 #define GRCAN_CONF_RSJ_BIT 12 #define GRCAN_CONF_PS1_BIT 20 @@ -392,14 +383,14 @@ static struct grcan_device_config grcan_module_config= =3D =20 static const struct can_bittiming_const grcan_bittiming_const =3D { .name =3D DRV_NAME, - .tseg1_min =3D GRCAN_CONF_PS1_MIN + 1, - .tseg1_max =3D GRCAN_CONF_PS1_MAX + 1, - .tseg2_min =3D GRCAN_CONF_PS2_MIN, - .tseg2_max =3D GRCAN_CONF_PS2_MAX, - .sjw_max =3D GRCAN_CONF_RSJ_MAX, - .brp_min =3D GRCAN_CONF_SCALER_MIN + 1, - .brp_max =3D GRCAN_CONF_SCALER_MAX + 1, - .brp_inc =3D GRCAN_CONF_SCALER_INC, + .tseg1_min =3D 2, + .tseg1_max =3D 16, + .tseg2_min =3D 2, + .tseg2_max =3D 8, + .sjw_max =3D 4, + .brp_min =3D 1, + .brp_max =3D 256, + .brp_inc =3D 1, }; =20 static int grcan_set_bittiming(struct net_device *dev) --=20 2.51.0 From nobody Fri Apr 3 01:41:56 2026 Received: from smtp-out3.simply.com (smtp-out3.simply.com [94.231.106.210]) (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 BE9973F23BE; Fri, 6 Mar 2026 16:29:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=94.231.106.210 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772814605; cv=none; b=D17/vCJugX3pWzdrSTQEgl8p+PYHUJbOj1paQme4cLkKOz0yLbuRp6XaVr7R4xP2PNfRqP9pajqPxyO9rCvfWDmdYzQCuvDnXshDC8BEKklOql/SGENBznncAvewl+TOzQxRVGI1de1cbSS6h2YlM/d7q4kzuh6tuNMwppnKfZ8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772814605; c=relaxed/simple; bh=igF+hLU1L5ID9WyNspch4RFhzKl9bZvoNEezH3jqiKM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=fhnczvgbFgzKF1q6sn8nHN2/H7AZ+bNne0HkaURUnGCB3cCydpHCAW8MeMNajk9lhur59YfVDW9CAp4XmYKyLEzoN+2z2hbhGKa0LRW2RauidY8arW+1rB6OCPj5+kSjhlkuFZhFRfozlKoQ8fGfnlUMaxCobjw+tGo52oYauvc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gaisler.com; spf=pass smtp.mailfrom=gaisler.com; dkim=fail (0-bit key) header.d=gaisler.com header.i=@gaisler.com header.b=UXhQEsU5 reason="key not found in DNS"; arc=none smtp.client-ip=94.231.106.210 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gaisler.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gaisler.com Authentication-Results: smtp.subspace.kernel.org; dkim=fail reason="key not found in DNS" (0-bit key) header.d=gaisler.com header.i=@gaisler.com header.b="UXhQEsU5" Received: from localhost (localhost [127.0.0.1]) by smtp.simply.com (Simply.com) with ESMTP id 4fSBhB20X6z1Fg9L; Fri, 6 Mar 2026 17:29:46 +0100 (CET) Received: from d-5xj5g74.got.gaisler.com.com (h-98-128-223-123.NA.cust.bahnhof.se [98.128.223.123]) by smtp.simply.com (Simply.com) with ESMTPA id 4fSBhB08flz1DDTQ; Fri, 6 Mar 2026 17:29:46 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gaisler.com; s=simplycom2; t=1772814586; bh=AWhiK64Qe9+qE4eBamGkQQY/DBTVBN3Vw0RtnG6lRe0=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=UXhQEsU5O2Y378m1559M/zkxS82zt75xGMauvvIMng8dqZvGRwtPbjFDJ8IwMDOMf bU8RJ6fYqR8ivu3X5qR3B8Or+fBB4slcA/qTMxOJdTIM789p5w09fFkEcHBlEL//IF p12FJGv+S0PdaguGKO+nxMq5Ds/ySvnRs91xz9AC6mE/wPRWUvZoDgZ6f/KxoUvCy5 /fzD71tbYTYY/jyVYZ5XxZN2bzpXvXriQdFEEEQR6j3jidcTQ+pNKvlBJgsNkz82Vt t33wnZbrO4HQrUFAh7XHcH2ExC90slw4YVRLEBgCHQ0mivWVmE9pBuHCq/Sich6wju iRcAfgMnCmlUg== From: Arun Muthusamy To: robh@kernel.org, krzk+dt@kernel.org, conor+dt@kernel.org, mkl@pengutronix.de, mailhol@kernel.org Cc: devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-can@vger.kernel.org, Arun Muthusamy , Daniel Hellstrom Subject: [PATCH v6 06/15] can: grcan: Simplify timing configuration Date: Fri, 6 Mar 2026 17:29:25 +0100 Message-ID: <20260306162934.22955-7-arun.muthusamy@gaisler.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20260306162934.22955-1-arun.muthusamy@gaisler.com> References: <20260306162934.22955-1-arun.muthusamy@gaisler.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Remove redundant error checks and use FIELD_PREP for bit timing assignments to simplify the timing configuration Signed-off-by: Daniel Hellstrom Signed-off-by: Arun Muthusamy --- drivers/net/can/grcan.c | 41 +++++++++++++---------------------------- 1 file changed, 13 insertions(+), 28 deletions(-) diff --git a/drivers/net/can/grcan.c b/drivers/net/can/grcan.c index 12fd4911add2..4ed0fb1d70b7 100644 --- a/drivers/net/can/grcan.c +++ b/drivers/net/can/grcan.c @@ -396,41 +396,26 @@ static const struct can_bittiming_const grcan_bittimi= ng_const =3D { static int grcan_set_bittiming(struct net_device *dev) { struct grcan_priv *priv =3D netdev_priv(dev); - struct grcan_registers __iomem *regs =3D priv->regs; - struct can_bittiming *bt =3D &priv->can.bittiming; - u32 timing =3D 0; + struct grcan_registers __iomem *regs; int bpr, rsj, ps1, ps2, scaler; + struct can_bittiming *bt; + u32 timing =3D 0; =20 - /* Should never happen - function will not be called when - * device is up - */ - if (grcan_read_bits(®s->ctrl, GRCAN_CTRL_ENABLE)) - return -EBUSY; + regs =3D priv->regs; + bt =3D &priv->can.bittiming; =20 bpr =3D 0; /* Note bpr and brp are different concepts */ rsj =3D bt->sjw; ps1 =3D (bt->prop_seg + bt->phase_seg1) - 1; /* tseg1 - 1 */ ps2 =3D bt->phase_seg2; - scaler =3D (bt->brp - 1); - netdev_dbg(dev, "Request for BPR=3D%d, RSJ=3D%d, PS1=3D%d, PS2=3D%d, SCAL= ER=3D%d", - bpr, rsj, ps1, ps2, scaler); - if (!(ps1 > ps2)) { - netdev_err(dev, "PS1 > PS2 must hold: PS1=3D%d, PS2=3D%d\n", - ps1, ps2); - return -EINVAL; - } - if (!(ps2 >=3D rsj)) { - netdev_err(dev, "PS2 >=3D RSJ must hold: PS2=3D%d, RSJ=3D%d\n", - ps2, rsj); - return -EINVAL; - } - - timing |=3D (bpr << GRCAN_CONF_BPR_BIT) & GRCAN_CONF_BPR; - timing |=3D (rsj << GRCAN_CONF_RSJ_BIT) & GRCAN_CONF_RSJ; - timing |=3D (ps1 << GRCAN_CONF_PS1_BIT) & GRCAN_CONF_PS1; - timing |=3D (ps2 << GRCAN_CONF_PS2_BIT) & GRCAN_CONF_PS2; - timing |=3D (scaler << GRCAN_CONF_SCALER_BIT) & GRCAN_CONF_SCALER; - netdev_info(dev, "setting timing=3D0x%x\n", timing); + scaler =3D bt->brp - 1; + + timing |=3D FIELD_PREP(GRCAN_CONF_BPR, bpr); + timing |=3D FIELD_PREP(GRCAN_CONF_RSJ, rsj); + timing |=3D FIELD_PREP(GRCAN_CONF_PS1, ps1); + timing |=3D FIELD_PREP(GRCAN_CONF_PS2, ps2); + timing |=3D FIELD_PREP(GRCAN_CONF_SCALER, scaler); + netdev_dbg(dev, "setting timing=3D0x%x\n", timing); grcan_write_bits(®s->conf, timing, GRCAN_CONF_TIMING); =20 return 0; --=20 2.51.0 From nobody Fri Apr 3 01:41:56 2026 Received: from smtp-out3.simply.com (smtp-out3.simply.com [94.231.106.210]) (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 BEADC3F23C2; Fri, 6 Mar 2026 16:29:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=94.231.106.210 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772814606; cv=none; b=dY4IiSm41PTd8meCqqulEaF8BdVcUmlSROtC+ww97UrTsUQB6oLAYMS5bCadsjIPtdh3+QZSWUYmWnPe4Vy0YfB0wKKSUTGoKQK4XluzeaO2gzBiZ/nwrwNKyMruc4noUseh1HE9zGZxmD+E9kgwFGYB7mYwXkWlCNkXwKYYNmc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772814606; c=relaxed/simple; bh=YaHvvfEb88Vi1js3h+ePVjEeBl6EZNzpudqoWSjoSiE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=WxlI6Z55Ar1MpjkW//OSx3l38nQfGDtSHyIebCyinVm3XgUeNRI8VRXqO2u8VFYZ47B9itmKx2uqHkqXuUDdb7ZA7SWK0btEB8mr4nik6FZWhkgUdBflq3g9d5UWU3eI9TF/RMWoaZ8Arcv8ioEz5eQDEQdWOIbAzX+Vfnlv9qg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gaisler.com; spf=pass smtp.mailfrom=gaisler.com; dkim=fail (0-bit key) header.d=gaisler.com header.i=@gaisler.com header.b=Sij77XRk reason="key not found in DNS"; arc=none smtp.client-ip=94.231.106.210 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gaisler.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gaisler.com Authentication-Results: smtp.subspace.kernel.org; dkim=fail reason="key not found in DNS" (0-bit key) header.d=gaisler.com header.i=@gaisler.com header.b="Sij77XRk" Received: from localhost (localhost [127.0.0.1]) by smtp.simply.com (Simply.com) with ESMTP id 4fSBhB3fhkz1Fg8v; Fri, 6 Mar 2026 17:29:46 +0100 (CET) Received: from d-5xj5g74.got.gaisler.com.com (h-98-128-223-123.NA.cust.bahnhof.se [98.128.223.123]) by smtp.simply.com (Simply.com) with ESMTPA id 4fSBhB1nT6z1DDgW; Fri, 6 Mar 2026 17:29:46 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gaisler.com; s=simplycom2; t=1772814586; bh=OaTLEI+yc4RYqeiJU7jtLMAv7/4/hDPDhIWDCpBmibQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=Sij77XRk5fVBUoMTr+Tff4uBnoK4Drarzw4avkU0MenDEWSZ5PSvOlg/kMP89XPAp 6t4QbepwlwLGCCC8urK+uDHz3gF1NNOZ2qfFASrbDN0Tj+jPfCeSpiKTTLVtuwW0Nj JaA5Ks+2S4jlLlON5CddDosbBe9GeoYI2jeCJ3HXy0IS1ee3TpIe/uO4obBpnh/D+0 OaQCqfEsj3p15aeqg012QYtNb/KF6/SKiRlxyj7W7ZjDq3m/OW4UpX7nHVGeu3sAT8 m77zvlW3kcreYQdlk1TSRQRUy0TgTc6X+yGBgwTx6REt7qA/X3tAB1I+j64hg94Uxr QS9kKUyVHh+Ew== From: Arun Muthusamy To: robh@kernel.org, krzk+dt@kernel.org, conor+dt@kernel.org, mkl@pengutronix.de, mailhol@kernel.org Cc: devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-can@vger.kernel.org, Arun Muthusamy , Daniel Hellstrom Subject: [PATCH v6 07/15] can: grcan: add FD capability detection and nominal bit-timing Date: Fri, 6 Mar 2026 17:29:26 +0100 Message-ID: <20260306162934.22955-8-arun.muthusamy@gaisler.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20260306162934.22955-1-arun.muthusamy@gaisler.com> References: <20260306162934.22955-1-arun.muthusamy@gaisler.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add capability for the driver to detect CAN FD support and adjust accordingly. Introduce structures and functions for setting nominal bit-timing for standard CAN FD. The `grcan_hwcap` structure defines hardware capabilities like CAN FD support and baud-rate options. Additionally, improved device tree compatibility by updating the `of_device_id` table for better matching of GRCAN and GRCANFD devices. Also update Kconfig to mention GRCANFD support. Signed-off-by: Daniel Hellstrom Signed-off-by: Arun Muthusamy --- drivers/net/can/Kconfig | 6 +- drivers/net/can/grcan.c | 137 +++++++++++++++++++++++++++++++++++----- 2 files changed, 125 insertions(+), 18 deletions(-) diff --git a/drivers/net/can/Kconfig b/drivers/net/can/Kconfig index d43d56694667..96f61b40a898 100644 --- a/drivers/net/can/Kconfig +++ b/drivers/net/can/Kconfig @@ -133,10 +133,12 @@ config CAN_FLEXCAN Say Y here if you want to support for Freescale FlexCAN. =20 config CAN_GRCAN - tristate "Aeroflex Gaisler GRCAN and GRHCAN CAN devices" + tristate "Aeroflex Gaisler GRCAN(FD) and GRHCAN CAN devices" depends on OF && HAS_DMA && HAS_IOMEM help - Say Y here if you want to use Aeroflex Gaisler GRCAN or GRHCAN. + Say Y here if you want to use Aeroflex Gaisler GRCAN or GRCANFD + or GRHCAN. + Note that the driver supports little endian, even though little endian syntheses of the cores would need some modifications on the hardware level to work. diff --git a/drivers/net/can/grcan.c b/drivers/net/can/grcan.c index 4ed0fb1d70b7..a752aea51d96 100644 --- a/drivers/net/can/grcan.c +++ b/drivers/net/can/grcan.c @@ -33,6 +33,7 @@ #include #include #include +#include #include #include #include @@ -51,7 +52,11 @@ struct grcan_registers { u32 __reserved1[GRCAN_RESERVE_SIZE(0x08, 0x18)]; u32 smask; /* 0x18 - CanMASK */ u32 scode; /* 0x1c - CanCODE */ - u32 __reserved2[GRCAN_RESERVE_SIZE(0x1c, 0x100)]; + u32 __reserved2[GRCAN_RESERVE_SIZE(0x1c, 0x40)]; + u32 nbtr; /* 0x40 */ + u32 fdbtr; /* 0x44 */ + u32 tdelay; /* 0x48 */ + u32 __reserved2_[GRCAN_RESERVE_SIZE(0x48, 0x100)]; u32 pimsr; /* 0x100 */ u32 pimr; /* 0x104 */ u32 pisr; /* 0x108 */ @@ -203,6 +208,39 @@ struct grcan_registers { #error "Invalid default buffer size" #endif =20 +#define GRCANFD_NBTR_SCALER GENMASK(23, 16) +#define GRCANFD_NBTR_PS1 GENMASK(17, 10) +#define GRCANFD_NBTR_PS2 GENMASK(9, 5) +#define GRCANFD_NBTR_SJW GENMASK(4, 0) +#define GRCANFD_NBTR_TIMING \ + (GRCANFD_NBTR_SCALER | GRCANFD_NBTR_PS1 | GRCANFD_NBTR_PS2 | \ + GRCANFD_NBTR_SJW) + +#define GRCANFD_FDBTR_SCALER 0x00ff0000 +#define GRCANFD_FDBTR_PS1 0x00003c00 +#define GRCANFD_FDBTR_PS2 0x000001e0 +#define GRCANFD_FDBTR_SJW 0x0000000f +#define GRCANFD_FDBTR_TIMING \ + (GRCANFD_FDBTR_SCALER | GRCANFD_FDBTR_PS1 | GRCANFD_FDBTR_PS2 | \ + GRCANFD_FDBTR_SJW) + +#define GRCANFD_FDBTR_SCALER_BIT 16 +#define GRCANFD_FDBTR_PS1_BIT 10 +#define GRCANFD_FDBTR_PS2_BIT 5 +#define GRCANFD_FDBTR_SJW_BIT 0 + +/* Hardware capabilities */ +struct grcan_hwcap { + /* CAN-FD capable, indicates GRCANFD IP. + * The GRCANFD has different baud-rate registers and extended DMA + * format to also describe FD-frames. + */ + const struct can_bittiming_const *bt_const; + int (*set_bittiming)(struct net_device *dev); + bool txbug_possible; + bool fd; +}; + struct grcan_dma_buffer { size_t size; void *buf; @@ -245,6 +283,7 @@ struct grcan_priv { struct napi_struct napi; =20 struct grcan_registers __iomem *regs; /* ioremap'ed registers */ + const struct grcan_hwcap *hwcap; struct grcan_device_config config; struct grcan_dma dma; =20 @@ -393,6 +432,19 @@ static const struct can_bittiming_const grcan_bittimin= g_const =3D { .brp_inc =3D 1, }; =20 +/* GRCANFD nominal boundaries for baud-rate parameters */ +static const struct can_bittiming_const grcanfd_bittiming_const =3D { + .name =3D DRV_NAME, + .tseg1_min =3D 2, + .tseg1_max =3D 63, + .tseg2_min =3D 2, + .tseg2_max =3D 16, + .sjw_max =3D 16, + .brp_min =3D 1, + .brp_max =3D 256, + .brp_inc =3D 1, +}; + static int grcan_set_bittiming(struct net_device *dev) { struct grcan_priv *priv =3D netdev_priv(dev); @@ -421,6 +473,32 @@ static int grcan_set_bittiming(struct net_device *dev) return 0; } =20 +static int grcanfd_set_bittiming(struct net_device *dev) +{ + struct grcan_priv *priv =3D netdev_priv(dev); + struct grcan_registers __iomem *regs; + int sjw, ps1, ps2, scaler; + struct can_bittiming *bt; + u32 timing =3D 0; + + regs =3D priv->regs; + bt =3D &priv->can.bittiming; + + sjw =3D bt->sjw; + ps1 =3D (bt->prop_seg + bt->phase_seg1); + ps2 =3D bt->phase_seg2; + scaler =3D bt->brp - 1; + + timing |=3D FIELD_PREP(GRCANFD_NBTR_SJW, sjw); + timing |=3D FIELD_PREP(GRCANFD_NBTR_PS1, ps1); + timing |=3D FIELD_PREP(GRCANFD_NBTR_PS2, ps2); + timing |=3D FIELD_PREP(GRCANFD_NBTR_SCALER, scaler); + netdev_dbg(dev, "setting timing=3D0x%x\n", timing); + grcan_write_bits(®s->nbtr, timing, GRCANFD_NBTR_TIMING); + + return 0; +} + static int grcan_get_berr_counter(const struct net_device *dev, struct can_berr_counter *bec) { @@ -1545,7 +1623,8 @@ static const struct ethtool_ops grcan_ethtool_ops =3D= { =20 static int grcan_setup_netdev(struct platform_device *ofdev, void __iomem *base, - int irq, u32 ambafreq, bool txbug) + int irq, u32 ambafreq, bool txbug, + const struct grcan_hwcap *hwcap) { struct net_device *dev; struct grcan_priv *priv; @@ -1568,14 +1647,14 @@ static int grcan_setup_netdev(struct platform_devic= e *ofdev, priv->dev =3D dev; priv->ofdev_dev =3D &ofdev->dev; priv->regs =3D base; - priv->can.bittiming_const =3D &grcan_bittiming_const; - priv->can.do_set_bittiming =3D grcan_set_bittiming; + priv->can.bittiming_const =3D hwcap->bt_const; priv->can.do_set_mode =3D grcan_set_mode; priv->can.do_get_berr_counter =3D grcan_get_berr_counter; priv->can.clock.freq =3D ambafreq; priv->can.ctrlmode_supported =3D CAN_CTRLMODE_LISTENONLY | CAN_CTRLMODE_ONE_SHOT; priv->need_txbug_workaround =3D txbug; + priv->hwcap =3D hwcap; =20 /* Discover if triple sampling is supported by hardware */ regs =3D priv->regs; @@ -1620,22 +1699,29 @@ static int grcan_probe(struct platform_device *ofde= v) { struct device_node *np =3D ofdev->dev.of_node; struct device_node *sysid_parent; + const struct grcan_hwcap *hwcap; struct clk *clk; u32 sysid, ambafreq; int irq, err; void __iomem *base; bool txbug =3D true; =20 + hwcap =3D device_get_match_data(&ofdev->dev); + /* Compare GRLIB version number with the first that does not * have the tx bug (see start_xmit) */ - sysid_parent =3D of_find_node_by_path("/ambapp0"); - if (sysid_parent) { - err =3D of_property_read_u32(sysid_parent, "systemid", &sysid); - if (!err && ((sysid & GRLIB_VERSION_MASK) >=3D - GRCAN_TXBUG_SAFE_GRLIB_VERSION)) - txbug =3D false; - of_node_put(sysid_parent); + if (!hwcap->txbug_possible) { + txbug =3D false; + } else { + sysid_parent =3D of_find_node_by_path("/ambapp0"); + if (sysid_parent) { + err =3D of_property_read_u32(sysid_parent, "systemid", &sysid); + if (!err && ((sysid & GRLIB_VERSION_MASK) >=3D + GRCAN_TXBUG_SAFE_GRLIB_VERSION)) + txbug =3D false; + of_node_put(sysid_parent); + } } =20 err =3D of_property_read_u32(np, "freq", &ambafreq); @@ -1670,7 +1756,7 @@ static int grcan_probe(struct platform_device *ofdev) =20 grcan_sanitize_module_config(ofdev); =20 - err =3D grcan_setup_netdev(ofdev, base, irq, ambafreq, txbug); + err =3D grcan_setup_netdev(ofdev, base, irq, ambafreq, txbug, hwcap); if (err) goto exit_dispose_irq; =20 @@ -1697,11 +1783,30 @@ static void grcan_remove(struct platform_device *of= dev) free_candev(dev); } =20 +static const struct grcan_hwcap grcan_hwcap =3D { + .fd =3D false, + .txbug_possible =3D true, + .bt_const =3D &grcan_bittiming_const, + .set_bittiming =3D grcan_set_bittiming, +}; + +static const struct grcan_hwcap grcanfd_hwcap =3D { + .fd =3D true, + .txbug_possible =3D false, + .bt_const =3D &grcanfd_bittiming_const, + .set_bittiming =3D grcanfd_set_bittiming, +}; + static const struct of_device_id grcan_match[] =3D { - {.name =3D "GAISLER_GRCAN"}, - {.name =3D "01_03d"}, - {.name =3D "GAISLER_GRHCAN"}, - {.name =3D "01_034"}, + {.name =3D "GAISLER_GRCAN", .data =3D &grcan_hwcap}, + {.name =3D "01_03d", .data =3D &grcan_hwcap}, + {.name =3D "GAISLER_GRHCAN", .data =3D &grcan_hwcap}, + {.name =3D "01_034", .data =3D &grcan_hwcap}, + {.compatible =3D "gaisler,grcan", .data =3D &grcan_hwcap}, + /* GRCANFD */ + {.compatible =3D "gaisler,grcanfd", .data =3D &grcanfd_hwcap}, + {.name =3D "GAISLER_GRCANFD", .data =3D &grcanfd_hwcap}, + {.name =3D "01_0b5", .data =3D &grcanfd_hwcap}, {}, }; =20 --=20 2.51.0 From nobody Fri Apr 3 01:41:56 2026 Received: from smtp-out3.simply.com (smtp-out3.simply.com [94.231.106.210]) (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 BEEF23F23C5; Fri, 6 Mar 2026 16:29:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=94.231.106.210 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772814605; cv=none; b=B8s18jlceYE1hdqtHfx8AClVp4LecredzMOAImRXNtsFnQqSvH9oPr0la0xrR3l0VEmsQefs22zexa8zHwwTTaTJWFiHeazNEtdLT34k4aKXrgwECe6OQ0NH6wT3ERANyDqrE3D9b963rWv/aOVVJmfH4r9xum5CxSjRF4wo4xo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772814605; c=relaxed/simple; bh=sBPLttc71DWTT/X+2aWt8iCWd65cG/MxNoG6shfvVaE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=AJBR//vS9Dsn1KwloGj1UvbX//oESxOW6yyT74tTI0C4sg162/2PFFOgsWOqYyDROjL+g1LelN26q9aNqRLttshlg1footBwalhp/giE53oz+RwPjcbt+/XJJ2H8a+weIpyKRCa+8qKN3yzDlzPf8HEg+UiT7bEc4wPsxvzvF+A= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gaisler.com; spf=pass smtp.mailfrom=gaisler.com; dkim=fail (0-bit key) header.d=gaisler.com header.i=@gaisler.com header.b=LyYW5O84 reason="key not found in DNS"; arc=none smtp.client-ip=94.231.106.210 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gaisler.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gaisler.com Authentication-Results: smtp.subspace.kernel.org; dkim=fail reason="key not found in DNS" (0-bit key) header.d=gaisler.com header.i=@gaisler.com header.b="LyYW5O84" Received: from localhost (localhost [127.0.0.1]) by smtp.simply.com (Simply.com) with ESMTP id 4fSBhB5hzVz1Fljj; Fri, 6 Mar 2026 17:29:46 +0100 (CET) Received: from d-5xj5g74.got.gaisler.com.com (h-98-128-223-123.NA.cust.bahnhof.se [98.128.223.123]) by smtp.simply.com (Simply.com) with ESMTPA id 4fSBhB3RLZz1DDTY; Fri, 6 Mar 2026 17:29:46 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gaisler.com; s=simplycom2; t=1772814586; bh=07n+7rUUHQB31+eXavT4VzVjngd4Ef6mCnRynH3s4pw=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=LyYW5O84S2eycTn8c2Lrre/JPrqz/cZQoCy2290WEfPqr6e5P4meMVSf9nPjW/3KA laDOojphrnw5i1pXR63dcUT8JZe5NdOgwMbX1BeJoVQxDLh7pAJ5w4gV70G7ldYk5q hLb8ref0y3/kpfWEliGCBvw8cSECa6zFLqtDSyvEXE4hEVbDRHF2nWJC78DYzuLbCz cUFTLWAdFv93UCx584LAh5BcUZTz1UgBaQiyNbyF/lptNYLNkRQvSD8mbKTBHnmFXe NbWz66bU8wTY8MrcyGkf43I5WzkCx6eTsG8/E1vZoe9dtmhvvdDak8YqcVzv4zYCwY yhxB/YAAdA8dg== From: Arun Muthusamy To: robh@kernel.org, krzk+dt@kernel.org, conor+dt@kernel.org, mkl@pengutronix.de, mailhol@kernel.org Cc: devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-can@vger.kernel.org, Daniel Hellstrom , Arun Muthusamy Subject: [PATCH v6 08/15] can: grcan: set DMA mask for GRCAN and GRCANFD to 32-bit Date: Fri, 6 Mar 2026 17:29:27 +0100 Message-ID: <20260306162934.22955-9-arun.muthusamy@gaisler.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20260306162934.22955-1-arun.muthusamy@gaisler.com> References: <20260306162934.22955-1-arun.muthusamy@gaisler.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Daniel Hellstrom Sets the DMA mask for GRCAN and GRCANFD devices to 32-bit. Setting the DMA mask and coherent DMA mask to 32-bit ensures proper memory addressing during DMA operations Signed-off-by: Daniel Hellstrom Signed-off-by: Arun Muthusamy --- drivers/net/can/grcan.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/drivers/net/can/grcan.c b/drivers/net/can/grcan.c index a752aea51d96..74caedbcd55d 100644 --- a/drivers/net/can/grcan.c +++ b/drivers/net/can/grcan.c @@ -1747,6 +1747,13 @@ static int grcan_probe(struct platform_device *ofdev) goto exit_error; } =20 + /* On 64-bit systems.. GRCAN and GRCANFD can only address 32-bit */ + err =3D dma_set_mask_and_coherent(&ofdev->dev, DMA_BIT_MASK(32)); + if (err) { + dev_err_probe(&ofdev->dev, err, "No usable DMA configuration.\n"); + goto exit_error; + } + irq =3D irq_of_parse_and_map(np, GRCAN_IRQIX_IRQ); if (!irq) { dev_err(&ofdev->dev, "no irq found\n"); --=20 2.51.0 From nobody Fri Apr 3 01:41:56 2026 Received: from smtp-out3.simply.com (smtp-out3.simply.com [94.231.106.210]) (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 EC35D3F23D8; Fri, 6 Mar 2026 16:29:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=94.231.106.210 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772814605; cv=none; b=CfJgJnuZIhMxBurOKeQLaI6G5x95nV60Gp5+WL7aiDPC7w48IITyC0qkyiO9Ktri5aZhgeY/PPmfE/5wX37l+k0u1vdpzSHorNo7AVfDbv5/jQkNwIhLMmVdpy2sEVCkNkKYBVoyKFWsWMjMKhESjYlFusejAjCBhncZai67G3Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772814605; c=relaxed/simple; bh=jxTYQKjJc9VfAgRwg/nZ6qy1YUH+cw2WrnuOXz10Qug=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=OwgKgWZoyPnVh+TUE5RtBHTBLFFn8xIZ/MyFtvSYt/NhSikKk1ALhpjyyxZNaktJEAUf/vpsImV1N/Dl/X2/bfiGvQ84T+aWe1Ceaa5mSAobtJ1T9aBqZfvzLdD6kuIkUPd+l0T+bZ/TimgmzQMbV7TNEGFUsyvu1gD7Ug9VybU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gaisler.com; spf=pass smtp.mailfrom=gaisler.com; dkim=fail (0-bit key) header.d=gaisler.com header.i=@gaisler.com header.b=j1PEuuWW reason="key not found in DNS"; arc=none smtp.client-ip=94.231.106.210 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gaisler.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gaisler.com Authentication-Results: smtp.subspace.kernel.org; dkim=fail reason="key not found in DNS" (0-bit key) header.d=gaisler.com header.i=@gaisler.com header.b="j1PEuuWW" Received: from localhost (localhost [127.0.0.1]) by smtp.simply.com (Simply.com) with ESMTP id 4fSBhC0PVrz1DDRx; Fri, 6 Mar 2026 17:29:47 +0100 (CET) Received: from d-5xj5g74.got.gaisler.com.com (h-98-128-223-123.NA.cust.bahnhof.se [98.128.223.123]) by smtp.simply.com (Simply.com) with ESMTPA id 4fSBhB5PTTz1DDTQ; Fri, 6 Mar 2026 17:29:46 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gaisler.com; s=simplycom2; t=1772814586; bh=2H9zcDHFJZTqODlTnjEqtv89BRBVUKCoeaXN9y9asDE=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=j1PEuuWWnCCmWZJt7vXoj83rqBAe6C5KY/f/W/hQH/hVYsZnYAvASSFMbEcaW23bN XreFZwv3rxxoU4orGPiM9Zu28G2CxHI15nPI3dfcxA4pVws8/NqvrkwKKmUihweQ0q GncKITFLSLnw3ZDhGu0YqlLnz/z2SiJfYihoL+40tyFmqQQbRU8szWfdr5IrgXVqo3 QTqc2lGbmPx94XMirlJzKGZ6z/Jb9fqD/5e6IaG1xIMwb8E5Muty+PGeNY7UYGyHnq 8CKRnLiUmSFo0I16GzYbWbnzEze3pWKaKJ7XUNgTiS3lWaQPA8a9QyENnijK0/IUFm 74w8W/4348k8Q== From: Arun Muthusamy To: robh@kernel.org, krzk+dt@kernel.org, conor+dt@kernel.org, mkl@pengutronix.de, mailhol@kernel.org Cc: devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-can@vger.kernel.org, Daniel Hellstrom , Arun Muthusamy Subject: [PATCH v6 09/15] can: grcan: Add saving and restoring of CAN FD baud-rate registers Date: Fri, 6 Mar 2026 17:29:28 +0100 Message-ID: <20260306162934.22955-10-arun.muthusamy@gaisler.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20260306162934.22955-1-arun.muthusamy@gaisler.com> References: <20260306162934.22955-1-arun.muthusamy@gaisler.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Daniel Hellstrom While reset the GRCAN baud-rates are preserved, since GRCANFD has the baud-rate in different registers we need to add saving of those registers too. Signed-off-by: Daniel Hellstrom Signed-off-by: Arun Muthusamy --- drivers/net/can/grcan.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/net/can/grcan.c b/drivers/net/can/grcan.c index 74caedbcd55d..1cfc8d90573a 100644 --- a/drivers/net/can/grcan.c +++ b/drivers/net/can/grcan.c @@ -528,6 +528,8 @@ static void grcan_reset(struct net_device *dev) =20 /* Turn off hardware filtering - regs->rxcode set to 0 by reset */ grcan_write_reg(®s->rxmask, 0); + + priv->hwcap->set_bittiming(dev); } =20 /* stop device without changing any configurations */ --=20 2.51.0 From nobody Fri Apr 3 01:41:56 2026 Received: from smtp-out3.simply.com (smtp-out3.simply.com [94.231.106.210]) (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 185503EDABC; Fri, 6 Mar 2026 16:30:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=94.231.106.210 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772814605; cv=none; b=rd80q0EUndPgoROO7Va7eKH6bidkRJ8ErQXCOAc8z06TPbrkC3i61kOQ3xviu+UxYWF/0fQOAKgDTWnLHkijytBvNmn7tCi5PDKvrAnPLVbC4tndnTkBtLQShS7fB1a5kF8t13gyTk/7j6YWgwMr/rJhF4ln8AbuIR5hmyp+DsI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772814605; c=relaxed/simple; bh=ajVC59DpGQnhF76fmIDA30+THs0hk+AI3phoAt+fkp0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=FKizlftvNhe7aS0zn7q+rxTxEID/M4bpjCTTRy0GkZ1oCbhR1mCK2HvlvBT7VYRuxdzSCF/6eVb3xPDTj32aX3SmYt1GzSkM4J99EuDJRs/a9mRncVFT54ZN/5J9grXU1yaYxarP/7ZvvuyRBSr7JLJbQeD1oNVUSKSxjJcBugg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gaisler.com; spf=pass smtp.mailfrom=gaisler.com; dkim=fail (0-bit key) header.d=gaisler.com header.i=@gaisler.com header.b=A4IsRJ1r reason="key not found in DNS"; arc=none smtp.client-ip=94.231.106.210 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gaisler.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gaisler.com Authentication-Results: smtp.subspace.kernel.org; dkim=fail reason="key not found in DNS" (0-bit key) header.d=gaisler.com header.i=@gaisler.com header.b="A4IsRJ1r" Received: from localhost (localhost [127.0.0.1]) by smtp.simply.com (Simply.com) with ESMTP id 4fSBhC2Jjcz1Fljk; Fri, 6 Mar 2026 17:29:47 +0100 (CET) Received: from d-5xj5g74.got.gaisler.com.com (h-98-128-223-123.NA.cust.bahnhof.se [98.128.223.123]) by smtp.simply.com (Simply.com) with ESMTPA id 4fSBhC0CGZz1DDgW; Fri, 6 Mar 2026 17:29:47 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gaisler.com; s=simplycom2; t=1772814587; bh=upU4u1eJLfMz8n7CUAHXsVmudBTZqYBIgYsKLTy7nOI=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=A4IsRJ1rmCikNr1GeVaBfh0K7JcL2/esjolNiAfxP/pYY5R+srBFRa5kQkX+ZC+i5 NFsbwcuHC5zQsv0S8uHKfoEqmc2L7+tdg0d/mhDmBsDsaO9rbErMK8ZO4A/H5MRJSJ ISv/bll7O8Qn0kQwz6eVrPK2CV9BFcnxJJ+gtBIGKxC3aU4qE4bNt6mr1ChepRCdkB piwUIqtYinlTZ98xUdBcuVw+zHQ5fioemE5Z7RdS+oCkz4ZXwIt/IPMzuXwGKHU+j4 /EaWgOIG0n3oFkpputTex10ixAeux9o/PFuVzan3u1BmE0ufwJWE2y+0IQpwjoHShE j3RlKtsDT98iw== From: Arun Muthusamy To: robh@kernel.org, krzk+dt@kernel.org, conor+dt@kernel.org, mkl@pengutronix.de, mailhol@kernel.org Cc: devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-can@vger.kernel.org, Daniel Hellstrom , Arun Muthusamy Subject: [PATCH v6 10/15] can: grcan: Reserve space between cap and next register to align with address layout Date: Fri, 6 Mar 2026 17:29:29 +0100 Message-ID: <20260306162934.22955-11-arun.muthusamy@gaisler.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20260306162934.22955-1-arun.muthusamy@gaisler.com> References: <20260306162934.22955-1-arun.muthusamy@gaisler.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Daniel Hellstrom Reserves space between the capability register and the next register within the GRCAN driver to align with the hardware address layout. Signed-off-by: Daniel Hellstrom Signed-off-by: Arun Muthusamy --- drivers/net/can/grcan.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/net/can/grcan.c b/drivers/net/can/grcan.c index 1cfc8d90573a..b51b4235b1e7 100644 --- a/drivers/net/can/grcan.c +++ b/drivers/net/can/grcan.c @@ -49,7 +49,8 @@ struct grcan_registers { u32 conf; /* 0x00 */ u32 stat; /* 0x04 */ u32 ctrl; /* 0x08 */ - u32 __reserved1[GRCAN_RESERVE_SIZE(0x08, 0x18)]; + u32 cap; /* 0x0c */ + u32 __reserved1[GRCAN_RESERVE_SIZE(0x0c, 0x18)]; u32 smask; /* 0x18 - CanMASK */ u32 scode; /* 0x1c - CanCODE */ u32 __reserved2[GRCAN_RESERVE_SIZE(0x1c, 0x40)]; --=20 2.51.0 From nobody Fri Apr 3 01:41:56 2026 Received: from smtp-out3.simply.com (smtp-out3.simply.com [94.231.106.210]) (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 0A8B93E95B0; Fri, 6 Mar 2026 16:30:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=94.231.106.210 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772814614; cv=none; b=Nkvls5Oqdmw+8mqpCZ6A0bGKxYrnGDyQ9ZTB7Fvo5qvcSfVFYpbOwlqj+g0WQQ3beDasuaBPe5hEhdFKQ0zqr9QTbRKe6wRBqmfVPI/k9mGuxhZJDLL5cr2ll2hAtkrbQPwx//x071qP+l6Arh3dy/oOCKGzAjVen9E0uGTQcVY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772814614; c=relaxed/simple; bh=40O6WxzzWA+JBIi1GLuYIywzZsPzqJ13r/levFHuB84=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=HF6rdHZT5wYlZOFSRAv/V8FjPHXanXcFsImOdczoGKoXFW0bEZGUjvT/8bA8pupwK73SYwhnALZNhT3zLzuu/CY1yGMNuK5R1scmoPTFnD/GYNID3ua16vSIaepEAzNjNq5WP1oNW/l6e8H6rnRd4C5XB3IlU8IC8bAK1x5hTe8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gaisler.com; spf=pass smtp.mailfrom=gaisler.com; dkim=fail (0-bit key) header.d=gaisler.com header.i=@gaisler.com header.b=akVFI84U reason="key not found in DNS"; arc=none smtp.client-ip=94.231.106.210 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gaisler.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gaisler.com Authentication-Results: smtp.subspace.kernel.org; dkim=fail reason="key not found in DNS" (0-bit key) header.d=gaisler.com header.i=@gaisler.com header.b="akVFI84U" Received: from localhost (localhost [127.0.0.1]) by smtp.simply.com (Simply.com) with ESMTP id 4fSBhC3pS2z1Fg8H; Fri, 6 Mar 2026 17:29:47 +0100 (CET) Received: from d-5xj5g74.got.gaisler.com.com (h-98-128-223-123.NA.cust.bahnhof.se [98.128.223.123]) by smtp.simply.com (Simply.com) with ESMTPA id 4fSBhC25h2z1DDTQ; Fri, 6 Mar 2026 17:29:47 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gaisler.com; s=simplycom2; t=1772814587; bh=GAJVvOQ/6Tk3aH1n5JHBwlQ4JF3J7rjYi4rRc0KzJtM=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=akVFI84UeIhSdlCSuXccvbDYMU5LQBmWdRyK5v3LjKGOxIRw3iiz505uRcCdor6Mw dAjbCPk4TPCFRx2KlnWtRHVpaVZCbUl6nqUKMRJtuErVefX/6/RBylWAEoy0TU4N6b smH3XIMFeEP4EpW9Prs6TC/2ekPpGmrLm/JjrETdh48bJouBowop3jHMEbSHM65rtm lp5dIJQHhdZQoPifL5fp/ugTeZmzF0KcGe3j7y/WQFH8GHcUlbX6kUmLXNPOLDePGf 5GZWzcCYh7djf1aV0cWFbrBEtRa90BH1yHL3YI8I2D47DS1AITCc7OpZasE4ow1VPe AkmDoaVSmTprw== From: Arun Muthusamy To: robh@kernel.org, krzk+dt@kernel.org, conor+dt@kernel.org, mkl@pengutronix.de, mailhol@kernel.org Cc: devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-can@vger.kernel.org, Arun Muthusamy Subject: [PATCH v6 11/15] can: grcan: Refactor GRCAN DMA buffer to use structured memory layout Date: Fri, 6 Mar 2026 17:29:30 +0100 Message-ID: <20260306162934.22955-12-arun.muthusamy@gaisler.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20260306162934.22955-1-arun.muthusamy@gaisler.com> References: <20260306162934.22955-1-arun.muthusamy@gaisler.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" - Introduce a structured layout to represent hardware memory using struct grcan_msg_header and struct grcan_msg_fragment. - Updated the GRCAN receive and transmit functions to utilize this new stru= ctured approach. - Implemented helper functions grcan_msg_header_at for accessing header str= uctures within DMA buffers. - Replaced array and bitwise operations with memcpy for copying between CAN= frames and header structures. Signed-off-by: Arun Muthusamy --- drivers/net/can/grcan.c | 80 +++++++++++++++++++++++++---------------- 1 file changed, 49 insertions(+), 31 deletions(-) diff --git a/drivers/net/can/grcan.c b/drivers/net/can/grcan.c index b51b4235b1e7..4c56861e21d7 100644 --- a/drivers/net/can/grcan.c +++ b/drivers/net/can/grcan.c @@ -195,9 +195,6 @@ struct grcan_registers { #define GRCAN_MSG_OFF 0x00000002 #define GRCAN_MSG_PASS 0x00000001 =20 -#define GRCAN_MSG_DATA_SLOT_INDEX(i) (2 + (i) / 4) -#define GRCAN_MSG_DATA_SHIFT(i) ((3 - (i) % 4) * 8) - #define GRCAN_BUFFER_ALIGNMENT 1024 #define GRCAN_DEFAULT_BUFFER_SIZE 1024 #define GRCAN_VALID_TR_SIZE_MASK 0x001fffc0 @@ -242,9 +239,23 @@ struct grcan_hwcap { bool fd; }; =20 +struct grcan_msg_header { + u32 id; + u32 ctrl; + u8 data[CAN_MAX_DLEN]; +} __packed; + +struct grcan_msg_fragment { + u8 data[GRCAN_MSG_SIZE]; +} __packed; + struct grcan_dma_buffer { size_t size; void *buf; + union { + struct grcan_msg_header *header; + struct grcan_msg_fragment *frag; + }; dma_addr_t handle; }; =20 @@ -417,6 +428,12 @@ static inline u32 grcan_txspace(size_t txsize, u32 txw= r, u32 eskbp) return slots - used; } =20 +static inline struct grcan_msg_header * +grcan_msg_header_at(struct grcan_dma_buffer *dbuf, u32 offset) +{ + return (struct grcan_msg_header *)((u8 *)dbuf->buf + offset); +} + /* Configuration parameters that can be set via module parameters */ static struct grcan_device_config grcan_module_config =3D GRCAN_DEFAULT_DEVICE_CONFIG; @@ -1216,11 +1233,11 @@ static int grcan_receive(struct net_device *dev, in= t budget) struct grcan_registers __iomem *regs =3D priv->regs; struct grcan_dma *dma =3D &priv->dma; struct net_device_stats *stats =3D &dev->stats; + struct grcan_msg_header *hdr; struct can_frame *cf; struct sk_buff *skb; u32 wr, rd, startrd; - u32 *slot; - u32 i, rtr, eff, j, shift; + u32 rtr, eff; int work_done =3D 0; =20 rd =3D grcan_read_reg(®s->rxrd); @@ -1240,30 +1257,33 @@ static int grcan_receive(struct net_device *dev, in= t budget) continue; } =20 - slot =3D dma->rx.buf + rd; - eff =3D slot[0] & GRCAN_MSG_IDE; - rtr =3D slot[0] & GRCAN_MSG_RTR; + hdr =3D grcan_msg_header_at(&dma->rx, rd); + + eff =3D hdr->id & GRCAN_MSG_IDE; + rtr =3D hdr->id & GRCAN_MSG_RTR; + if (eff) { - cf->can_id =3D ((slot[0] & GRCAN_MSG_EID) + cf->can_id =3D ((hdr->id & GRCAN_MSG_EID) >> GRCAN_MSG_EID_BIT); cf->can_id |=3D CAN_EFF_FLAG; } else { - cf->can_id =3D ((slot[0] & GRCAN_MSG_BID) + cf->can_id =3D ((hdr->id & GRCAN_MSG_BID) >> GRCAN_MSG_BID_BIT); } - cf->len =3D can_cc_dlc2len((slot[1] & GRCAN_MSG_DLC) - >> GRCAN_MSG_DLC_BIT); + + cf->len =3D can_cc_dlc2len((hdr->ctrl & GRCAN_MSG_DLC) + >> GRCAN_MSG_DLC_BIT); + if (rtr) { cf->can_id |=3D CAN_RTR_FLAG; } else { - for (i =3D 0; i < cf->len; i++) { - j =3D GRCAN_MSG_DATA_SLOT_INDEX(i); - shift =3D GRCAN_MSG_DATA_SHIFT(i); - cf->data[i] =3D (u8)(slot[j] >> shift); - } + if (cf->len > 0) + memcpy(cf->data, hdr->data, + min_t(u32, cf->len, CAN_MAX_DLEN)); =20 stats->rx_bytes +=3D cf->len; } + stats->rx_packets++; =20 netif_receive_skb(skb); @@ -1396,11 +1416,10 @@ static netdev_tx_t grcan_start_xmit(struct sk_buff = *skb, struct grcan_registers __iomem *regs =3D priv->regs; struct grcan_dma *dma =3D &priv->dma; struct can_frame *cf =3D (struct can_frame *)skb->data; + struct grcan_msg_header *hdr; u32 id, txwr, txrd, space, txctrl; int slotindex; - u32 *slot; - u32 i, rtr, eff, dlc, tmp, err; - int j, shift; + u32 rtr, eff, dlc, tmp, err; unsigned long flags; u32 oneshotmode =3D priv->can.ctrlmode & CAN_CTRLMODE_ONE_SHOT; =20 @@ -1423,7 +1442,6 @@ static netdev_tx_t grcan_start_xmit(struct sk_buff *s= kb, space =3D grcan_txspace(dma->tx.size, txwr, priv->eskbp); =20 slotindex =3D txwr / GRCAN_MSG_SIZE; - slot =3D dma->tx.buf + txwr; =20 if (unlikely(space =3D=3D 1)) netif_stop_queue(dev); @@ -1439,6 +1457,9 @@ static netdev_tx_t grcan_start_xmit(struct sk_buff *s= kb, return NETDEV_TX_BUSY; } =20 + hdr =3D grcan_msg_header_at(&dma->tx, txwr); + memset(hdr, 0, sizeof(*hdr)); + /* Convert and write CAN message to DMA buffer */ eff =3D cf->can_id & CAN_EFF_FLAG; rtr =3D cf->can_id & CAN_RTR_FLAG; @@ -1448,16 +1469,13 @@ static netdev_tx_t grcan_start_xmit(struct sk_buff = *skb, tmp =3D (id << GRCAN_MSG_EID_BIT) & GRCAN_MSG_EID; else tmp =3D (id << GRCAN_MSG_BID_BIT) & GRCAN_MSG_BID; - slot[0] =3D (eff ? GRCAN_MSG_IDE : 0) | (rtr ? GRCAN_MSG_RTR : 0) | tmp; - - slot[1] =3D ((dlc << GRCAN_MSG_DLC_BIT) & GRCAN_MSG_DLC); - slot[2] =3D 0; - slot[3] =3D 0; - for (i =3D 0; i < dlc; i++) { - j =3D GRCAN_MSG_DATA_SLOT_INDEX(i); - shift =3D GRCAN_MSG_DATA_SHIFT(i); - slot[j] |=3D cf->data[i] << shift; - } + + hdr->id =3D (eff ? GRCAN_MSG_IDE : 0) | (rtr ? GRCAN_MSG_RTR : 0) | tmp; + + hdr->ctrl =3D ((dlc << GRCAN_MSG_DLC_BIT) & GRCAN_MSG_DLC); + + if (dlc > 0) + memcpy(hdr->data, cf->data, min_t(u32, cf->len, CAN_MAX_DLEN)); =20 /* Checking that channel has not been disabled. These cases * should never happen --=20 2.51.0 From nobody Fri Apr 3 01:41:56 2026 Received: from smtp-out3.simply.com (smtp-out3.simply.com [94.231.106.210]) (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 263033AA1A6; Fri, 6 Mar 2026 16:30:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=94.231.106.210 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772814607; cv=none; b=nS/kxfd8Lhxq89tBeu/pqMSVjlP6txfUCuVX+hFzoFBAA5j6vAz2K9uxSwZICKJsJW7MX+DNvAQHg5x6zRPXyA3mzSDU0PTC3GkIS0x0nEm5b3CxVk1K6cMAiwz2JSKnibAy143g1L+XuEyJV5p2Y0mNRnDGB/emvEDmKMr3ukQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772814607; c=relaxed/simple; bh=ec9Q8bC+SzrjWd9DEgqt0ENqCEnKlztjG2W/AgncgE8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=KLNBJjuuozUlITy+y0s1fSGf7svGVgTxxlXTsqr7Ik8TlPgRt58m7OWruGQA2Jv3qUfWUZB+pF3tEdUdPf2a/8yqGycYdvAio1qtNM22oP0XwBGCLAdeV+Mm3t/QMjTIDSP6d6SssEpq6huh8xHplJ6snfKRoSrSmZeAgjyZ5/k= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gaisler.com; spf=pass smtp.mailfrom=gaisler.com; dkim=fail (0-bit key) header.d=gaisler.com header.i=@gaisler.com header.b=kFmuM90c reason="key not found in DNS"; arc=none smtp.client-ip=94.231.106.210 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gaisler.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gaisler.com Authentication-Results: smtp.subspace.kernel.org; dkim=fail reason="key not found in DNS" (0-bit key) header.d=gaisler.com header.i=@gaisler.com header.b="kFmuM90c" Received: from localhost (localhost [127.0.0.1]) by smtp.simply.com (Simply.com) with ESMTP id 4fSBhC5XRzz1Fljl; Fri, 6 Mar 2026 17:29:47 +0100 (CET) Received: from d-5xj5g74.got.gaisler.com.com (h-98-128-223-123.NA.cust.bahnhof.se [98.128.223.123]) by smtp.simply.com (Simply.com) with ESMTPA id 4fSBhC3bwBz1DDgW; Fri, 6 Mar 2026 17:29:47 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gaisler.com; s=simplycom2; t=1772814587; bh=+Dw6R2enjEsOg8oLAY+9D/rSw/CY/HhSy4Ay5c2tBbM=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=kFmuM90c4CY6PbYWuNiD1xOlRiU6makX9YAQ+AKggwW3ogMBBQXKqfmNJ0urjuT3p m+IbBZCNL/TSz8S4aOVl+XXJCBbwlePctbudgdnZzygW+4DjxqOd4MorWsbDxh8VfB fXAYXjXDuZO359h8Hr9h6mhzSqKqt7tM/3lN2k/SoOwpPWwRKpKATfSvjrZM+K0YeJ J0OQ7EUTOWFLTsbClEgoX4cueyEVuvmU+XC/jFFoXZ98Lp5aMrQikavq4XAjjHiHOB SkKFbSic4Xu3kx1I2Z/wDJ0h6o1tBTvfRhaNf101swsEnCoitLtY8jZ3RE1Z2pLTTg 2D6I3lHOFo5QA== From: Arun Muthusamy To: robh@kernel.org, krzk+dt@kernel.org, conor+dt@kernel.org, mkl@pengutronix.de, mailhol@kernel.org Cc: devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-can@vger.kernel.org, Arun Muthusamy Subject: [PATCH v6 12/15] can: grcan: Add CANFD TX support alongside legacy CAN Date: Fri, 6 Mar 2026 17:29:31 +0100 Message-ID: <20260306162934.22955-13-arun.muthusamy@gaisler.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20260306162934.22955-1-arun.muthusamy@gaisler.com> References: <20260306162934.22955-1-arun.muthusamy@gaisler.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Include CANFD TX support with the legacy CAN support, enabling support for extended data payloads to provide higher bit rates. Signed-off-by: Arun Muthusamy --- drivers/net/can/grcan.c | 117 +++++++++++++++++++++++++++++----------- 1 file changed, 87 insertions(+), 30 deletions(-) diff --git a/drivers/net/can/grcan.c b/drivers/net/can/grcan.c index 4c56861e21d7..94af34fbd1fd 100644 --- a/drivers/net/can/grcan.c +++ b/drivers/net/can/grcan.c @@ -174,6 +174,7 @@ struct grcan_registers { #define GRCAN_IRQ_DEFAULT (GRCAN_IRQ_RX | GRCAN_IRQ_TX | GRCAN_IRQ_ERRORS) =20 #define GRCAN_MSG_SIZE 16 +#define GRCAN_CLASSIC_DATA_SIZE 8 =20 #define GRCAN_MSG_IDE 0x80000000 #define GRCAN_MSG_RTR 0x40000000 @@ -195,6 +196,10 @@ struct grcan_registers { #define GRCAN_MSG_OFF 0x00000002 #define GRCAN_MSG_PASS 0x00000001 =20 +#define GRCAN_MSG_EID_MASK GENMASK(28, 0) +#define GRCAN_MSG_BID_MASK GENMASK(28, 18) +#define GRCAN_MSG_DLC_MASK GENMASK(31, 28) + #define GRCAN_BUFFER_ALIGNMENT 1024 #define GRCAN_DEFAULT_BUFFER_SIZE 1024 #define GRCAN_VALID_TR_SIZE_MASK 0x001fffc0 @@ -227,6 +232,9 @@ struct grcan_registers { #define GRCANFD_FDBTR_PS2_BIT 5 #define GRCANFD_FDBTR_SJW_BIT 0 =20 +#define GRCAN_TX_BRS BIT(25) +#define GRCAN_TX_FDF BIT(26) + /* Hardware capabilities */ struct grcan_hwcap { /* CAN-FD capable, indicates GRCANFD IP. @@ -434,6 +442,12 @@ grcan_msg_header_at(struct grcan_dma_buffer *dbuf, u32= offset) return (struct grcan_msg_header *)((u8 *)dbuf->buf + offset); } =20 +static inline struct grcan_msg_fragment * +grcan_msg_frag_at(struct grcan_dma_buffer *dbuf, u32 offset) +{ + return (struct grcan_msg_fragment *)((u8 *)dbuf->buf + offset); +} + /* Configuration parameters that can be set via module parameters */ static struct grcan_device_config grcan_module_config =3D GRCAN_DEFAULT_DEVICE_CONFIG; @@ -1227,6 +1241,14 @@ static void grcan_transmit_catch_up(struct net_devic= e *dev) spin_unlock_irqrestore(&priv->lock, flags); } =20 +static int grcan_numbds(int len) +{ + if (len <=3D GRCAN_CLASSIC_DATA_SIZE) + return 1; + + return 1 + DIV_ROUND_UP(len - GRCAN_CLASSIC_DATA_SIZE, GRCAN_MSG_SIZE); +} + static int grcan_receive(struct net_device *dev, int budget) { struct grcan_priv *priv =3D netdev_priv(dev); @@ -1413,15 +1435,24 @@ static netdev_tx_t grcan_start_xmit(struct sk_buff = *skb, struct net_device *dev) { struct grcan_priv *priv =3D netdev_priv(dev); - struct grcan_registers __iomem *regs =3D priv->regs; + struct grcan_registers __iomem *regs; + u32 eff, rtr, dlc, tmp, err, can_id; struct grcan_dma *dma =3D &priv->dma; - struct can_frame *cf =3D (struct can_frame *)skb->data; - struct grcan_msg_header *hdr; + u32 bds, copy_len, payload_offset; u32 id, txwr, txrd, space, txctrl; - int slotindex; - u32 rtr, eff, dlc, tmp, err; + struct grcan_msg_fragment *frag; + struct grcan_msg_header *hdr; + struct canfd_frame *cfd; + struct can_frame *cf; unsigned long flags; - u32 oneshotmode =3D priv->can.ctrlmode & CAN_CTRLMODE_ONE_SHOT; + u32 oneshotmode; + int slotindex; + u8 *payload; + u8 len; + int i; + + regs =3D priv->regs; + oneshotmode =3D priv->can.ctrlmode & CAN_CTRLMODE_ONE_SHOT; =20 if (can_dev_dropped_skb(dev, skb)) return NETDEV_TX_OK; @@ -1432,6 +1463,18 @@ static netdev_tx_t grcan_start_xmit(struct sk_buff *= skb, if (priv->can.ctrlmode & CAN_CTRLMODE_LISTENONLY) return NETDEV_TX_BUSY; =20 + cfd =3D (struct canfd_frame *)skb->data; + len =3D cfd->len; + can_id =3D cfd->can_id; + payload =3D cfd->data; + + if (can_is_canfd_skb(skb)) { + dlc =3D can_fd_len2dlc(len); + } else { + cf =3D (struct can_frame *)skb->data; + dlc =3D can_get_cc_dlc(cf, priv->can.ctrlmode); + } + /* Reads of priv->eskbp and shut-downs of the queue needs to * be atomic towards the updates to priv->eskbp and wake-ups * of the queue in the interrupt handler. @@ -1442,40 +1485,55 @@ static netdev_tx_t grcan_start_xmit(struct sk_buff = *skb, space =3D grcan_txspace(dma->tx.size, txwr, priv->eskbp); =20 slotindex =3D txwr / GRCAN_MSG_SIZE; + bds =3D grcan_numbds(len); =20 - if (unlikely(space =3D=3D 1)) + if (unlikely(space < bds)) { netif_stop_queue(dev); + spin_unlock_irqrestore(&priv->lock, flags); + return NETDEV_TX_BUSY; + } =20 spin_unlock_irqrestore(&priv->lock, flags); /* End of critical section*/ =20 - /* This should never happen. If circular buffer is full, the - * netif_stop_queue should have been stopped already. - */ - if (unlikely(!space)) { - netdev_err(dev, "No buffer space, but queue is non-stopped.\n"); - return NETDEV_TX_BUSY; - } - hdr =3D grcan_msg_header_at(&dma->tx, txwr); memset(hdr, 0, sizeof(*hdr)); =20 - /* Convert and write CAN message to DMA buffer */ - eff =3D cf->can_id & CAN_EFF_FLAG; - rtr =3D cf->can_id & CAN_RTR_FLAG; - id =3D cf->can_id & (eff ? CAN_EFF_MASK : CAN_SFF_MASK); - dlc =3D cf->len; - if (eff) - tmp =3D (id << GRCAN_MSG_EID_BIT) & GRCAN_MSG_EID; - else - tmp =3D (id << GRCAN_MSG_BID_BIT) & GRCAN_MSG_BID; + eff =3D can_id & CAN_EFF_FLAG; + rtr =3D can_id & CAN_RTR_FLAG; + id =3D can_id & (eff ? CAN_EFF_MASK : CAN_SFF_MASK); + + tmp =3D eff ? FIELD_PREP(GRCAN_MSG_EID_MASK, id) + : FIELD_PREP(GRCAN_MSG_BID_MASK, id); + + hdr->id =3D (eff ? GRCAN_MSG_IDE : 0) | + (rtr ? GRCAN_MSG_RTR : 0) | + tmp; =20 - hdr->id =3D (eff ? GRCAN_MSG_IDE : 0) | (rtr ? GRCAN_MSG_RTR : 0) | tmp; + hdr->ctrl =3D FIELD_PREP(GRCAN_MSG_DLC_MASK, dlc); + + if (can_is_canfd_skb(skb)) { + hdr->ctrl |=3D GRCAN_TX_FDF; + if (cfd->flags & CANFD_BRS) + hdr->ctrl |=3D GRCAN_TX_BRS; + } =20 - hdr->ctrl =3D ((dlc << GRCAN_MSG_DLC_BIT) & GRCAN_MSG_DLC); + copy_len =3D min_t(u32, len, CAN_MAX_DLEN); + memcpy(hdr->data, payload, copy_len); + payload_offset =3D copy_len; =20 - if (dlc > 0) - memcpy(hdr->data, cf->data, min_t(u32, cf->len, CAN_MAX_DLEN)); + txwr =3D grcan_ring_add(txwr, GRCAN_MSG_SIZE, dma->tx.size); + + for (i =3D 1; i < bds; i++) { + frag =3D grcan_msg_frag_at(&dma->tx, txwr); + + memset(frag, 0, sizeof(*frag)); + copy_len =3D min_t(u32, (u32)len - payload_offset, (u32)GRCAN_MSG_SIZE); + memcpy(frag->data, payload + payload_offset, copy_len); + payload_offset +=3D copy_len; + + txwr =3D grcan_ring_add(txwr, GRCAN_MSG_SIZE, dma->tx.size); + } =20 /* Checking that channel has not been disabled. These cases * should never happen @@ -1517,8 +1575,7 @@ static netdev_tx_t grcan_start_xmit(struct sk_buff *s= kb, wmb(); =20 /* Update write pointer to start transmission */ - grcan_write_reg(®s->txwr, - grcan_ring_add(txwr, GRCAN_MSG_SIZE, dma->tx.size)); + grcan_write_reg(®s->txwr, txwr); =20 return NETDEV_TX_OK; } --=20 2.51.0 From nobody Fri Apr 3 01:41:56 2026 Received: from smtp-out3.simply.com (smtp-out3.simply.com [94.231.106.210]) (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 696BB3ED5A0; Fri, 6 Mar 2026 16:30:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=94.231.106.210 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772814609; cv=none; b=R5xoBgdR0m89i2oIz1FHxKKRgAyKE2B9hQcHHAcy3WxfjWD+fp5Pt/HuMcf6DuVtbXdNifYRsYQsh7liAXG+9iDUrSXn8elZSkIYxFi2Q1Hu+XEYfyU7X27mzmQwMjbHXLU1o+zG/IjAqHm+QH/win7O2VNv2MxJlspEJzZwIEQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772814609; c=relaxed/simple; bh=Sqyrt/nDjXpX4UtO/J4ydRp8egTd0J6OjaYBQ9XVgAg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=WmUZhLxRcgyMBpgT1iP6Xwrat1snqFjSCirT80OkXLn9Y9KLjfZkUalqq0dm7D6u1C8mphiDFnxO+J8aoyn0kzvC+JdJW4hti+D8uDqPa5jZ7faQNTdE8wwzm38cDLu4eoOF3cuBeHw9FyxlOS47IYjMqc4ggG81e66HGM972J0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gaisler.com; spf=pass smtp.mailfrom=gaisler.com; dkim=fail (0-bit key) header.d=gaisler.com header.i=@gaisler.com header.b=gU/KTf2A reason="key not found in DNS"; arc=none smtp.client-ip=94.231.106.210 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gaisler.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gaisler.com Authentication-Results: smtp.subspace.kernel.org; dkim=fail reason="key not found in DNS" (0-bit key) header.d=gaisler.com header.i=@gaisler.com header.b="gU/KTf2A" Received: from localhost (localhost [127.0.0.1]) by smtp.simply.com (Simply.com) with ESMTP id 4fSBhC74r5z1Fljn; Fri, 6 Mar 2026 17:29:47 +0100 (CET) Received: from d-5xj5g74.got.gaisler.com.com (h-98-128-223-123.NA.cust.bahnhof.se [98.128.223.123]) by smtp.simply.com (Simply.com) with ESMTPA id 4fSBhC5CNCz1Fljf; Fri, 6 Mar 2026 17:29:47 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gaisler.com; s=simplycom2; t=1772814587; bh=wG1Xz3PFJ5zaeS/mHFd20/KLBCZNWCnlzL13w0Ig5cs=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=gU/KTf2AGfKoNu5aeQgEUerNRC/qGJNxGhYKI9sw4OJELOFi+u8uePKLPe7RV3237 ME172g17Vb/gB8/TuoDfKBYKfbdbs4dPsQ4Q68reJ/J1YPVgMUKq1pygctgCISeWPA RIzpH6bICImoLBaGeX9YYOYPPXbguXsB7GbbgtXhT7GplLMMiDMb1fxNRIpIXy3STh 6HL6OX6xkt7T/4Bbm7JvwJsu/ldrphXwcPoKOdVOEGDr4Rm+biNh6p7mUjrpVOqFPA qLuNTR4Db3b4KUQLTcGS6Ael+Fa9l+/YN3UIgIg6Xokp6hbPUnF4muWZGsntez2HOo rfG/2XA54TlcQ== From: Arun Muthusamy To: robh@kernel.org, krzk+dt@kernel.org, conor+dt@kernel.org, mkl@pengutronix.de, mailhol@kernel.org Cc: devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-can@vger.kernel.org, Arun Muthusamy Subject: [PATCH v6 13/15] can: grcan: Add CANFD RX support alongside legacy CAN Date: Fri, 6 Mar 2026 17:29:32 +0100 Message-ID: <20260306162934.22955-14-arun.muthusamy@gaisler.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20260306162934.22955-1-arun.muthusamy@gaisler.com> References: <20260306162934.22955-1-arun.muthusamy@gaisler.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Include CANFD RX support with the legacy CAN support, enabling support for extended data payloads to provide higher bit rates. Signed-off-by: Arun Muthusamy --- drivers/net/can/grcan.c | 72 +++++++++++++++++++++++++++-------------- 1 file changed, 47 insertions(+), 25 deletions(-) diff --git a/drivers/net/can/grcan.c b/drivers/net/can/grcan.c index 94af34fbd1fd..514a065cab5f 100644 --- a/drivers/net/can/grcan.c +++ b/drivers/net/can/grcan.c @@ -235,6 +235,9 @@ struct grcan_registers { #define GRCAN_TX_BRS BIT(25) #define GRCAN_TX_FDF BIT(26) =20 +#define GRCAN_RX_BRS BIT(25) +#define GRCAN_RX_FDF BIT(26) + /* Hardware capabilities */ struct grcan_hwcap { /* CAN-FD capable, indicates GRCANFD IP. @@ -1251,17 +1254,21 @@ static int grcan_numbds(int len) =20 static int grcan_receive(struct net_device *dev, int budget) { + struct net_device_stats *stats =3D &dev->stats; struct grcan_priv *priv =3D netdev_priv(dev); - struct grcan_registers __iomem *regs =3D priv->regs; + struct grcan_registers __iomem *regs; struct grcan_dma *dma =3D &priv->dma; - struct net_device_stats *stats =3D &dev->stats; + u32 bds, copy_len, payload_offset; + struct grcan_msg_fragment *frag; struct grcan_msg_header *hdr; - struct can_frame *cf; + u32 wr, rd, dlc, startrd; + struct canfd_frame *cf; + int i, work_done =3D 0; struct sk_buff *skb; - u32 wr, rd, startrd; u32 rtr, eff; - int work_done =3D 0; + u8 *data; =20 + regs =3D priv->regs; rd =3D grcan_read_reg(®s->rxrd); startrd =3D rd; for (work_done =3D 0; work_done < budget; work_done++) { @@ -1270,47 +1277,62 @@ static int grcan_receive(struct net_device *dev, in= t budget) if (rd =3D=3D wr) break; =20 - /* Take care of packet */ - skb =3D alloc_can_skb(dev, &cf); - if (skb =3D=3D NULL) { - netdev_err(dev, - "dropping frame: skb allocation failed\n"); + hdr =3D grcan_msg_header_at(&dma->rx, rd); + if (hdr->ctrl & GRCAN_RX_FDF) + skb =3D alloc_canfd_skb(dev, &cf); + else + skb =3D alloc_can_skb(dev, (struct can_frame **)&cf); + + if (unlikely(!skb)) { + netdev_err(dev, "dropping frame: skb allocation failed\n"); stats->rx_dropped++; continue; } =20 - hdr =3D grcan_msg_header_at(&dma->rx, rd); + dlc =3D FIELD_GET(GRCAN_MSG_DLC_MASK, hdr->ctrl); + if (hdr->ctrl & GRCAN_RX_FDF) + cf->len =3D can_fd_dlc2len(dlc); + else + cf->len =3D can_cc_dlc2len(dlc); + + bds =3D grcan_numbds(cf->len); + payload_offset =3D 0; + data =3D cf->data; =20 eff =3D hdr->id & GRCAN_MSG_IDE; rtr =3D hdr->id & GRCAN_MSG_RTR; =20 if (eff) { - cf->can_id =3D ((hdr->id & GRCAN_MSG_EID) - >> GRCAN_MSG_EID_BIT); + cf->can_id =3D FIELD_GET(GRCAN_MSG_EID_MASK, hdr->id); cf->can_id |=3D CAN_EFF_FLAG; } else { - cf->can_id =3D ((hdr->id & GRCAN_MSG_BID) - >> GRCAN_MSG_BID_BIT); + cf->can_id =3D FIELD_GET(GRCAN_MSG_BID_MASK, hdr->id); } - - cf->len =3D can_cc_dlc2len((hdr->ctrl & GRCAN_MSG_DLC) - >> GRCAN_MSG_DLC_BIT); - if (rtr) { cf->can_id |=3D CAN_RTR_FLAG; + rd =3D grcan_ring_add(rd, GRCAN_MSG_SIZE, dma->rx.size); } else { - if (cf->len > 0) - memcpy(cf->data, hdr->data, - min_t(u32, cf->len, CAN_MAX_DLEN)); + copy_len =3D min_t(u32, cf->len, CAN_MAX_DLEN); + memcpy(data, hdr->data, copy_len); + payload_offset +=3D copy_len; + + rd =3D grcan_ring_add(rd, GRCAN_MSG_SIZE, dma->rx.size); =20 + for (i =3D 1; i < bds; i++) { + frag =3D grcan_msg_frag_at(&dma->rx, rd); + + copy_len =3D min_t(u32, (u32)cf->len - payload_offset, + (u32)GRCAN_MSG_SIZE); + memcpy(data + payload_offset, frag->data, copy_len); + payload_offset +=3D copy_len; + + rd =3D grcan_ring_add(rd, GRCAN_MSG_SIZE, dma->rx.size); + } stats->rx_bytes +=3D cf->len; } =20 stats->rx_packets++; - netif_receive_skb(skb); - - rd =3D grcan_ring_add(rd, GRCAN_MSG_SIZE, dma->rx.size); } =20 /* Make sure everything is read before allowing hardware to --=20 2.51.0 From nobody Fri Apr 3 01:41:56 2026 Received: from smtp-out3.simply.com (smtp-out3.simply.com [94.231.106.210]) (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 75A5B3EDADC; Fri, 6 Mar 2026 16:30:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=94.231.106.210 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772814609; cv=none; b=Sm9a9VbUb3KdwlD36coWSpTY30coVdi23f8ge4aDqOPeI/NEtvs+t8gdn45UEHUnea7q0HrvBSPLMJ7jBN8K+c0SSnXCNDX/tveiDNnvD8g9UtcqmIgr4rdjRkO+AQBsnek5UrX1oh5C2hJyJSzFxyc4BHvyhfMF8j90lRokzT8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772814609; c=relaxed/simple; bh=WX4iliFH8rfFSUeWBkDCpuXCMfyaJLwZIYpivfuVBr4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=BAexSdLBM7GUhCyEHl7s7WBZEOe4dkUpU3pailBqTAOT05R25LN6ZTlI53OD9pfX3yOgaV8UxyYrW53j+nFqmlaAgRlVOVh/j6H/bOfX3GYG3zp2hOwhbQQ/m1S+QsOHorUuxJX5mfAKbF8fr3LhjlCX6s9sByzn+oteZ3qrkR0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gaisler.com; spf=pass smtp.mailfrom=gaisler.com; dkim=fail (0-bit key) header.d=gaisler.com header.i=@gaisler.com header.b=dzvAOqM8 reason="key not found in DNS"; arc=none smtp.client-ip=94.231.106.210 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gaisler.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gaisler.com Authentication-Results: smtp.subspace.kernel.org; dkim=fail reason="key not found in DNS" (0-bit key) header.d=gaisler.com header.i=@gaisler.com header.b="dzvAOqM8" Received: from localhost (localhost [127.0.0.1]) by smtp.simply.com (Simply.com) with ESMTP id 4fSBhD1bSkz1Fljp; Fri, 6 Mar 2026 17:29:48 +0100 (CET) Received: from d-5xj5g74.got.gaisler.com.com (h-98-128-223-123.NA.cust.bahnhof.se [98.128.223.123]) by smtp.simply.com (Simply.com) with ESMTPA id 4fSBhC6vLBz1Fljm; Fri, 6 Mar 2026 17:29:47 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gaisler.com; s=simplycom2; t=1772814588; bh=SCH4E58TYURvvthpUcjs5e27F0JdgS5Nv2Q29b4pMq8=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=dzvAOqM84qdbgYz9JS8l4OX1z08HEDI0zhWrzw0sFa4KwTKOfM6Fu9fI1elh2wyCt WVefHty8bQiMYtO1wjcHKquiOI/0PwsdWsltnBRY9ovEm3pdl6CsRQIEl+uTjTi4we TfEioaLp+sELrm0r4PfpmDlUg/Dm5SAQNgTTKpxj57p40cs2rrIQGQdmAgyWkSdy9P p/rmx7QzzCeb1KNCbOx0frhxv/+ohu+il68KQpBVdUumYAyUGEhbseDMG83aDU5Bl8 yErpT22r5at3BCRH/pyn2TVtkUlmvAc7a1MZv59SEKg/1XvYXotI8nBm/OGybKxVAV 2GR4CH7CtOk1A== From: Arun Muthusamy To: robh@kernel.org, krzk+dt@kernel.org, conor+dt@kernel.org, mkl@pengutronix.de, mailhol@kernel.org Cc: devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-can@vger.kernel.org, Arun Muthusamy Subject: [PATCH v6 14/15] can: grcan: Update echo skb handling to match variable length CANFD frame Date: Fri, 6 Mar 2026 17:29:33 +0100 Message-ID: <20260306162934.22955-15-arun.muthusamy@gaisler.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20260306162934.22955-1-arun.muthusamy@gaisler.com> References: <20260306162934.22955-1-arun.muthusamy@gaisler.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Refactor echo socket buffer management by introducing dedicated indices for current and next echo slots. - Introduce "echo_skb_idx" to keep track of the current packet index in the echo buffer, and "next_echo_idx" for the next available slot. - Adjust memory allocation for echo skb to calculate the number of slots based on slot size. - Enhance logic in catch_up_echo_skb() to correctly process and free echo skbs. - Initialize "next_echo_idx" in grcan_set_mode() to ensure proper starting conditions when the device enters proper modes. - Improve memory and index handling in grcan_start_xmit() and added a check to stop the network queue when necessary. Signed-off-by: Arun Muthusamy --- drivers/net/can/grcan.c | 53 ++++++++++++++++++++++++++++------------- 1 file changed, 36 insertions(+), 17 deletions(-) diff --git a/drivers/net/can/grcan.c b/drivers/net/can/grcan.c index 514a065cab5f..9204fcb93b2d 100644 --- a/drivers/net/can/grcan.c +++ b/drivers/net/can/grcan.c @@ -312,6 +312,15 @@ struct grcan_priv { =20 struct sk_buff **echo_skb; /* We allocate this on our own */ =20 + /* + * Since the CAN FD frame has a variable length, this variable is used + * to keep track of the index of the CAN echo skb (socket buffer) frame. + */ + u32 echo_skb_idx; + + /* Next echo skb free slot index */ + u32 next_echo_idx; + /* The echo skb pointer, pointing into echo_skb and indicating which * frames can be echoed back. See the "Notes on the tx cyclic buffer * handling"-comment for grcan_start_xmit for more details. @@ -593,7 +602,7 @@ static int catch_up_echo_skb(struct net_device *dev, in= t budget, bool echo) struct grcan_registers __iomem *regs =3D priv->regs; struct grcan_dma *dma =3D &priv->dma; struct net_device_stats *stats =3D &dev->stats; - int i, work_done; + int work_done; =20 /* Updates to priv->eskbp and wake-ups of the queue needs to * be atomic towards the reads of priv->eskbp and shut-downs @@ -604,19 +613,22 @@ static int catch_up_echo_skb(struct net_device *dev, = int budget, bool echo) for (work_done =3D 0; work_done < budget || budget < 0; work_done++) { if (priv->eskbp =3D=3D txrd) break; - i =3D priv->eskbp / GRCAN_MSG_SIZE; - if (echo) { - /* Normal echo of messages */ - stats->tx_packets++; - stats->tx_bytes +=3D can_get_echo_skb(dev, i, NULL); - } else { - /* For cleanup of untransmitted messages */ - can_free_echo_skb(dev, i, NULL); - } =20 priv->eskbp =3D grcan_ring_add(priv->eskbp, GRCAN_MSG_SIZE, dma->tx.size); txrd =3D grcan_read_reg(®s->txrd); + + /* Grab the packet once the packet is send or free untransmitted packet = */ + if (priv->eskbp =3D=3D txrd) { + if (echo) { + /* Normal echo of messages */ + stats->tx_packets++; + stats->tx_bytes +=3D can_get_echo_skb(dev, priv->echo_skb_idx, NULL); + } else { + /* For cleanup of untransmitted messages */ + can_free_echo_skb(dev, priv->echo_skb_idx, NULL); + } + } } return work_done; } @@ -1124,6 +1136,7 @@ static int grcan_set_mode(struct net_device *dev, enu= m can_mode mode) if (!(priv->can.ctrlmode & CAN_CTRLMODE_LISTENONLY)) netif_wake_queue(dev); } + priv->next_echo_idx =3D 0; spin_unlock_irqrestore(&priv->lock, flags); return err; } @@ -1135,6 +1148,7 @@ static int grcan_open(struct net_device *dev) struct grcan_priv *priv =3D netdev_priv(dev); struct grcan_dma *dma =3D &priv->dma; unsigned long flags; + u32 nr_echo_slots; int err; =20 /* Allocate memory */ @@ -1145,13 +1159,15 @@ static int grcan_open(struct net_device *dev) return err; } =20 - priv->echo_skb =3D kcalloc(dma->tx.size, sizeof(*priv->echo_skb), + nr_echo_slots =3D dma->tx.size / GRCAN_MSG_SIZE; + + priv->echo_skb =3D kcalloc(nr_echo_slots, sizeof(*priv->echo_skb), GFP_KERNEL); if (!priv->echo_skb) { err =3D -ENOMEM; goto exit_free_dma_buffers; } - priv->can.echo_skb_max =3D dma->tx.size; + priv->can.echo_skb_max =3D nr_echo_slots; priv->can.echo_skb =3D priv->echo_skb; =20 /* Get can device up */ @@ -1468,7 +1484,6 @@ static netdev_tx_t grcan_start_xmit(struct sk_buff *s= kb, struct can_frame *cf; unsigned long flags; u32 oneshotmode; - int slotindex; u8 *payload; u8 len; int i; @@ -1505,11 +1520,9 @@ static netdev_tx_t grcan_start_xmit(struct sk_buff *= skb, =20 txwr =3D grcan_read_reg(®s->txwr); space =3D grcan_txspace(dma->tx.size, txwr, priv->eskbp); - - slotindex =3D txwr / GRCAN_MSG_SIZE; bds =3D grcan_numbds(len); =20 - if (unlikely(space < bds)) { + if (unlikely(space < bds || priv->can.echo_skb[priv->echo_skb_idx])) { netif_stop_queue(dev); spin_unlock_irqrestore(&priv->lock, flags); return NETDEV_TX_BUSY; @@ -1589,7 +1602,13 @@ static netdev_tx_t grcan_start_xmit(struct sk_buff *= skb, * can_put_echo_skb would be an error unless other measures are * taken. */ - can_put_echo_skb(skb, dev, slotindex, 0); + + priv->echo_skb_idx =3D priv->next_echo_idx; + + can_put_echo_skb(skb, dev, priv->next_echo_idx, 0); + + /* Move to the next index in the echo skb buffer */ + priv->next_echo_idx =3D (priv->next_echo_idx + 1) % priv->can.echo_skb_ma= x; =20 /* Make sure everything is written before allowing hardware to * read from the memory --=20 2.51.0 From nobody Fri Apr 3 01:41:56 2026 Received: from smtp-out3.simply.com (smtp-out3.simply.com [94.231.106.210]) (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 BF7F82BE65B; Fri, 6 Mar 2026 16:30:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=94.231.106.210 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772814612; cv=none; b=tCqpl+b1FA2mpgC6c4OojznkAuSa0ajYJVkhcUrCvpFdCuJMneK9FMbIAYib21pTsLNvO4fcXK/2/WzXTRyV1GCjK/uZwjya9dosSMorHs9RJ9umip9VwVMsocmiqf2U63G0gl4wZItRhUU0iRD5L45QbRL/KdPO60/Ep1JFNCI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772814612; c=relaxed/simple; bh=mnI5oDMgftj6ROv25d9OoO3w8YnN1pQpJUb6cxATwdc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=WaWSDM9UCDhJCmtkzgxfGr4gxhehm0qM7UuBA9CvW7kOHxtZU1LDXgJPJHdwy/pn5m313WdUZkPJwpzOosw4hI1R1D/DzCUK5Sw0aCI5T56WjSyKRFhlYMSW98xhdMLSpOjB1s8wuCTplxfLm3tSwCOaUUCqDj5SM83Gg1Of6TE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gaisler.com; spf=pass smtp.mailfrom=gaisler.com; dkim=fail (0-bit key) header.d=gaisler.com header.i=@gaisler.com header.b=SFRD93kN reason="key not found in DNS"; arc=none smtp.client-ip=94.231.106.210 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gaisler.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gaisler.com Authentication-Results: smtp.subspace.kernel.org; dkim=fail reason="key not found in DNS" (0-bit key) header.d=gaisler.com header.i=@gaisler.com header.b="SFRD93kN" Received: from localhost (localhost [127.0.0.1]) by smtp.simply.com (Simply.com) with ESMTP id 4fSBhD3Xnmz1Fljg; Fri, 6 Mar 2026 17:29:48 +0100 (CET) Received: from d-5xj5g74.got.gaisler.com.com (h-98-128-223-123.NA.cust.bahnhof.se [98.128.223.123]) by smtp.simply.com (Simply.com) with ESMTPA id 4fSBhD1Rxyz1DDgW; Fri, 6 Mar 2026 17:29:48 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gaisler.com; s=simplycom2; t=1772814588; bh=HEHS4MCK05/7iplJTF+QJ7BrkPa/UogpKyHpuJ4BN8E=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=SFRD93kNH0cpLrxRiys1ijob71KeDQW9Jo/4gUUSdaM49J5q2Vq3NBo6pNxp5eJSv wsk3A+sRVJcqUbhqkbS7XFA9u0VY3VYz83jKDy3vTIEPc6Va9QHUVxfu+BN1U6pJvL T3qkjQF2riPUpdbGGEkR5dCLg4UjjsS7BqCG78fp6tMYweJ6Gh06uPLRqUeTcvoTt+ 6kdOQMog/Km3KokYALj/g0knicHgm3r5hcb97qbRJtybCI5Dkeb2ifZYShdQGBOATv k4OK4Utc9Hy8g0QfKROrrF5GsEnBvjkF4Et7fK3pE84X/p12R59rGx1QZ0fnpA3jSq 8x0U+oSWBKZLw== From: Arun Muthusamy To: robh@kernel.org, krzk+dt@kernel.org, conor+dt@kernel.org, mkl@pengutronix.de, mailhol@kernel.org Cc: devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-can@vger.kernel.org, Arun Muthusamy Subject: [PATCH v6 15/15] can: grcan: Advertise CANFD capability Date: Fri, 6 Mar 2026 17:29:34 +0100 Message-ID: <20260306162934.22955-16-arun.muthusamy@gaisler.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20260306162934.22955-1-arun.muthusamy@gaisler.com> References: <20260306162934.22955-1-arun.muthusamy@gaisler.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Advertise CANFD capability for GRCANFD hardware by enabling CAN_CTRLMODE_FD flag and providing CANFD timing operations. Signed-off-by: Arun Muthusamy --- drivers/net/can/grcan.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/net/can/grcan.c b/drivers/net/can/grcan.c index 9204fcb93b2d..bc1f205e10a5 100644 --- a/drivers/net/can/grcan.c +++ b/drivers/net/can/grcan.c @@ -1767,11 +1767,14 @@ static int grcan_setup_netdev(struct platform_devic= e *ofdev, priv->ofdev_dev =3D &ofdev->dev; priv->regs =3D base; priv->can.bittiming_const =3D hwcap->bt_const; + priv->can.fd.data_bittiming_const =3D hwcap->bt_const; priv->can.do_set_mode =3D grcan_set_mode; priv->can.do_get_berr_counter =3D grcan_get_berr_counter; priv->can.clock.freq =3D ambafreq; priv->can.ctrlmode_supported =3D CAN_CTRLMODE_LISTENONLY | CAN_CTRLMODE_ONE_SHOT; + if (hwcap->fd) + priv->can.ctrlmode_supported |=3D CAN_CTRLMODE_FD; priv->need_txbug_workaround =3D txbug; priv->hwcap =3D hwcap; =20 --=20 2.51.0