GNU Linux-libre 4.9.292-gnu1
[releases.git] / drivers / staging / lustre / lnet / klnds / o2iblnd / o2iblnd_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 (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
24  * Use is subject to license terms.
25  *
26  * Copyright (c) 2012, Intel Corporation.
27  */
28 /*
29  * This file is part of Lustre, http://www.lustre.org/
30  * Lustre is a trademark of Sun Microsystems, Inc.
31  *
32  * lnet/klnds/o2iblnd/o2iblnd_modparams.c
33  *
34  * Author: Eric Barton <eric@bartonsoftware.com>
35  */
36
37 #include "o2iblnd.h"
38
39 static int service = 987;
40 module_param(service, int, 0444);
41 MODULE_PARM_DESC(service, "service number (within RDMA_PS_TCP)");
42
43 static int cksum;
44 module_param(cksum, int, 0644);
45 MODULE_PARM_DESC(cksum, "set non-zero to enable message (not RDMA) checksums");
46
47 static int timeout = 50;
48 module_param(timeout, int, 0644);
49 MODULE_PARM_DESC(timeout, "timeout (seconds)");
50
51 /*
52  * Number of threads in each scheduler pool which is percpt,
53  * we will estimate reasonable value based on CPUs if it's set to zero.
54  */
55 static int nscheds;
56 module_param(nscheds, int, 0444);
57 MODULE_PARM_DESC(nscheds, "number of threads in each scheduler pool");
58
59 /* NB: this value is shared by all CPTs, it can grow at runtime */
60 static int ntx = 512;
61 module_param(ntx, int, 0444);
62 MODULE_PARM_DESC(ntx, "# of message descriptors allocated for each pool");
63
64 /* NB: this value is shared by all CPTs */
65 static int credits = 256;
66 module_param(credits, int, 0444);
67 MODULE_PARM_DESC(credits, "# concurrent sends");
68
69 static int peer_credits = 8;
70 module_param(peer_credits, int, 0444);
71 MODULE_PARM_DESC(peer_credits, "# concurrent sends to 1 peer");
72
73 static int peer_credits_hiw;
74 module_param(peer_credits_hiw, int, 0444);
75 MODULE_PARM_DESC(peer_credits_hiw, "when eagerly to return credits");
76
77 static int peer_buffer_credits;
78 module_param(peer_buffer_credits, int, 0444);
79 MODULE_PARM_DESC(peer_buffer_credits, "# per-peer router buffer credits");
80
81 static int peer_timeout = 180;
82 module_param(peer_timeout, int, 0444);
83 MODULE_PARM_DESC(peer_timeout, "Seconds without aliveness news to declare peer dead (<=0 to disable)");
84
85 static char *ipif_name = "ib0";
86 module_param(ipif_name, charp, 0444);
87 MODULE_PARM_DESC(ipif_name, "IPoIB interface name");
88
89 static int retry_count = 5;
90 module_param(retry_count, int, 0644);
91 MODULE_PARM_DESC(retry_count, "Retransmissions when no ACK received");
92
93 static int rnr_retry_count = 6;
94 module_param(rnr_retry_count, int, 0644);
95 MODULE_PARM_DESC(rnr_retry_count, "RNR retransmissions");
96
97 static int keepalive = 100;
98 module_param(keepalive, int, 0644);
99 MODULE_PARM_DESC(keepalive, "Idle time in seconds before sending a keepalive");
100
101 static int ib_mtu;
102 module_param(ib_mtu, int, 0444);
103 MODULE_PARM_DESC(ib_mtu, "IB MTU 256/512/1024/2048/4096");
104
105 static int concurrent_sends;
106 module_param(concurrent_sends, int, 0444);
107 MODULE_PARM_DESC(concurrent_sends, "send work-queue sizing");
108
109 static int map_on_demand;
110 module_param(map_on_demand, int, 0444);
111 MODULE_PARM_DESC(map_on_demand, "map on demand");
112
113 /* NB: this value is shared by all CPTs, it can grow at runtime */
114 static int fmr_pool_size = 512;
115 module_param(fmr_pool_size, int, 0444);
116 MODULE_PARM_DESC(fmr_pool_size, "size of fmr pool on each CPT (>= ntx / 4)");
117
118 /* NB: this value is shared by all CPTs, it can grow at runtime */
119 static int fmr_flush_trigger = 384;
120 module_param(fmr_flush_trigger, int, 0444);
121 MODULE_PARM_DESC(fmr_flush_trigger, "# dirty FMRs that triggers pool flush");
122
123 static int fmr_cache = 1;
124 module_param(fmr_cache, int, 0444);
125 MODULE_PARM_DESC(fmr_cache, "non-zero to enable FMR caching");
126
127 /*
128  * 0: disable failover
129  * 1: enable failover if necessary
130  * 2: force to failover (for debug)
131  */
132 static int dev_failover;
133 module_param(dev_failover, int, 0444);
134 MODULE_PARM_DESC(dev_failover, "HCA failover for bonding (0 off, 1 on, other values reserved)");
135
136 static int require_privileged_port;
137 module_param(require_privileged_port, int, 0644);
138 MODULE_PARM_DESC(require_privileged_port, "require privileged port when accepting connection");
139
140 static int use_privileged_port = 1;
141 module_param(use_privileged_port, int, 0644);
142 MODULE_PARM_DESC(use_privileged_port, "use privileged port when initiating connection");
143
144 struct kib_tunables kiblnd_tunables = {
145         .kib_dev_failover      = &dev_failover,
146         .kib_service           = &service,
147         .kib_cksum             = &cksum,
148         .kib_timeout           = &timeout,
149         .kib_keepalive         = &keepalive,
150         .kib_ntx               = &ntx,
151         .kib_default_ipif      = &ipif_name,
152         .kib_retry_count       = &retry_count,
153         .kib_rnr_retry_count   = &rnr_retry_count,
154         .kib_ib_mtu            = &ib_mtu,
155         .kib_require_priv_port = &require_privileged_port,
156         .kib_use_priv_port     = &use_privileged_port,
157         .kib_nscheds           = &nscheds
158 };
159
160 static struct lnet_ioctl_config_o2iblnd_tunables default_tunables;
161
162 /* # messages/RDMAs in-flight */
163 int kiblnd_msg_queue_size(int version, lnet_ni_t *ni)
164 {
165         if (version == IBLND_MSG_VERSION_1)
166                 return IBLND_MSG_QUEUE_SIZE_V1;
167         else if (ni)
168                 return ni->ni_peertxcredits;
169         else
170                 return peer_credits;
171 }
172
173 int kiblnd_tunables_setup(struct lnet_ni *ni)
174 {
175         struct lnet_ioctl_config_o2iblnd_tunables *tunables;
176
177         /*
178          * if there was no tunables specified, setup the tunables to be
179          * defaulted
180          */
181         if (!ni->ni_lnd_tunables) {
182                 LIBCFS_ALLOC(ni->ni_lnd_tunables,
183                              sizeof(*ni->ni_lnd_tunables));
184                 if (!ni->ni_lnd_tunables)
185                         return -ENOMEM;
186
187                 memcpy(&ni->ni_lnd_tunables->lt_tun_u.lt_o2ib,
188                        &default_tunables, sizeof(*tunables));
189         }
190         tunables = &ni->ni_lnd_tunables->lt_tun_u.lt_o2ib;
191
192         /* Current API version */
193         tunables->lnd_version = 0;
194
195         if (kiblnd_translate_mtu(*kiblnd_tunables.kib_ib_mtu) < 0) {
196                 CERROR("Invalid ib_mtu %d, expected 256/512/1024/2048/4096\n",
197                        *kiblnd_tunables.kib_ib_mtu);
198                 return -EINVAL;
199         }
200
201         if (!ni->ni_peertimeout)
202                 ni->ni_peertimeout = peer_timeout;
203
204         if (!ni->ni_maxtxcredits)
205                 ni->ni_maxtxcredits = credits;
206
207         if (!ni->ni_peertxcredits)
208                 ni->ni_peertxcredits = peer_credits;
209
210         if (!ni->ni_peerrtrcredits)
211                 ni->ni_peerrtrcredits = peer_buffer_credits;
212
213         if (ni->ni_peertxcredits < IBLND_CREDITS_DEFAULT)
214                 ni->ni_peertxcredits = IBLND_CREDITS_DEFAULT;
215
216         if (ni->ni_peertxcredits > IBLND_CREDITS_MAX)
217                 ni->ni_peertxcredits = IBLND_CREDITS_MAX;
218
219         if (ni->ni_peertxcredits > credits)
220                 ni->ni_peertxcredits = credits;
221
222         if (!tunables->lnd_peercredits_hiw)
223                 tunables->lnd_peercredits_hiw = peer_credits_hiw;
224
225         if (tunables->lnd_peercredits_hiw < ni->ni_peertxcredits / 2)
226                 tunables->lnd_peercredits_hiw = ni->ni_peertxcredits / 2;
227
228         if (tunables->lnd_peercredits_hiw >= ni->ni_peertxcredits)
229                 tunables->lnd_peercredits_hiw = ni->ni_peertxcredits - 1;
230
231         if (tunables->lnd_map_on_demand < 0 ||
232             tunables->lnd_map_on_demand > IBLND_MAX_RDMA_FRAGS) {
233                 /* disable map-on-demand */
234                 tunables->lnd_map_on_demand = 0;
235         }
236
237         if (tunables->lnd_map_on_demand == 1) {
238                 /* don't make sense to create map if only one fragment */
239                 tunables->lnd_map_on_demand = 2;
240         }
241
242         if (!tunables->lnd_concurrent_sends) {
243                 if (tunables->lnd_map_on_demand > 0 &&
244                     tunables->lnd_map_on_demand <= IBLND_MAX_RDMA_FRAGS / 8) {
245                         tunables->lnd_concurrent_sends =
246                                                 ni->ni_peertxcredits * 2;
247                 } else {
248                         tunables->lnd_concurrent_sends = ni->ni_peertxcredits;
249                 }
250         }
251
252         if (tunables->lnd_concurrent_sends > ni->ni_peertxcredits * 2)
253                 tunables->lnd_concurrent_sends = ni->ni_peertxcredits * 2;
254
255         if (tunables->lnd_concurrent_sends < ni->ni_peertxcredits / 2)
256                 tunables->lnd_concurrent_sends = ni->ni_peertxcredits / 2;
257
258         if (tunables->lnd_concurrent_sends < ni->ni_peertxcredits) {
259                 CWARN("Concurrent sends %d is lower than message queue size: %d, performance may drop slightly.\n",
260                       tunables->lnd_concurrent_sends, ni->ni_peertxcredits);
261         }
262
263         if (!tunables->lnd_fmr_pool_size)
264                 tunables->lnd_fmr_pool_size = fmr_pool_size;
265         if (!tunables->lnd_fmr_flush_trigger)
266                 tunables->lnd_fmr_flush_trigger = fmr_flush_trigger;
267         if (!tunables->lnd_fmr_cache)
268                 tunables->lnd_fmr_cache = fmr_cache;
269
270         return 0;
271 }
272
273 void kiblnd_tunables_init(void)
274 {
275         default_tunables.lnd_version = 0;
276         default_tunables.lnd_peercredits_hiw = peer_credits_hiw,
277         default_tunables.lnd_map_on_demand = map_on_demand;
278         default_tunables.lnd_concurrent_sends = concurrent_sends;
279         default_tunables.lnd_fmr_pool_size = fmr_pool_size;
280         default_tunables.lnd_fmr_flush_trigger = fmr_flush_trigger;
281         default_tunables.lnd_fmr_cache = fmr_cache;
282 }