Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Data Structures | Macros | Functions | Variables
scsi_lib.c File Reference
#include <linux/bio.h>
#include <linux/bitops.h>
#include <linux/blkdev.h>
#include <linux/completion.h>
#include <linux/kernel.h>
#include <linux/export.h>
#include <linux/mempool.h>
#include <linux/slab.h>
#include <linux/init.h>
#include <linux/pci.h>
#include <linux/delay.h>
#include <linux/hardirq.h>
#include <linux/scatterlist.h>
#include <scsi/scsi.h>
#include <scsi/scsi_cmnd.h>
#include <scsi/scsi_dbg.h>
#include <scsi/scsi_device.h>
#include <scsi/scsi_driver.h>
#include <scsi/scsi_eh.h>
#include <scsi/scsi_host.h>
#include "scsi_priv.h"
#include "scsi_logging.h"

Go to the source code of this file.

Data Structures

struct  scsi_host_sg_pool
 

Macros

#define SG_MEMPOOL_NR   ARRAY_SIZE(scsi_sg_pools)
 
#define SG_MEMPOOL_SIZE   2
 
#define SP(x)   { x, "sgpool-" __stringify(x) }
 
#define SCSI_QUEUE_DELAY   3
 

Functions

void scsi_queue_insert (struct scsi_cmnd *cmd, int reason)
 
int scsi_execute (struct scsi_device *sdev, const unsigned char *cmd, int data_direction, void *buffer, unsigned bufflen, unsigned char *sense, int timeout, int retries, int flags, int *resid)
 
 EXPORT_SYMBOL (scsi_execute)
 
int scsi_execute_req (struct scsi_device *sdev, const unsigned char *cmd, int data_direction, void *buffer, unsigned bufflen, struct scsi_sense_hdr *sshdr, int timeout, int retries, int *resid)
 
 EXPORT_SYMBOL (scsi_execute_req)
 
void scsi_device_unbusy (struct scsi_device *sdev)
 
void scsi_requeue_run_queue (struct work_struct *work)
 
void scsi_next_command (struct scsi_cmnd *cmd)
 
void scsi_run_host_queues (struct Scsi_Host *shost)
 
void scsi_release_buffers (struct scsi_cmnd *cmd)
 
 EXPORT_SYMBOL (scsi_release_buffers)
 
void scsi_io_completion (struct scsi_cmnd *cmd, unsigned int good_bytes)
 
int scsi_init_io (struct scsi_cmnd *cmd, gfp_t gfp_mask)
 
 EXPORT_SYMBOL (scsi_init_io)
 
int scsi_setup_blk_pc_cmnd (struct scsi_device *sdev, struct request *req)
 
 EXPORT_SYMBOL (scsi_setup_blk_pc_cmnd)
 
int scsi_setup_fs_cmnd (struct scsi_device *sdev, struct request *req)
 
 EXPORT_SYMBOL (scsi_setup_fs_cmnd)
 
int scsi_prep_state_check (struct scsi_device *sdev, struct request *req)
 
 EXPORT_SYMBOL (scsi_prep_state_check)
 
int scsi_prep_return (struct request_queue *q, struct request *req, int ret)
 
 EXPORT_SYMBOL (scsi_prep_return)
 
int scsi_prep_fn (struct request_queue *q, struct request *req)
 
 EXPORT_SYMBOL (scsi_prep_fn)
 
u64 scsi_calculate_bounce_limit (struct Scsi_Host *shost)
 
 EXPORT_SYMBOL (scsi_calculate_bounce_limit)
 
struct request_queue__scsi_alloc_queue (struct Scsi_Host *shost, request_fn_proc *request_fn)
 
 EXPORT_SYMBOL (__scsi_alloc_queue)
 
struct request_queuescsi_alloc_queue (struct scsi_device *sdev)
 
void scsi_block_requests (struct Scsi_Host *shost)
 
 EXPORT_SYMBOL (scsi_block_requests)
 
void scsi_unblock_requests (struct Scsi_Host *shost)
 
 EXPORT_SYMBOL (scsi_unblock_requests)
 
