Beispiel #1
0
int ata_scsi_abort(struct scsi_cmnd *cmd)
{
	struct ata_port *ap;
	struct scsi_device *scsidev;
	struct Scsi_Host *shost;
	struct ata_queued_cmd *qc;
	int rc;
	int i; 

	BUG_ON(cmd == NULL);
	scsidev = cmd->device;
	BUG_ON(scsidev == NULL);
	shost = scsidev->host;
	BUG_ON(shost == NULL);

	/* If no port available, no way to abort, fail */
	ap = ata_shost_to_port(shost);
	if (ap == NULL) {
		printk("%s: cmd %p, ap not found\n", __FUNCTION__, cmd);
		rc = FAILED;
		goto exit_abort;
	}

	/* If the cmd is not found, return abort failed */
	for (i = 0; i < ATA_MAX_QUEUE; i++) {
		if ((qc = __ata_qc_from_tag(ap, i))) {
			if (qc->scsicmd == cmd)
				break;
		}
	}
	if (i == ATA_MAX_QUEUE) {
		printk("%s: ap %p, cmd %p not found\n", __FUNCTION__, ap, cmd);
		rc = FAILED;
		goto exit_abort;
	}

	printk("%s: ap %p, qc %p, cmd %p, tag %d, flags %x, "
		"waiting for completion\n", 
		__FUNCTION__, ap, qc, cmd, i, (unsigned int)qc->flags);
	rc = FAILED;
	for (i = 0; i < 5; i++) {
		if (ata_cmd_completed(ap, qc)) {
			printk("%s: ap %p, cmd %p completed in %d seconds\n",
				__FUNCTION__, ap, cmd, i);
			/* wait to make sure scsi_done is called */
			msleep(1000);
			rc = SUCCESS;
			break;
		}
		msleep(1000);
	}

exit_abort:
	printk("%s: ap %p, cmd %p, %s\n", 
		__FUNCTION__, ap, cmd, (rc==SUCCESS)?"SUCCEEDED":"FAILED");
	return rc;
}
Beispiel #2
0
int pio_write_corefile(int offset) {
	/*
	 * The original idea here is to write to the "alternate
	 * application partition".  This has some problems though,
	 * spec. with developer boxes.  For now, we're going to
	 * assume this won't be called from a dev build.  (This is so
	 * broken it bothers me, we could write it to swap -32M -1M)
	 *
	 * The second broken thing here is we don't account for
	 * actual size of the memory of the box in question.  We
	 * assume it's 32Meg.  This is somewhat easily overcome by
	 * just checking the config variables.  However, I'm loathe
	 * to do that at this point since having variable size input
	 * just risks adding a new bug to the system.  (Something I don't
	 * want to do at this point in the release cycle)
	 *
	 * This is a *very basic* implementation of what we want to do.
	 * It starts at 0x80000000, goes for 32MB writing out to alternate
	 * application at either "offset 0", or "offset 1".  Offset 0 is
	 * at the beginning of the partition.  Offset 1 is 32MB into the
	 * partition.  (ah, now you see why I don't want to deal with
	 * variable sizes)
	 *
	 * Cache flushing is not required as we're doing it PIO, which just
	 * pulls from cache.  Of course, we're taking the kernel centric
	 * as opposed to hardware centric view of memory.  This is reasonable
	 * because really, the core is just a bunch of kernel memory
	 * structures for the most part.
	 * 
	 */
	struct block_device *bdev;
	struct gendisk *gp;
	struct scsi_disk *sdkp;
	struct scsi_device *sdev;
	struct ata_port *ap;
	struct ata_device *dev;
	
	int altpartition;
	unsigned long secoffset = (CORE_SIZE / 512) * offset;
	u32 csum; /* Currently unused */
	static int core_written = 0;

	/* Only 0 or 1 are valid offset values */
	if(!(offset == 0 || offset == 1))
		return -EINVAL;

	/* If the root is sda4, then altap is sda7 and vice-versa */
	if(ROOT_DEV == MKDEV(SCSI_DISK0_MAJOR, 4))
		altpartition = 7;
	else if(ROOT_DEV == MKDEV(SCSI_DISK0_MAJOR, 7))
		altpartition = 4;
	else
		return -ENODEV;

        if( (bdev = bdget(MKDEV(SCSI_DISK0_MAJOR, 0))) != NULL )
        { 
                if( (gp = bdev->bd_disk) != NULL){
                        if ((sdkp = scsi_disk_get(gp)) == NULL){
                                return -ENXIO;
                        }
                }
                else{
                        return -ENODEV;
                }
        }
        else{
                return -ENODEV;
        }

        if((sdev = scsi_dev_get(sdkp)) == NULL)
        {
                return -ENXIO;
        }

        ap = ata_shost_to_port(sdev->host);
	dev = ata_scsi_find_dev(ap, sdev);	  	   

        if( ap == NULL || dev == NULL ){
                return -ENXIO;
        }
        
	if(core_written != 0) {
		printk("Core already written\n");
		return -EINVAL;
	}
	
	core_written = 1;
	
	/* Partition must be at least twice a CORE */
	/* disk_get_part() increments ref count so need to release */
	struct hd_struct *hd_info = disk_get_part(gp, altpartition);
	if(hd_info->nr_sects < ((2 * CORE_SIZE) / 512)) {
	    /* release hd_info */
	    disk_put_part(hd_info);
		return -ENODEV;
	}
	
	if(initdrive) {
                /* Issue software reset, disable ide interrupts */
		if(pio_reset(ap) < 0) {
		    /* release hd_info */
		    disk_put_part(hd_info);
			return -ENODEV;
		}
		initdrive=0;
	}

	secoffset += hd_info->start_sect;

	/* release hd_info */
	disk_put_part(hd_info);

	return pio_write_buffer(dev, ap, secoffset, (const u8*)CORE_START,
		       CORE_SIZE, &csum);
}
Beispiel #3
0
/* Returns number of sectors written */
int pio_write_buffer_to_swap(const u8* buf, unsigned int size, int secoffset,
	u32 *csum) {
	struct block_device *bdev = NULL;
	struct gendisk *gp = NULL;
	struct scsi_disk *sdkp = NULL;
	struct scsi_device *sdev = NULL;
	struct ata_port *ap = NULL;
	struct ata_device *dev = NULL;
        int written_sect;
	
	unsigned long tsector;

        if( (bdev = bdget(MKDEV(SWAPFS_MAJOR, SWAPFS_MINOR))) != NULL )
        { 
                if( (gp = bdev->bd_disk) != NULL){
                        if ((sdkp = scsi_disk_get(gp)) == NULL){
                                return -ENXIO;
                        }
                }
                else{
                        return -ENODEV;
                }
        }
        else{
                return -ENODEV;
        }

        if((sdev = scsi_dev_get(sdkp)) == NULL)
        {
                return -ENXIO;
        }

        ap = ata_shost_to_port(sdev->host);
	dev = ata_scsi_find_dev(ap, sdev);	  	   

        if( ap == NULL || dev == NULL ){
                return -ENXIO;
        }

	/*
	 * We adjust secoffset to write to the last 1MB of the device,
	 * this is because we don't want to rebuild swap mostly, and
	 * because we can use "lspanic" to grab the last tivo panic.
	 *
	 * We will track which one we've logged by bit-inverting
	 * the checksum.
	 *
	 */
    /* disk_get_part() increments ref count so need to release */
    struct hd_struct *hd_info = disk_get_part(gp, SWAPFS_MINOR);
	/* Partition must be at least 2 MB */
	if(hd_info->nr_sects < (2* 1024 * 1024 / 512)){
		goto HD_INFO_ERROR;
        }

	/* Offset by 1MB from end of partition */
	secoffset += hd_info->nr_sects - (1 * 1024 * 1024 /512);

	/* Make sure partition is sane size-wise */

	if(hd_info->nr_sects < secoffset){
	    goto HD_INFO_ERROR;
        }
	if(hd_info->nr_sects - secoffset < ((size + 511)/512)) {
	    goto HD_INFO_ERROR;
	}
	
	if(initdrive) {
                /* Issue software reset, disable ide interrupts */
		if(pio_reset(ap) < 0) { 
		    goto HD_INFO_ERROR;
		}
	
                initdrive=0;
	}

	tsector = hd_info->start_sect + secoffset;

        written_sect = pio_write_buffer(dev, ap, tsector, buf, size, csum);

	scsi_disk_put(sdkp);
	/* release hd_info */
    disk_put_part(hd_info);
	return written_sect;

HD_INFO_ERROR:
    /* release hd_info */
    disk_put_part(hd_info);
    return -ENODEV;
}