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