int __init scsi_init_queue (void)
 
void scsi_exit_queue (void)
 
int scsi_mode_select (struct scsi_device *sdev, int pf, int sp, int modepage, unsigned char *buffer, int len, int timeout, int retries, struct scsi_mode_data *data, struct scsi_sense_hdr *sshdr)
 
 EXPORT_SYMBOL_GPL (scsi_mode_select)
 
int scsi_mode_sense (struct scsi_device *sdev, int dbd, int modepage, unsigned char *buffer, int len, int timeout, int retries, struct scsi_mode_data *data, struct scsi_sense_hdr *sshdr)
 
 EXPORT_SYMBOL (scsi_mode_sense)
 
int scsi_test_unit_ready (struct scsi_device *sdev, int timeout, int retries, struct scsi_sense_hdr *sshdr_external)
 
 EXPORT_SYMBOL (scsi_test_unit_ready)
 
int scsi_device_set_state (struct scsi_device *sdev, enum scsi_device_state state)
 
 EXPORT_SYMBOL (scsi_device_set_state)
 
void scsi_evt_thread (struct work_struct *work)
 
void sdev_evt_send (struct scsi_device *sdev, struct scsi_event *evt)
 
 EXPORT_SYMBOL_GPL (sdev_evt_send)
 
struct scsi_eventsdev_evt_alloc (enum scsi_device_event evt_type, gfp_t gfpflags)
 
 EXPORT_SYMBOL_GPL (sdev_evt_alloc)
 
void sdev_evt_send_simple (struct scsi_device *sdev, enum scsi_device_event evt_type, gfp_t gfpflags)
 
 EXPORT_SYMBOL_GPL (sdev_evt_send_simple)
 
int scsi_device_quiesce (struct scsi_device *sdev)
 
 EXPORT_SYMBOL (scsi_device_quiesce)
 
void scsi_device_resume (struct scsi_device *sdev)
 
 EXPORT_SYMBOL (scsi_device_resume)
 
void scsi_target_quiesce (struct scsi_target *starget)
 
 EXPORT_SYMBOL (scsi_target_quiesce)
 
void scsi_target_resume (struct scsi_target *starget)
 
 EXPORT_SYMBOL (scsi_target_resume)
 
int scsi_internal_device_block (struct scsi_device *sdev)
 
 EXPORT_SYMBOL_GPL (scsi_internal_device_block)
 
int scsi_internal_device_unblock (struct scsi_device *sdev, enum scsi_device_state new_state)
 
 EXPORT_SYMBOL_GPL (scsi_internal_device_unblock)
 
void scsi_target_block (struct device *dev)
 
 EXPORT_SYMBOL_GPL (scsi_target_block)
 
void scsi_target_unblock (struct device *dev, enum scsi_device_state new_state)
 
 EXPORT_SYMBOL_GPL (scsi_target_unblock)
 
voidscsi_kmap_atomic_sg (struct scatterlist *sgl, int sg_count, size_t *offset, size_t *len)
 
 EXPORT_SYMBOL (scsi_kmap_atomic_sg)
 
void scsi_kunmap_atomic_sg (void *virt)
 
 EXPORT_SYMBOL (scsi_kunmap_atomic_sg)
 

Variables

struct kmem_cachescsi_sdb_cache
 

Macro Definition Documentation

#define SCSI_QUEUE_DELAY   3

Definition at line 93 of file scsi_lib.c.

#define SG_MEMPOOL_NR   ARRAY_SIZE(scsi_sg_pools)

Definition at line 36 of file scsi_lib.c.

#define SG_MEMPOOL_SIZE   2

Definition at line 37 of file scsi_lib.c.

#define SP (   x)    { x, "sgpool-" __stringify(x) }

Definition at line 46 of file scsi_lib.c.

Function Documentation

struct request_queue* __scsi_alloc_queue ( struct Scsi_Host shost,
request_fn_proc *  request_fn 
)
read

Definition at line 1673 of file scsi_lib.c.

