scsi.h

来自「基于组件方式开发操作系统的OSKIT源代码」· C头文件 代码 · 共 782 行 · 第 1/2 页

H
782
字号
			 void (*done)(struct scsi_cmnd *),			 int timeout, int retries);extern Scsi_Cmnd * scsi_allocate_device(struct request **, Scsi_Device *, int);extern Scsi_Cmnd * scsi_request_queueable(struct request *, Scsi_Device *);extern void scsi_release_command(Scsi_Cmnd *);extern int max_scsi_hosts;extern void proc_print_scsidevice(Scsi_Device *, char *, int *, int);extern void print_command(unsigned char *);extern void print_sense(const char *, Scsi_Cmnd *);extern void print_driverbyte(int scsiresult);extern void print_hostbyte(int scsiresult);/* *  The scsi_device struct contains what we know about each given scsi *  device. */struct scsi_device {/* private: */    /*     * This information is private to the scsi mid-layer.  Wrapping it in a     * struct private is a way of marking it in a sort of C++ type of way.     */    struct scsi_device * next;      /* Used for linked list */    struct scsi_device * prev;      /* Used for linked list */    struct wait_queue  * device_wait;/* Used to wait if                                                      device is busy */    struct Scsi_Host   * host;    volatile unsigned short device_busy;   /* commands actually active on low-level */    void              (* scsi_request_fn)(void);  /* Used to jumpstart things after an                                      * ioctl */    Scsi_Cmnd          * device_queue;    /* queue of SCSI Command structures *//* public: */    unsigned char id, lun, channel;    unsigned int manufacturer;      /* Manufacturer of device, for using 				     * vendor-specific cmd's */    int attached;                   /* # of high level drivers attached to 				     * this */    int access_count;               /* Count of open channels/mounts */    void *hostdata;                 /* available to low-level driver */    char type;    char scsi_level;    char vendor[8], model[16], rev[4];    unsigned char current_tag;      /* current tag */    unsigned char sync_min_period;  /* Not less than this period */    unsigned char sync_max_offset;  /* Not greater than this offset */    unsigned char queue_depth;	    /* How deep a queue to use */    unsigned online:1;    unsigned writeable:1;    unsigned removable:1;     unsigned random:1;    unsigned has_cmdblocks:1;    unsigned changed:1;             /* Data invalid due to media change */    unsigned busy:1;                /* Used to prevent races */    unsigned lockable:1;            /* Able to prevent media removal */    unsigned borken:1;              /* Tell the Seagate driver to be 				     * painfully slow on this device */     unsigned tagged_supported:1;    /* Supports SCSI-II tagged queuing */    unsigned tagged_queue:1;        /* SCSI-II tagged queuing enabled */    unsigned disconnect:1;          /* can disconnect */    unsigned soft_reset:1;          /* Uses soft reset option */    unsigned sync:1;                /* Negotiate for sync transfers */    unsigned wide:1;                /* Negotiate for WIDE transfers */    unsigned single_lun:1;          /* Indicates we should only allow I/O to                                     * one of the luns for the device at a                                      * time. */    unsigned was_reset:1;           /* There was a bus reset on the bus for                                      * this device */    unsigned expecting_cc_ua:1;     /* Expecting a CHECK_CONDITION/UNIT_ATTN                                     * because we did a bus reset. */    unsigned device_blocked:1;      /* Device returned QUEUE_FULL. */};/* * The Scsi_Cmnd structure is used by scsi.c internally, and for communication * with low level drivers that support multiple outstanding commands. */typedef struct scsi_pointer {    char * ptr;                     /* data pointer */    int this_residual;              /* left in this buffer */    struct scatterlist *buffer;     /* which buffer */    int buffers_residual;           /* how many buffers left */        volatile int Status;    volatile int Message;    volatile int have_data_in;    volatile int sent_command;    volatile int phase;} Scsi_Pointer;struct scsi_cmnd {/* private: */    /*     * This information is private to the scsi mid-layer.  Wrapping it in a     * struct private is a way of marking it in a sort of C++ type of way.     */    struct Scsi_Host * host;    unsigned short     state;    unsigned short     owner;    Scsi_Device      * device;    struct scsi_cmnd * next;    struct scsi_cmnd * reset_chain;        int                 eh_state; /* Used for state tracking in error handlr */    void               (*done)(struct scsi_cmnd *);  /* Mid-level done function */    /*      A SCSI Command is assigned a nonzero serial_number when internal_cmnd      passes it to the driver's queue command function.  The serial_number      is cleared when scsi_done is entered indicating that the command has      been completed.  If a timeout occurs, the serial number at the moment      of timeout is copied into serial_number_at_timeout.  By subsequently      comparing the serial_number and serial_number_at_timeout fields      during abort or reset processing, we can detect whether the command      has already completed.  This also detects cases where the command has      completed and the SCSI Command structure has already being reused      for another command, so that we can avoid incorrectly aborting or      resetting the new command.      */        unsigned long      serial_number;    unsigned long      serial_number_at_timeout;        int                retries;    int                allowed;    int                timeout_per_command;    int                timeout_total;    int                timeout;        /*     * We handle the timeout differently if it happens when a reset,      * abort, etc are in process.      */    unsigned volatile char internal_timeout;    struct scsi_cmnd  * bh_next;  /* To enumerate the commands waiting                                      to be processed. */    /* public: */    unsigned char      target;    unsigned char      lun;    unsigned char      channel;    unsigned char      cmd_len;    unsigned char      old_cmd_len;    /* These elements define the operation we are about to perform */    unsigned char      cmnd[12];    unsigned           request_bufflen;	/* Actual request size */        struct timer_list  eh_timeout;         /* Used to time out the command. */    void             * request_buffer;	/* Actual requested buffer */        /* These elements define the operation we ultimately want to perform */    unsigned char      data_cmnd[12];    unsigned short     old_use_sg;	/* We save  use_sg here when requesting                                         * sense info */    unsigned short     use_sg;          /* Number of pieces of scatter-gather */    unsigned short     sglist_len;	/* size of malloc'd scatter-gather list */    unsigned short     abort_reason;    /* If the mid-level code requests an                                         * abort, this is the reason. */    unsigned           bufflen;		/* Size of data buffer */    void             * buffer;		/* Data buffer */        unsigned           underflow;	/* Return error if less than                                           this amount is transfered */        unsigned           transfersize;	/* How much we are guaranteed to                                           transfer with each SCSI transfer                                           (ie, between disconnect /                                            reconnects.	 Probably == sector                                           size */            struct request     request;           /* A copy of the command we are                                             working on */    unsigned char      sense_buffer[16];  /* Sense for this command,                                              needed */        unsigned           flags;        /*     * These two flags are used to track commands that are in the     * mid-level queue.  The idea is that a command can be there for     * one of two reasons - either the host is busy or the device is     * busy.  Thus when a command on the host finishes, we only try     * and requeue commands that we might expect to be queueable.     */    unsigned           host_wait:1;    unsigned           device_wait:1;    /* These variables are for the cdrom only. Once we have variable size      * buffers in the buffer cache, they will go away. */    int                this_count;     /* End of special cdrom variables */        /* Low-level done function - can be used by low-level driver to point     *	to completion function.	 Not used by mid/upper level code. */    void               (*scsi_done)(struct scsi_cmnd *);          /*     * The following fields can be written to by the host specific code.      * Everything else should be left alone.      */        Scsi_Pointer       SCp;	   /* Scratchpad used by some host adapters */        unsigned char    * host_scribble; /* The host adapter is allowed to				    * call scsi_malloc and get some memory				    * and hang it here.	 The host adapter				    * is also expected to call scsi_free				    * to release this memory.  (The memory				    * obtained by scsi_malloc is guaranteed				    * to be at an address < 16Mb). */        int                result;	   /* Status code from lower level driver */        unsigned char      tag;	   /* SCSI-II queued command tag */    unsigned long      pid;	   /* Process ID, starts at 0 */};/* * Definitions and prototypes used for scsi mid-level queue. */#define SCSI_MLQUEUE_HOST_BUSY   0x1055#define SCSI_MLQUEUE_DEVICE_BUSY 0x1056extern int scsi_mlqueue_insert(Scsi_Cmnd * cmd, int reason);extern int scsi_mlqueue_finish(struct Scsi_Host * host, Scsi_Device * device);#if defined(MAJOR_NR) && (MAJOR_NR != SCSI_TAPE_MAJOR)#include "hosts.h"static Scsi_Cmnd * end_scsi_request(Scsi_Cmnd * SCpnt, int uptodate, int sectors){    struct request * req;    struct buffer_head * bh;        req = &SCpnt->request;    req->errors = 0;    if (!uptodate) {	printk(DEVICE_NAME " I/O error: dev %s, sector %lu\n",	       kdevname(req->rq_dev), req->sector);#ifdef OSKIT        req->errors = 1;        while (req->bh) {            bh = req->bh;            req->bh = bh->b_reqnext;            mark_buffer_uptodate(bh, 0);            unlock_buffer(bh);        }        goto done;#endif    }        do {	if ((bh = req->bh) != NULL) {	    req->bh = bh->b_reqnext;	    req->nr_sectors -= bh->b_size >> 9;	    req->sector += bh->b_size >> 9;	    bh->b_reqnext = NULL;#ifdef OSKIT            mark_buffer_uptodate(bh, uptodate);		            unlock_buffer(bh);#else	    bh->b_end_io(bh, uptodate);#endif	    sectors -= bh->b_size >> 9;	    if ((bh = req->bh) != NULL) {		req->current_nr_sectors = bh->b_size >> 9;		if (req->nr_sectors < req->current_nr_sectors) {		    req->nr_sectors = req->current_nr_sectors;		    printk("end_scsi_request: buffer-list destroyed\n");		}	    }	}    } while(sectors && bh);    if (req->bh){	req->buffer = bh->b_data;	return SCpnt;    }#ifdef OSKIT    req->errors = 0;done:#endif    DEVICE_OFF(req->rq_dev);    if (req->sem != NULL) {	up(req->sem);    }    add_blkdev_randomness(MAJOR(req->rq_dev));        if (SCpnt->host->block) {	struct Scsi_Host * next;		for (next = SCpnt->host->block; next != SCpnt->host;	     next = next->block)	    wake_up(&next->host_wait);    }        wake_up(&wait_for_request);    wake_up(&SCpnt->device->device_wait);    scsi_release_command(SCpnt);    return NULL;}/* This is just like INIT_REQUEST, but we need to be aware of the fact * that an interrupt may start another request, so we run this with interrupts * turned off  */#if MAJOR_NR == SCSI_DISK0_MAJOR#define CHECK_INITREQ_SD_MAJOR(major) SCSI_DISK_MAJOR(major)#else#define CHECK_INITREQ_SD_MAJOR(major) ((major) == MAJOR_NR)#endif#define INIT_SCSI_REQUEST       			\    if (!CURRENT) {             			\	CLEAR_INTR;             			\	return;                 			\    }                           			\    if (!CHECK_INITREQ_SD_MAJOR(MAJOR(CURRENT->rq_dev)))\	panic(DEVICE_NAME ": request list destroyed");	\    if (CURRENT->bh) {                                	\	if (!buffer_locked(CURRENT->bh))              	\	    panic(DEVICE_NAME ": block not locked");  	\    }#endif#ifndef OSKIT#define SCSI_SLEEP(QUEUE, CONDITION) {		    \    if (CONDITION) {			            \	struct wait_queue wait = { current, NULL};  \	add_wait_queue(QUEUE, &wait);		    \	for(;;) {			            \	current->state = TASK_UNINTERRUPTIBLE;	    \	if (CONDITION) {		            \            if (in_interrupt())	                    \	        panic("scsi: trying to call schedule() in interrupt" \		      ", file %s, line %d.\n", __FILE__, __LINE__);  \	    schedule();			\        }				\	else			        \	    break;      		\	}			        \	remove_wait_queue(QUEUE, &wait);\	current->state = TASK_RUNNING;	\    }; }#else /* OSKIT */#define SCSI_SLEEP(QUEUE, CONDITION) {		    \	if (CONDITION)				    \		printk(KERN_ALERT "SCSI NEEDS SCSI_SLEEP NOW!\n"); \	}#endif /* OSKIT */#endif/* * Overrides for Emacs so that we follow Linus's tabbing style. * Emacs will notice this stuff at the end of the file and automatically * adjust the settings for this buffer only.  This must remain at the end * of the file. * --------------------------------------------------------------------------- * Local variables: * c-indent-level: 4  * c-brace-imaginary-offset: 0 * c-brace-offset: -4 * c-argdecl-indent: 4 * c-label-offset: -4 * c-continued-statement-offset: 4 * c-continued-brace-offset: 0 * indent-tabs-mode: nil * tab-width: 8 * End: */

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?