Debian Codegraph @

drivers/usb/gadget/function/tcm.h

raw
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef __TARGET_USB_GADGET_H__
3 #define __TARGET_USB_GADGET_H__
4
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>
13
14 #define USBG_NAMELEN 32
15
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)
19
20 #define USBG_NUM_CMDS (UASP_SS_EP_COMP_NUM_STREAMS + 1)
21
22 enum {
23 USB_G_STR_INT_UAS = 0,
24 USB_G_STR_INT_BBB,
25 };
26
27 #define USB_G_ALT_INT_BBB 0
28 #define USB_G_ALT_INT_UAS 1
29
30 #define USB_G_DEFAULT_SESSION_TAGS USBG_NUM_CMDS
31
32 struct tcm_usbg_nexus {
33 struct se_session *tvn_se_sess;
34 };
35
36 struct usbg_tpg {
37 struct mutex tpg_mutex;
38 /* SAS port target portal group tag for TCM */
39 u16 tport_tpgt;
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;
45 u32 gadget_connect;
46 struct tcm_usbg_nexus *tpg_nexus;
47 atomic_t tpg_port_count;
48
49 struct usb_function_instance *fi;
50 };
51
52 struct usbg_tport {
53 /* Binary World Wide unique Port Name for SAS Target port */
54 u64 tport_wwpn;
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;
59 };
60
61 enum uas_state {
62 UASP_SEND_DATA,
63 UASP_RECEIVE_DATA,
64 UASP_SEND_STATUS,
65 UASP_QUEUE_COMMAND,
66 };
67
68 #define USBG_MAX_CMD 64
69 struct usbg_cmd {
70 /* common */
71 u8 cmd_buf[USBG_MAX_CMD];
72 u32 data_len;
73 struct work_struct work;
74 int unpacked_lun;
75 struct se_cmd se_cmd;
76 void *data_buf; /* used if no sg support available */
77 struct f_uas *fu;
78 struct kref ref;
79
80 struct usb_request *req;
81
82 u32 flags;
83 #define USBG_CMD_PENDING_DATA_WRITE BIT(0)
84
85 /* UAS only */
86 u16 tag;
87 u16 prio_attr;
88 struct sense_iu sense_iu;
89 struct response_iu response_iu;
90 enum uas_state state;
91
92 int tmr_func;
93 int tmr_rsp;
94 #define RC_RESPONSE_UNKNOWN 0xff
95
96 /* BOT only */
97 __le32 bot_tag;
98 unsigned int csw_code;
99 unsigned is_read:1;
100
101 };
102
103 struct uas_stream {
104 struct usb_request *req_in;
105 struct usb_request *req_out;
106 struct usb_request *req_status;
107
108 struct completion cmd_completion;
109 struct hlist_node node;
110 };
111
112 struct usbg_cdb {
113 struct usb_request *req;
114 void *buf;
115 };
116
117 struct bot_status {
118 struct usb_request *req;
119 struct bulk_cs_wrap csw;
120 };
121
122 struct f_uas {
123 struct usbg_tpg *tpg;
124 struct usb_function function;
125 u16 iface;
126
127 u32 flags;
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)
134
135 struct usbg_cdb cmd[USBG_NUM_CMDS];
136 struct usb_ep *ep_in;
137 struct usb_ep *ep_out;
138
139 /* UAS */
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);
144
145 /* BOT */
146 struct bot_status bot_status;
147 struct usb_request *bot_req_in;
148 struct usb_request *bot_req_out;
149 };
150
151 #endif /* __TARGET_USB_GADGET_H__ */