Changeset b3c39690 in mainline for uspace/drv/nic


Ignore:
Timestamp:
2018-01-21T23:19:20Z (8 years ago)
Author:
Ondřej Hlavatý <aearsis@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
db51a6a6
Parents:
09187c6e
git-author:
Ondřej Hlavatý <aearsis@…> (2018-01-21 23:19:14)
git-committer:
Ondřej Hlavatý <aearsis@…> (2018-01-21 23:19:20)
Message:

usb: remove misleading usb_device_get_mapped_ep

Even though this method may seem very convenient to use, it's actually
wrong. The devices are usually not required to have strict endpoint
numbers. That's why the mapping mechanism exists. Therefore, it's just
not possible to rely on fixed endpoint mapping.

There could be similar method, that would take the transfer type and
direction, but it's much better to ask for the complete mapping then.

Location:
uspace/drv/nic/ar9271
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/nic/ar9271/ar9271.c

    r09187c6e rb3c39690  
    665665}
    666666
    667 static int ar9271_init(ar9271_t *ar9271, usb_device_t *usb_device)
     667static int ar9271_init(ar9271_t *ar9271, usb_device_t *usb_device, const usb_endpoint_description_t **endpoints)
    668668{
    669669        ar9271->starting_up = true;
     
    679679        }
    680680       
    681         int rc = ath_usb_init(ar9271->ath_device, usb_device);
     681        int rc = ath_usb_init(ar9271->ath_device, usb_device, endpoints);
    682682        if (rc != EOK) {
    683683                free(ar9271->ath_device);
     
    850850        ar9271->ddf_dev = dev;
    851851       
    852         rc = ar9271_init(ar9271, usb_device_get(dev));
     852        rc = ar9271_init(ar9271, usb_device_get(dev), endpoints);
    853853        if (rc != EOK) {
    854854                free(ar9271);
  • uspace/drv/nic/ar9271/ath_usb.c

    r09187c6e rb3c39690  
    5959 *
    6060 */
    61 int ath_usb_init(ath_t *ath, usb_device_t *usb_device)
     61int ath_usb_init(ath_t *ath, usb_device_t *usb_device, const usb_endpoint_description_t **endpoints)
    6262{
    6363        ath_usb_t *ath_usb = malloc(sizeof(ath_usb_t));
     
    7070        ath_usb->usb_device = usb_device;
    7171       
    72         /* TODO: Assign by iterating over pipes. */
    73         ath_usb->output_data_pipe_number = 0;
    74         ath_usb->input_data_pipe_number = 1;
    75         ath_usb->input_ctrl_pipe_number = 2;
    76         ath_usb->output_ctrl_pipe_number = 3;
     72        int rc;
     73
     74#define _MAP_EP(target, ep_no) do {\
     75        usb_endpoint_mapping_t *epm = usb_device_get_mapped_ep_desc(usb_device, endpoints[ep_no]);\
     76        if (!epm || !epm->present) {\
     77                usb_log_error("Failed to map endpoint: " #ep_no ".");\
     78                rc = ENOENT;\
     79                goto err_ath_usb;\
     80        }\
     81        target = &epm->pipe;\
     82        } while (0);
     83
     84        _MAP_EP(ath_usb->output_data_pipe, 0);
     85        _MAP_EP(ath_usb->input_data_pipe, 1);
     86        _MAP_EP(ath_usb->input_ctrl_pipe, 2);
     87        _MAP_EP(ath_usb->output_ctrl_pipe, 3);
     88
     89#undef _MAP_EP
    7790       
    7891        ath->ctrl_response_length = 64;
     
    8396       
    8497        return EOK;
     98err_ath_usb:
     99        free(ath_usb);
     100        return rc;
    85101}
    86102
     
    98114{
    99115        ath_usb_t *ath_usb = (ath_usb_t *) ath->specific_data;
    100         usb_pipe_t *pipe = &usb_device_get_mapped_ep(
    101             ath_usb->usb_device, ath_usb->output_ctrl_pipe_number)->pipe;
    102        
    103         return usb_pipe_write(pipe, buffer, buffer_size);
     116        return usb_pipe_write(ath_usb->output_ctrl_pipe, buffer, buffer_size);
    104117}
    105118
     
    118131{
    119132        ath_usb_t *ath_usb = (ath_usb_t *) ath->specific_data;
    120         usb_pipe_t *pipe = &usb_device_get_mapped_ep(
    121             ath_usb->usb_device, ath_usb->input_ctrl_pipe_number)->pipe;
    122        
    123         return usb_pipe_read(pipe, buffer, buffer_size, transferred_size);
     133        return usb_pipe_read(ath_usb->input_ctrl_pipe, buffer, buffer_size, transferred_size);
    124134}
    125135
     
    148158       
    149159        ath_usb_t *ath_usb = (ath_usb_t *) ath->specific_data;
    150         usb_pipe_t *pipe = &usb_device_get_mapped_ep(
    151             ath_usb->usb_device, ath_usb->output_data_pipe_number)->pipe;
    152        
    153         int ret_val = usb_pipe_write(pipe, complete_buffer,
     160        int ret_val = usb_pipe_write(ath_usb->output_data_pipe, complete_buffer,
    154161            complete_buffer_size);
    155162       
     
    173180{
    174181        ath_usb_t *ath_usb = (ath_usb_t *) ath->specific_data;
    175         usb_pipe_t *pipe = &usb_device_get_mapped_ep(
    176             ath_usb->usb_device, ath_usb->input_data_pipe_number)->pipe;
    177        
    178         return usb_pipe_read(pipe, buffer, buffer_size, transferred_size);
     182        return usb_pipe_read(ath_usb->input_data_pipe, buffer, buffer_size, transferred_size);
    179183}
  • uspace/drv/nic/ar9271/ath_usb.h

    r09187c6e rb3c39690  
    4545typedef struct {
    4646        /** USB pipes indexes */
    47         int input_ctrl_pipe_number;
    48         int output_ctrl_pipe_number;
    49         int input_data_pipe_number;
    50         int output_data_pipe_number;
     47        usb_pipe_t *input_ctrl_pipe;
     48        usb_pipe_t *output_ctrl_pipe;
     49        usb_pipe_t *input_data_pipe;
     50        usb_pipe_t *output_data_pipe;
    5151       
    5252        /** Pointer to connected USB device. */
     
    5959} ath_usb_data_header_t;
    6060
    61 extern int ath_usb_init(ath_t *, usb_device_t *);
     61extern int ath_usb_init(ath_t *, usb_device_t *, const usb_endpoint_description_t **endpoints);
    6262
    6363#endif  /* ATHEROS_ATH_USB_H */
Note: See TracChangeset for help on using the changeset viewer.