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