Commit 08eeccb2 authored by Jakub Kicinski's avatar Jakub Kicinski

Merge tag 'linux-can-next-for-6.5-20230622' of...

Merge tag 'linux-can-next-for-6.5-20230622' of git://git.kernel.org/pub/scm/linux/kernel/git/mkl/linux-can-next

Marc Kleine-Budde says:

====================
pull-request: can-next 2023-06-22

The first patch is by Carsten Schmidt, targets the kvaser_usb driver
and adds len8_dlc support.

Marcel Hellwig's patch for the xilinx_can driver adds support for CAN
transceivers via the PHY framework.

Frank Jungclaus contributes 6+2 patches for the esd_usb driver in
preparation for the upcoming CAN-USB/3 support.

The 2 patches by Miquel Raynal for the sja1000 driver work around
overruns stalls on the Renesas SoCs.

The next 3 patches are by me and fix the coding style in the
rx-offload helper and in the m_can and ti_hecc driver.

Vincent Mailhol contributes 3 patches to fix and update the
calculation of the length of CAN frames on the wire.

Oliver Hartkopp's patch moves the CAN_RAW_FILTER_MAX definition into
the correct header.

The remaining 14 patches are by Jimmy Assarsson, target the
kvaser_pciefd driver and bring various updates and improvements.

* tag 'linux-can-next-for-6.5-20230622' of git://git.kernel.org/pub/scm/linux/kernel/git/mkl/linux-can-next: (33 commits)
  can: kvaser_pciefd: Use TX FIFO size read from CAN controller
  can: kvaser_pciefd: Refactor code
  can: kvaser_pciefd: Add len8_dlc support
  can: kvaser_pciefd: Use FIELD_{GET,PREP} and GENMASK where appropriate
  can: kvaser_pciefd: Sort register definitions
  can: kvaser_pciefd: Change return type for kvaser_pciefd_{receive,transmit,set_tx}_irq()
  can: kvaser_pciefd: Rename device ID defines
  can: kvaser_pciefd: Sort includes in alphabetic order
  can: kvaser_pciefd: Remove SPI flash parameter read functionality
  can: uapi: move CAN_RAW_FILTER_MAX definition to raw.h
  can: kvaser_pciefd: Define unsigned constants with type suffix 'U'
  can: kvaser_pciefd: Set hardware timestamp on transmitted packets
  can: kvaser_pciefd: Add function to set skb hwtstamps
  can: kvaser_pciefd: Remove handler for unused KVASER_PCIEFD_PACK_TYPE_EFRAME_ACK
  can: kvaser_pciefd: Remove useless write to interrupt register
  can: length: refactor frame lengths definition to add size in bits
  can: length: fix bitstuffing count
  can: length: fix description of the RRS field
  can: m_can: fix coding style
  can: ti_hecc: fix coding style
  ...
====================

