1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3  * Huawei HiNIC PCI Express Linux driver
4  * Copyright(c) 2017 Huawei Technologies Co., Ltd
5  */
6 
7 #ifndef HINIC_HW_IO_H
8 #define HINIC_HW_IO_H
9 
10 #include <linux/types.h>
11 #include <linux/pci.h>
12 #include <linux/semaphore.h>
13 #include <linux/sizes.h>
14 
15 #include "hinic_hw_if.h"
16 #include "hinic_hw_eqs.h"
17 #include "hinic_hw_wq.h"
18 #include "hinic_hw_cmdq.h"
19 #include "hinic_hw_qp.h"
20 
21 #define HINIC_DB_PAGE_SIZE      SZ_4K
22 #define HINIC_DB_SIZE           SZ_4M
23 #define HINIC_HW_WQ_PAGE_SIZE	SZ_4K
24 #define HINIC_DEFAULT_WQ_PAGE_SIZE SZ_256K
25 
26 #define HINIC_DB_MAX_AREAS      (HINIC_DB_SIZE / HINIC_DB_PAGE_SIZE)
27 
28 enum hinic_db_type {
29 	HINIC_DB_CMDQ_TYPE,
30 	HINIC_DB_SQ_TYPE,
31 };
32 
33 enum hinic_io_path {
34 	HINIC_CTRL_PATH,
35 	HINIC_DATA_PATH,
36 };
37 
38 struct hinic_free_db_area {
39 	int             db_idx[HINIC_DB_MAX_AREAS];
40 
41 	int             alloc_pos;
42 	int             return_pos;
43 
44 	int             num_free;
45 
46 	/* Lock for getting db area */
47 	struct semaphore        idx_lock;
48 };
49 
50 struct hinic_nic_cfg {
51 	/* lock for getting nic cfg */
52 	struct mutex		cfg_mutex;
53 	bool			pause_set;
54 	u32			auto_neg;
55 	u32			rx_pause;
56 	u32			tx_pause;
57 };
58 
59 struct hinic_func_to_io {
60 	struct hinic_hwif       *hwif;
61 	struct hinic_hwdev      *hwdev;
62 	struct hinic_ceqs       ceqs;
63 
64 	struct hinic_wqs        wqs;
65 
66 	struct hinic_wq         *sq_wq;
67 	struct hinic_wq         *rq_wq;
68 
69 	struct hinic_qp         *qps;
70 	u16                     max_qps;
71 
72 	u16			sq_depth;
73 	u16			rq_depth;
74 
75 	void __iomem            **sq_db;
76 	void __iomem            *db_base;
77 
78 	void                    *ci_addr_base;
79 	dma_addr_t              ci_dma_base;
80 
81 	struct hinic_free_db_area       free_db_area;
82 
83 	void __iomem                    *cmdq_db_area[HINIC_MAX_CMDQ_TYPES];
84 
85 	struct hinic_cmdqs              cmdqs;
86 
87 	u16			max_vfs;
88 	struct vf_data_storage	*vf_infos;
89 	u8			link_status;
90 	struct hinic_nic_cfg	nic_cfg;
91 };
92 
93 struct hinic_wq_page_size {
94 	u8	status;
95 	u8	version;
96 	u8	rsvd0[6];
97 
98 	u16	func_idx;
99 	u8	ppf_idx;
100 	u8	page_size;
101 
102 	u32	rsvd1;
103 };
104 
105 int hinic_set_wq_page_size(struct hinic_hwdev *hwdev, u16 func_idx,
106 			   u32 page_size);
107 
108 int hinic_io_create_qps(struct hinic_func_to_io *func_to_io,
109 			u16 base_qpn, int num_qps,
110 			struct msix_entry *sq_msix_entries,
111 			struct msix_entry *rq_msix_entries);
112 
113 void hinic_io_destroy_qps(struct hinic_func_to_io *func_to_io,
114 			  int num_qps);
115 
116 int hinic_io_init(struct hinic_func_to_io *func_to_io,
117 		  struct hinic_hwif *hwif, u16 max_qps, int num_ceqs,
118 		  struct msix_entry *ceq_msix_entries);
119 
120 void hinic_io_free(struct hinic_func_to_io *func_to_io);
121 
122 #endif
123