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