Skip to content

Commit

Permalink
gd patch appears to work now, basic_write test still hoses the target…
Browse files Browse the repository at this point in the history
… which

is not so good
  • Loading branch information
Paul Betts committed Nov 20, 2006
1 parent 049dca1 commit e7f7657
Showing 1 changed file with 91 additions and 37 deletions.
128 changes: 91 additions & 37 deletions osd_initiator/kernel/suo.c
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ struct scsi_osd_disk {
struct scsi_driver *driver; /* always &suo_template */
struct scsi_device *device;
struct cdev chrdev;
struct gendisk gd; /* not used much but needed for private_data */
struct file_operations* fops;
struct class_device classdev;
unsigned long __never_unset_me;
Expand Down Expand Up @@ -178,6 +179,10 @@ static DEFINE_SPINLOCK(sd_index_lock);
static DEFINE_MUTEX(sd_ref_mutex);


static DEFINE_SPINLOCK(cmd_key_lock);
static atomic_t cmd_key;


/*
* Forward Declarations
*/
Expand Down Expand Up @@ -230,7 +235,7 @@ static void suo_read_capacity(struct scsi_osd_disk *sdkp,
static int suo_revalidate_disk(struct scsi_osd_disk* sdkp);
static int suo_sync_cache(struct scsi_device *sdp);
EXPORT_SYMBOL(suo_sync_cache);
static int suo_init_command(struct scsi_cmnd* SCpnt);
static int suo_dispatch_command(struct scsi_device* sdp, struct request* req);
static void suo_rw_intr(struct scsi_cmnd * command);

/* Init / Release / Probe */
Expand Down Expand Up @@ -354,8 +359,7 @@ static struct scsi_driver suo_template = {
},
.rescan = sd_rescan,
.issue_flush = sd_issue_flush,

.init_command = suo_init_command,
.init_command = NULL,
};

static inline struct scsi_osd_disk* scsi_osd_disk(struct cdev* chrdev)
Expand All @@ -367,6 +371,7 @@ struct scsi_osd_disk* alloc_osd_disk(void)
{
struct cdev* chrdev;
struct scsi_osd_disk* sdkp;
struct gendisk* gd;

sdkp = kzalloc(sizeof(*sdkp), GFP_KERNEL);
if (!sdkp)
Expand All @@ -375,6 +380,15 @@ struct scsi_osd_disk* alloc_osd_disk(void)
atomic_set(&sdkp->inflight, 0);
sdkp->inflight_lock = SPIN_LOCK_UNLOCKED;
chrdev = &sdkp->chrdev;
gd = &sdkp->gd;

/* Even though we don't really use this structure,
* scsi_prep_fn and several other functions expect
* a somewhat kosher version of it */
gd->major = MAJOR(sdkp->dev_id);
gd->first_minor = MINOR(sdkp->dev_id);
gd->minors = 1;
gd->private_data = sdkp->driver;

cdev_init(chrdev, &suo_fops);
sdkp->fops = &suo_fops;
Expand Down Expand Up @@ -431,6 +445,40 @@ static void scsi_osd_disk_put(struct scsi_osd_disk *sdkp)
mutex_unlock(&sd_ref_mutex);
}

static inline int suo_get_cmdkey(void)
{
int ret;
spin_lock(&cmd_key_lock);
ret = atomic_read(&cmd_key);
spin_unlock(&cmd_key_lock);
return ret;
}

static inline int suo_get_cmdkey_irqsave(void)
{
int ret;
unsigned long flags;
spin_lock_irqsave(&cmd_key_lock, flags);
ret = atomic_read(&cmd_key);
spin_unlock_irqrestore(&cmd_key_lock, flags);
return ret;
}

static inline void suo_inc_cmdkey(void)
{
spin_lock(&cmd_key_lock);
atomic_inc(&cmd_key);
spin_unlock(&cmd_key_lock);
}

static inline void suo_inc_cmdkey_irqsave(void)
{
unsigned long flags;
spin_lock_irqsave(&cmd_key_lock, flags);
atomic_inc(&cmd_key);
spin_unlock_irqrestore(&cmd_key_lock, flags);
}


/**
* sd_open - open a scsi disk device
Expand Down Expand Up @@ -630,9 +678,9 @@ check_suo_request(struct request* req, struct suo_req* ureq)
{
int ret;

#ifdef CONFIG_SKIP_VERIFICATION
//#ifdef CONFIG_SKIP_VERIFICATION
return 0;
#endif
//#endif
ENTERING;

/* Check the request semantics */
Expand Down Expand Up @@ -787,15 +835,12 @@ suo_write(struct file *filp, const char __user *buf, size_t count, loff_t *ppos)
req->cmd_len = ureq.cdb_len;
req->sense = sense;
req->sense_len = 0;
req->retries = SD_MAX_RETRIES;
req->timeout = SD_TIMEOUT;
req->cmd_type = REQ_TYPE_BLOCK_PC;
req->cmd_flags |= REQ_QUIET | REQ_PREEMPT;
req->rq_disk = &sdkp->gd;
bio = req->bio;
blk_execute_rq(req->q, NULL, req, 1);

ret = req->errors;
suo_dispatch_command(sdev, req);

ret = req->errors;
scsi_normalize_sense(sense, SCSI_SENSE_BUFFERSIZE, &sshdr);
if (scsi_sense_valid(&sshdr))
scsi_print_sense_hdr(sdkp->disk_name, &sshdr);
Expand Down Expand Up @@ -971,26 +1016,18 @@ static void sd_rescan(struct device *dev)


/**
* suo_init_command - build a scsi (read or write) command from
* information in the request structure.
* @SCpnt: pointer to mid-level's per scsi command structure that
* contains request and into which the scsi command is written
* suo_dispatch_command - build a scsi (read or write) command from
* information in the request structure and send it off
*
* Returns 1 if successful and 0 if error (or cannot be done now).
**/
static int suo_init_command(struct scsi_cmnd* SCpnt)
static int suo_dispatch_command(struct scsi_device* sdp, struct request* req)
{
struct scsi_device *sdp = SCpnt->device;
struct request *rq = SCpnt->request;
unsigned int this_count = SCpnt->request_bufflen >> 9;
unsigned int timeout = sdp->timeout;

static unsigned char key = 1;

struct scsi_cmnd* cmd;
ENTERING;

if (!sdp || !scsi_device_online(sdp)) {
SCSI_LOG_HLQUEUE(2, printk("Retry with 0x%p\n", SCpnt));
SCSI_LOG_HLQUEUE(2, printk("Retry with 0x%p\n", cmd));
return 0;
}

Expand All @@ -1003,29 +1040,46 @@ static int suo_init_command(struct scsi_cmnd* SCpnt)
return 0;
}

/*
* We shouldn't disconnect in the middle of a sector, so with a dumb
* host adapter, it's safe to assume that we can at least transfer
* this many bytes between each connect / disconnect.
*/
SCpnt->transfersize = sdp->sector_size;
SCpnt->underflow = this_count << 9;
SCpnt->allowed = SD_MAX_RETRIES;
SCpnt->timeout_per_command = timeout;
cmd = scsi_get_command(sdp, GFP_ATOMIC);
if (unlikely(!cmd))
return 0;

memcpy(cmd->cmnd, req->cmd, sizeof(cmd->cmnd));
cmd->cmd_len = req->cmd_len;
if (!req->data_len)
cmd->sc_data_direction = DMA_NONE;
else if (rq_data_dir(req) == WRITE)
cmd->sc_data_direction = DMA_TO_DEVICE;
else
cmd->sc_data_direction = DMA_FROM_DEVICE;

cmd->transfersize = req->data_len;
cmd->allowed = req->retries;
cmd->timeout_per_command = req->timeout;
cmd->device = sdp;

/*
* This is the completion routine we use. This is matched in terms
* of capability to this function.
*/
SCpnt->done = suo_rw_intr;
SCpnt->tag = key;
key++;
dprintk("init_request: tag = %d\n", key);
cmd->done = suo_rw_intr;

/* Set some params before we jump out */
cmd->tag = suo_get_cmdkey();
suo_inc_cmdkey();
dprintk("init_request: tag = %d\n", cmd->tag);

struct scsi_osd_disk* sdkp = dev_get_drvdata(&sdp->sdev_gendev);
spin_lock(&sdkp->inflight_lock);
atomic_inc(&sdkp->inflight);
spin_unlock(&sdkp->inflight_lock);
req->special = cmd;
req->retries = SD_MAX_RETRIES;
req->timeout = SD_TIMEOUT;
req->cmd_type = REQ_TYPE_SPECIAL;
req->cmd_flags |= REQ_QUIET | REQ_PREEMPT;

blk_execute_rq(req->q, NULL, req, 1);

/*
* This indicates that the command is ready from our end to be
Expand Down

0 comments on commit e7f7657

Please sign in to comment.