| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
#include <linux/gcd.h> |
| 13 |
#include <linux/kernel.h> |
| 14 |
#include <linux/module.h> |
| 15 |
#include <linux/spinlock.h> |
| 16 |
#include <linux/interrupt.h> |
| 17 |
#include <linux/dma-mapping.h> |
| 18 |
#include <linux/io.h> |
| 19 |
#include <linux/seq_buf.h> |
| 20 |
#include <linux/slab.h> |
| 21 |
#include <linux/usb.h> |
| 22 |
|
| 23 |
#include <linux/usb/hcd.h> |
| 24 |
#include <linux/usb/ch11.h> |
| 25 |
|
| 26 |
#include "core.h" |
| 27 |
#include "hcd.h" |
| 28 |
|
| 29 |
|
| 30 |
#define DWC2_UNRESERVE_DELAY (msecs_to_jiffies(5)) |
| 31 |
|
| 32 |
|
| 33 |
#define DWC2_RETRY_WAIT_DELAY (1 * NSEC_PER_MSEC) |
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
static int dwc2_periodic_channel_available(struct dwc2_hsotg *hsotg) |
| 44 |
{ |
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
int status; |
| 51 |
int num_channels; |
| 52 |
|
| 53 |
num_channels = hsotg->params.host_channels; |
| 54 |
if ((hsotg->periodic_channels + hsotg->non_periodic_channels < |
| 55 |
num_channels) && (hsotg->periodic_channels < num_channels - 1)) { |
| 56 |
status = 0; |
| 57 |
} else { |
| 58 |
dev_dbg(hsotg->dev, |
| 59 |
"%s: Total channels: %d, Periodic: %d, Non-periodic: %d\n", |
| 60 |
__func__, num_channels, |
| 61 |
hsotg->periodic_channels, hsotg->non_periodic_channels); |
| 62 |
status = -ENOSPC; |
| 63 |
} |
| 64 |
|
| 65 |
return status; |
| 66 |
} |
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
static int dwc2_check_periodic_bandwidth(struct dwc2_hsotg *hsotg, |
| 81 |
struct dwc2_qh *qh) |
| 82 |
{ |
| 83 |
int status; |
| 84 |
s16 max_claimed_usecs; |
| 85 |
|
| 86 |
status = 0; |
| 87 |
|
| 88 |
if (qh->dev_speed == USB_SPEED_HIGH || qh->do_split) { |
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
max_claimed_usecs = 100 - qh->host_us; |
| 94 |
} else { |
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
max_claimed_usecs = 900 - qh->host_us; |
| 100 |
} |
| 101 |
|
| 102 |
if (hsotg->periodic_usecs > max_claimed_usecs) { |
| 103 |
dev_err(hsotg->dev, |
| 104 |
"%s: already claimed usecs %d, required usecs %d\n", |
| 105 |
__func__, hsotg->periodic_usecs, qh->host_us); |
| 106 |
status = -ENOSPC; |
| 107 |
} |
| 108 |
|
| 109 |
return status; |
| 110 |
} |
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
|
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
|
| 155 |
|
| 156 |
|
| 157 |
|
| 158 |
|
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
|
| 164 |
|
| 165 |
|
| 166 |
|
| 167 |
|
| 168 |
|
| 169 |
|
| 170 |
|
| 171 |
|
| 172 |
|
| 173 |
|
| 174 |
|
| 175 |
|
| 176 |
|
| 177 |
|
| 178 |
|
| 179 |
|
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
|
| 184 |
|
| 185 |
|
| 186 |
|
| 187 |
|
| 188 |
|
| 189 |
|
| 190 |
|
| 191 |
|
| 192 |
|
| 193 |
|
| 194 |
|
| 195 |
|
| 196 |
|
| 197 |
|
| 198 |
|
| 199 |
|
| 200 |
|
| 201 |
|
| 202 |
|
| 203 |
static int pmap_schedule(unsigned long *map, int bits_per_period, |
| 204 |
int periods_in_map, int num_bits, |
| 205 |
int interval, int start, bool only_one_period) |
| 206 |
{ |
| 207 |
int interval_bits; |
| 208 |
int to_reserve; |
| 209 |
int first_end; |
| 210 |
int i; |
| 211 |
|
| 212 |
if (num_bits > bits_per_period) |
| 213 |
return -ENOSPC; |
| 214 |
|
| 215 |
|
| 216 |
interval = gcd(interval, periods_in_map); |
| 217 |
|
| 218 |
interval_bits = bits_per_period * interval; |
| 219 |
to_reserve = periods_in_map / interval; |
| 220 |
|
| 221 |
|
| 222 |
if (start >= interval_bits) |
| 223 |
return -ENOSPC; |
| 224 |
|
| 225 |
if (only_one_period) |
| 226 |
|
| 227 |
first_end = (start / bits_per_period + 1) * bits_per_period; |
| 228 |
else |
| 229 |
|
| 230 |
first_end = interval_bits; |
| 231 |
|
| 232 |
|
| 233 |
|
| 234 |
|
| 235 |
|
| 236 |
|
| 237 |
|
| 238 |
while (start + num_bits <= first_end) { |
| 239 |
int end; |
| 240 |
|
| 241 |
|
| 242 |
end = (start / bits_per_period + 1) * bits_per_period; |
| 243 |
|
| 244 |
|
| 245 |
start = bitmap_find_next_zero_area(map, end, start, num_bits, |
| 246 |
0); |
| 247 |
|
| 248 |
|
| 249 |
|
| 250 |
|
| 251 |
|
| 252 |
|
| 253 |
if (start >= end) { |
| 254 |
start = end; |
| 255 |
continue; |
| 256 |
} |
| 257 |
|
| 258 |
|
| 259 |
for (i = 1; i < to_reserve; i++) { |
| 260 |
int ith_start = start + interval_bits * i; |
| 261 |
int ith_end = end + interval_bits * i; |
| 262 |
int ret; |
| 263 |
|
| 264 |
|
| 265 |
ret = bitmap_find_next_zero_area( |
| 266 |
map, ith_start + num_bits, ith_start, num_bits, |
| 267 |
0); |
| 268 |
|
| 269 |
|
| 270 |
if (ret == ith_start) |
| 271 |
continue; |
| 272 |
|
| 273 |
|
| 274 |
ith_start = bitmap_find_next_zero_area( |
| 275 |
map, ith_end, ith_start, num_bits, 0); |
| 276 |
if (ith_start >= ith_end) |
| 277 |
|
| 278 |
start = end; |
| 279 |
else |
| 280 |
start = ith_start - interval_bits * i; |
| 281 |
break; |
| 282 |
} |
| 283 |
|
| 284 |
|
| 285 |
if (i == to_reserve) |
| 286 |
break; |
| 287 |
} |
| 288 |
|
| 289 |
if (start + num_bits > first_end) |
| 290 |
return -ENOSPC; |
| 291 |
|
| 292 |
for (i = 0; i < to_reserve; i++) { |
| 293 |
int ith_start = start + interval_bits * i; |
| 294 |
|
| 295 |
bitmap_set(map, ith_start, num_bits); |
| 296 |
} |
| 297 |
|
| 298 |
return start; |
| 299 |
} |
| 300 |
|
| 301 |
|
| 302 |
|
| 303 |
|
| 304 |
|
| 305 |
|
| 306 |
|
| 307 |
|
| 308 |
|
| 309 |
|
| 310 |
|
| 311 |
static void pmap_unschedule(unsigned long *map, int bits_per_period, |
| 312 |
int periods_in_map, int num_bits, |
| 313 |
int interval, int start) |
| 314 |
{ |
| 315 |
int interval_bits; |
| 316 |
int to_release; |
| 317 |
int i; |
| 318 |
|
| 319 |
|
| 320 |
interval = gcd(interval, periods_in_map); |
| 321 |
|
| 322 |
interval_bits = bits_per_period * interval; |
| 323 |
to_release = periods_in_map / interval; |
| 324 |
|
| 325 |
for (i = 0; i < to_release; i++) { |
| 326 |
int ith_start = start + interval_bits * i; |
| 327 |
|
| 328 |
bitmap_clear(map, ith_start, num_bits); |
| 329 |
} |
| 330 |
} |
| 331 |
|
| 332 |
|
| 333 |
|
| 334 |
|
| 335 |
|
| 336 |
|
| 337 |
|
| 338 |
|
| 339 |
|
| 340 |
|
| 341 |
|
| 342 |
|
| 343 |
|
| 344 |
|
| 345 |
static unsigned long *dwc2_get_ls_map(struct dwc2_hsotg *hsotg, |
| 346 |
struct dwc2_qh *qh) |
| 347 |
{ |
| 348 |
unsigned long *map; |
| 349 |
|
| 350 |
|
| 351 |
if (WARN_ON(!qh->dwc_tt)) |
| 352 |
return NULL; |
| 353 |
|
| 354 |
|
| 355 |
map = qh->dwc_tt->periodic_bitmaps; |
| 356 |
if (qh->dwc_tt->usb_tt->multi) |
| 357 |
map += DWC2_ELEMENTS_PER_LS_BITMAP * (qh->ttport - 1); |
| 358 |
|
| 359 |
return map; |
| 360 |
} |
| 361 |
|
| 362 |
#ifdef DWC2_PRINT_SCHEDULE |
| 363 |
|
| 364 |
|
| 365 |
|
| 366 |
|
| 367 |
|
| 368 |
|
| 369 |
|
| 370 |
|
| 371 |
|
| 372 |
|
| 373 |
|
| 374 |
|
| 375 |
|
| 376 |
static void pmap_print(unsigned long *map, int bits_per_period, |
| 377 |
int periods_in_map, const char *period_name, |
| 378 |
const char *units, |
| 379 |
void (*print_fn)(const char *str, void *data), |
| 380 |
void *print_data) |
| 381 |
{ |
| 382 |
int period; |
| 383 |
|
| 384 |
for (period = 0; period < periods_in_map; period++) { |
| 385 |
DECLARE_SEQ_BUF(buf, 64); |
| 386 |
int period_start = period * bits_per_period; |
| 387 |
int period_end = period_start + bits_per_period; |
| 388 |
int start = 0; |
| 389 |
int count = 0; |
| 390 |
bool printed = false; |
| 391 |
int i; |
| 392 |
|
| 393 |
for (i = period_start; i < period_end + 1; i++) { |
| 394 |
|
| 395 |
if (i < period_end && |
| 396 |
bitmap_find_next_zero_area(map, i + 1, |
| 397 |
i, 1, 0) != i) { |
| 398 |
if (count == 0) |
| 399 |
start = i - period_start; |
| 400 |
count++; |
| 401 |
continue; |
| 402 |
} |
| 403 |
|
| 404 |
|
| 405 |
if (count == 0) |
| 406 |
continue; |
| 407 |
|
| 408 |
if (!printed) |
| 409 |
seq_buf_printf(&buf, "%s %d: ", |
| 410 |
period_name, period); |
| 411 |
else |
| 412 |
seq_buf_puts(&buf, ", "); |
| 413 |
printed = true; |
| 414 |
|
| 415 |
seq_buf_printf(&buf, "%d %s -%3d %s", start, |
| 416 |
units, start + count - 1, units); |
| 417 |
count = 0; |
| 418 |
} |
| 419 |
|
| 420 |
if (printed) |
| 421 |
print_fn(seq_buf_str(&buf), print_data); |
| 422 |
} |
| 423 |
} |
| 424 |
|
| 425 |
struct dwc2_qh_print_data { |
| 426 |
struct dwc2_hsotg *hsotg; |
| 427 |
struct dwc2_qh *qh; |
| 428 |
}; |
| 429 |
|
| 430 |
|
| 431 |
|
| 432 |
|
| 433 |
|
| 434 |
|
| 435 |
|
| 436 |
static void dwc2_qh_print(const char *str, void *data) |
| 437 |
{ |
| 438 |
struct dwc2_qh_print_data *print_data = data; |
| 439 |
|
| 440 |
dwc2_sch_dbg(print_data->hsotg, "QH=%p ...%s\n", print_data->qh, str); |
| 441 |
} |
| 442 |
|
| 443 |
|
| 444 |
|
| 445 |
|
| 446 |
|
| 447 |
|
| 448 |
|
| 449 |
static void dwc2_qh_schedule_print(struct dwc2_hsotg *hsotg, |
| 450 |
struct dwc2_qh *qh) |
| 451 |
{ |
| 452 |
struct dwc2_qh_print_data print_data = { hsotg, qh }; |
| 453 |
int i; |
| 454 |
|
| 455 |
|
| 456 |
|
| 457 |
|
| 458 |
|
| 459 |
|
| 460 |
|
| 461 |
if (qh->schedule_low_speed) { |
| 462 |
unsigned long *map = dwc2_get_ls_map(hsotg, qh); |
| 463 |
|
| 464 |
dwc2_sch_dbg(hsotg, "QH=%p LS/FS trans: %d=>%d us @ %d us", |
| 465 |
qh, qh->device_us, |
| 466 |
DWC2_ROUND_US_TO_SLICE(qh->device_us), |
| 467 |
DWC2_US_PER_SLICE * qh->ls_start_schedule_slice); |
| 468 |
|
| 469 |
if (map) { |
| 470 |
dwc2_sch_dbg(hsotg, |
| 471 |
"QH=%p Whole low/full speed map %p now:\n", |
| 472 |
qh, map); |
| 473 |
pmap_print(map, DWC2_LS_PERIODIC_SLICES_PER_FRAME, |
| 474 |
DWC2_LS_SCHEDULE_FRAMES, "Frame ", "slices", |
| 475 |
dwc2_qh_print, &print_data); |
| 476 |
} |
| 477 |
} |
| 478 |
|
| 479 |
for (i = 0; i < qh->num_hs_transfers; i++) { |
| 480 |
struct dwc2_hs_transfer_time *trans_time = qh->hs_transfers + i; |
| 481 |
int uframe = trans_time->start_schedule_us / |
| 482 |
DWC2_HS_PERIODIC_US_PER_UFRAME; |
| 483 |
int rel_us = trans_time->start_schedule_us % |
| 484 |
DWC2_HS_PERIODIC_US_PER_UFRAME; |
| 485 |
|
| 486 |
dwc2_sch_dbg(hsotg, |
| 487 |
"QH=%p HS trans #%d: %d us @ uFrame %d + %d us\n", |
| 488 |
qh, i, trans_time->duration_us, uframe, rel_us); |
| 489 |
} |
| 490 |
if (qh->num_hs_transfers) { |
| 491 |
dwc2_sch_dbg(hsotg, "QH=%p Whole high speed map now:\n", qh); |
| 492 |
pmap_print(hsotg->hs_periodic_bitmap, |
| 493 |
DWC2_HS_PERIODIC_US_PER_UFRAME, |
| 494 |
DWC2_HS_SCHEDULE_UFRAMES, "uFrame", "us", |
| 495 |
dwc2_qh_print, &print_data); |
| 496 |
} |
| 497 |
} |
| 498 |
#else |
| 499 |
static inline void dwc2_qh_schedule_print(struct dwc2_hsotg *hsotg, |
| 500 |
struct dwc2_qh *qh) {}; |
| 501 |
#endif |
| 502 |
|
| 503 |
|
| 504 |
|
| 505 |
|
| 506 |
|
| 507 |
|
| 508 |
|
| 509 |
|
| 510 |
|
| 511 |
|
| 512 |
|
| 513 |
|
| 514 |
|
| 515 |
|
| 516 |
|
| 517 |
|
| 518 |
static int dwc2_ls_pmap_schedule(struct dwc2_hsotg *hsotg, struct dwc2_qh *qh, |
| 519 |
int search_slice) |
| 520 |
{ |
| 521 |
int slices = DIV_ROUND_UP(qh->device_us, DWC2_US_PER_SLICE); |
| 522 |
unsigned long *map = dwc2_get_ls_map(hsotg, qh); |
| 523 |
int slice; |
| 524 |
|
| 525 |
if (!map) |
| 526 |
return -EINVAL; |
| 527 |
|
| 528 |
|
| 529 |
|
| 530 |
|
| 531 |
|
| 532 |
|
| 533 |
|
| 534 |
|
| 535 |
|
| 536 |
|
| 537 |
|
| 538 |
|
| 539 |
|
| 540 |
slice = pmap_schedule(map, DWC2_LS_PERIODIC_SLICES_PER_FRAME, |
| 541 |
DWC2_LS_SCHEDULE_FRAMES, slices, |
| 542 |
qh->device_interval, search_slice, false); |
| 543 |
|
| 544 |
if (slice < 0) |
| 545 |
return slice; |
| 546 |
|
| 547 |
qh->ls_start_schedule_slice = slice; |
| 548 |
return 0; |
| 549 |
} |
| 550 |
|
| 551 |
|
| 552 |
|
| 553 |
|
| 554 |
|
| 555 |
|
| 556 |
|
| 557 |
static void dwc2_ls_pmap_unschedule(struct dwc2_hsotg *hsotg, |
| 558 |
struct dwc2_qh *qh) |
| 559 |
{ |
| 560 |
int slices = DIV_ROUND_UP(qh->device_us, DWC2_US_PER_SLICE); |
| 561 |
unsigned long *map = dwc2_get_ls_map(hsotg, qh); |
| 562 |
|
| 563 |
|
| 564 |
if (!map) |
| 565 |
return; |
| 566 |
|
| 567 |
pmap_unschedule(map, DWC2_LS_PERIODIC_SLICES_PER_FRAME, |
| 568 |
DWC2_LS_SCHEDULE_FRAMES, slices, qh->device_interval, |
| 569 |
qh->ls_start_schedule_slice); |
| 570 |
} |
| 571 |
|
| 572 |
|
| 573 |
|
| 574 |
|
| 575 |
|
| 576 |
|
| 577 |
|
| 578 |
|
| 579 |
|
| 580 |
|
| 581 |
|
| 582 |
|
| 583 |
|
| 584 |
|
| 585 |
|
| 586 |
|
| 587 |
|
| 588 |
|
| 589 |
|
| 590 |
|
| 591 |
|
| 592 |
static int dwc2_hs_pmap_schedule(struct dwc2_hsotg *hsotg, struct dwc2_qh *qh, |
| 593 |
bool only_one_period, int index) |
| 594 |
{ |
| 595 |
struct dwc2_hs_transfer_time *trans_time = qh->hs_transfers + index; |
| 596 |
int us; |
| 597 |
|
| 598 |
us = pmap_schedule(hsotg->hs_periodic_bitmap, |
| 599 |
DWC2_HS_PERIODIC_US_PER_UFRAME, |
| 600 |
DWC2_HS_SCHEDULE_UFRAMES, trans_time->duration_us, |
| 601 |
qh->host_interval, trans_time->start_schedule_us, |
| 602 |
only_one_period); |
| 603 |
|
| 604 |
if (us < 0) |
| 605 |
return us; |
| 606 |
|
| 607 |
trans_time->start_schedule_us = us; |
| 608 |
return 0; |
| 609 |
} |
| 610 |
|
| 611 |
|
| 612 |
|
| 613 |
|
| 614 |
|
| 615 |
|
| 616 |
|
| 617 |
|
| 618 |
static void dwc2_hs_pmap_unschedule(struct dwc2_hsotg *hsotg, |
| 619 |
struct dwc2_qh *qh, int index) |
| 620 |
{ |
| 621 |
struct dwc2_hs_transfer_time *trans_time = qh->hs_transfers + index; |
| 622 |
|
| 623 |
pmap_unschedule(hsotg->hs_periodic_bitmap, |
| 624 |
DWC2_HS_PERIODIC_US_PER_UFRAME, |
| 625 |
DWC2_HS_SCHEDULE_UFRAMES, trans_time->duration_us, |
| 626 |
qh->host_interval, trans_time->start_schedule_us); |
| 627 |
} |
| 628 |
|
| 629 |
|
| 630 |
|
| 631 |
|
| 632 |
|
| 633 |
|
| 634 |
|
| 635 |
|
| 636 |
|
| 637 |
|
| 638 |
|
| 639 |
|
| 640 |
|
| 641 |
|
| 642 |
static int dwc2_uframe_schedule_split(struct dwc2_hsotg *hsotg, |
| 643 |
struct dwc2_qh *qh) |
| 644 |
{ |
| 645 |
int bytecount = qh->maxp_mult * qh->maxp; |
| 646 |
int ls_search_slice; |
| 647 |
int err = 0; |
| 648 |
int host_interval_in_sched; |
| 649 |
|
| 650 |
|
| 651 |
|
| 652 |
|
| 653 |
|
| 654 |
host_interval_in_sched = gcd(qh->host_interval, |
| 655 |
DWC2_HS_SCHEDULE_UFRAMES); |
| 656 |
|
| 657 |
|
| 658 |
|
| 659 |
|
| 660 |
|
| 661 |
|
| 662 |
|
| 663 |
|
| 664 |
|
| 665 |
|
| 666 |
|
| 667 |
|
| 668 |
ls_search_slice = 0; |
| 669 |
|
| 670 |
while (ls_search_slice < DWC2_LS_SCHEDULE_SLICES) { |
| 671 |
int start_s_uframe; |
| 672 |
int ssplit_s_uframe; |
| 673 |
int second_s_uframe; |
| 674 |
int rel_uframe; |
| 675 |
int first_count; |
| 676 |
int middle_count; |
| 677 |
int end_count; |
| 678 |
int first_data_bytes; |
| 679 |
int other_data_bytes; |
| 680 |
int i; |
| 681 |
|
| 682 |
if (qh->schedule_low_speed) { |
| 683 |
err = dwc2_ls_pmap_schedule(hsotg, qh, ls_search_slice); |
| 684 |
|
| 685 |
|
| 686 |
|
| 687 |
|
| 688 |
|
| 689 |
|
| 690 |
|
| 691 |
if (err) |
| 692 |
return err; |
| 693 |
} else { |
| 694 |
|
| 695 |
WARN_ON_ONCE(1); |
| 696 |
} |
| 697 |
|
| 698 |
|
| 699 |
|
| 700 |
|
| 701 |
|
| 702 |
start_s_uframe = qh->ls_start_schedule_slice / |
| 703 |
DWC2_SLICES_PER_UFRAME; |
| 704 |
|
| 705 |
|
| 706 |
rel_uframe = (start_s_uframe % 8); |
| 707 |
|
| 708 |
|
| 709 |
|
| 710 |
|
| 711 |
|
| 712 |
|
| 713 |
|
| 714 |
|
| 715 |
|
| 716 |
if (rel_uframe == 7) { |
| 717 |
if (qh->schedule_low_speed) |
| 718 |
dwc2_ls_pmap_unschedule(hsotg, qh); |
| 719 |
ls_search_slice = |
| 720 |
(qh->ls_start_schedule_slice / |
| 721 |
DWC2_LS_PERIODIC_SLICES_PER_FRAME + 1) * |
| 722 |
DWC2_LS_PERIODIC_SLICES_PER_FRAME; |
| 723 |
continue; |
| 724 |
} |
| 725 |
|
| 726 |
|
| 727 |
|
| 728 |
|
| 729 |
|
| 730 |
|
| 731 |
|
| 732 |
|
| 733 |
|
| 734 |
|
| 735 |
|
| 736 |
|
| 737 |
|
| 738 |
|
| 739 |
|
| 740 |
|
| 741 |
|
| 742 |
|
| 743 |
|
| 744 |
|
| 745 |
|
| 746 |
|
| 747 |
|
| 748 |
|
| 749 |
|
| 750 |
|
| 751 |
|
| 752 |
|
| 753 |
|
| 754 |
|
| 755 |
|
| 756 |
|
| 757 |
ssplit_s_uframe = (start_s_uframe + |
| 758 |
host_interval_in_sched - 1) % |
| 759 |
host_interval_in_sched; |
| 760 |
if (qh->ep_type == USB_ENDPOINT_XFER_ISOC && !qh->ep_is_in) |
| 761 |
second_s_uframe = start_s_uframe; |
| 762 |
else |
| 763 |
second_s_uframe = start_s_uframe + 1; |
| 764 |
|
| 765 |
|
| 766 |
first_data_bytes = 188 - |
| 767 |
DIV_ROUND_UP(188 * (qh->ls_start_schedule_slice % |
| 768 |
DWC2_SLICES_PER_UFRAME), |
| 769 |
DWC2_SLICES_PER_UFRAME); |
| 770 |
if (first_data_bytes > bytecount) |
| 771 |
first_data_bytes = bytecount; |
| 772 |
other_data_bytes = bytecount - first_data_bytes; |
| 773 |
|
| 774 |
|
| 775 |
|
| 776 |
|
| 777 |
|
| 778 |
|
| 779 |
|
| 780 |
|
| 781 |
|
| 782 |
|
| 783 |
|
| 784 |
|
| 785 |
|
| 786 |
|
| 787 |
|
| 788 |
|
| 789 |
if (!qh->ep_is_in && |
| 790 |
(first_data_bytes != min_t(int, 188, bytecount))) { |
| 791 |
dwc2_sch_dbg(hsotg, |
| 792 |
"QH=%p avoiding broken 1st xfer (%d, %d)\n", |
| 793 |
qh, first_data_bytes, bytecount); |
| 794 |
if (qh->schedule_low_speed) |
| 795 |
dwc2_ls_pmap_unschedule(hsotg, qh); |
| 796 |
ls_search_slice = (start_s_uframe + 1) * |
| 797 |
DWC2_SLICES_PER_UFRAME; |
| 798 |
continue; |
| 799 |
} |
| 800 |
|
| 801 |
|
| 802 |
qh->num_hs_transfers = 1 + DIV_ROUND_UP(other_data_bytes, 188); |
| 803 |
|
| 804 |
|
| 805 |
|
| 806 |
|
| 807 |
|
| 808 |
|
| 809 |
if (qh->ep_type == USB_ENDPOINT_XFER_INT) { |
| 810 |
if (rel_uframe == 6) |
| 811 |
qh->num_hs_transfers += 2; |
| 812 |
else |
| 813 |
qh->num_hs_transfers += 3; |
| 814 |
|
| 815 |
if (qh->ep_is_in) { |
| 816 |
|
| 817 |
|
| 818 |
|
| 819 |
|
| 820 |
first_count = 4; |
| 821 |
middle_count = bytecount; |
| 822 |
end_count = bytecount; |
| 823 |
} else { |
| 824 |
|
| 825 |
|
| 826 |
|
| 827 |
|
| 828 |
|
| 829 |
first_count = first_data_bytes; |
| 830 |
middle_count = max_t(int, 4, other_data_bytes); |
| 831 |
end_count = 4; |
| 832 |
} |
| 833 |
} else { |
| 834 |
if (qh->ep_is_in) { |
| 835 |
int last; |
| 836 |
|
| 837 |
|
| 838 |
qh->num_hs_transfers++; |
| 839 |
|
| 840 |
|
| 841 |
last = rel_uframe + qh->num_hs_transfers + 1; |
| 842 |
|
| 843 |
|
| 844 |
if (last <= 6) |
| 845 |
qh->num_hs_transfers += 2; |
| 846 |
else |
| 847 |
qh->num_hs_transfers += 1; |
| 848 |
|
| 849 |
|
| 850 |
if (last >= 6 && rel_uframe == 0) |
| 851 |
qh->num_hs_transfers--; |
| 852 |
|
| 853 |
|
| 854 |
first_count = 4; |
| 855 |
middle_count = min_t(int, 188, bytecount); |
| 856 |
end_count = middle_count; |
| 857 |
} else { |
| 858 |
|
| 859 |
first_count = first_data_bytes; |
| 860 |
middle_count = min_t(int, 188, |
| 861 |
other_data_bytes); |
| 862 |
end_count = other_data_bytes % 188; |
| 863 |
} |
| 864 |
} |
| 865 |
|
| 866 |
|
| 867 |
qh->hs_transfers[0].duration_us = HS_USECS_ISO(first_count); |
| 868 |
for (i = 1; i < qh->num_hs_transfers - 1; i++) |
| 869 |
qh->hs_transfers[i].duration_us = |
| 870 |
HS_USECS_ISO(middle_count); |
| 871 |
if (qh->num_hs_transfers > 1) |
| 872 |
qh->hs_transfers[qh->num_hs_transfers - 1].duration_us = |
| 873 |
HS_USECS_ISO(end_count); |
| 874 |
|
| 875 |
|
| 876 |
|
| 877 |
|
| 878 |
|
| 879 |
|
| 880 |
qh->hs_transfers[0].start_schedule_us = |
| 881 |
ssplit_s_uframe * DWC2_HS_PERIODIC_US_PER_UFRAME; |
| 882 |
for (i = 1; i < qh->num_hs_transfers; i++) |
| 883 |
qh->hs_transfers[i].start_schedule_us = |
| 884 |
((second_s_uframe + i - 1) % |
| 885 |
DWC2_HS_SCHEDULE_UFRAMES) * |
| 886 |
DWC2_HS_PERIODIC_US_PER_UFRAME; |
| 887 |
|
| 888 |
|
| 889 |
for (i = 0; i < qh->num_hs_transfers; i++) { |
| 890 |
err = dwc2_hs_pmap_schedule(hsotg, qh, true, i); |
| 891 |
if (err) |
| 892 |
break; |
| 893 |
} |
| 894 |
|
| 895 |
|
| 896 |
if (i == qh->num_hs_transfers) |
| 897 |
break; |
| 898 |
|
| 899 |
for (; i >= 0; i--) |
| 900 |
dwc2_hs_pmap_unschedule(hsotg, qh, i); |
| 901 |
|
| 902 |
if (qh->schedule_low_speed) |
| 903 |
dwc2_ls_pmap_unschedule(hsotg, qh); |
| 904 |
|
| 905 |
|
| 906 |
ls_search_slice = (start_s_uframe + 1) * DWC2_SLICES_PER_UFRAME; |
| 907 |
} |
| 908 |
|
| 909 |
if (ls_search_slice >= DWC2_LS_SCHEDULE_SLICES) |
| 910 |
return -ENOSPC; |
| 911 |
|
| 912 |
return 0; |
| 913 |
} |
| 914 |
|
| 915 |
|
| 916 |
|
| 917 |
|
| 918 |
|
| 919 |
|
| 920 |
|
| 921 |
|
| 922 |
|
| 923 |
|
| 924 |
static int dwc2_uframe_schedule_hs(struct dwc2_hsotg *hsotg, struct dwc2_qh *qh) |
| 925 |
{ |
| 926 |
|
| 927 |
WARN_ON(qh->host_us != qh->device_us); |
| 928 |
WARN_ON(qh->host_interval != qh->device_interval); |
| 929 |
WARN_ON(qh->num_hs_transfers != 1); |
| 930 |
|
| 931 |
|
| 932 |
qh->hs_transfers[0].start_schedule_us = 0; |
| 933 |
qh->hs_transfers[0].duration_us = qh->host_us; |
| 934 |
|
| 935 |
return dwc2_hs_pmap_schedule(hsotg, qh, false, 0); |
| 936 |
} |
| 937 |
|
| 938 |
|
| 939 |
|
| 940 |
|
| 941 |
|
| 942 |
|
| 943 |
|
| 944 |
|
| 945 |
|
| 946 |
|
| 947 |
static int dwc2_uframe_schedule_ls(struct dwc2_hsotg *hsotg, struct dwc2_qh *qh) |
| 948 |
{ |
| 949 |
|
| 950 |
WARN_ON(qh->host_us != qh->device_us); |
| 951 |
WARN_ON(qh->host_interval != qh->device_interval); |
| 952 |
WARN_ON(!qh->schedule_low_speed); |
| 953 |
|
| 954 |
|
| 955 |
return dwc2_ls_pmap_schedule(hsotg, qh, 0); |
| 956 |
} |
| 957 |
|
| 958 |
|
| 959 |
|
| 960 |
|
| 961 |
|
| 962 |
|
| 963 |
|
| 964 |
|
| 965 |
|
| 966 |
|
| 967 |
static int dwc2_uframe_schedule(struct dwc2_hsotg *hsotg, struct dwc2_qh *qh) |
| 968 |
{ |
| 969 |
int ret; |
| 970 |
|
| 971 |
if (qh->dev_speed == USB_SPEED_HIGH) |
| 972 |
ret = dwc2_uframe_schedule_hs(hsotg, qh); |
| 973 |
else if (!qh->do_split) |
| 974 |
ret = dwc2_uframe_schedule_ls(hsotg, qh); |
| 975 |
else |
| 976 |
ret = dwc2_uframe_schedule_split(hsotg, qh); |
| 977 |
|
| 978 |
if (ret) |
| 979 |
dwc2_sch_dbg(hsotg, "QH=%p Failed to schedule %d\n", qh, ret); |
| 980 |
else |
| 981 |
dwc2_qh_schedule_print(hsotg, qh); |
| 982 |
|
| 983 |
return ret; |
| 984 |
} |
| 985 |
|
| 986 |
|
| 987 |
|
| 988 |
|
| 989 |
|
| 990 |
|
| 991 |
|
| 992 |
static void dwc2_uframe_unschedule(struct dwc2_hsotg *hsotg, struct dwc2_qh *qh) |
| 993 |
{ |
| 994 |
int i; |
| 995 |
|
| 996 |
for (i = 0; i < qh->num_hs_transfers; i++) |
| 997 |
dwc2_hs_pmap_unschedule(hsotg, qh, i); |
| 998 |
|
| 999 |
if (qh->schedule_low_speed) |
| 1000 |
dwc2_ls_pmap_unschedule(hsotg, qh); |
| 1001 |
|
| 1002 |
dwc2_sch_dbg(hsotg, "QH=%p Unscheduled\n", qh); |
| 1003 |
} |
| 1004 |
|
| 1005 |
|
| 1006 |
|
| 1007 |
|
| 1008 |
|
| 1009 |
|
| 1010 |
|
| 1011 |
|
| 1012 |
|
| 1013 |
|
| 1014 |
|
| 1015 |
|
| 1016 |
|
| 1017 |
|
| 1018 |
|
| 1019 |
|
| 1020 |
static void dwc2_pick_first_frame(struct dwc2_hsotg *hsotg, struct dwc2_qh *qh) |
| 1021 |
{ |
| 1022 |
u16 frame_number; |
| 1023 |
u16 earliest_frame; |
| 1024 |
u16 next_active_frame; |
| 1025 |
u16 relative_frame; |
| 1026 |
u16 interval; |
| 1027 |
|
| 1028 |
|
| 1029 |
|
| 1030 |
|
| 1031 |
|
| 1032 |
frame_number = dwc2_hcd_get_frame_number(hsotg); |
| 1033 |
|
| 1034 |
|
| 1035 |
|
| 1036 |
|
| 1037 |
|
| 1038 |
|
| 1039 |
|
| 1040 |
|
| 1041 |
|
| 1042 |
earliest_frame = dwc2_frame_num_inc(frame_number, 1); |
| 1043 |
next_active_frame = earliest_frame; |
| 1044 |
|
| 1045 |
|
| 1046 |
if (!hsotg->params.uframe_sched) { |
| 1047 |
if (qh->do_split) |
| 1048 |
|
| 1049 |
next_active_frame |= 0x7; |
| 1050 |
goto exit; |
| 1051 |
} |
| 1052 |
|
| 1053 |
if (qh->dev_speed == USB_SPEED_HIGH || qh->do_split) { |
| 1054 |
|
| 1055 |
|
| 1056 |
|
| 1057 |
|
| 1058 |
|
| 1059 |
|
| 1060 |
WARN_ON(qh->num_hs_transfers < 1); |
| 1061 |
|
| 1062 |
relative_frame = qh->hs_transfers[0].start_schedule_us / |
| 1063 |
DWC2_HS_PERIODIC_US_PER_UFRAME; |
| 1064 |
|
| 1065 |
|
| 1066 |
interval = gcd(qh->host_interval, DWC2_HS_SCHEDULE_UFRAMES); |
| 1067 |
|
| 1068 |
} else { |
| 1069 |
|
| 1070 |
|
| 1071 |
|
| 1072 |
|
| 1073 |
|
| 1074 |
|
| 1075 |
|
| 1076 |
relative_frame = qh->ls_start_schedule_slice / |
| 1077 |
DWC2_LS_PERIODIC_SLICES_PER_FRAME; |
| 1078 |
interval = gcd(qh->host_interval, DWC2_LS_SCHEDULE_FRAMES); |
| 1079 |
} |
| 1080 |
|
| 1081 |
|
| 1082 |
WARN_ON(relative_frame >= interval); |
| 1083 |
|
| 1084 |
|
| 1085 |
|
| 1086 |
|
| 1087 |
|
| 1088 |
|
| 1089 |
|
| 1090 |
|
| 1091 |
|
| 1092 |
next_active_frame = (next_active_frame / interval) * interval; |
| 1093 |
|
| 1094 |
|
| 1095 |
|
| 1096 |
|
| 1097 |
|
| 1098 |
next_active_frame = dwc2_frame_num_inc(next_active_frame, |
| 1099 |
relative_frame); |
| 1100 |
|
| 1101 |
|
| 1102 |
|
| 1103 |
|
| 1104 |
|
| 1105 |
|
| 1106 |
next_active_frame = dwc2_frame_num_dec(next_active_frame, 1); |
| 1107 |
|
| 1108 |
|
| 1109 |
|
| 1110 |
|
| 1111 |
|
| 1112 |
while (dwc2_frame_num_gt(earliest_frame, next_active_frame)) |
| 1113 |
next_active_frame = dwc2_frame_num_inc(next_active_frame, |
| 1114 |
interval); |
| 1115 |
|
| 1116 |
exit: |
| 1117 |
qh->next_active_frame = next_active_frame; |
| 1118 |
qh->start_active_frame = next_active_frame; |
| 1119 |
|
| 1120 |
dwc2_sch_vdbg(hsotg, "QH=%p First fn=%04x nxt=%04x\n", |
| 1121 |
qh, frame_number, qh->next_active_frame); |
| 1122 |
} |
| 1123 |
|
| 1124 |
|
| 1125 |
|
| 1126 |
|
| 1127 |
|
| 1128 |
|
| 1129 |
|
| 1130 |
|
| 1131 |
|
| 1132 |
|
| 1133 |
|
| 1134 |
|
| 1135 |
static int dwc2_do_reserve(struct dwc2_hsotg *hsotg, struct dwc2_qh *qh) |
| 1136 |
{ |
| 1137 |
int status; |
| 1138 |
|
| 1139 |
if (hsotg->params.uframe_sched) { |
| 1140 |
status = dwc2_uframe_schedule(hsotg, qh); |
| 1141 |
} else { |
| 1142 |
status = dwc2_periodic_channel_available(hsotg); |
| 1143 |
if (status) { |
| 1144 |
dev_info(hsotg->dev, |
| 1145 |
"%s: No host channel available for periodic transfer\n", |
| 1146 |
__func__); |
| 1147 |
return status; |
| 1148 |
} |
| 1149 |
|
| 1150 |
status = dwc2_check_periodic_bandwidth(hsotg, qh); |
| 1151 |
} |
| 1152 |
|
| 1153 |
if (status) { |
| 1154 |
dev_dbg(hsotg->dev, |
| 1155 |
"%s: Insufficient periodic bandwidth for periodic transfer\n", |
| 1156 |
__func__); |
| 1157 |
return status; |
| 1158 |
} |
| 1159 |
|
| 1160 |
if (!hsotg->params.uframe_sched) |
| 1161 |
|
| 1162 |
hsotg->periodic_channels++; |
| 1163 |
|
| 1164 |
|
| 1165 |
hsotg->periodic_usecs += qh->host_us; |
| 1166 |
|
| 1167 |
dwc2_pick_first_frame(hsotg, qh); |
| 1168 |
|
| 1169 |
return 0; |
| 1170 |
} |
| 1171 |
|
| 1172 |
|
| 1173 |
|
| 1174 |
|
| 1175 |
|
| 1176 |
|
| 1177 |
|
| 1178 |
|
| 1179 |
|
| 1180 |
|
| 1181 |
static void dwc2_do_unreserve(struct dwc2_hsotg *hsotg, struct dwc2_qh *qh) |
| 1182 |
{ |
| 1183 |
assert_spin_locked(&hsotg->lock); |
| 1184 |
|
| 1185 |
WARN_ON(!qh->unreserve_pending); |
| 1186 |
|
| 1187 |
|
| 1188 |
qh->unreserve_pending = false; |
| 1189 |
|
| 1190 |
if (WARN_ON(!list_empty(&qh->qh_list_entry))) |
| 1191 |
list_del_init(&qh->qh_list_entry); |
| 1192 |
|
| 1193 |
|
| 1194 |
hsotg->periodic_usecs -= qh->host_us; |
| 1195 |
|
| 1196 |
if (hsotg->params.uframe_sched) { |
| 1197 |
dwc2_uframe_unschedule(hsotg, qh); |
| 1198 |
} else { |
| 1199 |
|
| 1200 |
hsotg->periodic_channels--; |
| 1201 |
} |
| 1202 |
} |
| 1203 |
|
| 1204 |
|
| 1205 |
|
| 1206 |
|
| 1207 |
|
| 1208 |
|
| 1209 |
|
| 1210 |
|
| 1211 |
|
| 1212 |
|
| 1213 |
|
| 1214 |
|
| 1215 |
|
| 1216 |
static void dwc2_unreserve_timer_fn(struct timer_list *t) |
| 1217 |
{ |
| 1218 |
struct dwc2_qh *qh = timer_container_of(qh, t, unreserve_timer); |
| 1219 |
struct dwc2_hsotg *hsotg = qh->hsotg; |
| 1220 |
unsigned long flags; |
| 1221 |
|
| 1222 |
|
| 1223 |
|
| 1224 |
|
| 1225 |
|
| 1226 |
|
| 1227 |
|
| 1228 |
|
| 1229 |
|
| 1230 |
|
| 1231 |
while (!spin_trylock_irqsave(&hsotg->lock, flags)) { |
| 1232 |
if (timer_pending(&qh->unreserve_timer)) |
| 1233 |
return; |
| 1234 |
} |
| 1235 |
|
| 1236 |
|
| 1237 |
|
| 1238 |
|
| 1239 |
|
| 1240 |
|
| 1241 |
|
| 1242 |
|
| 1243 |
|
| 1244 |
|
| 1245 |
|
| 1246 |
if (qh->unreserve_pending) |
| 1247 |
dwc2_do_unreserve(hsotg, qh); |
| 1248 |
|
| 1249 |
spin_unlock_irqrestore(&hsotg->lock, flags); |
| 1250 |
} |
| 1251 |
|
| 1252 |
|
| 1253 |
|
| 1254 |
|
| 1255 |
|
| 1256 |
|
| 1257 |
|
| 1258 |
|
| 1259 |
|
| 1260 |
|
| 1261 |
|
| 1262 |
static int dwc2_check_max_xfer_size(struct dwc2_hsotg *hsotg, |
| 1263 |
struct dwc2_qh *qh) |
| 1264 |
{ |
| 1265 |
u32 max_xfer_size; |
| 1266 |
u32 max_channel_xfer_size; |
| 1267 |
int status = 0; |
| 1268 |
|
| 1269 |
max_xfer_size = qh->maxp * qh->maxp_mult; |
| 1270 |
max_channel_xfer_size = hsotg->params.max_transfer_size; |
| 1271 |
|
| 1272 |
if (max_xfer_size > max_channel_xfer_size) { |
| 1273 |
dev_err(hsotg->dev, |
| 1274 |
"%s: Periodic xfer length %d > max xfer length for channel %d\n", |
| 1275 |
__func__, max_xfer_size, max_channel_xfer_size); |
| 1276 |
status = -ENOSPC; |
| 1277 |
} |
| 1278 |
|
| 1279 |
return status; |
| 1280 |
} |
| 1281 |
|
| 1282 |
|
| 1283 |
|
| 1284 |
|
| 1285 |
|
| 1286 |
|
| 1287 |
|
| 1288 |
|
| 1289 |
|
| 1290 |
|
| 1291 |
|
| 1292 |
static int dwc2_schedule_periodic(struct dwc2_hsotg *hsotg, struct dwc2_qh *qh) |
| 1293 |
{ |
| 1294 |
int status; |
| 1295 |
|
| 1296 |
status = dwc2_check_max_xfer_size(hsotg, qh); |
| 1297 |
if (status) { |
| 1298 |
dev_dbg(hsotg->dev, |
| 1299 |
"%s: Channel max transfer size too small for periodic transfer\n", |
| 1300 |
__func__); |
| 1301 |
return status; |
| 1302 |
} |
| 1303 |
|
| 1304 |
|
| 1305 |
if (timer_delete(&qh->unreserve_timer)) |
| 1306 |
WARN_ON(!qh->unreserve_pending); |
| 1307 |
|
| 1308 |
|
| 1309 |
|
| 1310 |
|
| 1311 |
|
| 1312 |
|
| 1313 |
|
| 1314 |
|
| 1315 |
if (!qh->unreserve_pending) { |
| 1316 |
status = dwc2_do_reserve(hsotg, qh); |
| 1317 |
if (status) |
| 1318 |
return status; |
| 1319 |
} else { |
| 1320 |
|
| 1321 |
|
| 1322 |
|
| 1323 |
|
| 1324 |
|
| 1325 |
|
| 1326 |
if (dwc2_frame_num_le(qh->next_active_frame, |
| 1327 |
hsotg->frame_number)) |
| 1328 |
dwc2_pick_first_frame(hsotg, qh); |
| 1329 |
} |
| 1330 |
|
| 1331 |
qh->unreserve_pending = 0; |
| 1332 |
|
| 1333 |
if (hsotg->params.dma_desc_enable) |
| 1334 |
|
| 1335 |
list_add_tail(&qh->qh_list_entry, &hsotg->periodic_sched_ready); |
| 1336 |
else |
| 1337 |
|
| 1338 |
list_add_tail(&qh->qh_list_entry, |
| 1339 |
&hsotg->periodic_sched_inactive); |
| 1340 |
|
| 1341 |
return 0; |
| 1342 |
} |
| 1343 |
|
| 1344 |
|
| 1345 |
|
| 1346 |
|
| 1347 |
|
| 1348 |
|
| 1349 |
|
| 1350 |
|
| 1351 |
static void dwc2_deschedule_periodic(struct dwc2_hsotg *hsotg, |
| 1352 |
struct dwc2_qh *qh) |
| 1353 |
{ |
| 1354 |
bool did_modify; |
| 1355 |
|
| 1356 |
assert_spin_locked(&hsotg->lock); |
| 1357 |
|
| 1358 |
|
| 1359 |
|
| 1360 |
|
| 1361 |
|
| 1362 |
|
| 1363 |
|
| 1364 |
|
| 1365 |
|
| 1366 |
|
| 1367 |
|
| 1368 |
|
| 1369 |
|
| 1370 |
|
| 1371 |
|
| 1372 |
|
| 1373 |
did_modify = mod_timer(&qh->unreserve_timer, |
| 1374 |
jiffies + DWC2_UNRESERVE_DELAY + 1); |
| 1375 |
WARN_ON(did_modify); |
| 1376 |
qh->unreserve_pending = 1; |
| 1377 |
|
| 1378 |
list_del_init(&qh->qh_list_entry); |
| 1379 |
} |
| 1380 |
|
| 1381 |
|
| 1382 |
|
| 1383 |
|
| 1384 |
|
| 1385 |
|
| 1386 |
|
| 1387 |
|
| 1388 |
|
| 1389 |
|
| 1390 |
|
| 1391 |
|
| 1392 |
|
| 1393 |
|
| 1394 |
|
| 1395 |
|
| 1396 |
|
| 1397 |
|
| 1398 |
|
| 1399 |
|
| 1400 |
|
| 1401 |
|
| 1402 |
|
| 1403 |
|
| 1404 |
static enum hrtimer_restart dwc2_wait_timer_fn(struct hrtimer *t) |
| 1405 |
{ |
| 1406 |
struct dwc2_qh *qh = container_of(t, struct dwc2_qh, wait_timer); |
| 1407 |
struct dwc2_hsotg *hsotg = qh->hsotg; |
| 1408 |
unsigned long flags; |
| 1409 |
|
| 1410 |
spin_lock_irqsave(&hsotg->lock, flags); |
| 1411 |
|
| 1412 |
|
| 1413 |
|
| 1414 |
|
| 1415 |
|
| 1416 |
if (!qh->wait_timer_cancel) { |
| 1417 |
enum dwc2_transaction_type tr_type; |
| 1418 |
|
| 1419 |
qh->want_wait = false; |
| 1420 |
|
| 1421 |
list_move(&qh->qh_list_entry, |
| 1422 |
&hsotg->non_periodic_sched_inactive); |
| 1423 |
|
| 1424 |
tr_type = dwc2_hcd_select_transactions(hsotg); |
| 1425 |
if (tr_type != DWC2_TRANSACTION_NONE) |
| 1426 |
dwc2_hcd_queue_transactions(hsotg, tr_type); |
| 1427 |
} |
| 1428 |
|
| 1429 |
spin_unlock_irqrestore(&hsotg->lock, flags); |
| 1430 |
return HRTIMER_NORESTART; |
| 1431 |
} |
| 1432 |
|
| 1433 |
|
| 1434 |
|
| 1435 |
|
| 1436 |
|
| 1437 |
|
| 1438 |
|
| 1439 |
|
| 1440 |
|
| 1441 |
|
| 1442 |
static void dwc2_qh_init(struct dwc2_hsotg *hsotg, struct dwc2_qh *qh, |
| 1443 |
struct dwc2_hcd_urb *urb, gfp_t mem_flags) |
| 1444 |
{ |
| 1445 |
int dev_speed = dwc2_host_get_speed(hsotg, urb->priv); |
| 1446 |
u8 ep_type = dwc2_hcd_get_pipe_type(&urb->pipe_info); |
| 1447 |
bool ep_is_in = !!dwc2_hcd_is_pipe_in(&urb->pipe_info); |
| 1448 |
bool ep_is_isoc = (ep_type == USB_ENDPOINT_XFER_ISOC); |
| 1449 |
bool ep_is_int = (ep_type == USB_ENDPOINT_XFER_INT); |
| 1450 |
u32 hprt = dwc2_readl(hsotg, HPRT0); |
| 1451 |
u32 prtspd = (hprt & HPRT0_SPD_MASK) >> HPRT0_SPD_SHIFT; |
| 1452 |
bool do_split = (prtspd == HPRT0_SPD_HIGH_SPEED && |
| 1453 |
dev_speed != USB_SPEED_HIGH); |
| 1454 |
int maxp = dwc2_hcd_get_maxp(&urb->pipe_info); |
| 1455 |
int maxp_mult = dwc2_hcd_get_maxp_mult(&urb->pipe_info); |
| 1456 |
int bytecount = maxp_mult * maxp; |
| 1457 |
char *speed, *type; |
| 1458 |
|
| 1459 |
|
| 1460 |
qh->hsotg = hsotg; |
| 1461 |
timer_setup(&qh->unreserve_timer, dwc2_unreserve_timer_fn, 0); |
| 1462 |
hrtimer_setup(&qh->wait_timer, &dwc2_wait_timer_fn, CLOCK_MONOTONIC, HRTIMER_MODE_REL); |
| 1463 |
qh->ep_type = ep_type; |
| 1464 |
qh->ep_is_in = ep_is_in; |
| 1465 |
|
| 1466 |
qh->data_toggle = DWC2_HC_PID_DATA0; |
| 1467 |
qh->maxp = maxp; |
| 1468 |
qh->maxp_mult = maxp_mult; |
| 1469 |
INIT_LIST_HEAD(&qh->qtd_list); |
| 1470 |
INIT_LIST_HEAD(&qh->qh_list_entry); |
| 1471 |
|
| 1472 |
qh->do_split = do_split; |
| 1473 |
qh->dev_speed = dev_speed; |
| 1474 |
|
| 1475 |
if (ep_is_int || ep_is_isoc) { |
| 1476 |
|
| 1477 |
int host_speed = do_split ? USB_SPEED_HIGH : dev_speed; |
| 1478 |
struct dwc2_tt *dwc_tt = dwc2_host_get_tt_info(hsotg, urb->priv, |
| 1479 |
mem_flags, |
| 1480 |
&qh->ttport); |
| 1481 |
int device_ns; |
| 1482 |
|
| 1483 |
qh->dwc_tt = dwc_tt; |
| 1484 |
|
| 1485 |
qh->host_us = NS_TO_US(usb_calc_bus_time(host_speed, ep_is_in, |
| 1486 |
ep_is_isoc, bytecount)); |
| 1487 |
device_ns = usb_calc_bus_time(dev_speed, ep_is_in, |
| 1488 |
ep_is_isoc, bytecount); |
| 1489 |
|
| 1490 |
if (do_split && dwc_tt) |
| 1491 |
device_ns += dwc_tt->usb_tt->think_time; |
| 1492 |
qh->device_us = NS_TO_US(device_ns); |
| 1493 |
|
| 1494 |
qh->device_interval = urb->interval; |
| 1495 |
qh->host_interval = urb->interval * (do_split ? 8 : 1); |
| 1496 |
|
| 1497 |
|
| 1498 |
|
| 1499 |
|
| 1500 |
|
| 1501 |
|
| 1502 |
qh->schedule_low_speed = prtspd != HPRT0_SPD_HIGH_SPEED || |
| 1503 |
dwc_tt; |
| 1504 |
|
| 1505 |
if (do_split) { |
| 1506 |
|
| 1507 |
qh->num_hs_transfers = -1; |
| 1508 |
} else if (dev_speed == USB_SPEED_HIGH) { |
| 1509 |
qh->num_hs_transfers = 1; |
| 1510 |
} else { |
| 1511 |
qh->num_hs_transfers = 0; |
| 1512 |
} |
| 1513 |
|
| 1514 |
|
| 1515 |
} |
| 1516 |
|
| 1517 |
switch (dev_speed) { |
| 1518 |
case USB_SPEED_LOW: |
| 1519 |
speed = "low"; |
| 1520 |
break; |
| 1521 |
case USB_SPEED_FULL: |
| 1522 |
speed = "full"; |
| 1523 |
break; |
| 1524 |
case USB_SPEED_HIGH: |
| 1525 |
speed = "high"; |
| 1526 |
break; |
| 1527 |
default: |
| 1528 |
speed = "?"; |
| 1529 |
break; |
| 1530 |
} |
| 1531 |
|
| 1532 |
switch (qh->ep_type) { |
| 1533 |
case USB_ENDPOINT_XFER_ISOC: |
| 1534 |
type = "isochronous"; |
| 1535 |
break; |
| 1536 |
case USB_ENDPOINT_XFER_INT: |
| 1537 |
type = "interrupt"; |
| 1538 |
break; |
| 1539 |
case USB_ENDPOINT_XFER_CONTROL: |
| 1540 |
type = "control"; |
| 1541 |
break; |
| 1542 |
case USB_ENDPOINT_XFER_BULK: |
| 1543 |
type = "bulk"; |
| 1544 |
break; |
| 1545 |
default: |
| 1546 |
type = "?"; |
| 1547 |
break; |
| 1548 |
} |
| 1549 |
|
| 1550 |
dwc2_sch_dbg(hsotg, "QH=%p Init %s, %s speed, %d bytes:\n", qh, type, |
| 1551 |
speed, bytecount); |
| 1552 |
dwc2_sch_dbg(hsotg, "QH=%p ...addr=%d, ep=%d, %s\n", qh, |
| 1553 |
dwc2_hcd_get_dev_addr(&urb->pipe_info), |
| 1554 |
dwc2_hcd_get_ep_num(&urb->pipe_info), |
| 1555 |
ep_is_in ? "IN" : "OUT"); |
| 1556 |
if (ep_is_int || ep_is_isoc) { |
| 1557 |
dwc2_sch_dbg(hsotg, |
| 1558 |
"QH=%p ...duration: host=%d us, device=%d us\n", |
| 1559 |
qh, qh->host_us, qh->device_us); |
| 1560 |
dwc2_sch_dbg(hsotg, "QH=%p ...interval: host=%d, device=%d\n", |
| 1561 |
qh, qh->host_interval, qh->device_interval); |
| 1562 |
if (qh->schedule_low_speed) |
| 1563 |
dwc2_sch_dbg(hsotg, "QH=%p ...low speed schedule=%p\n", |
| 1564 |
qh, dwc2_get_ls_map(hsotg, qh)); |
| 1565 |
} |
| 1566 |
} |
| 1567 |
|
| 1568 |
|
| 1569 |
|
| 1570 |
|
| 1571 |
|
| 1572 |
|
| 1573 |
|
| 1574 |
|
| 1575 |
|
| 1576 |
|
| 1577 |
|
| 1578 |
struct dwc2_qh *dwc2_hcd_qh_create(struct dwc2_hsotg *hsotg, |
| 1579 |
struct dwc2_hcd_urb *urb, |
| 1580 |
gfp_t mem_flags) |
| 1581 |
{ |
| 1582 |
struct dwc2_qh *qh; |
| 1583 |
|
| 1584 |
if (!urb->priv) |
| 1585 |
return NULL; |
| 1586 |
|
| 1587 |
|
| 1588 |
qh = kzalloc_obj(*qh, mem_flags); |
| 1589 |
if (!qh) |
| 1590 |
return NULL; |
| 1591 |
|
| 1592 |
dwc2_qh_init(hsotg, qh, urb, mem_flags); |
| 1593 |
|
| 1594 |
if (hsotg->params.dma_desc_enable && |
| 1595 |
dwc2_hcd_qh_init_ddma(hsotg, qh, mem_flags) < 0) { |
| 1596 |
dwc2_hcd_qh_free(hsotg, qh); |
| 1597 |
return NULL; |
| 1598 |
} |
| 1599 |
|
| 1600 |
return qh; |
| 1601 |
} |
| 1602 |
|
| 1603 |
|
| 1604 |
|
| 1605 |
|
| 1606 |
|
| 1607 |
|
| 1608 |
|
| 1609 |
|
| 1610 |
|
| 1611 |
|
| 1612 |
|
| 1613 |
|
| 1614 |
void dwc2_hcd_qh_free(struct dwc2_hsotg *hsotg, struct dwc2_qh *qh) |
| 1615 |
{ |
| 1616 |
|
| 1617 |
if (timer_delete_sync(&qh->unreserve_timer)) { |
| 1618 |
unsigned long flags; |
| 1619 |
|
| 1620 |
spin_lock_irqsave(&hsotg->lock, flags); |
| 1621 |
dwc2_do_unreserve(hsotg, qh); |
| 1622 |
spin_unlock_irqrestore(&hsotg->lock, flags); |
| 1623 |
} |
| 1624 |
|
| 1625 |
|
| 1626 |
|
| 1627 |
|
| 1628 |
|
| 1629 |
|
| 1630 |
|
| 1631 |
|
| 1632 |
hrtimer_cancel(&qh->wait_timer); |
| 1633 |
|
| 1634 |
dwc2_host_put_tt_info(hsotg, qh->dwc_tt); |
| 1635 |
|
| 1636 |
if (qh->desc_list) |
| 1637 |
dwc2_hcd_qh_free_ddma(hsotg, qh); |
| 1638 |
else if (hsotg->unaligned_cache && qh->dw_align_buf) |
| 1639 |
kmem_cache_free(hsotg->unaligned_cache, qh->dw_align_buf); |
| 1640 |
|
| 1641 |
kfree(qh); |
| 1642 |
} |
| 1643 |
|
| 1644 |
|
| 1645 |
|
| 1646 |
|
| 1647 |
|
| 1648 |
|
| 1649 |
|
| 1650 |
|
| 1651 |
|
| 1652 |
|
| 1653 |
|
| 1654 |
int dwc2_hcd_qh_add(struct dwc2_hsotg *hsotg, struct dwc2_qh *qh) |
| 1655 |
{ |
| 1656 |
int status; |
| 1657 |
u32 intr_mask; |
| 1658 |
ktime_t delay; |
| 1659 |
|
| 1660 |
if (dbg_qh(qh)) |
| 1661 |
dev_vdbg(hsotg->dev, "%s()\n", __func__); |
| 1662 |
|
| 1663 |
if (!list_empty(&qh->qh_list_entry)) |
| 1664 |
|
| 1665 |
return 0; |
| 1666 |
|
| 1667 |
|
| 1668 |
if (dwc2_qh_is_non_per(qh)) { |
| 1669 |
|
| 1670 |
qh->start_active_frame = hsotg->frame_number; |
| 1671 |
qh->next_active_frame = qh->start_active_frame; |
| 1672 |
|
| 1673 |
if (qh->want_wait) { |
| 1674 |
list_add_tail(&qh->qh_list_entry, |
| 1675 |
&hsotg->non_periodic_sched_waiting); |
| 1676 |
qh->wait_timer_cancel = false; |
| 1677 |
delay = ktime_set(0, DWC2_RETRY_WAIT_DELAY); |
| 1678 |
hrtimer_start(&qh->wait_timer, delay, HRTIMER_MODE_REL); |
| 1679 |
} else { |
| 1680 |
list_add_tail(&qh->qh_list_entry, |
| 1681 |
&hsotg->non_periodic_sched_inactive); |
| 1682 |
} |
| 1683 |
return 0; |
| 1684 |
} |
| 1685 |
|
| 1686 |
status = dwc2_schedule_periodic(hsotg, qh); |
| 1687 |
if (status) |
| 1688 |
return status; |
| 1689 |
if (!hsotg->periodic_qh_count) { |
| 1690 |
intr_mask = dwc2_readl(hsotg, GINTMSK); |
| 1691 |
intr_mask |= GINTSTS_SOF; |
| 1692 |
dwc2_writel(hsotg, intr_mask, GINTMSK); |
| 1693 |
} |
| 1694 |
hsotg->periodic_qh_count++; |
| 1695 |
|
| 1696 |
return 0; |
| 1697 |
} |
| 1698 |
|
| 1699 |
|
| 1700 |
|
| 1701 |
|
| 1702 |
|
| 1703 |
|
| 1704 |
|
| 1705 |
|
| 1706 |
void dwc2_hcd_qh_unlink(struct dwc2_hsotg *hsotg, struct dwc2_qh *qh) |
| 1707 |
{ |
| 1708 |
u32 intr_mask; |
| 1709 |
|
| 1710 |
dev_vdbg(hsotg->dev, "%s()\n", __func__); |
| 1711 |
|
| 1712 |
|
| 1713 |
qh->wait_timer_cancel = true; |
| 1714 |
|
| 1715 |
if (list_empty(&qh->qh_list_entry)) |
| 1716 |
|
| 1717 |
return; |
| 1718 |
|
| 1719 |
if (dwc2_qh_is_non_per(qh)) { |
| 1720 |
if (hsotg->non_periodic_qh_ptr == &qh->qh_list_entry) |
| 1721 |
hsotg->non_periodic_qh_ptr = |
| 1722 |
hsotg->non_periodic_qh_ptr->next; |
| 1723 |
list_del_init(&qh->qh_list_entry); |
| 1724 |
return; |
| 1725 |
} |
| 1726 |
|
| 1727 |
dwc2_deschedule_periodic(hsotg, qh); |
| 1728 |
hsotg->periodic_qh_count--; |
| 1729 |
if (!hsotg->periodic_qh_count && |
| 1730 |
!hsotg->params.dma_desc_enable) { |
| 1731 |
intr_mask = dwc2_readl(hsotg, GINTMSK); |
| 1732 |
intr_mask &= ~GINTSTS_SOF; |
| 1733 |
dwc2_writel(hsotg, intr_mask, GINTMSK); |
| 1734 |
} |
| 1735 |
} |
| 1736 |
|
| 1737 |
|
| 1738 |
|
| 1739 |
|
| 1740 |
|
| 1741 |
|
| 1742 |
|
| 1743 |
|
| 1744 |
|
| 1745 |
|
| 1746 |
|
| 1747 |
|
| 1748 |
|
| 1749 |
|
| 1750 |
|
| 1751 |
|
| 1752 |
|
| 1753 |
|
| 1754 |
|
| 1755 |
|
| 1756 |
static int dwc2_next_for_periodic_split(struct dwc2_hsotg *hsotg, |
| 1757 |
struct dwc2_qh *qh, u16 frame_number) |
| 1758 |
{ |
| 1759 |
u16 old_frame = qh->next_active_frame; |
| 1760 |
u16 prev_frame_number = dwc2_frame_num_dec(frame_number, 1); |
| 1761 |
int missed = 0; |
| 1762 |
u16 incr; |
| 1763 |
|
| 1764 |
|
| 1765 |
|
| 1766 |
|
| 1767 |
|
| 1768 |
|
| 1769 |
|
| 1770 |
if (old_frame == qh->start_active_frame && |
| 1771 |
!(qh->ep_type == USB_ENDPOINT_XFER_ISOC && !qh->ep_is_in)) |
| 1772 |
incr = 2; |
| 1773 |
else |
| 1774 |
incr = 1; |
| 1775 |
|
| 1776 |
qh->next_active_frame = dwc2_frame_num_inc(old_frame, incr); |
| 1777 |
|
| 1778 |
|
| 1779 |
|
| 1780 |
|
| 1781 |
|
| 1782 |
|
| 1783 |
|
| 1784 |
|
| 1785 |
|
| 1786 |
if (dwc2_frame_num_gt(prev_frame_number, qh->next_active_frame)) { |
| 1787 |
|
| 1788 |
|
| 1789 |
|
| 1790 |
|
| 1791 |
missed = dwc2_frame_num_dec(prev_frame_number, |
| 1792 |
qh->next_active_frame); |
| 1793 |
qh->next_active_frame = frame_number; |
| 1794 |
} |
| 1795 |
|
| 1796 |
return missed; |
| 1797 |
} |
| 1798 |
|
| 1799 |
|
| 1800 |
|
| 1801 |
|
| 1802 |
|
| 1803 |
|
| 1804 |
|
| 1805 |
|
| 1806 |
|
| 1807 |
|
| 1808 |
|
| 1809 |
|
| 1810 |
|
| 1811 |
|
| 1812 |
|
| 1813 |
|
| 1814 |
|
| 1815 |
|
| 1816 |
|
| 1817 |
|
| 1818 |
|
| 1819 |
static int dwc2_next_periodic_start(struct dwc2_hsotg *hsotg, |
| 1820 |
struct dwc2_qh *qh, u16 frame_number) |
| 1821 |
{ |
| 1822 |
int missed = 0; |
| 1823 |
u16 interval = qh->host_interval; |
| 1824 |
u16 prev_frame_number = dwc2_frame_num_dec(frame_number, 1); |
| 1825 |
|
| 1826 |
qh->start_active_frame = dwc2_frame_num_inc(qh->start_active_frame, |
| 1827 |
interval); |
| 1828 |
|
| 1829 |
|
| 1830 |
|
| 1831 |
|
| 1832 |
|
| 1833 |
|
| 1834 |
|
| 1835 |
|
| 1836 |
|
| 1837 |
if (interval >= 0x1000) |
| 1838 |
goto exit; |
| 1839 |
|
| 1840 |
|
| 1841 |
|
| 1842 |
|
| 1843 |
|
| 1844 |
|
| 1845 |
|
| 1846 |
|
| 1847 |
|
| 1848 |
|
| 1849 |
|
| 1850 |
|
| 1851 |
|
| 1852 |
|
| 1853 |
|
| 1854 |
|
| 1855 |
|
| 1856 |
|
| 1857 |
|
| 1858 |
|
| 1859 |
|
| 1860 |
|
| 1861 |
|
| 1862 |
|
| 1863 |
|
| 1864 |
|
| 1865 |
|
| 1866 |
if (qh->start_active_frame == qh->next_active_frame || |
| 1867 |
dwc2_frame_num_gt(prev_frame_number, qh->start_active_frame)) { |
| 1868 |
u16 ideal_start = qh->start_active_frame; |
| 1869 |
int periods_in_map; |
| 1870 |
|
| 1871 |
|
| 1872 |
|
| 1873 |
|
| 1874 |
|
| 1875 |
if (qh->do_split || qh->dev_speed == USB_SPEED_HIGH) |
| 1876 |
periods_in_map = DWC2_HS_SCHEDULE_UFRAMES; |
| 1877 |
else |
| 1878 |
periods_in_map = DWC2_LS_SCHEDULE_FRAMES; |
| 1879 |
interval = gcd(interval, periods_in_map); |
| 1880 |
|
| 1881 |
do { |
| 1882 |
qh->start_active_frame = dwc2_frame_num_inc( |
| 1883 |
qh->start_active_frame, interval); |
| 1884 |
} while (dwc2_frame_num_gt(prev_frame_number, |
| 1885 |
qh->start_active_frame)); |
| 1886 |
|
| 1887 |
missed = dwc2_frame_num_dec(qh->start_active_frame, |
| 1888 |
ideal_start); |
| 1889 |
} |
| 1890 |
|
| 1891 |
exit: |
| 1892 |
qh->next_active_frame = qh->start_active_frame; |
| 1893 |
|
| 1894 |
return missed; |
| 1895 |
} |
| 1896 |
|
| 1897 |
|
| 1898 |
|
| 1899 |
|
| 1900 |
|
| 1901 |
|
| 1902 |
|
| 1903 |
|
| 1904 |
|
| 1905 |
|
| 1906 |
|
| 1907 |
|
| 1908 |
|
| 1909 |
|
| 1910 |
void dwc2_hcd_qh_deactivate(struct dwc2_hsotg *hsotg, struct dwc2_qh *qh, |
| 1911 |
int sched_next_periodic_split) |
| 1912 |
{ |
| 1913 |
u16 old_frame = qh->next_active_frame; |
| 1914 |
u16 frame_number; |
| 1915 |
int missed; |
| 1916 |
|
| 1917 |
if (dbg_qh(qh)) |
| 1918 |
dev_vdbg(hsotg->dev, "%s()\n", __func__); |
| 1919 |
|
| 1920 |
if (dwc2_qh_is_non_per(qh)) { |
| 1921 |
dwc2_hcd_qh_unlink(hsotg, qh); |
| 1922 |
if (!list_empty(&qh->qtd_list)) |
| 1923 |
|
| 1924 |
dwc2_hcd_qh_add(hsotg, qh); |
| 1925 |
return; |
| 1926 |
} |
| 1927 |
|
| 1928 |
|
| 1929 |
|
| 1930 |
|
| 1931 |
|
| 1932 |
|
| 1933 |
|
| 1934 |
frame_number = dwc2_hcd_get_frame_number(hsotg); |
| 1935 |
|
| 1936 |
if (sched_next_periodic_split) |
| 1937 |
missed = dwc2_next_for_periodic_split(hsotg, qh, frame_number); |
| 1938 |
else |
| 1939 |
missed = dwc2_next_periodic_start(hsotg, qh, frame_number); |
| 1940 |
|
| 1941 |
dwc2_sch_vdbg(hsotg, |
| 1942 |
"QH=%p next(%d) fn=%04x, sch=%04x=>%04x (%+d) miss=%d %s\n", |
| 1943 |
qh, sched_next_periodic_split, frame_number, old_frame, |
| 1944 |
qh->next_active_frame, |
| 1945 |
dwc2_frame_num_dec(qh->next_active_frame, old_frame), |
| 1946 |
missed, missed ? "MISS" : ""); |
| 1947 |
|
| 1948 |
if (list_empty(&qh->qtd_list)) { |
| 1949 |
dwc2_hcd_qh_unlink(hsotg, qh); |
| 1950 |
return; |
| 1951 |
} |
| 1952 |
|
| 1953 |
|
| 1954 |
|
| 1955 |
|
| 1956 |
|
| 1957 |
|
| 1958 |
|
| 1959 |
|
| 1960 |
if (dwc2_frame_num_le(qh->next_active_frame, hsotg->frame_number)) |
| 1961 |
list_move_tail(&qh->qh_list_entry, |
| 1962 |
&hsotg->periodic_sched_ready); |
| 1963 |
else |
| 1964 |
list_move_tail(&qh->qh_list_entry, |
| 1965 |
&hsotg->periodic_sched_inactive); |
| 1966 |
} |
| 1967 |
|
| 1968 |
|
| 1969 |
|
| 1970 |
|
| 1971 |
|
| 1972 |
|
| 1973 |
|
| 1974 |
void dwc2_hcd_qtd_init(struct dwc2_qtd *qtd, struct dwc2_hcd_urb *urb) |
| 1975 |
{ |
| 1976 |
qtd->urb = urb; |
| 1977 |
if (dwc2_hcd_get_pipe_type(&urb->pipe_info) == |
| 1978 |
USB_ENDPOINT_XFER_CONTROL) { |
| 1979 |
|
| 1980 |
|
| 1981 |
|
| 1982 |
|
| 1983 |
|
| 1984 |
qtd->data_toggle = DWC2_HC_PID_DATA1; |
| 1985 |
qtd->control_phase = DWC2_CONTROL_SETUP; |
| 1986 |
} |
| 1987 |
|
| 1988 |
|
| 1989 |
qtd->complete_split = 0; |
| 1990 |
qtd->isoc_split_pos = DWC2_HCSPLT_XACTPOS_ALL; |
| 1991 |
qtd->isoc_split_offset = 0; |
| 1992 |
qtd->in_process = 0; |
| 1993 |
|
| 1994 |
|
| 1995 |
urb->qtd = qtd; |
| 1996 |
} |
| 1997 |
|
| 1998 |
|
| 1999 |
|
| 2000 |
|
| 2001 |
|
| 2002 |
|
| 2003 |
|
| 2004 |
|
| 2005 |
|
| 2006 |
|
| 2007 |
|
| 2008 |
|
| 2009 |
|
| 2010 |
|
| 2011 |
int dwc2_hcd_qtd_add(struct dwc2_hsotg *hsotg, struct dwc2_qtd *qtd, |
| 2012 |
struct dwc2_qh *qh) |
| 2013 |
{ |
| 2014 |
int retval; |
| 2015 |
|
| 2016 |
if (unlikely(!qh)) { |
| 2017 |
dev_err(hsotg->dev, "%s: Invalid QH\n", __func__); |
| 2018 |
retval = -EINVAL; |
| 2019 |
goto fail; |
| 2020 |
} |
| 2021 |
|
| 2022 |
retval = dwc2_hcd_qh_add(hsotg, qh); |
| 2023 |
if (retval) |
| 2024 |
goto fail; |
| 2025 |
|
| 2026 |
qtd->qh = qh; |
| 2027 |
list_add_tail(&qtd->qtd_list_entry, &qh->qtd_list); |
| 2028 |
|
| 2029 |
return 0; |
| 2030 |
fail: |
| 2031 |
return retval; |
| 2032 |
} |