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