Link: https://lore.kernel.org/r/20230622082658.571150-1-mkl@pengutronix.deSigned-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parents 0ec92a8f 790ef390
......@@ -153,7 +153,6 @@ config CAN_JANZ_ICAN3
config CAN_KVASER_PCIEFD
depends on PCI
tristate "Kvaser PCIe FD cards"
select CRC32
help
This is a driver for the Kvaser PCI Express CAN FD family.
......
......@@ -78,18 +78,7 @@ unsigned int can_skb_get_frame_len(const struct sk_buff *skb)
else
len = cf->len;
if (can_is_canfd_skb(skb)) {
if (cf->can_id & CAN_EFF_FLAG)
len += CANFD_FRAME_OVERHEAD_EFF;
else
len += CANFD_FRAME_OVERHEAD_SFF;
} else {
if (cf->can_id & CAN_EFF_FLAG)
len += CAN_FRAME_OVERHEAD_EFF;
else
len += CAN_FRAME_OVERHEAD_SFF;
}
return len;
return can_frame_bytes(can_is_canfd_skb(skb), cf->can_id & CAN_EFF_FLAG,
false, len);
}
EXPORT_SYMBOL_GPL(can_skb_get_frame_len);
This diff is collapsed.
......@@ -387,6 +387,16 @@ static void sja1000_rx(struct net_device *dev)
netif_rx(skb);
}
static irqreturn_t sja1000_reset_interrupt(int irq, void *dev_id)
{
struct net_device *dev = (struct net_device *)dev_id;
netdev_dbg(dev, "performing a soft reset upon overrun\n");
sja1000_start(dev);
return IRQ_HANDLED;
}
static int sja1000_err(struct net_device *dev, uint8_t isrc, uint8_t status)
{
struct sja1000_priv *priv = netdev_priv(dev);
......@@ -397,6 +407,7 @@ static int sja1000_err(struct net_device *dev, uint8_t isrc, uint8_t status)
enum can_state rx_state, tx_state;
unsigned int rxerr, txerr;
uint8_t ecc, alc;
int ret = 0;
skb = alloc_can_err_skb(dev, &cf);
if (skb == NULL)
......@@ -413,6 +424,15 @@ static int sja1000_err(struct net_device *dev, uint8_t isrc, uint8_t status)
stats->rx_over_errors++;
stats->rx_errors++;
sja1000_write_cmdreg(priv, CMD_CDO); /* clear bit */
/* Some controllers needs additional handling upon overrun
* condition: the controller may sometimes be totally confused
* and refuse any new frame while its buffer is empty. The only
* way to re-sync the read vs. write buffer offsets is to
* stop any current handling and perform a reset.
*/
if (priv->flags & SJA1000_QUIRK_RESET_ON_OVERRUN)
ret = IRQ_WAKE_THREAD;
}
if (isrc & IRQ_EI) {
......@@ -492,7 +512,7 @@ static int sja1000_err(struct net_device *dev, uint8_t isrc, uint8_t status)
netif_rx(skb);
return 0;
return ret;
}
irqreturn_t sja1000_interrupt(int irq, void *dev_id)
......@@ -501,7 +521,8 @@ irqreturn_t sja1000_interrupt(int irq, void *dev_id)
struct sja1000_priv *priv = netdev_priv(dev);
struct net_device_stats *stats = &dev->stats;
uint8_t isrc, status;
int n = 0;
irqreturn_t ret = 0;
int n = 0, err;
if (priv->pre_irq)
priv->pre_irq(priv);
......@@ -546,19 +567,25 @@ irqreturn_t sja1000_interrupt(int irq, void *dev_id)
}
if (isrc & (IRQ_DOI | IRQ_EI | IRQ_BEI | IRQ_EPI | IRQ_ALI)) {
/* error interrupt */
if (sja1000_err(dev, isrc, status))
err = sja1000_err(dev, isrc, status);
if (err == IRQ_WAKE_THREAD)
ret = err;
if (err)
break;
}
n++;
}
out:
if (!ret)
ret = (n) ? IRQ_HANDLED : IRQ_NONE;
if (priv->post_irq)
priv->post_irq(priv);
if (n >= SJA1000_MAX_IRQ)
netdev_dbg(dev, "%d messages handled in ISR", n);
return (n) ? IRQ_HANDLED : IRQ_NONE;
return ret;
}
EXPORT_SYMBOL_GPL(sja1000_interrupt);
......@@ -577,8 +604,9 @@ static int sja1000_open(struct net_device *dev)
/* register interrupt handler, if not done by the device driver */
if (!(priv->flags & SJA1000_CUSTOM_IRQ_HANDLER)) {
err = request_irq(dev->irq, sja1000_interrupt, priv->irq_flags,
dev->name, (void *)dev);
err = request_threaded_irq(dev->irq, sja1000_interrupt,
sja1000_reset_interrupt,
priv->irq_flags, dev->name, (void *)dev);
if (err) {
close_candev(dev);
return -EAGAIN;
......
......@@ -147,6 +147,7 @@
*/
#define SJA1000_CUSTOM_IRQ_HANDLER BIT(0)
#define SJA1000_QUIRK_NO_CDR_REG BIT(1)
#define SJA1000_QUIRK_RESET_ON_OVERRUN BIT(2)
/*
* SJA1000 private data structure
......
......@@ -106,7 +106,7 @@ static void sp_technologic_init(struct sja1000_priv *priv, struct device_node *o
static void sp_rzn1_init(struct sja1000_priv *priv, struct device_node *of)
{
priv->flags = SJA1000_QUIRK_NO_CDR_REG;
priv->flags = SJA1000_QUIRK_NO_CDR_REG | SJA1000_QUIRK_RESET_ON_OVERRUN;
}
static void sp_populate(struct sja1000_priv *priv,
......@@ -277,6 +277,9 @@ static int sp_probe(struct platform_device *pdev)
priv->irq_flags = IRQF_SHARED;
}
if (priv->flags & SJA1000_QUIRK_RESET_ON_OVERRUN)
priv->irq_flags |= IRQF_ONESHOT;
dev->irq = irq;
priv->reg_base = addr;
......
This diff is collapsed.
......@@ -816,7 +816,7 @@ static int kvaser_usb_init_one(struct kvaser_usb *dev, int channel)
init_completion(&priv->stop_comp);
init_completion(&priv->flush_comp);
init_completion(&priv->get_busparams_comp);
priv->can.ctrlmode_supported = 0;
priv->can.ctrlmode_supported = CAN_CTRLMODE_CC_LEN8_DLC;
priv->dev = dev;
priv->netdev = netdev;
......
......@@ -1263,7 +1263,7 @@ 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->len = can_cc_dlc2len(cmd->rx_can.dlc);
can_frame_set_cc_len((struct can_frame *)cf, cmd->rx_can.dlc, priv->can.ctrlmode);
if (flags & KVASER_USB_HYDRA_CF_FLAG_REMOTE_FRAME) {
cf->can_id |= CAN_RTR_FLAG;
......@@ -1342,7 +1342,7 @@ static void kvaser_usb_hydra_rx_msg_ext(const struct kvaser_usb *dev,
if (flags & KVASER_USB_HYDRA_CF_FLAG_ESI)
cf->flags |= CANFD_ESI;
} else {
cf->len = can_cc_dlc2len(dlc);
can_frame_set_cc_len((struct can_frame *)cf, dlc, priv->can.ctrlmode);
}
if (flags & KVASER_USB_HYDRA_CF_FLAG_REMOTE_FRAME) {
......@@ -1442,7 +1442,7 @@ kvaser_usb_hydra_frame_to_cmd_ext(const struct kvaser_usb_net_priv *priv,
struct kvaser_usb *dev = priv->dev;
struct kvaser_cmd_ext *cmd;
struct canfd_frame *cf = (struct canfd_frame *)skb->data;
u8 dlc = can_fd_len2dlc(cf->len);
u8 dlc;
u8 nbr_of_bytes = cf->len;
u32 flags;
u32 id;
......@@ -1467,6 +1467,11 @@ kvaser_usb_hydra_frame_to_cmd_ext(const struct kvaser_usb_net_priv *priv,
cmd->len = cpu_to_le16(*cmd_len);
if (can_is_canfd_skb(skb))
dlc = can_fd_len2dlc(cf->len);
else
dlc = can_get_cc_dlc((struct can_frame *)cf, priv->can.ctrlmode);
cmd->tx_can.databytes = nbr_of_bytes;
cmd->tx_can.dlc = dlc;
......@@ -1542,7 +1547,7 @@ kvaser_usb_hydra_frame_to_cmd_std(const struct kvaser_usb_net_priv *priv,
id = cf->can_id & CAN_SFF_MASK;
}
cmd->tx_can.dlc = cf->len;
cmd->tx_can.dlc = can_get_cc_dlc(cf, priv->can.ctrlmode);
flags = (cf->can_id & CAN_EFF_FLAG ?
KVASER_USB_HYDRA_CF_FLAG_EXTENDED_ID : 0);
......
......@@ -573,7 +573,7 @@ kvaser_usb_leaf_frame_to_cmd(const struct kvaser_usb_net_priv *priv,
cmd->u.tx_can.data[1] = cf->can_id & 0x3f;
}
cmd->u.tx_can.data[5] = cf->len;
cmd->u.tx_can.data[5] = can_get_cc_dlc(cf, priv->can.ctrlmode);
memcpy(&cmd->u.tx_can.data[6], cf->data, cf->len);
if (cf->can_id & CAN_RTR_FLAG)
......@@ -1349,7 +1349,7 @@ static void kvaser_usb_leaf_rx_can_msg(const struct kvaser_usb *dev,
else
cf->can_id &= CAN_SFF_MASK;
cf->len = can_cc_dlc2len(cmd->u.leaf.log_message.dlc);
can_frame_set_cc_len(cf, cmd->u.leaf.log_message.dlc & 0xF, priv->can.ctrlmode);
if (cmd->u.leaf.log_message.flags & MSG_FLAG_REMOTE_FRAME)
cf->can_id |= CAN_RTR_FLAG;
......@@ -1367,7 +1367,7 @@ static void kvaser_usb_leaf_rx_can_msg(const struct kvaser_usb *dev,
cf->can_id |= CAN_EFF_FLAG;
}
cf->len = can_cc_dlc2len(rx_data[5]);
can_frame_set_cc_len(cf, rx_data[5] & 0xF, priv->can.ctrlmode);
if (cmd->u.rx_can_header.flag & MSG_FLAG_REMOTE_FRAME)
cf->can_id |= CAN_RTR_FLAG;
......
......@@ -28,6 +28,7 @@
#include <linux/types.h>
#include <linux/can/dev.h>
#include <linux/can/error.h>
#include <linux/phy/phy.h>
#include <linux/pm_runtime.h>
#define DRIVER_NAME "xilinx_can"
......@@ -198,6 +199,7 @@ struct xcan_devtype_data {
* @bus_clk: Pointer to struct clk
* @can_clk: Pointer to struct clk
* @devtype: Device type specific constants
* @transceiver: Optional pointer to associated CAN transceiver
*/
struct xcan_priv {
struct can_priv can;
......@@ -215,6 +217,7 @@ struct xcan_priv {
struct clk *bus_clk;
struct clk *can_clk;
struct xcan_devtype_data devtype;
struct phy *transceiver;
};
/* CAN Bittiming constants as per Xilinx CAN specs */
......@@ -1419,6 +1422,10 @@ static int xcan_open(struct net_device *ndev)
struct xcan_priv *priv = netdev_priv(ndev);
int ret;
ret = phy_power_on(priv->transceiver);
if (ret)
return ret;
ret = pm_runtime_get_sync(priv->dev);
if (ret < 0) {
netdev_err(ndev, "%s: pm_runtime_get failed(%d)\n",
......@@ -1462,6 +1469,7 @@ static int xcan_open(struct net_device *ndev)
free_irq(ndev->irq, ndev);
err:
pm_runtime_put(priv->dev);
phy_power_off(priv->transceiver);
return ret;
}
......@@ -1483,6 +1491,7 @@ static int xcan_close(struct net_device *ndev)
close_candev(ndev);
pm_runtime_put(priv->dev);
phy_power_off(priv->transceiver);
return 0;
}
......@@ -1713,6 +1722,7 @@ static int xcan_probe(struct platform_device *pdev)
{
struct net_device *ndev;
struct xcan_priv *priv;
struct phy *transceiver;
const struct of_device_id *of_id;
const struct xcan_devtype_data *devtype = &xcan_axi_data;
void __iomem *addr;
......@@ -1843,6 +1853,14 @@ static int xcan_probe(struct platform_device *pdev)
goto err_free;
}
transceiver = devm_phy_optional_get(&pdev->dev, NULL);
if (IS_ERR(transceiver)) {
ret = PTR_ERR(transceiver);
dev_err_probe(&pdev->dev, ret, "failed to get phy\n");
goto err_free;
}
priv->transceiver = transceiver;
priv->write_reg = xcan_write_reg_le;
priv->read_reg = xcan_read_reg_le;
......@@ -1869,6 +1887,7 @@ static int xcan_probe(struct platform_device *pdev)
goto err_disableclks;
}
of_can_transceiver(ndev);
pm_runtime_put(&pdev->dev);
if (priv->devtype.flags & XCAN_FLAG_CANFD_2) {
......
/* SPDX-License-Identifier: GPL-2.0 */
/* Copyright (C) 2020 Oliver Hartkopp <socketcan@hartkopp.net>
* Copyright (C) 2020 Marc Kleine-Budde <kernel@pengutronix.de>
* Copyright (C) 2020, 2023 Vincent Mailhol <mailhol.vincent@wanadoo.fr>
*/
#ifndef _CAN_LENGTH_H
#define _CAN_LENGTH_H
#include <linux/bits.h>
#include <linux/can.h>
#include <linux/can/netlink.h>
#include <linux/math.h>
/*
* Size of a Classical CAN Standard Frame
* Size of a Classical CAN Standard Frame header in bits
*
* Name of Field Bits
* ---------------------------------------------------------
* Start-of-frame 1
* Identifier 11
* Remote transmission request (RTR) 1
* Identifier extension bit (IDE) 1
* Reserved bit (r0) 1
* Data length code (DLC) 4
* Data field 0...64
* CRC 15
* CRC delimiter 1
* ACK slot 1
* ACK delimiter 1
* End-of-frame (EOF) 7
* Inter frame spacing 3
* Start Of Frame (SOF) 1
* Arbitration field:
* base ID 11
* Remote Transmission Request (RTR) 1
* Control field:
* IDentifier Extension bit (IDE) 1
* FD Format indicator (FDF) 1
* Data Length Code (DLC) 4
*
* rounded up and ignoring bitstuffing
* including all fields preceding the data field, ignoring bitstuffing
*/
#define CAN_FRAME_OVERHEAD_SFF DIV_ROUND_UP(47, 8)
#define CAN_FRAME_HEADER_SFF_BITS 19
/*
* Size of a Classical CAN Extended Frame
* Size of a Classical CAN Extended Frame header in bits
*
* Name of Field Bits
* ---------------------------------------------------------
* Start-of-frame 1
* Identifier A 11
* Substitute remote request (SRR) 1
* Identifier extension bit (IDE) 1
* Identifier B 18
* Remote transmission request (RTR) 1
* Reserved bits (r1, r0) 2
* Start Of Frame (SOF) 1
* Arbitration field:
* base ID 11
* Substitute Remote Request (SRR) 1
* IDentifier Extension bit (IDE) 1
* ID extension 18
* Remote Transmission Request (RTR) 1
* Control field:
* FD Format indicator (FDF) 1
* Reserved bit (r0) 1
* Data length code (DLC) 4
* Data field 0...64
* CRC 15
* CRC delimiter 1
* ACK slot 1
* ACK delimiter 1
* End-of-frame (EOF) 7
* Inter frame spacing 3
*
* rounded up and ignoring bitstuffing
* including all fields preceding the data field, ignoring bitstuffing
*/
#define CAN_FRAME_OVERHEAD_EFF DIV_ROUND_UP(67, 8)
#define CAN_FRAME_HEADER_EFF_BITS 39
/*
* Size of a CAN-FD Standard Frame
* Size of a CAN-FD Standard Frame in bits
*
* Name of Field Bits
* ---------------------------------------------------------
* Start-of-frame 1
* Identifier 11
* Reserved bit (r1) 1
* Identifier extension bit (IDE) 1
* Flexible data rate format (FDF) 1
* Reserved bit (r0) 1
* Start Of Frame (SOF) 1
* Arbitration field:
* base ID 11
* Remote Request Substitution (RRS) 1
* Control field:
* IDentifier Extension bit (IDE) 1
* FD Format indicator (FDF) 1
* Reserved bit (res) 1
* Bit Rate Switch (BRS) 1
* Error Status Indicator (ESI) 1
* Data length code (DLC) 4
* Data field 0...512
* Stuff Bit Count (SBC) 0...16: 4 20...64:5
* CRC 0...16: 17 20...64:21
* CRC delimiter (CD) 1
* ACK slot (AS) 1
* ACK delimiter (AD) 1
* End-of-frame (EOF) 7
* Inter frame spacing 3
*
* assuming CRC21, rounded up and ignoring bitstuffing
* including all fields preceding the data field, ignoring bitstuffing
*/
#define CANFD_FRAME_OVERHEAD_SFF DIV_ROUND_UP(61, 8)
#define CANFD_FRAME_HEADER_SFF_BITS 22
/*
* Size of a CAN-FD Extended Frame
* Size of a CAN-FD Extended Frame in bits
*
* Name of Field Bits
* ---------------------------------------------------------
* Start-of-frame 1
* Identifier A 11
* Substitute remote request (SRR) 1
* Identifier extension bit (IDE) 1
* Identifier B 18
* Reserved bit (r1) 1
* Flexible data rate format (FDF) 1
* Reserved bit (r0) 1
* Start Of Frame (SOF) 1
* Arbitration field:
* base ID 11
* Substitute Remote Request (SRR) 1
* IDentifier Extension bit (IDE) 1
* ID extension 18
* Remote Request Substitution (RRS) 1
* Control field:
* FD Format indicator (FDF) 1
* Reserved bit (res) 1
* Bit Rate Switch (BRS) 1
* Error Status Indicator (ESI) 1
* Data length code (DLC) 4
* Data field 0...512
* Stuff Bit Count (SBC) 0...16: 4 20...64:5
* CRC 0...16: 17 20...64:21
* CRC delimiter (CD) 1
* ACK slot (AS) 1
* ACK delimiter (AD) 1
* End-of-frame (EOF) 7
* Inter frame spacing 3
*
* assuming CRC21, rounded up and ignoring bitstuffing
* including all fields preceding the data field, ignoring bitstuffing
*/
#define CANFD_FRAME_HEADER_EFF_BITS 41
/*
* Size of a CAN CRC Field in bits
*
* Name of Field Bits
* ---------------------------------------------------------
* CRC sequence (CRC15) 15
* CRC Delimiter 1
*
* ignoring bitstuffing
*/
#define CAN_FRAME_CRC_FIELD_BITS 16
/*
* Size of a CAN-FD CRC17 Field in bits (length: 0..16)
*
* Name of Field Bits
* ---------------------------------------------------------
* Stuff Count 4
* CRC Sequence (CRC17) 17
* CRC Delimiter 1
* Fixed stuff bits 6
*/
#define CANFD_FRAME_CRC17_FIELD_BITS 28
/*
* Size of a CAN-FD CRC21 Field in bits (length: 20..64)
*
* Name of Field Bits
* ---------------------------------------------------------
* Stuff Count 4
* CRC sequence (CRC21) 21
* CRC Delimiter 1
* Fixed stuff bits 7
*/
#define CANFD_FRAME_CRC21_FIELD_BITS 33
/*
* Size of a CAN(-FD) Frame footer in bits
*
* Name of Field Bits
* ---------------------------------------------------------
* ACK slot 1
* ACK delimiter 1
* End Of Frame (EOF) 7
*
* including all fields following the CRC field
*/
#define CAN_FRAME_FOOTER_BITS 9
/*
* First part of the Inter Frame Space
* (a.k.a. IMF - intermission field)
*/
#define CAN_INTERMISSION_BITS 3
/**
* can_bitstuffing_len() - Calculate the maximum length with bitstuffing
* @destuffed_len: length of a destuffed bit stream
*
* The worst bit stuffing case is a sequence in which dominant and
* recessive bits alternate every four bits:
*
* Destuffed: 1 1111 0000 1111 0000 1111
* Stuffed: 1 1111o 0000i 1111o 0000i 1111o
*
* Nomenclature
*
* - "0": dominant bit
* - "o": dominant stuff bit
* - "1": recessive bit
* - "i": recessive stuff bit
*
* Aside from the first bit, one stuff bit is added every four bits.
*
* Return: length of the stuffed bit stream in the worst case scenario.
*/
#define can_bitstuffing_len(destuffed_len) \
(destuffed_len + (destuffed_len - 1) / 4)
#define __can_bitstuffing_len(bitstuffing, destuffed_len) \
(bitstuffing ? can_bitstuffing_len(destuffed_len) : \
destuffed_len)
#define __can_cc_frame_bits(is_eff, bitstuffing, \
intermission, data_len) \
( \
__can_bitstuffing_len(bitstuffing, \
(is_eff ? CAN_FRAME_HEADER_EFF_BITS : \
CAN_FRAME_HEADER_SFF_BITS) + \
(data_len) * BITS_PER_BYTE + \
CAN_FRAME_CRC_FIELD_BITS) + \
CAN_FRAME_FOOTER_BITS + \
(intermission ? CAN_INTERMISSION_BITS : 0) \
)
#define __can_fd_frame_bits(is_eff, bitstuffing, \
intermission, data_len) \
( \
__can_bitstuffing_len(bitstuffing, \
(is_eff ? CANFD_FRAME_HEADER_EFF_BITS : \
CANFD_FRAME_HEADER_SFF_BITS) + \
(data_len) * BITS_PER_BYTE) + \
((data_len) <= 16 ? \
CANFD_FRAME_CRC17_FIELD_BITS : \
CANFD_FRAME_CRC21_FIELD_BITS) + \
CAN_FRAME_FOOTER_BITS + \
(intermission ? CAN_INTERMISSION_BITS : 0) \
)
/**
* can_frame_bits() - Calculate the number of bits on the wire in a
* CAN frame
* @is_fd: true: CAN-FD frame; false: Classical CAN frame.
* @is_eff: true: Extended frame; false: Standard frame.
* @bitstuffing: true: calculate the bitstuffing worst case; false:
* calculate the bitstuffing best case (no dynamic
* bitstuffing). CAN-FD's fixed stuff bits are always included.
* @intermission: if and only if true, include the inter frame space
* assuming no bus idle (i.e. only the intermission). Strictly
* speaking, the inter frame space is not part of the
* frame. However, it is needed when calculating the delay
* between the Start Of Frame of two consecutive frames.
* @data_len: length of the data field in bytes. Correspond to
* can(fd)_frame->len. Should be zero for remote frames. No
* sanitization is done on @data_len and it shall have no side
* effects.
*
* Return: the numbers of bits on the wire of a CAN frame.
*/
#define can_frame_bits(is_fd, is_eff, bitstuffing, \
intermission, data_len) \
( \
is_fd ? __can_fd_frame_bits(is_eff, bitstuffing, \
intermission, data_len) : \
__can_cc_frame_bits(is_eff, bitstuffing, \
intermission, data_len) \
)
/*
* Number of bytes in a CAN frame
* (rounded up, including intermission)
*/
#define CANFD_FRAME_OVERHEAD_EFF DIV_ROUND_UP(80, 8)
#define can_frame_bytes(is_fd, is_eff, bitstuffing, data_len) \
DIV_ROUND_UP(can_frame_bits(is_fd, is_eff, bitstuffing, \
true, data_len), \
BITS_PER_BYTE)
/*
* Maximum size of a Classical CAN frame
* (rounded up and ignoring bitstuffing)
* (rounded up, ignoring bitstuffing but including intermission)
*/
#define CAN_FRAME_LEN_MAX (CAN_FRAME_OVERHEAD_EFF + CAN_MAX_DLEN)
#define CAN_FRAME_LEN_MAX can_frame_bytes(false, true, false, CAN_MAX_DLEN)
/*
* Maximum size of a CAN-FD frame
* (rounded up and ignoring bitstuffing)
* (rounded up, ignoring dynamic bitstuffing but including intermission)
*/
#define CANFD_FRAME_LEN_MAX (CANFD_FRAME_OVERHEAD_EFF + CANFD_MAX_DLEN)
#define CANFD_FRAME_LEN_MAX can_frame_bytes(true, true, false, CANFD_MAX_DLEN)
/*
* can_cc_dlc2len(value) - convert a given data length code (dlc) of a
......
......@@ -285,6 +285,5 @@ struct can_filter {
};
#define CAN_INV_FILTER 0x20000000U /* to be set in can_filter.can_id */
#define CAN_RAW_FILTER_MAX 512 /* maximum number of can_filter set via setsockopt() */
#endif /* !_UAPI_CAN_H */
......@@ -49,6 +49,8 @@
#include <linux/can.h>
#define SOL_CAN_RAW (SOL_CAN_BASE + CAN_RAW)
#define CAN_RAW_FILTER_MAX 512 /* maximum number of can_filter set via setsockopt() */
enum {
SCM_CAN_RAW_ERRQUEUE = 1,
};
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment