linux/drivers/usb/usbip/usbip_common.h

// SPDX-License-Identifier: GPL-2.0+
/*
 * Copyright (C) 2003-2008 Takahiro Hirofuchi
 * Copyright (C) 2015-2016 Samsung Electronics
 *               Krzysztof Opasiak <[email protected]>
 */

#ifndef __USBIP_COMMON_H
#define __USBIP_COMMON_H

#include <linux/compiler.h>
#include <linux/device.h>
#include <linux/interrupt.h>
#include <linux/net.h>
#include <linux/printk.h>
#include <linux/spinlock.h>
#include <linux/types.h>
#include <linux/usb.h>
#include <linux/wait.h>
#include <linux/sched/task.h>
#include <linux/kcov.h>
#include <uapi/linux/usbip.h>

#undef pr_fmt

#ifdef DEBUG
#define pr_fmt(fmt)
#else
#define pr_fmt
#endif

enum {};

#define usbip_dbg_flag_xmit
#define usbip_dbg_flag_vhci_rh
#define usbip_dbg_flag_vhci_hc
#define usbip_dbg_flag_vhci_rx
#define usbip_dbg_flag_vhci_tx
#define usbip_dbg_flag_stub_rx
#define usbip_dbg_flag_stub_tx
#define usbip_dbg_flag_vhci_sysfs

extern unsigned long usbip_debug_flag;
extern struct device_attribute dev_attr_usbip_debug;

#define usbip_dbg_with_flag(flag, fmt, args...)

#define usbip_dbg_sysfs(fmt, args...)
#define usbip_dbg_xmit(fmt, args...)
#define usbip_dbg_urb(fmt, args...)
#define usbip_dbg_eh(fmt, args...)

#define usbip_dbg_vhci_rh(fmt, args...)
#define usbip_dbg_vhci_hc(fmt, args...)
#define usbip_dbg_vhci_rx(fmt, args...)
#define usbip_dbg_vhci_tx(fmt, args...)
#define usbip_dbg_vhci_sysfs(fmt, args...)

#define usbip_dbg_stub_cmp(fmt, args...)
#define usbip_dbg_stub_rx(fmt, args...)
#define usbip_dbg_stub_tx(fmt, args...)

/*
 * USB/IP request headers
 *
 * Each request is transferred across the network to its counterpart, which
 * facilitates the normal USB communication. The values contained in the headers
 * are basically the same as in a URB. Currently, four request types are
 * defined:
 *
 *  - USBIP_CMD_SUBMIT: a USB request block, corresponds to usb_submit_urb()
 *    (client to server)
 *
 *  - USBIP_RET_SUBMIT: the result of USBIP_CMD_SUBMIT
 *    (server to client)
 *
 *  - USBIP_CMD_UNLINK: an unlink request of a pending USBIP_CMD_SUBMIT,
 *    corresponds to usb_unlink_urb()
 *    (client to server)
 *
 *  - USBIP_RET_UNLINK: the result of USBIP_CMD_UNLINK
 *    (server to client)
 *
 */
#define USBIP_CMD_SUBMIT
#define USBIP_CMD_UNLINK
#define USBIP_RET_SUBMIT
#define USBIP_RET_UNLINK

#define USBIP_DIR_OUT
#define USBIP_DIR_IN

/*
 * Arbitrary limit for the maximum number of isochronous packets in an URB,
 * compare for example the uhci_submit_isochronous function in
 * drivers/usb/host/uhci-q.c
 */
#define USBIP_MAX_ISO_PACKETS

/**
 * struct usbip_header_basic - data pertinent to every request
 * @command: the usbip request type
 * @seqnum: sequential number that identifies requests; incremented per
 *	    connection
 * @devid: specifies a remote USB device uniquely instead of busnum and devnum;
 *	   in the stub driver, this value is ((busnum << 16) | devnum)
 * @direction: direction of the transfer
 * @ep: endpoint number
 */
struct usbip_header_basic {} __packed;

/**
 * struct usbip_header_cmd_submit - USBIP_CMD_SUBMIT packet header
 * @transfer_flags: URB flags
 * @transfer_buffer_length: the data size for (in) or (out) transfer
 * @start_frame: initial frame for isochronous or interrupt transfers
 * @number_of_packets: number of isochronous packets
 * @interval: maximum time for the request on the server-side host controller
 * @setup: setup data for a control request
 */
