Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/bus/usb/vhc/transfer.c

    rd369b3b r58563585  
    3131#include <usb/debug.h>
    3232#include <usbvirt/device.h>
    33 #include <usb/host/bandwidth.h>
    34 #include <usb/host/endpoint.h>
    35 #include <usb/host/usb_transfer_batch.h>
    3633#include <usbvirt/ipc.h>
    3734#include "vhcd.h"
     
    4037static bool is_set_address_transfer(vhc_transfer_t *transfer)
    4138{
    42         if (transfer->batch.target.endpoint != 0) {
    43                 return false;
    44         }
    45         if (transfer->batch.ep->transfer_type != USB_TRANSFER_CONTROL) {
    46                 return false;
    47         }
    48         if (transfer->batch.dir != USB_DIRECTION_OUT) {
    49                 return false;
    50         }
    51         const usb_device_request_setup_packet_t *setup
    52                 = &transfer->batch.setup.packet;
     39        if (transfer->batch->ep->endpoint != 0) {
     40                return false;
     41        }
     42        if (transfer->batch->ep->transfer_type != USB_TRANSFER_CONTROL) {
     43                return false;
     44        }
     45        if (usb_transfer_batch_direction(transfer->batch) != USB_DIRECTION_OUT) {
     46                return false;
     47        }
     48        const usb_device_request_setup_packet_t *setup =
     49            (void*)transfer->batch->setup_buffer;
    5350        if (setup->request_type != 0) {
    5451                return false;
     
    6562{
    6663        int rc;
    67 
    68         const usb_direction_t dir = batch->dir;
     64       
     65        const usb_direction_t dir = usb_transfer_batch_direction(batch);
    6966
    7067        if (batch->ep->transfer_type == USB_TRANSFER_CONTROL) {
    7168                if (dir == USB_DIRECTION_IN) {
    7269                        rc = usbvirt_control_read(dev,
    73                             batch->setup.buffer, USB_SETUP_PACKET_SIZE,
     70                            batch->setup_buffer, batch->setup_size,
    7471                            batch->buffer, batch->buffer_size,
    7572                            actual_data_size);
     
    7774                        assert(dir == USB_DIRECTION_OUT);
    7875                        rc = usbvirt_control_write(dev,
    79                             batch->setup.buffer, USB_SETUP_PACKET_SIZE,
     76                            batch->setup_buffer, batch->setup_size,
    8077                            batch->buffer, batch->buffer_size);
    8178                }
     
    10299        int rc;
    103100
    104         const usb_direction_t dir = batch->dir;
     101        const usb_direction_t dir = usb_transfer_batch_direction(batch);
    105102
    106103        if (batch->ep->transfer_type == USB_TRANSFER_CONTROL) {
    107104                if (dir == USB_DIRECTION_IN) {
    108105                        rc = usbvirt_ipc_send_control_read(sess,
    109                             batch->setup.buffer, USB_SETUP_PACKET_SIZE,
     106                            batch->setup_buffer, batch->setup_size,
    110107                            batch->buffer, batch->buffer_size,
    111108                            actual_data_size);
     
    113110                        assert(dir == USB_DIRECTION_OUT);
    114111                        rc = usbvirt_ipc_send_control_write(sess,
    115                             batch->setup.buffer, USB_SETUP_PACKET_SIZE,
     112                            batch->setup_buffer, batch->setup_size,
    116113                            batch->buffer, batch->buffer_size);
    117114                }
     
    150147        assert(outcome != ENAK);
    151148        assert(transfer);
    152         transfer->batch.error = outcome;
    153         transfer->batch.transferred_size = data_transfer_size;
    154         usb_transfer_batch_finish(&transfer->batch);
    155 }
    156 
    157 static usb_transfer_batch_t *batch_create(endpoint_t *ep)
    158 {
    159         vhc_transfer_t *transfer = calloc(1, sizeof(vhc_transfer_t));
    160         usb_transfer_batch_init(&transfer->batch, ep);
    161         link_initialize(&transfer->link);
    162         return &transfer->batch;
    163 }
    164 
    165 static int device_enumerate(device_t *device)
    166 {
    167         vhc_data_t *vhc = bus_to_vhc(device->bus);
    168         return usb2_bus_device_enumerate(&vhc->bus_helper, device);
    169 }
    170 
    171 static int endpoint_register(endpoint_t *endpoint)
    172 {
    173         vhc_data_t *vhc = bus_to_vhc(endpoint->device->bus);
    174         return usb2_bus_endpoint_register(&vhc->bus_helper, endpoint);
    175 }
    176 
    177 static void endpoint_unregister(endpoint_t *endpoint)
    178 {
    179         vhc_data_t *vhc = bus_to_vhc(endpoint->device->bus);
    180         usb2_bus_endpoint_unregister(&vhc->bus_helper, endpoint);
    181 
    182         // TODO: abort transfer?
    183 }
    184 
    185 static const bus_ops_t vhc_bus_ops = {
    186         .batch_create = batch_create,
    187         .batch_schedule = vhc_schedule,
    188 
    189         .device_enumerate = device_enumerate,
    190         .endpoint_register = endpoint_register,
    191         .endpoint_unregister = endpoint_unregister,
    192 };
     149        assert(transfer->batch);
     150        usb_transfer_batch_finish_error(transfer->batch, NULL,
     151            data_transfer_size, outcome);
     152        usb_transfer_batch_destroy(transfer->batch);
     153        free(transfer);
     154}
    193155
    194156int vhc_init(vhc_data_t *instance)
     
    197159        list_initialize(&instance->devices);
    198160        fibril_mutex_initialize(&instance->guard);
    199         bus_init(&instance->bus, sizeof(device_t));
    200         usb2_bus_helper_init(&instance->bus_helper, &bandwidth_accounting_usb11);
    201         instance->bus.ops = &vhc_bus_ops;
     161        instance->magic = 0xDEADBEEF;
    202162        return virthub_init(&instance->hub, "root hub");
    203163}
    204164
    205 int vhc_schedule(usb_transfer_batch_t *batch)
    206 {
     165int vhc_schedule(hcd_t *hcd, usb_transfer_batch_t *batch)
     166{
     167        assert(hcd);
    207168        assert(batch);
    208         vhc_transfer_t *transfer = (vhc_transfer_t *) batch;
    209         vhc_data_t *vhc = bus_to_vhc(endpoint_get_bus(batch->ep));
     169        vhc_data_t *vhc = hcd_get_driver_data(hcd);
    210170        assert(vhc);
     171
     172        vhc_transfer_t *transfer = malloc(sizeof(vhc_transfer_t));
     173        if (!transfer)
     174                return ENOMEM;
     175        link_initialize(&transfer->link);
     176        transfer->batch = batch;
    211177
    212178        fibril_mutex_lock(&vhc->guard);
     
    216182        list_foreach(vhc->devices, link, vhc_virtdev_t, dev) {
    217183                fibril_mutex_lock(&dev->guard);
    218                 if (dev->address == transfer->batch.target.address) {
     184                if (dev->address == transfer->batch->ep->address) {
    219185                        if (!targets) {
    220186                                list_append(&transfer->link, &dev->transfer_queue);
     
    228194       
    229195        if (targets > 1)
    230                 usb_log_warning("Transfer would be accepted by more devices!");
     196                usb_log_warning("Transfer would be accepted by more devices!\n");
    231197
    232198        return targets ? EOK : ENOENT;
     
    251217                size_t data_transfer_size = 0;
    252218                if (dev->dev_sess) {
    253                         rc = process_transfer_remote(&transfer->batch,
     219                        rc = process_transfer_remote(transfer->batch,
    254220                            dev->dev_sess, &data_transfer_size);
    255221                } else if (dev->dev_local != NULL) {
    256                         rc = process_transfer_local(&transfer->batch,
     222                        rc = process_transfer_local(transfer->batch,
    257223                            dev->dev_local, &data_transfer_size);
    258224                } else {
    259                         usb_log_warning("Device has no remote phone nor local node.");
     225                        usb_log_warning("Device has no remote phone nor local node.\n");
    260226                        rc = ESTALL;
    261227                }
    262228
    263                 usb_log_debug2("Transfer %p processed: %s.",
     229                usb_log_debug2("Transfer %p processed: %s.\n",
    264230                    transfer, str_error(rc));
    265231
     
    268234                        if (is_set_address_transfer(transfer)) {
    269235                                usb_device_request_setup_packet_t *setup =
    270                                     (void*) transfer->batch.setup.buffer;
     236                                    (void*) transfer->batch->setup_buffer;
    271237                                dev->address = setup->value;
    272                                 usb_log_debug2("Address changed to %d",
     238                                usb_log_debug2("Address changed to %d\n",
    273239                                    dev->address);
    274240                        }
Note: See TracChangeset for help on using the changeset viewer.