1 #ifndef __LINUX_ETRAX_USB_H
2 #define __LINUX_ETRAX_USB_H
3 
4 #include <linux/types.h>
5 #include <linux/list.h>
6 
7 typedef struct USB_IN_Desc {
8 	volatile __u16 sw_len;
9 	volatile __u16 command;
10 	volatile unsigned long next;
11 	volatile unsigned long buf;
12         volatile __u16 hw_len;
13 	volatile __u16 status;
14 } USB_IN_Desc_t;
15 
16 typedef struct USB_SB_Desc {
17 	volatile __u16 sw_len;
18 	volatile __u16 command;
19 	volatile unsigned long next;
20 	volatile unsigned long buf;
21 	__u32 dummy;
22 } USB_SB_Desc_t;
23 
24 typedef struct USB_EP_Desc {
25 	volatile __u16 hw_len;
26 	volatile __u16 command;
27 	volatile unsigned long sub;
28 	volatile unsigned long next;
29 	__u32 dummy;
30 } USB_EP_Desc_t;
31 
32 struct virt_root_hub {
33 	int devnum;
34 	void *urb;
35 	void *int_addr;
36 	int send;
37 	int interval;
38 	int numports;
39 	struct timer_list rh_int_timer;
40 	volatile __u16 wPortChange_1;
41 	volatile __u16 wPortChange_2;
42 	volatile __u16 prev_wPortStatus_1;
43 	volatile __u16 prev_wPortStatus_2;
44 };
45 
46 struct etrax_usb_intr_traffic {
47 	int sleeping;
48 	int error;
49 	struct wait_queue *wq;
50 };
51 
52 typedef struct etrax_usb_hc {
53 	struct usb_bus *bus;
54 	struct virt_root_hub rh;
55 	struct etrax_usb_intr_traffic intr;
56 } etrax_hc_t;
57 
58 typedef enum {
59         STARTED,
60         NOT_STARTED,
61         UNLINK
62 } etrax_usb_urb_state_t;
63 
64 
65 
66 typedef struct etrax_usb_urb_priv {
67         /* The first_sb field is used for freeing all SB descriptors belonging
68            to an urb. The corresponding ep descriptor's sub pointer cannot be
69            used for this since the DMA advances the sub pointer as it processes
70            the sb list. */
71 	USB_SB_Desc_t *first_sb;
72 	/* The last_sb field referes to the last SB descriptor that belongs to
73            this urb. This is important to know so we can free the SB descriptors
74 	   that ranges between first_sb and last_sb. */
75 	USB_SB_Desc_t *last_sb;
76 
77         /* The rx_offset field is used in ctrl and bulk traffic to keep track
78            of the offset in the urb's transfer_buffer where incoming data should be
79            copied to. */
80 	__u32 rx_offset;
81 
82 	/* Counter used in isochronous transfers to keep track of the
83 	   number of packets received/transmitted.  */
84         __u32 isoc_packet_counter;
85 
86         /* This field is used to pass information about the urb's current state between
87            the various interrupt handlers (thus marked volatile). */
88 	volatile etrax_usb_urb_state_t urb_state;
89 
90 	/* Connection between the submitted urb and ETRAX epid number */
91 	__u8 epid;
92 
93         /* The rx_data_list field is used for periodic traffic, to hold
94            received data for later processing in the the complete_urb functions,
95            where the data us copied to the urb's transfer_buffer. Basically, we
96            use this intermediate storage because we don't know when it's safe to
97            reuse the transfer_buffer (FIXME?). */
98 	struct list_head rx_data_list;
99 } etrax_urb_priv_t;
100 
101 /* This struct is for passing data from the top half to the bottom half. */
102 typedef struct usb_interrupt_registers
103 {
104 	etrax_hc_t *hc;
105 	__u32 r_usb_epid_attn;
106 	__u8 r_usb_status;
107 	__u16 r_usb_rh_port_status_1;
108 	__u16 r_usb_rh_port_status_2;
109 	__u32 r_usb_irq_mask_read;
110         __u32 r_usb_fm_number;
111 	struct tq_struct usb_bh;
112 } usb_interrupt_registers_t;
113 
114 /* This struct holds data we get from the rx descriptors for DMA channel 9
115    for periodic traffic (intr and isoc). */
116 typedef struct rx_data
117 {
118 	void *data;
119 	int length;
120 	struct list_head list;
121 } rx_data_t;
122 
123 typedef struct urb_entry
124 {
125         urb_t *urb;
126 	struct list_head list;
127 } urb_entry_t;
128 
129 /* ---------------------------------------------------------------------------
130    Virtual Root HUB
131    ------------------------------------------------------------------------- */
132 /* destination of request */
133 #define RH_INTERFACE               0x01
134 #define RH_ENDPOINT                0x02
135 #define RH_OTHER                   0x03
136 
137 #define RH_CLASS                   0x20
138 #define RH_VENDOR                  0x40
139 
140 /* Requests: bRequest << 8 | bmRequestType */
141 #define RH_GET_STATUS           0x0080
142 #define RH_CLEAR_FEATURE        0x0100
143 #define RH_SET_FEATURE          0x0300
144 #define RH_SET_ADDRESS		0x0500
145 #define RH_GET_DESCRIPTOR	0x0680
146 #define RH_SET_DESCRIPTOR       0x0700
147 #define RH_GET_CONFIGURATION	0x0880
148 #define RH_SET_CONFIGURATION	0x0900
149 #define RH_GET_STATE            0x0280
150 #define RH_GET_INTERFACE        0x0A80
151 #define RH_SET_INTERFACE        0x0B00
152 #define RH_SYNC_FRAME           0x0C80
153 /* Our Vendor Specific Request */
154 #define RH_SET_EP               0x2000
155 
156 
157 /* Hub port features */
158 #define RH_PORT_CONNECTION         0x00
159 #define RH_PORT_ENABLE             0x01
160 #define RH_PORT_SUSPEND            0x02
161 #define RH_PORT_OVER_CURRENT       0x03
162 #define RH_PORT_RESET              0x04
163 #define RH_PORT_POWER              0x08
164 #define RH_PORT_LOW_SPEED          0x09
165 #define RH_C_PORT_CONNECTION       0x10
166 #define RH_C_PORT_ENABLE           0x11
167 #define RH_C_PORT_SUSPEND          0x12
168 #define RH_C_PORT_OVER_CURRENT     0x13
169 #define RH_C_PORT_RESET            0x14
170 
171 /* Hub features */
172 #define RH_C_HUB_LOCAL_POWER       0x00
173 #define RH_C_HUB_OVER_CURRENT      0x01
174 
175 #define RH_DEVICE_REMOTE_WAKEUP    0x00
176 #define RH_ENDPOINT_STALL          0x01
177 
178 /* Our Vendor Specific feature */
179 #define RH_REMOVE_EP               0x00
180 
181 
182 #define RH_ACK                     0x01
183 #define RH_REQ_ERR                 -1
184 #define RH_NACK                    0x00
185 
186 /* Field definitions for */
187 
188 #define USB_IN_command__eol__BITNR      0 /* command macros */
189 #define USB_IN_command__eol__WIDTH      1
190 #define USB_IN_command__eol__no         0
191 #define USB_IN_command__eol__yes        1
192 
193 #define USB_IN_command__intr__BITNR     3
194 #define USB_IN_command__intr__WIDTH     1
195 #define USB_IN_command__intr__no        0
196 #define USB_IN_command__intr__yes       1
197 
198 #define USB_IN_status__eop__BITNR       1 /* status macros. */
199 #define USB_IN_status__eop__WIDTH       1
200 #define USB_IN_status__eop__no          0
201 #define USB_IN_status__eop__yes         1
202 
203 #define USB_IN_status__eot__BITNR       5
204 #define USB_IN_status__eot__WIDTH       1
205 #define USB_IN_status__eot__no          0
206 #define USB_IN_status__eot__yes         1
207 
208 #define USB_IN_status__error__BITNR     6
209 #define USB_IN_status__error__WIDTH     1
210 #define USB_IN_status__error__no        0
211 #define USB_IN_status__error__yes       1
212 
213 #define USB_IN_status__nodata__BITNR    7
214 #define USB_IN_status__nodata__WIDTH    1
215 #define USB_IN_status__nodata__no       0
216 #define USB_IN_status__nodata__yes      1
217 
218 #define USB_IN_status__epid__BITNR      8
219 #define USB_IN_status__epid__WIDTH      5
220 
221 #define USB_EP_command__eol__BITNR      0
222 #define USB_EP_command__eol__WIDTH      1
223 #define USB_EP_command__eol__no         0
224 #define USB_EP_command__eol__yes        1
225 
226 #define USB_EP_command__eof__BITNR      1
227 #define USB_EP_command__eof__WIDTH      1
228 #define USB_EP_command__eof__no         0
229 #define USB_EP_command__eof__yes        1
230 
231 #define USB_EP_command__intr__BITNR     3
232 #define USB_EP_command__intr__WIDTH     1
233 #define USB_EP_command__intr__no        0
234 #define USB_EP_command__intr__yes       1
235 
236 #define USB_EP_command__enable__BITNR   4
237 #define USB_EP_command__enable__WIDTH   1
238 #define USB_EP_command__enable__no      0
239 #define USB_EP_command__enable__yes     1
240 
241 #define USB_EP_command__hw_valid__BITNR 5
242 #define USB_EP_command__hw_valid__WIDTH 1
243 #define USB_EP_command__hw_valid__no    0
244 #define USB_EP_command__hw_valid__yes   1
245 
246 #define USB_EP_command__epid__BITNR     8
247 #define USB_EP_command__epid__WIDTH     5
248 
249 #define USB_SB_command__eol__BITNR      0 /* command macros. */
250 #define USB_SB_command__eol__WIDTH      1
251 #define USB_SB_command__eol__no         0
252 #define USB_SB_command__eol__yes        1
253 
254 #define USB_SB_command__eot__BITNR      1
255 #define USB_SB_command__eot__WIDTH      1
256 #define USB_SB_command__eot__no         0
257 #define USB_SB_command__eot__yes        1
258 
259 #define USB_SB_command__intr__BITNR     3
260 #define USB_SB_command__intr__WIDTH     1
261 #define USB_SB_command__intr__no        0
262 #define USB_SB_command__intr__yes       1
263 
264 #define USB_SB_command__tt__BITNR       4
265 #define USB_SB_command__tt__WIDTH       2
266 #define USB_SB_command__tt__zout        0
267 #define USB_SB_command__tt__in          1
268 #define USB_SB_command__tt__out         2
269 #define USB_SB_command__tt__setup       3
270 
271 
272 #define USB_SB_command__rem__BITNR      8
273 #define USB_SB_command__rem__WIDTH      6
274 
275 #define USB_SB_command__full__BITNR     6
276 #define USB_SB_command__full__WIDTH     1
277 #define USB_SB_command__full__no        0
278 #define USB_SB_command__full__yes       1
279 
280 #endif
281