add ability to set device queue depth to mptfusion
Subsystems (2)
RFC PATCH 1/1 add ability to set device queue depth to mptfusion
This patch lets you override the default queue depth for SCSI devices attached through the mptfusion driver.
I moved some common code that I needed out of mpt_slave_configure() into its own function.
===== drivers/message/fusion/mptscsih.c 1.47 vs edited =====
drivers/message/fusion/mptscsih.c +68 -18
@@ -2887,6 +2887,40 @@return ; } +static void +mptscsih_set_queue_depth (struct scsi_device *device,MPT_SCSI_HOST *hd,VirtDevice *pTarget,int qdepth) +{ +int max_depth; +int tagged; + +if ( hd->is_spi ) { +if (pTarget->tflags &MPT_TARGET_FLAGS_VALID_INQUIRY ) { +if (!(pTarget->tflags &MPT_TARGET_FLAGS_Q_YES )) + max_depth =1 ; +else if (((pTarget->inq_data[0 ] &0x1f ) ==0x00 ) + && (pTarget->minSyncFactor <=MPT_ULTRA160 )) + max_depth =MPT_SCSI_CMD_PER_DEV_HIGH ; +else + max_depth =MPT_SCSI_CMD_PER_DEV_LOW ; + }else { +/* error case - No Inq. Data */ + max_depth =1 ; + } + } +else + max_depth =MPT_SCSI_CMD_PER_DEV_HIGH ; + +if (qdepth > max_depth) + qdepth = max_depth; +if (qdepth ==1 ) + tagged =0 ; +else + tagged =MSG_SIMPLE_TAG ; + +scsi_adjust_queue_depth (device, tagged, qdepth); +} + +/* * OS entry point to adjust the queue_depths on a per-device basis. * Called once per device the bus scan. Use it to force the queue_depth
@@ -2936,24 +2970,7 @@mptscsih_initTarget (hd, device->channel, device->id, device->lun, device->inquiry, device->inquiry_len ); -scsi_adjust_queue_depth (device,MSG_SIMPLE_TAG , -MPT_SCSI_CMD_PER_DEV_HIGH ); -if ( hd->is_spi ) { -if (pTarget->tflags &MPT_TARGET_FLAGS_VALID_INQUIRY ) { -if (!(pTarget->tflags &MPT_TARGET_FLAGS_Q_YES )) -scsi_adjust_queue_depth (device,0 ,1 ); -else if (((pTarget->inq_data[0 ] &0x1f ) ==0x00 ) - && (pTarget->minSyncFactor <=MPT_ULTRA160 )) -scsi_adjust_queue_depth (device,MSG_SIMPLE_TAG , -MPT_SCSI_CMD_PER_DEV_HIGH ); -else -scsi_adjust_queue_depth (device,MSG_SIMPLE_TAG , -MPT_SCSI_CMD_PER_DEV_LOW ); - }else { -/* error case - No Inq. Data */ -scsi_adjust_queue_depth (device,0 ,1 ); - } - } +mptscsih_set_queue_depth (device, hd, pTarget,MPT_SCSI_CMD_PER_DEV_HIGH ); dsprintk((MYIOC_s_INFO_FMT "Queue depth=%d, tflags=%x\n",
@@ -2973,6 +2990,25 @@return 0 ; } +static ssize_t +mptscsih_store_queue_depth (struct device *dev,const char *buf,size_t count) +{ +int depth; +struct scsi_device *sdev =to_scsi_device (dev); +MPT_SCSI_HOST *hd = (MPT_SCSI_HOST *) sdev->host->hostdata; +VirtDevice *pTarget; + + depth =simple_strtoul (buf,NULL ,0 ); +if (depth ==0 ) +return -EINVAL ; + pTarget = hd->Targets[sdev->id]; +if (pTarget ==NULL ) +return -EINVAL ; +mptscsih_set_queue_depth (sdev, (MPT_SCSI_HOST *) sdev->host->hostdata, + pTarget, depth); +return count; +} +/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ /*
@@ -3302,6 +3338,19 @@return 1 ;/* currently means nothing really */ } +static struct device_attribute mptscsih_queue_depth_attr = { + .attr = { + .name ="queue_depth" , + .mode =S_IWUSR , + }, + .store = mptscsih_store_queue_depth, +}; + +static struct device_attribute *mptscsih_dev_attrs[] = { + &mptscsih_queue_depth_attr, +NULL , +}; +static struct scsi_host_template driver_template = { .proc_name ="mptscsih" , .proc_info = mptscsih_proc_info,
@@ -3322,6 +3371,7 @@ .max_sectors = 8192, .cmd_per_lun = 7, .use_clustering = ENABLE_CLUSTERING, + .sdev_attrs = mptscsih_dev_attrs, };/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
Code looks good but some style nitpicks (often inherited from the original code):
drivers/message/fusion/mptscsih.c line 2891
Quoted 2 lines
drivers/message/fusion/mptscsih.c +2
-0+static void +mptscsih_set_queue_depth (struct scsi_device *device,MPT_SCSI_HOST *hd,VirtDevice *pTarget,int qdepth)
linebreaks after 80characters please.
drivers/message/fusion/mptscsih.c line 2896
Quoted 1 line
drivers/message/fusion/mptscsih.c +1
-0+if ( hd->is_spi ) {
if (hdis_spi) {drivers/message/fusion/mptscsih.c line 2901
Quoted 2 lines
drivers/message/fusion/mptscsih.c +2
-0+else if (((pTarget->inq_data[0 ] &0x1f ) ==0x00 ) + && (pTarget->minSyncFactor <=MPT_ULTRA160 ))
else if (!(pTarget->inq_data[0] & 0x1f) && (pTarget->minSyncFactor <= MPT_ULTRA160)
Review
Quoted 2 lines
(quoted diff) +2
-0+ } + else
} else
Quoted 6 lines · Christoph Hellwig
drivers/message/fusion/mptscsih.c line 2901
Quoted 2 lines
drivers/message/fusion/mptscsih.c +2
-0+else if (((pTarget->inq_data[0 ] &0x1f ) ==0x00 ) + && (pTarget->minSyncFactor <=MPT_ULTRA160 ))else if (!(pTarget->inq_data[0] & 0x1f) && (pTarget->minSyncFactor <= MPT_ULTRA160)
I'm not sure about converting
if ((pTarget->inq_data[0] & 0x1f) == 0x00) to if (!(pTarget->inq_data[0] & 0x1f))
It really depends on the semantics -- in this case I think it's "this 5 bit field has the value 0", rather than "this field is not set". It's the same reason I hate people using if (!strcmp()) -- it's not that strcmp() failed, it's that it returned 0.
Signature · 6 lines
"Next the statesmen will invent cheap lies, putting the blame upon the nation that is attacked, and every man will be glad of those conscience-soothing falsities, and will diligently study them, and refuse to examine any refutations of them; and thus he will by and by convince himself that the war is just, and will thank God for the better sleep he enjoys after this process of grotesque self-deception." -- Mark Twain
Quoted 3 lines · Christoph Hellwig
Code looks good but some style nitpicks (often inherited from the original code):
I cut and pasted, leaving original style intact. I was of the opinion that I should not make style changes for one little piece of code.
I can add the line break.
jeremy
New patch with some style issues fixed. I went ahead and moved the logical "and" to the end of the line from the start of the next line. I agreed with Matthew's reasoning on the comparison with 0.
Thanks for reviewing, Christoph.
===== drivers/message/fusion/mptscsih.c 1.47 vs edited =====
drivers/message/fusion/mptscsih.c +68 -18
@@ -2887,6 +2887,40 @@return ; } +static void +mptscsih_set_queue_depth (struct scsi_device *device,MPT_SCSI_HOST *hd, +VirtDevice *pTarget,int qdepth) +{ +int max_depth; +int tagged; + +if ( hd->is_spi ) { +if (pTarget->tflags &MPT_TARGET_FLAGS_VALID_INQUIRY ) { +if (!(pTarget->tflags &MPT_TARGET_FLAGS_Q_YES )) + max_depth =1 ; +else if (((pTarget->inq_data[0 ] &0x1f ) ==0x00 ) && + (pTarget->minSyncFactor <=MPT_ULTRA160 )) + max_depth =MPT_SCSI_CMD_PER_DEV_HIGH ; +else + max_depth =MPT_SCSI_CMD_PER_DEV_LOW ; + }else { +/* error case - No Inq. Data */ + max_depth =1 ; + } + }else + max_depth =MPT_SCSI_CMD_PER_DEV_HIGH ; + +if (qdepth > max_depth) + qdepth = max_depth; +if (qdepth ==1 ) + tagged =0 ; +else + tagged =MSG_SIMPLE_TAG ; + +scsi_adjust_queue_depth (device, tagged, qdepth); +} + +/* * OS entry point to adjust the queue_depths on a per-device basis. * Called once per device the bus scan. Use it to force the queue_depth
@@ -2936,24 +2970,7 @@mptscsih_initTarget (hd, device->channel, device->id, device->lun, device->inquiry, device->inquiry_len ); -scsi_adjust_queue_depth (device,MSG_SIMPLE_TAG , -MPT_SCSI_CMD_PER_DEV_HIGH ); -if ( hd->is_spi ) { -if (pTarget->tflags &MPT_TARGET_FLAGS_VALID_INQUIRY ) { -if (!(pTarget->tflags &MPT_TARGET_FLAGS_Q_YES )) -scsi_adjust_queue_depth (device,0 ,1 ); -else if (((pTarget->inq_data[0 ] &0x1f ) ==0x00 ) - && (pTarget->minSyncFactor <=MPT_ULTRA160 )) -scsi_adjust_queue_depth (device,MSG_SIMPLE_TAG , -MPT_SCSI_CMD_PER_DEV_HIGH ); -else -scsi_adjust_queue_depth (device,MSG_SIMPLE_TAG , -MPT_SCSI_CMD_PER_DEV_LOW ); - }else { -/* error case - No Inq. Data */ -scsi_adjust_queue_depth (device,0 ,1 ); - } - } +mptscsih_set_queue_depth (device, hd, pTarget,MPT_SCSI_CMD_PER_DEV_HIGH ); dsprintk((MYIOC_s_INFO_FMT "Queue depth=%d, tflags=%x\n",
@@ -2973,6 +2990,25 @@return 0 ; } +static ssize_t +mptscsih_store_queue_depth (struct device *dev,const char *buf,size_t count) +{ +int depth; +struct scsi_device *sdev =to_scsi_device (dev); +MPT_SCSI_HOST *hd = (MPT_SCSI_HOST *) sdev->host->hostdata; +VirtDevice *pTarget; + + depth =simple_strtoul (buf,NULL ,0 ); +if (depth ==0 ) +return -EINVAL ; + pTarget = hd->Targets[sdev->id]; +if (pTarget ==NULL ) +return -EINVAL ; +mptscsih_set_queue_depth (sdev, (MPT_SCSI_HOST *) sdev->host->hostdata, + pTarget, depth); +return count; +} +/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ /*
@@ -3302,6 +3338,19 @@return 1 ;/* currently means nothing really */ } +static struct device_attribute mptscsih_queue_depth_attr = { + .attr = { + .name ="queue_depth" , + .mode =S_IWUSR , + }, + .store = mptscsih_store_queue_depth, +}; + +static struct device_attribute *mptscsih_dev_attrs[] = { + &mptscsih_queue_depth_attr, +NULL , +}; +static struct scsi_host_template driver_template = { .proc_name ="mptscsih" , .proc_info = mptscsih_proc_info,
@@ -3322,6 +3371,7 @@ .max_sectors = 8192, .cmd_per_lun = 7, .use_clustering = ENABLE_CLUSTERING, + .sdev_attrs = mptscsih_dev_attrs, };/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/