Re: [PATCH 4/7] crypto: add hisilicon Queue Manager driver

2018-09-06 Thread Kenneth Lee
On Sun, Sep 02, 2018 at 07:15:07PM -0700, Randy Dunlap wrote:
> Date: Sun, 2 Sep 2018 19:15:07 -0700
> From: Randy Dunlap 
> To: Kenneth Lee , Jonathan Corbet ,
>  Herbert Xu , "David S . Miller"
>  , Joerg Roedel , Alex Williamson
>  , Kenneth Lee , Hao
>  Fang , Zhou Wang , Zaibo Xu
>  , Philippe Ombredanne , Greg
>  Kroah-Hartman , Thomas Gleixner
>  , linux-...@vger.kernel.org,
>  linux-ker...@vger.kernel.org, linux-cry...@vger.kernel.org,
>  iommu@lists.linux-foundation.org, k...@vger.kernel.org,
>  linux-accelerat...@lists.ozlabs.org, Lu Baolu ,
>  Sanjay Kumar 
> CC: linux...@huawei.com
> Subject: Re: [PATCH 4/7] crypto: add hisilicon Queue Manager driver
> User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101
>  Thunderbird/52.9.1
> Message-ID: <4e46a451-d1cd-ac68-84b4-20792fdbc...@infradead.org>
> 
> On 09/02/2018 05:52 PM, Kenneth Lee wrote:
> > diff --git a/drivers/crypto/hisilicon/Kconfig 
> > b/drivers/crypto/hisilicon/Kconfig
> > index 8ca9c503bcb0..02a6eef84101 100644
> > --- a/drivers/crypto/hisilicon/Kconfig
> > +++ b/drivers/crypto/hisilicon/Kconfig
> > @@ -1,4 +1,8 @@
> >  # SPDX-License-Identifier: GPL-2.0
> > +config CRYPTO_DEV_HISILICON
> > +   tristate "Support for HISILICON CRYPTO ACCELERATOR"
> > +   help
> > + Enable this to use Hisilicon Hardware Accelerators
> 
>   Accelerators.

Thanks, will change it in next version.

> 
> 
> -- 
> ~Randy

-- 
-Kenneth(Hisilicon)


本邮件及其附件含有华为公司的保密信息,仅限于发送给上面地址中列出的个人或群组。禁
止任何其他人以任何形式使用(包括但不限于全部或部分地泄露、复制、或散发)本邮件中
的信息。如果您错收了本邮件,请您立即电话或邮件通知发件人并删除本邮件!
This e-mail and its attachments contain confidential information from HUAWEI,
which is intended only for the person or entity whose address is listed above.
Any use of the 
information contained herein in any way (including, but not limited to, total or
partial disclosure, reproduction, or dissemination) by persons other than the
intended 
recipient(s) is prohibited. If you receive this e-mail in error, please notify
the sender by phone or email immediately and delete it!

___
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu

Re: [PATCH 4/7] crypto: add hisilicon Queue Manager driver

2018-09-02 Thread Randy Dunlap
On 09/02/2018 05:52 PM, Kenneth Lee wrote:
> diff --git a/drivers/crypto/hisilicon/Kconfig 
> b/drivers/crypto/hisilicon/Kconfig
> index 8ca9c503bcb0..02a6eef84101 100644
> --- a/drivers/crypto/hisilicon/Kconfig
> +++ b/drivers/crypto/hisilicon/Kconfig
> @@ -1,4 +1,8 @@
>  # SPDX-License-Identifier: GPL-2.0
> +config CRYPTO_DEV_HISILICON
> + tristate "Support for HISILICON CRYPTO ACCELERATOR"
> + help
> +   Enable this to use Hisilicon Hardware Accelerators

Accelerators.


-- 
~Randy
___
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu


[PATCH 4/7] crypto: add hisilicon Queue Manager driver

2018-09-02 Thread Kenneth Lee
From: Kenneth Lee 

Hisilicon QM is a general IP used by some Hisilicon accelerators. It
provides a general PCIE interface for the CPU and the accelerator to share
a group of queues.

This commit includes a library used by the accelerator driver to access
the QM hardware.

