FreeBSD/sbin/camcontrol/fwdownload.c
/*
 * Returns 0 for "success", where success means that the device has met the
 * requirement in the vendor structure for being ready or not ready when
 * firmware is downloaded.
 *
 * Returns 1 for a failure to be ready to accept a firmware download.
 * (e.g., a drive needs to be ready, but returns not ready)
 *
 * Returns -1 for any other failure.
 */
Returns 0 for "success", where success means that the device has met the
requirement in the vendor structure for being ready or not ready when
firmware is downloaded.

Returns 1 for a failure to be ready to accept a firmware download.

1 for any other failure.
Returns 0 for " success " where success means that the device has met the requirement in the vendor structure for being ready or not ready when firmware is downloaded . Returns 1 for a failure to be ready to accept a firmware download . 1 for any other failure .
static int
fw_check_device_ready(struct cam_device *dev, camcontrol_devtype devtype,
		      struct fw_vendor *vp, int printerrors, int timeout)
{
	union ccb *ccb;
	int retval = 0;
	int16_t *ptr = NULL;
	size_t dxfer_len = 0;
	if ((ccb = cam_getccb(dev)) == NULL) {
		warnx("Could not allocate CCB");
		retval = -1;
		goto bailout;
	}
	CCB_CLEAR_ALL_EXCEPT_HDR(ccb);
	if (devtype != CC_DT_SCSI) {
		dxfer_len = sizeof(struct ata_params);
		ptr = (uint16_t *)malloc(dxfer_len);
		if (ptr == NULL) {
			warnx("can't malloc memory for identify");
			retval = -1;
			goto bailout;
		}
		bzero(ptr, dxfer_len);
	}
	switch (devtype) {
	case CC_DT_SCSI:
		scsi_test_unit_ready(&ccb->csio,
				      0,
				      NULL,
				      MSG_SIMPLE_Q_TAG,
		    		      SSD_FULL_SIZE,
				      5000);
		break;
	case CC_DT_ATA_BEHIND_SCSI:
	case CC_DT_ATA: {
		retval = build_ata_cmd(ccb,
			      1,
			      CAM_DIR_IN,
			      MSG_SIMPLE_Q_TAG,
			      AP_PROTO_PIO_IN,
			      AP_FLAG_BYT_BLOK_BYTES |
					   AP_FLAG_TLEN_SECT_CNT |
					   AP_FLAG_TDIR_FROM_DEV,
			      0,
			      (uint8_t) dxfer_len,
			      0,
			      ATA_ATA_IDENTIFY,
			      0,
			      (uint8_t *)ptr,
			      dxfer_len,
			      NULL,
			      0,
			      SSD_FULL_SIZE,
			      timeout ? timeout : 30 * 1000,
			      0,
			      devtype);
		if (retval != 0) {
			retval = -1;
			warnx("%s: build_ata_cmd() failed, likely "
			    "programmer error", __func__);
			goto bailout;
		}
		break;
	}
	default:
		warnx("Unknown disk type %d", devtype);
		retval = -1;
		goto bailout;
		break; 
	}
	ccb->ccb_h.flags |= CAM_DEV_QFRZDIS;
	retval = cam_send_ccb(dev, ccb);
	if (retval != 0) {
		warn("error sending %s CCB", (devtype == CC_DT_SCSI) ?
		     "Test Unit Ready" : "Identify");
		retval = -1;
		goto bailout;
	}
	if (((ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP)
	 && (vp->tur_status == FW_TUR_READY)) {
		warnx("Device is not ready");
		if (printerrors)
			cam_error_print(dev, ccb, CAM_ESF_ALL,
			    CAM_EPF_ALL, stderr);
		retval = 1;
		goto bailout;
	} else if (((ccb->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) 
		&& (vp->tur_status == FW_TUR_NOT_READY)) {
		warnx("Device cannot have media loaded when firmware is "
		    "downloaded");
		retval = 1;
		goto bailout;
	}
bailout:
	if (ccb != NULL)
		cam_freeccb(ccb);
	return (retval);
}
static int fw_check_device_ready ( struct cam_device * dev , camcontrol_devtype devtype , struct fw_vendor * vp , int printerrors , int timeout ) { union ccb * ccb ; int retval = 0 ; int16_t * ptr = NULL ; size_t dxfer_len = 0 ; if ( ( ccb = cam_getccb ( dev ) ) == NULL ) { warnx ( " " ) ; retval = -1 ; goto bailout ; } CCB_CLEAR_ALL_EXCEPT_HDR ( ccb ) ; if ( devtype != CC_DT_SCSI ) { dxfer_len = sizeof ( struct ata_params ) ; ptr = ( uint16_t * ) malloc ( dxfer_len ) ; if ( ptr == NULL ) { warnx ( " " ) ; retval = -1 ; goto bailout ; } bzero ( ptr , dxfer_len ) ; } switch ( devtype ) { case CC_DT_SCSI : scsi_test_unit_ready ( & ccb -> csio , 0 , NULL , MSG_SIMPLE_Q_TAG , SSD_FULL_SIZE , 5000 ) ; break ; case CC_DT_ATA_BEHIND_SCSI : case CC_DT_ATA : { retval = build_ata_cmd ( ccb , 1 , CAM_DIR_IN , MSG_SIMPLE_Q_TAG , AP_PROTO_PIO_IN , AP_FLAG_BYT_BLOK_BYTES | AP_FLAG_TLEN_SECT_CNT | AP_FLAG_TDIR_FROM_DEV , 0 , ( uint8_t ) dxfer_len , 0 , ATA_ATA_IDENTIFY , 0 , ( uint8_t * ) ptr , dxfer_len , NULL , 0 , SSD_FULL_SIZE , timeout ? timeout : 30 * 1000 , 0 , devtype ) ; if ( retval != 0 ) { retval = -1 ; warnx ( " " " " , __func__ ) ; goto bailout ; } break ; } default : warnx ( " " , devtype ) ; retval = -1 ; goto bailout ; break ; } ccb -> ccb_h . flags |= CAM_DEV_QFRZDIS ; retval = cam_send_ccb ( dev , ccb ) ; if ( retval != 0 ) { warn ( " " , ( devtype == CC_DT_SCSI ) ? " " : " " ) ; retval = -1 ; goto bailout ; } if ( ( ( ccb -> ccb_h . status & CAM_STATUS_MASK ) != CAM_REQ_CMP ) && ( vp -> tur_status == FW_TUR_READY ) ) { warnx ( " " ) ; if ( printerrors ) cam_error_print ( dev , ccb , CAM_ESF_ALL , CAM_EPF_ALL , stderr ) ; retval = 1 ; goto bailout ; } else if ( ( ( ccb -> ccb_h . status & CAM_STATUS_MASK ) == CAM_REQ_CMP ) && ( vp -> tur_status == FW_TUR_NOT_READY ) ) { warnx ( " " " " ) ; retval = 1 ; goto bailout ; } bailout : if ( ccb != NULL ) cam_freeccb ( ccb ) ; return ( retval ) ; }
Returns 0 for "success", where success means that the device has met the
 requirement in the vendor structure for being ready or not ready when
 firmware is downloaded.
Returns 0 for " success " where success means that the device has met the requirement in the vendor structure for being ready or not ready when firmware is downloaded .
/*retries*/ /*cbfcnp*/ /*tag_action*/ /*sense_len*/ /*timeout*/ /*retries*/ /*flags*/ /*tag_action*/ /*protocol*/ /*ata_flags*/ /*features*/ /*sector_count*/ /*lba*/ /*command*/ /*auxiliary*/ /*data_ptr*/ /*dxfer_len*/ /*cdb_storage*/ /*cdb_storage_len*/ /*sense_len*/ /*timeout*/ /*is48bit*/ /*devtype*/ /*NOTREACHED*/