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_func_to_io { 51 struct hinic_hwif *hwif; 52 struct hinic_hwdev *hwdev; 53 struct hinic_ceqs ceqs; 54 55 struct hinic_wqs wqs; 56 57 struct hinic_wq *sq_wq; 58 struct hinic_wq *rq_wq; 59 60 struct hinic_qp *qps; 61 u16 max_qps; 62 63 u16 sq_depth; 64 u16 rq_depth; 65 66 void __iomem **sq_db; 67 void __iomem *db_base; 68 69 void *ci_addr_base; 70 dma_addr_t ci_dma_base; 71 72 struct hinic_free_db_area free_db_area; 73 74 void __iomem *cmdq_db_area[HINIC_MAX_CMDQ_TYPES]; 75 76 struct hinic_cmdqs cmdqs; 77 78 u16 max_vfs; 79 struct vf_data_storage *vf_infos; 80 u8 link_status; 81 }; 82 83 struct hinic_wq_page_size { 84 u8 status; 85 u8 version; 86 u8 rsvd0[6]; 87 88 u16 func_idx; 89 u8 ppf_idx; 90 u8 page_size; 91 92 u32 rsvd1; 93 }; 94 95 int hinic_set_wq_page_size(struct hinic_hwdev *hwdev, u16 func_idx, 96 u32 page_size); 97 98 int hinic_io_create_qps(struct hinic_func_to_io *func_to_io, 99 u16 base_qpn, int num_qps, 100 struct msix_entry *sq_msix_entries, 101 struct msix_entry *rq_msix_entries); 102 103 void hinic_io_destroy_qps(struct hinic_func_to_io *func_to_io, 104 int num_qps); 105 106 int hinic_io_init(struct hinic_func_to_io *func_to_io, 107 struct hinic_hwif *hwif, u16 max_qps, int num_ceqs, 108 struct msix_entry *ceq_msix_entries); 109 110 void hinic_io_free(struct hinic_func_to_io *func_to_io); 111 112 #endif 113