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