mirror of
https://github.com/LuckfoxTECH/luckfox-pico.git
synced 2026-01-19 09:52:31 +01:00
project:build.sh: Added fastboot support; custom modifications to U-Boot and kernel implemented using patches.
project:cfg:BoardConfig_IPC: Added fastboot BoardConfig file and firmware post-scripts, distinguishing between the BoardConfigs for Luckfox Pico Pro and Luckfox Pico Max. project:app: Added fastboot_client and rk_smart_door for quick boot applications; updated rkipc app to adapt to the latest media library. media:samples: Added more usage examples. media:rockit: Fixed bugs; removed support for retrieving data frames from VPSS. media:isp: Updated rkaiq library and related tools to support connection to RKISP_Tuner. sysdrv:Makefile: Added support for compiling drv_ko on Luckfox Pico Ultra W using Ubuntu; added support for custom root filesystem. sysdrv:tools:board: Updated Buildroot optional mirror sources, updated some software versions, and stored device tree files and configuration files that undergo multiple modifications for U-Boot and kernel separately. sysdrv:source:mcu: Used RISC-V MCU SDK with RT-Thread system, mainly for initializing camera AE during quick boot. sysdrv:source:uboot: Added support for fastboot; added high baud rate DDR bin for serial firmware upgrades. sysdrv:source:kernel: Upgraded to version 5.10.160; increased NPU frequency for RV1106G3; added support for fastboot. Signed-off-by: luckfox-eng29 <eng29@luckfox.com>
This commit is contained in:
@@ -194,7 +194,7 @@ struct __packed ems_cpc_msg {
|
||||
__le32 ts_sec; /* timestamp in seconds */
|
||||
__le32 ts_nsec; /* timestamp in nano seconds */
|
||||
|
||||
union {
|
||||
union __packed {
|
||||
u8 generic[64];
|
||||
struct cpc_can_msg can_msg;
|
||||
struct cpc_can_params can_params;
|
||||
|
||||
@@ -227,6 +227,10 @@ static void esd_usb2_rx_event(struct esd_usb2_net_priv *priv,
|
||||
u8 rxerr = msg->msg.rx.data[2];
|
||||
u8 txerr = msg->msg.rx.data[3];
|
||||
|
||||
netdev_dbg(priv->netdev,
|
||||
"CAN_ERR_EV_EXT: dlc=%#02x state=%02x ecc=%02x rec=%02x tec=%02x\n",
|
||||
msg->msg.rx.dlc, state, ecc, rxerr, txerr);
|
||||
|
||||
skb = alloc_can_err_skb(priv->netdev, &cf);
|
||||
if (skb == NULL) {
|
||||
stats->rx_dropped++;
|
||||
@@ -253,6 +257,8 @@ static void esd_usb2_rx_event(struct esd_usb2_net_priv *priv,
|
||||
break;
|
||||
default:
|
||||
priv->can.state = CAN_STATE_ERROR_ACTIVE;
|
||||
txerr = 0;
|
||||
rxerr = 0;
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
|
||||
@@ -184,6 +184,8 @@ struct gs_can {
|
||||
|
||||
struct usb_anchor tx_submitted;
|
||||
atomic_t active_tx_urbs;
|
||||
void *rxbuf[GS_MAX_RX_URBS];
|
||||
dma_addr_t rxbuf_dma[GS_MAX_RX_URBS];
|
||||
};
|
||||
|
||||
/* usb interface struct */
|
||||
@@ -592,6 +594,7 @@ static int gs_can_open(struct net_device *netdev)
|
||||
for (i = 0; i < GS_MAX_RX_URBS; i++) {
|
||||
struct urb *urb;
|
||||
u8 *buf;
|
||||
dma_addr_t buf_dma;
|
||||
|
||||
/* alloc rx urb */
|
||||
urb = usb_alloc_urb(0, GFP_KERNEL);
|
||||
@@ -602,7 +605,7 @@ static int gs_can_open(struct net_device *netdev)
|
||||
buf = usb_alloc_coherent(dev->udev,
|
||||
sizeof(struct gs_host_frame),
|
||||
GFP_KERNEL,
|
||||
&urb->transfer_dma);
|
||||
&buf_dma);
|
||||
if (!buf) {
|
||||
netdev_err(netdev,
|
||||
"No memory left for USB buffer\n");
|
||||
@@ -610,6 +613,8 @@ static int gs_can_open(struct net_device *netdev)
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
urb->transfer_dma = buf_dma;
|
||||
|
||||
/* fill, anchor, and submit rx urb */
|
||||
usb_fill_bulk_urb(urb,
|
||||
dev->udev,
|
||||
@@ -633,10 +638,17 @@ static int gs_can_open(struct net_device *netdev)
|
||||
rc);
|
||||
|
||||
usb_unanchor_urb(urb);
|
||||
usb_free_coherent(dev->udev,
|
||||
sizeof(struct gs_host_frame),
|
||||
buf,
|
||||
buf_dma);
|
||||
usb_free_urb(urb);
|
||||
break;
|
||||
}
|
||||
|
||||
dev->rxbuf[i] = buf;
|
||||
dev->rxbuf_dma[i] = buf_dma;
|
||||
|
||||
/* Drop reference,
|
||||
* USB core will take care of freeing it
|
||||
*/
|
||||
@@ -666,6 +678,7 @@ static int gs_can_open(struct net_device *netdev)
|
||||
flags |= GS_CAN_MODE_TRIPLE_SAMPLE;
|
||||
|
||||
/* finally start device */
|
||||
dev->can.state = CAN_STATE_ERROR_ACTIVE;
|
||||
dm->mode = cpu_to_le32(GS_CAN_MODE_START);
|
||||
dm->flags = cpu_to_le32(flags);
|
||||
rc = usb_control_msg(interface_to_usbdev(dev->iface),
|
||||
@@ -682,13 +695,12 @@ static int gs_can_open(struct net_device *netdev)
|
||||
if (rc < 0) {
|
||||
netdev_err(netdev, "Couldn't start device (err=%d)\n", rc);
|
||||
kfree(dm);
|
||||
dev->can.state = CAN_STATE_STOPPED;
|
||||
return rc;
|
||||
}
|
||||
|
||||
kfree(dm);
|
||||
|
||||
dev->can.state = CAN_STATE_ERROR_ACTIVE;
|
||||
|
||||
parent->active_channels++;
|
||||
if (!(dev->can.ctrlmode & CAN_CTRLMODE_LISTENONLY))
|
||||
netif_start_queue(netdev);
|
||||
@@ -701,13 +713,20 @@ static int gs_can_close(struct net_device *netdev)
|
||||
int rc;
|
||||
struct gs_can *dev = netdev_priv(netdev);
|
||||
struct gs_usb *parent = dev->parent;
|
||||
unsigned int i;
|
||||
|
||||
netif_stop_queue(netdev);
|
||||
|
||||
/* Stop polling */
|
||||
parent->active_channels--;
|
||||
if (!parent->active_channels)
|
||||
if (!parent->active_channels) {
|
||||
usb_kill_anchored_urbs(&parent->rx_submitted);
|
||||
for (i = 0; i < GS_MAX_RX_URBS; i++)
|
||||
usb_free_coherent(dev->udev,
|
||||
sizeof(struct gs_host_frame),
|
||||
dev->rxbuf[i],
|
||||
dev->rxbuf_dma[i]);
|
||||
}
|
||||
|
||||
/* Stop sending URBs */
|
||||
usb_kill_anchored_urbs(&dev->tx_submitted);
|
||||
|
||||
@@ -35,9 +35,10 @@
|
||||
#define KVASER_USB_RX_BUFFER_SIZE 3072
|
||||
#define KVASER_USB_MAX_NET_DEVICES 5
|
||||
|
||||
/* USB devices features */
|
||||
#define KVASER_USB_HAS_SILENT_MODE BIT(0)
|
||||
#define KVASER_USB_HAS_TXRX_ERRORS BIT(1)
|
||||
/* Kvaser USB device quirks */
|
||||
#define KVASER_USB_QUIRK_HAS_SILENT_MODE BIT(0)
|
||||
#define KVASER_USB_QUIRK_HAS_TXRX_ERRORS BIT(1)
|
||||
#define KVASER_USB_QUIRK_IGNORE_CLK_FREQ BIT(2)
|
||||
|
||||
/* Device capabilities */
|
||||
#define KVASER_USB_CAP_BERR_CAP 0x01
|
||||
@@ -65,12 +66,7 @@ struct kvaser_usb_dev_card_data_hydra {
|
||||
struct kvaser_usb_dev_card_data {
|
||||
u32 ctrlmode_supported;
|
||||
u32 capabilities;
|
||||
union {
|
||||
struct {
|
||||
enum kvaser_usb_leaf_family family;
|
||||
} leaf;
|
||||
struct kvaser_usb_dev_card_data_hydra hydra;
|
||||
};
|
||||
struct kvaser_usb_dev_card_data_hydra hydra;
|
||||
};
|
||||
|
||||
/* Context for an outstanding, not yet ACKed, transmission */
|
||||
@@ -84,7 +80,7 @@ struct kvaser_usb {
|
||||
struct usb_device *udev;
|
||||
struct usb_interface *intf;
|
||||
struct kvaser_usb_net_priv *nets[KVASER_USB_MAX_NET_DEVICES];
|
||||
const struct kvaser_usb_dev_ops *ops;
|
||||
const struct kvaser_usb_driver_info *driver_info;
|
||||
const struct kvaser_usb_dev_cfg *cfg;
|
||||
|
||||
struct usb_endpoint_descriptor *bulk_in, *bulk_out;
|
||||
@@ -166,6 +162,12 @@ struct kvaser_usb_dev_ops {
|
||||
int *cmd_len, u16 transid);
|
||||
};
|
||||
|
||||
struct kvaser_usb_driver_info {
|
||||
u32 quirks;
|
||||
enum kvaser_usb_leaf_family family;
|
||||
const struct kvaser_usb_dev_ops *ops;
|
||||
};
|
||||
|
||||
struct kvaser_usb_dev_cfg {
|
||||
const struct can_clock clock;
|
||||
const unsigned int timestamp_freq;
|
||||
@@ -176,6 +178,8 @@ struct kvaser_usb_dev_cfg {
|
||||
extern const struct kvaser_usb_dev_ops kvaser_usb_hydra_dev_ops;
|
||||
extern const struct kvaser_usb_dev_ops kvaser_usb_leaf_dev_ops;
|
||||
|
||||
void kvaser_usb_unlink_tx_urbs(struct kvaser_usb_net_priv *priv);
|
||||
|
||||
int kvaser_usb_recv_cmd(const struct kvaser_usb *dev, void *cmd, int len,
|
||||
int *actual_len);
|
||||
|
||||
@@ -185,4 +189,7 @@ int kvaser_usb_send_cmd_async(struct kvaser_usb_net_priv *priv, void *cmd,
|
||||
int len);
|
||||
|
||||
int kvaser_usb_can_rx_over_error(struct net_device *netdev);
|
||||
|
||||
extern const struct can_bittiming_const kvaser_usb_flexc_bittiming_const;
|
||||
|
||||
#endif /* KVASER_USB_H */
|
||||
|
||||
@@ -79,104 +79,134 @@
|
||||
#define USB_ATI_MEMO_PRO_2HS_V2_PRODUCT_ID 269
|
||||
#define USB_HYBRID_PRO_CANLIN_PRODUCT_ID 270
|
||||
|
||||
static inline bool kvaser_is_leaf(const struct usb_device_id *id)
|
||||
{
|
||||
return (id->idProduct >= USB_LEAF_DEVEL_PRODUCT_ID &&
|
||||
id->idProduct <= USB_CAN_R_PRODUCT_ID) ||
|
||||
(id->idProduct >= USB_LEAF_LITE_V2_PRODUCT_ID &&
|
||||
id->idProduct <= USB_MINI_PCIE_2HS_PRODUCT_ID);
|
||||
}
|
||||
static const struct kvaser_usb_driver_info kvaser_usb_driver_info_hydra = {
|
||||
.quirks = 0,
|
||||
.ops = &kvaser_usb_hydra_dev_ops,
|
||||
};
|
||||
|
||||
static inline bool kvaser_is_usbcan(const struct usb_device_id *id)
|
||||
{
|
||||
return id->idProduct >= USB_USBCAN_REVB_PRODUCT_ID &&
|
||||
id->idProduct <= USB_MEMORATOR_PRODUCT_ID;
|
||||
}
|
||||
static const struct kvaser_usb_driver_info kvaser_usb_driver_info_usbcan = {
|
||||
.quirks = KVASER_USB_QUIRK_HAS_TXRX_ERRORS |
|
||||
KVASER_USB_QUIRK_HAS_SILENT_MODE,
|
||||
.family = KVASER_USBCAN,
|
||||
.ops = &kvaser_usb_leaf_dev_ops,
|
||||
};
|
||||
|
||||
static inline bool kvaser_is_hydra(const struct usb_device_id *id)
|
||||
{
|
||||
return id->idProduct >= USB_BLACKBIRD_V2_PRODUCT_ID &&
|
||||
id->idProduct <= USB_HYBRID_PRO_CANLIN_PRODUCT_ID;
|
||||
}
|
||||
static const struct kvaser_usb_driver_info kvaser_usb_driver_info_leaf = {
|
||||
.quirks = KVASER_USB_QUIRK_IGNORE_CLK_FREQ,
|
||||
.family = KVASER_LEAF,
|
||||
.ops = &kvaser_usb_leaf_dev_ops,
|
||||
};
|
||||
|
||||
static const struct kvaser_usb_driver_info kvaser_usb_driver_info_leaf_err = {
|
||||
.quirks = KVASER_USB_QUIRK_HAS_TXRX_ERRORS |
|
||||
KVASER_USB_QUIRK_IGNORE_CLK_FREQ,
|
||||
.family = KVASER_LEAF,
|
||||
.ops = &kvaser_usb_leaf_dev_ops,
|
||||
};
|
||||
|
||||
static const struct kvaser_usb_driver_info kvaser_usb_driver_info_leaf_err_listen = {
|
||||
.quirks = KVASER_USB_QUIRK_HAS_TXRX_ERRORS |
|
||||
KVASER_USB_QUIRK_HAS_SILENT_MODE |
|
||||
KVASER_USB_QUIRK_IGNORE_CLK_FREQ,
|
||||
.family = KVASER_LEAF,
|
||||
.ops = &kvaser_usb_leaf_dev_ops,
|
||||
};
|
||||
|
||||
static const struct kvaser_usb_driver_info kvaser_usb_driver_info_leafimx = {
|
||||
.quirks = 0,
|
||||
.ops = &kvaser_usb_leaf_dev_ops,
|
||||
};
|
||||
|
||||
static const struct usb_device_id kvaser_usb_table[] = {
|
||||
/* Leaf USB product IDs */
|
||||
{ USB_DEVICE(KVASER_VENDOR_ID, USB_LEAF_DEVEL_PRODUCT_ID) },
|
||||
{ USB_DEVICE(KVASER_VENDOR_ID, USB_LEAF_LITE_PRODUCT_ID) },
|
||||
/* Leaf M32C USB product IDs */
|
||||
{ USB_DEVICE(KVASER_VENDOR_ID, USB_LEAF_DEVEL_PRODUCT_ID),
|
||||
.driver_info = (kernel_ulong_t)&kvaser_usb_driver_info_leaf },
|
||||
{ USB_DEVICE(KVASER_VENDOR_ID, USB_LEAF_LITE_PRODUCT_ID),
|
||||
.driver_info = (kernel_ulong_t)&kvaser_usb_driver_info_leaf },
|
||||
{ USB_DEVICE(KVASER_VENDOR_ID, USB_LEAF_PRO_PRODUCT_ID),
|
||||
.driver_info = KVASER_USB_HAS_TXRX_ERRORS |
|
||||
KVASER_USB_HAS_SILENT_MODE },
|
||||
.driver_info = (kernel_ulong_t)&kvaser_usb_driver_info_leaf_err_listen },
|
||||
{ USB_DEVICE(KVASER_VENDOR_ID, USB_LEAF_SPRO_PRODUCT_ID),
|
||||
.driver_info = KVASER_USB_HAS_TXRX_ERRORS |
|
||||
KVASER_USB_HAS_SILENT_MODE },
|
||||
.driver_info = (kernel_ulong_t)&kvaser_usb_driver_info_leaf_err_listen },
|
||||
{ USB_DEVICE(KVASER_VENDOR_ID, USB_LEAF_PRO_LS_PRODUCT_ID),
|
||||
.driver_info = KVASER_USB_HAS_TXRX_ERRORS |
|
||||
KVASER_USB_HAS_SILENT_MODE },
|
||||
.driver_info = (kernel_ulong_t)&kvaser_usb_driver_info_leaf_err_listen },
|
||||
{ USB_DEVICE(KVASER_VENDOR_ID, USB_LEAF_PRO_SWC_PRODUCT_ID),
|
||||
.driver_info = KVASER_USB_HAS_TXRX_ERRORS |
|
||||
KVASER_USB_HAS_SILENT_MODE },
|
||||
.driver_info = (kernel_ulong_t)&kvaser_usb_driver_info_leaf_err_listen },
|
||||
{ USB_DEVICE(KVASER_VENDOR_ID, USB_LEAF_PRO_LIN_PRODUCT_ID),
|
||||
.driver_info = KVASER_USB_HAS_TXRX_ERRORS |
|
||||
KVASER_USB_HAS_SILENT_MODE },
|
||||
.driver_info = (kernel_ulong_t)&kvaser_usb_driver_info_leaf_err_listen },
|
||||
{ USB_DEVICE(KVASER_VENDOR_ID, USB_LEAF_SPRO_LS_PRODUCT_ID),
|
||||
.driver_info = KVASER_USB_HAS_TXRX_ERRORS |
|
||||
KVASER_USB_HAS_SILENT_MODE },
|
||||
.driver_info = (kernel_ulong_t)&kvaser_usb_driver_info_leaf_err_listen },
|
||||
{ USB_DEVICE(KVASER_VENDOR_ID, USB_LEAF_SPRO_SWC_PRODUCT_ID),
|
||||
.driver_info = KVASER_USB_HAS_TXRX_ERRORS |
|
||||
KVASER_USB_HAS_SILENT_MODE },
|
||||
.driver_info = (kernel_ulong_t)&kvaser_usb_driver_info_leaf_err_listen },
|
||||
{ USB_DEVICE(KVASER_VENDOR_ID, USB_MEMO2_DEVEL_PRODUCT_ID),
|
||||
.driver_info = KVASER_USB_HAS_TXRX_ERRORS |
|
||||
KVASER_USB_HAS_SILENT_MODE },
|
||||
.driver_info = (kernel_ulong_t)&kvaser_usb_driver_info_leaf_err_listen },
|
||||
{ USB_DEVICE(KVASER_VENDOR_ID, USB_MEMO2_HSHS_PRODUCT_ID),
|
||||
.driver_info = KVASER_USB_HAS_TXRX_ERRORS |
|
||||
KVASER_USB_HAS_SILENT_MODE },
|
||||
.driver_info = (kernel_ulong_t)&kvaser_usb_driver_info_leaf_err_listen },
|
||||
{ USB_DEVICE(KVASER_VENDOR_ID, USB_UPRO_HSHS_PRODUCT_ID),
|
||||
.driver_info = KVASER_USB_HAS_TXRX_ERRORS },
|
||||
{ USB_DEVICE(KVASER_VENDOR_ID, USB_LEAF_LITE_GI_PRODUCT_ID) },
|
||||
.driver_info = (kernel_ulong_t)&kvaser_usb_driver_info_leaf_err },
|
||||
{ USB_DEVICE(KVASER_VENDOR_ID, USB_LEAF_LITE_GI_PRODUCT_ID),
|
||||
.driver_info = (kernel_ulong_t)&kvaser_usb_driver_info_leaf },
|
||||
{ USB_DEVICE(KVASER_VENDOR_ID, USB_LEAF_PRO_OBDII_PRODUCT_ID),
|
||||
.driver_info = KVASER_USB_HAS_TXRX_ERRORS |
|
||||
KVASER_USB_HAS_SILENT_MODE },
|
||||
.driver_info = (kernel_ulong_t)&kvaser_usb_driver_info_leaf_err_listen },
|
||||
{ USB_DEVICE(KVASER_VENDOR_ID, USB_MEMO2_HSLS_PRODUCT_ID),
|
||||
.driver_info = KVASER_USB_HAS_TXRX_ERRORS },
|
||||
.driver_info = (kernel_ulong_t)&kvaser_usb_driver_info_leaf_err },
|
||||
{ USB_DEVICE(KVASER_VENDOR_ID, USB_LEAF_LITE_CH_PRODUCT_ID),
|
||||
.driver_info = KVASER_USB_HAS_TXRX_ERRORS },
|
||||
.driver_info = (kernel_ulong_t)&kvaser_usb_driver_info_leaf_err },
|
||||
{ USB_DEVICE(KVASER_VENDOR_ID, USB_BLACKBIRD_SPRO_PRODUCT_ID),
|
||||
.driver_info = KVASER_USB_HAS_TXRX_ERRORS },
|
||||
.driver_info = (kernel_ulong_t)&kvaser_usb_driver_info_leaf_err },
|
||||
{ USB_DEVICE(KVASER_VENDOR_ID, USB_OEM_MERCURY_PRODUCT_ID),
|
||||
.driver_info = KVASER_USB_HAS_TXRX_ERRORS },
|
||||
.driver_info = (kernel_ulong_t)&kvaser_usb_driver_info_leaf_err },
|
||||
{ USB_DEVICE(KVASER_VENDOR_ID, USB_OEM_LEAF_PRODUCT_ID),
|
||||
.driver_info = KVASER_USB_HAS_TXRX_ERRORS },
|
||||
.driver_info = (kernel_ulong_t)&kvaser_usb_driver_info_leaf_err },
|
||||
{ USB_DEVICE(KVASER_VENDOR_ID, USB_CAN_R_PRODUCT_ID),
|
||||
.driver_info = KVASER_USB_HAS_TXRX_ERRORS },
|
||||
{ USB_DEVICE(KVASER_VENDOR_ID, USB_LEAF_LITE_V2_PRODUCT_ID) },
|
||||
{ USB_DEVICE(KVASER_VENDOR_ID, USB_MINI_PCIE_HS_PRODUCT_ID) },
|
||||
{ USB_DEVICE(KVASER_VENDOR_ID, USB_LEAF_LIGHT_HS_V2_OEM_PRODUCT_ID) },
|
||||
{ USB_DEVICE(KVASER_VENDOR_ID, USB_USBCAN_LIGHT_2HS_PRODUCT_ID) },
|
||||
{ USB_DEVICE(KVASER_VENDOR_ID, USB_MINI_PCIE_2HS_PRODUCT_ID) },
|
||||
.driver_info = (kernel_ulong_t)&kvaser_usb_driver_info_leaf_err },
|
||||
|
||||
/* Leaf i.MX28 USB product IDs */
|
||||
{ USB_DEVICE(KVASER_VENDOR_ID, USB_LEAF_LITE_V2_PRODUCT_ID),
|
||||
.driver_info = (kernel_ulong_t)&kvaser_usb_driver_info_leafimx },
|
||||
{ USB_DEVICE(KVASER_VENDOR_ID, USB_MINI_PCIE_HS_PRODUCT_ID),
|
||||
.driver_info = (kernel_ulong_t)&kvaser_usb_driver_info_leafimx },
|
||||
{ USB_DEVICE(KVASER_VENDOR_ID, USB_LEAF_LIGHT_HS_V2_OEM_PRODUCT_ID),
|
||||
.driver_info = (kernel_ulong_t)&kvaser_usb_driver_info_leafimx },
|
||||
{ USB_DEVICE(KVASER_VENDOR_ID, USB_USBCAN_LIGHT_2HS_PRODUCT_ID),
|
||||
.driver_info = (kernel_ulong_t)&kvaser_usb_driver_info_leafimx },
|
||||
{ USB_DEVICE(KVASER_VENDOR_ID, USB_MINI_PCIE_2HS_PRODUCT_ID),
|
||||
.driver_info = (kernel_ulong_t)&kvaser_usb_driver_info_leafimx },
|
||||
|
||||
/* USBCANII USB product IDs */
|
||||
{ USB_DEVICE(KVASER_VENDOR_ID, USB_USBCAN2_PRODUCT_ID),
|
||||
.driver_info = KVASER_USB_HAS_TXRX_ERRORS },
|
||||
.driver_info = (kernel_ulong_t)&kvaser_usb_driver_info_usbcan },
|
||||
{ USB_DEVICE(KVASER_VENDOR_ID, USB_USBCAN_REVB_PRODUCT_ID),
|
||||
.driver_info = KVASER_USB_HAS_TXRX_ERRORS },
|
||||
.driver_info = (kernel_ulong_t)&kvaser_usb_driver_info_usbcan },
|
||||
{ USB_DEVICE(KVASER_VENDOR_ID, USB_MEMORATOR_PRODUCT_ID),
|
||||
.driver_info = KVASER_USB_HAS_TXRX_ERRORS },
|
||||
.driver_info = (kernel_ulong_t)&kvaser_usb_driver_info_usbcan },
|
||||
{ USB_DEVICE(KVASER_VENDOR_ID, USB_VCI2_PRODUCT_ID),
|
||||
.driver_info = KVASER_USB_HAS_TXRX_ERRORS },
|
||||
.driver_info = (kernel_ulong_t)&kvaser_usb_driver_info_usbcan },
|
||||
|
||||
/* Minihydra USB product IDs */
|
||||
{ USB_DEVICE(KVASER_VENDOR_ID, USB_BLACKBIRD_V2_PRODUCT_ID) },
|
||||
{ USB_DEVICE(KVASER_VENDOR_ID, USB_MEMO_PRO_5HS_PRODUCT_ID) },
|
||||
{ USB_DEVICE(KVASER_VENDOR_ID, USB_USBCAN_PRO_5HS_PRODUCT_ID) },
|
||||
{ USB_DEVICE(KVASER_VENDOR_ID, USB_USBCAN_LIGHT_4HS_PRODUCT_ID) },
|
||||
{ USB_DEVICE(KVASER_VENDOR_ID, USB_LEAF_PRO_HS_V2_PRODUCT_ID) },
|
||||
{ USB_DEVICE(KVASER_VENDOR_ID, USB_USBCAN_PRO_2HS_V2_PRODUCT_ID) },
|
||||
{ USB_DEVICE(KVASER_VENDOR_ID, USB_MEMO_2HS_PRODUCT_ID) },
|
||||
{ USB_DEVICE(KVASER_VENDOR_ID, USB_MEMO_PRO_2HS_V2_PRODUCT_ID) },
|
||||
{ USB_DEVICE(KVASER_VENDOR_ID, USB_HYBRID_CANLIN_PRODUCT_ID) },
|
||||
{ USB_DEVICE(KVASER_VENDOR_ID, USB_ATI_USBCAN_PRO_2HS_V2_PRODUCT_ID) },
|
||||
{ USB_DEVICE(KVASER_VENDOR_ID, USB_ATI_MEMO_PRO_2HS_V2_PRODUCT_ID) },
|
||||
{ USB_DEVICE(KVASER_VENDOR_ID, USB_HYBRID_PRO_CANLIN_PRODUCT_ID) },
|
||||
{ USB_DEVICE(KVASER_VENDOR_ID, USB_BLACKBIRD_V2_PRODUCT_ID),
|
||||
.driver_info = (kernel_ulong_t)&kvaser_usb_driver_info_hydra },
|
||||
{ USB_DEVICE(KVASER_VENDOR_ID, USB_MEMO_PRO_5HS_PRODUCT_ID),
|
||||
.driver_info = (kernel_ulong_t)&kvaser_usb_driver_info_hydra },
|
||||
{ USB_DEVICE(KVASER_VENDOR_ID, USB_USBCAN_PRO_5HS_PRODUCT_ID),
|
||||
.driver_info = (kernel_ulong_t)&kvaser_usb_driver_info_hydra },
|
||||
{ USB_DEVICE(KVASER_VENDOR_ID, USB_USBCAN_LIGHT_4HS_PRODUCT_ID),
|
||||
.driver_info = (kernel_ulong_t)&kvaser_usb_driver_info_hydra },
|
||||
{ USB_DEVICE(KVASER_VENDOR_ID, USB_LEAF_PRO_HS_V2_PRODUCT_ID),
|
||||
.driver_info = (kernel_ulong_t)&kvaser_usb_driver_info_hydra },
|
||||
{ USB_DEVICE(KVASER_VENDOR_ID, USB_USBCAN_PRO_2HS_V2_PRODUCT_ID),
|
||||
.driver_info = (kernel_ulong_t)&kvaser_usb_driver_info_hydra },
|
||||
{ USB_DEVICE(KVASER_VENDOR_ID, USB_MEMO_2HS_PRODUCT_ID),
|
||||
.driver_info = (kernel_ulong_t)&kvaser_usb_driver_info_hydra },
|
||||
{ USB_DEVICE(KVASER_VENDOR_ID, USB_MEMO_PRO_2HS_V2_PRODUCT_ID),
|
||||
.driver_info = (kernel_ulong_t)&kvaser_usb_driver_info_hydra },
|
||||
{ USB_DEVICE(KVASER_VENDOR_ID, USB_HYBRID_CANLIN_PRODUCT_ID),
|
||||
.driver_info = (kernel_ulong_t)&kvaser_usb_driver_info_hydra },
|
||||
{ USB_DEVICE(KVASER_VENDOR_ID, USB_ATI_USBCAN_PRO_2HS_V2_PRODUCT_ID),
|
||||
.driver_info = (kernel_ulong_t)&kvaser_usb_driver_info_hydra },
|
||||
{ USB_DEVICE(KVASER_VENDOR_ID, USB_ATI_MEMO_PRO_2HS_V2_PRODUCT_ID),
|
||||
.driver_info = (kernel_ulong_t)&kvaser_usb_driver_info_hydra },
|
||||
{ USB_DEVICE(KVASER_VENDOR_ID, USB_HYBRID_PRO_CANLIN_PRODUCT_ID),
|
||||
.driver_info = (kernel_ulong_t)&kvaser_usb_driver_info_hydra },
|
||||
{ }
|
||||
};
|
||||
MODULE_DEVICE_TABLE(usb, kvaser_usb_table);
|
||||
@@ -267,6 +297,7 @@ int kvaser_usb_can_rx_over_error(struct net_device *netdev)
|
||||
static void kvaser_usb_read_bulk_callback(struct urb *urb)
|
||||
{
|
||||
struct kvaser_usb *dev = urb->context;
|
||||
const struct kvaser_usb_dev_ops *ops = dev->driver_info->ops;
|
||||
int err;
|
||||
unsigned int i;
|
||||
|
||||
@@ -283,8 +314,8 @@ static void kvaser_usb_read_bulk_callback(struct urb *urb)
|
||||
goto resubmit_urb;
|
||||
}
|
||||
|
||||
dev->ops->dev_read_bulk_callback(dev, urb->transfer_buffer,
|
||||
urb->actual_length);
|
||||
ops->dev_read_bulk_callback(dev, urb->transfer_buffer,
|
||||
urb->actual_length);
|
||||
|
||||
resubmit_urb:
|
||||
usb_fill_bulk_urb(urb, dev->udev,
|
||||
@@ -378,6 +409,7 @@ static int kvaser_usb_open(struct net_device *netdev)
|
||||
{
|
||||
struct kvaser_usb_net_priv *priv = netdev_priv(netdev);
|
||||
struct kvaser_usb *dev = priv->dev;
|
||||
const struct kvaser_usb_dev_ops *ops = dev->driver_info->ops;
|
||||
int err;
|
||||
|
||||
err = open_candev(netdev);
|
||||
@@ -388,11 +420,11 @@ static int kvaser_usb_open(struct net_device *netdev)
|
||||
if (err)
|
||||
goto error;
|
||||
|
||||
err = dev->ops->dev_set_opt_mode(priv);
|
||||
err = ops->dev_set_opt_mode(priv);
|
||||
if (err)
|
||||
goto error;
|
||||
|
||||
err = dev->ops->dev_start_chip(priv);
|
||||
err = ops->dev_start_chip(priv);
|
||||
if (err) {
|
||||
netdev_warn(netdev, "Cannot start device, error %d\n", err);
|
||||
goto error;
|
||||
@@ -421,7 +453,7 @@ static void kvaser_usb_reset_tx_urb_contexts(struct kvaser_usb_net_priv *priv)
|
||||
/* This method might sleep. Do not call it in the atomic context
|
||||
* of URB completions.
|
||||
*/
|
||||
static void kvaser_usb_unlink_tx_urbs(struct kvaser_usb_net_priv *priv)
|
||||
void kvaser_usb_unlink_tx_urbs(struct kvaser_usb_net_priv *priv)
|
||||
{
|
||||
usb_kill_anchored_urbs(&priv->tx_submitted);
|
||||
kvaser_usb_reset_tx_urb_contexts(priv);
|
||||
@@ -449,22 +481,23 @@ static int kvaser_usb_close(struct net_device *netdev)
|
||||
{
|
||||
struct kvaser_usb_net_priv *priv = netdev_priv(netdev);
|
||||
struct kvaser_usb *dev = priv->dev;
|
||||
const struct kvaser_usb_dev_ops *ops = dev->driver_info->ops;
|
||||
int err;
|
||||
|
||||
netif_stop_queue(netdev);
|
||||
|
||||
err = dev->ops->dev_flush_queue(priv);
|
||||
err = ops->dev_flush_queue(priv);
|
||||
if (err)
|
||||
netdev_warn(netdev, "Cannot flush queue, error %d\n", err);
|
||||
|
||||
if (dev->ops->dev_reset_chip) {
|
||||
err = dev->ops->dev_reset_chip(dev, priv->channel);
|
||||
if (ops->dev_reset_chip) {
|
||||
err = ops->dev_reset_chip(dev, priv->channel);
|
||||
if (err)
|
||||
netdev_warn(netdev, "Cannot reset card, error %d\n",
|
||||
err);
|
||||
}
|
||||
|
||||
err = dev->ops->dev_stop_chip(priv);
|
||||
err = ops->dev_stop_chip(priv);
|
||||
if (err)
|
||||
netdev_warn(netdev, "Cannot stop device, error %d\n", err);
|
||||
|
||||
@@ -503,6 +536,7 @@ static netdev_tx_t kvaser_usb_start_xmit(struct sk_buff *skb,
|
||||
{
|
||||
struct kvaser_usb_net_priv *priv = netdev_priv(netdev);
|
||||
struct kvaser_usb *dev = priv->dev;
|
||||
const struct kvaser_usb_dev_ops *ops = dev->driver_info->ops;
|
||||
struct net_device_stats *stats = &netdev->stats;
|
||||
struct kvaser_usb_tx_urb_context *context = NULL;
|
||||
struct urb *urb;
|
||||
@@ -545,8 +579,8 @@ static netdev_tx_t kvaser_usb_start_xmit(struct sk_buff *skb,
|
||||
goto freeurb;
|
||||
}
|
||||
|
||||
buf = dev->ops->dev_frame_to_cmd(priv, skb, &context->dlc, &cmd_len,
|
||||
context->echo_index);
|
||||
buf = ops->dev_frame_to_cmd(priv, skb, &context->dlc, &cmd_len,
|
||||
context->echo_index);
|
||||
if (!buf) {
|
||||
stats->tx_dropped++;
|
||||
dev_kfree_skb(skb);
|
||||
@@ -630,15 +664,16 @@ static void kvaser_usb_remove_interfaces(struct kvaser_usb *dev)
|
||||
}
|
||||
}
|
||||
|
||||
static int kvaser_usb_init_one(struct kvaser_usb *dev,
|
||||
const struct usb_device_id *id, int channel)
|
||||
static int kvaser_usb_init_one(struct kvaser_usb *dev, int channel)
|
||||
{
|
||||
struct net_device *netdev;
|
||||
struct kvaser_usb_net_priv *priv;
|
||||
const struct kvaser_usb_driver_info *driver_info = dev->driver_info;
|
||||
const struct kvaser_usb_dev_ops *ops = driver_info->ops;
|
||||
int err;
|
||||
|
||||
if (dev->ops->dev_reset_chip) {
|
||||
err = dev->ops->dev_reset_chip(dev, channel);
|
||||
if (ops->dev_reset_chip) {
|
||||
err = ops->dev_reset_chip(dev, channel);
|
||||
if (err)
|
||||
return err;
|
||||
}
|
||||
@@ -655,6 +690,7 @@ static int kvaser_usb_init_one(struct kvaser_usb *dev,
|
||||
init_usb_anchor(&priv->tx_submitted);
|
||||
init_completion(&priv->start_comp);
|
||||
init_completion(&priv->stop_comp);
|
||||
init_completion(&priv->flush_comp);
|
||||
priv->can.ctrlmode_supported = 0;
|
||||
|
||||
priv->dev = dev;
|
||||
@@ -667,20 +703,19 @@ static int kvaser_usb_init_one(struct kvaser_usb *dev,
|
||||
priv->can.state = CAN_STATE_STOPPED;
|
||||
priv->can.clock.freq = dev->cfg->clock.freq;
|
||||
priv->can.bittiming_const = dev->cfg->bittiming_const;
|
||||
priv->can.do_set_bittiming = dev->ops->dev_set_bittiming;
|
||||
priv->can.do_set_mode = dev->ops->dev_set_mode;
|
||||
if ((id->driver_info & KVASER_USB_HAS_TXRX_ERRORS) ||
|
||||
priv->can.do_set_bittiming = ops->dev_set_bittiming;
|
||||
priv->can.do_set_mode = ops->dev_set_mode;
|
||||
if ((driver_info->quirks & KVASER_USB_QUIRK_HAS_TXRX_ERRORS) ||
|
||||
(priv->dev->card_data.capabilities & KVASER_USB_CAP_BERR_CAP))
|
||||
priv->can.do_get_berr_counter = dev->ops->dev_get_berr_counter;
|
||||
if (id->driver_info & KVASER_USB_HAS_SILENT_MODE)
|
||||
priv->can.do_get_berr_counter = ops->dev_get_berr_counter;
|
||||
if (driver_info->quirks & KVASER_USB_QUIRK_HAS_SILENT_MODE)
|
||||
priv->can.ctrlmode_supported |= CAN_CTRLMODE_LISTENONLY;
|
||||
|
||||
priv->can.ctrlmode_supported |= dev->card_data.ctrlmode_supported;
|
||||
|
||||
if (priv->can.ctrlmode_supported & CAN_CTRLMODE_FD) {
|
||||
priv->can.data_bittiming_const = dev->cfg->data_bittiming_const;
|
||||
priv->can.do_set_data_bittiming =
|
||||
dev->ops->dev_set_data_bittiming;
|
||||
priv->can.do_set_data_bittiming = ops->dev_set_data_bittiming;
|
||||
}
|
||||
|
||||
netdev->flags |= IFF_ECHO;
|
||||
@@ -711,29 +746,22 @@ static int kvaser_usb_probe(struct usb_interface *intf,
|
||||
struct kvaser_usb *dev;
|
||||
int err;
|
||||
int i;
|
||||
const struct kvaser_usb_driver_info *driver_info;
|
||||
const struct kvaser_usb_dev_ops *ops;
|
||||
|
||||
driver_info = (const struct kvaser_usb_driver_info *)id->driver_info;
|
||||
if (!driver_info)
|
||||
return -ENODEV;
|
||||
|
||||
dev = devm_kzalloc(&intf->dev, sizeof(*dev), GFP_KERNEL);
|
||||
if (!dev)
|
||||
return -ENOMEM;
|
||||
|
||||
if (kvaser_is_leaf(id)) {
|
||||
dev->card_data.leaf.family = KVASER_LEAF;
|
||||
dev->ops = &kvaser_usb_leaf_dev_ops;
|
||||
} else if (kvaser_is_usbcan(id)) {
|
||||
dev->card_data.leaf.family = KVASER_USBCAN;
|
||||
dev->ops = &kvaser_usb_leaf_dev_ops;
|
||||
} else if (kvaser_is_hydra(id)) {
|
||||
dev->ops = &kvaser_usb_hydra_dev_ops;
|
||||
} else {
|
||||
dev_err(&intf->dev,
|
||||
"Product ID (%d) is not a supported Kvaser USB device\n",
|
||||
id->idProduct);
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
dev->intf = intf;
|
||||
dev->driver_info = driver_info;
|
||||
ops = driver_info->ops;
|
||||
|
||||
err = dev->ops->dev_setup_endpoints(dev);
|
||||
err = ops->dev_setup_endpoints(dev);
|
||||
if (err) {
|
||||
dev_err(&intf->dev, "Cannot get usb endpoint(s)");
|
||||
return err;
|
||||
@@ -747,22 +775,22 @@ static int kvaser_usb_probe(struct usb_interface *intf,
|
||||
|
||||
dev->card_data.ctrlmode_supported = 0;
|
||||
dev->card_data.capabilities = 0;
|
||||
err = dev->ops->dev_init_card(dev);
|
||||
err = ops->dev_init_card(dev);
|
||||
if (err) {
|
||||
dev_err(&intf->dev,
|
||||
"Failed to initialize card, error %d\n", err);
|
||||
return err;
|
||||
}
|
||||
|
||||
err = dev->ops->dev_get_software_info(dev);
|
||||
err = ops->dev_get_software_info(dev);
|
||||
if (err) {
|
||||
dev_err(&intf->dev,
|
||||
"Cannot get software info, error %d\n", err);
|
||||
return err;
|
||||
}
|
||||
|
||||
if (dev->ops->dev_get_software_details) {
|
||||
err = dev->ops->dev_get_software_details(dev);
|
||||
if (ops->dev_get_software_details) {
|
||||
err = ops->dev_get_software_details(dev);
|
||||
if (err) {
|
||||
dev_err(&intf->dev,
|
||||
"Cannot get software details, error %d\n", err);
|
||||
@@ -780,14 +808,14 @@ static int kvaser_usb_probe(struct usb_interface *intf,
|
||||
|
||||
dev_dbg(&intf->dev, "Max outstanding tx = %d URBs\n", dev->max_tx_urbs);
|
||||
|
||||
err = dev->ops->dev_get_card_info(dev);
|
||||
err = ops->dev_get_card_info(dev);
|
||||
if (err) {
|
||||
dev_err(&intf->dev, "Cannot get card info, error %d\n", err);
|
||||
return err;
|
||||
}
|
||||
|
||||
if (dev->ops->dev_get_capabilities) {
|
||||
err = dev->ops->dev_get_capabilities(dev);
|
||||
if (ops->dev_get_capabilities) {
|
||||
err = ops->dev_get_capabilities(dev);
|
||||
if (err) {
|
||||
dev_err(&intf->dev,
|
||||
"Cannot get capabilities, error %d\n", err);
|
||||
@@ -797,7 +825,7 @@ static int kvaser_usb_probe(struct usb_interface *intf,
|
||||
}
|
||||
|
||||
for (i = 0; i < dev->nchannels; i++) {
|
||||
err = kvaser_usb_init_one(dev, id, i);
|
||||
err = kvaser_usb_init_one(dev, i);
|
||||
if (err) {
|
||||
kvaser_usb_remove_interfaces(dev);
|
||||
return err;
|
||||
|
||||
@@ -371,7 +371,7 @@ static const struct can_bittiming_const kvaser_usb_hydra_kcan_bittiming_c = {
|
||||
.brp_inc = 1,
|
||||
};
|
||||
|
||||
static const struct can_bittiming_const kvaser_usb_hydra_flexc_bittiming_c = {
|
||||
const struct can_bittiming_const kvaser_usb_flexc_bittiming_const = {
|
||||
.name = "kvaser_usb_flex",
|
||||
.tseg1_min = 4,
|
||||
.tseg1_max = 16,
|
||||
@@ -890,8 +890,10 @@ static void kvaser_usb_hydra_update_state(struct kvaser_usb_net_priv *priv,
|
||||
new_state < CAN_STATE_BUS_OFF)
|
||||
priv->can.can_stats.restarts++;
|
||||
|
||||
cf->data[6] = bec->txerr;
|
||||
cf->data[7] = bec->rxerr;
|
||||
if (new_state != CAN_STATE_BUS_OFF) {
|
||||
cf->data[6] = bec->txerr;
|
||||
cf->data[7] = bec->rxerr;
|
||||
}
|
||||
|
||||
stats = &netdev->stats;
|
||||
stats->rx_packets++;
|
||||
@@ -1045,8 +1047,10 @@ kvaser_usb_hydra_error_frame(struct kvaser_usb_net_priv *priv,
|
||||
shhwtstamps->hwtstamp = hwtstamp;
|
||||
|
||||
cf->can_id |= CAN_ERR_BUSERROR;
|
||||
cf->data[6] = bec.txerr;
|
||||
cf->data[7] = bec.rxerr;
|
||||
if (new_state != CAN_STATE_BUS_OFF) {
|
||||
cf->data[6] = bec.txerr;
|
||||
cf->data[7] = bec.rxerr;
|
||||
}
|
||||
|
||||
stats->rx_packets++;
|
||||
stats->rx_bytes += cf->can_dlc;
|
||||
@@ -1841,7 +1845,7 @@ static int kvaser_usb_hydra_start_chip(struct kvaser_usb_net_priv *priv)
|
||||
{
|
||||
int err;
|
||||
|
||||
init_completion(&priv->start_comp);
|
||||
reinit_completion(&priv->start_comp);
|
||||
|
||||
err = kvaser_usb_hydra_send_simple_cmd(priv->dev, CMD_START_CHIP_REQ,
|
||||
priv->channel);
|
||||
@@ -1859,7 +1863,7 @@ static int kvaser_usb_hydra_stop_chip(struct kvaser_usb_net_priv *priv)
|
||||
{
|
||||
int err;
|
||||
|
||||
init_completion(&priv->stop_comp);
|
||||
reinit_completion(&priv->stop_comp);
|
||||
|
||||
/* Make sure we do not report invalid BUS_OFF from CMD_CHIP_STATE_EVENT
|
||||
* see comment in kvaser_usb_hydra_update_state()
|
||||
@@ -1882,7 +1886,7 @@ static int kvaser_usb_hydra_flush_queue(struct kvaser_usb_net_priv *priv)
|
||||
{
|
||||
int err;
|
||||
|
||||
init_completion(&priv->flush_comp);
|
||||
reinit_completion(&priv->flush_comp);
|
||||
|
||||
err = kvaser_usb_hydra_send_simple_cmd(priv->dev, CMD_FLUSH_QUEUE,
|
||||
priv->channel);
|
||||
@@ -2024,5 +2028,5 @@ static const struct kvaser_usb_dev_cfg kvaser_usb_hydra_dev_cfg_flexc = {
|
||||
.freq = 24000000,
|
||||
},
|
||||
.timestamp_freq = 1,
|
||||
.bittiming_const = &kvaser_usb_hydra_flexc_bittiming_c,
|
||||
.bittiming_const = &kvaser_usb_flexc_bittiming_const,
|
||||
};
|
||||
|
||||
@@ -100,16 +100,6 @@
|
||||
#define USBCAN_ERROR_STATE_RX_ERROR BIT(1)
|
||||
#define USBCAN_ERROR_STATE_BUSERROR BIT(2)
|
||||
|
||||
/* bittiming parameters */
|
||||
#define KVASER_USB_TSEG1_MIN 1
|
||||
#define KVASER_USB_TSEG1_MAX 16
|
||||
#define KVASER_USB_TSEG2_MIN 1
|
||||
#define KVASER_USB_TSEG2_MAX 8
|
||||
#define KVASER_USB_SJW_MAX 4
|
||||
#define KVASER_USB_BRP_MIN 1
|
||||
#define KVASER_USB_BRP_MAX 64
|
||||
#define KVASER_USB_BRP_INC 1
|
||||
|
||||
/* ctrl modes */
|
||||
#define KVASER_CTRL_MODE_NORMAL 1
|
||||
#define KVASER_CTRL_MODE_SILENT 2
|
||||
@@ -319,6 +309,38 @@ struct kvaser_cmd {
|
||||
} u;
|
||||
} __packed;
|
||||
|
||||
#define CMD_SIZE_ANY 0xff
|
||||
#define kvaser_fsize(field) sizeof_field(struct kvaser_cmd, field)
|
||||
|
||||
static const u8 kvaser_usb_leaf_cmd_sizes_leaf[] = {
|
||||
[CMD_START_CHIP_REPLY] = kvaser_fsize(u.simple),
|
||||
[CMD_STOP_CHIP_REPLY] = kvaser_fsize(u.simple),
|
||||
[CMD_GET_CARD_INFO_REPLY] = kvaser_fsize(u.cardinfo),
|
||||
[CMD_TX_ACKNOWLEDGE] = kvaser_fsize(u.tx_acknowledge_header),
|
||||
[CMD_GET_SOFTWARE_INFO_REPLY] = kvaser_fsize(u.leaf.softinfo),
|
||||
[CMD_RX_STD_MESSAGE] = kvaser_fsize(u.leaf.rx_can),
|
||||
[CMD_RX_EXT_MESSAGE] = kvaser_fsize(u.leaf.rx_can),
|
||||
[CMD_LEAF_LOG_MESSAGE] = kvaser_fsize(u.leaf.log_message),
|
||||
[CMD_CHIP_STATE_EVENT] = kvaser_fsize(u.leaf.chip_state_event),
|
||||
[CMD_CAN_ERROR_EVENT] = kvaser_fsize(u.leaf.error_event),
|
||||
/* ignored events: */
|
||||
[CMD_FLUSH_QUEUE_REPLY] = CMD_SIZE_ANY,
|
||||
};
|
||||
|
||||
static const u8 kvaser_usb_leaf_cmd_sizes_usbcan[] = {
|
||||
[CMD_START_CHIP_REPLY] = kvaser_fsize(u.simple),
|
||||
[CMD_STOP_CHIP_REPLY] = kvaser_fsize(u.simple),
|
||||
[CMD_GET_CARD_INFO_REPLY] = kvaser_fsize(u.cardinfo),
|
||||
[CMD_TX_ACKNOWLEDGE] = kvaser_fsize(u.tx_acknowledge_header),
|
||||
[CMD_GET_SOFTWARE_INFO_REPLY] = kvaser_fsize(u.usbcan.softinfo),
|
||||
[CMD_RX_STD_MESSAGE] = kvaser_fsize(u.usbcan.rx_can),
|
||||
[CMD_RX_EXT_MESSAGE] = kvaser_fsize(u.usbcan.rx_can),
|
||||
[CMD_CHIP_STATE_EVENT] = kvaser_fsize(u.usbcan.chip_state_event),
|
||||
[CMD_CAN_ERROR_EVENT] = kvaser_fsize(u.usbcan.error_event),
|
||||
/* ignored events: */
|
||||
[CMD_USBCAN_CLOCK_OVERFLOW_EVENT] = CMD_SIZE_ANY,
|
||||
};
|
||||
|
||||
/* Summary of a kvaser error event, for a unified Leaf/Usbcan error
|
||||
* handling. Some discrepancies between the two families exist:
|
||||
*
|
||||
@@ -342,50 +364,107 @@ struct kvaser_usb_err_summary {
|
||||
};
|
||||
};
|
||||
|
||||
static const struct can_bittiming_const kvaser_usb_leaf_bittiming_const = {
|
||||
.name = "kvaser_usb",
|
||||
.tseg1_min = KVASER_USB_TSEG1_MIN,
|
||||
.tseg1_max = KVASER_USB_TSEG1_MAX,
|
||||
.tseg2_min = KVASER_USB_TSEG2_MIN,
|
||||
.tseg2_max = KVASER_USB_TSEG2_MAX,
|
||||
.sjw_max = KVASER_USB_SJW_MAX,
|
||||
.brp_min = KVASER_USB_BRP_MIN,
|
||||
.brp_max = KVASER_USB_BRP_MAX,
|
||||
.brp_inc = KVASER_USB_BRP_INC,
|
||||
static const struct can_bittiming_const kvaser_usb_leaf_m16c_bittiming_const = {
|
||||
.name = "kvaser_usb_ucii",
|
||||
.tseg1_min = 4,
|
||||
.tseg1_max = 16,
|
||||
.tseg2_min = 2,
|
||||
.tseg2_max = 8,
|
||||
.sjw_max = 4,
|
||||
.brp_min = 1,
|
||||
.brp_max = 16,
|
||||
.brp_inc = 1,
|
||||
};
|
||||
|
||||
static const struct kvaser_usb_dev_cfg kvaser_usb_leaf_dev_cfg_8mhz = {
|
||||
static const struct can_bittiming_const kvaser_usb_leaf_m32c_bittiming_const = {
|
||||
.name = "kvaser_usb_leaf",
|
||||
.tseg1_min = 3,
|
||||
.tseg1_max = 16,
|
||||
.tseg2_min = 2,
|
||||
.tseg2_max = 8,
|
||||
.sjw_max = 4,
|
||||
.brp_min = 2,
|
||||
.brp_max = 128,
|
||||
.brp_inc = 2,
|
||||
};
|
||||
|
||||
static const struct kvaser_usb_dev_cfg kvaser_usb_leaf_usbcan_dev_cfg = {
|
||||
.clock = {
|
||||
.freq = 8000000,
|
||||
},
|
||||
.timestamp_freq = 1,
|
||||
.bittiming_const = &kvaser_usb_leaf_bittiming_const,
|
||||
.bittiming_const = &kvaser_usb_leaf_m16c_bittiming_const,
|
||||
};
|
||||
|
||||
static const struct kvaser_usb_dev_cfg kvaser_usb_leaf_dev_cfg_16mhz = {
|
||||
static const struct kvaser_usb_dev_cfg kvaser_usb_leaf_m32c_dev_cfg = {
|
||||
.clock = {
|
||||
.freq = 16000000,
|
||||
},
|
||||
.timestamp_freq = 1,
|
||||
.bittiming_const = &kvaser_usb_leaf_bittiming_const,
|
||||
.bittiming_const = &kvaser_usb_leaf_m32c_bittiming_const,
|
||||
};
|
||||
|
||||
static const struct kvaser_usb_dev_cfg kvaser_usb_leaf_dev_cfg_24mhz = {
|
||||
static const struct kvaser_usb_dev_cfg kvaser_usb_leaf_imx_dev_cfg_16mhz = {
|
||||
.clock = {
|
||||
.freq = 16000000,
|
||||
},
|
||||
.timestamp_freq = 1,
|
||||
.bittiming_const = &kvaser_usb_flexc_bittiming_const,
|
||||
};
|
||||
|
||||
static const struct kvaser_usb_dev_cfg kvaser_usb_leaf_imx_dev_cfg_24mhz = {
|
||||
.clock = {
|
||||
.freq = 24000000,
|
||||
},
|
||||
.timestamp_freq = 1,
|
||||
.bittiming_const = &kvaser_usb_leaf_bittiming_const,
|
||||
.bittiming_const = &kvaser_usb_flexc_bittiming_const,
|
||||
};
|
||||
|
||||
static const struct kvaser_usb_dev_cfg kvaser_usb_leaf_dev_cfg_32mhz = {
|
||||
static const struct kvaser_usb_dev_cfg kvaser_usb_leaf_imx_dev_cfg_32mhz = {
|
||||
.clock = {
|
||||
.freq = 32000000,
|
||||
},
|
||||
.timestamp_freq = 1,
|
||||
.bittiming_const = &kvaser_usb_leaf_bittiming_const,
|
||||
.bittiming_const = &kvaser_usb_flexc_bittiming_const,
|
||||
};
|
||||
|
||||
static int kvaser_usb_leaf_verify_size(const struct kvaser_usb *dev,
|
||||
const struct kvaser_cmd *cmd)
|
||||
{
|
||||
/* buffer size >= cmd->len ensured by caller */
|
||||
u8 min_size = 0;
|
||||
|
||||
switch (dev->driver_info->family) {
|
||||
case KVASER_LEAF:
|
||||
if (cmd->id < ARRAY_SIZE(kvaser_usb_leaf_cmd_sizes_leaf))
|
||||
min_size = kvaser_usb_leaf_cmd_sizes_leaf[cmd->id];
|
||||
break;
|
||||
case KVASER_USBCAN:
|
||||
if (cmd->id < ARRAY_SIZE(kvaser_usb_leaf_cmd_sizes_usbcan))
|
||||
min_size = kvaser_usb_leaf_cmd_sizes_usbcan[cmd->id];
|
||||
break;
|
||||
}
|
||||
|
||||
if (min_size == CMD_SIZE_ANY)
|
||||
return 0;
|
||||
|
||||
if (min_size) {
|
||||
min_size += CMD_HEADER_LEN;
|
||||
if (cmd->len >= min_size)
|
||||
return 0;
|
||||
|
||||
dev_err_ratelimited(&dev->intf->dev,
|
||||
"Received command %u too short (size %u, needed %u)",
|
||||
cmd->id, cmd->len, min_size);
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
dev_warn_ratelimited(&dev->intf->dev,
|
||||
"Unhandled command (%d, size %d)\n",
|
||||
cmd->id, cmd->len);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
static void *
|
||||
kvaser_usb_leaf_frame_to_cmd(const struct kvaser_usb_net_priv *priv,
|
||||
const struct sk_buff *skb, int *frame_len,
|
||||
@@ -405,7 +484,7 @@ kvaser_usb_leaf_frame_to_cmd(const struct kvaser_usb_net_priv *priv,
|
||||
sizeof(struct kvaser_cmd_tx_can);
|
||||
cmd->u.tx_can.channel = priv->channel;
|
||||
|
||||
switch (dev->card_data.leaf.family) {
|
||||
switch (dev->driver_info->family) {
|
||||
case KVASER_LEAF:
|
||||
cmd_tx_can_flags = &cmd->u.tx_can.leaf.flags;
|
||||
break;
|
||||
@@ -493,6 +572,9 @@ static int kvaser_usb_leaf_wait_cmd(const struct kvaser_usb *dev, u8 id,
|
||||
end:
|
||||
kfree(buf);
|
||||
|
||||
if (err == 0)
|
||||
err = kvaser_usb_leaf_verify_size(dev, cmd);
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
@@ -525,16 +607,23 @@ static void kvaser_usb_leaf_get_software_info_leaf(struct kvaser_usb *dev,
|
||||
dev->fw_version = le32_to_cpu(softinfo->fw_version);
|
||||
dev->max_tx_urbs = le16_to_cpu(softinfo->max_outstanding_tx);
|
||||
|
||||
switch (sw_options & KVASER_USB_LEAF_SWOPTION_FREQ_MASK) {
|
||||
case KVASER_USB_LEAF_SWOPTION_FREQ_16_MHZ_CLK:
|
||||
dev->cfg = &kvaser_usb_leaf_dev_cfg_16mhz;
|
||||
break;
|
||||
case KVASER_USB_LEAF_SWOPTION_FREQ_24_MHZ_CLK:
|
||||
dev->cfg = &kvaser_usb_leaf_dev_cfg_24mhz;
|
||||
break;
|
||||
case KVASER_USB_LEAF_SWOPTION_FREQ_32_MHZ_CLK:
|
||||
dev->cfg = &kvaser_usb_leaf_dev_cfg_32mhz;
|
||||
break;
|
||||
if (dev->driver_info->quirks & KVASER_USB_QUIRK_IGNORE_CLK_FREQ) {
|
||||
/* Firmware expects bittiming parameters calculated for 16MHz
|
||||
* clock, regardless of the actual clock
|
||||
*/
|
||||
dev->cfg = &kvaser_usb_leaf_m32c_dev_cfg;
|
||||
} else {
|
||||
switch (sw_options & KVASER_USB_LEAF_SWOPTION_FREQ_MASK) {
|
||||
case KVASER_USB_LEAF_SWOPTION_FREQ_16_MHZ_CLK:
|
||||
dev->cfg = &kvaser_usb_leaf_imx_dev_cfg_16mhz;
|
||||
break;
|
||||
case KVASER_USB_LEAF_SWOPTION_FREQ_24_MHZ_CLK:
|
||||
dev->cfg = &kvaser_usb_leaf_imx_dev_cfg_24mhz;
|
||||
break;
|
||||
case KVASER_USB_LEAF_SWOPTION_FREQ_32_MHZ_CLK:
|
||||
dev->cfg = &kvaser_usb_leaf_imx_dev_cfg_32mhz;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -551,7 +640,7 @@ static int kvaser_usb_leaf_get_software_info_inner(struct kvaser_usb *dev)
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
switch (dev->card_data.leaf.family) {
|
||||
switch (dev->driver_info->family) {
|
||||
case KVASER_LEAF:
|
||||
kvaser_usb_leaf_get_software_info_leaf(dev, &cmd.u.leaf.softinfo);
|
||||
break;
|
||||
@@ -559,7 +648,7 @@ static int kvaser_usb_leaf_get_software_info_inner(struct kvaser_usb *dev)
|
||||
dev->fw_version = le32_to_cpu(cmd.u.usbcan.softinfo.fw_version);
|
||||
dev->max_tx_urbs =
|
||||
le16_to_cpu(cmd.u.usbcan.softinfo.max_outstanding_tx);
|
||||
dev->cfg = &kvaser_usb_leaf_dev_cfg_8mhz;
|
||||
dev->cfg = &kvaser_usb_leaf_usbcan_dev_cfg;
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -598,7 +687,7 @@ static int kvaser_usb_leaf_get_card_info(struct kvaser_usb *dev)
|
||||
|
||||
dev->nchannels = cmd.u.cardinfo.nchannels;
|
||||
if (dev->nchannels > KVASER_USB_MAX_NET_DEVICES ||
|
||||
(dev->card_data.leaf.family == KVASER_USBCAN &&
|
||||
(dev->driver_info->family == KVASER_USBCAN &&
|
||||
dev->nchannels > MAX_USBCAN_NET_DEVICES))
|
||||
return -EINVAL;
|
||||
|
||||
@@ -734,7 +823,7 @@ kvaser_usb_leaf_rx_error_update_can_state(struct kvaser_usb_net_priv *priv,
|
||||
new_state < CAN_STATE_BUS_OFF)
|
||||
priv->can.can_stats.restarts++;
|
||||
|
||||
switch (dev->card_data.leaf.family) {
|
||||
switch (dev->driver_info->family) {
|
||||
case KVASER_LEAF:
|
||||
if (es->leaf.error_factor) {
|
||||
priv->can.can_stats.bus_error++;
|
||||
@@ -813,7 +902,7 @@ static void kvaser_usb_leaf_rx_error(const struct kvaser_usb *dev,
|
||||
}
|
||||
}
|
||||
|
||||
switch (dev->card_data.leaf.family) {
|
||||
switch (dev->driver_info->family) {
|
||||
case KVASER_LEAF:
|
||||
if (es->leaf.error_factor) {
|
||||
cf->can_id |= CAN_ERR_BUSERROR | CAN_ERR_PROT;
|
||||
@@ -840,8 +929,10 @@ static void kvaser_usb_leaf_rx_error(const struct kvaser_usb *dev,
|
||||
break;
|
||||
}
|
||||
|
||||
cf->data[6] = es->txerr;
|
||||
cf->data[7] = es->rxerr;
|
||||
if (new_state != CAN_STATE_BUS_OFF) {
|
||||
cf->data[6] = es->txerr;
|
||||
cf->data[7] = es->rxerr;
|
||||
}
|
||||
|
||||
stats->rx_packets++;
|
||||
stats->rx_bytes += cf->can_dlc;
|
||||
@@ -1005,7 +1096,7 @@ static void kvaser_usb_leaf_rx_can_msg(const struct kvaser_usb *dev,
|
||||
stats = &priv->netdev->stats;
|
||||
|
||||
if ((cmd->u.rx_can_header.flag & MSG_FLAG_ERROR_FRAME) &&
|
||||
(dev->card_data.leaf.family == KVASER_LEAF &&
|
||||
(dev->driver_info->family == KVASER_LEAF &&
|
||||
cmd->id == CMD_LEAF_LOG_MESSAGE)) {
|
||||
kvaser_usb_leaf_leaf_rx_error(dev, cmd);
|
||||
return;
|
||||
@@ -1021,7 +1112,7 @@ static void kvaser_usb_leaf_rx_can_msg(const struct kvaser_usb *dev,
|
||||
return;
|
||||
}
|
||||
|
||||
switch (dev->card_data.leaf.family) {
|
||||
switch (dev->driver_info->family) {
|
||||
case KVASER_LEAF:
|
||||
rx_data = cmd->u.leaf.rx_can.data;
|
||||
break;
|
||||
@@ -1036,7 +1127,7 @@ static void kvaser_usb_leaf_rx_can_msg(const struct kvaser_usb *dev,
|
||||
return;
|
||||
}
|
||||
|
||||
if (dev->card_data.leaf.family == KVASER_LEAF && cmd->id ==
|
||||
if (dev->driver_info->family == KVASER_LEAF && cmd->id ==
|
||||
CMD_LEAF_LOG_MESSAGE) {
|
||||
cf->can_id = le32_to_cpu(cmd->u.leaf.log_message.id);
|
||||
if (cf->can_id & KVASER_EXTENDED_FRAME)
|
||||
@@ -1118,6 +1209,9 @@ static void kvaser_usb_leaf_stop_chip_reply(const struct kvaser_usb *dev,
|
||||
static void kvaser_usb_leaf_handle_command(const struct kvaser_usb *dev,
|
||||
const struct kvaser_cmd *cmd)
|
||||
{
|
||||
if (kvaser_usb_leaf_verify_size(dev, cmd) < 0)
|
||||
return;
|
||||
|
||||
switch (cmd->id) {
|
||||
case CMD_START_CHIP_REPLY:
|
||||
kvaser_usb_leaf_start_chip_reply(dev, cmd);
|
||||
@@ -1133,14 +1227,14 @@ static void kvaser_usb_leaf_handle_command(const struct kvaser_usb *dev,
|
||||
break;
|
||||
|
||||
case CMD_LEAF_LOG_MESSAGE:
|
||||
if (dev->card_data.leaf.family != KVASER_LEAF)
|
||||
if (dev->driver_info->family != KVASER_LEAF)
|
||||
goto warn;
|
||||
kvaser_usb_leaf_rx_can_msg(dev, cmd);
|
||||
break;
|
||||
|
||||
case CMD_CHIP_STATE_EVENT:
|
||||
case CMD_CAN_ERROR_EVENT:
|
||||
if (dev->card_data.leaf.family == KVASER_LEAF)
|
||||
if (dev->driver_info->family == KVASER_LEAF)
|
||||
kvaser_usb_leaf_leaf_rx_error(dev, cmd);
|
||||
else
|
||||
kvaser_usb_leaf_usbcan_rx_error(dev, cmd);
|
||||
@@ -1152,12 +1246,12 @@ static void kvaser_usb_leaf_handle_command(const struct kvaser_usb *dev,
|
||||
|
||||
/* Ignored commands */
|
||||
case CMD_USBCAN_CLOCK_OVERFLOW_EVENT:
|
||||
if (dev->card_data.leaf.family != KVASER_USBCAN)
|
||||
if (dev->driver_info->family != KVASER_USBCAN)
|
||||
goto warn;
|
||||
break;
|
||||
|
||||
case CMD_FLUSH_QUEUE_REPLY:
|
||||
if (dev->card_data.leaf.family != KVASER_LEAF)
|
||||
if (dev->driver_info->family != KVASER_LEAF)
|
||||
goto warn;
|
||||
break;
|
||||
|
||||
@@ -1230,7 +1324,7 @@ static int kvaser_usb_leaf_start_chip(struct kvaser_usb_net_priv *priv)
|
||||
{
|
||||
int err;
|
||||
|
||||
init_completion(&priv->start_comp);
|
||||
reinit_completion(&priv->start_comp);
|
||||
|
||||
err = kvaser_usb_leaf_send_simple_cmd(priv->dev, CMD_START_CHIP,
|
||||
priv->channel);
|
||||
@@ -1248,7 +1342,7 @@ static int kvaser_usb_leaf_stop_chip(struct kvaser_usb_net_priv *priv)
|
||||
{
|
||||
int err;
|
||||
|
||||
init_completion(&priv->stop_comp);
|
||||
reinit_completion(&priv->stop_comp);
|
||||
|
||||
err = kvaser_usb_leaf_send_simple_cmd(priv->dev, CMD_STOP_CHIP,
|
||||
priv->channel);
|
||||
@@ -1336,9 +1430,13 @@ static int kvaser_usb_leaf_set_mode(struct net_device *netdev,
|
||||
|
||||
switch (mode) {
|
||||
case CAN_MODE_START:
|
||||
kvaser_usb_unlink_tx_urbs(priv);
|
||||
|
||||
err = kvaser_usb_leaf_simple_cmd_async(priv, CMD_START_CHIP);
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
priv->can.state = CAN_STATE_ERROR_ACTIVE;
|
||||
break;
|
||||
default:
|
||||
return -EOPNOTSUPP;
|
||||
|
||||
@@ -47,6 +47,10 @@
|
||||
#define MCBA_VER_REQ_USB 1
|
||||
#define MCBA_VER_REQ_CAN 2
|
||||
|
||||
/* Drive the CAN_RES signal LOW "0" to activate R24 and R25 */
|
||||
#define MCBA_VER_TERMINATION_ON 0
|
||||
#define MCBA_VER_TERMINATION_OFF 1
|
||||
|
||||
#define MCBA_SIDL_EXID_MASK 0x8
|
||||
#define MCBA_DLC_MASK 0xf
|
||||
#define MCBA_DLC_RTR_MASK 0x40
|
||||
@@ -469,7 +473,7 @@ static void mcba_usb_process_ka_usb(struct mcba_priv *priv,
|
||||
priv->usb_ka_first_pass = false;
|
||||
}
|
||||
|
||||
if (msg->termination_state)
|
||||
if (msg->termination_state == MCBA_VER_TERMINATION_ON)
|
||||
priv->can.termination = MCBA_TERMINATION_ENABLED;
|
||||
else
|
||||
priv->can.termination = MCBA_TERMINATION_DISABLED;
|
||||
@@ -789,9 +793,9 @@ static int mcba_set_termination(struct net_device *netdev, u16 term)
|
||||
};
|
||||
|
||||
if (term == MCBA_TERMINATION_ENABLED)
|
||||
usb_msg.termination = 1;
|
||||
usb_msg.termination = MCBA_VER_TERMINATION_ON;
|
||||
else
|
||||
usb_msg.termination = 0;
|
||||
usb_msg.termination = MCBA_VER_TERMINATION_OFF;
|
||||
|
||||
mcba_usb_xmit_cmd(priv, (struct mcba_usb_msg *)&usb_msg);
|
||||
|
||||
|
||||
@@ -442,9 +442,10 @@ static void usb_8dev_rx_err_msg(struct usb_8dev_priv *priv,
|
||||
|
||||
if (rx_errors)
|
||||
stats->rx_errors++;
|
||||
|
||||
cf->data[6] = txerr;
|
||||
cf->data[7] = rxerr;
|
||||
if (priv->can.state != CAN_STATE_BUS_OFF) {
|
||||
cf->data[6] = txerr;
|
||||
cf->data[7] = rxerr;
|
||||
}
|
||||
|
||||
priv->bec.txerr = txerr;
|
||||
priv->bec.rxerr = rxerr;
|
||||
|
||||
Reference in New Issue
Block a user