| 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 | 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 | }; |
| 15 | |
| 16 | struct USB_SB_Desc { |
| 17 | volatile __u16 sw_len; |
| 18 | volatile __u16 command; |
| 19 | volatile unsigned long next; |
| 20 | volatile unsigned long buf; |
| 21 | }; |
| 22 | |
| 23 | struct USB_EP_Desc { |
| 24 | volatile __u16 hw_len; |
| 25 | volatile __u16 command; |
| 26 | volatile unsigned long sub; |
| 27 | volatile unsigned long next; |
| 28 | }; |
| 29 | |
| 30 | |
| 31 | /* Root Hub port status struct */ |
| 32 | struct crisv10_rh { |
| 33 | volatile __u16 wPortChange[2]; |
| 34 | volatile __u16 wPortStatusPrev[2]; |
| 35 | }; |
| 36 | |
| 37 | /* HCD description */ |
| 38 | struct crisv10_hcd { |
| 39 | spinlock_t lock; |
| 40 | __u8 num_ports; |
| 41 | __u8 running; |
| 42 | }; |
| 43 | |
| 44 | |
| 45 | /* Endpoint HC private data description */ |
| 46 | struct crisv10_ep_priv { |
| 47 | int epid; |
| 48 | }; |
| 49 | |
| 50 | /* Additional software state info for a USB Controller epid */ |
| 51 | struct etrax_epid { |
| 52 | __u8 inuse; /* !0 = setup in Etrax and used for a endpoint */ |
| 53 | __u8 disabled; /* !0 = Temporarly disabled to avoid resubmission */ |
| 54 | __u8 type; /* Setup as: PIPE_BULK, PIPE_CONTROL ... */ |
| 55 | __u8 out_traffic; /* !0 = This epid is for out traffic */ |
| 56 | }; |
| 57 | |
| 58 | /* Struct to hold information of scheduled later URB completion */ |
| 59 | struct urb_later_data { |
| 60 | struct delayed_work dws; |
| 61 | struct usb_hcd *hcd; |
| 62 | struct urb *urb; |
| 63 | int urb_num; |
| 64 | int status; |
| 65 | }; |
| 66 | |
| 67 | |
| 68 | typedef enum { |
| 69 | STARTED, |
| 70 | NOT_STARTED, |
| 71 | UNLINK, |
| 72 | } crisv10_urb_state_t; |
| 73 | |
| 74 | |
| 75 | struct crisv10_urb_priv { |
| 76 | /* Sequence number for this URB. Every new submited URB gets this from |
| 77 | a incrementing counter. Used when a URB is scheduled for later finish to |
| 78 | be sure that the intended URB hasn't already been completed (device |
| 79 | drivers has a tendency to reuse URBs once they are completed, causing us |
| 80 | to not be able to single old ones out only based on the URB pointer.) */ |
| 81 | __u32 urb_num; |
| 82 | |
| 83 | /* The first_sb field is used for freeing all SB descriptors belonging |
| 84 | to an urb. The corresponding ep descriptor's sub pointer cannot be |
| 85 | used for this since the DMA advances the sub pointer as it processes |
| 86 | the sb list. */ |
| 87 | struct USB_SB_Desc *first_sb; |
| 88 | |
| 89 | /* The last_sb field referes to the last SB descriptor that belongs to |
| 90 | this urb. This is important to know so we can free the SB descriptors |
| 91 | that ranges between first_sb and last_sb. */ |
| 92 | struct USB_SB_Desc *last_sb; |
| 93 | |
| 94 | /* The rx_offset field is used in ctrl and bulk traffic to keep track |
| 95 | of the offset in the urb's transfer_buffer where incoming data should be |
| 96 | copied to. */ |
| 97 | __u32 rx_offset; |
| 98 | |
| 99 | /* Counter used in isochronous transfers to keep track of the |
| 100 | number of packets received/transmitted. */ |
| 101 | __u32 isoc_packet_counter; |
| 102 | |
| 103 | /* Flag that marks if this Isoc Out URB has finished it's transfer. Used |
| 104 | because several URBs can be finished before list is processed */ |
| 105 | __u8 isoc_out_done; |
| 106 | |
| 107 | /* This field is used to pass information about the urb's current state |
| 108 | between the various interrupt handlers (thus marked volatile). */ |
| 109 | volatile crisv10_urb_state_t urb_state; |
| 110 | |
| 111 | /* In Ctrl transfers consist of (at least) 3 packets: SETUP, IN and ZOUT. |
| 112 | When DMA8 sub-channel 2 has processed the SB list for this sequence we |
| 113 | get a interrupt. We also get a interrupt for In transfers and which |
| 114 | one of these interrupts that comes first depends of data size and device. |
| 115 | To be sure that we have got both interrupts before we complete the URB |
| 116 | we have these to flags that shows which part that has completed. |
| 117 | We can then check when we get one of the interrupts that if the other has |
| 118 | occured it's safe for us to complete the URB, otherwise we set appropriate |
| 119 | flag and do the completion when we get the other interrupt. */ |
| 120 | volatile unsigned char ctrl_zout_done; |
| 121 | volatile unsigned char ctrl_rx_done; |
| 122 | |
| 123 | /* Connection between the submitted urb and ETRAX epid number */ |
| 124 | __u8 epid; |
| 125 | |
| 126 | /* The rx_data_list field is used for periodic traffic, to hold |
| 127 | received data for later processing in the the complete_urb functions, |
| 128 | where the data us copied to the urb's transfer_buffer. Basically, we |
| 129 | use this intermediate storage because we don't know when it's safe to |
| 130 | reuse the transfer_buffer (FIXME?). */ |
| 131 | struct list_head rx_data_list; |
| 132 | |
| 133 | |
| 134 | /* The interval time rounded up to closest 2^N */ |
| 135 | int interval; |
| 136 | |
| 137 | /* Pool of EP descriptors needed if it's a INTR transfer. |
| 138 | Amount of EPs in pool correspons to how many INTR that should |
| 139 | be inserted in TxIntrEPList (max 128, defined by MAX_INTR_INTERVAL) */ |
| 140 | struct USB_EP_Desc* intr_ep_pool[128]; |
| 141 | |
| 142 | /* The mount of EPs allocated for this INTR URB */ |
| 143 | int intr_ep_pool_length; |
| 144 | |
| 145 | /* Pointer to info struct if URB is scheduled to be finished later */ |
| 146 | struct urb_later_data* later_data; |
| 147 | |
| 148 | /* Allocated bandwidth for isochronous and interrupt traffic */ |
| 149 | int bandwidth; |
| 150 | }; |
| 151 | |
| 152 | |
| 153 | /* This struct is for passing data from the top half to the bottom half irq |
| 154 | handlers */ |
| 155 | struct crisv10_irq_reg { |
| 156 | struct usb_hcd* hcd; |
| 157 | __u32 r_usb_epid_attn; |
| 158 | __u8 r_usb_status; |
| 159 | __u16 r_usb_rh_port_status_1; |
| 160 | __u16 r_usb_rh_port_status_2; |
| 161 | __u32 r_usb_irq_mask_read; |
| 162 | __u32 r_usb_fm_number; |
| 163 | struct work_struct usb_bh; |
| 164 | }; |
| 165 | |
| 166 | |
| 167 | /* This struct is for passing data from the isoc top half to the isoc bottom |
| 168 | half. */ |
| 169 | struct crisv10_isoc_complete_data { |
| 170 | struct usb_hcd *hcd; |
| 171 | struct urb *urb; |
| 172 | struct work_struct usb_bh; |
| 173 | }; |
| 174 | |
| 175 | /* Entry item for URB lists for each endpint */ |
| 176 | typedef struct urb_entry |
| 177 | { |
| 178 | struct urb *urb; |
| 179 | struct list_head list; |
| 180 | } urb_entry_t; |
| 181 | |
| 182 | /* --------------------------------------------------------------------------- |
| 183 | Virtual Root HUB |
| 184 | ------------------------------------------------------------------------- */ |
| 185 | /* destination of request */ |
| 186 | #define RH_INTERFACE 0x01 |
| 187 | #define RH_ENDPOINT 0x02 |
| 188 | #define RH_OTHER 0x03 |
| 189 | |
| 190 | #define RH_CLASS 0x20 |
| 191 | #define RH_VENDOR 0x40 |
| 192 | |
| 193 | /* Requests: bRequest << 8 | bmRequestType */ |
| 194 | #define RH_GET_STATUS 0x0080 |
| 195 | #define RH_CLEAR_FEATURE 0x0100 |
| 196 | #define RH_SET_FEATURE 0x0300 |
| 197 | #define RH_SET_ADDRESS 0x0500 |
| 198 | #define RH_GET_DESCRIPTOR 0x0680 |
| 199 | #define RH_SET_DESCRIPTOR 0x0700 |
| 200 | #define RH_GET_CONFIGURATION 0x0880 |
| 201 | #define RH_SET_CONFIGURATION 0x0900 |
| 202 | #define RH_GET_STATE 0x0280 |
| 203 | #define RH_GET_INTERFACE 0x0A80 |
| 204 | #define RH_SET_INTERFACE 0x0B00 |
| 205 | #define RH_SYNC_FRAME 0x0C80 |
| 206 | /* Our Vendor Specific Request */ |
| 207 | #define RH_SET_EP 0x2000 |
| 208 | |
| 209 | |
| 210 | /* Hub port features */ |
| 211 | #define RH_PORT_CONNECTION 0x00 |
| 212 | #define RH_PORT_ENABLE 0x01 |
| 213 | #define RH_PORT_SUSPEND 0x02 |
| 214 | #define RH_PORT_OVER_CURRENT 0x03 |
| 215 | #define RH_PORT_RESET 0x04 |
| 216 | #define RH_PORT_POWER 0x08 |
| 217 | #define RH_PORT_LOW_SPEED 0x09 |
| 218 | #define RH_C_PORT_CONNECTION 0x10 |
| 219 | #define RH_C_PORT_ENABLE 0x11 |
| 220 | #define RH_C_PORT_SUSPEND 0x12 |
| 221 | #define RH_C_PORT_OVER_CURRENT 0x13 |
| 222 | #define RH_C_PORT_RESET 0x14 |
| 223 | |
| 224 | /* Hub features */ |
| 225 | #define RH_C_HUB_LOCAL_POWER 0x00 |
| 226 | #define RH_C_HUB_OVER_CURRENT 0x01 |
| 227 | |
| 228 | #define RH_DEVICE_REMOTE_WAKEUP 0x00 |
| 229 | #define RH_ENDPOINT_STALL 0x01 |
| 230 | |
| 231 | /* Our Vendor Specific feature */ |
| 232 | #define RH_REMOVE_EP 0x00 |
| 233 | |
| 234 | |
| 235 | #define RH_ACK 0x01 |
| 236 | #define RH_REQ_ERR -1 |
| 237 | #define RH_NACK 0x00 |
| 238 | |
| 239 | /* Field definitions for */ |
| 240 | |
| 241 | #define USB_IN_command__eol__BITNR 0 /* command macros */ |
| 242 | #define USB_IN_command__eol__WIDTH 1 |
| 243 | #define USB_IN_command__eol__no 0 |
| 244 | #define USB_IN_command__eol__yes 1 |
| 245 | |
| 246 | #define USB_IN_command__intr__BITNR 3 |
| 247 | #define USB_IN_command__intr__WIDTH 1 |
| 248 | #define USB_IN_command__intr__no 0 |
| 249 | #define USB_IN_command__intr__yes 1 |
| 250 | |
| 251 | #define USB_IN_status__eop__BITNR 1 /* status macros. */ |
| 252 | #define USB_IN_status__eop__WIDTH 1 |
| 253 | #define USB_IN_status__eop__no 0 |
| 254 | #define USB_IN_status__eop__yes 1 |
| 255 | |
| 256 | #define USB_IN_status__eot__BITNR 5 |
| 257 | #define USB_IN_status__eot__WIDTH 1 |
| 258 | #define USB_IN_status__eot__no 0 |
| 259 | #define USB_IN_status__eot__yes 1 |
| 260 | |
| 261 | #define USB_IN_status__error__BITNR 6 |
| 262 | #define USB_IN_status__error__WIDTH 1 |
| 263 | #define USB_IN_status__error__no 0 |
| 264 | #define USB_IN_status__error__yes 1 |
| 265 | |
| 266 | #define USB_IN_status__nodata__BITNR 7 |
| 267 | #define USB_IN_status__nodata__WIDTH 1 |
| 268 | #define USB_IN_status__nodata__no 0 |
| 269 | #define USB_IN_status__nodata__yes 1 |
| 270 | |
| 271 | #define USB_IN_status__epid__BITNR 8 |
| 272 | #define USB_IN_status__epid__WIDTH 5 |
| 273 | |
| 274 | #define USB_EP_command__eol__BITNR 0 |
| 275 | #define USB_EP_command__eol__WIDTH 1 |
| 276 | #define USB_EP_command__eol__no 0 |
| 277 | #define USB_EP_command__eol__yes 1 |
| 278 | |
| 279 | #define USB_EP_command__eof__BITNR 1 |
| 280 | #define USB_EP_command__eof__WIDTH 1 |
| 281 | #define USB_EP_command__eof__no 0 |
| 282 | #define USB_EP_command__eof__yes 1 |
| 283 | |
| 284 | #define USB_EP_command__intr__BITNR 3 |
| 285 | #define USB_EP_command__intr__WIDTH 1 |
| 286 | #define USB_EP_command__intr__no 0 |
| 287 | #define USB_EP_command__intr__yes 1 |
| 288 | |
| 289 | #define USB_EP_command__enable__BITNR 4 |
| 290 | #define USB_EP_command__enable__WIDTH 1 |
| 291 | #define USB_EP_command__enable__no 0 |
| 292 | #define USB_EP_command__enable__yes 1 |
| 293 | |
| 294 | #define USB_EP_command__hw_valid__BITNR 5 |
| 295 | #define USB_EP_command__hw_valid__WIDTH 1 |
| 296 | #define USB_EP_command__hw_valid__no 0 |
| 297 | #define USB_EP_command__hw_valid__yes 1 |
| 298 | |
| 299 | #define USB_EP_command__epid__BITNR 8 |
| 300 | #define USB_EP_command__epid__WIDTH 5 |
| 301 | |
| 302 | #define USB_SB_command__eol__BITNR 0 /* command macros. */ |
| 303 | #define USB_SB_command__eol__WIDTH 1 |
| 304 | #define USB_SB_command__eol__no 0 |
| 305 | #define USB_SB_command__eol__yes 1 |
| 306 | |
| 307 | #define USB_SB_command__eot__BITNR 1 |
| 308 | #define USB_SB_command__eot__WIDTH 1 |
| 309 | #define USB_SB_command__eot__no 0 |
| 310 | #define USB_SB_command__eot__yes 1 |
| 311 | |
| 312 | #define USB_SB_command__intr__BITNR 3 |
| 313 | #define USB_SB_command__intr__WIDTH 1 |
| 314 | #define USB_SB_command__intr__no 0 |
| 315 | #define USB_SB_command__intr__yes 1 |
| 316 | |
| 317 | #define USB_SB_command__tt__BITNR 4 |
| 318 | #define USB_SB_command__tt__WIDTH 2 |
| 319 | #define USB_SB_command__tt__zout 0 |
| 320 | #define USB_SB_command__tt__in 1 |
| 321 | #define USB_SB_command__tt__out 2 |
| 322 | #define USB_SB_command__tt__setup 3 |
| 323 | |
| 324 | |
| 325 | #define USB_SB_command__rem__BITNR 8 |
| 326 | #define USB_SB_command__rem__WIDTH 6 |
| 327 | |
| 328 | #define USB_SB_command__full__BITNR 6 |
| 329 | #define USB_SB_command__full__WIDTH 1 |
| 330 | #define USB_SB_command__full__no 0 |
| 331 | #define USB_SB_command__full__yes 1 |
| 332 | |
| 333 | #endif |
| 334 | |
| 335 | |