File: cpfl_ethdev.h

package info (click to toggle)
dpdk 25.11-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 127,892 kB
  • sloc: ansic: 2,358,479; python: 16,426; sh: 4,474; makefile: 1,713; awk: 70
file content (416 lines) | stat: -rw-r--r-- 10,572 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
/* SPDX-License-Identifier: BSD-3-Clause
 * Copyright(c) 2023 Intel Corporation
 */

#ifndef _CPFL_ETHDEV_H_
#define _CPFL_ETHDEV_H_

#include <stdint.h>
#include <rte_malloc.h>
#include <rte_spinlock.h>
#include <rte_ethdev.h>
#include <rte_kvargs.h>
#include <rte_hash.h>
#include <ethdev_driver.h>
#include <ethdev_pci.h>

#include <idpf_common_device.h>
#include <idpf_common_virtchnl.h>
#include <base/idpf_prototype.h>
#include <base/virtchnl2.h>

#include "cpfl_logs.h"
#include "cpfl_cpchnl.h"
#include "cpfl_representor.h"
#include "cpfl_controlq.h"

/* Currently, backend supports up to 8 vports */
#define CPFL_MAX_VPORT_NUM	8

#define CPFL_INVALID_VPORT_IDX	0xffff

#define CPFL_DFLT_Q_VEC_NUM	1

#define CPFL_MIN_BUF_SIZE	1024
#define CPFL_MAX_FRAME_SIZE	9728
#define CPFL_DEFAULT_MTU	RTE_ETHER_MTU

#define CPFL_VLAN_TAG_SIZE	4
#define CPFL_ETH_OVERHEAD \
	(RTE_ETHER_HDR_LEN + RTE_ETHER_CRC_LEN + CPFL_VLAN_TAG_SIZE * 2)

#define CPFL_RSS_OFFLOAD_ALL (				\
		RTE_ETH_RSS_IPV4                |	\
		RTE_ETH_RSS_FRAG_IPV4           |	\
		RTE_ETH_RSS_NONFRAG_IPV4_TCP    |	\
		RTE_ETH_RSS_NONFRAG_IPV4_UDP    |	\
		RTE_ETH_RSS_NONFRAG_IPV4_SCTP   |	\
		RTE_ETH_RSS_NONFRAG_IPV4_OTHER  |	\
		RTE_ETH_RSS_IPV6                |	\
		RTE_ETH_RSS_FRAG_IPV6           |	\
		RTE_ETH_RSS_NONFRAG_IPV6_TCP    |	\
		RTE_ETH_RSS_NONFRAG_IPV6_UDP    |	\
		RTE_ETH_RSS_NONFRAG_IPV6_SCTP   |	\
		RTE_ETH_RSS_NONFRAG_IPV6_OTHER  |	\
		RTE_ETH_RSS_L2_PAYLOAD)

#define CPFL_ADAPTER_NAME_LEN	(PCI_PRI_STR_SIZE + 1)

#define CPFL_ALARM_INTERVAL	50000 /* us */

/* Device IDs */
#define CPFL_DEV_ID_MMG			0x11E0
#define CPFL_DEV_ID_MEV			0x1453
#define VIRTCHNL2_QUEUE_GROUP_P2P	0x100

#define CPFL_HOST_ID_NUM	2
#define CPFL_PF_TYPE_NUM	2
#define CPFL_HOST_ID_HOST	0
#define CPFL_HOST_ID_ACC	1
#define CPFL_INVALID_HOST_ID	UINT8_MAX
#define CPFL_PF_TYPE_APF	0
#define CPFL_PF_TYPE_CPF	1

/* Function IDs on IMC side */
#define CPFL_HOST0_APF		0
#define CPFL_ACC_APF_ID		4
#define CPFL_HOST0_CPF_ID	8
#define CPFL_ACC_CPF_ID		12

#define CPFL_VPORT_LAN_PF	0
#define CPFL_VPORT_LAN_VF	1

#define CPFL_FLOW_FILE_LEN 100
#define CPFL_INVALID_HW_ID	UINT16_MAX
#define CPFL_META_CHUNK_LENGTH	1024
#define CPFL_META_LENGTH	32

