Skip to content

Commit e94b45d

Browse files
Christoph Hellwigaxboe
authored andcommitted
block: move dma_pad_mask into queue_limits
dma_pad_mask is a queue_limits by all ways of looking at it, so move it there and set it through the atomic queue limits APIs. Add a little helper that takes the alignment and pad into account to simplify the code that is touched a bit. Note that there never was any need for the > check in blk_queue_update_dma_pad, this probably was just copy and paste from dma_update_dma_alignment. Signed-off-by: Christoph Hellwig <[email protected]> Reviewed-by: Damien Le Moal <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jens Axboe <[email protected]>
1 parent abfc9d8 commit e94b45d

File tree

8 files changed

+21
-33
lines changed

8 files changed

+21
-33
lines changed

block/bio-integrity.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ int bio_integrity_map_user(struct bio *bio, void __user *ubuf, ssize_t bytes,
312312
u32 seed)
313313
{
314314
struct request_queue *q = bdev_get_queue(bio->bi_bdev);
315-
unsigned int align = q->dma_pad_mask | queue_dma_alignment(q);
315+
unsigned int align = blk_lim_dma_alignment_and_pad(&q->limits);
316316
struct page *stack_pages[UIO_FASTIOV], **pages = stack_pages;
317317
struct bio_vec stack_vec[UIO_FASTIOV], *bvec = stack_vec;
318318
unsigned int direction, nr_bvecs;

block/blk-map.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -634,7 +634,7 @@ int blk_rq_map_user_iov(struct request_queue *q, struct request *rq,
634634
const struct iov_iter *iter, gfp_t gfp_mask)
635635
{
636636
bool copy = false, map_bvec = false;
637-
unsigned long align = q->dma_pad_mask | queue_dma_alignment(q);
637+
unsigned long align = blk_lim_dma_alignment_and_pad(&q->limits);
638638
struct bio *bio = NULL;
639639
struct iov_iter i;
640640
int ret = -EINVAL;

block/blk-settings.c

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -768,23 +768,6 @@ bool queue_limits_stack_integrity(struct queue_limits *t,
768768
}
769769
EXPORT_SYMBOL_GPL(queue_limits_stack_integrity);
770770

771-
/**
772-
* blk_queue_update_dma_pad - update pad mask
773-
* @q: the request queue for the device
774-
* @mask: pad mask
775-
*
776-
* Update dma pad mask.
777-
*
778-
* Appending pad buffer to a request modifies the last entry of a
779-
* scatter list such that it includes the pad buffer.
780-
**/
781-
void blk_queue_update_dma_pad(struct request_queue *q, unsigned int mask)
782-
{
783-
if (mask > q->dma_pad_mask)
784-
q->dma_pad_mask = mask;
785-
}
786-
EXPORT_SYMBOL(blk_queue_update_dma_pad);
787-
788771
/**
789772
* blk_set_queue_depth - tell the block layer about the device queue depth
790773
* @q: the request queue for the device

drivers/ata/libata-scsi.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1024,7 +1024,6 @@ EXPORT_SYMBOL_GPL(ata_scsi_dma_need_drain);
10241024
int ata_scsi_dev_config(struct scsi_device *sdev, struct queue_limits *lim,
10251025
struct ata_device *dev)
10261026
{
1027-
struct request_queue *q = sdev->request_queue;
10281027
int depth = 1;
10291028

10301029
if (!ata_id_has_unload(dev->id))
@@ -1038,7 +1037,7 @@ int ata_scsi_dev_config(struct scsi_device *sdev, struct queue_limits *lim,
10381037
sdev->sector_size = ATA_SECT_SIZE;
10391038

10401039
/* set DMA padding */
1041-
blk_queue_update_dma_pad(q, ATA_DMA_PAD_SZ - 1);
1040+
lim->dma_pad_mask = ATA_DMA_PAD_SZ - 1;
10421041

10431042
/* make room for appending the drain */
10441043
lim->max_segments--;

drivers/ata/pata_macio.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -816,7 +816,7 @@ static int pata_macio_device_configure(struct scsi_device *sdev,
816816
/* OHare has issues with non cache aligned DMA on some chipsets */
817817
if (priv->kind == controller_ohare) {
818818
lim->dma_alignment = 31;
819-
blk_queue_update_dma_pad(sdev->request_queue, 31);
819+
lim->dma_pad_mask = 31;
820820

821821
/* Tell the world about it */
822822
ata_dev_info(dev, "OHare alignment limits applied\n");
@@ -831,7 +831,7 @@ static int pata_macio_device_configure(struct scsi_device *sdev,
831831
if (priv->kind == controller_sh_ata6 || priv->kind == controller_k2_ata6) {
832832
/* Allright these are bad, apply restrictions */
833833
lim->dma_alignment = 15;
834-
blk_queue_update_dma_pad(sdev->request_queue, 15);
834+
lim->dma_pad_mask = 15;
835835

836836
/* We enable MWI and hack cache line size directly here, this
837837
* is specific to this chipset and not normal values, we happen

drivers/scsi/scsi_lib.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1139,9 +1139,9 @@ blk_status_t scsi_alloc_sgtables(struct scsi_cmnd *cmd)
11391139
*/
11401140
count = __blk_rq_map_sg(rq->q, rq, cmd->sdb.table.sgl, &last_sg);
11411141

1142-
if (blk_rq_bytes(rq) & rq->q->dma_pad_mask) {
1142+
if (blk_rq_bytes(rq) & rq->q->limits.dma_pad_mask) {
11431143
unsigned int pad_len =
1144-
(rq->q->dma_pad_mask & ~blk_rq_bytes(rq)) + 1;
1144+
(rq->q->limits.dma_pad_mask & ~blk_rq_bytes(rq)) + 1;
11451145

11461146
last_sg->length += pad_len;
11471147
cmd->extra_len += pad_len;

drivers/ufs/core/ufshcd.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5193,17 +5193,19 @@ static int ufshcd_change_queue_depth(struct scsi_device *sdev, int depth)
51935193
}
51945194

51955195
/**
5196-
* ufshcd_slave_configure - adjust SCSI device configurations
5196+
* ufshcd_device_configure - adjust SCSI device configurations
51975197
* @sdev: pointer to SCSI device
5198+
* @lim: queue limits
51985199
*
51995200
* Return: 0 (success).
52005201
*/
5201-
static int ufshcd_slave_configure(struct scsi_device *sdev)
5202+
static int ufshcd_device_configure(struct scsi_device *sdev,
5203+
struct queue_limits *lim)
52025204
{
52035205
struct ufs_hba *hba = shost_priv(sdev->host);
52045206
struct request_queue *q = sdev->request_queue;
52055207

5206-
blk_queue_update_dma_pad(q, PRDT_DATA_BYTE_COUNT_PAD - 1);
5208+
lim->dma_pad_mask = PRDT_DATA_BYTE_COUNT_PAD - 1;
52075209

52085210
/*
52095211
* Block runtime-pm until all consumers are added.
@@ -8907,7 +8909,7 @@ static const struct scsi_host_template ufshcd_driver_template = {
89078909
.queuecommand = ufshcd_queuecommand,
89088910
.mq_poll = ufshcd_poll,
89098911
.slave_alloc = ufshcd_slave_alloc,
8910-
.slave_configure = ufshcd_slave_configure,
8912+
.device_configure = ufshcd_device_configure,
89118913
.slave_destroy = ufshcd_slave_destroy,
89128914
.change_queue_depth = ufshcd_change_queue_depth,
89138915
.eh_abort_handler = ufshcd_abort,

include/linux/blkdev.h

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,7 @@ struct queue_limits {
401401
* due to possible offsets.
402402
*/
403403
unsigned int dma_alignment;
404+
unsigned int dma_pad_mask;
404405

405406
struct blk_integrity integrity;
406407
};
@@ -509,8 +510,6 @@ struct request_queue {
509510
*/
510511
int id;
511512

512-
unsigned int dma_pad_mask;
513-
514513
/*
515514
* queue settings
516515
*/
@@ -981,7 +980,6 @@ extern int blk_stack_limits(struct queue_limits *t, struct queue_limits *b,
981980
sector_t offset);
982981
void queue_limits_stack_bdev(struct queue_limits *t, struct block_device *bdev,
983982
sector_t offset, const char *pfx);
984-
extern void blk_queue_update_dma_pad(struct request_queue *, unsigned int);
985983
extern void blk_queue_rq_timeout(struct request_queue *, unsigned int);
986984

987985
struct blk_independent_access_ranges *
@@ -1433,10 +1431,16 @@ static inline bool bdev_iter_is_aligned(struct block_device *bdev,
14331431
bdev_logical_block_size(bdev) - 1);
14341432
}
14351433

1434+
static inline int blk_lim_dma_alignment_and_pad(struct queue_limits *lim)
1435+
{
1436+
return lim->dma_alignment | lim->dma_pad_mask;
1437+
}
1438+
14361439
static inline int blk_rq_aligned(struct request_queue *q, unsigned long addr,
14371440
unsigned int len)
14381441
{
1439-
unsigned int alignment = queue_dma_alignment(q) | q->dma_pad_mask;
1442+
unsigned int alignment = blk_lim_dma_alignment_and_pad(&q->limits);
1443+
14401444
return !(addr & alignment) && !(len & alignment);
14411445
}
14421446

0 commit comments

Comments
 (0)