Changes in uspace/drv/bus/usb/vhc/transfer.c [1d758fc:b7fd2a0] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/bus/usb/vhc/transfer.c
r1d758fc rb7fd2a0 31 31 #include <usb/debug.h> 32 32 #include <usbvirt/device.h> 33 #include <usb/host/bandwidth.h>34 #include <usb/host/endpoint.h>35 #include <usb/host/usb_transfer_batch.h>36 33 #include <usbvirt/ipc.h> 37 34 #include "vhcd.h" … … 40 37 static bool is_set_address_transfer(vhc_transfer_t *transfer) 41 38 { 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; 53 50 if (setup->request_type != 0) { 54 51 return false; … … 65 62 { 66 63 errno_t rc; 67 68 const usb_direction_t dir = batch->dir;64 65 const usb_direction_t dir = usb_transfer_batch_direction(batch); 69 66 70 67 if (batch->ep->transfer_type == USB_TRANSFER_CONTROL) { 71 68 if (dir == USB_DIRECTION_IN) { 72 69 rc = usbvirt_control_read(dev, 73 batch->setup .buffer, USB_SETUP_PACKET_SIZE,74 batch-> dma_buffer.virt, batch->size,70 batch->setup_buffer, batch->setup_size, 71 batch->buffer, batch->buffer_size, 75 72 actual_data_size); 76 73 } else { 77 74 assert(dir == USB_DIRECTION_OUT); 78 75 rc = usbvirt_control_write(dev, 79 batch->setup .buffer, USB_SETUP_PACKET_SIZE,80 batch-> dma_buffer.virt, batch->size);76 batch->setup_buffer, batch->setup_size, 77 batch->buffer, batch->buffer_size); 81 78 } 82 79 } else { … … 84 81 rc = usbvirt_data_in(dev, batch->ep->transfer_type, 85 82 batch->ep->endpoint, 86 batch-> dma_buffer.virt, batch->size,83 batch->buffer, batch->buffer_size, 87 84 actual_data_size); 88 85 } else { … … 90 87 rc = usbvirt_data_out(dev, batch->ep->transfer_type, 91 88 batch->ep->endpoint, 92 batch-> dma_buffer.virt, batch->size);89 batch->buffer, batch->buffer_size); 93 90 } 94 91 } … … 102 99 errno_t rc; 103 100 104 const usb_direction_t dir = batch->dir;101 const usb_direction_t dir = usb_transfer_batch_direction(batch); 105 102 106 103 if (batch->ep->transfer_type == USB_TRANSFER_CONTROL) { 107 104 if (dir == USB_DIRECTION_IN) { 108 105 rc = usbvirt_ipc_send_control_read(sess, 109 batch->setup .buffer, USB_SETUP_PACKET_SIZE,110 batch-> dma_buffer.virt, batch->size,106 batch->setup_buffer, batch->setup_size, 107 batch->buffer, batch->buffer_size, 111 108 actual_data_size); 112 109 } else { 113 110 assert(dir == USB_DIRECTION_OUT); 114 111 rc = usbvirt_ipc_send_control_write(sess, 115 batch->setup .buffer, USB_SETUP_PACKET_SIZE,116 batch-> dma_buffer.virt, batch->size);112 batch->setup_buffer, batch->setup_size, 113 batch->buffer, batch->buffer_size); 117 114 } 118 115 } else { … … 120 117 rc = usbvirt_ipc_send_data_in(sess, batch->ep->endpoint, 121 118 batch->ep->transfer_type, 122 batch-> dma_buffer.virt, batch->size,119 batch->buffer, batch->buffer_size, 123 120 actual_data_size); 124 121 } else { … … 126 123 rc = usbvirt_ipc_send_data_out(sess, batch->ep->endpoint, 127 124 batch->ep->transfer_type, 128 batch-> dma_buffer.virt, batch->size);125 batch->buffer, batch->buffer_size); 129 126 } 130 127 } … … 150 147 assert(outcome != ENAK); 151 148 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 } 193 155 194 156 errno_t vhc_init(vhc_data_t *instance) … … 197 159 list_initialize(&instance->devices); 198 160 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; 202 162 return virthub_init(&instance->hub, "root hub"); 203 163 } 204 164 205 errno_t vhc_schedule(usb_transfer_batch_t *batch) 206 { 165 errno_t vhc_schedule(hcd_t *hcd, usb_transfer_batch_t *batch) 166 { 167 assert(hcd); 207 168 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); 210 170 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; 211 177 212 178 fibril_mutex_lock(&vhc->guard); … … 216 182 list_foreach(vhc->devices, link, vhc_virtdev_t, dev) { 217 183 fibril_mutex_lock(&dev->guard); 218 if (dev->address == transfer->batch .target.address) {184 if (dev->address == transfer->batch->ep->address) { 219 185 if (!targets) { 220 186 list_append(&transfer->link, &dev->transfer_queue); … … 228 194 229 195 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"); 231 197 232 198 return targets ? EOK : ENOENT; … … 251 217 size_t data_transfer_size = 0; 252 218 if (dev->dev_sess) { 253 rc = process_transfer_remote( &transfer->batch,219 rc = process_transfer_remote(transfer->batch, 254 220 dev->dev_sess, &data_transfer_size); 255 221 } else if (dev->dev_local != NULL) { 256 rc = process_transfer_local( &transfer->batch,222 rc = process_transfer_local(transfer->batch, 257 223 dev->dev_local, &data_transfer_size); 258 224 } 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"); 260 226 rc = ESTALL; 261 227 } 262 228 263 usb_log_debug2("Transfer %p processed: %s. ",229 usb_log_debug2("Transfer %p processed: %s.\n", 264 230 transfer, str_error(rc)); 265 231 … … 268 234 if (is_set_address_transfer(transfer)) { 269 235 usb_device_request_setup_packet_t *setup = 270 (void*) transfer->batch .setup.buffer;236 (void*) transfer->batch->setup_buffer; 271 237 dev->address = setup->value; 272 usb_log_debug2("Address changed to %d ",238 usb_log_debug2("Address changed to %d\n", 273 239 dev->address); 274 240 }
Note:
See TracChangeset
for help on using the changeset viewer.