EXPORT_SYMBOL ( scsi_execute  )
EXPORT_SYMBOL ( scsi_execute_req  )
EXPORT_SYMBOL ( scsi_release_buffers  )
EXPORT_SYMBOL ( scsi_init_io  )
EXPORT_SYMBOL ( scsi_setup_blk_pc_cmnd  )
EXPORT_SYMBOL ( scsi_setup_fs_cmnd  )
EXPORT_SYMBOL ( scsi_prep_state_check  )
EXPORT_SYMBOL ( scsi_prep_return  )
EXPORT_SYMBOL ( scsi_prep_fn  )
EXPORT_SYMBOL ( scsi_calculate_bounce_limit  )
EXPORT_SYMBOL ( __scsi_alloc_queue  )
EXPORT_SYMBOL ( scsi_block_requests  )
EXPORT_SYMBOL ( scsi_unblock_requests  )
EXPORT_SYMBOL ( scsi_mode_sense  )
EXPORT_SYMBOL ( scsi_test_unit_ready  )
EXPORT_SYMBOL ( scsi_device_set_state  )
EXPORT_SYMBOL ( scsi_device_quiesce  )
EXPORT_SYMBOL ( scsi_device_resume  )
EXPORT_SYMBOL ( scsi_target_quiesce  )
EXPORT_SYMBOL ( scsi_target_resume  )
EXPORT_SYMBOL ( scsi_kmap_atomic_sg  )
EXPORT_SYMBOL ( scsi_kunmap_atomic_sg  )
EXPORT_SYMBOL_GPL ( scsi_mode_select  )
EXPORT_SYMBOL_GPL ( sdev_evt_send  )
EXPORT_SYMBOL_GPL ( sdev_evt_alloc  )
EXPORT_SYMBOL_GPL ( sdev_evt_send_simple  )
EXPORT_SYMBOL_GPL ( scsi_internal_device_block  )
EXPORT_SYMBOL_GPL ( scsi_internal_device_unblock  )
EXPORT_SYMBOL_GPL ( scsi_target_block  )
EXPORT_SYMBOL_GPL ( scsi_target_unblock  )
struct request_queue* scsi_alloc_queue ( struct scsi_device sdev)
read

Definition at line 1718 of file scsi_lib.c.

void scsi_block_requests ( struct Scsi_Host shost)

Definition at line 1749 of file scsi_lib.c.

u64 scsi_calculate_bounce_limit ( struct Scsi_Host shost)

Definition at line 1651 of file scsi_lib.c.

int scsi_device_quiesce ( struct scsi_device sdev)

scsi_device_quiesce - Block user issued commands. : scsi device to quiesce.

This works by trying to transition to the SDEV_QUIESCE state (which must be a legal transition). When the device is in this state, only special requests will be accepted, all others will be deferred. Since special requests may also be requeued requests, a successful return doesn't guarantee the device will be totally quiescent.

Must be called with user context, may sleep.

Returns zero if unsuccessful or an error if not.

Definition at line 2354 of file scsi_lib.c.

void scsi_device_resume ( struct scsi_device sdev)

scsi_device_resume - Restart user issued commands to a quiesced device. : scsi device to resume.

Moves the device from quiesced back to running and restarts the queues.

Must be called with user context, may sleep.

Definition at line 2378 of file scsi_lib.c.

int scsi_device_set_state ( struct scsi_device sdev,
enum scsi_device_state  state 
)

scsi_device_set_state - Take the given device through the device state model. : scsi device to change the state of. : state to change to.

Returns zero if unsuccessful or an error if the requested transition is illegal.

Definition at line 2082 of file scsi_lib.c.

void scsi_device_unbusy ( struct scsi_device sdev)

Definition at line 318 of file scsi_lib.c.

void scsi_evt_thread ( struct work_struct work)

sdev_evt_thread - send a uevent for each scsi event : work struct for scsi_device

Dispatch queued events to their associated scsi_device kobjects as uevents.

Definition at line 2231 of file scsi_lib.c.

int scsi_execute ( struct scsi_device sdev,
const unsigned char cmd,
int  data_direction,
void buffer,
unsigned  bufflen,
unsigned char sense,
int  timeout,
int  retries,
int  flags,
int resid 
)

