linux/drivers/net/can/usb/peak_usb/pcan_usb.c

// SPDX-License-Identifier: GPL-2.0-only
/*
 * CAN driver for PEAK System PCAN-USB adapter
 * Derived from the PCAN project file driver/src/pcan_usb.c
 *
 * Copyright (C) 2003-2010 PEAK System-Technik GmbH
 * Copyright (C) 2011-2012 Stephane Grosjean <[email protected]>
 *
 * Many thanks to Klaus Hitschler <[email protected]>
 */
#include <asm/unaligned.h>

#include <linux/ethtool.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 "pcan_usb_core.h"

/* PCAN-USB Endpoints */
#define PCAN_USB_EP_CMDOUT
#define PCAN_USB_EP_CMDIN
#define PCAN_USB_EP_MSGOUT
#define PCAN_USB_EP_MSGIN

/* PCAN-USB command struct */
#define PCAN_USB_CMD_FUNC
#define PCAN_USB_CMD_NUM
#define PCAN_USB_CMD_ARGS
#define PCAN_USB_CMD_ARGS_LEN
#define PCAN_USB_CMD_LEN

/* PCAN-USB commands */
#define PCAN_USB_CMD_BITRATE
#define PCAN_USB_CMD_SET_BUS
#define PCAN_USB_CMD_DEVID
#define PCAN_USB_CMD_SN
#define PCAN_USB_CMD_REGISTER
#define PCAN_USB_CMD_EXT_VCC
#define PCAN_USB_CMD_ERR_FR
#define PCAN_USB_CMD_LED

/* PCAN_USB_CMD_SET_BUS number arg */
#define PCAN_USB_BUS_XCVER
#define PCAN_USB_BUS_SILENT_MODE

/* PCAN_USB_CMD_xxx functions */
#define PCAN_USB_GET
#define PCAN_USB_SET

/* PCAN-USB command timeout (ms.) */
#define PCAN_USB_COMMAND_TIMEOUT

/* PCAN-USB startup timeout (ms.) */
#define PCAN_USB_STARTUP_TIMEOUT

/* PCAN-USB rx/tx buffers size */
#define PCAN_USB_RX_BUFFER_SIZE
#define PCAN_USB_TX_BUFFER_SIZE

#define PCAN_USB_MSG_HEADER_LEN

#define PCAN_USB_MSG_TX_CAN

/* PCAN-USB adapter internal clock (MHz) */
#define PCAN_USB_CRYSTAL_HZ

/* PCAN-USB USB message record status/len field */
#define PCAN_USB_STATUSLEN_TIMESTAMP
#define PCAN_USB_STATUSLEN_INTERNAL
#define PCAN_USB_STATUSLEN_EXT_ID
#define PCAN_USB_STATUSLEN_RTR
#define PCAN_USB_STATUSLEN_DLC

/* PCAN-USB 4.1 CAN Id tx extended flags */
#define PCAN_USB_TX_SRR
#define PCAN_USB_TX_AT

/* PCAN-USB error flags */
#define PCAN_USB_ERROR_TXFULL
#define PCAN_USB_ERROR_RXQOVR
#define PCAN_USB_ERROR_BUS_LIGHT
#define PCAN_USB_ERROR_BUS_HEAVY
#define PCAN_USB_ERROR_BUS_OFF
#define PCAN_USB_ERROR_RXQEMPTY
#define PCAN_USB_ERROR_QOVR
#define PCAN_USB_ERROR_TXQFULL

#define PCAN_USB_ERROR_BUS

/* SJA1000 modes */
#define SJA1000_MODE_NORMAL
#define SJA1000_MODE_INIT

/*
 * tick duration = 42.666 us =>
 * (tick_number * 44739243) >> 20 ~ (tick_number * 42666) / 1000
 * accuracy = 10^-7
 */
#define PCAN_USB_TS_DIV_SHIFTER
#define PCAN_USB_TS_US_PER_TICK

/* PCAN-USB messages record types */
#define PCAN_USB_REC_ERROR
#define PCAN_USB_REC_ANALOG
#define PCAN_USB_REC_BUSLOAD
#define PCAN_USB_REC_TS
#define PCAN_USB_REC_BUSEVT

/* CAN bus events notifications selection mask */
#define PCAN_USB_ERR_RXERR
#define PCAN_USB_ERR_TXERR

/* This mask generates an usb packet each time the state of the bus changes.
 * In other words, its interest is to know which side among rx and tx is
 * responsible of the change of the bus state.
 */
#define PCAN_USB_BERR_MASK

/* identify bus event packets with rx/tx error counters */
#define PCAN_USB_ERR_CNT_DEC
#define PCAN_USB_ERR_CNT_INC

