summaryrefslogtreecommitdiffstats
path: root/drivers/scsi/scsi_lib.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/scsi/scsi_lib.c')
-rw-r--r--drivers/scsi/scsi_lib.c162
1 files changed, 95 insertions, 67 deletions
diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
index 701a328f7beb..8f010a314a3d 100644
--- a/drivers/scsi/scsi_lib.c
+++ b/drivers/scsi/scsi_lib.c
@@ -286,13 +286,12 @@ int scsi_execute_req(struct scsi_device *sdev, const unsigned char *cmd,
int result;
if (sshdr) {
- sense = kmalloc(SCSI_SENSE_BUFFERSIZE, GFP_NOIO);
+ sense = kzalloc(SCSI_SENSE_BUFFERSIZE, GFP_NOIO);
if (!sense)
return DRIVER_ERROR << 24;
- memset(sense, 0, SCSI_SENSE_BUFFERSIZE);
}
result = scsi_execute(sdev, cmd, data_direction, buffer, bufflen,
- sense, timeout, retries, 0);
+ sense, timeout, retries, 0);
if (sshdr)
scsi_normalize_sense(sense, SCSI_SENSE_BUFFERSIZE, sshdr);
@@ -1788,9 +1787,8 @@ int __init scsi_init_queue(void)
sgp->name);
}
- sgp->pool = mempool_create(SG_MEMPOOL_SIZE,
- mempool_alloc_slab, mempool_free_slab,
- sgp->slab);
+ sgp->pool = mempool_create_slab_pool(SG_MEMPOOL_SIZE,
+ sgp->slab);
if (!sgp->pool) {
printk(KERN_ERR "SCSI: can't init sg mempool %s\n",
sgp->name);
@@ -1812,6 +1810,84 @@ void scsi_exit_queue(void)
kmem_cache_destroy(sgp->slab);
}
}
+
+/**
+ * scsi_mode_select - issue a mode select
+ * @sdev: SCSI device to be queried
+ * @pf: Page format bit (1 == standard, 0 == vendor specific)
+ * @sp: Save page bit (0 == don't save, 1 == save)
+ * @modepage: mode page being requested
+ * @buffer: request buffer (may not be smaller than eight bytes)
+ * @len: length of request buffer.
+ * @timeout: command timeout
+ * @retries: number of retries before failing
+ * @data: returns a structure abstracting the mode header data
+ * @sense: 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
+ *
+ */
+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)
+{
+ unsigned char cmd[10];
+ unsigned char *real_buffer;
+ int ret;
+
+ memset(cmd, 0, sizeof(cmd));
+ cmd[1] = (pf ? 0x10 : 0) | (sp ? 0x01 : 0);
+
+ if (sdev->use_10_for_ms) {
+ if (len > 65535)
+ return -EINVAL;
+ real_buffer = kmalloc(8 + len, GFP_KERNEL);
+ if (!real_buffer)
+ return -ENOMEM;
+ memcpy(real_buffer + 8, buffer, len);
+ len += 8;
+ real_buffer[0] = 0;
+ real_buffer[1] = 0;
+ real_buffer[2] = data->medium_type;
+ real_buffer[3] = data->device_specific;
+ real_buffer[4] = data->longlba ? 0x01 : 0;
+ real_buffer[5] = 0;
+ real_buffer[6] = data->block_descriptor_length >> 8;
+ real_buffer[7] = data->block_descriptor_length;
+
+ cmd[0] = MODE_SELECT_10;
+ cmd[7] = len >> 8;
+ cmd[8] = len;
+ } else {
+ if (len > 255 || data->block_descriptor_length > 255 ||
+ data->longlba)
+ return -EINVAL;
+
+ real_buffer = kmalloc(4 + len, GFP_KERNEL);
+ if (!real_buffer)
+ return -ENOMEM;
+ memcpy(real_buffer + 4, buffer, len);
+ len += 4;
+ real_buffer[0] = 0;
+ real_buffer[1] = data->medium_type;
+ real_buffer[2] = data->device_specific;
+ real_buffer[3] = data->block_descriptor_length;
+
+
+ cmd[0] = MODE_SELECT;
+ cmd[4] = len;
+ }
+
+ ret = scsi_execute_req(sdev, cmd, DMA_TO_DEVICE, real_buffer, len,
+ sshdr, timeout, retries);
+ kfree(real_buffer);
+ return ret;
+}
+EXPORT_SYMBOL_GPL(scsi_mode_select);
+
/**
* scsi_mode_sense - issue a mode sense, falling back from 10 to
* six bytes if necessary.
@@ -1833,7 +1909,8 @@ void scsi_exit_queue(void)
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) {
+ struct scsi_mode_data *data, struct scsi_sense_hdr *sshdr)
+{
unsigned char cmd[12];
int use_10_for_ms;
int header_length;
@@ -1893,8 +1970,16 @@ scsi_mode_sense(struct scsi_device *sdev, int dbd, int modepage,
}
if(scsi_status_is_good(result)) {
- data->header_length = header_length;
- if(use_10_for_ms) {
+ if (unlikely(buffer[0] == 0x86 && buffer[1] == 0x0b &&
+ (modepage == 6 || modepage == 8))) {
+ /* Initio breakage? */
+ header_length = 0;
+ data->length = 13;
+ data->medium_type = 0;
+ data->device_specific = 0;
+ data->longlba = 0;
+ data->block_descriptor_length = 0;
+ } else if(use_10_for_ms) {
data->length = buffer[0]*256 + buffer[1] + 2;
data->medium_type = buffer[2];
data->device_specific = buffer[3];
@@ -1907,6 +1992,7 @@ scsi_mode_sense(struct scsi_device *sdev, int dbd, int modepage,
data->device_specific = buffer[2];
data->block_descriptor_length = buffer[3];
}
+ data->header_length = header_length;
}
return result;
@@ -2249,61 +2335,3 @@ scsi_target_unblock(struct device *dev)
device_for_each_child(dev, NULL, target_unblock);
}
EXPORT_SYMBOL_GPL(scsi_target_unblock);
-
-
-struct work_queue_work {
- struct work_struct work;
- void (*fn)(void *);
- void *data;
-};
-
-static void execute_in_process_context_work(void *data)
-{
- void (*fn)(void *data);
- struct work_queue_work *wqw = data;
-
- fn = wqw->fn;
- data = wqw->data;
-
- kfree(wqw);
-
- fn(data);
-}
-
-/**
- * scsi_execute_in_process_context - reliably execute the routine with user context
- * @fn: the function to execute
- * @data: data to pass to the function
- *
- * Executes the function immediately if process context is available,
- * otherwise schedules the function for delayed execution.
- *
- * Returns: 0 - function was executed
- * 1 - function was scheduled for execution
- * <0 - error
- */
-int scsi_execute_in_process_context(void (*fn)(void *data), void *data)
-{
- struct work_queue_work *wqw;
-
- if (!in_interrupt()) {
- fn(data);
- return 0;
- }
-
- wqw = kmalloc(sizeof(struct work_queue_work), GFP_ATOMIC);
-
- if (unlikely(!wqw)) {
- printk(KERN_ERR "Failed to allocate memory\n");
- WARN_ON(1);
- return -ENOMEM;
- }
-
- INIT_WORK(&wqw->work, execute_in_process_context_work, wqw);
- wqw->fn = fn;
- wqw->data = data;
- schedule_work(&wqw->work);
-
- return 1;
-}
-EXPORT_SYMBOL_GPL(scsi_execute_in_process_context);