Re: [PATCH V2 net-next 12/21] net-next/hinic: Add qp resources

2017-07-23 Thread Aviad Krawczyk
Hi David,

Strange that checkpatch.pl --strict didn't warn about it.
We will fix it.

Thanks for review,
Aviad

On 7/20/2017 2:13 AM, David Miller wrote:
> From: Aviad Krawczyk 
> Date: Wed, 19 Jul 2017 17:19:10 +0800
> 
>> diff --git a/drivers/net/ethernet/huawei/hinic/Makefile 
>> b/drivers/net/ethernet/huawei/hinic/Makefile
>> index 519382b..24728f0 100644
>> --- a/drivers/net/ethernet/huawei/hinic/Makefile
>> +++ b/drivers/net/ethernet/huawei/hinic/Makefile
>> @@ -1,5 +1,5 @@
>>  obj-$(CONFIG_HINIC) += hinic.o
>>  
>>  hinic-y := hinic_main.o hinic_tx.o hinic_rx.o hinic_port.o hinic_hw_dev.o \
>> -   hinic_hw_io.o hinic_hw_wq.o hinic_hw_mgmt.o hinic_hw_api_cmd.o \
>> -   hinic_hw_eqs.o hinic_hw_if.o
>> \ No newline at end of file
>> +   hinic_hw_io.o hinic_hw_qp.o hinic_hw_wq.o hinic_hw_mgmt.o \
>> +   hinic_hw_api_cmd.o hinic_hw_eqs.o hinic_hw_if.o
>> \ No newline at end of file
> 
> Please add the missing newline to the end of this Makefile so that these 
> patches
> don't keep emitting this message.
> 
> .
> 



Re: [PATCH V2 net-next 12/21] net-next/hinic: Add qp resources

2017-07-19 Thread David Miller
From: Aviad Krawczyk 
Date: Wed, 19 Jul 2017 17:19:10 +0800

> diff --git a/drivers/net/ethernet/huawei/hinic/Makefile 
> b/drivers/net/ethernet/huawei/hinic/Makefile
> index 519382b..24728f0 100644
> --- a/drivers/net/ethernet/huawei/hinic/Makefile
> +++ b/drivers/net/ethernet/huawei/hinic/Makefile
> @@ -1,5 +1,5 @@
>  obj-$(CONFIG_HINIC) += hinic.o
>  
>  hinic-y := hinic_main.o hinic_tx.o hinic_rx.o hinic_port.o hinic_hw_dev.o \
> -hinic_hw_io.o hinic_hw_wq.o hinic_hw_mgmt.o hinic_hw_api_cmd.o \
> -hinic_hw_eqs.o hinic_hw_if.o
> \ No newline at end of file
> +hinic_hw_io.o hinic_hw_qp.o hinic_hw_wq.o hinic_hw_mgmt.o \
> +hinic_hw_api_cmd.o hinic_hw_eqs.o hinic_hw_if.o
> \ No newline at end of file

Please add the missing newline to the end of this Makefile so that these patches
don't keep emitting this message.


[PATCH V2 net-next 12/21] net-next/hinic: Add qp resources

2017-07-19 Thread Aviad Krawczyk
Create the resources for queue pair operations: doorbell area,
consumer index address and producer index address.

Signed-off-by: Aviad Krawczyk 
Signed-off-by: Zhao Chen 
---
 drivers/net/ethernet/huawei/hinic/Makefile  |   4 +-
 drivers/net/ethernet/huawei/hinic/hinic_hw_if.h |   1 +
 drivers/net/ethernet/huawei/hinic/hinic_hw_io.c | 167 ++-
 drivers/net/ethernet/huawei/hinic/hinic_hw_io.h |  27 +++
 drivers/net/ethernet/huawei/hinic/hinic_hw_qp.c | 264 
 drivers/net/ethernet/huawei/hinic/hinic_hw_qp.h |  60 +-
 6 files changed, 518 insertions(+), 5 deletions(-)
 create mode 100644 drivers/net/ethernet/huawei/hinic/hinic_hw_qp.c

diff --git a/drivers/net/ethernet/huawei/hinic/Makefile 
b/drivers/net/ethernet/huawei/hinic/Makefile
index 519382b..24728f0 100644
--- a/drivers/net/ethernet/huawei/hinic/Makefile
+++ b/drivers/net/ethernet/huawei/hinic/Makefile
@@ -1,5 +1,5 @@
 obj-$(CONFIG_HINIC) += hinic.o
 
 hinic-y := hinic_main.o hinic_tx.o hinic_rx.o hinic_port.o hinic_hw_dev.o \
