Changes in uspace/drv/uhci-hcd/batch.c [bdc8ab1:30a4301] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/uhci-hcd/batch.c
rbdc8ab1 r30a4301 33 33 */ 34 34 #include <errno.h> 35 #include <str_error.h> 36 37 #include <usb/usb.h> 35 38 36 #include <usb/debug.h> 39 37 … … 47 45 static int batch_schedule(batch_t *instance); 48 46 49 static void batch_control(50 batch_t *instance, int data_stage, int status_stage);51 47 static void batch_call_in(batch_t *instance); 52 48 static void batch_call_out(batch_t *instance); … … 55 51 56 52 57 batch_t * batch_get(d df_fun_t *fun, usb_target_t target,53 batch_t * batch_get(device_t *dev, usb_target_t target, 58 54 usb_transfer_type_t transfer_type, size_t max_packet_size, 59 usb_speed_t speed, char *buffer, size_t size,55 dev_speed_t speed, char *buffer, size_t size, 60 56 char* setup_buffer, size_t setup_size, 61 57 usbhc_iface_transfer_in_callback_t func_in, … … 96 92 instance->transport_buffer = 97 93 (size > 0) ? malloc32(transport_size) : NULL; 98 99 94 if ((size > 0) && (instance->transport_buffer == NULL)) { 100 95 usb_log_error("Failed to allocate device accessible buffer.\n"); … … 133 128 instance->buffer_size = size; 134 129 instance->setup_size = setup_size; 135 instance-> fun = fun;130 instance->dev = dev; 136 131 instance->arg = arg; 137 132 instance->speed = speed; 138 133 139 134 queue_head_element_td(instance->qh, addr_to_phys(instance->tds)); 140 usb_log_debug("Batch(%p) %d:%d memory structures ready.\n",141 instance, target.address, target.endpoint);142 135 return instance; 143 136 } … … 146 139 { 147 140 assert(instance); 148 usb_log_debug 2("Batch(%p) checking %d packet(s)for completion.\n",141 usb_log_debug("Checking(%p) %d packet for completion.\n", 149 142 instance, instance->packets); 150 143 instance->transfered_size = 0; … … 158 151 if (i > 0) 159 152 instance->transfered_size -= instance->setup_size; 160 usb_log_debug("Batch(%p) found error TD(%d):%x.\n",161 instance, i, instance->tds[i].status);162 153 return true; 163 154 } … … 165 156 transfer_descriptor_actual_size(&instance->tds[i]); 166 157 } 158 /* This is just an ugly trick to support the old API */ 167 159 instance->transfered_size -= instance->setup_size; 168 160 return true; … … 172 164 { 173 165 assert(instance); 166 174 167 /* we are data out, we are supposed to provide data */ 175 168 memcpy(instance->transport_buffer, instance->buffer, instance->buffer_size); 176 batch_control(instance, USB_PID_OUT, USB_PID_IN); 169 170 int toggle = 0; 171 /* setup stage */ 172 transfer_descriptor_init(instance->tds, DEFAULT_ERROR_COUNT, 173 instance->setup_size, toggle, false, instance->target, 174 USB_PID_SETUP, instance->setup_buffer, &instance->tds[1]); 175 176 /* data stage */ 177 size_t i = 1; 178 for (;i < instance->packets - 1; ++i) { 179 char *data = 180 instance->transport_buffer + ((i - 1) * instance->max_packet_size); 181 toggle = 1 - toggle; 182 183 transfer_descriptor_init(&instance->tds[i], DEFAULT_ERROR_COUNT, 184 instance->max_packet_size, toggle++, false, instance->target, 185 USB_PID_OUT, data, &instance->tds[i + 1]); 186 } 187 188 /* status stage */ 189 i = instance->packets - 1; 190 transfer_descriptor_init(&instance->tds[i], DEFAULT_ERROR_COUNT, 191 0, 1, false, instance->target, USB_PID_IN, NULL, NULL); 192 193 instance->tds[i].status |= TD_STATUS_COMPLETE_INTERRUPT_FLAG; 194 177 195 instance->next_step = batch_call_out_and_dispose; 178 usb_log_debug("Batch(%p) CONTROL WRITE initialized.\n", instance);179 196 batch_schedule(instance); 180 197 } … … 183 200 { 184 201 assert(instance); 185 batch_control(instance, USB_PID_IN, USB_PID_OUT); 202 203 int toggle = 0; 204 /* setup stage */ 205 transfer_descriptor_init(instance->tds, DEFAULT_ERROR_COUNT, 206 instance->setup_size, toggle, false, instance->target, 207 USB_PID_SETUP, instance->setup_buffer, &instance->tds[1]); 208 209 /* data stage */ 210 size_t i = 1; 211 for (;i < instance->packets - 1; ++i) { 212 char *data = 213 instance->transport_buffer + ((i - 1) * instance->max_packet_size); 214 toggle = 1 - toggle; 215 216 transfer_descriptor_init(&instance->tds[i], DEFAULT_ERROR_COUNT, 217 instance->max_packet_size, toggle, false, instance->target, 218 USB_PID_IN, data, &instance->tds[i + 1]); 219 } 220 221 /* status stage */ 222 i = instance->packets - 1; 223 transfer_descriptor_init(&instance->tds[i], DEFAULT_ERROR_COUNT, 224 0, 1, false, instance->target, USB_PID_OUT, NULL, NULL); 225 226 instance->tds[i].status |= TD_STATUS_COMPLETE_INTERRUPT_FLAG; 227 186 228 instance->next_step = batch_call_in_and_dispose; 187 usb_log_debug("Batch(%p) CONTROL READ initialized.\n", instance);188 229 batch_schedule(instance); 189 230 } … … 193 234 assert(instance); 194 235 195 const bool low_speed = instance->speed == USB_SPEED_LOW;196 236 int toggle = 1; 197 237 size_t i = 0; … … 204 244 205 245 transfer_descriptor_init(&instance->tds[i], DEFAULT_ERROR_COUNT, 206 instance->max_packet_size, toggle, false, low_speed,207 instance->target,USB_PID_IN, data, next);246 instance->max_packet_size, toggle, false, instance->target, 247 USB_PID_IN, data, next); 208 248 } 209 249 … … 211 251 212 252 instance->next_step = batch_call_in_and_dispose; 213 usb_log_debug("Batch(%p) INTERRUPT IN initialized.\n", instance);214 253 batch_schedule(instance); 215 254 } … … 218 257 { 219 258 assert(instance); 259 220 260 memcpy(instance->transport_buffer, instance->buffer, instance->buffer_size); 221 261 222 const bool low_speed = instance->speed == USB_SPEED_LOW;223 262 int toggle = 1; 224 263 size_t i = 0; … … 231 270 232 271 transfer_descriptor_init(&instance->tds[i], DEFAULT_ERROR_COUNT, 233 instance->max_packet_size, toggle++, false, low_speed,234 instance->target,USB_PID_OUT, data, next);272 instance->max_packet_size, toggle++, false, instance->target, 273 USB_PID_OUT, data, next); 235 274 } 236 275 … … 238 277 239 278 instance->next_step = batch_call_out_and_dispose; 240 usb_log_debug("Batch(%p) INTERRUPT OUT initialized.\n", instance); 241 batch_schedule(instance); 242 } 243 /*----------------------------------------------------------------------------*/ 244 static void batch_control( 245 batch_t *instance, int data_stage, int status_stage) 246 { 247 assert(instance); 248 249 const bool low_speed = instance->speed == USB_SPEED_LOW; 250 int toggle = 0; 251 /* setup stage */ 252 transfer_descriptor_init(instance->tds, DEFAULT_ERROR_COUNT, 253 instance->setup_size, toggle, false, low_speed, instance->target, 254 USB_PID_SETUP, instance->setup_buffer, &instance->tds[1]); 255 256 /* data stage */ 257 size_t packet = 1; 258 size_t remain_size = instance->buffer_size; 259 while (remain_size > 0) { 260 char *data = 261 instance->transport_buffer + instance->buffer_size 262 - remain_size; 263 264 toggle = 1 - toggle; 265 266 const size_t packet_size = 267 (instance->max_packet_size > remain_size) ? 268 remain_size : instance->max_packet_size; 269 270 transfer_descriptor_init(&instance->tds[packet], 271 DEFAULT_ERROR_COUNT, packet_size, toggle, false, low_speed, 272 instance->target, data_stage, data, 273 &instance->tds[packet + 1]); 274 275 ++packet; 276 assert(packet < instance->packets); 277 assert(packet_size <= remain_size); 278 remain_size -= packet_size; 279 } 280 281 /* status stage */ 282 assert(packet == instance->packets - 1); 283 transfer_descriptor_init(&instance->tds[packet], DEFAULT_ERROR_COUNT, 284 0, 1, false, low_speed, instance->target, status_stage, NULL, NULL); 285 286 287 instance->tds[packet].status |= TD_STATUS_COMPLETE_INTERRUPT_FLAG; 288 usb_log_debug2("Control last TD status: %x.\n", 289 instance->tds[packet].status); 279 batch_schedule(instance); 290 280 } 291 281 /*----------------------------------------------------------------------------*/ … … 298 288 299 289 int err = instance->error; 300 usb_log_debug("Batch(%p) callback IN(type:%d): %s(%d), %zu.\n", 301 instance, instance->transfer_type, str_error(err), err, 302 instance->transfered_size); 303 304 instance->callback_in(instance->fun, 290 usb_log_info("Callback IN(%d): %d, %zu.\n", instance->transfer_type, 291 err, instance->transfered_size); 292 293 instance->callback_in(instance->dev, 305 294 err, instance->transfered_size, 306 295 instance->arg); … … 313 302 314 303 int err = instance->error; 315 usb_log_debug("Batch(%p) callback OUT(type:%d): %s(%d).\n", 316 instance, instance->transfer_type, str_error(err), err); 317 instance->callback_out(instance->fun, 304 usb_log_info("Callback OUT(%d): %d.\n", instance->transfer_type, err); 305 instance->callback_out(instance->dev, 318 306 err, instance->arg); 319 307 } … … 323 311 assert(instance); 324 312 batch_call_in(instance); 325 usb_log_debug(" Batch(%p) disposing.\n", instance);313 usb_log_debug("Disposing batch: %p.\n", instance); 326 314 free32(instance->tds); 327 315 free32(instance->qh); … … 335 323 assert(instance); 336 324 batch_call_out(instance); 337 usb_log_debug(" Batch(%p) disposing.\n", instance);325 usb_log_debug("Disposing batch: %p.\n", instance); 338 326 free32(instance->tds); 339 327 free32(instance->qh); … … 346 334 { 347 335 assert(instance); 348 uhci_t *hc = fun_to_uhci(instance->fun);336 uhci_t *hc = dev_to_uhci(instance->dev); 349 337 assert(hc); 350 338 return uhci_schedule(hc, instance); 339 } 340 /*----------------------------------------------------------------------------*/ 341 /* DEPRECATED FUNCTIONS NEEDED BY THE OLD API */ 342 void batch_control_setup_old(batch_t *instance) 343 { 344 assert(instance); 345 instance->packets = 1; 346 347 /* setup stage */ 348 transfer_descriptor_init(instance->tds, DEFAULT_ERROR_COUNT, 349 instance->setup_size, 0, false, instance->target, 350 USB_PID_SETUP, instance->setup_buffer, NULL); 351 352 instance->next_step = batch_call_out_and_dispose; 353 batch_schedule(instance); 354 } 355 /*----------------------------------------------------------------------------*/ 356 void batch_control_write_data_old(batch_t *instance) 357 { 358 assert(instance); 359 instance->packets -= 2; 360 batch_interrupt_out(instance); 361 } 362 /*----------------------------------------------------------------------------*/ 363 void batch_control_read_data_old(batch_t *instance) 364 { 365 assert(instance); 366 instance->packets -= 2; 367 batch_interrupt_in(instance); 368 } 369 /*----------------------------------------------------------------------------*/ 370 void batch_control_write_status_old(batch_t *instance) 371 { 372 assert(instance); 373 instance->packets = 1; 374 transfer_descriptor_init(instance->tds, DEFAULT_ERROR_COUNT, 375 0, 1, false, instance->target, USB_PID_IN, NULL, NULL); 376 instance->next_step = batch_call_in_and_dispose; 377 batch_schedule(instance); 378 } 379 /*----------------------------------------------------------------------------*/ 380 void batch_control_read_status_old(batch_t *instance) 381 { 382 assert(instance); 383 instance->packets = 1; 384 transfer_descriptor_init(instance->tds, DEFAULT_ERROR_COUNT, 385 0, 1, false, instance->target, USB_PID_OUT, NULL, NULL); 386 instance->next_step = batch_call_out_and_dispose; 387 batch_schedule(instance); 351 388 } 352 389 /**
Note:
See TracChangeset
for help on using the changeset viewer.