From patchwork Tue Nov 10 10:18:45 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oliver Hartkopp X-Patchwork-Id: 11893755 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 535F4C4741F for ; Tue, 10 Nov 2020 10:19:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0466E207BB for ; Tue, 10 Nov 2020 10:19:11 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=hartkopp.net header.i=@hartkopp.net header.b="neypGtT6" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729417AbgKJKTJ (ORCPT ); Tue, 10 Nov 2020 05:19:09 -0500 Received: from mo4-p01-ob.smtp.rzone.de ([85.215.255.54]:23328 "EHLO mo4-p01-ob.smtp.rzone.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731008AbgKJKTG (ORCPT ); Tue, 10 Nov 2020 05:19:06 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1605003543; s=strato-dkim-0002; d=hartkopp.net; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: X-RZG-CLASS-ID:X-RZG-AUTH:From:Subject:Sender; bh=MTQtC6hu8jphXFm30aQ9c48BEEYCvjQQKzJ5LYSSuWA=; b=neypGtT67+tRs+DxiGHWDeVnD/qp3rtB2f0Pxvi4tZ5f11M9+7j9w56DyhHZmFzd/t v/pVpNAAVDS4YayHHbjIyIvZPnkbU85/id7Zu+MvGYBt7m6Qho+Bd+qJOWcgOGGQoQ38 c/lAB97Kb+FEN2dKxAECxyM+lqBBJ3l8LgYbDPNimBjJVBAc2QIqZhvRyGj/+4CIB6z6 qtztqEERGfFtAyulvnJrFhjRpOITGODlco6ohwpHcokVSqrx/n3qdrfkcSBzb2vt9L+f 8H+QO+6THySxXUOBYIZ4ux6Z2WInIicvX6FyQ4glWhWKT8VqQYaj1y5sZqFEXDlURkWf oitw== X-RZG-AUTH: ":P2MHfkW8eP4Mre39l357AZT/I7AY/7nT2yrDxb8mjGrp7owjzFK3JbFk1mS0k+8CejudJywjsi+/Fw==" X-RZG-CLASS-ID: mo00 Received: from silver.lan by smtp.strato.de (RZmta 47.3.3 DYNA|AUTH) with ESMTPSA id V0298cwAAAJ1AQd (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256 bits)) (Client did not present a certificate); Tue, 10 Nov 2020 11:19:01 +0100 (CET) From: Oliver Hartkopp To: linux-can@vger.kernel.org, mkl@pengutronix.de, mailhol.vincent@wanadoo.fr Cc: netdev@vger.kernel.org, Oliver Hartkopp Subject: [PATCH v6 1/8] can: add optional DLC element to Classical CAN frame structure Date: Tue, 10 Nov 2020 11:18:45 +0100 Message-Id: <20201110101852.1973-2-socketcan@hartkopp.net> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201110101852.1973-1-socketcan@hartkopp.net> References: <20201110101852.1973-1-socketcan@hartkopp.net> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org ISO 11898-1 Chapter 8.4.2.3 defines a 4 bit data length code (DLC) table which maps the DLC to the payload length of the CAN frame in bytes: DLC -> payload length 0 .. 8 -> 0 .. 8 9 .. 15 -> 8 Although the DLC values 8 .. 15 in Classical CAN always result in a payload length of 8 bytes these DLC values are transparently transmitted on the CAN bus. As the struct can_frame only provides a 'len' element (formerly 'can_dlc') which contains the plain payload length ( 0 .. 8 ) of the CAN frame, the raw DLC is not visible to the application programmer, e.g. for testing use-cases. To access the raw DLC values 9 .. 15 the len8_dlc element is introduced, which is only valid when the payload length 'len' is 8 and the DLC is greater than 8. The len8_dlc element is filled by the CAN interface driver and used for CAN frame creation by the CAN driver when the CAN_CTRLMODE_CC_LEN8_DLC flag is supported by the driver and enabled via netlink configuration interface. Reported-by: Vincent Mailhol Signed-off-by: Oliver Hartkopp --- include/uapi/linux/can.h | 38 ++++++++++++++++++++------------ include/uapi/linux/can/netlink.h | 1 + 2 files changed, 25 insertions(+), 14 deletions(-) diff --git a/include/uapi/linux/can.h b/include/uapi/linux/can.h index 6a6d2c7655ff..f75238ac6dce 100644 --- a/include/uapi/linux/can.h +++ b/include/uapi/linux/can.h @@ -82,34 +82,44 @@ typedef __u32 canid_t; */ typedef __u32 can_err_mask_t; /* CAN payload length and DLC definitions according to ISO 11898-1 */ #define CAN_MAX_DLC 8 +#define CAN_MAX_RAW_DLC 15 #define CAN_MAX_DLEN 8 /* CAN FD payload length and DLC definitions according to ISO 11898-7 */ #define CANFD_MAX_DLC 15 #define CANFD_MAX_DLEN 64 /** - * struct can_frame - basic CAN frame structure - * @can_id: CAN ID of the frame and CAN_*_FLAG flags, see canid_t definition - * @can_dlc: frame payload length in byte (0 .. 8) aka data length code - * N.B. the DLC field from ISO 11898-1 Chapter 8.4.2.3 has a 1:1 - * mapping of the 'data length code' to the real payload length - * @__pad: padding - * @__res0: reserved / padding - * @__res1: reserved / padding - * @data: CAN frame payload (up to 8 byte) + * struct can_frame - Classical CAN frame structure (aka CAN 2.0B) + * @can_id: CAN ID of the frame and CAN_*_FLAG flags, see canid_t definition + * @len: CAN frame payload length in byte (0 .. 8) + * @can_dlc: deprecated name for CAN frame payload length in byte (0 .. 8) + * @__pad: padding + * @__res0: reserved / padding + * @len8_dlc: optional DLC value (9 .. 15) at 8 byte payload length + * len8_dlc contains values from 9 .. 15 when the payload length is + * 8 bytes but the DLC value (see ISO 11898-1) is greater then 8. + * CAN_CTRLMODE_CC_LEN8_DLC flag has to be enabled in CAN driver. + * @data: CAN frame payload (up to 8 byte) */ struct can_frame { canid_t can_id; /* 32 bit CAN_ID + EFF/RTR/ERR flags */ - __u8 can_dlc; /* frame payload length in byte (0 .. CAN_MAX_DLEN) */ - __u8 __pad; /* padding */ - __u8 __res0; /* reserved / padding */ - __u8 __res1; /* reserved / padding */ - __u8 data[CAN_MAX_DLEN] __attribute__((aligned(8))); + union { + /* CAN frame payload length in byte (0 .. CAN_MAX_DLEN) + * was previously named can_dlc so we need to carry that + * name for legacy support + */ + __u8 len; + __u8 can_dlc; /* deprecated */ + }; + __u8 __pad; /* padding */ + __u8 __res0; /* reserved / padding */ + __u8 len8_dlc; /* optional DLC for 8 byte payload length (9 .. 15) */ + __u8 data[CAN_MAX_DLEN] __attribute__((aligned(8))); }; /* * defined bits for canfd_frame.flags * diff --git a/include/uapi/linux/can/netlink.h b/include/uapi/linux/can/netlink.h index 6f598b73839e..f730d443b918 100644 --- a/include/uapi/linux/can/netlink.h +++ b/include/uapi/linux/can/netlink.h @@ -98,10 +98,11 @@ struct can_ctrlmode { #define CAN_CTRLMODE_ONE_SHOT 0x08 /* One-Shot mode */ #define CAN_CTRLMODE_BERR_REPORTING 0x10 /* Bus-error reporting */ #define CAN_CTRLMODE_FD 0x20 /* CAN FD mode */ #define CAN_CTRLMODE_PRESUME_ACK 0x40 /* Ignore missing CAN ACKs */ #define CAN_CTRLMODE_FD_NON_ISO 0x80 /* CAN FD in non-ISO mode */ +#define CAN_CTRLMODE_CC_LEN8_DLC 0x100 /* Classic CAN DLC option */ /* * CAN device statistics */ struct can_device_stats { From patchwork Tue Nov 10 10:18:46 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oliver Hartkopp X-Patchwork-Id: 11893767 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 27548C388F7 for ; Tue, 10 Nov 2020 10:19:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B962E207BB for ; Tue, 10 Nov 2020 10:19:19 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=hartkopp.net header.i=@hartkopp.net header.b="MPD54UF+" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732079AbgKJKTT (ORCPT ); Tue, 10 Nov 2020 05:19:19 -0500 Received: from mo4-p01-ob.smtp.rzone.de ([85.215.255.51]:8830 "EHLO mo4-p01-ob.smtp.rzone.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731466AbgKJKTP (ORCPT ); Tue, 10 Nov 2020 05:19:15 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1605003545; s=strato-dkim-0002; d=hartkopp.net; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: X-RZG-CLASS-ID:X-RZG-AUTH:From:Subject:Sender; bh=no9RTCv0CeqSy5OyOioJuW48Cp+WyB+CT43N7BE4F3s=; b=MPD54UF+rqjeLsDgcmm8JVdgrGJHid6HPn5mXGYx89yiaZDaXnjuD7wVsGUDq3c16m 4FVB1/HKya211C/gIWf3BpuNL2eUGfNLAj4ZXvWWqpIoZlezXXBufDD/KBYAWoS98DdX l4rAm6u/a3nqZbdZXgNV7hLRseLoS+/HIYEs2O+R2xz78wJU4fXA08ntewb5J0ZUFsTO cHdTRiDs9MpUs8GakRJapK3dZMlsbDNSjHwVjp9NtfOn/iecL/Dwf9pPu1ZU8PJA7fXP Ob7V0dLTcN30no/K8IDP1O3kyHuY0p89gyAYXp5EDCeHkjKe823mS3+TDKZVzXPennXp DBLg== X-RZG-AUTH: ":P2MHfkW8eP4Mre39l357AZT/I7AY/7nT2yrDxb8mjGrp7owjzFK3JbFk1mS0k+8CejudJywjsi+/Fw==" X-RZG-CLASS-ID: mo00 Received: from silver.lan by smtp.strato.de (RZmta 47.3.3 DYNA|AUTH) with ESMTPSA id V0298cwAAAJ1AQe (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256 bits)) (Client did not present a certificate); Tue, 10 Nov 2020 11:19:01 +0100 (CET) From: Oliver Hartkopp To: linux-can@vger.kernel.org, mkl@pengutronix.de, mailhol.vincent@wanadoo.fr Cc: netdev@vger.kernel.org, Oliver Hartkopp Subject: [PATCH v6 2/8] can: rename get_can_dlc() macro with can_cc_dlc2len() Date: Tue, 10 Nov 2020 11:18:46 +0100 Message-Id: <20201110101852.1973-3-socketcan@hartkopp.net> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201110101852.1973-1-socketcan@hartkopp.net> References: <20201110101852.1973-1-socketcan@hartkopp.net> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org The get_can_dlc() macro is used to ensure the payload length information of the Classical CAN frame to be max 8 bytes (the CAN_MAX_DLEN). Rename the macro and use the correct constant in preparation of the len/dlc cleanup for Classical CAN frames. Signed-off-by: Oliver Hartkopp --- drivers/net/can/at91_can.c | 2 +- drivers/net/can/c_can/c_can.c | 2 +- drivers/net/can/cc770/cc770.c | 2 +- drivers/net/can/flexcan.c | 2 +- drivers/net/can/grcan.c | 2 +- drivers/net/can/ifi_canfd/ifi_canfd.c | 2 +- drivers/net/can/janz-ican3.c | 4 ++-- drivers/net/can/m_can/m_can.c | 2 +- drivers/net/can/mscan/mscan.c | 2 +- drivers/net/can/pch_can.c | 4 ++-- drivers/net/can/peak_canfd/peak_canfd.c | 2 +- drivers/net/can/rcar/rcar_can.c | 2 +- drivers/net/can/rcar/rcar_canfd.c | 4 ++-- drivers/net/can/sja1000/sja1000.c | 2 +- drivers/net/can/softing/softing_main.c | 2 +- drivers/net/can/spi/hi311x.c | 2 +- drivers/net/can/spi/mcp251x.c | 4 ++-- drivers/net/can/spi/mcp251xfd/mcp251xfd-core.c | 2 +- drivers/net/can/sun4i_can.c | 2 +- drivers/net/can/ti_hecc.c | 2 +- drivers/net/can/usb/ems_usb.c | 2 +- drivers/net/can/usb/esd_usb2.c | 2 +- drivers/net/can/usb/gs_usb.c | 2 +- drivers/net/can/usb/kvaser_usb/kvaser_usb_hydra.c | 4 ++-- drivers/net/can/usb/kvaser_usb/kvaser_usb_leaf.c | 4 ++-- drivers/net/can/usb/mcba_usb.c | 2 +- drivers/net/can/usb/peak_usb/pcan_usb.c | 2 +- drivers/net/can/usb/peak_usb/pcan_usb_fd.c | 2 +- drivers/net/can/usb/ucan.c | 8 ++++---- drivers/net/can/usb/usb_8dev.c | 2 +- drivers/net/can/xilinx_can.c | 4 ++-- include/linux/can/dev.h | 8 ++++---- 32 files changed, 45 insertions(+), 45 deletions(-) diff --git a/drivers/net/can/at91_can.c b/drivers/net/can/at91_can.c index c14de95d2ca7..db06254f8eb7 100644 --- a/drivers/net/can/at91_can.c +++ b/drivers/net/can/at91_can.c @@ -578,11 +578,11 @@ static void at91_read_mb(struct net_device *dev, unsigned int mb, cf->can_id = ((reg_mid >> 0) & CAN_EFF_MASK) | CAN_EFF_FLAG; else cf->can_id = (reg_mid >> 18) & CAN_SFF_MASK; reg_msr = at91_read(priv, AT91_MSR(mb)); - cf->can_dlc = get_can_dlc((reg_msr >> 16) & 0xf); + cf->can_dlc = can_cc_dlc2len((reg_msr >> 16) & 0xf); if (reg_msr & AT91_MSR_MRTR) cf->can_id |= CAN_RTR_FLAG; else { *(u32 *)(cf->data + 0) = at91_read(priv, AT91_MDL(mb)); diff --git a/drivers/net/can/c_can/c_can.c b/drivers/net/can/c_can/c_can.c index 1ccdbe89585b..56cc705959ea 100644 --- a/drivers/net/can/c_can/c_can.c +++ b/drivers/net/can/c_can/c_can.c @@ -395,11 +395,11 @@ static int c_can_read_msg_object(struct net_device *dev, int iface, u32 ctrl) if (!skb) { stats->rx_dropped++; return -ENOMEM; } - frame->can_dlc = get_can_dlc(ctrl & 0x0F); + frame->can_dlc = can_cc_dlc2len(ctrl & 0x0F); arb = priv->read_reg32(priv, C_CAN_IFACE(ARB1_REG, iface)); if (arb & IF_ARB_MSGXTD) frame->can_id = (arb & CAN_EFF_MASK) | CAN_EFF_FLAG; diff --git a/drivers/net/can/cc770/cc770.c b/drivers/net/can/cc770/cc770.c index 07e2b8df5153..3fd2a276dd93 100644 --- a/drivers/net/can/cc770/cc770.c +++ b/drivers/net/can/cc770/cc770.c @@ -484,11 +484,11 @@ static void cc770_rx(struct net_device *dev, unsigned int mo, u8 ctrl1) id |= cc770_read_reg(priv, msgobj[mo].id[0]) << 8; id >>= 5; } cf->can_id = id; - cf->can_dlc = get_can_dlc((config & 0xf0) >> 4); + cf->can_dlc = can_cc_dlc2len((config & 0xf0) >> 4); for (i = 0; i < cf->can_dlc; i++) cf->data[i] = cc770_read_reg(priv, msgobj[mo].data[i]); } stats->rx_packets++; diff --git a/drivers/net/can/flexcan.c b/drivers/net/can/flexcan.c index 881799bd9c5e..d77276cd1d99 100644 --- a/drivers/net/can/flexcan.c +++ b/drivers/net/can/flexcan.c @@ -1001,11 +1001,11 @@ static struct sk_buff *flexcan_mailbox_read(struct can_rx_offload *offload, cfd->len = can_dlc2len(get_canfd_dlc((reg_ctrl >> 16) & 0xf)); if (reg_ctrl & FLEXCAN_MB_CNT_BRS) cfd->flags |= CANFD_BRS; } else { - cfd->len = get_can_dlc((reg_ctrl >> 16) & 0xf); + cfd->len = can_cc_dlc2len((reg_ctrl >> 16) & 0xf); if (reg_ctrl & FLEXCAN_MB_CNT_RTR) cfd->can_id |= CAN_RTR_FLAG; } diff --git a/drivers/net/can/grcan.c b/drivers/net/can/grcan.c index 39802f107eb1..c71c9b8683d5 100644 --- a/drivers/net/can/grcan.c +++ b/drivers/net/can/grcan.c @@ -1199,11 +1199,11 @@ static int grcan_receive(struct net_device *dev, int budget) cf->can_id |= CAN_EFF_FLAG; } else { cf->can_id = ((slot[0] & GRCAN_MSG_BID) >> GRCAN_MSG_BID_BIT); } - cf->can_dlc = get_can_dlc((slot[1] & GRCAN_MSG_DLC) + cf->can_dlc = can_cc_dlc2len((slot[1] & GRCAN_MSG_DLC) >> GRCAN_MSG_DLC_BIT); if (rtr) { cf->can_id |= CAN_RTR_FLAG; } else { for (i = 0; i < cf->can_dlc; i++) { diff --git a/drivers/net/can/ifi_canfd/ifi_canfd.c b/drivers/net/can/ifi_canfd/ifi_canfd.c index 74503cacf594..cc790354a8ee 100644 --- a/drivers/net/can/ifi_canfd/ifi_canfd.c +++ b/drivers/net/can/ifi_canfd/ifi_canfd.c @@ -271,11 +271,11 @@ static void ifi_canfd_read_fifo(struct net_device *ndev) dlc = (rxdlc >> IFI_CANFD_RXFIFO_DLC_DLC_OFFSET) & IFI_CANFD_RXFIFO_DLC_DLC_MASK; if (rxdlc & IFI_CANFD_RXFIFO_DLC_EDL) cf->len = can_dlc2len(dlc); else - cf->len = get_can_dlc(dlc); + cf->len = can_cc_dlc2len(dlc); rxid = readl(priv->base + IFI_CANFD_RXFIFO_ID); id = (rxid >> IFI_CANFD_RXFIFO_ID_ID_OFFSET); if (id & IFI_CANFD_RXFIFO_ID_IDE) { id &= IFI_CANFD_RXFIFO_ID_ID_XTD_MASK; diff --git a/drivers/net/can/janz-ican3.c b/drivers/net/can/janz-ican3.c index f929db893957..6a21af05ba27 100644 --- a/drivers/net/can/janz-ican3.c +++ b/drivers/net/can/janz-ican3.c @@ -914,14 +914,14 @@ static void ican3_to_can_frame(struct ican3_dev *mod, if (desc->data[1] & ICAN3_SFF_RTR) cf->can_id |= CAN_RTR_FLAG; cf->can_id |= desc->data[0] << 3; cf->can_id |= (desc->data[1] & 0xe0) >> 5; - cf->can_dlc = get_can_dlc(desc->data[1] & ICAN3_CAN_DLC_MASK); + cf->can_dlc = can_cc_dlc2len(desc->data[1] & ICAN3_CAN_DLC_MASK); memcpy(cf->data, &desc->data[2], cf->can_dlc); } else { - cf->can_dlc = get_can_dlc(desc->data[0] & ICAN3_CAN_DLC_MASK); + cf->can_dlc = can_cc_dlc2len(desc->data[0] & ICAN3_CAN_DLC_MASK); if (desc->data[0] & ICAN3_EFF_RTR) cf->can_id |= CAN_RTR_FLAG; if (desc->data[0] & ICAN3_EFF) { cf->can_id |= CAN_EFF_FLAG; diff --git a/drivers/net/can/m_can/m_can.c b/drivers/net/can/m_can/m_can.c index 02c5795b7393..ca040de8f909 100644 --- a/drivers/net/can/m_can/m_can.c +++ b/drivers/net/can/m_can/m_can.c @@ -457,11 +457,11 @@ static void m_can_read_fifo(struct net_device *dev, u32 rxfs) } if (dlc & RX_BUF_FDF) cf->len = can_dlc2len((dlc >> 16) & 0x0F); else - cf->len = get_can_dlc((dlc >> 16) & 0x0F); + cf->len = can_cc_dlc2len((dlc >> 16) & 0x0F); id = m_can_fifo_read(cdev, fgi, M_CAN_FIFO_ID); if (id & RX_BUF_XTD) cf->can_id = (id & CAN_EFF_MASK) | CAN_EFF_FLAG; else diff --git a/drivers/net/can/mscan/mscan.c b/drivers/net/can/mscan/mscan.c index 640ba1b356ec..95bf7338b358 100644 --- a/drivers/net/can/mscan/mscan.c +++ b/drivers/net/can/mscan/mscan.c @@ -310,11 +310,11 @@ static void mscan_get_rx_frame(struct net_device *dev, struct can_frame *frame) frame->can_id |= can_id >> 1; if (can_id & 1) frame->can_id |= CAN_RTR_FLAG; - frame->can_dlc = get_can_dlc(in_8(®s->rx.dlr) & 0xf); + frame->can_dlc = can_cc_dlc2len(in_8(®s->rx.dlr) & 0xf); if (!(frame->can_id & CAN_RTR_FLAG)) { void __iomem *data = ®s->rx.dsr1_0; u16 *payload = (u16 *)frame->data; diff --git a/drivers/net/can/pch_can.c b/drivers/net/can/pch_can.c index 5c180d2f3c3c..9509bac8352d 100644 --- a/drivers/net/can/pch_can.c +++ b/drivers/net/can/pch_can.c @@ -681,11 +681,11 @@ static int pch_can_rx_normal(struct net_device *ndev, u32 obj_num, int quota) } if (id2 & PCH_ID2_DIR) cf->can_id |= CAN_RTR_FLAG; - cf->can_dlc = get_can_dlc((ioread32(&priv->regs-> + cf->can_dlc = can_cc_dlc2len((ioread32(&priv->regs-> ifregs[0].mcont)) & 0xF); for (i = 0; i < cf->can_dlc; i += 2) { data_reg = ioread16(&priv->regs->ifregs[0].data[i / 2]); cf->data[i] = data_reg; @@ -713,11 +713,11 @@ static void pch_can_tx_complete(struct net_device *ndev, u32 int_stat) can_get_echo_skb(ndev, int_stat - PCH_RX_OBJ_END - 1); iowrite32(PCH_CMASK_RX_TX_GET | PCH_CMASK_CLRINTPND, &priv->regs->ifregs[1].cmask); pch_can_rw_msg_obj(&priv->regs->ifregs[1].creq, int_stat); - dlc = get_can_dlc(ioread32(&priv->regs->ifregs[1].mcont) & + dlc = can_cc_dlc2len(ioread32(&priv->regs->ifregs[1].mcont) & PCH_IF_MCONT_DLC); stats->tx_bytes += dlc; stats->tx_packets++; if (int_stat == PCH_TX_OBJ_END) netif_wake_queue(ndev); diff --git a/drivers/net/can/peak_canfd/peak_canfd.c b/drivers/net/can/peak_canfd/peak_canfd.c index 40c33b8a5fda..9ea2adea3f0f 100644 --- a/drivers/net/can/peak_canfd/peak_canfd.c +++ b/drivers/net/can/peak_canfd/peak_canfd.c @@ -257,11 +257,11 @@ static int pucan_handle_can_rx(struct peak_canfd_priv *priv, u8 cf_len; if (rx_msg_flags & PUCAN_MSG_EXT_DATA_LEN) cf_len = can_dlc2len(get_canfd_dlc(pucan_msg_get_dlc(msg))); else - cf_len = get_can_dlc(pucan_msg_get_dlc(msg)); + cf_len = can_cc_dlc2len(pucan_msg_get_dlc(msg)); /* if this frame is an echo, */ if (rx_msg_flags & PUCAN_MSG_LOOPED_BACK) { unsigned long flags; diff --git a/drivers/net/can/rcar/rcar_can.c b/drivers/net/can/rcar/rcar_can.c index 48575900adb7..711ef4996b48 100644 --- a/drivers/net/can/rcar/rcar_can.c +++ b/drivers/net/can/rcar/rcar_can.c @@ -657,11 +657,11 @@ static void rcar_can_rx_pkt(struct rcar_can_priv *priv) cf->can_id = (data & CAN_EFF_MASK) | CAN_EFF_FLAG; else cf->can_id = (data >> RCAR_CAN_SID_SHIFT) & CAN_SFF_MASK; dlc = readb(&priv->regs->mb[RCAR_CAN_RX_FIFO_MBX].dlc); - cf->can_dlc = get_can_dlc(dlc); + cf->can_dlc = can_cc_dlc2len(dlc); if (data & RCAR_CAN_RTR) { cf->can_id |= CAN_RTR_FLAG; } else { for (dlc = 0; dlc < cf->can_dlc; dlc++) cf->data[dlc] = diff --git a/drivers/net/can/rcar/rcar_canfd.c b/drivers/net/can/rcar/rcar_canfd.c index de59dd6aad29..899a3218ce5e 100644 --- a/drivers/net/can/rcar/rcar_canfd.c +++ b/drivers/net/can/rcar/rcar_canfd.c @@ -1446,11 +1446,11 @@ static void rcar_canfd_rx_pkt(struct rcar_canfd_channel *priv) if (priv->can.ctrlmode & CAN_CTRLMODE_FD) { if (sts & RCANFD_RFFDSTS_RFFDF) cf->len = can_dlc2len(RCANFD_RFPTR_RFDLC(dlc)); else - cf->len = get_can_dlc(RCANFD_RFPTR_RFDLC(dlc)); + cf->len = can_cc_dlc2len(RCANFD_RFPTR_RFDLC(dlc)); if (sts & RCANFD_RFFDSTS_RFESI) { cf->flags |= CANFD_ESI; netdev_dbg(priv->ndev, "ESI Error\n"); } @@ -1462,11 +1462,11 @@ static void rcar_canfd_rx_pkt(struct rcar_canfd_channel *priv) cf->flags |= CANFD_BRS; rcar_canfd_get_data(priv, cf, RCANFD_F_RFDF(ridx, 0)); } } else { - cf->len = get_can_dlc(RCANFD_RFPTR_RFDLC(dlc)); + cf->len = can_cc_dlc2len(RCANFD_RFPTR_RFDLC(dlc)); if (id & RCANFD_RFID_RFRTR) cf->can_id |= CAN_RTR_FLAG; else rcar_canfd_get_data(priv, cf, RCANFD_C_RFDF(ridx, 0)); } diff --git a/drivers/net/can/sja1000/sja1000.c b/drivers/net/can/sja1000/sja1000.c index 9f107798f904..1f188f2d126e 100644 --- a/drivers/net/can/sja1000/sja1000.c +++ b/drivers/net/can/sja1000/sja1000.c @@ -365,11 +365,11 @@ static void sja1000_rx(struct net_device *dev) dreg = SJA1000_SFF_BUF; id = (priv->read_reg(priv, SJA1000_ID1) << 3) | (priv->read_reg(priv, SJA1000_ID2) >> 5); } - cf->can_dlc = get_can_dlc(fi & 0x0F); + cf->can_dlc = can_cc_dlc2len(fi & 0x0F); if (fi & SJA1000_FI_RTR) { id |= CAN_RTR_FLAG; } else { for (i = 0; i < cf->can_dlc; i++) cf->data[i] = priv->read_reg(priv, dreg++); diff --git a/drivers/net/can/softing/softing_main.c b/drivers/net/can/softing/softing_main.c index 9d2faaa39ce4..39e8275ee7ba 100644 --- a/drivers/net/can/softing/softing_main.c +++ b/drivers/net/can/softing/softing_main.c @@ -259,11 +259,11 @@ static int softing_handle_1(struct softing *card) } } else { if (cmd & CMD_RTR) msg.can_id |= CAN_RTR_FLAG; - msg.can_dlc = get_can_dlc(*ptr++); + msg.can_dlc = can_cc_dlc2len(*ptr++); if (cmd & CMD_XTD) { msg.can_id |= CAN_EFF_FLAG; msg.can_id |= le32_to_cpup((void *)ptr); ptr += 4; } else { diff --git a/drivers/net/can/spi/hi311x.c b/drivers/net/can/spi/hi311x.c index 73d48c3b8ded..728f34b696a7 100644 --- a/drivers/net/can/spi/hi311x.c +++ b/drivers/net/can/spi/hi311x.c @@ -339,11 +339,11 @@ static void hi3110_hw_rx(struct spi_device *spi) (buf[HI3110_FIFO_WOTIME_ID_OFF] << 3) | ((buf[HI3110_FIFO_WOTIME_ID_OFF + 1] & 0xE0) >> 5); } /* Data length */ - frame->can_dlc = get_can_dlc(buf[HI3110_FIFO_WOTIME_DLC_OFF] & 0x0F); + frame->can_dlc = can_cc_dlc2len(buf[HI3110_FIFO_WOTIME_DLC_OFF] & 0x0F); if (buf[HI3110_FIFO_WOTIME_ID_OFF + 3] & HI3110_FIFO_WOTIME_ID_RTR) frame->can_id |= CAN_RTR_FLAG; else memcpy(frame->data, buf + HI3110_FIFO_WOTIME_DAT_OFF, diff --git a/drivers/net/can/spi/mcp251x.c b/drivers/net/can/spi/mcp251x.c index 22d814ae4edc..6ddebb1c4a24 100644 --- a/drivers/net/can/spi/mcp251x.c +++ b/drivers/net/can/spi/mcp251x.c @@ -662,11 +662,11 @@ static void mcp251x_hw_rx_frame(struct spi_device *spi, u8 *buf, int i, len; for (i = 1; i < RXBDAT_OFF; i++) buf[i] = mcp251x_read_reg(spi, RXBCTRL(buf_idx) + i); - len = get_can_dlc(buf[RXBDLC_OFF] & RXBDLC_LEN_MASK); + len = can_cc_dlc2len(buf[RXBDLC_OFF] & RXBDLC_LEN_MASK); for (; i < (RXBDAT_OFF + len); i++) buf[i] = mcp251x_read_reg(spi, RXBCTRL(buf_idx) + i); } else { priv->spi_tx_buf[RXBCTRL_OFF] = INSTRUCTION_READ_RXB(buf_idx); if (spi->controller->flags & SPI_CONTROLLER_HALF_DUPLEX) { @@ -718,11 +718,11 @@ static void mcp251x_hw_rx(struct spi_device *spi, int buf_idx) (buf[RXBSIDL_OFF] >> RXBSIDL_SHIFT); if (buf[RXBSIDL_OFF] & RXBSIDL_SRR) frame->can_id |= CAN_RTR_FLAG; } /* Data length */ - frame->can_dlc = get_can_dlc(buf[RXBDLC_OFF] & RXBDLC_LEN_MASK); + frame->can_dlc = can_cc_dlc2len(buf[RXBDLC_OFF] & RXBDLC_LEN_MASK); memcpy(frame->data, buf + RXBDAT_OFF, frame->can_dlc); priv->net->stats.rx_packets++; priv->net->stats.rx_bytes += frame->can_dlc; diff --git a/drivers/net/can/spi/mcp251xfd/mcp251xfd-core.c b/drivers/net/can/spi/mcp251xfd/mcp251xfd-core.c index 9c215f7c5f81..c0a08400f444 100644 --- a/drivers/net/can/spi/mcp251xfd/mcp251xfd-core.c +++ b/drivers/net/can/spi/mcp251xfd/mcp251xfd-core.c @@ -1408,11 +1408,11 @@ mcp251xfd_hw_rx_obj_to_skb(const struct mcp251xfd_priv *priv, cfd->len = can_dlc2len(get_canfd_dlc(dlc)); } else { if (hw_rx_obj->flags & MCP251XFD_OBJ_FLAGS_RTR) cfd->can_id |= CAN_RTR_FLAG; - cfd->len = get_can_dlc(FIELD_GET(MCP251XFD_OBJ_FLAGS_DLC, + cfd->len = can_cc_dlc2len(FIELD_GET(MCP251XFD_OBJ_FLAGS_DLC, hw_rx_obj->flags)); } memcpy(cfd->data, hw_rx_obj->data, cfd->len); } diff --git a/drivers/net/can/sun4i_can.c b/drivers/net/can/sun4i_can.c index e2c6cf4b2228..0e2569779895 100644 --- a/drivers/net/can/sun4i_can.c +++ b/drivers/net/can/sun4i_can.c @@ -473,11 +473,11 @@ static void sun4i_can_rx(struct net_device *dev) skb = alloc_can_skb(dev, &cf); if (!skb) return; fi = readl(priv->base + SUN4I_REG_BUF0_ADDR); - cf->can_dlc = get_can_dlc(fi & 0x0F); + cf->can_dlc = can_cc_dlc2len(fi & 0x0F); if (fi & SUN4I_MSG_EFF_FLAG) { dreg = SUN4I_REG_BUF5_ADDR; id = (readl(priv->base + SUN4I_REG_BUF1_ADDR) << 21) | (readl(priv->base + SUN4I_REG_BUF2_ADDR) << 13) | (readl(priv->base + SUN4I_REG_BUF3_ADDR) << 5) | diff --git a/drivers/net/can/ti_hecc.c b/drivers/net/can/ti_hecc.c index 9913f5458279..060ce0b16cdc 100644 --- a/drivers/net/can/ti_hecc.c +++ b/drivers/net/can/ti_hecc.c @@ -564,11 +564,11 @@ static struct sk_buff *ti_hecc_mailbox_read(struct can_rx_offload *offload, cf->can_id = (data >> 18) & CAN_SFF_MASK; data = hecc_read_mbx(priv, mbxno, HECC_CANMCF); if (data & HECC_CANMCF_RTR) cf->can_id |= CAN_RTR_FLAG; - cf->can_dlc = get_can_dlc(data & 0xF); + cf->can_dlc = can_cc_dlc2len(data & 0xF); data = hecc_read_mbx(priv, mbxno, HECC_CANMDL); *(__be32 *)(cf->data) = cpu_to_be32(data); if (cf->can_dlc > 4) { data = hecc_read_mbx(priv, mbxno, HECC_CANMDH); diff --git a/drivers/net/can/usb/ems_usb.c b/drivers/net/can/usb/ems_usb.c index 4f52810bebf8..288781934149 100644 --- a/drivers/net/can/usb/ems_usb.c +++ b/drivers/net/can/usb/ems_usb.c @@ -304,11 +304,11 @@ static void ems_usb_rx_can_msg(struct ems_usb *dev, struct ems_cpc_msg *msg) skb = alloc_can_skb(dev->netdev, &cf); if (skb == NULL) return; cf->can_id = le32_to_cpu(msg->msg.can_msg.id); - cf->can_dlc = get_can_dlc(msg->msg.can_msg.length & 0xF); + cf->can_dlc = can_cc_dlc2len(msg->msg.can_msg.length & 0xF); if (msg->type == CPC_MSG_TYPE_EXT_CAN_FRAME || msg->type == CPC_MSG_TYPE_EXT_RTR_FRAME) cf->can_id |= CAN_EFF_FLAG; diff --git a/drivers/net/can/usb/esd_usb2.c b/drivers/net/can/usb/esd_usb2.c index b5d7ed21d7d9..72999de550d1 100644 --- a/drivers/net/can/usb/esd_usb2.c +++ b/drivers/net/can/usb/esd_usb2.c @@ -319,11 +319,11 @@ static void esd_usb2_rx_can_msg(struct esd_usb2_net_priv *priv, stats->rx_dropped++; return; } cf->can_id = id & ESD_IDMASK; - cf->can_dlc = get_can_dlc(msg->msg.rx.dlc & ~ESD_RTR); + cf->can_dlc = can_cc_dlc2len(msg->msg.rx.dlc & ~ESD_RTR); if (id & ESD_EXTID) cf->can_id |= CAN_EFF_FLAG; if (msg->msg.rx.dlc & ESD_RTR) { diff --git a/drivers/net/can/usb/gs_usb.c b/drivers/net/can/usb/gs_usb.c index 3005157059ca..b1729b208788 100644 --- a/drivers/net/can/usb/gs_usb.c +++ b/drivers/net/can/usb/gs_usb.c @@ -329,11 +329,11 @@ static void gs_usb_receive_bulk_callback(struct urb *urb) if (!skb) return; cf->can_id = hf->can_id; - cf->can_dlc = get_can_dlc(hf->can_dlc); + cf->can_dlc = can_cc_dlc2len(hf->can_dlc); memcpy(cf->data, hf->data, 8); /* ERROR frames tell us information about the controller */ if (hf->can_id & CAN_ERR_FLAG) gs_update_state(dev, cf); diff --git a/drivers/net/can/usb/kvaser_usb/kvaser_usb_hydra.c b/drivers/net/can/usb/kvaser_usb/kvaser_usb_hydra.c index 7ab87a758754..399e9698ffeb 100644 --- a/drivers/net/can/usb/kvaser_usb/kvaser_usb_hydra.c +++ b/drivers/net/can/usb/kvaser_usb/kvaser_usb_hydra.c @@ -1178,11 +1178,11 @@ static void kvaser_usb_hydra_rx_msg_std(const struct kvaser_usb *dev, } if (flags & KVASER_USB_HYDRA_CF_FLAG_OVERRUN) kvaser_usb_can_rx_over_error(priv->netdev); - cf->can_dlc = get_can_dlc(cmd->rx_can.dlc); + cf->can_dlc = can_cc_dlc2len(cmd->rx_can.dlc); if (flags & KVASER_USB_HYDRA_CF_FLAG_REMOTE_FRAME) cf->can_id |= CAN_RTR_FLAG; else memcpy(cf->data, cmd->rx_can.data, cf->can_dlc); @@ -1255,11 +1255,11 @@ static void kvaser_usb_hydra_rx_msg_ext(const struct kvaser_usb *dev, if (flags & KVASER_USB_HYDRA_CF_FLAG_BRS) cf->flags |= CANFD_BRS; if (flags & KVASER_USB_HYDRA_CF_FLAG_ESI) cf->flags |= CANFD_ESI; } else { - cf->len = get_can_dlc(dlc); + cf->len = can_cc_dlc2len(dlc); } if (flags & KVASER_USB_HYDRA_CF_FLAG_REMOTE_FRAME) cf->can_id |= CAN_RTR_FLAG; else diff --git a/drivers/net/can/usb/kvaser_usb/kvaser_usb_leaf.c b/drivers/net/can/usb/kvaser_usb/kvaser_usb_leaf.c index 1b9957f12459..916ab994cce4 100644 --- a/drivers/net/can/usb/kvaser_usb/kvaser_usb_leaf.c +++ b/drivers/net/can/usb/kvaser_usb/kvaser_usb_leaf.c @@ -976,11 +976,11 @@ static void kvaser_usb_leaf_rx_can_msg(const struct kvaser_usb *dev, if (cf->can_id & KVASER_EXTENDED_FRAME) cf->can_id &= CAN_EFF_MASK | CAN_EFF_FLAG; else cf->can_id &= CAN_SFF_MASK; - cf->can_dlc = get_can_dlc(cmd->u.leaf.log_message.dlc); + cf->can_dlc = can_cc_dlc2len(cmd->u.leaf.log_message.dlc); if (cmd->u.leaf.log_message.flags & MSG_FLAG_REMOTE_FRAME) cf->can_id |= CAN_RTR_FLAG; else memcpy(cf->data, &cmd->u.leaf.log_message.data, @@ -994,11 +994,11 @@ static void kvaser_usb_leaf_rx_can_msg(const struct kvaser_usb *dev, ((rx_data[3] & 0xff) << 6) | (rx_data[4] & 0x3f); cf->can_id |= CAN_EFF_FLAG; } - cf->can_dlc = get_can_dlc(rx_data[5]); + cf->can_dlc = can_cc_dlc2len(rx_data[5]); if (cmd->u.rx_can_header.flag & MSG_FLAG_REMOTE_FRAME) cf->can_id |= CAN_RTR_FLAG; else memcpy(cf->data, &rx_data[6], cf->can_dlc); diff --git a/drivers/net/can/usb/mcba_usb.c b/drivers/net/can/usb/mcba_usb.c index 5857b37dcd96..0e6d180597f3 100644 --- a/drivers/net/can/usb/mcba_usb.c +++ b/drivers/net/can/usb/mcba_usb.c @@ -449,11 +449,11 @@ static void mcba_usb_process_can(struct mcba_priv *priv, } if (msg->dlc & MCBA_DLC_RTR_MASK) cf->can_id |= CAN_RTR_FLAG; - cf->can_dlc = get_can_dlc(msg->dlc & MCBA_DLC_MASK); + cf->can_dlc = can_cc_dlc2len(msg->dlc & MCBA_DLC_MASK); memcpy(cf->data, msg->data, cf->can_dlc); stats->rx_packets++; stats->rx_bytes += cf->can_dlc; diff --git a/drivers/net/can/usb/peak_usb/pcan_usb.c b/drivers/net/can/usb/peak_usb/pcan_usb.c index 63bd2ed96697..f7fc82203489 100644 --- a/drivers/net/can/usb/peak_usb/pcan_usb.c +++ b/drivers/net/can/usb/peak_usb/pcan_usb.c @@ -732,11 +732,11 @@ static int pcan_usb_decode_data(struct pcan_usb_msg_context *mc, u8 status_len) mc->ptr += 2; cf->can_id = le16_to_cpu(tmp16) >> 5; } - cf->can_dlc = get_can_dlc(rec_len); + cf->can_dlc = can_cc_dlc2len(rec_len); /* Only first packet timestamp is a word */ if (pcan_usb_decode_ts(mc, !mc->rec_ts_idx)) goto decode_failed; diff --git a/drivers/net/can/usb/peak_usb/pcan_usb_fd.c b/drivers/net/can/usb/peak_usb/pcan_usb_fd.c index d29d20525588..1f08dd22b3d5 100644 --- a/drivers/net/can/usb/peak_usb/pcan_usb_fd.c +++ b/drivers/net/can/usb/peak_usb/pcan_usb_fd.c @@ -497,11 +497,11 @@ static int pcan_usb_fd_decode_canmsg(struct pcan_usb_fd_if *usb_if, /* CAN 2.0 frame case */ skb = alloc_can_skb(netdev, (struct can_frame **)&cfd); if (!skb) return -ENOMEM; - cfd->len = get_can_dlc(pucan_msg_get_dlc(rm)); + cfd->len = can_cc_dlc2len(pucan_msg_get_dlc(rm)); } cfd->can_id = le32_to_cpu(rm->can_id); if (rx_msg_flags & PUCAN_MSG_EXT_ID) diff --git a/drivers/net/can/usb/ucan.c b/drivers/net/can/usb/ucan.c index dc5290b36598..072058c6f6e8 100644 --- a/drivers/net/can/usb/ucan.c +++ b/drivers/net/can/usb/ucan.c @@ -301,16 +301,16 @@ struct ucan_priv { spinlock_t context_lock; unsigned int available_tx_urbs; struct ucan_urb_context *context_array; }; -static u8 ucan_get_can_dlc(struct ucan_can_msg *msg, u16 len) +static u8 ucan_can_cc_dlc2len(struct ucan_can_msg *msg, u16 len) { if (le32_to_cpu(msg->id) & CAN_RTR_FLAG) - return get_can_dlc(msg->dlc); + return can_cc_dlc2len(msg->dlc); else - return get_can_dlc(len - (UCAN_IN_HDR_SIZE + sizeof(msg->id))); + return can_cc_dlc2len(len - (UCAN_IN_HDR_SIZE + sizeof(msg->id))); } static void ucan_release_context_array(struct ucan_priv *up) { if (!up->context_array) @@ -612,11 +612,11 @@ static void ucan_rx_can_msg(struct ucan_priv *up, struct ucan_message_in *m) /* fill the can frame */ cf->can_id = canid; /* compute DLC taking RTR_FLAG into account */ - cf->can_dlc = ucan_get_can_dlc(&m->msg.can_msg, len); + cf->can_dlc = ucan_can_cc_dlc2len(&m->msg.can_msg, len); /* copy the payload of non RTR frames */ if (!(cf->can_id & CAN_RTR_FLAG) || (cf->can_id & CAN_ERR_FLAG)) memcpy(cf->data, m->msg.can_msg.data, cf->can_dlc); diff --git a/drivers/net/can/usb/usb_8dev.c b/drivers/net/can/usb/usb_8dev.c index 62749c67c959..216c58f8df6e 100644 --- a/drivers/net/can/usb/usb_8dev.c +++ b/drivers/net/can/usb/usb_8dev.c @@ -468,11 +468,11 @@ static void usb_8dev_rx_can_msg(struct usb_8dev_priv *priv, skb = alloc_can_skb(priv->netdev, &cf); if (!skb) return; cf->can_id = be32_to_cpu(msg->id); - cf->can_dlc = get_can_dlc(msg->dlc & 0xF); + cf->can_dlc = can_cc_dlc2len(msg->dlc & 0xF); if (msg->flags & USB_8DEV_EXTID) cf->can_id |= CAN_EFF_FLAG; if (msg->flags & USB_8DEV_RTR) diff --git a/drivers/net/can/xilinx_can.c b/drivers/net/can/xilinx_can.c index 48d746e18f30..73e8b1df1071 100644 --- a/drivers/net/can/xilinx_can.c +++ b/drivers/net/can/xilinx_can.c @@ -757,11 +757,11 @@ static int xcan_rx(struct net_device *ndev, int frame_base) id_xcan = priv->read_reg(priv, XCAN_FRAME_ID_OFFSET(frame_base)); dlc = priv->read_reg(priv, XCAN_FRAME_DLC_OFFSET(frame_base)) >> XCAN_DLCR_DLC_SHIFT; /* Change Xilinx CAN data length format to socketCAN data format */ - cf->can_dlc = get_can_dlc(dlc); + cf->can_dlc = can_cc_dlc2len(dlc); /* Change Xilinx CAN ID format to socketCAN ID format */ if (id_xcan & XCAN_IDR_IDE_MASK) { /* The received frame is an Extended format frame */ cf->can_id = (id_xcan & XCAN_IDR_ID1_MASK) >> 3; @@ -833,11 +833,11 @@ static int xcanfd_rx(struct net_device *ndev, int frame_base) */ if (dlc & XCAN_DLCR_EDL_MASK) cf->len = can_dlc2len((dlc & XCAN_DLCR_DLC_MASK) >> XCAN_DLCR_DLC_SHIFT); else - cf->len = get_can_dlc((dlc & XCAN_DLCR_DLC_MASK) >> + cf->len = can_cc_dlc2len((dlc & XCAN_DLCR_DLC_MASK) >> XCAN_DLCR_DLC_SHIFT); /* Change Xilinx CAN ID format to socketCAN ID format */ if (id_xcan & XCAN_IDR_IDE_MASK) { /* The received frame is an Extended format frame */ diff --git a/include/linux/can/dev.h b/include/linux/can/dev.h index 41ff31795320..9bc84c6978ec 100644 --- a/include/linux/can/dev.h +++ b/include/linux/can/dev.h @@ -96,18 +96,18 @@ static inline unsigned int can_bit_time(const struct can_bittiming *bt) { return CAN_SYNC_SEG + bt->prop_seg + bt->phase_seg1 + bt->phase_seg2; } /* - * get_can_dlc(value) - helper macro to cast a given data length code (dlc) - * to u8 and ensure the dlc value to be max. 8 bytes. + * can_cc_dlc2len(value) - convert a given data length code (dlc) of a + * Classical CAN frame into a valid data length of max. 8 bytes. * * To be used in the CAN netdriver receive path to ensure conformance with * ISO 11898-1 Chapter 8.4.2.3 (DLC field) */ -#define get_can_dlc(i) (min_t(u8, (i), CAN_MAX_DLC)) -#define get_canfd_dlc(i) (min_t(u8, (i), CANFD_MAX_DLC)) +#define can_cc_dlc2len(dlc) (min_t(u8, (dlc), CAN_MAX_DLEN)) +#define get_canfd_dlc(dlc) (min_t(u8, (dlc), CANFD_MAX_DLC)) /* Check for outgoing skbs that have not been created by the CAN subsystem */ static inline bool can_skb_headroom_valid(struct net_device *dev, struct sk_buff *skb) { From patchwork Tue Nov 10 10:18:47 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oliver Hartkopp X-Patchwork-Id: 11893781 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A96BBC4741F for ; Tue, 10 Nov 2020 10:19:32 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5FDF920639 for ; Tue, 10 Nov 2020 10:19:32 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=hartkopp.net header.i=@hartkopp.net header.b="H+pK9ESw" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731924AbgKJKTb (ORCPT ); Tue, 10 Nov 2020 05:19:31 -0500 Received: from mo4-p01-ob.smtp.rzone.de ([85.215.255.52]:22124 "EHLO mo4-p01-ob.smtp.rzone.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731283AbgKJKTH (ORCPT ); Tue, 10 Nov 2020 05:19:07 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1605003544; s=strato-dkim-0002; d=hartkopp.net; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: X-RZG-CLASS-ID:X-RZG-AUTH:From:Subject:Sender; bh=ShD5wP8N+wA7/jyGa7FFyWPH1RJMVxvRkuGIWHO4RkY=; b=H+pK9ESwdsq8LiVQiw0Rq4IhOJlV5KzkuMFASowICnGYadeaSMw+rpTbbCpqYgfu3E Fy4CF8Pm4pwde/yfdfIpv1WsGAn2ntH3G4Jw0MOedbceyN1OvjCxn0eLji1YYkbs1PnT qmA/oW3srOIsuJLOvO7fb+qQZ2kL6y+0VNHx0mAyArBYHBcGi174cX16jJIwfHe3hIHY 8xXlDcoiARpQu09fgYiLvpcc/BE1q4GA0v6PEUtMpOBKDoHNXp0qmPFUzoAp7o49PnIc LyP8aQB7fK+IebXv3Lbjzkidluqhf455iFqRBn79fYtPUh3ScWP1S4XnarqO+sQ4ee7s aWOA== X-RZG-AUTH: ":P2MHfkW8eP4Mre39l357AZT/I7AY/7nT2yrDxb8mjGrp7owjzFK3JbFk1mS0k+8CejudJywjsi+/Fw==" X-RZG-CLASS-ID: mo00 Received: from silver.lan by smtp.strato.de (RZmta 47.3.3 DYNA|AUTH) with ESMTPSA id V0298cwAAAJ2AQf (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256 bits)) (Client did not present a certificate); Tue, 10 Nov 2020 11:19:02 +0100 (CET) From: Oliver Hartkopp To: linux-can@vger.kernel.org, mkl@pengutronix.de, mailhol.vincent@wanadoo.fr Cc: netdev@vger.kernel.org, Oliver Hartkopp Subject: [PATCH v6 3/8] can: remove obsolete get_canfd_dlc() macro Date: Tue, 10 Nov 2020 11:18:47 +0100 Message-Id: <20201110101852.1973-4-socketcan@hartkopp.net> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201110101852.1973-1-socketcan@hartkopp.net> References: <20201110101852.1973-1-socketcan@hartkopp.net> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org The macro was always used together with can_dlc2len() which sanitizes the given dlc value on its own. Signed-off-by: Oliver Hartkopp --- drivers/net/can/flexcan.c | 2 +- drivers/net/can/peak_canfd/peak_canfd.c | 2 +- drivers/net/can/spi/mcp251xfd/mcp251xfd-core.c | 2 +- drivers/net/can/usb/kvaser_usb/kvaser_usb_hydra.c | 2 +- drivers/net/can/usb/peak_usb/pcan_usb_fd.c | 2 +- include/linux/can/dev.h | 1 - include/linux/can/dev/peak_canfd.h | 2 +- 7 files changed, 6 insertions(+), 7 deletions(-) diff --git a/drivers/net/can/flexcan.c b/drivers/net/can/flexcan.c index d77276cd1d99..e76fb1500fa1 100644 --- a/drivers/net/can/flexcan.c +++ b/drivers/net/can/flexcan.c @@ -996,11 +996,11 @@ static struct sk_buff *flexcan_mailbox_read(struct can_rx_offload *offload, cfd->can_id = ((reg_id >> 0) & CAN_EFF_MASK) | CAN_EFF_FLAG; else cfd->can_id = (reg_id >> 18) & CAN_SFF_MASK; if (reg_ctrl & FLEXCAN_MB_CNT_EDL) { - cfd->len = can_dlc2len(get_canfd_dlc((reg_ctrl >> 16) & 0xf)); + cfd->len = can_dlc2len((reg_ctrl >> 16) & 0xf); if (reg_ctrl & FLEXCAN_MB_CNT_BRS) cfd->flags |= CANFD_BRS; } else { cfd->len = can_cc_dlc2len((reg_ctrl >> 16) & 0xf); diff --git a/drivers/net/can/peak_canfd/peak_canfd.c b/drivers/net/can/peak_canfd/peak_canfd.c index 9ea2adea3f0f..c6077e07214e 100644 --- a/drivers/net/can/peak_canfd/peak_canfd.c +++ b/drivers/net/can/peak_canfd/peak_canfd.c @@ -255,11 +255,11 @@ static int pucan_handle_can_rx(struct peak_canfd_priv *priv, struct sk_buff *skb; const u16 rx_msg_flags = le16_to_cpu(msg->flags); u8 cf_len; if (rx_msg_flags & PUCAN_MSG_EXT_DATA_LEN) - cf_len = can_dlc2len(get_canfd_dlc(pucan_msg_get_dlc(msg))); + cf_len = can_dlc2len(pucan_msg_get_dlc(msg)); else cf_len = can_cc_dlc2len(pucan_msg_get_dlc(msg)); /* if this frame is an echo, */ if (rx_msg_flags & PUCAN_MSG_LOOPED_BACK) { diff --git a/drivers/net/can/spi/mcp251xfd/mcp251xfd-core.c b/drivers/net/can/spi/mcp251xfd/mcp251xfd-core.c index c0a08400f444..3bac7274ee5b 100644 --- a/drivers/net/can/spi/mcp251xfd/mcp251xfd-core.c +++ b/drivers/net/can/spi/mcp251xfd/mcp251xfd-core.c @@ -1403,11 +1403,11 @@ mcp251xfd_hw_rx_obj_to_skb(const struct mcp251xfd_priv *priv, if (hw_rx_obj->flags & MCP251XFD_OBJ_FLAGS_BRS) cfd->flags |= CANFD_BRS; dlc = FIELD_GET(MCP251XFD_OBJ_FLAGS_DLC, hw_rx_obj->flags); - cfd->len = can_dlc2len(get_canfd_dlc(dlc)); + cfd->len = can_dlc2len(dlc); } else { if (hw_rx_obj->flags & MCP251XFD_OBJ_FLAGS_RTR) cfd->can_id |= CAN_RTR_FLAG; cfd->len = can_cc_dlc2len(FIELD_GET(MCP251XFD_OBJ_FLAGS_DLC, diff --git a/drivers/net/can/usb/kvaser_usb/kvaser_usb_hydra.c b/drivers/net/can/usb/kvaser_usb/kvaser_usb_hydra.c index 399e9698ffeb..906a3a340131 100644 --- a/drivers/net/can/usb/kvaser_usb/kvaser_usb_hydra.c +++ b/drivers/net/can/usb/kvaser_usb/kvaser_usb_hydra.c @@ -1249,11 +1249,11 @@ static void kvaser_usb_hydra_rx_msg_ext(const struct kvaser_usb *dev, if (flags & KVASER_USB_HYDRA_CF_FLAG_OVERRUN) kvaser_usb_can_rx_over_error(priv->netdev); if (flags & KVASER_USB_HYDRA_CF_FLAG_FDF) { - cf->len = can_dlc2len(get_canfd_dlc(dlc)); + cf->len = can_dlc2len(dlc); if (flags & KVASER_USB_HYDRA_CF_FLAG_BRS) cf->flags |= CANFD_BRS; if (flags & KVASER_USB_HYDRA_CF_FLAG_ESI) cf->flags |= CANFD_ESI; } else { diff --git a/drivers/net/can/usb/peak_usb/pcan_usb_fd.c b/drivers/net/can/usb/peak_usb/pcan_usb_fd.c index 1f08dd22b3d5..1233ef20646a 100644 --- a/drivers/net/can/usb/peak_usb/pcan_usb_fd.c +++ b/drivers/net/can/usb/peak_usb/pcan_usb_fd.c @@ -490,11 +490,11 @@ static int pcan_usb_fd_decode_canmsg(struct pcan_usb_fd_if *usb_if, cfd->flags |= CANFD_BRS; if (rx_msg_flags & PUCAN_MSG_ERROR_STATE_IND) cfd->flags |= CANFD_ESI; - cfd->len = can_dlc2len(get_canfd_dlc(pucan_msg_get_dlc(rm))); + cfd->len = can_dlc2len(pucan_msg_get_dlc(rm)); } else { /* CAN 2.0 frame case */ skb = alloc_can_skb(netdev, (struct can_frame **)&cfd); if (!skb) return -ENOMEM; diff --git a/include/linux/can/dev.h b/include/linux/can/dev.h index 9bc84c6978ec..802606e36b58 100644 --- a/include/linux/can/dev.h +++ b/include/linux/can/dev.h @@ -103,11 +103,10 @@ static inline unsigned int can_bit_time(const struct can_bittiming *bt) * * To be used in the CAN netdriver receive path to ensure conformance with * ISO 11898-1 Chapter 8.4.2.3 (DLC field) */ #define can_cc_dlc2len(dlc) (min_t(u8, (dlc), CAN_MAX_DLEN)) -#define get_canfd_dlc(dlc) (min_t(u8, (dlc), CANFD_MAX_DLC)) /* Check for outgoing skbs that have not been created by the CAN subsystem */ static inline bool can_skb_headroom_valid(struct net_device *dev, struct sk_buff *skb) { diff --git a/include/linux/can/dev/peak_canfd.h b/include/linux/can/dev/peak_canfd.h index 5fd627e9da19..f38772fd0c07 100644 --- a/include/linux/can/dev/peak_canfd.h +++ b/include/linux/can/dev/peak_canfd.h @@ -280,11 +280,11 @@ static inline int pucan_msg_get_channel(const struct pucan_rx_msg *msg) { return msg->channel_dlc & 0xf; } /* return the dlc value from any received message channel_dlc field */ -static inline int pucan_msg_get_dlc(const struct pucan_rx_msg *msg) +static inline u8 pucan_msg_get_dlc(const struct pucan_rx_msg *msg) { return msg->channel_dlc >> 4; } static inline int pucan_ermsg_get_channel(const struct pucan_error_msg *msg) From patchwork Tue Nov 10 10:18:48 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oliver Hartkopp X-Patchwork-Id: 11893783 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5C03DC4741F for ; Tue, 10 Nov 2020 10:19:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id CF332207BB for ; Tue, 10 Nov 2020 10:19:35 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=hartkopp.net header.i=@hartkopp.net header.b="jNDJFkAI" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731114AbgKJKTf (ORCPT ); Tue, 10 Nov 2020 05:19:35 -0500 Received: from mo4-p02-ob.smtp.rzone.de ([85.215.255.81]:25031 "EHLO mo4-p02-ob.smtp.rzone.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731929AbgKJKTe (ORCPT ); Tue, 10 Nov 2020 05:19:34 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1605003552; s=strato-dkim-0002; d=hartkopp.net; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: X-RZG-CLASS-ID:X-RZG-AUTH:From:Subject:Sender; bh=EkNKXZdCL8KK1xWoczcIILGeC3lzAUpD2xgDrjicOPM=; b=jNDJFkAIZHdkKxSomPFVA9QcfpnXLnmXrKn6Hf9w0LOe3OorhYHher2Ivg1cnWc7u1 2u0LtS8i60+3lTK2FmhVcT4kA//Mm7Ghwb+ksfWMo0uCITqFQsFsmGoJHX2I0Lw7TpiC k5fvn1k4MwXZrQMjsbmXYnz5mYdmM1YDIolfX2I92LnHZozmZEKG9UikVZhk8OWrlSWB g56xQvJr+FBmapbV1Yl+dP6PZNN8cd01CNEyRLAenTRZgdyg6fLq6/M3RtnhjVuQ9nKh Etvj0DgCCo8wvuUjx+sLqvChV1xofbmK5ew1XAaCOXRzFCQwJRZE2zOINvQMMZd5lUdZ pEJg== X-RZG-AUTH: ":P2MHfkW8eP4Mre39l357AZT/I7AY/7nT2yrDxb8mjGrp7owjzFK3JbFk1mS0k+8CejudJywjsi+/Fw==" X-RZG-CLASS-ID: mo00 Received: from silver.lan by smtp.strato.de (RZmta 47.3.3 DYNA|AUTH) with ESMTPSA id V0298cwAAAJ2AQg (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256 bits)) (Client did not present a certificate); Tue, 10 Nov 2020 11:19:02 +0100 (CET) From: Oliver Hartkopp To: linux-can@vger.kernel.org, mkl@pengutronix.de, mailhol.vincent@wanadoo.fr Cc: netdev@vger.kernel.org, Oliver Hartkopp Subject: [PATCH v6 4/8] can: replace can_dlc as variable/element for payload length Date: Tue, 10 Nov 2020 11:18:48 +0100 Message-Id: <20201110101852.1973-5-socketcan@hartkopp.net> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201110101852.1973-1-socketcan@hartkopp.net> References: <20201110101852.1973-1-socketcan@hartkopp.net> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org The naming of can_dlc as element of struct can_frame and also as variable name is misleading as it claims to be a 'data length CODE' but in reality it always was a plain data length. With the indroduction of a new 'len' element in struct can_frame we can now remove can_dlc as name and make clear which of the former uses was a plain length (-> 'len') or a data length code (-> 'dlc') value. Signed-off-by: Oliver Hartkopp --- drivers/net/can/at91_can.c | 14 ++++---- drivers/net/can/c_can/c_can.c | 20 ++++++------ drivers/net/can/cc770/cc770.c | 14 ++++---- drivers/net/can/dev.c | 10 +++--- drivers/net/can/grcan.c | 10 +++--- drivers/net/can/ifi_canfd/ifi_canfd.c | 4 +-- drivers/net/can/janz-ican3.c | 20 ++++++------ drivers/net/can/kvaser_pciefd.c | 4 +-- drivers/net/can/m_can/m_can.c | 4 +-- drivers/net/can/mscan/mscan.c | 20 ++++++------ drivers/net/can/pch_can.c | 12 +++---- drivers/net/can/peak_canfd/peak_canfd.c | 12 +++---- drivers/net/can/rcar/rcar_can.c | 14 ++++---- drivers/net/can/rcar/rcar_canfd.c | 4 +-- drivers/net/can/rx-offload.c | 2 +- drivers/net/can/sja1000/sja1000.c | 10 +++--- drivers/net/can/slcan.c | 32 +++++++++---------- drivers/net/can/softing/softing_fw.c | 2 +- drivers/net/can/softing/softing_main.c | 14 ++++---- drivers/net/can/spi/hi311x.c | 20 ++++++------ drivers/net/can/spi/mcp251x.c | 18 +++++------ drivers/net/can/sun4i_can.c | 10 +++--- drivers/net/can/ti_hecc.c | 8 ++--- drivers/net/can/usb/ems_usb.c | 16 +++++----- drivers/net/can/usb/esd_usb2.c | 16 +++++----- drivers/net/can/usb/gs_usb.c | 14 ++++---- .../net/can/usb/kvaser_usb/kvaser_usb_core.c | 2 +- .../net/can/usb/kvaser_usb/kvaser_usb_hydra.c | 16 +++++----- .../net/can/usb/kvaser_usb/kvaser_usb_leaf.c | 22 ++++++------- drivers/net/can/usb/mcba_usb.c | 10 +++--- drivers/net/can/usb/peak_usb/pcan_usb.c | 14 ++++---- drivers/net/can/usb/peak_usb/pcan_usb_fd.c | 10 +++--- drivers/net/can/usb/peak_usb/pcan_usb_pro.c | 14 ++++---- drivers/net/can/usb/ucan.c | 14 ++++---- drivers/net/can/usb/usb_8dev.c | 14 ++++---- drivers/net/can/xilinx_can.c | 10 +++--- include/linux/can/dev.h | 4 +-- net/can/af_can.c | 2 +- net/can/gw.c | 2 +- net/can/j1939/main.c | 4 +-- 40 files changed, 231 insertions(+), 231 deletions(-) diff --git a/drivers/net/can/at91_can.c b/drivers/net/can/at91_can.c index db06254f8eb7..5284f0ab3b06 100644 --- a/drivers/net/can/at91_can.c +++ b/drivers/net/can/at91_can.c @@ -466,11 +466,11 @@ static netdev_tx_t at91_start_xmit(struct sk_buff *skb, struct net_device *dev) netdev_err(dev, "BUG! TX buffer full when queue awake!\n"); return NETDEV_TX_BUSY; } reg_mid = at91_can_id_to_reg_mid(cf->can_id); reg_mcr = ((cf->can_id & CAN_RTR_FLAG) ? AT91_MCR_MRTR : 0) | - (cf->can_dlc << 16) | AT91_MCR_MTCR; + (cf->len << 16) | AT91_MCR_MTCR; /* disable MB while writing ID (see datasheet) */ set_mb_mode(priv, mb, AT91_MB_MODE_DISABLED); at91_write(priv, AT91_MID(mb), reg_mid); set_mb_mode_prio(priv, mb, AT91_MB_MODE_TX, prio); @@ -479,11 +479,11 @@ static netdev_tx_t at91_start_xmit(struct sk_buff *skb, struct net_device *dev) at91_write(priv, AT91_MDH(mb), *(u32 *)(cf->data + 4)); /* This triggers transmission */ at91_write(priv, AT91_MCR(mb), reg_mcr); - stats->tx_bytes += cf->can_dlc; + stats->tx_bytes += cf->len; /* _NOTE_: subtract AT91_MB_TX_FIRST offset from mb! */ can_put_echo_skb(skb, dev, mb - get_mb_tx_first(priv)); /* @@ -552,11 +552,11 @@ static void at91_rx_overflow_err(struct net_device *dev) cf->can_id |= CAN_ERR_CRTL; cf->data[1] = CAN_ERR_CRTL_RX_OVERFLOW; stats->rx_packets++; - stats->rx_bytes += cf->can_dlc; + stats->rx_bytes += cf->len; netif_receive_skb(skb); } /** * at91_read_mb - read CAN msg from mailbox (lowlevel impl) @@ -578,11 +578,11 @@ static void at91_read_mb(struct net_device *dev, unsigned int mb, cf->can_id = ((reg_mid >> 0) & CAN_EFF_MASK) | CAN_EFF_FLAG; else cf->can_id = (reg_mid >> 18) & CAN_SFF_MASK; reg_msr = at91_read(priv, AT91_MSR(mb)); - cf->can_dlc = can_cc_dlc2len((reg_msr >> 16) & 0xf); + cf->len = can_cc_dlc2len((reg_msr >> 16) & 0xf); if (reg_msr & AT91_MSR_MRTR) cf->can_id |= CAN_RTR_FLAG; else { *(u32 *)(cf->data + 0) = at91_read(priv, AT91_MDL(mb)); @@ -617,11 +617,11 @@ static void at91_read_msg(struct net_device *dev, unsigned int mb) } at91_read_mb(dev, mb, cf); stats->rx_packets++; - stats->rx_bytes += cf->can_dlc; + stats->rx_bytes += cf->len; netif_receive_skb(skb); can_led_event(dev, CAN_LED_EVENT_RX); } @@ -778,11 +778,11 @@ static int at91_poll_err(struct net_device *dev, int quota, u32 reg_sr) return 0; at91_poll_err_frame(dev, cf, reg_sr); dev->stats.rx_packets++; - dev->stats.rx_bytes += cf->can_dlc; + dev->stats.rx_bytes += cf->len; netif_receive_skb(skb); return 1; } @@ -1045,11 +1045,11 @@ static void at91_irq_err(struct net_device *dev) return; at91_irq_err_state(dev, cf, new_state); dev->stats.rx_packets++; - dev->stats.rx_bytes += cf->can_dlc; + dev->stats.rx_bytes += cf->len; netif_rx(skb); priv->can.state = new_state; } diff --git a/drivers/net/can/c_can/c_can.c b/drivers/net/can/c_can/c_can.c index 56cc705959ea..0420f09f2b70 100644 --- a/drivers/net/can/c_can/c_can.c +++ b/drivers/net/can/c_can/c_can.c @@ -304,11 +304,11 @@ static void c_can_inval_msg_object(struct net_device *dev, int iface, int obj) static void c_can_setup_tx_object(struct net_device *dev, int iface, struct can_frame *frame, int idx) { struct c_can_priv *priv = netdev_priv(dev); - u16 ctrl = IF_MCONT_TX | frame->can_dlc; + u16 ctrl = IF_MCONT_TX | frame->len; bool rtr = frame->can_id & CAN_RTR_FLAG; u32 arb = IF_ARB_MSGVAL; int i; if (frame->can_id & CAN_EFF_FLAG) { @@ -337,19 +337,19 @@ static void c_can_setup_tx_object(struct net_device *dev, int iface, priv->write_reg(priv, C_CAN_IFACE(MSGCTRL_REG, iface), ctrl); if (priv->type == BOSCH_D_CAN) { u32 data = 0, dreg = C_CAN_IFACE(DATA1_REG, iface); - for (i = 0; i < frame->can_dlc; i += 4, dreg += 2) { + for (i = 0; i < frame->len; i += 4, dreg += 2) { data = (u32)frame->data[i]; data |= (u32)frame->data[i + 1] << 8; data |= (u32)frame->data[i + 2] << 16; data |= (u32)frame->data[i + 3] << 24; priv->write_reg32(priv, dreg, data); } } else { - for (i = 0; i < frame->can_dlc; i += 2) { + for (i = 0; i < frame->len; i += 2) { priv->write_reg(priv, C_CAN_IFACE(DATA1_REG, iface) + i / 2, frame->data[i] | (frame->data[i + 1] << 8)); } @@ -395,11 +395,11 @@ static int c_can_read_msg_object(struct net_device *dev, int iface, u32 ctrl) if (!skb) { stats->rx_dropped++; return -ENOMEM; } - frame->can_dlc = can_cc_dlc2len(ctrl & 0x0F); + frame->len = can_cc_dlc2len(ctrl & 0x0F); arb = priv->read_reg32(priv, C_CAN_IFACE(ARB1_REG, iface)); if (arb & IF_ARB_MSGXTD) frame->can_id = (arb & CAN_EFF_MASK) | CAN_EFF_FLAG; @@ -410,28 +410,28 @@ static int c_can_read_msg_object(struct net_device *dev, int iface, u32 ctrl) frame->can_id |= CAN_RTR_FLAG; } else { int i, dreg = C_CAN_IFACE(DATA1_REG, iface); if (priv->type == BOSCH_D_CAN) { - for (i = 0; i < frame->can_dlc; i += 4, dreg += 2) { + for (i = 0; i < frame->len; i += 4, dreg += 2) { data = priv->read_reg32(priv, dreg); frame->data[i] = data; frame->data[i + 1] = data >> 8; frame->data[i + 2] = data >> 16; frame->data[i + 3] = data >> 24; } } else { - for (i = 0; i < frame->can_dlc; i += 2, dreg++) { + for (i = 0; i < frame->len; i += 2, dreg++) { data = priv->read_reg(priv, dreg); frame->data[i] = data; frame->data[i + 1] = data >> 8; } } } stats->rx_packets++; - stats->rx_bytes += frame->can_dlc; + stats->rx_bytes += frame->len; netif_receive_skb(skb); return 0; } @@ -473,11 +473,11 @@ static netdev_tx_t c_can_start_xmit(struct sk_buff *skb, * Store the message in the interface so we can call * can_put_echo_skb(). We must do this before we enable * transmit as we might race against do_tx(). */ c_can_setup_tx_object(dev, IF_TX, frame, idx); - priv->dlc[idx] = frame->can_dlc; + priv->dlc[idx] = frame->len; can_put_echo_skb(skb, dev, idx); /* Update the active bits */ atomic_add((1 << idx), &priv->tx_active); /* Start transmission */ @@ -975,11 +975,11 @@ static int c_can_handle_state_change(struct net_device *dev, default: break; } stats->rx_packets++; - stats->rx_bytes += cf->can_dlc; + stats->rx_bytes += cf->len; netif_receive_skb(skb); return 1; } @@ -1045,11 +1045,11 @@ static int c_can_handle_bus_err(struct net_device *dev, default: break; } stats->rx_packets++; - stats->rx_bytes += cf->can_dlc; + stats->rx_bytes += cf->len; netif_receive_skb(skb); return 1; } static int c_can_poll(struct napi_struct *napi, int quota) diff --git a/drivers/net/can/cc770/cc770.c b/drivers/net/can/cc770/cc770.c index 3fd2a276dd93..8d9f332c35e0 100644 --- a/drivers/net/can/cc770/cc770.c +++ b/drivers/net/can/cc770/cc770.c @@ -388,11 +388,11 @@ static void cc770_tx(struct net_device *dev, int mo) struct can_frame *cf = (struct can_frame *)priv->tx_skb->data; u8 dlc, rtr; u32 id; int i; - dlc = cf->can_dlc; + dlc = cf->len; id = cf->can_id; rtr = cf->can_id & CAN_RTR_FLAG ? 0 : MSGCFG_DIR; cc770_write_reg(priv, msgobj[mo].ctrl0, MSGVAL_RES | TXIE_RES | RXIE_RES | INTPND_RES); @@ -468,11 +468,11 @@ static void cc770_rx(struct net_device *dev, unsigned int mo, u8 ctrl1) * frame. Therefore we set it to 0. */ cf->can_id = CAN_RTR_FLAG; if (config & MSGCFG_XTD) cf->can_id |= CAN_EFF_FLAG; - cf->can_dlc = 0; + cf->len = 0; } else { if (config & MSGCFG_XTD) { id = cc770_read_reg(priv, msgobj[mo].id[3]); id |= cc770_read_reg(priv, msgobj[mo].id[2]) << 8; id |= cc770_read_reg(priv, msgobj[mo].id[1]) << 16; @@ -484,17 +484,17 @@ static void cc770_rx(struct net_device *dev, unsigned int mo, u8 ctrl1) id |= cc770_read_reg(priv, msgobj[mo].id[0]) << 8; id >>= 5; } cf->can_id = id; - cf->can_dlc = can_cc_dlc2len((config & 0xf0) >> 4); - for (i = 0; i < cf->can_dlc; i++) + cf->len = can_cc_dlc2len((config & 0xf0) >> 4); + for (i = 0; i < cf->len; i++) cf->data[i] = cc770_read_reg(priv, msgobj[mo].data[i]); } stats->rx_packets++; - stats->rx_bytes += cf->can_dlc; + stats->rx_bytes += cf->len; netif_rx(skb); } static int cc770_err(struct net_device *dev, u8 status) { @@ -570,11 +570,11 @@ static int cc770_err(struct net_device *dev, u8 status) } } stats->rx_packets++; - stats->rx_bytes += cf->can_dlc; + stats->rx_bytes += cf->len; netif_rx(skb); return 0; } @@ -697,11 +697,11 @@ static void cc770_tx_interrupt(struct net_device *dev, unsigned int o) cc770_tx(dev, mo); return; } cf = (struct can_frame *)priv->tx_skb->data; - stats->tx_bytes += cf->can_dlc; + stats->tx_bytes += cf->len; stats->tx_packets++; can_put_echo_skb(priv->tx_skb, dev, 0); can_get_echo_skb(dev, 0); priv->tx_skb = NULL; diff --git a/drivers/net/can/dev.c b/drivers/net/can/dev.c index 6dee4f8f2024..566501a02b91 100644 --- a/drivers/net/can/dev.c +++ b/drivers/net/can/dev.c @@ -28,14 +28,14 @@ MODULE_AUTHOR("Wolfgang Grandegger "); /* CAN DLC to real data length conversion helpers */ static const u8 dlc2len[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 12, 16, 20, 24, 32, 48, 64}; -/* get data length from can_dlc with sanitized can_dlc */ -u8 can_dlc2len(u8 can_dlc) +/* get data length from raw data length code (DLC) */ +u8 can_dlc2len(u8 dlc) { - return dlc2len[can_dlc & 0x0F]; + return dlc2len[dlc & 0x0F]; } EXPORT_SYMBOL_GPL(can_dlc2len); static const u8 len2dlc[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, /* 0 - 8 */ 9, 9, 9, 9, /* 9 - 12 */ @@ -593,11 +593,11 @@ static void can_restart(struct net_device *dev) cf->can_id |= CAN_ERR_RESTARTED; netif_rx(skb); stats->rx_packets++; - stats->rx_bytes += cf->can_dlc; + stats->rx_bytes += cf->len; restart: netdev_dbg(dev, "restarted\n"); priv->can_stats.restarts++; @@ -735,11 +735,11 @@ struct sk_buff *alloc_can_err_skb(struct net_device *dev, struct can_frame **cf) skb = alloc_can_skb(dev, cf); if (unlikely(!skb)) return NULL; (*cf)->can_id = CAN_ERR_FLAG; - (*cf)->can_dlc = CAN_ERR_DLC; + (*cf)->len = CAN_ERR_DLC; return skb; } EXPORT_SYMBOL_GPL(alloc_can_err_skb); diff --git a/drivers/net/can/grcan.c b/drivers/net/can/grcan.c index c71c9b8683d5..f5d94a692576 100644 --- a/drivers/net/can/grcan.c +++ b/drivers/net/can/grcan.c @@ -1199,25 +1199,25 @@ static int grcan_receive(struct net_device *dev, int budget) cf->can_id |= CAN_EFF_FLAG; } else { cf->can_id = ((slot[0] & GRCAN_MSG_BID) >> GRCAN_MSG_BID_BIT); } - cf->can_dlc = can_cc_dlc2len((slot[1] & GRCAN_MSG_DLC) + cf->len = can_cc_dlc2len((slot[1] & GRCAN_MSG_DLC) >> GRCAN_MSG_DLC_BIT); if (rtr) { cf->can_id |= CAN_RTR_FLAG; } else { - for (i = 0; i < cf->can_dlc; i++) { + for (i = 0; i < cf->len; i++) { j = GRCAN_MSG_DATA_SLOT_INDEX(i); shift = GRCAN_MSG_DATA_SHIFT(i); cf->data[i] = (u8)(slot[j] >> shift); } } /* Update statistics and read pointer */ stats->rx_packets++; - stats->rx_bytes += cf->can_dlc; + stats->rx_bytes += cf->len; netif_receive_skb(skb); rd = grcan_ring_add(rd, GRCAN_MSG_SIZE, dma->rx.size); } @@ -1397,11 +1397,11 @@ static netdev_tx_t grcan_start_xmit(struct sk_buff *skb, /* Convert and write CAN message to DMA buffer */ eff = cf->can_id & CAN_EFF_FLAG; rtr = cf->can_id & CAN_RTR_FLAG; id = cf->can_id & (eff ? CAN_EFF_MASK : CAN_SFF_MASK); - dlc = cf->can_dlc; + dlc = cf->len; if (eff) tmp = (id << GRCAN_MSG_EID_BIT) & GRCAN_MSG_EID; else tmp = (id << GRCAN_MSG_BID_BIT) & GRCAN_MSG_BID; slot[0] = (eff ? GRCAN_MSG_IDE : 0) | (rtr ? GRCAN_MSG_RTR : 0) | tmp; @@ -1445,11 +1445,11 @@ static netdev_tx_t grcan_start_xmit(struct sk_buff *skb, * as ownership of the skb is passed on by calling can_put_echo_skb. * Returning NETDEV_TX_BUSY or accessing skb or cf after a call to * can_put_echo_skb would be an error unless other measures are * taken. */ - priv->txdlc[slotindex] = cf->can_dlc; /* Store dlc for statistics */ + priv->txdlc[slotindex] = cf->len; /* Store dlc for statistics */ can_put_echo_skb(skb, dev, slotindex); /* Make sure everything is written before allowing hardware to * read from the memory */ diff --git a/drivers/net/can/ifi_canfd/ifi_canfd.c b/drivers/net/can/ifi_canfd/ifi_canfd.c index cc790354a8ee..3df55b0e4ef3 100644 --- a/drivers/net/can/ifi_canfd/ifi_canfd.c +++ b/drivers/net/can/ifi_canfd/ifi_canfd.c @@ -429,11 +429,11 @@ static int ifi_canfd_handle_lec_err(struct net_device *ndev) writel(IFI_CANFD_INTERRUPT_ERROR_COUNTER, priv->base + IFI_CANFD_INTERRUPT); writel(IFI_CANFD_ERROR_CTR_ER_ENABLE, priv->base + IFI_CANFD_ERROR_CTR); stats->rx_packets++; - stats->rx_bytes += cf->can_dlc; + stats->rx_bytes += cf->len; netif_receive_skb(skb); return 1; } @@ -521,11 +521,11 @@ static int ifi_canfd_handle_state_change(struct net_device *ndev, default: break; } stats->rx_packets++; - stats->rx_bytes += cf->can_dlc; + stats->rx_bytes += cf->len; netif_receive_skb(skb); return 1; } diff --git a/drivers/net/can/janz-ican3.c b/drivers/net/can/janz-ican3.c index 6a21af05ba27..2a6c918186c0 100644 --- a/drivers/net/can/janz-ican3.c +++ b/drivers/net/can/janz-ican3.c @@ -914,14 +914,14 @@ static void ican3_to_can_frame(struct ican3_dev *mod, if (desc->data[1] & ICAN3_SFF_RTR) cf->can_id |= CAN_RTR_FLAG; cf->can_id |= desc->data[0] << 3; cf->can_id |= (desc->data[1] & 0xe0) >> 5; - cf->can_dlc = can_cc_dlc2len(desc->data[1] & ICAN3_CAN_DLC_MASK); - memcpy(cf->data, &desc->data[2], cf->can_dlc); + cf->len = can_cc_dlc2len(desc->data[1] & ICAN3_CAN_DLC_MASK); + memcpy(cf->data, &desc->data[2], cf->len); } else { - cf->can_dlc = can_cc_dlc2len(desc->data[0] & ICAN3_CAN_DLC_MASK); + cf->len = can_cc_dlc2len(desc->data[0] & ICAN3_CAN_DLC_MASK); if (desc->data[0] & ICAN3_EFF_RTR) cf->can_id |= CAN_RTR_FLAG; if (desc->data[0] & ICAN3_EFF) { cf->can_id |= CAN_EFF_FLAG; @@ -932,11 +932,11 @@ static void ican3_to_can_frame(struct ican3_dev *mod, } else { cf->can_id |= desc->data[2] << 3; /* 10-3 */ cf->can_id |= desc->data[3] >> 5; /* 2-0 */ } - memcpy(cf->data, &desc->data[6], cf->can_dlc); + memcpy(cf->data, &desc->data[6], cf->len); } } static void can_frame_to_ican3(struct ican3_dev *mod, struct can_frame *cf, @@ -945,11 +945,11 @@ static void can_frame_to_ican3(struct ican3_dev *mod, /* clear out any stale data in the descriptor */ memset(desc->data, 0, sizeof(desc->data)); /* we always use the extended format, with the ECHO flag set */ desc->command = ICAN3_CAN_TYPE_EFF; - desc->data[0] |= cf->can_dlc; + desc->data[0] |= cf->len; desc->data[1] |= ICAN3_ECHO; /* support single transmission (no retries) mode */ if (mod->can.ctrlmode & CAN_CTRLMODE_ONE_SHOT) desc->data[1] |= ICAN3_SNGL; @@ -968,11 +968,11 @@ static void can_frame_to_ican3(struct ican3_dev *mod, desc->data[2] = (cf->can_id & 0x7F8) >> 3; /* bits 10-3 */ desc->data[3] = (cf->can_id & 0x007) << 5; /* bits 2-0 */ } /* copy the data bits into the descriptor */ - memcpy(&desc->data[6], cf->data, cf->can_dlc); + memcpy(&desc->data[6], cf->data, cf->len); } /* * Interrupt Handling */ @@ -1292,11 +1292,11 @@ static unsigned int ican3_get_echo_skb(struct ican3_dev *mod) netdev_err(mod->ndev, "BUG: echo skb not occupied\n"); return 0; } cf = (struct can_frame *)skb->data; - dlc = cf->can_dlc; + dlc = cf->len; /* check flag whether this packet has to be looped back */ if (skb->pkt_type != PACKET_LOOPBACK) { kfree_skb(skb); return dlc; @@ -1330,14 +1330,14 @@ static bool ican3_echo_skb_matches(struct ican3_dev *mod, struct sk_buff *skb) echo_cf = (struct can_frame *)echo_skb->data; if (cf->can_id != echo_cf->can_id) return false; - if (cf->can_dlc != echo_cf->can_dlc) + if (cf->len != echo_cf->len) return false; - return memcmp(cf->data, echo_cf->data, cf->can_dlc) == 0; + return memcmp(cf->data, echo_cf->data, cf->len) == 0; } /* * Check that there is room in the TX ring to transmit another skb * @@ -1419,11 +1419,11 @@ static int ican3_recv_skb(struct ican3_dev *mod) goto err_noalloc; } /* update statistics, receive the skb */ stats->rx_packets++; - stats->rx_bytes += cf->can_dlc; + stats->rx_bytes += cf->len; netif_receive_skb(skb); err_noalloc: /* toggle the valid bit and return the descriptor to the ring */ desc.control ^= DESC_VALID; diff --git a/drivers/net/can/kvaser_pciefd.c b/drivers/net/can/kvaser_pciefd.c index 6f766918211a..8b5f75209b09 100644 --- a/drivers/net/can/kvaser_pciefd.c +++ b/drivers/net/can/kvaser_pciefd.c @@ -1297,11 +1297,11 @@ static int kvaser_pciefd_rx_error_frame(struct kvaser_pciefd_can *can, cf->data[6] = bec.txerr; cf->data[7] = bec.rxerr; stats->rx_packets++; - stats->rx_bytes += cf->can_dlc; + stats->rx_bytes += cf->len; netif_rx(skb); return 0; } @@ -1496,11 +1496,11 @@ static void kvaser_pciefd_handle_nack_packet(struct kvaser_pciefd_can *can, cf->can_id |= CAN_ERR_ACK; } if (skb) { cf->can_id |= CAN_ERR_BUSERROR; - stats->rx_bytes += cf->can_dlc; + stats->rx_bytes += cf->len; stats->rx_packets++; netif_rx(skb); } else { stats->rx_dropped++; netdev_warn(can->can.dev, "No memory left for err_skb\n"); diff --git a/drivers/net/can/m_can/m_can.c b/drivers/net/can/m_can/m_can.c index ca040de8f909..e753c5f636bb 100644 --- a/drivers/net/can/m_can/m_can.c +++ b/drivers/net/can/m_can/m_can.c @@ -594,11 +594,11 @@ static int m_can_handle_lec_err(struct net_device *dev, default: break; } stats->rx_packets++; - stats->rx_bytes += cf->can_dlc; + stats->rx_bytes += cf->len; netif_receive_skb(skb); return 1; } @@ -721,11 +721,11 @@ static int m_can_handle_state_change(struct net_device *dev, default: break; } stats->rx_packets++; - stats->rx_bytes += cf->can_dlc; + stats->rx_bytes += cf->len; netif_receive_skb(skb); return 1; } diff --git a/drivers/net/can/mscan/mscan.c b/drivers/net/can/mscan/mscan.c index 95bf7338b358..5ed00a1558e1 100644 --- a/drivers/net/can/mscan/mscan.c +++ b/drivers/net/can/mscan/mscan.c @@ -248,20 +248,20 @@ static netdev_tx_t mscan_start_xmit(struct sk_buff *skb, struct net_device *dev) if (!rtr) { void __iomem *data = ®s->tx.dsr1_0; u16 *payload = (u16 *)frame->data; - for (i = 0; i < frame->can_dlc / 2; i++) { + for (i = 0; i < frame->len / 2; i++) { out_be16(data, *payload++); data += 2 + _MSCAN_RESERVED_DSR_SIZE; } /* write remaining byte if necessary */ - if (frame->can_dlc & 1) - out_8(data, frame->data[frame->can_dlc - 1]); + if (frame->len & 1) + out_8(data, frame->data[frame->len - 1]); } - out_8(®s->tx.dlr, frame->can_dlc); + out_8(®s->tx.dlr, frame->len); out_8(®s->tx.tbpr, priv->cur_pri); /* Start transmission. */ out_8(®s->cantflg, 1 << buf_id); @@ -310,23 +310,23 @@ static void mscan_get_rx_frame(struct net_device *dev, struct can_frame *frame) frame->can_id |= can_id >> 1; if (can_id & 1) frame->can_id |= CAN_RTR_FLAG; - frame->can_dlc = can_cc_dlc2len(in_8(®s->rx.dlr) & 0xf); + frame->len = can_cc_dlc2len(in_8(®s->rx.dlr) & 0xf); if (!(frame->can_id & CAN_RTR_FLAG)) { void __iomem *data = ®s->rx.dsr1_0; u16 *payload = (u16 *)frame->data; - for (i = 0; i < frame->can_dlc / 2; i++) { + for (i = 0; i < frame->len / 2; i++) { *payload++ = in_be16(data); data += 2 + _MSCAN_RESERVED_DSR_SIZE; } /* read remaining byte if necessary */ - if (frame->can_dlc & 1) - frame->data[frame->can_dlc - 1] = in_8(data); + if (frame->len & 1) + frame->data[frame->len - 1] = in_8(data); } out_8(®s->canrflg, MSCAN_RXF); } @@ -370,11 +370,11 @@ static void mscan_get_err_frame(struct net_device *dev, struct can_frame *frame, } can_bus_off(dev); } } priv->shadow_statflg = canrflg & MSCAN_STAT_MSK; - frame->can_dlc = CAN_ERR_DLC; + frame->len = CAN_ERR_DLC; out_8(®s->canrflg, MSCAN_ERR_IF); } static int mscan_rx_poll(struct napi_struct *napi, int quota) { @@ -405,11 +405,11 @@ static int mscan_rx_poll(struct napi_struct *napi, int quota) mscan_get_rx_frame(dev, frame); else if (canrflg & MSCAN_ERR_IF) mscan_get_err_frame(dev, frame, canrflg); stats->rx_packets++; - stats->rx_bytes += frame->can_dlc; + stats->rx_bytes += frame->len; work_done++; netif_receive_skb(skb); } if (work_done < quota) { diff --git a/drivers/net/can/pch_can.c b/drivers/net/can/pch_can.c index 9509bac8352d..4f9e7ec192aa 100644 --- a/drivers/net/can/pch_can.c +++ b/drivers/net/can/pch_can.c @@ -561,11 +561,11 @@ static void pch_can_error(struct net_device *ndev, u32 status) priv->can.state = state; netif_receive_skb(skb); stats->rx_packets++; - stats->rx_bytes += cf->can_dlc; + stats->rx_bytes += cf->len; } static irqreturn_t pch_can_interrupt(int irq, void *dev_id) { struct net_device *ndev = (struct net_device *)dev_id; @@ -681,24 +681,24 @@ static int pch_can_rx_normal(struct net_device *ndev, u32 obj_num, int quota) } if (id2 & PCH_ID2_DIR) cf->can_id |= CAN_RTR_FLAG; - cf->can_dlc = can_cc_dlc2len((ioread32(&priv->regs-> + cf->len = can_cc_dlc2len((ioread32(&priv->regs-> ifregs[0].mcont)) & 0xF); - for (i = 0; i < cf->can_dlc; i += 2) { + for (i = 0; i < cf->len; i += 2) { data_reg = ioread16(&priv->regs->ifregs[0].data[i / 2]); cf->data[i] = data_reg; cf->data[i + 1] = data_reg >> 8; } netif_receive_skb(skb); rcv_pkts++; stats->rx_packets++; quota--; - stats->rx_bytes += cf->can_dlc; + stats->rx_bytes += cf->len; pch_fifo_thresh(priv, obj_num); obj_num++; } while (quota > 0); @@ -917,19 +917,19 @@ static netdev_tx_t pch_xmit(struct sk_buff *skb, struct net_device *ndev) id2 |= PCH_ID2_DIR; iowrite32(id2, &priv->regs->ifregs[1].id2); /* Copy data to register */ - for (i = 0; i < cf->can_dlc; i += 2) { + for (i = 0; i < cf->len; i += 2) { iowrite16(cf->data[i] | (cf->data[i + 1] << 8), &priv->regs->ifregs[1].data[i / 2]); } can_put_echo_skb(skb, ndev, tx_obj_no - PCH_RX_OBJ_END - 1); /* Set the size of the data. Update if2_mcont */ - iowrite32(cf->can_dlc | PCH_IF_MCONT_NEWDAT | PCH_IF_MCONT_TXRQXT | + iowrite32(cf->len | PCH_IF_MCONT_NEWDAT | PCH_IF_MCONT_TXRQXT | PCH_IF_MCONT_TXIE, &priv->regs->ifregs[1].mcont); pch_can_rw_msg_obj(&priv->regs->ifregs[1].creq, tx_obj_no); return NETDEV_TX_OK; diff --git a/drivers/net/can/peak_canfd/peak_canfd.c b/drivers/net/can/peak_canfd/peak_canfd.c index c6077e07214e..fff3a35276aa 100644 --- a/drivers/net/can/peak_canfd/peak_canfd.c +++ b/drivers/net/can/peak_canfd/peak_canfd.c @@ -408,11 +408,11 @@ static int pucan_handle_status(struct peak_canfd_priv *priv, stats->rx_dropped++; return -ENOMEM; } stats->rx_packets++; - stats->rx_bytes += cf->can_dlc; + stats->rx_bytes += cf->len; pucan_netif_rx(skb, msg->ts_low, msg->ts_high); return 0; } @@ -436,11 +436,11 @@ static int pucan_handle_cache_critical(struct peak_canfd_priv *priv) cf->data[1] = CAN_ERR_CRTL_RX_OVERFLOW; cf->data[6] = priv->bec.txerr; cf->data[7] = priv->bec.rxerr; - stats->rx_bytes += cf->can_dlc; + stats->rx_bytes += cf->len; stats->rx_packets++; netif_rx(skb); return 0; } @@ -650,11 +650,11 @@ static netdev_tx_t peak_canfd_start_xmit(struct sk_buff *skb, struct pucan_tx_msg *msg; u16 msg_size, msg_flags; unsigned long flags; bool should_stop_tx_queue; int room_left; - u8 can_dlc; + u8 len; if (can_dropped_invalid_skb(ndev, skb)) return NETDEV_TX_OK; msg_size = ALIGN(sizeof(*msg) + cf->len, 4); @@ -680,22 +680,22 @@ static netdev_tx_t peak_canfd_start_xmit(struct sk_buff *skb, msg->can_id = cpu_to_le32(cf->can_id & CAN_SFF_MASK); } if (can_is_canfd_skb(skb)) { /* CAN FD frame format */ - can_dlc = can_len2dlc(cf->len); + len = can_len2dlc(cf->len); msg_flags |= PUCAN_MSG_EXT_DATA_LEN; if (cf->flags & CANFD_BRS) msg_flags |= PUCAN_MSG_BITRATE_SWITCH; if (cf->flags & CANFD_ESI) msg_flags |= PUCAN_MSG_ERROR_STATE_IND; } else { /* CAN 2.0 frame format */ - can_dlc = cf->len; + len = cf->len; if (cf->can_id & CAN_RTR_FLAG) msg_flags |= PUCAN_MSG_RTR; } @@ -705,11 +705,11 @@ static netdev_tx_t peak_canfd_start_xmit(struct sk_buff *skb, /* set driver specific bit to differentiate with application loopback */ if (priv->can.ctrlmode & CAN_CTRLMODE_LOOPBACK) msg_flags |= PUCAN_MSG_SELF_RECEIVE; msg->flags = cpu_to_le16(msg_flags); - msg->channel_dlc = PUCAN_MSG_CHANNEL_DLC(priv->index, can_dlc); + msg->channel_dlc = PUCAN_MSG_CHANNEL_DLC(priv->index, len); memcpy(msg->d, cf->data, cf->len); /* struct msg client field is used as an index in the echo skbs ring */ msg->client = priv->echo_idx; diff --git a/drivers/net/can/rcar/rcar_can.c b/drivers/net/can/rcar/rcar_can.c index 711ef4996b48..c803327f8f79 100644 --- a/drivers/net/can/rcar/rcar_can.c +++ b/drivers/net/can/rcar/rcar_can.c @@ -362,11 +362,11 @@ static void rcar_can_error(struct net_device *ndev) } } if (skb) { stats->rx_packets++; - stats->rx_bytes += cf->can_dlc; + stats->rx_bytes += cf->len; netif_rx(skb); } } static void rcar_can_tx_done(struct net_device *ndev) @@ -605,20 +605,20 @@ static netdev_tx_t rcar_can_start_xmit(struct sk_buff *skb, data = (cf->can_id & CAN_SFF_MASK) << RCAR_CAN_SID_SHIFT; if (cf->can_id & CAN_RTR_FLAG) { /* Remote transmission request */ data |= RCAR_CAN_RTR; } else { - for (i = 0; i < cf->can_dlc; i++) + for (i = 0; i < cf->len; i++) writeb(cf->data[i], &priv->regs->mb[RCAR_CAN_TX_FIFO_MBX].data[i]); } writel(data, &priv->regs->mb[RCAR_CAN_TX_FIFO_MBX].id); - writeb(cf->can_dlc, &priv->regs->mb[RCAR_CAN_TX_FIFO_MBX].dlc); + writeb(cf->len, &priv->regs->mb[RCAR_CAN_TX_FIFO_MBX].dlc); - priv->tx_dlc[priv->tx_head % RCAR_CAN_FIFO_DEPTH] = cf->can_dlc; + priv->tx_dlc[priv->tx_head % RCAR_CAN_FIFO_DEPTH] = cf->len; can_put_echo_skb(skb, ndev, priv->tx_head % RCAR_CAN_FIFO_DEPTH); priv->tx_head++; /* Start Tx: write 0xff to the TFPCR register to increment * the CPU-side pointer for the transmit FIFO to the next * mailbox location @@ -657,22 +657,22 @@ static void rcar_can_rx_pkt(struct rcar_can_priv *priv) cf->can_id = (data & CAN_EFF_MASK) | CAN_EFF_FLAG; else cf->can_id = (data >> RCAR_CAN_SID_SHIFT) & CAN_SFF_MASK; dlc = readb(&priv->regs->mb[RCAR_CAN_RX_FIFO_MBX].dlc); - cf->can_dlc = can_cc_dlc2len(dlc); + cf->len = can_cc_dlc2len(dlc); if (data & RCAR_CAN_RTR) { cf->can_id |= CAN_RTR_FLAG; } else { - for (dlc = 0; dlc < cf->can_dlc; dlc++) + for (dlc = 0; dlc < cf->len; dlc++) cf->data[dlc] = readb(&priv->regs->mb[RCAR_CAN_RX_FIFO_MBX].data[dlc]); } can_led_event(priv->ndev, CAN_LED_EVENT_RX); - stats->rx_bytes += cf->can_dlc; + stats->rx_bytes += cf->len; stats->rx_packets++; netif_receive_skb(skb); } static int rcar_can_rx_poll(struct napi_struct *napi, int quota) diff --git a/drivers/net/can/rcar/rcar_canfd.c b/drivers/net/can/rcar/rcar_canfd.c index 899a3218ce5e..86c6cbdb7e53 100644 --- a/drivers/net/can/rcar/rcar_canfd.c +++ b/drivers/net/can/rcar/rcar_canfd.c @@ -1023,11 +1023,11 @@ static void rcar_canfd_error(struct net_device *ndev, u32 cerfl, /* Clear channel error interrupts that are handled */ rcar_canfd_write(priv->base, RCANFD_CERFL(ch), RCANFD_CERFL_ERR(~cerfl)); stats->rx_packets++; - stats->rx_bytes += cf->can_dlc; + stats->rx_bytes += cf->len; netif_rx(skb); } static void rcar_canfd_tx_done(struct net_device *ndev) { @@ -1132,11 +1132,11 @@ static void rcar_canfd_state_change(struct net_device *ndev, tx_state = txerr >= rxerr ? state : 0; rx_state = txerr <= rxerr ? state : 0; can_change_state(ndev, cf, tx_state, rx_state); stats->rx_packets++; - stats->rx_bytes += cf->can_dlc; + stats->rx_bytes += cf->len; netif_rx(skb); } } static irqreturn_t rcar_canfd_channel_interrupt(int irq, void *dev_id) diff --git a/drivers/net/can/rx-offload.c b/drivers/net/can/rx-offload.c index 6e95193b215b..450c5cfcb3fc 100644 --- a/drivers/net/can/rx-offload.c +++ b/drivers/net/can/rx-offload.c @@ -53,11 +53,11 @@ static int can_rx_offload_napi_poll(struct napi_struct *napi, int quota) (skb = skb_dequeue(&offload->skb_queue))) { struct can_frame *cf = (struct can_frame *)skb->data; work_done++; stats->rx_packets++; - stats->rx_bytes += cf->can_dlc; + stats->rx_bytes += cf->len; netif_receive_skb(skb); } if (work_done < quota) { napi_complete_done(napi, work_done); diff --git a/drivers/net/can/sja1000/sja1000.c b/drivers/net/can/sja1000/sja1000.c index 1f188f2d126e..d55394aa0b95 100644 --- a/drivers/net/can/sja1000/sja1000.c +++ b/drivers/net/can/sja1000/sja1000.c @@ -293,11 +293,11 @@ static netdev_tx_t sja1000_start_xmit(struct sk_buff *skb, if (can_dropped_invalid_skb(dev, skb)) return NETDEV_TX_OK; netif_stop_queue(dev); - fi = dlc = cf->can_dlc; + fi = dlc = cf->len; id = cf->can_id; if (id & CAN_RTR_FLAG) fi |= SJA1000_FI_RTR; @@ -365,25 +365,25 @@ static void sja1000_rx(struct net_device *dev) dreg = SJA1000_SFF_BUF; id = (priv->read_reg(priv, SJA1000_ID1) << 3) | (priv->read_reg(priv, SJA1000_ID2) >> 5); } - cf->can_dlc = can_cc_dlc2len(fi & 0x0F); + cf->len = can_cc_dlc2len(fi & 0x0F); if (fi & SJA1000_FI_RTR) { id |= CAN_RTR_FLAG; } else { - for (i = 0; i < cf->can_dlc; i++) + for (i = 0; i < cf->len; i++) cf->data[i] = priv->read_reg(priv, dreg++); } cf->can_id = id; /* release receive buffer */ sja1000_write_cmdreg(priv, CMD_RRB); stats->rx_packets++; - stats->rx_bytes += cf->can_dlc; + stats->rx_bytes += cf->len; netif_rx(skb); can_led_event(dev, CAN_LED_EVENT_RX); } @@ -488,11 +488,11 @@ static int sja1000_err(struct net_device *dev, uint8_t isrc, uint8_t status) if(state == CAN_STATE_BUS_OFF) can_bus_off(dev); } stats->rx_packets++; - stats->rx_bytes += cf->can_dlc; + stats->rx_bytes += cf->len; netif_rx(skb); return 0; } diff --git a/drivers/net/can/slcan.c b/drivers/net/can/slcan.c index b4a39f0449ba..a1bd1be09548 100644 --- a/drivers/net/can/slcan.c +++ b/drivers/net/can/slcan.c @@ -104,12 +104,12 @@ static struct net_device **slcan_devs; * SLCAN ENCAPSULATION FORMAT * ************************************************************************/ /* * A CAN frame has a can_id (11 bit standard frame format OR 29 bit extended - * frame format) a data length code (can_dlc) which can be from 0 to 8 - * and up to data bytes as payload. + * frame format) a data length code (len) which can be from 0 to 8 + * and up to data bytes as payload. * Additionally a CAN frame may become a remote transmission frame if the * RTR-bit is set. This causes another ECU to send a CAN frame with the * given can_id. * * The SLCAN ASCII representation of these different frame types is: @@ -126,14 +126,14 @@ static struct net_device **slcan_devs; * The is a one byte ASCII number ('0' - '8') * The section has at much ASCII Hex bytes as defined by the * * Examples: * - * t1230 : can_id 0x123, can_dlc 0, no data - * t4563112233 : can_id 0x456, can_dlc 3, data 0x11 0x22 0x33 - * T12ABCDEF2AA55 : extended can_id 0x12ABCDEF, can_dlc 2, data 0xAA 0x55 - * r1230 : can_id 0x123, can_dlc 0, no data, remote transmission request + * t1230 : can_id 0x123, len 0, no data + * t4563112233 : can_id 0x456, len 3, data 0x11 0x22 0x33 + * T12ABCDEF2AA55 : extended can_id 0x12ABCDEF, len 2, data 0xAA 0x55 + * r1230 : can_id 0x123, len 0, no data, remote transmission request * */ /************************************************************************ * STANDARD SLCAN DECAPSULATION * @@ -154,22 +154,22 @@ static void slc_bump(struct slcan *sl) case 'r': cf.can_id = CAN_RTR_FLAG; fallthrough; case 't': /* store dlc ASCII value and terminate SFF CAN ID string */ - cf.can_dlc = sl->rbuff[SLC_CMD_LEN + SLC_SFF_ID_LEN]; + cf.len = sl->rbuff[SLC_CMD_LEN + SLC_SFF_ID_LEN]; sl->rbuff[SLC_CMD_LEN + SLC_SFF_ID_LEN] = 0; /* point to payload data behind the dlc */ cmd += SLC_CMD_LEN + SLC_SFF_ID_LEN + 1; break; case 'R': cf.can_id = CAN_RTR_FLAG; fallthrough; case 'T': cf.can_id |= CAN_EFF_FLAG; /* store dlc ASCII value and terminate EFF CAN ID string */ - cf.can_dlc = sl->rbuff[SLC_CMD_LEN + SLC_EFF_ID_LEN]; + cf.len = sl->rbuff[SLC_CMD_LEN + SLC_EFF_ID_LEN]; sl->rbuff[SLC_CMD_LEN + SLC_EFF_ID_LEN] = 0; /* point to payload data behind the dlc */ cmd += SLC_CMD_LEN + SLC_EFF_ID_LEN + 1; break; default: @@ -179,19 +179,19 @@ static void slc_bump(struct slcan *sl) if (kstrtou32(sl->rbuff + SLC_CMD_LEN, 16, &tmpid)) return; cf.can_id |= tmpid; - /* get can_dlc from sanitized ASCII value */ - if (cf.can_dlc >= '0' && cf.can_dlc < '9') - cf.can_dlc -= '0'; + /* get len from sanitized ASCII value */ + if (cf.len >= '0' && cf.len < '9') + cf.len -= '0'; else return; /* RTR frames may have a dlc > 0 but they never have any data bytes */ if (!(cf.can_id & CAN_RTR_FLAG)) { - for (i = 0; i < cf.can_dlc; i++) { + for (i = 0; i < cf.len; i++) { tmp = hex_to_bin(*cmd++); if (tmp < 0) return; cf.data[i] = (tmp << 4); tmp = hex_to_bin(*cmd++); @@ -216,11 +216,11 @@ static void slc_bump(struct slcan *sl) can_skb_prv(skb)->skbcnt = 0; skb_put_data(skb, &cf, sizeof(struct can_frame)); sl->dev->stats.rx_packets++; - sl->dev->stats.rx_bytes += cf.can_dlc; + sl->dev->stats.rx_bytes += cf.len; netif_rx_ni(skb); } /* parse tty input stream */ static void slcan_unesc(struct slcan *sl, unsigned char s) @@ -280,15 +280,15 @@ static void slc_encaps(struct slcan *sl, struct can_frame *cf) id >>= 4; } pos += (cf->can_id & CAN_EFF_FLAG) ? SLC_EFF_ID_LEN : SLC_SFF_ID_LEN; - *pos++ = cf->can_dlc + '0'; + *pos++ = cf->len + '0'; /* RTR frames may have a dlc > 0 but they never have any data bytes */ if (!(cf->can_id & CAN_RTR_FLAG)) { - for (i = 0; i < cf->can_dlc; i++) + for (i = 0; i < cf->len; i++) pos = hex_byte_pack_upper(pos, cf->data[i]); } *pos++ = '\r'; @@ -302,11 +302,11 @@ static void slc_encaps(struct slcan *sl, struct can_frame *cf) */ set_bit(TTY_DO_WRITE_WAKEUP, &sl->tty->flags); actual = sl->tty->ops->write(sl->tty, sl->xbuff, pos - sl->xbuff); sl->xleft = (pos - sl->xbuff) - actual; sl->xhead = sl->xbuff + actual; - sl->dev->stats.tx_bytes += cf->can_dlc; + sl->dev->stats.tx_bytes += cf->len; } /* Write out any remaining transmit buffer. Scheduled when tty is writable */ static void slcan_transmit(struct work_struct *work) { diff --git a/drivers/net/can/softing/softing_fw.c b/drivers/net/can/softing/softing_fw.c index ccd649a8e37b..7e1536877993 100644 --- a/drivers/net/can/softing/softing_fw.c +++ b/drivers/net/can/softing/softing_fw.c @@ -622,11 +622,11 @@ int softing_startstop(struct net_device *dev, int up) * from here, no errors should occur, or the failed: part * must be reviewed */ memset(&msg, 0, sizeof(msg)); msg.can_id = CAN_ERR_FLAG | CAN_ERR_RESTARTED; - msg.can_dlc = CAN_ERR_DLC; + msg.len = CAN_ERR_DLC; for (j = 0; j < ARRAY_SIZE(card->net); ++j) { if (!(bus_bitmask_start & (1 << j))) continue; netdev = card->net[j]; if (!netdev) diff --git a/drivers/net/can/softing/softing_main.c b/drivers/net/can/softing/softing_main.c index 39e8275ee7ba..03a68bb486fd 100644 --- a/drivers/net/can/softing/softing_main.c +++ b/drivers/net/can/softing/softing_main.c @@ -82,22 +82,22 @@ static netdev_tx_t softing_netdev_start_xmit(struct sk_buff *skb, if (cf->can_id & CAN_EFF_FLAG) *ptr |= CMD_XTD; if (priv->index) *ptr |= CMD_BUS2; ++ptr; - *ptr++ = cf->can_dlc; + *ptr++ = cf->len; *ptr++ = (cf->can_id >> 0); *ptr++ = (cf->can_id >> 8); if (cf->can_id & CAN_EFF_FLAG) { *ptr++ = (cf->can_id >> 16); *ptr++ = (cf->can_id >> 24); } else { /* increment 1, not 2 as you might think */ ptr += 1; } if (!(cf->can_id & CAN_RTR_FLAG)) - memcpy(ptr, &cf->data[0], cf->can_dlc); + memcpy(ptr, &cf->data[0], cf->len); memcpy_toio(&card->dpram[DPRAM_TX + DPRAM_TX_SIZE * fifo_wr], buf, DPRAM_TX_SIZE); if (++fifo_wr >= DPRAM_TX_CNT) fifo_wr = 0; iowrite8(fifo_wr, &card->dpram[DPRAM_TX_WR]); @@ -165,11 +165,11 @@ static int softing_handle_1(struct softing *card) int j; /* reset condition */ iowrite8(0, &card->dpram[DPRAM_RX_LOST]); /* prepare msg */ msg.can_id = CAN_ERR_FLAG | CAN_ERR_CRTL; - msg.can_dlc = CAN_ERR_DLC; + msg.len = CAN_ERR_DLC; msg.data[1] = CAN_ERR_CRTL_RX_OVERFLOW; /* * service to all buses, we don't know which it was applicable * but only service buses that are online */ @@ -216,11 +216,11 @@ static int softing_handle_1(struct softing *card) uint8_t can_state, state; state = *ptr++; msg.can_id = CAN_ERR_FLAG; - msg.can_dlc = CAN_ERR_DLC; + msg.len = CAN_ERR_DLC; if (state & SF_MASK_BUSOFF) { can_state = CAN_STATE_BUS_OFF; msg.can_id |= CAN_ERR_BUSOFF; state = STATE_BUSOFF; @@ -259,11 +259,11 @@ static int softing_handle_1(struct softing *card) } } else { if (cmd & CMD_RTR) msg.can_id |= CAN_RTR_FLAG; - msg.can_dlc = can_cc_dlc2len(*ptr++); + msg.len = can_cc_dlc2len(*ptr++); if (cmd & CMD_XTD) { msg.can_id |= CAN_EFF_FLAG; msg.can_id |= le32_to_cpup((void *)ptr); ptr += 4; } else { @@ -292,19 +292,19 @@ static int softing_handle_1(struct softing *card) --priv->tx.pending; if (card->tx.pending) --card->tx.pending; ++netdev->stats.tx_packets; if (!(msg.can_id & CAN_RTR_FLAG)) - netdev->stats.tx_bytes += msg.can_dlc; + netdev->stats.tx_bytes += msg.len; } else { int ret; ret = softing_netdev_rx(netdev, &msg, ktime); if (ret == NET_RX_SUCCESS) { ++netdev->stats.rx_packets; if (!(msg.can_id & CAN_RTR_FLAG)) - netdev->stats.rx_bytes += msg.can_dlc; + netdev->stats.rx_bytes += msg.len; } else { ++netdev->stats.rx_dropped; } } } diff --git a/drivers/net/can/spi/hi311x.c b/drivers/net/can/spi/hi311x.c index 728f34b696a7..f9455de94786 100644 --- a/drivers/net/can/spi/hi311x.c +++ b/drivers/net/can/spi/hi311x.c @@ -275,31 +275,31 @@ static void hi3110_hw_tx(struct spi_device *spi, struct can_frame *frame) (frame->can_id & CAN_EFF_MASK) >> 7; buf[HI3110_FIFO_ID_OFF + 3] = ((frame->can_id & CAN_EFF_MASK) << 1) | ((frame->can_id & CAN_RTR_FLAG) ? 1 : 0); - buf[HI3110_FIFO_EXT_DLC_OFF] = frame->can_dlc; + buf[HI3110_FIFO_EXT_DLC_OFF] = frame->len; memcpy(buf + HI3110_FIFO_EXT_DATA_OFF, - frame->data, frame->can_dlc); + frame->data, frame->len); hi3110_hw_tx_frame(spi, buf, HI3110_TX_EXT_BUF_LEN - - (HI3110_CAN_MAX_DATA_LEN - frame->can_dlc)); + (HI3110_CAN_MAX_DATA_LEN - frame->len)); } else { /* Standard frame */ buf[HI3110_FIFO_ID_OFF] = (frame->can_id & CAN_SFF_MASK) >> 3; buf[HI3110_FIFO_ID_OFF + 1] = ((frame->can_id & CAN_SFF_MASK) << 5) | ((frame->can_id & CAN_RTR_FLAG) ? (1 << 4) : 0); - buf[HI3110_FIFO_STD_DLC_OFF] = frame->can_dlc; + buf[HI3110_FIFO_STD_DLC_OFF] = frame->len; memcpy(buf + HI3110_FIFO_STD_DATA_OFF, - frame->data, frame->can_dlc); + frame->data, frame->len); hi3110_hw_tx_frame(spi, buf, HI3110_TX_STD_BUF_LEN - - (HI3110_CAN_MAX_DATA_LEN - frame->can_dlc)); + (HI3110_CAN_MAX_DATA_LEN - frame->len)); } } static void hi3110_hw_rx_frame(struct spi_device *spi, u8 *buf) { @@ -339,20 +339,20 @@ static void hi3110_hw_rx(struct spi_device *spi) (buf[HI3110_FIFO_WOTIME_ID_OFF] << 3) | ((buf[HI3110_FIFO_WOTIME_ID_OFF + 1] & 0xE0) >> 5); } /* Data length */ - frame->can_dlc = can_cc_dlc2len(buf[HI3110_FIFO_WOTIME_DLC_OFF] & 0x0F); + frame->len = can_cc_dlc2len(buf[HI3110_FIFO_WOTIME_DLC_OFF] & 0x0F); if (buf[HI3110_FIFO_WOTIME_ID_OFF + 3] & HI3110_FIFO_WOTIME_ID_RTR) frame->can_id |= CAN_RTR_FLAG; else memcpy(frame->data, buf + HI3110_FIFO_WOTIME_DAT_OFF, - frame->can_dlc); + frame->len); priv->net->stats.rx_packets++; - priv->net->stats.rx_bytes += frame->can_dlc; + priv->net->stats.rx_bytes += frame->len; can_led_event(priv->net, CAN_LED_EVENT_RX); netif_rx_ni(skb); } @@ -583,11 +583,11 @@ static void hi3110_tx_work_handler(struct work_struct *ws) if (priv->can.state == CAN_STATE_BUS_OFF) { hi3110_clean(net); } else { frame = (struct can_frame *)priv->tx_skb->data; hi3110_hw_tx(spi, frame); - priv->tx_len = 1 + frame->can_dlc; + priv->tx_len = 1 + frame->len; can_put_echo_skb(priv->tx_skb, net, 0); priv->tx_skb = NULL; } } mutex_unlock(&priv->hi3110_lock); diff --git a/drivers/net/can/spi/mcp251x.c b/drivers/net/can/spi/mcp251x.c index 6ddebb1c4a24..25859d16d06f 100644 --- a/drivers/net/can/spi/mcp251x.c +++ b/drivers/net/can/spi/mcp251x.c @@ -642,13 +642,13 @@ static void mcp251x_hw_tx(struct spi_device *spi, struct can_frame *frame, buf[TXBSIDL_OFF] = ((sid & SIDL_SID_MASK) << SIDL_SID_SHIFT) | (exide << SIDL_EXIDE_SHIFT) | ((eid >> SIDL_EID_SHIFT) & SIDL_EID_MASK); buf[TXBEID8_OFF] = GET_BYTE(eid, 1); buf[TXBEID0_OFF] = GET_BYTE(eid, 0); - buf[TXBDLC_OFF] = (rtr << DLC_RTR_SHIFT) | frame->can_dlc; - memcpy(buf + TXBDAT_OFF, frame->data, frame->can_dlc); - mcp251x_hw_tx_frame(spi, buf, frame->can_dlc, tx_buf_idx); + buf[TXBDLC_OFF] = (rtr << DLC_RTR_SHIFT) | frame->len; + memcpy(buf + TXBDAT_OFF, frame->data, frame->len); + mcp251x_hw_tx_frame(spi, buf, frame->len, tx_buf_idx); /* use INSTRUCTION_RTS, to avoid "repeated frame problem" */ priv->spi_tx_buf[0] = INSTRUCTION_RTS(1 << tx_buf_idx); mcp251x_spi_trans(priv->spi, 1); } @@ -718,15 +718,15 @@ static void mcp251x_hw_rx(struct spi_device *spi, int buf_idx) (buf[RXBSIDL_OFF] >> RXBSIDL_SHIFT); if (buf[RXBSIDL_OFF] & RXBSIDL_SRR) frame->can_id |= CAN_RTR_FLAG; } /* Data length */ - frame->can_dlc = can_cc_dlc2len(buf[RXBDLC_OFF] & RXBDLC_LEN_MASK); - memcpy(frame->data, buf + RXBDAT_OFF, frame->can_dlc); + frame->len = can_cc_dlc2len(buf[RXBDLC_OFF] & RXBDLC_LEN_MASK); + memcpy(frame->data, buf + RXBDAT_OFF, frame->len); priv->net->stats.rx_packets++; - priv->net->stats.rx_bytes += frame->can_dlc; + priv->net->stats.rx_bytes += frame->len; can_led_event(priv->net, CAN_LED_EVENT_RX); netif_rx_ni(skb); } @@ -996,14 +996,14 @@ static void mcp251x_tx_work_handler(struct work_struct *ws) if (priv->can.state == CAN_STATE_BUS_OFF) { mcp251x_clean(net); } else { frame = (struct can_frame *)priv->tx_skb->data; - if (frame->can_dlc > CAN_FRAME_MAX_DATA_LEN) - frame->can_dlc = CAN_FRAME_MAX_DATA_LEN; + if (frame->len > CAN_FRAME_MAX_DATA_LEN) + frame->len = CAN_FRAME_MAX_DATA_LEN; mcp251x_hw_tx(spi, frame, 0); - priv->tx_len = 1 + frame->can_dlc; + priv->tx_len = 1 + frame->len; can_put_echo_skb(priv->tx_skb, net, 0); priv->tx_skb = NULL; } } mutex_unlock(&priv->mcp_lock); diff --git a/drivers/net/can/sun4i_can.c b/drivers/net/can/sun4i_can.c index 0e2569779895..098cc9670f0f 100644 --- a/drivers/net/can/sun4i_can.c +++ b/drivers/net/can/sun4i_can.c @@ -422,11 +422,11 @@ static netdev_tx_t sun4ican_start_xmit(struct sk_buff *skb, struct net_device *d return NETDEV_TX_OK; netif_stop_queue(dev); id = cf->can_id; - dlc = cf->can_dlc; + dlc = cf->len; msg_flag_n = dlc; if (id & CAN_RTR_FLAG) msg_flag_n |= SUN4I_MSG_RTR_FLAG; @@ -473,11 +473,11 @@ static void sun4i_can_rx(struct net_device *dev) skb = alloc_can_skb(dev, &cf); if (!skb) return; fi = readl(priv->base + SUN4I_REG_BUF0_ADDR); - cf->can_dlc = can_cc_dlc2len(fi & 0x0F); + cf->len = can_cc_dlc2len(fi & 0x0F); if (fi & SUN4I_MSG_EFF_FLAG) { dreg = SUN4I_REG_BUF5_ADDR; id = (readl(priv->base + SUN4I_REG_BUF1_ADDR) << 21) | (readl(priv->base + SUN4I_REG_BUF2_ADDR) << 13) | (readl(priv->base + SUN4I_REG_BUF3_ADDR) << 5) | @@ -491,19 +491,19 @@ static void sun4i_can_rx(struct net_device *dev) /* remote frame ? */ if (fi & SUN4I_MSG_RTR_FLAG) id |= CAN_RTR_FLAG; else - for (i = 0; i < cf->can_dlc; i++) + for (i = 0; i < cf->len; i++) cf->data[i] = readl(priv->base + dreg + i * 4); cf->can_id = id; sun4i_can_write_cmdreg(priv, SUN4I_CMD_RELEASE_RBUF); stats->rx_packets++; - stats->rx_bytes += cf->can_dlc; + stats->rx_bytes += cf->len; netif_rx(skb); can_led_event(dev, CAN_LED_EVENT_RX); } @@ -623,11 +623,11 @@ static int sun4i_can_err(struct net_device *dev, u8 isrc, u8 status) can_bus_off(dev); } if (likely(skb)) { stats->rx_packets++; - stats->rx_bytes += cf->can_dlc; + stats->rx_bytes += cf->len; netif_rx(skb); } else { return -ENOMEM; } diff --git a/drivers/net/can/ti_hecc.c b/drivers/net/can/ti_hecc.c index 060ce0b16cdc..16cf5ded781f 100644 --- a/drivers/net/can/ti_hecc.c +++ b/drivers/net/can/ti_hecc.c @@ -494,11 +494,11 @@ static netdev_tx_t ti_hecc_xmit(struct sk_buff *skb, struct net_device *ndev) return NETDEV_TX_BUSY; } spin_unlock_irqrestore(&priv->mbx_lock, flags); /* Prepare mailbox for transmission */ - data = cf->can_dlc | (get_tx_head_prio(priv) << 8); + data = cf->len | (get_tx_head_prio(priv) << 8); if (cf->can_id & CAN_RTR_FLAG) /* Remote transmission request */ data |= HECC_CANMCF_RTR; hecc_write_mbx(priv, mbxno, HECC_CANMCF, data); if (cf->can_id & CAN_EFF_FLAG) /* Extended frame format */ @@ -506,11 +506,11 @@ static netdev_tx_t ti_hecc_xmit(struct sk_buff *skb, struct net_device *ndev) else /* Standard frame format */ data = (cf->can_id & CAN_SFF_MASK) << 18; hecc_write_mbx(priv, mbxno, HECC_CANMID, data); hecc_write_mbx(priv, mbxno, HECC_CANMDL, be32_to_cpu(*(__be32 *)(cf->data))); - if (cf->can_dlc > 4) + if (cf->len > 4) hecc_write_mbx(priv, mbxno, HECC_CANMDH, be32_to_cpu(*(__be32 *)(cf->data + 4))); else *(u32 *)(cf->data + 4) = 0; can_put_echo_skb(skb, ndev, mbxno); @@ -564,15 +564,15 @@ static struct sk_buff *ti_hecc_mailbox_read(struct can_rx_offload *offload, cf->can_id = (data >> 18) & CAN_SFF_MASK; data = hecc_read_mbx(priv, mbxno, HECC_CANMCF); if (data & HECC_CANMCF_RTR) cf->can_id |= CAN_RTR_FLAG; - cf->can_dlc = can_cc_dlc2len(data & 0xF); + cf->len = can_cc_dlc2len(data & 0xF); data = hecc_read_mbx(priv, mbxno, HECC_CANMDL); *(__be32 *)(cf->data) = cpu_to_be32(data); - if (cf->can_dlc > 4) { + if (cf->len > 4) { data = hecc_read_mbx(priv, mbxno, HECC_CANMDH); *(__be32 *)(cf->data + 4) = cpu_to_be32(data); } *timestamp = hecc_read_stamp(priv, mbxno); diff --git a/drivers/net/can/usb/ems_usb.c b/drivers/net/can/usb/ems_usb.c index 288781934149..25eee4466364 100644 --- a/drivers/net/can/usb/ems_usb.c +++ b/drivers/net/can/usb/ems_usb.c @@ -304,26 +304,26 @@ static void ems_usb_rx_can_msg(struct ems_usb *dev, struct ems_cpc_msg *msg) skb = alloc_can_skb(dev->netdev, &cf); if (skb == NULL) return; cf->can_id = le32_to_cpu(msg->msg.can_msg.id); - cf->can_dlc = can_cc_dlc2len(msg->msg.can_msg.length & 0xF); + cf->len = can_cc_dlc2len(msg->msg.can_msg.length & 0xF); if (msg->type == CPC_MSG_TYPE_EXT_CAN_FRAME || msg->type == CPC_MSG_TYPE_EXT_RTR_FRAME) cf->can_id |= CAN_EFF_FLAG; if (msg->type == CPC_MSG_TYPE_RTR_FRAME || msg->type == CPC_MSG_TYPE_EXT_RTR_FRAME) { cf->can_id |= CAN_RTR_FLAG; } else { - for (i = 0; i < cf->can_dlc; i++) + for (i = 0; i < cf->len; i++) cf->data[i] = msg->msg.can_msg.msg[i]; } stats->rx_packets++; - stats->rx_bytes += cf->can_dlc; + stats->rx_bytes += cf->len; netif_rx(skb); } static void ems_usb_rx_err(struct ems_usb *dev, struct ems_cpc_msg *msg) { @@ -394,11 +394,11 @@ static void ems_usb_rx_err(struct ems_usb *dev, struct ems_cpc_msg *msg) stats->rx_over_errors++; stats->rx_errors++; } stats->rx_packets++; - stats->rx_bytes += cf->can_dlc; + stats->rx_bytes += cf->len; netif_rx(skb); } /* * callback for bulk IN urb @@ -753,25 +753,25 @@ static netdev_tx_t ems_usb_start_xmit(struct sk_buff *skb, struct net_device *ne } msg = (struct ems_cpc_msg *)&buf[CPC_HEADER_SIZE]; msg->msg.can_msg.id = cpu_to_le32(cf->can_id & CAN_ERR_MASK); - msg->msg.can_msg.length = cf->can_dlc; + msg->msg.can_msg.length = cf->len; if (cf->can_id & CAN_RTR_FLAG) { msg->type = cf->can_id & CAN_EFF_FLAG ? CPC_CMD_TYPE_EXT_RTR_FRAME : CPC_CMD_TYPE_RTR_FRAME; msg->length = CPC_CAN_MSG_MIN_SIZE; } else { msg->type = cf->can_id & CAN_EFF_FLAG ? CPC_CMD_TYPE_EXT_CAN_FRAME : CPC_CMD_TYPE_CAN_FRAME; - for (i = 0; i < cf->can_dlc; i++) + for (i = 0; i < cf->len; i++) msg->msg.can_msg.msg[i] = cf->data[i]; - msg->length = CPC_CAN_MSG_MIN_SIZE + cf->can_dlc; + msg->length = CPC_CAN_MSG_MIN_SIZE + cf->len; } for (i = 0; i < MAX_TX_URBS; i++) { if (dev->tx_contexts[i].echo_index == MAX_TX_URBS) { context = &dev->tx_contexts[i]; @@ -792,11 +792,11 @@ static netdev_tx_t ems_usb_start_xmit(struct sk_buff *skb, struct net_device *ne return NETDEV_TX_BUSY; } context->dev = dev; context->echo_index = i; - context->dlc = cf->can_dlc; + context->dlc = cf->len; usb_fill_bulk_urb(urb, dev->udev, usb_sndbulkpipe(dev->udev, 2), buf, size, ems_usb_write_bulk_callback, context); urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; usb_anchor_urb(urb, &dev->tx_submitted); diff --git a/drivers/net/can/usb/esd_usb2.c b/drivers/net/can/usb/esd_usb2.c index 72999de550d1..3643a8ee03cf 100644 --- a/drivers/net/can/usb/esd_usb2.c +++ b/drivers/net/can/usb/esd_usb2.c @@ -290,11 +290,11 @@ static void esd_usb2_rx_event(struct esd_usb2_net_priv *priv, priv->bec.txerr = txerr; priv->bec.rxerr = rxerr; stats->rx_packets++; - stats->rx_bytes += cf->can_dlc; + stats->rx_bytes += cf->len; netif_rx(skb); } } static void esd_usb2_rx_can_msg(struct esd_usb2_net_priv *priv, @@ -319,24 +319,24 @@ static void esd_usb2_rx_can_msg(struct esd_usb2_net_priv *priv, stats->rx_dropped++; return; } cf->can_id = id & ESD_IDMASK; - cf->can_dlc = can_cc_dlc2len(msg->msg.rx.dlc & ~ESD_RTR); + cf->len = can_cc_dlc2len(msg->msg.rx.dlc & ~ESD_RTR); if (id & ESD_EXTID) cf->can_id |= CAN_EFF_FLAG; if (msg->msg.rx.dlc & ESD_RTR) { cf->can_id |= CAN_RTR_FLAG; } else { - for (i = 0; i < cf->can_dlc; i++) + for (i = 0; i < cf->len; i++) cf->data[i] = msg->msg.rx.data[i]; } stats->rx_packets++; - stats->rx_bytes += cf->can_dlc; + stats->rx_bytes += cf->len; netif_rx(skb); } return; } @@ -735,23 +735,23 @@ static netdev_tx_t esd_usb2_start_xmit(struct sk_buff *skb, msg = (struct esd_usb2_msg *)buf; msg->msg.hdr.len = 3; /* minimal length */ msg->msg.hdr.cmd = CMD_CAN_TX; msg->msg.tx.net = priv->index; - msg->msg.tx.dlc = cf->can_dlc; + msg->msg.tx.dlc = cf->len; msg->msg.tx.id = cpu_to_le32(cf->can_id & CAN_ERR_MASK); if (cf->can_id & CAN_RTR_FLAG) msg->msg.tx.dlc |= ESD_RTR; if (cf->can_id & CAN_EFF_FLAG) msg->msg.tx.id |= cpu_to_le32(ESD_EXTID); - for (i = 0; i < cf->can_dlc; i++) + for (i = 0; i < cf->len; i++) msg->msg.tx.data[i] = cf->data[i]; - msg->msg.hdr.len += (cf->can_dlc + 3) >> 2; + msg->msg.hdr.len += (cf->len + 3) >> 2; for (i = 0; i < MAX_TX_URBS; i++) { if (priv->tx_contexts[i].echo_index == MAX_TX_URBS) { context = &priv->tx_contexts[i]; break; @@ -767,11 +767,11 @@ static netdev_tx_t esd_usb2_start_xmit(struct sk_buff *skb, goto releasebuf; } context->priv = priv; context->echo_index = i; - context->dlc = cf->can_dlc; + context->dlc = cf->len; /* hnd must not be 0 - MSB is stripped in txdone handling */ msg->msg.tx.hnd = 0x80000000 | i; /* returned in TX done message */ usb_fill_bulk_urb(urb, dev->udev, usb_sndbulkpipe(dev->udev, 2), buf, diff --git a/drivers/net/can/usb/gs_usb.c b/drivers/net/can/usb/gs_usb.c index b1729b208788..940589667a7f 100644 --- a/drivers/net/can/usb/gs_usb.c +++ b/drivers/net/can/usb/gs_usb.c @@ -133,11 +133,11 @@ struct gs_device_bt_const { struct gs_host_frame { u32 echo_id; u32 can_id; - u8 can_dlc; + u8 len; u8 channel; u8 flags; u8 reserved; u8 data[8]; @@ -329,19 +329,19 @@ static void gs_usb_receive_bulk_callback(struct urb *urb) if (!skb) return; cf->can_id = hf->can_id; - cf->can_dlc = can_cc_dlc2len(hf->can_dlc); + cf->len = can_cc_dlc2len(hf->len); memcpy(cf->data, hf->data, 8); /* ERROR frames tell us information about the controller */ if (hf->can_id & CAN_ERR_FLAG) gs_update_state(dev, cf); netdev->stats.rx_packets++; - netdev->stats.rx_bytes += hf->can_dlc; + netdev->stats.rx_bytes += hf->len; netif_rx(skb); } else { /* echo_id == hf->echo_id */ if (hf->echo_id >= GS_MAX_TX_URBS) { netdev_err(netdev, @@ -349,11 +349,11 @@ static void gs_usb_receive_bulk_callback(struct urb *urb) hf->echo_id); goto resubmit_urb; } netdev->stats.tx_packets++; - netdev->stats.tx_bytes += hf->can_dlc; + netdev->stats.tx_bytes += hf->len; txc = gs_get_tx_context(dev, hf->echo_id); /* bad devices send bad echo_ids. */ if (!txc) { @@ -376,11 +376,11 @@ static void gs_usb_receive_bulk_callback(struct urb *urb) skb = alloc_can_err_skb(netdev, &cf); if (!skb) goto resubmit_urb; cf->can_id |= CAN_ERR_CRTL; - cf->can_dlc = CAN_ERR_DLC; + cf->len = CAN_ERR_DLC; cf->data[1] = CAN_ERR_CRTL_RX_OVERFLOW; stats->rx_over_errors++; stats->rx_errors++; netif_rx(skb); } @@ -502,12 +502,12 @@ static netdev_tx_t gs_can_start_xmit(struct sk_buff *skb, hf->channel = dev->channel; cf = (struct can_frame *)skb->data; hf->can_id = cf->can_id; - hf->can_dlc = cf->can_dlc; - memcpy(hf->data, cf->data, cf->can_dlc); + hf->len = cf->len; + memcpy(hf->data, cf->data, cf->len); usb_fill_bulk_urb(urb, dev->udev, usb_sndbulkpipe(dev->udev, GSUSB_ENDPOINT_OUT), hf, sizeof(*hf), diff --git a/drivers/net/can/usb/kvaser_usb/kvaser_usb_core.c b/drivers/net/can/usb/kvaser_usb/kvaser_usb_core.c index 0f1d3e807d63..d6e18bcb1a7f 100644 --- a/drivers/net/can/usb/kvaser_usb/kvaser_usb_core.c +++ b/drivers/net/can/usb/kvaser_usb/kvaser_usb_core.c @@ -256,11 +256,11 @@ int kvaser_usb_can_rx_over_error(struct net_device *netdev) cf->can_id |= CAN_ERR_CRTL; cf->data[1] = CAN_ERR_CRTL_RX_OVERFLOW; stats->rx_packets++; - stats->rx_bytes += cf->can_dlc; + stats->rx_bytes += cf->len; netif_rx(skb); return 0; } diff --git a/drivers/net/can/usb/kvaser_usb/kvaser_usb_hydra.c b/drivers/net/can/usb/kvaser_usb/kvaser_usb_hydra.c index 906a3a340131..fea87398e5b7 100644 --- a/drivers/net/can/usb/kvaser_usb/kvaser_usb_hydra.c +++ b/drivers/net/can/usb/kvaser_usb/kvaser_usb_hydra.c @@ -893,11 +893,11 @@ static void kvaser_usb_hydra_update_state(struct kvaser_usb_net_priv *priv, cf->data[6] = bec->txerr; cf->data[7] = bec->rxerr; stats = &netdev->stats; stats->rx_packets++; - stats->rx_bytes += cf->can_dlc; + stats->rx_bytes += cf->len; netif_rx(skb); } static void kvaser_usb_hydra_state_event(const struct kvaser_usb *dev, const struct kvaser_cmd *cmd) @@ -1047,11 +1047,11 @@ kvaser_usb_hydra_error_frame(struct kvaser_usb_net_priv *priv, cf->can_id |= CAN_ERR_BUSERROR; cf->data[6] = bec.txerr; cf->data[7] = bec.rxerr; stats->rx_packets++; - stats->rx_bytes += cf->can_dlc; + stats->rx_bytes += cf->len; netif_rx(skb); priv->bec.txerr = bec.txerr; priv->bec.rxerr = bec.rxerr; } @@ -1082,11 +1082,11 @@ static void kvaser_usb_hydra_one_shot_fail(struct kvaser_usb_net_priv *priv, priv->can.can_stats.arbitration_lost++; } stats->tx_errors++; stats->rx_packets++; - stats->rx_bytes += cf->can_dlc; + stats->rx_bytes += cf->len; netif_rx(skb); } static void kvaser_usb_hydra_tx_acknowledge(const struct kvaser_usb *dev, const struct kvaser_cmd *cmd) @@ -1178,19 +1178,19 @@ static void kvaser_usb_hydra_rx_msg_std(const struct kvaser_usb *dev, } if (flags & KVASER_USB_HYDRA_CF_FLAG_OVERRUN) kvaser_usb_can_rx_over_error(priv->netdev); - cf->can_dlc = can_cc_dlc2len(cmd->rx_can.dlc); + cf->len = can_cc_dlc2len(cmd->rx_can.dlc); if (flags & KVASER_USB_HYDRA_CF_FLAG_REMOTE_FRAME) cf->can_id |= CAN_RTR_FLAG; else - memcpy(cf->data, cmd->rx_can.data, cf->can_dlc); + memcpy(cf->data, cmd->rx_can.data, cf->len); stats->rx_packets++; - stats->rx_bytes += cf->can_dlc; + stats->rx_bytes += cf->len; netif_rx(skb); } static void kvaser_usb_hydra_rx_msg_ext(const struct kvaser_usb *dev, const struct kvaser_cmd_ext *cmd) @@ -1432,11 +1432,11 @@ kvaser_usb_hydra_frame_to_cmd_std(const struct kvaser_usb_net_priv *priv, struct kvaser_cmd *cmd; struct can_frame *cf = (struct can_frame *)skb->data; u32 flags; u32 id; - *frame_len = cf->can_dlc; + *frame_len = cf->len; cmd = kcalloc(1, sizeof(struct kvaser_cmd), GFP_ATOMIC); if (!cmd) return NULL; @@ -1453,11 +1453,11 @@ kvaser_usb_hydra_frame_to_cmd_std(const struct kvaser_usb_net_priv *priv, id |= KVASER_USB_HYDRA_EXTENDED_FRAME_ID; } else { id = cf->can_id & CAN_SFF_MASK; } - cmd->tx_can.dlc = cf->can_dlc; + cmd->tx_can.dlc = cf->len; flags = (cf->can_id & CAN_EFF_FLAG ? KVASER_USB_HYDRA_CF_FLAG_EXTENDED_ID : 0); if (cf->can_id & CAN_RTR_FLAG) diff --git a/drivers/net/can/usb/kvaser_usb/kvaser_usb_leaf.c b/drivers/net/can/usb/kvaser_usb/kvaser_usb_leaf.c index 916ab994cce4..98c016ef0607 100644 --- a/drivers/net/can/usb/kvaser_usb/kvaser_usb_leaf.c +++ b/drivers/net/can/usb/kvaser_usb/kvaser_usb_leaf.c @@ -348,11 +348,11 @@ kvaser_usb_leaf_frame_to_cmd(const struct kvaser_usb_net_priv *priv, struct kvaser_usb *dev = priv->dev; struct kvaser_cmd *cmd; u8 *cmd_tx_can_flags = NULL; /* GCC */ struct can_frame *cf = (struct can_frame *)skb->data; - *frame_len = cf->can_dlc; + *frame_len = cf->len; cmd = kmalloc(sizeof(*cmd), GFP_ATOMIC); if (cmd) { cmd->u.tx_can.tid = transid & 0xff; cmd->len = *cmd_len = CMD_HEADER_LEN + @@ -381,12 +381,12 @@ kvaser_usb_leaf_frame_to_cmd(const struct kvaser_usb_net_priv *priv, cmd->id = CMD_TX_STD_MESSAGE; cmd->u.tx_can.data[0] = (cf->can_id >> 6) & 0x1f; cmd->u.tx_can.data[1] = cf->can_id & 0x3f; } - cmd->u.tx_can.data[5] = cf->can_dlc; - memcpy(&cmd->u.tx_can.data[6], cf->data, cf->can_dlc); + cmd->u.tx_can.data[5] = cf->len; + memcpy(&cmd->u.tx_can.data[6], cf->data, cf->len); if (cf->can_id & CAN_RTR_FLAG) *cmd_tx_can_flags |= MSG_FLAG_REMOTE_FRAME; } return cmd; @@ -574,11 +574,11 @@ static void kvaser_usb_leaf_tx_acknowledge(const struct kvaser_usb *dev, skb = alloc_can_err_skb(priv->netdev, &cf); if (skb) { cf->can_id |= CAN_ERR_RESTARTED; stats->rx_packets++; - stats->rx_bytes += cf->can_dlc; + stats->rx_bytes += cf->len; netif_rx(skb); } else { netdev_err(priv->netdev, "No memory left for err_skb\n"); } @@ -692,11 +692,11 @@ kvaser_usb_leaf_rx_error_update_can_state(struct kvaser_usb_net_priv *priv, static void kvaser_usb_leaf_rx_error(const struct kvaser_usb *dev, const struct kvaser_usb_err_summary *es) { struct can_frame *cf; struct can_frame tmp_cf = { .can_id = CAN_ERR_FLAG, - .can_dlc = CAN_ERR_DLC }; + .len = CAN_ERR_DLC }; struct sk_buff *skb; struct net_device_stats *stats; struct kvaser_usb_net_priv *priv; enum can_state old_state, new_state; @@ -776,11 +776,11 @@ static void kvaser_usb_leaf_rx_error(const struct kvaser_usb *dev, cf->data[6] = es->txerr; cf->data[7] = es->rxerr; stats->rx_packets++; - stats->rx_bytes += cf->can_dlc; + stats->rx_bytes += cf->len; netif_rx(skb); } /* For USBCAN, report error to userspace if the channels's errors counter * has changed, or we're the only channel seeing a bus error state. @@ -976,17 +976,17 @@ static void kvaser_usb_leaf_rx_can_msg(const struct kvaser_usb *dev, if (cf->can_id & KVASER_EXTENDED_FRAME) cf->can_id &= CAN_EFF_MASK | CAN_EFF_FLAG; else cf->can_id &= CAN_SFF_MASK; - cf->can_dlc = can_cc_dlc2len(cmd->u.leaf.log_message.dlc); + cf->len = can_cc_dlc2len(cmd->u.leaf.log_message.dlc); if (cmd->u.leaf.log_message.flags & MSG_FLAG_REMOTE_FRAME) cf->can_id |= CAN_RTR_FLAG; else memcpy(cf->data, &cmd->u.leaf.log_message.data, - cf->can_dlc); + cf->len); } else { cf->can_id = ((rx_data[0] & 0x1f) << 6) | (rx_data[1] & 0x3f); if (cmd->id == CMD_RX_EXT_MESSAGE) { cf->can_id <<= 18; @@ -994,20 +994,20 @@ static void kvaser_usb_leaf_rx_can_msg(const struct kvaser_usb *dev, ((rx_data[3] & 0xff) << 6) | (rx_data[4] & 0x3f); cf->can_id |= CAN_EFF_FLAG; } - cf->can_dlc = can_cc_dlc2len(rx_data[5]); + cf->len = can_cc_dlc2len(rx_data[5]); if (cmd->u.rx_can_header.flag & MSG_FLAG_REMOTE_FRAME) cf->can_id |= CAN_RTR_FLAG; else - memcpy(cf->data, &rx_data[6], cf->can_dlc); + memcpy(cf->data, &rx_data[6], cf->len); } stats->rx_packets++; - stats->rx_bytes += cf->can_dlc; + stats->rx_bytes += cf->len; netif_rx(skb); } static void kvaser_usb_leaf_start_chip_reply(const struct kvaser_usb *dev, const struct kvaser_cmd *cmd) diff --git a/drivers/net/can/usb/mcba_usb.c b/drivers/net/can/usb/mcba_usb.c index 0e6d180597f3..2f2bd18d5a10 100644 --- a/drivers/net/can/usb/mcba_usb.c +++ b/drivers/net/can/usb/mcba_usb.c @@ -182,11 +182,11 @@ static inline struct mcba_usb_ctx *mcba_usb_get_free_ctx(struct mcba_priv *priv, ctx = &priv->tx_context[i]; ctx->ndx = i; if (cf) { ctx->can = true; - ctx->dlc = cf->can_dlc; + ctx->dlc = cf->len; } else { ctx->can = false; ctx->dlc = 0; } @@ -348,11 +348,11 @@ static netdev_tx_t mcba_usb_start_xmit(struct sk_buff *skb, put_unaligned_be16((cf->can_id & CAN_SFF_MASK) << 5, &usb_msg.sid); usb_msg.eid = 0; } - usb_msg.dlc = cf->can_dlc; + usb_msg.dlc = cf->len; memcpy(usb_msg.data, cf->data, usb_msg.dlc); if (cf->can_id & CAN_RTR_FLAG) usb_msg.dlc |= MCBA_DLC_RTR_MASK; @@ -449,16 +449,16 @@ static void mcba_usb_process_can(struct mcba_priv *priv, } if (msg->dlc & MCBA_DLC_RTR_MASK) cf->can_id |= CAN_RTR_FLAG; - cf->can_dlc = can_cc_dlc2len(msg->dlc & MCBA_DLC_MASK); + cf->len = can_cc_dlc2len(msg->dlc & MCBA_DLC_MASK); - memcpy(cf->data, msg->data, cf->can_dlc); + memcpy(cf->data, msg->data, cf->len); stats->rx_packets++; - stats->rx_bytes += cf->can_dlc; + stats->rx_bytes += cf->len; can_led_event(priv->netdev, CAN_LED_EVENT_RX); netif_rx(skb); } diff --git a/drivers/net/can/usb/peak_usb/pcan_usb.c b/drivers/net/can/usb/peak_usb/pcan_usb.c index f7fc82203489..ec34f87cc02c 100644 --- a/drivers/net/can/usb/peak_usb/pcan_usb.c +++ b/drivers/net/can/usb/peak_usb/pcan_usb.c @@ -594,11 +594,11 @@ static int pcan_usb_decode_error(struct pcan_usb_msg_context *mc, u8 n, peak_usb_get_ts_time(&mc->pdev->time_ref, mc->ts16, &hwts->hwtstamp); } mc->netdev->stats.rx_packets++; - mc->netdev->stats.rx_bytes += cf->can_dlc; + mc->netdev->stats.rx_bytes += cf->len; netif_rx(skb); return 0; } @@ -732,11 +732,11 @@ static int pcan_usb_decode_data(struct pcan_usb_msg_context *mc, u8 status_len) mc->ptr += 2; cf->can_id = le16_to_cpu(tmp16) >> 5; } - cf->can_dlc = can_cc_dlc2len(rec_len); + cf->len = can_cc_dlc2len(rec_len); /* Only first packet timestamp is a word */ if (pcan_usb_decode_ts(mc, !mc->rec_ts_idx)) goto decode_failed; @@ -749,21 +749,21 @@ static int pcan_usb_decode_data(struct pcan_usb_msg_context *mc, u8 status_len) cf->can_id |= CAN_RTR_FLAG; } else { if ((mc->ptr + rec_len) > mc->end) goto decode_failed; - memcpy(cf->data, mc->ptr, cf->can_dlc); + memcpy(cf->data, mc->ptr, cf->len); mc->ptr += rec_len; } /* convert timestamp into kernel time */ hwts = skb_hwtstamps(skb); peak_usb_get_ts_time(&mc->pdev->time_ref, mc->ts16, &hwts->hwtstamp); /* update statistics */ mc->netdev->stats.rx_packets++; - mc->netdev->stats.rx_bytes += cf->can_dlc; + mc->netdev->stats.rx_bytes += cf->len; /* push the skb */ netif_rx(skb); return 0; @@ -836,11 +836,11 @@ static int pcan_usb_encode_msg(struct peak_usb_device *dev, struct sk_buff *skb, obuf[1] = 1; pc = obuf + PCAN_USB_MSG_HEADER_LEN; /* status/len byte */ - *pc = cf->can_dlc; + *pc = cf->len; if (cf->can_id & CAN_RTR_FLAG) *pc |= PCAN_USB_STATUSLEN_RTR; /* can id */ if (cf->can_id & CAN_EFF_FLAG) { @@ -856,12 +856,12 @@ static int pcan_usb_encode_msg(struct peak_usb_device *dev, struct sk_buff *skb, pc += 2; } /* can data */ if (!(cf->can_id & CAN_RTR_FLAG)) { - memcpy(pc, cf->data, cf->can_dlc); - pc += cf->can_dlc; + memcpy(pc, cf->data, cf->len); + pc += cf->len; } obuf[(*size)-1] = (u8)(stats->tx_packets & 0xff); return 0; diff --git a/drivers/net/can/usb/peak_usb/pcan_usb_fd.c b/drivers/net/can/usb/peak_usb/pcan_usb_fd.c index 1233ef20646a..922280692a8f 100644 --- a/drivers/net/can/usb/peak_usb/pcan_usb_fd.c +++ b/drivers/net/can/usb/peak_usb/pcan_usb_fd.c @@ -579,11 +579,11 @@ static int pcan_usb_fd_decode_status(struct pcan_usb_fd_if *usb_if, return -ENOMEM; peak_usb_netif_rx(skb, &usb_if->time_ref, le32_to_cpu(sm->ts_low)); netdev->stats.rx_packets++; - netdev->stats.rx_bytes += cf->can_dlc; + netdev->stats.rx_bytes += cf->len; return 0; } /* handle uCAN error message */ @@ -735,11 +735,11 @@ static int pcan_usb_fd_encode_msg(struct peak_usb_device *dev, struct sk_buff *skb, u8 *obuf, size_t *size) { struct pucan_tx_msg *tx_msg = (struct pucan_tx_msg *)obuf; struct canfd_frame *cfd = (struct canfd_frame *)skb->data; u16 tx_msg_size, tx_msg_flags; - u8 can_dlc; + u8 len; if (cfd->len > CANFD_MAX_DLEN) return -EINVAL; tx_msg_size = ALIGN(sizeof(struct pucan_tx_msg) + cfd->len, 4); @@ -754,29 +754,29 @@ static int pcan_usb_fd_encode_msg(struct peak_usb_device *dev, tx_msg->can_id = cpu_to_le32(cfd->can_id & CAN_SFF_MASK); } if (can_is_canfd_skb(skb)) { /* considering a CANFD frame */ - can_dlc = can_len2dlc(cfd->len); + len = can_len2dlc(cfd->len); tx_msg_flags |= PUCAN_MSG_EXT_DATA_LEN; if (cfd->flags & CANFD_BRS) tx_msg_flags |= PUCAN_MSG_BITRATE_SWITCH; if (cfd->flags & CANFD_ESI) tx_msg_flags |= PUCAN_MSG_ERROR_STATE_IND; } else { /* CAND 2.0 frames */ - can_dlc = cfd->len; + len = cfd->len; if (cfd->can_id & CAN_RTR_FLAG) tx_msg_flags |= PUCAN_MSG_RTR; } tx_msg->flags = cpu_to_le16(tx_msg_flags); - tx_msg->channel_dlc = PUCAN_MSG_CHANNEL_DLC(dev->ctrl_idx, can_dlc); + tx_msg->channel_dlc = PUCAN_MSG_CHANNEL_DLC(dev->ctrl_idx, len); memcpy(tx_msg->d, cfd->data, cfd->len); /* add null size message to tag the end (messages are 32-bits aligned) */ tx_msg = (struct pucan_tx_msg *)(obuf + tx_msg_size); diff --git a/drivers/net/can/usb/peak_usb/pcan_usb_pro.c b/drivers/net/can/usb/peak_usb/pcan_usb_pro.c index c7564773fb2b..275087c39602 100644 --- a/drivers/net/can/usb/peak_usb/pcan_usb_pro.c +++ b/drivers/net/can/usb/peak_usb/pcan_usb_pro.c @@ -530,26 +530,26 @@ static int pcan_usb_pro_handle_canmsg(struct pcan_usb_pro_interface *usb_if, skb = alloc_can_skb(netdev, &can_frame); if (!skb) return -ENOMEM; can_frame->can_id = le32_to_cpu(rx->id); - can_frame->can_dlc = rx->len & 0x0f; + can_frame->len = rx->len & 0x0f; if (rx->flags & PCAN_USBPRO_EXT) can_frame->can_id |= CAN_EFF_FLAG; if (rx->flags & PCAN_USBPRO_RTR) can_frame->can_id |= CAN_RTR_FLAG; else - memcpy(can_frame->data, rx->data, can_frame->can_dlc); + memcpy(can_frame->data, rx->data, can_frame->len); hwts = skb_hwtstamps(skb); peak_usb_get_ts_time(&usb_if->time_ref, le32_to_cpu(rx->ts32), &hwts->hwtstamp); netdev->stats.rx_packets++; - netdev->stats.rx_bytes += can_frame->can_dlc; + netdev->stats.rx_bytes += can_frame->len; netif_rx(skb); return 0; } @@ -660,11 +660,11 @@ static int pcan_usb_pro_handle_error(struct pcan_usb_pro_interface *usb_if, dev->can.state = new_state; hwts = skb_hwtstamps(skb); peak_usb_get_ts_time(&usb_if->time_ref, le32_to_cpu(er->ts32), &hwts->hwtstamp); netdev->stats.rx_packets++; - netdev->stats.rx_bytes += can_frame->can_dlc; + netdev->stats.rx_bytes += can_frame->len; netif_rx(skb); return 0; } @@ -765,18 +765,18 @@ static int pcan_usb_pro_encode_msg(struct peak_usb_device *dev, u8 data_type, len, flags; struct pcan_usb_pro_msg usb_msg; pcan_msg_init_empty(&usb_msg, obuf, *size); - if ((cf->can_id & CAN_RTR_FLAG) || (cf->can_dlc == 0)) + if ((cf->can_id & CAN_RTR_FLAG) || (cf->len == 0)) data_type = PCAN_USBPRO_TXMSG0; - else if (cf->can_dlc <= 4) + else if (cf->len <= 4) data_type = PCAN_USBPRO_TXMSG4; else data_type = PCAN_USBPRO_TXMSG8; - len = (dev->ctrl_idx << 4) | (cf->can_dlc & 0x0f); + len = (dev->ctrl_idx << 4) | (cf->len & 0x0f); flags = 0; if (cf->can_id & CAN_EFF_FLAG) flags |= 0x02; if (cf->can_id & CAN_RTR_FLAG) diff --git a/drivers/net/can/usb/ucan.c b/drivers/net/can/usb/ucan.c index 072058c6f6e8..7d92da8954fe 100644 --- a/drivers/net/can/usb/ucan.c +++ b/drivers/net/can/usb/ucan.c @@ -612,19 +612,19 @@ static void ucan_rx_can_msg(struct ucan_priv *up, struct ucan_message_in *m) /* fill the can frame */ cf->can_id = canid; /* compute DLC taking RTR_FLAG into account */ - cf->can_dlc = ucan_can_cc_dlc2len(&m->msg.can_msg, len); + cf->len = ucan_can_cc_dlc2len(&m->msg.can_msg, len); /* copy the payload of non RTR frames */ if (!(cf->can_id & CAN_RTR_FLAG) || (cf->can_id & CAN_ERR_FLAG)) - memcpy(cf->data, m->msg.can_msg.data, cf->can_dlc); + memcpy(cf->data, m->msg.can_msg.data, cf->len); /* don't count error frames as real packets */ stats->rx_packets++; - stats->rx_bytes += cf->can_dlc; + stats->rx_bytes += cf->len; /* pass it to Linux */ netif_rx(skb); } @@ -1076,19 +1076,19 @@ static struct urb *ucan_prepare_tx_urb(struct ucan_priv *up, if (cf->can_id & CAN_RTR_FLAG) { mlen = UCAN_OUT_HDR_SIZE + offsetof(struct ucan_can_msg, dlc) + sizeof(m->msg.can_msg.dlc); - m->msg.can_msg.dlc = cf->can_dlc; + m->msg.can_msg.dlc = cf->len; } else { mlen = UCAN_OUT_HDR_SIZE + - sizeof(m->msg.can_msg.id) + cf->can_dlc; - memcpy(m->msg.can_msg.data, cf->data, cf->can_dlc); + sizeof(m->msg.can_msg.id) + cf->len; + memcpy(m->msg.can_msg.data, cf->data, cf->len); } m->len = cpu_to_le16(mlen); - context->dlc = cf->can_dlc; + context->dlc = cf->len; m->subtype = echo_index; /* build the urb */ usb_fill_bulk_urb(urb, up->udev, diff --git a/drivers/net/can/usb/usb_8dev.c b/drivers/net/can/usb/usb_8dev.c index 216c58f8df6e..6517aaeb4bc0 100644 --- a/drivers/net/can/usb/usb_8dev.c +++ b/drivers/net/can/usb/usb_8dev.c @@ -447,11 +447,11 @@ static void usb_8dev_rx_err_msg(struct usb_8dev_priv *priv, priv->bec.txerr = txerr; priv->bec.rxerr = rxerr; stats->rx_packets++; - stats->rx_bytes += cf->can_dlc; + stats->rx_bytes += cf->len; netif_rx(skb); } /* Read data and status frames */ static void usb_8dev_rx_can_msg(struct usb_8dev_priv *priv, @@ -468,22 +468,22 @@ static void usb_8dev_rx_can_msg(struct usb_8dev_priv *priv, skb = alloc_can_skb(priv->netdev, &cf); if (!skb) return; cf->can_id = be32_to_cpu(msg->id); - cf->can_dlc = can_cc_dlc2len(msg->dlc & 0xF); + cf->len = can_cc_dlc2len(msg->dlc & 0xF); if (msg->flags & USB_8DEV_EXTID) cf->can_id |= CAN_EFF_FLAG; if (msg->flags & USB_8DEV_RTR) cf->can_id |= CAN_RTR_FLAG; else - memcpy(cf->data, msg->data, cf->can_dlc); + memcpy(cf->data, msg->data, cf->len); stats->rx_packets++; - stats->rx_bytes += cf->can_dlc; + stats->rx_bytes += cf->len; netif_rx(skb); can_led_event(priv->netdev, CAN_LED_EVENT_RX); } else { netdev_warn(priv->netdev, "frame type %d unknown", @@ -635,12 +635,12 @@ static netdev_tx_t usb_8dev_start_xmit(struct sk_buff *skb, if (cf->can_id & CAN_EFF_FLAG) msg->flags |= USB_8DEV_EXTID; msg->id = cpu_to_be32(cf->can_id & CAN_ERR_MASK); - msg->dlc = cf->can_dlc; - memcpy(msg->data, cf->data, cf->can_dlc); + msg->dlc = cf->len; + memcpy(msg->data, cf->data, cf->len); msg->end = USB_8DEV_DATA_END; for (i = 0; i < MAX_TX_URBS; i++) { if (priv->tx_contexts[i].echo_index == MAX_TX_URBS) { context = &priv->tx_contexts[i]; @@ -654,11 +654,11 @@ static netdev_tx_t usb_8dev_start_xmit(struct sk_buff *skb, if (!context) goto nofreecontext; context->priv = priv; context->echo_index = i; - context->dlc = cf->can_dlc; + context->dlc = cf->len; usb_fill_bulk_urb(urb, priv->udev, usb_sndbulkpipe(priv->udev, USB_8DEV_ENDP_DATA_TX), buf, size, usb_8dev_write_bulk_callback, context); urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; diff --git a/drivers/net/can/xilinx_can.c b/drivers/net/can/xilinx_can.c index 73e8b1df1071..88831ce0f2f8 100644 --- a/drivers/net/can/xilinx_can.c +++ b/drivers/net/can/xilinx_can.c @@ -757,11 +757,11 @@ static int xcan_rx(struct net_device *ndev, int frame_base) id_xcan = priv->read_reg(priv, XCAN_FRAME_ID_OFFSET(frame_base)); dlc = priv->read_reg(priv, XCAN_FRAME_DLC_OFFSET(frame_base)) >> XCAN_DLCR_DLC_SHIFT; /* Change Xilinx CAN data length format to socketCAN data format */ - cf->can_dlc = can_cc_dlc2len(dlc); + cf->len = can_cc_dlc2len(dlc); /* Change Xilinx CAN ID format to socketCAN ID format */ if (id_xcan & XCAN_IDR_IDE_MASK) { /* The received frame is an Extended format frame */ cf->can_id = (id_xcan & XCAN_IDR_ID1_MASK) >> 3; @@ -782,17 +782,17 @@ static int xcan_rx(struct net_device *ndev, int frame_base) data[0] = priv->read_reg(priv, XCAN_FRAME_DW1_OFFSET(frame_base)); data[1] = priv->read_reg(priv, XCAN_FRAME_DW2_OFFSET(frame_base)); if (!(cf->can_id & CAN_RTR_FLAG)) { /* Change Xilinx CAN data format to socketCAN data format */ - if (cf->can_dlc > 0) + if (cf->len > 0) *(__be32 *)(cf->data) = cpu_to_be32(data[0]); - if (cf->can_dlc > 4) + if (cf->len > 4) *(__be32 *)(cf->data + 4) = cpu_to_be32(data[1]); } - stats->rx_bytes += cf->can_dlc; + stats->rx_bytes += cf->len; stats->rx_packets++; netif_receive_skb(skb); return 1; } @@ -968,11 +968,11 @@ static void xcan_update_error_state_after_rxtx(struct net_device *ndev) if (skb) { struct net_device_stats *stats = &ndev->stats; stats->rx_packets++; - stats->rx_bytes += cf->can_dlc; + stats->rx_bytes += cf->len; netif_rx(skb); } } } diff --git a/include/linux/can/dev.h b/include/linux/can/dev.h index 802606e36b58..77da061c21c9 100644 --- a/include/linux/can/dev.h +++ b/include/linux/can/dev.h @@ -183,12 +183,12 @@ static inline void can_set_static_ctrlmode(struct net_device *dev, /* override MTU which was set by default in can_setup()? */ if (static_mode & CAN_CTRLMODE_FD) dev->mtu = CANFD_MTU; } -/* get data length from can_dlc with sanitized can_dlc */ -u8 can_dlc2len(u8 can_dlc); +/* get data length from raw data length code (DLC) */ +u8 can_dlc2len(u8 dlc); /* map the sanitized data length to an appropriate data length code */ u8 can_len2dlc(u8 len); struct net_device *alloc_candev_mqs(int sizeof_priv, unsigned int echo_skb_max, diff --git a/net/can/af_can.c b/net/can/af_can.c index 6373ab9c5507..fd558e4df8bb 100644 --- a/net/can/af_can.c +++ b/net/can/af_can.c @@ -868,11 +868,11 @@ static struct pernet_operations can_pernet_ops __read_mostly = { static __init int can_init(void) { int err; /* check for correct padding to be able to use the structs similarly */ - BUILD_BUG_ON(offsetof(struct can_frame, can_dlc) != + BUILD_BUG_ON(offsetof(struct can_frame, len) != offsetof(struct canfd_frame, len) || offsetof(struct can_frame, data) != offsetof(struct canfd_frame, data)); pr_info("can: controller area network core\n"); diff --git a/net/can/gw.c b/net/can/gw.c index 6b790b6ff8d2..de5e8859ec9b 100644 --- a/net/can/gw.c +++ b/net/can/gw.c @@ -205,11 +205,11 @@ static void canframecpy(struct canfd_frame *dst, struct can_frame *src) * data are copied in the 3 bytes hole of the struct. This is needed * to make easy compares of the data in the struct cf_mod. */ dst->can_id = src->can_id; - dst->len = src->can_dlc; + dst->len = src->len; *(u64 *)dst->data = *(u64 *)src->data; } static void canfdframecpy(struct canfd_frame *dst, struct canfd_frame *src) { diff --git a/net/can/j1939/main.c b/net/can/j1939/main.c index 137054bff9ec..bb914d8b4216 100644 --- a/net/can/j1939/main.c +++ b/net/can/j1939/main.c @@ -60,11 +60,11 @@ static void j1939_can_recv(struct sk_buff *iskb, void *data) */ cf = (void *)skb->data; skb_pull(skb, J1939_CAN_HDR); /* fix length, set to dlc, with 8 maximum */ - skb_trim(skb, min_t(uint8_t, cf->can_dlc, 8)); + skb_trim(skb, min_t(uint8_t, cf->len, 8)); /* set addr */ skcb = j1939_skb_to_cb(skb); memset(skcb, 0, sizeof(*skcb)); @@ -333,11 +333,11 @@ int j1939_send_one(struct j1939_priv *priv, struct sk_buff *skb) skcb->addr.sa; if (j1939_pgn_is_pdu1(skcb->addr.pgn)) canid |= skcb->addr.da << 8; cf->can_id = canid; - cf->can_dlc = dlc; + cf->len = dlc; return can_send(skb, 1); failed: kfree_skb(skb); From patchwork Tue Nov 10 10:18:49 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oliver Hartkopp X-Patchwork-Id: 11893771 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id EBAA2C55ABD for ; Tue, 10 Nov 2020 10:19:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8C0F4207D3 for ; Tue, 10 Nov 2020 10:19:17 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=hartkopp.net header.i=@hartkopp.net header.b="SbJnpEKI" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732050AbgKJKTR (ORCPT ); Tue, 10 Nov 2020 05:19:17 -0500 Received: from mo4-p02-ob.smtp.rzone.de ([85.215.255.84]:23173 "EHLO mo4-p02-ob.smtp.rzone.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731886AbgKJKTP (ORCPT ); Tue, 10 Nov 2020 05:19:15 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1605003548; s=strato-dkim-0002; d=hartkopp.net; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: X-RZG-CLASS-ID:X-RZG-AUTH:From:Subject:Sender; bh=998jvg33guotTgYt35/RlgpnmOOkOUBLFFKj1YMI8B0=; b=SbJnpEKIYAt02c5Uos1N4PUb4HLlDa+SGT84sHe4B1Kec9KIWrSIV5Kv7anTbGvXGO 5MYx/Gvi05KIQSf+1t3rlkiB8ID37z/eO+YzYS+Kuvi1Az4VPw/NguVATgVrNJRWjGAS nk4ifCfWNUZtvWo1Cbst/rhz9A/iWNnFgWwoNPLXIgH2eLCdejol62rinmGHYor33xZE A39MML2nno0EYqah9idlq1NQ+PqZVJhGT7d0kH8BJIUtvz34IiAsFGy46wTWF0f20wXS LH9FZSR1zwHk2BBnO38LobS31FykX6K1+u4bZaskCry7IcAZ0ZR45oFhjJ16eQ+t1fnd lr8w== X-RZG-AUTH: ":P2MHfkW8eP4Mre39l357AZT/I7AY/7nT2yrDxb8mjGrp7owjzFK3JbFk1mS0k+8CejudJywjsi+/Fw==" X-RZG-CLASS-ID: mo00 Received: from silver.lan by smtp.strato.de (RZmta 47.3.3 DYNA|AUTH) with ESMTPSA id V0298cwAAAJ3AQh (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256 bits)) (Client did not present a certificate); Tue, 10 Nov 2020 11:19:03 +0100 (CET) From: Oliver Hartkopp To: linux-can@vger.kernel.org, mkl@pengutronix.de, mailhol.vincent@wanadoo.fr Cc: netdev@vger.kernel.org, Oliver Hartkopp Subject: [PATCH v6 5/8] can: rename CAN FD related can_len2dlc and can_dlc2len helpers Date: Tue, 10 Nov 2020 11:18:49 +0100 Message-Id: <20201110101852.1973-6-socketcan@hartkopp.net> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201110101852.1973-1-socketcan@hartkopp.net> References: <20201110101852.1973-1-socketcan@hartkopp.net> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org The helper functions can_len2dlc and can_dlc2len are only relevant for CAN FD data length code (DLC) conversion. To fit the introduced can_cc_dlc2len for Classical CAN we rename: can_dlc2len -> can_fd_dlc2len to get the payload length from the DLC can_len2dlc -> can_fd_len2dlc to get the DLC from the payload length Suggested-by: Vincent Mailhol Signed-off-by: Oliver Hartkopp --- Documentation/networking/can.rst | 2 +- drivers/net/can/dev.c | 8 ++++---- drivers/net/can/flexcan.c | 4 ++-- drivers/net/can/ifi_canfd/ifi_canfd.c | 4 ++-- drivers/net/can/kvaser_pciefd.c | 6 +++--- drivers/net/can/m_can/m_can.c | 6 +++--- drivers/net/can/peak_canfd/peak_canfd.c | 4 ++-- drivers/net/can/rcar/rcar_canfd.c | 4 ++-- drivers/net/can/spi/mcp251xfd/mcp251xfd-core.c | 8 ++++---- drivers/net/can/usb/kvaser_usb/kvaser_usb_hydra.c | 6 +++--- drivers/net/can/usb/peak_usb/pcan_usb_fd.c | 4 ++-- drivers/net/can/xilinx_can.c | 4 ++-- include/linux/can/dev.h | 4 ++-- 13 files changed, 32 insertions(+), 32 deletions(-) diff --git a/Documentation/networking/can.rst b/Documentation/networking/can.rst index ff05cbd05e0d..4895b0dd2714 100644 --- a/Documentation/networking/can.rst +++ b/Documentation/networking/can.rst @@ -1330,11 +1330,11 @@ payload. The representation of this length in can_frame.can_dlc and canfd_frame.len for userspace applications and inside the Linux network layer is a plain value from 0 .. 64 instead of the CAN 'data length code'. The data length code was a 1:1 mapping to the payload length in the legacy CAN frames anyway. The payload length to the bus-relevant DLC mapping is only performed inside the CAN drivers, preferably with the helper -functions can_dlc2len() and can_len2dlc(). +functions can_fd_dlc2len() and can_fd_len2dlc(). The CAN netdevice driver capabilities can be distinguished by the network devices maximum transfer unit (MTU):: MTU = 16 (CAN_MTU) => sizeof(struct can_frame) => 'legacy' CAN device diff --git a/drivers/net/can/dev.c b/drivers/net/can/dev.c index 566501a02b91..7878544184b9 100644 --- a/drivers/net/can/dev.c +++ b/drivers/net/can/dev.c @@ -29,15 +29,15 @@ MODULE_AUTHOR("Wolfgang Grandegger "); static const u8 dlc2len[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 12, 16, 20, 24, 32, 48, 64}; /* get data length from raw data length code (DLC) */ -u8 can_dlc2len(u8 dlc) +u8 can_fd_dlc2len(u8 dlc) { return dlc2len[dlc & 0x0F]; } -EXPORT_SYMBOL_GPL(can_dlc2len); +EXPORT_SYMBOL_GPL(can_fd_dlc2len); static const u8 len2dlc[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, /* 0 - 8 */ 9, 9, 9, 9, /* 9 - 12 */ 10, 10, 10, 10, /* 13 - 16 */ 11, 11, 11, 11, /* 17 - 20 */ @@ -47,18 +47,18 @@ static const u8 len2dlc[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, /* 0 - 8 */ 14, 14, 14, 14, 14, 14, 14, 14, /* 41 - 48 */ 15, 15, 15, 15, 15, 15, 15, 15, /* 49 - 56 */ 15, 15, 15, 15, 15, 15, 15, 15}; /* 57 - 64 */ /* map the sanitized data length to an appropriate data length code */ -u8 can_len2dlc(u8 len) +u8 can_fd_len2dlc(u8 len) { if (unlikely(len > 64)) return 0xF; return len2dlc[len]; } -EXPORT_SYMBOL_GPL(can_len2dlc); +EXPORT_SYMBOL_GPL(can_fd_len2dlc); #ifdef CONFIG_CAN_CALC_BITTIMING #define CAN_CALC_MAX_ERROR 50 /* in one-tenth of a percent */ /* Bit-timing calculation derived from: diff --git a/drivers/net/can/flexcan.c b/drivers/net/can/flexcan.c index e76fb1500fa1..5542290d29f5 100644 --- a/drivers/net/can/flexcan.c +++ b/drivers/net/can/flexcan.c @@ -742,11 +742,11 @@ static netdev_tx_t flexcan_start_xmit(struct sk_buff *skb, struct net_device *de { const struct flexcan_priv *priv = netdev_priv(dev); struct canfd_frame *cfd = (struct canfd_frame *)skb->data; u32 can_id; u32 data; - u32 ctrl = FLEXCAN_MB_CODE_TX_DATA | ((can_len2dlc(cfd->len)) << 16); + u32 ctrl = FLEXCAN_MB_CODE_TX_DATA | ((can_fd_len2dlc(cfd->len)) << 16); int i; if (can_dropped_invalid_skb(dev, skb)) return NETDEV_TX_OK; @@ -996,11 +996,11 @@ static struct sk_buff *flexcan_mailbox_read(struct can_rx_offload *offload, cfd->can_id = ((reg_id >> 0) & CAN_EFF_MASK) | CAN_EFF_FLAG; else cfd->can_id = (reg_id >> 18) & CAN_SFF_MASK; if (reg_ctrl & FLEXCAN_MB_CNT_EDL) { - cfd->len = can_dlc2len((reg_ctrl >> 16) & 0xf); + cfd->len = can_fd_dlc2len((reg_ctrl >> 16) & 0xf); if (reg_ctrl & FLEXCAN_MB_CNT_BRS) cfd->flags |= CANFD_BRS; } else { cfd->len = can_cc_dlc2len((reg_ctrl >> 16) & 0xf); diff --git a/drivers/net/can/ifi_canfd/ifi_canfd.c b/drivers/net/can/ifi_canfd/ifi_canfd.c index 3df55b0e4ef3..86b0e1406a21 100644 --- a/drivers/net/can/ifi_canfd/ifi_canfd.c +++ b/drivers/net/can/ifi_canfd/ifi_canfd.c @@ -269,11 +269,11 @@ static void ifi_canfd_read_fifo(struct net_device *ndev) } dlc = (rxdlc >> IFI_CANFD_RXFIFO_DLC_DLC_OFFSET) & IFI_CANFD_RXFIFO_DLC_DLC_MASK; if (rxdlc & IFI_CANFD_RXFIFO_DLC_EDL) - cf->len = can_dlc2len(dlc); + cf->len = can_fd_dlc2len(dlc); else cf->len = can_cc_dlc2len(dlc); rxid = readl(priv->base + IFI_CANFD_RXFIFO_ID); id = (rxid >> IFI_CANFD_RXFIFO_ID_ID_OFFSET); @@ -898,11 +898,11 @@ static netdev_tx_t ifi_canfd_start_xmit(struct sk_buff *skb, txid |= IFI_CANFD_TXFIFO_ID_IDE; } else { txid = cf->can_id & CAN_SFF_MASK; } - txdlc = can_len2dlc(cf->len); + txdlc = can_fd_len2dlc(cf->len); if ((priv->can.ctrlmode & CAN_CTRLMODE_FD) && can_is_canfd_skb(skb)) { txdlc |= IFI_CANFD_TXFIFO_DLC_EDL; if (cf->flags & CANFD_BRS) txdlc |= IFI_CANFD_TXFIFO_DLC_BRS; } diff --git a/drivers/net/can/kvaser_pciefd.c b/drivers/net/can/kvaser_pciefd.c index 8b5f75209b09..118c6d7b38ac 100644 --- a/drivers/net/can/kvaser_pciefd.c +++ b/drivers/net/can/kvaser_pciefd.c @@ -738,11 +738,11 @@ static int kvaser_pciefd_prepare_tx_packet(struct kvaser_pciefd_tx_packet *p, if (cf->can_id & CAN_EFF_FLAG) p->header[0] |= KVASER_PCIEFD_RPACKET_IDE; p->header[0] |= cf->can_id & CAN_EFF_MASK; - p->header[1] |= can_len2dlc(cf->len) << KVASER_PCIEFD_RPACKET_DLC_SHIFT; + p->header[1] |= can_fd_len2dlc(cf->len) << KVASER_PCIEFD_RPACKET_DLC_SHIFT; p->header[1] |= KVASER_PCIEFD_TPACKET_AREQ; if (can_is_canfd_skb(skb)) { p->header[1] |= KVASER_PCIEFD_RPACKET_FDF; if (cf->flags & CANFD_BRS) @@ -1172,11 +1172,11 @@ static int kvaser_pciefd_handle_data_packet(struct kvaser_pciefd *pcie, cf->can_id = p->header[0] & CAN_EFF_MASK; if (p->header[0] & KVASER_PCIEFD_RPACKET_IDE) cf->can_id |= CAN_EFF_FLAG; - cf->len = can_dlc2len(p->header[1] >> KVASER_PCIEFD_RPACKET_DLC_SHIFT); + cf->len = can_fd_dlc2len(p->header[1] >> KVASER_PCIEFD_RPACKET_DLC_SHIFT); if (p->header[0] & KVASER_PCIEFD_RPACKET_RTR) cf->can_id |= CAN_RTR_FLAG; else memcpy(cf->data, data, cf->len); @@ -1598,11 +1598,11 @@ static int kvaser_pciefd_read_packet(struct kvaser_pciefd *pcie, int *start_pos, case KVASER_PCIEFD_PACK_TYPE_DATA: ret = kvaser_pciefd_handle_data_packet(pcie, p, &buffer[pos]); if (!(p->header[0] & KVASER_PCIEFD_RPACKET_RTR)) { u8 data_len; - data_len = can_dlc2len(p->header[1] >> + data_len = can_fd_dlc2len(p->header[1] >> KVASER_PCIEFD_RPACKET_DLC_SHIFT); pos += DIV_ROUND_UP(data_len, 4); } break; diff --git a/drivers/net/can/m_can/m_can.c b/drivers/net/can/m_can/m_can.c index e753c5f636bb..18a0f41bd90a 100644 --- a/drivers/net/can/m_can/m_can.c +++ b/drivers/net/can/m_can/m_can.c @@ -455,11 +455,11 @@ static void m_can_read_fifo(struct net_device *dev, u32 rxfs) stats->rx_dropped++; return; } if (dlc & RX_BUF_FDF) - cf->len = can_dlc2len((dlc >> 16) & 0x0F); + cf->len = can_fd_dlc2len((dlc >> 16) & 0x0F); else cf->len = can_cc_dlc2len((dlc >> 16) & 0x0F); id = m_can_fifo_read(cdev, fgi, M_CAN_FIFO_ID); if (id & RX_BUF_XTD) @@ -1482,11 +1482,11 @@ static netdev_tx_t m_can_tx_handler(struct m_can_classdev *cdev) netif_stop_queue(dev); /* message ram configuration */ m_can_fifo_write(cdev, 0, M_CAN_FIFO_ID, id); m_can_fifo_write(cdev, 0, M_CAN_FIFO_DLC, - can_len2dlc(cf->len) << 16); + can_fd_len2dlc(cf->len) << 16); for (i = 0; i < cf->len; i += 4) m_can_fifo_write(cdev, 0, M_CAN_FIFO_DATA(i / 4), *(u32 *)(cf->data + i)); @@ -1550,11 +1550,11 @@ static netdev_tx_t m_can_tx_handler(struct m_can_classdev *cdev) * sending the correct echo frame */ m_can_fifo_write(cdev, putidx, M_CAN_FIFO_DLC, ((putidx << TX_BUF_MM_SHIFT) & TX_BUF_MM_MASK) | - (can_len2dlc(cf->len) << 16) | + (can_fd_len2dlc(cf->len) << 16) | fdflags | TX_BUF_EFC); for (i = 0; i < cf->len; i += 4) m_can_fifo_write(cdev, putidx, M_CAN_FIFO_DATA(i / 4), *(u32 *)(cf->data + i)); diff --git a/drivers/net/can/peak_canfd/peak_canfd.c b/drivers/net/can/peak_canfd/peak_canfd.c index fff3a35276aa..c5334b0c3038 100644 --- a/drivers/net/can/peak_canfd/peak_canfd.c +++ b/drivers/net/can/peak_canfd/peak_canfd.c @@ -255,11 +255,11 @@ static int pucan_handle_can_rx(struct peak_canfd_priv *priv, struct sk_buff *skb; const u16 rx_msg_flags = le16_to_cpu(msg->flags); u8 cf_len; if (rx_msg_flags & PUCAN_MSG_EXT_DATA_LEN) - cf_len = can_dlc2len(pucan_msg_get_dlc(msg)); + cf_len = can_fd_dlc2len(pucan_msg_get_dlc(msg)); else cf_len = can_cc_dlc2len(pucan_msg_get_dlc(msg)); /* if this frame is an echo, */ if (rx_msg_flags & PUCAN_MSG_LOOPED_BACK) { @@ -680,11 +680,11 @@ static netdev_tx_t peak_canfd_start_xmit(struct sk_buff *skb, msg->can_id = cpu_to_le32(cf->can_id & CAN_SFF_MASK); } if (can_is_canfd_skb(skb)) { /* CAN FD frame format */ - len = can_len2dlc(cf->len); + len = can_fd_len2dlc(cf->len); msg_flags |= PUCAN_MSG_EXT_DATA_LEN; if (cf->flags & CANFD_BRS) msg_flags |= PUCAN_MSG_BITRATE_SWITCH; diff --git a/drivers/net/can/rcar/rcar_canfd.c b/drivers/net/can/rcar/rcar_canfd.c index 86c6cbdb7e53..2778ed5c61d1 100644 --- a/drivers/net/can/rcar/rcar_canfd.c +++ b/drivers/net/can/rcar/rcar_canfd.c @@ -1355,11 +1355,11 @@ static netdev_tx_t rcar_canfd_start_xmit(struct sk_buff *skb, } if (cf->can_id & CAN_RTR_FLAG) id |= RCANFD_CFID_CFRTR; - dlc = RCANFD_CFPTR_CFDLC(can_len2dlc(cf->len)); + dlc = RCANFD_CFPTR_CFDLC(can_fd_len2dlc(cf->len)); if (priv->can.ctrlmode & CAN_CTRLMODE_FD) { rcar_canfd_write(priv->base, RCANFD_F_CFID(ch, RCANFD_CFFIFO_IDX), id); rcar_canfd_write(priv->base, @@ -1444,11 +1444,11 @@ static void rcar_canfd_rx_pkt(struct rcar_canfd_channel *priv) else cf->can_id = id & CAN_SFF_MASK; if (priv->can.ctrlmode & CAN_CTRLMODE_FD) { if (sts & RCANFD_RFFDSTS_RFFDF) - cf->len = can_dlc2len(RCANFD_RFPTR_RFDLC(dlc)); + cf->len = can_fd_dlc2len(RCANFD_RFPTR_RFDLC(dlc)); else cf->len = can_cc_dlc2len(RCANFD_RFPTR_RFDLC(dlc)); if (sts & RCANFD_RFFDSTS_RFESI) { cf->flags |= CANFD_ESI; diff --git a/drivers/net/can/spi/mcp251xfd/mcp251xfd-core.c b/drivers/net/can/spi/mcp251xfd/mcp251xfd-core.c index 3bac7274ee5b..afa8cfc729b5 100644 --- a/drivers/net/can/spi/mcp251xfd/mcp251xfd-core.c +++ b/drivers/net/can/spi/mcp251xfd/mcp251xfd-core.c @@ -1403,11 +1403,11 @@ mcp251xfd_hw_rx_obj_to_skb(const struct mcp251xfd_priv *priv, if (hw_rx_obj->flags & MCP251XFD_OBJ_FLAGS_BRS) cfd->flags |= CANFD_BRS; dlc = FIELD_GET(MCP251XFD_OBJ_FLAGS_DLC, hw_rx_obj->flags); - cfd->len = can_dlc2len(dlc); + cfd->len = can_fd_dlc2len(dlc); } else { if (hw_rx_obj->flags & MCP251XFD_OBJ_FLAGS_RTR) cfd->can_id |= CAN_RTR_FLAG; cfd->len = can_cc_dlc2len(FIELD_GET(MCP251XFD_OBJ_FLAGS_DLC, @@ -2242,11 +2242,11 @@ mcp251xfd_tx_obj_from_skb(const struct mcp251xfd_priv *priv, /* Use the MCP2518FD mask even on the MCP2517FD. It doesn't * harm, only the lower 7 bits will be transferred into the * TEF object. */ - dlc = can_len2dlc(cfd->len); + dlc = can_fd_len2dlc(cfd->len); flags |= FIELD_PREP(MCP251XFD_OBJ_FLAGS_SEQ_MCP2518FD_MASK, seq) | FIELD_PREP(MCP251XFD_OBJ_FLAGS_DLC, dlc); if (cfd->can_id & CAN_RTR_FLAG) flags |= MCP251XFD_OBJ_FLAGS_RTR; @@ -2271,19 +2271,19 @@ mcp251xfd_tx_obj_from_skb(const struct mcp251xfd_priv *priv, put_unaligned_le32(id, &hw_tx_obj->id); put_unaligned_le32(flags, &hw_tx_obj->flags); /* Clear data at end of CAN frame */ offset = round_down(cfd->len, sizeof(u32)); - len = round_up(can_dlc2len(dlc), sizeof(u32)) - offset; + len = round_up(can_fd_dlc2len(dlc), sizeof(u32)) - offset; if (MCP251XFD_SANITIZE_CAN && len) memset(hw_tx_obj->data + offset, 0x0, len); memcpy(hw_tx_obj->data, cfd->data, cfd->len); /* Number of bytes to be written into the RAM of the controller */ len = sizeof(hw_tx_obj->id) + sizeof(hw_tx_obj->flags); if (MCP251XFD_SANITIZE_CAN) - len += round_up(can_dlc2len(dlc), sizeof(u32)); + len += round_up(can_fd_dlc2len(dlc), sizeof(u32)); else len += round_up(cfd->len, sizeof(u32)); if (priv->devtype_data.quirks & MCP251XFD_QUIRK_CRC_TX) { u16 crc; diff --git a/drivers/net/can/usb/kvaser_usb/kvaser_usb_hydra.c b/drivers/net/can/usb/kvaser_usb/kvaser_usb_hydra.c index fea87398e5b7..b8e0e2a88326 100644 --- a/drivers/net/can/usb/kvaser_usb/kvaser_usb_hydra.c +++ b/drivers/net/can/usb/kvaser_usb/kvaser_usb_hydra.c @@ -1118,11 +1118,11 @@ static void kvaser_usb_hydra_tx_acknowledge(const struct kvaser_usb *dev, context = &priv->tx_contexts[transid % dev->max_tx_urbs]; if (!one_shot_fail) { struct net_device_stats *stats = &priv->netdev->stats; stats->tx_packets++; - stats->tx_bytes += can_dlc2len(context->dlc); + stats->tx_bytes += can_fd_dlc2len(context->dlc); } spin_lock_irqsave(&priv->tx_contexts_lock, irq_flags); can_get_echo_skb(priv->netdev, context->echo_index); @@ -1249,11 +1249,11 @@ static void kvaser_usb_hydra_rx_msg_ext(const struct kvaser_usb *dev, if (flags & KVASER_USB_HYDRA_CF_FLAG_OVERRUN) kvaser_usb_can_rx_over_error(priv->netdev); if (flags & KVASER_USB_HYDRA_CF_FLAG_FDF) { - cf->len = can_dlc2len(dlc); + cf->len = can_fd_dlc2len(dlc); if (flags & KVASER_USB_HYDRA_CF_FLAG_BRS) cf->flags |= CANFD_BRS; if (flags & KVASER_USB_HYDRA_CF_FLAG_ESI) cf->flags |= CANFD_ESI; } else { @@ -1349,11 +1349,11 @@ kvaser_usb_hydra_frame_to_cmd_ext(const struct kvaser_usb_net_priv *priv, int *cmd_len, u16 transid) { struct kvaser_usb *dev = priv->dev; struct kvaser_cmd_ext *cmd; struct canfd_frame *cf = (struct canfd_frame *)skb->data; - u8 dlc = can_len2dlc(cf->len); + u8 dlc = can_fd_len2dlc(cf->len); u8 nbr_of_bytes = cf->len; u32 flags; u32 id; u32 kcan_id; u32 kcan_header; diff --git a/drivers/net/can/usb/peak_usb/pcan_usb_fd.c b/drivers/net/can/usb/peak_usb/pcan_usb_fd.c index 922280692a8f..761e78d8e647 100644 --- a/drivers/net/can/usb/peak_usb/pcan_usb_fd.c +++ b/drivers/net/can/usb/peak_usb/pcan_usb_fd.c @@ -490,11 +490,11 @@ static int pcan_usb_fd_decode_canmsg(struct pcan_usb_fd_if *usb_if, cfd->flags |= CANFD_BRS; if (rx_msg_flags & PUCAN_MSG_ERROR_STATE_IND) cfd->flags |= CANFD_ESI; - cfd->len = can_dlc2len(pucan_msg_get_dlc(rm)); + cfd->len = can_fd_dlc2len(pucan_msg_get_dlc(rm)); } else { /* CAN 2.0 frame case */ skb = alloc_can_skb(netdev, (struct can_frame **)&cfd); if (!skb) return -ENOMEM; @@ -754,11 +754,11 @@ static int pcan_usb_fd_encode_msg(struct peak_usb_device *dev, tx_msg->can_id = cpu_to_le32(cfd->can_id & CAN_SFF_MASK); } if (can_is_canfd_skb(skb)) { /* considering a CANFD frame */ - len = can_len2dlc(cfd->len); + len = can_fd_len2dlc(cfd->len); tx_msg_flags |= PUCAN_MSG_EXT_DATA_LEN; if (cfd->flags & CANFD_BRS) tx_msg_flags |= PUCAN_MSG_BITRATE_SWITCH; diff --git a/drivers/net/can/xilinx_can.c b/drivers/net/can/xilinx_can.c index 88831ce0f2f8..3f54edee92eb 100644 --- a/drivers/net/can/xilinx_can.c +++ b/drivers/net/can/xilinx_can.c @@ -581,11 +581,11 @@ static void xcan_write_frame(struct net_device *ndev, struct sk_buff *skb, if (cf->can_id & CAN_RTR_FLAG) /* Standard frames remote TX request */ id |= XCAN_IDR_SRR_MASK; } - dlc = can_len2dlc(cf->len) << XCAN_DLCR_DLC_SHIFT; + dlc = can_fd_len2dlc(cf->len) << XCAN_DLCR_DLC_SHIFT; if (can_is_canfd_skb(skb)) { if (cf->flags & CANFD_BRS) dlc |= XCAN_DLCR_BRS_MASK; dlc |= XCAN_DLCR_EDL_MASK; } @@ -830,11 +830,11 @@ static int xcanfd_rx(struct net_device *ndev, int frame_base) /* Change Xilinx CANFD data length format to socketCAN data * format */ if (dlc & XCAN_DLCR_EDL_MASK) - cf->len = can_dlc2len((dlc & XCAN_DLCR_DLC_MASK) >> + cf->len = can_fd_dlc2len((dlc & XCAN_DLCR_DLC_MASK) >> XCAN_DLCR_DLC_SHIFT); else cf->len = can_cc_dlc2len((dlc & XCAN_DLCR_DLC_MASK) >> XCAN_DLCR_DLC_SHIFT); diff --git a/include/linux/can/dev.h b/include/linux/can/dev.h index 77da061c21c9..e767a96ae075 100644 --- a/include/linux/can/dev.h +++ b/include/linux/can/dev.h @@ -184,14 +184,14 @@ static inline void can_set_static_ctrlmode(struct net_device *dev, if (static_mode & CAN_CTRLMODE_FD) dev->mtu = CANFD_MTU; } /* get data length from raw data length code (DLC) */ -u8 can_dlc2len(u8 dlc); +u8 can_fd_dlc2len(u8 dlc); /* map the sanitized data length to an appropriate data length code */ -u8 can_len2dlc(u8 len); +u8 can_fd_len2dlc(u8 len); struct net_device *alloc_candev_mqs(int sizeof_priv, unsigned int echo_skb_max, unsigned int txqs, unsigned int rxqs); #define alloc_candev(sizeof_priv, echo_skb_max) \ alloc_candev_mqs(sizeof_priv, echo_skb_max, 1, 1) From patchwork Tue Nov 10 10:18:50 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oliver Hartkopp X-Patchwork-Id: 11893773 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B4B79C56201 for ; Tue, 10 Nov 2020 10:19:21 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 57E9920809 for ; Tue, 10 Nov 2020 10:19:21 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=hartkopp.net header.i=@hartkopp.net header.b="oElOmSiz" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731969AbgKJKTN (ORCPT ); Tue, 10 Nov 2020 05:19:13 -0500 Received: from mo4-p02-ob.smtp.rzone.de ([85.215.255.83]:25374 "EHLO mo4-p02-ob.smtp.rzone.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731327AbgKJKTK (ORCPT ); Tue, 10 Nov 2020 05:19:10 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1605003546; s=strato-dkim-0002; d=hartkopp.net; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: X-RZG-CLASS-ID:X-RZG-AUTH:From:Subject:Sender; bh=0tSZQqbLxMtOAQqSv7xXuQUjGz61FmSkW4Hx2u7TkDg=; b=oElOmSizep+i/oJRcy/crHxnUV7PcXfFt7RDLik55e9O2CYCYh6hh9ihZ4/OR4o4cr o3eUhCZ06atguuWLGmkalYUQv0nNQ9u/CSvjP6eknLmuaEOaoPEjPsxdOIFwM8tI+ZfT hGLGVlx3TjNuffaUbBSuOdom9NFkS9XULFu/eCTBZDlz53SHBIWV6eDkzC7hiC/mn7Xu P1j3JG6hEnGjSMKXUxC7N0Qdy9l4J0c2/kWj88fk3XDQe5znNVBvDO6gaLyPmyyJ2rhK AjfpgcPCl3w0O/pjbSqaHp3OYhk3s1h38hGRYh2aYWH/UgQRuRdLT9q/Ta2plXktlOgI 0ASA== X-RZG-AUTH: ":P2MHfkW8eP4Mre39l357AZT/I7AY/7nT2yrDxb8mjGrp7owjzFK3JbFk1mS0k+8CejudJywjsi+/Fw==" X-RZG-CLASS-ID: mo00 Received: from silver.lan by smtp.strato.de (RZmta 47.3.3 DYNA|AUTH) with ESMTPSA id V0298cwAAAJ3AQi (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256 bits)) (Client did not present a certificate); Tue, 10 Nov 2020 11:19:03 +0100 (CET) From: Oliver Hartkopp To: linux-can@vger.kernel.org, mkl@pengutronix.de, mailhol.vincent@wanadoo.fr Cc: netdev@vger.kernel.org, Oliver Hartkopp Subject: [PATCH v6 6/8] can: update documentation for DLC usage in Classical CAN Date: Tue, 10 Nov 2020 11:18:50 +0100 Message-Id: <20201110101852.1973-7-socketcan@hartkopp.net> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201110101852.1973-1-socketcan@hartkopp.net> References: <20201110101852.1973-1-socketcan@hartkopp.net> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org The extension of struct can_frame with the len8_dlc element and the can_dlc naming issue required an update of the documentation. Additionally introduce the term 'Classical CAN' which has been established by CAN in Automation to separate the original CAN2.0 A/B from CAN FD. Updated some data structures and flags. Signed-off-by: Oliver Hartkopp --- Documentation/networking/can.rst | 68 ++++++++++++++++++++++++-------- 1 file changed, 52 insertions(+), 16 deletions(-) diff --git a/Documentation/networking/can.rst b/Documentation/networking/can.rst index 4895b0dd2714..f8dae662e454 100644 --- a/Documentation/networking/can.rst +++ b/Documentation/networking/can.rst @@ -226,24 +226,40 @@ interface (which is different from TCP/IP due to different addressing the socket, you can read(2) and write(2) from/to the socket or use send(2), sendto(2), sendmsg(2) and the recv* counterpart operations on the socket as usual. There are also CAN specific socket options described below. -The basic CAN frame structure and the sockaddr structure are defined -in include/linux/can.h: +The Classical CAN frame structure (aka CAN 2.0B), the CAN FD frame structure +and the sockaddr structure are defined in include/linux/can.h: .. code-block:: C struct can_frame { canid_t can_id; /* 32 bit CAN_ID + EFF/RTR/ERR flags */ - __u8 can_dlc; /* frame payload length in byte (0 .. 8) */ + union { + /* CAN frame payload length in byte (0 .. CAN_MAX_DLEN) + * was previously named can_dlc so we need to carry that + * name for legacy support + */ + __u8 len; + __u8 can_dlc; /* deprecated */ + }; __u8 __pad; /* padding */ __u8 __res0; /* reserved / padding */ - __u8 __res1; /* reserved / padding */ + __u8 len8_dlc; /* optional DLC for 8 byte payload length (9 .. 15) */ __u8 data[8] __attribute__((aligned(8))); }; +Remark: The len element contains the payload length in bytes and should be +used instead of can_dlc. The deprecated can_dlc was misleadingly named as +it always contained the plain payload length in bytes and not the so called +'data length code' (DLC). + +To pass the raw DLC from/to a Classical CAN network device the len8_dlc +element can contain values 9 .. 15 when the len element is 8 (the real +payload length for all DLC values greater or equal to 8). + The alignment of the (linear) payload data[] to a 64bit boundary allows the user to define their own structs and unions to easily access the CAN payload. There is no given byteorder on the CAN bus by default. A read(2) system call on a CAN_RAW socket transfers a struct can_frame to the user space. @@ -258,10 +274,27 @@ PF_PACKET socket, that also binds to a specific interface: int can_ifindex; union { /* transport protocol class address info (e.g. ISOTP) */ struct { canid_t rx_id, tx_id; } tp; + /* J1939 address information */ + struct { + /* 8 byte name when using dynamic addressing */ + __u64 name; + + /* pgn: + * 8 bit: PS in PDU2 case, else 0 + * 8 bit: PF + * 1 bit: DP + * 1 bit: reserved + */ + __u32 pgn; + + /* 1 byte address */ + __u8 addr; + } j1939; + /* reserved for future CAN protocols address information */ } can_addr; }; To determine the interface index an appropriate ioctl() has to @@ -369,11 +402,11 @@ bitrates for the arbitration phase and the payload phase of the CAN FD frame and up to 64 bytes of payload. This extended payload length breaks all the kernel interfaces (ABI) which heavily rely on the CAN frame with fixed eight bytes of payload (struct can_frame) like the CAN_RAW socket. Therefore e.g. the CAN_RAW socket supports a new socket option CAN_RAW_FD_FRAMES that switches the socket into a mode that allows the handling of CAN FD frames -and (legacy) CAN frames simultaneously (see :ref:`socketcan-rawfd`). +and Classical CAN frames simultaneously (see :ref:`socketcan-rawfd`). The struct canfd_frame is defined in include/linux/can.h: .. code-block:: C @@ -395,21 +428,21 @@ all structure elements can be used as-is - only the data[] becomes extended. When introducing the struct canfd_frame it turned out that the data length code (DLC) of the struct can_frame was used as a length information as the length and the DLC has a 1:1 mapping in the range of 0 .. 8. To preserve the easy handling of the length information the canfd_frame.len element contains a plain length value from 0 .. 64. So both canfd_frame.len and -can_frame.can_dlc are equal and contain a length information and no DLC. +can_frame.len are equal and contain a length information and no DLC. For details about the distinction of CAN and CAN FD capable devices and the mapping to the bus-relevant data length code (DLC), see :ref:`socketcan-can-fd-driver`. The length of the two CAN(FD) frame structures define the maximum transfer unit (MTU) of the CAN(FD) network interface and skbuff data length. Two definitions are specified for CAN specific MTUs in include/linux/can.h: .. code-block:: C - #define CAN_MTU (sizeof(struct can_frame)) == 16 => 'legacy' CAN frame + #define CAN_MTU (sizeof(struct can_frame)) == 16 => Classical CAN frame #define CANFD_MTU (sizeof(struct canfd_frame)) == 72 => CAN FD frame .. _socketcan-raw-sockets: @@ -607,11 +640,11 @@ Example: if (nbytes == CANFD_MTU) { printf("got CAN FD frame with length %d\n", cfd.len); /* cfd.flags contains valid data */ } else if (nbytes == CAN_MTU) { - printf("got legacy CAN frame with length %d\n", cfd.len); + printf("got Classical CAN frame with length %d\n", cfd.len); /* cfd.flags is undefined */ } else { fprintf(stderr, "read: invalid CAN(FD) frame\n"); return 1; } @@ -621,21 +654,21 @@ Example: printf("can_id: %X data length: %d data: ", cfd.can_id, cfd.len); for (i = 0; i < cfd.len; i++) printf("%02X ", cfd.data[i]); When reading with size CANFD_MTU only returns CAN_MTU bytes that have -been received from the socket a legacy CAN frame has been read into the +been received from the socket a Classical CAN frame has been read into the provided CAN FD structure. Note that the canfd_frame.flags data field is not specified in the struct can_frame and therefore it is only valid in CANFD_MTU sized CAN FD frames. Implementation hint for new CAN applications: To build a CAN FD aware application use struct canfd_frame as basic CAN data structure for CAN_RAW based applications. When the application is executed on an older Linux kernel and switching the CAN_RAW_FD_FRAMES -socket option returns an error: No problem. You'll get legacy CAN frames +socket option returns an error: No problem. You'll get Classical CAN frames or CAN FD frames and can process them the same way. When sending to CAN devices make sure that the device is capable to handle CAN FD frames by checking if the device maximum transfer unit is CANFD_MTU. The CAN device MTU can be retrieved e.g. with a SIOCGIFMTU ioctl() syscall. @@ -840,10 +873,12 @@ TX_RESET_MULTI_IDX: Reset the index for the multiple frame transmission. RX_RTR_FRAME: Send reply for RTR-request (placed in op->frames[0]). +CAN_FD_FRAME: + The CAN frames following the bcm_msg_head are struct canfd_frame's Broadcast Manager Transmission Timers ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Periodic transmission configurations may use up to two interval timers. @@ -1024,11 +1059,11 @@ In this example an application requests any CAN traffic from vcan0:: Additional procfs files in /proc/net/can:: stats - SocketCAN core statistics (rx/tx frames, match ratios, ...) reset_stats - manual statistic reset - version - prints the SocketCAN core version and the ABI version + version - prints SocketCAN core and ABI version (removed in Linux 5.10) Writing Own CAN Protocol Modules -------------------------------- @@ -1068,11 +1103,11 @@ General Settings .. code-block:: C dev->type = ARPHRD_CAN; /* the netdevice hardware type */ dev->flags = IFF_NOARP; /* CAN has no arp */ - dev->mtu = CAN_MTU; /* sizeof(struct can_frame) -> legacy CAN interface */ + dev->mtu = CAN_MTU; /* sizeof(struct can_frame) -> Classical CAN interface */ or alternative, when the controller supports CAN with flexible data rate: dev->mtu = CANFD_MTU; /* sizeof(struct canfd_frame) -> CAN FD interface */ The struct can_frame or struct canfd_frame is the payload of each socket @@ -1182,10 +1217,11 @@ Setting CAN device properties:: [ one-shot { on | off } ] [ berr-reporting { on | off } ] [ fd { on | off } ] [ fd-non-iso { on | off } ] [ presume-ack { on | off } ] + [ cc-len8-dlc { on | off } ] [ restart-ms TIME-MS ] [ restart ] Where: BITRATE := { 1..1000000 } @@ -1324,26 +1360,26 @@ CAN FD (Flexible Data Rate) Driver Support CAN FD capable CAN controllers support two different bitrates for the arbitration phase and the payload phase of the CAN FD frame. Therefore a second bit timing has to be specified in order to enable the CAN FD bitrate. Additionally CAN FD capable CAN controllers support up to 64 bytes of -payload. The representation of this length in can_frame.can_dlc and +payload. The representation of this length in can_frame.len and canfd_frame.len for userspace applications and inside the Linux network layer is a plain value from 0 .. 64 instead of the CAN 'data length code'. -The data length code was a 1:1 mapping to the payload length in the legacy +The data length code was a 1:1 mapping to the payload length in the Classical CAN frames anyway. The payload length to the bus-relevant DLC mapping is only performed inside the CAN drivers, preferably with the helper functions can_fd_dlc2len() and can_fd_len2dlc(). The CAN netdevice driver capabilities can be distinguished by the network devices maximum transfer unit (MTU):: - MTU = 16 (CAN_MTU) => sizeof(struct can_frame) => 'legacy' CAN device + MTU = 16 (CAN_MTU) => sizeof(struct can_frame) => Classical CAN device MTU = 72 (CANFD_MTU) => sizeof(struct canfd_frame) => CAN FD capable device The CAN device MTU can be retrieved e.g. with a SIOCGIFMTU ioctl() syscall. -N.B. CAN FD capable devices can also handle and send legacy CAN frames. +N.B. CAN FD capable devices can also handle and send Classical CAN frames. When configuring CAN FD capable CAN controllers an additional 'data' bitrate has to be set. This bitrate for the data phase of the CAN FD frame has to be at least the bitrate which was configured for the arbitration phase. This second bitrate is specified analogue to the first bitrate but the bitrate From patchwork Tue Nov 10 10:18:51 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oliver Hartkopp X-Patchwork-Id: 11893785 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id F04B5C388F7 for ; Tue, 10 Nov 2020 10:19:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 99458207BB for ; Tue, 10 Nov 2020 10:19:28 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=hartkopp.net header.i=@hartkopp.net header.b="pmCfNJEy" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731896AbgKJKT1 (ORCPT ); Tue, 10 Nov 2020 05:19:27 -0500 Received: from mo4-p02-ob.smtp.rzone.de ([85.215.255.84]:32990 "EHLO mo4-p02-ob.smtp.rzone.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731106AbgKJKTJ (ORCPT ); Tue, 10 Nov 2020 05:19:09 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1605003546; s=strato-dkim-0002; d=hartkopp.net; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: X-RZG-CLASS-ID:X-RZG-AUTH:From:Subject:Sender; bh=YvpqB0xJCuWRpBeC2un0LqxQx1LgqTTH8Kl4db4+eNc=; b=pmCfNJEySajdqWhZ5zlqC0k50I1X9aaXR0/z0c859GGV54FkH4MOVnqaFZ3gsc+Xpj VgnAqWXjtSv1IF86Jh9QGOlID+jvdurgeMoO8PYM/8htX5h6PPL9BqZmQkdG1KXcI0Fe 4USl+JlnVoLYfnxGlT7lLimOqRkpaNwBy+a6cEEnpzjxsZHgzsfDWpqsgjuf4iVyXJ9/ AUdUwzPp0eQnwpWGs9mXSiJtebx3IxpOEWLpOBgYg/S8tBL0VkLquJD+5Ct0TXnEDLK5 lwRvQR1ZRsLO/c9yg94NXQKRiPVi1WfdX2riVfBLdmH6aC/J3ljc/rrP4cIRWJnRita3 dQHw== X-RZG-AUTH: ":P2MHfkW8eP4Mre39l357AZT/I7AY/7nT2yrDxb8mjGrp7owjzFK3JbFk1mS0k+8CejudJywjsi+/Fw==" X-RZG-CLASS-ID: mo00 Received: from silver.lan by smtp.strato.de (RZmta 47.3.3 DYNA|AUTH) with ESMTPSA id V0298cwAAAJ4AQk (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256 bits)) (Client did not present a certificate); Tue, 10 Nov 2020 11:19:04 +0100 (CET) From: Oliver Hartkopp To: linux-can@vger.kernel.org, mkl@pengutronix.de, mailhol.vincent@wanadoo.fr Cc: netdev@vger.kernel.org, Oliver Hartkopp Subject: [PATCH v6 7/8] can-dev: introduce helpers to access Classical CAN DLC values Date: Tue, 10 Nov 2020 11:18:51 +0100 Message-Id: <20201110101852.1973-8-socketcan@hartkopp.net> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201110101852.1973-1-socketcan@hartkopp.net> References: <20201110101852.1973-1-socketcan@hartkopp.net> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org can_get_cc_dlc: get the data length code for Classical CAN raw DLC access can_get_cc_len: get len and len8_dlc value for Classical CAN raw DLC access Signed-off-by: Oliver Hartkopp --- include/linux/can/dev.h | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/include/linux/can/dev.h b/include/linux/can/dev.h index e767a96ae075..9a787f73399e 100644 --- a/include/linux/can/dev.h +++ b/include/linux/can/dev.h @@ -168,10 +168,38 @@ static inline bool can_is_canfd_skb(const struct sk_buff *skb) { /* the CAN specific type of skb is identified by its data length */ return skb->len == CANFD_MTU; } +/* helper to get the data length code (DLC) for Classical CAN raw DLC access */ +static inline u8 can_get_cc_dlc(const u32 ctrlmode, const struct can_frame *cf) +{ + /* return len8_dlc as dlc value only if all conditions apply */ + if ((ctrlmode & CAN_CTRLMODE_CC_LEN8_DLC) && + (cf->len == CAN_MAX_DLEN) && + (cf->len8_dlc > CAN_MAX_DLEN && cf->len8_dlc <= CAN_MAX_RAW_DLC)) + return cf->len8_dlc; + + /* return the payload length as dlc value */ + return cf->len; +} + +/* helper to get len and len8_dlc value for Classical CAN raw DLC access */ +static inline u8 can_get_cc_len(const u32 ctrlmode, struct can_frame *cf, + u8 dlc) +{ + /* the caller already ensured that dlc is a value from 0 .. 15 */ + if ((ctrlmode & CAN_CTRLMODE_CC_LEN8_DLC) && (dlc > CAN_MAX_DLEN)) + cf->len8_dlc = dlc; + + /* limit the payload length 'len' to CAN_MAX_DLEN */ + if (dlc > CAN_MAX_DLEN) + return CAN_MAX_DLEN; + + return dlc; +} + /* helper to define static CAN controller features at device creation time */ static inline void can_set_static_ctrlmode(struct net_device *dev, u32 static_mode) { struct can_priv *priv = netdev_priv(dev); From patchwork Tue Nov 10 10:18:52 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oliver Hartkopp X-Patchwork-Id: 11893759 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0ECADC4741F for ; Tue, 10 Nov 2020 10:19:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id AFBF0207D3 for ; Tue, 10 Nov 2020 10:19:15 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=hartkopp.net header.i=@hartkopp.net header.b="mDOIDUSN" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732008AbgKJKTO (ORCPT ); Tue, 10 Nov 2020 05:19:14 -0500 Received: from mo4-p02-ob.smtp.rzone.de ([81.169.146.171]:12399 "EHLO mo4-p02-ob.smtp.rzone.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731729AbgKJKTM (ORCPT ); Tue, 10 Nov 2020 05:19:12 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1605003546; s=strato-dkim-0002; d=hartkopp.net; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: X-RZG-CLASS-ID:X-RZG-AUTH:From:Subject:Sender; bh=+hbqq5QMUb3pkjLtHBdNPzPERlh5RJ9buD6zG+C1rOw=; b=mDOIDUSNOArNfpfdk10KepiAHqT/qqCscWv6wnJD8r/l9F7I+QVN3aNc/zfcocETaH bWTAGbYacsoVUAYOtyrDP30JZ7D29rC5rkKseXsI3XygUJdf7k6wuw0QJOUc7fG6v46s nEAr8WO7Wg0MrrxSMl5ztgtlRvVmDhIigm9EO1U18OLgsmQPMcTUHhZIvldjHIEf7il0 6BdxCT8fF6XzrKdzOsFiabn8TOE6dcPwCAPkhJhMpI70tfM9HTfA6nMTtqL5yuYgSqSt f5Vs3r//v79lqP4uUYVaj+NL8OHSZCh9i3+6qQmWtUf84I3E9NTS8vRvZ2nmiWQq90FB Hj+w== X-RZG-AUTH: ":P2MHfkW8eP4Mre39l357AZT/I7AY/7nT2yrDxb8mjGrp7owjzFK3JbFk1mS0k+8CejudJywjsi+/Fw==" X-RZG-CLASS-ID: mo00 Received: from silver.lan by smtp.strato.de (RZmta 47.3.3 DYNA|AUTH) with ESMTPSA id V0298cwAAAJ4AQm (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256 bits)) (Client did not present a certificate); Tue, 10 Nov 2020 11:19:04 +0100 (CET) From: Oliver Hartkopp To: linux-can@vger.kernel.org, mkl@pengutronix.de, mailhol.vincent@wanadoo.fr Cc: netdev@vger.kernel.org, Oliver Hartkopp Subject: [PATCH v6 8/8] can-dev: add len8_dlc support for various CAN USB adapters Date: Tue, 10 Nov 2020 11:18:52 +0100 Message-Id: <20201110101852.1973-9-socketcan@hartkopp.net> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201110101852.1973-1-socketcan@hartkopp.net> References: <20201110101852.1973-1-socketcan@hartkopp.net> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org Support the Classical CAN raw DLC functionality to send and receive DLC values from 9 .. 15 on various Classical CAN capable USB network drivers: - gs_usb - pcan_usb - pcan_usb_fd - usb_8dev Tested-by: Oliver Hartkopp Signed-off-by: Oliver Hartkopp --- drivers/net/can/usb/gs_usb.c | 7 ++++--- drivers/net/can/usb/peak_usb/pcan_usb.c | 8 +++++--- drivers/net/can/usb/peak_usb/pcan_usb_fd.c | 19 +++++++++++++------ drivers/net/can/usb/usb_8dev.c | 10 ++++++---- 4 files changed, 28 insertions(+), 16 deletions(-) diff --git a/drivers/net/can/usb/gs_usb.c b/drivers/net/can/usb/gs_usb.c index 940589667a7f..bd2c828030e9 100644 --- a/drivers/net/can/usb/gs_usb.c +++ b/drivers/net/can/usb/gs_usb.c @@ -329,11 +329,11 @@ static void gs_usb_receive_bulk_callback(struct urb *urb) if (!skb) return; cf->can_id = hf->can_id; - cf->len = can_cc_dlc2len(hf->len); + cf->len = can_get_cc_len(dev->can.ctrlmode, cf, hf->len); memcpy(cf->data, hf->data, 8); /* ERROR frames tell us information about the controller */ if (hf->can_id & CAN_ERR_FLAG) gs_update_state(dev, cf); @@ -502,11 +502,12 @@ static netdev_tx_t gs_can_start_xmit(struct sk_buff *skb, hf->channel = dev->channel; cf = (struct can_frame *)skb->data; hf->can_id = cf->can_id; - hf->len = cf->len; + hf->len = can_get_cc_dlc(dev->can.ctrlmode, cf); + memcpy(hf->data, cf->data, cf->len); usb_fill_bulk_urb(urb, dev->udev, usb_sndbulkpipe(dev->udev, GSUSB_ENDPOINT_OUT), hf, @@ -856,11 +857,11 @@ static struct gs_can *gs_make_candev(unsigned int channel, dev->can.state = CAN_STATE_STOPPED; dev->can.clock.freq = bt_const->fclk_can; dev->can.bittiming_const = &dev->bt_const; dev->can.do_set_bittiming = gs_usb_set_bittiming; - dev->can.ctrlmode_supported = 0; + dev->can.ctrlmode_supported = CAN_CTRLMODE_CC_LEN8_DLC; if (bt_const->feature & GS_CAN_FEATURE_LISTEN_ONLY) dev->can.ctrlmode_supported |= CAN_CTRLMODE_LISTENONLY; if (bt_const->feature & GS_CAN_FEATURE_LOOP_BACK) diff --git a/drivers/net/can/usb/peak_usb/pcan_usb.c b/drivers/net/can/usb/peak_usb/pcan_usb.c index ec34f87cc02c..a418e43ef59d 100644 --- a/drivers/net/can/usb/peak_usb/pcan_usb.c +++ b/drivers/net/can/usb/peak_usb/pcan_usb.c @@ -732,11 +732,11 @@ static int pcan_usb_decode_data(struct pcan_usb_msg_context *mc, u8 status_len) mc->ptr += 2; cf->can_id = le16_to_cpu(tmp16) >> 5; } - cf->len = can_cc_dlc2len(rec_len); + cf->len = can_get_cc_len(mc->pdev->dev.can.ctrlmode, cf, rec_len); /* Only first packet timestamp is a word */ if (pcan_usb_decode_ts(mc, !mc->rec_ts_idx)) goto decode_failed; @@ -836,11 +836,12 @@ static int pcan_usb_encode_msg(struct peak_usb_device *dev, struct sk_buff *skb, obuf[1] = 1; pc = obuf + PCAN_USB_MSG_HEADER_LEN; /* status/len byte */ - *pc = cf->len; + *pc = can_get_cc_dlc(dev->can.ctrlmode, cf); + if (cf->can_id & CAN_RTR_FLAG) *pc |= PCAN_USB_STATUSLEN_RTR; /* can id */ if (cf->can_id & CAN_EFF_FLAG) { @@ -990,11 +991,12 @@ static const struct can_bittiming_const pcan_usb_const = { const struct peak_usb_adapter pcan_usb = { .name = "PCAN-USB", .device_id = PCAN_USB_PRODUCT_ID, .ctrl_count = 1, .ctrlmode_supported = CAN_CTRLMODE_3_SAMPLES | CAN_CTRLMODE_LISTENONLY | - CAN_CTRLMODE_BERR_REPORTING, + CAN_CTRLMODE_BERR_REPORTING | + CAN_CTRLMODE_CC_LEN8_DLC, .clock = { .freq = PCAN_USB_CRYSTAL_HZ / 2 , }, .bittiming_const = &pcan_usb_const, diff --git a/drivers/net/can/usb/peak_usb/pcan_usb_fd.c b/drivers/net/can/usb/peak_usb/pcan_usb_fd.c index 761e78d8e647..93468106c97b 100644 --- a/drivers/net/can/usb/peak_usb/pcan_usb_fd.c +++ b/drivers/net/can/usb/peak_usb/pcan_usb_fd.c @@ -497,11 +497,13 @@ static int pcan_usb_fd_decode_canmsg(struct pcan_usb_fd_if *usb_if, /* CAN 2.0 frame case */ skb = alloc_can_skb(netdev, (struct can_frame **)&cfd); if (!skb) return -ENOMEM; - cfd->len = can_cc_dlc2len(pucan_msg_get_dlc(rm)); + cfd->len = can_get_cc_len(dev->can.ctrlmode, + (struct can_frame *)cfd, + pucan_msg_get_dlc(rm)); } cfd->can_id = le32_to_cpu(rm->can_id); if (rx_msg_flags & PUCAN_MSG_EXT_ID) @@ -765,11 +767,12 @@ static int pcan_usb_fd_encode_msg(struct peak_usb_device *dev, if (cfd->flags & CANFD_ESI) tx_msg_flags |= PUCAN_MSG_ERROR_STATE_IND; } else { /* CAND 2.0 frames */ - len = cfd->len; + len = can_get_cc_dlc(dev->can.ctrlmode, + (struct can_frame *)cfd); if (cfd->can_id & CAN_RTR_FLAG) tx_msg_flags |= PUCAN_MSG_RTR; } @@ -1034,11 +1037,12 @@ static const struct can_bittiming_const pcan_usb_fd_data_const = { const struct peak_usb_adapter pcan_usb_fd = { .name = "PCAN-USB FD", .device_id = PCAN_USBFD_PRODUCT_ID, .ctrl_count = PCAN_USBFD_CHANNEL_COUNT, .ctrlmode_supported = CAN_CTRLMODE_FD | - CAN_CTRLMODE_3_SAMPLES | CAN_CTRLMODE_LISTENONLY, + CAN_CTRLMODE_3_SAMPLES | CAN_CTRLMODE_LISTENONLY | + CAN_CTRLMODE_CC_LEN8_DLC, .clock = { .freq = PCAN_UFD_CRYSTAL_HZ, }, .bittiming_const = &pcan_usb_fd_const, .data_bittiming_const = &pcan_usb_fd_data_const, @@ -1106,11 +1110,12 @@ static const struct can_bittiming_const pcan_usb_chip_data_const = { const struct peak_usb_adapter pcan_usb_chip = { .name = "PCAN-Chip USB", .device_id = PCAN_USBCHIP_PRODUCT_ID, .ctrl_count = PCAN_USBFD_CHANNEL_COUNT, .ctrlmode_supported = CAN_CTRLMODE_FD | - CAN_CTRLMODE_3_SAMPLES | CAN_CTRLMODE_LISTENONLY, + CAN_CTRLMODE_3_SAMPLES | CAN_CTRLMODE_LISTENONLY | + CAN_CTRLMODE_CC_LEN8_DLC, .clock = { .freq = PCAN_UFD_CRYSTAL_HZ, }, .bittiming_const = &pcan_usb_chip_const, .data_bittiming_const = &pcan_usb_chip_data_const, @@ -1178,11 +1183,12 @@ static const struct can_bittiming_const pcan_usb_pro_fd_data_const = { const struct peak_usb_adapter pcan_usb_pro_fd = { .name = "PCAN-USB Pro FD", .device_id = PCAN_USBPROFD_PRODUCT_ID, .ctrl_count = PCAN_USBPROFD_CHANNEL_COUNT, .ctrlmode_supported = CAN_CTRLMODE_FD | - CAN_CTRLMODE_3_SAMPLES | CAN_CTRLMODE_LISTENONLY, + CAN_CTRLMODE_3_SAMPLES | CAN_CTRLMODE_LISTENONLY | + CAN_CTRLMODE_CC_LEN8_DLC, .clock = { .freq = PCAN_UFD_CRYSTAL_HZ, }, .bittiming_const = &pcan_usb_pro_fd_const, .data_bittiming_const = &pcan_usb_pro_fd_data_const, @@ -1250,11 +1256,12 @@ static const struct can_bittiming_const pcan_usb_x6_data_const = { const struct peak_usb_adapter pcan_usb_x6 = { .name = "PCAN-USB X6", .device_id = PCAN_USBX6_PRODUCT_ID, .ctrl_count = PCAN_USBPROFD_CHANNEL_COUNT, .ctrlmode_supported = CAN_CTRLMODE_FD | - CAN_CTRLMODE_3_SAMPLES | CAN_CTRLMODE_LISTENONLY, + CAN_CTRLMODE_3_SAMPLES | CAN_CTRLMODE_LISTENONLY | + CAN_CTRLMODE_CC_LEN8_DLC, .clock = { .freq = PCAN_UFD_CRYSTAL_HZ, }, .bittiming_const = &pcan_usb_x6_const, .data_bittiming_const = &pcan_usb_x6_data_const, diff --git a/drivers/net/can/usb/usb_8dev.c b/drivers/net/can/usb/usb_8dev.c index 6517aaeb4bc0..8078ab44a768 100644 --- a/drivers/net/can/usb/usb_8dev.c +++ b/drivers/net/can/usb/usb_8dev.c @@ -468,11 +468,12 @@ static void usb_8dev_rx_can_msg(struct usb_8dev_priv *priv, skb = alloc_can_skb(priv->netdev, &cf); if (!skb) return; cf->can_id = be32_to_cpu(msg->id); - cf->len = can_cc_dlc2len(msg->dlc & 0xF); + cf->len = can_get_cc_len(priv->can.ctrlmode, cf, + msg->dlc & 0xF); if (msg->flags & USB_8DEV_EXTID) cf->can_id |= CAN_EFF_FLAG; if (msg->flags & USB_8DEV_RTR) @@ -635,11 +636,11 @@ static netdev_tx_t usb_8dev_start_xmit(struct sk_buff *skb, if (cf->can_id & CAN_EFF_FLAG) msg->flags |= USB_8DEV_EXTID; msg->id = cpu_to_be32(cf->can_id & CAN_ERR_MASK); - msg->dlc = cf->len; + msg->dlc = can_get_cc_dlc(priv->can.ctrlmode, cf); memcpy(msg->data, cf->data, cf->len); msg->end = USB_8DEV_DATA_END; for (i = 0; i < MAX_TX_URBS; i++) { if (priv->tx_contexts[i].echo_index == MAX_TX_URBS) { @@ -925,12 +926,13 @@ static int usb_8dev_probe(struct usb_interface *intf, priv->can.clock.freq = USB_8DEV_ABP_CLOCK; priv->can.bittiming_const = &usb_8dev_bittiming_const; priv->can.do_set_mode = usb_8dev_set_mode; priv->can.do_get_berr_counter = usb_8dev_get_berr_counter; priv->can.ctrlmode_supported = CAN_CTRLMODE_LOOPBACK | - CAN_CTRLMODE_LISTENONLY | - CAN_CTRLMODE_ONE_SHOT; + CAN_CTRLMODE_LISTENONLY | + CAN_CTRLMODE_ONE_SHOT | + CAN_CTRLMODE_CC_LEN8_DLC; netdev->netdev_ops = &usb_8dev_netdev_ops; netdev->flags |= IFF_ECHO; /* we support local echo */