Skip to content

Commit 941bf38

Browse files
Added new tool to configure congestion in MH
Signed-off-by: Adham Masarwah <[email protected]>
1 parent 9d144df commit 941bf38

File tree

8 files changed

+959
-243
lines changed

8 files changed

+959
-243
lines changed

mstflint.spec.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ rm -rf $RPM_BUILD_ROOT
105105
%{_bindir}/mstmcra
106106
%{_bindir}/mstconfig
107107
%{_bindir}/mstfwreset
108+
%{_bindir}/mstcongestion
108109
%if %{enablefwmgr}
109110
%{_bindir}/mstfwmanager
110111
%{CONF_DIR}/ca-bundle.crt

reg_access/reg_access.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
#define REG_ID_MNVGN 0x9035
5050
#define REG_ID_MLCOK 0x402D
5151

52+
#define REG_ID_MPEGC 0x9056
5253

5354
#define REG_ID_MCDA 0x9063
5455
#define REG_ID_MCQS 0x9060
@@ -57,6 +58,7 @@
5758
#define REG_ID_MCAM 0x907f
5859
#define REG_ID_MQIS 0x9064
5960

61+
6062
// TODO: get correct register ID for mfrl mfai
6163
#define REG_ID_MFRL 0x9028
6264
#define REG_ID_MFAI 0x9029
@@ -445,6 +447,13 @@ reg_access_status_t reg_access_mqis(mfile *mf, reg_access_method_t method, struc
445447
reg_access_hca, reg_size, r_size_reg, w_size_reg, reg_access_hca_mqis_reg_size, info_string, read_length);
446448
}
447449

450+
451+
452+
reg_access_status_t reg_access_mpegc(mfile *mf, reg_access_method_t method, struct reg_access_hca_mpegc_reg *mpegc)
453+
{
454+
// reg_access_hca_mpegc_reg_dump(mpegc, stdout)s;
455+
REG_ACCCESS(mf, method, REG_ID_MPEGC, mpegc, mpegc_reg, reg_access_hca);
456+
}
448457
/************************************
449458
* Function: reg_access_err2str
450459
************************************/

