^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /* SPDX-License-Identifier: GPL-2.0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) #ifndef __TARGET_USB_GADGET_H__
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) #define __TARGET_USB_GADGET_H__
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) #include <linux/kref.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) /* #include <linux/usb/uas.h> */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) #include <linux/usb/composite.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #include <linux/usb/uas.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #include <linux/usb/storage.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <target/target_core_base.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <target/target_core_fabric.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #define USBG_NAMELEN 32
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #define fuas_to_gadget(f) (f->function.config->cdev->gadget)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #define UASP_SS_EP_COMP_LOG_STREAMS 4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #define UASP_SS_EP_COMP_NUM_STREAMS (1 << UASP_SS_EP_COMP_LOG_STREAMS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) enum {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) USB_G_STR_INT_UAS = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) USB_G_STR_INT_BBB,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #define USB_G_ALT_INT_BBB 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #define USB_G_ALT_INT_UAS 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) #define USB_G_DEFAULT_SESSION_TAGS 128
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) struct tcm_usbg_nexus {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) struct se_session *tvn_se_sess;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) struct usbg_tpg {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) struct mutex tpg_mutex;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) /* SAS port target portal group tag for TCM */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) u16 tport_tpgt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) /* Pointer back to usbg_tport */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) struct usbg_tport *tport;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) struct workqueue_struct *workqueue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) /* Returned by usbg_make_tpg() */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) struct se_portal_group se_tpg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) u32 gadget_connect;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) struct tcm_usbg_nexus *tpg_nexus;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) atomic_t tpg_port_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) struct usb_function_instance *fi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) struct usbg_tport {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) /* Binary World Wide unique Port Name for SAS Target port */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) u64 tport_wwpn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) /* ASCII formatted WWPN for SAS Target port */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) char tport_name[USBG_NAMELEN];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) /* Returned by usbg_make_tport() */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) struct se_wwn tport_wwn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) enum uas_state {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) UASP_SEND_DATA,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) UASP_RECEIVE_DATA,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) UASP_SEND_STATUS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) UASP_QUEUE_COMMAND,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) #define USBG_MAX_CMD 64
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) struct usbg_cmd {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) /* common */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) u8 cmd_buf[USBG_MAX_CMD];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) u32 data_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) struct work_struct work;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) int unpacked_lun;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) struct se_cmd se_cmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) void *data_buf; /* used if no sg support available */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) struct f_uas *fu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) struct completion write_complete;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) struct kref ref;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) /* UAS only */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) u16 tag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) u16 prio_attr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) struct sense_iu sense_iu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) enum uas_state state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) struct uas_stream *stream;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) /* BOT only */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) __le32 bot_tag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) unsigned int csw_code;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) unsigned is_read:1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) struct uas_stream {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) struct usb_request *req_in;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) struct usb_request *req_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) struct usb_request *req_status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) struct usbg_cdb {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) struct usb_request *req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) void *buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) struct bot_status {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) struct usb_request *req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) struct bulk_cs_wrap csw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) struct f_uas {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) struct usbg_tpg *tpg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) struct usb_function function;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) u16 iface;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) u32 flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) #define USBG_ENABLED (1 << 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) #define USBG_IS_UAS (1 << 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) #define USBG_USE_STREAMS (1 << 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) #define USBG_IS_BOT (1 << 3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) #define USBG_BOT_CMD_PEND (1 << 4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) struct usbg_cdb cmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) struct usb_ep *ep_in;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) struct usb_ep *ep_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) /* UAS */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) struct usb_ep *ep_status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) struct usb_ep *ep_cmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) struct uas_stream stream[UASP_SS_EP_COMP_NUM_STREAMS];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) /* BOT */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) struct bot_status bot_status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) struct usb_request *bot_req_in;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) struct usb_request *bot_req_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) #endif /* __TARGET_USB_GADGET_H__ */