skd: Simplify the code for allocating DMA message buffers
authorBart Van Assche <bart.vanassche@wdc.com>
Thu, 17 Aug 2017 20:13:06 +0000 (13:13 -0700)
committerJens Axboe <axboe@kernel.dk>
Fri, 18 Aug 2017 14:45:29 +0000 (08:45 -0600)
dma_alloc_coherent() guarantees alignment on a page boundary so
no explicit alignment is needed to align on a 64 byte boundary.

Signed-off-by: Bart Van Assche <bart.vanassche@wdc.com>
Cc: Christoph Hellwig <hch@lst.de>
Cc: Hannes Reinecke <hare@suse.de>
Cc: Johannes Thumshirn <jthumshirn@suse.de>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
drivers/block/skd_main.c
drivers/block/skd_s1120.h

index 3fc6ec9477c7c80576297a98c20c43792091bf47..37b900c97b87ef1941f7a3cec048beca7024da66 100644 (file)
@@ -190,7 +190,6 @@ struct skd_fitmsg_context {
        u16 outstanding;
 
        u32 length;
-       u32 offset;
 
        u8 *msg_buf;
        dma_addr_t mb_dma_address;
@@ -2016,8 +2015,7 @@ static void skd_send_fitmsg(struct skd_device *skdev,
 
        dev_dbg(&skdev->pdev->dev, "dma address 0x%llx, busy=%d\n",
                skmsg->mb_dma_address, skdev->in_flight);
-       dev_dbg(&skdev->pdev->dev, "msg_buf 0x%p, offset %x\n", skmsg->msg_buf,
-               skmsg->offset);
+       dev_dbg(&skdev->pdev->dev, "msg_buf %p\n", skmsg->msg_buf);
 
        qcmd = skmsg->mb_dma_address;
        qcmd |= FIT_QCMD_QID_NORMAL;
@@ -3854,7 +3852,7 @@ static int skd_cons_skmsg(struct skd_device *skdev)
 
                skmsg->state = SKD_MSG_STATE_IDLE;
                skmsg->msg_buf = pci_alloc_consistent(skdev->pdev,
-                                                     SKD_N_FITMSG_BYTES + 64,
+                                                     SKD_N_FITMSG_BYTES,
                                                      &skmsg->mb_dma_address);
 
                if (skmsg->msg_buf == NULL) {
@@ -3862,13 +3860,10 @@ static int skd_cons_skmsg(struct skd_device *skdev)
                        goto err_out;
                }
 
-               skmsg->offset = (u32)((u64)skmsg->msg_buf &
-                                     (~FIT_QCMD_BASE_ADDRESS_MASK));
-               skmsg->msg_buf += ~FIT_QCMD_BASE_ADDRESS_MASK;
-               skmsg->msg_buf = (u8 *)((u64)skmsg->msg_buf &
-                                      FIT_QCMD_BASE_ADDRESS_MASK);
-               skmsg->mb_dma_address += ~FIT_QCMD_BASE_ADDRESS_MASK;
-               skmsg->mb_dma_address &= FIT_QCMD_BASE_ADDRESS_MASK;
+               WARN(((uintptr_t)skmsg->msg_buf | skmsg->mb_dma_address) &
+                    (FIT_QCMD_ALIGN - 1),
+                    "not aligned: msg_buf %p mb_dma_address %#llx\n",
+                    skmsg->msg_buf, skmsg->mb_dma_address);
                memset(skmsg->msg_buf, 0, SKD_N_FITMSG_BYTES);
 
                skmsg->next = &skmsg[1];
@@ -4230,8 +4225,6 @@ static void skd_free_skmsg(struct skd_device *skdev)
                skmsg = &skdev->skmsg_table[i];
 
                if (skmsg->msg_buf != NULL) {
-                       skmsg->msg_buf += skmsg->offset;
-                       skmsg->mb_dma_address += skmsg->offset;
                        pci_free_consistent(skdev->pdev, SKD_N_FITMSG_BYTES,
                                            skmsg->msg_buf,
                                            skmsg->mb_dma_address);
index f69d3d97744d633c7c13d06788e50bdbabc76d88..8044705cbbf94e7647e2447b298f65f16cc35517 100644 (file)
@@ -28,7 +28,7 @@
 #define  FIT_QCMD_MSGSIZE_128          (0x1 << 4)
 #define  FIT_QCMD_MSGSIZE_256          (0x2 << 4)
 #define  FIT_QCMD_MSGSIZE_512          (0x3 << 4)
-#define  FIT_QCMD_BASE_ADDRESS_MASK    (0xFFFFFFFFFFFFFFC0ull)
+#define  FIT_QCMD_ALIGN                        L1_CACHE_BYTES
 
 /*
  * Control, 32-bit r/w