Changes in uspace/drv/bus/usb/ohci/ohci_batch.c [9d58539:584aa38] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/bus/usb/ohci/ohci_batch.c
r9d58539 r584aa38 32 32 * @brief OHCI driver USB transaction structure 33 33 */ 34 35 #include <assert.h> 34 36 #include <errno.h> 35 #include <str_error.h>36 37 #include <macros.h> 38 #include <mem.h> 39 #include <stdbool.h> 37 40 38 41 #include <usb/usb.h> … … 44 47 45 48 static void (*const batch_setup[])(ohci_transfer_batch_t*, usb_direction_t); 46 /*----------------------------------------------------------------------------*/ 49 47 50 /** Safely destructs ohci_transfer_batch_t structure 48 51 * … … 67 70 free(ohci_batch); 68 71 } 69 /*----------------------------------------------------------------------------*/ 72 70 73 /** Finishes usb_transfer_batch and destroys the structure. 71 74 * … … 80 83 ohci_transfer_batch_dispose(ohci_batch); 81 84 } 82 /*----------------------------------------------------------------------------*/ 85 83 86 /** Allocate memory and initialize internal data structure. 84 87 * … … 94 97 { 95 98 assert(usb_batch); 96 #define CHECK_NULL_DISPOSE_RET(ptr, message...) \97 if (ptr == NULL) { \98 usb_log_error(message); \99 ohci_transfer_batch_dispose(ohci_batch); \100 return NULL; \101 } else (void)0102 99 103 100 ohci_transfer_batch_t *ohci_batch = 104 101 calloc(1, sizeof(ohci_transfer_batch_t)); 105 CHECK_NULL_DISPOSE_RET(ohci_batch, 106 "Failed to allocate OHCI batch data.\n"); 102 if (!ohci_batch) { 103 usb_log_error("Failed to allocate OHCI batch data."); 104 goto dispose; 105 } 107 106 link_initialize(&ohci_batch->link); 108 107 ohci_batch->td_count = … … 116 115 /* We need an extra place for TD that was left at ED */ 117 116 ohci_batch->tds = calloc(ohci_batch->td_count + 1, sizeof(td_t*)); 118 CHECK_NULL_DISPOSE_RET(ohci_batch->tds, 119 "Failed to allocate OHCI transfer descriptors.\n"); 117 if (!ohci_batch->tds) { 118 usb_log_error("Failed to allocate OHCI transfer descriptors."); 119 goto dispose; 120 } 120 121 121 122 /* Add TD left over by the previous transfer */ … … 125 126 for (unsigned i = 1; i <= ohci_batch->td_count; ++i) { 126 127 ohci_batch->tds[i] = malloc32(sizeof(td_t)); 127 CHECK_NULL_DISPOSE_RET(ohci_batch->tds[i], 128 "Failed to allocate TD %d.\n", i ); 128 if (!ohci_batch->tds[i]) { 129 usb_log_error("Failed to allocate TD %d.", i); 130 goto dispose; 131 } 129 132 } 130 133 … … 138 141 ohci_batch->device_buffer = 139 142 malloc32(usb_batch->setup_size + usb_batch->buffer_size); 140 CHECK_NULL_DISPOSE_RET(ohci_batch->device_buffer, 141 "Failed to allocate device accessible buffer.\n"); 143 if (!ohci_batch->device_buffer) { 144 usb_log_error("Failed to allocate device buffer"); 145 goto dispose; 146 } 142 147 /* Copy setup data */ 143 148 memcpy(ohci_batch->device_buffer, usb_batch->setup_buffer, … … 156 161 157 162 return ohci_batch; 158 #undef CHECK_NULL_DISPOSE_RET 159 } 160 /*----------------------------------------------------------------------------*/ 163 dispose: 164 ohci_transfer_batch_dispose(ohci_batch); 165 return NULL; 166 } 167 161 168 /** Check batch TDs' status. 162 169 * … … 199 206 ohci_batch->tds[i]->next, ohci_batch->tds[i]->be); 200 207 201 /* If the TD got all its data through, it will report 0 bytes202 * remain, the sole exception is INPUT with data rounding flag203 * (short), i.e. every INPUT. Nice thing is that short packets204 * will correctly report remaining data, thus making205 * this computation correct (short packets need to be produced206 * by the last TD)207 * NOTE: This also works for CONTROL transfer as208 * the first TD will return 0 remain.209 * NOTE: Short packets don't break the assumption that210 * we leave the very last(unused) TD behind.211 */212 ohci_batch->usb_batch->transfered_size213 -= td_remain_size(ohci_batch->tds[i]);214 215 208 ohci_batch->usb_batch->error = td_error(ohci_batch->tds[i]); 216 if (ohci_batch->usb_batch->error != EOK) { 209 if (ohci_batch->usb_batch->error == EOK) { 210 /* If the TD got all its data through, it will report 211 * 0 bytes remain, the sole exception is INPUT with 212 * data rounding flag (short), i.e. every INPUT. 213 * Nice thing is that short packets will correctly 214 * report remaining data, thus making this computation 215 * correct (short packets need to be produced by the 216 * last TD) 217 * NOTE: This also works for CONTROL transfer as 218 * the first TD will return 0 remain. 219 * NOTE: Short packets don't break the assumption that 220 * we leave the very last(unused) TD behind. 221 */ 222 ohci_batch->usb_batch->transfered_size 223 -= td_remain_size(ohci_batch->tds[i]); 224 } else { 217 225 usb_log_debug("Batch %p found error TD(%zu):%08x.\n", 218 226 ohci_batch->usb_batch, i, … … 231 239 232 240 /* Check TD assumption */ 233 const uint32_t pa = 234 addr_to_phys(ohci_batch->tds[leave_td]); 235 assert((ohci_batch->ed->td_head & ED_TDHEAD_PTR_MASK) 236 == pa); 237 241 assert(ed_head_td(ohci_batch->ed) == 242 addr_to_phys(ohci_batch->tds[leave_td])); 243 244 /* Set tail to the same TD */ 238 245 ed_set_tail_td(ohci_batch->ed, 239 246 ohci_batch->tds[leave_td]); 240 247 241 248 /* Clear possible ED HALT */ 242 ohci_batch->ed->td_head &= ~ED_TDHEAD_HALTED_FLAG;249 ed_clear_halt(ohci_batch->ed); 243 250 break; 244 251 } … … 253 260 254 261 /* Make sure that we are leaving the right TD behind */ 255 const uint32_t pa = addr_to_phys(ohci_ep->td); 256 assert(pa == (ohci_batch->ed->td_head & ED_TDHEAD_PTR_MASK)); 257 assert(pa == (ohci_batch->ed->td_tail & ED_TDTAIL_PTR_MASK)); 262 assert(addr_to_phys(ohci_ep->td) == ed_head_td(ohci_batch->ed)); 263 assert(addr_to_phys(ohci_ep->td) == ed_tail_td(ohci_batch->ed)); 258 264 259 265 return true; 260 266 } 261 /*----------------------------------------------------------------------------*/ 267 262 268 /** Starts execution of the TD list 263 269 * … … 269 275 ed_set_tail_td(ohci_batch->ed, ohci_batch->tds[ohci_batch->td_count]); 270 276 } 271 /*----------------------------------------------------------------------------*/ 277 272 278 /** Prepare generic control transfer 273 279 * … … 345 351 USB_TRANSFER_BATCH_ARGS(*ohci_batch->usb_batch)); 346 352 } 347 /*----------------------------------------------------------------------------*/ 353 348 354 /** Prepare generic data transfer 349 355 * … … 392 398 USB_TRANSFER_BATCH_ARGS(*ohci_batch->usb_batch)); 393 399 } 394 /*----------------------------------------------------------------------------*/ 400 395 401 /** Transfer setup table. */ 396 402 static void (*const batch_setup[])(ohci_transfer_batch_t*, usb_direction_t) =
Note:
See TracChangeset
for help on using the changeset viewer.