Skip to content

Commit d8d7e28

Browse files
sumanku3herbertx
authored andcommitted
crypto: qat - consolidate service enums
The enums `adf_base_services` (used in rate limiting) and `adf_services` define the same values, resulting in code duplication. To improve consistency across the QAT driver: (1) rename `adf_services` to `adf_base_services` in adf_cfg_services.c to better reflect its role in defining core services (those with dedicated accelerators), (2) introduce a new `adf_extended_services` enum starting from `SVC_BASE_COUNT`, and move `SVC_DCC` into it, as it represents an extended service (DC with chaining), and (3) remove the redundant `adf_base_services` enum from the rate limiting implementation. This does not introduce any functional change. Signed-off-by: Suman Kumar Chakraborty <suman.kumar.chakraborty@intel.com> Reviewed-by: Giovanni Cabiddu <giovanni.cabiddu@intel.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
1 parent fa37d38 commit d8d7e28

9 files changed

Lines changed: 47 additions & 50 deletions

File tree

drivers/crypto/intel/qat/qat_420xx/adf_420xx_hw_data.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -296,9 +296,9 @@ static void adf_init_rl_data(struct adf_rl_hw_data *rl_data)
296296
rl_data->pcie_scale_div = ADF_420XX_RL_PCIE_SCALE_FACTOR_DIV;
297297
rl_data->pcie_scale_mul = ADF_420XX_RL_PCIE_SCALE_FACTOR_MUL;
298298
rl_data->dcpr_correction = ADF_420XX_RL_DCPR_CORRECTION;
299-
rl_data->max_tp[ADF_SVC_ASYM] = ADF_420XX_RL_MAX_TP_ASYM;
300-
rl_data->max_tp[ADF_SVC_SYM] = ADF_420XX_RL_MAX_TP_SYM;
301-
rl_data->max_tp[ADF_SVC_DC] = ADF_420XX_RL_MAX_TP_DC;
299+
rl_data->max_tp[SVC_ASYM] = ADF_420XX_RL_MAX_TP_ASYM;
300+
rl_data->max_tp[SVC_SYM] = ADF_420XX_RL_MAX_TP_SYM;
301+
rl_data->max_tp[SVC_DC] = ADF_420XX_RL_MAX_TP_DC;
302302
rl_data->scan_interval = ADF_420XX_RL_SCANS_PER_SEC;
303303
rl_data->scale_ref = ADF_420XX_RL_SLICE_REF;
304304
}

drivers/crypto/intel/qat/qat_4xxx/adf_4xxx_hw_data.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -222,9 +222,9 @@ static void adf_init_rl_data(struct adf_rl_hw_data *rl_data)
222222
rl_data->pcie_scale_div = ADF_4XXX_RL_PCIE_SCALE_FACTOR_DIV;
223223
rl_data->pcie_scale_mul = ADF_4XXX_RL_PCIE_SCALE_FACTOR_MUL;
224224
rl_data->dcpr_correction = ADF_4XXX_RL_DCPR_CORRECTION;
225-
rl_data->max_tp[ADF_SVC_ASYM] = ADF_4XXX_RL_MAX_TP_ASYM;
226-
rl_data->max_tp[ADF_SVC_SYM] = ADF_4XXX_RL_MAX_TP_SYM;
227-
rl_data->max_tp[ADF_SVC_DC] = ADF_4XXX_RL_MAX_TP_DC;
225+
rl_data->max_tp[SVC_ASYM] = ADF_4XXX_RL_MAX_TP_ASYM;
226+
rl_data->max_tp[SVC_SYM] = ADF_4XXX_RL_MAX_TP_SYM;
227+
rl_data->max_tp[SVC_DC] = ADF_4XXX_RL_MAX_TP_DC;
228228
rl_data->scan_interval = ADF_4XXX_RL_SCANS_PER_SEC;
229229
rl_data->scale_ref = ADF_4XXX_RL_SLICE_REF;
230230
}

