Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge tag 'firewire-updates-6.18' of git://git.kernel.org/pub/scm/linux/kernel/git/ieee1394/linux1394

Pull firewire updates from Takashi Sakamoto:
"This update includes the following changes:

- Removal of the deprecated debug parameter from firewire-ohci module

- Replacement of the module-local workqueue in 1394 OHCI PCI driver
with a companion IRQ thread

- Refactoring of bus management code

- Additional minor code cleanup

The existing tracepoints serve as an alternative to the removed debug
parameter. The use of IRQ thread is experimental, as it handles 1394
OHCI SelfIDComplete event only. It may be replaced in the future
releases with another approach; e.g. by providing workqueue from core
functionality"

* tag 'firewire-updates-6.18' of git://git.kernel.org/pub/scm/linux/kernel/git/ieee1394/linux1394: (43 commits)
firewire: core: fix undefined reference error in ARM EABI
Revert "firewire: core: disable bus management work temporarily during updating topology"
Revert "firewire: core: shrink critical section of fw_card spinlock in bm_work"
firewire: core: suppress overflow warning when computing jiffies from isochronous cycle
firewire: core: minor code refactoring to delete useless local variable
firewire: core; eliminate pick_me goto label
firewire: core: code refactoring to split contention procedure for bus manager
firewire: core: code refactoring for the case of generation mismatch
firewire: core: use switch statement to evaluate transaction result to CSR_BUS_MANAGER_ID
firewire: core: remove useless generation check
firewire: core: use struct_size and flex_array_size in ioctl_add_descriptor
firewire: core: shrink critical section of fw_card spinlock in bm_work
firewire: core: disable bus management work temporarily during updating topology
firewire: core: schedule bm_work item outside of spin lock
firewire: core: annotate fw_destroy_nodes with must-hold-lock
firewire: core: use spin lock specific to timer for split transaction
firewire: core: use spin lock specific to transaction
firewire: core: use spin lock specific to topology map
firewire: core: maintain phy packet receivers locally in cdev layer
firewire: core: use scoped_guard() to manage critical section to update topology
...