#define CPFL_RX_CFGQ_NUM	4
#define CPFL_TX_CFGQ_NUM	4
#define CPFL_FPCP_CFGQ_TX	0
#define CPFL_FPCP_CFGQ_RX	1
#define CPFL_CFGQ_NUM		8
#define VCPF_RX_CFGQ_NUM	1
#define VCPF_TX_CFGQ_NUM	1
#define VCPF_CFGQ_NUM		2

/* bit[15:14] type
 * bit[13] host/accelerator core
 * bit[12] apf/cpf
 * bit[11:0] vf
 */
#define CPFL_REPRESENTOR_ID(type, host_id, pf_id, vf_id)	\
	((((type) & 0x3) << 14) + (((host_id) & 0x1) << 13) +	\
	 (((pf_id) & 0x1) << 12) + ((vf_id) & 0xfff))

struct cpfl_vport_param {
	struct cpfl_adapter_ext *adapter;
	uint16_t devarg_id; /* arg id from user */
	uint16_t idx;       /* index in adapter->vports[]*/
};

#define CPFL_REPR_ARG_NUM_MAX	4
/* Struct used when parse driver specific devargs */
struct cpfl_devargs {
	uint16_t req_vports[CPFL_MAX_VPORT_NUM];
	uint16_t req_vport_nb;
	uint8_t repr_args_num;
	struct rte_eth_devargs repr_args[CPFL_REPR_ARG_NUM_MAX];
	char flow_parser[CPFL_FLOW_FILE_LEN];
};

struct p2p_queue_chunks_info {
	uint32_t tx_start_qid;
	uint32_t rx_start_qid;
	uint32_t tx_compl_start_qid;
	uint32_t rx_buf_start_qid;

	uint64_t tx_qtail_start;
	uint32_t tx_qtail_spacing;
	uint64_t rx_qtail_start;
	uint32_t rx_qtail_spacing;
	uint64_t tx_compl_qtail_start;
	uint32_t tx_compl_qtail_spacing;
	uint64_t rx_buf_qtail_start;
	uint32_t rx_buf_qtail_spacing;
};

struct cpfl_vport_id {
	uint32_t vport_id;
	uint8_t func_type;
	uint8_t pf_id;
	uint16_t vf_id;
};

struct cpfl_vport_info {
	struct cpchnl2_event_vport_created vport;
	bool enabled;
};

enum cpfl_itf_type {
	CPFL_ITF_TYPE_VPORT,
	CPFL_ITF_TYPE_REPRESENTOR,
};

TAILQ_HEAD(cpfl_flow_list, rte_flow);

#define CPFL_FLOW_BATCH_SIZE  490
struct cpfl_itf {
	enum cpfl_itf_type type;
	struct cpfl_adapter_ext *adapter;
	struct cpfl_flow_list flow_list;
	struct idpf_dma_mem flow_dma;
	struct idpf_dma_mem dma[CPFL_FLOW_BATCH_SIZE];
	struct idpf_ctlq_msg msg[CPFL_FLOW_BATCH_SIZE];
	void *data;
};

struct vcpf_vport_info {
	u16 vport_index;
	u16 vsi_id;
	u32 abs_start_txq_id;
	u32 num_tx_q;
	u32 abs_start_rxq_id;
	u32 num_rx_q;
};

struct cpfl_vport {
	struct cpfl_itf itf;
	struct idpf_vport base;
	struct p2p_queue_chunks_info *p2p_q_chunks_info;
	struct vcpf_vport_info vport_info;

	struct rte_mempool *p2p_mp;

	uint16_t nb_data_rxq;
	uint16_t nb_data_txq;
	uint16_t nb_p2p_rxq;
	uint16_t nb_p2p_txq;

	struct idpf_rx_queue *p2p_rx_bufq;
	struct ci_tx_queue *p2p_tx_complq;
	bool p2p_manual_bind;
};

struct cpfl_repr {
	struct cpfl_itf itf;
	struct cpfl_repr_id repr_id;
	struct rte_ether_addr mac_addr;
	struct cpfl_vport_info *vport_info;
	bool func_up; /* If the represented function is up */
};

