brintos

brintos / linux-shallow public Read only

0
0
Text · 5.8 KiB · bfe750e Raw
180 lines · c
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 10struct adf_accel_dev;11 12#define RL_ROOT_MAX		413#define RL_CLUSTER_MAX		1614#define RL_LEAF_MAX		6415#define RL_NODES_CNT_MAX	(RL_ROOT_MAX + RL_CLUSTER_MAX + RL_LEAF_MAX)16#define RL_RP_CNT_PER_LEAF_MAX	4U17#define RL_RP_CNT_MAX		6418#define RL_SLA_EMPTY_ID		-119#define RL_PARENT_DEFAULT_ID	-120 21enum rl_node_type {22	RL_ROOT,23	RL_CLUSTER,24	RL_LEAF,25};26 27enum 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 structure36 * @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 add39 *	    operation, this field will be updated with the ID of the newly40 *	    added SLA41 * @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 value44 *	 is expressed in permille scale, i.e. 1000 refers to the maximum45 *	 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 to48 *	 the maximum device throughput for a selected service.49 * @type: SLA type: root, cluster, node50 * @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_id56 *	- update: cir, pir, sla_id57 *	- rm: sla_id58 *	- rm_all: -59 *	- get: sla_id60 *	- get_capability_rem: srv, sla_id61 */62struct 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 72struct rl_slice_cnt {73	u8 dcpr_cnt;74	u8 pke_cnt;75	u8 cph_cnt;76};77 78struct 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	bool sysfs_added;83};84 85struct adf_rl_hw_data {86	u32 scale_ref;87	u32 scan_interval;88	u32 r2l_offset;89	u32 l2c_offset;90	u32 c2s_offset;91	u32 pciin_tb_offset;92	u32 pciout_tb_offset;93	u32 pcie_scale_mul;94	u32 pcie_scale_div;95	u32 dcpr_correction;96	u32 max_tp[RL_ROOT_MAX];97	struct rl_slice_cnt slices;98};99 100/**101 * struct adf_rl - ratelimiting data structure102 * @accel_dev: pointer to acceleration device data103 * @device_data: pointer to rate limiting data specific to a device type (or revision)104 * @sla: array of pointers to SLA objects105 * @root: array of pointers to root type SLAs, element number reflects node_id106 * @cluster: array of pointers to cluster type SLAs, element number reflects node_id107 * @leaf: array of pointers to leaf type SLAs, element number reflects node_id108 * @rp_in_use: array of ring pair IDs already used in one of SLAs109 * @rl_lock: mutex object which is protecting data in this structure110 * @input: structure which is used for holding the data received from user111 */112struct adf_rl {113	struct adf_accel_dev *accel_dev;114	struct adf_rl_hw_data *device_data;115	/* mapping sla_id to SLA objects */116	struct rl_sla *sla[RL_NODES_CNT_MAX];117	struct rl_sla *root[RL_ROOT_MAX];118	struct rl_sla *cluster[RL_CLUSTER_MAX];119	struct rl_sla *leaf[RL_LEAF_MAX];120	bool rp_in_use[RL_RP_CNT_MAX];121	/* Mutex protecting writing to SLAs lists */122	struct mutex rl_lock;123	struct adf_rl_interface_data user_input;124};125 126/**127 * struct rl_sla - SLA object data structure128 * @parent: pointer to the parent SLA (root/cluster)129 * @type: SLA type130 * @srv: service associated with this SLA131 * @sla_id: ID of the SLA, used as element number in SLA array and as identifier132 *	    shared with the user133 * @node_id: ID of node, each of SLA type have a separate ID list134 * @cir: committed information rate135 * @pir: peak information rate (PIR >= CIR)136 * @rem_cir: if this SLA is a parent then this field represents a remaining137 *	     value to be used by child SLAs.138 * @ring_pairs_ids: array with numeric ring pairs IDs assigned to this SLA139 * @ring_pairs_cnt: number of assigned ring pairs listed in the array above140 */141struct rl_sla {142	struct rl_sla *parent;143	enum rl_node_type type;144	enum adf_base_services srv;145	u32 sla_id;146	u32 node_id;147	u32 cir;148	u32 pir;149	u32 rem_cir;150	u16 ring_pairs_ids[RL_RP_CNT_PER_LEAF_MAX];151	u16 ring_pairs_cnt;152};153 154u32 adf_rl_get_sla_arr_of_type(struct adf_rl *rl_data, enum rl_node_type type,155			       struct rl_sla ***sla_arr);156int adf_rl_add_sla(struct adf_accel_dev *accel_dev,157		   struct adf_rl_sla_input_data *sla_in);158int adf_rl_update_sla(struct adf_accel_dev *accel_dev,159		      struct adf_rl_sla_input_data *sla_in);160int adf_rl_get_sla(struct adf_accel_dev *accel_dev,161		   struct adf_rl_sla_input_data *sla_in);162int adf_rl_get_capability_remaining(struct adf_accel_dev *accel_dev,163				    enum adf_base_services srv, int sla_id);164int adf_rl_remove_sla(struct adf_accel_dev *accel_dev, u32 sla_id);165void adf_rl_remove_sla_all(struct adf_accel_dev *accel_dev, bool incl_default);166 167int adf_rl_init(struct adf_accel_dev *accel_dev);168int adf_rl_start(struct adf_accel_dev *accel_dev);169void adf_rl_stop(struct adf_accel_dev *accel_dev);170void adf_rl_exit(struct adf_accel_dev *accel_dev);171 172u32 adf_rl_calculate_pci_bw(struct adf_accel_dev *accel_dev, u32 sla_val,173			    enum adf_base_services svc_type, bool is_bw_out);174u32 adf_rl_calculate_ae_cycles(struct adf_accel_dev *accel_dev, u32 sla_val,175			       enum adf_base_services svc_type);176u32 adf_rl_calculate_slice_tokens(struct adf_accel_dev *accel_dev, u32 sla_val,177				  enum adf_base_services svc_type);178 179#endif /* ADF_RL_H_ */180