reg_access/reg_access.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ reg_access_status_t reg_access_nvqgc(mfile *mf, reg_access_method_t method, stru
7878
reg_access_status_t reg_access_mvts(mfile *mf, reg_access_method_t method, struct tools_open_mvts *mvts);
7979
reg_access_status_t reg_access_mnvgn(mfile *mf, reg_access_method_t method, struct tools_open_mnvgn *mnvgn, int *status);
8080
reg_access_status_t reg_access_mfmc(mfile *mf, reg_access_method_t method, struct tools_open_mfmc *mfmc);
81+
reg_access_status_t reg_access_mpegc(mfile *mf, reg_access_method_t method, struct reg_access_hca_mpegc_reg *mpegc);
8182

8283
reg_access_status_t reg_access_mcam(mfile *mf, reg_access_method_t method, struct tools_open_mcam *mcam);
8384
reg_access_status_t reg_access_secure_host(mfile *mf, reg_access_method_t method, struct tools_open_mlock *mlock);

small_utils/Makefile.am

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ bin_PROGRAMS = mstmread \
4141
mstmwrite \
4242
mstmcra \
4343
mstmtserver \
44-
mstvpd
44+
mstvpd \
45+
mstcongestion
4546

4647
bin_SCRIPTS = mstfwreset
4748

@@ -52,6 +53,13 @@ mstmwrite_SOURCES = mwrite.c
5253
mstvpd_SOURCES = vpd.c
5354
mstvpd_LDADD = $(top_srcdir)/mvpd/libmvpd.a $(top_srcdir)/${MTCR_CONF_DIR}/libmtcr_ul.a ${LDL}
5455

56+
mstcongestion_SOURCES = congestion.cpp
57+
mstcongestion_LDADD = $(top_srcdir)/cmdif/libcmdif.a \
58+
$(top_srcdir)/reg_access/libreg_access.a \
59+
$(top_srcdir)/tools_layouts/libtools_layouts.a \
60+
$(top_srcdir)/cmdparser/libcmdparser.a \
61+
$(top_srcdir)/${MTCR_CONF_DIR}/libmtcr_ul.a ${LDL}
62+
5563
mstmcra_SOURCES = mcra.c
5664

5765
mstmtserver_SOURCES = mtserver.c tcp.c tcp.h

small_utils/congestion.cpp

Lines changed: 272 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,272 @@
1+
/*
2+
* Copyright (C) Jan 2013 Mellanox Technologies Ltd. All rights reserved.
3+
*
4+
* This software is available to you under a choice of one of two
5+
* licenses. You may choose to be licensed under the terms of the GNU
6+
* General Public License (GPL) Version 2, available from the file
7+
* COPYING in the main directory of this source tree, or the
8+
* OpenIB.org BSD license below:
9+
*
10+
* Redistribution and use in source and binary forms, with or
11+
* without modification, are permitted provided that the following
12+
* conditions are met:
13+
*
14+
* - Redistributions of source code must retain the above
15+
* copyright notice, this list of conditions and the following
16+
* disclaimer.
17+
*
18+
* - Redistributions in binary form must reproduce the above
19+
* copyright notice, this list of conditions and the following
20+
* disclaimer in the documentation and/or other materials
21+
* provided with the distribution.
22+
*
23+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25+
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26+
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
27+
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
28+
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29+
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30+
* SOFTWARE.
31+
*
32+
*/
33+
34+
#include "congestion.h"
35+
#include "reg_access/reg_access.h"
36+
#include "common/tools_version.h"
37+
#include <stdlib.h>
38+
#include <iostream>
39+
40+
using namespace std;
41+
42+
enum {
43+
BIT_TX_LOSSY_OPER = 1,
44+
BIT_TX_SENSE = 1 << 3,
45+
BIT_MARK_TX_CQE = 1 << 4,
46+
BIT_MARK_TX_CNP = 1 << 5,
47+
};
48+
49+
int main(int argc, char **argv)
50+
{
51+
CongestionUI congestObject;
52+
if (!congestObject.run(argc, argv)) {
53+
cout << "-E- Failed to perform the operation: " << congestObject.getError() << endl;
54+
return 1;
55+
} else {
56+
if (congestObject.getSuccess() != "") {
57+
cout << "-I- " << congestObject.getSuccess() << endl;
58+
}
59+
}
60+
return 0;
61+
}
62+
63+
64+
CongestionUI::CongestionUI() :
65+
CommandLineRequester("mstcongestion [OPTIONS]"),
66+
_cmdParser("mstcongestion")
67+
{
68+
_mf = NULL;
69+
_action = ACTION_NA;
70+
_mode = MODE_NA;
71+
_query = false;
72+
_ops = 0;
73+
_dynamicSupp = 0;
74+
_markCqeSupp = 0;
75+
_markCnpSupp = 0;
76+
initCmdParser();
77+
}
78+
79+
CongestionUI::~CongestionUI()
80+
{
81+
if (_mf) {
82+
mclose(_mf);
83+
_mf = NULL;
84+
}
85+
}
86+
87+
void CongestionUI::initCmdParser()
88+
{
89+
90+
AddOptions("device", 'd', "<PCI DEVICE>", "Mellanox PCI device address");
91+
AddOptions("mode", ' ', "<MODE>", "Set Mode, options are: [aggressive | dynamic]");
92+
AddOptions("action", ' ', "<ACTION>", "Set Action, options are: [disabled | drop | mark]");
93+
AddOptions("query", 'q', "", "Query congestion");
94+
AddOptions("help", 'h', "", "Show help message and exit");
95+
AddOptions("version", 'v', "", "Show version and exit");
96+
AddDescription("mstcongestion is a tool to set Congestion mode and action.");
97+
_cmdParser.AddRequester(this);
98+
}
99+
100+
ParseStatus CongestionUI::HandleOption(string name, string value)
101+
{
102+
if (name == "device") {
103+
_devname = value;
104+
} else if (name == "mode" ) {
105+
_ops++;
106+
if (value == "aggressive") {
107+
_mode = MODE_AGGRESSIVE;
108+
} else if (value == "dynamic") {
109+
_mode = MODE_DYNAMIC;
110+
} else {
111+
_errorMsg = "Invalid mode, options are: [aggressive | dynamic]";
112+
return PARSE_ERROR;
113+
}
114+
} else if (name == "action") {
115+
_ops++;
116+
if (value == "disabled") {
117+
_action = ACTION_DISABLED;
118+
} else if (value == "drop") {
119+
_action = ACTION_DROP;
120+
} else if (value == "mark") {
121+
_action = ACTION_MARK;
122+
} else {
123+
_errorMsg = "Invalid action, options are: [disabled | drop | mark]";
124+
return PARSE_ERROR;
125+
}
126+
} else if (name == "help") {
127+
cout << _cmdParser.GetUsage() << endl;
128+
return PARSE_OK_WITH_EXIT;
129+
} else if (name == "version") {
130+
print_version_string("mstcongestion", NULL);
131+
return PARSE_OK_WITH_EXIT;
132+
} else if (name == "query") {
133+
_ops++;
134+
_query = true;
135+
} else {
136+
_errorMsg = "Invalid option: " + name;
137+
return PARSE_ERROR;
138+
}
139+
return PARSE_OK;
140+
}
141+
142+
bool CongestionUI::run(int argc, char** argv)
143+
{
144+
ParseStatus rc = _cmdParser.ParseOptions(argc, argv);
145+
if (rc == PARSE_OK_WITH_EXIT) {
146+
return true;
147+
} else if (rc == PARSE_ERROR) {
148+
if (_errorMsg == "") {
149+
_errorMsg = "Failed while parsing the arguments.";
150+
}
151+
return false;
152+
}
153+
154+
if (_devname == "") {
155+
_errorMsg = "Missing device.";
156+
return false;
157+
}
158+
_mf = mopen(_devname.c_str());
159+
if (!_mf) {
160+
_errorMsg = "Failed to open device: " + _devname;
161+
return false;
162+
}
163+
struct tools_open_mcam mcam;
164+
memset(&mcam, 0, sizeof(mcam));
165+
reg_access_status_t status = reg_access_mcam(_mf, REG_ACCESS_METHOD_GET, &mcam);
166+
if (status) {
167+
_errorMsg = "Failed to get device capabilities!";
168+
return false;
169+
}
170+
u_int8_t caps = mcam.mng_feature_cap_mask[14];
171+
_dynamicSupp = caps & 0x2;
172+
_markCqeSupp = caps & 0x4;
173+
_markCnpSupp = caps & 0x8;
174+
if (_ops != 1) {
175+
_errorMsg = "Please choose one operation.";
176+
return false;
177+
}
178+
if (_mode != MODE_NA) {
179+
return setMode(_mode);
180+
} else if (_action != ACTION_NA) {
181+
return setAction(_action);
182+
} else if (_query) {
183+
return query();
184+
}
185+
return true;
186+
}
187+
188+
189+
bool CongestionUI::setMode(cong_mode_t mode)
190+
{
191+
if (!_dynamicSupp) {
192+
_errorMsg = "Dynamic overflow is not supported.";
193+
return false;
194+
}
195+
_successMsg = "Mode was set successfully.";
196+
struct reg_access_hca_mpegc_reg mpegc;
197+
memset(&mpegc, 0, sizeof (mpegc));
198+
mpegc.tx_overflow_sense = (int)mode;
199+
mpegc.field_select |= BIT_TX_SENSE;
200+
reg_access_status_t status = reg_access_mpegc(_mf, REG_ACCESS_METHOD_SET, &mpegc);
201+
if (status) {
202+
_errorMsg = string(reg_access_err2str(status));
203+
return false;
204+
}
205+
return true;
206+
}
207+
208+
bool CongestionUI::setAction(cong_action_t action)
209+
{
210+
_successMsg = "Action was set successfully.";
211+
struct reg_access_hca_mpegc_reg mpegc;
212+
memset(&mpegc, 0, sizeof (mpegc));
213+
mpegc.tx_lossy_overflow_oper = (int)action;
214+
mpegc.field_select |= BIT_TX_LOSSY_OPER;
215+
if (action == ACTION_MARK) {
216+
if (_markCqeSupp) {
217+
mpegc.field_select |= BIT_MARK_TX_CQE;
218+
mpegc.mark_cqe = 1;
219+
}
220+
if (_markCnpSupp) {
221+
mpegc.field_select |= BIT_MARK_TX_CNP;
222+
mpegc.mark_cnp = 1;
223+
}
224+
}
225+
reg_access_status_t status = reg_access_mpegc(_mf, REG_ACCESS_METHOD_SET, &mpegc);
226+
if (status) {
227+
_errorMsg = string(reg_access_err2str(status));
228+
return false;
229+
}
230+
return true;
231+
}
232+
233+
bool CongestionUI::query()
234+
{
235+
struct reg_access_hca_mpegc_reg mpegc;
236+
memset(&mpegc, 0, sizeof (mpegc));
237+
reg_access_status_t status = reg_access_mpegc(_mf, REG_ACCESS_METHOD_GET, &mpegc);
238+
if (status) {
239+
_errorMsg = string(reg_access_err2str(status));
240+
return false;
241+
}
242+
printf("Action: %s\nMode: %s\n", getActionString((cong_action_t)mpegc.tx_lossy_overflow_oper).c_str(),
243+
getModeString((cong_mode_t)mpegc.tx_overflow_sense).c_str());
244+
return true;
245+
}
246+
247+
248+
string CongestionUI::getModeString(cong_mode_t mode)
249+
{
250+
switch (mode) {
251+
case MODE_AGGRESSIVE:
252+
return "Aggressive";
253+
case MODE_DYNAMIC:
254+
return "Dynamic";
255+
default:
256+
return "N/A";
257+
}
258+
}
259+
260+
string CongestionUI::getActionString(cong_action_t action)
261+
{
262+
switch (action) {
263+
case ACTION_DISABLED:
264+
return "Disabled";
265+
case ACTION_DROP:
266+
return "Drop";
267+
case ACTION_MARK:
268+
return "Mark";
269+
default:
270+
return "N/A";
271+
}
272+
}

0 commit comments

Comments
 (0)