Style cleanup.
Some more useful default levels for the debug output (only wrapper.h, the values actually used were okay). git-svn-id: file:///srv/svn/repos/haiku/trunk/current@10303 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
** Copyright 2002/03, Thomas Kurschel. All rights reserved.
|
* Copyright 2002/03, Thomas Kurschel. All rights reserved.
|
||||||
** Distributed under the terms of the OpenBeOS License.
|
* Distributed under the terms of the MIT License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Part of Open SCSI Disk Driver
|
Part of Open SCSI Disk Driver
|
||||||
@@ -9,6 +9,7 @@
|
|||||||
Device management.
|
Device management.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#include "scsi_dsk_int.h"
|
#include "scsi_dsk_int.h"
|
||||||
|
|
||||||
#include <pnp_devfs.h>
|
#include <pnp_devfs.h>
|
||||||
@@ -23,7 +24,7 @@ das_init_device(pnp_node_handle node, void *user_cookie, void **cookie)
|
|||||||
status_t res;
|
status_t res;
|
||||||
scsi_ccb *request;
|
scsi_ccb *request;
|
||||||
|
|
||||||
SHOW_FLOW0( 3, "" );
|
SHOW_FLOW0(3, "");
|
||||||
|
|
||||||
device = (das_device_info *)malloc(sizeof(*device));
|
device = (das_device_info *)malloc(sizeof(*device));
|
||||||
if (device == NULL)
|
if (device == NULL)
|
||||||
@@ -135,12 +136,11 @@ das_device_added(pnp_node_handle node)
|
|||||||
goto err;
|
goto err;
|
||||||
}
|
}
|
||||||
|
|
||||||
SHOW_FLOW(3, "name=%s", name);
|
SHOW_FLOW(3, "name = %s", name);
|
||||||
|
|
||||||
// ready to register
|
// ready to register
|
||||||
{
|
{
|
||||||
pnp_node_attr attrs[] =
|
pnp_node_attr attrs[] = {
|
||||||
{
|
|
||||||
{ PNP_DRIVER_DRIVER, B_STRING_TYPE, { string: SCSI_DSK_MODULE_NAME }},
|
{ PNP_DRIVER_DRIVER, B_STRING_TYPE, { string: SCSI_DSK_MODULE_NAME }},
|
||||||
{ PNP_DRIVER_TYPE, B_STRING_TYPE, { string: BLKDEV_TYPE_NAME }},
|
{ PNP_DRIVER_TYPE, B_STRING_TYPE, { string: BLKDEV_TYPE_NAME }},
|
||||||
// we always want blkdev on top of us
|
// we always want blkdev on top of us
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
** Copyright 2002/03, Thomas Kurschel. All rights reserved.
|
* Copyright 2002/03, Thomas Kurschel. All rights reserved.
|
||||||
** Distributed under the terms of the OpenBeOS License.
|
* Distributed under the terms of the MIT License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Part of Open SCSI Disk Driver
|
Part of Open SCSI Disk Driver
|
||||||
@@ -9,56 +9,63 @@
|
|||||||
File handle management.
|
File handle management.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#include "scsi_dsk_int.h"
|
#include "scsi_dsk_int.h"
|
||||||
|
|
||||||
#include <malloc.h>
|
#include <malloc.h>
|
||||||
|
|
||||||
status_t das_open( das_device_info *device, das_handle_info **handle_out )
|
|
||||||
|
status_t
|
||||||
|
das_open(das_device_info *device, das_handle_info **handle_out)
|
||||||
{
|
{
|
||||||
das_handle_info *handle;
|
das_handle_info *handle;
|
||||||
int res;
|
int res;
|
||||||
|
|
||||||
SHOW_FLOW0( 3, "" );
|
SHOW_FLOW0(3, "");
|
||||||
|
|
||||||
handle = (das_handle_info *)malloc( sizeof( *handle ));
|
handle = (das_handle_info *)malloc(sizeof(*handle));
|
||||||
if( handle == NULL )
|
if (handle == NULL)
|
||||||
return B_NO_MEMORY;
|
return B_NO_MEMORY;
|
||||||
|
|
||||||
handle->device = device;
|
handle->device = device;
|
||||||
|
|
||||||
res = scsi_periph->handle_open( device->scsi_periph_device,
|
res = scsi_periph->handle_open(device->scsi_periph_device,
|
||||||
(periph_handle_cookie)handle,
|
(periph_handle_cookie)handle,
|
||||||
&handle->scsi_periph_handle );
|
&handle->scsi_periph_handle);
|
||||||
if( res < 0 ) {
|
if (res < 0) {
|
||||||
free( handle );
|
free(handle);
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
SHOW_FLOW0( 3, "opened" );
|
SHOW_FLOW0(3, "opened");
|
||||||
|
|
||||||
*handle_out = handle;
|
*handle_out = handle;
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
status_t das_close( das_handle_info *handle )
|
|
||||||
|
status_t
|
||||||
|
das_close(das_handle_info *handle)
|
||||||
{
|
{
|
||||||
SHOW_FLOW0( 3, "" );
|
SHOW_FLOW0(3, "");
|
||||||
|
|
||||||
scsi_periph->handle_close( handle->scsi_periph_handle );
|
scsi_periph->handle_close(handle->scsi_periph_handle);
|
||||||
|
|
||||||
SHOW_FLOW0( 3, "done" );
|
SHOW_FLOW0(3, "done");
|
||||||
|
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
status_t das_free( das_handle_info *handle )
|
|
||||||
|
status_t
|
||||||
|
das_free(das_handle_info *handle)
|
||||||
{
|
{
|
||||||
SHOW_FLOW0( 3, "" );
|
SHOW_FLOW0(3, "");
|
||||||
|
|
||||||
scsi_periph->handle_free( handle->scsi_periph_handle );
|
scsi_periph->handle_free(handle->scsi_periph_handle);
|
||||||
free( handle );
|
free(handle);
|
||||||
|
|
||||||
SHOW_FLOW0( 3, "done" );
|
SHOW_FLOW0(3, "done");
|
||||||
|
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
** Copyright 2002/03, Thomas Kurschel. All rights reserved.
|
* Copyright 2002/03, Thomas Kurschel. All rights reserved.
|
||||||
** Distributed under the terms of the OpenBeOS License.
|
* Distributed under the terms of the MIT License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Part of Open SCSI Disk Driver
|
Part of Open SCSI Disk Driver
|
||||||
@@ -9,37 +9,41 @@
|
|||||||
Everything doing the real input/output stuff.
|
Everything doing the real input/output stuff.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#include "scsi_dsk_int.h"
|
#include "scsi_dsk_int.h"
|
||||||
|
|
||||||
#define DAS_STD_TIMEOUT 10
|
#define DAS_STD_TIMEOUT 10
|
||||||
|
|
||||||
|
|
||||||
// we don't want to inline this function - it's just not worth it
|
// we don't want to inline this function - it's just not worth it
|
||||||
static int das_read_write( das_handle_info *handle, const phys_vecs *vecs,
|
static int das_read_write(das_handle_info *handle, const phys_vecs *vecs,
|
||||||
off_t pos, size_t num_blocks, uint32 block_size, size_t *bytes_transferred,
|
off_t pos, size_t num_blocks, uint32 block_size, size_t *bytes_transferred,
|
||||||
bool write );
|
bool write);
|
||||||
|
|
||||||
|
|
||||||
status_t das_read( das_handle_info *handle, const phys_vecs *vecs,
|
status_t
|
||||||
off_t pos, size_t num_blocks, uint32 block_size, size_t *bytes_transferred )
|
das_read(das_handle_info *handle, const phys_vecs *vecs, off_t pos, size_t numBlocks,
|
||||||
|
uint32 blockSize, size_t *bytesTransferred)
|
||||||
{
|
{
|
||||||
return das_read_write( handle, vecs, pos,
|
return das_read_write(handle, vecs, pos, numBlocks, blockSize,
|
||||||
num_blocks, block_size, bytes_transferred, false );
|
bytesTransferred, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
status_t das_write( das_handle_info *handle, const phys_vecs *vecs,
|
status_t
|
||||||
off_t pos, size_t num_blocks, uint32 block_size, size_t *bytes_transferred )
|
das_write(das_handle_info *handle, const phys_vecs *vecs, off_t pos, size_t numBlocks,
|
||||||
|
uint32 blockSize, size_t *bytesTransferred)
|
||||||
{
|
{
|
||||||
return das_read_write( handle, vecs, pos,
|
return das_read_write(handle, vecs, pos, numBlocks, blockSize,
|
||||||
num_blocks, block_size, bytes_transferred, true );
|
bytesTransferred, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// universal read/write function
|
/** universal read/write function */
|
||||||
static int das_read_write( das_handle_info *handle, const phys_vecs *vecs,
|
|
||||||
off_t pos64, size_t num_blocks, uint32 block_size, size_t *bytes_transferred,
|
static int
|
||||||
bool write )
|
das_read_write(das_handle_info *handle, const phys_vecs *vecs, off_t pos64,
|
||||||
|
size_t num_blocks, uint32 block_size, size_t *bytes_transferred, bool write)
|
||||||
{
|
{
|
||||||
das_device_info *device = handle->device;
|
das_device_info *device = handle->device;
|
||||||
scsi_ccb *request;
|
scsi_ccb *request;
|
||||||
@@ -49,38 +53,37 @@ static int das_read_write( das_handle_info *handle, const phys_vecs *vecs,
|
|||||||
uint32 pos = pos64;
|
uint32 pos = pos64;
|
||||||
|
|
||||||
// don't test rw10_enabled restrictions - this flag may get changed
|
// don't test rw10_enabled restrictions - this flag may get changed
|
||||||
request = device->scsi->alloc_ccb( device->scsi_device );
|
request = device->scsi->alloc_ccb(device->scsi_device);
|
||||||
|
if (request == NULL)
|
||||||
if( request == NULL )
|
|
||||||
return B_NO_MEMORY;
|
return B_NO_MEMORY;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
size_t num_bytes;
|
size_t num_bytes;
|
||||||
bool is_rw10;
|
bool is_rw10;
|
||||||
|
|
||||||
request->flags = write ? SCSI_DIR_OUT : SCSI_DIR_IN;
|
request->flags = write ? SCSI_DIR_OUT : SCSI_DIR_IN;
|
||||||
|
|
||||||
// make sure we avoid 10 byte commands if they aren't supported
|
// make sure we avoid 10 byte commands if they aren't supported
|
||||||
if( !device->rw10_enabled ) {
|
if (!device->rw10_enabled) {
|
||||||
// restricting transfer is OK - the block manager will
|
// restricting transfer is OK - the block manager will
|
||||||
// take care of transferring the rest
|
// take care of transferring the rest
|
||||||
if( num_blocks > 0x100 )
|
if (num_blocks > 0x100)
|
||||||
num_blocks = 0x100;
|
num_blocks = 0x100;
|
||||||
|
|
||||||
// no way to break the 21 bit address limit
|
// no way to break the 21 bit address limit
|
||||||
if( pos64 > 0x200000 ) {
|
if (pos64 > 0x200000) {
|
||||||
err = B_BAD_VALUE;
|
err = B_BAD_VALUE;
|
||||||
goto abort;
|
goto abort;
|
||||||
}
|
}
|
||||||
|
|
||||||
// don't allow transfer cross the 24 bit address limit
|
// don't allow transfer cross the 24 bit address limit
|
||||||
// (I'm not sure whether this is allowed, but this way we
|
// (I'm not sure whether this is allowed, but this way we
|
||||||
// are sure to not ask for trouble)
|
// are sure to not ask for trouble)
|
||||||
num_blocks = min( num_blocks, 0x100000 - pos );
|
num_blocks = min(num_blocks, 0x100000 - pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
num_bytes = num_blocks * block_size;
|
num_bytes = num_blocks * block_size;
|
||||||
|
|
||||||
request->data = NULL;
|
request->data = NULL;
|
||||||
request->sg_list = vecs->vec;
|
request->sg_list = vecs->vec;
|
||||||
request->data_len = num_bytes;
|
request->data_len = num_bytes;
|
||||||
@@ -89,123 +92,126 @@ static int das_read_write( das_handle_info *handle, const phys_vecs *vecs,
|
|||||||
request->timeout = DAS_STD_TIMEOUT;
|
request->timeout = DAS_STD_TIMEOUT;
|
||||||
// see whether daemon instructed us to post an ordered command;
|
// see whether daemon instructed us to post an ordered command;
|
||||||
// reset flag after read
|
// reset flag after read
|
||||||
request->flags = atomic_and( &device->next_tag_action, 0 );
|
request->flags = atomic_and(&device->next_tag_action, 0);
|
||||||
|
|
||||||
SHOW_FLOW( 3, "ordered: %s",
|
SHOW_FLOW(3, "ordered: %s",
|
||||||
(request->flags & SCSI_ORDERED_QTAG) == 0 ? "yes" : "no" );
|
(request->flags & SCSI_ORDERED_QTAG) == 0 ? "yes" : "no");
|
||||||
|
|
||||||
// use 6 byte commands whenever possible
|
// use 6 byte commands whenever possible
|
||||||
if( pos + num_blocks < 0x200000 && num_blocks <= 0x100 ) {
|
if (pos + num_blocks < 0x200000 && num_blocks <= 0x100) {
|
||||||
scsi_cmd_rw_6 *cmd = (scsi_cmd_rw_6 *)request->cdb;
|
scsi_cmd_rw_6 *cmd = (scsi_cmd_rw_6 *)request->cdb;
|
||||||
|
|
||||||
is_rw10 = false;
|
is_rw10 = false;
|
||||||
|
|
||||||
memset( cmd, 0, sizeof( *cmd ));
|
memset(cmd, 0, sizeof(*cmd));
|
||||||
cmd->opcode = write ? SCSI_OP_WRITE_6 : SCSI_OP_READ_6;
|
cmd->opcode = write ? SCSI_OP_WRITE_6 : SCSI_OP_READ_6;
|
||||||
cmd->high_LBA = (pos >> 16) & 0x1f;
|
cmd->high_LBA = (pos >> 16) & 0x1f;
|
||||||
cmd->mid_LBA = (pos >> 8) & 0xff;
|
cmd->mid_LBA = (pos >> 8) & 0xff;
|
||||||
cmd->low_LBA = pos & 0xff;
|
cmd->low_LBA = pos & 0xff;
|
||||||
cmd->length = num_blocks;
|
cmd->length = num_blocks;
|
||||||
|
|
||||||
request->cdb_len = sizeof( *cmd );
|
request->cdb_len = sizeof(*cmd);
|
||||||
} else {
|
} else {
|
||||||
scsi_cmd_rw_10 *cmd = (scsi_cmd_rw_10 *)request->cdb;
|
scsi_cmd_rw_10 *cmd = (scsi_cmd_rw_10 *)request->cdb;
|
||||||
|
|
||||||
is_rw10 = true;
|
is_rw10 = true;
|
||||||
|
|
||||||
memset( cmd, 0, sizeof( *cmd ));
|
memset(cmd, 0, sizeof(*cmd));
|
||||||
cmd->opcode = write ? SCSI_OP_WRITE_10 : SCSI_OP_READ_10;
|
cmd->opcode = write ? SCSI_OP_WRITE_10 : SCSI_OP_READ_10;
|
||||||
cmd->RelAdr = 0;
|
cmd->RelAdr = 0;
|
||||||
cmd->FUA = 0;
|
cmd->FUA = 0;
|
||||||
cmd->DPO = 0;
|
cmd->DPO = 0;
|
||||||
|
|
||||||
cmd->top_LBA = (pos >> 24) & 0xff;
|
cmd->top_LBA = (pos >> 24) & 0xff;
|
||||||
cmd->high_LBA = (pos >> 16) & 0xff;
|
cmd->high_LBA = (pos >> 16) & 0xff;
|
||||||
cmd->mid_LBA = (pos >> 8) & 0xff;
|
cmd->mid_LBA = (pos >> 8) & 0xff;
|
||||||
cmd->low_LBA = pos & 0xff;
|
cmd->low_LBA = pos & 0xff;
|
||||||
|
|
||||||
cmd->high_length = (num_blocks >> 8) & 0xff;
|
cmd->high_length = (num_blocks >> 8) & 0xff;
|
||||||
cmd->low_length = num_blocks & 0xff;
|
cmd->low_length = num_blocks & 0xff;
|
||||||
|
|
||||||
request->cdb_len = sizeof( *cmd );
|
request->cdb_len = sizeof(*cmd);
|
||||||
}
|
}
|
||||||
|
|
||||||
// last chance to detect errors that occured during concurrent accesses
|
// last chance to detect errors that occured during concurrent accesses
|
||||||
err = handle->pending_error;
|
err = handle->pending_error;
|
||||||
|
if (err)
|
||||||
if( err )
|
|
||||||
goto abort;
|
goto abort;
|
||||||
|
|
||||||
device->scsi->scsi_io( request );
|
device->scsi->scsi_io(request);
|
||||||
|
|
||||||
acquire_sem( request->completion_sem );
|
acquire_sem(request->completion_sem);
|
||||||
|
|
||||||
// ask generic peripheral layer what to do now
|
// ask generic peripheral layer what to do now
|
||||||
res = scsi_periph->check_error( device->scsi_periph_device, request );
|
res = scsi_periph->check_error(device->scsi_periph_device, request);
|
||||||
|
|
||||||
switch( res.action ) {
|
switch (res.action) {
|
||||||
case err_act_ok:
|
case err_act_ok:
|
||||||
*bytes_transferred = num_bytes - request->data_resid;
|
*bytes_transferred = num_bytes - request->data_resid;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case err_act_start:
|
case err_act_start:
|
||||||
res = scsi_periph->send_start_stop(
|
res = scsi_periph->send_start_stop(device->scsi_periph_device,
|
||||||
device->scsi_periph_device, request, 1, device->removable );
|
request, 1, device->removable);
|
||||||
if( res.action == err_act_ok )
|
if (res.action == err_act_ok)
|
||||||
res.action = err_act_retry;
|
res.action = err_act_retry;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case err_act_invalid_req:
|
case err_act_invalid_req:
|
||||||
// if this was a 10 byte command, the device probably doesn't
|
// if this was a 10 byte command, the device probably doesn't
|
||||||
// support them, so disable them and retry
|
// support them, so disable them and retry
|
||||||
if( is_rw10 ) {
|
if (is_rw10) {
|
||||||
atomic_and( &device->rw10_enabled, 0 );
|
atomic_and(&device->rw10_enabled, 0);
|
||||||
res.action = err_act_retry;
|
res.action = err_act_retry;
|
||||||
} else
|
} else
|
||||||
res.action = err_act_fail;
|
res.action = err_act_fail;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
} while ((res.action == err_act_retry && retries++ < 3)
|
||||||
} while(
|
|| (res.action == err_act_many_retries && retries++ < 30));
|
||||||
(res.action == err_act_retry && retries++ < 3) ||
|
|
||||||
(res.action == err_act_many_retries && retries++ < 30 ));
|
device->scsi->free_ccb(request);
|
||||||
|
|
||||||
device->scsi->free_ccb( request );
|
|
||||||
|
|
||||||
// peripheral layer only created "read" error, so we have to
|
// peripheral layer only created "read" error, so we have to
|
||||||
// map them to "write" errors if this was a write request
|
// map them to "write" errors if this was a write request
|
||||||
if( res.error_code == B_DEV_READ_ERROR && write )
|
if (res.error_code == B_DEV_READ_ERROR && write)
|
||||||
return B_DEV_WRITE_ERROR;
|
return B_DEV_WRITE_ERROR;
|
||||||
else
|
|
||||||
return res.error_code;
|
return res.error_code;
|
||||||
|
|
||||||
abort:
|
abort:
|
||||||
device->scsi->free_ccb( request );
|
device->scsi->free_ccb(request);
|
||||||
|
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// kernel daemon
|
/** kernel daemon
|
||||||
// once in a minute, it sets a flag so that the next command is executed
|
* once in a minute, it sets a flag so that the next command is executed
|
||||||
// ordered; this way, we avoid starvation of SCSI commands inside the
|
* ordered; this way, we avoid starvation of SCSI commands inside the
|
||||||
// SCSI queuing system - the ordered command waits for all previous
|
* SCSI queuing system - the ordered command waits for all previous
|
||||||
// commands and thus no command can starve longer then a minute
|
* commands and thus no command can starve longer then a minute
|
||||||
void das_sync_queue_daemon( void *arg, int iteration )
|
*/
|
||||||
|
|
||||||
|
void
|
||||||
|
das_sync_queue_daemon(void *arg, int iteration)
|
||||||
{
|
{
|
||||||
das_device_info *device = (das_device_info *)arg;
|
das_device_info *device = (das_device_info *)arg;
|
||||||
|
|
||||||
atomic_or( &device->next_tag_action, SCSI_ORDERED_QTAG );
|
atomic_or(&device->next_tag_action, SCSI_ORDERED_QTAG);
|
||||||
}
|
}
|
||||||
|
|
||||||
void das_handle_set_error( das_handle_info *handle, status_t error_code )
|
|
||||||
|
void
|
||||||
|
das_handle_set_error(das_handle_info *handle, status_t errorCode)
|
||||||
{
|
{
|
||||||
handle->pending_error = error_code;
|
handle->pending_error = errorCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
status_t das_handle_get_error( das_handle_info *handle )
|
status_t
|
||||||
|
das_handle_get_error(das_handle_info *handle)
|
||||||
{
|
{
|
||||||
return handle->pending_error;
|
return handle->pending_error;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -43,7 +43,7 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef debug_level_flow
|
#ifndef debug_level_flow
|
||||||
# define debug_level_flow 3
|
# define debug_level_flow 1
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef debug_level_info
|
#ifndef debug_level_info
|
||||||
@@ -51,7 +51,7 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef debug_level_error
|
#ifndef debug_level_error
|
||||||
# define debug_level_error 1
|
# define debug_level_error 3
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define FUNC_NAME DEBUG_MSG_PREFIX __FUNCTION__ ": "
|
#define FUNC_NAME DEBUG_MSG_PREFIX __FUNCTION__ ": "
|
||||||
|
|||||||
Reference in New Issue
Block a user