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

// SPDX-License-Identifier: GPL-2.0-only
/* SocketCAN driver for Microchip CAN BUS Analyzer Tool
 *
 * Copyright (C) 2017 Mobica Limited
 *
 * This driver is inspired by the 4.6.2 version of net/can/usb/usb_8dev.c
 */

#include <linux/unaligned.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/usb.h>

/* vendor and product id */
#define MCBA_MODULE_NAME
#define MCBA_VENDOR_ID
#define MCBA_PRODUCT_ID

/* driver constants */
#define MCBA_MAX_RX_URBS
#define MCBA_MAX_TX_URBS
#define MCBA_CTX_FREE

/* RX buffer must be bigger than msg size since at the
 * beginning USB messages are stacked.
 */
#define MCBA_USB_RX_BUFF_SIZE
#define MCBA_USB_TX_BUFF_SIZE

/* Microchip command id */
#define MBCA_CMD_RECEIVE_MESSAGE
#define MBCA_CMD_I_AM_ALIVE_FROM_CAN
#define MBCA_CMD_I_AM_ALIVE_FROM_USB
#define MBCA_CMD_CHANGE_BIT_RATE
#define MBCA_CMD_TRANSMIT_MESSAGE_EV
#define MBCA_CMD_SETUP_TERMINATION_RESISTANCE
#define MBCA_CMD_READ_FW_VERSION
#define MBCA_CMD_NOTHING_TO_SEND
#define MBCA_CMD_TRANSMIT_MESSAGE_RSP

#define MCBA_VER_REQ_USB
#define MCBA_VER_REQ_CAN

/* Drive the CAN_RES signal LOW "0" to activate R24 and R25 */
#define MCBA_VER_TERMINATION_ON
#define MCBA_VER_TERMINATION_OFF

#define MCBA_SIDL_EXID_MASK
#define MCBA_DLC_MASK
#define MCBA_DLC_RTR_MASK

#define MCBA_CAN_STATE_WRN_TH
#define MCBA_CAN_STATE_ERR_PSV_TH

#define MCBA_TERMINATION_DISABLED
#define MCBA_TERMINATION_ENABLED

struct mcba_usb_ctx {};

/* Structure to hold all of our device specific stuff */
struct mcba_priv {};

/* CAN frame */
struct __packed mcba_usb_msg_can {};

/* command frame */
struct __packed mcba_usb_msg {};

struct __packed mcba_usb_msg_ka_usb {};

struct __packed mcba_usb_msg_ka_can {};

struct __packed mcba_usb_msg_change_bitrate {};

struct __packed mcba_usb_msg_termination {};

struct __packed mcba_usb_msg_fw_ver {};

static const struct usb_device_id mcba_usb_table[] =;

MODULE_DEVICE_TABLE(usb, mcba_usb_table);

static const u16 mcba_termination[] =;

static const u32 mcba_bitrate[] =;

static inline void mcba_init_ctx(struct mcba_priv *priv)
{}

static inline struct mcba_usb_ctx *mcba_usb_get_free_ctx(struct mcba_priv *priv,
							 struct can_frame *cf)
{}

/* mcba_usb_free_ctx and mcba_usb_get_free_ctx are executed by different
 * threads. The order of execution in below function is important.
 */
static inline void mcba_usb_free_ctx(struct mcba_usb_ctx *ctx)
{}

static void mcba_usb_write_bulk_callback(struct urb *urb)
{}

/* Send data to device */
static netdev_tx_t mcba_usb_xmit(struct mcba_priv *priv,
				 struct mcba_usb_msg *usb_msg,
				 struct mcba_usb_ctx *ctx)
{}

/* Send data to device */
static netdev_tx_t mcba_usb_start_xmit(struct sk_buff *skb,
				       struct net_device *netdev)
{}

/* Send cmd to device */
static void mcba_usb_xmit_cmd(struct mcba_priv *priv,
			      struct mcba_usb_msg *usb_msg)
{}

static void mcba_usb_xmit_change_bitrate(struct mcba_priv *priv, u16 bitrate)
{}

static void mcba_usb_xmit_read_fw_ver(struct mcba_priv *priv, u8 pic)
{}

static void mcba_usb_process_can(struct mcba_priv *priv,
				 struct mcba_usb_msg_can *msg)
{}

static void mcba_usb_process_ka_usb(struct mcba_priv *priv,
				    struct mcba_usb_msg_ka_usb *msg)
{}

static u32 convert_can2host_bitrate(struct mcba_usb_msg_ka_can *msg)
{}

static void mcba_usb_process_ka_can(struct mcba_priv *priv,
				    struct mcba_usb_msg_ka_can *msg)
{}

static void mcba_usb_process_rx(struct mcba_priv *priv,
				struct mcba_usb_msg *msg)
{}

/* Callback for reading data from device
 *
 * Check urb status, call read function and resubmit urb read operation.
 */
static void mcba_usb_read_bulk_callback(struct urb *urb)
{}

/* Start USB device */
static int mcba_usb_start(struct mcba_priv *priv)
{}

/* Open USB device */
static int mcba_usb_open(struct net_device *netdev)
{}

static void mcba_urb_unlink(struct mcba_priv *priv)
{}

/* Close USB device */
static int mcba_usb_close(struct net_device *netdev)
{}

/* Set network device mode
 *
 * Maybe we should leave this function empty, because the device
 * set mode variable with open command.
 */
static int mcba_net_set_mode(struct net_device *netdev, enum can_mode mode)
{}

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

static const struct net_device_ops mcba_netdev_ops =;

static const struct ethtool_ops mcba_ethtool_ops =;

/* Microchip CANBUS has hardcoded bittiming values by default.
 * This function sends request via USB to change the speed and align bittiming
 * values for presentation purposes only
 */
static int mcba_net_set_bittiming(struct net_device *netdev)
{}

static int mcba_set_termination(struct net_device *netdev, u16 term)
{}

static int mcba_usb_probe(struct usb_interface *intf,
			  const struct usb_device_id *id)
{}

/* Called by the usb core when driver is unloaded or device is removed */
static void mcba_usb_disconnect(struct usb_interface *intf)
{}

static struct usb_driver mcba_usb_driver =;

module_usb_driver();

MODULE_AUTHOR();
MODULE_DESCRIPTION();
MODULE_LICENSE();