Skip to content

Commit dd1c416

Browse files
vladimirolteandavem330
authored andcommitted
net: ethtool: add helpers for MM fragment size translation
We deliberately make the Linux UAPI pass the minimum fragment size in octets, even though IEEE 802.3 defines it as discrete values, and addFragSize is just the multiplier. This is because there is nothing impossible in operating with an in-between value for the fragment size of non-final preempted fragments, and there may even appear hardware which supports the in-between sizes. For the hardware which just understands the addFragSize multiplier, create two helpers which translate back and forth the values passed in octets. Signed-off-by: Vladimir Oltean <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 449c545 commit dd1c416

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

include/linux/ethtool.h

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
#include <linux/bitmap.h>
1717
#include <linux/compat.h>
18+
#include <linux/if_ether.h>
1819
#include <linux/netlink.h>
1920
#include <uapi/linux/ethtool.h>
2021

@@ -1001,6 +1002,47 @@ void ethtool_aggregate_pause_stats(struct net_device *dev,
10011002
void ethtool_aggregate_rmon_stats(struct net_device *dev,
10021003
struct ethtool_rmon_stats *rmon_stats);
10031004

1005+
/**
1006+
* ethtool_mm_frag_size_add_to_min - Translate (standard) additional fragment
1007+
* size expressed as multiplier into (absolute) minimum fragment size
1008+
* value expressed in octets
1009+
* @val_add: Value of addFragSize multiplier
1010+
*/
1011+
static inline u32 ethtool_mm_frag_size_add_to_min(u32 val_add)
1012+
{
1013+
return (ETH_ZLEN + ETH_FCS_LEN) * (1 + val_add) - ETH_FCS_LEN;
1014+
}
1015+
1016+
/**
1017+
* ethtool_mm_frag_size_min_to_add - Translate (absolute) minimum fragment size
1018+
* expressed in octets into (standard) additional fragment size expressed
1019+
* as multiplier
1020+
* @val_min: Value of addFragSize variable in octets
1021+
* @val_add: Pointer where the standard addFragSize value is to be returned
1022+
* @extack: Netlink extended ack
1023+
*
1024+
* Translate a value in octets to one of 0, 1, 2, 3 according to the reverse
1025+
* application of the 802.3 formula 64 * (1 + addFragSize) - 4. To be called
1026+
* by drivers which do not support programming the minimum fragment size to a
1027+
* continuous range. Returns error on other fragment length values.
1028+
*/
1029+
static inline int ethtool_mm_frag_size_min_to_add(u32 val_min, u32 *val_add,
1030+
struct netlink_ext_ack *extack)
1031+
{
1032+
u32 add_frag_size;
1033+
1034+
for (add_frag_size = 0; add_frag_size < 4; add_frag_size++) {
1035+
if (ethtool_mm_frag_size_add_to_min(add_frag_size) == val_min) {
1036+
*val_add = add_frag_size;
1037+
return 0;
1038+
}
1039+
}
1040+
1041+
NL_SET_ERR_MSG_MOD(extack,
1042+
"minFragSize required to be one of 60, 124, 188 or 252");
1043+
return -EINVAL;
1044+
}
1045+
10041046
/**
10051047
* ethtool_sprintf - Write formatted string to ethtool string data
10061048
* @data: Pointer to start of string to update

0 commit comments

Comments
 (0)