GNU Linux-libre 4.19.264-gnu1
[releases.git] / drivers / net / ethernet / huawei / hinic / hinic_hw_io.h
1 /*
2  * Huawei HiNIC PCI Express Linux driver
3  * Copyright(c) 2017 Huawei Technologies Co., Ltd
4  *
5  * This program is free software; you can redistribute it and/or modify it
6  * under the terms and conditions of the GNU General Public License,
7  * version 2, as published by the Free Software Foundation.
8  *
9  * This program is distributed in the hope it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12  * for more details.
13  *
14  */
15
16 #ifndef HINIC_HW_IO_H
17 #define HINIC_HW_IO_H
18
19 #include <linux/types.h>
20 #include <linux/pci.h>
21 #include <linux/semaphore.h>
22 #include <linux/sizes.h>
23
24 #include "hinic_hw_if.h"
25 #include "hinic_hw_eqs.h"
26 #include "hinic_hw_wq.h"
27 #include "hinic_hw_cmdq.h"
28 #include "hinic_hw_qp.h"
29
30 #define HINIC_DB_PAGE_SIZE      SZ_4K
31 #define HINIC_DB_SIZE           SZ_4M
32
33 #define HINIC_DB_MAX_AREAS      (HINIC_DB_SIZE / HINIC_DB_PAGE_SIZE)
34
35 enum hinic_db_type {
36         HINIC_DB_CMDQ_TYPE,
37         HINIC_DB_SQ_TYPE,
38 };
39
40 enum hinic_io_path {
41         HINIC_CTRL_PATH,
42         HINIC_DATA_PATH,
43 };
44
45 struct hinic_free_db_area {
46         int             db_idx[HINIC_DB_MAX_AREAS];
47
48         int             alloc_pos;
49         int             return_pos;
50
51         int             num_free;
52
53         /* Lock for getting db area */
54         struct semaphore        idx_lock;
55 };
56
57 struct hinic_func_to_io {
58         struct hinic_hwif       *hwif;
59
60         struct hinic_ceqs       ceqs;
61
62         struct hinic_wqs        wqs;
63
64         struct hinic_wq         *sq_wq;
65         struct hinic_wq         *rq_wq;
66
67         struct hinic_qp         *qps;
68         u16                     max_qps;
69
70         void __iomem            **sq_db;
71         void __iomem            *db_base;
72
73         void                    *ci_addr_base;
74         dma_addr_t              ci_dma_base;
75
76         struct hinic_free_db_area       free_db_area;
77
78         void __iomem                    *cmdq_db_area[HINIC_MAX_CMDQ_TYPES];
79
80         struct hinic_cmdqs              cmdqs;
81 };
82
83 int hinic_io_create_qps(struct hinic_func_to_io *func_to_io,
84                         u16 base_qpn, int num_qps,
85                         struct msix_entry *sq_msix_entries,
86                         struct msix_entry *rq_msix_entries);
87
88 void hinic_io_destroy_qps(struct hinic_func_to_io *func_to_io,
89                           int num_qps);
90
91 int hinic_io_init(struct hinic_func_to_io *func_to_io,
92                   struct hinic_hwif *hwif, u16 max_qps, int num_ceqs,
93                   struct msix_entry *ceq_msix_entries);
94
95 void hinic_io_free(struct hinic_func_to_io *func_to_io);
96
97 #endif