linux/drivers/net/can/usb/esd_usb.c

// SPDX-License-Identifier: GPL-2.0-only
/*
 * CAN driver for esd electronics gmbh CAN-USB/2, CAN-USB/3 and CAN-USB/Micro
 *
 * Copyright (C) 2010-2012 esd electronic system design gmbh, Matthias Fuchs <[email protected]>
 * Copyright (C) 2022-2023 esd electronics gmbh, Frank Jungclaus <[email protected]>
 */

#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();
MODULE_AUTHOR();
MODULE_DESCRIPTION();
MODULE_LICENSE();

/* USB vendor and product ID */
#define ESD_USB_ESDGMBH_VENDOR_ID
#define ESD_USB_CANUSB2_PRODUCT_ID
#define ESD_USB_CANUSBM_PRODUCT_ID
#define ESD_USB_CANUSB3_PRODUCT_ID

/* CAN controller clock frequencies */
#define ESD_USB_2_CAN_CLOCK
#define ESD_USB_M_CAN_CLOCK
#define ESD_USB_3_CAN_CLOCK

/* Maximum number of CAN nets */
#define ESD_USB_MAX_NETS

/* USB commands */
#define ESD_USB_CMD_VERSION
#define ESD_USB_CMD_CAN_RX
#define ESD_USB_CMD_CAN_TX
#define ESD_USB_CMD_SETBAUD
#define ESD_USB_CMD_TS
#define ESD_USB_CMD_IDADD

/* esd CAN message flags - dlc field */
#define ESD_USB_RTR
#define ESD_USB_NO_BRS
#define ESD_USB_ESI
#define ESD_USB_FD

/* esd CAN message flags - id field */
#define ESD_USB_EXTID
#define ESD_USB_EVENT
#define ESD_USB_IDMASK

/* esd CAN event ids */
#define ESD_USB_EV_CAN_ERROR_EXT

/* baudrate message flags */
#define ESD_USB_LOM
#define ESD_USB_UBR
#define ESD_USB_NO_BAUDRATE

/* bit timing esd CAN-USB */
#define ESD_USB_2_TSEG1_SHIFT
#define ESD_USB_2_TSEG2_SHIFT
#define ESD_USB_2_SJW_SHIFT
#define ESD_USB_M_SJW_SHIFT
#define ESD_USB_TRIPLE_SAMPLES

/* Transmitter Delay Compensation */
#define ESD_USB_3_TDC_MODE_AUTO

/* esd IDADD message */
#define ESD_USB_ID_ENABLE
#define ESD_USB_MAX_ID_SEGMENT

/* SJA1000 ECC register (emulated by usb firmware) */
#define ESD_USB_SJA1000_ECC_SEG
#define ESD_USB_SJA1000_ECC_DIR
#define ESD_USB_SJA1000_ECC_ERR
#define ESD_USB_SJA1000_ECC_BIT
#define ESD_USB_SJA1000_ECC_FORM
#define ESD_USB_SJA1000_ECC_STUFF
#define ESD_USB_SJA1000_ECC_MASK

/* esd bus state event codes */
#define ESD_USB_BUSSTATE_MASK
#define ESD_USB_BUSSTATE_WARN
#define ESD_USB_BUSSTATE_ERRPASSIVE
#define ESD_USB_BUSSTATE_BUSOFF

#define ESD_USB_RX_BUFFER_SIZE
#define ESD_USB_MAX_RX_URBS
#define ESD_USB_MAX_TX_URBS

/* Modes for CAN-USB/3, to be used for esd_usb_3_set_baudrate_msg_x.mode */
#define ESD_USB_3_BAUDRATE_MODE_DISABLE
#define ESD_USB_3_BAUDRATE_MODE_INDEX
#define ESD_USB_3_BAUDRATE_MODE_BTR_CTRL
#define ESD_USB_3_BAUDRATE_MODE_BTR_CANONICAL
#define ESD_USB_3_BAUDRATE_MODE_NUM
#define ESD_USB_3_BAUDRATE_MODE_AUTOBAUD

/* Flags for CAN-USB/3, to be used for esd_usb_3_set_baudrate_msg_x.flags */
#define ESD_USB_3_BAUDRATE_FLAG_FD
#define ESD_USB_3_BAUDRATE_FLAG_LOM
#define ESD_USB_3_BAUDRATE_FLAG_STM
#define ESD_USB_3_BAUDRATE_FLAG_TRS
#define ESD_USB_3_BAUDRATE_FLAG_TXP

struct esd_usb_header_msg {};

struct esd_usb_version_msg {};

struct esd_usb_version_reply_msg {};

struct esd_usb_rx_msg {};

struct esd_usb_tx_msg {};

struct esd_usb_tx_done_msg {};

struct esd_usb_id_filter_msg {};

struct esd_usb_set_baudrate_msg {};

/* CAN-USB/3 baudrate configuration, used for nominal as well as for data bit rate */
struct esd_usb_3_baudrate_cfg {};

