Something went wrong. Try again.
(I'm so sorry!) Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585// SPDX-License-Identifier: GPL-2.0-only
#include <linux/ethtool_netlink.h>#include <linux/net_tstamp.h>#include <linux/once.h>#include <linux/random.h>#include <linux/unaligned.h>#include <linux/phy.h>#include <linux/rtnetlink.h>#include <linux/ptp_clock_kernel.h>#include <linux/phy_link_topology.h>#include <net/netdev_queues.h>
#include "common.h"#include "netlink.h"#include "../core/dev.h"
const char netdev_features_strings[NETDEV_FEATURE_COUNT][ETH_GSTRING_LEN] = { [NETIF_F_SG_BIT] = "tx-scatter-gather", [NETIF_F_IP_CSUM_BIT] = "tx-checksum-ipv4", [NETIF_F_HW_CSUM_BIT] = "tx-checksum-ip-generic", [NETIF_F_IPV6_CSUM_BIT] = "tx-checksum-ipv6", [NETIF_F_HIGHDMA_BIT] = "highdma", [NETIF_F_FRAGLIST_BIT] = "tx-scatter-gather-fraglist", [NETIF_F_HW_VLAN_CTAG_TX_BIT] = "tx-vlan-hw-insert",
[NETIF_F_HW_VLAN_CTAG_RX_BIT] = "rx-vlan-hw-parse", [NETIF_F_HW_VLAN_CTAG_FILTER_BIT] = "rx-vlan-filter", [NETIF_F_HW_VLAN_STAG_TX_BIT] = "tx-vlan-stag-hw-insert", [NETIF_F_HW_VLAN_STAG_RX_BIT] = "rx-vlan-stag-hw-parse", [NETIF_F_HW_VLAN_STAG_FILTER_BIT] = "rx-vlan-stag-filter", [NETIF_F_VLAN_CHALLENGED_BIT] = "vlan-challenged", [NETIF_F_GSO_BIT] = "tx-generic-segmentation", [NETIF_F_GRO_BIT] = "rx-gro", [NETIF_F_GRO_HW_BIT] = "rx-gro-hw", [NETIF_F_LRO_BIT] = "rx-lro",
[NETIF_F_TSO_BIT] = "tx-tcp-segmentation", [NETIF_F_GSO_ROBUST_BIT] = "tx-gso-robust", [NETIF_F_TSO_ECN_BIT] = "tx-tcp-ecn-segmentation", [NETIF_F_GSO_ACCECN_BIT] = "tx-tcp-accecn-segmentation", [NETIF_F_TSO_MANGLEID_BIT] = "tx-tcp-mangleid-segmentation", [NETIF_F_TSO6_BIT] = "tx-tcp6-segmentation", [NETIF_F_FSO_BIT] = "tx-fcoe-segmentation", [NETIF_F_GSO_GRE_BIT] = "tx-gre-segmentation", [NETIF_F_GSO_GRE_CSUM_BIT] = "tx-gre-csum-segmentation", [NETIF_F_GSO_IPXIP4_BIT] = "tx-ipxip4-segmentation", [NETIF_F_GSO_IPXIP6_BIT] = "tx-ipxip6-segmentation", [NETIF_F_GSO_UDP_TUNNEL_BIT] = "tx-udp_tnl-segmentation", [NETIF_F_GSO_UDP_TUNNEL_CSUM_BIT] = "tx-udp_tnl-csum-segmentation", [NETIF_F_GSO_PARTIAL_BIT] = "tx-gso-partial", [NETIF_F_GSO_TUNNEL_REMCSUM_BIT] = "tx-tunnel-remcsum-segmentation", [NETIF_F_GSO_SCTP_BIT] = "tx-sctp-segmentation", [NETIF_F_GSO_ESP_BIT] = "tx-esp-segmentation", [NETIF_F_GSO_UDP_L4_BIT] = "tx-udp-segmentation", [NETIF_F_GSO_FRAGLIST_BIT] = "tx-gso-list",
[NETIF_F_FCOE_CRC_BIT] = "tx-checksum-fcoe-crc", [NETIF_F_SCTP_CRC_BIT] = "tx-checksum-sctp", [NETIF_F_NTUPLE_BIT] = "rx-ntuple-filter", [NETIF_F_RXHASH_BIT] = "rx-hashing", [NETIF_F_RXCSUM_BIT] = "rx-checksum", [NETIF_F_NOCACHE_COPY_BIT] = "tx-nocache-copy", [NETIF_F_LOOPBACK_BIT] = "loopback", [NETIF_F_RXFCS_BIT] = "rx-fcs", [NETIF_F_RXALL_BIT] = "rx-all", [NETIF_F_HW_L2FW_DOFFLOAD_BIT] = "l2-fwd-offload", [NETIF_F_HW_TC_BIT] = "hw-tc-offload", [NETIF_F_HW_ESP_BIT] = "esp-hw-offload", [NETIF_F_HW_ESP_TX_CSUM_BIT] = "esp-tx-csum-hw-offload", [NETIF_F_RX_UDP_TUNNEL_PORT_BIT] = "rx-udp_tunnel-port-offload", [NETIF_F_HW_TLS_TX_BIT] = "tls-hw-tx-offload", [NETIF_F_HW_TLS_RX_BIT] = "tls-hw-rx-offload", [NETIF_F_GRO_FRAGLIST_BIT] = "rx-gro-list", [NETIF_F_HW_MACSEC_BIT] = "macsec-hw-offload", [NETIF_F_GRO_UDP_FWD_BIT] = "rx-udp-gro-forwarding", [NETIF_F_HW_HSR_TAG_INS_BIT] = "hsr-tag-ins-offload", [NETIF_F_HW_HSR_TAG_RM_BIT] = "hsr-tag-rm-offload", [NETIF_F_HW_HSR_FWD_BIT] = "hsr-fwd-offload", [NETIF_F_HW_HSR_DUP_BIT] = "hsr-dup-offload",};
const charrss_hash_func_strings[ETH_RSS_HASH_FUNCS_COUNT][ETH_GSTRING_LEN] = { [ETH_RSS_HASH_TOP_BIT] = "toeplitz", [ETH_RSS_HASH_XOR_BIT] = "xor", [ETH_RSS_HASH_CRC32_BIT] = "crc32",};
const chartunable_strings[__ETHTOOL_TUNABLE_COUNT][ETH_GSTRING_LEN] = { [ETHTOOL_ID_UNSPEC] = "Unspec", [ETHTOOL_RX_COPYBREAK] = "rx-copybreak", [ETHTOOL_TX_COPYBREAK] = "tx-copybreak", [ETHTOOL_PFC_PREVENTION_TOUT] = "pfc-prevention-tout", [ETHTOOL_TX_COPYBREAK_BUF_SIZE] = "tx-copybreak-buf-size",};
const charphy_tunable_strings[__ETHTOOL_PHY_TUNABLE_COUNT][ETH_GSTRING_LEN] = { [ETHTOOL_ID_UNSPEC] = "Unspec", [ETHTOOL_PHY_DOWNSHIFT] = "phy-downshift", [ETHTOOL_PHY_FAST_LINK_DOWN] = "phy-fast-link-down", [ETHTOOL_PHY_EDPD] = "phy-energy-detect-power-down", [ETHTOOL_PHY_SHORT_CABLE_PRESET] = "phy-short-cable-preset", [ETHTOOL_PHY_LPF_BW] = "phy-lpf-bandwidth", [ETHTOOL_PHY_DSP_EQ_INIT_VALUE] = "phy-dsp-eq-init-value",};
#define __LINK_MODE_NAME(speed, type, duplex) \ #speed "base" #type "/" #duplex#define __DEFINE_LINK_MODE_NAME(speed, type, duplex) \ [ETHTOOL_LINK_MODE(speed, type, duplex)] = \ __LINK_MODE_NAME(speed, type, duplex)#define __DEFINE_SPECIAL_MODE_NAME(_mode, _name) \ [ETHTOOL_LINK_MODE_ ## _mode ## _BIT] = _name
const char link_mode_names[][ETH_GSTRING_LEN] = { __DEFINE_LINK_MODE_NAME(10, T, Half), __DEFINE_LINK_MODE_NAME(10, T, Full), __DEFINE_LINK_MODE_NAME(100, T, Half), __DEFINE_LINK_MODE_NAME(100, T, Full), __DEFINE_LINK_MODE_NAME(1000, T, Half), __DEFINE_LINK_MODE_NAME(1000, T, Full), __DEFINE_SPECIAL_MODE_NAME(Autoneg, "Autoneg"), __DEFINE_SPECIAL_MODE_NAME(TP, "TP"), __DEFINE_SPECIAL_MODE_NAME(AUI, "AUI"), __DEFINE_SPECIAL_MODE_NAME(MII, "MII"), __DEFINE_SPECIAL_MODE_NAME(FIBRE, "FIBRE"), __DEFINE_SPECIAL_MODE_NAME(BNC, "BNC"), __DEFINE_LINK_MODE_NAME(10000, T, Full), __DEFINE_SPECIAL_MODE_NAME(Pause, "Pause"), __DEFINE_SPECIAL_MODE_NAME(Asym_Pause, "Asym_Pause"), __DEFINE_LINK_MODE_NAME(2500, X, Full), __DEFINE_SPECIAL_MODE_NAME(Backplane, "Backplane"), __DEFINE_LINK_MODE_NAME(1000, KX, Full), __DEFINE_LINK_MODE_NAME(10000, KX4, Full), __DEFINE_LINK_MODE_NAME(10000, KR, Full), __DEFINE_SPECIAL_MODE_NAME(10000baseR_FEC, "10000baseR_FEC"), __DEFINE_LINK_MODE_NAME(20000, MLD2, Full), __DEFINE_LINK_MODE_NAME(20000, KR2, Full), __DEFINE_LINK_MODE_NAME(40000, KR4, Full), __DEFINE_LINK_MODE_NAME(40000, CR4, Full), __DEFINE_LINK_MODE_NAME(40000, SR4, Full), __DEFINE_LINK_MODE_NAME(40000, LR4, Full), __DEFINE_LINK_MODE_NAME(56000, KR4, Full), __DEFINE_LINK_MODE_NAME(56000, CR4, Full), __DEFINE_LINK_MODE_NAME(56000, SR4, Full), __DEFINE_LINK_MODE_NAME(56000, LR4, Full), __DEFINE_LINK_MODE_NAME(25000, CR, Full), __DEFINE_LINK_MODE_NAME(25000, KR, Full), __DEFINE_LINK_MODE_NAME(25000, SR, Full), __DEFINE_LINK_MODE_NAME(50000, CR2, Full), __DEFINE_LINK_MODE_NAME(50000, KR2, Full), __DEFINE_LINK_MODE_NAME(100000, KR4, Full), __DEFINE_LINK_MODE_NAME(100000, SR4, Full), __DEFINE_LINK_MODE_NAME(100000, CR4, Full), __DEFINE_LINK_MODE_NAME(100000, LR4_ER4, Full), __DEFINE_LINK_MODE_NAME(50000, SR2, Full), __DEFINE_LINK_MODE_NAME(1000, X, Full), __DEFINE_LINK_MODE_NAME(10000, CR, Full), __DEFINE_LINK_MODE_NAME(10000, SR, Full), __DEFINE_LINK_MODE_NAME(10000, LR, Full), __DEFINE_LINK_MODE_NAME(10000, LRM, Full), __DEFINE_LINK_MODE_NAME(10000, ER, Full), __DEFINE_LINK_MODE_NAME(2500, T, Full), __DEFINE_LINK_MODE_NAME(5000, T, Full), __DEFINE_SPECIAL_MODE_NAME(FEC_NONE, "None"), __DEFINE_SPECIAL_MODE_NAME(FEC_RS, "RS"), __DEFINE_SPECIAL_MODE_NAME(FEC_BASER, "BASER"), __DEFINE_LINK_MODE_NAME(50000, KR, Full), __DEFINE_LINK_MODE_NAME(50000, SR, Full), __DEFINE_LINK_MODE_NAME(50000, CR, Full), __DEFINE_LINK_MODE_NAME(50000, LR_ER_FR, Full), __DEFINE_LINK_MODE_NAME(50000, DR, Full), __DEFINE_LINK_MODE_NAME(100000, KR2, Full), __DEFINE_LINK_MODE_NAME(100000, SR2, Full), __DEFINE_LINK_MODE_NAME(100000, CR2, Full), __DEFINE_LINK_MODE_NAME(100000, LR2_ER2_FR2, Full), __DEFINE_LINK_MODE_NAME(100000, DR2, Full), __DEFINE_LINK_MODE_NAME(200000, KR4, Full), __DEFINE_LINK_MODE_NAME(200000, SR4, Full), __DEFINE_LINK_MODE_NAME(200000, LR4_ER4_FR4, Full), __DEFINE_LINK_MODE_NAME(200000, DR4, Full), __DEFINE_LINK_MODE_NAME(200000, CR4, Full), __DEFINE_LINK_MODE_NAME(100, T1, Full), __DEFINE_LINK_MODE_NAME(1000, T1, Full), __DEFINE_LINK_MODE_NAME(400000, KR8, Full), __DEFINE_LINK_MODE_NAME(400000, SR8, Full), __DEFINE_LINK_MODE_NAME(400000, LR8_ER8_FR8, Full), __DEFINE_LINK_MODE_NAME(400000, DR8, Full), __DEFINE_LINK_MODE_NAME(400000, CR8, Full), __DEFINE_SPECIAL_MODE_NAME(FEC_LLRS, "LLRS"), __DEFINE_LINK_MODE_NAME(100000, KR, Full), __DEFINE_LINK_MODE_NAME(100000, SR, Full), __DEFINE_LINK_MODE_NAME(100000, LR_ER_FR, Full), __DEFINE_LINK_MODE_NAME(100000, DR, Full), __DEFINE_LINK_MODE_NAME(100000, CR, Full), __DEFINE_LINK_MODE_NAME(200000, KR2, Full), __DEFINE_LINK_MODE_NAME(200000, SR2, Full), __DEFINE_LINK_MODE_NAME(200000, LR2_ER2_FR2, Full), __DEFINE_LINK_MODE_NAME(200000, DR2, Full), __DEFINE_LINK_MODE_NAME(200000, CR2, Full), __DEFINE_LINK_MODE_NAME(400000, KR4, Full), __DEFINE_LINK_MODE_NAME(400000, SR4, Full), __DEFINE_LINK_MODE_NAME(400000, LR4_ER4_FR4, Full), __DEFINE_LINK_MODE_NAME(400000, DR4, Full), __DEFINE_LINK_MODE_NAME(400000, CR4, Full), __DEFINE_LINK_MODE_NAME(100, FX, Half), __DEFINE_LINK_MODE_NAME(100, FX, Full), __DEFINE_LINK_MODE_NAME(10, T1L, Full), __DEFINE_LINK_MODE_NAME(800000, CR8, Full), __DEFINE_LINK_MODE_NAME(800000, KR8, Full), __DEFINE_LINK_MODE_NAME(800000, DR8, Full), __DEFINE_LINK_MODE_NAME(800000, DR8_2, Full), __DEFINE_LINK_MODE_NAME(800000, SR8, Full), __DEFINE_LINK_MODE_NAME(800000, VR8, Full), __DEFINE_LINK_MODE_NAME(10, T1S, Full), __DEFINE_LINK_MODE_NAME(10, T1S, Half), __DEFINE_LINK_MODE_NAME(10, T1S_P2MP, Half), __DEFINE_LINK_MODE_NAME(10, T1BRR, Full), __DEFINE_LINK_MODE_NAME(200000, CR, Full), __DEFINE_LINK_MODE_NAME(200000, KR, Full), __DEFINE_LINK_MODE_NAME(200000, DR, Full), __DEFINE_LINK_MODE_NAME(200000, DR_2, Full), __DEFINE_LINK_MODE_NAME(200000, SR, Full), __DEFINE_LINK_MODE_NAME(200000, VR, Full), __DEFINE_LINK_MODE_NAME(400000, CR2, Full), __DEFINE_LINK_MODE_NAME(400000, KR2, Full), __DEFINE_LINK_MODE_NAME(400000, DR2, Full), __DEFINE_LINK_MODE_NAME(400000, DR2_2, Full), __DEFINE_LINK_MODE_NAME(400000, SR2, Full), __DEFINE_LINK_MODE_NAME(400000, VR2, Full), __DEFINE_LINK_MODE_NAME(800000, CR4, Full), __DEFINE_LINK_MODE_NAME(800000, KR4, Full), __DEFINE_LINK_MODE_NAME(800000, DR4, Full), __DEFINE_LINK_MODE_NAME(800000, DR4_2, Full), __DEFINE_LINK_MODE_NAME(800000, SR4, Full), __DEFINE_LINK_MODE_NAME(800000, VR4, Full), __DEFINE_LINK_MODE_NAME(1600000, CR8, Full), __DEFINE_LINK_MODE_NAME(1600000, KR8, Full), __DEFINE_LINK_MODE_NAME(1600000, DR8, Full), __DEFINE_LINK_MODE_NAME(1600000, DR8_2, Full),};static_assert(ARRAY_SIZE(link_mode_names) == __ETHTOOL_LINK_MODE_MASK_NBITS);
#define __LINK_MODE_LANES_CR 1#define __LINK_MODE_LANES_CR2 2#define __LINK_MODE_LANES_CR4 4#define __LINK_MODE_LANES_CR8 8#define __LINK_MODE_LANES_DR 1#define __LINK_MODE_LANES_DR_2 1#define __LINK_MODE_LANES_DR2 2#define __LINK_MODE_LANES_DR2_2 2#define __LINK_MODE_LANES_DR4 4#define __LINK_MODE_LANES_DR4_2 4#define __LINK_MODE_LANES_DR8 8#define __LINK_MODE_LANES_KR 1#define __LINK_MODE_LANES_KR2 2#define __LINK_MODE_LANES_KR4 4#define __LINK_MODE_LANES_KR8 8#define __LINK_MODE_LANES_SR 1#define __LINK_MODE_LANES_SR2 2#define __LINK_MODE_LANES_SR4 4#define __LINK_MODE_LANES_SR8 8#define __LINK_MODE_LANES_ER 1#define __LINK_MODE_LANES_KX 1#define __LINK_MODE_LANES_KX4 4#define __LINK_MODE_LANES_LR 1#define __LINK_MODE_LANES_LR4 4#define __LINK_MODE_LANES_LR4_ER4 4#define __LINK_MODE_LANES_LR_ER_FR 1#define __LINK_MODE_LANES_LR2_ER2_FR2 2#define __LINK_MODE_LANES_LR4_ER4_FR4 4#define __LINK_MODE_LANES_LR8_ER8_FR8 8#define __LINK_MODE_LANES_LRM 1#define __LINK_MODE_LANES_MLD2 2#define __LINK_MODE_LANES_T 1#define __LINK_MODE_LANES_T1 1#define __LINK_MODE_LANES_X 1#define __LINK_MODE_LANES_FX 1#define __LINK_MODE_LANES_T1L 1#define __LINK_MODE_LANES_T1S 1#define __LINK_MODE_LANES_T1S_P2MP 1#define __LINK_MODE_LANES_VR 1#define __LINK_MODE_LANES_VR2 2#define __LINK_MODE_LANES_VR4 4#define __LINK_MODE_LANES_VR8 8#define __LINK_MODE_LANES_DR8_2 8#define __LINK_MODE_LANES_T1BRR 1
#define __DEFINE_LINK_MODE_PARAMS_PAIRS(_speed, _type, _min_pairs, _pairs, _duplex, _medium) \ [ETHTOOL_LINK_MODE(_speed, _type, _duplex)] = { \ .speed = SPEED_ ## _speed, \ .lanes = __LINK_MODE_LANES_ ## _type, \ .min_pairs = _min_pairs, \ .pairs = _pairs, \ .duplex = __DUPLEX_ ## _duplex, \ .mediums = BIT(ETHTOOL_LINK_MEDIUM_BASE ## _medium) \ }
#define __DEFINE_LINK_MODE_PARAMS(_speed, _type, _duplex, _medium) \ [ETHTOOL_LINK_MODE(_speed, _type, _duplex)] = { \ .speed = SPEED_ ## _speed, \ .lanes = __LINK_MODE_LANES_ ## _type, \ .min_pairs = 0, \ .pairs = 0, \ .duplex = __DUPLEX_ ## _duplex, \ .mediums = BIT(ETHTOOL_LINK_MEDIUM_BASE ## _medium) \ }#define __DEFINE_LINK_MODE_PARAMS_MEDIUMS(_speed, _type, _duplex, _mediums) \ [ETHTOOL_LINK_MODE(_speed, _type, _duplex)] = { \ .speed = SPEED_ ## _speed, \ .lanes = __LINK_MODE_LANES_ ## _type, \ .min_pairs = 0, \ .pairs = 0, \ .duplex = __DUPLEX_ ## _duplex, \ .mediums = (_mediums) \ }#define __MED(_medium) (BIT(ETHTOOL_LINK_MEDIUM_BASE ## _medium))#define __DUPLEX_Half DUPLEX_HALF#define __DUPLEX_Full DUPLEX_FULL#define __DEFINE_SPECIAL_MODE_PARAMS(_mode) \ [ETHTOOL_LINK_MODE_ ## _mode ## _BIT] = { \ .speed = SPEED_UNKNOWN, \ .lanes = 0, \ .duplex = DUPLEX_UNKNOWN, \ .mediums = BIT(ETHTOOL_LINK_MEDIUM_NONE), \ }
const struct link_mode_info link_mode_params[] = { __DEFINE_LINK_MODE_PARAMS_PAIRS(10, T, 2, 4, Half, T), __DEFINE_LINK_MODE_PARAMS_PAIRS(10, T, 2, 4, Full, T), __DEFINE_LINK_MODE_PARAMS_PAIRS(100, T, 2, 4, Half, T), __DEFINE_LINK_MODE_PARAMS_PAIRS(100, T, 2, 4, Full, T), __DEFINE_LINK_MODE_PARAMS_PAIRS(1000, T, 4, 4, Half, T), __DEFINE_LINK_MODE_PARAMS_PAIRS(1000, T, 4, 4, Full, T), __DEFINE_SPECIAL_MODE_PARAMS(Autoneg), __DEFINE_SPECIAL_MODE_PARAMS(TP), __DEFINE_SPECIAL_MODE_PARAMS(AUI), __DEFINE_SPECIAL_MODE_PARAMS(MII), __DEFINE_SPECIAL_MODE_PARAMS(FIBRE), __DEFINE_SPECIAL_MODE_PARAMS(BNC), __DEFINE_LINK_MODE_PARAMS_PAIRS(10000, T, 4, 4, Full, T), __DEFINE_SPECIAL_MODE_PARAMS(Pause), __DEFINE_SPECIAL_MODE_PARAMS(Asym_Pause), __DEFINE_LINK_MODE_PARAMS_MEDIUMS(2500, X, Full, __MED(C) | __MED(S) | __MED(L)), __DEFINE_SPECIAL_MODE_PARAMS(Backplane), __DEFINE_LINK_MODE_PARAMS(1000, KX, Full, K), __DEFINE_LINK_MODE_PARAMS(10000, KX4, Full, K), __DEFINE_LINK_MODE_PARAMS(10000, KR, Full, K), [ETHTOOL_LINK_MODE_10000baseR_FEC_BIT] = { .speed = SPEED_10000, .lanes = 1, .duplex = DUPLEX_FULL, }, __DEFINE_LINK_MODE_PARAMS(20000, MLD2, Full, MLD), __DEFINE_LINK_MODE_PARAMS(20000, KR2, Full, K), __DEFINE_LINK_MODE_PARAMS(40000, KR4, Full, K), __DEFINE_LINK_MODE_PARAMS(40000, CR4, Full, C), __DEFINE_LINK_MODE_PARAMS(40000, SR4, Full, S), __DEFINE_LINK_MODE_PARAMS(40000, LR4, Full, L), __DEFINE_LINK_MODE_PARAMS(56000, KR4, Full, K), __DEFINE_LINK_MODE_PARAMS(56000, CR4, Full, C), __DEFINE_LINK_MODE_PARAMS(56000, SR4, Full, S), __DEFINE_LINK_MODE_PARAMS(56000, LR4, Full, L), __DEFINE_LINK_MODE_PARAMS(25000, CR, Full, C), __DEFINE_LINK_MODE_PARAMS(25000, KR, Full, K), __DEFINE_LINK_MODE_PARAMS(25000, SR, Full, S), __DEFINE_LINK_MODE_PARAMS(50000, CR2, Full, C), __DEFINE_LINK_MODE_PARAMS(50000, KR2, Full, K), __DEFINE_LINK_MODE_PARAMS(100000, KR4, Full, K), __DEFINE_LINK_MODE_PARAMS(100000, SR4, Full, S), __DEFINE_LINK_MODE_PARAMS(100000, CR4, Full, C), __DEFINE_LINK_MODE_PARAMS_MEDIUMS(100000, LR4_ER4, Full, __MED(L) | __MED(E)), __DEFINE_LINK_MODE_PARAMS(50000, SR2, Full, S), __DEFINE_LINK_MODE_PARAMS_MEDIUMS(1000, X, Full, __MED(C) | __MED(S) | __MED(L)), __DEFINE_LINK_MODE_PARAMS(10000, CR, Full, C), __DEFINE_LINK_MODE_PARAMS(10000, SR, Full, S), __DEFINE_LINK_MODE_PARAMS(10000, LR, Full, L), __DEFINE_LINK_MODE_PARAMS(10000, LRM, Full, L), __DEFINE_LINK_MODE_PARAMS(10000, ER, Full, E), __DEFINE_LINK_MODE_PARAMS_PAIRS(2500, T, 4, 4, Full, T), __DEFINE_LINK_MODE_PARAMS_PAIRS(5000, T, 4, 4, Full, T), __DEFINE_SPECIAL_MODE_PARAMS(FEC_NONE), __DEFINE_SPECIAL_MODE_PARAMS(FEC_RS), __DEFINE_SPECIAL_MODE_PARAMS(FEC_BASER), __DEFINE_LINK_MODE_PARAMS(50000, KR, Full, K), __DEFINE_LINK_MODE_PARAMS(50000, SR, Full, S), __DEFINE_LINK_MODE_PARAMS(50000, CR, Full, C), __DEFINE_LINK_MODE_PARAMS_MEDIUMS(50000, LR_ER_FR, Full, __MED(L) | __MED(E) | __MED(F)), __DEFINE_LINK_MODE_PARAMS(50000, DR, Full, D), __DEFINE_LINK_MODE_PARAMS(100000, KR2, Full, K), __DEFINE_LINK_MODE_PARAMS(100000, SR2, Full, S), __DEFINE_LINK_MODE_PARAMS(100000, CR2, Full, C), __DEFINE_LINK_MODE_PARAMS_MEDIUMS(100000, LR2_ER2_FR2, Full, __MED(L) | __MED(E) | __MED(F)), __DEFINE_LINK_MODE_PARAMS(100000, DR2, Full, D), __DEFINE_LINK_MODE_PARAMS(200000, KR4, Full, K), __DEFINE_LINK_MODE_PARAMS(200000, SR4, Full, S), __DEFINE_LINK_MODE_PARAMS_MEDIUMS(200000, LR4_ER4_FR4, Full, __MED(L) | __MED(E) | __MED(F)), __DEFINE_LINK_MODE_PARAMS(200000, DR4, Full, D), __DEFINE_LINK_MODE_PARAMS(200000, CR4, Full, C), __DEFINE_LINK_MODE_PARAMS_PAIRS(100, T1, 1, 1, Full, T), __DEFINE_LINK_MODE_PARAMS_PAIRS(1000, T1, 1, 1, Full, T), __DEFINE_LINK_MODE_PARAMS(400000, KR8, Full, K), __DEFINE_LINK_MODE_PARAMS(400000, SR8, Full, S), __DEFINE_LINK_MODE_PARAMS_MEDIUMS(400000, LR8_ER8_FR8, Full, __MED(L) | __MED(E) | __MED(F)), __DEFINE_LINK_MODE_PARAMS(400000, DR8, Full, D), __DEFINE_LINK_MODE_PARAMS(400000, CR8, Full, C), __DEFINE_SPECIAL_MODE_PARAMS(FEC_LLRS), __DEFINE_LINK_MODE_PARAMS(100000, KR, Full, K), __DEFINE_LINK_MODE_PARAMS(100000, SR, Full, S), __DEFINE_LINK_MODE_PARAMS_MEDIUMS(100000, LR_ER_FR, Full, __MED(L) | __MED(E) | __MED(F)), __DEFINE_LINK_MODE_PARAMS(100000, DR, Full, D), __DEFINE_LINK_MODE_PARAMS(100000, CR, Full, C), __DEFINE_LINK_MODE_PARAMS(200000, KR2, Full, K), __DEFINE_LINK_MODE_PARAMS(200000, SR2, Full, S), __DEFINE_LINK_MODE_PARAMS_MEDIUMS(200000, LR2_ER2_FR2, Full, __MED(L) | __MED(E) | __MED(F)), __DEFINE_LINK_MODE_PARAMS(200000, DR2, Full, D), __DEFINE_LINK_MODE_PARAMS(200000, CR2, Full, C), __DEFINE_LINK_MODE_PARAMS(400000, KR4, Full, K), __DEFINE_LINK_MODE_PARAMS(400000, SR4, Full, S), __DEFINE_LINK_MODE_PARAMS_MEDIUMS(400000, LR4_ER4_FR4, Full, __MED(L) | __MED(E) | __MED(F)), __DEFINE_LINK_MODE_PARAMS(400000, DR4, Full, D), __DEFINE_LINK_MODE_PARAMS(400000, CR4, Full, C), __DEFINE_LINK_MODE_PARAMS(100, FX, Half, F), __DEFINE_LINK_MODE_PARAMS(100, FX, Full, F), __DEFINE_LINK_MODE_PARAMS_PAIRS(10, T1L, 1, 1, Full, T), __DEFINE_LINK_MODE_PARAMS(800000, CR8, Full, C), __DEFINE_LINK_MODE_PARAMS(800000, KR8, Full, K), __DEFINE_LINK_MODE_PARAMS(800000, DR8, Full, D), __DEFINE_LINK_MODE_PARAMS(800000, DR8_2, Full, D), __DEFINE_LINK_MODE_PARAMS(800000, SR8, Full, S), __DEFINE_LINK_MODE_PARAMS(800000, VR8, Full, V), __DEFINE_LINK_MODE_PARAMS_PAIRS(10, T1S, 1, 1, Full, T), __DEFINE_LINK_MODE_PARAMS_PAIRS(10, T1S, 1, 1, Half, T), __DEFINE_LINK_MODE_PARAMS_PAIRS(10, T1S_P2MP, 1, 1, Half, T), __DEFINE_LINK_MODE_PARAMS_PAIRS(10, T1BRR, 1, 1, Full, T), __DEFINE_LINK_MODE_PARAMS(200000, CR, Full, C), __DEFINE_LINK_MODE_PARAMS(200000, KR, Full, K), __DEFINE_LINK_MODE_PARAMS(200000, DR, Full, D), __DEFINE_LINK_MODE_PARAMS(200000, DR_2, Full, D), __DEFINE_LINK_MODE_PARAMS(200000, SR, Full, S), __DEFINE_LINK_MODE_PARAMS(200000, VR, Full, V), __DEFINE_LINK_MODE_PARAMS(400000, CR2, Full, C), __DEFINE_LINK_MODE_PARAMS(400000, KR2, Full, K), __DEFINE_LINK_MODE_PARAMS(400000, DR2, Full, D), __DEFINE_LINK_MODE_PARAMS(400000, DR2_2, Full, D), __DEFINE_LINK_MODE_PARAMS(400000, SR2, Full, S), __DEFINE_LINK_MODE_PARAMS(400000, VR2, Full, V), __DEFINE_LINK_MODE_PARAMS(800000, CR4, Full, C), __DEFINE_LINK_MODE_PARAMS(800000, KR4, Full, K), __DEFINE_LINK_MODE_PARAMS(800000, DR4, Full, D), __DEFINE_LINK_MODE_PARAMS(800000, DR4_2, Full, D), __DEFINE_LINK_MODE_PARAMS(800000, SR4, Full, S), __DEFINE_LINK_MODE_PARAMS(800000, VR4, Full, V), __DEFINE_LINK_MODE_PARAMS(1600000, CR8, Full, C), __DEFINE_LINK_MODE_PARAMS(1600000, KR8, Full, K), __DEFINE_LINK_MODE_PARAMS(1600000, DR8, Full, D), __DEFINE_LINK_MODE_PARAMS(1600000, DR8_2, Full, D),};static_assert(ARRAY_SIZE(link_mode_params) == __ETHTOOL_LINK_MODE_MASK_NBITS);EXPORT_SYMBOL_GPL(link_mode_params);
static const char ethtool_link_medium_names[][ETH_GSTRING_LEN] = { [ETHTOOL_LINK_MEDIUM_BASET] = "BaseT", [ETHTOOL_LINK_MEDIUM_BASEK] = "BaseK", [ETHTOOL_LINK_MEDIUM_BASES] = "BaseS", [ETHTOOL_LINK_MEDIUM_BASEC] = "BaseC", [ETHTOOL_LINK_MEDIUM_BASEL] = "BaseL", [ETHTOOL_LINK_MEDIUM_BASED] = "BaseD", [ETHTOOL_LINK_MEDIUM_BASEE] = "BaseE", [ETHTOOL_LINK_MEDIUM_BASEF] = "BaseF", [ETHTOOL_LINK_MEDIUM_BASEV] = "BaseV", [ETHTOOL_LINK_MEDIUM_BASEMLD] = "BaseMLD", [ETHTOOL_LINK_MEDIUM_NONE] = "None",};static_assert(ARRAY_SIZE(ethtool_link_medium_names) == __ETHTOOL_LINK_MEDIUM_LAST);
const char netif_msg_class_names[][ETH_GSTRING_LEN] = { [NETIF_MSG_DRV_BIT] = "drv", [NETIF_MSG_PROBE_BIT] = "probe", [NETIF_MSG_LINK_BIT] = "link", [NETIF_MSG_TIMER_BIT] = "timer", [NETIF_MSG_IFDOWN_BIT] = "ifdown", [NETIF_MSG_IFUP_BIT] = "ifup", [NETIF_MSG_RX_ERR_BIT] = "rx_err", [NETIF_MSG_TX_ERR_BIT] = "tx_err", [NETIF_MSG_TX_QUEUED_BIT] = "tx_queued", [NETIF_MSG_INTR_BIT] = "intr", [NETIF_MSG_TX_DONE_BIT] = "tx_done", [NETIF_MSG_RX_STATUS_BIT] = "rx_status", [NETIF_MSG_PKTDATA_BIT] = "pktdata", [NETIF_MSG_HW_BIT] = "hw", [NETIF_MSG_WOL_BIT] = "wol",};static_assert(ARRAY_SIZE(netif_msg_class_names) == NETIF_MSG_CLASS_COUNT);
const char wol_mode_names[][ETH_GSTRING_LEN] = { [const_ilog2(WAKE_PHY)] = "phy", [const_ilog2(WAKE_UCAST)] = "ucast", [const_ilog2(WAKE_MCAST)] = "mcast", [const_ilog2(WAKE_BCAST)] = "bcast", [const_ilog2(WAKE_ARP)] = "arp", [const_ilog2(WAKE_MAGIC)] = "magic", [const_ilog2(WAKE_MAGICSECURE)] = "magicsecure", [const_ilog2(WAKE_FILTER)] = "filter",};static_assert(ARRAY_SIZE(wol_mode_names) == WOL_MODE_COUNT);
const char sof_timestamping_names[][ETH_GSTRING_LEN] = { [const_ilog2(SOF_TIMESTAMPING_TX_HARDWARE)] = "hardware-transmit", [const_ilog2(SOF_TIMESTAMPING_TX_SOFTWARE)] = "software-transmit", [const_ilog2(SOF_TIMESTAMPING_RX_HARDWARE)] = "hardware-receive", [const_ilog2(SOF_TIMESTAMPING_RX_SOFTWARE)] = "software-receive", [const_ilog2(SOF_TIMESTAMPING_SOFTWARE)] = "software-system-clock", [const_ilog2(SOF_TIMESTAMPING_SYS_HARDWARE)] = "hardware-legacy-clock", [const_ilog2(SOF_TIMESTAMPING_RAW_HARDWARE)] = "hardware-raw-clock", [const_ilog2(SOF_TIMESTAMPING_OPT_ID)] = "option-id", [const_ilog2(SOF_TIMESTAMPING_TX_SCHED)] = "sched-transmit", [const_ilog2(SOF_TIMESTAMPING_TX_ACK)] = "ack-transmit", [const_ilog2(SOF_TIMESTAMPING_OPT_CMSG)] = "option-cmsg", [const_ilog2(SOF_TIMESTAMPING_OPT_TSONLY)] = "option-tsonly", [const_ilog2(SOF_TIMESTAMPING_OPT_STATS)] = "option-stats", [const_ilog2(SOF_TIMESTAMPING_OPT_PKTINFO)] = "option-pktinfo", [const_ilog2(SOF_TIMESTAMPING_OPT_TX_SWHW)] = "option-tx-swhw", [const_ilog2(SOF_TIMESTAMPING_BIND_PHC)] = "bind-phc", [const_ilog2(SOF_TIMESTAMPING_OPT_ID_TCP)] = "option-id-tcp", [const_ilog2(SOF_TIMESTAMPING_OPT_RX_FILTER)] = "option-rx-filter", [const_ilog2(SOF_TIMESTAMPING_TX_COMPLETION)] = "tx-completion",};static_assert(ARRAY_SIZE(sof_timestamping_names) == __SOF_TIMESTAMPING_CNT);
const char ts_tx_type_names[][ETH_GSTRING_LEN] = { [HWTSTAMP_TX_OFF] = "off", [HWTSTAMP_TX_ON] = "on", [HWTSTAMP_TX_ONESTEP_SYNC] = "onestep-sync", [HWTSTAMP_TX_ONESTEP_P2P] = "onestep-p2p",};static_assert(ARRAY_SIZE(ts_tx_type_names) == __HWTSTAMP_TX_CNT);
const char ts_rx_filter_names[][ETH_GSTRING_LEN] = { [HWTSTAMP_FILTER_NONE] = "none", [HWTSTAMP_FILTER_ALL] = "all", [HWTSTAMP_FILTER_SOME] = "some", [HWTSTAMP_FILTER_PTP_V1_L4_EVENT] = "ptpv1-l4-event", [HWTSTAMP_FILTER_PTP_V1_L4_SYNC] = "ptpv1-l4-sync", [HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ] = "ptpv1-l4-delay-req", [HWTSTAMP_FILTER_PTP_V2_L4_EVENT] = "ptpv2-l4-event", [HWTSTAMP_FILTER_PTP_V2_L4_SYNC] = "ptpv2-l4-sync", [HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ] = "ptpv2-l4-delay-req", [HWTSTAMP_FILTER_PTP_V2_L2_EVENT] = "ptpv2-l2-event", [HWTSTAMP_FILTER_PTP_V2_L2_SYNC] = "ptpv2-l2-sync", [HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ] = "ptpv2-l2-delay-req", [HWTSTAMP_FILTER_PTP_V2_EVENT] = "ptpv2-event", [HWTSTAMP_FILTER_PTP_V2_SYNC] = "ptpv2-sync", [HWTSTAMP_FILTER_PTP_V2_DELAY_REQ] = "ptpv2-delay-req", [HWTSTAMP_FILTER_NTP_ALL] = "ntp-all",};static_assert(ARRAY_SIZE(ts_rx_filter_names) == __HWTSTAMP_FILTER_CNT);
const char ts_flags_names[][ETH_GSTRING_LEN] = { [const_ilog2(HWTSTAMP_FLAG_BONDED_PHC_INDEX)] = "bonded-phc-index",};static_assert(ARRAY_SIZE(ts_flags_names) == __HWTSTAMP_FLAG_CNT);
const char udp_tunnel_type_names[][ETH_GSTRING_LEN] = { [ETHTOOL_UDP_TUNNEL_TYPE_VXLAN] = "vxlan", [ETHTOOL_UDP_TUNNEL_TYPE_GENEVE] = "geneve", [ETHTOOL_UDP_TUNNEL_TYPE_VXLAN_GPE] = "vxlan-gpe",};static_assert(ARRAY_SIZE(udp_tunnel_type_names) == __ETHTOOL_UDP_TUNNEL_TYPE_CNT);
/* return false if legacy contained non-0 deprecated fields * maxtxpkt/maxrxpkt. rest of ksettings always updated */boolconvert_legacy_settings_to_link_ksettings( struct ethtool_link_ksettings *link_ksettings, const struct ethtool_cmd *legacy_settings){ bool retval = true;
memset(link_ksettings, 0, sizeof(*link_ksettings));
/* This is used to tell users that driver is still using these * deprecated legacy fields, and they should not use * %ETHTOOL_GLINKSETTINGS/%ETHTOOL_SLINKSETTINGS */ if (legacy_settings->maxtxpkt || legacy_settings->maxrxpkt) retval = false;
ethtool_convert_legacy_u32_to_link_mode( link_ksettings->link_modes.supported, legacy_settings->supported); ethtool_convert_legacy_u32_to_link_mode( link_ksettings->link_modes.advertising, legacy_settings->advertising); ethtool_convert_legacy_u32_to_link_mode( link_ksettings->link_modes.lp_advertising, legacy_settings->lp_advertising); link_ksettings->base.speed = ethtool_cmd_speed(legacy_settings); link_ksettings->base.duplex = legacy_settings->duplex; link_ksettings->base.port = legacy_settings->port; link_ksettings->base.phy_address = legacy_settings->phy_address; link_ksettings->base.autoneg = legacy_settings->autoneg; link_ksettings->base.mdio_support = legacy_settings->mdio_support; link_ksettings->base.eth_tp_mdix = legacy_settings->eth_tp_mdix; link_ksettings->base.eth_tp_mdix_ctrl = legacy_settings->eth_tp_mdix_ctrl; return retval;}
int __ethtool_get_link(struct net_device *dev){ if (!dev->ethtool_ops->get_link) return -EOPNOTSUPP;
return netif_running(dev) && dev->ethtool_ops->get_link(dev);}
int ethtool_get_rx_ring_count(struct net_device *dev){ const struct ethtool_ops *ops = dev->ethtool_ops;
if (!ops->get_rx_ring_count) return -EOPNOTSUPP;
return ops->get_rx_ring_count(dev);}
static int ethtool_get_rxnfc_rule_count(struct net_device *dev){ const struct ethtool_ops *ops = dev->ethtool_ops; struct ethtool_rxnfc info = { .cmd = ETHTOOL_GRXCLSRLCNT, }; int err;
err = ops->get_rxnfc(dev, &info, NULL); if (err) return err;
return info.rule_cnt;}
/* Max offset for one RSS context */static u32 ethtool_get_rss_ctx_max_channel(struct ethtool_rxfh_context *ctx){ u32 max_ring = 0; u32 i, *tbl;
if (WARN_ON_ONCE(!ctx)) return 0; tbl = ethtool_rxfh_context_indir(ctx); for (i = 0; i < ctx->indir_size; i++) max_ring = max(max_ring, tbl[i]); return max_ring;}
static int ethtool_get_max_rxnfc_channel(struct net_device *dev, u64 *max){ const struct ethtool_ops *ops = dev->ethtool_ops; struct ethtool_rxnfc *info; int err, i, rule_cnt; u64 max_ring = 0;
if (!ops->get_rxnfc) return -EOPNOTSUPP;
rule_cnt = ethtool_get_rxnfc_rule_count(dev); if (rule_cnt <= 0) return -EINVAL;
info = kvzalloc_flex(*info, rule_locs, rule_cnt); if (!info) return -ENOMEM;
info->cmd = ETHTOOL_GRXCLSRLALL; info->rule_cnt = rule_cnt; err = ops->get_rxnfc(dev, info, info->rule_locs); if (err) goto err_free_info;
for (i = 0; i < rule_cnt; i++) { struct ethtool_rxnfc rule_info = { .cmd = ETHTOOL_GRXCLSRULE, .fs.location = info->rule_locs[i], };
err = ops->get_rxnfc(dev, &rule_info, NULL); if (err) goto err_free_info;
if (rule_info.fs.ring_cookie != RX_CLS_FLOW_DISC && rule_info.fs.ring_cookie != RX_CLS_FLOW_WAKE && !ethtool_get_flow_spec_ring_vf(rule_info.fs.ring_cookie)) { u64 ring = rule_info.fs.ring_cookie;
if (rule_info.flow_type & FLOW_RSS) { struct ethtool_rxfh_context *ctx;
ctx = xa_load(&dev->ethtool->rss_ctx, rule_info.rss_context); ring += ethtool_get_rss_ctx_max_channel(ctx); } max_ring = max_t(u64, max_ring, ring); } }
kvfree(info); *max = max_ring; return 0;
err_free_info: kvfree(info); return err;}
/* Max offset across all of a device's RSS contexts */static u32 ethtool_get_max_rss_ctx_channel(struct net_device *dev){ struct ethtool_rxfh_context *ctx; unsigned long context; u32 max_ring = 0;
mutex_lock(&dev->ethtool->rss_lock); xa_for_each(&dev->ethtool->rss_ctx, context, ctx) max_ring = max(max_ring, ethtool_get_rss_ctx_max_channel(ctx)); mutex_unlock(&dev->ethtool->rss_lock);
return max_ring;}
static u32 ethtool_get_max_rxfh_channel(struct net_device *dev){ struct ethtool_rxfh_param rxfh = {}; u32 dev_size, current_max = 0; int ret;
/* While we do track whether RSS context has an indirection * table explicitly set by the user, no driver looks at that bit. * Assume drivers won't auto-regenerate the additional tables, * to be safe. */ current_max = ethtool_get_max_rss_ctx_channel(dev);
if (!netif_is_rxfh_configured(dev)) return current_max;
if (!dev->ethtool_ops->get_rxfh_indir_size || !dev->ethtool_ops->get_rxfh) return current_max; dev_size = dev->ethtool_ops->get_rxfh_indir_size(dev); if (dev_size == 0) return current_max;
rxfh.indir = kzalloc_objs(rxfh.indir[0], dev_size, GFP_USER); if (!rxfh.indir) return U32_MAX;
mutex_lock(&dev->ethtool->rss_lock); ret = dev->ethtool_ops->get_rxfh(dev, &rxfh); mutex_unlock(&dev->ethtool->rss_lock); if (ret) { current_max = U32_MAX; goto out_free; }
while (dev_size--) current_max = max(current_max, rxfh.indir[dev_size]);
out_free: kfree(rxfh.indir); return current_max;}
int ethtool_check_max_channel(struct net_device *dev, struct ethtool_channels channels, struct genl_info *info){ u64 max_rxnfc_in_use; u32 max_rxfh_in_use; int max_mp_in_use;
/* ensure the new Rx count fits within the configured Rx flow * indirection table/rxnfc settings */ if (ethtool_get_max_rxnfc_channel(dev, &max_rxnfc_in_use)) max_rxnfc_in_use = 0; max_rxfh_in_use = ethtool_get_max_rxfh_channel(dev); if (channels.combined_count + channels.rx_count <= max_rxfh_in_use) { if (info) GENL_SET_ERR_MSG_FMT(info, "requested channel counts are too low for existing indirection table (%d)", max_rxfh_in_use); return -EINVAL; } if (channels.combined_count + channels.rx_count <= max_rxnfc_in_use) { if (info) GENL_SET_ERR_MSG(info, "requested channel counts are too low for existing ntuple filter settings"); return -EINVAL; }
max_mp_in_use = dev_get_min_mp_channel_count(dev); if (channels.combined_count + channels.rx_count <= max_mp_in_use) { if (info) GENL_SET_ERR_MSG_FMT(info, "requested channel counts are too low for existing memory provider setting (%d)", max_mp_in_use); return -EINVAL; }
return 0;}
int ethtool_check_rss_ctx_busy(struct net_device *dev, u32 rss_context){ const struct ethtool_ops *ops = dev->ethtool_ops; struct ethtool_rxnfc *info; int rc, i, rule_cnt;
if (!ops->get_rxnfc) return 0;
rule_cnt = ethtool_get_rxnfc_rule_count(dev); if (!rule_cnt) return 0;
if (rule_cnt < 0) return -EINVAL;
info = kvzalloc_flex(*info, rule_locs, rule_cnt); if (!info) return -ENOMEM;
info->cmd = ETHTOOL_GRXCLSRLALL; info->rule_cnt = rule_cnt; rc = ops->get_rxnfc(dev, info, info->rule_locs); if (rc) goto out_free;
for (i = 0; i < rule_cnt; i++) { struct ethtool_rxnfc rule_info = { .cmd = ETHTOOL_GRXCLSRULE, .fs.location = info->rule_locs[i], };
rc = ops->get_rxnfc(dev, &rule_info, NULL); if (rc) goto out_free;
if (rule_info.fs.flow_type & FLOW_RSS && rule_info.rss_context == rss_context) { rc = -EBUSY; goto out_free; } }
out_free: kvfree(info); return rc;}
struct ethtool_rxfh_context *ethtool_rxfh_ctx_alloc(const struct ethtool_ops *ops, u32 indir_size, u32 key_size){ size_t indir_bytes, flex_len, key_off, size; struct ethtool_rxfh_context *ctx; u32 priv_bytes, indir_max; u16 key_max;
key_max = max(key_size, ops->rxfh_key_space); indir_max = max(indir_size, ops->rxfh_indir_space);
priv_bytes = ALIGN(ops->rxfh_priv_size, sizeof(u32)); indir_bytes = array_size(indir_max, sizeof(u32));
key_off = size_add(priv_bytes, indir_bytes); flex_len = size_add(key_off, key_max); size = struct_size_t(struct ethtool_rxfh_context, data, flex_len);
ctx = kzalloc(size, GFP_KERNEL_ACCOUNT); if (!ctx) return NULL;
ctx->indir_size = indir_size; ctx->key_size = key_size; ctx->key_off = key_off; ctx->priv_size = ops->rxfh_priv_size;
return ctx;}
/* Check if fields configured for flow hash are symmetric - if src is included * so is dst and vice versa. */int ethtool_rxfh_config_is_sym(u64 rxfh){ bool sym;
sym = rxfh == (rxfh & (RXH_IP_SRC | RXH_IP_DST | RXH_L4_B_0_1 | RXH_L4_B_2_3)); sym &= !!(rxfh & RXH_IP_SRC) == !!(rxfh & RXH_IP_DST); sym &= !!(rxfh & RXH_L4_B_0_1) == !!(rxfh & RXH_L4_B_2_3);
return sym;}
int ethtool_check_ops(const struct ethtool_ops *ops){ if (WARN_ON(ops->set_coalesce && !ops->supported_coalesce_params)) return -EINVAL; if (WARN_ON(ops->rxfh_max_num_contexts == 1)) return -EINVAL; if (WARN_ON(ops->supported_input_xfrm && !ops->get_rxfh_fields)) return -EINVAL; if (WARN_ON(ops->supported_input_xfrm && ops->rxfh_per_ctx_fields != ops->rxfh_per_ctx_key)) return -EINVAL;
/* NOTE: sufficiently insane drivers may swap ethtool_ops at runtime, * the fact that ops are checked at registration time does not * mean the ops attached to a netdev later on are sane. */ return 0;}
void ethtool_ringparam_get_cfg(struct net_device *dev, struct ethtool_ringparam *param, struct kernel_ethtool_ringparam *kparam, struct netlink_ext_ack *extack){ memset(param, 0, sizeof(*param)); memset(kparam, 0, sizeof(*kparam));
param->cmd = ETHTOOL_GRINGPARAM; dev->ethtool_ops->get_ringparam(dev, param, kparam, extack);
/* Driver gives us current state, we want to return current config */ kparam->tcp_data_split = dev->cfg->hds_config; kparam->hds_thresh = dev->cfg->hds_thresh;}
void ethtool_ringparam_set_cfg(struct netdev_config *cfg, const struct ethtool_ringparam *param){ cfg->rings.rx_pending = param->rx_pending; cfg->rings.rx_mini_pending = param->rx_mini_pending; cfg->rings.rx_jumbo_pending = param->rx_jumbo_pending;}
static void ethtool_init_tsinfo(struct kernel_ethtool_ts_info *info){ memset(info, 0, sizeof(*info)); info->cmd = ETHTOOL_GET_TS_INFO; info->phc_index = -1;}
int ethtool_net_get_ts_info_by_phc(struct net_device *dev, struct kernel_ethtool_ts_info *info, struct hwtstamp_provider_desc *hwprov_desc){ const struct ethtool_ops *ops = dev->ethtool_ops; int err;
if (!ops->get_ts_info) return -EOPNOTSUPP;
/* Does ptp comes from netdev */ ethtool_init_tsinfo(info); info->phc_qualifier = hwprov_desc->qualifier; err = ops->get_ts_info(dev, info); if (err) return err;
if (info->phc_index == hwprov_desc->index && net_support_hwtstamp_qualifier(dev, hwprov_desc->qualifier)) return 0;
return -ENODEV;}
struct phy_device *ethtool_phy_get_ts_info_by_phc(struct net_device *dev, struct kernel_ethtool_ts_info *info, struct hwtstamp_provider_desc *hwprov_desc){ int err;
/* Only precise qualifier is supported in phydev */ if (hwprov_desc->qualifier != HWTSTAMP_PROVIDER_QUALIFIER_PRECISE) return ERR_PTR(-ENODEV);
/* Look in the phy topology */ if (dev->link_topo) { struct phy_device_node *pdn; unsigned long phy_index;
xa_for_each(&dev->link_topo->phys, phy_index, pdn) { if (!phy_has_tsinfo(pdn->phy)) continue;
ethtool_init_tsinfo(info); err = phy_ts_info(pdn->phy, info); if (err) return ERR_PTR(err);
if (info->phc_index == hwprov_desc->index) return pdn->phy; } return ERR_PTR(-ENODEV); }
/* Look on the dev->phydev */ if (phy_has_tsinfo(dev->phydev)) { ethtool_init_tsinfo(info); err = phy_ts_info(dev->phydev, info); if (err) return ERR_PTR(err);
if (info->phc_index == hwprov_desc->index) return dev->phydev; }
return ERR_PTR(-ENODEV);}
int ethtool_get_ts_info_by_phc(struct net_device *dev, struct kernel_ethtool_ts_info *info, struct hwtstamp_provider_desc *hwprov_desc){ int err;
err = ethtool_net_get_ts_info_by_phc(dev, info, hwprov_desc); if (err == -ENODEV || err == -EOPNOTSUPP) { struct phy_device *phy;
phy = ethtool_phy_get_ts_info_by_phc(dev, info, hwprov_desc); if (IS_ERR(phy)) return PTR_ERR(phy);
/* Report the phc source only if we have a real * phc source with an index. */ if (info->phc_index >= 0) { info->phc_source = HWTSTAMP_SOURCE_PHYLIB; info->phc_phyindex = phy->phyindex; } err = 0; } else if (!err && info->phc_index >= 0) { info->phc_source = HWTSTAMP_SOURCE_NETDEV; }
info->so_timestamping |= SOF_TIMESTAMPING_RX_SOFTWARE | SOF_TIMESTAMPING_SOFTWARE;
return err;}
int __ethtool_get_ts_info(struct net_device *dev, struct kernel_ethtool_ts_info *info){ struct hwtstamp_provider *hwprov; int err = 0;
rcu_read_lock(); hwprov = rcu_dereference(dev->hwprov); /* No provider specified, use default behavior */ if (!hwprov) { const struct ethtool_ops *ops = dev->ethtool_ops; struct phy_device *phydev = dev->phydev;
ethtool_init_tsinfo(info); if (phy_is_default_hwtstamp(phydev) && phy_has_tsinfo(phydev)) { err = phy_ts_info(phydev, info); /* Report the phc source only if we have a real * phc source with an index. */ if (!err && info->phc_index >= 0) { info->phc_source = HWTSTAMP_SOURCE_PHYLIB; info->phc_phyindex = phydev->phyindex; } } else if (ops->get_ts_info) { err = ops->get_ts_info(dev, info); if (!err && info->phc_index >= 0) info->phc_source = HWTSTAMP_SOURCE_NETDEV; }
info->so_timestamping |= SOF_TIMESTAMPING_RX_SOFTWARE | SOF_TIMESTAMPING_SOFTWARE;
rcu_read_unlock(); return err; }
err = ethtool_get_ts_info_by_phc(dev, info, &hwprov->desc); rcu_read_unlock(); return err;}
bool net_support_hwtstamp_qualifier(struct net_device *dev, enum hwtstamp_provider_qualifier qualifier){ const struct ethtool_ops *ops = dev->ethtool_ops;
if (!ops) return false;
/* Return true with precise qualifier and with NIC without * qualifier description to not break the old behavior. */ if (!ops->supported_hwtstamp_qualifiers && qualifier == HWTSTAMP_PROVIDER_QUALIFIER_PRECISE) return true;
if (ops->supported_hwtstamp_qualifiers & BIT(qualifier)) return true;
return false;}
int ethtool_get_phc_vclocks(struct net_device *dev, int **vclock_index){ struct kernel_ethtool_ts_info info = { }; int num = 0;
if (!__ethtool_get_ts_info(dev, &info)) num = ptp_get_vclocks_index(info.phc_index, vclock_index);
return num;}EXPORT_SYMBOL(ethtool_get_phc_vclocks);
int ethtool_get_ts_info_by_layer(struct net_device *dev, struct kernel_ethtool_ts_info *info){ return __ethtool_get_ts_info(dev, info);}EXPORT_SYMBOL(ethtool_get_ts_info_by_layer);
const struct ethtool_phy_ops *ethtool_phy_ops;
void ethtool_set_ethtool_phy_ops(const struct ethtool_phy_ops *ops){ ASSERT_RTNL(); ethtool_phy_ops = ops;}EXPORT_SYMBOL_GPL(ethtool_set_ethtool_phy_ops);
voidethtool_params_from_link_mode(struct ethtool_link_ksettings *link_ksettings, enum ethtool_link_mode_bit_indices link_mode){ const struct link_mode_info *link_info;
if (WARN_ON_ONCE(link_mode >= __ETHTOOL_LINK_MODE_MASK_NBITS)) return;
link_info = &link_mode_params[link_mode]; link_ksettings->base.speed = link_info->speed; link_ksettings->lanes = link_info->lanes; link_ksettings->base.duplex = link_info->duplex;}EXPORT_SYMBOL_GPL(ethtool_params_from_link_mode);
/** * ethtool_forced_speed_maps_init * @maps: Pointer to an array of Ethtool forced speed map * @size: Array size * * Initialize an array of Ethtool forced speed map to Ethtool link modes. This * should be called during driver module init. */voidethtool_forced_speed_maps_init(struct ethtool_forced_speed_map *maps, u32 size){ for (u32 i = 0; i < size; i++) { struct ethtool_forced_speed_map *map = &maps[i];
linkmode_set_bit_array(map->cap_arr, map->arr_size, map->caps); map->cap_arr = NULL; map->arr_size = 0; }}EXPORT_SYMBOL_GPL(ethtool_forced_speed_maps_init);
void ethtool_rxfh_context_lost(struct net_device *dev, u32 context_id){ struct ethtool_rxfh_context *ctx;
WARN_ONCE(!rtnl_is_locked() && !lockdep_is_held_type(&dev->ethtool->rss_lock, -1), "RSS context lock assertion failed\n");
netdev_err(dev, "device error, RSS context %d lost\n", context_id); ctx = xa_erase(&dev->ethtool->rss_ctx, context_id); kfree(ctx); ethtool_rss_notify(dev, ETHTOOL_MSG_RSS_DELETE_NTF, context_id);}EXPORT_SYMBOL(ethtool_rxfh_context_lost);
bool netif_is_rxfh_configured(const struct net_device *dev){ return dev->ethtool->rss_indir_user_size;}EXPORT_SYMBOL(netif_is_rxfh_configured);
/** * ethtool_rxfh_indir_lost - Notify core that the RSS indirection table was lost * @dev: network device * * Drivers should call this when the device can no longer maintain the * user-configured indirection table, typically after a HW fault recovery * that reduced the maximum queue count. Marks the default RSS context * indirection table as unconfigured and sends an %ETHTOOL_MSG_RSS_NTF * notification. */void ethtool_rxfh_indir_lost(struct net_device *dev){ WARN_ONCE(!rtnl_is_locked() && !lockdep_is_held_type(&dev->ethtool->rss_lock, -1), "RSS context lock assertion failed\n");
netdev_err(dev, "device error, RSS indirection table lost\n"); dev->ethtool->rss_indir_user_size = 0; ethtool_rss_notify(dev, ETHTOOL_MSG_RSS_NTF, 0);}EXPORT_SYMBOL(ethtool_rxfh_indir_lost);
static bool ethtool_rxfh_is_periodic(const u32 *tbl, u32 old_size, u32 new_size){ u32 i;
for (i = new_size; i < old_size; i++) if (tbl[i] != tbl[i % new_size]) return false; return true;}
static bool ethtool_rxfh_can_resize(const u32 *tbl, u32 old_size, u32 new_size, u32 user_size){ if (new_size == old_size) return true;
if (!user_size) return true;
if (new_size < old_size) { if (new_size < user_size) return false; if (old_size % new_size) return false; if (!ethtool_rxfh_is_periodic(tbl, old_size, new_size)) return false; return true; }
if (new_size % old_size) return false; return true;}
/* Resize without validation; caller must have called can_resize first */static void ethtool_rxfh_resize(u32 *tbl, u32 old_size, u32 new_size){ u32 i;
/* Grow: replicate existing pattern; shrink is a no-op on the data */ for (i = old_size; i < new_size; i++) tbl[i] = tbl[i % old_size];}
/** * ethtool_rxfh_indir_can_resize - Check if context 0 indir table can resize * @dev: network device * @tbl: indirection table * @old_size: current number of entries in the table * @new_size: desired number of entries * * Validate that @tbl can be resized from @old_size to @new_size without * data loss. Uses the user_size floor from context 0. When user_size is * zero the table is not user-configured and resize always succeeds. * Read-only; does not modify the table. * * Return: true if resize is possible, false otherwise. */bool ethtool_rxfh_indir_can_resize(struct net_device *dev, const u32 *tbl, u32 old_size, u32 new_size){ return ethtool_rxfh_can_resize(tbl, old_size, new_size, dev->ethtool->rss_indir_user_size);}EXPORT_SYMBOL(ethtool_rxfh_indir_can_resize);
/** * ethtool_rxfh_indir_resize - Fold or unfold context 0 indirection table * @dev: network device * @tbl: indirection table (must have room for max(old_size, new_size) entries) * @old_size: current number of entries in the table * @new_size: desired number of entries * * Resize the default RSS context indirection table in place. Caller * must have validated with ethtool_rxfh_indir_can_resize() first. */void ethtool_rxfh_indir_resize(struct net_device *dev, u32 *tbl, u32 old_size, u32 new_size){ if (!dev->ethtool->rss_indir_user_size) return;
ethtool_rxfh_resize(tbl, old_size, new_size);}EXPORT_SYMBOL(ethtool_rxfh_indir_resize);
/** * ethtool_rxfh_ctxs_can_resize - Validate resize for all RSS contexts * @dev: network device * @new_indir_size: new indirection table size * * Validate that the indirection tables of all non-default RSS contexts * can be resized to @new_indir_size. Read-only; does not modify any * context. Intended to be paired with ethtool_rxfh_ctxs_resize(). * * Return: 0 if all contexts can be resized, negative errno on failure. */int ethtool_rxfh_ctxs_can_resize(struct net_device *dev, u32 new_indir_size){ struct ethtool_rxfh_context *ctx; unsigned long context; int ret = 0;
if (!dev->ethtool_ops->rxfh_indir_space || new_indir_size > dev->ethtool_ops->rxfh_indir_space) return -EINVAL;
mutex_lock(&dev->ethtool->rss_lock); xa_for_each(&dev->ethtool->rss_ctx, context, ctx) { u32 *indir = ethtool_rxfh_context_indir(ctx);
if (!ethtool_rxfh_can_resize(indir, ctx->indir_size, new_indir_size, ctx->indir_user_size)) { ret = -EINVAL; goto unlock; } }unlock: mutex_unlock(&dev->ethtool->rss_lock); return ret;}EXPORT_SYMBOL(ethtool_rxfh_ctxs_can_resize);
/** * ethtool_rxfh_ctxs_resize - Resize all RSS context indirection tables * @dev: network device * @new_indir_size: new indirection table size * * Resize the indirection table of every non-default RSS context to * @new_indir_size. Caller must have validated with * ethtool_rxfh_ctxs_can_resize() first. An %ETHTOOL_MSG_RSS_NTF is * sent for each resized context. * * Notifications are sent outside the RSS lock to avoid holding the * mutex during notification delivery. */void ethtool_rxfh_ctxs_resize(struct net_device *dev, u32 new_indir_size){ struct ethtool_rxfh_context *ctx; unsigned long context;
mutex_lock(&dev->ethtool->rss_lock); xa_for_each(&dev->ethtool->rss_ctx, context, ctx) { ethtool_rxfh_resize(ethtool_rxfh_context_indir(ctx), ctx->indir_size, new_indir_size); ctx->indir_size = new_indir_size; } mutex_unlock(&dev->ethtool->rss_lock);
xa_for_each(&dev->ethtool->rss_ctx, context, ctx) ethtool_rss_notify(dev, ETHTOOL_MSG_RSS_NTF, context);}EXPORT_SYMBOL(ethtool_rxfh_ctxs_resize);
enum ethtool_link_medium ethtool_str_to_medium(const char *str){ int i;
for (i = 0; i < __ETHTOOL_LINK_MEDIUM_LAST; i++) if (!strcmp(ethtool_link_medium_names[i], str)) return i;
return ETHTOOL_LINK_MEDIUM_NONE;}EXPORT_SYMBOL_GPL(ethtool_str_to_medium);
u8 netdev_rss_key[NETDEV_RSS_KEY_LEN] __read_mostly;bool netdev_rss_key_initialized __read_mostly;
/* Toeplitz is linear over GF(2): the hash is the XOR of the 32-bit key * windows selected by the set bits of the input, and hardware indexes the * indirection table with the low order bits of the hash. Only the tail of * each window therefore matters for queue selection: * * v(i) = key bits [i + 32 - q .. i + 31] * * for input bit @i, with q = log2(number of RX queues). Consecutive input * bits give windows overlapping in q - 1 positions, so the matrix formed by * the windows of the q lowest bits of a header field is a Toeplitz matrix * built from 2 * q - 1 key bits, not from q * q independent ones. A random * Toeplitz matrix over GF(2) is singular with probability 1/2, whatever its * size, and when it is singular the flows of a burst differing only in the * low order bits of that field (consecutive ephemeral ports, typically) * cannot reach all the RX queues no matter how many of them are configured. * * Keep the key random, but constrain the few bits that decide this. The * fixup is applied at every 16-bit aligned position of the key, rather than * at the offsets of the one hash input layout the software happens to know * about: hardware is free to hash whatever it wants, but the fields it picks * are 16 bits wide at the smallest and are not expected to straddle that * grid, so an encapsulated or offloaded layout is covered like the usual * 2-tuple and 4-tuple ones. Each position constrains 2 * q - 1 bits, so * NETDEV_RSS_KEY_QMAX is both enough for 256 queues and the largest value * keeping the ranges of two adjacent positions disjoint. */#define NETDEV_RSS_KEY_QMAX 8#define NETDEV_RSS_KEY_SPAN (2 * NETDEV_RSS_KEY_QMAX - 1)
static bool netdev_rss_key_bit(const u8 *key, unsigned int bit){ return key[bit / BITS_PER_BYTE] & (0x80 >> (bit % BITS_PER_BYTE));}
static void netdev_rss_key_assign_bit(u8 *key, unsigned int bit, bool value){ u8 mask = 0x80 >> (bit % BITS_PER_BYTE);
if (value) key[bit / BITS_PER_BYTE] |= mask; else key[bit / BITS_PER_BYTE] &= ~mask;}
/* Writing d[t] for key bit (@lsb + 31 - t), the matrices of all the q values * up to NETDEV_RSS_KEY_QMAX are non singular if and only if * * d[2 * i] = 1 ^ d[i] ^ d[i + 1] ^ ... ^ d[2 * i - 1] * * The odd positions stay free, so this is a one pass fixup rather than a * search. It is also a bijection onto the set of the values having the * property, so the key stays uniformly distributed over that set. It costs * NETDEV_RSS_KEY_QMAX bits of entropy per position. */static void netdev_rss_key_fixup_field(u8 *key, unsigned int lsb){ bool d[NETDEV_RSS_KEY_SPAN]; unsigned int i, t;
for (t = 0; t < NETDEV_RSS_KEY_SPAN; t++) d[t] = netdev_rss_key_bit(key, lsb + 31 - t);
for (i = 0; 2 * i < NETDEV_RSS_KEY_SPAN; i++) { bool value = true;
for (t = i; t < 2 * i; t++) value ^= d[t];
d[2 * i] = value; }
for (t = 0; t < NETDEV_RSS_KEY_SPAN; t++) netdev_rss_key_assign_bit(key, lsb + 31 - t, d[t]);}
/* The 32 key bits starting at @bit, which is what input bit @bit contributes * to the hash. @bit + 32 must fit in the key. */static u32 netdev_rss_key_window(const u8 *key, unsigned int bit){ unsigned int byte = bit / BITS_PER_BYTE; unsigned int shift = bit % BITS_PER_BYTE; u32 window = get_unaligned_be32(key + byte);
if (shift) window = (window << shift) | (key[byte + 4] >> (BITS_PER_BYTE - shift));
return window;}
/* Two input bits contributing the same window are indistinguishable to the * hash, since flipping both of them leaves it unchanged. For a uniformly * random key that is a 2 ** -32 event per pair of positions, but the fixup * makes it likelier: it derives 8 of every 16 bits from the 8 others, so a * 16-bit aligned word only takes 2 ** 8 values and two windows a whole * number of words apart collide with probability 2 ** -16 instead. Half a * word apart is less affected but still well clear of the random odds, so * cover every distance that is a multiple of 8. What is left after that is * below what a plain random key gives. * * Two windows at a distance that is a multiple of 8 are two windows at the * same offset modulo 8. Caching a whole class would put 253 u32 on the * stack, so cache one class modulo 16 and stream the class 8 bits above it * against it. */static bool netdev_rss_key_aliases(const u8 *key, unsigned int bits){ u32 windows[NETDEV_RSS_KEY_LEN * BITS_PER_BYTE / 16]; unsigned int i, j, n, r;
for (r = 0; r < 16; r++) { n = 0; for (i = r; i + 32 <= bits; i += 16) windows[n++] = netdev_rss_key_window(key, i);
for (i = 0; i < n; i++) for (j = i + 1; j < n; j++) if (windows[i] == windows[j]) return true;
if (r >= 8) continue;
for (i = r + 8; i + 32 <= bits; i += 16) { u32 window = netdev_rss_key_window(key, i);
for (j = 0; j < n; j++) if (windows[j] == window) return true; } }
return false;}
static void netdev_rss_key_init(u8 *key, size_t len){ unsigned int lsb, bits = len * BITS_PER_BYTE;
/* Four keys out of five come out of the fixup free of aliases, so * drawing another one is both simpler and cheaper than repairing. */ do { get_random_bytes(key, len);
/* A field ending at bit @lsb uses key bits [.. , @lsb + 31], * so stop as soon as a 32-bit window no longer fits in the * key. */ for (lsb = 15; lsb + 32 <= bits; lsb += 16) netdev_rss_key_fixup_field(key, lsb); } while (netdev_rss_key_aliases(key, bits));
/* Pair with smp_rmb() in proc_do_rss_key(). */ smp_wmb(); WRITE_ONCE(netdev_rss_key_initialized, true);}
void netdev_rss_key_fill(void *buffer, size_t len){ if (WARN_ON_ONCE(len > sizeof(netdev_rss_key))) len = sizeof(netdev_rss_key); DO_ONCE(netdev_rss_key_init, netdev_rss_key, sizeof(netdev_rss_key)); memcpy(buffer, netdev_rss_key, len);}EXPORT_SYMBOL(netdev_rss_key_fill);