scsi_execute - insert request and wait for the result : scsi device : scsi command : data direction : data buffer : len of buffer : optional sense buffer : request timeout in seconds : number of times to retry request : or into request flags; : optional residual length

returns the req->errors value which is the scsi_cmnd result field.

Definition at line 224 of file scsi_lib.c.

int scsi_execute_req ( struct scsi_device sdev,
const unsigned char cmd,
int  data_direction,
void buffer,
unsigned  bufflen,
struct scsi_sense_hdr sshdr,
int  timeout,
int  retries,
int resid 
)

Definition at line 275 of file scsi_lib.c.

void scsi_exit_queue ( void  )

Definition at line 1830 of file scsi_lib.c.

int scsi_init_io ( struct scsi_cmnd cmd,
gfp_t  gfp_mask 
)

Definition at line 1045 of file scsi_lib.c.

int __init scsi_init_queue ( void  )

Definition at line 1782 of file scsi_lib.c.

int scsi_internal_device_block ( struct scsi_device sdev)

scsi_internal_device_block - internal function to put a device temporarily into the SDEV_BLOCK state : device to block

Block request made by scsi lld's to temporarily stop all scsi commands on the specified device. Called from interrupt or normal process context.

Returns zero if successful or error if not

Notes: This routine transitions the device to the SDEV_BLOCK state (which must be a legal transition). When the device is in this state, all commands are deferred until the scsi lld reenables the device with scsi_device_unblock or device_block_tmo fires.

Definition at line 2434 of file scsi_lib.c.

int scsi_internal_device_unblock ( struct scsi_device sdev,
enum scsi_device_state  new_state 
)

scsi_internal_device_unblock - resume a device after a block request : device to resume : state to set devices to after unblocking

Called by scsi lld's or the midlayer to restart the device queue for the previously suspended scsi device. Called from interrupt or normal process context.

Returns zero if successful or error if not.

Notes: This routine transitions the device to the SDEV_RUNNING state or to one of the offline states (which must be a legal transition) allowing the midlayer to goose the queue for this device.

Definition at line 2478 of file scsi_lib.c.

void scsi_io_completion ( struct scsi_cmnd cmd,
unsigned int  good_bytes 
)

Definition at line 759 of file scsi_lib.c.

void* scsi_kmap_atomic_sg ( struct scatterlist sgl,
int  sg_count,
size_t offset,
size_t len 
)

scsi_kmap_atomic_sg - find and atomically map an sg-elemnt : scatter-gather list : number of segments in sg : offset in bytes into sg, on return offset into the mapped area : bytes to map, on return number of bytes mapped

Returns virtual address of the start of the mapped page

Definition at line 2570 of file scsi_lib.c.

void scsi_kunmap_atomic_sg ( void virt)

scsi_kunmap_atomic_sg - atomically unmap a virtual address, previously mapped with scsi_kmap_atomic_sg : virtual address to be unmapped

Definition at line 2615 of file scsi_lib.c.

int scsi_mode_select ( struct scsi_device sdev,
int  pf,
int  sp,
int  modepage,
unsigned char buffer,
int  len,
int  timeout,
int  retries,
struct scsi_mode_data data,
struct scsi_sense_hdr sshdr 
)

