Skip to content

Commit 0284556

Browse files
Arvind KumarJames Bottomley
authored andcommitted
[SCSI] vmw_pvscsi: Some improvements in pvscsi driver.
This change is about the following: (1) If the number of targets is 16+ then default ring_pages to 32. (2) Change default queue depth (per device) to 254. (3) Implement change_queue_depth function so that queue_depth per device can be changed at run time. Honors the request only if coming from sysfs. (4) Clean up the info returned by modinfo. Signed-off-by: Arvind Kumar <arvindkumar@vmware.com> Signed-off-by: James Bottomley <JBottomley@Parallels.com>
1 parent 2a815b5 commit 0284556

2 files changed

Lines changed: 105 additions & 39 deletions

File tree

‎drivers/scsi/vmw_pvscsi.c‎

Lines changed: 104 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#include <scsi/scsi_host.h>
3333
#include <scsi/scsi_cmnd.h>
3434
#include <scsi/scsi_device.h>
35+
#include <scsi/scsi_tcq.h>
3536

3637
#include "vmw_pvscsi.h"
3738

@@ -44,7 +45,7 @@ MODULE_VERSION(PVSCSI_DRIVER_VERSION_STRING);
4445

4546
#define PVSCSI_DEFAULT_NUM_PAGES_PER_RING 8
4647
#define PVSCSI_DEFAULT_NUM_PAGES_MSG_RING 1
47-
#define PVSCSI_DEFAULT_QUEUE_DEPTH 64
48+
#define PVSCSI_DEFAULT_QUEUE_DEPTH 254
4849
#define SGL_SIZE PAGE_SIZE
4950

5051
struct pvscsi_sg_list {
@@ -104,7 +105,7 @@ struct pvscsi_adapter {
104105

105106

106107
/* Command line parameters */
107-
static int pvscsi_ring_pages = PVSCSI_DEFAULT_NUM_PAGES_PER_RING;
108+
static int pvscsi_ring_pages;
108109
static int pvscsi_msg_ring_pages = PVSCSI_DEFAULT_NUM_PAGES_MSG_RING;
109110
static int pvscsi_cmd_per_lun = PVSCSI_DEFAULT_QUEUE_DEPTH;
110111
static bool pvscsi_disable_msi;
@@ -116,15 +117,18 @@ static bool pvscsi_use_req_threshold = true;
116117

117118
module_param_named(ring_pages, pvscsi_ring_pages, int, PVSCSI_RW);
118119
MODULE_PARM_DESC(ring_pages, "Number of pages per req/cmp ring - (default="
119-
__stringify(PVSCSI_DEFAULT_NUM_PAGES_PER_RING) ")");
120+
__stringify(PVSCSI_DEFAULT_NUM_PAGES_PER_RING)
121+
"[up to 16 targets],"
122+
__stringify(PVSCSI_SETUP_RINGS_MAX_NUM_PAGES)
123+
"[for 16+ targets])");
120124

121125
module_param_named(msg_ring_pages, pvscsi_msg_ring_pages, int, PVSCSI_RW);
122126
MODULE_PARM_DESC(msg_ring_pages, "Number of pages for the msg ring - (default="
123127
__stringify(PVSCSI_DEFAULT_NUM_PAGES_MSG_RING) ")");
124128

125129
module_param_named(cmd_per_lun, pvscsi_cmd_per_lun, int, PVSCSI_RW);
126130
MODULE_PARM_DESC(cmd_per_lun, "Maximum commands per lun - (default="
127-
__stringify(PVSCSI_MAX_REQ_QUEUE_DEPTH) ")");
131+
__stringify(PVSCSI_DEFAULT_QUEUE_DEPTH) ")");
128132

129133
module_param_named(disable_msi, pvscsi_disable_msi, bool, PVSCSI_RW);
130134
MODULE_PARM_DESC(disable_msi, "Disable MSI use in driver - (default=0)");
@@ -500,6 +504,35 @@ static void pvscsi_setup_all_rings(const struct pvscsi_adapter *adapter)
500504
}
501505
}
502506

