| 1 |
// SPDX-License-Identifier: GPL-2.0-only |
| 2 |
/* |
| 3 |
* CAN driver for esd electronics gmbh CAN-USB/2, CAN-USB/3 and CAN-USB/Micro |
| 4 |
* |
| 5 |
* Copyright (C) 2010-2012 esd electronic system design gmbh, Matthias Fuchs <[email protected]> |
| 6 |
* Copyright (C) 2022-2024 esd electronics gmbh, Frank Jungclaus <[email protected]> |
| 7 |
*/ |
| 8 |
|
| 9 |
#include <linux/can.h> |
| 10 |
#include <linux/can/dev.h> |
| 11 |
#include <linux/can/error.h> |
| 12 |
#include <linux/err.h> |
| 13 |
#include <linux/ethtool.h> |
| 14 |
#include <linux/module.h> |
| 15 |
#include <linux/netdevice.h> |
| 16 |
#include <linux/signal.h> |
| 17 |
#include <linux/slab.h> |
| 18 |
#include <linux/units.h> |
| 19 |
#include <linux/usb.h> |
| 20 |
|
| 21 |
MODULE_AUTHOR("Matthias Fuchs <[email protected]>"); |
| 22 |
MODULE_AUTHOR("Frank Jungclaus <[email protected]>"); |
| 23 |
MODULE_DESCRIPTION("CAN driver for esd electronics gmbh CAN-USB/2, CAN-USB/3 and CAN-USB/Micro interfaces"); |
| 24 |
MODULE_LICENSE("GPL v2"); |
| 25 |
|
| 26 |
/* USB vendor and product ID */ |
| 27 |
#define ESD_USB_ESDGMBH_VENDOR_ID 0x0ab4 |
| 28 |
#define ESD_USB_CANUSB2_PRODUCT_ID 0x0010 |
| 29 |
#define ESD_USB_CANUSBM_PRODUCT_ID 0x0011 |
| 30 |
#define ESD_USB_CANUSB3_PRODUCT_ID 0x0014 |
| 31 |
|
| 32 |
/* CAN controller clock frequencies */ |
| 33 |
#define ESD_USB_2_CAN_CLOCK (60 * MEGA) /* Hz */ |
| 34 |
#define ESD_USB_M_CAN_CLOCK (36 * MEGA) /* Hz */ |
| 35 |
#define ESD_USB_3_CAN_CLOCK (80 * MEGA) /* Hz */ |
| 36 |
|
| 37 |
/* Maximum number of CAN nets */ |
| 38 |
#define ESD_USB_MAX_NETS 2 |
| 39 |
|
| 40 |
/* USB commands */ |
| 41 |
#define ESD_USB_CMD_VERSION 1 /* also used for VERSION_REPLY */ |
| 42 |
#define ESD_USB_CMD_CAN_RX 2 /* device to host only */ |
| 43 |
#define ESD_USB_CMD_CAN_TX 3 /* also used for TX_DONE */ |
| 44 |
#define ESD_USB_CMD_SETBAUD 4 /* also used for SETBAUD_REPLY */ |
| 45 |
#define ESD_USB_CMD_TS 5 /* also used for TS_REPLY */ |
| 46 |
#define ESD_USB_CMD_IDADD 6 /* also used for IDADD_REPLY */ |
| 47 |
|
| 48 |
/* esd CAN message flags - dlc field */ |
| 49 |
#define ESD_USB_RTR BIT(4) |
| 50 |
#define ESD_USB_NO_BRS BIT(4) |
| 51 |
#define ESD_USB_ESI BIT(5) |
| 52 |
#define ESD_USB_FD BIT(7) |
| 53 |
|
| 54 |
/* esd CAN message flags - id field */ |
| 55 |
#define ESD_USB_EXTID BIT(29) |
| 56 |
#define ESD_USB_EVENT BIT(30) |
| 57 |
#define ESD_USB_IDMASK GENMASK(28, 0) |
| 58 |
|
| 59 |
/* esd CAN event ids */ |
| 60 |
#define ESD_USB_EV_CAN_ERROR_EXT 2 /* CAN controller specific diagnostic data */ |
| 61 |
|
| 62 |
/* baudrate message flags */ |
| 63 |
#define ESD_USB_LOM BIT(30) /* Listen Only Mode */ |
| 64 |
#define ESD_USB_UBR BIT(31) /* User Bit Rate (controller BTR) in bits 0..27 */ |
| 65 |
#define ESD_USB_NO_BAUDRATE GENMASK(30, 0) /* bit rate unconfigured */ |
| 66 |
|
| 67 |
/* bit timing esd CAN-USB */ |
| 68 |
#define ESD_USB_2_TSEG1_SHIFT 16 |
| 69 |
#define ESD_USB_2_TSEG2_SHIFT 20 |
| 70 |
#define ESD_USB_2_SJW_SHIFT 14 |
| 71 |
#define ESD_USB_M_SJW_SHIFT 24 |
| 72 |
#define ESD_USB_TRIPLE_SAMPLES BIT(23) |
| 73 |
|
| 74 |
/* Transmitter Delay Compensation */ |
| 75 |
#define ESD_USB_3_TDC_MODE_AUTO 0 |
| 76 |
|
| 77 |
/* esd IDADD message */ |
| 78 |
#define ESD_USB_ID_ENABLE BIT(7) |
| 79 |
#define ESD_USB_MAX_ID_SEGMENT 64 |
| 80 |
|
| 81 |
/* SJA1000 ECC register (emulated by usb firmware) */ |
| 82 |
#define ESD_USB_SJA1000_ECC_SEG GENMASK(4, 0) |
| 83 |
#define ESD_USB_SJA1000_ECC_DIR BIT(5) |
| 84 |
#define ESD_USB_SJA1000_ECC_ERR BIT(2, 1) |
| 85 |
#define ESD_USB_SJA1000_ECC_BIT 0x00 |
| 86 |
#define ESD_USB_SJA1000_ECC_FORM BIT(6) |
| 87 |
#define ESD_USB_SJA1000_ECC_STUFF BIT(7) |
| 88 |
#define ESD_USB_SJA1000_ECC_MASK GENMASK(7, 6) |
| 89 |
|
| 90 |
/* esd bus state event codes */ |
| 91 |
#define ESD_USB_BUSSTATE_MASK GENMASK(7, 6) |
| 92 |
#define ESD_USB_BUSSTATE_WARN BIT(6) |
| 93 |
#define ESD_USB_BUSSTATE_ERRPASSIVE BIT(7) |
| 94 |
#define ESD_USB_BUSSTATE_BUSOFF GENMASK(7, 6) |
| 95 |
|
| 96 |
#define ESD_USB_RX_BUFFER_SIZE 1024 |
| 97 |
#define ESD_USB_MAX_RX_URBS 4 |
| 98 |
#define ESD_USB_MAX_TX_URBS 16 /* must be power of 2 */ |
| 99 |
|
| 100 |
/* Modes for CAN-USB/3, to be used for esd_usb_3_set_baudrate_msg_x.mode */ |
| 101 |
#define ESD_USB_3_BAUDRATE_MODE_DISABLE 0 /* remove from bus */ |
| 102 |
#define ESD_USB_3_BAUDRATE_MODE_INDEX 1 /* ESD (CiA) bit rate idx */ |
| 103 |
#define ESD_USB_3_BAUDRATE_MODE_BTR_CTRL 2 /* BTR values (controller)*/ |
| 104 |
#define ESD_USB_3_BAUDRATE_MODE_BTR_CANONICAL 3 /* BTR values (canonical) */ |
| 105 |
#define ESD_USB_3_BAUDRATE_MODE_NUM 4 /* numerical bit rate */ |
| 106 |
#define ESD_USB_3_BAUDRATE_MODE_AUTOBAUD 5 /* autobaud */ |
| 107 |
|
| 108 |
/* Flags for CAN-USB/3, to be used for esd_usb_3_set_baudrate_msg_x.flags */ |
| 109 |
#define ESD_USB_3_BAUDRATE_FLAG_FD BIT(0) /* enable CAN FD mode */ |
| 110 |
#define ESD_USB_3_BAUDRATE_FLAG_LOM BIT(1) /* enable listen only mode */ |
| 111 |
#define ESD_USB_3_BAUDRATE_FLAG_STM BIT(2) /* enable self test mode */ |
| 112 |
#define ESD_USB_3_BAUDRATE_FLAG_TRS BIT(3) /* enable triple sampling */ |
| 113 |
#define ESD_USB_3_BAUDRATE_FLAG_TXP BIT(4) /* enable transmit pause */ |
| 114 |
|
| 115 |
struct esd_usb_header_msg { |
| 116 |
u8 len; /* total message length in 32bit words */ |
| 117 |
u8 cmd; |
| 118 |
u8 rsvd[2]; |
| 119 |
}; |
| 120 |
|
| 121 |
struct esd_usb_version_msg { |
| 122 |
u8 len; /* total message length in 32bit words */ |
| 123 |
u8 cmd; |
| 124 |
u8 rsvd; |
| 125 |
u8 flags; |
| 126 |
__le32 drv_version; |
| 127 |
}; |
| 128 |
|
| 129 |
struct esd_usb_version_reply_msg { |
| 130 |
u8 len; /* total message length in 32bit words */ |
| 131 |
u8 cmd; |
| 132 |
u8 nets; |
| 133 |
u8 features; |
| 134 |
__le32 version; |
| 135 |
u8 name[16]; |
| 136 |
__le32 rsvd; |
| 137 |
__le32 ts; |
| 138 |
}; |
| 139 |
|
| 140 |
struct esd_usb_rx_msg { |
| 141 |
u8 len; /* total message length in 32bit words */ |
| 142 |
u8 cmd; |
| 143 |
u8 net; |
| 144 |
u8 dlc; |
| 145 |
__le32 ts; |
| 146 |
__le32 id; /* upper 3 bits contain flags */ |
| 147 |
union { |
| 148 |
u8 data[CAN_MAX_DLEN]; |
| 149 |
u8 data_fd[CANFD_MAX_DLEN]; |
| 150 |
struct { |
| 151 |
u8 status; /* CAN Controller Status */ |
| 152 |
u8 ecc; /* Error Capture Register */ |
| 153 |
u8 rec; /* RX Error Counter */ |
| 154 |
u8 tec; /* TX Error Counter */ |
| 155 |
} ev_can_err_ext; /* For ESD_EV_CAN_ERROR_EXT */ |
| 156 |
}; |
| 157 |
}; |
| 158 |
|
| 159 |
struct esd_usb_tx_msg { |
| 160 |
u8 len; /* total message length in 32bit words */ |
| 161 |
u8 cmd; |
| 162 |
u8 net; |
| 163 |
u8 dlc; |
| 164 |
u32 hnd; /* opaque handle, not used by device */ |
| 165 |
__le32 id; /* upper 3 bits contain flags */ |
| 166 |
union { |
| 167 |
u8 data[CAN_MAX_DLEN]; |
| 168 |
u8 data_fd[CANFD_MAX_DLEN]; |
| 169 |
}; |
| 170 |
}; |
| 171 |
|
| 172 |
struct esd_usb_tx_done_msg { |
| 173 |
u8 len; /* total message length in 32bit words */ |
| 174 |
u8 cmd; |
| 175 |
u8 net; |
| 176 |
u8 status; |
| 177 |
u32 hnd; /* opaque handle, not used by device */ |
| 178 |
__le32 ts; |
| 179 |
}; |
| 180 |
|
| 181 |
struct esd_usb_id_filter_msg { |
| 182 |
u8 len; /* total message length in 32bit words */ |
| 183 |
u8 cmd; |
| 184 |
u8 net; |
| 185 |
u8 option; |
| 186 |
__le32 mask[ESD_USB_MAX_ID_SEGMENT + 1]; /* +1 for 29bit extended IDs */ |
| 187 |
}; |
| 188 |
|
| 189 |
struct esd_usb_set_baudrate_msg { |
| 190 |
u8 len; /* total message length in 32bit words */ |
| 191 |
u8 cmd; |
| 192 |
u8 net; |
| 193 |
u8 rsvd; |
| 194 |
__le32 baud; |
| 195 |
}; |
| 196 |
|
| 197 |
/* CAN-USB/3 baudrate configuration, used for nominal as well as for data bit rate */ |
| 198 |
struct esd_usb_3_baudrate_cfg { |
| 199 |
__le16 brp; /* bit rate pre-scaler */ |
| 200 |
__le16 tseg1; /* time segment before sample point */ |
| 201 |
__le16 tseg2; /* time segment after sample point */ |
| 202 |
__le16 sjw; /* synchronization jump Width */ |
| 203 |
}; |
| 204 |
|
| 205 |
/* In principle, the esd CAN-USB/3 supports Transmitter Delay Compensation (TDC), |
| 206 |
* but currently only the automatic TDC mode is supported by this driver. |
| 207 |
* An implementation for manual TDC configuration will follow. |
| 208 |
* |
| 209 |
* For information about struct esd_usb_3_tdc_cfg, see |
| 210 |
* NTCAN Application Developers Manual, 6.2.25 NTCAN_TDC_CFG + related chapters |
| 211 |
* https://esd.eu/fileadmin/esd/docs/manuals/NTCAN_Part1_Function_API_Manual_en_56.pdf |
| 212 |
*/ |
| 213 |
struct esd_usb_3_tdc_cfg { |
| 214 |
u8 tdc_mode; /* transmitter delay compensation mode */ |
| 215 |
u8 ssp_offset; /* secondary sample point offset in mtq */ |
| 216 |
s8 ssp_shift; /* secondary sample point shift in mtq */ |
| 217 |
u8 tdc_filter; /* TDC filter in mtq */ |
| 218 |
}; |
| 219 |
|
| 220 |
/* Extended version of the above set_baudrate_msg for a CAN-USB/3 |
| 221 |
* to define the CAN bit timing configuration of the CAN controller in |
| 222 |
* CAN FD mode as well as in Classical CAN mode. |
| 223 |
* |
| 224 |
* The payload of this command is a NTCAN_BAUDRATE_X structure according to |
| 225 |
* esd electronics gmbh, NTCAN Application Developers Manual, 6.2.15 NTCAN_BAUDRATE_X |
| 226 |
* https://esd.eu/fileadmin/esd/docs/manuals/NTCAN_Part1_Function_API_Manual_en_56.pdf |
| 227 |
*/ |
| 228 |
struct esd_usb_3_set_baudrate_msg_x { |
| 229 |
u8 len; /* total message length in 32bit words */ |
| 230 |
u8 cmd; |
| 231 |
u8 net; |
| 232 |
u8 rsvd; /*reserved */ |
| 233 |
/* Payload ... */ |
| 234 |
__le16 mode; /* mode word, see ESD_USB_3_BAUDRATE_MODE_xxx */ |
| 235 |
__le16 flags; /* control flags, see ESD_USB_3_BAUDRATE_FLAG_xxx */ |
| 236 |
struct esd_usb_3_tdc_cfg tdc; /* TDC configuration */ |
| 237 |
struct esd_usb_3_baudrate_cfg nom; /* nominal bit rate */ |
| 238 |
struct esd_usb_3_baudrate_cfg data; /* data bit rate */ |
| 239 |
}; |
| 240 |
|
| 241 |
/* Main message type used between library and application */ |
| 242 |
union __packed esd_usb_msg { |
| 243 |
struct esd_usb_header_msg hdr; |
| 244 |
struct esd_usb_version_msg version; |
| 245 |
struct esd_usb_version_reply_msg version_reply; |
| 246 |
struct esd_usb_rx_msg rx; |
| 247 |
struct esd_usb_tx_msg tx; |
| 248 |
struct esd_usb_tx_done_msg txdone; |
| 249 |
struct esd_usb_set_baudrate_msg setbaud; |
| 250 |
struct esd_usb_3_set_baudrate_msg_x setbaud_x; |
| 251 |
struct esd_usb_id_filter_msg filter; |
| 252 |
}; |
| 253 |
|
| 254 |
static struct usb_device_id esd_usb_table[] = { |
| 255 |
{USB_DEVICE(ESD_USB_ESDGMBH_VENDOR_ID, ESD_USB_CANUSB2_PRODUCT_ID)}, |
| 256 |
{USB_DEVICE(ESD_USB_ESDGMBH_VENDOR_ID, ESD_USB_CANUSBM_PRODUCT_ID)}, |
| 257 |
{USB_DEVICE(ESD_USB_ESDGMBH_VENDOR_ID, ESD_USB_CANUSB3_PRODUCT_ID)}, |
| 258 |
{} |
| 259 |
}; |
| 260 |
MODULE_DEVICE_TABLE(usb, esd_usb_table); |
| 261 |
|
| 262 |
struct esd_usb_net_priv; |
| 263 |
|
| 264 |
struct esd_tx_urb_context { |
| 265 |
struct esd_usb_net_priv *priv; |
| 266 |
u32 echo_index; |
| 267 |
}; |
| 268 |
|
| 269 |
struct esd_usb { |
| 270 |
struct usb_device *udev; |
| 271 |
struct esd_usb_net_priv *nets[ESD_USB_MAX_NETS]; |
| 272 |
|
| 273 |
struct usb_anchor rx_submitted; |
| 274 |
|
| 275 |
unsigned int rx_pipe; |
| 276 |
unsigned int tx_pipe; |
| 277 |
|
| 278 |
int net_count; |
| 279 |
u32 version; |
| 280 |
int rxinitdone; |
| 281 |
int in_usb_disconnect; |
| 282 |
void *rxbuf[ESD_USB_MAX_RX_URBS]; |
| 283 |
dma_addr_t rxbuf_dma[ESD_USB_MAX_RX_URBS]; |
| 284 |
}; |
| 285 |
|
| 286 |
struct esd_usb_net_priv { |
| 287 |
struct can_priv can; /* must be the first member */ |
| 288 |
|
| 289 |
atomic_t active_tx_jobs; |
| 290 |
struct usb_anchor tx_submitted; |
| 291 |
struct esd_tx_urb_context tx_contexts[ESD_USB_MAX_TX_URBS]; |
| 292 |
|
| 293 |
struct esd_usb *usb; |
| 294 |
struct net_device *netdev; |
| 295 |
int index; |
| 296 |
u8 old_state; |
| 297 |
struct can_berr_counter bec; |
| 298 |
}; |
| 299 |
|
| 300 |
static void esd_usb_rx_event(struct esd_usb_net_priv *priv, |
| 301 |
union esd_usb_msg *msg) |
| 302 |
{ |
| 303 |
struct net_device_stats *stats = &priv->netdev->stats; |
| 304 |
struct can_frame *cf; |
| 305 |
struct sk_buff *skb; |
| 306 |
u32 id = le32_to_cpu(msg->rx.id) & ESD_USB_IDMASK; |
| 307 |
|
| 308 |
if (id == ESD_USB_EV_CAN_ERROR_EXT) { |
| 309 |
u8 state = msg->rx.ev_can_err_ext.status; |
| 310 |
u8 ecc = msg->rx.ev_can_err_ext.ecc; |
| 311 |
|
| 312 |
priv->bec.rxerr = msg->rx.ev_can_err_ext.rec; |
| 313 |
priv->bec.txerr = msg->rx.ev_can_err_ext.tec; |
| 314 |
|
| 315 |
netdev_dbg(priv->netdev, |
| 316 |
"CAN_ERR_EV_EXT: dlc=%#02x state=%02x ecc=%02x rec=%02x tec=%02x\n", |
| 317 |
msg->rx.dlc, state, ecc, |
| 318 |
priv->bec.rxerr, priv->bec.txerr); |
| 319 |
|
| 320 |
/* if berr-reporting is off, only pass through on state change ... */ |
| 321 |
if (!(priv->can.ctrlmode & CAN_CTRLMODE_BERR_REPORTING) && |
| 322 |
state == priv->old_state) |
| 323 |
return; |
| 324 |
|
| 325 |
skb = alloc_can_err_skb(priv->netdev, &cf); |
| 326 |
if (!skb) |
| 327 |
stats->rx_dropped++; |
| 328 |
|
| 329 |
if (state != priv->old_state) { |
| 330 |
enum can_state tx_state, rx_state; |
| 331 |
enum can_state new_state = CAN_STATE_ERROR_ACTIVE; |
| 332 |
|
| 333 |
priv->old_state = state; |
| 334 |
|
| 335 |
switch (state & ESD_USB_BUSSTATE_MASK) { |
| 336 |
case ESD_USB_BUSSTATE_BUSOFF: |
| 337 |
new_state = CAN_STATE_BUS_OFF; |
| 338 |
can_bus_off(priv->netdev); |
| 339 |
break; |
| 340 |
case ESD_USB_BUSSTATE_WARN: |
| 341 |
new_state = CAN_STATE_ERROR_WARNING; |
| 342 |
break; |
| 343 |
case ESD_USB_BUSSTATE_ERRPASSIVE: |
| 344 |
new_state = CAN_STATE_ERROR_PASSIVE; |
| 345 |
break; |
| 346 |
default: |
| 347 |
new_state = CAN_STATE_ERROR_ACTIVE; |
| 348 |
priv->bec.txerr = 0; |
| 349 |
priv->bec.rxerr = 0; |
| 350 |
break; |
| 351 |
} |
| 352 |
|
| 353 |
if (new_state != priv->can.state) { |
| 354 |
tx_state = (priv->bec.txerr >= priv->bec.rxerr) ? new_state : 0; |
| 355 |
rx_state = (priv->bec.txerr <= priv->bec.rxerr) ? new_state : 0; |
| 356 |
can_change_state(priv->netdev, cf, |
| 357 |
tx_state, rx_state); |
| 358 |
} |
| 359 |
} else if (skb) { |
| 360 |
priv->can.can_stats.bus_error++; |
| 361 |
stats->rx_errors++; |
| 362 |
|
| 363 |
cf->can_id |= CAN_ERR_PROT | CAN_ERR_BUSERROR; |
| 364 |
|
| 365 |
switch (ecc & ESD_USB_SJA1000_ECC_MASK) { |
| 366 |
case ESD_USB_SJA1000_ECC_BIT: |
| 367 |
cf->data[2] |= CAN_ERR_PROT_BIT; |
| 368 |
break; |
| 369 |
case ESD_USB_SJA1000_ECC_FORM: |
| 370 |
cf->data[2] |= CAN_ERR_PROT_FORM; |
| 371 |
break; |
| 372 |
case ESD_USB_SJA1000_ECC_STUFF: |
| 373 |
cf->data[2] |= CAN_ERR_PROT_STUFF; |
| 374 |
break; |
| 375 |
default: |
| 376 |
break; |
| 377 |
} |
| 378 |
|
| 379 |
/* Error occurred during transmission? */ |
| 380 |
if (!(ecc & ESD_USB_SJA1000_ECC_DIR)) |
| 381 |
cf->data[2] |= CAN_ERR_PROT_TX; |
| 382 |
|
| 383 |
/* Bit stream position in CAN frame as the error was detected */ |
| 384 |
cf->data[3] = ecc & ESD_USB_SJA1000_ECC_SEG; |
| 385 |
} |
| 386 |
|
| 387 |
if (skb) { |
| 388 |
cf->can_id |= CAN_ERR_CNT; |
| 389 |
cf->data[6] = priv->bec.txerr; |
| 390 |
cf->data[7] = priv->bec.rxerr; |
| 391 |
|
| 392 |
netif_rx(skb); |
| 393 |
} |
| 394 |
} |
| 395 |
} |
| 396 |
|
| 397 |
static void esd_usb_rx_can_msg(struct esd_usb_net_priv *priv, |
| 398 |
union esd_usb_msg *msg) |
| 399 |
{ |
| 400 |
struct net_device_stats *stats = &priv->netdev->stats; |
| 401 |
struct can_frame *cf; |
| 402 |
struct canfd_frame *cfd; |
| 403 |
struct sk_buff *skb; |
| 404 |
u32 id; |
| 405 |
u8 len; |
| 406 |
|
| 407 |
if (!netif_device_present(priv->netdev)) |
| 408 |
return; |
| 409 |
|
| 410 |
id = le32_to_cpu(msg->rx.id); |
| 411 |
|
| 412 |
if (id & ESD_USB_EVENT) { |
| 413 |
esd_usb_rx_event(priv, msg); |
| 414 |
} else { |
| 415 |
if (msg->rx.dlc & ESD_USB_FD) { |
| 416 |
skb = alloc_canfd_skb(priv->netdev, &cfd); |
| 417 |
} else { |
| 418 |
skb = alloc_can_skb(priv->netdev, &cf); |
| 419 |
cfd = (struct canfd_frame *)cf; |
| 420 |
} |
| 421 |
|
| 422 |
if (skb == NULL) { |
| 423 |
stats->rx_dropped++; |
| 424 |
return; |
| 425 |
} |
| 426 |
|
| 427 |
cfd->can_id = id & ESD_USB_IDMASK; |
| 428 |
|
| 429 |
if (msg->rx.dlc & ESD_USB_FD) { |
| 430 |
/* masking by 0x0F is already done within can_fd_dlc2len() */ |
| 431 |
cfd->len = can_fd_dlc2len(msg->rx.dlc); |
| 432 |
len = cfd->len; |
| 433 |
if ((msg->rx.dlc & ESD_USB_NO_BRS) == 0) |
| 434 |
cfd->flags |= CANFD_BRS; |
| 435 |
if (msg->rx.dlc & ESD_USB_ESI) |
| 436 |
cfd->flags |= CANFD_ESI; |
| 437 |
} else { |
| 438 |
can_frame_set_cc_len(cf, msg->rx.dlc & ~ESD_USB_RTR, priv->can.ctrlmode); |
| 439 |
len = cf->len; |
| 440 |
if (msg->rx.dlc & ESD_USB_RTR) { |
| 441 |
cf->can_id |= CAN_RTR_FLAG; |
| 442 |
len = 0; |
| 443 |
} |
| 444 |
} |
| 445 |
|
| 446 |
if (id & ESD_USB_EXTID) |
| 447 |
cfd->can_id |= CAN_EFF_FLAG; |
| 448 |
|
| 449 |
memcpy(cfd->data, msg->rx.data_fd, len); |
| 450 |
stats->rx_bytes += len; |
| 451 |
stats->rx_packets++; |
| 452 |
|
| 453 |
netif_rx(skb); |
| 454 |
} |
| 455 |
} |
| 456 |
|
| 457 |
static void esd_usb_tx_done_msg(struct esd_usb_net_priv *priv, |
| 458 |
union esd_usb_msg *msg) |
| 459 |
{ |
| 460 |
struct net_device_stats *stats = &priv->netdev->stats; |
| 461 |
struct net_device *netdev = priv->netdev; |
| 462 |
struct esd_tx_urb_context *context; |
| 463 |
|
| 464 |
if (!netif_device_present(netdev)) |
| 465 |
return; |
| 466 |
|
| 467 |
context = &priv->tx_contexts[msg->txdone.hnd & (ESD_USB_MAX_TX_URBS - 1)]; |
| 468 |
|
| 469 |
if (!msg->txdone.status) { |
| 470 |
stats->tx_packets++; |
| 471 |
stats->tx_bytes += can_get_echo_skb(netdev, context->echo_index, |
| 472 |
NULL); |
| 473 |
} else { |
| 474 |
stats->tx_errors++; |
| 475 |
can_free_echo_skb(netdev, context->echo_index, NULL); |
| 476 |
} |
| 477 |
|
| 478 |
/* Release context */ |
| 479 |
context->echo_index = ESD_USB_MAX_TX_URBS; |
| 480 |
atomic_dec(&priv->active_tx_jobs); |
| 481 |
|
| 482 |
netif_wake_queue(netdev); |
| 483 |
} |
| 484 |
|
| 485 |
static void esd_usb_read_bulk_callback(struct urb *urb) |
| 486 |
{ |
| 487 |
struct esd_usb *dev = urb->context; |
| 488 |
int err; |
| 489 |
int pos = 0; |
| 490 |
int i; |
| 491 |
|
| 492 |
switch (urb->status) { |
| 493 |
case 0: /* success */ |
| 494 |
break; |
| 495 |
|
| 496 |
case -ENOENT: |
| 497 |
case -EPIPE: |
| 498 |
case -EPROTO: |
| 499 |
case -ESHUTDOWN: |
| 500 |
return; |
| 501 |
|
| 502 |
default: |
| 503 |
dev_info(dev->udev->dev.parent, |
| 504 |
"Rx URB aborted (%pe)\n", ERR_PTR(urb->status)); |
| 505 |
goto resubmit_urb; |
| 506 |
} |
| 507 |
|
| 508 |
while (pos < urb->actual_length) { |
| 509 |
union esd_usb_msg *msg; |
| 510 |
|
| 511 |
msg = (union esd_usb_msg *)(urb->transfer_buffer + pos); |
| 512 |
|
| 513 |
switch (msg->hdr.cmd) { |
| 514 |
case ESD_USB_CMD_CAN_RX: |
| 515 |
if (msg->rx.net >= dev->net_count) { |
| 516 |
dev_err(dev->udev->dev.parent, "format error\n"); |
| 517 |
break; |
| 518 |
} |
| 519 |
|
| 520 |
esd_usb_rx_can_msg(dev->nets[msg->rx.net], msg); |
| 521 |
break; |
| 522 |
|
| 523 |
case ESD_USB_CMD_CAN_TX: |
| 524 |
if (msg->txdone.net >= dev->net_count) { |
| 525 |
dev_err(dev->udev->dev.parent, "format error\n"); |
| 526 |
break; |
| 527 |
} |
| 528 |
|
| 529 |
esd_usb_tx_done_msg(dev->nets[msg->txdone.net], |
| 530 |
msg); |
| 531 |
break; |
| 532 |
} |
| 533 |
|
| 534 |
pos += msg->hdr.len * sizeof(u32); /* convert to # of bytes */ |
| 535 |
|
| 536 |
if (pos > urb->actual_length) { |
| 537 |
dev_err(dev->udev->dev.parent, "format error\n"); |
| 538 |
break; |
| 539 |
} |
| 540 |
} |
| 541 |
|
| 542 |
resubmit_urb: |
| 543 |
usb_fill_bulk_urb(urb, dev->udev, dev->rx_pipe, |
| 544 |
urb->transfer_buffer, ESD_USB_RX_BUFFER_SIZE, |
| 545 |
esd_usb_read_bulk_callback, dev); |
| 546 |
|
| 547 |
usb_anchor_urb(urb, &dev->rx_submitted); |
| 548 |
|
| 549 |
err = usb_submit_urb(urb, GFP_ATOMIC); |
| 550 |
if (!err) |
| 551 |
return; |
| 552 |
|
| 553 |
usb_unanchor_urb(urb); |
| 554 |
|
| 555 |
if (err == -ENODEV) { |
| 556 |
for (i = 0; i < dev->net_count; i++) { |
| 557 |
if (dev->nets[i]) |
| 558 |
netif_device_detach(dev->nets[i]->netdev); |
| 559 |
} |
| 560 |
} else { |
| 561 |
dev_err(dev->udev->dev.parent, |
| 562 |
"failed resubmitting read bulk urb: %pe\n", ERR_PTR(err)); |
| 563 |
} |
| 564 |
} |
| 565 |
|
| 566 |
/* callback for bulk IN urb */ |
| 567 |
static void esd_usb_write_bulk_callback(struct urb *urb) |
| 568 |
{ |
| 569 |
struct esd_tx_urb_context *context = urb->context; |
| 570 |
struct esd_usb_net_priv *priv; |
| 571 |
struct net_device *netdev; |
| 572 |
size_t size = sizeof(union esd_usb_msg); |
| 573 |
|
| 574 |
WARN_ON(!context); |
| 575 |
|
| 576 |
priv = context->priv; |
| 577 |
netdev = priv->netdev; |
| 578 |
|
| 579 |
/* free up our allocated buffer */ |
| 580 |
usb_free_coherent(urb->dev, size, |
| 581 |
urb->transfer_buffer, urb->transfer_dma); |
| 582 |
|
| 583 |
if (!netif_device_present(netdev)) |
| 584 |
return; |
| 585 |
|
| 586 |
if (urb->status) |
| 587 |
netdev_info(netdev, "Tx URB aborted (%pe)\n", ERR_PTR(urb->status)); |
| 588 |
|
| 589 |
netif_trans_update(netdev); |
| 590 |
} |
| 591 |
|
| 592 |
static ssize_t firmware_show(struct device *d, |
| 593 |
struct device_attribute *attr, char *buf) |
| 594 |
{ |
| 595 |
struct usb_interface *intf = to_usb_interface(d); |
| 596 |
struct esd_usb *dev = usb_get_intfdata(intf); |
| 597 |
|
| 598 |
return sprintf(buf, "%d.%d.%d\n", |
| 599 |
(dev->version >> 12) & 0xf, |
| 600 |
(dev->version >> 8) & 0xf, |
| 601 |
dev->version & 0xff); |
| 602 |
} |
| 603 |
static DEVICE_ATTR_RO(firmware); |
| 604 |
|
| 605 |
static ssize_t hardware_show(struct device *d, |
| 606 |
struct device_attribute *attr, char *buf) |
| 607 |
{ |
| 608 |
struct usb_interface *intf = to_usb_interface(d); |
| 609 |
struct esd_usb *dev = usb_get_intfdata(intf); |
| 610 |
|
| 611 |
return sprintf(buf, "%d.%d.%d\n", |
| 612 |
(dev->version >> 28) & 0xf, |
| 613 |
(dev->version >> 24) & 0xf, |
| 614 |
(dev->version >> 16) & 0xff); |
| 615 |
} |
| 616 |
static DEVICE_ATTR_RO(hardware); |
| 617 |
|
| 618 |
static ssize_t nets_show(struct device *d, |
| 619 |
struct device_attribute *attr, char *buf) |
| 620 |
{ |
| 621 |
struct usb_interface *intf = to_usb_interface(d); |
| 622 |
struct esd_usb *dev = usb_get_intfdata(intf); |
| 623 |
|
| 624 |
return sprintf(buf, "%d", dev->net_count); |
| 625 |
} |
| 626 |
static DEVICE_ATTR_RO(nets); |
| 627 |
|
| 628 |
static int esd_usb_send_msg(struct esd_usb *dev, union esd_usb_msg *msg) |
| 629 |
{ |
| 630 |
int actual_length; |
| 631 |
|
| 632 |
return usb_bulk_msg(dev->udev, dev->tx_pipe, msg, |
| 633 |
msg->hdr.len * sizeof(u32), /* convert to # of bytes */ |
| 634 |
&actual_length, |
| 635 |
1000); |
| 636 |
} |
| 637 |
|
| 638 |
static int esd_usb_wait_msg(struct esd_usb *dev, |
| 639 |
union esd_usb_msg *msg) |
| 640 |
{ |
| 641 |
int actual_length; |
| 642 |
|
| 643 |
return usb_bulk_msg(dev->udev, dev->rx_pipe, msg, |
| 644 |
sizeof(*msg), &actual_length, 1000); |
| 645 |
} |
| 646 |
|
| 647 |
static int esd_usb_setup_rx_urbs(struct esd_usb *dev) |
| 648 |
{ |
| 649 |
int i, err = 0; |
| 650 |
|
| 651 |
if (dev->rxinitdone) |
| 652 |
return 0; |
| 653 |
|
| 654 |
for (i = 0; i < ESD_USB_MAX_RX_URBS; i++) { |
| 655 |
struct urb *urb = NULL; |
| 656 |
u8 *buf = NULL; |
| 657 |
dma_addr_t buf_dma; |
| 658 |
|
| 659 |
/* create a URB, and a buffer for it */ |
| 660 |
urb = usb_alloc_urb(0, GFP_KERNEL); |
| 661 |
if (!urb) { |
| 662 |
err = -ENOMEM; |
| 663 |
break; |
| 664 |
} |
| 665 |
|
| 666 |
buf = usb_alloc_coherent(dev->udev, ESD_USB_RX_BUFFER_SIZE, GFP_KERNEL, |
| 667 |
&buf_dma); |
| 668 |
if (!buf) { |
| 669 |
dev_warn(dev->udev->dev.parent, |
| 670 |
"No memory left for USB buffer\n"); |
| 671 |
err = -ENOMEM; |
| 672 |
goto freeurb; |
| 673 |
} |
| 674 |
|
| 675 |
urb->transfer_dma = buf_dma; |
| 676 |
|
| 677 |
usb_fill_bulk_urb(urb, dev->udev, dev->rx_pipe, |
| 678 |
buf, ESD_USB_RX_BUFFER_SIZE, |
| 679 |
esd_usb_read_bulk_callback, dev); |
| 680 |
urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; |
| 681 |
usb_anchor_urb(urb, &dev->rx_submitted); |
| 682 |
|
| 683 |
err = usb_submit_urb(urb, GFP_KERNEL); |
| 684 |
if (err) { |
| 685 |
usb_unanchor_urb(urb); |
| 686 |
usb_free_coherent(dev->udev, ESD_USB_RX_BUFFER_SIZE, buf, |
| 687 |
urb->transfer_dma); |
| 688 |
goto freeurb; |
| 689 |
} |
| 690 |
|
| 691 |
dev->rxbuf[i] = buf; |
| 692 |
dev->rxbuf_dma[i] = buf_dma; |
| 693 |
|
| 694 |
freeurb: |
| 695 |
/* Drop reference, USB core will take care of freeing it */ |
| 696 |
usb_free_urb(urb); |
| 697 |
if (err) |
| 698 |
break; |
| 699 |
} |
| 700 |
|
| 701 |
/* Did we submit any URBs */ |
| 702 |
if (i == 0) { |
| 703 |
dev_err(dev->udev->dev.parent, "couldn't setup read URBs\n"); |
| 704 |
return err; |
| 705 |
} |
| 706 |
|
| 707 |
/* Warn if we've couldn't transmit all the URBs */ |
| 708 |
if (i < ESD_USB_MAX_RX_URBS) { |
| 709 |
dev_warn(dev->udev->dev.parent, |
| 710 |
"rx performance may be slow\n"); |
| 711 |
} |
| 712 |
|
| 713 |
dev->rxinitdone = 1; |
| 714 |
return 0; |
| 715 |
} |
| 716 |
|
| 717 |
/* Start interface */ |
| 718 |
static int esd_usb_start(struct esd_usb_net_priv *priv) |
| 719 |
{ |
| 720 |
struct esd_usb *dev = priv->usb; |
| 721 |
struct net_device *netdev = priv->netdev; |
| 722 |
union esd_usb_msg *msg; |
| 723 |
int err, i; |
| 724 |
|
| 725 |
msg = kmalloc_obj(*msg); |
| 726 |
if (!msg) { |
| 727 |
err = -ENOMEM; |
| 728 |
goto out; |
| 729 |
} |
| 730 |
|
| 731 |
/* Enable all IDs |
| 732 |
* The IDADD message takes up to 64 32 bit bitmasks (2048 bits). |
| 733 |
* Each bit represents one 11 bit CAN identifier. A set bit |
| 734 |
* enables reception of the corresponding CAN identifier. A cleared |
| 735 |
* bit disabled this identifier. An additional bitmask value |
| 736 |
* following the CAN 2.0A bits is used to enable reception of |
| 737 |
* extended CAN frames. Only the LSB of this final mask is checked |
| 738 |
* for the complete 29 bit ID range. The IDADD message also allows |
| 739 |
* filter configuration for an ID subset. In this case you can add |
| 740 |
* the number of the starting bitmask (0..64) to the filter.option |
| 741 |
* field followed by only some bitmasks. |
| 742 |
*/ |
| 743 |
msg->hdr.cmd = ESD_USB_CMD_IDADD; |
| 744 |
msg->hdr.len = sizeof(struct esd_usb_id_filter_msg) / sizeof(u32); /* # of 32bit words */ |
| 745 |
msg->filter.net = priv->index; |
| 746 |
msg->filter.option = ESD_USB_ID_ENABLE; /* start with segment 0 */ |
| 747 |
for (i = 0; i < ESD_USB_MAX_ID_SEGMENT; i++) |
| 748 |
msg->filter.mask[i] = cpu_to_le32(GENMASK(31, 0)); |
| 749 |
/* enable 29bit extended IDs */ |
| 750 |
msg->filter.mask[ESD_USB_MAX_ID_SEGMENT] = cpu_to_le32(BIT(0)); |
| 751 |
|
| 752 |
err = esd_usb_send_msg(dev, msg); |
| 753 |
if (err) |
| 754 |
goto out; |
| 755 |
|
| 756 |
err = esd_usb_setup_rx_urbs(dev); |
| 757 |
if (err) |
| 758 |
goto out; |
| 759 |
|
| 760 |
priv->can.state = CAN_STATE_ERROR_ACTIVE; |
| 761 |
|
| 762 |
out: |
| 763 |
if (err == -ENODEV) |
| 764 |
netif_device_detach(netdev); |
| 765 |
if (err) |
| 766 |
netdev_err(netdev, "couldn't start device: %pe\n", ERR_PTR(err)); |
| 767 |
|
| 768 |
kfree(msg); |
| 769 |
return err; |
| 770 |
} |
| 771 |
|
| 772 |
static void unlink_all_urbs(struct esd_usb *dev) |
| 773 |
{ |
| 774 |
struct esd_usb_net_priv *priv; |
| 775 |
int i, j; |
| 776 |
|
| 777 |
usb_kill_anchored_urbs(&dev->rx_submitted); |
| 778 |
|
| 779 |
for (i = 0; i < ESD_USB_MAX_RX_URBS; ++i) |
| 780 |
usb_free_coherent(dev->udev, ESD_USB_RX_BUFFER_SIZE, |
| 781 |
dev->rxbuf[i], dev->rxbuf_dma[i]); |
| 782 |
|
| 783 |
for (i = 0; i < dev->net_count; i++) { |
| 784 |
priv = dev->nets[i]; |
| 785 |
if (priv) { |
| 786 |
usb_kill_anchored_urbs(&priv->tx_submitted); |
| 787 |
atomic_set(&priv->active_tx_jobs, 0); |
| 788 |
|
| 789 |
for (j = 0; j < ESD_USB_MAX_TX_URBS; j++) |
| 790 |
priv->tx_contexts[j].echo_index = ESD_USB_MAX_TX_URBS; |
| 791 |
} |
| 792 |
} |
| 793 |
} |
| 794 |
|
| 795 |
static int esd_usb_open(struct net_device *netdev) |
| 796 |
{ |
| 797 |
struct esd_usb_net_priv *priv = netdev_priv(netdev); |
| 798 |
int err; |
| 799 |
|
| 800 |
/* common open */ |
| 801 |
err = open_candev(netdev); |
| 802 |
if (err) |
| 803 |
return err; |
| 804 |
|
| 805 |
/* finally start device */ |
| 806 |
err = esd_usb_start(priv); |
| 807 |
if (err) { |
| 808 |
close_candev(netdev); |
| 809 |
return err; |
| 810 |
} |
| 811 |
|
| 812 |
netif_start_queue(netdev); |
| 813 |
|
| 814 |
return 0; |
| 815 |
} |
| 816 |
|
| 817 |
static netdev_tx_t esd_usb_start_xmit(struct sk_buff *skb, |
| 818 |
struct net_device *netdev) |
| 819 |
{ |
| 820 |
struct esd_usb_net_priv *priv = netdev_priv(netdev); |
| 821 |
struct esd_usb *dev = priv->usb; |
| 822 |
struct esd_tx_urb_context *context = NULL; |
| 823 |
struct net_device_stats *stats = &netdev->stats; |
| 824 |
struct canfd_frame *cfd = (struct canfd_frame *)skb->data; |
| 825 |
union esd_usb_msg *msg; |
| 826 |
struct urb *urb; |
| 827 |
u8 *buf; |
| 828 |
int i, err; |
| 829 |
int ret = NETDEV_TX_OK; |
| 830 |
size_t size = sizeof(union esd_usb_msg); |
| 831 |
|
| 832 |
if (can_dev_dropped_skb(netdev, skb)) |
| 833 |
return NETDEV_TX_OK; |
| 834 |
|
| 835 |
/* create a URB, and a buffer for it, and copy the data to the URB */ |
| 836 |
urb = usb_alloc_urb(0, GFP_ATOMIC); |
| 837 |
if (!urb) { |
| 838 |
stats->tx_dropped++; |
| 839 |
dev_kfree_skb(skb); |
| 840 |
goto nourbmem; |
| 841 |
} |
| 842 |
|
| 843 |
buf = usb_alloc_coherent(dev->udev, size, GFP_ATOMIC, |
| 844 |
&urb->transfer_dma); |
| 845 |
if (!buf) { |
| 846 |
netdev_err(netdev, "No memory left for USB buffer\n"); |
| 847 |
stats->tx_dropped++; |
| 848 |
dev_kfree_skb(skb); |
| 849 |
goto nobufmem; |
| 850 |
} |
| 851 |
|
| 852 |
msg = (union esd_usb_msg *)buf; |
| 853 |
|
| 854 |
/* minimal length as # of 32bit words */ |
| 855 |
msg->hdr.len = offsetof(struct esd_usb_tx_msg, data) / sizeof(u32); |
| 856 |
msg->hdr.cmd = ESD_USB_CMD_CAN_TX; |
| 857 |
msg->tx.net = priv->index; |
| 858 |
|
| 859 |
if (can_is_canfd_skb(skb)) { |
| 860 |
msg->tx.dlc = can_fd_len2dlc(cfd->len); |
| 861 |
msg->tx.dlc |= ESD_USB_FD; |
| 862 |
|
| 863 |
if ((cfd->flags & CANFD_BRS) == 0) |
| 864 |
msg->tx.dlc |= ESD_USB_NO_BRS; |
| 865 |
} else { |
| 866 |
msg->tx.dlc = can_get_cc_dlc((struct can_frame *)cfd, priv->can.ctrlmode); |
| 867 |
|
| 868 |
if (cfd->can_id & CAN_RTR_FLAG) |
| 869 |
msg->tx.dlc |= ESD_USB_RTR; |
| 870 |
} |
| 871 |
|
| 872 |
msg->tx.id = cpu_to_le32(cfd->can_id & CAN_ERR_MASK); |
| 873 |
|
| 874 |
if (cfd->can_id & CAN_EFF_FLAG) |
| 875 |
msg->tx.id |= cpu_to_le32(ESD_USB_EXTID); |
| 876 |
|
| 877 |
memcpy(msg->tx.data_fd, cfd->data, cfd->len); |
| 878 |
|
| 879 |
/* round up, then divide by 4 to add the payload length as # of 32bit words */ |
| 880 |
msg->hdr.len += DIV_ROUND_UP(cfd->len, sizeof(u32)); |
| 881 |
|
| 882 |
for (i = 0; i < ESD_USB_MAX_TX_URBS; i++) { |
| 883 |
if (priv->tx_contexts[i].echo_index == ESD_USB_MAX_TX_URBS) { |
| 884 |
context = &priv->tx_contexts[i]; |
| 885 |
break; |
| 886 |
} |
| 887 |
} |
| 888 |
|
| 889 |
/* This may never happen */ |
| 890 |
if (!context) { |
| 891 |
netdev_warn(netdev, "couldn't find free context\n"); |
| 892 |
ret = NETDEV_TX_BUSY; |
| 893 |
goto releasebuf; |
| 894 |
} |
| 895 |
|
| 896 |
context->priv = priv; |
| 897 |
context->echo_index = i; |
| 898 |
|
| 899 |
/* hnd must not be 0 - MSB is stripped in txdone handling */ |
| 900 |
msg->tx.hnd = BIT(31) | i; /* returned in TX done message */ |
| 901 |
|
| 902 |
usb_fill_bulk_urb(urb, dev->udev, dev->tx_pipe, buf, |
| 903 |
msg->hdr.len * sizeof(u32), /* convert to # of bytes */ |
| 904 |
esd_usb_write_bulk_callback, context); |
| 905 |
|
| 906 |
urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; |
| 907 |
|
| 908 |
usb_anchor_urb(urb, &priv->tx_submitted); |
| 909 |
|
| 910 |
can_put_echo_skb(skb, netdev, context->echo_index, 0); |
| 911 |
|
| 912 |
atomic_inc(&priv->active_tx_jobs); |
| 913 |
|
| 914 |
/* Slow down tx path */ |
| 915 |
if (atomic_read(&priv->active_tx_jobs) >= ESD_USB_MAX_TX_URBS) |
| 916 |
netif_stop_queue(netdev); |
| 917 |
|
| 918 |
err = usb_submit_urb(urb, GFP_ATOMIC); |
| 919 |
if (err) { |
| 920 |
can_free_echo_skb(netdev, context->echo_index, NULL); |
| 921 |
|
| 922 |
atomic_dec(&priv->active_tx_jobs); |
| 923 |
usb_unanchor_urb(urb); |
| 924 |
|
| 925 |
stats->tx_dropped++; |
| 926 |
|
| 927 |
if (err == -ENODEV) |
| 928 |
netif_device_detach(netdev); |
| 929 |
else |
| 930 |
netdev_warn(netdev, "failed tx_urb %pe\n", ERR_PTR(err)); |
| 931 |
|
| 932 |
goto releasebuf; |
| 933 |
} |
| 934 |
|
| 935 |
netif_trans_update(netdev); |
| 936 |
|
| 937 |
/* Release our reference to this URB, the USB core will eventually free |
| 938 |
* it entirely. |
| 939 |
*/ |
| 940 |
usb_free_urb(urb); |
| 941 |
|
| 942 |
return NETDEV_TX_OK; |
| 943 |
|
| 944 |
releasebuf: |
| 945 |
usb_free_coherent(dev->udev, size, buf, urb->transfer_dma); |
| 946 |
|
| 947 |
nobufmem: |
| 948 |
usb_free_urb(urb); |
| 949 |
|
| 950 |
nourbmem: |
| 951 |
return ret; |
| 952 |
} |
| 953 |
|
| 954 |
/* Stop interface */ |
| 955 |
static int esd_usb_stop(struct esd_usb_net_priv *priv) |
| 956 |
{ |
| 957 |
union esd_usb_msg *msg; |
| 958 |
int err; |
| 959 |
int i; |
| 960 |
|
| 961 |
msg = kmalloc_obj(*msg); |
| 962 |
if (!msg) |
| 963 |
return -ENOMEM; |
| 964 |
|
| 965 |
/* Disable all IDs (see esd_usb_start()) */ |
| 966 |
msg->hdr.cmd = ESD_USB_CMD_IDADD; |
| 967 |
msg->hdr.len = sizeof(struct esd_usb_id_filter_msg) / sizeof(u32);/* # of 32bit words */ |
| 968 |
msg->filter.net = priv->index; |
| 969 |
msg->filter.option = ESD_USB_ID_ENABLE; /* start with segment 0 */ |
| 970 |
for (i = 0; i <= ESD_USB_MAX_ID_SEGMENT; i++) |
| 971 |
msg->filter.mask[i] = 0; |
| 972 |
err = esd_usb_send_msg(priv->usb, msg); |
| 973 |
if (err < 0) { |
| 974 |
netdev_err(priv->netdev, "sending idadd message failed: %pe\n", ERR_PTR(err)); |
| 975 |
goto bail; |
| 976 |
} |
| 977 |
|
| 978 |
/* set CAN controller to reset mode */ |
| 979 |
msg->hdr.len = sizeof(struct esd_usb_set_baudrate_msg) / sizeof(u32); /* # of 32bit words */ |
| 980 |
msg->hdr.cmd = ESD_USB_CMD_SETBAUD; |
| 981 |
msg->setbaud.net = priv->index; |
| 982 |
msg->setbaud.rsvd = 0; |
| 983 |
msg->setbaud.baud = cpu_to_le32(ESD_USB_NO_BAUDRATE); |
| 984 |
err = esd_usb_send_msg(priv->usb, msg); |
| 985 |
if (err < 0) |
| 986 |
netdev_err(priv->netdev, "sending setbaud message failed: %pe\n", ERR_PTR(err)); |
| 987 |
|
| 988 |
bail: |
| 989 |
kfree(msg); |
| 990 |
|
| 991 |
return err; |
| 992 |
} |
| 993 |
|
| 994 |
static int esd_usb_close(struct net_device *netdev) |
| 995 |
{ |
| 996 |
struct esd_usb_net_priv *priv = netdev_priv(netdev); |
| 997 |
int err = 0; |
| 998 |
|
| 999 |
if (!priv->usb->in_usb_disconnect) { |
| 1000 |
/* It's moot to try this in usb_disconnect()! */ |
| 1001 |
err = esd_usb_stop(priv); |
| 1002 |
} |
| 1003 |
|
| 1004 |
priv->can.state = CAN_STATE_STOPPED; |
| 1005 |
|
| 1006 |
netif_stop_queue(netdev); |
| 1007 |
|
| 1008 |
close_candev(netdev); |
| 1009 |
|
| 1010 |
return err; |
| 1011 |
} |
| 1012 |
|
| 1013 |
static const struct net_device_ops esd_usb_netdev_ops = { |
| 1014 |
.ndo_open = esd_usb_open, |
| 1015 |
.ndo_stop = esd_usb_close, |
| 1016 |
.ndo_start_xmit = esd_usb_start_xmit, |
| 1017 |
}; |
| 1018 |
|
| 1019 |
static const struct ethtool_ops esd_usb_ethtool_ops = { |
| 1020 |
.get_ts_info = ethtool_op_get_ts_info, |
| 1021 |
}; |
| 1022 |
|
| 1023 |
static const struct can_bittiming_const esd_usb_2_bittiming_const = { |
| 1024 |
.name = "esd_usb_2", |
| 1025 |
.tseg1_min = 1, |
| 1026 |
.tseg1_max = 16, |
| 1027 |
.tseg2_min = 1, |
| 1028 |
.tseg2_max = 8, |
| 1029 |
.sjw_max = 4, |
| 1030 |
.brp_min = 1, |
| 1031 |
.brp_max = 1024, |
| 1032 |
.brp_inc = 1, |
| 1033 |
}; |
| 1034 |
|
| 1035 |
static int esd_usb_2_set_bittiming(struct net_device *netdev) |
| 1036 |
{ |
| 1037 |
const struct can_bittiming_const *btc = &esd_usb_2_bittiming_const; |
| 1038 |
struct esd_usb_net_priv *priv = netdev_priv(netdev); |
| 1039 |
struct can_bittiming *bt = &priv->can.bittiming; |
| 1040 |
union esd_usb_msg *msg; |
| 1041 |
int err; |
| 1042 |
u32 canbtr; |
| 1043 |
int sjw_shift; |
| 1044 |
|
| 1045 |
canbtr = ESD_USB_UBR; |
| 1046 |
if (priv->can.ctrlmode & CAN_CTRLMODE_LISTENONLY) |
| 1047 |
canbtr |= ESD_USB_LOM; |
| 1048 |
|
| 1049 |
canbtr |= (bt->brp - 1) & (btc->brp_max - 1); |
| 1050 |
|
| 1051 |
if (le16_to_cpu(priv->usb->udev->descriptor.idProduct) == |
| 1052 |
ESD_USB_CANUSBM_PRODUCT_ID) |
| 1053 |
sjw_shift = ESD_USB_M_SJW_SHIFT; |
| 1054 |
else |
| 1055 |
sjw_shift = ESD_USB_2_SJW_SHIFT; |
| 1056 |
|
| 1057 |
canbtr |= ((bt->sjw - 1) & (btc->sjw_max - 1)) |
| 1058 |
<< sjw_shift; |
| 1059 |
canbtr |= ((bt->prop_seg + bt->phase_seg1 - 1) |
| 1060 |
& (btc->tseg1_max - 1)) |
| 1061 |
<< ESD_USB_2_TSEG1_SHIFT; |
| 1062 |
canbtr |= ((bt->phase_seg2 - 1) & (btc->tseg2_max - 1)) |
| 1063 |
<< ESD_USB_2_TSEG2_SHIFT; |
| 1064 |
if (priv->can.ctrlmode & CAN_CTRLMODE_3_SAMPLES) |
| 1065 |
canbtr |= ESD_USB_TRIPLE_SAMPLES; |
| 1066 |
|
| 1067 |
msg = kmalloc_obj(*msg); |
| 1068 |
if (!msg) |
| 1069 |
return -ENOMEM; |
| 1070 |
|
| 1071 |
msg->hdr.len = sizeof(struct esd_usb_set_baudrate_msg) / sizeof(u32); /* # of 32bit words */ |
| 1072 |
msg->hdr.cmd = ESD_USB_CMD_SETBAUD; |
| 1073 |
msg->setbaud.net = priv->index; |
| 1074 |
msg->setbaud.rsvd = 0; |
| 1075 |
msg->setbaud.baud = cpu_to_le32(canbtr); |
| 1076 |
|
| 1077 |
netdev_dbg(netdev, "setting BTR=%#x\n", canbtr); |
| 1078 |
|
| 1079 |
err = esd_usb_send_msg(priv->usb, msg); |
| 1080 |
|
| 1081 |
kfree(msg); |
| 1082 |
return err; |
| 1083 |
} |
| 1084 |
|
| 1085 |
/* Nominal bittiming constants, see |
| 1086 |
* Microchip SAM E70/S70/V70/V71, Data Sheet, Rev. G - 07/2022 |
| 1087 |
* 48.6.8 MCAN Nominal Bit Timing and Prescaler Register |
| 1088 |
*/ |
| 1089 |
static const struct can_bittiming_const esd_usb_3_nom_bittiming_const = { |
| 1090 |
.name = "esd_usb_3", |
| 1091 |
.tseg1_min = 2, |
| 1092 |
.tseg1_max = 256, |
| 1093 |
.tseg2_min = 2, |
| 1094 |
.tseg2_max = 128, |
| 1095 |
.sjw_max = 128, |
| 1096 |
.brp_min = 1, |
| 1097 |
.brp_max = 512, |
| 1098 |
.brp_inc = 1, |
| 1099 |
}; |
| 1100 |
|
| 1101 |
/* Data bittiming constants, see |
| 1102 |
* Microchip SAM E70/S70/V70/V71, Data Sheet, Rev. G - 07/2022 |
| 1103 |
* 48.6.4 MCAN Data Bit Timing and Prescaler Register |
| 1104 |
*/ |
| 1105 |
static const struct can_bittiming_const esd_usb_3_data_bittiming_const = { |
| 1106 |
.name = "esd_usb_3", |
| 1107 |
.tseg1_min = 2, |
| 1108 |
.tseg1_max = 32, |
| 1109 |
.tseg2_min = 1, |
| 1110 |
.tseg2_max = 16, |
| 1111 |
.sjw_max = 8, |
| 1112 |
.brp_min = 1, |
| 1113 |
.brp_max = 32, |
| 1114 |
.brp_inc = 1, |
| 1115 |
}; |
| 1116 |
|
| 1117 |
static int esd_usb_3_set_bittiming(struct net_device *netdev) |
| 1118 |
{ |
| 1119 |
const struct can_bittiming_const *nom_btc = &esd_usb_3_nom_bittiming_const; |
| 1120 |
const struct can_bittiming_const *data_btc = &esd_usb_3_data_bittiming_const; |
| 1121 |
struct esd_usb_net_priv *priv = netdev_priv(netdev); |
| 1122 |
struct can_bittiming *nom_bt = &priv->can.bittiming; |
| 1123 |
struct can_bittiming *data_bt = &priv->can.fd.data_bittiming; |
| 1124 |
struct esd_usb_3_set_baudrate_msg_x *baud_x; |
| 1125 |
union esd_usb_msg *msg; |
| 1126 |
u16 flags = 0; |
| 1127 |
int err; |
| 1128 |
|
| 1129 |
msg = kmalloc_obj(*msg); |
| 1130 |
if (!msg) |
| 1131 |
return -ENOMEM; |
| 1132 |
|
| 1133 |
baud_x = &msg->setbaud_x; |
| 1134 |
|
| 1135 |
/* Canonical is the most reasonable mode for SocketCAN on CAN-USB/3 ... */ |
| 1136 |
baud_x->mode = cpu_to_le16(ESD_USB_3_BAUDRATE_MODE_BTR_CANONICAL); |
| 1137 |
|
| 1138 |
if (priv->can.ctrlmode & CAN_CTRLMODE_LISTENONLY) |
| 1139 |
flags |= ESD_USB_3_BAUDRATE_FLAG_LOM; |
| 1140 |
|
| 1141 |
baud_x->nom.brp = cpu_to_le16(nom_bt->brp & (nom_btc->brp_max - 1)); |
| 1142 |
baud_x->nom.sjw = cpu_to_le16(nom_bt->sjw & (nom_btc->sjw_max - 1)); |
| 1143 |
baud_x->nom.tseg1 = cpu_to_le16((nom_bt->prop_seg + nom_bt->phase_seg1) |
| 1144 |
& (nom_btc->tseg1_max - 1)); |
| 1145 |
baud_x->nom.tseg2 = cpu_to_le16(nom_bt->phase_seg2 & (nom_btc->tseg2_max - 1)); |
| 1146 |
|
| 1147 |
if (priv->can.ctrlmode & CAN_CTRLMODE_FD) { |
| 1148 |
baud_x->data.brp = cpu_to_le16(data_bt->brp & (data_btc->brp_max - 1)); |
| 1149 |
baud_x->data.sjw = cpu_to_le16(data_bt->sjw & (data_btc->sjw_max - 1)); |
| 1150 |
baud_x->data.tseg1 = cpu_to_le16((data_bt->prop_seg + data_bt->phase_seg1) |
| 1151 |
& (data_btc->tseg1_max - 1)); |
| 1152 |
baud_x->data.tseg2 = cpu_to_le16(data_bt->phase_seg2 & (data_btc->tseg2_max - 1)); |
| 1153 |
flags |= ESD_USB_3_BAUDRATE_FLAG_FD; |
| 1154 |
} |
| 1155 |
|
| 1156 |
/* Currently this driver only supports the automatic TDC mode */ |
| 1157 |
baud_x->tdc.tdc_mode = ESD_USB_3_TDC_MODE_AUTO; |
| 1158 |
baud_x->tdc.ssp_offset = 0; |
| 1159 |
baud_x->tdc.ssp_shift = 0; |
| 1160 |
baud_x->tdc.tdc_filter = 0; |
| 1161 |
|
| 1162 |
baud_x->flags = cpu_to_le16(flags); |
| 1163 |
baud_x->net = priv->index; |
| 1164 |
baud_x->rsvd = 0; |
| 1165 |
|
| 1166 |
/* set len as # of 32bit words */ |
| 1167 |
msg->hdr.len = sizeof(struct esd_usb_3_set_baudrate_msg_x) / sizeof(u32); |
| 1168 |
msg->hdr.cmd = ESD_USB_CMD_SETBAUD; |
| 1169 |
|
| 1170 |
netdev_dbg(netdev, |
| 1171 |
"ctrlmode=%#x/%#x, esd-net=%u, esd-mode=%#x, esd-flags=%#x\n", |
| 1172 |
priv->can.ctrlmode, priv->can.ctrlmode_supported, |
| 1173 |
priv->index, le16_to_cpu(baud_x->mode), flags); |
| 1174 |
|
| 1175 |
err = esd_usb_send_msg(priv->usb, msg); |
| 1176 |
|
| 1177 |
kfree(msg); |
| 1178 |
return err; |
| 1179 |
} |
| 1180 |
|
| 1181 |
static int esd_usb_get_berr_counter(const struct net_device *netdev, |
| 1182 |
struct can_berr_counter *bec) |
| 1183 |
{ |
| 1184 |
struct esd_usb_net_priv *priv = netdev_priv(netdev); |
| 1185 |
|
| 1186 |
bec->txerr = priv->bec.txerr; |
| 1187 |
bec->rxerr = priv->bec.rxerr; |
| 1188 |
|
| 1189 |
return 0; |
| 1190 |
} |
| 1191 |
|
| 1192 |
static int esd_usb_set_mode(struct net_device *netdev, enum can_mode mode) |
| 1193 |
{ |
| 1194 |
switch (mode) { |
| 1195 |
case CAN_MODE_START: |
| 1196 |
netif_wake_queue(netdev); |
| 1197 |
break; |
| 1198 |
|
| 1199 |
default: |
| 1200 |
return -EOPNOTSUPP; |
| 1201 |
} |
| 1202 |
|
| 1203 |
return 0; |
| 1204 |
} |
| 1205 |
|
| 1206 |
static int esd_usb_probe_one_net(struct usb_interface *intf, int index) |
| 1207 |
{ |
| 1208 |
struct esd_usb *dev = usb_get_intfdata(intf); |
| 1209 |
struct net_device *netdev; |
| 1210 |
struct esd_usb_net_priv *priv; |
| 1211 |
int err = 0; |
| 1212 |
int i; |
| 1213 |
|
| 1214 |
netdev = alloc_candev(sizeof(*priv), ESD_USB_MAX_TX_URBS); |
| 1215 |
if (!netdev) { |
| 1216 |
dev_err(&intf->dev, "couldn't alloc candev\n"); |
| 1217 |
err = -ENOMEM; |
| 1218 |
goto done; |
| 1219 |
} |
| 1220 |
|
| 1221 |
priv = netdev_priv(netdev); |
| 1222 |
|
| 1223 |
init_usb_anchor(&priv->tx_submitted); |
| 1224 |
atomic_set(&priv->active_tx_jobs, 0); |
| 1225 |
|
| 1226 |
for (i = 0; i < ESD_USB_MAX_TX_URBS; i++) |
| 1227 |
priv->tx_contexts[i].echo_index = ESD_USB_MAX_TX_URBS; |
| 1228 |
|
| 1229 |
priv->usb = dev; |
| 1230 |
priv->netdev = netdev; |
| 1231 |
priv->index = index; |
| 1232 |
|
| 1233 |
priv->can.state = CAN_STATE_STOPPED; |
| 1234 |
priv->can.ctrlmode_supported = CAN_CTRLMODE_LISTENONLY | |
| 1235 |
CAN_CTRLMODE_CC_LEN8_DLC | |
| 1236 |
CAN_CTRLMODE_BERR_REPORTING; |
| 1237 |
|
| 1238 |
switch (le16_to_cpu(dev->udev->descriptor.idProduct)) { |
| 1239 |
case ESD_USB_CANUSB3_PRODUCT_ID: |
| 1240 |
priv->can.clock.freq = ESD_USB_3_CAN_CLOCK; |
| 1241 |
priv->can.ctrlmode_supported |= CAN_CTRLMODE_FD; |
| 1242 |
priv->can.bittiming_const = &esd_usb_3_nom_bittiming_const; |
| 1243 |
priv->can.fd.data_bittiming_const = &esd_usb_3_data_bittiming_const; |
| 1244 |
priv->can.do_set_bittiming = esd_usb_3_set_bittiming; |
| 1245 |
priv->can.fd.do_set_data_bittiming = esd_usb_3_set_bittiming; |
| 1246 |
break; |
| 1247 |
|
| 1248 |
case ESD_USB_CANUSBM_PRODUCT_ID: |
| 1249 |
priv->can.clock.freq = ESD_USB_M_CAN_CLOCK; |
| 1250 |
priv->can.bittiming_const = &esd_usb_2_bittiming_const; |
| 1251 |
priv->can.do_set_bittiming = esd_usb_2_set_bittiming; |
| 1252 |
break; |
| 1253 |
|
| 1254 |
case ESD_USB_CANUSB2_PRODUCT_ID: |
| 1255 |
default: |
| 1256 |
priv->can.clock.freq = ESD_USB_2_CAN_CLOCK; |
| 1257 |
priv->can.ctrlmode_supported |= CAN_CTRLMODE_3_SAMPLES; |
| 1258 |
priv->can.bittiming_const = &esd_usb_2_bittiming_const; |
| 1259 |
priv->can.do_set_bittiming = esd_usb_2_set_bittiming; |
| 1260 |
break; |
| 1261 |
} |
| 1262 |
|
| 1263 |
priv->can.do_set_mode = esd_usb_set_mode; |
| 1264 |
priv->can.do_get_berr_counter = esd_usb_get_berr_counter; |
| 1265 |
|
| 1266 |
netdev->flags |= IFF_ECHO; /* we support local echo */ |
| 1267 |
|
| 1268 |
netdev->netdev_ops = &esd_usb_netdev_ops; |
| 1269 |
netdev->ethtool_ops = &esd_usb_ethtool_ops; |
| 1270 |
|
| 1271 |
SET_NETDEV_DEV(netdev, &intf->dev); |
| 1272 |
netdev->dev_id = index; |
| 1273 |
|
| 1274 |
err = register_candev(netdev); |
| 1275 |
if (err) { |
| 1276 |
dev_err(&intf->dev, "couldn't register CAN device: %pe\n", ERR_PTR(err)); |
| 1277 |
free_candev(netdev); |
| 1278 |
err = -ENOMEM; |
| 1279 |
goto done; |
| 1280 |
} |
| 1281 |
|
| 1282 |
dev->nets[index] = priv; |
| 1283 |
netdev_info(netdev, "registered\n"); |
| 1284 |
|
| 1285 |
done: |
| 1286 |
return err; |
| 1287 |
} |
| 1288 |
|
| 1289 |
/* probe function for new USB devices |
| 1290 |
* |
| 1291 |
* check version information and number of available |
| 1292 |
* CAN interfaces |
| 1293 |
*/ |
| 1294 |
static int esd_usb_probe(struct usb_interface *intf, |
| 1295 |
const struct usb_device_id *id) |
| 1296 |
{ |
| 1297 |
struct usb_endpoint_descriptor *ep_in, *ep_out; |
| 1298 |
struct esd_usb *dev; |
| 1299 |
union esd_usb_msg *msg; |
| 1300 |
int i, err; |
| 1301 |
|
| 1302 |
err = usb_find_common_endpoints(intf->cur_altsetting, &ep_in, &ep_out, |
| 1303 |
NULL, NULL); |
| 1304 |
if (err) |
| 1305 |
return err; |
| 1306 |
|
| 1307 |
dev = kzalloc_obj(*dev); |
| 1308 |
if (!dev) { |
| 1309 |
err = -ENOMEM; |
| 1310 |
goto done; |
| 1311 |
} |
| 1312 |
|
| 1313 |
dev->udev = interface_to_usbdev(intf); |
| 1314 |
dev->rx_pipe = usb_rcvbulkpipe(dev->udev, ep_in->bEndpointAddress); |
| 1315 |
dev->tx_pipe = usb_sndbulkpipe(dev->udev, ep_out->bEndpointAddress); |
| 1316 |
|
| 1317 |
init_usb_anchor(&dev->rx_submitted); |
| 1318 |
|
| 1319 |
usb_set_intfdata(intf, dev); |
| 1320 |
|
| 1321 |
msg = kmalloc_obj(*msg); |
| 1322 |
if (!msg) { |
| 1323 |
err = -ENOMEM; |
| 1324 |
goto free_msg; |
| 1325 |
} |
| 1326 |
|
| 1327 |
/* query number of CAN interfaces (nets) */ |
| 1328 |
msg->hdr.cmd = ESD_USB_CMD_VERSION; |
| 1329 |
msg->hdr.len = sizeof(struct esd_usb_version_msg) / sizeof(u32); /* # of 32bit words */ |
| 1330 |
msg->version.rsvd = 0; |
| 1331 |
msg->version.flags = 0; |
| 1332 |
msg->version.drv_version = 0; |
| 1333 |
|
| 1334 |
err = esd_usb_send_msg(dev, msg); |
| 1335 |
if (err < 0) { |
| 1336 |
dev_err(&intf->dev, "sending version message failed\n"); |
| 1337 |
goto free_msg; |
| 1338 |
} |
| 1339 |
|
| 1340 |
err = esd_usb_wait_msg(dev, msg); |
| 1341 |
if (err < 0) { |
| 1342 |
dev_err(&intf->dev, "no version message answer\n"); |
| 1343 |
goto free_msg; |
| 1344 |
} |
| 1345 |
|
| 1346 |
dev->net_count = (int)msg->version_reply.nets; |
| 1347 |
dev->version = le32_to_cpu(msg->version_reply.version); |
| 1348 |
|
| 1349 |
if (device_create_file(&intf->dev, &dev_attr_firmware)) |
| 1350 |
dev_err(&intf->dev, |
| 1351 |
"Couldn't create device file for firmware\n"); |
| 1352 |
|
| 1353 |
if (device_create_file(&intf->dev, &dev_attr_hardware)) |
| 1354 |
dev_err(&intf->dev, |
| 1355 |
"Couldn't create device file for hardware\n"); |
| 1356 |
|
| 1357 |
if (device_create_file(&intf->dev, &dev_attr_nets)) |
| 1358 |
dev_err(&intf->dev, |
| 1359 |
"Couldn't create device file for nets\n"); |
| 1360 |
|
| 1361 |
/* do per device probing */ |
| 1362 |
for (i = 0; i < dev->net_count; i++) |
| 1363 |
esd_usb_probe_one_net(intf, i); |
| 1364 |
|
| 1365 |
free_msg: |
| 1366 |
kfree(msg); |
| 1367 |
if (err) |
| 1368 |
kfree(dev); |
| 1369 |
done: |
| 1370 |
return err; |
| 1371 |
} |
| 1372 |
|
| 1373 |
/* called by the usb core when the device is removed from the system */ |
| 1374 |
static void esd_usb_disconnect(struct usb_interface *intf) |
| 1375 |
{ |
| 1376 |
struct esd_usb *dev = usb_get_intfdata(intf); |
| 1377 |
struct net_device *netdev; |
| 1378 |
int i; |
| 1379 |
|
| 1380 |
device_remove_file(&intf->dev, &dev_attr_firmware); |
| 1381 |
device_remove_file(&intf->dev, &dev_attr_hardware); |
| 1382 |
device_remove_file(&intf->dev, &dev_attr_nets); |
| 1383 |
|
| 1384 |
usb_set_intfdata(intf, NULL); |
| 1385 |
|
| 1386 |
if (dev) { |
| 1387 |
dev->in_usb_disconnect = 1; |
| 1388 |
for (i = 0; i < dev->net_count; i++) { |
| 1389 |
if (dev->nets[i]) { |
| 1390 |
netdev = dev->nets[i]->netdev; |
| 1391 |
netdev_info(netdev, "unregister\n"); |
| 1392 |
unregister_netdev(netdev); |
| 1393 |
free_candev(netdev); |
| 1394 |
} |
| 1395 |
} |
| 1396 |
unlink_all_urbs(dev); |
| 1397 |
kfree(dev); |
| 1398 |
} |
| 1399 |
} |
| 1400 |
|
| 1401 |
/* usb specific object needed to register this driver with the usb subsystem */ |
| 1402 |
static struct usb_driver esd_usb_driver = { |
| 1403 |
.name = KBUILD_MODNAME, |
| 1404 |
.probe = esd_usb_probe, |
| 1405 |
.disconnect = esd_usb_disconnect, |
| 1406 |
.id_table = esd_usb_table, |
| 1407 |
}; |
| 1408 |
|
| 1409 |
module_usb_driver(esd_usb_driver); |