Signed-off-by: Kenneth Lee 
Signed-off-by: Zhou Wang 
Signed-off-by: Hao Fang 
---
 drivers/crypto/Makefile   |   2 +-
 drivers/crypto/hisilicon/Kconfig  |   8 +
 drivers/crypto/hisilicon/Makefile |   1 +
 drivers/crypto/hisilicon/qm.c | 820 ++
 drivers/crypto/hisilicon/qm.h | 110 
 5 files changed, 940 insertions(+), 1 deletion(-)
 create mode 100644 drivers/crypto/hisilicon/qm.c
 create mode 100644 drivers/crypto/hisilicon/qm.h

diff --git a/drivers/crypto/Makefile b/drivers/crypto/Makefile
index c23396f32c8a..f3a7abe42424 100644
--- a/drivers/crypto/Makefile
+++ b/drivers/crypto/Makefile
@@ -46,4 +46,4 @@ obj-$(CONFIG_CRYPTO_DEV_VMX) += vmx/
 obj-$(CONFIG_CRYPTO_DEV_BCM_SPU) += bcm/
 obj-$(CONFIG_CRYPTO_DEV_SAFEXCEL) += inside-secure/
 obj-$(CONFIG_CRYPTO_DEV_ARTPEC6) += axis/
-obj-y += hisilicon/
+obj-$(CONFIG_CRYPTO_DEV_HISILICON) += hisilicon/
diff --git a/drivers/crypto/hisilicon/Kconfig b/drivers/crypto/hisilicon/Kconfig
index 8ca9c503bcb0..02a6eef84101 100644
--- a/drivers/crypto/hisilicon/Kconfig
+++ b/drivers/crypto/hisilicon/Kconfig
@@ -1,4 +1,8 @@
 # SPDX-License-Identifier: GPL-2.0
+config CRYPTO_DEV_HISILICON
+   tristate "Support for HISILICON CRYPTO ACCELERATOR"
+   help
+ Enable this to use Hisilicon Hardware Accelerators
 
 config CRYPTO_DEV_HISI_SEC
tristate "Support for Hisilicon SEC crypto block cipher accelerator"
@@ -12,3 +16,7 @@ config CRYPTO_DEV_HISI_SEC
 
  To compile this as a module, choose M here: the module
  will be called hisi_sec.
+
+config CRYPTO_DEV_HISI_QM
+   tristate
+   depends on ARM64 && PCI
diff --git a/drivers/crypto/hisilicon/Makefile 
b/drivers/crypto/hisilicon/Makefile
index 463f46ace182..05e9052e0f52 100644
--- a/drivers/crypto/hisilicon/Makefile
+++ b/drivers/crypto/hisilicon/Makefile
@@ -1,2 +1,3 @@
 # SPDX-License-Identifier: GPL-2.0
 obj-$(CONFIG_CRYPTO_DEV_HISI_SEC) += sec/