507+
static int pvscsi_change_queue_depth(struct scsi_device *sdev,
508+
int qdepth,
509+
int reason)
510+
{
511+
int max_depth;
512+
struct Scsi_Host *shost = sdev->host;
513+
514+
if (reason != SCSI_QDEPTH_DEFAULT)
515+
/*
516+
* We support only changing default.
517+
*/
518+
return -EOPNOTSUPP;
519+
520+
max_depth = shost->can_queue;
521+
if (!sdev->tagged_supported)
522+
max_depth = 1;
523+
if (qdepth > max_depth)
524+
qdepth = max_depth;
525+
scsi_adjust_queue_depth(sdev, scsi_get_tag_type(sdev), qdepth);
526+
527+
if (sdev->inquiry_len > 7)
528+
sdev_printk(KERN_INFO, sdev,
529+
"qdepth(%d), tagged(%d), simple(%d), ordered(%d), scsi_level(%d), cmd_que(%d)\n",
530+
sdev->queue_depth, sdev->tagged_supported,
531+
sdev->simple_tags, sdev->ordered_tags,
532+
sdev->scsi_level, (sdev->inquiry[7] & 2) >> 1);
533+
return sdev->queue_depth;
534+
}
535+
503536
/*
504537
* Pull a completion descriptor off and pass the completion back
505538
* to the SCSI mid layer.
@@ -965,6 +998,7 @@ static struct scsi_host_template pvscsi_template = {
965998
.dma_boundary = UINT_MAX,
966999
.max_sectors = 0xffff,
9671000
.use_clustering = ENABLE_CLUSTERING,
1001+
.change_queue_depth = pvscsi_change_queue_depth,
9681002
.eh_abort_handler = pvscsi_abort,
9691003
.eh_device_reset_handler = pvscsi_device_reset,
9701004
.eh_bus_reset_handler = pvscsi_bus_reset,
@@ -1318,11 +1352,12 @@ static u32 pvscsi_get_max_targets(struct pvscsi_adapter *adapter)
13181352
static int pvscsi_probe(struct pci_dev *pdev, const struct pci_device_id *id)
13191353
{
13201354
struct pvscsi_adapter *adapter;
1321-
struct Scsi_Host *host;
1322-
struct device *dev;
1355+
struct pvscsi_adapter adapter_temp;
1356+
struct Scsi_Host *host = NULL;
13231357
unsigned int i;
13241358
unsigned long flags = 0;
13251359
int error;
1360+
u32 max_id;
13261361

13271362
error = -ENODEV;
13281363

@@ -1340,34 +1375,19 @@ static int pvscsi_probe(struct pci_dev *pdev, const struct pci_device_id *id)
13401375
goto out_disable_device;
13411376
}
13421377

1343-
pvscsi_template.can_queue =
1344-
min(PVSCSI_MAX_NUM_PAGES_REQ_RING, pvscsi_ring_pages) *
1345-
PVSCSI_MAX_NUM_REQ_ENTRIES_PER_PAGE;
1346-
pvscsi_template.cmd_per_lun =
1347-
min(pvscsi_template.can_queue, pvscsi_cmd_per_lun);
1348-
host = scsi_host_alloc(&pvscsi_template, sizeof(struct pvscsi_adapter));
1349-
if (!host) {
1350-
printk(KERN_ERR "vmw_pvscsi: failed to allocate host\n");
1351-
goto out_disable_device;
1352-
}
1353-
1354-
adapter = shost_priv(host);
1378+
/*
1379+
* Let's use a temp pvscsi_adapter struct until we find the number of
1380+
* targets on the adapter, after that we will switch to the real
1381+
* allocated struct.
1382+
*/
1383+
adapter = &adapter_temp;
13551384
memset(adapter, 0, sizeof(*adapter));
13561385
adapter->dev = pdev;
1357-
adapter->host = host;
1358-
1359-
spin_lock_init(&adapter->hw_lock);
1360-
1361-
host->max_channel = 0;
1362-
host->max_id = 16;
1363-
host->max_lun = 1;
1364-
host->max_cmd_len = 16;
1365-
13661386
adapter->rev = pdev->revision;
13671387

13681388
if (pci_request_regions(pdev, "vmw_pvscsi")) {
13691389
printk(KERN_ERR "vmw_pvscsi: pci memory selection failed\n");
1370-
goto out_free_host;
1390+
goto out_disable_device;
13711391
}
13721392

13731393
for (i = 0; i < DEVICE_COUNT_RESOURCE; i++) {
@@ -1383,7 +1403,7 @@ static int pvscsi_probe(struct pci_dev *pdev, const struct pci_device_id *id)
13831403
if (i == DEVICE_COUNT_RESOURCE) {
13841404
printk(KERN_ERR
13851405
"vmw_pvscsi: adapter has no suitable MMIO region\n");
1386-
goto out_release_resources;
1406+
goto out_release_resources_and_disable;
13871407
}
13881408

13891409
adapter->mmioBase = pci_iomap(pdev, i, PVSCSI_MEM_SPACE_SIZE);
@@ -1392,10 +1412,60 @@ static int pvscsi_probe(struct pci_dev *pdev, const struct pci_device_id *id)
13921412
printk(KERN_ERR
13931413
"vmw_pvscsi: can't iomap for BAR %d memsize %lu\n",
13941414
i, PVSCSI_MEM_SPACE_SIZE);
1395-
goto out_release_resources;
1415+
goto out_release_resources_and_disable;
13961416
}
13971417