drivers/crypto/intel/qat/qat_6xxx/adf_6xxx_hw_data.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ static bool services_supported(unsigned long mask)
103103
{
104104
int num_svc;
105105

106-
if (mask >= BIT(SVC_BASE_COUNT))
106+
if (mask >= BIT(SVC_COUNT))
107107
return false;
108108

109109
num_svc = hweight_long(mask);
@@ -138,7 +138,7 @@ static int get_service(unsigned long *mask)
138138
return -EINVAL;
139139
}
140140

141-
static enum adf_cfg_service_type get_ring_type(enum adf_services service)
141+
static enum adf_cfg_service_type get_ring_type(unsigned int service)
142142
{
143143
switch (service) {
144144
case SVC_SYM:
@@ -155,7 +155,7 @@ static enum adf_cfg_service_type get_ring_type(enum adf_services service)
155155
}
156156
}
157157

158-
static const unsigned long *get_thrd_mask(enum adf_services service)
158+
static const unsigned long *get_thrd_mask(unsigned int service)
159159
{
160160
switch (service) {
161161
case SVC_SYM:

drivers/crypto/intel/qat/qat_common/adf_cfg_services.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ static const char *const adf_cfg_services[] = {
2020

2121
/*
2222
* Ensure that the size of the array matches the number of services,
23-
* SVC_BASE_COUNT, that is used to size the bitmap.
23+
* SVC_COUNT, that is used to size the bitmap.
2424
*/
25-
static_assert(ARRAY_SIZE(adf_cfg_services) == SVC_BASE_COUNT);
25+
static_assert(ARRAY_SIZE(adf_cfg_services) == SVC_COUNT);
2626

2727
/*
2828
* Ensure that the maximum number of concurrent services that can be
@@ -35,7 +35,7 @@ static_assert(ARRAY_SIZE(adf_cfg_services) >= MAX_NUM_CONCURR_SVC);
3535
* Ensure that the number of services fit a single unsigned long, as each
3636
* service is represented by a bit in the mask.
3737
*/
38-
static_assert(BITS_PER_LONG >= SVC_BASE_COUNT);
38+
static_assert(BITS_PER_LONG >= SVC_COUNT);
3939

4040
/*
4141
* Ensure that size of the concatenation of all service strings is smaller
@@ -90,7 +90,7 @@ static int adf_service_mask_to_string(unsigned long mask, char *buf, size_t len)
9090
if (len < ADF_CFG_MAX_VAL_LEN_IN_BYTES)
9191
return -ENOSPC;
9292

93-
for_each_set_bit(bit, &mask, SVC_BASE_COUNT) {
93+
for_each_set_bit(bit, &mask, SVC_COUNT) {
9494
if (offset)
9595
offset += scnprintf(buf + offset, len - offset,
9696
ADF_SERVICES_DELIMITER);

drivers/crypto/intel/qat/qat_common/adf_cfg_services.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,21 @@
77

88
struct adf_accel_dev;
99

10-
enum adf_services {
10+
enum adf_base_services {
1111
SVC_ASYM = 0,
1212
SVC_SYM,
1313
SVC_DC,
1414
SVC_DECOMP,
15-
SVC_DCC,
1615
SVC_BASE_COUNT
1716
};
1817

18+
enum adf_extended_services {
19+
SVC_DCC = SVC_BASE_COUNT,
20+
SVC_COUNT
21+
};
22+
1923
enum adf_composed_services {
20-
SVC_SYM_ASYM = SVC_BASE_COUNT,
24+
SVC_SYM_ASYM = SVC_COUNT,
2125
SVC_SYM_DC,
2226
SVC_ASYM_DC,
2327
};

drivers/crypto/intel/qat/qat_common/adf_gen4_hw_data.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ bool adf_gen4_services_supported(unsigned long mask)
262262
{
263263
unsigned long num_svc = hweight_long(mask);
264264

265-
if (mask >= BIT(SVC_BASE_COUNT))
265+
if (mask >= BIT(SVC_COUNT))
266266
return false;
267267

268268
if (test_bit(SVC_DECOMP, &mask))

drivers/crypto/intel/qat/qat_common/adf_rl.c

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include <linux/units.h>
1414

1515
#include "adf_accel_devices.h"
16+
#include "adf_cfg_services.h"
1617
#include "adf_common_drv.h"
1718
#include "adf_rl_admin.h"
1819
#include "adf_rl.h"
@@ -55,7 +56,7 @@ static int validate_user_input(struct adf_accel_dev *accel_dev,
5556
}
5657
}
5758

58-
if (sla_in->srv >= ADF_SVC_NONE) {
59+
if (sla_in->srv >= SVC_BASE_COUNT) {
5960
dev_notice(&GET_DEV(accel_dev),
6061
"Wrong service type\n");
6162
return -EINVAL;
@@ -171,13 +172,13 @@ static struct rl_sla *find_parent(struct adf_rl *rl_data,
171172
static enum adf_cfg_service_type srv_to_cfg_svc_type(enum adf_base_services rl_srv)
172173
{
173174
switch (rl_srv) {
174-
case ADF_SVC_ASYM:
175+
case SVC_ASYM:
175176
return ASYM;
176-
case ADF_SVC_SYM:
177+
case SVC_SYM:
177178
return SYM;
178-
case ADF_SVC_DC:
179+
case SVC_DC:
179180
return COMP;
180-
case ADF_SVC_DECOMP:
181+
case SVC_DECOMP:
181182
return DECOMP;
182183
default:
183184
return UNUSED;
@@ -562,13 +563,13 @@ u32 adf_rl_calculate_slice_tokens(struct adf_accel_dev *accel_dev, u32 sla_val,
562563
avail_slice_cycles = hw_data->clock_frequency;
563564

564565
switch (svc_type) {
565-
case ADF_SVC_ASYM:
566+
case SVC_ASYM:
566567
avail_slice_cycles *= device_data->slices.pke_cnt;
567568
break;
568-
case ADF_SVC_SYM:
569+
case SVC_SYM:
569570
avail_slice_cycles *= device_data->slices.cph_cnt;
570571
break;
571-
case ADF_SVC_DC:
572+
case SVC_DC:
572573
avail_slice_cycles *= device_data->slices.dcpr_cnt;
573574
break;
574575
default:
@@ -618,9 +619,8 @@ u32 adf_rl_calculate_pci_bw(struct adf_accel_dev *accel_dev, u32 sla_val,
618619
sla_to_bytes *= device_data->max_tp[svc_type];
619620
do_div(sla_to_bytes, device_data->scale_ref);
620621

621-
sla_to_bytes *= (svc_type == ADF_SVC_ASYM) ? RL_TOKEN_ASYM_SIZE :
622-
BYTES_PER_MBIT;
623-
if (svc_type == ADF_SVC_DC && is_bw_out)
622+
sla_to_bytes *= (svc_type == SVC_ASYM) ? RL_TOKEN_ASYM_SIZE : BYTES_PER_MBIT;
623+
if (svc_type == SVC_DC && is_bw_out)
624624
sla_to_bytes *= device_data->slices.dcpr_cnt -
625625
device_data->dcpr_correction;
626626

@@ -731,7 +731,7 @@ static int initialize_default_nodes(struct adf_accel_dev *accel_dev)
731731
sla_in.type = RL_ROOT;
732732
sla_in.parent_id = RL_PARENT_DEFAULT_ID;
733733

734-
for (i = 0; i < ADF_SVC_NONE; i++) {
734+
for (i = 0; i < SVC_BASE_COUNT; i++) {
735735
if (!is_service_enabled(accel_dev, i))
736736
continue;
737737

@@ -746,10 +746,9 @@ static int initialize_default_nodes(struct adf_accel_dev *accel_dev)
746746

747747
/* Init default cluster for each root */
748748
sla_in.type = RL_CLUSTER;
749-
for (i = 0; i < ADF_SVC_NONE; i++) {
749+
for (i = 0; i < SVC_BASE_COUNT; i++) {
750750
if (!rl_data->root[i])
751751
continue;
752-
753752
sla_in.cir = rl_data->root[i]->cir;
754753
sla_in.pir = sla_in.cir;
755754
sla_in.srv = rl_data->root[i]->srv;
@@ -988,7 +987,7 @@ int adf_rl_get_capability_remaining(struct adf_accel_dev *accel_dev,
988987
struct rl_sla *sla = NULL;
989988
int i;
990989

991-
if (srv >= ADF_SVC_NONE)
990+
if (srv >= SVC_BASE_COUNT)
992991
return -EINVAL;
993992

994993
if (sla_id > RL_SLA_EMPTY_ID && !validate_sla_id(accel_dev, sla_id)) {
@@ -1087,9 +1086,9 @@ int adf_rl_init(struct adf_accel_dev *accel_dev)
10871086
int ret = 0;
10881087

10891088
/* Validate device parameters */
1090-
if (RL_VALIDATE_NON_ZERO(rl_hw_data->max_tp[ADF_SVC_ASYM]) ||
1091-
RL_VALIDATE_NON_ZERO(rl_hw_data->max_tp[ADF_SVC_SYM]) ||
1092-
RL_VALIDATE_NON_ZERO(rl_hw_data->max_tp[ADF_SVC_DC]) ||
1089+
if (RL_VALIDATE_NON_ZERO(rl_hw_data->max_tp[SVC_ASYM]) ||
1090+
RL_VALIDATE_NON_ZERO(rl_hw_data->max_tp[SVC_SYM]) ||
1091+
RL_VALIDATE_NON_ZERO(rl_hw_data->max_tp[SVC_DC]) ||
10931092
RL_VALIDATE_NON_ZERO(rl_hw_data->scan_interval) ||
10941093
RL_VALIDATE_NON_ZERO(rl_hw_data->pcie_scale_div) ||
10951094
RL_VALIDATE_NON_ZERO(rl_hw_data->pcie_scale_mul) ||

drivers/crypto/intel/qat/qat_common/adf_rl.h

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
#include <linux/mutex.h>
88
#include <linux/types.h>
99

10+
#include "adf_cfg_services.h"
11+
1012
struct adf_accel_dev;
1113

1214
#define RL_ROOT_MAX 4
@@ -24,14 +26,6 @@ enum rl_node_type {
2426
RL_LEAF,
2527
};
2628

27-
enum adf_base_services {
28-
ADF_SVC_ASYM = 0,
29-
ADF_SVC_SYM,
30-
ADF_SVC_DC,
31-
ADF_SVC_DECOMP,
32-
ADF_SVC_NONE,
33-
};
34-
3529
/**
3630
* struct adf_rl_sla_input_data - ratelimiting user input data structure
3731
* @rp_mask: 64 bit bitmask of ring pair IDs which will be assigned to SLA.

drivers/crypto/intel/qat/qat_common/adf_sysfs_rl.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@ enum rl_params {
3232
};
3333

3434
static const char *const rl_services[] = {
35-
[ADF_SVC_ASYM] = "asym",
36-
[ADF_SVC_SYM] = "sym",
37-
[ADF_SVC_DC] = "dc",
38-
[ADF_SVC_DECOMP] = "decomp",
35+
[SVC_ASYM] = "asym",
36+
[SVC_SYM] = "sym",
37+
[SVC_DC] = "dc",
38+
[SVC_DECOMP] = "decomp",
3939
};
4040

4141
static const char *const rl_operations[] = {
@@ -283,7 +283,7 @@ static ssize_t srv_show(struct device *dev, struct device_attribute *attr,
283283
if (ret)
284284
return ret;
285285

286-
if (get == ADF_SVC_NONE)
286+
if (get == SVC_BASE_COUNT)
287287
return -EINVAL;
288288

289289
return sysfs_emit(buf, "%s\n", rl_services[get]);
@@ -448,8 +448,8 @@ int adf_sysfs_rl_add(struct adf_accel_dev *accel_dev)
448448
dev_err(&GET_DEV(accel_dev),
449449
"Failed to create qat_rl attribute group\n");
450450

451-
data->cap_rem_srv = ADF_SVC_NONE;
452-
data->input.srv = ADF_SVC_NONE;
451+
data->cap_rem_srv = SVC_BASE_COUNT;
452+
data->input.srv = SVC_BASE_COUNT;
453453
data->sysfs_added = true;
454454

455455
return ret;

0 commit comments

Comments
 (0)