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_wq.h" 26 #include "hinic_hw_cmdq.h" 27 #include "hinic_hw_qp.h" 28 29 #define HINIC_DB_PAGE_SIZE SZ_4K 30 #define HINIC_DB_SIZE SZ_4M 31 32 #define HINIC_DB_MAX_AREAS (HINIC_DB_SIZE / HINIC_DB_PAGE_SIZE) 33 34 struct hinic_free_db_area { 35 int db_idx[HINIC_DB_MAX_AREAS]; 36 37 int alloc_pos; 38 int return_pos; 39 40 int num_free; 41 42 /* Lock for getting db area */ 43 struct semaphore idx_lock; 44 }; 45 46 struct hinic_func_to_io { 47 struct hinic_hwif *hwif; 48 49 struct hinic_wqs wqs; 50 51 struct hinic_wq *sq_wq; 52 struct hinic_wq *rq_wq; 53 54 struct hinic_qp *qps; 55 u16 max_qps; 56 57 void __iomem **sq_db; 58 void __iomem *db_base; 59 60 void *ci_addr_base; 61 dma_addr_t ci_dma_base; 62 63 struct hinic_free_db_area free_db_area; 64 65 void __iomem *cmdq_db_area[HINIC_MAX_CMDQ_TYPES]; 66 67 struct hinic_cmdqs cmdqs; 68 }; 69 70 int hinic_io_create_qps(struct hinic_func_to_io *func_to_io, 71 u16 base_qpn, int num_qps, 72 struct msix_entry *sq_msix_entries, 73 struct msix_entry *rq_msix_entries); 74 75 void hinic_io_destroy_qps(struct hinic_func_to_io *func_to_io, 76 int num_qps); 77 78 int hinic_io_init(struct hinic_func_to_io *func_to_io, 79 struct hinic_hwif *hwif, u16 max_qps, int num_ceqs, 80 struct msix_entry *ceq_msix_entries); 81 82 void hinic_io_free(struct hinic_func_to_io *func_to_io); 83 84 #endif 85