Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Data Structures | Macros | Functions | Variables
scsi.c File Reference
#include <linux/module.h>
#include <linux/moduleparam.h>
#include <linux/kernel.h>
#include <linux/timer.h>
#include <linux/string.h>
#include <linux/slab.h>
#include <linux/blkdev.h>
#include <linux/delay.h>
#include <linux/init.h>
#include <linux/completion.h>
#include <linux/unistd.h>
#include <linux/spinlock.h>
#include <linux/kmod.h>
#include <linux/interrupt.h>
#include <linux/notifier.h>
#include <linux/cpu.h>
#include <linux/mutex.h>
#include <linux/async.h>
#include <asm/unaligned.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/scsi_tcq.h>
#include "scsi_priv.h"
#include "scsi_logging.h"
#include <trace/events/scsi.h>

Go to the source code of this file.

Data Structures

struct  scsi_host_cmd_pool
 

Macros

#define CREATE_TRACE_POINTS
 
#define MIN_RESET_DELAY   (2*HZ)
 
#define MIN_RESET_PERIOD   (15*HZ)
 

Functions

 ASYNC_DOMAIN (scsi_sd_probe_domain)
 
 EXPORT_SYMBOL (scsi_sd_probe_domain)
 
const charscsi_device_type (unsigned type)
 
 EXPORT_SYMBOL (scsi_device_type)
 
struct scsi_cmnd__scsi_get_command (struct Scsi_Host *shost, gfp_t gfp_mask)
 
 EXPORT_SYMBOL_GPL (__scsi_get_command)
 
struct scsi_cmndscsi_get_command (struct scsi_device *dev, gfp_t gfp_mask)
 
 EXPORT_SYMBOL (scsi_get_command)
 
void __scsi_put_command (struct Scsi_Host *shost, struct scsi_cmnd *cmd, struct device *dev)
 
 EXPORT_SYMBOL (__scsi_put_command)
 
void scsi_put_command (struct scsi_cmnd *cmd)
 
 EXPORT_SYMBOL (scsi_put_command)
 
struct scsi_cmndscsi_allocate_command (gfp_t gfp_mask)
 
 EXPORT_SYMBOL (scsi_allocate_command)
 
void scsi_free_command (gfp_t gfp_mask, struct scsi_cmnd *cmd)
 
 EXPORT_SYMBOL (scsi_free_command)
 
int scsi_setup_command_freelist (struct Scsi_Host *shost)
 
void scsi_destroy_command_freelist (struct Scsi_Host *shost)
 
void scsi_cmd_get_serial (struct Scsi_Host *host, struct scsi_cmnd *cmd)
 
 EXPORT_SYMBOL (scsi_cmd_get_serial)
 
int scsi_dispatch_cmd (struct scsi_cmnd *cmd)
 
void scsi_finish_command (struct scsi_cmnd *cmd)
 
 EXPORT_SYMBOL (scsi_finish_command)
 
void scsi_adjust_queue_depth (struct scsi_device *sdev, int tagged, int tags)
 
 EXPORT_SYMBOL (scsi_adjust_queue_depth)
 
int scsi_track_queue_full (struct scsi_device *sdev, int depth)
 
 EXPORT_SYMBOL (scsi_track_queue_full)
 
int scsi_get_vpd_page (struct scsi_device *sdev, u8 page, unsigned char *buf, int buf_len)
 
 EXPORT_SYMBOL_GPL (scsi_get_vpd_page)
 
int scsi_report_opcode (struct scsi_device *sdev, unsigned char *buffer, unsigned int len, unsigned char opcode)
 
 EXPORT_SYMBOL (scsi_report_opcode)
 
int scsi_device_get (struct scsi_device *sdev)
 
 EXPORT_SYMBOL (scsi_device_get)
 
void scsi_device_put (struct scsi_device *sdev)
 
 EXPORT_SYMBOL (scsi_device_put)
 
struct scsi_device__scsi_iterate_devices (struct Scsi_Host *shost, struct scsi_device *prev)
 
 EXPORT_SYMBOL (__scsi_iterate_devices)
 
void starget_for_each_device (struct scsi_target *starget, void *data, void(*fn)(struct scsi_device *, void *))
 
 EXPORT_SYMBOL (starget_for_each_device)
 
