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