Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause
2 : : * Copyright(C) 2021 Marvell.
3 : : */
4 : :
5 : : #include <rte_devargs.h>
6 : :
7 : : #include "cn10k_tls.h"
8 : : #include "cnxk_cryptodev.h"
9 : : #include "cnxk_security.h"
10 : :
11 : : #define CNXK_MAX_QPS_LIMIT "max_qps_limit"
12 : : #define CNXK_MAX_QPS_LIMIT_MIN 1
13 : : #define CNXK_MAX_QPS_LIMIT_MAX (ROC_CPT_MAX_LFS - 1)
14 : : #define CNXK_RX_INJECT_QP "rx_inject_qp"
15 : : #define CNXK_CPT_CTX_ILEN "ctx_ilen"
16 : : #define CNXK_MAX_CPT_CTX_ILEN 7
17 : :
18 : : static int
19 : 0 : parse_rx_inject_qp(const char *key, const char *value, void *extra_args)
20 : : {
21 : : RTE_SET_USED(key);
22 : : uint32_t val;
23 : :
24 : 0 : val = atoi(value);
25 : :
26 [ # # ]: 0 : if (val < CNXK_MAX_QPS_LIMIT_MIN || val > CNXK_MAX_QPS_LIMIT_MAX)
27 : : return -EINVAL;
28 : :
29 : 0 : *(uint16_t *)extra_args = val;
30 : :
31 : 0 : return 0;
32 : : }
33 : :
34 : : static int
35 : 0 : parse_max_qps_limit(const char *key, const char *value, void *extra_args)
36 : : {
37 : : RTE_SET_USED(key);
38 : : uint32_t val;
39 : :
40 : 0 : val = atoi(value);
41 : :
42 [ # # ]: 0 : if (val < CNXK_MAX_QPS_LIMIT_MIN || val > CNXK_MAX_QPS_LIMIT_MAX)
43 : : return -EINVAL;
44 : :
45 : 0 : *(uint16_t *)extra_args = val;
46 : :
47 : 0 : return 0;
48 : : }
49 : :
50 : : static uint32_t
51 : : find_max_ctx_value(void)
52 : : {
53 : : uint32_t val;
54 : :
55 : : val = RTE_MAX(offsetof(struct roc_ot_ipsec_inb_sa, ctx),
56 : : offsetof(struct roc_ot_ipsec_outb_sa, ctx));
57 : :
58 : : val = RTE_MAX(val, offsetof(struct roc_ie_ot_tls_read_sa, tls_12.ctx));
59 : : val = RTE_MAX(val, offsetof(struct roc_ie_ot_tls_read_sa, tls_13.ctx));
60 : : val = RTE_MAX(val, offsetof(struct roc_ie_ot_tls_write_sa, tls_12.w26_rsvd7));
61 : : val = RTE_MAX(val, offsetof(struct roc_ie_ot_tls_write_sa, tls_13.w10_rsvd7));
62 : :
63 : : return val / 128 + 1;
64 : : }
65 : :
66 : : static int
67 : 0 : parse_cpt_ctx_ilen(const char *key, const char *value, void *extra_args)
68 : : {
69 : : RTE_SET_USED(key);
70 : : uint32_t val, min_val;
71 : :
72 : 0 : val = atoi(value);
73 [ # # ]: 0 : if (val > CNXK_MAX_CPT_CTX_ILEN)
74 : : return -EINVAL;
75 : :
76 : : min_val = find_max_ctx_value();
77 [ # # ]: 0 : if (val < min_val)
78 : : return -EINVAL;
79 : :
80 : 0 : *(uint16_t *)extra_args = val;
81 : :
82 : 0 : return 0;
83 : : }
84 : :
85 : : int
86 : 0 : cnxk_cpt_parse_devargs(struct rte_devargs *devargs, struct cnxk_cpt_vf *vf)
87 : : {
88 : 0 : uint16_t max_qps_limit = CNXK_MAX_QPS_LIMIT_MAX;
89 : : struct rte_kvargs *kvlist;
90 : : uint16_t rx_inject_qp;
91 : 0 : uint16_t ctx_ilen = 0;
92 : : int rc;
93 : :
94 : : /* Set to max value as default so that the feature is disabled by default. */
95 : 0 : rx_inject_qp = CNXK_MAX_QPS_LIMIT_MAX;
96 : :
97 [ # # ]: 0 : if (devargs == NULL)
98 : 0 : goto null_devargs;
99 : :
100 : 0 : kvlist = rte_kvargs_parse(devargs->args, NULL);
101 [ # # ]: 0 : if (kvlist == NULL)
102 : 0 : goto exit;
103 : :
104 : 0 : rc = rte_kvargs_process(kvlist, CNXK_MAX_QPS_LIMIT,
105 : : &parse_max_qps_limit, &max_qps_limit);
106 [ # # ]: 0 : if (rc < 0) {
107 : 0 : plt_err("max_qps_limit should in the range <%d-%d>",
108 : : CNXK_MAX_QPS_LIMIT_MIN, CNXK_MAX_QPS_LIMIT_MAX);
109 : 0 : rte_kvargs_free(kvlist);
110 : 0 : goto exit;
111 : : }
112 : :
113 : 0 : rc = rte_kvargs_process(kvlist, CNXK_RX_INJECT_QP, parse_rx_inject_qp, &rx_inject_qp);
114 [ # # ]: 0 : if (rc < 0) {
115 : 0 : plt_err("rx_inject_qp should in the range <%d-%d>", CNXK_MAX_QPS_LIMIT_MIN,
116 : : max_qps_limit - 1);
117 : 0 : rte_kvargs_free(kvlist);
118 : 0 : goto exit;
119 : : }
120 : :
121 : 0 : rc = rte_kvargs_process(kvlist, CNXK_CPT_CTX_ILEN, parse_cpt_ctx_ilen, &ctx_ilen);
122 [ # # ]: 0 : if (rc < 0) {
123 : 0 : plt_err("ctx_ilen should in the range <%d-%d>", find_max_ctx_value(),
124 : : CNXK_MAX_CPT_CTX_ILEN);
125 : 0 : rte_kvargs_free(kvlist);
126 : 0 : goto exit;
127 : : }
128 : :
129 : 0 : rte_kvargs_free(kvlist);
130 : :
131 : 0 : null_devargs:
132 : 0 : vf->max_qps_limit = max_qps_limit;
133 : 0 : vf->rx_inject_qp = rx_inject_qp;
134 : 0 : vf->cpt.ctx_ilen = ctx_ilen;
135 : 0 : return 0;
136 : :
137 : : exit:
138 : : return -EINVAL;
139 : : }
140 : :
141 : : RTE_PMD_REGISTER_PARAM_STRING(crypto_cnxk, CNXK_MAX_QPS_LIMIT "=<1-63>");
|