Whamcloud - gitweb
LU-8191 tests: convert functions to static
[fs/lustre-release.git] / lnet / klnds / kfilnd / kfilnd_modparams.c
1 /*
2  * GPL HEADER START
3  *
4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 only,
8  * as published by the Free Software Foundation.
9  *
10  * This program is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * General Public License version 2 for more details (a copy is included
14  * in the LICENSE file that accompanied this code).
15  *
16  * You should have received a copy of the GNU General Public License
17  * version 2 along with this program; If not, see
18  * http://www.gnu.org/licenses/gpl-2.0.html
19  *
20  * GPL HEADER END
21  */
22 /*
23  * Copyright 2022 Hewlett Packard Enterprise Development LP
24  */
25 /*
26  * This file is part of Lustre, http://www.lustre.org/
27  */
28 /*
29  * kfilnd module parameters
30  */
31
32 #include "kfilnd.h"
33
34 unsigned int cksum;
35 module_param(cksum, uint, 0444);
36 MODULE_PARM_DESC(cksum, "Enable checksums for non-zero messages (not RDMA)");
37
38 /* Scale factor for TX context queue depth. The factor is applied to the number
39  * of credits to determine queue depth.
40  */
41 unsigned int tx_scale_factor = 2;
42 module_param(tx_scale_factor, uint, 0444);
43 MODULE_PARM_DESC(tx_scale_factor,
44                  "Factor applied to credits to determine TX context size");
45
46 /* Scale factor for TX and RX completion queue depth. The factor is applied to
47  * the number of credits to determine queue depth.
48  */
49 unsigned int rx_cq_scale_factor = 10;
50 module_param(rx_cq_scale_factor, uint, 0444);
51 MODULE_PARM_DESC(rx_cq_scale_factor,
52                  "Factor applied to credits to determine RX CQ size");
53
54 unsigned int tx_cq_scale_factor = 10;
55 module_param(tx_cq_scale_factor, uint, 0444);
56 MODULE_PARM_DESC(tx_cq_scale_factor,
57                  "Factor applied to credits to determine TX CQ size");
58
59 unsigned int eq_size = 1024;
60 module_param(eq_size, uint, 0444);
61 MODULE_PARM_DESC(eq_size, "Default event queue size used by all kfi LNet NIs");
62
63 unsigned int immediate_rx_buf_count = 8;
64 module_param(immediate_rx_buf_count, uint, 0444);
65 MODULE_PARM_DESC(immediate_rx_buf_count,
66                  "Number of immediate multi-receive buffers posted per CPT");
67
68 /* Common LND network tunables. */
69 static int credits = 256;
70 module_param(credits, int, 0444);
71 MODULE_PARM_DESC(credits, "Number of concurrent sends on network");
72
73 static int peer_credits = 16;
74 module_param(peer_credits, int, 0444);
75 MODULE_PARM_DESC(peer_credits, "Number of concurrent sends to 1 peer");
76
77 static int peer_buffer_credits = -1;
78 module_param(peer_buffer_credits, int, 0444);
79 MODULE_PARM_DESC(peer_buffer_credits,
80                  "Number of per-peer router buffer credits");
81
82 static int peer_timeout = -1;
83 module_param(peer_timeout, int, 0444);
84 MODULE_PARM_DESC(peer_timeout,
85                  "Seconds without aliveness news to declare peer dead (less than or equal to 0 to disable).");
86
87 static unsigned int prov_major_version = 1;
88 module_param(prov_major_version, int, 0444);
89 MODULE_PARM_DESC(prov_major_version,
90                  "Default kfabric provider major version kfilnd should use");
91
92 static unsigned int prov_minor_version;
93 module_param(prov_minor_version, int, 0444);
94 MODULE_PARM_DESC(prov_minor_version,
95                  "Default kfabric provider minor version kfilnd should use");
96
97 static unsigned int auth_key = 255;
98 module_param(auth_key, uint, 0444);
99 MODULE_PARM_DESC(auth_key, "Default authorization key to be used for LNet NIs");
100
101 static char *traffic_class = "best_effort";
102 module_param(traffic_class, charp, 0444);
103 MODULE_PARM_DESC(traffic_class, "Traffic class - default is \"best_effort\"");
104
105 static int
106 kfilnd_tcstr2num(char *tcstr)
107 {
108         if (!strcmp(tcstr, "best_effort"))
109                 return KFI_TC_BEST_EFFORT;
110         if (!strcmp(tcstr, "low_latency"))
111                 return KFI_TC_LOW_LATENCY;
112         if (!strcmp(tcstr, "dedicated_access"))
113                 return KFI_TC_DEDICATED_ACCESS;
114         if (!strcmp(tcstr, "bulk_data"))
115                 return KFI_TC_BULK_DATA;
116         if (!strcmp(tcstr, "scavenger"))
117                 return KFI_TC_SCAVENGER;
118         if (!strcmp(tcstr, "network_ctrl"))
119                 return KFI_TC_NETWORK_CTRL;
120         return -1;
121 }
122
123 int kfilnd_tunables_setup(struct lnet_ni *ni)
124 {
125         struct lnet_ioctl_config_lnd_cmn_tunables *net_tunables;
126         struct lnet_ioctl_config_kfilnd_tunables *kfilnd_tunables;
127
128         net_tunables = &ni->ni_net->net_tunables;
129         kfilnd_tunables = &ni->ni_lnd_tunables.lnd_tun_u.lnd_kfi;
130
131         if (net_tunables->lct_peer_timeout == -1)
132                 net_tunables->lct_peer_timeout = peer_timeout;
133
134         if (net_tunables->lct_max_tx_credits == -1)
135                 net_tunables->lct_max_tx_credits = credits;
136
137         if (net_tunables->lct_peer_tx_credits == -1)
138                 net_tunables->lct_peer_tx_credits = peer_credits;
139
140         if (net_tunables->lct_peer_rtr_credits == -1)
141                 net_tunables->lct_peer_rtr_credits = peer_buffer_credits;
142
143         if (net_tunables->lct_peer_tx_credits >
144                 net_tunables->lct_max_tx_credits)
145                 net_tunables->lct_peer_tx_credits =
146                         net_tunables->lct_max_tx_credits;
147
148         kfilnd_tunables->lnd_version = KFILND_MSG_VERSION;
149         if (!ni->ni_lnd_tunables_set) {
150                 kfilnd_tunables->lnd_prov_major_version = prov_major_version;
151                 kfilnd_tunables->lnd_prov_minor_version = prov_minor_version;
152                 kfilnd_tunables->lnd_auth_key = auth_key;
153                 if (strlen(traffic_class) < LNET_MAX_STR_LEN)
154                         strcpy(&kfilnd_tunables->lnd_traffic_class_str[0],
155                                traffic_class);
156         }
157
158         /* Treat kfilnd_tunables set to zero as uninitialized. */
159         if (kfilnd_tunables->lnd_prov_major_version == 0 &&
160                 kfilnd_tunables->lnd_prov_major_version == 0) {
161                 kfilnd_tunables->lnd_prov_major_version = prov_major_version;
162                 kfilnd_tunables->lnd_prov_minor_version = prov_minor_version;
163         }
164
165         if (kfilnd_tunables->lnd_auth_key == 0)
166                 kfilnd_tunables->lnd_auth_key = auth_key;
167
168         if (strlen(kfilnd_tunables->lnd_traffic_class_str) == 0 &&
169             strlen(traffic_class) < LNET_MAX_STR_LEN)
170                 strcpy(&kfilnd_tunables->lnd_traffic_class_str[0],
171                        traffic_class);
172
173         kfilnd_tunables->lnd_traffic_class =
174                 kfilnd_tcstr2num(kfilnd_tunables->lnd_traffic_class_str);
175
176         if (net_tunables->lct_max_tx_credits > KFILND_EP_KEY_MAX) {
177                 CERROR("Credits cannot exceed %lu\n", KFILND_EP_KEY_MAX);
178                 return -EINVAL;
179         }
180
181         if (net_tunables->lct_peer_tx_credits > KFILND_EP_KEY_MAX) {
182                 CERROR("Peer credits cannot exceed %lu\n", KFILND_EP_KEY_MAX);
183                 return -EINVAL;
184         }
185
186         if (kfilnd_tunables->lnd_prov_major_version > prov_major_version) {
187                 CERROR("Provider major version greater than %d unsupported\n",
188                         prov_major_version);
189                 return -EINVAL;
190         }
191
192         if (kfilnd_tunables->lnd_traffic_class == -1) {
193                 CERROR("Invalid traffic_class \"%s\" - Valid values are: best_effort, low_latency, dedicated_access, bulk_data, scavenger, and network_ctrl\n",
194                        kfilnd_tunables->lnd_traffic_class_str);
195                 return -EINVAL;
196         }
197
198         return 0;
199 }
200
201 int kfilnd_tunables_init(void)
202 {
203         if (tx_scale_factor < 1) {
204                 CERROR("TX context scale factor less than 1");
205                 return -EINVAL;
206         }
207
208         if (rx_cq_scale_factor < 1) {
209                 CERROR("RX CQ scale factor less than 1");
210                 return -EINVAL;
211         }
212
213         if (tx_cq_scale_factor < 1) {
214                 CERROR("TX CQ scale factor less than 1");
215                 return -EINVAL;
216         }
217
218         if (immediate_rx_buf_count < 2) {
219                 CERROR("Immediate multi-receive buffer count less than 2");
220                 return -EINVAL;
221         }
222
223         if (auth_key < 1) {
224                 CERROR("Authorization key cannot be less than 1");
225                 return -EINVAL;
226         }
227
228         if (credits > KFILND_EP_KEY_MAX) {
229                 CERROR("Credits cannot exceed %lu\n", KFILND_EP_KEY_MAX);
230                 return -EINVAL;
231         }
232
233         if (peer_credits > KFILND_EP_KEY_MAX) {
234                 CERROR("Peer credits cannot exceed %lu\n", KFILND_EP_KEY_MAX);
235                 return -EINVAL;
236         }
237
238         if (kfilnd_tcstr2num(traffic_class) == -1) {
239                 CERROR("Invalid traffic_class \"%s\" - Valid values are: best_effort, low_latency, dedicated_access, bulk_data, scavenger, and network_ctrl\n",
240                        traffic_class);
241                 return -EINVAL;
242         }
243
244         return 0;
245 }