struct cpfl_metadata_chunk {
	int type;
	uint8_t data[CPFL_META_CHUNK_LENGTH];
};

/**
 * It is driver's responsibility to simlulate a metadata buffer which
 * can be used as data source to fill the key of a flow rule.
 */
struct cpfl_metadata {
	int length;
	struct cpfl_metadata_chunk chunks[CPFL_META_LENGTH];
};

/**
 * struct vcpf_cfg_queue - config queue information
 * @qid: rx/tx queue id
 * @qtail_reg_start: rx/tx tail queue register start
 * @qtail_reg_spacing: rx/tx tail queue register spacing
 */
struct vcpf_cfg_queue {
	u32 qid;
	u64 qtail_reg_start;
	u32 qtail_reg_spacing;
};

/**
 * struct vcpf_cfgq_info - config queue information
 * @num_cfgq: number of config queues
 * @cfgq_add: config queue add information
 * @cfgq: config queue information
 */
struct vcpf_cfgq_info {
	u16 num_cfgq;
	struct virtchnl2_add_queues *cfgq_add;
	struct vcpf_cfg_queue *cfgq;
};

struct cpfl_adapter_ext {
	TAILQ_ENTRY(cpfl_adapter_ext) next;
	struct idpf_adapter base;

	char name[CPFL_ADAPTER_NAME_LEN];

	struct cpfl_vport **vports;
	uint16_t max_vport_nb;

	uint16_t cur_vports; /* bit mask of created vport */
	uint16_t cur_vport_nb;

	uint16_t used_vecs_num;

	rte_spinlock_t vport_map_lock;
	struct rte_hash *vport_map_hash;

	rte_spinlock_t repr_lock;
	struct rte_hash *repr_allowlist_hash;

	struct cpfl_flow_js_parser *flow_parser;
	struct rte_bitmap *mod_bm;
	void *mod_bm_mem;

	struct cpfl_metadata meta;

	/* ctrl vport and ctrl queues. */
	struct cpfl_vport ctrl_vport;
	uint8_t ctrl_vport_recv_info[IDPF_DFLT_MBX_BUF_SIZE];
	struct idpf_ctlq_info **ctlqp;
	struct cpfl_ctlq_create_info *cfgq_info;
	struct vcpf_cfgq_info cfgq_in;
	uint8_t addq_recv_info[IDPF_DFLT_MBX_BUF_SIZE];
	uint16_t num_cfgq;
	uint16_t num_rx_cfgq;
	uint16_t num_tx_cfgq;
	uint8_t host_id;
};

TAILQ_HEAD(cpfl_adapter_list, cpfl_adapter_ext);

int cpfl_vport_info_create(struct cpfl_adapter_ext *adapter,
			   struct cpfl_vport_id *vport_identity,
			   struct cpchnl2_event_vport_created *vport);
int cpfl_cc_vport_list_get(struct cpfl_adapter_ext *adapter,
			   struct cpfl_vport_id *vi,
			   struct cpchnl2_get_vport_list_response *response);
int cpfl_cc_vport_info_get(struct cpfl_adapter_ext *adapter,
			   struct cpchnl2_vport_id *vport_id,
			   struct cpfl_vport_id *vi,
			   struct cpchnl2_get_vport_info_response *response);
int cpfl_vc_create_ctrl_vport(struct cpfl_adapter_ext *adapter);
int cpfl_config_ctlq_rx(struct cpfl_adapter_ext *adapter);
int cpfl_config_ctlq_tx(struct cpfl_adapter_ext *adapter);
int cpfl_alloc_dma_mem_batch(struct idpf_dma_mem *orig_dma, struct idpf_dma_mem *dma,
			     uint32_t size, int batch_size);
int vcpf_add_queues(struct cpfl_adapter_ext *adapter);
int vcpf_del_queues(struct cpfl_adapter_ext *adapter);

#define CPFL_DEV_TO_PCI(eth_dev)		\
	RTE_DEV_TO_PCI((eth_dev)->device)
#define CPFL_ADAPTER_TO_EXT(p)					\
	container_of((p), struct cpfl_adapter_ext, base)
#define CPFL_DEV_TO_VPORT(dev)					\
	((struct cpfl_vport *)((dev)->data->dev_private))