void __starget_for_each_device (struct scsi_target *starget, void *data, void(*fn)(struct scsi_device *, void *))
 
 EXPORT_SYMBOL (__starget_for_each_device)
 
struct scsi_device__scsi_device_lookup_by_target (struct scsi_target *starget, uint lun)
 
 EXPORT_SYMBOL (__scsi_device_lookup_by_target)
 
struct scsi_devicescsi_device_lookup_by_target (struct scsi_target *starget, uint lun)
 
 EXPORT_SYMBOL (scsi_device_lookup_by_target)
 
struct scsi_device__scsi_device_lookup (struct Scsi_Host *shost, uint channel, uint id, uint lun)
 
 EXPORT_SYMBOL (__scsi_device_lookup)
 
struct scsi_devicescsi_device_lookup (struct Scsi_Host *shost, uint channel, uint id, uint lun)
 
 EXPORT_SYMBOL (scsi_device_lookup)
 
 MODULE_DESCRIPTION ("SCSI core")
 
 MODULE_LICENSE ("GPL")
 
 module_param (scsi_logging_level, int, S_IRUGO|S_IWUSR)
 
 MODULE_PARM_DESC (scsi_logging_level,"a bit mask of logging levels")
 
 subsys_initcall (init_scsi)
 
 module_exit (exit_scsi)
 

Variables

unsigned int scsi_logging_level
 

Macro Definition Documentation

#define CREATE_TRACE_POINTS

Definition at line 72 of file scsi.c.

#define MIN_RESET_DELAY   (2*HZ)

Definition at line 81 of file scsi.c.

#define MIN_RESET_PERIOD   (15*HZ)

Definition at line 84 of file scsi.c.

Function Documentation

struct scsi_device* __scsi_device_lookup ( struct Scsi_Host shost,
uint  channel,
uint  id,
uint  lun 
)
read

__scsi_device_lookup - find a device given the host (UNLOCKED) : SCSI host pointer : SCSI channel (zero if only one channel) : SCSI target number (physical unit number) : SCSI Logical Unit Number

Description: Looks up the scsi_device with the specified , , for a given host. The returned scsi_device does not have an additional reference. You must hold the host's host_lock over this call and any access to the returned scsi_device.

Note: The only reason why drivers would want to use this is because they need to access the device list in irq context. Otherwise you really want to use scsi_device_lookup instead.

Definition at line 1303 of file scsi.c.

struct scsi_device* __scsi_device_lookup_by_target ( struct scsi_target starget,
uint  lun 
)
read

__scsi_device_lookup_by_target - find a device given the target (UNLOCKED) : SCSI target pointer : SCSI Logical Unit Number

Description: Looks up the scsi_device with the specified for a given . The returned scsi_device does not have an additional reference. You must hold the host's host_lock over this call and any access to the returned scsi_device. A scsi_device in state SDEV_DEL is skipped.

Note: The only reason why drivers should use this is because they need to access the device list in irq context. Otherwise you really want to use scsi_device_lookup_by_target instead.

Definition at line 1245 of file scsi.c.

struct scsi_cmnd* __scsi_get_command ( struct Scsi_Host shost,
gfp_t  gfp_mask 
)
read

__scsi_get_command - Allocate a struct scsi_cmnd : host to transmit command : allocation mask

Description: allocate a struct scsi_cmd from host's slab, recycling from the host's free_list if necessary.

Definition at line 251 of file scsi.c.

struct scsi_device* __scsi_iterate_devices ( struct Scsi_Host shost,
struct scsi_device prev 
)
read

Definition at line 1154 of file scsi.c.

void __scsi_put_command ( struct Scsi_Host shost,
struct scsi_cmnd cmd,
struct device dev 
)

__scsi_put_command - Free a struct scsi_cmnd : dev->host : Command to free : parent scsi device

Definition at line 322 of file scsi.c.

void __starget_for_each_device ( struct scsi_target starget,
void data,
void(*)(struct scsi_device *, void *)  fn 
)

Definition at line 1216 of file scsi.c.

