mirror of
https://github.com/torvalds/linux.git
synced 2026-05-25 23:52:08 +02:00
linux-can-next-for-6.5-20230622
-----BEGIN PGP SIGNATURE-----
iQFHBAABCgAxFiEEDs2BvajyNKlf9TJQvlAcSiqKBOgFAmSUAFUTHG1rbEBwZW5n
dXRyb25peC5kZQAKCRC+UBxKKooE6JwcB/4mlKQUkUSf+dHVCyI7DqML4Qb3zzUu
7+9x+cWx8rPGF0aEU2cMgbiRXIt+Eha5NdUkcOX43mBUT627rYLq1Wb0fYJ3hy6Z
hizCkUmZPjLR4gyTYIT8pEsnc1p5BO/LViFjdIgmMY+DPTb+m72w3kYzJG3UhvFc
FO263mUIR5pi5/Fvb4rq01RPBg9MsFOVpU+AhMOjMpFbE1MJki3u6EA5f3jYKcai
HKM21xd6I2eGpr8Tdd7EHEZCubZb74vCPUNUxAF3meXb1kQ52YngHBX94nseSGu8
ImHHvVSXHfF0hdz4+lI6HV6insg3Cs5W8oleViyVFzv1aQHw/AMusoyq
=qm4G
-----END PGP SIGNATURE-----
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.de
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
This commit is contained in:
commit
08eeccb249
|
|
@ -153,8 +153,7 @@ config CAN_JANZ_ICAN3
|
|||
config CAN_KVASER_PCIEFD
|
||||
depends on PCI
|
||||
tristate "Kvaser PCIe FD cards"
|
||||
select CRC32
|
||||
help
|
||||
help
|
||||
This is a driver for the Kvaser PCI Express CAN FD family.
|
||||
|
||||
Supported devices:
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -220,7 +220,7 @@ int can_rx_offload_irq_offload_fifo(struct can_rx_offload *offload)
|
|||
EXPORT_SYMBOL_GPL(can_rx_offload_irq_offload_fifo);
|
||||
|
||||
int can_rx_offload_queue_timestamp(struct can_rx_offload *offload,
|
||||
struct sk_buff *skb, u32 timestamp)
|
||||
struct sk_buff *skb, u32 timestamp)
|
||||
{
|
||||
struct can_rx_offload_cb *cb;
|
||||
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load Diff
|
|
@ -469,7 +469,7 @@ static void m_can_receive_skb(struct m_can_classdev *cdev,
|
|||
int err;
|
||||
|
||||
err = can_rx_offload_queue_timestamp(&cdev->offload, skb,
|
||||
timestamp);
|
||||
timestamp);
|
||||
if (err)
|
||||
stats->rx_fifo_errors++;
|
||||
} else {
|
||||
|
|
@ -895,7 +895,7 @@ static int m_can_handle_bus_errors(struct net_device *dev, u32 irqstatus,
|
|||
netdev_dbg(dev, "Arbitration phase error detected\n");
|
||||
work_done += m_can_handle_lec_err(dev, lec);
|
||||
}
|
||||
|
||||
|
||||
if (is_lec_err(dlec)) {
|
||||
netdev_dbg(dev, "Data phase error detected\n");
|
||||
work_done += m_can_handle_lec_err(dev, dlec);
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
||||
|
|
|
|||
|
|
@ -625,7 +625,7 @@ static int ti_hecc_error(struct net_device *ndev, int int_status,
|
|||
|
||||
timestamp = hecc_read(priv, HECC_CANLNT);
|
||||
err = can_rx_offload_queue_timestamp(&priv->offload, skb,
|
||||
timestamp);
|
||||
timestamp);
|
||||
if (err)
|
||||
ndev->stats.rx_fifo_errors++;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,18 +3,19 @@
|
|||
* CAN driver for esd electronics gmbh CAN-USB/2 and CAN-USB/Micro
|
||||
*
|
||||
* Copyright (C) 2010-2012 esd electronic system design gmbh, Matthias Fuchs <socketcan@esd.eu>
|
||||
* Copyright (C) 2022 esd electronics gmbh, Frank Jungclaus <frank.jungclaus@esd.eu>
|
||||
* Copyright (C) 2022-2023 esd electronics gmbh, Frank Jungclaus <frank.jungclaus@esd.eu>
|
||||
*/
|
||||
#include <linux/ethtool.h>
|
||||
#include <linux/signal.h>
|
||||
#include <linux/slab.h>
|
||||
#include <linux/module.h>
|
||||
#include <linux/netdevice.h>
|
||||
#include <linux/usb.h>
|
||||
|
||||
#include <linux/can.h>
|
||||
#include <linux/can/dev.h>
|
||||
#include <linux/can/error.h>
|
||||
#include <linux/ethtool.h>
|
||||
#include <linux/module.h>
|
||||
#include <linux/netdevice.h>
|
||||
#include <linux/signal.h>
|
||||
#include <linux/slab.h>
|
||||
#include <linux/units.h>
|
||||
#include <linux/usb.h>
|
||||
|
||||
MODULE_AUTHOR("Matthias Fuchs <socketcan@esd.eu>");
|
||||
MODULE_AUTHOR("Frank Jungclaus <frank.jungclaus@esd.eu>");
|
||||
|
|
@ -22,95 +23,87 @@ MODULE_DESCRIPTION("CAN driver for esd electronics gmbh CAN-USB/2 and CAN-USB/Mi
|
|||
MODULE_LICENSE("GPL v2");
|
||||
|
||||
/* USB vendor and product ID */
|
||||
#define USB_ESDGMBH_VENDOR_ID 0x0ab4
|
||||
#define USB_CANUSB2_PRODUCT_ID 0x0010
|
||||
#define USB_CANUSBM_PRODUCT_ID 0x0011
|
||||
#define ESD_USB_ESDGMBH_VENDOR_ID 0x0ab4
|
||||
#define ESD_USB_CANUSB2_PRODUCT_ID 0x0010
|
||||
#define ESD_USB_CANUSBM_PRODUCT_ID 0x0011
|
||||
|
||||
/* CAN controller clock frequencies */
|
||||
#define ESD_USB2_CAN_CLOCK 60000000
|
||||
#define ESD_USBM_CAN_CLOCK 36000000
|
||||
#define ESD_USB_2_CAN_CLOCK (60 * MEGA) /* Hz */
|
||||
#define ESD_USB_M_CAN_CLOCK (36 * MEGA) /* Hz */
|
||||
|
||||
/* Maximum number of CAN nets */
|
||||
#define ESD_USB_MAX_NETS 2
|
||||
|
||||
/* USB commands */
|
||||
#define CMD_VERSION 1 /* also used for VERSION_REPLY */
|
||||
#define CMD_CAN_RX 2 /* device to host only */
|
||||
#define CMD_CAN_TX 3 /* also used for TX_DONE */
|
||||
#define CMD_SETBAUD 4 /* also used for SETBAUD_REPLY */
|
||||
#define CMD_TS 5 /* also used for TS_REPLY */
|
||||
#define CMD_IDADD 6 /* also used for IDADD_REPLY */
|
||||
#define ESD_USB_CMD_VERSION 1 /* also used for VERSION_REPLY */
|
||||
#define ESD_USB_CMD_CAN_RX 2 /* device to host only */
|
||||
#define ESD_USB_CMD_CAN_TX 3 /* also used for TX_DONE */
|
||||
#define ESD_USB_CMD_SETBAUD 4 /* also used for SETBAUD_REPLY */
|
||||
#define ESD_USB_CMD_TS 5 /* also used for TS_REPLY */
|
||||
#define ESD_USB_CMD_IDADD 6 /* also used for IDADD_REPLY */
|
||||
|
||||
/* esd CAN message flags - dlc field */
|
||||
#define ESD_RTR 0x10
|
||||
#define ESD_USB_RTR BIT(4)
|
||||
|
||||
/* esd CAN message flags - id field */
|
||||
#define ESD_EXTID 0x20000000
|
||||
#define ESD_EVENT 0x40000000
|
||||
#define ESD_IDMASK 0x1fffffff
|
||||
#define ESD_USB_EXTID BIT(29)
|
||||
#define ESD_USB_EVENT BIT(30)
|
||||
#define ESD_USB_IDMASK GENMASK(28, 0)
|
||||
|
||||
/* esd CAN event ids */
|
||||
#define ESD_EV_CAN_ERROR_EXT 2 /* CAN controller specific diagnostic data */
|
||||
#define ESD_USB_EV_CAN_ERROR_EXT 2 /* CAN controller specific diagnostic data */
|
||||
|
||||
/* baudrate message flags */
|
||||
#define ESD_USB_UBR 0x80000000
|
||||
#define ESD_USB_LOM 0x40000000
|
||||
#define ESD_USB_NO_BAUDRATE 0x7fffffff
|
||||
#define ESD_USB_LOM BIT(30) /* Listen Only Mode */
|
||||
#define ESD_USB_UBR BIT(31) /* User Bit Rate (controller BTR) in bits 0..27 */
|
||||
#define ESD_USB_NO_BAUDRATE GENMASK(30, 0) /* bit rate unconfigured */
|
||||
|
||||
/* bit timing CAN-USB/2 */
|
||||
#define ESD_USB2_TSEG1_MIN 1
|
||||
#define ESD_USB2_TSEG1_MAX 16
|
||||
#define ESD_USB2_TSEG1_SHIFT 16
|
||||
#define ESD_USB2_TSEG2_MIN 1
|
||||
#define ESD_USB2_TSEG2_MAX 8
|
||||
#define ESD_USB2_TSEG2_SHIFT 20
|
||||
#define ESD_USB2_SJW_MAX 4
|
||||
#define ESD_USB2_SJW_SHIFT 14
|
||||
#define ESD_USBM_SJW_SHIFT 24
|
||||
#define ESD_USB2_BRP_MIN 1
|
||||
#define ESD_USB2_BRP_MAX 1024
|
||||
#define ESD_USB2_BRP_INC 1
|
||||
#define ESD_USB2_3_SAMPLES 0x00800000
|
||||
/* bit timing esd CAN-USB */
|
||||
#define ESD_USB_2_TSEG1_SHIFT 16
|
||||
#define ESD_USB_2_TSEG2_SHIFT 20
|
||||
#define ESD_USB_2_SJW_SHIFT 14
|
||||
#define ESD_USB_M_SJW_SHIFT 24
|
||||
#define ESD_USB_TRIPLE_SAMPLES BIT(23)
|
||||
|
||||
/* esd IDADD message */
|
||||
#define ESD_ID_ENABLE 0x80
|
||||
#define ESD_MAX_ID_SEGMENT 64
|
||||
#define ESD_USB_ID_ENABLE BIT(7)
|
||||
#define ESD_USB_MAX_ID_SEGMENT 64
|
||||
|
||||
/* SJA1000 ECC register (emulated by usb firmware) */
|
||||
#define SJA1000_ECC_SEG 0x1F
|
||||
#define SJA1000_ECC_DIR 0x20
|
||||
#define SJA1000_ECC_ERR 0x06
|
||||
#define SJA1000_ECC_BIT 0x00
|
||||
#define SJA1000_ECC_FORM 0x40
|
||||
#define SJA1000_ECC_STUFF 0x80
|
||||
#define SJA1000_ECC_MASK 0xc0
|
||||
#define ESD_USB_SJA1000_ECC_SEG GENMASK(4, 0)
|
||||
#define ESD_USB_SJA1000_ECC_DIR BIT(5)
|
||||
#define ESD_USB_SJA1000_ECC_ERR BIT(2, 1)
|
||||
#define ESD_USB_SJA1000_ECC_BIT 0x00
|
||||
#define ESD_USB_SJA1000_ECC_FORM BIT(6)
|
||||
#define ESD_USB_SJA1000_ECC_STUFF BIT(7)
|
||||
#define ESD_USB_SJA1000_ECC_MASK GENMASK(7, 6)
|
||||
|
||||
/* esd bus state event codes */
|
||||
#define ESD_BUSSTATE_MASK 0xc0
|
||||
#define ESD_BUSSTATE_WARN 0x40
|
||||
#define ESD_BUSSTATE_ERRPASSIVE 0x80
|
||||
#define ESD_BUSSTATE_BUSOFF 0xc0
|
||||
#define ESD_USB_BUSSTATE_MASK GENMASK(7, 6)
|
||||
#define ESD_USB_BUSSTATE_WARN BIT(6)
|
||||
#define ESD_USB_BUSSTATE_ERRPASSIVE BIT(7)
|
||||
#define ESD_USB_BUSSTATE_BUSOFF GENMASK(7, 6)
|
||||
|
||||
#define RX_BUFFER_SIZE 1024
|
||||
#define MAX_RX_URBS 4
|
||||
#define MAX_TX_URBS 16 /* must be power of 2 */
|
||||
#define ESD_USB_RX_BUFFER_SIZE 1024
|
||||
#define ESD_USB_MAX_RX_URBS 4
|
||||
#define ESD_USB_MAX_TX_URBS 16 /* must be power of 2 */
|
||||
|
||||
struct header_msg {
|
||||
u8 len; /* len is always the total message length in 32bit words */
|
||||
struct esd_usb_header_msg {
|
||||
u8 len; /* total message length in 32bit words */
|
||||
u8 cmd;
|
||||
u8 rsvd[2];
|
||||
};
|
||||
|
||||
struct version_msg {
|
||||
u8 len;
|
||||
struct esd_usb_version_msg {
|
||||
u8 len; /* total message length in 32bit words */
|
||||
u8 cmd;
|
||||
u8 rsvd;
|
||||
u8 flags;
|
||||
__le32 drv_version;
|
||||
};
|
||||
|
||||
struct version_reply_msg {
|
||||
u8 len;
|
||||
struct esd_usb_version_reply_msg {
|
||||
u8 len; /* total message length in 32bit words */
|
||||
u8 cmd;
|
||||
u8 nets;
|
||||
u8 features;
|
||||
|
|
@ -120,15 +113,15 @@ struct version_reply_msg {
|
|||
__le32 ts;
|
||||
};
|
||||
|
||||
struct rx_msg {
|
||||
u8 len;
|
||||
struct esd_usb_rx_msg {
|
||||
u8 len; /* total message length in 32bit words */
|
||||
u8 cmd;
|
||||
u8 net;
|
||||
u8 dlc;
|
||||
__le32 ts;
|
||||
__le32 id; /* upper 3 bits contain flags */
|
||||
union {
|
||||
u8 data[8];
|
||||
u8 data[CAN_MAX_DLEN];
|
||||
struct {
|
||||
u8 status; /* CAN Controller Status */
|
||||
u8 ecc; /* Error Capture Register */
|
||||
|
|
@ -138,18 +131,18 @@ struct rx_msg {
|
|||
};
|
||||
};
|
||||
|
||||
struct tx_msg {
|
||||
u8 len;
|
||||
struct esd_usb_tx_msg {
|
||||
u8 len; /* total message length in 32bit words */
|
||||
u8 cmd;
|
||||
u8 net;
|
||||
u8 dlc;
|
||||
u32 hnd; /* opaque handle, not used by device */
|
||||
__le32 id; /* upper 3 bits contain flags */
|
||||
u8 data[8];
|
||||
u8 data[CAN_MAX_DLEN];
|
||||
};
|
||||
|
||||
struct tx_done_msg {
|
||||
u8 len;
|
||||
struct esd_usb_tx_done_msg {
|
||||
u8 len; /* total message length in 32bit words */
|
||||
u8 cmd;
|
||||
u8 net;
|
||||
u8 status;
|
||||
|
|
@ -157,16 +150,16 @@ struct tx_done_msg {
|
|||
__le32 ts;
|
||||
};
|
||||
|
||||
struct id_filter_msg {
|
||||
u8 len;
|
||||
struct esd_usb_id_filter_msg {
|
||||
u8 len; /* total message length in 32bit words */
|
||||
u8 cmd;
|
||||
u8 net;
|
||||
u8 option;
|
||||
__le32 mask[ESD_MAX_ID_SEGMENT + 1];
|
||||
__le32 mask[ESD_USB_MAX_ID_SEGMENT + 1]; /* +1 for 29bit extended IDs */
|
||||
};
|
||||
|
||||
struct set_baudrate_msg {
|
||||
u8 len;
|
||||
struct esd_usb_set_baudrate_msg {
|
||||
u8 len; /* total message length in 32bit words */
|
||||
u8 cmd;
|
||||
u8 net;
|
||||
u8 rsvd;
|
||||
|
|
@ -175,19 +168,19 @@ struct set_baudrate_msg {
|
|||
|
||||
/* Main message type used between library and application */
|
||||
union __packed esd_usb_msg {
|
||||
struct header_msg hdr;
|
||||
struct version_msg version;
|
||||
struct version_reply_msg version_reply;
|
||||
struct rx_msg rx;
|
||||
struct tx_msg tx;
|
||||
struct tx_done_msg txdone;
|
||||
struct set_baudrate_msg setbaud;
|
||||
struct id_filter_msg filter;
|
||||
struct esd_usb_header_msg hdr;
|
||||
struct esd_usb_version_msg version;
|
||||
struct esd_usb_version_reply_msg version_reply;
|
||||
struct esd_usb_rx_msg rx;
|
||||
struct esd_usb_tx_msg tx;
|
||||
struct esd_usb_tx_done_msg txdone;
|
||||
struct esd_usb_set_baudrate_msg setbaud;
|
||||
struct esd_usb_id_filter_msg filter;
|
||||
};
|
||||
|
||||
static struct usb_device_id esd_usb_table[] = {
|
||||
{USB_DEVICE(USB_ESDGMBH_VENDOR_ID, USB_CANUSB2_PRODUCT_ID)},
|
||||
{USB_DEVICE(USB_ESDGMBH_VENDOR_ID, USB_CANUSBM_PRODUCT_ID)},
|
||||
{USB_DEVICE(ESD_USB_ESDGMBH_VENDOR_ID, ESD_USB_CANUSB2_PRODUCT_ID)},
|
||||
{USB_DEVICE(ESD_USB_ESDGMBH_VENDOR_ID, ESD_USB_CANUSBM_PRODUCT_ID)},
|
||||
{}
|
||||
};
|
||||
MODULE_DEVICE_TABLE(usb, esd_usb_table);
|
||||
|
|
@ -208,8 +201,8 @@ struct esd_usb {
|
|||
int net_count;
|
||||
u32 version;
|
||||
int rxinitdone;
|
||||
void *rxbuf[MAX_RX_URBS];
|
||||
dma_addr_t rxbuf_dma[MAX_RX_URBS];
|
||||
void *rxbuf[ESD_USB_MAX_RX_URBS];
|
||||
dma_addr_t rxbuf_dma[ESD_USB_MAX_RX_URBS];
|
||||
};
|
||||
|
||||
struct esd_usb_net_priv {
|
||||
|
|
@ -217,7 +210,7 @@ struct esd_usb_net_priv {
|
|||
|
||||
atomic_t active_tx_jobs;
|
||||
struct usb_anchor tx_submitted;
|
||||
struct esd_tx_urb_context tx_contexts[MAX_TX_URBS];
|
||||
struct esd_tx_urb_context tx_contexts[ESD_USB_MAX_TX_URBS];
|
||||
|
||||
struct esd_usb *usb;
|
||||
struct net_device *netdev;
|
||||
|
|
@ -232,9 +225,9 @@ static void esd_usb_rx_event(struct esd_usb_net_priv *priv,
|
|||
struct net_device_stats *stats = &priv->netdev->stats;
|
||||
struct can_frame *cf;
|
||||
struct sk_buff *skb;
|
||||
u32 id = le32_to_cpu(msg->rx.id) & ESD_IDMASK;
|
||||
u32 id = le32_to_cpu(msg->rx.id) & ESD_USB_IDMASK;
|
||||
|
||||
if (id == ESD_EV_CAN_ERROR_EXT) {
|
||||
if (id == ESD_USB_EV_CAN_ERROR_EXT) {
|
||||
u8 state = msg->rx.ev_can_err_ext.status;
|
||||
u8 ecc = msg->rx.ev_can_err_ext.ecc;
|
||||
|
||||
|
|
@ -261,15 +254,15 @@ static void esd_usb_rx_event(struct esd_usb_net_priv *priv,
|
|||
|
||||
priv->old_state = state;
|
||||
|
||||
switch (state & ESD_BUSSTATE_MASK) {
|
||||
case ESD_BUSSTATE_BUSOFF:
|
||||
switch (state & ESD_USB_BUSSTATE_MASK) {
|
||||
case ESD_USB_BUSSTATE_BUSOFF:
|
||||
new_state = CAN_STATE_BUS_OFF;
|
||||
can_bus_off(priv->netdev);
|
||||
break;
|
||||
case ESD_BUSSTATE_WARN:
|
||||
case ESD_USB_BUSSTATE_WARN:
|
||||
new_state = CAN_STATE_ERROR_WARNING;
|
||||
break;
|
||||
case ESD_BUSSTATE_ERRPASSIVE:
|
||||
case ESD_USB_BUSSTATE_ERRPASSIVE:
|
||||
new_state = CAN_STATE_ERROR_PASSIVE;
|
||||
break;
|
||||
default:
|
||||
|
|
@ -291,14 +284,14 @@ static void esd_usb_rx_event(struct esd_usb_net_priv *priv,
|
|||
|
||||
cf->can_id |= CAN_ERR_PROT | CAN_ERR_BUSERROR;
|
||||
|
||||
switch (ecc & SJA1000_ECC_MASK) {
|
||||
case SJA1000_ECC_BIT:
|
||||
switch (ecc & ESD_USB_SJA1000_ECC_MASK) {
|
||||
case ESD_USB_SJA1000_ECC_BIT:
|
||||
cf->data[2] |= CAN_ERR_PROT_BIT;
|
||||
break;
|
||||
case SJA1000_ECC_FORM:
|
||||
case ESD_USB_SJA1000_ECC_FORM:
|
||||
cf->data[2] |= CAN_ERR_PROT_FORM;
|
||||
break;
|
||||
case SJA1000_ECC_STUFF:
|
||||
case ESD_USB_SJA1000_ECC_STUFF:
|
||||
cf->data[2] |= CAN_ERR_PROT_STUFF;
|
||||
break;
|
||||
default:
|
||||
|
|
@ -306,11 +299,11 @@ static void esd_usb_rx_event(struct esd_usb_net_priv *priv,
|
|||
}
|
||||
|
||||
/* Error occurred during transmission? */
|
||||
if (!(ecc & SJA1000_ECC_DIR))
|
||||
if (!(ecc & ESD_USB_SJA1000_ECC_DIR))
|
||||
cf->data[2] |= CAN_ERR_PROT_TX;
|
||||
|
||||
/* Bit stream position in CAN frame as the error was detected */
|
||||
cf->data[3] = ecc & SJA1000_ECC_SEG;
|
||||
cf->data[3] = ecc & ESD_USB_SJA1000_ECC_SEG;
|
||||
}
|
||||
|
||||
if (skb) {
|
||||
|
|
@ -337,7 +330,7 @@ static void esd_usb_rx_can_msg(struct esd_usb_net_priv *priv,
|
|||
|
||||
id = le32_to_cpu(msg->rx.id);
|
||||
|
||||
if (id & ESD_EVENT) {
|
||||
if (id & ESD_USB_EVENT) {
|
||||
esd_usb_rx_event(priv, msg);
|
||||
} else {
|
||||
skb = alloc_can_skb(priv->netdev, &cf);
|
||||
|
|
@ -346,14 +339,14 @@ static void esd_usb_rx_can_msg(struct esd_usb_net_priv *priv,
|
|||
return;
|
||||
}
|
||||
|
||||
cf->can_id = id & ESD_IDMASK;
|
||||
can_frame_set_cc_len(cf, msg->rx.dlc & ~ESD_RTR,
|
||||
cf->can_id = id & ESD_USB_IDMASK;
|
||||
can_frame_set_cc_len(cf, msg->rx.dlc & ~ESD_USB_RTR,
|
||||
priv->can.ctrlmode);
|
||||
|
||||
if (id & ESD_EXTID)
|
||||
if (id & ESD_USB_EXTID)
|
||||
cf->can_id |= CAN_EFF_FLAG;
|
||||
|
||||
if (msg->rx.dlc & ESD_RTR) {
|
||||
if (msg->rx.dlc & ESD_USB_RTR) {
|
||||
cf->can_id |= CAN_RTR_FLAG;
|
||||
} else {
|
||||
for (i = 0; i < cf->len; i++)
|
||||
|
|
@ -377,7 +370,7 @@ static void esd_usb_tx_done_msg(struct esd_usb_net_priv *priv,
|
|||
if (!netif_device_present(netdev))
|
||||
return;
|
||||
|
||||
context = &priv->tx_contexts[msg->txdone.hnd & (MAX_TX_URBS - 1)];
|
||||
context = &priv->tx_contexts[msg->txdone.hnd & (ESD_USB_MAX_TX_URBS - 1)];
|
||||
|
||||
if (!msg->txdone.status) {
|
||||
stats->tx_packets++;
|
||||
|
|
@ -389,7 +382,7 @@ static void esd_usb_tx_done_msg(struct esd_usb_net_priv *priv,
|
|||
}
|
||||
|
||||
/* Release context */
|
||||
context->echo_index = MAX_TX_URBS;
|
||||
context->echo_index = ESD_USB_MAX_TX_URBS;
|
||||
atomic_dec(&priv->active_tx_jobs);
|
||||
|
||||
netif_wake_queue(netdev);
|
||||
|
|
@ -424,7 +417,7 @@ static void esd_usb_read_bulk_callback(struct urb *urb)
|
|||
msg = (union esd_usb_msg *)(urb->transfer_buffer + pos);
|
||||
|
||||
switch (msg->hdr.cmd) {
|
||||
case CMD_CAN_RX:
|
||||
case ESD_USB_CMD_CAN_RX:
|
||||
if (msg->rx.net >= dev->net_count) {
|
||||
dev_err(dev->udev->dev.parent, "format error\n");
|
||||
break;
|
||||
|
|
@ -433,7 +426,7 @@ static void esd_usb_read_bulk_callback(struct urb *urb)
|
|||
esd_usb_rx_can_msg(dev->nets[msg->rx.net], msg);
|
||||
break;
|
||||
|
||||
case CMD_CAN_TX:
|
||||
case ESD_USB_CMD_CAN_TX:
|
||||
if (msg->txdone.net >= dev->net_count) {
|
||||
dev_err(dev->udev->dev.parent, "format error\n");
|
||||
break;
|
||||
|
|
@ -444,7 +437,7 @@ static void esd_usb_read_bulk_callback(struct urb *urb)
|
|||
break;
|
||||
}
|
||||
|
||||
pos += msg->hdr.len << 2;
|
||||
pos += msg->hdr.len * sizeof(u32); /* convert to # of bytes */
|
||||
|
||||
if (pos > urb->actual_length) {
|
||||
dev_err(dev->udev->dev.parent, "format error\n");
|
||||
|
|
@ -454,7 +447,7 @@ static void esd_usb_read_bulk_callback(struct urb *urb)
|
|||
|
||||
resubmit_urb:
|
||||
usb_fill_bulk_urb(urb, dev->udev, usb_rcvbulkpipe(dev->udev, 1),
|
||||
urb->transfer_buffer, RX_BUFFER_SIZE,
|
||||
urb->transfer_buffer, ESD_USB_RX_BUFFER_SIZE,
|
||||
esd_usb_read_bulk_callback, dev);
|
||||
|
||||
retval = usb_submit_urb(urb, GFP_ATOMIC);
|
||||
|
|
@ -538,7 +531,7 @@ static int esd_usb_send_msg(struct esd_usb *dev, union esd_usb_msg *msg)
|
|||
return usb_bulk_msg(dev->udev,
|
||||
usb_sndbulkpipe(dev->udev, 2),
|
||||
msg,
|
||||
msg->hdr.len << 2,
|
||||
msg->hdr.len * sizeof(u32), /* convert to # of bytes */
|
||||
&actual_length,
|
||||
1000);
|
||||
}
|
||||
|
|
@ -563,7 +556,7 @@ static int esd_usb_setup_rx_urbs(struct esd_usb *dev)
|
|||
if (dev->rxinitdone)
|
||||
return 0;
|
||||
|
||||
for (i = 0; i < MAX_RX_URBS; i++) {
|
||||
for (i = 0; i < ESD_USB_MAX_RX_URBS; i++) {
|
||||
struct urb *urb = NULL;
|
||||
u8 *buf = NULL;
|
||||
dma_addr_t buf_dma;
|
||||
|
|
@ -575,7 +568,7 @@ static int esd_usb_setup_rx_urbs(struct esd_usb *dev)
|
|||
break;
|
||||
}
|
||||
|
||||
buf = usb_alloc_coherent(dev->udev, RX_BUFFER_SIZE, GFP_KERNEL,
|
||||
buf = usb_alloc_coherent(dev->udev, ESD_USB_RX_BUFFER_SIZE, GFP_KERNEL,
|
||||
&buf_dma);
|
||||
if (!buf) {
|
||||
dev_warn(dev->udev->dev.parent,
|
||||
|
|
@ -588,7 +581,7 @@ static int esd_usb_setup_rx_urbs(struct esd_usb *dev)
|
|||
|
||||
usb_fill_bulk_urb(urb, dev->udev,
|
||||
usb_rcvbulkpipe(dev->udev, 1),
|
||||
buf, RX_BUFFER_SIZE,
|
||||
buf, ESD_USB_RX_BUFFER_SIZE,
|
||||
esd_usb_read_bulk_callback, dev);
|
||||
urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
|
||||
usb_anchor_urb(urb, &dev->rx_submitted);
|
||||
|
|
@ -596,7 +589,7 @@ static int esd_usb_setup_rx_urbs(struct esd_usb *dev)
|
|||
err = usb_submit_urb(urb, GFP_KERNEL);
|
||||
if (err) {
|
||||
usb_unanchor_urb(urb);
|
||||
usb_free_coherent(dev->udev, RX_BUFFER_SIZE, buf,
|
||||
usb_free_coherent(dev->udev, ESD_USB_RX_BUFFER_SIZE, buf,
|
||||
urb->transfer_dma);
|
||||
goto freeurb;
|
||||
}
|
||||
|
|
@ -618,7 +611,7 @@ static int esd_usb_setup_rx_urbs(struct esd_usb *dev)
|
|||
}
|
||||
|
||||
/* Warn if we've couldn't transmit all the URBs */
|
||||
if (i < MAX_RX_URBS) {
|
||||
if (i < ESD_USB_MAX_RX_URBS) {
|
||||
dev_warn(dev->udev->dev.parent,
|
||||
"rx performance may be slow\n");
|
||||
}
|
||||
|
|
@ -653,14 +646,14 @@ static int esd_usb_start(struct esd_usb_net_priv *priv)
|
|||
* the number of the starting bitmask (0..64) to the filter.option
|
||||
* field followed by only some bitmasks.
|
||||
*/
|
||||
msg->hdr.cmd = CMD_IDADD;
|
||||
msg->hdr.len = 2 + ESD_MAX_ID_SEGMENT;
|
||||
msg->hdr.cmd = ESD_USB_CMD_IDADD;
|
||||
msg->hdr.len = sizeof(struct esd_usb_id_filter_msg) / sizeof(u32); /* # of 32bit words */
|
||||
msg->filter.net = priv->index;
|
||||
msg->filter.option = ESD_ID_ENABLE; /* start with segment 0 */
|
||||
for (i = 0; i < ESD_MAX_ID_SEGMENT; i++)
|
||||
msg->filter.mask[i] = cpu_to_le32(0xffffffff);
|
||||
msg->filter.option = ESD_USB_ID_ENABLE; /* start with segment 0 */
|
||||
for (i = 0; i < ESD_USB_MAX_ID_SEGMENT; i++)
|
||||
msg->filter.mask[i] = cpu_to_le32(GENMASK(31, 0));
|
||||
/* enable 29bit extended IDs */
|
||||
msg->filter.mask[ESD_MAX_ID_SEGMENT] = cpu_to_le32(0x00000001);
|
||||
msg->filter.mask[ESD_USB_MAX_ID_SEGMENT] = cpu_to_le32(BIT(0));
|
||||
|
||||
err = esd_usb_send_msg(dev, msg);
|
||||
if (err)
|
||||
|
|
@ -689,8 +682,8 @@ static void unlink_all_urbs(struct esd_usb *dev)
|
|||
|
||||
usb_kill_anchored_urbs(&dev->rx_submitted);
|
||||
|
||||
for (i = 0; i < MAX_RX_URBS; ++i)
|
||||
usb_free_coherent(dev->udev, RX_BUFFER_SIZE,
|
||||
for (i = 0; i < ESD_USB_MAX_RX_URBS; ++i)
|
||||
usb_free_coherent(dev->udev, ESD_USB_RX_BUFFER_SIZE,
|
||||
dev->rxbuf[i], dev->rxbuf_dma[i]);
|
||||
|
||||
for (i = 0; i < dev->net_count; i++) {
|
||||
|
|
@ -699,8 +692,8 @@ static void unlink_all_urbs(struct esd_usb *dev)
|
|||
usb_kill_anchored_urbs(&priv->tx_submitted);
|
||||
atomic_set(&priv->active_tx_jobs, 0);
|
||||
|
||||
for (j = 0; j < MAX_TX_URBS; j++)
|
||||
priv->tx_contexts[j].echo_index = MAX_TX_URBS;
|
||||
for (j = 0; j < ESD_USB_MAX_TX_URBS; j++)
|
||||
priv->tx_contexts[j].echo_index = ESD_USB_MAX_TX_URBS;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -765,25 +758,27 @@ static netdev_tx_t esd_usb_start_xmit(struct sk_buff *skb,
|
|||
|
||||
msg = (union esd_usb_msg *)buf;
|
||||
|
||||
msg->hdr.len = 3; /* minimal length */
|
||||
msg->hdr.cmd = CMD_CAN_TX;
|
||||
/* minimal length as # of 32bit words */
|
||||
msg->hdr.len = offsetof(struct esd_usb_tx_msg, data) / sizeof(u32);
|
||||
msg->hdr.cmd = ESD_USB_CMD_CAN_TX;
|
||||
msg->tx.net = priv->index;
|
||||
msg->tx.dlc = can_get_cc_dlc(cf, priv->can.ctrlmode);
|
||||
msg->tx.id = cpu_to_le32(cf->can_id & CAN_ERR_MASK);
|
||||
|
||||
if (cf->can_id & CAN_RTR_FLAG)
|
||||
msg->tx.dlc |= ESD_RTR;
|
||||
msg->tx.dlc |= ESD_USB_RTR;
|
||||
|
||||
if (cf->can_id & CAN_EFF_FLAG)
|
||||
msg->tx.id |= cpu_to_le32(ESD_EXTID);
|
||||
msg->tx.id |= cpu_to_le32(ESD_USB_EXTID);
|
||||
|
||||
for (i = 0; i < cf->len; i++)
|
||||
msg->tx.data[i] = cf->data[i];
|
||||
|
||||
msg->hdr.len += (cf->len + 3) >> 2;
|
||||
/* round up, then divide by 4 to add the payload length as # of 32bit words */
|
||||
msg->hdr.len += DIV_ROUND_UP(cf->len, sizeof(u32));
|
||||
|
||||
for (i = 0; i < MAX_TX_URBS; i++) {
|
||||
if (priv->tx_contexts[i].echo_index == MAX_TX_URBS) {
|
||||
for (i = 0; i < ESD_USB_MAX_TX_URBS; i++) {
|
||||
if (priv->tx_contexts[i].echo_index == ESD_USB_MAX_TX_URBS) {
|
||||
context = &priv->tx_contexts[i];
|
||||
break;
|
||||
}
|
||||
|
|
@ -800,10 +795,10 @@ static netdev_tx_t esd_usb_start_xmit(struct sk_buff *skb,
|
|||
context->echo_index = i;
|
||||
|
||||
/* hnd must not be 0 - MSB is stripped in txdone handling */
|
||||
msg->tx.hnd = 0x80000000 | i; /* returned in TX done message */
|
||||
msg->tx.hnd = BIT(31) | i; /* returned in TX done message */
|
||||
|
||||
usb_fill_bulk_urb(urb, dev->udev, usb_sndbulkpipe(dev->udev, 2), buf,
|
||||
msg->hdr.len << 2,
|
||||
msg->hdr.len * sizeof(u32), /* convert to # of bytes */
|
||||
esd_usb_write_bulk_callback, context);
|
||||
|
||||
urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
|
||||
|
|
@ -815,7 +810,7 @@ static netdev_tx_t esd_usb_start_xmit(struct sk_buff *skb,
|
|||
atomic_inc(&priv->active_tx_jobs);
|
||||
|
||||
/* Slow down tx path */
|
||||
if (atomic_read(&priv->active_tx_jobs) >= MAX_TX_URBS)
|
||||
if (atomic_read(&priv->active_tx_jobs) >= ESD_USB_MAX_TX_URBS)
|
||||
netif_stop_queue(netdev);
|
||||
|
||||
err = usb_submit_urb(urb, GFP_ATOMIC);
|
||||
|
|
@ -865,18 +860,18 @@ static int esd_usb_close(struct net_device *netdev)
|
|||
return -ENOMEM;
|
||||
|
||||
/* Disable all IDs (see esd_usb_start()) */
|
||||
msg->hdr.cmd = CMD_IDADD;
|
||||
msg->hdr.len = 2 + ESD_MAX_ID_SEGMENT;
|
||||
msg->hdr.cmd = ESD_USB_CMD_IDADD;
|
||||
msg->hdr.len = sizeof(struct esd_usb_id_filter_msg) / sizeof(u32);/* # of 32bit words */
|
||||
msg->filter.net = priv->index;
|
||||
msg->filter.option = ESD_ID_ENABLE; /* start with segment 0 */
|
||||
for (i = 0; i <= ESD_MAX_ID_SEGMENT; i++)
|
||||
msg->filter.option = ESD_USB_ID_ENABLE; /* start with segment 0 */
|
||||
for (i = 0; i <= ESD_USB_MAX_ID_SEGMENT; i++)
|
||||
msg->filter.mask[i] = 0;
|
||||
if (esd_usb_send_msg(priv->usb, msg) < 0)
|
||||
netdev_err(netdev, "sending idadd message failed\n");
|
||||
|
||||
/* set CAN controller to reset mode */
|
||||
msg->hdr.len = 2;
|
||||
msg->hdr.cmd = CMD_SETBAUD;
|
||||
msg->hdr.len = sizeof(struct esd_usb_set_baudrate_msg) / sizeof(u32); /* # of 32bit words */
|
||||
msg->hdr.cmd = ESD_USB_CMD_SETBAUD;
|
||||
msg->setbaud.net = priv->index;
|
||||
msg->setbaud.rsvd = 0;
|
||||
msg->setbaud.baud = cpu_to_le32(ESD_USB_NO_BAUDRATE);
|
||||
|
|
@ -905,20 +900,21 @@ static const struct ethtool_ops esd_usb_ethtool_ops = {
|
|||
.get_ts_info = ethtool_op_get_ts_info,
|
||||
};
|
||||
|
||||
static const struct can_bittiming_const esd_usb2_bittiming_const = {
|
||||
.name = "esd_usb2",
|
||||
.tseg1_min = ESD_USB2_TSEG1_MIN,
|
||||
.tseg1_max = ESD_USB2_TSEG1_MAX,
|
||||
.tseg2_min = ESD_USB2_TSEG2_MIN,
|
||||
.tseg2_max = ESD_USB2_TSEG2_MAX,
|
||||
.sjw_max = ESD_USB2_SJW_MAX,
|
||||
.brp_min = ESD_USB2_BRP_MIN,
|
||||
.brp_max = ESD_USB2_BRP_MAX,
|
||||
.brp_inc = ESD_USB2_BRP_INC,
|
||||
static const struct can_bittiming_const esd_usb_2_bittiming_const = {
|
||||
.name = "esd_usb_2",
|
||||
.tseg1_min = 1,
|
||||
.tseg1_max = 16,
|
||||
.tseg2_min = 1,
|
||||
.tseg2_max = 8,
|
||||
.sjw_max = 4,
|
||||
.brp_min = 1,
|
||||
.brp_max = 1024,
|
||||
.brp_inc = 1,
|
||||
};
|
||||
|
||||
static int esd_usb2_set_bittiming(struct net_device *netdev)
|
||||
static int esd_usb_2_set_bittiming(struct net_device *netdev)
|
||||
{
|
||||
const struct can_bittiming_const *btc = &esd_usb_2_bittiming_const;
|
||||
struct esd_usb_net_priv *priv = netdev_priv(netdev);
|
||||
struct can_bittiming *bt = &priv->can.bittiming;
|
||||
union esd_usb_msg *msg;
|
||||
|
|
@ -930,35 +926,35 @@ static int esd_usb2_set_bittiming(struct net_device *netdev)
|
|||
if (priv->can.ctrlmode & CAN_CTRLMODE_LISTENONLY)
|
||||
canbtr |= ESD_USB_LOM;
|
||||
|
||||
canbtr |= (bt->brp - 1) & (ESD_USB2_BRP_MAX - 1);
|
||||
canbtr |= (bt->brp - 1) & (btc->brp_max - 1);
|
||||
|
||||
if (le16_to_cpu(priv->usb->udev->descriptor.idProduct) ==
|
||||
USB_CANUSBM_PRODUCT_ID)
|
||||
sjw_shift = ESD_USBM_SJW_SHIFT;
|
||||
ESD_USB_CANUSBM_PRODUCT_ID)
|
||||
sjw_shift = ESD_USB_M_SJW_SHIFT;
|
||||
else
|
||||
sjw_shift = ESD_USB2_SJW_SHIFT;
|
||||
sjw_shift = ESD_USB_2_SJW_SHIFT;
|
||||
|
||||
canbtr |= ((bt->sjw - 1) & (ESD_USB2_SJW_MAX - 1))
|
||||
canbtr |= ((bt->sjw - 1) & (btc->sjw_max - 1))
|
||||
<< sjw_shift;
|
||||
canbtr |= ((bt->prop_seg + bt->phase_seg1 - 1)
|
||||
& (ESD_USB2_TSEG1_MAX - 1))
|
||||
<< ESD_USB2_TSEG1_SHIFT;
|
||||
canbtr |= ((bt->phase_seg2 - 1) & (ESD_USB2_TSEG2_MAX - 1))
|
||||
<< ESD_USB2_TSEG2_SHIFT;
|
||||
& (btc->tseg1_max - 1))
|
||||
<< ESD_USB_2_TSEG1_SHIFT;
|
||||
canbtr |= ((bt->phase_seg2 - 1) & (btc->tseg2_max - 1))
|
||||
<< ESD_USB_2_TSEG2_SHIFT;
|
||||
if (priv->can.ctrlmode & CAN_CTRLMODE_3_SAMPLES)
|
||||
canbtr |= ESD_USB2_3_SAMPLES;
|
||||
canbtr |= ESD_USB_TRIPLE_SAMPLES;
|
||||
|
||||
msg = kmalloc(sizeof(*msg), GFP_KERNEL);
|
||||
if (!msg)
|
||||
return -ENOMEM;
|
||||
|
||||
msg->hdr.len = 2;
|
||||
msg->hdr.cmd = CMD_SETBAUD;
|
||||
msg->hdr.len = sizeof(struct esd_usb_set_baudrate_msg) / sizeof(u32); /* # of 32bit words */
|
||||
msg->hdr.cmd = ESD_USB_CMD_SETBAUD;
|
||||
msg->setbaud.net = priv->index;
|
||||
msg->setbaud.rsvd = 0;
|
||||
msg->setbaud.baud = cpu_to_le32(canbtr);
|
||||
|
||||
netdev_info(netdev, "setting BTR=%#x\n", canbtr);
|
||||
netdev_dbg(netdev, "setting BTR=%#x\n", canbtr);
|
||||
|
||||
err = esd_usb_send_msg(priv->usb, msg);
|
||||
|
||||
|
|
@ -999,7 +995,7 @@ static int esd_usb_probe_one_net(struct usb_interface *intf, int index)
|
|||
int err = 0;
|
||||
int i;
|
||||
|
||||
netdev = alloc_candev(sizeof(*priv), MAX_TX_URBS);
|
||||
netdev = alloc_candev(sizeof(*priv), ESD_USB_MAX_TX_URBS);
|
||||
if (!netdev) {
|
||||
dev_err(&intf->dev, "couldn't alloc candev\n");
|
||||
err = -ENOMEM;
|
||||
|
|
@ -1011,8 +1007,8 @@ static int esd_usb_probe_one_net(struct usb_interface *intf, int index)
|
|||
init_usb_anchor(&priv->tx_submitted);
|
||||
atomic_set(&priv->active_tx_jobs, 0);
|
||||
|
||||
for (i = 0; i < MAX_TX_URBS; i++)
|
||||
priv->tx_contexts[i].echo_index = MAX_TX_URBS;
|
||||
for (i = 0; i < ESD_USB_MAX_TX_URBS; i++)
|
||||
priv->tx_contexts[i].echo_index = ESD_USB_MAX_TX_URBS;
|
||||
|
||||
priv->usb = dev;
|
||||
priv->netdev = netdev;
|
||||
|
|
@ -1024,15 +1020,15 @@ static int esd_usb_probe_one_net(struct usb_interface *intf, int index)
|
|||
CAN_CTRLMODE_BERR_REPORTING;
|
||||
|
||||
if (le16_to_cpu(dev->udev->descriptor.idProduct) ==
|
||||
USB_CANUSBM_PRODUCT_ID)
|
||||
priv->can.clock.freq = ESD_USBM_CAN_CLOCK;
|
||||
ESD_USB_CANUSBM_PRODUCT_ID)
|
||||
priv->can.clock.freq = ESD_USB_M_CAN_CLOCK;
|
||||
else {
|
||||
priv->can.clock.freq = ESD_USB2_CAN_CLOCK;
|
||||
priv->can.clock.freq = ESD_USB_2_CAN_CLOCK;
|
||||
priv->can.ctrlmode_supported |= CAN_CTRLMODE_3_SAMPLES;
|
||||
}
|
||||
|
||||
priv->can.bittiming_const = &esd_usb2_bittiming_const;
|
||||
priv->can.do_set_bittiming = esd_usb2_set_bittiming;
|
||||
priv->can.bittiming_const = &esd_usb_2_bittiming_const;
|
||||
priv->can.do_set_bittiming = esd_usb_2_set_bittiming;
|
||||
priv->can.do_set_mode = esd_usb_set_mode;
|
||||
priv->can.do_get_berr_counter = esd_usb_get_berr_counter;
|
||||
|
||||
|
|
@ -1090,8 +1086,8 @@ static int esd_usb_probe(struct usb_interface *intf,
|
|||
}
|
||||
|
||||
/* query number of CAN interfaces (nets) */
|
||||
msg->hdr.cmd = CMD_VERSION;
|
||||
msg->hdr.len = 2;
|
||||
msg->hdr.cmd = ESD_USB_CMD_VERSION;
|
||||
msg->hdr.len = sizeof(struct esd_usb_version_msg) / sizeof(u32); /* # of 32bit words */
|
||||
msg->version.rsvd = 0;
|
||||
msg->version.flags = 0;
|
||||
msg->version.drv_version = 0;
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -1,129 +1,258 @@
|
|||
/* 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 (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
|
||||
*
|
||||
* including all fields preceding the data field, ignoring bitstuffing
|
||||
*/
|
||||
#define CAN_FRAME_HEADER_SFF_BITS 19
|
||||
|
||||
/*
|
||||
* Size of a Classical CAN Extended Frame header in bits
|
||||
*
|
||||
* Name of Field Bits
|
||||
* ---------------------------------------------------------
|
||||
* 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
|
||||
*
|
||||
* including all fields preceding the data field, ignoring bitstuffing
|
||||
*/
|
||||
#define CAN_FRAME_HEADER_EFF_BITS 39
|
||||
|
||||
/*
|
||||
* Size of a CAN-FD Standard Frame in bits
|
||||
*
|
||||
* Name of Field Bits
|
||||
* ---------------------------------------------------------
|
||||
* 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
|
||||
*
|
||||
* including all fields preceding the data field, ignoring bitstuffing
|
||||
*/
|
||||
#define CANFD_FRAME_HEADER_SFF_BITS 22
|
||||
|
||||
/*
|
||||
* Size of a CAN-FD Extended Frame in bits
|
||||
*
|
||||
* Name of Field Bits
|
||||
* ---------------------------------------------------------
|
||||
* 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
|
||||
*
|
||||
* 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
|
||||
* ---------------------------------------------------------
|
||||
* 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
|
||||
* End Of Frame (EOF) 7
|
||||
*
|
||||
* rounded up and ignoring bitstuffing
|
||||
* including all fields following the CRC field
|
||||
*/
|
||||
#define CAN_FRAME_OVERHEAD_SFF DIV_ROUND_UP(47, 8)
|
||||
#define CAN_FRAME_FOOTER_BITS 9
|
||||
|
||||
/*
|
||||
* Size of a Classical CAN Extended Frame
|
||||
*
|
||||
* 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
|
||||
* 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
|
||||
* First part of the Inter Frame Space
|
||||
* (a.k.a. IMF - intermission field)
|
||||
*/
|
||||
#define CAN_FRAME_OVERHEAD_EFF DIV_ROUND_UP(67, 8)
|
||||
#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) \
|
||||
)
|
||||
|
||||
/*
|
||||
* Size of a CAN-FD Standard Frame
|
||||
*
|
||||
* 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
|
||||
* 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
|
||||
* Number of bytes in a CAN frame
|
||||
* (rounded up, including intermission)
|
||||
*/
|
||||
#define CANFD_FRAME_OVERHEAD_SFF DIV_ROUND_UP(61, 8)
|
||||
|
||||
/*
|
||||
* Size of a CAN-FD Extended Frame
|
||||
*
|
||||
* 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
|
||||
* 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
|
||||
*/
|
||||
#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,
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user