/* private to PCAN-USB adapter */
struct pcan_usb {};

/* incoming message context for decoding */
struct pcan_usb_msg_context {};

/*
 * send a command
 */
static int pcan_usb_send_cmd(struct peak_usb_device *dev, u8 f, u8 n, u8 *p)
{}

/*
 * send a command then wait for its response
 */
static int pcan_usb_wait_rsp(struct peak_usb_device *dev, u8 f, u8 n, u8 *p)
{}

static int pcan_usb_set_sja1000(struct peak_usb_device *dev, u8 mode)
{}

static int pcan_usb_set_bus(struct peak_usb_device *dev, u8 onoff)
{}

static int pcan_usb_set_silent(struct peak_usb_device *dev, u8 onoff)
{}

/* send the cmd to be notified from bus errors */
static int pcan_usb_set_err_frame(struct peak_usb_device *dev, u8 err_mask)
{}

static int pcan_usb_set_ext_vcc(struct peak_usb_device *dev, u8 onoff)
{}

static int pcan_usb_set_led(struct peak_usb_device *dev, u8 onoff)
{}

/*
 * set bittiming value to can
 */
static int pcan_usb_set_bittiming(struct peak_usb_device *dev,
				  struct can_bittiming *bt)
{}

/*
 * init/reset can
 */
static int pcan_usb_write_mode(struct peak_usb_device *dev, u8 onoff)
{}

/*
 * handle end of waiting for the device to reset
 */
static void pcan_usb_restart(struct timer_list *t)
{}

/*
 * handle the submission of the restart urb
 */
static void pcan_usb_restart_pending(struct urb *urb)
{}

/*
 * handle asynchronous restart
 */
static int pcan_usb_restart_async(struct peak_usb_device *dev, struct urb *urb,
				  u8 *buf)
{}

/*
 * read serial number from device
 */
static int pcan_usb_get_serial(struct peak_usb_device *dev, u32 *serial_number)
{}

/*
 * read can channel id from device
 */
static int pcan_usb_get_can_channel_id(struct peak_usb_device *dev, u32 *can_ch_id)
{}

/* set a new CAN channel id in the flash memory of the device */
static int pcan_usb_set_can_channel_id(struct peak_usb_device *dev, u32 can_ch_id)
{}

/*
 * update current time ref with received timestamp
 */
static int pcan_usb_update_ts(struct pcan_usb_msg_context *mc)
{}

/*
 * decode received timestamp
 */
static int pcan_usb_decode_ts(struct pcan_usb_msg_context *mc, u8 first_packet)
{}

static int pcan_usb_decode_error(struct pcan_usb_msg_context *mc, u8 n,
				 u8 status_len)
{}

/* decode bus event usb packet: first byte contains rxerr while 2nd one contains
 * txerr.
 */
static int pcan_usb_handle_bus_evt(struct pcan_usb_msg_context *mc, u8 ir)
{}

/*
 * decode non-data usb message
 */
static int pcan_usb_decode_status(struct pcan_usb_msg_context *mc,
				  u8 status_len)
{}

/*
 * decode data usb message
 */
static int pcan_usb_decode_data(struct pcan_usb_msg_context *mc, u8 status_len)
{}

/*
 * process incoming message
 */
static int pcan_usb_decode_msg(struct peak_usb_device *dev, u8 *ibuf, u32 lbuf)
{}

/*
 * process any incoming buffer
 */
static int pcan_usb_decode_buf(struct peak_usb_device *dev, struct urb *urb)
{}

/*
 * process outgoing packet
 */
static int pcan_usb_encode_msg(struct peak_usb_device *dev, struct sk_buff *skb,
			       u8 *obuf, size_t *size)
{}

/* socket callback used to copy berr counters values received through USB */
static int pcan_usb_get_berr_counter(const struct net_device *netdev,
				     struct can_berr_counter *bec)
{}

/*
 * start interface
 */
static int pcan_usb_start(struct peak_usb_device *dev)
{}

static int pcan_usb_init(struct peak_usb_device *dev)
{}

/*
 * probe function for new PCAN-USB usb interface
 */
static int pcan_usb_probe(struct usb_interface *intf)
{}

static int pcan_usb_set_phys_id(struct net_device *netdev,
				enum ethtool_phys_id_state state)
{}

/* This device only handles 8-bit CAN channel id. */
static int pcan_usb_get_eeprom_len(struct net_device *netdev)
{}

static const struct ethtool_ops pcan_usb_ethtool_ops =;

/*
 * describe the PCAN-USB adapter
 */
static const struct can_bittiming_const pcan_usb_const =;

const struct peak_usb_adapter pcan_usb =;