Lines Matching +full:out +full:- +full:of +full:- +full:reset

1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Copyright (C) 2005-2007 Kristian Hoegsberg <krh@bitplanet.net>
8 #include <linux/crc-itu-t.h>
12 #include <linux/firewire-constants.h>
38 dev_name(card->device), &vaf); \
83 * IEEE-1394 specifies a default SPLIT_TIMEOUT value of 800 cycles (100 ms),
97 * Initialize contents of config rom buffer. On the OHCI in generate_config_rom()
101 * sure the contents of bus info block in host memory matches in generate_config_rom()
109 BIB_LINK_SPEED(card->link_speed) | in generate_config_rom()
110 BIB_GENERATION(card->config_rom_generation++ % 14 + 2) | in generate_config_rom()
112 BIB_MAX_RECEIVE(card->max_receive) | in generate_config_rom()
114 config_rom[3] = cpu_to_be32(card->guid >> 32); in generate_config_rom()
115 config_rom[4] = cpu_to_be32(card->guid); in generate_config_rom()
124 if (desc->immediate > 0) in generate_config_rom()
125 config_rom[i++] = cpu_to_be32(desc->immediate); in generate_config_rom()
126 config_rom[i] = cpu_to_be32(desc->key | (j - i)); in generate_config_rom()
128 j += desc->length; in generate_config_rom()
132 config_rom[5] = cpu_to_be32((i - 5 - 1) << 16); in generate_config_rom()
134 /* End of root directory, now copy in descriptors. */ in generate_config_rom()
136 for (k = 0; k < desc->length; k++) in generate_config_rom()
137 config_rom[i + k] = cpu_to_be32(desc->data[k]); in generate_config_rom()
138 i += desc->length; in generate_config_rom()
157 card->driver->set_config_rom(card, tmp_config_rom, in update_config_roms()
165 return desc->length + 1 + (desc->immediate > 0 ? 1 : 0); in required_space()
173 * Check descriptor is valid; the length of all blocks in the in fw_core_add_descriptor()
174 * descriptor has to add up to exactly the length of the in fw_core_add_descriptor()
178 while (i < desc->length) in fw_core_add_descriptor()
179 i += (desc->data[i] >> 16) + 1; in fw_core_add_descriptor()
181 if (i != desc->length) in fw_core_add_descriptor()
182 return -EINVAL; in fw_core_add_descriptor()
187 return -EBUSY; in fw_core_add_descriptor()
189 list_add_tail(&desc->link, &descriptor_list); in fw_core_add_descriptor()
192 if (desc->immediate > 0) in fw_core_add_descriptor()
204 list_del(&desc->link); in fw_core_remove_descriptor()
205 config_rom_length -= required_space(desc); in fw_core_remove_descriptor()
206 descriptor_count--; in fw_core_remove_descriptor()
207 if (desc->immediate > 0) in fw_core_remove_descriptor()
208 descriptor_count--; in fw_core_remove_descriptor()
218 trace_bus_reset_initiate(card->index, card->generation, short_reset); in reset_bus()
220 return card->driver->update_phy_reg(card, reg, 0, bit); in reset_bus()
225 trace_bus_reset_schedule(card->index, card->generation, short_reset); in fw_schedule_bus_reset()
227 /* We don't try hard to sort out requests of long vs. short resets. */ in fw_schedule_bus_reset()
228 card->br_short = short_reset; in fw_schedule_bus_reset()
230 /* Use an arbitrary short delay to combine multiple reset requests. */ in fw_schedule_bus_reset()
232 if (!queue_delayed_work(fw_workqueue, &card->br_work, in fw_schedule_bus_reset()
242 /* Delay for 2s after last reset per IEEE 1394 clause 8.2.1. */ in br_work()
243 if (card->reset_jiffies != 0 && in br_work()
244 time_before64(get_jiffies_64(), card->reset_jiffies + 2 * HZ)) { in br_work()
245 trace_bus_reset_postpone(card->index, card->generation, card->br_short); in br_work()
247 if (!queue_delayed_work(fw_workqueue, &card->br_work, 2 * HZ)) in br_work()
252 fw_send_phy_config(card, FW_PHY_CONFIG_NO_NODE_ID, card->generation, in br_work()
254 reset_bus(card, card->br_short); in br_work()
262 if (!card->broadcast_channel_allocated) { in allocate_broadcast_channel()
269 card->broadcast_channel_allocated = true; in allocate_broadcast_channel()
272 device_for_each_child(card->device, (void *)(long)generation, in allocate_broadcast_channel()
283 if (!schedule_delayed_work(&card->bm_work, delay)) in fw_schedule_bm_work()
301 spin_lock_irq(&card->lock); in bm_work()
303 if (card->local_node == NULL) { in bm_work()
304 spin_unlock_irq(&card->lock); in bm_work()
308 generation = card->generation; in bm_work()
310 root_node = card->root_node; in bm_work()
312 root_device = root_node->data; in bm_work()
314 atomic_read(&root_device->state) == FW_DEVICE_RUNNING; in bm_work()
315 root_device_is_cmc = root_device && root_device->cmc; in bm_work()
317 irm_device = card->irm_node->data; in bm_work()
318 irm_is_1394_1995_only = irm_device && irm_device->config_rom && in bm_work()
319 (irm_device->config_rom[2] & 0x000000f0) == 0; in bm_work()
322 keep_this_irm = irm_device && irm_device->config_rom && in bm_work()
323 irm_device->config_rom[3] >> 8 == CANON_OUI; in bm_work()
325 root_id = root_node->node_id; in bm_work()
326 irm_id = card->irm_node->node_id; in bm_work()
327 local_id = card->local_node->node_id; in bm_work()
330 card->reset_jiffies + DIV_ROUND_UP(HZ, 8)); in bm_work()
332 if ((is_next_generation(generation, card->bm_generation) && in bm_work()
333 !card->bm_abdicate) || in bm_work()
334 (card->bm_generation != generation && grace)) { in bm_work()
336 * This first step is to figure out who is IRM and in bm_work()
342 * so that when we do the reset, we still optimize the in bm_work()
343 * gap count. That could well save a reset in the in bm_work()
347 if (!card->irm_node->link_on) { in bm_work()
364 spin_unlock_irq(&card->lock); in bm_work()
372 /* Another bus reset, BM work has been rescheduled. */ in bm_work()
373 goto out; in bm_work()
377 scoped_guard(spinlock_irq, &card->lock) { in bm_work()
378 if (rcode == RCODE_COMPLETE && generation == card->generation) in bm_work()
379 card->bm_node_id = in bm_work()
388 goto out; in bm_work()
398 goto out; in bm_work()
401 spin_lock_irq(&card->lock); in bm_work()
407 * do a bus reset and pick the local node as in bm_work()
415 } else if (card->bm_generation != generation) { in bm_work()
418 * bus reset is less than 125ms ago. Reschedule this job. in bm_work()
420 spin_unlock_irq(&card->lock); in bm_work()
422 goto out; in bm_work()
430 card->bm_generation = generation; in bm_work()
432 if (card->gap_count == 0) { in bm_work()
435 * bus reset ASAP. The config rom read might never in bm_work()
438 * bus reset. The PHY configuration packet might in bm_work()
439 * fail, but 1394-2008 8.4.5.2 explicitly permits in bm_work()
444 * We must always send a bus reset if the gap count in bm_work()
445 * is inconsistent, so bypass the 5-reset limit. in bm_work()
447 card->bm_retries = 0; in bm_work()
456 * If we haven't probed this device yet, bail out now in bm_work()
459 spin_unlock_irq(&card->lock); in bm_work()
460 goto out; in bm_work()
463 * We will send out a force root packet for this in bm_work()
464 * node as part of the gap count optimization. in bm_work()
478 * Pick a gap count from 1394a table E-1. The table doesn't cover in bm_work()
481 if (!card->beta_repeaters_present && in bm_work()
482 root_node->max_hops < ARRAY_SIZE(gap_count_table)) in bm_work()
483 gap_count = gap_count_table[root_node->max_hops]; in bm_work()
488 * Finally, figure out if we should do a reset or not. If we have in bm_work()
493 if (card->bm_retries++ < 5 && in bm_work()
494 (card->gap_count != gap_count || new_root_id != root_id)) in bm_work()
497 spin_unlock_irq(&card->lock); in bm_work()
504 * Where possible, use a short bus reset to minimize in bm_work()
506 * of a gap count inconsistency, use a long bus reset. in bm_work()
509 * may set different gap counts after a bus reset. On a mixed in bm_work()
510 * 1394/1394a bus, a short bus reset can get doubled. Some in bm_work()
511 * nodes may treat the double reset as one bus reset and others in bm_work()
513 * again. Using a long bus reset prevents this. in bm_work()
515 reset_bus(card, card->gap_count != 0); in bm_work()
516 /* Will allocate broadcast channel after the reset. */ in bm_work()
517 goto out; in bm_work()
530 goto out; in bm_work()
536 out: in bm_work()
546 static atomic_t index = ATOMIC_INIT(-1); in fw_card_initialize()
548 card->index = atomic_inc_return(&index); in fw_card_initialize()
549 card->driver = driver; in fw_card_initialize()
550 card->device = device; in fw_card_initialize()
551 card->current_tlabel = 0; in fw_card_initialize()
552 card->tlabel_mask = 0; in fw_card_initialize()
553 card->split_timeout_hi = DEFAULT_SPLIT_TIMEOUT / 8000; in fw_card_initialize()
554 card->split_timeout_lo = (DEFAULT_SPLIT_TIMEOUT % 8000) << 19; in fw_card_initialize()
555 card->split_timeout_cycles = DEFAULT_SPLIT_TIMEOUT; in fw_card_initialize()
556 card->split_timeout_jiffies = in fw_card_initialize()
558 card->color = 0; in fw_card_initialize()
559 card->broadcast_channel = BROADCAST_CHANNEL_INITIAL; in fw_card_initialize()
561 kref_init(&card->kref); in fw_card_initialize()
562 init_completion(&card->done); in fw_card_initialize()
563 INIT_LIST_HEAD(&card->transaction_list); in fw_card_initialize()
564 INIT_LIST_HEAD(&card->phy_receiver_list); in fw_card_initialize()
565 spin_lock_init(&card->lock); in fw_card_initialize()
567 card->local_node = NULL; in fw_card_initialize()
569 INIT_DELAYED_WORK(&card->br_work, br_work); in fw_card_initialize()
570 INIT_DELAYED_WORK(&card->bm_work, bm_work); in fw_card_initialize()
583 // implementation of unit protocol could consumes the core in fw_card_add()
585 // * != WQ_MEM_RECLAIM Not used for any backend of block device. in fw_card_add()
588 // * == WQ_HIGHPRI High priority to process semi-realtime timestamped data. in fw_card_add()
592 isoc_wq = alloc_workqueue("firewire-isoc-card%u", in fw_card_add()
594 supported_isoc_contexts, card->index); in fw_card_add()
596 return -ENOMEM; in fw_card_add()
598 card->max_receive = max_receive; in fw_card_add()
599 card->link_speed = link_speed; in fw_card_add()
600 card->guid = guid; in fw_card_add()
605 ret = card->driver->enable(card, tmp_config_rom, config_rom_length); in fw_card_add()
611 card->isoc_wq = isoc_wq; in fw_card_add()
612 list_add_tail(&card->link, &card_list); in fw_card_add()
622 * instead of calling into the module. Only functions for iso context
627 * .set_config_rom() is never called since the card is taken out of card_list
633 return -ENODEV; in dummy_read_phy_reg()
639 return -ENODEV; in dummy_update_phy_reg()
644 packet->callback(packet, card, RCODE_CANCELLED); in dummy_send_request()
649 packet->callback(packet, card, RCODE_CANCELLED); in dummy_send_response()
654 return -ENOENT; in dummy_cancel_packet()
660 return -ENODEV; in dummy_enable_phys_dma()
666 return ERR_PTR(-ENODEV); in dummy_allocate_iso_context()
681 return -ENODEV; in dummy_start_iso()
686 return -ENODEV; in dummy_set_iso_channels()
692 return -ENODEV; in dummy_queue_iso()
701 return -ENODEV; in dummy_flush_iso_completions()
725 complete(&card->done); in fw_card_release()
735 card->driver->update_phy_reg(card, 4, in fw_core_remove_card()
740 list_del_init(&card->link); in fw_core_remove_card()
742 /* Switch off most of the card driver interface. */ in fw_core_remove_card()
743 dummy_driver.free_iso_context = card->driver->free_iso_context; in fw_core_remove_card()
744 dummy_driver.stop_iso = card->driver->stop_iso; in fw_core_remove_card()
745 card->driver = &dummy_driver; in fw_core_remove_card()
746 drain_workqueue(card->isoc_wq); in fw_core_remove_card()
748 scoped_guard(spinlock_irqsave, &card->lock) in fw_core_remove_card()
753 wait_for_completion(&card->done); in fw_core_remove_card()
755 destroy_workqueue(card->isoc_wq); in fw_core_remove_card()
757 WARN_ON(!list_empty(&card->transaction_list)); in fw_core_remove_card()
762 * fw_card_read_cycle_time: read from Isochronous Cycle Timer Register of 1394 OHCI in MMIO region
764 * @card: The instance of card for 1394 OHCI controller.
765 * @cycle_time: The mutual reference to value of cycle time for the read operation.
767 * Read value from Isochronous Cycle Timer Register of 1394 OHCI in MMIO region for the given
769 * When returning successfully, the content of @value argument has value aligned to host endianness,
770 * formetted by CYCLE_TIME CSR Register of IEEE 1394 std.
774 * * 0 - Read successfully.
775 * * -ENODEV - The controller is unavailable due to being removed or unbound.
779 if (card->driver->read_csr == dummy_read_csr) in fw_card_read_cycle_time()
780 return -ENODEV; in fw_card_read_cycle_time()
783 // effort to return -ENODEV. in fw_card_read_cycle_time()
784 *cycle_time = card->driver->read_csr(card, CSR_CYCLE_TIME); in fw_card_read_cycle_time()