Skip to content

Commit e48469e

Browse files
committed
ethtool: bindings for binding for ETHTOOL_[GS]RINGPARAM
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
1 parent e7b8606 commit e48469e

File tree

2 files changed

+129
-2
lines changed

2 files changed

+129
-2
lines changed

ethtool-cmd.py

Lines changed: 79 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,75 @@ def set_offload(interface, args):
207207
except:
208208
pass
209209

210+
ethtool_ringparam_msgs = (
211+
( "Pre-set maximums", ),
212+
( "RX:\t\t", "rx_max_pending" ),
213+
( "RX Mini:\t", "rx_mini_max_pending" ),
214+
( "RX Jumbo:\t", "rx_jumbo_max_pending" ),
215+
( "TX:\t\t", "tx_max_pending" ),
216+
( "Current hardware settings", ),
217+
( "RX:\t\t", "rx_pending" ),
218+
( "RX Mini:\t", "rx_mini_pending" ),
219+
( "RX Jumbo:\t", "rx_jumbo_pending" ),
220+
( "TX:\t\t", "tx_pending" ),
221+
)
222+
223+
def show_ring(interface, args = None):
224+
printtab("Ring parameters for %s:" % interface)
225+
try:
226+
ring = ethtool.get_ringparam(interface)
227+
except IOError:
228+
printtab(" NOT supported!")
229+
return
230+
231+
printed = []
232+
for tunable in ethtool_ringparam_msgs:
233+
if len(tunable) == 1:
234+
printtab("%s:" % tunable[0])
235+
else:
236+
printtab("%s %s" % (tunable[0], ring[tunable[1]]))
237+
printed.append(tunable[1])
238+
239+
ringkeys = ring.keys()
240+
if len(ringkeys) != len(printed):
241+
print
242+
for tunable in ringkeys:
243+
if tunable not in printed:
244+
printtab("%s %s" % (tunable, ring[tunable]))
245+
246+
ethtool_ringparam_map = {
247+
"rx": "rx_pending",
248+
"rx-mini": "rx_mini_pending",
249+
"rx-jumbo": "rx_jumbo_pending",
250+
"tx": "tx_pending",
251+
}
252+
253+
def set_ringparam(interface, args):
254+
try:
255+
ring = ethtool.get_ringparam(interface)
256+
except IOError:
257+
printtab("ring parameters NOT supported on %s!" % interface)
258+
return
259+
260+
changed = False
261+
args = [a.lower() for a in args]
262+
for arg, value in [ ( args[i], args[i + 1] ) for i in range(0, len(args), 2) ]:
263+
if not ethtool_ringparam_map.has_key(arg):
264+
continue
265+
try:
266+
value = int(value)
267+
except:
268+
continue
269+
real_arg = ethtool_ringparam_map[arg]
270+
if ring[real_arg] != value:
271+
ring[real_arg] = value
272+
changed = True
273+
274+
if not changed:
275+
return
276+
277+
ethtool.set_ringparam(interface, ring)
278+
210279
def show_driver(interface, args = None):
211280
try:
212281
driver = ethtool.get_module(interface)
@@ -249,10 +318,12 @@ def main():
249318

250319
try:
251320
opts, args = getopt.getopt(sys.argv[1:],
252-
"hcCikK",
321+
"hcCgGikK",
253322
("help",
254323
"show-coalesce",
255324
"coalesce",
325+
"show-ring",
326+
"set-ring",
256327
"driver",
257328
"show-offload",
258329
"offload"))
@@ -278,8 +349,12 @@ def main():
278349
elif o in ("-k", "--show-offload"):
279350
run_cmd_noargs(show_offload, args)
280351
break
352+
elif o in ("-g", "--show-ring"):
353+
run_cmd_noargs(show_ring, args)
354+
break
281355
elif o in ("-K", "--offload",
282-
"-C", "--coalesce"):
356+
"-C", "--coalesce",
357+
"-G", "--set-ring"):
283358
all_devices = ethtool.get_devices()
284359
if len(args) < 2:
285360
usage()
@@ -295,6 +370,8 @@ def main():
295370
cmd = set_offload
296371
elif o in ("-C", "--coalesce"):
297372
cmd = set_coalesce
373+
elif o in ("-G", "--set-ring"):
374+
cmd = set_ringparam
298375

299376
run_cmd(cmd, interface, args)
300377
break

python-ethtool/ethtool.c

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -667,6 +667,46 @@ static PyObject *set_coalesce(PyObject *self __unused, PyObject *args)
667667
return Py_None;
668668
}
669669

670+
struct struct_desc ethtool_ringparam_desc[] = {
671+
member_desc(struct ethtool_ringparam, rx_max_pending),
672+
member_desc(struct ethtool_ringparam, rx_mini_max_pending),
673+
member_desc(struct ethtool_ringparam, rx_jumbo_max_pending),
674+
member_desc(struct ethtool_ringparam, tx_max_pending),
675+
member_desc(struct ethtool_ringparam, rx_pending),
676+
member_desc(struct ethtool_ringparam, rx_mini_pending),
677+
member_desc(struct ethtool_ringparam, rx_jumbo_pending),
678+
member_desc(struct ethtool_ringparam, tx_pending),
679+
};
680+
681+
static PyObject *get_ringparam(PyObject *self __unused, PyObject *args)
682+
{
683+
struct ethtool_ringparam ring;
684+
685+
if (get_dev_value(ETHTOOL_GRINGPARAM, args, &ring) < 0)
686+
return NULL;
687+
688+
return struct_desc_create_dict(ethtool_ringparam_desc, &ring);
689+
}
690+
691+
static PyObject *set_ringparam(PyObject *self __unused, PyObject *args)
692+
{
693+
struct ethtool_ringparam ring;
694+
char *devname;
695+
PyObject *dict;
696+
697+
if (!PyArg_ParseTuple(args, "sO", &devname, &dict))
698+
return NULL;
699+
700+
if (struct_desc_from_dict(ethtool_ringparam_desc, &ring, dict) != 0)
701+
return NULL;
702+
703+
if (send_command(ETHTOOL_SRINGPARAM, devname, &ring))
704+
return NULL;
705+
706+
Py_INCREF(Py_None);
707+
return Py_None;
708+
}
709+
670710
static struct PyMethodDef PyEthModuleMethods[] = {
671711
{
672712
.ml_name = "get_module",
@@ -718,6 +758,16 @@ static struct PyMethodDef PyEthModuleMethods[] = {
718758
.ml_meth = (PyCFunction)get_active_devices,
719759
.ml_flags = METH_VARARGS,
720760
},
761+
{
762+
.ml_name = "get_ringparam",
763+
.ml_meth = (PyCFunction)get_ringparam,
764+
.ml_flags = METH_VARARGS,
765+
},
766+
{
767+
.ml_name = "set_ringparam",
768+
.ml_meth = (PyCFunction)set_ringparam,
769+
.ml_flags = METH_VARARGS,
770+
},
721771
{
722772
.ml_name = "get_tso",
723773
.ml_meth = (PyCFunction)get_tso,

0 commit comments

Comments
 (0)