1 /* SPDX-License-Identifier: BSD-3-Clause */
2 /* Copyright(c) 2007-2022 Intel Corporation */
3 /* $FreeBSD$ */
4 #ifndef ADF_CFG_BUNDLE_H_
5 #define ADF_CFG_BUNDLE_H_
6 
7 #include "adf_accel_devices.h"
8 #include "adf_cfg_common.h"
9 
10 #define MAX_SECTIONS_PER_BUNDLE 8
11 #define MAX_SECTION_NAME_LEN 64
12 
13 #define TX 0x0
14 #define RX 0x1
15 
16 #define ASSIGN_SERV_TO_RINGS(bund, index, base, stype, rng_per_srv)            \
17 	do {                                                                   \
18 		int j = 0;                                                     \
19 		typeof(bund) b = (bund);                                       \
20 		typeof(index) i = (index);                                     \
21 		typeof(base) s = (base);                                       \
22 		typeof(stype) t = (stype);                                     \
23 		typeof(rng_per_srv) rps = (rng_per_srv);                       \
24 		for (j = 0; j < rps; j++) {                                    \
25 			b->rings[i + j]->serv_type = t;                        \
26 			b->rings[i + j + s]->serv_type = t;                    \
27 		}                                                              \
28 	} while (0)
29 
30 bool adf_cfg_is_free(struct adf_cfg_bundle *bundle);
31 
32 int adf_cfg_get_ring_pairs_from_bundle(struct adf_cfg_bundle *bundle,
33 				       struct adf_cfg_instance *inst,
34 				       const char *process_name,
35 				       struct adf_cfg_instance *bundle_inst);
36 
37 struct adf_cfg_instance *
38 adf_cfg_get_free_instance(struct adf_cfg_device *device,
39 			  struct adf_cfg_bundle *bundle,
40 			  struct adf_cfg_instance *inst,
41 			  const char *process_name);
42 
43 int adf_cfg_bundle_init(struct adf_cfg_bundle *bundle,
44 			struct adf_cfg_device *device,
45 			int bank_num,
46 			struct adf_accel_dev *accel_dev);
47 
48 void adf_cfg_bundle_clear(struct adf_cfg_bundle *bundle,
49 			  struct adf_accel_dev *accel_dev);
50 
51 void adf_cfg_init_ring2serv_mapping(struct adf_accel_dev *accel_dev,
52 				    struct adf_cfg_bundle *bundle,
53 				    struct adf_cfg_device *device);
54 
55 int adf_cfg_rel_ring2serv_mapping(struct adf_cfg_bundle *bundle);
56 
57 static inline void
58 adf_get_ring_svc_map_data(struct adf_hw_device_data *hw_data,
59 			  int bundle_num,
60 			  int ring_pair_index,
61 			  u8 *serv_type,
62 			  int *ring_index,
63 			  int *num_rings_per_srv)
64 {
65 	if (hw_data->get_ring_svc_map_data)
66 		return hw_data->get_ring_svc_map_data(ring_pair_index,
67 						      hw_data->ring_to_svc_map,
68 						      serv_type,
69 						      ring_index,
70 						      num_rings_per_srv,
71 						      bundle_num);
72 	*serv_type = GET_SRV_TYPE(hw_data->ring_to_svc_map, ring_pair_index);
73 	*num_rings_per_srv =
74 	    hw_data->num_rings_per_bank / (2 * ADF_CFG_NUM_SERVICES);
75 	*ring_index = (*num_rings_per_srv) * ring_pair_index;
76 }
77 #endif
78