xref: /openbmc/linux/drivers/infiniband/hw/irdma/puda.h (revision 301306a9)
1 /* SPDX-License-Identifier: GPL-2.0 or Linux-OpenIB */
2 /* Copyright (c) 2015 - 2020 Intel Corporation */
3 #ifndef IRDMA_PUDA_H
4 #define IRDMA_PUDA_H
5 
6 #define IRDMA_IEQ_MPA_FRAMING	6
7 #define IRDMA_TCP_OFFSET	40
8 #define IRDMA_IPV4_PAD		20
9 #define IRDMA_MRK_BLK_SZ	512
10 
11 enum puda_rsrc_type {
12 	IRDMA_PUDA_RSRC_TYPE_ILQ = 1,
13 	IRDMA_PUDA_RSRC_TYPE_IEQ,
14 	IRDMA_PUDA_RSRC_TYPE_MAX, /* Must be last entry */
15 };
16 
17 enum puda_rsrc_complete {
18 	PUDA_CQ_CREATED = 1,
19 	PUDA_QP_CREATED,
20 	PUDA_TX_COMPLETE,
21 	PUDA_RX_COMPLETE,
22 	PUDA_HASH_CRC_COMPLETE,
23 };
24 
25 struct irdma_sc_dev;
26 struct irdma_sc_qp;
27 struct irdma_sc_cq;
28 
29 struct irdma_puda_cmpl_info {
30 	struct irdma_qp_uk *qp;
31 	u8 q_type;
32 	u8 l3proto;
33 	u8 l4proto;
34 	u16 vlan;
35 	u32 payload_len;
36 	u32 compl_error; /* No_err=0, else major and minor err code */
37 	u32 qp_id;
38 	u32 wqe_idx;
39 	bool ipv4:1;
40 	bool smac_valid:1;
41 	bool vlan_valid:1;
42 	u8 smac[ETH_ALEN];
43 };
44 
45 struct irdma_puda_send_info {
46 	u64 paddr; /* Physical address */
47 	u32 len;
48 	u32 ah_id;
49 	u8 tcplen;
50 	u8 maclen;
51 	bool ipv4:1;
52 	bool do_lpb:1;
53 	void *scratch;
54 };
55 
56 struct irdma_puda_buf {
57 	struct list_head list; /* MUST be first entry */
58 	struct irdma_dma_mem mem; /* DMA memory for the buffer */
59 	struct irdma_puda_buf *next; /* for alloclist in rsrc struct */
60 	struct irdma_virt_mem buf_mem; /* Buffer memory for this buffer */
61 	void *scratch;
62 	u8 *iph;
63 	u8 *tcph;
64 	u8 *data;
65 	u16 datalen;
66 	u16 vlan_id;
67 	u8 tcphlen; /* tcp length in bytes */
68 	u8 maclen; /* mac length in bytes */
69 	u32 totallen; /* machlen+iphlen+tcphlen+datalen */
70 	refcount_t refcount;
71 	u8 hdrlen;
72 	bool ipv4:1;
73 	bool vlan_valid:1;
74 	bool do_lpb:1; /* Loopback buffer */
75 	bool smac_valid:1;
76 	u32 seqnum;
77 	u32 ah_id;
78 	u8 smac[ETH_ALEN];
79 	struct irdma_sc_vsi *vsi;
80 };
81 
82 struct irdma_puda_rsrc_info {
83 	void (*receive)(struct irdma_sc_vsi *vsi, struct irdma_puda_buf *buf);
84 	void (*xmit_complete)(struct irdma_sc_vsi *vsi, void *sqwrid);
85 	enum puda_rsrc_type type; /* ILQ or IEQ */
86 	u32 count;
87 	u32 pd_id;
88 	u32 cq_id;
89 	u32 qp_id;
90 	u32 sq_size;
91 	u32 rq_size;
92 	u32 tx_buf_cnt; /* total bufs allocated will be rq_size + tx_buf_cnt */
93 	u16 buf_size;
94 	u8 stats_idx;
95 	bool stats_idx_valid:1;
96 	int abi_ver;
97 };
98 
99 struct irdma_puda_rsrc {
100 	struct irdma_sc_cq cq;
101 	struct irdma_sc_qp qp;
102 	struct irdma_sc_pd sc_pd;
103 	struct irdma_sc_dev *dev;
104 	struct irdma_sc_vsi *vsi;
105 	struct irdma_dma_mem cqmem;
106 	struct irdma_dma_mem qpmem;
107 	struct irdma_virt_mem ilq_mem;
108 	enum puda_rsrc_complete cmpl;
109 	enum puda_rsrc_type type;
110 	u16 buf_size; /*buf must be max datalen + tcpip hdr + mac */
111 	u32 cq_id;
112 	u32 qp_id;
113 	u32 sq_size;
114 	u32 rq_size;
115 	u32 cq_size;
116 	struct irdma_sq_uk_wr_trk_info *sq_wrtrk_array;
117 	u64 *rq_wrid_array;
118 	u32 compl_rxwqe_idx;
119 	u32 rx_wqe_idx;
120 	u32 rxq_invalid_cnt;
121 	u32 tx_wqe_avail_cnt;
122 	struct shash_desc *hash_desc;
123 	struct list_head txpend;
124 	struct list_head bufpool; /* free buffers pool list for recv and xmit */
125 	u32 alloc_buf_count;
126 	u32 avail_buf_count; /* snapshot of currently available buffers */
127 	spinlock_t bufpool_lock;
128 	struct irdma_puda_buf *alloclist;
129 	void (*receive)(struct irdma_sc_vsi *vsi, struct irdma_puda_buf *buf);
130 	void (*xmit_complete)(struct irdma_sc_vsi *vsi, void *sqwrid);
131 	/* puda stats */
132 	u64 stats_buf_alloc_fail;
133 	u64 stats_pkt_rcvd;
134 	u64 stats_pkt_sent;
135 	u64 stats_rcvd_pkt_err;
136 	u64 stats_sent_pkt_q;
137 	u64 stats_bad_qp_id;
138 	/* IEQ stats */
139 	u64 fpdu_processed;
140 	u64 bad_seq_num;
141 	u64 crc_err;
142 	u64 pmode_count;
143 	u64 partials_handled;
144 	u8 stats_idx;
145 	bool check_crc:1;
146 	bool stats_idx_valid:1;
147 };
148 
149 struct irdma_puda_buf *irdma_puda_get_bufpool(struct irdma_puda_rsrc *rsrc);
150 void irdma_puda_ret_bufpool(struct irdma_puda_rsrc *rsrc,
151 			    struct irdma_puda_buf *buf);
152 void irdma_puda_send_buf(struct irdma_puda_rsrc *rsrc,
153 			 struct irdma_puda_buf *buf);
154 enum irdma_status_code irdma_puda_send(struct irdma_sc_qp *qp,
155 				       struct irdma_puda_send_info *info);
156 enum irdma_status_code
157 irdma_puda_create_rsrc(struct irdma_sc_vsi *vsi,
158 		       struct irdma_puda_rsrc_info *info);
159 void irdma_puda_dele_rsrc(struct irdma_sc_vsi *vsi, enum puda_rsrc_type type,
160 			  bool reset);
161 enum irdma_status_code irdma_puda_poll_cmpl(struct irdma_sc_dev *dev,
162 					    struct irdma_sc_cq *cq,
163 					    u32 *compl_err);
164 
165 struct irdma_sc_qp *irdma_ieq_get_qp(struct irdma_sc_dev *dev,
166 				     struct irdma_puda_buf *buf);
167 enum irdma_status_code
168 irdma_puda_get_tcpip_info(struct irdma_puda_cmpl_info *info,
169 			  struct irdma_puda_buf *buf);
170 enum irdma_status_code irdma_ieq_check_mpacrc(struct shash_desc *desc,
171 					      void *addr, u32 len, u32 val);
172 enum irdma_status_code irdma_init_hash_desc(struct shash_desc **desc);
173 void irdma_ieq_mpa_crc_ae(struct irdma_sc_dev *dev, struct irdma_sc_qp *qp);
174 void irdma_free_hash_desc(struct shash_desc *desc);
175 void irdma_ieq_update_tcpip_info(struct irdma_puda_buf *buf, u16 len,
176 				 u32 seqnum);
177 enum irdma_status_code irdma_cqp_qp_create_cmd(struct irdma_sc_dev *dev,
178 					       struct irdma_sc_qp *qp);
179 enum irdma_status_code irdma_cqp_cq_create_cmd(struct irdma_sc_dev *dev,
180 					       struct irdma_sc_cq *cq);
181 enum irdma_status_code irdma_cqp_qp_destroy_cmd(struct irdma_sc_dev *dev, struct irdma_sc_qp *qp);
182 void irdma_cqp_cq_destroy_cmd(struct irdma_sc_dev *dev, struct irdma_sc_cq *cq);
183 void irdma_puda_ieq_get_ah_info(struct irdma_sc_qp *qp,
184 				struct irdma_ah_info *ah_info);
185 enum irdma_status_code irdma_puda_create_ah(struct irdma_sc_dev *dev,
186 					    struct irdma_ah_info *ah_info,
187 					    bool wait, enum puda_rsrc_type type,
188 					    void *cb_param,
189 					    struct irdma_sc_ah **ah);
190 void irdma_puda_free_ah(struct irdma_sc_dev *dev, struct irdma_sc_ah *ah);
191 void irdma_ieq_process_fpdus(struct irdma_sc_qp *qp,
192 			     struct irdma_puda_rsrc *ieq);
193 void irdma_ieq_cleanup_qp(struct irdma_puda_rsrc *ieq, struct irdma_sc_qp *qp);
194 #endif /*IRDMA_PROTOS_H */
195