+obj-$(CONFIG_CRYPTO_DEV_HISI_QM) += qm.o
diff --git a/drivers/crypto/hisilicon/qm.c b/drivers/crypto/hisilicon/qm.c
new file mode 100644
index ..ea618b4d0929
--- /dev/null
+++ b/drivers/crypto/hisilicon/qm.c
@@ -0,0 +1,820 @@
+// SPDX-License-Identifier: GPL-2.0+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include "qm.h"
+
+#define QM_DEF_Q_NUM   128
+
+/* eq/aeq irq enable */
+#define QM_VF_AEQ_INT_SOURCE   0x0
+#define QM_VF_AEQ_INT_MASK 0x4
+#define QM_VF_EQ_INT_SOURCE0x8
+#define QM_VF_EQ_INT_MASK  0xc
+
+/* mailbox */
+#define MAILBOX_CMD_SQC0x0
+#define MAILBOX_CMD_CQC0x1
+#define MAILBOX_CMD_EQC0x2
+#define MAILBOX_CMD_SQC_BT 0x4
+#define MAILBOX_CMD_CQC_BT 0x5
+
+#define MAILBOX_CMD_SEND_BASE  0x300
+#define MAILBOX_EVENT_SHIFT8
+#define MAILBOX_STATUS_SHIFT   9
+#define MAILBOX_BUSY_SHIFT 13
+#define MAILBOX_OP_SHIFT   14
+#define MAILBOX_QUEUE_SHIFT16
+
+/* sqc shift */
+#define SQ_HEAD_SHIFT  0
+#define SQ_TAIL_SHIFI  16
+#define SQ_HOP_NUM_SHIFT   0
+#define SQ_PAGE_SIZE_SHIFT 4
+#define SQ_BUF_SIZE_SHIFT  8
+#define SQ_SQE_SIZE_SHIFT  12
+#define SQ_HEAD_IDX_SIG_SHIFT  0
+#define SQ_TAIL_IDX_SIG_SHIFT  0
+#define SQ_CQN_SHIFT   0
+#define SQ_PRIORITY_SHIFT  0
+#define SQ_ORDERS_SHIFT4
+#define SQ_TYPE_SHIFT  8
+
+#define SQ_TYPE_MASK   0xf
+
+/* cqc shift */
+#define CQ_HEAD_SHIFT  0
+#define CQ_TAIL_SHIFI  16
+#define CQ_HOP_NUM_SHIFT   0
+#define CQ_PAGE_SIZE_SHIFT 4
+#define CQ_BUF_SIZE_SHIFT  8
+#define CQ_SQE_SIZE_SHIFT  12
+#define CQ_PASID   0
+#define CQ_HEAD_IDX_SIG_SHIFT  0
+#define CQ_TAIL_IDX_SIG_SHIFT  0
+#define CQ_CQN_SHIFT   0
+#define CQ_PRIORITY_SHIFT  16
+#define CQ_ORDERS_SHIFT0
+#define CQ_TYPE_SHIFT  0
+#define CQ_PHASE_SHIFT 0
+#define CQ_FLAG_SHIFT  1
+
+#define CQC_HEAD_INDEX(cqc)((cqc)->cq_head)
+#define CQC_PHASE(cqc) (((cqc)->dw6) & 0x1)
+#define CQC_CQ_ADDRESS(cqc)(((u64)((cqc)->cq_base_h) << 32) | \
+((cqc)->cq_base_l))
+#define CQC_PHASE_BIT  0x1
+
+/* eqc shift */
+#define MB_EQC_EQE_SHIFT   12
+#define MB_EQC_PHASE_SHIFT 

[RFC PATCH 4/7] crypto: add hisilicon Queue Manager driver

2018-08-01 Thread Kenneth Lee
From: Kenneth Lee 

Hisilicon QM is a general IP used by some Hisilicon accelerators. It
provides a general PCIE interface for the CPU and the accelerator to share
a group of queues.

This commit includes a library used by the accelerator driver to access
the QM hardware.

Signed-off-by: Kenneth Lee 
Signed-off-by: Zhou Wang 
Signed-off-by: Hao Fang 
---
 drivers/crypto/Kconfig|   2 +
 drivers/crypto/Makefile   |   1 +
 drivers/crypto/hisilicon/Kconfig  |   8 +
 drivers/crypto/hisilicon/Makefile |   1 +
 drivers/crypto/hisilicon/qm.c | 855 ++
 drivers/crypto/hisilicon/qm.h | 111 
 6 files changed, 978 insertions(+)
 create mode 100644 drivers/crypto/hisilicon/Kconfig
 create mode 100644 drivers/crypto/hisilicon/Makefile
 create mode 100644 drivers/crypto/hisilicon/qm.c
 create mode 100644 drivers/crypto/hisilicon/qm.h

diff --git a/drivers/crypto/Kconfig b/drivers/crypto/Kconfig
index 43cccf6aff61..8da1e3170eb4 100644
--- a/drivers/crypto/Kconfig
+++ b/drivers/crypto/Kconfig
@@ -746,4 +746,6 @@ config CRYPTO_DEV_CCREE
  cryptographic operations on the system REE.
  If unsure say Y.
 
+source "drivers/crypto/hisilicon/Kconfig"
+
 endif # CRYPTO_HW
diff --git a/drivers/crypto/Makefile b/drivers/crypto/Makefile
index 7ae87b4f6c8d..32e9bf64a42f 100644
--- a/drivers/crypto/Makefile
+++ b/drivers/crypto/Makefile
@@ -45,3 +45,4 @@ obj-$(CONFIG_CRYPTO_DEV_VMX) += vmx/
 obj-$(CONFIG_CRYPTO_DEV_BCM_SPU) += bcm/
 obj-$(CONFIG_CRYPTO_DEV_SAFEXCEL) += inside-secure/
 obj-$(CONFIG_CRYPTO_DEV_ARTPEC6) += axis/