13981418
pci_set_master(pdev);
1419+
1420+
/*
1421+
* Ask the device for max number of targets before deciding the
1422+
* default pvscsi_ring_pages value.
1423+
*/
1424+
max_id = pvscsi_get_max_targets(adapter);
1425+
printk(KERN_INFO "vmw_pvscsi: max_id: %u\n", max_id);
1426+
1427+
if (pvscsi_ring_pages == 0)
1428+
/*
1429+
* Set the right default value. Up to 16 it is 8, above it is
1430+
* max.
1431+
*/
1432+
pvscsi_ring_pages = (max_id > 16) ?
1433+
PVSCSI_SETUP_RINGS_MAX_NUM_PAGES :
1434+
PVSCSI_DEFAULT_NUM_PAGES_PER_RING;
1435+
printk(KERN_INFO
1436+
"vmw_pvscsi: setting ring_pages to %d\n",
1437+
pvscsi_ring_pages);
1438+
1439+
pvscsi_template.can_queue =
1440+
min(PVSCSI_MAX_NUM_PAGES_REQ_RING, pvscsi_ring_pages) *
1441+
PVSCSI_MAX_NUM_REQ_ENTRIES_PER_PAGE;
1442+
pvscsi_template.cmd_per_lun =
1443+
min(pvscsi_template.can_queue, pvscsi_cmd_per_lun);
1444+
host = scsi_host_alloc(&pvscsi_template, sizeof(struct pvscsi_adapter));
1445+
if (!host) {
1446+
printk(KERN_ERR "vmw_pvscsi: failed to allocate host\n");
1447+
goto out_release_resources_and_disable;
1448+
}
1449+
1450+
/*
1451+
* Let's use the real pvscsi_adapter struct here onwards.
1452+
*/
1453+
adapter = shost_priv(host);
1454+
memset(adapter, 0, sizeof(*adapter));
1455+
adapter->dev = pdev;
1456+
adapter->host = host;
1457+
/*
1458+
* Copy back what we already have to the allocated adapter struct.
1459+
*/
1460+
adapter->rev = adapter_temp.rev;
1461+
adapter->mmioBase = adapter_temp.mmioBase;
1462+
1463+
spin_lock_init(&adapter->hw_lock);
1464+
host->max_channel = 0;
1465+
host->max_lun = 1;
1466+
host->max_cmd_len = 16;
1467+
host->max_id = max_id;
1468+
13991469
pci_set_drvdata(pdev, host);
14001470

14011471
ll_adapter_reset(adapter);
@@ -1408,13 +1478,6 @@ static int pvscsi_probe(struct pci_dev *pdev, const struct pci_device_id *id)
14081478
goto out_release_resources;
14091479
}
14101480

1411-
/*
1412-
* Ask the device for max number of targets.
1413-
*/
1414-
host->max_id = pvscsi_get_max_targets(adapter);
1415-
dev = pvscsi_dev(adapter);
1416-
dev_info(dev, "vmw_pvscsi: host->max_id: %u\n", host->max_id);
1417-
14181481
/*
14191482
* From this point on we should reset the adapter if anything goes
14201483
* wrong.
@@ -1488,12 +1551,15 @@ static int pvscsi_probe(struct pci_dev *pdev, const struct pci_device_id *id)
14881551
ll_adapter_reset(adapter);
14891552
out_release_resources:
14901553
pvscsi_release_resources(adapter);
1491-
out_free_host:
14921554
scsi_host_put(host);
14931555
out_disable_device:
14941556
pci_disable_device(pdev);
14951557

14961558
return error;
1559+
1560+
out_release_resources_and_disable:
1561+
pvscsi_release_resources(adapter);
1562+
goto out_disable_device;
14971563
}
14981564

14991565
static void __pvscsi_shutdown(struct pvscsi_adapter *adapter)

‎drivers/scsi/vmw_pvscsi.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626

2727
#include <linux/types.h>
2828

29-
#define PVSCSI_DRIVER_VERSION_STRING "1.0.4.0-k"
29+
#define PVSCSI_DRIVER_VERSION_STRING "1.0.5.0-k"
3030

3131
#define PVSCSI_MAX_NUM_SG_ENTRIES_PER_SEGMENT 128
3232

0 commit comments

Comments
 (0)