rem: bool send_command( ide_device_info *device, ide_qrequest *qrequest, bool need_drdy, uint32 timeout, ide_bus_state new_state )
add: send_command(ide_device_info *device, ide_qrequest *qrequest, bool need_drdy, uint32 timeout, ide_bus_state new_state)
context: bool send_command( ide_device_info *device, ide_qrequest *qrequest,	bool need_drdy, uint32 timeout, ide_bus_state new_state ){	ide_bus_info *bus = device->bus;	bigtime_t irq_disabled_at = 0; // make compiler happy	uint8 num_retries = 0;	bool irq_guard;		FAST_LOGN( bus->log, ev_ide_send_command, 15, device->is_device1, (uint32)qrequest, 		device->tf.raw.r[0], device->tf.raw.r[1], device->tf.raw.r[2], 		device->tf.raw.r[3], device->tf.raw.r[4], device->tf.raw.r[5], 		device->tf.raw.r[6], 		device->tf.raw.r[7], device->tf.raw.r[8], device->tf.raw.r[9], 		device->tf.raw.r[10], device->tf.raw.r[11] );	retry:	irq_guard = bus->num_running_reqs > 1;		SHOW_FLOW( 3, "qrequest=%p, request=%p", qrequest,		qrequest ? qrequest->request : NULL );	// if there are pending requests, IRQs must be disabled to	// not mix up IRQ reasons	// XXX can we avoid that with the IDE_LOCK trick? It would	//     save some work and the bug workaround!	if( irq_guard ) {		if( bus->controller->write_device_control( bus->channel, 			ide_devctrl_nien | ide_devctrl_bit3 ) != B_OK )			goto err;		irq_disabled_at = system_time();	}	// select device	if( bus->controller->write_command_block_regs( bus->channel, &device->tf, 		ide_mask_device_head ) != B_OK ) 		goto err;			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 ) {			// there is no device (should happen during detection only)			SHOW_FLOW0( 1, "there is no device" );						// device detection recognizes this code as "all hope lost", so			// neither replace it nor use it anywhere else			device->subsys_status = SCSI_TID_INVALID;			return false;		}			// reset device and retry		if( reset_device( device, qrequest ) && ++num_retries <= MAX_FAILED_SEND ) {			SHOW_FLOW0( 1, "retrying" );			goto retry;		}				SHOW_FLOW0( 1, "giving up" );		// reset to often - abort request		device->subsys_status = SCSI_SEL_TIMEOUT;		return false;	}		if( need_drdy &&		(bus->controller->get_altstatus( bus->channel ) & ide_status_drdy) == 0 ) 	{		SHOW_FLOW0( 3, "drdy not set" );		device->subsys_status = SCSI_SEQUENCE_FAIL;		return false;	}		// write parameters		if( bus->controller->write_command_block_regs( bus->channel, &device->tf, 		device->tf_param_mask ) != B_OK )		goto err;			if( irq_guard ) {		// 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 )			spin( 1 );	}		// if we will start waiting once the command is sent, we have to	// lock the bus before sending; this way, IRQs that are fired	// shortly before/after sending of command are delayed until the	// command is really sent (start_waiting unlocks the bus) and then	// the IRQ handler can check savely whether the IRQ really signals 	// finishing of command or not by testing the busy-signal of the device	if( new_state != ide_state_accessing ) {		IDE_LOCK( bus );		}		if( irq_guard ) {		// now it's clear why IRQs gets fired, so we can enable them again		if( bus->controller->write_device_control( bus->channel, 			ide_devctrl_bit3 ) != B_OK ) 			goto err1;	}	// write command code - this will start the actual command		SHOW_FLOW( 3, "Writing command 0x%02x", (int)device->tf.write.command );	if( bus->controller->write_command_block_regs( bus->channel, 		&device->tf, ide_mask_command ) != B_OK ) 		goto err1;			// start waiting now; also un-blocks IRQ handler (see above)	if( new_state != ide_state_accessing ) {		start_waiting( bus, timeout, new_state );	}		return true;err1:	if( timeout > 0 ) {		bus->state = ide_state_accessing;		IDE_UNLOCK( bus );		}	err:	device->subsys_status = SCSI_HBA_ERR;	return false;}