scsi_mode_select - issue a mode select : SCSI device to be queried : Page format bit (1 == standard, 0 == vendor specific) : Save page bit (0 == don't save, 1 == save) : mode page being requested : request buffer (may not be smaller than eight bytes) : length of request buffer. : command timeout : number of retries before failing : returns a structure abstracting the mode header data : place to put sense data (or NULL if no sense to be collected). must be SCSI_SENSE_BUFFERSIZE big.

Returns zero if successful; negative error number or scsi status on error

Definition at line 1862 of file scsi_lib.c.

int scsi_mode_sense ( struct scsi_device sdev,
int  dbd,
int  modepage,
unsigned char buffer,
int  len,
int  timeout,
int  retries,
struct scsi_mode_data data,
struct scsi_sense_hdr sshdr 
)

scsi_mode_sense - issue a mode sense, falling back from 10 to six bytes if necessary. : SCSI device to be queried : set if mode sense will allow block descriptors to be returned : mode page being requested : request buffer (may not be smaller than eight bytes) : length of request buffer. : command timeout : number of retries before failing : returns a structure abstracting the mode header data : place to put sense data (or NULL if no sense to be collected). must be SCSI_SENSE_BUFFERSIZE big.

Returns zero if unsuccessful, or the header offset (either 4 or 8 depending on whether a six or ten byte command was issued) if successful.

Definition at line 1938 of file scsi_lib.c.

void scsi_next_command ( struct scsi_cmnd cmd)

Definition at line 520 of file scsi_lib.c.

int scsi_prep_fn ( struct request_queue q,
struct request req 
)

Definition at line 1289 of file scsi_lib.c.

int scsi_prep_return ( struct request_queue q,
struct request req,
int  ret 
)

Definition at line 1257 of file scsi_lib.c.

int scsi_prep_state_check ( struct scsi_device sdev,
struct request req 
)

Definition at line 1203 of file scsi_lib.c.

void scsi_queue_insert ( struct scsi_cmnd cmd,
int  reason 
)

Definition at line 204 of file scsi_lib.c.

void scsi_release_buffers ( struct scsi_cmnd cmd)

Definition at line 693 of file scsi_lib.c.

void scsi_requeue_run_queue ( struct work_struct work)

Definition at line 468 of file scsi_lib.c.

void scsi_run_host_queues ( struct Scsi_Host shost)

Definition at line 535 of file scsi_lib.c.

int scsi_setup_blk_pc_cmnd ( struct scsi_device sdev,
struct request req 
)

Definition at line 1122 of file scsi_lib.c.

int scsi_setup_fs_cmnd ( struct scsi_device sdev,
struct request req 
)

Definition at line 1174 of file scsi_lib.c.

void scsi_target_block ( struct device dev)

Definition at line 2525 of file scsi_lib.c.

void scsi_target_quiesce ( struct scsi_target starget)

Definition at line 2398 of file scsi_lib.c.

void scsi_target_resume ( struct scsi_target starget)

Definition at line 2411 of file scsi_lib.c.

void scsi_target_unblock ( struct device dev,
enum scsi_device_state  new_state 
)

Definition at line 2551 of file scsi_lib.c.

int scsi_test_unit_ready ( struct scsi_device sdev,
int  timeout,
int  retries,
struct scsi_sense_hdr sshdr_external 
)

scsi_test_unit_ready - test if unit is ready : scsi device to change the state of. : command timeout : number of retries before failing : Optional pointer to struct scsi_sense_hdr for returning sense. Make sure that this is cleared before passing in.

Returns zero if unsuccessful or an error if TUR failed. For removable media, UNIT_ATTENTION sets ->changed flag.

Definition at line 2043 of file scsi_lib.c.

void scsi_unblock_requests ( struct Scsi_Host shost)

Definition at line 1775 of file scsi_lib.c.

struct scsi_event* sdev_evt_alloc ( enum scsi_device_event  evt_type,
gfp_t  gfpflags 
)
read

sdev_evt_alloc - allocate a new scsi event : type of event to allocate : GFP flags for allocation

Allocates and returns a new scsi_event.

Definition at line 2294 of file scsi_lib.c.

void sdev_evt_send ( struct scsi_device sdev,
struct scsi_event evt 
)

sdev_evt_send - send asserted event to uevent thread : scsi_device event occurred on : event to send

Assert scsi device event asynchronously.

Definition at line 2266 of file scsi_lib.c.

void sdev_evt_send_simple ( struct scsi_device sdev,
enum scsi_device_event  evt_type,
gfp_t  gfpflags 
)

sdev_evt_send_simple - send asserted event to uevent thread : scsi_device event occurred on : type of event to send : GFP flags for allocation

Assert scsi device event asynchronously, given an event type.

Definition at line 2324 of file scsi_lib.c.

Variable Documentation

struct kmem_cache* scsi_sdb_cache

Definition at line 69 of file scsi_lib.c.