[PATCH v2 1/2] libata-scsi: use dev->max_sectors from libata-core appropriately

2016-08-12 Thread tom . ty89
From: Tom Yan Currently we use dev->max_sectors to set max_hw_sectors, which is actually supposed to be a host controller limit (that get set by the host controller driver like ahci, and if not it would be the fallback SCSI_DEFAULT_MAX_SECTORS). That means we have been doing the wrong thing. The

[PATCH v2 2/2] sd: check BLK_DEF_MAX_SECTORS against max_dev_sectors

2016-08-12 Thread tom . ty89
From: Tom Yan The SCSI disk driver sets max_sectors to BLK_DEF_MAX_SECTORS when the device does not report Optimal Transfer Length. However, it checks only whether it is smaller than max_hw_sectors, but not max_dev_sectors. Signed-off-by: Tom Yan diff --git a/drivers/scsi/sd.c b/drivers/scsi/s

[PATCH 2/2] sd: check BLK_DEF_MAX_SECTORS against max_dev_sectors

2016-08-12 Thread tom . ty89
From: Tom Yan The SCSI disk driver sets max_sector to BLK_DEF_MAX_SECTORS when the device does not report Optimal Transfer Length. However, it checks only whether it is smaller than max_hw_sectors, but not max_dev_sectors. Signed-off-by: Tom Yan diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd

[PATCH 1/2] libata-scsi: use dev->max_sectors from libata-core appropriately

2016-08-12 Thread tom . ty89
From: Tom Yan Currently we use dev->max_sectors to set max_hw_sectors, which is actually supposed to be a host controller limit (that get set by the host controller driver like ahci, and if not it would be the fallback SCSI_DEFAULT_MAX_SECTORS). That means we have been doing the wrong thing. The

[RFC] sd: dynamically adjust SD_MAX_WS16_BLOCKS as per the actual logical block size

2016-08-11 Thread tom . ty89
From: Tom Yan WRITE SAME (16) command can technically handle up to 32-bit number of blocks. However, since 32-bit is also the limitation of the maximum number of bytes that can be represented in the block layer, the current SD_MAX_WS16_BLOCKS was hence derived from the technical limit devided by

[RFC] libata-scsi: make sure Maximum Write Same Length is not too large

2016-08-11 Thread tom . ty89
From: Tom Yan Currently we advertise Maximum Write Same Length based on the maximum number of sectors that one-block TRIM payload can cover. The field are used to derived discard_max_bytes and write_same_max_bytes limits in the block layer, which currently can at max be 0x (32-bit). Howe

[PATCH v2 1/2] libata-scsi: set max_hw_sectors again only when dev->max_sectors is set

2016-08-09 Thread tom . ty89
From: Tom Yan When the request queue is initialized (see __scsi_init_queue() in scsi_lib.c), the block layer limit max_hw_sectors is set to shost->max_sectors, which will be set to the "machine infinity" SCSI_DEFAULT_MAX_SECTORS (currently 1024) if sht->max_sectors is not set (see scsi_host_alloc

[PATCH v2 2/2] libata-core: do not set dev->max_sectors for LBA48 devices

2016-08-09 Thread tom . ty89
From: Tom Yan Currently block layer limit max_hw_sectors is set to ATA_MAX_SECTORS_LBA48 (65535), for devices with LBA48 support. However, block layer limit max_sectors (which is the effective one; also adjustable, upper-bounded by max_hw_sectors) is set to BLK_DEF_MAX_SECTORS (currently 2560) b

[PATCH 2/2] libata: do not set max_sectors for LBA48 device

2016-08-09 Thread tom . ty89
From: Tom Yan Along with commit 1dc8fff24187 ("libata-scsi: do not call blk_queue_max_hw_sectors()"), devices with LBA48 support will have max_sectors set to SCSI_DEFAULT_MAX_SECTORS (currently 1024), by the scsi driver. Note that the "max_sectors" here is actually the block layer limit "max_hw_

[PATCH 1/2] libata-scsi: do not call blk_queue_max_hw_sectors()

2016-08-09 Thread tom . ty89
From: Tom Yan We should just let the scsi driver (hosts.c) call the function. It has better heuristic anyway (i.e. use SCSI_DEFAULT_MAX_SECTORS as fallback when max_sectors is not set). diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c index 2bdb5da..495d916 100644 --- a/drivers