1 /* SPDX-License-Identifier: GPL-2.0-only */ 2 /* Copyright(c) 2023 Intel Corporation */ 3 4 #ifndef ADF_RL_H_ 5 #define ADF_RL_H_ 6 7 #include <linux/mutex.h> 8 #include <linux/types.h> 9 10 struct adf_accel_dev; 11 12 #define RL_ROOT_MAX 4 13 #define RL_CLUSTER_MAX 16 14 #define RL_LEAF_MAX 64 15 #define RL_NODES_CNT_MAX (RL_ROOT_MAX + RL_CLUSTER_MAX + RL_LEAF_MAX) 16 #define RL_RP_CNT_PER_LEAF_MAX 4U 17 #define RL_RP_CNT_MAX 64 18 #define RL_SLA_EMPTY_ID -1 19 #define RL_PARENT_DEFAULT_ID -1 20 21 enum rl_node_type { 22 RL_ROOT, 23 RL_CLUSTER, 24 RL_LEAF, 25 }; 26 27 enum adf_base_services { 28 ADF_SVC_ASYM = 0, 29 ADF_SVC_SYM, 30 ADF_SVC_DC, 31 ADF_SVC_NONE, 32 }; 33 34 /** 35 * struct adf_rl_sla_input_data - ratelimiting user input data structure 36 * @rp_mask: 64 bit bitmask of ring pair IDs which will be assigned to SLA. 37 * Eg. 0x5 -> RP0 and RP2 assigned; 0xA005 -> RP0,2,13,15 assigned. 38 * @sla_id: ID of current SLA for operations update, rm, get. For the add 39 * operation, this field will be updated with the ID of the newly 40 * added SLA 41 * @parent_id: ID of the SLA to which the current one should be assigned. 42 * Set to -1 to refer to the default parent. 43 * @cir: Committed information rate. Rate guaranteed to be achieved. Input value 44 * is expressed in permille scale, i.e. 1000 refers to the maximum 45 * device throughput for a selected service. 46 * @pir: Peak information rate. Maximum rate available that the SLA can achieve. 47 * Input value is expressed in permille scale, i.e. 1000 refers to 48 * the maximum device throughput for a selected service. 49 * @type: SLA type: root, cluster, node 50 * @srv: Service associated to the SLA: asym, sym dc. 51 * 52 * This structure is used to perform operations on an SLA. 53 * Depending on the operation, some of the parameters are ignored. 54 * The following list reports which parameters should be set for each operation. 55 * - add: all except sla_id 56 * - update: cir, pir, sla_id 57 * - rm: sla_id 58 * - rm_all: - 59 * - get: sla_id 60 * - get_capability_rem: srv, sla_id 61 */ 62 struct adf_rl_sla_input_data { 63 u64 rp_mask; 64 int sla_id; 65 int parent_id; 66 unsigned int cir; 67 unsigned int pir; 68 enum rl_node_type type; 69 enum adf_base_services srv; 70 }; 71 72 struct rl_slice_cnt { 73 u8 dcpr_cnt; 74 u8 pke_cnt; 75 u8 cph_cnt; 76 }; 77 78 struct adf_rl_interface_data { 79 struct adf_rl_sla_input_data input; 80 enum adf_base_services cap_rem_srv; 81 struct rw_semaphore lock; 82 }; 83 84 struct adf_rl_hw_data { 85 u32 scale_ref; 86 u32 scan_interval; 87 u32 r2l_offset; 88 u32 l2c_offset; 89 u32 c2s_offset; 90 u32 pciin_tb_offset; 91 u32 pciout_tb_offset; 92 u32 pcie_scale_mul; 93 u32 pcie_scale_div; 94 u32 dcpr_correction; 95 u32 max_tp[RL_ROOT_MAX]; 96 struct rl_slice_cnt slices; 97 }; 98 99 /** 100 * struct adf_rl - ratelimiting data structure 101 * @accel_dev: pointer to acceleration device data 102 * @device_data: pointer to rate limiting data specific to a device type (or revision) 103 * @sla: array of pointers to SLA objects 104 * @root: array of pointers to root type SLAs, element number reflects node_id 105 * @cluster: array of pointers to cluster type SLAs, element number reflects node_id 106 * @leaf: array of pointers to leaf type SLAs, element number reflects node_id 107 * @rp_in_use: array of ring pair IDs already used in one of SLAs 108 * @rl_lock: mutex object which is protecting data in this structure 109 * @input: structure which is used for holding the data received from user 110 */ 111 struct adf_rl { 112 struct adf_accel_dev *accel_dev; 113 struct adf_rl_hw_data *device_data; 114 /* mapping sla_id to SLA objects */ 115 struct rl_sla *sla[RL_NODES_CNT_MAX]; 116 struct rl_sla *root[RL_ROOT_MAX]; 117 struct rl_sla *cluster[RL_CLUSTER_MAX]; 118 struct rl_sla *leaf[RL_LEAF_MAX]; 119 bool rp_in_use[RL_RP_CNT_MAX]; 120 /* Mutex protecting writing to SLAs lists */ 121 struct mutex rl_lock; 122 struct adf_rl_interface_data user_input; 123 }; 124 125 /** 126 * struct rl_sla - SLA object data structure 127 * @parent: pointer to the parent SLA (root/cluster) 128 * @type: SLA type 129 * @srv: service associated with this SLA 130 * @sla_id: ID of the SLA, used as element number in SLA array and as identifier 131 * shared with the user 132 * @node_id: ID of node, each of SLA type have a separate ID list 133 * @cir: committed information rate 134 * @pir: peak information rate (PIR >= CIR) 135 * @rem_cir: if this SLA is a parent then this field represents a remaining 136 * value to be used by child SLAs. 137 * @ring_pairs_ids: array with numeric ring pairs IDs assigned to this SLA 138 * @ring_pairs_cnt: number of assigned ring pairs listed in the array above 139 */ 140 struct rl_sla { 141 struct rl_sla *parent; 142 enum rl_node_type type; 143 enum adf_base_services srv; 144 u32 sla_id; 145 u32 node_id; 146 u32 cir; 147 u32 pir; 148 u32 rem_cir; 149 u16 ring_pairs_ids[RL_RP_CNT_PER_LEAF_MAX]; 150 u16 ring_pairs_cnt; 151 }; 152 153 int adf_rl_add_sla(struct adf_accel_dev *accel_dev, 154 struct adf_rl_sla_input_data *sla_in); 155 int adf_rl_update_sla(struct adf_accel_dev *accel_dev, 156 struct adf_rl_sla_input_data *sla_in); 157 int adf_rl_get_sla(struct adf_accel_dev *accel_dev, 158 struct adf_rl_sla_input_data *sla_in); 159 int adf_rl_get_capability_remaining(struct adf_accel_dev *accel_dev, 160 enum adf_base_services srv, int sla_id); 161 int adf_rl_remove_sla(struct adf_accel_dev *accel_dev, u32 sla_id); 162 void adf_rl_remove_sla_all(struct adf_accel_dev *accel_dev, bool incl_default); 163 164 int adf_rl_init(struct adf_accel_dev *accel_dev); 165 int adf_rl_start(struct adf_accel_dev *accel_dev); 166 void adf_rl_stop(struct adf_accel_dev *accel_dev); 167 void adf_rl_exit(struct adf_accel_dev *accel_dev); 168 169 u32 adf_rl_calculate_pci_bw(struct adf_accel_dev *accel_dev, u32 sla_val, 170 enum adf_base_services svc_type, bool is_bw_out); 171 u32 adf_rl_calculate_ae_cycles(struct adf_accel_dev *accel_dev, u32 sla_val, 172 enum adf_base_services svc_type); 173 u32 adf_rl_calculate_slice_tokens(struct adf_accel_dev *accel_dev, u32 sla_val, 174 enum adf_base_services svc_type); 175 176 #endif /* ADF_RL_H_ */ 177