struct usbip_header_cmd_submit {} __packed;

/**
 * struct usbip_header_ret_submit - USBIP_RET_SUBMIT packet header
 * @status: return status of a non-iso request
 * @actual_length: number of bytes transferred
 * @start_frame: initial frame for isochronous or interrupt transfers
 * @number_of_packets: number of isochronous packets
 * @error_count: number of errors for isochronous transfers
 */
struct usbip_header_ret_submit {} __packed;

/**
 * struct usbip_header_cmd_unlink - USBIP_CMD_UNLINK packet header
 * @seqnum: the URB seqnum to unlink
 */
struct usbip_header_cmd_unlink {} __packed;

/**
 * struct usbip_header_ret_unlink - USBIP_RET_UNLINK packet header
 * @status: return status of the request
 */
struct usbip_header_ret_unlink {} __packed;

/**
 * struct usbip_header - common header for all usbip packets
 * @base: the basic header
 * @u: packet type dependent header
 */
struct usbip_header {} __packed;

/*
 * This is the same as usb_iso_packet_descriptor but packed for pdu.
 */
struct usbip_iso_packet_descriptor {} __packed;

enum usbip_side {};

/* event handler */
#define USBIP_EH_SHUTDOWN
#define USBIP_EH_BYE
#define USBIP_EH_RESET
#define USBIP_EH_UNUSABLE

#define SDEV_EVENT_REMOVED
#define SDEV_EVENT_DOWN
#define SDEV_EVENT_ERROR_TCP
#define SDEV_EVENT_ERROR_SUBMIT
#define SDEV_EVENT_ERROR_MALLOC

#define VUDC_EVENT_REMOVED
#define VUDC_EVENT_DOWN
#define VUDC_EVENT_ERROR_TCP
/* catastrophic emulated usb error */
#define VUDC_EVENT_ERROR_USB
#define VUDC_EVENT_ERROR_MALLOC

#define VDEV_EVENT_REMOVED
#define VDEV_EVENT_DOWN
#define VDEV_EVENT_ERROR_TCP
#define VDEV_EVENT_ERROR_MALLOC

/* a common structure for stub_device and vhci_device */
struct usbip_device {};

#define kthread_get_run(threadfn, data, namefmt, ...)

/* usbip_common.c */
void usbip_dump_urb(struct urb *purb);
void usbip_dump_header(struct usbip_header *pdu);

int usbip_recv(struct socket *sock, void *buf, int size);

void usbip_pack_pdu(struct usbip_header *pdu, struct urb *urb, int cmd,
		    int pack);
void usbip_header_correct_endian(struct usbip_header *pdu, int send);

struct usbip_iso_packet_descriptor*
usbip_alloc_iso_desc_pdu(struct urb *urb, ssize_t *bufflen);

/* some members of urb must be substituted before. */
int usbip_recv_iso(struct usbip_device *ud, struct urb *urb);
void usbip_pad_iso(struct usbip_device *ud, struct urb *urb);
int usbip_recv_xbuff(struct usbip_device *ud, struct urb *urb);

/* usbip_event.c */
int usbip_init_eh(void);
void usbip_finish_eh(void);
int usbip_start_eh(struct usbip_device *ud);
void usbip_stop_eh(struct usbip_device *ud);
void usbip_event_add(struct usbip_device *ud, unsigned long event);
int usbip_event_happened(struct usbip_device *ud);
int usbip_in_eh(struct task_struct *task);

static inline int interface_to_busnum(struct usb_interface *interface)
{}

static inline int interface_to_devnum(struct usb_interface *interface)
{}

#ifdef CONFIG_KCOV

static inline void usbip_kcov_handle_init(struct usbip_device *ud)
{}

static inline void usbip_kcov_remote_start(struct usbip_device *ud)
{}

static inline void usbip_kcov_remote_stop(void)
{}

#else /* CONFIG_KCOV */

static inline void usbip_kcov_handle_init(struct usbip_device *ud) { }
static inline void usbip_kcov_remote_start(struct usbip_device *ud) { }
static inline void usbip_kcov_remote_stop(void) { }

#endif /* CONFIG_KCOV */

#endif /* __USBIP_COMMON_H */