Changeset 9e5b162 in mainline


Ignore:
Timestamp:
2018-01-05T22:09:24Z (6 years ago)
Author:
Ondřej Hlavatý <aearsis@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
86650db
Parents:
35c37fc
Message:

usbdev: refactored usb_pipe_init

Finally.

Location:
uspace/lib
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/drv/include/usb_iface.h

    r35c37fc r9e5b162  
    103103 */
    104104typedef struct {
     105        unsigned max_burst;
     106        unsigned max_streams;
     107        unsigned mult;
     108        unsigned bytes_per_interval;
     109} usb3_endpoint_desc_t;
     110
     111typedef struct {
     112        unsigned polling_interval;
     113} usb2_endpoint_desc_t;
     114
     115typedef struct usb_endpoint_desc {
    105116        /** Endpoint number. */
    106117        usb_endpoint_t endpoint_no;
     
    122133        unsigned packets;
    123134
    124         struct {
    125                 unsigned polling_interval;
    126         } usb2;
    127 
    128         struct {
    129                 unsigned max_burst;
    130                 unsigned max_streams;
    131                 unsigned mult;
    132                 unsigned bytes_per_interval;
    133         } usb3;
     135        /** Bus version specific information */
     136        usb2_endpoint_desc_t usb2;
     137        usb3_endpoint_desc_t usb3;
    134138} usb_endpoint_desc_t;
    135139
  • uspace/lib/usbdev/include/usb/dev/pipes.h

    r35c37fc r9e5b162  
    100100} usb_endpoint_mapping_t;
    101101
    102 int usb_pipe_initialize(usb_pipe_t *, usb_endpoint_t, usb_transfer_type_t,
    103     size_t, usb_direction_t, unsigned, unsigned, unsigned, unsigned, unsigned, usb_dev_session_t *);
     102int usb_pipe_initialize(usb_pipe_t *, usb_dev_session_t *, const usb_endpoint_desc_t *);
    104103int usb_pipe_initialize_default_control(usb_pipe_t *, usb_dev_session_t *);
    105104
  • uspace/lib/usbdev/src/pipes.c

    r35c37fc r9e5b162  
    271271 *
    272272 * @param pipe Endpoint pipe to be initialized.
    273  * @param endpoint_no Endpoint number (in USB 1.1 in range 0 to 15).
    274  * @param transfer_type Transfer type (e.g. interrupt or bulk).
    275  * @param max_packet_size Maximum packet size in bytes.
    276  * @param direction Endpoint direction (in/out).
    277  * @return Error code.
    278  */
    279 int usb_pipe_initialize(usb_pipe_t *pipe, usb_endpoint_t endpoint_no,
    280     usb_transfer_type_t transfer_type, size_t max_packet_size,
    281     usb_direction_t direction, unsigned packets,
    282     unsigned max_burst, unsigned max_streams, unsigned bytes_per_interval,
    283         unsigned mult, usb_dev_session_t *bus_session)
     273 * @param bus_session Endpoint pipe to be initialized.
     274 * @param ep_desc Prepared endpoint descriptor
     275 * @return Error code.
     276 */
     277int usb_pipe_initialize(usb_pipe_t *pipe,
     278    usb_dev_session_t *bus_session,
     279    const usb_endpoint_desc_t *ep_desc)
    284280{
    285281        int ret = EOK;
    286         // FIXME: refactor this function PLEASE
    287         assert(pipe);
    288 
    289         pipe->desc.endpoint_no = endpoint_no;
    290         pipe->desc.transfer_type = transfer_type;
    291         pipe->desc.packets = packets;
    292         pipe->desc.max_packet_size = max_packet_size;
    293         pipe->desc.direction = direction;
    294         pipe->desc.usb3.max_burst = max_burst;
    295         pipe->desc.usb3.max_streams = max_streams;
    296         pipe->desc.usb3.mult = mult;
    297         pipe->desc.usb3.bytes_per_interval = bytes_per_interval;
     282        assert(pipe);
     283
     284        pipe->desc = *ep_desc;
    298285        pipe->auto_reset_halt = false;
    299286        pipe->bus_session = bus_session;
    300287
    301         // TODO: hardcoded, remake to receive from device descriptors
    302         pipe->desc.interval = 14;
    303 
    304         if (transfer_type == USB_TRANSFER_ISOCHRONOUS) {
     288        if (pipe->desc.transfer_type == USB_TRANSFER_ISOCHRONOUS) {
    305289                ret = usb_isoch_session_initialize(pipe);
    306290        }
     
    309293}
    310294
     295static const usb_endpoint_desc_t default_control_ep_desc = {
     296        .max_packet_size = CTRL_PIPE_MIN_PACKET_SIZE,
     297        .direction = USB_DIRECTION_BOTH,
     298        .packets = 1,
     299};
     300
    311301/** Initialize USB endpoint pipe as the default zero control pipe.
    312302 *
    313303 * @param pipe Endpoint pipe to be initialized.
    314  * @return Error code.
    315  */
    316 int usb_pipe_initialize_default_control(usb_pipe_t *pipe,
    317     usb_dev_session_t *bus_session)
    318 {
    319         assert(pipe);
    320 
    321         const int rc = usb_pipe_initialize(pipe, 0, USB_TRANSFER_CONTROL,
    322             CTRL_PIPE_MIN_PACKET_SIZE, USB_DIRECTION_BOTH, 1, 0, 0, 0, 0, bus_session);
    323 
    324         pipe->auto_reset_halt = true;
    325 
    326         return rc;
     304 * @param bus_session
     305 * @return Error code.
     306 */
     307int usb_pipe_initialize_default_control(usb_pipe_t *pipe, usb_dev_session_t *bus_session)
     308{
     309        return usb_pipe_initialize(pipe, bus_session, &default_control_ep_desc);
    327310}
    328311
  • uspace/lib/usbdev/src/pipesinit.c

    r35c37fc r9e5b162  
    208208        }
    209209
    210         unsigned max_burst = 0;
    211         unsigned max_streams = 0;
    212         unsigned bytes_per_interval = 0;
    213         unsigned mult = 0;
     210        usb_endpoint_desc_t ep_desc = {
     211                .endpoint_no = ep_no,
     212                .transfer_type = description.transfer_type,
     213                .direction = description.direction,
     214                // FIXME: USB2 max_packet_size is limited to 1023 bytes, 1024+ doesn't work for USB3
     215                // See 4.14.2.1.1 of XHCI specification -> possibly refactor into one somehow-named field
     216                .max_packet_size
     217                        = ED_MPS_PACKET_SIZE_GET(uint16_usb2host(endpoint_desc->max_packet_size)),
     218                .interval = endpoint_desc->poll_interval,
     219                // FIXME: USB2 packets and USB3 max_burst are probably the same thing
     220                .packets
     221                        = ED_MPS_TRANS_OPPORTUNITIES_GET(uint16_usb2host(endpoint_desc->max_packet_size)),
     222        };
     223
     224        /* TODO Extract USB2-related information */
     225        ep_desc.usb2 = (usb2_endpoint_desc_t) { 0 };
     226
    214227        if (companion_desc) {
    215                 max_burst = companion_desc->max_burst;
    216                 max_streams = SS_COMPANION_MAX_STREAMS(companion_desc->attributes);
    217                 bytes_per_interval = companion_desc->bytes_per_interval;
    218                 mult = SS_COMPANION_MULT(companion_desc->attributes);
    219         }
    220 
    221         // FIXME: USB2 packets and USB3 max_burst are probably the same thing
    222         // FIXME: USB2 max_packet_size is limited to 1023 bytes, 1024+ doesn't work for USB3
    223         // See 4.14.2.1.1 of XHCI specification -> possibly refactor into one somehow-named field
    224         int rc = usb_pipe_initialize(&ep_mapping->pipe,
    225             ep_no, description.transfer_type,
    226             ED_MPS_PACKET_SIZE_GET(
    227                 uint16_usb2host(endpoint_desc->max_packet_size)),
    228             description.direction, ED_MPS_TRANS_OPPORTUNITIES_GET(
    229                 uint16_usb2host(endpoint_desc->max_packet_size)),
    230             max_burst, max_streams, bytes_per_interval, mult, bus_session);
    231         if (rc != EOK) {
    232                 return rc;
    233         }
     228                ep_desc.usb3 = (usb3_endpoint_desc_t) {
     229                        .max_burst = companion_desc->max_burst,
     230                        .max_streams
     231                                = SS_COMPANION_MAX_STREAMS(companion_desc->attributes),
     232                        .bytes_per_interval
     233                                = companion_desc->bytes_per_interval,
     234                        .mult = SS_COMPANION_MULT(companion_desc->attributes),
     235                };
     236        }
     237
     238        int err = usb_pipe_initialize(&ep_mapping->pipe, bus_session, &ep_desc);
     239        if (err)
     240                return err;
    234241
    235242        ep_mapping->present = true;
Note: See TracChangeset for help on using the changeset viewer.