-  hinic_hw_io.o hinic_hw_wq.o hinic_hw_mgmt.o hinic_hw_api_cmd.o \
-  hinic_hw_eqs.o hinic_hw_if.o
\ No newline at end of file
+  hinic_hw_io.o hinic_hw_qp.o hinic_hw_wq.o hinic_hw_mgmt.o \
+  hinic_hw_api_cmd.o hinic_hw_eqs.o hinic_hw_if.o
\ No newline at end of file
diff --git a/drivers/net/ethernet/huawei/hinic/hinic_hw_if.h 
b/drivers/net/ethernet/huawei/hinic/hinic_hw_if.h
index 88df3c0..89f71e5 100644
--- a/drivers/net/ethernet/huawei/hinic/hinic_hw_if.h
+++ b/drivers/net/ethernet/huawei/hinic/hinic_hw_if.h
@@ -137,6 +137,7 @@
 #define HINIC_IS_PPF(hwif)  (HINIC_FUNC_TYPE(hwif) == HINIC_PPF)
 
 #define HINIC_PCI_CFG_REGS_BAR  0
+#define HINIC_PCI_DB_BAR4
 
 #define HINIC_PCIE_ST_DISABLE   0
 #define HINIC_PCIE_AT_DISABLE   0
diff --git a/drivers/net/ethernet/huawei/hinic/hinic_hw_io.c 
b/drivers/net/ethernet/huawei/hinic/hinic_hw_io.c
index 419fcb0..fa789da 100644
--- a/drivers/net/ethernet/huawei/hinic/hinic_hw_io.c
+++ b/drivers/net/ethernet/huawei/hinic/hinic_hw_io.c
@@ -13,17 +13,93 @@
  *
  */
 
+#include 
 #include 
 #include 
 #include 
 #include 
 #include 
+#include 
+#include 
+#include 
 
 #include "hinic_hw_if.h"
 #include "hinic_hw_wq.h"
 #include "hinic_hw_qp.h"
 #include "hinic_hw_io.h"
 
+#define CI_Q_ADDR_SIZE  sizeof(u32)
+
+#define CI_ADDR(base_addr, q_id)((base_addr) + \
+(q_id) * CI_Q_ADDR_SIZE)
+
+#define CI_TABLE_SIZE(num_qps)  ((num_qps) * CI_Q_ADDR_SIZE)
+
+#define DB_IDX(db, db_base) \
+   (((unsigned long)(db) - (unsigned long)(db_base)) / HINIC_DB_PAGE_SIZE)
+
+static void init_db_area_idx(struct hinic_free_db_area *free_db_area)
+{
+   int i;
+
+   for (i = 0; i < HINIC_DB_MAX_AREAS; i++)
+   free_db_area->db_idx[i] = i;
+
+   free_db_area->alloc_pos = 0;
+   free_db_area->return_pos = HINIC_DB_MAX_AREAS;
+
+   free_db_area->num_free = HINIC_DB_MAX_AREAS;
+
+   sema_init(_db_area->idx_lock, 1);
+}
+
+static int get_db_area(struct hinic_func_to_io *func_to_io,
+  void __iomem **db_base)
+{
+   struct hinic_free_db_area *free_db_area = _to_io->free_db_area;
+   int pos, idx;
+
+   down(_db_area->idx_lock);
+
+   free_db_area->num_free--;
+
+   if (free_db_area->num_free < 0) {
+   free_db_area->num_free++;
+   up(_db_area->idx_lock);
+   return -ENOMEM;
+   }
+
+   pos = free_db_area->alloc_pos++;
+   pos &= HINIC_DB_MAX_AREAS - 1;
+
+   idx = free_db_area->db_idx[pos];
+
+   free_db_area->db_idx[pos] = -1;
+
+   up(_db_area->idx_lock);
+
+   *db_base = func_to_io->db_base + idx * HINIC_DB_PAGE_SIZE;
+   return 0;
+}
+
+static void return_db_area(struct hinic_func_to_io *func_to_io,
+  void __iomem *db_base)
+{
+   struct hinic_free_db_area *free_db_area = _to_io->free_db_area;
+   int pos, idx = DB_IDX(db_base, func_to_io->db_base);
+
+   down(_db_area->idx_lock);
+
+   pos = free_db_area->return_pos++;
+   pos &= HINIC_DB_MAX_AREAS - 1;
+
+   free_db_area->db_idx[pos] = idx;
+
+   free_db_area->num_free++;
+
+   up(_db_area->idx_lock);
+}
+
 /**
  * init_qp - Initialize a Queue Pair
  * @func_to_io: func to io channel that holds the IO components
@@ -41,6 +117,9 @@ static int init_qp(struct hinic_func_to_io *func_to_io,
 {
struct hinic_hwif *hwif = func_to_io->hwif;
struct pci_dev *pdev = hwif->pdev;
+   void *ci_addr_base = func_to_io->ci_addr_base;
+   dma_addr_t ci_dma_base = func_to_io->ci_dma_base;
+   void __iomem *db_base;
int err;
 
qp->q_id = q_id;
@@ -61,8 +140,40 @@ static int init_qp(struct hinic_func_to_io *func_to_io,
goto rq_alloc_err;
}
 
+   err =