drivers/net/can/usb/peak_usb/pcan_usb.c
Source file repositories/reference/linux-study-clean/drivers/net/can/usb/peak_usb/pcan_usb.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/net/can/usb/peak_usb/pcan_usb.c- Extension
.c- Size
- 24938 bytes
- Lines
- 1057
- Domain
- Driver Families
- Bucket
- drivers/net
- Inferred role
- Driver Families: implementation source
- Status
- source implementation candidate
Why This File Exists
Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/unaligned.hlinux/ethtool.hlinux/module.hlinux/netdevice.hlinux/usb.hlinux/can.hlinux/can/dev.hlinux/can/error.hpcan_usb_core.h
Detected Declarations
struct pcan_usbstruct pcan_usb_msg_contextfunction pcan_usb_send_cmdfunction pcan_usb_wait_rspfunction pcan_usb_set_sja1000function pcan_usb_set_busfunction pcan_usb_set_silentfunction pcan_usb_set_err_framefunction pcan_usb_set_ext_vccfunction pcan_usb_set_ledfunction pcan_usb_set_bittimingfunction pcan_usb_write_modefunction pcan_usb_restartfunction pcan_usb_restart_pendingfunction pcan_usb_restart_asyncfunction pcan_usb_get_serialfunction pcan_usb_get_can_channel_idfunction pcan_usb_set_can_channel_idfunction pcan_usb_update_tsfunction pcan_usb_decode_tsfunction pcan_usb_decode_errorfunction pcan_usb_handle_bus_evtfunction pcan_usb_decode_statusfunction pcan_usb_decode_datafunction pcan_usb_decode_msgfunction pcan_usb_decode_buffunction pcan_usb_encode_msgfunction pcan_usb_get_berr_counterfunction pcan_usb_startfunction pcan_usb_initfunction pcan_usb_probefunction pcan_usb_set_phys_idfunction pcan_usb_get_eeprom_len
Annotated Snippet
struct pcan_usb {
struct peak_usb_device dev;
struct peak_time_ref time_ref;
struct timer_list restart_timer;
struct can_berr_counter bec;
};
/* incoming message context for decoding */
struct pcan_usb_msg_context {
u16 ts16;
u8 prev_ts8;
u8 *ptr;
u8 *end;
u8 rec_cnt;
u8 rec_idx;
u8 rec_ts_idx;
struct net_device *netdev;
struct pcan_usb *pdev;
};
/*
* send a command
*/
static int pcan_usb_send_cmd(struct peak_usb_device *dev, u8 f, u8 n, u8 *p)
{
int err;
int actual_length;
/* usb device unregistered? */
if (!(dev->state & PCAN_USB_STATE_CONNECTED))
return 0;
dev->cmd_buf[PCAN_USB_CMD_FUNC] = f;
dev->cmd_buf[PCAN_USB_CMD_NUM] = n;
if (p)
memcpy(dev->cmd_buf + PCAN_USB_CMD_ARGS,
p, PCAN_USB_CMD_ARGS_LEN);
err = usb_bulk_msg(dev->udev,
usb_sndbulkpipe(dev->udev, PCAN_USB_EP_CMDOUT),
dev->cmd_buf, PCAN_USB_CMD_LEN, &actual_length,
PCAN_USB_COMMAND_TIMEOUT);
if (err)
netdev_err(dev->netdev,
"sending cmd f=0x%x n=0x%x failure: %d\n",
f, n, err);
return err;
}
/*
* send a command then wait for its response
*/
static int pcan_usb_wait_rsp(struct peak_usb_device *dev, u8 f, u8 n, u8 *p)
{
int err;
int actual_length;
/* usb device unregistered? */
if (!(dev->state & PCAN_USB_STATE_CONNECTED))
return 0;
/* first, send command */
err = pcan_usb_send_cmd(dev, f, n, NULL);
if (err)
return err;
err = usb_bulk_msg(dev->udev,
usb_rcvbulkpipe(dev->udev, PCAN_USB_EP_CMDIN),
dev->cmd_buf, PCAN_USB_CMD_LEN, &actual_length,
PCAN_USB_COMMAND_TIMEOUT);
if (err)
netdev_err(dev->netdev,
"waiting rsp f=0x%x n=0x%x failure: %d\n", f, n, err);
else if (p)
memcpy(p, dev->cmd_buf + PCAN_USB_CMD_ARGS,
PCAN_USB_CMD_ARGS_LEN);
return err;
}
static int pcan_usb_set_sja1000(struct peak_usb_device *dev, u8 mode)
{
u8 args[PCAN_USB_CMD_ARGS_LEN] = {
[1] = mode,
};
return pcan_usb_send_cmd(dev, PCAN_USB_CMD_REGISTER, PCAN_USB_SET,
args);
}
Annotation
- Immediate include surface: `linux/unaligned.h`, `linux/ethtool.h`, `linux/module.h`, `linux/netdevice.h`, `linux/usb.h`, `linux/can.h`, `linux/can/dev.h`, `linux/can/error.h`.
- Detected declarations: `struct pcan_usb`, `struct pcan_usb_msg_context`, `function pcan_usb_send_cmd`, `function pcan_usb_wait_rsp`, `function pcan_usb_set_sja1000`, `function pcan_usb_set_bus`, `function pcan_usb_set_silent`, `function pcan_usb_set_err_frame`, `function pcan_usb_set_ext_vcc`, `function pcan_usb_set_led`.
- Atlas domain: Driver Families / drivers/net.
- Implementation status: source implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.