linux/drivers/net/can/usb/peak_usb/pcan_usb_core.h
<<
>>
Prefs
   1/*
   2 * CAN driver for PEAK System USB adapters
   3 * Derived from the PCAN project file driver/src/pcan_usb_core.c
   4 *
   5 * Copyright (C) 2003-2010 PEAK System-Technik GmbH
   6 * Copyright (C) 2010-2012 Stephane Grosjean <s.grosjean@peak-system.com>
   7 *
   8 * Many thanks to Klaus Hitschler <klaus.hitschler@gmx.de>
   9 *
  10 * This program is free software; you can redistribute it and/or modify it
  11 * under the terms of the GNU General Public License as published
  12 * by the Free Software Foundation; version 2 of the License.
  13 *
  14 * This program is distributed in the hope that it will be useful, but
  15 * WITHOUT ANY WARRANTY; without even the implied warranty of
  16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  17 * General Public License for more details.
  18 */
  19#ifndef PCAN_USB_CORE_H
  20#define PCAN_USB_CORE_H
  21
  22/* PEAK-System vendor id. */
  23#define PCAN_USB_VENDOR_ID              0x0c72
  24
  25/* supported device ids. */
  26#define PCAN_USB_PRODUCT_ID             0x000c
  27#define PCAN_USBPRO_PRODUCT_ID          0x000d
  28#define PCAN_USBPROFD_PRODUCT_ID        0x0011
  29#define PCAN_USBFD_PRODUCT_ID           0x0012
  30#define PCAN_USBCHIP_PRODUCT_ID         0x0013
  31#define PCAN_USBX6_PRODUCT_ID           0x0014
  32
  33#define PCAN_USB_DRIVER_NAME            "peak_usb"
  34
  35/* number of urbs that are submitted for rx/tx per channel */
  36#define PCAN_USB_MAX_RX_URBS            4
  37#define PCAN_USB_MAX_TX_URBS            10
  38
  39/* usb adapters maximum channels per usb interface */
  40#define PCAN_USB_MAX_CHANNEL            2
  41
  42/* maximum length of the usb commands sent to/received from  the devices */
  43#define PCAN_USB_MAX_CMD_LEN            32
  44
  45struct peak_usb_device;
  46
  47/* PEAK-System USB adapter descriptor */
  48struct peak_usb_adapter {
  49        char *name;
  50        u32 device_id;
  51        u32 ctrlmode_supported;
  52        struct can_clock clock;
  53        const struct can_bittiming_const * const bittiming_const;
  54        const struct can_bittiming_const * const data_bittiming_const;
  55        unsigned int ctrl_count;
  56
  57        int (*intf_probe)(struct usb_interface *intf);
  58
  59        int (*dev_init)(struct peak_usb_device *dev);
  60        void (*dev_exit)(struct peak_usb_device *dev);
  61        void (*dev_free)(struct peak_usb_device *dev);
  62        int (*dev_open)(struct peak_usb_device *dev);
  63        int (*dev_close)(struct peak_usb_device *dev);
  64        int (*dev_set_bittiming)(struct peak_usb_device *dev,
  65                                        struct can_bittiming *bt);
  66        int (*dev_set_data_bittiming)(struct peak_usb_device *dev,
  67                                      struct can_bittiming *bt);
  68        int (*dev_set_bus)(struct peak_usb_device *dev, u8 onoff);
  69        int (*dev_get_device_id)(struct peak_usb_device *dev, u32 *device_id);
  70        int (*dev_decode_buf)(struct peak_usb_device *dev, struct urb *urb);
  71        int (*dev_encode_msg)(struct peak_usb_device *dev, struct sk_buff *skb,
  72                                        u8 *obuf, size_t *size);
  73        int (*dev_start)(struct peak_usb_device *dev);
  74        int (*dev_stop)(struct peak_usb_device *dev);
  75        int (*dev_restart_async)(struct peak_usb_device *dev, struct urb *urb,
  76                                        u8 *buf);
  77        int (*do_get_berr_counter)(const struct net_device *netdev,
  78                                   struct can_berr_counter *bec);
  79        u8 ep_msg_in;
  80        u8 ep_msg_out[PCAN_USB_MAX_CHANNEL];
  81        u8 ts_used_bits;
  82        u32 ts_period;
  83        u8 us_per_ts_shift;
  84        u32 us_per_ts_scale;
  85
  86        int rx_buffer_size;
  87        int tx_buffer_size;
  88        int sizeof_dev_private;
  89};
  90
  91extern const struct peak_usb_adapter pcan_usb;
  92extern const struct peak_usb_adapter pcan_usb_pro;
  93extern const struct peak_usb_adapter pcan_usb_fd;
  94extern const struct peak_usb_adapter pcan_usb_chip;
  95extern const struct peak_usb_adapter pcan_usb_pro_fd;
  96extern const struct peak_usb_adapter pcan_usb_x6;
  97
  98struct peak_time_ref {
  99        ktime_t tv_host_0, tv_host;
 100        u32 ts_dev_1, ts_dev_2;
 101        u64 ts_total;
 102        u32 tick_count;
 103        const struct peak_usb_adapter *adapter;
 104};
 105
 106struct peak_tx_urb_context {
 107        struct peak_usb_device *dev;
 108        u32 echo_index;
 109        u8 data_len;
 110        struct urb *urb;
 111};
 112
 113#define PCAN_USB_STATE_CONNECTED        0x00000001
 114#define PCAN_USB_STATE_STARTED          0x00000002
 115
 116/* PEAK-System USB device */
 117struct peak_usb_device {
 118        struct can_priv can;
 119        const struct peak_usb_adapter *adapter;
 120        unsigned int ctrl_idx;
 121        u32 state;
 122
 123        struct sk_buff *echo_skb[PCAN_USB_MAX_TX_URBS];
 124
 125        struct usb_device *udev;
 126        struct net_device *netdev;
 127
 128        atomic_t active_tx_urbs;
 129        struct usb_anchor tx_submitted;
 130        struct peak_tx_urb_context tx_contexts[PCAN_USB_MAX_TX_URBS];
 131
 132        u8 *cmd_buf;
 133        struct usb_anchor rx_submitted;
 134
 135        u32 device_number;
 136        u8 device_rev;
 137
 138        u8 ep_msg_in;
 139        u8 ep_msg_out;
 140
 141        u16 bus_load;
 142
 143        struct peak_usb_device *prev_siblings;
 144        struct peak_usb_device *next_siblings;
 145};
 146
 147void pcan_dump_mem(char *prompt, void *p, int l);
 148
 149/* common timestamp management */
 150void peak_usb_init_time_ref(struct peak_time_ref *time_ref,
 151                            const struct peak_usb_adapter *adapter);
 152void peak_usb_update_ts_now(struct peak_time_ref *time_ref, u32 ts_now);
 153void peak_usb_set_ts_now(struct peak_time_ref *time_ref, u32 ts_now);
 154void peak_usb_get_ts_time(struct peak_time_ref *time_ref, u32 ts, ktime_t *tv);
 155int peak_usb_netif_rx(struct sk_buff *skb,
 156                      struct peak_time_ref *time_ref, u32 ts_low);
 157void peak_usb_async_complete(struct urb *urb);
 158void peak_usb_restart_complete(struct peak_usb_device *dev);
 159
 160#endif
 161