Esempio n. 1
0
/**
 * Scan for devices on a bus.
 *
 * If there are bridges on the bus, recursively scan the buses behind the
 * bridges. If the setting up and tuning of the bus causes a reset to be
 * required, reset the bus and scan it again.
 *
 * @param busdev Pointer to the bus device.
 * @param max Current bus number.
 * @return The maximum bus number found, after scanning all subordinate buses.
 */
unsigned int scan_bus(struct device *busdev, unsigned int max)
{
	unsigned int new_max;
	int do_scan_bus;

	if (!busdev || !busdev->enabled || !busdev->ops ||
	    !busdev->ops->scan_bus) {
		return max;
	}

	do_scan_bus = 1;
	while (do_scan_bus) {
		struct bus *link;
		new_max = busdev->ops->scan_bus(busdev, max);
		do_scan_bus = 0;
		for (link = busdev->link_list; link; link = link->next) {
			if (link->reset_needed) {
				if (reset_bus(link))
					do_scan_bus = 1;
				else
					busdev->bus->reset_needed = 1;
			}
		}
	}
	return new_max;
}
/**
 * reset this master.
**/
BOOL w1_sysfs_master_reset(w1_master_id masterId)
{
    if(0 == masterId) return FALSE;
    if(g_masterId != masterId) return FALSE;

    return reset_bus();
}
Esempio n. 3
0
void reset_flashmodule(struct flashmodule *p_fm)
{
	int i;

	p_fm->power_fail_flag = 0;
	for (i = 0; i < NUM_OF_BUS; i++)
	{
		reset_bus(&p_fm->buses[i]);
	}
}
Esempio n. 4
0
bool
reset_device(ide_device_info *device, ide_qrequest *ignore)
{
	ide_bus_info *bus = device->bus;
	status_t res;
	uint8 orig_command;

	dprintf("ide: reset_device() device %p\n", device);

	SHOW_FLOW0(3, "");

	if (!device->is_atapi)
		goto err;

	if (device->reconnect_timer_installed) {
		cancel_timer(&device->reconnect_timer.te);
		device->reconnect_timer_installed = false;
	}

	// select device
	if (bus->controller->write_command_block_regs(bus->channel_cookie, &device->tf,
			ide_mask_device_head) != B_OK)
		goto err;

	// safe original command to let caller restart it
	orig_command = device->tf.write.command;

	// send device reset, independ of current device state
	// (that's the point of a reset)
	device->tf.write.command = IDE_CMD_DEVICE_RESET;
	res = bus->controller->write_command_block_regs(bus->channel_cookie,
		&device->tf, ide_mask_command);
	device->tf.write.command = orig_command;

	if (res != B_OK)
		goto err;

	// don't know how long to wait, but 31 seconds, like soft reset,
	// should be enough
	if (!ide_wait(device, 0, ide_status_bsy, true, 31000000))
		goto err;

	// alright, resubmit all requests
	finish_all_requests(device, ignore, SCSI_SCSI_BUS_RESET, true);

	SHOW_FLOW0(3, "done");
	dprintf("ide: reset_device() device %p success\n", device);
	return true;

err:
	// do the hard way
	dprintf("ide: reset_device() device %p failed, calling reset_bus\n", device);
	return reset_bus(device, ignore);
}
Esempio n. 5
0
int
main (int argc, char **argv)
{
  opts_t opts = OPTS_INIT;

  dc1394_t *dc1394_cxt = NULL;
  dc1394camera_list_t *cam_list = NULL;
  dc1394error_t err;

  if (argc < 2)
    {
      show_help ();
      return EXIT_SUCCESS;
    }

  parse_opts (&opts, argc, argv);
  dc1394_cxt = dc1394_new ();
  if (dc1394_cxt == NULL)
    {
      printf ("error: dc1394_new() failed.\n");
      return EXIT_FAILURE;
    }

  err = dc1394_camera_enumerate (dc1394_cxt, &cam_list);
  if (err != DC1394_SUCCESS || cam_list == NULL)
    {
      printf ("error: dc1394_camera_enumerate() failed.\n");
      dc1394_free (dc1394_cxt);
      return EXIT_FAILURE;
    }

  /* reset specified buses */
  if (opts.show_list == 0)
    {
      reset_bus (&opts, dc1394_cxt, cam_list);
    }
  else  /* show the list of detected cameras */
    {
      list_cameras (dc1394_cxt, cam_list);
    }

  dc1394_camera_free_list (cam_list);
  dc1394_free (dc1394_cxt);
  return EXIT_SUCCESS;
}
Esempio n. 6
0
// new_state must be either accessing, async_waiting or sync_waiting
// param_mask must not include command register
bool send_command( ide_device_info *device,
	bool need_drdy, bigtime_t timeout, ide_bus_state new_state )
{
	ide_bus_info *bus = device->bus;
	bigtime_t irq_disabled_at = 0; // make compiler happy

	bool irq_guard = bus->num_running_reqs > 1;

	SHOW_FLOW0( 3, "" );

	reset_timeouts( device );

	if( irq_guard ) {
		if( bus->controller->write_device_control( bus->channel,
			ide_devctrl_nien | ide_devctrl_bit3 ) != NO_ERROR )
			goto err;

		irq_disabled_at = system_time();
	}

	if( bus->controller->write_command_block_regs( bus->channel, &device->tf,
		ide_mask_device_head ) != NO_ERROR )
		goto err;

	SHOW_FLOW0( 3, "1" );

	bus->active_device = device;

	if( !ide_wait( device, 0, ide_status_bsy | ide_status_drq, false, 50000 )) {
		uint8 status;

		SHOW_FLOW0( 1, "device is not ready" );

		status = bus->controller->get_altstatus( bus->channel );
		if( status == 0xff ) {
			// this shouldn't happen unless the device has died
			// as we only submit commands to existing devices
			// (only detection routines shoot at will)
			set_sense( device, SCSIS_KEY_HARDWARE_ERROR, SCSIS_ASC_INTERNAL_FAILURE );
			return false;
		}

		if( !reset_bus( device ))
			return false;

		SHOW_FLOW0( 1, "retrying" );

		if( bus->controller->write_command_block_regs( bus->channel,
			 &device->tf, ide_mask_device_head ) != NO_ERROR )
			goto err;

		bus->active_device = device;

		if( !ide_wait( device, 0, ide_status_bsy | ide_status_drq, false, 50000 )) {
			// XXX this is not a device but a bus error, we should return
			// CAM_SEL_TIMEOUT instead
			SHOW_FLOW0( 1, "device is dead" );
			set_sense( device, SCSIS_KEY_ILLEGAL_REQUEST, SCSIS_ASC_LUN_SEL_FAILED );
			return false;
		}
	}

	SHOW_FLOW0( 3, "3" );

	if( need_drdy &&
		(bus->controller->get_altstatus( bus->channel ) & ide_status_drdy) == 0 )
	{
		SHOW_FLOW0( 3, "drdy not set" );
		set_sense( device, SCSIS_KEY_HARDWARE_ERROR, SCSIS_ASC_LUN_TIMEOUT );
		return false;
	}

	SHOW_FLOW0( 3, "4" );

	if( bus->controller->write_command_block_regs( bus->channel, &device->tf,
		device->tf_param_mask ) != NO_ERROR )
		goto err;

	SHOW_FLOW0( 3, "5" );

	if( irq_guard ) {
		// enable IRQs now
		// IRQ may be fired by service requests and by the process of disabling(!)
		// them (I heard this is caused by edge triggered PCI IRQs)

		// wait at least 50 µs to catch all pending irq's
		// (at my system, up to 30 µs elapsed)

		// additionally, old drives (at least my IBM-DTTA-351010) loose
		// sync if they are pushed too hard - on heavy overlapped write
		// stress this drive tends to forget outstanding requests,
		// waiting at least 50 µs seems(!) to solve this
		while( system_time() - irq_disabled_at < MAX_IRQ_DELAY )
			cpu_spin( 1 );

	}

	SHOW_FLOW0( 3, "6" );

	if( new_state != ide_state_accessing ) {
		IDE_LOCK( bus );
	}

	SHOW_FLOW( 3, "Writing command %x", (int)device->tf.write.command );
	if( bus->controller->write_command_block_regs( bus->channel,
		&device->tf, ide_mask_command ) != NO_ERROR )
		goto err2;

	SHOW_FLOW0( 3, "7" );

	if( irq_guard ) {
		if( bus->controller->write_device_control( bus->channel,
			ide_devctrl_bit3 ) != NO_ERROR )
			goto err1;
	}

	SHOW_FLOW0( 3, "8" );

	if( new_state != ide_state_accessing ) {
		start_waiting( bus, timeout, new_state );
	}

	SHOW_FLOW0( 3, "9" );

	return true;

err2:
	if( irq_guard )
		bus->controller->write_device_control( bus->channel,
			ide_devctrl_bit3 );

err1:
	if( timeout > 0 ) {
		bus->state = ide_state_accessing;
		IDE_UNLOCK( bus );
	}

err:
	set_sense( device, SCSIS_KEY_HARDWARE_ERROR, SCSIS_ASC_INTERNAL_FAILURE );
	return false;
}