aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/scsi/scsi.c
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2007-11-03 14:30:39 -0400
committerJames Bottomley <James.Bottomley@HansenPartnership.com>2008-01-11 19:22:40 -0500
commiteb44820c28bc9a042e1157b41c677018a8fdfc74 (patch)
treede027b3cd40533488805ef7ee8156f077cd2b7e5 /drivers/scsi/scsi.c
parent3f48985823001c89c9bd5c5e57cc07530578dfcc (diff)
[SCSI] Add Documentation and integrate into docbook build
Add Documentation/DocBook/scsi_midlayer.tmpl, add to Makefile, and update lots of kerneldoc comments in drivers/scsi/*. Updated with comments from Stefan Richter, Stephen M. Cameron, James Bottomley and Randy Dunlap. Signed-off-by: Rob Landley <rob@landley.net> Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
Diffstat (limited to 'drivers/scsi/scsi.c')
-rw-r--r--drivers/scsi/scsi.c183
1 files changed, 96 insertions, 87 deletions
diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
index 0fb1709ce5e3..412a351c6cf7 100644
--- a/drivers/scsi/scsi.c
+++ b/drivers/scsi/scsi.c
@@ -122,6 +122,11 @@ static const char *const scsi_device_types[] = {
122 "Automation/Drive ", 122 "Automation/Drive ",
123}; 123};
124 124
125/**
126 * scsi_device_type - Return 17 char string indicating device type.
127 * @type: type number to look up
128 */
129
125const char * scsi_device_type(unsigned type) 130const char * scsi_device_type(unsigned type)
126{ 131{
127 if (type == 0x1e) 132 if (type == 0x1e)
@@ -156,6 +161,14 @@ static struct scsi_host_cmd_pool scsi_cmd_dma_pool = {
156 161
157static DEFINE_MUTEX(host_cmd_pool_mutex); 162static DEFINE_MUTEX(host_cmd_pool_mutex);
158 163
164/**
165 * __scsi_get_command - Allocate a struct scsi_cmnd
166 * @shost: host to transmit command
167 * @gfp_mask: allocation mask
168 *
169 * Description: allocate a struct scsi_cmd from host's slab, recycling from the
170 * host's free_list if necessary.
171 */
159struct scsi_cmnd *__scsi_get_command(struct Scsi_Host *shost, gfp_t gfp_mask) 172struct scsi_cmnd *__scsi_get_command(struct Scsi_Host *shost, gfp_t gfp_mask)
160{ 173{
161 struct scsi_cmnd *cmd; 174 struct scsi_cmnd *cmd;
@@ -179,13 +192,10 @@ struct scsi_cmnd *__scsi_get_command(struct Scsi_Host *shost, gfp_t gfp_mask)
179} 192}
180EXPORT_SYMBOL_GPL(__scsi_get_command); 193EXPORT_SYMBOL_GPL(__scsi_get_command);
181 194
182/* 195/**
183 * Function: scsi_get_command() 196 * scsi_get_command - Allocate and setup a scsi command block
184 * 197 * @dev: parent scsi device
185 * Purpose: Allocate and setup a scsi command block 198 * @gfp_mask: allocator flags
186 *
187 * Arguments: dev - parent scsi device
188 * gfp_mask- allocator flags
189 * 199 *
190 * Returns: The allocated scsi command structure. 200 * Returns: The allocated scsi command structure.
191 */ 201 */
@@ -217,6 +227,12 @@ struct scsi_cmnd *scsi_get_command(struct scsi_device *dev, gfp_t gfp_mask)
217} 227}
218EXPORT_SYMBOL(scsi_get_command); 228EXPORT_SYMBOL(scsi_get_command);
219 229
230/**
231 * __scsi_put_command - Free a struct scsi_cmnd
232 * @shost: dev->host
233 * @cmd: Command to free
234 * @dev: parent scsi device
235 */
220void __scsi_put_command(struct Scsi_Host *shost, struct scsi_cmnd *cmd, 236void __scsi_put_command(struct Scsi_Host *shost, struct scsi_cmnd *cmd,
221 struct device *dev) 237 struct device *dev)
222{ 238{
@@ -237,12 +253,9 @@ void __scsi_put_command(struct Scsi_Host *shost, struct scsi_cmnd *cmd,
237} 253}
238EXPORT_SYMBOL(__scsi_put_command); 254EXPORT_SYMBOL(__scsi_put_command);
239 255
240/* 256/**
241 * Function: scsi_put_command() 257 * scsi_put_command - Free a scsi command block
242 * 258 * @cmd: command block to free
243 * Purpose: Free a scsi command block
244 *
245 * Arguments: cmd - command block to free
246 * 259 *
247 * Returns: Nothing. 260 * Returns: Nothing.
248 * 261 *
@@ -263,12 +276,13 @@ void scsi_put_command(struct scsi_cmnd *cmd)
263} 276}
264EXPORT_SYMBOL(scsi_put_command); 277EXPORT_SYMBOL(scsi_put_command);
265 278
266/* 279/**
267 * Function: scsi_setup_command_freelist() 280 * scsi_setup_command_freelist - Setup the command freelist for a scsi host.
268 * 281 * @shost: host to allocate the freelist for.
269 * Purpose: Setup the command freelist for a scsi host.
270 * 282 *
271 * Arguments: shost - host to allocate the freelist for. 283 * Description: The command freelist protects against system-wide out of memory
284 * deadlock by preallocating one SCSI command structure for each host, so the
285 * system can always write to a swap file on a device associated with that host.
272 * 286 *
273 * Returns: Nothing. 287 * Returns: Nothing.
274 */ 288 */
@@ -282,7 +296,7 @@ int scsi_setup_command_freelist(struct Scsi_Host *shost)
282 296
283 /* 297 /*
284 * Select a command slab for this host and create it if not 298 * Select a command slab for this host and create it if not
285 * yet existant. 299 * yet existent.
286 */ 300 */
287 mutex_lock(&host_cmd_pool_mutex); 301 mutex_lock(&host_cmd_pool_mutex);
288 pool = (shost->unchecked_isa_dma ? &scsi_cmd_dma_pool : &scsi_cmd_pool); 302 pool = (shost->unchecked_isa_dma ? &scsi_cmd_dma_pool : &scsi_cmd_pool);
@@ -318,12 +332,9 @@ int scsi_setup_command_freelist(struct Scsi_Host *shost)
318 332
319} 333}
320 334
321/* 335/**
322 * Function: scsi_destroy_command_freelist() 336 * scsi_destroy_command_freelist - Release the command freelist for a scsi host.
323 * 337 * @shost: host whose freelist is going to be destroyed
324 * Purpose: Release the command freelist for a scsi host.
325 *
326 * Arguments: shost - host that's freelist is going to be destroyed
327 */ 338 */
328void scsi_destroy_command_freelist(struct Scsi_Host *shost) 339void scsi_destroy_command_freelist(struct Scsi_Host *shost)
329{ 340{
@@ -441,8 +452,12 @@ void scsi_log_completion(struct scsi_cmnd *cmd, int disposition)
441} 452}
442#endif 453#endif
443 454
444/* 455/**
445 * Assign a serial number to the request for error recovery 456 * scsi_cmd_get_serial - Assign a serial number to a command
457 * @host: the scsi host
458 * @cmd: command to assign serial number to
459 *
460 * Description: a serial number identifies a request for error recovery
446 * and debugging purposes. Protected by the Host_Lock of host. 461 * and debugging purposes. Protected by the Host_Lock of host.
447 */ 462 */
448static inline void scsi_cmd_get_serial(struct Scsi_Host *host, struct scsi_cmnd *cmd) 463static inline void scsi_cmd_get_serial(struct Scsi_Host *host, struct scsi_cmnd *cmd)
@@ -452,14 +467,12 @@ static inline void scsi_cmd_get_serial(struct Scsi_Host *host, struct scsi_cmnd
452 cmd->serial_number = host->cmd_serial_number++; 467 cmd->serial_number = host->cmd_serial_number++;
453} 468}
454 469
455/* 470/**
456 * Function: scsi_dispatch_command 471 * scsi_dispatch_command - Dispatch a command to the low-level driver.
457 * 472 * @cmd: command block we are dispatching.
458 * Purpose: Dispatch a command to the low-level driver.
459 *
460 * Arguments: cmd - command block we are dispatching.
461 * 473 *
462 * Notes: 474 * Return: nonzero return request was rejected and device's queue needs to be
475 * plugged.
463 */ 476 */
464int scsi_dispatch_cmd(struct scsi_cmnd *cmd) 477int scsi_dispatch_cmd(struct scsi_cmnd *cmd)
465{ 478{
@@ -585,7 +598,7 @@ int scsi_dispatch_cmd(struct scsi_cmnd *cmd)
585 598
586/** 599/**
587 * scsi_req_abort_cmd -- Request command recovery for the specified command 600 * scsi_req_abort_cmd -- Request command recovery for the specified command
588 * cmd: pointer to the SCSI command of interest 601 * @cmd: pointer to the SCSI command of interest
589 * 602 *
590 * This function requests that SCSI Core start recovery for the 603 * This function requests that SCSI Core start recovery for the
591 * command by deleting the timer and adding the command to the eh 604 * command by deleting the timer and adding the command to the eh
@@ -606,9 +619,9 @@ EXPORT_SYMBOL(scsi_req_abort_cmd);
606 * @cmd: The SCSI Command for which a low-level device driver (LLDD) gives 619 * @cmd: The SCSI Command for which a low-level device driver (LLDD) gives
607 * ownership back to SCSI Core -- i.e. the LLDD has finished with it. 620 * ownership back to SCSI Core -- i.e. the LLDD has finished with it.
608 * 621 *
609 * This function is the mid-level's (SCSI Core) interrupt routine, which 622 * Description: This function is the mid-level's (SCSI Core) interrupt routine,
610 * regains ownership of the SCSI command (de facto) from a LLDD, and enqueues 623 * which regains ownership of the SCSI command (de facto) from a LLDD, and
611 * the command to the done queue for further processing. 624 * enqueues the command to the done queue for further processing.
612 * 625 *
613 * This is the producer of the done queue who enqueues at the tail. 626 * This is the producer of the done queue who enqueues at the tail.
614 * 627 *
@@ -617,7 +630,7 @@ EXPORT_SYMBOL(scsi_req_abort_cmd);
617static void scsi_done(struct scsi_cmnd *cmd) 630static void scsi_done(struct scsi_cmnd *cmd)
618{ 631{
619 /* 632 /*
620 * We don't have to worry about this one timing out any more. 633 * We don't have to worry about this one timing out anymore.
621 * If we are unable to remove the timer, then the command 634 * If we are unable to remove the timer, then the command
622 * has already timed out. In which case, we have no choice but to 635 * has already timed out. In which case, we have no choice but to
623 * let the timeout function run, as we have no idea where in fact 636 * let the timeout function run, as we have no idea where in fact
@@ -660,10 +673,11 @@ static struct scsi_driver *scsi_cmd_to_driver(struct scsi_cmnd *cmd)
660 return *(struct scsi_driver **)cmd->request->rq_disk->private_data; 673 return *(struct scsi_driver **)cmd->request->rq_disk->private_data;
661} 674}
662 675
663/* 676/**
664 * Function: scsi_finish_command 677 * scsi_finish_command - cleanup and pass command back to upper layer
678 * @cmd: the command
665 * 679 *
666 * Purpose: Pass command off to upper layer for finishing of I/O 680 * Description: Pass command off to upper layer for finishing of I/O
667 * request, waking processes that are waiting on results, 681 * request, waking processes that are waiting on results,
668 * etc. 682 * etc.
669 */ 683 */
@@ -708,18 +722,14 @@ void scsi_finish_command(struct scsi_cmnd *cmd)
708} 722}
709EXPORT_SYMBOL(scsi_finish_command); 723EXPORT_SYMBOL(scsi_finish_command);
710 724
711/* 725/**
712 * Function: scsi_adjust_queue_depth() 726 * scsi_adjust_queue_depth - Let low level drivers change a device's queue depth
713 * 727 * @sdev: SCSI Device in question
714 * Purpose: Allow low level drivers to tell us to change the queue depth 728 * @tagged: Do we use tagged queueing (non-0) or do we treat
715 * on a specific SCSI device 729 * this device as an untagged device (0)
716 * 730 * @tags: Number of tags allowed if tagged queueing enabled,
717 * Arguments: sdev - SCSI Device in question 731 * or number of commands the low level driver can
718 * tagged - Do we use tagged queueing (non-0) or do we treat 732 * queue up in non-tagged mode (as per cmd_per_lun).
719 * this device as an untagged device (0)
720 * tags - Number of tags allowed if tagged queueing enabled,
721 * or number of commands the low level driver can
722 * queue up in non-tagged mode (as per cmd_per_lun).
723 * 733 *
724 * Returns: Nothing 734 * Returns: Nothing
725 * 735 *
@@ -742,8 +752,8 @@ void scsi_adjust_queue_depth(struct scsi_device *sdev, int tagged, int tags)
742 752
743 spin_lock_irqsave(sdev->request_queue->queue_lock, flags); 753 spin_lock_irqsave(sdev->request_queue->queue_lock, flags);
744 754
745 /* Check to see if the queue is managed by the block layer 755 /* Check to see if the queue is managed by the block layer.
746 * if it is, and we fail to adjust the depth, exit */ 756 * If it is, and we fail to adjust the depth, exit. */
747 if (blk_queue_tagged(sdev->request_queue) && 757 if (blk_queue_tagged(sdev->request_queue) &&
748 blk_queue_resize_tags(sdev->request_queue, tags) != 0) 758 blk_queue_resize_tags(sdev->request_queue, tags) != 0)
749 goto out; 759 goto out;
@@ -772,20 +782,17 @@ void scsi_adjust_queue_depth(struct scsi_device *sdev, int tagged, int tags)
772} 782}
773EXPORT_SYMBOL(scsi_adjust_queue_depth); 783EXPORT_SYMBOL(scsi_adjust_queue_depth);
774 784
775/* 785/**
776 * Function: scsi_track_queue_full() 786 * scsi_track_queue_full - track QUEUE_FULL events to adjust queue depth
787 * @sdev: SCSI Device in question
788 * @depth: Current number of outstanding SCSI commands on this device,
789 * not counting the one returned as QUEUE_FULL.
777 * 790 *
778 * Purpose: This function will track successive QUEUE_FULL events on a 791 * Description: This function will track successive QUEUE_FULL events on a
779 * specific SCSI device to determine if and when there is a 792 * specific SCSI device to determine if and when there is a
780 * need to adjust the queue depth on the device. 793 * need to adjust the queue depth on the device.
781 * 794 *
782 * Arguments: sdev - SCSI Device in question 795 * Returns: 0 - No change needed, >0 - Adjust queue depth to this new depth,
783 * depth - Current number of outstanding SCSI commands on
784 * this device, not counting the one returned as
785 * QUEUE_FULL.
786 *
787 * Returns: 0 - No change needed
788 * >0 - Adjust queue depth to this new depth
789 * -1 - Drop back to untagged operation using host->cmd_per_lun 796 * -1 - Drop back to untagged operation using host->cmd_per_lun
790 * as the untagged command depth 797 * as the untagged command depth
791 * 798 *
@@ -824,10 +831,10 @@ int scsi_track_queue_full(struct scsi_device *sdev, int depth)
824EXPORT_SYMBOL(scsi_track_queue_full); 831EXPORT_SYMBOL(scsi_track_queue_full);
825 832
826/** 833/**
827 * scsi_device_get - get an addition reference to a scsi_device 834 * scsi_device_get - get an additional reference to a scsi_device
828 * @sdev: device to get a reference to 835 * @sdev: device to get a reference to
829 * 836 *
830 * Gets a reference to the scsi_device and increments the use count 837 * Description: Gets a reference to the scsi_device and increments the use count
831 * of the underlying LLDD module. You must hold host_lock of the 838 * of the underlying LLDD module. You must hold host_lock of the
832 * parent Scsi_Host or already have a reference when calling this. 839 * parent Scsi_Host or already have a reference when calling this.
833 */ 840 */
@@ -849,8 +856,8 @@ EXPORT_SYMBOL(scsi_device_get);
849 * scsi_device_put - release a reference to a scsi_device 856 * scsi_device_put - release a reference to a scsi_device
850 * @sdev: device to release a reference on. 857 * @sdev: device to release a reference on.
851 * 858 *
852 * Release a reference to the scsi_device and decrements the use count 859 * Description: Release a reference to the scsi_device and decrements the use
853 * of the underlying LLDD module. The device is freed once the last 860 * count of the underlying LLDD module. The device is freed once the last
854 * user vanishes. 861 * user vanishes.
855 */ 862 */
856void scsi_device_put(struct scsi_device *sdev) 863void scsi_device_put(struct scsi_device *sdev)
@@ -867,7 +874,7 @@ void scsi_device_put(struct scsi_device *sdev)
867} 874}
868EXPORT_SYMBOL(scsi_device_put); 875EXPORT_SYMBOL(scsi_device_put);
869 876
870/* helper for shost_for_each_device, thus not documented */ 877/* helper for shost_for_each_device, see that for documentation */
871struct scsi_device *__scsi_iterate_devices(struct Scsi_Host *shost, 878struct scsi_device *__scsi_iterate_devices(struct Scsi_Host *shost,
872 struct scsi_device *prev) 879 struct scsi_device *prev)
873{ 880{
@@ -895,6 +902,8 @@ EXPORT_SYMBOL(__scsi_iterate_devices);
895/** 902/**
896 * starget_for_each_device - helper to walk all devices of a target 903 * starget_for_each_device - helper to walk all devices of a target
897 * @starget: target whose devices we want to iterate over. 904 * @starget: target whose devices we want to iterate over.
905 * @data: Opaque passed to each function call.
906 * @fn: Function to call on each device
898 * 907 *
899 * This traverses over each device of @starget. The devices have 908 * This traverses over each device of @starget. The devices have
900 * a reference that must be released by scsi_host_put when breaking 909 * a reference that must be released by scsi_host_put when breaking
@@ -946,13 +955,13 @@ EXPORT_SYMBOL(__starget_for_each_device);
946 * @starget: SCSI target pointer 955 * @starget: SCSI target pointer
947 * @lun: SCSI Logical Unit Number 956 * @lun: SCSI Logical Unit Number
948 * 957 *
949 * Looks up the scsi_device with the specified @lun for a give 958 * Description: Looks up the scsi_device with the specified @lun for a given
950 * @starget. The returned scsi_device does not have an additional 959 * @starget. The returned scsi_device does not have an additional
951 * reference. You must hold the host's host_lock over this call and 960 * reference. You must hold the host's host_lock over this call and
952 * any access to the returned scsi_device. 961 * any access to the returned scsi_device.
953 * 962 *
954 * Note: The only reason why drivers would want to use this is because 963 * Note: The only reason why drivers would want to use this is because
955 * they're need to access the device list in irq context. Otherwise you 964 * they need to access the device list in irq context. Otherwise you
956 * really want to use scsi_device_lookup_by_target instead. 965 * really want to use scsi_device_lookup_by_target instead.
957 **/ 966 **/
958struct scsi_device *__scsi_device_lookup_by_target(struct scsi_target *starget, 967struct scsi_device *__scsi_device_lookup_by_target(struct scsi_target *starget,
@@ -974,9 +983,9 @@ EXPORT_SYMBOL(__scsi_device_lookup_by_target);
974 * @starget: SCSI target pointer 983 * @starget: SCSI target pointer
975 * @lun: SCSI Logical Unit Number 984 * @lun: SCSI Logical Unit Number
976 * 985 *
977 * Looks up the scsi_device with the specified @channel, @id, @lun for a 986 * Description: Looks up the scsi_device with the specified @channel, @id, @lun
978 * give host. The returned scsi_device has an additional reference that 987 * for a given host. The returned scsi_device has an additional reference that
979 * needs to be release with scsi_host_put once you're done with it. 988 * needs to be released with scsi_device_put once you're done with it.
980 **/ 989 **/
981struct scsi_device *scsi_device_lookup_by_target(struct scsi_target *starget, 990struct scsi_device *scsi_device_lookup_by_target(struct scsi_target *starget,
982 uint lun) 991 uint lun)
@@ -996,19 +1005,19 @@ struct scsi_device *scsi_device_lookup_by_target(struct scsi_target *starget,
996EXPORT_SYMBOL(scsi_device_lookup_by_target); 1005EXPORT_SYMBOL(scsi_device_lookup_by_target);
997 1006
998/** 1007/**
999 * scsi_device_lookup - find a device given the host (UNLOCKED) 1008 * __scsi_device_lookup - find a device given the host (UNLOCKED)
1000 * @shost: SCSI host pointer 1009 * @shost: SCSI host pointer
1001 * @channel: SCSI channel (zero if only one channel) 1010 * @channel: SCSI channel (zero if only one channel)
1002 * @pun: SCSI target number (physical unit number) 1011 * @id: SCSI target number (physical unit number)
1003 * @lun: SCSI Logical Unit Number 1012 * @lun: SCSI Logical Unit Number
1004 * 1013 *
1005 * Looks up the scsi_device with the specified @channel, @id, @lun for a 1014 * Description: Looks up the scsi_device with the specified @channel, @id, @lun
1006 * give host. The returned scsi_device does not have an additional reference. 1015 * for a given host. The returned scsi_device does not have an additional
1007 * You must hold the host's host_lock over this call and any access to the 1016 * reference. You must hold the host's host_lock over this call and any access
1008 * returned scsi_device. 1017 * to the returned scsi_device.
1009 * 1018 *
1010 * Note: The only reason why drivers would want to use this is because 1019 * Note: The only reason why drivers would want to use this is because
1011 * they're need to access the device list in irq context. Otherwise you 1020 * they need to access the device list in irq context. Otherwise you
1012 * really want to use scsi_device_lookup instead. 1021 * really want to use scsi_device_lookup instead.
1013 **/ 1022 **/
1014struct scsi_device *__scsi_device_lookup(struct Scsi_Host *shost, 1023struct scsi_device *__scsi_device_lookup(struct Scsi_Host *shost,
@@ -1033,9 +1042,9 @@ EXPORT_SYMBOL(__scsi_device_lookup);
1033 * @id: SCSI target number (physical unit number) 1042 * @id: SCSI target number (physical unit number)
1034 * @lun: SCSI Logical Unit Number 1043 * @lun: SCSI Logical Unit Number
1035 * 1044 *
1036 * Looks up the scsi_device with the specified @channel, @id, @lun for a 1045 * Description: Looks up the scsi_device with the specified @channel, @id, @lun
1037 * give host. The returned scsi_device has an additional reference that 1046 * for a given host. The returned scsi_device has an additional reference that
1038 * needs to be release with scsi_host_put once you're done with it. 1047 * needs to be released with scsi_device_put once you're done with it.
1039 **/ 1048 **/
1040struct scsi_device *scsi_device_lookup(struct Scsi_Host *shost, 1049struct scsi_device *scsi_device_lookup(struct Scsi_Host *shost,
1041 uint channel, uint id, uint lun) 1050 uint channel, uint id, uint lun)