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_QP_H
17 #define HINIC_HW_QP_H
18 
19 #include <linux/types.h>
20 #include <linux/sizes.h>
21 #include <linux/pci.h>
22 #include <linux/skbuff.h>
23 
24 #include "hinic_hw_if.h"
25 #include "hinic_hw_wqe.h"
26 #include "hinic_hw_wq.h"
27 #include "hinic_hw_qp_ctxt.h"
28 
29 #define HINIC_SQ_WQEBB_SIZE                     64
30 #define HINIC_RQ_WQEBB_SIZE                     32
31 
32 #define HINIC_SQ_PAGE_SIZE                      SZ_4K
33 #define HINIC_RQ_PAGE_SIZE                      SZ_4K
34 
35 #define HINIC_SQ_DEPTH                          SZ_4K
36 #define HINIC_RQ_DEPTH                          SZ_4K
37 
38 #define HINIC_RX_BUF_SZ                         2048
39 
40 struct hinic_sq {
41 	struct hinic_hwif       *hwif;
42 
43 	struct hinic_wq         *wq;
44 
45 	u32                     irq;
46 	u16                     msix_entry;
47 
48 	void                    *hw_ci_addr;
49 	dma_addr_t              hw_ci_dma_addr;
50 
51 	void __iomem            *db_base;
52 
53 	struct sk_buff          **saved_skb;
54 };
55 
56 struct hinic_rq {
57 	struct hinic_hwif       *hwif;
58 
59 	struct hinic_wq         *wq;
60 
61 	u32                     irq;
62 	u16                     msix_entry;
63 
64 	size_t                  buf_sz;
65 
66 	struct sk_buff          **saved_skb;
67 
68 	struct hinic_rq_cqe     **cqe;
69 	dma_addr_t              *cqe_dma;
70 
71 	u16                     *pi_virt_addr;
72 	dma_addr_t              pi_dma_addr;
73 };
74 
75 struct hinic_qp {
76 	struct hinic_sq         sq;
77 	struct hinic_rq         rq;
78 
79 	u16     q_id;
80 };
81 
82 void hinic_qp_prepare_header(struct hinic_qp_ctxt_header *qp_ctxt_hdr,
83 			     enum hinic_qp_ctxt_type ctxt_type,
84 			     u16 num_queues, u16 max_queues);
85 
86 void hinic_sq_prepare_ctxt(struct hinic_sq_ctxt *sq_ctxt,
87 			   struct hinic_sq *sq, u16 global_qid);
88 
89 void hinic_rq_prepare_ctxt(struct hinic_rq_ctxt *rq_ctxt,
90 			   struct hinic_rq *rq, u16 global_qid);
91 
92 int hinic_init_sq(struct hinic_sq *sq, struct hinic_hwif *hwif,
93 		  struct hinic_wq *wq, struct msix_entry *entry, void *ci_addr,
94 		  dma_addr_t ci_dma_addr, void __iomem *db_base);
95 
96 void hinic_clean_sq(struct hinic_sq *sq);
97 
98 int hinic_init_rq(struct hinic_rq *rq, struct hinic_hwif *hwif,
99 		  struct hinic_wq *wq, struct msix_entry *entry);
100 
101 void hinic_clean_rq(struct hinic_rq *rq);
102 
103 #endif
104