/* In principle, the esd CAN-USB/3 supports Transmitter Delay Compensation (TDC),
 * but currently only the automatic TDC mode is supported by this driver.
 * An implementation for manual TDC configuration will follow.
 *
 * For information about struct esd_usb_3_tdc_cfg, see
 * NTCAN Application Developers Manual, 6.2.25 NTCAN_TDC_CFG + related chapters
 * https://esd.eu/fileadmin/esd/docs/manuals/NTCAN_Part1_Function_API_Manual_en_56.pdf
 */
struct esd_usb_3_tdc_cfg {};

/* Extended version of the above set_baudrate_msg for a CAN-USB/3
 * to define the CAN bit timing configuration of the CAN controller in
 * CAN FD mode as well as in Classical CAN mode.
 *
 * The payload of this command is a NTCAN_BAUDRATE_X structure according to
 * esd electronics gmbh, NTCAN Application Developers Manual, 6.2.15 NTCAN_BAUDRATE_X
 * https://esd.eu/fileadmin/esd/docs/manuals/NTCAN_Part1_Function_API_Manual_en_56.pdf
 */
struct esd_usb_3_set_baudrate_msg_x {};

/* Main message type used between library and application */
esd_usb_msg;

static struct usb_device_id esd_usb_table[] =;
MODULE_DEVICE_TABLE(usb, esd_usb_table);

struct esd_usb_net_priv;

struct esd_tx_urb_context {};

struct esd_usb {};

struct esd_usb_net_priv {};

static void esd_usb_rx_event(struct esd_usb_net_priv *priv,
			     union esd_usb_msg *msg)
{}

static void esd_usb_rx_can_msg(struct esd_usb_net_priv *priv,
			       union esd_usb_msg *msg)
{}

static void esd_usb_tx_done_msg(struct esd_usb_net_priv *priv,
				union esd_usb_msg *msg)
{}

static void esd_usb_read_bulk_callback(struct urb *urb)
{}

/* callback for bulk IN urb */
static void esd_usb_write_bulk_callback(struct urb *urb)
{}

static ssize_t firmware_show(struct device *d,
			     struct device_attribute *attr, char *buf)
{}
static DEVICE_ATTR_RO(firmware);

static ssize_t hardware_show(struct device *d,
			     struct device_attribute *attr, char *buf)
{}
static DEVICE_ATTR_RO(hardware);

static ssize_t nets_show(struct device *d,
			 struct device_attribute *attr, char *buf)
{}
static DEVICE_ATTR_RO(nets);

static int esd_usb_send_msg(struct esd_usb *dev, union esd_usb_msg *msg)
{}

static int esd_usb_wait_msg(struct esd_usb *dev,
			    union esd_usb_msg *msg)
{}

static int esd_usb_setup_rx_urbs(struct esd_usb *dev)
{}

/* Start interface */
static int esd_usb_start(struct esd_usb_net_priv *priv)
{}

static void unlink_all_urbs(struct esd_usb *dev)
{}

static int esd_usb_open(struct net_device *netdev)
{}

static netdev_tx_t esd_usb_start_xmit(struct sk_buff *skb,
				      struct net_device *netdev)
{}

static int esd_usb_close(struct net_device *netdev)
{}

static const struct net_device_ops esd_usb_netdev_ops =;

static const struct ethtool_ops esd_usb_ethtool_ops =;

static const struct can_bittiming_const esd_usb_2_bittiming_const =;

static int esd_usb_2_set_bittiming(struct net_device *netdev)
{}

/* Nominal bittiming constants, see
 * Microchip SAM E70/S70/V70/V71, Data Sheet, Rev. G - 07/2022
 * 48.6.8 MCAN Nominal Bit Timing and Prescaler Register
 */
static const struct can_bittiming_const esd_usb_3_nom_bittiming_const =;

/* Data bittiming constants, see
 * Microchip SAM E70/S70/V70/V71, Data Sheet, Rev. G - 07/2022
 * 48.6.4 MCAN Data Bit Timing and Prescaler Register
 */
static const struct can_bittiming_const esd_usb_3_data_bittiming_const =;

static int esd_usb_3_set_bittiming(struct net_device *netdev)
{}

static int esd_usb_get_berr_counter(const struct net_device *netdev,
				    struct can_berr_counter *bec)
{}

static int esd_usb_set_mode(struct net_device *netdev, enum can_mode mode)
{}

static int esd_usb_probe_one_net(struct usb_interface *intf, int index)
{}

/* probe function for new USB devices
 *
 * check version information and number of available
 * CAN interfaces
 */
static int esd_usb_probe(struct usb_interface *intf,
			 const struct usb_device_id *id)
{}

/* called by the usb core when the device is removed from the system */
static void esd_usb_disconnect(struct usb_interface *intf)
{}

/* usb specific object needed to register this driver with the usb subsystem */
static struct usb_driver esd_usb_driver =;

module_usb_driver();