+522 -631
+266 -234
drivers/firewire/core-card.c
··· 229 229 230 230 /* Use an arbitrary short delay to combine multiple reset requests. */ 231 231 fw_card_get(card); 232 - if (!queue_delayed_work(fw_workqueue, &card->br_work, 233 - delayed ? DIV_ROUND_UP(HZ, 100) : 0)) 232 + if (!queue_delayed_work(fw_workqueue, &card->br_work, delayed ? msecs_to_jiffies(10) : 0)) 234 233 fw_card_put(card); 235 234 } 236 235 EXPORT_SYMBOL(fw_schedule_bus_reset); ··· 240 241 241 242 /* Delay for 2s after last reset per IEEE 1394 clause 8.2.1. */ 242 243 if (card->reset_jiffies != 0 && 243 - time_before64(get_jiffies_64(), card->reset_jiffies + 2 * HZ)) { 244 + time_is_after_jiffies64(card->reset_jiffies + secs_to_jiffies(2))) { 244 245 trace_bus_reset_postpone(card->index, card->generation, card->br_short); 245 246 246 - if (!queue_delayed_work(fw_workqueue, &card->br_work, 2 * HZ)) 247 + if (!queue_delayed_work(fw_workqueue, &card->br_work, secs_to_jiffies(2))) 247 248 fw_card_put(card); 248 249 return; 249 250 } ··· 279 280 fw_card_put(card); 280 281 } 281 282 283 + enum bm_contention_outcome { 284 + // The bus management contention window is not expired. 285 + BM_CONTENTION_OUTCOME_WITHIN_WINDOW = 0, 286 + // The IRM node has link off. 287 + BM_CONTENTION_OUTCOME_IRM_HAS_LINK_OFF, 288 + // The IRM node complies IEEE 1394:1994 only. 289 + BM_CONTENTION_OUTCOME_IRM_COMPLIES_1394_1995_ONLY, 290 + // Another bus reset, BM work has been rescheduled. 291 + BM_CONTENTION_OUTCOME_AT_NEW_GENERATION, 292 + // We have been unable to send the lock request to IRM node due to some local problem. 293 + BM_CONTENTION_OUTCOME_LOCAL_PROBLEM_AT_TRANSACTION, 294 + // The lock request failed, maybe the IRM isn't really IRM capable after all. 295 + BM_CONTENTION_OUTCOME_IRM_IS_NOT_CAPABLE_FOR_IRM, 296 + // Somebody else is BM. 297 + BM_CONTENTION_OUTCOME_IRM_HOLDS_ANOTHER_NODE_AS_BM, 298 + // The local node succeeds after contending for bus manager. 299 + BM_CONTENTION_OUTCOME_IRM_HOLDS_LOCAL_NODE_AS_BM, 300 + }; 301 + 302 + static enum bm_contention_outcome contend_for_bm(struct fw_card *card) 303 + __must_hold(&card->lock) 304 + { 305 + int generation = card->generation; 306 + int local_id = card->local_node->node_id; 307 + __be32 data[2] = { 308 + cpu_to_be32(BUS_MANAGER_ID_NOT_REGISTERED), 309 + cpu_to_be32(local_id), 310 + }; 311 + bool grace = time_is_before_jiffies64(card->reset_jiffies + msecs_to_jiffies(125)); 312 + bool irm_is_1394_1995_only = false; 313 + bool keep_this_irm = false; 314 + struct fw_node *irm_node; 315 + struct fw_device *irm_device; 316 + int irm_node_id; 317 + int rcode; 318 + 319 + lockdep_assert_held(&card->lock); 320 + 321 + if (!grace) { 322 + if (!is_next_generation(generation, card->bm_generation) || card->bm_abdicate) 323 + return BM_CONTENTION_OUTCOME_WITHIN_WINDOW; 324 + } 325 + 326 + irm_node = card->irm_node; 327 + if (!irm_node->link_on) { 328 + fw_notice(card, "IRM has link off, making local node (%02x) root\n", local_id); 329 + return BM_CONTENTION_OUTCOME_IRM_HAS_LINK_OFF; 330 + } 331 + 332 + irm_device = fw_node_get_device(irm_node); 333 + if (irm_device && irm_device->config_rom) { 334 + irm_is_1394_1995_only = (irm_device->config_rom[2] & 0x000000f0) == 0; 335 + 336 + // Canon MV5i works unreliably if it is not root node. 337 + keep_this_irm = irm_device->config_rom[3] >> 8 == CANON_OUI; 338 + } 339 + 340 + if (irm_is_1394_1995_only && !keep_this_irm) { 341 + fw_notice(card, "IRM is not 1394a compliant, making local node (%02x) root\n", 342 + local_id); 343 + return BM_CONTENTION_OUTCOME_IRM_COMPLIES_1394_1995_ONLY; 344 + } 345 + 346 + irm_node_id = irm_node->node_id; 347 + 348 + spin_unlock_irq(&card->lock); 349 + 350 + rcode = fw_run_transaction(card, TCODE_LOCK_COMPARE_SWAP, irm_node_id, generation, 351 + SCODE_100, CSR_REGISTER_BASE + CSR_BUS_MANAGER_ID, data, 352 + sizeof(data)); 353 + 354 + spin_lock_irq(&card->lock); 355 + 356 + switch (rcode) { 357 + case RCODE_GENERATION: 358 + return BM_CONTENTION_OUTCOME_AT_NEW_GENERATION; 359 + case RCODE_SEND_ERROR: 360 + return BM_CONTENTION_OUTCOME_LOCAL_PROBLEM_AT_TRANSACTION; 361 + case RCODE_COMPLETE: 362 + { 363 + int bm_id = be32_to_cpu(data[0]); 364 + 365 + // Used by cdev layer for "struct fw_cdev_event_bus_reset". 366 + if (bm_id != BUS_MANAGER_ID_NOT_REGISTERED) 367 + card->bm_node_id = 0xffc0 & bm_id; 368 + else 369 + card->bm_node_id = local_id; 370 + 371 + if (bm_id != BUS_MANAGER_ID_NOT_REGISTERED) 372 + return BM_CONTENTION_OUTCOME_IRM_HOLDS_ANOTHER_NODE_AS_BM; 373 + else 374 + return BM_CONTENTION_OUTCOME_IRM_HOLDS_LOCAL_NODE_AS_BM; 375 + } 376 + default: 377 + if (!keep_this_irm) { 378 + fw_notice(card, "BM lock failed (%s), making local node (%02x) root\n", 379 + fw_rcode_string(rcode), local_id); 380 + return BM_CONTENTION_OUTCOME_IRM_COMPLIES_1394_1995_ONLY; 381 + } else { 382 + return BM_CONTENTION_OUTCOME_IRM_IS_NOT_CAPABLE_FOR_IRM; 383 + } 384 + } 385 + } 386 + 387 + DEFINE_FREE(node_unref, struct fw_node *, if (_T) fw_node_put(_T)) 388 + DEFINE_FREE(card_unref, struct fw_card *, if (_T) fw_card_put(_T)) 389 + 282 390 static void bm_work(struct work_struct *work) 283 391 { 284 392 static const char gap_count_table[] = { 285 393 63, 5, 7, 8, 10, 13, 16, 18, 21, 24, 26, 29, 32, 35, 37, 40 286 394 }; 287 - struct fw_card *card = from_work(card, work, bm_work.work); 288 - struct fw_device *root_device, *irm_device; 289 - struct fw_node *root_node; 290 - int root_id, new_root_id, irm_id, bm_id, local_id; 291 - int gap_count, generation, grace, rcode; 292 - bool do_reset = false; 293 - bool root_device_is_running; 294 - bool root_device_is_cmc; 295 - bool irm_is_1394_1995_only; 296 - bool keep_this_irm; 297 - __be32 transaction_data[2]; 395 + struct fw_card *card __free(card_unref) = from_work(card, work, bm_work.work); 396 + struct fw_node *root_node __free(node_unref) = NULL; 397 + int root_id, new_root_id, irm_id, local_id; 398 + int expected_gap_count, generation; 399 + bool stand_for_root = false; 298 400 299 401 spin_lock_irq(&card->lock); 300 402 301 403 if (card->local_node == NULL) { 302 404 spin_unlock_irq(&card->lock); 303 - goto out_put_card; 405 + return; 304 406 } 305 407 306 408 generation = card->generation; 307 409 308 - root_node = card->root_node; 309 - fw_node_get(root_node); 310 - root_device = root_node->data; 311 - root_device_is_running = root_device && 312 - atomic_read(&root_device->state) == FW_DEVICE_RUNNING; 313 - root_device_is_cmc = root_device && root_device->cmc; 314 - 315 - irm_device = card->irm_node->data; 316 - irm_is_1394_1995_only = irm_device && irm_device->config_rom && 317 - (irm_device->config_rom[2] & 0x000000f0) == 0; 318 - 319 - /* Canon MV5i works unreliably if it is not root node. */ 320 - keep_this_irm = irm_device && irm_device->config_rom && 321 - irm_device->config_rom[3] >> 8 == CANON_OUI; 410 + root_node = fw_node_get(card->root_node); 322 411 323 412 root_id = root_node->node_id; 324 413 irm_id = card->irm_node->node_id; 325 414 local_id = card->local_node->node_id; 326 415 327 - grace = time_after64(get_jiffies_64(), 328 - card->reset_jiffies + DIV_ROUND_UP(HZ, 8)); 416 + if (card->bm_generation != generation) { 417 + enum bm_contention_outcome result = contend_for_bm(card); 329 418 330 - if ((is_next_generation(generation, card->bm_generation) && 331 - !card->bm_abdicate) || 332 - (card->bm_generation != generation && grace)) { 333 - /* 334 - * This first step is to figure out who is IRM and 335 - * then try to become bus manager. If the IRM is not 336 - * well defined (e.g. does not have an active link 337 - * layer or does not responds to our lock request, we 338 - * will have to do a little vigilante bus management. 339 - * In that case, we do a goto into the gap count logic 340 - * so that when we do the reset, we still optimize the 341 - * gap count. That could well save a reset in the 342 - * next generation. 343 - */ 344 - 345 - if (!card->irm_node->link_on) { 346 - new_root_id = local_id; 347 - fw_notice(card, "%s, making local node (%02x) root\n", 348 - "IRM has link off", new_root_id); 349 - goto pick_me; 350 - } 351 - 352 - if (irm_is_1394_1995_only && !keep_this_irm) { 353 - new_root_id = local_id; 354 - fw_notice(card, "%s, making local node (%02x) root\n", 355 - "IRM is not 1394a compliant", new_root_id); 356 - goto pick_me; 357 - } 358 - 359 - transaction_data[0] = cpu_to_be32(0x3f); 360 - transaction_data[1] = cpu_to_be32(local_id); 361 - 362 - spin_unlock_irq(&card->lock); 363 - 364 - rcode = fw_run_transaction(card, TCODE_LOCK_COMPARE_SWAP, 365 - irm_id, generation, SCODE_100, 366 - CSR_REGISTER_BASE + CSR_BUS_MANAGER_ID, 367 - transaction_data, 8); 368 - 369 - if (rcode == RCODE_GENERATION) 370 - /* Another bus reset, BM work has been rescheduled. */ 371 - goto out; 372 - 373 - bm_id = be32_to_cpu(transaction_data[0]); 374 - 375 - scoped_guard(spinlock_irq, &card->lock) { 376 - if (rcode == RCODE_COMPLETE && generation == card->generation) 377 - card->bm_node_id = 378 - bm_id == 0x3f ? local_id : 0xffc0 | bm_id; 379 - } 380 - 381 - if (rcode == RCODE_COMPLETE && bm_id != 0x3f) { 382 - /* Somebody else is BM. Only act as IRM. */ 383 - if (local_id == irm_id) 419 + switch (result) { 420 + case BM_CONTENTION_OUTCOME_WITHIN_WINDOW: 421 + spin_unlock_irq(&card->lock); 422 + fw_schedule_bm_work(card, msecs_to_jiffies(125)); 423 + return; 424 + case BM_CONTENTION_OUTCOME_IRM_HAS_LINK_OFF: 425 + stand_for_root = true; 426 + break; 427 + case BM_CONTENTION_OUTCOME_IRM_COMPLIES_1394_1995_ONLY: 428 + stand_for_root = true; 429 + break; 430 + case BM_CONTENTION_OUTCOME_AT_NEW_GENERATION: 431 + // BM work has been rescheduled. 432 + spin_unlock_irq(&card->lock); 433 + return; 434 + case BM_CONTENTION_OUTCOME_LOCAL_PROBLEM_AT_TRANSACTION: 435 + // Let's try again later and hope that the local problem has gone away by 436 + // then. 437 + spin_unlock_irq(&card->lock); 438 + fw_schedule_bm_work(card, msecs_to_jiffies(125)); 439 + return; 440 + case BM_CONTENTION_OUTCOME_IRM_IS_NOT_CAPABLE_FOR_IRM: 441 + // Let's do a bus reset and pick the local node as root, and thus, IRM. 442 + stand_for_root = true; 443 + break; 444 + case BM_CONTENTION_OUTCOME_IRM_HOLDS_ANOTHER_NODE_AS_BM: 445 + if (local_id == irm_id) { 446 + // Only acts as IRM. 447 + spin_unlock_irq(&card->lock); 384 448 allocate_broadcast_channel(card, generation); 385 - 386 - goto out; 449 + spin_lock_irq(&card->lock); 450 + } 451 + fallthrough; 452 + case BM_CONTENTION_OUTCOME_IRM_HOLDS_LOCAL_NODE_AS_BM: 453 + default: 454 + card->bm_generation = generation; 455 + break; 387 456 } 388 - 389 - if (rcode == RCODE_SEND_ERROR) { 390 - /* 391 - * We have been unable to send the lock request due to 392 - * some local problem. Let's try again later and hope 393 - * that the problem has gone away by then. 394 - */ 395 - fw_schedule_bm_work(card, DIV_ROUND_UP(HZ, 8)); 396 - goto out; 397 - } 398 - 399 - spin_lock_irq(&card->lock); 400 - 401 - if (rcode != RCODE_COMPLETE && !keep_this_irm) { 402 - /* 403 - * The lock request failed, maybe the IRM 404 - * isn't really IRM capable after all. Let's 405 - * do a bus reset and pick the local node as 406 - * root, and thus, IRM. 407 - */ 408 - new_root_id = local_id; 409 - fw_notice(card, "BM lock failed (%s), making local node (%02x) root\n", 410 - fw_rcode_string(rcode), new_root_id); 411 - goto pick_me; 412 - } 413 - } else if (card->bm_generation != generation) { 414 - /* 415 - * We weren't BM in the last generation, and the last 416 - * bus reset is less than 125ms ago. Reschedule this job. 417 - */ 418 - spin_unlock_irq(&card->lock); 419 - fw_schedule_bm_work(card, DIV_ROUND_UP(HZ, 8)); 420 - goto out; 421 457 } 422 458 423 - /* 424 - * We're bus manager for this generation, so next step is to 425 - * make sure we have an active cycle master and do gap count 426 - * optimization. 427 - */ 428 - card->bm_generation = generation; 459 + // We're bus manager for this generation, so next step is to make sure we have an active 460 + // cycle master and do gap count optimization. 461 + if (!stand_for_root) { 462 + if (card->gap_count == GAP_COUNT_MISMATCHED) { 463 + // If self IDs have inconsistent gap counts, do a 464 + // bus reset ASAP. The config rom read might never 465 + // complete, so don't wait for it. However, still 466 + // send a PHY configuration packet prior to the 467 + // bus reset. The PHY configuration packet might 468 + // fail, but 1394-2008 8.4.5.2 explicitly permits 469 + // it in this case, so it should be safe to try. 470 + stand_for_root = true; 429 471 430 - if (card->gap_count == 0) { 431 - /* 432 - * If self IDs have inconsistent gap counts, do a 433 - * bus reset ASAP. The config rom read might never 434 - * complete, so don't wait for it. However, still 435 - * send a PHY configuration packet prior to the 436 - * bus reset. The PHY configuration packet might 437 - * fail, but 1394-2008 8.4.5.2 explicitly permits 438 - * it in this case, so it should be safe to try. 439 - */ 472 + // We must always send a bus reset if the gap count 473 + // is inconsistent, so bypass the 5-reset limit. 474 + card->bm_retries = 0; 475 + } else { 476 + // Now investigate root node. 477 + struct fw_device *root_device = fw_node_get_device(root_node); 478 + 479 + if (root_device == NULL) { 480 + // Either link_on is false, or we failed to read the 481 + // config rom. In either case, pick another root. 482 + stand_for_root = true; 483 + } else { 484 + bool root_device_is_running = 485 + atomic_read(&root_device->state) == FW_DEVICE_RUNNING; 486 + 487 + if (!root_device_is_running) { 488 + // If we haven't probed this device yet, bail out now 489 + // and let's try again once that's done. 490 + spin_unlock_irq(&card->lock); 491 + return; 492 + } else if (!root_device->cmc) { 493 + // Current root has an active link layer and we 494 + // successfully read the config rom, but it's not 495 + // cycle master capable. 496 + stand_for_root = true; 497 + } 498 + } 499 + } 500 + } 501 + 502 + if (stand_for_root) { 440 503 new_root_id = local_id; 441 - /* 442 - * We must always send a bus reset if the gap count 443 - * is inconsistent, so bypass the 5-reset limit. 444 - */ 445 - card->bm_retries = 0; 446 - } else if (root_device == NULL) { 447 - /* 448 - * Either link_on is false, or we failed to read the 449 - * config rom. In either case, pick another root. 450 - */ 451 - new_root_id = local_id; 452 - } else if (!root_device_is_running) { 453 - /* 454 - * If we haven't probed this device yet, bail out now 455 - * and let's try again once that's done. 456 - */ 457 - spin_unlock_irq(&card->lock); 458 - goto out; 459 - } else if (root_device_is_cmc) { 460 - /* 461 - * We will send out a force root packet for this 462 - * node as part of the gap count optimization. 463 - */ 464 - new_root_id = root_id; 465 504 } else { 466 - /* 467 - * Current root has an active link layer and we 468 - * successfully read the config rom, but it's not 469 - * cycle master capable. 470 - */ 471 - new_root_id = local_id; 505 + // We will send out a force root packet for this node as part of the gap count 506 + // optimization on behalf of the node. 507 + new_root_id = root_id; 472 508 } 473 509 474 - pick_me: 475 510 /* 476 511 * Pick a gap count from 1394a table E-1. The table doesn't cover 477 512 * the typically much larger 1394b beta repeater delays though. 478 513 */ 479 514 if (!card->beta_repeaters_present && 480 515 root_node->max_hops < ARRAY_SIZE(gap_count_table)) 481 - gap_count = gap_count_table[root_node->max_hops]; 516 + expected_gap_count = gap_count_table[root_node->max_hops]; 482 517 else 483 - gap_count = 63; 518 + expected_gap_count = 63; 484 519 485 - /* 486 - * Finally, figure out if we should do a reset or not. If we have 487 - * done less than 5 resets with the same physical topology and we 488 - * have either a new root or a new gap count setting, let's do it. 489 - */ 520 + // Finally, figure out if we should do a reset or not. If we have done less than 5 resets 521 + // with the same physical topology and we have either a new root or a new gap count 522 + // setting, let's do it. 523 + if (card->bm_retries++ < 5 && (card->gap_count != expected_gap_count || new_root_id != root_id)) { 524 + int card_gap_count = card->gap_count; 490 525 491 - if (card->bm_retries++ < 5 && 492 - (card->gap_count != gap_count || new_root_id != root_id)) 493 - do_reset = true; 526 + spin_unlock_irq(&card->lock); 494 527 495 - spin_unlock_irq(&card->lock); 496 - 497 - if (do_reset) { 498 528 fw_notice(card, "phy config: new root=%x, gap_count=%d\n", 499 - new_root_id, gap_count); 500 - fw_send_phy_config(card, new_root_id, generation, gap_count); 529 + new_root_id, expected_gap_count); 530 + fw_send_phy_config(card, new_root_id, generation, expected_gap_count); 501 531 /* 502 532 * Where possible, use a short bus reset to minimize 503 533 * disruption to isochronous transfers. But in the event ··· 539 511 * may treat it as two, causing a gap count inconsistency 540 512 * again. Using a long bus reset prevents this. 541 513 */ 542 - reset_bus(card, card->gap_count != 0); 514 + reset_bus(card, card_gap_count != 0); 543 515 /* Will allocate broadcast channel after the reset. */ 544 - goto out; 516 + } else { 517 + struct fw_device *root_device = fw_node_get_device(root_node); 518 + 519 + spin_unlock_irq(&card->lock); 520 + 521 + if (root_device && root_device->cmc) { 522 + // Make sure that the cycle master sends cycle start packets. 523 + __be32 data = cpu_to_be32(CSR_STATE_BIT_CMSTR); 524 + int rcode = fw_run_transaction(card, TCODE_WRITE_QUADLET_REQUEST, 525 + root_id, generation, SCODE_100, 526 + CSR_REGISTER_BASE + CSR_STATE_SET, 527 + &data, sizeof(data)); 528 + if (rcode == RCODE_GENERATION) 529 + return; 530 + } 531 + 532 + if (local_id == irm_id) 533 + allocate_broadcast_channel(card, generation); 545 534 } 546 - 547 - if (root_device_is_cmc) { 548 - /* 549 - * Make sure that the cycle master sends cycle start packets. 550 - */ 551 - transaction_data[0] = cpu_to_be32(CSR_STATE_BIT_CMSTR); 552 - rcode = fw_run_transaction(card, TCODE_WRITE_QUADLET_REQUEST, 553 - root_id, generation, SCODE_100, 554 - CSR_REGISTER_BASE + CSR_STATE_SET, 555 - transaction_data, 4); 556 - if (rcode == RCODE_GENERATION) 557 - goto out; 558 - } 559 - 560 - if (local_id == irm_id) 561 - allocate_broadcast_channel(card, generation); 562 - 563 - out: 564 - fw_node_put(root_node); 565 - out_put_card: 566 - fw_card_put(card); 567 535 } 568 536 569 537 void fw_card_initialize(struct fw_card *card, ··· 571 547 card->index = atomic_inc_return(&index); 572 548 card->driver = driver; 573 549 card->device = device; 574 - card->current_tlabel = 0; 575 - card->tlabel_mask = 0; 576 - card->split_timeout_hi = DEFAULT_SPLIT_TIMEOUT / 8000; 577 - card->split_timeout_lo = (DEFAULT_SPLIT_TIMEOUT % 8000) << 19; 578 - card->split_timeout_cycles = DEFAULT_SPLIT_TIMEOUT; 579 - card->split_timeout_jiffies = 580 - DIV_ROUND_UP(DEFAULT_SPLIT_TIMEOUT * HZ, 8000); 550 + 551 + card->transactions.current_tlabel = 0; 552 + card->transactions.tlabel_mask = 0; 553 + INIT_LIST_HEAD(&card->transactions.list); 554 + spin_lock_init(&card->transactions.lock); 555 + 556 + card->split_timeout.hi = DEFAULT_SPLIT_TIMEOUT / 8000; 557 + card->split_timeout.lo = (DEFAULT_SPLIT_TIMEOUT % 8000) << 19; 558 + card->split_timeout.cycles = DEFAULT_SPLIT_TIMEOUT; 559 + card->split_timeout.jiffies = isoc_cycles_to_jiffies(DEFAULT_SPLIT_TIMEOUT); 560 + spin_lock_init(&card->split_timeout.lock); 561 + 581 562 card->color = 0; 582 563 card->broadcast_channel = BROADCAST_CHANNEL_INITIAL; 583 564 584 565 kref_init(&card->kref); 585 566 init_completion(&card->done); 586 - INIT_LIST_HEAD(&card->transaction_list); 587 - INIT_LIST_HEAD(&card->phy_receiver_list); 567 + 588 568 spin_lock_init(&card->lock); 589 569 590 570 card->local_node = NULL; ··· 598 570 } 599 571 EXPORT_SYMBOL(fw_card_initialize); 600 572 573 + DEFINE_FREE(workqueue_destroy, struct workqueue_struct *, if (_T) destroy_workqueue(_T)) 574 + 601 575 int fw_card_add(struct fw_card *card, u32 max_receive, u32 link_speed, u64 guid, 602 576 unsigned int supported_isoc_contexts) 603 577 { 578 + struct workqueue_struct *isoc_wq __free(workqueue_destroy) = NULL; 579 + struct workqueue_struct *async_wq __free(workqueue_destroy) = NULL; 604 580 int ret; 605 581 606 582 // This workqueue should be: ··· 619 587 // * == WQ_SYSFS Parameters are available via sysfs. 620 588 // * max_active == n_it + n_ir A hardIRQ could notify events for multiple isochronous 621 589 // contexts if they are scheduled to the same cycle. 622 - card->isoc_wq = alloc_workqueue("firewire-isoc-card%u", 623 - WQ_UNBOUND | WQ_FREEZABLE | WQ_HIGHPRI | WQ_SYSFS, 624 - supported_isoc_contexts, card->index); 625 - if (!card->isoc_wq) 590 + isoc_wq = alloc_workqueue("firewire-isoc-card%u", 591 + WQ_UNBOUND | WQ_FREEZABLE | WQ_HIGHPRI | WQ_SYSFS, 592 + supported_isoc_contexts, card->index); 593 + if (!isoc_wq) 626 594 return -ENOMEM; 627 595 628 596 // This workqueue should be: ··· 634 602 // * == WQ_SYSFS Parameters are available via sysfs. 635 603 // * max_active == 4 A hardIRQ could notify events for a pair of requests and 636 604 // response AR/AT contexts. 637 - card->async_wq = alloc_workqueue("firewire-async-card%u", 638 - WQ_UNBOUND | WQ_MEM_RECLAIM | WQ_FREEZABLE | WQ_HIGHPRI | WQ_SYSFS, 639 - 4, card->index); 640 - if (!card->async_wq) { 641 - ret = -ENOMEM; 642 - goto err_isoc; 643 - } 605 + async_wq = alloc_workqueue("firewire-async-card%u", 606 + WQ_UNBOUND | WQ_MEM_RECLAIM | WQ_FREEZABLE | WQ_HIGHPRI | WQ_SYSFS, 607 + 4, card->index); 608 + if (!async_wq) 609 + return -ENOMEM; 644 610 611 + card->isoc_wq = isoc_wq; 612 + card->async_wq = async_wq; 645 613 card->max_receive = max_receive; 646 614 card->link_speed = link_speed; 647 615 card->guid = guid; ··· 649 617 scoped_guard(mutex, &card_mutex) { 650 618 generate_config_rom(card, tmp_config_rom); 651 619 ret = card->driver->enable(card, tmp_config_rom, config_rom_length); 652 - if (ret < 0) 653 - goto err_async; 620 + if (ret < 0) { 621 + card->isoc_wq = NULL; 622 + card->async_wq = NULL; 623 + return ret; 624 + } 625 + retain_and_null_ptr(isoc_wq); 626 + retain_and_null_ptr(async_wq); 654 627 655 628 list_add_tail(&card->link, &card_list); 656 629 } 657 630 658 631 return 0; 659 - err_async: 660 - destroy_workqueue(card->async_wq); 661 - err_isoc: 662 - destroy_workqueue(card->isoc_wq); 663 - return ret; 664 632 } 665 633 EXPORT_SYMBOL(fw_card_add); 666 634 ··· 805 773 destroy_workqueue(card->isoc_wq); 806 774 destroy_workqueue(card->async_wq); 807 775 808 - WARN_ON(!list_empty(&card->transaction_list)); 776 + WARN_ON(!list_empty(&card->transactions.list)); 809 777 } 810 778 EXPORT_SYMBOL(fw_core_remove_card); 811 779
+25 -11
drivers/firewire/core-cdev.c
··· 47 47 #define FW_CDEV_VERSION_AUTO_FLUSH_ISO_OVERFLOW 5 48 48 #define FW_CDEV_VERSION_EVENT_ASYNC_TSTAMP 6 49 49 50 + static DEFINE_SPINLOCK(phy_receiver_list_lock); 51 + static LIST_HEAD(phy_receiver_list); 52 + 50 53 struct client { 51 54 u32 version; 52 55 struct fw_device *device; ··· 940 937 if (a->length > 256) 941 938 return -EINVAL; 942 939 943 - r = kmalloc(sizeof(*r) + a->length * 4, GFP_KERNEL); 940 + r = kmalloc(struct_size(r, data, a->length), GFP_KERNEL); 944 941 if (r == NULL) 945 942 return -ENOMEM; 946 943 947 - if (copy_from_user(r->data, u64_to_uptr(a->data), a->length * 4)) { 944 + if (copy_from_user(r->data, u64_to_uptr(a->data), 945 + flex_array_size(r, data, a->length))) { 948 946 ret = -EFAULT; 949 947 goto failed; 950 948 } ··· 1328 1324 todo = r->todo; 1329 1325 // Allow 1000ms grace period for other reallocations. 1330 1326 if (todo == ISO_RES_ALLOC && 1331 - time_before64(get_jiffies_64(), client->device->card->reset_jiffies + HZ)) { 1332 - schedule_iso_resource(r, DIV_ROUND_UP(HZ, 3)); 1327 + time_is_after_jiffies64(client->device->card->reset_jiffies + secs_to_jiffies(1))) { 1328 + schedule_iso_resource(r, msecs_to_jiffies(333)); 1333 1329 skip = true; 1334 1330 } else { 1335 1331 // We could be called twice within the same generation. ··· 1673 1669 static int ioctl_receive_phy_packets(struct client *client, union ioctl_arg *arg) 1674 1670 { 1675 1671 struct fw_cdev_receive_phy_packets *a = &arg->receive_phy_packets; 1676 - struct fw_card *card = client->device->card; 1677 1672 1678 1673 /* Access policy: Allow this ioctl only on local nodes' device files. */ 1679 1674 if (!client->device->is_local) 1680 1675 return -ENOSYS; 1681 1676 1682 - guard(spinlock_irq)(&card->lock); 1677 + // NOTE: This can be without irq when we can guarantee that __fw_send_request() for local 1678 + // destination never runs in any type of IRQ context. 1679 + scoped_guard(spinlock_irq, &phy_receiver_list_lock) 1680 + list_move_tail(&client->phy_receiver_link, &phy_receiver_list); 1683 1681 1684 - list_move_tail(&client->phy_receiver_link, &card->phy_receiver_list); 1685 1682 client->phy_receiver_closure = a->closure; 1686 1683 1687 1684 return 0; ··· 1692 1687 { 1693 1688 struct client *client; 1694 1689 1695 - guard(spinlock_irqsave)(&card->lock); 1690 + // NOTE: This can be without irqsave when we can guarantee that __fw_send_request() for local 1691 + // destination never runs in any type of IRQ context. 1692 + guard(spinlock_irqsave)(&phy_receiver_list_lock); 1696 1693 1697 - list_for_each_entry(client, &card->phy_receiver_list, phy_receiver_link) { 1698 - struct inbound_phy_packet_event *e = kmalloc(sizeof(*e) + 8, GFP_ATOMIC); 1694 + list_for_each_entry(client, &phy_receiver_list, phy_receiver_link) { 1695 + struct inbound_phy_packet_event *e; 1696 + 1697 + if (client->device->card != card) 1698 + continue; 1699 + 1700 + e = kmalloc(sizeof(*e) + 8, GFP_ATOMIC); 1699 1701 if (e == NULL) 1700 1702 break; 1701 1703 ··· 1869 1857 struct client_resource *resource; 1870 1858 unsigned long index; 1871 1859 1872 - scoped_guard(spinlock_irq, &client->device->card->lock) 1860 + // NOTE: This can be without irq when we can guarantee that __fw_send_request() for local 1861 + // destination never runs in any type of IRQ context. 1862 + scoped_guard(spinlock_irq, &phy_receiver_list_lock) 1873 1863 list_del(&client->phy_receiver_link); 1874 1864 1875 1865 scoped_guard(mutex, &client->device->client_list_mutex)
+13 -14
drivers/firewire/core-device.c
··· 847 847 */ 848 848 849 849 #define MAX_RETRIES 10 850 - #define RETRY_DELAY (3 * HZ) 851 - #define INITIAL_DELAY (HZ / 2) 852 - #define SHUTDOWN_DELAY (2 * HZ) 850 + #define RETRY_DELAY secs_to_jiffies(3) 851 + #define INITIAL_DELAY msecs_to_jiffies(500) 852 + #define SHUTDOWN_DELAY secs_to_jiffies(2) 853 853 854 854 static void fw_device_shutdown(struct work_struct *work) 855 855 { 856 856 struct fw_device *device = from_work(device, work, work.work); 857 857 858 - if (time_before64(get_jiffies_64(), 859 - device->card->reset_jiffies + SHUTDOWN_DELAY) 858 + if (time_is_after_jiffies64(device->card->reset_jiffies + SHUTDOWN_DELAY) 860 859 && !list_empty(&device->card->link)) { 861 860 fw_schedule_device_work(device, SHUTDOWN_DELAY); 862 861 return; ··· 886 887 * bus manager work looks at this node. 887 888 */ 888 889 scoped_guard(spinlock_irqsave, &card->lock) 889 - device->node->data = NULL; 890 + fw_node_set_device(device->node, NULL); 890 891 891 892 fw_node_put(device->node); 892 893 kfree(device->config_rom); ··· 1006 1007 int ret; 1007 1008 1008 1009 /* 1009 - * All failure paths here set node->data to NULL, so that we 1010 + * All failure paths here call fw_node_set_device(node, NULL), so that we 1010 1011 * don't try to do device_for_each_child() on a kfree()'d 1011 1012 * device. 1012 1013 */ ··· 1050 1051 struct fw_node *obsolete_node = reused->node; 1051 1052 1052 1053 device->node = obsolete_node; 1053 - device->node->data = device; 1054 + fw_node_set_device(device->node, device); 1054 1055 reused->node = current_node; 1055 - reused->node->data = reused; 1056 + fw_node_set_device(reused->node, reused); 1056 1057 1057 1058 reused->max_speed = device->max_speed; 1058 1059 reused->node_id = current_node->node_id; ··· 1291 1292 * FW_NODE_UPDATED callbacks can update the node_id 1292 1293 * and generation for the device. 1293 1294 */ 1294 - node->data = device; 1295 + fw_node_set_device(node, device); 1295 1296 1296 1297 /* 1297 1298 * Many devices are slow to respond after bus resets, ··· 1306 1307 1307 1308 case FW_NODE_INITIATED_RESET: 1308 1309 case FW_NODE_LINK_ON: 1309 - device = node->data; 1310 + device = fw_node_get_device(node); 1310 1311 if (device == NULL) 1311 1312 goto create; 1312 1313 ··· 1323 1324 break; 1324 1325 1325 1326 case FW_NODE_UPDATED: 1326 - device = node->data; 1327 + device = fw_node_get_device(node); 1327 1328 if (device == NULL) 1328 1329 break; 1329 1330 ··· 1338 1339 1339 1340 case FW_NODE_DESTROYED: 1340 1341 case FW_NODE_LINK_OFF: 1341 - if (!node->data) 1342 + if (!fw_node_get_device(node)) 1342 1343 break; 1343 1344 1344 1345 /* ··· 1353 1354 * the device in shutdown state to have that code fail 1354 1355 * to create the device. 1355 1356 */ 1356 - device = node->data; 1357 + device = fw_node_get_device(node); 1357 1358 if (atomic_xchg(&device->state, 1358 1359 FW_DEVICE_GONE) == FW_DEVICE_RUNNING) { 1359 1360 device->workfn = fw_device_shutdown;
+46 -43
drivers/firewire/core-topology.c
··· 241 241 // If PHYs report different gap counts, set an invalid count which will force a gap 242 242 // count reconfiguration and a reset. 243 243 if (phy_packet_self_id_zero_get_gap_count(self_id_sequence[0]) != gap_count) 244 - gap_count = 0; 244 + gap_count = GAP_COUNT_MISMATCHED; 245 245 246 246 update_hop_count(node); 247 247 ··· 325 325 card->bm_retries = 0; 326 326 } 327 327 328 - /* Must be called with card->lock held */ 329 328 void fw_destroy_nodes(struct fw_card *card) 329 + __must_hold(&card->lock) 330 330 { 331 + lockdep_assert_held(&card->lock); 332 + 331 333 card->color++; 332 334 if (card->local_node != NULL) 333 335 for_each_fw_node(card, card->local_node, report_lost_node); ··· 437 435 } 438 436 } 439 437 440 - static void update_topology_map(struct fw_card *card, 441 - u32 *self_ids, int self_id_count) 438 + static void update_topology_map(__be32 *buffer, size_t buffer_size, int root_node_id, 439 + const u32 *self_ids, int self_id_count) 442 440 { 443 - int node_count = (card->root_node->node_id & 0x3f) + 1; 444 - __be32 *map = card->topology_map; 441 + __be32 *map = buffer; 442 + int node_count = (root_node_id & 0x3f) + 1; 443 + 444 + memset(map, 0, buffer_size); 445 445 446 446 *map++ = cpu_to_be32((self_id_count + 2) << 16); 447 - *map++ = cpu_to_be32(be32_to_cpu(card->topology_map[1]) + 1); 447 + *map++ = cpu_to_be32(be32_to_cpu(buffer[1]) + 1); 448 448 *map++ = cpu_to_be32((node_count << 16) | self_id_count); 449 449 450 450 while (self_id_count--) 451 451 *map++ = cpu_to_be32p(self_ids++); 452 452 453 - fw_compute_block_crc(card->topology_map); 453 + fw_compute_block_crc(buffer); 454 454 } 455 455 456 456 void fw_core_handle_bus_reset(struct fw_card *card, int node_id, int generation, ··· 462 458 463 459 trace_bus_reset_handle(card->index, generation, node_id, bm_abdicate, self_ids, self_id_count); 464 460 465 - guard(spinlock_irqsave)(&card->lock); 461 + scoped_guard(spinlock, &card->lock) { 462 + // If the selfID buffer is not the immediate successor of the 463 + // previously processed one, we cannot reliably compare the 464 + // old and new topologies. 465 + if (!is_next_generation(generation, card->generation) && card->local_node != NULL) { 466 + fw_destroy_nodes(card); 467 + card->bm_retries = 0; 468 + } 469 + card->broadcast_channel_allocated = card->broadcast_channel_auto_allocated; 470 + card->node_id = node_id; 471 + // Update node_id before generation to prevent anybody from using 472 + // a stale node_id together with a current generation. 473 + smp_wmb(); 474 + card->generation = generation; 475 + card->reset_jiffies = get_jiffies_64(); 476 + card->bm_node_id = 0xffff; 477 + card->bm_abdicate = bm_abdicate; 466 478 467 - /* 468 - * If the selfID buffer is not the immediate successor of the 469 - * previously processed one, we cannot reliably compare the 470 - * old and new topologies. 471 - */ 472 - if (!is_next_generation(generation, card->generation) && 473 - card->local_node != NULL) { 474 - fw_destroy_nodes(card); 475 - card->bm_retries = 0; 479 + local_node = build_tree(card, self_ids, self_id_count, generation); 480 + 481 + card->color++; 482 + 483 + if (local_node == NULL) { 484 + fw_err(card, "topology build failed\n"); 485 + // FIXME: We need to issue a bus reset in this case. 486 + } else if (card->local_node == NULL) { 487 + card->local_node = local_node; 488 + for_each_fw_node(card, local_node, report_found_node); 489 + } else { 490 + update_tree(card, local_node); 491 + } 476 492 } 477 493 478 - card->broadcast_channel_allocated = card->broadcast_channel_auto_allocated; 479 - card->node_id = node_id; 480 - /* 481 - * Update node_id before generation to prevent anybody from using 482 - * a stale node_id together with a current generation. 483 - */ 484 - smp_wmb(); 485 - card->generation = generation; 486 - card->reset_jiffies = get_jiffies_64(); 487 - card->bm_node_id = 0xffff; 488 - card->bm_abdicate = bm_abdicate; 489 494 fw_schedule_bm_work(card, 0); 490 495 491 - local_node = build_tree(card, self_ids, self_id_count, generation); 492 - 493 - update_topology_map(card, self_ids, self_id_count); 494 - 495 - card->color++; 496 - 497 - if (local_node == NULL) { 498 - fw_err(card, "topology build failed\n"); 499 - /* FIXME: We need to issue a bus reset in this case. */ 500 - } else if (card->local_node == NULL) { 501 - card->local_node = local_node; 502 - for_each_fw_node(card, local_node, report_found_node); 503 - } else { 504 - update_tree(card, local_node); 496 + // Just used by transaction layer. 497 + scoped_guard(spinlock, &card->topology_map.lock) { 498 + update_topology_map(card->topology_map.buffer, sizeof(card->topology_map.buffer), 499 + card->root_node->node_id, self_ids, self_id_count); 505 500 } 506 501 } 507 502 EXPORT_SYMBOL(fw_core_handle_bus_reset);
+84 -46
drivers/firewire/core-transaction.c
··· 49 49 { 50 50 struct fw_transaction *t = NULL, *iter; 51 51 52 - scoped_guard(spinlock_irqsave, &card->lock) { 53 - list_for_each_entry(iter, &card->transaction_list, link) { 52 + // NOTE: This can be without irqsave when we can guarantee that __fw_send_request() for 53 + // local destination never runs in any type of IRQ context. 54 + scoped_guard(spinlock_irqsave, &card->transactions.lock) { 55 + list_for_each_entry(iter, &card->transactions.list, link) { 54 56 if (iter == transaction) { 55 57 if (try_cancel_split_timeout(iter)) { 56 58 list_del_init(&iter->link); 57 - card->tlabel_mask &= ~(1ULL << iter->tlabel); 59 + card->transactions.tlabel_mask &= ~(1ULL << iter->tlabel); 58 60 t = iter; 59 61 } 60 62 break; ··· 119 117 struct fw_transaction *t = timer_container_of(t, timer, split_timeout_timer); 120 118 struct fw_card *card = t->card; 121 119 122 - scoped_guard(spinlock_irqsave, &card->lock) { 120 + scoped_guard(spinlock_irqsave, &card->transactions.lock) { 123 121 if (list_empty(&t->link)) 124 122 return; 125 123 list_del(&t->link); 126 - card->tlabel_mask &= ~(1ULL << t->tlabel); 124 + card->transactions.tlabel_mask &= ~(1ULL << t->tlabel); 127 125 } 128 126 129 127 if (!t->with_tstamp) { ··· 137 135 static void start_split_transaction_timeout(struct fw_transaction *t, 138 136 struct fw_card *card) 139 137 { 140 - guard(spinlock_irqsave)(&card->lock); 138 + unsigned long delta; 141 139 142 140 if (list_empty(&t->link) || WARN_ON(t->is_split_transaction)) 143 141 return; 144 142 145 143 t->is_split_transaction = true; 146 - mod_timer(&t->split_timeout_timer, 147 - jiffies + card->split_timeout_jiffies); 144 + 145 + // NOTE: This can be without irqsave when we can guarantee that __fw_send_request() for 146 + // local destination never runs in any type of IRQ context. 147 + scoped_guard(spinlock_irqsave, &card->split_timeout.lock) 148 + delta = card->split_timeout.jiffies; 149 + mod_timer(&t->split_timeout_timer, jiffies + delta); 148 150 } 149 151 150 152 static u32 compute_split_timeout_timestamp(struct fw_card *card, u32 request_timestamp); ··· 168 162 break; 169 163 case ACK_PENDING: 170 164 { 171 - t->split_timeout_cycle = 172 - compute_split_timeout_timestamp(card, packet->timestamp) & 0xffff; 165 + // NOTE: This can be without irqsave when we can guarantee that __fw_send_request() for 166 + // local destination never runs in any type of IRQ context. 167 + scoped_guard(spinlock_irqsave, &card->split_timeout.lock) { 168 + t->split_timeout_cycle = 169 + compute_split_timeout_timestamp(card, packet->timestamp) & 0xffff; 170 + } 173 171 start_split_transaction_timeout(t, card); 174 172 break; 175 173 } ··· 269 259 } 270 260 271 261 static int allocate_tlabel(struct fw_card *card) 262 + __must_hold(&card->transactions_lock) 272 263 { 273 264 int tlabel; 274 265 275 - tlabel = card->current_tlabel; 276 - while (card->tlabel_mask & (1ULL << tlabel)) { 266 + lockdep_assert_held(&card->transactions.lock); 267 + 268 + tlabel = card->transactions.current_tlabel; 269 + while (card->transactions.tlabel_mask & (1ULL << tlabel)) { 277 270 tlabel = (tlabel + 1) & 0x3f; 278 - if (tlabel == card->current_tlabel) 271 + if (tlabel == card->transactions.current_tlabel) 279 272 return -EBUSY; 280 273 } 281 274 282 - card->current_tlabel = (tlabel + 1) & 0x3f; 283 - card->tlabel_mask |= 1ULL << tlabel; 275 + card->transactions.current_tlabel = (tlabel + 1) & 0x3f; 276 + card->transactions.tlabel_mask |= 1ULL << tlabel; 284 277 285 278 return tlabel; 286 279 } ··· 344 331 void *payload, size_t length, union fw_transaction_callback callback, 345 332 bool with_tstamp, void *callback_data) 346 333 { 347 - unsigned long flags; 348 334 int tlabel; 349 335 350 336 /* ··· 351 339 * the list while holding the card spinlock. 352 340 */ 353 341 354 - spin_lock_irqsave(&card->lock, flags); 355 - 356 - tlabel = allocate_tlabel(card); 342 + // NOTE: This can be without irqsave when we can guarantee that __fw_send_request() for 343 + // local destination never runs in any type of IRQ context. 344 + scoped_guard(spinlock_irqsave, &card->transactions.lock) 345 + tlabel = allocate_tlabel(card); 357 346 if (tlabel < 0) { 358 - spin_unlock_irqrestore(&card->lock, flags); 359 347 if (!with_tstamp) { 360 348 callback.without_tstamp(card, RCODE_SEND_ERROR, NULL, 0, callback_data); 361 349 } else { ··· 380 368 t->callback = callback; 381 369 t->with_tstamp = with_tstamp; 382 370 t->callback_data = callback_data; 383 - 384 - fw_fill_request(&t->packet, tcode, t->tlabel, destination_id, card->node_id, generation, 385 - speed, offset, payload, length); 386 371 t->packet.callback = transmit_complete_callback; 387 372 388 - list_add_tail(&t->link, &card->transaction_list); 373 + // NOTE: This can be without irqsave when we can guarantee that __fw_send_request() for 374 + // local destination never runs in any type of IRQ context. 375 + scoped_guard(spinlock_irqsave, &card->lock) { 376 + // The node_id field of fw_card can be updated when handling SelfIDComplete. 377 + fw_fill_request(&t->packet, tcode, t->tlabel, destination_id, card->node_id, 378 + generation, speed, offset, payload, length); 379 + } 389 380 390 - spin_unlock_irqrestore(&card->lock, flags); 381 + // NOTE: This can be without irqsave when we can guarantee that __fw_send_request() for 382 + // local destination never runs in any type of IRQ context. 383 + scoped_guard(spinlock_irqsave, &card->transactions.lock) 384 + list_add_tail(&t->link, &card->transactions.list); 391 385 386 + // Safe with no lock, since the index field of fw_card is immutable once assigned. 392 387 trace_async_request_outbound_initiate((uintptr_t)t, card->index, generation, speed, 393 388 t->packet.header, payload, 394 389 tcode_is_read_request(tcode) ? 0 : length / 4); ··· 477 458 void fw_send_phy_config(struct fw_card *card, 478 459 int node_id, int generation, int gap_count) 479 460 { 480 - long timeout = DIV_ROUND_UP(HZ, 10); 461 + long timeout = msecs_to_jiffies(100); 481 462 u32 data = 0; 482 463 483 464 phy_packet_set_packet_identifier(&data, PHY_PACKET_PACKET_IDENTIFIER_PHY_CONFIG); ··· 798 779 799 780 static u32 compute_split_timeout_timestamp(struct fw_card *card, 800 781 u32 request_timestamp) 782 + __must_hold(&card->split_timeout.lock) 801 783 { 802 784 unsigned int cycles; 803 785 u32 timestamp; 804 786 805 - cycles = card->split_timeout_cycles; 787 + lockdep_assert_held(&card->split_timeout.lock); 788 + 789 + cycles = card->split_timeout.cycles; 806 790 cycles += request_timestamp & 0x1fff; 807 791 808 792 timestamp = request_timestamp & ~0x1fff; ··· 856 834 return NULL; 857 835 kref_init(&request->kref); 858 836 837 + // NOTE: This can be without irqsave when we can guarantee that __fw_send_request() for 838 + // local destination never runs in any type of IRQ context. 839 + scoped_guard(spinlock_irqsave, &card->split_timeout.lock) 840 + request->response.timestamp = compute_split_timeout_timestamp(card, p->timestamp); 841 + 859 842 request->response.speed = p->speed; 860 - request->response.timestamp = 861 - compute_split_timeout_timestamp(card, p->timestamp); 862 843 request->response.generation = p->generation; 863 844 request->response.ack = 0; 864 845 request->response.callback = free_response_callback; ··· 1136 1111 break; 1137 1112 } 1138 1113 1139 - scoped_guard(spinlock_irqsave, &card->lock) { 1140 - list_for_each_entry(iter, &card->transaction_list, link) { 1114 + // NOTE: This can be without irqsave when we can guarantee that __fw_send_request() for 1115 + // local destination never runs in any type of IRQ context. 1116 + scoped_guard(spinlock_irqsave, &card->transactions.lock) { 1117 + list_for_each_entry(iter, &card->transactions.list, link) { 1141 1118 if (iter->node_id == source && iter->tlabel == tlabel) { 1142 1119 if (try_cancel_split_timeout(iter)) { 1143 1120 list_del_init(&iter->link); 1144 - card->tlabel_mask &= ~(1ULL << iter->tlabel); 1121 + card->transactions.tlabel_mask &= ~(1ULL << iter->tlabel); 1145 1122 t = iter; 1146 1123 } 1147 1124 break; ··· 1223 1196 } 1224 1197 1225 1198 start = (offset - topology_map_region.start) / 4; 1226 - memcpy(payload, &card->topology_map[start], length); 1199 + 1200 + // NOTE: This can be without irqsave when we can guarantee that fw_send_request() for local 1201 + // destination never runs in any type of IRQ context. 1202 + scoped_guard(spinlock_irqsave, &card->topology_map.lock) 1203 + memcpy(payload, &card->topology_map.buffer[start], length); 1227 1204 1228 1205 fw_send_response(card, request, RCODE_COMPLETE); 1229 1206 } ··· 1242 1211 .end = CSR_REGISTER_BASE | CSR_CONFIG_ROM, }; 1243 1212 1244 1213 static void update_split_timeout(struct fw_card *card) 1214 + __must_hold(&card->split_timeout.lock) 1245 1215 { 1246 1216 unsigned int cycles; 1247 1217 1248 - cycles = card->split_timeout_hi * 8000 + (card->split_timeout_lo >> 19); 1218 + cycles = card->split_timeout.hi * 8000 + (card->split_timeout.lo >> 19); 1249 1219 1250 1220 /* minimum per IEEE 1394, maximum which doesn't overflow OHCI */ 1251 1221 cycles = clamp(cycles, 800u, 3u * 8000u); 1252 1222 1253 - card->split_timeout_cycles = cycles; 1254 - card->split_timeout_jiffies = DIV_ROUND_UP(cycles * HZ, 8000); 1223 + card->split_timeout.cycles = cycles; 1224 + card->split_timeout.jiffies = isoc_cycles_to_jiffies(cycles); 1255 1225 } 1256 1226 1257 1227 static void handle_registers(struct fw_card *card, struct fw_request *request, ··· 1302 1270 1303 1271 case CSR_SPLIT_TIMEOUT_HI: 1304 1272 if (tcode == TCODE_READ_QUADLET_REQUEST) { 1305 - *data = cpu_to_be32(card->split_timeout_hi); 1273 + *data = cpu_to_be32(card->split_timeout.hi); 1306 1274 } else if (tcode == TCODE_WRITE_QUADLET_REQUEST) { 1307 - guard(spinlock_irqsave)(&card->lock); 1308 - 1309 - card->split_timeout_hi = be32_to_cpu(*data) & 7; 1310 - update_split_timeout(card); 1275 + // NOTE: This can be without irqsave when we can guarantee that 1276 + // __fw_send_request() for local destination never runs in any type of IRQ 1277 + // context. 1278 + scoped_guard(spinlock_irqsave, &card->split_timeout.lock) { 1279 + card->split_timeout.hi = be32_to_cpu(*data) & 7; 1280 + update_split_timeout(card); 1281 + } 1311 1282 } else { 1312 1283 rcode = RCODE_TYPE_ERROR; 1313 1284 } ··· 1318 1283 1319 1284 case CSR_SPLIT_TIMEOUT_LO: 1320 1285 if (tcode == TCODE_READ_QUADLET_REQUEST) { 1321 - *data = cpu_to_be32(card->split_timeout_lo); 1286 + *data = cpu_to_be32(card->split_timeout.lo); 1322 1287 } else if (tcode == TCODE_WRITE_QUADLET_REQUEST) { 1323 - guard(spinlock_irqsave)(&card->lock); 1324 - 1325 - card->split_timeout_lo = be32_to_cpu(*data) & 0xfff80000; 1326 - update_split_timeout(card); 1288 + // NOTE: This can be without irqsave when we can guarantee that 1289 + // __fw_send_request() for local destination never runs in any type of IRQ 1290 + // context. 1291 + scoped_guard(spinlock_irqsave, &card->split_timeout.lock) { 1292 + card->split_timeout.lo = be32_to_cpu(*data) & 0xfff80000; 1293 + update_split_timeout(card); 1294 + } 1327 1295 } else { 1328 1296 rcode = RCODE_TYPE_ERROR; 1329 1297 }
+20 -2
drivers/firewire/core.h
··· 27 27 28 28 /* -card */ 29 29 30 + // This is the arbitrary value we use to indicate a mismatched gap count. 31 + #define GAP_COUNT_MISMATCHED 0 32 + 33 + #define isoc_cycles_to_jiffies(cycles) usecs_to_jiffies((u32)div_u64((u64)cycles * USEC_PER_SEC, 8000)) 34 + 30 35 extern __printf(2, 3) 31 36 void fw_err(const struct fw_card *card, const char *fmt, ...); 32 37 extern __printf(2, 3) ··· 172 167 173 168 /* -topology */ 174 169 170 + // The initial value of BUS_MANAGER_ID register, to express nothing registered. 171 + #define BUS_MANAGER_ID_NOT_REGISTERED 0x3f 172 + 175 173 enum { 176 174 FW_NODE_CREATED, 177 175 FW_NODE_UPDATED, ··· 202 194 /* For serializing node topology into a list. */ 203 195 struct list_head link; 204 196 205 - /* Upper layer specific data. */ 206 - void *data; 197 + // The device when already associated, else NULL. 198 + struct fw_device *device; 207 199 208 200 struct fw_node *ports[] __counted_by(port_count); 209 201 }; ··· 225 217 static inline void fw_node_put(struct fw_node *node) 226 218 { 227 219 kref_put(&node->kref, release_node); 220 + } 221 + 222 + static inline struct fw_device *fw_node_get_device(struct fw_node *node) 223 + { 224 + return node->device; 225 + } 226 + 227 + static inline void fw_node_set_device(struct fw_node *node, struct fw_device *device) 228 + { 229 + node->device = device; 228 230 } 229 231 230 232 void fw_core_handle_bus_reset(struct fw_card *card, int node_id,
+47 -269
drivers/firewire/ohci.c
··· 228 228 229 229 __le32 *self_id; 230 230 dma_addr_t self_id_bus; 231 - struct work_struct bus_reset_work; 232 231 233 232 u32 self_id_buffer[512]; 234 233 }; 235 - 236 - static struct workqueue_struct *selfid_workqueue; 237 234 238 235 static inline struct fw_ohci *fw_ohci(struct fw_card *card) 239 236 { ··· 390 393 ", IR wake unreliable = " __stringify(QUIRK_IR_WAKE) 391 394 ")"); 392 395 393 - #define OHCI_PARAM_DEBUG_AT_AR 1 394 - #define OHCI_PARAM_DEBUG_SELFIDS 2 395 - #define OHCI_PARAM_DEBUG_IRQS 4 396 - 397 - static int param_debug; 398 - module_param_named(debug, param_debug, int, 0644); 399 - MODULE_PARM_DESC(debug, "Verbose logging, deprecated in v6.11 kernel or later. (default = 0" 400 - ", AT/AR events = " __stringify(OHCI_PARAM_DEBUG_AT_AR) 401 - ", self-IDs = " __stringify(OHCI_PARAM_DEBUG_SELFIDS) 402 - ", IRQs = " __stringify(OHCI_PARAM_DEBUG_IRQS) 403 - ", or a combination, or all = -1)"); 404 - 405 396 static bool param_remote_dma; 406 397 module_param_named(remote_dma, param_remote_dma, bool, 0444); 407 398 MODULE_PARM_DESC(remote_dma, "Enable unfiltered remote DMA (default = N)"); 408 - 409 - static void log_irqs(struct fw_ohci *ohci, u32 evt) 410 - { 411 - if (likely(!(param_debug & OHCI_PARAM_DEBUG_IRQS))) 412 - return; 413 - 414 - ohci_notice(ohci, "IRQ %08x%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s\n", evt, 415 - evt & OHCI1394_selfIDComplete ? " selfID" : "", 416 - evt & OHCI1394_RQPkt ? " AR_req" : "", 417 - evt & OHCI1394_RSPkt ? " AR_resp" : "", 418 - evt & OHCI1394_reqTxComplete ? " AT_req" : "", 419 - evt & OHCI1394_respTxComplete ? " AT_resp" : "", 420 - evt & OHCI1394_isochRx ? " IR" : "", 421 - evt & OHCI1394_isochTx ? " IT" : "", 422 - evt & OHCI1394_postedWriteErr ? " postedWriteErr" : "", 423 - evt & OHCI1394_cycleTooLong ? " cycleTooLong" : "", 424 - evt & OHCI1394_cycle64Seconds ? " cycle64Seconds" : "", 425 - evt & OHCI1394_cycleInconsistent ? " cycleInconsistent" : "", 426 - evt & OHCI1394_regAccessFail ? " regAccessFail" : "", 427 - evt & OHCI1394_unrecoverableError ? " unrecoverableError" : "", 428 - evt & OHCI1394_busReset ? " busReset" : "", 429 - evt & ~(OHCI1394_selfIDComplete | OHCI1394_RQPkt | 430 - OHCI1394_RSPkt | OHCI1394_reqTxComplete | 431 - OHCI1394_respTxComplete | OHCI1394_isochRx | 432 - OHCI1394_isochTx | OHCI1394_postedWriteErr | 433 - OHCI1394_cycleTooLong | OHCI1394_cycle64Seconds | 434 - OHCI1394_cycleInconsistent | 435 - OHCI1394_regAccessFail | OHCI1394_busReset) 436 - ? " ?" : ""); 437 - } 438 - 439 - static void log_selfids(struct fw_ohci *ohci, int generation, int self_id_count) 440 - { 441 - static const char *const speed[] = { 442 - [0] = "S100", [1] = "S200", [2] = "S400", [3] = "beta", 443 - }; 444 - static const char *const power[] = { 445 - [0] = "+0W", [1] = "+15W", [2] = "+30W", [3] = "+45W", 446 - [4] = "-3W", [5] = " ?W", [6] = "-3..-6W", [7] = "-3..-10W", 447 - }; 448 - static const char port[] = { 449 - [PHY_PACKET_SELF_ID_PORT_STATUS_NONE] = '.', 450 - [PHY_PACKET_SELF_ID_PORT_STATUS_NCONN] = '-', 451 - [PHY_PACKET_SELF_ID_PORT_STATUS_PARENT] = 'p', 452 - [PHY_PACKET_SELF_ID_PORT_STATUS_CHILD] = 'c', 453 - }; 454 - struct self_id_sequence_enumerator enumerator = { 455 - .cursor = ohci->self_id_buffer, 456 - .quadlet_count = self_id_count, 457 - }; 458 - 459 - if (likely(!(param_debug & OHCI_PARAM_DEBUG_SELFIDS))) 460 - return; 461 - 462 - ohci_notice(ohci, "%d selfIDs, generation %d, local node ID %04x\n", 463 - self_id_count, generation, ohci->node_id); 464 - 465 - while (enumerator.quadlet_count > 0) { 466 - unsigned int quadlet_count; 467 - unsigned int port_index; 468 - const u32 *s; 469 - int i; 470 - 471 - s = self_id_sequence_enumerator_next(&enumerator, &quadlet_count); 472 - if (IS_ERR(s)) 473 - break; 474 - 475 - ohci_notice(ohci, 476 - "selfID 0: %08x, phy %d [%c%c%c] %s gc=%d %s %s%s%s\n", 477 - *s, 478 - phy_packet_self_id_get_phy_id(*s), 479 - port[self_id_sequence_get_port_status(s, quadlet_count, 0)], 480 - port[self_id_sequence_get_port_status(s, quadlet_count, 1)], 481 - port[self_id_sequence_get_port_status(s, quadlet_count, 2)], 482 - speed[*s >> 14 & 3], *s >> 16 & 63, 483 - power[*s >> 8 & 7], *s >> 22 & 1 ? "L" : "", 484 - *s >> 11 & 1 ? "c" : "", *s & 2 ? "i" : ""); 485 - 486 - port_index = 3; 487 - for (i = 1; i < quadlet_count; ++i) { 488 - ohci_notice(ohci, 489 - "selfID n: %08x, phy %d [%c%c%c%c%c%c%c%c]\n", 490 - s[i], 491 - phy_packet_self_id_get_phy_id(s[i]), 492 - port[self_id_sequence_get_port_status(s, quadlet_count, port_index)], 493 - port[self_id_sequence_get_port_status(s, quadlet_count, port_index + 1)], 494 - port[self_id_sequence_get_port_status(s, quadlet_count, port_index + 2)], 495 - port[self_id_sequence_get_port_status(s, quadlet_count, port_index + 3)], 496 - port[self_id_sequence_get_port_status(s, quadlet_count, port_index + 4)], 497 - port[self_id_sequence_get_port_status(s, quadlet_count, port_index + 5)], 498 - port[self_id_sequence_get_port_status(s, quadlet_count, port_index + 6)], 499 - port[self_id_sequence_get_port_status(s, quadlet_count, port_index + 7)] 500 - ); 501 - 502 - port_index += 8; 503 - } 504 - } 505 - } 506 - 507 - static const char *evts[] = { 508 - [0x00] = "evt_no_status", [0x01] = "-reserved-", 509 - [0x02] = "evt_long_packet", [0x03] = "evt_missing_ack", 510 - [0x04] = "evt_underrun", [0x05] = "evt_overrun", 511 - [0x06] = "evt_descriptor_read", [0x07] = "evt_data_read", 512 - [0x08] = "evt_data_write", [0x09] = "evt_bus_reset", 513 - [0x0a] = "evt_timeout", [0x0b] = "evt_tcode_err", 514 - [0x0c] = "-reserved-", [0x0d] = "-reserved-", 515 - [0x0e] = "evt_unknown", [0x0f] = "evt_flushed", 516 - [0x10] = "-reserved-", [0x11] = "ack_complete", 517 - [0x12] = "ack_pending ", [0x13] = "-reserved-", 518 - [0x14] = "ack_busy_X", [0x15] = "ack_busy_A", 519 - [0x16] = "ack_busy_B", [0x17] = "-reserved-", 520 - [0x18] = "-reserved-", [0x19] = "-reserved-", 521 - [0x1a] = "-reserved-", [0x1b] = "ack_tardy", 522 - [0x1c] = "-reserved-", [0x1d] = "ack_data_error", 523 - [0x1e] = "ack_type_error", [0x1f] = "-reserved-", 524 - [0x20] = "pending/cancelled", 525 - }; 526 - 527 - static void log_ar_at_event(struct fw_ohci *ohci, 528 - char dir, int speed, u32 *header, int evt) 529 - { 530 - static const char *const tcodes[] = { 531 - [TCODE_WRITE_QUADLET_REQUEST] = "QW req", 532 - [TCODE_WRITE_BLOCK_REQUEST] = "BW req", 533 - [TCODE_WRITE_RESPONSE] = "W resp", 534 - [0x3] = "-reserved-", 535 - [TCODE_READ_QUADLET_REQUEST] = "QR req", 536 - [TCODE_READ_BLOCK_REQUEST] = "BR req", 537 - [TCODE_READ_QUADLET_RESPONSE] = "QR resp", 538 - [TCODE_READ_BLOCK_RESPONSE] = "BR resp", 539 - [TCODE_CYCLE_START] = "cycle start", 540 - [TCODE_LOCK_REQUEST] = "Lk req", 541 - [TCODE_STREAM_DATA] = "async stream packet", 542 - [TCODE_LOCK_RESPONSE] = "Lk resp", 543 - [0xc] = "-reserved-", 544 - [0xd] = "-reserved-", 545 - [TCODE_LINK_INTERNAL] = "link internal", 546 - [0xf] = "-reserved-", 547 - }; 548 - int tcode = async_header_get_tcode(header); 549 - char specific[12]; 550 - 551 - if (likely(!(param_debug & OHCI_PARAM_DEBUG_AT_AR))) 552 - return; 553 - 554 - if (unlikely(evt >= ARRAY_SIZE(evts))) 555 - evt = 0x1f; 556 - 557 - if (evt == OHCI1394_evt_bus_reset) { 558 - ohci_notice(ohci, "A%c evt_bus_reset, generation %d\n", 559 - dir, (header[2] >> 16) & 0xff); 560 - return; 561 - } 562 - 563 - switch (tcode) { 564 - case TCODE_WRITE_QUADLET_REQUEST: 565 - case TCODE_READ_QUADLET_RESPONSE: 566 - case TCODE_CYCLE_START: 567 - snprintf(specific, sizeof(specific), " = %08x", 568 - be32_to_cpu((__force __be32)header[3])); 569 - break; 570 - case TCODE_WRITE_BLOCK_REQUEST: 571 - case TCODE_READ_BLOCK_REQUEST: 572 - case TCODE_READ_BLOCK_RESPONSE: 573 - case TCODE_LOCK_REQUEST: 574 - case TCODE_LOCK_RESPONSE: 575 - snprintf(specific, sizeof(specific), " %x,%x", 576 - async_header_get_data_length(header), 577 - async_header_get_extended_tcode(header)); 578 - break; 579 - default: 580 - specific[0] = '\0'; 581 - } 582 - 583 - switch (tcode) { 584 - case TCODE_STREAM_DATA: 585 - ohci_notice(ohci, "A%c %s, %s\n", 586 - dir, evts[evt], tcodes[tcode]); 587 - break; 588 - case TCODE_LINK_INTERNAL: 589 - ohci_notice(ohci, "A%c %s, PHY %08x %08x\n", 590 - dir, evts[evt], header[1], header[2]); 591 - break; 592 - case TCODE_WRITE_QUADLET_REQUEST: 593 - case TCODE_WRITE_BLOCK_REQUEST: 594 - case TCODE_READ_QUADLET_REQUEST: 595 - case TCODE_READ_BLOCK_REQUEST: 596 - case TCODE_LOCK_REQUEST: 597 - ohci_notice(ohci, 598 - "A%c spd %x tl %02x, %04x -> %04x, %s, %s, %012llx%s\n", 599 - dir, speed, async_header_get_tlabel(header), 600 - async_header_get_source(header), async_header_get_destination(header), 601 - evts[evt], tcodes[tcode], async_header_get_offset(header), specific); 602 - break; 603 - default: 604 - ohci_notice(ohci, 605 - "A%c spd %x tl %02x, %04x -> %04x, %s, %s%s\n", 606 - dir, speed, async_header_get_tlabel(header), 607 - async_header_get_source(header), async_header_get_destination(header), 608 - evts[evt], tcodes[tcode], specific); 609 - } 610 - } 611 399 612 400 static inline void reg_write(const struct fw_ohci *ohci, int offset, u32 data) 613 401 { ··· 739 957 p.timestamp = status & 0xffff; 740 958 p.generation = ohci->request_generation; 741 959 742 - log_ar_at_event(ohci, 'R', p.speed, p.header, evt); 743 - 744 960 /* 745 961 * Several controllers, notably from NEC and VIA, forget to 746 962 * write ack_complete status at PHY packet reception. ··· 757 977 * 758 978 * Alas some chips sometimes emit bus reset packets with a 759 979 * wrong generation. We set the correct generation for these 760 - * at a slightly incorrect time (in bus_reset_work). 980 + * at a slightly incorrect time (in handle_selfid_complete_event). 761 981 */ 762 982 if (evt == OHCI1394_evt_bus_reset) { 763 983 if (!(ohci->quirks & QUIRK_RESET_PACKET)) ··· 1346 1566 evt = le16_to_cpu(last->transfer_status) & 0x1f; 1347 1567 packet->timestamp = le16_to_cpu(last->res_count); 1348 1568 1349 - log_ar_at_event(ohci, 'T', packet->speed, packet->header, evt); 1350 - 1351 1569 switch (evt) { 1352 1570 case OHCI1394_evt_timeout: 1353 1571 /* Async response transmit timed out. */ ··· 1550 1772 static void detect_dead_context(struct fw_ohci *ohci, 1551 1773 const char *name, unsigned int regs) 1552 1774 { 1775 + static const char *const evts[] = { 1776 + [0x00] = "evt_no_status", [0x01] = "-reserved-", 1777 + [0x02] = "evt_long_packet", [0x03] = "evt_missing_ack", 1778 + [0x04] = "evt_underrun", [0x05] = "evt_overrun", 1779 + [0x06] = "evt_descriptor_read", [0x07] = "evt_data_read", 1780 + [0x08] = "evt_data_write", [0x09] = "evt_bus_reset", 1781 + [0x0a] = "evt_timeout", [0x0b] = "evt_tcode_err", 1782 + [0x0c] = "-reserved-", [0x0d] = "-reserved-", 1783 + [0x0e] = "evt_unknown", [0x0f] = "evt_flushed", 1784 + [0x10] = "-reserved-", [0x11] = "ack_complete", 1785 + [0x12] = "ack_pending ", [0x13] = "-reserved-", 1786 + [0x14] = "ack_busy_X", [0x15] = "ack_busy_A", 1787 + [0x16] = "ack_busy_B", [0x17] = "-reserved-", 1788 + [0x18] = "-reserved-", [0x19] = "-reserved-", 1789 + [0x1a] = "-reserved-", [0x1b] = "ack_tardy", 1790 + [0x1c] = "-reserved-", [0x1d] = "ack_data_error", 1791 + [0x1e] = "ack_type_error", [0x1f] = "-reserved-", 1792 + [0x20] = "pending/cancelled", 1793 + }; 1553 1794 u32 ctl; 1554 1795 1555 1796 ctl = reg_read(ohci, CONTROL_SET(regs)); ··· 1827 2030 return self_id_count; 1828 2031 } 1829 2032 1830 - static void bus_reset_work(struct work_struct *work) 2033 + static irqreturn_t handle_selfid_complete_event(int irq, void *data) 1831 2034 { 1832 - struct fw_ohci *ohci = from_work(ohci, work, bus_reset_work); 2035 + struct fw_ohci *ohci = data; 1833 2036 int self_id_count, generation, new_generation, i, j; 1834 2037 u32 reg, quadlet; 1835 2038 void *free_rom = NULL; ··· 1840 2043 if (!(reg & OHCI1394_NodeID_idValid)) { 1841 2044 ohci_notice(ohci, 1842 2045 "node ID not valid, new bus reset in progress\n"); 1843 - return; 2046 + goto end; 1844 2047 } 1845 2048 if ((reg & OHCI1394_NodeID_nodeNumber) == 63) { 1846 2049 ohci_notice(ohci, "malconfigured bus\n"); 1847 - return; 2050 + goto end; 1848 2051 } 1849 2052 ohci->node_id = reg & (OHCI1394_NodeID_busNumber | 1850 2053 OHCI1394_NodeID_nodeNumber); ··· 1858 2061 reg = reg_read(ohci, OHCI1394_SelfIDCount); 1859 2062 if (ohci1394_self_id_count_is_error(reg)) { 1860 2063 ohci_notice(ohci, "self ID receive error\n"); 1861 - return; 2064 + goto end; 1862 2065 } 2066 + 2067 + trace_self_id_complete(ohci->card.index, reg, ohci->self_id, has_be_header_quirk(ohci)); 2068 + 1863 2069 /* 1864 2070 * The count in the SelfIDCount register is the number of 1865 2071 * bytes in the self ID receive buffer. Since we also receive ··· 1873 2073 1874 2074 if (self_id_count > 252) { 1875 2075 ohci_notice(ohci, "bad selfIDSize (%08x)\n", reg); 1876 - return; 2076 + goto end; 1877 2077 } 1878 2078 1879 2079 quadlet = cond_le32_to_cpu(ohci->self_id[0], has_be_header_quirk(ohci)); ··· 1900 2100 1901 2101 ohci_notice(ohci, "bad self ID %d/%d (%08x != ~%08x)\n", 1902 2102 j, self_id_count, id, id2); 1903 - return; 2103 + goto end; 1904 2104 } 1905 2105 ohci->self_id_buffer[j] = id; 1906 2106 } ··· 1910 2110 if (self_id_count < 0) { 1911 2111 ohci_notice(ohci, 1912 2112 "could not construct local self ID\n"); 1913 - return; 2113 + goto end; 1914 2114 } 1915 2115 } 1916 2116 1917 2117 if (self_id_count == 0) { 1918 2118 ohci_notice(ohci, "no self IDs\n"); 1919 - return; 2119 + goto end; 1920 2120 } 1921 2121 rmb(); 1922 2122 ··· 1938 2138 new_generation = ohci1394_self_id_count_get_generation(reg); 1939 2139 if (new_generation != generation) { 1940 2140 ohci_notice(ohci, "new bus reset, discarding self ids\n"); 1941 - return; 2141 + goto end; 1942 2142 } 1943 2143 1944 2144 // FIXME: Document how the locking works. ··· 1995 2195 if (free_rom) 1996 2196 dmam_free_coherent(ohci->card.device, CONFIG_ROM_SIZE, free_rom, free_rom_bus); 1997 2197 1998 - log_selfids(ohci, generation, self_id_count); 1999 - 2000 2198 fw_core_handle_bus_reset(&ohci->card, ohci->node_id, generation, 2001 2199 self_id_count, ohci->self_id_buffer, 2002 2200 ohci->csr_state_setclear_abdicate); 2003 2201 ohci->csr_state_setclear_abdicate = false; 2202 + end: 2203 + return IRQ_HANDLED; 2004 2204 } 2005 2205 2006 2206 static irqreturn_t irq_handler(int irq, void *data) ··· 2014 2214 if (!event || !~event) 2015 2215 return IRQ_NONE; 2016 2216 2017 - if (unlikely(param_debug > 0)) { 2018 - dev_notice_ratelimited(ohci->card.device, 2019 - "The debug parameter is superseded by tracepoints events, and deprecated."); 2020 - } 2021 - 2022 2217 /* 2023 2218 * busReset and postedWriteErr events must not be cleared yet 2024 2219 * (OHCI 1.1 clauses 7.2.3.2 and 13.2.8.1) ··· 2021 2226 reg_write(ohci, OHCI1394_IntEventClear, 2022 2227 event & ~(OHCI1394_busReset | OHCI1394_postedWriteErr)); 2023 2228 trace_irqs(ohci->card.index, event); 2024 - log_irqs(ohci, event); 2025 - // The flag is masked again at bus_reset_work() scheduled by selfID event. 2229 + 2230 + // The flag is masked again at handle_selfid_complete_event() scheduled by selfID event. 2026 2231 if (event & OHCI1394_busReset) 2027 2232 reg_write(ohci, OHCI1394_IntMaskClear, OHCI1394_busReset); 2028 - 2029 - if (event & OHCI1394_selfIDComplete) { 2030 - if (trace_self_id_complete_enabled()) { 2031 - u32 reg = reg_read(ohci, OHCI1394_SelfIDCount); 2032 - 2033 - trace_self_id_complete(ohci->card.index, reg, ohci->self_id, 2034 - has_be_header_quirk(ohci)); 2035 - } 2036 - queue_work(selfid_workqueue, &ohci->bus_reset_work); 2037 - } 2038 2233 2039 2234 if (event & OHCI1394_RQPkt) 2040 2235 queue_work(ohci->card.async_wq, &ohci->ar_request_ctx.work); ··· 2096 2311 } else 2097 2312 flush_writes(ohci); 2098 2313 2099 - return IRQ_HANDLED; 2314 + if (event & OHCI1394_selfIDComplete) 2315 + return IRQ_WAKE_THREAD; 2316 + else 2317 + return IRQ_HANDLED; 2100 2318 } 2101 2319 2102 2320 static int software_reset(struct fw_ohci *ohci) ··· 2412 2624 * then set up the real values for the two registers. 2413 2625 * 2414 2626 * We use ohci->lock to avoid racing with the code that sets 2415 - * ohci->next_config_rom to NULL (see bus_reset_work). 2627 + * ohci->next_config_rom to NULL (see handle_selfid_complete_event). 2416 2628 */ 2417 2629 2418 2630 next_config_rom = dmam_alloc_coherent(ohci->card.device, CONFIG_ROM_SIZE, ··· 2493 2705 dma_unmap_single(ohci->card.device, packet->payload_bus, 2494 2706 packet->payload_length, DMA_TO_DEVICE); 2495 2707 2496 - log_ar_at_event(ohci, 'T', packet->speed, packet->header, 0x20); 2497 2708 driver_data->packet = NULL; 2498 2709 packet->ack = RCODE_CANCELLED; 2499 2710 ··· 3482 3695 u32 bus_options, max_receive, link_speed, version; 3483 3696 u64 guid; 3484 3697 int i, flags, irq, err; 3485 - size_t size; 3486 3698 3487 3699 if (dev->vendor == PCI_VENDOR_ID_PINNACLE_SYSTEMS) { 3488 3700 dev_err(&dev->dev, "Pinnacle MovieBoard is not yet supported\n"); ··· 3507 3721 3508 3722 spin_lock_init(&ohci->lock); 3509 3723 mutex_init(&ohci->phy_reg_mutex); 3510 - 3511 - INIT_WORK(&ohci->bus_reset_work, bus_reset_work); 3512 3724 3513 3725 if (!(pci_resource_flags(dev, 0) & IORESOURCE_MEM) || 3514 3726 pci_resource_len(dev, 0) < OHCI1394_REGISTER_SIZE) { ··· 3575 3791 reg_write(ohci, OHCI1394_IsoRecvIntMaskClear, ~0); 3576 3792 ohci->ir_context_mask = ohci->ir_context_support; 3577 3793 ohci->n_ir = hweight32(ohci->ir_context_mask); 3578 - size = sizeof(struct iso_context) * ohci->n_ir; 3579 - ohci->ir_context_list = devm_kzalloc(&dev->dev, size, GFP_KERNEL); 3794 + ohci->ir_context_list = devm_kcalloc(&dev->dev, ohci->n_ir, sizeof(struct iso_context), GFP_KERNEL); 3580 3795 if (!ohci->ir_context_list) 3581 3796 return -ENOMEM; 3582 3797 ··· 3589 3806 reg_write(ohci, OHCI1394_IsoXmitIntMaskClear, ~0); 3590 3807 ohci->it_context_mask = ohci->it_context_support; 3591 3808 ohci->n_it = hweight32(ohci->it_context_mask); 3592 - size = sizeof(struct iso_context) * ohci->n_it; 3593 - ohci->it_context_list = devm_kzalloc(&dev->dev, size, GFP_KERNEL); 3809 + ohci->it_context_list = devm_kcalloc(&dev->dev, ohci->n_it, sizeof(struct iso_context), GFP_KERNEL); 3594 3810 if (!ohci->it_context_list) 3595 3811 return -ENOMEM; 3596 3812 ··· 3614 3832 goto fail_msi; 3615 3833 } 3616 3834 3617 - err = request_threaded_irq(irq, irq_handler, NULL, 3835 + // IRQF_ONESHOT is not applied so that any events are handled in the hardIRQ handler during 3836 + // invoking the threaded IRQ handler for SelfIDComplete event. 3837 + err = request_threaded_irq(irq, irq_handler, handle_selfid_complete_event, 3618 3838 pci_dev_msi_enabled(dev) ? 0 : IRQF_SHARED, ohci_driver_name, 3619 3839 ohci); 3620 3840 if (err < 0) { ··· 3660 3876 reg_write(ohci, OHCI1394_IntMaskClear, ~0); 3661 3877 flush_writes(ohci); 3662 3878 } 3663 - cancel_work_sync(&ohci->bus_reset_work); 3664 3879 fw_core_remove_card(&ohci->card); 3665 3880 3666 3881 /* ··· 3732 3949 3733 3950 static int __init fw_ohci_init(void) 3734 3951 { 3735 - selfid_workqueue = alloc_workqueue(KBUILD_MODNAME, WQ_MEM_RECLAIM, 0); 3736 - if (!selfid_workqueue) 3737 - return -ENOMEM; 3738 - 3739 3952 return pci_register_driver(&fw_ohci_pci_driver); 3740 3953 } 3741 3954 3742 3955 static void __exit fw_ohci_cleanup(void) 3743 3956 { 3744 3957 pci_unregister_driver(&fw_ohci_pci_driver); 3745 - destroy_workqueue(selfid_workqueue); 3746 3958 } 3747 3959 3748 3960 module_init(fw_ohci_init);
+21 -12
include/linux/firewire.h
··· 88 88 89 89 int node_id; 90 90 int generation; 91 - int current_tlabel; 92 - u64 tlabel_mask; 93 - struct list_head transaction_list; 94 91 u64 reset_jiffies; 95 92 96 - u32 split_timeout_hi; 97 - u32 split_timeout_lo; 98 - unsigned int split_timeout_cycles; 99 - unsigned int split_timeout_jiffies; 93 + struct { 94 + int current_tlabel; 95 + u64 tlabel_mask; 96 + struct list_head list; 97 + spinlock_t lock; 98 + } transactions; 99 + 100 + struct { 101 + u32 hi; 102 + u32 lo; 103 + unsigned int cycles; 104 + unsigned int jiffies; 105 + spinlock_t lock; 106 + } split_timeout; 100 107 101 108 unsigned long long guid; 102 109 unsigned max_receive; 103 110 int link_speed; 104 111 int config_rom_generation; 105 112 106 - spinlock_t lock; /* Take this lock when handling the lists in 107 - * this struct. */ 113 + spinlock_t lock; 114 + 108 115 struct fw_node *local_node; 109 116 struct fw_node *root_node; 110 117 struct fw_node *irm_node; ··· 121 114 122 115 int index; 123 116 struct list_head link; 124 - 125 - struct list_head phy_receiver_list; 126 117 127 118 struct delayed_work br_work; /* bus reset job */ 128 119 bool br_short; ··· 136 131 137 132 bool broadcast_channel_allocated; 138 133 u32 broadcast_channel; 139 - __be32 topology_map[(CSR_TOPOLOGY_MAP_END - CSR_TOPOLOGY_MAP) / 4]; 134 + 135 + struct { 136 + __be32 buffer[(CSR_TOPOLOGY_MAP_END - CSR_TOPOLOGY_MAP) / 4]; 137 + spinlock_t lock; 138 + } topology_map; 140 139 141 140 __be32 maint_utility_register; 142 141