#define CPFL_DEV_TO_REPR(dev)					\
	((struct cpfl_repr *)((dev)->data->dev_private))
#define CPFL_DEV_TO_ITF(dev)				\
	((struct cpfl_itf *)((dev)->data->dev_private))

static inline uint16_t
cpfl_get_port_id(struct cpfl_itf *itf)
{
	if (!itf)
		return CPFL_INVALID_HW_ID;

	if (itf->type == CPFL_ITF_TYPE_VPORT) {
		struct cpfl_vport *vport = (void *)itf;

		return vport->base.devarg_id;
	}

	return CPFL_INVALID_HW_ID;
}

static inline uint16_t
cpfl_get_vsi_id(struct cpfl_itf *itf)
{
	struct cpfl_vport_info *info;
	uint32_t vport_id;
	int ret;
	struct cpfl_vport_id vport_identity;
	u16 vsi_id = 0;

	if (!itf)
		return CPFL_INVALID_HW_ID;

	if (itf->type == CPFL_ITF_TYPE_REPRESENTOR) {
		struct cpfl_repr *repr = (void *)itf;

		return repr->vport_info->vport.info.vsi_id;
	} else if (itf->type == CPFL_ITF_TYPE_VPORT) {
		if (itf->adapter->base.hw.device_id == CPFL_DEV_ID_MEV) {
			vport_id = ((struct cpfl_vport *)itf)->base.vport_id;

			vport_identity.func_type = CPCHNL2_FTYPE_LAN_PF;
			/* host: CPFL_HOST0_CPF_ID, acc: CPFL_ACC_CPF_ID */
			vport_identity.pf_id = (itf->adapter->host_id == CPFL_HOST_ID_ACC) ?
							CPFL_ACC_CPF_ID : CPFL_HOST0_CPF_ID;
			vport_identity.vf_id = 0;
			vport_identity.vport_id = vport_id;
			ret = rte_hash_lookup_data(itf->adapter->vport_map_hash,
						   &vport_identity,
						   (void **)&info);
			if (ret < 0) {
				PMD_DRV_LOG(ERR, "vport id not exist");
				goto err;
			}

			vsi_id = info->vport.info.vsi_id;
		} else {
			if (itf->adapter->base.hw.device_id == IXD_DEV_ID_VCPF)
				vsi_id = (uint16_t)((struct cpfl_vport *)itf)->vport_info.vsi_id;
		}
	}
	return vsi_id;

err:
	return CPFL_INVALID_HW_ID;
}

static inline struct cpfl_itf *
cpfl_get_itf_by_port_id(uint16_t port_id)
{
	struct rte_eth_dev *dev;

	if (port_id >= RTE_MAX_ETHPORTS) {
		PMD_DRV_LOG(ERR, "port_id should be < %d.", RTE_MAX_ETHPORTS);
		return NULL;
	}

	dev = &rte_eth_devices[port_id];
	if (dev->state == RTE_ETH_DEV_UNUSED) {
		PMD_DRV_LOG(ERR, "eth_dev[%d] is unused.", port_id);
		return NULL;
	}

	if (!dev->data) {
		PMD_DRV_LOG(ERR, "eth_dev[%d] data not be allocated.", port_id);
		return NULL;
	}

	return CPFL_DEV_TO_ITF(dev);
}

static inline uint32_t
vcpf_get_abs_qid(uint16_t port_id,  uint32_t queue_type)
{
	struct cpfl_itf *itf = cpfl_get_itf_by_port_id(port_id);
	struct cpfl_vport *vport;
	if (!itf)
		return CPFL_INVALID_HW_ID;
	if (itf->type == CPFL_ITF_TYPE_VPORT) {
		vport = (void *)itf;
		if (itf->adapter->base.hw.device_id == IXD_DEV_ID_VCPF) {
			switch (queue_type) {
			case VIRTCHNL2_QUEUE_TYPE_TX:
				return vport->vport_info.abs_start_txq_id;
			case VIRTCHNL2_QUEUE_TYPE_RX:
				return vport->vport_info.abs_start_rxq_id;
			}
		}
	}
	return 0;
}
#endif /* _CPFL_ETHDEV_H_ */