Merge branch 'perf-urgent-for-linus' of git://git.kernel.org/pub/scm/linux/kernel...
[firefly-linux-kernel-4.4.55.git] / drivers / usb / gadget / legacy / tcm_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
18 enum {
19         USB_G_STR_CONFIG = USB_GADGET_FIRST_AVAIL_IDX,
20         USB_G_STR_INT_UAS,
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 struct usbg_nacl {
28         /* Binary World Wide unique Port Name for SAS Initiator port */
29         u64 iport_wwpn;
30         /* ASCII formatted WWPN for Sas Initiator port */
31         char iport_name[USBG_NAMELEN];
32         /* Returned by usbg_make_nodeacl() */
33         struct se_node_acl se_node_acl;
34 };
35
36 struct tcm_usbg_nexus {
37         struct se_session *tvn_se_sess;
38 };
39
40 struct usbg_tpg {
41         struct mutex tpg_mutex;
42         /* SAS port target portal group tag for TCM */
43         u16 tport_tpgt;
44         /* Pointer back to usbg_tport */
45         struct usbg_tport *tport;
46         struct workqueue_struct *workqueue;
47         /* Returned by usbg_make_tpg() */
48         struct se_portal_group se_tpg;
49         u32 gadget_connect;
50         struct tcm_usbg_nexus *tpg_nexus;
51         atomic_t tpg_port_count;
52 };
53
54 struct usbg_tport {
55         /* SCSI protocol the tport is providing */
56         u8 tport_proto_id;
57         /* Binary World Wide unique Port Name for SAS Target port */
58         u64 tport_wwpn;
59         /* ASCII formatted WWPN for SAS Target port */
60         char tport_name[USBG_NAMELEN];
61         /* Returned by usbg_make_tport() */
62         struct se_wwn tport_wwn;
63 };
64
65 enum uas_state {
66         UASP_SEND_DATA,
67         UASP_RECEIVE_DATA,
68         UASP_SEND_STATUS,
69         UASP_QUEUE_COMMAND,
70 };
71
72 #define USBG_MAX_CMD    64
73 struct usbg_cmd {
74         /* common */
75         u8 cmd_buf[USBG_MAX_CMD];
76         u32 data_len;
77         struct work_struct work;
78         int unpacked_lun;
79         struct se_cmd se_cmd;
80         void *data_buf; /* used if no sg support available */
81         struct f_uas *fu;
82         struct completion write_complete;
83         struct kref ref;
84
85         /* UAS only */
86         u16 tag;
87         u16 prio_attr;
88         struct sense_iu sense_iu;
89         enum uas_state state;
90         struct uas_stream *stream;
91
92         /* BOT only */
93         __le32 bot_tag;
94         unsigned int csw_code;
95         unsigned is_read:1;
96
97 };
98
99 struct uas_stream {
100         struct usb_request      *req_in;
101         struct usb_request      *req_out;
102         struct usb_request      *req_status;
103 };
104
105 struct usbg_cdb {
106         struct usb_request      *req;
107         void                    *buf;
108 };
109
110 struct bot_status {
111         struct usb_request      *req;
112         struct bulk_cs_wrap     csw;
113 };
114
115 struct f_uas {
116         struct usbg_tpg         *tpg;
117         struct usb_function     function;
118         u16                     iface;
119
120         u32                     flags;
121 #define USBG_ENABLED            (1 << 0)
122 #define USBG_IS_UAS             (1 << 1)
123 #define USBG_USE_STREAMS        (1 << 2)
124 #define USBG_IS_BOT             (1 << 3)
125 #define USBG_BOT_CMD_PEND       (1 << 4)
126
127         struct usbg_cdb         cmd;
128         struct usb_ep           *ep_in;
129         struct usb_ep           *ep_out;
130
131         /* UAS */
132         struct usb_ep           *ep_status;
133         struct usb_ep           *ep_cmd;
134         struct uas_stream       stream[UASP_SS_EP_COMP_NUM_STREAMS];
135
136         /* BOT */
137         struct bot_status       bot_status;
138         struct usb_request      *bot_req_in;
139         struct usb_request      *bot_req_out;
140 };
141
142 extern struct usbg_tpg *the_only_tpg_I_currently_have;
143
144 #endif