ASYNC_DOMAIN ( scsi_sd_probe_domain  )
EXPORT_SYMBOL ( scsi_sd_probe_domain  )
EXPORT_SYMBOL ( scsi_device_type  )
EXPORT_SYMBOL ( scsi_get_command  )
EXPORT_SYMBOL ( __scsi_put_command  )
EXPORT_SYMBOL ( scsi_put_command  )
EXPORT_SYMBOL ( scsi_allocate_command  )
EXPORT_SYMBOL ( scsi_free_command  )
EXPORT_SYMBOL ( scsi_cmd_get_serial  )
EXPORT_SYMBOL ( scsi_finish_command  )
EXPORT_SYMBOL ( scsi_adjust_queue_depth  )
EXPORT_SYMBOL ( scsi_track_queue_full  )
EXPORT_SYMBOL ( scsi_report_opcode  )
EXPORT_SYMBOL ( scsi_device_get  )
EXPORT_SYMBOL ( scsi_device_put  )
EXPORT_SYMBOL ( __scsi_iterate_devices  )
EXPORT_SYMBOL ( starget_for_each_device  )
EXPORT_SYMBOL ( __starget_for_each_device  )
EXPORT_SYMBOL ( __scsi_device_lookup_by_target  )
EXPORT_SYMBOL ( scsi_device_lookup_by_target  )
EXPORT_SYMBOL ( __scsi_device_lookup  )
EXPORT_SYMBOL ( scsi_device_lookup  )
EXPORT_SYMBOL_GPL ( __scsi_get_command  )
EXPORT_SYMBOL_GPL ( scsi_get_vpd_page  )
MODULE_DESCRIPTION ( "SCSI core )
module_exit ( exit_scsi  )
MODULE_LICENSE ( "GPL"  )
module_param ( scsi_logging_level  ,
int  ,
S_IRUGO S_IWUSR 
)
MODULE_PARM_DESC ( scsi_logging_level  ,
"a bit mask of logging levels"   
)
void scsi_adjust_queue_depth ( struct scsi_device sdev,
int  tagged,
int  tags 
)

scsi_adjust_queue_depth - Let low level drivers change a device's queue depth : SCSI Device in question : Do we use tagged queueing (non-0) or do we treat this device as an untagged device (0) : Number of tags allowed if tagged queueing enabled, or number of commands the low level driver can queue up in non-tagged mode (as per cmd_per_lun).

Returns: Nothing

Lock Status: None held on entry

Notes: Low level drivers may call this at any time and we will do the right thing depending on whether or not the device is currently active and whether or not it even has the command blocks built yet.

Definition at line 869 of file scsi.c.

struct scsi_cmnd* scsi_allocate_command ( gfp_t  gfp_mask)
read

scsi_allocate_command - get a fully allocated SCSI command : allocation mask

This function is for use outside of the normal host based pools. It allocates the relevant command and takes an additional reference on the pool it used. This function must be paired with scsi_free_command which also has the identical mask, otherwise the free pool counts will eventually go wrong and you'll trigger a bug.

This function should only be used by drivers that need a static command allocation at start of day for internal functions.

Definition at line 432 of file scsi.c.

void scsi_cmd_get_serial ( struct Scsi_Host host,
struct scsi_cmnd cmd 
)

scsi_cmd_get_serial - Assign a serial number to a command : the scsi host : command to assign serial number to

Description: a serial number identifies a request for error recovery and debugging purposes. Protected by the Host_Lock of host.

Definition at line 643 of file scsi.c.

void scsi_destroy_command_freelist ( struct Scsi_Host shost)

scsi_destroy_command_freelist - Release the command freelist for a scsi host. : host whose freelist is going to be destroyed

Definition at line 515 of file scsi.c.

int scsi_device_get ( struct scsi_device sdev)

scsi_device_get - get an additional reference to a scsi_device : device to get a reference to

Description: Gets a reference to the scsi_device and increments the use count of the underlying LLDD module. You must hold host_lock of the parent Scsi_Host or already have a reference when calling this.

Definition at line 1117 of file scsi.c.

struct scsi_device* scsi_device_lookup ( struct Scsi_Host shost,
uint  channel,
uint  id,
uint  lun 
)
read

scsi_device_lookup - find a device given the host : SCSI host pointer : SCSI channel (zero if only one channel) : SCSI target number (physical unit number) : SCSI Logical Unit Number

Description: Looks up the scsi_device with the specified , , for a given host. The returned scsi_device has an additional reference that needs to be released with scsi_device_put once you're done with it.

Definition at line 1329 of file scsi.c.

struct scsi_device* scsi_device_lookup_by_target ( struct scsi_target starget,
uint  lun 
)
read

scsi_device_lookup_by_target - find a device given the target : SCSI target pointer : SCSI Logical Unit Number

Description: Looks up the scsi_device with the specified for a given . The returned scsi_device has an additional reference that needs to be released with scsi_device_put once you're done with it.

Definition at line 1270 of file scsi.c.

void scsi_device_put ( struct scsi_device sdev)

scsi_device_put - release a reference to a scsi_device : device to release a reference on.

Description: Release a reference to the scsi_device and decrements the use count of the underlying LLDD module. The device is freed once the last user vanishes.

Definition at line 1139 of file scsi.c.

const char* scsi_device_type ( unsigned  type)

scsi_device_type - Return 17 char string indicating device type. : type number to look up

Definition at line 130 of file scsi.c.

int scsi_dispatch_cmd ( struct scsi_cmnd cmd)

scsi_dispatch_command - Dispatch a command to the low-level driver. : command block we are dispatching.

Return: nonzero return request was rejected and device's queue needs to be plugged.

Definition at line 658 of file scsi.c.

void scsi_finish_command ( struct scsi_cmnd cmd)

scsi_finish_command - cleanup and pass command back to upper layer : the command

Description: Pass command off to upper layer for finishing of I/O request, waking processes that are waiting on results, etc.

Definition at line 799 of file scsi.c.

void scsi_free_command ( gfp_t  gfp_mask,
struct scsi_cmnd cmd 
)

scsi_free_command - free a command allocated by scsi_allocate_command : mask used in the original allocation : command to free

Note: using the original allocation mask is vital because that's what determines which command pool we use to free the command. Any mismatch will cause the system to BUG eventually.

Definition at line 452 of file scsi.c.

struct scsi_cmnd* scsi_get_command ( struct scsi_device dev,
gfp_t  gfp_mask 
)
read

scsi_get_command - Allocate and setup a scsi command block : parent scsi device : allocator flags

Returns: The allocated scsi command structure.

Definition at line 290 of file scsi.c.

int scsi_get_vpd_page ( struct scsi_device sdev,
u8  page,
unsigned char buf,
int  buf_len 
)

Definition at line 1029 of file scsi.c.

void scsi_put_command ( struct scsi_cmnd cmd)

scsi_put_command - Free a scsi command block : command block to free

Returns: Nothing.

Notes: The command must not belong to any lists.

Definition at line 350 of file scsi.c.

int scsi_report_opcode ( struct scsi_device sdev,
unsigned char buffer,
unsigned int  len,
unsigned char  opcode 
)

scsi_report_opcode - Find out if a given command opcode is supported : scsi device to query : scratch buffer (must be at least 20 bytes long) : length of buffer : opcode for command to look up

Uses the REPORT SUPPORTED OPERATION CODES to look up the given opcode. Returns 0 if RSOC fails or if the command opcode is unsupported. Returns 1 if the device claims to support the command.

Definition at line 1076 of file scsi.c.

int scsi_setup_command_freelist ( struct Scsi_Host shost)

scsi_setup_command_freelist - Setup the command freelist for a scsi host. : host to allocate the freelist for.

Description: The command freelist protects against system-wide out of memory deadlock by preallocating one SCSI command structure for each host, so the system can always write to a swap file on a device associated with that host.

Returns: Nothing.

Definition at line 485 of file scsi.c.

int scsi_track_queue_full ( struct scsi_device sdev,
int  depth 
)

scsi_track_queue_full - track QUEUE_FULL events to adjust queue depth : SCSI Device in question : Current number of outstanding SCSI commands on this device, not counting the one returned as QUEUE_FULL.

Description: This function will track successive QUEUE_FULL events on a specific SCSI device to determine if and when there is a need to adjust the queue depth on the device.

Returns: 0 - No change needed, >0 - Adjust queue depth to this new depth, -1 - Drop back to untagged operation using host->cmd_per_lun as the untagged command depth

Lock Status: None held on entry

Notes: Low level drivers may call this at any time and we will do "The Right Thing." We are interrupt context safe.

Definition at line 939 of file scsi.c.

void starget_for_each_device ( struct scsi_target starget,
void data,
void(*)(struct scsi_device *, void *)  fn 
)

Definition at line 1188 of file scsi.c.

subsys_initcall ( init_scsi  )

Variable Documentation

unsigned int scsi_logging_level

Definition at line 90 of file scsi.c.