1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef __TARGET_USB_GADGET_H__
3 #define __TARGET_USB_GADGET_H__
5 #include <linux/kref.h>
6 /* #include <linux/usb/uas.h> */
7 #include <linux/hashtable.h>
8 #include <linux/usb/composite.h>
9 #include <linux/usb/uas.h>
10 #include <linux/usb/storage.h>
11 #include <target/target_core_base.h>
12 #include <target/target_core_fabric.h>
14 #define USBG_NAMELEN 32
16 #define fuas_to_gadget(f) (f->function.config->cdev->gadget)
17 #define UASP_SS_EP_COMP_LOG_STREAMS 5
18 #define UASP_SS_EP_COMP_NUM_STREAMS (1 << UASP_SS_EP_COMP_LOG_STREAMS)
20 #define USBG_NUM_CMDS (UASP_SS_EP_COMP_NUM_STREAMS + 1)
23 USB_G_STR_INT_UAS = 0,
27 #define USB_G_ALT_INT_BBB 0
28 #define USB_G_ALT_INT_UAS 1
30 #define USB_G_DEFAULT_SESSION_TAGS USBG_NUM_CMDS
32 struct tcm_usbg_nexus {
33 struct se_session *tvn_se_sess;
37 struct mutex tpg_mutex;
38 /* SAS port target portal group tag for TCM */
40 /* Pointer back to usbg_tport */
41 struct usbg_tport *tport;
42 struct workqueue_struct *workqueue;
43 /* Returned by usbg_make_tpg() */
44 struct se_portal_group se_tpg;
46 struct tcm_usbg_nexus *tpg_nexus;
47 atomic_t tpg_port_count;
49 struct usb_function_instance *fi;
53 /* Binary World Wide unique Port Name for SAS Target port */
55 /* ASCII formatted WWPN for SAS Target port */
56 char tport_name[USBG_NAMELEN];
57 /* Returned by usbg_make_tport() */
58 struct se_wwn tport_wwn;
68 #define USBG_MAX_CMD 64
71 u8 cmd_buf[USBG_MAX_CMD];
73 struct work_struct work;
76 void *data_buf; /* used if no sg support available */
80 struct usb_request *req;
83 #define USBG_CMD_PENDING_DATA_WRITE BIT(0)
88 struct sense_iu sense_iu;
89 struct response_iu response_iu;
94 #define RC_RESPONSE_UNKNOWN 0xff
98 unsigned int csw_code;
104 struct usb_request *req_in;
105 struct usb_request *req_out;
106 struct usb_request *req_status;
108 struct completion cmd_completion;
109 struct hlist_node node;
113 struct usb_request *req;
118 struct usb_request *req;
119 struct bulk_cs_wrap csw;
123 struct usbg_tpg *tpg;
124 struct usb_function function;
128 #define USBG_ENABLED (1 << 0)
129 #define USBG_IS_UAS (1 << 1)
130 #define USBG_USE_STREAMS (1 << 2)
131 #define USBG_IS_BOT (1 << 3)
132 #define USBG_BOT_CMD_PEND (1 << 4)
133 #define USBG_BOT_WEDGED (1 << 5)
135 struct usbg_cdb cmd[USBG_NUM_CMDS];
136 struct usb_ep *ep_in;
137 struct usb_ep *ep_out;
140 struct usb_ep *ep_status;
141 struct usb_ep *ep_cmd;
142 struct uas_stream stream[USBG_NUM_CMDS];
143 DECLARE_HASHTABLE(stream_hash, UASP_SS_EP_COMP_LOG_STREAMS);
146 struct bot_status bot_status;
147 struct usb_request *bot_req_in;
148 struct usb_request *bot_req_out;
151 #endif /* __TARGET_USB_GADGET_H__ */