mtip32xx: fixes and cleanups
Various low hanging fruit, kicked of by seeing one of the few remaining req->special users.
Compile tested only.
PATCH 1/9 mtip32xx: move the blk_rq_map_sg call to mtip_hw_submit_io
We have all arguments at hand in mtip_hw_submit_io, so keep the rq to sg mapping close to the dma_map_sg call.
--- drivers/block/mtip32xx/mtip32xx.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-)
drivers/block/mtip32xx/mtip32xx.c +4 -7
@@ -2171,7 +2171,6 @@ static int mtip_hw_ioctl(struct driver_data *dd, unsigned int cmd,* @dd Pointer to the driver data structure. * @start First sector to read. * @nsect Number of sectors to read. -* @nents Number of entries in scatter list for the read command. * @tag The tag of this read command. * @callback Pointer to the function that should be called * when the read completes.
@@ -2183,7 +2182,7 @@ static int mtip_hw_ioctl(struct driver_data *dd, unsigned int cmd,* None */ static void mtip_hw_submit_io (struct driver_data *dd,struct request *rq, -struct mtip_cmd *command,int nents, +struct mtip_cmd *command,struct blk_mq_hw_ctx *hctx) {struct host_to_dev_fis *fis;
@@ -2191,8 +2190,10 @@ static void mtip_hw_submit_io(struct driver_data *dd, struct request *rq,int dma_dir =rq_data_dir (rq) ==READ ?DMA_FROM_DEVICE :DMA_TO_DEVICE ;u64 start =blk_rq_pos (rq);unsigned int nsect =blk_rq_sectors (rq); +unsigned int nents;/* Map the scatter list for DMA access */ + nents =blk_rq_map_sg (hctx->queue, rq, command->sg); nents =dma_map_sg (&dd->pdev->dev, command->sg, nents, dma_dir);prefetch (&port->flags);
@@ -3548,7 +3549,6 @@ static int mtip_submit_request(struct blk_mq_hw_ctx *hctx, struct request *rq) {struct driver_data *dd = hctx->queue->queuedata;struct mtip_cmd *cmd =blk_mq_rq_to_pdu (rq); -unsigned int nents;if (is_se_active (dd))return -ENODATA ;
@@ -3579,11 +3579,8 @@ static int mtip_submit_request(struct blk_mq_hw_ctx *hctx, struct request *rq)return 0 ; } -/* Create the scatter list for this request. */ - nents =blk_rq_map_sg (hctx->queue, rq, cmd->sg); -/* Issue the read/write. */ -mtip_hw_submit_io (dd, rq, cmd, nents, hctx); +mtip_hw_submit_io (dd, rq, cmd, hctx);return 0 ; }
Signature · 1 line
2.19.1
PATCH 2/9 mtip32xx: merge mtip_submit_request into mtip_queue_rq
In reply to Christoph HellwigFactor out a new is_stopped helper that matches the existing is_se_active helper, and merge the trivial amount of remaining code into the only caller. This also allows better error handling by returning a BLK_STS_* directly instead of explicitly calling blk_mq_end_request, and moving blk_mq_start_request closer to the actual issue to hardware.
--- drivers/block/mtip32xx/mtip32xx.c | 78 +++++++++++-------------------- 1 file changed, 28 insertions(+), 50 deletions(-)
drivers/block/mtip32xx/mtip32xx.c +28 -50
@@ -3534,54 +3534,24 @@ static inline bool is_se_active(struct driver_data *dd)return false; } -/* -* Block layer make request function. -* -* This function is called by the kernel to process a BIO for -* the P320 device. -* -* @queue Pointer to the request queue. Unused other than to obtain -* the driver data structure. -* @rq Pointer to the request. -* -*/ -static int mtip_submit_request (struct blk_mq_hw_ctx *hctx,struct request *rq) +static inline bool is_stopped (struct driver_data *dd,struct request *rq) { -struct driver_data *dd = hctx->queue->queuedata; -struct mtip_cmd *cmd =blk_mq_rq_to_pdu (rq); - -if (is_se_active (dd)) -return -ENODATA ; - -if (unlikely (dd->dd_flag &MTIP_DDF_STOP_IO )) { -if (unlikely (test_bit (MTIP_DDF_REMOVE_PENDING_BIT , - &dd->dd_flag))) { -return -ENXIO ; - } -if (unlikely (test_bit (MTIP_DDF_OVER_TEMP_BIT , &dd->dd_flag))) { -return -ENODATA ; - } -if (unlikely (test_bit (MTIP_DDF_WRITE_PROTECT_BIT , - &dd->dd_flag) && -rq_data_dir (rq))) { -return -ENODATA ; - } -if (unlikely (test_bit (MTIP_DDF_SEC_LOCK_BIT , &dd->dd_flag) || -test_bit (MTIP_DDF_REBUILD_FAILED_BIT , &dd->dd_flag))) -return -ENODATA ; - } - -if (req_op (rq) ==REQ_OP_DISCARD ) { -int err; +if (likely (!(dd->dd_flag &MTIP_DDF_STOP_IO ))) +return false; - err =mtip_send_trim (dd,blk_rq_pos (rq),blk_rq_sectors (rq)); -blk_mq_end_request (rq, err ?BLK_STS_IOERR :BLK_STS_OK ); -return 0 ; - } +if (test_bit (MTIP_DDF_REMOVE_PENDING_BIT , &dd->dd_flag)) +return true; +if (test_bit (MTIP_DDF_OVER_TEMP_BIT , &dd->dd_flag)) +return true; +if (test_bit (MTIP_DDF_WRITE_PROTECT_BIT , &dd->dd_flag) && +rq_data_dir (rq)) +return true; +if (test_bit (MTIP_DDF_SEC_LOCK_BIT , &dd->dd_flag)) +return true; +if (test_bit (MTIP_DDF_REBUILD_FAILED_BIT , &dd->dd_flag)) +return true; -/* Issue the read/write. */ -mtip_hw_submit_io (dd, rq, cmd, hctx); -return 0 ; +return false; } static bool mtip_check_unal_depth(struct blk_mq_hw_ctx *hctx,
@@ -3647,8 +3617,9 @@ static blk_status_t mtip_issue_reserved_cmd(struct blk_mq_hw_ctx *hctx,static blk_status_t mtip_queue_rq (struct blk_mq_hw_ctx *hctx,const struct blk_mq_queue_data *bd) { +struct driver_data *dd = hctx->queue->queuedata;struct request *rq = bd->rq; -int ret; +struct mtip_cmd *cmd =blk_mq_rq_to_pdu (rq);mtip_init_cmd_header (rq);
@@ -3658,12 +3629,19 @@ static blk_status_t mtip_queue_rq(struct blk_mq_hw_ctx *hctx,if (unlikely (mtip_check_unal_depth (hctx, rq)))return BLK_STS_RESOURCE ; +if (is_se_active (dd) ||is_stopped (dd, rq)) +return BLK_STS_IOERR ; +blk_mq_start_request (rq); - ret =mtip_submit_request (hctx, rq); -if (likely (!ret)) -return BLK_STS_OK ; -return BLK_STS_IOERR ; +if (req_op (rq) ==REQ_OP_DISCARD ) { +if (mtip_send_trim (dd,blk_rq_pos (rq),blk_rq_sectors (rq)) <0 ) +return BLK_STS_IOERR ; + }else { +mtip_hw_submit_io (dd, rq, cmd, hctx); + } + +return BLK_STS_OK ; } static void mtip_free_cmd(struct blk_mq_tag_set *set, struct request *rq,
Signature · 1 line
2.19.1
PATCH 3/9 mtip32xx: return a blk_status_t from mtip_send_trim
In reply to Christoph HellwigThis allows for better error propagation and simpler code.
--- drivers/block/mtip32xx/mtip32xx.c | 30 +++++++++++------------------- 1 file changed, 11 insertions(+), 19 deletions(-)
drivers/block/mtip32xx/mtip32xx.c +11 -19
@@ -1423,23 +1423,19 @@ static int mtip_get_smart_attr(struct mtip_port *port, unsigned int id,* @dd pointer to driver_data structure * @lba starting lba * @len # of 512b sectors to trim -* -* return value -* -ENOMEM Out of dma memory -* -EINVAL Invalid parameters passed in, trim not supported -* -EIO Error submitting trim request to hw */ -static int mtip_send_trim (struct driver_data *dd,unsigned int lba, -unsigned int len) +static blk_status_t mtip_send_trim (struct driver_data *dd,unsigned int lba, +unsigned int len) { -int i, rv =0 ;u64 tlba, tlen, sect_left;struct mtip_trim_entry *buf;dma_addr_t dma_addr;struct host_to_dev_fis fis; +blk_status_t ret =BLK_STS_OK ; +int i;if (!len || dd->trim_supp == false) -return -EINVAL ; +return BLK_STS_IOERR ;/* Trim request too big */ WARN_ON (len > (MTIP_MAX_TRIM_ENTRY_LEN *MTIP_MAX_TRIM_ENTRIES ));
@@ -1454,7 +1450,7 @@ static int mtip_send_trim(struct driver_data *dd, unsigned int lba, buf =dmam_alloc_coherent (&dd->pdev->dev,ATA_SECT_SIZE , &dma_addr,GFP_KERNEL );if (!buf) -return -ENOMEM ; +return BLK_STS_RESOURCE ;memset (buf,0 ,ATA_SECT_SIZE ); for (i = 0, sect_left = len, tlba = lba;
@@ -1486,10 +1482,10 @@ static int mtip_send_trim(struct driver_data *dd, unsigned int lba, ATA_SECT_SIZE, 0, MTIP_TRIM_TIMEOUT_MS) < 0) - rv = -EIO ; + ret =BLK_STS_IOERR ;dmam_free_coherent (&dd->pdev->dev,ATA_SECT_SIZE , buf, dma_addr); -return rv; +return ret; }/*
@@ -3634,13 +3630,9 @@ static blk_status_t mtip_queue_rq(struct blk_mq_hw_ctx *hctx,blk_mq_start_request (rq); -if (req_op (rq) ==REQ_OP_DISCARD ) { -if (mtip_send_trim (dd,blk_rq_pos (rq),blk_rq_sectors (rq)) <0 ) -return BLK_STS_IOERR ; - }else { -mtip_hw_submit_io (dd, rq, cmd, hctx); - } - +if (req_op (rq) ==REQ_OP_DISCARD ) +return mtip_send_trim (dd,blk_rq_pos (rq),blk_rq_sectors (rq)); +mtip_hw_submit_io (dd, rq, cmd, hctx);return BLK_STS_OK ; }
Signature · 1 line
2.19.1
PATCH 4/9 mtip32xx: remove __force_bit2int
In reply to Christoph HellwigThere is no good excuse not to use proper __le16/32 types.
--- drivers/block/mtip32xx/mtip32xx.c | 33 ++++++++++++------------------- drivers/block/mtip32xx/mtip32xx.h | 28 ++++++++++++-------------- 2 files changed, 26 insertions(+), 35 deletions(-)
drivers/block/mtip32xx/mtip32xx.c +13 -20
@@ -181,9 +181,9 @@ static void mtip_init_cmd_header(struct request *rq) (sizeof (struct mtip_cmd_hdr ) * rq->tag);if (test_bit (MTIP_PF_HOST_CAP_64 , &dd->port->flags)) - cmd->command_header->ctbau = __force_bit2int cpu_to_le32((cmd->command_dma >> 16) >> 16); + cmd->command_header->ctbau =cpu_to_le32 ((cmd->command_dma >>16 ) >>16 ); - cmd->command_header->ctba = __force_bit2int cpu_to_le32(cmd->command_dma & 0xFFFFFFFF); + cmd->command_header->ctba =cpu_to_le32 (cmd->command_dma &0xFFFFFFFF ); }static struct mtip_cmd *mtip_get_int_command (struct driver_data *dd)
@@ -1459,8 +1459,8 @@ static blk_status_t mtip_send_trim(struct driver_data *dd, unsigned int lba, tlen = (sect_left >=MTIP_MAX_TRIM_ENTRY_LEN ?MTIP_MAX_TRIM_ENTRY_LEN : sect_left); - buf[i].lba = __force_bit2int cpu_to_le32(tlba); - buf[i].range = __force_bit2int cpu_to_le16(tlen); + buf[i].lba =cpu_to_le32 (tlba); + buf[i].range =cpu_to_le16 (tlen); tlba += tlen; sect_left -= tlen; }
@@ -1590,11 +1590,9 @@ static inline void fill_command_sg(struct driver_data *dd,if (dma_len >0x400000 )dev_err (&dd->pdev->dev,"DMA segment length truncated\n" ); - command_sg->info = __force_bit2int -cpu_to_le32 ((dma_len-1 ) &0x3FFFFF ); - command_sg->dba = __force_bit2int -cpu_to_le32 (sg_dma_address (sg)); - command_sg->dba_upper = __force_bit2int + command_sg->info =cpu_to_le32 ((dma_len-1 ) &0x3FFFFF ); + command_sg->dba =cpu_to_le32 (sg_dma_address (sg)); + command_sg->dba_upper =cpu_to_le32 ((sg_dma_address (sg) >>16 ) >>16 ); command_sg++; sg++;
@@ -2231,8 +2229,7 @@ static void mtip_hw_submit_io(struct driver_data *dd, struct request *rq,/* Populate the command header */ command->command_header->opts = - __force_bit2int cpu_to_le32( - (nents <<16 ) |5 |AHCI_CMD_PREFETCH ); +cpu_to_le32 ((nents <<16 ) |5 |AHCI_CMD_PREFETCH ); command->command_header->byte_count =0 ; command->direction = dma_dir;
@@ -3586,20 +3583,16 @@ static blk_status_t mtip_issue_reserved_cmd(struct blk_mq_hw_ctx *hctx,return BLK_STS_RESOURCE ;/* Populate the SG list */ - cmd->command_header->opts = - __force_bit2int cpu_to_le32(icmd->opts | icmd->fis_len); + cmd->command_header->opts =cpu_to_le32 (icmd->opts | icmd->fis_len);if (icmd->buf_len) { command_sg = cmd->command +AHCI_CMD_TBL_HDR_SZ ; - command_sg->info = - __force_bit2int cpu_to_le32((icmd->buf_len-1) & 0x3FFFFF); - command_sg->dba = - __force_bit2int cpu_to_le32(icmd->buffer & 0xFFFFFFFF); + command_sg->info =cpu_to_le32 ((icmd->buf_len-1 ) &0x3FFFFF ); + command_sg->dba =cpu_to_le32 (icmd->buffer &0xFFFFFFFF ); command_sg->dba_upper = - __force_bit2int cpu_to_le32((icmd->buffer >> 16) >> 16); +cpu_to_le32 ((icmd->buffer >>16 ) >>16 ); - cmd->command_header->opts |= - __force_bit2int cpu_to_le32((1 << 16)); + cmd->command_header->opts |=cpu_to_le32 ((1 <<16 )); }/* Populate the command header */
drivers/block/mtip32xx/mtip32xx.h +13 -15
@@ -126,8 +126,6 @@#define MTIP_DFS_MAX_BUF_SIZE 1024 -#define __force_bit2int (unsigned int __force) -enum {/* below are bit numbers in 'flags' defined in mtip_port */ MTIP_PF_IC_ACTIVE_BIT =0 ,/* pio/ioctl */
@@ -200,9 +198,9 @@ struct mtip_work {#define MTIP_MAX_TRIM_ENTRY_LEN 0xfff8struct mtip_trim_entry { -u32 lba;/* starting lba of region */ -u16 rsvd;/* unused */ -u16 range;/* # of 512b blocks to trim */ +__le32 lba;/* starting lba of region */ +__le16 rsvd;/* unused */ +__le16 range;/* # of 512b blocks to trim */ } __packed;struct mtip_trim {
@@ -278,24 +276,24 @@ struct mtip_cmd_hdr {* - Bit 5 Unused in this implementation. * - Bits 4:0 Length of the command FIS in DWords (DWord = 4 bytes). */ -unsigned int opts; +__le32 opts;/* This field is unsed when using NCQ. */ union { -unsigned int byte_count; -unsigned int status; +__le32 byte_count; +__le32 status; };/* * Lower 32 bits of the command table address associated with this * header. The command table addresses must be 128 byte aligned. */ -unsigned int ctba; +__le32 ctba;/* * If 64 bit addressing is used this field is the upper 32 bits * of the command table address associated with this command. */ -unsigned int ctbau; +__le32 ctbau;/* Reserved and unused. */ -unsigned int res[4 ]; +u32 res[4 ]; };/* Command scatter gather structure (PRD). */
@@ -305,21 +303,21 @@ struct mtip_cmd_sg {* address must be 8 byte aligned signified by bits 2:0 being * set to 0. */ -unsigned int dba; +__le32 dba;/* * When 64 bit addressing is used this field is the upper * 32 bits of the data buffer address. */ -unsigned int dba_upper; +__le32 dba_upper;/* Unused. */ -unsigned int reserved; +__le32 reserved;/* * Bit 31: interrupt when this data block has been transferred. * Bits 30..22: reserved * Bits 21..0: byte count (minus 1). For P320 the byte count must be * 8 byte aligned signified by bits 2:0 being set to 1. */ -unsigned int info; +__le32 info; };struct mtip_port ;
Signature · 1 line
2.19.1
PATCH 5/9 mtip32xx: add missing endianess annotations on struct smart_attr
In reply to Christoph Hellwig--- drivers/block/mtip32xx/mtip32xx.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/block/mtip32xx/mtip32xx.h +2 -2
@@ -172,10 +172,10 @@ enum {struct smart_attr {u8 attr_id; -u16 flags; +__le16 flags;u8 cur;u8 worst; -u32 data; +__le32 data;u8 res[3 ]; } __packed;
Signature · 1 line
2.19.1
PATCH 6/9 mtip32xx: remove mtip_init_cmd_header
In reply to Christoph HellwigThere isn't much need for this helper - we can just calculate the offset for the command header once late in the submission path and fill out the ctba and ctbau fields there.
--- drivers/block/mtip32xx/mtip32xx.c | 44 +++++++++++-------------------- drivers/block/mtip32xx/mtip32xx.h | 5 ---- 2 files changed, 15 insertions(+), 34 deletions(-)
drivers/block/mtip32xx/mtip32xx.c +15 -29
@@ -168,24 +168,6 @@ static bool mtip_check_surprise_removal(struct pci_dev *pdev)return false;/* device present */ } -/* we have to use runtime tag to setup command header */ -static void mtip_init_cmd_header (struct request *rq) -{ -struct driver_data *dd = rq->q->queuedata; -struct mtip_cmd *cmd =blk_mq_rq_to_pdu (rq); - -/* Point the command headers at the command tables. */ - cmd->command_header = dd->port->command_list + - (sizeof (struct mtip_cmd_hdr ) * rq->tag); - cmd->command_header_dma = dd->port->command_list_dma + - (sizeof (struct mtip_cmd_hdr ) * rq->tag); - -if (test_bit (MTIP_PF_HOST_CAP_64 , &dd->port->flags)) - cmd->command_header->ctbau =cpu_to_le32 ((cmd->command_dma >>16 ) >>16 ); - - cmd->command_header->ctba =cpu_to_le32 (cmd->command_dma &0xFFFFFFFF ); -} -static struct mtip_cmd *mtip_get_int_command (struct driver_data *dd) {struct request *rq;
@@ -197,9 +179,6 @@ static struct mtip_cmd *mtip_get_int_command(struct driver_data *dd)if (IS_ERR (rq))return NULL ; -/* Internal cmd isn't submitted via .queue_rq */ -mtip_init_cmd_header (rq); -return blk_mq_rq_to_pdu (rq); }
@@ -2179,6 +2158,8 @@ static void mtip_hw_submit_io(struct driver_data *dd, struct request *rq,struct mtip_cmd *command, struct blk_mq_hw_ctx *hctx) { + struct mtip_cmd_hdr *hdr = + dd->port->command_list +sizeof (struct mtip_cmd_hdr ) * rq->tag;struct host_to_dev_fis *fis;struct mtip_port *port = dd->port;int dma_dir =rq_data_dir (rq) ==READ ?DMA_FROM_DEVICE :DMA_TO_DEVICE ;
@@ -2228,9 +2209,11 @@ static void mtip_hw_submit_io(struct driver_data *dd, struct request *rq, fis->device |=1 <<7 ;/* Populate the command header */ - command->command_header->opts = -cpu_to_le32 ((nents <<16 ) |5 |AHCI_CMD_PREFETCH ); - command->command_header->byte_count =0 ; + hdr->ctba =cpu_to_le32 (command->command_dma &0xFFFFFFFF ); +if (test_bit (MTIP_PF_HOST_CAP_64 , &dd->port->flags)) + hdr->ctbau =cpu_to_le32 ((command->command_dma >>16 ) >>16 ); + hdr->opts =cpu_to_le32 ((nents <<16 ) |5 |AHCI_CMD_PREFETCH ); + hdr->byte_count =0 ; command->direction = dma_dir;
@@ -3577,13 +3560,18 @@ static blk_status_t mtip_issue_reserved_cmd(struct blk_mq_hw_ctx *hctx,struct driver_data *dd = hctx->queue->queuedata;struct mtip_int_cmd *icmd = rq->special;struct mtip_cmd *cmd =blk_mq_rq_to_pdu (rq); +struct mtip_cmd_hdr *hdr = + dd->port->command_list +sizeof (struct mtip_cmd_hdr ) * rq->tag;struct mtip_cmd_sg *command_sg;if (mtip_commands_active (dd->port))return BLK_STS_RESOURCE ; + hdr->ctba =cpu_to_le32 (cmd->command_dma &0xFFFFFFFF ); +if (test_bit (MTIP_PF_HOST_CAP_64 , &dd->port->flags)) + hdr->ctbau =cpu_to_le32 ((cmd->command_dma >>16 ) >>16 );/* Populate the SG list */ - cmd->command_header->opts =cpu_to_le32 (icmd->opts | icmd->fis_len); + hdr->opts =cpu_to_le32 (icmd->opts | icmd->fis_len);if (icmd->buf_len) { command_sg = cmd->command +AHCI_CMD_TBL_HDR_SZ ;
@@ -3592,11 +3580,11 @@ static blk_status_t mtip_issue_reserved_cmd(struct blk_mq_hw_ctx *hctx, command_sg->dba_upper =cpu_to_le32 ((icmd->buffer >>16 ) >>16 ); - cmd->command_header->opts |=cpu_to_le32 ((1 <<16 )); + hdr->opts |=cpu_to_le32 ((1 <<16 )); }/* Populate the command header */ - cmd->command_header->byte_count =0 ; + hdr->byte_count =0 ;blk_mq_start_request (rq);mtip_issue_non_ncq_command (dd->port, rq->tag);
@@ -3610,8 +3598,6 @@ static blk_status_t mtip_queue_rq(struct blk_mq_hw_ctx *hctx,struct request *rq = bd->rq;struct mtip_cmd *cmd =blk_mq_rq_to_pdu (rq); -mtip_init_cmd_header (rq); -if (blk_rq_is_passthrough (rq))return mtip_issue_reserved_cmd (hctx, rq);
drivers/block/mtip32xx/mtip32xx.h +0 -5
@@ -323,11 +323,6 @@ struct mtip_port;/* Structure used to describe a command. */ struct mtip_cmd { - -struct mtip_cmd_hdr *command_header;/* ptr to command header entry */ - -dma_addr_t command_header_dma;/* corresponding physical address */ -void *command;/* ptr to command table entry */ dma_addr_t command_dma;/* corresponding physical address */
Signature · 1 line
2.19.1
PATCH 7/9 mtip32xx: remove mtip_get_int_command
In reply to Christoph HellwigMerging this function into the only callers makes the code flow easier.
--- drivers/block/mtip32xx/mtip32xx.c | 24 +++++++----------------- 1 file changed, 7 insertions(+), 17 deletions(-)
drivers/block/mtip32xx/mtip32xx.c +7 -17
@@ -168,20 +168,6 @@ static bool mtip_check_surprise_removal(struct pci_dev *pdev)return false;/* device present */ } -static struct mtip_cmd *mtip_get_int_command (struct driver_data *dd) -{ -struct request *rq; - -if (mtip_check_surprise_removal (dd->pdev)) -return NULL ; - - rq =blk_mq_alloc_request (dd->queue,REQ_OP_DRV_IN ,BLK_MQ_REQ_RESERVED ); -if (IS_ERR (rq)) -return NULL ; - -return blk_mq_rq_to_pdu (rq); -} -static struct mtip_cmd *mtip_cmd_from_tag (struct driver_data *dd,unsigned int tag) {
@@ -1002,12 +988,15 @@ static int mtip_exec_internal_command(struct mtip_port *port,return -EFAULT ; } - int_cmd =mtip_get_int_command (dd); -if (!int_cmd) { +if (mtip_check_surprise_removal (dd->pdev)) +return -EFAULT ; + + rq =blk_mq_alloc_request (dd->queue,REQ_OP_DRV_IN ,BLK_MQ_REQ_RESERVED ); +if (IS_ERR (rq)) {dbg_printk (MTIP_DRV_NAME "Unable to allocate tag for PIO cmd\n" );return -EFAULT ; } - rq =blk_mq_rq_from_pdu (int_cmd); + rq->special = &icmd;set_bit (MTIP_PF_IC_ACTIVE_BIT , &port->flags);
@@ -1029,6 +1018,7 @@ static int mtip_exec_internal_command(struct mtip_port *port, }/* Copy the command to the command table */ + int_cmd =blk_mq_rq_to_pdu (rq);memcpy (int_cmd->command, fis, fis_len*4 ); rq->timeout = timeout;
Signature · 1 line
2.19.1
PATCH 8/9 mtip32xx: don't use req->special
In reply to Christoph HellwigInstead create add to the icmd into struct mtip_cmd which can be unioned with the scatterlist used for the normal I/O path.
--- drivers/block/mtip32xx/mtip32xx.c | 5 ++--- drivers/block/mtip32xx/mtip32xx.h | 7 ++++++- 2 files changed, 8 insertions(+), 4 deletions(-)
drivers/block/mtip32xx/mtip32xx.c +2 -3
@@ -997,8 +997,6 @@ static int mtip_exec_internal_command(struct mtip_port *port,return -EFAULT ; } - rq->special = &icmd; -set_bit (MTIP_PF_IC_ACTIVE_BIT , &port->flags);if (fis->command ==ATA_CMD_SEC_ERASE_PREP )
@@ -1019,6 +1017,7 @@ static int mtip_exec_internal_command(struct mtip_port *port,/* Copy the command to the command table */ int_cmd =blk_mq_rq_to_pdu (rq); + int_cmd->icmd = &icmd;memcpy (int_cmd->command, fis, fis_len*4 ); rq->timeout = timeout;
@@ -3548,8 +3547,8 @@ static blk_status_t mtip_issue_reserved_cmd(struct blk_mq_hw_ctx *hctx, struct request *rq) {struct driver_data *dd = hctx->queue->queuedata; -struct mtip_int_cmd *icmd = rq->special;struct mtip_cmd *cmd =blk_mq_rq_to_pdu (rq); +struct mtip_int_cmd *icmd = cmd->icmd;struct mtip_cmd_hdr *hdr = dd->port->command_list +sizeof (struct mtip_cmd_hdr ) * rq->tag;struct mtip_cmd_sg *command_sg;
drivers/block/mtip32xx/mtip32xx.h +6 -1
@@ -321,6 +321,8 @@ struct mtip_cmd_sg { };struct mtip_port ; +struct mtip_int_cmd ; +/* Structure used to describe a command. */ struct mtip_cmd {void *command;/* ptr to command table entry */
@@ -331,7 +333,10 @@ struct mtip_cmd {int unaligned;/* command is unaligned on 4k boundary */ -struct scatterlist sg[MTIP_MAX_SG ];/* Scatter list entries */ +union { +struct scatterlist sg[MTIP_MAX_SG ];/* Scatter list entries */ +struct mtip_int_cmd *icmd; + };int retries;/* The number of retries left for this command. */
Signature · 1 line
2.19.1
PATCH 9/9 mtip32xxx: use for_each_sg
In reply to Christoph HellwigUse the proper helper instead of manually iterating the scatterlist, which is broken in the presence of chained S/G lists.
--- drivers/block/mtip32xx/mtip32xx.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/block/mtip32xx/mtip32xx.c +2 -3
@@ -1549,11 +1549,11 @@ static inline void fill_command_sg(struct driver_data *dd,int n;unsigned int dma_len;struct mtip_cmd_sg *command_sg; -struct scatterlist *sg = command->sg; +struct scatterlist *sg; command_sg = command->command +AHCI_CMD_TBL_HDR_SZ ; -for (n =0 ; n < nents; n++) { +for_each_sg (command->sg, sg, nents, n) { dma_len =sg_dma_len (sg);if (dma_len >0x400000 ) dev_err(&dd->pdev->dev,
@@ -1563,7 +1563,6 @@ static inline void fill_command_sg(struct driver_data *dd, command_sg->dba_upper =cpu_to_le32 ((sg_dma_address (sg) >>16 ) >>16 ); command_sg++; - sg++; } }
Signature · 1 line
2.19.1
Jens Axboe
maintainerQuoted 4 lines · Christoph Hellwig
Various low hanging fruit, kicked of by seeing one of the few remaining
req->specialusers.Compile tested only.
Looks good to me - as it so happens, I do have a few of these cards. Tested working fine after the patches.
Signature · 1 line
Jens Axboe