+obj-$(CONFIG_CRYPTO_DEV_HISILICON) += hisilicon/
diff --git a/drivers/crypto/hisilicon/Kconfig b/drivers/crypto/hisilicon/Kconfig
new file mode 100644
index ..0dd30f84b90e
--- /dev/null
+++ b/drivers/crypto/hisilicon/Kconfig
@@ -0,0 +1,8 @@
+config CRYPTO_DEV_HISILICON
+   tristate "Support for HISILICON CRYPTO ACCELERATOR"
+   help
+ Enable this to use Hisilicon Hardware Accelerators
+
+config CRYPTO_DEV_HISI_QM
+   tristate
+   depends on ARM64 && PCI
diff --git a/drivers/crypto/hisilicon/Makefile 
b/drivers/crypto/hisilicon/Makefile
new file mode 100644
index ..3378afc11703
--- /dev/null
+++ b/drivers/crypto/hisilicon/Makefile
@@ -0,0 +1 @@
+obj-$(CONFIG_CRYPTO_DEV_HISI_QM) += qm.o
diff --git a/drivers/crypto/hisilicon/qm.c b/drivers/crypto/hisilicon/qm.c
new file mode 100644
index ..e779bc661500
--- /dev/null
+++ b/drivers/crypto/hisilicon/qm.c
@@ -0,0 +1,855 @@
+// SPDX-License-Identifier: GPL-2.0+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include "qm.h"
+
+#define QM_DEF_Q_NUM   128
+
+/* eq/aeq irq enable */
+#define QM_VF_AEQ_INT_SOURCE   0x0
+#define QM_VF_AEQ_INT_MASK 0x4
+#define QM_VF_EQ_INT_SOURCE0x8
+#define QM_VF_EQ_INT_MASK  0xc
+
+/* mailbox */
+#define MAILBOX_CMD_SQC0x0
+#define MAILBOX_CMD_CQC0x1
+#define MAILBOX_CMD_EQC0x2
+#define MAILBOX_CMD_AEQC   0x3
+#define MAILBOX_CMD_SQC_BT 0x4
+#define MAILBOX_CMD_CQC_BT 0x5
+
+#define MAILBOX_CMD_SEND_BASE  0x300
+#define MAILBOX_EVENT_SHIFT8
+#define MAILBOX_STATUS_SHIFT   9
+#define MAILBOX_BUSY_SHIFT 13
+#define MAILBOX_OP_SHIFT   14
+#define MAILBOX_QUEUE_SHIFT16
+
+/* sqc shift */
+#define SQ_HEAD_SHIFT  0
+#define SQ_TAIL_SHIFI  16
+#define SQ_HOP_NUM_SHIFT   0
+#define SQ_PAGE_SIZE_SHIFT 4
+#define SQ_BUF_SIZE_SHIFT  8
+#define SQ_SQE_SIZE_SHIFT  12
+#define SQ_HEAD_IDX_SIG_SHIFT  0
+#define SQ_TAIL_IDX_SIG_SHIFT  0
+#define SQ_CQN_SHIFT   0
+#define SQ_PRIORITY_SHIFT  0
+#define SQ_ORDERS_SHIFT4
+#define SQ_TYPE_SHIFT  8
+
+#define SQ_TYPE_MASK   0xf
+
+/* cqc shift */
+#define CQ_HEAD_SHIFT  0
+#define CQ_TAIL_SHIFI  16
+#define CQ_HOP_NUM_SHIFT   0
+#define CQ_PAGE_SIZE_SHIFT 4
+#define CQ_BUF_SIZE_SHIFT  8
+#define CQ_SQE_SIZE_SHIFT  12
+#define CQ_PASID   0
+#define CQ_HEAD_IDX_SIG_SHIFT  0
+#define CQ_TAIL_IDX_SIG_SHIFT  0
+#define CQ_CQN_SHIFT   0
+#define CQ_PRIORITY_SHIFT  16
+#define CQ_ORDERS_SHIFT0
+#define CQ_TYPE_SHIFT  0
+#define CQ_PHASE_SHIFT 0
+#define CQ_FLAG_SHIFT  1
+
+#define CQC_HEAD_INDEX(cqc)((cqc)->cq_head)
+#define CQC_PHASE(cqc) (((cqc)->dw6) & 0x1)
+#define CQC_CQ_ADDRESS(cqc)(((u64)((cqc)->cq_base_h) << 32) | \
+((cqc)->cq_base_l))
+#define CQC_PHASE_BIT