Whamcloud - gitweb
ac36cd7c75af69d5aec53241da3bf0f49cb95afb
[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 int kfilnd_tunables_setup(struct lnet_ni *ni)
102 {
103         struct lnet_ioctl_config_lnd_cmn_tunables *net_tunables;
104         struct lnet_ioctl_config_kfilnd_tunables *kfilnd_tunables;
105
106         net_tunables = &ni->ni_net->net_tunables;
107         kfilnd_tunables = &ni->ni_lnd_tunables.lnd_tun_u.lnd_kfi;
108
109         if (net_tunables->lct_peer_timeout == -1)
110                 net_tunables->lct_peer_timeout = peer_timeout;
111
112         if (net_tunables->lct_max_tx_credits == -1)
113                 net_tunables->lct_max_tx_credits = credits;
114
115         if (net_tunables->lct_peer_tx_credits == -1)
116                 net_tunables->lct_peer_tx_credits = peer_credits;
117
118         if (net_tunables->lct_peer_rtr_credits == -1)
119                 net_tunables->lct_peer_rtr_credits = peer_buffer_credits;
120
121         if (net_tunables->lct_peer_tx_credits >
122                 net_tunables->lct_max_tx_credits)
123                 net_tunables->lct_peer_tx_credits =
124                         net_tunables->lct_max_tx_credits;
125
126         kfilnd_tunables->lnd_version = KFILND_MSG_VERSION;
127         if (!ni->ni_lnd_tunables_set) {
128                 kfilnd_tunables->lnd_prov_major_version = prov_major_version;
129                 kfilnd_tunables->lnd_prov_minor_version = prov_minor_version;
130                 kfilnd_tunables->lnd_auth_key = auth_key;
131         }
132
133         /* Treat kfilnd_tunables set to zero as uninitialized. */
134         if (kfilnd_tunables->lnd_prov_major_version == 0 &&
135                 kfilnd_tunables->lnd_prov_major_version == 0) {
136                 kfilnd_tunables->lnd_prov_major_version = prov_major_version;
137                 kfilnd_tunables->lnd_prov_minor_version = prov_minor_version;
138         }
139
140         if (kfilnd_tunables->lnd_auth_key == 0)
141                 kfilnd_tunables->lnd_auth_key = auth_key;
142
143         if (net_tunables->lct_max_tx_credits > KFILND_EP_KEY_MAX) {
144                 CERROR("Credits cannot exceed %lu\n", KFILND_EP_KEY_MAX);
145                 return -EINVAL;
146         }
147
148         if (net_tunables->lct_peer_tx_credits > KFILND_EP_KEY_MAX) {
149                 CERROR("Peer credits cannot exceed %lu\n", KFILND_EP_KEY_MAX);
150                 return -EINVAL;
151         }
152
153         if (kfilnd_tunables->lnd_prov_major_version > prov_major_version) {
154                 CERROR("Provider major version greater than %d unsupported\n",
155                         prov_major_version);
156                 return -EINVAL;
157         }
158
159         return 0;
160 }
161
162 int kfilnd_tunables_init(void)
163 {
164         if (tx_scale_factor < 1) {
165                 CERROR("TX context scale factor less than 1");
166                 return -EINVAL;
167         }
168
169         if (rx_cq_scale_factor < 1) {
170                 CERROR("RX CQ scale factor less than 1");
171                 return -EINVAL;
172         }
173
174         if (tx_cq_scale_factor < 1) {
175                 CERROR("TX CQ scale factor less than 1");
176                 return -EINVAL;
177         }
178
179         if (immediate_rx_buf_count < 2) {
180                 CERROR("Immediate multi-receive buffer count less than 2");
181                 return -EINVAL;
182         }
183
184         if (auth_key < 1) {
185                 CERROR("Authorization key cannot be less than 1");
186                 return -EINVAL;
187         }
188
189         if (credits > KFILND_EP_KEY_MAX) {
190                 CERROR("Credits cannot exceed %lu\n", KFILND_EP_KEY_MAX);
191                 return -EINVAL;
192         }
193
194         if (peer_credits > KFILND_EP_KEY_MAX) {
195                 CERROR("Peer credits cannot exceed %lu\n", KFILND_EP_KEY_MAX);
196                 return -EINVAL;
197         }
198
199         return 0;
200 }